NSBitmapImageRep byte/color component ordering
NSBitmapImageRep byte/color component ordering
- Subject: NSBitmapImageRep byte/color component ordering
- From: "Brian Tarricone" <email@hidden>
- Date: Wed, 31 Oct 2007 17:06:15 -0700
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