tags:

views:

45

answers:

1

i have a char* array of data that was in RGBA and then moved to ARGB

Bottom line is the set application image looks totally messed up and i cant put my finger on why?

    //create a bitmap representation of the image data.
   //The data is expected to be unsigned char**
   NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
       initWithBitmapDataPlanes : (unsigned char**) &dest
       pixelsWide:width pixelsHigh:height
       bitsPerSample:8
       samplesPerPixel:4
       hasAlpha:YES
       isPlanar:NO
       colorSpaceName:NSDeviceRGBColorSpace
       bitmapFormat: NSAlphaFirstBitmapFormat
       bytesPerRow: bytesPerRow
       bitsPerPixel:32 ];

   //allocate the image
   NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
   [image addRepresentation:bitmap];


   if( image == NULL) {
       printf("image is null\n");
       fflush(stdout);
   }

   //set the icon image of the application
   [NSApp setApplicationIconImage :image];

   //tell the image to autorelease when done
   [image autorelease];

What in these values is not right? the image looks very multicolored and pixelated, with transparent parts/lines as well.

EDIT: after changing bytes per row to width*4 (scanline), this is the image i get. ![alt text][1]

The original image is just an orange square.

EDIT2: updated image and some of the parameters.

Thanks!

alt text

+1  A: 

It is only useful to specify 0 for bytesPerRow if you're also passing NULL for the data (and thus letting the rep allocate it itself). If you pass zero, you're asking the system to use the "best" bytesPerRow, which is not stable between architectures and OS versions. It isn't width*bitsPerPixel, it's padded out for alignment.

This is one that that is wrong, at least.

Ken
I added an edit to include your change, the result is posted, thanks! almost there.
Joe
Er, 32 for bitsPerPixel too. If you're passing in data, the format of the data is already determined, so you shouldn't let the framework choose on anything. Other than that, I guess I'd wonder whether the data is really in the format you're passing to the bitmap. You might need to attach a complete sample app yo let peole see.
Ken
I wish i could... I added in that as well and it looks more or less the same... i know the data is right because i use it on windows.It is char ** though, does making it unsigned make things weird? i dont think it should. THanks for the suggestions
Joe
You should always be able to make a sample app. I'm not suggesting you publish your source, just make an isolated app the shows the problem.
Ken
The fact that you use it on windows does not mean that the format is what you're passing to NSBitmapImageRep. For example, is it really ARGB, or is it BGRA. ARGB to NSBitmapImageRep means the first byte is A, second R, third G, fourth B, when examined byte by byte.
Ken
yes i went back and forth. I switched it back to argb and it looks a lot closer not, its a bit dark and obviously there is what looks like width and height. I updated the image.
Joe