-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScaledImage.cpp
executable file
·81 lines (79 loc) · 1.89 KB
/
ScaledImage.cpp
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
72
73
74
75
76
77
78
79
80
81
#include <iostream>
#include "Base/color.h"
#include "Base/pixel.h"
#include "Base/image.h"
#include "ScaledImage.h"
#include <cmath>
using namespace std;
ScaledImage::ScaledImage() {}
ScaledImage::ScaledImage(Image *img)
{
type="";
_w = img->get_w();
_h = img->get_h();
int ht = ceil(_h/2.0);
int width = ceil(_w/2.0);
set_arr();
for (int i = 0; i < _h; ++i)
{
for (int j = 0; j < _w; ++j)
{
if (i < ht && j < width)
_arr[i][j].set_color(img->color_at(2*i,2*j));
else
_arr[i][j].set_color(255,255,255);
}
}
}
ScaledImage::ScaledImage(Image *img, string s)
{
_w = img->get_w();
_h = img->get_h();
type = s;
int ht = ceil(_h/2.0);
int width = ceil(_w/2.0);
set_arr();
if(s=="A")
{
for (int i = 0; i < _h; ++i)
{
for (int j = 0; j < _w; ++j)
{
if (i < ht && j >= width)
_arr[i][j].set_color(img->color_at(2*i,2*(_w-j)-1));
else
_arr[i][j].set_color(255,255,255);
}
}
}
if(s=="B")
{
for (int i = 0; i < _h; ++i)
{
for (int j = 0; j < _w; ++j)
{
if (i >= ht && j < width)
_arr[i][j].set_color(img->color_at(2*(_h-i)-1,2*j));
else
_arr[i][j].set_color(255,255,255);
}
}
}
if(s=="AB")
{
for (int i = 0; i < _h; ++i)
{
for (int j = 0; j < _w; ++j)
{
if (i >= ht && j >= width)
{
_arr[i][j].set_color(img->color_at(2*(_h-i)-1,2*(_w-j)-1));
}
else
{
_arr[i][j].set_color(255,255,255);
}
}
}
}
}