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

  1. /*
  2.  * jpeg2sprt.c
  3.  * Copyright (C) 2000, 2001 A.J. van Os; Released under GPL
  4.  *
  5.  * Description:
  6.  * Functions to translate jpeg pictures into sprites
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include "antiword.h"
  11.  
  12. #if 0 /* defined(DEBUG) */
  13. static int iPicCounter = 0;
  14. #endif /* DEBUG */
  15.  
  16.  
  17. #if 0 /* defined(DEBUG) */
  18. static void
  19. vCopy2File(unsigned char *pucJpeg, size_t tJpegSize)
  20. {
  21.     FILE    *pOutFile;
  22.     size_t    tIndex;
  23.     char    szFilename[30];
  24.  
  25.     sprintf(szFilename, "<Wimp$ScrapDir>.jpeg%04d", ++iPicCounter);
  26.     pOutFile = fopen(szFilename, "wb");
  27.     if (pOutFile == NULL) {
  28.         return;
  29.     }
  30.     DBG_MSG(szFilename);
  31.     for (tIndex = 0; tIndex < tJpegSize; tIndex++) {
  32.         if (putc(pucJpeg[tIndex], pOutFile) == EOF) {
  33.             break;
  34.         }
  35.     }
  36.     (void)fclose(pOutFile);
  37.     vSetFiletype(szFilename, FILETYPE_JPEG);
  38. } /* end of vCopy2File */
  39. #endif /* DEBUG */
  40.  
  41. /*
  42.  * bSave2Draw - save the JPEG picture to the Draw file
  43.  *
  44.  * This function puts a JPEG picture in a Draw file
  45.  *
  46.  * return TRUE when sucessful, otherwise FALSE
  47.  */
  48. BOOL
  49. bSave2Draw(diagram_type *pDiag, FILE *pFile,
  50.     size_t tJpegSize, const imagedata_type *pImg)
  51. {
  52.     unsigned char    *pucJpeg, *pucTmp;
  53.     size_t    tLen;
  54.     int    iByte;
  55.  
  56.     pucJpeg = xmalloc(tJpegSize);
  57.     for (pucTmp = pucJpeg, tLen = 0; tLen < tJpegSize; pucTmp++, tLen++) {
  58.         iByte = iNextByte(pFile);
  59.         if (iByte == EOF) {
  60.             return FALSE;
  61.         }
  62.         *pucTmp = (unsigned char)iByte;
  63.     }
  64.  
  65. #if 0 /* defined(DEBUG) */
  66.     vCopy2File(pucJpeg, tJpegSize);
  67. #endif /* DEBUG */
  68.  
  69.     /* Add the JPEG to the Draw file */
  70.     vImage2Diagram(pDiag, pImg, pucJpeg, tJpegSize);
  71.  
  72.     xfree(pucJpeg);
  73.     return TRUE;
  74. } /* end of bSave2Draw */
  75.  
  76. /*
  77.  * bTranslateJPEG - translate a JPEG picture
  78.  *
  79.  * This function translates a picture from jpeg to sprite
  80.  *
  81.  * return TRUE when sucessful, otherwise FALSE
  82.  */
  83. BOOL
  84. bTranslateJPEG(diagram_type *pDiag, FILE *pFile,
  85.     long lFileOffset, int iPictureLen, const imagedata_type *pImg)
  86. {
  87.       /* seek to start position of JPEG data */
  88.     if (!bSetDataOffset(pFile, lFileOffset)) {
  89.         return FALSE;
  90.     }
  91.  
  92.     if (iGetRiscOsVersion() >= 360) {
  93.         return bSave2Draw(pDiag, pFile, iPictureLen, pImg);
  94.     }
  95.       /* JPEG is not supported until RISC OS 3.6 */
  96.     return bAddDummyImage(pDiag, pImg);
  97. } /* end of bTranslateJPEG */
  98.