-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcdecorator_scale.cpp
More file actions
135 lines (126 loc) · 5.72 KB
/
cdecorator_scale.cpp
File metadata and controls
135 lines (126 loc) · 5.72 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//****************************************************************************************************
//ïîäêëþ÷àåìûå áèáëèîòåêè
//****************************************************************************************************
#include "cdecorator_scale.h"
#include <math.h>
//****************************************************************************************************
//ãëîáàëüíûå ïåðåìåííûå
//****************************************************************************************************
//****************************************************************************************************
//êîíñòàíòû
//****************************************************************************************************
//****************************************************************************************************
//ìàêðîîïðåäåëåíèÿ
//****************************************************************************************************
//****************************************************************************************************
//êîíñòðóêòîð è äåñòðóêòîð
//****************************************************************************************************
//----------------------------------------------------------------------------------------------------
//êîíñòðóêòîð
//----------------------------------------------------------------------------------------------------
CDecorator_Scale::CDecorator_Scale(IImage *iImage_Set_Ptr,uint32_t new_width,uint32_t new_height):CDecorator_IImage(iImage_Set_Ptr)
{
Width=new_width;
Height=new_height;
}
//----------------------------------------------------------------------------------------------------
//äåñòðóêòîð
//----------------------------------------------------------------------------------------------------
CDecorator_Scale::~CDecorator_Scale()
{
}
//****************************************************************************************************
//çàêðûòûå ôóíêöèè
//****************************************************************************************************
//****************************************************************************************************
//îòêðûòûå ôóíêöèè
//****************************************************************************************************
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü RGBA èçîáðàæåíèå
//----------------------------------------------------------------------------------------------------
void CDecorator_Scale::GetRGBAImage(uint32_t &width,uint32_t &height,std::vector<uint32_t> &vector_image)
{
//ñîçäà¸ì óâåëè÷åííîå èçîáðàæåíèå
std::vector<uint32_t> vector_oldimage;//äàííûå èçîáðàæåíèÿ
//çàïðàøèâàåì èçîáðàæåíèå
CDecorator_IImage::GetRGBAImage(width,height,vector_oldimage);
//ïðîèçâîäèì ìàñøòàáèðîâàíèå
uint32_t x;
uint32_t y;
vector_image.resize(Width*Height);
uint32_t *i_ptr=&(vector_image[0]);
uint32_t *oldi_ptr=&(vector_oldimage[0]);
for(y=0;y<Height;y++)
{
float tmp=static_cast<float>(y)/static_cast<float>(Height-1)*static_cast<float>(height-1);
int32_t ys=static_cast<int32_t>(floor(tmp));
if (ys<0) ys=0;
if (ys>=height-1) ys=height-2;
float u=tmp-ys;
for(x=0;x<Width;x++,i_ptr++)
{
float tmp=static_cast<float>(x)/static_cast<float>(Width-1)*static_cast<float>(width-1);
int32_t xs=static_cast<int32_t>(floor(tmp));
if (xs<0) xs=0;
if (xs>=width-1) xs=width-2;
float v=tmp-xs;
//êîýôôèöèåíòû
float d1=(1-v)*(1-u);
float d2=v*(1-u);
float d3=v*u;
float d4=(1-v)*u;
//îêðåñòíûå ïèêñåëè
uint32_t p1=oldi_ptr[xs+ys*width];
uint32_t p2=oldi_ptr[xs+1+ys*width];
uint32_t p3=oldi_ptr[xs+1+(ys+1)*width];
uint32_t p4=oldi_ptr[xs+(ys+1)*width];
//âû÷èñëÿåì íîâîå çíà÷åíèå ïèêñåëÿ
uint32_t color=0;
uint32_t mask=0xFF;
uint32_t offset=0;
for(uint8_t k=0;k<4;k++,mask<<=8,offset+=8)
{
uint32_t kp1=(p1&mask)>>offset;
uint32_t kp2=(p2&mask)>>offset;
uint32_t kp3=(p3&mask)>>offset;
uint32_t kp4=(p4&mask)>>offset;
uint32_t c=static_cast<short>(kp1*d1+kp2*d2+kp3*d3+kp4*d4);
if (c>=0xFF) c=0xFF;
color|=(c<<offset);
}
*i_ptr=color;
}
}
width=Width;
height=Height;
}
//----------------------------------------------------------------------------------------------------
//çàäàòü RGBA èçîáðàæåíèå
//----------------------------------------------------------------------------------------------------
void CDecorator_Scale::SetRGBAImage(const uint32_t &width,const uint32_t &height,const std::vector<uint32_t> &vector_image)
{
CDecorator_IImage::SetRGBAImage(width,height,vector_image);
}
//----------------------------------------------------------------------------------------------------
//çàäàòü ðàçìåð èçîáðàæåíèÿ
//----------------------------------------------------------------------------------------------------
void CDecorator_Scale::SetSize(uint32_t width,uint32_t height)
{
Width=width;
Height=height;
//CDecorator_IImage::SetSize(width,height);
}
//----------------------------------------------------------------------------------------------------
//çàäàòü òî÷êó
//----------------------------------------------------------------------------------------------------
void CDecorator_Scale::SetRGBAPixel(uint32_t x,uint32_t y,uint32_t color)
{
CDecorator_IImage::SetRGBAPixel(x,y,color);
}
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü òî÷êó
//----------------------------------------------------------------------------------------------------
uint32_t CDecorator_Scale::GetRGBAPixel(uint32_t x,uint32_t y)
{
return(CDecorator_IImage::GetRGBAPixel(x,y));
}