mirror of
https://github.com/libretro/RetroArch
synced 2025-04-09 21:45:45 +00:00
Rewrite rpng_test.c
This commit is contained in:
parent
614dc9039a
commit
e55827a8a6
@ -29,12 +29,8 @@
|
|||||||
#include <Imlib2.h>
|
#include <Imlib2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
static bool test_write_image(const char *path)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_IMLIB2
|
|
||||||
Imlib_Image img;
|
|
||||||
const uint32_t *imlib_data = NULL;
|
|
||||||
#endif
|
|
||||||
const uint32_t test_data[] = {
|
const uint32_t test_data[] = {
|
||||||
0xff000000 | 0x50, 0xff000000 | 0x80,
|
0xff000000 | 0x50, 0xff000000 | 0x80,
|
||||||
0xff000000 | 0x40, 0xff000000 | 0x88,
|
0xff000000 | 0x40, 0xff000000 | 0x88,
|
||||||
@ -45,28 +41,21 @@ int main(int argc, char *argv[])
|
|||||||
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
||||||
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
0xff000000 | 0xc3, 0xff000000 | 0xd3,
|
||||||
};
|
};
|
||||||
uint32_t *data = NULL;
|
|
||||||
|
if (!rpng_save_image_argb(path, test_data, 4, 4, 16))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool test_load_image(const char *path, uint32_t *data)
|
||||||
|
{
|
||||||
unsigned width = 0;
|
unsigned width = 0;
|
||||||
unsigned height = 0;
|
unsigned height = 0;
|
||||||
const char *in_path = "/tmp/test.png";
|
|
||||||
|
|
||||||
if (argc > 2)
|
if (!rpng_load_image_argb(path, &data, &width, &height))
|
||||||
{
|
return false;
|
||||||
fprintf(stderr, "Usage: %s <png file>\n", argv[0]);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc == 2)
|
fprintf(stderr, "Path: %s.\n", path);
|
||||||
in_path = argv[1];
|
|
||||||
|
|
||||||
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);
|
fprintf(stderr, "Got image: %u x %u.\n", width, height);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -80,11 +69,20 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool test_with_imlib(const char *in_path, uint32_t *data)
|
||||||
|
{
|
||||||
#ifdef HAVE_IMLIB2
|
#ifdef HAVE_IMLIB2
|
||||||
|
Imlib_Image img;
|
||||||
|
unsigned width, height;
|
||||||
|
const uint32_t *imlib_data = NULL;
|
||||||
|
|
||||||
/* Validate with imlib2 as well. */
|
/* Validate with imlib2 as well. */
|
||||||
img = imlib_load_image(in_path);
|
img = imlib_load_image(in_path);
|
||||||
if (!img)
|
if (!img)
|
||||||
return 4;
|
return false;
|
||||||
|
|
||||||
imlib_context_set_image(img);
|
imlib_context_set_image(img);
|
||||||
|
|
||||||
@ -102,16 +100,53 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (memcmp(imlib_data, data, width * height * sizeof(uint32_t)) != 0)
|
if (memcmp(imlib_data, &data, width * height * sizeof(uint32_t)) != 0)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Imlib and RPNG differs!\n");
|
fprintf(stderr, "Imlib and RPNG differs!\n");
|
||||||
return 5;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Imlib and RPNG are equivalent!\n");
|
fprintf(stderr, "Imlib and RPNG are equivalent!\n");
|
||||||
|
|
||||||
imlib_free_image();
|
imlib_free_image();
|
||||||
#endif
|
#endif
|
||||||
free(data);
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int test_blocking_rpng(const char *path, uint32_t *data)
|
||||||
|
{
|
||||||
|
if (!test_write_image("/tmp/test.png"))
|
||||||
|
return 1;
|
||||||
|
if (!test_load_image(path, data))
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
#ifdef HAVE_IMLIB2
|
||||||
|
if (!test_with_imlib(path, data))
|
||||||
|
return 5;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
uint32_t *data = NULL;
|
||||||
|
const char *in_path = "/tmp/test.png";
|
||||||
|
|
||||||
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: %s <png file>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
in_path = argv[1];
|
||||||
|
|
||||||
|
ret = test_blocking_rpng(in_path, data);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user