/* RetroArch - A frontend for libretro. * Copyright (C) 2010-2013 - Hans-Kristian Arntzen * * RetroArch is free software: you can redistribute it and/or modify it under the terms * of the GNU General Public License as published by the Free Software Found- * ation, either version 3 of the License, or (at your option) any later version. * * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with RetroArch. * If not, see . */ #include "rpng.h" #include #include #include #include #include int main(int argc, char *argv[]) { if (argc > 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } const char *in_path = argc == 2 ? argv[1] : "/tmp/test.png"; 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, }; if (!rpng_save_image_argb("/tmp/test.png", test_data, 4, 4, 16)) return 1; uint32_t *data = NULL; unsigned width = 0; unsigned height = 0; if (!rpng_load_image_argb(in_path, &data, &width, &height)) return 2; fprintf(stderr, "Got image: %u x %u.\n", width, height); fprintf(stderr, "\nRPNG:\n"); for (unsigned h = 0; h < height; h++) { for (unsigned w = 0; w < width; w++) fprintf(stderr, "[%08x] ", data[h * width + w]); fprintf(stderr, "\n"); } if (width != 4 || height != 4) return 3; // Validate with imlib2 as well. Imlib_Image 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(); const uint32_t *imlib_data = imlib_image_get_data_for_reading_only(); 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"); } imlib_free_image(); if (memcmp(test_data, data, sizeof(test_data)) != 0) return 5; free(data); }