//--------------------------------------------------------------------------- #pragma hdrstop #include "TClrUtil.h" #include //#include "ColorLibrary.h" // Palette Upgrade - by monkman (2006.09.29) //--------------------------------------------------------------------------- #pragma package(smart_init) // »ç¿ëÇÏÁö ¾ÊÀ½ - by monkman (2007.06.25) TAdditionalColorDataTag::TAdditionalColorDataTag() { Data = NULL; } //--------------------------------------------------------------------------- TAdditionalColorDataTag::~TAdditionalColorDataTag() { if(Data != NULL) delete[] Data; } //--------------------------------------------------------------------------- void TAdditionalColorDataTag::MakeTag(TUCLTagNum tag_number, TUCLTagType tag_type, int count, const void* data, int data_size) { TagNumber = tag_number; TagType = tag_type; Count = count; Data = new BYTE[data_size]; memcpy(Data, data, data_size); } //--------------------------------------------------------------------------- TAdditionalColorData::TAdditionalColorData() { Reset(); } //--------------------------------------------------------------------------- TAdditionalColorData::~TAdditionalColorData() { Reset(); } //--------------------------------------------------------------------------- void TAdditionalColorData::AddTag(TUCLTagNum tag_number, TUCLTagType tag_type, int count, const void* data) { TAdditionalColorDataTag* tag = new TAdditionalColorDataTag(); tag->MakeTag(tag_number, tag_type, count, data, HowManyBytesOccupy(tag_type) * count); TagList.push_back(tag); } //--------------------------------------------------------------------------- void TAdditionalColorData::DeleteTag(TUCLTagNum tag_number) { for(std::list::iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { if(tag_number == (*iter)->TagNumber) { delete *iter; TagList.erase(iter); break; } } } //--------------------------------------------------------------------------- void TAdditionalColorData::Copy(const TAdditionalColorData& additional_color_data) { for(std::list::const_iterator iter = additional_color_data.TagList.begin() ; iter != additional_color_data.TagList.end() ; ++iter) { AddTag((*iter)->TagNumber, (*iter)->TagType, (*iter)->Count, (*iter)->Data); } } //--------------------------------------------------------------------------- const bool TAdditionalColorData::Compare(const TAdditionalColorData& additional_color_data) const { for(std::list::const_iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { const BYTE* data = GetData((*iter)->TagNumber); if( data == NULL || memcmp(data, (*iter)->Data, HowManyBytesOccupy((*iter)->TagType) * (*iter)->Count) != 0 ) return false; } return true; } //--------------------------------------------------------------------------- const BYTE* TAdditionalColorData::GetData(TUCLTagNum tag_number) const { for(std::list::const_iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { if((*iter)->TagNumber == tag_number) return (*iter)->Data; } return NULL; } //--------------------------------------------------------------------------- const TUCLTagType TAdditionalColorData::GetType(TUCLTagNum tag_number) const { for(std::list::const_iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { if((*iter)->TagNumber == tag_number) return (*iter)->TagType; } return TAG_NULL_TYPE; } //--------------------------------------------------------------------------- const int TAdditionalColorData::HowManyBytesOccupy(TUCLTagType tag_type) const { int result_bytes = -1; switch(tag_type) { case TAG_BYTE_TYPE: result_bytes = sizeof(BYTE); break; case TAG_CHAR_TYPE: result_bytes = sizeof(char); break; case TAG_SHORT_TYPE: result_bytes = sizeof(short); break; case TAG_INT_TYPE: result_bytes = sizeof(int); break; case TAG_FLOAT_TYPE: result_bytes = sizeof(float); break; case TAG_WCHAR_TYPE: result_bytes = sizeof(wchar_t); break; } return result_bytes; } //--------------------------------------------------------------------------- int TAdditionalColorData::SaveClipBoard(Byte *lpData) { int size = 0; TUCLTagNum tagNum = NULL; int tagCount = TagList.size(); memcpy(lpData, &tagCount, sizeof(int)); lpData += sizeof(int); size += sizeof(int); for(std::list::iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { TUCLTagNum num = (*iter)->TagNumber; TUCLTagType type = (*iter)->TagType; int tcount = (*iter)->Count; Byte *temp = (*iter)->Data; memcpy(lpData, &(*iter)->TagNumber, sizeof(TUCLTagNum)); // TUCLTagNum lpData += sizeof(TUCLTagNum); memcpy(lpData, &(*iter)->TagType, sizeof(TUCLTagType)); // TUCLTagType lpData += sizeof(TUCLTagType); memcpy(lpData, &(*iter)->Count, sizeof(int)); // FColorMode lpData += sizeof(int); int len = HowManyBytesOccupy((*iter)->TagType) * (*iter)->Count; memcpy(lpData, (*iter)->Data, len); // FColorMode lpData += len; int tagsize = sizeof(TUCLTagNum) + sizeof(TUCLTagType) + sizeof(int) + len; size += tagsize; } return size; } //--------------------------------------------------------------------------- int TAdditionalColorData::GetClipboard(Byte *lpData) { int tagCount = 0; memcpy(&tagCount, lpData, sizeof(int)); // FColorMode lpData += sizeof(int); int size = sizeof(int); TUCLTagNum tagNum = NULL; TUCLTagType tagType = NULL; int count = 0; for (int i = 0; i < tagCount; i++) { memcpy(&tagNum, lpData, sizeof(TUCLTagNum)); // TUCLTagNum lpData += sizeof(TUCLTagNum); size += sizeof(TUCLTagNum); memcpy(&tagType, lpData, sizeof(TUCLTagType)); // TUCLTagType lpData += sizeof(TUCLTagType); size += sizeof(TUCLTagType); memcpy(&count, lpData, sizeof(int)); // Count lpData += sizeof(int); size += sizeof(int); int len = HowManyBytesOccupy(tagType) * count; Byte *buf = new Byte[len]; memcpy(buf, lpData, len); // Data lpData += len; size += len; AddTag(tagNum, tagType, count, buf); delete[] buf; } return size; } //--------------------------------------------------------------------------- int TAdditionalColorData::GetDataSize() { int size = 0; size += sizeof(int); // TagList.size for(std::list::iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { size += sizeof(TUCLTagNum); size += sizeof(TUCLTagType); size += sizeof(int); size += (HowManyBytesOccupy((*iter)->TagType) * (*iter)->Count); } return size; } //--------------------------------------------------------------------------- void TAdditionalColorData::Reset() { for(std::list::iterator iter = TagList.begin() ; iter != TagList.end() ; ++iter) { delete (*iter); } TagList.clear(); } //--------------------------------------------------------------------------- // Private Method //--------------------------------------------------------------------------- void __fastcall TColorData::DeleteUserColor() { if (FileName != NULL){ delete[] FileName; FileName = NULL; } if (ColorName != NULL){ delete[] ColorName; ColorName = NULL; } // if (PantoneColor != NULL){ // delete[] PantoneColor; // PantoneColor = NULL; // } // if (PantoneFileName != NULL){ // delete[] PantoneFileName; // PantoneFileName = NULL; // } } //--------------------------------------------------------------------------- WORD __fastcall TColorData::GetKind() { return (WORD)(FInfor & 0x7FFF); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetKind(WORD s) { FInfor = ((FInfor & 0x8000) | (s & 0x7FFF)); } //--------------------------------------------------------------------------- WORD __fastcall TColorData::GetProtect() { return (WORD)((FInfor & 0x8000) >> 15); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetProtect(WORD s) { FInfor = FInfor = ((FInfor & 0x7FFF) | (s << 15)); } //--------------------------------------------------------------------------- Graphics::TColor __fastcall TColorData::GetColor() { return (Graphics::TColor)(RGB.rgbRed + (RGB.rgbGreen << 8) + (RGB.rgbBlue << 16)); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetColor(TColor tcolor) { BYTE r, g, b; r = (BYTE)tcolor; g = (BYTE)(tcolor >> 8); b = (BYTE)(tcolor >> 16); SetNormal(r, g, b); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetFileName(int len, Char *srcName) { if (FileName == NULL) FileName = new Char[len]; Char *strChar = new Char[len]; if (strChar) { _tcscpy(strChar, srcName); //memcpy(&strChar, srcName, sizeof(Char)*len); StrCopy(FileName, strChar); delete[] strChar; } } //--------------------------------------------------------------------------- void __fastcall TColorData::SetColorName(int len, Char *srcName) { if (ColorName == NULL) ColorName = new Char[len]; Char *strChar = new Char[len]; if (strChar) { _tcscpy(strChar, srcName); //memcpy(&strChar, srcName, sizeof(Char)*len); StrCopy(ColorName, strChar); delete[] strChar; } } //--------------------------------------------------------------------------- void __fastcall TColorData::SetPantoneColorName(int len, Char *srcName) { // if (PantoneColor == NULL) // PantoneColor = new Char[len]; // // Char *strChar = new Char[len]; // if (strChar) { // _tcscpy(strChar, srcName); // // StrCopy(PantoneColor, strChar); // delete[] strChar; // } } //--------------------------------------------------------------------------- void __fastcall TColorData::SetPantoneFileName(int len, Char *srcName) { // if (PantoneFileName == NULL) // PantoneFileName = new Char[len]; // // Char *strChar = new Char[len]; // if (strChar) { // _tcscpy(strChar, srcName); // // StrCopy(PantoneFileName, strChar); // delete[] strChar; // } } //--------------------------------------------------------------------------- void __fastcall TColorData::PantoneToTPColor() { int i; switch ((FInfor & 0x0F)) { case 0x0001: FInfor = FInfor + 2; for (i = 0; i < 148; i++) { if (FPage == StandardPage[i]) FPage = 20 + i; } break; case 0x0002: FInfor = FInfor + 2; FPage = FPage + 1000; break; } } //--------------------------------------------------------------------------- void __fastcall TColorData::EnumChangeColorMode(TColorMode &color_mode) { if (color_mode == OLD_TCM_MORE_TAGS_ADDED) color_mode = TCM_MORE_TAGS_ADDED; } //--------------------------------------------------------------------------- void __fastcall TColorData::EnumChangeUCLTagNum(TUCLTagNum &tag_number) { if (tag_number == OLD_TAG_PANTONE_BOOK_ORDER) tag_number = TAG_PANTONE_BOOK_ORDER; else if (tag_number == OLD_TAG_PANTONE_COLOR) tag_number = TAG_PANTONE_COLOR; else if (tag_number == OLD_TAG_PANTONE_COLOR_NAME) tag_number = TAG_PANTONE_COLOR_NAME; else if (tag_number == OLD_TAG_PANTONE_PEARL_COLOR_WARNING_MSG) tag_number = TAG_PANTONE_PEARL_COLOR_WARNING_MSG; else if (tag_number == OLD_TAG_BOOK_NAME) tag_number = TAG_BOOK_NAME; else if (tag_number == OLD_TAG_MAX) tag_number = TAG_MAX; } //--------------------------------------------------------------------------- void __fastcall TColorData::EnumChangeUCLTagType(TUCLTagType &tag_type) { if (tag_type == OLD_TAG_MAX_TYPE) tag_type = TAG_MAX_TYPE; } //--------------------------------------------------------------------------- // Public Method //--------------------------------------------------------------------------- __fastcall TColorData::TColorData() { FColorMode = TCM_RGB; //texprint FInfor = 0; FPage = 0; FNumber = 0; FReserved = 0; //texprint FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = 0; FRGB.rgbGreen = 0; FRGB.rgbBlue = 0; FRGB.rgbReserved = 0; FValue1 = UNDEFINED; FValue2 = UNDEFINED; FValue3 = UNDEFINED; FValue4 = UNDEFINED; FileName = NULL; ColorName = NULL; // PantoneColor = NULL; // PantoneFileName = NULL; additionalColorData = new TAdditionalColorData(); } //--------------------------------------------------------------------------- __fastcall TColorData::~TColorData() { DeleteUserColor(); if (additionalColorData) delete additionalColorData; } //--------------------------------------------------------------------------- bool __fastcall TColorData::Compare(TColorData *cm) { bool bReturn = true; TAdditionalColorData* buf1 = additionalColorData; TAdditionalColorData* buf2 = cm->additionalColorData; if (FColorMode == cm->ColorMode && FInfor == cm->Infor && FPage == cm->Page && FNumber == cm->Number && FValue1 == cm->Value1 && FValue2 == cm->Value2 && FValue3 == cm->Value3 && FValue4 == cm->Value4) { if ((FInfor & 0x1000) == 0x1000 && StrComp(ColorName, cm->ColorName) != 0) bReturn = false; if ((FInfor & 0x2000) == 0x2000 && StrComp(FileName, cm->FileName) != 0) bReturn = false; if(additionalColorData->Compare(*(cm->additionalColorData)) == false) bReturn = false; } else if (FInfor == cm->Infor && FPage == cm->Page && FNumber == cm->Number && FRGB.rgbRed == cm->RGB.rgbRed && FRGB.rgbGreen == cm->RGB.rgbGreen && FRGB.rgbBlue == cm->RGB.rgbBlue) { if ((FInfor & 0x1000) == 0x1000 && StrComp(ColorName, cm->ColorName) != 0) bReturn = false; if ((FInfor & 0x2000) == 0x2000 && StrComp(FileName, cm->FileName) != 0) bReturn = false; if(additionalColorData->Compare(*(cm->additionalColorData)) == false) bReturn = false; } else { bReturn = false; } return bReturn; /* bool bReturn = true; if ((FInfor == cm->Infor) && (FPage == cm->Page) && (FNumber == cm->Number) && (FRGB.rgbRed == cm->RGB.rgbRed) && (FRGB.rgbGreen == cm->RGB.rgbGreen) && (FRGB.rgbBlue == cm->RGB.rgbBlue)) { if ((FInfor & 0x10) != 0){ if (FileName != NULL && cm->FileName != NULL){ if (StrComp(FileName, cm->FileName) ==0){ if (ColorName != NULL && cm->ColorName != NULL){ if (StrComp(ColorName, cm->ColorName) == 0) bReturn = true; else bReturn = false; } else { bReturn = false; } } else { bReturn = false; } } else { if (FileName == NULL && cm->FileName == NULL){ if (ColorName != NULL && cm->ColorName != NULL){ if (StrComp(ColorName, cm->ColorName) == 0) bReturn = true; else bReturn = false; } else { if (ColorName == NULL && cm->ColorName == NULL) bReturn = true; else bReturn = false; } } else { bReturn = false; } } } else { bReturn = true; } if ((FInfor & 0x06) != 0 ||(FInfor & 0x16) != 0){ //080410 if (PantoneColor != NULL && cm->PantoneColor != NULL){ if (StrComp(PantoneColor, cm->PantoneColor) == 0){ if (PantoneFileName != NULL && cm->PantoneFileName != NULL){ if (StrComp(PantoneFileName, cm->PantoneFileName) == 0) bReturn = true; else bReturn = false; } else { if (PantoneFileName == NULL && cm->PantoneFileName == NULL) bReturn = true; else bReturn = false; } } else { bReturn = false; } } else { if (PantoneColor == NULL && cm->PantoneColor == NULL){ if (PantoneFileName != NULL && cm->PantoneFileName != NULL){ if (StrComp(PantoneFileName, cm->PantoneFileName) == 0) bReturn = true; else bReturn = false; } if (PantoneFileName == NULL && cm->PantoneFileName == NULL) bReturn = true; else bReturn = false; } else { bReturn = false; } } } } else { bReturn = false; } return bReturn; */ } //--------------------------------------------------------------------------- void __fastcall TColorData::Copy(TColorData *cm) { /* FColorMode = cm->FColorMode; if (ColorName) { delete []ColorName; ColorName = NULL; } if (FileName) { delete []FileName; FileName = NULL; } additionalColorData->Reset(); if (cm->ColorName) { ColorName = new char[_tcslen(cm->ColorName)+1]; memset(ColorName, 0, _tcslen(cm->ColorName)+1); StrCopy(ColorName, cm->ColorName); SetKind((0x1000 | cm->Infor)); } if (cm->FileName) { FileName = new char[_tcslen(cm->FileName)+1]; memset(FileName, 0, _tcslen(cm->FileName)+1); StrCopy(FileName, cm->FileName); SetKind((0x2000 | cm->Infor)); } additionalColorData->Copy(*cm->additionalColorData); */ DeleteUserColor(); additionalColorData->Reset(); FColorMode = cm->FColorMode; FInfor = cm->Infor; FPage = cm->Page; FNumber = cm->Number; FReserved = cm->Reserved; FCode = cm->Code; FExtend = cm->Extend; FBase = cm->Base; FRGB = cm->RGB; FValue1 = cm->Value1; FValue2 = cm->Value2; FValue3 = cm->Value3; FValue4 = cm->Value4; if (cm->ColorName) { ColorName = new Char[_tcslen(cm->ColorName)+1]; memset(ColorName, 0, _tcslen(cm->ColorName)+1); StrCopy(ColorName, cm->ColorName); SetKind((0x1000 | cm->Infor)); } if (cm->FileName) { FileName = new Char[_tcslen(cm->FileName)+1]; memset(FileName, 0, _tcslen(cm->FileName)+1); StrCopy(FileName, cm->FileName); SetKind((0x2000 | cm->Infor)); } if(cm->additionalColorData != NULL) additionalColorData->Copy(*cm->additionalColorData); /* if ((FInfor & 0x10) != 0){ if (cm->FileName != NULL){ FileName = new Char[_tcslen(cm->FileName)+1]; StrCopy(FileName, cm->FileName); } if (cm->ColorName != NULL){ ColorName = new Char[_tcslen(cm->ColorName)+1]; StrCopy(ColorName, cm->ColorName); } } if ((FInfor & 0x06) != 0 ||(FInfor & 0x16) != 0){ //080410 if (cm->PantoneColor != NULL){ //»öº¸È£ ±â´ÉÀ» ½ÇÇàÇÑ ÈÄ copy / paste¸¦ ÇßÀ» ¶§ 254¹ø ColorData¿¡¼­ access error°¡ ¹ß»ýÇÏ¿© ÀÌ Á¶°ÇÀ» Ãß°¡ÇÔ. PantoneColor = new Char [_tcslen(cm->PantoneColor)+1]; //_tcslen(cm->PantoneColor)+1];//080417 StrCopy(PantoneColor, cm->PantoneColor); } if (cm->PantoneFileName != NULL){ PantoneFileName = new Char [_tcslen(cm->PantoneFileName)+1]; //_tcslen(cm->PantoneFileName)+1];//080417 StrCopy(PantoneFileName, cm->PantoneFileName); } } */ } //--------------------------------------------------------------------------- void __fastcall TColorData::LoadFromFile(HANDLE fh, int v)//, TAdditionalColorData *additional_color_data) { WORD n; BYTE Stand; DWORD dwRead; DeleteUserColor(); additionalColorData->Reset(); if (v==0) { ReadFile(fh, &FInfor, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FPage, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FNumber, sizeof(BYTE), &dwRead, NULL); ReadFile(fh, &Stand, sizeof(BYTE), &dwRead, NULL); ReadFile(fh, &FRGB, sizeof(tagRGBQUAD), &dwRead, NULL); } else if(v== 1){ //080408 ReadFile(fh, &FInfor, sizeof(Word), &dwRead, NULL); ReadFile(fh, &FPage, sizeof(Word), &dwRead, NULL); ReadFile(fh, &FNumber, sizeof(Byte), &dwRead, NULL); ReadFile(fh, &FRGB, sizeof(tagRGBQUAD), &dwRead, NULL); if ((FInfor & 0x10) > 0){ ReadFile(fh, &n, sizeof(WORD), &dwRead, NULL); char *fname = NULL; if (n > 0){ fname = new char[n+1]; memset(fname, 0, n+1); FileName = new Char[n+1]; ReadFile(fh, fname, n, &dwRead, NULL); StrCopy(FileName, String(fname).c_str()); delete[] fname; } ReadFile(fh, &n, sizeof(WORD), &dwRead, NULL); char *cname = NULL; if (n > 0){ cname = new char[n+1]; memset(cname, 0, n+1); ColorName = new Char[n+1]; ReadFile(fh, cname, n, &dwRead, NULL); StrCopy(ColorName, String(cname).c_str()); delete[] cname; } } char *pcolor = NULL; int len = 0; if((FInfor & 0x0F) == 0x06 || (FInfor & 0x1F) == 0x16){ if ((FInfor & 0x80) == 0){ ReadFile(fh, &len, sizeof(Word), &dwRead, NULL); if (len > 0){ pcolor = new char[len+1];//080417 memset(pcolor, 0, len+1); ReadFile(fh, pcolor, len, &dwRead, NULL); } } LoadAdditionalColorData(fh); } if ((FInfor & 0x10) > 0) { // UserColor (ColorName, FileName) if ((FInfor & 0x80) > 0) FInfor = ((FInfor & 0x0F) | 0x4000) | 0x8000; else FInfor = ((FInfor & 0x0F) | 0x4000); } else if ((FInfor & 0x80) > 0){ FInfor = ((FInfor & 0x0F) | 0x8000); } if (ColorName) FInfor |= 0x1000; if (FileName) FInfor |= 0x2000; //LoadAdditionalColorData(fh); if (pcolor){ // ~10.2 ÆÄÀÏ¿¡¼­ pantonecolor¸¦ ÀúÀåÇѰæ¿ì // additionalColorDataÀÇ tag¿¡ Ãß°¡½ÃŲ´Ù. // LoadAdditionalColorData(fh)¿¡¼­ additionalColorData¸¦ ºÒ·¯¿ÔÀ» °æ¿ì // Áߺ¹µÇ¾îÀÖÀ»¼öÀÖÀ¸¹Ç·Î additionalColorData°¡ ¾ø´Â °æ¿ì¸¸ Ãß°¡Çϵµ·Ï ÇÔ. if (additionalColorData->TagList.size() == 0){ additionalColorData->AddTag(TAG_PANTONE_COLOR, TAG_CHAR_TYPE, len+1, pcolor); } delete[] pcolor; } } else if (v >= 2){ int Version = 0; ReadFile(fh, &Version, sizeof(int), &dwRead, NULL); ReadFile(fh, &FColorMode, sizeof(TColorMode), &dwRead, NULL); ReadFile(fh, &FInfor, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FPage, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FNumber, sizeof(BYTE), &dwRead, NULL); ReadFile(fh, &FReserved, sizeof(BYTE), &dwRead, NULL); ReadFile(fh, &FCode, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FExtend, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FBase, sizeof(WORD), &dwRead, NULL); ReadFile(fh, &FRGB, sizeof(tagRGBQUAD), &dwRead, NULL); ReadFile(fh, &FValue1, sizeof(double), &dwRead, NULL); ReadFile(fh, &FValue2, sizeof(double), &dwRead, NULL); ReadFile(fh, &FValue3, sizeof(double), &dwRead, NULL); ReadFile(fh, &FValue4, sizeof(double), &dwRead, NULL); if ((FInfor & 0x1000) == 0x1000) { ReadFile(fh, &n, sizeof(WORD), &dwRead, NULL); ColorName = new Char[n+1]; memset(ColorName, 0, n+1); ReadFile(fh, ColorName, sizeof(Char)*n, &dwRead, NULL); } if ((FInfor & 0x2000) == 0x2000) { ReadFile(fh, &n, sizeof(WORD), &dwRead, NULL); FileName = new Char[n+1]; memset(FileName, 0, n+1); ReadFile(fh, FileName, sizeof(Char)*n, &dwRead, NULL); } LoadAdditionalColorData(fh); } else { return; } //if ((FInfor & 0x4000) != 0x4000) { // User Color°¡ ¾Æ´Ò¶§¸¸ Pantone Color¸¦ TP Color·Î.. - by monkman (2006.10.10) PantoneToTPColor(); //} } //--------------------------------------------------------------------------- void __fastcall TColorData::SaveToFile(HANDLE fh, int v)//, TAdditionalColorData *additional_color_data) { WORD n; DWORD dwWrite; // Textile 10.0 ÀÌÇÏ¿¡ ÇØ´çÇÏ´Â ColorData Çü½ÄÀ¸·Î ÀúÀå if (v <= 1) { WORD infor = 0; if (FInfor & 0x4000) infor = 0x10; infor |= (FInfor & 0xF); WriteFile(fh, &infor, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FPage, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FNumber, sizeof(BYTE), &dwWrite, NULL); WriteFile(fh, &FRGB, sizeof(tagRGBQUAD), &dwWrite, NULL); if ((infor & 0x10) != 0) { AnsiString ansiStr = FileName; if (ansiStr != "") n = strlen(ansiStr.c_str()); else n = 0; WriteFile(fh, &n, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, ansiStr.c_str(), sizeof(char)*n, &dwWrite, NULL); ansiStr = ColorName; if (ansiStr != "") n = strlen(ansiStr.c_str()); else n = 0; WriteFile(fh, &n, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, ansiStr.c_str(), sizeof(char)*n, &dwWrite, NULL); } if ((infor & 0x0F) == 0x06 || (infor & 0x1F) == 0x16) { AnsiString ansiStr = (char*)additionalColorData->GetData(TAG_PANTONE_COLOR); if (ansiStr != NULL) n = strlen(ansiStr.c_str()); else n = 0; WriteFile(fh, &n, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, ansiStr.c_str(), sizeof(char)*n, &dwWrite, NULL); } //SaveAdditionalColorData(fh); } else { int Version = 1; WriteFile(fh, &Version, sizeof(int), &dwWrite, NULL); WriteFile(fh, &FColorMode, sizeof(TColorMode), &dwWrite, NULL); WriteFile(fh, &FInfor, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FPage, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FNumber, sizeof(BYTE), &dwWrite, NULL); WriteFile(fh, &FReserved, sizeof(BYTE), &dwWrite, NULL); WriteFile(fh, &FCode, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FExtend, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FBase, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, &FRGB, sizeof(tagRGBQUAD), &dwWrite, NULL); WriteFile(fh, &FValue1, sizeof(double), &dwWrite, NULL); WriteFile(fh, &FValue2, sizeof(double), &dwWrite, NULL); WriteFile(fh, &FValue3, sizeof(double), &dwWrite, NULL); WriteFile(fh, &FValue4, sizeof(double), &dwWrite, NULL); if ((FInfor & 0x1000) == 0x1000) { n = StrLen(ColorName)+1; WriteFile(fh, &n, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, ColorName, sizeof(Char)*n, &dwWrite, NULL); } if ((FInfor & 0x2000) == 0x2000) { n = StrLen(FileName)+1; WriteFile(fh, &n, sizeof(WORD), &dwWrite, NULL); WriteFile(fh, FileName, sizeof(Char)*n, &dwWrite, NULL); } SaveAdditionalColorData(fh); } } //--------------------------------------------------------------------------- void __fastcall TColorData::SetNormal(BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(0); FPage = 0; FNumber = 0; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetPrinterColor(WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(0); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetPantone1000(WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(1); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetPantoneTextile(WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(2); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetTPStandardColor(WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(3); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetTPTextileColor(WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(4); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- //20050518 by lhskys pantone Color void __fastcall TColorData::SetPantoneColor(WORD p, BYTE n, BYTE r, BYTE g, BYTE b) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; SetKind(5); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetUserColor(WORD k, WORD p, BYTE n, BYTE r, BYTE g, BYTE b, Char *fn, Char *cn, Char *pc, Char *pf) { DeleteUserColor(); additionalColorData->Reset(); int nLength = 0; FColorMode = TCM_RGB; SetKind(0x4000); FPage = p; FNumber = n; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = r; FRGB.rgbGreen = g; FRGB.rgbBlue = b; FRGB.rgbReserved = 0; FValue1 = (double)r; FValue2 = (double)g; FValue3 = (double)b; FValue4 = (double)UNDEFINED; if (fn != NULL) { nLength = _tcslen(fn)+1; FileName = new Char[nLength]; StrCopy(FileName, fn); FInfor |= 0x2000; } if (cn != NULL) { nLength = _tcslen(cn)+1; ColorName = new Char[nLength]; StrCopy(ColorName, cn); FInfor |= 0x1000; } // if (pc != NULL){ // nLength = _tcslen(pc)+1; // PantoneColor = new Char[nLength]; // StrCopy(PantoneColor, pc); // } // if (pf != NULL){ // nLength = _tcslen(pf)+1; // PantoneFileName= new Char[nLength]; // StrCopy(PantoneFileName, pf); // } } //--------------------------------------------------------------------------- void __fastcall TColorData::SetTexColor(const TTexColor &tc) { DeleteUserColor(); additionalColorData->Reset(); FColorMode = TCM_RGB; if (tc.Kind < 3) { FInfor = tc.Kind; FPage = tc.Page; FNumber = tc.Number; PantoneToTPColor(); } else { FInfor = 0; FPage = 0; FNumber = 0; } FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; FRGB.rgbRed = (tc.R << 2 | tc.R >> 4); FRGB.rgbGreen = (tc.G << 2 | tc.G >> 4); FRGB.rgbBlue = (tc.B << 2 | tc.B >> 4); FRGB.rgbReserved = 0; FValue1 = (double)FRGB.rgbRed; FValue2 = (double)FRGB.rgbGreen; FValue3 = (double)FRGB.rgbBlue; FValue4 = (double)UNDEFINED; } //--------------------------------------------------------------------------- void __fastcall TColorData::PassColorsFromFile(HANDLE fh, int v, int pass_count) { WORD n; BYTE Stand; DWORD dwRead; int nKind; for(int i=0 ; i= 2) { int Version = 0; ReadFile(fh, &Version, sizeof(int), &dwRead, NULL); if (Version > 0){ SetFilePointer(fh, sizeof(TColorMode), NULL, FILE_CURRENT); ReadFile(fh, &FInfor, sizeof(WORD), &dwRead, NULL); SetFilePointer(fh, sizeof(WORD)+ sizeof(BYTE)+sizeof(BYTE)+ sizeof(WORD)+sizeof(WORD)+sizeof(WORD)+ sizeof(tagRGBQUAD)+ sizeof(double)+sizeof(double)+sizeof(double)+sizeof(double), NULL, FILE_CURRENT); if ((FInfor & 0x1000) == 0x1000) { ReadFile(fh, &n, sizeof(WORD), &dwRead, NULL); SetFilePointer(fh, n, NULL, FILE_CURRENT); } if ((FInfor & 0x2000) == 0x2000) { ReadFile(fh, &n, sizeof(WORD), &dwRead, NULL); SetFilePointer(fh, n, NULL, FILE_CURRENT); } PassAdditionalColorData(fh); } } PantoneToTPColor(); } } //--------------------------------------------------------------------------- void __fastcall TColorData::LoadAdditionalColorData(HANDLE fh)//, TAdditionalColorData *additionalColorData) { DWORD dwRead; TColorMode color_mode_for_distinguish_additional_color_data; ReadFile(fh, &color_mode_for_distinguish_additional_color_data, sizeof(TColorMode), &dwRead, NULL); EnumChangeColorMode(color_mode_for_distinguish_additional_color_data); if(color_mode_for_distinguish_additional_color_data != TCM_MORE_TAGS_ADDED) { SetFilePointer(fh, sizeof(TColorMode) * -1, NULL, FILE_CURRENT); return; } int number_of_tags; TUCLTagNum tag_number; TUCLTagType tag_type; int count; char* data_buf = new char[100]; int data_buf_size = 0, data_size = 0; ReadFile(fh, &number_of_tags, sizeof(int), &dwRead, NULL); for(int i = 0 ; i < number_of_tags ; ++i) { short tagnum = 0, tagtype = 0; ReadFile(fh, &tagnum, sizeof(short), &dwRead, NULL); tag_number = (byte)tagnum; EnumChangeUCLTagNum(tag_number); ReadFile(fh, &tagtype, sizeof(short), &dwRead, NULL); tag_type = (byte)tagtype; EnumChangeUCLTagType(tag_type); ReadFile(fh, &count, sizeof(int), &dwRead, NULL); data_size = additionalColorData->HowManyBytesOccupy(tag_type) * count; if(data_size > data_buf_size) { delete[] data_buf; data_buf = new char[data_size]; data_buf_size = data_size; } ReadFile(fh, data_buf, data_size, &dwRead, NULL); additionalColorData->AddTag(tag_number, tag_type, count, data_buf); } delete[] data_buf; } //--------------------------------------------------------------------------- void __fastcall TColorData::SaveAdditionalColorData(HANDLE fh)//, TAdditionalColorData *additionalColorData) { int number_of_tags = additionalColorData->TagList.size(); if(number_of_tags == 0) return; DWORD dwRead; TColorMode color_mode_for_distinguish_additional_color_data = TCM_MORE_TAGS_ADDED; WriteFile(fh, &color_mode_for_distinguish_additional_color_data, sizeof(TColorMode), &dwRead, NULL); WriteFile(fh, &number_of_tags, sizeof(int), &dwRead, NULL); for(std::list::iterator iter = additionalColorData->TagList.begin() ; iter != additionalColorData->TagList.end() ; ++iter) { TAdditionalColorDataTag* tag = (*iter); WriteFile(fh, &(tag->TagNumber), sizeof(short), &dwRead, NULL); WriteFile(fh, &(tag->TagType), sizeof(short), &dwRead, NULL); WriteFile(fh, &(tag->Count), sizeof(int), &dwRead, NULL); WriteFile(fh, tag->Data, additionalColorData->HowManyBytesOccupy(tag->TagType) * tag->Count, &dwRead, NULL); } } //--------------------------------------------------------------------------- void __fastcall TColorData::PassAdditionalColorData(HANDLE fh) { DWORD dwRead; TColorMode color_mode_for_distinguish_additional_color_data; ReadFile(fh, &color_mode_for_distinguish_additional_color_data, sizeof(TColorMode), &dwRead, NULL); EnumChangeColorMode(color_mode_for_distinguish_additional_color_data); if(color_mode_for_distinguish_additional_color_data != TCM_MORE_TAGS_ADDED) { SetFilePointer(fh, sizeof(TColorMode) * -1, NULL, FILE_CURRENT); return; } int number_of_tags; TUCLTagNum tag_number; TUCLTagType tag_type; int count; TAdditionalColorData additional_color_data; ReadFile(fh, &number_of_tags, sizeof(int), &dwRead, NULL); for(int i = 0 ; i < number_of_tags ; ++i) { short tagnum = 0, tagtype = 0; ReadFile(fh, &tagnum, sizeof(short), &dwRead, NULL); tag_number = (byte)tagnum; EnumChangeUCLTagNum(tag_number); ReadFile(fh, &tagtype, sizeof(short), &dwRead, NULL); tag_type = (byte)tagtype; EnumChangeUCLTagType(tag_type); ReadFile(fh, &count, sizeof(int), &dwRead, NULL); SetFilePointer(fh, additional_color_data.HowManyBytesOccupy(tag_type) * count, NULL, FILE_CURRENT); } } //--------------------------------------------------------------------------- void __fastcall TColorData::SetUserColor(void *data) { TColorData *ColorData = NULL; ColorData = (TColorData *)data; Copy(ColorData); ColorData->SetKind((0x4000 | ColorData->Infor)); } //--------------------------------------------------------------------------- ///PANTONE Color Ãß°¡·Î »ý±â°Ô µÊ. ¼Ó¼º¹øÈ£´Â 6 ¹øÀ» ºÎ¿©ÇÔ by smallpotato(2008.03.07) void __fastcall TColorData::SetPantoneColor2(void * data)//, Char * ptColor, Char * ptFileName) { TColorData *ColorData = NULL; ColorData = (TColorData *)data; Copy(ColorData); ColorData->SetKind((0x0006 | ColorData->Infor)); // if (ptColor != NULL){ // PantoneColor = new Char[_tcslen(ptColor) + 1]; // StrCopy(PantoneColor, ptColor); // } // if (ptFileName != NULL){ // PantoneFileName = new Char[_tcslen(ptFileName) + 1]; // StrCopy(PantoneFileName, ptFileName); // } } //--------------------------------------------------------------------------- WORD __fastcall TColorData::GetInfor() { return FInfor; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetInfor(WORD Inf) { // Infor¸¦ Àӽ÷Π¼öÁ¤ (ÀúÀåÇϵµ·Ï) if (Inf >= 0x10) { // UserColor (ColorName, FileName) if (Inf >= 0x80) FInfor = ((Inf & 0x0F) | 0x4000) | 0x8000; else FInfor = ((Inf & 0x0F) | 0x4000); } else FInfor = Inf; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetRGB(tagRGBQUAD rgb) // RGB¸¦ ÃʱâÈ­ÇÒ¶§¸¸ »ç¿ëÇÑ´Ù { FRGB = rgb; } //--------------------------------------------------------------------------- void __fastcall TColorData::SetRGBColor(tagRGBQUAD rgb) // RGB »öÀ» º¯°æÇÒ ¶§ »ç¿ëÇÑ´Ù { FRGB = rgb; // Value Ä÷¯ »ö º¯È¯ switch (ColorMode) { case TCM_RGB: FValue1 = (double)FRGB.rgbRed; FValue2 = (double)FRGB.rgbGreen; FValue3 = (double)FRGB.rgbBlue; FValue4 = (double)FRGB.rgbReserved; break; case TCM_CMY: FValue1 = 255 - FRGB.rgbRed; FValue2 = 255 - FRGB.rgbGreen; FValue3 = 255 - FRGB.rgbBlue; FValue4 = 255 - FRGB.rgbReserved; break; case TCM_HLS: RGB2HLS(FRGB.rgbRed, FRGB.rgbGreen, FRGB.rgbBlue, FValue1, FValue2, FValue3); FValue4 = UNDEFINED; break; // case TCM_LAB: // LABColor output = RGBtoLAB(FRGB.rgbRed, FRGB.rgbGreen, FRGB.rgbBlue); // FValue1 = (double)output.L; FValue2 = (double)output.A; FValue3 = (double)output.B; // break; } // »ö»óÀÌ Á¶±ÝÀÌ¶óµµ º¯°æµÇ¸é ´Ù¸¥ Ä÷¯°¡ µÇ¾î¹ö¸®¹Ç·Î FPage µîÀ» ÃʱâÈ­ÇØÁØ´Ù - by monkman (2006.09.29) SetKind(0); FPage = 0; FNumber = 0; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; DeleteUserColor(); additionalColorData->Reset(); } //--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void __fastcall TColorData::SetValue1(double dVal1) { FValue1 = dVal1; switch (ColorMode) { case TCM_RGB: FRGB.rgbRed = (BYTE)FValue1; break; case TCM_CMY: FRGB.rgbRed = (BYTE)255 - FValue1; // CMY -> RGB break; case TCM_HLS: HLS2RGB(FValue1, FValue2, FValue3, FRGB.rgbRed, FRGB.rgbGreen, FRGB.rgbBlue); break; // case TCM_LAB: // RGBColor RGBresult = LABtoRGB(FValue1, FValue2, FValue3); // FRGB.rgbRed = (double)RGBresult.R; FRGB.rgbGreen = (double)RGBresult.G; FRGB.rgbBlue = (double)RGBresult.B; // break; } // »ö»óÀÌ Á¶±ÝÀÌ¶óµµ º¯°æµÇ¸é ´Ù¸¥ Ä÷¯°¡ µÇ¾î¹ö¸®¹Ç·Î FPage µîÀ» ÃʱâÈ­ÇØÁØ´Ù - by monkman (2006.09.29) SetKind(0); FPage = 0; FNumber = 0; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; DeleteUserColor(); additionalColorData->Reset(); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetValue2(double dVal2) { FValue2 = dVal2; switch (ColorMode) { case TCM_RGB: FRGB.rgbGreen = (BYTE)FValue2; break; case TCM_CMY: FRGB.rgbGreen = (BYTE)255 - FValue2; // CMY -> RGB break; case TCM_HLS: HLS2RGB(FValue1, FValue2, FValue3, FRGB.rgbRed, FRGB.rgbGreen, FRGB.rgbBlue); break; // case TCM_LAB: // RGBColor RGBresult = LABtoRGB(FValue1, FValue2, FValue3); // FRGB.rgbRed = (double)RGBresult.R; FRGB.rgbGreen = (double)RGBresult.G; FRGB.rgbBlue = (double)RGBresult.B; // break; } // »ö»óÀÌ Á¶±ÝÀÌ¶óµµ º¯°æµÇ¸é ´Ù¸¥ Ä÷¯°¡ µÇ¾î¹ö¸®¹Ç·Î FPage µîÀ» ÃʱâÈ­ÇØÁØ´Ù - by monkman (2006.09.29) SetKind(0); FPage = 0; FNumber = 0; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; DeleteUserColor(); additionalColorData->Reset(); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetValue3(double dVal3) { FValue3 = dVal3; switch (ColorMode) { case TCM_RGB: FRGB.rgbBlue = (BYTE)FValue3; break; case TCM_CMY: FRGB.rgbBlue = (BYTE)255 - FValue3; // CMY -> RGB break; case TCM_HLS: HLS2RGB(FValue1, FValue2, FValue3, FRGB.rgbRed, FRGB.rgbGreen, FRGB.rgbBlue); break; // case TCM_LAB: // RGBColor RGBresult = LABtoRGB(FValue1, FValue2, FValue3); // FRGB.rgbRed = (double)RGBresult.R; FRGB.rgbGreen = (double)RGBresult.G; FRGB.rgbBlue = (double)RGBresult.B; // break; } // »ö»óÀÌ Á¶±ÝÀÌ¶óµµ º¯°æµÇ¸é ´Ù¸¥ Ä÷¯°¡ µÇ¾î¹ö¸®¹Ç·Î FPage µîÀ» ÃʱâÈ­ÇØÁØ´Ù - by monkman (2006.09.29) SetKind(0); FPage = 0; FNumber = 0; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; DeleteUserColor(); additionalColorData->Reset(); } //--------------------------------------------------------------------------- void __fastcall TColorData::SetValue4(double dVal4) { HANDLE hClrHandle; BYTE cInput[3], cOutput[3]; double C, M, Y, K; FValue4 = dVal4; switch (ColorMode) { case TCM_RGB: break; case TCM_CMY: break; case TCM_HLS: break; case TCM_LAB: break; } // »ö»óÀÌ Á¶±ÝÀÌ¶óµµ º¯°æµÇ¸é ´Ù¸¥ Ä÷¯°¡ µÇ¾î¹ö¸®¹Ç·Î FPage µîÀ» ÃʱâÈ­ÇØÁØ´Ù - by monkman (2006.09.29) SetKind(0); FPage = 0; FNumber = 0; FReserved = 0; FCode = 0; FExtend = 0; FBase = 0; DeleteUserColor(); additionalColorData->Reset(); } //--------------------------------------------------------------------------- //int __fastcall TColorData::GetClipboardSize() //{ // int calSize = 0; // calSize = sizeof(Word) // Infor // + sizeof(Word) // Page // + sizeof(Byte) // Number // + sizeof(RGBQUAD) // RGB // + sizeof(int)*4; // size of name // // if (FileName != NULL) // calSize = calSize + StrLen(FileName) + 1; // // if (ColorName != NULL) // calSize = calSize + StrLen(ColorName) + 1; // //// if (PantoneColor != NULL) //// calSize = calSize + StrLen(PantoneColor) + 1; //// //// if (PantoneFileName != NULL) //// calSize = calSize + StrLen(PantoneFileName) + 1; // // // return calSize; //} //--------------------------------------------------------------------------- int __fastcall TColorData::GetClipboardSize() { int size = 0; int typeSize = 0; // savedata count size += sizeof(int); // Ŭ¸³º¸µå¿¡ Ãß°¡ÇÒ µ¥ÀÌÅÍ °¢°¢À» ³Ö°Å³ª »«´Ù // µ¥ÀÌÅÍ Å¸ÀÔ, ŸÀÔÀÇ »çÀÌÁî, ŸÀÔµ¥ÀÌÅ͸¦ ÀúÀåÇÒ Å©±â¸¦ Ãß°¡ÇÑ´Ù // FColorMode typeSize = sizeof(TColorMode); size += sizeof(TColorDataType); // ű׻çÀÌÁî Ãß°¡ size += sizeof(int); // µ¥ÀÌÅÍŸÀÔ »çÀÌÁî°¡ ¾ó¸¶ÀÎÁö ÀúÀåÇÒ int Ãß°¡ size += typeSize; // µ¥ÀÌÅÍ Å¸ÀÔ»çÀÌÁŭ Ãß°¡ // FInfor typeSize = sizeof(WORD); size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; // FPage typeSize = sizeof(WORD); size += sizeof(TColorDataType); size += sizeof(int); size +=typeSize; // FNumber typeSize = sizeof(BYTE); size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; // FCode typeSize = sizeof(WORD); size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; // FExtend typeSize = sizeof(WORD); size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; // FBase typeSize = sizeof(WORD); size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; // FRGB typeSize = sizeof(RGBQUAD); size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; if (FileName){ typeSize = sizeof(Char)*(StrLen(FileName) + 1); // FileName size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; } if (ColorName){ typeSize = sizeof(Char)*(StrLen(ColorName) + 1); // ColorName size += sizeof(TColorDataType); size += sizeof(int); size += typeSize; } if (additionalColorData && additionalColorData->TagList.size() > 0){ // additionalColorData size += sizeof(TColorDataType); int acdSize = additionalColorData->GetDataSize(); size += sizeof(int); size += acdSize; } return size; } //--------------------------------------------------------------------------- void __fastcall TColorData::SaveClipboard(Byte *lpData) { TColorDataType cdt = NULL; int typeSize = 0; int saveDataCount = 8; // FColorMode, FInfor, FPage, FNumber, FCode, FExtend, FBase, FRGB if (FileName) saveDataCount++; if (ColorName) saveDataCount++; if (additionalColorData && additionalColorData->TagList.size() > 0) saveDataCount++; memcpy(lpData, &saveDataCount, sizeof(int)); // savedata count lpData += sizeof(int); // Ŭ¸³º¸µå¿¡ Ãß°¡ÇÒ µ¥ÀÌÅÍÀÇ ¼ö cdt = TYPE_COLORMODE; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FColorMode lpData += sizeof(TColorDataType); // 1. ű׸¦ ÀúÀåÇϰí typeSize = sizeof(TColorMode); memcpy(lpData, &typeSize, sizeof(int)); // 2. µ¥ÀÌÅÍÀÇ Å©±â¸¦ ÀúÀåÇϰí lpData += sizeof(int); memcpy(lpData, &FColorMode, typeSize); // 3. ±× Å©±â¸¸Å­ µ¥ÀÌÅ͸¦ ÀúÀåÇÑ´Ù lpData += typeSize; cdt = TYPE_INFOR; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FInfor lpData += sizeof(TColorDataType); typeSize = sizeof(WORD); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FInfor, typeSize); lpData += typeSize; cdt = TYPE_PAGE; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FPage lpData += sizeof(TColorDataType); typeSize = sizeof(WORD); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FPage, typeSize); lpData +=typeSize; cdt = TYPE_NUMBER; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FNumber lpData += sizeof(TColorDataType); typeSize = sizeof(BYTE); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FNumber, typeSize); lpData += typeSize; cdt = TYPE_CODE; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FCode lpData += sizeof(TColorDataType); typeSize = sizeof(WORD); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FCode, typeSize); lpData += typeSize; cdt = TYPE_EXTEND; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FExtend lpData += sizeof(TColorDataType); typeSize = sizeof(WORD); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FExtend, typeSize); lpData += typeSize; cdt = TYPE_BASE; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FBase lpData += sizeof(TColorDataType); typeSize = sizeof(WORD); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FBase, typeSize); lpData += typeSize; cdt = TYPE_RGB; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FRGB lpData += sizeof(TColorDataType); typeSize = sizeof(RGBQUAD); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, &FRGB, typeSize); lpData += typeSize; if (FileName){ typeSize = sizeof(Char)*(StrLen(FileName) + 1); cdt = TYPE_FILENAME; memcpy(lpData, &cdt, sizeof(TColorDataType)); // FileName lpData += sizeof(TColorDataType); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, FileName, typeSize); lpData += typeSize; } if (ColorName){ typeSize = sizeof(Char)*(StrLen(ColorName) + 1); cdt = TYPE_COLORNAME; memcpy(lpData, &cdt, sizeof(TColorDataType)); // ColorName lpData += sizeof(TColorDataType); memcpy(lpData, &typeSize, sizeof(int)); lpData += sizeof(int); memcpy(lpData, ColorName, typeSize); lpData += typeSize; } if (additionalColorData && additionalColorData->TagList.size() > 0){ cdt = TYPE_ADDITIONALCOLORDATA; memcpy(lpData, &cdt, sizeof(TColorDataType)); // additionalColorData lpData += sizeof(TColorDataType); int acdSize = additionalColorData->GetDataSize(); memcpy(lpData, &cdt, sizeof(TColorDataType)); memcpy(lpData, &acdSize, sizeof(int)); lpData += sizeof(int); additionalColorData->SaveClipBoard(lpData); lpData += acdSize; } } //--------------------------------------------------------------------------- int __fastcall TColorData::GetClipboard(Byte *lpData) { int DataCount = 0; int Size = 0; memcpy(&DataCount, lpData, sizeof(int)); // size lpData += sizeof(int); Size += sizeof(int); while (DataCount > 0){ TColorDataType cdt; memcpy(&cdt, lpData, sizeof(TColorDataType)); lpData += sizeof(TColorDataType); int typeSize = 0; memcpy(&typeSize, lpData, sizeof(int)); lpData += sizeof(int); GetTagData(cdt, lpData, typeSize); lpData += typeSize; Size += (sizeof(TColorDataType) + sizeof(int) + typeSize); DataCount--; } return Size; } //--------------------------------------------------------------------------- void __fastcall TColorData::GetTagData(TColorDataType tag, Byte *lpData, int len) { switch(tag){ case TYPE_COLORMODE : memcpy(&FColorMode, lpData, len); lpData += len; break; case TYPE_INFOR : memcpy(&FInfor, lpData, len); lpData += len; break; case TYPE_PAGE : memcpy(&FPage, lpData, len); lpData += len; break; case TYPE_NUMBER : memcpy(&FNumber, lpData, len); lpData += len; break; case TYPE_CODE : memcpy(&FCode, lpData, len); lpData += len; break; case TYPE_EXTEND : memcpy(&FExtend, lpData, len); lpData += len; break; case TYPE_BASE : memcpy(&FBase, lpData, len); lpData += len; break; case TYPE_RGB : memcpy(&FRGB, lpData, len); lpData += len; break; case TYPE_FILENAME : //len = 0; //memcpy(&len, lpData, sizeof(int)); //lpData += sizeof(int); FileName = new Char[len]; memcpy(FileName, lpData, len); lpData += sizeof(Char)*len; break; case TYPE_COLORNAME : //len = 0; //memcpy(&len, lpData, sizeof(int)); //lpData += sizeof(int); ColorName = new Char[len]; memcpy(ColorName, lpData, len); lpData += sizeof(Char)*len; break; case TYPE_ADDITIONALCOLORDATA : int acdSize = additionalColorData->GetClipboard(lpData); lpData += acdSize; break; } } //--------------------------------------------------------------------------- // Search Color //--------------------------------------------------------------------------- __fastcall TSearchColor::TSearchColor(BYTE r, BYTE g, BYTE b) { sc[0] = 256*3; sc[1] = 256; rgb[0] = r; rgb[1] = g; rgb[2] = b; } //--------------------------------------------------------------------------- int __fastcall TSearchColor::Search(BYTE r, BYTE g, BYTE b) { int nReturn = 0; WORD t[4]; t[0] = abs(r-rgb[0]); t[1] = abs(g-rgb[1]); t[2] = abs(b-rgb[2]); t[3] = t[0]+t[1]+t[2]; if (t[3] == 0) { nReturn = 2; } else if (t[3] == sc[0]) { if ((sc[1] > t[0]) && (sc[1] > t[1]) && (sc[1] > t[2])) { sc[1] = t[0]; if (sc[1] < t[1]) sc[1] = t[1]; if (sc[1] < t[2]) sc[1] = t[2]; nReturn = 1; } } else if (t[3] < sc[0]) { sc[0] = t[3]; sc[1] = t[0]; if (sc[1] < t[1]) sc[1] = t[1]; if (sc[1] < t[2]) sc[1] = t[2]; nReturn = 1; } return nReturn; } //--------------------------------------------------------------------------- // External Common Function // Color Map int StandardPage[148] = { 11, 12, 13, 20, 30, 40, 50, 55, 60, 70, 75, 80, 90, 95, 100, 105, 110, 115, 120, 130, 135, 137, 140, 150, 155, 160, 170, 180, 190, 200, 210, 220, 225, 230, 240, 250, 252, 253, 257, 260, 265, 270, 275, 276, 277, 278, 280, 290, 300, 305, 310, 315, 320, 330, 335, 340, 350, 352, 355, 358, 360, 370, 375, 380, 390, 400, 410, 420, 430, 440, 450, 455, 460, 470, 480, 490, 500, 510, 520, 521, 522, 523, 524, 530, 535, 540, 550, 555, 560, 565, 570, 580, 590, 600, 605, 610, 620, 625, 630, 635, 640, 645, 650, 660, 665, 670, 673, 677, 680, 685, 690, 695, 700, 710, 713, 717, 720, 725, 730, 740, 750, 760, 770, 780, 790, 800, 810, 820, 830, 840, 850, 860, 870, 880, 890, 900, 910, 920, 930, 940, 950, 960, 970, 980, 990, 1000, 1010, 1020 }; //--------------------------------------------------------------------------- void __fastcall HLS2RGB(double h, double l, double s, BYTE &r, BYTE &g, BYTE &b) { double m1, m2; if (l <= 0.5) m2 = l*(1+s); else m2 = l+s-l*s; m1 = 2*l-m2; if (s == 0) { r = floor(l*255); g = floor(l*255); b = floor(l*255); } else { r = floor(HLS2RGBSub(m1, m2, h + 120)*255); g = floor(HLS2RGBSub(m1, m2, h)*255); b = floor(HLS2RGBSub(m1, m2, h - 120)*255); } } //--------------------------------------------------------------------------- double __fastcall HLS2RGBSub(double n1, double n2, double hue) { if (hue > 360) { hue = hue-360; } else if (hue < 0) { hue = hue+360; } if (hue < 60) { return (n1+(n2-n1)*hue/60.0); } else if (hue < 180) { return n2; } else if (hue < 240) { return (n1+(n2-n1)*(240-hue)/60.0); } else { return n1; } } //--------------------------------------------------------------------------- void __fastcall RGB2HLS(BYTE r, BYTE g, BYTE b, double &h, double &l, double &s) { double rgb[3]; double max, min, delta; rgb[0] = r/255.0; rgb[1] = g/255.0; rgb[2] = b/255.0; max = RGB2HLSMax(rgb[0], rgb[1], rgb[2]); min = RGB2HLSMin(rgb[0], rgb[1], rgb[2]); l = (max+min)/2.0; if (max == min) { s = 0; h = UNDEFINED; } else { if (l <= 0.5) { s = (max-min)/(double)(max+min); } else { s = (max-min)/(double)(2-max-min); } delta = (max-min); if (rgb[0] == max) { h = (rgb[1]-rgb[2])/(double)delta; } else if (rgb[1] == max) { h = 2+(rgb[2]-rgb[0])/(double)delta; } else if (rgb[2] == max) { h = 4+(rgb[0]-rgb[1])/(double)delta; } h = h*60; if (h < 0.0) h = h+360; } } //--------------------------------------------------------------------------- double __fastcall RGB2HLSMin(double x, double y, double z) { if (x < y) { if (x < z) return x; else return z; } else { if (y < z) return y; else return z; } } //--------------------------------------------------------------------------- double __fastcall RGB2HLSMax(double x, double y, double z) { if (x > y) { if (x > z) return x; else return z; } else { if (y > z) return y; else return z; } } //--------------------------------------------------------------------------- Graphics::TColor __fastcall RGB2TColor(BYTE r, BYTE g, BYTE b) { return (Graphics::TColor)(r | (g << 8) | (b << 16)); } //--------------------------------------------------------------------------- void __fastcall TColor2RGB(Graphics::TColor Value, BYTE &r, BYTE &g, BYTE &b) { r = Value & 0xFF; g = ((Value >> 8) & 0xFF); b = ((Value >> 16) & 0xFF); } //--------------------------------------------------------------------------- Graphics::TColor __fastcall HLS2TColor(double h, double l, double s) { BYTE r, g, b; HLS2RGB(h, l, s, r, g, b); return RGB2TColor(r, g, b); } //--------------------------------------------------------------------------- void __fastcall TColor2HLS(Graphics::TColor Value, double &h, double &l, double &s) { BYTE r, g, b; TColor2RGB(Value, r, g, b); RGB2HLS(r, g, b, h, l, s); } //--------------------------------------------------------------------------- tagRGBQUAD __fastcall HLS2RGBQUAD(double h, double l, double s) { tagRGBQUAD rgbquadReturn; BYTE r, g, b; HLS2RGB(h, l, s, r, g, b); rgbquadReturn.rgbRed = r; rgbquadReturn.rgbGreen = g; rgbquadReturn.rgbBlue = b; rgbquadReturn.rgbReserved = 0; return rgbquadReturn; } //--------------------------------------------------------------------------- void __fastcall RGBQUAD2HLS(tagRGBQUAD Value, double &h, double &l, double &s) { BYTE r, g, b; r = Value.rgbRed; g = Value.rgbGreen; b = Value.rgbBlue; RGB2HLS(r, g, b, h, l, s); } //--------------------------------------------------------------------------- tagRGBQUAD __fastcall TColorToRGB(Graphics::TColor Value) { tagRGBQUAD rgbquadReturn; rgbquadReturn.rgbRed = Value & 0xFF; Value = Value >> 8; rgbquadReturn.rgbGreen = Value & 0xFF; Value = Value >> 8; rgbquadReturn.rgbBlue = Value & 0xFF; return rgbquadReturn; } //--------------------------------------------------------------------------- Graphics::TColor __fastcall RGBToTColor(tagRGBQUAD Value) { return (Graphics::TColor)((Value.rgbBlue << 16) | (Value.rgbGreen << 8) | Value.rgbRed); } //--------------------------------------------------------------------------- tagRGBQUAD __fastcall Color24ToRGB(unsigned Value) { tagRGBQUAD rgbquadReturn; rgbquadReturn.rgbRed = Value & 0xFF; Value = Value >> 8; rgbquadReturn.rgbGreen = Value & 0xFF; Value = Value >> 8; rgbquadReturn.rgbBlue = Value & 0xFF; //rgbquadReturn.rgbBlue = Value & 0xFF; //Value = Value >> 8; //rgbquadReturn.rgbGreen = Value & 0xFF; //Value = Value >> 8; //rgbquadReturn.rgbRed = Value & 0xFF; return rgbquadReturn; } //--------------------------------------------------------------------------- unsigned __fastcall RGBToColor24(tagRGBQUAD Value) { return (unsigned)((Value.rgbBlue << 16) | (Value.rgbGreen << 8) | Value.rgbRed); //return (unsigned)((Value.rgbRed << 16) | (Value.rgbGreen << 8) | Value.rgbBlue); } //--------------------------------------------------------------------------- tagRGBQUAD __fastcall Color15ToRGB(WORD Value) { tagRGBQUAD rgbquadReturn; rgbquadReturn.rgbBlue = (((Value & 0x1F) << 3) | ((Value & 0x1F) >> 2)); Value = Value >> 5; rgbquadReturn.rgbGreen = (((Value & 0x1F) << 3) | ((Value & 0x1F) >> 2)); Value = Value >> 5; rgbquadReturn.rgbRed = (((Value & 0x1F) << 3) | (Value >> 2)); return rgbquadReturn; } //--------------------------------------------------------------------------- WORD __fastcall RGBToColor15(tagRGBQUAD Value) { return (WORD)(((Value.rgbRed & 0xF8) << 7) | ((Value.rgbGreen & 0xF8) << 2) | (Value.rgbBlue >> 3)); } //--------------------------------------------------------------------------- Graphics::TColor __fastcall TColorToBW(Graphics::TColor c) { BYTE r, g, b; r = c & 0xFF; g = ((c >> 8) & 0xFF); b = ((c >> 16) & 0xFF); if (r + g + b <384) { return (Graphics::TColor)(0xFFFFFF); } else { return (Graphics::TColor)(0); } } //---------------------------------------------------------------------------