2019-02-07 16:55:03 +03:00
|
|
|
#define STBI_WINDOWS_UTF8
|
|
|
|
|
2014-05-28 08:56:42 +04:00
|
|
|
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
|
|
|
#include "stb_image_write.h"
|
|
|
|
|
2014-05-31 15:49:43 +04:00
|
|
|
#define STB_IMAGE_IMPLEMENTATION
|
|
|
|
#include "stb_image.h"
|
2014-05-28 08:56:42 +04:00
|
|
|
|
2014-06-03 19:45:34 +04:00
|
|
|
#define STB_DEFINE
|
|
|
|
#include "stb.h"
|
2014-05-28 08:56:42 +04:00
|
|
|
|
2015-11-08 12:22:30 +03:00
|
|
|
//#define PNGSUITE_PRIMARY
|
2014-12-14 11:01:50 +03:00
|
|
|
|
2014-12-20 16:13:25 +03:00
|
|
|
#if 0
|
2014-12-19 15:39:04 +03:00
|
|
|
void test_ycbcr(void)
|
|
|
|
{
|
|
|
|
STBI_SIMD_ALIGN(unsigned char, y[256]);
|
|
|
|
STBI_SIMD_ALIGN(unsigned char, cb[256]);
|
|
|
|
STBI_SIMD_ALIGN(unsigned char, cr[256]);
|
|
|
|
STBI_SIMD_ALIGN(unsigned char, out1[256][4]);
|
|
|
|
STBI_SIMD_ALIGN(unsigned char, out2[256][4]);
|
|
|
|
|
|
|
|
int i,j,k;
|
2014-12-23 16:11:36 +03:00
|
|
|
int count = 0, bigcount=0, total=0;
|
2014-12-19 15:39:04 +03:00
|
|
|
|
|
|
|
for (i=0; i < 256; ++i) {
|
|
|
|
for (j=0; j < 256; ++j) {
|
|
|
|
for (k=0; k < 256; ++k) {
|
2014-12-23 16:11:36 +03:00
|
|
|
y [k] = k;
|
2014-12-19 15:39:04 +03:00
|
|
|
cb[k] = j;
|
|
|
|
cr[k] = i;
|
|
|
|
}
|
2014-12-20 16:13:25 +03:00
|
|
|
stbi__YCbCr_to_RGB_row(out1[0], y, cb, cr, 256, 4);
|
|
|
|
stbi__YCbCr_to_RGB_sse2(out2[0], y, cb, cr, 256, 4);
|
2014-12-19 15:39:04 +03:00
|
|
|
for (k=0; k < 256; ++k) {
|
2014-12-23 16:11:36 +03:00
|
|
|
// inaccurate proxy for values outside of RGB cube
|
|
|
|
if (out1[k][0] == 0 || out1[k][1] == 0 || out1[k][2] == 0 || out1[k][0] == 255 || out1[k][1] == 255 || out1[k][2] == 255)
|
|
|
|
continue;
|
|
|
|
++total;
|
2014-12-19 15:39:04 +03:00
|
|
|
if (out1[k][0] != out2[k][0] || out1[k][1] != out2[k][1] || out1[k][2] != out2[k][2]) {
|
|
|
|
int dist1 = abs(out1[k][0] - out2[k][0]);
|
|
|
|
int dist2 = abs(out1[k][1] - out2[k][1]);
|
|
|
|
int dist3 = abs(out1[k][2] - out2[k][2]);
|
|
|
|
++count;
|
2014-12-20 16:13:25 +03:00
|
|
|
if (out1[k][1] > out2[k][1])
|
2014-12-19 15:39:04 +03:00
|
|
|
++bigcount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 16:11:36 +03:00
|
|
|
printf("So far: %d (%d big) of %d\n", count, bigcount, total);
|
2014-12-19 15:39:04 +03:00
|
|
|
}
|
2014-12-23 16:11:36 +03:00
|
|
|
printf("Final: %d (%d big) of %d\n", count, bigcount, total);
|
2014-12-19 15:39:04 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-18 21:43:42 +03:00
|
|
|
float hdr_data[200][200][3];
|
|
|
|
|
2015-09-14 15:57:42 +03:00
|
|
|
void dummy_write(void *context, void *data, int len)
|
2015-09-14 15:48:24 +03:00
|
|
|
{
|
|
|
|
static char dummy[1024];
|
|
|
|
if (len > 1024) len = 1024;
|
|
|
|
memcpy(dummy, data, len);
|
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:27 +03:00
|
|
|
extern void image_write_test(void);
|
|
|
|
|
2014-05-28 08:56:42 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int w,h;
|
2014-12-20 16:13:25 +03:00
|
|
|
//test_ycbcr();
|
2015-01-18 21:43:42 +03:00
|
|
|
|
2019-02-25 22:17:27 +03:00
|
|
|
image_write_test();
|
|
|
|
|
2015-11-08 12:22:30 +03:00
|
|
|
#if 0
|
2015-01-18 21:43:42 +03:00
|
|
|
// test hdr asserts
|
|
|
|
for (h=0; h < 100; h += 2)
|
|
|
|
for (w=0; w < 200; ++w)
|
|
|
|
hdr_data[h][w][0] = (float) rand(),
|
|
|
|
hdr_data[h][w][1] = (float) rand(),
|
|
|
|
hdr_data[h][w][2] = (float) rand();
|
|
|
|
|
|
|
|
stbi_write_hdr("output/test.hdr", 200,200,3,hdr_data[0][0]);
|
|
|
|
#endif
|
|
|
|
|
2014-06-03 19:45:34 +04:00
|
|
|
if (argc > 1) {
|
2014-12-21 18:53:05 +03:00
|
|
|
int i, n;
|
|
|
|
|
2014-06-03 19:45:34 +04:00
|
|
|
for (i=1; i < argc; ++i) {
|
2015-09-13 15:41:21 +03:00
|
|
|
int res;
|
2015-11-09 00:09:16 +03:00
|
|
|
int w2,h2,n2;
|
2014-06-03 19:45:34 +04:00
|
|
|
unsigned char *data;
|
|
|
|
printf("%s\n", argv[i]);
|
2019-02-07 15:42:32 +03:00
|
|
|
res = stbi_info(argv[i], &w2, &h2, &n2);
|
2014-06-16 00:17:04 +04: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");
|
2015-11-09 00:09:16 +03:00
|
|
|
data = stbi_load(argv[i], &w, &h, &n, 4);
|
2014-06-03 19:45:34 +04:00
|
|
|
assert(data);
|
2015-11-09 00:09:16 +03:00
|
|
|
assert(w == w2 && h == h2 && n == n2);
|
2015-09-13 15:41:21 +03:00
|
|
|
assert(res);
|
2014-06-03 19:45:34 +04:00
|
|
|
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);
|
2015-09-14 15:48:24 +03:00
|
|
|
stbi_write_bmp(stb_sprintf("output/%s.bmp", fname), w, h, 4, data);
|
|
|
|
stbi_write_tga(stb_sprintf("output/%s.tga", fname), w, h, 4, data);
|
2015-09-14 15:57:42 +03:00
|
|
|
stbi_write_png_to_func(dummy_write,0, w, h, 4, data, w*4);
|
|
|
|
stbi_write_bmp_to_func(dummy_write,0, w, h, 4, data);
|
|
|
|
stbi_write_tga_to_func(dummy_write,0, w, h, 4, data);
|
2014-06-03 19:45:34 +04:00
|
|
|
free(data);
|
2014-06-16 00:17:04 +04:00
|
|
|
} else
|
|
|
|
printf("FAILED 4\n");
|
2014-06-03 19:45:34 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-12-14 11:01:50 +03:00
|
|
|
int i, nope=0;
|
2014-12-14 12:43:23 +03:00
|
|
|
#ifdef PNGSUITE_PRIMARY
|
|
|
|
char **files = stb_readdir_files("pngsuite/primary");
|
2014-12-14 11:01:50 +03:00
|
|
|
#else
|
|
|
|
char **files = stb_readdir_files("images");
|
|
|
|
#endif
|
2014-06-03 19:45:34 +04:00
|
|
|
for (i=0; i < stb_arr_len(files); ++i) {
|
2014-06-16 00:17:04 +04:00
|
|
|
int n;
|
2014-12-14 10:35:55 +03:00
|
|
|
char **failed = NULL;
|
2014-06-03 19:45:34 +04:00
|
|
|
unsigned char *data;
|
2014-12-14 12:57:22 +03:00
|
|
|
printf(".");
|
|
|
|
//printf("%s\n", files[i]);
|
2014-12-14 10:35:55 +03: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 19:45:34 +04:00
|
|
|
if (data) {
|
|
|
|
char fname[512];
|
2014-12-14 11:01:50 +03:00
|
|
|
|
2014-12-14 12:43:23 +03:00
|
|
|
#ifdef PNGSUITE_PRIMARY
|
2014-12-14 11:01:50 +03:00
|
|
|
int w2,h2;
|
|
|
|
unsigned char *data2;
|
|
|
|
stb_splitpath(fname, files[i], STB_FILE_EXT);
|
2014-12-14 12:43:23 +03:00
|
|
|
data2 = stbi_load(stb_sprintf("pngsuite/primary_check/%s", fname), &w2, &h2, 0, 4);
|
2014-12-14 11:01:50 +03:00
|
|
|
if (!data2)
|
2014-12-14 12:43:23 +03:00
|
|
|
printf("FAILED: couldn't load 'pngsuite/primary_check/%s\n", fname);
|
2014-12-14 11:01:50 +03:00
|
|
|
else {
|
|
|
|
if (w != w2 || h != w2 || 0 != memcmp(data, data2, w*h*4)) {
|
2014-12-14 12:43:23 +03: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 11:01:50 +03:00
|
|
|
}
|
|
|
|
free(data2);
|
|
|
|
}
|
|
|
|
#else
|
2014-06-03 19:45:34 +04: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 11:01:50 +03:00
|
|
|
#endif
|
2014-06-03 19:45:34 +04:00
|
|
|
free(data);
|
2014-12-14 10:35:55 +03: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 19:45:34 +04:00
|
|
|
}
|
2014-12-14 11:01:50 +03:00
|
|
|
printf("Tested %d files.\n", i);
|
2014-06-03 19:45:34 +04:00
|
|
|
}
|
2014-05-28 08:56:42 +04:00
|
|
|
return 0;
|
2014-05-28 22:05:17 +04:00
|
|
|
}
|