Re: NSEPSImageRep to NSBitmapImageRep to GWorld problems
Re: NSEPSImageRep to NSBitmapImageRep to GWorld problems
- Subject: Re: NSEPSImageRep to NSBitmapImageRep to GWorld problems
- From: p3consulting <email@hidden>
- Date: Sun, 30 Nov 2003 10:57:44 +0100
>
Hi,
>
>
I've been attempting to draw an NSEPSImapgeRep image into a GWorld and
>
have
>
had suboptimal luck doing so. (and yes I am using Panther which is
>
supposed to
>
fix EPS.)
>
>
To make a long story short I:
>
1) Alloc and load the image with [[NSImage alloc]
>
initWithContentsOfFile: <
>
filename>]
>
2) lockFocus on the image, then
>
3) [[NSBitmapImageRep alloc] initWithFocusedViewRect:<myNSRect>] to
>
pull the
>
image into a bitmap,
>
4) and then use Apple's sample code CopyNSImageToGWorld(NSImage *,
>
GWorldPtr)
>
to copy the image into a GWorld. (Note: I did modify their code
>
slightly to
>
handle both 24-bit and 32-bit NSImages...their original sample was
>
setup for
>
24-bit only).
>
>
The problem is that while my bitmap image representation reports to
>
have one
>
plane the image comes out in just one color, blue. I was expecting
>
the mesh
>
of RGB.
>
>
Does anyone have any ideas what my problem could be? My first guess
>
was that
>
the bitmap actually had multiple color planes encoded in some way that
>
was
>
not obvious to me. Is it possible NSEPSImageRep does not correctly
>
map into a
>
NSBitmapImageRep?
>
The Apple example code handles only meshed RGB (888 format) bitmaps.
You have to adapt it further more than you have done to test for other
formats:
read the doc about which formats are supported by NSBitmapRep,
(if I remember correctly, 8 bits per pixel grayscale, rgb 555, rgb 888
and rgba 8888 for the meshed ones + rgb,, rgba, cmyk, cmyka for the
planar ones)
the first test in the conversion routine should be
if ([(NSBitmapImageRep *)imageRepresentation isPlanar])
if the bimap is planar you have to get the planes
unsigned char *dataPanes[5] ;
[(NSBitmapImageRep *)imageRepresentation getBitmapDataPlanes:&
dataPanes]
and in the inside loop you will have to go thru the n planes at the
same time to reassemble the planes into one meshed bitmap
and in case the original data is a CMYKA image (the reason why you have
to pass a 5 pointers array)
and of course don't forget to convert from CMYK to RGB
[(NSBitmapImageRep *)imageRepresentation numberOfPlanes] will tell you
how many planes are actually used by the representation.
[(NSBitmapImageRep *)imageRepresentation colorSpaceName] will tell you
if you are in RGB or CMYK color space (or any other)
[(NSBitmapImageRep *)imageRepresentation bitsPerPixel] ;
will tell you if you are facing a 32 bits meshed image or 16 bits one.
Also be careful with meshed 32 bits NSBitmapImageRep that are RGBA
where GWorld are ARGB.
Another way of solving the problem would be to force drawing of the EPS
in a bitmap you have allocated yourself and that will always have the
same specs,
but to do that you have to go to CG lower-level drawing primitives.
Pascal Pochet
P3 Consulting
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.