//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "File.h" #include "lzw.hpp" #include "StatusProgress.h" #include "Define.h" //#include "MainImage.h" //#include "Palette.h" //--------------------------------------------------------------------------- #pragma package(smart_init) //--------------------------------------------------------------------------- // TODO : Weave File ¹öÀü ¿Ã¸®¸é ¿©±â ¼öÁ¤ÇÒ °Í!! int WeaveFileCheckVersion = 270; // »óÀ§ ¹öÀü üũ¿¡¼­ »ç¿ëÇÒ ¹öÀü : TexKnit¿¡¼­ ÀúÀåÇÏ´Â Knit 270 version file ±îÁö ÀÐÀ» ¼ö ÀÖµµ·Ï ÇÔ int KnitFileCheckVersion = 280; // TFileInfor //--------------------------------------------------------------------------- __fastcall TFileInfor::TFileInfor() { Bitmap = NULL; tBitmap = NULL; } //--------------------------------------------------------------------------- __fastcall TFileInfor::~TFileInfor() { if (tBitmap) delete tBitmap; if (Bitmap) delete Bitmap; } //--------------------------------------------------------------------------- // TDirectoryInfor //--------------------------------------------------------------------------- __fastcall TDirectoryInfor::TDirectoryInfor() { pDirectoryList = NULL; pFileList = NULL; } //--------------------------------------------------------------------------- __fastcall TDirectoryInfor::~TDirectoryInfor() { Clear(); } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void __fastcall TDirectoryInfor::FileListDestroy(TList *&pList) { TFileInfor *fi; if (pList) { while (pList->Count>0) { fi = (TFileInfor *)pList->First(); pList->Remove(fi); delete fi; } delete pList; pList = NULL; } } //--------------------------------------------------------------------------- void __fastcall TDirectoryInfor::DirectoryListDestroy(TList *&pList) { TDirectoryInfor *sdi; if (pList) { while (pList->Count>0) { sdi = (TDirectoryInfor *)pList->First(); pList->Remove(sdi); ListDestroy(sdi); delete sdi; } delete pList; pList = NULL; } } //--------------------------------------------------------------------------- void __fastcall TDirectoryInfor::ListDestroy(TDirectoryInfor *sdi) { FileListDestroy(sdi->pFileList); DirectoryListDestroy(sdi->pDirectoryList); } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TDirectoryInfor::Clear() { FileListDestroy(pFileList); DirectoryListDestroy(pDirectoryList); } //--------------------------------------------------------------------------- // TSearchFile //--------------------------------------------------------------------------- __fastcall TSearchFile::TSearchFile() : TObject() { FFileName = String("*.*"); #ifdef TRIAL FTrialFileName = String("*.*"); #endif FMake = false; FSubDirectory = false; FileNameList = new TStringList(); //090804 by david } //--------------------------------------------------------------------------- __fastcall TSearchFile::~TSearchFile() { if (FileNameList) delete FileNameList; //090804 by david FileNameList = NULL; } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- void __fastcall TSearchFile::Add(TObject *Sender, int depth, TDirectoryInfor *di) { int rtn, rIndex = -1; //TSearchRec sr; TSearchRec sr; TDirectoryInfor *sdi = NULL; TFileInfor *fi = NULL; String ext; //rtn = FindFirst("*.*", faReadOnly | faArchive, sr); rtn = FindFirst(String("*.*"), faReadOnly | faArchive, sr); while (rtn==0) { //if(ExtractFileExt(sr.Name) == ExtractFileExt(FFileName) //if(ExtractFileExt(sr.Name) == ExtractFileExt(FFileName) ext = ExtractFileExt(sr.Name); rIndex = FileNameList->IndexOf(ext); if(ext == ExtractFileExt(FFileName) #ifdef TRIAL //Trial Version¿ë file format ó¸® //|| ExtractFileExt(sr.Name) == ExtractFileExt(FTrialFileName) //|| ExtractFileExt(sr.Name) == ExtractFileExt(FTrialFileName) || ext == ExtractFileExt(FTrialFileName) #endif || rIndex > -1 //090804 by david ){ if (FMake) { fi = new TFileInfor; if (fi) { fi->Name = sr.Name; if (di->Path.Length()>0) { fi->Path = di->Path + String("\\") + di->Name; } else { fi->Path = di->Name; } fi->Depth = depth; if (di->pFileList==NULL) di->pFileList = new TList; if (di->pFileList) { di->pFileList->Add(fi); if (FOnFile) FOnFile(Sender, &sr, depth, fi); } else { delete fi; } } } else { if (FOnFile) FOnFile(Sender, &sr, depth, NULL); } } //rtn = FindNext(sr); rtn = FindNext(sr); } //FindClose(sr);// by jeegeo // ²À²À²À ¿©±â¼­ ´Ý¾ÆÁÖ¶ó-_-; ¾È±×·¯¸é À©2000À̻󿡼­ µð·ºÅ丮³ª È­ÀÏÀÇ »èÁ¦°¡ ¾ÈµÊ FindClose(sr);// by jeegeo // ²À²À²À ¿©±â¼­ ´Ý¾ÆÁÖ¶ó-_-; ¾È±×·¯¸é À©2000À̻󿡼­ µð·ºÅ丮³ª È­ÀÏÀÇ »èÁ¦°¡ ¾ÈµÊ if (FSubDirectory) { //rtn = FindFirst("*.*", faReadOnly | faArchive | faDirectory, sr); rtn = FindFirst(String("*.*"), faReadOnly | faArchive | faDirectory, sr); while (rtn==0) { if ((sr.Attr&faDirectory) && *sr.Name.c_str()!= L'.') { if (FMake) { sdi = new TDirectoryInfor; if (sdi) { sdi->Name = sr.Name; if (di->Path.Length()>0) { sdi->Path = di->Path + String("\\") + di->Name; } else { sdi->Path = di->Name; } sdi->Depth = depth; if (di->pDirectoryList==NULL) di->pDirectoryList = new TList; if (di->pDirectoryList) { di->pDirectoryList->Add(sdi); if (FOnDirectory) FOnDirectory(Sender, &sr, depth, sdi); } else { delete sdi; } } } else { if (FOnDirectory) FOnDirectory(Sender, &sr, depth, NULL); } //chdir(sr.Name.c_str()); _wchdir(sr.Name.c_str()); Add(Sender, depth+1, sdi); //chdir(".."); _wchdir(L".."); } //rtn = FindNext(sr); rtn = FindNext(sr); } } //FindClose(sr); FindClose(sr); if(sdi)sdi = NULL; if(fi)fi = NULL; } //--------------------------------------------------------------------------- //TDirectoryInfor *__fastcall TSearchFile::SearchDirectory(String dn, TDirectoryInfor *di) TDirectoryInfor *__fastcall TSearchFile::SearchDirectory(String dn, TDirectoryInfor *di) { TDirectoryInfor *sdi; if (di->Name!=dn) { if (di->pDirectoryList) { for (int i=0; ipDirectoryList->Count; i++) { sdi = SearchDirectory(dn, (TDirectoryInfor *)di->pDirectoryList->Items[i]); if (sdi) return sdi; } } return NULL; } else { return di; } } //--------------------------------------------------------------------------- //TFileInfor *__fastcall TSearchFile::SearchFile(String fn, TDirectoryInfor *di) TFileInfor *__fastcall TSearchFile::SearchFile(String fn, TDirectoryInfor *di) { int i; TFileInfor *sfi; for (i=0; ipFileList->Count; i++) { sfi = (TFileInfor *)di->pFileList->Items[i]; if (fn==sfi->Name) return sfi; } if (di->pDirectoryList) { for (i=0; ipDirectoryList->Count; i++) { sfi = SearchFile(fn, (TDirectoryInfor *)di->pDirectoryList->Items[i]); if (sfi) return sfi; } } return NULL; } //--------------------------------------------------------------------------- //void __fastcall TSearchFile::SetFileName(String fn) void __fastcall TSearchFile::SetFileName(String fn) { if (fn!=FFileName) FFileName = fn; } //--------------------------------------------------------------------------- //void __fastcall TSearchFile::SetInitDirectory(String id) void __fastcall TSearchFile::SetInitDirectory(String id) { if (id!=FInitDirectory) FInitDirectory = id; } //--------------------------------------------------------------------------- void __fastcall TSearchFile::SetMake(bool b) { if (b!=FMake) FMake = b; } //--------------------------------------------------------------------------- void __fastcall TSearchFile::SetSubDirectory(bool b) { if (b!=FSubDirectory) FSubDirectory = b; } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TSearchFile::Create(TObject *Sender) { FData.Clear(); //chdir(FInitDirectory.c_str()); _wchdir(FInitDirectory.c_str()); Add(Sender, 0, &FData); } //--------------------------------------------------------------------------- TDirectoryInfor *__fastcall TSearchFile::RootDirectory() { return &FData; } //--------------------------------------------------------------------------- //TDirectoryInfor *__fastcall TSearchFile::SearchDirectory(String dn) TDirectoryInfor *__fastcall TSearchFile::SearchDirectory(String dn) { return SearchDirectory(dn, &FData); } //--------------------------------------------------------------------------- //TFileInfor *__fastcall TSearchFile::SearchFile(String fn) TFileInfor *__fastcall TSearchFile::SearchFile(String fn) { return SearchFile(fn, &FData); } //--------------------------------------------------------------------------- // Extern Function //--------------------------------------------------------------------------- //String __fastcall FullPathName(String dn, String fn) String __fastcall FullPathName(String dn, String fn) { //char *str = dn.c_str(); Char *str = dn.c_str(); if (str[dn.Length()-1] == L'\\') return dn + fn; return dn + String("\\") + fn; } //--------------------------------------------------------------------------- //Trial Verion ¿ë file format(ttex, ttfc, ...)À» ºÒ·¯¿À´Â ºÎºÐ Ãß°¡ TPException __fastcall LoadFromTexpiaTag(HANDLE fh, TFileInfor *fi, TGraphicFileFormat gff, TTexVersion *ver, bool bTrialVersion) { TEXPIAFILEHEADER tpfh; int y, j, r, g, b; TPException ec = EC_NONE; TTexVersion Tex; RGBQUAD rgb[256]; Byte buf[320]; TPalette *palette = NULL; WORD BitCount; DWORD dwRead; int versionNum; WORD useColor; WORD checkVersion; //int nVer = tpfh.Version.Number; //0804089 if ((palette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } #ifdef TRIAL //TrialVersion ó¸® if(bTrialVersion == true) //trial ¿ë file formatÀº ±âÁ¸ file formatÀÇ header°¡ µÚÁý¾îÁ® ÀÖ´Â ÇüÅÂÀ̹ǷΠµÚÁý¾î¼­ loadÇÔ. { TEXPIAFILEHEADER_TRIAL temp; if (!ReadFile(fh, &temp, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } tpfh.Version = temp.Version; tpfh.CanvasInfor = temp.CanvasInfor; tpfh.BitsPerPixel = temp.BitsPerPixel; tpfh.Compress = temp.Compress; }else { if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } } #else if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } #endif if (ver) *ver = tpfh.Version; if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T' && tpfh.Version.Number>=210) { checkVersion = GetHigherCheckVersion(gff); if (tpfh.Version.Number > checkVersion) { // 090527 upper version ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail; } if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } palette->UseColor = useColor; checkVersion = GetPaletteHigherCheckVersion(gff); if (tpfh.Version.Number < checkVersion){ palette->LoadFromFileHandle(fh, 1); } else { palette->LoadFromFileHandle(fh, 2); } if (!ReadFile(fh, &BitCount, sizeof(WORD), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (BitCount==8) { palette->ToRGBQUAD(rgb, 256); fi->Bitmap->PixelFormat = pf8bit; fi->Bitmap->Width = 80; fi->Bitmap->Height = 100; if (fi->Bitmap->Empty) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } SetDIBColorTable(fi->Bitmap->Canvas->Handle, 0, 256, rgb); if (tpfh.Version.Number<222) { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(fi->Bitmap->ScanLine[99-y], buf, 80); } } else { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(fi->Bitmap->ScanLine[y], buf, 80); } } } else { fi->Bitmap->PixelFormat = pf24bit; fi->Bitmap->Width = 80; fi->Bitmap->Height = 100; if (fi->Bitmap->Empty) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (tpfh.Version.Number<222) { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 240, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(fi->Bitmap->ScanLine[99-y], buf, 240); } } else { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 240, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(fi->Bitmap->ScanLine[y], buf, 240); } } } } else { if (SetFilePointer(fh, 0, NULL, FILE_BEGIN)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, &Tex, sizeof(TTexVersion), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } fi->Bitmap->PixelFormat = pf8bit; fi->Bitmap->Width = 80; fi->Bitmap->Height = 100; if (fi->Bitmap->Empty) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Tex.Method=='T' && Tex.Number>=200) { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(fi->Bitmap->ScanLine[99-y], buf, 80); } if (SetFilePointer(fh, 2, NULL, FILE_CURRENT)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } palette->LoadFromFileHandle(fh, 0); palette->ToRGBQUAD(rgb, 256); } else { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(fi->Bitmap->ScanLine[y], buf, 80); } rgb[0].rgbRed = 255; rgb[0].rgbGreen = 255; rgb[0].rgbBlue = 255; j = 1; for (r=0; r<=5; r++) { for (g=0; g<=5; g++) { for (b=0; b<=5; b++) { rgb[j].rgbRed = r*51; rgb[j].rgbGreen = g*51; rgb[j].rgbBlue = b*51; j = j+1; } } } for (r=j; r<=255; r++) { rgb[r].rgbRed = 255; rgb[r].rgbGreen = 255; rgb[r].rgbBlue = 255; } } SetDIBColorTable(fi->Bitmap->Canvas->Handle, 0, 256, rgb); } delete palette; return ec; fail: if (palette) delete palette; if (ec == EC_NONE) ec = EC_FILE_NOT_READ; if (ec != EC_FILE_NOT_OPEN_NEWERVERSION) EXCEPTION_MESSAGE_OK(ec); return ec; } //--------------------------------------------------------------------------- //Trial Verion ¿ë file format(ttex, ttfc, ...)À» ºÒ·¯¿À´Â ºÎºÐ Ãß°¡ bool __fastcall LoadFromTexpiaStyleTag(HANDLE fh, TFileInfor *fi, TGraphicFileFormat gff, TTexVersion *ver, bool bTrialVersion) { TEXPIAFILEHEADER tpfh; int y, j, r, g, b, i, tt; TPException ec = EC_NONE; TTexVersion Tex; RGBQUAD rgb[256]; Byte buf[320], *get; TPalette *palette = NULL; WORD BitCount; DWORD dwRead; TCanvas *canvas; WORD useColor; WORD checkVersion; if ((palette = new TPalette)==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } #ifdef TRIAL //TrialVersion ó¸® if(bTrialVersion == true) //trial ¿ë file formatÀº ±âÁ¸ file formatÀÇ header°¡ µÚÁý¾îÁ® ÀÖ´Â ÇüÅÂÀ̹ǷΠµÚÁý¾î¼­ loadÇÔ. { TEXPIAFILEHEADER_TRIAL temp; if (!ReadFile(fh, &temp, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } tpfh.Version = temp.Version; tpfh.CanvasInfor = temp.CanvasInfor; tpfh.BitsPerPixel = temp.BitsPerPixel; tpfh.Compress = temp.Compress; }else { if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } } #else if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } #endif if (ver) *ver = tpfh.Version; if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T' && tpfh.Version.Number>=210) { checkVersion = GetHigherCheckVersion(gff); if (tpfh.Version.Number > checkVersion) { // 090527 upper version ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail; } if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } palette->UseColor = useColor; checkVersion = GetPaletteHigherCheckVersion(gff); if (tpfh.Version.Number < checkVersion){ palette->LoadFromFileHandle(fh, 1); } else { palette->LoadFromFileHandle(fh, 2); } if (!ReadFile(fh, &BitCount, sizeof(WORD), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (BitCount==8) { palette->ToRGBQUAD(rgb, 256); if (!fi->tBitmap->Create(80, 100, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } canvas = fi->tBitmap->CreateCanvas(); if (!canvas) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } SetDIBColorTable(canvas->Handle, 0, 256, rgb); fi->tBitmap->DeleteCanvas(canvas); if (!(fi->tBitmap->StartScanLine())) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (tpfh.Version.Number<222) { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(99 - y); for ( i = 0 ; i < 80 ; i++) { get[i] = buf[i]; } fi->tBitmap->PutScanLine(99 - y); } } else { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(y); for ( i = 0 ; i < 80 ; i++) { get[i] = buf[i]; } fi->tBitmap->PutScanLine(y); } } fi->tBitmap->StopScanLine(); } else { if (!fi->tBitmap->Create(80, 100, 24)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } fi->tBitmap->StartScanLine(); if (tpfh.Version.Number<222) { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 240, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(99 - y); for (i=0, tt=0 ; i<80 ; i++, tt+=3) { get[tt] = buf[tt]; get[tt+1] = buf[tt+1]; get[tt+2] = buf[tt+2]; } fi->tBitmap->PutScanLine(99 - y); } } else { for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 240, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(y); for (i=0, tt=0 ; i<80 ; i++, tt+=3) { get[tt] = buf[tt]; get[tt+1] = buf[tt+1]; get[tt+2] = buf[tt+2]; } fi->tBitmap->PutScanLine(y); } } fi->tBitmap->StopScanLine(); } } else { if (SetFilePointer(fh, 0, NULL, FILE_BEGIN)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, &Tex, sizeof(TTexVersion), &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } //============================================= if (Tex.Method=='T' && Tex.Number>=200) { // TBitmap->TexpiaBitmapÀ¸·Î ¹Ù²Û°Í¿¡ ´ëÇÑ ¼öÁ¤ÀÌ ¾ÈµÇ¾ú´Ù. // ¾î¶² °æ¿ì¿¡ µé¾î¿À´ÂÁö È®ÀÎÇÒ ¼ö ¾ø´Ù. if (!fi->tBitmap->Create(80, 100, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } fi->tBitmap->StartScanLine(); for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(99 - y); for ( i = 0 ; i < 80 ; i++) { get[i] = buf[i]; } fi->tBitmap->PutScanLine(99 - y); } if (SetFilePointer(fh, 2, NULL, FILE_CURRENT)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } palette->LoadFromFileHandle(fh, 0); palette->ToRGBQUAD(rgb, 256); fi->tBitmap->StopScanLine(); canvas = fi->tBitmap->CreateCanvas(); SetDIBColorTable(canvas->Handle, 0, 256, rgb); fi->tBitmap->DeleteCanvas(canvas); ShowMessage("Please tell me... by kjs"); } else { rgb[0].rgbRed = 0; rgb[0].rgbGreen = 0; rgb[0].rgbBlue = 0; rgb[1].rgbRed = 255; rgb[1].rgbGreen = 255; rgb[1].rgbBlue = 255; for (r=2; r<=255; r++) { rgb[r].rgbRed = 0; rgb[r].rgbGreen = 0; rgb[r].rgbBlue = 0; } if (!fi->tBitmap->Create(80, 100, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } fi->tBitmap->StartScanLine(); for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(y); for ( i = 0 ; i < 80 ; i++) { get[i] = buf[i]; } fi->tBitmap->PutScanLine(y); } fi->tBitmap->StopScanLine(); } //============================================================= /* if (!fi->tBitmap->Create(80, 100, 8, rgb)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (Tex.Method=='T' && Tex.Number>=200) { fi->tBitmap->StartScanLine(); for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } get = fi->tBitmap->GetScanLine(99 - y); for ( i = 0 ; i < 80 ; i++) { get[i] = buf[i]; } fi->tBitmap->PutScanLine(99 - y); } if (SetFilePointer(fh, 2, NULL, FILE_CURRENT)==0xFFFFFFFF) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } palette->LoadFromFileHandle((int)fh, 0); palette->ToRGBQUAD(rgb, 256); fi->tBitmap->StopScanLine(); } else { fi->tBitmap->StartScanLine(); for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } get = fi->tBitmap->GetScanLine(y); for ( i = 0 ; i < 80 ; i++) { get[i] = buf[i]; } fi->tBitmap->PutScanLine(y); } fi->tBitmap->StopScanLine(); rgb[0].rgbRed = 255; rgb[0].rgbGreen = 255; rgb[0].rgbBlue = 255; j = 1; for (r=0; r<=5; r++) { for (g=0; g<=5; g++) { for (b=0; b<=5; b++) { rgb[j].rgbRed = r*51; rgb[j].rgbGreen = g*51; rgb[j].rgbBlue = b*51; j = j+1; } } } for (r=j; r<=255; r++) { rgb[r].rgbRed = 255; rgb[r].rgbGreen = 255; rgb[r].rgbBlue = 255; } } canvas = fi->tBitmap->CreateCanvas(); SetDIBColorTable(canvas->Handle, 0, 256, rgb); fi->tBitmap->DeleteCanvas(canvas); */ } delete palette; return ec; fail: if (palette) delete palette; if (ec == EC_NONE) ec = EC_FILE_NOT_READ; if (ec != EC_FILE_NOT_OPEN_NEWERVERSION) EXCEPTION_MESSAGE_OK(ec); return ec; } //--------------------------------------------------------------------------- void __fastcall MakeTexpiaTag(TTexpiaBitmap *tag, TTexpiaBitmap *tb, TRect src) { // 8.0 conversion double rx, ry; int w, h, x, y, hh, ww, mw, mh, yy, xx, rtn; HDC dcSrc = NULL, dcDst = NULL; Byte *srcp, *srcpp, *dstp; TPException ec = EC_NONE; RGBQUAD rgb[256]; Byte *DP, *SP; if (tb->BitsPerPixel==8) { if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} tb->GetColors(0, 256, rgb); tag->PutColors(0, 256, rgb); } else { if (!(tag->Create(80, 100, 24))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} } tag->FillRect(Rect(0, 0, 80, 100), clWhite); rx = 80.0/(src.Right-src.Left); ry = 100.0/(src.Bottom-src.Top); if (rx>ry) { w = (src.Right-src.Left)*ry; h = (src.Bottom-src.Top)*ry; } else { w = (src.Right-src.Left)*rx; h = (src.Bottom-src.Top)*rx; } if ((dcDst = tag->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((dcSrc = tb->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(dcDst, COLORONCOLOR); rtn = StretchBlt(dcDst, 0, 0, w, h, dcSrc, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); tb->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteDC(dcDst); dcDst = NULL; if (!rtn) { tb->StartScanLine(); tag->StartScanLine(); if (tb->BitsPerPixel==8) { for (y=0; yGetScanLine(y*ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } else { for (y=0; yGetScanLine(y/ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } tb->StopScanLine(); tag->StopScanLine(); } return; fail : if (dcSrc) tb->DeleteDC(dcSrc); if (dcDst) tag->DeleteDC(dcDst); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall MakeTexpiaTag(TTexpiaBitmap *tag, TUnionBitmap *tb, TRect src) { // convert by celberus double rx, ry; int w, h, x, y, hh, ww, mw, mh, yy, xx, rtn; HDC /*dcSrc = NULL,*/ dcDst = NULL; Byte *srcp, *srcpp, *dstp; TPException ec = EC_NONE; RGBQUAD rgb[256]; Byte *DP, *SP; if (tb->BitsPerPixel==8) { if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; goto fail;} tb->GetColors(0, 256, rgb); tag->PutColors(0, 256, rgb); } else { if (!(tag->Create(80, 100, 24))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} } tag->FillRect(Rect(0, 0, 80, 100), clWhite); rx = 80.0/(src.Right-src.Left); ry = 100.0/(src.Bottom-src.Top); if (rx>ry) { w = (src.Right-src.Left)*ry; h = (src.Bottom-src.Top)*ry; } else { w = (src.Right-src.Left)*rx; h = (src.Bottom-src.Top)*rx; } if ((dcDst = tag->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } // if ((dcSrc = tb->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(dcDst, COLORONCOLOR); // rtn = StretchBlt(dcDst, 0, 0, w, h, dcSrc, src.Left, src.Top, // src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); rtn = tb->UnionStretchBlt(dcDst, 0, 0, w, h, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); // tb->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteDC(dcDst); dcDst = NULL; if (!rtn) { tb->StartScanLine(); tag->StartScanLine(); if (tb->BitsPerPixel==8) { for (y=0; yGetScanLine(y*ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } else { for (y=0; yGetScanLine(y/ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } tb->StopScanLine(); tag->StopScanLine(); } return; fail : // if (dcSrc) tb->DeleteDC(dcSrc); if (dcDst) tag->DeleteDC(dcDst); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall MakeTexpiaTag(TTexpiaBitmap *tag, TTexpiaBitmap *tb, TRect src, int method) { // TCanvas *cv = NULL; double rx, ry; int w, h, x, y, hh, ww, mw, mh, yy, xx, rtn; HDC dcSrc = NULL, dcDst = NULL; Byte *srcp, *srcpp, *dstp; TPException ec = EC_NONE; RGBQUAD rgb[256]; Byte *DP, *SP; switch (method) { case 0 : if (tb->BitsPerPixel==8) { if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} tb->GetColors(0, 256, rgb); tag->PutColors(0, 256, rgb); } else { if (!(tag->Create(80, 100, 24))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} } // if ((cv = tag->CreateCanvas())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } // cv->Brush->Color = clWhite; // cv->FillRect(Rect(0, 0, 80, 100)); tag->FillRect(Rect(0, 0, 80, 100), clWhite); rx = 80.0/(src.Right-src.Left); ry = 100.0/(src.Bottom-src.Top); if (rx>ry) { w = (src.Right-src.Left)*ry; h = (src.Bottom-src.Top)*ry; } else { w = (src.Right-src.Left)*rx; h = (src.Bottom-src.Top)*rx; } /* if ((dcSrc = tb->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(cv->Handle, COLORONCOLOR); rtn = StretchBlt(cv->Handle, 0, 0, w, h, dcSrc, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); tb->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteCanvas(cv); cv = NULL; */ if ((dcDst = tag->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((dcSrc = tb->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(dcDst, COLORONCOLOR); rtn = StretchBlt(dcDst, 0, 0, w, h, dcSrc, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); tb->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteDC(dcDst); dcDst = NULL; if (!rtn) { tb->StartScanLine(); tag->StartScanLine(); if (tb->BitsPerPixel==8) { for (y=0; yGetScanLine(y*ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } else { for (y=0; yGetScanLine(y/ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } tb->StopScanLine(); tag->StopScanLine(); } break; case 1 : /// Style Tag........ tb->GetColors(0, 256, rgb); if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} /* if ((cv = tag->CreateCanvas()) == NULL) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} cv->Brush->Color = clWhite; cv->FillRect(Rect(0, 0, 80, 100)); tag->DeleteCanvas(cv); cv = NULL; */ tag->FillRect(Rect(0, 0, 80, 100), clWhite); mw = src.Right-src.Left; mh = src.Bottom-src.Top; rx = 80.0 / mw; ry = 100.0 / mh; if (rx>ry) { w = mw*ry; h = mh*ry; } else { w = mw*rx; h = mh*rx; } hh = Ceil((double) mh / h); ww = Ceil((double) mw / w); if (tb->StartScanLine() == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} if (tag->StartScanLine() == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} for (y = src.Top; y < src.Bottom; y++) { SP = (Byte *) tb->GetScanLine(y); yy = (y - src.Top) / hh; DP = (Byte *) tag->GetScanLine(yy); for (x = src.Left; x < src.Right; x++) { if (SP[x] > 1) { xx = (x - src.Left) / ww; DP[xx] = SP[x]; } } tag->PutScanLine(yy); } tag->StopScanLine(); tb->StopScanLine(); break; } return; fail : if (dcSrc) tb->DeleteDC(dcSrc); // if (cv) tag->DeleteCanvas(cv); if (dcDst) tag->DeleteDC(dcDst); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- void __fastcall MakeTexpiaTag(TTexpiaBitmap *tag, TUnionBitmap *tb, TRect src, int method) { // 8.0 conversion // TCanvas *cv = NULL; double rx, ry; int w, h, x, y, hh, ww, mw, mh, yy, xx, rtn; HDC dcSrc = NULL, dcDst = NULL; Byte *srcp, *srcpp, *dstp; TPException ec = EC_NONE; RGBQUAD rgb[256]; Byte *DP, *SP; switch (method) { case 0 : if (tb->BitsPerPixel==8) { if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} tb->GetColors(0, 256, rgb); tag->PutColors(0, 256, rgb); } else { if (!(tag->Create(80, 100, 24))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} } // if ((cv = tag->CreateCanvas())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } // cv->Brush->Color = clWhite; // cv->FillRect(Rect(0, 0, 80, 100)); tag->FillRect(Rect(0, 0, 80, 100), clWhite); rx = 80.0/(src.Right-src.Left); ry = 100.0/(src.Bottom-src.Top); if (rx>ry) { w = (src.Right-src.Left)*ry; h = (src.Bottom-src.Top)*ry; } else { w = (src.Right-src.Left)*rx; h = (src.Bottom-src.Top)*rx; } /* if ((dcSrc = tb->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(cv->Handle, COLORONCOLOR); rtn = StretchBlt(cv->Handle, 0, 0, w, h, dcSrc, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); tb->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteCanvas(cv); cv = NULL; */ if ((dcDst = tag->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } //if ((dcSrc = tb->CreateDC())==NULL) { ec = EC_RESOURCE_LACK; SAVE_EXCEPTION(ec); goto fail; } SetStretchBltMode(dcDst, COLORONCOLOR); rtn = tb->UnionStretchBlt(dcDst, 0, 0, w, h, src.Left, src.Top, src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); if (rtn == 0) goto fail; //rtn = StretchBlt(dcDst, 0, 0, w, h, dcSrc, src.Left, src.Top, // src.Right-src.Left, src.Bottom-src.Top, SRCCOPY); //tb->DeleteDC(dcSrc); dcSrc = NULL; tag->DeleteDC(dcDst); dcDst = NULL; /* if (!rtn) { tb->StartScanLine(); tag->StartScanLine(); if (tb->BitsPerPixel==8) { for (y=0; yGetScanLine(y*ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } else { for (y=0; yGetScanLine(y/ry); dstp = tag->GetScanLine(y); for (x=0; xPutScanLine(y); } } tb->StopScanLine(); tag->StopScanLine(); }*/ break; case 1 : /// Style Tag........ tb->GetColors(0, 256, rgb); if (!(tag->Create(80, 100, 8, rgb))) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} /* if ((cv = tag->CreateCanvas()) == NULL) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} cv->Brush->Color = clWhite; cv->FillRect(Rect(0, 0, 80, 100)); tag->DeleteCanvas(cv); cv = NULL; */ tag->FillRect(Rect(0, 0, 80, 100), clWhite); mw = src.Right-src.Left; mh = src.Bottom-src.Top; rx = 80.0 / mw; ry = 100.0 / mh; if (rx>ry) { w = mw*ry; h = mh*ry; } else { w = mw*rx; h = mh*rx; } hh = Ceil((double) mh / h); ww = Ceil((double) mw / w); if (tb->StartScanLine() == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} if (tag->StartScanLine() == false) {ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail;} for (y = src.Top; y < src.Bottom; y++) { SP = (Byte *) tb->GetScanLine(y); yy = (y - src.Top) / hh; DP = (Byte *) tag->GetScanLine(yy); for (x = src.Left; x < src.Right; x++) { if (SP[x] > 1) { xx = (x - src.Left) / ww; DP[xx] = SP[x]; } } tag->PutScanLine(yy); } tag->StopScanLine(); tb->StopScanLine(); break; } return; fail : if (dcSrc) tb->DeleteDC(dcSrc); // if (cv) tag->DeleteCanvas(cv); if (dcDst) tag->DeleteDC(dcDst); EXCEPTION_MESSAGE_OK(ec); } //--------------------------------------------------------------------------- //Trial Verion ¿ë file format(ttex, ttfc, ...)À» ºÒ·¯¿À´Â ºÎºÐ Ãß°¡ TPException __fastcall LoadFromTexpiaFile(HANDLE fh, TPalette *pPalette, TEXPIAFILEHEADER &tpfh, TTexpiaBitmap *pBitmap, TGraphicFileFormat gff, bool bTopLeft, bool bTrialVersion) { TTexVersion Tex; TTexColor TexPal[225]; int x, y, iw, ih, scan, offset; short ww, wh; HGLOBAL hMem = NULL; char *src = NULL, *sp; long attr, packsize; RGBQUAD rgb[256]; bool sw; Byte *bp; WORD BitCount; int w; TPMemory *memory = NULL; TPException ec = EC_NONE; DWORD dwRead; TUnionBitmap *tempBitmap = NULL; AnsiString strMem; WORD useColor; WORD checkVersion; //int nVer = tpfh.Version.Number; //080408 #ifdef TRIAL //TrialVersion ó¸® if(bTrialVersion == true) //trial ¿ë file formatÀº ±âÁ¸ file formatÀÇ header°¡ µÚÁý¾îÁ® ÀÖ´Â ÇüÅÂÀ̹ǷΠµÚÁý¾î¼­ loadÇÔ. { TEXPIAFILEHEADER_TRIAL temp; if (!ReadFile(fh, &temp, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; tpfh.Version = temp.Version; tpfh.CanvasInfor = temp.CanvasInfor; tpfh.BitsPerPixel = temp.BitsPerPixel; tpfh.Compress = temp.Compress; }else { if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; } #else if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; #endif if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T' && tpfh.Version.Number>=210) { checkVersion = GetHigherCheckVersion(gff); if (tpfh.Version.Number > checkVersion) { ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail; } // 090527 upper version if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) goto fail; pPalette->UseColor = useColor; checkVersion = GetHigherCheckVersion(gff); if (tpfh.Version.Number LoadFromFileHandle(fh, 1); } else { pPalette->LoadFromFileHandle(fh, 2); } if (!ReadFile(fh, &BitCount, sizeof(WORD), &dwRead, NULL)) goto fail; if (SetFilePointer(fh, BitCount==8 ? 8000 : 24000, NULL, FILE_CURRENT)== 0xFFFFFFFF) goto fail; #ifdef TRIAL if(bTrialVersion == true) //Trial Version ¿ë formatÀ¸·Î ÀúÀåÇÒ ¶§ Áý¾î³ÖÀº 'TRIAL X 10'À» ÀÐÀ½ { BYTE garbage[6]; for(int i = 0; i < 10; i++) if (!ReadFile(fh, garbage, sizeof(Byte) * 6, &dwRead, NULL)) return false; } #endif if (pBitmap) { if (!pBitmap->Create(tpfh.CanvasInfor.Width, tpfh.CanvasInfor.Height, tpfh.BitsPerPixel)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (tpfh.BitsPerPixel==8) { pPalette->ToRGBQUAD(rgb, 256); pBitmap->PutColors(0, 256, rgb); if (tpfh.Version.Number<220) { scan = ((pBitmap->Width+3)/4)*4; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } sp = src; for (y=0; yHeight; y++) { bp = pBitmap->GetScanLine(y); memcpy(bp, sp, pBitmap->Width); pBitmap->PutScanLine(y); sp += scan; } pBitmap->StopScanLine(); GlobalUnlock(hMem); src = NULL; GlobalFree(hMem); hMem = NULL; } else { if (tpfh.Version.Number<222) { w = pBitmap->Width; switch (pBitmap->BitsPerPixel) { case 16: w *= 2; break; case 24: w *= 3; break; } if ((memory = new TPMemory(w*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (memory->lock()==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!memory->LoadFromFile(fh, tpfh.Compress)) goto fail; pBitmap->LoadFromMemory(memory->pointer(), w); delete memory; memory = NULL; } else if (tpfh.Version.Number < 300 || gff == gffWEA || gff == gffKNT) { if (!pBitmap->LoadFromTexpiaFile(fh, tpfh.Compress)) goto fail; } else { // n3d ÆÐÅÏÀ» union¿¡¼­ Àбâ tempBitmap = new TUnionBitmap; tempBitmap->Create(pBitmap->Width, pBitmap->Height, pBitmap->BitsPerPixel); if (pBitmap->BitsPerPixel == 8) { pBitmap->GetColors(0, 256, rgb); tempBitmap->PutColors(0, 256, rgb); } if (!tempBitmap->LoadFromTexpiaFile(fh, tpfh.Compress)) goto fail; tempBitmap->CopyToTexpia(pBitmap, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY); delete tempBitmap; tempBitmap = NULL; } } } else { if (tpfh.Version.Number<220) { scan = ((3*pBitmap->Width+3)/4)*4; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } sp = src; for (y=0; yHeight; y++) { bp = pBitmap->GetScanLine(y); memcpy(bp, sp, 3*pBitmap->Width); pBitmap->PutScanLine(y); sp += scan; } pBitmap->StopScanLine(); GlobalUnlock(hMem); src = NULL; GlobalFree(hMem); hMem = NULL; } else { if (tpfh.Version.Number<222) { w = pBitmap->Width; switch (pBitmap->BitsPerPixel) { case 16: w *= 2; break; case 24: w *= 3; break; } if ((memory = new TPMemory(w*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (memory->lock()==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!memory->LoadFromFile(fh, tpfh.Compress)) goto fail; pBitmap->LoadFromMemory(memory->pointer(), w); delete memory; memory = NULL; } else if (tpfh.Version.Number < 300 || gff == gffWEA || gff == gffKNT) { if (!pBitmap->LoadFromTexpiaFile(fh, tpfh.Compress)) goto fail; } else { // n3d ÆÐÅÏÀ» union¿¡¼­ Àбâ tempBitmap = new TUnionBitmap; tempBitmap->Create(pBitmap->Width, pBitmap->Height, pBitmap->BitsPerPixel); if (pBitmap->BitsPerPixel == 8) { pBitmap->GetColors(0, 256, rgb); tempBitmap->PutColors(0, 256, rgb); } if (!tempBitmap->LoadFromTexpiaFile(fh, tpfh.Compress)) goto fail; tempBitmap->CopyToTexpia(pBitmap, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY); delete tempBitmap; tempBitmap = NULL; } } } } } else { if (SetFilePointer(fh, 0, NULL, FILE_BEGIN)== 0xFFFFFFFF) goto fail; if (!ReadFile(fh, &Tex, sizeof(TTexVersion), &dwRead, NULL)) goto fail; if (SetFilePointer(fh, 8000, NULL, FILE_CURRENT)== 0xFFFFFFFF) goto fail; if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) goto fail; pPalette->UseColor = useColor; if (pBitmap) { if (Tex.Method=='T') { if (Tex.Number<200) { if (!ReadFile(fh, TexPal, sizeof(TexPal), &dwRead, NULL)) goto fail; pPalette->SetTexPalette(TexPal, 225); sw = true; if (!ReadFile(fh, &attr, sizeof(long), &dwRead, NULL)) goto fail; tpfh.Compress = attr&0xF ? cmLZW : cmNone; if (!ReadFile(fh, &tpfh.CanvasInfor.DotsPerInch, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &ww, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &wh, sizeof(short), &dwRead, NULL)) goto fail; tpfh.CanvasInfor.SetSize(cstFree, ww, wh); } else if (Tex.Number<201) { pPalette->LoadFromFileHandle(fh, 0); if (!ReadFile(fh, &attr, sizeof(long), &dwRead, NULL)) goto fail; tpfh.Compress = attr&0xF ? cmLZW : cmNone; if (!ReadFile(fh, &tpfh.CanvasInfor.DotsPerInch, sizeof(short), &dwRead, NULL)) goto fail; sw = false; if (!ReadFile(fh, &iw, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &ih, sizeof(int), &dwRead, NULL)) goto fail; tpfh.CanvasInfor.SetSize(cstFree, iw, ih); } else { pPalette->LoadFromFileHandle(fh, 0); sw = false; if (!ReadFile(fh, &attr, sizeof(long), &dwRead, NULL)) goto fail; tpfh.Compress = attr&0xF ? cmLZW : cmNone; if (!ReadFile(fh, &tpfh.CanvasInfor, sizeof(TPCanvasInfor), &dwRead, NULL)) goto fail; } } else { if (!ReadFile(fh, TexPal, sizeof(TexPal), &dwRead, NULL)) goto fail; pPalette->SetTexPalette(TexPal, 225); sw = true; if (Tex.Method == 'C') { tpfh.Compress = cmLZW; attr = 1; } else { tpfh.Compress = cmNone; attr = 0; } tpfh.CanvasInfor.DotsPerInch = 160; if (!ReadFile(fh, &ww, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &wh, sizeof(short), &dwRead, NULL)) goto fail; tpfh.CanvasInfor.SetSize(cstFree, ww, wh); } pPalette->ToRGBQUAD(rgb, 256); if (pBitmap->Create(tpfh.CanvasInfor.Width, tpfh.CanvasInfor.Height, 8, rgb)==false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (attr&0x10) { scan = ((pBitmap->Width+3)/4)*4; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; } else { scan = pBitmap->Width; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (tpfh.Compress==cmLZW) { if ((offset = SetFilePointer(fh, 0, NULL, FILE_CURRENT))==0xFFFFFFFF) goto fail; if (Tex.Method=='T' && Tex.Number>100) { if (!ReadFile(fh, &packsize, sizeof(long), &dwRead, NULL)) goto fail; if (LZWdecoder_1((int)fh, src, packsize)!=scan*pBitmap->Height) goto fail; offset += 4+packsize; } else { offset += LZWdecoder((int)fh, src); } if (SetFilePointer(fh, offset, NULL, FILE_BEGIN)==0xFFFFFFFF) goto fail; } else { if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; } } if (sw) { sp = src; for (y=0; yHeight; y++) { for (x=0; xWidth; x++) *(sp+x) += 1; sp += pBitmap->Width; } pPalette->UseColor++; } if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (bTopLeft) { sp = src; for (y=0; yHeight; y++) { memcpy(pBitmap->GetScanLine(y), sp, pBitmap->Width); pBitmap->PutScanLine(y); sp += scan; } } else { sp = src+(pBitmap->Height-1)*scan; for (y=0; yHeight; y++) { memcpy(pBitmap->GetScanLine(y), sp, pBitmap->Width); pBitmap->PutScanLine(y); sp -= scan; } } pBitmap->StopScanLine(); GlobalUnlock(hMem); src = NULL; GlobalFree(hMem); hMem = NULL; } else { if (Tex.Method=='V') { if (SetFilePointer(fh, (int)sizeof(TTexColor), NULL, FILE_CURRENT)==0xFFFFFFFF) goto fail; if (!ReadFile(fh, TexPal, sizeof(TTexColor)*pPalette->UseColor, &dwRead, NULL)) goto fail; pPalette->SetTexPalette(TexPal, 225); } else { pPalette->LoadFromFileHandle(fh, 0); if (SetFilePointer(fh, 6, NULL, FILE_CURRENT)==0xFFFFFFFF) goto fail; } } } return EC_NONE; fail: if (hMem) { if (src) { pBitmap->StopScanLine(); GlobalUnlock(hMem); } GlobalFree(hMem); } if (memory) delete memory; if (tempBitmap) delete tempBitmap; if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- //Trial Verion ¿ë file format(ttex, ttfc, ...)À» ºÒ·¯¿À´Â ºÎºÐ Ãß°¡ bool __fastcall SaveToTexpiaFile(HANDLE fh, TPalette *pPalette, TEXPIAFILEHEADER &src_tpfh, TTexpiaBitmap *tag, TTexpiaBitmap *pBitmap, RECT *rect) { #ifdef TRIAL //trial ¿ë file formatÀº ±âÁ¸ file formatÀÇ header¸¦ µÚÁý¾î¼­ ÀúÀå. TEXPIAFILEHEADER_TRIAL tpfh; tpfh.Version = src_tpfh.Version; tpfh.CanvasInfor = src_tpfh.CanvasInfor; tpfh.BitsPerPixel = src_tpfh.BitsPerPixel; tpfh.Compress = src_tpfh.Compress; #else TEXPIAFILEHEADER tpfh = src_tpfh; #endif WORD bpp; DWORD dwWrite; WORD useColor; if (!WriteFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwWrite, NULL)) return false; useColor = pPalette->UseColor; if (!WriteFile(fh, &useColor, sizeof(Word), &dwWrite, NULL)) return false; if (tpfh.Version.Number < 302) pPalette->SaveToFileHandle(fh, 1); else pPalette->SaveToFileHandle(fh, 2); bpp = tag->BitsPerPixel; if (!WriteFile(fh, &bpp, sizeof(WORD), &dwWrite, NULL)) return false; if (!tag->SaveToTexpiaFile(fh, cmNone)) return false; #ifdef TRIAL //Trial Version ¿ë formatÀ¸·Î ÀúÀåÇÒ ¶§ 'TRIAL X 10' ½áÁÜ Byte garbage[6] = "TRIAL"; for(int i = 0; i < 10; i++) if (!WriteFile(fh, garbage, sizeof(Byte) * 6, &dwWrite, NULL)) return false; #endif if (pBitmap) { if (rect) { if (!pBitmap->SaveToTexpiaFile(fh, *rect, tpfh.Compress)) return false; } else { if (!pBitmap->SaveToTexpiaFile(fh, tpfh.Compress)) return false; } } return true; } //--------------------------------------------------------------------------- //Trial Verion ¿ë file format(ttex, ttfc, ...)À» ºÒ·¯¿À´Â ºÎºÐ Ãß°¡ TPException __fastcall LoadFromTexpiaFile(HANDLE fh, TPalette *pPalette, TEXPIAFILEHEADER &tpfh, TUnionBitmap *pBitmap, TGraphicFileFormat gff, bool bTopLeft, TTexpiaBitmap *tag, bool bTrialVersion) //gabriel: added tag { // 8.0 conversion TTexVersion Tex; TTexColor TexPal[225]; int x, y, iw, ih, scan, offset; short ww, wh; HGLOBAL hMem = NULL; char *src = NULL, *sp; long attr, packsize; RGBQUAD rgb[256]; bool sw; Byte *bp; WORD BitCount; int w; TPMemory *memory = NULL; TTexpiaBitmap *tempBitmap = NULL; TPException ec = EC_NONE; DWORD dwRead; int version; AnsiString strMem; WORD useColor; WORD checkVersion; #ifdef TRIAL //TrialVersion ó¸® if(bTrialVersion == true) //trial ¿ë file formatÀº ±âÁ¸ file formatÀÇ header°¡ µÚÁý¾îÁ® ÀÖ´Â ÇüÅÂÀ̹ǷΠµÚÁý¾î¼­ loadÇÔ. { TEXPIAFILEHEADER_TRIAL temp; if (!ReadFile(fh, &temp, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; tpfh.Version = temp.Version; tpfh.CanvasInfor = temp.CanvasInfor; tpfh.BitsPerPixel = temp.BitsPerPixel; tpfh.Compress = temp.Compress; }else { if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; } #else if (!ReadFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwRead, NULL)) goto fail; #endif if (tpfh.Version.Texpia=='P' && tpfh.Version.Method=='T' && tpfh.Version.Number>=210) { checkVersion = GetHigherCheckVersion(gff); if (tpfh.Version.Number > checkVersion) { ec = EC_FILE_NOT_OPEN_NEWERVERSION; goto fail; } // 090527 upper version if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) goto fail; pPalette->UseColor = useColor; checkVersion = GetPaletteHigherCheckVersion(gff); if (tpfh.Version.Number < checkVersion){ pPalette->LoadFromFileHandle(fh, 1); } else { pPalette->LoadFromFileHandle(fh, 2); } if (!ReadFile(fh, &BitCount, sizeof(WORD), &dwRead, NULL)) goto fail; if (tag) { ReadTexpiaBitmapTag(fh, tag, BitCount, pPalette);//gabriel } else { if (SetFilePointer(fh, BitCount==8 ? 8000 : 24000, NULL, FILE_CURRENT)== 0xFFFFFFFF) goto fail; } #ifdef TRIAL if(bTrialVersion == true) //Trial Version ¿ë formatÀ¸·Î ÀúÀåÇÒ ¶§ Áý¾î³ÖÀº 'TRIAL X 10'À» ÀÐÀ½ { Byte garbage[6]; for(int i = 0; i < 10; i++) { if (!ReadFile(fh, &garbage, sizeof(Byte) * 6, &dwRead, NULL)) return false; } } #endif //Error È®ÀÎÇϱâ À§Çؼ­ Ãß°¡ÇÔ. Motive ÆÄÀÏ load Áß 0º¸´Ù ÀÛÀº °æ¿ì°¡ ÀÖ¾ú´Ù. by david 081211 if (tpfh.CanvasInfor.Width < 0 || tpfh.CanvasInfor.Height < 0) goto fail; if (pBitmap) { if (!pBitmap->Create(tpfh.CanvasInfor.Width, tpfh.CanvasInfor.Height, tpfh.BitsPerPixel)) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (tpfh.BitsPerPixel==8) { pPalette->ToRGBQUAD(rgb, 256); pBitmap->PutColors(0, 256, rgb); if (tpfh.Version.Number<220) { scan = ((pBitmap->Width+3)/4)*4; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } sp = src; for (y=0; yHeight; y++) { bp = pBitmap->GetScanLine(y); memcpy(bp, sp, pBitmap->Width); pBitmap->PutScanLine(y); sp += scan; } pBitmap->StopScanLine(); GlobalUnlock(hMem); src = NULL; GlobalFree(hMem); hMem = NULL; } else { if (tpfh.Version.Number<222) { w = pBitmap->Width; switch (pBitmap->BitsPerPixel) { case 16: w *= 2; break; case 24: w *= 3; break; } if ((memory = new TPMemory(w*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (memory->lock()==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!memory->LoadFromFile(fh, tpfh.Compress)) goto fail; pBitmap->LoadFromMemory(memory->pointer(), w); delete memory; memory = NULL; } else if (tpfh.Version.Number < 300 || gff == gffWEA || gff == gffKNT) { tempBitmap = new TTexpiaBitmap; tempBitmap->Create(pBitmap->Width, pBitmap->Height, pBitmap->BitsPerPixel, rgb); if (!tempBitmap->LoadFromTexpiaFile(fh, tpfh.Compress)) goto fail; HDC tempDC = tempBitmap->CreateDC(); pBitmap->UnionBitBlt(tempDC, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY, true); tempBitmap->DeleteDC(tempDC); delete tempBitmap; } else { if (!pBitmap->LoadFromTexpiaFile(fh, tpfh.Compress, StatusProgress)) goto fail; //int w, h; //if (!ReadFile(fh, &w, sizeof(int), &dwRead, NULL)) goto fail; //if (!ReadFile(fh, &h, sizeof(int), &dwRead, NULL)) goto fail; } } } else { if (tpfh.Version.Number<220) { scan = ((3*pBitmap->Width+3)/4)*4; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } sp = src; for (y=0; yHeight; y++) { bp = pBitmap->GetScanLine(y); memcpy(bp, sp, 3*pBitmap->Width); pBitmap->PutScanLine(y); sp += scan; } pBitmap->StopScanLine(); GlobalUnlock(hMem); src = NULL; GlobalFree(hMem); hMem = NULL; } else { if (tpfh.Version.Number<222) { w = pBitmap->Width; switch (pBitmap->BitsPerPixel) { case 16: w *= 2; break; case 24: w *= 3; break; } if ((memory = new TPMemory(w*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (memory->lock()==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!memory->LoadFromFile(fh, tpfh.Compress)) goto fail; pBitmap->LoadFromMemory(memory->pointer(), w); delete memory; memory = NULL; } else if (tpfh.Version.Number<300 || gff == gffWEA || gff == gffKNT) { tempBitmap = new TTexpiaBitmap; tempBitmap->Create(pBitmap->Width, pBitmap->Height, pBitmap->BitsPerPixel); if (!tempBitmap->LoadFromTexpiaFile(fh, tpfh.Compress)) goto fail; HDC tempDC = tempBitmap->CreateDC(); pBitmap->UnionBitBlt(tempDC, 0, 0, tempBitmap->Width, tempBitmap->Height, 0, 0, SRCCOPY, true); tempBitmap->DeleteDC(tempDC); delete tempBitmap; } else { if (!pBitmap->LoadFromTexpiaFile(fh, tpfh.Compress, StatusProgress)) goto fail; //int w, h; //if (!ReadFile(fh, &w, sizeof(int), &dwRead, NULL)) goto fail; //if (!ReadFile(fh, &h, sizeof(int), &dwRead, NULL)) goto fail; } } } } } else { if (SetFilePointer(fh, 0, NULL, FILE_BEGIN)== 0xFFFFFFFF) goto fail; if (!ReadFile(fh, &Tex, sizeof(TTexVersion), &dwRead, NULL)) goto fail; if (SetFilePointer(fh, 8000, NULL, FILE_CURRENT)== 0xFFFFFFFF) goto fail; if (!ReadFile(fh, &useColor, sizeof(Word), &dwRead, NULL)) goto fail; pPalette->UseColor = useColor; if (pBitmap) { if (Tex.Method=='T') { if (Tex.Number<200) { if (!ReadFile(fh, TexPal, sizeof(TexPal), &dwRead, NULL)) goto fail; pPalette->SetTexPalette(TexPal, 225); sw = true; if (!ReadFile(fh, &attr, sizeof(long), &dwRead, NULL)) goto fail; tpfh.Compress = attr&0xF ? cmLZW : cmNone; if (!ReadFile(fh, &tpfh.CanvasInfor.DotsPerInch, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &ww, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &wh, sizeof(short), &dwRead, NULL)) goto fail; tpfh.CanvasInfor.SetSize(cstFree, ww, wh); } else if (Tex.Number<201) { pPalette->LoadFromFileHandle(fh, 0); if (!ReadFile(fh, &attr, sizeof(long), &dwRead, NULL)) goto fail; tpfh.Compress = attr&0xF ? cmLZW : cmNone; if (!ReadFile(fh, &tpfh.CanvasInfor.DotsPerInch, sizeof(short), &dwRead, NULL)) goto fail; sw = false; if (!ReadFile(fh, &iw, sizeof(int), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &ih, sizeof(int), &dwRead, NULL)) goto fail; tpfh.CanvasInfor.SetSize(cstFree, iw, ih); } else { pPalette->LoadFromFileHandle(fh, 0); sw = false; if (!ReadFile(fh, &attr, sizeof(long), &dwRead, NULL)) goto fail; tpfh.Compress = attr&0xF ? cmLZW : cmNone; if (!ReadFile(fh, &tpfh.CanvasInfor, sizeof(TPCanvasInfor), &dwRead, NULL)) goto fail; } } else { if (!ReadFile(fh, TexPal, sizeof(TexPal), &dwRead, NULL)) goto fail; pPalette->SetTexPalette(TexPal, 225); sw = true; if (Tex.Method == 'C') { tpfh.Compress = cmLZW; attr = 1; } else { tpfh.Compress = cmNone; attr = 0; } tpfh.CanvasInfor.DotsPerInch = 160; if (!ReadFile(fh, &ww, sizeof(short), &dwRead, NULL)) goto fail; if (!ReadFile(fh, &wh, sizeof(short), &dwRead, NULL)) goto fail; tpfh.CanvasInfor.SetSize(cstFree, ww, wh); } pPalette->ToRGBQUAD(rgb, 256); if (pBitmap->Create(tpfh.CanvasInfor.Width, tpfh.CanvasInfor.Height, 8, rgb)==false) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (attr&0x10) { scan = ((pBitmap->Width+3)/4)*4; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; } else { scan = pBitmap->Width; if ((hMem = GlobalAlloc(GHND, scan*pBitmap->Height))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if ((src = (Byte *)GlobalLock(hMem))==NULL) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (tpfh.Compress==cmLZW) { if ((offset = SetFilePointer(fh, 0, NULL, FILE_CURRENT))==0xFFFFFFFF) goto fail; if (Tex.Method=='T' && Tex.Number>100) { if (!ReadFile(fh, &packsize, sizeof(long), &dwRead, NULL)) goto fail; if (LZWdecoder_1((int)fh, src, packsize)!=scan*pBitmap->Height) goto fail; offset += 4+packsize; } else { offset += LZWdecoder((int)fh, src); } if (SetFilePointer(fh, offset, NULL, FILE_BEGIN)==0xFFFFFFFF) goto fail; } else { if (!ReadFile(fh, src, scan*pBitmap->Height, &dwRead, NULL)) goto fail; } } if (sw) { sp = src; for (y=0; yHeight; y++) { for (x=0; xWidth; x++) *(sp+x) += 1; sp += pBitmap->Width; } pPalette->UseColor++; } if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } if (bTopLeft) { sp = src; for (y=0; yHeight; y++) { memcpy(pBitmap->GetScanLine(y), sp, pBitmap->Width); pBitmap->PutScanLine(y); sp += scan; } } else { sp = src+(pBitmap->Height-1)*scan; for (y=0; yHeight; y++) { memcpy(pBitmap->GetScanLine(y), sp, pBitmap->Width); pBitmap->PutScanLine(y); sp -= scan; } } pBitmap->StopScanLine(); GlobalUnlock(hMem); src = NULL; GlobalFree(hMem); hMem = NULL; } else { if (Tex.Method=='V') { if (SetFilePointer(fh, (int)sizeof(TTexColor), NULL, FILE_CURRENT)==0xFFFFFFFF) goto fail; if (!ReadFile(fh, TexPal, sizeof(TTexColor)*pPalette->UseColor, &dwRead, NULL)) goto fail; pPalette->SetTexPalette(TexPal, 225); } else { pPalette->LoadFromFileHandle(fh, 0); if (SetFilePointer(fh, 6, NULL, FILE_CURRENT)==0xFFFFFFFF) goto fail; } } } return EC_NONE; fail: if (hMem) { if (src) { pBitmap->StopScanLine(); GlobalUnlock(hMem); } GlobalFree(hMem); } if (memory) delete memory; if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- //Trial Verion ¿ë file format(ttex, ttfc, ...)À» ºÒ·¯¿À´Â ºÎºÐ Ãß°¡ bool __fastcall SaveToTexpiaFile(HANDLE fh, TPalette *pPalette, TEXPIAFILEHEADER &src_tpfh, TTexpiaBitmap *tag, TUnionBitmap *pBitmap, RECT *rect) { // 8.0 conversion #ifdef TRIAL //trial ¿ë file formatÀº ±âÁ¸ file formatÀÇ header¸¦ µÚÁý¾î¼­ ÀúÀå. TEXPIAFILEHEADER_TRIAL tpfh; tpfh.Version = src_tpfh.Version; tpfh.CanvasInfor = src_tpfh.CanvasInfor; tpfh.BitsPerPixel = src_tpfh.BitsPerPixel; tpfh.Compress = src_tpfh.Compress; #else TEXPIAFILEHEADER tpfh = src_tpfh; #endif WORD bpp; DWORD dwWrite; WORD useColor; if (!WriteFile(fh, &tpfh, sizeof(TEXPIAFILEHEADER), &dwWrite, NULL)) return false; useColor = pPalette->UseColor; if (!WriteFile(fh, &useColor, sizeof(Word), &dwWrite, NULL)) return false; if (tpfh.Version.Number < 302) pPalette->SaveToFileHandle(fh, 1); else pPalette->SaveToFileHandle(fh, 2); bpp = tag->BitsPerPixel; if (!WriteFile(fh, &bpp, sizeof(WORD), &dwWrite, NULL)) return false; if (!tag->SaveToTexpiaFile(fh, cmNone)) return false; #ifdef TRIAL //Trial Version ¿ë formatÀ¸·Î ÀúÀåÇÒ ¶§ 'TRIAL X 10' ½áÁÜ Byte garbage[6] = "TRIAL"; for(int i = 0; i < 10; i++) { if (!WriteFile(fh, garbage, sizeof(Byte) * 6, &dwWrite, NULL)) return false; } #endif if (pBitmap) { if (rect) { if (!pBitmap->SaveToTexpiaFile(fh, *rect, tpfh.Compress)) return false; } else { if (!pBitmap->SaveToTexpiaFile(fh, tpfh.Compress, false, StatusProgress)) return false; } } //Stripe_FÀÇ tag bitmap ÀúÀå ÇÒ ¶§¿¡´Â pBirmapÀ» NULL·Î º¸³½´Ù. //µû¶ó¼­ ¹«Á¶°Ç false·Î ó¸®ÇÏ¸é ¾ÈµÈ´Ù. //else { // return false; //} return true; } //--------------------------------------------------------------------------- #ifdef TEXSTYLIST TGraphicFileFormat __fastcall FindExtension(String ext) { TGraphicFileFormat ExtIndex = gffNON; ext = ext.LowerCase(); // È®ÀåÀÚ¸¦ ¼Ò¹®ÀÚ·Î º¯È¯ ÈÄ Ã³¸®Çϵµ·Ï ¼öÁ¤ - by monkman (2010.10.07) if (ext == ".tex") ExtIndex = gffTEX; else if (ext == ".vst") ExtIndex = gffVST; else if (ext == ".tfc") ExtIndex = gffTFC; // else if (ext == ".t3d") ExtIndex = gffT3D; // #ifdef NOTN3D // #else // else if (ext == ".n3d") ExtIndex = gffN3D; // #endif else if (ext == ".wea") ExtIndex = gffWEA; else if (ext == ".wav") ExtIndex = gffWAV; else if (ext == ".knt") ExtIndex = gffKNT; else if (ext == ".bmp") ExtIndex = gffBMP; else if (ext == ".jpg") ExtIndex = gffJPG; else if (ext == ".pct") ExtIndex = gffPCT; else if (ext == ".pcx") ExtIndex = gffPCX; else if (ext == ".png") ExtIndex = gffPNG; else if (ext == ".psd") ExtIndex = gffPSD; else if (ext == ".ras") ExtIndex = gffRAS; else if (ext == ".tga") ExtIndex = gffTGA; else if (ext == ".tif") ExtIndex = gffTIF; else if (ext == ".eps") ExtIndex = gffEPS; else if (ext == ".dxf") ExtIndex = gffDXF; else if (ext == ".svg") ExtIndex = gffSVG; // for SVG by maxleo21c(06.06.17) // else if (ext == ".pil") ExtIndex = gffPIL; // else if (ext == ".cmb") ExtIndex = gffCMB; // else if (ext == ".jqd") ExtIndex = gffJQD; // else if (ext == ".stp") ExtIndex = gffSTP; // else if (ext == ".mcw") ExtIndex = gffMCW; // else if (ext == ".mtl") ExtIndex = gffMTL; // else if (ext == ".wal") ExtIndex = gffWAL; // else if (ext == ".apt") ExtIndex = gffAPT; else if (ext == ".*") ExtIndex = gffALL; #ifdef TRIAL //Trial Vesion¿ë format Ãß°¡ else if (ext == ".ttex") ExtIndex = gffTEX_TRIAL; else if (ext == ".ttfc") ExtIndex = gffTFC_TRIAL; else if (ext == ".tt3d") ExtIndex = gffT3D_TRIAL; else if (ext == ".twea") ExtIndex = gffWEA_TRIAL; else if (ext == ".tknt") ExtIndex = gffKNT_TRIAL; else if (ext == ".tvst") ExtIndex = gffVST_TRIAL; #endif else ExtIndex = gffNON; return ExtIndex; } #endif //--------------------------------------------------------------------------- bool __fastcall ReadTexpiaBitmapTag(HANDLE fh, TTexpiaBitmap *tag, WORD bpp, TPalette *palette)//gabriel {//read TTexpiaBitmap tags from TTexpiaBitmap-type-saved files Graphics::TBitmap *tempBitmap; tempBitmap = new Graphics::TBitmap; if (!ReadTBitmapTag(fh, tempBitmap, bpp, palette)) goto fail; RGBQUAD rgb[256]; HDC tDC; palette->ToRGBQUAD(rgb, 256); tag->Create(80,100,bpp,rgb); //BitsPerPixel is saved tDC = tag->CreateDC(); BitBlt(tDC, 0, 0, 80, 100, tempBitmap->Canvas->Handle, 0, 0, SRCCOPY); tag->DeleteDC(tDC); return true; fail: return false; } //--------------------------------------------------------------------------- bool __fastcall ReadTBitmapTag(HANDLE fh, Graphics::TBitmap *tag, WORD bpp, TPalette *palette)//gabriel {//read TBitmap tags from TTexpiaBitmap-type-saved files TPException ec = EC_NONE; int y; RGBQUAD rgb[256]; Byte buf[320]; DWORD dwRead; if (bpp==8) { palette->ToRGBQUAD(rgb, 256); tag->PixelFormat = pf8bit; tag->Width = 80; tag->Height = 100; if (tag->Empty) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } SetDIBColorTable(tag->Canvas->Handle, 0, 256, rgb); for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 80, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(tag->ScanLine[y], buf, 80); } } else { tag->PixelFormat = pf24bit; tag->Width = 80; tag->Height = 100; if (tag->Empty) { ec = EC_MEMORY_LACK; SAVE_EXCEPTION(ec); goto fail; } for (y=0; y<100; y++) { if (!ReadFile(fh, buf, 240, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; SAVE_EXCEPTION(ec); goto fail; } memcpy(tag->ScanLine[y], buf, 240); } } return true; fail: return false; } //--------------------------------------------------------------------------- //bool __fastcall MakeBackupFile(String dirName, String fileName) bool __fastcall MakeBackupFile(String dirName, String fileName) { //String backupDir = DefaultDir + "\\Backup"; String backupDir = String(DefaultDir + "\\Backup"); if(!DirectoryExists(backupDir)) CreateDir(backupDir); //String tempFileName = fileName + ".bak"; //String srcfullName = fileName; String tempFileName = fileName + ".bak"; String srcfullName = fileName; if (dirName != NULL){ srcfullName = FullPathName(dirName, fileName); } //String dstfullName = backupDir + "\\" + tempFileName; String dstfullName = backupDir + String("\\") + tempFileName; int result = CopyFile(srcfullName.c_str(), dstfullName.c_str(), false); if (result != 0) return true; else return false; } //--------------------------------------------------------------------------- //bool __fastcall BackupFileRollback(String dirName, String fileName) bool __fastcall BackupFileRollback(String dirName, String fileName) { //String backupDir = DefaultDir + "\\Backup"; //String tempFileName = fileName + ".bak"; //String tempfullName = backupDir + "\\" + tempFileName; String backupDir = String(DefaultDir + "\\Backup"); String tempFileName = fileName + String(".bak"); String tempfullName = backupDir + String("\\") + tempFileName; int result = 0; if (FileExists(tempfullName)){ //String fullName = fileName; String fullName = fileName; if (dirName != NULL){ fullName = FullPathName(dirName, fileName); } result = CopyFile(tempfullName.c_str(), fullName.c_str(), false); } if (result != 0) return true; else return false; } //--------------------------------------------------------------------------- void __fastcall FindFiles(String strRootPath, TStringList *DirList , TStringList *FileList, bool bRecursive, String FileExt) { try { if (String(strRootPath.LastChar()) != "\\") strRootPath += "\\"; String strFindPath; TSearchRec srPath; int Found = FindFirst(strRootPath + "*.*", faAnyFile, srPath); while (Found == 0) { strFindPath = strRootPath + srPath.Name; if (*srPath.Name.c_str() != '.') { if (DirectoryExists(strFindPath)) { if (DirList) DirList->Add(strFindPath); if (bRecursive) FindFiles(strFindPath, DirList, FileList, bRecursive, FileExt); } else if (FileExists(strFindPath)) { if (FileList){ if (FileExt.IsEmpty()) FileList->Add(strFindPath); else { String findext = ExtractFileExt(strFindPath); if (FileExt.Compare(findext) == 0) FileList->Add(strFindPath); } } } } Found = FindNext(srPath); } FindClose(srPath); } catch (Exception &e) { //throw e; } } //--------------------------------------------------------------------------- TTexProFileType GetFileType(TGraphicFileFormat gff) { #if defined(TEXSTYLIST) if (gff == gffWEA || gff == gffWAV #ifdef TRIAL || gff == gffWEA_TRIAL #endif ) { return WEAVE_FILE; } else if (gff == gffKNT #ifdef TRIAL || gff == gffKNT_TRIAL #endif ) { return KNIT_FILE; } // ³ª¸ÓÁö´Â ¸ðµÎ Textile File·Î ó¸® else { return TEXTILE_FILE; } #endif } //--------------------------------------------------------------------------- // »óÀ§ ¹öÀü üũ¿¡¼­ »ç¿ëÇÒ °¢ Format¿¡ ÇØ´ç ÇÏ´Â ¹öÀü Word GetHigherCheckVersion(TGraphicFileFormat gff) { if (gff == gffTEX || gff == gffTFC || gff == gffVST) { return TextileFileVersion; } else if (gff == gffWEA || gff == gffWAV) { return WeaveFileCheckVersion; } else if (gff == gffKNT) { return KnitFileCheckVersion; } else return TextileFileVersion; } //--------------------------------------------------------------------------- Word GetPaletteHigherCheckVersion(TGraphicFileFormat gff) { if (gff == gffTEX || gff == gffTFC || gff == gffVST) { return 302; } else if (gff == gffWEA || gff == gffWAV) { return 270; } else if (gff == gffKNT) { return 280; } else return 302; } //--------------------------------------------------------------------------- bool __fastcall GotoRecycler(String strFileName) { // ÈÞÁöÅëÀ¸·Î º¸³»±â - by monkman (2011.02.07) SHFILEOPSTRUCT shfoFile; Char *ucFrom = NULL; // ÈÞÁöÅëÀ¸·Î º¸³»±â (Á¾°á ¹®ÀÚ¿­ÀÌ "\0\0" µÎ ¹ÙÀÌÆ®·Î ³¡³ª¾ßÇÑ´Ù!!) memset(&shfoFile, 0, sizeof(SHFILEOPSTRUCT)); shfoFile.hwnd = Application->Handle; shfoFile.wFunc = FO_DELETE; if ((ucFrom = (Char *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(Char) * strFileName.Length()+2)) == NULL) goto fail; _tcscpy(ucFrom, strFileName.c_str()); shfoFile.pFrom = ucFrom; shfoFile.fFlags = FOF_ALLOWUNDO ; SHFileOperation(&shfoFile); if (ucFrom) HeapFree(GetProcessHeap(), 0, ucFrom); ucFrom = NULL; return true; fail: if (ucFrom) HeapFree(GetProcessHeap(), 0, ucFrom); return false; } //---------------------------------------------------------------------------