-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageBW.cpp
40 lines (36 loc) · 958 Bytes
/
ImageBW.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "ImageBW.h"
namespace phoenix {
#include <iostream>
ImageBW::ImageBW() {
}
void ImageBW::SaveAs(const char* filename) const {
std::string fn = filename;
std::string ext = fn.substr(fn.find_last_of("."));
FIBITMAP *dib;
if (ext == ".png") {
dib = FreeImage_Allocate(Width(), Height(), 24);
if (!dib) {
throw;
}
} else {
throw;
}
for (unsigned int y = 0; y < Height(); y++) {
for (unsigned int x = 0; x < Width(); x++) {
RGBQUAD color;
BW* colorXY = (BW*)(data + y * Width() + x);
color.rgbRed = *colorXY * 255;
color.rgbGreen = *colorXY * 255;
color.rgbBlue = *colorXY * 255;
FreeImage_SetPixelColor(dib, x, y, &color);
}
}
BOOL isSuccess = FreeImage_Save(FIF_PNG, dib, filename);
if (!isSuccess) {
throw;
}
FreeImage_Unload(dib);
}
ImageBW::~ImageBW() {
}
}