// a test program that converts a tga image between // parameterizable color formats int main( char inNumArgs, char **inArgs ) { if( inNumArgs != 5 ) { usage( inArgs[0] ); } Image *inImage = loadTGAImage( inArgs[1] ); Image *outImage; // convert inImage to outImage based on the color space strings if( !strcmp( inArgs[3], "rgb" ) ) { if( !strcmp( inArgs[4], "yiq" ) ) { outImage = ImageColorConverter::RGBToYIQ( inImage ); } if( !strcmp( inArgs[4], "ycbcr" ) ) { outImage = ImageColorConverter::RGBToYCbCr( inImage ); } } if( !strcmp( inArgs[3], "yiq" ) ) { if( !strcmp( inArgs[4], "rgb" ) ) { outImage = ImageColorConverter::YIQToRGB( inImage ); } if( !strcmp( inArgs[4], "ycbcr" ) ) { Image *tempImage = ImageColorConverter::YIQToRGB( inImage ); outImage = ImageColorConverter::RGBToYCbCr( tempImage ); delete tempImage; } } if( !strcmp( inArgs[3], "ycbcr" ) ) { if( !strcmp( inArgs[4], "rgb" ) ) { outImage = ImageColorConverter::YCbCrToRGB( inImage ); } if( !strcmp( inArgs[4], "yiq" ) ) { Image *tempImage = ImageColorConverter::YCbCrToRGB( inImage ); outImage = ImageColorConverter::RGBToYIQ( tempImage ); delete tempImage; } } writeTGAImage( inArgs[2], outImage ); delete inImage; delete outImage; return 0; }
int main() { createWindow(640, 480); int framecnt = 0; Image* img = loadTGAImage("cat.tga"); if(img == NULL) { printf("ERROR: Could not open image file\n"); exit(1); } Image* font = loadTGAImage("font.tga"); if(font == NULL) { printf("ERROR: Could not load font file\n"); exit(1); } int mousePos[2] = {0, 0}; while(1) { KeyEvent ev; profileBlockStart("eventHandling"); while(pollEvent(&ev)) { switch(ev.type) { case KEY_DOWN: printf("Keycode: %d\n", ev.key); if(ev.key == 53) { goto endGame; } break; case MOUSE_MOVE: mousePos[0] = ev.posx; mousePos[1] = ev.posy; break; } } profileBlockEnd("eventHandling"); Image* fb = getFramebuffer(); profileBlockStart("clearFramebuffer"); Color backColor = color(0, 30, 140, 40); clear(fb, &backColor); profileBlockEnd("clearFramebuffer"); profileBlockStart("paintCats"); for(int i = 0; i < 300; i++) { paint(PAINT_OVER, img, fb, (int)(fb->width / 2 + (i * 0.7) * sin(i * 1.221 + framecnt * 0.004)), (int)(fb->height / 2 + (i * 0.7) * cos(i * 1.221 + framecnt * 0.004))); } profileBlockEnd("paintCats"); profileBlockStart("paintText"); Color textColor = color(255, 200, 250, 255); textColor.a = (framecnt * 32) % 256; drawText(fb, font, &textColor, "Hello world!", mousePos[0], mousePos[1]); drawButton(fb, font, "Click here!", 120, 200); profileBlockEnd("paintText"); profileBlockStart("flush"); flushFramebuffer(); profileBlockEnd("flush"); framecnt++; } endGame: saveProfile("_profile.json"); deleteImage(img); closeWindow(); }