Skip to content
Myr

image_write_test.c

This file

Path

tests/image_write_test.c

60 lines · 1.8 KiB · C

Last changed by

Merge branch 'master' into workingSean Barrettbefore adoptiond940053

History of this file

Take it

1#ifdef __clang__2#define STBIWDEF static inline3#endif4#define STB_IMAGE_WRITE_STATIC5#define STB_IMAGE_WRITE_IMPLEMENTATION6#include "stb_image_write.h"78// using an 'F' since it has no rotational symmetries, and 6x59// because it's a small, atypical size likely to trigger edge cases.10//11// conveniently, it's also small enough to fully fit inside a typical12// directory listing thumbnail, which simplifies checking at a glance.13static const char img6x5_template[] =14   ".****."15   ".*...."16   ".***.."17   ".*...."18   ".*....";1920void image_write_test(void)21{22   // make a RGB version of the template image23   // use red on blue to detect R<->B swaps24   unsigned char img6x5_rgb[6*5*3];25   float img6x5_rgbf[6*5*3];26   int i;2728   for (i = 0; i < 6*5; i++) {29      int on = img6x5_template[i] == '*';30      img6x5_rgb[i*3 + 0] = on ? 255 : 0;31      img6x5_rgb[i*3 + 1] = 0;32      img6x5_rgb[i*3 + 2] = on ? 0 : 255;3334      img6x5_rgbf[i*3 + 0] = on ? 1.0f : 0.0f;35      img6x5_rgbf[i*3 + 1] = 0.0f;36      img6x5_rgbf[i*3 + 2] = on ? 0.0f : 1.0f;37   }3839   stbi_write_png("output/wr6x5_regular.png", 6, 5, 3, img6x5_rgb, 6*3);40   stbi_write_bmp("output/wr6x5_regular.bmp", 6, 5, 3, img6x5_rgb);41   stbi_write_tga("output/wr6x5_regular.tga", 6, 5, 3, img6x5_rgb);42   stbi_write_jpg("output/wr6x5_regular.jpg", 6, 5, 3, img6x5_rgb, 95);43   stbi_write_hdr("output/wr6x5_regular.hdr", 6, 5, 3, img6x5_rgbf);4445   stbi_flip_vertically_on_write(1);4647   stbi_write_png("output/wr6x5_flip.png", 6, 5, 3, img6x5_rgb, 6*3);48   stbi_write_bmp("output/wr6x5_flip.bmp", 6, 5, 3, img6x5_rgb);49   stbi_write_tga("output/wr6x5_flip.tga", 6, 5, 3, img6x5_rgb);50   stbi_write_jpg("output/wr6x5_flip.jpg", 6, 5, 3, img6x5_rgb, 95);51   stbi_write_hdr("output/wr6x5_flip.hdr", 6, 5, 3, img6x5_rgbf);52}5354#ifdef IWT_TEST55int main(int argc, char **argv)56{57   image_write_test();58   return 0;59}60#endif