Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | #define __IMAGEDECODER_C__ |
2 | /****************************************************************************** |
||
3 | |||
4 | * FileName: ImageDecoder.c |
||
5 | * Dependencies: project requires File System library |
||
6 | * Processor: PIC24/dsPIC30/dsPIC33/PIC32MX |
||
7 | * Compiler: C30 v2.01/C32 v0.00.18 |
||
8 | * Company: Microchip Technology, Inc. |
||
9 | |||
10 | * Software License Agreement |
||
11 | * |
||
12 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
13 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
14 | * Software only when embedded on a Microchip microcontroller or digital |
||
15 | * signal controller, which is integrated into your product or third party |
||
16 | * product (pursuant to the sublicense terms in the accompanying license |
||
17 | * agreement). |
||
18 | * |
||
19 | * You should refer to the license agreement accompanying this Software |
||
20 | * for additional information regarding your rights and obligations. |
||
21 | * |
||
22 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
23 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
24 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
25 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
26 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
27 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
28 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
29 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
30 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
31 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
32 | * OR OTHER SIMILAR COSTS. |
||
33 | |||
34 | Author Date Comments |
||
35 | -------------------------------------------------------------------------------- |
||
36 | Pradeep Budagutta 03-Mar-2008 First release |
||
37 | *******************************************************************************/ |
||
38 | |||
39 | /* This is used as a common header for all image decoders. |
||
40 | This contains interfaces to sheild the image decoders |
||
41 | from project specific information like reading from |
||
42 | USB drive or from sd card, etc... */ |
||
43 | |||
44 | #include "Image Decoders\ImageDecoder.h" |
||
45 | |||
46 | /**************************/ |
||
47 | /**** GLOBAL VARIABLES ****/ |
||
48 | /**************************/ |
||
49 | |||
50 | IMG_FILE *IMG_pCurrentFile; |
||
51 | |||
52 | WORD IMG_wStartX; |
||
53 | WORD IMG_wStartY; |
||
54 | WORD IMG_wWidth; |
||
55 | WORD IMG_wHeight; |
||
56 | WORD IMG_wImageWidth; |
||
57 | WORD IMG_wImageHeight; |
||
58 | BYTE IMG_bDownScalingFactor; |
||
59 | BYTE IMG_bAlignCenter; |
||
60 | BYTE IMG_blAbortImageDecoding; |
||
61 | |||
62 | #ifndef IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT |
||
63 | IMG_PIXEL_OUTPUT IMG_pPixelOutput; |
||
64 | IMG_PIXEL_XY_RGB_888 IMG_PixelXYColor; |
||
65 | #endif |
||
66 | |||
67 | #ifndef IMG_USE_ONLY_MDD_FILE_SYSTEM_FOR_INPUT |
||
68 | IMG_FILE_SYSTEM_API *IMG_pFileAPIs; |
||
69 | #endif |
||
70 | |||
71 | #ifdef IMG_SUPPORT_IMAGE_DECODER_LOOP_CALLBACK |
||
72 | IMG_LOOP_CALLBACK IMG_pLoopCallbackFn; |
||
73 | #endif |
||
74 | |||
75 | /**************************/ |
||
76 | /******************************************************************************* |
||
77 | Function: void ImageDecoderInit(void) |
||
78 | |||
79 | Precondition: None |
||
80 | |||
81 | Overview: This function resets the variables and initializes the display |
||
82 | |||
83 | Input: None |
||
84 | |||
85 | Output: None |
||
86 | *******************************************************************************/ |
||
87 | void ImageDecoderInit(void) |
||
88 | { |
||
89 | IMG_wStartX = 0; |
||
90 | IMG_wStartY = 0; |
||
91 | IMG_wWidth = 0; |
||
92 | IMG_wHeight = 0; |
||
93 | IMG_wImageWidth = 0; |
||
94 | IMG_wImageHeight = 0; |
||
95 | |||
96 | #ifndef IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT |
||
97 | IMG_pPixelOutput = NULL; |
||
98 | IMG_PixelXYColor.X = 0; |
||
99 | IMG_PixelXYColor.Y = 0; |
||
100 | IMG_PixelXYColor.R = 0; |
||
101 | IMG_PixelXYColor.G = 0; |
||
102 | IMG_PixelXYColor.B = 0; |
||
103 | #endif |
||
104 | |||
105 | #ifndef IMG_USE_ONLY_MDD_FILE_SYSTEM_FOR_INPUT |
||
106 | IMG_pFileAPIs = NULL; |
||
107 | #endif |
||
108 | |||
109 | #ifdef IMG_SUPPORT_IMAGE_DECODER_LOOP_CALLBACK |
||
110 | IMG_pLoopCallbackFn = NULL; |
||
111 | #endif |
||
112 | IMG_blAbortImageDecoding = 0; |
||
113 | |||
114 | #ifdef IMG_USE_NON_BLOCKING_DECODING |
||
115 | IMG_pCurrentFile = NULL; |
||
116 | #endif |
||
117 | } |
||
118 | |||
119 | /******************************************************************************* |
||
120 | Function: void ImageLoopCallbackRegister(IMG_LOOP_CALLBACK pLoopCallbackFn) |
||
121 | |||
122 | Precondition: None |
||
123 | |||
124 | Overview: This function registers the loop callback function |
||
125 | |||
126 | Input: Loop callback function pointer |
||
127 | |||
128 | Output: None |
||
129 | *******************************************************************************/ |
||
130 | void ImageLoopCallbackRegister(IMG_LOOP_CALLBACK pLoopCallbackFn) |
||
131 | { |
||
132 | #ifdef IMG_SUPPORT_IMAGE_DECODER_LOOP_CALLBACK |
||
133 | IMG_pLoopCallbackFn = pLoopCallbackFn; |
||
134 | #endif |
||
135 | } |
||
136 | |||
137 | /******************************************************************************* |
||
138 | 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) |
||
139 | |||
140 | Precondition: None |
||
141 | |||
142 | Overview: This function uses the approperiate image decoding function to |
||
143 | decode and display the image |
||
144 | |||
145 | Input: File pointer, Kind of image, Image position and boundaries, If center alignment and downscaling to fit into the display is required, File System API pointer and function to output the decoded pixels |
||
146 | |||
147 | Output: Error code - '0' means no error |
||
148 | *******************************************************************************/ |
||
149 | BYTE ImageDecode(IMG_FILE *pImageFile, IMG_FILE_FORMAT eImgFormat, |
||
150 | WORD wStartx, WORD wStarty, WORD wWidth, WORD wHeight, |
||
151 | WORD wFlags, IMG_FILE_SYSTEM_API *pFileAPIs, |
||
152 | IMG_PIXEL_OUTPUT pPixelOutput) |
||
153 | { |
||
154 | BYTE bRetVal = 0; |
||
155 | |||
156 | IMG_wStartX = wStartx; |
||
157 | IMG_wStartY = wStarty; |
||
158 | IMG_wWidth = wWidth; |
||
159 | IMG_wHeight = wHeight; |
||
160 | IMG_wImageWidth = 0; |
||
161 | IMG_wImageHeight = 0; |
||
162 | |||
163 | IMG_bDownScalingFactor = (wFlags & IMG_DOWN_SCALE)? 1: 0; |
||
164 | IMG_bAlignCenter = (wFlags & IMG_ALIGN_CENTER)? 1: 0; |
||
165 | |||
166 | #ifndef IMG_USE_ONLY_565_GRAPHICS_DRIVER_FOR_OUTPUT |
||
167 | IMG_pPixelOutput = pPixelOutput; |
||
168 | #endif |
||
169 | |||
170 | #ifndef IMG_USE_ONLY_MDD_FILE_SYSTEM_FOR_INPUT |
||
171 | IMG_pFileAPIs = pFileAPIs; |
||
172 | #endif |
||
173 | |||
174 | switch(eImgFormat) |
||
175 | { |
||
176 | #ifdef IMG_SUPPORT_BMP |
||
177 | case IMG_BMP: bRetVal = BMP_bDecode(pImageFile); |
||
178 | break; |
||
179 | #endif |
||
180 | #ifdef IMG_SUPPORT_JPEG |
||
181 | case IMG_JPEG: bRetVal = JPEG_bDecode(pImageFile, TRUE); |
||
182 | IMG_pCurrentFile = pImageFile; |
||
183 | break; |
||
184 | #endif |
||
185 | #ifdef IMG_SUPPORT_GIF |
||
186 | case IMG_GIF: bRetVal = GIF_bDecode(pImageFile); |
||
187 | break; |
||
188 | #endif |
||
189 | default: bRetVal = 0xFF; |
||
190 | } |
||
191 | |||
192 | return(bRetVal); |
||
193 | } |
||
194 | |||
195 | |||
196 | /******************************************************************************* |
||
197 | Function: BYTE ImageDecodeTask(void) |
||
198 | |||
199 | Precondition: ImageDecode() must have been called |
||
200 | |||
201 | Overview: This function completes one small part of the image decode function |
||
202 | |||
203 | Input: None |
||
204 | |||
205 | Output: Status code - '1' means decoding is completed |
||
206 | - '0' means decoding is not yet completed, call this function again |
||
207 | *******************************************************************************/ |
||
208 | BYTE ImageDecodeTask(void) |
||
209 | { |
||
210 | #ifdef IMG_USE_NON_BLOCKING_DECODING |
||
211 | { |
||
212 | if(IMG_pCurrentFile != NULL) // At present, supports only JPEG |
||
213 | { |
||
214 | return JPEG_bDecode(IMG_pCurrentFile, FALSE); |
||
215 | } |
||
216 | } |
||
217 | #endif |
||
218 | |||
219 | return 1; |
||
220 | } |
||
221 | |||
222 | |||
223 | /******************************************************************************* |
||
224 | Function: BYTE IMG_vSetboundaries(void) |
||
225 | |||
226 | Precondition: None |
||
227 | |||
228 | Overview: This function sets the boundaries and scaling factor. THIS IS |
||
229 | NOT FOR THE USER. |
||
230 | |||
231 | Input: None |
||
232 | |||
233 | Output: None |
||
234 | *******************************************************************************/ |
||
235 | void IMG_vSetboundaries(void) |
||
236 | { |
||
237 | if(IMG_bDownScalingFactor > 0) |
||
238 | { |
||
239 | WORD wXScalingFactor = IMG_wImageWidth / IMG_wWidth; |
||
240 | WORD wYScalingFactor = IMG_wImageHeight / IMG_wHeight; |
||
241 | |||
242 | if(wXScalingFactor * IMG_wWidth < IMG_wImageWidth) |
||
243 | { |
||
244 | wXScalingFactor++; |
||
245 | } |
||
246 | if(wYScalingFactor * IMG_wHeight < IMG_wImageHeight) |
||
247 | { |
||
248 | wYScalingFactor++; |
||
249 | } |
||
250 | |||
251 | IMG_bDownScalingFactor = (BYTE)(wXScalingFactor > wYScalingFactor)? wXScalingFactor: wYScalingFactor; |
||
252 | |||
253 | if(IMG_bDownScalingFactor <= 1) |
||
254 | { |
||
255 | IMG_bDownScalingFactor = 0; |
||
256 | } |
||
257 | } |
||
258 | |||
259 | if(IMG_bAlignCenter > 0) |
||
260 | { |
||
261 | BYTE bDownScalingFactor = (IMG_bDownScalingFactor <= 1)? 1: IMG_bDownScalingFactor; |
||
262 | if(IMG_wWidth > (IMG_wImageWidth / bDownScalingFactor)) |
||
263 | { |
||
264 | IMG_wStartX += (IMG_wWidth - (IMG_wImageWidth / bDownScalingFactor)) / 2; |
||
265 | } |
||
266 | if(IMG_wHeight > (IMG_wImageHeight / bDownScalingFactor)) |
||
267 | { |
||
268 | IMG_wStartY += (IMG_wHeight - (IMG_wImageHeight / bDownScalingFactor)) / 2; |
||
269 | } |
||
270 | } |
||
271 | } |
||
272 | |||
273 | #undef __IMAGEDECODER_C__ |
Powered by WebSVN v2.8.3