提交 | 用户 | age
|
4b03ae
|
1 |
//**********************************************//
|
Q |
2 |
//Image Function File
|
|
3 |
//V1.02
|
|
4 |
//2017-04-26
|
|
5 |
//
|
|
6 |
//**********************************************//
|
|
7 |
|
|
8 |
#pragma once
|
|
9 |
|
|
10 |
#include <GdiPlus.h>
|
|
11 |
|
|
12 |
#include <math.h>
|
|
13 |
//#include <boost/smart_ptr.hpp>
|
|
14 |
//#include <math.h>
|
|
15 |
//#include <intrin.h>
|
|
16 |
//#include <omp.h>
|
|
17 |
//#include <opencv2/opencv.hpp>
|
|
18 |
#include "../../MyLib/Functions.hpp"
|
|
19 |
//#include "MyImage.h"
|
|
20 |
#include <vector>
|
|
21 |
struct Complexf;
|
|
22 |
union COLOR;
|
|
23 |
union COLORf;
|
|
24 |
struct HSI;
|
|
25 |
struct Lab;
|
|
26 |
//class MyImage;
|
|
27 |
class QMat; //matrix;
|
|
28 |
|
|
29 |
class MyImage
|
|
30 |
{
|
|
31 |
// Bitmask value of the monochrome type. Internal use only.
|
|
32 |
#define MyPIXEL_MONO 0x01000000
|
|
33 |
// Bitmask value of the color pixel type. Internal use only.
|
|
34 |
#define MyPIXEL_COLOR 0x02000000
|
|
35 |
// Sets the bit count of pixel type. Internal use only.
|
|
36 |
#define MyPIXEL_BIT_COUNT(n) ((n) << 16)
|
|
37 |
public:
|
|
38 |
enum eMyPixelType
|
|
39 |
{
|
|
40 |
NDEF=0,
|
|
41 |
MyPixelType_Mono8,
|
|
42 |
MyPixelType_Mono8signed,
|
|
43 |
MyPixelType_Mono10,
|
|
44 |
MyPixelType_Mono10packed,
|
|
45 |
MyPixelType_Mono12,
|
|
46 |
MyPixelType_Mono12packed,
|
|
47 |
MyPixelType_Mono16,
|
|
48 |
|
|
49 |
MyPixelType_BayerGB8,
|
|
50 |
MyPixelType_BayerBG8,
|
|
51 |
MyPixelType_BayerGR8,
|
|
52 |
MyPixelType_BayerRG8,
|
|
53 |
|
|
54 |
MyPixelType_BayerGB10,
|
|
55 |
MyPixelType_BayerBG10,
|
|
56 |
MyPixelType_BayerGR10,
|
|
57 |
MyPixelType_BayerRG10,
|
|
58 |
|
|
59 |
MyPixelType_BayerGB12,
|
|
60 |
MyPixelType_BayerBG12,
|
|
61 |
MyPixelType_BayerGR12,
|
|
62 |
MyPixelType_BayerRG12,
|
|
63 |
|
|
64 |
MyPixelType_BayerGB12_Packed,
|
|
65 |
MyPixelType_BayerBG12_Packed,
|
|
66 |
MyPixelType_BayerGR12_Packed,
|
|
67 |
MyPixelType_BayerRG12_Packed,
|
|
68 |
|
|
69 |
MyPixelType_RGB8packed,
|
|
70 |
MyPixelType_BGR8packed,
|
|
71 |
|
|
72 |
MyPixelType_RGBA8packed,
|
|
73 |
MyPixelType_BGRA8packed,
|
|
74 |
|
|
75 |
MyPixelType_RGB10packed,
|
|
76 |
MyPixelType_BGR10packed,
|
|
77 |
|
|
78 |
MyPixelType_RGB12packed,
|
|
79 |
MyPixelType_BGR12packed,
|
|
80 |
|
|
81 |
MyPixelType_RGB8planar,
|
|
82 |
MyPixelType_RGB10planar,
|
|
83 |
MyPixelType_RGB12planar,
|
|
84 |
MyPixelType_RGB16planar,
|
|
85 |
|
|
86 |
MyPixelType_BayerGB16,
|
|
87 |
MyPixelType_BayerBG16,
|
|
88 |
MyPixelType_BayerGR16,
|
|
89 |
MyPixelType_BayerRG16,
|
|
90 |
|
|
91 |
MyPixelType_YUV411packed,
|
|
92 |
MyPixelType_YUV422packed,
|
|
93 |
MyPixelType_YUV422_YUYV_Packed,
|
|
94 |
MyPixelType_YUV444packed,
|
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
MyPixelType_Float,
|
|
99 |
// MyPixelType_RGB16,
|
|
100 |
// MyPixelType_RGB24,
|
|
101 |
|
|
102 |
MyPixelType_ARGB32,
|
|
103 |
};
|
|
104 |
enum enumPixelFormatConst
|
|
105 |
{
|
|
106 |
Default=0,
|
|
107 |
Mono8=1,
|
|
108 |
};
|
|
109 |
|
|
110 |
public:
|
|
111 |
int PixelFormat; //像素格式
|
|
112 |
int Width; //宽度
|
|
113 |
int Height; //高度
|
|
114 |
static const int Stride_Align=4; //对齐数
|
|
115 |
int Stride; //行宽
|
|
116 |
int BPP; //颜色深度
|
|
117 |
int IsValid; //是否有效
|
|
118 |
void * buffer0; //申请数据指针
|
|
119 |
void * buffer; //数据存储指针
|
|
120 |
void * buffer2;
|
|
121 |
void * buffer3;
|
|
122 |
int HistoArray[256]; //直方图数据
|
|
123 |
int HistoMaxCount; //最大直方图数量;
|
|
124 |
int MaxHistoIndex; //最大直方图索引
|
|
125 |
int IsHistoValid; //直方图有效
|
|
126 |
int SN;
|
|
127 |
CString Name;
|
|
128 |
CString InfoStr;
|
|
129 |
CString ResultStr;
|
|
130 |
Gdiplus::Bitmap * ShowCache;
|
|
131 |
int IsToRefreshCache;
|
|
132 |
|
|
133 |
int bIsLookUpTable;
|
|
134 |
USHORT ULookUpTable[256]; //逆向查找表
|
|
135 |
|
|
136 |
|
|
137 |
struct MyPoint
|
|
138 |
{
|
|
139 |
|
|
140 |
int X;
|
|
141 |
int Y;
|
|
142 |
MyPoint(){ X = 0; Y = 0; }
|
|
143 |
};
|
|
144 |
struct MyRegion
|
|
145 |
{
|
|
146 |
int IsValid;
|
|
147 |
CString RegionStr;
|
|
148 |
DWORD RegionColor;
|
|
149 |
std::vector<MyPoint> pts;
|
|
150 |
MyRegion& operator=(const MyRegion& MyRegion1)
|
|
151 |
{
|
|
152 |
IsValid = MyRegion1.IsValid;
|
|
153 |
pts.assign(MyRegion1.pts.begin(), MyRegion1.pts.end());
|
|
154 |
return *this;
|
|
155 |
};
|
|
156 |
int PtInMyRegion(MyPoint pt1)
|
|
157 |
{
|
|
158 |
int minx, miny, maxx, maxy;
|
|
159 |
int k = (int)pts.size();
|
|
160 |
if (k > 0)
|
|
161 |
{
|
|
162 |
MyPoint thispt = pts.at(0);
|
|
163 |
minx = thispt.X;
|
|
164 |
maxx = thispt.X;
|
|
165 |
miny = thispt.Y;
|
|
166 |
maxy = thispt.Y;
|
|
167 |
}
|
|
168 |
for (int i = 1; i < k; i++)
|
|
169 |
{
|
|
170 |
MyPoint thispt = pts.at(i);
|
|
171 |
if (thispt.X < minx) { minx = thispt.X; }
|
|
172 |
if (thispt.X > maxx) { maxx = thispt.X; }
|
|
173 |
if (thispt.Y < miny) { miny = thispt.Y; }
|
|
174 |
if (thispt.Y > maxy) { maxy = thispt.Y; }
|
|
175 |
}
|
|
176 |
if (pt1.X < minx) return false;
|
|
177 |
if (pt1.X > maxx) return false;
|
|
178 |
if (pt1.Y < miny) return false;
|
|
179 |
if (pt1.Y > maxy) return false;
|
|
180 |
int count = 0;
|
|
181 |
for (int i = 0, j = k - 1; i < k; j = i++)
|
|
182 |
{
|
|
183 |
MyPoint & tpt1 = pts.at(i);
|
|
184 |
MyPoint & tpt2 = pts.at(j);
|
|
185 |
if ((tpt1.Y > pt1.Y) != (tpt2.Y>pt1.Y))
|
|
186 |
{
|
|
187 |
if (pt1.X<(tpt2.X - tpt1.X)*(pt1.Y - tpt1.Y) / (tpt2.Y-tpt1.Y)+tpt1.X)
|
|
188 |
{
|
|
189 |
count++;
|
|
190 |
}
|
|
191 |
}
|
|
192 |
}
|
|
193 |
if (count % 2) return true;
|
|
194 |
return false;
|
|
195 |
}
|
|
196 |
};
|
|
197 |
std::vector<MyRegion> myregions;
|
|
198 |
|
|
199 |
struct stThumbImg
|
|
200 |
{
|
|
201 |
int IsValid;
|
|
202 |
int nWidth;
|
|
203 |
int nHeight;
|
|
204 |
void * buffer;
|
|
205 |
}m_thumbImg;
|
|
206 |
// boost::shared_array;
|
|
207 |
MyImage()
|
|
208 |
{
|
|
209 |
buffer0=NULL;
|
|
210 |
buffer=NULL;
|
|
211 |
buffer2 = NULL;
|
|
212 |
buffer3 = NULL;
|
|
213 |
IsValid=false;
|
|
214 |
IsHistoValid=0;
|
|
215 |
HistoMaxCount=0;
|
|
216 |
MaxHistoIndex=0;
|
|
217 |
m_thumbImg.IsValid = false;
|
|
218 |
m_thumbImg.buffer = NULL;
|
|
219 |
ShowCache = NULL;
|
|
220 |
IsToRefreshCache = 0;
|
|
221 |
}
|
|
222 |
~MyImage()
|
|
223 |
{
|
|
224 |
Destory();
|
|
225 |
}
|
|
226 |
int AllocBuf(int width,int height,int stride=0,int PixelFormat1=MyPixelType_Mono8);
|
|
227 |
int Destory()
|
|
228 |
{
|
|
229 |
if (buffer0!=NULL)
|
|
230 |
{
|
|
231 |
IsValid=false;
|
|
232 |
delete [] buffer0;
|
|
233 |
buffer0=NULL;
|
|
234 |
buffer=NULL;
|
|
235 |
}
|
|
236 |
if (buffer2 != NULL) {delete[] buffer2; }
|
|
237 |
if (buffer3 != NULL) delete [] buffer3;
|
|
238 |
|
|
239 |
if (m_thumbImg.IsValid)
|
|
240 |
{
|
|
241 |
delete[] m_thumbImg.buffer;
|
|
242 |
m_thumbImg.buffer = 0;
|
|
243 |
}
|
|
244 |
if (ShowCache!=NULL)
|
|
245 |
{
|
|
246 |
::delete ShowCache;
|
|
247 |
}
|
|
248 |
return true;
|
|
249 |
}
|
|
250 |
void Clear(int Color=0)
|
|
251 |
{
|
|
252 |
memset(buffer,Color,Stride*Height);
|
|
253 |
HistoMaxCount=0;
|
|
254 |
MaxHistoIndex=0;
|
|
255 |
IsHistoValid=0;
|
|
256 |
}
|
|
257 |
MyImage(const MyImage& Image1)
|
|
258 |
{
|
|
259 |
*this = Image1;
|
|
260 |
}
|
|
261 |
MyImage& operator=(const MyImage& Image1)
|
|
262 |
{
|
|
263 |
CopyFromBuf(Image1.buffer,Image1.Width,Image1.Height,Image1.Stride,Image1.PixelFormat);
|
|
264 |
this->SN=Image1.SN;
|
|
265 |
this->Name=Image1.Name;
|
|
266 |
this->IsHistoValid=Image1.IsHistoValid;
|
|
267 |
this->MaxHistoIndex=Image1.MaxHistoIndex;
|
|
268 |
this->HistoMaxCount=Image1.HistoMaxCount;
|
|
269 |
for (int i=0;i<256;i++) this->HistoArray[i]=Image1.HistoArray[i];
|
|
270 |
return *this;
|
|
271 |
}
|
|
272 |
int GetWidth(){return Width;}
|
|
273 |
int GetHeight(){return Height;}
|
|
274 |
int GetStride(){return Stride;}
|
|
275 |
int GetBPP(){return BPP;}
|
|
276 |
int GetPixelFormat(){return PixelFormat;}
|
|
277 |
int CopyFromBuf(void * buf, int w, int h, int stride, int pixelformat);
|
|
278 |
int CopyFromBufR90(void * buf, int w, int h, int stride, int pixelformat);
|
|
279 |
int CopyFromGdipBitMap(Gdiplus::Bitmap * bitmap1);
|
|
280 |
void * GetBuffer(){ return buffer;}
|
|
281 |
int DrawOnWindow(HWND hWnd,int Brightness=0,int Contrast=0);
|
|
282 |
int LoadFromBitmapFile(CString sFilePathName);
|
|
283 |
int SaveToFile(CString sFilePathName);
|
|
284 |
int LoadRegionFromFile(CString sFilePathName);
|
|
285 |
int SaveRegionToFile(CString sFilePathName);
|
|
286 |
|
|
287 |
int ConvertTypeToGdipBitmap32(Gdiplus::Bitmap** bitmapdest,int Brightness=0,int Contrast=0);
|
|
288 |
int CreateThumbImg(int w=0, int h=0,float startx=0,float starty=0,float Width=0,float Height=0);
|
|
289 |
int DrawThumbOnWindow(HWND hWnd, int Brightness = 0, int Contrast = 0);
|
|
290 |
int ConvertThumbToGdipBitmap32(Gdiplus::Bitmap** bitmapdest, int Brightness = 0, int Contrast = 0);
|
|
291 |
|
|
292 |
int Meg3ImgIntoRGB8planar(MyImage & img1, MyImage &img2, MyImage & img3);
|
|
293 |
int Meg3ImgIntoRGB(MyImage & img1, MyImage &img2, MyImage & img3);
|
|
294 |
void RefreshShowCache(){ IsToRefreshCache = 1; };
|
|
295 |
|
|
296 |
};
|
|
297 |
|
|
298 |
double GetTickCountmS();
|
|
299 |
WCHAR* ToWChar(char * str) ;
|
|
300 |
int GetEncoderClsid(const WCHAR* format, CLSID* pClsid);
|
|
301 |
//int Split(CString s1,CString divider,CString resultstr[]);
|
|
302 |
int GdipDrawRoundRect(Gdiplus::Graphics &gr1, Gdiplus::Pen &pen1, int x1, int y1, int x2, int y2, int r);
|
|
303 |
HSI RGBToHSI(COLOR c1);
|
|
304 |
HSI RGBfToHSI(COLORf &c1f);
|
|
305 |
Lab RGBfToLab(COLORf &c1f);
|
|
306 |
COLORf LabToRGBf(Lab lab1);
|
|
307 |
DWORD HSIToRGB(HSI hsi1);
|
|
308 |
COLORf HSIToRGBf(HSI hsi1);
|
|
309 |
int BayerGR8toRGB32(void * srcbuf,void * destbuf,int width,int height,int stride,int stride2=0);
|
|
310 |
int BayerGB8toRGB32(void * srcbuf,void * destbuf,int width,int height,int stride,int stride2=0);
|
|
311 |
int BayerGB8toRGB24(void * srcbuf,void * destbuf,int width,int height,int stride,int stride2=0);
|
|
312 |
/*
|
|
313 |
Translate From BayerGB12Mode To RGB8:8:8:8 Mode
|
|
314 |
*/
|
|
315 |
int BayerGB12PackedToRGB32(void * destbuf,void * srcbuf,int width,int height,float gamma);
|
|
316 |
int Raw12toRaw16(void * destbuf,void * srcbuf,int width,int height);
|
|
317 |
int Raw12ToRaw8(void * dest, void * src, int width, int height);
|
|
318 |
int BayerGB16toRGB64(void * destbuf,void * srcbuf,int width,int height);
|
|
319 |
int BayerGB12toRGB64(void * destbuf,void * srcbuf,int width,int height);
|
|
320 |
int RGB32toRGB64(void * destbuf,void * srcbuf,int width,int height);
|
|
321 |
int RGB64toRGB32(void * destbuf,void * srcbuf,int width,int height);
|
|
322 |
|
|
323 |
int QuadRectTransForm(Gdiplus::Bitmap* bitmapsrc,Gdiplus::PointF srcpt[4],Gdiplus::Bitmap * bitmapdest,Gdiplus::Rect destrect);
|
|
324 |
int QuadRectTransForm(Gdiplus::Bitmap* bitmapsrc,Gdiplus::Point srcpt[4],Gdiplus::Bitmap * bitmapdest,Gdiplus::Rect destrect);
|
|
325 |
int QuadRectTransForm(Gdiplus::Bitmap* bitmapsrc,POINT srcpt[4],Gdiplus::Bitmap * bitmapdest,Gdiplus::Rect destrect);
|
|
326 |
int DrawBitmapOnWindow(HWND DestWindow,Gdiplus::Bitmap* srcbitmap,CString * Lable=0, CString * ResultStr=0, double scale=0);
|
|
327 |
int DrawImageOnWindow(HWND DestWindow, Gdiplus::Image* srcimage, CString * Lable = 0, CString * ResultStr = 0, double scale = 0);
|
|
328 |
int nihe(CPoint pt5[100], int pt5total, int pt5valid[100]);
|
|
329 |
int juanji(int incount,int corecount,double * inbuf, double * outbuf,double *corebuf);
|
|
330 |
int juanjiV(int incount,int corecount,int stride, int x, double inbuf[], double outbuf[],double corebuf[]);
|
|
331 |
int juanji2D(double inbuf[], int sizex, int sizey, int stride, double outbuf[], double corebuf[], int coresizex, int coresizey, int corestrie);
|
|
332 |
template <typename T>
|
|
333 |
int juanji2D3x3(T inbuf[], int sizex, int sizey, int stride, T outbuf[], T corebuf[3][3]);
|
|
334 |
//int juanji2D3x3(float inbuf[], int sizex, int sizey, int stride, float outbuf[], float corebuf[3][3]);
|
|
335 |
//int juanji2D3x3(double inbuf[], int sizex, int sizey, int stride, double outbuf[], double corebuf[3][3]);
|
|
336 |
int DCT(double pt[], double dpt[],int size,int start,int end);
|
|
337 |
int DCT(float pt[], float dpt[],int size,int start,int end);
|
|
338 |
int FDCT(double pt[], double dpt[],int size,int start,int end);
|
|
339 |
int FDCT(float pt[], float dpt[],int size,int start,int end);
|
|
340 |
int FFDCT(double pt[], double dpt[],int size,int start,int end);
|
|
341 |
int FFDCT(float pt[], float dpt[],int size,int start,int end);
|
|
342 |
int SaveBufferToFile(void *pBuf, size_t nSize, CString sFilePathName);
|
|
343 |
int SaveBufferToBmpFile(void * buf1,int width, int height, int stride, CString FilePathName,LONG XPelsPerMeter=0,LONG YPelsPerMeter=0);
|
|
344 |
int SaveGdiPImageAsFile(Gdiplus::Bitmap * bitmap1, CString sFileName, double Ratio=1.0,int Quality=70);
|
|
345 |
int SaveGdiPImageAsBuffer(Gdiplus::Image * image1, void ** ppbuffer, ULONGLONG *psizeImage, double Ratio = 1.0, int Quality = 70);
|
|
346 |
int LoadImageFromBuffer(void *pBuffer, ULONGLONG sizeImage, Gdiplus::Image ** ppimage1);
|
|
347 |
|
|
348 |
double RefCompare(double * buf1, int count1, double * buf2, int count2 ,int mode);
|
|
349 |
|
|
350 |
struct Complexf
|
|
351 |
{
|
|
352 |
float x,y; //real part and imaginary parts
|
|
353 |
operator float(){ return x; }
|
|
354 |
};
|
|
355 |
union COLOR
|
|
356 |
{
|
|
357 |
DWORD argb;
|
|
358 |
struct {
|
|
359 |
unsigned char B;
|
|
360 |
unsigned char G;
|
|
361 |
unsigned char R;
|
|
362 |
unsigned char A;
|
|
363 |
};
|
|
364 |
inline void ToStr(CString &str1)
|
|
365 |
{
|
|
366 |
str1.Format(_T("%d,%d,%d"),R,G,B);
|
|
367 |
}
|
|
368 |
inline void FromStr(CString &str1)
|
|
369 |
{
|
|
370 |
CString result[10];
|
|
371 |
Split(str1,_T(","),result);
|
|
372 |
R = _tstoi(result[0]);
|
|
373 |
G = _tstoi(result[1]);
|
|
374 |
B = _tstoi(result[2]);
|
|
375 |
}
|
|
376 |
inline void Clear()
|
|
377 |
{
|
|
378 |
argb=0;
|
|
379 |
}
|
|
380 |
};
|
|
381 |
|
|
382 |
union COLORf
|
|
383 |
{
|
|
384 |
// __m128 argb;
|
|
385 |
struct {
|
|
386 |
float B;
|
|
387 |
float G;
|
|
388 |
float R;
|
|
389 |
float A;
|
|
390 |
};
|
|
391 |
COLORf():B(0),G(0),R(0),A(0){}
|
|
392 |
COLORf(float b,float g,float r,float a):B(b),G(g),R(r),A(a){}
|
|
393 |
void ToStr(CString &s1)
|
|
394 |
{
|
|
395 |
s1.Format(_T("%.3f,%.3f,%.3f"),R,G,B);
|
|
396 |
}
|
|
397 |
void FromStr(CString &s1)
|
|
398 |
{
|
|
399 |
R=G=B=0;
|
|
400 |
CString result[10];
|
|
401 |
Split(s1,_T(","),result);
|
|
402 |
R = float(_tstof(result[0]));
|
|
403 |
G = float(_tstof(result[1]));
|
|
404 |
B = float(_tstof(result[2]));
|
|
405 |
}
|
|
406 |
void Clear()
|
|
407 |
{
|
|
408 |
// argb=_mm_setzero_ps();
|
|
409 |
A=R=G=B=0;
|
|
410 |
}
|
|
411 |
COLORf & operator+=(COLORf & color1)
|
|
412 |
{
|
|
413 |
this->B+=color1.B;
|
|
414 |
this->G+=color1.G;
|
|
415 |
this->R+=color1.R;
|
|
416 |
this->A+=color1.A;
|
|
417 |
return *this;
|
|
418 |
}
|
|
419 |
COLORf & operator/=(float f1)
|
|
420 |
{
|
|
421 |
this->B/=f1;
|
|
422 |
this->G/=f1;
|
|
423 |
this->R/=f1;
|
|
424 |
this->A/=f1;
|
|
425 |
return *this;
|
|
426 |
}
|
|
427 |
};
|
|
428 |
|
|
429 |
union RGB16
|
|
430 |
{
|
|
431 |
QWORD ARGB;
|
|
432 |
struct {
|
|
433 |
unsigned short int B;
|
|
434 |
unsigned short int G;
|
|
435 |
unsigned short int R;
|
|
436 |
unsigned short int A;
|
|
437 |
};
|
|
438 |
void ToStr(CString &s1)
|
|
439 |
{
|
|
440 |
s1.Format(_T("%d,%d,%d"),R,G,B);
|
|
441 |
}
|
|
442 |
void FromStr(CString &s1)
|
|
443 |
{
|
|
444 |
CString result[10];
|
|
445 |
Split(s1,_T(","),result);
|
|
446 |
R = _tstoi(result[0]);
|
|
447 |
G = _tstoi(result[1]);
|
|
448 |
B = _tstoi(result[2]);
|
|
449 |
}
|
|
450 |
void Clear()
|
|
451 |
{
|
|
452 |
ARGB=0;
|
|
453 |
}
|
|
454 |
};
|
|
455 |
|
|
456 |
struct HSI
|
|
457 |
{
|
|
458 |
float H;
|
|
459 |
float S;
|
|
460 |
float I;
|
|
461 |
HSI():H(0),S(0),I(0){}
|
|
462 |
inline void ToStr(CString &s1)
|
|
463 |
{
|
|
464 |
s1.Format(_T("%.3f,%.3f,%.3f"),H,S,I);
|
|
465 |
}
|
|
466 |
inline void FromStr(CString &s1)
|
|
467 |
{
|
|
468 |
CString result[10];
|
|
469 |
Split(s1,_T(","),result);
|
|
470 |
H = float(_tstof(result[0]));
|
|
471 |
S = float(_tstof(result[1]));
|
|
472 |
I = float(_tstof(result[2]));
|
|
473 |
}
|
|
474 |
};
|
|
475 |
struct Lab
|
|
476 |
{
|
|
477 |
float L,a,b;
|
|
478 |
Lab():L(0),a(128),b(128){}
|
|
479 |
Lab(float L1,float a1,float b1):L(L1),a(a1),b(b1){}
|
|
480 |
// Lab(Lab &lab1):L(lab1.L),a(lab1.a),b(lab1.b){}
|
|
481 |
void ToStr(CStringW &s1)
|
|
482 |
{
|
|
483 |
s1.Format(L"%.3f,%.3f,%.3f",L,a,b);
|
|
484 |
}
|
|
485 |
void ToStr(CStringA &s1)
|
|
486 |
{
|
|
487 |
s1.Format("%.3f,%.3f,%.3f",L,a,b);
|
|
488 |
}
|
|
489 |
/*
|
|
490 |
void FromStr(CStringW &s1)
|
|
491 |
{
|
|
492 |
_stscanf_s(s1.GetString(),_T("%f,%f,%f"),&L,&a,&b);
|
|
493 |
}
|
|
494 |
*/
|
|
495 |
void FromStr(CString &s1)
|
|
496 |
{
|
|
497 |
CString result[10];
|
|
498 |
Split(s1,_T(","),result);
|
|
499 |
L = float(_tstof(result[0]));
|
|
500 |
a = float(_tstof(result[1]));
|
|
501 |
b = float(_tstof(result[2]));
|
|
502 |
}
|
|
503 |
void ToRGB(COLORf &rgbf1)
|
|
504 |
{
|
|
505 |
rgbf1=LabToRGBf(*this);
|
|
506 |
}
|
|
507 |
void FromRGB(COLORf &c1f)
|
|
508 |
{
|
|
509 |
*this = RGBfToLab(c1f);
|
|
510 |
}
|
|
511 |
float DistanceTo(Lab lab2)
|
|
512 |
{
|
|
513 |
return sqrtf((lab2.L-L)*(lab2.L-L)+(lab2.a-a)*(lab2.a-a)+(lab2.b-b)*(lab2.b-b));
|
|
514 |
}
|
|
515 |
float Distance2To(Lab lab2)
|
|
516 |
{
|
|
517 |
return ((lab2.L-L)*(lab2.L-L)+(lab2.a-a)*(lab2.a-a)+(lab2.b-b)*(lab2.b-b));
|
|
518 |
}
|
|
519 |
};
|
|
520 |
|
|
521 |
class QMat
|
|
522 |
{
|
|
523 |
enum enumElementFormat
|
|
524 |
{
|
|
525 |
Default=0,
|
|
526 |
Q8Byte,
|
|
527 |
Q32F,
|
|
528 |
};
|
|
529 |
public:
|
|
530 |
int ElementFormat;
|
|
531 |
int Width;
|
|
532 |
int Height;
|
|
533 |
int stride;
|
|
534 |
void * buffer1;
|
|
535 |
void * buffer2;
|
|
536 |
QMat(){}
|
|
537 |
QMat(int x,int y,enumElementFormat eEF);
|
|
538 |
~QMat(){}
|
|
539 |
|
|
540 |
};
|
|
541 |
|
|
542 |
|
|
543 |
/*
|
|
544 |
int HSIinHSIs(HSI hsi,HSI hsi1,HSI hsi2);
|
|
545 |
int HSIinHSIst(HSI hsi,HSI HSI1,HSI hsi2,HSI Ht);
|
|
546 |
int HSIinHSIt(HSI hsi,HSI hsi1,HSI hsit);
|
|
547 |
int HSIinHSIsts(HSI hsi1,HSI hsi2,HSI hsi3,HSI Ht1,HSI ht2); //hsi1 in [hsi2,hsi3]
|
|
548 |
*/
|
|
549 |
|
|
550 |
//float Calk(HSI hsi0,HSI hsi1,HSI hsi2); //hsi0被测量点,hsi1,基准点1,hsi2,基准点2
|
|
551 |
//float CalPos(HSI HSI1);
|
|
552 |
//float CalHSIDistance(HSI hsi1, HSI hsi2);
|
|
553 |
|
|
554 |
//__m64 Get_m64(__int64 n);
|
|
555 |
|
|
556 |
/*
|
|
557 |
class QuadRectF
|
|
558 |
{
|
|
559 |
RectF Pt[4];
|
|
560 |
};
|
|
561 |
*/
|
|
562 |
///*
|
|
563 |
const BYTE RtoVI[256]=
|
|
564 |
{0,0,0,0,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,5,6,6,6,7,7,7,8,8,8,8,9,9,9,10,10,10,11,11,11,11,12,12,12,13,13,13,
|
|
565 |
14,14,14,14,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,20,20,20,20,21,21,21,22,22,22,23,23,23,23,24,24,
|
|
566 |
24,25,25,25,26,26,26,26,27,27,27,28,28,28,29,29,29,29,30,30,30,31,31,31,31,32,32,32,33,33,33,34,34,34,34,35,
|
|
567 |
35,35,36,36,36,37,37,37,37,38,38,38,39,39,39,40,40,40,40,41,41,41,42,42,42,43,43,43,43,44,44,44,45,45,45,46,
|
|
568 |
46,46,46,47,47,47,48,48,48,49,49,49,49,50,50,50,51,51,51,52,52,52,52,53,53,53,54,54,54,55,55,55,55,56,56,56,
|
|
569 |
57,57,57,58,58,58,58,59,59,59,60,60,60,60,61,61,61,62,62,62,63,63,63,63,64,64,64,65,65,65,66,66,66,66,67,67,
|
|
570 |
67,68,68,68,69,69,69,69,70,70,70,71,71,71,72,72,72,72,73,73,73,74,74,74,75,75,75,75,76,};
|
|
571 |
const BYTE GtoVI[256]=
|
|
572 |
{0,0,1,1,2,2,3,4,4,5,5,6,7,7,8,8,9,9,10,11,11,12,12,13,14,14,15,15,16,17,17,18,18,19,19,20,21,21,22,22,23,24,24,25,25,26,27,27,
|
|
573 |
28,28,29,29,30,31,31,32,32,33,34,34,35,35,36,36,37,38,38,39,39,40,41,41,42,42,43,44,44,45,45,46,46,47,48,48,49,49,50,51,51,52,
|
|
574 |
52,53,54,54,55,55,56,56,57,58,58,59,59,60,61,61,62,62,63,63,64,65,65,66,66,67,68,68,69,69,70,71,71,72,72,73,73,74,75,75,76,76,
|
|
575 |
77,78,78,79,79,80,81,81,82,82,83,83,84,85,85,86,86,87,88,88,89,89,90,90,91,92,92,93,93,94,95,95,96,96,97,98,98,99,99,100,100,
|
|
576 |
101,102,102,103,103,104,105,105,106,106,107,108,108,109,109,110,110,111,112,112,113,113,114,115,115,116,116,117,117,118,119,
|
|
577 |
119,120,120,121,122,122,123,123,124,125,125,126,126,127,127,128,129,129,130,130,131,132,132,133,133,134,135,135,136,136,137,
|
|
578 |
137,138,139,139,140,140,141,142,142,143,143,144,144,145,146,146,147,147,148,149,149,};
|
|
579 |
const BYTE BtoVI[256]=
|
|
580 |
{0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,
|
|
581 |
7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,
|
|
582 |
12,12,13,13,13,13,13,13,13,13,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,17,17,17,17,17,
|
|
583 |
17,17,17,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,20,20,20,20,20,20,20,20,20,21,21,21,21,21,21,21,21,22,22,22,22,
|
|
584 |
22,22,22,22,22,23,23,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,25,25,25,25,25,25,25,25,25,26,26,26,26,26,26,26,26,27,27,
|
|
585 |
27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,29,};
|
|
586 |
//*/
|
|
587 |
const float RtoVf[256]=
|
|
588 |
{ 0.0*0.299f,1*0.299f,2*0.299f,3*0.299f,4*0.299f,5*0.299f,6*0.299f,7*0.299f,8*0.299f,9*0.299f,
|
|
589 |
10*0.299f,11*0.299f,12*0.299f,13*0.299f,14*0.299f,15*0.299f,16*0.299f,17*0.299f,18*0.299f,19*0.299f,
|
|
590 |
20*0.299f,21*0.299f,22*0.299f,23*0.299f,24*0.299f,25*0.299f,26*0.299f,27*0.299f,28*0.299f,29*0.299f,
|
|
591 |
30*0.299f,31*0.299f,32*0.299f,33*0.299f,34*0.299f,35*0.299f,36*0.299f,37*0.299f,38*0.299f,39*0.299f,
|
|
592 |
40*0.299f,41*0.299f,42*0.299f,43*0.299f,44*0.299f,45*0.299f,46*0.299f,47*0.299f,48*0.299f,49*0.299f,
|
|
593 |
50*0.299f,51*0.299f,52*0.299f,53*0.299f,54*0.299f,55*0.299f,56*0.299f,57*0.299f,58*0.299f,59*0.299f,
|
|
594 |
60*0.299f,61*0.299f,62*0.299f,63*0.299f,64*0.299f,65*0.299f,66*0.299f,67*0.299f,68*0.299f,69*0.299f,
|
|
595 |
70*0.299f,71*0.299f,72*0.299f,73*0.299f,74*0.299f,75*0.299f,76*0.299f,77*0.299f,78*0.299f,79*0.299f,
|
|
596 |
80*0.299f,81*0.299f,82*0.299f,83*0.299f,84*0.299f,85*0.299f,86*0.299f,87*0.299f,88*0.299f,89*0.299f,
|
|
597 |
90*0.299f,91*0.299f,92*0.299f,93*0.299f,94*0.299f,95*0.299f,96*0.299f,97*0.299f,98*0.299f,99*0.299f,
|
|
598 |
100*0.299f,101*0.299f,102*0.299f,103*0.299f,104*0.299f,105*0.299f,106*0.299f,107*0.299f,108*0.299f,109*0.299f,
|
|
599 |
110*0.299f,111*0.299f,112*0.299f,113*0.299f,114*0.299f,115*0.299f,116*0.299f,117*0.299f,118*0.299f,119*0.299f,
|
|
600 |
120*0.299f,121*0.299f,122*0.299f,123*0.299f,124*0.299f,125*0.299f,126*0.299f,127*0.299f,128*0.299f,129*0.299f,
|
|
601 |
130*0.299f,131*0.299f,132*0.299f,133*0.299f,134*0.299f,135*0.299f,136*0.299f,137*0.299f,138*0.299f,139*0.299f,
|
|
602 |
140*0.299f,141*0.299f,142*0.299f,143*0.299f,144*0.299f,145*0.299f,146*0.299f,147*0.299f,148*0.299f,149*0.299f,
|
|
603 |
150*0.299f,151*0.299f,152*0.299f,153*0.299f,154*0.299f,155*0.299f,156*0.299f,157*0.299f,158*0.299f,159*0.299f,
|
|
604 |
160*0.299f,161*0.299f,162*0.299f,163*0.299f,164*0.299f,165*0.299f,166*0.299f,167*0.299f,168*0.299f,169*0.299f,
|
|
605 |
170*0.299f,171*0.299f,172*0.299f,173*0.299f,174*0.299f,175*0.299f,176*0.299f,177*0.299f,178*0.299f,179*0.299f,
|
|
606 |
180*0.299f,181*0.299f,182*0.299f,183*0.299f,184*0.299f,185*0.299f,186*0.299f,187*0.299f,188*0.299f,189*0.299f,
|
|
607 |
190*0.299f,191*0.299f,192*0.299f,193*0.299f,194*0.299f,195*0.299f,196*0.299f,197*0.299f,198*0.299f,199*0.299f,
|
|
608 |
200*0.299f,201*0.299f,202*0.299f,203*0.299f,204*0.299f,205*0.299f,206*0.299f,207*0.299f,208*0.299f,209*0.299f,
|
|
609 |
210*0.299f,211*0.299f,212*0.299f,213*0.299f,214*0.299f,215*0.299f,216*0.299f,217*0.299f,218*0.299f,219*0.299f,
|
|
610 |
220*0.299f,221*0.299f,222*0.299f,223*0.299f,224*0.299f,225*0.299f,226*0.299f,227*0.299f,228*0.299f,229*0.299f,
|
|
611 |
230*0.299f,231*0.299f,232*0.299f,233*0.299f,234*0.299f,235*0.299f,236*0.299f,237*0.299f,238*0.299f,239*0.299f,
|
|
612 |
240*0.299f,241*0.299f,242*0.299f,243*0.299f,244*0.299f,245*0.299f,246*0.299f,247*0.299f,248*0.299f,249*0.299f,
|
|
613 |
250*0.299f,251*0.299f,252*0.299f,253*0.299f,254*0.299f,255*0.299f
|
|
614 |
};
|
|
615 |
|
|
616 |
const float GtoVf[256]=
|
|
617 |
{ 0.0*0.587f,1*0.587f,2*0.587f,3*0.587f,4*0.587f,5*0.587f,6*0.587f,7*0.587f,8*0.587f,9*0.587f,
|
|
618 |
10*0.587f,11*0.587f,12*0.587f,13*0.587f,14*0.587f,15*0.587f,16*0.587f,17*0.587f,18*0.587f,19*0.587f,
|
|
619 |
20*0.587f,21*0.587f,22*0.587f,23*0.587f,24*0.587f,25*0.587f,26*0.587f,27*0.587f,28*0.587f,29*0.587f,
|
|
620 |
30*0.587f,31*0.587f,32*0.587f,33*0.587f,34*0.587f,35*0.587f,36*0.587f,37*0.587f,38*0.587f,39*0.587f,
|
|
621 |
40*0.587f,41*0.587f,42*0.587f,43*0.587f,44*0.587f,45*0.587f,46*0.587f,47*0.587f,48*0.587f,49*0.587f,
|
|
622 |
50*0.587f,51*0.587f,52*0.587f,53*0.587f,54*0.587f,55*0.587f,56*0.587f,57*0.587f,58*0.587f,59*0.587f,
|
|
623 |
60*0.587f,61*0.587f,62*0.587f,63*0.587f,64*0.587f,65*0.587f,66*0.587f,67*0.587f,68*0.587f,69*0.587f,
|
|
624 |
70*0.587f,71*0.587f,72*0.587f,73*0.587f,74*0.587f,75*0.587f,76*0.587f,77*0.587f,78*0.587f,79*0.587f,
|
|
625 |
80*0.587f,81*0.587f,82*0.587f,83*0.587f,84*0.587f,85*0.587f,86*0.587f,87*0.587f,88*0.587f,89*0.587f,
|
|
626 |
90*0.587f,91*0.587f,92*0.587f,93*0.587f,94*0.587f,95*0.587f,96*0.587f,97*0.587f,98*0.587f,99*0.587f,
|
|
627 |
100*0.587f,101*0.587f,102*0.587f,103*0.587f,104*0.587f,105*0.587f,106*0.587f,107*0.587f,108*0.587f,109*0.587f,
|
|
628 |
110*0.587f,111*0.587f,112*0.587f,113*0.587f,114*0.587f,115*0.587f,116*0.587f,117*0.587f,118*0.587f,119*0.587f,
|
|
629 |
120*0.587f,121*0.587f,122*0.587f,123*0.587f,124*0.587f,125*0.587f,126*0.587f,127*0.587f,128*0.587f,129*0.587f,
|
|
630 |
130*0.587f,131*0.587f,132*0.587f,133*0.587f,134*0.587f,135*0.587f,136*0.587f,137*0.587f,138*0.587f,139*0.587f,
|
|
631 |
140*0.587f,141*0.587f,142*0.587f,143*0.587f,144*0.587f,145*0.587f,146*0.587f,147*0.587f,148*0.587f,149*0.587f,
|
|
632 |
150*0.587f,151*0.587f,152*0.587f,153*0.587f,154*0.587f,155*0.587f,156*0.587f,157*0.587f,158*0.587f,159*0.587f,
|
|
633 |
160*0.587f,161*0.587f,162*0.587f,163*0.587f,164*0.587f,165*0.587f,166*0.587f,167*0.587f,168*0.587f,169*0.587f,
|
|
634 |
170*0.587f,171*0.587f,172*0.587f,173*0.587f,174*0.587f,175*0.587f,176*0.587f,177*0.587f,178*0.587f,179*0.587f,
|
|
635 |
180*0.587f,181*0.587f,182*0.587f,183*0.587f,184*0.587f,185*0.587f,186*0.587f,187*0.587f,188*0.587f,189*0.587f,
|
|
636 |
190*0.587f,191*0.587f,192*0.587f,193*0.587f,194*0.587f,195*0.587f,196*0.587f,197*0.587f,198*0.587f,199*0.587f,
|
|
637 |
200*0.587f,201*0.587f,202*0.587f,203*0.587f,204*0.587f,205*0.587f,206*0.587f,207*0.587f,208*0.587f,209*0.587f,
|
|
638 |
210*0.587f,211*0.587f,212*0.587f,213*0.587f,214*0.587f,215*0.587f,216*0.587f,217*0.587f,218*0.587f,219*0.587f,
|
|
639 |
220*0.587f,221*0.587f,222*0.587f,223*0.587f,224*0.587f,225*0.587f,226*0.587f,227*0.587f,228*0.587f,229*0.587f,
|
|
640 |
230*0.587f,231*0.587f,232*0.587f,233*0.587f,234*0.587f,235*0.587f,236*0.587f,237*0.587f,238*0.587f,239*0.587f,
|
|
641 |
240*0.587f,241*0.587f,242*0.587f,243*0.587f,244*0.587f,245*0.587f,246*0.587f,247*0.587f,248*0.587f,249*0.587f,
|
|
642 |
250*0.587f,251*0.587f,252*0.587f,253*0.587f,254*0.587f,255*0.587f
|
|
643 |
};
|
|
644 |
const float BtoVf[256]=
|
|
645 |
{ 0.0*0.114f,1*0.114f,2*0.114f,3*0.114f,4*0.114f,5*0.114f,6*0.114f,7*0.114f,8*0.114f,9*0.114f,
|
|
646 |
10*0.114f,11*0.114f,12*0.114f,13*0.114f,14*0.114f,15*0.114f,16*0.114f,17*0.114f,18*0.114f,19*0.114f,
|
|
647 |
20*0.114f,21*0.114f,22*0.114f,23*0.114f,24*0.114f,25*0.114f,26*0.114f,27*0.114f,28*0.114f,29*0.114f,
|
|
648 |
30*0.114f,31*0.114f,32*0.114f,33*0.114f,34*0.114f,35*0.114f,36*0.114f,37*0.114f,38*0.114f,39*0.114f,
|
|
649 |
40*0.114f,41*0.114f,42*0.114f,43*0.114f,44*0.114f,45*0.114f,46*0.114f,47*0.114f,48*0.114f,49*0.114f,
|
|
650 |
50*0.114f,51*0.114f,52*0.114f,53*0.114f,54*0.114f,55*0.114f,56*0.114f,57*0.114f,58*0.114f,59*0.114f,
|
|
651 |
60*0.114f,61*0.114f,62*0.114f,63*0.114f,64*0.114f,65*0.114f,66*0.114f,67*0.114f,68*0.114f,69*0.114f,
|
|
652 |
70*0.114f,71*0.114f,72*0.114f,73*0.114f,74*0.114f,75*0.114f,76*0.114f,77*0.114f,78*0.114f,79*0.114f,
|
|
653 |
80*0.114f,81*0.114f,82*0.114f,83*0.114f,84*0.114f,85*0.114f,86*0.114f,87*0.114f,88*0.114f,89*0.114f,
|
|
654 |
90*0.114f,91*0.114f,92*0.114f,93*0.114f,94*0.114f,95*0.114f,96*0.114f,97*0.114f,98*0.114f,99*0.114f,
|
|
655 |
100*0.114f,101*0.114f,102*0.114f,103*0.114f,104*0.114f,105*0.114f,106*0.114f,107*0.114f,108*0.114f,109*0.114f,
|
|
656 |
110*0.114f,111*0.114f,112*0.114f,113*0.114f,114*0.114f,115*0.114f,116*0.114f,117*0.114f,118*0.114f,119*0.114f,
|
|
657 |
120*0.114f,121*0.114f,122*0.114f,123*0.114f,124*0.114f,125*0.114f,126*0.114f,127*0.114f,128*0.114f,129*0.114f,
|
|
658 |
130*0.114f,131*0.114f,132*0.114f,133*0.114f,134*0.114f,135*0.114f,136*0.114f,137*0.114f,138*0.114f,139*0.114f,
|
|
659 |
140*0.114f,141*0.114f,142*0.114f,143*0.114f,144*0.114f,145*0.114f,146*0.114f,147*0.114f,148*0.114f,149*0.114f,
|
|
660 |
150*0.114f,151*0.114f,152*0.114f,153*0.114f,154*0.114f,155*0.114f,156*0.114f,157*0.114f,158*0.114f,159*0.114f,
|
|
661 |
160*0.114f,161*0.114f,162*0.114f,163*0.114f,164*0.114f,165*0.114f,166*0.114f,167*0.114f,168*0.114f,169*0.114f,
|
|
662 |
170*0.114f,171*0.114f,172*0.114f,173*0.114f,174*0.114f,175*0.114f,176*0.114f,177*0.114f,178*0.114f,179*0.114f,
|
|
663 |
180*0.114f,181*0.114f,182*0.114f,183*0.114f,184*0.114f,185*0.114f,186*0.114f,187*0.114f,188*0.114f,189*0.114f,
|
|
664 |
190*0.114f,191*0.114f,192*0.114f,193*0.114f,194*0.114f,195*0.114f,196*0.114f,197*0.114f,198*0.114f,199*0.114f,
|
|
665 |
200*0.114f,201*0.114f,202*0.114f,203*0.114f,204*0.114f,205*0.114f,206*0.114f,207*0.114f,208*0.114f,209*0.114f,
|
|
666 |
210*0.114f,211*0.114f,212*0.114f,213*0.114f,214*0.114f,215*0.114f,216*0.114f,217*0.114f,218*0.114f,219*0.114f,
|
|
667 |
220*0.114f,221*0.114f,222*0.114f,223*0.114f,224*0.114f,225*0.114f,226*0.114f,227*0.114f,228*0.114f,229*0.114f,
|
|
668 |
230*0.114f,231*0.114f,232*0.114f,233*0.114f,234*0.114f,235*0.114f,236*0.114f,237*0.114f,238*0.114f,239*0.114f,
|
|
669 |
240*0.114f,241*0.114f,242*0.114f,243*0.114f,244*0.114f,245*0.114f,246*0.114f,247*0.114f,248*0.114f,249*0.114f,
|
|
670 |
250*0.114f,251*0.114f,252*0.114f,253*0.114f,254*0.114f,255*0.114f
|
|
671 |
};
|
|
672 |
|
|
673 |
#define RGBtoVI(R,G,B) (RtoVI[int(R)]+GtoVI[int(G)]+BtoVI[int(B)])
|
|
674 |
#define RGBtoVf(R,G,B) ((R)*0.299f+(G)*0.587f+(B)*0.114f)
|
|
675 |
struct TransFormThreadDataStruct
|
|
676 |
{
|
|
677 |
int ThreadNo;
|
|
678 |
volatile int Running;
|
|
679 |
volatile int Done;
|
|
680 |
UINT * srcpixels;
|
|
681 |
int srcstride;
|
|
682 |
UINT * destpixels;
|
|
683 |
int deststride;
|
|
684 |
int srcw;
|
|
685 |
int srch;
|
|
686 |
Gdiplus::PointF srcpt[4];
|
|
687 |
Gdiplus::Rect destrect;
|
|
688 |
int starth;
|
|
689 |
int endh;
|
|
690 |
};
|
|
691 |
UINT __cdecl TransFormThread(LPVOID pParam);
|
|
692 |
|
|
693 |
class HistoGram
|
|
694 |
{
|
|
695 |
public:
|
|
696 |
int totalpixels;
|
|
697 |
int maxRsample,maxRsampleindex;
|
|
698 |
int maxGsample,maxGsampleindex;
|
|
699 |
int maxBsample,maxBsampleindex;
|
|
700 |
int maxVsample,maxVsampleindex;
|
|
701 |
int minRvalue,maxRvalue;
|
|
702 |
int minGvalue,maxGvalue;
|
|
703 |
int minBvalue,maxBvalue;
|
|
704 |
int minVvalue,maxVvalue;
|
|
705 |
DWORD totalRvalues,totalGvalues,totalBvalues,totalVvalues;
|
|
706 |
float aveRvalue,aveGvalue,aveBvalue,aveVvalue; //平均值
|
|
707 |
float mostRvalue,mostGvalue,mostBvalue; //大部分,去掉最高和最低剩余的。
|
|
708 |
float midRvalue,midGvalue,midBvalue,midVvalue; //中位数
|
|
709 |
int Rsamples[256],Gsamples[256],Bsamples[256],Vsamples[256];
|
|
710 |
int MakeHistoGram(Gdiplus::Bitmap * bitmap, int startx=0, int starty=0, int width=0, int height=0);
|
|
711 |
int getRpercentvalue(float percent);
|
|
712 |
int getGpercentvalue(float percent);
|
|
713 |
int getBpercentvalue(float percent);
|
|
714 |
int getVpercentvalue(float percent);
|
|
715 |
float GetMostRvalue(); //取得
|
|
716 |
float GetMostGvalue(); //取得
|
|
717 |
float GetMostBvalue(); //取得
|
|
718 |
|
|
719 |
};
|
|
720 |
class cBlackFix
|
|
721 |
{
|
|
722 |
public:
|
|
723 |
int IsBlackFixInited;
|
|
724 |
int Width;
|
|
725 |
int Height;
|
|
726 |
MyImage BlackFixImage;
|
|
727 |
cBlackFix()
|
|
728 |
{
|
|
729 |
IsBlackFixInited=0;
|
|
730 |
}
|
|
731 |
cBlackFix(CString sFilePathName)
|
|
732 |
{
|
|
733 |
BlackFixImage.LoadFromBitmapFile(sFilePathName);
|
|
734 |
Width=BlackFixImage.Width;
|
|
735 |
Height=BlackFixImage.Height;
|
|
736 |
IsBlackFixInited=1;
|
|
737 |
}
|
|
738 |
int LoadFixFile(CString sFilePathName)
|
|
739 |
{
|
|
740 |
int j=BlackFixImage.LoadFromBitmapFile(sFilePathName);
|
|
741 |
Width=BlackFixImage.Width;
|
|
742 |
Height=BlackFixImage.Height;
|
|
743 |
if (Width>0&&Height>0)
|
|
744 |
{
|
|
745 |
IsBlackFixInited=1;
|
|
746 |
return 0;
|
|
747 |
}else
|
|
748 |
{
|
|
749 |
IsBlackFixInited=0;
|
|
750 |
return -1;
|
|
751 |
}
|
|
752 |
}
|
|
753 |
int Fix(MyImage & theImage)
|
|
754 |
{
|
|
755 |
if (!IsBlackFixInited)
|
|
756 |
{
|
|
757 |
return -1;
|
|
758 |
}
|
|
759 |
if (theImage.Width!=Width||theImage.Height!=Height)
|
|
760 |
{
|
|
761 |
return -2;
|
|
762 |
}
|
|
763 |
unsigned char *dstbuf=(unsigned char *)theImage.buffer;
|
|
764 |
unsigned char *thisbuf=(unsigned char *)BlackFixImage.buffer;
|
|
765 |
for (int i=0;i<Height;i++)
|
|
766 |
{
|
|
767 |
int k=i*BlackFixImage.Stride;
|
|
768 |
int l=i*theImage.Stride;
|
|
769 |
for (int j=0;j<Width;j++)
|
|
770 |
{
|
|
771 |
unsigned char thepixel;
|
|
772 |
unsigned char fixpixel;
|
|
773 |
unsigned char newpixel;
|
|
774 |
fixpixel=thisbuf[k+j];
|
|
775 |
thepixel=dstbuf[l+j];
|
|
776 |
if (fixpixel>=80) {newpixel=dstbuf[l+j-1];}
|
|
777 |
else if (thepixel>=fixpixel) {newpixel=thepixel-fixpixel;}
|
|
778 |
else {newpixel=0;}
|
|
779 |
dstbuf[l+j]=newpixel;
|
|
780 |
};
|
|
781 |
}
|
|
782 |
return 0;
|
|
783 |
}
|
|
784 |
};
|
|
785 |
|
|
786 |
class SecWhiteBalance
|
|
787 |
{
|
|
788 |
public:
|
|
789 |
const static int wbxsecs=256;
|
|
790 |
const static int wbysecs=192;
|
|
791 |
int wbsectotalR[256][256];
|
|
792 |
int wbsectotalG[256][256];
|
|
793 |
int wbsectotalB[256][256];
|
|
794 |
int wbsectotalG2[256][256];
|
|
795 |
|
|
796 |
int wbsecsamples[256][256];
|
|
797 |
// float bright[256][256];
|
|
798 |
float wbsecR[256][256];
|
|
799 |
float wbsecG[256][256];
|
|
800 |
float wbsecB[256][256];
|
|
801 |
float wbsecG2[256][256];
|
|
802 |
|
|
803 |
float wbsecRcorr[256][256];
|
|
804 |
float wbsecGcorr[256][256];
|
|
805 |
float wbsecBcorr[256][256];
|
|
806 |
float wbsecG2corr[256][256];
|
|
807 |
|
|
808 |
float wbaveR;
|
|
809 |
float wbaveG;
|
|
810 |
float wbaveB;
|
|
811 |
float wbaveG2;
|
|
812 |
float wbtotalV;
|
|
813 |
float wbaveV;
|
|
814 |
float TargetLight;
|
|
815 |
float TargetLightR;
|
|
816 |
float TargetLightG;
|
|
817 |
float TargetLightB;
|
|
818 |
float TargetLightG2;
|
|
819 |
|
|
820 |
int wbcorrloaded;
|
|
821 |
int autowbcorronopen;
|
|
822 |
float BrightnessCorr;
|
|
823 |
public:
|
|
824 |
SecWhiteBalance()
|
|
825 |
{
|
|
826 |
wbcorrloaded=0;
|
|
827 |
autowbcorronopen=1;
|
|
828 |
BrightnessCorr=1.0f;
|
|
829 |
TargetLight=128.0f;
|
|
830 |
}
|
|
831 |
~SecWhiteBalance()
|
|
832 |
{
|
|
833 |
|
|
834 |
}
|
|
835 |
int LoadWBParamFromFile(CString sFilePathName);
|
|
836 |
int ReadWBParamFromBmp(Gdiplus::Bitmap * bitmap1);
|
|
837 |
int LoadBayerWBParamFromFile(CString sFilePathName);
|
|
838 |
int ReadBayerWBParamFromBmp(Gdiplus::Bitmap * bitmap1);
|
|
839 |
|
|
840 |
// int WBCorrect1(Gdiplus::Bitmap * bitmap1);
|
|
841 |
int WBCorrect(Gdiplus::Bitmap * bitmap1,Gdiplus::Bitmap * bitmap2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
842 |
int WBCorrectVC(Gdiplus::Bitmap * bitmap1,Gdiplus::Bitmap * bitmap2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
843 |
int WBCorrect1VC(Gdiplus::Bitmap * bitmap1,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
844 |
int WBCorrect2VC(Gdiplus::Bitmap * bitmap1,Gdiplus::Bitmap * bitmap2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
845 |
|
|
846 |
int WBBayerCorrect(MyImage * Image1,MyImage * Image2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
847 |
int WBBayerCorrectVC(MyImage * Image1,MyImage * Image2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
848 |
int WBBayerCorrect1VC(void * buf1,int w,int h,int stride,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
849 |
int WBBayerCorrect2VC(MyImage * Image1,MyImage * Image2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0);
|
|
850 |
};
|
|
851 |
|
|
852 |
|
|
853 |
struct MemcpyThreadDataStruct
|
|
854 |
{
|
|
855 |
void * src;
|
|
856 |
void * dest;
|
|
857 |
unsigned long size;
|
|
858 |
volatile int done;
|
|
859 |
};
|
|
860 |
|
|
861 |
struct PointD
|
|
862 |
{
|
|
863 |
double x,y;
|
|
864 |
PointD ():x(0),y(0) {}
|
|
865 |
PointD (double x1,double y1):x(x1),y(y1) {}
|
|
866 |
PointD & operator=(PointD & d1)
|
|
867 |
{
|
|
868 |
x=d1.x;y=d1.y;
|
|
869 |
return *this;
|
|
870 |
}
|
|
871 |
PointD operator +(PointD & d1)
|
|
872 |
{
|
|
873 |
return PointD(x+d1.x,y+d1.y);
|
|
874 |
}
|
|
875 |
PointD operator -(PointD & d1)
|
|
876 |
{
|
|
877 |
return PointD(x-d1.x,y-d1.y);
|
|
878 |
}
|
|
879 |
PointD operator *(double n)
|
|
880 |
{
|
|
881 |
return PointD(x*n,y*n);
|
|
882 |
}
|
|
883 |
PointD operator /(double n)
|
|
884 |
{
|
|
885 |
return PointD(x/n,y/n);
|
|
886 |
}
|
|
887 |
PointD Miror(PointD & pt1) //求相对于目标点对称的点
|
|
888 |
{
|
|
889 |
return pt1*2-(*this);
|
|
890 |
}
|
|
891 |
double DistanceTo(PointD & pt1) //计算到点的距离
|
|
892 |
{
|
|
893 |
return sqrt((x-pt1.x)*(x-pt1.x)+(y-pt1.y)*(y-pt1.y));
|
|
894 |
}
|
|
895 |
double CalR(PointD pt1) //计算以当前点为起点,到终点的连线的角度。
|
|
896 |
{
|
|
897 |
return asin(pt1.y-y/DistanceTo(pt1));
|
|
898 |
}
|
|
899 |
};
|
|
900 |
struct MyLineSegment
|
|
901 |
{
|
|
902 |
PointD start,end;
|
|
903 |
MyLineSegment():start(0,0),end(0,0){};
|
|
904 |
MyLineSegment (PointD d1,PointD d2):start(d1),end(d2) {start=d1;end=d2;};
|
|
905 |
void SetStartEnd(PointD d1,PointD d2){start=d1;end=d2;};
|
|
906 |
void SetStartEnd(double startx,double starty,double endx,double endy){start.x=startx,start.y=starty,end.x=endx,end.y=endy;};
|
|
907 |
};
|
|
908 |
void fastmemcpy(void* dest, const void* src, const unsigned long size_t);
|
|
909 |
|
|
910 |
void fastmemcpyMT(void* dest, const void* src, const unsigned long size_t);
|
|
911 |
|
|
912 |
int GetLineSegmentPart(double startx, double starty, double endx, double endy, double numerator, double denominator, double & x1, double & y1);
|
|
913 |
double LineSegmentDirection(PointD pt1,PointD pt2,PointD pt3);
|
|
914 |
int IsOnLineSegment(MyLineSegment linesegment1,PointD pt1);
|
|
915 |
int IsLineSegmentCross(MyLineSegment linesegment1, MyLineSegment linesegment2);
|
|
916 |
int IsLineSegmentCross(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4);
|
|
917 |
struct stHoughResult
|
|
918 |
{
|
|
919 |
int Score;
|
|
920 |
PointD Pt;
|
|
921 |
};
|
|
922 |
int Hough(MyImage& img1,stHoughResult res[],int MaxFound, double Threshold,int starta,int enda);
|
|
923 |
int NewHough(MyImage& img1,stHoughResult res[],int MaxFound, double Threshold,int starta,int enda);
|
|
924 |
int TransRGBToBayerGR(Gdiplus::Bitmap * bitmap1,CString sFilePathname);
|
|
925 |
int TransRGBToBayerGR2(Gdiplus::Bitmap * bitmap1,CString sFilePathname);
|
|
926 |
int TransRGBToBayerGR3(Gdiplus::Bitmap * bitmap1,CString sFilePathname);
|
|
927 |
|
|
928 |
struct DftFilterPos
|
|
929 |
{
|
|
930 |
double x;
|
|
931 |
double y;
|
|
932 |
double w;
|
|
933 |
double h;
|
|
934 |
};
|
|
935 |
|
|
936 |
int fdf1(double * pData, int width, int height, DftFilterPos filterPos[], int filterPosCount, int showstatus);
|
|
937 |
|
|
938 |
|
|
939 |
//---------------------------------------------------------------------------------------------------
|