/**
* From im, grabs the vertical strip of pixels whose
* upper left corner is at position (column,0), and
* whose width is width.
*/
void Block::build(PNG & im, int column, int width){
int h = im.height();
// first x,then y,copy vertically
for (int i = column; i < column + width; i++) {
vector<HSLAPixel> temp;
for (int j = 0; j < h; j++) {
HSLAPixel* p = im.getPixel(i, j);
temp.push_back(*p);
}
data.push_back(temp);
}
return;
};
m
er as
co
eH w
/**
* Draws the current block at position (column,0) in im.
o.
*/ rs e
void Block::render(PNG & im, int column) const {
ou urc
for (int i = column; i <column + width(); i++) {
for (int j = 0; j < height(); j++) {
HSLAPixel* p = im.getPixel(i, j);
*p = data[i-column][j];
o
}
aC s
}
v i y re
};
/**
* This function changes the saturation of every pixel
* in the block to 0, which removes the color, leaving grey.
ed d
*/
ar stu
void Block::greyscale(){
if (data.empty())
{return;}
for(int i = 0; i < width(); i++){
sh is
for(int j = 0; j < height(); j++){
Th
HSLAPixel * pixel= &data[i][j];
pixel->s=0;
}}
};
/**
* Returns the width of the current block.
*/
int Block::width() const {
return data.size();
};
/**
* Returns the height of the current block.
This study source was downloaded by 100000805705997 from CourseHero.com on 10-15-2021 21:47:45 GMT -05:00
https://www.coursehero.com/file/34808990/blockcpp/