[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx:[616] branches/fuse_corevideo/fuse
Brought to you by:
fredm
From: <fr...@us...> - 2009-08-13 11:54:21
|
Revision: 616 http://fuse-for-macosx.svn.sourceforge.net/fuse-for-macosx/?rev=616&view=rev Author: fredm Date: 2009-08-13 11:54:12 +0000 (Thu, 13 Aug 2009) Log Message: ----------- Switch to 8888 pixel format as its more CoreImage-friendly. Modified Paths: -------------- branches/fuse_corevideo/fuse/fusepb/scaler/scalers16.c branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.h branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.m branches/fuse_corevideo/fuse/ui/cocoa/cocoadisplay.m branches/fuse_corevideo/fuse/ui/scaler/scaler.c Modified: branches/fuse_corevideo/fuse/fusepb/scaler/scalers16.c =================================================================== --- branches/fuse_corevideo/fuse/fusepb/scaler/scalers16.c 2009-08-08 14:04:58 UTC (rev 615) +++ branches/fuse_corevideo/fuse/fusepb/scaler/scalers16.c 2009-08-13 11:54:12 UTC (rev 616) @@ -23,6 +23,6 @@ * */ -#define SCALER_DATA_SIZE 2 +#define SCALER_DATA_SIZE 4 #include "ui/scaler/scalers.c" Modified: branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.h =================================================================== --- branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.h 2009-08-08 14:04:58 UTC (rev 615) +++ branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.h 2009-08-13 11:54:12 UTC (rev 616) @@ -77,6 +77,8 @@ CVDisplayLinkRef displayLink; CGDirectDisplayID mainViewDisplayID; BOOL displayLinkRunning; + + CIContext * ciContext; } +(DisplayOpenGLView *) instance; @@ -94,6 +96,7 @@ -(id) initWithFrame:(NSRect)frameRect; -(void) awakeFromNib; -(void) initDisplayLink; +-(void) createCIContext; -(void) loadPicture:(NSString *) name greenTex:(Texture*) greenTexture Modified: branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.m =================================================================== --- branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.m 2009-08-08 14:04:58 UTC (rev 615) +++ branches/fuse_corevideo/fuse/fusepb/views/DisplayOpenGLView.m 2009-08-13 11:54:12 UTC (rev 616) @@ -205,6 +205,8 @@ [self prepareOpenGL:[self openGLContext]]; + [self createCIContext]; + greenCassette = [Texture alloc]; redCassette = [Texture alloc]; [self loadPicture: @"cassette" greenTex:greenCassette @@ -312,6 +314,24 @@ displayLinkRunning = NO; } +-(void) createCIContext +{ + [[self openGLContext] makeCurrentContext]; + /* Create CGColorSpaceRef */ + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + /* Create CIContext */ + ciContext = [[CIContext contextWithCGLContext: + (CGLContextObj)[[self openGLContext] CGLContextObj] + pixelFormat:(CGLPixelFormatObj) + [[self pixelFormat] CGLPixelFormatObj] + options:[NSDictionary dictionaryWithObjectsAndKeys: + (id)colorSpace,kCIContextOutputColorSpace, + (id)colorSpace,kCIContextWorkingColorSpace,nil]] retain]; + + CGColorSpaceRelease(colorSpace); +} + - (void)windowWillClose:(NSNotification *)notification { [[self window] setDelegate:nil]; @@ -334,6 +354,9 @@ [greenDisk release]; greenDisk = nil; + [ciContext release]; + ciContext = nil; + [self release]; } @@ -598,13 +621,13 @@ screenTex[i].image_xoffset = newScreen->image_xoffset; screenTex[i].image_yoffset = newScreen->image_yoffset; screenTex[i].pixels = calloc( screenTex[i].full_width * screenTex[i].full_height, - sizeof(uint16_t) ); + sizeof(uint32_t) ); if( !screenTex[i].pixels ) { NSLog( @"%s: couldn't create screenTex[%ud].pixels\n", fuse_progname, (unsigned int)i ); return; } - screenTex[i].pitch = screenTex[i].full_width * sizeof(uint16_t); + screenTex[i].pitch = screenTex[i].full_width * sizeof(uint32_t); glDisable( GL_TEXTURE_2D ); glEnable( GL_TEXTURE_RECTANGLE_ARB ); @@ -625,7 +648,7 @@ glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); glTexImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, screenTex[i].full_width, - screenTex[i].full_height, 0, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, + screenTex[i].full_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, screenTex[i].pixels ); } screenTexInitialised = YES; @@ -1330,7 +1353,7 @@ glTexSubImage2D( GL_TEXTURE_RECTANGLE_ARB, 0, 0, 0, screenTex[currentScreenTex].full_width, screenTex[currentScreenTex].full_height, GL_BGRA, - GL_UNSIGNED_SHORT_1_5_5_5_REV, + GL_UNSIGNED_INT_8_8_8_8_REV, screenTex[currentScreenTex].pixels ); } Modified: branches/fuse_corevideo/fuse/ui/cocoa/cocoadisplay.m =================================================================== --- branches/fuse_corevideo/fuse/ui/cocoa/cocoadisplay.m 2009-08-08 14:04:58 UTC (rev 615) +++ branches/fuse_corevideo/fuse/ui/cocoa/cocoadisplay.m 2009-08-13 11:54:12 UTC (rev 616) @@ -68,27 +68,31 @@ /* and a lock to protect it from concurrent access */ NSLock *buffered_screen_lock = nil; -/* Colours are in 1A 5R 5G 5B format */ -static uint16_t colour_values[] = { - 0x0000, - 0x0017, - 0x5c00, - 0x5c17, - 0x02e0, - 0x02f7, - 0x5ee0, - 0x5ef7, - 0x0000, - 0x001f, - 0x7c00, - 0x7c1f, - 0x03e0, - 0x03ff, - 0x7fe0, - 0x7fff +/* The colour palette */ +static const uint8_t rgb_colours[16][3] = { + + { 0, 0, 0 }, + { 0, 0, 192 }, + { 192, 0, 0 }, + { 192, 0, 192 }, + { 0, 192, 0 }, + { 0, 192, 192 }, + { 192, 192, 0 }, + { 192, 192, 192 }, + { 0, 0, 0 }, + { 0, 0, 255 }, + { 255, 0, 0 }, + { 255, 0, 255 }, + { 0, 255, 0 }, + { 0, 255, 255 }, + { 255, 255, 0 }, + { 255, 255, 255 }, + }; -static uint16_t bw_values[16]; +/* Colours are in 8A 8R 8G 8B format */ +static uint32_t colour_values[16]; +static uint32_t bw_values[16]; static int display_updated = 0; @@ -126,7 +130,7 @@ scaler_select_scaler( SCALER_NORMAL ); } - scaler_select_bitformat( 555 ); + //scaler_select_bitformat( 555 ); } static int @@ -143,7 +147,7 @@ screen->image_yoffset = 1; screen->pixels = calloc( screen->full_width*screen->full_height, - sizeof(uint16_t) ); + sizeof(uint32_t) ); if( !screen->pixels ) { fprintf( stderr, "%s: couldn't allocate screen.pixels\n", fuse_progname ); return 1; @@ -156,7 +160,7 @@ return 1; } - screen->pitch = screen->full_width * sizeof(uint16_t); + screen->pitch = screen->full_width * sizeof(uint32_t); return 0; } @@ -208,21 +212,25 @@ } static int -cocoadisplay_allocate_colours( int numColours, uint16_t *colour_values, - uint16_t *bw_values ) +init_colours( void ) { - int i; - uint8_t red, green, blue, grey; + size_t i; - for( i = 0; i < numColours; i++ ) { - red = (colour_values[i] >> 10) & 0x1f; - green = (colour_values[i] >> 5) & 0x1f; - blue = colour_values[i] & 0x1f; + for( i = 0; i < 16; i++ ) { + + uint8_t red, green, blue, grey; + + red = rgb_colours[i][0]; + green = rgb_colours[i][1]; + blue = rgb_colours[i][2]; + /* Addition of 0.5 is to avoid rounding errors */ grey = ( 0.299 * red + 0.587 * green + 0.114 * blue ) + 0.5; - bw_values[i] = (grey << 10) | (grey << 5) | grey; + colour_values[i] = blue | green << 8 | red << 16; + bw_values[i] = grey | grey << 8 | grey << 16; + } return 0; @@ -232,8 +240,7 @@ uidisplay_init( int width, int height ) { int error; - error = cocoadisplay_allocate_colours( sizeof(colour_values) / sizeof(uint16_t), - colour_values, bw_values ); + error = init_colours(); if( error ) return error; image_width = width; image_height = height; @@ -280,25 +287,25 @@ void uidisplay_putpixel( int x, int y, int colour ) { - uint16_t *dest_base, *dest; - uint16_t *palette_values = settings_current.bw_tv ? bw_values : colour_values; + uint32_t *dest_base, *dest; + uint32_t *palette_values = settings_current.bw_tv ? bw_values : colour_values; - uint16_t palette_colour = palette_values[ colour ]; + uint32_t palette_colour = palette_values[ colour ]; if( machine_current->timex ) { x <<= 1; y <<= 1; - dest_base = dest = (uint16_t*)( (uint8_t*)unscaled_screen.pixels + - (x+unscaled_screen.image_xoffset) * sizeof(uint16_t) + + dest_base = dest = (uint32_t*)( (uint8_t*)unscaled_screen.pixels + + (x+unscaled_screen.image_xoffset) * sizeof(uint32_t) + (y+unscaled_screen.image_yoffset) * unscaled_screen.pitch ); *(dest++) = palette_colour; *(dest++) = palette_colour; - dest = (uint16_t*)( (uint8_t*)dest_base + unscaled_screen.pitch ); + dest = (uint32_t*)( (uint8_t*)dest_base + unscaled_screen.pitch ); *(dest++) = palette_colour; *(dest++) = palette_colour; } else { - dest = (uint16_t*)( (uint8_t*)unscaled_screen.pixels + - (x+unscaled_screen.image_xoffset) * sizeof(uint16_t) + + dest = (uint32_t*)( (uint8_t*)unscaled_screen.pixels + + (x+unscaled_screen.image_xoffset) * sizeof(uint32_t) + (y+unscaled_screen.image_yoffset) * unscaled_screen.pitch ); *dest = palette_colour; @@ -311,20 +318,20 @@ uidisplay_plot8( int x, int y, libspectrum_byte data, libspectrum_byte ink, libspectrum_byte paper ) { - uint16_t *dest; - uint16_t *palette_values = settings_current.bw_tv ? bw_values : colour_values; + uint32_t *dest; + uint32_t *palette_values = settings_current.bw_tv ? bw_values : colour_values; - uint16_t palette_ink = palette_values[ ink ]; - uint16_t palette_paper = palette_values[ paper ]; + uint32_t palette_ink = palette_values[ ink ]; + uint32_t palette_paper = palette_values[ paper ]; if( machine_current->timex ) { int i; - uint16_t *dest_base; + uint32_t *dest_base; x <<= 4; y <<= 1; - dest_base = (uint16_t*)( (uint8_t*)unscaled_screen.pixels + - (x+unscaled_screen.image_xoffset) * sizeof(uint16_t) + + dest_base = (uint32_t*)( (uint8_t*)unscaled_screen.pixels + + (x+unscaled_screen.image_xoffset) * sizeof(uint32_t) + (y+unscaled_screen.image_yoffset) * unscaled_screen.pitch ); for( i=0; i<2; i++ ) { @@ -347,12 +354,12 @@ *(dest++) = ( data & 0x01 ) ? palette_ink : palette_paper; *dest = ( data & 0x01 ) ? palette_ink : palette_paper; - dest_base = (uint16_t*)( (uint8_t*)dest_base + unscaled_screen.pitch ); + dest_base = (uint32_t*)( (uint8_t*)dest_base + unscaled_screen.pitch ); } } else { x <<= 3; - dest = (uint16_t*)( (uint8_t*)unscaled_screen.pixels + - (x+unscaled_screen.image_xoffset) * sizeof(uint16_t) + + dest = (uint32_t*)( (uint8_t*)unscaled_screen.pixels + + (x+unscaled_screen.image_xoffset) * sizeof(uint32_t) + (y+unscaled_screen.image_yoffset) * unscaled_screen.pitch ); *(dest++) = ( data & 0x80 ) ? palette_ink : palette_paper; @@ -372,15 +379,15 @@ uidisplay_plot16( int x, int y, libspectrum_word data, libspectrum_byte ink, libspectrum_byte paper ) { - uint16_t *dest_base, *dest; + uint32_t *dest_base, *dest; int i; - uint16_t *palette_values = settings_current.bw_tv ? bw_values : colour_values; - uint16_t palette_ink = palette_values[ ink ]; - uint16_t palette_paper = palette_values[ paper ]; + uint32_t *palette_values = settings_current.bw_tv ? bw_values : colour_values; + uint32_t palette_ink = palette_values[ ink ]; + uint32_t palette_paper = palette_values[ paper ]; x <<= 4; y <<= 1; - dest_base = (uint16_t*)( (uint8_t*)unscaled_screen.pixels + (x+unscaled_screen.image_xoffset) * - sizeof(uint16_t) + (y+unscaled_screen.image_yoffset) * + dest_base = (uint32_t*)( (uint8_t*)unscaled_screen.pixels + (x+unscaled_screen.image_xoffset) * + sizeof(uint32_t) + (y+unscaled_screen.image_yoffset) * unscaled_screen.pitch ); for( i=0; i<2; i++ ) { @@ -403,7 +410,7 @@ *(dest++) = ( data & 0x0002 ) ? palette_ink : palette_paper; *dest = ( data & 0x0001 ) ? palette_ink : palette_paper; - dest_base = (uint16_t*)( (uint8_t*)dest_base + unscaled_screen.pitch ); + dest_base = (uint32_t*)( (uint8_t*)dest_base + unscaled_screen.pitch ); } } @@ -414,11 +421,11 @@ for( y = r->y; y <= r->y + r->h; y++ ) { int src_offset = (y + src_screen->image_yoffset) * src_screen->pitch + - sizeof(uint16_t) * ( r->x + src_screen->image_xoffset); + sizeof(uint32_t) * ( r->x + src_screen->image_xoffset); int dest_offset = (y + dest_screen->image_yoffset) * dest_screen->pitch + - sizeof(uint16_t) * ( r->x + dest_screen->image_xoffset); + sizeof(uint32_t) * ( r->x + dest_screen->image_xoffset); memcpy( dest_screen->pixels + dest_offset, src_screen->pixels + src_offset, - r->w * sizeof(uint16_t) ); + r->w * sizeof(uint32_t) ); } } @@ -470,12 +477,12 @@ pig_dirty_add( scaled_screen.dirty, &r ); /* Create scaled image */ - scaler_proc16( unscaled_screen.pixels + ( y + unscaled_screen.image_yoffset ) * - unscaled_screen.pitch + sizeof(uint16_t) * + scaler_proc32( unscaled_screen.pixels + ( y + unscaled_screen.image_yoffset ) * + unscaled_screen.pitch + sizeof(uint32_t) * ( x + unscaled_screen.image_xoffset ), unscaled_screen.pitch, scaled_screen.pixels + ( r.y + scaled_screen.image_yoffset ) * - scaled_screen.pitch + sizeof(uint16_t) * + scaled_screen.pitch + sizeof(uint32_t) * ( r.x + scaled_screen.image_xoffset ), scaled_screen.pitch, width, height ); } Modified: branches/fuse_corevideo/fuse/ui/scaler/scaler.c =================================================================== --- branches/fuse_corevideo/fuse/ui/scaler/scaler.c 2009-08-08 14:04:58 UTC (rev 615) +++ branches/fuse_corevideo/fuse/ui/scaler/scaler.c 2009-08-13 11:54:12 UTC (rev 616) @@ -76,45 +76,45 @@ static struct scaler_info available_scalers[] = { { "Timex Half (smoothed)", "half", SCALER_FLAGS_NONE, SCALE_FACTOR_HALF, - scaler_Half_16, NULL, NULL }, + NULL, scaler_Half_32, NULL }, { "Timex Half (skipping)", "halfskip", SCALER_FLAGS_NONE, SCALE_FACTOR_HALF, - scaler_HalfSkip_16, NULL, NULL }, + NULL, scaler_HalfSkip_32, NULL }, { "Normal", "normal", SCALER_FLAGS_NONE, SCALE_FACTOR_ONE, - scaler_Normal1x_16, NULL, NULL }, + NULL, scaler_Normal1x_32, NULL }, { "Double size", "2x", SCALER_FLAGS_NONE, SCALE_FACTOR_TWO, - scaler_Normal2x_16, NULL, NULL }, + NULL, scaler_Normal2x_32, NULL }, { "Triple size", "3x", SCALER_FLAGS_NONE, SCALE_FACTOR_THREE, - scaler_Normal3x_16, NULL, NULL }, + NULL, scaler_Normal3x_32, NULL }, { "2xSaI", "2xsai", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_2xSaI_16, NULL, expand_sai }, + NULL, scaler_2xSaI_32, expand_sai }, { "Super 2xSaI", "super2xsai", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_Super2xSaI_16, NULL, expand_sai }, + NULL, scaler_Super2xSaI_32, expand_sai }, { "SuperEagle", "supereagle", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_SuperEagle_16, NULL, expand_sai }, + NULL, scaler_SuperEagle_32, expand_sai }, { "AdvMAME 2x", "advmame2x", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_AdvMame2x_16, NULL, expand_1 }, + NULL, scaler_AdvMame2x_32, expand_1 }, { "AdvMAME 3x", "advmame3x", SCALER_FLAGS_EXPAND, SCALE_FACTOR_THREE, - scaler_AdvMame3x_16, NULL, expand_1 }, + NULL, scaler_AdvMame3x_32, expand_1 }, { "TV 2x", "tv2x", SCALER_FLAGS_NONE, SCALE_FACTOR_TWO, - scaler_TV2x_16, NULL, NULL }, + NULL, scaler_TV2x_32, NULL }, { "TV 3x", "tv3x", SCALER_FLAGS_NONE, SCALE_FACTOR_THREE, - scaler_TV3x_16, NULL, NULL }, + NULL, scaler_TV3x_32, NULL }, { "Timex TV", "timextv", SCALER_FLAGS_NONE, SCALE_FACTOR_ONE, - scaler_TimexTV_16, NULL, NULL }, + NULL, scaler_TimexTV_32, NULL }, { "Dot Matrix", "dotmatrix", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_DotMatrix_16, NULL, expand_dotmatrix }, + NULL, scaler_DotMatrix_32, expand_dotmatrix }, { "Timex 1.5x", "timex15x", SCALER_FLAGS_NONE, SCALE_FACTOR_ONE_HALF, - scaler_Timex1_5x_16, NULL, NULL }, + NULL, scaler_Timex1_5x_32, NULL }, { "PAL TV", "paltv", SCALER_FLAGS_EXPAND, SCALE_FACTOR_ONE, - scaler_PalTV_16, NULL, expand_pal1 }, + NULL, scaler_PalTV_32, expand_pal1 }, { "PAL TV 2x", "paltv2x", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_PalTV2x_16, NULL, expand_pal }, + NULL, scaler_PalTV2x_32, expand_pal }, { "PAL TV 3x", "paltv3x", SCALER_FLAGS_EXPAND, SCALE_FACTOR_THREE, - scaler_PalTV3x_16, NULL, expand_pal }, + NULL, scaler_PalTV3x_32, expand_pal }, { "HQ 2x", "hq2x", SCALER_FLAGS_EXPAND, SCALE_FACTOR_TWO, - scaler_HQ2x_16, NULL, expand_1 }, + NULL, scaler_HQ2x_32, expand_1 }, { "HQ 3x", "hq3x", SCALER_FLAGS_EXPAND, SCALE_FACTOR_THREE, - scaler_HQ3x_16, NULL, expand_1 }, + NULL, scaler_HQ3x_32, expand_1 }, }; scaler_type current_scaler = SCALER_NUM; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |