-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageMatch.cpp
More file actions
71 lines (61 loc) · 1.86 KB
/
Copy pathImageMatch.cpp
File metadata and controls
71 lines (61 loc) · 1.86 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* ImageMatch.cpp
* xwall
*
* Created by Tim Medcalf on 16/02/2011.
* Copyright 2011 ErgoThis Ltd. All rights reserved.
*
*/
#include "ImageMatch.h"
#include "Global.h"
#include <png.hpp>
#include <math.h>
ImageMatch::ImageMatch()
{
}
ImageMatch::~ImageMatch()
{
}
void ImageMatch::imagefile(string theimagefile)
{
_imagefile = theimagefile;
pngimage.read(_imagefile.c_str());
}
void ImageMatch::Calculate_Ratio_Adjustments(double outputWidth, double outputHeight)
{
x_modifier = pngimage.get_width() / outputWidth;
y_modifier = pngimage.get_height() / outputHeight;
}
color_array ImageMatch::rgb_at_rect(double x, double y, double width, double height)
{
color_array colors;
int pixelcount = 0;
float redcumulative = 0;
float greencumulative = 0;
float bluecumulative = 0;
for (int iy = y; iy < (y + height); iy++)
{
if (roundf(iy * y_modifier) < pngimage.get_height())
{
//cout << "asking image for y pixel " << roundf(iy * y_modifier) << endl;
for (int ix = x; ix < (x + width); ix++)
{
//if ((roundf(iy * y_modifier) > pngimage.get_height()) || (roundf(iy * y_modifier) < 1))
// {
//cout << "asking image for y pixel " << roundf(iy * y_modifier) << endl;
//}
if (roundf(ix * x_modifier) < pngimage.get_width())
{
redcumulative += pngimage[roundf(iy * y_modifier)][roundf(ix * x_modifier)].red;
greencumulative += pngimage[roundf(iy * y_modifier)][roundf(ix * x_modifier)].green;
bluecumulative += pngimage[roundf(iy * y_modifier)][roundf(ix * x_modifier)].blue;
pixelcount++;
}
}
}
}
colors.r = (redcumulative / (double)pixelcount) / 255.0f;
colors.g = (greencumulative / (double)pixelcount) / 255.0f;
colors.b = (bluecumulative / (double)pixelcount) / 255.0f;
return colors;
}