//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Scratch_F.h" #include "MainImage.h" #include "Undo.h" #include "StatusProgress.h" #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzButton" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_DENSITY StringTable[0] //--------------------------------------------------------------------------- TScratchForm *ScratchForm; //--------------------------------------------------------------------------- __fastcall TScratchForm::TScratchForm(TComponent* Owner) : TForm(Owner) { //=========================================== StringTable.Create(DirectoryItem, Language, "Scratch"); SetSmallFont(Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label3->Font); SetSmallFont(Label4->Font); Label1->Caption = IDS_COMMON_ANGLE; Label2->Caption = IDS_DENSITY; Label3->Caption = IDS_COMMON_LENGTH; Label4->Caption = IDS_COMMON_WIDTH; sbWarp->Caption = IDS_COMMON_RUN; //=========================================== } //--------------------------------------------------------------------------- void __fastcall TScratchForm::FormCreate(TObject *Sender) { Temp = NULL; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::RxEditClick(TObject *Sender) { TRzSpinEdit *rx = (TRzSpinEdit *) Sender; rx->SelectAll(); rx->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TScratchForm::RxAngleChange(TObject *Sender) { if (RxAngle->Text.Length() > 0) { if(RxAngle->Value < 0) { RxAngle->Value = 0; } else if(RxAngle->Value > 179) { RxAngle->Value = 179; } } } //--------------------------------------------------------------------------- void __fastcall TScratchForm::RxDensityChange(TObject *Sender) { if (RxDensity->Text.Length() > 0) { if(RxDensity->Value < 1) { RxDensity->Value = 1; } else if(RxDensity->Value >5) { RxDensity->Value = 5; } } } //--------------------------------------------------------------------------- void __fastcall TScratchForm::RxLengthChange(TObject *Sender) { if (RxLength->Text.Length() > 0) { if(RxLength->Value < 1){ RxLength->Value = 1; } else if(RxLength->Value > 50) { RxLength->Value = 50; } } } //--------------------------------------------------------------------------- void __fastcall TScratchForm::RxWidthChange(TObject *Sender) { if (RxWidth->Text.Length() > 0) { if(RxWidth->Value < 1) { RxWidth->Value = 1; } else if(RxWidth->Value > 30) { RxWidth->Value = 30; } } } //--------------------------------------------------------------------------- void __fastcall TScratchForm::InitMemory8(RECT work) { BEGIN_LOG(""); int x, y; Byte *pp, *tp; for(y=work.top; yGetScanLine(y)+work.left; tp = Temp->ScanLine(y - work.top); memcpy(tp, pp, work.right-work.left); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::InitMemory24(RECT work) { BEGIN_LOG(""); int x, y; Byte *tp, *pp; COLORREF tcl; for(y=work.top; yGetScanLine(y)+3*work.left; tp = Temp->ScanLine(y - work.top); memcpy(tp, pp, (work.right-work.left)*3); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::warp_none() { BEGIN_LOG(""); TCursor cursor; int x, y, den, len, vx, vy, zx, zy, dotcount, l1, l2, count; Byte *pp, *tp, *lock = NULL; long double theta, sx1, sy1, ex1, ey1; TTransfer *Trans = NULL; // TUnionBitmap *LMbmp; RECT work; COLORREF c; bool execute, undoSw = false; TPException ec = EC_NONE; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; tb = MainImageForm->iMainImage->uBitmap; // LMbmp = MainImageForm->iMainImage->LayerMask; theta = RxAngle->Value * M_PI / 180; den = RxDensity->Value; len = RxLength->Value; dotcount = RxWidth->Value; if (MainImageForm->WorkArea->Mask) { work = MainImageForm->WorkArea->Range; if ((undoSw = MainImageForm->UndoSave(UK_ALL, work)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!tb->StartScanLineN(2)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } l1 = random(len); l2 = random(len); count = 0; execute = true; switch ((int)RxAngle->Value) { case 0: StatusProgress->Maximum = work.right-work.left; if (tb->BitsPerPixel==8) { // Horizontal, Mask 8Bit if ((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Temp->Create(work.right-work.left, work.bottom-work.top, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (x=work.left; xPosition = x - work.left; count = 0; for (y=work.top; yGetScanLine(y)+x; if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } delete Temp; Temp = NULL; } else { // Horizontal, Mask 24Bit if((Temp = new TPBitmap)== NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (x=work.left; xPosition = x - work.left; count = 0; for(y=work.top; yGetScanLine(y) + 3*x; if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } delete Temp; Temp = NULL; } StatusProgress->End(); break; case 90: StatusProgress->Maximum = work.bottom - work.top; if (tb->BitsPerPixel==8) { // Vertical, Mask 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (y=work.top; yPosition = y-work.top; pp = tb->GetScanLine(y)+work.left; count = 0; for (x=work.left; xLoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } delete Temp; Temp = NULL; } else { // Vertical, Mask 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (y=work.top; yPosition = y - work.top; pp = tb->GetScanLine(y)+3*work.left; count = 0; for (x=work.left; xLoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } delete Temp; Temp = NULL; } StatusProgress->End(); break; default: if((Trans = new TTransfer)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Trans->rotation(theta); if (tb->BitsPerPixel==8) { // 45 <= theta <= 135, Mask 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = work.bottom - work.top; for (y=work.top; yPosition = y - work.top; pp = tb->GetScanLine(y)+work.left; count = 0; for (x=work.left; xconvert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLineMask8(vx, vy, zx, zy, work, *pp); } } } StatusProgress->End(); } else { // theta < 45 OR theta > 135, Mask 8Bit StatusProgress->Maximum = work.right - work.left; for (x=work.left; xPosition = x-work.left; count = 0; for (y=work.top; yGetScanLine(y)+x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLineMask8(vx, vy, zx, zy, work, *pp); } } } StatusProgress->End(); } if((tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } delete Temp; Temp = NULL; } else { // 45 <= theta <= 135, Mask 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = work.bottom - work.top; for (y=work.top; yPosition = y - work.top; pp = tb->GetScanLine(y)+3*work.left; count = 0; for (x=work.left; xconvert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLineMask24(vx, vy, zx, zy, work, c); } } } StatusProgress->End(); } else { // theta < 45 OR theta> 135, Mask, 24Bit StatusProgress->Maximum = work.right - work.left; for (x=work.left; xPosition = x-work.left; count = 0; for (y=work.top; yGetScanLine(y)+3*x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLineMask24(vx, vy, zx, zy, work, c); } } } StatusProgress->End(); } if((tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } delete Temp; Temp = NULL; } delete Trans; Trans = NULL; break; } MainImageForm->WorkArea->Mask->StopScanLine(); tb->StopScanLine(); } else { work = Rect(0, 0, tb->Width, tb->Height); if ((undoSw = MainImageForm->UndoSave(UK_ALL, work)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!tb->StartScanLineN(2)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } l1 = random(len); l2 = random(len); count = 0; execute = true; switch ((int)RxAngle->Value) { case 0: StatusProgress->Maximum = tb->Width; if (tb->BitsPerPixel==8) { // Horizontal, 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+x; DrawHLine8(x-l1, x+l2, y, *pp); } } } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); delete Temp; Temp = NULL; } else { // Horizontal, 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+3*x; GetPixel24(pp, c); DrawHLine24(x-l1, x+l2, y, c); } } } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); delete Temp; Temp = NULL; } StatusProgress->End(); break; case 90: StatusProgress->Maximum = tb->Height; if (tb->BitsPerPixel==8) { // Vertical, 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp++) { if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); delete Temp; Temp = NULL; } else { // Vertical, 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp+=3) { if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); delete Temp; Temp = NULL; } StatusProgress->End(); break; default: if ((Trans = new TTransfer)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Trans->rotation(theta); if (tb->BitsPerPixel==8) { // 45 <= theta <= 135, 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = tb->Height; for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp++) { if(count == dotcount) { count = 0; if(random(10)convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLine8(vx, vy, zx, zy, *pp); } } } StatusProgress->End(); } else { // theta < 45 OR theta > 135, 8Bit StatusProgress->Maximum = tb->Width; for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLine8(vx, vy, zx, zy, *pp); } } } StatusProgress->End(); } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); delete Temp; Temp = NULL; } else { // 45 <= theta <= 135, 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = tb->Height; for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp+=3) { if(count == dotcount) { count = 0; if(random(10)convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLine24(vx, vy, zx, zy, c); } } } StatusProgress->End(); } else { // theta < 45 OR theta > 135, 24Bit StatusProgress->Maximum = tb->Width; for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+3*x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLine24(vx, vy, zx, zy, c); } } } StatusProgress->End(); } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); delete Temp; Temp = NULL; } delete Trans; Trans = NULL; break; } tb->StopScanLine(); } MainImageForm->iMainImage->Repaint(); Screen->Cursor = cursor; END_LOG; return; fail: if (MainImageForm->WorkArea->Mask) MainImageForm->WorkArea->Mask->StopScanLine(); tb->StopScanLine(); Screen->Cursor = cursor; if (Trans) delete Trans; if (Temp) { if (lock) Temp->Unlock(); delete Temp; Temp = NULL; } if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::warp_layer() { BEGIN_LOG(""); TCursor cursor; int x, y, den, len, vx, vy, zx, zy, dotcount, l1, l2, count; Byte *pp, *tp, *lock = NULL; long double theta, sx1, sy1, ex1, ey1; TTransfer *Trans = NULL; TUnionBitmap *LMbmp; RECT work; COLORREF c; bool execute, undoSw = false; TPException ec = EC_NONE; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; tb = MainImageForm->iMainImage->uBitmap; LMbmp = MainImageForm->iMainImage->LayerMask; theta = RxAngle->Value * M_PI / 180; den = RxDensity->Value; len = RxLength->Value; dotcount = RxWidth->Value; if (MainImageForm->WorkArea->Mask) { work = MainImageForm->WorkArea->Range; if ((undoSw = MainImageForm->UndoSave(UK_ALL, work)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!tb->StartScanLineN(2)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } l1 = random(len); l2 = random(len); count = 0; execute = true; switch ((int)RxAngle->Value) { case 0: StatusProgress->Maximum = work.right-work.left; if (tb->BitsPerPixel==8) { // Horizontal, Mask 8Bit if ((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Temp->Create(work.right-work.left, work.bottom-work.top, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (x=work.left; xPosition = x - work.left; count = 0; for (y=work.top; yGetScanLine(y)+x; if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } else { // Horizontal, Mask 24Bit if((Temp = new TPBitmap)== NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (x=work.left; xPosition = x - work.left; count = 0; for(y=work.top; yGetScanLine(y) + 3*x; if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } StatusProgress->End(); break; case 90: StatusProgress->Maximum = work.bottom - work.top; if (tb->BitsPerPixel==8) { // Vertical, Mask 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (y=work.top; yPosition = y-work.top; pp = tb->GetScanLine(y)+work.left; count = 0; for (x=work.left; xLoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } else { // Vertical, Mask 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (y=work.top; yPosition = y - work.top; pp = tb->GetScanLine(y)+3*work.left; count = 0; for (x=work.left; xLoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } StatusProgress->End(); break; default: if((Trans = new TTransfer)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Trans->rotation(theta); if (tb->BitsPerPixel==8) { // 45 <= theta <= 135, Mask 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = work.bottom - work.top; for (y=work.top; yPosition = y - work.top; pp = tb->GetScanLine(y)+work.left; count = 0; for (x=work.left; xconvert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLineMask8(vx, vy, zx, zy, work, *pp); } } } StatusProgress->End(); } else { // theta < 45 OR theta > 135, Mask 8Bit StatusProgress->Maximum = work.right - work.left; for (x=work.left; xPosition = x-work.left; count = 0; for (y=work.top; yGetScanLine(y)+x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLineMask8(vx, vy, zx, zy, work, *pp); } } } StatusProgress->End(); } if((tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } else { // 45 <= theta <= 135, Mask 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(work.right-work.left, work.bottom-work.top, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = work.bottom - work.top; for (y=work.top; yPosition = y - work.top; pp = tb->GetScanLine(y)+3*work.left; count = 0; for (x=work.left; xconvert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLineMask24(vx, vy, zx, zy, work, c); } } } StatusProgress->End(); } else { // theta < 45 OR theta> 135, Mask, 24Bit StatusProgress->Maximum = work.right - work.left; for (x=work.left; xPosition = x-work.left; count = 0; for (y=work.top; yGetScanLine(y)+3*x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLineMask24(vx, vy, zx, zy, work, c); } } } StatusProgress->End(); } if((tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine, work))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } delete Trans; Trans = NULL; break; } MainImageForm->WorkArea->Mask->StopScanLine(); tb->StopScanLine(); } else { work = Rect(0, 0, tb->Width, tb->Height); if ((undoSw = MainImageForm->UndoSave(UK_ALL, work)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!tb->StartScanLineN(2)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } l1 = random(len); l2 = random(len); count = 0; execute = true; switch ((int)RxAngle->Value) { case 0: StatusProgress->Maximum = tb->Width; if (tb->BitsPerPixel==8) { // Horizontal, 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+x; DrawHLine8(x-l1, x+l2, y, *pp); } } } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } else { // Horizontal, 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+3*x; GetPixel24(pp, c); DrawHLine24(x-l1, x+l2, y, c); } } } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } StatusProgress->End(); break; case 90: StatusProgress->Maximum = tb->Height; if (tb->BitsPerPixel==8) { // Vertical, 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp++) { if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } else { // Vertical, 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp+=3) { if(count == dotcount) { count = 0; if(random(10)LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } StatusProgress->End(); break; default: if ((Trans = new TTransfer)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Trans->rotation(theta); if (tb->BitsPerPixel==8) { // 45 <= theta <= 135, 8Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 8)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory8(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = tb->Height; for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp++) { if(count == dotcount) { count = 0; if(random(10)convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLine8(vx, vy, zx, zy, *pp); } } } StatusProgress->End(); } else { // theta < 45 OR theta > 135, 8Bit StatusProgress->Maximum = tb->Width; for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); DrawLine8(vx, vy, zx, zy, *pp); } } } StatusProgress->End(); } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } else { // 45 <= theta <= 135, 24Bit if((Temp = new TPBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if(!Temp->Create(tb->Width, tb->Height, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((lock = Temp->Lock()) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } InitMemory24(work); if(RxAngle->Value>=45 && RxAngle->Value<=135) { StatusProgress->Maximum = tb->Height; for (y=0; yHeight; y += (l2+1)) { StatusProgress->Position = y; pp = tb->GetScanLine(y); count = 0; for (x=0; xWidth; x++, pp+=3) { if(count == dotcount) { count = 0; if(random(10)convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLine24(vx, vy, zx, zy, c); } } } StatusProgress->End(); } else { // theta < 45 OR theta > 135, 24Bit StatusProgress->Maximum = tb->Width; for (x=0; xWidth; x += (l2+1)) { StatusProgress->Position = x; count = 0; for (y=0; yHeight; y++) { if(count == dotcount) { count = 0; if(random(10)GetScanLine(y)+3*x; Trans->convert2(-l1, 0, sx1, sy1); Trans->convert2(l2, 0, ex1, ey1); vx = (int)(x+sx1); vy = (int)(y+sy1); zx = (int)(x+ex1); zy = (int)(y+ey1); GetPixel24(pp, c); DrawLine24(vx, vy, zx, zy, c); } } } StatusProgress->End(); } tb->LoadFromMemory(Temp->ScanLine(), Temp->BytesPerLine); LMbmp->FillRect(work, 0); delete Temp; Temp = NULL; } delete Trans; Trans = NULL; break; } tb->StopScanLine(); } MainImageForm->iMainImage->Repaint(); Screen->Cursor = cursor; END_LOG; return; fail: if (MainImageForm->WorkArea->Mask) MainImageForm->WorkArea->Mask->StopScanLine(); tb->StopScanLine(); Screen->Cursor = cursor; if (Trans) delete Trans; if (Temp) { if (lock) Temp->Unlock(); delete Temp; Temp = NULL; } if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void TScratchForm::DrawPointMask8(int x, int y, RECT work, COLORREF c) { Byte *dp, *mp; if (y>=work.top && y=work.left && xWorkArea->Mask->GetScanLine(y-work.top)+x-work.left; if (*mp) { dp = Temp->ScanLine(y - work.top)+x-work.left ; *dp = c; } } } } //--------------------------------------------------------------------------- void TScratchForm::DrawPointMask24(int x, int y, RECT work, COLORREF c) { Byte *dp, *mp, mm; if (y>=work.top && y=work.left && xWorkArea->Mask->GetScanLine(y-work.top)+((x-work.left)>>3); mm = 0x80>>((x-work.left)&7); if (*mp&mm) { dp = Temp->ScanLine(y-work.top)+3*(x-work.left); *dp = (c >> 16); // b *(dp+1) = (c >> 8) & 0xFF; // g *(dp+2) = c & 0xFF; // r } } } } //--------------------------------------------------------------------------- void TScratchForm::DrawHLineMask8(int sx, int ex, int y, RECT work, COLORREF c) { int k; Byte *dp, *mp; mp = MainImageForm->WorkArea->Mask->GetScanLine(y-work.top)+sx-work.left; for (k=sx; k<=ex; k++, mp++) { if (k>=work.left && kScanLine(y - work.top)+k-work.left; *dp = c; } } } } //--------------------------------------------------------------------------- void TScratchForm::DrawHLineMask24(int sx, int ex, int y, RECT work, COLORREF c) { int k; Byte *dp, *mp, mm; mp = MainImageForm->WorkArea->Mask->GetScanLine(y-work.top)+((sx-work.left)>>3); mm = 0x80>>((sx-work.left)&7); for (k=sx; k<=ex; k++) { if (k>=work.left && kScanLine(y - work.top)+3*(k-work.left); *dp = (c >> 16); // b *(dp+1) = (c >> 8) & 0xFF; // g *(dp+2) = c & 0xFF; // r } } if (mm==1) { mp++; mm = 0x80; } else mm >>= 1; } } //--------------------------------------------------------------------------- void TScratchForm::DrawVLineMask8(int x, int sy, int ey, RECT work, COLORREF c) { int k; Byte *dp, *mp; for (k=sy; k<=ey; k++) { if (k>=work.top && kWorkArea->Mask->GetScanLine(k-work.top)+x-work.left; if (*mp) { dp = Temp->ScanLine(k - work.top)+x-work.left; *dp = c; } } } } //--------------------------------------------------------------------------- void TScratchForm::DrawVLineMask24(int x, int sy, int ey, RECT work, COLORREF c) { int k; Byte *dp, *mp, mm; mm = 0x80>>((x-work.left)&7); for (k=sy; k<=ey; k++) { if (k>=work.top && kWorkArea->Mask->GetScanLine(k-work.top)+((x-work.left)>>3); if (*mp&mm) { dp = Temp->ScanLine(k - work.top)+3*(x-work.left); *dp = (c >> 16); // b *(dp+1) = (c >> 8) & 0xFF; // g *(dp+2) = c & 0xFF; // r } } } } //--------------------------------------------------------------------------- void TScratchForm::DrawLineMask8(int sx, int sy, int ex, int ey, RECT work, COLORREF c) { int x, y, sp, ep; double s; if (sx==ex) { if (sy1.0) { if (sy1.0) { if (sy=0 && yHeight) { if (x>=0 && xWidth) { dp = Temp->ScanLine(y)+x; *dp = c; } } } //--------------------------------------------------------------------------- void TScratchForm::DrawPoint24(int x, int y, COLORREF c) { Byte *dp; if (y>=0 && yHeight) { if (x>=0 && xWidth) { dp = Temp->ScanLine( y)+3*x; *dp = (c >> 16); // b *(dp+1) = (c >> 8) & 0xFF; // g *(dp+2) = c & 0xFF; // r } } } //--------------------------------------------------------------------------- void TScratchForm::DrawHLine8(int sx, int ex, int y, COLORREF c) { int k; Byte *dp; int startx = sx; int endx = ex; if (startx < 0) startx = 0; if (endx > tb->Width) endx = tb->Width; for (k = startx; k < endx; k++) { dp = Temp->ScanLine(y)+k; *dp = c; } } //--------------------------------------------------------------------------- void TScratchForm::DrawHLine24(int sx, int ex, int y, COLORREF c) { int k; Byte *dp; int startx = sx; int endx = ex; if (startx < 0) startx = 0; if (endx > tb->Width) endx = tb->Width; for (k = startx; k < endx; k++) { dp = Temp->ScanLine(y)+3*k; *dp = (c >> 16); // b *(dp+1) = (c >> 8) & 0xFF; // g *(dp+2) = c & 0xFF; // r } } //--------------------------------------------------------------------------- void TScratchForm::DrawVLine8(int x, int sy, int ey, COLORREF c) { int k; Byte *dp; int starty = sy; int endy = ey; if (starty < 0) starty = 0; if (endy > tb->Height) endy = tb->Height; for (k = starty; k < endy; k++) { dp = Temp->ScanLine(k)+x; *dp = c; } } //--------------------------------------------------------------------------- void TScratchForm::DrawVLine24(int x, int sy, int ey, COLORREF c) { int k; Byte *dp; int starty = sy; int endy = ey; if (starty < 0) starty = 0; if (endy > tb->Height) endy = tb->Height; for (k = starty; k < endy; k++) { dp = Temp->ScanLine(k)+3*x; *dp = (c >> 16); // b *(dp+1) = (c >> 8) & 0xFF; // g *(dp+2) = c & 0xFF; // r } } //--------------------------------------------------------------------------- void TScratchForm::DrawLine8(int sx, int sy, int ex, int ey, COLORREF c) { int x, y, sp, ep; double s; if (sx==ex) { if (sy1.0) { if (sy1.0) { if (syHeight+20; //ClientHeight = 157; //Parent->Height = ParentHeight+ClientHeight; IniFile = new TIniFile(AppDataItem+"\\Scratch.ini"); if (IniFile) { RxAngle->Value = IniFile->ReadInteger("Value", "Angle", 0); RxDensity->Value = IniFile->ReadInteger("Value", "Density", 3); RxLength->Value = IniFile->ReadInteger("Value", "Length", 3); RxWidth->Value = IniFile->ReadInteger("Value", "Width", 3); delete IniFile; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::ExitForm() { BEGIN_LOG(""); TIniFile *IniFile; IniFile = new TIniFile(AppDataItem+"\\Scratch.ini"); if (IniFile) { IniFile->WriteInteger("Value", "Angle", RxAngle->Value); IniFile->WriteInteger("Value", "Density", RxDensity->Value); IniFile->WriteInteger("Value", "Length", RxLength->Value); IniFile->WriteInteger("Value", "Width", RxWidth->Value); delete IniFile; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::sbWarpClick(TObject *Sender) { BEGIN_LOG(""); if (MainImageForm->iMainImage->LayerMask) warp_layer(); else warp_none(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TScratchForm::iMainImageKeyDown(WORD Key, TShiftState Shift) //lhskys ±Ü±â¿¡¼­ { // ¿£ÅÍ·Î ½ÇÇàÇϱâ if (Key == VK_RETURN) if (sbWarp->Enabled == true)sbWarpClick(this); } //--------------------------------------------------------------------------- void __fastcall TScratchForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); HWND hWnd = ((TWinControl *)Owner)->Handle; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //---------------------------------------------------------------------------