MCPcopy Create free account
hub / github.com/MyGUI/mygui / pngSave

Function pngSave

MyGUIEngine/src/msdfgen/ext/save-png.cpp:48–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48static bool pngSave(const byte *pixels, int width, int height, int rowStride, int colorType, const char *filename) {
49 if (!(pixels && width && height))
50 return false;
51 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, &pngIgnoreError, &pngIgnoreError);
52 if (!png)
53 return false;
54 png_infop info = png_create_info_struct(png);
55 PngGuard guard(png, info);
56 if (!info)
57 return false;
58 FILE *file = fopen(filename, "wb");
59 if (!file)
60 return false;
61 guard.setFile(file);
62 std::vector<const byte *> rows(height);
63 for (int y = 0; y < height; ++y)
64 rows[y] = pixels+rowStride*y;
65 if (setjmp(png_jmpbuf(png)))
66 return false;
67 png_set_write_fn(png, file, &pngWrite, &pngFlush);
68 png_set_IHDR(png, info, width, height, 8, colorType, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
69 png_set_compression_level(png, 9);
70 png_set_rows(png, info, const_cast<png_bytepp>(&rows[0]));
71 png_write_png(png, info, PNG_TRANSFORM_IDENTITY, NULL);
72 return true;
73}
74
75static bool pngSave(const float *pixels, int width, int height, int rowStride, int channels, int colorType, const char *filename) {
76 if (!(pixels && width && height))

Callers 1

savePngFunction · 0.85

Calls 2

pixelFloatToByteFunction · 0.85
setFileMethod · 0.80

Tested by

no test coverage detected