//--------------------------------------------------------------------------- #include #pragma hdrstop #include "LogData.h" #include "APMenu_F.h" #include "Main.h" #include "MainImage.h" #include "APTable_F.h" #include "Palette.h" //#include "Grouping_F.h" #include "StatusProgress.h" #include "MainMenu.h" #include "Library_F.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "RzEdit" #pragma link "RzSpnEdt" #pragma link "RzButton" #pragma link "RzTrkBar" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_REARRANGE StringTable[0] #define IDS_REPROPORTION StringTable[1] #define IDS_CONCENTRATION StringTable[2] #define IDS_DELETEALL StringTable[3] TAPMenuForm *APMenuForm; //--------------------------------------------------------------------------- __fastcall TAPMenuForm::TAPMenuForm(TComponent* Owner) : TForm(Owner) { //============================================ StringTable.Create(DirectoryItem, Language, "APMenu"); //SetSmallFont(Font); rzbitbtnRearrange->Caption = IDS_REARRANGE; rzbitbtnFile->Caption = IDS_COMMON_FILE; lbRepro->Caption = IDS_REPROPORTION; lbConcen->Caption = IDS_CONCENTRATION; sbDeleteAll->Hint = IDS_DELETEALL; sbDelete->Hint = IDS_COMMON_DELETE; sbFile->Hint = IDS_COMMON_FILE; rzbitbtnRun->Caption = IDS_COMMON_RUN; //sbRun->Caption = IDS_COMMON_RUN; //sbView->Caption = IDS_COMMON_FILE; //============================================ } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::InitForm() { BEGIN_LOG("APMenu_F"); int ParentHeight; TRect rt; TPItemImage *Image = MainImageForm->iMainImage; rt.Left = 0; rt.Top = 0; rt.Right = fileimg->Width; rt.Bottom = fileimg->Height; fileimg->Canvas->FillRect( rt); if (Image->uBitmap->BitsPerPixel == 8) { Panel2->Visible = true; Panel1->BringToFront(); Panel1->Visible = true; ClientHeight = Panel1->Height; } else { Panel1->Visible = false; Panel2->BringToFront(); Panel2->Visible = true; Panel2->Top = 0; ClientHeight = Panel2->ClientHeight; } APTableForm = new TAPTableForm(MainForm); APTableForm->InitForm(); APTableForm->Parent = MainForm; APTableForm->Visible = false; store = new TList; ReadIniFile(); if (LibraryForm) LibraryForm->OnRead = LibraryOnRead; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::ExitForm() { BEGIN_LOG("APMenu_F"); WriteIniFile(); if (APTableForm) { APTableForm->bFree = true; APTableForm->Close(); } delete APTableForm; if(Bitmap) delete Bitmap; TFileInfor *pinfo; if (store){ while(store->Count > 0){ pinfo = (TFileInfor*)(store->Last()); store->Remove(pinfo); delete pinfo; } delete store; } ::RepaintColor(); Visible = false; END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::ScrollBar1Change(TObject *Sender) { if(store->Count >0){ TFileInfor *fi; fi = (TFileInfor *) store->Items[ScrollBar1->Position]; lblfilename->Caption = ExtractFileName(((TFileInfor*)(store->Items[ScrollBar1->Position]))->Name) ; fileimg->Canvas->Draw(0,0, fi->Bitmap); rzbitbtnRun->Enabled = true; } } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::sbDeleteAllClick(TObject *Sender) { BEGIN_LOG("APMenu_F"); TFileInfor *fi; TRect rt; rt.Left = 0; rt.Top = 0; rt.Right = fileimg->Width; rt.Bottom = fileimg->Height; if (store) { while (store->Count>0) { fi = (TFileInfor *)store->Last(); store->Remove(fi); delete fi; } } ScrollBar1->Max = 0; ScrollBar1->Position = 0; lblfilename->Caption = String(""); fileimg->Canvas->FillRect( rt); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::sbDeleteClick(TObject *Sender) { BEGIN_LOG("APMenu_F"); TFileInfor *fi; if (store->Count>0) { fi = (TFileInfor *) store->Items[ScrollBar1->Position]; // Áö¿ï ºñÆ®¸ÊÀ» ãÀ½ store->Remove(fi); delete fi; if(ScrollBar1->Max == 0){ // ºñÆ®¸ÊÀÌ 1°³ ¶Ç´Â ¾øÀ»°æ¿ì ScrollBar1->Position = 0; // º°µµ ó¸® ScrollBar1->Max = 0; } else { if(ScrollBar1->Position == ScrollBar1->Max) ScrollBar1->Position--; // ºñÆ®¸ÊÀÌ 2°³ÀÌ»ó ScrollBar1->Max--; // ÀÖÀ» °æ¿ì } if (store->Count>0) { // ºñÆ®¸ÊÀÌ 1°³ÀÏ °æ¿ì fi = (TFileInfor *) store->Items[ScrollBar1->Position]; fileimg->Canvas->Draw(0,0, fi->Bitmap); } else { TRect rt; // ºñÆ®¸ÊÀÌ ¾øÀ» °æ¿ì ó¸® rt.Left = 0; rt.Top = 0; rt.Right = fileimg->Width; rt.Bottom = fileimg->Height; fileimg->Canvas->FillRect( rt); lblfilename->Caption = String(""); } } END_LOG; } //--------------------------------------------------------------------------- bool __fastcall TAPMenuForm::InsertImage(String fn) { BEGIN_LOG("APMenu_F"); TFileInfor *fi; HANDLE hFile = INVALID_HANDLE_VALUE; int ec; TTexVersion ver; TGraphicFileFormat gff; fi = new TFileInfor; fi->Name = fn; fi->Bitmap = new Graphics::TBitmap; gff = FindExtension(ExtractFileExt(fi->Name)); if (gff == gffAPT) { if ((hFile = CreateFile(fi->Name.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) goto next; if (LoadFromTexpiaTag(hFile, fi, gff, &ver) != EC_NONE) goto next; // fi->Bitmap ¿¡ ÆÄÀÏ ·Îµå CloseHandle(hFile); } else { //´Ù¸¥ ÆÄÀÏ Æ÷¸äÀÏ °æ¿ì¿¡´Â Èæ¹é º¯È¯À» ÇØ¼­ ³Ö¾î ÁØ´Ù. if (!LibraryForm) goto next; TTexpiaBitmap *thumbImage = LibraryForm->GetThumbImage(fi->Name); if (!thumbImage) goto next; fi->Bitmap->Width = 80; fi->Bitmap->Height = 100; fi->Bitmap->PixelFormat = pf24bit; HDC dc = thumbImage->CreateDC(); if (!dc) { if (thumbImage) delete thumbImage; thumbImage = NULL; goto next; } StretchBlt(fi->Bitmap->Canvas->Handle, 0, 0,80, 100, dc, 0, 0, thumbImage->Width, thumbImage->Height, SRCCOPY); thumbImage->DeleteDC(dc); dc = NULL; if (thumbImage) delete thumbImage; thumbImage = NULL; TColor color; Byte r, g, b; for (int y = 0; y < fi->Bitmap->Height; y++) { for (int x = 0; x < fi->Bitmap->Width; x++) { color = fi->Bitmap->Canvas->Pixels[x][y]; b = (color >> 16) & 0xFF; g = (color >> 8) & 0xFF; r = (color) & 0xFF; b = (b+g+r)/3; color = TColor((b<<16) + (b<<8) + b); fi->Bitmap->Canvas->Pixels[x][y] = color; } } } store->Add(fi); // store ¸®½ºÆ®¿¡ ÆÄÀÏÀ̸§,Bitmap Ãß°¡ if (store->Count <= 1) { ScrollBar1->Max = 0; // óÀ½ Ãß°¡½Ã ó¸® fileimg->Canvas->Draw(0,0, fi->Bitmap); lblfilename->Caption = ExtractFileName(fi->Name); } else { ScrollBar1->Max = store->Count -1; // µÎ¹øÂ° ºÎÅÍ Ã³¸® } // scrollbar ÀÇ Ã¼ÀÎÁö À̺¥Æ® È£Ãâ ScrollBar1->Position = ScrollBar1->Max; END_LOG; return true; next: if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); if(fi) delete fi; return false; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::LibraryOnRead(TObject *Sender) { InsertImage(LibraryForm->SelectedFileName); } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::ReproScrollChange(TObject *Sender) { txtRepro->Value = ReproScroll->Position; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::DensityScrollChange(TObject *Sender) { txtDensity->Value = DensityScroll->Position; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::txtReproChange(TObject *Sender) { ReproScroll->Position = txtRepro->Value; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::txtDensityChange(TObject *Sender) { DensityScroll->Position = txtDensity->Value; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::WriteIniFile() { BEGIN_LOG("APMenu_F"); int i; TIniFile *IniFile = new TIniFile(AppDataItem + "\\APMenu.ini"); if (IniFile) { IniFile->WriteInteger("APMenu","ReproScrollValue",ReproScroll->Position); IniFile->WriteInteger("APMenu","DensityScrollValue",DensityScroll->Position); IniFile->WriteInteger("APMenu","txtReproValue",txtRepro->Value ); IniFile->WriteInteger("APMenu","txtDensityValue",txtDensity->Value); IniFile->WriteInteger("APMenu","FileCount",store->Count); for(i = 0; i< store->Count; i++) { IniFile->WriteString(i,"Path", ((TFileInfor*)(store->Items[i]))->Name); } delete IniFile; } END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::ReadIniFile() { /* int i,Count; AnsiString fn; TIniFile *IniFile = new TIniFile(AppDataItem + "\\APMenu.ini"); if (IniFile) { ReproScroll->Position = IniFile->ReadInteger("APMenu","ReproScrollValue",100); DensityScroll->Position =IniFile->ReadInteger("APMenu","DensityScrollValue",50); txtRepro->Value = IniFile->ReadInteger("APMenu","txtReproValue",100); txtDensity->Value = IniFile->ReadInteger("APMenu","txtDensityValue",50); Count = IniFile->ReadInteger("APMenu","FileCount",0); for(i = 0 ; i< Count;i++) { fn = IniFile->ReadString(i,"Path","C:\\"); InsertImage(fn); } delete IniFile; } */ BEGIN_LOG("APMenu_F"); String fn = String(AppDataItem + "\\APMenu.ini"); ReproScroll->Position = GetPrivateProfileInt(String("APMenu").c_str(), String("ReproScrollValue").c_str(), 100, fn.c_str()); DensityScroll->Position = GetPrivateProfileInt(String("APMenu").c_str(), String("DensityScrollValue").c_str(), 50, fn.c_str()); txtRepro->Value = GetPrivateProfileInt(String("APMenu").c_str(), String("txtReproValue").c_str(), 100, fn.c_str()); txtDensity->Value = GetPrivateProfileInt(String("APMenu").c_str(), String("txtDensityValue").c_str(), 50, fn.c_str()); int count = GetPrivateProfileInt(String("APMenu").c_str(), String("FileCount").c_str(), 0, fn.c_str()); for(int i = 0; i < count; i++) { Char fileName[256]; GetPrivateProfileString(String(i).c_str(), String("Path").c_str(), String("C:\\").c_str(), fileName, 256, fn.c_str()); InsertImage(String(fileName)); } END_LOG; } //--------------------------------------------------------------------------- int __fastcall TAPMenuForm::FindUseColor() { BEGIN_LOG("APMenu_F"); int UseColor; bool cn[256]; int i, x, y; Byte *scan; RECT r; r = MainImageForm->WorkArea->Range; for (i=0; i<=255; i++) cn[i] = false; if(MainImageForm->iMainImage->uBitmap->StartScanLine()) { for (y = r.top; y < r.bottom; y++) { scan = MainImageForm->iMainImage->uBitmap->GetScanLine(y); for (x = r.left; x < r.right; x++) cn[*(scan+x)] = true; } MainImageForm->iMainImage->uBitmap->StopScanLine(); } else {SAVE_EXCEPTION(EC_MEMORY_LACK); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); return 0;} UseColor = 0; for (i=2; i<252; i++) { if (cn[i]) UseColor++; } END_LOG; return UseColor; } //---------------------------------------------------------------------------- void __fastcall TAPMenuForm::iMainImageKeyDown(WORD Key, TShiftState Shift) //lhskys Èİ¡°ø¿¡¼­ ¿£ÅͽÇÇà { if(Key == VK_RETURN && MainImageForm->iMainImage->uBitmap->BitsPerPixel==24) rzbitbtnRunClick(rzbitbtnRun); } //---------------------------------------------------------------------------- void __fastcall TAPMenuForm::EditorSelectAll(TObject *Sender) { SetFocusAndSelectAll(Sender); } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::rzbitbtnRunClick(TObject *Sender) { BEGIN_LOG("APMenu_F"); //* Be Converted by linuxjun Undo_Method TEXPIAFILEHEADER tpfh; TPException ec; TTexVersion ver; THLS APMask; COLORREF temp; Byte *bpMainImage,*bpMaskImage,*bpUndo,*bpMp,mm; TPalette *spalette = NULL; RECT rect; int x,y,xx,yy; double APRange,ratio; //AnsiString fn; String fn; HANDLE hFile = INVALID_HANDLE_VALUE; bool undoSw = false; ec = EC_NONE; TCursor OldCursor; #ifdef TRIAL TTexpiaBitmap *tempBitmap = NULL; HDC dcDst = NULL; #endif TGraphicFileFormat ExtIndex; TPItemImage *Image = MainImageForm->iMainImage; if(store->Count <= 0) { END_LOG; return; } if(!first){ if(MainImageForm->WorkArea->Mask){ rect = MainImageForm->WorkArea->Range; if ((undoSw = MainImageForm->UndoSave(UK_PATTERN, rect)) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } }else { if ((undoSw = MainImageForm->UndoSave(UK_PATTERN, Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height))) == false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } } first = true; } if (Bitmap) delete Bitmap; fn = ((TFileInfor *) store->Items[ScrollBar1->Position])->Name; ExtIndex = FindExtension(ExtractFileExt(fn)); if (ExtIndex != gffAPT) { ApplyAptForOtherFile(fn, ExtIndex); END_LOG; return; } if ((Bitmap = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((spalette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((hFile = CreateFile(fn.c_str(),GENERIC_READ, 0, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((ec = LoadFromTexpiaFile(hFile, spalette, tpfh, Bitmap, ExtIndex))!=EC_NONE) goto fail; CloseHandle(hFile); delete spalette; APRange = DensityScroll->Position / 5000.0; ud = MainImageForm->Undo->GetLast(); MainImageForm->iMainImage->uBitmap->PartialUndo->LoadLast(ud->FromRgb); ratio = ReproScroll->Position / 100.0; Bitmap->ResizeStretch(int (ratio * Bitmap->Width), int(ratio * Bitmap->Height)); Image->uBitmap->StartScanLine(); Bitmap->StartScanLine(); MainImageForm->iMainImage->uBitmap->StartUndoScanLine(); //by linuxjun OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; // Undo À̹ÌÁö¿Í pattern À̹ÌÁö¸¦ Àоî Main À̹ÌÁö¿¡ È¿°ú¸¦ ÁÜ. if(MainImageForm->WorkArea->Mask){ // ÀÛ¾÷ ¿µ¿ªÀÌ ÀÖÀ»½Ã rect = MainImageForm->WorkArea->Range; StatusProgress->Maximum = rect.bottom - rect.top; MainImageForm->WorkArea->Mask->StartScanLine(); for(y = rect.top, yy = 0 ; y < rect.bottom; y++,yy++) { StatusProgress->Position = y - rect.top; bpMainImage = Image->uBitmap->GetScanLine(y) + 3*rect.left; //MainImage bpMaskImage = Bitmap->GetScanLine(yy%Bitmap->Height); //Pattern // bpUndo = ud->uBitmap->GetScanLine(y - rect.top); // UndoImage bpUndo = MainImageForm->iMainImage->uBitmap->GetUndoScanLine(y,rect.left,rect.right) + 3*rect.left; // UndoImage bpMp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(y-rect.top); mm = 0x80; for(x = rect.left ,xx =0; x < rect.right; x++,xx++,bpMainImage+=3,bpUndo+=3) { if((*(bpMp) & mm)) { GetPixel24(bpUndo,temp); // UndoImage¸¦ Àбâ TColor2HLS((TColor)temp, APMask.Hue, APMask.Lig, APMask.Sat); APMask.Lig += (*(bpMaskImage+(xx%Bitmap->Width)) - 26) * APRange; // ¸íµµ°ª º¯°æ if(APMask.Lig < 0) APMask.Lig = 0 ; if(APMask.Lig > 1) APMask.Lig = 1.0; temp = HLS2TColor(APMask.Hue,APMask.Lig,APMask.Sat); SetPixel24(bpMainImage, temp); //MainImage ¿¡ ¾²±â } if (mm==1) { bpMp++; mm = 0x80; } else mm >>= 1; } Image->uBitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); } else { StatusProgress->Maximum = Image->uBitmap->Height; for(y=0,yy=0 ;yuBitmap->Height;y++,yy++){ StatusProgress->Position = y; bpMainImage = Image->uBitmap->GetScanLine(y) ; // MainImage bpMaskImage = Bitmap->GetScanLine(yy%Bitmap->Height); // pattern bpUndo = MainImageForm->iMainImage->uBitmap->GetUndoScanLine(y) ; // UndoImage for(x = 0,xx = 0 ; x < Image->uBitmap->Width;x++,xx++,bpUndo+=3,bpMainImage+=3) { GetPixel24(bpUndo,temp); // UndoImage¸¦ Àбâ TColor2HLS((TColor)temp,APMask.Hue,APMask.Lig,APMask.Sat); APMask.Lig += (*(bpMaskImage+(xx%Bitmap->Width)) - 26) * APRange; if(APMask.Lig < 0) APMask.Lig = 0 ; if(APMask.Lig > 1) APMask.Lig = 1.0; temp = HLS2TColor(APMask.Hue,APMask.Lig,APMask.Sat); SetPixel24(bpMainImage, temp); //MainImage ¿¡ ¾²±â } Image->uBitmap->PutScanLine(y); } } StatusProgress->End(); Bitmap->StopScanLine(); Image->uBitmap->StopScanLine(); // ud->uBitmap->StopScanLine() ; MainImageForm->iMainImage->uBitmap->StopUndoScanLine(); //by linuxjun // ud->Complete(); #ifdef TRIAL tempBitmap = new TTexpiaBitmap; tempBitmap->Create(MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height, MainImageForm->iMainImage->uBitmap->BitsPerPixel); MainImageForm->iMainImage->uBitmap->CopyToTexpia(tempBitmap, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY); dcDst = tempBitmap->CreateDC(); PaintWaterMark(dcDst, 0, 0, tempBitmap->Width, tempBitmap->Height, 1, 1, random(2) ? random(30)+10 : random(30)+320); tempBitmap->DeleteDC(dcDst); MainImageForm->iMainImage->uBitmap->Copy(tempBitmap, SRCCOPY); delete tempBitmap; //MainImageForm->WaterMarkPaint = true; #endif ::RepaintColor(); Screen->Cursor = OldCursor; END_LOG; return; fail: if (Bitmap) delete Bitmap; if (spalette) delete spalette; if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); if (undoSw == true) { // ud->Complete(); MainImageForm->Undo->RemoveLast(); } MainImageForm->iMainImage->uBitmap->StopUndoScanLine(); //by linuxjun EXCEPTION_MESSAGE_OK(ec); END_LOG; } //--------------------------------------------------------------------------- // ¶óÀ̺귯¸® À̹ÌÁö¸¦ ó¸®Çϱâ À§ÇÑ ÇÔ¼ö bool __fastcall TAPMenuForm::ApplyAptForOtherFile(String FileName, TGraphicFileFormat ExtIndex) { BEGIN_LOG("APMenu_F"); TEXPIAFILEHEADER tpfh; TPException ec; TTexVersion ver; THLS APMask; COLORREF temp; Byte *bpMainImage,*bpMaskImage,*bpUndo,*bpMp,mm, b,g,r; RECT rect; int x,y,xx,yy, uBitPoz; double APRange,ratio; ec = EC_NONE; TCursor OldCursor; TUnionBitmap *uBitmap = NULL; TPalette *spalette = NULL; TPItemImage *Image = MainImageForm->iMainImage; LibraryData::LibData *libData = NULL; libData = LibraryForm->LoadLibraryFile(FileName); LibraryData::LibraryBitmapData *BitmapData = (LibraryData::LibraryBitmapData *)libData; uBitmap = BitmapData->Bitmap; spalette = BitmapData->Palette; APRange = DensityScroll->Position / 5000.0; ud = MainImageForm->Undo->GetLast(); MainImageForm->iMainImage->uBitmap->PartialUndo->LoadLast(ud->FromRgb); ratio = ReproScroll->Position / 100.0; uBitmap->ResizeStretch(int (ratio * uBitmap->Width), int(ratio * uBitmap->Height)); Image->uBitmap->StartScanLine(); uBitmap->StartScanLine(); MainImageForm->iMainImage->uBitmap->StartUndoScanLine(); //by linuxjun OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; // Undo À̹ÌÁö¿Í pattern À̹ÌÁö¸¦ Àоî Main À̹ÌÁö¿¡ È¿°ú¸¦ ÁÜ. if(MainImageForm->WorkArea->Mask){ // ÀÛ¾÷ ¿µ¿ªÀÌ ÀÖÀ»½Ã rect = MainImageForm->WorkArea->Range; StatusProgress->Maximum = rect.bottom - rect.top; MainImageForm->WorkArea->Mask->StartScanLine(); for(y = rect.top, yy = 0 ; y < rect.bottom; y++,yy++) { StatusProgress->Position = y - rect.top; bpMainImage = Image->uBitmap->GetScanLine(y) + 3*rect.left; //MainImage bpMaskImage = uBitmap->GetScanLine(yy%uBitmap->Height); //Pattern bpUndo = MainImageForm->iMainImage->uBitmap->GetUndoScanLine(y,rect.left,rect.right) + 3*rect.left; // UndoImage bpMp = (Byte *)MainImageForm->WorkArea->Mask->GetScanLine(y-rect.top); mm = 0x80; for(x = rect.left ,xx =0; x < rect.right; x++,xx++,bpMainImage+=3,bpUndo+=3) { if (uBitmap->BitsPerPixel == 8) { uBitPoz = xx%uBitmap->Width; r = spalette->ColorData[*(bpMaskImage + uBitPoz) + 1]->RGB.rgbRed; g = spalette->ColorData[*(bpMaskImage + uBitPoz) + 1]->RGB.rgbGreen; b = spalette->ColorData[*(bpMaskImage + uBitPoz) + 1]->RGB.rgbBlue; } else { uBitPoz = (xx*3)%(uBitmap->Width*3); b = Byte(*(bpMaskImage + uBitPoz)); g = Byte(*(bpMaskImage + uBitPoz + 1)); r = Byte(*(bpMaskImage + uBitPoz + 2)); } b = (b+g+r)/3; if((*(bpMp) & mm)) { GetPixel24(bpUndo,temp); // UndoImage¸¦ Àбâ TColor2HLS((TColor)temp, APMask.Hue, APMask.Lig, APMask.Sat); //rÀ» 0~255·Î µÇ¾î ÀÖ°í ¸íµµ°ªÀº -128 ~ 128±îÁö µÇ¾î ÀÖ´Ù. APMask.Lig += (b - 125) * APRange; // ¸íµµ°ª º¯°æ if(APMask.Lig < 0) APMask.Lig = 0 ; if(APMask.Lig > 1) APMask.Lig = 1.0; temp = HLS2TColor(APMask.Hue,APMask.Lig,APMask.Sat); SetPixel24(bpMainImage, temp); //MainImage ¿¡ ¾²±â } if (mm==1) { bpMp++; mm = 0x80; } else mm >>= 1; } Image->uBitmap->PutScanLine(y); } MainImageForm->WorkArea->Mask->StopScanLine(); } else { StatusProgress->Maximum = Image->uBitmap->Height; for(y=0,yy=0 ;yuBitmap->Height;y++,yy++){ StatusProgress->Position = y; bpMainImage = Image->uBitmap->GetScanLine(y) ; // MainImage bpMaskImage = uBitmap->GetScanLine(yy%uBitmap->Height); // pattern bpUndo = MainImageForm->iMainImage->uBitmap->GetUndoScanLine(y) ; // UndoImage for(x = 0,xx = 0 ; x < Image->uBitmap->Width;x++,xx++,bpUndo+=3,bpMainImage+=3) { if (uBitmap->BitsPerPixel == 8) { uBitPoz = xx%uBitmap->Width; r = spalette->ColorData[*(bpMaskImage + uBitPoz) + 1]->RGB.rgbRed; g = spalette->ColorData[*(bpMaskImage + uBitPoz) + 1]->RGB.rgbGreen; b = spalette->ColorData[*(bpMaskImage + uBitPoz) + 1]->RGB.rgbBlue; } else { uBitPoz = (xx*3)%(uBitmap->Width*3); b = Byte(*(bpMaskImage + uBitPoz)); g = Byte(*(bpMaskImage + uBitPoz + 1)); r = Byte(*(bpMaskImage + uBitPoz + 2)); } b = (b+g+r)/3; GetPixel24(bpUndo,temp); // UndoImage¸¦ Àбâ TColor2HLS((TColor)temp,APMask.Hue,APMask.Lig,APMask.Sat); //rÀ» 0~255·Î µÇ¾î ÀÖ°í ¸íµµ°ªÀº -128 ~ 128±îÁö µÇ¾î ÀÖ´Ù. APMask.Lig += (b - 125) * APRange; if(APMask.Lig < 0) APMask.Lig = 0 ; if(APMask.Lig > 1) APMask.Lig = 1.0; temp = HLS2TColor(APMask.Hue,APMask.Lig,APMask.Sat); SetPixel24(bpMainImage, temp); //MainImage ¿¡ ¾²±â } Image->uBitmap->PutScanLine(y); } } StatusProgress->End(); uBitmap->StopScanLine(); Image->uBitmap->StopScanLine(); MainImageForm->iMainImage->uBitmap->StopUndoScanLine(); //by linuxjun if (libData) delete libData; libData = NULL; ::RepaintColor(); Screen->Cursor = OldCursor; END_LOG; return true; fail: if (libData) delete libData; libData = NULL; END_LOG; EXCEPTION_MESSAGE_OK(ec); return false; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::rzbitbtnRearrangeClick(TObject *Sender) { OldConvertGrayScale(); //ConvertGrayScale1(); } //--------------------------------------------------------------------------- bool __fastcall TAPMenuForm::OldConvertGrayScale() { BEGIN_LOG("APMenu_F"); int i,j,PCount; BYTE r,g,b; THLS APTemp,*APSColor; int PaletteIndex[52]; RECT rect; double Interval; BYTE *bp,*tempbp; RGBQUAD temp,*sColor; TPException ec = EC_NONE; TTexpiaBitmap *tb; RGBQUAD rgb[256]; TCursor OldCursor; PCount = MainImageForm->Palette->UseColor; if(PCount > 52){ ShowMessage(IDS_MESSAGE_LESSTHENCOLOR); END_LOG; return false; } OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; MainImageForm->Palette->UseColor = 52; // 1µµÀÏ ¶§´Â rearrange ¾ÈÇØÁ༭ Æí¹ýÀ¸·Î.. by celberus RunRearrange(); PCount = 52;//MainImageForm->Palette->UseColor; if (PCount == 1) { //(PCount -1)·Î ³ª´©´Â ¹®Á¦ ¹ß»ý 100715 by david END_LOG; return false; } Interval = 50.0 / (PCount -1); APSColor = new THLS[PCount]; sColor = new RGBQUAD[PCount]; for(i = 2; i < PCount +2; i++) { r = PaletteForm->DIB256Palette->Palette->ColorData[i]->RGB.rgbRed; g = PaletteForm->DIB256Palette->Palette->ColorData[i]->RGB.rgbGreen; b = PaletteForm->DIB256Palette->Palette->ColorData[i]->RGB.rgbBlue; RGB2HLS(r,g,b,APSColor[i-2].Hue,APSColor[i-2].Lig,APSColor[i-2].Sat); } for(i = 0 ; i < PCount ; i++){ sColor[i].rgbRed = PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbRed; sColor[i].rgbGreen = PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbGreen; sColor[i].rgbBlue = PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbBlue; } // ¸íµµ¿¡ µû¶ó Palette ¸¦ Á¤·Ä for(i = 0 ; i < PCount -1; i++) { for(j = i+1; j < PCount; j++) { if(APSColor[i].Lig > APSColor[j].Lig){ APTemp.Lig = APSColor[i].Lig; APSColor[i].Lig = APSColor[j].Lig; APSColor[j].Lig = APTemp.Lig; temp.rgbRed = PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbRed; temp.rgbGreen = PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbGreen; temp.rgbBlue = PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbBlue; PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbRed = PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbRed; PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbGreen = PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbGreen; PaletteForm->DIB256Palette->Palette->ColorData[i+2]->RGB.rgbBlue = PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbBlue; PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbRed = temp.rgbRed; PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbGreen = temp.rgbGreen; PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbBlue = temp.rgbBlue; } } } // Á¤·ÄµÈ Palette ¿¡ Àû¿ëÇÒ index ÀÇ ¹è¿­ »ý¼º for(i = 0 ; i < PCount; i++){ for(j = 0 ; j < PCount; j++) { if( (sColor[i].rgbRed == PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbRed) && (sColor[i].rgbGreen == PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbGreen) && (sColor[i].rgbBlue == PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbBlue)) { PaletteIndex[i] = j+2; break; } } } delete []APSColor; delete []sColor; MainImageForm->iMainImage->uBitmap->StartScanLine(); if(MainImageForm->WorkArea->Mask){ RECT Dst; COLORREF C; rect = MainImageForm->WorkArea->Range; Dst = Rect(0,0,MainImageForm->iMainImage->uBitmap->Width,MainImageForm->iMainImage->uBitmap->Height); if ((tb = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } tb->Create(rect.right - rect.left, rect.bottom - rect.top, 8, rgb); C = PaletteForm->DIB256Palette->GetBGCOLORREF(8); // ÀÛ¾÷¿µ¿ª À̹ÌÁö¸¦ tb À̹ÌÁö¿¡ º¹»ç tb->StartScanLine(); for(i = rect.top ; i < rect.bottom; i++) { bp = MainImageForm->iMainImage->uBitmap->GetScanLine(i); tempbp = tb->GetScanLine(i - rect.top); for(j = rect.left ; j < rect.right; j++) { tempbp[j-rect.left] = bp[j]; } tb->PutScanLine(i-rect.top); } // ¸ÞÀÎ À̹ÌÁö¸¦ ¹è°æ»öÀ¸·Î ä¿ò MainImageForm->iMainImage->uBitmap->FillRect(Dst, C); // tb À̹ÌÁö¿¡ µû¶ó ¸ÞÀÎ À̹ÌÁöÀÇ ÀÛ¾÷¿µ¿ªÀ» º¯°æ for(i = rect.top ; i < rect.bottom; i++) { bp = MainImageForm->iMainImage->uBitmap->GetScanLine(i); tempbp = tb->GetScanLine(i - rect.top); for(j = rect.left ; j < rect.right; j++) { if(*(tempbp + j - rect.left) == 1){ bp[j] = 52; } else { bp[j] = ((BYTE)(PaletteIndex[*(tempbp+j-rect.left)-2])-2) * Interval +2; } } MainImageForm->iMainImage->uBitmap->PutScanLine(i); } tb->StopScanLine(); delete tb; } else { for(i = 0 ;i < MainImageForm->iMainImage->uBitmap->Height;i++){ bp = MainImageForm->iMainImage->uBitmap->GetScanLine(i); for(j = 0 ; j < MainImageForm->iMainImage->uBitmap->Width;j++) { if(*(bp+j) == 1) bp[j] = 52; else{ bp[j] = ((BYTE)(PaletteIndex[*(bp+j)-2]) - 2) * Interval +2; } } MainImageForm->iMainImage->uBitmap->PutScanLine(i); } } MainImageForm->iMainImage->uBitmap->StopScanLine(); // ¹è°æ»öÀ» ÁöÁ¤ PaletteForm->DIB256Palette->Palette->ColorData[1]->RGB.rgbRed = 0; PaletteForm->DIB256Palette->Palette->ColorData[1]->RGB.rgbGreen = 0; PaletteForm->DIB256Palette->Palette->ColorData[1]->RGB.rgbBlue = 0; // Palette ÀÇ »ö±ò ÁöÁ¤ for(i = 2 ; i< 53; i++){ PaletteForm->DIB256Palette->Palette->ColorData[i]->RGB.rgbRed = (i-2) * 4.9; PaletteForm->DIB256Palette->Palette->ColorData[i]->RGB.rgbGreen = (i-2)* 4.9; PaletteForm->DIB256Palette->Palette->ColorData[i]->RGB.rgbBlue = (i-2) * 4.9; } MainImageForm->Palette->UseColor = PCount; // // ::RunRearrange(); // by celberus Àý´ë ÇÏÁö¸¶¼¼¿ä. ¼ø¼­°¡ ¹Ù²î¸é ¾ÈµË´Ï´Ù ::RepaintColor(); //sbRearrange->Enabled = false; MainMenuForm->Rearrange1->Enabled = false; Screen->Cursor = OldCursor; END_LOG; return true; fail: if (tb) delete tb; EXCEPTION_MESSAGE_OK(ec); END_LOG; return false; } //--------------------------------------------------------------------------- // ÆÈ·¹Æ®ÀÇ »öÀ» ¹à±â·Î ºñ±³ÇÏ¿© Á¤·ÄÇϰí 255¸¦ 250À¸·Î ³ª´« interval¸¸Å­ÀÇ // Â÷ÀÌ·Î Grayscale ó¸® ÇÔ // ±âÁ¸Ã³·³ ÆÈ·¹Æ®ÀÇ »ö À§Ä¡³ª Gray»öÀ¸·Î º¯°æÇÏÁö ¾Ê°í Àӽà µ¥ÀÌÅÍ·Î ¸¸µé°í // index¸¦ ÀÌ¿ëÇÏ¿© ó¸® ÇÔ. //--------------------------------------------------------------------------- bool __fastcall TAPMenuForm::ConvertGrayScale1() { BEGIN_LOG("APMenu_F"); int i,j,PCount; BYTE r,g,b; THLS APTemp,*APSColor; RECT rect; double Interval; BYTE *bp,*tempbp; RGBQUAD temp,*sColor; TPException ec = EC_NONE; TTexpiaBitmap *tb; RGBQUAD rgb[256]; TCursor OldCursor; OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; // 1µµÀÏ ¶§´Â rearrange ¾ÈÇØÁ༭ Æí¹ýÀ¸·Î.. by celberus MainImageForm->Palette->UseColor = 52; RunRearrange(); PCount = 250; if (PCount == 1) { //(PCount -1)·Î ³ª´©´Â ¹®Á¦ ¹ß»ý 100715 by david END_LOG; return false; } Interval = 255.0 / PCount; APSColor = new THLS[PCount]; sColor = new RGBQUAD[PCount]; int tIndex, *TempPalette; int *PaletteIndex; TempPalette = new int[PCount]; PaletteIndex = new int[PCount]; for(i = 0; i < PCount; i++) { r = PaletteForm->DIB256Palette->Palette->ColorData[i+1]->RGB.rgbRed; g = PaletteForm->DIB256Palette->Palette->ColorData[i+1]->RGB.rgbGreen; b = PaletteForm->DIB256Palette->Palette->ColorData[i+1]->RGB.rgbBlue; sColor[i].rgbRed = r; sColor[i].rgbGreen = g; sColor[i].rgbBlue = b; PaletteIndex[i] = i+1; RGB2HLS(r,g,b,APSColor[i].Hue,APSColor[i].Lig,APSColor[i].Sat); // Temp Palette ÀÇ »ö±ò ÁöÁ¤ TempPalette[i] = Interval * i; } // ¸íµµ¿¡ µû¶ó Palette ¸¦ Á¤·Ä for(i = 0 ; i < PCount; i++) { for(j = i + 1; j < PCount; j++) { if(APSColor[i].Lig > APSColor[j].Lig){ APTemp.Lig = APSColor[i].Lig; APSColor[i].Lig = APSColor[j].Lig; APSColor[j].Lig = APTemp.Lig; tIndex = PaletteIndex[i]; PaletteIndex[i] = PaletteIndex[j]; PaletteIndex[j] = tIndex; } } } delete []APSColor; delete []sColor; delete []TempPalette; delete []PaletteIndex; // Temp Palette ÀÇ »ö±ò ÁöÁ¤ for(j = 0 ; j < MainImageForm->Palette->UseColor; j++) { for (i = 0; i < PCount; i++) { if (j+1 == PaletteIndex[i]) { PaletteForm->DIB256Palette->Palette->ColorData[j+1]->RGB.rgbRed = TempPalette[i]; PaletteForm->DIB256Palette->Palette->ColorData[j+1]->RGB.rgbGreen = TempPalette[i]; PaletteForm->DIB256Palette->Palette->ColorData[j+1]->RGB.rgbBlue = TempPalette[i]; break; } } } ::RepaintColor(); MainMenuForm->Rearrange1->Enabled = false; Screen->Cursor = OldCursor; END_LOG; return true; fail: if (tb) delete tb; EXCEPTION_MESSAGE_OK(ec); END_LOG; return false; } //--------------------------------------------------------------------------- // ÆÈ·¹Æ®ÀÇ »öÀÇ Â÷À̸¦ ÀÌ¿ëÇÏÁö ¾Ê°í R,G,B¸¦ ´õÇØ¼­ 3À¸·Î ³ª´« °ªÀ¸·Î // Grayscale ó¸® ÇÔ //--------------------------------------------------------------------------- bool __fastcall TAPMenuForm::ConvertGrayScale2() { int PCount; BYTE r,g,b; // 1µµÀÏ ¶§´Â rearrange ¾ÈÇØÁ༭ Æí¹ýÀ¸·Î.. by celberus MainImageForm->Palette->UseColor = 52; RunRearrange(); PCount = MainImageForm->Palette->UseColor; for(int j = 0 ; j < PCount; j++) { r = PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbRed; g = PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbGreen; b = PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbBlue; PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbRed = (r+g+b)/3; PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbGreen = (r+g+b)/3; PaletteForm->DIB256Palette->Palette->ColorData[j+2]->RGB.rgbBlue = (r+g+b)/3; } ::RepaintColor(); return true; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::rzbitbtnFileClick(TObject *Sender) { APTableForm->Show(); } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::sbFileClick(TObject *Sender) { APTableForm->Show(); } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::FormClose(TObject *Sender, TCloseAction &Action) { BEGIN_LOG(""); HWND hWnd = ((TWinControl *)Owner)->Handle; PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); END_LOG; } //--------------------------------------------------------------------------- void __fastcall TAPMenuForm::FormDestroy(TObject *Sender) { if (LibraryForm) LibraryForm->OnRead = NULL; } //---------------------------------------------------------------------------