Imported from antiword-0.37.tar.gz.
[antiword.git] / jpeg2eps.c
blobee438cec4df528f53c409350d8614432fab5fdf9
1 /*
2 * jpeg2eps.c
3 * Copyright (C) 2000-2002 A.J. van Os; Released under GPL
5 * Description:
6 * Functions to translate jpeg pictures into eps
8 */
10 #include <stdio.h>
11 #include "antiword.h"
13 #if defined(DEBUG)
14 static int iPicCounter = 0;
15 #endif /* DEBUG */
18 #if defined(DEBUG)
20 * vCopy2File
22 static void
23 vCopy2File(FILE *pFile, ULONG ulFileOffset, size_t tPictureLen)
25 FILE *pOutFile;
26 size_t tIndex;
27 int iTmp;
28 char szFilename[30];
30 if (!bSetDataOffset(pFile, ulFileOffset)) {
31 return;
34 sprintf(szFilename, "/tmp/pic/pic%04d.jpg", ++iPicCounter);
35 pOutFile = fopen(szFilename, "wb");
36 if (pOutFile == NULL) {
37 return;
39 for (tIndex = 0; tIndex < tPictureLen; tIndex++) {
40 iTmp = iNextByte(pFile);
41 if (putc(iTmp, pOutFile) == EOF) {
42 break;
45 (void)fclose(pOutFile);
46 } /* end of vCopy2File */
47 #endif /* DEBUG */
50 * bTranslateJPEG - translate a JPEG picture
52 * This function translates a picture from jpeg to eps
54 * return TRUE when sucessful, otherwise FALSE
56 BOOL
57 bTranslateJPEG(diagram_type *pDiag, FILE *pFile,
58 ULONG ulFileOffset, size_t tPictureLen, const imagedata_type *pImg)
60 #if defined(DEBUG)
61 vCopy2File(pFile, ulFileOffset, tPictureLen);
62 #endif /* DEBUG */
64 /* Seek to start position of JPEG data */
65 if (!bSetDataOffset(pFile, ulFileOffset)) {
66 return FALSE;
69 vImagePrologue(pDiag, pImg);
70 vASCII85EncodeFile(pFile, pDiag->pOutFile, tPictureLen);
71 vImageEpilogue(pDiag);
73 return TRUE;
74 } /* end of bTranslateJPEG */