• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating a color image with NSBitmapImageRep and greyscale data
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a color image with NSBitmapImageRep and greyscale data


  • Subject: Re: Creating a color image with NSBitmapImageRep and greyscale data
  • From: David Spooner <email@hidden>
  • Date: Tue, 27 Nov 2007 20:34:34 -0700


On 27-Nov-07, at 5:38 PM, Jason Horn wrote:

I need to create a color image from greyscale data. This is because I would like to display the image in false color to aid in visualization. I have tried using the CIColorMap core image filter on a CIImage created from a 16 bit greyscale NSBitmapImageRep, but this does not work (you just get a modified greyscale image, not color). Unfortunately, there is nothing in the documentation for CIColorMap that says you can only apply this filter to a color image, but I am assuming that that is the case. So, I though I would transform the greyscale image data into color RGB data and create a color NSBitmapImageRep, but this is not working either. Here's what I have:

	NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
		        initWithBitmapDataPlanes:NULL
				      pixelsWide:width
				      pixelsHigh:height
				   bitsPerSample:16
				 samplesPerPixel:3
					hasAlpha:NO
					isPlanar:NO
				  colorSpaceName:NSCalibratedRGBColorSpace
				    bitmapFormat:0
			   	     bytesPerRow:3840
				    bitsPerPixel:48];
	unsigned char *bitmapData = [bitmap bitmapData];
	uint16_t RGBData[921600];
	int pixel, color;
	int numPixels = height*width;
	for (pixel=0; pixel<numPixels; pixel++) {
		for (color=0; color<3; color++) {
			RGBData[pixel+color] = pixels[pixel];

The preceding line sets the r, g and b components uniformly for each output pixel, so you'll always get grey. You might try distributing each input pixel p across r, g and b along the lines of...


int bpr = [bitmap bytesPerRow];

for (int i = 0; i < height; ++i) {
  char *row = bitmapData + i * bpr;
  for (int j = 0; j < width; ++j) {
    uint16_t p = pixels[i * width + j];
    unsigned char *rgb = row + j * 3;
    rgb[0] = p & 0x3f;
    rgb[1] = (p >> 6) & 0x3f;
    rgb[2] = (p >> 12);
  }
}

}
}
memcpy(bitmapData, RGBData, [bitmap bytesPerRow] * [bitmap pixelsHigh]);

'pixels' is an array of 16 bit integers that contain the data for the 16 bit greyscale image that is 640 x 480. This code actually produces a three mini-greyscale images inside the main image.

Does anyone know hat I'm doing wrong? Any suggestions for creating a color image from greyscale data?

Thanks!_______________________________________________



Cheers, dave

_______________________________________________

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


  • Follow-Ups:
    • Re: Creating a color image with NSBitmapImageRep and greyscale data
      • From: David Spooner <email@hidden>
References: 
 >Creating a color image with NSBitmapImageRep and greyscale data (From: Jason Horn <email@hidden>)

  • Prev by Date: Re: Archived QTMovieViews on 64-bit?
  • Next by Date: Use of assign vs. copy for accessors in Garbage Collected app
  • Previous by thread: Creating a color image with NSBitmapImageRep and greyscale data
  • Next by thread: Re: Creating a color image with NSBitmapImageRep and greyscale data
  • Index(es):
    • Date
    • Thread