//--------------------------------------------------------------------------- #include #include #include #include #pragma hdrstop #include "MainImage.h" #include "ColorLibrary_F.h" #include "FullView.h" #include "History.h" #include "Main.h" #include "MainMenu.h" #include "Palette.h" #include "PenManager.h" #include "ProtectCard.h" #include "Undo.h" #include "UserColor_F.h" #include "MarkEdit_F.h" #include "Text_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPImage" #pragma link "TPKnitImage" #pragma link "TPSelectImage" #pragma link "TPRuler2D" #pragma link "TPKnitImage" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_ZOOMIN StringTable[0] #define IDS_ZOOMOUT StringTable[1] #define IDS_RULER StringTable[2] #define IDS_PROTECTION StringTable[3] #define IDS_MESSAGE StringTable[4] //--------------------------------------------------------------------------- TMainImageForm *MainImageForm; int MainImageCount = 0; //--------------------------------------------------------------------------- __fastcall TMainImageForm::TMainImageForm(TComponent* Owner) : TForm(Owner) { Number = MainImageCount; MainImageCount++; hMemLine = NULL; BtnClick = false; DownState = false; bProtect = false; bMaskArea = false; bDrawPen = true; isDrawPenLocate = false; ALLClose = false; // MainMenu ´ÝÇôµµ Filemanager´Â »ç¿ë °¡´ÉÇÏ°Ô MouseState = 0; CurrentUnit = uDot; BackupUnit = uCm; cbTime = 0; Modify = false; LineList = new TList; isPaintDirectlyClean=false; IndexSW = false; // 7.41 isMarkDraw = false; // //======================================== StringTable.Create(DirectoryItem, Language, "MainImage"); SetSmallFont(Font); SetSmallFont(TempLabel->Font); SetSmallFont(sbUnit->Font); sbZoomIn->Hint = IDS_ZOOMIN; sbZoomOut->Hint = IDS_ZOOMOUT; sbGrid->Hint = IDS_COMMON_GRID; sbRuler->Hint = IDS_RULER; sbProtect->Hint = IDS_PROTECTION; sbMaskArea->Hint = IDS_COMMON_MASKAREA; sbMaskShow->Hint = IDS_COMMON_MASKSHOW; sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : " + UnitName(); //======================================== } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormActivate(TObject *Sender) { if (MainImageForm!=this) { MainMenuForm->ExitForm(); MainImageForm = this; PenManagerForm->InitPenForm(); InitKnitMenuForm(); } Undo->Set(Number, iMainImage, Palette, WorkArea); ReviewStatusBar(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::InitKnitMenuForm() { if (DesignMode == D_YARN) { MainMenuForm->sbYarn->Down = true; MainMenuForm->sbYarnClick(MainMenuForm->sbYarn); } else if (DesignMode == D_MARK) { MainMenuForm->sbMark->Down = true; MainMenuForm->sbMarkClick(MainMenuForm->sbMark); } else { MainMenuForm->sbKnit->Down = true; MainMenuForm->sbKnitClick(MainMenuForm->sbKnit); } MainMenuForm->YarnMarkUpdate(); } //--------------------------------------------------------------------------- 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; gff = gffKNT; ext = ".knt"; if (MainForm->MDIChildCount == 1)ALLClose = true; // MainMenu ´ÝÇôµµ Filemanager´Â »ç¿ë °¡´ÉÇÏ°Ô MainMenuForm->ExitForm(); if (Modify) { msg = Format("Save changes to %s!", OPENARRAY (TVarRec,(FileName))); int Btn = MessageDlg(msg, mtWarning, TMsgDlgButtons()<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) { int i; #ifndef LOCK_CRYPKEY #ifndef LOCK_IFC ProtectCard->Check(); #endif #endif if ((WorkArea = new TPWorkArea(&(iMainImage->Bitmap)))==NULL) goto fail; if ((Palette = new TPalette)==NULL) goto fail; if ((Arrange = new TKnitArrange) == NULL) goto fail; MainImageForm = this; CanvasInfor.DotsPerInch = 160; CanvasInfor.SetExtFileOption(); ApplyEnvironment(); Panel->PopupMenu = MainMenuForm->PopupMenu1; iSelectImage->Bitmap->CoordinateSystem = csBottomLeft; iMainImage->Stitch = Mark; Mark[0] = Smark[MS_FRONT].data.micon; Mark[1] = Smark[MS_BACK].data.micon; for (i=0; iDmark.sp[i+2] = &Cmark.data[i]; Arrange->Dmark.chart[i+2] = i; Mark[i+2] = Arrange->Dmark.sp[i+2]->micon; Arrange->Dmark.cnt++; } Arrange->SetFrontBack(0); MarkEditForm->sbFront->Down = true; MarkEditForm->UseGrid->Row = 0; MarkEditForm->UseGrid->Repaint(); iMainImage->Cursor = crPen; ZoomChange(16, 1); PaletteForm->InitForm(Palette); ReviewStatusBar(); InitKnitMenuForm(); return; fail: ::doDestroy(Arrange); ::doDestroy(Palette); ::doDestroy(WorkArea); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormDestroy(TObject *Sender) { MainMenuForm->sbYarn->Down = true; MainMenuForm->InitKnitMenu(); DelLineMem(); ::doDestroy(Arrange); ::doDestroy(Palette); ::doDestroy(WorkArea); FullViewForm->InitForm(NULL); if (ALLClose) MainMenuForm->CloseMainMenuItem(); // MainMenu ´ÝÇôµµ Filemanager´Â »ç¿ë °¡´ÉÇÏ°Ô PostMessage(MainForm->Handle, TPM_DESTROYCHILDFORM, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormPaint(TObject *Sender) { if (isDrawPenLocate) { iMainImage->Invalidate(); iMainImage->Update(); 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->Width = Ruler->Width-Ruler->Thick; Panel->Height = Ruler->Height-Ruler->Thick; } else { Panel->Left = 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) { if((Key == 65) || (Key == 97) || (Key == 115) || (Key == 83)) //a, A, S, s iMainImageKeyDown(Key); MainMenuForm->iMainImageKeyPress(this, Key); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TRect r; if (Active) { 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 (MainMenuForm->iMainImageMouseDown(this, Button, Shift, X, Y)) { PaletteForm->iMainImageMouseDown(Sender, Button, Shift, X, Y); if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { if (DesignMode == D_YARN) { 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; } if (DesignMode == D_MARK && iMainImage->ZoomIn == 16) { /* 7.41 */ if (isMarkDraw) DrawRectangleLocate(MarkRect); isMarkDraw = false; } else if (DesignMode == D_KNIT) { if (isMarkDraw) DrawRectangleLocate(MarkRect, 1, DesignMode == D_KNIT); isMarkDraw = 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 = iMainImage->Bitmap->Height-1-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) { if (DesignMode ==D_YARN) { color = iMainImage->Bitmap->GetPixelColor(CursorPosition.x, iMainImage->Bitmap->Height-1-CursorPosition.y); PaletteForm->DIB256Palette->CursorIndex = color; } else if (DesignMode ==D_KNIT) { color = iMainImage->Bitmap->GetPixelColor(CursorPosition.x, iMainImage->Bitmap->Height-1-CursorPosition.y); color = GetPaletteIndex(color); 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 = DesignMode==D_YARN ? crPen : crCross; } } 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; } } if (iMainImage->Cross) { iMainImage->SetCrossPos(Point(X, Y)); iMainImage->Repaint(); } } //--------------------------------------------------------------------------- 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; } } isPaintDirectlyClean=false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImagePaint(TObject *Sender) { isDrawPenLocate = false; isMarkDraw = 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 = sbVert->Max-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 = DesignMode==D_YARN ? crPen : crCross; 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 (DesignMode==D_KNIT) { if (CurrentUnit==uDot) UnitChange(uInch); else if (CurrentUnit==uInch) UnitChange(uCm); else if (CurrentUnit==uCm) UnitChange(uDot); } } //--------------------------------------------------------------------------- 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->Max-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); Caption = (DirName.Length()>0 ? DirName+"\\"+ fn: fn); sbProtect->Enabled = true; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::LoadFromFile(TFMReadParameter rp, TKnitArrange *ka, TPBitmapList *pBitmapList, TPalette *pPalette, TPCanvasInfor &ci, bool mainimage) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; int x, y, i, j, ec = EC_NONE; RGBQUAD rgb[256]; Byte c[256], *bp; short sx, sy; TTexpiaBitmap *pYarn, *pMark; TPMemory *buf = NULL; TPalette *pal = NULL; AnsiString fn, dn; if (!mainimage) { fn = FileName; dn = DirName; } FileName = rp.FileName; DirName = rp.DirName; if (rp.ExtIndex==gffTEX) { if ((hFile = CreateFile((FullPathName(DirName, FileName)).c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if (rp.Method == 0) { pYarn = pBitmapList->GetBitmap(0); if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pYarn)) != EC_NONE) goto fail; CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; if (mainimage) UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; ci.SizeType = cstFree; ka->kdsn.wpi = rp.WPI; ka->kdsn.cpi = rp.CPI; ci.Width = Ceil((double)ci.DotsPerInch*ci.Width/ka->kdsn.wpi); ci.Height = Ceil((double)ci.DotsPerInch*ci.Height/ka->kdsn.cpi); pPalette->ToRGBQUAD(rgb, 256); pMark = pBitmapList->GetBitmap(1); pMark->Create(pYarn->Width, pYarn->Height, 8, rgb); pMark->FillRect(Rect(0, 0, pMark->Width, pMark->Height), PALETTEINDEX(1)); pBitmapList->GetBitmap(2)->PutColors(0, 256, rgb); } else if (rp.Method == 1) { pYarn = pBitmapList->GetBitmap(0); if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pYarn)) != EC_NONE) goto fail; CloseHandle(hFile); hFile = INVALID_HANDLE_VALUE; if (mainimage) UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; ci.SizeType = cstFree; ci.DotsPerInch = rp.DPI; ka->kdsn.wpi = rp.WPI; ka->kdsn.cpi = rp.CPI; pPalette->ToRGBQUAD(rgb, 256); pMark = pBitmapList->GetBitmap(1); pMark->Create(pYarn->Width, pYarn->Height, 8, rgb); pMark->FillRect(Rect(0, 0, pMark->Width, pMark->Height), PALETTEINDEX(1)); pBitmapList->GetBitmap(2)->PutColors(0, 256, rgb); } } else if (rp.ExtIndex==gffKNT) { if ((hFile = CreateFile((FullPathName(DirName, FileName)).c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_OPEN; goto fail; } if ((pal = new TPalette) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pal, tpfh, pBitmapList->GetBitmap(2))) != EC_NONE) goto fail; if (!ReadFile(hFile, &ka->Dyarn.cnt, 2, &dwRead, NULL)) goto fail; if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T' && tpfh.Version.Number>=222) { if (!ReadFile(hFile, ka->Dyarn.data+1, ka->Dyarn.cnt*sizeof(kyd), &dwRead, NULL)) goto fail; for (i=1; i<=ka->Dyarn.cnt; i++) { //since version 'P', 'T', 232 if (ka->Dyarn.data[i].type == DYT_DESIGN) { ka->Dyarn.ydData[i] = new TYarnData; ka->Dyarn.ydData[i]->LoadFromFile(hFile, tpfh.Version.Number, true); } } if (!ReadFile(hFile, &ka->Dmark.cnt, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, ka->Dmark.chart, 16, &dwRead, NULL)) goto fail; for (i=2; iDmark.cnt; i++) ka->Dmark.sp[i] = &Cmark.data[ka->Dmark.chart[i]]; if (!ReadFile(hFile, &ka->kdsn.wpi, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &ka->kdsn.cpi, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &(ka->ksmlt.hair), 6, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sx, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sy, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &pPalette->UseColor, sizeof(Word), &dwRead, NULL)) goto fail; pPalette->LoadFromFileHandle((int)hFile, 1); pPalette->ToRGBQUAD(rgb, 256); pYarn = pBitmapList->GetBitmap(0); if (!pYarn->Create(sx, sy, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if (!pYarn->LoadFromTexpiaFile(hFile, tpfh.Compress)) goto fail; pMark = pBitmapList->GetBitmap(1); if (!pMark->Create(sx, sy, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if (!pMark->LoadFromTexpiaFile(hFile, tpfh.Compress)) goto fail; if (tpfh.Version.Number<242) { //since version 'P', 'T', 242 pMark->StartScanLine(); for (y=0; yHeight; y++) { bp = pMark->GetScanLine(y); for (x=0; xWidth; x++, bp++) { if ((*bp&0x0F) <= 1) { *bp = ((*bp&0x30)<<2) + (*bp&0x0f); } else { // for (i=2; iDmark.cnt; i++) { // if (Arrange->Dmark.sp[i]->mname == Cmark.data[ka->Dmark.chart[(*bp&0x0F)]].mname) { // *bp = ((*bp&0x30)<<2) + (i&0x3f); // break; // } // } i = ka->Dmark.chart[(*bp&0x0F)] + 2; *bp = ((*bp&0x30)<<2) + (i&0x3f); } } pMark->PutScanLine(y); } pMark->StopScanLine(); } } else { pPalette->SetPalette(pal); if (!ReadFile(hFile, ka->Dyarn.data, 64*sizeof(kyd), &dwRead, NULL)) goto fail; for (i=0; i<64; i++) { for (j=0; jDyarn.data[i].cnt; j++) { ka->Dyarn.data[i].color[j]++; } } for (i=1; i<=ka->Dyarn.cnt; i++) { //since version 'P', 'T', 232 if (ka->Dyarn.data[i].type == DYT_DESIGN) { ka->Dyarn.ydData[i] = new TYarnData; ka->Dyarn.ydData[i]->LoadFromFile(hFile, tpfh.Version.Number, true); } } if (!ReadFile(hFile, &ka->Dmark.cnt, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, ka->Dmark.chart, 16, &dwRead, NULL)) goto fail; for (i=2; iDmark.cnt; i++) ka->Dmark.sp[i] = &Cmark.data[ka->Dmark.chart[i]]; if (!ReadFile(hFile, &ka->kdsn.wpi, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &ka->kdsn.cpi, 2, &dwRead, NULL)) goto fail; if (tpfh.Version.Method=='T' || tpfh.Version.Number>=310) { if (!ReadFile(hFile, &(ka->ksmlt.hair), 6, &dwRead, NULL)) goto fail; } if (!ReadFile(hFile, &sx, 2, &dwRead, NULL)) goto fail; if (!ReadFile(hFile, &sy, 2, &dwRead, NULL)) goto fail; pPalette->ToRGBQUAD(rgb, 256); if ((buf = new TPMemory(sx*sy)) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (buf->lock() == NULL) { ec = EC_MEMORY_LACK; goto fail; } pYarn = pBitmapList->GetBitmap(0); if (!pYarn->Create(sx, sy, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if (!buf->LoadFromFile(hFile, cmNone)) goto fail; if (!pYarn->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } bp = buf->pointer(); for (y=0; yDyarn.data[*(bp+x)].color[0] : 1; } pYarn->PutScanLine(sy-1-y, bp); } pYarn->StopScanLine(); pMark = pBitmapList->GetBitmap(1); if (!pMark->Create(sx, sy, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if (!buf->LoadFromFile(hFile, cmNone)) goto fail; if (!pMark->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } bp = buf->pointer(); for (y=0; yPutScanLine(sy-1-y, bp); } pMark->StopScanLine(); pMark->StartScanLine(); //since version 'P', 'T', 232 for (y=0; yHeight; y++) { bp = pMark->GetScanLine(y); for (x=0; xWidth; x++, bp++) { if ((*bp&0x0F) <= 1) { *bp = ((*bp&0x30)<<2) + (*bp&0x0f); } else { // for (i=2; iDmark.cnt; i++) { // if (Arrange->Dmark.sp[i]->mname == Cmark.data[ka->Dmark.chart[(*bp&0x0F)]].mname) { // *bp = ((*bp&0x30)<<2) + (i&0x3f); // break; // } // } i = ka->Dmark.chart[(*bp&0x0F)] + 2; *bp = ((*bp&0x30)<<2) + (i&0x3f); } } pMark->PutScanLine(y); } pMark->StopScanLine(); delete buf; L_FlipBitmap(pBitmapList->GetBitmap(2)->Handle); RearrangeDosPattern(pYarn, ka); ConvertDosPattern(pYarn, pBitmapList->GetBitmap(2), ka); } delete pal; if (mainimage) UserColorLibForm->ThisFileHasUserColor(pPalette); ci = tpfh.CanvasInfor; CloseHandle(hFile); } else { if (!pYarn->LoadFromFile(FileName.c_str())) goto fail; ci.DotsPerInch = CanvasInfor.DotsPerInch ? CanvasInfor.DotsPerInch : 160; ci.SetSize(cstFree, pYarn->Width, pYarn->Height); if (pYarn->BitsPerPixel==8) { pYarn->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); pYarn->PutColors(0, 256, rgb); memset(c, 0, 256); if (!pYarn->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { bp = pYarn->GetScanLine(y); for (x=0; xWidth; x++) { *(bp+x) += 2; c[*(bp+x)] = 1; } pYarn->PutScanLine(y); } pYarn->StopScanLine(); for (x=251; x>=1; x--) { if (c[x]==1) { pPalette->UseColor = x; break; } } } } if (!mainimage) { FileName = fn; DirName = dn; } return EC_NONE; fail: if (buf) delete buf; if (pal) delete pal; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::LoadFromFile(AnsiString FileName, TGraphicFileFormat Index, TTexpiaBitmap *pBitmap, TPalette *pPalette, TPCanvasInfor &ci, TKnitArrange *ka) { TEXPIAFILEHEADER tpfh; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; int x, y, ec = EC_NONE; RGBQUAD rgb[256]; Byte c[256], *bp; short sx, sy; if (Index==gffTEX) { 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 (!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++) { *(bp+x) += 2; c[*(bp+x)] = 1; } pBitmap->PutScanLine(y); } pBitmap->StopScanLine(); for (x=251; x>=1; x--) { if (c[x]==1) { pPalette->UseColor = x; break; } } } } return EC_NONE; fail: if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ConvertDosPattern(TTexpiaBitmap *ybmp, TTexpiaBitmap *kbmp, TKnitArrange *ka) { RGBQUAD rgb[256], gc[256]; Byte color[256], order[256]; Byte *IP; int x, y, i, j, c; double h, l, s; memset(color, 0, 256); memset(order, 0, 256); c = 0; for (y = 1; y <= ka->Dyarn.cnt; y++) { for (x = 0; x < ka->Dyarn.data[y].cnt; x++) { i = ka->Dyarn.data[y].color[x]; if (color[i] == 0) { order[i] = c; color[i] = 255; c++; } } } kbmp->StartScanLine(); for (y = 0; y < kbmp->Height; y++) { IP = kbmp->GetScanLine(y); for (x = 0; x < kbmp->Width; x++, IP++) { i = ((*IP - 2) / 7) * 7 + 5; j = (*IP - 2) % 7; *IP = order[i] * 7 + 2 + j; } kbmp->PutScanLine(y); } kbmp->StopScanLine(); ybmp->GetColors(0, 256, rgb); gc[0] = rgb[0]; gc[1] = rgb[1]; gc[255] = rgb[255]; memset(color, 0, 256); j = 0; for (y = 1; y <= ka->Dyarn.cnt; y++) { for (x = 0; x < ka->Dyarn.data[y].cnt; x++) { c = ka->Dyarn.data[y].color[x]; if (color[c] == 0) { i = 5 + j * 7; gc[i] = rgb[c]; RGBQUAD2HLS(gc[i], h, l, s); gc[i-3] = HLS2RGBQUAD(h, l-0.12<0 ? 0 : l-0.12, s); gc[i-2] = HLS2RGBQUAD(h, l-0.08<0 ? 0 : l-0.08, s); gc[i-1] = HLS2RGBQUAD(h, l-0.04<0 ? 0 : l-0.04, s); gc[i+1] = HLS2RGBQUAD(h, l+0.04>1 ? 1 : l+0.04, s); gc[i+2] = HLS2RGBQUAD(h, l+0.08>1 ? 1 : l+0.08, s); gc[i+3] = HLS2RGBQUAD(h, l+0.12>1 ? 1 : l+0.12, s); color[c] = 255; j++; } } } kbmp->PutColors(0, 256, gc); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::RearrangeDosPattern(TTexpiaBitmap *ybmp, TKnitArrange *ka) { Byte color[256]; int x, y, i, j; Byte *IP; bool find; memset(color, 0, 256); ybmp->StartScanLine(); for (y = 0; y < ybmp->Height; y++) { IP = ybmp->GetScanLine(y); for (x = 0; x < ybmp->Width; x++, IP++) { color[*IP] = 1; } } ybmp->StopScanLine(); j = 1; while (j <= ka->Dyarn.cnt) { i = ka->Dyarn.data[j].color[0]; if (color[i] == 0) { for (x = j; x < ka->Dyarn.cnt; x++) { ka->Dyarn.data[x].type = ka->Dyarn.data[x+1].type; ka->Dyarn.data[x].cnt = ka->Dyarn.data[x+1].cnt; memcpy(ka->Dyarn.data[x].color, ka->Dyarn.data[x+1].color, 8); } ka->Dyarn.data[x].type = 0; ka->Dyarn.data[x].cnt = 0; memset(ka->Dyarn.data[x].color, 0, 8); ka->Dyarn.cnt--; } else { j++; } } for (i = 2; i < 256; i++) { if (color[i]) { find = false; for (j = 1; j <= ka->Dyarn.cnt; j++) { if (i == ka->Dyarn.data[j].color[0]) find = true; } if (find == false) { ka->Dyarn.cnt++; ka->Dyarn.data[ka->Dyarn.cnt].type = DYT_NORMAL; ka->Dyarn.data[ka->Dyarn.cnt].cnt = 1; memset(ka->Dyarn.data[ka->Dyarn.cnt].color, 0, 8); ka->Dyarn.data[ka->Dyarn.cnt].color[0] = i; } } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ReviewStatusBar() { MainForm->StatusBar->Panels->Items[StatusBarSize]->Text = "Size : " + CanvasInfor.Name(DesignMode==D_KNIT ? CurrentUnit : BackupUnit, iMainImage->ArrayBitmap[2].Width, iMainImage->ArrayBitmap[2].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) { try { if (d!=memsize) { DelLineMem(); hMemLine = GlobalAlloc(GHND, 2 * d * sizeof(int)); if (hMemLine==NULL) throw EC_MEMORY_LACK; msx = (int *)GlobalLock(hMemLine); mex = (int *)msx + d; memsize = d; } } catch (int ec) { EXCEPTION_MESSAGE_OK(ec); DelLineMem(); return false; } catch (...) { DelLineMem(); return false; } return true; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DelLineMem() { if (hMemLine) { GlobalUnlock(hMemLine); 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 (dBitmap->Width, iMainImage->Bitmap->Height); UndoSave(UK_ALL, r); } Image->Visible = false; p.x = iMainImage->CanvasToBitmapX(Image->Left) - Image->PositionX; p.y = iMainImage->CanvasToBitmapY(Image->Top) - Image->PositionY; rc = Rect(p.x, p.y, p.x+Image->Bitmap->Width, p.y+Image->Bitmap->Height); if (DesignMode == D_MARK && iMainImage->ZoomIn == 16) { //7.41 rc = MarkRect; check(rc.left, rc.top, TempBitmap->Width, TempBitmap->Height, &rc); iMainImage->Bitmap->CopyToRect(MarkRect.left, MarkRect.top, TempBitmap, SRCCOPY); iMainImage->SetMark(rc); return true; } else if (DesignMode == D_KNIT) { TCursor OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; RGBQUAD rgb[256]; TStatusProgress *sp = new TStatusProgress(MainForm->StatusBar, StatusBarHint); PaletteForm->DIB256Palette->Palette->ToRGBQUAD(rgb, 256); MainImageForm->iMainImage->ArrayBitmap[0].PutColors(0, 256, rgb); MainImageForm->iMainImage->ArrayBitmap[1].PutColors(0, 256, rgb); rc = MarkRect; check(rc.left, rc.top, TempBitmap->Width, TempBitmap->Height, &rc); iMainImage->ArrayBitmap[1].CopyToRect(MarkRect.left, MarkRect.top, TempBitmap, SRCCOPY); iMainImage->SetMark(rc); ConvertRegion(rc, &rc, true); MainImageForm->Arrange->Simulation(MainImageForm->iMainImage->ArrayBitmap, NULL, rc, MainImageForm->CanvasInfor.DotsPerInch, sp); ::RepaintImage(); delete sp; Screen->Cursor = OldCursor; return true; } if (MainImageForm->bMaskArea) { Image->Bitmap->StartScanLine(); Image->Mask->StartScanLine(); iMainImage->Bitmap->StartScanLine(); if (FullViewForm->Super==sOverlap) { InitOverlap(); if (iMainImage->Bitmap->BitsPerPixel==8) { if (Image->Bitmap->BitsPerPixel==8) { 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)) { color = Overlap(*dsl, *ssl); if (color==0xFF) { ExitOverlap(); iMainImage->Bitmap->StopScanLine(); Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } else *dsl = color; } } 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; xBitmap->StopScanLine(); Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } else *dsl = color; } } iMainImage->Bitmap->PutScanLine(y); } } } else { ExitOverlap(); iMainImage->Bitmap->StopScanLine(); Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } } else { 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); color = Overlap(dc, sc); SetPixel24(dsl, color); } } 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); color = Overlap(dc, sc); SetPixel24(dsl, color); } } iMainImage->Bitmap->PutScanLine(y); } } } ExitOverlap(); } else { 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); } } } iMainImage->Bitmap->StopScanLine(); Image->Mask->StopScanLine(); Image->Bitmap->StopScanLine(); } else { if (FullViewForm->Super==sOverlap) { Image->Bitmap->StartScanLine(); iMainImage->Bitmap->StartScanLine(); InitOverlap(); if (iMainImage->Bitmap->BitsPerPixel==8) { if (Image->Bitmap->BitsPerPixel==8) { 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) { color = Overlap(*dsl, *ssl); if (color==0xFF) { ExitOverlap(); iMainImage->Bitmap->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } else *dsl = color; } } 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; xBitmap->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } else *dsl = color; } iMainImage->Bitmap->PutScanLine(y); } } } else { ExitOverlap(); iMainImage->Bitmap->StopScanLine(); Image->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); return false; } } else { 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) { Image->Bitmap->StartScanLine(); iMainImage->Bitmap->StartScanLine(); 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 (DesignMode == D_MARK) { iMainImage->SetMark(rc); } if (MainMenuForm->SubItem==0 && DesignMode == D_YARN) { WorkArea->SetRectangle(rc); WorkAreaChange(); } return true; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::SaveToClipboard() { RGBQUAD rgb[256]; BITMAPHANDLE bh, *pbh; int w, h, i, j, x, y, count; 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) { iMainImage->Bitmap->GetColors(0, 256, rgb); 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[DesignMode%2]) { cbi.Version = 0; cbi.Time = clock(); cbi.Width = w; cbi.Height = h; cbi.Mask = true; if (DesignMode == D_KNIT) { cbi.BitsPerPixel = 8; for (count = 0, j = 1; j <= Arrange->Dyarn.cnt; j++) { count += Arrange->Dyarn.data[j].cnt; } cbi.Colors = count*7 + 1; // 1 -> background color 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); cd = new TColorData; for (i=1; i<=cbi.Colors; i++) { cd->SetNormal(rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue); memcpy(lpData, cd, sizeof(TColorData)); lpData += sizeof(TColorData); } delete cd; cd = NULL; 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 if (DesignMode == D_YARN) { 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 if (DesignMode == D_MARK) { cbi.BitsPerPixel = 8; cbi.Colors = Arrange->Dmark.cnt; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+ sizeof(short)+Arrange->Dmark.cnt+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); memcpy(lpData, &Arrange->Dmark.cnt, sizeof(short)); lpData += sizeof(short); memcpy(lpData, Arrange->Dmark.chart, Arrange->Dmark.cnt); lpData += Arrange->Dmark.cnt; 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); } SetClipboardData(MainForm->ClipboardFormat[DesignMode%2], 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[DesignMode%2]) { cbi.Version = 0; cbi.Time = clock(); cbi.Width = iMainImage->Bitmap->Width; cbi.Height = iMainImage->Bitmap->Height; cbi.Mask = false; if (DesignMode == D_KNIT) { cbi.BitsPerPixel = 8; for (count = 0, j = 1; j <= Arrange->Dyarn.cnt; j++) { count += Arrange->Dyarn.data[j].cnt; } cbi.Colors = count*7 + 1; // + 1 -> background color 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); iMainImage->Bitmap->GetColors(0, 256, rgb); cd = new TColorData; for (i=1; i<=cbi.Colors; i++) { cd->SetNormal(rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue); memcpy(lpData, cd, sizeof(TColorData)); lpData += sizeof(TColorData); } delete cd; cd = NULL; 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 if (DesignMode == D_YARN) { 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 if (DesignMode == D_MARK) { cbi.BitsPerPixel = 8; cbi.Colors = Palette->UseColor; if ((hMem = GlobalAlloc(GHND, sizeof(TClipboardInfo)+ sizeof(short)+Arrange->Dmark.cnt+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); memcpy(lpData, &Arrange->Dmark.cnt, sizeof(short)); lpData += sizeof(short); memcpy(lpData, Arrange->Dmark.chart, Arrange->Dmark.cnt); lpData += Arrange->Dmark.cnt; if (!iMainImage->Bitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yBitmap->GetScanLine(y); for (x=0; xBitmap->StopScanLine(); GlobalUnlock(hMem); } SetClipboardData(MainForm->ClipboardFormat[DesignMode%2], 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 (ReadTexpiaFormatSuperGauge(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 (ReadTexpiaFormatSuperGauge(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 (ReadTexpiaFormatSuperGauge(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<1 || ((x+y)&1)) { *ip = 0; *mp = 0xFF; } else { *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } } else { 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 ((x&1)==(y&1)) { *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 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; case sGauze: 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) { if ((*mp&mm) || ((x+y)&1)) { 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) { if ((x&1)==(y&1)) { 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) { if ((x&1)==(y&1)) { 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: 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; case sGauze: if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(bh->Width, bh->Height, 8, rgb)) { 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++) { L_GetBitmapRow(bh, pBuffer, y, bh->BytesPerLine); bp = TempBitmap->GetScanLine(y); memcpy(bp, pBuffer, bh->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, bp++, mp++) { if ((x+y)&1) { *bp = 0; *mp = 0xFF; } else { *bp = color[*bp]; *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->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: 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; case sGauze: if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(bh->Width, bh->Height, 8, rgb)) { 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++) { L_GetBitmapRow(bh, pBuffer, y, bh->BytesPerLine); ip = TempBitmap->GetScanLine(y); memcpy(ip, pBuffer, bh->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, ip++, mp++) { if ((x+y)&1) { *ip = 0; *mp = 0xFF; } else { *mp = 0; } } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->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); switch (FullViewForm->Super) { case sGauze: if ((TempMask = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempMask->Create(bh->Width, bh->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); *mp = 0; mm = 0x80; x = 0; while (1) { if ((x+y)&1) { SetPixel24(ip, 0); *mp |= mm; } x++; if (x >= bh->Width) break; ip += 3; if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } /* for (x=0; xWidth; x++, ip+=3) { if ((x+y)&1) { SetPixel24(ip, 0); *mp |= mm; } if (mm==1) { mp++; *mp = 0; mm = 0x80; } else mm >>= 1; } */ TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempBitmap->StopScanLine(); TempMask->StopScanLine(); break; } return EC_NONE; fail: if (TempBitmap) { ::doDestroy(TempMask); if (hBuffer) { if (pBuffer) GlobalUnlock(hBuffer); GlobalFree(hBuffer); } delete TempBitmap; TempBitmap = NULL; } return ec; } //---------------------------------------------------------------------------- TPException __fastcall TMainImageForm::ReadMarkFormat(TClipboardInfo *cbi) { TRect r; int i, x, y, bg; bool sw = false; short *cnt; Byte *chart, *Bitmap, *IP, *OP; TPException ec = EC_NONE; RGBQUAD rgb[256]; Byte *sp, *bp, *mp; cnt = (short *)((Byte *)cbi+sizeof(TClipboardInfo)); chart = (Byte *)((Byte *)cnt + sizeof(short)); IP = Bitmap = chart + *cnt; 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; } Byte mc[MU_CNT]; Byte find; for (y=0; yHeight; y++) { for (x=0; xWidth; x++, IP++) { mc[*IP & 0x3F] = 1; } } mc[0] = 0; mc[1] = 1; for (x=2; x<*cnt; x++) { find = 0; if ( mc[x] ) { for (y=2; yDmark.cnt; y++) { if (chart[x] == Arrange->Dmark.chart[y]) find = y; } if (find) { mc[x] = find; } else { Arrange->Dmark.sp[Arrange->Dmark.cnt] = &Cmark.data[chart[x]]; Arrange->Dmark.chart[Arrange->Dmark.cnt] = chart[x]; Mark[Arrange->Dmark.cnt] = Arrange->Dmark.sp[Arrange->Dmark.cnt]->micon; mc[x] = Arrange->Dmark.cnt; Arrange->Dmark.cnt++; } } } 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++) { *bp = (*bp&0xC0) | mc[*bp&0x3F]; *mp = 0; } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); sp += cbi->Width; } TempMask->StopScanLine(); } else { sp = Bitmap; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); memcpy(bp, sp, cbi->Width); for (x=0; xWidth; x++, bp++) { *bp = (*bp&0xC0) | mc[*bp&0x3F]; } TempBitmap->PutScanLine(y); sp += cbi->Width; } } TempBitmap->StopScanLine(); if (cbTime==cbi->Time) { cbTime = cbi->Time; } else { cbTime = cbi->Time; } return EC_NONE; fail: TempBitmap->StopScanLine(); ::doDestroy(TempBitmap); TempBitmap = NULL; TempMask->StopScanLine(); ::doDestroy(TempMask); TempMask = NULL; return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::MosaicDraw(TCanvas *Canvas, int k, int m, int w, int h) { Canvas->Pen->Color = clBlack; Canvas->Pen->Width = 1; int mk = k*w; int mm = m*h; if (mk==0) mk = 1; if (mm==0) mm = 1; Canvas->Rectangle(mk-1, mm-1, (k+1)*w, (m+1)*h); } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::InitForm(TPCanvasInfor &ci, int wpi, int cpi) { PALETTEENTRY peEntry[256]; Top = 0; Left = 0; if (Palette->LoadFromFile((DirectoryColor+"\\Textile.fcr").c_str())==false) { 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, wpi, cpi)) return EC_MEMORY_LACK; FileName = Format("Noname%d.knt", OPENARRAY(TVarRec, (Number+1))); MaskPixel = 0x0F; iMainImage->ArrayBitmap[0].FillRect(Rect(0, 0, CanvasInfor.Width, CanvasInfor.Height), PaletteForm->DIB256Palette->GetBGCOLORREF(8)); iMainImage->ArrayBitmap[1].FillRect(Rect(0, 0, CanvasInfor.Width, CanvasInfor.Height), 0); iMainImage->ArrayBitmap[2].FillRect(Rect(0, 0, CanvasInfor.Width, CanvasInfor.Height), PALETTEINDEX(1)); 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); PaletteForm->DIB256Palette->ChoiceIndex = 2; PenManagerForm->SetColor(Palette); PenChange(); return EC_NONE; } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::InitFormFile(TFMReadParameter rp) { int pw, ph, sw, sh, x, y, i; RGBQUAD rgb[256]; TPCanvasInfor ci; Byte c[256], *bp; TPBitmapList *bl = NULL; // TKnitArrange *ka = new TKnitArrange; HDC dcSrc, dcDst; TTexpiaBitmap *TexBitmap = NULL; TPException ec = EC_NONE; FileName = rp.FileName; DirName = rp.DirName; Top = 0; Left = 0; sw = MainForm->ClientWidth-267; sh = MainForm->ClientHeight-MainForm->StatusBar->Height -GetSystemMetrics(SM_CYSMCAPTION)-GetSystemMetrics(SM_CYMENU)+3; bl = new TPBitmapList; if (bl) { bl->SetCount(3); if (LoadFromFile(rp, Arrange, bl, Palette, ci) == EC_NONE) { if (!ResizePattern(ci, Arrange->kdsn.wpi, Arrange->kdsn.cpi)) { ec = EC_MEMORY_LACK; goto fail; } MaskPixel = 0x0F; // if (Arrange) delete Arrange; // Arrange = ka; Arrange->Dmark.cnt = 2; for (i=0; iDmark.sp[i+2] = &Cmark.data[i]; Arrange->Dmark.chart[i+2] = i; Mark[i+2] = Arrange->Dmark.sp[i+2]->micon; Arrange->Dmark.cnt++; } bl->GetBitmap(0)->GetColors(0, 256, rgb); iMainImage->ArrayBitmap[0].PutColors(0, 256, rgb); dcSrc = bl->GetBitmap(0)->CreateDC(); if (dcSrc) { dcDst = iMainImage->ArrayBitmap[0].CreateDC(); if (dcDst) { SetStretchBltMode(dcDst, COLORONCOLOR); StretchBlt(dcDst, 0, 0, iMainImage->ArrayBitmap[0].Width, iMainImage->ArrayBitmap[0].Height, dcSrc, 0, 0, bl->GetBitmap(0)->Width, bl->GetBitmap(0)->Height, SRCCOPY); iMainImage->ArrayBitmap[0].DeleteDC(dcDst); } bl->GetBitmap(0)->DeleteDC(dcSrc); } bl->GetBitmap(1)->GetColors(0, 256, rgb); iMainImage->ArrayBitmap[1].PutColors(0, 256, rgb); dcSrc = bl->GetBitmap(1)->CreateDC(); if (dcSrc) { dcDst = iMainImage->ArrayBitmap[1].CreateDC(); if (dcDst) { SetStretchBltMode(dcDst, COLORONCOLOR); StretchBlt(dcDst, 0, 0, iMainImage->ArrayBitmap[1].Width, iMainImage->ArrayBitmap[1].Height, dcSrc, 0, 0, bl->GetBitmap(1)->Width, bl->GetBitmap(1)->Height, SRCCOPY); iMainImage->ArrayBitmap[1].DeleteDC(dcDst); } bl->GetBitmap(1)->DeleteDC(dcSrc); } bl->GetBitmap(2)->GetColors(0, 256, rgb); iMainImage->ArrayBitmap[2].PutColors(0, 256, rgb); dcSrc = bl->GetBitmap(2)->CreateDC(); if (dcSrc) { dcDst = iMainImage->ArrayBitmap[2].CreateDC(); if (dcDst) { SetStretchBltMode(dcDst, COLORONCOLOR); StretchBlt(dcDst, 0, 0, iMainImage->ArrayBitmap[2].Width, iMainImage->ArrayBitmap[2].Height, dcSrc, 0, 0, bl->GetBitmap(2)->Width, bl->GetBitmap(2)->Height, SRCCOPY); iMainImage->ArrayBitmap[2].DeleteDC(dcDst); } bl->GetBitmap(2)->DeleteDC(dcSrc); } iMainImage->SetMark(); pw = iMainImage->Bitmap->Width*iMainImage->ZoomIn+PanelVert->Width; ph = iMainImage->Bitmap->Height*iMainImage->ZoomIn+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; } return ec; fail: if (bl) delete bl; return ec; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ResizeCanvas(short dpi, int yw, int yh) { RGNXFORM XForm; int w, h; HRGN rgn; w = yw * dpi / Arrange->kdsn.wpi; h = yh * dpi / Arrange->kdsn.cpi; iMainImage->ArrayBitmap[0].ResizeStretch(yw, yh); MarkBitmapResize(yw, yh); iMainImage->ArrayBitmap[2].ResizeStretch(w, h); iMainImage->CreateMark(); iMainImage->SetMark(); if (iMainImage->Mask) { iMainImage->Mask->ResizeStretch(yw, yh); } 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); } iMainImage->SetPosition(0, 0); UpdateImage(); ::RepaintColor(); ReviewStatusBar(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::MarkBitmapResize(int w, int h) { TPBitmap *pbmp = NULL; TTexpiaBitmap *tbmp; RGBQUAD rgb[256]; int x, y, xx, yy, wid, hei, wale, course, wx, wy, k; double rx, ry; Byte *IP, *DP, set; bool find; tbmp = &iMainImage->ArrayBitmap[1]; wid = tbmp->Width; hei = tbmp->Height; rx = (double) wid / w; ry = (double) hei / h; tbmp->GetColors(0, 256, rgb); pbmp = new TPBitmap; pbmp->Create(wid, hei, 8); pbmp->Lock(); tbmp->StartScanLine(); for (y = 0; y < hei; y++) { IP = tbmp->GetScanLine(y); DP = pbmp->ScanLine(y); memcpy(DP, IP, wid); } tbmp->StopScanLine(); tbmp->Create(w, h, 8, rgb); tbmp->StartScanLine(); for (y = 0; y < hei; y++) { yy = y / ry; if (yy < 0 || yy >= h) continue; DP = pbmp->ScanLine(y); x = 0; while (x < wid) { xx = x / rx; if (xx < 0 || xx >= w) { x++; continue; } if ((DP[x] & 0x3F) > 1 && (DP[x] & 0x80) == 0) { wale = Arrange->Dmark.sp[DP[x] & 0x3F]->wale; course = Arrange->Dmark.sp[DP[x] & 0x3F]->course; set = DP[x] & 0x7F; } else if ((DP[x] & 0x3F) > 1 && (DP[x] & 0x80)) { wale = 1; course = 1; set = (DP[x] & 0x40) | 1; } else if ((DP[x] & 0x3F) <= 1) { wale = 1; course = 1; set = DP[x]; } find = false; for (wy=0; wyGetScanLine(yy+wy); for (wx=0; wx 1) find = true; } } if (!find) { for (wy=0; wyGetScanLine(yy+wy); for (wx=0; wxPutScanLine(yy+wy); } } x++; } } for (y = 0; y < h; y++) { yy = y * ry; if (yy < 0 || yy >= hei) continue; IP = tbmp->GetScanLine(y); DP = pbmp->ScanLine(yy); x = 0; while (x < w) { xx = x * rx; if (xx < 0 || xx >= wid) { x++; continue; } if ((IP[x] & 0x3F) < 1) { if ((DP[xx] & 0x3F) > 1) IP[x] = (DP[xx]&0x40) | 1; else IP[x] = DP[xx]&0x7F; } x++; } tbmp->PutScanLine(y); } tbmp->StopScanLine(); delete pbmp; /* TPBitmap *pbmp = NULL; TTexpiaBitmap *tbmp; RGBQUAD rgb[256]; int x, y, xx, yy, wid, hei, wale, wx, k; double rx, ry; Byte *IP, *DP, set; tbmp = &iMainImage->ArrayBitmap[1]; wid = tbmp->Width; hei = tbmp->Height; rx = (double) wid / w; ry = (double) hei / h; tbmp->GetColors(0, 256, rgb); pbmp = new TPBitmap; pbmp->Create(wid, hei, 8); pbmp->Lock(); tbmp->StartScanLine(); for (y = 0; y < hei; y++) { IP = tbmp->GetScanLine(y); DP = pbmp->ScanLine(y); memcpy(DP, IP, wid); } tbmp->StopScanLine(); tbmp->Create(w, h, 8, rgb); tbmp->StartScanLine(); for (y = 0; y < h; y++) { yy = y * ry; if (yy < 0 || yy >= hei) continue; IP = tbmp->GetScanLine(y); DP = pbmp->ScanLine(yy); x = 0; while (x < w) { xx = x * rx; if (xx < 0 || xx >= wid) { x++; continue; } if ((DP[xx] & 0x3F) > 1) { wale = Arrange->Dmark.sp[DP[xx] & 0x3F]->wale; set = DP[xx] & 0x7F; if (rx < 0) wx = wale / rx; else wx = wale; if (x + wale >= w) { while (x < w) { IP[x] = (Arrange->Dmark.set & 0x40) | 1; x++; } break; } else if (x + wx >= w) { k = 0; while (x < w) { if (k < wale) { IP[x] = set; set |= 0x80; } else { IP[x] = (Arrange->Dmark.set & 0x40) | 1; } x++; k++; } break; } else { k = 0; while (k < wx) { if (k < wale) { IP[x] = set; set |= 0x80; } else { IP[x] = (Arrange->Dmark.set & 0x40) | 1; } x++; k++; } } } else { IP[x] = DP[xx]; x++; } } tbmp->PutScanLine(y); } tbmp->StopScanLine(); delete pbmp; */ } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::EnlargeCanvas(int w, int h) { int x, y; CanvasInfor.SetSize(cstFree, w, h); x = (double)Arrange->kdsn.wpi*w/CanvasInfor.DotsPerInch; y = (double)Arrange->kdsn.cpi*h/CanvasInfor.DotsPerInch; iMainImage->ArrayBitmap[0].Resize(x, y, PaletteForm->DIB256Palette->GetBGCOLORREF(8)); iMainImage->ArrayBitmap[1].Resize(x, y, 0); iMainImage->ArrayBitmap[2].Resize(w, h, PALETTEINDEX(1)); iMainImage->CreateMark(); iMainImage->SetMark(); if (iMainImage->Mask) { iMainImage->Mask->Resize(w, h, 0); } UpdateImage(); iMainImage->SetPosition(0, 0); ::RepaintColor(); AllocLineMem(h); ReviewStatusBar(); } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::ResizePattern(TPCanvasInfor &pi, int wpi, int cpi) { int x, y; RGBQUAD rgb[256]; Arrange->kdsn.wpi = wpi; Arrange->kdsn.cpi = cpi; if (pi.SizeType!=cstFree) { pi.Width = pi.GetWidth(); pi.Height = pi.GetHeight(); } x = (double)Arrange->kdsn.wpi*pi.Width/pi.DotsPerInch; y = (double)Arrange->kdsn.cpi*pi.Height/pi.DotsPerInch; CanvasInfor = pi; CanvasInfor.SetExtFileOption(); Ruler->DPI = CanvasInfor.DotsPerInch; Palette->ToRGBQUAD(rgb, 256); if (!iMainImage->Create(x, y, CanvasInfor.Width, CanvasInfor.Height, rgb)) return false; if (!AllocLineMem(y)) 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; bool sw; Byte *pp, *mp, mm; TPalette *TempPalette; COLORREF bgc, c; TKnitArrange ka; r = Rect(0, 0, iMainImage->Bitmap->Width, iMainImage->Bitmap->Height); UndoSave(UK_ALL, r); TempPalette = new TPalette; sw = false; switch (FullViewForm->Super) { case sOff: TempBitmap = NULL; if (LoadFromFile(FullFileName, Index, iSelectImage->Bitmap, TempPalette, ci, &ka) == EC_NONE) { if (iSelectImage->Bitmap->Width<=iMainImage->Bitmap->Width && iSelectImage->Bitmap->Height<=iMainImage->Bitmap->Height) { if (iMainImage->Bitmap->BitsPerPixel==8) { if (iSelectImage->Bitmap->BitsPerPixel==8) { bg = 0; iSelectImage->Bitmap->StartScanLine(); 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) { TempMask = NULL; UseColor = Palette->UseColor-1+bg; iSelectImage->Bitmap->StartScanLine(); 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); sw = true; } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { TempMask = NULL; sw = true; } } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } break; case sOverlap: case sNormal: TempBitmap = new TTexpiaBitmap; if (LoadFromFile(FullFileName, Index, TempBitmap, TempPalette, ci, &ka) == EC_NONE) { if (TempBitmap->Width<=iMainImage->Bitmap->Width && TempBitmap->Height<=iMainImage->Bitmap->Height) { if (iMainImage->Bitmap->BitsPerPixel==8) { if (TempBitmap->BitsPerPixel==8) { if (Palette->UseColor+TempPalette->UseColor-2<252) { TempMask = new TTexpiaBitmap; TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8); UseColor = Palette->UseColor-1; TempBitmap->StartScanLine(); TempMask->StartScanLine(); 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); iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb); sw = true; } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { TempMask = new TTexpiaBitmap; TempMask->Create(TempBitmap->Width, TempBitmap->Height, 1); if (TempBitmap->BitsPerPixel==8) { TempBitmap->StartScanLine(); TempMask->StartScanLine(); 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]; TempBitmap->StartScanLine(); TempMask->StartScanLine(); 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(); } iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 24); sw = true; } } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } break; case sGauze: TempBitmap = new TTexpiaBitmap; if (LoadFromFile(FullFileName, Index, TempBitmap, TempPalette, ci, &ka) == EC_NONE) { if (TempBitmap->Width<=iMainImage->Bitmap->Width && TempBitmap->Height<=iMainImage->Bitmap->Height) { if (iMainImage->Bitmap->BitsPerPixel==8) { if (TempBitmap->BitsPerPixel==8) { bg = 0; TempBitmap->StartScanLine(); 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) { TempMask = new TTexpiaBitmap; TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8); UseColor = Palette->UseColor-1+bg; TempBitmap->StartScanLine(); TempMask->StartScanLine(); 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); iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb); sw = true; } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else { TempMask = new TTexpiaBitmap; TempMask->Create(TempBitmap->Width, TempBitmap->Height, 1); if (TempBitmap->BitsPerPixel==8) { TempBitmap->StartScanLine(); TempMask->StartScanLine(); for (y=0; yHeight; y++) { pp = TempBitmap->GetScanLine(y); mp = TempMask->GetScanLine(y); *mp = 0; mm = 0x80; x = 0; while (1) { if (*pp < 2 || (x+y)&1) { *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 || (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]; TempBitmap->StartScanLine(); TempMask->StartScanLine(); 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) || (x&1)==(y&1)) { 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) || (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(); } iSelectImage->Bitmap->Create(TempBitmap->Width, TempBitmap->Height, 24); sw = true; } } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } break; } if (sw) { 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(); } else { ExitMerge(); } delete TempPalette; return sw; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ExitMerge() { iSelectImage->Bitmap->Destroy(); iSelectImage->Width = 0; iSelectImage->Height = 0; if (DesignMode == D_MARK && iMainImage->ZoomIn == 16) { if (isMarkDraw) DrawRectangleLocate(MarkRect); isMarkDraw = false; } if (TempBitmap) { if (TempMask) { delete TempMask; TempMask = NULL; } delete TempBitmap; TempBitmap = NULL; } } //--------------------------------------------------------------------------- TPException __fastcall TMainImageForm::SaveToFile(AnsiString dn, AnsiString fn, TGraphicFileFormat Index, TCompressMethod cm, bool mainimage) { HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; int i, DPI, ec = EC_NONE; short tx, ty; TEXPIAFILEHEADER tpfh; RECT src, yRect; RGBQUAD rgb[256]; TTexpiaBitmap *tb; TTexpiaBitmap *tag = NULL; HDC dcSrc; TPalette *pal = NULL; TPWorkArea *wa = NULL; POINT first, second; 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.Version = TexVersion('P', 'T', 232); //From 7.41 (YarnData is Added) tpfh.Version = TexVersion('P', 'T', 242); //From 7.41 (DMark is Changeed) tpfh.CanvasInfor = CanvasInfor; tpfh.BitsPerPixel = 8; tpfh.Compress = cm; if ((wa = new TPWorkArea(&(iMainImage->ArrayBitmap))) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (WorkArea->Mask) { if (DesignMode != D_KNIT) { ConvertRegion(WorkArea->Range, &src, true); wa->SetShapeRegion(&iMainImage->ArrayBitmap[2], Point(src.left, src.top), Point(src.right, src.bottom)); tpfh.CanvasInfor.SetSize(cstFree, wa->Mask->Width, wa->Mask->Height); } else { src = WorkArea->Range; tpfh.CanvasInfor.SetSize(cstFree, WorkArea->Mask->Width, WorkArea->Mask->Height); } } else { src.left = 0; src.top = 0; src.right = iMainImage->ArrayBitmap[2].Width; src.bottom = iMainImage->ArrayBitmap[2].Height; } iMainImage->ArrayBitmap[2].GetColors(0, 256, rgb); if ((tag = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } MakeTexpiaTag(tag, &iMainImage->ArrayBitmap[2], src, 0); if ((pal = new TPalette) == NULL) { ec = EC_MEMORY_LACK; goto fail; } pal->UseColor = 1+Arrange->Count*7; for (i=0; i<256; i++) { pal->SetNormal(i, rgb[i].rgbRed, rgb[i].rgbGreen, rgb[i].rgbBlue); } if (DesignMode != D_KNIT) { if (wa && wa->Mask) { if (!SaveToTexpiaFile(hFile, pal, tpfh, tag, &iMainImage->ArrayBitmap[2], &wa->Range)) goto fail; } else { if (!SaveToTexpiaFile(hFile, pal, tpfh, tag, &iMainImage->ArrayBitmap[2])) goto fail; } } else { if (WorkArea && WorkArea->Mask) { if (!SaveToTexpiaFile(hFile, pal, tpfh, tag, &iMainImage->ArrayBitmap[2], &WorkArea->Range)) goto fail; } else { if (!SaveToTexpiaFile(hFile, pal, tpfh, tag, &iMainImage->ArrayBitmap[2])) goto fail; } } delete wa; wa = NULL; delete tag; tag = NULL; delete pal; pal = NULL; if (Index == gffKNT) { if (!WriteFile(hFile, &Arrange->Dyarn.cnt, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, Arrange->Dyarn.data+1, Arrange->Dyarn.cnt*sizeof(kyd), &dwWrite, NULL)) { goto fail; } //~~~~ 7.41¿¡¼­ YarnData Ãß°¡ ~~~~// for (i=1; i<=Arrange->Dyarn.cnt; i++) { if (Arrange->Dyarn.data[i].type == DYT_DESIGN) { if ((ec = Arrange->Dyarn.ydData[i]->SaveToFile(hFile, true)) != EC_NONE) goto fail; } } //~~~~ 7.41¿¡¼­ YarnData Ãß°¡ ~~~~// if (!WriteFile(hFile, &Arrange->Dmark.cnt, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, Arrange->Dmark.chart, 16, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Arrange->kdsn.wpi, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Arrange->kdsn.cpi, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Arrange->ksmlt.hair, 6, &dwWrite, NULL)) goto fail; if (WorkArea->Mask) { if (DesignMode != D_KNIT) { yRect = WorkArea->Range; tx = WorkArea->Mask->Width; ty = WorkArea->Mask->Height; } else { ConvertRegion(WorkArea->Range, &yRect, false); yRect.right++; yRect.bottom++; //7.41 Çϳª¾¿ MainMenuForm->InitKnitMenu()¿¡¼­´Â ¹®Á¦°¡ ¾øÀ¸³ª ¿©±â¼­ ¹®Á¦°¡ »ý±è. tx = yRect.right - yRect.left; ty = yRect.bottom - yRect.top; } } else { tx = iMainImage->ArrayBitmap[0].Width; ty = iMainImage->ArrayBitmap[0].Height; } if (!WriteFile(hFile, &tx, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &ty, 2, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &Palette->UseColor, sizeof(Word), &dwWrite, NULL)) goto fail; Palette->SaveToFileHandle((int)hFile); if (WorkArea->Mask) { if (!iMainImage->ArrayBitmap[0].SaveToTexpiaFile(hFile, yRect, cm)) goto fail; if (!iMainImage->ArrayBitmap[1].SaveToTexpiaFile(hFile, yRect, cm)) goto fail; } else { if (!iMainImage->ArrayBitmap[0].SaveToTexpiaFile(hFile, cm)) goto fail; if (!iMainImage->ArrayBitmap[1].SaveToTexpiaFile(hFile, cm)) goto fail; } } CloseHandle(hFile); if (mainimage) { DirName = dn; FileName = fn; } SetCaption(); return EC_NONE; fail: if (wa) delete wa; if (tag) delete tag; if (pal) delete pal; 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 = Panel->Height - iSelectImage->Height; } //--------------------------------------------------------------------------- POINT __fastcall TMainImageForm::iSelectImageConvert(int X, int Y) { POINT p; p.x = iMainImage->CanvasToBitmapX(iSelectImage->Left+X)-Center.x; p.y = iMainImage->CanvasToBitmapY(iSelectImage->Top+Y)-Center.y; return p; } //--------------------------------------------------------------------------- POINT __fastcall TMainImageForm::iSelectImagePosition(POINT p) { TRect dst; if (DesignMode == D_KNIT) { p.x += (Center.x - CanvasInfor.DotsPerInch/Arrange->kdsn.wpi/2); p.y += (Center.y - CanvasInfor.DotsPerInch/Arrange->kdsn.wpi/2); } 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; 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; iSelectImage->Top = iMainImage->BitmapToCanvasY(p.y); iSelectImage->PositionY = 0; if (TempBitmap) { if (DesignMode == D_KNIT || DesignMode == D_MARK && iMainImage->ZoomIn == 16) { if (p.x>iMainImage->Bitmap->Width-TempBitmap->Width) p.x = iMainImage->Bitmap->Width-TempBitmap->Width; iSelectImage->Left = iMainImage->BitmapToCanvasX(p.x); iSelectImage->PositionX = 0; if (p.y>iMainImage->Bitmap->Height-TempBitmap->Height) p.y = iMainImage->Bitmap->Height-TempBitmap->Height; iSelectImage->Top = iMainImage->BitmapToCanvasY(p.y); iSelectImage->PositionY = 0; } } return p; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::IsMerge(POINT p) { HDC dcSrc, dcDst; int w, h; if (TempBitmap) { if (TempMask) { w = iSelectImage->Bitmap->Width; h = iSelectImage->Bitmap->Height; 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) { StretchBlt(dcDst, 0, 0, w, h, dcSrc, 0, 0, TempBitmap->Width, TempBitmap->Height, SRCCOPY); TempBitmap->DeleteDC(dcSrc); } iSelectImage->Bitmap->DeleteDC(dcDst); } else { if (DesignMode == D_MARK && iMainImage->ZoomIn == 16) { /* 7.41 */ if (isMarkDraw) DrawRectangleLocate(MarkRect); MarkRect.left = p.x; MarkRect.top = p.y; MarkRect.right = p.x + TempBitmap->Width; MarkRect.bottom = p.y + TempBitmap->Height; DrawRectangleLocate(MarkRect); isMarkDraw = true; } else if (DesignMode == D_KNIT) { if (isMarkDraw) DrawRectangleLocate(MarkRect, 1, DesignMode == D_KNIT); ConvertRegion(MarkRect, &MarkRect, false); MarkRect.left -= Center.x; MarkRect.top -= Center.y; MarkRect.right = MarkRect.left + TempBitmap->Width; MarkRect.bottom = MarkRect.top + TempBitmap->Height; if (MarkRect.left<0) { MarkRect.left = 0; MarkRect.right = MarkRect.left + TempBitmap->Width; } else if (MarkRect.right>iMainImage->ArrayBitmap[1].Width) { MarkRect.right = iMainImage->ArrayBitmap[1].Width; MarkRect.left = MarkRect.right - TempBitmap->Width; } if (MarkRect.top<0) { MarkRect.top = 0; MarkRect.bottom = MarkRect.top + TempBitmap->Height; } else if (MarkRect.bottom>iMainImage->ArrayBitmap[1].Height) { MarkRect.bottom = iMainImage->ArrayBitmap[1].Height; MarkRect.top = MarkRect.bottom - TempBitmap->Height; } DrawRectangleLocate(MarkRect, 1, DesignMode == D_KNIT); isMarkDraw = true; } } } else { if (DesignMode == D_MARK && iMainImage->ZoomIn == 16) { /* 7.41 */ if (isMarkDraw) DrawRectangleLocate(MarkRect); MarkRect.left = p.x; MarkRect.top = p.y; MarkRect.right = p.x + TempBitmap->Width; MarkRect.bottom = p.y + TempBitmap->Height; DrawRectangleLocate(MarkRect); isMarkDraw = true; } else if (DesignMode == D_KNIT) { if (isMarkDraw) DrawRectangleLocate(MarkRect, 1, DesignMode == D_KNIT); MarkRect.left = p.x; MarkRect.top = p.y; ConvertRegion(MarkRect, &MarkRect, false); MarkRect.left -= Center.x; MarkRect.top -= Center.y; MarkRect.right = MarkRect.left + TempBitmap->Width; MarkRect.bottom = MarkRect.top + TempBitmap->Height; if (MarkRect.left<0) { MarkRect.left = 0; MarkRect.right = MarkRect.left + TempBitmap->Width; } else if (MarkRect.right>iMainImage->ArrayBitmap[1].Width) { MarkRect.right = iMainImage->ArrayBitmap[1].Width; MarkRect.left = MarkRect.right - TempBitmap->Width; } if (MarkRect.top<0) { MarkRect.top = 0; MarkRect.bottom = MarkRect.top + TempBitmap->Height; } else if (MarkRect.bottom>iMainImage->ArrayBitmap[1].Height) { MarkRect.bottom = iMainImage->ArrayBitmap[1].Height; MarkRect.top = MarkRect.bottom - TempBitmap->Height; } DrawRectangleLocate(MarkRect, 1, DesignMode == D_KNIT); isMarkDraw = true; } else { iSelectImage->Bitmap->Copy(TempBitmap, SRCCOPY); } } iMainImage->Update(); } } //--------------------------------------------------------------------------- AnsiString __fastcall TMainImageForm::UnitName(TUnit unit) { if (unit==uDot) return DesignMode==D_KNIT ? "Dot" : "Stitch"; else if (unit==uInch) return "Inch"; else if (unit==uCm) return "Cm"; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::UnitChange(TUnit unit) { CurrentUnit = unit; Ruler->AUnit = CurrentUnit; //================================ //2001.4.11. by lhskys congi¿¡¼­ unit ³Ö±â // CurrentUnit = uCm; TIniFile *IniFile = new TIniFile(DirectoryItem+"\\Environment.ini"); int UNITS; if (KUnits == "uCm")UNITS = 0; else if (KUnits == "uInch")UNITS = 1; else UNITS = 2; IniFile->WriteInteger("MainImage", "Unit", UNITS); // unit = IniFile->ReadInteger("MainImage", "Unit", 0); if (DesignMode==D_KNIT) { if (CurrentUnit == 0) { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Dot"; CurrentUnit = uDot; } else if (CurrentUnit == 1) { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Inch"; CurrentUnit = uInch; } else { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Cm"; CurrentUnit = uCm; } }else { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Stitch"; } //================================= /* if (CurrentUnit==uDot) { if (DesignMode==D_KNIT) { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Dot"; } else { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Stitch"; } } else if (CurrentUnit==uInch) { sbUnit->Caption = AnsiString(IDS_COMMON_UNIT) + " : Inch"; } else if (CurrentUnit==uCm) { sbUnit->Caption = AnsiString(IDS_COMMON_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); ptClient.y = iMainImage->Height - ptClient.y; 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_MOVECOPY: case T_STRIPE: iSelectImageSize(); } } 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, lx, ly; double d, r1, r2, xx, yy; TLineData ld; RECT rect, mrect = Rect(-1, -1, -1, -1); Byte *IP, set; if (DesignMode == D_YARN) { 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) { 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); } } else if (DesignMode == D_MARK) { set = Arrange->Dmark.set; Arrange->Dmark.sp[set&0x3F]->use = true; if ((set&0x3F) > 1) { // cross mark lx = Arrange->Dmark.sp[set&0x3F]->wale; ly = Arrange->Dmark.sp[set&0x3F]->course; mrect = Rect(sx, sy, sx+lx, sy+ly); } else { // front or back mark lx = 1; ly = 1; mrect = Rect(sx, sy, sx+lx, sy+ly); } if (check(sx, sy, lx, ly, &mrect)) { iMainImage->Bitmap->StartScanLine(); for (y=0; yBitmap->GetScanLine(sy+y); for (x = 0; x < lx; x++) { IP[sx+x] = (x==0 && y==0) ? set : set | 0x80; } iMainImage->Bitmap->PutScanLine(sy+y); } iMainImage->Bitmap->StopScanLine(); } if (MainMenuForm->Item!=T_DRAW) { rect = Rect(sx-10, sy-5, sx+20, sy+10); //if (rect.left < 0) rect.left = 0; //if (rect.right >= w) rect.right = w; //if (rect.bottom >= h) rect.bottom = h; iMainImage->SetMark(mrect); //7.41 iMainImage->RectPaint(rect); } } return; fail: iMainImage->Bitmap->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::check(int sx, int sy, int wale, int course, RECT *rect) { Byte *IP, *JP, set; bool find; int x, y, xx, yy, len, psx, psy, w, c; if (iMainImage->ArrayBitmap[1].Width <= sx+wale || iMainImage->ArrayBitmap[1].Height <= sy+course) return false; iMainImage->ArrayBitmap[1].StartScanLine(); for (y=0; yArrayBitmap[1].GetScanLine(sy+y); for (x=0; x 1) { w = Arrange->Dmark.sp[(IP[sx + x] & 0x3F)]->wale; c = Arrange->Dmark.sp[(IP[sx + x] & 0x3F)]->course; find = false; for (yy=0; yyArrayBitmap[1].GetScanLine(sy+y-yy); for(xx=0; xxArrayBitmap[1].GetScanLine(psy+yy); for(xx=0; xxDmark.set & 0x40) | 0x01; } iMainImage->ArrayBitmap[1].PutScanLine(psy+yy); } if (rect) { rect->left = (rect->leftleft : psx); rect->right = (rect->right>psx+w ? rect->right : psx+w); rect->top = (rect->toptop : psy); rect->bottom= (rect->bottom>psy+c ? rect->bottom : psy+c); } } } } iMainImage->ArrayBitmap[1].StopScanLine(); return true; } //--------------------------------------------------------------------------- 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 formDCState; int ls, rs, left, top, right, bottom, x, y; formDC = iMainImage->Canvas->Handle; formDCState = SaveDC(formDC); /* needed because we select a region */ 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); RestoreDC(formDC, formDCState); } } //--------------------------------------------------------------------------- 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); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawLineLocate(POINT First, POINT Second,int NOL) { HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; int formDCState; POINT pt; formDC = iMainImage->Canvas->Handle; formDCState = SaveDC(formDC); /* needed because we select a region */ 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); RestoreDC(formDC, formDCState); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawRectangleLocate(RECT rc,int NOR, bool ToKnit) { HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; int formDCState; RECT rr; if (ToKnit) { ConvertRegion(rc, &rc, ToKnit); } formDC = iMainImage->Canvas->Handle; formDCState = SaveDC(formDC); /* needed because we select a region */ 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)+1, max(rr.left, rr.right), max(rr.top, rr.bottom)+1); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); RestoreDC(formDC, formDCState); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawEllipseLocate(RECT rc,int NOE) { HDC formDC; HBRUSH hOldBrush; HPEN hOldPen; int nDrawMode; int formDCState; RECT rr; formDC = iMainImage->Canvas->Handle; formDCState = SaveDC(formDC); /* needed because we select a region */ 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)+1, max(rr.left, rr.right), max(rr.top, rr.bottom)+1); SetROP2(formDC, nDrawMode); SelectObject(formDC, hOldBrush); SelectObject(formDC, hOldPen); RestoreDC(formDC, formDCState); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SearchWholeColor(TChoiceColor *ChoiceColor) { int x, y; Byte *bp; iMainImage->ArrayBitmap[0].StartScanLine(); for (y=0; yArrayBitmap[0].Height; y++) { bp = iMainImage->ArrayBitmap[0].GetScanLine(y); for (x=0; xArrayBitmap[0].Width; x++) { ChoiceColor->Add(Palette, *(bp+x)); } } iMainImage->ArrayBitmap[0].StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::SearchWorkAreaColor(TChoiceColor *ChoiceColor) { Byte *mp, mm, *bp; int x, y; WorkArea->Mask->StartScanLine(); iMainImage->ArrayBitmap[0].StartScanLine(); if (iMainImage->ArrayBitmap[0].BitsPerPixel==8) { for (y=WorkArea->Range.top; yRange.bottom; y++) { bp = iMainImage->ArrayBitmap[0].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)); } } } } WorkArea->Mask->StopScanLine(); iMainImage->ArrayBitmap[0].StopScanLine(); } //--------------------------------------------------------------------------- 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; if (DesignMode == D_MARK) c = 0; else c = PaletteForm->DIB256Palette->GetBGCOLORREF(iMainImage->Bitmap->BitsPerPixel); if (WorkArea->Mask) { if ((undoSw = UndoSave(UK_ALL, WorkArea->Range, true))==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); } if (DesignMode == D_MARK) iMainImage->SetMark(); 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; if (DesignMode == D_KNIT) { EXCEPTION_MESSAGE_OK(EC_UNABLE_CLIPBOARD); return; } if (!IsClipboardFormatAvailable(MainForm->ClipboardFormat[DesignMode%2])) { if (IsClipboardFormatAvailable(MainForm->ClipboardFormat[(DesignMode+1)%2])) { EXCEPTION_MESSAGE_OK(EC_UNAVAILABLE_CLIPBOARD); return; } } 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[DesignMode%2])) { if ((hMem = GetClipboardData(MainForm->ClipboardFormat[DesignMode%2]))==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 (DesignMode == D_YARN) { 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 if (DesignMode == D_MARK) { if ((ec = ReadMarkFormat(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 (DesignMode == D_YARN || (DesignMode == D_MARK && iMainImage->ZoomIn != 16)) { 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); } iSelectImageSize(); Center.x = iSelectImage->Bitmap->Width/2; Center.y = iSelectImage->Bitmap->Height/2; POINT pt; //add by qe ¸¶¿ì¼­ Ä¿¼­ ÇöÀç À§Ä¡¸¦ ¹Þ¾Æ¼­ ±× À§Ä¡¿¡ SelectImage º¸¿©ÁÜ. GetCursorPos(&pt); pt = iMainImage->ScreenToClient(pt); pt.x = iMainImage->CanvasToBitmapX(pt.x); pt.y = iMainImage->CanvasToBitmapY(pt.y); IsMerge(iSelectImagePosition(Point(pt.x-Center.x, pt.y-Center.y))); iSelectImage->Visible = true; } else { iSelectImage->Bitmap->Destroy(); iSelectImage->Visible = false; Center.x = TempBitmap->Width/2; Center.y = TempBitmap->Height/2; } PenManagerForm->SetColor(Palette); 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); } //--------------------------------------------------------------------- void __fastcall TMainImageForm::InitOverlap(void) { if (iMainImage->Bitmap->BitsPerPixel==8) { overlapdata = (Byte *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 252*252); } } //--------------------------------------------------------------------- void __fastcall TMainImageForm::ExitOverlap(void) { if (iMainImage->Bitmap->BitsPerPixel==8) { HeapFree(GetProcessHeap(), 0, overlapdata); overlapdata = NULL; } } //--------------------------------------------------------------------- COLORREF __fastcall TMainImageForm::Overlap(COLORREF base, COLORREF cover) { int point = PaletteForm->DIB256Palette->UseColor; RGBQUAD rgb[256]; if (iMainImage->Bitmap->BitsPerPixel==8) { if (base && cover) { if (base==cover) return base; else { if (point>=251) return 0xFF; if (overlapdata[base*252+cover]) return overlapdata[base*252+cover]; point++; PaletteForm->DIB256Palette->UseColor = point; overlapdata[base*252+cover] = overlapdata[cover*252+base] = point; Palette->ColorData[point]->RGB.rgbRed = (Palette->ColorData[base]->RGB.rgbRed*(63-FullViewForm->OverlapDensity)+ Palette->ColorData[cover]->RGB.rgbRed*FullViewForm->OverlapDensity)/63; Palette->ColorData[point]->RGB.rgbGreen = (Palette->ColorData[base]->RGB.rgbGreen*(63-FullViewForm->OverlapDensity)+ Palette->ColorData[cover]->RGB.rgbGreen*FullViewForm->OverlapDensity)/63; Palette->ColorData[point]->RGB.rgbBlue = (Palette->ColorData[base]->RGB.rgbBlue*(63-FullViewForm->OverlapDensity)+ Palette->ColorData[cover]->RGB.rgbBlue*FullViewForm->OverlapDensity)/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-FullViewForm->OverlapDensity)+rgb[1].rgbRed*FullViewForm->OverlapDensity)/63; rgb[2].rgbGreen = (rgb[0].rgbGreen*(63-FullViewForm->OverlapDensity)+rgb[1].rgbGreen*FullViewForm->OverlapDensity)/63; rgb[2].rgbBlue = (rgb[0].rgbBlue*(63-FullViewForm->OverlapDensity)+rgb[1].rgbBlue*FullViewForm->OverlapDensity)/63; return RGBToTColor(rgb[2]); } } } //---------------------------------------------------------------------------- bool __fastcall TMainImageForm::UndoSave(int k, RECT r, bool down) { Undo->Save(k, r, down); if (DesignMode == D_MARK && (k & UK_MARK) == 0) { Undo->InsertMarkData(); } Modify = true; } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::UndoSave(int k) { Undo->Save(k); Modify = true; } //--------------------------------------------------------------------------- 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) { OnSetHLine = SetHLineMask8; if (PenManagerForm->chDelete->Checked) { MaskPixel = 0x00; } else { MaskPixel = 0x0F; } } else { 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 if (MainMenuForm->Item == T_DRAW) { if (PenManagerForm->Type == PT_MASK) { OnSetHLine = SetHLineMask8; if (PenManagerForm->chDelete->Checked) { MaskPixel = 0x00; } else { MaskPixel = 0x0F; } } else { OnSetHLine = SetHLine8ColorNo; } } } //--------------------------------------------------------------------------- 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() { if (CurrentUnit==uDot) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%d : %d", OPENARRAY(TVarRec, ((int)CursorPosition.x, (int)CursorPosition.y))); } else if (CurrentUnit==uInch) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%f : %f", OPENARRAY(TVarRec, ((double)CursorPosition.x/CanvasInfor.DotsPerInch, (double)CursorPosition.y/CanvasInfor.DotsPerInch))); } else if (CurrentUnit==uCm) { MainForm->StatusBar->Panels->Items[StatusBarAxis]->Text = Format("%f : %f", OPENARRAY(TVarRec, (2.54*CursorPosition.x/CanvasInfor.DotsPerInch, 2.54*CursorPosition.y/CanvasInfor.DotsPerInch))); } if (sbRuler) { if (sbRuler->Down) Ruler->PositionBar(CursorPosition); } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Timer1000ms() { if (!BtnClick) iMainImage->OutlineBitmapRgn(WorkArea->bComplex); } //--------------------------------------------------------------------- void __fastcall TMainImageForm::ChangeColor(int Index) { RGBQUAD rgb[256]; Tdesign_yarn *dyn; bool find = false; double h, l, s; int i, j, count = 0; if (Index > 1) { dyn = &Arrange->Dyarn; for (i = 1; i <= dyn->cnt; i++) { for (j = 0; j < dyn->data[i].cnt; j++) { if (dyn->data[i].color[j] == Index) { find = true; goto next; } count++; } } next: if (find) { iMainImage->ArrayBitmap[2].GetColors(0, 256, rgb); i = 5 + count* 7; rgb[i] = PaletteForm->DIB256Palette->Palette->ColorData[Index]->RGB; RGBQUAD2HLS(rgb[i], h, l, s); rgb[i-3] = HLS2RGBQUAD(h, l-0.12<0 ? 0 : l-0.12, s); rgb[i-2] = HLS2RGBQUAD(h, l-0.08<0 ? 0 : l-0.08, s); rgb[i-1] = HLS2RGBQUAD(h, l-0.04<0 ? 0 : l-0.04, s); rgb[i+1] = HLS2RGBQUAD(h, l+0.04>1 ? 1 : l+0.04, s); rgb[i+2] = HLS2RGBQUAD(h, l+0.08>1 ? 1 : l+0.08, s); rgb[i+3] = HLS2RGBQUAD(h, l+0.12>1 ? 1 : l+0.12, s); iMainImage->ArrayBitmap[2].PutColors(0, 256, rgb); } } else { iMainImage->ArrayBitmap[2].GetColors(0, 256, rgb); rgb[Index] = PaletteForm->DIB256Palette->Palette->ColorData[Index]->RGB; iMainImage->ArrayBitmap[2].PutColors(0, 256, rgb); } } //--------------------------------------------------------------------- Byte __fastcall TMainImageForm::GetPaletteIndex(Byte c) { Tdesign_yarn *dyn; int i, j, count = 0, k; dyn = &Arrange->Dyarn; k = (c-2) / 7; for (i = 1; i <= dyn->cnt; i++) { for (j = 0; j < dyn->data[i].cnt; j++) { if (k == count) return dyn->data[i].color[j]; count++; } } return 1; } //--------------------------------------------------------------------- void __fastcall TMainImageForm::ConvertRegion(RECT rect, RECT *r, bool ToKnit) { int wpi, cpi, dpi, h0, h2; double wrate, crate; dpi = CanvasInfor.DotsPerInch; h0 = iMainImage->ArrayBitmap[0].Height; h2 = iMainImage->ArrayBitmap[2].Height; if (ToKnit) { wrate = (double) dpi / Arrange->kdsn.wpi; crate = (double) dpi / Arrange->kdsn.cpi; r->left = rect.left * wrate; r->right = rect.right * wrate; r->top = h2 - (h0 - rect.top) * crate; r->bottom = h2 - (h0 - rect.bottom) * crate; if (r->right > iMainImage->ArrayBitmap[2].Width) r->right = iMainImage->ArrayBitmap[2].Width; if (r->bottom > iMainImage->ArrayBitmap[2].Height) r->bottom = iMainImage->ArrayBitmap[2].Height; } else { wrate = (double) Arrange->kdsn.wpi / dpi; crate = (double) Arrange->kdsn.cpi / dpi; r->left = rect.left * wrate + 0.5; r->right = rect.right * wrate - 0.5; r->top = h0 - (h2 - rect.top) * crate + 0.5; r->bottom = h0 - (h2 - rect.bottom) * crate - 0.5; if (r->right > iMainImage->ArrayBitmap[0].Width) r->right = iMainImage->ArrayBitmap[0].Width; if (r->bottom > iMainImage->ArrayBitmap[0].Height) r->bottom = iMainImage->ArrayBitmap[0].Height; } } //--------------------------------------------------------------------------- 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::RepaintKnitColor() { Tdesign_yarn *dyn; int i, j, k, Index, count = 0; double h, l, s; RGBQUAD rgb[256]; dyn = &Arrange->Dyarn; iMainImage->ArrayBitmap[2].GetColors(0, 256, rgb); rgb[1] = PaletteForm->DIB256Palette->Palette->ColorData[1]->RGB; for (i = 1; i <= dyn->cnt; i++) { for (j = 0; j < dyn->data[i].cnt; j++) { Index = dyn->data[i].color[j]; k = 5 + count* 7; rgb[k] = PaletteForm->DIB256Palette->Palette->ColorData[Index]->RGB; RGBQUAD2HLS(rgb[k], h, l, s); rgb[k-3] = HLS2RGBQUAD(h, l-0.12<0 ? 0 : l-0.12, s); rgb[k-2] = HLS2RGBQUAD(h, l-0.08<0 ? 0 : l-0.08, s); rgb[k-1] = HLS2RGBQUAD(h, l-0.04<0 ? 0 : l-0.04, s); rgb[k+1] = HLS2RGBQUAD(h, l+0.04>1 ? 1 : l+0.04, s); rgb[k+2] = HLS2RGBQUAD(h, l+0.08>1 ? 1 : l+0.08, s); rgb[k+3] = HLS2RGBQUAD(h, l+0.12>1 ? 1 : l+0.12, s); count++; } } iMainImage->ArrayBitmap[2].PutColors(0, 256, rgb); PaletteForm->KnitChangeColor(); ::RepaintColor(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawOutLine(TTexpiaBitmap *Pattern, int H, AnsiString form) { int w, h, x, A4Width, A4Height; AnsiString str, company = "", date, time; TRegIniFile *Reg = NULL; TCanvas *Canvas = NULL; Reg = new TRegIniFile(""); if (Reg) { Reg->RootKey = HKEY_LOCAL_MACHINE; if (Reg->OpenKey("\\SOFTWARE\\MicroSoft\\Windows", false)) company = Reg->ReadString("CurrentVersion", "RegisteredOrganization", ""); delete Reg; } A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); A4Height = GetDeviceCaps(Printer()->Handle, VERTRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); w = A4Width-1; h = A4Height-1; if((Canvas = Pattern->CreateCanvas()) == NULL) goto fail; Canvas->Font->Size = 15; Canvas->Font->Color = clPurple; Canvas->MoveTo(0, H); Canvas->LineTo(w, H); Canvas->LineTo(w, H+30); Canvas->LineTo(0, H+30); Canvas->LineTo(0, H); str = "PATTERN NAME : " + FileName + form; Canvas->TextOut(30, H+5, str); date = DateToStr(Date()); time = TimeToStr(Time()); str = Format("%s %s", OPENARRAY(TVarRec, (date.c_str(), time.c_str()))); x = w - Canvas->TextWidth(str) - 20; Canvas->TextOut(x, H+5, str); Canvas->Font->Size = 12; Canvas->Font->Color = clBlack; Canvas->MoveTo(0, H+35); Canvas->LineTo(w, H+35); Canvas->LineTo(w, H+h-22); Canvas->LineTo(0, H+h-22); Canvas->LineTo(0, H+35); x = Canvas->TextWidth(company); Canvas->TextOut(w-x-80, H+h-19, company); Pattern->DeleteCanvas(Canvas); Canvas = NULL; return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ImageA4Print(TTexpiaBitmap *Pattern, int HeaderNo) { int w, h, A4Width, A4Height; int top, left, hei_gab, chipHeight, stchip, chiph; HDC hDC = NULL, phDC = NULL; RGBQUAD rgb[256]; int EC = EC_NONE; A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); A4Height = GetDeviceCaps(Printer()->Handle, VERTRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); w = A4Width-(5+5)-1; h = A4Height-(30+5+5+5+22)-1; iMainImage->ArrayBitmap[2].GetColors(0, 256, rgb); if (!(Pattern->Create(A4Width, A4Height, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); DrawOutLine(Pattern, 0, " [Image]"); if (iMainImage->ArrayBitmap[2].WidthArrayBitmap[2].Width; } left = 5; top = 40; if (HeaderNo) { //Header NO if (iMainImage->ArrayBitmap[2].Height>=h) { hei_gab = iMainImage->ArrayBitmap[2].Height - h; } else { h = iMainImage->ArrayBitmap[2].Height; hei_gab = 0; } if ((hDC = iMainImage->ArrayBitmap[2].CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, hDC, 0, hei_gab, SRCCOPY); Pattern->DeleteDC(phDC); iMainImage->ArrayBitmap[2].DeleteDC(hDC); } else { //Header Yes chipHeight = Cal_ChipHeight(); h = h - (chipHeight + 5); if (iMainImage->ArrayBitmap[2].Height>=h) { hei_gab = iMainImage->ArrayBitmap[2].Height - h; } else { h = iMainImage->ArrayBitmap[2].Height; hei_gab = 0; } if ((hDC = iMainImage->ArrayBitmap[2].CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, hDC, 0, hei_gab, SRCCOPY); Pattern->DeleteDC(phDC); iMainImage->ArrayBitmap[2].DeleteDC(hDC); stchip = top + h + 5; chiph = 5+20+5+25; Call_DrawColorChip(Pattern, 1, stchip, chiph); } return; fail: if (hDC) iMainImage->ArrayBitmap[2].DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::ImageFreePrint(TTexpiaBitmap *Pattern, int w, int h, int rep_x, int rep_y, TPoint spoint, int HeaderNo) { HDC hDC = NULL, phDC = NULL; RGBQUAD rgb[256]; int A4Width, chipHeight, chiph, stchip, pbh, pbw; int i, j, EC = EC_NONE; pbw = w*rep_x; if (HeaderNo) { pbh = h*rep_y; } else { A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); if (w*rep_x < A4Width) pbw = A4Width; chipHeight = Cal_ChipHeight(); pbh = h*rep_y + chipHeight + 5; } iMainImage->ArrayBitmap[2].GetColors(0, 256, rgb); if (!(Pattern->Create(pbw, pbh, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((hDC = iMainImage->ArrayBitmap[2].CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} for (i=0; iDeleteDC(phDC); iMainImage->ArrayBitmap[2].DeleteDC(hDC); if (!HeaderNo) { stchip = h*rep_y + 5; chiph = 5+20+5+25; Call_DrawColorChip(Pattern, 1, stchip, chiph); } return; fail: if (hDC) iMainImage->ArrayBitmap[2].DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::YarnA4Print(TTexpiaBitmap *Pattern, int HeaderNo) { int w, h, A4Width, A4Height; int top, left, hei_gab; HDC hDC = NULL, phDC = NULL, thDC = NULL; RGBQUAD rgb[256]; TTexpiaBitmap *Temp = NULL; TPoint sp; int DPI, wpi, cpi; int chipHeight, stchip, chiph; int EC = EC_NONE; DPI = MainImageForm->CanvasInfor.DotsPerInch; wpi = Arrange->kdsn.wpi; cpi = Arrange->kdsn.cpi; A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); A4Height = GetDeviceCaps(Printer()->Handle, VERTRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); w = A4Width-(5+5)-1-25-25; h = A4Height-(30+5+5+5+22)-1-25-25; left = 30; top = 65; iMainImage->ArrayBitmap[0].GetColors(0, 256, rgb); if ((Temp = new TTexpiaBitmap) == NULL) {EC = EC_MEMORY_LACK; goto fail;} if (!(Temp->Create(iMainImage->ArrayBitmap[0].Width*(DPI/wpi), iMainImage->ArrayBitmap[0].Height*(DPI/cpi), 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} if (!(Pattern->Create(A4Width, A4Height, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} Temp->FillRect(Rect(0, 0, Temp->Width, Temp->Height), clWhite); Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((hDC = iMainImage->ArrayBitmap[0].CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} SetStretchBltMode(thDC, COLORONCOLOR); StretchBlt(thDC, 0, 0, Temp->Width, Temp->Height, hDC, 0, 0, iMainImage->ArrayBitmap[0].Width, iMainImage->ArrayBitmap[0].Height, SRCCOPY); Temp->DeleteDC(thDC); iMainImage->ArrayBitmap[0].DeleteDC(hDC); DrawOutLine(Pattern, 0, " [Yarn]"); if (Temp->WidthWidth; if (HeaderNo) { //Header NO if (Temp->Height>=h) { hei_gab = Temp->Height - h; } else { h = Temp->Height; hei_gab = 0; } if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, thDC, 0, hei_gab, SRCCOPY); Temp->DeleteDC(thDC); Pattern->DeleteDC(phDC); } else { //Header YES chipHeight = Cal_ChipHeight(); h = h - (chipHeight + 5); if (Temp->Height>=h) { hei_gab = Temp->Height - h; } else { h = Temp->Height; hei_gab = 0; } if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, thDC, 0, hei_gab, SRCCOPY); Temp->DeleteDC(thDC); Pattern->DeleteDC(phDC); stchip = top + h + 30; chiph = 5+20+5+25; Call_DrawColorChip(Pattern, 0, stchip, chiph); } sp.x = left; sp.y = top+h; DrawGrid(Pattern, w, h, sp, DPI/wpi, DPI/cpi, true); delete Temp; return; fail: if (phDC) Pattern->DeleteDC(phDC); if (hDC) iMainImage->ArrayBitmap[0].DeleteDC(hDC); if (Temp) delete Temp; EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::YarnFreePrint(TTexpiaBitmap *Pattern, int w, int h, TPoint spoint, int HeaderNo) { HDC hDC = NULL, phDC = NULL; RGBQUAD rgb[256]; int DPI, wpi, cpi, k, stchip, chiph, chipHeight, A4Width; int pbw, pbh, EC = EC_NONE; TPoint sp; DPI = MainImageForm->CanvasInfor.DotsPerInch; wpi = Arrange->kdsn.wpi; cpi = Arrange->kdsn.cpi; k = DPI/wpi; //==========Compensate if (w%k) w = (w/k + 1)*k; k = DPI/cpi; if (h%k) h = (h/k +1)*k; pbw = w + 60; if (HeaderNo) { pbh = h + 60; } else { A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); if((w+60)ArrayBitmap[0].GetColors(0, 256, rgb); if (!(Pattern->Create(pbw, pbh, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); if ((hDC = iMainImage->ArrayBitmap[0].CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} SetStretchBltMode(phDC, COLORONCOLOR); StretchBlt(phDC, 30, 30, w, h, hDC, spoint.x, spoint.y, w/(DPI/wpi), h/(DPI/cpi), SRCCOPY); Pattern->DeleteDC(phDC); iMainImage->ArrayBitmap[0].DeleteDC(hDC); sp.x = 30, sp.y = h+30; DrawGrid(Pattern, w, h, sp, DPI/wpi, DPI/cpi, true); if (!HeaderNo) { stchip = 30 + h + 30; chiph = 5+20+5+25; Call_DrawColorChip(Pattern, 0, stchip, chiph); } return; fail: if (hDC) iMainImage->ArrayBitmap[0].DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::MarkA4Print(TTexpiaBitmap *Pattern) { int w, h, A4Width, A4Height; int top, left, hei_gab; HDC phDC = NULL, thDC = NULL; RGBQUAD rgb[256]; TTexpiaBitmap *Temp = NULL; TPoint sp; int EC = EC_NONE; A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); A4Height = GetDeviceCaps(Printer()->Handle, VERTRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); w = A4Width-(5+5)-1-25-25; h = A4Height-(30+5+5+5+22)-1-25-25; left = 30; top = 65; rgb[0].rgbRed = 0; rgb[0].rgbBlue = 0; rgb[0].rgbGreen = 0; rgb[1].rgbRed = 255; rgb[1].rgbBlue = 0; rgb[1].rgbGreen = 0; rgb[2].rgbRed = 0; rgb[2].rgbBlue = 255; rgb[2].rgbGreen = 0; rgb[3].rgbRed = 0; rgb[3].rgbBlue = 0; rgb[3].rgbGreen = 255; rgb[4].rgbRed = 0; rgb[4].rgbBlue = 255; rgb[4].rgbGreen = 255; rgb[5].rgbRed = 255; rgb[5].rgbBlue = 0; rgb[5].rgbGreen = 255; rgb[6].rgbRed = 255; rgb[6].rgbBlue = 255; rgb[6].rgbGreen = 0; rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; if ((Temp = new TTexpiaBitmap) == NULL) {EC = EC_MEMORY_LACK; goto fail;} if (!(Temp->Create(iMainImage->ArrayBitmap[1].Width*16, iMainImage->ArrayBitmap[1].Height*16, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} if(!(Pattern->Create(A4Width, A4Height, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} Temp->FillRect(Rect(0, 0, Temp->Width, Temp->Height), clWhite); Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); sp.x = 0; sp.y = 0; DrawMark(Temp, iMainImage->ArrayBitmap[1].Width, iMainImage->ArrayBitmap[1].Height, sp); if (Temp->WidthWidth; if (Temp->Height>=h) { hei_gab = Temp->Height - h; } else { h = Temp->Height; hei_gab = 0; } DrawOutLine(Pattern, 0, " [Mark]"); if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, thDC, 0, hei_gab, SRCCOPY); Temp->DeleteDC(thDC); Pattern->DeleteDC(phDC); sp.x = left; sp.y = top+h; DrawGrid(Pattern, w, h, sp, 16, 16, false); delete Temp; return; fail: if (phDC) Pattern->DeleteDC(phDC); if (Temp) delete Temp; EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::MarkFreePrint(TTexpiaBitmap *Pattern, int w, int h, TPoint spoint) { RGBQUAD rgb[256]; TPoint sp; int top, left, i, x, y, comp; int EC = EC_NONE; Byte *mk; HDC phDC = NULL, thDC = NULL; TTexpiaBitmap *Temp; if ( h%16) h = (h/16 + 1)*16; if ( w%16) w = (w/16 + 1)*16; rgb[0].rgbRed = 0; rgb[0].rgbBlue = 0; rgb[0].rgbGreen = 0; rgb[1].rgbRed = 255; rgb[1].rgbBlue = 0; rgb[1].rgbGreen = 0; rgb[2].rgbRed = 0; rgb[2].rgbBlue = 255; rgb[2].rgbGreen = 0; rgb[3].rgbRed = 0; rgb[3].rgbBlue = 0; rgb[3].rgbGreen = 255; rgb[4].rgbRed = 0; rgb[4].rgbBlue = 255; rgb[4].rgbGreen = 255; rgb[5].rgbRed = 255; rgb[5].rgbBlue = 0; rgb[5].rgbGreen = 255; rgb[6].rgbRed = 255; rgb[6].rgbBlue = 255; rgb[6].rgbGreen = 0; rgb[255].rgbRed = 255; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 255; if ((Temp = new TTexpiaBitmap) == NULL) {EC = EC_MEMORY_LACK; goto fail;} if (!(Temp->Create(w, h, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} if (!(Pattern->Create(w+60, h+60, 8, rgb))) {EC = EC_MEMORY_LACK; goto fail;} Temp->FillRect(Rect(0, 0, Temp->Width, Temp->Height), clWhite); Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); top = 30, left = 30; h = h/16; w = w/16; DrawMark(Temp, w, h, spoint); if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w*16, h*16, thDC, 0, 0, SRCCOPY); Temp->DeleteDC(thDC); Pattern->DeleteDC(phDC); sp.x = 30, sp.y = Pattern->Height-30; DrawGrid(Pattern, w*16, h*16, sp, 16, 16, false); delete Temp; return; fail: if (phDC) Pattern->DeleteDC(phDC); if (Temp) delete Temp; EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::MixA4Print(TTexpiaBitmap *Pattern, int HeaderNo) { int w, h, A4Width, A4Height; int top, left, hei_gab; int chipHeight, stchip, chiph, EC = EC_NONE; Byte *mk; HDC phDC = NULL, thDC = NULL; TPoint sp; RGBQUAD rgb[256]; TTexpiaBitmap *Temp; A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); A4Height = GetDeviceCaps(Printer()->Handle, VERTRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSY); w = A4Width-(5+5)-1-25-25; h = A4Height-(30+5+5+5+22)-1-25-25; left = 30; top = 65; sp.x = sp.y = 0; if ((Temp = new TTexpiaBitmap) == NULL) {EC = EC_MEMORY_LACK; goto fail;} if (!(Temp->Create(iMainImage->ArrayBitmap[0].Width*16, iMainImage->ArrayBitmap[0].Height*16, 24))) {EC = EC_MEMORY_LACK; goto fail;} if (!(Pattern->Create(A4Width, A4Height, 24))) {EC = EC_MEMORY_LACK; goto fail;} Temp->FillRect(Rect(0, 0, Temp->Width, Temp->Height), clWhite); Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); Draw_MixYarn(Temp, iMainImage->ArrayBitmap[0].Width, iMainImage->ArrayBitmap[0].Height, sp); Mix_DrawMark(Temp, iMainImage->ArrayBitmap[1].Width, iMainImage->ArrayBitmap[1].Height, sp); DrawOutLine(Pattern, 0, " [Mix]"); if (Temp->Width<=w) w = Temp->Width; if (HeaderNo) { //Header NO if (Temp->Height>=h) { hei_gab = Temp->Height - h; } else { h = Temp->Height; hei_gab = 0; } } else { //Header YES chipHeight = Cal_ChipHeight(); h = h - (chipHeight + 5); if (Temp->Height>=h) { hei_gab = Temp->Height - h; } else { h = Temp->Height; hei_gab = 0; } stchip = top + h + 30; chiph = 5+20+5+25; Call_DrawColorChip(Pattern, 2, stchip, chiph); } if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, thDC, 0, hei_gab, SRCCOPY); Temp->DeleteDC(thDC); Pattern->DeleteDC(phDC); sp.x = left; sp.y = top+h; DrawGrid(Pattern, w, h, sp, 16, 16, true); delete Temp; return; fail: if (phDC) Pattern->DeleteDC(phDC); if (Temp) delete Temp; EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::MixFreePrint(TTexpiaBitmap *Pattern, int w, int h, TPoint spoint, int HeaderNo) { int top, left, A4Width; int chiph, chipHeight, stchip; int rtn, size, n, bw, bh, k; int pbw, pbh, EC = EC_NONE; RGBQUAD rgb[256]; TPoint sp; Byte *mk; HDC thDC = NULL, phDC = NULL; TTexpiaBitmap *Temp = NULL; if ( w%16) w = (w/16 + 1)*16; if ( h%16) h = (h/16 + 1)*16; pbw = w + 60; if (HeaderNo) { pbh = h + 60; } else { A4Width = GetDeviceCaps(Printer()->Handle, HORZRES)*CanvasInfor.DotsPerInch/ GetDeviceCaps(Printer()->Handle, LOGPIXELSX); if (w+60 < A4Width) pbw = A4Width; chipHeight = Cal_ChipHeight(); pbh = h+60+chipHeight+5; } left = 30; top = 30; if ((Temp = new TTexpiaBitmap) == NULL) {EC = EC_MEMORY_LACK; goto fail;} if (!(Temp->Create(w, h, 24))) {EC = EC_MEMORY_LACK; goto fail;} if (!(Pattern->Create(pbw, pbh, 24))) {EC = EC_MEMORY_LACK; goto fail;} Temp->FillRect(Rect(0, 0, Temp->Width, Temp->Height), clWhite); Pattern->FillRect(Rect(0, 0, Pattern->Width, Pattern->Height), clWhite); Draw_MixYarn(Temp, w/16, h/16, spoint); Mix_DrawMark(Temp, w/16, h/16, spoint); if ((phDC = Pattern->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} BitBlt(phDC, left, top, w, h, thDC, 0, 0, SRCCOPY); Temp->DeleteDC(thDC); Pattern->DeleteDC(phDC); sp.x = left; sp.y = top+h; DrawGrid(Pattern, w, h, sp, 16, 16, true); if (!HeaderNo) { stchip = top + h + 30; chiph = 5+20+5+25; Call_DrawColorChip(Pattern, 2, stchip, chiph); } delete Temp; return; fail: if (phDC) Pattern->DeleteDC(phDC); if (Temp) delete Temp; EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Draw_MixYarn(TTexpiaBitmap *MY_Temp, int bw, int bh, TPoint sp) { int rtn, size, n, k; HDC hDC = NULL, thDC = NULL; int tx, ty, x, y, WWW, HHH, SW, SH, DW, DH; bool remain_x = false, remain_y = false, div_x = true, div_y = true; if ((hDC = iMainImage->ArrayBitmap[0].CreateDC()) == NULL) goto fail; if ((thDC = MY_Temp->CreateDC()) == NULL) goto fail; SetStretchBltMode(thDC, COLORONCOLOR); rtn = 0; tx = 1; ty = 1; WWW = bw; HHH = bh; while (div_x || div_y) { SW = WWW / tx; SH = HHH / ty; if (SW == 0) { tx -= 1; SW = WWW/tx; div_x = false; } if (SH == 0) { ty -= 1; SH = HHH/ty; div_y = false; } DW = 16*SW; DH = 16*SH; if (tx*SW < WWW) remain_x = true; if (ty*SH < HHH) remain_y = true; rtn = StretchBlt(thDC, 0, 0, DW, DH, hDC, sp.x, sp.y, SW, SH, SRCCOPY); if (rtn) { for (y=0; yDeleteDC(thDC); iMainImage->ArrayBitmap[0].DeleteDC(hDC); return; /* if ((hDC = iMainImage->ArrayBitmap[0].CreateDC()) == NULL) goto fail; if ((thDC = MY_Temp->CreateDC()) == NULL) goto fail; SetStretchBltMode(thDC, COLORONCOLOR); n=1; if (bh >= bw) { while (true) { size = bh/n; if (size == 0) { ShowMessage(IDS_MESSAGE); return; } for (k=0; kWidth, 16*(bh-size*k), hDC, sp.x, sp.y + size*k, bw, bh-size*k, SRCCOPY); } else { rtn = StretchBlt(thDC, 0, 16*size*k, MY_Temp->Width, 16*size, hDC, sp.x, sp.y + size*k, bw, size, SRCCOPY); } if (rtn == 0) break; } if (rtn) break; else n++; } } else { while (true) { size = bw/n; if (size == 0) { ShowMessage(IDS_MESSAGE); return; } for (k=0; kHeight, hDC, sp.x + size*k, sp.y, bw-size*k, bh, SRCCOPY); } else { rtn = StretchBlt(thDC, 16*(size*k), 0, 16*size, MY_Temp->Height, hDC, sp.x + size*k, sp.y, size, bh, SRCCOPY); } if (rtn == 0) break; //When fail StretchBlt } if (rtn) break; else n++; } } MY_Temp->DeleteDC(thDC); iMainImage->ArrayBitmap[0].DeleteDC(hDC); return; */ fail: if (hDC) iMainImage->ArrayBitmap[0].DeleteDC(hDC); EXCEPTION_MESSAGE_OK(EC_RESOURCE_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawMark(TTexpiaBitmap *Mbmp, int w, int h, TPoint sp) { int comp, x, y, i, EC = EC_NONE; int sizex, sizey, stx, sty, bkcnt = 0; bool execute = false; RGBQUAD rgb[256]; Byte *mk; HDC thDC = NULL, shDC; rgb[0].rgbRed = rgb[0].rgbBlue = rgb[0].rgbGreen = 255; rgb[255].rgbRed = 255; rgb[255].rgbBlue = 0; rgb[255].rgbGreen = 0; SetDIBColorTable(Mark[0]->DC, 0, 256, rgb); rgb[0].rgbRed = rgb[0].rgbBlue = rgb[0].rgbGreen = 255; rgb[255].rgbRed = 0; rgb[255].rgbBlue = 255; rgb[255].rgbGreen = 0; SetDIBColorTable(Mark[1]->DC, 0, 256, rgb); rgb[0].rgbRed = rgb[0].rgbBlue = rgb[0].rgbGreen = 255; rgb[255].rgbRed = rgb[255].rgbBlue = 0; rgb[255].rgbGreen = 255; for (i=2; iDmark.cnt; i++) { SetDIBColorTable(Mark[i]->DC, 0, 256, rgb); } if (!(iMainImage->ArrayBitmap[1].StartScanLine())) {EC = EC_MEMORY_LACK; goto fail;} if ((thDC = Mbmp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} for (y=0; yArrayBitmap[1].GetScanLine(y+sp.y); //+sp.x; for (x=0; xDC; } else { //Back (1) shDC = Mark[1]->DC; } execute = true; stx = 0; sty = 0; sizex = 15; sizey = 15; } else if (comp > 1){ //Cross if ((mk[x+sp.x] & 0x80) == 0) { //Start Point execute = true; shDC = Mark[comp]->DC; stx = 0; sty = 0; sizex = Arrange->Dmark.sp[comp]->wale*16-1; sizey = Arrange->Dmark.sp[comp]->course*16-1; } else { if (x==0) { bkcnt = 1; while(mk[sp.x-bkcnt] & 0x80) { bkcnt++; } shDC = Mark[comp]->DC; sizex = (Arrange->Dmark.sp[comp]->wale - bkcnt)*16-1; sizey = Arrange->Dmark.sp[comp]->course*16-1; stx = 16*bkcnt; sty = 0; } else { execute = false; } } } if (execute) { BitBlt(thDC, 16*x+1, 16*y+1, sizex, sizey, shDC, stx, sty, SRCCOPY); execute = false; } } } Mbmp->DeleteDC(thDC); iMainImage->ArrayBitmap[1].StopScanLine(); rgb[0].rgbRed = rgb[0].rgbBlue = rgb[0].rgbGreen = 0; rgb[255].rgbRed = rgb[255].rgbBlue = rgb[255].rgbGreen = 255; for (i=0; iDmark.cnt; i++) { SetDIBColorTable(Mark[i]->DC, 0, 256, rgb); } return; fail: iMainImage->ArrayBitmap[1].StopScanLine(); EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Mix_DrawMark(TTexpiaBitmap *Temp, int w, int h, TPoint spoint) { int comp, i,x, y, ave, bkcnt, EC = EC_NONE; RGBQUAD rgb[256]; Byte *mk, *yk; bool Paint, execute; HDC hYDC = NULL, hDC = NULL, thDC = NULL; TPoint start, size; if ((hYDC = iMainImage->ArrayBitmap[0].CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} GetDIBColorTable(hYDC, 0, 256, rgb); for(i=0; i < Arrange->Dmark.cnt; i++) { SetDIBColorTable(Mark[i]->DC, 0, 256, rgb); } iMainImage->ArrayBitmap[0].DeleteDC(hYDC); if (!(iMainImage->ArrayBitmap[0].StartScanLine())) {EC = EC_MEMORY_LACK; goto fail;} if (!(iMainImage->ArrayBitmap[1].StartScanLine())) {EC = EC_MEMORY_LACK; goto fail;} if ((thDC = Temp->CreateDC()) == NULL) {EC = EC_RESOURCE_LACK; goto fail;} for (y=0; yArrayBitmap[0].GetScanLine(y+spoint.y)+spoint.x; mk = iMainImage->ArrayBitmap[1].GetScanLine(y+spoint.y); for (x=0; xDC; } else { //Back (1) hDC = Mark[1]->DC; } size.x =15; size.y = 15; start.x = 0; start.y = 0; execute = true; } else if (comp > 1){ //Cross if ((mk[x+spoint.x] & 0x80) == 0) { //Start Point hDC = Mark[comp]->DC; size.x = Arrange->Dmark.sp[comp]->wale*16-1; size.y = Arrange->Dmark.sp[comp]->course*16-1; start.x = 0; start.y = 0; execute = true; } else { if (x == 0) { bkcnt=1; while(mk[spoint.x-bkcnt] & 0x80) { bkcnt++; } hDC = Mark[comp]->DC; size.x = (Arrange->Dmark.sp[comp]->wale-bkcnt)*16-1; size.y = Arrange->Dmark.sp[comp]->course*16-1; start.x = bkcnt*16; start.y = 0; execute = true; } else { execute = false; } } } if (execute) { if (ave < 384) { BitBlt(thDC, 16*x+1, 16*y+1, size.x, size.y, hDC, start.x, start.y, SRCPAINT); } else { BitBlt(thDC, 16*x+1, 16*y+1, size.x, size.y, NULL, 0, 0, DSTINVERT); BitBlt(thDC, 16*x+1, 16*y+1, size.x, size.y, hDC, start.x, start.y, NOTSRCERASE); } execute = false; } } } Temp->DeleteDC(thDC); iMainImage->ArrayBitmap[1].StopScanLine(); iMainImage->ArrayBitmap[0].StopScanLine(); rgb[0].rgbRed = rgb[0].rgbBlue = rgb[0].rgbGreen = 0; rgb[255].rgbRed = rgb[255].rgbBlue = rgb[255].rgbGreen = 255; for(i=0; i < Arrange->Dmark.cnt; i++) { SetDIBColorTable(Mark[i]->DC, 0, 256, rgb); } return; fail: iMainImage->ArrayBitmap[1].StopScanLine(); iMainImage->ArrayBitmap[0].StopScanLine(); EXCEPTION_MESSAGE_OK(EC); } //--------------------------------------------------------------------------- int __fastcall TMainImageForm::Cal_ChipHeight() { int max = 0, chipHeight = 0, chiph, i; chiph = 5+20+5+25; for (i=1; i<=Arrange->Dyarn.cnt; i++) { if (Arrange->Dyarn.data[i].type) { //Melange if (max < (Arrange->Dyarn.data[i].cnt*(25+5)+20+5)) max = Arrange->Dyarn.data[i].cnt*(25+5)+20+5; } else { if (!max) max = chiph; } if (!(i%7)) { chipHeight += max; max = 0; } } chipHeight += max; // ½ÇÀÇ °¹¼ö°¡ 7ÀÇ ¹è¼ö°¡ ¾Æ´Ñ°æ¿ì ¸¶Áö¸· ³ª¸ÓÁöÀÇ ³ôÀ̸¦ ÷°¡!! return chipHeight; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::Call_DrawColorChip(TTexpiaBitmap *P_ColorChip, int n, int chip_stp, int chip_h) { int i, j=0, max=0, col = 0; TPoint sp; for ( i=1; i<=Arrange->Dyarn.cnt; i++) { if (Arrange->Dyarn.data[i].type == 0) { sp = Point(10+col*(60+10+100+10), chip_stp+(25+5)); DrawColorChip(sp, i, j, P_ColorChip, n); col++; } else { for (j=0; jDyarn.data[i].cnt; j++) { sp = Point(10+col*(60+10+100+10), chip_stp+(25+5)*(j+1)); DrawColorChip(sp, i, j, P_ColorChip, n); } col++; j=0; if (max < Arrange->Dyarn.data[i].cnt*(25+5)+20+5) max = Arrange->Dyarn.data[i].cnt*(25+5)+20+5; } if (!(i%7)) { if (!max) max = chip_h; chip_stp += max; max = 0; col = 0; } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawColorChip(TPoint sp, int i, int j, TTexpiaBitmap *ColorChip, int n) { int color, k, c; AnsiString str, stryarn; TCanvas *Canvas = NULL; if ((Canvas = ColorChip->CreateCanvas()) == NULL) goto fail; color = Arrange->Dyarn.data[i].color[j]; Canvas->Brush->Color = clWhite; Canvas->Font->Size = 12; if (j == 0) { str = "<"+AnsiString(i)+"> "; if (Arrange->Dyarn.data[i].type == 0) stryarn = "Normal"; else stryarn = "Melange"; Canvas->Font->Color = clBlack; Canvas->TextOut(sp.x, sp.y-25, str+stryarn); } str = GetColorName(Palette->ColorData[color]); Canvas->Font->Color = clBlue; Canvas->TextOut(sp.x+70, sp.y, str); ColorChip->DeleteCanvas(Canvas); switch (n) { case 0: PrintColorChip8(ColorChip, Rect(sp.x, sp.y, sp.x+60, sp.y+25), color); break; case 1: c = 0; for (k = 1; k < i; k++) { c += Arrange->Dyarn.data[k].cnt; } PrintColorChip8(ColorChip, Rect(sp.x, sp.y, sp.x+60, sp.y+25), 5 + (c + j) * 7); break; case 2: PrintColorChip24(ColorChip, Rect(sp.x, sp.y, sp.x+60, sp.y+25), Palette->ColorData[color]->RGB.rgbRed, Palette->ColorData[color]->RGB.rgbGreen, Palette->ColorData[color]->RGB.rgbBlue); break; } return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::DrawGrid(TTexpiaBitmap *grid, int Width, int Height, TPoint sp, int rat_x, int rat_y, bool gridcolor) { int i, ratio, dot_x, dot_y, black; int count=0, unit = 0, add; TCanvas *Canvas = NULL; if ((Canvas = grid->CreateCanvas()) == NULL) goto fail; Canvas->Font->Size = 12; Canvas->Font->Color = clBlack; Canvas->Brush->Color = clWhite; Canvas->TextOut(sp.x+Width-3, sp.y-Height-28, "Inch"); Canvas->TextOut(sp.x-28, sp.y+10, "Dot"); //----------------------------------------------------Draw Arrow Unit Canvas->Pen->Color = clBlack; Canvas->MoveTo(sp.x-18, sp.y+5); Canvas->LineTo(sp.x-18, sp.y-50); Canvas->MoveTo(sp.x-25, sp.y-40); Canvas->LineTo(sp.x-18, sp.y-50); Canvas->LineTo(sp.x-11, sp.y-40); Canvas->MoveTo(sp.x+10, sp.y+20); Canvas->LineTo(sp.x+65, sp.y+20); Canvas->MoveTo(sp.x+55, sp.y+13); Canvas->LineTo(sp.x+65, sp.y+20); Canvas->LineTo(sp.x+55, sp.y+27); Canvas->MoveTo(sp.x+Width-68, sp.y-Height-20); Canvas->LineTo(sp.x+Width-13, sp.y-Height-20); Canvas->MoveTo(sp.x+Width-23, sp.y-Height-13); Canvas->LineTo(sp.x+Width-13, sp.y-Height-20); Canvas->LineTo(sp.x+Width-23, sp.y-Height-27); Canvas->MoveTo(sp.x+Width+20, sp.y-Height+55); Canvas->LineTo(sp.x+Width+20, sp.y-Height); Canvas->MoveTo(sp.x+Width+13, sp.y-Height+10); Canvas->LineTo(sp.x+Width+20, sp.y-Height); Canvas->LineTo(sp.x+Width+27, sp.y-Height+10); //--------------------------------------------------------------------- Canvas->Font->Size = 10; if (gridcolor) Canvas->Pen->Color = clWhite; else Canvas->Pen->Color = clBlack; for(i=0; iMoveTo(sp.x, sp.y-i); Canvas->LineTo(sp.x+Width, sp.y-i); } for(i=0; iMoveTo(sp.x+i, sp.y); Canvas->LineTo(sp.x+i, sp.y - Height); } Canvas->Pen->Color = clBlack; //==============================================================Vertical Dot count = 0; if (rat_y>=13) { dot_y = rat_y; unit = 10; add = 1; for (i = 0; iMoveTo(sp.x-10, sp.y-i); Canvas->LineTo(sp.x-1, sp.y-i); } else { Canvas->MoveTo(sp.x-5, sp.y-i); Canvas->LineTo(sp.x-1, sp.y-i); } } else { Canvas->MoveTo(sp.x-15, sp.y-i); Canvas->LineTo(sp.x-1, sp.y-i); Canvas->MoveTo(sp.x, sp.y-i); Canvas->LineTo(sp.x+Width, sp.y-i); if (count) Canvas->TextOut(sp.x-28, sp.y-i-20, count); else Canvas->TextOut(sp.x-15, sp.y-i-20, count); } count += add; } } else { if (rat_y >= 8 && rat_y < 13) { dot_y = rat_y*5; unit = 20; add = 5; } else { dot_y = rat_y*10; unit = 50; add = 10; } for (i=0; iMoveTo(sp.x-10, sp.y-i); Canvas->LineTo(sp.x-1, sp.y-i); } else { Canvas->MoveTo(sp.x-15, sp.y-i); Canvas->LineTo(sp.x-1, sp.y-i); Canvas->MoveTo(sp.x, sp.y-i); Canvas->LineTo(sp.x+Width, sp.y-i); if (count) Canvas->TextOut(sp.x-28, sp.y-i-20, count); else Canvas->TextOut(sp.x-15, sp.y-i-20, count); } count += add; } } //===============================================================Horizontal Dot count = 0; if (rat_x>=13) { dot_x = rat_x; unit = 10; add = 1; for (i = 0; iMoveTo(sp.x+i, sp.y+1); Canvas->LineTo(sp.x+i, sp.y+10); } else { Canvas->MoveTo(sp.x+i, sp.y+1); Canvas->LineTo(sp.x+i, sp.y+5); } } else { Canvas->MoveTo(sp.x+i, sp.y+1); Canvas->LineTo(sp.x+i, sp.y+15); Canvas->MoveTo(sp.x+i, sp.y); Canvas->LineTo(sp.x+i, sp.y-Height); Canvas->TextOut(sp.x+i+5, sp.y+7, count); } count += add; } } else { if (rat_x >= 8 && rat_x < 13) { dot_x = rat_x*5; unit = 20; add = 5; } else { dot_x = rat_x*10; unit = 50; add = 10; } for (i=0; iMoveTo(sp.x+i, sp.y+1); Canvas->LineTo(sp.x+i, sp.y+10); } else { Canvas->MoveTo(sp.x+i, sp.y+1); Canvas->LineTo(sp.x+i, sp.y+15); Canvas->MoveTo(sp.x+i, sp.y); Canvas->LineTo(sp.x+i, sp.y-Height); Canvas->TextOut(sp.x+i+5, sp.y+7, count); } count += add; } } //==============================================================Vertical Inch float t, ave; ave =(float)(rat_y*Arrange->kdsn.cpi)/10; count = 0; for (t = 0; tMoveTo(sp.x+Width+10, sp.y-t); Canvas->LineTo(sp.x+Width+1, sp.y-t); } else { Canvas->MoveTo(sp.x+Width+5, sp.y-t); Canvas->LineTo(sp.x+Width+1, sp.y-t); } } else { Canvas->MoveTo(sp.x+Width+15, sp.y-t); Canvas->LineTo(sp.x+Width+1, sp.y-t); Canvas->TextOut(sp.x+Width+5, sp.y-t-20, count/10); } count++; } //===============================================================Horizontal Inch ave = (float)(rat_x*Arrange->kdsn.wpi)/10; count = 0; for (t = 0; tMoveTo(sp.x+t, sp.y-Height-1); Canvas->LineTo(sp.x+t, sp.y-Height-10); } else { Canvas->MoveTo(sp.x+t, sp.y-Height-1); Canvas->LineTo(sp.x+t, sp.y-Height-5); } } else { Canvas->MoveTo(sp.x+t, sp.y-Height-1); Canvas->LineTo(sp.x+t, sp.y-Height-15); Canvas->TextOut(sp.x+t+5, sp.y-Height-20, count/10); } count++; } //============================================================== Canvas->MoveTo(sp.x, sp.y-Height); Canvas->LineTo(sp.x+Width, sp.y-Height); Canvas->LineTo(sp.x+Width, sp.y); Canvas->LineTo(sp.x, sp.y); Canvas->LineTo(sp.x, sp.y-Height); grid->DeleteCanvas(Canvas); Canvas = NULL; return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- // External Function //--------------------------------------------------------------------- void __fastcall RepaintImage() { if (MainImageForm) { MainImageForm->iMainImage->Repaint(); if (DesignMode==D_MARK) { FullViewForm->InitForm(MainImageForm->iMainImage, MainImageForm->iMainImage->ArrayBitmap); } else { 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->ArrayBitmap[0].PutColors(0, 256, rgb); MainImageForm->iMainImage->ArrayBitmap[1].PutColors(0, 256, rgb); } MainImageForm->iMainImage->Repaint(); if (DesignMode==D_MARK) { FullViewForm->InitForm(MainImageForm->iMainImage, MainImageForm->iMainImage->ArrayBitmap); } else { FullViewForm->InitForm(MainImageForm->iMainImage); } PaletteForm->InitForm(MainImageForm->Palette); PenManagerForm->SetColor(MainImageForm->Palette); ColorLibraryForm->View(); } } //--------------------------------------------------------------------------- void __fastcall KnitRepaintColor() { MainImageForm->ChangeColor(PaletteForm->DIB256Palette->ChoiceIndex); PaletteForm->KnitChangeColor(); ::RepaintColor(); } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::iMainImageKeyDown(int Key) { int Ratio = 0; bool IsEditMode = false; if(TextForm) IsEditMode = TextForm->Edit->Focused(); // if(!((PaletteForm->PanelLibrary->Visible) || IsEditMode )){ if(PaletteForm) IsEditMode != PaletteForm->PanelLibrary->Visible; //TextForm °ú PalletteFormÀÌ ¾Æ´Ò¶§ ½ÇÇà // if(KnittingForm) IsEditMode = true; if(!IsEditMode){ if(Key == 65 || Key == 97){ //'a' or 'A' Key = 0; switch (iMainImage->ZoomIn) { //ÇöÀçÀÇ È®´ë, Ãà¼ÒµÈ ºñÀ²Àº ¾Ë¾Æ³»¾î case 1: switch (iMainImage->ZoomOut) { // ºñÀ²¿¡ µû¶ó ratio¶ó´Â º¯¼ö¿¡ Àû´çÇÑ °ªÀ» case 1: Ratio = 302; break; // ÀԷ½Ã۰í, ±×°ÍÀº parameter·Î ÇÏ´Â ÇÔ¼ö(RatioZoom) case 2: Ratio = 203; break; // ¸¦ È£ÃâÇÑ´Ù. case 3: Ratio = 102; break; case 4: Ratio = 103; break; // ¼öÁ¤ By GreenFish (Áܴܰè È®Àå) case 6: Ratio = 104; break; case 8: Ratio = 106; break; case 12: Ratio = 108; break; case 16: Ratio = 112; break; } break; case 2: switch (iMainImage->ZoomOut) { case 1: Ratio = 301; break; case 3: Ratio = 101; break; } break; case 3: switch (iMainImage->ZoomOut) { case 1: Ratio = 401; break; case 2: Ratio = 201; break; } break; case 4: Ratio = 601; break; case 6: Ratio = 801; break; case 8: Ratio = 1201; break; case 12: Ratio = 1601; break; default: return; } RatioZoom(Ratio); } if((Key == 83) || (Key == 115)){ // 's' or 'S' Key = 0; switch (iMainImage->ZoomIn) { case 1: switch (iMainImage->ZoomOut) { case 1: Ratio = 203 ; break; case 2: Ratio = 103; break; case 3: Ratio = 104; break; case 4: Ratio = 106; break; case 6: Ratio = 108; break; case 8: Ratio = 112; break; case 12: Ratio = 116; break; default: return; } break; case 2: switch (iMainImage->ZoomOut) { case 1: Ratio = 302; break; case 3: Ratio = 102; break; } break; case 3: switch (iMainImage->ZoomOut) { case 1: Ratio = 201; break; case 2: Ratio = 101; break; } break; case 4: Ratio = 301; break; case 6: Ratio = 401; break; case 8: Ratio = 601; break; case 12 : Ratio = 801; break; case 16 : Ratio = 1201; break; default: return; } RatioZoom(Ratio); } } } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::RatioZoom(int r) //by qe { int a, b; a = r / 100; b = r % 100; GetCursorPos(&ptScreen); //¸¶¿ì½º Ä¿¼­ÀÇ À§Ä¡¸¦ ÀԷ¹޴´Ù. ZoomChange(a, b, &ptScreen); } //--------------------------------------------------------------------------- bool __fastcall TMainImageForm::SetMerge(TTexpiaBitmap *bmp, TKnitArrange *ka) { TRect r; int i, x, y, bg; bool sw = false; short cnt; Byte *chart, *IP, *OP; TPException ec = EC_NONE; Byte mc[MU_CNT]; Byte find; RGBQUAD rgb[256]; Byte *sp, *bp, *mp; ExitMerge(); if ((TempBitmap = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!TempBitmap->Create(bmp->Width, bmp->Height, 8)) { ec = EC_MEMORY_LACK; goto fail; } Palette->ToRGBQUAD(rgb, 256); TempBitmap->PutColors(0, 256, rgb); if (!TempBitmap->StartScanLine()) goto fail; if (false/*cbi->Mask*/) { if ((TempMask = new TTexpiaBitmap)==NULL) goto fail; if (!TempMask->Create(TempBitmap->Width, TempBitmap->Height, 8, rgb)) goto fail; if (!bmp->StartScanLine()) goto fail; if (!TempMask->StartScanLine()) goto fail; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); sp = bmp->GetScanLine(y); memcpy(bp, sp, bmp->Width); mp = TempMask->GetScanLine(y); for (x=0; xWidth; x++, bp++, mp++) { *bp = (*bp&0xC0) | mc[*bp&0x3F]; *mp = 0; } TempBitmap->PutScanLine(y); TempMask->PutScanLine(y); } TempMask->StopScanLine(); bmp->StopScanLine(); } else { if (!bmp->StartScanLine()) goto fail; for (y=0; yHeight; y++) { bp = TempBitmap->GetScanLine(y); sp = bmp->GetScanLine(y); memcpy(bp, sp, bmp->Width); // for (x=0; xWidth; x++, bp++) { // *bp = (*bp&0xC0) | mc[*bp&0x3F]; // } TempBitmap->PutScanLine(y); } bmp->StopScanLine(); } TempBitmap->StopScanLine(); if (DesignMode == D_YARN || (DesignMode == D_MARK && iMainImage->ZoomIn != 16)) { 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); } iSelectImageSize(); iSelectImage->Visible = true; Center.x = iSelectImage->Bitmap->Width/2; Center.y = iSelectImage->Bitmap->Height/2; } else { iSelectImage->Bitmap->Destroy(); iSelectImage->Visible = false; Center.x = TempBitmap->Width/2; Center.y = TempBitmap->Height/2; } PenManagerForm->SetColor(Palette); MainMenuForm->Item = T_MERGE; MainMenuForm->SubItem = 0; return true; fail: bmp->StopScanLine(); TempBitmap->StopScanLine(); TempMask->StopScanLine(); ::doDestroy(TempBitmap); TempBitmap = NULL; ::doDestroy(TempMask); TempMask = NULL; return false; } //--------------------------------------------------------------------------- void __fastcall TMainImageForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift) { MainMenuForm->iMainImageKeyDown(Key); } //---------------------------------------------------------------------------