-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.cpp
More file actions
71 lines (63 loc) · 1.89 KB
/
block.cpp
File metadata and controls
71 lines (63 loc) · 1.89 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
71
#include "block.h"
/**
* Returns the width of the block.
*/
int Block::width() const{/*your code here*/
return data[0].size();
}
/**
* Returns the height of the block.
*/
int Block::height() const{/*your code here*/
return data.size();
}
/**
* Default Block constructor.
*/
Block::Block() {/* nothing */}
/**
* Useful Block constructor.
* Makes a block from the rectangle of width by height pixels in im
* whose upper-left corner is at position (x,y).
*/
Block::Block(PNG & im, int x, int y, int width, int height) {/*your code here*/
data.resize(height, vector<HSLAPixel>(width));
for(int blocky = 0; blocky < height; blocky++){
for(int blockx = 0; blockx < width; blockx++){
if((blocky+y) >= int(im.height()) || (blockx+x) >= int(im.width())){
cout << "finish build" << endl;
return;
}
data[blocky][blockx] = *(im.getPixel(blockx+x, blocky+y));
}
}
}
/**
* Draws the block at position (x,y) in the image im
*/
void Block::render(PNG & im, int x, int y) const {/*your code here*/
int im_h = im.height();
int im_w = im.width();
for(int blockh = 0; blockh < height(); blockh++){
if (blockh+y >= im_h) return;
for(int blockw = 0; blockw < width(); blockw++){
if (blockw+x >= im_w) return;
/*for(int countCol = x; countCol < sizeOfCol + x; countCol++){*/
(im.getPixel(blockw+x,blockh+y)) -> h = (data[blockh][blockw]).h;
(im.getPixel(blockw+x,blockh+y)) -> s = (data[blockh][blockw]).s;
(im.getPixel(blockw+x,blockh+y)) -> l = (data[blockh][blockw]).l;
(im.getPixel(blockw+x,blockh+y)) -> a = (data[blockh][blockw]).a;
}
}
}
/**
* Changes the saturation of every pixel in the block to 0,
* which removes the color, leaving grey.
*/
void Block::greyscale() {/*your code here*/
for(unsigned int countRow= 0; countRow < data.size(); countRow++){
for(unsigned int countCol = 0; countCol < data[0].size(); countCol++){
data[countRow][countCol].s = 0;
}
}
}