#include "save-png.h" #include #include #include "../core/pixel-conversion.hpp" namespace msdfgen { bool savePng(const BitmapConstRef &bitmap, const char *filename) { std::vector pixels(bitmap.width*bitmap.height); for (int y = 0; y < bitmap.height; ++y) memcpy(&pixels[bitmap.width*y], bitmap(0, bitmap.height-y-1), bitmap.width); return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_GREY); } bool savePng(const BitmapConstRef &bitmap, const char *filename) { std::vector pixels(3*bitmap.width*bitmap.height); for (int y = 0; y < bitmap.height; ++y) memcpy(&pixels[3*bitmap.width*y], bitmap(0, bitmap.height-y-1), 3*bitmap.width); return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGB); } bool savePng(const BitmapConstRef &bitmap, const char *filename) { std::vector pixels(4*bitmap.width*bitmap.height); for (int y = 0; y < bitmap.height; ++y) memcpy(&pixels[4*bitmap.width*y], bitmap(0, bitmap.height-y-1), 4*bitmap.width); return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGBA); } bool savePng(const BitmapConstRef &bitmap, const char *filename) { std::vector pixels(bitmap.width*bitmap.height); std::vector::iterator it = pixels.begin(); for (int y = bitmap.height-1; y >= 0; --y) for (int x = 0; x < bitmap.width; ++x) *it++ = pixelFloatToByte(*bitmap(x, y)); return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_GREY); } bool savePng(const BitmapConstRef &bitmap, const char *filename) { std::vector pixels(3*bitmap.width*bitmap.height); std::vector::iterator it = pixels.begin(); for (int y = bitmap.height-1; y >= 0; --y) for (int x = 0; x < bitmap.width; ++x) { *it++ = pixelFloatToByte(bitmap(x, y)[0]); *it++ = pixelFloatToByte(bitmap(x, y)[1]); *it++ = pixelFloatToByte(bitmap(x, y)[2]); } return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGB); } bool savePng(const BitmapConstRef &bitmap, const char *filename) { std::vector pixels(4*bitmap.width*bitmap.height); std::vector::iterator it = pixels.begin(); for (int y = bitmap.height-1; y >= 0; --y) for (int x = 0; x < bitmap.width; ++x) { *it++ = pixelFloatToByte(bitmap(x, y)[0]); *it++ = pixelFloatToByte(bitmap(x, y)[1]); *it++ = pixelFloatToByte(bitmap(x, y)[2]); *it++ = pixelFloatToByte(bitmap(x, y)[3]); } return !lodepng::encode(filename, pixels, bitmap.width, bitmap.height, LCT_RGBA); } }