1 #define STB_IMAGE_WRITE_IMPLEMENTATION
2 #include "stb_image_write.h"
4 #define STB_IMAGE_IMPLEMENTATION
10 //#define PNGSUITE_PRIMARY
15 STBI_SIMD_ALIGN(unsigned char, y
[256]);
16 STBI_SIMD_ALIGN(unsigned char, cb
[256]);
17 STBI_SIMD_ALIGN(unsigned char, cr
[256]);
18 STBI_SIMD_ALIGN(unsigned char, out1
[256][4]);
19 STBI_SIMD_ALIGN(unsigned char, out2
[256][4]);
22 int count
= 0, bigcount
=0, total
=0;
24 for (i
=0; i
< 256; ++i
) {
25 for (j
=0; j
< 256; ++j
) {
26 for (k
=0; k
< 256; ++k
) {
31 stbi__YCbCr_to_RGB_row(out1
[0], y
, cb
, cr
, 256, 4);
32 stbi__YCbCr_to_RGB_sse2(out2
[0], y
, cb
, cr
, 256, 4);
33 for (k
=0; k
< 256; ++k
) {
34 // inaccurate proxy for values outside of RGB cube
35 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)
38 if (out1
[k
][0] != out2
[k
][0] || out1
[k
][1] != out2
[k
][1] || out1
[k
][2] != out2
[k
][2]) {
39 int dist1
= abs(out1
[k
][0] - out2
[k
][0]);
40 int dist2
= abs(out1
[k
][1] - out2
[k
][1]);
41 int dist3
= abs(out1
[k
][2] - out2
[k
][2]);
43 if (out1
[k
][1] > out2
[k
][1])
48 printf("So far: %d (%d big) of %d\n", count
, bigcount
, total
);
50 printf("Final: %d (%d big) of %d\n", count
, bigcount
, total
);
54 float hdr_data
[200][200][3];
56 void dummy_write(void *context
, void *data
, int len
)
58 static char dummy
[1024];
59 if (len
> 1024) len
= 1024;
60 memcpy(dummy
, data
, len
);
63 int main(int argc
, char **argv
)
70 for (h
=0; h
< 100; h
+= 2)
71 for (w
=0; w
< 200; ++w
)
72 hdr_data
[h
][w
][0] = (float) rand(),
73 hdr_data
[h
][w
][1] = (float) rand(),
74 hdr_data
[h
][w
][2] = (float) rand();
76 stbi_write_hdr("output/test.hdr", 200,200,3,hdr_data
[0][0]);
82 for (i
=1; i
< argc
; ++i
) {
86 printf("%s\n", argv
[i
]);
87 res
= stbi_info(argv
[1], &w2
, &h2
, &n2
);
88 data
= stbi_load(argv
[i
], &w
, &h
, &n
, 4); if (data
) free(data
); else printf("Failed &n\n");
89 data
= stbi_load(argv
[i
], &w
, &h
, 0, 1); if (data
) free(data
); else printf("Failed 1\n");
90 data
= stbi_load(argv
[i
], &w
, &h
, 0, 2); if (data
) free(data
); else printf("Failed 2\n");
91 data
= stbi_load(argv
[i
], &w
, &h
, 0, 3); if (data
) free(data
); else printf("Failed 3\n");
92 data
= stbi_load(argv
[i
], &w
, &h
, &n
, 4);
94 assert(w
== w2
&& h
== h2
&& n
== n2
);
98 stb_splitpath(fname
, argv
[i
], STB_FILE
);
99 stbi_write_png(stb_sprintf("output/%s.png", fname
), w
, h
, 4, data
, w
*4);
100 stbi_write_bmp(stb_sprintf("output/%s.bmp", fname
), w
, h
, 4, data
);
101 stbi_write_tga(stb_sprintf("output/%s.tga", fname
), w
, h
, 4, data
);
102 stbi_write_png_to_func(dummy_write
,0, w
, h
, 4, data
, w
*4);
103 stbi_write_bmp_to_func(dummy_write
,0, w
, h
, 4, data
);
104 stbi_write_tga_to_func(dummy_write
,0, w
, h
, 4, data
);
107 printf("FAILED 4\n");
111 #ifdef PNGSUITE_PRIMARY
112 char **files
= stb_readdir_files("pngsuite/primary");
114 char **files
= stb_readdir_files("images");
116 for (i
=0; i
< stb_arr_len(files
); ++i
) {
118 char **failed
= NULL
;
121 //printf("%s\n", files[i]);
122 data
= stbi_load(files
[i
], &w
, &h
, &n
, 0); if (data
) free(data
); else stb_arr_push(failed
, "&n");
123 data
= stbi_load(files
[i
], &w
, &h
, 0, 1); if (data
) free(data
); else stb_arr_push(failed
, "1");
124 data
= stbi_load(files
[i
], &w
, &h
, 0, 2); if (data
) free(data
); else stb_arr_push(failed
, "2");
125 data
= stbi_load(files
[i
], &w
, &h
, 0, 3); if (data
) free(data
); else stb_arr_push(failed
, "3");
126 data
= stbi_load(files
[i
], &w
, &h
, 0, 4); if (data
) ; else stb_arr_push(failed
, "4");
130 #ifdef PNGSUITE_PRIMARY
132 unsigned char *data2
;
133 stb_splitpath(fname
, files
[i
], STB_FILE_EXT
);
134 data2
= stbi_load(stb_sprintf("pngsuite/primary_check/%s", fname
), &w2
, &h2
, 0, 4);
136 printf("FAILED: couldn't load 'pngsuite/primary_check/%s\n", fname
);
138 if (w
!= w2
|| h
!= w2
|| 0 != memcmp(data
, data2
, w
*h
*4)) {
140 if (w
== w2
&& h
== h2
)
141 for (y
=0; y
< h
; ++y
)
142 for (x
=0; x
< w
; ++x
)
143 for (c
=0; c
< 4; ++c
)
144 assert(data
[y
*w
*4+x
*4+c
] == data2
[y
*w
*4+x
*4+c
]);
145 printf("FAILED: %s loaded but didn't match PRIMARY_check 32-bit version\n", files
[i
]);
150 stb_splitpath(fname
, files
[i
], STB_FILE
);
151 stbi_write_png(stb_sprintf("output/%s.png", fname
), w
, h
, 4, data
, w
*4);
158 for (j
=0; j
< stb_arr_len(failed
); ++j
)
159 printf("%s ", failed
[j
]);
160 printf(" -- %s\n", files
[i
]);
163 printf("Tested %d files.\n", i
);