//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "PatternRepeat.h" #include "FullView.h" #include "MainImage.h" #include "Palette.h" #include "PenManager.h" #include "StatusProgress.h" #include "Undo.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_REGULAR StringTable[0] #define IDS_IRREGULAR StringTable[1] #define IDS_IMAGESPRAY StringTable[2] #define IDS_REGULAR1 StringTable[3] #define IDS_SELECTPOS StringTable[4] #define IDS_MIRROR StringTable[5] #define IDS_UPDOWN StringTable[6] #define IDS_MUPDOWN StringTable[7] #define IDS_IMAGESPRAY2 StringTable[8] #define IDS_IRREGULAR3 StringTable[9] //--------------------------------------------------------------------------- TPatternRepeatForm *PatternRepeatForm; //--------------------------------------------------------------------------- __fastcall TPatternRepeatForm::TPatternRepeatForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //=========================================================== StringTable.Create(DirectoryBin, Language, "PatternRepeat"); SetSmallFont(Font); SetSmallFont(Label4->Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label->Font); SetSmallFont(LabelUnit->Font); sbRegular->Caption = IDS_REGULAR; sbIrregular->Caption = IDS_IRREGULAR; sbImgSpray->Caption = IDS_IMAGESPRAY; Label2->Caption = IDS_REGULAR1; sbSelectPos->Caption = IDS_SELECTPOS; Label1->Caption = IDS_COMMON_DIRECTION; ComboDirection->Items->Clear(); ComboDirection->Items->Add(IDS_COMMON_NORMAL); ComboDirection->Items->Add(IDS_MIRROR); ComboDirection->Items->Add(IDS_UPDOWN); ComboDirection->Items->Add(IDS_MUPDOWN); Label->Caption = IDS_IMAGESPRAY2; LabelUnit->Caption = "CM"; Label4->Caption = IDS_IRREGULAR3; //=========================================================== } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::EditDotClick(TObject *Sender) { EditDot->SetFocus(); EditDot->SelectAll(); } //--------------------------------------------------------------------------- //// PRIVATE METHOD /////////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::InitData() { POINT *p = NULL; if (pstore) { while (pstore->Count>0) { p = (POINT *) pstore->Last(); pstore->Remove(p); if (p) { delete p; p = NULL; } } } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::EraseLine() { POINT *p, *temp, pre; temp = (POINT *) pstore->Items[0]; pre = *temp; for (int i = 1; i < pstore->Count; i++) { p = (POINT *) pstore->Items[i]; MainImageForm->DrawLineLocate(pre, *p); pre = *p; } } //--------------------------------------------------------------------------- double __fastcall calculatelength(POINT sp, POINT ep) { int x, y; x = ep.x - sp.x; y = ep.y - sp.y; return sqrt (x*x + y*y); } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageSpray() { POINT *sp, *ep, pre, drawpoint, temp; double rad, len; int a, dx, dy; bool first; TCursor old = Screen->Cursor; Screen->Cursor = crHourGlass; if (pstore->Count>0) { sumlength = 0; a = 0; len = 0; rad = 0; sp = (POINT *) pstore->Items[0]; pre = *sp; drawpoint = pre; StatusProgress->Maximum = pstore->Count - 1; for (int i = 1; i < pstore->Count; i++) { StatusProgress->Position = i; ep = (POINT *) pstore->Items[i]; len = calculatelength(pre, *ep); sumlength += len; first = true; while (sumlength > Limit) { dx = ep->x - pre.x; dy = ep->y - pre.y; if (dx || dy) rad = atan2(dy, dx); else rad = 0; if (first) { a = Limit - (sumlength - len); } else { a = Limit; } temp.x = a * cos(rad) + pre.x; temp.y = a * sin(rad) + pre.y; /* dx = temp.x - drawpoint.x; dy = temp.y - drawpoint.y; if (dx || dy) { rad = atan2(dy, dx); deg = 18000*rad / M_PI; //for RotateBitmapFine (pai / 180000) if (deg<0) deg = 35999 + deg; } else { deg = 0; } DrawImage(drawpoint, deg); */ PutImage(temp, drawpoint); if (first) { sumlength = len - a; } else { sumlength = sumlength - Limit; } pre = temp; drawpoint = temp; first = false; } pre = *ep; } PutImage(pre, drawpoint); StatusProgress->End(); ::RepaintColor(); } Screen->Cursor = old; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::PutImage(POINT sp, POINT ep) { int dx, dy, deg; double rad; dx = sp.x - ep.x; dy = sp.y - ep.y; if (dx || dy) { rad = atan2(dy, dx); deg = 18000*rad / M_PI; //for RotateBitmapFine (pai / 180000) if (deg<0) deg = 35999 + deg; } else { deg = 0; } DrawImage(ep, deg); } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::DrawImage(POINT sp, int deg) { POINT fp; //fix point Byte *sl, *mp, mm; int x, y; COLORREF crrf; // Mask ¸¸µé±â if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (TempBitmap->Create(FSize.x, FSize.y, 8, rgb) == false) goto fail; TempBitmap->Copy(sBitmap, SRCCOPY); if (deg) { if (!TempBitmap->Rotate(deg, true, PALETTEINDEX(0))) goto fail; } if (sMask->Create(TempBitmap->Width, TempBitmap->Height, 8) == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (sMask->Lock() == NULL) goto fail; for (y = 0; y < TempBitmap->Height; y++) { sl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if (*(sl + x) == 0) { *(mp + x) = 0; } else *(mp + x) = 0xFF; } } sMask->Unlock(); TempBitmap->StopScanLine(); } else { if (TempBitmap->Create(FSize.x, FSize.y, 24) == false) goto fail; TempBitmap->Copy(sBitmap, SRCCOPY); if (deg) { if (!TempBitmap->Rotate(deg, true, FillColor)) goto fail; } if (sMask->Create(TempBitmap->Width, TempBitmap->Height, 1) == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (sMask->Lock() == NULL) goto fail; for (y = 0; y < TempBitmap->Height; y++) { sl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); *mp = 0; mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, sl += 3) { GetPixel24(sl, crrf); if (crrf != FillColor) { *mp |= mm; } if (mm == 1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } } sMask->Unlock(); TempBitmap->StopScanLine(); } fp.x = sp.x - TempBitmap->Width / 2; fp.y = sp.y - TempBitmap->Height / 2; // ½ÇÁ¦ ±×¸®±â.... switch (FullViewForm->Super) { case sOff: ImageOffDrawing(fp.x, fp.y); break; case sNormal: ImageNormalDrawing(fp.x, fp.y); break; case sGauze: ImageGauzeDrawing(fp.x, fp.y); break; case sOverlap: if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) ImageGauzeDrawing(fp.x, fp.y); else ImageOverLapDrawing(fp.x, fp.y); break; } TempBitmap->Destroy(); return; fail : sMask->Destroy(); TempBitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageOffDrawing(int sx, int sy) { int x, y; Byte *ssl, *dsl, *mp, mm, *mml; COLORREF crrf; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; if (Bitmap->StartScanLine() == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (sMask->Lock() == NULL) goto fail; if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (MainImageForm->Palette->ColorData[dsl[sx+x]]->Protect==0 && (mml[sx + x] == 0)) if (mp[x]) dsl[sx+x] = ssl[x]; } } Bitmap->PutScanLine(sy+y); } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (mml[sx + x] == 0) { if (mp[x]) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { if ((mml[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0) { if (*mp & mm) { GetPixel24(ssl, crrf); SetPixel24(dsl, crrf); } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } Mask->StopScanLine(); } else { if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (MainImageForm->Palette->ColorData[dsl[sx+x]]->Protect==0) { if (mp[x]) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) if (mp[x]) dsl[sx+x] = ssl[x]; } Bitmap->PutScanLine(sy+y); } } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { if (*mp & mm) { GetPixel24(ssl, crrf); SetPixel24(dsl, crrf); } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } } sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); return; fail : Mask->StopScanLine(); sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageNormalDrawing(int sx, int sy) { int x, y; Byte *ssl, *dsl, *mp, mm, *mml; COLORREF crrf, dc; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; if (Bitmap->StartScanLine() == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (sMask->Lock() == NULL) goto fail; if (MainImageForm->MaskArea) { if(Mask->StartScanLine() == false) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (MainImageForm->Palette->ColorData[dsl[sx+x]]->Protect==0 && (mml[sx + x] == 0)) { if (mp[x] && (ssl[x] != 1)) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (mml[sx + x] == 0) { if (mp[x] && (ssl[x] != 1)) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } } else { dc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { if ((mml[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0) { if (*mp & mm) { GetPixel24(ssl, crrf); if (crrf != dc) SetPixel24(dsl, crrf); } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } Mask->StopScanLine(); } else { if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (MainImageForm->Palette->ColorData[dsl[sx+x]]->Protect==0) { if (mp[x] && (ssl[x] != 1)) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) if (mp[x] && (ssl[x] != 1)) dsl[sx+x] = ssl[x]; } Bitmap->PutScanLine(sy+y); } } } } else { dc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { if (*mp & mm) { GetPixel24(ssl, crrf); if (crrf != dc) SetPixel24(dsl, crrf); } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } } sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); return; fail : Mask->StopScanLine(); sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageGauzeDrawing(int sx, int sy) { int x, y; Byte *ssl, *dsl, *mp, mm, *mml; COLORREF crrf, bgc; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; if (Bitmap->StartScanLine() == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (sMask->Lock() == NULL) goto fail; if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (MainImageForm->Palette->ColorData[dsl[sx+x]]->Protect==0 && (mml[sx + x] == 0) && (ssl[x] != 1)) { if (mp[x]) if ((x + y) & 1) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (mml[sx + x] == 0 && (ssl[x] != 1)) { if (mp[x]) if ((x + y) & 1) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { GetPixel24(ssl, crrf); if ((mml[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0 && (crrf != bgc)) { if (*mp & mm) { if ((x + y) & 1) { SetPixel24(dsl, crrf); } } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } Mask->StopScanLine(); } else { if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) { if (MainImageForm->Palette->ColorData[dsl[sx+x]]->Protect==0 && (ssl[x] != 1)) { if (mp[x]) if ((x + y) & 1) dsl[sx+x] = ssl[x]; } } } Bitmap->PutScanLine(sy+y); } } } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); for (x = 0; x < TempBitmap->Width; x++) { if ((sx + x) >=0 && (sx+x) < Bitmap->Width) if (mp[x] && ssl[x] != 1) if ((x + y) & 1) dsl[sx+x] = ssl[x]; } Bitmap->PutScanLine(sy+y); } } } } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { GetPixel24(ssl, crrf); if (crrf != bgc) { if (*mp & mm) { if ((x + y) & 1) { SetPixel24(dsl, crrf); } } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } } sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); return; fail : Mask->StopScanLine(); sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageOverLapDrawing(int sx, int sy) { int x, y; Byte *ssl, *dsl, *mp, mm, *mml; COLORREF color, crr1, crr2, bgc; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (Bitmap->StartScanLine() == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (sMask->Lock() == NULL) goto fail; MainImageForm->InitOverlap(); if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; mml = Mask->GetScanLine(sy+y); ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { GetPixel24(ssl, crr1); if ((mml[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0 && (crr1 != bgc)) { if (*mp & mm) { GetPixel24(dsl, crr2); color = MainImageForm->Overlap(crr2, crr1); SetPixel24(dsl, color); } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } Mask->StopScanLine(); } else { for (y = 0; y < TempBitmap->Height; y++) { if ((sy + y) >=0 && (sy + y) < Bitmap->Height) { dsl = Bitmap->GetScanLine(sy+y) + 3*sx; ssl = TempBitmap->GetScanLine(y); mp = sMask->ScanLine(y); mm = 0x80; for (x = 0; x < TempBitmap->Width; x++, dsl += 3, ssl += 3) { if ((sx + x) >=0 && (sx + x) < Bitmap->Width) { GetPixel24(ssl, crr1); if (crr1 != bgc) { if (*mp & mm) { GetPixel24(dsl, crr2); color = MainImageForm->Overlap(crr2, crr1); SetPixel24(dsl, color); } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Bitmap->PutScanLine(sy+y); } } } MainImageForm->ExitOverlap(); sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); return; fail : Mask->StopScanLine(); MainImageForm->ExitOverlap(); sMask->Unlock(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::PreviewImageDraw() { TCanvas *cv; PreviewImage->Picture->Bitmap->Width = 110; PreviewImage->Picture->Bitmap->Height = 110; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { PreviewImage->Picture->Bitmap->PixelFormat = pf8bit; SetDIBColorTable(PreviewImage->Picture->Bitmap->Canvas->Handle, 0, 256, rgb); } else { PreviewImage->Picture->Bitmap->PixelFormat = pf24bit; } if ((cv = sBitmap->CreateCanvas()) == NULL) goto fail; PreviewImage->Picture->Bitmap->Canvas->CopyRect(Rect(0, 0, PreviewImage->Picture->Bitmap->Width, PreviewImage->Picture->Bitmap->Height), cv, Rect(0, 0, sBitmap->Width, sBitmap->Height)); sBitmap->DeleteCanvas(cv); PreviewImage->Repaint(); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::convertTemp24() { Byte *ssl, *mp, mm; COLORREF crrf = FillColor; int x, y; if (sBitmap->StartScanLine() == false) goto fail; if (MainImageForm->WorkArea->Mask->StartScanLine() == false) goto fail; for (y = 0; y < sBitmap->Height; y++) { ssl = sBitmap->GetScanLine(y); mp = MainImageForm->WorkArea->Mask->GetScanLine(y); mm = 0x80; for (x = 0; x < sBitmap->Width; x++, ssl += 3) { if ((*mp & mm) == 0) SetPixel24(ssl, crrf); if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } sBitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); sBitmap->StopScanLine(); return; fail : MainImageForm->WorkArea->Mask->StopScanLine(); sBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- COLORREF __fastcall TPatternRepeatForm::SearchFillColor() { int x, y, i, j; Byte *sl; Byte rgb[3][256]; int r, g, b; COLORREF crrf; memset(rgb, 0, 256 * 3); if (sBitmap->StartScanLine() == false) goto fail; for (y = 0; y < sBitmap->Height; y++) { sl = sBitmap->GetScanLine(y); for (x = 0; x < sBitmap->Width; x++, sl += 3) { GetPixel24(sl, crrf); r = crrf & 0x00000011; g = (crrf>>8) & 0x000011; b = (crrf>>16) & 0x0011; rgb[0][r] = 1; rgb[1][g] = 1; rgb[2][b] = 1; } } sBitmap->StopScanLine(); for (i = 0; i < 3; i++) { for (j = 0; j < 256; j++) { if (rgb[i][j] == 0) return 0x00000000 | (j<<(8*i)); } } return 0; fail : sBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return 0; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::set_brush_spread_regular_pattern_pen(int lsx, int lsy, int size, COLORREF color) { int sx, sy, x, y, s, e, pw; Byte *IP = 0, *SP = 0, *MP = 0, *Mdsl = 0, *Tsl = 0, *IMP = 0; int x0, y0; COLORREF dc; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; pw = size; sx = lsx - 14; sy = lsy - 14; s = 13 - pw / 2.0; e = 14 + pw / 2.0; x0 = (sx - FStart.x) % FSize.x; if (x0 < 0) x0 = x0 + FSize.x; y0 = (sy - FStart.y) % FSize.y; if (y0 < 0) y0 = y0 + FSize.y; if (Bitmap->StartScanLine() == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; if (Bitmap->BitsPerPixel == 8) { if (TempMask->StartScanLine() == false) goto fail; if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } TempMask->StopScanLine(); } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && ((IMP[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0)) { Tsl = SP; Tsl += 3*((x0 + x) % FSize.x); GetPixel24(Tsl, dc); if (dc != FillColor) SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } } Mask->StopScanLine(); } else { if (Bitmap->BitsPerPixel == 8) { if (TempMask->StartScanLine() == false) goto fail; if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } TempMask->StopScanLine(); } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) { Tsl = SP; Tsl += 3*((x0 + x) % FSize.x); GetPixel24(Tsl, dc); if (dc != FillColor) SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } } } TempBitmap->StopScanLine(); Bitmap->StopScanLine(); return; fail : Mask->StopScanLine(); TempMask->StopScanLine(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::set_brush_spread_irregular_pattern_pen(int lsx, int lsy, int size, COLORREF color) { int sx, sy, x, y, s, e, pw; Byte *IP = 0, *Mdsl = 0, *SSP = 0, *MP = 0; COLORREF dc; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; pw = size; sx = lsx - 14; sy = lsy - 14; s = 13 - pw / 2.0; e = 14 + pw / 2.0; if (Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; if (Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } } else { if (TempBitmap->StartScanLine() == false) goto fail; for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); MP = Mask->GetScanLine(sy + y); IP = TempBitmap->GetScanLine(random(FSize.y)); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && ((MP[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0)) { SSP = IP; SSP += 3*random(FSize.x); GetPixel24(SSP, dc); SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } TempBitmap->StopScanLine(); } Mask->StopScanLine(); } else { if (Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } } else { if (TempBitmap->StartScanLine() == false) goto fail; for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); IP = TempBitmap->GetScanLine(random(FSize.y)); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) { SSP = IP; SSP += 3*random(FSize.x); GetPixel24(SSP, dc); SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } TempBitmap->StopScanLine(); } } Bitmap->StopScanLine(); return; fail : TempBitmap->StopScanLine(); Mask->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::set_crayon_brush_spread_regular_pattern_pen(int lsx, int lsy, int size, COLORREF color) { int s, e, sx, sy, x, y, pw, p; Byte *IP = 0, *SP = 0, *MP = 0, *Mdsl = 0, *Tsl = 0, *IMP = 0; int ran; int x0, y0; COLORREF dc; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; pw = size; sx = lsx - 14; sy = lsy - 14; s = 13 - pw / 2.0; e = 14 + pw / 2.0; if (pw <= 0) p = 1; else p = pw; if (PenManagerForm->density == 1) { ran = 5000 / p; } else if (PenManagerForm->density == 2) { ran = 12000 / p; } else if (PenManagerForm->density == 3) { ran = 18000 / p; } else if (PenManagerForm->density == 4) { ran = 24000 / p; } else { ran = 30000 / p; } x0 = (sx - FStart.x) % FSize.x; if (x0 < 0) x0 = x0 + FSize.x; y0 = (sy - FStart.y) % FSize.y; if (y0 < 0) y0 = y0 + FSize.y; if (Bitmap->StartScanLine() == false) goto fail; if (TempBitmap->StartScanLine() == false) goto fail; if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; if (Bitmap->BitsPerPixel ==8) { if (TempMask->StartScanLine() == false) goto fail; if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (IMP[sx + x] == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } TempMask->StopScanLine(); } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); IMP = Mask->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && (rand() < ran) && ((IMP[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0)) { Tsl = SP; Tsl += 3*((x0 + x) % FSize.x); GetPixel24(Tsl, dc); if (dc != FillColor) SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } } Mask->StopScanLine(); } else { if (Bitmap->BitsPerPixel ==8) { if (TempMask->StartScanLine() == false) goto fail; if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); MP = TempMask->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran)) { if (MP[(x0 + x) % FSize.x]) IP[sx + x] = SP[(x0 + x) % FSize.x]; } } } Bitmap->PutScanLine(sy + y); } } } } TempMask->StopScanLine(); } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); SP = TempBitmap->GetScanLine((y0 + y) % FSize.y); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && (rand() < ran)) { Tsl = SP; Tsl += 3*((x0 + x) % FSize.x); GetPixel24(Tsl, dc); if (dc != FillColor) SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } } } TempBitmap->StopScanLine(); Bitmap->StopScanLine(); return; fail : TempMask->StopScanLine(); Mask->StopScanLine(); TempBitmap->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::set_crayon_brush_spread_irregular_pattern_pen(int lsx, int lsy, int size, COLORREF color) { int s, e, sx, sy, x, y, pw, p; Byte *IP = 0, *Mdsl = 0, *SSP = 0, *MP = 0; COLORREF dc; int ran; TTexpiaBitmap *Bitmap = MainImageForm->iMainImage->Bitmap; TTexpiaBitmap *Mask = MainImageForm->iMainImage->Mask; pw = size; sx = lsx - 14; sy = lsy - 14; s = 13 - pw / 2.0; e = 14 + pw / 2.0; if (pw <= 0) p = 1; else p = pw; if (PenManagerForm->density == 1) { ran = 5000 / p; } else if (PenManagerForm->density == 2) { ran = 12000 / p; } else if (PenManagerForm->density == 3) { ran = 18000 / p; } else if (PenManagerForm->density == 4) { ran = 24000 / p; } else { ran = 30000 / p; } if (Bitmap->StartScanLine() == false) goto fail; if (MainImageForm->MaskArea) { if (Mask->StartScanLine() == false) goto fail; if (Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); MP = Mask->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MP[sx + x] == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } } else { if (TempBitmap->StartScanLine() == false) goto fail; for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); MP = Mask->GetScanLine(sy + y); IP = TempBitmap->GetScanLine(random(FSize.y)); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && (rand() < ran) && ((MP[(sx + x) >> 3] & (0x80 >> ((sx + x) & 7))) == 0)) { SSP = IP; SSP += 3*random(FSize.x); GetPixel24(SSP, dc); SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } TempBitmap->StopScanLine(); } Mask->StopScanLine(); } else { if (Bitmap->BitsPerPixel == 8) { if (MainImageForm->Protect) { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (MainImageForm->Palette->ColorData[IP[sx + x]]->Protect == 0)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } else { if (PenManagerForm->acolor == 2) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (PenManagerForm->Selector->Number[IP[sx + x]] < 255)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { IP = Bitmap->GetScanLine(sy + y); for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if ((PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran)) { IP[sx + x] = CColor->Code[random(CColor->Count)]; } } } Bitmap->PutScanLine(sy + y); } } } } } else { if (TempBitmap->StartScanLine() == false) goto fail; for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Bitmap->Height)) { Mdsl = Bitmap->GetScanLine(sy + y) + 3*(sx+s); IP = TempBitmap->GetScanLine(random(FSize.y)); for (x = s; x <= e; x++, Mdsl += 3) { if ((sx + x >= 0) && (sx + x < Bitmap->Width)) { if (PenManagerForm->pshape[PenManagerForm->Pen->Shape].size[pw - 1].dot[y][x] && (rand() < ran)) { SSP = IP; SSP += 3*random(FSize.x); GetPixel24(SSP, dc); SetPixel24(Mdsl, dc); } } } Bitmap->PutScanLine(sy + y); } } TempBitmap->StopScanLine(); } } Bitmap->StopScanLine(); return; fail : TempBitmap->StopScanLine(); Mask->StopScanLine(); Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::point_pressure_pattern_pen(int lsx, int lsy, int size, COLORREF color) { if (PenManagerForm->Type == PT_NORMAL) { if (Item == T_REGULAR) set_brush_spread_regular_pattern_pen(lsx, lsy, size, color); else set_brush_spread_irregular_pattern_pen(lsx, lsy, size, color); } else if (PenManagerForm->Type == PT_CRAYON) { if (Item == T_REGULAR) set_crayon_brush_spread_regular_pattern_pen(lsx, lsy, size, color); else set_crayon_brush_spread_irregular_pattern_pen(lsx, lsy, size, color); } } //--------------------------------------------------------------------------- ////// PUBLIC METHOD ///////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::InitFunction() { if (Item == T_REGULAR) { if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (TempBitmap->Create(FSize.x, FSize.y, 8, rgb) == false) goto fail; TempBitmap->Copy(sBitmap, SRCCOPY); TempMask = NULL; if ((TempMask = new TTexpiaBitmap) == NULL) goto fail; if (TempMask->Create(FSize.x, FSize.y, 8, rgb) == false) goto fail; TempMask->Copy(MainImageForm->WorkArea->Mask, SRCCOPY); } else { if (TempBitmap->Create(FSize.x, FSize.y, 24) == false) goto fail; TempBitmap->Copy(sBitmap, SRCCOPY); } } else if (Item == T_IRREGULAR) { CColor = new TChoiceColor; MainImageForm->SearchWorkAreaColor(CColor); } else if (Item == T_IMGSPRAY) { sMask = NULL; if ((sMask = new TPBitmap)==NULL) goto fail; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { if (sMask->Create(FSize.x, FSize.y, 8) == false) goto fail; } else { if (sMask->Create(FSize.x, FSize.y, 1) == false) goto fail; } pstore = new TList; mdown = false; } return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ExitFunction() { if (Item == T_REGULAR) { ::doDestroy(TempMask); } else if (Item == T_IRREGULAR) { ::doDestroy(CColor); } else if (Item == T_IMGSPRAY) { InitData(); ::doDestroy(pstore); ::doDestroy(sMask); } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::InitForm() { TempMask = NULL; CColor = NULL; pstore = NULL; sMask = NULL; sBitmap = NULL; TempBitmap = NULL; ParentHeight = Parent->Height+20; ClientHeight = 192; Parent->Height = ParentHeight+ClientHeight; PenManagerForm->PointPressurePen = point_pressure_pattern_pen; RECT rect = MainImageForm->WorkArea->Range; FSize = Point ((rect.right - rect.left), (rect.bottom - rect.top)); //REGULAR FStart = Point (rect.left, rect.top); if ((TempBitmap = new TTexpiaBitmap) == NULL) goto fail; if ((sBitmap = new TTexpiaBitmap) == NULL) goto fail; MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { //Image Spray if (sBitmap->Create(FSize.x, FSize.y, 8, rgb) == false) goto fail; sBitmap->CopyFromRect(MainImageForm->iMainImage->Bitmap, rect.left, rect.top, SRCCOPY); MainImageForm->WorkArea->Mask->PutColors(0, 256, rgb); sBitmap->Copy(MainImageForm->WorkArea->Mask, SRCAND); if (TempBitmap->Create(FSize.x, FSize.y, 8, rgb) == false) goto fail; TempBitmap->Copy(sBitmap, SRCCOPY); } else { //Image Spray if (sBitmap->Create(FSize.x, FSize.y, 24) == false) goto fail; sBitmap->CopyFromRect(MainImageForm->iMainImage->Bitmap, rect.left, rect.top, SRCCOPY); sBitmap->Copy(MainImageForm->WorkArea->Mask, SRCAND); FillColor = SearchFillColor(); if (TempBitmap->Create(FSize.x, FSize.y, 24) == false) goto fail; TempBitmap->Copy(sBitmap, SRCCOPY); convertTemp24(); } MainImageForm->OnSetHLine = SetHLine; ComboDirection->ItemIndex = 0; ReadIni(); if (Item == T_REGULAR) { sbRegular->Down = true; FunctionClick(sbRegular); } else if (Item == T_IRREGULAR) { sbIrregular->Down = true; FunctionClick(sbIrregular); } else if (Item == T_IMGSPRAY) { sbImgSpray->Down = true; FunctionClick(sbImgSpray); } PreviewImageDraw(); return; fail : TempBitmap->Destroy(); sBitmap->Destroy(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ExitForm() { WriteIni(); if (Item == T_IMGSPRAY) { InitData(); ::doDestroy(pstore); ::doDestroy(sMask); } ::doDestroy(sBitmap); ::doDestroy(TempBitmap); ::doDestroy(TempMask); PenManagerForm->PointPressurePen = PenManagerForm->point_pressure_pen; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ReadIni() { double value; TIniFile *PRIni = new TIniFile(DirectoryItem + "\\Pattern.ini"); if (PRIni) { Item = PRIni->ReadInteger("Menu", "Item", 0); Limit = PRIni->ReadInteger("Irregular", "Value" , 80); delete PRIni; } else { Item = T_REGULAR; Limit = 80; } LabelUnit->Caption = MainImageForm->UnitName(); if (MainImageForm->CurrentUnit == uDot) { currentUnit = 1; EditDot->Text = Limit; } else if (MainImageForm->CurrentUnit == uInch) { currentUnit = 2; value = (StrToInt(Limit) / 160.0) + 0.0005; EditDot->Text = Format("%.3f", OPENARRAY(TVarRec,(value))); } else if (MainImageForm->CurrentUnit == uCm) { currentUnit = 0; value = (StrToFloat(Limit) * 2.54 / 160) + 0.0005; EditDot->Text = Format("%.3f", OPENARRAY(TVarRec,(value))); } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::WriteIni() { TIniFile *PRIni = new TIniFile(DirectoryItem + "\\Pattern.ini"); if (PRIni) { PRIni->WriteInteger("Menu", "Item", Item); PRIni->WriteInteger("Irregular", "Value", Limit); delete PRIni; } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::FunctionClick(TObject *Sender) { if (sbRegular->Down) { ExitFunction(); Item = T_REGULAR; PanelRegular->BringToFront(); is_startpoint = false; sbSelectPos->Down = false; } else if (sbIrregular->Down) { ExitFunction(); Item = T_IRREGULAR; PanelIrregular->BringToFront(); } else if (sbImgSpray->Down) { ExitFunction(); Item = T_IMGSPRAY; PanelImg->BringToFront(); } InitFunction(); } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageSprayMouseDown(int X, int Y) { InitData(); MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->Bitmap->Width, MainImageForm->iMainImage->Bitmap->Height)); POINT *p = new POINT; *p = Point(X, Y); MainImageForm->DrawLineLocate(*p, *p); pstore->Add(p); prepoint = *p; mdown = true; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageSprayMouseMove(int X, int Y, bool leave) { MainImageForm->iMainImage->Cursor = crCross; if (leave) { if (mdown) { POINT *p = new POINT; *p = Point(X, Y); MainImageForm->DrawLineLocate(prepoint, *p); pstore->Add(p); prepoint = *p; } } else { if (mdown) { EraseLine(); ImageSpray(); mdown = false; } } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageSprayMouseUp(int X, int Y) { if (mdown) { POINT *p = new POINT; *p = Point(X, Y); MainImageForm->DrawLineLocate(prepoint, *p); pstore->Add(p); EraseLine(); ImageSpray(); } mdown = false; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ImageSprayMouseLeave() { if (mdown) { EraseLine(); ImageSpray(); mdown = false; } } //--------------------------------------------------------------------------- bool __fastcall TPatternRepeatForm::SetStartPoint(int X, int Y) { if (sbSelectPos->Down) { if (L_IsPtInBitmapRgn(MainImageForm->iMainImage->Bitmap->Handle, Y, X)) { sbSelectPos->Down = false; RECT rc = MainImageForm->WorkArea->Range; switch (ComboDirection->ItemIndex) { case 0: margin.x = X - rc.left; margin.y = Y - rc.top; break; case 1: margin.x = rc.right - X; margin.y = Y - rc.top; break; case 2: margin.x = X - rc.left; margin.y = rc.bottom - Y; break; case 3: margin.x = rc.right - X; margin.y = rc.bottom - Y; break; } is_startpoint = true; } return true; } else { if (is_startpoint) { FStart.x = X - margin.x; FStart.y = Y - margin.y; is_startpoint = false; } return false; } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ChangeUnit(TUnit CUnit) { if (Item == T_IMGSPRAY) { LabelUnit->Caption = MainImageForm->UnitName(CUnit); if (CUnit==uDot) { currentUnit = 1; EditDot->Text = (int)(160 * StrToInt(EditDot->Text) / 2.54); } else if (CUnit==uInch) { currentUnit = 2; EditDot->Text = (double)(StrToFloat(EditDot->Text) / 160.0); } else if (CUnit==uCm) { currentUnit = 0; EditDot->Text = (double)(StrToFloat(EditDot->Text) * 2.54); } } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::EditDotChange(TObject *Sender) { if (EditDot->Text != "") { if (currentUnit == 0) { Limit = 160 * StrToFloat(EditDot->Text) / 2.54; } else if (currentUnit == 1) { Limit = StrToInt(EditDot->Text); } else if (currentUnit == 2) { Limit = 160 * StrToFloat(EditDot->Text); } } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::SetHLine(int x, int y, int len, COLORREF c) { if (Item == T_REGULAR) { RegularSetHLine(x, y, len); } else if (Item == T_IRREGULAR) { IrregularSetHLine(x, y, len); } } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::RegularSetHLine(int x, int y, int len) { int xx, yy, i; Byte *dsl = 0, *ssl = 0, *ssl24 = 0; COLORREF dc; TChoiceColor *ChoiceColor = PenManagerForm->Selector->ChoiceColor; if (TempBitmap->StartScanLine() == false) goto fail; xx = (x - FStart.x) % FSize.x; if (xx < 0) xx = FSize.x + xx; yy = (y - FStart.y) % FSize.y; if (yy < 0) yy = FSize.y + yy; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { dsl = MainImageForm->iMainImage->Bitmap->GetScanLine(y); ssl = TempBitmap->GetScanLine(yy); for (i = x; i < x + len; i++, xx++) { xx = xx % FSize.x; if (PenManagerForm->acolor == 2) { if (ChoiceColor->Number[*(dsl+i)] < 255) if (*(ssl+xx)) *(dsl+i) = *(ssl+xx); } else { if (*(ssl+xx)) *(dsl+i) = *(ssl+xx); } } MainImageForm->iMainImage->Bitmap->PutScanLine(y); } else { //24bit true color bitmap/////////////////////////////////////// dsl = MainImageForm->iMainImage->Bitmap->GetScanLine(y) + 3*x; ssl = TempBitmap->GetScanLine(yy); for (i = x; i < x + len; i++, xx++, dsl += 3) { xx = xx % FSize.x; ssl24 = ssl; ssl24 += 3*xx; GetPixel24(ssl24, dc); if (dc != FillColor) SetPixel24(dsl, dc); } MainImageForm->iMainImage->Bitmap->PutScanLine(y); } TempBitmap->StopScanLine(); return; fail : TempBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::IrregularSetHLine(int x, int y, int len) { int col; Byte *dsl, *ssl, *ssl24; COLORREF dc; TChoiceColor *ChoiceColor = PenManagerForm->Selector->ChoiceColor; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel == 8) { dsl = MainImageForm->iMainImage->Bitmap->GetScanLine(y); for (int i = x; i < x + len; i++) { col = random(CColor->Count); if (PenManagerForm->acolor == 2) { if (ChoiceColor->Number[*(dsl+i)] < 255) if (CColor->Code[col]) *(dsl+i) = CColor->Code[col]; } else { if (CColor->Code[col]) *(dsl+i) = CColor->Code[col]; } } MainImageForm->iMainImage->Bitmap->PutScanLine(y); } else { if (!(sBitmap->StartScanLine())) goto fail; dsl = MainImageForm->iMainImage->Bitmap->GetScanLine(y) + 3*x; ssl = sBitmap->GetScanLine(random(FSize.y)); for (int i = x; i < x + len; i++, dsl += 3) { ssl24 = ssl; ssl24 += 3*random(FSize.x); GetPixel24(ssl24, dc); SetPixel24(dsl, dc); } MainImageForm->iMainImage->Bitmap->PutScanLine(y); sBitmap->StopScanLine(); } return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPatternRepeatForm::ComboDirectionChange(TObject *Sender) { TempBitmap->Copy(sBitmap, SRCCOPY); if (TempMask) TempMask->Copy(MainImageForm->WorkArea->Mask, SRCCOPY); switch (ComboDirection->ItemIndex) { case 1: L_ReverseBitmap(TempBitmap->Handle); if (TempMask) L_ReverseBitmap(TempMask->Handle); break; case 2: L_FlipBitmap(TempBitmap->Handle); if (TempMask) L_FlipBitmap(TempMask->Handle); break; case 3: L_ReverseBitmap(TempBitmap->Handle); L_FlipBitmap(TempBitmap->Handle); if (TempMask) { L_ReverseBitmap(TempMask->Handle); L_FlipBitmap(TempMask->Handle); } break; } } //---------------------------------------------------------------------------