2014-05-28 05:56:42 +01:00
|
|
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
|
|
#include "stb_image_write.h"
|
|
|
|
|
2014-05-31 12:49:43 +01:00
|
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
|
|
#include "stb_image.h"
|
2014-05-28 05:56:42 +01:00
|
|
|
|
2014-06-03 16:45:34 +01:00
|
|
|
#define STB_DEFINE
|
|
|
|
#include "stb.h"
|
2014-05-28 05:56:42 +01:00
|
|
|
|
2014-12-14 09:43:23 +00:00
|
|
|
#define PNGSUITE_PRIMARY
|
2014-12-14 08:01:50 +00:00
|
|
|
|
2014-05-28 05:56:42 +01:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int w,h;
|
2014-06-03 16:45:34 +01:00
|
|
|
if (argc > 1) {
|
|
|
|
int i;
|
|
|
|
for (i=1; i < argc; ++i) {
|
|
|
|
unsigned char *data;
|
2014-06-15 21:17:04 +01:00
|
|
|
int n;
|
2014-06-03 16:45:34 +01:00
|
|
|
printf("%s\n", argv[i]);
|
2014-06-15 21:17:04 +01:00
|
|
|
data = stbi_load(argv[i], &w, &h, &n, 4); if (data) free(data); else printf("Failed &n\n");
|
|
|
|
data = stbi_load(argv[i], &w, &h, 0, 1); if (data) free(data); else printf("Failed 1\n");
|
|
|
|
data = stbi_load(argv[i], &w, &h, 0, 2); if (data) free(data); else printf("Failed 2\n");
|
|
|
|
data = stbi_load(argv[i], &w, &h, 0, 3); if (data) free(data); else printf("Failed 3\n");
|
|
|
|
data = stbi_load(argv[i], &w, &h, 0, 4);
|
2014-06-03 16:45:34 +01:00
|
|
|
assert(data);
|
|
|
|
if (data) {
|
|
|
|
char fname[512];
|
|
|
|
stb_splitpath(fname, argv[i], STB_FILE);
|
|
|
|
stbi_write_png(stb_sprintf("output/%s.png", fname), w, h, 4, data, w*4);
|
|
|
|
free(data);
|
2014-06-15 21:17:04 +01:00
|
|
|
} else
|
|
|
|
printf("FAILED 4\n");
|
2014-06-03 16:45:34 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-14 08:01:50 +00:00
|
|
|
int i, nope=0;
|
2014-12-14 09:43:23 +00:00
|
|
|
#ifdef PNGSUITE_PRIMARY
|
|
|
|
char **files = stb_readdir_files("pngsuite/primary");
|
2014-12-14 08:01:50 +00:00
|
|
|
#else
|
|
|
|
char **files = stb_readdir_files("images");
|
|
|
|
#endif
|
2014-06-03 16:45:34 +01:00
|
|
|
for (i=0; i < stb_arr_len(files); ++i) {
|
2014-06-15 21:17:04 +01:00
|
|
|
int n;
|
2014-12-14 07:35:55 +00:00
|
|
|
char **failed = NULL;
|
2014-06-03 16:45:34 +01:00
|
|
|
unsigned char *data;
|
2014-12-14 09:43:23 +00:00
|
|
|
printf("%s\n", files[i]);
|
2014-12-14 07:35:55 +00:00
|
|
|
data = stbi_load(files[i], &w, &h, &n, 0); if (data) free(data); else stb_arr_push(failed, "&n");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 1); if (data) free(data); else stb_arr_push(failed, "1");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 2); if (data) free(data); else stb_arr_push(failed, "2");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 3); if (data) free(data); else stb_arr_push(failed, "3");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 4); if (data) ; else stb_arr_push(failed, "4");
|
2014-06-03 16:45:34 +01:00
|
|
|
if (data) {
|
|
|
|
char fname[512];
|
2014-12-14 08:01:50 +00:00
|
|
|
|
2014-12-14 09:43:23 +00:00
|
|
|
#ifdef PNGSUITE_PRIMARY
|
2014-12-14 08:01:50 +00:00
|
|
|
int w2,h2;
|
|
|
|
unsigned char *data2;
|
|
|
|
stb_splitpath(fname, files[i], STB_FILE_EXT);
|
2014-12-14 09:43:23 +00:00
|
|
|
data2 = stbi_load(stb_sprintf("pngsuite/primary_check/%s", fname), &w2, &h2, 0, 4);
|
2014-12-14 08:01:50 +00:00
|
|
|
if (!data2)
|
2014-12-14 09:43:23 +00:00
|
|
|
printf("FAILED: couldn't load 'pngsuite/primary_check/%s\n", fname);
|
2014-12-14 08:01:50 +00:00
|
|
|
else {
|
|
|
|
if (w != w2 || h != w2 || 0 != memcmp(data, data2, w*h*4)) {
|
2014-12-14 09:43:23 +00:00
|
|
|
int x,y,c;
|
|
|
|
if (w == w2 && h == h2)
|
|
|
|
for (y=0; y < h; ++y)
|
|
|
|
for (x=0; x < w; ++x)
|
|
|
|
for (c=0; c < 4; ++c)
|
|
|
|
assert(data[y*w*4+x*4+c] == data2[y*w*4+x*4+c]);
|
|
|
|
printf("FAILED: %s loaded but didn't match PRIMARY_check 32-bit version\n", files[i]);
|
2014-12-14 08:01:50 +00:00
|
|
|
}
|
|
|
|
free(data2);
|
|
|
|
}
|
|
|
|
#else
|
2014-06-03 16:45:34 +01:00
|
|
|
stb_splitpath(fname, files[i], STB_FILE);
|
|
|
|
stbi_write_png(stb_sprintf("output/%s.png", fname), w, h, 4, data, w*4);
|
2014-12-14 08:01:50 +00:00
|
|
|
#endif
|
2014-06-03 16:45:34 +01:00
|
|
|
free(data);
|
2014-12-14 07:35:55 +00:00
|
|
|
}
|
|
|
|
if (failed) {
|
|
|
|
int j;
|
|
|
|
printf("FAILED: ");
|
|
|
|
for (j=0; j < stb_arr_len(failed); ++j)
|
|
|
|
printf("%s ", failed[j]);
|
|
|
|
printf(" -- %s\n", files[i]);
|
|
|
|
}
|
2014-06-03 16:45:34 +01:00
|
|
|
}
|
2014-12-14 08:01:50 +00:00
|
|
|
printf("Tested %d files.\n", i);
|
2014-06-03 16:45:34 +01:00
|
|
|
}
|
2014-05-28 05:56:42 +01:00
|
|
|
return 0;
|
2014-05-28 19:05:17 +01:00
|
|
|
}
|