home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / anwor032.zip / antiword.0.32 / jpeg2eps.c < prev    next >
C/C++ Source or Header  |  2000-10-26  |  1KB  |  74 lines

  1. /*
  2.  * jpeg2eps.c
  3.  * Copyright (C) 2000 A.J. van Os; Released under GPL
  4.  *
  5.  * Description:
  6.  * Functions to translate jpeg pictures into eps
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include "antiword.h"
  12.  
  13. #if defined(DEBUG)
  14. static int    iPicCounter = 0;
  15. #endif /* DEBUG */
  16.  
  17.  
  18. #if defined(DEBUG)
  19. /*
  20.  * vCopy2File
  21.  */
  22. static void
  23. vCopy2File(FILE *pFile, long lFileOffset, int iPictureLen)
  24. {
  25.     FILE    *pOutFile;
  26.     int    iIndex, iTmp;
  27.     char    szFilename[30];
  28.  
  29.     if (!bSetDataOffset(pFile, lFileOffset)) {
  30.         return;
  31.     }
  32.  
  33.     sprintf(szFilename, "/tmp/pic/pic%04d.jpg", ++iPicCounter);
  34.     pOutFile = fopen(szFilename, "wb");
  35.     if (pOutFile == NULL) {
  36.         return;
  37.     }
  38.     for (iIndex = 0; iIndex < iPictureLen; iIndex++) {
  39.         iTmp = iNextByte(pFile);
  40.         if (putc(iTmp, pOutFile) == EOF) {
  41.             break;
  42.         }
  43.     }
  44.     (void)fclose(pOutFile);
  45. } /* end of vCopy2File */
  46. #endif /* DEBUG */
  47.  
  48. /*
  49.  * bTranslateJPEG - translate a JPEG picture
  50.  *
  51.  * This function translates a picture from jpeg to eps
  52.  *
  53.  * return TRUE when sucessful, otherwise FALSE
  54.  */
  55. BOOL
  56. bTranslateJPEG(diagram_type *pDiag, FILE *pFile,
  57.         long lFileOffset, int iPictureLen, const imagedata_type *pImg)
  58. {
  59. #if defined(DEBUG)
  60.     vCopy2File(pFile, lFileOffset, iPictureLen);
  61. #endif /* DEBUG */
  62.  
  63.     /* Seek to start position of JPEG data */
  64.     if (!bSetDataOffset(pFile, lFileOffset)) {
  65.         return FALSE;
  66.     }
  67.  
  68.     vImagePrologue(pDiag, pImg);
  69.     vASCII85EncodeFile(pFile, pDiag->pOutFile, iPictureLen);
  70.     vImageEpilogue(pDiag);
  71.  
  72.     return TRUE;
  73. } /* end of bTranslateJPEG */
  74.