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
|
|
|
|
|
|
|
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 {
|
|
|
|
int i;
|
|
|
|
char **files = stb_readdir_files("images");
|
|
|
|
for (i=0; i < stb_arr_len(files); ++i) {
|
2014-06-15 21:17:04 +01:00
|
|
|
int n;
|
2014-06-03 16:45:34 +01:00
|
|
|
unsigned char *data;
|
|
|
|
printf("%s\n", files[i]);
|
2014-06-15 21:17:04 +01:00
|
|
|
data = stbi_load(files[i], &w, &h, &n, 4); if (data) free(data); else printf("Failed &n\n");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 1); if (data) free(data); else printf("Failed 1\n");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 2); if (data) free(data); else printf("Failed 2\n");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 3); if (data) free(data); else printf("Failed 3\n");
|
|
|
|
data = stbi_load(files[i], &w, &h, 0, 4);
|
2014-06-03 16:45:34 +01:00
|
|
|
if (data) {
|
|
|
|
char fname[512];
|
|
|
|
stb_splitpath(fname, files[i], STB_FILE);
|
|
|
|
stbi_write_png(stb_sprintf("output/%s.png", fname), w, h, 4, data, w*4);
|
|
|
|
free(data);
|
|
|
|
} else
|
|
|
|
printf("FAILED\n");
|
|
|
|
}
|
|
|
|
}
|
2014-05-28 05:56:42 +01:00
|
|
|
return 0;
|
2014-05-28 19:05:17 +01:00
|
|
|
}
|