int main( int argc, char *argv[] ) { FILE *fbmp; struct contest_data_t *bmp; if ( argc < 2 ) { printf("Usage: %s pic [dir]\n", argv[ 0 ] ); return 1; } else { /* args ok */ fbmp = fopen( argv[ 1 ], "r" ); if ( !fbmp ) { printf( "Can't open '%s'!\n", argv[ 1 ] ); return 2; } else { /* open ok */ bmp = bmpread_read( fbmp ); fclose( fbmp ); if ( bmp ) { if ( argc >= 3 ) { contest( bmp, argv[ 2 ] ); } /* have res dir? */ bmpread_free( bmp ); } /* read ok? */ } /* open ok? */ } /* args ok? */ return 0; }
void contest_produce( const char * const fdir ) { struct contest_producer_t *prod; struct contest_data_t *bmp; char fname[ PATH_MAX + 1 ]; int step; int r; prod = produce_data_init(); if ( prod ) { produce_data_read( prod, "algo" ); r = produce_data_validate( prod ); if ( r ) { bmp = produce_image_create(); produce_image_fill( prod, bmp ); bmpread_save( bmp, fdir, "50_initial", bmp->result_color ); for ( step = 1; step <= 9; step++ ) { produce_copy( prod ); produce_calculate( prod ); produce_image_fill( prod, bmp ); snprintf( fname, PATH_MAX, "5%d_step%d", step, step ); bmpread_save( bmp, fdir, fname, bmp->result_color ); } /* 7 steps */ bmpread_free( bmp ); } /* check ok? */ } /* alloc ok? */ }
int main(int argc, char * argv[]) { bmpread_t bmp; puts("Test utility for libbmpread"); puts("Copyright (C) 2005, 2012 Charles Lindsay <*****@*****.**>"); puts(""); if(argc < 2) { puts("Usage: test <bmpfile> [glut_options]"); puts("Loads <bmpfile> and attempts to display it on an OpenGL quad, stretched across"); puts("the entire window, using GLUT. If the bitmap looks correct, libbmpread works"); puts("correctly! You can pass options to GLUT using [glut_options]."); return 0; } printf("Loading %s...", argv[1]); if(!bmpread(argv[1], 0, &bmp)) { puts("error!"); return 1; } puts("OK"); glutInitWindowSize(bmp.width, bmp.height); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow(argv[1]); glutDisplayFunc(DrawBitmap); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-0.5f, 0.5f, -0.5f, 0.5f, 0.1f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_TEXTURE_2D); glGenTextures(1, &tex); glBindTexture(GL_TEXTURE_2D, tex); glTexImage2D(GL_TEXTURE_2D, 0, 3, bmp.width, bmp.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bmp.rgb_data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); bmpread_free(&bmp); glutPostRedisplay(); glutMainLoop(); return 0; }