#include "save-png.h" #include "../core/arithmetics.hpp" #include namespace msdfgen { bool savePng(const Bitmap &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++ = clamp(int(bitmap(x, y)*0x100), 0xff); return !lodepng::encode(filename, pixels, bitmap.width(), bitmap.height(), LCT_GREY); } bool savePng(const Bitmap &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++ = clamp(int(bitmap(x, y).r*0x100), 0xff); *it++ = clamp(int(bitmap(x, y).g*0x100), 0xff); *it++ = clamp(int(bitmap(x, y).b*0x100), 0xff); } return !lodepng::encode(filename, pixels, bitmap.width(), bitmap.height(), LCT_RGB); } }