int InitImage( PSENTIENT ps, PENTITY pe, PTEXT parameters ) { INDEX idx; for( idx = 0; idx < NUM_IMAGE_VARS; idx++ ) { PTEXT saveparms = parameters; PTEXT arg; Image parent = GetLink( &FindContainer( pe )->pPlugin, iImage ); arg = GetParam( ps, ¶meters ); if( IsNumber( arg ) ) { PTEXT arg2 = GetParam( ps, ¶meters ); if( IsNumber( arg2 ) ) { Image image; if( parent ) image = MakeSubImage( parent , 0, 0 // need other 2 arguments. , atoi( GetText( arg ) ) , atoi( GetText( arg2 ) ) ); else image = MakeImageFile( atoi( GetText( arg ) ) , atoi( GetText( arg2 ) ) ); SetLink( &pe->pPlugin, iImage, image ); if( ps->CurrentMacro ) ps->CurrentMacro->state.flags.bSuccess = TRUE; else { DECLTEXT( msg, "Invalid second parameter, expecting a number" ); EnqueLink( &ps->Command->Output, &msg ); } // if more args - warn? } } else { Image image; // expect that the remainder is a name.. parameters = saveparms; arg = GetFileName( ps, ¶meters ); // loaded image file doesn't care for parent status... image = LoadImageFile( GetText( arg ) ); if( image ) { SetLink( &pe->pPlugin, iImage, image ); if( ps->CurrentMacro ) ps->CurrentMacro->state.flags.bSuccess = TRUE; else { DECLTEXT( msg, "Failed to load image..." ); EnqueLink( &ps->Command->Output, &msg ); } } } AddVolatileVariable( pe, ImageVars + idx, 0 ); { int n; for( n = 0; n < NUM_METHODS; n++ ) AddMethod( pe, ImageMethods + n ); } } return 0; // return success }
int main( void ) { uint32_t width, height; uint32_t imagecount = 0; uint32_t testimagesatinitialization = 0; Image blank; srand( time( NULL ) ); for(width=0; width< NUM_REELS; width++) { g.uiSpeedCounter[width] = 0; g.uiSpeedStep[width] = 2; g.idx[width]= 0; } g.pdi = GetDisplayInterface(); g.pii = GetImageInterface(); //SetSystemLog( SYSLOG_FILE, stdout ); SetSystemLoggingLevel( 1000 + LOG_NOISE); GetDisplaySize( &width, &height );; g.render = OpenDisplaySizedAt( 0, width, height, 0, 0 ); UpdateDisplay(g.render); g.surface = GetDisplayImage( g.render ); SetMouseHandler( g.render, MouseMethod, 0 ); // blank = LoadImageFile( WIDE("blankimage.jpg")); blank = MakeImageFile(96,96); ClearImageTo( blank, BASE_COLOR_CYAN ); g.playagain=LoadImageFile( WIDE("%images%/playagain.jpg")); g.playing =LoadImageFile( WIDE("%images%/playing.jpg")); g.background = LoadImageFile( WIDE("%images%/background.jpg") ); // g.background = blank; g.strip = LoadImageFile( WIDE("%images%/slot_strip.jpg") ); g.nReels = NUM_REELS; { Image icons[NUM_ICONS]; int n, m; INDEX idx; for( n = 0; n < NUM_ICONS; n++ ) { icons[n] = MakeSubImage( g.strip, 96 * n, 0, 96, 96 ); } n = width = imagecount = height = 0; while(imagecount < NUM_IMAGES ) { idx = rand()%NUM_ICONS; g.images[imagecount] = icons[idx]; if( testimagesatinitialization ) { BlotImage( g.surface, g.images[imagecount], width * 96, height * 96 ); width++; if(!( width % 8 )) { width=0; height++; } } imagecount++; for( m = 0; m < (( rand()%2 ) ); m++) { g.images[imagecount] = blank; if( testimagesatinitialization ) { BlotImage( g.surface, g.images[imagecount], width * 96, height * 96 ); width++; if(!( width % 8 )) { width=0; height++; } } imagecount++; } if( testimagesatinitialization ) { SyncRender( g.render); UpdateDisplay(g.render); } } if( !testimagesatinitialization ) { SyncRender( g.render); UpdateDisplay(g.render); } for( n = 0; n < NUM_BLURS; n++ ) { g.blurs[n] = MakeImageFile( 96, (NUM_PICS) * 96 ); g.dodges[n] = MakeImageFile( 96, (NUM_PICS) * 96 ); for( m = 0; m < NUM_IMAGES; m++ ) { idx = rand()%NUM_IMAGES; g.reel[0][m] = g.images[idx]; } Blur( g.blurs[n], g.reel[0] ); DodgeEx( g.dodges[n], g.reel[0] , 2); } for( n = 0; n < NUM_REELS; n++) { g.subsurface[n] = MakeSubImage( g.surface , REEL_OFSX + REEL_STEPX * n , REEL_OFSY , REEL_WIDTH, (96 * NUM_PICS_IN_WINDOW) ); g.testsurface[n] = MakeSubImage( g.surface, REEL_OFSX + REEL_STEPX * n + 480, REEL_OFSY , REEL_WIDTH, (96 * NUM_PICS) ); } g.statussurface = MakeSubImage( g.surface , 490, 10 , 140, 68 ); g.backgroundsurface = MakeSubImage( g.surface , 0, 0 , 640, 460 ); } g.flags.bBackgroundInitialized = 0; ThreadTo( ReadInput, 0 ); { uint32_t start = GetTickCount(); xlprintf(LOG_NOISE)("Started at %lu" , start); g.ofs = 0; while( 1 ) { if( g.flags.bSpinning ) { DrawSpinningReels(FALSE); } #ifndef __ARM__ // scale to approx unit speeds.. WakeableSleep( 250 ); //WakeableSleep( 33); #endif } } CloseDisplay( g.render ); UnmakeImageFile( g.strip ); return 0; }
Image ImageJpgFile (uint8_t * buf, uint32_t size) { ImageFile *Image; struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; int row_stride; /* physical row width in output buffer */ JSAMPARRAY buffer; int bufp; int i; // RGBcolor *out; /* ==== Step 1: allocate and initialize JPEG decompression object */ /* We set up the normal JPEG error routines, then override error_exit. */ cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if (setjmp(jerr.setjmp_buffer)) { jpeg_destroy_decompress(&cinfo); return NULL; } /* Now we can initialize the JPEG decompression object. */ jpeg_create_decompress (&cinfo); /* ==== Step 2: specify data source (memory buffer, in this case) */ jpeg_memory_src (&cinfo, (char *)buf, size); /* ==== Step 3: read file parameters with jpeg_read_header() */ (void) jpeg_read_header(&cinfo, TRUE); /* ==== Step 4: set parameters for decompression */ // We want max quality, doesnt matter too much it can be a bit slow // We almost always want RGB output (no grayscale, yuv etc) if (cinfo.jpeg_color_space != JCS_GRAYSCALE) cinfo.out_color_space = JCS_RGB; // Recalculate output image dimensions jpeg_calc_output_dimensions (&cinfo); /* ==== Step 5: Start decompressor */ (void) jpeg_start_decompress (&cinfo); /* We may need to do some setup of our own at this point before reading * the data. After jpeg_start_decompress() we have the correct scaled * output image dimensions available, as well as the output colormap * if we asked for color quantization. * In this example, we need to make an output work buffer of the right size. */ Image = MakeImageFile(cinfo.output_width, cinfo.output_height); /* JSAMPLEs per row in output buffer */ row_stride = cinfo.output_width * cinfo.output_components; /* Make a one-row-high sample array that will go away when done with image */ buffer = (*cinfo.mem->alloc_sarray) ((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, cinfo.output_height); // read into the buffer upside down... for( i = 0; i < Image->height; i++ ) { if( Image->flags & IF_FLAG_INVERTED ) buffer[i] = (JSAMPROW)(Image->image + ( ( (Image->height - i) - 1 ) * Image->width )); else buffer[i] = (JSAMPROW)(Image->image + ( i * Image->width )); } /* ==== Step 6: while (scan lines remain to be read) */ /* jpeg_read_scanlines(...); */ /* Here we use the library's state variable cinfo.output_scanline as the * loop counter, so that we don't have to keep track ourselves. */ bufp = 0; while (cinfo.output_scanline < cinfo.output_height) jpeg_read_scanlines( &cinfo, buffer + cinfo.output_scanline, cinfo.image_height ); /* blah! we're in 32 bit color space - and this reads * into 24 bit space - WHY oh WHY is that... ahh well * we need to update this */ for( i = 0; i < Image->height; i++ ) { int j; char *row; row = (char*)buffer[i]; for( j = Image->width; j > 0; j-- ) { row[j * 4 - 1] = (uint8_t)0xff; if( bGLColorMode ) { row[j * 4 - 2] = row[j*3-1]; row[j * 4 - 3] = row[j*3-2]; row[j * 4 - 4] = row[j*3-3]; } else { row[j * 4 - 2] = row[j*3-3]; row[j * 4 - 3] = row[j*3-2]; row[j * 4 - 4] = row[j*3-1]; } } } /* ==== Step 7: Finish decompression */ (void) jpeg_finish_decompress(&cinfo); /* We can ignore the return value since suspension is not possible * with the buffer data source. */ /* ==== Step 8: Release JPEG decompression object */ /* This is an important step since it will release a good deal of memory. */ jpeg_destroy_decompress(&cinfo); /* At this point you may want to check to see whether any corrupt-data * warnings occurred (test whether jerr.pub.num_warnings is nonzero). */ /* And we're done! */ return Image; }
void Render( PRENDERER r, int output ) { int a,b; Image surface = GetDisplayImage( r ); RCOORD aspect; if( !output_surface ) output_surface = MakeImageFile( surface->width, surface->height ); aspect = (RCOORD)output_surface->width / (RCOORD)output_surface->height; ofsx = (output_surface->width/2); ofsy = (output_surface->height/2); dx = display_scale*4.0 / (RCOORD)output_surface->width; dy = display_scale*4.0 / (RCOORD)output_surface->height; if( !drawn ) { drawn = 1; ClearImage( output_surface); _ii1_max_iter = 0; _ii2_max_iter = 0; { RCOORD dam, dbm; dam = ( mx - ofsx ) * dx + xorg; dbm = ( my - ofsy ) * dy + yorg; for( a = 0; a < output_surface->width; a++ ) { for( b = 0; b < output_surface->height; b++ ) { RCOORD da, db; RCOORD rda, rdb; int r, g = 0, bl = 0; int direction; //rda = ( ( b *2 ) / (RCOORD)output_surface->height) * sin(3.14159/2 + ( ( a * 2*3.14159 ) / (RCOORD)output_surface->width)); //rdb = ( ( b *2 ) / (RCOORD)output_surface->height) * cos(3.14159/2 + ( ( a * 2*3.14159 ) / (RCOORD)output_surface->width)); //da = ( rda ) + xorg; //db = ( rdb ) + yorg; da = aspect * ( a - ofsx ) * dx + xorg; db = ( b - ofsy ) * dy + yorg; //if( (r = IsInfinite( dam, dbm, da, db )) == -1 ) r = 0; /* // draw just in range of the cursor if( !( ( (mx - a) > -20) && ( (mx-a) < 20 ) && ( (my - b) > -20 ) && ( (my - b) < 20 ) ) ) { continue; } */ //if( (g = IsInfinite2( dam, dbm, da, db )) == -1 ) // g = 0; bl = IsInfinite2( 0, 0, da, db, &direction ); if( (direction) < 0 ) { r = ( -bl ); bl = 0; } else if( bl < 0 ) { g = 32; bl = 0; //r = 0; } else if( bl != 0 ) { //r = 0; bl = bl; } //else // r = 0; if( g == 255 ) { int a = 3; } { // point pair horiz -0.123 (R) 0.35071355833500363833634934966131 // 0.422(I) 0.64961527075646859365525325998975 // // point pair vert -0.563(R) 0.75033325929216279143681201481957 0(I) /*distance to next 0.49986672471039669667784846697923*/ // point pair vert -1.563(R) 1.2501999840025594881146604817988 0(I) /* to next 0.1125178884860932415243100526011 */ // next is -1.857 (R) 1.3627178724886527296389705343999 0(I) RCOORD unity = da*da + db*db; RCOORD offset_unity = (da+0.123)*(da+0.123) + db*db; if( unity < 0.564 && unity >= 0.562 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_WHITE, 64, 256 ) ); else if( offset_unity < 0.422 && offset_unity >= 0.420 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_WHITE, 64, 256 ) ); else if( unity < 1.001 && unity >= 0.999 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_WHITE, 138, 256 ) ); else if( unity < 1.564 && unity >= 1.562 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_WHITE, 64, 256 ) ); else if( unity < 1.868 && unity >= 1.866 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_WHITE, 64, 256 ) ); else if( da >= -0.125 && da <= -0.122 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_BLUE, 64, 256 ) ); else if( da >= -0.001 && da <= 0.001 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_GREEN, 64, 256 ) ); else if( db >= -0.001 && db <= 0.001 ) plot( output_surface, a, b, ColorAverage( Color(r,g,bl), BASE_COLOR_ORANGE, 64, 256 ) ); else plot( output_surface, a, b, Color(r,g,bl) ); } } } } ii1_max_iter = _ii1_max_iter; ii2_max_iter = _ii1_max_iter; if( output ) { // actually put the changes on the screen.... PutString( output_surface, 10, 10, BASE_COLOR_WHITE, BASE_COLOR_BLACK, "Alt+TAB and select application,\nThen Press ALT+F4 to Exit. " ); } } BlotImage( surface, output_surface, 0, 0 ); { { RCOORD dam, dbm; dam = ( mx - ofsx ) * dx + xorg; dbm = ( my - ofsy ) * dy + yorg; for( a = -20; a <= 20; a++ ) { for( b = -20; b <= 20; b++ ) { RCOORD da, db; int r, g = 0, bl = 0; int direction; float v1[3]; float v2[3]; da = aspect * ( mx + a - ofsx ) * dx + xorg; db = ( my + b - ofsy ) * dy + yorg; r = 0; bl = IsInfinite2( 0, 0, da, db, &direction ); if( (direction) < 0 ) { v1[vForward] = bl * 0.05; r = ( bl ); bl = 0; } else if( bl < 0 ) { v1[vForward] = 0.5; g = 32; bl = 0; //r = 0; } else if( bl != 0 ) { v1[vForward] = bl * 0.04; //r = 0; bl = bl; } //else // r = 0; if( g == 255 ) { int a = 3; } glBegin( GL_LINES ); v2[vRight] = v1[vRight] = ( mx + a ) * 0.1; v2[vUp] = v1[vUp] = ( my + b ) * 0.1; v2[vForward] = 0; glColor4ub( r*0xFF,g,bl,255 ); glVertex3fv( v1 ); glVertex3fv( v2 ); glEnd(); //plot( output_surface, a, b, Color(r,g,bl) ); } } } } { RCOORD da, db; int r, g, bl = 0; int iter; da = aspect * ( mx - ofsx ) * dx + xorg; db = ( my - ofsy ) * dy + yorg; //iter = DrawInfinite2( output_surface, 0, 0, da, db, dx, dy, ofsx, ofsy ); iter = GLDrawInfinite2( output_surface, 0, 0, da, db, dx, dy, ofsx, ofsy ); if( 0 ) { TEXTCHAR buf[256]; snprintf( buf,256, "%d %d,%d = %g, %g", iter, mx, my, da, db ); PutString( output_surface, 10, 50, BASE_COLOR_WHITE, BASE_COLOR_BLACK, buf ); } } }