-
Notifications
You must be signed in to change notification settings - Fork 0
/
RGBAImage.cpp
75 lines (65 loc) · 1.82 KB
/
RGBAImage.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// RGBAImage.cpp: implementation of the CRGBAImage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "pngconv.h"
#include "RGBAImage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#endif
#include <sstream>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CRGBAImage::CRGBAImage(POINT size)
: m_size(size)
, m_image(size.y)
{
// in which to store our image of size (x,y)
if (m_size.x <= 0 || m_size.y <= 0)
{
std::ostringstream except;
except << "(" << m_size.x << "," << m_size.y << ")";
throw CExBadSize(except.str());
}
for (unsigned int i = 0; i < m_size.y; ++i)
m_image[i].resize(m_size.x);
}
CRGBAImage::~CRGBAImage()
{
}
RGBA& CRGBAImage::operator () (unsigned int row, unsigned int col)
{
if (row >= nrows() || col >= ncols())
{
std::ostringstream except;
except << "(" << col << "," << row << ")";
throw CExBoundsViolation(except.str());
}
return m_image[row][col];
}
const RGBA& CRGBAImage::operator () (unsigned int row, unsigned int col) const
{
if (row >= nrows() || col >= ncols())
{
std::ostringstream except;
except << "(" << col << "," << row << ")";
throw CExBoundsViolation(except.str());
}
return m_image[row][col];
}
CRGBAImage::ExtractImageData(const CPngImage &png, POINT origin)
{
// here we want to extract the image data from the PNG
// and put it into our vectors of RGBA.
for (unsigned int yy = 0; yy < nrows(); ++yy)
{
// get a line of data from the PNG image
for (unsigned int xx = 0; xx < ncols(); ++xx)
{
RGBA rgba = png.GetRGBA(xx + origin.x, yy + origin.y);
m_image[yy][xx] = rgba;
}
}
}