3 * Copyright (C) 2000-2002 A.J. van Os; Released under GPL
6 * Functions to translate jpeg pictures into sprites
12 #if 0 /* defined(DEBUG) */
13 static int iPicCounter
= 0;
17 #if 0 /* defined(DEBUG) */
19 vCopy2File(UCHAR
*pucJpeg
, size_t tJpegSize
)
25 sprintf(szFilename
, "<Wimp$ScrapDir>.jpeg%04d", ++iPicCounter
);
26 pOutFile
= fopen(szFilename
, "wb");
27 if (pOutFile
== NULL
) {
31 for (tIndex
= 0; tIndex
< tJpegSize
; tIndex
++) {
32 if (putc(pucJpeg
[tIndex
], pOutFile
) == EOF
) {
36 (void)fclose(pOutFile
);
37 vSetFiletype(szFilename
, FILETYPE_JPEG
);
38 } /* end of vCopy2File */
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
49 bSave2Draw(diagram_type
*pDiag
, FILE *pFile
,
50 size_t tJpegSize
, const imagedata_type
*pImg
)
52 UCHAR
*pucJpeg
, *pucTmp
;
56 pucJpeg
= xmalloc(tJpegSize
);
57 for (pucTmp
= pucJpeg
, tLen
= 0; tLen
< tJpegSize
; pucTmp
++, tLen
++) {
58 iByte
= iNextByte(pFile
);
62 *pucTmp
= (UCHAR
)iByte
;
65 #if 0 /* defined(DEBUG) */
66 vCopy2File(pucJpeg
, tJpegSize
);
69 /* Add the JPEG to the Draw file */
70 vImage2Diagram(pDiag
, pImg
, pucJpeg
, tJpegSize
);
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
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
)) {
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 */