mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
formatspecs, making for much cleaner code. Reformatted everything. This actually happened in multiple steps but then I corrupted my local repository and I had to recover from the working tree.
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include "globals.h"
|
|
#include "flags.h"
|
|
#include "dep/agg/include/agg2d.h"
|
|
#include "dep/stb/stb_image_write.h"
|
|
#include "utils.h"
|
|
#include "bitmap.h"
|
|
#include <regex>
|
|
#include <sstream>
|
|
|
|
Bitmap::Bitmap(const std::string filename, unsigned width, unsigned height):
|
|
filename(filename),
|
|
width(width),
|
|
height(height),
|
|
initialised(true)
|
|
{
|
|
}
|
|
|
|
Agg2D& Bitmap::painter()
|
|
{
|
|
if (!_painter)
|
|
{
|
|
_bitmap.resize(width * height * 4, 255);
|
|
_painter.reset(new Agg2D());
|
|
_painter->attach(&_bitmap[0], width, height, width * 4);
|
|
}
|
|
return *_painter;
|
|
}
|
|
|
|
void Bitmap::save()
|
|
{
|
|
if (endsWith(filename, ".png"))
|
|
stbi_write_png(
|
|
filename.c_str(), width, height, 4, &_bitmap[0], width * 4);
|
|
else if (endsWith(filename, ".bmp"))
|
|
stbi_write_bmp(filename.c_str(), width, height, 4, &_bitmap[0]);
|
|
else if (endsWith(filename, ".tga"))
|
|
stbi_write_tga(filename.c_str(), width, height, 4, &_bitmap[0]);
|
|
else if (endsWith(filename, ".jpg"))
|
|
stbi_write_jpg(filename.c_str(), width, height, 4, &_bitmap[0], 80);
|
|
else
|
|
error("don't know how to write that image format");
|
|
}
|