| AWARE [SYSTEMS] | Imaging expertise for the Delphi developer | |||||||
![]() |
TIFF and LibTiff Mailing List Archive | |||||||
LibTiff Mailing List
TIFF and LibTiff Mailing List Archive Contact
The TIFF Mailing List Homepage |
Thread1999.12.17 15:54 "Re: TIFF previews in EPS files", by Dean GrimmHi Flemming,
I use the following C++ code on Windows:
#define EPS_BUFFER_LEN 8192
#define EPS_THUMBTYPE_ERROR -2
#define EPS_THUMBTYPE_NONE -1
#define EPS_THUMBTYPE_TIFF 0
#define EPS_THUMBTYPE_META 1
const BYTE EPS_HDR_MAGIC_PS_ASCII[] = "%!";
const BYTE EPS_HDR_MAGIC_PS_WIN[] = {0xc5,0xd0,0xd3,0xc6};
typedef struct tagEPSHEADER {
BYTE magic[4];
DWORD offPS;
DWORD lenPS;
DWORD offMeta;
DWORD lenMeta;
DWORD offTiff;
DWORD lenTiff;
WORD checksum;
}EPSHEADER;
int ExtractEPSThumbnail(LPCTSTR pszEPSPath, LPCTSTR pszOutPath)
{
int result = EPS_THUMBTYPE_NONE;
HANDLE hf;
// open the EPS file
if ((hf=FOPEN(pszEPSPath)) != INVALID_HANDLE_VALUE)
{
EPSHEADER hdr;
DWORD dwRead, dwOffset=0, dwLength=0;
// read the header
if (!ReadFile(hf, &hdr, sizeof(EPSHEADER), &dwRead, NULL)
|| dwRead != sizeof(EPSHEADER))
{
CloseHandle(hf);
return EPS_THUMBTYPE_NONE;
}
// check the type
if (hdr.magic[0] == EPS_HDR_MAGIC_PS_ASCII[0]
&& hdr.magic[1] == EPS_HDR_MAGIC_PS_ASCII[1])
{
result = EPS_THUMBTYPE_NONE;
}
else if (hdr.magic[0] == EPS_HDR_MAGIC_PS_WIN[0]
&& hdr.magic[1] == EPS_HDR_MAGIC_PS_WIN[1]
&& hdr.magic[2] == EPS_HDR_MAGIC_PS_WIN[2]
&& hdr.magic[3] == EPS_HDR_MAGIC_PS_WIN[3])
{
// thumbnail is TIFF
if (hdr.lenTiff>0)
{
result = EPS_THUMBTYPE_TIFF;
dwOffset = hdr.offTiff;
dwLength = hdr.lenTiff;
}
// thumbnail is metafile
else if (hdr.lenMeta>0)
{
result = EPS_THUMBTYPE_META;
dwOffset = hdr.offMeta;
dwLength = hdr.lenMeta;
}
else
result = EPS_THUMBTYPE_NONE;
// extract the file
if (dwLength > 0)
{
HANDLE hfOut;
DWORD dwOut = 0, dwSize, dwWrite;
// open the EPS file
if ((hfOut=FOPEN(pszOutPath, GENERIC_WRITE,
CREATE_ALWAYS)) != INVALID_HANDLE_VALUE)
{
char buf[EPS_BUFFER_LEN];
// seek to the thumbnail offset
if (SetFilePointer(hf, dwOffset,
NULL, FILE_BEGIN) != 0xFFFFFFFF)
{
while (dwOut < dwLength)
{
// read, at most,
bufferlen bytes from input file
dwSize =
min(EPS_BUFFER_LEN, dwLength-dwOut);
if (!ReadFile(hf,
buf, dwSize, &dwRead, NULL)
|| dwRead !=
dwSize)
{
result =
EPS_THUMBTYPE_ERROR;
break;
}
// write bytes to
output file
if
(!WriteFile(hfOut, buf, dwRead, &dwWrite, NULL)
|| dwWrite
!= dwRead)
{
result =
EPS_THUMBTYPE_ERROR;
break;
}
dwOut += dwSize;
}
}
else
result =
EPS_THUMBTYPE_ERROR;
CloseHandle(hfOut);
}
}
}
CloseHandle(hf);
}
return result;
}
> -----Original Message-----
> From: Flemming Bengtsson [mailto:fb@adaptor-as.dk]
> Sent: Friday, December 17, 1999 3:30 AM
> To: tiff@olympiakos.com
> Subject: TIFF previews in EPS files
>
>
> Hi all,
>
> Using Libtiff 3.5.3 on a PowerMac G4.
>
> Does anyone know how to read TIFF previews in EPS files ?
>
> Regards,
> --
> Flemming Bengtsson, Adaptor Digital Publishing A/S.
>
>
|
|||||||