-
Notifications
You must be signed in to change notification settings - Fork 0
/
tileimage.h
54 lines (47 loc) · 1.41 KB
/
tileimage.h
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
/**
* tileimage.h (v2)
* Definition of the TileImage class.
*/
#ifndef TILEIMAGE_H
#define TILEIMAGE_H
#include <math.h>
#include <stdint.h>
#include "cs225/PNG.h"
#include "cs225/HSLAPixel.h"
using namespace cs225;
/**
* Represents a Tile in the Photomosaic.
*/
class TileImage {
private:
PNG image_;
PNG resized_;
HSLAPixel averageColor_;
public:
TileImage();
explicit TileImage(const PNG& theImage);
HSLAPixel getAverageColor() const { return averageColor_; }
int getResolution() const { return image_.width(); }
void paste(PNG& canvas, int startX, int startY, int resolution);
private:
void generateResizedImage(int startX, int startY, int resolution);
static PNG cropSourceImage(const PNG& source);
HSLAPixel calculateAverageColor() const;
HSLAPixel getScaledPixelDouble(double startX, double endX,
double startY, double endY) const;
HSLAPixel getScaledPixelInt(int startX, int endX,
int startY, int endY) const;
static uint64_t divide(uint64_t a, uint64_t b) {
return (a + b / 2) / b;
}
static int divide(int a, int b) {
return divide(static_cast<uint64_t>(a), static_cast<uint64_t>(b));
}
static int fdivide(double a, double b) {
return a / b + 0.5;
}
static double frac(double x) {
return x - floor(x);
}
};
#endif // TILEIMAGE_H