//--------------------------------------------------------------------------- #pragma hdrstop #include #include "Kasuri.h" #include "MainImage.h"//for Repaint() #include "Palette.h" #include "LogData.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "gdiplus.lib" //--------------------------------------------------------------------------- __fastcall TKasuri::TKasuri() { BEGIN_LOG(""); pointCount = 0; branchCount = 0; twigCount = 0; allBranchCount = 0; oldBranchCount = 0; nowCount = 0; dDist = 0.2; KPointList = new TList; AllPoints = NULL; CrayonBitmap = NULL; PenBitmap = NULL; PenMask = NULL; //tempBitmap = NULL; KasuriPenPoints = NULL; EditPenPoints = NULL; EditPenPointCount = 0; isNormalPen = true; bPointCalEnd = false; bMove = false; //shin 061024 gdp::GdiplusStartup(&gdp_token_, &gdp::GdiplusStartupInput(), NULL); END_LOG; } //--------------------------------------------------------------------------- __fastcall TKasuri::~TKasuri() { BEGIN_LOG(""); if (AllPoints){ for (int i = 0; i < allBranchCount; i++){ delete[] AllPoints[i]; AllPoints[i] = NULL; } delete[] AllPoints; AllPoints = NULL; } while(KPointList->Count > 0){ TPoint *point = (TPoint *)KPointList->Last(); KPointList->Remove(point); delete point; } KPointList = NULL; if (CrayonBitmap) delete CrayonBitmap; if (PenBitmap) delete PenBitmap; if (PenMask) delete PenMask; //if (tempBitmap) delete tempBitmap; gdp::GdiplusShutdown(gdp_token_); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::CalculatePoints() { BEGIN_LOG(""); if (branchCount > 1 && KPointList->Count > 0){ TPoint *point; TList *BranchPointList = new TList; if (AllPoints){ for (int i = 0; i < oldBranchCount; i++){ delete[] AllPoints[i]; AllPoints[i] = NULL; } delete[] AllPoints; AllPoints = NULL; } oldBranchCount = allBranchCount; AllPoints = new TPoint*[allBranchCount]; for (int i = 0; i < allBranchCount; i++){ AllPoints[i] = new TPoint[pointCount]; } // branch¸ÕÀú ³Ö±â. int count = 0; for (int y = 0; y < allBranchCount; y += (twigCount+1)){ for (int x = 0; x < pointCount; x++){ point = (TPoint *)KPointList->Items[count]; AllPoints[y][x].x = point->x; AllPoints[y][x].y = point->y; count++; } } for (int i = 0; i < branchCount - 1; i++){ CalculateSegment(i); } } if (!isNormalPen) ChangeCrayonPen(); bPointCalEnd = true; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::MakeSameOrderBranchPointList(int nOrder, TList *BranchPointList) { BEGIN_LOG(""); TPoint *point; int count = 0; if (KPointList && KPointList->Count == pointCount*branchCount){ for (int i = nOrder; i < KPointList->Count; i += pointCount){ point = (TPoint *)KPointList->Items[i]; TPoint *branchPoint = new TPoint; branchPoint->x = point->x; branchPoint->y = point->y; BranchPointList->Add(branchPoint); count++; } } END_LOG; } //--------------------------------------------------------------------------- /* void __fastcall TKasuri::CalculatePositions(TList *branchPointList, TPoint *twigPoints) { int sx = 0, mx = 0, ex = 0, sy = 0, my = 0, ey = 0; int Lsx, Lex, Lsy, Ley; int Count = 0; double d1 = 0.0, d2 = 0.0, d3 = 0.0, a = 0.0, b = 0.0; double ct = 0.0, st = 0.0, ss = 0.0, theta = 0.0, alpha = 0.0; double txs = 0.0, tys = 0.0, txe = 0.0, tye = 0.0, x = 0.0, y = 0.0, pw = 0.0, count = 0.0; TPoint *pointS, *pointC, *pointE; for (int i = 0; i < branchPointList->Count - 1; i++){ pointS = (TPoint *)branchPointList->Items[i]; pointE = (TPoint *)branchPointList->Items[i + 1]; TPoint *pointC = new TPoint; GetMiddlePoint(pointS, pointE, pointC, i, dDist); sx = pointS->x; sy = pointS->y; mx = pointC->x; my = pointC->y; ex = pointE->x; ey = pointE->y; if (pointC) delete pointC; d1 = sqrt((double)(sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((double)(ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((double)(ex - sx) * (ex - sx) + (ey - sy) * (ey - sy)); if (d1 > d2) { a = d1; b = d2; } else { a = d2; b = d1; } if ((a > b * 1.8) && (d3 < a)) { d1 = sqrt(d1); d2 = sqrt(d2); } txs = (ex * d1 + sx * d2) / (d1 + d2); tys = (ey * d1 + sy * d2) / (d1 + d2); if (txs == mx) ss = tys - my; else ss = (double)(tys - my) / (txs - mx); theta = M_PI / 2.0 - atan(ss); ct = cos(theta); st = sin(theta); txs = ct * (sx - mx) - st * (sy - my); tys = st * (sx - mx) + ct * (sy - my); txe = ct * (ex - mx) - st * (ey - my); tye = st * (ex - mx) + ct * (ey - my); //count = (abs(txs) + abs(txe))/(twigCount+1) + 1; alpha = tys / (txs * txs); if (twigCount%2){ count = abs(txs)/(twigCount/2 + 1); } else { count = abs(txs)/(twigCount + 1); } if (count == 0){ count = 1; } Lsx = mx; Lsy = my; int tempcount = 0; if (txs < 0) { x = 0; bool first = true; //tempcount = (twigCount+1)/2 - 1; tempcount = twigCount/2 - 1; while (x >= txs) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if ((Lex != sx || Ley != sy) && (Lex != mx || Ley != my)){ twigPoints[i*twigCount+tempcount].x = Lex; twigPoints[i*twigCount+tempcount].y = Ley; tempcount--; } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x - count; first = false; } else { x = x - count*2; } if (tempcount < 0) break; } if (tempcount >= 0){ for (int j = tempcount; j >= 0; j--){ twigPoints[i*twigCount+j].x = Lex; twigPoints[i*twigCount+j].y = Ley; } } } else { x = 0; //tempcount = (twigCount+1)/2 - 1; tempcount = twigCount/2 - 1; bool first = true; while (x <= txs) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if ((Lex != sx || Ley != sy) && (Lex != mx || Ley != my)){ twigPoints[i*twigCount+tempcount].x = Lex; twigPoints[i*twigCount+tempcount].y = Ley; tempcount--; } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x + count; first = false; } else { x = x + count*2; } if (tempcount < 0) break; } if (tempcount >= 0){ for (int j = tempcount; j >= 0; j--){ twigPoints[i*twigCount+j].x = Lex; twigPoints[i*twigCount+j].y = Ley; } } } ////////////////////////////////////// alpha = tye / (txe * txe); if (twigCount%2){ count = abs(txe)/(twigCount/2 + 1); } else { count = abs(txe)/(twigCount + 1); } if (count == 0){ count = 1; } Lsx = mx; Lsy = my; tempcount = 0; if (txe < 0) { x = 0; //tempcount = (twigCount+1)/2; tempcount = twigCount/2; bool first = true; while (x >= txe) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if (Lex != sx || Ley != sy){ if (twigCount%2){ twigPoints[i*twigCount+tempcount].x = Lex; twigPoints[i*twigCount+tempcount].y = Ley; tempcount++; } else { if (Lex != mx || Ley != my){ twigPoints[i*twigCount+tempcount].x = Lex; twigPoints[i*twigCount+tempcount].y = Ley; tempcount++; } } } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x - count; first = false; } else { x = x - count*2; } if (tempcount >= twigCount) break; } if (tempcount < twigCount){ for (int j = 0; j < twigCount - tempcount; j++){ twigPoints[i*twigCount+j].x = Lex; twigPoints[i*twigCount+j].y = Ley; } } } else { x = 0; //tempcount = (twigCount+1)/2; tempcount = twigCount/2; bool first = true; while (x <= txe) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if (Lex != sx || Ley != sy){ if (twigCount%2){ twigPoints[i*twigCount+tempcount].x = Lex; twigPoints[i*twigCount+tempcount].y = Ley; tempcount++; } else { if (Lex != mx || Ley != my){ twigPoints[i*twigCount+tempcount].x = Lex; twigPoints[i*twigCount+tempcount].y = Ley; tempcount++; } } } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x + count; first = false; } else { x = x + count*2; } if (tempcount >= twigCount) break; } if (tempcount < twigCount){ for (int j = 0; j < twigCount - tempcount; j++){ twigPoints[i*twigCount+j].x = Lex; twigPoints[i*twigCount+j].y = Ley; } } } } } */ //--------------------------------------------------------------------------- /* void __fastcall TKasuri::AddTwigPoints(int nOrder, TPoint *twigPoints) { TPoint *point; int count = 0; for (int i = 0; i < allBranchCount; i++){ if ((i % (twigCount + 1)) != 0){ AllPoints[i][nOrder].x = twigPoints[count].x; AllPoints[i][nOrder].y = twigPoints[count].y; count++; if (count >= twigCount*(branchCount-1)) return; } } } */ //--------------------------------------------------------------------------- void __fastcall TKasuri::FindBranchPoints(int nBranchNum, int nOrder, TPoint *pS, TPoint *pE) { BEGIN_LOG(""); TPoint *pointS, *pointE; int count = 0; pointS = (TPoint *)KPointList->Items[pointCount*nBranchNum + nOrder]; pointE = (TPoint *)KPointList->Items[pointCount*(nBranchNum + 1) + nOrder]; pS->x = pointS->x; pS->y = pointS->y; pE->x = pointE->x; pE->y = pointE->y; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::CalculateSegmentTwigPositions(int nBranchNum, TPoint *pointS, TPoint *pointE, TPoint *twigPoints) { BEGIN_LOG(""); int sx = 0, mx = 0, ex = 0, sy = 0, my = 0, ey = 0; int Lsx, Lex, Lsy, Ley; int Count = 0; double d1 = 0.0, d2 = 0.0, d3 = 0.0, a = 0.0, b = 0.0; double ct = 0.0, st = 0.0, ss = 0.0, theta = 0.0, alpha = 0.0; double txs = 0.0, tys = 0.0, txe = 0.0, tye = 0.0, x = 0.0, y = 0.0, pw = 0.0, count = 0.0; TPoint *pointC; pointC = new TPoint; GetMiddlePoint(pointS, pointE, pointC, nBranchNum, dDist); sx = pointS->x; sy = pointS->y; mx = pointC->x; my = pointC->y; ex = pointE->x; ey = pointE->y; if (pointC) delete pointC; d1 = sqrt((double)(sx - mx) * (sx - mx) + (sy - my) * (sy - my)); d2 = sqrt((double)(ex - mx) * (ex - mx) + (ey - my) * (ey - my)); d3 = sqrt((double)(ex - sx) * (ex - sx) + (ey - sy) * (ey - sy)); if (d1 > d2) { a = d1; b = d2; } else { a = d2; b = d1; } if ((a > b * 1.8) && (d3 < a)) { d1 = sqrt(d1); d2 = sqrt(d2); } txs = (ex * d1 + sx * d2) / (d1 + d2); tys = (ey * d1 + sy * d2) / (d1 + d2); if (txs == mx) ss = tys - my; else ss = (double)(tys - my) / (txs - mx); theta = M_PI / 2.0 - atan(ss); ct = cos(theta); st = sin(theta); txs = ct * (sx - mx) - st * (sy - my); tys = st * (sx - mx) + ct * (sy - my); txe = ct * (ex - mx) - st * (ey - my); tye = st * (ex - mx) + ct * (ey - my); alpha = tys / (txs * txs); if (twigCount%2){ count = abs(txs)/(twigCount/2 + 1); } else { count = abs(txs)/(twigCount + 1); } if (count == 0){ count = 1; } Lsx = mx; Lsy = my; int tempcount = 0; if (txs < 0) { x = 0; bool first = true; tempcount = twigCount/2 - 1; while (x >= txs) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if ((Lex != sx || Ley != sy) && (Lex != mx || Ley != my)){ twigPoints[tempcount].x = Lex; twigPoints[tempcount].y = Ley; tempcount--; } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x - count; first = false; } else { x = x - count*2; } if (tempcount < 0) break; } if (tempcount >= 0){ for (int j = tempcount; j >= 0; j--){ twigPoints[j].x = Lex; twigPoints[j].y = Ley; } } } else { x = 0; tempcount = twigCount/2 - 1; bool first = true; while (x <= txs) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if ((Lex != sx || Ley != sy) && (Lex != mx || Ley != my)){ twigPoints[tempcount].x = Lex; twigPoints[tempcount].y = Ley; tempcount--; } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x + count; first = false; } else { x = x + count*2; } if (tempcount < 0) break; } if (tempcount >= 0){ for (int j = tempcount; j >= 0; j--){ twigPoints[j].x = Lex; twigPoints[j].y = Ley; } } } ////////////////////////////////////// alpha = tye / (txe * txe); if (twigCount%2){ count = abs(txe)/(twigCount/2 + 1); } else { count = abs(txe)/(twigCount + 1); } if (count == 0){ count = 1; } Lsx = mx; Lsy = my; tempcount = 0; if (txe < 0) { x = 0; tempcount = twigCount/2; bool first = true; while (x >= txe) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if (Lex != sx || Ley != sy){ if (twigCount%2){ twigPoints[tempcount].x = Lex; twigPoints[tempcount].y = Ley; tempcount++; } else { if (Lex != mx || Ley != my){ twigPoints[tempcount].x = Lex; twigPoints[tempcount].y = Ley; tempcount++; } } } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x - count; first = false; } else { x = x - count*2; } if (tempcount >= twigCount) break; } if (tempcount < twigCount){ for (int j = 0; j < twigCount - tempcount; j++){ twigPoints[j].x = Lex; twigPoints[j].y = Ley; } } } else { x = 0; tempcount = twigCount/2; bool first = true; while (x <= txe) { y = alpha * (x * x); Lex = ct * x + st * y + mx; Ley = ct * y - st * x + my; if (Lex != sx || Ley != sy){ if (twigCount%2){ twigPoints[tempcount].x = Lex; twigPoints[tempcount].y = Ley; tempcount++; } else { if (Lex != mx || Ley != my){ twigPoints[tempcount].x = Lex; twigPoints[tempcount].y = Ley; tempcount++; } } } Lsx = Lex; Lsy = Ley; if (first || twigCount%2){ x = x + count; first = false; } else { x = x + count*2; } if (tempcount >= twigCount) break; } if (tempcount < twigCount){ for (int j = 0; j < twigCount - tempcount; j++){ twigPoints[j].x = Lex; twigPoints[j].y = Ley; } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::AddSegmentTwigPoints(int nBranchNum, int nOrder, TPoint *twigPoints) { BEGIN_LOG(""); for (int i = 0; i < twigCount; i++){ AllPoints[nBranchNum*(twigCount+1)+i+1][nOrder].x = twigPoints[i].x; AllPoints[nBranchNum*(twigCount+1)+i+1][nOrder].y = twigPoints[i].y; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::DrawKasuri(HDC dcDst, int zoomIn, int zoomOut, int xPoz, int yPoz, int px, int py, int bpp, bool isMask, COLORREF bgColor, RGBQUAD *rgb) { BEGIN_LOG(""); if (isNormalPen || bMove){ //shin 061024 DrawNormalPen(dcDst, zoomIn, zoomOut, xPoz, yPoz, px, py, isMask); } else { DrawCrayonPen(dcDst, zoomIn, zoomOut, xPoz, yPoz, px, py, bpp, bgColor, rgb, isMask); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::DrawNormalPen(HDC dcDst, int zoomIn, int zoomOut, int xPoz, int yPoz, int px, int py, bool isMask) { BEGIN_LOG(""); kZoomIn = zoomIn; kZoomOut = zoomOut; gdp::Graphics graphics(dcDst); //graphics.SetSmoothingMode(gdp::SmoothingModeHighQuality); gdp::Color penColor; if (!isMask){ penColor.SetValue(gdp::Color::MakeARGB(255, KPenColor.rgbRed, KPenColor.rgbGreen, KPenColor.rgbBlue)); } else{ penColor.SetValue(gdp::Color::MakeARGB(255, 0, 0, 0)); } gdp::SolidBrush penBrush(penColor); gdp::GraphicsPath penPath; penPath.SetFillMode(gdp::FillModeWinding); gdp::Point *pPoints; gdp::Point *pPenPoints; pPoints = new gdp::Point[pointCount]; pPenPoints = new gdp::Point[4*pointCount]; int count; gdp::PointF *OutLineUpPoints, *OutLineDownPoints; if (branchCount > 1){ for (int y = 0; y < allBranchCount; y++){ for (int x = 0; x < pointCount; x++){ pPoints[x].X = (AllPoints[y][x].x - xPoz)*zoomIn/zoomOut - px; pPoints[x].Y = (AllPoints[y][x].y - yPoz)*zoomIn/zoomOut - py; } OutLineUpPoints = new gdp::PointF[(pointCount - 1)*20]; OutLineDownPoints = new gdp::PointF[(pointCount - 1)*20]; count = 0; GetPathOutLine(pPoints, OutLineUpPoints, OutLineDownPoints, (pointCount - 1)*20, count); penPath.AddLines(OutLineUpPoints, count); penPath.AddLines(OutLineDownPoints, count); penPath.AddLine(OutLineDownPoints[count-1].X, OutLineDownPoints[count-1].Y, AllPoints[0][0].x, AllPoints[0][0].y); //graphics.DrawPath(&penRed, &penPath); graphics.FillPath(&penBrush, &penPath); //graphics.DrawCurve(&pen, pPoints, pointCount); delete[] OutLineUpPoints; OutLineUpPoints = NULL; delete[] OutLineDownPoints; OutLineDownPoints = NULL; } } else { TPoint *point; for (int i = 0; i < KPointList->Count; i++){ point = (TPoint *)KPointList->Items[i]; pPoints[i].X = (point->x - xPoz)*zoomIn/zoomOut - px; pPoints[i].Y = (point->y - yPoz)*zoomIn/zoomOut - py; } OutLineUpPoints = new gdp::PointF[(pointCount - 1)*20]; OutLineDownPoints = new gdp::PointF[(pointCount - 1)*20]; count = 0; GetPathOutLine(pPoints, OutLineUpPoints, OutLineDownPoints, (pointCount - 1)*20, count); penPath.AddLines(OutLineUpPoints, count); penPath.AddLines(OutLineDownPoints, count); //graphics.DrawPath(&penRed, &penPath); graphics.FillPath(&penBrush, &penPath); delete[] OutLineUpPoints; OutLineUpPoints = NULL; delete[] OutLineDownPoints; OutLineDownPoints = NULL; } delete[] pPoints; delete[] pPenPoints; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::DrawCrayonPen(HDC dcDst, int zoomIn, int zoomOut, int xPoz, int yPoz, int px, int py, int bpp, COLORREF bgColor, RGBQUAD *rgb, bool isMask) { BEGIN_LOG(""); if (!PenBitmap) ChangeCrayonPen(); //shin 061024 HDC dcTemp, dcMask, dcBitmap; //if (tempBitmap) delete tempBitmap; TTexpiaBitmap *tempBitmap; //shin 070302 tempBitmap = new TTexpiaBitmap; tempBitmap->Create(PenBitmap->Width*zoomIn/zoomOut, PenBitmap->Height*zoomIn/zoomOut, bpp, rgb); if (bpp == 24){ tempBitmap->FillRect(Rect(0, 0, tempBitmap->Width, tempBitmap->Height), bgColor); } else if (bpp == 8){ tempBitmap->StartScanLine(); BYTE *DstM; for (int y = 0; y < tempBitmap->Height; y++){ DstM = tempBitmap->GetScanLine(y); memset(DstM, 0xFF, tempBitmap->Width); tempBitmap->PutScanLine(y); } tempBitmap->StopScanLine(); } else { tempBitmap->StartScanLine(); BYTE *DstM; for (int y = 0; y < tempBitmap->Height; y++){ DstM = tempBitmap->GetScanLine(y); memset(DstM, 0xFF, (tempBitmap->Width+7)/8); tempBitmap->PutScanLine(y); } tempBitmap->StopScanLine(); } if (!isMask){ dcBitmap = PenBitmap->CreateDC(); dcMask = PenMask->CreateDC(); dcTemp = tempBitmap->CreateDC(); StretchBlt(dcDst, (double)(KRect.left-xPoz)*zoomIn/zoomOut - px, (double)(KRect.top-yPoz)*zoomIn/zoomOut - py, (double)(KRect.right - KRect.left)*zoomIn/zoomOut, (double)(KRect.bottom - KRect.top)*zoomIn/zoomOut, dcMask, 0, 0, PenMask->Width, PenMask->Height, SRCAND); StretchBlt(dcTemp, 0, 0, (double)PenBitmap->Width*zoomIn/zoomOut, (double)PenBitmap->Height*zoomIn/zoomOut, dcMask, 0, 0, PenMask->Width, PenMask->Height, NOTSRCCOPY); StretchBlt(dcTemp, 0, 0, (double)PenBitmap->Width*zoomIn/zoomOut, (double)PenBitmap->Height*zoomIn/zoomOut, dcBitmap, 0, 0, PenBitmap->Width, PenBitmap->Height, SRCAND); StretchBlt(dcDst, (double)(KRect.left-xPoz)*zoomIn/zoomOut - px, (double)(KRect.top-yPoz)*zoomIn/zoomOut - py, (double)(KRect.right - KRect.left)*zoomIn/zoomOut, (double)(KRect.bottom - KRect.top)*zoomIn/zoomOut, dcTemp, 0, 0, tempBitmap->Width, tempBitmap->Height, SRCPAINT); PenBitmap->DeleteDC(dcBitmap); PenMask->DeleteDC(dcMask); tempBitmap->DeleteDC(dcTemp); } else{ dcMask = PenMask->CreateDC(); StretchBlt(dcDst, (double)(KRect.left-xPoz)*zoomIn/zoomOut - px, (double)(KRect.top-yPoz)*zoomIn/zoomOut - py, (double)(KRect.right - KRect.left)*zoomIn/zoomOut, (double)(KRect.bottom - KRect.top)*zoomIn/zoomOut, dcMask, 0, 0, PenMask->Width, PenMask->Height, SRCAND); PenMask->DeleteDC(dcMask); } delete tempBitmap; //shin 070302 END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::GetMiddlePoint(TPoint *pointS, TPoint *pointE, TPoint *pMiddle, int nNum, double dBend) { BEGIN_LOG(""); double m = dBend*10; double n = (1 - dBend)*10; int startx = 0, starty = 0; int tempx = 0, tempy = 0; startx = (AllPoints[nNum][0].x + AllPoints[nNum + 1][0].x)/2; starty = (AllPoints[nNum][0].y + AllPoints[nNum + 1][0].y)/2; tempx = (pointS->x + pointE->x)/2; tempy = (pointS->y + pointE->y)/2; if (m == 0){ pMiddle->x = tempx; pMiddle->y = tempy; } else { pMiddle->x = (tempx * n + startx * m)/(m + n); pMiddle->y = (tempy * n + starty * m)/(m + n); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::DrawEditLine(HDC dcDst, int zoomIn, int zoomOut, int xPoz, int yPoz, int px, int py) { BEGIN_LOG(""); gdp::Graphics graphics(dcDst); gdp::Point *pPoints; gdp::Color penColor(0, 0, 255); gdp::Color redPenColor(255, 0, 0); gdp::Pen pen(penColor, 1); gdp::Pen penBold(penColor, 2); gdp::Pen penRed(redPenColor, 1); gdp::Pen penRedBold(redPenColor, 2); pPoints = new gdp::Point[pointCount]; TPoint *point, *point2; if (branchCount > 1){ for(int i = 0; i < KPointList->Count; i++) { point = (TPoint *)KPointList->Items[i]; if (i > 0 && ((i+1)%pointCount == 0)){ for(int j = 0; j < pointCount ; j++){ TPoint *temp = (TPoint *)KPointList->Items[i - (pointCount-1) + j]; pPoints[j].X =(temp->x - xPoz) * zoomIn / zoomOut - px; pPoints[j].Y =(temp->y - yPoz) * zoomIn / zoomOut - py; } graphics.DrawCurve(&pen, pPoints, pointCount); } int tempx = (point->x - xPoz) * zoomIn / zoomOut - px; int tempy = (point->y - yPoz) * zoomIn / zoomOut - py; //if(tempx - 3 <= MainImageForm->nKasuriXPosition && MainImageForm->nKasuriXPosition <= tempx + 3 && tempy - 3 <= MainImageForm->nKasuriYPosition && MainImageForm->nKasuriYPosition <= tempy + 3) pen.SetColor(redPenColor); //by bomchun (06.10.13) //else pen.SetColor(penColor); //graphics.DrawRectangle(&pen, tempx - 3, tempy - 3, 6, 6); //pen.SetColor(penColor);///* if (MovePointIndex != -1 && MovePointIndex == i){ //061014 if (i % pointCount == 0){ //shin 061024 graphics.DrawRectangle(&penRedBold, tempx - 3, tempy - 3, 6, 6); } else { graphics.DrawRectangle(&penRed, tempx - 3, tempy - 3, 6, 6); } } else { if (i % pointCount == 0){ //shin 061024 graphics.DrawRectangle(&penBold, tempx - 3, tempy - 3, 6, 6); } else { graphics.DrawRectangle(&pen, tempx - 3, tempy - 3, 6, 6); } } //*/ } } else { // ¶óÀÎ ±×¸®°í ÆíÁýÁ¡ Ç¥½Ã if (KPointList->Count > pointCount){ for(int i = 0; i < pointCount ; i++){ TPoint *point = (TPoint *)KPointList->Items[i]; pPoints[i].X = (point->x - xPoz) * zoomIn / zoomOut - px; pPoints[i].Y = (point->y - yPoz) * zoomIn / zoomOut - py; } graphics.DrawCurve(&pen, pPoints, pointCount); } for(int i = 0; i < KPointList->Count; i++){ TPoint *point = (TPoint *)KPointList->Items[i]; int tempx = (point->x - xPoz) * zoomIn / zoomOut - px; int tempy = (point->y - yPoz) * zoomIn / zoomOut - py; //if(tempx - 3 <= MainImageForm->nKasuriXPosition && MainImageForm->nKasuriXPosition <= tempx + 3 && tempy - 3 <= MainImageForm->nKasuriYPosition && MainImageForm->nKasuriYPosition <= tempy + 3) pen.SetColor(redPenColor); //by bomchun (06.10.13) //else pen.SetColor(penColor); //graphics.DrawRectangle(&pen, tempx - 3, tempy - 3, 6, 6); //pen.SetColor(penColor);///* if (MovePointIndex != -1 && MovePointIndex == i){ //061014 if (i % pointCount == 0){ //shin 061024 graphics.DrawRectangle(&penRedBold, tempx - 3, tempy - 3, 6, 6); } else { graphics.DrawRectangle(&penRed, tempx - 3, tempy - 3, 6, 6); } } else { if (i % pointCount == 0){ //shin 061024 graphics.DrawRectangle(&penBold, tempx - 3, tempy - 3, 6, 6); } else { graphics.DrawRectangle(&pen, tempx - 3, tempy - 3, 6, 6); } } //*/ } } if (pPoints) delete[] pPoints; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetPointCount(int Value) { pointCount = Value; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetBranchCount(int Value) { branchCount = Value; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetTwigCount(int Value) { twigCount = Value; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetAllBranchCount(int Value) { if (allBranchCount > 0){ oldBranchCount = allBranchCount; } else { oldBranchCount = Value; } allBranchCount = Value; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetDistance(int Value) { dDist = (double)Value/10; if (dDist <= 0) dDist = 0.05; } //--------------------------------------------------------------------------- TPoint __fastcall TKasuri::CalculatePointsOnSpline(TPoint *pt, double t) { TPoint tempPoint; tempPoint.x = 0; tempPoint.y = 0; double tempx = 0.0, tempy = 0.0; // tensionÀÌ 0.5ÀÎ Cardinal spline = Catmull-Rom spline // P(i-1), P(i), P(i+1), P(i+2) tempx = 0.5*(-t*(t-1)*(t-1)*pt[0].x + (2 - 5*t*t + 3*t*t*t)*pt[1].x + t*(1 + 4*t - 3*t*t)*pt[2].x - t*t*(1 - t)*pt[3].x); tempy = 0.5*(-t*(t-1)*(t-1)*pt[0].y + (2 - 5*t*t + 3*t*t*t)*pt[1].y + t*(1 + 4*t - 3*t*t)*pt[2].y - t*t*(1 - t)*pt[3].y); tempPoint.x = tempx; tempPoint.y = tempy; return tempPoint; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetPenPoints(TPoint *pPoints, int nPenPointCount, int nPenSize) { BEGIN_LOG(""); KPenWidth = nPenSize; EditPenPointCount = nPenPointCount; if (EditPenPoints) delete[] EditPenPoints; EditPenPoints = new TPoint[4]; for (int i = 0; i < 4; i++){ EditPenPoints[i].x = pPoints[i].x; EditPenPoints[i].y = pPoints[i].y; } if (KasuriPenPoints) delete[] KasuriPenPoints; KasuriPenPoints = new TPoint[4+pointCount-2]; // ¿©±â¼­ÀÇ segment´Â ÆæÀÇ Á¡µé »çÀÌÀÇ ºÐÇÒ int segwidth = pPoints[3].x/3; TPoint *tempPoints = new TPoint[pointCount - 2]; int oldseg = 0; for (int i = 0; i < pointCount - 2; i++){ int tempwidth = segwidth*(i+1); tempPoints[i].x = tempwidth; int seg = 1; while(seg < nPenPointCount && pPoints[seg].x < tempPoints[i].x){ seg++; } // ÇöÀç seg ¹øÂ° ¼¼±×¸ÕÆ®¿¡ ÀÖ´Ù. if (seg == nPenPointCount) seg = nPenPointCount - 1; TPoint *fourPoints = new TPoint[4]; GetFourPoints(fourPoints, pPoints, nPenPointCount, seg); TPoint tempp; if (seg > 0){ tempp = CalculatePointsOnSpline(fourPoints, (tempPoints[i].x - pPoints[seg-1].x) / (pPoints[seg].x - pPoints[seg-1].x)); } else { tempp = CalculatePointsOnSpline(fourPoints, tempPoints[i].x/pPoints[seg].x); } tempPoints[i].y = tempp.y; oldseg = seg; delete[] fourPoints; } int count = 0; int k = 0, j = 0; for (int i = 0; i < pointCount - 2; i++){ for (j = k; j < 4; j++){ if (pPoints[j].x < tempPoints[i].x){ KasuriPenPoints[count].x = pPoints[j].x; KasuriPenPoints[count].y = pPoints[j].y; k = j+1; count++; } } KasuriPenPoints[count].x = tempPoints[i].x; KasuriPenPoints[count].y = tempPoints[i].y; count++; if (count > 4+pointCount-2) break; } for (int i = count; i < 4+pointCount-2; i++){ KasuriPenPoints[i].x = pPoints[k].x; KasuriPenPoints[i].y = pPoints[k].y; k++; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::GetFourPoints(TPoint *pPoints, TPoint *linePoints, int segcount, int seg) { BEGIN_LOG(""); if (seg - 1 >= 0){ pPoints[0].x = linePoints[seg-1].x; pPoints[0].y = linePoints[seg-1].y; } else { pPoints[0].x = linePoints[seg].x; pPoints[0].y = linePoints[seg].y; } pPoints[1].x = linePoints[seg].x; pPoints[1].y = linePoints[seg].y; if (seg+1 < segcount){ pPoints[2].x = linePoints[seg+1].x; pPoints[2].y = linePoints[seg+1].y; if (seg+2 < segcount){ pPoints[3].x = linePoints[seg+2].x; pPoints[3].y = linePoints[seg+2].y; } else { pPoints[3].x = linePoints[seg+1].x; pPoints[3].y = linePoints[seg+1].y; } } else { pPoints[2].x = linePoints[seg].x; pPoints[2].y = linePoints[seg].y; pPoints[3].x = linePoints[seg].x; pPoints[3].y = linePoints[seg].y; } END_LOG; } //--------------------------------------------------------------------------- double __fastcall TKasuri::CalculateLineLangth(TPoint *linePoints) { BEGIN_LOG(""); double length = 0.0; TPoint *fourPoints = new TPoint[4]; for (int i = 0; i < pointCount - 1; i++){ GetFourPoints(fourPoints, linePoints, pointCount, i); length += CalculateSegmentLangth(fourPoints, 1); } END_LOG; return length; } //--------------------------------------------------------------------------- double __fastcall TKasuri::CalculateSegmentLangth(TPoint *pFourPoints, double dDist) { BEGIN_LOG(""); double segLength = 0.0; int x = 0, y = 0; TPoint startp, tempp; startp = CalculatePointsOnSpline(pFourPoints, 0); x = startp.x; y = startp.y; for (double t = 0.01; t < dDist; t+= 0.01){ tempp = CalculatePointsOnSpline(pFourPoints, t); segLength += sqrt((x - tempp.x)*(x - tempp.x) + (y - tempp.y)*(y - tempp.y)); x = tempp.x; y = tempp.y; } END_LOG; return segLength; } //--------------------------------------------------------------------------- double __fastcall TKasuri::nowPositionLength(TPoint *linePoints, int nSegment, double dDist) { BEGIN_LOG(""); double length = 0.0; TPoint *fourPoints = new TPoint[4]; for (int i = 0; i <= nSegment; i++){ GetFourPoints(fourPoints, linePoints, pointCount, i); if (i <= nSegment - 1){ length += CalculateSegmentLangth(fourPoints, 1); } else { length += CalculateSegmentLangth(fourPoints, dDist); } } delete[] fourPoints; END_LOG; return length; } //--------------------------------------------------------------------------- void __fastcall TKasuri::GetPathOutLine(gdp::Point *pPoints, gdp::PointF *OutLineUpPoints, gdp::PointF *OutLineDownPoints, int nPathCount, int &nCount) { BEGIN_LOG(""); gdp::PointF *UpPoints = new gdp::PointF[nPathCount/2 + 1]; gdp::PointF *DownPoints = new gdp::PointF[nPathCount/2 + 1]; TPoint *linePoint = new TPoint[pointCount]; for (int i = 0; i < pointCount; i++){ linePoint[i].x = pPoints[pointCount- 1 - i].X; linePoint[i].y = pPoints[pointCount- 1 - i].Y; } TPoint *fourPoint = new TPoint[4]; int count = 0; double plus = (double)1/((nPathCount/2)/(pointCount - 1)); for (int i = 0; i < pointCount - 1; i++){ GetFourPoints(fourPoint, linePoint, pointCount, i); gdp::PointF tempup, tempdown; double start = 0; if (i == 0){ start = 0.5; UpPoints[0].X = linePoint[0].x; UpPoints[0].Y = linePoint[0].y; DownPoints[0].X = linePoint[0].x; DownPoints[0].Y = linePoint[0].y; count++; } else { start = 0; } //Ææ±½±â Àû¿ëÇØ¾ßÇÔ. //Ææ¸ð¾ç Á¶ÀýÁ¡Àº ¾îµð¿¡ ÀÖ³ª double LineLen = CalculateLineLangth(linePoint); double nowLen = 0.0; double nowPenWidth = 0.0; for (double t = plus; t < 1; t += plus){ nowLen = nowPositionLength(linePoint, i, t); nowPenWidth = CalNowPosPenWidth(LineLen, nowLen); tempup = CalculatePointsNormalOnSpline2(fourPoint, t, nowPenWidth/2, true); tempdown = CalculatePointsNormalOnSpline2(fourPoint, t, nowPenWidth/2, false); UpPoints[count].X = tempup.X; UpPoints[count].Y = tempup.Y; DownPoints[count].X = tempdown.X; DownPoints[count].Y = tempdown.Y; count++; } } for (int i = 0; i <= count; i++){ if (i < count){ OutLineUpPoints[count - i].X = UpPoints[i].X; OutLineUpPoints[count - i].Y = UpPoints[i].Y; OutLineDownPoints[i].X = DownPoints[i].X; OutLineDownPoints[i].Y = DownPoints[i].Y; } else { OutLineUpPoints[0].X = linePoint[pointCount-1].x; OutLineUpPoints[0].Y = linePoint[pointCount-1].y; OutLineDownPoints[i].X = linePoint[pointCount-1].x; OutLineDownPoints[i].Y = linePoint[pointCount-1].y; } } count++; nCount = count; delete[] UpPoints; delete[] DownPoints; END_LOG; } //--------------------------------------------------------------------------- gdp::PointF __fastcall TKasuri::CalculatePointsNormalOnSpline2(TPoint *pt, double t, double dSize, bool bUp) { BEGIN_LOG(""); TPoint temp; gdp::PointF result; double tempx = 0.0, tempy = 0.0; tempx = 0.5*((-1 +4*t-3*t*t)*pt[0].x + (-10*t+9*t*t)*pt[1].x + (1+8*t-9*t*t)*pt[2].x + (-2*t+3*t*t)*pt[3].x); tempy = 0.5*((-1 +4*t-3*t*t)*pt[0].y + (-10*t+9*t*t)*pt[1].y + (1+8*t-9*t*t)*pt[2].y + (-2*t+3*t*t)*pt[3].y); double e = sqrt((tempx*tempx)+(tempy*tempy)); //for normalize tempx = tempx *dSize / e; tempy = tempy *dSize / e; temp = CalculatePointsOnSpline(pt, t); if (bUp){ result.X = temp.x + tempy; result.Y = temp.y - tempx; } else { result.X = temp.x - tempy; result.Y = temp.y + tempx; } END_LOG; return result; } //--------------------------------------------------------------------------- //Àüü±æÀÌ, ÇöÀç À§Ä¡ ³Ñ°ÜÁÖ¸é ÇöÀçÀÇ ±½±â ³Ñ°ÜÁØ´Ù. double __fastcall TKasuri::CalNowPosPenWidth(int Length, int nowPos) { BEGIN_LOG(""); TPoint *newPenPoints; newPenPoints = new TPoint[EditPenPointCount]; int maxheight = 0; int mid = 0; int maxpos = 0; double *height = new double[EditPenPointCount]; double *width = new double[EditPenPointCount]; //Àüü¿¡ ´ëÇÑ ³ÐÀÌ ºñÀ² double nowPosPenWidth = 0.0; int oldwidth = 0; for (int i = 0; i < EditPenPointCount; i++){ TPoint point = EditPenPoints[i]; if (i == 0){ mid = point.y; height[i] = 0; width[i] = 0; } else { if ((mid - point.y)*2 > maxheight){ maxheight = (mid - point.y)*2; maxpos = i; } height[i] = (mid - point.y)*2; width[i] = point.x; } } // ºñÀ²·Î ³Ö±â for (int i = 0; i < EditPenPointCount; i++){ double temp = height[i]; height[i] = (double)temp/maxheight; width[i] = (double)width[i]/EditPenPoints[EditPenPointCount - 1].x; } for (int i = 0; i < EditPenPointCount; i++){ newPenPoints[i].x = (double)Length*width[i]; newPenPoints[i].y = (double)(KPenWidth*kZoomIn/kZoomOut)*height[i]; } int seg = 0; int pos = nowPos; for (int i = 1; i < EditPenPointCount; i++){ if (pos <= newPenPoints[i].x){ seg = i; break; } } pos -= newPenPoints[seg-1].x; TPoint *fourPoints = new TPoint[4]; GetFourPoints(fourPoints, newPenPoints, EditPenPointCount, seg - 1); gdp::PointF tempp; double t = 0.0; if (seg > 0){ if (newPenPoints[seg].x > 0){ t = (double)pos/ (newPenPoints[seg].x - newPenPoints[seg-1].x); } else { t = 0; } tempp = CalculatePointsOnSpline2(fourPoints, t); } else { if (newPenPoints[seg].x > 0){ t = (double)nowPos/newPenPoints[seg].x; } else { t = 0; } tempp = CalculatePointsOnSpline2(fourPoints, t); } nowPosPenWidth = tempp.Y; delete[] height; delete[] width; END_LOG; return nowPosPenWidth; } //--------------------------------------------------------------------------- gdp::PointF __fastcall TKasuri::CalculatePointsOnSpline2(TPoint *pt, double t) { BEGIN_LOG(""); gdp::PointF tempPoint; tempPoint.X = 0; tempPoint.Y = 0; double tempx = 0.0, tempy = 0.0; // tensionÀÌ 0.5ÀÎ Cardinal spline = Catmull-Rom spline // P(i-1), P(i), P(i+1), P(i+2) tempx = 0.5*(-t*(t-1)*(t-1)*pt[0].x + (2 - 5*t*t + 3*t*t*t)*pt[1].x + t*(1 + 4*t - 3*t*t)*pt[2].x - t*t*(1 - t)*pt[3].x); tempy = 0.5*(-t*(t-1)*(t-1)*pt[0].y + (2 - 5*t*t + 3*t*t*t)*pt[1].y + t*(1 + 4*t - 3*t*t)*pt[2].y - t*t*(1 - t)*pt[3].y); tempPoint.X = tempx; tempPoint.Y = tempy; END_LOG; return tempPoint; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetPenColor(RGBQUAD color, int colorIndex) { KPenColor.rgbBlue = color.rgbBlue; KPenColor.rgbGreen = color.rgbGreen; KPenColor.rgbRed = color.rgbRed; KPenColor.rgbReserved = 0xFF; KPenColorIndex = colorIndex; } //--------------------------------------------------------------------------- void __fastcall TKasuri::Apply(TUnionBitmap *Image, TUnionBitmap *Background, bool useProtectColor, bool isMask, TUnionBitmap *ProtectMask, bool useProtectPen) { BEGIN_LOG(""); CalculateRect(); //061018 if ((Image->BitsPerPixel == 24 || Image->BitsPerPixel == 1 || (Image->BitsPerPixel == 8 && !useProtectColor)) && !useProtectPen){ ApplyKasuri(Image, isMask); } else if (Image->BitsPerPixel == 8){ ApplyKasuriHasProtectColor8(Image, Background, isMask, ProtectMask); } else if (Image->BitsPerPixel == 24 || Image->BitsPerPixel == 1){ ApplyKasuriHasProtectColor24(Image, Background, isMask, ProtectMask); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::ApplyKasuri(TUnionBitmap *Image, bool isMask) { BEGIN_LOG(""); RECT rtInter; HDC dc = NULL, dcNormalPen = NULL; if (Image->BitsPerPixel == 8 && isNormalPen && isMask){ // shin // vista¿¡¼­ 256Ä®¶ó ºñÆ®¸ÊÀÇ DC¿¡ Èò ¹ÙÅÁ(255)¿¡ °ËÀº »ö(0)À¸·Î ±×¸± ¶§ // ÆÈ·¹Æ®¿¡ Èò »ö(255)ÀÌ ÀÖ´Â °æ¿ì ±× ÆÈ·¹Æ® ¹øÈ£·Î ä¿öÁö´Â ºÎºÐÀÌ À־ // Åõ¸íÇØ¾ßÇÒ ¹è°æºÎºÐÀÌ Èò»öÀ¸·Î ³ª¿À´Â ¹®Á¦¶§¹®¿¡ ¾Æ·¡ÀÇ ³»¿ë Ãß°¡. // Àӽà ºñÆ®¸ÊÀ» ¸¸µé°í Ææ »ö(0)ÀÌ ¾Æ´Ñ °æ¿ì ¹è°æ»ö(255)À¸·Î ³Ö¾îÁØ´Ù. TTexpiaBitmap *normalBitmap = new TTexpiaBitmap; normalBitmap->Create(KRect.right - KRect.left, KRect.bottom - KRect.top, 8, Image->RGB); normalBitmap->StartScanLine(); BYTE *Dst; for (int y = 0; y < normalBitmap->Height; y++){ Dst = normalBitmap->GetScanLine(y); for (int x = 0; x < normalBitmap->Width; x++){ Dst[x] = 255; } normalBitmap->PutScanLine(y); } normalBitmap->StopScanLine(); dcNormalPen = normalBitmap->CreateDC(); if (dcNormalPen){ DrawNormalPen(dcNormalPen, 1, 1, KRect.left, KRect.top, 0, 0, true); normalBitmap->DeleteDC(dcNormalPen); } normalBitmap->StartScanLine(); for (int y = 0; y < normalBitmap->Height; y++){ BYTE *Dst; Dst = normalBitmap->GetScanLine(y); for (int x = 0; x < normalBitmap->Width; x++){ if (Dst[x] != 255 && Dst[x] != 0){ int r, g, b; r = PaletteForm->DIB256Palette->Palette->ColorData[Dst[x]]->RGB.rgbRed; g = PaletteForm->DIB256Palette->Palette->ColorData[Dst[x]]->RGB.rgbGreen; b = PaletteForm->DIB256Palette->Palette->ColorData[Dst[x]]->RGB.rgbBlue; int sum = r + g + b; if (sum/3 < 256/2){ Dst[x] = 0; } else { Dst[x] = 255; } } } normalBitmap->PutScanLine(y); } normalBitmap->StopScanLine(); int y, x, i, j; Byte *dstImage, *srcNormal; Image->StartScanLine(); normalBitmap->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcNormal = normalBitmap->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcNormal[j] != 255){ dstImage[x] = srcNormal[j]; } } Image->PutScanLine(y); } normalBitmap->StopScanLine(); Image->StopScanLine(); if (normalBitmap) delete normalBitmap; } else { for (int Count = 0; Count < Image->CountX*Image->CountY; Count++) { if (IntersectRect(&rtInter, &(Image->uRect[0][Count]), &KRect)) { dc = Image->CreateDC(Count); DrawKasuri(dc, 1, 1, 0, 0, (Image->uRect[0][Count]).left, (Image->uRect[0][Count]).top, Image->BitsPerPixel, isMask, Image->BackgroundColor, Image->RGB); Image->Table[0][Count].blank = false; (Image->Table[0][Count]).modify = true; (Image->Table[0][Count]).isZoomUpdated = false; Image->DeleteDC(dc, Count); } } } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::ApplyKasuriHasProtectColor8(TUnionBitmap *Image, TUnionBitmap *Background, bool isMask, TUnionBitmap *ProtectPenImage) { BEGIN_LOG(""); int zoomIn = 1; int zoomOut = 1; TTexpiaBitmap *protectColorMask; protectColorMask = new TTexpiaBitmap; Byte *Dst, *Src, *ProI; TUnionBitmap *dstBitmap = NULL; if (Background){ dstBitmap = Background; } else { dstBitmap = Image; } int y, x, i, j; protectColorMask->Create(KRect.right - KRect.left, KRect.bottom - KRect.top, 8); protectColorMask->FillRect(Rect(0, 0, protectColorMask->Width, protectColorMask->Height), clWhite); dstBitmap->StartScanLine(); protectColorMask->StartScanLine(); if (ProtectPenImage){ ProtectPenImage->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ Src = dstBitmap->GetScanLine(y); ProI = ProtectPenImage->GetScanLine(y); Dst = protectColorMask->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (PaletteForm->DIB256Palette->Palette->ColorData[Src[x]]->Protect || (ProI[x] != 0)){ Dst[j] = 0; } } protectColorMask->PutScanLine(i); } ProtectPenImage->StopScanLine(); } else { for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ Src = dstBitmap->GetScanLine(y); Dst = protectColorMask->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (PaletteForm->DIB256Palette->Palette->ColorData[Src[x]]->Protect){ Dst[j] = 0; } } protectColorMask->PutScanLine(i); } } protectColorMask->StopScanLine(); dstBitmap->StopScanLine(); if (isNormalPen){ NormalPenProtectColor8(isMask, Image, protectColorMask); } else { CrayonProtectColor8(isMask, Image, protectColorMask); } if (protectColorMask){ delete protectColorMask; protectColorMask = NULL; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::ApplyKasuriHasProtectColor24(TUnionBitmap *Image, TUnionBitmap *Background, bool isMask, TUnionBitmap *ProtectPenImage) { BEGIN_LOG(""); int zoomIn = 1; int zoomOut = 1; TTexpiaBitmap *protectColorMask; protectColorMask = new TTexpiaBitmap; Byte *Dst, *Src, *ProI; TUnionBitmap *dstBitmap = NULL; if (Background){ dstBitmap = Background; } else { dstBitmap = Image; } if (isNormalPen){ NormalPenProtectColor24(isMask, Image, ProtectPenImage); } else { CrayonPenProtectColor24(isMask, Image, ProtectPenImage); } if (protectColorMask){ delete protectColorMask; protectColorMask = NULL; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetCrayonBitmap(TTexpiaBitmap *Bitmap, COLORREF Color, int zoomIn, int zoomOut) { BEGIN_LOG(""); RGBQUAD rgb[256]; if (CrayonBitmap) delete CrayonBitmap; CrayonBitmap = new TTexpiaBitmap; Bitmap->GetColors(0, 256, rgb); CrayonBitmap->Create(Bitmap->Width, Bitmap->Height, Bitmap->BitsPerPixel, rgb); CrayonBitmap->Copy(Bitmap, SRCCOPY); bgColor = Color; if (bPointCalEnd) ChangeCrayonPen(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::CalculateRect() { //ÇöÀç Á¡µéÀÇ Rect±¸Çϱâ int minx = 100000; int miny = 100000; int maxx = 0; int maxy = 0; for (int i = 0; i < KPointList->Count; i++){ TPoint *point = (TPoint *)KPointList->Items[i]; if (point->x < minx) minx = point->x; if (point->y < miny) miny = point->y; if (point->x > maxx) maxx = point->x; if (point->y > maxy) maxy = point->y; } KRect.left = minx - KPenWidth; KRect.top = miny - KPenWidth; KRect.right = maxx + KPenWidth; KRect.bottom = maxy + KPenWidth; } //--------------------------------------------------------------------------- void __fastcall TKasuri::ChangeCrayonPen() { BEGIN_LOG(""); CalculateRect(); if (PenBitmap) delete PenBitmap; if (PenMask) delete PenMask; PenBitmap = new TTexpiaBitmap; PenMask = new TTexpiaBitmap; RGBQUAD rgb[256]; if (CrayonBitmap->BitsPerPixel == 24){ PenBitmap->Create(CrayonBitmap->Width, CrayonBitmap->Height, CrayonBitmap->BitsPerPixel); PenBitmap->FillRect(Rect(0, 0, PenBitmap->Width, PenBitmap->Height), bgColor); PenMask->Create(CrayonBitmap->Width, CrayonBitmap->Height, 1); PenMask->FillRect(Rect(0, 0, PenMask->Width, PenMask->Height), clWhite); } else { CrayonBitmap->GetColors(0, 256, rgb); PenBitmap->Create(CrayonBitmap->Width, CrayonBitmap->Height, CrayonBitmap->BitsPerPixel, rgb); //PenBitmap->FillRect(Rect(0, 0, PenBitmap->Width, PenBitmap->Height), bgColor); PenMask->Create(CrayonBitmap->Width, CrayonBitmap->Height, 8, rgb); PenBitmap->StartScanLine(); PenMask->StartScanLine(); BYTE *Dst, *DstM; for (int y = 0; y < CrayonBitmap->Height; y++){ Dst = PenBitmap->GetScanLine(y); DstM = PenMask->GetScanLine(y); memset(Dst, 0xFF, PenBitmap->Width); memset(DstM, 0xFF, PenMask->Width); PenBitmap->PutScanLine(y); PenMask->PutScanLine(y); } PenBitmap->StopScanLine(); PenMask->StopScanLine(); } HDC dcPen = PenBitmap->CreateDC(); DrawNormalPen(dcPen, 1, 1, KRect.left, KRect.top, 0, 0, true); PenBitmap->DeleteDC(dcPen); // shin // vista¿¡¼­ 256Ä®¶ó ºñÆ®¸ÊÀÇ DC¿¡ Èò ¹ÙÅÁ(255)¿¡ °ËÀº »ö(0)À¸·Î ±×¸± ¶§ // ÆÈ·¹Æ®¿¡ Èò »ö(255)ÀÌ ÀÖ´Â °æ¿ì ±× ÆÈ·¹Æ® ¹øÈ£·Î ä¿öÁö´Â ºÎºÐÀÌ À־ // Åõ¸íÇØ¾ßÇÒ ¹è°æºÎºÐÀÌ Èò»öÀ¸·Î ³ª¿À´Â ¹®Á¦¶§¹®¿¡ ¾Æ·¡ÀÇ ³»¿ë Ãß°¡. // xp¿¡¼­µµ 0ÀÌ ´Ù¸¥ »öÀ¸·Î ¹Ù²î´Â °æ¿ì°¡ ÀÖ¾î // 0°ú 255°¡ µÇµµ·Ï ¾Æ·¡Ã³·³ ¼öÁ¤. //---------------------------------------------------------------------------> Byte changeW = 0xFF, changeB = 0x00; Byte *pen; PenBitmap->StartScanLine(); for (int y = 0; y < PenBitmap->Height; y++){ pen = PenBitmap->GetScanLine(y); for (int x = 0; x < PenBitmap->Width; x++){ if (pen[x] != 255 || pen[x] != 0){ int red, green, blue; red = PaletteForm->DIB256Palette->Palette->ColorData[pen[x]]->RGB.rgbRed; green = PaletteForm->DIB256Palette->Palette->ColorData[pen[x]]->RGB.rgbGreen; blue = PaletteForm->DIB256Palette->Palette->ColorData[pen[x]]->RGB.rgbBlue; int sum = red + green + blue; if (sum != 0){ if (sum/3 < 256/2){ changeB = pen[x]; } else { changeW = pen[x]; } } else { changeB = pen[x]; } if (changeB != 0 && changeW != 255) break; } } } PenBitmap->StopScanLine(); if (changeB != 0 || changeW != 255){ PenBitmap->StartScanLine(); for (int y = 0; y < PenBitmap->Height; y++){ pen = PenBitmap->GetScanLine(y); for (int x = 0; x < PenBitmap->Width; x++){ if ((pen[x] != 0 && pen[x] == changeB)){ pen[x] = 0; } else if ((pen[x] != 255 && pen[x] == changeW)){ pen[x] = 255; } } PenBitmap->PutScanLine(y); } PenBitmap->StopScanLine(); } //---------------------------------------------------------------------------< BYTE *Src, *Dst, *DstM; PenBitmap->StartScanLine(); PenMask->StartScanLine(); CrayonBitmap->StartScanLine(); if (CrayonBitmap->BitsPerPixel == 24){ for (int y = 0; y < CrayonBitmap->Height; y++){ Dst = PenBitmap->GetScanLine(y); DstM = PenMask->GetScanLine(y); Src = CrayonBitmap->GetScanLine(y); int count = 0; for (int x = 0; x < CrayonBitmap->Width*3; x += 3){ if ((Dst[x] != 0xFF) || (Dst[x+1] != 0xFF) || (Dst[x+2] != 0xFF)){ if ((Src[x] != 0xFF) || (Src[x+1] != 0xFF) || (Src[x+2] != 0xFF)){ Dst[x] = Src[x]; Dst[x+1] = Src[x+1]; Dst[x+2] = Src[x+2]; DstM[count/8] &= ~(0x80 >> (count%8)); } } count++; } PenBitmap->PutScanLine(y); PenMask->PutScanLine(y); } } else { for (int y = 0; y < CrayonBitmap->Height; y++){ Dst = PenBitmap->GetScanLine(y); DstM = PenMask->GetScanLine(y); Src = CrayonBitmap->GetScanLine(y); int count = 0; for (int x = 0; x < CrayonBitmap->Width; x++){ if (Dst[x] == 0x00){ if (Src[x] != bgColor){ Dst[x] = Src[x]; DstM[x] = 0; } else { Dst[x] = 0xFF; } } } PenBitmap->PutScanLine(y); PenMask->PutScanLine(y); } } PenBitmap->StopScanLine(); PenMask->StopScanLine(); CrayonBitmap->StopScanLine(); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::SetPen(bool IsNormal) { isNormalPen = IsNormal; } //--------------------------------------------------------------------------- int __fastcall TKasuri::CalMaxTwigs() { BEGIN_LOG(""); int result = 0; int diff = 10000; int finda = 0, findb = 0; TList *BranchPointList = new TList; for (int i = 1; i < pointCount; i++){ MakeSameOrderBranchPointList(i, BranchPointList); //°¢ branch¸¶´Ù °°Àº À§Ä¡¿¡ ÀÖ´Â Á¡µéÀ» °¡Á®¿Â´Ù //Á¡»çÀÌÀÇ °Å¸®°¡ °¡Àå Á¼Àº °÷À» ã´Â´Ù for (int j = 0; j < BranchPointList->Count - 1; j++){ TPoint *point = (TPoint *)BranchPointList->Items[j]; TPoint *pointn = (TPoint *)BranchPointList->Items[j+1]; int temp = sqrt((point->x - pointn->x)*(point->x - pointn->x) + (point->y - pointn->y)*(point->y - pointn->y)); if (temp < diff){ diff = temp; finda = i; findb = j; } } } while(BranchPointList->Count > 0){ TPoint *point = (TPoint *)BranchPointList->Last(); BranchPointList->Remove(point); if (point) delete point; } delete BranchPointList; result = (double)diff*0.3; END_LOG; return result; } //--------------------------------------------------------------------------- void __fastcall TKasuri::ChangePoint(int nMoveIndex) { BEGIN_LOG(""); int branchNum, nOrder; if (nMoveIndex == 0){ branchNum = 0; nOrder = 0; } else { branchNum = nMoveIndex/pointCount; nOrder = nMoveIndex%pointCount; } TPoint *point = (TPoint *)KPointList->Items[nMoveIndex]; AllPoints[branchNum*(twigCount+1)][nOrder].x = point->x; AllPoints[branchNum*(twigCount+1)][nOrder].y = point->y; int start, end; if (branchNum == 0){ start = 0; end = 0; } else { start = branchNum - 1; if (branchNum == branchCount-1){ end = branchNum - 1; } else { end = branchNum; } } for (int i = start; i <= end; i++){ CalculateSegment(i); } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::CalculateSegment(int nBranchNum) { BEGIN_LOG(""); TPoint *twigPoints = new TPoint[twigCount]; TPoint *pBranchS, *pBranchE; pBranchS = new TPoint; pBranchE = new TPoint; for (int order = 0; order < pointCount; order++){ for (int j = 0; j < twigCount; j++){ twigPoints[j].x = 0; twigPoints[j].y = 0; } FindBranchPoints(nBranchNum, order, pBranchS, pBranchE); if (order == 0){ int tempx = 0, tempy = 0; int count = twigCount + 1; int sx = 0, sy = 0, ex = 0, ey = 0; sx = pBranchS->x; sy = pBranchS->y; ex = pBranchE->x; ey = pBranchE->y; int m = 1; int n = count - m; for (int k = 0; k < twigCount; k++){ tempx = (sx * n + ex * m)/(m + n); tempy = (sy * n + ey * m)/(m + n); twigPoints[k].x = tempx; twigPoints[k].y = tempy; m++; n--; if (m < 1 || n < 1) break; } } else { CalculateSegmentTwigPositions(nBranchNum, pBranchS, pBranchE, twigPoints); // »çÀ̸¶´Ù À§Ä¡ÇÒ Á¡µéÀ» °è»êÇÑ´Ù. for (int i = 0; i < twigCount; i++){ if (i != 0){ if (twigPoints[i].x == 0 && twigPoints[i].y == 0){ twigPoints[i].x = twigPoints[i-1].x; twigPoints[i].y = twigPoints[i-1].y; } } } } AddSegmentTwigPoints(nBranchNum, order, twigPoints); } if (twigPoints){ delete[] twigPoints; twigPoints = NULL; } delete pBranchS; delete pBranchE; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::NormalPenProtectColor8(bool isMask, TUnionBitmap *Image, TTexpiaBitmap *protectColorMask) { BEGIN_LOG(""); if (!isMask){ HDC dcNormalPen = NULL; TTexpiaBitmap *normalBitmap = new TTexpiaBitmap; normalBitmap->Create(protectColorMask->Width, protectColorMask->Height, 8, Image->RGB); normalBitmap->StartScanLine(); BYTE *Dst; for (int y = 0; y < normalBitmap->Height; y++){ Dst = normalBitmap->GetScanLine(y); for (int x = 0; x < normalBitmap->Width; x++){ Dst[x] = 255; } normalBitmap->PutScanLine(y); } normalBitmap->StopScanLine(); dcNormalPen = normalBitmap->CreateDC(); if (dcNormalPen){ DrawNormalPen(dcNormalPen, 1, 1, KRect.left, KRect.top, 0, 0, false); normalBitmap->DeleteDC(dcNormalPen); } // shin 070309 vista¿¡¼­ 256Ä®¶ó ºñÆ®¸Ê¿¡ DC¸¦ ½èÀ» °æ¿ì ÆÈ·¹Æ®¿¡ Èò»öÀÌ Æ÷ÇԵǾúÀ» ¶§ // ¹è°æÀ» Èò»öÀÌ ÀÖ´Â ÆÈ·¹Æ® ¹øÈ£·Î ä¿ö¹ö¸®´Â ¹®Á¦°¡ À־ ¾Æ·¡ ºÎºÐÀ» ³ÖÀ½. normalBitmap->StartScanLine(); for (int y = 0; y < normalBitmap->Height; y++){ Dst = normalBitmap->GetScanLine(y); for (int x = 0; x < normalBitmap->Width; x++){ if (Dst[x] != 255 && Dst[x] != KPenColorIndex){ //Dst[x] = 255; int r, g, b; r = PaletteForm->DIB256Palette->Palette->ColorData[Dst[x]]->RGB.rgbRed; g = PaletteForm->DIB256Palette->Palette->ColorData[Dst[x]]->RGB.rgbGreen; b = PaletteForm->DIB256Palette->Palette->ColorData[Dst[x]]->RGB.rgbBlue; int sum = r + g + b; if (sum/3 < 256/2){ Dst[x] = KPenColorIndex; } else { Dst[x] = 255; } } } normalBitmap->PutScanLine(y); } normalBitmap->StopScanLine(); Byte *ptm = NULL, *norb = NULL; normalBitmap->StartScanLine(); protectColorMask->StartScanLine(); for (int y = 0; y < protectColorMask->Height; y++){ ptm = protectColorMask->GetScanLine(y); norb = normalBitmap->GetScanLine(y); for (int x = 0; x < protectColorMask->Width; x++){ if (ptm[x] == 0){ norb[x] = 255; } } normalBitmap->PutScanLine(y); } normalBitmap->StopScanLine(); protectColorMask->StopScanLine(); int y, x, i, j; Byte *dstImage, *srcNormal; Image->StartScanLine(); normalBitmap->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcNormal = normalBitmap->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcNormal[j] != 0 && srcNormal[j] != 255){ dstImage[x] = srcNormal[j]; } } Image->PutScanLine(y); } normalBitmap->StopScanLine(); Image->StopScanLine(); if (normalBitmap) delete normalBitmap; } else { HDC dcNormalMask = NULL; TTexpiaBitmap *normalMask = new TTexpiaBitmap; normalMask->Create(protectColorMask->Width, protectColorMask->Height, 8, Image->RGB); BYTE *Dst, *DstM; normalMask->StartScanLine(); for (int y = 0; y < normalMask->Height; y++){ DstM = normalMask->GetScanLine(y); memset(DstM, 1, normalMask->Width); normalMask->PutScanLine(y); } normalMask->StopScanLine(); dcNormalMask = normalMask->CreateDC(); if (dcNormalMask){ DrawNormalPen(dcNormalMask, 1, 1, KRect.left, KRect.top, 0, 0, true); normalMask->DeleteDC(dcNormalMask); } Byte *ptm = NULL, *norb = NULL, *norm = NULL; normalMask->StartScanLine(); protectColorMask->StartScanLine(); for (int y = 0; y < protectColorMask->Height; y++){ ptm = protectColorMask->GetScanLine(y); norm = normalMask->GetScanLine(y); for (int x = 0; x < protectColorMask->Width; x++){ if (ptm[x] == 0){ norm[x] = 1; } } normalMask->PutScanLine(y); } normalMask->StopScanLine(); protectColorMask->StopScanLine(); int y, x, i, j; Byte *dstImage, *srcNormal; Image->StartScanLine(); normalMask->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcNormal = normalMask->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcNormal[j] != 1){ dstImage[x] = srcNormal[j]; } } Image->PutScanLine(y); } Image->StopScanLine(); normalMask->StopScanLine(); if (normalMask) delete normalMask; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::CrayonProtectColor8(bool isMask, TUnionBitmap *Image, TTexpiaBitmap *protectColorMask) { BEGIN_LOG(""); TTexpiaBitmap *tempPen = new TTexpiaBitmap; tempPen->Create(PenBitmap->Width, PenBitmap->Height, Image->BitsPerPixel, Image->RGB); tempPen->StartScanLine(); BYTE *DstM; for (int y = 0; y < tempPen->Height; y++){ DstM = tempPen->GetScanLine(y); memset(DstM, 0xFF, tempPen->Width); tempPen->PutScanLine(y); } tempPen->StopScanLine(); if (!isMask){ Byte *pen, *temp, *protect; PenBitmap->StartScanLine(); tempPen->StartScanLine(); protectColorMask->StartScanLine(); for (int y = 0; y < PenBitmap->Height; y++){ pen = PenBitmap->GetScanLine(y); temp = tempPen->GetScanLine(y); protect = protectColorMask->GetScanLine(y); for (int x = 0; x < PenBitmap->Width; x++){ if (protect[x] != 0){ temp[x] = pen[x]; } } tempPen->PutScanLine(y); } PenBitmap->StopScanLine(); tempPen->StopScanLine(); protectColorMask->StopScanLine(); int y, x, i, j; int imageOldLine = -1, nImageAccNum = 0; Byte *dstImage, *srcTemp; Image->StartScanLine(); tempPen->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcTemp = tempPen->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcTemp[j] != 255){ dstImage[x] = srcTemp[j]; } } Image->PutScanLine(y); } Image->StopScanLine(); tempPen->StopScanLine(); } else { Byte *pen, *temp, *protect; PenMask->StartScanLine(); tempPen->StartScanLine(); protectColorMask->StartScanLine(); for (int y = 0; y < PenMask->Height; y++){ pen = PenMask->GetScanLine(y); temp = tempPen->GetScanLine(y); protect = protectColorMask->GetScanLine(y); for (int x = 0; x < PenMask->Width; x++){ if (protect[x] != 0){ temp[x] = pen[x]; } } tempPen->PutScanLine(y); } PenMask->StopScanLine(); tempPen->StopScanLine(); protectColorMask->StopScanLine(); int y, x, i, j; Byte *dstImage, *srcTemp; Image->StartScanLine(); tempPen->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcTemp = tempPen->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcTemp[j] != 255){ dstImage[x] = 0; } } Image->PutScanLine(y); } Image->StopScanLine(); tempPen->StopScanLine(); } if (tempPen){ delete tempPen; tempPen = NULL; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::NormalPenProtectColor24(bool isMask, TUnionBitmap *Image, TUnionBitmap *ProtectPenImage) { BEGIN_LOG(""); if (!isMask){ HDC dcNormalPen = NULL; TTexpiaBitmap *normalBitmap = new TTexpiaBitmap; normalBitmap->Create(KRect.right - KRect.left, KRect.bottom - KRect.top, 24); normalBitmap->FillRect(Rect(0, 0, normalBitmap->Width, normalBitmap->Height), clWhite); dcNormalPen = normalBitmap->CreateDC(); if (dcNormalPen){ DrawNormalPen(dcNormalPen, 1, 1, KRect.left, KRect.top, 0, 0, false); normalBitmap->DeleteDC(dcNormalPen); } int y, x, i, j; Byte *dstImage, *srcNormal, *protectImage; Image->StartScanLine(); normalBitmap->StartScanLine(); ProtectPenImage->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); protectImage = ProtectPenImage->GetScanLine(y); srcNormal = normalBitmap->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcNormal[j*3] != 255 || srcNormal[j*3+1] != 255 || srcNormal[j*3+2] != 255){ if ((protectImage[x >> 3] & (0x80 >> (x&7))) == 0){ dstImage[x*3] = srcNormal[j*3]; dstImage[x*3+1] = srcNormal[j*3+1]; dstImage[x*3+2] = srcNormal[j*3+2]; } } } Image->PutScanLine(y); } Image->StopScanLine(); normalBitmap->StopScanLine(); ProtectPenImage->StopScanLine(); if (normalBitmap) delete normalBitmap; } else { HDC dcNormalMask = NULL; TTexpiaBitmap *normalMask = new TTexpiaBitmap; normalMask->Create(KRect.right - KRect.left, KRect.bottom - KRect.top, 1); normalMask->FillRect(Rect(0, 0, normalMask->Width, normalMask->Height), clWhite); dcNormalMask = normalMask->CreateDC(); if (dcNormalMask){ DrawNormalPen(dcNormalMask, 1, 1, KRect.left, KRect.top, 0, 0, true); normalMask->DeleteDC(dcNormalMask); } int y, x, i, j; Byte *dstImage, *srcNormal, *protectImage; Image->StartScanLine(); normalMask->StartScanLine(); ProtectPenImage->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); protectImage = ProtectPenImage->GetScanLine(y); srcNormal = normalMask->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if( ((srcNormal[j>>3] & (0x80 >> (j&7))) == 0)){ if ((protectImage[x >> 3] & (0x80 >> (x&7))) == 0){ dstImage[x>>3] &= (0xFF - (0x80 >> (x&7))); } } } Image->PutScanLine(y); } Image->StopScanLine(); normalMask->StopScanLine(); ProtectPenImage->StopScanLine(); if (normalMask) delete normalMask; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TKasuri::CrayonPenProtectColor24(bool isMask, TUnionBitmap *Image, TUnionBitmap *ProtectPenImage) { BEGIN_LOG(""); TTexpiaBitmap *tempPen = new TTexpiaBitmap; tempPen->Create(PenBitmap->Width, PenBitmap->Height, Image->BitsPerPixel, Image->RGB); tempPen->FillRect(Rect(0, 0, tempPen->Width, tempPen->Height), clWhite); if (!isMask){ int x, y, i, j; Byte *pen, *temp, *protectImage; PenBitmap->StartScanLine(); tempPen->StartScanLine(); ProtectPenImage->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ pen = PenBitmap->GetScanLine(i); temp = tempPen->GetScanLine(i); protectImage = ProtectPenImage->GetScanLine(y); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if ((protectImage[x >> 3] & (0x80 >> (x&7))) == 0 && (pen[j*3] != 0 ||pen[j*3+1] != 0 || pen[j*3+2] != 0)){ temp[j*3] = pen[j*3]; temp[j*3+1] = pen[j*3+1]; temp[j*3+2] = pen[j*3+2]; } } tempPen->PutScanLine(i); } PenBitmap->StopScanLine(); tempPen->StopScanLine(); ProtectPenImage->StopScanLine(); Byte *dstImage, *srcTemp; Image->StartScanLine(); tempPen->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcTemp = tempPen->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (srcTemp[j*3] != 255 || srcTemp[j*3+1] != 255 || srcTemp[j*3+2] != 255){ dstImage[x*3] = srcTemp[j*3]; dstImage[x*3+1] = srcTemp[j*3+1]; dstImage[x*3+2] = srcTemp[j*3+2]; } } Image->PutScanLine(y); } Image->StopScanLine(); tempPen->StopScanLine(); } else { int x, y, i, j; Byte *pen, *temp, *protectImage; PenMask->StartScanLine(); tempPen->StartScanLine(); ProtectPenImage->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ pen = PenMask->GetScanLine(i); temp = tempPen->GetScanLine(i); protectImage = ProtectPenImage->GetScanLine(y); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if (((protectImage[x>>3] & (0x80 >> (x&7))) == 0) && ((pen[j>>3] & (0x80>>(j&7))) == 0)){ temp[j>>3] &= (0xFF - (0x80 >> (j&7))); } } tempPen->PutScanLine(i); } PenMask->StopScanLine(); tempPen->StopScanLine(); ProtectPenImage->StopScanLine(); Byte *dstImage, *srcTemp; Image->StartScanLine(); tempPen->StartScanLine(); for (y = KRect.top, i = 0; y < KRect.bottom; y++, i++){ dstImage = Image->GetScanLine(y); srcTemp = tempPen->GetScanLine(i); for (x = KRect.left, j = 0; x < KRect.right; x++, j++){ if ((srcTemp[j>>3] & (0x80 >> (j&7))) == 0){ dstImage[x>>3] &= (0xFF - (0x80 >> (x&7))); } } Image->PutScanLine(y); } Image->StopScanLine(); tempPen->StopScanLine(); } if (tempPen){ delete tempPen; tempPen = NULL; } END_LOG; } //---------------------------------------------------------------------------