//{ ----------------------------------------------------------------------------} //{ Authorization : F. A Electronics } //{ Date : 1997. 6. } //{ Compiler : Delphi 3.0 } //{ ----------------------------------------------------------------------------} //{ Palette.pas } //--------------------------------------------------------------------------- #pragma hdrstop #include "Palettes.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall TPalette::TPalette() { for (int i = 0; i < 256; i++){ FColorData[i] = new TColorData(); } FUseColor = 1; FColorCount = 2; } //--------------------------------------------------------------------------- __fastcall TPalette::~TPalette() { for (int i = 0; i < 256; i++){ delete FColorData[i]; } } //--------------------------------------------------------------------------- //Private Method //--------------------------------------------------------------------------- TColorData *__fastcall TPalette::GetColorData(int n) { return FColorData[n]; } //--------------------------------------------------------------------------- TColor __fastcall TPalette::GetColor(int n) { return FColorData[n]->Color; } //--------------------------------------------------------------------------- void __fastcall TPalette::SetColorData(int n, TColorData *cm) { FColorData[n]->Copy(cm); } //--------------------------------------------------------------------------- //Public Method //--------------------------------------------------------------------------- void __fastcall TPalette::SetPalette(TPalette *APalette) { int i; for (i = 0; i < 256; i++){ FColorData[i]->Copy(APalette->FColorData[i]); } FUseColor = APalette->UseColor; FColorCount = APalette->ColorCount; } //--------------------------------------------------------------------------- void __fastcall TPalette::SetTexPalette(TTexColor *ATexPalette, int ATexPalette_Size) { int i; FColorData[0]->SetNormal(0, 0, 0); for(i = 1; i < 256; i++){ if (i <= ATexPalette_Size){ FColorData[i]->SetTexColor(ATexPalette[i-1]); } else { FColorData[i]->SetNormal(i, i, i); } } } //--------------------------------------------------------------------------- bool __fastcall TPalette::LoadFromFile(Char *FileName) { // palette file(.fcr) HANDLE FH; DWORD dwRead; TTexVersion ver; int i; TTexColor palette[225]; FColorCount = 256; FH = CreateFile(FileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (FH != INVALID_HANDLE_VALUE){ ReadFile(FH, &ver, sizeof(TTexVersion), &dwRead, NULL); if ((ver.Texpia == 'C') && (ver.Method == 'P')){ if (ver.Number <= 100) { for (i = 0; i < 256; i++){ FColorData[i]->LoadFromFile(FH, 0); } } else if (100 < ver.Number && ver.Number <= 110){ for (i = 0; i < 256; i++){ FColorData[i]->LoadFromFile(FH, 1); } } else if (111 == ver.Number){ // texprint ÆÄÀÏÀÓ } else if (112 <= ver.Number){ //shin palette add ColorCount : 112 ReadFile(FH, &FUseColor, sizeof(WORD), &dwRead, NULL); ReadFile(FH, &FColorCount, sizeof(WORD), &dwRead, NULL); for (i = 0; i < 256; i++){ //for (i = 0; i < FColorCount; i++){ FColorData[i]->LoadFromFile(FH, 2); } } } else { SetFilePointer(FH, 0, NULL, FILE_BEGIN); ReadFile(FH, palette, sizeof(palette), &dwRead, NULL); FColorData[0]->SetNormal(0, 0, 0); for(i = 1; i < 256; i++){ if (i<=225){ FColorData[i]->SetTexColor(palette[i-1]); } else { FColorData[i]->SetNormal(i, i, i); } } } CloseHandle(FH); return true; } else { return false; } } //--------------------------------------------------------------------------- void __fastcall TPalette::SaveToFile(Char *FileName) { // palette file(.fcr) HANDLE FH; DWORD dwWrite; TTexVersion ver; int i; int version = 2; FH = CreateFile(FileName, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); if (FH != INVALID_HANDLE_VALUE){ ver.Texpia = 'C'; ver.Method = 'P'; ver.Number = 112; //shin palette add ColorCount : 112 WriteFile(FH, &ver, sizeof(TTexVersion), &dwWrite, NULL); WriteFile(FH, &FUseColor, sizeof(WORD), &dwWrite, NULL); //shin palette add ColorCount : 111 WriteFile(FH, &FColorCount, sizeof(WORD), &dwWrite, NULL); for (i = 0; i < 256; i++){ FColorData[i]->SaveToFile(FH, version); } CloseHandle(FH); } else { String msg = "Cannot open file" + String(FileName); throw (Exception(msg));//EFOpenError(msg); } } //--------------------------------------------------------------------------- void __fastcall TPalette::LoadFromFileHandle(HANDLE FH, int v) { DWORD dwRead; int Version = 0; if (1 < v){ ReadFile(FH, &Version, sizeof(int), &dwRead, NULL); //shin palette add ColorCount : 111 ReadFile(FH, &FUseColor, sizeof(WORD), &dwRead, NULL); //shin palette add ColorCount : 111 ReadFile(FH, &FColorCount, sizeof(WORD), &dwRead, NULL); //shin palette add ColorCount : 111 } else { FColorCount = 256; } for(int i = 0; i < 256; i++){ FColorData[i]->LoadFromFile(FH, v); } } //--------------------------------------------------------------------------- void __fastcall TPalette::SaveToFileHandle(HANDLE FH, int v) { DWORD dwWrite; if (v > 1) { int Version = 112; //ÆÈ·¹Æ®ÆÄÀÏÀúÀåÇÒ¶§¿Í µ¿ÀÏÇÏ°Ô WriteFile(FH, &Version, sizeof(int), &dwWrite, NULL); //shin palette add ColorCount WriteFile(FH, &FUseColor, sizeof(WORD), &dwWrite, NULL); //shin palette add ColorCount WriteFile(FH, &FColorCount, sizeof(WORD), &dwWrite, NULL); //shin palette add ColorCount } for(int i = 0; i < 256; i++){ FColorData[i]->SaveToFile(FH, v); } } //--------------------------------------------------------------------------- void __fastcall TPalette::ToRGBQUAD(RGBQUAD *v, int v_Size) { for (int i = 0; i < v_Size; i++){ v[i] = FColorData[i]->RGB; } } //--------------------------------------------------------------------------- void __fastcall TPalette::MakeSpread(int nColorCount, BYTE *ColorIndex, int ColorIndex_Size, BYTE *Gap, int Gap_Size) { int i, j, k; BYTE r, g, b; RGBQUAD rgb[2]; int SpreadCount; SpreadCount = 1; for(i = 0; i < nColorCount; i++){ SpreadCount = SpreadCount + Gap[i]; } k = FUseColor + 1; for(i = 0; i < nColorCount; i++){ ColorData[k] = ColorData[ColorIndex[i]]; k++; rgb[0] = ColorData[ColorIndex[i]]->RGB; rgb[1] = ColorData[ColorIndex[i+1]]->RGB; for(j = 1; j < Gap[i]; j++){ r = rgb[0].rgbRed + (((rgb[1].rgbRed - rgb[0].rgbRed)*j)/Gap[i]); g = rgb[0].rgbGreen + (((rgb[1].rgbGreen - rgb[0].rgbGreen)*j)/Gap[i]); b = rgb[0].rgbBlue + (((rgb[1].rgbBlue - rgb[0].rgbBlue)*j)/Gap[i]); SetNormal(k, r, g, b); k++; } } ColorData[k] = ColorData[ColorIndex[nColorCount]]; FUseColor = FUseColor + SpreadCount; if (FColorCount <= FUseColor) FColorCount = FUseColor + 1; if (FColorCount > 252) FColorCount = 252; } //--------------------------------------------------------------------------- void __fastcall TPalette::Copy(int i, TColorData* cm) { FColorData[i]->Copy(cm); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetNormal(int i, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetNormal(r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetPrinterColor(int i, WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetPrinterColor(p, n, r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetPantone1000(int i, WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetPantone1000(p, n, r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetPantoneTextile(int i, WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetPantoneTextile(p, n, r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetTPStandardColor(int i, WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetTPStandardColor(p, n, r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetTPTextileColor(int i, WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetTPTextileColor(p, n, r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetUserColor(int i, WORD k, WORD p, BYTE n, BYTE r, BYTE g, BYTE b, Char * fn, Char * cn, Char *pc, Char *pf) { FColorData[i]->SetUserColor(k, p, n, r, g, b, fn, cn, pc, pf); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetPantoneColor(int i, WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { FColorData[i]->SetPantoneColor(p, n, r, g, b); } //--------------------------------------------------------------------------- void __fastcall TPalette::SetUserColor(int i, void *data) { FColorData[i]->SetUserColor(data); } //--------------------------------------------------------------------------- ///PANTONE Color Ãß°¡·Î »ý±â°Ô µÊ. ¼Ó¼º¹øÈ£´Â 6 ¹øÀ» ºÎ¿©ÇÔ by smallpotato(2008.03.07) void __fastcall TPalette::SetPantoneColor2(int i, void *data) { FColorData[i]->SetPantoneColor2(data); } //--------------------------------------------------------------------------- void __fastcall TPalette::RGBToHLS(int n, double &h, double &l, double &s) { RGB2HLS(FColorData[n]->RGB.rgbRed, FColorData[n]->RGB.rgbGreen, FColorData[n]->RGB.rgbBlue, h, l, s); } //--------------------------------------------------------------------------- void __fastcall TPalette::HLSToRGB(int n, double h, double l, double s) { BYTE r, g, b; HLS2RGB(h, l, s, r, g, b); SetNormal(n, r, g, b); } //--------------------------------------------------------------------------- WORD __fastcall TPalette::GetUseColor() { return FUseColor; } //--------------------------------------------------------------------------- void __fastcall TPalette::SetUseColor(WORD Value) { FUseColor = Value; if (FColorCount <= FUseColor) FColorCount = FUseColor + 1; } //--------------------------------------------------------------------------- WORD __fastcall TPalette::GetColorCount() { return FColorCount; } //--------------------------------------------------------------------------- void __fastcall TPalette::SetColorCount(WORD Value) { FColorCount = Value; } //---------------------------------------------------------------------------