//--------------------------------------------------------------------------- #pragma hdrstop #include "grouping_lib2.h" #include "math.h" #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // óÀ½À¸·Î ¿øÇÏ´Â »öÀÌ ³ª¿À¸é Label=0, 3 X 3 À©µµ¿ì·Î ÁÖº¯À» È®ÀÎÇÏ°í ¿·¿¡ °°Àº »öÀÌ ÀÖÀ¸¸é // ±× Çȼ¿µµ °°Àº LabelÀ» ºÙÈù´Ù. ¸¸¾à ¿·ÀÇ LabelÀÌ ÀÌ¹Ì ºÙÀº °ÍÀ̸é ÇöÀçÀÇ LabelÀ» ±× Label·Î // º¯°æÇÑ´Ù. // ¸¸¾à »õ·Î¿î LabelÀ» ºÙ¿©¼­ °è¼Ó ³ª°¡´Ù°¡ ¿¬°áµÇ¾úÀ¸¸é¼­ ÀÌÀü LabelÀ» °¡Áö°í ÀÖ´Ù¸é // óÀ½ ºÎÅÍ Áö±Ý±îÁö »õ·Î¿î LabelÀ» ºÙÈù °ÍÀ» ÀÌÀü Label·Î °íÄ£´Ù.(ÇÔ¼ö»ç¿ë) //--------------------------------------------------------------------------- void __fastcall LabelingFilter(TUnionBitmap *previewBitmap, TList *ListOfColor, TList *GroupingColorList, int pixelSize, TStatusProgress *progress, TPWorkArea *WorkArea) { BEGIN_LOG(""); TColor *cp; progress->Maximum = previewBitmap->Height * 11 * ListOfColor->Count; for (int i=0; iCount; i++) { cp = (TColor *)ListOfColor->Items[i]; if (WorkArea) makeLabelingMapWA(previewBitmap, cp, GroupingColorList, pixelSize, progress, WorkArea); else makeLabelingMap(previewBitmap, cp, GroupingColorList, pixelSize, progress); } progress->End(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall makeLabelingMap(TUnionBitmap *previewBitmap, TColor *cp, TList *GroupingColorList, int pixelSize, TStatusProgress *progress) { BEGIN_LOG(""); Byte *Line; Byte c_Red, c_Green, c_Blue; int x, y, i, j; int Width = previewBitmap->Width; int Height = previewBitmap->Height; int Label; int **LabelIndex; Byte **LabelColor; int **LabelCCheck; int *ET; int order; int D; int v,v1,v2,v3,v4, VT1,VT2; int v5,v6,v7,v8,VT3,VT4, VT5,VT6; int LabelNum; LabelIndex = new int *[Height]; LabelColor = new Byte *[Height]; for(int i =0;iPosition++; } //------------------------------------------------------------------------- c_Red = *cp & 0xFF; c_Green = (*cp >> 8) & 0xFF; c_Blue = (*cp >> 16) & 0xFF; previewBitmap->StartScanLine(); for (y=1; yGetScanLine(y); for (x=1; xPosition++; } previewBitmap->StopScanLine(); //------------------------------------------------------------------------- Label = 2; for(y=1; y= v2) VT1 = v2; // v1, v2, v3, v4¸¦ ºñ±³Çؼ­ v(x,y)¸¦ ±¸ÇÑ´Ù. else VT1 = v1; // À̹ÌÁö¸¦ Çѹø ScanÇØ¼­ LabelIndex¸¦ Çѹø¿¡ if(v3 >= v4) VT2 = v4; // ¸¸µé±â À§ÇÑ ºÎºÐÀÌ´Ù. else VT2 = v3; // ÇöÀç±îÁö scanÇÑ Çȼ¿Áß¿¡ v1, v2, v3, v4´Â v¿Í if(VT1 >= VT2) v = VT2; // ¿¬°áµÇ¾î ÀÖ´Â Çȼ¿µéÀÌ´Ù. ±× Áß¿¡¼­ °¡Àå ÀÛÀº else v = VT1; // LabelÀ» °¡Áø °ÍÀÌ vÀÇ LavelÀÌ µÈ´Ù. if(v == 255 || v == 0) { LabelIndex[y][x] = Label; Label++; } else LabelIndex[y][x] = v; } } progress->Position++; } for(y=Height-1; y >= 0; y--) // (Height-1, Width-1)¿¡¼­ scan½ÃÀÛ { // for(x= Width-1; x >=0; x--) // 0 0 0 0 1 1 1 °°Àº °æ¿ì¸¦ ó¸®Çϱâ À§Çؼ­ { // 5 5 5 1 1 0 0 if(LabelColor[y][x] == 0) continue; v1 = 255; v2 = 255; v3 = 255; v4 = 255; if(x ==0 || y ==0 || x == Width-1 || y ==Height-1) continue; if(LabelColor[y][x+1] == 1) v1 =LabelIndex[y][x+1]; if(LabelColor[y+1][x+1] == 1) v2 =LabelIndex[y+1][x+1]; if(LabelColor[y+1][x] == 1) v3 =LabelIndex[y+1][x]; if(LabelColor[y+1][x-1] == 1) v4 =LabelIndex[y+1][x-1]; if(v1 >= v2) VT1 = v2; else VT1 = v1; if(v3 >= v4) VT2 = v4; else VT2 = v3; if(VT1 >= VT2) v = VT2; else v = VT1; if(v == 255 || v == 0); else LabelIndex[y][x] = v; } progress->Position++; } //////////////////////////////////////////////////////////////// LabelCCheck = new int *[Label]; for(i =0; iPosition++; } order = 2; for(x= 0; x< Label; x++) { if(LabelCCheck[x][0]) // °¢ LabelIndex¿¡ ´ëÇÑ LabelCCheck¿¡ 1À̸é order¸¦ Áõ°¡½ÃÄÑ { // LabelCCheck¿¡ Lebel No.¸¦ ÀúÀå LabelCCheck[x][1] = order; order++; } } for(y=1; yPosition++; } //------------------------------------------------------------------------- // µî°¡ Å×À̺í(Equivalence Table)À» ¸¸µå´Â ºÎºÐ // LabelÀ» ¸¸µå´Â °úÁ¤¿¡ ¹®Á¦°¡ À־ µÎ°¡Áö °æ¿ì·Î ó¸®ÇßÁö¸¸ ´ë°¢¼±¹æÇâÀº // ¿©ÀüÈ÷ ¹®Á¦°¡ Á¸ÀçÇÑ´Ù. ÀÌ ¹®Á¦¸¦ ÇØ°áÇϱâ À§Çؼ­ µî°¡Å×À̺íÀ» ÀÌ¿ëÇÑ´Ù. // 3 X 3 À©µµ¿ì°¡ µ¹¸é¼­ ÁÖº¯ÀÇ Label¸¦ ºÐ¼® Table¿¡ Label°ªÀ» ÀúÀåÇÏ´Ù. ET = new int [order]; for(y=0; y=LabelIndex[i][j]) ET[D] = LabelIndex[i][j]; } } } } progress->Position++; } // µî°¡ Å×À̺íÀ» ÀÌ¿ëÇØ¼­ Labelindex¸¦ Á¤¸®ÇÏ´Â ºÎºÐ // ¿¹) no. 1 2 3 4 5 6 7 8 9 9 10 // ET[x]: 1 1 2 4 4 3 6 2 7 .... // °á°ú: 1 1 1 4 4 1 1 1 1 .... // Å×ÀÌºí¿¡ µû¶ó¼­ °¢°¢ÀÇ LabelÀÌ ¾î´À Label°ú °°Àº °ÍÀÎÁö °áÁ¤µÈ´Ù. int M; for(x = 2; xPosition++; } LabelNum = order; //------------------------------------------------------------------------- // Label MapÀ» ¸¸µçÈÄ¿¡ °¢°¢ LabelÀÇ °³¼ö¸¦ È®ÀÎÇÑ´Ù. // °°Àº LabelÀÌ ºÙÀº °Í°ú PixelÀÇ ¼ö°¡ °°Àº °ÍÀ» º¯°æÇϱâ À§Çؼ­... // i : Label Number, k[i] : Pixel Number°¡ µÈ´Ù. // nL[cNum] : Á¦°ÅÇϱ⠿øÇÏ´Â PixelSizeÀÇ LabelNum unsigned short *k = new unsigned short[LabelNum]; for ( i=2; iPosition++; } //------------------------------------------------------------------------- // Noise¿¡ ä¿ö¾ß ÇÒ Color¸¦ ã´Â ºÎºÐ // chColorIndex : 2Â÷¿ø ¹è¿­·Î LabelNum¿Í GroupingColorListÀÇ ¼ö°¡ µé¾î°£´Ù. unsigned short **chColorIndex; Byte *upLine, *middLine, *downLine; TColor tempCP; try { chColorIndex = new unsigned short *[LabelNum];// STEP 1: SET UP THE ROWS. for (j = 0; j < LabelNum; j++) chColorIndex[j] = new unsigned short[GroupingColorList->Count]; // STEP 2: SET UP THE COLUMNS } catch (...) { // ENTER THIS BLOCK ONLY IF bad_alloc IS THROWN. // YOU COULD REQUEST OTHER ACTIONS BEFORE TERMINATING cout << "Could not allocate. Bye ..."; exit(-1); } for (i=0; iCount; j++) { chColorIndex[i][j]=0; } } previewBitmap->StartScanLineN(3); for ( y=1; yGetScanLineN(y-1, (y-1)%3); middLine = previewBitmap->GetScanLineN( y, y%3); downLine = previewBitmap->GetScanLineN(y+1, (y+1)%3); for ( x=1; xPosition++; } previewBitmap->StopScanLine(); //------------------------------------------------------------------------- // °¢°¢ÀÇ Label¿¡ ´ëÇØ¼­ ÁÖº¯ »öÁß °¡Àå ¸¹Àº »öÀ» ã´Â ºÎºÐ int t=0, indt=0; int Max; for (i=2; iCount; j++) { if(Max <= chColorIndex[i][j]) { Max = chColorIndex[i][j]; indt = j; } } chColorIndex[i][0] = indt; } //------------------------------------------------------------------------- // ¸¶¹«¸® ÀÛ¾÷ // ³ëÀÌÁ ´Ù¸¥ »öÀ¸·Î ±³Ã¼ÇÑ´Ù. previewBitmap->StartScanLine(); for (y=1; yGetScanLine(y); for (x=1; xItems[chColorIndex[LabelIndex[y][x]][0]]) & 0xFF; c_Green = (*((TColor *)GroupingColorList->Items[chColorIndex[LabelIndex[y][x]][0]]) >> 8) & 0xFF; c_Blue = (*((TColor *)GroupingColorList->Items[chColorIndex[LabelIndex[y][x]][0]]) >> 16) & 0xFF; Line[3*x]=c_Blue; Line[3*x+1]=c_Green; Line[3*x+2]=c_Red; } } previewBitmap->PutScanLine(y); progress->Position++; } previewBitmap->StopScanLine(); //------------------------------------------------------------------------- delete[] k; de_allist(chColorIndex, LabelNum); for(i =0; iRange; int Width = Range.right - Range.left; int Height = Range.bottom - Range.top; if ( (Height < pixelSize) || (Width < pixelSize) ) return; BEGIN_LOG(""); int Label; int **LabelIndex; Byte **LabelColor; int **LabelCCheck; int *ET; int order; int D; int v,v1,v2,v3,v4, VT1,VT2; int v5,v6,v7,v8,VT3,VT4, VT5,VT6; int LabelNum; LabelIndex = new int *[Height]; LabelColor = new Byte *[Height]; for(i =0;iPosition++; } //------------------------------------------------------------------------- c_Red = *cp & 0xFF; c_Green = (*cp >> 8) & 0xFF; c_Blue = (*cp >> 16) & 0xFF; previewBitmap->StartScanLine(); WorkArea->Mask->StartScanLine(); for (y=1; yGetScanLine(y + Range.top, Range.left, Width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(y); // 1 bit mask°¡ µÇ¾ú´Ù ¶Ç´Â ¾Æ´Ï´Ù (on/off) for (x=1; x> 3] & (0x80 >> (x & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if (Line[3*x] == c_Blue && Line[3*x+1] == c_Green && Line[3*x+2] == c_Red ) LabelColor[y][x]=1; } } progress->Position++; } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); //------------------------------------------------------------------------- Label = 2; for(y=1;y= v2) VT1 = v2; else VT1 = v1; if(v3 >= v4) VT2 = v4; else VT2 = v3; if(VT1 >= VT2) v = VT2; else v = VT1; if(v == 255 || v == 0) { LabelIndex[y][x] = Label; Label++; } else LabelIndex[y][x] = v; } } progress->Position++; } for(y=Height-1;y >= 0;y--) { for(x= Width-1 ;x >=0 ;x--) { if(LabelColor[y][x] == 0) continue; v1 = 255; v2 = 255; v3 = 255; v4 = 255; if(x ==0 || y ==0 || x == Width-1 || y ==Height-1) continue; if(LabelColor[y][x+1] == 1) v1 =LabelIndex[y][x+1]; if(LabelColor[y+1][x+1] == 1) v2 =LabelIndex[y+1][x+1]; if(LabelColor[y+1][x] == 1) v3 =LabelIndex[y+1][x]; if(LabelColor[y+1][x-1] == 1) v4 =LabelIndex[y+1][x-1]; if(v1 >= v2) VT1 = v2; else VT1 = v1; if(v3 >= v4) VT2 = v4; else VT2 = v3; if(VT1 >= VT2) v = VT2; else v = VT1; if(v == 255 || v == 0); else LabelIndex[y][x] = v; } progress->Position++; } /////////////////////////////////////////////////////////// LabelCCheck = new int *[Label]; for(i =0;iPosition++; } order = 2; for(x= 0; xPosition++; } /////////////////////////////////////////// ET = new int [order]; /////////////////////////////////////////// for(y = 0; y=LabelIndex[i][j]) ET[D] = LabelIndex[i][j]; } } } } progress->Position++; } int M; for(x = 2; x < order; x++) { M = x; do { D = ET[M]; M = D; } while(ET[D] != D); ET[x] = M; } for(y=1; yPosition++; } LabelNum = order; //------------------------------------------------------------------------- // Label MapÀ» ¸¸µçÈÄ¿¡ °¢°¢ LabelÀÇ °³¼ö¸¦ È®ÀÎÇÑ´Ù. // °°Àº LabelÀÌ ºÙÀº °Í°ú PixelÀÇ ¼ö°¡ °°Àº °ÍÀ» º¯°æÇϱâ À§Çؼ­... // i : Label Number, k[i] : Pixel Number°¡ µÈ´Ù. // nL[cNum] : Á¦°ÅÇϱ⠿øÇÏ´Â PixelSizeÀÇ LabelNum unsigned short *k = new unsigned short[LabelNum]; for ( i=2; i< LabelNum; i++) k[i]=0; for ( y=1; y < Height-1; y++ ) { for ( x=1; x < Width-1; x++ ) { k[LabelIndex[y][x]]++; } progress->Position++; } //------------------------------------------------------------------------- // Noise¿¡ ä¿ö¾ß ÇÒ Color¸¦ ã´Â ºÎºÐ // chColorIndex : 2Â÷¿ø ¹è¿­·Î LabelNum¿Í GroupingColorListÀÇ ¼ö°¡ µé¾î°£´Ù. unsigned short **chColorIndex; Byte *upLine, *middLine, *downLine; TColor tempCP; try { // TEST FOR EXCEPTIONS. chColorIndex = new unsigned short *[LabelNum]; // STEP 1: SET UP THE ROWS. for (j = 0; j < LabelNum; j++) chColorIndex[j] = new unsigned short[GroupingColorList->Count]; // STEP 2: SET UP THE COLUMNS } catch (...) { // ENTER THIS BLOCK ONLY IF bad_alloc IS THROWN. // YOU COULD REQUEST OTHER ACTIONS BEFORE TERMINATING cout << "Could not allocate. Bye ..."; exit(-1); } for (i=0; iCount; j++) { chColorIndex[i][j]=0; } } previewBitmap->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for ( y = 1; y < Height-1; y++ ) { upLine = previewBitmap->GetScanLineN( (y-1) + Range.top, Range.left, Width, (y-1)%3 ) + 3 * Range.left; middLine = previewBitmap->GetScanLineN( y + Range.top, Range.left, Width, y%3 ) + 3 * Range.left; downLine = previewBitmap->GetScanLineN( (y+1) + Range.top, Range.left, Width, (y+1)%3) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(y); // 1 bit mask°¡ µÇ¾ú´Ù ¶Ç´Â ¾Æ´Ï´Ù (on/off) for ( x = 1; x < Width-1; x++ ) { if (pMask[x >> 3] & (0x80 >> (x & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(k[LabelIndex[y][x]] <=pixelSize) { // up // R, G, B ¸ðµÎ °°Áö ¾Ê¾Æ¾ß Çϱ⠶§¹®¿¡ ÀÌ·¸°Ô if/else·Î ó¸®Çß´Ù. if ( upLine[3*x]==c_Blue && upLine[3*x+1]==c_Green && upLine[3*x+2]==c_Red ); else { tempCP= (TColor)(upLine[3*x]<<16 | upLine[3*x+1]<<8 | upLine[3*x+2]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } if ( upLine[3*x+3]==c_Blue && upLine[3*x+4]==c_Green && upLine[3*x+5]==c_Red ); else { tempCP= (TColor)(upLine[3*x+3]<<16 | upLine[3*x+4]<<8 | upLine[3*x+5]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } if ( upLine[3*x+6]==c_Blue && upLine[3*x+7]==c_Green && upLine[3*x+8]==c_Red ); else { tempCP= (TColor)(upLine[3*x+6]<<16 | upLine[3*x+7]<<8 | upLine[3*x+8]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } // middle if ( middLine[3*x]==c_Blue && middLine[3*x+1]==c_Green && middLine[3*x+2]==c_Red ); else { tempCP= (TColor)(middLine[3*x]<<16 | middLine[3*x+1]<<8 | middLine[3*x+2]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } if ( middLine[3*x+6]==c_Blue && middLine[3*x+7]==c_Green && middLine[3*x+8]==c_Red ); else { tempCP= (TColor)(middLine[3*x+6]<<16 | middLine[3*x+7]<<8 | middLine[3*x+8]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } // down if ( downLine[3*x]==c_Blue && downLine[3*x+1]==c_Green && downLine[3*x+2]==c_Red ); else { tempCP= (TColor)(downLine[3*x]<<16 | downLine[3*x+1]<<8 | downLine[3*x+2]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } if ( downLine[3*x+3]==c_Blue && downLine[3*x+4]==c_Green && downLine[3*x+5]==c_Red ); else { tempCP= (TColor)(downLine[3*x+3]<<16 | downLine[3*x+4]<<8 | downLine[3*x+5]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } if ( downLine[3*x+6]==c_Blue && downLine[3*x+7]==c_Green && downLine[3*x+8]==c_Red ); else { tempCP= (TColor)(downLine[3*x+6]<<16 | downLine[3*x+7]<<8 | downLine[3*x+8]); checkChangingColor(chColorIndex, LabelIndex[y][x], GroupingColorList, tempCP); } } } // ¿©±â±îÁö Mask } progress->Position++; } previewBitmap->StopScanLine(); WorkArea->Mask->StopScanLine(); //------------------------------------------------------------------------- int t=0, indt=0; int Max; for (i=2; iCount; j++) { if(Max <= chColorIndex[i][j]) { Max = chColorIndex[i][j]; indt = j; } } chColorIndex[i][0] = indt; } //------------------------------------------------------------------------- // ¸¶¹«¸® ÀÛ¾÷ // ³ëÀÌÁ ´Ù¸¥ »öÀ¸·Î ±³Ã¼ÇÑ´Ù. previewBitmap->StartScanLine(); WorkArea->Mask->StartScanLine(); for (y=1; yGetScanLine(y + Range.top, Range.left, Width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(y); // 1 bit mask°¡ µÇ¾ú´Ù ¶Ç´Â ¾Æ´Ï´Ù (on/off) for (x=1; x> 3] & (0x80 >> (x & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(k[LabelIndex[y][x]] <=pixelSize) { c_Red = *((TColor *)GroupingColorList->Items[chColorIndex[LabelIndex[y][x]][0]]) & 0xFF; c_Green = (*((TColor *)GroupingColorList->Items[chColorIndex[LabelIndex[y][x]][0]]) >> 8) & 0xFF; c_Blue = (*((TColor *)GroupingColorList->Items[chColorIndex[LabelIndex[y][x]][0]]) >> 16) & 0xFF; Line[3*x]=c_Blue; Line[3*x+1]=c_Green; Line[3*x+2]=c_Red; } } } previewBitmap->PutScanLine(y + Range.top, Range.left, Width); progress->Position++; } previewBitmap->StopScanLine(); WorkArea->Mask->StopScanLine(); //------------------------------------------------------------------------- delete[] k; de_allist(chColorIndex, LabelNum); for(i =0; iCount; i++) { if ( *((TColor *)GroupingColorList->Items[i]) == tempCP ) chColorIndex[reLableNum][i]++; } } //--------------------------------------------------------------------------- void __fastcall checkImageLabel(int xX,int yY, unsigned short **LabelIndex, unsigned short LabelNum, int height, int width) { int cnt, x, y; LabelIndex[yY][xX]=LabelNum; for ( ; ; ) { cnt=0; for ( y = 1; y < height-1; y++ ) { for ( x = 1; x < width-1; x++ ) { if ( LabelIndex[y][x] == LabelNum ) { if (LabelIndex[y-1][x-1] == 1) {LabelIndex[y-1][x-1]=LabelNum; cnt++;} if (LabelIndex[y-1][x] == 1) {LabelIndex[y-1][x]=LabelNum; cnt++;} if (LabelIndex[y-1][x+1] == 1) {LabelIndex[y-1][x+1]=LabelNum; cnt++;} if (LabelIndex[y][x-1] == 1) {LabelIndex[y][x-1]=LabelNum; cnt++;} if (LabelIndex[y][x+1] == 1) {LabelIndex[y][x+1]=LabelNum; cnt++;} if (LabelIndex[y+1][x-1] == 1) {LabelIndex[y+1][x-1]=LabelNum; cnt++;} if (LabelIndex[y+1][x] == 1) {LabelIndex[y+1][x]=LabelNum; cnt++;} if (LabelIndex[y+1][x+1] == 1) {LabelIndex[y+1][x+1]=LabelNum; cnt++;} } } // ¿©±â±îÁö for (int x=1 ~ } // ¿©±â±îÁö for (int y=1 ~ if (cnt==0) return; } } //--------------------------------------------------------------------------- void __fastcall EraseOutLine(TUnionBitmap *previewBitmap, TList *ListOfColor, TColor *cp, TStatusProgress *progress) { BEGIN_LOG(""); Byte *ptr,*ptrU, *ptrD,*ptrUU, *ptrDD, *Aptr1,*AptrU,*AptrUU,*AptrD,*AptrDD, *Aptr2, *Aptr2U, *Aptr2D; Byte Neigh[9][3]; int NMean[3]; int SColor[3]; int MiniL; Byte WinColor[9]; unsigned char WinSpace[9]; int TPColor[100]; int MaxCnt; int SelectColor; int Va; int Dummy; int WinCnt; int N,again; bool breakSW; int Cnt, height, width; Byte *tempMidd, *tempDown; Byte *tempApMidd, *tempApDown; Byte *tempAp2Midd, *tempAp2Down; Byte items_red = 0, items_green = 0, items_blue = 0; height = previewBitmap->Height; width = previewBitmap->Width; progress->Maximum = height * 25; TUnionBitmap *tempBitmap = new TUnionBitmap; tempBitmap->Create(width, height, 24); TUnionBitmap *tempBitmap2 = new TUnionBitmap; tempBitmap2->Create(width, height, 24); previewBitmap->PartialUndo->RangeSaveUndo(0, 0, previewBitmap->Width, previewBitmap->Height); //by linuxjun //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine(i); Aptr1 = tempBitmap->GetScanLine(i); for(int j = 0 ;j < width; j++) { Aptr1[3*j] = ptr[3*j]; Aptr1[3*j+1] = ptr[3*j+1]; Aptr1[3*j+2] = ptr[3*j+2]; } tempBitmap->PutScanLine(i); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); //------------------------------------------------------------------------- for(int n = 0; nCount;n++) { if( *((TColor *)ListOfColor->Items[n]) == *cp ) Va = n; } //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap2->StartScanLine(); for(int y = 0; y < height ; y++) { ptr = previewBitmap->GetScanLine(y); Aptr2 = tempBitmap2->GetScanLine(y); for(int x = 0 ;x < width; x++) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if( ptr[3*(x)]== items_blue && ptr[3*(x)+1]== items_green && ptr[3*(x)+2]== items_red ) { Aptr2[3*x] = 1; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } else { Aptr2[3*x] = 0; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } } tempBitmap2->PutScanLine(y); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- Cnt = 5; do { Cnt--; again = 0; tempBitmap2->StartScanLineN(3); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i, i%3); } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i, i%3); } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i, i%3); } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i, i%3); } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*j] != 1) continue; //¿µ»óÀÇ Áß¾Ó ºÎºÐÀ» Áß½ÉÀ¸·Î 1ÀÎ ¿µ»óÀÇ °³¼ö °è»ê. WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((Aptr1[3*(j+1)]*AptrU[3*(j)]*Aptr1[3*(j-1)]) == 0 && (AptrU[3*(j)]*AptrD[3*(j)]*Aptr1[3*(j-1)])== 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } tempBitmap2->PutScanLineN(i-1,(i-1)%3); } progress->Position++; } tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); for(int i = 1; i GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0; } } tempBitmap2->PutScanLine(i); progress->Position++; } tempBitmap2->StopScanLine(); if(again == 0) break; // Second sub-iteration //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLineN(3); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i, i%3); } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i, i%3); } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i, i%3); } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i, i%3); } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*(j)] != 1) continue; WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((AptrU[3*(j)]*Aptr1[3*(j+1)]*AptrD[3*(j)]) == 0 &&(Aptr1[3*(j+1)]*AptrD[3*(j)]*Aptr1[3*(j-1)]) == 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } tempBitmap2->PutScanLineN(i-1,(i-1)%3); } progress->Position++; } tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); for(int i = 1; i < height-1 ; i++) { Aptr1 = tempBitmap2->GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0 ; } } tempBitmap2->PutScanLine(i); progress->Position++; } tempBitmap2->StopScanLine(); if(again == 0) break; } while(1 && Cnt >0); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(3); tempBitmap2->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { ptrU = previewBitmap->GetScanLineN( i, i%3); } else if (i==1) { ptr = previewBitmap->GetScanLineN( i, i%3); } else if (i==2) { ptrD = previewBitmap->GetScanLineN( i, i%3); } else { ptrU = tempMidd; ptr = tempDown; ptrD = previewBitmap->GetScanLineN( i, i%3); Aptr1 = tempBitmap2->GetScanLine(i-1); } tempMidd=ptr; tempDown=ptrD; if(i >= 2) { for(int j = 2 ;j < width-2; j++) { if(Aptr1[3*(j)] == 1) { WinCnt = 0; for(int z = j-2 ;z<= j+2; z++) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if(ptrU[3*z] == items_blue && ptrU[3*z+1] == items_green && ptrU[3*z+2] == items_red) WinCnt++; if(ptr[3*z] == items_blue && ptr[3*z+1] == items_green && ptr[3*z+2] == items_red) WinCnt++; if(ptrD[3*z] == items_blue && ptrD[3*z+1] == items_green && ptrD[3*z+2] == items_red) WinCnt++; } if(WinCnt == 15) Aptr1[3*j] = 0; } } tempBitmap2->PutScanLine(i-1); } progress->Position++; } previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(3); tempBitmap->StartScanLineN(3); tempBitmap2->StartScanLineN(3); for(int i = 0; i < height ; i++) { if (i==0) { ptrU = previewBitmap->GetScanLineN( i, i%3); AptrU = tempBitmap2->GetScanLineN( i, i%3); Aptr2U = tempBitmap->GetScanLineN( i, i%3); } else if (i==1) { ptr = previewBitmap->GetScanLineN( i, i%3); Aptr1 = tempBitmap2->GetScanLineN( i, i%3); Aptr2 = tempBitmap->GetScanLineN( i, i%3); } else if (i==2) { ptrD = previewBitmap->GetScanLineN( i, i%3); AptrD = tempBitmap2->GetScanLineN( i, i%3); Aptr2D = tempBitmap->GetScanLineN( i, i%3); } else { ptrU = tempMidd; ptr = tempDown; ptrD = previewBitmap->GetScanLineN( i, i%3); AptrU = tempApMidd; Aptr1 = tempApDown; AptrD = tempBitmap2->GetScanLineN( i, i%3); Aptr2U = tempAp2Midd; Aptr2 = tempAp2Down; Aptr2D = tempBitmap->GetScanLineN( i, i%3); } tempMidd=ptr; tempDown=ptrD; tempApMidd=Aptr1; tempApDown=AptrD; tempAp2Midd=Aptr2; tempAp2Down=Aptr2D; if(i >= 2) { for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*j] == 1) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { TPColor[Va1] = 0; } for(int m = j-1; m <= j+1; m++) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrU[3*m] == items_blue && ptrU[3*m+1] == items_green && ptrU[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptr[3*m] == items_blue && ptr[3*m+1] == items_green && ptr[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrD[3*m] == items_blue && ptrD[3*m+1] == items_green && ptrD[3*m+2] == items_red) TPColor[Va1]++; } MaxCnt = 100000000; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; Dummy = (items_blue - ptr[3*j])*(items_green - ptr[3*j+1])*(items_red - ptr[3*j+2]); if(TPColor[Va1] > 0 && Va1 != Va && Dummy <= MaxCnt ) { MaxCnt = Dummy; SelectColor = Va1; } } MaxCnt = 0; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { if(TPColor[Va1] > 0) { MaxCnt++; } } } if(MaxCnt >= 3) { items_red = (*(TColor*)(ListOfColor->Items[SelectColor])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 16) & 0xFF; Aptr2[3*j] = items_blue; Aptr2[3*j+1] = items_green; Aptr2[3*j+2] = items_red; } } }// for(j) tempBitmap->PutScanLineN(i-1,(i-1)%3); }//if() progress->Position++; } previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); tempBitmap2->StopScanLine(); previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine(i); Aptr1 = tempBitmap->GetScanLine(i); for(int j = 0 ;j < width; j++) { ptr[3*j] = Aptr1[3*j]; ptr[3*j+1] = Aptr1[3*j+1]; ptr[3*j+2] = Aptr1[3*j+2]; } previewBitmap->PutScanLine(i); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); progress->End(); delete tempBitmap; delete tempBitmap2; END_LOG; } //--------------------------------------------------------------------------- int __fastcall nays(Byte *WinColor) { int k,l,N=0; for(k=0;k<3;k++) { for(l=0;l<3;l++) { if(k!=1 || l!=1) { if(WinColor[3*k+l] >=1) N++; } } } return(N); } //----------------------------------------------------------------------------- int __fastcall Connect(Byte *WinColor) { int n=0; if( WinColor[5] >= 1 && WinColor[2] == 0 ) n++; if( WinColor[2] >= 1 && WinColor[1] == 0 ) n++; if( WinColor[1] >= 1 && WinColor[0] == 0 ) n++; if( WinColor[0] >= 1 && WinColor[3] == 0 ) n++; if( WinColor[3] >= 1 && WinColor[6] == 0 ) n++; if( WinColor[6] >= 1 && WinColor[7] == 0 ) n++; if( WinColor[7] >= 1 && WinColor[8] == 0 ) n++; if( WinColor[8] >= 1 && WinColor[5] == 0 ) n++; return(n); } //----------------------------------------------------------------------------- void __fastcall EraseOutLineWA(TUnionBitmap *previewBitmap, TList *ListOfColor, TColor *cp, TPWorkArea *WorkArea) { BEGIN_LOG(""); Byte *ptr,*ptrU, *ptrD,*ptrUU, *ptrDD, *Aptr1,*AptrU,*AptrUU,*AptrD,*AptrDD, *Aptr2, *Aptr2U, *Aptr2D; Byte Neigh[9][3]; int NMean[3]; int SColor[3]; int MiniL; Byte WinColor[9]; unsigned char WinSpace[9]; int TPColor[100]; int MaxCnt; int SelectColor; int Va; int Dummy; int WinCnt; int N,again; bool breakSW; int Cnt, height, width; Byte *tempMidd, *tempDown; Byte *tempApMidd, *tempApDown; Byte *tempAp2Midd, *tempAp2Down; Byte items_red = 0, items_green = 0, items_blue = 0; Byte *pMask; RECT Range = WorkArea->Range; width = Range.right - Range.left; height = Range.bottom - Range.top; TUnionBitmap *tempBitmap = new TUnionBitmap; tempBitmap->Create(previewBitmap->Width, previewBitmap->Height, 24); TUnionBitmap *tempBitmap2 = new TUnionBitmap; tempBitmap2->Create(previewBitmap->Width, previewBitmap->Height, 24); previewBitmap->PartialUndo->RangeSaveUndo(0, 0, previewBitmap->Width, previewBitmap->Height); //by linuxjun //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; Aptr1 = tempBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 0 ;j < width; j++) { if ( pMask[j >> 3] & (0x80 >> (j & 7)) ) { Aptr1[3*j] = ptr[3*j]; Aptr1[3*j+1] = ptr[3*j+1]; Aptr1[3*j+2] = ptr[3*j+2]; } } tempBitmap->PutScanLine( i + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); //------------------------------------------------------------------------- for(int n = 0; nCount;n++) { if( *((TColor *)ListOfColor->Items[n]) == *cp ) Va = n; } //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int y = 0; y < height ; y++) { ptr = previewBitmap->GetScanLine( y + Range.top, Range.left, width) + 3 * Range.left; Aptr2 = tempBitmap2->GetScanLine( y + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(y); for(int x = 0 ;x < width; x++) { if ( pMask[x >> 3] & (0x80 >> (x & 7)) ) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if( ptr[3*(x)]== items_blue && ptr[3*(x)+1]== items_green && ptr[3*(x)+2]== items_red ) { Aptr2[3*x] = 1; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } else { Aptr2[3*x] = 0; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } } } tempBitmap2->PutScanLine( y + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- Cnt = 5; do { Cnt--; again = 0; tempBitmap2->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*j] != 1) continue; //¿µ»óÀÇ Áß¾Ó ºÎºÐÀ» Áß½ÉÀ¸·Î 1ÀÎ ¿µ»óÀÇ °³¼ö °è»ê. WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((Aptr1[3*(j+1)]*AptrU[3*(j)]*Aptr1[3*(j-1)]) == 0 &&(AptrU[3*(j)]*AptrD[3*(j)]*Aptr1[3*(j-1)])== 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } } tempBitmap2->PutScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3); } } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 1; i GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0; } } } tempBitmap2->PutScanLine( i + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); if(again == 0) break; // Second sub-iteration //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)] != 1) continue; WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((AptrU[3*(j)]*Aptr1[3*(j+1)]*AptrD[3*(j)]) == 0 &&(Aptr1[3*(j+1)]*AptrD[3*(j)]*Aptr1[3*(j-1)]) == 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } //¿©±â±îÁö Mask } tempBitmap2->PutScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3); } } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 1; i < height-1 ; i++) { Aptr1 = tempBitmap2->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0 ; } } } tempBitmap2->PutScanLine( i + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); if(again == 0) break; } while(1 && Cnt >0); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(3); tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { ptrU = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { ptr = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { ptrD = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { ptrU = tempMidd; ptr = tempDown; ptrD = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr1 = tempBitmap2->GetScanLine(i-1+ Range.top, Range.left, width) + 3 * Range.left; } tempMidd=ptr; tempDown=ptrD; if(i >= 2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 2 ;j < width-2; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)] == 1) { WinCnt = 0; for(int z = j-2 ;z<= j+2; z++) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if(ptrU[3*z] == items_blue && ptrU[3*z+1] == items_green && ptrU[3*z+2] == items_red) WinCnt++; if(ptr[3*z] == items_blue && ptr[3*z+1] == items_green && ptr[3*z+2] == items_red) WinCnt++; if(ptrD[3*z] == items_blue && ptrD[3*z+1] == items_green && ptrD[3*z+2] == items_red) WinCnt++; } if(WinCnt == 15) Aptr1[3*j] = 0; } } //¿©±â±îÁö Mask } tempBitmap2->PutScanLine( i-1 + Range.top, Range.left, width); } } previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); WorkArea->Mask->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(3); tempBitmap->StartScanLineN(3); tempBitmap2->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { ptrU = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; AptrU = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr2U = tempBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { ptr = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr1 = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr2 = tempBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { ptrD = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr2D = tempBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { ptrU = tempMidd; ptr = tempDown; ptrD = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; AptrU = tempApMidd; Aptr1 = tempApDown; AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr2U = tempAp2Midd; Aptr2 = tempAp2Down; Aptr2D = tempBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } tempMidd=ptr; tempDown=ptrD; tempApMidd=Aptr1; tempApDown=AptrD; tempAp2Midd=Aptr2; tempAp2Down=Aptr2D; if(i >= 2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*j] == 1) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { TPColor[Va1] = 0; } for(int m = j-1; m <= j+1; m++) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrU[3*m] == items_blue && ptrU[3*m+1] == items_green && ptrU[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptr[3*m] == items_blue && ptr[3*m+1] == items_green && ptr[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrD[3*m] == items_blue && ptrD[3*m+1] == items_green && ptrD[3*m+2] == items_red) TPColor[Va1]++; } MaxCnt = 100000000; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; Dummy = (items_blue - ptr[3*j])*(items_green - ptr[3*j+1])*(items_red - ptr[3*j+2]); if(TPColor[Va1] > 0 && Va1 != Va && Dummy <= MaxCnt ) { MaxCnt = Dummy; SelectColor = Va1; } } MaxCnt = 0; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { if(TPColor[Va1] > 0) { MaxCnt++; } } } if(MaxCnt >= 3) { items_red = (*(TColor*)(ListOfColor->Items[SelectColor])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 16) & 0xFF; Aptr2[3*j] = items_blue; Aptr2[3*j+1] = items_green; Aptr2[3*j+2] = items_red; } } }// ¿©±â±îÁö Mask } // for(j) tempBitmap->PutScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3); }//if() } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; Aptr1 = tempBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 0 ;j < width; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { ptr[3*j] = Aptr1[3*j]; ptr[3*j+1] = Aptr1[3*j+1]; ptr[3*j+2] = Aptr1[3*j+2]; } } previewBitmap->PutScanLine( i + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); delete tempBitmap; delete tempBitmap2; END_LOG; } //--------------------------------------------------------------------------- void __fastcall EraseOrganization(TUnionBitmap *previewBitmap, TList *ListOfColor, TStatusProgress *progress) { BEGIN_LOG(""); Byte *ptr,*ptrU, *ptrD,*ptrUU, *ptrDD, *Aptr1,*AptrU,*AptrUU,*AptrD,*AptrDD, *Aptr2, *Aptr2U, *Aptr2D; Byte Neigh[9][3]; int NMean[3]; int SColor[3]; int MiniL; Byte WinColor[9]; unsigned char WinSpace[9]; int TPColor[100]; int MaxCnt; int SelectColor; int Dummy; int WinCnt; int N,again; bool breakSW; int Cnt, height, width; Byte *tempMidd, *tempDown; Byte *tempApMidd, *tempApDown; Byte *tempAp2Midd, *tempAp2Down; Byte items_red = 0, items_green = 0, items_blue = 0; height = previewBitmap->Height; width = previewBitmap->Width; TUnionBitmap *tempBitmap = new TUnionBitmap; tempBitmap->Create(width, height, 24); TUnionBitmap *tempBitmap2 = new TUnionBitmap; tempBitmap2->Create(width, height, 24); previewBitmap->PartialUndo->RangeSaveUndo(0, 0, previewBitmap->Width, previewBitmap->Height); //by linuxjun //------------------------------------------------------------------------- progress->Maximum = height * 5 * ListOfColor->Count; for(int Va = 0; Va< ListOfColor->Count; Va++) { previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine(i); Aptr1 = tempBitmap->GetScanLine(i); for(int j = 0 ;j < width; j++) { Aptr1[3*j] = ptr[3*j]; Aptr1[3*j+1] = ptr[3*j+1]; Aptr1[3*j+2] = ptr[3*j+2]; } tempBitmap->PutScanLine(i); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap2->StartScanLine(); for(int y = 0; y < height ; y++) { ptr = previewBitmap->GetScanLine(y); Aptr2 = tempBitmap2->GetScanLine(y); for(int x = 0 ;x < width; x++) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if( ptr[3*(x)]== items_blue && ptr[3*(x)+1]== items_green && ptr[3*(x)+2]== items_red ) { Aptr2[3*x] = 1; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } else { Aptr2[3*x] = 0; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } } tempBitmap2->PutScanLine(y); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- Cnt = 2; do { Cnt--; again = 0; tempBitmap2->StartScanLineN(3); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i, i%3); } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i, i%3); } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i, i%3); } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i, i%3); } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*j] != 1) continue; //¿µ»óÀÇ Áß¾Ó ºÎºÐÀ» Áß½ÉÀ¸·Î 1ÀÎ ¿µ»óÀÇ °³¼ö °è»ê. WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((Aptr1[3*(j+1)]*AptrU[3*(j)]*Aptr1[3*(j-1)]) == 0 &&(AptrU[3*(j)]*AptrD[3*(j)]*Aptr1[3*(j-1)])== 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } tempBitmap2->PutScanLineN(i-1,(i-1)%3); } } tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); for(int i = 1; i GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0; } } tempBitmap2->PutScanLine(i); } tempBitmap2->StopScanLine(); if(again == 0) break; // Second sub-iteration //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLineN(3); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i, i%3); } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i, i%3); } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i, i%3); } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i, i%3); } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*(j)] != 1) continue; WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((AptrU[3*(j)]*Aptr1[3*(j+1)]*AptrD[3*(j)]) == 0 &&(Aptr1[3*(j+1)]*AptrD[3*(j)]*Aptr1[3*(j-1)]) == 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } tempBitmap2->PutScanLineN(i-1,(i-1)%3); } } tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); for(int i = 1; i < height-1 ; i++) { Aptr1 = tempBitmap2->GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0 ; } } tempBitmap2->PutScanLine(i); } tempBitmap2->StopScanLine(); if(again == 0) break; } while(1 && Cnt >0); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(3); tempBitmap2->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { ptrU = previewBitmap->GetScanLineN( i, i%3); } else if (i==1) { ptr = previewBitmap->GetScanLineN( i, i%3); } else if (i==2) { ptrD = previewBitmap->GetScanLineN( i, i%3); } else { ptrU = tempMidd; ptr = tempDown; ptrD = previewBitmap->GetScanLineN( i, i%3); Aptr1 = tempBitmap2->GetScanLine(i-1); } tempMidd=ptr; tempDown=ptrD; if(i >= 2) { for(int j = 2 ;j < width-2; j++) { if(Aptr1[3*(j)] == 1) { WinCnt = 0; for(int z = j-2 ;z<= j+2; z++) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if(ptrU[3*z] == items_blue && ptrU[3*z+1] == items_green && ptrU[3*z+2] == items_red) WinCnt++; if(ptr[3*z] == items_blue && ptr[3*z+1] == items_green && ptr[3*z+2] == items_red) WinCnt++; if(ptrD[3*z] == items_blue && ptrD[3*z+1] == items_green && ptrD[3*z+2] == items_red) WinCnt++; } if(WinCnt == 15) Aptr1[3*j] = 0; } } tempBitmap2->PutScanLine(i-1); progress->Position++; } } previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(5); tempBitmap->StartScanLineN(3); tempBitmap2->StartScanLineN(3); for(int i = 3; i < height -3; i++) { ptrUU = previewBitmap->GetScanLineN( i-2, (i-2)%5); ptrDD = previewBitmap->GetScanLineN( i+2, (i+2)%5); ptrU = previewBitmap->GetScanLineN( i-1, (i-1)%5); AptrU = tempBitmap2->GetScanLineN( i-1, (i-1)%3); Aptr2U = tempBitmap->GetScanLineN( i-1, (i-1)%3); ptr = previewBitmap->GetScanLineN( (i), (i)%5); Aptr1 = tempBitmap2->GetScanLineN( i, i%3); Aptr2 = tempBitmap->GetScanLineN( (i), (i)%3); ptrD = previewBitmap->GetScanLineN( i+1, (i+1)%5); AptrD = tempBitmap2->GetScanLineN( i+1, (i+1)%3); Aptr2D = tempBitmap->GetScanLineN( i+1, (i+1)%3); for(int j = 3 ;j < width-3; j++) { if(Aptr1[3*j] == 1) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { TPColor[Va1] = 0; } for(int m = j-2; m <= j+2; m++) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrUU[3*m] == items_blue && ptrUU[3*m+1] == items_green && ptrUU[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrU[3*m] == items_blue && ptrU[3*m+1] == items_green && ptrU[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptr[3*m] == items_blue && ptr[3*m+1] == items_green && ptr[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrD[3*m] == items_blue && ptrD[3*m+1] == items_green && ptrD[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrDD[3*m] == items_blue && ptrDD[3*m+1] == items_green && ptrDD[3*m+2] == items_red) TPColor[Va1]++; } } MaxCnt = 0; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { if(TPColor[Va1] >= MaxCnt ) { MaxCnt = TPColor[Va1]; SelectColor = Va1; } } MaxCnt = 0; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { if(TPColor[Va1] > 0) { MaxCnt++; } } if(MaxCnt >= 2) { items_red = (*(TColor*)(ListOfColor->Items[SelectColor])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 16) & 0xFF; Aptr2[3*j] = items_blue; Aptr2[3*j+1] = items_green; Aptr2[3*j+2] = items_red; } } }// for(j) tempBitmap->PutScanLineN(i,(i)%3); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); tempBitmap2->StopScanLine(); previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine(i); Aptr1 = tempBitmap->GetScanLine(i); for(int j = 0 ;j < width; j++) { ptr[3*j] = Aptr1[3*j]; ptr[3*j+1] = Aptr1[3*j+1]; ptr[3*j+2] = Aptr1[3*j+2]; } previewBitmap->PutScanLine(i); progress->Position++; } previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); } progress->End(); delete tempBitmap; delete tempBitmap2; END_LOG; } //--------------------------------------------------------------------------- void __fastcall EraseOrganizationWA(TUnionBitmap *previewBitmap, TList *ListOfColor, TPWorkArea *WorkArea, TStatusProgress *progress) { BEGIN_LOG(""); Byte *ptr,*ptrU, *ptrD,*ptrUU, *ptrDD, *Aptr1,*AptrU,*AptrUU,*AptrD,*AptrDD, *Aptr2, *Aptr2U, *Aptr2D; Byte Neigh[9][3]; int NMean[3]; int SColor[3]; int MiniL; Byte WinColor[9]; unsigned char WinSpace[9]; int TPColor[100]; int MaxCnt; int SelectColor; int Dummy; int WinCnt; int N,again; bool breakSW; int Cnt, height, width; Byte *tempMidd, *tempDown; Byte *tempApMidd, *tempApDown; Byte *tempAp2Midd, *tempAp2Down; Byte items_red = 0, items_green = 0, items_blue = 0; Byte *pMask; RECT Range = WorkArea->Range; width = Range.right - Range.left; height = Range.bottom - Range.top; TUnionBitmap *tempBitmap = new TUnionBitmap; tempBitmap->Create(previewBitmap->Width, previewBitmap->Height, 24); TUnionBitmap *tempBitmap2 = new TUnionBitmap; tempBitmap2->Create(previewBitmap->Width, previewBitmap->Height, 24); previewBitmap->PartialUndo->RangeSaveUndo(0, 0, previewBitmap->Width, previewBitmap->Height); //by linuxjun progress->Maximum = height * 5 * ListOfColor->Count; //------------------------------------------------------------------------- for(int Va = 0; Va< ListOfColor->Count; Va++) { previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; Aptr1 = tempBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 0 ;j < width; j++) { if ( pMask[j >> 3] & (0x80 >> (j & 7)) ) { Aptr1[3*j] = ptr[3*j]; Aptr1[3*j+1] = ptr[3*j+1]; Aptr1[3*j+2] = ptr[3*j+2]; } } tempBitmap->PutScanLine( i + Range.top, Range.left, width); progress->Position++; } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int y = 0; y < height ; y++) { ptr = previewBitmap->GetScanLine( y + Range.top, Range.left, width) + 3 * Range.left; Aptr2 = tempBitmap2->GetScanLine( y + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(y); for(int x = 0 ;x < width; x++) { if ( pMask[x >> 3] & (0x80 >> (x & 7)) ) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if( ptr[3*(x)]== items_blue && ptr[3*(x)+1]== items_green && ptr[3*(x)+2]== items_red ) { Aptr2[3*x] = 1; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } else { Aptr2[3*x] = 0; Aptr2[3*x+1] = 0; Aptr2[3*x+2] = 0; } } //¿©±â±îÁö Mask } tempBitmap2->PutScanLine( y + Range.top, Range.left, width); progress->Position++; } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- Cnt = 2; do { Cnt--; again = 0; tempBitmap2->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*j] != 1) continue; //¿µ»óÀÇ Áß¾Ó ºÎºÐÀ» Áß½ÉÀ¸·Î 1ÀÎ ¿µ»óÀÇ °³¼ö °è»ê. WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((Aptr1[3*(j+1)]*AptrU[3*(j)]*Aptr1[3*(j-1)]) == 0 &&(AptrU[3*(j)]*AptrD[3*(j)]*Aptr1[3*(j-1)])== 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } } //¿©±â±îÁö Mask tempBitmap2->PutScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3); } } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 1; i GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0; } } } tempBitmap2->PutScanLine( i + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); if(again == 0) break; // Second sub-iteration //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { AptrU = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { Aptr1 = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { AptrU = tempMidd; Aptr1 = tempDown; AptrD = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } tempMidd=Aptr1; tempDown=AptrD; if(i >=2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)] != 1) continue; WinColor[0] = AptrU[3*(j-1)]; WinColor[1] = AptrU[3*(j)]; WinColor[2] = AptrU[3*(j+1)]; WinColor[3] = Aptr1[3*(j-1)]; WinColor[4] = Aptr1[3*(j)]; WinColor[5] = Aptr1[3*(j+1)]; WinColor[6] = AptrD[3*(j-1)]; WinColor[7] = AptrD[3*(j)]; WinColor[8] = AptrD[3*(j+1)]; N = nays(WinColor); if((N>=2 && N<=6) && Connect(WinColor) == 1) { if((AptrU[3*(j)]*Aptr1[3*(j+1)]*AptrD[3*(j)]) == 0 &&(Aptr1[3*(j+1)]*AptrD[3*(j)]*Aptr1[3*(j-1)]) == 0) { Aptr1[3*(j)+1] = 1; again = 1; } } } } //¿©±â±îÁö Mask tempBitmap2->PutScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3); } } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); //////////////////////////////////////////////////////////////////////// tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 1; i < height-1 ; i++) { Aptr1 = tempBitmap2->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 1 ;j < width-1; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)+1]) { Aptr1[3*(j)] = 0; Aptr1[3*(j)+1] = 0 ; } } } tempBitmap2->PutScanLine( i + Range.top, Range.left, width); } WorkArea->Mask->StopScanLine(); tempBitmap2->StopScanLine(); if(again == 0) break; } while(1 && Cnt >0); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(3); tempBitmap2->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { if (i==0) { ptrU = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==1) { ptr = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else if (i==2) { ptrD = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; } else { ptrU = tempMidd; ptr = tempDown; ptrD = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr1 = tempBitmap2->GetScanLine( i-1 + Range.top, Range.left, width) + 3 * Range.left; } tempMidd=ptr; tempDown=ptrD; if(i >= 2) { pMask = WorkArea->Mask->GetScanLine(i-1); for(int j = 2 ;j < width-2; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*(j)] == 1) { WinCnt = 0; for(int z = j-2 ;z<= j+2; z++) { items_red = (*(TColor*)(ListOfColor->Items[Va])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va])) >> 16) & 0xFF; if(ptrU[3*z] == items_blue && ptrU[3*z+1] == items_green && ptrU[3*z+2] == items_red) WinCnt++; if(ptr[3*z] == items_blue && ptr[3*z+1] == items_green && ptr[3*z+2] == items_red) WinCnt++; if(ptrD[3*z] == items_blue && ptrD[3*z+1] == items_green && ptrD[3*z+2] == items_red) WinCnt++; } if(WinCnt == 15) Aptr1[3*j] = 0; } } //¿©±â±îÁö Mask } tempBitmap2->PutScanLine( i-1 + Range.top, Range.left, width); } progress->Position++; } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLineN(5); tempBitmap->StartScanLineN(3); tempBitmap2->StartScanLineN(3); WorkArea->Mask->StartScanLine(); for(int i = 3; i < height -3; i++) { ptrUU = previewBitmap->GetScanLineN( i-2 + Range.top, Range.left, width, (i-2)%5) + 3 * Range.left; ptrDD = previewBitmap->GetScanLineN( i+2 + Range.top, Range.left, width, (i+2)%5) + 3 * Range.left; ptrU = previewBitmap->GetScanLineN( i-1 + Range.top, Range.left, width, (i-1)%5) + 3 * Range.left; AptrU = tempBitmap2->GetScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3) + 3 * Range.left; Aptr2U = tempBitmap->GetScanLineN( i-1 + Range.top, Range.left, width, (i-1)%3) + 3 * Range.left; ptr = previewBitmap->GetScanLineN( i + Range.top, Range.left, width, i%5) + 3 * Range.left; Aptr1 = tempBitmap2->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; Aptr2 = tempBitmap->GetScanLineN( i + Range.top, Range.left, width, i%3) + 3 * Range.left; ptrD = previewBitmap->GetScanLineN( i+1 + Range.top, Range.left, width, (i+1)%5) + 3 * Range.left; AptrD = tempBitmap2->GetScanLineN( i+1 + Range.top, Range.left, width, (i+1)%3) + 3 * Range.left; Aptr2D = tempBitmap->GetScanLineN( i+1 + Range.top, Range.left, width, (i+1)%3) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 3 ;j < width-3; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { if(Aptr1[3*j] == 1) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { TPColor[Va1] = 0; } for(int m = j-2; m <= j+2; m++) { for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrUU[3*m] == items_blue && ptrUU[3*m+1] == items_green && ptrUU[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrU[3*m] == items_blue && ptrU[3*m+1] == items_green && ptrU[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptr[3*m] == items_blue && ptr[3*m+1] == items_green && ptr[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrD[3*m] == items_blue && ptrD[3*m+1] == items_green && ptrD[3*m+2] == items_red) TPColor[Va1]++; } for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { items_red = (*(TColor*)(ListOfColor->Items[Va1])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[Va1])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[Va1])) >> 16) & 0xFF; if(ptrDD[3*m] == items_blue && ptrDD[3*m+1] == items_green && ptrDD[3*m+2] == items_red) TPColor[Va1]++; } } MaxCnt = 0; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { if(TPColor[Va1] >= MaxCnt ) { MaxCnt = TPColor[Va1]; SelectColor = Va1; } } MaxCnt = 0; for(int Va1 = 0; Va1 < ListOfColor->Count; Va1++) { if(TPColor[Va1] > 0) { MaxCnt++; } } if(MaxCnt >= 2) { items_red = (*(TColor*)(ListOfColor->Items[SelectColor])) & 0xFF; items_green = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 8) & 0xFF; items_blue = (*((TColor*)(ListOfColor->Items[SelectColor])) >> 16) & 0xFF; Aptr2[3*j] = items_blue; Aptr2[3*j+1] = items_green; Aptr2[3*j+2] = items_red; } } } //¿©±â±îÁö Mask } // for(j) tempBitmap->PutScanLineN( i + Range.top, Range.left, width, i%3); progress->Position++; } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); tempBitmap2->StopScanLine(); //------------------------------------------------------------------------- previewBitmap->StartScanLine(); tempBitmap->StartScanLine(); WorkArea->Mask->StartScanLine(); for(int i = 0; i < height ; i++) { ptr = previewBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; Aptr1 = tempBitmap->GetScanLine( i + Range.top, Range.left, width) + 3 * Range.left; pMask = WorkArea->Mask->GetScanLine(i); for(int j = 0 ;j < width; j++) { if (pMask[j >> 3] & (0x80 >> (j & 7))) // x>>3 == x/8, x&7={0,1,2,3,4,5,6,7} { ptr[3*j] = Aptr1[3*j]; ptr[3*j+1] = Aptr1[3*j+1]; ptr[3*j+2] = Aptr1[3*j+2]; } } previewBitmap->PutScanLine( i + Range.top, Range.left, width); progress->Position++; } WorkArea->Mask->StopScanLine(); previewBitmap->StopScanLine(); tempBitmap->StopScanLine(); } progress->End(); delete tempBitmap; delete tempBitmap2; END_LOG; } //--------------------------------------------------------------------------- void __fastcall de_allocate(unsigned short **data, int height) { for (int i = 0; i < height; i++) delete[] data[i]; // STEP 1: DELETE THE COLUMNS delete[] data; // STEP 2: DELETE THE ROWS } //--------------------------------------------------------------------------- void __fastcall de_allist(unsigned short **chColorIndex, int LabelNum) { for (int i = 0; i < LabelNum; i++) delete[] chColorIndex[i]; // STEP 1: DELETE THE COLUMNS delete[] chColorIndex; // STEP 2: DELETE THE ROWS } //---------------------------------------------------------------------------