Переход на PixelArray
This commit is contained in:
parent
a1e42a0c28
commit
63b0d22340
3 changed files with 171 additions and 156 deletions
133
bmpimage.cpp
133
bmpimage.cpp
|
@ -1,6 +1,6 @@
|
|||
#include "bmpimage.h"
|
||||
|
||||
BMPImage::BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, PixelArray pixelArray)
|
||||
BMPImage::BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, const PixelArray &pixelArray)
|
||||
: pixelArray(pixelArray) {
|
||||
this->fileHeader = fileHeader;
|
||||
this->infoHeader = infoHeader;
|
||||
|
@ -21,24 +21,28 @@ void BMPImage::save(const std::string &filename) {
|
|||
ofs.write((char *) &this->fileHeader, sizeof(this->fileHeader));
|
||||
ofs.write((char *) &this->infoHeader, sizeof(this->infoHeader));
|
||||
uint32_t byteByRow = this->infoHeader.BitmapWidth * 3;
|
||||
uint8_t padding = 4 - byteByRow % 4;
|
||||
for (int i = this->infoHeader.BitmapHeight - 1; i > -1; --i) {
|
||||
uint8_t padding = (4 - byteByRow % 4) % 4;
|
||||
for (auto i = (int) this->infoHeader.BitmapHeight - 1; i > -1; --i) {
|
||||
ofs.write((char *) pixelArray(i), byteByRow);
|
||||
if (padding != 4) ofs.write(PADDING_ZEROES, padding); // Write padding
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const PixelArray BMPImage::pixels() {
|
||||
PixelArray BMPImage::pixels() {
|
||||
return this->pixelArray;
|
||||
}
|
||||
|
||||
Pixel **BMPImage::pixels_copy() {
|
||||
Pixel **newPixelArray;
|
||||
newPixelArray = new Pixel *[this->infoHeader.BitmapHeight];
|
||||
PixelArray BMPImage::pixels_copy() {
|
||||
// Pixel **newPixelArray;
|
||||
PixelArray newPixelArray(this->infoHeader.BitmapWidth, this->infoHeader.BitmapHeight);
|
||||
// newPixelArray = new Pixel *[this->infoHeader.BitmapHeight];
|
||||
for (int i = 0; i < this->infoHeader.BitmapHeight; ++i) {
|
||||
newPixelArray[i] = new Pixel[this->infoHeader.BitmapWidth];
|
||||
std::copy(this->pixelArray(i), this->pixelArray(i) + this->infoHeader.BitmapWidth, newPixelArray[i]);
|
||||
// newPixelArray[i] = new Pixel[this->infoHeader.BitmapWidth];
|
||||
// std::copy(this->pixelArray(i), this->pixelArray(i) + this->infoHeader.BitmapWidth, newPixelArray(i)); // TODO
|
||||
for (int j = 0; j < this->infoHeader.BitmapWidth; ++j) {
|
||||
newPixelArray(i, j) = this->pixelArray(i, j);
|
||||
}
|
||||
}
|
||||
return newPixelArray;
|
||||
}
|
||||
|
@ -59,21 +63,21 @@ BMPImage::~BMPImage() {
|
|||
// delete[] this->pixelArray;
|
||||
}
|
||||
|
||||
BMPImage::BMPImage(PixelArray pixelArray): pixelArray(pixelArray) {
|
||||
BMPImage::BMPImage(const PixelArray &pixelArray) : pixelArray(pixelArray) {
|
||||
uint32_t width = pixelArray.width();
|
||||
uint32_t height = pixelArray.height();
|
||||
BitmapFileHeader fileHeader;
|
||||
BITMAPINFOHEADER infoHeader;
|
||||
infoHeader.BitmapWidth = width;
|
||||
infoHeader.BitmapHeight = height;
|
||||
infoHeader.ImageSize = width * height * 3 + ((4 - width % 4) % 4) * height;
|
||||
fileHeader.fileSize = infoHeader.ImageSize + fileHeader.imageDataOffset;
|
||||
this->infoHeader = infoHeader;
|
||||
this->fileHeader = fileHeader;
|
||||
BitmapFileHeader _fileHeader;
|
||||
BITMAPINFOHEADER _infoHeader;
|
||||
_infoHeader.BitmapWidth = width;
|
||||
_infoHeader.BitmapHeight = height;
|
||||
_infoHeader.ImageSize = width * height * 3 + ((4 - (width * 3) % 4) % 4) * height;
|
||||
_fileHeader.fileSize = _infoHeader.ImageSize + _fileHeader.imageDataOffset;
|
||||
this->infoHeader = _infoHeader;
|
||||
this->fileHeader = _fileHeader;
|
||||
// this->pixelArray = pixelArray;
|
||||
}
|
||||
|
||||
BMPImage *BMPImage::appendRight(const BMPImage &img) {
|
||||
BMPImage BMPImage::appendRight(BMPImage &img) {
|
||||
uint32_t newHeight = std::max(this->infoHeader.BitmapHeight, img.height());
|
||||
uint32_t newWidth = this->infoHeader.BitmapWidth + img.width();
|
||||
// Pixel **newPixelArray;
|
||||
|
@ -87,14 +91,14 @@ BMPImage *BMPImage::appendRight(const BMPImage &img) {
|
|||
std::copy(img.pixels()(i), img.pixelArray(i) + img.width(), newPixelArray(i) + this->infoHeader.BitmapWidth);
|
||||
}
|
||||
|
||||
return new BMPImage(newPixelArray);
|
||||
return {newPixelArray};
|
||||
}
|
||||
|
||||
|
||||
BMPImage readBMPImage(const std::string &filename) {
|
||||
BitmapFileHeader bitmapFileHeader;
|
||||
BITMAPINFOHEADER bitmapInfoHeader;
|
||||
Pixel **pixelArray;
|
||||
// Pixel **pixelArray;
|
||||
uint32_t DIB_Header_Size;
|
||||
{
|
||||
std::ifstream ifs(filename, std::ios_base::binary);
|
||||
|
@ -116,7 +120,8 @@ BMPImage readBMPImage(const std::string &filename) {
|
|||
ifs.seekg(14, std::ios::beg);
|
||||
ifs.read((char *) &bitmapInfoHeader, sizeof(bitmapInfoHeader));
|
||||
}
|
||||
pixelArray = new Pixel *[bitmapInfoHeader.BitmapHeight];
|
||||
PixelArray pixelArray = PixelArray(bitmapInfoHeader.BitmapWidth, bitmapInfoHeader.BitmapHeight);
|
||||
// pixelArray = new Pixel *[bitmapInfoHeader.BitmapHeight];
|
||||
{
|
||||
std::ifstream ifs(filename, std::ios_base::binary);
|
||||
if (!ifs.good()) {
|
||||
|
@ -124,10 +129,10 @@ BMPImage readBMPImage(const std::string &filename) {
|
|||
}
|
||||
ifs.seekg(bitmapFileHeader.imageDataOffset, std::ios::beg);
|
||||
uint32_t byteByRow = bitmapInfoHeader.BitmapWidth * 3;
|
||||
uint8_t padding = 4 - byteByRow % 4;
|
||||
for (int i = bitmapInfoHeader.BitmapHeight - 1; i > -1; --i) {
|
||||
pixelArray[i] = new Pixel[bitmapInfoHeader.BitmapWidth];
|
||||
ifs.read((char *) pixelArray[i], byteByRow);
|
||||
uint8_t padding = (4 - byteByRow % 4) % 4;
|
||||
for (auto i = (int) bitmapInfoHeader.BitmapHeight - 1; i > -1; --i) {
|
||||
// pixelArray(i) = new Pixel[bitmapInfoHeader.BitmapWidth];
|
||||
ifs.read((char *) pixelArray(i), byteByRow);
|
||||
if (padding != 4) ifs.seekg(padding, std::ios_base::cur); // Skip padding
|
||||
}
|
||||
}
|
||||
|
@ -152,11 +157,11 @@ BMPImage grayscale(BMPImage &img) {
|
|||
auto pixels = img.pixels_copy();
|
||||
for (int i = 0; i < img.height(); ++i) {
|
||||
for (int j = 0; j < img.width(); ++j) {
|
||||
uint8_t gray = pixels[i][j].r / 3 + pixels[i][j].g / 3 + pixels[i][j].b / 3;
|
||||
pixels[i][j] = {gray, gray, gray};
|
||||
uint8_t gray = pixels(i, j).r / 3 + pixels(i, j).g / 3 + pixels(i, j).b / 3;
|
||||
pixels(i, j) = {gray, gray, gray};
|
||||
}
|
||||
}
|
||||
return BMPImage(img.fileHeader_copy(), img.infoHeader_copy(), pixels);
|
||||
return {img.fileHeader_copy(), img.infoHeader_copy(), pixels};
|
||||
}
|
||||
|
||||
Pixel operator*(const Pixel &p, const int &n) {
|
||||
|
@ -180,10 +185,10 @@ BMPImage invertColors(BMPImage &img) {
|
|||
auto pixels = img.pixels_copy();
|
||||
for (int i = 0; i < img.height(); ++i) {
|
||||
for (int j = 0; j < img.width(); ++j) {
|
||||
pixels[i][j] = 255 - pixels[i][j];
|
||||
pixels(i, j) = 255 - pixels(i, j);
|
||||
}
|
||||
}
|
||||
return BMPImage(img.fileHeader_copy(), img.infoHeader_copy(), pixels);
|
||||
return {img.fileHeader_copy(), img.infoHeader_copy(), pixels};
|
||||
}
|
||||
|
||||
Pixel operator-(const uint8_t &n, const Pixel &p) {
|
||||
|
@ -202,81 +207,86 @@ Pixel operator-(const Pixel &p, const uint8_t &n) {
|
|||
|
||||
BMPImage upscale2x(BMPImage &img) {
|
||||
auto oldPixels = img.pixels();
|
||||
Pixel **newPixelArray;
|
||||
// Pixel **newPixelArray;
|
||||
const uint32_t newHeight = img.height() * 2;
|
||||
const uint32_t newWidth = img.width() * 2;
|
||||
newPixelArray = new Pixel *[newHeight];
|
||||
// newPixelArray = new Pixel *[newHeight];
|
||||
PixelArray newPixelArray(newWidth, newHeight);
|
||||
for (int i = 0; i < newHeight; i += 2) {
|
||||
newPixelArray[i] = new Pixel[newWidth];
|
||||
// newPixelArray(i) = new Pixel[newWidth];
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
if (j % 2 == 0)
|
||||
newPixelArray[i][j] = oldPixels[i / 2][j / 2];
|
||||
newPixelArray(i, j) = oldPixels(i / 2, j / 2);
|
||||
else if (j == newWidth - 1)
|
||||
newPixelArray[i][j] = oldPixels[i / 2][j / 2] / 2;
|
||||
newPixelArray(i, j) = oldPixels(i / 2, j / 2) / 2;
|
||||
else
|
||||
newPixelArray[i][j] = oldPixels[i / 2][j / 2] / 2 + oldPixels[i / 2][j / 2 + 1] / 2;
|
||||
newPixelArray(i, j) = oldPixels(i / 2, j / 2) / 2 + oldPixels(i / 2, j / 2 + 1) / 2;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i < newHeight; i += 2) {
|
||||
newPixelArray[i] = new Pixel[newWidth];
|
||||
// newPixelArray(i) = new Pixel[newWidth];
|
||||
if (i == newHeight - 1)
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
newPixelArray[i][j] = newPixelArray[i - 1][j] / 2;
|
||||
newPixelArray(i, j) = newPixelArray(i - 1, j) / 2;
|
||||
}
|
||||
else
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
newPixelArray[i][j] = newPixelArray[i - 1][j] / 2 + newPixelArray[i + 1][j] / 2;
|
||||
newPixelArray(i, j) = newPixelArray(i - 1, j) / 2 + newPixelArray(i + 1, j) / 2;
|
||||
}
|
||||
}
|
||||
return BMPImage(newPixelArray, newWidth, newHeight);
|
||||
return {newPixelArray};
|
||||
// return BMPImage(newPixelArray, newWidth, newHeight);
|
||||
}
|
||||
|
||||
BMPImage downscale2x(BMPImage &img) {
|
||||
Pixel **newPixelArray;
|
||||
// Pixel **newPixelArray;
|
||||
auto oldPixels = img.pixels_copy();
|
||||
const uint32_t newHeight = img.height() / 2;
|
||||
const uint32_t newWidth = img.width() / 2;
|
||||
newPixelArray = new Pixel *[newHeight];
|
||||
PixelArray newPixelArray(newWidth, newHeight);
|
||||
// newPixelArray = new Pixel *[newHeight];
|
||||
for (int i = 0; i < newHeight; ++i) {
|
||||
newPixelArray[i] = new Pixel[newWidth];
|
||||
// newPixelArray(i) = new Pixel[newWidth];
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
newPixelArray[i][j] = oldPixels[i * 2][j * 2];
|
||||
newPixelArray(i, j) = oldPixels(i * 2, j * 2);
|
||||
}
|
||||
}
|
||||
return BMPImage(newPixelArray, newWidth, newHeight);
|
||||
// return BMPImage(newPixelArray, newWidth, newHeight);
|
||||
return {newPixelArray};
|
||||
}
|
||||
|
||||
BMPImage upscale1_5x(BMPImage &img) {
|
||||
auto oldPixels = img.pixels();
|
||||
Pixel **newPixelArray;
|
||||
// Pixel **newPixelArray;
|
||||
const uint32_t newHeight = img.height() * 3 / 2;
|
||||
const uint32_t newWidth = img.width() * 3 / 2;
|
||||
newPixelArray = new Pixel *[newHeight];
|
||||
PixelArray newPixelArray(newWidth, newHeight);
|
||||
// newPixelArray = new Pixel *[newHeight];
|
||||
for (int i = 0; i < newHeight; ++i) {
|
||||
newPixelArray[i] = new Pixel[newWidth];
|
||||
// newPixelArray(i) = new Pixel[newWidth];
|
||||
if ((i + 1) % 3 == 0) continue;
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
int oldi = i * 2 / 3;
|
||||
int oldj = j * 2 / 3;
|
||||
if ((j + 1) % 3 != 0)
|
||||
newPixelArray[i][j] = oldPixels[oldi][oldj];
|
||||
newPixelArray(i, j) = oldPixels(oldi, oldj);
|
||||
else if (j == newWidth - 1)
|
||||
newPixelArray[i][j] = oldPixels[oldi][oldj] / 2;
|
||||
newPixelArray(i, j) = oldPixels(oldi, oldj) / 2;
|
||||
else
|
||||
newPixelArray[i][j] = oldPixels[oldi][oldj] / 2 + oldPixels[oldi][oldj + 1] / 2;
|
||||
newPixelArray(i, j) = oldPixels(oldi, oldj) / 2 + oldPixels(oldi, oldj + 1) / 2;
|
||||
}
|
||||
}
|
||||
for (int i = 2; i < newHeight; i += 3) {
|
||||
if (i == newHeight - 1)
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
newPixelArray[i][j] = newPixelArray[i - 1][j] / 2;
|
||||
newPixelArray(i, j) = newPixelArray(i - 1, j) / 2;
|
||||
}
|
||||
else
|
||||
for (int j = 0; j < newWidth; ++j) {
|
||||
newPixelArray[i][j] = newPixelArray[i - 1][j] / 2 + newPixelArray[i + 1][j] / 2;
|
||||
newPixelArray(i, j) = newPixelArray(i - 1, j) / 2 + newPixelArray(i + 1, j) / 2;
|
||||
}
|
||||
}
|
||||
return BMPImage(newPixelArray, newWidth, newHeight);
|
||||
return {newPixelArray};
|
||||
|
||||
}
|
||||
|
||||
|
@ -289,15 +299,15 @@ PixelArray::PixelArray(uint32_t width, uint32_t height) {
|
|||
}
|
||||
}
|
||||
|
||||
Pixel PixelArray::operator()(const uint32_t &i, const uint32_t &j) {
|
||||
Pixel &PixelArray::operator()(const uint32_t &i, const uint32_t &j) {
|
||||
return this->array[i][j];
|
||||
}
|
||||
|
||||
PixelArray::~PixelArray() {
|
||||
for (int i = 0; i < this->_height; ++i) {
|
||||
delete[] this->array[i];
|
||||
}
|
||||
delete[] this->array;
|
||||
// for (int i = 0; i < this->_height; ++i) {
|
||||
// delete[] this->array[i];
|
||||
// }
|
||||
// delete[] this->array;
|
||||
}
|
||||
|
||||
PixelArray::PixelArray(const PixelArray &pA) {
|
||||
|
@ -306,9 +316,10 @@ PixelArray::PixelArray(const PixelArray &pA) {
|
|||
this->array = pA.array;
|
||||
}
|
||||
|
||||
Pixel* PixelArray::operator()(const uint32_t &i) {
|
||||
Pixel *&PixelArray::operator()(const uint32_t &i) {
|
||||
return this->array[i];
|
||||
}
|
||||
|
||||
const uint32_t &PixelArray::width() const { return this->_width; }
|
||||
|
||||
const uint32_t &PixelArray::height() const { return this->_height; }
|
||||
|
|
14
bmpimage.h
14
bmpimage.h
|
@ -55,8 +55,8 @@ public:
|
|||
|
||||
// Pixel operator()(const uint32_t &, const uint32_t &);
|
||||
// Pixel* operator()(const uint32_t &);
|
||||
Pixel operator()(const uint32_t &, const uint32_t &);
|
||||
Pixel* operator()(const uint32_t &);
|
||||
Pixel &operator()(const uint32_t &, const uint32_t &);
|
||||
Pixel* &operator()(const uint32_t &);
|
||||
};
|
||||
|
||||
class BMPImage {
|
||||
|
@ -64,9 +64,9 @@ class BMPImage {
|
|||
BITMAPINFOHEADER infoHeader;
|
||||
PixelArray pixelArray;
|
||||
public:
|
||||
BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, PixelArray pixelArray);
|
||||
BMPImage(const BitmapFileHeader &fileHeader, const BITMAPINFOHEADER &infoHeader, const PixelArray& pixelArray);
|
||||
|
||||
BMPImage(PixelArray pixelArray);
|
||||
BMPImage(const PixelArray& pixelArray);
|
||||
|
||||
~BMPImage();
|
||||
|
||||
|
@ -74,9 +74,9 @@ public:
|
|||
|
||||
[[nodiscard]] const uint32_t &height() const;
|
||||
|
||||
[[nodiscard]] const PixelArray pixels();
|
||||
[[nodiscard]] PixelArray pixels();
|
||||
|
||||
[[nodiscard]] Pixel **pixels_copy();
|
||||
[[nodiscard]] PixelArray pixels_copy();
|
||||
|
||||
[[nodiscard]] BitmapFileHeader fileHeader_copy();
|
||||
|
||||
|
@ -84,7 +84,7 @@ public:
|
|||
|
||||
void save(const std::string &);
|
||||
|
||||
BMPImage *appendRight(const BMPImage &);
|
||||
BMPImage appendRight(BMPImage &);
|
||||
};
|
||||
|
||||
BMPImage readBMPImage(const std::string &filename);
|
||||
|
|
180
main.cpp
180
main.cpp
|
@ -3,33 +3,36 @@
|
|||
|
||||
const std::string FILENAME = "../elef.bmp";
|
||||
const std::string FILENAME_OUT = "../elef_out.bmp";
|
||||
|
||||
//
|
||||
//void lab01() {
|
||||
// auto og_image = readBMPImage("../elef.bmp");
|
||||
// auto pixels1 = og_image.pixels_copy();
|
||||
// auto pixels2 = og_image.pixels_copy();
|
||||
// for (int i = 0; i < og_image.height(); ++i) {
|
||||
// for (int j = 0; j < og_image.width(); ++j) {
|
||||
// pixels1[i][j] = pixels1[i][j] / 2;
|
||||
// pixels2[i][j] = pixels2[i][j] * 2;
|
||||
// }
|
||||
// }
|
||||
// auto darkenImg = BMPImage(pixels1, og_image.width(), og_image.height());
|
||||
// auto lighterImg = BMPImage(pixels2, og_image.width(), og_image.height());
|
||||
// og_image.appendRight(lighterImg)->appendRight(darkenImg)->appendRight(invertColors(og_image))->appendRight(
|
||||
// grayscale(og_image))->save("../lab01/elef1.bmp");
|
||||
//}
|
||||
void lab01() {
|
||||
auto og_image = readBMPImage("../elef.bmp");
|
||||
auto pixels1 = og_image.pixels_copy();
|
||||
auto pixels2 = og_image.pixels_copy();
|
||||
for (int i = 0; i < og_image.height(); ++i) {
|
||||
for (int j = 0; j < og_image.width(); ++j) {
|
||||
pixels1(i, j) = pixels1(i, j) / 2;
|
||||
pixels2(i, j) = pixels2(i, j) * 2;
|
||||
}
|
||||
}
|
||||
auto darkenImg = BMPImage(pixels1);
|
||||
auto lighterImg = BMPImage(pixels2);
|
||||
auto invert_img = invertColors(og_image); // TODO
|
||||
auto grayscale_img = grayscale(og_image);
|
||||
og_image.appendRight(lighterImg).appendRight(darkenImg).appendRight(invert_img).appendRight(grayscale_img).save(
|
||||
"../lab01/elef1.bmp");
|
||||
}
|
||||
//
|
||||
//void lab02_01() {
|
||||
// auto img = readBMPImage("../tea.bmp");
|
||||
// auto img_512 = downscale2x(img);
|
||||
// auto img_256 = downscale2x(img_512);
|
||||
// auto img_128 = downscale2x(img_256);
|
||||
// img_512.save("../lab02/tea_512.bmp");
|
||||
// img_256.save("../lab02/tea_256.bmp");
|
||||
// img_128.save("../lab02/tea_128.bmp");
|
||||
// auto newImg = img.appendRight(img_512)->appendRight(img_256)->appendRight(img_128);
|
||||
// newImg->save("../lab02/tea_downscale.bmp");
|
||||
void lab02_01() {
|
||||
auto img = readBMPImage("../tea.bmp");
|
||||
auto img_512 = downscale2x(img);
|
||||
auto img_256 = downscale2x(img_512);
|
||||
auto img_128 = downscale2x(img_256);
|
||||
img_512.save("../lab02/tea_512.bmp");
|
||||
img_256.save("../lab02/tea_256.bmp");
|
||||
img_128.save("../lab02/tea_128.bmp");
|
||||
auto newImg = img.appendRight(img_512).appendRight(img_256).appendRight(img_128);
|
||||
newImg.save("../lab02/tea_downscale.bmp");
|
||||
// auto img_from_512 = upscale2x(img_512);
|
||||
//// auto img_from_256 = upscale2x(upscale2x(img_256));
|
||||
//// auto img_from_128 = upscale2x(upscale2x(upscale2x(img_128)));
|
||||
|
@ -43,79 +46,80 @@ const std::string FILENAME_OUT = "../elef_out.bmp";
|
|||
// img_from_128.save("../lab02/tea_from_128.bmp");
|
||||
// img.appendRight(img_from_512)->appendRight(img_from_256)->appendRight(img_from_128)->save("../lab02/tea_upscale.bmp");
|
||||
//// newImg2->save("../lab02/tea_upscale.bmp");
|
||||
//}
|
||||
}
|
||||
//
|
||||
//void lab02_02() {
|
||||
// auto img = readBMPImage("../tea.bmp");
|
||||
// auto gsImg = grayscale(img);
|
||||
// gsImg.save("../lab02/tea_grayscale_256.bmp");
|
||||
// auto gsPixels = gsImg.pixels_copy();
|
||||
// auto width = gsImg.width();
|
||||
// auto height = gsImg.height();
|
||||
// for (int i = 0; i < height; ++i) {
|
||||
// for (int j = 0; j < width; ++j) {
|
||||
// gsPixels[i][j] = (gsPixels[i][j] / 2) * 2;
|
||||
// }
|
||||
// }
|
||||
// auto gsImg128 = BMPImage(gsPixels, width, height);
|
||||
// gsPixels = gsImg.pixels_copy();
|
||||
// for (int i = 0; i < height; ++i) {
|
||||
// for (int j = 0; j < width; ++j) {
|
||||
// gsPixels[i][j] = (gsPixels[i][j] / 4) * 4;
|
||||
// }
|
||||
// }
|
||||
// auto gsImg64 = BMPImage(gsPixels, width, height);
|
||||
// gsPixels = gsImg.pixels_copy();
|
||||
// for (int i = 0; i < height; ++i) {
|
||||
// for (int j = 0; j < width; ++j) {
|
||||
// gsPixels[i][j] = (gsPixels[i][j] / 8) * 8;
|
||||
// }
|
||||
// }
|
||||
// auto gsImg32 = BMPImage(gsPixels, width, height);
|
||||
// gsImg128.save("../lab02/tea_grayscale_128.bmp");
|
||||
// gsImg64.save("../lab02/tea_grayscale_64.bmp");
|
||||
// gsImg32.save("../lab02/tea_grayscale_32.bmp");
|
||||
// gsImg.appendRight(gsImg128)->appendRight(gsImg64)->appendRight(gsImg32)->save("../lab02/tea_grayscale.bmp");
|
||||
//}
|
||||
void lab02_02() {
|
||||
auto img = readBMPImage("../tea.bmp");
|
||||
auto gsImg = grayscale(img);
|
||||
gsImg.save("../lab02/tea_grayscale_256.bmp");
|
||||
auto gsPixels = gsImg.pixels_copy();
|
||||
auto width = gsImg.width();
|
||||
auto height = gsImg.height();
|
||||
for (int i = 0; i < height; ++i) {
|
||||
for (int j = 0; j < width; ++j) {
|
||||
gsPixels(i,j) = (gsPixels(i,j) / 2) * 2;
|
||||
}
|
||||
}
|
||||
auto gsImg128 = BMPImage(gsPixels);
|
||||
gsPixels = gsImg.pixels_copy();
|
||||
for (int i = 0; i < height; ++i) {
|
||||
for (int j = 0; j < width; ++j) {
|
||||
gsPixels(i,j) = (gsPixels(i,j) / 4) * 4;
|
||||
}
|
||||
}
|
||||
auto gsImg64 = BMPImage(gsPixels);
|
||||
gsPixels = gsImg.pixels_copy();
|
||||
for (int i = 0; i < height; ++i) {
|
||||
for (int j = 0; j < width; ++j) {
|
||||
gsPixels(i,j) = (gsPixels(i,j) / 8) * 8;
|
||||
}
|
||||
}
|
||||
auto gsImg32 = BMPImage(gsPixels);
|
||||
gsImg128.save("../lab02/tea_grayscale_128.bmp");
|
||||
gsImg64.save("../lab02/tea_grayscale_64.bmp");
|
||||
gsImg32.save("../lab02/tea_grayscale_32.bmp");
|
||||
gsImg.appendRight(gsImg128).appendRight(gsImg64).appendRight(gsImg32).save("../lab02/tea_grayscale.bmp");
|
||||
}
|
||||
//
|
||||
//void lab02_03(){
|
||||
// auto img = readBMPImage("../tea.bmp");
|
||||
// auto img_1_5 = upscale1_5x(img);
|
||||
// auto img_2 = upscale2x(img);
|
||||
// auto img_3 = upscale2x(img_1_5);
|
||||
// img_1_5.save("../lab02/lab02_03/tea_x1_5.bmp");
|
||||
// img_2.save("../lab02/lab02_03/tea_x2.bmp");
|
||||
// img_3.save("../lab02/lab02_03/tea_x3.bmp");
|
||||
//// img.appendRight(img_1_5)->appendRight(img_2)->appendRight(img_3)->save("../lab02/lab02_03/tea_upscale.bmp");
|
||||
// img.appendRight(img_1_5)->save("../lab02/lab02_03/tea_upscale.bmp");
|
||||
//}
|
||||
void lab02_03(){
|
||||
auto img = readBMPImage("../tea.bmp");
|
||||
auto img_1_5 = upscale1_5x(img);
|
||||
auto img_2 = upscale2x(img);
|
||||
auto img_3 = upscale2x(img_1_5);
|
||||
img_1_5.save("../lab02/lab02_03/tea_x1_5.bmp");
|
||||
img_2.save("../lab02/lab02_03/tea_x2.bmp");
|
||||
img_3.save("../lab02/lab02_03/tea_x3.bmp");
|
||||
img.appendRight(img_1_5).appendRight(img_2).appendRight(img_3).save("../lab02/lab02_03/tea_upscale.bmp"); //.appendRight(img_3)
|
||||
// img.appendRight(img_1_5).save("../lab02/lab02_03/tea_upscale.bmp");
|
||||
}
|
||||
|
||||
void test() {
|
||||
Pixel **test;
|
||||
test = new Pixel *[3];
|
||||
test[0] = new Pixel[3];
|
||||
test[1] = new Pixel[3];
|
||||
test[2] = new Pixel[3];
|
||||
test[0][0] = Pixel{0, 0, 0};
|
||||
test[0][1] = Pixel{127, 127, 127};
|
||||
test[0][2] = Pixel{255, 255, 255};
|
||||
test[1][0] = Pixel{127, 127, 127};
|
||||
test[1][1] = Pixel{63, 63, 63};
|
||||
test[1][2] = Pixel{127, 127, 127};
|
||||
test[2][0] = Pixel{255, 255, 255};
|
||||
test[2][1] = Pixel{127, 127, 127};
|
||||
test[2][2] = Pixel{0, 0, 0};
|
||||
auto test_img = BMPImage(test, 3, 3);
|
||||
// Pixel **test;
|
||||
PixelArray test(3, 3);
|
||||
// test = new Pixel *[3];
|
||||
// test[0] = new Pixel[3];
|
||||
// test[1] = new Pixel[3];
|
||||
// test[2] = new Pixel[3];
|
||||
test(0, 0) = Pixel{0, 0, 0};
|
||||
test(0, 1) = Pixel{127, 127, 127};
|
||||
test(0, 2) = Pixel{255, 255, 255};
|
||||
test(1, 0) = Pixel{127, 127, 127};
|
||||
test(1, 1) = Pixel{63, 63, 63};
|
||||
test(1, 2) = Pixel{127, 127, 127};
|
||||
test(2, 0) = Pixel{255, 255, 255};
|
||||
test(2, 1) = Pixel{127, 127, 127};
|
||||
test(2, 2) = Pixel{0, 0, 0};
|
||||
auto test_img = BMPImage(test);
|
||||
test_img.save("../test.bmp");
|
||||
auto test_scale = upscale2x(test_img);
|
||||
test_scale.save("../test_scale.bmp");
|
||||
}
|
||||
|
||||
int main() {
|
||||
//lab01();
|
||||
//lab02_01();
|
||||
//lab02_02();
|
||||
// lab01();
|
||||
// lab02_01();
|
||||
lab02_02();
|
||||
// lab02_03();
|
||||
test();
|
||||
// test();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue