//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Repro_F.h" #include "FullView.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #include "MainMenu.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_PULL StringTable[0] #define IDS_PERSPFIXX StringTable[1] #define IDS_PERSPFIXY StringTable[2] #define IDS_TYPE StringTable[3] #define IDS_RATIO StringTable[4] #define IDS_PERSPANGLE StringTable[5] #define IDS_PERSPDISTANCE StringTable[6] #define IDS_PERSPSHAPE StringTable[7] #define IDS_SETPOINT StringTable[8] #define IDS_INITIALIZE StringTable[9] //--------------------------------------------------------------------------- TReproForm *ReproForm; //--------------------------------------------------------------------------- __fastcall TReproForm::TReproForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; StringTable.Create(DirectoryBin, Language, "Repro"); SetSmallFont(Font); SetSmallFont(StaticText5->Font); SetSmallFont(lShape->Font); SetSmallFont(Label2->Font); SetSmallFont(Label3->Font); SetSmallFont(Label4->Font); SetSmallFont(Label5->Font); SetSmallFont(Label6->Font); SetSmallFont(Label9->Font); SetSmallFont(lYlength2->Font); SetSmallFont(lYlength1->Font); SetSmallFont(lXlength2->Font); SetSmallFont(lXlength1->Font); SetSmallFont(LeftRightLabel->Font); SetSmallFont(UpDownLabel->Font); sbRect->Caption = IDS_COMMON_RECTANGLE; sbPull->Caption = IDS_PULL; sbX->Caption = IDS_PERSPFIXX; sbY->Caption = IDS_PERSPFIXY; lShape->Caption = IDS_TYPE; btnSize->Caption = IDS_RATIO; btnRectRun->Caption = IDS_COMMON_RUN; Label2->Caption = IDS_PERSPANGLE; Label3->Caption = IDS_PERSPDISTANCE; Label9->Caption = IDS_PERSPSHAPE; LeftRightLabel->Caption = IDS_COMMON_LEFT; btnYrun->Caption = IDS_COMMON_RUN; Label4->Caption = IDS_PERSPANGLE; Label5->Caption = IDS_PERSPDISTANCE; Label6->Caption = IDS_PERSPSHAPE; UpDownLabel->Caption = IDS_COMMON_UP; btnXRun->Caption = IDS_COMMON_RUN; StaticText5->Caption = IDS_SETPOINT; btnPull->Caption = IDS_COMMON_RUN; btInit->Caption = IDS_INITIALIZE; } //--------------------------------------------------------------------------- void __fastcall TReproForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TReproForm::btnSizeClick(TObject *Sender) { if (btnSize->Caption == IDS_COMMON_LENGTH) { btnSize->Caption = IDS_RATIO; } else if (btnSize->Caption == IDS_RATIO) { btnSize->Caption = IDS_COMMON_LENGTH; } ChangeUnit(MainImageForm->CurrentUnit); } //--------------------------------------------------------------------------- void __fastcall TReproForm::btInitClick(TObject *Sender) { if (item == TREPRO_RECT || item == TREPRO_NULL) { MainImageForm->iSelectImage->Width = 0; MainImageForm->iSelectImage->Height = 0; InitRect(); SetSizeText(); } } //--------------------------------------------------------------------------- void __fastcall TReproForm::UpDownLabelClick(TObject *Sender) { if (item == TREPRO_XFIX) { if (XTextItem == _StateDown) { UpDownLabel->Caption = IDS_COMMON_UP; XTextItem = _StateUp; } else if (XTextItem == _StateUp) { UpDownLabel->Caption = IDS_COMMON_DOWN; XTextItem = _StateDown; } } else if (item == TREPRO_YFIX) { if (YTextItem == _StateRight) { LeftRightLabel->Caption = IDS_COMMON_LEFT; YTextItem = _StateLeft; } else if (YTextItem == _StateLeft) { LeftRightLabel->Caption = IDS_COMMON_RIGHT; YTextItem = _StateRight; } } } //--------------------------------------------------------------------------- void __fastcall TReproForm::btnXRunClick(TObject *Sender) { TCursor OldCursor; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; perspective_reproportion(); MainImageForm->WorkAreaReset(); Screen->Cursor = OldCursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TReproForm::btnPullClick(TObject *Sender) { TCursor OldCursor; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; pull_image_repro(); MainImageForm->WorkAreaReset(); Screen->Cursor = OldCursor; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TReproForm::EditKeyPress1(TObject *Sender, char &Key) { if(Key == 13 && sbPull->Down)btnPullClick(this); //lhskys ¿£Å͸¦ ¹Þ¾ÒÀ»¶§ else if (Key == 13) { //lhskys edit·Î °¥°ÍÀΰ¡ ÆÇ´Ü if (sbRect->Down == false || norun == 1){ //lhskys PullEdit(Sender); //lhskys SelectNext((TWinControl *)Sender, true, true); //lhskys ¹Ù·Î ½ÇÇàŰ·Î.... Key = 0; //lhskys PreviewRun(this); //lhskys } } } //--------------------------------------------------------------------------- void __fastcall TReproForm::FunctionClick(TObject *Sender) { TSpeedButton *s; MainImageForm->iMainImage->OnPaintLocate=NULL; MainImageForm->iMainImage->Repaint(); ///////»©Áö¸¶½Ã¿À //PULL¿¡¼­ ¾¸ s = (TSpeedButton *)Sender; if (s == sbRect) { RectMode(); InitRect(); sbRect->Down = true; } else if (s == sbPull) { PullMode(); MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; sbPull->Down = true; btnPull->SetFocus(); //lhskys ¿£ÅÍ·Î ½ÇÇàÇϱâ } else if (s == sbX) { XReproMode(); MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; sbX->Down = true; } else if (s == sbY) { YReproMode(); MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; sbY->Down = true; } } //--------------------------------------------------------------------------- void __fastcall TReproForm::PullEdit(TObject *Sender) { TEdit *e; int l1, l2, angle, ratio; e = (TEdit *)Sender; if (e->Text != "") { if (e == EXAngle) { compute_len(l1, l2); angle = StrToInt(EXAngle->Text); if ((angle > 9) && (angle < 81)) { s_repro.angle = angle; compute_len(l1, l2); lXlength1->Caption = l1; lXlength2->Caption = l2; } else { EXAngle->Text = s_repro.angle; } if ((s_repro.ratio < l1) || (s_repro.ratio > l2)) { s_repro.ratio = l1; lXlength1->Caption = l1; lXlength2->Caption = l2; EXratio->Text = l1; } } else if (e == EXratio) { compute_len(l1, l2); lXlength1->Caption = l1; lXlength2->Caption = l2; ratio = StrToInt(EXratio->Text); if ((ratio >= l1) && (ratio <= l2)) { s_repro.ratio = ratio; lXlength1->Caption = l1; lXlength2->Caption = l2; EXratio->Text = s_repro.ratio; } else { lXlength1->Caption = l1; lXlength2->Caption = l2; EXratio->Text = s_repro.ratio; } } else if (e == eYAngle) { compute_len(l1, l2); angle = StrToInt(eYAngle->Text); if ((angle > 9) && (angle < 81)) { s_repro.angle = angle; compute_len(l1, l2); lYlength1->Caption = l1; lYlength2->Caption = l2; } else { eYAngle->Text = s_repro.angle; } if ((s_repro.ratio < l1) || (s_repro.ratio > l2)) { s_repro.ratio = l1; lYlength1->Caption = l1; lYlength2->Caption = l2; eYratio->Text = l1; } } else if (e == eYratio) { compute_len(l1, l2); lYlength1->Caption = l1; lYlength2->Caption = l2; ratio = StrToInt(eYratio->Text); if ((ratio >= l1) && (ratio <= l2)) { s_repro.ratio = ratio; lYlength1->Caption = l1; lXlength2->Caption = l2; eYratio->Text = s_repro.ratio; } else { lYlength1->Caption = l1; lYlength2->Caption = l2; eYratio->Text = s_repro.ratio; } } } } //--------------------------------------------------------------------------- void __fastcall TReproForm::shRectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TPSelectImage *ReproImage = MainImageForm->iSelectImage; eXsize->SetFocus(); eXsize->SelectAll(); norun = 1; //lhskys ½ÇÇàÀ» ÇÒ¶§¸¦ Ç¥½ÃÇϱâÀ§ÇØ InitRect(); ReproImage->Enabled = true; ReproImage->Visible = false; } //--------------------------------------------------------------------------- void __fastcall TReproForm::btnRectRunClick(TObject *Sender) { norun = 0; //lhskys ½ÇÇàÀ» ÇÏÁö ¾ÊÀ»¶§¸¦ Ç¥½ÃÇϱâÀ§ÇØ bool crtSw = false; TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; if (btnSize->Caption == IDS_COMMON_LENGTH) { if (eXsize->Text != "") { switch (MainImageForm->CurrentUnit) { case uDot : ReproRect.size.x = StrToInt(eXsize->Text); break; case uInch : ReproRect.size.x = StrToFloat(eXsize->Text) * MainImageForm->CanvasInfor.DotsPerInch; break; case uCm : ReproRect.size.x = StrToFloat(eXsize->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54; } } if (eYsize->Text != "") { switch (MainImageForm->CurrentUnit) { case uDot : ReproRect.size.y = StrToInt(eYsize->Text); break; case uInch : ReproRect.size.y = StrToFloat(eYsize->Text) * MainImageForm->CanvasInfor.DotsPerInch; break; case uCm : ReproRect.size.y = StrToFloat(eYsize->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54; } } } else if (btnSize->Caption == IDS_RATIO) { if (eXsize->Text != "") { ReproRect.size.x = window.size.x * StrToFloat(eXsize->Text) / 100.0; } if (eYsize->Text != "") { ReproRect.size.y = window.size.y * StrToFloat(eYsize->Text) / 100.0; } } MainImageForm->iMainImage->SubEnabled = true; if (Image->Bitmap->BitsPerPixel==8) { if ((crtSw = window.Back->Create(ReproRect.size.x, ReproRect.size.y, 8, rgb)) == false) goto fail; if (ReproImage->Bitmap->Create(ReproRect.size.x, ReproRect.size.y, 8, rgb) == false) goto fail; } else { if ((crtSw = window.Back->Create(ReproRect.size.x, ReproRect.size.y, 24)) == false) goto fail; if (ReproImage->Bitmap->Create(ReproRect.size.x, ReproRect.size.y, 24) == false) goto fail; } ReproImage->SetPosition(0, 0); Image->SubVisible = false; rect_repro(); return; fail : if (crtSw) window.Back->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::XYEditClick(TObject *Sender) { TEdit *s = (TEdit *) Sender; s->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TReproForm::XYEditDblClick(TObject *Sender) { TEdit *s = (TEdit *) Sender; s->SelectAll(); s->SetFocus(); } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void __fastcall TReproForm::AddIrrePoint(TList *list, bool curve, TPoint pos, TPoint apex) { } //--------------------------------------------------------------------------- void __fastcall TReproForm::moveline(void) { MainImageForm->DrawLineLocate(Point(Rpos[0].x, Rpos[0].y), Point(Rpos[1].x, Rpos[1].y)); MainImageForm->DrawLineLocate(Point(Rpos[1].x, Rpos[1].y), Point(Rpos[2].x, Rpos[2].y)); MainImageForm->DrawLineLocate(Point(Rpos[2].x, Rpos[2].y), Point(Rpos[3].x, Rpos[3].y)); MainImageForm->DrawLineLocate(Point(Rpos[3].x, Rpos[3].y), Point(Rpos[0].x, Rpos[0].y)); } //--------------------------------------------------------------------------- void __fastcall TReproForm::perspective_reproportion(void) { int c, d, x, y, xi; double sd, xd, l, alpha1, alpha2, theta, a, b, x1, x2, y1, y2, si, yi, yd; TPoint u_ptr, tp, tp1, tp2; Byte *IPP, *IPM, *AP, *APN; TTexpiaBitmap *area; bool undoSw = false, sw; TPItemImage *Image = MainImageForm->iMainImage; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height))) == false) goto fail; area = Undo->Last->Bitmap; Image->Bitmap->FillRect(Rect(window.s.x, window.s.y, window.e.x, window.e.y), PaletteForm->DIB256Palette->GetBGCOLORREF(Image->Bitmap->BitsPerPixel)); if(Image->Bitmap->StartScanLine() == false) goto fail; if(area->StartScanLine() == false) goto fail; if (item == TREPRO_XFIX) { sw = UpDownLabel->Caption == IDS_COMMON_UP; alpha1 = (90.0 - s_repro.angle) * M_PI / 180.0; a = tan(alpha1); alpha2 = atan(2.0 * a) - alpha1; b = tan(alpha2); l = s_repro.ratio; y1 = l * a; y2 = l * b; if (sw) { tp1 = Point(window.s.x + (window.size.x >> 1), window.e.y); } else { tp1 = Point(window.s.x + (window.size.x >> 1), window.s.y); } if (Image->Bitmap->BitsPerPixel==8) { for (d = 0; d < y1 + y2; d++) { if (d < y1) { theta = atan((y1 - d) / l); c = (window.size.y / (2.0 * a)) * tan(alpha1 - theta); if (sw) { u_ptr = Point(tp1.x, tp1.y - c); tp2 = Point(tp1.x, tp1.y - d); } else { u_ptr = Point(tp1.x, tp1.y + c); tp2 = Point(tp1.x, tp1.y + d); } si = window.size.y / (2 * a * cos(alpha1 - theta)); sd = l / cos(theta); xd = window.size.x * sd / (2.0 * si); IPP = IPM = Image->Bitmap->GetScanLine(tp2.y) + tp2.x; AP = area->GetScanLine(u_ptr.y) + u_ptr.x; for (x = 0; x < xd; x++, IPP++, IPM--) { xi = x * si / sd; if (sw) { if ((tp2.y == window.e.y - d) || (tp2.y == window.e.y - d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { *IPP = *(AP + xi); } if (tp2.x - x >= 0) { *IPM = *(AP - xi); } } } else { if ((tp2.y == window.s.y + d) || (tp2.y == window.s.y + d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { *IPP = *(AP + xi); } if (tp2.x - x >= 0) { *IPM = *(AP - xi); } } } } Image->Bitmap->PutScanLine(tp2.y); } else { theta = atan((d - y1) / l); c = window.size.y / (2.0 * a) * tan(alpha1 + theta); if (sw) { u_ptr = Point(tp1.x, tp1.y - c); tp2 = Point(tp1.x, tp1.y - d); } else { u_ptr = Point(tp1.x, tp1.y + c); tp2 = Point(tp1.x, tp1.y + d); } si = window.size.y / (2.0 * a * cos(alpha1 + theta)); sd = l / cos(theta); xd = window.size.x * sd / (2.0 * si); IPP = IPM = Image->Bitmap->GetScanLine(tp2.y) + tp2.x; AP = area->GetScanLine(u_ptr.y) + u_ptr.x; for (x = 0; x < xd; x++, IPP++, IPM--) { xi = x * si / sd; if (sw) { if ((tp2.y == window.e.y - d) || (tp2.y == window.e.y - d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { *IPP = *(AP + xi); } if (tp2.x - x >= 0) { *IPM = *(AP - xi); } } } else { if ((tp2.y == window.s.y + d) || (tp2.y == window.s.y + d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { *IPP = *(AP + xi); } if (tp2.x - x >= 0) { *IPM = *(AP - xi); } } } } Image->Bitmap->PutScanLine(tp2.y); } } } else { for (d = 0; d < y1 + y2; d++) { if (d < y1) { theta = atan((y1 - d) / l); c = (window.size.y / (2.0 * a)) * tan(alpha1 - theta); if (sw) { u_ptr = Point(tp1.x, tp1.y - c); tp2 = Point(tp1.x, tp1.y - d); } else { u_ptr = Point(tp1.x, tp1.y + c); tp2 = Point(tp1.x, tp1.y + d); } si = window.size.y / (2 * a * cos(alpha1 - theta)); sd = l / cos(theta); xd = window.size.x * sd / (2.0 * si); IPP = IPM = Image->Bitmap->GetScanLine(tp2.y) + 3 * tp2.x; AP = area->GetScanLine(u_ptr.y) + 3 * u_ptr.x; for (x = 0; x < xd; x++, IPP += 3, IPM -= 3) { xi = x * si / sd; if (sw) { if ((tp2.y == window.e.y - d) || (tp2.y == window.e.y - d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { APN = AP + 3 * xi; CopyPixel24(IPP, APN); } if (tp2.x - x >= 0) { APN = AP - 3 * xi; CopyPixel24(IPM, APN); } } } else { if ((tp2.y == window.s.y + d) || (tp2.y == window.s.y +- d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { APN = AP + 3 * xi; CopyPixel24(IPP, APN); } if (tp2.x - x >= 0) { APN = AP - 3 * xi; CopyPixel24(IPM, APN); } } } } Image->Bitmap->PutScanLine(tp2.y); } else { theta = atan((d - y1) / l); c = window.size.y / (2.0 * a) * tan(alpha1 + theta); if (sw) { u_ptr = Point(tp1.x, tp1.y - c); tp2 = Point(tp1.x, tp1.y - d); } else { u_ptr = Point(tp1.x, tp1.y + c); tp2 = Point(tp1.x, tp1.y + d); } si = window.size.y / (2.0 * a * cos(alpha1 + theta)); sd = l / cos(theta); xd = window.size.x * sd / (2.0 * si); IPP = IPM = Image->Bitmap->GetScanLine(tp2.y) + 3 * tp2.x; AP = area->GetScanLine(u_ptr.y) + 3 * u_ptr.x; for (x = 0; x < xd; x++, IPP += 3, IPM -= 3) { xi = x * si / sd; if (sw) { if ((tp2.y == window.e.y - d) || (tp2.y == window.e.y - d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { APN = AP + 3 * xi; CopyPixel24(IPP, APN); } if (tp2.x - x >= 0) { APN = AP - 3 * xi; CopyPixel24(IPM, APN); } } } else { if ((tp2.y == window.s.y + d) || (tp2.y == window.s.y + d + 1)) { if (tp2.x + x < Image->Bitmap->Width) { APN = AP + 3 * xi; CopyPixel24(IPP, APN); } if (tp2.x - x >= 0) { APN = AP - 3 * xi; CopyPixel24(IPM, APN); } } } } Image->Bitmap->PutScanLine(tp2.y); } } } } else if (item == TREPRO_YFIX) { sw = LeftRightLabel->Caption == IDS_COMMON_LEFT; alpha1 = (90.0 - s_repro.angle) * M_PI / 180.0; a = tan(alpha1); alpha2 = atan(2.0 * a) - alpha1; b = tan(alpha2); l = s_repro.ratio; x1 = l * a; x2 = l * b; if (sw) { tp1 = Point(window.e.x, window.s.y + (window.size.y >> 1)); } else { tp1 = Point(window.s.x, window.s.y + (window.size.y >> 1)); } if (Image->Bitmap->BitsPerPixel==8) { for (d = 0; d < x1 + x2; d++) { if (d < x1) { theta = atan((x1 - d) / l); c = (window.size.x / (2.0 * a)) * tan(alpha1 - theta); if (sw) { u_ptr = Point(tp1.x - c, tp1.y); tp2 = Point(tp1.x - d, tp1.y); } else { u_ptr = Point(tp1.x + c, tp1.y); tp2 = Point(tp1.x + d, tp1.y); } si = window.size.x / (2 * a * cos(alpha1 - theta)); sd = l / cos(theta); yd = window.size.y * sd / (2.0 * si); for (y = 0; y < yd; y++) { yi = y * si / sd; tp.y = window.s.y + (window.size.y >> 1); if (tp.y + y < Image->Bitmap->Height) { *(Image->Bitmap->GetScanLine(tp2.y + y) + tp2.x) = *(area->GetScanLine(u_ptr.y + yi) + u_ptr.x); Image->Bitmap->PutScanLine(tp2.y + y); } if (tp.y - y >= 0) { *(Image->Bitmap->GetScanLine(tp2.y - y) + tp2.x) = *(area->GetScanLine(u_ptr.y - yi) + u_ptr.x); Image->Bitmap->PutScanLine(tp2.y - y); } } } else { theta = atan((d - x1) / l); c = (window.size.x / (2.0 * a)) * tan(alpha1 + theta); if (sw) { u_ptr = Point(tp1.x - c, tp1.y); tp2 = Point(tp1.x - d, tp1.y); } else { u_ptr = Point(tp1.x + c, tp1.y); tp2 = Point(tp1.x + d, tp1.y); } si = window.size.x / (2 * a * cos(alpha1 + theta)); sd = l / cos(theta); yd = window.size.y * sd / (2.0 * si); for (y = 0; y < yd; y++) { yi = y * si / sd; tp.y = window.s.y + (window.size.y >> 1); if (tp.y + y < Image->Bitmap->Height) { *(Image->Bitmap->GetScanLine(tp2.y + y) + tp2.x) = *(area->GetScanLine(u_ptr.y + yi) + u_ptr.x); Image->Bitmap->PutScanLine(tp2.y + y); } if (tp.y - y >= 0) { *(Image->Bitmap->GetScanLine(tp2.y - y) + tp2.x) = *(area->GetScanLine(u_ptr.y - yi) + u_ptr.x); Image->Bitmap->PutScanLine(tp2.y - y); } } } } } else { for (d = 0; d < x1 + x2; d++) { if (d < x1) { theta = atan((x1 - d) / l); c = (window.size.x / (2.0 * a)) * tan(alpha1 - theta); if (sw) { u_ptr = Point(tp1.x - c, tp1.y); tp2 = Point(tp1.x - d, tp1.y); } else { u_ptr = Point(tp1.x + c, tp1.y); tp2 = Point(tp1.x + d, tp1.y); } si = window.size.x / (2 * a * cos(alpha1 - theta)); sd = l / cos(theta); yd = window.size.y * sd / (2.0 * si); for (y = 0; y < yd; y++) { yi = y * si / sd; tp.y = window.s.y + (window.size.y >> 1); if (tp.y + y < Image->Bitmap->Height) { IPP = Image->Bitmap->GetScanLine(tp2.y + y) + 3 * tp2.x; AP = area->GetScanLine(u_ptr.y + yi) + 3 * u_ptr.x; CopyPixel24(IPP, AP); Image->Bitmap->PutScanLine(tp2.y + y); } if (tp.y - y >= 0) { IPP = Image->Bitmap->GetScanLine(tp2.y - y) + 3 * tp2.x; AP = area->GetScanLine(u_ptr.y - yi) + 3 * u_ptr.x; CopyPixel24(IPP, AP); Image->Bitmap->PutScanLine(tp2.y - y); } } } else { theta = atan((d - x1) / l); c = (window.size.x / (2.0 * a)) * tan(alpha1 + theta); if (sw) { u_ptr = Point(tp1.x - c, tp1.y); tp2 = Point(tp1.x - d, tp1.y); } else { u_ptr = Point(tp1.x + c, tp1.y); tp2 = Point(tp1.x + d, tp1.y); } si = window.size.x / (2 * a * cos(alpha1 + theta)); sd = l / cos(theta); yd = window.size.y * sd / (2.0 * si); for (y = 0; y < yd; y++) { yi = y * si / sd; tp.y = window.s.y + (window.size.y >> 1); if (tp.y + y < Image->Bitmap->Height) { IPP = Image->Bitmap->GetScanLine(tp2.y + y) + 3 * tp2.x; AP = area->GetScanLine(u_ptr.y + yi) + 3 * u_ptr.x; CopyPixel24(IPP, AP); Image->Bitmap->PutScanLine(tp2.y + y); } if (tp.y - y >= 0) { IPP = Image->Bitmap->GetScanLine(tp2.y - y) + 3 * tp2.x; AP = area->GetScanLine(u_ptr.y - yi) + 3 * u_ptr.x; CopyPixel24(IPP, AP); Image->Bitmap->PutScanLine(tp2.y - y); } } } } } } area->StopScanLine(); Image->Bitmap->StopScanLine(); ::RepaintImage(); return; fail : if (undoSw) { area->StopScanLine(); Image->Bitmap->StopScanLine(); Undo->RemoveLast(); } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::compute_len(int &l1, int &l2) { double alpha1, alpha2, a, b; alpha1 = (90.0 - s_repro.angle) * M_PI / 180.0; a = tan(alpha1); alpha2 = atan(2.0 * a) - alpha1; b = tan(alpha2); l1 = window.size.y * cos(alpha1) / (2.0 * a); l2 = window.size.y / (a + b); } //--------------------------------------------------------------------------- void __fastcall TReproForm::repro_dis(double *a, double *b, double *c, double *sqr, int i, int j, int k) { a[i] = Rpos[j].y - Rpos[k].y; b[i] = Rpos[k].x - Rpos[j].x; c[i] = Rpos[j].x * Rpos[k].y - Rpos[k].x * Rpos[j].y; sqr[i] = sqrt(a[i] * a[i] + b[i] * b[i]); } //--------------------------------------------------------------------------- void __fastcall TReproForm::pull_image_repro(void) { int x, y, nx, ny, winlx, winly; double lx1, lx2, ly1, ly2; double a[4], b[4], c[4], sqr[4]; TTexpiaBitmap *area; Byte *IP, *AP, *MP; bool undoSw = false; TPlaneVertex pv; TPItemImage *Image = MainImageForm->iMainImage; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height))) == false) goto fail; area = Undo->Last->Bitmap; Image->Bitmap->FillRect(Rect(window.s.x, window.s.y, window.e.x, window.e.y), PaletteForm->DIB256Palette->GetBGCOLORREF(Image->Bitmap->BitsPerPixel)); pv.Create(Rpos[0], Rpos[1], Rpos[2], Rpos[3]); repro_dis(a, b, c, sqr, 0, 0, 1); repro_dis(a, b, c, sqr, 1, 2, 3); repro_dis(a, b, c, sqr, 2, 3, 0); repro_dis(a, b, c, sqr, 3, 1, 2); winlx = window.size.x - 1; winly = window.size.y - 1; if (Image->Bitmap->StartScanLine() == false) goto fail; if (area->StartScanLine() == false) goto fail; if (MainImageForm->MaskArea) { if (Image->Mask->StartScanLine() == false) goto fail; if (Image->Bitmap->BitsPerPixel==8) { if (MainImageForm->Protect) { for (y = pv.start.y; y < pv.end.y; y++) { if (y < Image->Bitmap->Height) { IP = Image->Bitmap->GetScanLine(y)+pv.start.x; MP = Image->Mask->GetScanLine(y)+pv.start.x; for (x = pv.start.x; x < pv.end.x; x++, IP++, MP++) { if (x < Image->Bitmap->Width) { if (MainImageForm->Palette->ColorData[*IP]->Protect == 0 && (*MP == 0)) { if (pv.Check(x, y)) { ly1 = fabs(a[0] * x + b[0] * y + c[0]) / sqr[0]; ly2 = fabs(a[1] * x + b[1] * y + c[1]) / sqr[1]; lx1 = fabs(a[2] * x + b[2] * y + c[2]) / sqr[2]; lx2 = fabs(a[3] * x + b[3] * y + c[3]) / sqr[3]; nx = winlx * lx1 / (lx1 + lx2); ny = winly * ly1 / (ly1 + ly2); *IP = *(area->GetScanLine(window.s.y+ny)+window.s.x+nx); } } } } Image->Bitmap->PutScanLine(y); } } } else { for (y = pv.start.y; y < pv.end.y; y++) { if (y < Image->Bitmap->Height) { IP = Image->Bitmap->GetScanLine(y)+pv.start.x; MP = Image->Mask->GetScanLine(y)+pv.start.x; for (x = pv.start.x; x < pv.end.x; x++, IP++, MP++) { if (x < Image->Bitmap->Width) { if (*MP == 0) { if (pv.Check(x, y)) { ly1 = fabs(a[0] * x + b[0] * y + c[0]) / sqr[0]; ly2 = fabs(a[1] * x + b[1] * y + c[1]) / sqr[1]; lx1 = fabs(a[2] * x + b[2] * y + c[2]) / sqr[2]; lx2 = fabs(a[3] * x + b[3] * y + c[3]) / sqr[3]; nx = winlx * lx1 / (lx1 + lx2); ny = winly * ly1 / (ly1 + ly2); *IP = *(area->GetScanLine(window.s.y+ny)+window.s.x+nx); } } } } Image->Bitmap->PutScanLine(y); } } } } else { for (y = pv.start.y; y < pv.end.y; y++) { if (y < Image->Bitmap->Height) { IP = Image->Bitmap->GetScanLine(y)+3*pv.start.x; MP = Image->Mask->GetScanLine(y); for (x = pv.start.x; x < pv.end.x; x++, IP+=3) { if (x < Image->Bitmap->Width) { if ((MP[x >> 3] & (0x80 >> (x & 7))) == 0) { if (pv.Check(x, y)) { ly1 = fabs(a[0] * x + b[0] * y + c[0]) / sqr[0]; ly2 = fabs(a[1] * x + b[1] * y + c[1]) / sqr[1]; lx1 = fabs(a[2] * x + b[2] * y + c[2]) / sqr[2]; lx2 = fabs(a[3] * x + b[3] * y + c[3]) / sqr[3]; nx = winlx * lx1 / (lx1 + lx2); ny = winly * ly1 / (ly1 + ly2); AP = area->GetScanLine(window.s.y+ny)+3*(window.s.x+nx); CopyPixel24(IP, AP); } } } } Image->Bitmap->PutScanLine(y); } } } Image->Mask->StopScanLine(); } else { if (Image->Bitmap->BitsPerPixel==8) { if (MainImageForm->Protect) { for (y = pv.start.y; y < pv.end.y; y++) { if (y < Image->Bitmap->Height) { IP = Image->Bitmap->GetScanLine(y)+pv.start.x; for (x = pv.start.x; x < pv.end.x; x++, IP++) { if (x < Image->Bitmap->Width) { if (MainImageForm->Palette->ColorData[*IP]->Protect == 0) { if (pv.Check(x, y)) { ly1 = fabs(a[0] * x + b[0] * y + c[0]) / sqr[0]; ly2 = fabs(a[1] * x + b[1] * y + c[1]) / sqr[1]; lx1 = fabs(a[2] * x + b[2] * y + c[2]) / sqr[2]; lx2 = fabs(a[3] * x + b[3] * y + c[3]) / sqr[3]; nx = winlx * lx1 / (lx1 + lx2); ny = winly * ly1 / (ly1 + ly2); *IP = *(area->GetScanLine(window.s.y+ny)+window.s.x+nx); } } } } Image->Bitmap->PutScanLine(y); } } } else { for (y = pv.start.y; y < pv.end.y; y++) { if (y < Image->Bitmap->Height) { IP = Image->Bitmap->GetScanLine(y)+pv.start.x; for (x = pv.start.x; x < pv.end.x; x++, IP++) { if (x < Image->Bitmap->Width) { if (pv.Check(x, y)) { ly1 = fabs(a[0] * x + b[0] * y + c[0]) / sqr[0]; ly2 = fabs(a[1] * x + b[1] * y + c[1]) / sqr[1]; lx1 = fabs(a[2] * x + b[2] * y + c[2]) / sqr[2]; lx2 = fabs(a[3] * x + b[3] * y + c[3]) / sqr[3]; nx = winlx * lx1 / (lx1 + lx2); ny = winly * ly1 / (ly1 + ly2); *IP = *(area->GetScanLine(window.s.y+ny)+window.s.x+nx); } } } Image->Bitmap->PutScanLine(y); } } } } else { for (y = pv.start.y; y < pv.end.y; y++) { if (y < Image->Bitmap->Height) { IP = Image->Bitmap->GetScanLine(y)+3*pv.start.x; for (x = pv.start.x; x < pv.end.x; x++, IP+=3) { if (x < Image->Bitmap->Width) { if (pv.Check(x, y)) { ly1 = fabs(a[0] * x + b[0] * y + c[0]) / sqr[0]; ly2 = fabs(a[1] * x + b[1] * y + c[1]) / sqr[1]; lx1 = fabs(a[2] * x + b[2] * y + c[2]) / sqr[2]; lx2 = fabs(a[3] * x + b[3] * y + c[3]) / sqr[3]; nx = winlx * lx1 / (lx1 + lx2); ny = winly * ly1 / (ly1 + ly2); AP = area->GetScanLine(window.s.y+ny)+3*(window.s.x+nx); CopyPixel24(IP, AP); } } } Image->Bitmap->PutScanLine(y); } } } } area->StopScanLine(); Image->Bitmap->StopScanLine(); ::RepaintImage(); return; fail : Image->Mask->StopScanLine(); area->StopScanLine(); Image->Bitmap->StopScanLine(); if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::PullMouseDown(int x, int y) { int i; for (i = 0; i <= 3; i++) { if ((Rpos[i].x < x + 5) && (Rpos[i].x > x - 5) && (Rpos[i].y < y + 5) && (Rpos[i].y > y - 5)) { if (PullStep == 0) { PullStep = i + 1; break; } else { PullStep = 0; break; } } } } //--------------------------------------------------------------------------- void __fastcall TReproForm::PullMouseMove(int x, int y) { int i; TPItemImage *Image = MainImageForm->iMainImage; for (i = 0; i <= 3; i++) { if ((Rpos[i].x < x + 5) && (Rpos[i].x > x - 5) && (Rpos[i].y < y + 5) && (Rpos[i].y > y - 5)) { Image->Cursor = crHandPoint; break; } else { Image->Cursor = crCross; } } if (PullStep) { moveline(); Rpos[PullStep - 1].x = x; Rpos[PullStep - 1].y = y; moveline(); } } //--------------------------------------------------------------------------- void __fastcall TReproForm::XReproMode(void) { double alpha1, alpha2, a, b, e1, e2; TPSelectImage *ReproImage = MainImageForm->iSelectImage; item = TREPRO_XFIX; RectPanel->Visible = false; PullPanel->Visible = false; YPanel->Visible = false; XPanel->Visible = true; ReproImage->Visible = false; ReproImage->Width = 0; ReproImage->Height = 0; s_repro.angle = 45; EXAngle->Text = s_repro.angle; alpha1 = (90.0 - s_repro.angle) * M_PI / 180.0; a = tan(alpha1); alpha2 = atan(2.0 * a) - alpha1; b = tan(alpha2); e1 = window.size.x * cos(alpha1) / (2.0 * a); e2 = window.size.y / (a + b); s_repro.ratio = (e1 + e2) / 2.0; EXratio->Text = s_repro.ratio; XTextItem = _StateUp; UpDownLabel->Caption = IDS_COMMON_UP; PullEdit(EXAngle); EXAngle->SetFocus(); EXAngle->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TReproForm::PullMode(void) { TPSelectImage *ReproImage = MainImageForm->iSelectImage; item = TREPRO_PULL; RectPanel->Visible = false; YPanel->Visible = false; XPanel->Visible = false; PullPanel->Visible = true; ReproImage->Visible = false; ReproImage->Width = 0; ReproImage->Height = 0; } //--------------------------------------------------------------------------- void __fastcall TReproForm::YReproMode(void) { double alpha1, alpha2, a, b, e1, e2; TPSelectImage *ReproImage = MainImageForm->iSelectImage; item = TREPRO_YFIX; RectPanel->Visible = false; PullPanel->Visible = false; XPanel->Visible = false; YPanel->Visible = true; ReproImage->Visible = false; ReproImage->Width = 0; ReproImage->Height = 0; s_repro.angle = 45; eYAngle->Text = s_repro.angle; alpha1 = (90.0 - s_repro.angle) * M_PI / 180.0; a = tan(alpha1); alpha2 = atan(2.0 * a) - alpha1; b = tan(alpha2); e1 = window.size.x * cos(alpha1) / (2.0 * a); e2 = window.size.y / (a + b); s_repro.ratio = (e1 + e2) / 2.0; eYratio->Text = s_repro.ratio; YTextItem = _StateLeft; LeftRightLabel->Caption = IDS_COMMON_LEFT; PullEdit(eYAngle); eYAngle->SetFocus(); eYAngle->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TReproForm::RectMode(void) { TPSelectImage *ReproImage = MainImageForm->iSelectImage; item = TREPRO_RECT; PullPanel->Visible = false; XPanel->Visible = false; YPanel->Visible = false; RectPanel->Visible = true; ReproImage->Visible = true; InitRect(); } //--------------------------------------------------------------------------- void __fastcall TReproForm::SubMouseMove(int X, int Y) { HDC imageDC = NULL, reproDC = NULL, wbitmapDC = NULL, wmaskDC = NULL, wbackDC = NULL; bool crtSw = false, crtSw1 = false; TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; if (X < 0) X = 0; else if (X > Image->Bitmap->Width) X = Image->Bitmap->Width; if (Y < 0) Y = 0; else if (Y > Image->Bitmap->Height) Y = Image->Bitmap->Height; if (item == TREPRO_RECT) { if (X < window.s.x) { ReproRect.s.x = X; ReproRect.e.x = window.e.x; ReproRect.size.x = window.e.x - X; } else { ReproRect.s.x = window.s.x; ReproRect.e.x = X; ReproRect.size.x = X - ReproRect.s.x; } if (Y < window.s.y) { ReproRect.s.y = Y; ReproRect.e.y = window.e.y; ReproRect.size.y = window.e.y - Y; } else { ReproRect.s.y = window.s.y; ReproRect.e.y = Y; ReproRect.size.y = Y - ReproRect.s.y; } ReproImage->Left = Image->BitmapToCanvasX(ReproRect.s.x); ReproImage->Top = Image->BitmapToCanvasY(ReproRect.s.y); ReproImage->Width = ReproRect.size.x * ReproImage->ZoomIn / ReproImage->ZoomOut; ReproImage->Height = ReproRect.size.y * ReproImage->ZoomIn / ReproImage->ZoomOut; if (ReproRect.size.x == 0 || ReproRect.size.y == 0) return; if (Image->Bitmap->BitsPerPixel==8) { if ((crtSw = window.Back->Create(ReproRect.size.x, ReproRect.size.y, 8, rgb)) == false) goto fail; if ((crtSw1 = ReproImage->Bitmap->Create(ReproRect.size.x, ReproRect.size.y, 8, rgb)) == false) goto fail; } else { if ((crtSw = window.Back->Create(ReproRect.size.x, ReproRect.size.y, 24)) == false) goto fail; if ((crtSw1 = ReproImage->Bitmap->Create(ReproRect.size.x, ReproRect.size.y, 24)) == false) goto fail; } if ((imageDC = Image->Bitmap->CreateDC()) == NULL) goto fail; if ((wbackDC = window.Back->CreateDC()) == NULL) goto fail; if ((wmaskDC = window.Mask->CreateDC()) == NULL) goto fail; if ((wbitmapDC = window.Bitmap->CreateDC()) == NULL) goto fail; if ((reproDC = ReproImage->Bitmap->CreateDC()) == NULL) goto fail; BitBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, imageDC, ReproRect.s.x, ReproRect.s.y, SRCCOPY); SetStretchBltMode(wbackDC, COLORONCOLOR); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wmaskDC, 0, 0, window.size.x, window.size.y, SRCAND); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wbitmapDC, 0, 0, window.size.x, window.size.y, SRCPAINT); BitBlt(reproDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wbackDC, 0, 0, SRCCOPY); ReproImage->Bitmap->DeleteDC(reproDC); window.Bitmap->DeleteDC(wbitmapDC); window.Mask->DeleteDC(wmaskDC); window.Back->DeleteDC(wbackDC); Image->Bitmap->DeleteDC(imageDC); SetSizeText(); } else if (item == TREPRO_PULL) { PullMouseMove(X, Y); } ReproImage->SetPosition(0, 0); return; fail: if (reproDC) ReproImage->Bitmap->DeleteDC(reproDC); if (wbitmapDC) window.Bitmap->DeleteDC(wbitmapDC); if (wmaskDC) window.Mask->DeleteDC(wmaskDC); if (wbackDC) window.Back->DeleteDC(wbackDC); if (imageDC) Image->Bitmap->DeleteDC(imageDC); if (crtSw1) ReproImage->Bitmap->Destroy(); if (crtSw) window.Back->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::InitRect() { ReproRect.s.x = window.s.x; ReproRect.e.x = window.e.x; ReproRect.s.y = window.s.y; ReproRect.e.y = window.e.y; ReproRect.size.x = window.size.x; ReproRect.size.y = window.size.y; } //--------------------------------------------------------------------------- void __fastcall TReproForm::SetSizeText() { if (btnSize->Caption == IDS_COMMON_LENGTH) { switch (MainImageForm->CurrentUnit) { case uDot : eXsize->Text = ReproRect.size.x; break; case uInch : eXsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.x / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eXsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.x / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } switch (MainImageForm->CurrentUnit) { case uDot : eYsize->Text = ReproRect.size.y; break; case uInch : eYsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.y / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eYsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.y / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); } } else if (btnSize->Caption == IDS_RATIO) { eXsize->Text = Format("%.2f", OPENARRAY(TVarRec, (100.0 * ReproRect.size.x / window.size.x))); eYsize->Text = Format("%.2f", OPENARRAY(TVarRec, (100.0 * ReproRect.size.y / window.size.y))); } } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TReproForm::InitForm() { TCursor OldCursor; TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; ParentHeight = Parent->Height+20; ClientHeight = 216; Parent->Height = ParentHeight+ClientHeight; window.Bitmap = NULL; window.Mask = NULL; window.Back = NULL; if ((window.Bitmap = new TTexpiaBitmap) == NULL) goto fail; if ((window.Mask = new TTexpiaBitmap) == NULL) goto fail; if ((window.Back = new TTexpiaBitmap) == NULL) goto fail; PullStep = 0; XTextItem = _StateUp; YTextItem = _StateLeft; item = TREPRO_RECT; sbRect->Down = true; PullPanel->Visible = false; XPanel->Visible = false; YPanel->Visible = false; RectPanel->Visible = true; SetReproImage(); ReproImage->Visible = true; Rpos[0].x = window.s.x; Rpos[0].y = window.s.y; Rpos[1].x = window.e.x; Rpos[1].y = window.s.y; Rpos[2].x = window.e.x; Rpos[2].y = window.e.y; Rpos[3].x = window.s.x; Rpos[3].y = window.e.y; ChangeUnit(MainImageForm->CurrentUnit); Screen->Cursor = OldCursor; btnRectRun->SetFocus(); //lhskys ½ÃÀ۽à focus¸¦ Ç¥½ÃÇϵµ·Ï norun = 0; //lhskys ¿£ÅÍ۸¦ ÃÆÀ»¶§ ½ÇÇà À¯¹«¸¦ Ç¥½ÃÇϱâÀ§ÇØ return; fail: if (window.Back) delete window.Back; if (window.Mask) delete window.Mask; if (window.Bitmap) delete window.Bitmap; Screen->Cursor = OldCursor; ReproImage->Bitmap->Destroy(); ReproImage->Visible = false; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TReproForm::ExitForm(void) { TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; if (window.Back) { delete window.Back; window.Back = 0; } if (window.Mask) { delete window.Mask; window.Mask = 0; } if (window.Bitmap) { delete window.Bitmap; window.Bitmap = 0; } ReproImage->Bitmap->Destroy(); ReproImage->Width = 0; ReproImage->Height = 0; ReproImage->Visible = false; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TReproForm::rect_repro(void) { TCursor OldCursor; int i, j; Byte *IP, *WP, mm; bool undoSw = false; COLORREF c; RECT r; HDC imageDC = NULL, wbitmapDC = NULL, wmaskDC = NULL, wbackDC = NULL; HRGN hRgn = NULL; TPItemImage *Image = MainImageForm->iMainImage; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Image->Bitmap->Width, Image->Bitmap->Height))) == false) goto fail; ReproRect.e.x = ReproRect.s.x + ReproRect.size.x; ReproRect.e.y = ReproRect.s.y + ReproRect.size.y; if (ReproRect.e.x > Image->Bitmap->Width) { ReproRect.e.x = Image->Bitmap->Width; ReproRect.size.x = ReproRect.e.x - ReproRect.s.x; } if (ReproRect.e.y > Image->Bitmap->Height) { ReproRect.e.y = Image->Bitmap->Width; ReproRect.size.y = ReproRect.e.y - ReproRect.s.y; } if (Image->Bitmap->BitsPerPixel==8) { if (Image->Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->WorkArea->Mask->StartScanLine() == false) goto fail; c = PaletteForm->DIB256Palette->GetBGCOLORREF(8); for (i=0; iBitmap->GetScanLine(window.s.y+i)+window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(i); for (j=0; jBitmap->PutScanLine(window.s.y + i); } MainImageForm->WorkArea->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); hRgn = Image->Bitmap->GetRegion(true); if((imageDC = Image->Bitmap->CreateDC()) == NULL) goto fail; if((wbackDC = window.Back->CreateDC()) == NULL) goto fail; if((wmaskDC = window.Mask->CreateDC()) == NULL) goto fail; if((wbitmapDC = window.Bitmap->CreateDC()) == NULL) goto fail; BitBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, imageDC, ReproRect.s.x, ReproRect.s.y, SRCCOPY); SetStretchBltMode(wbackDC, COLORONCOLOR); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wmaskDC, 0, 0, window.size.x, window.size.y, SRCAND); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wbitmapDC, 0, 0, window.size.x, window.size.y, SRCPAINT); BitBlt(imageDC, ReproRect.s.x, ReproRect.s.y, ReproRect.size.x, ReproRect.size.y, wbackDC, 0, 0, SRCCOPY); window.Bitmap->DeleteDC(wbitmapDC); window.Mask->DeleteDC(wmaskDC); window.Back->DeleteDC(wbackDC); Image->Bitmap->DeleteDC(imageDC); if (hRgn) { Image->Bitmap->PutRegion(hRgn); DeleteObject(hRgn); } } else { if (Image->Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->WorkArea->Mask->StartScanLine() == false) goto fail; c = PaletteForm->DIB256Palette->GetBGCOLORREF(24); for (i=0; iBitmap->GetScanLine(window.s.y+i)+3*window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(i); mm = 0x80; for (j=0; j>= 1; } Image->Bitmap->PutScanLine(window.s.y + i); } MainImageForm->WorkArea->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); hRgn = Image->Bitmap->GetRegion(true); if((imageDC = Image->Bitmap->CreateDC()) == NULL) goto fail; if((wbackDC = window.Back->CreateDC()) == NULL) goto fail; if((wmaskDC = window.Mask->CreateDC()) == NULL) goto fail; window.Bitmap->ResizeStretch(ReproRect.size.x, ReproRect.size.y, true); if((wbitmapDC = window.Bitmap->CreateDC()) == NULL) goto fail; BitBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, imageDC, ReproRect.s.x, ReproRect.s.y, SRCCOPY); SetStretchBltMode(wbackDC, COLORONCOLOR); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wmaskDC, 0, 0, window.size.x, window.size.y, SRCAND); BitBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wbitmapDC, 0, 0, SRCPAINT); BitBlt(imageDC, ReproRect.s.x, ReproRect.s.y, ReproRect.size.x, ReproRect.size.y, wbackDC, 0, 0, SRCCOPY); window.Bitmap->DeleteDC(wbitmapDC); window.Mask->DeleteDC(wmaskDC); window.Back->DeleteDC(wbackDC); Image->Bitmap->DeleteDC(imageDC); if (hRgn) { Image->Bitmap->PutRegion(hRgn); DeleteObject(hRgn); } } r = Rect(ReproRect.s.x, ReproRect.s.y, ReproRect.e.x, ReproRect.e.y); MainImageForm->WorkArea->Transform(r); MainImageForm->WorkAreaChange(); ::RepaintImage(); SetReproImage(); Rpos[0].x = window.s.x; Rpos[0].y = window.s.y; Rpos[1].x = window.e.x; Rpos[1].y = window.s.y; Rpos[2].x = window.e.x; Rpos[2].y = window.e.y; Rpos[3].x = window.s.x; Rpos[3].y = window.e.y; ChangeUnit(MainImageForm->CurrentUnit); Screen->Cursor = OldCursor; return; fail: if (undoSw) { if (wbitmapDC) window.Bitmap->DeleteDC(wbitmapDC); if (wmaskDC) window.Mask->DeleteDC(wmaskDC); if (wbackDC) window.Back->DeleteDC(wbackDC); if (imageDC) Image->Bitmap->DeleteDC(imageDC); if (hRgn) { Image->Bitmap->PutRegion(hRgn); DeleteObject(hRgn); } MainImageForm->WorkArea->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); Undo->RemoveLast(); } Screen->Cursor = OldCursor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::ReproImageMouseDown(int X, int Y) { if (item == TREPRO_RECT) { rect_repro(); } else if (item == TREPRO_PULL) { PullMouseDown(X, Y); } } //--------------------------------------------------------------------------- void __fastcall TReproForm::ReproImageMouseMove(int X, int Y) { SubMouseMove(X, Y); } //--------------------------------------------------------------------------- void __fastcall TReproForm::ReproMouseDown(int X, int Y) { if (item == TREPRO_RECT) { MainImageForm->iMainImage->SubVisible = false; rect_repro(); sbRect->Down = false; item = TREPRO_NULL; MainImageForm->iMainImage->SubVisible = false; MainImageForm->iMainImage->SubEnabled = false; // rect_repro(); } else if (item == TREPRO_PULL) { PullMouseDown(X, Y); } } //--------------------------------------------------------------------------- void __fastcall TReproForm::ReproMouseMove(int X, int Y) { SubMouseMove(X, Y); } //--------------------------------------------------------------------------- void __fastcall TReproForm::iMainImageKeyDown(int Key) { if (item == TREPRO_RECT) { int px, py; switch (Key) { case 13: EditKeyPress(this, Key); //lhskys ¿£ÅÍ۸¦ ¾ç¹æÇâ¿¡¼­ °°ÀÌ break; //lhskys ¹ÞÀ¸¹Ç·Î È£ÃâÀ» ÇÑ´Ù case 37: if (window.e.x == ReproRect.e.x) { px = ReproRect.s.x - 1; } else { px = ReproRect.e.x - 1; } if (ReproRect.s.y < window.s.y) { SubMouseMove(px, ReproRect.s.y); } else { SubMouseMove(px, ReproRect.e.y); } break; // left case 38: if (window.e.y == ReproRect.e.y) { py = ReproRect.s.y - 1; } else { py = ReproRect.e.y - 1; } if (ReproRect.s.x < window.s.x) { SubMouseMove(ReproRect.s.x, py); } else { SubMouseMove(ReproRect.e.x, py); } break; // top case 39: if (window.s.x == ReproRect.s.x) { px = ReproRect.e.x + 1; } else { px = ReproRect.s.x + 1; } if (ReproRect.s.y < window.s.y) { SubMouseMove(px, ReproRect.s.y); } else { SubMouseMove(px, ReproRect.e.y); } break; // right case 40: if (window.s.y == ReproRect.s.y) { py = ReproRect.e.y + 1; } else { py = ReproRect.s.y + 1; } if (ReproRect.s.x < window.s.x) { SubMouseMove(ReproRect.s.x, py); } else { SubMouseMove(ReproRect.e.x, py); } break; // bottom case 17: rect_repro(); break; // Ctrl - Key } } } //--------------------------------------------------------------------------- void __fastcall TReproForm::iMainImageChange(void) { TPSelectImage *ReproImage = MainImageForm->iSelectImage; ReproImage->Width = 0; ReproImage->Height = 0; } //--------------------------------------------------------------------------- void __fastcall TReproForm::SetReproImage(void) { int x, y; Byte *WP, *WBP, *MP, mm, *RP, *PP; COLORREF bgc, c; TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; 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; ReproRect.s = window.s; ReproRect.e = window.e; ReproRect.size = window.size; ReproRect.Bitmap = 0; ReproRect.Mask = 0; ReproRect.Back = 0; ReproImage->Left = window.s.x; ReproImage->Top = window.s.y; ReproImage->Width = 0; ReproImage->Height = 0; if (Image->Bitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (ReproImage->Bitmap->Create(window.size.x, window.size.y, 8, rgb) == false) goto fail; ReproImage->SetPosition(0, 0); if (window.Bitmap->Create(window.size.x, window.size.y, 8, rgb) == false) goto fail; if (window.Mask->Create(window.size.x, window.size.y, 8, rgb) == false) goto fail; if (window.Back->Create(window.size.x, window.size.y, 8, rgb) == false) goto fail; if (ReproImage->Bitmap->StartScanLine() == false) goto fail; if (window.Bitmap->StartScanLine() == false) goto fail; if (window.Mask->StartScanLine() == false) goto fail; if (Image->Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->WorkArea->Mask->StartScanLine() == false) goto fail; for (y=0; yBitmap->GetScanLine(y); WBP = window.Bitmap->GetScanLine(y); MP = window.Mask->GetScanLine(y); PP = Image->Bitmap->GetScanLine(window.s.y+y)+window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xBitmap->PutScanLine(y); window.Bitmap->PutScanLine(y); window.Mask->PutScanLine(y); } ReproImage->Bitmap->StopScanLine(); window.Bitmap->StopScanLine(); window.Mask->StopScanLine(); Image->Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } else { if (ReproImage->Bitmap->Create(window.size.x, window.size.y, 24) == false) goto fail; ReproImage->SetPosition(0, 0); if (window.Bitmap->Create(window.size.x, window.size.y, 24) == false) goto fail; if (window.Mask->Create(window.size.x, window.size.y, 1) == false) goto fail; if (window.Back->Create(window.size.x, window.size.y, 24) == false) goto fail; if (ReproImage->Bitmap->StartScanLine() == false) goto fail; if (window.Bitmap->StartScanLine() == false) goto fail; if (window.Mask->StartScanLine() == false) goto fail; if (Image->Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->WorkArea->Mask->StartScanLine() == false) goto fail; for (y=0; yBitmap->GetScanLine(y); WBP = window.Bitmap->GetScanLine(y); MP = window.Mask->GetScanLine(y); *MP = 0; PP = Image->Bitmap->GetScanLine(window.s.y+y)+3*window.s.x; WP = MainImageForm->WorkArea->Mask->GetScanLine(y); mm = 0x80; for (x=0; x>= 1; } ReproImage->Bitmap->PutScanLine(y); window.Bitmap->PutScanLine(y); window.Mask->PutScanLine(y); } ReproImage->Bitmap->StopScanLine(); window.Bitmap->StopScanLine(); window.Mask->StopScanLine(); Image->Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } return; fail : MainImageForm->WorkArea->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); window.Mask->StopScanLine(); window.Bitmap->StopScanLine(); ReproImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::ChangeUnit(TUnit CUnit) { if (btnSize->Caption == IDS_COMMON_LENGTH) { lUnit->Caption = MainImageForm->UnitName(CUnit); switch (CUnit) { case uDot : eXsize->Text = ReproRect.size.x; eYsize->Text = ReproRect.size.y; lXsize->Caption = window.size.x; lYsize->Caption = window.size.y; break; case uInch : eXsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.x / MainImageForm->CanvasInfor.DotsPerInch))); eYsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.y / MainImageForm->CanvasInfor.DotsPerInch))); lXsize->Caption = Format("%.2f", OPENARRAY(TVarRec, ((double)window.size.x / MainImageForm->CanvasInfor.DotsPerInch))); lYsize->Caption = Format("%.2f", OPENARRAY(TVarRec, ((double)window.size.y / MainImageForm->CanvasInfor.DotsPerInch))); break; case uCm : eXsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.x / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); eYsize->Text = Format("%.2f", OPENARRAY(TVarRec, ((double)ReproRect.size.y / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); lXsize->Caption = Format("%.2f", OPENARRAY(TVarRec, ((double)window.size.x / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); lYsize->Caption = Format("%.2f", OPENARRAY(TVarRec, ((double)window.size.y / MainImageForm->CanvasInfor.DotsPerInch * 2.54))); break; } } else if (btnSize->Caption == IDS_RATIO) { eXsize->Text = Format("%.2f", OPENARRAY(TVarRec, (100.0 * ReproRect.size.x / window.size.x))); eYsize->Text = Format("%.2f", OPENARRAY(TVarRec, (100.0 * ReproRect.size.y / window.size.y))); lUnit->Caption = " %"; lXsize->Caption = 100; lYsize->Caption = 100; } } //--------------------------------------------------------------------------- void __fastcall TReproForm::PreviewRun(TObject *Sender) //by lhskys 2002.07.16 { // ½ÇÇàÇϱâÀü¿¡ ¹Ì¸®º¸±â COLORREF C; norun = 0; //lhskys ½ÇÇàÀ» ÇÏÁö ¾ÊÀ»¶§¸¦ Ç¥½ÃÇϱâÀ§ÇØ bool crtSw = false; TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; 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; if (btnSize->Caption == IDS_COMMON_LENGTH) { if (eXsize->Text != "") { switch (MainImageForm->CurrentUnit) { case uDot : ReproRect.size.x = StrToInt(eXsize->Text); break; case uInch : ReproRect.size.x = StrToFloat(eXsize->Text) * MainImageForm->CanvasInfor.DotsPerInch; break; case uCm : ReproRect.size.x = StrToFloat(eXsize->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54; } } if (eYsize->Text != "") { switch (MainImageForm->CurrentUnit) { case uDot : ReproRect.size.y = StrToInt(eYsize->Text); break; case uInch : ReproRect.size.y = StrToFloat(eYsize->Text) * MainImageForm->CanvasInfor.DotsPerInch; break; case uCm : ReproRect.size.y = StrToFloat(eYsize->Text) * MainImageForm->CanvasInfor.DotsPerInch / 2.54; } } } else if (btnSize->Caption == IDS_RATIO) { if (eXsize->Text != "") { ReproRect.size.x = window.size.x * StrToFloat(eXsize->Text) / 100.0; } if (eYsize->Text != "") { ReproRect.size.y = window.size.y * StrToFloat(eYsize->Text) / 100.0; } } ReproImage->Enabled = true; ReproImage->Visible = false; if (Image->Bitmap->BitsPerPixel==8) { Repro.size.x = max(ReproRect.size.x,window.size.x); Repro.size.y = max(ReproRect.size.y,window.size.y); if ((crtSw = window.Back->Create(Repro.size.x, Repro.size.y, 8, rgb)) == false) goto fail; if (ReproImage->Bitmap->Create(ReproRect.size.x, ReproRect.size.y, 8, rgb) == false) goto fail; HDC hDC = ReproImage->Bitmap->CreateDC(); BitBlt(hDC,0,0,window.size.x, window.size.y,NULL,0,0,WHITENESS); ReproImage->Bitmap->DeleteDC(hDC); C = PaletteForm->DIB256Palette->GetBGCOLORREF(8); ReproImage->Bitmap->FillRect(Rect(0,0,ReproImage->Bitmap->Width,ReproImage->Bitmap->Height), C); } else { Repro.size.x = max(ReproRect.size.x,window.size.x); Repro.size.y = max(ReproRect.size.y,window.size.y); if ((crtSw = window.Back->Create(Repro.size.x, Repro.size.y, 24)) == false) goto fail; if (ReproImage->Bitmap->Create(ReproRect.size.x, ReproRect.size.y, 24) == false) goto fail; HDC hDC = ReproImage->Bitmap->CreateDC(); BitBlt(hDC,0,0,window.size.x, window.size.y,NULL,0,0,WHITENESS); ReproImage->Bitmap->DeleteDC(hDC); C = PaletteForm->DIB256Palette->GetBGCOLORREF(24); ReproImage->Bitmap->FillRect(Rect(0,0,ReproImage->Bitmap->Width,ReproImage->Bitmap->Height), C); } ReproImage->SetPosition(0, 0); ReproImage->Visible = false; Preview(); return; fail : if (crtSw) window.Back->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TReproForm::Preview(void) //by lhskys 2002.07.16 { // ½ÇÇàÇϱâÀü¿¡ ¹Ì¸®º¸±â HDC imageDC = NULL, reproDC = NULL, wbitmapDC = NULL, wmaskDC = NULL, wbackDC = NULL, maskDC = NULL; bool crtSw = false, crtSw1 = false; TPItemImage *Image = MainImageForm->iMainImage; TPSelectImage *ReproImage = MainImageForm->iSelectImage; ReproRect.e.x = ReproRect.s.x + ReproRect.size.x; ReproRect.e.y = ReproRect.s.y + ReproRect.size.y; if (ReproRect.e.x > Image->Bitmap->Width) { ReproRect.e.x = Image->Bitmap->Width; ReproRect.size.x = ReproRect.e.x - ReproRect.s.x; } if (ReproRect.e.y > Image->Bitmap->Height) { ReproRect.e.y = Image->Bitmap->Height; ReproRect.size.y = ReproRect.e.y - ReproRect.s.y; } ReproImage->Left = Image->BitmapToCanvasX(ReproRect.s.x); ReproImage->Top = Image->BitmapToCanvasY(ReproRect.s.y); ReproImage->Width = ReproRect.size.x * ReproImage->ZoomIn / ReproImage->ZoomOut; ReproImage->Height = ReproRect.size.y * ReproImage->ZoomIn / ReproImage->ZoomOut; if (ReproRect.size.x == 0 || ReproRect.size.y == 0) return; if ((imageDC = Image->Bitmap->CreateDC()) == NULL) goto fail; if ((wbackDC = window.Back->CreateDC()) == NULL) goto fail; if ((wmaskDC = window.Mask->CreateDC()) == NULL) goto fail; if ((wbitmapDC = window.Bitmap->CreateDC()) == NULL) goto fail; if ((reproDC = ReproImage->Bitmap->CreateDC()) == NULL) goto fail; BitBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, imageDC, ReproRect.s.x, ReproRect.s.y, SRCCOPY); SetStretchBltMode(wbackDC, COLORONCOLOR); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wmaskDC, 0, 0, window.size.x, window.size.y, SRCAND); StretchBlt(wbackDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wbitmapDC, 0, 0, window.size.x, window.size.y, SRCPAINT); BitBlt(reproDC, 0, 0, ReproRect.size.x, ReproRect.size.y, wbackDC, 0, 0, SRCCOPY); ReproImage->Bitmap->DeleteDC(reproDC); window.Bitmap->DeleteDC(wbitmapDC); window.Mask->DeleteDC(wmaskDC); window.Back->DeleteDC(wbackDC); Image->Bitmap->DeleteDC(imageDC); ReproImage->SetPosition(0, 0); return; fail: if (reproDC) ReproImage->Bitmap->DeleteDC(reproDC); if (wbitmapDC) window.Bitmap->DeleteDC(wbitmapDC); if (wmaskDC) window.Mask->DeleteDC(wmaskDC); if (wbackDC) window.Back->DeleteDC(wbackDC); if (imageDC) Image->Bitmap->DeleteDC(imageDC); if (crtSw1) ReproImage->Bitmap->Destroy(); if (crtSw) window.Back->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------- void __fastcall TReproForm::EditKeyPress(TObject *Sender, char &Key) { if(Key == 13 && sbPull->Down)btnPullClick(this); //lhskys ¿£ÅÍ·Î ½ÇÇàÇϱâ else if (Key == 13) { if (sbRect->Down == false || norun == 1){ //lhskys ¿£Å͸¦ ¹Þ¾ÒÀ»¶§ PullEdit(Sender); //lhskys edit·Î °¥°ÍÀΰ¡ ÆÇ´Ü SelectNext((TWinControl *)Sender, true, true); //lhskys Key = 0; //lhskys }else if(norun == 0){ //lhskys ¹Ù·Î ½ÇÇàŰ·Î.... if(sbRect->Down){ //lhskys btnRectRunClick(this); //lhskys } } } } //---------------------------------------------------------------------------