//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Grouping_F.h" #include "MainImage.h" #include "Palette.h" #include "StatusProgress.h" #include "Undo.h" #include "Clear.h" #include "MainMenu.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma link "TPSpin" #pragma link "TPImage" #pragma link "TPTextileImage" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_TYPE StringTable[0] #define IDS_FILLTER StringTable[1] #define IDS_USERCHOOSE StringTable[2] #define IDS_REARRANGE StringTable[3] #define IDS_COLORNUMBER StringTable[4] #define IDS_SIZE StringTable[5] #define IDS_SHAPE StringTable[6] #define IDS_Method1 StringTable[7] #define IDS_Method2 StringTable[8] #define IDS_SelectColor StringTable[9] #define IDS_SQUARE StringTable[10] #define IDS_RECTANGLE StringTable[11] #define IDS_CIRCLE StringTable[12] #define IDS_ELLIPSE StringTable[13] #define CHeight 32 //--------------------------------------------------------------------------- TGroupingForm *GroupingForm; //--------------------------------------------------------------------------- // TAutoGrouping //--------------------------------------------------------------------------- __fastcall TAutoGrouping::TAutoGrouping(TUnionBitmap *bm) // convert by celberus { Bitmap = bm; FRed = NULL; FGreen = NULL; FBlue = NULL; #ifdef TPDEBUG if ((FRed = new TMemoryStream) == NULL) SHOWDEBUG; if ((FGreen = new TMemoryStream) == NULL) SHOWDEBUG; if ((FBlue = new TMemoryStream) == NULL) SHOWDEBUG; #else FRed = new TMemoryStream; FGreen = new TMemoryStream; FBlue = new TMemoryStream; #endif } //--------------------------------------------------------------------------- __fastcall TAutoGrouping::~TAutoGrouping() { delete FBlue; delete FGreen; delete FRed; } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SetArea(RECT r) { FArea = r; Width = Area.right-Area.left; Height = Area.bottom-Area.top; FImageSize = Width*Height; FRed->SetSize(FImageSize); FillMemory(FRed->Memory, FRed->Size, 0); FGreen->SetSize(FImageSize); FillMemory(FGreen->Memory, FGreen->Size, 0); FBlue->SetSize(FImageSize); FillMemory(FBlue->Memory, FBlue->Size, 0); } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SetRed(int APos, Byte Value) { FRed->Position = APos; FRed->Write(&Value, sizeof(Byte)); } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SetGreen(int APos, Byte Value) { FGreen->Position = APos; FGreen->Write(&Value, sizeof(Byte)); } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SetBlue(int APos, Byte Value) { FBlue->Position = APos; FBlue->Write(&Value, sizeof(Byte)); } //--------------------------------------------------------------------------- Byte __fastcall TAutoGrouping::GetRed(int APos) { Byte Result; FRed->Position = APos; FRed->Read(&Result, sizeof(Byte)); return Result; } //--------------------------------------------------------------------------- Byte __fastcall TAutoGrouping::GetGreen(int APos) { Byte Result; FGreen->Position = APos; FGreen->Read(&Result, sizeof(Byte)); return Result; } //--------------------------------------------------------------------------- Byte __fastcall TAutoGrouping::GetBlue(int APos) { Byte Result; FBlue->Position = APos; FBlue->Read(&Result, sizeof(Byte)); return Result; } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::Processing() { FRed->Position = 0; FGreen->Position = 0; FBlue->Position = 0; make_rgb_cube(); SelectColorBoxes(); SortColors(); Postprocessing(); } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::make_rgb_cube() { int i, j, k; Byte r, g, b; for (i=0; i=FBoxes[BoxIndex].Lo[ax0]+1) { ind[Fax1] = FBoxes[BoxIndex].Hi[Fax1]; while (ind[Fax1]+1>=FBoxes[BoxIndex].Lo[Fax1]+1) { ind[Fax2] = FBoxes[BoxIndex].Hi[Fax2]; while (ind[Fax2]+1>=FBoxes[BoxIndex].Lo[Fax2]+1) { if (FRGBCube[ind[0]][ind[1]][ind[2]]) { flag = true; break; } ind[Fax2]--; } if (flag) break; ind[Fax1]--; } if (flag) break; ind[ax0]--; } FBoxes[BoxIndex].Hi[ax0] = ind[ax0]; } } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SelectColorBoxes() { int c, k, SelectedBox, TargetBox, Max, ax0, ax1, ax2, LongMax, ElementSum, PlaneSum; int ind[3]; ax1 = 0; ax2 = 0; PlaneSum = 0; for (c=0; c<=2; c++) { FBoxes[0].Lo[c] = 0; FBoxes[0].Hi[c] = ColorGrade-1; } FBoxes[0].NumElements = FImageSize; FNumBoxes = 1; Shrink(0); while (FNumBoxesLongMax) && ((FBoxes[c].Lo[0]!=FBoxes[c].Hi[0]) || (FBoxes[c].Lo[1]!=FBoxes[c].Hi[1]) || (FBoxes[c].Lo[2]!=FBoxes[c].Hi[2]))) { LongMax = FBoxes[c].NumElements; SelectedBox = c; } } if (SelectedBox==1000) break; ax0 = 0; Max = FBoxes[SelectedBox].Hi[ax0] - FBoxes[SelectedBox].Lo[ax0]; for (k=1; k<=2; k++) { c = FBoxes[SelectedBox].Hi[k] - FBoxes[SelectedBox].Lo[k]; if (Max(FBoxes[SelectedBox].NumElements/2)) break; ind[ax0]++; } if (ind[ax0]==FBoxes[SelectedBox].Hi[ax0]) { ind[ax0]--; ElementSum = ElementSum - PlaneSum; } for (c=0; c<=2; c++) { FBoxes[TargetBox].Lo[c] = FBoxes[SelectedBox].Lo[c]; FBoxes[TargetBox].Hi[c] = FBoxes[SelectedBox].Hi[c]; } FBoxes[TargetBox].Lo[ax0] = ind[ax0]+1; FBoxes[TargetBox].NumElements = FBoxes[SelectedBox].NumElements - ElementSum; FBoxes[SelectedBox].Hi[ax0] = ind[ax0]; FBoxes[SelectedBox].NumElements = ElementSum; Shrink(SelectedBox); Shrink(TargetBox); if (TargetBox==FNumBoxes) FNumBoxes++; } } } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SortColors() { int Index, c, r, b, g, i, temp, rsum, bsum, gsum; int indices[256], weightedcolor[256]; bool flag; for (i=0; i<=255; i++) { weightedcolor[i] = 0; indices[i] = 0; } for (Index=0; Indexweightedcolor[indices[Index+1]]) { temp = indices[Index]; indices[Index] = indices[Index+1]; indices[Index+1] = temp; flag = true; } Index++; } } for (Index=0; IndexStartScanLine()) { for (RowIndex=0; RowIndexHeight) { scan = Bitmap->GetScanLine(Area.top+RowIndex); for (ColIndex=0; ColIndexWidth) { if(!L_IsPtInBitmapRgn(MainImageForm->iMainImage->uBitmap->RgnBitmap->Handle,Area.top+RowIndex,Area.left+ColIndex)){//by jeegeo // convert by celberus LongIndex++; // ÀÌÀ¯´Â ¸ð¸£°ÚÁö¸¸ x,y°¡ ¹Ù²î¾îÀÖ´Ù continue; } Red = GetRed(LongIndex); Blue = GetBlue(LongIndex); Green = GetGreen(LongIndex); if ((RedPutScanLine(Area.top+RowIndex); } } Bitmap->StopScanLine(); } else {EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} } //--------------------------------------------------------------------------- // TGroupingForm //--------------------------------------------------------------------------- Byte Filter[3][4][9] = { { { 0, 0, 0, 1, 1, 1, 0, 0, 0 }, { 0, 0, 1, 0, 1, 0, 1, 0, 0 }, { 0, 1, 0, 0, 1, 0, 0, 1, 0 }, { 1, 0, 0, 0, 1, 0, 0, 0, 1 } }, { { 0, 1, 0, 1, 1, 1, 0, 1, 0 }, { 1, 0, 1, 0, 1, 0, 1, 0, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, { { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 } } }; typedef struct { Byte no; Byte spread; int count; } sColorArrange; //--------------------------------------------------------------------------- __fastcall TGroupingForm::TGroupingForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //=========================================================================== StringTable.Create(DirectoryCommon, Language, "Grouping"); SetSmallFont(Font); SetSmallFont(atLabel1->Font); SetSmallFont(atLabel2->Font); SpeedButtonType->Caption = IDS_TYPE; SpeedButtonFilter->Caption = IDS_FILLTER; SpeedButtonUser->Caption = IDS_USERCHOOSE; SpeedButtonRearrange->Caption = IDS_REARRANGE; atLabel1->Caption = IDS_COLORNUMBER; ButtonTypeRun->Caption = IDS_COMMON_RUN; ButtonUserRun->Caption = IDS_COMMON_RUN; SpeedButtonUserNew->Hint = IDS_COMMON_NEW; SpeedButtonUserAll->Hint = IDS_COMMON_ALL; SpeedButtonUserOne->Hint = IDS_COMMON_BLOCKCOLOR; SpeedButtonUserDelete->Hint = IDS_COMMON_INSERTCOLOR; SpeedButtonUserBeforeColor->Hint = IDS_COMMON_BEFORECOLOR; rgFilterSize->Caption = AnsiString(IDS_SIZE) + ":"; Label4->Caption = AnsiString(IDS_SHAPE) + ":"; SpeedButtonFilterNew->Hint = IDS_COMMON_NEW; SpeedButtonFilterAll->Hint = IDS_COMMON_ALL; SpeedButtonFilterOne->Hint = IDS_COMMON_BLOCKCOLOR; SpeedButtonFilterDelete->Hint = IDS_COMMON_INSERTCOLOR; SpeedButtonFilterBefore->Hint = IDS_COMMON_BEFORECOLOR; ButtonFilterRun->Caption = IDS_COMMON_RUN; Method1->Caption = IDS_Method1; Method2->Caption = IDS_Method2; SelectColor->Caption = IDS_SelectColor; sbFilter->Caption = IDS_FILLTER; Simulation->Caption = IDS_COMMON_RUN; sbSquare->Caption = IDS_SQUARE; sbRectangle->Caption = IDS_RECTANGLE; sbCircle->Caption = IDS_CIRCLE; sbEllipse->Caption = IDS_ELLIPSE; //=========================================================================== isFirst = true; isDrawingRegion = false; num_color_shape = 0; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::FormCreate(TObject *Sender) { // } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonTypeClick(TObject *Sender) { InitItem(0); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserClick(TObject *Sender) { InitItem(1); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterClick(TObject *Sender) { InitItem(2); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonRearrangeClick(TObject *Sender) { Rearrange(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ButtonTypeRunClick(TObject *Sender) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; RunType(); #if defined(KNIT) MainImageForm->Arrange->Dyarn.cnt = 0; #endif Screen->Cursor = cursor; ::RepaintColor(); // PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserNewClick(TObject *Sender) { ColorSelectorUser->Initial(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserAllClick(TObject *Sender) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(ColorSelectorUser->ChoiceColor); else MainImageForm->SearchWholeColor(ColorSelectorUser->ChoiceColor); ColorSelectorUser->Invalid(); Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserOneClick(TObject *Sender) { if (SpeedButtonUserOne->Down) SpeedButtonUserOne->Hint = IDS_COMMON_ONECOLOR; else SpeedButtonUserOne->Hint = IDS_COMMON_BLOCKCOLOR; InitLocate(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserDeleteClick(TObject *Sender) { if (SpeedButtonUserDelete->Down) SpeedButtonUserDelete->Hint = IDS_COMMON_DELETECOLOR; else SpeedButtonUserDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserBeforeColorClick(TObject *Sender) { ColorSelectorUser->LoadFromFile(DirectoryItem+"\\Grouping.Ini", "ColorSelector(UserChoose)"); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ButtonUserRunClick(TObject *Sender) { if (Item == 1) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; RunUser(); #if defined(KNIT) MainImageForm->Arrange->Dyarn.cnt = 0; #endif Screen->Cursor = cursor; ::RepaintColor(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rgFilterSizeClick(TObject *Sender) { FilterSize = rgFilterSize->ItemIndex; switch (FilterSize) { case 0: UpDown->Max = 3; break; case 1: UpDown->Max = 1; break; case 2: UpDown->Max = 0; break; } View(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::UpDownClick(TObject *Sender, TUDBtnType Button) { View(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterNewClick(TObject *Sender) { ColorSelectorFilter->Initial(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterAllClick(TObject *Sender) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(ColorSelectorFilter->ChoiceColor); else MainImageForm->SearchWholeColor(ColorSelectorFilter->ChoiceColor); ColorSelectorFilter->Invalid(); Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterOneClick(TObject *Sender) { if (SpeedButtonFilterOne->Down) SpeedButtonFilterOne->Hint = IDS_COMMON_ONECOLOR; else SpeedButtonFilterOne->Hint = IDS_COMMON_BLOCKCOLOR; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterDeleteClick(TObject *Sender) { if (SpeedButtonFilterDelete->Down) SpeedButtonFilterDelete->Hint = IDS_COMMON_DELETECOLOR; else SpeedButtonFilterDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterBeforeClick(TObject *Sender) { ColorSelectorFilter->LoadFromFile(DirectoryItem+"\\Grouping.Ini", "ColorSelector(Filter)"); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ButtonFilterRunClick(TObject *Sender) { if (Item == 2) { TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) RunFilter_WA_IRRE(); else RunFilter_WA_NONE(); Screen->Cursor = cursor; } } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TGroupingForm::InitItem(int i) { Item = i; switch (Item) { case 0: ClientHeight = PanelType->Top+PanelType->Height+32; Parent->Height = ParentHeight+ClientHeight; PanelType->BringToFront(); SpeedButtonType->Down = true; break; case 1: ClientHeight = PanelUser->Top+PanelUser->Height+32; Parent->Height = ParentHeight+ClientHeight; PanelUser->BringToFront(); SpeedButtonUser->Down = true; break; case 2: ClientHeight = PanelFilter->Top+PanelFilter->Height+32; Parent->Height = ParentHeight+ClientHeight; PanelFilter->BringToFront(); rgFilterSize->ItemIndex = 0; SpeedButtonFilter->Down = true; break; case 3: ClientHeight = Simulation->Top+Simulation->Height+39; Parent->Height = ParentHeight+ClientHeight; PanelMethod1->Visible = false; PanelMethod1->Enabled = false; PanelMethod2->Left = 0; PanelMethod2->Top = CHeight+1; PanelMethod2->BringToFront(); PanelMethod2->Visible = true; PanelMethod2->Enabled = true; SelectColorClick(this); SelectColor->Down = true; Simulation->Visible = true; ScrollBox->BringToFront(); if (SelectColorList) { SelectColorList = NULL; delete SelectColorList; } SelectColorList = new TList; break; } if(Step>0)MainImageForm->iMainImage->OnPaintLocate = NULL; Step = 0; MainImageForm->iMainImage->Repaint(); View(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::View() { int UseColor; bool cn[256]; int i, x, y; Byte *scan, *mask; RECT r; TChoiceColor *ChoiceColor = NULL; ChoiceColor = new TChoiceColor; if (Item==0) { TypeEdit->SetFocus(); if (MainImageForm->WorkArea->Mask) { r = MainImageForm->WorkArea->Range; for (i=0; i<=255; i++) cn[i] = false; if(MainImageForm->iMainImage->uBitmap->StartScanLine() && MainImageForm->WorkArea->Mask->StartScanLine()) { for (y = r.top; y < r.bottom; y++) { scan = MainImageForm->iMainImage->uBitmap->GetScanLine(y); mask = MainImageForm->WorkArea->Mask->GetScanLine(y-MainImageForm->WorkArea->Range.top); for (x = r.left; x < r.right; x++, mask++){ if (*mask) cn[*(scan+x)] = true; } } MainImageForm->WorkArea->Mask->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopScanLine(); } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); MainImageForm->iMainImage->Repaint(); return; } UseColor = 0; for (i=2; i<252; i++) { if (cn[i]) UseColor++; } MaxValue = UseColor; } else { // MaxValue = MainImageForm->Palette->UseColor-1; //r = MainImageForm->iMainImage->uBitmap->Range; for (i=0; i<=255; i++) cn[i] = false; if(MainImageForm->iMainImage->uBitmap->StartScanLine()) { for (y = 0; y < MainImageForm->iMainImage->uBitmap->Height; y++) { scan = MainImageForm->iMainImage->uBitmap->GetScanLine(y); for (x = 0; x < MainImageForm->iMainImage->uBitmap->Width; x++){ cn[*(scan+x)] = true; } } MainImageForm->iMainImage->uBitmap->StopScanLine(); } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); MainImageForm->iMainImage->Repaint(); return; } UseColor = 0; for (i=2; i<252; i++) { if (cn[i]) UseColor++; } MaxValue = UseColor; } /* MainImageForm->SearchWorkAreaColor(ChoiceColor); ///k3dogs 20010205 MaxValue = ChoiceColor->Count; /// } else { /// MainImageForm->SearchWholeColor(ChoiceColor); /// MaxValue = ChoiceColor->Count; /// } */ if (MaxValue>0 && MaxValue<=250) TypeEdit->Value = MaxValue; TypeEdit->SelectAll(); atLabel2->Caption = "( 1 -> "+ AnsiString(MaxValue)+" )"; } else if (Item==1) { ColorSelectorUser->SetPalette(MainImageForm->Palette); } else if (Item==2) { ButtonFilterRun->SetFocus(); //lhskys ¿£ÅÍ·Î ½ÇÇàÇϱâ À§Çؼ­ focus¸¦ ÁØ´Ù rgFilterSize->ItemIndex = FilterSize; Image->Canvas->Brush->Color = clWhite; Image->Canvas->Brush->Style = bsSolid; Image->Canvas->Rectangle(0, 0, 26, 26); Image->Canvas->Brush->Color = clBlack; for (i=0; i<=8; i++) { if (Filter[FilterSize][UpDown->Position][i]==1) { x = (i % 3)*9; y = (i / 3)*9; if (i==4) Image->Canvas->Brush->Style = bsSolid; else Image->Canvas->Brush->Style = bsClear; Image->Canvas->Rectangle(x, y, x+7, y+7); } } ColorSelectorFilter->SetPalette(MainImageForm->Palette); } if (ChoiceColor) delete ChoiceColor; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunType() { // for test by celberus /* RGBQUAD selectRGB[256]; selectRGB[0].rgbRed = 0; selectRGB[0].rgbGreen = 0; selectRGB[0].rgbBlue = 0; selectRGB[0].rgbReserved = RGB_RESERVED; selectRGB[1].rgbRed = 0xFF; selectRGB[1].rgbGreen = 0xFF; selectRGB[1].rgbBlue = 0xFF; selectRGB[1].rgbReserved = RGB_RESERVED; for (int i = 0; i < 256; i++) { selectRGB[i+1].rgbReserved = RGB_EMPTY; } MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE, selectRGB, TypeEdit->Value+2); for (int i = 1; i <= TypeEdit->Value; i++) { MainImageForm->Palette->SetNormal(i+1, selectRGB[i+1].rgbRed, selectRGB[i+1].rgbGreen, selectRGB[i+1].rgbBlue); } SimulationCheck = true; OnlyColor->Enabled = true;*/ ///////////////////////////////////////// int i, x, y, yy, c; TAutoGrouping *at = NULL; Byte *scan; bool undoSw = false; TWorkArea *wa; Byte *mp; if ((at = new TAutoGrouping(MainImageForm->iMainImage->uBitmap)) == NULL) goto fail; at->ColorNumber = TypeEdit->Value; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) goto fail; if (MainImageForm->WorkArea->Mask) { at->Area = MainImageForm->WorkArea->Range; } else { at->Area = Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); } if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) goto fail; for (y=0; yHeight; y++) { scan = MainImageForm->iMainImage->uBitmap->GetScanLine(at->Area.top+y); yy = y*at->Width; for (x=0; xWidth; x++) { c = scan[at->Area.left+x]; at->SetRed(yy+x, MainImageForm->Palette->ColorData[c]->RGB.rgbRed >> 2); at->SetGreen(yy+x, MainImageForm->Palette->ColorData[c]->RGB.rgbGreen >> 2); at->SetBlue(yy+x, MainImageForm->Palette->ColorData[c]->RGB.rgbBlue >> 2); } } MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->iMainImage->uBitmap->FillRect(Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height), // PALETTEINDEX(BackgroundIndex)); PALETTEINDEX(0)); at->Processing(); for (i=1; i<=at->ColorNumber+1; i++) { MainImageForm->Palette->ColorData[i+1]->RGB.rgbRed = (at->Palette[i].rgbRed << 2) | (at->Palette[i].rgbRed >> 6); MainImageForm->Palette->ColorData[i+1]->RGB.rgbGreen = (at->Palette[i].rgbGreen << 2) | (at->Palette[i].rgbGreen >> 6); MainImageForm->Palette->ColorData[i+1]->RGB.rgbBlue = (at->Palette[i].rgbBlue << 2) | (at->Palette[i].rgbBlue >> 6); } delete at; at = NULL; // MainImageForm->iMainImage->uBitmap->PutColors(1, at->ColorNumber + 2, rgb); /* Use the LEADTOOLS BITMAPHANDLE hBitmap; RGBQUAD rgb[256]; int nRet; HDC dcSrc, dcDst; RECT src, dst; Byte *sl; if (MainImageForm->WorkArea->Mask) { MainImageForm->Undo->Save(UK_ALL, MainImageForm->WorkArea->Range); src = MainImageForm->WorkArea->Range; dst.left = 0; dst.top = 0; dst.right = MainImageForm->WorkArea->Range.right-MainImageForm->WorkArea->Range.left; dst.bottom = MainImageForm->WorkArea->Range.bottom-MainImageForm->WorkArea->Range.top; } else { MainImageForm->Undo->Save(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height)); src.left = 0; src.top = 0; src.right = MainImageForm->iMainImage->uBitmap->Width; src.bottom = MainImageForm->iMainImage->uBitmap->Height; dst = src; } nRet = L_CreateBitmap(&hBitmap, TYPE_CONV, dst.right, dst.bottom, 8, ORDER_BGR, NULL, TOP_LEFT); MainImageForm->Palette->ToRGBQUAD(rgb, 256); nRet = L_PutBitmapColors(&hBitmap, 0, 256, rgb); dcSrc = MainImageForm->iMainImage->uBitmap->CreateDC(); dcDst = L_CreateLeadDC(&hBitmap); BitBlt(dcDst, dst.left, dst.top, dst.right, dst.bottom, dcSrc, src.left, src.top, SRCCOPY); L_DeleteLeadDC(dcDst); MainImageForm->iMainImage->uBitmap->DeleteDC(dcSrc); nRet = L_ColorResBitmap(&hBitmap, &hBitmap, 8, CRF_OPTIMIZEDPALETTE | CRF_ORDEREDDITHERING, NULL, SpinEdit->Value, NULL, NULL); nRet = L_GetBitmapColors(&hBitmap, 0, 256, rgb); MainImageForm->iMainImage->uBitmap->PutColors(0, 256, rgb); dcSrc = L_CreateLeadDC(&hBitmap); dcDst = MainImageForm->iMainImage->uBitmap->CreateDC(); BitBlt(dcDst, src.left, src.top, dst.right, dst.bottom, dcSrc, dst.left, dst.top, SRCCOPY); MainImageForm->iMainImage->uBitmap->DeleteDC(dcDst); L_DeleteLeadDC(dcSrc); for (x=0; xValue; x++) { MainImageForm->Palette->SetNormal(x+2, rgb[x].rgbRed, rgb[x].rgbGreen, rgb[x].rgbBlue); } MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->uBitmap->PutColors(0, 256, rgb); MainImageForm->iMainImage->uBitmap->StartScanLine(); for (y=src.top; yiMainImage->uBitmap->GetScanLine(y); for (x=src.left; xiMainImage->uBitmap->PutScanLine(y); } MainImageForm->iMainImage->uBitmap->StopScanLine(); L_FreeBitmap(&hBitmap); */ // MainImageForm->iMainImage->Repaint(); MainImageForm->Palette->UseColor = TypeEdit->Value+1; PaletteForm->DIB256Palette->ChoiceIndex = 2; return; fail: if (at) { MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->Undo->RemoveLast(); delete at; } if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunUser() { if (MainImageForm->iMainImage->LayerList->Count > 1) { MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height)); // RunUser_layer(); RunUser_none(); } else { MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height)); RunUser_none(); } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunUser_none() { TUnionBitmap *tb; // convert by celberus TPWorkArea *wa; Byte pal[256]; int cnt[256]; int i, j, x, y, t; TColorData *cm; Byte *scan, *mp; RGBQUAD rgb[256]; tb = MainImageForm->iMainImage->uBitmap; if (ColorSelectorUser->Count > 0) { for (i=1; i<=MainImageForm->Palette->UseColor; i++) { for (j=0; jCount; j++) { cm = ColorSelectorUser->GetColorMap(j); cnt[j] = abs(MainImageForm->Palette->ColorData[i]->RGB.rgbRed-cm->RGB.rgbRed)+ abs(MainImageForm->Palette->ColorData[i]->RGB.rgbGreen-cm->RGB.rgbGreen)+ abs(MainImageForm->Palette->ColorData[i]->RGB.rgbBlue-cm->RGB.rgbBlue); } t = 0; for (j=1; jCount; j++) { if (cnt[j]WorkArea; if (!tb->StartScanLine()) goto fail; if (wa->Mask) { if(!wa->Mask->StartScanLine()) goto fail; for (y=wa->Range.top; yRange.bottom; y++) { scan = tb->GetScanLine(y)+wa->Range.left; mp = (Byte *)wa->Mask->GetScanLine(y-wa->Range.top); for (x=wa->Range.left; xRange.right; x++, scan++, mp++) { if (*mp) *scan = ColorSelectorUser->Code[pal[*scan]]; } tb->PutScanLine(y); } wa->Mask->StopScanLine(); } else { for (y=0; yHeight; y++) { scan = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(scan+x) = ColorSelectorUser->Code[pal[*(scan+x)]]; } tb->PutScanLine(y); } } tb->StopScanLine(); } else { wa = MainImageForm->WorkArea; if (!tb->StartScanLine()) goto fail; if (wa->Mask) { if(!wa->Mask->StartScanLine()) goto fail; for (y=wa->Range.top; yRange.bottom; y++) { scan = tb->GetScanLine(y)+wa->Range.left; mp = (Byte *)wa->Mask->GetScanLine(y-wa->Range.top); for (x=wa->Range.left; xRange.right; x++, scan++, mp++) { if (*mp) *scan = 1; } tb->PutScanLine(y); } wa->Mask->StopScanLine(); } else { for (y=0; yHeight; y++) { scan = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(scan+x) = 1; } tb->PutScanLine(y); } } tb->StopScanLine(); } MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->ChangeRGBColors(rgb); MainImageForm->iMainImage->Repaint(); RunRearrange(false); return; fail: if (wa->Mask) wa->Mask->StopScanLine(); tb->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunUser_layer() { TUnionBitmap *tb; // convert by celberus TPWorkArea *wa; Byte pal[256]; int cnt[256]; int i, j, x, y, t; TColorData *cm; Byte *scan, *mp; bool undoSw = false; RGBQUAD rgb[256]; if (ColorSelectorUser->Count > 0) { for (i = 1; i <= MainImageForm->Palette->UseColor; i++) { for (j = 0; j < ColorSelectorUser->Count; j++) { cm = ColorSelectorUser->GetColorMap(j); cnt[j] = abs(MainImageForm->Palette->ColorData[i]->RGB.rgbRed-cm->RGB.rgbRed)+ abs(MainImageForm->Palette->ColorData[i]->RGB.rgbGreen-cm->RGB.rgbGreen)+ abs(MainImageForm->Palette->ColorData[i]->RGB.rgbBlue-cm->RGB.rgbBlue); } t = 0; for (j=1; jCount; j++) { if (cnt[j]WorkArea; j = MainImageForm->iMainImage->LayerList->Count; for (i = 0; i < j; i++) { tb = MainImageForm->iMainImage->GetLayerBitmap(i); if (!tb->StartScanLine()) goto fail; if (wa->Mask) { if(!wa->Mask->StartScanLine()) goto fail; for (y=wa->Range.top; yRange.bottom; y++) { scan = tb->GetScanLine(y)+wa->Range.left; mp = (Byte *)wa->Mask->GetScanLine(y-wa->Range.top); for (x=wa->Range.left; xRange.right; x++, scan++, mp++) { if (*mp) *scan = ColorSelectorUser->Code[pal[*scan]]; } tb->PutScanLine(y); } wa->Mask->StopScanLine(); } else { for (y=0; yHeight; y++) { scan = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(scan+x) = ColorSelectorUser->Code[pal[*(scan+x)]]; } tb->PutScanLine(y); } } tb->StopScanLine(); MainImageForm->iMainImage->SetLayerBitmap(i); } } else { wa = MainImageForm->WorkArea; for (i = 0; i < j; i++) { tb = MainImageForm->iMainImage->GetLayerBitmap(i); if (!tb->StartScanLine()) goto fail; if (wa->Mask) { if(!wa->Mask->StartScanLine()) goto fail; for (y=wa->Range.top; yRange.bottom; y++) { scan = tb->GetScanLine(y)+wa->Range.left; mp = (Byte *)wa->Mask->GetScanLine(y-wa->Range.top); for (x=wa->Range.left; xRange.right; x++, scan++, mp++) { if (*mp) *scan = 1; } tb->PutScanLine(y); } wa->Mask->StopScanLine(); } else { for (y=0; yHeight; y++) { scan = tb->GetScanLine(y); for (x=0; xWidth; x++) { *(scan+x) = 1; } tb->PutScanLine(y); } } tb->StopScanLine(); MainImageForm->iMainImage->SetLayerBitmap(i); } } MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->RearrangeColors(rgb); MainImageForm->iMainImage->Repaint(); RunRearrange(false); return; fail: if (wa->Mask) wa->Mask->StopScanLine(); tb->StopScanLine(); if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunFilter_WA_NONE() { ///* BeConverted by linuxjun Don't Forget!! Undo_Method int ipx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int ipy[9] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; Byte max, maxp, c; Byte cm[256]; int Tcol[256]; int x, y, w, h, pss; int i, j; TUnionBitmap *Sbmp; // convert by celberus // TUndoManager *Ubmp; TUnionBitmap *Ubmp; Byte *Usl[3]; Byte *Ssl; bool undoSw = false; int Direction; // TUndoData *ud; THistoryData *ud; //by linuxjun For Undo_Method Sbmp = MainImageForm->iMainImage->uBitmap; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Sbmp->Width, Sbmp->Height))) == false) goto fail; ud = MainImageForm->Undo->GetLast(); // Ubmp = ud->uBitmap; Ubmp = ud->uBitmap; //1 Ubmp->PartialUndo->LoadLast(ud->FromRgb); //2 w = Sbmp->Width-2; h = Sbmp->Height-2; StatusProgress->Maximum = h + 1; for (i=0; i<=255; i++) { Tcol[i] = -1; for (j=0; j<=255; j++) { if (i==ColorSelectorFilter->Code[j]) { Tcol[i] = j; break; } } } StatusProgress->Position = 1; Direction = UpDown->Position; if (!Ubmp->StartUndoScanLineN(3)) goto fail; if (!Sbmp->StartScanLine()) goto fail; Usl[0] = Ubmp->GetUndoScanLineN(0, 0); Usl[1] = Ubmp->GetUndoScanLineN(1, 1); for (y=1; y<=h; y++) { Usl[2] = Ubmp->GetUndoScanLineN(y+1, (y+1)%3); Ssl = Sbmp->GetScanLine(y); for (x=1; x<=w; x++) { c = Usl[1][x]; if (Tcol[c]==-1) { memset(cm, 0, 256); max = 0; for (i=0; i<=8; i++) { if (Filter[FilterSize][Direction][i]==1) { c = Usl[ipy[i]][x+ipx[i]]; cm[c] = cm[c]+1; if (cm[c]>max) { max = cm[c]; maxp = c; } } } if (Tcol[maxp]==-1) { if (max>1) Ssl[x] = maxp; } } } Sbmp->PutScanLine(y); Usl[0] = Usl[1]; Usl[1] = Usl[2]; StatusProgress->Position = y + 1; } Sbmp->StopScanLine(); Ubmp->StopUndoScanLine(); // ud->Complete(); MainImageForm->iMainImage->Repaint(); StatusProgress->End(); return; fail: Sbmp->StopScanLine(); Ubmp->StopUndoScanLine(); if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); //*/ /* BeConverted by linuxjun Don't Forget!! Undo_Method int ipx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int ipy[9] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; Byte max, maxp, c; Byte cm[256]; int Tcol[256]; int x, y, w, h, pss; int i, j; TUnionBitmap *Sbmp; // convert by celberus TUnionBitmap *Ubmp; // convert by celberus Byte *Usl[3]; Byte *Ssl; bool undoSw = false; int Direction; // TUndoData *ud; THistoryData *ud; //by linuxjun For Undo_Method Sbmp = MainImageForm->iMainImage->uBitmap; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Sbmp->Width, Sbmp->Height))) == false) goto fail; ud = Undo->Last; Ubmp = ud->Bitmap; w = Sbmp->Width-2; h = Sbmp->Height-2; StatusProgress->Maximum = h + 1; for (i=0; i<=255; i++) { Tcol[i] = -1; for (j=0; j<=255; j++) { if (i==ColorSelectorFilter->Code[j]) { Tcol[i] = j; break; } } } StatusProgress->Position = 1; Direction = UpDown->Position; if (!Ubmp->StartScanLineN(3)) goto fail; if (!Sbmp->StartScanLine()) goto fail; Usl[0] = Ubmp->GetScanLineN(0, 0); Usl[1] = Ubmp->GetScanLineN(1, 1); for (y=1; y<=h; y++) { Usl[2] = Ubmp->GetScanLineN(y+1, (y+1)%3); Ssl = Sbmp->GetScanLine(y); for (x=1; x<=w; x++) { c = Usl[1][x]; if (Tcol[c]==-1) { memset(cm, 0, 256); max = 0; for (i=0; i<=8; i++) { if (Filter[FilterSize][Direction][i]==1) { c = Usl[ipy[i]][x+ipx[i]]; cm[c] = cm[c]+1; if (cm[c]>max) { max = cm[c]; maxp = c; } } } if (Tcol[maxp]==-1) { if (max>1) Ssl[x] = maxp; } } } Sbmp->PutScanLine(y); Usl[0] = Usl[1]; Usl[1] = Usl[2]; StatusProgress->Position = y + 1; } Sbmp->StopScanLine(); Ubmp->StopScanLine(); ud->Complete(); MainImageForm->iMainImage->Repaint(); StatusProgress->End(); return; fail: Sbmp->StopScanLine(); Ubmp->StopScanLine(); if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); */ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunFilter_WA_IRRE() { ///* BeConverted by linuxjun Don't Forget!! Undo_Method int ipx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int ipy[9] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; Byte max, maxp, c; Byte cm[256]; int Tcol[256]; int x, y, sx, sy, w, h; int i, j; TTexpiaBitmap *Mbmp; TUnionBitmap *Sbmp, *Ubmp; // convert by celberus // TUnionBitmap *Sbmp; // convert by celberus Byte *Usl[3]; // TUndoManager *Ubmp; Byte *mp, *Ssl, mm; bool undoSw = false; int Direction; THistoryData *ud; //by linuxjun for UndoData #if defined(TEXTILE) if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range)) == false) goto fail; #elif defined(KNIT) if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range, true)) == false) goto fail; #endif ud = MainImageForm->Undo->GetLast(); Ubmp = ud->uBitmap; // Ubmp = ud->uBitmap->PartialUndo; //1 Ubmp->PartialUndo->LoadLast(ud->FromRgb); //2 Sbmp = MainImageForm->iMainImage->uBitmap; Mbmp = MainImageForm->WorkArea->Mask; sx = MainImageForm->WorkArea->Range.left; sy = MainImageForm->WorkArea->Range.top; w = MainImageForm->WorkArea->Range.right-MainImageForm->WorkArea->Range.left-2; h = MainImageForm->WorkArea->Range.bottom-MainImageForm->WorkArea->Range.top-2; StatusProgress->Maximum = h + 1; for (i=0; i<=255; i++) { Tcol[i] = -1; for (j=0; j<=255; j++) { if (i==ColorSelectorFilter->Code[j]) { Tcol[i] = j; break; } } } StatusProgress->Position = 1; Direction = UpDown->Position; if (!Ubmp->StartUndoScanLineN(3)) goto fail; if (!Sbmp->StartScanLine()) goto fail; Usl[0] = Ubmp->GetUndoScanLineN(sy+0, 0)+sx; Usl[1] = Ubmp->GetUndoScanLineN(sy+1, 1)+sx; if (!Mbmp->StartScanLine()) goto fail; for (y=1; y<=h; y++) { Usl[2] = Ubmp->GetUndoScanLineN(sy+y+1, (y+1)%3)+sx; Ssl = Sbmp->GetScanLine(sy+y); mp = (Byte *)Mbmp->GetScanLine(y); mm = 0x80; for (x=1; x<=w; x++) { if (*mp & mm) { c = Usl[1][x]; if (Tcol[c]==-1) { memset(cm, 0, 256); max = 0; for (i=0; i<=8; i++) { if (Filter[FilterSize][Direction][i]==1) { c = Usl[ipy[i]][x+ipx[i]]; cm[c] = cm[c]+1; if (cm[c]>max) { max = cm[c]; maxp = c; } } } if (Tcol[maxp]==-1) { if (max>1) Ssl[sx+x] = maxp; } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Sbmp->PutScanLine(sy+y); Usl[0] = Usl[1]; Usl[1] = Usl[2]; StatusProgress->Position = y + 1; } Mbmp->StopScanLine(); Sbmp->StopScanLine(); Ubmp->StopUndoScanLine(); // ud->Complete(); MainImageForm->iMainImage->Repaint(); StatusProgress->End(); return; fail: Mbmp->StopScanLine(); Sbmp->StopScanLine(); Ubmp->StopUndoScanLine(); if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); //*/ /* BeConverted by linuxjun Don't Forget!! Undo_Method int ipx[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int ipy[9] = {0, 0, 0, 1, 1, 1, 2, 2, 2}; Byte max, maxp, c; Byte cm[256]; int Tcol[256]; int x, y, sx, sy, w, h; int i, j; TTexpiaBitmap *Mbmp; TUnionBitmap *Sbmp, *Ubmp; // convert by celberus Byte *Usl[3]; Byte *mp, *Ssl, mm; bool undoSw = false; int Direction; THistoryData *ud; //by linuxjun for UndoData #if defined(TEXTILE) if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range)) == false) goto fail; #elif defined(KNIT) if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range, true)) == false) goto fail; #endif ud = Undo->Last; Ubmp = ud->Bitmap; Sbmp = MainImageForm->iMainImage->uBitmap; Mbmp = MainImageForm->WorkArea->Mask; sx = MainImageForm->WorkArea->Range.left; sy = MainImageForm->WorkArea->Range.top; w = MainImageForm->WorkArea->Range.right-MainImageForm->WorkArea->Range.left-2; h = MainImageForm->WorkArea->Range.bottom-MainImageForm->WorkArea->Range.top-2; StatusProgress->Maximum = h + 1; for (i=0; i<=255; i++) { Tcol[i] = -1; for (j=0; j<=255; j++) { if (i==ColorSelectorFilter->Code[j]) { Tcol[i] = j; break; } } } StatusProgress->Position = 1; Direction = UpDown->Position; if (!Ubmp->StartScanLineN(3)) goto fail; if (!Sbmp->StartScanLine()) goto fail; Usl[0] = Ubmp->GetScanLineN(0, 0); Usl[1] = Ubmp->GetScanLineN(1, 1); if (!Mbmp->StartScanLine()) goto fail; for (y=1; y<=h; y++) { Usl[2] = Ubmp->GetScanLineN(y+1, (y+1)%3); Ssl = Sbmp->GetScanLine(sy+y); mp = (Byte *)Mbmp->GetScanLine(y); mm = 0x80; for (x=1; x<=w; x++) { if (*mp & mm) { c = Usl[1][x]; if (Tcol[c]==-1) { memset(cm, 0, 256); max = 0; for (i=0; i<=8; i++) { if (Filter[FilterSize][Direction][i]==1) { c = Usl[ipy[i]][x+ipx[i]]; cm[c] = cm[c]+1; if (cm[c]>max) { max = cm[c]; maxp = c; } } } if (Tcol[maxp]==-1) { if (max>1) Ssl[sx+x] = maxp; } } } if (mm == 1) { mp++; mm = 0x80; } else mm >>= 1; } Sbmp->PutScanLine(sy+y); Usl[0] = Usl[1]; Usl[1] = Usl[2]; StatusProgress->Position = y + 1; } Mbmp->StopScanLine(); Sbmp->StopScanLine(); Ubmp->StopScanLine(); ud->Complete(); MainImageForm->iMainImage->Repaint(); StatusProgress->End(); return; fail: Mbmp->StopScanLine(); Sbmp->StopScanLine(); Ubmp->StopScanLine(); if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); */ } //--------------------------------------------------------------------------- int __fastcall find(int current, TList *List) { int k, p, count; sColorArrange *pOrder; k = 0; while (kCount) { pOrder = (sColorArrange *)List->Items[k]; count = pOrder->count; p = k; if (pOrder->spread) { while (true) { k = k+1; pOrder = (sColorArrange *)List->Items[k]; count = count+pOrder->count; if (k+1Count) { pOrder = (sColorArrange *)List->Items[k+1]; if (pOrder->spread==0 || pOrder->spread==1) break; } else break; } } k = k+1; if (current>count) return p; } return List->Count; } //--------------------------------------------------------------------------- void __fastcall RunRearrange(bool undo) { RECT rt; if (MainImageForm->iMainImage->LayerList->Count > 1) { rt = Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); // if (undo) MainImageForm->UndoSave(UK_ALL, rt); if (undo) MainImageForm->UndoSave(UK_REARRANGE, rt); if (!GroupingForm->RunRearrange_layer() && undo){ MainImageForm->Undo->RemoveLast(); }else{ MainImageForm->iMainImage->MakeBeforeBitmap(); //by linuxjun for layer rearrange } // GroupingForm->RunRearrange_layer(); } else { rt = Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); if (undo) MainImageForm->UndoSave(UK_ALL, rt); if (!GroupingForm->RunRearrange_none() && undo) MainImageForm->Undo->RemoveLast(); } } //--------------------------------------------------------------------------- bool __fastcall TGroupingForm::RunRearrange_none() { int Code[256]; int ColorCount[256]; int i, j, n, x, y, count; Byte *Scan; TList *List = NULL; sColorArrange *pOrder = NULL; TChoiceColor *ChoiceColor = NULL; RGBQUAD rgb[256]; if (MainImageForm->Palette->UseColor>2) { if ((ChoiceColor = new TChoiceColor) == NULL) goto fail; if ((List = new TList) == NULL) goto fail; for (i=0; i<=255; i++) { Code[i] = -1; ColorCount[i] = 0; } ///////////////////////////////////k3dogs 20010131 Make Colors, which have same RGB, to indicate same palette /* TColorData *first, *second; int p, q, r, color[256]; for (r=0; r<256; r++) color[r] = 0; for (p=2; p<252; p++) { if (color[p]) continue; first = MainImageForm->Palette->ColorData[p]; for (q=p+1; q<256; q++) { if (color[q]) continue; second = MainImageForm->Palette->ColorData[q]; if ((first->RGB.rgbBlue == second->RGB.rgbBlue) && (first->RGB.rgbGreen == second->RGB.rgbGreen) && (first->RGB.rgbRed == second->RGB.rgbRed)) color[q] = p; } }*/ /////////////////////////////////// if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) goto fail; for (y=0; yiMainImage->uBitmap->Height; y++) { Scan = MainImageForm->iMainImage->uBitmap->GetScanLine(y); for (x=0; xiMainImage->uBitmap->Width; x++) { n = Scan[x]; ColorCount[n]++; //k3dogs 20010131 /* if (color[n] == 0) ColorCount[n]++;// else ColorCount[ color[n] ]++; //*/ } } MainImageForm->iMainImage->uBitmap->StopScanLine(); i = 2; while (i<252) { if (ColorCount[i]) { j = find(ColorCount[i], List); if ((pOrder = (sColorArrange *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(sColorArrange))) == NULL) goto fail; pOrder->no = i; pOrder->spread = 0; pOrder->count = ColorCount[i]; if (jCount) List->Insert(j, pOrder); else List->Add(pOrder); } i = i+1; } for (i=0; iCount; i++) { pOrder = (sColorArrange *)List->Items[i]; Code[pOrder->no] = ChoiceColor->Count+1; ChoiceColor->Add(MainImageForm->Palette, pOrder->no); } if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) goto fail; for (y=0; yiMainImage->uBitmap->Height; y++) { Scan = MainImageForm->iMainImage->uBitmap->GetScanLine(y); for (x=0; xiMainImage->uBitmap->Width; x++) { n = Scan[x]; if (n>1) Scan[x] = Code[n]+1; //k3dogs 20010131 /* if (n>1) { if (color[n] == 0) Scan[x] = Code[n]+1; // else Scan[x] = Code[ color[n] ] + 1; // }*/ } MainImageForm->iMainImage->uBitmap->PutScanLine(y); } MainImageForm->iMainImage->uBitmap->StopScanLine(); for (i=0; iCount; i++) { MainImageForm->Palette->ColorData[i+2] = ChoiceColor->ColorMap[i]; } if (List->Count) MainImageForm->Palette->UseColor = List->Count+1; else MainImageForm->Palette->UseColor = 2; while (List->Count>0) { pOrder = (sColorArrange *)List->First(); HeapFree(GetProcessHeap(), 0, pOrder); List->Remove(pOrder); } delete List; List = NULL; delete ChoiceColor; ChoiceColor = NULL; } MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->uBitmap->PutColors(0, 256, rgb); PaletteForm->DIB256Palette->ChoiceIndex = 2; return true; fail: if (List) { while (List->Count>0) { pOrder = (sColorArrange *)List->First(); HeapFree(GetProcessHeap(), 0, pOrder); List->Remove(pOrder); } delete List; } MainImageForm->iMainImage->uBitmap->StopScanLine(); if (ChoiceColor) delete ChoiceColor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return false; } //--------------------------------------------------------------------------- bool __fastcall TGroupingForm::RunRearrange_layer() { int Code[256]; int ColorCount[256]; int i, j, n, x, y, count; Byte *Scan; TList *List = NULL; sColorArrange *pOrder = NULL; TChoiceColor *ChoiceColor = NULL; RGBQUAD rgb[256]; TUnionBitmap *Bitmap; // convert by celberus if (MainImageForm->Palette->UseColor>2) { if ((ChoiceColor = new TChoiceColor) == NULL) goto fail; if ((List = new TList) == NULL) goto fail; for (i=0; i<=255; i++) { Code[i] = -1; ColorCount[i] = 0; } ///////////////////////////////////k3dogs 20010131 Make Colors, which have same RGB, to indicate same palette TColorData *first, *second; int p, q, r, color[256]; for (r=0; r<256; r++) color[r] = 0; for (p=2; p<252; p++) { if (color[p]) continue; first = MainImageForm->Palette->ColorData[p]; for (q=p+1; q<256; q++) { if (color[q]) continue; second = MainImageForm->Palette->ColorData[q]; if ((first->RGB.rgbBlue == second->RGB.rgbBlue) && (first->RGB.rgbGreen == second->RGB.rgbGreen) && (first->RGB.rgbRed == second->RGB.rgbRed)) color[q] = p; } } /////////////////////////////////// count = MainImageForm->iMainImage->LayerList->Count; for (i = 0; i < count; i++) { Bitmap = MainImageForm->iMainImage->GetLayerBitmap(i); if (!Bitmap->StartScanLine()) goto fail; for (y=0; y < Bitmap->Height; y++) { Scan = Bitmap->GetScanLine(y); for (x=0; x < Bitmap->Width; x++) { n = Scan[x]; //ColorCount[n]++; //k3dogs 20010131 if (color[n] == 0) ColorCount[n]++;// else ColorCount[ color[n] ]++; // } } Bitmap->StopScanLine(); } i = 2; while (i<252) { if (ColorCount[i]) { j = find(ColorCount[i], List); if ((pOrder = (sColorArrange *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(sColorArrange))) == NULL) goto fail; pOrder->no = i; pOrder->spread = 0; pOrder->count = ColorCount[i]; if (jCount) List->Insert(j, pOrder); else List->Add(pOrder); } i = i+1; } for (i=0; iCount; i++) { pOrder = (sColorArrange *)List->Items[i]; Code[pOrder->no] = ChoiceColor->Count+1; ChoiceColor->Add(MainImageForm->Palette, pOrder->no); } for (i = 0; i < count; i++) { Bitmap = MainImageForm->iMainImage->GetLayerBitmap(i); if (!Bitmap->StartScanLine()) goto fail; for (y=0; y < Bitmap->Height; y++) { Scan = Bitmap->GetScanLine(y); for (x=0; x < Bitmap->Width; x++) { n = Scan[x]; //if (n>1) Scan[x] = Code[n]+1; //k3dogs 20010131 if (n>1) { if (color[n] == 0) Scan[x] = Code[n]+1; // else Scan[x] = Code[ color[n] ] + 1; // } } Bitmap->PutScanLine(y); } Bitmap->StopScanLine(); MainImageForm->iMainImage->SetLayerBitmap(i); } for (i=0; iCount; i++) { MainImageForm->Palette->ColorData[i+2] = ChoiceColor->ColorMap[i]; } MainImageForm->Palette->UseColor = List->Count+1; while (List->Count>0) { pOrder = (sColorArrange *)List->First(); HeapFree(GetProcessHeap(), 0, pOrder); List->Remove(pOrder); } delete List; List = NULL; delete ChoiceColor; ChoiceColor = NULL; } MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->RearrangeColors(rgb); PaletteForm->DIB256Palette->ChoiceIndex = 2; return true; fail: if (List) { while (List->Count>0) { pOrder = (sColorArrange *)List->First(); HeapFree(GetProcessHeap(), 0, pOrder); List->Remove(pOrder); } delete List; } MainImageForm->iMainImage->uBitmap->StopScanLine(); if (ChoiceColor) delete ChoiceColor; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return false; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::InitLocate() { if (Item==1 || Item==2) { if (Step>0) { if (IsDraw) { MainImageForm->DrawRectangleLocate(Temp); IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo Step = 0; } } } } //--------------------------------------------------------------------------- // Public Method //--------------------------------------------------------------------------- void __fastcall TGroupingForm::InitForm() { if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { ParentHeight = Parent->Height+20; ClientHeight = 60+32; Parent->Height = ParentHeight + ClientHeight; SpeedButtonType->Enabled = false; SpeedButtonUser->Enabled = false; SpeedButtonFilter->Enabled = false; SpeedButtonRearrange->Enabled = true; } else { ParentHeight = Parent->Height+20; FilterSize = 0; MaxValue = 255; ColorSelectorFilter->Initial(); ColorSelectorUser->Initial(); if (MainImageForm->iMainImage->LayerList->Count > 1) { SpeedButtonUser->Down = true; SpeedButtonType->Enabled = false; InitItem(1); } else { SpeedButtonType->Down = true; InitItem(0); } } SimulationCheck = false; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ExitForm() { if (Step > 0){ Step = 0; MainImageForm->iMainImage->OnPaintLocate = NULL; MainImageForm->iMainImage->Repaint(); } if (SelectColorList) { TSelectColorList *Temp; while(SelectColorList->Count > 0){ Temp = (TSelectColorList *)SelectColorList->Last(); SelectColorList->Remove(Temp); delete Temp; } SelectColorList = NULL; delete SelectColorList; } if(scColor && num_color_shape > 0) { for(int i = 0 ; i < num_color_shape ; i++) delete scColor[i]; num_color_shape = 0; free(scColor); } ColorSelectorFilter->SaveToFile(DirectoryItem+"\\Grouping.Ini", "ColorSelector(Filter)"); ColorSelectorUser->SaveToFile(DirectoryItem+"\\Grouping.Ini", "ColorSelector(UserChoose)"); for (int i=0; i<256; i++) PaletteForm->DIB256Palette->Palette->ColorData[i]->Protect = 0; //0:±×³É 1:»öº¸È£ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImageMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { RECT r, gr; bool sw, One, Delete; bool undoSw = false; int ix, iy; TColorSelector *ColorSelector; TUnionBitmap *tb; // convert by celberus Byte *bp; unsigned long int temp_red = 0, temp_green = 0, temp_blue = 0, total_pixel; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { switch (Item) { case 1: One = SpeedButtonUserOne->Down; Delete = SpeedButtonUserDelete->Down; ColorSelector = ColorSelectorUser; sw = true; break; case 2: One = SpeedButtonFilterOne->Down; Delete = SpeedButtonFilterDelete->Down; ColorSelector = ColorSelectorFilter; sw = true; break; case 3: if(sbFilter->Down)return; One = sbBlock->Down; Delete = false; ColorSelector = ColorSelectorUser; sw = true; break; default: sw = false; break; } if (sw) { tb = MainImageForm->iMainImage->uBitmap; if (One) { if (Delete) { ColorSelector->DeleteColor(tb->GetPixelColor(X, Y)); } else { if(Item==3 && SelectColor->Down){ if (tb->StartScanLine()) { bp = tb->GetScanLine(Y); temp_red = MainImageForm->Palette->ColorData[bp[X]]->RGB.rgbRed; temp_green = MainImageForm->Palette->ColorData[bp[X]]->RGB.rgbGreen; temp_blue = MainImageForm->Palette->ColorData[bp[X]]->RGB.rgbBlue; TSelectColorList *Gcolor; Gcolor = new TSelectColorList; Gcolor->color = (TColor)((temp_blue << 16) + (temp_green << 8) + temp_red); SelectColorList->Add(Gcolor); AverageColorPaint(); tb->StopScanLine(); } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} }else { ColorSelector->AddColor(tb->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 (tb->StartScanLine()) { if (Delete) { for (iy=r.top; iyGetScanLine(iy); for (ix=r.left; ixDeleteColor(*(bp+ix)); } } } else { for (iy=r.top; iyGetScanLine(iy); for (ix=r.left; ixPalette->ColorData[bp[ix]]->RGB.rgbRed; temp_green += MainImageForm->Palette->ColorData[bp[ix]]->RGB.rgbGreen; temp_blue += MainImageForm->Palette->ColorData[bp[ix]]->RGB.rgbBlue; } else ColorSelector->AddColor(*(bp+ix)); } } if(Item==3 && SelectColor->Down){ total_pixel = (r.bottom - r.top) * (r.right - r.left); if(total_pixel == 0){ bp = tb->GetScanLine(r.top); temp_red = MainImageForm->Palette->ColorData[bp[r.left]]->RGB.rgbRed; temp_green = MainImageForm->Palette->ColorData[bp[r.left]]->RGB.rgbGreen; temp_blue = MainImageForm->Palette->ColorData[bp[r.left]]->RGB.rgbBlue; }else { temp_red /= total_pixel; temp_green /= total_pixel; temp_blue /= total_pixel; } TSelectColorList *Gcolor; // int CNT = 252+SelectColorList->Count; // PaletteForm->DIB256Palette->SetNormal(CNT,temp_red, temp_green, temp_blue); Gcolor = new TSelectColorList; Gcolor->color = (TColor)((temp_blue << 16) + (temp_green << 8) + temp_red); SelectColorList->Add(Gcolor); AverageColorPaint(); } } tb->StopScanLine(); } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} Step = 0; IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } else { Temp.left = Temp.top = X; Temp.top = Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; Step = 11; FirstX = X; FirstY = Y; } } } }else if(Button==mbLeft) { if(sbFilter->Down){ if(sbSquare->Down){ if(isFirst) { // ¿µ¿ªÀ» ±×¸®±â À§ÇÑ Ã¹¹øÂ° Ŭ¸¯À̸é isFirst = false; isDrawingRegion = true; Region_rect.left = X; Region_rect.right = X; Region_rect.top = Y; Region_rect.bottom = Y; }else { // ¿µ¿ªÀ» ¼³Á¤ÇÑ ÈÄ °áÁ¤ÇÏ´Â ÀǹÌÀÇ Å¬¸¯À̸é unsigned long int color_cnt[0xFF] = {0}, compare_value = 0; int search_start_x, search_end_x, search_start_y, search_end_y; BYTE max_color_pal_no; /*PaintRegionRectangle(first_x, first_y, last_x, last_y); isFirst = true; isDrawingRegion = false;*/ isFirst = true; isDrawingRegion = false; if(Region_rect.right > Region_rect.left){ search_start_x = Region_rect.left; search_end_x = Region_rect.right; }else { search_start_x = Region_rect.right; search_end_x = Region_rect.left; } if(Region_rect.bottom > Region_rect.top){ search_start_y = Region_rect.top; search_end_y = Region_rect.bottom; }else { search_start_y = Region_rect.bottom; search_end_y = Region_rect.top; } Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; MainImageForm->DrawRectangleLocate(Region_rect); tb = MainImageForm->iMainImage->uBitmap; if(tb->StartScanLine()){ for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++) color_cnt[bp[j]]++; } for(int i = 0 ; i < 0xFF ; i++) { if(compare_value <= color_cnt[i]){ compare_value = color_cnt[i]; max_color_pal_no = i; } } if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) goto fail; for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++){ bp[j] = max_color_pal_no; } tb->PutScanLine(i); } }else { tb->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } tb->StopScanLine(); } }else if(sbRectangle->Down){ if(isFirst) { // ¿µ¿ªÀ» ±×¸®±â À§ÇÑ Ã¹¹øÂ° Ŭ¸¯À̸é /*isFirst = false; isDrawingRegion = true; first_x = X; first_y = Y; PaintRegionRectangle(first_x, first_y, X, Y); last_x = X; last_y = Y;*/ isFirst = false; isDrawingRegion = true; Region_rect.left = X; Region_rect.right = X; Region_rect.top = Y; Region_rect.bottom = Y; //MainImageForm->DrawRectangleLocate(Region_rect); }else { // ¿µ¿ªÀ» ¼³Á¤ÇÑ ÈÄ °áÁ¤ÇÏ´Â ÀǹÌÀÇ Å¬¸¯À̸é unsigned long int color_cnt[0xFF] = {0}, compare_value = 0; int search_start_x, search_end_x, search_start_y, search_end_y; BYTE max_color_pal_no; /*PaintRegionRectangle(first_x, first_y, last_x, last_y); isFirst = true; isDrawingRegion = false;*/ isFirst = true; isDrawingRegion = false; if(Region_rect.right > Region_rect.left){ search_start_x = Region_rect.left; search_end_x = Region_rect.right; }else { search_start_x = Region_rect.right; search_end_x = Region_rect.left; } if(Region_rect.bottom > Region_rect.top){ search_start_y = Region_rect.top; search_end_y = Region_rect.bottom; }else { search_start_y = Region_rect.bottom; search_end_y = Region_rect.top; } Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; MainImageForm->DrawRectangleLocate(Region_rect); tb = MainImageForm->iMainImage->uBitmap; if(tb->StartScanLine()){ for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++) color_cnt[bp[j]]++; } for(int i = 0 ; i < 0xFF ; i++) { if(compare_value <= color_cnt[i]){ compare_value = color_cnt[i]; max_color_pal_no = i; } } if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) goto fail; for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++){ bp[j] = max_color_pal_no; } tb->PutScanLine(i); } }else { tb->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } tb->StopScanLine(); } }else if(sbCircle->Down){ if(isFirst){ /*isFirst = false; isDrawingRegion = true; c_x = X; c_y = Y; circle_r = 0; PaintRegionCircle(c_x, c_y, circle_r);*/ isFirst = false; isDrawingRegion = true; c_x = X; c_y = Y; circle_r = 0; }else { unsigned long int color_cnt[0xFF] = {0}, compare_value = 0; int search_start_x, search_end_x, search_start_y, search_end_y; BYTE max_color_pal_no; //PaintRegionCircle(c_x, c_y, circle_r); isFirst = true; isDrawingRegion = false; search_start_x = Region_rect.left; search_end_x = Region_rect.right; search_start_y = Region_rect.top; search_end_y = Region_rect.bottom; Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; MainImageForm->DrawEllipseLocate(Region_rect); tb = MainImageForm->iMainImage->uBitmap; if(tb->StartScanLine()){ for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++) if((double)circle_r >= (double)sqrt((double)((c_x - j) * (c_x - j)) + (double)((c_y - i) * (c_y - i)))) color_cnt[bp[j]]++; } for(int i = 0 ; i < 0xFF ; i++){ if(compare_value <= color_cnt[i]){ compare_value = color_cnt[i]; max_color_pal_no = i; } } if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) goto fail; for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++){ if((double)circle_r >= sqrt((double)((c_x - j) * (c_x - j)) + (double)((c_y - i) * (c_y - i)))){ bp[j] = max_color_pal_no; } } tb->PutScanLine(i); } }else { tb->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } tb->StopScanLine(); } }else if(sbEllipse->Down){ if(isFirst){ isFirst = false; isDrawingRegion = true; c_x = X; c_y = Y; }else { unsigned long int color_cnt[0xFF] = {0}, compare_value = 0; int search_start_x, search_end_x, search_start_y, search_end_y; BYTE max_color_pal_no; int ellipse_width, ellipse_height; //PaintRegionCircle(c_x, c_y, circle_r); isFirst = true; isDrawingRegion = false; search_start_x = Region_rect.left; search_end_x = Region_rect.right; search_start_y = Region_rect.top; search_end_y = Region_rect.bottom; ellipse_width = Region_rect.right - c_x; ellipse_height = Region_rect.bottom - c_y; Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; MainImageForm->DrawEllipseLocate(Region_rect); tb = MainImageForm->iMainImage->uBitmap; if(tb->StartScanLine()){ for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++) if((double)1 >= (double)((j - c_x) * (j - c_x)) / (double)(ellipse_width * ellipse_width) + (double)((i - c_y) * (i - c_y)) / (double)(ellipse_height * ellipse_height)) color_cnt[bp[j]]++; } for(int i = 0 ; i < 0xFF ; i++){ if(compare_value <= color_cnt[i]){ compare_value = color_cnt[i]; max_color_pal_no = i; } } if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) goto fail; for(int i = search_start_y ; i <= search_end_y ; i++){ bp = tb->GetScanLine(i); for(int j = search_start_x ; j <= search_end_x ; j++){ if((double)1 >= (double)((j - c_x) * (j - c_x)) / (double)(ellipse_width * ellipse_width) + (double)((i - c_y) * (i - c_y)) / (double)(ellipse_height * ellipse_height)){ bp[j] = max_color_pal_no; } } tb->PutScanLine(i); } }else { tb->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } tb->StopScanLine(); } }/*else if(sbIrregular->Down){ if(isFirst){ }else { } }*/ } } return; fail: if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImageMouseMove(TShiftState Shift, int X, int Y) { bool sw; bool One; switch (Item) { case 1: One = SpeedButtonUserOne->Down; sw = true; break; case 2: One = SpeedButtonFilterOne->Down; sw = true; break; case 3: One = false; sw = true; break; default: sw = false; break; } if (sw) { if (One==false) { if (Step>0) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } } } if(isDrawingRegion){ if(sbSquare->Down){ if(abs(X - Region_rect.left) <= abs(Y - Region_rect.top)) { Region_rect.right = X; if(Y <= Region_rect.top) Region_rect.bottom = Region_rect.top - abs(X - Region_rect.left); else Region_rect.bottom = Region_rect.top + abs(X - Region_rect.left); } else { Region_rect.bottom = Y; if(X <= Region_rect.left) Region_rect.right = Region_rect.left - abs(Y - Region_rect.top); else Region_rect.right = Region_rect.left + abs(Y - Region_rect.top); } MainImageForm->DrawRectangleLocate(Region_rect); }else if(sbRectangle->Down){ /*PaintRegionRectangle(first_x, first_y, last_x, last_y); last_x = X; last_y = Y; PaintRegionRectangle(first_x, first_y, X, Y);*/ //MainImageForm->DrawRectangleLocate(Region_rect); Region_rect.right = X; Region_rect.bottom = Y; MainImageForm->DrawRectangleLocate(Region_rect); }else if(sbCircle->Down){ int min_r; /*PaintRegionCircle(c_x, c_y, circle_r); circle_r = sqrt(abs(X - c_x) * abs(X - c_x) + abs(Y - c_y) * abs(Y - c_y)); PaintRegionCircle(c_x, c_y, circle_r);*/ circle_r = sqrt(abs(X - c_x) * abs(X - c_x) + abs(Y - c_y) * abs(Y - c_y)); Region_rect.left = c_x - circle_r; Region_rect.right = c_x + circle_r; Region_rect.top = c_y - circle_r; Region_rect.bottom = c_y + circle_r; min_r = c_x; if(min_r > c_y) min_r = c_y; if(min_r > MainImageForm->iMainImage->uBitmap->Width - c_x) min_r = MainImageForm->iMainImage->uBitmap->Width - c_x; if(min_r > MainImageForm->iMainImage->uBitmap->Height - c_y) min_r = MainImageForm->iMainImage->uBitmap->Height - c_y; if(Region_rect.left < 0 || Region_rect.right > MainImageForm->iMainImage->uBitmap->Width || Region_rect.top < 0 || Region_rect.bottom > MainImageForm->iMainImage->uBitmap->Height) { circle_r = min_r; } Region_rect.left = c_x - circle_r; Region_rect.right = c_x + circle_r; Region_rect.top = c_y - circle_r; Region_rect.bottom = c_y + circle_r; MainImageForm->DrawEllipseLocate(Region_rect); }else if(sbEllipse->Down){ int min_w, min_h; Region_rect.left = c_x - abs(X - c_x); Region_rect.right = c_x + abs(X - c_x); Region_rect.top = c_y - abs(Y - c_y); Region_rect.bottom = c_y + abs(Y - c_y); if(Region_rect.left < 0 || Region_rect.right > MainImageForm->iMainImage->uBitmap->Width) { min_w = c_x; if(min_w > MainImageForm->iMainImage->uBitmap->Width - c_x) min_w = MainImageForm->iMainImage->uBitmap->Width - c_x; Region_rect.left = c_x - min_w; Region_rect.right = c_x + min_w; } if(Region_rect.top < 0 || Region_rect.bottom > MainImageForm->iMainImage->uBitmap->Height) { min_h = c_y; if(min_h > MainImageForm->iMainImage->uBitmap->Height - c_y) min_h = MainImageForm->iMainImage->uBitmap->Height - c_y; Region_rect.top = c_y - min_h; Region_rect.bottom = c_y + min_h; } MainImageForm->DrawEllipseLocate(Region_rect); }/*else if(sbIrregular->Down){ }*/ } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImagePaint() { IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::TypeEditChange(TObject *Sender) { if (TypeEdit->Text.Length()>0) { int k = TypeEdit->Value; if (k > MaxValue) TypeEdit->Value = MaxValue; if (k < 1) TypeEdit->Value = 1; } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::Rearrange() // ÆË¾÷¸Þ´º¸¦ À§ÇØ ÇÔ¼ö µû·Î °ü¸®. playzzang { TCursor cursor; MainMenuForm->showGrouping = false; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; RunRearrange(); #if defined(KNIT) MainImageForm->Arrange->Dyarn.cnt = 0; #endif Screen->Cursor = cursor; ::RepaintColor(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //---------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImageKeyDown(int Key) //lhskys »öÁ¤¸®¿¡¼­ { // °¢°¢Àǰæ¿ì¿¡ µû¶ó if ( Key == 13 ) { if(Method1->Down){ // ¿£ÅÍŰ·Î ½ÇÇàÇϱâ if (SpeedButtonUser->Down == true)ButtonUserRunClick(this); if (SpeedButtonType->Down == true)ButtonTypeRunClick(this); if (SpeedButtonFilter->Down == true)ButtonFilterRunClick(this); } } } //---------------------------------------------------------------------------- void __fastcall TGroupingForm::TypeEditClick(TObject *Sender) { TypeEdit->SetFocus(); TypeEdit->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::Method1Click(TObject *Sender) { if (SelectColorList) { TSelectColorList *Temp; while(SelectColorList->Count > 0){ Temp = (TSelectColorList *)SelectColorList->Last(); SelectColorList->Remove(Temp); delete Temp; } SelectColorList = NULL; delete SelectColorList; } if(scColor && num_color_shape > 0){ for(int i = 0 ; i < num_color_shape ; i++) delete scColor[i]; num_color_shape = 0; free(scColor); } PanelMethod2->Visible = false; PanelMethod2->Enabled = false; PanelMethod1->Left = 0; PanelMethod1->Top = CHeight+1; PanelMethod1->BringToFront(); PanelMethod1->Visible = true; PanelMethod1->Enabled = true; ParentHeight = 165; FilterSize = 0; MaxValue = 255; ColorSelectorFilter->Initial(); ColorSelectorUser->Initial(); Item = 0; if(MainImageForm->iMainImage->LayerList->Count > 1) { SpeedButtonUser->Down = true; SpeedButtonType->Enabled = false; InitItem(1); } else { SpeedButtonType->Down = true; InitItem(0); } for (int i=0; i<256; i++) PaletteForm->DIB256Palette->Palette->ColorData[i]->Protect = 0; //0:±×³É 1:»öº¸È£ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::Method2Click(TObject *Sender) { InitItem(3); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::AverageColorPaint() { int i; TSelectColorList *Temp; TShape *s; if(scColor && num_color_shape > 0){ for(int i = 0 ; i < num_color_shape ; i++) delete scColor[i]; num_color_shape = 0; free(scColor); } if(SelectColorList->Count == 0){ delete1->Enabled = false; return; }else if(SelectColorList->Count > 0){ delete1->Enabled = true; } scColor=(TShape**)malloc(sizeof(TShape*)*SelectColorList->Count); if(SelectColorList->Count==0) ScrollBox->VertScrollBar->Margin = 102; else if(1<=SelectColorList->Count && SelectColorList->Count<6) ScrollBox->VertScrollBar->Margin = 55; else if(6<=SelectColorList->Count && SelectColorList->Count<11) ScrollBox->VertScrollBar->Margin = 10; else ScrollBox->VertScrollBar->Margin = 0; for (i = 0; i < SelectColorList->Count; i++) { scColor[i]=new TShape(NULL); scColor[i]->Parent = ScrollBox; scColor[i]->Top = 3+45*((i)/5); scColor[i]->Left = 45*((i)%5)+2; scColor[i]->Width = 44; scColor[i]->Height = 44; scColor[i]->Name = "sc"+IntToStr(i); scColor[i]->OnMouseDown = ScrollMouseDown; Temp = (TSelectColorList *)(SelectColorList->Items[i]); s = (TShape *)scColor[i]; s->Brush->Color = Temp->color; } num_color_shape = SelectColorList->Count; SimulationCheck = false; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SimulationClick(TObject *Sender) { TSelectColorList *Temp; TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; TIniFile *GroupingColor = new TIniFile(DirectoryItem + "\\GroupingColor.ini"); GroupingColor->WriteInteger("ColorSelect", "Count", SelectColorList->Count); for (int i = 0; i < SelectColorList->Count; i++) { Temp = (TSelectColorList *)(SelectColorList->Items[i]); GroupingColor->WriteInteger("ColorSelect", "Color"+IntToStr(i), Temp->color); } delete GroupingColor; SimulationRun(); Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::delete1Click(TObject *Sender) { TSelectColorList *Temp; int SaveCount; TShape *s; TIniFile *GroupingColor = new TIniFile(DirectoryItem + "\\GroupingColorbackup.ini"); GroupingColor->WriteInteger("ColorSelect", "Count", SelectColorList->Count); for (int i = 0; i < SelectColorList->Count; i++) { Temp = (TSelectColorList *)(SelectColorList->Items[i]); GroupingColor->WriteInteger("ColorSelect", "Color"+IntToStr(i), Temp->color); } SaveCount = SelectColorList->Count; if(scColor && num_color_shape > 0){ for(int i = 0 ; i < num_color_shape ; i++) delete scColor[i]; num_color_shape = 0; free(scColor); } if (SelectColorList) { TSelectColorList *Temp; while(SelectColorList->Count > 0){ Temp = (TSelectColorList *)SelectColorList->Last(); SelectColorList->Remove(Temp); delete Temp; } SelectColorList = NULL; delete SelectColorList; } SelectColorList = new TList; TSelectColorList *Gcolor; for (int i = 0; i < SaveCount; i++) { if(i != DelSelect){ Gcolor = new TSelectColorList; Gcolor->color = (TColor) GroupingColor->ReadInteger("ColorSelect", "Color"+IntToStr(i), 0); SelectColorList->Add(Gcolor); } } AverageColorPaint(); delete GroupingColor; DeleteFile(DirectoryItem + "\\GroupingColorbackup.ini"); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SelectColorClick(TObject *Sender) { ClientHeight = Simulation->Top+Simulation->Height+39; Parent->Height = ParentHeight+ClientHeight; ScrollBox->Visible = true; Simulation->Visible = true; for (int i=0; i<256; i++) PaletteForm->DIB256Palette->Palette->ColorData[i]->Protect = 0; //0:±×³É 1:»öº¸È£ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::GroupClick(TObject *Sender) { GroupPanel->Visible = false; GroupPanel->Visible = true; for (int i=0; i<256; i++) PaletteForm->DIB256Palette->Palette->ColorData[i]->Protect = 0; //0:±×³É 1:»öº¸È£ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::PaintRegionRectangle(int lt_x, int lt_y, int rb_x, int rb_y) { HDC formDC=NULL; formDC = MainImageForm->iMainImage->Canvas->Handle; HPEN hOldPen = NULL , hPen = NULL; HBRUSH hOldBrush=NULL; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hPen = CreatePen(psSolid , 1, clBlack); hOldPen = SelectObject(formDC, hPen); SetROP2(formDC, R2_NOT); Rectangle(formDC, lt_x, lt_y, rb_x, rb_y); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); DeleteObject(hPen); hPen = NULL; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::PaintRegionCircle(int c_x, int c_y, int circle_r) { HDC formDC=NULL; formDC = MainImageForm->iMainImage->Canvas->Handle; HPEN hOldPen = NULL , hPen = NULL; HBRUSH hOldBrush=NULL; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hPen = CreatePen(psSolid , 1, clBlack); hOldPen = SelectObject(formDC, hPen); SetROP2(formDC, R2_NOT); Ellipse(formDC, c_x - circle_r, c_y - circle_r, c_x + circle_r, c_y + circle_r); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); DeleteObject(hPen); hPen = NULL; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::sbFilterClick(TObject *Sender) { ClientHeight = Simulation->Top+Simulation->Height; Parent->Height = ParentHeight+ClientHeight; ScrollBox->Visible = false; Simulation->Visible = false; GroupPanel->Visible = true; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::sbNewClick(TObject *Sender) { if (SelectColorList) { TSelectColorList *Temp; while(SelectColorList->Count > 0){ Temp = (TSelectColorList *)SelectColorList->Last(); SelectColorList->Remove(Temp); delete Temp; } SelectColorList = NULL; delete SelectColorList; SelectColorList = new TList; } if(scColor && num_color_shape > 0){ for(int i = 0 ; i < num_color_shape ; i++) delete scColor[i]; num_color_shape = 0; free(scColor); } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::sbAllClick(TObject *Sender) { TSelectColorList *Gcolor; unsigned long int temp_red = 0, temp_green = 0, temp_blue = 0, total_pixel; for(int i=1;i<251;i++){ temp_red = MainImageForm->Palette->ColorData[i]->RGB.rgbRed; temp_green = MainImageForm->Palette->ColorData[i]->RGB.rgbGreen; temp_blue = MainImageForm->Palette->ColorData[i]->RGB.rgbBlue; Gcolor = new TSelectColorList; Gcolor->color = (TColor) ((temp_blue << 16) + (temp_green << 8) + temp_red); SelectColorList->Add(Gcolor); } AverageColorPaint(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::sbBlockClick(TObject *Sender) { if (sbBlock->Down) sbBlock->Hint = IDS_COMMON_ONECOLOR; else sbBlock->Hint = IDS_COMMON_BLOCKCOLOR; /* if (Item==1 || Item==2) { if (Step>0) { if (IsDraw) { MainImageForm->DrawRectangleLocate(Temp); IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo Step = 0; } } }*/ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::sbBeforeClick(TObject *Sender) { TShape *s; TIniFile *GroupingColor = new TIniFile(DirectoryItem + "\\GroupingColor.ini"); int SaveCount = GroupingColor->ReadInteger("ColorSelect", "Count", 0); if(scColor && num_color_shape > 0){ for(int i = 0 ; i < num_color_shape ; i++) delete scColor[i]; num_color_shape = 0; free(scColor); } if (SelectColorList) { TSelectColorList *Temp; while(SelectColorList->Count > 0){ Temp = (TSelectColorList *)SelectColorList->Last(); SelectColorList->Remove(Temp); delete Temp; } SelectColorList = NULL; delete SelectColorList; } SelectColorList = new TList; TSelectColorList *Gcolor; for (int i = 0; i < SaveCount; i++) { Gcolor = new TSelectColorList; Gcolor->color = (TColor) GroupingColor->ReadInteger("ColorSelect", "Color"+IntToStr(i), 0); SelectColorList->Add(Gcolor); } AverageColorPaint(); delete GroupingColor; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ScrollMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int row, col; TShape *aShape; AnsiString ShapeName; int NameLength, last1, last2, last3, last4; AnsiString num1, num2, num3; if (Button==mbRight) { aShape = (TShape *)Sender; ShapeName = aShape->Name; NameLength = ShapeName.Length(); if(NameLength == 3){ last1 = NameLength; num1 = ShapeName[last1]; DelSelect = StrToInt(num1); }else if(NameLength == 4){ last1 = NameLength-1; last2 = NameLength; num1 = ShapeName[last1]; num2 = ShapeName[last2]; DelSelect = StrToInt(num1+num2); }else if(NameLength == 5){ last1 = NameLength-2; last2 = NameLength-1; last3 = NameLength; num1 = ShapeName[last1]; num2 = ShapeName[last2]; num3 = ShapeName[last3]; DelSelect = StrToInt(num1+num2+num3); } } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SimulationRun() { int i; bool undoSw = false; TSelectColorList *Temp; RGBQUAD selectRGB[256]; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) goto fail; selectRGB[0].rgbRed = 0; selectRGB[0].rgbGreen = 0; selectRGB[0].rgbBlue = 0; selectRGB[0].rgbReserved = RGB_RESERVED; selectRGB[1].rgbRed = 0xFF; selectRGB[1].rgbGreen = 0xFF; selectRGB[1].rgbBlue = 0xFF; selectRGB[1].rgbReserved = RGB_RESERVED; for (i = 1; i <= 10; i++) { if (i <= SelectColorList->Count) { Temp = (TSelectColorList *)(SelectColorList->Items[i-1]); selectRGB[i+1].rgbRed = Temp->color & 0xFF; selectRGB[i+1].rgbGreen = (Temp->color >> 8) & 0xFF; selectRGB[i+1].rgbBlue = (Temp->color >> 16) & 0xFF; selectRGB[i+1].rgbReserved = 0; }else { break; } } MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE, selectRGB, i+1); /* switch (i) { case 0: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE, selectRGB, i+1); break; case 1: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_FLOYDSTEINDITHERING, selectRGB, i+1); break; case 2: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_STUCKIDITHERING, selectRGB, i+1); break; case 3: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_BURKESDITHERING, selectRGB, i+1); break; case 4: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_SIERRADITHERING, selectRGB, i+1); break; case 5: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_STEVENSONARCEDITHERING, selectRGB, i+1); break; case 6: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_JARVISDITHERING, selectRGB, i+1); break; case 7: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_ORDEREDDITHERING, selectRGB, i+1); break; case 8: MainImageForm->iMainImage->uBitmap->ColorResolution(8, CRF_USERPALETTE|CRF_CLUSTEREDDITHERING, selectRGB, i+1); break; }*/ for (i = 1; i <= SelectColorList->Count; i++) { MainImageForm->Palette->SetNormal(i+1, selectRGB[i+1].rgbRed, selectRGB[i+1].rgbGreen, selectRGB[i+1].rgbBlue); } // MainImageForm->shiftImageData(); Âü°íÇÒ°Í! // SelectColorClick(this); // SelectColor->Down = true; SimulationCheck = true; MainImageForm->Palette->UseColor = SelectColorList->Count+1; PaletteForm->DIB256Palette->ChoiceIndex = 2; ::RepaintColor(); return; fail: if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //---------------------------------------------------------------------------