-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdecorator_hightcontrastfilter.cpp
98 lines (94 loc) · 3.75 KB
/
cdecorator_hightcontrastfilter.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "cdecorator_hightcontrastfilter.h"
//----------------------------------------------------------------------------------------------------
//êîíñòðóêòîð
//----------------------------------------------------------------------------------------------------
CDecorator_HightContrastFilter::CDecorator_HightContrastFilter(CIImage *cIImage_Set_Ptr):CDecorator_CIImage(cIImage_Set_Ptr)
{
}
//----------------------------------------------------------------------------------------------------
//äåñòðóêòîð
//----------------------------------------------------------------------------------------------------
CDecorator_HightContrastFilter::~CDecorator_HightContrastFilter()
{
}
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü RGBA èçîáðàæåíèå
//----------------------------------------------------------------------------------------------------
void CDecorator_HightContrastFilter::GetRGBAImage(unsigned long &width,unsigned long &height,vector<unsigned long> &vector_image)
{
//çàïðàøèâàåì èçîáðàæåíèå
vector<unsigned long> vector_oldimage;
CDecorator_CIImage::GetRGBAImage(width,height,vector_oldimage);
//ïðèìåíÿåì ê èçîáðàæåíèþ êîíòðàñòîïîâûøàþùèé ôèëüòð
vector_image.resize(width*height);
unsigned long *i_ptr=&(vector_image[0]);
unsigned long *oldi_ptr=&(vector_oldimage[0]);
float MatrixF[3][3]={-1,-1,-1,-1,9,-1,-1,-1,-1};
long x1,y1;
for(long x=0;x<width;x++)
{
for(long y=0;y<height;y++)
{
//çàïîëíÿåì ìàòðèöó çíà÷åíèÿìè èçîáðàæåíèÿ
float value[4]={0,0,0,0};
for(y1=0;y1<3;y1++)
{
for(x1=0;x1<3;x1++)
{
long x_p=x1+x-1;
long y_p=y1+y-1;
if (x_p>=width) x_p=width-1;
if (x_p<0) x_p=0;
if (y_p>=height) y_p=height-1;
if (y_p<0) y_p=0;
unsigned long p=oldi_ptr[y_p*width+x_p];
unsigned long mask=0xFF;
unsigned long offset=0;
for(unsigned char k=0;k<4;k++,mask<<=8,offset+=8)
{
unsigned long kp=(p&mask)>>offset;
value[k]+=MatrixF[y1][x1]*static_cast<float>(kp);
}
}
}
unsigned long color=0;
unsigned long offset=0;
for(unsigned char k=0;k<4;k++,offset+=8)
{
long c=static_cast<long>(value[k]);
if (c<0) c=0;
if (c>0xFF) c=0xFF;
color|=(c<<offset);
}
i_ptr[y*width+x]=color;
}
}
}
//----------------------------------------------------------------------------------------------------
//çàäàòü RGBA èçîáðàæåíèå
//----------------------------------------------------------------------------------------------------
void CDecorator_HightContrastFilter::SetRGBAImage(unsigned long &width,unsigned long &height,vector<unsigned long> &vector_image)
{
CDecorator_CIImage::SetRGBAImage(width,height,vector_image);
}
//----------------------------------------------------------------------------------------------------
//çàäàòü ðàçìåð èçîáðàæåíèÿ
//----------------------------------------------------------------------------------------------------
void CDecorator_HightContrastFilter::SetSize(unsigned long width,unsigned long height)
{
CDecorator_CIImage::SetSize(width,height);
}
//----------------------------------------------------------------------------------------------------
//çàäàòü òî÷êó
//----------------------------------------------------------------------------------------------------
void CDecorator_HightContrastFilter::SetRGBAPixel(unsigned long x,unsigned long y,unsigned long color)
{
CDecorator_CIImage::SetRGBAPixel(x,y,color);
}
//----------------------------------------------------------------------------------------------------
//ïîëó÷èòü òî÷êó
//----------------------------------------------------------------------------------------------------
unsigned long CDecorator_HightContrastFilter::GetRGBAPixel(unsigned long x,unsigned long y)
{
return(CDecorator_CIImage::GetRGBAPixel(x,y));
}