예제 #1
0
파일: test.c 프로젝트: nabePi/FLIF
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;
}
예제 #2
0
파일: test.c 프로젝트: nawawi/FLIF
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;
}