//**********************************************// //Image Function File //V1.02 //2017-04-26 // //**********************************************// #pragma once #include #include //#include //#include //#include //#include //#include #include "../../MyLib/Functions.hpp" //#include "MyImage.h" #include struct Complexf; union COLOR; union COLORf; struct HSI; struct Lab; //class MyImage; class QMat; //matrix; class MyImage { // Bitmask value of the monochrome type. Internal use only. #define MyPIXEL_MONO 0x01000000 // Bitmask value of the color pixel type. Internal use only. #define MyPIXEL_COLOR 0x02000000 // Sets the bit count of pixel type. Internal use only. #define MyPIXEL_BIT_COUNT(n) ((n) << 16) public: enum eMyPixelType { NDEF=0, MyPixelType_Mono8, MyPixelType_Mono8signed, MyPixelType_Mono10, MyPixelType_Mono10packed, MyPixelType_Mono12, MyPixelType_Mono12packed, MyPixelType_Mono16, MyPixelType_BayerGB8, MyPixelType_BayerBG8, MyPixelType_BayerGR8, MyPixelType_BayerRG8, MyPixelType_BayerGB10, MyPixelType_BayerBG10, MyPixelType_BayerGR10, MyPixelType_BayerRG10, MyPixelType_BayerGB12, MyPixelType_BayerBG12, MyPixelType_BayerGR12, MyPixelType_BayerRG12, MyPixelType_BayerGB12_Packed, MyPixelType_BayerBG12_Packed, MyPixelType_BayerGR12_Packed, MyPixelType_BayerRG12_Packed, MyPixelType_RGB8packed, MyPixelType_BGR8packed, MyPixelType_RGBA8packed, MyPixelType_BGRA8packed, MyPixelType_RGB10packed, MyPixelType_BGR10packed, MyPixelType_RGB12packed, MyPixelType_BGR12packed, MyPixelType_RGB8planar, MyPixelType_RGB10planar, MyPixelType_RGB12planar, MyPixelType_RGB16planar, MyPixelType_BayerGB16, MyPixelType_BayerBG16, MyPixelType_BayerGR16, MyPixelType_BayerRG16, MyPixelType_YUV411packed, MyPixelType_YUV422packed, MyPixelType_YUV422_YUYV_Packed, MyPixelType_YUV444packed, MyPixelType_Float, // MyPixelType_RGB16, // MyPixelType_RGB24, MyPixelType_ARGB32, }; enum enumPixelFormatConst { Default=0, Mono8=1, }; public: int PixelFormat; //ÏñËظñʽ int Width; //¿í¶È int Height; //¸ß¶È static const int Stride_Align=4; //¶ÔÆëÊý int Stride; //Ðпí int BPP; //ÑÕÉ«Éî¶È int IsValid; //ÊÇ·ñÓÐЧ void * buffer0; //ÉêÇëÊý¾ÝÖ¸Õë void * buffer; //Êý¾Ý´æ´¢Ö¸Õë void * buffer2; void * buffer3; int HistoArray[256]; //Ö±·½Í¼Êý¾Ý int HistoMaxCount; //×î´óÖ±·½Í¼ÊýÁ¿£» int MaxHistoIndex; //×î´óÖ±·½Í¼Ë÷Òý int IsHistoValid; //Ö±·½Í¼ÓÐЧ int SN; CString Name; CString InfoStr; CString ResultStr; Gdiplus::Bitmap * ShowCache; int IsToRefreshCache; int bIsLookUpTable; USHORT ULookUpTable[256]; //ÄæÏò²éÕÒ±í struct MyPoint { int X; int Y; MyPoint(){ X = 0; Y = 0; } }; struct MyRegion { int IsValid; CString RegionStr; DWORD RegionColor; std::vector pts; MyRegion& operator=(const MyRegion& MyRegion1) { IsValid = MyRegion1.IsValid; pts.assign(MyRegion1.pts.begin(), MyRegion1.pts.end()); return *this; }; int PtInMyRegion(MyPoint pt1) { int minx, miny, maxx, maxy; int k = (int)pts.size(); if (k > 0) { MyPoint thispt = pts.at(0); minx = thispt.X; maxx = thispt.X; miny = thispt.Y; maxy = thispt.Y; } for (int i = 1; i < k; i++) { MyPoint thispt = pts.at(i); if (thispt.X < minx) { minx = thispt.X; } if (thispt.X > maxx) { maxx = thispt.X; } if (thispt.Y < miny) { miny = thispt.Y; } if (thispt.Y > maxy) { maxy = thispt.Y; } } if (pt1.X < minx) return false; if (pt1.X > maxx) return false; if (pt1.Y < miny) return false; if (pt1.Y > maxy) return false; int count = 0; for (int i = 0, j = k - 1; i < k; j = i++) { MyPoint & tpt1 = pts.at(i); MyPoint & tpt2 = pts.at(j); if ((tpt1.Y > pt1.Y) != (tpt2.Y>pt1.Y)) { if (pt1.X<(tpt2.X - tpt1.X)*(pt1.Y - tpt1.Y) / (tpt2.Y-tpt1.Y)+tpt1.X) { count++; } } } if (count % 2) return true; return false; } }; std::vector myregions; struct stThumbImg { int IsValid; int nWidth; int nHeight; void * buffer; }m_thumbImg; // boost::shared_array; MyImage() { buffer0=NULL; buffer=NULL; buffer2 = NULL; buffer3 = NULL; IsValid=false; IsHistoValid=0; HistoMaxCount=0; MaxHistoIndex=0; m_thumbImg.IsValid = false; m_thumbImg.buffer = NULL; ShowCache = NULL; IsToRefreshCache = 0; } ~MyImage() { Destory(); } int AllocBuf(int width,int height,int stride=0,int PixelFormat1=MyPixelType_Mono8); int Destory() { if (buffer0!=NULL) { IsValid=false; delete [] buffer0; buffer0=NULL; buffer=NULL; } if (buffer2 != NULL) {delete[] buffer2; } if (buffer3 != NULL) delete [] buffer3; if (m_thumbImg.IsValid) { delete[] m_thumbImg.buffer; m_thumbImg.buffer = 0; } if (ShowCache!=NULL) { ::delete ShowCache; } return true; } void Clear(int Color=0) { memset(buffer,Color,Stride*Height); HistoMaxCount=0; MaxHistoIndex=0; IsHistoValid=0; } MyImage(const MyImage& Image1) { *this = Image1; } MyImage& operator=(const MyImage& Image1) { CopyFromBuf(Image1.buffer,Image1.Width,Image1.Height,Image1.Stride,Image1.PixelFormat); this->SN=Image1.SN; this->Name=Image1.Name; this->IsHistoValid=Image1.IsHistoValid; this->MaxHistoIndex=Image1.MaxHistoIndex; this->HistoMaxCount=Image1.HistoMaxCount; for (int i=0;i<256;i++) this->HistoArray[i]=Image1.HistoArray[i]; return *this; } int GetWidth(){return Width;} int GetHeight(){return Height;} int GetStride(){return Stride;} int GetBPP(){return BPP;} int GetPixelFormat(){return PixelFormat;} int CopyFromBuf(void * buf, int w, int h, int stride, int pixelformat); int CopyFromBufR90(void * buf, int w, int h, int stride, int pixelformat); int CopyFromGdipBitMap(Gdiplus::Bitmap * bitmap1); void * GetBuffer(){ return buffer;} int DrawOnWindow(HWND hWnd,int Brightness=0,int Contrast=0); int LoadFromBitmapFile(CString sFilePathName); int SaveToFile(CString sFilePathName); int LoadRegionFromFile(CString sFilePathName); int SaveRegionToFile(CString sFilePathName); int ConvertTypeToGdipBitmap32(Gdiplus::Bitmap** bitmapdest,int Brightness=0,int Contrast=0); int CreateThumbImg(int w=0, int h=0,float startx=0,float starty=0,float Width=0,float Height=0); int DrawThumbOnWindow(HWND hWnd, int Brightness = 0, int Contrast = 0); int ConvertThumbToGdipBitmap32(Gdiplus::Bitmap** bitmapdest, int Brightness = 0, int Contrast = 0); int Meg3ImgIntoRGB8planar(MyImage & img1, MyImage &img2, MyImage & img3); int Meg3ImgIntoRGB(MyImage & img1, MyImage &img2, MyImage & img3); void RefreshShowCache(){ IsToRefreshCache = 1; }; }; double GetTickCountmS(); WCHAR* ToWChar(char * str) ; int GetEncoderClsid(const WCHAR* format, CLSID* pClsid); //int Split(CString s1,CString divider,CString resultstr[]); int GdipDrawRoundRect(Gdiplus::Graphics &gr1, Gdiplus::Pen &pen1, int x1, int y1, int x2, int y2, int r); HSI RGBToHSI(COLOR c1); HSI RGBfToHSI(COLORf &c1f); Lab RGBfToLab(COLORf &c1f); COLORf LabToRGBf(Lab lab1); DWORD HSIToRGB(HSI hsi1); COLORf HSIToRGBf(HSI hsi1); int BayerGR8toRGB32(void * srcbuf,void * destbuf,int width,int height,int stride,int stride2=0); int BayerGB8toRGB32(void * srcbuf,void * destbuf,int width,int height,int stride,int stride2=0); int BayerGB8toRGB24(void * srcbuf,void * destbuf,int width,int height,int stride,int stride2=0); /* Translate From BayerGB12Mode To RGB8:8:8:8 Mode */ int BayerGB12PackedToRGB32(void * destbuf,void * srcbuf,int width,int height,float gamma); int Raw12toRaw16(void * destbuf,void * srcbuf,int width,int height); int Raw12ToRaw8(void * dest, void * src, int width, int height); int BayerGB16toRGB64(void * destbuf,void * srcbuf,int width,int height); int BayerGB12toRGB64(void * destbuf,void * srcbuf,int width,int height); int RGB32toRGB64(void * destbuf,void * srcbuf,int width,int height); int RGB64toRGB32(void * destbuf,void * srcbuf,int width,int height); int QuadRectTransForm(Gdiplus::Bitmap* bitmapsrc,Gdiplus::PointF srcpt[4],Gdiplus::Bitmap * bitmapdest,Gdiplus::Rect destrect); int QuadRectTransForm(Gdiplus::Bitmap* bitmapsrc,Gdiplus::Point srcpt[4],Gdiplus::Bitmap * bitmapdest,Gdiplus::Rect destrect); int QuadRectTransForm(Gdiplus::Bitmap* bitmapsrc,POINT srcpt[4],Gdiplus::Bitmap * bitmapdest,Gdiplus::Rect destrect); int DrawBitmapOnWindow(HWND DestWindow,Gdiplus::Bitmap* srcbitmap,CString * Lable=0, CString * ResultStr=0, double scale=0); int DrawImageOnWindow(HWND DestWindow, Gdiplus::Image* srcimage, CString * Lable = 0, CString * ResultStr = 0, double scale = 0); int nihe(CPoint pt5[100], int pt5total, int pt5valid[100]); int juanji(int incount,int corecount,double * inbuf, double * outbuf,double *corebuf); int juanjiV(int incount,int corecount,int stride, int x, double inbuf[], double outbuf[],double corebuf[]); int juanji2D(double inbuf[], int sizex, int sizey, int stride, double outbuf[], double corebuf[], int coresizex, int coresizey, int corestrie); template int juanji2D3x3(T inbuf[], int sizex, int sizey, int stride, T outbuf[], T corebuf[3][3]); //int juanji2D3x3(float inbuf[], int sizex, int sizey, int stride, float outbuf[], float corebuf[3][3]); //int juanji2D3x3(double inbuf[], int sizex, int sizey, int stride, double outbuf[], double corebuf[3][3]); int DCT(double pt[], double dpt[],int size,int start,int end); int DCT(float pt[], float dpt[],int size,int start,int end); int FDCT(double pt[], double dpt[],int size,int start,int end); int FDCT(float pt[], float dpt[],int size,int start,int end); int FFDCT(double pt[], double dpt[],int size,int start,int end); int FFDCT(float pt[], float dpt[],int size,int start,int end); int SaveBufferToFile(void *pBuf, size_t nSize, CString sFilePathName); int SaveBufferToBmpFile(void * buf1,int width, int height, int stride, CString FilePathName,LONG XPelsPerMeter=0,LONG YPelsPerMeter=0); int SaveGdiPImageAsFile(Gdiplus::Bitmap * bitmap1, CString sFileName, double Ratio=1.0,int Quality=70); int SaveGdiPImageAsBuffer(Gdiplus::Image * image1, void ** ppbuffer, ULONGLONG *psizeImage, double Ratio = 1.0, int Quality = 70); int LoadImageFromBuffer(void *pBuffer, ULONGLONG sizeImage, Gdiplus::Image ** ppimage1); double RefCompare(double * buf1, int count1, double * buf2, int count2 ,int mode); struct Complexf { float x,y; //real part and imaginary parts operator float(){ return x; } }; union COLOR { DWORD argb; struct { unsigned char B; unsigned char G; unsigned char R; unsigned char A; }; inline void ToStr(CString &str1) { str1.Format(_T("%d,%d,%d"),R,G,B); } inline void FromStr(CString &str1) { CString result[10]; Split(str1,_T(","),result); R = _tstoi(result[0]); G = _tstoi(result[1]); B = _tstoi(result[2]); } inline void Clear() { argb=0; } }; union COLORf { // __m128 argb; struct { float B; float G; float R; float A; }; COLORf():B(0),G(0),R(0),A(0){} COLORf(float b,float g,float r,float a):B(b),G(g),R(r),A(a){} void ToStr(CString &s1) { s1.Format(_T("%.3f,%.3f,%.3f"),R,G,B); } void FromStr(CString &s1) { R=G=B=0; CString result[10]; Split(s1,_T(","),result); R = float(_tstof(result[0])); G = float(_tstof(result[1])); B = float(_tstof(result[2])); } void Clear() { // argb=_mm_setzero_ps(); A=R=G=B=0; } COLORf & operator+=(COLORf & color1) { this->B+=color1.B; this->G+=color1.G; this->R+=color1.R; this->A+=color1.A; return *this; } COLORf & operator/=(float f1) { this->B/=f1; this->G/=f1; this->R/=f1; this->A/=f1; return *this; } }; union RGB16 { QWORD ARGB; struct { unsigned short int B; unsigned short int G; unsigned short int R; unsigned short int A; }; void ToStr(CString &s1) { s1.Format(_T("%d,%d,%d"),R,G,B); } void FromStr(CString &s1) { CString result[10]; Split(s1,_T(","),result); R = _tstoi(result[0]); G = _tstoi(result[1]); B = _tstoi(result[2]); } void Clear() { ARGB=0; } }; struct HSI { float H; float S; float I; HSI():H(0),S(0),I(0){} inline void ToStr(CString &s1) { s1.Format(_T("%.3f,%.3f,%.3f"),H,S,I); } inline void FromStr(CString &s1) { CString result[10]; Split(s1,_T(","),result); H = float(_tstof(result[0])); S = float(_tstof(result[1])); I = float(_tstof(result[2])); } }; struct Lab { float L,a,b; Lab():L(0),a(128),b(128){} Lab(float L1,float a1,float b1):L(L1),a(a1),b(b1){} // Lab(Lab &lab1):L(lab1.L),a(lab1.a),b(lab1.b){} void ToStr(CStringW &s1) { s1.Format(L"%.3f,%.3f,%.3f",L,a,b); } void ToStr(CStringA &s1) { s1.Format("%.3f,%.3f,%.3f",L,a,b); } /* void FromStr(CStringW &s1) { _stscanf_s(s1.GetString(),_T("%f,%f,%f"),&L,&a,&b); } */ void FromStr(CString &s1) { CString result[10]; Split(s1,_T(","),result); L = float(_tstof(result[0])); a = float(_tstof(result[1])); b = float(_tstof(result[2])); } void ToRGB(COLORf &rgbf1) { rgbf1=LabToRGBf(*this); } void FromRGB(COLORf &c1f) { *this = RGBfToLab(c1f); } float DistanceTo(Lab lab2) { return sqrtf((lab2.L-L)*(lab2.L-L)+(lab2.a-a)*(lab2.a-a)+(lab2.b-b)*(lab2.b-b)); } float Distance2To(Lab lab2) { return ((lab2.L-L)*(lab2.L-L)+(lab2.a-a)*(lab2.a-a)+(lab2.b-b)*(lab2.b-b)); } }; class QMat { enum enumElementFormat { Default=0, Q8Byte, Q32F, }; public: int ElementFormat; int Width; int Height; int stride; void * buffer1; void * buffer2; QMat(){} QMat(int x,int y,enumElementFormat eEF); ~QMat(){} }; /* int HSIinHSIs(HSI hsi,HSI hsi1,HSI hsi2); int HSIinHSIst(HSI hsi,HSI HSI1,HSI hsi2,HSI Ht); int HSIinHSIt(HSI hsi,HSI hsi1,HSI hsit); int HSIinHSIsts(HSI hsi1,HSI hsi2,HSI hsi3,HSI Ht1,HSI ht2); //hsi1 in [hsi2,hsi3] */ //float Calk(HSI hsi0,HSI hsi1,HSI hsi2); //hsi0±»²âÁ¿µã£¬hsi1,»ù×¼µã1£¬hsi2,»ù×¼µã2 //float CalPos(HSI HSI1); //float CalHSIDistance(HSI hsi1, HSI hsi2); //__m64 Get_m64(__int64 n); /* class QuadRectF { RectF Pt[4]; }; */ ///* const BYTE RtoVI[256]= {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, 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, 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, 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, 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, 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, 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,}; const BYTE GtoVI[256]= {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, 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, 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, 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, 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, 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, 137,138,139,139,140,140,141,142,142,143,143,144,144,145,146,146,147,147,148,149,149,}; const BYTE BtoVI[256]= {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, 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, 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, 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, 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, 27,27,27,27,27,27,27,28,28,28,28,28,28,28,28,28,29,}; //*/ const float RtoVf[256]= { 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 250*0.299f,251*0.299f,252*0.299f,253*0.299f,254*0.299f,255*0.299f }; const float GtoVf[256]= { 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 250*0.587f,251*0.587f,252*0.587f,253*0.587f,254*0.587f,255*0.587f }; const float BtoVf[256]= { 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 250*0.114f,251*0.114f,252*0.114f,253*0.114f,254*0.114f,255*0.114f }; #define RGBtoVI(R,G,B) (RtoVI[int(R)]+GtoVI[int(G)]+BtoVI[int(B)]) #define RGBtoVf(R,G,B) ((R)*0.299f+(G)*0.587f+(B)*0.114f) struct TransFormThreadDataStruct { int ThreadNo; volatile int Running; volatile int Done; UINT * srcpixels; int srcstride; UINT * destpixels; int deststride; int srcw; int srch; Gdiplus::PointF srcpt[4]; Gdiplus::Rect destrect; int starth; int endh; }; UINT __cdecl TransFormThread(LPVOID pParam); class HistoGram { public: int totalpixels; int maxRsample,maxRsampleindex; int maxGsample,maxGsampleindex; int maxBsample,maxBsampleindex; int maxVsample,maxVsampleindex; int minRvalue,maxRvalue; int minGvalue,maxGvalue; int minBvalue,maxBvalue; int minVvalue,maxVvalue; DWORD totalRvalues,totalGvalues,totalBvalues,totalVvalues; float aveRvalue,aveGvalue,aveBvalue,aveVvalue; //ƽ¾ùÖµ float mostRvalue,mostGvalue,mostBvalue; //´ó²¿·Ö£¬È¥µô×î¸ßºÍ×îµÍÊ£ÓàµÄ¡£ float midRvalue,midGvalue,midBvalue,midVvalue; //ÖÐλÊý int Rsamples[256],Gsamples[256],Bsamples[256],Vsamples[256]; int MakeHistoGram(Gdiplus::Bitmap * bitmap, int startx=0, int starty=0, int width=0, int height=0); int getRpercentvalue(float percent); int getGpercentvalue(float percent); int getBpercentvalue(float percent); int getVpercentvalue(float percent); float GetMostRvalue(); //È¡µÃ float GetMostGvalue(); //È¡µÃ float GetMostBvalue(); //È¡µÃ }; class cBlackFix { public: int IsBlackFixInited; int Width; int Height; MyImage BlackFixImage; cBlackFix() { IsBlackFixInited=0; } cBlackFix(CString sFilePathName) { BlackFixImage.LoadFromBitmapFile(sFilePathName); Width=BlackFixImage.Width; Height=BlackFixImage.Height; IsBlackFixInited=1; } int LoadFixFile(CString sFilePathName) { int j=BlackFixImage.LoadFromBitmapFile(sFilePathName); Width=BlackFixImage.Width; Height=BlackFixImage.Height; if (Width>0&&Height>0) { IsBlackFixInited=1; return 0; }else { IsBlackFixInited=0; return -1; } } int Fix(MyImage & theImage) { if (!IsBlackFixInited) { return -1; } if (theImage.Width!=Width||theImage.Height!=Height) { return -2; } unsigned char *dstbuf=(unsigned char *)theImage.buffer; unsigned char *thisbuf=(unsigned char *)BlackFixImage.buffer; for (int i=0;i=80) {newpixel=dstbuf[l+j-1];} else if (thepixel>=fixpixel) {newpixel=thepixel-fixpixel;} else {newpixel=0;} dstbuf[l+j]=newpixel; }; } return 0; } }; class SecWhiteBalance { public: const static int wbxsecs=256; const static int wbysecs=192; int wbsectotalR[256][256]; int wbsectotalG[256][256]; int wbsectotalB[256][256]; int wbsectotalG2[256][256]; int wbsecsamples[256][256]; // float bright[256][256]; float wbsecR[256][256]; float wbsecG[256][256]; float wbsecB[256][256]; float wbsecG2[256][256]; float wbsecRcorr[256][256]; float wbsecGcorr[256][256]; float wbsecBcorr[256][256]; float wbsecG2corr[256][256]; float wbaveR; float wbaveG; float wbaveB; float wbaveG2; float wbtotalV; float wbaveV; float TargetLight; float TargetLightR; float TargetLightG; float TargetLightB; float TargetLightG2; int wbcorrloaded; int autowbcorronopen; float BrightnessCorr; public: SecWhiteBalance() { wbcorrloaded=0; autowbcorronopen=1; BrightnessCorr=1.0f; TargetLight=128.0f; } ~SecWhiteBalance() { } int LoadWBParamFromFile(CString sFilePathName); int ReadWBParamFromBmp(Gdiplus::Bitmap * bitmap1); int LoadBayerWBParamFromFile(CString sFilePathName); int ReadBayerWBParamFromBmp(Gdiplus::Bitmap * bitmap1); // int WBCorrect1(Gdiplus::Bitmap * bitmap1); int WBCorrect(Gdiplus::Bitmap * bitmap1,Gdiplus::Bitmap * bitmap2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); int WBCorrectVC(Gdiplus::Bitmap * bitmap1,Gdiplus::Bitmap * bitmap2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); int WBCorrect1VC(Gdiplus::Bitmap * bitmap1,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); int WBCorrect2VC(Gdiplus::Bitmap * bitmap1,Gdiplus::Bitmap * bitmap2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); int WBBayerCorrect(MyImage * Image1,MyImage * Image2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); int WBBayerCorrectVC(MyImage * Image1,MyImage * Image2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); 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); int WBBayerCorrect2VC(MyImage * Image1,MyImage * Image2,float fRateV = 1.0, float fRateR = 1.0, float fRateG = 1.0, float fRateB = 1.0); }; struct MemcpyThreadDataStruct { void * src; void * dest; unsigned long size; volatile int done; }; struct PointD { double x,y; PointD ():x(0),y(0) {} PointD (double x1,double y1):x(x1),y(y1) {} PointD & operator=(PointD & d1) { x=d1.x;y=d1.y; return *this; } PointD operator +(PointD & d1) { return PointD(x+d1.x,y+d1.y); } PointD operator -(PointD & d1) { return PointD(x-d1.x,y-d1.y); } PointD operator *(double n) { return PointD(x*n,y*n); } PointD operator /(double n) { return PointD(x/n,y/n); } PointD Miror(PointD & pt1) //ÇóÏà¶ÔÓÚÄ¿±êµã¶Ô³ÆµÄµã { return pt1*2-(*this); } double DistanceTo(PointD & pt1) //¼ÆËãµ½µãµÄ¾àÀë { return sqrt((x-pt1.x)*(x-pt1.x)+(y-pt1.y)*(y-pt1.y)); } double CalR(PointD pt1) //¼ÆËãÒÔµ±Ç°µãΪÆðµã£¬µ½ÖÕµãµÄÁ¬ÏߵĽǶȡ£ { return asin(pt1.y-y/DistanceTo(pt1)); } }; struct MyLineSegment { PointD start,end; MyLineSegment():start(0,0),end(0,0){}; MyLineSegment (PointD d1,PointD d2):start(d1),end(d2) {start=d1;end=d2;}; void SetStartEnd(PointD d1,PointD d2){start=d1;end=d2;}; void SetStartEnd(double startx,double starty,double endx,double endy){start.x=startx,start.y=starty,end.x=endx,end.y=endy;}; }; void fastmemcpy(void* dest, const void* src, const unsigned long size_t); void fastmemcpyMT(void* dest, const void* src, const unsigned long size_t); int GetLineSegmentPart(double startx, double starty, double endx, double endy, double numerator, double denominator, double & x1, double & y1); double LineSegmentDirection(PointD pt1,PointD pt2,PointD pt3); int IsOnLineSegment(MyLineSegment linesegment1,PointD pt1); int IsLineSegmentCross(MyLineSegment linesegment1, MyLineSegment linesegment2); int IsLineSegmentCross(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4); struct stHoughResult { int Score; PointD Pt; }; int Hough(MyImage& img1,stHoughResult res[],int MaxFound, double Threshold,int starta,int enda); int NewHough(MyImage& img1,stHoughResult res[],int MaxFound, double Threshold,int starta,int enda); int TransRGBToBayerGR(Gdiplus::Bitmap * bitmap1,CString sFilePathname); int TransRGBToBayerGR2(Gdiplus::Bitmap * bitmap1,CString sFilePathname); int TransRGBToBayerGR3(Gdiplus::Bitmap * bitmap1,CString sFilePathname); struct DftFilterPos { double x; double y; double w; double h; }; int fdf1(double * pData, int width, int height, DftFilterPos filterPos[], int filterPosCount, int showstatus); //---------------------------------------------------------------------------------------------------