forked from vchukanov/cppimagefilterbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpng_toolkit.cpp
More file actions
46 lines (41 loc) · 1.12 KB
/
png_toolkit.cpp
File metadata and controls
46 lines (41 loc) · 1.12 KB
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
41
42
43
44
45
46
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <array>
#include "stb_image_write.h"
#include "png_toolkit.h"
png_toolkit::png_toolkit()
{
}
png_toolkit::~png_toolkit()
{
stbi_image_free(imgData.pixels);
}
bool png_toolkit::load( const std::string &pictureName )
{
imgData.pixels = stbi_load(pictureName.c_str(), &imgData.w, &imgData.h, &imgData.compPerPixel, 0);
return imgData.pixels != nullptr;
}
bool png_toolkit::save( const std::string &pictureName )
{
return stbi_write_png(pictureName.c_str(),
imgData.w, imgData.h,
imgData.compPerPixel,
imgData.pixels, 0) != 0;
}
image_data png_toolkit::getPixelData( void ) const
{
return imgData;
}
void png_toolkit::paint()
{
auto a = imgData.compPerPixel;
int i, j;
if ((imgData.compPerPixel == 3) || (imgData.compPerPixel == 4))
for (i = (imgData.h) / 2; i < imgData.h; i++)
for (j = 0; j < a * imgData.w; j += a)
{
imgData.pixels[i * imgData.w * a + j] = 255;
imgData.pixels[1 + i * imgData.w * a + j] = 0;
imgData.pixels[2 + i * imgData.w * a + j] = 0;
}
}