Re: NSBitmapImageRep byte/color component ordering
Re: NSBitmapImageRep byte/color component ordering
- Subject: Re: NSBitmapImageRep byte/color component ordering
- From: "Brian Tarricone" <email@hidden>
- Date: Thu, 1 Nov 2007 17:18:22 -0700
In the meantime, I've "solved" my problem by using -[NSImage
TIFFRepresentationWithCompression:factor:] to get TIFF data, which I
then feed to a CGImageSource -> CGImage, then draw to a
CGBitmapContext (which I've created by telling it the endianness I
want), then taking the raw bitmap data back out, applying my "border
trimming", and then stuffing it in a new NSBitmapImageRep. Weirdly,
the image seems to lose some quality in the colors (maybe a colorspace
issue?), but for now it at least works.
Thanks to Alastair and Ben for their help.
-brian
On Oct 31, 2007 5:06 PM, Brian Tarricone <email@hidden> wrote:
> Hi all,
>
> I'm working on an audio/video metadata tagging application. One of
> the metadata types it can tag a file with is cover/album art. Users
> can get art in one of three ways: selecting an image file on their
> hard drive, picking a frame from the video file itself to serve as the
> cover art (using QTMovieView from QTKit), or fetching the cover image
> from imdb.com or amazon.com (using an embedded WebView from WebKit for
> this). No problems so far...
>
> I've also implemented a feature to automatically "trim" a border off
> the image. This is mainly useful for images retrieved from
> amazon.com, which has a large white border around the actual cover art
> images. Here's where the problem lies. The image is shown in my UI
> in a NSImageView. I pull the underlying NSImage out, get the
> NSBitmapImageRep's bitmap data (using NSBitmapImageRep::bitmapData),
> convert it to 32bpp (RGBA), run my border trimmer on the data, and
> then pack it into a new NSBitmapImageRep (created with NULL as the
> bitmap data, and then memcpy()ing the data in) which gets set as the
> representation for a new NSImage.
>
> When I do all this when the source image is a frame from the movie
> itself, it works fine. However, when I do this for an image fetched
> from amazon.com, the post-trimmed image has the colors messed up; it
> looks like the raw bitmap data is BGRA (or maybe ABGR, not sure), but
> the new NSBitmapImageRep I create expects RGBA, so, in the final
> image, the green and red components are swapped.
>
> I can think of two possible ways to solve this problem, neither of
> which appears to be possible:
>
> 1. Convert the color order myself before copying the image data to
> the new NSBitmapImageRep, or
> 2. Tell the new NSBitmapImageRep what color order to expect.
>
> However, I can't seem to figure out how to 1) determine the color
> order in the source NSBitmapImageRep, or 2) tell the destination
> imagerep what color order the data is in. Any ideas? Am I missing
> something here? I looked around in the list archives(*), and I found
> a couple similar posts, but with no useful answers.
>
> Thanks,
> Brian
>
> * These:
> http://lists.apple.com/archives/cocoa-dev/2002/Jan/msg00350.html (no answer)
> http://lists.apple.com/archives/cocoa-dev/2004/Jul/msg00560.html
> (possibly useful answer, but no hint as to how to do it)
> http://lists.apple.com/archives/cocoa-dev/2006/Feb/msg00185.html (no answer)
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden