eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4d_imgdec_bmp.c
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
46 #include "d4d.h"
50 
51 #if (D4D_BMP_EXTSRC_SUPPORT_BMP == D4D_TRUE) && (D4D_EXTSRC_FILE_ENABLE == D4D_TRUE)
52 static void D4D_PrintPixel(D4D_COLOR color, D4D_BOOL greyScale);
53 
54 static void D4D_PrintPixel(D4D_COLOR color, D4D_BOOL greyScale)
55 {
56  if(greyScale)
57  color = D4D_GetGreyScale(color); // if needed convert it to grayscale
58  D4D_LLD_LCD.D4DLCD_Send_PixelColor(color); // and send color to display
59 }
60 
61 
62 /**************************************************************/
67 void D4D_ImgDecBmpDraw(D4D_COOR x, D4D_COOR y, D4D_CHAR* pFileName, D4D_BOOL greyScale, D4D_COOR radius)
68 {
69  D4D_FILEPTR pFile;
70  D4D_BITMAPINFOHEADER bitmapInfo;
71  D4D_BGRA* pPalleteBgra = NULL;
72  D4D_COOR locX, locY;
73  D4D_COLOR color;
74  LWord dataLineLength;
75  LWord dataLoadedCnt;
76  LWord dataIx, dataBuffIx, i;
77  LWord dataOffset;
78  D4D_LONG tmpLong;
79 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
80  LWord non_print_len;
81  D4D_BOOL printPixel;
82 #endif
83  // open the picture file
84  pFile = D4D_OpenImgFile(pFileName, "r");
85 
86  // check if the file is opened
87  if(pFile == NULL)
88  return;
89 
90  // load the header of picture file
91 
92  #ifdef D4D_DEBUG
93  // sanity check
95  #endif
96 
97  /********************************************************************************************
98  *
99  * Load the bitmap headers
100  *
101  ********************************************************************************************/
102 
103  // read the file info
105  {
106  // the header isn't loaded succesfully
107  D4D_FileClose(pFile);
108  return;
109  }
110 
111  // check if this is bitmap and if it's supported
113  {
114  //this is not the bitmap file in supported format
115  D4D_FileClose(pFile);
116  return;
117  }
118 
119  // save the data offset
120  dataOffset = D4D_READ32L(D4D_TMP_PBITMAPHEADER->dataOff);
121 
122  // load the Bitmap info one of base header bitmap type (it should be enough for eGUI purposes)
123  if(D4D_FileRead(pFile,(void*)&bitmapInfo, D4D_BITMAPINFOHEADER_SIZE) != D4D_BITMAPINFOHEADER_SIZE)
124  {
125  // the header isn't loaded succesfully
126  D4D_FileClose(pFile);
127  return;
128  }
129 
130 #if D4D_ENDIAN == D4D_ENDIAN_BIG
131  // Fill up right the bmp info (solve endianism)
132  bitmapInfo.headerSz = D4D_READ32L(bitmapInfo.headerSz);
133  bitmapInfo.width = D4D_READ32L(bitmapInfo.width);
134  bitmapInfo.height = D4D_READ32L(bitmapInfo.height);
135  bitmapInfo.nplanes = D4D_READ16L(bitmapInfo.nplanes);
136  bitmapInfo.bitspp = D4D_READ16L(bitmapInfo.bitspp);
137  bitmapInfo.compressType = D4D_READ32L(bitmapInfo.compressType);
138  bitmapInfo.bmpBytesz = D4D_READ32L(bitmapInfo.bmpBytesz);
139  bitmapInfo.hres = D4D_READ32L(bitmapInfo.hres);
140  bitmapInfo.vres = D4D_READ32L(bitmapInfo.vres);
141  bitmapInfo.ncolors = D4D_READ32L(bitmapInfo.ncolors);
142  bitmapInfo.nimpcolors = D4D_READ32L(bitmapInfo.nimpcolors);
143 #endif
144 
145  // check the size parameters of bitmap - Could be in negative
146  if(bitmapInfo.width < 0)
147  bitmapInfo.width *= -1;
148 
149  if(bitmapInfo.height < 0)
150  bitmapInfo.height *= -1;
151 
152  // check the number of planes - MUST be 1
153  if(bitmapInfo.nplanes != 1)
154  {
155  // the count of planes doesn't match the standard
156  D4D_FileClose(pFile);
157  return;
158  }
159 
160 
161  /********************************************************************************************
162  *
163  * Load the bitmap color pallete
164  *
165  ********************************************************************************************/
166 
167  // setup position of bitmap pallete
168  if(D4D_FileSeek(pFile, D4D_BITMAPHEADER_SIZE + bitmapInfo.headerSz, D4D_SEEK_SET) != 0)
169  {
170  // the position in file can't be sets
171  D4D_FileClose(pFile);
172  return;
173  }
174  if(!bitmapInfo.ncolors)
175  {
176  if((D4D_BITMAPCOMPRESSION)(bitmapInfo.compressType) == D4D_BC_RGB)
177  {
178  switch(bitmapInfo.bitspp)
179  {
180  case 1:
181  bitmapInfo.ncolors = 2;
182  break;
183  case 4:
184  bitmapInfo.ncolors = 16;
185  break;
186  case 8:
187  bitmapInfo.ncolors = 256;
188  break;
189  }
190  }else if((D4D_BITMAPCOMPRESSION)(bitmapInfo.compressType) == D4D_BC_RLE8)
191  {
192  bitmapInfo.ncolors = 256;
193  }
194  }
195 
196 
197  if(bitmapInfo.ncolors)
198  {
199  LWord palleteSize = sizeof(D4D_BGRA) * bitmapInfo.ncolors;
200 
201  // alloc the memory for pallete
202  pPalleteBgra = D4D_MemAlloc(palleteSize);
203  if(pPalleteBgra == NULL)
204  {
205  // the Bitmap pallete isn't loaded succesfully
206  D4D_FileClose(pFile);
207  return;
208  }
209 
210  // load the Bitmap pallete
211  if(D4D_FileRead(pFile, pPalleteBgra, palleteSize) != palleteSize)
212  {
213  // the Bitmap pallete isn't loaded succesfully
214  if(pPalleteBgra)
215  D4D_MemFree(pPalleteBgra);
216  D4D_FileClose(pFile);
217  return;
218  }
219 
220  if(greyScale)
221  {
222  int c,i;
223  for(i = 0; i < bitmapInfo.ncolors; i++)
224  {
225  c = pPalleteBgra[i].Red + pPalleteBgra[i].Green + pPalleteBgra[i].Blue;
226  c /= 3;
227 
228  pPalleteBgra[i].Red = c;
229  pPalleteBgra[i].Green = c;
230  pPalleteBgra[i].Blue = c;
231 
232  }
233  }
234 
235  }
236 
237 
238  /********************************************************************************************
239  *
240  * Start Drawing the picture on screen
241  *
242  ********************************************************************************************/
243 
244  // setup position of bitmap data
245  if(D4D_FileSeek(pFile, dataOffset, D4D_SEEK_SET) != 0)
246  {
247  // the position in file can't be sets
248  D4D_FileClose(pFile);
249  if(pPalleteBgra)
250  D4D_MemFree(pPalleteBgra);
251  return;
252  }
253 
254 
255 
256  // Check the compression type and select the right decode method
257  switch((D4D_BITMAPCOMPRESSION)(bitmapInfo.compressType))
258  {
259  // Uncompressed BMP type
260  case D4D_BC_RGB:
261  /********************************************************************************************
262  *
263  * Not compressed BMP types
264  *
265  ********************************************************************************************/
266 
267  // Compute the one line length in source file
268  dataLineLength = (int)((((bitmapInfo.width * bitmapInfo.bitspp) / 8) + 3) & ~3);
269 
270  // do all lines
271  for(locY=0; locY < bitmapInfo.height; locY++)
272  {
273 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
274  if(locY < radius)
275  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, (D4D_COOR)(locY)); // get len of non printed pixels
276  else if((bitmapInfo.height - 1 - locY) < radius)
277  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, (D4D_COOR)(bitmapInfo.height - 1 - locY)); // get len of non printed pixels
278  else
279  non_print_len = 0;
280 #endif
281 
282  // Define window on screen
283 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
284  (void)D4D_LLD_LCD.D4DLCD_SetWindow (x + non_print_len, (D4D_COOR)(y + bitmapInfo.height - locY - 1), (D4D_COOR)(x + bitmapInfo.width - non_print_len), (D4D_COOR)(y + bitmapInfo.height - locY - 1));
285 #else
286  (void)D4D_LLD_LCD.D4DLCD_SetWindow (x, (D4D_COOR)(y + bitmapInfo.height - locY - 1), (D4D_COOR)(x + bitmapInfo.width), (D4D_COOR)(y + bitmapInfo.height - locY - 1));
287 #endif
288  // setup position of bitmap data
289  if(D4D_FileSeek(pFile, dataOffset + locY * dataLineLength, D4D_SEEK_SET) != 0)
290  {
291  // the position in file can't be sets
292  D4D_FileClose(pFile);
293  if(pPalleteBgra)
294  D4D_MemFree(pPalleteBgra);
295  return;
296  }
297 
298  // reset the index counter of line data
299  dataIx = 0;
300  dataLoadedCnt = 0;
301  dataBuffIx = 0; // just to notify that the buffer is empty
302 
303  // do all pixels on line
304  for(locX=0; locX < bitmapInfo.width; locX++)
305  {
306 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
307  printPixel = D4D_TRUE;
308  if(non_print_len)
309  {
310  if((locX < non_print_len) || ((bitmapInfo.width - 1 - locX) < non_print_len))
311  printPixel = D4D_FALSE;
312  }
313 #endif
314 
315  //if(dataIx % D4D_EXTSRC_BUFF_SIZE > (bitmapInfo.bitspp / 8))
316  if(dataBuffIx + (bitmapInfo.bitspp / 8) > dataLoadedCnt )
317  {
318 
319  // setup position of bitmap data
320  if(D4D_FileSeek(pFile, -1 * (dataLoadedCnt - dataBuffIx), D4D_SEEK_CUR) != 0)
321  {
322  // the position in file can't be sets
323  D4D_FileClose(pFile);
324  if(pPalleteBgra)
325  D4D_MemFree(pPalleteBgra);
326  return;
327  }
328 
329  dataBuffIx = 0;
330 
331  if((dataLineLength - dataIx) <= D4D_EXTSRC_BUFF_SIZE)
332  dataLoadedCnt = (dataLineLength - dataIx);
333  else
334  dataLoadedCnt = D4D_EXTSRC_BUFF_SIZE;
335 
336 
337  // load the Bitmap pallete
338  if(D4D_FileRead(pFile, d4d_extsrcBuffer, dataLoadedCnt) != dataLoadedCnt)
339  {
340  // the Bitmap data isn't loaded succesfully
341  D4D_FileClose(pFile);
342  if(pPalleteBgra)
343  D4D_MemFree(pPalleteBgra);
344  return;
345  }
346  }
347 
348 
349 
350  // check the color depth
351  switch(bitmapInfo.bitspp)
352  {
353  /********************************************************************************************
354  * MonoChromatic colors
355  ********************************************************************************************/
356  case 1:
357  tmpLong.complete = 0;
358 
359  i = d4d_extsrcBuffer[dataBuffIx];
360 
361  for(; tmpLong.complete < 8; tmpLong.complete++)
362  {
363  if(locX < bitmapInfo.width)
364  {
365 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
366  if(printPixel)
367 #endif
368  {
369  color = D4D_COLOR_RGB(pPalleteBgra[(i & 0x80)? 1:0].Red, pPalleteBgra[(i & 0x80)? 1:0].Green, pPalleteBgra[(i & 0x80)? 1:0].Blue);
370  D4D_LLD_LCD.D4DLCD_Send_PixelColor(color); // and send color to display
371  }
372 
373  locX++;
374  i <<= 1;
375 
376 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
377  printPixel = D4D_TRUE;
378  if(non_print_len)
379  {
380  if((locX < non_print_len) || ((bitmapInfo.width - 1 - locX) < non_print_len))
381  printPixel = D4D_FALSE;
382  }
383 #endif
384  }else
385  break;
386 
387  }
388 
389  locX--;
390 
391 
392  dataIx++;
393  dataBuffIx++;
394  break;
395 
396  /********************************************************************************************
397  * 16 Color depth of pallete
398  ********************************************************************************************/
399  case 4:
400 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
401  if(printPixel)
402 #endif
403  {
404  tmpLong.Bytes.ll = d4d_extsrcBuffer[dataBuffIx];
405 
406  tmpLong.Bytes.ll >>= 4;
407 
408  color = D4D_COLOR_RGB(pPalleteBgra[tmpLong.Bytes.ll].Red, pPalleteBgra[tmpLong.Bytes.ll].Green, pPalleteBgra[tmpLong.Bytes.ll].Blue);
409  D4D_LLD_LCD.D4DLCD_Send_PixelColor(color); // and send color to display
410  }
411 
412  locX++;
413 
414 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
415  printPixel = D4D_TRUE;
416  if(non_print_len)
417  {
418  if((locX < non_print_len) || ((bitmapInfo.width - 1 - locX) < non_print_len))
419  printPixel = D4D_FALSE;
420  }
421 #endif
422  if(locX < bitmapInfo.width)
423  {
424 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
425  if(printPixel)
426 #endif
427  {
428  tmpLong.Bytes.ll = d4d_extsrcBuffer[dataBuffIx];
429 
430  tmpLong.Bytes.ll &= 0x0f;
431 
432  color = D4D_COLOR_RGB(pPalleteBgra[tmpLong.Bytes.ll].Red, pPalleteBgra[tmpLong.Bytes.ll].Green, pPalleteBgra[tmpLong.Bytes.ll].Blue);
433  D4D_LLD_LCD.D4DLCD_Send_PixelColor(color); // and send color to display
434  }
435  }
436 
437 
438  dataIx++;
439  dataBuffIx++;
440  break;
441 
442  /********************************************************************************************
443  * 256 Color depth of pallete
444  ********************************************************************************************/
445  case 8:
446 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
447  if(printPixel)
448 #endif
449  {
450  color = D4D_COLOR_RGB(pPalleteBgra[d4d_extsrcBuffer[dataBuffIx]].Red, pPalleteBgra[d4d_extsrcBuffer[dataBuffIx]].Green, pPalleteBgra[d4d_extsrcBuffer[dataBuffIx]].Blue);
451  D4D_LLD_LCD.D4DLCD_Send_PixelColor(color); // and send color to display
452  }
453 
454  dataIx++;
455  dataBuffIx++;
456  break;
457 
458  /********************************************************************************************
459  * 565 Colors depth
460  ********************************************************************************************/
461  case 16:
462 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
463  if(printPixel)
464 #endif
465  {
466  tmpLong.Words.low = D4D_READ16L(*((Word*)(&d4d_extsrcBuffer[dataBuffIx])));
467 
468  // the BGR 555 system 15 bits is probably default 16 bit system used in bitmap - PROBABLY - Who knows :-)
470  D4D_PrintPixel(color, greyScale);
471  }
472 
473  dataIx +=2;
474  dataBuffIx +=2;
475  break;
476 
477  /********************************************************************************************
478  * 24- bit Colors depth
479  *******************************************************************************************/
480  case 24:
481 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
482  if(printPixel)
483 #endif
484  {
485  tmpLong.complete = *((LWord*)(&d4d_extsrcBuffer[dataBuffIx]));
486 
487  color = D4D_COLOR_RGB(((D4D_BGRA*)&(tmpLong.complete))->Red, ((D4D_BGRA*)&(tmpLong.complete))->Green, ((D4D_BGRA*)&(tmpLong.complete))->Blue);
488 
489  D4D_PrintPixel(color, greyScale);
490  }
491 
492  dataIx +=3;
493  dataBuffIx +=3;
494  break;
495 
496  /********************************************************************************************
497  * 32- bit Colors depth
498  ********************************************************************************************/
499  case 32:
500 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
501  if(printPixel)
502 #endif
503  {
504  tmpLong.complete = *((LWord*)(&d4d_extsrcBuffer[dataBuffIx]));
505 
506  color = D4D_COLOR_RGB(((D4D_BGRA*)&(tmpLong.complete))->Red, ((D4D_BGRA*)&(tmpLong.complete))->Green, ((D4D_BGRA*)&(tmpLong.complete))->Blue);
507 
508  D4D_PrintPixel(color, greyScale);
509  }
510  dataIx +=4;
511  dataBuffIx +=4;
512  break;
513  }
514  }
515  }
516 
517 
518  break;
519 
520  case D4D_BC_RLE8:
521  /********************************************************************************************
522  *
523  * RLE 8 Compression type
524  *
525  ********************************************************************************************/
526  {
527 
528  #define COUNTER 0
529  #define COLOR_IX 1
530 
531  #define OFFSET_X 2
532  #define OFFSET_Y 3
533  #define COLOR 4
534 
535  locX = x;
536  locY = y + bitmapInfo.height - 1;
537 
538 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
539  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, 0); // get len of non printed pixels for first line
540 #endif
541  while(D4D_FileRead(pFile, d4d_extsrcBuffer, 2) == 2)
542  {
543 
544  dataOffset +=2;
545 
546  if(d4d_extsrcBuffer[COUNTER] > 0)
547  {
548  D4D_COOR x1, x2;
549 
550  color = D4D_COLOR_RGB(pPalleteBgra[d4d_extsrcBuffer[COLOR_IX]].Red, pPalleteBgra[d4d_extsrcBuffer[COLOR_IX]].Green, pPalleteBgra[d4d_extsrcBuffer[COLOR_IX]].Blue);
551 
552  x1 = locX;
553  x2 = (D4D_COOR)(locX + d4d_extsrcBuffer[COUNTER]);
554 
555 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
556  if(x1 < x + non_print_len)
557  x1 = x + non_print_len;
558 
559  if(x2 > (x + bitmapInfo.width - 1 - non_print_len))
560  x2 = (x + bitmapInfo.width - 1 - non_print_len);
561 
562  if(x2 > x1)
563 #endif
564  {
565  // Define window on screen
566  (void)D4D_LLD_LCD.D4DLCD_SetWindow (x1, locY, x2, locY);
567 
568  for(i=0;i<(x2-x1);i++)
569  D4D_LLD_LCD.D4DLCD_Send_PixelColor(color); // and send color to display
570  }
571  locX += d4d_extsrcBuffer[COUNTER];
572 
573  }
574  else
575  {
576  /********************************************************************************************
577  * Second byte Meaning
578  *
579  * 0 End of line
580  * 1 End of bitmap
581  * 2 Delta. The next two bytes are the horizontal
582  * and vertical offsets from the current position
583  * to the next pixel.
584  * 3-255 Switch to absolute mode
585  ********************************************************************************************/
586 
587  switch(d4d_extsrcBuffer[COLOR_IX])
588  {
589  case 0:
590  locX = x;
591  locY--;
592 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
593  if((locY - y) < radius)
594  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, (D4D_COOR)(locY - y)); // get len of non printed pixels
595  else if((bitmapInfo.height - 1 - (locY - y)) < radius)
596  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, (D4D_COOR)(bitmapInfo.height - 1 - (locY - y))); // get len of non printed pixels
597  else
598  non_print_len = 0;
599 #endif
600  break;
601 
602  case 1:
603  // the bitmap is completelly drawed
604  D4D_FileClose(pFile);
605  if(pPalleteBgra)
606  D4D_MemFree(pPalleteBgra);
607  return;
608 
609  case 2:
610  // change offset of cursor position
611  if(D4D_FileRead(pFile, &d4d_extsrcBuffer[OFFSET_X], 2) != 2)
612  {
613  // the header isn't loaded succesfully
614  D4D_FileClose(pFile);
615  if(pPalleteBgra)
616  D4D_MemFree(pPalleteBgra);
617  return;
618  }
619 
620  dataOffset +=2;
621 
622  locX += d4d_extsrcBuffer[OFFSET_X];
623  locY -= d4d_extsrcBuffer[OFFSET_Y];
624 
625 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
626  if((locY - y) < radius)
627  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, (D4D_COOR)(locY - y)); // get len of non printed pixels
628  else if((bitmapInfo.height - 1 - (locY - y)) < radius)
629  non_print_len = D4D_RndCornerGetNonPrintedPxl(radius, (D4D_COOR)(bitmapInfo.height - 1 - (locY - y))); // get len of non printed pixels
630  else
631  non_print_len = 0;
632 #endif
633  break;
634 
635  default:
636 
637 
638  for(i=0;i<d4d_extsrcBuffer[COLOR_IX];i++)
639  {
640  if(D4D_FileRead(pFile, &d4d_extsrcBuffer[COLOR], 1) != 1)
641  {
642  // the header isn't loaded succesfully
643  D4D_FileClose(pFile);
644  if(pPalleteBgra)
645  D4D_MemFree(pPalleteBgra);
646  return;
647  }
648 
649  dataOffset++;
650 
651 #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
652  printPixel = D4D_TRUE;
653  if(non_print_len)
654  {
655  if((locX < non_print_len + x) || ((bitmapInfo.width - 1 - (locX - x)) < non_print_len))
656  printPixel = D4D_FALSE;
657  }
658 
659  if(printPixel)
660 #endif
661  {
662  color = D4D_COLOR_RGB(pPalleteBgra[d4d_extsrcBuffer[COLOR]].Red, pPalleteBgra[d4d_extsrcBuffer[COLOR]].Green, pPalleteBgra[d4d_extsrcBuffer[COLOR]].Blue);
663 
664  D4D_LCD_PutPixel(locX, locY, D4D_LINE_THIN, color);
665  }
666  locX++;
667 
668  }
669 
670  if(dataOffset & 0x01)
671  {
672  // setup position of bitmap data
673  if(D4D_FileSeek(pFile, 1, D4D_SEEK_CUR) != 0)
674  {
675  // the position in file can't be sets
676  D4D_FileClose(pFile);
677  if(pPalleteBgra)
678  D4D_MemFree(pPalleteBgra);
679  return;
680  }
681 
682  dataOffset++;
683  }
684 
685  break;
686  }
687 
688 
689  }
690  }
691 
692  }
693  break;
694 
695  case D4D_BC_RLE4:
696  case D4D_BC_BITFIELDS:
697  case D4D_BC_JPEG:
698  case D4D_BC_PNG:
699  default:
700  // there are all non supported bitmaps
701  #if D4D_ROUND_CORNER_ENABLE != D4D_FALSE
702  D4D_RBoxXY(x, y, (D4D_COOR)(x + bitmapInfo.width - 1), (D4D_COOR)(y + bitmapInfo.height - 1), D4D_LINE_THIN, D4D_ScreenGetScheme(D4D_GetActiveScreen())->fore, D4D_ScreenGetScheme(D4D_GetActiveScreen())->bckg, radius);
703  #else
704  D4D_BoxXY(x, y, (D4D_COOR)(x + bitmapInfo.width - 1), (D4D_COOR)(y + bitmapInfo.height - 1), D4D_LINE_THIN, D4D_ScreenGetScheme(D4D_GetActiveScreen())->fore, D4D_ScreenGetScheme(D4D_GetActiveScreen())->bckg);
705  #endif
706  break;
707  // not supported compressions
708  }
709 
710  // the Bitmap is drawed, just close opened file
711  D4D_FileClose(pFile);
712  if(pPalleteBgra)
713  D4D_MemFree(pPalleteBgra);
714 
715 #if D4D_LLD_FLUSH_ELEMENT != D4D_FALSE
717 #endif
718  // end
719 
720 
721 }
722 
723 
724 /**************************************************************/
730 {
731  D4D_SIZE tmp_size = D4D_ImgDecBmpGetSize(pFileName);
732 
733  return tmp_size.cx;
734 }
735 
736 /**************************************************************/
742 {
743  D4D_SIZE tmp_size = D4D_ImgDecBmpGetSize(pFileName);
744 
745  return tmp_size.cy;
746 }
747 
748 
749 /**************************************************************/
755 {
756  D4D_BITMAPINFOHEADER bitmapInfo;
757 
758  if(D4D_ImgDecBmpGetHeader(pFileName, (void*)&bitmapInfo, D4D_BITMAPINFOHEADER_SIZE) != D4D_BITMAPINFOHEADER_SIZE)
759  return *(D4D_SIZE*)&d4d_size_zero;
760  else
761  {
762  D4D_SIZE tmp_size;
763  // check the size parameters of bitmap - Could be in negative
764  if(bitmapInfo.width < 0)
765  bitmapInfo.width *= -1;
766 
767  if(bitmapInfo.height < 0)
768  bitmapInfo.height *= -1;
769 
770  tmp_size.cx = (D4D_COOR)bitmapInfo.width;
771  tmp_size.cy = (D4D_COOR)bitmapInfo.height;
772 
773  return tmp_size;
774 
775  }
776 }
777 
778 /**************************************************************/
783 int D4D_ImgDecBmpGetHeader(D4D_CHAR* pFileName, void* pBuff, int max_size)
784 {
785  D4D_FILEPTR pFile;
786  int res;
787 
788  if(max_size < D4D_BITMAPINFOHEADER_SIZE)
789  return 0;
790 
791  // open the picture file
792  pFile = D4D_OpenImgFile(pFileName, "r");
793 
794  // check if the file is opened
795  if(pFile == NULL)
796  return 0;
797 
798  // load the header of picture file
799 
800  #ifdef D4D_DEBUG
801  // sanity check
803  #endif
804 
805  /********************************************************************************************
806  *
807  * Load the bitmap headers
808  *
809  ********************************************************************************************/
810 
811  // read the file info
813  {
814  // the header isn't loaded succesfully
815  D4D_FileClose(pFile);
816  return 0;
817  }
818 
819  // check if this is bitmap and if it's supported
821  {
822  //this is not the bitmap file in supported format
823  D4D_FileClose(pFile);
824  return 0;
825  }
826 
827  // load the Bitmap info one of base header bitmap type (it should be enough for eGUI purposes)
828  res = D4D_FileRead(pFile, pBuff, D4D_BITMAPINFOHEADER_SIZE);
829 
830  D4D_FileClose(pFile);
831 
832 #if D4D_ENDIAN == D4D_ENDIAN_BIG
833  if(res == D4D_BITMAPINFOHEADER_SIZE)
834  {
835 
836  // Fill up right the bmp info (solve endianism)
837  ((D4D_BITMAPINFOHEADER*)pBuff)->headerSz = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->headerSz);
838  ((D4D_BITMAPINFOHEADER*)pBuff)->width = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->width);
839  ((D4D_BITMAPINFOHEADER*)pBuff)->height = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->height);
840  ((D4D_BITMAPINFOHEADER*)pBuff)->nplanes = D4D_READ16L(((D4D_BITMAPINFOHEADER*)pBuff)->nplanes);
841  ((D4D_BITMAPINFOHEADER*)pBuff)->bitspp = D4D_READ16L(((D4D_BITMAPINFOHEADER*)pBuff)->bitspp);
842  ((D4D_BITMAPINFOHEADER*)pBuff)->compressType = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->compressType);
843  ((D4D_BITMAPINFOHEADER*)pBuff)->bmpBytesz = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->bmpBytesz);
844  ((D4D_BITMAPINFOHEADER*)pBuff)->hres = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->hres);
845  ((D4D_BITMAPINFOHEADER*)pBuff)->vres = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->vres);
846  ((D4D_BITMAPINFOHEADER*)pBuff)->ncolors = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->ncolors);
847  ((D4D_BITMAPINFOHEADER*)pBuff)->nimpcolors = D4D_READ32L(((D4D_BITMAPINFOHEADER*)pBuff)->nimpcolors);
848 
849  }
850 #endif
851 
852  return res;
853 }
854 
855 
856 /**************************************************************************/
863 {
864 #if D4D_EXTSRC_BUFF_SIZE < 64
865  D4D_UNUSED(pFileName);
866  return D4D_FALSE;
867 #else
868  D4D_FILEPTR pFile = NULL;
869  D4D_COLOR clr;
870  D4D_COOR x, y, x_max, y_max;
871  LWord dataIx = 0;
872 
874  {
877  }else
878  {
881  }
882 
883  // 1. Open File for Write
884  pFile = D4D_OpenImgFile(pFileName, "w");
885 
886  if(pFile == NULL)
887  return D4D_FALSE;
888 
889  // 2. Create BMP Header
890  d4d_extsrcBuffer[0] = 'B';
891  d4d_extsrcBuffer[1] = 'M';
892  // File Size 54B header + 24bits color (3Bytes) * width * height
894  // Bitmap header reserved bytes
895  *((LWord*)&(d4d_extsrcBuffer[6])) = D4D_WRITE32L(0);
896  // Bitmap bitmap data offset
897  *((LWord*)&(d4d_extsrcBuffer[10])) = D4D_WRITE32L(54);
898 
899  // 3. Create BMP Information Data BID
900  //size of this information
901  *((LWord*)&(d4d_extsrcBuffer[14])) = D4D_WRITE32L(40);
902  // Width of bitmap
903  *((LWord*)&(d4d_extsrcBuffer[18])) = D4D_WRITE32L(x_max);
904  // Height of bitmap
905  *((LWord*)&(d4d_extsrcBuffer[22])) = D4D_WRITE32L(y_max);
906  // Number of color planes being used.
907  *((Word*)&(d4d_extsrcBuffer[26])) = D4D_WRITE16L(1);
908  // The number of bits/pixel.
909  *((Word*)&(d4d_extsrcBuffer[28])) = D4D_WRITE16L(24);
910  //BI_RGB, No compression used
911  *((LWord*)&(d4d_extsrcBuffer[30])) = D4D_WRITE32L(0);
912  // Bitmap data size 24bits color (3Bytes) * width * height
913  *((LWord*)&(d4d_extsrcBuffer[34])) = D4D_WRITE32L( 3 * D4D_SCREEN_SIZE_LONGER_SIDE * D4D_SCREEN_SIZE_SHORTER_SIDE);
914  //The horizontal resolution of the image 2,835 pixels/meter
915  *((LWord*)&(d4d_extsrcBuffer[38])) = D4D_WRITE32L(2835);
916  //The vertical resolution of the image 2,835 pixels/meter
917  *((LWord*)&(d4d_extsrcBuffer[42])) = D4D_WRITE32L(2835);
918  //Number of colors in the palette
919  *((LWord*)&(d4d_extsrcBuffer[46])) = D4D_WRITE32L(0);
920  // Means all colors are important
921  *((LWord*)&(d4d_extsrcBuffer[50])) = D4D_WRITE32L(0);
922 
923  if(D4D_FileWrite(pFile, d4d_extsrcBuffer, 54) != 54)
924  {
925  D4D_FileClose(pFile);
926  return D4D_FALSE;
927  }
928 
929  // 4. Write the Bitmap Data
930 
931  for(y = 0; y < y_max; y++)
932  {
933 
934  (void)D4D_LLD_LCD.D4DLCD_SetWindow(0, (D4D_COOR)(y_max - 1 - y), (D4D_COOR)(x_max - 1), (D4D_COOR)(y_max - 1 - y));
935  for(x = 0; x < x_max; x++)
936  {
938  d4d_extsrcBuffer[dataIx++] = D4D_COLOR_GET_B(clr);
939  d4d_extsrcBuffer[dataIx++] = D4D_COLOR_GET_G(clr);
940  d4d_extsrcBuffer[dataIx++] = D4D_COLOR_GET_R(clr);
941 
942  // Check if data buffer is full
943  if(dataIx > (D4D_EXTSRC_BUFF_SIZE - 3))
944  {
945  // If it full, flush data to file
946  if(D4D_FileWrite(pFile, d4d_extsrcBuffer, dataIx) != dataIx)
947  {
948  D4D_FileClose(pFile);
949  return D4D_FALSE;
950  }
951  dataIx = 0;
952  }
953  }
954  }
955 
956  // check the last chunk of data
957  if(dataIx)
958  {
959  if(D4D_FileWrite(pFile, d4d_extsrcBuffer, dataIx) != dataIx)
960  {
961  D4D_FileClose(pFile);
962  return D4D_FALSE;
963  }
964  }
965 
966  D4D_FileClose(pFile);
967  return D4D_TRUE;
968 #endif
969 }
970 
971 #endif
struct D4D_LONG_S::@2 Bytes
void D4D_RBoxXY(D4D_COOR x1, D4D_COOR y1, D4D_COOR x2, D4D_COOR y2, D4D_LINETYPE ltype, D4D_COLOR colorLine, D4D_COLOR colorFill, D4D_COOR radius)
Function draw filled rectangle with outline on the screen with round corners.
#define D4D_MemAlloc(size)
Mem Alloc eGUI definition. If not defined by user config any special user function, it used standard system function.
Definition: d4d_extsrc.h:320
#define D4D_COLOR_GET_B(color)
Definition: d4d_scheme.h:438
D4D_COLOR(* D4DLCD_Read_PixelColor)(void)
The LCD driver read pixel function. The pixels will be read on position (automaticaly incremented) se...
Definition: d4d_lldapi.h:153
void(* D4DLCD_FlushBuffer)(D4DLCD_FLUSH_MODE mode)
The LCD driver flush function.
Definition: d4d_lldapi.h:154
#define D4D_TMP_PBITMAPHEADER
#define D4D_BITMAPINFOHEADER_SIZE
#define D4D_READ32L(x)
Macro for handling endianism - read 32bit - from Little Endian.
Definition: d4d_extsrc.h:249
#define D4D_FALSE
This is definition of boolean operation value in eGUI - FALSE.
Definition: d4d_types.h:104
#define D4D_SCREEN_SIZE_LONGER_SIDE
This macro is used to define the size of longer side of LCD. If not defined, the longer side is set t...
Definition: d4d_base.h:101
#define D4D_COLOR_RGB(R, G, B)
Definition: d4d_scheme.h:434
#define D4D_READ16L(x)
Macro for handling endianism - read 16bit - from Little Endian.
Definition: d4d_extsrc.h:247
D4D_BITMAPCOMPRESSION
The flush after one basic element is draw.
Definition: d4d_lldapi.h:138
D4D_COOR D4D_ImgDecBmpGetWidth(D4D_CHAR *pFileName)
#define D4D_TRUE
This is definition of boolean operation value in eGUI - TRUE.
Definition: d4d_types.h:106
void D4D_ImgDecBmpDraw(D4D_COOR x, D4D_COOR y, D4D_CHAR *pFileName, D4D_BOOL greyScale, D4D_COOR radius)
D4D Driver main header file.
const D4D_SIZE d4d_size_zero
Definition: d4d_base.c:74
D4D Driver private header file.
Portrait up side down orientation.
Definition: d4d_types.h:344
D4D_COOR cx
Size in axis X (width)
Definition: d4d_types.h:232
#define D4D_BITMAP_SIGNATURE
Byte D4D_COOR
Type definition of eGUI coordination variables.
Definition: d4d_types.h:219
#define D4D_COLOR_RGB555_GET_B(color)
The macro gets the Blue component from 15-bit RGB555 format to 8-bit component format.
Definition: d4d_scheme.h:319
static void D4D_PrintPixel(D4D_COLOR color, D4D_BOOL greyScale)
#define D4D_WRITE16L(x)
Macro for handling endianism - write 16bit - from Little Endian.
Definition: d4d_extsrc.h:261
D4D_CLR_SCHEME * D4D_ScreenGetScheme(D4D_SCREEN *pScreen)
#define D4D_BITMAPHEADER_SIZE
D4D_COOR D4D_ImgDecBmpGetHeight(D4D_CHAR *pFileName)
D4D_ORIENTATION D4D_LCD_GetOrientation(void)
Definition: d4d_low.c:147
#define D4D_EXTSRC_BUFF_SIZE
This macro is used to specify size of buffer that is using when external file support is enabled...
Definition: d4d_base.h:167
void D4D_LCD_PutPixel(D4D_COOR x1, D4D_COOR y1, D4D_LINETYPE line_type, D4D_COLOR color)
Definition: d4d_low.c:192
#define NULL
Type definition of null pointer.
Definition: d4d_types.h:184
D4D_SIZE D4D_ImgDecBmpGetSize(D4D_CHAR *pFileName)
#define D4D_ASSERT(cond)
Definition: d4d_base.h:583
#define D4D_MemFree(pMem)
Mem Free eGUI definition. If not defined by user config any special user function, it used standard system function.
Definition: d4d_extsrc.h:329
void D4D_BoxXY(D4D_COOR x1, D4D_COOR y1, D4D_COOR x2, D4D_COOR y2, D4D_LINETYPE ltype, D4D_COLOR colorLine, D4D_COLOR colorFill)
Function draw filled rectangle with outline on the screen.
unsigned long LWord
Type definition of LWord (unsigned 32-bit).
Definition: d4d_types.h:167
D4D_SCREEN * D4D_GetActiveScreen(void)
Returns pointer to current active screen.
Definition: d4d_screen.c:78
D4D driver external bmp files decoder header file.
int D4D_ImgDecBmpGetHeader(D4D_CHAR *pFileName, void *pBuff, int max_size)
D4D_COOR D4D_RndCornerGetNonPrintedPxl(D4D_COOR radius, D4D_COOR line)
Function that counts number of printed pixels in specified line of circle quadrant.
#define D4D_FileWrite
Macro used as short cut to used File Write function defined by D4D_DECLARE_FILE_FUNCTIONS.
Definition: d4d_extsrc.h:309
#define OFFSET_Y
#define D4D_SCREEN_SIZE_SHORTER_SIDE
This macro is used to define the size of shorter side of LCD. If not defined, the shorter side is set...
Definition: d4d_base.h:108
#define COUNTER
struct D4D_LONG_S::@1 Words
#define D4D_SEEK_SET
D4D_SEEK_SET eGUI Origin constant for begin of file (1)
Definition: d4d_extsrc.h:139
#define OFFSET_X
D4D_COOR cy
Size in axis Y (height)
Definition: d4d_types.h:233
#define COLOR_IX
#define D4D_SEEK_CUR
D4D_SEEK_CUR eGUI Origin constant for current position of file (2)
Definition: d4d_extsrc.h:141
#define D4D_FileClose
Macro used as short cut to used File Close function defined by D4D_DECLARE_FILE_FUNCTIONS.
Definition: d4d_extsrc.h:305
const D4DLCD_FUNCTIONS D4D_LLD_LCD
LWord D4D_BOOL
Type definition of eGUI boolean.
Definition: d4d_types.h:204
#define D4D_UNUSED(x)
Macro used just for notify compiler that the input parameter is not used.
Definition: d4d_base.h:504
char D4D_CHAR
Type definition of eGUI ASCII character.
Definition: d4d_types.h:280
#define COLOR
Type definition of eGUI size structure.
Definition: d4d_types.h:230
#define D4D_COLOR_GET_G(color)
Definition: d4d_scheme.h:437
struct D4D_BGRA_S D4D_BGRA
#define D4D_FileSeek
Macro used as short cut to used File Seek function defined by D4D_DECLARE_FILE_FUNCTIONS.
Definition: d4d_extsrc.h:311
Portrait orientation.
Definition: d4d_types.h:343
Line type thin.
Definition: d4d_types.h:293
#define D4D_WRITE32L(x)
Macro for handling endianism - write 32bit - from Little Endian.
Definition: d4d_extsrc.h:263
#define D4D_COLOR_RGB555_GET_R(color)
The macro gets the Red component from 15-bit RGB555 format to 8-bit component format.
Definition: d4d_scheme.h:317
Byte d4d_extsrcBuffer[D4D_EXTSRC_BUFF_SIZE]
D4D driver - resistive touch screen driver function header file.
void(* D4DLCD_Send_PixelColor)(D4D_COLOR value)
The LCD driver send pixel function. The pixels will be draw on position (automaticaly incremented) se...
Definition: d4d_lldapi.h:152
#define D4D_COLOR_RGB555_GET_G(color)
The macro gets the Green component from 15-bit RGB555 format to 8-bit component format.
Definition: d4d_scheme.h:318
LWord D4D_COLOR
Type definition of eGUI color variables.
Definition: d4d_types.h:262
D4D_COLOR D4D_GetGreyScale(D4D_COLOR color)
Compute the grayscale color.
Definition: d4d_scheme.c:333
D4D_BOOL D4D_PrintScreenToBMP(D4D_CHAR *pFileName)
The function convert screen into BMP file.
unsigned short Word
Type definition of Word (unsigned 16-bit).
Definition: d4d_types.h:159
void * D4D_FILEPTR
Type definition of eGUI file pointer.
Definition: d4d_types.h:298
#define D4D_COLOR_GET_R(color)
Definition: d4d_scheme.h:436
#define D4D_FileRead
Macro used as short cut to used File Read function defined by D4D_DECLARE_FILE_FUNCTIONS.
Definition: d4d_extsrc.h:307
unsigned char(* D4DLCD_SetWindow)(unsigned short x1, unsigned short y1, unsigned short x2, unsigned short y2)
The LCD driver Set logic window function. Into this logic window will be draw pixels.
Definition: d4d_lldapi.h:150