int main(int argc, char **argv) { if (argc < 2 || argc > 2) { printf("Usage: %s image.flif\n",argv[0]); return 0; } SDL_Init(SDL_INIT_VIDEO); SDL_EventState(SDL_MOUSEMOTION,SDL_IGNORE); window = SDL_CreateWindow("FLIF Viewer -- Loading...", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200, 200, SDL_WINDOW_RESIZABLE); renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_SetRenderDrawColor(renderer, 127, 127, 127, 255); // background color (in case aspect ratio of window doesn't match image) SDL_RenderClear(renderer); SDL_RenderPresent(renderer); if (SDL_GetWindowDisplayMode(window,&dm)) { printf("Error: SDL_GetWindowDisplayMode\n"); return 1; } int result = 0; #ifdef PROGRESSIVE_DECODING printf("Decoding progressively...\n"); SDL_Thread *decode_thread = SDL_CreateThread(decodeThread,"Decode_FLIF",argv); if (!decode_thread) { printf("Error: failed to create decode thread\n"); return 1; } #else printf("Decoding entire image...\n"); result = decodeThread(argv); #endif SDL_Event e; unsigned int current_time; unsigned int begin=SDL_GetTicks(); while (!quit) { if (nb_frames > 1) { current_time = SDL_GetTicks(); draw_image(); int time_passed = SDL_GetTicks()-current_time; int time_to_wait = frame_delay[frame] - time_passed; if (time_to_wait>0) SDL_Delay(time_to_wait); // todo: if the animation has extremely long frame delays, this makes the viewer unresponsive frame++; frame %= nb_frames; } else { SDL_Delay(200); // if it's not an animation, check event queue 5 times per second } while (SDL_PollEvent(&e)) do_event(e); } if (nb_frames > 1) printf("Rendered %i frames in %.2f seconds, %.4f frames per second\n", framecount, 0.001*(SDL_GetTicks()-begin), 1000.0*framecount/(SDL_GetTicks()-begin)); #ifdef PROGRESSIVE_DECODING // make sure the decoding gets properly aborted (in case it was not done yet) while(flif_abort_decoder(d)) SDL_Delay(100); SDL_WaitThread(decode_thread, &result); #endif SDL_DestroyWindow(window); SDL_Quit(); return result; }
int main(int argc, char **argv) { if (argc < 2 || argc > 2) { printf("Usage: %s image.flif\n",argv[0]); return 0; } d = flif_create_decoder(); if (!d) return 1; SDL_Init(SDL_INIT_VIDEO); window = SDL_CreateWindow("FLIF Viewer", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 200, 200, 0); flif_decoder_set_quality(d, 100); // this is the default flif_decoder_set_scale(d, 1); // this is the default #ifdef PROGRESSIVE_DECODING flif_decoder_set_callback(d, &(progressive_render)); flif_decoder_set_first_callback_quality(d, 500); // do the first callback when at least 5.00% quality has been decoded printf("Decoding progressively...\n"); SDL_Thread *decode_thread = SDL_CreateThread(decodeThread,"Decode_FLIF",argv); if (!decode_thread) { printf("Error: failed to create decode thread\n"); return 1; } #else printf("Decoding entire image...\n"); decodeThread(argv); progressive_render(10000,-1); #endif SDL_Event e; int result = 0; while (!quit) { draw_image(); if (animation) { SDL_Delay(frame_delay[frame]); frame++; frame %= flif_decoder_num_images(d); } else { SDL_WaitEvent(&e); if (!do_event(e)) break; SDL_Delay(100); } while (SDL_PollEvent(&e)) if (!do_event(e)) break; } #ifdef PROGRESSIVE_DECODING while(flif_abort_decoder(d)) SDL_Delay(100); SDL_WaitThread(decode_thread, &result); #endif flif_destroy_decoder(d); SDL_DestroyWindow(window); SDL_Quit(); return result; }