Line No. | Rev | Author | Line |
---|---|---|---|
1 | 32 | kaklik | /***************************************************************************** |
2 | * Module for Microchip Graphics Library |
||
3 | * Densitron HIT1270 controller driver |
||
4 | * Landscape orientation |
||
5 | ***************************************************************************** |
||
6 | * FileName: HIT1270.c |
||
7 | * Dependencies: Graphics.h |
||
8 | * Processor: PIC24 |
||
9 | * Compiler: MPLAB C30 |
||
10 | * Linker: MPLAB LINK30 |
||
11 | * Company: Microchip Technology Incorporated |
||
12 | * |
||
13 | * Software License Agreement |
||
14 | * |
||
15 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
16 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
17 | * Software only when embedded on a Microchip microcontroller or digital |
||
18 | * signal controller, which is integrated into your product or third party |
||
19 | * product (pursuant to the sublicense terms in the accompanying license |
||
20 | * agreement). |
||
21 | * |
||
22 | * You should refer to the license agreement accompanying this Software |
||
23 | * for additional information regarding your rights and obligations. |
||
24 | * |
||
25 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
26 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
27 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
28 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
29 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
30 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
31 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
32 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
33 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
34 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
35 | * OR OTHER SIMILAR COSTS. |
||
36 | * |
||
37 | * Author Date Comment |
||
38 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
39 | * Anton Alkhimenok 11/12/07 Version 1.0 release |
||
40 | *****************************************************************************/ |
||
41 | #include "Graphics\Graphics.h" |
||
42 | |||
43 | // Color |
||
44 | WORD_VAL _color; |
||
45 | |||
46 | // Clipping region control |
||
47 | SHORT _clipRgn; |
||
48 | |||
49 | // Clipping region borders |
||
50 | SHORT _clipLeft; |
||
51 | SHORT _clipTop; |
||
52 | SHORT _clipRight; |
||
53 | SHORT _clipBottom; |
||
54 | |||
55 | /////////////////////// LOCAL FUNCTIONS PROTOTYPES //////////////////////////// |
||
56 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
57 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
58 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
59 | void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch); |
||
60 | |||
61 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
62 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
63 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
64 | void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch); |
||
65 | |||
66 | |||
67 | /********************************************************************* |
||
68 | * Function: SetAddress(addr2,addr1,addr0) |
||
69 | * |
||
70 | * PreCondition: none |
||
71 | * |
||
72 | * Input: addr0,addr1,addr2 - address bytes |
||
73 | * |
||
74 | * Output: none |
||
75 | * |
||
76 | * Side Effects: none |
||
77 | * |
||
78 | * Overview: writes S6D0129 address pointer |
||
79 | * |
||
80 | * Note: none |
||
81 | * |
||
82 | ********************************************************************/ |
||
83 | inline void SetAddress(DWORD address) |
||
84 | { |
||
85 | DeviceSetCommand(); |
||
86 | DeviceWrite(SET_DATA_POINTER); |
||
87 | DeviceSetData(); |
||
88 | DeviceWrite(((DWORD_VAL)address).v[0]); |
||
89 | DeviceWrite(((DWORD_VAL)address).v[1]); |
||
90 | DeviceWrite(((DWORD_VAL)address).v[2]); |
||
91 | } |
||
92 | |||
93 | /********************************************************************* |
||
94 | * Function: void ResetDevice() |
||
95 | * |
||
96 | * PreCondition: none |
||
97 | * |
||
98 | * Input: none |
||
99 | * |
||
100 | * Output: none |
||
101 | * |
||
102 | * Side Effects: none |
||
103 | * |
||
104 | * Overview: resets LCD, initializes PMP |
||
105 | * |
||
106 | * Note: none |
||
107 | * |
||
108 | ********************************************************************/ |
||
109 | void ResetDevice(void) |
||
110 | { |
||
111 | // Initialize the device |
||
112 | DeviceInit(); |
||
113 | |||
114 | // Enable LCD |
||
115 | DeviceSelect(); |
||
116 | |||
117 | DelayMs(10); |
||
118 | |||
119 | // Clear text layer |
||
120 | SetAddress(0); |
||
121 | for(counter = 0; counter < 0x4b0; counter++) |
||
122 | { |
||
123 | DeviceWrite(0x07); |
||
124 | DeviceWrite(0x07); |
||
125 | } |
||
126 | |||
127 | // Disable LCD |
||
128 | DeviceDeselect(); |
||
129 | |||
130 | DelayMs(20); |
||
131 | } |
||
132 | |||
133 | /********************************************************************* |
||
134 | * Function: void SetColor(WORD color) |
||
135 | * |
||
136 | * PreCondition: none |
||
137 | * |
||
138 | * Input: color coded in format: |
||
139 | * bits 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 |
||
140 | * color R R R R R G G G G G G B B B B B |
||
141 | * |
||
142 | * Output: none |
||
143 | * |
||
144 | * Side Effects: none |
||
145 | * |
||
146 | * Overview: sets current color |
||
147 | * |
||
148 | * Note: none |
||
149 | * |
||
150 | ********************************************************************/ |
||
151 | void SetColor(WORD color) |
||
152 | { |
||
153 | _color.v[0] = ((WORD_VAL) color).v[0] & 0x1c; |
||
154 | _color.v[1] = (((WORD_VAL) color).v[1] >> 1) & 0x73; |
||
155 | } |
||
156 | |||
157 | /********************************************************************* |
||
158 | * Function: void PutPixel(SHORT x, SHORT y) |
||
159 | * |
||
160 | * PreCondition: none |
||
161 | * |
||
162 | * Input: x,y - pixel coordinates |
||
163 | * |
||
164 | * Output: none |
||
165 | * |
||
166 | * Side Effects: none |
||
167 | * |
||
168 | * Overview: puts pixel |
||
169 | * |
||
170 | * Note: none |
||
171 | * |
||
172 | ********************************************************************/ |
||
173 | void PutPixel(SHORT x, SHORT y) |
||
174 | { |
||
175 | DWORD address; |
||
176 | if(_clipRgn) |
||
177 | { |
||
178 | if(x < _clipLeft) |
||
179 | return; |
||
180 | if(x > _clipRight) |
||
181 | return; |
||
182 | if(y < _clipTop) |
||
183 | return; |
||
184 | if(y > _clipBottom) |
||
185 | return; |
||
186 | } |
||
187 | |||
188 | DeviceSelect(); |
||
189 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * y + x; |
||
190 | SetAddress(address); |
||
191 | DeviceWrite(_color.v[0]); |
||
192 | DeviceWrite(_color.v[1]); |
||
193 | DeviceDeselect(); |
||
194 | } |
||
195 | |||
196 | /********************************************************************* |
||
197 | * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) |
||
198 | * |
||
199 | * PreCondition: none |
||
200 | * |
||
201 | * Input: left,top - top left corner coordinates, |
||
202 | * right,bottom - bottom right corner coordinates |
||
203 | * |
||
204 | * Output: For NON-Blocking configuration: |
||
205 | * - Returns 0 when device is busy and the shape is not yet completely drawn. |
||
206 | * - Returns 1 when the shape is completely drawn. |
||
207 | * For Blocking configuration: |
||
208 | * - Always return 1. |
||
209 | * |
||
210 | * Side Effects: none |
||
211 | * |
||
212 | * Overview: draws rectangle filled with current color |
||
213 | * |
||
214 | * Note: none |
||
215 | * |
||
216 | ********************************************************************/ |
||
217 | WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) |
||
218 | { |
||
219 | DWORD address; |
||
220 | register SHORT x, y; |
||
221 | |||
222 | #ifndef USE_NONBLOCKING_CONFIG |
||
223 | while(IsDeviceBusy() != 0); |
||
224 | |||
225 | /* Ready */ |
||
226 | #else |
||
227 | if(IsDeviceBusy() != 0) |
||
228 | return (0); |
||
229 | #endif |
||
230 | if(_clipRgn) |
||
231 | { |
||
232 | if(left < _clipLeft) |
||
233 | left = _clipLeft; |
||
234 | if(right > _clipRight) |
||
235 | right = _clipRight; |
||
236 | if(top < _clipTop) |
||
237 | top = _clipTop; |
||
238 | if(bottom > _clipBottom) |
||
239 | bottom = _clipBottom; |
||
240 | } |
||
241 | |||
242 | address = BUF_MEM_OFFSET + (DWORD) LINE_MEM_PITCH * top + left; |
||
243 | |||
244 | DeviceSelect(); |
||
245 | |||
246 | for(y = top; y < bottom + 1; y++) |
||
247 | { |
||
248 | SetAddress(address); |
||
249 | for(x = left; x < right + 1; x++) |
||
250 | { |
||
251 | DeviceWrite(_color.v[1]); |
||
252 | DeviceWrite(_color.v[0]); |
||
253 | } |
||
254 | |||
255 | address += LINE_MEM_PITCH; |
||
256 | } |
||
257 | |||
258 | DeviceDeselect(); |
||
259 | return (1); |
||
260 | } |
||
261 | |||
262 | /********************************************************************* |
||
263 | * Function: void ClearDevice(void) |
||
264 | * |
||
265 | * PreCondition: none |
||
266 | * |
||
267 | * Input: none |
||
268 | * |
||
269 | * Output: none |
||
270 | * |
||
271 | * Side Effects: none |
||
272 | * |
||
273 | * Overview: clears screen with current color |
||
274 | * |
||
275 | * Note: none |
||
276 | * |
||
277 | ********************************************************************/ |
||
278 | void ClearDevice(void) |
||
279 | { |
||
280 | DWORD counter; |
||
281 | |||
282 | DeviceSelect(); |
||
283 | SetAddress(0x018000); |
||
284 | for(counter = 0; counter < (DWORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++) |
||
285 | { |
||
286 | DeviceWrite(_color.v[1]); |
||
287 | DeviceWrite(_color.v[0]); |
||
288 | } |
||
289 | |||
290 | DeviceDeselect(); |
||
291 | MoveTo(0, 0); |
||
292 | } |
||
293 | |||
294 | /********************************************************************* |
||
295 | * Function: WORD PutImage(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
296 | * |
||
297 | * PreCondition: none |
||
298 | * |
||
299 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
300 | * stretch - image stretch factor |
||
301 | * |
||
302 | * Output: For NON-Blocking configuration: |
||
303 | * - Returns 0 when device is busy and the image is not yet completely drawn. |
||
304 | * - Returns 1 when the image is completely drawn. |
||
305 | * For Blocking configuration: |
||
306 | * - Always return 1. |
||
307 | * |
||
308 | * Side Effects: none |
||
309 | * |
||
310 | * Overview: outputs image starting from left,top coordinates |
||
311 | * |
||
312 | * Note: image must be located in flash |
||
313 | * |
||
314 | ********************************************************************/ |
||
315 | WORD PutImage(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
316 | { |
||
317 | FLASH_BYTE *flashAddress; |
||
318 | BYTE colorDepth; |
||
319 | WORD colorTemp; |
||
320 | |||
321 | #ifndef USE_NONBLOCKING_CONFIG |
||
322 | while(IsDeviceBusy() != 0); |
||
323 | |||
324 | /* Ready */ |
||
325 | #else |
||
326 | if(IsDeviceBusy() != 0) |
||
327 | return (0); |
||
328 | #endif |
||
329 | |||
330 | // Save current color |
||
331 | colorTemp = _color.Val; |
||
332 | |||
333 | switch(*((SHORT *)bitmap)) |
||
334 | { |
||
335 | #ifdef USE_BITMAP_FLASH |
||
336 | |||
337 | case FLASH: |
||
338 | |||
339 | // Image address |
||
340 | flashAddress = ((BITMAP_FLASH *)bitmap)->address; |
||
341 | |||
342 | // Read color depth |
||
343 | colorDepth = *(flashAddress + 1); |
||
344 | |||
345 | // Draw picture |
||
346 | switch(colorDepth) |
||
347 | { |
||
348 | case 1: PutImage1BPP(left, top, flashAddress, stretch); break; |
||
349 | case 4: PutImage4BPP(left, top, flashAddress, stretch); break; |
||
350 | case 8: PutImage8BPP(left, top, flashAddress, stretch); break; |
||
351 | case 16: PutImage16BPP(left, top, flashAddress, stretch); break; |
||
352 | } |
||
353 | |||
354 | break; |
||
355 | #endif |
||
356 | #ifdef USE_BITMAP_EXTERNAL |
||
357 | |||
358 | case EXTERNAL: |
||
359 | |||
360 | // Get color depth |
||
361 | ExternalMemoryCallback(bitmap, 1, 1, &colorDepth); |
||
362 | |||
363 | // Draw picture |
||
364 | switch(colorDepth) |
||
365 | { |
||
366 | case 1: PutImage1BPPExt(left, top, bitmap, stretch); break; |
||
367 | case 4: PutImage4BPPExt(left, top, bitmap, stretch); break; |
||
368 | case 8: PutImage8BPPExt(left, top, bitmap, stretch); break; |
||
369 | case 16: PutImage16BPPExt(left, top, bitmap, stretch); break; |
||
370 | default: break; |
||
371 | } |
||
372 | |||
373 | break; |
||
374 | #endif |
||
375 | |||
376 | default: |
||
377 | break; |
||
378 | } |
||
379 | |||
380 | // Restore current color |
||
381 | _color.Val = colorTemp; |
||
382 | return (1); |
||
383 | } |
||
384 | |||
385 | #ifdef USE_BITMAP_FLASH |
||
386 | |||
387 | /********************************************************************* |
||
388 | * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
389 | * |
||
390 | * PreCondition: none |
||
391 | * |
||
392 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
393 | * stretch - image stretch factor |
||
394 | * |
||
395 | * Output: none |
||
396 | * |
||
397 | * Side Effects: none |
||
398 | * |
||
399 | * Overview: outputs monochrome image starting from left,top coordinates |
||
400 | * |
||
401 | * Note: image must be located in flash |
||
402 | * |
||
403 | ********************************************************************/ |
||
404 | void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
405 | { |
||
406 | register FLASH_BYTE *flashAddress; |
||
407 | register FLASH_BYTE *tempFlashAddress; |
||
408 | register DWORD address; |
||
409 | BYTE temp; |
||
410 | register WORD sizeX, sizeY; |
||
411 | WORD x, y; |
||
412 | register BYTE stretchX, stretchY; |
||
413 | WORD pallete[2]; |
||
414 | BYTE mask; |
||
415 | |||
416 | // Move pointer to size information |
||
417 | flashAddress = bitmap + 2; |
||
418 | |||
419 | // Set start address |
||
420 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
421 | |||
422 | // Read image size |
||
423 | sizeY = *((FLASH_WORD *)flashAddress); |
||
424 | flashAddress += 2; |
||
425 | sizeX = *((FLASH_WORD *)flashAddress); |
||
426 | flashAddress += 2; |
||
427 | pallete[0] = *((FLASH_WORD *)flashAddress); |
||
428 | flashAddress += 2; |
||
429 | pallete[1] = *((FLASH_WORD *)flashAddress); |
||
430 | flashAddress += 2; |
||
431 | |||
432 | for(y = 0; y < sizeY; y++) |
||
433 | { |
||
434 | tempFlashAddress = flashAddress; |
||
435 | DeviceSelect(); |
||
436 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
437 | { |
||
438 | flashAddress = tempFlashAddress; |
||
439 | SetAddress(address); |
||
440 | mask = 0; |
||
441 | for(x = 0; x < sizeX; x++) |
||
442 | { |
||
443 | |||
444 | // Read 8 pixels from flash |
||
445 | if(mask == 0) |
||
446 | { |
||
447 | temp = *flashAddress; |
||
448 | flashAddress++; |
||
449 | mask = 0x80; |
||
450 | } |
||
451 | |||
452 | // Set color |
||
453 | if(mask & temp) |
||
454 | { |
||
455 | SetColor(pallete[1]); |
||
456 | } |
||
457 | else |
||
458 | { |
||
459 | SetColor(pallete[0]); |
||
460 | } |
||
461 | |||
462 | // Write pixel to screen |
||
463 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
464 | { |
||
465 | DeviceWrite(_color.v[1]); |
||
466 | DeviceWrite(_color.v[0]); |
||
467 | } |
||
468 | |||
469 | // Shift to the next pixel |
||
470 | mask >>= 1; |
||
471 | } |
||
472 | |||
473 | address += LINE_MEM_PITCH; |
||
474 | } |
||
475 | } |
||
476 | |||
477 | DeviceDeselect(); |
||
478 | } |
||
479 | |||
480 | /********************************************************************* |
||
481 | * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
482 | * |
||
483 | * PreCondition: none |
||
484 | * |
||
485 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
486 | * stretch - image stretch factor |
||
487 | * |
||
488 | * Output: none |
||
489 | * |
||
490 | * Side Effects: none |
||
491 | * |
||
492 | * Overview: outputs 16 color image starting from left,top coordinates |
||
493 | * |
||
494 | * Note: image must be located in flash |
||
495 | * |
||
496 | ********************************************************************/ |
||
497 | void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
498 | { |
||
499 | register DWORD address; |
||
500 | register FLASH_BYTE *flashAddress; |
||
501 | register FLASH_BYTE *tempFlashAddress; |
||
502 | WORD sizeX, sizeY; |
||
503 | register WORD x, y; |
||
504 | BYTE temp; |
||
505 | register BYTE stretchX, stretchY; |
||
506 | WORD pallete[16]; |
||
507 | WORD counter; |
||
508 | |||
509 | // Move pointer to size information |
||
510 | flashAddress = bitmap + 2; |
||
511 | |||
512 | // Set start address |
||
513 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
514 | |||
515 | // Read image size |
||
516 | sizeY = *((FLASH_WORD *)flashAddress); |
||
517 | flashAddress += 2; |
||
518 | sizeX = *((FLASH_WORD *)flashAddress); |
||
519 | flashAddress += 2; |
||
520 | |||
521 | // Read pallete |
||
522 | for(counter = 0; counter < 16; counter++) |
||
523 | { |
||
524 | pallete[counter] = *((FLASH_WORD *)flashAddress); |
||
525 | flashAddress += 2; |
||
526 | } |
||
527 | |||
528 | |||
529 | for(y = 0; y < sizeY; y++) |
||
530 | { |
||
531 | tempFlashAddress = flashAddress; |
||
532 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
533 | { |
||
534 | DeviceSelect(); |
||
535 | flashAddress = tempFlashAddress; |
||
536 | SetAddress(address); |
||
537 | for(x = 0; x < sizeX; x++) |
||
538 | { |
||
539 | |||
540 | // Read 2 pixels from flash |
||
541 | if((x & 0x0001) == 0) |
||
542 | { |
||
543 | temp = *flashAddress; |
||
544 | flashAddress++; |
||
545 | } |
||
546 | |||
547 | // Set color |
||
548 | SetColor(pallete[temp & 0x0f]); |
||
549 | |||
550 | // Write pixel to screen |
||
551 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
552 | { |
||
553 | DeviceWrite(_color.v[1]); |
||
554 | DeviceWrite(_color.v[0]); |
||
555 | } |
||
556 | |||
557 | // Shift to the next pixel |
||
558 | temp >>= 4; |
||
559 | } |
||
560 | |||
561 | address += LINE_MEM_PITCH; |
||
562 | DeviceDeselect(); |
||
563 | } |
||
564 | } |
||
565 | |||
566 | |||
567 | } |
||
568 | |||
569 | /********************************************************************* |
||
570 | * Function: void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
571 | * |
||
572 | * PreCondition: none |
||
573 | * |
||
574 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
575 | * stretch - image stretch factor |
||
576 | * |
||
577 | * Output: none |
||
578 | * |
||
579 | * Side Effects: none |
||
580 | * |
||
581 | * Overview: outputs 256 color image starting from left,top coordinates |
||
582 | * |
||
583 | * Note: image must be located in flash |
||
584 | * |
||
585 | ********************************************************************/ |
||
586 | void PutImage8BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
587 | { |
||
588 | register DWORD address; |
||
589 | register FLASH_BYTE *flashAddress; |
||
590 | register FLASH_BYTE *tempFlashAddress; |
||
591 | WORD sizeX, sizeY; |
||
592 | register WORD x, y; |
||
593 | BYTE temp; |
||
594 | register BYTE stretchX, stretchY; |
||
595 | WORD pallete[256]; |
||
596 | WORD counter; |
||
597 | |||
598 | // Move pointer to size information |
||
599 | flashAddress = bitmap + 2; |
||
600 | |||
601 | // Set start address |
||
602 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
603 | |||
604 | // Read image size |
||
605 | sizeY = *((FLASH_WORD *)flashAddress); |
||
606 | flashAddress += 2; |
||
607 | sizeX = *((FLASH_WORD *)flashAddress); |
||
608 | flashAddress += 2; |
||
609 | |||
610 | // Read pallete |
||
611 | for(counter = 0; counter < 256; counter++) |
||
612 | { |
||
613 | pallete[counter] = *((FLASH_WORD *)flashAddress); |
||
614 | flashAddress += 2; |
||
615 | } |
||
616 | |||
617 | DeviceSelect(); |
||
618 | for(y = 0; y < sizeY; y++) |
||
619 | { |
||
620 | tempFlashAddress = flashAddress; |
||
621 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
622 | { |
||
623 | flashAddress = tempFlashAddress; |
||
624 | SetAddress(address); |
||
625 | for(x = 0; x < sizeX; x++) |
||
626 | { |
||
627 | |||
628 | // Read pixels from flash |
||
629 | temp = *flashAddress; |
||
630 | flashAddress++; |
||
631 | |||
632 | // Set color |
||
633 | SetColor(pallete[temp]); |
||
634 | |||
635 | // Write pixel to screen |
||
636 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
637 | { |
||
638 | DeviceWrite(_color.v[1]); |
||
639 | DeviceWrite(_color.v[0]); |
||
640 | } |
||
641 | } |
||
642 | |||
643 | address += LINE_MEM_PITCH; |
||
644 | } |
||
645 | } |
||
646 | |||
647 | DeviceDeselect(); |
||
648 | } |
||
649 | |||
650 | /********************************************************************* |
||
651 | * Function: void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) |
||
652 | * |
||
653 | * PreCondition: none |
||
654 | * |
||
655 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
656 | * stretch - image stretch factor |
||
657 | * |
||
658 | * Output: none |
||
659 | * |
||
660 | * Side Effects: none |
||
661 | * |
||
662 | * Overview: outputs hicolor image starting from left,top coordinates |
||
663 | * |
||
664 | * Note: image must be located in flash |
||
665 | * |
||
666 | ********************************************************************/ |
||
667 | void PutImage16BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) |
||
668 | { |
||
669 | register DWORD address; |
||
670 | register FLASH_WORD *flashAddress; |
||
671 | register FLASH_WORD *tempFlashAddress; |
||
672 | WORD sizeX, sizeY; |
||
673 | register WORD x, y; |
||
674 | WORD temp; |
||
675 | register BYTE stretchX, stretchY; |
||
676 | |||
677 | // Move pointer to size information |
||
678 | flashAddress = (FLASH_WORD *)bitmap + 1; |
||
679 | |||
680 | // Set start address |
||
681 | address.Val = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
682 | |||
683 | // Read image size |
||
684 | sizeY = *flashAddress; |
||
685 | flashAddress++; |
||
686 | sizeX = *flashAddress; |
||
687 | flashAddress++; |
||
688 | |||
689 | DeviceSelect(); |
||
690 | for(y = 0; y < sizeY; y++) |
||
691 | { |
||
692 | tempFlashAddress = flashAddress; |
||
693 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
694 | { |
||
695 | flashAddress = tempFlashAddress; |
||
696 | SetAddress(address); |
||
697 | for(x = 0; x < sizeX; x++) |
||
698 | { |
||
699 | |||
700 | // Read pixels from flash |
||
701 | temp = *flashAddress; |
||
702 | flashAddress++; |
||
703 | |||
704 | // Set color |
||
705 | SetColor(temp); |
||
706 | |||
707 | // Write pixel to screen |
||
708 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
709 | { |
||
710 | DeviceWrite(_color.v[1]); |
||
711 | DeviceWrite(_color.v[0]); |
||
712 | } |
||
713 | } |
||
714 | |||
715 | address += LINE_MEM_PITCH; |
||
716 | } |
||
717 | } |
||
718 | |||
719 | DeviceDeselect(); |
||
720 | } |
||
721 | |||
722 | #endif |
||
723 | #ifdef USE_BITMAP_EXTERNAL |
||
724 | |||
725 | /********************************************************************* |
||
726 | * Function: void PutImage1BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
727 | * |
||
728 | * PreCondition: none |
||
729 | * |
||
730 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
731 | * stretch - image stretch factor |
||
732 | * |
||
733 | * Output: none |
||
734 | * |
||
735 | * Side Effects: none |
||
736 | * |
||
737 | * Overview: outputs monochrome image starting from left,top coordinates |
||
738 | * |
||
739 | * Note: image must be located in flash |
||
740 | * |
||
741 | ********************************************************************/ |
||
742 | void PutImage1BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
743 | { |
||
744 | register DWORD address; |
||
745 | register DWORD memOffset; |
||
746 | BITMAP_HEADER bmp; |
||
747 | WORD pallete[2]; |
||
748 | BYTE lineBuffer[320 / 8]; |
||
749 | BYTE *pData; |
||
750 | SHORT byteWidth; |
||
751 | |||
752 | BYTE temp; |
||
753 | BYTE mask; |
||
754 | WORD sizeX, sizeY; |
||
755 | WORD x, y; |
||
756 | BYTE stretchX, stretchY; |
||
757 | |||
758 | // Set start address |
||
759 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
760 | |||
761 | // Get bitmap header |
||
762 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
763 | |||
764 | // Get pallete (2 entries) |
||
765 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 2 * sizeof(WORD), pallete); |
||
766 | |||
767 | // Set offset to the image data |
||
768 | memOffset = sizeof(BITMAP_HEADER) + 2 * sizeof(WORD); |
||
769 | |||
770 | // Line width in bytes |
||
771 | byteWidth = bmp.width >> 3; |
||
772 | if(bmp.width & 0x0007) |
||
773 | byteWidth++; |
||
774 | |||
775 | // Get size |
||
776 | sizeX = bmp.width; |
||
777 | sizeY = bmp.height; |
||
778 | |||
779 | DeviceSelect(); |
||
780 | for(y = 0; y < sizeY; y++) |
||
781 | { |
||
782 | |||
783 | // Get line |
||
784 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
785 | memOffset += byteWidth; |
||
786 | |||
787 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
788 | { |
||
789 | pData = lineBuffer; |
||
790 | SetAddress(address); |
||
791 | mask = 0; |
||
792 | for(x = 0; x < sizeX; x++) |
||
793 | { |
||
794 | |||
795 | // Read 8 pixels from flash |
||
796 | if(mask == 0) |
||
797 | { |
||
798 | temp = *pData++; |
||
799 | mask = 0x80; |
||
800 | } |
||
801 | |||
802 | // Set color |
||
803 | if(mask & temp) |
||
804 | { |
||
805 | SetColor(pallete[1]); |
||
806 | } |
||
807 | else |
||
808 | { |
||
809 | SetColor(pallete[0]); |
||
810 | } |
||
811 | |||
812 | // Write pixel to screen |
||
813 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
814 | { |
||
815 | DeviceWrite(_color.v[1]); |
||
816 | DeviceWrite(_color.v[0]); |
||
817 | } |
||
818 | |||
819 | // Shift to the next pixel |
||
820 | mask >>= 1; |
||
821 | } |
||
822 | |||
823 | address += LINE_MEM_PITCH; |
||
824 | } |
||
825 | } |
||
826 | |||
827 | DeviceDeselect(); |
||
828 | } |
||
829 | |||
830 | /********************************************************************* |
||
831 | * Function: void PutImage4BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
832 | * |
||
833 | * PreCondition: none |
||
834 | * |
||
835 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
836 | * stretch - image stretch factor |
||
837 | * |
||
838 | * Output: none |
||
839 | * |
||
840 | * Side Effects: none |
||
841 | * |
||
842 | * Overview: outputs monochrome image starting from left,top coordinates |
||
843 | * |
||
844 | * Note: image must be located in flash |
||
845 | * |
||
846 | ********************************************************************/ |
||
847 | void PutImage4BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
848 | { |
||
849 | register DWORD address; |
||
850 | register DWORD memOffset; |
||
851 | BITMAP_HEADER bmp; |
||
852 | WORD pallete[16]; |
||
853 | BYTE lineBuffer[320 / 2]; |
||
854 | BYTE *pData; |
||
855 | SHORT byteWidth; |
||
856 | |||
857 | BYTE temp; |
||
858 | WORD sizeX, sizeY; |
||
859 | WORD x, y; |
||
860 | BYTE stretchX, stretchY; |
||
861 | |||
862 | // Set start address |
||
863 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
864 | |||
865 | // Get bitmap header |
||
866 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
867 | |||
868 | // Get pallete (16 entries) |
||
869 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 16 * sizeof(WORD), pallete); |
||
870 | |||
871 | // Set offset to the image data |
||
872 | memOffset = sizeof(BITMAP_HEADER) + 16 * sizeof(WORD); |
||
873 | |||
874 | // Line width in bytes |
||
875 | byteWidth = bmp.width >> 1; |
||
876 | if(bmp.width & 0x0001) |
||
877 | byteWidth++; |
||
878 | |||
879 | // Get size |
||
880 | sizeX = bmp.width; |
||
881 | sizeY = bmp.height; |
||
882 | |||
883 | for(y = 0; y < sizeY; y++) |
||
884 | { |
||
885 | |||
886 | // Get line |
||
887 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
888 | memOffset += byteWidth; |
||
889 | DeviceSelect(); |
||
890 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
891 | { |
||
892 | pData = lineBuffer; |
||
893 | SetAddress(address); |
||
894 | |||
895 | for(x = 0; x < sizeX; x++) |
||
896 | { |
||
897 | |||
898 | // Read 2 pixels from flash |
||
899 | if(x & 0x0001) |
||
900 | { |
||
901 | |||
902 | // second pixel in byte |
||
903 | SetColor(pallete[temp & 0x0f]); |
||
904 | } |
||
905 | else |
||
906 | { |
||
907 | temp = *pData++; |
||
908 | |||
909 | // first pixel in byte |
||
910 | SetColor(pallete[temp >> 4]); |
||
911 | } |
||
912 | |||
913 | // Write pixel to screen |
||
914 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
915 | { |
||
916 | DeviceWrite(_color.v[1]); |
||
917 | DeviceWrite(_color.v[0]); |
||
918 | } |
||
919 | } |
||
920 | |||
921 | address += LINE_MEM_PITCH; |
||
922 | } |
||
923 | |||
924 | DeviceDeselect(); |
||
925 | } |
||
926 | } |
||
927 | |||
928 | /********************************************************************* |
||
929 | * Function: void PutImage8BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
930 | * |
||
931 | * PreCondition: none |
||
932 | * |
||
933 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
934 | * stretch - image stretch factor |
||
935 | * |
||
936 | * Output: none |
||
937 | * |
||
938 | * Side Effects: none |
||
939 | * |
||
940 | * Overview: outputs monochrome image starting from left,top coordinates |
||
941 | * |
||
942 | * Note: image must be located in flash |
||
943 | * |
||
944 | ********************************************************************/ |
||
945 | void PutImage8BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
946 | { |
||
947 | register DWORD address; |
||
948 | register DWORD memOffset; |
||
949 | BITMAP_HEADER bmp; |
||
950 | WORD pallete[256]; |
||
951 | BYTE lineBuffer[320]; |
||
952 | BYTE *pData; |
||
953 | |||
954 | BYTE temp; |
||
955 | WORD sizeX, sizeY; |
||
956 | WORD x, y; |
||
957 | BYTE stretchX, stretchY; |
||
958 | |||
959 | // Set start address |
||
960 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
961 | |||
962 | // Get bitmap header |
||
963 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
964 | |||
965 | // Get pallete (256 entries) |
||
966 | ExternalMemoryCallback(bitmap, sizeof(BITMAP_HEADER), 256 * sizeof(WORD), pallete); |
||
967 | |||
968 | // Set offset to the image data |
||
969 | memOffset = sizeof(BITMAP_HEADER) + 256 * sizeof(WORD); |
||
970 | |||
971 | // Get size |
||
972 | sizeX = bmp.width; |
||
973 | sizeY = bmp.height; |
||
974 | |||
975 | for(y = 0; y < sizeY; y++) |
||
976 | { |
||
977 | |||
978 | // Get line |
||
979 | ExternalMemoryCallback(bitmap, memOffset, sizeX, lineBuffer); |
||
980 | memOffset += sizeX; |
||
981 | |||
982 | DeviceSelect(); |
||
983 | |||
984 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
985 | { |
||
986 | pData = lineBuffer; |
||
987 | SetAddress(address); |
||
988 | |||
989 | for(x = 0; x < sizeX; x++) |
||
990 | { |
||
991 | temp = *pData++; |
||
992 | SetColor(pallete[temp]); |
||
993 | |||
994 | // Write pixel to screen |
||
995 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
996 | { |
||
997 | DeviceWrite(_color.v[1]); |
||
998 | DeviceWrite(_color.v[0]); |
||
999 | } |
||
1000 | } |
||
1001 | |||
1002 | address += LINE_MEM_PITCH; |
||
1003 | } |
||
1004 | |||
1005 | DeviceDeselect(); |
||
1006 | } |
||
1007 | } |
||
1008 | |||
1009 | /********************************************************************* |
||
1010 | * Function: void PutImage8BPPExt(SHORT left, SHORT top, void* bitmap, BYTE stretch) |
||
1011 | * |
||
1012 | * PreCondition: none |
||
1013 | * |
||
1014 | * Input: left,top - left top image corner, bitmap - image pointer, |
||
1015 | * stretch - image stretch factor |
||
1016 | * |
||
1017 | * Output: none |
||
1018 | * |
||
1019 | * Side Effects: none |
||
1020 | * |
||
1021 | * Overview: outputs monochrome image starting from left,top coordinates |
||
1022 | * |
||
1023 | * Note: image must be located in flash |
||
1024 | * |
||
1025 | ********************************************************************/ |
||
1026 | void PutImage16BPPExt(SHORT left, SHORT top, void *bitmap, BYTE stretch) |
||
1027 | { |
||
1028 | register DWORD address; |
||
1029 | register DWORD memOffset; |
||
1030 | BITMAP_HEADER bmp; |
||
1031 | WORD lineBuffer[320]; |
||
1032 | WORD *pData; |
||
1033 | WORD byteWidth; |
||
1034 | |||
1035 | WORD temp; |
||
1036 | WORD sizeX, sizeY; |
||
1037 | WORD x, y; |
||
1038 | BYTE stretchX, stretchY; |
||
1039 | |||
1040 | // Set start address |
||
1041 | address = BUF_MEM_OFFSET + (long)LINE_MEM_PITCH * top + left; |
||
1042 | |||
1043 | // Get bitmap header |
||
1044 | ExternalMemoryCallback(bitmap, 0, sizeof(BITMAP_HEADER), &bmp); |
||
1045 | |||
1046 | // Set offset to the image data |
||
1047 | memOffset = sizeof(BITMAP_HEADER); |
||
1048 | |||
1049 | // Get size |
||
1050 | sizeX = bmp.width; |
||
1051 | sizeY = bmp.height; |
||
1052 | |||
1053 | byteWidth = sizeX << 1; |
||
1054 | |||
1055 | for(y = 0; y < sizeY; y++) |
||
1056 | { |
||
1057 | |||
1058 | // Get line |
||
1059 | ExternalMemoryCallback(bitmap, memOffset, byteWidth, lineBuffer); |
||
1060 | memOffset += byteWidth; |
||
1061 | |||
1062 | DeviceSelect(); |
||
1063 | |||
1064 | for(stretchY = 0; stretchY < stretch; stretchY++) |
||
1065 | { |
||
1066 | pData = lineBuffer; |
||
1067 | SetAddress(address); |
||
1068 | |||
1069 | for(x = 0; x < sizeX; x++) |
||
1070 | { |
||
1071 | temp = *pData++; |
||
1072 | SetColor(temp); |
||
1073 | |||
1074 | // Write pixel to screen |
||
1075 | for(stretchX = 0; stretchX < stretch; stretchX++) |
||
1076 | { |
||
1077 | DeviceWrite(_color.v[1]); |
||
1078 | DeviceWrite(_color.v[0]); |
||
1079 | } |
||
1080 | } |
||
1081 | |||
1082 | address += LINE_MEM_PITCH; |
||
1083 | } |
||
1084 | |||
1085 | DeviceDeselect(); |
||
1086 | } |
||
1087 | } |
||
1088 | |||
1089 | #endif |
Powered by WebSVN v2.8.3