X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=qoiconv.c;h=366e92c0e5fc797b9a36e264e34dd673ab359eb4;hb=aa435c13e7184bcd2034b8af1b20db1063baf9ec;hp=610f2b18d5dc376c844bac841e313969a5368931;hpb=72e9a469a490e537f2e12464c1b075eb8991a868;p=fishladder.git diff --git a/qoiconv.c b/qoiconv.c index 610f2b1..366e92c 100644 --- a/qoiconv.c +++ b/qoiconv.c @@ -38,7 +38,7 @@ SOFTWARE. #include "stb/stb_image.h" //#define STB_IMAGE_WRITE_IMPLEMENTATION -//#include "stb/stb_image_write.h" +//#include "stb_image_write.h" #define QOI_IMPLEMENTATION #include "phoboslab/qoi.h" @@ -48,23 +48,26 @@ SOFTWARE. int main(int argc, char **argv) { if (argc < 3) { - printf("Usage: qoiconv infile outfile\n"); + printf("Usage: qoiconv \n"); printf("Examples:\n"); - printf(" qoiconv image.png image.qoi\n"); - printf(" qoiconv image.qoi image.png\n"); + printf(" qoiconv input.png output.qoi\n"); + printf(" qoiconv input.qoi output.png\n"); exit(1); } stbi_set_flip_vertically_on_load(1); - + void *pixels = NULL; - int w, h; + int w, h, channels; if (STR_ENDS_WITH(argv[1], ".png")) { - - pixels = (void *)stbi_load(argv[1], &w, &h, NULL, 4); + pixels = (void *)stbi_load(argv[1], &w, &h, &channels, 4); } else if (STR_ENDS_WITH(argv[1], ".qoi")) { - pixels = qoi_read(argv[1], &w, &h, 4); + qoi_desc desc; + pixels = qoi_read(argv[1], &desc, 0); + channels = desc.channels; + w = desc.width; + h = desc.height; } if (pixels == NULL) { @@ -74,10 +77,15 @@ int main(int argc, char **argv) { int encoded = 0; if (STR_ENDS_WITH(argv[2], ".png")) { - //encoded = stbi_write_png(argv[2], w, h, 4, pixels, 0); + //encoded = stbi_write_png(argv[2], w, h, channels, pixels, 0); } else if (STR_ENDS_WITH(argv[2], ".qoi")) { - encoded = qoi_write(argv[2], pixels, w, h, 4); + encoded = qoi_write(argv[2], pixels, &(qoi_desc){ + .width = w, + .height = h, + .channels = 4, + .colorspace = QOI_SRGB + }); } if (!encoded) { @@ -85,5 +93,6 @@ int main(int argc, char **argv) { exit(1); } + free(pixels); return 0; }