//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Separate_F.h" #include "CommonPrint.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_RESTORE StringTable[0] #define IDS_OVERLAP StringTable[1] //--------------------------------------------------------------------------- TSeparateForm *SeparateForm; //--------------------------------------------------------------------------- __fastcall TSeparateForm::TSeparateForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //========================================= StringTable.Create(DirectoryItem, Language, "Separate"); SetSmallFont(Font); SetSmallFont(Label1->Font); sbRestore->Caption = IDS_RESTORE; sbPrint->Caption = IDS_COMMON_PRINT; sbRun->Caption = IDS_COMMON_RUN; sbExit->Caption = IDS_COMMON_EXIT; Label1->Caption = IDS_OVERLAP; sbNew->Hint = IDS_COMMON_NEW; sbAll->Hint = IDS_COMMON_ALL; sbBlock->Hint = IDS_COMMON_BLOCKCOLOR; sbDelete->Hint = IDS_COMMON_INSERTCOLOR; sbBefore->Hint = IDS_COMMON_BEFORECOLOR; //========================================== } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbRestoreClick(TObject *Sender) { if(step>0)MainImageForm->ResetDraw(true); MainImageForm->Undo->UndoRead(); //may be a bug , C ::RepaintColor(); sbRun->Enabled = true; sbRestore->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbPrintClick(TObject *Sender) { TCommonPrintForm *Form = NULL; TCursor oldcursor; int DPI, x, y; TTexpiaBitmap *Bitmap = NULL; TUnionBitmap *tb; // convert by celberus Byte *sp, *dp, * mp; RGBQUAD rgb[256]; RECT Src; if(step>0)MainImageForm->ResetDraw(true); if ((Form = new TCommonPrintForm((TComponent *)NULL))==NULL) goto fail; if (Form->ShowModal() == mrOk) { oldcursor = Screen->Cursor; Screen->Cursor = crHourGlass; tb = MainImageForm->iMainImage->uBitmap; DPI = MainImageForm->CanvasInfor.DotsPerInch; tb->GetColors(0, 256, rgb); if ((Bitmap = new TTexpiaBitmap)==NULL) goto fail; if (MainImageForm->WorkArea->Mask) Src = MainImageForm->WorkArea->Range; else Src = Rect(0, 0, tb->Width, tb->Height); if (!Bitmap->Create(Src.right-Src.left, Src.bottom-Src.top, 8, rgb)) goto fail; if (!tb->StartScanLine()) goto fail; if (!Bitmap->StartScanLine()) goto fail; if (MainImageForm->WorkArea->Mask) { if (!MainImageForm->WorkArea->Mask->StartScanLine()) goto fail; for (y=0; yHeight; y++) { sp = tb->GetScanLine(Src.top+y); dp = Bitmap->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xWidth; x++, dp++) { *dp = sp[Src.left+x]==BackgroundIndex || mp[x]==0 ? 255 : 0; } Bitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); } else { for (y=0; yHeight; y++) { sp = tb->GetScanLine(Src.top+y); dp = Bitmap->GetScanLine(y); for (x=0; xWidth; x++, dp++) { *dp = sp[Src.left+x]==BackgroundIndex ? 255 : 0; } Bitmap->PutScanLine(y); } } tb->StopScanLine(); Bitmap->StopScanLine(); if (!SendToPrinterTP(Bitmap, DPI, "Separate - "+MainImageForm->FileName, Form->PageEdit->Value, Form->cbMethod->ItemIndex)) goto fail; // convert by celberus delete Bitmap; Bitmap = NULL; Screen->Cursor = oldcursor; } delete Form; return; fail: if (Bitmap) { if (MainImageForm->WorkArea->Mask) MainImageForm->WorkArea->Mask->StopScanLine(); tb->StopScanLine(); Bitmap->StopScanLine(); delete Bitmap; } if (Form) delete Form; Screen->Cursor = oldcursor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------- void __fastcall TSeparateForm::sbRunClick(TObject *Sender) { //BeConverted by linuxjun Don't Forget!! Undo_Method int i, j, x, y; TCursor oldcursor; Byte *mp, *dp[11], *sp, *mp1; TUnionBitmap *tb, *Bitmap; // convert by // TUndoManager *uBitmap; TUnionBitmap *uBitmap; RGBQUAD rgb[256]; RECT Src; bool undoSw = false; THistoryData *ud; oldcursor = Screen->Cursor; Screen->Cursor = crHourGlass; MainImageForm->Palette->ToRGBQUAD(rgb, 256); Overlap = spEditOverlap->Value; tb = MainImageForm->iMainImage->uBitmap; if(step>0)MainImageForm->ResetDraw(true); if (MainImageForm->WorkArea->Mask) Src = MainImageForm->WorkArea->Range; else Src = Rect(0, 0, tb->Width, tb->Height); int Height=Src.bottom-Src.top; int Width=Src.right-Src.left; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Src)) == false) goto fail; ud = MainImageForm->Undo->GetLast(); Bitmap = ud->uBitmap; uBitmap = ud->uBitmap; uBitmap->PartialUndo->LoadLast(ud->FromRgb); if (MainImageForm->WorkArea->Mask) { if (!(uBitmap->StartUndoScanLine())) goto fail; if (!(MainImageForm->WorkArea->Mask->StartScanLineN(2))) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(Src.top+y)+Src.left, BackgroundIndex, Bitmap->Width); memset(tb->GetScanLine(Src.top+y)+Src.left, BackgroundIndex, Width); tb->PutScanLine(Src.top+y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; // dp[i] = j>=0 && jHeight ? tb->GetScanLineN(Src.top+j, j)+Src.left : NULL; dp[i] = j>=0 && jGetScanLineN(Src.top+j, j)+Src.left : NULL; } // for (y=0; yHeight; y++) { for (y=0; yGetUndoScanLine(y+Src.top)+Src.left; // dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(Src.top+y+Overlap, dp[2*Overlap] = y+OverlapGetScanLineN(Src.top+y+Overlap, (y+Overlap)%(2*Overlap+1))+Src.left : NULL; mp1 = MainImageForm->WorkArea->Mask->GetScanLineN(y, 0); // for (x=0; xWidth; x++) { for (x=0; xChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { #ifdef TPDEBUG // if (y-Overlap+i>=0 && y-Overlap+iHeight) if (y-Overlap+i>=0 && y-Overlap+iWorkArea->Mask->GetScanLineN(y-Overlap+i, 1); else SHOWDEBUG; #else mp = MainImageForm->WorkArea->Mask->GetScanLineN(y-Overlap+i, 1); #endif for (j=x-Overlap; j<=x+Overlap; j++) { // if (j>=0 && jWidth) { if (j>=0 && jPutScanLine(Src.top+y-Overlap, dp[0]-Src.left); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i = 0; i < Overlap; i++) if (dp[i]) tb->PutScanLine(Src.top+y-Overlap+i, dp[i]-Src.left); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y+Src.top)+Src.left; dp[0] = tb->GetScanLine(Src.top+y)+Src.left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y); // for (x=0; xWidth; x++, mp++) { for (x=0; xNumber[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } else { *(dp[0]+x) = *(sp+x); } } tb->PutScanLine(Src.top+y); } tb->StopScanLine(); } uBitmap->StopUndoScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } else { // if (!(Bitmap->StartScanLine())) goto fail; if (!(uBitmap->StartUndoScanLine())) goto fail; // if (!(uBitmap->StartScanLineN(2*Overlap+1))) goto fail; if (Overlap>0) { // uBitmap->StartScanLine(); if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; for (y=0; yHeight; y++) { memset(tb->GetScanLine(y), BackgroundIndex, Bitmap->Width); tb->PutScanLine(y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; dp[i] = j>=0 && jHeight ? tb->GetScanLineN(j, j) : NULL; } for (y=0; yHeight; y++) { sp = uBitmap->GetUndoScanLine(y); dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(y+Overlap, (y+Overlap)%(2*Overlap+1)) : NULL; for (x=0; xWidth; x++) { if (SepSelector->ChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { for (j=x-Overlap; j<=x+Overlap; j++) { if (j>=0 && jWidth) { *(dp[i]+j) = *(sp+x); } } } } } } if (dp[0]) tb->PutScanLine(y-Overlap, dp[0]); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i=0; iPutScanLineN(y-Overlap+i, i); tb->StopScanLine(); uBitmap->StopUndoScanLine(); } else { if (!(tb->StartScanLine())) goto fail; for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[0] = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(dp[0]+x) = SepSelector->Number[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } tb->PutScanLine(y); } tb->StopScanLine(); } uBitmap->StopUndoScanLine(); } // ud->Complete(); ::RepaintImage(); sbRun->Enabled = false; sbRestore->Enabled = true; Screen->Cursor = oldcursor; return; fail: tb->StopScanLine(); Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); Screen->Cursor = oldcursor; if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); /* //BeConverted by linuxjun Don't Forget!! Undo_Method int i, j, x, y; TCursor oldcursor; Byte *mp, *dp[11], *sp, *mp1; TUnionBitmap *tb, *Bitmap; // convert by celberus RGBQUAD rgb[256]; RECT Src; bool undoSw = false; THistoryData *ud; oldcursor = Screen->Cursor; Screen->Cursor = crHourGlass; MainImageForm->Palette->ToRGBQUAD(rgb, 256); Overlap = spEditOverlap->Value; tb = MainImageForm->iMainImage->uBitmap; if(step>0)MainImageForm->ResetDraw(true); if (MainImageForm->WorkArea->Mask) Src = MainImageForm->WorkArea->Range; else Src = Rect(0, 0, tb->Width, tb->Height); int Height=Src.bottom-Src.top; int Width=Src.right-Src.left; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Src)) == false) goto fail; ud = MainImageForm->Undo->GetLast(); Bitmap = ud->uBitmap; if (MainImageForm->WorkArea->Mask) { if (!(Bitmap->StartScanLine())) goto fail; if (!(MainImageForm->WorkArea->Mask->StartScanLineN(2))) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(Src.top+y)+Src.left, BackgroundIndex, Bitmap->Width); memset(tb->GetScanLine(Src.top+y)+Src.left, BackgroundIndex, Width); tb->PutScanLine(Src.top+y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; // dp[i] = j>=0 && jHeight ? tb->GetScanLineN(Src.top+j, j)+Src.left : NULL; dp[i] = j>=0 && jGetScanLineN(Src.top+j, j)+Src.left : NULL; } // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y+Src.top)+Src.left; // dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(Src.top+y+Overlap, dp[2*Overlap] = y+OverlapGetScanLineN(Src.top+y+Overlap, (y+Overlap)%(2*Overlap+1))+Src.left : NULL; mp1 = MainImageForm->WorkArea->Mask->GetScanLineN(y, 0); // for (x=0; xWidth; x++) { for (x=0; xChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { #ifdef TPDEBUG // if (y-Overlap+i>=0 && y-Overlap+iHeight) if (y-Overlap+i>=0 && y-Overlap+iWorkArea->Mask->GetScanLineN(y-Overlap+i, 1); else SHOWDEBUG; #else mp = MainImageForm->WorkArea->Mask->GetScanLineN(y-Overlap+i, 1); #endif for (j=x-Overlap; j<=x+Overlap; j++) { // if (j>=0 && jWidth) { if (j>=0 && jPutScanLine(Src.top+y-Overlap, dp[0]-Src.left); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i = 0; i < Overlap; i++) if (dp[i]) tb->PutScanLine(Src.top+y-Overlap+i, dp[i]-Src.left); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y+Src.top)+Src.left; dp[0] = tb->GetScanLine(Src.top+y)+Src.left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y); // for (x=0; xWidth; x++, mp++) { for (x=0; xNumber[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } else { *(dp[0]+x) = *(sp+x); } } tb->PutScanLine(Src.top+y); } tb->StopScanLine(); } Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } else { // if (!(Bitmap->StartScanLine())) goto fail; if (!(Bitmap->StartScanLineN(2*Overlap+1))) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; for (y=0; yHeight; y++) { memset(tb->GetScanLine(y), BackgroundIndex, Bitmap->Width); tb->PutScanLine(y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; dp[i] = j>=0 && jHeight ? tb->GetScanLineN(j, j) : NULL; } for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(y+Overlap, (y+Overlap)%(2*Overlap+1)) : NULL; for (x=0; xWidth; x++) { if (SepSelector->ChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { for (j=x-Overlap; j<=x+Overlap; j++) { if (j>=0 && jWidth) { *(dp[i]+j) = *(sp+x); } } } } } } if (dp[0]) tb->PutScanLine(y-Overlap, dp[0]); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i=0; iPutScanLineN(y-Overlap+i, i); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[0] = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(dp[0]+x) = SepSelector->Number[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } tb->PutScanLine(y); } tb->StopScanLine(); } Bitmap->StopScanLine(); } // ud->Complete(); ::RepaintImage(); sbRun->Enabled = false; sbRestore->Enabled = true; Screen->Cursor = oldcursor; return; fail: tb->StopScanLine(); Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); Screen->Cursor = oldcursor; if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); /* //BeConverted by linuxjun Don't Forget!! Undo_Method int i, j, x, y; TCursor oldcursor; Byte *mp, *dp[11], *sp, *mp1; TUnionBitmap *tb; // TUnionBitmap *Bitmap; // convert by celberus TUndoManager *UndoManager; RGBQUAD rgb[256]; RECT Src; bool undoSw = false; THistoryData *ud; oldcursor = Screen->Cursor; Screen->Cursor = crHourGlass; MainImageForm->Palette->ToRGBQUAD(rgb, 256); Overlap = spEditOverlap->Value; tb = MainImageForm->iMainImage->uBitmap; if(step>0)MainImageForm->ResetDraw(true); if (MainImageForm->WorkArea->Mask) Src = MainImageForm->WorkArea->Range; else Src = Rect(0, 0, tb->Width, tb->Height); int Height=Src.bottom-Src.top+1; int Width=Src.right-Src.left+1; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Src)) == false) goto fail; ud = MainImageForm->Undo->GetLast(); // Bitmap = ud->uBitmap; UndoManager = MainImageForm->iMainImage->uBitmap->PartialUndo; MainImageForm->iMainImage->uBitmap->PartialUndo->LoadLast(ud->FromRgb); if (MainImageForm->WorkArea->Mask) { if (!(UndoManager->StartScanLine())) goto fail; if (!(MainImageForm->WorkArea->Mask->StartScanLineN(2))) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(Src.top+y)+Src.left, BackgroundIndex, Bitmap->Width); memset(tb->GetScanLine(Src.top+y)+Src.left, BackgroundIndex, Width); tb->PutScanLine(Src.top+y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; // dp[i] = j>=0 && jHeight ? tb->GetScanLineN(Src.top+j, j)+Src.left : NULL; dp[i] = j>=0 && jGetScanLineN(Src.top+j, j)+Src.left : NULL; } // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y+Src.top)+Src.left; //caution!! sp = UndoManager->GetUndoScanLine(y+Src.top)+Src.left; // dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(Src.top+y+Overlap, dp[2*Overlap] = y+OverlapGetScanLineN(Src.top+y+Overlap, (y+Overlap)%(2*Overlap+1))+Src.left : NULL; mp1 = MainImageForm->WorkArea->Mask->GetScanLineN(y, 0); // for (x=0; xWidth; x++) { for (x=0; xChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { #ifdef TPDEBUG // if (y-Overlap+i>=0 && y-Overlap+iHeight) if (y-Overlap+i>=0 && y-Overlap+iWorkArea->Mask->GetScanLineN(y-Overlap+i, 1); else SHOWDEBUG; #else mp = MainImageForm->WorkArea->Mask->GetScanLineN(y-Overlap+i, 1); #endif for (j=x-Overlap; j<=x+Overlap; j++) { // if (j>=0 && jWidth) { if (j>=0 && jPutScanLine(Src.top+y-Overlap, dp[0]-Src.left); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i = 0; i < Overlap; i++) if (dp[i]) tb->PutScanLine(Src.top+y-Overlap+i, dp[i]-Src.left); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(Src.top+y)+Src.left; sp = UndoManager->GetUndoScanLine(y+Src.top)+Src.left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y); // for (x=0; xWidth; x++, mp++) { for (x=0; xNumber[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } else { *(dp[0]+x) = *(sp+x); } } tb->PutScanLine(Src.top+y); } tb->StopScanLine(); } UndoManager->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } else { if (!(UndoManager->StartScanLine())) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y), BackgroundIndex, Bitmap->Width); memset(tb->GetScanLine(y), BackgroundIndex, Width); tb->PutScanLine(y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; // dp[i] = j>=0 && jHeight ? tb->GetScanLineN(j, j) : NULL; dp[i] = j>=0 && jGetScanLineN(j, j) : NULL; } // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y+Src.top)+Src.left; sp = UndoManager->GetUndoScanLine(y+Src.top)+Src.left; // dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(y+Overlap, dp[2*Overlap] = y+OverlapGetScanLineN(y+Overlap, (y+Overlap)%(2*Overlap+1)) : NULL; // for (x=0; xWidth; x++) { for (x=0; xChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { for (j=x-Overlap; j<=x+Overlap; j++) { // if (j>=0 && jWidth) { if (j>=0 && jPutScanLine(y-Overlap, dp[0]); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i=0; iPutScanLineN(y-Overlap+i, i); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; // for (y=0; yHeight; y++) { for (y=0; yGetScanLine(y); dp[0] = tb->GetScanLine(y); sp = UndoManager->GetUndoScanLine(y); // for (x=0; xWidth; x++) { for (x=0; xNumber[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } tb->PutScanLine(y); } tb->StopScanLine(); } UndoManager->StopScanLine(); } // ud->Complete(); ::RepaintImage(); sbRun->Enabled = false; sbRestore->Enabled = true; Screen->Cursor = oldcursor; return; fail: tb->StopScanLine(); UndoManager->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); Screen->Cursor = oldcursor; if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); */ /* //BeConverted by linuxjun Don't Forget!! Undo_Method int i, j, x, y; TCursor oldcursor; Byte *mp, *dp[11], *sp, *mp1; TUnionBitmap *tb, *Bitmap; // convert by celberus RGBQUAD rgb[256]; RECT Src; bool undoSw = false; TUndoData *ud; oldcursor = Screen->Cursor; Screen->Cursor = crHourGlass; MainImageForm->Palette->ToRGBQUAD(rgb, 256); Overlap = spEditOverlap->Value; tb = MainImageForm->iMainImage->uBitmap; if(step>0)MainImageForm->ResetDraw(true); if (MainImageForm->WorkArea->Mask) Src = MainImageForm->WorkArea->Range; else Src = Rect(0, 0, tb->Width, tb->Height); if ((undoSw = MainImageForm->UndoSave(UK_ALL, Src)) == false) goto fail; ud = Undo->Last; Bitmap = ud->Bitmap; if (MainImageForm->WorkArea->Mask) { if (!(Bitmap->StartScanLine())) goto fail; if (!(MainImageForm->WorkArea->Mask->StartScanLineN(2))) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; for (y=0; yHeight; y++) { memset(tb->GetScanLine(Src.top+y)+Src.left, BackgroundIndex, Bitmap->Width); tb->PutScanLine(Src.top+y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; dp[i] = j>=0 && jHeight ? tb->GetScanLineN(Src.top+j, j)+Src.left : NULL; } for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(Src.top+y+Overlap, (y+Overlap)%(2*Overlap+1))+Src.left : NULL; mp1 = MainImageForm->WorkArea->Mask->GetScanLineN(y, 0); for (x=0; xWidth; x++) { if (*(mp1+x)) { if (SepSelector->ChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { #ifdef TPDEBUG if (y-Overlap+i>=0 && y-Overlap+iHeight) mp = MainImageForm->WorkArea->Mask->GetScanLineN(y-Overlap+i, 1); else SHOWDEBUG; #else mp = MainImageForm->WorkArea->Mask->GetScanLineN(y-Overlap+i, 1); #endif for (j=x-Overlap; j<=x+Overlap; j++) { if (j>=0 && jWidth) { if (*(mp+j)) *(dp[i]+j) = *(sp+x); } } } } } } else { *(dp[Overlap]+x) = *(sp+x); } } if (dp[0]) tb->PutScanLine(Src.top+y-Overlap, dp[0]-Src.left); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i = 0; i < Overlap; i++) if (dp[i]) tb->PutScanLine(Src.top+y-Overlap+i, dp[i]-Src.left); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[0] = tb->GetScanLine(Src.top+y)+Src.left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x=0; xWidth; x++, mp++) { if (*mp) { *(dp[0]+x) = SepSelector->Number[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } else { *(dp[0]+x) = *(sp+x); } } tb->PutScanLine(Src.top+y); } tb->StopScanLine(); } Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); } else { if (!(Bitmap->StartScanLine())) goto fail; if (Overlap>0) { if (!(tb->StartScanLineN(2*Overlap+1))) goto fail; for (y=0; yHeight; y++) { memset(tb->GetScanLine(y), BackgroundIndex, Bitmap->Width); tb->PutScanLine(y); } for (i=0; i<2*Overlap; i++) { j = i-Overlap; dp[i] = j>=0 && jHeight ? tb->GetScanLineN(j, j) : NULL; } for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[2*Overlap] = y+OverlapHeight ? tb->GetScanLineN(y+Overlap, (y+Overlap)%(2*Overlap+1)) : NULL; for (x=0; xWidth; x++) { if (SepSelector->ChoiceColor->Number[*(sp+x)]<255) { for (i=0; i<2*Overlap+1; i++) { if (dp[i]) { for (j=x-Overlap; j<=x+Overlap; j++) { if (j>=0 && jWidth) { *(dp[i]+j) = *(sp+x); } } } } } } if (dp[0]) tb->PutScanLine(y-Overlap, dp[0]); for (i=0; i<2*Overlap; i++) dp[i] = dp[i+1]; } for (i=0; iPutScanLineN(y-Overlap+i, i); tb->StopScanLine(); } else { if (!(tb->StartScanLine())) goto fail; for (y=0; yHeight; y++) { sp = Bitmap->GetScanLine(y); dp[0] = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(dp[0]+x) = SepSelector->Number[*(sp+x)]Count ? *(sp+x) : BackgroundIndex; } tb->PutScanLine(y); } tb->StopScanLine(); } Bitmap->StopScanLine(); } ud->Complete(); ::RepaintImage(); sbRun->Enabled = false; sbRestore->Enabled = true; Screen->Cursor = oldcursor; return; fail: tb->StopScanLine(); Bitmap->StopScanLine(); MainImageForm->WorkArea->Mask->StopScanLine(); Screen->Cursor = oldcursor; if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); */ } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbExitClick(TObject *Sender) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbNewClick(TObject *Sender) { SepSelector->Initial(); } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbAllClick(TObject *Sender) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(SepSelector->ChoiceColor); else MainImageForm->SearchWholeColor(SepSelector->ChoiceColor); SepSelector->Invalid(); Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbDeleteClick(TObject *Sender) { if (sbDelete->Down) sbDelete->Hint = IDS_COMMON_DELETECOLOR; else sbDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbBlockClick(TObject *Sender) { if (sbBlock->Down) sbBlock->Hint = IDS_COMMON_ONECOLOR; else sbBlock->Hint = IDS_COMMON_BLOCKCOLOR; } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::sbBeforeClick(TObject *Sender) { SepSelector->LoadFromFile(DirectoryItem+"\\Separate.Ini", "ColorSelector"); } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TSeparateForm::InitForm() { MainImageForm->iMainImage->Cursor = crDefault; ParentHeight = Parent->Height+20; ClientHeight = 153; Parent->Height = ParentHeight+ClientHeight; sbRestore->Enabled = false; sbRun->Enabled = true; SepSelector->SetPalette(MainImageForm->Palette); SepSelector->Initial(); } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::ExitForm() { MainImageForm->ResetDraw(true); SepSelector->SaveToFile(DirectoryItem+"\\Separate.Ini", "ColorSelector"); } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::SepSelectorColor(int Value) { SepSelector->AddColor(Value); sbRun->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TRect r; Byte *scan, c; int ix, iy; TPItemImage *MainImage = (TPItemImage *) Sender; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { if (sbBlock->Down) { c = MainImage->uBitmap->GetPixelColor(X, Y); if (sbDelete->Down) { SepSelector->DeleteColor(c); } else { SepSelector->AddColor(c); } } else { if (step>0) { Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); if (Temp.left>Temp.right) { r.Left = Temp.right; r.Right = Temp.left; } else { r.Left = Temp.left; r.Right = Temp.right; } if (Temp.top>Temp.bottom) { r.Top = Temp.bottom; r.Bottom = Temp.top; } else { r.Top = Temp.top; r.Bottom = Temp.bottom; } if (!(MainImage->uBitmap->StartScanLine())) goto fail; if (sbDelete->Down) { for (iy=r.Top; iyuBitmap->GetScanLine(iy); for (ix=r.Left; ixDeleteColor(*(scan+ix)); } } } else { for (iy=r.Top; iyuBitmap->GetScanLine(iy); for (ix=r.Left; ixAddColor(*(scan+ix)); } } } MainImage->uBitmap->StopScanLine(); step = 0; IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } else { Temp.left = X; Temp.top = Y; Temp.bottom = Temp.top; Temp.right = Temp.left; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; step = 1; } } } return; fail: MainImage->uBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::iMainImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (step > 0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::iMainImagePaint() { IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::spEditOverlapChange(TObject *Sender) { if (spEditOverlap->Text.Length() > 0) { if (spEditOverlap->Value > spEditOverlap->MaxValue) spEditOverlap->Value = spEditOverlap->MaxValue; else if (spEditOverlap->Value < spEditOverlap->MinValue) spEditOverlap->Value = spEditOverlap->MinValue; } } //--------------------------------------------------------------------------- void __fastcall TSeparateForm::iMainImageKeyDown(int Key) //lhskys »öºÐÇØ½Ã ¿£ÅÍ·Î ½ÇÇà { if ( Key == 13 && sbRun->Enabled) sbRunClick(this); } //---------------------------------------------------------------------------