173 lines
6 KiB
C++
173 lines
6 KiB
C++
#include <iostream>
|
||
#include "bmpimage.h"
|
||
#include "psf.h"
|
||
|
||
const std::string FILENAME = "../elef.bmp";
|
||
const std::string FILENAME_OUT = "../elef_out.bmp";
|
||
auto font = readPSF("../fonts/ruscii_8x16_2.psf");
|
||
|
||
//
|
||
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 orig_text = textImg(u"Оригинал", &font, 3);
|
||
auto darken_text = textImg(u"Темнее", &font, 3);
|
||
auto lighter_text = textImg(u"Светлее", &font, 3);
|
||
auto invert_text = textImg(u"Инвертирован", &font, 3);
|
||
auto grayscale_text = textImg(u"Оттенки серого", &font, 3);
|
||
auto darkenImg = BMPImage(pixels1).overlay(darken_text, 0, 0);
|
||
auto lighterImg = BMPImage(pixels2).overlay(lighter_text, 0, 0);
|
||
auto invert_img = invertColors(og_image).overlay(invert_text, 0, 0); // TODO
|
||
auto grayscale_img = grayscale(og_image).overlay(grayscale_text, 0, 0);
|
||
|
||
og_image.appendRight(lighterImg).appendRight(darkenImg).appendRight(invert_img).appendRight(grayscale_img).overlay(
|
||
orig_text, 0, 0).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");
|
||
// auto img_from_512 = upscale2x(img_512);
|
||
//// auto img_from_256 = upscale2x(upscale2x(img_256));
|
||
//// auto img_from_128 = upscale2x(upscale2x(upscale2x(img_128)));
|
||
// auto tmp = upscale2x(img_256);
|
||
// auto img_from_256 = upscale2x(tmp);
|
||
// auto tmp2 = upscale2x(img_128);
|
||
// auto tmp3 = upscale2x(tmp2);
|
||
// auto img_from_128 = upscale2x(tmp3);
|
||
// img_from_512.save("../lab02/tea_from_512.bmp");
|
||
// img_from_256.save("../lab02/tea_from_256.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);
|
||
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"); //.appendRight(img_3)
|
||
// img.appendRight(img_1_5).save("../lab02/lab02_03/tea_upscale.bmp");
|
||
}
|
||
|
||
void test() {
|
||
// 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");
|
||
}
|
||
|
||
void test2() {
|
||
auto background_color = Pixel{0, 0, 0};
|
||
auto font_color = Pixel{255, 255, 255};
|
||
auto glyph = font._glyphs[u'б'];
|
||
auto w = glyph.width;
|
||
auto h = glyph.height;
|
||
|
||
uint32_t imgWidth = 16 * glyph.width;
|
||
uint32_t imgHeight = 16 * glyph.height;
|
||
PixelArray test(imgWidth, imgHeight);
|
||
std::u16string str = u"Hello, World! Привет, Мир!";
|
||
uint32_t k = 0;
|
||
for (auto it: font._glyphs) {
|
||
if (k == 256) continue;
|
||
// glyph = font._glyphs[u'☺'];
|
||
// glyph = font._glyphs[str[k % str.size()]];
|
||
glyph = it.second;
|
||
for (int i = 0; i < h; ++i) {
|
||
for (int j = 0; j < w; ++j) {
|
||
if (glyph.glyph[i][j])
|
||
test((k / 16) * h + i, (k % 16) * w + j) = font_color;
|
||
else
|
||
test((k / 16) * h + i, (k % 16) * w + j) = background_color;
|
||
}
|
||
}
|
||
k++;
|
||
}
|
||
BMPImage(test).save("test_font.bmp");
|
||
}
|
||
|
||
void test3() {
|
||
textImg(u"Привет, Мир!", &font).save("../font_test.bmp");
|
||
}
|
||
|
||
int main() {
|
||
lab01();
|
||
// lab02_01();
|
||
// lab02_02();
|
||
// lab02_03();
|
||
// test();
|
||
// test2();
|
||
// test3();
|
||
return 0;
|
||
}
|