//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "SpreadFill.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzButton" #pragma link "RzRadChk" #pragma link "RzBckgnd" #pragma link "RzPanel" #pragma link "RzTrkBar" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_MULTIPLEGRADE StringTable[0] #define IDS_SINGLEGRADE StringTable[1] #define IDS_WAVEFREQUENCY StringTable[2] #define IDS_WAVEHEIGHT StringTable[3] #define IDS_LINEAR StringTable[4] #define IDS_CIRCULATE StringTable[5] #define IDS_READYTODRAW StringTable[6] #define IDS_COLORSELECT StringTable[7] #define IDS_INAUTOREP StringTable[8] #define IDS_SPREAD_FILL StringTable[9] #define IDS_DELETE_ALL StringTable[10] #define poldingSize 100 #define expandSize 163 //--------------------------------------------------------------------------- TSpreadFillForm *SpreadFillForm; //--------------------------------------------------------------------------- __fastcall TSpreadFillForm::TSpreadFillForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //=============================== 2001.9.11 lhskys FormCreate(TObject *Sender)³»¿ë ¿Å±è StringTable.Create(DirectoryBin, Language, "SpreadFill"); SetSmallFont(Font); // SetSmallFont(Label1->Font); //SetSmallFont(StaticTextColor->Font); this->Caption = IDS_SPREAD_FILL; Label2->Caption = IDS_WAVEFREQUENCY; Label3->Caption = IDS_WAVEHEIGHT; //SpeedButtonPosition->Caption = IDS_COMMON_POSITION; // Label1->Caption = IDS_COLOR; rzcbSelectColor->Caption = IDS_COLORSELECT; //IDS_READYTODRAW; SpeedButtonNew->Hint = IDS_COMMON_NEW; SpeedButtonAll->Hint = IDS_COMMON_ALL; SpeedButtonOne->Hint = IDS_COMMON_BLOCKCOLOR; SpeedButtonDelete->Hint = IDS_COMMON_INSERTCOLOR; SpeedButtonBefore->Hint = IDS_COMMON_BEFORECOLOR; ImageView->Hint = IDS_LINEAR; rzmtbtLinear->Hint = IDS_MULTIPLEGRADE + " " + IDS_LINEAR; rzmtbtCirculate->Hint = IDS_MULTIPLEGRADE + " " + IDS_CIRCULATE; rzmtbtSingleLinear->Hint = IDS_SINGLEGRADE + " " + IDS_LINEAR; rzmtbtSingleCirculate->Hint = IDS_SINGLEGRADE + " " + IDS_CIRCULATE; sbAutoRep->Hint = IDS_INAUTOREP; miDelete->Caption = IDS_COMMON_DELETE; miDeleteAll->Caption = IDS_DELETE_ALL; //sbAutoRep->Hint = IDS_INAUTOREP; //cbAutoRep->Caption = IDS_INAUTOREP; //cbFAutoRep->Caption = IDS_INAUTOREP; //===================================================================== } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::FormCreate(TObject *Sender) { //============ 2001.9.11 lhskys FormCreate(TObject *Sender)³»¿ë ¿Å±è } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::ImageViewClick(TObject *Sender) { BEGIN_LOG(""); if (!Bpp24){ if (Item) { ExitItem(); if (InitItem(0)) rzmtbtLinear->Down = true; } else { ExitItem(); if (InitItem(1)) rzmtbtCirculate->Down = true; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::SpeedButtonNewClick(TObject *Sender) { BEGIN_LOG(""); ColorSelector->Initial(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::SpeedButtonAllClick(TObject *Sender) { BEGIN_LOG(""); TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(ColorSelector->ChoiceColor); else MainImageForm->SearchWholeColor(ColorSelector->ChoiceColor); ColorSelector->Invalid(); Screen->Cursor = cursor; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::SpeedButtonOneClick(TObject *Sender) { if (SpeedButtonOne->Down) SpeedButtonOne->Hint = IDS_COMMON_ONECOLOR; else SpeedButtonOne->Hint = IDS_COMMON_BLOCKCOLOR; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::SpeedButtonDeleteClick(TObject *Sender) { if (SpeedButtonDelete->Down) SpeedButtonDelete->Hint=IDS_COMMON_DELETECOLOR; else SpeedButtonDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::TrackBarChange(TObject *Sender) { if (TrackBar->Position > 0 && TrackBar->Position < TrackBar->Max) { seGap->Value = Gap[TrackBar->Position - 1] + 1; seGap->Enabled = true; } else { seGap->Enabled = false; } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::seGapChange(TObject *Sender) { BEGIN_LOG(""); if (seGap->Text.Length() > 0 && TrackBar->Position > 0 && TrackBar->Position < TrackBar->Max) { if (seGap->Value < 1) seGap->Value = 1; if(!Bpp24) { if (seGap->Value > 255) seGap->Value = 255; }else { int total = 0; for (int i = 0; i < TrackBar->Max - 1; i++) total += Gap[i]; total = total - Gap[TrackBar->Position - 1] + seGap->Value - 1 + TrackBar->Max - 1; if(total > 1000) seGap->Value = total - 1000; } if (seGap->Value == 1) Gap[TrackBar->Position - 1] = 1; else Gap[TrackBar->Position - 1] = seGap->Value - 1; bChange = true; if (EnoughPalette()) View(); else { Gap[TrackBar->Position - 1] = 1; seGap->Value = 2; EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::SpinEditClick(TObject *Sender) { ((TRzSpinEdit *) Sender)->SetFocus(); ((TRzSpinEdit *) Sender)->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::SpeedButtonBeforeClick(TObject *Sender) { BEGIN_LOG(""); ColorSelector->LoadFromFile(AppDataItem + "\\SpreadFill.Ini", "ColorSelect"); END_LOG; } //---------------------------------------------------------------------------///////////////////////////////////////////////////////////////////////////// //----------------------------/Private Method/------------------------------- ///////////////////////////////////////////////////////////////////////////// //--------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::InitItem(int i) { BEGIN_LOG(""); int oldItem = Item; Item = i; if(Item == 0) { rzmtbtLinear->Down = true; ImageView->Hint = IDS_LINEAR; } else if(Item == 1) { rzmtbtCirculate->Down = true; ImageView->Hint = IDS_CIRCULATE; } else if(Item == 2) { rzmtbtSingleLinear->Click(); rzmtbtSingleLinear->Down = true; ImageView->Hint = IDS_LINEAR; } else if(Item == 3) { rzmtbtSingleCirculate->Click(); rzmtbtSingleCirculate->Down = true; ImageView->Hint = IDS_CIRCULATE; } if(Item == 0 || Item ==1) { if (!View()){ Item = oldItem; if(Item == 0) rzmtbtLinear->Down = true; else if(Item == 1) rzmtbtCirculate->Down = true; else if(Item == 2) { rzmtbtSingleLinear->Down = true; mono = true; } else if(Item == 3) { rzmtbtSingleCirculate->Down = true; mono = true; } END_LOG; return false; } } END_LOG; return true; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::ExitItem() { BEGIN_LOG(""); if (!Bpp24 && bColor) { //if (SpeedButtonPosition->Down) { if (SpeedButtonOne->Down==false) { if (step>0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo step = 0; } } } else { if (step>0) { if (IsDraw) MainImageForm->DrawLineLocate(First, Second); IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo step = 0; } } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::View() { BEGIN_LOG(""); int i, j ,k, l, x, y, d, m; TPException ec = EC_NONE; Byte r, g, b; RGBQUAD rgb[1000]; RGBQUAD rgbPal[256]; Byte *sl, *scan; if (SpreadColor) { HeapFree(GetProcessHeap(), 0, SpreadColor); SpreadColor = NULL; } SpreadCount = 1; for (i=0; iMax-1; i++) SpreadCount = SpreadCount+Gap[i]; SpreadColor = (TColor*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SpreadCount*sizeof(TColor)); if (SpreadColor == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } cp = SpreadColor; for (i=0; iMax-1; i++) { rgb[0] = MainImageForm->Palette->ColorData[ColorIndex[i]]->RGB; rgb[255] = MainImageForm->Palette->ColorData[ColorIndex[i+1]]->RGB; for (j=0; jPalette->ColorData[ColorIndex[TrackBar->Max-1]]->RGB.rgbRed; g = MainImageForm->Palette->ColorData[ColorIndex[TrackBar->Max-1]]->RGB.rgbGreen; b = MainImageForm->Palette->ColorData[ColorIndex[TrackBar->Max-1]]->RGB.rgbBlue; *cp = RGB2TColor(r, g, b); j = MainImageForm->Palette->UseColor+1; cp = SpreadColor; if (Bpp24) j = 0; else if (j + SpreadCount >= 252) { ec = EC_COLOR_OVERFLOW; goto fail; } for (i=0; iDIB256Palette->Palette->ToRGBQUAD(rgbPal, 256); ImageGrade2->Picture->Bitmap->PixelFormat = pf8bit; ImageGrade2->Picture->Bitmap->Width = 140; ImageGrade2->Picture->Bitmap->Height = 33; SetDIBColorTable(ImageGrade2->Picture->Bitmap->Canvas->Handle, 0, 256, rgbPal); ImageView->Picture->Bitmap->PixelFormat = pf8bit; ImageView->Picture->Bitmap->Width = 90; ImageView->Picture->Bitmap->Height = 60;//112; SetDIBColorTable(ImageView->Picture->Bitmap->Canvas->Handle, 0, 256, rgb); if (Bpp24) j = 0; else j = MainImageForm->Palette->UseColor+1; //l = ImageGrade2->Width; //k = ((l-1)/(SpreadCount-1))+1; for (int y = 0; y < ImageGrade2->Height; y++){ Byte *scan = (Byte *)ImageGrade2->Picture->Bitmap->ScanLine[y]; for (int x = 0; x Width; x++) { int index = 0; if (x > 0){ index = x / (ImageGrade2->Width / TrackBar->Max); } if (index > TrackBar->Max-1) index = TrackBar->Max-1; scan[x] = ColorIndex[index]; } } ImageGrade2->Repaint(); if (Item==0) { l = ImageView->Width; k = ((l-1)/(SpreadCount-1))+1; for (y=0; yHeight; y++) { sl = (Byte*) ImageView->Picture->Bitmap->ScanLine[y]; for (x=0; xWidth; x++) { d = x/k; m = x%k; if (rand() % k > m) sl[x] = (Byte) j+d; else sl[x] = Byte(j+d+1); } } ImageView->Repaint(); } else if(Item == 1) { l = sqrt(pow(ImageView->Width / 2, 2) + pow(ImageView->Height / 2, 2)); k = (l / (SpreadCount-1))+1; //¼ýÀÚ°¡ 55·Îµµ µÇ¾î À־ À̹ÌÁö°¡ 112À̱⠶§¹®¿¡ ¸¶Áö¸· ºÎºÐÀÌ ¹Ù²îÁö ¾Ê´Â //¹®Á¦°¡ À־ ¼öÁ¤ by david 100512 // for (y = -56; y < 56; y++) { // sl = (Byte*) ImageView->Picture->Bitmap->ScanLine[y + 56]; // for (x = -56; x < 56; x++) { // l = sqrt(x*x+y*y); // d = l/k; // m = l%k; // if (rand() % k > m) sl[x + 56] = (Byte) j+d; else sl[x + 56] = (Byte) j+d+1; // } // } for (y = -30; y < 30; y++) { sl = (Byte*) ImageView->Picture->Bitmap->ScanLine[y + 30]; for (x = -45; x < 45; x++) { l = sqrt(x*x+y*y); d = l/k; m = l%k; if (rand() % k > m) sl[x + 45] = (Byte) j+d; else sl[x + 45] = (Byte) j+d+1; } } ImageView->Repaint(); } END_LOG; return true; fail: EXCEPTION_MESSAGE_OK(ec); if (ec == EC_MEMORY_LACK) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; return false; } //--------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillSingle_none8(Byte *p, int x) { return *(p + x) == (Byte)FillColor; } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillSingle_layer8_nonezero(Byte *p, Byte *lp, int x) { return *(p + x) == (Byte)FillColor && (*(lp + x) != 0); } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillSingle_layer8_zero(Byte *p, Byte *lp, int x) { return *(p + x) == (Byte)FillColor && (*(lp + x) == 0); } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillMulti_none8(Byte *p, int x) { return ColorSelector->Number[*(p+x)] < 255; } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillMulti_layer8_nonezero(Byte *p, Byte *lp, int x) { return ColorSelector->Number[*(p+x)] < 255 && (*(lp + x) != 0); } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillMulti_layer8_zero(Byte *p, Byte *lp, int x) { return ColorSelector->Number[*(p+x)] < 255 && (*(lp + x) == 0); } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillSingle_none24(Byte *p, int x) { COLORREF c; p += 3*x; GetPixel24(p, c); return c == FillColor; } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillSingle_layer24_nonezero(Byte *p, Byte *lp, int x) { COLORREF c; p += 3*x; GetPixel24(p, c); return (c == FillColor) && ((lp[x >> 3] & (0x80 >> (x & 7))) != 0); } //---------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::FillSingle_layer24_zero(Byte *p, Byte *lp, int x) { COLORREF c; p += 3*x; GetPixel24(p, c); return (c == FillColor) && ((lp[x >> 3] & (0x80 >> (x & 7))) == 0); } //---------------------------------------------------------------------------- int xTransfer(int x, int y, double ct, double st) { int k = x*ct+y*st+0.5; return k; } //--------------------------------------------------------------------------- TPoint xyTransfer(int x, int y, double ct, double st) { return Point(x*ct+y*st+0.5, -x*st+y*ct+0.5); } //--------------------------------------------------------------------------- TPException __fastcall TSpreadFillForm::PaletteMakeSpread() { BEGIN_LOG(""); if (Bpp24) { END_LOG; return EC_NONE; //dog 256err } int i, max, rindex, pn = 0; if (seGap->Value>=2) { if (bChange) { //------------------------------------- max = ColorIndex[0]; //ÃʱâÈ­Çϴµ¥ ¹®Á¦Á¡... rindex = MainImageForm->Palette->UseColor; for (i = 1; i<= TrackBar->Max; i++) { if (max < ColorIndex[i]) max = ColorIndex[i]; } if (MainImageForm->Palette->UseColor < max) MainImageForm->Palette->UseColor = max; //------------------------------------- Index = MainImageForm->Palette->UseColor+1; for (i = 0; i < TrackBar->Max-1; i++) pn += (Gap[i]+1); if ((pn + Index + 1) >= 252) { MainImageForm->Palette->UseColor = rindex; END_LOG; return EC_COLOR_OVERFLOW; } MainImageForm->Palette->MakeSpread(TrackBar->Max-1, ColorIndex, 5, Gap, 4); bChange = false; } } END_LOG; return EC_NONE; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::GoSpreadFill() { BEGIN_LOG(""); TCursor cursor = Screen->Cursor; TPException ec = EC_NONE; Screen->Cursor = crHourGlass; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { if (Item == 0) { if ((ec = LinearSpreadFill_8()) != EC_NONE) goto fail; } else { if ((ec = CirculateSpreadFill_8()) != EC_NONE) goto fail; } } else { if (Item ==0) { if ((ec = LinearSpreadFill_24()) != EC_NONE) goto fail; } else { if ((ec = CirculateSpreadFill_24()) != EC_NONE) goto fail; } } ::RepaintColor(); Screen->Cursor = cursor; END_LOG; return; fail: Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(ec); if (ec == EC_COLOR_OVERFLOW) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- TPException __fastcall TSpreadFillForm::LinearSpreadFill_8() { BEGIN_LOG(""); int i, j, k, d, m, x, y; TPException ec = EC_NONE; double dx, dy, Theta, st, ct; TRect rect[2], art; RECT rt; bool sw, undosw = false; Byte *sl, *mp, *lp; TPBitmap *Mask = NULL; TPItemImage *Image = MainImageForm->iMainImage; if ((Mask = new TPBitmap) == NULL) goto fail; dx = Second.x-First.x; dy = Second.y-First.y; if (dx || dy) Theta = atan2(dy, dx); else Theta = 0; st = sin(Theta); ct = cos(Theta); if (ColorSelector->Count==0) { FillColor = Image->uBitmap->GetPixelColor(First.x, First.y); if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)){ art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if (Image->FloodFillMask(First, FillSingle_layer8_nonezero, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (Image->FloodFillMask(First, FillSingle_layer8_zero, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillSingle_none8, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { ec = EC_INCORRECT_POINT; goto fail; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if (Image->FloodFillMask(First, FillSingle_layer8_nonezero, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (Image->FloodFillMask(First, FillSingle_layer8_zero, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillSingle_none8, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } } else { if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)){ art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if (Image->FloodFillMask(First, FillMulti_layer8_nonezero, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (Image->FloodFillMask(First, FillMulti_layer8_zero, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillMulti_none8, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { ec = EC_INCORRECT_POINT; goto fail; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if (Image->FloodFillMask(First, FillMulti_layer8_nonezero, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (Image->FloodFillMask(First, FillMulti_layer8_zero, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillMulti_none8, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } } art = rect[0]; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { rt = MainImageForm->AutoRep_UndoRect((RECT)rect[0]); art = rt; } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, art)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; Mask->Lock(); sw = true; for (y=rect[0].Top; yScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x & 7))) { i = xTransfer(x, y, ct, st); if (sw) { rect[1].Left = i; rect[1].Right = rect[1].Left; sw = false; } else { if (irect[1].Right) rect[1].Right = i; } } } } j = Index; k = (rect[1].Right-rect[1].Left) / (SpreadCount-1) + 1; if (!Image->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (!Image->LayerMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect[0].Top; yuBitmap->GetScanLine(y); lp = Image->LayerMask->GetScanLine(y); mp = Mask->ScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x &7))) { i = xTransfer(x, y, ct, st)-rect[1].Left; d = i/k; m = i%k; if ( d >= SpreadCount-1) { *(sl+x) = (Byte) j+SpreadCount-1; } else { if (rand() % k > m) *(sl+x) = (Byte) j+d; else *(sl+x) = (Byte) j+d+1; } lp[x] = 0; } } Image->uBitmap->PutScanLine(y); Image->LayerMask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y=rect[0].Top; yuBitmap->GetScanLine(y); mp = Mask->ScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x &7))) { i = xTransfer(x, y, ct, st)-rect[1].Left; d = i/k; m = i%k; if (d >= SpreadCount - 1) { *(sl+x) = (Byte) j+SpreadCount-1; } else { if (rand() % k > m) *(sl+x) = (Byte) j+d; else *(sl+x) = (Byte) j+d+1; } } } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); delete Mask; END_LOG; return ec; fail: if (undosw) MainImageForm->Undo->RemoveLast(); if (Mask) delete Mask; if (Image->LayerMask) Image->LayerMask->StopScanLine(); Image->uBitmap->StopScanLine(); END_LOG; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TSpreadFillForm::CirculateSpreadFill_8() { BEGIN_LOG(""); int i, j, k, d, m, x, y, xx, yy; TPException ec = EC_NONE; TRect rect, art; RECT rt; Byte *sl, *mp, *lp; double max, l; TPBitmap *Mask = NULL; bool undosw = false; TPItemImage *Image = MainImageForm->iMainImage; if((Mask = new TPBitmap) == NULL) goto fail; if (ColorSelector->Count==0) { FillColor = Image->uBitmap->GetPixelColor(First.x, First.y); if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer8_nonezero, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer8_zero, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none8, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { ec = EC_INCORRECT_POINT; goto fail; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer8_nonezero, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer8_zero, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none8, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } } else { if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillMulti_layer8_nonezero, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillMulti_layer8_zero, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillMulti_none8, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { ec = EC_INCORRECT_POINT; goto fail; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillMulti_layer8_nonezero, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillMulti_layer8_zero, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillMulti_none8, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } } art = rect; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { rt = MainImageForm->AutoRep_UndoRect((RECT)rect); art = rt; } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, art)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; Mask->Lock() ; max = 0; for (y=rect.Top; yScanLine(y); yy = y-First.y; for (x=rect.Left; x> 3)) & (0x80 >> (x & 7))) { xx = x-First.x; l = sqrt(xx*xx+yy*yy); if (l>max) max = l; } } } j = Index; k = max / (SpreadCount-1) + 1; if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->iMainImage->LayerMask) { if (!MainImageForm->iMainImage->LayerMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect.Top; yiMainImage->uBitmap->GetScanLine(y); mp = Mask->ScanLine(y); lp = MainImageForm->iMainImage->LayerMask->GetScanLine(y); yy = y-First.y; for (x=rect.Left; x> 3)) & (0x80 >> (x&7))) { xx = x-First.x; i = sqrt(xx*xx+yy*yy); d = i/k; m = i%k; if (d >= SpreadCount - 1) { *(sl+x) = (Byte) j+SpreadCount-1; } else { if (rand() % k > m) *(sl+x) = (Byte) j+d; else *(sl+x) = (Byte) j+d+1; } lp[x] = 0; } } MainImageForm->iMainImage->uBitmap->PutScanLine(y); MainImageForm->iMainImage->LayerMask->PutScanLine(y); } MainImageForm->iMainImage->LayerMask->StopScanLine(); } else { for (y=rect.Top; yiMainImage->uBitmap->GetScanLine(y); mp = Mask->ScanLine(y); yy = y-First.y; for (x=rect.Left; x> 3)) & (0x80 >> (x&7))) { xx = x-First.x; i = sqrt(xx*xx+yy*yy); d = i/k; m = i%k; if (d >= SpreadCount - 1) { *(sl+x) = (Byte) j+SpreadCount-1; } else { if (rand() % k > m) *(sl+x) = (Byte) j+d; else *(sl+x) = (Byte) j+d+1; } } } MainImageForm->iMainImage->uBitmap->PutScanLine(y); } } MainImageForm->iMainImage->uBitmap->StopScanLine(); delete Mask; END_LOG; return ec; fail : if (undosw) MainImageForm->Undo->RemoveLast(); if (Mask) delete Mask; if (Image->LayerMask) Image->LayerMask->StopScanLine(); Image->uBitmap->StopScanLine(); END_LOG; return ec; } //--------------------------------------------------------------------------- COLORREF TSpreadFillForm::ColorMap2COLORREF(int i) { //dog 256err RGBQUAD rgb = MainImageForm->Palette->ColorData[i]->RGB; //dog 256err return rgb.rgbRed | (rgb.rgbGreen << 8) | (rgb.rgbBlue << 16); Byte r, g, b; TColor2RGB(SpreadColor[i], r, g, b); return r | (g << 8) | (b << 16); } //--------------------------------------------------------------------------- TPException __fastcall TSpreadFillForm::LinearSpreadFill_24() { BEGIN_LOG(""); int i, /*j, */k, d, m, x, y; TPException ec = EC_NONE; double dx, dy, Theta, st, ct; TRect rect[2], art; RECT rc, rt, uart; bool sw, undosw = false; Byte *ssl, *mp, mm, *lp; COLORREF crrf; TPBitmap *Mask = NULL; TPItemImage *Image = MainImageForm->iMainImage; dx = Second.x-First.x; dy = Second.y-First.y; if (dx || dy) Theta = atan2(dy, dx); else Theta = 0; st = sin(Theta); ct = cos(Theta); if (MainImageForm->WorkArea->Mask){ rc = MainImageForm->WorkArea->Range; uart = rc; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { uart = MainImageForm->AutoRep_UndoRect(rc); } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, uart)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; if (L_IsPtInBitmapRgn(Image->uBitmap->RgnBitmap->Handle, First.y, First.x)) { rect[0] = Rect(rc.left, rc.top, rc.right, rc.bottom); if (!MainImageForm->WorkArea->Mask->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } sw = true; for (y=rect[0].Top; yWorkArea->Mask->GetScanLine(y-rect[0].Top); mm = 0x80; for (x=rect[0].Left; xrect[1].Right) rect[1].Right = i; } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } } // j = Index; k = (rect[1].Right-rect[1].Left) / (SpreadCount-1) + 1; if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (MainImageForm->iMainImage->LayerMask) { if (!MainImageForm->iMainImage->LayerMask->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect[0].Top; yiMainImage->uBitmap->GetScanLine(y) + 3*rect[0].Left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y-rect[0].Top); lp = MainImageForm->iMainImage->LayerMask->GetScanLine(y); mm = 0x80; for (x=rect[0].Left; x= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1); //dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d); //dog 256err j+d else crrf = ColorMap2COLORREF(d+1); //dog 256err j+d+1 } SetPixel24(ssl, crrf); *(lp + (x>>3)) &= ~(0x80 >> (x&7)); } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } MainImageForm->iMainImage->uBitmap->PutScanLine(y); MainImageForm->iMainImage->LayerMask->PutScanLine(y); } MainImageForm->iMainImage->LayerMask->StopScanLine(); } else { for (y=rect[0].Top; yiMainImage->uBitmap->GetScanLine(y) + 3*rect[0].Left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y-rect[0].Top); mm = 0x80; for (x=rect[0].Left; x= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1); //dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d); //dog 256err j+d else crrf = ColorMap2COLORREF(d+1); //dog 256err j+d+1 } SetPixel24(ssl, crrf); } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } MainImageForm->iMainImage->uBitmap->PutScanLine(y); } } MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); } else { goto next; } } else { next: if((Mask = new TPBitmap) == NULL) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } FillColor = Image->uBitmap->GetPixelColor(First.x, First.y); if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if (Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect[0], Mask, &art) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect[0], Mask, &art) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect[0], Mask, &art) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { ec = EC_INCORRECT_POINT; goto fail; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if (Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect[0], Mask) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect[0], Mask) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect[0], Mask) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } art = rect[0]; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { rt = MainImageForm->AutoRep_UndoRect((RECT)rect[0]); art = rt; } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, art)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; Mask->Lock(); sw = true; for (y=rect[0].Top; yScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x & 7))) { i = xTransfer(x, y, ct, st); if (sw) { rect[1].Left = i; rect[1].Right = rect[1].Left; sw = false; } else { if (irect[1].Right) rect[1].Right = i; } } } } // j = Index; k = (rect[1].Right-rect[1].Left) / (SpreadCount-1) + 1; if (!Image->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (!Image->LayerMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect[0].Top; yuBitmap->GetScanLine(y) + 3*rect[0].Left; mp = Mask->ScanLine(y); lp = Image->LayerMask->GetScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x &7))) { i = xTransfer(x, y, ct, st)-rect[1].Left; d = i/k; m = i%k; if (d >= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1); //dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d); //dog 256err j+d else crrf = ColorMap2COLORREF(d+1); //dog 256err j+d+1 } SetPixel24(ssl, crrf); *(lp + (x>>3)) &= ~(0x80 >>(x&7)); } } Image->uBitmap->PutScanLine(y); Image->LayerMask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y=rect[0].Top; yuBitmap->GetScanLine(y) + 3*rect[0].Left; mp = Mask->ScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x &7))) { i = xTransfer(x, y, ct, st)-rect[1].Left; d = i/k; m = i%k; if (d >= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1); //dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d);//dog 256err j+d else crrf = ColorMap2COLORREF(d+1);//dog 256err j+d+1 } SetPixel24(ssl, crrf); } } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); delete Mask; } END_LOG; return ec; fail : if (undosw) MainImageForm->Undo->RemoveLast(); if (Mask) delete Mask; if (Image->LayerMask) Image->LayerMask->StopScanLine(); if (MainImageForm->WorkArea->Mask) MainImageForm->WorkArea->Mask->StopScanLine(); Image->uBitmap->StopScanLine(); END_LOG; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TSpreadFillForm::CirculateSpreadFill_24() { BEGIN_LOG(""); int i, /*j, */k, d, m, x, y, xx, yy; TPException ec = EC_NONE; TRect rect, art; RECT rc, rt, uart; Byte *ssl, *mp, mm, *lp; double max, l; COLORREF crrf; bool undosw = false; TPBitmap *Mask = NULL; TPItemImage *Image = MainImageForm->iMainImage; if (MainImageForm->WorkArea->Mask) { rc = MainImageForm->WorkArea->Range; uart = rc; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { uart = MainImageForm->AutoRep_UndoRect(rc); } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, uart)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; if (L_IsPtInBitmapRgn(Image->uBitmap->RgnBitmap->Handle, First.y, First.x)) { max = 0; rect = Rect(rc.left, rc.top, rc.right, rc.bottom); if (!MainImageForm->WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect.Top; yWorkArea->Mask->GetScanLine(y - rect.Top); yy = y-First.y; mm = 0x80; for (x=rect.Left; xmax) max = l; } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } } // j = Index; k = max / (SpreadCount-1) + 1; if (!Image->uBitmap->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect.Top; yuBitmap->GetScanLine(y) + 3*rect.Left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y - rect.Top); yy = y-First.y; mm = 0x80; for (x=rect.Left; x= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1);//dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d);//dog 256err j+d else crrf = ColorMap2COLORREF(d+1);//dog 256err j+d+1 } SetPixel24(ssl, crrf); } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Image->uBitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); Image->uBitmap->StopScanLine(); } else goto next; } else { next: if((Mask = new TPBitmap) == NULL) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } FillColor = Image->uBitmap->GetPixelColor(First.x, First.y); if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect, Mask, &art) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect, Mask, &art) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect, Mask, &art) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { ec = EC_INCORRECT_POINT; goto fail; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect, Mask) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect, Mask) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect, Mask) == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } art = rect; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { rt = MainImageForm->AutoRep_UndoRect((RECT)rect); art = rt; } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, art)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; Mask->Lock(); max = 0; for (y=rect.Top; yScanLine(y); yy = y-First.y; for (x=rect.Left; x> 3)) & (0x80 >> (x & 7))) { xx = x-First.x; l = sqrt(xx*xx+yy*yy); if (l>max) max = l; } } } // j = Index; k = max / (SpreadCount-1) + 1; if (!Image->uBitmap->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (!Image->LayerMask->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=rect.Top; yuBitmap->GetScanLine(y) + 3*rect.Left; mp = Mask->ScanLine(y); lp = Image->LayerMask->GetScanLine(y); yy = y-First.y; for (x=rect.Left; x> 3)) & (0x80 >> (x&7))) { xx = x-First.x; i = sqrt(xx*xx+yy*yy); d = i/k; m = i%k; if (d >= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1);//dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d);//dog 256err j+d else crrf = ColorMap2COLORREF(d+1);//dog 256err j+d+1 } SetPixel24(ssl, crrf); *(lp + (x>>3)) &= ~(0x80 >> (x&7)); } } Image->uBitmap->PutScanLine(y); Image->LayerMask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y=rect.Top; yuBitmap->GetScanLine(y) + 3*rect.Left; mp = Mask->ScanLine(y); yy = y-First.y; for (x=rect.Left; x> 3)) & (0x80 >> (x&7))) { xx = x-First.x; i = sqrt(xx*xx+yy*yy); d = i/k; m = i%k; if (d >= SpreadCount - 1) { crrf = ColorMap2COLORREF(SpreadCount-1);//dog 256err j+SpreadCount-1 } else { if (rand() % k > m) crrf = ColorMap2COLORREF(d);//dog 256err j+d else crrf = ColorMap2COLORREF(d+1);//dog 256err j+d+1 } SetPixel24(ssl, crrf); } } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); delete Mask; } END_LOG; return ec; fail : if (undosw) MainImageForm->Undo->RemoveLast(); if (Mask) delete Mask; if (Image->LayerMask) Image->LayerMask->StopScanLine(); if (MainImageForm->WorkArea->Mask) MainImageForm->WorkArea->Mask->StopScanLine(); Image->uBitmap->StopScanLine(); END_LOG; return ec; } //-------------------------------------------------------------------------- void __fastcall TSpreadFillForm::GoSingleSpread() { BEGIN_LOG(""); TPException ec = EC_NONE; TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (!monoItem) { if (LinearSingleSpread() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if (CirculateSingleSpread() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } ::RepaintColor(); Screen->Cursor = cursor; END_LOG; return; fail: Screen->Cursor = cursor; //EXCEPTION_MESSAGE_OK(ec); END_LOG; } //-------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::LinearSingleSpread() { BEGIN_LOG(""); int i, j, x, y, hei, dx, dy; TPException ec = EC_NONE; double st, ct, Theta; TRect rect[2], art; RECT rt, rc, uart; bool sw, undosw = false; Byte *ssl, *mp, *lp, mm; Byte RGB[3][3]; COLORREF crrf; TPoint center, start, o; int WaveLength, tempdeg; double WaveHeight, ratio, r, temprad, tempdouble; double *wh = NULL; short *eLen = NULL, sLen; TPBitmap *Mask = NULL; TPItemImage *Image = MainImageForm->iMainImage; dx = Second.x-First.x; dy = Second.y-First.y; if (dx || dy) Theta = atan2(dy, dx); else Theta = 0; st = sin(Theta); ct = cos(Theta); if (MainImageForm->WorkArea->Mask){ rc = MainImageForm->WorkArea->Range; uart = rc; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { uart = MainImageForm->AutoRep_UndoRect(rc); } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, uart)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = PaletteMakeSpread()) != EC_NONE) goto fail; if (L_IsPtInBitmapRgn(Image->uBitmap->RgnBitmap->Handle, First.y, First.x)) { rect[0] = Rect(rc.left, rc.top, rc.right, rc.bottom); if (!MainImageForm->WorkArea->Mask->StartScanLine()) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } sw = true; for (y=rect[0].Top; yWorkArea->Mask->GetScanLine(y-rect[0].Top); for (x=rect[0].Left; x> 3)) & (0x80 >> ((x - rect[0].Left)& 7))) { o = xyTransfer(x, y, ct, st); if (sw) { rect[1].Left = o.x; rect[1].Right = rect[1].Left; rect[1].Top = o.y; rect[1].Bottom = rect[1].Top; sw = false; } else { if (o.xrect[1].Right) rect[1].Right = o.x; if (o.yrect[1].Bottom) rect[1].Bottom = o.y; } } } } WaveLength = spEditWlength->Value; WaveHeight = spEditWheight->Value / 100.0; center = xyTransfer(First.x, First.y, ct, st); start = xyTransfer(Second.x, Second.y, ct, st); RGB[1][0] = FGColor & 0xFF; RGB[1][1] = (FGColor >> 8) & 0xFF; RGB[1][2] = (FGColor >> 16) & 0xFF; hei = rect[1].Bottom - rect[1].Top; if (hei == 0) hei = 1; eLen = (short *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, hei*sizeof(short)); if (eLen == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y = rect[1].Top; y < rect[1].Bottom; y++) { for (x = rect[1].Right - 1; x >= rect[1].Left; x--) { o = xyTransfer(x, y, ct, -st); if (rect[0].Top <= o.y && rect[0].Bottom > o.y && rect[0].Left <= o.x && rect[0].Right > o.x) { mp = MainImageForm->WorkArea->Mask->GetScanLine(o.y - rect[0].Top); if (*(mp + ((o.x - rect[0].Left)>>3)) & (0x80 >> ((o.x - rect[0].Left)&7))) break; } } eLen[y - rect[1].Top] = x - center.x; } if (eLen[start.y - rect[1].Top]) ratio = double(start.x - center.x) / eLen[start.y - rect[1].Top]; else ratio = double(start.x - center.x); wh = (double *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2*WaveLength*sizeof(double)); if (wh == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (i = 0; i < 2*WaveLength; i++) { wh[i] = WaveHeight * (rand()%1001 - 500) / 1000.0; // -0.005 - 0.5 } if (!Image->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (!Image->LayerMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y = rect[0].Top; y < rect[0].Bottom; y++) { ssl = Image->uBitmap->GetScanLine(y) + 3*rect[0].Left; lp = Image->LayerMask->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(y); for (x = rect[0].Left; x < rect[0].Right; x++, ssl += 3) { RGB[0][0] = ssl[2]; RGB[0][1] = ssl[1]; RGB[0][2] = ssl[0]; if (*(mp + (x >> 3)) & (0x80 >> (x & 7))) { o = xyTransfer(x, y, ct, st); o.x -= center.x; o.y -=rect[1].Top; j = 360 * o.y / hei; // 0 - 360 tempdeg = j * WaveLength / 180; // 0 - 2* WaveLength if (tempdeg >= 2*WaveLength) tempdeg = tempdeg - 1; temprad = WaveLength * j * M_PI / 180; tempdouble = wh[tempdeg] * sin(temprad); // -0.5 - 0.5 if (o.y >= hei) o.y = hei - 1; sLen = eLen[o.y] * ratio * (1.0 + tempdouble); if (o.x >= sLen) { if ((eLen[o.y] - sLen) == 0) r = 0; else r = (double) (o.x - sLen) / (eLen[o.y] - sLen); if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; RGB[2][0] = RGB[0][0] + r*(RGB[1][0] - RGB[0][0]); RGB[2][1] = RGB[0][1] + r*(RGB[1][1] - RGB[0][1]); RGB[2][2] = RGB[0][2] + r*(RGB[1][2] - RGB[0][2]); crrf = RGB(RGB[2][0], RGB[2][1], RGB[2][2]); SetPixel24(ssl, crrf); *(lp + (x>>3)) &= ~(0x80 >> (x&7)); } } } Image->uBitmap->PutScanLine(y); Image->LayerMask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y = rect[0].Top; y < rect[0].Bottom; y++) { ssl = Image->uBitmap->GetScanLine(y) + 3*rect[0].Left; mp = MainImageForm->WorkArea->Mask->GetScanLine(y - rect[0].Top); for (x = rect[0].Left; x < rect[0].Right; x++, ssl += 3) { RGB[0][0] = ssl[2]; RGB[0][1] = ssl[1]; RGB[0][2] = ssl[0]; if (*(mp + ((x - rect[0].Left) >> 3)) & (0x80 >> ((x - rect[0].Left) & 7))) { o = xyTransfer(x, y, ct, st); o.x -= center.x; o.y -= rect[1].Top; j = 360 * o.y / hei; // 0 - 360 tempdeg = j * WaveLength / 180; // 0 - 2* WaveLength if (tempdeg >= 2*WaveLength) tempdeg = tempdeg - 1; temprad = WaveLength * j * M_PI / 180; tempdouble = wh[tempdeg] * sin(temprad); // -0.5 - 0.5 if (o.y >= hei) o.y = hei - 1; sLen = eLen[o.y] * ratio * (1.0 + tempdouble); if (o.x >= sLen) { if ((eLen[o.y] - sLen) == 0) r = 0; else r = (double) (o.x - sLen) / (eLen[o.y] - sLen); if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; RGB[2][0] = RGB[0][0] + r*(RGB[1][0] - RGB[0][0]); RGB[2][1] = RGB[0][1] + r*(RGB[1][1] - RGB[0][1]); RGB[2][2] = RGB[0][2] + r*(RGB[1][2] - RGB[0][2]); crrf = RGB(RGB[2][0], RGB[2][1], RGB[2][2]); SetPixel24(ssl, crrf); } } } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); HeapFree(GetProcessHeap(), 0, wh); HeapFree(GetProcessHeap(), 0, eLen); } else { goto next; } } else { next: if ((Mask = new TPBitmap) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } FillColor = Image->uBitmap->GetPixelColor(First.x, First.y); if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect[0], Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { delete Mask; EXCEPTION_MESSAGE_OK(EC_INCORRECT_POINT); END_LOG; return false; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect[0], Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } art = rect[0]; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { rt = MainImageForm->AutoRep_UndoRect((RECT)rect[0]); art = rt; } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, art)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Mask->Lock(); sw = true; for (y=rect[0].Top; yScanLine(y); for (x=rect[0].Left; x> 3)) & (0x80 >> (x & 7))) { o = xyTransfer(x, y, ct, st); if (sw) { rect[1].Left = o.x; rect[1].Right = rect[1].Left; rect[1].Top = o.y; rect[1].Bottom = rect[1].Top; sw = false; } else { if (o.xrect[1].Right) rect[1].Right = o.x; if (o.yrect[1].Bottom) rect[1].Bottom = o.y; } } } } WaveLength = spEditWlength->Value; WaveHeight = spEditWheight->Value / 100.0; center = xyTransfer(First.x, First.y, ct, st); start = xyTransfer(Second.x, Second.y, ct, st); RGB[0][0] = FillColor & 0xFF; RGB[0][1] = (FillColor >> 8) & 0xFF; RGB[0][2] = (FillColor >> 16) & 0xFF; RGB[1][0] = FGColor & 0xFF; RGB[1][1] = (FGColor >> 8) & 0xFF; RGB[1][2] = (FGColor >> 16) & 0xFF; hei = rect[1].Bottom - rect[1].Top; if (hei == 0) hei = 1; eLen = (short *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, hei*sizeof(short)); if (eLen == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y = rect[1].Top; y < rect[1].Bottom; y++) { for (x = rect[1].Right - 1; x >= rect[1].Left; x--) { o = xyTransfer(x, y, ct, -st); if (rect[0].Top <= o.y && rect[0].Bottom > o.y && rect[0].Left <= o.x && rect[0].Right > o.x) { mp = Mask->ScanLine(o.y); if (*(mp + (o.x>>3)) & (0x80 >> (o.x&7))) break; } } eLen[y - rect[1].Top] = x - center.x; } if (eLen[start.y - rect[1].Top]) ratio = double(start.x - center.x) / eLen[start.y - rect[1].Top]; else ratio = double(start.x - center.x); wh = (double *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2*WaveLength*sizeof(double)); if (wh == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (i = 0; i < 2*WaveLength; i++) { wh[i] = WaveHeight * (rand()%1001 - 500) / 1000.0; // -0.005 - 0.5 } if (!Image->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (!Image->LayerMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y = rect[0].Top; y < rect[0].Bottom; y++) { ssl = Image->uBitmap->GetScanLine(y) + 3*rect[0].Left; lp = Image->LayerMask->GetScanLine(y); for (x = rect[0].Left; x < rect[0].Right; x++, ssl += 3) { mp = Mask->ScanLine(y); if (*(mp + (x >> 3)) & (0x80 >> (x & 7))) { o = xyTransfer(x, y, ct, st); o.x -= center.x; o.y -=rect[1].Top; j = 360 * o.y / hei; // 0 - 360 tempdeg = j * WaveLength / 180; // 0 - 2* WaveLength if (tempdeg >= 2*WaveLength) tempdeg = tempdeg - 1; temprad = WaveLength * j * M_PI / 180; tempdouble = wh[tempdeg] * sin(temprad); // -0.5 - 0.5 if (o.y >= hei) o.y = hei - 1; sLen = eLen[o.y] * ratio * (1.0 + tempdouble); if (o.x >= sLen) { if ((eLen[o.y] - sLen) == 0) r = 0; else r = (double) (o.x - sLen) / (eLen[o.y] - sLen); if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; RGB[2][0] = RGB[0][0] + r*(RGB[1][0] - RGB[0][0]); RGB[2][1] = RGB[0][1] + r*(RGB[1][1] - RGB[0][1]); RGB[2][2] = RGB[0][2] + r*(RGB[1][2] - RGB[0][2]); crrf = RGB(RGB[2][0], RGB[2][1], RGB[2][2]); SetPixel24(ssl, crrf); *(lp + (x>>3)) &= ~(0x80 >> (x&7)); } } } Image->uBitmap->PutScanLine(y); Image->LayerMask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y = rect[0].Top; y < rect[0].Bottom; y++) { ssl = Image->uBitmap->GetScanLine(y) + 3*rect[0].Left; for (x = rect[0].Left; x < rect[0].Right; x++, ssl += 3) { mp = Mask->ScanLine(y); if (*(mp + (x >> 3)) & (0x80 >> (x & 7))) { o = xyTransfer(x, y, ct, st); o.x -= center.x; o.y -= rect[1].Top; j = 360 * o.y / hei; // 0 - 360 tempdeg = j * WaveLength / 180; // 0 - 2* WaveLength if (tempdeg >= 2*WaveLength) tempdeg = tempdeg - 1; temprad = WaveLength * j * M_PI / 180; tempdouble = wh[tempdeg] * sin(temprad); // -0.5 - 0.5 if (o.y >= hei) o.y = hei - 1; sLen = eLen[o.y] * ratio * (1.0 + tempdouble); if (o.x >= sLen) { if ((eLen[o.y] - sLen) == 0) r = 0; else r = (double) (o.x - sLen) / (eLen[o.y] - sLen); if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; RGB[2][0] = RGB[0][0] + r*(RGB[1][0] - RGB[0][0]); RGB[2][1] = RGB[0][1] + r*(RGB[1][1] - RGB[0][1]); RGB[2][2] = RGB[0][2] + r*(RGB[1][2] - RGB[0][2]); crrf = RGB(RGB[2][0], RGB[2][1], RGB[2][2]); SetPixel24(ssl, crrf); } } } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); HeapFree(GetProcessHeap(), 0, wh); HeapFree(GetProcessHeap(), 0, eLen); delete Mask; } END_LOG; return true; fail : if (undosw) MainImageForm->Undo->RemoveLast(); if (Mask) delete Mask; if (Image->LayerMask) Image->LayerMask->StopScanLine(); Image->uBitmap->StopScanLine(); if (wh) HeapFree(GetProcessHeap(), 0, wh); if (eLen) HeapFree(GetProcessHeap(), 0, eLen); if (ec == EC_NONE) ec = EC_MEMORY_LACK; EXCEPTION_MESSAGE_OK(ec); END_LOG; return false; } //-------------------------------------------------------------------------- double __fastcall TSpreadFillForm::max_process(TRect rect, TPoint center, double i, TPBitmap *mask) { BEGIN_LOG(""); int j; double a; TPoint p, l; Byte *mp; if (i > 45.0 && i < 135.0){ a = tan((90-i)*M_PI/180); for (p.y=rect.Bottom; p.y>=center.y; p.y--) { p.x = center.x+(p.y-center.y)*a; if (p.y >= mask->Height) p.y = mask->Height-1; if (p.y < 0) p.y = 0; mp = mask->ScanLine(p.y); if (*(mp + (p.x >> 3)) & (0x80 >> (p.x & 7))) break; } } else if (i >= 135.0 && i <= 225.0) { a = tan((i-180)*M_PI/180); for (p.x=rect.Left; p.x<=center.x; p.x++) { p.y = center.y+(p.x-center.x)*a; if (p.y >= mask->Height) p.y = mask->Height-1; if (p.y < 0) p.y = 0; mp = mask->ScanLine(p.y); if (*(mp + (p.x >> 3)) & (0x80 >> (p.x & 7))) break; } } else if (i > 225.0 && i < 315.0) { a = tan((270-i)*M_PI/180); for (p.y=rect.Top; p.y<=center.y; p.y++) { p.x = center.x+(p.y-center.y)*a; if (p.y >= mask->Height) p.y = mask->Height-1; if (p.y < 0) p.y = 0; mp = mask->ScanLine(p.y); if (*(mp + (p.x >> 3)) & (0x80 >> (p.x & 7))) break; } } else { a = tan(i*M_PI/180); for (p.x=rect.Right; p.x>=center.x; p.x--) { p.y = center.y+(p.x-center.x)*a; if (p.y >= mask->Height) p.y = mask->Height-1; if (p.y < 0) p.y = 0; mp = mask->ScanLine(p.y); if (*(mp + (p.x >> 3)) & (0x80 >> (p.x & 7))) break; } } l.x = p.x-center.x; l.y = p.y-center.y; END_LOG; return sqrt((double)l.x*l.x + l.y*l.y); } //------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::CirculateSingleSpread() { BEGIN_LOG(""); int i, j, x, y, n; TRect rect, art; RECT rt; Byte *ssl, *mp, *lp; double sLen, cLen, ratio, r, t, theta; COLORREF crrf; Byte RGB[3][3]; TPoint lxy; bool undosw = false; double *wh = NULL, *eLen = NULL; int WaveLength, tempdeg; double WaveHeight, temprad, tempdouble; TPBitmap *Mask = NULL; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; if((Mask = new TPBitmap) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } FillColor = Image->uBitmap->GetPixelColor(First.x, First.y); if (MainImageForm->AutoRepeat && sbAutoRep->Down && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { art = Rect(MainImageForm->arwindow.s.x, MainImageForm->arwindow.s.y, MainImageForm->arwindow.e.x, MainImageForm->arwindow.e.y); if ((First.x >= art.Left) && (First.x < art.Right) && (First.y >= art.Top) && (First.y < art.Bottom)) { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if(Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect, Mask, &art) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { delete Mask; EXCEPTION_MESSAGE_OK(EC_INCORRECT_POINT); END_LOG; return false; } } else { if (Image->LayerMask) { if (Image->LayerMask->GetPixelColor(First.x, First.y)) { if(Image->FloodFillMask(First, FillSingle_layer24_nonezero, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } else { if(Image->FloodFillMask(First, FillSingle_layer24_zero, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } else { if (Image->uBitmap->FloodFillMask(First, FillSingle_none24, NULL, rect, Mask) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } } art = rect; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { rt = MainImageForm->AutoRep_UndoRect((RECT)rect); art = rt; } if ((undosw = MainImageForm->UndoSave(UK_PATTERN, art)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Mask->Lock(); WaveLength = spEditWlength->Value; WaveHeight = spEditWheight->Value / 100.0; RGB[0][0] = FillColor & 0xFF; RGB[0][1] = (FillColor >> 8) & 0xFF; RGB[0][2] = (FillColor >> 16) & 0xFF; RGB[1][0] = FGColor & 0xFF; RGB[1][1] = (FGColor >> 8) & 0xFF; RGB[1][2] = (FGColor >> 16) & 0xFF; lxy.x = max(First.x - rect.Left + 1, rect.Right - First.x + 1); lxy.y = max(First.y - rect.Top + 1, rect.Bottom - First.y + 1); i = 8*max(lxy.x, lxy.y); n = 90; while (i > n) n <<= 1; t = n / 360.0; eLen = (double *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, n*sizeof(double)); if (eLen == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (i = 0; i < n; i++) eLen[i] = max_process(rect, First, i/t, Mask); lxy.x = Second.x - First.x; lxy.y = Second.y - First.y; if (lxy.x) { theta = atan2(lxy.y, lxy.x) / M_PI; if (theta < 0.0) theta += 2.0; j = 180 * theta; } else { if (lxy.y) j = lxy.y < 0 ? 270: 90; else j = 0; } sLen = sqrt(lxy.x * lxy.x + lxy.y * lxy.y); i = j * t; if (i >= n) i = n - 1; if (eLen[i] == 0) ratio = sLen; else ratio = sLen / eLen[i]; wh = (double *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2*WaveLength*sizeof(double)); if (wh == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (i = 0; i < 2*WaveLength; i++) { wh[i] = WaveHeight * (rand() % 1001 - 500) / 1000.0; } if (!Image->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Image->LayerMask) { if (!Image->LayerMask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y = rect.Top; y < rect.Bottom; y++) { ssl = Image->uBitmap->GetScanLine(y) + 3*rect.Left; lp = Image->LayerMask->GetScanLine(y); for (x = rect.Left; x < rect.Right; x++, ssl += 3) { mp = Mask->ScanLine(y); if (*(mp + (x >> 3)) & (0x80 >> (x & 7))) { lxy.x = x - First.x; lxy.y = y - First.y; if (lxy.x) { theta = atan2(lxy.y, lxy.x) / M_PI; if (theta < 0.0) theta += 2.0; j = 180 * theta; } else { if (lxy.y) j = lxy.y < 0 ? 270: 90; else j = 0; } cLen = sqrt (lxy.x * lxy.x + lxy.y * lxy.y); tempdeg = j * WaveLength / 180; // 0 - 2* WaveLength if (tempdeg == 2*WaveLength) tempdeg = tempdeg - 1; temprad = WaveLength * j * M_PI / 180; tempdouble = wh[tempdeg] * sin(temprad); // -0.5 - 0.5 i = j * t; if (i >= n) i = n - 1; sLen = eLen[i] * ratio * (1.0 + tempdouble); if (cLen >= sLen) { if ((eLen[i] - sLen) == 0) r = 0; else r = (cLen - sLen) / (eLen[i] - sLen); if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; RGB[2][0] = RGB[0][0] + r*(RGB[1][0] - RGB[0][0]); RGB[2][1] = RGB[0][1] + r*(RGB[1][1] - RGB[0][1]); RGB[2][2] = RGB[0][2] + r*(RGB[1][2] - RGB[0][2]); crrf = RGB(RGB[2][0], RGB[2][1], RGB[2][2]); SetPixel24(ssl, crrf); *(lp + (x>>3)) &= ~(0x80 >> (x&7)); } } } Image->uBitmap->PutScanLine(y); Image->LayerMask->PutScanLine(y); } Image->LayerMask->StopScanLine(); } else { for (y = rect.Top; y < rect.Bottom; y++) { ssl = Image->uBitmap->GetScanLine(y) + 3*rect.Left; for (x = rect.Left; x < rect.Right; x++, ssl += 3) { mp = Mask->ScanLine(y); if (*(mp + (x >> 3)) & (0x80 >> (x & 7))) { lxy.x = x - First.x; lxy.y = y - First.y; if (lxy.x) { theta = atan2(lxy.y, lxy.x) / M_PI; if (theta < 0.0) theta += 2.0; j = 180 * theta; } else { if (lxy.y) j = lxy.y < 0 ? 270: 90; else j = 0; } cLen = sqrt (lxy.x * lxy.x + lxy.y * lxy.y); tempdeg = j * WaveLength / 180; // 0 - 2* WaveLength if (tempdeg == 2*WaveLength) tempdeg = tempdeg - 1; temprad = WaveLength * j * M_PI / 180; tempdouble = wh[tempdeg] * sin(temprad); // -0.5 - 0.5 i = j * t; if (i >= n) i = n - 1; sLen = eLen[i] * ratio * (1.0 + tempdouble); if (cLen >= sLen) { if ((eLen[i] - sLen) == 0) r = 0; else r = (cLen - sLen) / (eLen[i] - sLen); if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; RGB[2][0] = RGB[0][0] + r*(RGB[1][0] - RGB[0][0]); RGB[2][1] = RGB[0][1] + r*(RGB[1][1] - RGB[0][1]); RGB[2][2] = RGB[0][2] + r*(RGB[1][2] - RGB[0][2]); crrf = RGB(RGB[2][0], RGB[2][1], RGB[2][2]); SetPixel24(ssl, crrf); } } } Image->uBitmap->PutScanLine(y); } } Image->uBitmap->StopScanLine(); HeapFree(GetProcessHeap(), 0, wh); HeapFree(GetProcessHeap(), 0, eLen); delete Mask; END_LOG; return true; fail : if (undosw) MainImageForm->Undo->RemoveLast(); if(Mask) delete Mask; if (Image->LayerMask) Image->LayerMask->StopScanLine(); Image->uBitmap->StopScanLine(); if(wh) HeapFree(GetProcessHeap(), 0, wh); if(eLen) HeapFree(GetProcessHeap(), 0, eLen); EXCEPTION_MESSAGE_OK(ec); END_LOG; return false; } //------------------------------/Public Method/------------------------------ void __fastcall TSpreadFillForm::InitForm() { BEGIN_LOG(""); int i, SingleSpread, fgcol, s_item, max; TIniFile* SpIni = NULL; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //ParentHeight = Parent->Height+20; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { Bpp24 = false; rzcbSelectColor->Visible = true; rzpn256->BringToFront(); rzmtbtSingleLinear->Visible = false; rzmtbtSingleCirculate->Visible = false; } else { Bpp24 = true; rzcbSelectColor->Visible = false; rzmtbtSingleLinear->Visible = true; rzmtbtSingleCirculate->Visible = true; rzpnFull->BringToFront(); } ColorSelector->SetPalette(MainImageForm->Palette); step = 0; for (i=0; i<5; i++) { ColorIndex[i] = 1; if (i<4) Gap[i] = 1; } SpreadColor = NULL; bChange = true; pal = false; TrackBar->Max = 2; ////////// Multi Spread Init........ SpIni = new TIniFile(AppDataItem+"\\SpreadFill.ini"); if (SpIni) { Item = SpIni->ReadInteger("DrawType", "Type", 0); TrackBar->Max = SpIni->ReadInteger("TrackBar", "Max", 2); if (TrackBar->Max < 2) TrackBar->Max = 2; //UpDown->Position = SpIni->ReadInteger("UpDown", "Pos", 2); max = 0; //for (i=0; i<=TrackBar->Max; i++) { for (i=0; iMax; i++) { String str = Format("%d", OPENARRAY(TVarRec, (i))); if (i < 4) Gap[i] = SpIni->ReadInteger("Gap", str, 1); ColorIndex[i] = SpIni->ReadInteger("Color", str, 1); if (max < ColorIndex[i]) max = ColorIndex[i]; } if (EnoughPalette() == false) { for (i=0; i < TrackBar->Max; i++) { if (i < 4) Gap[i] = 1; } } SingleSpread = SpIni->ReadInteger("Single", "Single", 0); fgcol = SpIni->ReadInteger("Single", "Foreground", 2); s_item = SpIni->ReadInteger("Single", "monoItem", 0); delete SpIni; } TrackBar->Position = 0; TrackBarChange(TrackBar); //SpeedButtonPosition->Down = false; if(SingleSpread && Bpp24) { PaletteForm->DIB256Palette->ChoiceIndex = fgcol; //sbSingle->Down = true; //sbSingleClick(sbSingle); monoItem = s_item; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { sbAutoRep->Enabled = true; } InitItem(Item); END_LOG; return; } InitItem(Item); HVmode = false; ClientHeight = expandSize; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //Parent->Height = ParentHeight+ClientHeight; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::ExitForm() { BEGIN_LOG(""); int max, i; String str; TIniFile* SpIni = NULL; if(step > 0){ MainImageForm->iMainImage->OnPaintLocate = NULL; step = 0; } if (SpreadColor) { HeapFree(GetProcessHeap(), 0, SpreadColor); SpreadColor = NULL; } if (IsDraw) MainImageForm->iMainImage->Repaint(); SpIni = new TIniFile(AppDataItem+"\\SpreadFill.ini"); if (SpIni) { max = SpIni->ReadInteger("TrackBar", "Max", 0); if (TrackBar->Max-1 < max) { for (i=TrackBar->Max-1; iDeleteKey("Gap", str); SpIni->DeleteKey("Color", str); } } SpIni->WriteInteger("DrawType", "Type", Item); SpIni->WriteInteger("TrackBar", "Max", TrackBar->Max); for (i=0; iMax; i++) { String str = Format("%d", OPENARRAY(TVarRec, (i))); if (i < 4) SpIni->WriteInteger("Gap", str, Gap[i]); SpIni->WriteInteger("Color", str, ColorIndex[i]); } if (rzmtbtSingleLinear->Down || rzmtbtSingleCirculate->Down) SpIni->WriteInteger("Single", "Single", 1); else SpIni->WriteInteger("Single", "Single", 0); SpIni->WriteInteger("Single", "Foreground", PaletteForm->DIB256Palette->ChoiceIndex); SpIni->WriteInteger("Single", "monoItem", monoItem); delete SpIni; } ColorSelector->SaveToFile(AppDataItem + "\\SpreadFill.Ini", "ColorSelect"); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); TRect r; Byte *scan; int ix, iy; TPException ec = EC_NONE; HVmode = false; TPItemImage *MainImage = (TPItemImage *) Sender; if (!Shift.Contains(ssShift) && Button==mbLeft) { if (!bColor) { if (step>0) { Second = Point(X, Y); MainImageForm->DrawLineLocate(First, Second); IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo step = 0; if (!mono) GoSpreadFill(); else GoSingleSpread(); if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) MainImageForm->RedrawingRepeat(false, true); } else { First = Point(X, Y); Second = First; MainImageForm->DrawLineLocate(First, Second); IsDraw = true; step = 1; } } } else if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { if (bColor) { if (SpeedButtonOne->Down) { if (SpeedButtonDelete->Down) { ColorSelector->DeleteColor(MainImageForm->iMainImage->uBitmap->GetPixelColor(X, Y)); } else { ColorSelector->AddColor(MainImageForm->iMainImage->uBitmap->GetPixelColor(X, Y)); } } 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() == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (SpeedButtonDelete->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 = 11; } } } else { if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8){ FGChange(MainImageForm->iMainImage->uBitmap->GetPixelColor(X, Y)); } else { // º¯°æµÈ »öÀ» Àû¿ë½ÃÅ´. bChange = true; pal = true; View(); } } } END_LOG; return; fail : MainImage->uBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::iMainImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (!bColor){ //if (SpeedButtonPosition->Down) { if (step>0) { if (IsDraw) MainImageForm->DrawLineLocate(First, Second); if ( HVmode == 1){ int delta_x,delta_y; delta_x = X - First.x; delta_y = Y - First.y; if(delta_x<0) delta_x = -delta_x; if(delta_y<0) delta_y = -delta_y; if(delta_xDrawLineLocate(First, Second); IsDraw = true; } } else { if (bColor) { if (SpeedButtonOne->Down==false) { if (step>0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } } } } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::iMainImagePaint() { IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::FGChange(int Value) { BEGIN_LOG(""); if (!mono) { if (EnoughPalette()){ ColorIndex[TrackBar->Position] = Value; if (TrackBar->Position < TrackBar->Max) { TrackBar->Position++; } else { if (TrackBar->Max < 5 && TrackBar->Position == TrackBar->Max){ TrackBar->Max++; TrackBar->Position++; } else { TrackBar->Position = 0; } } TrackBarChange(TrackBar); bChange = true; pal = true; View(); } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { FGColor = PaletteForm->DIB256Palette->GetFGCOLORREF(24); ImageView->Canvas->Brush->Color = (TColor)FGColor; ImageView->Canvas->FillRect(Rect(0, 0, ImageView->Width, ImageView->Height)); } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TSpreadFillForm::EnoughPalette() { if (Bpp24) return true; //dog 256err int i, total = 0; for (i = 0; i < TrackBar->Max-1; i++) total += Gap[i]; if ((MainImageForm->Palette->UseColor+total)>251) { return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::spEditWlengthChange(TObject *Sender) { if (spEditWlength->Text.Length() > 0 ) { if (spEditWlength->Value > spEditWlength->Max) spEditWlength->Value = spEditWlength->Max; else if (spEditWlength->Value < spEditWlength->Min) spEditWlength->Value = spEditWlength->Min; } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::spEditWheightChange(TObject *Sender) { if (spEditWheight->Text.Length() > 0) { if (spEditWheight->Value > spEditWheight->Max) spEditWheight->Value = spEditWheight->Max; else if (spEditWheight->Value < spEditWheight->Min) spEditWheight->Value = spEditWheight->Min; } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::iMainImageKeyDown(WORD Key, TShiftState Shift) { if (Key == 'Z'){ HVmode = true; } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::iMainImageKeyUp(WORD Key) { if (Key == 'Z'){ HVmode = false; } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::rzcbSelectColorClick(TObject *Sender) { if(step > 0){ MainImageForm->iMainImage->OnPaintLocate = NULL; step = 0; ::RepaintImage(); } if (!Bpp24) { if (bColor) { ExitItem(); //rzcbSelectColor->Caption = IDS_READYTODRAW; ColorSelector->Enabled = false; SpeedButtonNew->Enabled = false; SpeedButtonAll->Enabled = false; SpeedButtonOne->Enabled = false; SpeedButtonDelete->Enabled = false; SpeedButtonBefore->Enabled = false; //SpeedButtonPosition->Enabled = true; bColor = false; } else { //rzcbSelectColor->Caption = IDS_COLORSELECT; ColorSelector->Enabled = true; SpeedButtonNew->Enabled = true; SpeedButtonAll->Enabled = true; SpeedButtonOne->Enabled = true; SpeedButtonDelete->Enabled = true; SpeedButtonBefore->Enabled = true; //SpeedButtonPosition->Down = false; //SpeedButtonPosition->Enabled = false; bColor = true; } } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::sbAutoRepClick(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::rzmtbtCirculateClick(TObject *Sender) { rzpnGrade->Enabled = true; if (Bpp24){ rzpnFull->Enabled = false; } ExitItem(); mono = false; InitItem(1); ClientHeight = expandSize; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::rzmtbtLinearClick(TObject *Sender) { rzpnGrade->Enabled = true; if (Bpp24){ rzpnFull->Enabled = false; } ExitItem(); mono = false; InitItem(0); ClientHeight = expandSize; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::ImageGrade2MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { SelectIndex = 0; if (X > 0){ SelectIndex = X / (ImageGrade2->Width / TrackBar->Max); } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::miDeleteClick(TObject *Sender) { if (TrackBar->Max > 2){ for (int i = SelectIndex; i < TrackBar->Max-1; i++){ ColorIndex[i] = ColorIndex[i+1]; } TrackBar->Max--; View(); } } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::miDeleteAllClick(TObject *Sender) { TrackBar->Max = 2; ColorIndex[0] = 1; ColorIndex[1] = 1; TrackBar->Position = 0; View(); } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::rzmtbtSingleCirculateClick(TObject *Sender) { rzpnGrade->Enabled = false; if(step > 0){ MainImageForm->iMainImage->OnPaintLocate = NULL; step = 0; ::RepaintImage(); } mono = true; monoItem = 1; Item = 3; FGColor = PaletteForm->DIB256Palette->GetFGCOLORREF(24); ImageView->Canvas->Brush->Color = (TColor)FGColor; ImageView->Canvas->FillRect(Rect(0, 0, ImageView->Width, ImageView->Height)); ImageView->Hint = IDS_CIRCULATE; rzpnFull->Enabled = true; ClientHeight = poldingSize; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::rzmtbtSingleLinearClick(TObject *Sender) { rzpnGrade->Enabled = true; if(step > 0){ MainImageForm->iMainImage->OnPaintLocate = NULL; step = 0; ::RepaintImage(); } mono = true; monoItem = 0; Item = 2; FGColor = PaletteForm->DIB256Palette->GetFGCOLORREF(24); ImageView->Canvas->Brush->Color = (TColor)FGColor; ImageView->Canvas->FillRect(Rect(0, 0, ImageView->Width, ImageView->Height)); ImageView->Hint = IDS_LINEAR; //SpeedButtonPosition->Down = true; rzpnFull->Enabled = true; ClientHeight = poldingSize; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TSpreadFillForm::PopupGradePopup(TObject *Sender) { if (TrackBar->Max > 2) { miDelete->Enabled = true; miDeleteAll->Enabled = true; } else { miDelete->Enabled = false; miDeleteAll->Enabled = false; } } //---------------------------------------------------------------------------