jpeg2eps.c 1.4 KB

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