//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "MainImage.h" #include "PenManager.h" #include "NewGrouping_F.h" #include "Palette.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPSpin" #pragma link "TPImage" #pragma link "TPLayerImage" #pragma link "RXSlider" #pragma link "ToolEdit" #pragma link "RXSpin" #pragma resource "*.dfm" TNewGroupingForm *NewGroupingForm; //--------------------------------------------------------------------------- __fastcall TNewGroupingForm::TNewGroupingForm(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *)Owner)->Handle; //=========================================================== // StringTable.Create(DirectoryCommon, Language, "NewGrouping"); // SetSmallFont(Font); //=========================================================== Image->OnPaintDirectly=GroupPaintDirectly; this->Left = 0; this->Top = 0; SelectColorListAdd = false; isDrawingRegion = false; isFirst = true; freedraw = false; originalBitmap = NULL; previewBitmap = NULL; processingBitmap = NULL; subViewBitmap = NULL; resultBitmap = NULL; compareMethod = NULL; previewType = TYPE_ALL; cbGroupingType->Items->Add("Ball"); cbGroupingType->Items->Add("Cube"); cbGroupingType->Items->Add("Ball(Weight)"); cbGroupingType->Items->Add("Cube(Weight)"); cbGroupingType->Items->Add("User RGB (+ and -)"); isNewProcess = false; CompareBitmap = NULL; msx = NULL; memsize = 0; hMemLine = NULL; NewGroupingStart = false; ColorCount = 0; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::InitForm() { initBitmaps(); // by celberus addOneGroupColor(); selectGroupingItem(0); ColorCount++; NewGroupingStart = true; mustNotDelete = false; advToleranceValue = 0; isDragImage = false; trimmer = NULL; // n initBrushMenu(); // n initFunctionMenu(); // n cbGroupingType->ItemIndex = 0; if (compareMethod) delete compareMethod; compareMethod = (CompareMethod *) new CompareMethod_Ball; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ExitForm() { if (trimmer) delete trimmer; // n deleteBitmaps(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::FormClose(TObject *Sender, TCloseAction &Action) { if(CompareBitmap){ delete CompareBitmap; CompareBitmap = NULL; } PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initBitmaps() { int w, h; TRect Src = Rect(0, 0, 0, 0); if (MainImageForm->WorkArea->Mask) { Src = MainImageForm->WorkArea->Range; w = Src.Right-Src.Left; h = Src.Bottom-Src.Top; }else { w = MainImageForm->iMainImage->uBitmap->Width; h = MainImageForm->iMainImage->uBitmap->Height; } try { originalBitmap = Image->uBitmap; if (!originalBitmap->Create(w, h, 24)) throw EC_MEMORY_LACK; originalBitmap->CopyFromRect(MainImageForm->iMainImage->uBitmap, Src.left, Src.top, SRCCOPY); if (!previewBitmap) { if ((previewBitmap = new TUnionBitmap)==NULL) throw EC_MEMORY_LACK; if (!previewBitmap->Create(w, h, 24)) throw EC_MEMORY_LACK; previewBitmap->Copy(originalBitmap, SRCCOPY); } if (!processingBitmap) { if ((processingBitmap = new TUnionBitmap)==NULL) throw EC_MEMORY_LACK; if (!processingBitmap->Create(w, h, 24)) throw EC_MEMORY_LACK; } if (!subViewBitmap) { if ((subViewBitmap = new TUnionBitmap)==NULL) throw EC_MEMORY_LACK; if (!subViewBitmap->Create(w, h, 24)) throw EC_MEMORY_LACK; } Image->uBitmap = previewBitmap; } catch(TPException ec) { if (originalBitmap != NULL) { originalBitmap->Destroy(); } if (previewBitmap != NULL) { delete previewBitmap; previewBitmap = NULL; } if (processingBitmap != NULL) { delete processingBitmap; processingBitmap = NULL; } if (subViewBitmap != NULL) { delete subViewBitmap; subViewBitmap = NULL; } EXCEPTION_MESSAGE_OK(ec); /* TODO : exception ó¸® Á¦´ë·Î ÇÒ°Í */ } AllocLineMem(h); /* TODO : µû·Î »¬°Í */ updateImage(); Image->Repaint(); return; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::deleteBitmaps() { if(previewBitmap){ delete previewBitmap; previewBitmap = NULL; } if(processingBitmap){ delete processingBitmap; processingBitmap = NULL; } if(subViewBitmap){ delete subViewBitmap; subViewBitmap = NULL; } Image->uBitmap = originalBitmap; // originalBitmap Àº ~TPLayerImage¿¡¼­ Áö¿öÁØ´Ù. } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::fixColor(int number) { TColor fillColor = groupingItemSet.getCurrentColor(); TUnionBitmap *fillMask = groupingItemSet.getCurrentMask(); fillPreviewImage(fillMask, fillColor); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::fillPreviewImage(TUnionBitmap *fillMask, TColor fillColor) { Byte *pMask, *pPreview; int x, y; previewBitmap->StartScanLine(); fillMask->StartScanLine(); for (y = 0; y < previewBitmap->Height; y++ ) { pPreview = previewBitmap->GetScanLine(y); pMask = fillMask->GetScanLine(y); for (x = 0; x < previewBitmap->Width; x++ ) { if (pMask[x >> 3] & (0x80 >> (x & 7))) { pPreview[0] = (fillColor >> 16 ) & 0xFF; pPreview[1] = (fillColor >> 8 ) & 0xFF; pPreview[2] = (fillColor ) & 0xFF; } pPreview += 3; } previewBitmap->PutScanLine(y); } previewBitmap->StopScanLine(); fillMask->StopScanLine(); makeSubView(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::recoverColor(int number) { TUnionBitmap *maskBitmap = groupingItemSet.getItem(number)->getMask(); TUnionBitmap *tempBitmap = new TUnionBitmap; tempBitmap->Create(maskBitmap->Width, maskBitmap->Height, 1); tempBitmap->Copy(maskBitmap, NOTSRCCOPY); previewBitmap->MergeBitmap(originalBitmap, tempBitmap); delete tempBitmap; makeSubView(); if (RadioSelection->Checked) drawProcessingBitmap(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::RadioImageClick(TObject *Sender) { sbFree->Enabled = false; sbSquare->Enabled = false; sbRectangle->Enabled = false; sbCircle->Enabled = false; sbEllipse->Enabled = false; isFirst = true; isDrawingRegion = false; colorSelectionStep = 0; brushState = FIRST_POINT; if (previewType == TYPE_ALL) { Image->uBitmap = previewBitmap; // by celberus } else { Image->uBitmap = subViewBitmap; } Image->isRepaintAll = true; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::RadioSelectionClick(TObject *Sender) { sbFree->Enabled = true; sbSquare->Enabled = true; sbRectangle->Enabled = true; sbCircle->Enabled = true; sbEllipse->Enabled = true; Image->uBitmap = processingBitmap; // by celberus Image->isRepaintAll = true; // toleranceChange(); // by celberus // drawProcessingBitmap(); Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::RadioOriginalClick(TObject *Sender) { sbFree->Enabled = false; sbSquare->Enabled = false; sbRectangle->Enabled = false; sbCircle->Enabled = false; sbEllipse->Enabled = false; Image->uBitmap = originalBitmap; // by celberus Image->isRepaintAll = true; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (isDragImage) { dragPointEnd = Point(X, Y); // iMainImageChange(); Image->SetPosition(Image->PositionX-(dragPointEnd.x - dragPointStart.x), Image->PositionY-(dragPointEnd.y - dragPointStart.y)); isDragImage = false; } if(freedraw){ freedraw = false; isDrawingRegion = false; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { RECT r, gr; bool sw, One; bool undoSw = false; int i, j, ix, iy; int rgb[3][256]; TUnionBitmap *tb; Byte *bp; unsigned long int temp_red = 0, temp_green = 0, temp_blue = 0, total_pixel = 0; COLORREF color; memset(rgb, 0, 3*256*4); if(NewGroupingStart == false)return; if (Shift.Contains(ssCtrl) && Button==mbLeft) { isDragImage = true; Image->Cursor = crHandPoint; dragPointStart = Point(X, Y); }else if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { // if (isNewProcess && functionType == FUNC_RESET) { if (functionMenu.getCurrentFunction() == FUNC_RESET) { groupResetMouseDown(X, Y); } else if (functionMenu.getCurrentFunction() == FUNC_COLOR_ADD) { colorAddMouseDown(X, Y); } // } else if (isNewProcess && functionType == FUNC_COLOR_ADD) { // colorAddMouseDown(X, Y); // } else { // colorSelectionMouseDown(X, Y); // } }else if(Button==mbLeft) { if (functionMenu.getCurrentFunction() == FUNC_TRIMMER) { trimmerMouseDown(X, Y); } else if (functionMenu.getCurrentFunction() == FUNC_SIMPLIFY) { simplifyMouseDown(X, Y); } else if (functionMenu.getCurrentFunction() == FUNC_AREA_ADD) { if(RadioSelection->Checked){ if(sbFree->Down){ freedraw = true; isDrawingRegion = true; SpecialMouseDown(Button, Shift, X, Y); }else 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 { // ¿µ¿ªÀ» ¼³Á¤ÇÑ ÈÄ °áÁ¤ÇÏ´Â ÀǹÌÀÇ Å¬¸¯À̸é RECT drawRect; isFirst = true; isDrawingRegion = false; drawRect = Region_rect; if (Region_rect.right < Region_rect.left) { drawRect.left = Region_rect.right; drawRect.right = Region_rect.left; } if (Region_rect.bottom < Region_rect.top) { drawRect.top = Region_rect.bottom; drawRect.bottom = Region_rect.top; } Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; NewGroupingDrawRectangleLocate(Region_rect); drawRectangleSelection(drawRect, sbDelete->Down); Image->Repaint(); } }else if(sbRectangle->Down){ if(isFirst) { // ¿µ¿ªÀ» ±×¸®±â À§ÇÑ Ã¹¹øÂ° Ŭ¸¯À̸é isFirst = false; isDrawingRegion = true; Region_rect.left = X; Region_rect.right = X; Region_rect.top = Y; Region_rect.bottom = Y; //NewGroupingDrawRectangleLocate(Region_rect); }else { // ¿µ¿ªÀ» ¼³Á¤ÇÑ ÈÄ °áÁ¤ÇÏ´Â ÀǹÌÀÇ Å¬¸¯À̸é RECT drawRect; isFirst = true; isDrawingRegion = false; drawRect = Region_rect; if (Region_rect.right < Region_rect.left) { drawRect.left = Region_rect.right; drawRect.right = Region_rect.left; } if (Region_rect.bottom < Region_rect.top) { drawRect.top = Region_rect.bottom; drawRect.bottom = Region_rect.top; } Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; NewGroupingDrawRectangleLocate(Region_rect); drawRectangleSelection(drawRect, sbDelete->Down); Image->Repaint(); } }else if(sbCircle->Down){ if(isFirst){ isFirst = false; isDrawingRegion = true; c_x = X; c_y = Y; circle_r = 0; }else { RECT drawRect; isFirst = true; isDrawingRegion = false; drawRect = Region_rect; Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; NewGroupingDrawEllipseLocate(Region_rect); drawCircleSelection(drawRect, sbDelete->Down); Image->Repaint(); } }else if(sbEllipse->Down){ if(isFirst){ isFirst = false; isDrawingRegion = true; c_x = X; c_y = Y; }else { RECT drawRect; isFirst = true; isDrawingRegion = false; drawRect = Region_rect; Region_rect.left = 0; // ¸¶Áö¸·¿¡ ¾Èº¸ÀÌ°Ô Çϱâ À§ÇÔ Region_rect.right = 0; Region_rect.top = 0; Region_rect.bottom = 0; NewGroupingDrawEllipseLocate(Region_rect); drawEllipseSelection(drawRect, sbDelete->Down); Image->Repaint(); } } } } } return; fail: if (undoSw == true) MainImageForm->Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::drawRectangleSelection(RECT drawRect, bool isDelete) { int x, y; Byte *pMask, *pWholeMask; TUnionBitmap *drawMask = groupingItemSet.getCurrentMask(); TUnionBitmap *wholeMask = groupingItemSet.getWholeMask(); if (drawRect.left < 0) drawRect.left = 0; if (drawRect.right >= drawMask->Width) drawRect.right = drawMask->Width; if (drawRect.top < 0) drawRect.top = 0; if (drawRect.bottom >= drawMask->Height) drawRect.bottom = drawMask->Height; if (groupingItemSet.getCurrentItem()->isLocked()) return; if (wholeMask == NULL) { drawMask->StartScanLine(); for (y = drawRect.top; y <= drawRect.bottom; y++) { pMask = drawMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); for (x = drawRect.left; x <= drawRect.right; x++) { if (isDelete) { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } else { pMask[x >> 3] |= (0x80 >> (x & 7)); } } drawMask->PutScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); } drawMask->StopScanLine(); } else { drawMask->StartScanLine(); wholeMask->StartScanLine(); for (y = drawRect.top; y <= drawRect.bottom; y++) { pMask = drawMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); pWholeMask = wholeMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); for (x = drawRect.left; x <= drawRect.right; x++) { if (!(pWholeMask[x >> 3] & (0x80 >> (x & 7)))) { if (isDelete) { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } else { pMask[x >> 3] |= (0x80 >> (x & 7)); } } } drawMask->PutScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); } drawMask->StopScanLine(); wholeMask->StopScanLine(); } drawProcessingBitmap(drawRect); groupingItemSet.updateMask(drawRect); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::drawCircleSelection(RECT drawRect, bool isDelete) { int x, y; Byte *pMask, *pWholeMask; TUnionBitmap *drawMask = groupingItemSet.getCurrentMask(); TUnionBitmap *wholeMask = groupingItemSet.getWholeMask(); if (drawRect.left < 0) drawRect.left = 0; if (drawRect.right >= drawMask->Width) drawRect.right = drawMask->Width; if (drawRect.top < 0) drawRect.top = 0; if (drawRect.bottom >= drawMask->Height) drawRect.bottom = drawMask->Height; if (groupingItemSet.getCurrentItem()->isLocked()) return; if (wholeMask == NULL) { drawMask->StartScanLine(); for (y = drawRect.top; y <= drawRect.bottom; y++) { pMask = drawMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); for (x = drawRect.left; x <= drawRect.right; x++) { if((double)circle_r >= (double)sqrt((double)((c_x - x) * (c_x - x)) + (double)((c_y - y) * (c_y - y)))){ if (isDelete) { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } else { pMask[x >> 3] |= (0x80 >> (x & 7)); } } } drawMask->PutScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); } drawMask->StopScanLine(); } else { drawMask->StartScanLine(); wholeMask->StartScanLine(); for (y = drawRect.top; y <= drawRect.bottom; y++) { pMask = drawMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); pWholeMask = wholeMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); for (x = drawRect.left; x <= drawRect.right; x++) { if (!(pWholeMask[x >> 3] & (0x80 >> (x & 7)))) { if((double)circle_r >= (double)sqrt((double)((c_x - x) * (c_x - x)) + (double)((c_y - y) * (c_y - y)))){ if (isDelete) { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } else { pMask[x >> 3] |= (0x80 >> (x & 7)); } } } } drawMask->PutScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); } drawMask->StopScanLine(); wholeMask->StopScanLine(); } drawProcessingBitmap(drawRect); groupingItemSet.updateMask(drawRect); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::drawEllipseSelection(RECT drawRect, bool isDelete) { int x, y; int ellipse_width, ellipse_height; Byte *pMask, *pWholeMask; if (groupingItemSet.getCurrentItem()->isLocked()) return; TUnionBitmap *drawMask = groupingItemSet.getCurrentMask(); TUnionBitmap *wholeMask = groupingItemSet.getWholeMask(); if (drawRect.left < 0) drawRect.left = 0; if (drawRect.right >= drawMask->Width) drawRect.right = drawMask->Width; if (drawRect.top < 0) drawRect.top = 0; if (drawRect.bottom >= drawMask->Height) drawRect.bottom = drawMask->Height; ellipse_width = Region_rect.right - c_x; ellipse_height = Region_rect.bottom - c_y; if (wholeMask == NULL) { drawMask->StartScanLine(); for (y = drawRect.top; y <= drawRect.bottom; y++) { pMask = drawMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); for (x = drawRect.left; x <= drawRect.right; x++) { if((double)1 >= (double)((x - c_x) * (x - c_x)) / (double)(ellipse_width * ellipse_width) + (double)((y - c_y) * (y - c_y)) / (double)(ellipse_height * ellipse_height)){ if (isDelete) { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } else { pMask[x >> 3] |= (0x80 >> (x & 7)); } } } drawMask->PutScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); } drawMask->StopScanLine(); } else { drawMask->StartScanLine(); wholeMask->StartScanLine(); for (y = drawRect.top; y <= drawRect.bottom; y++) { pMask = drawMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); pWholeMask = wholeMask->GetScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); for (x = drawRect.left; x <= drawRect.right; x++) { if (!(pWholeMask[x >> 3] & (0x80 >> (x & 7)))) { if((double)1 >= (double)((x - c_x) * (x - c_x)) / (double)(ellipse_width * ellipse_width) + (double)((y - c_y) * (y - c_y)) / (double)(ellipse_height * ellipse_height)){ if (isDelete) { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } else { pMask[x >> 3] |= (0x80 >> (x & 7)); } } } } drawMask->PutScanLine(y, drawRect.left, drawRect.right - drawRect.left + 1); } drawMask->StopScanLine(); wholeMask->StopScanLine(); } drawProcessingBitmap(drawRect); groupingItemSet.updateMask(drawRect); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::SetHLineMask(int x, int y, int len) { Byte *pMask, *pWholeMask; TUnionBitmap *drawMask = groupingItemSet.getCurrentMask(); TUnionBitmap *wholeMask = groupingItemSet.getWholeMask(); if (wholeMask == NULL) { pMask = drawMask->GetScanLine(y, x, len); for (int i = x; i < x + len; i++) { if (sbDelete->Down) { pMask[i >> 3] &= ~(0x80 >> (i & 7)); } else { pMask[i >> 3] |= (0x80 >> (i & 7)); } } drawMask->PutScanLine(y, x, len); } else { pMask = drawMask->GetScanLine(y, x, len); pWholeMask = wholeMask->GetScanLine(y, x, len); for (int i = x; i < x + len; i++) { if (!(pWholeMask[i >> 3] & (0x80 >> (i & 7)))) { if (sbDelete->Down) { pMask[i >> 3] &= ~(0x80 >> (i & 7)); } else { pMask[i >> 3] |= (0x80 >> (i & 7)); } } } drawMask->PutScanLine(y, x, len); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::colorSelectionMouseDown(int X, int Y) { RECT r; bool oneColor; COLORREF color; if(!RadioImage->Checked)return; oneColor = sbBlock->Down; if (oneColor) { color = Image->uBitmap->GetPixelColor(X, Y); groupingItemSet.setCurrentColor((TColor)color); RadioSelection->Enabled = true; } else { if (colorSelectionStep>0) { colorSelectionArea.right = X; colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); if (colorSelectionArea.left>colorSelectionArea.right) { r.left = colorSelectionArea.right; r.right = colorSelectionArea.left; } else { r.left = colorSelectionArea.left; r.right = colorSelectionArea.right; } if (colorSelectionArea.top>colorSelectionArea.bottom) { r.top = colorSelectionArea.bottom; r.bottom = colorSelectionArea.top; } else { r.top = colorSelectionArea.top; r.bottom = colorSelectionArea.bottom; } color = getAverageColor(r); groupingItemSet.setCurrentColor((TColor)color); RadioSelection->Enabled = true; NewGroupingDrawRectangleLocate(colorSelectionArea); colorSelectionStep = 0; IsDraw = false; Image->OnPaintLocate = NULL;/////////////////by jeegeo Image->Repaint(); } else { colorSelectionArea.left = colorSelectionArea.top = X; colorSelectionArea.top = colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); IsDraw = true; colorSelectionStep = 11; } } } //--------------------------------------------------------------------------- COLORREF TNewGroupingForm::getAverageColor(RECT imageRect) { Byte *bp; TUnionBitmap *theBitmap = Image->uBitmap; int ix, iy; COLORREF color; int rgb[3][256]; unsigned long temp_red = 0, temp_green = 0, temp_blue = 0, total_pixel = 0; memset(rgb, 0, 3*256*4); if (theBitmap->StartScanLine()) { for (iy=imageRect.top; iyGetScanLine(iy) + 3*imageRect.left; for (ix=imageRect.left; ixStopScanLine(); for (int i = 0; i < 256; i++) { if (rgb[0][i]) temp_red += i*rgb[0][i]; if (rgb[1][i]) temp_green += i*rgb[1][i]; if (rgb[2][i]) temp_blue += i*rgb[2][i]; } if(total_pixel != 0){ temp_red /= total_pixel; temp_green /= total_pixel; temp_blue /= total_pixel; } color = (temp_blue << 16) + (temp_green << 8) + temp_red; return color; } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return 0;} } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::AverageColorPaint() { TNewSelectColorList *Temp; TShape *s; Temp = (TNewSelectColorList *)(SelectColorList->Items[SelectNum]); s = (TShape *)scColor[SelectNum]; s->Brush->Color = Temp->color; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { bool sw; bool One; TUnionBitmap *tb; int i, j; Byte *bp; if (brushMenu.getCurrentBrush() == BR_RECTANGLE && brushMenu.brushState == SECOND_POINT) { if (IsDraw) NewGroupingDrawRectangleLocate(colorSelectionArea); colorSelectionArea.right = X; colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); IsDraw = true; Image->Repaint(); } /* if (colorSelectionStep>0) { if (IsDraw) NewGroupingDrawRectangleLocate(colorSelectionArea); colorSelectionArea.right = X; colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); IsDraw = true; Image->Repaint(); } if (isDragImage) { POINT pt; dragPointEnd = Point(X, Y); pt.x = dragPointEnd.x-dragPointStart.x; pt.y = dragPointEnd.y-dragPointStart.y; Image->SetPosition(Image->PositionX-pt.x, Image->PositionY-pt.y); dragPointStart.x = dragPointEnd.x-pt.x; dragPointStart.y = dragPointEnd.y-pt.y; } if(isDrawingRegion){ if(sbFree->Down){ if(freedraw){ SpecialMouseMove(Shift, X, Y); } }else 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); } NewGroupingDrawRectangleLocate(Region_rect); }else if(sbRectangle->Down){ Region_rect.right = X; Region_rect.bottom = Y; NewGroupingDrawRectangleLocate(Region_rect); }else if(sbCircle->Down){ unsigned int min_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 > Image->uBitmap->Width - c_x) min_r = Image->uBitmap->Width - c_x; if(min_r > Image->uBitmap->Height - c_y) min_r = Image->uBitmap->Height - c_y; if(Region_rect.left < 0 || Region_rect.right > Image->uBitmap->Width || Region_rect.top < 0 || Region_rect.bottom > Image->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; NewGroupingDrawEllipseLocate(Region_rect); }else if(sbEllipse->Down){ unsigned 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 > Image->uBitmap->Width) { min_w = c_x; if(min_w > Image->uBitmap->Width - c_x) min_w = Image->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 > Image->uBitmap->Height) { min_h = c_y; if(min_h > Image->uBitmap->Height - c_y) min_h = Image->uBitmap->Height - c_y; Region_rect.top = c_y - min_h; Region_rect.bottom = c_y + min_h; } NewGroupingDrawEllipseLocate(Region_rect); } Image->Repaint(); } */ } //--------------------------------------------------------------------------- void TNewGroupingForm::NewGroupingDrawRectangleLocate(RECT rc,int NOR) { static RECT oldrc=Rect(0,0,0,0); Image->OnPaintLocate = GroupPaintRectangleLocate; FloatingRect.left = Image->BitmapToCanvasX(min(rc.left,rc.right)); FloatingRect.right = Image->BitmapToCanvasX(max(rc.left,rc.right)); FloatingRect.top = Image->BitmapToCanvasY(min(rc.top,rc.bottom)); FloatingRect.bottom = Image->BitmapToCanvasY(max(rc.top,rc.bottom)); InvalidateRect(this->Handle,&oldrc,false); InvalidateRect(this->Handle,&FloatingRect,false); oldrc=FloatingRect; } //--------------------------------------------------------------------------- void TNewGroupingForm::NewGroupingDrawEllipseLocate(RECT rc,int NOE) { static RECT oldrc=Rect(0,0,0,0); Image->OnPaintLocate = GroupPaintEllipseLocate; FloatingRect.left = Image->BitmapToCanvasX(min(rc.left,rc.right)); FloatingRect.right = Image->BitmapToCanvasX(max(rc.left,rc.right)); FloatingRect.top = Image->BitmapToCanvasY(min(rc.top,rc.bottom)); FloatingRect.bottom = Image->BitmapToCanvasY(max(rc.top,rc.bottom)); InvalidateRect(this->Handle,&oldrc,false); InvalidateRect(this->Handle,&FloatingRect,false); oldrc=FloatingRect; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::sbVertScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { Image->PositionY = sbVert->Position; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::sbHorzScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { Image->PositionX = sbHorz->Position; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::updateImage() { TPoint Size; Size.x = Panel1->Width*Image->ZoomOut/Image->ZoomIn; Size.y = Panel1->Height*Image->ZoomOut/Image->ZoomIn; if (Image->uBitmap->WidthMax = 0; else sbHorz->Max = Image->uBitmap->Width-Size.x; sbHorz->SmallChange = sbHorz->Max/10; sbHorz->LargeChange = sbHorz->Max/5; if (Image->uBitmap->HeightMax = 0; else sbVert->Max = Image->uBitmap->Height-Size.y; sbVert->SmallChange = sbVert->Max/10; // SmallChange´Â Àüü »çÀÌÁîÀÇ 1/10 sbVert->LargeChange = sbVert->Max/5; // LargeChange´Â Àüü »çÀÌÁîÀÇ 1/5 } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ZoomChange(int zi, int zo, POINT *ptScreen) { POINT ptClient; AnsiString sbZoom; if (zi!=Image->ZoomIn || zo!=Image->ZoomOut) { Image->isZoomChanged = true; if (ptScreen) { ptClient = Image->ScreenToClient(*ptScreen); Image->SetZoom(zi, zo, &ptClient); } else { Image->SetZoom(zi, zo); } } ShowZoomText(); updateImage(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ShowZoomText() { AnsiString sbZoom; switch (Image->ZoomIn) { case 1: switch (Image->ZoomOut) { case 1: sbZoom = "1"; break; case 2: sbZoom = "1/2"; break; case 3: sbZoom = "1/3"; break; case 4: sbZoom = "1/4"; break; case 6: sbZoom = "1/6"; break; case 8: sbZoom = "1/8"; break; case 12: sbZoom = "1/12"; break; case 16: sbZoom = "1/16"; break; } break; case 2: switch (Image->ZoomOut) { case 1: sbZoom = "2"; break; case 3: sbZoom = "2/3"; break; } break; case 3: switch (Image->ZoomOut) { case 1: sbZoom = "3"; break; case 2: sbZoom = "3/2"; break; } break; case 4: sbZoom = "4"; break; case 6: sbZoom = "6"; break; case 8: sbZoom = "8"; break; case 12: sbZoom = "12"; break; case 16: sbZoom = "16"; break; } ZoomEdit->Text = sbZoom; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::GroupPaintRectangleLocate(TObject *Sender, HDC formDC) { RECT rc = FloatingRect; HBRUSH hOldBrush=NULL; HPEN hOldPen=NULL; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); Rectangle(formDC, min(rc.left, rc.right)+1, min(rc.top, rc.bottom)+1, max(rc.left, rc.right), max(rc.top, rc.bottom)); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::GroupPaintEllipseLocate(TObject *Sender, HDC formDC) { RECT rc = FloatingRect; HBRUSH hOldBrush=NULL; HPEN hOldPen=NULL; int nDrawMode; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); Ellipse(formDC, min(rc.left, rc.right)+1, min(rc.top, rc.bottom)+1, max(rc.left, rc.right), max(rc.top, rc.bottom)); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::GroupPaintDirectly(HDC dcDst, int px, int py, int vw, int vh) { if(Image->OnPaintZoom) Image->OnPaintZoom(Image, dcDst); if(Image->OnPaintLocate) Image->OnPaintLocate(Image, dcDst); } //--------------------------------------------------------------------------- inline int __fastcall TNewGroupingForm::compare(BYTE &b1, BYTE &g1, BYTE &r1) { return abs(b1 - compareBlue) + abs(g1 - compareGreen) + abs(r1 - compareRed); } //--------------------------------------------------------------------------- inline int __fastcall TNewGroupingForm::compare_Weight(BYTE &b1, BYTE &g1, BYTE &r1) { return abs(b1 - compareBlue) / weightBlue + abs(g1 - compareGreen) / weightGreen + abs(r1 - compareRed) / weightRed; } //--------------------------------------------------------------------------- inline int __fastcall TNewGroupingForm::compare_Ball(BYTE &b1, BYTE &g1, BYTE &r1) { return (b1 - compareBlue) * (b1 - compareBlue) + (g1 - compareGreen) * (g1 - compareGreen) + (r1 - compareRed) * (r1 - compareRed); } //--------------------------------------------------------------------------- inline int __fastcall TNewGroupingForm::compare_Ball_Weight(BYTE &b1, BYTE &g1, BYTE &r1) { return (b1 - compareBlue) * (b1 - compareBlue) / weightBlueSquare + (g1 - compareGreen) * (g1 - compareGreen) / weightGreenSquare + (r1 - compareRed) * (r1 - compareRed) / weightRedSquare; } //--------------------------------------------------------------------------- inline int __fastcall TNewGroupingForm::compare_HLS(TColor &sourceColor, double &cH, double &cL, double &cS) { double srcH, srcL, srcS; TColor2HLS(sourceColor, srcH, srcL, srcS); return abs(srcH - cH) + abs(srcL - cL) * 10 + abs(srcS - cS); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::advToleranceChange(TObject *Sender) { toleranceChange(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::toleranceChange() { if (trackValue != groupingItemSet.getToleranceValue()) advTolerance->Position = 0; if (trackValue == groupingItemSet.getToleranceValue() && advTolerance->Position == advToleranceValue) return; if (compareMethod->isUserType()) { changeTolUsingBar = true; TolPlusRed->Value = trackValue; TolPlusGreen->Value = trackValue; TolPlusBlue->Value = trackValue; TolMinusRed->Value = trackValue; TolMinusGreen->Value = trackValue; TolMinusBlue->Value = trackValue; changeTolUsingBar = false; } if (groupingItemSet.getCurrentItem()->isColorSelected()) { RadioSelection->Checked = true; } if (RadioSelection->Checked) { if (!groupingItemSet.getCurrentItem()->isLocked()) { setCurrentMask(); groupingItemSet.updateMask(); } drawProcessingBitmap(); Image->Repaint(); } advTolerance->Max = 2 * groupingItemSet.getToleranceValue() + 1; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::toleranceChangeByUser() { if (groupingItemSet.getCurrentItem()->isColorSelected()) { RadioSelection->Checked = true; } if (RadioSelection->Checked) { if (!groupingItemSet.getCurrentItem()->isLocked()) { setCurrentMask(); groupingItemSet.updateMask(); } drawProcessingBitmap(); Image->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btWraperRunClick(TObject *Sender) { RadioSelection->Checked = true; if (RadioSelection->Checked) { if (!groupingItemSet.getCurrentItem()->isLocked()) { wrapingCurrentMask(); groupingItemSet.updateMask(); } drawProcessingBitmap(); Image->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::lockClick(int number) { AnsiString OKname; TButton *button; int NameLength, last1, last2, last3, last4; AnsiString num1, num2, num3; if (groupingItemSet.getItem(number)->getComponent()->isOKChecked()) { if (!groupingItemSet.getItem(number)->isColorSelected()) { Application->MessageBox("You cannot proceed without grouping a color", "Message", MB_OK); /* TODO : tds */ groupingItemSet.getItem(number)->getComponent()->setOKBox(false); return; } groupingItemSet.getItem(number)->lockItem(); groupingItemSet.addMaskToWhole(number); fixColor(number); if (groupingItemSet.isLastItem(number)) { addOneGroupColor(); } else { RadioImage->Checked = true; } } else { groupingItemSet.getItem(number)->unLockItem(); groupingItemSet.subtractMaskFromWhole(number); recoverColor(number); } isFirst = true; isDrawingRegion = false; colorSelectionStep = 0; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::setCurrentMask() { int x, y, w, h; Byte *bp = NULL, *mp = NULL, *pWhole, m; BYTE rBYTE, gBYTE, bBYTE; TRect Src = Rect(0, 0, 0, 0); TColor sourceColor; double cmpH, cmpL, cmpS; // TCursor oldCursor; // oldCursor = Screen->Cursor; // Screen->Cursor = crHourGlass; w = previewBitmap->Width; h = previewBitmap->Height; TUnionBitmap *maskBitmap = groupingItemSet.getCurrentMask(); TUnionBitmap *wholeMask = groupingItemSet.getWholeMask(); int toleranceValue = groupingItemSet.getToleranceValue(); trackValue = groupingItemSet.getToleranceValue(); advToleranceValue = advTolerance->Position; if (compareMethod->isBallType()) { toleranceValue = toleranceValue * toleranceValue + advTolerance->Position; // for compare_ball } compareColor = groupingItemSet.getCurrentColor(); compareMethod->setCompareColor((compareColor >> 16) & 0xFF, (compareColor >> 8) & 0xFF, (compareColor) & 0xFF); compareMethod->setTolValue(TolPlusRed->Value, TolPlusGreen->Value, TolPlusBlue->Value, TolMinusRed->Value, TolMinusGreen->Value, TolMinusBlue->Value); // compareBlue = (compareColor >> 16) & 0xFF; // compareGreen = (compareColor >> 8) & 0xFF; // compareRed = (compareColor) & 0xFF; weightRed = WeightRed->Value; weightGreen = WeightGreen->Value; weightBlue = WeightBlue->Value; weightRedSquare = WeightRed->Value * WeightRed->Value; weightGreenSquare = WeightGreen->Value * WeightGreen->Value; weightBlueSquare = WeightBlue->Value * WeightBlue->Value; // TColor2HLS(compareColor, cmpH, cmpL, cmpS); if (wholeMask == NULL) { if ((previewBitmap->StartScanLine()) == false) goto fail; if ((maskBitmap->StartScanLine()) == false) goto fail; for (y=0; yGetScanLine(y); mp = maskBitmap->GetScanLine(y); for (x=0; xcompare(bBYTE, gBYTE, rBYTE) > toleranceValue && !compareMethod->isInRange(bBYTE, gBYTE, rBYTE)) { // if (compare(bBYTE, gBYTE, rBYTE) > toleranceValue ) { // if (compare_Ball(bBYTE, gBYTE, rBYTE) > toleranceValue ) { // if (compare_Weight(bBYTE, gBYTE, rBYTE) > toleranceValue ) { // sourceColor = (bp[x*3] << 16) + (bp[x*3+1] << 8) + bp[x*3+2]; // if (compare_HLS(sourceColor, cmpH, cmpL, cmpS) > toleranceValue ) { mp[x >> 3] &= ~(0x80 >> (x & 7)); }else { mp[x >> 3] |= (0x80 >> (x & 7)); } } maskBitmap->PutScanLine(y); } previewBitmap->StopScanLine(); maskBitmap->StopScanLine(); } else { if ((previewBitmap->StartScanLine()) == false) goto fail; if ((maskBitmap->StartScanLine()) == false) goto fail; if ((wholeMask->StartScanLine()) == false) goto fail; for (y=0; yGetScanLine(y); mp = maskBitmap->GetScanLine(y); pWhole = wholeMask->GetScanLine(y); for (x=0; x> 3] & (0x80 >> (x & 7))) || compare_Weight(bBYTE, gBYTE, rBYTE) > toleranceValue ) { // if ((pWhole[x >> 3] & (0x80 >> (x & 7))) || compare(bBYTE, gBYTE, rBYTE) > toleranceValue ) { if ((pWhole[x >> 3] & (0x80 >> (x & 7))) || (compareMethod->compare(bBYTE, gBYTE, rBYTE) > toleranceValue && !compareMethod->isInRange(bBYTE, gBYTE, rBYTE))) { mp[x >> 3] &= ~(0x80 >> (x & 7)); }else { mp[x >> 3] |= (0x80 >> (x & 7)); } } maskBitmap->PutScanLine(y); } previewBitmap->StopScanLine(); maskBitmap->StopScanLine(); wholeMask->StopScanLine(); } // Screen->Cursor = oldCursor; return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); previewBitmap->StopScanLine(); maskBitmap->StopScanLine(); wholeMask->StopScanLine(); return; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::wrapingCurrentMask() { int x, y, w, h; Byte *bp = NULL, *mp = NULL, *pWhole, m; BYTE rBYTE, gBYTE, bBYTE; TRect Src = Rect(0, 0, 0, 0); TColor sourceColor; double cmpH, cmpL, cmpS; w = previewBitmap->Width; h = previewBitmap->Height; TUnionBitmap *maskBitmap = groupingItemSet.getCurrentMask(); TUnionBitmap *wholeMask = groupingItemSet.getWholeMask(); int toleranceValue = groupingItemSet.getToleranceValue(); compareColor = groupingItemSet.getCurrentColor(); // TColor2HLS(compareColor, cmpH, cmpL, cmpS); if (wholeMask == NULL) { if ((previewBitmap->StartScanLine()) == false) goto fail; if ((maskBitmap->StartScanLine()) == false) goto fail; for (y=0; yGetScanLine(y); mp = maskBitmap->GetScanLine(y); for (x=0; x toleranceValue ) { // sourceColor = (bp[x*3] << 16) + (bp[x*3+1] << 8) + bp[x*3+2]; // if (compare_HLS(sourceColor, cmpH, cmpL, cmpS) > toleranceValue ) { mp[x >> 3] &= ~(0x80 >> (x & 7)); }else { mp[x >> 3] |= (0x80 >> (x & 7)); } } maskBitmap->PutScanLine(y); } previewBitmap->StopScanLine(); maskBitmap->StopScanLine(); } else { if ((previewBitmap->StartScanLine()) == false) goto fail; if ((maskBitmap->StartScanLine()) == false) goto fail; if ((wholeMask->StartScanLine()) == false) goto fail; for (y=0; yGetScanLine(y); mp = maskBitmap->GetScanLine(y); pWhole = wholeMask->GetScanLine(y); for (x=0; x> 3] & (0x80 >> (x & 7))) || compare(bBYTE, gBYTE, rBYTE) > toleranceValue ) { mp[x >> 3] &= ~(0x80 >> (x & 7)); }else { mp[x >> 3] |= (0x80 >> (x & 7)); } } maskBitmap->PutScanLine(y); } previewBitmap->StopScanLine(); maskBitmap->StopScanLine(); wholeMask->StopScanLine(); } return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); previewBitmap->StopScanLine(); maskBitmap->StopScanLine(); wholeMask->StopScanLine(); return; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::drawProcessingBitmap() { TUnionBitmap *maskBitmap = groupingItemSet.getCurrentMask(); if (groupingItemSet.getCurrentItem()->getBGType() == TYPE_BLACK) { // black background processingBitmap->Copy(previewBitmap, SRCCOPY); processingBitmap->Copy(maskBitmap, SRCAND); } else if (groupingItemSet.getCurrentItem()->getBGType() == TYPE_WHITE) { // white background processingBitmap->FillRect(Rect(0, 0, processingBitmap->Width, processingBitmap->Height), clWhite); processingBitmap->Copy(maskBitmap, SRCINVERT); processingBitmap->Copy(previewBitmap, SRCPAINT); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::drawProcessingBitmap(RECT r) { TUnionBitmap *maskBitmap = groupingItemSet.getCurrentMask(); if (groupingItemSet.getCurrentItem()->getBGType() == TYPE_BLACK) { // black background processingBitmap->Copy(r.left, r.top, r.right - r.left, r.bottom - r.top, previewBitmap, r.left, r.top, SRCCOPY); processingBitmap->Copy(r.left, r.top, r.right - r.left, r.bottom - r.top, maskBitmap, r.left, r.top, SRCAND); } else if (groupingItemSet.getCurrentItem()->getBGType() == TYPE_WHITE) { // white background processingBitmap->FillRect(r, clWhite); processingBitmap->Copy(r.left, r.top, r.right - r.left, r.bottom - r.top, maskBitmap, r.left, r.top, SRCINVERT); processingBitmap->Copy(r.left, r.top, r.right - r.left, r.bottom - r.top, previewBitmap, r.left, r.top, SRCPAINT); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ZoomTrackBarChange(TObject *Sender) { switch (ZoomTrackBar->Position) { case 0: ZoomChange(1, 16); ZoomTrackBar->Hint = "1/16"; break; case 1: ZoomChange(1, 12); ZoomTrackBar->Hint = "1/12"; break; case 2: ZoomChange(1, 8); ZoomTrackBar->Hint = "1/8"; break; case 3: ZoomChange(1, 6); ZoomTrackBar->Hint = "1/6"; break; case 4: ZoomChange(1, 4); ZoomTrackBar->Hint = "1/4"; break; case 5: ZoomChange(1, 3); ZoomTrackBar->Hint = "1/3"; break; case 6: ZoomChange(1, 2); ZoomTrackBar->Hint = "1/2"; break; case 7: ZoomChange(2, 3); ZoomTrackBar->Hint = "2/3"; break; case 8: ZoomChange(1, 1); ZoomTrackBar->Hint = "1"; break; case 9: ZoomChange(3, 2); ZoomTrackBar->Hint = "3/2"; break; case 10: ZoomChange(2, 1); ZoomTrackBar->Hint = "2"; break; case 11: ZoomChange(3, 1); ZoomTrackBar->Hint = "3"; break; case 12: ZoomChange(4, 1); ZoomTrackBar->Hint = "4"; break; case 13: ZoomChange(6, 1); ZoomTrackBar->Hint = "6"; break; case 14: ZoomChange(8, 1); ZoomTrackBar->Hint = "8"; break; case 15: ZoomChange(12, 1); ZoomTrackBar->Hint = "12"; break; case 16: ZoomChange(16, 1); ZoomTrackBar->Hint = "16"; break; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ColorGroupClick(TObject *Sender) { colorSelectionStep = 0; isFirst = true; isDrawingRegion = false; IsDraw = false; Image->OnPaintLocate = NULL;/////////////////by jeegeo Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::sbBlockClick(TObject *Sender) { if (sbBlock->Down) sbBlock->Hint = IDS_COMMON_ONECOLOR; else sbBlock->Hint = IDS_COMMON_BLOCKCOLOR; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::sbDeleteClick(TObject *Sender) { if (sbDelete->Down) sbDelete->Hint = IDS_COMMON_DELETECOLOR; else sbDelete->Hint = IDS_COMMON_INSERTCOLOR; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::TrackbarEditKeyPress(TObject *Sender, char &Key) { if(Key == 13)TrackBar[SelectNum]->Position = StrToInt(TrackBarEdit[SelectNum]->Text); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::TrackbarEditMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TrackBarEdit[SelectNum]->SetFocus(); TrackBarEdit[SelectNum]->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::SpecialMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { RECT r; int ZoomIn = Image->ZoomIn; int ZoomOut = Image->ZoomOut; int PenSize = PenManagerForm->Pen->Thick; r.left = Image->PositionX - (PenSize + 30); // 30 is Caption Height if (r.left<0) r.left = 0; r.top = Image->PositionY - (PenSize + 30); if (r.top<0) r.top = 0; r.right = r.left+Image->Width*ZoomOut/ZoomIn + PenSize + 60; if (r.right>Image->uBitmap->Width) r.right = Image->uBitmap->Width; r.bottom = r.top+Image->Height*ZoomOut/ZoomIn + PenSize + 60; if (r.bottom>Image->uBitmap->Height) r.bottom = Image->uBitmap->Height; MainImageForm->UndoSave(UK_PATTERN, Rect(0,0,0,0)); //by linxujun Undo_Method // BtnClick = true; sp.x = X; sp.y = Y; ep.x = sp.x; ep.y = sp.y; if (sbDelete->Down) { freecolor = PaletteForm->DIB256Palette->GetBGCOLORREF(24); }else { freecolor = 0x00; } New_line_pen(sp.x, sp.y, ep.x, ep.y, freecolor, &r); Image->RectPaint(r); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::New_line_pen(int sx, int sy, int ex, int ey, COLORREF c, RECT *rect) { int PenType, dia, ls, rs, w, h, sw, y, x, r, yyy; double d, r1, r2, xx, yy; TNewLineData ld; if (groupingItemSet.getCurrentItem()->isLocked()) return; PenType = 0; //PenManagerForm->Pen->Shape; dia = PenManagerForm->Pen->Thick; //lhskys draw ¿¡¼­ ÇÑÁ¡µÚ·Î ÇÒ¶§ Pen size°ªÀ» ÀÌ¿ë ±×¸®±â À§ÇØ... ls = dia>>1; rs = dia-ls; w = Image->uBitmap->Width; h = Image->uBitmap->Height; for (y=0; yh) ld.sy = h; if (ld.ey<0) ld.ey = 0; else if (ld.ey>h) ld.ey = h; r = PenType ? (ld.sx=0 && y=0 && y=0 && y=0 && y*(mex + y)) *(mex + y) = x; } } ld.sy -= ls; ld.ey += rs; if (!(groupingItemSet.getCurrentMask()->StartScanLine())) goto fail; if (groupingItemSet.getWholeMask()) { if (!(groupingItemSet.getWholeMask()->StartScanLine())) goto fail; } // if (iMainImage->Mask) { // if (!(iMainImage->Mask->StartScanLine())) goto fail; // } for (y=ld.sy; y<=ld.ey; y++) { if (y >= 0 && y < h) { if (*(mex + y)>=0 && *(msx + y)Mask) iMainImage->Mask->StopScanLine(); groupingItemSet.getCurrentMask()->StopScanLine(); if (groupingItemSet.getWholeMask()) { groupingItemSet.getWholeMask()->StopScanLine(); } if (rect) { rect->left = min(sx, ex) - ls; rect->top = min(sy, ey) - ls; rect->right = max(sx, ex) + rs; rect->bottom = max(sy, ey) + rs; } if (rect->left < 0) rect->left = 0; if (rect->right >= processingBitmap->Width) rect->right = processingBitmap->Width; if (rect->top < 0) rect->top = 0; if (rect->bottom >= processingBitmap->Height) rect->bottom = processingBitmap->Height; drawProcessingBitmap(*rect); groupingItemSet.updateMask(*rect); return; fail: // if (iMainImage->Mask) iMainImage->Mask->StopScanLine(); groupingItemSet.getCurrentMask()->StopScanLine(); if (groupingItemSet.getWholeMask()) { groupingItemSet.getWholeMask()->StopScanLine(); } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::pos_in(TNewLineData &ld, int by, int bsx, int bex, int ch) { double d; if ((by>=0) && (byuBitmap->Height)) { if (*(msx+by)>bsx) { if (ch) { d = (ld.dx1 - bsx) * (ld.dx1 - bsx) + (ld.dy1 - by) * (ld.dy1 - by); if (d= Image->uBitmap->Width || y < 0 || y >= Image->uBitmap->Height) return; if (x < 0) { len += x; x = 0; if (len <= 0) return; } if (x + len > Image->uBitmap->Width) len = Image->uBitmap->Width-x; // Undo->SaveData(x,y,len); //by linuxjun SetHLineMask(x, y, len); return; } //--------------------------------------------------------------------------- bool __fastcall TNewGroupingForm::AllocLineMem(int d) { if (d!=memsize) { DelLineMem(); if ((hMemLine = GlobalAlloc(GHND, 2*d*sizeof(int)))==NULL) goto fail; if ((msx = (int *)GlobalLock(hMemLine))==NULL) goto fail; mex = (int *)msx + d; memsize = d; } return true; fail: DelLineMem(); return false; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::DelLineMem() { if (hMemLine) { if (msx) { GlobalUnlock(hMemLine); msx = NULL; } GlobalFree(hMemLine); hMemLine = NULL; } memsize = 0; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::FormDestroy(TObject *Sender) { DelLineMem(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::SetHLine24(int x, int y, int len, COLORREF c) { Byte *bp=NULL, *mp=NULL, *lp=NULL; bp = Image->uBitmap->GetScanLine(y, x, len); // convert by celberus /* if (bMaskArea) { mp = iMainImage->Mask->GetScanLine(y, x, len); // for (int i = x; i < x + len; i++, bp += 3) { if ((mp[i >> 3] & (0x80 >> (i & 7))) == 0) { memset24(bp + 3 * x, c, 1); } } } else {*/ for (int i = x; i < x + len; i++, bp += 3) { memset24(bp+3*x, c, 1); } // } Image->uBitmap->PutScanLine(y, x, len); // convert by celberus } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::SpecialMouseMove(TShiftState Shift, int X, int Y) { int pw; // RGBQUAD m_rgb[3]; TPItemImage *Image = MainImageForm->iMainImage; RECT r; ep.x = X; ep.y = Y; // if (Pen->Brush == 0) { New_line_pen(sp.x, sp.y, ep.x, ep.y, freecolor, &r); Image->RectPaint(r); /*} else if (Pen->Brush == 1) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } }*/ sp.x = ep.x; sp.y = ep.y; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::iMainImageKeyDown(int Key) { if (Key == 120 || Key == 88) { // 120: x 880: X down , 122 : z 900: Z down colorSelectionStep = 0; isFirst = true; isDrawingRegion = false; IsDraw = false; Image->OnPaintLocate = NULL;/////////////////by jeegeo Image->Repaint(); } else if (Key == 'a' || Key == 'A') { ZoomTrackBar->Position++; } else if (Key == 's' || Key == 'S') { ZoomTrackBar->Position--; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::addOneGroupColor() { groupingItemSet.addItem(this, ColorBox, previewBitmap->Width, previewBitmap->Height); groupingItemSet.getCurrentComponent()->ButtonSelectEvent = selectGroupingItem; groupingItemSet.getCurrentComponent()->TrackValueChangeEvent = toleranceChange; groupingItemSet.getCurrentComponent()->OKClickEvent = lockClick; selectGroupingItem(groupingItemSet.getCurrentItemNumber()); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::selectGroupingItem(int number) { if((groupingItemSet.getItem(number))->isColorSelected()) { if (RadioSelection->Checked == true) { RadioSelectionClick(this); } else { RadioSelection->Enabled = true; RadioSelection->Checked = true; RadioImage->Checked = false; } } else { RadioSelection->Enabled = false; RadioSelection->Checked = false; RadioImage->Checked = true; } groupingItemSet.selectItem(number); // GroupingItem *aGroupingItem; // aGroupingItem = (GroupingItem *)groupingItemList->Items[number]; // aGroupingItem->setSelected(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::Button1Click(TObject *Sender) { previewType = (previewType + 1) % 3; if (previewType != TYPE_ALL) { if (RadioImage->Checked) Image->uBitmap = subViewBitmap; makeSubView(); } else { if (RadioImage->Checked) Image->uBitmap = previewBitmap; } if (RadioImage->Checked) { Image->isRepaintAll = true; Image->Repaint(); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::makeSubView() { if (previewType == TYPE_GROUP) { if (groupingItemSet.getWholeMask() == NULL) { subViewBitmap->FillRect(Rect(0, 0, subViewBitmap->Width, subViewBitmap->Height), 0); } else { subViewBitmap->Copy(previewBitmap, SRCCOPY); subViewBitmap->Copy(groupingItemSet.getWholeMask(), SRCAND); } } else if (previewType == TYPE_REMAIN) { if (groupingItemSet.getWholeMask() == NULL) { subViewBitmap->Copy(previewBitmap, SRCCOPY); } else { TUnionBitmap *tempBitmap = new TUnionBitmap; tempBitmap->Create(previewBitmap->Width, previewBitmap->Height, 1); tempBitmap->Copy(groupingItemSet.getWholeMask(), NOTSRCCOPY); subViewBitmap->Copy(previewBitmap, SRCCOPY); subViewBitmap->Copy(tempBitmap, SRCAND); delete tempBitmap; } } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::BtnFinishClick(TObject *Sender) { int w, h; TRect Src = Rect(0, 0, 0, 0); if (MainImageForm->WorkArea->Mask) { Src = MainImageForm->WorkArea->Range; }else { Src.Right = MainImageForm->iMainImage->uBitmap->Width; Src.Bottom = MainImageForm->iMainImage->uBitmap->Height; } MainImageForm->iMainImage->uBitmap->Copy(Src.Left, Src.Top, Src.Right - Src.Left, Src.Bottom - Src.Top, previewBitmap, 0, 0, SRCCOPY); PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::BtnCancelClick(TObject *Sender) { PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::make256Bitmap() { int usedColor; /* RGBQUAD rgb[256]; TPCanvasInfor canvasInfor; HANDLE hFile = INVALID_HANDLE_VALUE; TEXPIAFILEHEADER tpfh; TTexpiaBitmap *tag = NULL; TPException ec; TPalette *Palette = NULL; AnsiString fileName = getTempGroupingFileName(); */ if (resultBitmap == NULL) { resultBitmap = new TUnionBitmap; resultBitmap->Create(previewBitmap->Width, previewBitmap->Height, 8); } if (groupingItemSet.getWholeMask() != NULL) { previewBitmap->Copy(groupingItemSet.getWholeMask(), SRCAND); } usedColor = groupingItemSet.make256_2(resultBitmap, previewBitmap); mustNotDelete = true; if (FOnGPNewCanvas) FOnGPNewCanvas(resultBitmap, usedColor); mustNotDelete = false; /* if ((hFile = CreateFile(fileName.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } canvasInfor = MainImageForm->CanvasInfor; canvasInfor.SetSize(cstFree, previewBitmap->Width, previewBitmap->Height); tpfh.Version = TexVersion('P', 'T', 300); tpfh.CanvasInfor = canvasInfor; tpfh.BitsPerPixel = resultBitmap->BitsPerPixel; tpfh.Compress = cmZLib; Palette = new TPalette; resultBitmap->GetColors(0, 256, rgb); for (int i = 0; i < 256; i++ ) { Palette->SetNormal(i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue); } if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } MakeTexpiaTag(tag, resultBitmap, Rect(0, 0, resultBitmap->Width, resultBitmap->Height)); if (!SaveToTexpiaFile(hFile, Palette, tpfh, tag, resultBitmap)) { ec = EC_FILE_NOT_WRITE; goto fail; } CloseHandle(hFile); delete tag; delete Palette; delete resultBitmap; if (FOnRead) ec = FOnRead(fileName.c_str());*/ PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); return;/* fail: if (tag) delete tag; if (Palette) delete Palette; if (resultBitmap) delete resultBitmap; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; */ } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::BtnFinish256Click(TObject *Sender) { make256Bitmap(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::cbGroupingTypeChange(TObject *Sender) { if (compareMethod) delete compareMethod; if (cbGroupingType->ItemIndex == 0) { compareMethod = (CompareMethod *) new CompareMethod_Ball; advTolerance->Enabled = true; } else if (cbGroupingType->ItemIndex == 1) { compareMethod = (CompareMethod *) new CompareMethod_Cube; advTolerance->Enabled = false; } else if (cbGroupingType->ItemIndex == 4) { compareMethod = (CompareMethod *) new CompareMethod_UserRGB; advTolerance->Enabled = false; } else { cbGroupingType->ItemIndex = 0; compareMethod = (CompareMethod *) new CompareMethod_Ball; advTolerance->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::ImagePositionChange(TObject *Sender) { sbHorz->Position = Image->PositionX; sbVert->Position = Image->PositionY; } //--------------------------------------------------------------------------- // Class GroupingMak //--------------------------------------------------------------------------- __fastcall GroupingMask::GroupingMask() { // } //--------------------------------------------------------------------------- // Class GroupingComponent //--------------------------------------------------------------------------- __fastcall GroupingComponent::GroupingComponent() { ButtonSelectEvent = NULL; OKClickEvent = NULL; TrackValueChangeEvent = NULL; // } //--------------------------------------------------------------------------- __fastcall GroupingComponent::~GroupingComponent() { // } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::initInterface(TComponent *owner, TWinControl* parent, int number) { componentNumber = number; radioButton = new TRadioButton(owner); radioButton->Parent = parent; radioButton->Top = 90+45*number; radioButton->Left = 8; radioButton->Width = 30; radioButton->Height = 16; radioButton->Caption = number+1; radioButton->Name = "num"+IntToStr(number); radioButton->OnClick = itemSelected; shapeColor = new TShape(owner); shapeColor->Parent = parent; shapeColor->Top = 84+45*number; shapeColor->Left = 42; shapeColor->Width = 43; shapeColor->Height = 25; shapeColor->Name = "sc"+IntToStr(number); trackBar = new TTrackBar(owner); trackBar->Parent = parent; trackBar->Top = 84+45*number; trackBar->Left = 88; trackBar->Width = 190; trackBar->Height = 25; trackBar->Max = 500; trackBar->Min = 0; trackBar->Name = "trackbar"+IntToStr(number); trackBar->OnChange = trackBarChanged; trackBarEdit = new TEdit(owner); trackBarEdit->Parent = parent; trackBarEdit->Top = 84+45*number; trackBarEdit->Left = 285; trackBarEdit->Width = 30; trackBarEdit->Height = 25; trackBarEdit->Name = "trackbaredit"+IntToStr(number); trackBarEdit->Text = 0; trackBarEdit->ReadOnly = false; // trackBarEdit->OnKeyPress = TrackbarEditKeyPress; // trackBarEdit->OnMouseDown = TrackbarEditMouseDown; cbOK = new TCheckBox(owner); cbOK->Parent = parent; cbOK->Top = 84+45*number; cbOK->Left = 323; cbOK->Width = 50; cbOK->Height = 25; cbOK->Caption = "OK"; cbOK->Name = "OK"+IntToStr(number); cbOK->OnClick = OKClick; if (number == 0) radioButton->Checked = true; } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::itemSelected(TObject *sender) { if (ButtonSelectEvent) ButtonSelectEvent(componentNumber); } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::trackBarChanged(TObject *sender) { if(radioButton->Checked == false)return; trackBarEdit->Text = trackBar->Position; if (TrackValueChangeEvent) TrackValueChangeEvent(); } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::OKClick(TObject *sender) { if (OKClickEvent) OKClickEvent(componentNumber); } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::setSelected() { radioButton->Checked = true; // if (ButtonSelectEvent) ButtonSelectEvent(componentNumber); } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::setNotSelected() { radioButton->Checked = false; } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::setShapeColor(TColor color) { shapeColor->Brush->Color = color; } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::lock() { trackBar->Enabled = false; trackBarEdit->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::unLock() { trackBar->Enabled = true; trackBarEdit->Enabled = true; } //--------------------------------------------------------------------------- int __fastcall GroupingComponent::getTrackValue() { return trackBar->Position; } //--------------------------------------------------------------------------- void __fastcall GroupingComponent::setOKBox(bool value) { cbOK->Checked = value; } //--------------------------------------------------------------------------- bool __fastcall GroupingComponent::isOKChecked() { return cbOK->Checked; } //--------------------------------------------------------------------------- // Class GroupingItem //--------------------------------------------------------------------------- __fastcall GroupingItem::GroupingItem() { groupingComponent = new GroupingComponent(); groupingMask = new TUnionBitmap; colorSelected = false; locked = false; } //--------------------------------------------------------------------------- __fastcall GroupingItem::~GroupingItem() { delete groupingComponent; delete groupingMask; groupingMask = NULL; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::initComponent(TComponent *owner, TWinControl* parent, int number) { groupingComponent->initInterface(owner, parent, number); /* TODO : remove middle man */ } //--------------------------------------------------------------------------- bool __fastcall GroupingItem::isColorSelected() { return colorSelected; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::setColorSelected(bool value) { colorSelected = value; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::setColor(TColor color) { if (locked) return; groupingColor = color; groupingComponent->setShapeColor(color); setBGType(color); colorSelected = true; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::setBGType(TColor color) { if ( (((color >> 16) & 0xFF) + ((color >> 8) & 0xFF) + (color & 0xFF)) / 3 < 0x80 ) { bgType = TYPE_WHITE; } else { bgType = TYPE_BLACK; } } //--------------------------------------------------------------------------- FillBGType __fastcall GroupingItem::getBGType() { return bgType; } //--------------------------------------------------------------------------- TColor __fastcall GroupingItem::getColor() { return groupingColor; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::createMask(int width, int height) { groupingMask->Create(width, height, 1); groupingMask->FillRect(Rect(0, 0, width, height), 0); } //--------------------------------------------------------------------------- TUnionBitmap* __fastcall GroupingItem::getMask() { return groupingMask; } //--------------------------------------------------------------------------- int __fastcall GroupingItem::getToleranceValue() { return groupingComponent->getTrackValue(); } //--------------------------------------------------------------------------- GroupingComponent* GroupingItem::getComponent() { return groupingComponent; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::lockItem() { getComponent()->lock(); locked = true; } //--------------------------------------------------------------------------- void __fastcall GroupingItem::unLockItem() { getComponent()->unLock(); locked = false; } //--------------------------------------------------------------------------- bool __fastcall GroupingItem::isLocked() { return locked; } //--------------------------------------------------------------------------- // Class GroupingItemSet //--------------------------------------------------------------------------- __fastcall GroupingItemSet::GroupingItemSet() { numOfItems = 0; wholeMask = NULL; initSet(); } //--------------------------------------------------------------------------- __fastcall GroupingItemSet::~GroupingItemSet() { clearSet(); } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::initSet() { itemList = new TList; } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::clearSet() { GroupingItem *aGroupingItem; while(itemList->Count > 0) { aGroupingItem = (GroupingItem *)itemList->Last(); itemList->Remove(aGroupingItem); delete aGroupingItem; } delete itemList; } //--------------------------------------------------------------------------- GroupingItem* __fastcall GroupingItemSet::getItem(int number) { return (GroupingItem *)itemList->Items[number]; } //--------------------------------------------------------------------------- GroupingItem* __fastcall GroupingItemSet::getCurrentItem() { return (GroupingItem *)itemList->Items[selectedItemNumber]; } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::addItem(TComponent *owner, TWinControl* parent, int bitmapWidth, int bitmapHeight) { int newItemNumber = numOfItems; GroupingItem *aGroupingItem = new GroupingItem(); aGroupingItem->initComponent(owner, parent, newItemNumber); aGroupingItem->createMask(bitmapWidth, bitmapHeight); itemList->Add(aGroupingItem); numOfItems++; selectItem(newItemNumber); } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::setCurrentColor(TColor color) { GroupingItem *selectedItem = (GroupingItem *)itemList->Items[selectedItemNumber]; selectedItem->setColor(color); } //--------------------------------------------------------------------------- TColor __fastcall GroupingItemSet::getCurrentColor() { GroupingItem *selectedItem = (GroupingItem *)itemList->Items[selectedItemNumber]; return selectedItem->getColor(); } //--------------------------------------------------------------------------- TUnionBitmap* __fastcall GroupingItemSet::getCurrentMask() { GroupingItem *selectedItem = (GroupingItem *)itemList->Items[selectedItemNumber]; /* TODO : selectedItem µµ property¿¡ Ãß°¡ÇÒ±î? */ return selectedItem->getMask(); } //--------------------------------------------------------------------------- int __fastcall GroupingItemSet::getToleranceValue() { GroupingItem *selectedItem = (GroupingItem *)itemList->Items[selectedItemNumber]; return selectedItem->getToleranceValue(); } //--------------------------------------------------------------------------- GroupingComponent* GroupingItemSet::getCurrentComponent() { GroupingItem *selectedItem = (GroupingItem *)itemList->Items[selectedItemNumber]; return selectedItem->getComponent(); } //--------------------------------------------------------------------------- bool __fastcall GroupingItemSet::isLastItem(int number) { return number == numOfItems - 1; } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::selectItem(int number) { if (selectedItemNumber == number) return; selectedItemNumber = number; getCurrentComponent()->setNotSelected(); getCurrentComponent()->setSelected(); } //--------------------------------------------------------------------------- int __fastcall GroupingItemSet::getCurrentItemNumber() { return selectedItemNumber; } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::addMaskToWhole(int number) { if (wholeMask == NULL) { wholeMask = new TUnionBitmap; wholeMask->Create(getItem(number)->getMask()->Width, getItem(number)->getMask()->Height, 1); wholeMask->FillRect(Rect(0, 0, wholeMask->Width, wholeMask->Height), 0); } wholeMask->Copy(getItem(number)->getMask(), SRCPAINT); } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::subtractMaskFromWhole(int number) { if (wholeMask == NULL) { wholeMask = new TUnionBitmap; wholeMask->Create(getItem(number)->getMask()->Width, getItem(number)->getMask()->Height, 1); wholeMask->FillRect(Rect(0, 0, wholeMask->Width, wholeMask->Height), 0); } wholeMask->Copy(getItem(number)->getMask(), SRCINVERT); } //--------------------------------------------------------------------------- TUnionBitmap* __fastcall GroupingItemSet::getWholeMask() { return wholeMask; } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::updateMask() { TUnionBitmap *tempMask = NULL; for (int i = 0; i < itemList->Count; i++) { if (i == selectedItemNumber) continue; else { if (!getItem(i)->isLocked()) { if (tempMask == NULL) { tempMask = new TUnionBitmap; tempMask->Create(wholeMask->Width, wholeMask->Height, 1); tempMask->Copy(getCurrentMask(), NOTSRCCOPY); } getItem(i)->getMask()->Copy(tempMask, SRCAND); } } } if (tempMask) delete tempMask; } //--------------------------------------------------------------------------- void __fastcall GroupingItemSet::updateMask(RECT r) { TUnionBitmap *tempMask = NULL; for (int i = 0; i < itemList->Count; i++) { if (i == selectedItemNumber) continue; else { if (!getItem(i)->isLocked()) { if (tempMask == NULL) { tempMask = new TUnionBitmap; tempMask->Create(r.right - r.left, r.bottom - r.top, 1); tempMask->Copy(0, 0, r.right - r.left, r.bottom - r.top, getCurrentMask(), r.left, r.top, NOTSRCCOPY); } getItem(i)->getMask()->Copy(r.left, r.top, r.right - r.left, r.bottom - r.top, tempMask, 0, 0, SRCAND); } } } if (tempMask) delete tempMask; } //--------------------------------------------------------------------------- int __fastcall GroupingItemSet::make256(TUnionBitmap *dstBitmap, TUnionBitmap *srcBitmap) { RGBQUAD rgb[256]; int usedColor = 0; TColor aColor; TUnionBitmap *tempBitmap = NULL; TUnionBitmap *aMask; Byte *pDst; // rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0; // rgb[0].rgbReserved = RGB_RESERVED; // rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xFF; // rgb[1].rgbReserved = RGB_RESERVED; // dstBitmap->FillRect(Rect(0, 0, tempBitmap->Width, tempBitmap->Height), 0x01000000); // tempBitmap = new TUnionBitmap; // tempBitmap->Create(srcBitmap->Width, srcBitmap->Height, 8); for (int i = 0; i < itemList->Count; i++ ) { if (getItem(i)->isColorSelected()) { aColor = getItem(i)->getColor(); rgb[usedColor].rgbBlue = (aColor >> 16) & 0xFF; rgb[usedColor].rgbGreen = (aColor >> 8) & 0xFF; rgb[usedColor].rgbRed = aColor & 0xFF; rgb[usedColor].rgbReserved = 0; // rgb[usedColor + 2].rgbBlue = (aColor >> 16) & 0xFF; // rgb[usedColor + 2].rgbGreen = (aColor >> 8) & 0xFF; // rgb[usedColor + 2].rgbRed = aColor & 0xFF; // aMask = getItem(i)->getMask(); // tempBitmap->FillRect(Rect(0, 0, tempBitmap->Width, tempBitmap->Height), 0x01000000 + usedColor); // tempBitmap->Copy(aMask, SRCAND); // dstBitmap->Copy(tempBitmap, SRCPAINT); usedColor++; } } // delete tempBitmap; dstBitmap->PutColors(0, 256, rgb); dstBitmap->Copy(srcBitmap, SRCCOPY); for (int i = 255; i >= 2; i--) { rgb[i].rgbRed = rgb[i - 2].rgbRed; rgb[i].rgbGreen = rgb[i - 2].rgbGreen; rgb[i].rgbBlue = rgb[i - 2].rgbBlue; } rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0; rgb[0].rgbReserved = RGB_RESERVED; rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xFF; rgb[1].rgbReserved = RGB_RESERVED; rgb[255].rgbBlue = rgb[255].rgbGreen = rgb[255].rgbRed = 0xFF; rgb[255].rgbReserved = RGB_RESERVED; dstBitmap->PutColors(0, 256, rgb); dstBitmap->StartScanLine(); for (int y = 0; y < dstBitmap->Height; y++) { pDst = dstBitmap->GetScanLine(y); for (int x = 0; x < dstBitmap->Width; x++, pDst++) { *pDst += 2; } dstBitmap->PutScanLine(y); } dstBitmap->StopScanLine(); return usedColor; } //--------------------------------------------------------------------------- int __fastcall GroupingItemSet::make256_2(TUnionBitmap *dstBitmap, TUnionBitmap *srcBitmap) { RGBQUAD rgb[256]; int usedColor = 0; TColor aColor; TUnionBitmap *tempBitmap = NULL; TUnionBitmap *aMask; Byte *pDst; rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0; rgb[0].rgbReserved = RGB_RESERVED; rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xFF; rgb[1].rgbReserved = RGB_RESERVED; rgb[255].rgbBlue = rgb[255].rgbGreen = rgb[255].rgbRed = 0xFF; rgb[255].rgbReserved = RGB_RESERVED; dstBitmap->FillRect(Rect(0, 0, srcBitmap->Width, srcBitmap->Height), 0x01000000); tempBitmap = new TUnionBitmap; tempBitmap->Create(srcBitmap->Width, srcBitmap->Height, 8); for (int i = 0; i < itemList->Count; i++ ) { if (getItem(i)->isColorSelected() && getItem(i)->isLocked()) { aColor = getItem(i)->getColor(); rgb[usedColor].rgbBlue = (aColor >> 16) & 0xFF; rgb[usedColor].rgbGreen = (aColor >> 8) & 0xFF; rgb[usedColor].rgbRed = aColor & 0xFF; rgb[usedColor].rgbReserved = 0; rgb[usedColor + 2].rgbBlue = (aColor >> 16) & 0xFF; rgb[usedColor + 2].rgbGreen = (aColor >> 8) & 0xFF; rgb[usedColor + 2].rgbRed = aColor & 0xFF; aMask = getItem(i)->getMask(); tempBitmap->FillRect(Rect(0, 0, tempBitmap->Width, tempBitmap->Height), 0x01000000 + usedColor); tempBitmap->Copy(aMask, SRCAND); dstBitmap->Copy(tempBitmap, SRCPAINT); usedColor++; } } delete tempBitmap; for (int i = 255; i >= 2; i--) { rgb[i].rgbRed = rgb[i - 2].rgbRed; rgb[i].rgbGreen = rgb[i - 2].rgbGreen; rgb[i].rgbBlue = rgb[i - 2].rgbBlue; } dstBitmap->PutColors(0, 256, rgb); dstBitmap->StartScanLine(); for (int y = 0; y < dstBitmap->Height; y++) { pDst = dstBitmap->GetScanLine(y); for (int x = 0; x < dstBitmap->Width; x++, pDst++) { *pDst += 2; } dstBitmap->PutScanLine(y); } dstBitmap->StopScanLine(); return usedColor; } //--------------------------------------------------------------------------- void __fastcall CompareMethod::setCompareColor(BYTE blue, BYTE green, BYTE red) { compareBlue = blue; compareGreen = green; compareRed = red; } //--------------------------------------------------------------------------- void __fastcall CompareMethod::setTolValue(int PR, int PG, int PB, int MR, int MG, int MB) { tolPlusRed = PR; tolPlusGreen = PG; tolPlusBlue = PB; tolMinusRed = MR; tolMinusGreen = MG; tolMinusBlue = MB; } //--------------------------------------------------------------------------- bool __fastcall CompareMethod::isBallType() { return compareType == 1; } //--------------------------------------------------------------------------- bool __fastcall CompareMethod::isUserType() { return compareType == 5; } //--------------------------------------------------------------------------- __fastcall CompareMethod_Cube::CompareMethod_Cube() { compareType = 0; // Type_Cube } //--------------------------------------------------------------------------- inline int __fastcall CompareMethod_Cube::compare(BYTE &b1, BYTE &g1, BYTE &r1) { return abs(b1 - compareBlue) + abs(g1 - compareGreen) + abs(r1 - compareRed); } //--------------------------------------------------------------------------- __fastcall CompareMethod_Ball::CompareMethod_Ball() { compareType = 1; // Type_Ball } //--------------------------------------------------------------------------- inline int __fastcall CompareMethod_Ball::compare(BYTE &b1, BYTE &g1, BYTE &r1) { return (b1 - compareBlue) * (b1 - compareBlue) + (g1 - compareGreen) * (g1 - compareGreen) + (r1 - compareRed) * (r1 - compareRed); } //--------------------------------------------------------------------------- __fastcall CompareMethod_UserRGB::CompareMethod_UserRGB() { compareType = 5; // Type_UserRGB } //--------------------------------------------------------------------------- inline bool __fastcall CompareMethod_UserRGB::isInRange(BYTE &b1, BYTE &g1, BYTE &r1) { return (b1 < compareBlue + tolPlusBlue) && (b1 > compareBlue - tolMinusBlue) && (g1 < compareGreen + tolPlusGreen) && (g1 > compareGreen - tolMinusGreen) && (r1 < compareRed + tolPlusRed) && (r1 > compareRed - tolMinusRed); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::UserTolChange(TObject *Sender) { if (!changeTolUsingBar) toleranceChangeByUser(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::TextCommandMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TextCommand->SetFocus(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::TextCommandKeyPress(TObject *Sender, char &Key) { if (Key == '\n' || Key == '\r') { runCommand(TextCommand->Text); TextCommand->Text = ""; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::runCommand(AnsiString command) { if (command == "ns") { isNewProcess = !isNewProcess; if (true == isNewProcess) { TextReport->Lines->Add("New process start"); } else { TextReport->Lines->Add("New process end"); } } if (false == isNewProcess) return; if (command == "fr") { functionType = FUNC_RESET; TextReport->Lines->Add("function changed - *group reset*"); } else if (command == "fc") { functionType = FUNC_COLOR_ADD; TextReport->Lines->Add("function changed - *color add*"); } else if (command == "br") { brushType = BR_RECTANGLE; TextReport->Lines->Add("brush changed - *rectangle*"); brushState = FIRST_POINT; } else if (command == "mv") { makeMergeView(); } else if (command == "gv") { makeGrayView(); } else if (command.SubString(1, 2) == "sp") { simplify(command.SubString(3, 3).ToInt()); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnNewClick(TObject *Sender) { isNewProcess = !isNewProcess; if (true == isNewProcess) { TextReport->Lines->Add("New process start"); } else { TextReport->Lines->Add("New process end"); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::groupResetMouseDown(int X, int Y) { RECT r; COLORREF color; if(!RadioImage->Checked)return; if (brushMenu.getCurrentBrush() == BR_PIXEL) { color = Image->uBitmap->GetPixelColor(X, Y); groupingItemSet.setCurrentColor((TColor)color); RadioSelection->Enabled = true; } else if (brushMenu.getCurrentBrush() == BR_RECTANGLE) { if (brushMenu.brushState == SECOND_POINT) { TextReport->Lines->Add("Second point accepted at (" + IntToStr(X) + "," + IntToStr(Y) + ")"); colorSelectionArea.right = X; colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); groupReset(); RadioSelection->Enabled = true; NewGroupingDrawRectangleLocate(colorSelectionArea); brushMenu.brushState = FIRST_POINT; IsDraw = false; Image->OnPaintLocate = NULL;/////////////////by jeegeo Image->Repaint(); } else if (brushMenu.brushState == FIRST_POINT) { TextReport->Lines->Add("First point accepted at (" + IntToStr(X) + "," + IntToStr(Y) + ")"); resetRGBSpace(); colorSelectionArea.left = colorSelectionArea.top = X; colorSelectionArea.top = colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); IsDraw = true; brushMenu.brushState = SECOND_POINT; } } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::colorAddMouseDown(int X, int Y) { RECT r; COLORREF color; if(!RadioSelection->Checked)return; if (brushMenu.getCurrentBrush() == BR_PIXEL) { } else if (brushMenu.getCurrentBrush() == BR_RECTANGLE) { if (brushMenu.brushState == SECOND_POINT) { TextReport->Lines->Add("Second point accepted at (" + IntToStr(X) + "," + IntToStr(Y) + ")"); colorSelectionArea.right = X; colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); colorAdd(); NewGroupingDrawRectangleLocate(colorSelectionArea); brushMenu.brushState = FIRST_POINT; IsDraw = false; Image->OnPaintLocate = NULL;/////////////////by jeegeo Image->Repaint(); } else if (brushMenu.brushState == FIRST_POINT) { TextReport->Lines->Add("First point accepted at (" + IntToStr(X) + "," + IntToStr(Y) + ")"); resetRGBSpace(); colorSelectionArea.left = colorSelectionArea.top = X; colorSelectionArea.top = colorSelectionArea.bottom = Y; NewGroupingDrawRectangleLocate(colorSelectionArea); IsDraw = true; brushMenu.brushState = SECOND_POINT; } } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::resetRGBSpace() { for (int i = 0; i < 256; i++ ) { for (int j = 0; j < 256; j++ ) { for (int k = 0; k < 256; k++ ) { rgbSpace[i][j][k] = false; } } } } //--------------------------------------------------------------------------- RECT __fastcall TNewGroupingForm::correctRect(RECT srcRect) { RECT resultRect; if (srcRect.left>srcRect.right) { resultRect.left = srcRect.right; resultRect.right = srcRect.left; } else { resultRect.left = srcRect.left; resultRect.right = srcRect.right; } if (srcRect.top>srcRect.bottom) { resultRect.top = srcRect.bottom; resultRect.bottom = srcRect.top; } else { resultRect.top = srcRect.top; resultRect.bottom = srcRect.bottom; } return resultRect; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::groupReset() { RECT selectedRect; COLORREF avgColor; if (brushMenu.getCurrentBrush() == BR_RECTANGLE) { selectedRect = correctRect(colorSelectionArea); avgColor = getAverageColor_Rect(selectedRect); groupingItemSet.setCurrentColor((TColor)avgColor); resetMask(groupingItemSet.getCurrentItem()->getMask()); } RadioSelection->Checked = true; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::colorAdd() { RECT selectedRect; COLORREF avgColor; if (brushMenu.getCurrentBrush() == BR_RECTANGLE) { selectedRect = correctRect(colorSelectionArea); addRGBSpace_Rect(selectedRect); addColorToMask(groupingItemSet.getCurrentItem()->getMask()); } } //--------------------------------------------------------------------------- COLORREF __fastcall TNewGroupingForm::getAverageColor_Rect(RECT imageRect) { Byte *bp; TUnionBitmap *theBitmap = Image->uBitmap; int ix, iy; COLORREF color; int rgb[3][256]; unsigned long temp_red = 0, temp_green = 0, temp_blue = 0, total_pixel = 0; TextReport->Lines->Add("Finding everage color"); if (imageRect.left == imageRect.right) { imageRect.left--; imageRect.right++; } if (imageRect.top == imageRect.bottom) { imageRect.top--; imageRect.bottom++; } if (imageRect.left < 0) imageRect.left = 0; if (imageRect.right > theBitmap->Width) imageRect.right = theBitmap->Width; if (imageRect.top < 0) imageRect.top = 0; if (imageRect.bottom > theBitmap->Height) imageRect.bottom = theBitmap->Height; memset(rgb, 0, 3*256*4); if (theBitmap->StartScanLine()) { for (iy=imageRect.top; iyGetScanLine(iy) + 3*imageRect.left; for (ix=imageRect.left; ixStopScanLine(); for (int i = 0; i < 256; i++) { if (rgb[0][i]) temp_red += i*rgb[0][i]; if (rgb[1][i]) temp_green += i*rgb[1][i]; if (rgb[2][i]) temp_blue += i*rgb[2][i]; } if(total_pixel != 0){ temp_red /= total_pixel; temp_green /= total_pixel; temp_blue /= total_pixel; } color = (temp_blue << 16) + (temp_green << 8) + temp_red; return color; } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return 0;} } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::addRGBSpace_Rect(RECT imageRect) { Byte *bp; TUnionBitmap *theBitmap = Image->uBitmap; int ix, iy; TextReport->Lines->Add("Adding color space"); if (imageRect.left < 0) imageRect.left = 0; if (imageRect.right > theBitmap->Width) imageRect.right = theBitmap->Width; if (imageRect.top < 0) imageRect.top = 0; if (imageRect.bottom > theBitmap->Height) imageRect.bottom = theBitmap->Height; if (theBitmap->StartScanLine()) { for (iy=imageRect.top; iyGetScanLine(iy) + 3*imageRect.left; for (ix=imageRect.left; ixStopScanLine(); } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::resetMask(TUnionBitmap *maskBitmap) { Byte *pBitmap, *pMask; TUnionBitmap *theBitmap = Image->uBitmap; int x, y; TextReport->Lines->Add("Reset mask"); theBitmap->StartScanLine(); maskBitmap->StartScanLine(); for (y = 0; y < theBitmap->Height; y++) { pBitmap = theBitmap->GetScanLine(y); pMask = maskBitmap->GetScanLine(y); for (x = 0; x< theBitmap->Width; x++, pBitmap+=3) { if(rgbSpace[pBitmap[2]][pBitmap[1]][pBitmap[0]]) { pMask[x >> 3] |= (0x80 >> (x & 7)); } else { pMask[x >> 3] &= ~(0x80 >> (x & 7)); } } maskBitmap->PutScanLine(y); } theBitmap->StopScanLine(); maskBitmap->StopScanLine(); makeMergeView(); // test } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::addColorToMask(TUnionBitmap *maskBitmap) { Byte *pBitmap, *pMask; TUnionBitmap *theBitmap = Image->uBitmap; int x, y; TextReport->Lines->Add("Add colors to mask"); theBitmap->StartScanLine(); maskBitmap->StartScanLine(); for (y = 0; y < theBitmap->Height; y++) { pBitmap = theBitmap->GetScanLine(y); pMask = maskBitmap->GetScanLine(y); for (x = 0; x< theBitmap->Width; x++, pBitmap+=3) { if(rgbSpace[pBitmap[2]][pBitmap[1]][pBitmap[0]]) { pMask[x >> 3] |= (0x80 >> (x & 7)); } } maskBitmap->PutScanLine(y); } theBitmap->StopScanLine(); maskBitmap->StopScanLine(); makeMergeView(); // test } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::simplify(int n) { Byte *pBitmap, *pMask; TUnionBitmap *theBitmap = originalBitmap; int x, y; TextReport->Lines->Add("Simplify Image " + AnsiString(n)); theBitmap->StartScanLine(); for (y = 0; y < theBitmap->Height; y++) { pBitmap = theBitmap->GetScanLine(y); for (x = 0; x< theBitmap->Width; x++, pBitmap+=3) { pBitmap[0] = pBitmap[0] / n * n; pBitmap[1] = pBitmap[1] / n * n; pBitmap[2] = pBitmap[2] / n * n; } theBitmap->PutScanLine(y); } theBitmap->StopScanLine(); resetPreviewBitmap(); /* TODO : ¾ÆÁ÷ ¹Ì¿Ï */ Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::makeMergeView() { Byte *pPreview, *pProcess, *pMask; int x, y; TextReport->Lines->Add("Make Merge View"); TColor fillColor = groupingItemSet.getCurrentColor(); BYTE fillBlue = (fillColor >> 16) & 0xFF, fillGreen = (fillColor >> 8) & 0xFF, fillRed = fillColor & 0xFF; TUnionBitmap *maskBitmap = groupingItemSet.getCurrentItem()->getMask(); previewBitmap->StartScanLine(); processingBitmap->StartScanLine(); maskBitmap->StartScanLine(); for (y = 0; y < previewBitmap->Height; y++) { pPreview = previewBitmap->GetScanLine(y); pProcess = processingBitmap->GetScanLine(y); pMask = maskBitmap->GetScanLine(y); for (x = 0; x< previewBitmap->Width; x++, pProcess+=3, pPreview+=3) { if (pMask[x >> 3] & (0x80 >> (x & 7))) { pProcess[0] = fillBlue; pProcess[1] = fillGreen; pProcess[2] = fillRed; } else { pProcess[0] = pPreview[0]; pProcess[1] = pPreview[1]; pProcess[2] = pPreview[2]; } } processingBitmap->PutScanLine(y); } previewBitmap->StopScanLine(); processingBitmap->StopScanLine(); maskBitmap->StopScanLine(); Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::makeGrayView() { Byte *pBitmap, *pSub, *pMask; int x, y; TextReport->Lines->Add("Make Gray View"); TColor fillColor = groupingItemSet.getCurrentColor(); BYTE fillBlue = (fillColor >> 16) & 0xFF, fillGreen = (fillColor >> 8) & 0xFF, fillRed = fillColor & 0xFF; // int minValue = fillBlue < fillRed ? (fillBlue < fillGreen ? 0 : 1) : (fillRed < fillGreen ? 2 : 1); // 0: blue, 1: green, 2: red static int grayType = 0; TUnionBitmap *maskBitmap = groupingItemSet.getCurrentItem()->getMask(); originalBitmap->StartScanLine(); subViewBitmap->StartScanLine(); maskBitmap->StartScanLine(); for (y = 0; y < originalBitmap->Height; y++) { pBitmap = originalBitmap->GetScanLine(y); pSub = subViewBitmap->GetScanLine(y); pMask = maskBitmap->GetScanLine(y); for (x = 0; x< originalBitmap->Width; x++, pBitmap+=3, pSub+=3) { if (pMask[x >> 3] & (0x80 >> (x & 7))) { pSub[0] = pBitmap[0]; pSub[1] = pBitmap[1]; pSub[2] = pBitmap[2]; // pSub[0] = fillBlue; // pSub[1] = fillGreen; // pSub[2] = fillRed; } else { if (grayType == 0) { pSub[0] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; pSub[1] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; pSub[2] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; } else if (grayType > 0 && grayType < 4) { pSub[0] = pSub[1] = pSub[2] = 0; pSub[grayType - 1] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; } else if (grayType == 4) { pSub[0] = 0; pSub[1] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; pSub[2] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; } else if (grayType == 5) { pSub[0] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; pSub[1] = 0; pSub[2] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; } else if (grayType == 6) { pSub[0] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; pSub[1] = (pBitmap[0] + pBitmap[1] + pBitmap[2]) / 3; pSub[2] = 0; } else if (grayType == 7) { pSub[0] = pBitmap[0] / 2; pSub[1] = pBitmap[1] / 2; pSub[2] = pBitmap[2] / 2; } else if (grayType == 8) { pSub[0] = pBitmap[0] * 2 / 3; pSub[1] = pBitmap[1] * 2 / 3; pSub[2] = pBitmap[2] * 2 / 3; } else if (grayType == 9) { pSub[0] = pBitmap[0] * 1.5 > 255 ? 255 : pBitmap[0] * 3 / 2; pSub[1] = pBitmap[1] * 1.5 > 255 ? 255 : pBitmap[1] * 3 / 2; pSub[2] = pBitmap[2] * 1.5 > 255 ? 255 : pBitmap[2] * 3 / 2; } else if (grayType == 10) { pSub[0] = pBitmap[0] * 2 > 255 ? 255 : pBitmap[0] * 2; pSub[1] = pBitmap[1] * 2 > 255 ? 255 : pBitmap[1] * 2; pSub[2] = pBitmap[2] * 2 > 255 ? 255 : pBitmap[2] * 2; } else if (grayType == 11) { pSub[0] = 255 - pBitmap[0]; pSub[1] = 255 - pBitmap[1]; pSub[2] = 255 - pBitmap[2]; } } } subViewBitmap->PutScanLine(y); } originalBitmap->StopScanLine(); subViewBitmap->StopScanLine(); maskBitmap->StopScanLine(); grayType = (grayType + 1) % 12; Image->uBitmap = subViewBitmap; Image->Repaint(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initBrushMenu() // n { brushMenu.initMenu(); } //--------------------------------------------------------------------------- void __fastcall BrushMenu::initMenu() // n { highlightedItem = BR_NONE; _brushState = FIRST_POINT; setBrush(BR_PIXEL); } //--------------------------------------------------------------------------- void __fastcall BrushMenu::setBrush(BrushType value) // n { currentBrush = value; if (currentBrush != highlightedItem) highlightItem(); } //--------------------------------------------------------------------------- void __fastcall BrushMenu::highlightItem() // n { shapeColorChange(highlightedItem, clBlack); shapeColorChange(currentBrush, clBlue); highlightedItem = currentBrush; } //--------------------------------------------------------------------------- void __fastcall BrushMenu::shapeColorChange(BrushType value, TColor color) // n { NewGroupingForm->shapeBrushColorChange(value, color); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::shapeBrushColorChange(BrushType value, TColor color) // n { if (value == BR_PIXEL) { shBrPixel->Brush->Color = color; shBrPixel->Pen->Color = color; } else if (value == BR_RECTANGLE) { shBrRectangle->Brush->Color = color; shBrRectangle->Pen->Color = color; } else if (value == BR_WHOLE) { shBrWhole->Brush->Color = color; shBrWhole->Pen->Color = color; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initFunctionMenu() // n { functionMenu.initMenu(); initGroupResetMenu(); } //--------------------------------------------------------------------------- void __fastcall FunctionMenu::initMenu() // n { highlightedItem = FUNC_NONE; setFunction(FUNC_RESET); } //--------------------------------------------------------------------------- void __fastcall FunctionMenu::setFunction(FunctionType value) // n { exitCurrentFunction(); currentFunction = value; if (currentFunction != highlightedItem) highlightItem(); } //--------------------------------------------------------------------------- void __fastcall FunctionMenu::highlightItem() // n { shapeColorChange(highlightedItem, clBlack); shapeColorChange(currentFunction, clBlue); highlightedItem = currentFunction; } //--------------------------------------------------------------------------- void __fastcall FunctionMenu::shapeColorChange(FunctionType value, TColor color) // n { NewGroupingForm->shapeFunctionColorChange(value, color); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::shapeFunctionColorChange(FunctionType value, TColor color) // n { if (value == FUNC_RESET) { shGroupReset->Brush->Color = color; shGroupReset->Pen->Color = color; } else if (value == FUNC_COLOR_ADD) { shColorAdd->Brush->Color = color; shColorAdd->Pen->Color = color; } else if (value == FUNC_TRIMMER) { shTrimmer->Brush->Color = color; shTrimmer->Pen->Color = color; } else if (value == FUNC_SIMPLIFY) { shSimplify->Brush->Color = color; shSimplify->Pen->Color = color; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnPixelBrushClick(TObject *Sender) // n { brushMenu.setBrush(BR_PIXEL); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnRectangleBrushClick(TObject *Sender) // n { brushMenu.setBrush(BR_RECTANGLE); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnSimplifyClick(TObject *Sender) // n { functionMenu.setFunction(FUNC_SIMPLIFY); initSimplifyMenu(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initSimplifyMenu() // n { BrushType defaultBrush = BR_WHOLE; panelSimplify->Visible = true; if (radioSimpUser->Checked) { editSimpUser->Enabled = true; } else { editSimpUser->Enabled = false; } btnPixelBrush->Enabled = false; btnPenBrush->Enabled = false; btnRectangleBrush->Enabled = false; btnEllipseBrush->Enabled = false; btnWholeBrush->Enabled = true; if (false == isCurrentBrushEnabled()) { brushMenu.setBrush(defaultBrush); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::exitSimplifyMenu() // n { panelSimplify->Visible = false; } //--------------------------------------------------------------------------- bool __fastcall TNewGroupingForm::isCurrentBrushEnabled() { if (brushMenu.getCurrentBrush() == BR_PIXEL) { return btnPixelBrush->Enabled; } else if (brushMenu.getCurrentBrush() == BR_PEN) { return btnPenBrush->Enabled; } else if (brushMenu.getCurrentBrush() == BR_RECTANGLE) { return btnRectangleBrush->Enabled; } else if (brushMenu.getCurrentBrush() == BR_ELLIPSE) { return btnEllipseBrush->Enabled; } else if (brushMenu.getCurrentBrush() == BR_WHOLE) { return btnWholeBrush->Enabled; } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnWholeBrushClick(TObject *Sender) // n { brushMenu.setBrush(BR_WHOLE); } //--------------------------------------------------------------------------- BrushType __fastcall BrushMenu::getCurrentBrush() { return currentBrush; } //--------------------------------------------------------------------------- FunctionType __fastcall FunctionMenu::getCurrentFunction() { return currentFunction; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::simplifyMouseDown(int X, int Y) { if (radioSimp2->Checked) { simplify(2); } else if (radioSimp4->Checked) { simplify(4); } else if (radioSimp8->Checked) { simplify(8); } else if (radioSimp16->Checked) { simplify(16); } else if (radioSimp32->Checked) { simplify(32); } else if (radioSimpUser->Checked) { simplify(editSimpUser->Text.Trim().ToInt()); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::radioSimpDefineClick(TObject *Sender) // n { editSimpUser->Enabled = false; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::radioSimpUserClick(TObject *Sender) // n { editSimpUser->Enabled = true; } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnTrimmerClick(TObject *Sender) { functionMenu.setFunction(FUNC_TRIMMER); initTrimmerMenu(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initTrimmerMenu() // n { BrushType defaultBrush = BR_WHOLE; panelTrimmer->Visible = true; btnPixelBrush->Enabled = false; btnPenBrush->Enabled = false; btnRectangleBrush->Enabled = false; btnEllipseBrush->Enabled = false; btnWholeBrush->Enabled = true; if (false == isCurrentBrushEnabled()) { brushMenu.setBrush(defaultBrush); } if (trimmer == NULL) trimmer = new Trimmer(processingBitmap->BytesPerLine); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::exitTrimmerMenu() // n { panelTrimmer->Visible = false; } //--------------------------------------------------------------------------- void __fastcall FunctionMenu::exitCurrentFunction() { if (currentFunction == FUNC_TRIMMER) { NewGroupingForm->exitTrimmerMenu(); } else if (currentFunction == FUNC_SIMPLIFY) { NewGroupingForm->exitSimplifyMenu(); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::trimmerMouseDown(int X, int Y) { if (brushMenu.getCurrentBrush() == BR_WHOLE) { trimmer_whole(); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::trimmer_whole() { TUnionBitmap *theMask = groupingItemSet.getCurrentMask(); BYTE *pLine[5] = {NULL, NULL, NULL, NULL, NULL}; int x, y; theMask->StartScanLineN(5); trimmer->setData(0, 0); trimmer->setData(1, 0); trimmer->setData(2, 0); trimmer->setData(3, 0); trimmer->setData(4, 0); if (0 < theMask->Height) { pLine[0] = theMask->GetScanLineN(0, 0); trimmer->copyLine(2, pLine[0]); } else { trimmer->setData(2, 0); } if (1 < theMask->Height) { pLine[1] = theMask->GetScanLineN(1, 1); trimmer->copyLine(3, pLine[1]); } else { trimmer->setData(3, 0); } for (y = 0; y < theMask->Height; y++) { if (y + 2 < theMask->Height) { pLine[(y + 2) % 5] = theMask->GetScanLineN(y + 2, (y + 2) % 5); trimmer->copyLine(4, pLine[(y + 2)% 5]); } else { trimmer->setData(4, 0); } for (x = 0; x < theMask->Width; x++) { if ( trimmer->isMatch_0(x, -2, -2) && trimmer->isMatch_0(x, -1, -2) && trimmer->isMatch_0(x, 0, -2) && trimmer->isMatch_0(x, 1, -2) && trimmer->isMatch_0(x, 2, -2) && trimmer->isMatch_0(x, -2, -1) && trimmer->isMatch_0(x, -1, -1) && trimmer->isMatch_0(x, 0, -1) && trimmer->isMatch_0(x, 1, -1) && trimmer->isMatch_0(x, 2, -1) && trimmer->isMatch_0(x, -2, 0) && trimmer->isMatch_0(x, -1, 0) && trimmer->isMatch_0(x, 0, 0) && trimmer->isMatch_0(x, 1, 0) && trimmer->isMatch_0(x, 2, 0) && trimmer->isMatch_0(x, -2, 1) && trimmer->isMatch_0(x, -1, 1) && trimmer->isMatch_0(x, 0, 1) && trimmer->isMatch_0(x, 1, 1) && trimmer->isMatch_0(x, 2, 1) && trimmer->isMatch_0(x, -2, 2) && trimmer->isMatch_0(x, -1, 2) && trimmer->isMatch_0(x, 0, 2) && trimmer->isMatch_0(x, 1, 2) && trimmer->isMatch_0(x, 2, 2) ) { trimmer->setData_0(x, y, pLine, theMask->Width, theMask->Height); } } if ((y - 2 >= 0) && (y - 2 < theMask->Height)) { theMask->PutScanLineN(y - 2, (y - 2) % 5); } trimmer->proceedLine(); } for (int iy = y - 1; iy <= y + 2; iy++) { if (iy >= 0 && iy < theMask->Height) { theMask->PutScanLineN(iy, iy % 5); } } trimmer->setData(0, 0xFF); trimmer->setData(1, 0xFF); trimmer->setData(2, 0xFF); trimmer->setData(3, 0xFF); trimmer->setData(4, 0xFF); if (0 < theMask->Height) { pLine[0] = theMask->GetScanLineN(0, 0); trimmer->copyLine(2, pLine[0]); } else { trimmer->setData(2, 0xFF); } if (1 < theMask->Height) { pLine[1] = theMask->GetScanLineN(1, 1); trimmer->copyLine(3, pLine[1]); } else { trimmer->setData(3, 0xFF); } for (y = 0; y < theMask->Height; y++) { if (y + 2 < theMask->Height) { pLine[(y + 2) % 5] = theMask->GetScanLineN(y + 2, (y + 2) % 5); trimmer->copyLine(4, pLine[(y + 2) % 5]); } else { trimmer->setData(4, 0xFF); } for (x = 0; x < theMask->Width; x++) { if ( trimmer->isMatch_1(x, -2, -2) && trimmer->isMatch_1(x, -1, -2) && trimmer->isMatch_1(x, 0, -2) && trimmer->isMatch_1(x, 1, -2) && trimmer->isMatch_1(x, 2, -2) && trimmer->isMatch_1(x, -2, -1) && trimmer->isMatch_1(x, -1, -1) && trimmer->isMatch_1(x, 0, -1) && trimmer->isMatch_1(x, 1, -1) && trimmer->isMatch_1(x, 2, -1) && trimmer->isMatch_1(x, -2, 0) && trimmer->isMatch_1(x, -1, 0) && trimmer->isMatch_1(x, 0, 0) && trimmer->isMatch_1(x, 1, 0) && trimmer->isMatch_1(x, 2, 0) && trimmer->isMatch_1(x, -2, 1) && trimmer->isMatch_1(x, -1, 1) && trimmer->isMatch_1(x, 0, 1) && trimmer->isMatch_1(x, 1, 1) && trimmer->isMatch_1(x, 2, 1) && trimmer->isMatch_1(x, -2, 2) && trimmer->isMatch_1(x, -1, 2) && trimmer->isMatch_1(x, 0, 2) && trimmer->isMatch_1(x, 1, 2) && trimmer->isMatch_1(x, 2, 2) ) { trimmer->setData_1(x, y, pLine, theMask->Width, theMask->Height); } } if (y - 2 >= 0 && y - 2 < theMask->Height) { theMask->PutScanLineN(y - 2, (y - 2) % 5); } trimmer->proceedLine(); } for (int iy = y - 1; iy <= y + 2; iy++) { if (iy >= 0 && iy < theMask->Height) { theMask->PutScanLineN(iy, iy % 5); } } theMask->StopScanLine(); makeMergeView(); // test } //--------------------------------------------------------------------------- __fastcall Trimmer::Trimmer(int bytesPerLine) { lineSize = bytesPerLine; for (int i = 0; i < 5; i++) { compareLine[i] = (BYTE *)HeapAlloc(GetProcessHeap(), 0, bytesPerLine + 2); } initBasicMask(0); } //--------------------------------------------------------------------------- __fastcall Trimmer::~Trimmer() { for (int i = 0; i < 5; i++) { HeapFree(GetProcessHeap(), 0, compareLine[i]); } } //--------------------------------------------------------------------------- void __fastcall Trimmer::copyLine(int yDst, BYTE *srcLine) { memcpy(compareLine[yDst] + 1, srcLine, lineSize); } //--------------------------------------------------------------------------- void __fastcall Trimmer::setData(int lineNum, BYTE value) { memset(compareLine[lineNum], value, lineSize + 2); } //--------------------------------------------------------------------------- void __fastcall Trimmer::proceedLine() { BYTE *switchLine; switchLine = compareLine[0]; compareLine[0] = compareLine[1]; compareLine[1] = compareLine[2]; compareLine[2] = compareLine[3]; compareLine[3] = compareLine[4]; compareLine[4] = switchLine; } //--------------------------------------------------------------------------- bool __fastcall Trimmer::isMatch_0(int x, int xDiff, int yDiff) { return (trimmerMask[2 + yDiff][2 + xDiff] != 0) || !(compareLine[2 + yDiff][((x + xDiff) >> 3) + 1] & (0x80 >> ((x + xDiff) & 7))); } //--------------------------------------------------------------------------- bool __fastcall Trimmer::isMatch_1(int x, int xDiff, int yDiff) { return (trimmerMask[2 + yDiff][2 + xDiff] != 0) || (compareLine[2 + yDiff][((x + xDiff) >> 3) + 1] & (0x80 >> ((x + xDiff) & 7))); } //--------------------------------------------------------------------------- void __fastcall Trimmer::initBasicMask(int styleNum) { filterType = styleNum; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { trimmerMask[i][j] = -1; } } if (styleNum == 0) { trimmerMask[ 1][ 1] = 0; trimmerMask[ 1][ 2] = 0; trimmerMask[ 1][ 3] = 0; // 000 trimmerMask[ 2][ 1] = 0; trimmerMask[ 2][ 2] = 1; trimmerMask[ 2][ 3] = 0; // 010 trimmerMask[ 3][ 1] = 0; trimmerMask[ 3][ 2] = 0; trimmerMask[ 3][ 3] = 0; // 000 } else if (styleNum == 1) { trimmerMask[ 1][ 0] = 0; trimmerMask[ 1][ 1] = 0; trimmerMask[ 1][ 2] = 0; trimmerMask[ 1][ 3] = 0; // 0000 trimmerMask[ 2][ 0] = 0; trimmerMask[ 2][ 1] = 1; trimmerMask[ 2][ 2] = 1; trimmerMask[ 2][ 3] = 0; // 0110 trimmerMask[ 3][ 0] = 0; trimmerMask[ 3][ 1] = 0; trimmerMask[ 3][ 2] = 0; trimmerMask[ 3][ 3] = 0; // 0000 } else if (styleNum == 2) { trimmerMask[ 0][ 1] = 0; trimmerMask[ 0][ 2] = 0; trimmerMask[ 0][ 3] = 0; // 000 trimmerMask[ 1][ 1] = 0; trimmerMask[ 1][ 2] = 1; trimmerMask[ 1][ 3] = 0; // 010 trimmerMask[ 2][ 1] = 0; trimmerMask[ 2][ 2] = 1; trimmerMask[ 2][ 3] = 0; // 010 trimmerMask[ 3][ 1] = 0; trimmerMask[ 3][ 2] = 0; trimmerMask[ 3][ 3] = 0; // 000 } else if (styleNum == 3) { trimmerMask[ 1][ 2] = 0; // 0 trimmerMask[ 2][ 1] = 0; trimmerMask[ 2][ 2] = 1; trimmerMask[ 2][ 3] = 0; // 010 trimmerMask[ 3][ 2] = 0; // 0 } else if (styleNum == 4) { trimmerMask[ 0][ 0] = 0; trimmerMask[ 0][ 1] = 0; trimmerMask[ 0][ 2] = 0; trimmerMask[ 0][ 3] = 0; // 0000 trimmerMask[ 1][ 0] = 0; trimmerMask[ 1][ 1] = 1; trimmerMask[ 1][ 2] = 1; trimmerMask[ 1][ 3] = 0; // 0110 trimmerMask[ 2][ 0] = 0; trimmerMask[ 2][ 1] = 1; trimmerMask[ 2][ 2] = 1; trimmerMask[ 2][ 3] = 0; // 0110 trimmerMask[ 3][ 0] = 0; trimmerMask[ 3][ 1] = 0; trimmerMask[ 3][ 2] = 0; trimmerMask[ 3][ 3] = 0; // 0000 } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btn1DotClick(TObject *Sender) { trimmer->initBasicMask(0); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnHor2DotClick(TObject *Sender) { trimmer->initBasicMask(1); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnVer2DotClick(TObject *Sender) { trimmer->initBasicMask(2); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnCrossClick(TObject *Sender) { trimmer->initBasicMask(3); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btn2x2SquareClick(TObject *Sender) { trimmer->initBasicMask(4); } //--------------------------------------------------------------------------- void __fastcall Trimmer::setData_0(int x, int y, BYTE **pLine, int width, int height) { for (int iy = 0; iy < 5; iy++) { for (int jx = 0; jx < 5; jx++) { if (trimmerMask[iy][jx] == 1 && (y + iy - 2) >= 0 && (y + iy - 2) < height && (x + jx - 2) >= 0 && (x + jx - 2) < width && pLine[(y + iy - 2) % 5] != NULL) { pLine[(y + iy - 2) % 5][(x + jx - 2) >> 3] &= ~(0x80 >> ((x + jx - 2) & 7)); } } } } //--------------------------------------------------------------------------- void __fastcall Trimmer::setData_1(int x, int y, BYTE **pLine, int width, int height) { for (int iy = 0; iy < 5; iy++) { for (int jx = 0; jx < 5; jx++) { if (trimmerMask[iy][jx] == 1 && (y + iy - 2) >= 0 && (y + iy - 2) < height && (x + jx - 2) >= 0 && (x + jx - 2) < width && pLine[(y + iy - 2) % 5] != NULL) { pLine[(y + iy - 2) % 5][(x + jx - 2) >> 3] |= (0x80 >> ((x + jx - 2) & 7)); } } } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnGroupResetClick(TObject *Sender) { functionMenu.setFunction(FUNC_RESET); initGroupResetMenu(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initGroupResetMenu() { BrushType defaultBrush = BR_RECTANGLE; btnPixelBrush->Enabled = false; btnPenBrush->Enabled = false; btnRectangleBrush->Enabled = true; btnEllipseBrush->Enabled = false; btnWholeBrush->Enabled = false; if (false == isCurrentBrushEnabled()) { brushMenu.setBrush(defaultBrush); } resetProcessingBitmap(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::btnColorAddClick(TObject *Sender) { functionMenu.setFunction(FUNC_COLOR_ADD); initColorAddMenu(); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::initColorAddMenu() { BrushType defaultBrush = BR_RECTANGLE; btnPixelBrush->Enabled = false; btnPenBrush->Enabled = false; btnRectangleBrush->Enabled = true; btnEllipseBrush->Enabled = false; btnWholeBrush->Enabled = false; if (false == isCurrentBrushEnabled()) { brushMenu.setBrush(defaultBrush); } } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::resetProcessingBitmap() { processingBitmap->ExactCopy(previewBitmap); } //--------------------------------------------------------------------------- void __fastcall TNewGroupingForm::resetPreviewBitmap() { previewBitmap->ExactCopy(originalBitmap); } //---------------------------------------------------------------------------