//--------------------------------------------------------------------------- #include #pragma hdrstop #include "MainImage.h" #include "Palette.h" #include "FullView.h" #include "PenManager.h" #include "Rotation.h" #include "CtrlT_func.h" #include "MainMenu.h" #include "LogData.h" //--------------------------------------------------------------------------- #define IDS_CTRLT_COPY StringTable[0] #define IDS_CTRLT_MOVE StringTable[1] #define IDS_CTRLT_FreeTrans StringTable[2] #define IDS_CTRLT_Scale StringTable[3] #define IDS_CTRLT_Rotate StringTable[4] #define IDS_CTRLT_Rotate180 StringTable[5] #define IDS_CTRLT_Rotate90cw StringTable[6] #define IDS_CTRLT_Rotate90Ccw StringTable[7] #define IDS_CTRLT_FlipHorz StringTable[8] #define IDS_CTRLT_FlipVert StringTable[9] #define IDS_CTRLT_MoveCenterPoint StringTable[10] #define IDS_CTRLT_MSG_OVERSCREEN StringTable[11] //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- TCtrlTFunc *CtrlTFunc; //--------------------------------------------------------------------------- __fastcall TCtrlTFunc::TCtrlTFunc(TObject *Sender) { BEGIN_LOG(""); StringTable.Create(DirectoryItem, Language, "CtrlTFunc"); hWnd = ((TWinControl *)Sender)->Handle; gdp::GdiplusStartup(&gdp_token_, &gdp::GdiplusStartupInput(), NULL); mouseDown = false; gBitmap = NULL; miniBitmap = NULL; window.Bitmap = NULL; window.Mask = NULL; window.Back = NULL; Angle = 0.0; dCenterIn=true; extended=false; backup = false; isMoveMode = false; if (static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[0])->Checked) isMoveMode = false; else isMoveMode = true; if (static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[3])->Checked) TCT_Item = CT_FREE; else if (static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[4])->Checked) TCT_Item = CT_SCALE; else TCT_Item = CT_ROTATE; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[0])->Caption = IDS_CTRLT_COPY; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[1])->Caption = IDS_CTRLT_MOVE; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[3])->Caption = IDS_CTRLT_FreeTrans; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[4])->Caption = IDS_CTRLT_Scale; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[5])->Caption = IDS_CTRLT_Rotate; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[7])->Caption = IDS_CTRLT_Rotate180; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[8])->Caption = IDS_CTRLT_Rotate90cw; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[9])->Caption = IDS_CTRLT_Rotate90Ccw; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[11])->Caption = IDS_CTRLT_FlipHorz; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[12])->Caption = IDS_CTRLT_FlipVert; static_cast(MainMenuForm->CtrlTPopupMenu->Items->Items[14])->Caption = IDS_CTRLT_MoveCenterPoint; min_x = 0; max_x = 0; min_y = 0; max_y = 0; StartNumber = 0; tMainImage = NULL; END_LOG; } //--------------------------------------------------------------------------- __fastcall TCtrlTFunc::~TCtrlTFunc() { BEGIN_LOG(""); gdp::GdiplusShutdown(gdp_token_); END_LOG; } //--------------------------------------------------------------------------- /** Initialize CtrlT Function 1. MainImageForm WorkArea Mask Ȯ. return 2. window.Bitmap, window.Mask, window.Back ̹ 3. initWindowBitmap()Լ ȣ: window Bitmap ۾ ̹ copyϴ Լ 4. miniBitmap: GDI+ Bitmap ϱ ӽ Bitmap 5. initSmallBitmap()Լ ȣ: ̸ ̹ Լ */ void __fastcall TCtrlTFunc::InitCTRLT() { if (!MainImageForm->WorkArea->Mask) return; BEGIN_LOG(""); TCursor OldCursor; TPItemImage *Image = MainImageForm->iMainImage; Image->OnPaintLocate=NULL; OldCursor = Screen->Cursor; if ((window.Bitmap = new TUnionBitmap) == NULL) goto fail; // convert by celberus if ((window.Mask = new TUnionBitmap) == NULL) goto fail; if ((window.Back = new TUnionBitmap) == NULL) goto fail; initWindowBitmap(); miniBitmap = new TTexpiaBitmap; Screen->Cursor = OldCursor; TCTL_Item = CM_CTL_NONE; if (!initSmallBitmap()) goto fail; END_LOG; return; fail: if (window.Back) delete window.Back; window.Back=NULL; if (window.Mask) delete window.Mask; window.Mask=NULL; if (window.Bitmap) delete window.Bitmap; window.Bitmap=NULL; if (miniBitmap) delete miniBitmap; miniBitmap=NULL; Screen->Cursor = OldCursor; // EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- /** Clear CtrlT Function data 1. ʱȭ 2. */ void __fastcall TCtrlTFunc::ExitCTRLT() { BEGIN_LOG(""); TPItemImage *Image = MainImageForm->iMainImage; Image->SubVisible = false; Image->SubEnabled = false; Image->OnPaintLocate = NULL; Image->Repaint(); Image->ExitBackGround(0x02); if (window.Bitmap) { delete window.Bitmap; window.Bitmap = 0; } if (window.Mask) { delete window.Mask; window.Mask = 0; } if (window.Back) { delete window.Back; window.Back = 0; } if (gBitmap) delete gBitmap; gBitmap = NULL; if (miniBitmap) delete miniBitmap; miniBitmap = NULL; if (tMainImage && tMainImage->LayerMask) { delete tMainImage->LayerMask; tMainImage->LayerMask=NULL; } if (tMainImage) delete tMainImage; tMainImage=NULL; END_LOG; } //--------------------------------------------------------------------------- /** Mouse Down Event 1. ConfigMousePosition(X, Y)Լ Cursor 2. First_gpoint, mouseDown setting 3. ȸ(Rotation) gtemppointf ̿ */ void __fastcall TCtrlTFunc::MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Button == mbRight) return; BEGIN_LOG(""); int kind=-1; /// x,y óϸ · óѴ. if ((kind=ConfigMousePosition(X, Y))>-1) { if ((TMControlPoint)kind==CM_8Center) { TCTL_Item=(TMControlPoint)kind; } else if (TCT_Item == CT_ROTATE) { if (kind > 0 && kind < 7) Screen->Cursor = crCross; END_LOG; return; } TCTL_Item=(TMControlPoint)kind; if (Shift.Contains(ssShift)) { for (int i=0; i<9; i++) { gtemppointf[i]=gpointf[i]; } } } else if (CursorOnImage(X, Y)) { TCTL_Item = CM_MOVE; } else { if (TCT_Item == CT_SCALE) { END_LOG; return; } TCTL_Item = CM_ROTATE; for (int i=0; i<9; i++) { gtemppointf[i]=gpointf[i]; } } First_gpoint.X = X; First_gpoint.Y = Y; mouseDown = true; END_LOG; } //--------------------------------------------------------------------------- /** Mouse Move Event 1. mouseDown == true̸ Cursor 2. ȸ(Rotation)϶ ӽ gtemppointf ̿ 3. ׹ۿ gpointf ̿ 4. CalculatePoints(X, Y, Shift) Լ ȣ: 콺 */ void __fastcall TCtrlTFunc::MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); int kind=-1; if (!mouseDown) { kind = ConfigMousePosition(X, Y); if (TCT_Item == CT_ROTATE && kind > 0 && kind < 7) Screen->Cursor = crDefault; else if (kind==-1 && CursorOnImage(X, Y)) { Screen->Cursor = crHandPoint; } else if (kind==-1) { Screen->Cursor = crCross;//crDefault; } else if ((TMControlPoint)kind==CM_8Center) { Screen->Cursor = crDefault; } } if ((TCT_Item==CT_FREE || TCT_Item==CT_ROTATE) && TCTL_Item==CM_ROTATE && mouseDown) { double ax = X - gtemppointf[8].X; double ay = gtemppointf[8].Y - Y; double bx = First_gpoint.X - gtemppointf[8].X; double by = gtemppointf[8].Y - First_gpoint.Y; double o_angle = ArcTan2(by, bx); Angle = ArcTan2(ay, ax) - o_angle; } if (TCTL_Item!=CM_CTL_NONE && mouseDown) { if (dCenterIn && gpointf[8].X == (gpointf[0].X + (gpointf[2].X - gpointf[0].X)/2) && gpointf[8].Y == (gpointf[0].Y + (gpointf[2].Y - gpointf[0].Y)/2)) { } else { dCenterIn = false; } CalculatePoints(X, Y, Shift); } END_LOG; } //--------------------------------------------------------------------------- /// Mouse Up Event: ʱȭ void __fastcall TCtrlTFunc::MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { First_gpoint.X = 0; First_gpoint.Y = 0; mouseDown = false; TCTL_Item = CM_CTL_NONE; } //--------------------------------------------------------------------------- /// ͸ ̿ؼ ̹ ȿ Ŀ ִ Ȯϴ Լ bool __fastcall TCtrlTFunc::CursorOnImage(int X, int Y) { BEGIN_LOG(""); int AX, AY, BX, BY, DX, DY; double Inside1, Inside2, dis1, dis2; AX = gpointf[0].X; AY = gpointf[0].Y; BX = gpointf[1].X; BY = gpointf[1].Y; DX = gpointf[3].X; DY = gpointf[3].Y; dis1 = (BX-AX)*(BX-AX) + (BY-AY)*(BY-AY); dis2 = (DX-AX)*(DX-AX) + (DY-AY)*(DY-AY); Inside1 = ((BX-AX)*(X-AX)+(BY-AY)*(Y-AY))/dis1; Inside2 = ((DX-AX)*(X-AX)+(DY-AY)*(Y-AY))/dis2; if ( Inside1 > 0 && Inside2 > 0) { if (Inside1 < 1 && Inside2 < 1) { END_LOG; return true; } } END_LOG; return false; } //--------------------------------------------------------------------------- /** Mouse Contol Ǵ 9 Point ġ 1. Shift, Angle ؼ 1 2. Shift GetPointXYForShift()Լ ̿ 3. Angle 4. ִ 츦 ܷ ó. by embakum(07.04.06) (Calculate_kvalue ۵ϴ ϰ, ۵ ʴ , ۵ ̿.) 5. MakeBaseRect() Լ ġ */ void __fastcall TCtrlTFunc::CalculatePoints(int X, int Y, TShiftState Shift) { BEGIN_LOG(""); float xGap, yGap; int t_x = X, t_y = Y; xGap = First_gpoint.X - X; yGap = First_gpoint.Y - Y; int last=9; if (!dCenterIn) last=8; if (TCTL_Item==CM_CTL_NONE) { END_LOG; return; } else if (TCTL_Item==CM_MOVE) { for (int i=0; iiMainImage->Repaint(); if (TCTL_Item != CM_ROTATE) {// && !Shift.Contains(ssShift)) { First_gpoint.X = X; First_gpoint.Y = Y; } END_LOG; } //--------------------------------------------------------------------------- /** Vector ̿ؼ Ǵ ؼ ޴ ϱ K Ȯ K = {(c'.x-a.x)(a.x-d.x) + (c'y-a.y)(a.y-d.y)} / {(a.x-d.x)^2 +(a.y-d.y)^2)} b' = a+(a-b)K , d' = a+(a-d)k a ̸ c' c ġ ̴. 簢 a, b, c, d ð ݴ ġǾ ִ. a--d | | b--c ġ̸ c ̵ c'̴. */ double __fastcall TCtrlTFunc::Calculate_Kvalue(gdp::PointF &Point_a, gdp::PointF &Point_b, gdp::PointF &Point_C) { double K_value; K_value = ((Point_C.X-Point_a.X)*(Point_a.X-Point_b.X)+(Point_C.Y-Point_a.Y)*(Point_a.Y-Point_b.Y))/ ((Point_a.X-Point_b.X)*(Point_a.X-Point_b.X)+(Point_a.Y-Point_b.Y)*(Point_a.Y-Point_b.Y)); Point_b.X = Point_a.X + (Point_a.X - Point_b.X)*K_value; Point_b.Y = Point_a.Y + (Point_a.Y - Point_b.Y)*K_value; return K_value; } //--------------------------------------------------------------------------- /** Ȯ/ KeyԷ ó, CanDrawԼ ׸ ִ 쿡 setresultimagetocanvas() . */ // (a,A) (s,S) , initSmallBitmap()κ ݴ. ӵ ֿ Ǵ . by embakum(07.06.08) void __fastcall TCtrlTFunc::KeyDown(TObject *Sender, WORD Key, TShiftState Shift) { BEGIN_LOG(""); if(Key == 'A'){ // 'A' // initSmallBitmap(true); } else if(Key == 'S'){ // 'S' // initSmallBitmap(true); // MainImageForm->iMainImage->Repaint(); } else if (Key == VK_RETURN) { if (!MainImageForm->WorkArea->Mask) { END_LOG; return; } if(CanDraw()) SetResultImageToCanvas(); } END_LOG; } //--------------------------------------------------------------------------- /** ׸ ׸ ִ ΰ üũ . ׸ , ÷ Ǿִٸ, stopscanlineȤ startscanline access violation ߻Ͽ. Check ׸ . 1, 2 簢 ߽ɰ ̷ ̸ ̿. ̰ M_PI normal, ׷ reversed. Arctan2 return value . */ //07.04.05 by embakum bool __fastcall TCtrlTFunc::CanDraw() { BEGIN_LOG(""); double CX = (gpointf[0].X + gpointf[2].X)/2; double CY = (gpointf[0].Y + gpointf[2].Y)/2; double jongik_angle[2], diff_angle,ang; double x_0th = gpointf[0].X-CX; double y_0th = CY - gpointf[0].Y; double x_1st = gpointf[1].X-CX; double y_1st = CY - gpointf[1].Y; jongik_angle[0] = ArcTan2(y_0th, x_0th); jongik_angle[1] = ArcTan2(y_1st, x_1st); for(int i=0;i<2;i++) { if(jongik_angle[i] < 0) jongik_angle[i] += (2* M_PI); } if(jongik_angle[0]>jongik_angle[1]) diff_angle = (2*M_PI) - (jongik_angle[0]-jongik_angle[1]); else diff_angle = jongik_angle[1]-jongik_angle[0]; if(diff_angle < 0.015 || ((diff_angle < M_PI+0.015)&&(diff_angle > M_PI-0.015)) || diff_angle > 2*M_PI-0.015)ImageState = 2; else if (diff_angle < M_PI) ImageState = 0; else ImageState = 1; if(diff_angle != 0 && diff_angle != M_PI && diff_angle != 2*M_PI) { if(diff_angle<0.14) ang=diff_angle; else if((diff_angle) > 3 && (diff_angle <3.28)) ang=DoubleABS(M_PI,diff_angle); else ang = 2*M_PI -diff_angle; } if(diff_angle < 0.14 || ((diff_angle) > 3 && (diff_angle <3.28)) || diff_angle >6.14) { if((DoubleABS(gpointf[0].X,gpointf[2].X)+DoubleABS(gpointf[0].Y,gpointf[2].Y))<(5/ang))ImageState=2; } if((DoubleABS(gpointf[0].X,gpointf[2].X)+DoubleABS(gpointf[0].Y,gpointf[2].Y))<8)ImageState=2; if(ImageState==2) { END_LOG; return false; } END_LOG; return true; } void __fastcall TCtrlTFunc::KeyUp(TObject *Sender, WORD Key, TShiftState Shift) { } //--------------------------------------------------------------------------- /**콺 ġ ִ Ȯ ϱ Լ crSizeNESW -6 : Ʒ crSizeNS -7 : <-> Ʒ crSizeNWSE -8 : Ʒ crSizeWE -9 : <-> TCTL_Item : CM_Out1, CC_Mid1 簢 缭, pi/2ٴ ũ鼭 pi/2 nwse Ѵ. 0 - 7 - 3 | | 4 6 | | 1 - 5 - 2 ѹ ȴ. nwse ٸ Ŀ ش. */ int __fastcall TCtrlTFunc::ConfigMousePosition(int X, int Y) { BEGIN_LOG(""); bool nomal = false; double CX,CY; double declination[4], temp,diff_angle; int nwse, Image_state; CX = (gpointf[0].X + gpointf[2].X)/2; CY = (gpointf[0].Y + gpointf[2].Y)/2; temp = 2*M_PI; for(int i=0;i<4;i++) { declination[i] = ArcTan2(CY-gpointf[i].Y , gpointf[i].X-CX); if(declination[i]<0) declination[i] += 2*M_PI; } if(declination[0]>declination[1]) diff_angle = (2*M_PI) - (declination[0]-declination[1]); else diff_angle = declination[1]-declination[0]; if(diff_angle ==0 || diff_angle == M_PI || diff_angle == 2*M_PI)Image_state = 2; //access error߻ state. if ɸ 簢 Ȥ Ǿ ̴. else if (diff_angle < M_PI) Image_state = 0;// ̹ else Image_state = 1;// ̹ for(int i=0;i<4;i++) { if((declination[i]>M_PI_2) && (declination[i] gpointf[i].X-5 && X < gpointf[i].X+5 && Y > gpointf[i].Y-5 && Y < gpointf[i].Y+5 && Image_state ==0) { if (i==nwse || i==(nwse+2)%4) { Screen->Cursor = crSizeNWSE; // Ʒ } else if (i==(nwse+1)%4 || i==(nwse+3)%4) { Screen->Cursor = crSizeNESW; // Ʒ } else if (i==nwse+4 || i==((nwse+2)%4)+4) { Screen->Cursor = crSizeWE; // <-> } else if (i==((nwse+1)%4)+4 || i==((nwse+3)%4)+4) { Screen->Cursor = crSizeNS; // <-> Ʒ } else if (i==8) { Screen->Cursor = crDefault; } END_LOG; return i; } else if(X > gpointf[i].X-5 && X < gpointf[i].X+5 && Y > gpointf[i].Y-5 && Y < gpointf[i].Y+5 && Image_state ==1) {//Imagestate 1ΰ NS, WEĿ Ǵ index Imagestate 0ΰ ٸ. if (i==nwse || i==(nwse+2)%4) { Screen->Cursor = crSizeNWSE; // Ʒ } else if (i==(nwse+1)%4 || i==(nwse+3)%4) { Screen->Cursor = crSizeNESW; // Ʒ } else if (i==nwse+4 || i==((nwse+2)%4)+4) { Screen->Cursor = crSizeNS; // <-> Ʒ } else if (i==((nwse+1)%4)+4 || i==((nwse+3)%4)+4) { Screen->Cursor = crSizeWE; // <-> } else if (i==8) { Screen->Cursor = crDefault; } END_LOG; return i; } else if(X > gpointf[i].X-5 && X < gpointf[i].X+5 && Y > gpointf[i].Y-5 && Y < gpointf[i].Y+5 && Image_state ==2) { if (i==nwse || i==(nwse+2)%4) { Screen->Cursor = crSizeNWSE; // Ʒ } else if (i==(nwse+1)%4 || i==(nwse+3)%4) { Screen->Cursor = crSizeNESW; // Ʒ } else if (i==nwse+4 || i==((nwse+2)%4)+4) { Screen->Cursor = crSizeWE; // <-> } else if (i==((nwse+1)%4)+4 || i==((nwse+3)%4)+4) { Screen->Cursor = crSizeNS; // <-> Ʒ } else if (i==8) { Screen->Cursor = crDefault; } END_LOG; return i; } } END_LOG; return -1; } //--------------------------------------------------------------------------- //TexPro α׷ ټ 쿡, ó ̹ ̸Ⱑ ٸ α׷ Ÿ // Ͽ. embakum // ϳ ִ ̸ 迭 ϰ . bool __fastcall TCtrlTFunc::initSmallBitmap(bool skip) { BEGIN_LOG(""); int zoomin = MainImageForm->iMainImage->ZoomIn; int zoomout = MainImageForm->iMainImage->ZoomOut; int positionx = MainImageForm->iMainImage->PositionX; int positiony = MainImageForm->iMainImage->PositionY; double ratio = (double)zoomin/zoomout; int rangeWidth = MainImageForm->WorkArea->Range.right - MainImageForm->WorkArea->Range.left; int rangeHeight = MainImageForm->WorkArea->Range.bottom - MainImageForm->WorkArea->Range.top; HDC tDC=NULL, tMaskDC=NULL; int currentBPP = MainImageForm->iMainImage->uBitmap->BitsPerPixel; int _tW = rangeWidth, _tH=rangeHeight; rangeWidth *= ratio; rangeHeight *= ratio; String t_bitmap_locate[10]; int index; for (int i = 0; i < 10; i++) { t_bitmap_locate[i] = DirectoryItem+"\\ctrlt_temp" + IntToStr(i) + ".bmp"; } try { TTexpiaBitmap *tmask = NULL; tmask = new TTexpiaBitmap; if (!miniBitmap) miniBitmap = new TTexpiaBitmap; miniBitmap->Create(rangeWidth, rangeHeight, 24); if (currentBPP==8) { TTexpiaBitmap *temp = new TTexpiaBitmap; temp->Create(rangeWidth, rangeHeight, 8, rgb); tDC = temp->CreateDC(); SetStretchBltMode(tDC, COLORONCOLOR); window.Bitmap->UnionStretchBlt(tDC, 0, 0, rangeWidth, rangeHeight, 0, 0, window.size.x, window.size.y, SRCCOPY); if (tDC) temp->DeleteDC(tDC); Convert8bitTo24bitmap(temp, miniBitmap); delete temp; } else { tDC = miniBitmap->CreateDC(); SetStretchBltMode(tDC, COLORONCOLOR); window.Bitmap->UnionStretchBlt(tDC, 0, 0, rangeWidth, rangeHeight, 0, 0, window.size.x, window.size.y, SRCCOPY); if (tDC) miniBitmap->DeleteDC(tDC); } for(int i = 0; i < 10; i++) { if(miniBitmap->SaveToFile(t_bitmap_locate[i], 6,0)) { index = i; break; } } delete miniBitmap; miniBitmap=NULL; if (gBitmap) delete gBitmap; gBitmap = NULL; //Char fname[100]; //ZeroMemory(fname, sizeof(fname)); //MultiByteToWideChar(CP_ACP, 0, t_bitmap_locate[index].c_str(), t_bitmap_locate[index].Length(), // fname, sizeof(fname) / sizeof(fname[0])); String fname = t_bitmap_locate[index]; gBitmap = new gdp::Bitmap(fname.c_str()); if (!gBitmap) { if (tmask) delete tmask; tmask=NULL; END_LOG; return false; } int iWidth = gBitmap->GetWidth(); int iHeight = gBitmap->GetHeight(); if (currentBPP==8) { tmask->Create(iWidth, iHeight, 8); } else { tmask->Create(iWidth, iHeight, 1); } tMaskDC = tmask->CreateDC(); SetStretchBltMode(tMaskDC, COLORONCOLOR); window.Mask->UnionStretchBlt(tMaskDC, 0, 0, iWidth, iHeight, 0, 0, window.size.x, window.size.y, SRCCOPY); if (tMaskDC) tmask->DeleteDC(tMaskDC); gdp::Color color, colorTemp; Byte *MP, mm=0x80; tmask->StartScanLine(); for(int iRow = 0; iRow < iHeight; iRow++) { if (tmask->Height < iRow) continue; MP = tmask->GetScanLine(iRow); mm = 0x80; for(int iColumn = 0; iColumn < iWidth; iColumn++) { if (tmask->Width < iColumn) continue; gBitmap->GetPixel(iColumn, iRow, &color); if (currentBPP==8) { if (*MP) { colorTemp.SetValue(color.MakeARGB( (BYTE)(0), color.GetRed(), color.GetGreen(), color.GetBlue())); } else { colorTemp.SetValue(color.MakeARGB( (BYTE)(255), color.GetRed(), color.GetGreen(), color.GetBlue())); } MP++; } else { if (*MP&mm) { colorTemp.SetValue(color.MakeARGB( (BYTE)(0), color.GetRed(), color.GetGreen(), color.GetBlue())); } else { colorTemp.SetValue(color.MakeARGB( (BYTE)(255), color.GetRed(), color.GetGreen(), color.GetBlue())); } if (mm==1) { mm = 0x80; MP++; } else { mm >>= 1; } } gBitmap->SetPixel(iColumn, iRow, colorTemp); } } tmask->StopScanLine(); delete tmask; if (!skip) { gpointf[0].X = MainImageForm->WorkArea->Range.left; gpointf[0].Y = MainImageForm->WorkArea->Range.top; gpointf[2].X = gpointf[0].X + _tW; gpointf[2].Y = gpointf[0].Y + _tH; MakeBaseRect(gpointf[0], gpointf[2]); } END_LOG; return true; } catch(...) { END_LOG; return false; } } //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::initWindowBitmap() { BEGIN_LOG(""); int x, y, xx; Byte *WP, *WBP, *MP, mm, *PP, *LP; COLORREF bgc, c; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; window.s.x = MainImageForm->WorkArea->Range.left; window.s.y = MainImageForm->WorkArea->Range.top; window.e.x = MainImageForm->WorkArea->Range.right; window.e.y = MainImageForm->WorkArea->Range.bottom; window.size.x = window.e.x - window.s.x; window.size.y = window.e.y - window.s.y; Image->SubRange.left = window.s.x; Image->SubRange.top = window.s.y; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (window.Bitmap->Create(window.size.x, window.size.y, 8, rgb) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (window.Mask->Create(window.size.x, window.size.y, 8, rgb) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (window.Bitmap->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (window.Mask->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->uBitmap->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->WorkArea->Mask->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (Image->LayerMask->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=0; yGetScanLine(y); MP = window.Mask->GetScanLine(y); PP = Image->uBitmap->GetScanLine(window.s.y+y)+window.s.x; LP = Image->LayerMask->GetScanLine(window.s.y+y)+window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xPutScanLine(y); window.Mask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y=0; yGetScanLine(y); MP = window.Mask->GetScanLine(y); PP = Image->uBitmap->GetScanLine(window.s.y+y)+window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xPutScanLine(y); window.Mask->PutScanLine(y); } } window.Bitmap->StopScanLine(); window.Mask->StopScanLine(); Image->uBitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } else { if (window.Bitmap->Create(window.size.x, window.size.y, 24) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (window.Mask->Create(window.size.x, window.size.y, 1) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (window.Bitmap->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (window.Mask->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->uBitmap->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->WorkArea->Mask->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (Image->LayerMask->StartScanLine() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=0; yGetScanLine(y); MP = window.Mask->GetScanLine(y); *MP = 0; PP = Image->uBitmap->GetScanLine(window.s.y+y)+3*window.s.x; LP = Image->LayerMask->GetScanLine(window.s.y + y); WP = MainImageForm->WorkArea->Mask->GetScanLine(y); x = 0; mm = 0x80; while(1) { xx = x + window.s.x; if ((*WP&mm) && (*(LP + (xx >> 3)) & (0x80 >> (xx & 7 ))) == 0) { CopyPixel24(WBP, PP); } else { SetPixel24(WBP, 0); *MP |= mm; } x++; if(x >= window.size.x) break; WBP += 3; PP += 3; if (mm==1) { MP++; *MP = 0; WP++; mm = 0x80; } else { mm >>= 1; } } window.Bitmap->PutScanLine(y); window.Mask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y=0; yGetScanLine(y); MP = window.Mask->GetScanLine(y); *MP = 0; PP = Image->uBitmap->GetScanLine(window.s.y+y)+3*window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(y); x=0; mm = 0x80; while(1) { if (*WP&mm) { CopyPixel24(WBP, PP); } else { SetPixel24(WBP, 0); *MP |= mm; } x++; if(x >= window.size.x) break; WBP += 3; PP += 3; if (mm==1) { MP++; *MP = 0; WP++; mm = 0x80; } else { mm >>= 1; } } window.Bitmap->PutScanLine(y); window.Mask->PutScanLine(y); } } window.Bitmap->StopScanLine(); window.Mask->StopScanLine(); Image->uBitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } END_LOG; return; fail : if (Image->LayerMask) Image->LayerMask->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); Image->uBitmap->StopScanLine(); window.Mask->StopScanLine(); window.Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- // 0----7----3 // | | // 4 8 6 // | | // 1----5----2 // 9 points => 3 x 9 + 1 = 28 ponit ʿϴ. Ф 켱 ϰ Ф //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::MakeBaseRect(gdp::PointF firstPoint, gdp::PointF secondPoint, bool includeCpoint) { BEGIN_LOG(""); if (Angle==0.0) { gpointf[0].X = firstPoint.X; gpointf[0].Y = firstPoint.Y; gpointf[1].X = firstPoint.X; gpointf[1].Y = secondPoint.Y; gpointf[2].X = secondPoint.X; gpointf[2].Y = secondPoint.Y; gpointf[3].X = secondPoint.X; gpointf[3].Y = firstPoint.Y; } else { } for (int i=0; i<4; i++) { gpointf[4+i].X = gpointf[i].X + (gpointf[(i+1)%4].X - gpointf[i].X)/2; gpointf[4+i].Y = gpointf[i].Y + (gpointf[(i+1)%4].Y - gpointf[i].Y)/2; } if (dCenterIn && includeCpoint) { gpointf[8].X = gpointf[0].X + (gpointf[2].X - gpointf[0].X)/2; gpointf[8].Y = gpointf[0].Y + (gpointf[2].Y - gpointf[0].Y)/2; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::GDIPlus(HDC dcDst, int px, int py) { if (!gBitmap) return; BEGIN_LOG(""); gdp::Graphics graphics(dcDst); // using GDI+ TPItemImage *Image = MainImageForm->iMainImage; int zoomin = Image->ZoomIn; int zoomout = Image->ZoomOut; int positionx = Image->PositionX; int positiony = Image->PositionY; double ratio = (double)zoomin/zoomout; gdp::PointF temp[4]; for (int i=0; i<4; i++) { temp[i].X = (gpointf[i].X - positionx)*ratio; temp[i].Y = (gpointf[i].Y - positiony)*ratio; } gdp::PointF destinationPoints[] = { // destination for upper-left point of original (0) // destination for upper-right point of original(3) // destination for lower-left point of original (1) temp[0], temp[3], temp[1]}; // graphics.SetPixelOffsetMode(gdp::PixelOffsetModeHalf); // graphics.SetCompositingQuality(gdp::CompositingQualityGammaCorrected); graphics.DrawImage(gBitmap, destinationPoints, 3); // DrawRectangle(graphics, ratio, positionx, positiony); DrawRectangle(dcDst, ratio, positionx, positiony); END_LOG; } //--------------------------------------------------------------------------- //GDI+ ׸ ׸ 쿡 ־. ̸ Ͽ GDI ׸. embakum(07.05.23) //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::DrawRectangle(HDC dcDst, double ratio, int px, int py) { BEGIN_LOG(""); // SetROP2(dcDst,R2_MERGEPENNOT); HPEN NewPen, OldPen; float width, height; gdp::PointF temp[9]; for (int i=0; i<9; i++) { temp[i].X = (gpointf[i].X - px)*ratio; temp[i].Y = (gpointf[i].Y - py)*ratio; } if (ratio<0.4) { width=2, height=2; } else { width=6, height=6; } //̹ ǥϴ 簢 NewPen = CreatePen(PS_DASHDOTDOT, 1, RGB(0x0,0xff,0xff)); SelectObject(dcDst, NewPen); MoveToEx(dcDst, temp[0].X, temp[0].Y,NULL); LineTo(dcDst, temp[1].X, temp[1].Y); LineTo(dcDst, temp[2].X, temp[2].Y); LineTo(dcDst, temp[3].X, temp[3].Y); LineTo(dcDst, temp[0].X, temp[0].Y); // 簢 9 SetROP2(dcDst,R2_COPYPEN); NewPen = CreatePen(PS_SOLID, 1, RGB(0x0, 0xff, 0xff)); SelectObject(dcDst, NewPen); for (int i =0; i<9; i++) { Rectangle(dcDst, temp[i].X-width/2, temp[i].Y-height/2, temp[i].X+width/2, temp[i].Y+height/2); } // Draw center point cross MoveToEx(dcDst, temp[8].X, temp[8].Y-height, NULL); LineTo(dcDst, temp[8].X, temp[8].Y+height); MoveToEx(dcDst, temp[8].X-width, temp[8].Y, NULL); LineTo(dcDst, temp[8].X+width, temp[8].Y); END_LOG; } //--------------------------------------------------------------------------- // //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::DrawRectangle(gdp::Graphics &graphics, double ratio, int px, int py) { BEGIN_LOG(""); float gap = 1.5; gap=gap*ratio; if (gap<0.5) gap=0.5; else if (gap>5) gap=5; // Declare and initialize color component values as BYTE types. BYTE a = 0xFF;//0xFF; BYTE r = 0x0; //0x80; BYTE g = 0xff;//0x80; BYTE b = 0xff;//0xFF; // Create an ARGB value from the four component values. gdp::ARGB argb = gdp::Color::MakeARGB(a, r, g, b); // Create a Color object from the ARGB value. gdp::Color argbColor(argb); gdp::Pen blackPen(argbColor, gap); // blackPen.SetDashStyle(gdp::DashStyleDash); float dashValues[3] = { 1, 5, 3}; int dashCount = 3; blackPen.SetDashPattern(dashValues, dashCount); gdp::PointF temp[9]; for (int i=0; i<9; i++) { temp[i].X = (gpointf[i].X - px)*ratio; temp[i].Y = (gpointf[i].Y - py)*ratio; } float width = abs(long(temp[0].X-temp[2].X)); float height = abs(long(temp[0].Y-temp[2].Y)); gap = 3; // ̹ ǥϴ 簢 gdp::PointF gpoint[4]; for (int i=0; i<4; i++) gpoint[i] = temp[i]; gdp::PointF* gpoints = gpoint; graphics.SetSmoothingMode(gdp::SmoothingModeHighQuality); graphics.DrawPolygon(&blackPen, gpoints, 4); // Create an array of Rect objects. if (ratio<0.4) { width=2, height=2; gap = 1; } else { width=6, height=6; } gdp::RectF rects[9]; blackPen.SetDashStyle(gdp::DashStyleSolid); for (int i=0; i<9; i++) { rects[i].X = temp[i].X-gap; rects[i].Y = temp[i].Y-gap; rects[i].Width = width; rects[i].Height = height; } gdp::RectF* pRects = rects; // Draw the rectangles. graphics.DrawRectangles(&blackPen, pRects, 9); // Draw center point cross graphics.DrawLine(&blackPen, rects[8].X+gap, rects[8].Y-gap, rects[8].X+gap, rects[8].Y+height+gap); graphics.DrawLine(&blackPen, rects[8].X-gap, rects[8].Y+gap, rects[8].X+width+gap, rects[8].Y+gap); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::Convert8bitTo24bitmap(TTexpiaBitmap *srcBitmap, TTexpiaBitmap *trgBitmap) { BEGIN_LOG(""); Byte *SB=NULL, *TB=NULL, mm; int x, y, width, height; COLORREF tc; RGBQUAD _rgb[256]; width = srcBitmap->Width; height = srcBitmap->Height; srcBitmap->GetColors(0, 256, _rgb); srcBitmap->StartScanLine(); trgBitmap->StartScanLine(); for (y = 0; y < height; y++) { SB = srcBitmap->GetScanLine(y); TB = trgBitmap->GetScanLine(y); x = 0; while (1) { tc = RGBToTColor(_rgb[*SB]); SetPixel24(TB, tc); x++; if (x >= width) break; SB++; TB+=3; } srcBitmap->PutScanLine(y); trgBitmap->PutScanLine(y); } srcBitmap->StopScanLine(); trgBitmap->StopScanLine(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::SetResultImageToCanvas() { BEGIN_LOG(""); TPItemImage *Image = MainImageForm->iMainImage; Image->SubVisible = false; Image->SubEnabled = true; int X, Y; double w, h; extended = false; InitRange(); CheckImageState(X, Y); SetMoveCopyImage(false); CheckExtention(w, h); if (Image->uBitmap->Width < w || Image->uBitmap->Height < h) { Application->MessageBox(IDS_CTRLT_MSG_OVERSCREEN.c_str(), L"Information", MB_ICONINFORMATION); END_LOG; return; } MoveCopyMouseDown(X, Y); if (tMainImage && tMainImage->LayerMask) { delete tMainImage->LayerMask; tMainImage->LayerMask=NULL; } if (tMainImage) delete tMainImage; tMainImage=NULL; END_LOG; } //--------------------------------------------------------------------------- double __fastcall TCtrlTFunc::DoubleABS(double a, double b) { double value = a - b; value = value < 0 ? -value : value; return value; } //--------------------------------------------------------------------------- /** ImageState ϴ Լ̴. ImageState(0): Nomal, ImageState(1): Reverse (ImageState 2 ̸ CanDraw() ɷ־. 1. gpointf[0] gpointf[1] ̷ ̿Ѵ. 2. gpointf[0] ð diff_angleȸ ָ gpointf[1] Ǵ diff_angle Ѵ. 3. diff_angle M_PI normal image, ׷ reverse image̴. */ // by embakum (07.04.04) void __fastcall TCtrlTFunc::CheckImageState(int &sx, int&sy, bool skip) { BEGIN_LOG(""); float minx = MaxInt, miny = MaxInt, maxx = 0, maxy = 0; ///ּ, ִ ã´. for (int i=0; i<4; i++) { minx = min(minx, gpointf[i].X); maxx = max(maxx, gpointf[i].X); miny = min(miny, gpointf[i].Y); maxy = max(maxy, gpointf[i].Y); } double CX = (gpointf[0].X + gpointf[2].X)/2; double CY = (gpointf[0].Y + gpointf[2].Y)/2; double jongik_angle[2], diff_angle; double x_0th = gpointf[0].X-CX; double y_0th = CY - gpointf[0].Y; double x_1st = gpointf[1].X-CX; double y_1st = CY - gpointf[1].Y; jongik_angle[0] = ArcTan2(y_0th, x_0th); jongik_angle[1] = ArcTan2(y_1st, x_1st); for(int i=0;i<2;i++) { if(jongik_angle[i] < 0) jongik_angle[i] += (2* M_PI); } if(jongik_angle[0]>jongik_angle[1]) diff_angle = (2*M_PI) - (jongik_angle[0]-jongik_angle[1]); else diff_angle = jongik_angle[1]-jongik_angle[0]; if (diff_angle < M_PI) ImageState = 0; else ImageState = 1; if (!skip) { MoveCopyRect.s.x = minx; MoveCopyRect.s.y = miny; MoveCopyRect.e.x = maxx; MoveCopyRect.e.y = maxy; MoveCopyRect.size.x = maxx-minx; MoveCopyRect.size.y = maxy-miny; } sx = minx, sy = miny; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TCtrlTFunc::InitRange() { TPItemImage *Image = MainImageForm->iMainImage; window.s.x = MainImageForm->WorkArea->Range.left; window.s.y = MainImageForm->WorkArea->Range.top; window.e.x = MainImageForm->WorkArea->Range.right; window.e.y = MainImageForm->WorkArea->Range.bottom; window.size.x = window.e.x - window.s.x; window.size.y = window.e.y - window.s.y; MoveCopyRect.s = window.s; MoveCopyRect.e = window.e; MoveCopyRect.size = window.size; MoveCopyRect.Bitmap = 0; MoveCopyRect.Mask = 0; MoveCopyRect.Back = 0; Image->SubRange.left = window.s.x; Image->SubRange.top = window.s.y; } //--------------------------------------------------------------------------- ///̸ ̹ ̹ Main Canvas Copyϱ ù° Լ /** ̹ ImageState Nomal, Reverse ̹ . */ void __fastcall TCtrlTFunc::SetMoveCopyImage(bool sw) { BEGIN_LOG(""); TCursor OldCursor; COLORREF bgc; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; Image->InitBackGround(0x02); MoveCopyRect.s = window.s; MoveCopyRect.e = window.e; MoveCopyRect.size = window.size; if(!CreateBitmaps(window.size.x, window.size.y)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->uBitmap->BitsPerPixel==8) { waItr = (WAItr *) new WAItr_8(Image->uBitmap, Image->LayerMask, MainImageForm->WorkArea, &window); windowItr = (WindowItr *) new WindowItr_8(&window); } else { waItr = (WAItr *) new WAItr_24(Image->uBitmap, Image->LayerMask, MainImageForm->WorkArea, &window); windowItr = (WindowItr *) new WindowItr_24(&window); bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); waItr->setBGColor(bgc); } if (!windowItr->startScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!waItr->startScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(ImageState ==0) MakeNormalImage(); else MakeTBMirrorImage(); windowItr->stopScanLine(); waItr->stopScanLine(); if(waItr) delete waItr; if(windowItr) delete windowItr; Screen->Cursor = OldCursor; END_LOG; return; fail: Screen->Cursor = OldCursor; windowItr->stopScanLine(); waItr->stopScanLine(); if(waItr) delete waItr; if(windowItr) delete windowItr; EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- /// Nomal ̹ void __fastcall TCtrlTFunc::MakeNormalImage() { BEGIN_LOG(""); switch (FullViewForm->Super) { case sOff: for (int i=0; igetScanLine(i, 0, window.size.x); waItr->getScanLine(i); for (int j=0; jisInArea(j)) { windowItr->copyPixel(j, waItr->getPixelPointer(j)); } else { windowItr->setToBlank(j); } } windowItr->putScanLine(i, 0, window.size.x); } break; case sOverlap: case sNormal: case sGauze: for (int i=0; igetScanLine(i, 0, window.size.x); waItr->getScanLine(i); for (int j=0; jisInArea(j)) { if (waItr->isNotBGColor(j)) { windowItr->copyPixel(j, waItr->getPixelPointer(j)); } else { windowItr->copyAndBlank(j, waItr->getPixelPointer(j)); } } } windowItr->putScanLine(i, 0, window.size.x); } break; } END_LOG; } //--------------------------------------------------------------------------- /// Reverse ̹ (X Ī ̹) void __fastcall TCtrlTFunc::MakeTBMirrorImage() { BEGIN_LOG(""); switch (FullViewForm->Super) { case sOff: for (int i=0; igetScanLine(i, 0, window.size.x); waItr->getScanLine(window.size.y - 1 - i); for (int j=0; jisInArea(j)) { windowItr->copyPixel(j, waItr->getPixelPointer(j)); } else { windowItr->setToBlank(j); } } windowItr->putScanLine(i, 0, window.size.x); } break; case sOverlap: case sNormal: case sGauze: for (int i=0; igetScanLine(i, 0, window.size.x); waItr->getScanLine(window.size.y - 1 - i); for (int j=0; jisInArea(j)) { if (waItr->isNotBGColor(j)) { windowItr->copyPixel(j, waItr->getPixelPointer(j)); } else { windowItr->copyAndBlank(j, waItr->getPixelPointer(j)); } } } windowItr->putScanLine(i, 0, window.size.x); } break; } END_LOG; } //--------------------------------------------------------------------------- /// ̹ ̸ ̹ ũ Ȯ bool __fastcall TCtrlTFunc::CheckExtention(double &width, double &height) { BEGIN_LOG(""); width = sqrt(pow((gpointf[3].X - gpointf[0].X), 2)+pow((gpointf[3].Y - gpointf[0].Y), 2)); height = sqrt(pow((gpointf[1].X - gpointf[0].X), 2)+pow((gpointf[1].Y - gpointf[0].Y), 2)); if (window.size.x != width || window.size.y != height) { extended = true; END_LOG; return true; } END_LOG; return false; } //--------------------------------------------------------------------------- /// ̵/ ̹ Left/Top(X,Y) ̹ Copyϴ Լ /** 1. CheckExtention() ũ Ȯ 2. ȸ/ũ Ǿٸ BackUpBeforeRotate() ۾ Backup 3. ȸ/ũ Ǿٸ ExpansionMakeBitmapRotate() Size 4. ȸ/ũ Ǿٸ Region 缳 5. ̹ ũⰡ ٸ MakeImage2() ȣ: ӽ LayerImage (ȸ/ũ Ǿٸ ExpansionMakeBitmapRotate() MakeImage()ȣ) 6. RotateImage()ȣϿ ̹ ó */ void __fastcall TCtrlTFunc::MoveCopyMouseDown(int X, int Y) { BEGIN_LOG(""); TCursor OldCursor; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; RECT rd, rs1, rs2; RECT rc; bool undoSw = false; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; double ex_w, ex_h; extended = CheckExtention(ex_w, ex_h); if (extended) { ExpansionRect.left = window.s.x; ExpansionRect.right = window.s.x + ex_w; ExpansionRect.top = window.s.y; ExpansionRect.bottom = window.s.y + ex_h; rs1.left = window.s.x; rs1.top = window.s.y; rs1.right = window.s.x + window.size.x; rs1.bottom = window.s.y + window.size.y; rs2 = ExpansionRect; UnionRect(&rd, &rs1, &rs2); ExpbackRect.left = window.s.x; ExpbackRect.right = window.e.x; ExpbackRect.top = window.s.y; ExpbackRect.bottom = window.e.y; // . BackUpBeforeRotate(); ExpansionMakeBitmapRotate(); //+1 ϱ mask ũⰡ ޶ right, bottom 1px ȭ鿡 //̴ ־. by david 2011.02.09 ExpansionRect.left = 0; // ġ ؼ ׽Ʈ -----1 ExpansionRect.right = ex_w; ExpansionRect.top = 0; ExpansionRect.bottom = ex_h;/////////////////////////////// window.s.x = ExpansionRect.left; window.e.x = ExpansionRect.right; window.s.y = ExpansionRect.top; window.e.y = ExpansionRect.bottom; window.size.x = window.e.x - window.s.x; window.size.y = window.e.y - window.s.y; rc = Rect(ExpansionRect.left, ExpansionRect.top, ExpansionRect.right, ExpansionRect.bottom); // by celberus if (MainImageForm->iMainImage->LayerMask) { First.x = ExpansionRect.left; First.y = ExpansionRect.top; Second.x = ExpansionRect.right; Second.y = ExpansionRect.bottom; SetBitmapRegion(); } else { MainImageForm->WorkArea->IrregularRegion(window.Mask, rc); } } else { ExpbackRect.left = window.s.x; ExpbackRect.right = window.e.x; ExpbackRect.top = window.s.y; ExpbackRect.bottom = window.e.y; window.s.x = 0; window.e.x = window.size.x; window.s.y = 0; window.e.y = window.size.y; // . BackUpBeforeRotate(); MakeImage2(); rc = Rect(window.s.x, window.s.y, window.size.x, window.size.y); if (MainImageForm->iMainImage->LayerMask) { First.x = window.s.x; First.y = window.s.y; Second.x = window.size.x; Second.y = window.size.y; SetBitmapRegion(); } else { MainImageForm->WorkArea->IrregularRegion(window.Mask, rc); } } MainImageForm->WorkAreaChange(); if (!RotateMouseDown(X, Y)) goto fail; if (FullViewForm) { if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { MainImageForm->ApplyPalette(); } FullViewForm->RepaintForm(MainImageForm->iMainImage); } Screen->Cursor = OldCursor; END_LOG; return; fail: if (undoSw == false)EXCEPTION_MESSAGE_OK(ec); Screen->Cursor = OldCursor; END_LOG; } //--------------------------------------------------------------------------- /// ȸ/ũ Ǿ MakeImage()ȣ void __fastcall TCtrlTFunc::ExpansionMakeBitmapRotate() { BEGIN_LOG(""); window.Mask->ResizeStretch((ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top)); window.Bitmap->ResizeStretch((ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top)); MakeImage(); END_LOG; } //------------------------------------------------------------------------- /// ȸ/ũ ũ ӽ TPLayerImage bool __fastcall TCtrlTFunc::MakeImage() { BEGIN_LOG(""); TPItemImage *Image = MainImageForm->iMainImage; Image->uBitmap->RgnBitmap->RemoveRegion(); // convert by celberus if (tMainImage && tMainImage->LayerMask) { delete tMainImage->LayerMask; tMainImage->LayerMask=NULL; } if (tMainImage) delete tMainImage; tMainImage=NULL; tMainImage = new TPLayerImage(MainImageForm); tMainImage->Visible = false; if (Image->uBitmap->BitsPerPixel == 8) { if (!tMainImage->uBitmap->Create((ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top), 8, rgb)) goto fail; tMainImage->uBitmap->BackgroundColor = PALETTEINDEX(0x00); } else { if (!tMainImage->uBitmap->Create((ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top), 24)) goto fail; tMainImage->uBitmap->BackgroundColor = 0; } tMainImage->uBitmap->Copy(0, 0, (ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top), window.Bitmap, 0, 0, SRCCOPY); if(Image->LayerMask) { tMainImage->LayerMask = new TUnionBitmap; if (Image->uBitmap->BitsPerPixel == 8) { if (!tMainImage->LayerMask->Create((ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top), 8, rgb)) goto fail; tMainImage->LayerMask->BackgroundColor = PALETTEINDEX(0x00); } else { if (!tMainImage->LayerMask->Create((ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top), 1)) goto fail; tMainImage->LayerMask->BackgroundColor = 0; } tMainImage->LayerMask->Copy(0, 0, (ExpansionRect.right - ExpansionRect.left), (ExpansionRect.bottom - ExpansionRect.top), window.Mask, 0, 0, SRCCOPY); // convert by celberus } END_LOG; return true; fail: if(window.Back) { delete window.Back; window.Back = NULL; } if (tMainImage && tMainImage->LayerMask) { delete tMainImage->LayerMask; tMainImage->LayerMask=NULL; } if (tMainImage) delete tMainImage; tMainImage=NULL; END_LOG; return false; } //--------------------------------------------------------------------------- /// ̹ ũ ӽ TPLayerImage bool __fastcall TCtrlTFunc::MakeImage2() { BEGIN_LOG(""); TPItemImage *Image = MainImageForm->iMainImage; Image->uBitmap->RgnBitmap->RemoveRegion(); // convert by celberus if (tMainImage) delete tMainImage; tMainImage=NULL; tMainImage = new TPLayerImage(MainImageForm); tMainImage->Visible = false; if (Image->uBitmap->BitsPerPixel == 8) { if (!tMainImage->uBitmap->Create(window.size.x, window.size.y, 8, rgb)) goto fail; } else { if (!tMainImage->uBitmap->Create(window.size.x, window.size.y, 24)) goto fail; } tMainImage->uBitmap->Copy(0, 0, window.size.x, window.size.y, window.Bitmap, 0, 0, SRCCOPY); if(Image->LayerMask) { tMainImage->LayerMask = new TUnionBitmap; if (Image->uBitmap->BitsPerPixel == 8) { if (!tMainImage->LayerMask->Create(window.size.x, window.size.y, 8, rgb)) goto fail; tMainImage->LayerMask->BackgroundColor = PALETTEINDEX(0x00); } else { if (!tMainImage->LayerMask->Create(window.size.x, window.size.y, 1)) goto fail; tMainImage->LayerMask->BackgroundColor = 0; } tMainImage->LayerMask->Copy(0, 0, window.size.x, window.size.y, window.Mask, 0, 0, SRCCOPY); // convert by celberus } END_LOG; return true; fail: if(window.Back) { delete window.Back; window.Back = NULL; } if (tMainImage && tMainImage->LayerMask) { delete tMainImage->LayerMask; tMainImage->LayerMask=NULL; } if (tMainImage) delete tMainImage; tMainImage=NULL; END_LOG; return false; } //--------------------------------------------------------------------------- /// ۾ void __fastcall TCtrlTFunc::SetBitmapRegion() { BEGIN_LOG(""); TCursor cursor; TPItemImage *Image; pBITMAPHANDLE bh; RGNXFORM XForm; HRGN rgnSrc, rgnDst; HDC dc; TWAPointData *pd; TPoint pt[3]; int i; int diff = abs(First.x-Second.x) - abs(First.y-Second.y); RECT rc; bool sw = false; XFORM xForm; DWORD dwSize; double r, h, l, s; RGBQUAD rgb; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; Image = MainImageForm->iMainImage; bh = Image->uBitmap->RgnBitmap->Handle; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; rc.left = min(First.x, Second.x); rc.top = min(First.y, Second.y); rc.right = max(First.x, Second.x)+1; rc.bottom = max(First.y, Second.y)+1; if (L_BitmapHasRgn(bh)) { L_SetBitmapRgnRect(bh, &XForm, &rc, L_RGN_SET); } L_GetBitmapRgnHandle(bh, &XForm, &rgnDst); MainImageForm->WorkArea->SetMask(rgnDst); DeleteObject(rgnDst); Image->OutlineBitmapRgn(MainImageForm->WorkArea->bComplex); Screen->Cursor = cursor; END_LOG; } //--------------------------------------------------------------------------- /// Ȯ/ ̵/ ۾ void __fastcall TCtrlTFunc::BackUpBeforeRotate() { BEGIN_LOG(""); pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle; MainImageForm->WorkArea->SaveToFile(bh, String(DirectoryItem + "\\MoveCopy")); backup = true; END_LOG; } //--------------------------------------------------------------------------- /// Ȯ/ ȸ ̵/ ¿ void __fastcall TCtrlTFunc::BackToBeforeRotate() { BEGIN_LOG(""); pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle; if(backup){ MainImageForm->WorkArea->LoadFromFile(bh, String(DirectoryItem + "\\MoveCopy")); backup = false; } END_LOG; } //--------------------------------------------------------------------------- /// ̹ /** 1. RunDataForRotation(): ȸ ̹ 2. SymmetryMouseDown(): MakeSubBitmap() Ͽ MainImage ̹ Copy */ bool __fastcall TCtrlTFunc::RotateMouseDown(int X, int Y) { BEGIN_LOG(""); TPException ec = EC_NONE; if (!RunDataForRotation()) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return false; } MainImageForm->iMainImage->OnPaintLocate = NULL; if (SymmetryMouseDown(X, Y)) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) MainImageForm->RedrawingRepeat(false, true); END_LOG; return true; fail: END_LOG; return false; } //--------------------------------------------------------------------------- /// ȸ ̹ ó bool __fastcall TCtrlTFunc::RunDataForRotation() { BEGIN_LOG(""); bool bRet = true; TPRotation *Trans = NULL; TPoint Cen; Cen.x = window.s.x + window.size.x / 2; Cen.y = window.s.y + window.size.y / 2; if ((Trans = new TPRotation) == NULL) {SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); END_LOG; return false;} Trans->translation(-Cen.x, -Cen.y); Theta = GetRotateAngle(); Trans->rotation(-Theta); Trans->convert(window.s.x, window.s.y, sx[0], sy[0]); sx[0] = sx[0] + Cen.x; sy[0] = sy[0] + Cen.y; Trans->convert(window.s.x, window.e.y, sx[1], sy[1]); sx[1] = sx[1] + Cen.x; sy[1] = sy[1] + Cen.y; Trans->convert(window.e.x, window.s.y, sx[2], sy[2]); sx[2] = sx[2] + Cen.x; sy[2] = sy[2] + Cen.y; Trans->convert(window.e.x, window.e.y, sx[3], sy[3]); sx[3] = sx[3] + Cen.x; sy[3] = sy[3] + Cen.y; max_x = sx[0]; min_x = max_x; max_y = sy[0]; min_y = max_y; delete Trans; Trans = 0; for (int i = 0; i <= 3; i++) { if (min_x >= sx[i]) min_x = sx[i]; else if (max_x <= sx[i]) max_x = sx[i]; if (min_y >= sy[i]) min_y = sy[i]; else if (max_y <= sy[i]) max_y = sy[i]; } RotateArea = Point(max_x-min_x+1, max_y-min_y+1); if (!MakeRotateImage()) bRet = false; // ֱ BackToBeforeRotate(); END_LOG; return bRet; } //--------------------------------------------------------------------------- /// Ǵ Ʈ Create bool __fastcall TCtrlTFunc::CreateBitmaps(int width, int height, bool bSubBitmap) { BEGIN_LOG(""); TCursor OldCursor; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!window.Bitmap->Create(width, height, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!window.Mask->Create(width, height, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (bSubBitmap && Image->SubBitmap) { if (!Image->SubBitmap->Create(width, height, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Image->SubMask->Create(width, height, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Image->SubMask->BackgroundColor = PALETTEINDEX(0xFF); } window.Bitmap->BackgroundColor = PALETTEINDEX(0x00); window.Mask->BackgroundColor = PALETTEINDEX(0xFF); } else { if (!window.Bitmap->Create(width, height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!window.Mask->Create(width, height, 1)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (bSubBitmap && Image->SubBitmap) { if (!Image->SubBitmap->Create(width, height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Image->SubMask->Create(width, height, 1)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Image->SubMask->BackgroundColor = 0xFFFFFF; } window.Bitmap->BackgroundColor = 0; window.Mask->BackgroundColor = 0xFFFFFF; } Screen->Cursor = OldCursor; END_LOG; return true; fail: DeleteBitmaps(); Screen->Cursor = OldCursor; EXCEPTION_MESSAGE_OK(ec); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; return false; } //OK //------------------------------------------------------------------------- /// Bitmap void __fastcall TCtrlTFunc::DeleteBitmaps() { TPItemImage *Image = MainImageForm->iMainImage; if (window.Bitmap) { delete window.Bitmap; window.Bitmap = NULL; } if (window.Mask) { delete window.Mask; window.Mask = NULL; } if (Image->SubBitmap) { delete Image->SubBitmap; Image->SubBitmap = NULL; } if (Image->SubMask) { delete Image->SubMask; Image->SubMask = NULL; } } //------------------------------------------------------------------------- /// ȸ Ʈ ó, Image->SubBitmap, Image->SubMask Copy bool __fastcall TCtrlTFunc::MakeRotateImage() { BEGIN_LOG(""); TPRotation *Trans = NULL; Extended dx, dy, px, py; TPoint Cen; //a pixel location on screen int LX, LY, xx, yy, i, j; COLORREF bgc; TPItemImage *Image = MainImageForm->iMainImage; //TPImage-TPLayerImage-TPItemImage TPException ec = EC_NONE; if (!MainImageForm->WorkArea->Mask) { END_LOG; return false; } WAItr *waItr = NULL; WindowItr *windowItr = NULL; if ((Trans = new TPRotation) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LX = window.size.x / 2; //TWindowData-window,MoveCopyRect,bendwindow LY = window.size.y / 2; Cen.x = window.s.x + LX; Cen.y = window.s.y + LY; Trans->translation(-Cen.x, -Cen.y); Trans->rotation(-Theta); if(RotateArea.x == 0 || RotateArea.y == 0) { RotateArea.x = window.size.x; RotateArea.y = window.size.y; } // Ȯ/ ȸ ̵ Ҷ super ٲٸ RotateArea 0,0 ä ƾ ȴ. by celberus MoveCopyRect.size = RotateArea; if(!CreateBitmaps(RotateArea.x, RotateArea.y, true)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->uBitmap->BitsPerPixel==8) { waItr = (WAItr *) new WAItr_8(tMainImage->uBitmap, tMainImage->LayerMask, MainImageForm->WorkArea, &window); windowItr = (WindowItr *) new WindowItr_8(&window); } else { waItr = (WAItr *) new WAItr_24(tMainImage->uBitmap, tMainImage->LayerMask, MainImageForm->WorkArea, &window); windowItr = (WindowItr *) new WindowItr_24(&window); bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); waItr->setBGColor(bgc); } waItr->startScanLine(); windowItr->startScanLine(); switch (FullViewForm->Super) { case sOff: // StatusProgress->Maximum = max_y-min_y; for (i=0; i<=max_y-min_y; i++) { StatusProgress->Position = i; windowItr->getScanLine(i, 0, max_x-min_x + 1); for (j=0; j<=max_x-min_x; j++) { Trans->convert(j+min_x, i+min_y, dx, dy); py = dy+LY; yy = floor(py); if (yy>=0 && yy=0 && xxgetScanLine(yy, xx, 1); if (waItr->isInArea(xx)) { windowItr->copyPixel(j, waItr->getPixelPointer(xx)); } else { windowItr->setToBlank(j); } } else { windowItr->setToBlank(j); } } else { windowItr->setToBlank(j); } } windowItr->putScanLine(i, 0, max_x-min_x + 1); } StatusProgress->End(); break; case sOverlap: case sNormal: case sGauze: StatusProgress->Maximum = max_y-min_y; for (i=0; i<=max_y-min_y; i++) { StatusProgress->Position = i; windowItr->getScanLine(i, 0, max_x-min_x + 1); for (j=0; j<=max_x-min_x; j++) { Trans->convert(j+min_x, i+min_y, dx, dy); py = dy+LY; yy = floor(py); if (yy>=0 && yy=0 && xxgetScanLine(yy, xx, 1); if (waItr->isInArea(xx)) { if (waItr->isNotBGColor(xx)) { windowItr->copyPixel(j, waItr->getPixelPointer(xx)); } else { windowItr->copyAndBlank(j, waItr->getPixelPointer(xx)); } } } else { windowItr->setToBlank(j); } } else { windowItr->setToBlank(j); } } windowItr->putScanLine(i, 0, max_x-min_x + 1); } StatusProgress->End(); break; } waItr->stopScanLine(); windowItr->stopScanLine(); delete Trans; if(waItr) delete waItr; if(windowItr) delete windowItr; Image->SubBitmap->Copy(window.Bitmap, SRCCOPY); Image->SubMask->Copy(window.Mask, SRCCOPY); END_LOG; return true; fail: waItr->stopScanLine(); windowItr->stopScanLine(); if (Trans) delete Trans; if(waItr) delete waItr; if(windowItr) delete windowItr; EXCEPTION_MESSAGE_OK(ec); END_LOG; return false; } //OK //--------------------------------------------------------------------------- /// Move/Copy ̹ ó /** 1. Move/Copy Ȯ 2. Undoó 3. Move/Copy WorkAreaó 4. MakeSubBitmap()Լ ȣ: ̹ 5. CopyToImage(): ó Լ ȣ */ bool __fastcall TCtrlTFunc::SymmetryMouseDown(int X, int Y) { BEGIN_LOG(""); int ww, hh; TPException ec = EC_NONE; bool undoSw = false; RECT dstRect, rc; TPItemImage *Image = MainImageForm->iMainImage; int delta_x,delta_y; CheckImageState(X, Y, false); dstRect = Rect(MoveCopyRect.s.x, MoveCopyRect.s.y, MoveCopyRect.e.x, MoveCopyRect.e.y); if (dstRect.left < 0) dstRect.left = 0; if (dstRect.top < 0) dstRect.top = 0; if (dstRect.right > Image->Width) dstRect.right = Image->Width; if (dstRect.bottom > Image->Height) dstRect.bottom = Image->Height; if (isMoveMode) { if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { if(!(undoSw = MainImageForm->UndoSave(UK_ALL, dstRect))) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} MainImageForm->Undo->SaveData(MainImageForm->WorkArea->Range); }else{ if(!(undoSw = MainImageForm->UndoSave(UK_ALL, dstRect))) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} MainImageForm->Undo->SaveData(MainImageForm->WorkArea->Range); } } else { if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { if(!(undoSw = MainImageForm->UndoSave(UK_PATTERN, dstRect))) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} }else{ if(!(undoSw = MainImageForm->UndoSave(UK_PATTERN, dstRect))) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} } } if (isMoveMode) { ExpbackRect1.left = window.s.x; ExpbackRect1.right = window.e.x; ExpbackRect1.top = window.s.y; ExpbackRect1.bottom = window.e.y; window.s.x = ExpbackRect.left; window.e.x = ExpbackRect.right; window.s.y = ExpbackRect.top; window.e.y = ExpbackRect.bottom; window.size.x = window.e.x - window.s.x; window.size.y = window.e.y - window.s.y; EraseWorkAreaIn(); window.s.x = ExpbackRect1.left; window.e.x = ExpbackRect1.right; window.s.y = ExpbackRect1.top; window.e.y = ExpbackRect1.bottom; window.size.x = window.e.x - window.s.x; window.size.y = window.e.y - window.s.y; } if (FullViewForm->Super==sOverlap) { //SubBitmap ũ MoveCopyRect.Size ũⰡ ٸ 찡 ߻Ѵ. //ȸ Ҷ ׹ Ȯ ʿ䰡 ִ. //켱 Ʒ Size . FullViewForm->ReadyToOverlapChange(Image->SubBitmap, Rect(MoveCopyRect.s.x, MoveCopyRect.s.y, MoveCopyRect.s.x + Image->SubBitmap->Width, MoveCopyRect.s.y + Image->SubBitmap->Height), MainImageForm->Palette->UseColor, false, Image->SubMask); } if(isMoveMode){ rc = Rect(X, Y, X + Image->SubBitmap->Width, Y + Image->SubBitmap->Height); MainImageForm->WorkArea->IrregularRegion2(Image->SubMask, rc); MainImageForm->WorkAreaChange(); } MakeSubBitmap(); if ((ec = CopyToImage(X, Y)) != EC_NONE) goto fail; if (FullViewForm->Super==sOverlap && Image->uBitmap->BitsPerPixel == 8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); Image->ChangeRGBColors(rgb); Image->SubBitmap->PutColors(0, 256, rgb); Image->SubMask->PutColors(0, 256, rgb); } END_LOG; return true; fail: if (undoSw) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; return false; } //--------------------------------------------------------------------------- /// Move ۾ void __fastcall TCtrlTFunc::EraseWorkAreaIn() { BEGIN_LOG(""); int i, j; Byte *IP, *WP, *LP, wm; COLORREF color; TPItemImage *Image = MainImageForm->iMainImage; WAItr *waItr = NULL; TPException ec = EC_NONE; if (Image->uBitmap->BitsPerPixel==8) { waItr = (WAItr *) new WAItr_8(Image->uBitmap, Image->LayerMask, MainImageForm->WorkArea, &window); } else { waItr = (WAItr *) new WAItr_24(Image->uBitmap, Image->LayerMask, MainImageForm->WorkArea, &window); color = PaletteForm->DIB256Palette->GetBGCOLORREF(24); waItr->setBGColor(color); } if (!waItr->startScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (i=0; igetScanLine(i); for (j=0; jisInArea(j)) { waItr->erasePixel(j); } } waItr->putScanLine(i); } waItr->stopScanLine(); Image->InitBackGround(0x02); if(waItr) delete waItr; END_LOG; return; fail: waItr->stopScanLine(); if(waItr) delete waItr; EXCEPTION_MESSAGE_OK(ec); END_LOG; } // OK //------------------------------------------------------------------------- /// ̹ ó /** 1. Layer, ȣ, ȣ濡 ó 2. 256, Full ó 3. SubBitmap ̿ؼ Main Canvas Copy */ TPException __fastcall TCtrlTFunc::CopyToImage(int X, int Y) { BEGIN_LOG(""); int i, j, ww, hh; Byte *WP, *WMP, mm; COLORREF color, IC, WC, bgc; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; if (!MainImageForm->WorkArea->Mask) { END_LOG; return ec; } LineItr *lineItr; ww = Image->uBitmap->Width; hh = Image->uBitmap->Height; switch (Image->IsBackGround()) { case 0: if(MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Mask(Image); } else { lineItr = (LineItr *)new LineItr(Image); } break; case 1: if(MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Layer_Mask(Image); } else { lineItr = (LineItr *)new LineItr_Layer(Image); } break; default: SAVE_EXCEPTION(EC_MEMORY_LACK); END_LOG; return EC_MEMORY_LACK; } if (Image->uBitmap->BitsPerPixel==8) { lineItr->setColorProtected(MainImageForm->Protect); if (!lineItr->startScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Image->SubBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Image->SubMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (FullViewForm->Super==sOverlap) { MainImageForm->InitOverlap(); for (i=0; i= hh) continue; if (i>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y+i, MoveCopyRect.s.x, MoveCopyRect.size.x); WP = Image->SubBitmap->GetScanLine(i); WMP = Image->SubMask->GetScanLine(i); int StartX = 0; int EndX = -1; for (j=0; j= ww){ continue; } if (j>=Image->SubBitmap->Width) { continue; /// ߰ } if (*WMP == 0) { if (lineItr->pickColor(MoveCopyRect.s.x + j) > 1) { color = MainImageForm->Overlap(lineItr->pickColor(MoveCopyRect.s.x + j), *WP); if (color==0xFF) { MainImageForm->ExitOverlap(); lineItr->stopScanLine(); Image->SubBitmap->StopScanLine(); Image->SubMask->StopScanLine(); if(lineItr) { delete lineItr; lineItr = NULL; } FullViewForm->ExitOverlapChange(); MainImageForm->Undo->UndoRead(); ::RepaintColor(); END_LOG; return EC_COLOR_OVERFLOW; } else { if(EndX==-1){StartX=j;} EndX=j; lineItr->setBaseColor(color); lineItr->putPixel(MoveCopyRect.s.x + j); } } else { if(EndX==-1){StartX=j;} EndX=j; lineItr->copyPixel(MoveCopyRect.s.x + j, WP); } } } lineItr->putScanLine(MoveCopyRect.s.y+i, StartX+MoveCopyRect.s.x, EndX-StartX+1); } MainImageForm->ExitOverlap(); } else { for (i=0; i= hh) continue; if (i>=Image->SubBitmap->Height) break; /// ߰ lineItr->getScanLine(MoveCopyRect.s.y+i, MoveCopyRect.s.x, MoveCopyRect.size.x); WP = Image->SubBitmap->GetScanLine(i); WMP = Image->SubMask->GetScanLine(i); int StartX = 0; int EndX = -1; for (j=0; j= ww){ continue; } if (j>=Image->SubBitmap->Width) { continue; /// ߰ } if (*WMP == 0) { if(EndX==-1){StartX=j;} EndX=j; lineItr->copyPixel(MoveCopyRect.s.x + j, WP); } } lineItr->putScanLine(MoveCopyRect.s.y+i, StartX+MoveCopyRect.s.x, EndX-StartX+1); } } lineItr->stopScanLine(); Image->SubMask->StopScanLine(); Image->SubBitmap->StopScanLine(); } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (!lineItr->startScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Image->SubBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Image->SubMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (FullViewForm->Super==sOverlap) { MainImageForm->InitOverlap(); for (i=0; i= hh) continue; if (i>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y+i, MoveCopyRect.s.x, MoveCopyRect.size.x); WP = Image->SubBitmap->GetScanLine(i); WMP = Image->SubMask->GetScanLine(i); mm = 0x80; int StartX = 0; int EndX = -1; for (j=0; j=Image->SubBitmap->Width) { continue; /// ߰ } if (MoveCopyRect.s.x+j < 0 || MoveCopyRect.s.x+j >= ww){ if (mm == 1) { WMP++; mm = 0x80; } else mm >>= 1; continue; } if ((*WMP&mm) == 0) { IC = lineItr->pickColor(MoveCopyRect.s.x + j); if (IC != bgc) { if(EndX==-1){StartX=j;} EndX=j; GetPixel24(WP, WC); color = MainImageForm->Overlap(IC, WC); lineItr->setBaseColor(color); lineItr->putPixel(MoveCopyRect.s.x + j); } else { if(EndX==-1){StartX=j;} EndX=j; lineItr->copyPixel(MoveCopyRect.s.x + j, WP); } } if (mm == 1) { mm = 0x80; WMP++; } else { mm >>= 1; } } lineItr->putScanLine(MoveCopyRect.s.y+i, StartX+MoveCopyRect.s.x, EndX-StartX+1); } MainImageForm->ExitOverlap(); } else { for (i=0; i= hh) continue; if (i>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y+i, MoveCopyRect.s.x, MoveCopyRect.size.x); WP = Image->SubBitmap->GetScanLine(i); WMP = Image->SubMask->GetScanLine(i); mm = 0x80; int StartX = 0; int EndX = -1; for (j=0; j=Image->SubBitmap->Width) { continue; /// ߰ } if (MoveCopyRect.s.x+j < 0 || MoveCopyRect.s.x+j >= ww){ if (mm == 1) { WMP++; mm = 0x80; } else mm >>= 1; continue; } if ((*WMP&mm) == 0) { if(EndX==-1){StartX=j;} EndX=j; lineItr->copyPixel(MoveCopyRect.s.x + j, WP); } if (mm == 1) { mm = 0x80; WMP++; } else { mm >>= 1; } } lineItr->putScanLine(MoveCopyRect.s.y+i, StartX+MoveCopyRect.s.x, EndX-StartX+1); } } lineItr->stopScanLine(); Image->SubMask->StopScanLine(); Image->SubBitmap->StopScanLine(); } if(lineItr) { delete lineItr; lineItr = NULL; } END_LOG; return EC_NONE; fail: lineItr->stopScanLine(); Image->SubMask->StopScanLine(); Image->SubBitmap->StopScanLine(); if(lineItr) { delete lineItr; lineItr = NULL; } END_LOG; return ec; } //--------------------------------------------------------------------------- ///IamgeState ̹ Լ /** ⺻ 簢϶ ߽ 4 PI̱ Ʒ PI ش. | | (4)----------(߽)------------( 0϶ ) | */ double __fastcall TCtrlTFunc::GetRotateAngle() { double CX = (gpointf[0].X + gpointf[2].X)/2; double CY = (gpointf[0].Y + gpointf[2].Y)/2; double x_4th = gpointf[4].X - CX; double y_4th = CY - gpointf[4].Y; double r_angle = ArcTan2(y_4th, x_4th); return M_PI-r_angle; } //--------------------------------------------------------------------------- /**CT_NONE, CT_FREE, CT_SCALE, CT_ROTATE, CT_SKEW, CT_DISTORT, CT_PERSPECTIVE, CT_WARP, CT_ROTATE180, CT_ROTATE90CW, CT_ROTATE90CCW, CT_FLIPHORZ, CT_FLIPVERT */ void __fastcall TCtrlTFunc::PopupMenuClick(int index) { BEGIN_LOG(""); //TCT_Item switch(index) { case 0: ///< Free TCT_Item = CT_FREE; break; case 1: ///< Scale TCT_Item = CT_SCALE; break; case 2: ///< ROTATE TCT_Item = CT_ROTATE; break; case 3: ///< ROTATE180 case 4: ///< ROTATE90CW case 5: ///< ROTATE90CCW { float tx, ty; if (index==3) Angle=M_PI; ///iMainImage->Repaint(); break; } case 6: ///< FLIP HORZ float h_gap; for (int i=0; i<4; i++) { h_gap = gpointf[i].X - gpointf[8].X; gpointf[i].X -= (h_gap*2); } if (CheckCenterPoint()) { gpointf[0].X -= 0.5; MakeBaseRect(gpointf[0], gpointf[2]); } else { MakeBaseRect(gpointf[0], gpointf[2], false); } MainImageForm->iMainImage->Repaint(); break; case 7: ///< FLIP VERT double v_gap; for (int i=0; i<4; i++) { v_gap = gpointf[i].Y - gpointf[8].Y; gpointf[i].Y -= (v_gap*2); } if (CheckCenterPoint()) { gpointf[0].X -= 0.5; MakeBaseRect(gpointf[0], gpointf[2]); } else { MakeBaseRect(gpointf[0], gpointf[2], false); } MainImageForm->iMainImage->Repaint(); break; case 8: ///< Move the central point dCenterIn = true; MakeBaseRect(gpointf[0], gpointf[2]); MainImageForm->iMainImage->Repaint(); break; case 9: isMoveMode = false; break; case 10: isMoveMode = true; break; } END_LOG; } //--------------------------------------------------------------------------- /// Center Point 簢 ȿ bool __fastcall TCtrlTFunc::CheckCenterPoint() { double CX = (gpointf[0].X + gpointf[2].X)/2; double CY = (gpointf[0].Y + gpointf[2].Y)/2; if ( (CX-0.5 <= gpointf[8].X && gpointf[8].X <= CX+0.5) && (CY-0.5 <= gpointf[8].Y && gpointf[8].Y <= CY+0.5) ) { return true; } return false; } //--------------------------------------------------------------------------- /// SubBitmap Լ /** 1. Layer, ȣ, ȣ濡 ó (MainImageForm->MaskArea, MainImageForm->Protect ó) 2. PenManager ħ ̹ */ bool __fastcall TCtrlTFunc::MakeSubBitmap(bool superChanged) { BEGIN_LOG(""); Byte *PP, *MP, *MBP, *DP, *IP, *MMP, mm; int x, y, ww, hh; COLORREF bgc, c; TPItemImage *Image = MainImageForm->iMainImage; LineItr *lineItr; ww = Image->uBitmap->Width; hh = Image->uBitmap->Height; if (!superChanged && !MainImageForm->MaskArea && FullViewForm->Super != sGauze) { if (Image->uBitmap->BitsPerPixel == 24) { END_LOG; return true; } else if (!MainImageForm->Protect) { END_LOG; return true; } } switch (MainImageForm->iMainImage->IsBackGround()) { case 0: if(MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Mask(Image); } else { lineItr = (LineItr *)new LineItr(Image); } break; case 1: if(MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Layer_Mask(Image); } else { lineItr = (LineItr *)new LineItr_Layer(Image); } break; default: { END_LOG; return false; } } if (Image->uBitmap->BitsPerPixel == 8) { lineItr->setColorProtected(MainImageForm->Protect); if (!lineItr->startScanLine()) goto fail; if (!Image->SubBitmap->StartScanLine()) goto fail; if (!Image->SubMask->StartScanLine()) goto fail; if (!window.Bitmap->StartScanLine()) goto fail; if (!window.Mask->StartScanLine()) goto fail; if (FullViewForm->Super == sGauze) { for (y = 0; y < MoveCopyRect.size.y; y++) { if (MoveCopyRect.s.y + y < 0 || MoveCopyRect.s.y + y >= hh) continue; if (y>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y + y, MoveCopyRect.s.x, MoveCopyRect.size.x); DP = Image->SubBitmap->GetScanLine(y); MMP = Image->SubMask->GetScanLine(y); PP = window.Bitmap->GetScanLine(y); MP = window.Mask->GetScanLine(y); int StartX = 0; int EndX = -1; //adsfadsf_for_declare for (x = 0; x < MoveCopyRect.size.x; x++, DP++, MMP++, PP++, MP++) { //////adsfadsf_for//////adsfadsf_Variable_Checked if (MoveCopyRect.s.x + x < 0 || MoveCopyRect.s.x + x >= ww){ continue; } if (x>=Image->SubBitmap->Width) { continue; /// ߰ } if (!lineItr->isProtected(MoveCopyRect.s.x + x)) { if (*MP) { if(EndX==-1){StartX=x;} EndX=x; *MMP = 0xFF;//////adsfadsf_Variable_Checked } else { if (lineItr->pickColor(MoveCopyRect.s.x + x) > 1){ if ((y+x)&1) { if(EndX==-1){StartX=x;} EndX=x; *DP = *PP; *MMP = 0; } else { if(EndX==-1){StartX=x;} EndX=x; *MMP = 0xFF; //////adsfadsf_Variable_Checked } } else { if(EndX==-1){StartX=x;} EndX=x; *DP = *PP; *MMP = 0; } } } else { if(EndX==-1){StartX=x;} EndX=x; *MMP = 0xFF;//Variable_Checked } } Image->SubMask->PutScanLine(y,StartX,EndX-StartX+1); Image->SubBitmap->PutScanLine(y,StartX,EndX-StartX+1); } } else { for (y = 0; y < MoveCopyRect.size.y; y++) { if (MoveCopyRect.s.y + y < 0 || MoveCopyRect.s.y + y >= hh) continue; if (y>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y + y, MoveCopyRect.s.x, MoveCopyRect.size.x); DP = Image->SubBitmap->GetScanLine(y); MMP = Image->SubMask->GetScanLine(y); PP = window.Bitmap->GetScanLine(y); MP = window.Mask->GetScanLine(y); int StartX = 0; int EndX = -1; //for_declare for (x = 0; x < MoveCopyRect.size.x; x++, DP++, MMP++, PP++, MP++) { //////adsfadsf_for//////adsfadsf_Variable_Checked if (MoveCopyRect.s.x + x < 0 || MoveCopyRect.s.x + x >= ww){ continue; } if (x>=Image->SubBitmap->Width) { continue; /// ߰ } if (!lineItr->isProtected(MoveCopyRect.s.x + x)) { if (*MP) { if(EndX==-1){StartX=x;} EndX=x; *MMP = 0xFF; //Variable_Checked } else { if(EndX==-1){StartX=x;} EndX=x; *DP = *PP; *MMP = 0; ///Variable_Checked } } else { if(EndX==-1){StartX=x;} EndX=x; *MMP = 0xFF;//Variable_Checked } } Image->SubMask->PutScanLine(y,StartX,EndX-StartX+1); Image->SubBitmap->PutScanLine(y,StartX,EndX-StartX+1); } } lineItr->stopScanLine(); window.Mask->StopScanLine(); window.Bitmap->StopScanLine(); Image->SubMask->StopScanLine(); Image->SubBitmap->StopScanLine(); } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (!lineItr->startScanLine()) goto fail; if (!Image->SubBitmap->StartScanLine()) goto fail; if (!Image->SubMask->StartScanLine()) goto fail; if (!window.Bitmap->StartScanLine()) goto fail; if (!window.Mask->StartScanLine()) goto fail; if (FullViewForm->Super == sGauze) { for (y = 0; y < MoveCopyRect.size.y; y++) { if (MoveCopyRect.s.y + y < 0 || MoveCopyRect.s.y + y >= hh) continue; if (y>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y + y, MoveCopyRect.s.x, MoveCopyRect.size.x); DP = Image->SubBitmap->GetScanLine(y); MMP = Image->SubMask->GetScanLine(y); PP = window.Bitmap->GetScanLine(y); MP = window.Mask->GetScanLine(y); int StartX = 0; int EndX = -1; //for_declare x = 0; *MMP = 0; mm = 0x80; while(1) { //while if (MoveCopyRect.s.x + x < 0 || MoveCopyRect.s.x + x >= ww) { x++; if (x >= MoveCopyRect.size.x) break; DP+=3; PP+=3; if (mm == 1) { MP++; MMP++; *MMP = 0; mm = 0x80; } else mm >>= 1; continue; } if (!lineItr->isProtected(MoveCopyRect.s.x + x)) { if (*MP & mm) { if(EndX==-1){StartX=x;} EndX=x; *MMP |= mm;//Variable_Checked } else { c = lineItr->pickColor(MoveCopyRect.s.x + x); if (c!=bgc) { if ((y+x)&1) { if(EndX==-1){StartX=x;} EndX=x; CopyPixel24(DP, PP);///Variable_Checked } else { if(EndX==-1){StartX=x;} EndX=x; *MMP |= mm;//Variable_Checked } if(EndX==-1){StartX=x;} EndX=x; } else CopyPixel24(DP, PP);//Variable_Checked } } else { if(EndX==-1){StartX=x;} EndX=x; *MMP |= mm;///Variable_Checked } x++; if (x >= MoveCopyRect.size.x) break; DP+=3; PP+=3; if (mm == 1) { MP++; MMP++; *MMP = 0; mm = 0x80; } else mm >>= 1; } Image->SubMask->PutScanLine(y,StartX,EndX-StartX+1); Image->SubBitmap->PutScanLine(y,StartX,EndX-StartX+1); } } else { for (y = 0; y < MoveCopyRect.size.y; y++) { if (MoveCopyRect.s.y + y < 0 || MoveCopyRect.s.y + y >= hh) continue; if (y>=Image->SubBitmap->Height) { continue; /// ߰ } lineItr->getScanLine(MoveCopyRect.s.y + y, MoveCopyRect.s.x, MoveCopyRect.size.x); DP = Image->SubBitmap->GetScanLine(y); MMP = Image->SubMask->GetScanLine(y); PP = window.Bitmap->GetScanLine(y); MP = window.Mask->GetScanLine(y); int StartX = 0; int EndX = -1; //for_declare x = 0; *MMP = 0; mm = 0x80; while(1) { ///while if (MoveCopyRect.s.x + x < 0 || MoveCopyRect.s.x + x >= ww) { x++; if (x >= MoveCopyRect.size.x) break; DP+=3; PP+=3; if (mm == 1) { MP++; MMP++; *MMP = 0; mm = 0x80; } else mm >>= 1; continue; } if (!lineItr->isProtected(MoveCopyRect.s.x + x)) { if (*MP & mm) { if(EndX==-1){StartX=x;} EndX=x; *MMP |= mm;///Variable_Checked } else { if(EndX==-1){StartX=x;} EndX=x; CopyPixel24(DP, PP);//Variable_Checked } } else { if(EndX==-1){StartX=x;} EndX=x; *MMP |= mm;//Variable_Checked } x++; if (x >= MoveCopyRect.size.x) break; DP+=3; PP+=3; if (mm == 1) { MP++; MMP++; *MMP = 0; mm = 0x80; } else mm >>= 1; } Image->SubMask->PutScanLine(y,StartX,EndX-StartX+1); Image->SubBitmap->PutScanLine(y,StartX,EndX-StartX+1); } } lineItr->stopScanLine(); window.Mask->StopScanLine(); window.Bitmap->StopScanLine(); Image->SubMask->StopScanLine(); Image->SubBitmap->StopScanLine(); } if(lineItr) { delete lineItr; lineItr = NULL; } END_LOG; return true; fail: lineItr->stopScanLine(); window.Mask->StopScanLine(); window.Bitmap->StopScanLine(); Image->SubBitmap->StopScanLine(); Image->SubMask->StopScanLine(); if(lineItr) { delete lineItr; lineItr = NULL; } END_LOG; return false; } //--------------------------------------------------------------------------- ///shift down óÿ ̴ ִ ϴ Լ int __fastcall TCtrlTFunc::GetPointXYForShift(gdp::PointF firstPoint, gdp::PointF secondPoint, int &X, int &Y) { double angle; if ((secondPoint.X - firstPoint.X)==0) return -1; angle = (secondPoint.Y - firstPoint.Y)/(secondPoint.X - firstPoint.X); if ((Y - (angle*X + firstPoint.Y - angle*firstPoint.X)) > 0) { Y = angle*X + firstPoint.Y - angle*firstPoint.X; return Y; } else { if(angle!=0) X = (Y - firstPoint.Y + angle*firstPoint.X)/angle; else return -1; return X; } } //---------------------------------------------------------------------------