mirror of
https://github.com/libretro/RetroArch.git
synced 2024-12-13 20:33:22 +00:00
Simplify rpng_test.c
This commit is contained in:
parent
d0651bae82
commit
3914fb9658
@ -31,92 +31,7 @@
|
||||
#include <file/nbio.h>
|
||||
#include <formats/rpng.h>
|
||||
|
||||
enum image_process_code
|
||||
{
|
||||
IMAGE_PROCESS_ERROR = -2,
|
||||
IMAGE_PROCESS_ERROR_END = -1,
|
||||
IMAGE_PROCESS_NEXT = 0,
|
||||
IMAGE_PROCESS_END = 1,
|
||||
};
|
||||
|
||||
static int test_nonblocking_rpng(const char *in_path)
|
||||
{
|
||||
#ifdef HAVE_IMLIB2
|
||||
Imlib_Image img;
|
||||
const uint32_t *imlib_data = NULL;
|
||||
#endif
|
||||
const uint32_t test_data[] = {
|
||||
0xff000000 | 0x50, 0xff000000 | 0x80,
|
||||
0xff000000 | 0x40, 0xff000000 | 0x88,
|
||||
0xff000000 | 0x50, 0xff000000 | 0x80,
|
||||
0xff000000 | 0x40, 0xff000000 | 0x88,
|
||||
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
||||
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
||||
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
||||
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
||||
};
|
||||
uint32_t *data = NULL;
|
||||
unsigned width = 0;
|
||||
unsigned height = 0;
|
||||
|
||||
if (!rpng_save_image_argb("/tmp/test.png", test_data, 4, 4, 16))
|
||||
return 1;
|
||||
|
||||
if (!rpng_load_image_argb(in_path, &data, &width, &height))
|
||||
return 2;
|
||||
|
||||
fprintf(stderr, "Path: %s.\n", in_path);
|
||||
fprintf(stderr, "Got image: %u x %u.\n", width, height);
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "\nRPNG:\n");
|
||||
for (unsigned h = 0; h < height; h++)
|
||||
{
|
||||
unsigned w;
|
||||
for (w = 0; w < width; w++)
|
||||
fprintf(stderr, "[%08x] ", data[h * width + w]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_IMLIB2
|
||||
/* Validate with imlib2 as well. */
|
||||
img = imlib_load_image(in_path);
|
||||
if (!img)
|
||||
return 4;
|
||||
|
||||
imlib_context_set_image(img);
|
||||
|
||||
width = imlib_image_get_width();
|
||||
height = imlib_image_get_width();
|
||||
imlib_data = imlib_image_get_data_for_reading_only();
|
||||
|
||||
#if 0
|
||||
fprintf(stderr, "\nImlib:\n");
|
||||
for (unsigned h = 0; h < height; h++)
|
||||
{
|
||||
for (unsigned w = 0; w < width; w++)
|
||||
fprintf(stderr, "[%08x] ", imlib_data[h * width + w]);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (memcmp(imlib_data, data, width * height * sizeof(uint32_t)) != 0)
|
||||
{
|
||||
fprintf(stderr, "Imlib and RPNG differs!\n");
|
||||
return 5;
|
||||
}
|
||||
else
|
||||
fprintf(stderr, "Imlib and RPNG are equivalent!\n");
|
||||
|
||||
imlib_free_image();
|
||||
#endif
|
||||
free(data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_blocking_rpng(const char *in_path)
|
||||
static int test_rpng(const char *in_path)
|
||||
{
|
||||
#ifdef HAVE_IMLIB2
|
||||
Imlib_Image img;
|
||||
@ -206,15 +121,13 @@ int main(int argc, char *argv[])
|
||||
if (argc == 2)
|
||||
in_path = argv[1];
|
||||
|
||||
fprintf(stderr, "Doing nonblocking tests...\n");
|
||||
fprintf(stderr, "Doing tests...\n");
|
||||
|
||||
if (test_nonblocking_rpng(in_path) != 0)
|
||||
if (test_rpng(in_path) != 0)
|
||||
{
|
||||
fprintf(stderr, "Nonblocking test failed.\n");
|
||||
fprintf(stderr, "Test failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Doing blocking tests...\n");
|
||||
|
||||
return test_blocking_rpng(in_path);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user