//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "Grouping_F.h" #include "MainImage.h" #include "Palette.h" #include "StatusProgress.h" #include "Undo.h" #include "Clear.h" #include "Main.h" #include "MainMenu.h" #include "NewGrouping_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzBckgnd" #pragma link "RzButton" #pragma link "RzPanel" #pragma link "RzRadGrp" #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] //--------------------------------------------------------------------------- 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() { BEGIN_LOG(""); FRed->Position = 0; FGreen->Position = 0; FBlue->Position = 0; make_rgb_cube(); SelectColorBoxes(); SortColors(); Postprocessing(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::make_rgb_cube() { BEGIN_LOG(""); 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]; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SelectColorBoxes() { BEGIN_LOG(""); 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++; } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAutoGrouping::SortColors() { BEGIN_LOG(""); int Index, c, r, b, g, i, temp;//, rsum, bsum, gsum; double rsum, bsum, gsum, rr, gg, bb; 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 { SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); END_LOG; return;} END_LOG; } //--------------------------------------------------------------------------- // 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(DirectoryBin, Language, "Grouping"); SetSmallFont(Font); SetSmallFont(atLabel1->Font); SetSmallFont(atLabel2->Font); rzbtType->Caption = IDS_TYPE; rzbtFilter->Caption = IDS_FILLTER; rzbtUser->Caption = IDS_USERCHOOSE; rzbtRearrange->Caption = IDS_REARRANGE; atLabel1->Caption = IDS_COLORNUMBER; ButtonTypeRun->Caption = IDS_COMMON_RUN; ButtonUserRun->Caption = IDS_COMMON_RUN; rzmtUserNew->Hint = IDS_COMMON_NEW; rzmtUserAll->Hint = IDS_COMMON_ALL; rzmtUserOne->Hint = IDS_COMMON_BLOCKCOLOR; rzmtUserDelete->Hint = IDS_COMMON_INSERTCOLOR; rzmtUserBefore->Hint = IDS_COMMON_BEFORECOLOR; // rzrgFilterSize->Caption = String(IDS_SIZE) + ":"; lbSize->Caption = String(IDS_SIZE) + ":"; rzmtFilterNew->Hint = IDS_COMMON_NEW; rzmtFilterAll->Hint = IDS_COMMON_ALL; rzmtFilterOne->Hint = IDS_COMMON_BLOCKCOLOR; rzmtFilterDelete->Hint = IDS_COMMON_INSERTCOLOR; rzmtFilterBefore->Hint = IDS_COMMON_BEFORECOLOR; ButtonFilterRun->Caption = IDS_COMMON_RUN; //=========================================================================== MakeMenuHintByShortcut(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzbtTypeClick(TObject *Sender) { InitItem(0); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzbtUserClick(TObject *Sender) { InitItem(1); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzbtFilterClick(TObject *Sender) { InitItem(2); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzbtRearrangeClick(TObject *Sender) { BEGIN_LOG(""); ClientHeight = 51; Rearrange(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ButtonTypeRunClick(TObject *Sender) { BEGIN_LOG(""); TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; RunType(); Screen->Cursor = cursor; ::RepaintColor(); END_LOG; // PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserNewClick(TObject *Sender) { BEGIN_LOG(""); ColorSelectorUser->Initial(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonUserAllClick(TObject *Sender) { BEGIN_LOG(""); 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; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ButtonUserRunClick(TObject *Sender) { BEGIN_LOG(""); if (Item == 1) { TCursor cursor; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; RunUser(); Screen->Cursor = cursor; ::RepaintColor(); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzrgFilterSizeClick(TObject *Sender) { FilterSize = rzrgFilterSize->ItemIndex; switch (FilterSize) { case 0: UpDown->Max = 3; break; case 1: UpDown->Max = 1; break; case 2: UpDown->Max = 0; break; } if (UpDown->Position > UpDown->Max) { UpDown->Position = UpDown->Max; } PostMessage(this->Handle, WM_UPDOWN, NULL, NULL); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::UpDownClick(TObject *Sender, TUDBtnType Button) { PostMessage(this->Handle, WM_UPDOWN, NULL, NULL); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterNewClick(TObject *Sender) { BEGIN_LOG(""); ColorSelectorFilter->Initial(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::SpeedButtonFilterAllClick(TObject *Sender) { BEGIN_LOG(""); 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; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ButtonFilterRunClick(TObject *Sender) { BEGIN_LOG(""); if (Item == 2) { TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) RunFilter_WA_IRRE(); else RunFilter_WA_NONE(); Screen->Cursor = cursor; } END_LOG; } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TGroupingForm::InitItem(int i) { Item = i; switch (Item) { case 0: //ClientHeight = PanelType->Top+PanelType->Height + 32; ClientHeight = 107; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //Parent->Height = ParentHeight+ClientHeight; //PanelType->BringToFront(); pl1->Visible = true; pl2->Visible = false; pl3->Visible = false; rzbtType->Down = true; break; case 1: //ClientHeight = PanelUser->Top+PanelUser->Height + 32; ClientHeight = 152; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //Parent->Height = ParentHeight+ClientHeight; //PanelUser->BringToFront(); pl1->Visible = false; pl2->Visible = false; pl3->Top = 58; pl3->Visible = true; rzbtUser->Down = true; break; case 2: //ClientHeight = PanelFilter->Top+PanelFilter->Height + 32; ClientHeight = 190; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //Parent->Height = ParentHeight+ClientHeight; //PanelFilter->BringToFront(); rzrgFilterSize->ItemIndex = 0; pl1->Visible = false; pl2->Top = 58; pl2->Visible = true; pl3->Visible = false; rzbtFilter->Down = true; break; } if(Step>0)MainImageForm->iMainImage->OnPaintLocate = NULL; Step = 0; MainImageForm->iMainImage->Repaint(); View(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::View() { BEGIN_LOG(""); int p = UpDown->Position; 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 { SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); MainImageForm->iMainImage->Repaint(); END_LOG; return; } UseColor = 0; for (i=1; i<252; i++) { //gabriel: background color included 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 { SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); MainImageForm->iMainImage->Repaint(); END_LOG; return; } UseColor = 0; for (i=1; i<252; i++) { //gabriel: background color included 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 -> "+ String(MaxValue)+" )"; } else if (Item==1) { ColorSelectorUser->SetPalette(MainImageForm->Palette); } else if (Item==2) { // ButtonFilterRun->SetFocus(); //lhskys ¿£ÅÍ·Î ½ÇÇàÇϱâ À§Çؼ­ focus¸¦ ÁØ´Ù rzrgFilterSize->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++) { int a = UpDown->Position; 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; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunType() { BEGIN_LOG(""); int i, x, y, yy, c; TAutoGrouping *at = NULL; Byte *scan; bool undoSw = false; TPException ec = EC_NONE; TWorkArea *wa; Byte *mp; if ((at = new TAutoGrouping(MainImageForm->iMainImage->uBitmap)) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } at->ColorNumber = TypeEdit->Value; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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)); 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; /* 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, sizeof(BITMAPHANDLE), 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, sizeof(BITMAPHANDLE), 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; END_LOG; return; fail: if (at) { MainImageForm->iMainImage->uBitmap->StopScanLine(); MainImageForm->Undo->RemoveLast(); delete at; } if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunUser() { BEGIN_LOG(""); 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(); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunUser_none() { BEGIN_LOG(""); 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]; TPException ec = EC_NONE; 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (wa->Mask) { if(!wa->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (wa->Mask) { if(!wa->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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); END_LOG; return; fail: if (wa->Mask) wa->Mask->StopScanLine(); tb->StopScanLine(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunUser_layer() { BEGIN_LOG(""); 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]; TPException ec = EC_NONE; 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (wa->Mask) { if(!wa->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (wa->Mask) { if(!wa->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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); END_LOG; return; fail: if (wa->Mask) wa->Mask->StopScanLine(); tb->StopScanLine(); if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunFilter_WA_NONE() { BEGIN_LOG(""); ///* 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 TPException ec = EC_NONE; Sbmp = MainImageForm->iMainImage->uBitmap; if ((undoSw = MainImageForm->UndoSave(UK_ALL, Rect(0, 0, Sbmp->Width, Sbmp->Height))) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Sbmp->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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(); END_LOG; return; fail: Sbmp->StopScanLine(); Ubmp->StopUndoScanLine(); if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; //*/ } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::RunFilter_WA_IRRE() { BEGIN_LOG(""); ///* 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 TPException ec = EC_NONE; #if defined(TEXSTYLIST) if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!Sbmp->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } Usl[0] = Ubmp->GetUndoScanLineN(sy+0, 0)+sx; Usl[1] = Ubmp->GetUndoScanLineN(sy+1, 1)+sx; if (!Mbmp->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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(); END_LOG; return; fail: Mbmp->StopScanLine(); Sbmp->StopScanLine(); Ubmp->StopUndoScanLine(); if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); END_LOG; //*/ /* 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(TEXSTYLIST) if ((undoSw = MainImageForm->UndoSave(UK_ALL, MainImageForm->WorkArea->Range)) == 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) { BEGIN_LOG(""); 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) { END_LOG; return p; } } END_LOG; return List->Count; } //--------------------------------------------------------------------------- void __fastcall RunRearrange(bool undo) { BEGIN_LOG(""); 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); //GroupingForm¸¦ Ãß°¡ 080405 if (GroupingForm && !GroupingForm->RunRearrange_none() && undo) MainImageForm->Undo->RemoveLast(); } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TGroupingForm::RunRearrange_none() { BEGIN_LOG(""); 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]; TPException ec = EC_NONE; if (MainImageForm->Palette->UseColor>2) { if ((ChoiceColor = new TChoiceColor) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((List = new TList) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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); MainImageForm->Palette->ColorData[pOrder->no]->Protect = 0; // ÀÌÀü ÆÈ·¹Æ®ÀÇ º¸È£»ö ÇØÁ¦ - by monkman (2009.09.10) } if (!MainImageForm->iMainImage->uBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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]; MainImageForm->Palette->ColorData[i+2]->Protect = ChoiceColor->ColorMap[i]->Protect; // Àç¹è¿­µÈ ÆÈ·¹Æ®ÀÇ º¸È£»öÀ¸·Î ¼³Á¤ - by monkman (2009.09.10) } 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; END_LOG; 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); END_LOG; return false; } //--------------------------------------------------------------------------- bool __fastcall TGroupingForm::RunRearrange_layer() { BEGIN_LOG(""); 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 TPException ec = EC_NONE; if (MainImageForm->Palette->UseColor>2) { if ((ChoiceColor = new TChoiceColor) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((List = new TList) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); 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; END_LOG; 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); END_LOG; 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() { BEGIN_LOG(""); if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) { /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //ParentHeight = Parent->Height+20 + 32; ClientHeight = 70; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //Parent->Height = ParentHeight + ClientHeight; rzbtType->Enabled = false; rzbtUser->Enabled = false; rzbtFilter->Enabled = false; rzbtRearrange->Enabled = true; } else { /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //ParentHeight = Parent->Height+20; FilterSize = 0; MaxValue = 255; ColorSelectorFilter->Initial(); ColorSelectorUser->Initial(); if (MainImageForm->iMainImage->LayerList->Count > 1) { rzbtUser->Down = true; rzbtType->Enabled = false; InitItem(1); } else { rzbtType->Down = true; InitItem(0); } } } else { rzbtType->Enabled = false; rzbtUser->Enabled = false; rzbtFilter->Enabled = false; rzbtRearrange->Enabled = false; /// °¢ Formµé µ¶¸³ÀûÀ¸·Î °ü¸®Çϱâ À§ÇØ ÁÖ¼®Ã³¸® //Parent->Height = Parent->Height + 20 + 90; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ExitForm() { if (Step > 0){ Step = 0; MainImageForm->iMainImage->OnPaintLocate = NULL; MainImageForm->iMainImage->Repaint(); } ColorSelectorFilter->SaveToFile(AppDataItem + "\\Grouping.Ini", "ColorSelector(Filter)"); ColorSelectorUser->SaveToFile(AppDataItem + "\\Grouping.Ini", "ColorSelector(UserChoose)"); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImageMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { BEGIN_LOG(""); 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 = rzmtUserOne->Down; Delete = rzmtUserDelete->Down; ColorSelector = ColorSelectorUser; sw = true; break; case 2: One = rzmtFilterOne->Down; Delete = rzmtFilterDelete->Down; ColorSelector = ColorSelectorFilter; sw = true; break; default: sw = false; break; } if (sw) { tb = MainImageForm->iMainImage->uBitmap; if (One) { if (Delete) { ColorSelector->DeleteColor(tb->GetPixelColor(X, Y)); } 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; ixAddColor(*(bp+ix)); } } } tb->StopScanLine(); } else { SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); END_LOG; 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; } } } } END_LOG; return; fail: if (undoSw == true) MainImageForm->Undo->RemoveLast(); SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImageMouseMove(TShiftState Shift, int X, int Y) { bool sw; bool One; switch (Item) { case 1: One = rzmtUserOne->Down; sw = true; break; case 2: One = rzmtFilterOne->Down; 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; } } } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImagePaint() { IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::TypeEdit_Change(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 { BEGIN_LOG(""); TCursor cursor; MainMenuForm->showGrouping = false; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; RunRearrange(); Screen->Cursor = cursor; ::RepaintColor(); END_LOG; //PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); by Altang } //---------------------------------------------------------------------------- void __fastcall TGroupingForm::iMainImageKeyDown(WORD Key, TShiftState Shift) //lhskys »öÁ¤¸®¿¡¼­ { // °¢°¢Àǰæ¿ì¿¡ µû¶ó if ( Key == VK_RETURN ) { // ¿£ÅÍŰ·Î ½ÇÇàÇϱâ if (rzbtUser->Down == true)ButtonUserRunClick(this); if (rzbtType->Down == true)ButtonTypeRunClick(this); if (rzbtFilter->Down == true)ButtonFilterRunClick(this); } } //---------------------------------------------------------------------------- void __fastcall TGroupingForm::TypeEdit_Click(TObject *Sender) { TypeEdit->SelectAll(); TypeEdit->SetFocus(); } //--------------------------------------------------------------------------- //void TGroupingForm::TPMExitFunction(TMessage &msg) //{ // if (NewGroupingForm) { // NewGroupingForm->ExitForm(); // delete NewGroupingForm; NewGroupingForm = NULL; // MainMenuForm->Item = T_GROUP; // // MainForm->FileItem->Enabled = true; // 05.07.30 by maxleo21c // MainForm->EditItem->Enabled = true; // MainForm->CaptureItem->Enabled = true; // MainForm->ImageItem->Enabled = true; // MainForm->ViewItem->Enabled = true; // MainForm->WindowItem->Enabled = true; // MainForm->HelpItem->Enabled = true; // // PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); // } //} ////--------------------------------------------------------------------------- void __fastcall TGroupingForm::Type1Click(TObject *Sender) { TSpeedButton *sp = (TSpeedButton *)Sender; switch(sp->Tag){ case 1 : GroupingForm->InitItem(0); break; case 2 : GroupingForm->InitItem(1); break; case 3 : GroupingForm->InitItem(2); break; case 4 : GroupingForm->Rearrange(); break; } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::MakeMenuHintByShortcut() { BEGIN_LOG(""); rzbtType->Hint = TexActionManager->GetHint("ColorGrouping", "AutoBy256"); rzbtFilter->Hint = TexActionManager->GetHint("ColorGrouping", "FilterBy256"); rzbtUser->Hint = TexActionManager->GetHint("ColorGrouping", "ColorChooseBy256"); rzbtRearrange->Hint = TexActionManager->GetHint("ColorGrouping", "RearrangeBy256"); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::ExecuteHotKey(String command) { if (command == "AutoBy256") { if (rzbtType->Down == false) InitItem(0); rzbtType->Down = true; } else if (command == "FilterBy256") { if (rzbtFilter->Down == false) InitItem(2); rzbtFilter->Down = true; } else if (command == "ColorChooseBy256") { if (rzbtUser->Down == false) InitItem(1); rzbtUser->Down = true; } else if (command == "RearrangeBy256") { Rearrange(); } } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtFilterNewClick(TObject *Sender) { BEGIN_LOG(""); ColorSelectorFilter->Initial(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtFilterAllClick(TObject *Sender) { BEGIN_LOG(""); 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; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtFilterOneClick(TObject *Sender) { if (rzmtFilterOne->Down) rzmtFilterOne->Hint = IDS_COMMON_ONECOLOR; else rzmtFilterOne->Hint = IDS_COMMON_BLOCKCOLOR; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtFilterDeleteClick(TObject *Sender) { if (rzmtFilterDelete->Down) rzmtFilterDelete->Hint = IDS_COMMON_DELETECOLOR; else rzmtFilterDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtFilterBeforeClick(TObject *Sender) { ColorSelectorFilter->LoadFromFile(AppDataItem + "\\Grouping.Ini", "ColorSelector(Filter)"); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtUserNewClick(TObject *Sender) { BEGIN_LOG(""); ColorSelectorUser->Initial(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtUserAllClick(TObject *Sender) { BEGIN_LOG(""); 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; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtUserOneClick(TObject *Sender) { BEGIN_LOG(""); if (rzmtUserOne->Down) rzmtUserOne->Hint = IDS_COMMON_ONECOLOR; else rzmtUserOne->Hint = IDS_COMMON_BLOCKCOLOR; InitLocate(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtUserDeleteClick(TObject *Sender) { if (rzmtUserDelete->Down) rzmtUserDelete->Hint = IDS_COMMON_DELETECOLOR; else rzmtUserDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::rzmtUserBeforeClick(TObject *Sender) { ColorSelectorUser->LoadFromFile(AppDataItem + "\\Grouping.Ini", "ColorSelector(UserChoose)"); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::WmUpDownUpdate(TMessage &msg) { View(); } //--------------------------------------------------------------------------- void __fastcall TGroupingForm::TypeEditKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { if (Key == VK_RETURN) { if (rzbtUser->Down == true)ButtonUserRunClick(this); if (rzbtType->Down == true)ButtonTypeRunClick(this); if (rzbtFilter->Down == true)ButtonFilterRunClick(this); } } //---------------------------------------------------------------------------