Imported from antiword-0.37.tar.gz.
[antiword.git] / jpeg2sprt.c
blob28bd6cdaa9ed456976b439ded66519ace3c61d52
1 /*
2 * jpeg2sprt.c
3 * Copyright (C) 2000-2002 A.J. van Os; Released under GPL
5 * Description:
6 * Functions to translate jpeg pictures into sprites
7 */
9 #include <stdio.h>
10 #include "antiword.h"
12 #if 0 /* defined(DEBUG) */
13 static int iPicCounter = 0;
14 #endif /* DEBUG */
17 #if 0 /* defined(DEBUG) */
18 static void
19 vCopy2File(UCHAR *pucJpeg, size_t tJpegSize)
21 FILE *pOutFile;
22 size_t tIndex;
23 char szFilename[30];
25 sprintf(szFilename, "<Wimp$ScrapDir>.jpeg%04d", ++iPicCounter);
26 pOutFile = fopen(szFilename, "wb");
27 if (pOutFile == NULL) {
28 return;
30 DBG_MSG(szFilename);
31 for (tIndex = 0; tIndex < tJpegSize; tIndex++) {
32 if (putc(pucJpeg[tIndex], pOutFile) == EOF) {
33 break;
36 (void)fclose(pOutFile);
37 vSetFiletype(szFilename, FILETYPE_JPEG);
38 } /* end of vCopy2File */
39 #endif /* DEBUG */
42 * bSave2Draw - save the JPEG picture to the Draw file
44 * This function puts a JPEG picture in a Draw file
46 * return TRUE when sucessful, otherwise FALSE
48 BOOL
49 bSave2Draw(diagram_type *pDiag, FILE *pFile,
50 size_t tJpegSize, const imagedata_type *pImg)
52 UCHAR *pucJpeg, *pucTmp;
53 size_t tLen;
54 int iByte;
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;
62 *pucTmp = (UCHAR)iByte;
65 #if 0 /* defined(DEBUG) */
66 vCopy2File(pucJpeg, tJpegSize);
67 #endif /* DEBUG */
69 /* Add the JPEG to the Draw file */
70 vImage2Diagram(pDiag, pImg, pucJpeg, tJpegSize);
72 xfree(pucJpeg);
73 return TRUE;
74 } /* end of bSave2Draw */
77 * bTranslateJPEG - translate a JPEG picture
79 * This function translates a picture from jpeg to sprite
81 * return TRUE when sucessful, otherwise FALSE
83 BOOL
84 bTranslateJPEG(diagram_type *pDiag, FILE *pFile,
85 ULONG ulFileOffset, size_t tPictureLen, const imagedata_type *pImg)
87 /* Seek to start position of JPEG data */
88 if (!bSetDataOffset(pFile, ulFileOffset)) {
89 return FALSE;
92 if (iGetRiscOsVersion() >= 360) {
93 return bSave2Draw(pDiag, pFile, tPictureLen, pImg);
95 /* JPEG is not supported until RISC OS 3.6 */
96 return bAddDummyImage(pDiag, pImg);
97 } /* end of bTranslateJPEG */