NSBitmapImageContext from WORD *

davecom
Unregistered
 
Post: #1
Hi everyone,
I'm attempting to put
WORD *WorkFrame;
which points to
WORD DoubleFrame[ 2 ][ NES_DISP_WIDTH * NES_DISP_HEIGHT ];
in which the pixels are stored like this:

Since Array WorkFrame stores the screen information (256x240) in
16-bit pallet format (5-5-5), it must be transformed and
displayed in the format of the target machine.

into an NSBitmapImageContext using the following:
Code:
NSBitmapImageRep *ir = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **)WorkFrame
                                            pixelsWide:NES_DISP_WIDTH pixelsHigh:NES_DISP_HEIGHT
                                         bitsPerSample:5 samplesPerPixel:3 hasAlpha:NO isPlanar:NO
                                        colorSpaceName:NSDeviceRGBColorSpace
                                           bytesPerRow:NES_DISP_WIDTH bitsPerPixel:16];

All I'm getting is blankness and "Inconsistent set of values to create NSBitmapImageRep"
Any help much appreciated. Thanks.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
bytesPerRow will need to be 2 * NES_DISP_WIDTH, at least. It may not be the only problem, but it is wrong.
Quote this message in a reply
davecom
Unregistered
 
Post: #3
Good catch, but yeah same errors still.
Quote this message in a reply
davecom
Unregistered
 
Post: #4
Okay I have a black box displaying now, but not the image! Also I seem to get a crash when trying to draw the image sometimes on the internal method:
vecCGSConvertRGB888
I'm shifting the 5-5-5 data over to 8-8-8 using the borrowed method:
register unsigned char* pBuf;
register int x,y;
/*
NSBitmapImageRep *ir;
NSImage *img = [[NSImage alloc] initWithSize:NSMakeSize(NES_DISP_WIDTH,NES_DISP_HEIGHT*3)];
NSData *datf;
*/
//gdk_threads_enter();

pBuf = pbyRgbBuf;

// Exchange 16-bit to 24-bit
for (y = 0; y < NES_DISP_HEIGHT; y++ )
{
for (x = 0; x < NES_DISP_WIDTH; x++ )
{
WORD wColor = WorkFrame[ ( y << 8 ) + x ];

*(pBuf++) = (unsigned char)( ( wColor & 0x7c00 ) >> 7 );
*(pBuf++) = (unsigned char)( ( wColor & 0x03e0 ) >> 2 );
*(pBuf++) = (unsigned char)( ( wColor & 0x001f ) << 3 );
}
}

where pbyRgbBuf is:
extern unsigned char pbyRgbBuf[ NES_DISP_WIDTH * NES_DISP_HEIGHT * 3 ];
extern because it's used in my view in a difference source file.

Any ideas?
Quote this message in a reply
davecom
Unregistered
 
Post: #5
Also I forgot to mention my bitmapimagerep now is:
ir = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **)pbyRgbBuf
pixelsWide:NES_DISP_WIDTH pixelsHigh:NES_DISP_HEIGHT
bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:3*NES_DISP_WIDTH bitsPerPixel:24];
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  The tabbing on a word playing back the recorded voice itcreate 0 2,271 Jun 25, 2010 02:06 PM
Last Post: itcreate