Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | #ifndef __IMAGEDECODER_H__ |
2 | #define __IMAGEDECODER_H__ |
||
3 | |||
4 | /****************************************************************************** |
||
5 | * FileName: ImageDecoder.h |
||
6 | * Dependencies: project requires File System library |
||
7 | * Processor: PIC24/dsPIC30/dsPIC33/PIC32MX |
||
8 | * Compiler: C30 v2.01/C32 v0.00.18 |
||
9 | * Company: Microchip Technology, Inc. |
||
10 | |||
11 | * Software License Agreement |
||
12 | * |
||
13 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
14 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
15 | * Software only when embedded on a Microchip microcontroller or digital |
||
16 | * signal controller, which is integrated into your product or third party |
||
17 | * product (pursuant to the sublicense terms in the accompanying license |
||
18 | * agreement). |
||
19 | * |
||
20 | * You should refer to the license agreement accompanying this Software |
||
21 | * for additional information regarding your rights and obligations. |
||
22 | * |
||
23 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
24 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
25 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
26 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
27 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
28 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
29 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
30 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
31 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
32 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
33 | * OR OTHER SIMILAR COSTS. |
||
34 | |||
35 | Author Date Comments |
||
36 | -------------------------------------------------------------------------------- |
||
37 | Pradeep Budagutta 03-Mar-2008 First release |
||
38 | *******************************************************************************/ |
||
39 | |||
40 | /* This is used as a common header for all image decoders. |
||
41 | This contains interfaces to sheild the image decoders |
||
42 | from project specific information like reading from |
||
43 | USB drive or from sd card, etc... */ |
||
44 | |||
45 | #include "GenericTypeDefs.h" |
||
46 | #include "stddef.h" |
||
47 | |||
48 | /************* User configuration start *************/ |
||
49 | #include "ImageDecoderConfig.h" |
||
50 | /************* User configuration end *************/ |
||
51 | |||
52 | /********************************************************************* |
||
53 | * Overview: Typedefs of the used File System APIs |
||
54 | *********************************************************************/ |
||
55 | typedef size_t (*FileRead)(void *ptr, size_t size, size_t n, void *stream); |
||
56 | typedef int (*FileSeek)(void *stream, long offset, int whence); |
||
57 | typedef long (*FileTell)(void *fo); |
||
58 | typedef int (*FileFeof)(void *stream); |
||
59 | |||
60 | /********************************************************************* |
||
61 | * Overview: IMG_FileSystemAPI holds function pointers to the used |
||
62 | * File System APIs |
||
63 | *********************************************************************/ |
||
64 | typedef struct _IMG_FILE_SYSTEM_API |
||
65 | { |
||
66 | FileRead pFread; |
||
67 | FileSeek pFseek; |
||
68 | FileTell pFtell; |
||
69 | FileFeof pFeof; |
||
70 | } IMG_FILE_SYSTEM_API; |
||
71 | |||
72 | /********************************************************************* |
||
73 | * Overview: IMG_ImageFileFormat specifies all the supported |
||
74 | * image file formats |
||
75 | *********************************************************************/ |
||
76 | typedef enum _IMG_FILE_FORMAT |
||
77 | { |
||
78 | IMG_NONE = 0, |
||
79 | IMG_BMP, /* Bitmap image */ |
||
80 | IMG_JPEG, /* JPEG image */ |
||
81 | IMG_GIF /* GIF image */ |
||
82 | } IMG_FILE_FORMAT; |
||
83 | |||
84 | /********************************************************************* |
||
85 | * Overview: IMG_PixelRgb holds the RGB information of a pixel in BYTES |
||
86 | *********************************************************************/ |
||
87 | typedef struct _IMG_PIXEL_XY_RGB_888 |
||
88 | { |
||
89 | WORD X; |
||
90 | WORD Y; |
||
91 | BYTE R; |
||
92 | BYTE G; |
||
93 | BYTE B; |
||
94 | } IMG_PIXEL_XY_RGB_888; |
||
95 | |||
96 | /********************************************************************* |
||
97 | * Overview: IMG_PixelOutput is a callback function which receives the |
||
98 | * color information of the output pixel |
||
99 | *********************************************************************/ |
||
100 | typedef void (*IMG_PIXEL_OUTPUT)(IMG_PIXEL_XY_RGB_888 *pPix); |
||
101 | |||
102 | /********************************************************************* |
||
103 | * Overview: IMG_LoopCallback is a callback function which is called |
||
104 | * in every loop of the decoding cycle so that user |
||
105 | * application can do some maintainance activities |
||
106 | *********************************************************************/ |
||
107 | typedef void (*IMG_LOOP_CALLBACK)(void); |
||
108 | |||
109 | /* The global variables which define the image position and size */ |
||
110 | #ifndef __IMAGEDECODER_C__ |
||
111 | extern BYTE IMG_blAbortImageDecoding; |
||
112 | extern WORD IMG_wStartX; |
||
113 | extern WORD IMG_wStartY; |
||
114 | extern WORD IMG_wWidth; |
||
115 | extern WORD IMG_wHeight; |
||
116 | extern WORD IMG_wImageWidth; |
||
117 | extern WORD IMG_wImageHeight; |
||
118 | extern BYTE IMG_bDownScalingFactor; |
||
119 | extern BYTE IMG_bAlignCenter; |
||
120 | |||
121 | #ifndef IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT |
||
122 | extern IMG_PIXEL_OUTPUT IMG_pPixelOutput; |
||
123 | extern IMG_PIXEL_XY_RGB_888 IMG_PixelXYColor; |
||
124 | #endif |
||
125 | |||
126 | #ifndef IMG_USE_ONLY_MDD_FILE_SYSTEM_FOR_INPUT |
||
127 | extern IMG_FILE_SYSTEM_API *IMG_pFileAPIs; |
||
128 | #endif |
||
129 | |||
130 | #ifdef IMG_SUPPORT_IMAGE_DECODER_LOOP_CALLBACK |
||
131 | extern IMG_LOOP_CALLBACK IMG_pLoopCallbackFn; |
||
132 | #endif |
||
133 | #endif |
||
134 | |||
135 | #ifdef IMG_USE_ONLY_MDD_FILE_SYSTEM_FOR_INPUT |
||
136 | |||
137 | #include <MDD File System\FSIO.h> |
||
138 | |||
139 | #define IMG_FILE FSFILE |
||
140 | #define IMG_FREAD FSfread |
||
141 | #define IMG_FSEEK FSfseek |
||
142 | #define IMG_FTELL FSftell |
||
143 | #define IMG_FEOF FSfeof |
||
144 | |||
145 | // added by Paolo 9/10/08 for MultiApp Demo |
||
146 | #define IMG_FOPEN FSfopen |
||
147 | #define IMG_FCLOSE FSfclose |
||
148 | |||
149 | #else |
||
150 | |||
151 | #define IMG_FILE void |
||
152 | #define IMG_FREAD IMG_pFileAPIs->pFread |
||
153 | #define IMG_FSEEK IMG_pFileAPIs->pFseek |
||
154 | #define IMG_FTELL IMG_pFileAPIs->pFtell |
||
155 | #define IMG_FEOF IMG_pFileAPIs->pFeof |
||
156 | |||
157 | #endif |
||
158 | |||
159 | #ifndef __IMAGEDECODER_C__ |
||
160 | |||
161 | extern IMG_FILE *IMG_pCurrentFile; |
||
162 | |||
163 | #endif |
||
164 | |||
165 | /* The individual image decoders use these defines instead of directly using those provided in the Display driver file */ |
||
166 | #define IMG_SCREEN_WIDTH (GetMaxX()+1) |
||
167 | #define IMG_SCREEN_HEIGHT (GetMaxY()+1) |
||
168 | |||
169 | #ifdef IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT |
||
170 | #include "Graphics\Graphics.h" |
||
171 | #define IMG_vSetColor(r, g, b) SetColor(RGB565CONVERT((r), (g), (b))) |
||
172 | #define IMG_vSetColor565(color) SetColor(color) |
||
173 | #define _PutPixel(x, y) PutPixel(x, y) |
||
174 | #else |
||
175 | #define IMG_vSetColor(r, g, b) IMG_PixelXYColor.R = r; IMG_PixelXYColor.G = g; IMG_PixelXYColor.B = b; |
||
176 | #define IMG_vSetColor565(color) IMG_PixelXYColor.R = ((color)>>11)&0x1F; IMG_PixelXYColor.G = ((color)>>5)&0x3F; IMG_PixelXYColor.B = (color)&0x1F; |
||
177 | #define _PutPixel(x, y) if(IMG_pPixelOutput != NULL) { IMG_PixelXYColor.X = x; IMG_PixelXYColor.Y = y; IMG_pPixelOutput(&IMG_PixelXYColor); } |
||
178 | #ifndef RGB565CONVERT |
||
179 | #define RGB565CONVERT(r, g, b) (((r >> 3) << 11) | ((g >> 2) << 5) | (b >> 3)) |
||
180 | #endif |
||
181 | #endif |
||
182 | |||
183 | #define IMG_vPutPixel(x, y) if(IMG_bDownScalingFactor <= 1)\ |
||
184 | { \ |
||
185 | if((x) < IMG_wImageWidth && (y) < IMG_wImageHeight) { _PutPixel(IMG_wStartX + (x), IMG_wStartY + (y)); }\ |
||
186 | } \ |
||
187 | else if((x)%IMG_bDownScalingFactor == 0 && (y)%IMG_bDownScalingFactor == 0) \ |
||
188 | { \ |
||
189 | if((x) < IMG_wImageWidth && (y) < IMG_wImageHeight) { _PutPixel(IMG_wStartX + ((x)/IMG_bDownScalingFactor), IMG_wStartY + ((y)/IMG_bDownScalingFactor)); }\ |
||
190 | } |
||
191 | |||
192 | |||
193 | #ifdef IMG_SUPPORT_IMAGE_DECODER_LOOP_CALLBACK |
||
194 | #define IMG_vLoopCallback() if(IMG_pLoopCallbackFn != NULL) { IMG_pLoopCallbackFn(); } |
||
195 | #else |
||
196 | #define IMG_vLoopCallback() |
||
197 | #endif |
||
198 | |||
199 | #define IMG_DECODE_ABORTED 0xFF |
||
200 | #define IMG_vCheckAndAbort() \ |
||
201 | if(IMG_blAbortImageDecoding == 1) \ |
||
202 | { \ |
||
203 | IMG_blAbortImageDecoding = 0; \ |
||
204 | return IMG_DECODE_ABORTED; \ |
||
205 | } |
||
206 | |||
207 | |||
208 | #ifdef IMG_SUPPORT_BMP |
||
209 | #include "BmpDecoder.h" |
||
210 | #endif |
||
211 | |||
212 | #ifdef IMG_SUPPORT_JPEG |
||
213 | #include "JpegDecoder.h" |
||
214 | #endif |
||
215 | |||
216 | #ifdef IMG_SUPPORT_GIF |
||
217 | #include "GifDecoder.h" |
||
218 | #endif |
||
219 | |||
220 | /* Function prototypes */ |
||
221 | /* User uses only these three functions */ |
||
222 | |||
223 | /********************************************************************* |
||
224 | * Function: void ImageDecoderInit(void) |
||
225 | * |
||
226 | * Overview: This function initializes the global variables to 0 |
||
227 | * and then initializes the driver. |
||
228 | * This must be called once before any other function of |
||
229 | * the library is called |
||
230 | * |
||
231 | * Input: None |
||
232 | * |
||
233 | * Output: None |
||
234 | * |
||
235 | * Example: |
||
236 | * <PRE> |
||
237 | * void main(void) |
||
238 | * { |
||
239 | * ImageInit(); |
||
240 | * ... |
||
241 | * } |
||
242 | * </PRE> |
||
243 | * |
||
244 | * Side Effects: The graphics driver will be reset |
||
245 | * |
||
246 | ********************************************************************/ |
||
247 | void ImageDecoderInit(void); |
||
248 | |||
249 | /********************************************************************* |
||
250 | * Function: void ImageLoopCallbackRegister(IMG_LOOP_CALLBACK pLoopCallbackFn) |
||
251 | * |
||
252 | * Overview: This function registers the loop callback function so that |
||
253 | * the decoder calls this function in every decoding loop. |
||
254 | * This can be used by the application program to do |
||
255 | * maintainance activities such as fetching data, updating |
||
256 | * the display, etc... |
||
257 | * |
||
258 | * Input: pLoopCallbackFn -> Loop callback function pointer |
||
259 | * |
||
260 | * Output: None |
||
261 | * |
||
262 | * Example: |
||
263 | * <PRE> |
||
264 | * void Mainantance(void) |
||
265 | * { |
||
266 | * ... |
||
267 | * } |
||
268 | * |
||
269 | * void main(void) |
||
270 | * { |
||
271 | * ImageInit(); |
||
272 | * ImageLoopCallbackRegister(Mainantance); |
||
273 | * ... |
||
274 | * } |
||
275 | * </PRE> |
||
276 | * |
||
277 | * Side Effects: The graphics driver will be reset |
||
278 | * |
||
279 | ********************************************************************/ |
||
280 | void ImageLoopCallbackRegister(IMG_LOOP_CALLBACK pFn); |
||
281 | |||
282 | /********************************************************************* |
||
283 | * Function: BYTE ImageDecode(IMG_FILE *pImageFile, IMG_FILE_FORMAT eImgFormat, WORD wStartx, WORD wStarty, WORD wWidth, WORD wHeight, WORD wFlags, IMG_FILE_SYSTEM_API *pFileAPIs, IMG_PIXEL_OUTPUT pPixelOutput) |
||
284 | * |
||
285 | * Overview: This function decodes and displays the image on the screen |
||
286 | * |
||
287 | * Input: pImageFile -> The image file pointer |
||
288 | * eImgFormat -> Type of image to be decoded |
||
289 | * wStartx -> Starting x position for the image to be displayed |
||
290 | * wStarty -> Starting y position for the image to be displayed |
||
291 | * wWidth -> The width into which the image to be displayed/compressed |
||
292 | * (This is not the width of the image) |
||
293 | * wHeight -> The height into which the image to be displayed/compressed |
||
294 | * (This is not the height of the image) |
||
295 | * wFlags -> If bit 0 is set, the image would be center aligned into the area |
||
296 | * specified by wStartx, wStarty, wWidth and wHeight |
||
297 | * -> If bit 1 is set, the image would be downscaled if required to fit |
||
298 | * into the area specified by wStartx, wStarty, wWidth |
||
299 | * and wHeight |
||
300 | * pFileAPIs -> The pointer to a structure which has function pointers |
||
301 | * to the File System APIs |
||
302 | * pPixelOutput -> The function to output (x, y) coordinates and the color |
||
303 | * |
||
304 | * Output: Error code -> 0 means no error |
||
305 | * |
||
306 | * Example: |
||
307 | * <PRE> |
||
308 | * void main(void) |
||
309 | * { |
||
310 | * IMG_FILE pImageFile; |
||
311 | * IMG_vInitialize(); |
||
312 | * pImageFile = IMG_FOPEN("Image.jpg", "r"); |
||
313 | * if(pImageFile == NULL) |
||
314 | * { |
||
315 | * <- Error handling -> |
||
316 | * } |
||
317 | * IMG_bDecode(pImageFile, IMG_JPEG, 0, 0, 320, 240, 0, NULL, NULL); |
||
318 | * IMG_FCLOSE(pImageFile); |
||
319 | * while(1); |
||
320 | * } |
||
321 | * </PRE> |
||
322 | * |
||
323 | * Side Effects: None |
||
324 | * |
||
325 | ********************************************************************/ |
||
326 | BYTE ImageDecode(IMG_FILE *pImageFile, IMG_FILE_FORMAT eImgFormat, |
||
327 | WORD wStartx, WORD wStarty, WORD wWidth, WORD wHeight, |
||
328 | WORD wFlags, IMG_FILE_SYSTEM_API *pFileAPIs, |
||
329 | IMG_PIXEL_OUTPUT pPixelOutput); |
||
330 | |||
331 | /* Flags */ |
||
332 | #define IMG_ALIGN_CENTER 0x0001 |
||
333 | #define IMG_DOWN_SCALE 0x0002 |
||
334 | |||
335 | |||
336 | /********************************************************************* |
||
337 | * Function: BYTE ImageFullScreenDecode(IMG_FILE *pImageFile, IMG_FILE_FORMAT eImgFormat, IMG_FILE_SYSTEM_API pFileAPIs, IMG_PIXEL_OUTPUT pPixelOutput) |
||
338 | * |
||
339 | * Overview: This function decodes and displays the image on the screen in |
||
340 | * fullscreen mode with center aligned and downscaled if required |
||
341 | * |
||
342 | * Input: pImageFile -> The image file pointer |
||
343 | * eImgFormat -> Type of image to be decoded |
||
344 | * pFileAPIs -> The pointer to a structure which has function pointers |
||
345 | * to the File System APIs |
||
346 | * pPixelOutput -> The function to output (x, y) coordinates and the color |
||
347 | * |
||
348 | * Output: Error code -> 0 means no error |
||
349 | * |
||
350 | * Example: |
||
351 | * <PRE> |
||
352 | * void main(void) |
||
353 | * { |
||
354 | * IMG_FILE pImageFile; |
||
355 | * IMG_vInitialize(); |
||
356 | * pImageFile = IMG_FOPEN("Image.jpg", "r"); |
||
357 | * if(pImageFile == NULL) |
||
358 | * { |
||
359 | * <- Error handling -> |
||
360 | * } |
||
361 | * IMG_bFullScreenDecode(pImageFile, IMG_JPEG, NULL, NULL); |
||
362 | * IMG_FCLOSE(pImageFile); |
||
363 | * while(1); |
||
364 | * } |
||
365 | * </PRE> |
||
366 | * |
||
367 | * Side Effects: None |
||
368 | * |
||
369 | ********************************************************************/ |
||
370 | #define ImageFullScreenDecode(pImageFile, eImgFormat, pFileAPIs, pPixelOutput) \ |
||
371 | ImageDecode(pImageFile, eImgFormat, 0, 0, IMG_SCREEN_WIDTH, IMG_SCREEN_HEIGHT, (IMG_ALIGN_CENTER | IMG_DOWN_SCALE), pFileAPIs, pPixelOutput) |
||
372 | |||
373 | /********************************************************************* |
||
374 | * Function: BYTE ImageDecodeTask(void) |
||
375 | * |
||
376 | * Overview: This function completes one small part of the image decode function |
||
377 | * |
||
378 | * Input: None |
||
379 | * |
||
380 | * Output: Status code - '1' means decoding is completed |
||
381 | * - '0' means decoding is not yet completed, call this function again |
||
382 | * |
||
383 | * Example: |
||
384 | * <PRE> |
||
385 | * |
||
386 | * IMG_bFullScreenDecode(pImageFile, IMG_JPEG, NULL, NULL); |
||
387 | * while(!ImageDecodeTask()); |
||
388 | * |
||
389 | * </PRE> |
||
390 | * |
||
391 | * Side Effects: None |
||
392 | * |
||
393 | ********************************************************************/ |
||
394 | BYTE ImageDecodeTask(void); |
||
395 | |||
396 | /********************************************************************* |
||
397 | * Function: void ImageAbort(void) |
||
398 | * |
||
399 | * Overview: This function sets the Image Decoder's Abort flag so that |
||
400 | * decoding aborts in the next decoding loop. |
||
401 | * |
||
402 | * Input: None |
||
403 | * |
||
404 | * Output: None |
||
405 | * |
||
406 | * Example: |
||
407 | * <PRE> |
||
408 | * |
||
409 | * void callback(void); |
||
410 | * void main(void) |
||
411 | * { |
||
412 | * IMG_FILE pImageFile; |
||
413 | * IMG_vInitialize(); |
||
414 | * ImageLoopCallbackRegister(callback); |
||
415 | * pImageFile = IMG_FOPEN("Image.jpg", "r"); |
||
416 | * if(pImageFile == NULL) |
||
417 | * { |
||
418 | * <- Error handling -> |
||
419 | * } |
||
420 | * IMG_bFullScreenDecode(pImageFile, IMG_JPEG, NULL, NULL); |
||
421 | * IMG_FCLOSE(pImageFile); |
||
422 | * while(1); |
||
423 | * } |
||
424 | * |
||
425 | * void callback(void) |
||
426 | * { |
||
427 | * if(<- check for abort condition ->) |
||
428 | * { |
||
429 | * ImageAbort(); |
||
430 | * } |
||
431 | * } |
||
432 | * |
||
433 | * </PRE> |
||
434 | * |
||
435 | * Side Effects: None |
||
436 | * |
||
437 | ********************************************************************/ |
||
438 | #define ImageAbort() IMG_blAbortImageDecoding = 1; |
||
439 | |||
440 | /********* This is not for the user *********/ |
||
441 | /* This is used by the individual decoders */ |
||
442 | void IMG_vSetboundaries(void); |
||
443 | /********* This is not for the user *********/ |
||
444 | #endif |
Powered by WebSVN v2.8.3