//--------------------------------------------------------------------------- #include #include #include #pragma hdrstop #include "ColorLibrary_F.h" #include "Common.h" #include "FullView.h" #include "History.h" #include "Main.h" #include "MainMenu.h" #include "PenManager.h" #include "ProtectCard.h" #include "Undo.h" #include "Carpet_F.h" #include "MainImage.h" #include "UserColor_F.h" #include "AutoSave.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPImage" #pragma link "TPTextileImage" #pragma link "TPSelectImage" #pragma link "TPRuler2D" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_ZOOMIN StringTable[0] #define IDS_ZOOMOUT StringTable[1] #define IDS_GRID StringTable[2] #define IDS_RULER StringTable[3] #define IDS_PROTECTION StringTable[4] #define IDS_UNIT StringTable[5] //--------------------------------------------------------------------------- TMainImageForm *MainImageForm; int MainImageCount = 0; //--------------------------------------------------------------------------- __fastcall TMainImageForm::TMainImageForm(TComponent* Owner) : TForm(Owner) { Number = MainImageCount; MainImageCount++; memsize = 0; hMemLine = NULL; msx = NULL; BtnClick = false; DownState = false; bProtect = false; bMaskArea = false; bDrawPen = true; isDrawPenLocate = false; MouseState = 0; CurrentUnit = uCm; cbTime = 0; Modify = false; Palette = NULL; WorkArea = NULL; TempBitmap = TempMask = NULL; CarpetTexture = NULL; Data3D = NULL; LineList = new TList; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormActivate(TObject *Sender) { if (MainImageForm!=this) { MainMenuForm->ExitForm(1); MainImageForm = this; PenManagerForm->InitPenForm(); } Undo->Set(Number, iMainImage, Palette, WorkArea); FullViewForm->InitForm(iMainImage); PaletteForm->UpdateForm(iMainImage->Bitmap->BitsPerPixel); ReviewStatusBar(); ReleaseCapture(); ShowZoomText(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormClose(TObject *Sender, TCloseAction &Action) { Action = caFree; delete LineList; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormCloseQuery(TObject *Sender, bool &CanClose) { AnsiString msg, fn, ext; char *s; TGraphicFileFormat gff; if (iMainImage->Bitmap->BitsPerPixel==8) { gff = gffTEX; ext = ".tex"; MainForm->SaveDialog->Filter = "Texpro Textile 256 Colors File (*.tex)|*.tex"; } else { if (MainMenuForm->Item == T_3D) { gff = gffT3D; ext = ".t3d"; MainForm->SaveDialog->Filter = "Texpro Textile 3D File (*.t3d)|*.t3d"; } else { gff = gffTFC; ext = ".tfc"; MainForm->SaveDialog->Filter = "Texpro Textile Full Colors File (*.tfc)|*.tfc"; } } MainMenuForm->ExitForm(1); if (Modify) { msg = Format(" %s", OPENARRAY (TVarRec,(FileName))); int Btn = MessageDlg(IDS_MESSAGE_SAVECHANGE + msg, mtWarning, TMsgDlgButtons()<SaveDialog->InitialDir = IniFile->ReadString("FileManager", "DirectoryName", "C:\\"); delete IniFile; } if (MainForm->SaveDialog->Execute()) { s = AnsiStrScan(MainForm->SaveDialog->FileName.c_str(), '.'); if (s==NULL) fn = MainForm->SaveDialog->FileName+ext; else fn = MainForm->SaveDialog->FileName; DirName = ExtractFileDir(fn); FileName = ExtractFileName(fn); SaveToFile(DirName, FileName, gff, MainForm->CompressMethod); CanClose = true; } } else { SaveToFile(DirName, FileName, gff, MainForm->CompressMethod); CanClose = true; } } else if (Btn == mrNo) { CanClose = true; } else { CanClose = false; } } else { CanClose = true; } if (CanClose) { PaletteForm->DIB256Palette->ChoiceIndex = 2; if (FileExists(FileName)) { FileHistory->InsertHistory(DirName, ExtractFileName(FileName), 1, iMainImage->Bitmap->BitsPerPixel); } } Modify = false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormCreate(TObject *Sender) { TGrid g; #ifndef LOCK_CRYPKEY #ifndef LOCK_IFC ProtectCard->Check(); #endif #endif //======================================== StringTable.Create(DirectoryBin+"\\Carpet", Language, "MainImage"); SetSmallFont(Font); sbZoomIn->Hint = IDS_ZOOMIN; sbZoomOut->Hint = IDS_ZOOMOUT; sbGrid->Hint = IDS_GRID; sbRuler->Hint = IDS_RULER; sbProtect->Hint = IDS_PROTECTION; sbMaskArea->Hint = IDS_COMMON_MASKAREA; sbMaskShow->Hint = IDS_COMMON_MASKSHOW; sbUnit->Caption = AnsiString(IDS_UNIT) + " : Cm"; //======================================== if ((WorkArea = new TWorkArea(&(iMainImage->Bitmap)))==NULL) goto fail; if ((Palette = new TPalette)==NULL) goto fail; if ((CarpetTexture = new TList) == NULL) goto fail; MainImageForm = this; CanvasInfor.DotsPerInch = 160; CanvasInfor.SetExtFileOption(); ApplyEnvironment(); Panel->PopupMenu = MainMenuForm->PopupMenu1; iMainImage->Cursor = crPen; ZoomChange(1, 1); PaletteForm->InitForm(Palette); PenManagerForm->InitPenForm(); ReviewStatusBar(); iMainImage->OnPaintRange = DrawCarpetArea; return; fail: ::doDestroy(CarpetTexture); ::doDestroy(Palette); ::doDestroy(WorkArea); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormDestroy(TObject *Sender) { MainMenuForm->ExitForm(1); ::doDestroy(Data3D); DelLineMem(); ::doDestroy(CarpetTexture); ::doDestroy(Palette); ::doDestroy(WorkArea); FullViewForm->InitForm(NULL); MainImageForm = NULL; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormPaint(TObject *Sender) { if (isDrawPenLocate) { iMainImage->Repaint(); isDrawPenLocate = false; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormResize(TObject *Sender) { Ruler->Width = ClientWidth-PanelVert->Width; Ruler->Height = ClientHeight-PanelHorz->Height; if (sbRuler->Down) { Panel->Left = Ruler->Thick; Panel->Top = Ruler->Thick; Panel->Width = Ruler->Width-Ruler->Thick; Panel->Height = Ruler->Height-Ruler->Thick; } else { Panel->Left = 0; Panel->Top = 0; Panel->Width = Ruler->Width; Panel->Height = Ruler->Height; } PanelHorz->Top = Ruler->Top+Ruler->Height+1; PanelHorz->Width = Ruler->Width; sbHorz->Width = PanelHorz->Width-sbHorz->Left-2; PanelVert->Left = Ruler->Left+Ruler->Width+1; PanelVert->Height = Ruler->Height; sbVert->Height = PanelVert->Height-sbVert->Top-2; iMainImage->SetPosition(); FullViewForm->SetSize(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { MainMenuForm->iMainImageKeyUp(Key); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormKeyPress(TObject *Sender, char &Key) { MainMenuForm->iMainImageKeyDown(Key); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TRect r; COLORREF c; Byte color; if (Active) { if (Button==mbRight) return; if (X>=0 && XBitmap->Width && Y>=0 && YBitmap->Height) { if (isDrawPenLocate) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); isDrawPenLocate = false; } DownState = true; if (Shift.Contains(ssCtrl) && Button==mbLeft) { MouseState = 1; iMainImage->Cursor = crHandPoint; ptFirst = Point(X, Y); } else { if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { c = iMainImage->Bitmap->GetPixelColor(X, Y); if (iMainImage->Bitmap->BitsPerPixel == 24) { PaletteForm->DIB256Palette->SetNormal(PaletteForm->DIB256Palette->ChoiceIndex, GetRValue(c), GetGValue(c), GetBValue(c)); color = PaletteForm->DIB256Palette->ChoiceIndex; PaletteForm->DIB256Palette->Repaint(); } else color = c; PenManagerForm->SelectColor(color); } if (MainMenuForm->iMainImageMouseDown(this, Button, Shift, X, Y)) { PaletteForm->iMainImageMouseDown(Sender, Button, Shift, X, Y); if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { // PenManagerForm->SelectColor(iMainImage->Bitmap->GetPixelColor(X, Y)); PenManagerForm->SpecialMouseDown(Button, Shift, X, Y); } else if (Button==mbLeft) { if (bDrawPen) { if (FullViewForm->iMainImageMouseDown(Sender, X, Y)) { PenManagerForm->SpecialMouseDown(Button, Shift, X, Y); BtnClick = true; } } } } } if (iMainImage->Cursor==crPen) { DrawPenLocate(X, Y); ptPenLocate = Point(X, Y); isDrawPenLocate = true; } } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseLeave(TObject *Sender) { if (isDrawPenLocate) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); isDrawPenLocate = false; } MainMenuForm->iMainImageMouseLeave(); iMainImage->Cursor = crDefault; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { POINT pt; COLORREF color; if (Active) { if (X < 0 || X >= iMainImage->Bitmap->Width || Y < 0 || Y >= iMainImage->Bitmap->Height) { BtnClick = false; } if (X>=0 && XBitmap->Width && Y>=0 && YBitmap->Height) { if (isDrawPenLocate) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); isDrawPenLocate = false; } CursorPosition.x = X; CursorPosition.y = Y; if (MouseState) { ptSecond = Point(X, Y); pt.x = ptSecond.x-ptFirst.x; pt.y = ptSecond.y-ptFirst.y; iMainImage->SetPosition(iMainImage->PositionX-pt.x, iMainImage->PositionY-pt.y); ptFirst.x = ptSecond.x-pt.x; ptFirst.y = ptSecond.y-pt.y; } else { if (DownState==false) { color = iMainImage->Bitmap->GetPixelColor(CursorPosition.x, CursorPosition.y); PaletteForm->DIB256Palette->CursorIndex = color; } if (MainMenuForm->iMainImageMouseMove(this, Shift, X, Y)) { if (bDrawPen) { if (FullViewForm->iMainImageMouseMove(Sender, X, Y)) { if (PenManagerForm->acolor == 1) { PenManagerForm->SpecialMouseMove(Shift, X, Y); iMainImage->Cursor = crCross; } else { if (BtnClick) PenManagerForm->SpecialMouseMove(Shift, X, Y); iMainImage->Cursor = crPen; } } else { iMainImage->Cursor = crCross; } } PaletteForm->iMainImageMouseMove(Sender, Shift, X, Y); } } if (iMainImage->Cursor==crPen) { DrawPenLocate(X, Y); ptPenLocate = Point(X, Y); isDrawPenLocate = true; } } else { MainMenuForm->iMainImageMouseLeave(); iMainImage->Cursor = crDefault; } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (Active) { if (isDrawPenLocate) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); isDrawPenLocate = false; } if (MouseState) { ptSecond = Point(X, Y); iMainImageChange(); iMainImage->SetPosition(iMainImage->PositionX-(ptSecond.x-ptFirst.x), iMainImage->PositionY-(ptSecond.y-ptFirst.y)); MouseState = 0; } else { if ((XBitmap->Width) && (YBitmap->Height)) { if (MainMenuForm->iMainImageMouseUp(this, Button, Shift, X, Y)) { PenManagerForm->SpecialMouseUp(Button, Shift, X, Y); BtnClick = false; } FullViewForm->View(); DownState = false; } } if (iMainImage->Cursor==crPen) { DrawPenLocate(X, Y); ptPenLocate = Point(X, Y); isDrawPenLocate = true; } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImagePaint(TObject *Sender) { isDrawPenLocate = false; if (MainMenuForm->iMainImagePaint(this)) { PaletteForm->iMainImagePaint(); PenManagerForm->SpecialPaint(); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImagePositionChange(TObject *Sender) { UpdateImage(); Ruler->StartX = iMainImage->PositionX; Ruler->StartY = iMainImage->PositionY; sbHorz->Position = iMainImage->PositionX; sbVert->Position = iMainImage->PositionY; FullViewForm->SetPositionX(iMainImage->PositionX); FullViewForm->SetPositionY(iMainImage->PositionY); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iSelectImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (MainMenuForm->iSelectImageMouseDown(this, Button, Shift, X, Y)) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); iMainImage->Cursor = crPen; isDrawPenLocate = true; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iSelectImageMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { MainMenuForm->iSelectImageMouseMove(this, Shift, X, Y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbUnitClick(TObject *Sender) { if (CurrentUnit==uDot) UnitChange(uInch); else if (CurrentUnit==uInch) UnitChange(uCm); else if (CurrentUnit==uCm) UnitChange(uDot); //================================== for fit size by kjs //v7.1À» ÄÄÆÄÀÏÇϱâ À§ÇØ Àá½Ã ¸·¾Æ³ð.. if (MainMenuForm->sb3D->Down) MainMenuForm->Show_FabricSize(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbHorzScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { iMainImageChange(); iMainImage->PositionX = sbHorz->Position; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbZoomInClick(TObject *Sender) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(2, 1); break; case 2: ZoomChange(1, 1); break; case 4: ZoomChange(1, 2); break; case 8: ZoomChange(1, 4); break; case 16: ZoomChange(1, 8); break; } break; case 2: ZoomChange(4, 1); break; case 4: ZoomChange(8, 1); break; case 8: ZoomChange(16, 1); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbZoomOutClick(TObject *Sender) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(1, 2); break; case 2: ZoomChange(1, 4); break; case 4: ZoomChange(1, 8); break; case 8: ZoomChange(1, 16); break; } break; case 2: ZoomChange(1, 1); break; case 4: ZoomChange(2, 1); break; case 8: ZoomChange(4, 1); break; case 16: ZoomChange(8, 1); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbRulerClick(TObject *Sender) { iMainImageChange(); FormResize(this); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbProtectClick(TObject *Sender) { TSpeedButton *s = (TSpeedButton *)Sender; if (s == sbProtect) { bProtect ^= 1; MainMenuForm->SuperChange(Sender); } else if (s == sbMaskArea) { bMaskArea ^= 1; MainMenuForm->SuperChange(Sender); } else if (s == sbMaskShow) { SetMaskShow(sbMaskShow->Down); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbGridClick(TObject *Sender) { iMainImageChange(); iMainImage->Grid = sbGrid->Down; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::sbVertScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { iMainImageChange(); iMainImage->PositionY = sbVert->Position; } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- int TMainImageForm::WMNCPaint(TMessage &msg) { if (isDrawPenLocate) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); isDrawPenLocate = false; } DefWindowProc(Handle, WM_NCPAINT, msg.WParam, msg.LParam); return 0; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetCaption() { AnsiString fn = ExtractFileName(FileName); if (iMainImage->Bitmap->BitsPerPixel==8) { Caption = (DirName.Length()>0 ? DirName+"\\"+ fn: fn)+" - 256 Colors"; } else { Caption = (DirName.Length()>0 ? DirName+"\\"+ fn : fn)+" - Full Colors"; } if (iMainImage->Bitmap->BitsPerPixel==8) { sbProtect->Enabled = true; } else { sbProtect->Enabled = false; } } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::LoadFromFile(AnsiString FileName, TGraphicFileFormat Index, TTexpiaBitmap *pBitmap, TPalette *pPalette, TPCanvasInfor &ci) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; int x, y; RGBQUAD rgb[256]; Byte c[256], *bp; TPException ec = EC_NONE; if (Index==gffTEX || Index==gffTFC) { if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pBitmap)) != EC_NONE) goto fail; UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; CloseHandle(hFile); } else if (Index==gffWEA || Index==gffWAV || Index==gffKNT) { if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pBitmap, false)) != EC_NONE) goto fail; UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; CloseHandle(hFile); } else { if (!pBitmap->LoadFromFile(FileName.c_str())) goto fail; ci.DotsPerInch = CanvasInfor.DotsPerInch ? CanvasInfor.DotsPerInch : 160; ci.SetSize(cstFree, pBitmap->Width, pBitmap->Height); if (pBitmap->BitsPerPixel == 8) { pBitmap->GetColors(0, 256, rgb); pPalette->SetNormal(0, 0, 0, 0); for (x=0; x<=249; x++) { pPalette->SetNormal(x+2, rgb[x].rgbRed, rgb[x].rgbGreen, rgb[x].rgbBlue); } pPalette->SetNormal(255, 255, 255, 255); pPalette->ToRGBQUAD(rgb, 256); pBitmap->PutColors(0, 256, rgb); memset(c, 0, 256); if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { bp = pBitmap->GetScanLine(y); for (x=0; xWidth; x++) { #ifdef TPDEBUG //////////////////////////////////////// BY KJS if ((*(bp+x)+2) >= 0 && (*(bp+x)+2) < 251) { *(bp+x) += 2; c[*(bp+x)] = 1; } else { AnsiString bpstring = AnsiString(*(bp+x)+2); ShowMessage("Out of Range " + bpstring); SHOWDEBUG; } #else *(bp+x) += 2; c[*(bp+x)] = 1; #endif } pBitmap->PutScanLine(y); } pBitmap->StopScanLine(); for (x=251; x>=1; x--) { if (c[x]==1) { pPalette->UseColor = x; break; } } } } return EC_NONE; fail: pBitmap->StopScanLine(); if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ReviewStatusBar() { MainForm->StatusBar->Panels->Items[StatusBarSize]->Text = "Size : " + CanvasInfor.Name(CurrentUnit, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); MainForm->StatusBar->Panels->Items[StatusBarDPI]->Text = Format("DPI : %d", OPENARRAY(TVarRec, (CanvasInfor.DotsPerInch))); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetProtect(bool Value) { if (Value!=bProtect) { bProtect = Value; if (bProtect) sbProtect->Down = true; else sbProtect->Down = false; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetMaskArea(bool Value) { if (Value!=bMaskArea) { bMaskArea = Value; sbMaskArea->Enabled = Value; sbMaskArea->Down = Value; sbMaskShow->Enabled = Value; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetMaskShow(bool Value) { if (iMainImage->MaskEnabled!=Value) { iMainImage->MaskEnabled = Value; sbMaskShow->Down = Value; } } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::AllocLineMem(int d) { if (d!=memsize) { DelLineMem(); if ((hMemLine = GlobalAlloc(GHND, 2*d*sizeof(int)))==NULL) goto fail; if ((msx = (int *)GlobalLock(hMemLine))==NULL) goto fail; mex = (int *)msx + d; memsize = d; } return true; fail: DelLineMem(); return false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DelLineMem() { if (hMemLine) { if (msx) { GlobalUnlock(hMemLine); msx = NULL; } GlobalFree(hMemLine); hMemLine = NULL; } memsize = 0; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::pos_in(TLineData &ld, int by, int bsx, int bex, int ch) { double d; if ((by>=0) && (byBitmap->Height)) { if (*(msx+by)>bsx) { if (ch) { d = (ld.dx1 - bsx) * (ld.dx1 - bsx) + (ld.dy1 - by) * (ld.dy1 - by); if (dVisible = false; if (Image->Width==Panel->Width) { p.x = iMainImage->PositionX-Image->PositionX; } else { p.x = iMainImage->CanvasToBitmapX(Image->Left); } if (Image->Height==Panel->Height) { p.y = iMainImage->PositionY-Image->PositionY; } else { p.y = iMainImage->CanvasToBitmapY(Image->Top); } rc = Rect(p.x, p.y, p.x+Image->Bitmap->Width, p.y+Image->Bitmap->Height); if (MainImageForm->bMaskArea) { if (!Image->Bitmap->StartScanLine()) goto fail; if (!iMainImage->Bitmap->StartScanLine()) goto fail; if (!iMainImage->Mask->StartScanLine()) goto fail; if (FullViewForm->Super==sOverlap) { if (!InitOverlap()) goto fail; if (iMainImage->Bitmap->BitsPerPixel==8) { if (Image->Bitmap->BitsPerPixel!=8) goto fail; if (bProtect) { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+rc.left; mml = iMainImage->Mask->GetScanLine(y)+rc.left; for (x=rc.left; xColorData[*dsl]->Protect==0 && (*mml == 0)) { if (*dsl > 1) { if ((color = Overlap(*dsl, *ssl))==0xFF) goto fail; *dsl = color; } else { *dsl = *ssl; } } } iMainImage->Bitmap->PutScanLine(y); } } else { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+rc.left; mml = iMainImage->Mask->GetScanLine(y)+rc.left; for (x=rc.left; x 1) { if ((color = Overlap(*dsl, *ssl))==0xFF) goto fail; *dsl = color; } else { *dsl = *ssl; } } } iMainImage->Bitmap->PutScanLine(y); } } } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (Image->Bitmap->BitsPerPixel==8) { Image->Bitmap->GetColors(0, 256, rgb); for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+3*rc.left; mml = iMainImage->Mask->GetScanLine(y); for (x=rc.left; x> 3] & (0x80 >> (x & 7))) == 0) { sc = RGBToTColor(rgb[*ssl]); GetPixel24(dsl, dc); if (dc != bgc) { color = Overlap(dc, sc); SetPixel24(dsl, color); } else { SetPixel24(dsl, sc); } } } iMainImage->Bitmap->PutScanLine(y); } } else { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+3*rc.left; mml = iMainImage->Mask->GetScanLine(y); for (x=rc.left; x> 3] & (0x80 >> (x & 7))) == 0) { GetPixel24(ssl, sc); GetPixel24(dsl, dc); if (dc != bgc) { color = Overlap(dc, sc); SetPixel24(dsl, color); } else { SetPixel24(dsl, sc); } } } iMainImage->Bitmap->PutScanLine(y); } } } ExitOverlap(); } else { if (iMainImage->Bitmap->BitsPerPixel == 8) { if (bProtect) { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y); mml = iMainImage->Mask->GetScanLine(y); for (x=rc.left; xColorData[dsl[x]]->Protect==0 && (mml[x] == 0)) dsl[x] = ssl[x-rc.left]; } iMainImage->Bitmap->PutScanLine(y); } } else { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y); mml = iMainImage->Mask->GetScanLine(y); for (x=rc.left; xBitmap->PutScanLine(y); } } } else { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y) + 3*rc.left; mml = iMainImage->Mask->GetScanLine(y); for (x=rc.left; x> 3)) & (0x80 >> (x & 7))) == 0) CopyPixel24(dsl, ssl); } iMainImage->Bitmap->PutScanLine(y); } } } iMainImage->Bitmap->StopScanLine(); iMainImage->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); } else { if (FullViewForm->Super==sOverlap) { if (!Image->Bitmap->StartScanLine()) goto fail; if (!iMainImage->Bitmap->StartScanLine()) goto fail; if (!InitOverlap()) goto fail; if (iMainImage->Bitmap->BitsPerPixel==8) { if (Image->Bitmap->BitsPerPixel!=8) goto fail; if (bProtect) { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+rc.left; for (x=rc.left; xColorData[*dsl]->Protect==0) { if (*dsl > 1) { if ((color = Overlap(*dsl, *ssl))==0xFF) goto fail; *dsl = color; } else { *dsl = *ssl; } } } iMainImage->Bitmap->PutScanLine(y); } } else { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+rc.left; for (x=rc.left; x 1) { if ((color = Overlap(*dsl, *ssl))==0xFF) goto fail; *dsl = color; } else { *dsl = *ssl; } } iMainImage->Bitmap->PutScanLine(y); } } } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (Image->Bitmap->BitsPerPixel==8) { Image->Bitmap->GetColors(0, 256, rgb); for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+3*rc.left; for (x=rc.left; xBitmap->PutScanLine(y); } } else { for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y)+3*rc.left; for (x=rc.left; xBitmap->PutScanLine(y); } } } ExitOverlap(); iMainImage->Bitmap->StopScanLine(); Image->Bitmap->StopScanLine(); } else { if (bProtect) { if (!(Image->Bitmap->StartScanLine())) goto fail; if (!(iMainImage->Bitmap->StartScanLine())) goto fail; for (y=rc.top; yBitmap->GetScanLine(y-rc.top); dsl = iMainImage->Bitmap->GetScanLine(y); for (x=rc.left; xColorData[dsl[x]]->Protect==0) dsl[x] = ssl[x-rc.left]; } iMainImage->Bitmap->PutScanLine(y); } iMainImage->Bitmap->StopScanLine(); Image->Bitmap->StopScanLine(); } else { iMainImage->Bitmap->CopyToRect(rc.left, rc.top, Image->Bitmap, SRCCOPY); } } } if (MainMenuForm->SubItem==0) { WorkArea->SetRectangle(rc); WorkAreaChange(); } return true; fail: ExitOverlap(); iMainImage->Bitmap->StopScanLine(); if (MainImageForm->bMaskArea) Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::SaveToClipboard() { RGBQUAD rgb[256]; BITMAPHANDLE bh, *pbh; int w, h, i, x, y; HDC dcSrc = NULL, dcMask = NULL, dcDst = NULL; HGLOBAL hMem = NULL; Byte *lpData = NULL; TClipboardInfo cbi; TColorData *cd; Byte *mp, *bp; COLORREF c; bool bClipboard = false; TPException ec = EC_NONE; if (WorkArea->Mask) { memset(&bh, 0, sizeof(BITMAPHANDLE)); w = WorkArea->Range.right-WorkArea->Range.left; h = WorkArea->Range.bottom-WorkArea->Range.top; // if (L_CreateBitmap(&bh, TYPE_CONV, w, h, iMainImage->Bitmap->BitsPerPixel, ORDER_BGR, NULL, TOP_LEFT)<1) goto next1; if (iMainImage->Bitmap->BitsPerPixel==8) { Palette->ToRGBQUAD(rgb, 256); L_PutBitmapColors(&bh, 0, 256, rgb); WorkArea->Mask->PutColors(0, 256, rgb); } if ((dcDst = L_CreateLeadDC(&bh))==NULL) goto next1; if ((dcSrc = iMainImage->Bitmap->CreateDC())==NULL) goto next1; BitBlt(dcDst, 0, 0, w, h, dcSrc, WorkArea->Range.left, WorkArea->Range.top, SRCCOPY); iMainImage->Bitmap->DeleteDC(dcSrc); dcSrc = NULL; if ((dcMask = WorkArea->Mask->CreateDC())==NULL) goto next1; BitBlt(dcDst, 0, 0, w, h, dcMask, 0, 0, SRCAND); WorkArea->Mask->DeleteDC(dcMask); dcMask = NULL; L_DeleteLeadDC(dcDst); dcDst = NULL; if (L_CopyToClipboard(MainForm->Handle, &bh)<1) goto next1; L_FreeBitmap(&bh); goto next2; next1: if (dcDst) { if (dcMask) WorkArea->Mask->DeleteDC(dcMask); if (dcSrc) iMainImage->Bitmap->DeleteDC(dcSrc); L_DeleteLeadDC(dcDst); } L_FreeBitmap(&bh); next2: // if (!OpenClipboard(MainForm->Handle)) { ec = EC_CLIPBOARD_NOT_OPEN; goto fail; } bClipboard = true; if (MainForm->ClipboardFormat) { cbi.Version = 0; cbi.Time = clock(); cbi.Width = w; cbi.Height = h; cbi.Mask = true; if (iMainImage->Bitmap->BitsPerPixel==8) { cbi.BitsPerPixel = 8; cbi.Colors = Palette->UseColor; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+ cbi.Colors*sizeof(TColorData)+cbi.Width*cbi.Height))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((lpData = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } memcpy(lpData, &cbi, sizeof(TClipboardInfo)); lpData += sizeof(TClipboardInfo); for (i=1; i<=cbi.Colors; i++) { cd = Palette->ColorData[i]; memcpy(lpData, cd, sizeof(TColorData)); lpData += sizeof(TColorData); } if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(WorkArea->Range.top+y); mp = WorkArea->Mask->GetScanLine(y); for (x=0; xRange.left+x); } else { *(lpData+x) = 0; } } lpData += cbi.Width; } iMainImage->Bitmap->StopScanLine(); WorkArea->Mask->StopScanLine(); GlobalUnlock(hMem); } else { cbi.BitsPerPixel = 24; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+sizeof(COLORREF)+ 3*cbi.Width*cbi.Height+WorkArea->Mask->BytesPerLine*cbi.Height))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((lpData = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } memcpy(lpData, &cbi, sizeof(TClipboardInfo)); lpData += sizeof(TClipboardInfo); c = Palette->Color[1]; memcpy(lpData, &c, sizeof(COLORREF)); lpData += sizeof(COLORREF); if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(WorkArea->Range.top+y)+3*WorkArea->Range.left; memcpy(lpData, bp, 3*cbi.Width); lpData += 3*cbi.Width; } iMainImage->Bitmap->StopScanLine(); if (!WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yMask->GetScanLine(y); for (x=0; xMask->BytesPerLine; x++) { *(lpData+x) = ~*(mp+x); } lpData += WorkArea->Mask->BytesPerLine; } WorkArea->Mask->StopScanLine(); GlobalUnlock(hMem); } SetClipboardData(MainForm->ClipboardFormat, hMem); } CloseClipboard(); } else { if ((pbh = iMainImage->Bitmap->Handle)==NULL) { ec = EC_RESOURCE_LACK; goto fail; } // L_CopyToClipboard(MainForm->Handle, pbh); // if (!OpenClipboard(MainForm->Handle)) { ec = EC_CLIPBOARD_NOT_OPEN; goto fail; } bClipboard = true; if (MainForm->ClipboardFormat) { cbi.Version = 0; cbi.Time = clock(); cbi.Width = iMainImage->Bitmap->Width; cbi.Height = iMainImage->Bitmap->Height; cbi.Mask = false; if (iMainImage->Bitmap->BitsPerPixel==8) { cbi.BitsPerPixel = 8; cbi.Colors = Palette->UseColor; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+ cbi.Colors*sizeof(TColorData)+cbi.Width*cbi.Height))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((lpData = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } memcpy(lpData, &cbi, sizeof(TClipboardInfo)); lpData += sizeof(TClipboardInfo); for (i=1; i<=cbi.Colors; i++) { cd = Palette->ColorData[i]; memcpy(lpData, cd, sizeof(TColorData)); lpData += sizeof(TColorData); } if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(y); memcpy(lpData, bp, cbi.Width); lpData += cbi.Width; } iMainImage->Bitmap->StopScanLine(); GlobalUnlock(hMem); } else { cbi.BitsPerPixel = 24; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+sizeof(COLORREF)+ 3*cbi.Width*cbi.Height))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((lpData = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } memcpy(lpData, &cbi, sizeof(TClipboardInfo)); lpData += sizeof(TClipboardInfo); c = Palette->Color[1]; memcpy(lpData, &c, sizeof(COLORREF)); lpData += sizeof(COLORREF); if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(y); memcpy(lpData, bp, 3*cbi.Width); lpData += 3*cbi.Width; } iMainImage->Bitmap->StopScanLine(); GlobalUnlock(hMem); } SetClipboardData(MainForm->ClipboardFormat, hMem); } CloseClipboard(); } return EC_NONE; fail: if (bClipboard) { if (hMem) { if (lpData) { if (WorkArea->Mask) WorkArea->Mask->StopScanLine(); iMainImage->Bitmap->StopScanLine(); GlobalUnlock(hMem); } GlobalFree(hMem); } CloseClipboard(); } return ec; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::ReadTexpiaFormatSuperOff(TClipboardInfo *cbi, Byte *Bitmap, int UseColor) { RGBQUAD rgb[256]; int x, y; Byte *sp, *bp, *mp; Palette->ToRGBQUAD(rgb, 256); TempBitmap->PutColors(0, 256, rgb); if (!TempBitmap->StartScanLine()) goto fail; if (cbi->Mask) { if ((TempMask = new TTexpiaBitmap)==NULL) goto fail; if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb)) goto fail; sp = Bitmap; if (!TempMask->StartScanLine()) goto fail; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); memcpy(bp, sp, cbi->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, bp++, mp++) { if (*bp<1) { *bp = 0; *mp = 0xFF; } else { *bp += UseColor; *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } TempMask->StopScanLine(); } else { // TempMask = NULL; sp = Bitmap; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); memcpy(bp, sp, cbi->Width); for (x=0; xWidth; x++) { if (*(bp+x)<1) { *(bp+x) = 0; } else { *(bp+x) += UseColor; } } TempBitmap->PutScanLine(y); sp += cbi->Width; } } TempBitmap->StopScanLine(); return true; fail: ::doDestroy(TempMask); TempBitmap->StopScanLine(); return false; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::ReadTexpiaFormatSuperNormal(TClipboardInfo *cbi, Byte *Bitmap, int UseColor) { RGBQUAD rgb[256]; int x, y; Byte *sp, *bp, *mp; Palette->ToRGBQUAD(rgb, 256); TempBitmap->PutColors(0, 256, rgb); if (!TempBitmap->StartScanLine()) goto fail; if ((TempMask = new TTexpiaBitmap)==NULL) goto fail; if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb)) goto fail; sp = Bitmap; if (!TempMask->StartScanLine()) goto fail; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); memcpy(bp, sp, cbi->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, bp++, mp++) { if (*bp<2) { *bp = 0; *mp = 0xFF; } else { *bp += UseColor; *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } TempMask->StopScanLine(); TempBitmap->StopScanLine(); return true; fail: ::doDestroy(TempMask); TempBitmap->StopScanLine(); return false; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::ReadTexpiaFormatSuperGauge(TClipboardInfo *cbi, Byte *Bitmap, int UseColor) { RGBQUAD rgb[256]; int x, y; Byte *sp, *bp, *mp; Palette->ToRGBQUAD(rgb, 256); TempBitmap->PutColors(0, 256, rgb); if (!TempBitmap->StartScanLine()) goto fail; if ((TempMask = new TTexpiaBitmap)==NULL) goto fail; if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb)) goto fail; sp = Bitmap; if (!TempMask->StartScanLine()) goto fail; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); memcpy(bp, sp, cbi->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, bp++, mp++) { if (*bp<2 || ((x+y)&1)) { *bp = 0; *mp = 0xFF; } else { *bp += UseColor; *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } TempMask->StopScanLine(); TempBitmap->StopScanLine(); return true; fail: ::doDestroy(TempMask); TempBitmap->StopScanLine(); return false; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadTexpiaFormat8To8(TClipboardInfo *cbi) { TRect r; int i, x, y, bg; bool sw = false; TColorData *Color; Byte *Bitmap, *sp; TPException ec = EC_NONE; Color = (TColorData *)((Byte *)cbi+sizeof(TClipboardInfo)); Bitmap = (Byte *)Color+cbi->Colors*sizeof(TColorData); if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(cbi->Width, cbi->Height, 8)) { ec = EC_MEMORY_LACK; goto fail; } switch (FullViewForm->Super) { case sOff: bg = 0; sp = Bitmap; for (y=0; yHeight; y++) { for (x=0; xWidth; x++) { if (*(sp+x)==1) { bg = 1; goto next1; } } sp += cbi->Width; } next1: if (cbTime==cbi->Time) { sw = true; if (Palette->UseColor==cbUseColor+cbi->Colors) { for (i=2-bg; i<=cbi->Colors; i++) { if (Palette->ColorData[cbUseColor+i]->Compare(Color+i-1)==false) { sw = false; break; } } } else { sw = false; } if (sw) { if (ReadTexpiaFormatSuperOff(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } } else { if (Palette->UseColor+cbi->Colors - 1 + bg >= 251) { ec = EC_COLOR_OVERFLOW; goto fail; } cbUseColor = Palette->UseColor - 1 + bg; for (i=2-bg; i<=cbi->Colors; i++) { Palette->ColorData[cbUseColor+i]->Copy(Color+i-1); } if (ReadTexpiaFormatSuperOff(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } Palette->UseColor = cbUseColor+cbi->Colors; cbTime = cbi->Time; } } else { if (Palette->UseColor+cbi->Colors - 1 + bg >= 251) { ec = EC_COLOR_OVERFLOW; goto fail; } cbUseColor = Palette->UseColor - 1 + bg; for (i=2-bg; i<=cbi->Colors; i++) { Palette->ColorData[cbUseColor+i]->Copy(Color+i-1); } if (ReadTexpiaFormatSuperOff(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } Palette->UseColor = cbUseColor+cbi->Colors; cbTime = cbi->Time; } break; case sOverlap: case sNormal: if (cbTime==cbi->Time) { sw = true; if (Palette->UseColor==cbUseColor+cbi->Colors) { for (i=2; i<=cbi->Colors; i++) { if (Palette->ColorData[cbUseColor+i]->Compare(Color+i-1)==false) { sw = false; break; } } } else { sw = false; } if (sw) { if (ReadTexpiaFormatSuperNormal(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } } else { if (Palette->UseColor + cbi->Colors - 1 >= 251) { ec = EC_COLOR_OVERFLOW; goto fail; } cbUseColor = Palette->UseColor-1; for (i=2; i<=cbi->Colors; i++) { Palette->ColorData[cbUseColor+i]->Copy(Color+i-1); } if (ReadTexpiaFormatSuperNormal(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } Palette->UseColor = cbUseColor+cbi->Colors; cbTime = cbi->Time; } } else { if (Palette->UseColor+cbi->Colors-1 >= 251) { ec = EC_COLOR_OVERFLOW; goto fail; } cbUseColor = Palette->UseColor-1; for (i=2; i<=cbi->Colors; i++) { Palette->ColorData[cbUseColor+i]->Copy(Color+i-1); } if (ReadTexpiaFormatSuperNormal(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } Palette->UseColor = cbUseColor+cbi->Colors; cbTime = cbi->Time; } break; case sGauze: bg = 0; sp = Bitmap; for (y=0; yHeight; y++) { for (x=0; xWidth; x++) { if (*(sp+x)==1) { bg = 1; goto next2; } } sp += cbi->Width; } next2: if (cbTime==cbi->Time) { sw = true; if (Palette->UseColor==cbUseColor+cbi->Colors) { for (i=2-bg; i<=cbi->Colors; i++) { if (Palette->ColorData[cbUseColor+i]->Compare(Color+i-1)==false) { sw = false; break; } } } else { sw = false; } if (sw) { if (ReadTexpiaFormatSuperNormal(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } } else { if (Palette->UseColor + cbi->Colors-1 + bg>=251) { ec = EC_COLOR_OVERFLOW; goto fail; } cbUseColor = Palette->UseColor-1+bg; for (i=2-bg; i<=cbi->Colors; i++) { Palette->ColorData[cbUseColor+i]->Copy(Color+i-1); } if (ReadTexpiaFormatSuperNormal(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } Palette->UseColor = cbUseColor+cbi->Colors; cbTime = cbi->Time; } } else { if (Palette->UseColor+cbi->Colors- 1 + bg>=251) { ec = EC_COLOR_OVERFLOW; goto fail; } cbUseColor = Palette->UseColor - 1 + bg; for (i=2-bg; i<=cbi->Colors; i++) { Palette->ColorData[cbUseColor+i]->Copy(Color+i-1); } if (ReadTexpiaFormatSuperNormal(cbi, Bitmap, cbUseColor) == false) { ec = EC_MEMORY_LACK; goto fail; } Palette->UseColor = cbUseColor+cbi->Colors; cbTime = cbi->Time; } break; } return EC_NONE; fail: ::doDestroy(TempBitmap); return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadTexpiaFormat8To24(TClipboardInfo *cbi) { TColorData *Color; int i, x, y; RGBQUAD rgb[256]; Byte *Bitmap, *sp, *ip, *mp; TPException ec = EC_NONE; Palette->ToRGBQUAD(rgb, 256); Color = (TColorData *)((Byte *)cbi+sizeof(TClipboardInfo)); for (i=1; i<=cbi->Colors; i++) { rgb[i] = Color[i-1].RGB; } Bitmap = (Byte *)Color+cbi->Colors*sizeof(TColorData); if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(cbi->Width, cbi->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } switch (FullViewForm->Super) { case sOff: if (cbi->Mask) { if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(cbi->Width, cbi->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } sp = Bitmap; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); memcpy(ip, sp, cbi->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, mp++) { if (*(ip+x)<1) { *mp = 0xFF; } else { *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } TempBitmap->StopScanLine(); TempMask->StopScanLine(); } else { sp = Bitmap; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); memcpy(ip, sp, cbi->Width); TempBitmap->PutScanLine(y); sp += cbi->Width; } TempBitmap->StopScanLine(); } break; case sOverlap: case sNormal: if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(cbi->Width, cbi->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } sp = Bitmap; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); memcpy(ip, sp, cbi->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, ip++, mp++) { if (*ip<2) { *ip = 0; *mp = 0xFF; } else { *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } TempBitmap->StopScanLine(); TempMask->StopScanLine(); break; case sGauze: if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(cbi->Width, cbi->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } sp = Bitmap; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (cbi->Mask) { for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); memcpy(ip, sp, cbi->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, ip++, mp++) { if (*ip<2) { *ip = 0; *mp = 0xFF; } else { *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } } TempBitmap->StopScanLine(); TempMask->StopScanLine(); break; } return EC_NONE; fail: if (TempBitmap) { ::doDestroy(TempMask); delete TempBitmap; TempBitmap = NULL; } return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadTexpiaFormat24To24(TClipboardInfo *cbi) { BYTE *sp, *ip, *mp, mm, b; WORD w; int x, y; COLORREF bgc, c; TPException ec = EC_NONE; sp = (Byte *)cbi+sizeof(TClipboardInfo); memcpy(&bgc, sp, sizeof(COLORREF)); sp += sizeof(COLORREF); if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(cbi->Width, cbi->Height, 24)) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (cbi->BitsPerPixel==15) { for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); for (x=0; xWidth; x++, sp+=2) { w = *(WORD *)sp; b = w&0x1F; *ip = (b<<3)|((b&0x1C)>>2); ip++; w >>= 5; b = w&0x1F; *ip = (b<<3)|((b&0x1C)>>2); ip++; w >>= 5; b = w&0x1F; *ip = (b<<3)|((b&0x1C)>>2); ip++; } TempBitmap->PutScanLine(y); } } else { for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); memcpy(ip, sp, 3*cbi->Width); TempBitmap->PutScanLine(y); sp += 3*cbi->Width; } } TempBitmap->StopScanLine(); switch (FullViewForm->Super) { case sOff: if (cbi->Mask) { if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(cbi->Width, cbi->Height, 1)) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); memcpy(mp, sp, TempMask->BytesPerLine); mm = 0x80; for (x=0; xWidth; x++, ip+=3) { if (*mp&mm) { SetPixel24(ip, 0); } if (mm==1) { mp++; mm = 0x80; } else mm >>= 1; } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += TempMask->BytesPerLine; } TempBitmap->StopScanLine(); TempMask->StopScanLine(); } break; case sOverlap: case sGauze: case sNormal: if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(cbi->Width, cbi->Height, 1)) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (cbi->Mask) { for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); memcpy(mp, sp, TempMask->BytesPerLine); mm = 0x80; for (x=0; xWidth; x++, ip+=3) { GetPixel24(ip, c); if ((*mp&mm) || c==bgc) { SetPixel24(ip, 0); *mp |= mm; } if (mm==1) { mp++; mm = 0x80; } else mm >>= 1; } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += TempMask->BytesPerLine; } } else { for (y=0; yHeight; y++) { ip = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); *mp = 0; mm = 0x80; x = 0; while(1) { GetPixel24(ip, c); if (c==bgc) { SetPixel24(ip, 0); *mp |= mm; } x++; if (x >= cbi->Width) break; ip += 3; if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } /* for (x=0; xWidth; x++, ip+=3) { GetPixel24(ip, c); if (c==bgc) { SetPixel24(ip, 0); *mp |= mm; } if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } */ TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += TempMask->BytesPerLine; } } TempBitmap->StopScanLine(); TempMask->StopScanLine(); break; } return EC_NONE; fail: if (TempBitmap) { ::doDestroy(TempMask); delete TempBitmap; TempBitmap = NULL; } return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadGeneralFormat8To8(BITMAPHANDLE *bh, int colors, short *color) { TRect r; int i, j, x, y; RGBQUAD rgb[256]; HANDLE hBuffer = NULL; Byte *pBuffer = NULL, *bp, *mp; TPException ec = EC_NONE; if (Palette->UseColor+colors-1>=252) { ec = EC_COLOR_OVERFLOW; goto fail; } L_GetBitmapColors(bh, 0, 256, rgb); cbUseColor = Palette->UseColor; for (i=0, j=cbUseColor+1; i<256; i++) { if (color[i]) { Palette->SetNormal(j, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue); color[i] = j; j++; } } Palette->ToRGBQUAD(rgb, 256); if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(bh->Width, bh->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } L_AccessBitmap(bh); if ((hBuffer = GlobalAlloc(GMEM_MOVEABLE, bh->BytesPerLine))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((pBuffer = (Byte *)GlobalLock(hBuffer))==NULL) { ec = EC_MEMORY_LACK; goto fail; } switch (FullViewForm->Super) { case sOff: case sNormal: case sOverlap: case sGauze: if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { L_GetBitmapRow(bh, pBuffer, y, bh->BytesPerLine); bp = TempBitmap->GetScanLine(y); memcpy(bp, pBuffer, bh->Width); for (x=0; xWidth; x++, bp++) { *bp = color[*bp]; } TempBitmap->PutScanLine(y); } TempBitmap->StopScanLine(); break; } Palette->UseColor = cbUseColor+colors; GlobalUnlock(hBuffer); GlobalFree(hBuffer); L_ReleaseBitmap(bh); return EC_NONE; fail: if (TempBitmap) { if (hBuffer) { if (pBuffer) { ::doDestroy(TempMask); GlobalUnlock(hBuffer); } GlobalFree(hBuffer); } delete TempBitmap; TempBitmap = NULL; } return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadGeneralFormat8To24(BITMAPHANDLE *bh, int colors, short *color) { HANDLE hBuffer = NULL; Byte *pBuffer = NULL; int i, x, y, nBlack, nWhite; RGBQUAD rgb[256], t; Byte *ip, *mp; TPException ec = EC_NONE; L_GetBitmapColors(bh, 0, 256, rgb); nBlack = -1; if (rgb[0].rgbRed!=0 || rgb[0].rgbGreen!=0 || rgb[0].rgbBlue!=0) { for (i=1; i<255; i++) { if (rgb[i].rgbRed==0 && rgb[i].rgbGreen==0 && rgb[i].rgbBlue==0) { nBlack = i; break; } } } else nBlack = 0; if (nBlack==-1) { for (i=1; i<255; i++) { if (color[i]==0) { nBlack = i; rgb[i].rgbRed = rgb[i].rgbGreen = rgb[i].rgbBlue = 0; color[i] = colors; colors++; break; } } if (i>=255) return false; } nWhite = -1; if (rgb[255].rgbRed!=255 || rgb[255].rgbGreen!=255 || rgb[255].rgbBlue!=255) { for (i=1; i<255; i++) { if (rgb[i].rgbRed==255 && rgb[i].rgbGreen==255 && rgb[i].rgbBlue==255) { nWhite = i; break; } } } else nWhite = 255; if (nWhite==-1) { for (i=1; i<255; i++) { if (color[i]==0) { nWhite = i; rgb[i].rgbRed = rgb[i].rgbGreen = rgb[i].rgbBlue = 255; color[i] = colors; colors++; break; } } if (i>=255) return false; } if (nBlack!=0) { t = rgb[0]; rgb[0] = rgb[nBlack]; rgb[nBlack] = t; } if (nWhite!=255) { t = rgb[255]; rgb[255] = rgb[nWhite]; rgb[nWhite] = t; } if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(bh->Width, bh->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if ((hBuffer = GlobalAlloc(GMEM_MOVEABLE, bh->BytesPerLine))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((pBuffer = (Byte *)GlobalLock(hBuffer))==NULL) { ec = EC_MEMORY_LACK; goto fail; } L_AccessBitmap(bh); if (nBlack!=0 || nWhite!=255) { for (y=0; yHeight; y++) { L_GetBitmapRow(bh, pBuffer, y, bh->BytesPerLine); ip = pBuffer; for (x=0; xWidth; x++, ip++) { if (*ip==nBlack) *ip = 0; else if (*ip==0) *ip = nBlack; else if (*ip==nWhite) *ip = 255; else if (*ip==255) *ip = nWhite; } } } switch (FullViewForm->Super) { case sOff: case sNormal: case sOverlap: case sGauze: if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { L_GetBitmapRow(bh, pBuffer, y, bh->BytesPerLine); ip = TempBitmap->GetScanLine(y); memcpy(ip, pBuffer, bh->Width); TempBitmap->PutScanLine(y); } TempBitmap->StopScanLine(); break; } L_ReleaseBitmap(bh); GlobalUnlock(hBuffer); GlobalFree(hBuffer); return EC_NONE; fail: if (TempBitmap) { if (hBuffer) { if (pBuffer) { ::doDestroy(TempMask); GlobalUnlock(hBuffer); } GlobalFree(hBuffer); } delete TempBitmap; TempBitmap = NULL; } return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadGeneralFormat24To24(BITMAPHANDLE *bh) { HANDLE hBuffer = NULL; Byte *pBuffer = NULL; Byte *ip, *mp, mm; int x, y; TPException ec = EC_NONE; if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(bh->Width, bh->Height, 24)) { ec = EC_MEMORY_LACK; goto fail; } L_AccessBitmap(bh); if ((hBuffer = GlobalAlloc(GMEM_MOVEABLE, bh->BytesPerLine))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((pBuffer = (Byte *)GlobalLock(hBuffer))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { L_GetBitmapRow(bh, pBuffer, y, bh->BytesPerLine); ip = TempBitmap->GetScanLine(y); memcpy(ip, pBuffer, 3*bh->Width); TempBitmap->PutScanLine(y); } TempBitmap->StopScanLine(); GlobalUnlock(hBuffer); pBuffer = NULL; GlobalFree(hBuffer); hBuffer = NULL; L_ReleaseBitmap(bh); return EC_NONE; fail: if (TempBitmap) { ::doDestroy(TempMask); if (hBuffer) { if (pBuffer) GlobalUnlock(hBuffer); GlobalFree(hBuffer); } delete TempBitmap; TempBitmap = NULL; } return ec; } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::Irregularrect(int bpp, HDC dcDst, TRect Src, TRect Dst) { TRect Msrc; RGBQUAD rgb[256]; TTexpiaBitmap *Mask = NULL; HDC dcSrc = NULL; if (iMainImage->Bitmap->BitsPerPixel==8) { if (bpp == 8) { Palette->ToRGBQUAD(rgb, 256); Mask = WorkArea->Mask; Mask->PutColors(0, 256, rgb); } else { Mask = new TTexpiaBitmap; if (!WorkArea->GetMask(Mask, 1)) goto fail; } } Msrc.Left = Src.Left-WorkArea->Range.left; Msrc.Right = Src.Right-WorkArea->Range.left; Msrc.Top = Src.Top-WorkArea->Range.top; Msrc.Bottom = Src.Bottom-WorkArea->Range.top; if ((dcSrc = Mask->CreateDC())==NULL) goto fail; SetStretchBltMode(dcDst, COLORONCOLOR); StretchBlt(dcDst, Dst.Left, Dst.Top, Dst.Right-Dst.Left, Dst.Bottom-Dst.Top, dcSrc, Msrc.Left, Msrc.Top, Msrc.Right-Msrc.Left, Msrc.Bottom-Msrc.Top, MERGEPAINT); Mask->DeleteDC(dcSrc); if (Mask != WorkArea->Mask) ::doDestroy(Mask); return true; fail: if (dcSrc) Mask->DeleteDC(dcSrc); if (Mask && Mask!=WorkArea->Mask) ::doDestroy(Mask); return false; } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::Repeat_Method(TTexpiaBitmap *Pattern, TSize r, TSize s, TRect Src, int len, int item) { int P; TRect Source, Dst; int x, y; HDC dcSrc = NULL, dcDst = NULL; Source = Src; if ((dcSrc = iMainImage->Bitmap->CreateDC()) == NULL) goto fail; if ((dcDst = Pattern->CreateDC()) == NULL) goto fail; SetStretchBltMode(dcDst, COLORONCOLOR); switch (item) { // 0: Normal, 1: Half Drop Horizontal, 2: Half Drop Vertical case 0: for (y=0; yMask) { if (!Irregularrect(Pattern->BitsPerPixel, dcDst, Src, Dst)) goto fail; } } } break; case 1: for (y=0; yMask) { if (!Irregularrect(Pattern->BitsPerPixel, dcDst, Src, Dst)) goto fail; } } if (Dst.RightWidth) { Dst.Left = Dst.Right; Dst.Right = Pattern->Width; Src.Left = Source.Left; Src.Right = P; StretchBlt(dcDst, Dst.Left, Dst.Top, (Dst.Right-Dst.Left), (Dst.Bottom-Dst.Top), dcSrc, Src.Left, Src.Top, (Src.Right-Src.Left), (Src.Bottom-Src.Top), SRCCOPY); if (WorkArea->Mask) { if (!Irregularrect(Pattern->BitsPerPixel, dcDst, Src, Dst)) goto fail; } } } break; case 2: for (x=0; xMask) { if (!Irregularrect(Pattern->BitsPerPixel, dcDst, Src, Dst)) goto fail; } } if (Dst.BottomHeight) { Dst.Top = Dst.Bottom; Dst.Bottom = Pattern->Height; Src.Top = Source.Top; Src.Bottom = P; StretchBlt(dcDst, Dst.Left, Dst.Top, (Dst.Right-Dst.Left), (Dst.Bottom-Dst.Top), dcSrc, Src.Left, Src.Top, (Src.Right-Src.Left), (Src.Bottom-Src.Top), SRCCOPY); if (WorkArea->Mask) { if (!Irregularrect(Pattern->BitsPerPixel, dcDst, Src, Dst)) goto fail; } } } break; } Pattern->DeleteDC(dcDst); iMainImage->Bitmap->DeleteDC(dcSrc); return true; fail: if (dcDst) Pattern->DeleteDC(dcDst); if (dcSrc) iMainImage->Bitmap->DeleteDC(dcSrc); return false; } //---------------------------------------------------------------------------- void __fastcall TMainImageForm::MosaicDraw8(TTexpiaBitmap *bm, int k, int m, int w, int h, int pi) { BYTE *p; TRect rect; int y, l; int mk = k*w; int mm = m*h; if (mk==0) mk = 1; if (mm==0) mm = 1; rect = Rect(mk-1, mm-1, (k+1)*w, (m+1)*h); bm->StartScanLine(); p = (BYTE *)bm->GetScanLine(rect.Top) + rect.Left; memset(p, 0, rect.Right-rect.Left); bm->PutScanLine(rect.Top); for (y=rect.Top+1; yGetScanLine(y) + rect.Left; *p = 0; p++; l = rect.Right-rect.Left-2; memset(p, pi, l); p += l; *p = 0; bm->PutScanLine(y); } p = (BYTE *)bm->GetScanLine(rect.Bottom-1) + rect.Left; memset(p, 0, rect.Right-rect.Left); bm->PutScanLine(rect.Bottom-1); bm->StopScanLine(); } //---------------------------------------------------------------------------- void __fastcall TMainImageForm::MosaicDraw24(TTexpiaBitmap *bm, int k, int m, int w, int h, RGBQUAD rgb) { BYTE *p; DWORD color = RGB(rgb.rgbRed, rgb.rgbGreen, rgb.rgbBlue); TRect rect; int y, l; int mk = k*w; int mm = m*h; if (mk==0) mk = 1; if (mm==0) mm = 1; rect = Rect(mk-1, mm-1, (k+1)*w, (m+1)*h); bm->StartScanLine(); p = (BYTE *)bm->GetScanLine(rect.Top) + 3*rect.Left; memset24(p, 0, rect.Right-rect.Left); bm->PutScanLine(rect.Top); for (y=rect.Top+1; yGetScanLine(y) + 3*rect.Left; SetPixel24(p, 0); p += 3; l = rect.Right-rect.Left-2; memset24(p, color, l); p += 3*l; SetPixel24(p, 0); bm->PutScanLine(y); } p = (BYTE *)bm->GetScanLine(rect.Bottom-1) + 3*rect.Left; memset24(p, 0, rect.Right-rect.Left); bm->PutScanLine(rect.Bottom-1); bm->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::LoadCarpetData(HANDLE FH) { int size, i, cnt; CTEXTURE *ct = NULL; DWORD dwRead; TPException ec=EC_NONE; if (!ReadFile(FH, &CarpetArea, sizeof(TCarpetArea), &dwRead, NULL)) goto fail; if (!ReadFile(FH, &cnt, sizeof(int), &dwRead, NULL)) goto fail; ClearData(); for (i = 0; i < cnt; i++) { ct = new CTEXTURE; if (!ct) goto fail; if (!ReadFile(FH, ct->name, 13, &dwRead, NULL)) goto fail; if (!ReadFile(FH, &ct->lx, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(FH, &ct->ly, sizeof(short), &dwRead, NULL)) goto fail; size = ct->lx * ct->ly; ct->map = new Byte[size]; if (!ct->map) { ec = EC_MEMORY_LACK; goto fail; } if (!ReadFile(FH, ct->map, size, &dwRead, NULL)) goto fail; CarpetTexture->Add(ct); } return; fail : if (ct) delete ct; if (ec == EC_NONE) ec = EC_FILE_NOT_READ; EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SaveCarpetData(HANDLE FH) { int size, i, cnt = CarpetTexture->Count; CTEXTURE *ct; DWORD dwWrite; if (!WriteFile(FH, &CarpetArea, sizeof(TCarpetArea), &dwWrite, NULL)) goto fail; if (!WriteFile(FH, &cnt, sizeof(int), &dwWrite, NULL)) goto fail; for (i = 0; i < cnt; i++) { ct = (CTEXTURE *) CarpetTexture->Items[i]; if (!WriteFile(FH, ct->name, 13, &dwWrite, NULL)) goto fail; if (!WriteFile(FH, &ct->lx, sizeof(short), &dwWrite, NULL)) goto fail; if (!WriteFile(FH, &ct->ly, sizeof(short), &dwWrite, NULL)) goto fail; size = ct->lx * ct->ly; if (!WriteFile(FH, ct->map, size, &dwWrite, NULL)) goto fail; } return; fail : EXCEPTION_MESSAGE_OK(EC_FILE_NOT_WRITE); } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::InitForm(TPCanvasInfor &ci, WORD bpp) { PALETTEENTRY peEntry[256]; RGBQUAD rgb[256]; if (Palette==NULL || WorkArea==NULL) return EC_MEMORY_LACK; Top = 0; Left = 0; if (!Palette->LoadFromFile((DirectoryColor+"\\Textile.fcr").c_str())) { GetSystemPaletteEntries(Canvas->Handle, 0, 256, peEntry); Palette->SetNormal(0, 0, 0, 0); Palette->SetNormal(1, 255, 255, 255); Palette->SetNormal(2, 0, 0, 0); for (int i=3; i<255; i++) { Palette->SetNormal(i, peEntry[i].peRed, peEntry[i].peGreen, peEntry[i].peBlue); } Palette->SetNormal(255, 255, 255, 255); } if (!ResizePattern(ci, bpp)) return EC_MEMORY_LACK; if (bpp==8) { Palette->ToRGBQUAD(rgb, 256); iMainImage->Bitmap->PutColors(0, 256, rgb); FileName = Format("Noname%d.tex", OPENARRAY(TVarRec, (Number+1))); MaskPixel = 0x0F; PaletteForm->SpeedButtonProtect->Enabled = true; } else { FileName = Format("Noname%d.tfc", OPENARRAY(TVarRec, (Number+1))); MaskPixel = 0x80; PaletteForm->SpeedButtonProtect->Enabled = false; } iMainImage->Bitmap->FillRect(Rect(0, 0, CanvasInfor.Width, CanvasInfor.Height), PaletteForm->DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel)); ClientWidth = MainForm->ClientWidth-267; ClientHeight = MainForm->ClientHeight-MainForm->StatusBar->Height -GetSystemMetrics(SM_CYSMCAPTION)-GetSystemMetrics(SM_CYMENU)+3; SetCaption(); iMainImage->SetPosition(0, 0); MainForm->UpdateMenuItems(NULL); PenManagerForm->SetColor(Palette); PenChange(); CarpetArea.IsArea = false; CarpetArea.Width = iMainImage->Bitmap->Width; CarpetArea.Height = iMainImage->Bitmap->Height; return EC_NONE; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::InitFormFile(AnsiString dn, AnsiString fn, TGraphicFileFormat ExtIndex, WORD bpp) { HANDLE hFile = INVALID_HANDLE_VALUE; int pw, ph, sw, sh, x, y; RGBQUAD rgb[256]; TTexpiaBitmap *tb = NULL; TPCanvasInfor ci; Byte c[256], *bp, *sp, *dp; TEXPIAFILEHEADER tpfh; TPException ec = EC_NONE; if (Palette==NULL || WorkArea==NULL) return false; Top = 0; Left = 0; sw = MainForm->ClientWidth-267; sh = MainForm->ClientHeight-MainForm->StatusBar->Height -GetSystemMetrics(SM_CYSMCAPTION)-GetSystemMetrics(SM_CYMENU)+3; if ((tb = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (ExtIndex==gffT3D) { if ((hFile = CreateFile(FullPathName(dn, fn).c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, Palette, tpfh, tb)) != EC_NONE) goto fail; ci = tpfh.CanvasInfor; if (!ResizePattern(ci, 24)) { ec = EC_MEMORY_LACK; goto fail; } MaskPixel = 0x80; if (!iMainImage->Bitmap->Copy(tb, SRCCOPY)) { ec = EC_RESOURCE_LACK; goto fail; } pw = iMainImage->Bitmap->Width+PanelVert->Width; ph = iMainImage->Bitmap->Height+PanelHorz->Height; if (sbRuler->Down) { pw += Ruler->Thick; ph += Ruler->Thick; } if (pwSetPosition(0, 0); MainForm->UpdateMenuItems(NULL); PenManagerForm->SetColor(Palette); PenChange(); if (Data3D) delete Data3D; if ((Data3D = new TData3D) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = MainMenuForm->LoadFrom3DFile(hFile, tpfh, tb)) != EC_NONE) goto fail; CloseHandle(hFile); if (iMainImage->Mask) MaskArea = true; } else { if (ExtIndex == gffCPT) { if ((ec = LoadFromCarpetFile(fn, tb, Palette, ci)) != EC_NONE) goto fail; } else { if ((ec = LoadFromFile(fn, ExtIndex, tb, Palette, ci)) != EC_NONE) goto fail; } if (!ResizePattern(ci, bpp)) { ec = EC_MEMORY_LACK; goto fail; } if (bpp==8) { if (tb->BitsPerPixel==8) { Palette->ToRGBQUAD(rgb, 256); iMainImage->Bitmap->PutColors(0, 256, rgb); if (!iMainImage->Bitmap->Copy(tb, SRCCOPY)) { ec = EC_RESOURCE_LACK; goto fail; } } else { tb->ColorResolution(8, CRF_OPTIMIZEDPALETTE, NULL, 250); tb->GetColors(0, 256, rgb); Palette->SetNormal(0, 0, 0, 0); for (x=0; x<250; x++) { Palette->SetNormal(x+2, rgb[x].rgbRed, rgb[x].rgbGreen, rgb[x].rgbBlue); } Palette->SetNormal(255, 255, 255, 255); Palette->ToRGBQUAD(rgb, 256); iMainImage->Bitmap->PutColors(0, 256, rgb); memset(c, 0, 256); if (!tb->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { sp = tb->GetScanLine(y); dp = iMainImage->Bitmap->GetScanLine(y); for (x=0; xWidth; x++, sp++, dp++) { *dp = *sp+2; c[*dp] = 1; } iMainImage->Bitmap->PutScanLine(y); } tb->StopScanLine(); iMainImage->Bitmap->StopScanLine(); for (x=251; x>=1; x--) { if (c[x]==1) { Palette->UseColor = x; break; } } } MaskPixel = 0x0F; } else { if (!iMainImage->Bitmap->Copy(tb, SRCCOPY)) { ec = EC_RESOURCE_LACK; goto fail; } MaskPixel = 0x80; } pw = iMainImage->Bitmap->Width+PanelVert->Width; ph = iMainImage->Bitmap->Height+PanelHorz->Height; if (sbRuler->Down) { pw += Ruler->Thick; ph += Ruler->Thick; } if (pwSetPosition(0, 0); MainForm->UpdateMenuItems(NULL); PenManagerForm->SetColor(Palette); PenChange(); PaletteForm->DIB256Palette->ChoiceIndex = 2; CarpetArea.IsArea = false; CarpetArea.Width = iMainImage->Bitmap->Width; CarpetArea.Height = iMainImage->Bitmap->Height; } delete tb; return EC_NONE; fail: if (tb) delete tb; if (ExtIndex==gffT3D) { ::doDestroy(Data3D); if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); } return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ResizeCanvas(short dpi, int w, int h) { RGNXFORM XForm; HRGN rgn; double rx, ry; rx = (double)w/iMainImage->Bitmap->Width; ry = (double)h/iMainImage->Bitmap->Height; iMainImage->Bitmap->ResizeStretch(w, h); if (iMainImage->Mask) iMainImage->Mask->ResizeStretch(w, h); AllocLineMem(h); CanvasInfor.DotsPerInch = dpi; CanvasInfor.SetExtFileOption(); CanvasInfor.SetSize(cstFree, w, h); BITMAPHANDLE *bh = iMainImage->Bitmap->Handle; if (L_BitmapHasRgn(bh)) { XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_GetBitmapRgnHandle(bh, &XForm, &rgn); WorkArea->SetMask(rgn); DeleteObject(rgn); } if (Data3D) { int btn = MessageDlg(IDS_MESSAGE_NEWMODEL, mtInformation, TMsgDlgButtons()<Source->Create(iMainImage->Bitmap->Width, iMainImage->Bitmap->Height, 24)) { iMainImage->Bitmap->ConvertColorSpace(csHLS); Data3D->Source->Copy(iMainImage->Bitmap, SRCCOPY); iMainImage->Bitmap->ConvertColorSpace(csRGB); } else { EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return; } } else { Data3D->Source->ResizeStretch(iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); } Data3D->Resize(rx, ry); Data3D->waStart.x = Data3D->waStart.x*rx+0.5; Data3D->waStart.y = Data3D->waStart.y*ry+0.5; Data3D->waSize.x = Data3D->waSize.x*rx+0.5; Data3D->waSize.y = Data3D->waSize.y*ry+0.5; } UpdateImage(); ::RepaintColor(); ReviewStatusBar(); Modify = false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::EnlargeCanvas(int w, int h) { BITMAPHANDLE *bh = iMainImage->Bitmap->Handle; RGNXFORM XForm; HRGN rgn; if (Data3D) { POINT max = Data3D->MaxGridPoint(); if (w < max.x || h < max.y) { MessageDlg(IDS_MESSAGE_INPUTVALUE, mtInformation, TMsgDlgButtons()<DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel); CanvasInfor.SetSize(cstFree, w, h); iMainImage->Bitmap->Resize(w, h, bc); if (L_BitmapHasRgn(bh)) { XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_GetBitmapRgnHandle(bh, &XForm, &rgn); WorkArea->SetMask(rgn); DeleteObject(rgn); } if (Data3D) { if (iMainImage->Mask) { iMainImage->Mask->Resize(w, h, clWhite); } int btn = MessageDlg(IDS_MESSAGE_NEWMODEL, mtInformation, TMsgDlgButtons()<Source->Create(iMainImage->Bitmap->Width, iMainImage->Bitmap->Height, 24)) { iMainImage->Bitmap->ConvertColorSpace(csHLS); Data3D->Source->Copy(iMainImage->Bitmap, SRCCOPY); iMainImage->Bitmap->ConvertColorSpace(csRGB); } else {EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return;} } else { Data3D->Source->Resize(iMainImage->Bitmap->Width, iMainImage->Bitmap->Height, bc); } } else { if (iMainImage->Mask) { iMainImage->Mask->Resize(w, h, 0); } } UpdateImage(); ::RepaintColor(); AllocLineMem(h); ReviewStatusBar(); Modify = false; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::ResizePattern(TPCanvasInfor &pi, int bpp) { if (pi.SizeType!=cstFree) { pi.Width = pi.GetWidth(); pi.Height = pi.GetHeight(); } CanvasInfor = pi; CanvasInfor.SetExtFileOption(); Ruler->DPI = CanvasInfor.DotsPerInch; if (!iMainImage->Bitmap->Create(CanvasInfor.Width, CanvasInfor.Height, bpp)) return false; if (!AllocLineMem(CanvasInfor.Height)) return false; ReviewStatusBar(); return true; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::InitMerge(AnsiString FullFileName, TGraphicFileFormat Index) { int i, x, y, bg, UseColor; TPCanvasInfor ci; TRect r; RGBQUAD rgb[256]; AnsiString FileName; Byte *pp, *mp, mm; bool undoSw = false; TPalette *TempPalette = NULL; COLORREF bgc, c; TPException ec = EC_NONE; r = Rect(0, 0, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); if ((undoSw = UndoSave(UK_ALL, r)) == false) goto fail; if ((TempPalette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; goto fail; } switch (FullViewForm->Super) { case sOff: // TempBitmap = NULL; if ((ec = LoadFromFile(FullFileName, Index, iSelectImage->Bitmap, TempPalette, ci))!=EC_NONE) goto fail; if (iSelectImage->Bitmap->Width>iMainImage->Bitmap->Width || iSelectImage->Bitmap->Height>iMainImage->Bitmap->Height) { ec = EC_BIG_SIZE; goto fail; } if (iMainImage->Bitmap->BitsPerPixel==8) { if (iSelectImage->Bitmap->BitsPerPixel!=8) { ec = EC_COLOR_OVERFLOW; goto fail; } bg = 0; if (!iSelectImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->Height; y++) { pp = iSelectImage->Bitmap->GetScanLine(y); for (x=0; xBitmap->Width; x++) { if (*(pp+x)==1) { bg = 1; goto next1; } } iSelectImage->Bitmap->PutScanLine(y); } next1: iSelectImage->Bitmap->StopScanLine(); if (Palette->UseColor+TempPalette->UseColor-2+bg>=252) { ec = EC_COLOR_OVERFLOW; goto fail; } // TempMask = NULL; UseColor = Palette->UseColor-1+bg; if (!iSelectImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->Height; y++) { pp = iSelectImage->Bitmap->GetScanLine(y); for (x=0; xBitmap->Width; x++) { *(pp+x) += UseColor; } iSelectImage->Bitmap->PutScanLine(y); } iSelectImage->Bitmap->StopScanLine(); for (i=2-bg; i<=TempPalette->UseColor; i++) { Palette->ColorData[UseColor+i] = TempPalette->ColorData[i]; } Palette->UseColor = UseColor+TempPalette->UseColor; Palette->ToRGBQUAD(rgb, 256); iSelectImage->Bitmap->PutColors(0, 256, rgb); } else { // TempMask = NULL; } break; case sOverlap: case sNormal: case sGauze: if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = LoadFromFile(FullFileName, Index, TempBitmap, TempPalette, ci))!=EC_NONE) goto fail; if (TempBitmap->Width>iMainImage->Bitmap->Width || TempBitmap->Height>iMainImage->Bitmap->Height) { ec = EC_BIG_SIZE; goto fail; } if (iMainImage->Bitmap->BitsPerPixel==8) { if (TempBitmap->BitsPerPixel!=8) { ec = EC_COLOR_OVERFLOW; goto fail; } if (Palette->UseColor+TempPalette->UseColor-2>=252) { ec = EC_COLOR_OVERFLOW; goto fail; } if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8)) { ec = EC_MEMORY_LACK; goto fail; } UseColor = Palette->UseColor-1; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, pp++, mp++) { if (*pp<2) { *pp = 0; *mp = 0xFF; } else { *pp += UseColor; *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); for (i=2; i<=TempPalette->UseColor; i++) { Palette->ColorData[UseColor+i] = TempPalette->ColorData[i]; } Palette->UseColor = UseColor+TempPalette->UseColor; Palette->ToRGBQUAD(rgb, 256); TempBitmap->PutColors(0, 256, rgb); TempMask->PutColors(0, 256, rgb); if (!iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } } else { if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 1)) { ec = EC_MEMORY_LACK; goto fail; } if (TempBitmap->BitsPerPixel==8) { if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); *mp = 0; mm = 0x80; x = 0; while(1) { if (*pp<2) { *pp = 0; *mp |= mm; } x++; if (x >= TempBitmap->Width) break; pp++; if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } /* for (x=0; xWidth; x++, pp++) { if (*pp<2) { *pp = 0; *mp |= mm; } if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } */ TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); } else { bgc = TempPalette->Color[1]; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); *mp = 0; mm = 0x80; x = 0; while(1) { GetPixel24(pp, c); if (c==bgc) { SetPixel24(pp, 0); *mp |= mm; } x++; if (x >= TempBitmap->Width) break; pp += 3; if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } /* for (x=0; xWidth; x++, pp+=3) { GetPixel24(pp, c); if (c==bgc) { SetPixel24(pp, 0); *mp |= mm; } if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } */ TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); } if (!iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 24)) { ec = EC_MEMORY_LACK; goto fail; } } break; /* case sGauze: if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = LoadFromFile(FullFileName, Index, TempBitmap, TempPalette, ci))!=EC_NONE) goto fail; if (TempBitmap->Width>iMainImage->Bitmap->Width || TempBitmap->Height>iMainImage->Bitmap->Height) { ec = EC_BIG_SIZE; goto fail; } if (iMainImage->Bitmap->BitsPerPixel==8) { if (TempBitmap->BitsPerPixel!=8) { ec = EC_COLOR_OVERFLOW; goto fail; } bg = 0; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); for (x=0; xWidth; x++) { if (*(pp+x)==1) { bg = 1; goto next2; } } TempBitmap->PutScanLine(y); } next2: TempBitmap->StopScanLine(); if (Palette->UseColor+TempPalette->UseColor-2+bg>=252) { ec = EC_COLOR_OVERFLOW; goto fail; } if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8)) { ec = EC_MEMORY_LACK; goto fail; } UseColor = Palette->UseColor-1+bg; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, pp++, mp++) { if (*pp > 1) { if ((x+y)&1) { *pp = 0; *mp = 0xFF; } else { *pp += UseColor; *mp = 0; } } else { *pp = 0; *mp = 0xFF; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); for (i=2-bg; i<=TempPalette->UseColor; i++) { Palette->ColorData[UseColor+i] = TempPalette->ColorData[i]; } Palette->UseColor = UseColor+TempPalette->UseColor; Palette->ToRGBQUAD(rgb, 256); TempBitmap->PutColors(0, 256, rgb); TempMask->PutColors(0, 256, rgb); if (!iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } } else { if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 1)) { ec = EC_MEMORY_LACK; goto fail; } if (TempBitmap->BitsPerPixel==8) { if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); *mp = 0; mm = 0x80; for (x=0; xWidth; x++, pp++) { if (*pp < 2 || (x+y)&1) { *pp = 0; *mp |= mm; } if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); } else { bgc = TempPalette->Color[1]; if (!TempBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); *mp = 0; mm = 0x80; for (x=0; xWidth; x++, pp+=3) { GetPixel24(pp, c); if ((c==bgc) || (x&1)==(y&1)) { SetPixel24(pp, 0); *mp |= mm; } if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); } if (!iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 24)) { ec = EC_MEMORY_LACK; goto fail; } } break; */ } PenManagerForm->SetColor(Palette); Center.x = iSelectImage->Bitmap->Width/2; Center.y = iSelectImage->Bitmap->Height/2; iSelectImageSize(); iSelectImage->Visible = true; iSelectImage->Repaint(); MainMenuForm->Item = T_MERGE; MainMenuForm->SubItem = 0; ::RepaintColor(); delete TempPalette; return true; fail: if (TempPalette) { if (TempBitmap) { ::doDestroy(TempMask); delete TempBitmap; TempBitmap = NULL; } delete TempPalette; } ExitMerge(); if (undoSw == true) Undo->RemoveLast(); EXCEPTION_MESSAGE_OK(ec); return false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ExitMerge() { iSelectImage->Bitmap->Destroy(); iSelectImage->Width = 0; iSelectImage->Height = 0; ::doDestroy(TempBitmap); ::doDestroy(TempMask); } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::SaveToFile(AnsiString dn, AnsiString fn, TGraphicFileFormat Index, TCompressMethod cm) { HANDLE hFile = INVALID_HANDLE_VALUE; TEXPIAFILEHEADER tpfh; TRect src; RGBQUAD rgb[256]; TTexpiaBitmap *tag = NULL, *tb = NULL; DWORD dwWrite; WORD bpp; TPException ec = EC_NONE; if (Index == gffTEX || Index == gffTFC) { if ((hFile = CreateFile(FullPathName(dn, fn).c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 222); tpfh.CanvasInfor = CanvasInfor; tpfh.BitsPerPixel = iMainImage->Bitmap->BitsPerPixel; tpfh.Compress = cm; if (WorkArea->Mask) { src = WorkArea->Range; tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.Right-src.Left, src.Bottom-src.Top); } else { src.Left = 0; src.Top = 0; src.Right = iMainImage->Bitmap->Width; src.Bottom = iMainImage->Bitmap->Height; } if ((tag = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } MakeTexpiaTag(tag, iMainImage->Bitmap, src, 0); if (WorkArea && WorkArea->Mask) { if (!SaveToTexpiaFile(hFile, Palette, tpfh, tag, iMainImage->Bitmap, &WorkArea->Range)) goto fail; } else { if (!SaveToTexpiaFile(hFile, Palette, tpfh, tag, iMainImage->Bitmap)) goto fail; } CloseHandle(hFile); delete tag; DirName = dn; FileName = fn; } else if (Index == gffT3D) { if ((hFile = CreateFile(FullPathName(dn, fn).c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 223); tpfh.CanvasInfor = CanvasInfor; tpfh.BitsPerPixel = 24; tpfh.Compress = cm; src.Left = 0; src.Top = 0; src.Right = iMainImage->Bitmap->Width; src.Bottom = iMainImage->Bitmap->Height; if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = MainMenuForm->SaveTo3DFile(hFile, tpfh, tag, iMainImage->Bitmap)) != EC_NONE) goto fail; CloseHandle(hFile); delete tag; DirName = dn; FileName = fn; } else if (Index == gffCPT) { SaveToCarpetFile(dn, fn, cm); DirName = dn; FileName = fn; } else { if (WorkArea->Mask) { src = WorkArea->Range; } else { src.Left = 0; src.Top = 0; src.Right = iMainImage->Bitmap->Width; src.Bottom = iMainImage->Bitmap->Height; } if ((tb = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!tb->Create(src.Right-src.Left, src.Bottom-src.Top, iMainImage->Bitmap->BitsPerPixel)) { ec = EC_MEMORY_LACK; goto fail; } if (tb->BitsPerPixel==8) { Palette->ToRGBQUAD(rgb, 256); tb->PutColors(0, 256, rgb); } if (!tb->CopyFromRect(iMainImage->Bitmap, src.Left, src.Top, SRCCOPY)) { ec = EC_MEMORY_LACK; goto fail; } switch (Index) { case gffBMP: if (!tb->SaveToFile(fn, FILE_BMP)) goto fail; break; case gffTIF: if (!tb->SaveToFile(fn, FILE_TIF)) goto fail; break; case gffPCT: if (!tb->SaveToFile(fn, FILE_PCT)) goto fail; break; case gffPCX: if (!tb->SaveToFile(fn, FILE_PCX)) goto fail; break; case gffPNG: if (!tb->SaveToFile(fn, FILE_PNG)) goto fail; break; case gffPSD: if (!tb->SaveToFile(fn, FILE_PSD)) goto fail; break; case gffRAS: if (!tb->SaveToFile(fn, FILE_RAS)) goto fail; break; case gffTGA: if (!tb->SaveToFile(fn, FILE_TGA)) goto fail; break; default: goto fail; } DirName = ""; if (iMainImage->Bitmap->BitsPerPixel == 8) { StrMove(StrPos(fn.c_str(), "."), ".tex", 4); } else { StrMove(StrPos(fn.c_str(), "."), ".tfc", 4); } FileName = fn; delete tb; } SetCaption(); return EC_NONE; fail: if (tb) delete tb; if (tag) delete tag; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iSelectImageSize() { TPoint Size; iSelectImage->SetPosition(0, 0); Size.x = Panel->Width*iSelectImage->ZoomOut/iSelectImage->ZoomIn; // if (iSelectImage->Bitmap->Width>Size.x) { // iSelectImage->Width = Panel->Width; // } else { iSelectImage->Width = iSelectImage->Bitmap->Width*iSelectImage->ZoomIn/iSelectImage->ZoomOut; // } Size.y = Panel->Height*iSelectImage->ZoomOut/iSelectImage->ZoomIn; // if (iSelectImage->Bitmap->Height>Size.y) { // iSelectImage->Height = Panel->Height; // } else { iSelectImage->Height = iSelectImage->Bitmap->Height*iSelectImage->ZoomIn/iSelectImage->ZoomOut; // } iSelectImage->Left = 0; iSelectImage->Top = 0; } //--------------------------------------------------------------------------- POINT __fastcall TMainImageForm::iSelectImageConvert(int X, int Y) { POINT p; // if (iSelectImage->Width==Panel->Width) { // p.x = iMainImage->PositionX; // } else { p.x = iMainImage->CanvasToBitmapX(iSelectImage->Left+X)-Center.x; // } // if (iSelectImage->Height==Panel->Height) { // p.y = iMainImage->PositionY; // } else { p.y = iMainImage->CanvasToBitmapY(iSelectImage->Top+Y)-Center.y; // } return p; } //--------------------------------------------------------------------------- POINT __fastcall TMainImageForm::iSelectImagePosition(POINT p) { TRect dst; if (p.x<0) p.x = 0; else if (p.x>iMainImage->Bitmap->Width-iSelectImage->Bitmap->Width) p.x = iMainImage->Bitmap->Width-iSelectImage->Bitmap->Width; // if (iSelectImage->Width==Panel->Width) { // iSelectImage->Left = 0; // iSelectImage->PositionX = iMainImage->PositionX-p.x; // } else { iSelectImage->Left = iMainImage->BitmapToCanvasX(p.x); iSelectImage->PositionX = 0; // } if (p.y<0) p.y = 0; else if (p.y>iMainImage->Bitmap->Height-iSelectImage->Bitmap->Height) p.y = iMainImage->Bitmap->Height-iSelectImage->Bitmap->Height; // if (iSelectImage->Height==Panel->Height) { // iSelectImage->Top = 0; // iSelectImage->PositionY = iMainImage->PositionY-p.y; // } else { iSelectImage->Top = iMainImage->BitmapToCanvasY(p.y); iSelectImage->PositionY = 0; // } return p; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::IsMerge(POINT p) { HDC dcSrc, dcDst; int w, h, x, y, i; Byte *DP, *TB, *TM, *PP, mm; COLORREF bgc, tc, pc; RGBQUAD rgb[256]; if (TempBitmap) { w = iSelectImage->Bitmap->Width; h = iSelectImage->Bitmap->Height; if (TempMask) { if (FullViewForm->Super == sGauze) { if (TempBitmap->StartScanLine() == false) goto fail; if (TempMask->StartScanLine() == false) goto fail; if (iMainImage->Bitmap->StartScanLine() == false) goto fail; if (iSelectImage->Bitmap->StartScanLine() == false) goto fail; if (iMainImage->Bitmap->BitsPerPixel == 8) { for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); TM = TempMask->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + p.x; for (x = 0; x < w; x++, PP++, DP++, TB++, TM++) { if (*TM == 0) { if (*PP > 1) { if ((x+y) & 1) *DP = *PP; else *DP = *TB; } else { *DP = *TB; } } else { *DP = *PP; } } iSelectImage->Bitmap->PutScanLine(y); } } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (TempBitmap->BitsPerPixel == 8) { TempBitmap->GetColors(0, 256, rgb); if (TempMask->BitsPerPixel == 8) { for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); TM = TempMask->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + 3*p.x; for (x = 0; x < w; x++, PP+=3, DP+=3, TM++, TB++) { if (*TM == 0) { GetPixel24(PP, pc); tc = RGBToTColor(rgb[*TB]); if (pc != bgc) { if ((x+y) & 1) { CopyPixel24(DP, PP); } else { SetPixel24(DP, tc); } } else { SetPixel24(DP, tc); } } else { CopyPixel24(DP, PP); } } iSelectImage->Bitmap->PutScanLine(y); } } else { for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); TM = TempMask->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + 3*p.x; mm = 0x80; for (x = 0; x < w; x++, PP+=3, DP+=3, TB++) { if ((*TM & mm) == 0) { GetPixel24(PP, pc); tc = RGBToTColor(rgb[*TB]); if (pc != bgc) { if ((x+y) & 1) { CopyPixel24(DP, PP); } else { SetPixel24(DP, tc); } } else { SetPixel24(DP, tc); } } else { CopyPixel24(DP, PP); } if (mm == 1) { TM++; mm = 0x80; } else mm >>= 1; } iSelectImage->Bitmap->PutScanLine(y); } } } else { for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); TM = TempMask->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + 3*p.x; mm = 0x80; for (x = 0; x < w; x++, PP+=3, DP+=3, TB+=3) { if ((*TM & mm) == 0) { GetPixel24(PP, pc); if (pc != bgc) { if ((x+y) & 1) { CopyPixel24(DP, PP); } else { CopyPixel24(DP, TB); } } else { CopyPixel24(DP, TB); } } else { CopyPixel24(DP, PP); } if (mm == 1) { TM++; mm = 0x80; } else mm >>= 1; } iSelectImage->Bitmap->PutScanLine(y); } } } iSelectImage->Bitmap->StopScanLine(); iMainImage->Bitmap->StopScanLine(); TempMask->StopScanLine(); TempBitmap->StopScanLine(); } else { dcDst = iSelectImage->Bitmap->CreateDC(); if (dcDst) { dcSrc = iMainImage->Bitmap->CreateDC(); if (dcSrc) { BitBlt(dcDst, 0, 0, w, h, dcSrc, p.x, p.y, SRCCOPY); iMainImage->Bitmap->DeleteDC(dcSrc); } dcSrc = TempMask->CreateDC(); if (dcSrc) { BitBlt(dcDst, 0, 0, w, h, dcSrc, 0, 0, SRCAND); TempMask->DeleteDC(dcSrc); } dcSrc = TempBitmap->CreateDC(); if (dcSrc) { BitBlt(dcDst, 0, 0, w, h, dcSrc, 0, 0, SRCPAINT); TempBitmap->DeleteDC(dcSrc); } iSelectImage->Bitmap->DeleteDC(dcDst); } } } else { if (FullViewForm->Super == sGauze) { if (TempBitmap->StartScanLine() == false) goto fail; if (iMainImage->Bitmap->StartScanLine() == false) goto fail; if (iSelectImage->Bitmap->StartScanLine() == false) goto fail; if (iMainImage->Bitmap->BitsPerPixel == 8) { for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + p.x; for (x = 0; x < w; x++, PP++, DP++, TB++, TM++) { if (*PP > 1) { if ((x+y) & 1) *DP = *PP; else *DP = *TB; } else { *DP = *TB; } } iSelectImage->Bitmap->PutScanLine(y); } } else { bgc = PaletteForm->DIB256Palette->GetBGCOLORREF(24); if (TempBitmap->BitsPerPixel == 8) { TempBitmap->GetColors(0, 256, rgb); for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + 3*p.x; for (x = 0; x < w; x++, PP+=3, DP+=3, TM++, TB++) { GetPixel24(PP, pc); tc = RGBToTColor(rgb[*TB]); if (pc != bgc) { if ((x+y) & 1) { CopyPixel24(DP, PP); } else { SetPixel24(DP, tc); } } else { SetPixel24(DP, tc); } } iSelectImage->Bitmap->PutScanLine(y); } } else { for (y = 0; y < h; y++) { TB = TempBitmap->GetScanLine(y); DP = iSelectImage->Bitmap->GetScanLine(y); PP = iMainImage->Bitmap->GetScanLine(y + p.y) + 3*p.x; for (x = 0; x < w; x++, PP+=3, DP+=3, TB+=3) { GetPixel24(PP, pc); if (pc != bgc) { if ((x+y) & 1) { CopyPixel24(DP, PP); } else { CopyPixel24(DP, TB); } } else { CopyPixel24(DP, TB); } } iSelectImage->Bitmap->PutScanLine(y); } } } iSelectImage->Bitmap->StopScanLine(); iMainImage->Bitmap->StopScanLine(); TempBitmap->StopScanLine(); } else { iSelectImage->Bitmap->Copy(TempBitmap, SRCCOPY); } } iMainImage->Update(); } return; fail: iSelectImage->Bitmap->StopScanLine(); iMainImage->Bitmap->StopScanLine(); TempMask->StopScanLine(); TempBitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- AnsiString __fastcall TMainImageForm::UnitName(TUnit unit) { if (unit==uDot) return "Dot"; else if (unit==uInch) return "Inch"; else if (unit==uCm) return "Cm"; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::UnitChange(TUnit unit) { CurrentUnit = unit; Ruler->AUnit = CurrentUnit; if (CurrentUnit==uDot) sbUnit->Caption = AnsiString(IDS_UNIT) + " : Dot"; else if (CurrentUnit==uInch) sbUnit->Caption = AnsiString(IDS_UNIT) + " : Inch"; else if (CurrentUnit==uCm) sbUnit->Caption = AnsiString(IDS_UNIT) + " : Cm"; FullViewForm->UnitChange(); MainMenuForm->UnitChange(); ReviewStatusBar(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomChange(int zi, int zo, POINT *ptScreen) { POINT ptClient; AnsiString sbZoom; if (zi!=iMainImage->ZoomIn || zo!=iMainImage->ZoomOut) { iMainImageChange(); if (ptScreen) { ptClient = iMainImage->ScreenToClient(*ptScreen); iMainImage->SetZoom(zi, zo, &ptClient); } else { iMainImage->SetZoom(zi, zo); } Ruler->Zoom = (double)zi/zo; FullViewForm->SetZoom(); switch (MainMenuForm->Item) { case T_MERGE: //case T_FILL: // case T_REPRO: case T_STYLE: case T_STRIPE: //case T_MOVECOPY: iSelectImageSize(); } } ShowZoomText(); /* switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: sbZoom = "Zoom : 1"; break; case 2: sbZoom = "Zoom : 1/2"; break; case 4: sbZoom = "Zoom : 1/4"; break; case 8: sbZoom = "Zoom : 1/8"; break; case 16: sbZoom = "Zoom : 1/16"; break; } break; case 2: sbZoom = "Zoom : 2"; break; case 4: sbZoom = "Zoom : 4"; break; case 8: sbZoom = "Zoom : 8"; break; case 16: sbZoom = "Zoom : 16"; break; } MainForm->StatusBar->Panels->Items[StatusBarZoom]->Text = sbZoom; */ } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ShowZoomText() { AnsiString sbZoom; switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: sbZoom = "Zoom : 1"; break; case 2: sbZoom = "Zoom : 1/2"; break; case 4: sbZoom = "Zoom : 1/4"; break; case 8: sbZoom = "Zoom : 1/8"; break; case 16: sbZoom = "Zoom : 1/16"; break; } break; case 2: sbZoom = "Zoom : 2"; break; case 4: sbZoom = "Zoom : 4"; break; case 8: sbZoom = "Zoom : 8"; break; case 16: sbZoom = "Zoom : 16"; break; } MainForm->StatusBar->Panels->Items[StatusBarZoom]->Text = sbZoom; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomChangeIn(POINT ptScreen) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(2, 1, &ptScreen); break; case 2: ZoomChange(1, 1, &ptScreen); break; case 4: ZoomChange(1, 2, &ptScreen); break; case 8: ZoomChange(1, 4, &ptScreen); break; case 16: ZoomChange(1, 8, &ptScreen); break; } break; case 2: ZoomChange(4, 1, &ptScreen); break; case 4: ZoomChange(8, 1, &ptScreen); break; case 8: ZoomChange(16, 1, &ptScreen); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ZoomChangeOut(POINT ptScreen) { switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: ZoomChange(1, 2, &ptScreen); break; case 2: ZoomChange(1, 4, &ptScreen); break; case 4: ZoomChange(1, 8, &ptScreen); break; case 8: ZoomChange(1, 16, &ptScreen); break; } break; case 2: ZoomChange(1, 1, &ptScreen); break; case 4: ZoomChange(2, 1, &ptScreen); break; case 8: ZoomChange(4, 1, &ptScreen); break; case 16: ZoomChange(8, 1, &ptScreen); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::set_hline(int x, int y, int len, COLORREF c) { if (x >= iMainImage->Bitmap->Width || y < 0 || y >= iMainImage->Bitmap->Height) return; if (x < 0) { len += x; x = 0; if (len <= 0) return; } if (x + len > iMainImage->Bitmap->Width) len = iMainImage->Bitmap->Width-x; if (FOnSetHLine) FOnSetHLine(x, y, len, c); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetHLine8ColorNo(int x, int y, int len, COLORREF c) { Byte *bp, *mp; bp = iMainImage->Bitmap->GetScanLine(y); if (bMaskArea) { mp = iMainImage->Mask->GetScanLine(y); if (bProtect) { for (int i = 0; i < len; i++) { if ((Palette->ColorData[bp[x + i]]->Protect == 0) && (mp[x + i] == 0)) bp[x + i] = c; } } else { for (int i = 0; i < len; i++) { if (mp[x + i] == 0) bp[x + i] = c; } } } else { if (bProtect) { for (int i = 0; i < len; i++) { if (Palette->ColorData[bp[x + i]]->Protect == 0) bp[x + i] = c; } } else { memset(bp+x, c, len); } } iMainImage->Bitmap->PutScanLine(y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetHLine8ColorYes(int x, int y, int len, COLORREF c) { Byte *bp, *mp; bp = iMainImage->Bitmap->GetScanLine(y); if (bMaskArea) { mp = iMainImage->Mask->GetScanLine(y); if (bProtect) { for (int i = 0; i < len; i++) { if ((Palette->ColorData[bp[x + i]]->Protect == 0) && (mp[x + i] == 0) && (PenManagerForm->Selector->Number[bp[x + i]] != 255)) bp[x + i] = c; } } else { for (int i = 0; i < len; i++) { if ((mp[x + i] == 0) && (PenManagerForm->Selector->Number[bp[x + i]] != 255)) bp[x + i] = c; } } } else { if (bProtect) { for (int i = 0; i < len; i++) { if ((Palette->ColorData[bp[x + i]]->Protect == 0) && (PenManagerForm->Selector->Number[bp[x + i]] != 255)) bp[x + i] = c; } } else { for (int i = 0; i < len; i++) { if (PenManagerForm->Selector->Number[bp[x + i]] != 255) bp[x + i] = c; } } } iMainImage->Bitmap->PutScanLine(y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetHLine24(int x, int y, int len, COLORREF c) { Byte *bp, *mp; bp = iMainImage->Bitmap->GetScanLine(y); if (bMaskArea) { mp = iMainImage->Mask->GetScanLine(y); for (int i = x; i < x + len; i++, bp += 3) { if ((mp[i >> 3] & (0x80 >> (i & 7))) == 0) memset24(bp + 3 * x, c, 1); } } else memset24(bp+3*x, c, len); iMainImage->Bitmap->PutScanLine(y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetHLineMask8(int x, int y, int len, COLORREF c) { Byte *bp; bp = iMainImage->Mask->GetScanLine(y); memset(bp + x, MaskPixel, len); iMainImage->Mask->PutScanLine(y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetHLineMask24(int x, int y, int len, COLORREF c) { Byte *bp; bp = iMainImage->Mask->GetScanLine(y); for (int i = x; i < x + len; i++) { bp[i >> 3] |= MaskPixel >> (i & 7); } iMainImage->Mask->PutScanLine(y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SetHLineMaskDelete24(int x, int y, int len, COLORREF c) { Byte *bp; bp = iMainImage->Mask->GetScanLine(y); for (int i = x; i < x + len; i++) { bp[i >> 3] &= ~(0x80 >> (i & 7)); } iMainImage->Mask->PutScanLine(y); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::dotted_pen(int x, int y, int cx, int cy, COLORREF c) { int i, PenType, ls, rs, len; double r, dx; PenType = PenManagerForm->Pen->Shape; len = PenManagerForm->Pen->Thick; r = len / 2.0; ls = (int) r; rs = len - ls; if (PenType) { if (cy > y) y = y - ls; if (cx < x) x = x - ls; for (i = y; i < y + len; i++) set_hline(x, i, len, c); } else { for (i = -ls; i < rs; i++) { dx = sqrt(r * r - i * i); set_hline(x - dx, y + i, 2 * dx, c); } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::line_pen(int sx, int sy, int ex, int ey, COLORREF c) { int PenType, dia, ls, rs, w, h, sw, y, x, r, yyy; double d, r1, r2, xx, yy; TLineData ld; RECT rect; PenType = PenManagerForm->Pen->Shape; dia = PenManagerForm->Pen->Thick; ls = dia>>1; rs = dia-ls; w = iMainImage->Bitmap->Width; h = iMainImage->Bitmap->Height; for (y=0; yh) ld.sy = h; if (ld.ey<0) ld.ey = 0; else if (ld.ey>h) ld.ey = h; r = PenType ? (ld.sx=0 && y=0 && y=0 && y=0 && y*(mex + y)) *(mex + y) = x; } } ld.sy -= ls; ld.ey += rs; if (!(iMainImage->Bitmap->StartScanLine())) goto fail; if (iMainImage->Mask) { if (!(iMainImage->Mask->StartScanLine())) goto fail; } for (y=ld.sy; y<=ld.ey; y++) { if (*(mex + y)>=0 && *(msx + y)Mask) iMainImage->Mask->StopScanLine(); iMainImage->Bitmap->StopScanLine(); if (MainMenuForm->Item!=T_DRAW) { if (MainMenuForm->Item!=T_STITCH) { rect.left = min(sx, ex)-ls; rect.top = min(sy, ey)-ls; rect.right = max(sx, ex)+rs; rect.bottom = max(sy, ey)+rs; iMainImage->RectPaint(rect); } } return; fail: iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageChange() { isDrawPenLocate = false; FullViewForm->iMainImageChange(); MainMenuForm->iMainImageChange(this); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::WorkAreaChange() { MainForm->UpdateMenuItems(NULL); PenManagerForm->WorkAreaChange(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::WorkAreaReset(bool bUndo) { MainImageForm->WorkArea->Reset(bUndo); MainForm->UpdateMenuItems(NULL); PenManagerForm->WorkAreaChange(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawPenLocate(int X, int Y) { HDC formDC = NULL; HBRUSH hOldBrush = NULL; HPEN hOldPen = NULL, hPen = NULL; int nDrawMode; int ls, rs, left, top, right, bottom, x, y; formDC = iMainImage->Canvas->Handle; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); hPen = CreatePen(PS_SOLID, 1, clWhite); if (hPen) { hOldPen = SelectObject(formDC, hPen); nDrawMode = GetROP2(formDC); SetROP2(formDC, R2_NOT); ls = PenManagerForm->Pen->BasicThick>>1; rs = PenManagerForm->Pen->BasicThick-ls; if (PenManagerForm->Pen->BasicThick*iMainImage->ZoomIn/iMainImage->ZoomOut>5) { left = iMainImage->BitmapToCanvasX(X-ls); top = iMainImage->BitmapToCanvasY(Y-ls); right = iMainImage->BitmapToCanvasX(X+rs)+1; bottom = iMainImage->BitmapToCanvasY(Y+rs)+1; if (PenManagerForm->Pen->Shape) Rectangle(formDC, left, top, right, bottom); else Ellipse(formDC, left, top, right, bottom); } x = iMainImage->BitmapToCanvasX(X); y = iMainImage->BitmapToCanvasY(Y); MoveToEx(formDC, x, y-15, NULL); LineTo(formDC, x, y+15); MoveToEx(formDC, x-15, y, NULL); LineTo(formDC, x+15, y); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); DeleteObject(hPen); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintLineLocate(TObject *Sender, HDC formDC) { // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; int NOL=NumberOfLine; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; POINT pt; POINT First; POINT Second; LineListData *line; for(int i=0;iItems[i]; First=line->First; Second=line->Second; pt.x = iMainImage->BitmapToCanvasX(First.x); pt.y = iMainImage->BitmapToCanvasY(First.y); MoveToEx(formDC, pt.x, pt.y, NULL); pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); LineTo(formDC, pt.x, pt.y); } SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::SearchWholeColor(TChoiceColor *ChoiceColor) { int x, y; Byte *bp; if (!iMainImage->Bitmap->StartScanLine()) return false; for (y=0; yBitmap->Height; y++) { bp = iMainImage->Bitmap->GetScanLine(y); for (x=0; xBitmap->Width; x++) { ChoiceColor->Add(Palette, *(bp+x)); } } iMainImage->Bitmap->StopScanLine(); return true; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::SearchWorkAreaColor(TChoiceColor *ChoiceColor) { Byte *mp, mm, *bp; int x, y; if (!WorkArea->Mask->StartScanLine()) goto fail; if (!iMainImage->Bitmap->StartScanLine()) goto fail; if (iMainImage->Bitmap->BitsPerPixel==8) { for (y=WorkArea->Range.top; yRange.bottom; y++) { bp = iMainImage->Bitmap->GetScanLine(y); mp = WorkArea->Mask->GetScanLine(y-WorkArea->Range.top); for (x=WorkArea->Range.left; xRange.right; x++, mp++) { if (*mp) { ChoiceColor->Add(Palette, *(bp+x)); } } } } else { for (y=WorkArea->Range.top; yRange.bottom; y++) { mp = WorkArea->Mask->GetScanLine(y-WorkArea->Range.top); mm = 0x80; bp = iMainImage->Bitmap->GetScanLine(y); for (x=WorkArea->Range.left; xRange.right; x++) { if (*mp&mm) { ChoiceColor->Add(Palette, *(bp+x)); } if (mm==1) { mp++; mm = 0x80; } else mm >>= 1; } } } iMainImage->Bitmap->StopScanLine(); WorkArea->Mask->StopScanLine(); return true; fail: iMainImage->Bitmap->StopScanLine(); WorkArea->Mask->StopScanLine(); return false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::UpdateImage() { TPoint Size; Size.x = Panel->Width*iMainImage->ZoomOut/iMainImage->ZoomIn; Size.y = Panel->Height*iMainImage->ZoomOut/iMainImage->ZoomIn; if (iMainImage->Bitmap->WidthMax = 0; else sbHorz->Max = iMainImage->Bitmap->Width-Size.x; sbHorz->SmallChange = Size.x/4; if (iMainImage->Bitmap->HeightMax = 0; else sbVert->Max = iMainImage->Bitmap->Height-Size.y; sbVert->SmallChange = Size.y/4; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::EditCut() { TCursor cursor; TPoint Size; TTexpiaBitmap *tb; int x, y; Byte *mp, mm, *pp; bool undoSw = false; COLORREF c; RECT r; TPException ec = EC_NONE; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; c = PaletteForm->DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel); if (WorkArea->Mask) { if ((undoSw = UndoSave(UK_ALL, WorkArea->Range))==false) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = SaveToClipboard())!=EC_NONE) goto fail; Size.x = WorkArea->Range.right-WorkArea->Range.left; Size.y = WorkArea->Range.bottom-WorkArea->Range.top; tb = iMainImage->Bitmap; if (!tb->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (!WorkArea->Mask->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } if (iMainImage->Bitmap->BitsPerPixel==8) { for (y=0; yGetScanLine(WorkArea->Range.top+y)+WorkArea->Range.left; mp = WorkArea->Mask->GetScanLine(y); for (x=0; xPutScanLine(WorkArea->Range.top+y); } } else { for (y=0; yGetScanLine(WorkArea->Range.top+y)+3*WorkArea->Range.left; mp = WorkArea->Mask->GetScanLine(y); mm = 0x80; for (x=0; x>= 1; } tb->PutScanLine(WorkArea->Range.top+y); } } tb->StopScanLine(); WorkArea->Mask->StopScanLine(); } else { r = Rect(0, 0, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); if ((undoSw = UndoSave(UK_ALL, r)) == false) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = SaveToClipboard())!=EC_NONE) goto fail; iMainImage->Bitmap->FillRect(r, c); } iMainImage->Repaint(); Screen->Cursor = cursor; return; fail: if (WorkArea->Mask) { WorkArea->Mask->StopScanLine(); tb->StopScanLine(); } if (undoSw == true) Undo->RemoveLast(); Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::EditCopy() { TCursor cursor; TPException ec; cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if ((ec = SaveToClipboard())!=EC_NONE) EXCEPTION_MESSAGE_OK(ec); Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::EditPaste() { RGBQUAD rgb[256]; int x, y; BITMAPHANDLE bh; HGLOBAL hMem = NULL; TClipboardInfo *cbi = NULL; HANDLE hBuffer = NULL; Byte *pBuffer = NULL, c; short color[256]; int colors; TPException ec = EC_NONE; bool undoSw = false, bClipboard = false; TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; TRect r = Rect(0, 0, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); if ((undoSw = UndoSave(UK_ALL, r)) == false) { ec = EC_MEMORY_LACK; goto fail; } memset(&bh, 0, sizeof(BITMAPHANDLE)); if (!OpenClipboard(MainForm->Handle)) { ec = EC_CLIPBOARD_NOT_OPEN; goto fail; } bClipboard = true; if (IsClipboardFormatAvailable(MainForm->ClipboardFormat)) { if ((hMem = GetClipboardData(MainForm->ClipboardFormat))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((cbi = (TClipboardInfo *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (cbi->Width<=iMainImage->Bitmap->Width && cbi->Height<=iMainImage->Bitmap->Height) { if (iMainImage->Bitmap->BitsPerPixel==8) { if (cbi->BitsPerPixel!=8) { ec = EC_COLOR_OVERFLOW; goto fail; } if ((ec = ReadTexpiaFormat8To8(cbi))!=EC_NONE) goto fail; } else { if (cbi->BitsPerPixel==8) { if ((ec = ReadTexpiaFormat8To24(cbi))!=EC_NONE) goto fail; } else { if ((ec = ReadTexpiaFormat24To24(cbi))!=EC_NONE) goto fail; } } } else { ec = EC_BIG_SIZE; goto fail; } GlobalUnlock(hMem); } else { if (L_ClipboardReady()) { if (L_InitBitmap(&bh, 0, 0, iMainImage->Bitmap->BitsPerPixel)<1) { ec = EC_MEMORY_LACK; goto fail; } if (L_CopyFromClipboard(MainForm->Handle, &bh)<1) { ec = EC_CLIPBOARD_NOT_READ; goto fail; } if (bh.Width<=iMainImage->Bitmap->Width && bh.Height<=iMainImage->Bitmap->Height) { if (bh.ViewPerspective!=TOP_LEFT) if (L_ChangeBitmapViewPerspective(NULL, &bh, TOP_LEFT)<1) { ec = EC_MEMORY_LACK; goto fail; } if (bh.BitsPerPixel<=8) { if (bh.BitsPerPixel!=8) { if (L_ColorResBitmap(&bh, &bh, 8, CRF_OPTIMIZEDPALETTE, NULL, 0, NULL, NULL)<1) { ec = EC_CAN_NOT_CONVERT; goto fail; } } L_AccessBitmap(&bh); if ((hBuffer = GlobalAlloc(GMEM_MOVEABLE, bh.BytesPerLine))==NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((pBuffer = (Byte *)GlobalLock(hBuffer))==NULL) { ec = EC_MEMORY_LACK; goto fail; } colors = 0; memset(color, 0, 256*sizeof(short)); L_GetBitmapColors(&bh, 0, 256, rgb); for (y=0; yBitmap->BitsPerPixel==8) { if (bh.BitsPerPixel!=8) { ec = EC_COLOR_OVERFLOW; goto fail; } if ((ec = ReadGeneralFormat8To8(&bh, colors, color))!=EC_NONE) goto fail; } else { if (bh.BitsPerPixel==8) { if ((ec = ReadGeneralFormat8To24(&bh, colors, color))!=EC_NONE) goto fail; } else { if ((ec = ReadGeneralFormat24To24(&bh))!=EC_NONE) goto fail; } } } else { ec = EC_BIG_SIZE; goto fail; } L_FreeBitmap(&bh); } else {ec = EC_NO_CLIPBOARDDATA; goto fail;} } CloseClipboard(); if (!(iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, iMainImage->Bitmap->BitsPerPixel))) goto fail; if (iSelectImage->Bitmap->BitsPerPixel==8) { Palette->ToRGBQUAD(rgb, 256); iSelectImage->Bitmap->PutColors(0, 256, rgb); } PenManagerForm->SetColor(Palette); Center.x = iSelectImage->Bitmap->Width/2; Center.y = iSelectImage->Bitmap->Height/2; iSelectImageSize(); IsMerge(Center); iSelectImage->Visible = true; MainMenuForm->Item = T_MERGE; MainMenuForm->SubItem = 0; ::RepaintColor(); Screen->Cursor = cursor; return; fail: if (undoSw) { if (bClipboard) { if (hBuffer) { if (pBuffer) GlobalUnlock(hBuffer); GlobalFree(hBuffer); } L_FreeBitmap(&bh); if (hMem) { if (cbi) GlobalUnlock(hMem); } ExitMerge(); CloseClipboard(); } Undo->RemoveLast(); } Screen->Cursor = cursor; EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------- TCaptureData *__fastcall TMainImageForm::MakeCapture() { TCaptureData *cd = NULL; if ((cd = new TCaptureData)==NULL) goto fail; cd->Range = WorkArea->Range; if ((cd->Bitmap = new TTexpiaBitmap)==NULL) goto fail; if (!cd->Bitmap->Create(cd->Range.Right-cd->Range.Left, cd->Range.Bottom-cd->Range.Top, iMainImage->Bitmap->BitsPerPixel)) goto fail; if (!cd->Bitmap->CopyFromRect(iMainImage->Bitmap, cd->Range.Left, cd->Range.Top, SRCCOPY)) goto fail; if ((cd->Mask = new TTexpiaBitmap)==NULL) goto fail; if (!cd->Mask->Create(cd->Range.Right-cd->Range.Left, cd->Range.Bottom-cd->Range.Top, WorkArea->Mask->BitsPerPixel)) goto fail; if (!cd->Mask->Copy(WorkArea->Mask, SRCCOPY)) goto fail; return cd; fail: if (cd) delete cd; return NULL; } //--------------------------------------------------------------------- bool __fastcall TMainImageForm::InitOverlap(void) { if (iMainImage->Bitmap->BitsPerPixel>8) return true; overlapdata = (Byte *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 252*252); return overlapdata!=NULL; } //--------------------------------------------------------------------- void __fastcall TMainImageForm::ExitOverlap(void) { if (iMainImage->Bitmap->BitsPerPixel==8) { if (overlapdata) { HeapFree(GetProcessHeap(), 0, overlapdata); overlapdata = NULL; } } } //--------------------------------------------------------------------- COLORREF __fastcall TMainImageForm::Overlap(COLORREF base, COLORREF cover) { int point, density = FullViewForm->OverlapDensity; RGBQUAD rgb[256], *rgbPoint, *rgbBase, *rgbCover; if (iMainImage->Bitmap->BitsPerPixel==8) { if (base && cover) { if (base==cover) return base; else { if (PaletteForm->DIB256Palette->UseColor>=251) return 0xFF; if (overlapdata[base*252+cover]) return overlapdata[base*252+cover]; point = PaletteForm->DIB256Palette->UseColor+1; PaletteForm->DIB256Palette->UseColor = point; overlapdata[base*252+cover] = overlapdata[cover*252+base] = point; rgbPoint = &Palette->ColorData[point]->RGB; rgbBase = &Palette->ColorData[base]->RGB; rgbCover = &Palette->ColorData[cover]->RGB; rgbPoint->rgbRed = (rgbBase->rgbRed*(63-density)+rgbCover->rgbRed*density)/63; rgbPoint->rgbGreen = (rgbBase->rgbGreen*(63-density)+rgbCover->rgbGreen*density)/63; rgbPoint->rgbBlue = (rgbBase->rgbBlue*(63-density)+rgbCover->rgbBlue*density)/63; PaletteForm->DIB256Palette->SetPalette(Palette); Palette->ToRGBQUAD(rgb, 256); iMainImage->Bitmap->PutColors(0, 256, rgb); return point; } } else if (base) return base; else return cover; } else { if (base==cover) return base; else { rgb[0] = TColorToRGB((TColor)base); rgb[1] = TColorToRGB((TColor)cover); rgb[2].rgbRed = (rgb[0].rgbRed*(63-density)+rgb[1].rgbRed*density)/63; rgb[2].rgbGreen = (rgb[0].rgbGreen*(63-density)+rgb[1].rgbGreen*density)/63; rgb[2].rgbBlue = (rgb[0].rgbBlue*(63-density)+rgb[1].rgbBlue*density)/63; return RGBToTColor(rgb[2]); } } } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::ComboHeaderNoMethod(TTexpiaBitmap *Pattern, TSize r, int len, int item) { TSize s; RECT Src; RGBQUAD rgb[256]; if (WorkArea->Mask) { Src = WorkArea->Range; } else { Src = Rect(0, 0, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); } s.cx = Src.right - Src.left; s.cy = Src.bottom - Src.top; if (iMainImage->Bitmap->BitsPerPixel==8) { Palette->ToRGBQUAD(rgb, 256); if (!Pattern->Create(s.cx*r.cx, s.cy*r.cy, 8, rgb)) return false; } else { if (!Pattern->Create(s.cx*r.cx, s.cy*r.cy, 24)) return false; } Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if (!Repeat_Method(Pattern, r, s, Src, len, item)) return false; return true; } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::ComboHeaderYesMethod(TTexpiaBitmap *Pattern) { TRect Src, Dst, Re, PDst; TTexpiaBitmap *UsedColBit = NULL; int w, h, temp, ht, width, height, cnt; HDC hd = NULL; bool over; TCanvas *Canvas = NULL, *UsedCanvas; if ((UsedColBit = new TTexpiaBitmap)==NULL) goto fail; if (!ComboHeaderUsedColorMethod(UsedColBit, true)) goto fail; if (WorkArea->Mask) { Src = WorkArea->Range; width = Src.Right-Src.Left; height = Src.Bottom-Src.Top; } else { width = iMainImage->Bitmap->Width; height = iMainImage->Bitmap->Height; } w = UsedColBit->Width*CanvasInfor.DotsPerInch/160; h = UsedColBit->Height*CanvasInfor.DotsPerInch/160; // {µÎ°³ÀÇ BitmapÀ» ÇÕÄ£ PatternÀÇ »õ·Î¿î ³ôÀÌ¿Í ³ÐÀÌ} ht = GetDeviceCaps(Printer()->Handle, VERTRES)*160/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); temp = height; //======================================= // Same as Textile if (w>width) width = w; cnt = temp/ht; if ((temp-ht*cnt+h) > ht) { // colorchipÀÌ À߸®´Â °ÍÀ» ¸·±â À§ÇØ cnt++; over = true; height = cnt*ht + h; } else { over = false; height = temp + h; } //======================================= if (!Pattern->Create(width, height, 24)) goto fail; // { White·Î PatternÀüü¸¦ ä¿ì±â } Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((hd = iMainImage->Bitmap->CreateDC())==NULL) goto fail; if ((Canvas = Pattern->CreateCanvas()) == NULL) goto fail; if (WorkArea->Mask) { Dst = Rect(0, 0, Src.Right-Src.Left, temp); BitBlt(Canvas->Handle, Dst.Left, Dst.Top, Dst.Right, Dst.Bottom, hd, Src.Left, Src.Top, SRCCOPY); if (!Irregularrect(Pattern->BitsPerPixel, Canvas->Handle, Src, Dst)) goto fail; } else { BitBlt(Canvas->Handle, 0, 0, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height, hd, 0, 0, SRCCOPY); } iMainImage->Bitmap->DeleteDC(hd); hd = NULL; //============================================ // Same as Textile if (over) { // colorchipÀÌ À߸®´Â °ÍÀ» ¸·±â À§ÇØ PDst = Rect(0, cnt*ht, w, cnt*ht+h); } else { PDst = Rect(0, temp , w, temp+h); } //============================================ Src = Rect(0, 0, UsedColBit->Width, UsedColBit->Height); if ((UsedCanvas = UsedColBit->CreateCanvas()) == NULL) goto fail; Canvas->CopyMode = cmSrcCopy; Canvas->CopyRect(PDst, UsedCanvas, Src); UsedColBit->DeleteCanvas(UsedCanvas); Pattern->DeleteCanvas(Canvas); delete UsedColBit; return true; fail: if (Canvas) Pattern->DeleteCanvas(Canvas); if (hd) iMainImage->Bitmap->DeleteDC(hd); if (UsedColBit) delete UsedColBit; return false; } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::ComboHeaderUsedColorMethod(TTexpiaBitmap *Pattern, bool Yes) { TChoiceColor *ChoiceColor = NULL; int i, j, k, l, row, width, height; short m, n, tab, bot, sbot, tb, t; AnsiString NameStr, Rgbvalue; RGBQUAD rgb[256]; TRect BitRect, StrRect, Re; TCanvas *Canvas; if ((ChoiceColor = new TChoiceColor)==NULL) goto fail; if (WorkArea->Mask) SearchWorkAreaColor(ChoiceColor); else SearchWholeColor(ChoiceColor); width = GetDeviceCaps(Printer()->Handle, HORZRES)*160/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); height = GetDeviceCaps(Printer()->Handle, VERTRES)*160/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); if (Yes) { // ComboBoxYesMethod¿¡¼­ »ç¿ë ÇÒ °ª m =100; n =70; bot = 80; sbot = 100; tb = 82; t = 90; } else { // UsedColorMethod¿¡¼­ »ç¿ë ÇÒ °ª m = 120; n = 130; bot = 130; sbot = 160; tb = 135; t = 110; } l = (width-34) / m ; // Pattern Height Á¤Çϱâ row = 1+ChoiceColor->Count / l; height = row*n+60; if (!Pattern->Create(width, height, 24)) goto fail; Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((Canvas = Pattern->CreateCanvas()) == NULL) goto fail; Canvas->Font->Size = 10; k = 0; for (i=0; iCount; i++) { if (i%l == 0) { j = i / l; k = 0; } BitRect = Rect(44+k*m, 30+j*n, 34+m+k*m, bot+j*n); PrintColorChip24(Pattern, BitRect, ChoiceColor->ColorMap[i]->RGB.rgbRed, ChoiceColor->ColorMap[i]->RGB.rgbGreen, ChoiceColor->ColorMap[i]->RGB.rgbBlue); StrRect = Rect(44+k*m, bot+j*n, 34+m+k*m, sbot+j*n); Canvas->Brush->Color = clWhite; switch (ChoiceColor->ColorMap[i]->Kind) { case 0: if (ChoiceColor->ColorMap[i]->Page==0) NameStr = Format("%d - %d - %d", OPENARRAY(TVarRec, (255-ChoiceColor->ColorMap[i]->RGB.rgbRed, 255-ChoiceColor->ColorMap[i]->RGB.rgbGreen, 255-ChoiceColor->ColorMap[i]->RGB.rgbBlue))); else NameStr = PrinterColor->PN2Code(ChoiceColor->ColorMap[i]->Page, ChoiceColor->ColorMap[i]->Number); break; case 3: NameStr = StandardColor->PN2Code(ChoiceColor->ColorMap[i]->Page, ChoiceColor->ColorMap[i]->Number); break; case 4: NameStr = TextileColor->PN2Code(ChoiceColor->ColorMap[i]->Page, ChoiceColor->ColorMap[i]->Number); break; case 0x10: case 0x13: case 0x14: NameStr = ChoiceColor->ColorMap[i]->ColorName; Rgbvalue = Format("%d - %d - %d", OPENARRAY(TVarRec, (ChoiceColor->ColorMap[i]->RGB.rgbRed, ChoiceColor->ColorMap[i]->RGB.rgbGreen, ChoiceColor->ColorMap[i]->RGB.rgbBlue))); break; } tab = (t-Canvas->TextWidth(NameStr)) / 2; // Adjust Center if (tab<0) tab = 0; Canvas->TextRect(StrRect, 44+tab+m*k, tb+j*n, NameStr); k = k+1; } Pattern->DeleteCanvas(Canvas); delete ChoiceColor; return true; fail: if (ChoiceColor) delete ChoiceColor; return false; } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::ComboHeaderMosaicMethod(TTexpiaBitmap *Pattern, int mx, int my) { Byte max, maxp, *sl, *Msl; short color[256]; RGBQUAD rgb[256]; int i, j, k, m, w, h, wh, sum, red, green, blue; TRect Dst, Wrc, Re; COLORREF c; if (!iMainImage->Bitmap->StartScanLine()) goto fail; if (iMainImage->Bitmap->BitsPerPixel==8) { Palette->ToRGBQUAD(rgb, 256); if (WorkArea->Mask) { // Case of Rect_None Mosaic Wrc = WorkArea->Range; w = (Wrc.Right-Wrc.Left)/mx; h = (Wrc.Bottom-Wrc.Top)/my; wh = w*h/2; if (!Pattern->Create(mx*w+1, my*h+1, 8, rgb)) goto fail; Re = Rect(0, 0, Pattern->Width, Pattern->Height); Pattern->FillRect(Re, clWhite); if (!WorkArea->Mask->StartScanLine()) goto fail; for (m=0; m=0 && j<(Wrc.Bottom-Wrc.Top)) { sl = iMainImage->Bitmap->GetScanLine(j+Wrc.Top)+Wrc.Left; Msl = WorkArea->Mask->GetScanLine(j); } else SHOWDEBUG; #else sl = iMainImage->Bitmap->GetScanLine(j+Wrc.Top)+Wrc.Left; Msl = WorkArea->Mask->GetScanLine(j); #endif for (i=k*w; i<(k+1)*w; i++) { #ifdef TPDEBUG if (i>=0 && i<(Wrc.Right-Wrc.Left)) { if (*(Msl+i)) { c = *(sl+i); color[c]++; if (color[c]>max) { max = color[c]; maxp = c; } sum++; } } else SHOWDEBUG; #else if (*(Msl+i)) { c = *(sl+i); color[c]++; if (color[c]>max) { max = color[c]; maxp = c; } sum++; } #endif } } if (sum>(wh)) { // Because of Irregular rect.... MosaicDraw8(Pattern, k, m, w, h, maxp); } } } WorkArea->Mask->StopScanLine(); } else { w = iMainImage->Bitmap->Width/mx; h = iMainImage->Bitmap->Height/my; if (!Pattern->Create(mx*w+1, my*h+1, 8, rgb)) goto fail; for (m=0; m=0 && j<(iMainImage->Bitmap->Height)) { sl = iMainImage->Bitmap->GetScanLine(j); } else SHOWDEBUG; #else sl = iMainImage->Bitmap->GetScanLine(j); #endif for (i=k*w; i<(k+1)*w; i++) { #ifdef TPDEBUG if (i>=0 && i<(iMainImage->Bitmap->Width)) { c = *(sl+i); color[c] = color[c]+1; if (color[c]>max) { max = color[c]; maxp = c; } } else SHOWDEBUG; #else c = *(sl+i); color[c] = color[c]+1; if (color[c]>max) { max = color[c]; maxp = c; } #endif } } MosaicDraw8(Pattern, k, m, w, h, maxp); } } } } else { if (WorkArea->Mask) { // Case of Rect_None Mosaic Wrc = WorkArea->Range; w = (Wrc.Right-Wrc.Left)/mx; h = (Wrc.Bottom-Wrc.Top)/my; wh = w*h/2; if (!Pattern->Create(mx*w+1, my*h+1, 24)) goto fail; Re = Rect(0, 0, Pattern->Width, Pattern->Height); Pattern->FillRect(Re, clWhite); if (!WorkArea->Mask->StartScanLine()) goto fail; for (m=0; m=0 && j<(Wrc.Right-Wrc.Left)) { sl = iMainImage->Bitmap->GetScanLine(j+Wrc.Top)+3*(Wrc.Left+k*w); Msl = WorkArea->Mask->GetScanLine(j); } else SHOWDEBUG; #else sl = iMainImage->Bitmap->GetScanLine(j+Wrc.Top)+3*(Wrc.Left+k*w); Msl = WorkArea->Mask->GetScanLine(j); #endif for (i=k*w; i<(k+1)*w; i++, sl+=3) { #ifdef TPDEBUG if (i>=0 && i<(Wrc.Bottom-Wrc.Top)) { if (*(Msl+(i>>3))&(0x80>>(i&7))) { GetPixel24(sl, c); rgb[0] = TColorToRGB(c); red += rgb[0].rgbRed; green += rgb[0].rgbGreen; blue += rgb[0].rgbBlue; sum++; } } else SHOWDEBUG; #else if (*(Msl+(i>>3))&(0x80>>(i&7))) { GetPixel24(sl, c); rgb[0] = TColorToRGB((TColor)c); red += rgb[0].rgbRed; green += rgb[0].rgbGreen; blue += rgb[0].rgbBlue; sum++; } #endif } } if (sum>(wh)) { // Because of Irregular rect.... rgb[0].rgbRed = red/sum; rgb[0].rgbGreen = green/sum; rgb[0].rgbBlue = blue/sum; MosaicDraw24(Pattern, k, m, w, h, rgb[0]); } } } WorkArea->Mask->StopScanLine(); } else { w = iMainImage->Bitmap->Width/mx; h = iMainImage->Bitmap->Height/my; wh = w*h; if (!Pattern->Create(mx*w+1, my*h+1, 24)) goto fail; for (m=0; m=0 && jBitmap->Height) { sl = iMainImage->Bitmap->GetScanLine(j)+3*k*w; } else SHOWDEBUG; #else sl = iMainImage->Bitmap->GetScanLine(j)+3*k*w; #endif for (i=0; i=0 && iBitmap->Width) { GetPixel24(sl, c); rgb[0] = TColorToRGB(c); red += rgb[0].rgbBlue; green += rgb[0].rgbGreen; blue += rgb[0].rgbRed; } else SHOWDEBUG; #else GetPixel24(sl, c); rgb[0] = TColorToRGB((TColor)c); red += rgb[0].rgbBlue; green += rgb[0].rgbGreen; blue += rgb[0].rgbRed; #endif } } rgb[0].rgbRed = Byte(blue/wh); rgb[0].rgbGreen = Byte(green/wh); rgb[0].rgbBlue = Byte(red/wh); MosaicDraw24(Pattern, k, m, w, h, rgb[0]); } } } } iMainImage->Bitmap->StopScanLine(); return true; fail: if (WorkArea->Mask) WorkArea->Mask->StopScanLine(); iMainImage->Bitmap->StopScanLine(); return false; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::UndoSave(int k, RECT r, bool bSave) { Modify = true; return Undo->Save(k, r, bSave); } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::UndoSave(int k, bool bSave) { Modify = true; return Undo->Save(k, bSave); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PenChange(void) { PenManagerForm->lColor->Enabled = iMainImage->Bitmap->BitsPerPixel==8; PenManagerForm->eGrade->Enabled = iMainImage->Bitmap->BitsPerPixel==8; if (MainMenuForm->Item == T_NONE) { if (PenManagerForm->Type == PT_MASK) { if (iMainImage->Bitmap->BitsPerPixel == 8) { OnSetHLine = SetHLineMask8; if (PenManagerForm->chDelete->Checked) { MaskPixel = 0x00; } else { MaskPixel = 0x0F; } } else { if (PenManagerForm->chDelete->Checked) { OnSetHLine = SetHLineMaskDelete24; MaskPixel = 0x00; } else { OnSetHLine = SetHLineMask24; MaskPixel = 0x80; } } } else { if (iMainImage->Bitmap->BitsPerPixel==8) { if (PenManagerForm->Type == PT_WATER) { PenManagerForm->Type == PT_NORMAL; PenManagerForm->sbNormal->Down = true; PenManagerForm->PenSelectClick(PenManagerForm->sbNormal); PenManagerForm->sbWater->Enabled = false; } else { PenManagerForm->sbWater->Enabled = false; } if (PenManagerForm->acolor == 2) OnSetHLine = SetHLine8ColorYes; else OnSetHLine = SetHLine8ColorNo; } else { PenManagerForm->sbWater->Enabled = true; OnSetHLine = SetHLine24; } } } else if (MainMenuForm->Item == T_DRAW || MainMenuForm->Item == T_3D) { if (PenManagerForm->Type == PT_MASK) { if (iMainImage->Bitmap->BitsPerPixel == 8) { OnSetHLine = SetHLineMask8; if (PenManagerForm->chDelete->Checked) { MaskPixel = 0x00; } else { MaskPixel = 0x0F; } } else { if (PenManagerForm->chDelete->Checked) { OnSetHLine = SetHLineMaskDelete24; MaskPixel = 0x00; } else { OnSetHLine = SetHLineMask24; MaskPixel = 0x80; } } } else { if (iMainImage->Bitmap->BitsPerPixel==8) { OnSetHLine = SetHLine8ColorNo; } else { OnSetHLine = SetHLine24; } } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Timer50ms() { POINT ptScreen, ptClient; if (isDrawPenLocate) { GetCursorPos(&ptScreen); ptClient = iMainImage->ScreenToClient(ptScreen); if (ptClient.x<0 || ptClient.x>=iMainImage->Width || ptClient.y<0 || ptClient.y>=iMainImage->Height) { DrawPenLocate(ptPenLocate.x, ptPenLocate.y); isDrawPenLocate = false; } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Timer200ms() { int ax, ay; ax = CursorPosition.x + 1; ay = iMainImage->Bitmap->Height - CursorPosition.y; if (CurrentUnit==uDot) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%d : %d", OPENARRAY(TVarRec, ((int)ax, (int)ay))); } else if (CurrentUnit==uInch) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%f : %f", OPENARRAY(TVarRec, ((double)ax/CanvasInfor.DotsPerInch, (double) ay/CanvasInfor.DotsPerInch))); } else if (CurrentUnit==uCm) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%f : %f", OPENARRAY(TVarRec, (2.54*ax/CanvasInfor.DotsPerInch, 2.54*ay/CanvasInfor.DotsPerInch))); } if (sbRuler->Down) Ruler->PositionBar(CursorPosition); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Timer1000ms() { if (!BtnClick) iMainImage->OutlineBitmapRgn(WorkArea->bComplex); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::TimerAutoSave() { AnsiString msg, fn, ext; char *s; TGraphicFileFormat gff; if (iMainImage->Bitmap->BitsPerPixel==8) { gff = gffTEX; ext = ".tex"; MainForm->SaveDialog->Filter = "Texpro Textile 256 Colors File (*.tex)|*.tex"; } else { if (MainMenuForm->Item == T_3D) { gff = gffT3D; ext = ".t3d"; MainForm->SaveDialog->Filter = "Texpro Textile 3D File (*.t3d)|*.t3d"; } else { gff = gffTFC; ext = ".tfc"; MainForm->SaveDialog->Filter = "Texpro Textile Full Colors File (*.tfc)|*.tfc"; } } if (FileName == Format("Noname%d%s", OPENARRAY(TVarRec, (Number+1, ext)))) { TIniFile *IniFile = new TIniFile(DirectoryItem + "\\Main.ini"); if (IniFile) { MainForm->SaveDialog->InitialDir = IniFile->ReadString("FileManager", "DirectoryName", "C:\\"); delete IniFile; } if (MainForm->SaveDialog->Execute()) { s = AnsiStrScan(MainForm->SaveDialog->FileName.c_str(), '.'); if (s==NULL) fn = MainForm->SaveDialog->FileName+ext; else fn = MainForm->SaveDialog->FileName; DirName = ExtractFileDir(fn); FileName = ExtractFileName(fn); AutoSaveForm = new TAutoSaveForm(NULL); AutoSaveForm->Visible = true; AutoSaveForm->Update(); SaveToFile(DirName, FileName, gff, MainForm->CompressMethod); delete AutoSaveForm; } } else { AutoSaveForm = new TAutoSaveForm(NULL); AutoSaveForm->Visible = true; AutoSaveForm->Update(); SaveToFile(DirName, FileName, gff, MainForm->CompressMethod); delete AutoSaveForm; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ApplyEnvironment() { TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); if (IniFile) { WorkArea->undoMax = IniFile->ReadInteger("Window", "MaxUndo", 5); delete IniFile; } } //--------------------------------------------------------------------- void __fastcall TMainImageForm::DrawCarpetArea(TObject *Sender, HDC dc, bool isrect, int x, int y) { TPItemImage *Image = (TPItemImage *)Sender; RECT rr; HBRUSH hOldBrush; COLORREF clOldBk; HPEN hOldPen, hPen; if (CarpetArea.IsArea) { rr.left = 0; rr.top = Image->Bitmap->Height - CarpetArea.Height; rr.right = CarpetArea.Width; rr.bottom = Image->Bitmap->Height; if (isrect) { rr.left = Image->RectBitmapToRectCanvasX(rr.left, x); rr.top = Image->RectBitmapToRectCanvasY(rr.top, y); rr.right = Image->RectBitmapToRectCanvasX(rr.right, x); rr.bottom = Image->RectBitmapToRectCanvasY(rr.bottom, y); } else { rr.left = Image->BitmapToCanvasX(rr.left); rr.top = Image->BitmapToCanvasY(rr.top); rr.right = Image->BitmapToCanvasX(rr.right); rr.bottom = Image->BitmapToCanvasY(rr.bottom); } hOldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH)); clOldBk = SetBkColor(dc, clWhite); hPen = CreatePen(PS_DOT, 1, clBlack); hOldPen = SelectObject(dc, hPen); Rectangle(dc, rr.left, rr.top, rr.right, rr.bottom); Rectangle(dc, rr.left+1, rr.top+1, rr.right-1, rr.bottom-1); Rectangle(dc, rr.left+2, rr.top+2, rr.right-2, rr.bottom-2); SelectObject(dc, hOldPen); DeleteObject(hPen); SetBkColor(dc, clOldBk); SelectObject(dc, hOldBrush); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ReDrawCarpetMenu() { if (CarpetForm) CarpetForm->ReDrawTexture(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ClearData() { CTEXTURE *ct; while(CarpetTexture->Count > 0) { ct = (CTEXTURE *) CarpetTexture->Last(); CarpetTexture->Remove(ct); delete[] ct->map; delete ct; } } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::LoadFromCarpetFile(AnsiString fn, TTexpiaBitmap *pBitmap, TPalette *pPalette, TPCanvasInfor &ci) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; TPException ec = EC_NONE; if ((hFile = CreateFile(fn.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pBitmap)) != EC_NONE) goto fail; if (tpfh.Version.Texpia == 'P' && tpfh.Version.Method == 'T' && tpfh.Version.Number >= 222) LoadCarpetData(hFile); UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; CloseHandle(hFile); return EC_NONE; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::SaveToCarpetFile(AnsiString DirName, AnsiString FileName, TCompressMethod cm) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; TEXPIAFILEHEADER tpfh; RECT src; RGBQUAD rgb[256]; TTexpiaBitmap *tag = NULL; TPException ec = EC_NONE; WORD bpp; if ((hFile = CreateFile(FullPathName(DirName, FileName).c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 222); tpfh.CanvasInfor = CanvasInfor; tpfh.BitsPerPixel = iMainImage->Bitmap->BitsPerPixel; tpfh.Compress = cm; src.left = 0; src.top = iMainImage->Bitmap->Height - CarpetArea.Height; src.right = CarpetArea.Width; src.bottom = iMainImage->Bitmap->Height; tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.SetSize(cstFree, src.right-src.left, src.bottom-src.top); if ((tag = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } MakeTexpiaTag(tag, iMainImage->Bitmap, src, 0); if (!SaveToTexpiaFile(hFile, Palette, tpfh, tag, iMainImage->Bitmap, &src)) goto fail; SaveCarpetData(hFile); CloseHandle(hFile); delete tag; return EC_NONE; fail: if (tag) delete tag; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------- // External Function //--------------------------------------------------------------------- void __fastcall RepaintImage() { if (MainImageForm) { MainImageForm->iMainImage->Repaint(); FullViewForm->InitForm(MainImageForm->iMainImage); } } //--------------------------------------------------------------------- void __fastcall RepaintColor() { RGBQUAD rgb[256]; if (MainImageForm) { if (MainImageForm->iMainImage->Bitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->Bitmap->PutColors(0, 256, rgb); } MainImageForm->iMainImage->Repaint(); MainImageForm->ReDrawCarpetMenu(); //Carpet Texture ReDraw FullViewForm->InitForm(MainImageForm->iMainImage); PaletteForm->InitForm(MainImageForm->Palette); PenManagerForm->SetColor(MainImageForm->Palette); ColorLibraryForm->View(); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageKeyDown(Key) { int Ratio; if(Key == 65 || Key == 97){ //'a' or 'A' switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: Ratio = 2 ; break; case 2: Ratio = 1; break; case 4: Ratio = 12; break; case 8: Ratio = 14; break; case 16: Ratio = 18; break; } break; case 2: Ratio = 4; break; case 4: Ratio = 8; break; case 8: Ratio = 16; break; } RatioZoom(Ratio); } if(Key == 83 || Key == 115){ // 's' or 'S' switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: Ratio = 12 ; break; case 2: Ratio = 14; break; case 4: Ratio = 18; break; case 8: Ratio = 116; break; } break; case 2: Ratio = 1; break; case 4: Ratio = 2; break; case 8: Ratio = 4; break; case 16 : Ratio = 8; break; } RatioZoom(Ratio); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::RatioZoom(int r) //by qe { GetCursorPos(&ptScreen); switch (r){ case 116 : ZoomChange(1, 16, &ptScreen); break; case 18 : ZoomChange(1, 8, &ptScreen); break; case 14 : ZoomChange(1, 4, &ptScreen); break; case 12 : ZoomChange(1, 2, &ptScreen); break; case 1 : ZoomChange(1, 1, &ptScreen); break; case 2 : ZoomChange(2, 1, &ptScreen); break; case 4 : ZoomChange(4, 1, &ptScreen); break; case 8 : ZoomChange(8, 1, &ptScreen); break; case 16 : ZoomChange(16, 1, &ptScreen); break; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::PaintFreeLineLocate(TObject *Sender, HDC formDC) { // HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; // int NOL=NumberOfLine; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); nDrawMode = GetROP2(formDC); hOldPen = SelectObject(formDC, GetStockObject(BLACK_PEN)); SetROP2(formDC, R2_NOT); // formDC = iMainImage->Canvas->Handle; POINT pt; POINT First; POINT Second; LineListData *line; if(LineList->Count>0){ line=(LineListData *)LineList->Items[0]; Second=line->Second; pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); MoveToEx(formDC, pt.x, pt.y, NULL); } for(int i=1;iCount;i++){ line=(LineListData *)LineList->Items[i]; First=line->First; Second=line->Second; pt.x = iMainImage->BitmapToCanvasX(First.x); pt.y = iMainImage->BitmapToCanvasY(First.y); MoveToEx(formDC, pt.x, pt.y, NULL); pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); LineTo(formDC, pt.x, pt.y); } SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawFreeLineLocate(POINT Second, int resetCount) { static RECT oldlines=Rect(0,0,0,0); static POINT First = Second; if(resetCount==0) { First=Second; LineList->Clear(); iMainImage->OnPaintLocate = NULL; InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); } else { iMainImage->OnPaintLocate = PaintFreeLineLocate;/////////////////by jeegeo LineListData *line; if(resetCount==-1||resetCount==-2){ line=new LineListData; line->First=First; line->Second=Second; LineList->Add(line); First=Second; } else { while(LineList->Count>resetCount){ line = (LineListData *)LineList->Last(); LineList->Remove(line); } First= ((LineListData *)LineList->Last())->Second; } line=(LineListData *)LineList->Items[0]; int minx,miny,maxx,maxy; minx = iMainImage->BitmapToCanvasX(min( line->First.x, line->Second.x )); maxx = iMainImage->BitmapToCanvasX(max( line->First.x, line->Second.x )); miny = iMainImage->BitmapToCanvasY(min( line->First.y, line->Second.y )); maxy = iMainImage->BitmapToCanvasY(max( line->First.y, line->Second.y )); for(int i=1;iCount;i++){ line=(LineListData *)LineList->Items[i]; minx = min(minx,iMainImage->BitmapToCanvasX(min(line->First.x,line->Second.x))); maxx = max(maxx,iMainImage->BitmapToCanvasX(max(line->First.x,line->Second.x))); miny = min(miny,iMainImage->BitmapToCanvasY(min(line->First.y,line->Second.y))); maxy = max(maxy,iMainImage->BitmapToCanvasY(max(line->First.y,line->Second.y))); } RECT rc = {minx-1,miny-1,maxx+1,maxy+1}; if(resetCount!=-2){ #if defined(TEXTILE) #if defined(CARPET) InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); InvalidateRect(iMainImage->Parent->Handle,&rc,false); #else #endif #else InvalidateRect(iMainImage->Parent->Handle,&oldlines,false); InvalidateRect(iMainImage->Parent->Handle,&rc,false); #endif } oldlines=rc; } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawLineLocate(POINT First, POINT Second,int NOL) { HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; POINT pt; formDC = iMainImage->Canvas->Handle; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(formDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(formDC); SetROP2(formDC, R2_NOT); pt.x = iMainImage->BitmapToCanvasX(First.x); pt.y = iMainImage->BitmapToCanvasY(First.y); MoveToEx(formDC, pt.x, pt.y, NULL); pt.x = iMainImage->BitmapToCanvasX(Second.x); pt.y = iMainImage->BitmapToCanvasY(Second.y); LineTo(formDC, pt.x, pt.y); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawRectangleLocate(RECT rc,int NOR) { HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; RECT rr; formDC = iMainImage->Canvas->Handle; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(formDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(formDC); SetROP2(formDC, R2_NOT); rr.left = iMainImage->BitmapToCanvasX(rc.left); rr.top = iMainImage->BitmapToCanvasY(rc.top); rr.right = iMainImage->BitmapToCanvasX(rc.right); rr.bottom = iMainImage->BitmapToCanvasY(rc.bottom); Rectangle(formDC, min(rr.left, rr.right), min(rr.top, rr.bottom), max(rr.left, rr.right), max(rr.top, rr.bottom)); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawEllipseLocate(RECT rc,int NOE) { HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; RECT rr; formDC = iMainImage->Canvas->Handle; hOldBrush = SelectObject(formDC, GetStockObject(NULL_BRUSH)); hOldPen = SelectObject(formDC, GetStockObject(WHITE_PEN)); nDrawMode = GetROP2(formDC); SetROP2(formDC, R2_NOT); rr.left = iMainImage->BitmapToCanvasX(rc.left); rr.top = iMainImage->BitmapToCanvasY(rc.top); rr.right = iMainImage->BitmapToCanvasX(rc.right); rr.bottom = iMainImage->BitmapToCanvasY(rc.bottom); Ellipse(formDC, min(rr.left, rr.right), min(rr.top, rr.bottom), max(rr.left, rr.right), max(rr.top, rr.bottom)); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); } //---------------------------------------------------------------------------