NSBitmapImageContext from WORD *
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:
All I'm getting is blankness and "Inconsistent set of values to create NSBitmapImageRep"
Any help much appreciated. Thanks.
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.
bytesPerRow will need to be 2 * NES_DISP_WIDTH, at least. It may not be the only problem, but it is wrong.
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?
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?
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];
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];
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| The tabbing on a word playing back the recorded voice | itcreate | 0 | 1,990 |
Jun 25, 2010 02:06 PM Last Post: itcreate |
|

