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); flif_decoder_set_quality(d, 100); flif_decoder_set_scale(d, 1); flif_decoder_set_callback(d, &(progressive_render)); printf("Decoding...\n"); if (flif_decoder_decode_file(d, argv[1]) == 0) { printf("Error: decoding failed\n"); return 1; } if (!quit) { printf("Done.\n"); SDL_Event e; while (1) { SDL_WaitEvent(&e); if (!do_event(e)) break; } } flif_destroy_decoder(d); SDL_DestroyWindow(window); SDL_Quit(); return 0; }
// When decoding progressively, this is a separate thread (so a partially loaded animation keeps playing while decoding more detail) static int decodeThread(void * arg) { char ** argv = (char **)arg; d = flif_create_decoder(); if (!d) return 1; // set the quality to 100% (a lower value will decode a lower-quality preview) flif_decoder_set_quality(d, 100); // this is the default, so can be omitted // set the scale-down factor to 1 (a higher value will decode a downsampled preview) flif_decoder_set_scale(d, 1); // this is the default, so can be omitted // set the maximum size to twice the screen resolution; if an image is larger, a downsampled preview will be decoded flif_decoder_set_resize(d, dm.w*2, dm.h*2); // the default is to not have a maximum size #ifdef PROGRESSIVE_DECODING // set the callback function to render the partial (and final) decoded images flif_decoder_set_callback(d, &(progressive_render)); // the default is "no callback"; decode completely until quality/scale/size target is reached // do the first callback when at least 5.00% quality has been decoded flif_decoder_set_first_callback_quality(d, 500); // the default is to callback almost immediately #endif if (!flif_decoder_decode_file(d, argv[1])) { printf("Error: decoding failed\n"); quit = 1; flif_destroy_decoder(d); return 1; } #ifndef PROGRESSIVE_DECODING // no callback was set, so we manually call our callback function to render the final image/frames progressive_render(10000,-1); #endif flif_destroy_decoder(d); return 0; }
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; }
int main() { int result = 0; const size_t WIDTH = 256; const size_t HEIGHT = 256; const char* dummy_file = "testFiles/dummy.flif"; FLIF_IMAGE* im = flif_create_image(WIDTH, HEIGHT); if(im == 0) { printf("Error: flif_create_image failed\n"); result = 1; } else { fill_dummy_image(im); void* blob = 0; size_t blob_size = 0; FLIF_ENCODER* e = flif_create_encoder(); if(e) { flif_encoder_set_interlaced(e, 1); flif_encoder_set_learn_repeat(e, 3); flif_encoder_set_auto_color_buckets(e, 1); flif_encoder_set_frame_delay(e, 100); flif_encoder_set_palette_size(e, 512); flif_encoder_set_lookback(e, 1); flif_encoder_add_image(e, im); if(!flif_encoder_encode_file(e, dummy_file)) { printf("Error: encoding file failed\n"); result = 1; } if(!flif_encoder_encode_memory(e, &blob, &blob_size)) { printf("Error: encoding blob failed\n"); result = 1; } // TODO: uncommenting this causes subsequent test to fail??? /*if(!compare_file_and_blob(blob, blob_size, dummy_file)) { result = 1; }*/ flif_destroy_encoder(e); e = 0; } FLIF_DECODER* d = flif_create_decoder(); if(d) { flif_decoder_set_quality(d, 100); flif_decoder_set_scale(d, 1); { if(!flif_decoder_decode_file(d, dummy_file)) { printf("Error: decoding file failed\n"); result = 1; } FLIF_IMAGE* decoded = flif_decoder_get_image(d, 0); if(decoded == 0) { printf("Error: No decoded image found\n"); result = 1; } else if(compare_images(im, decoded) != 0) { result = 1; } } { if(!flif_decoder_decode_memory(d, blob, blob_size)) { printf("Error: decoding memory failed\n"); result = 1; } FLIF_IMAGE* decoded = flif_decoder_get_image(d, 0); if(decoded == 0) { printf("Error: No decoded image found\n"); result = 1; } else if(compare_images(im, decoded) != 0) { result = 1; } } flif_destroy_decoder(d); d = 0; } flif_destroy_image(im); im = 0; if(blob) { flif_free_memory(blob); blob = 0; } } printf("interface test has succeeded.\n"); return result; }
int main(int argc, char** argv) { if (argc < 2) { printf("first argument must be a file path for the test image"); return 1; } int result = 0; const size_t WIDTH = 256; const size_t HEIGHT = 256; const char* dummy_file = argv[1]; FLIF_IMAGE* im = flif_create_image(WIDTH, HEIGHT); if(im == 0) { printf("Error: flif_create_image failed\n"); result = 1; } else { fill_dummy_image(im); void* blob = 0; size_t blob_size = 0; FLIF_ENCODER* e = flif_create_encoder(); if(e) { flif_encoder_set_interlaced(e, 1); flif_encoder_set_learn_repeat(e, 3); flif_encoder_set_auto_color_buckets(e, 1); flif_encoder_set_palette_size(e, 512); flif_encoder_set_lookback(e, 1); flif_encoder_add_image(e, im); if(!flif_encoder_encode_file(e, dummy_file)) { printf("Error: encoding file failed\n"); result = 1; } flif_destroy_encoder(e); e = 0; } e = flif_create_encoder(); if(e) { flif_encoder_set_interlaced(e, 1); flif_encoder_set_learn_repeat(e, 3); flif_encoder_set_auto_color_buckets(e, 1); flif_encoder_set_palette_size(e, 512); flif_encoder_set_lookback(e, 1); flif_encoder_add_image(e, im); if(!flif_encoder_encode_memory(e, &blob, &blob_size)) { printf("Error: encoding blob failed\n"); result = 1; } // TODO: uncommenting this causes subsequent test to fail??? /*if(!compare_file_and_blob(blob, blob_size, dummy_file)) { result = 1; }*/ flif_destroy_encoder(e); e = 0; } FLIF_DECODER* d = flif_create_decoder(); if(d) { flif_decoder_set_quality(d, 100); flif_decoder_set_scale(d, 1); { if(!flif_decoder_decode_file(d, dummy_file)) { printf("Error: decoding file failed\n"); result = 1; } FLIF_IMAGE* decoded = flif_decoder_get_image(d, 0); if(decoded == 0) { printf("Error: No decoded image found\n"); result = 1; } else if(compare_images(im, decoded) != 0) { result = 1; } } { if(!flif_decoder_decode_memory(d, blob, blob_size)) { printf("Error: decoding memory failed\n"); result = 1; } FLIF_IMAGE* decoded = flif_decoder_get_image(d, 0); if(decoded == 0) { printf("Error: No decoded image found\n"); result = 1; } else if(compare_images(im, decoded) != 0) { result = 1; } } flif_destroy_decoder(d); d = 0; } FLIF_INFO* info = flif_read_info_from_memory(blob, blob_size); if(info) { int w = flif_info_get_width(info); int h = flif_info_get_height(info); int channels = flif_info_get_nb_channels(info); int depth = flif_info_get_depth(info); int n = flif_info_num_images(info); if(w != WIDTH || h != HEIGHT || channels != 4 || depth != 8 || n != 1) { printf("Error: info should be %dx%d, %d channels, %d bit, %d images.\n" " Instead it is %dx%d, %d channels, %d bit, %d images.\n", WIDTH, HEIGHT, 4, 8, 1, w, h, channels, depth, n); result = 1; } flif_destroy_info(info); info = 0; } else { printf("Error: flif_read_info_from_memory failed\n"); result = 1; } flif_destroy_image(im); im = 0; if(blob) { flif_free_memory(blob); blob = 0; } } if (result) printf("interface test has FAILED.\n"); else printf("interface test has succeeded.\n"); return result; }