Skip to content
Myr

tests: Add simple image_write_test smoke test

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Fabian Giesen · committed by Fabian Giesen · parent 980add9 · Browse files · 2 files+53 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+53 added−0 removed

  • tests:+53 added−0 removed

2 files+53 added−0 removed

added:tests/image_write_test.c+50 added
1#define STB_IMAGE_WRITE_IMPLEMENTATION2#include "stb_image_write.h"34// using an 'F' since it has no rotational symmetries, and 6x55// because it's a small, atypical size likely to trigger edge cases.6//7// conveniently, it's also small enough to fully fit inside a typical8// directory listing thumbnail, which simplifies checking at a glance.9static const char img6x5_template[] =10 ".****."11 ".*...."12 ".***.."13 ".*...."14 ".*....";1516int main(int argc, char **argv)17{18 // make a RGB version of the template image19 // use red on blue to detect R<->B swaps20 unsigned char img6x5_rgb[6*5*3];21 float img6x5_rgbf[6*5*3];22 int i;2324 for (i = 0; i < 6*5; i++) {25 int on = img6x5_template[i] == '*';26 img6x5_rgb[i*3 + 0] = on ? 255 : 0;27 img6x5_rgb[i*3 + 1] = 0;28 img6x5_rgb[i*3 + 2] = on ? 0 : 255;2930 img6x5_rgbf[i*3 + 0] = on ? 1.0f : 0.0f;31 img6x5_rgbf[i*3 + 1] = 0.0f;32 img6x5_rgbf[i*3 + 2] = on ? 0.0f : 1.0f;33 }3435 stbi_write_png("wr6x5_regular.png", 6, 5, 3, img6x5_rgb, 6*3);36 stbi_write_bmp("wr6x5_regular.bmp", 6, 5, 3, img6x5_rgb);37 stbi_write_tga("wr6x5_regular.tga", 6, 5, 3, img6x5_rgb);38 stbi_write_jpg("wr6x5_regular.jpg", 6, 5, 3, img6x5_rgb, 95);39 stbi_write_hdr("wr6x5_regular.hdr", 6, 5, 3, img6x5_rgbf);4041 stbi_flip_vertically_on_write(1);4243 stbi_write_png("wr6x5_flip.png", 6, 5, 3, img6x5_rgb, 6*3);44 stbi_write_bmp("wr6x5_flip.bmp", 6, 5, 3, img6x5_rgb);45 stbi_write_tga("wr6x5_flip.tga", 6, 5, 3, img6x5_rgb);46 stbi_write_jpg("wr6x5_flip.jpg", 6, 5, 3, img6x5_rgb, 95);47 stbi_write_hdr("wr6x5_flip.hdr", 6, 5, 3, img6x5_rgbf);4849 return 0;50}
modified:tests/Makefile+3 added
1INCLUDES = -I..2CFLAGS = -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -DSTB_DIVIDE_TEST3CPPFLAGS = -Wno-write-strings -DSTB_DIVIDE_TEST45#CFLAGS += -O -fsanitize=address67all:8 $(CC) $(INCLUDES) $(CFLAGS) ../stb_vorbis.c test_c_compilation.c test_c_lexer.c test_dxt.c test_easyfont.c test_image.c test_image_write.c test_perlin.c test_sprintf.c test_truetype.c test_voxel.c -lm9 $(CC) $(INCLUDES) $(CPPFLAGS) test_cpp_compilation.cpp -lm -lstdc++10 $(CC) $(INCLUDES) $(CFLAGS) image_write_test.c -lm -o image_write_test