Esempio n. 1
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);

    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;
}
Esempio n. 2
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;
}
Esempio n. 3
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;
}