Ronan CHERIAUX / Mbed OS Projet_Interfacage_CHERIAU_Ronan

Dependencies:   BSP_DISCO_F746NG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers drawBitmap.cpp Source File

drawBitmap.cpp

00001 #include "drawBitmap.h"
00002 #include "stm32746g_discovery_lcd.h"
00003 
00004 void drawBitmap(int Xpos, int Ypos, const uint8_t *pbmp, bool transparent)
00005 {
00006     uint32_t index = 0, width = 0, height = 0, bit_pixel = 0;
00007     uint32_t *couleur;
00008 
00009     /* Get bitmap data address offset */
00010     index = pbmp[10] + (pbmp[11] << 8) + (pbmp[12] << 16)  + (pbmp[13] << 24);
00011 
00012     /* Read bitmap width */
00013     width = pbmp[18] + (pbmp[19] << 8) + (pbmp[20] << 16)  + (pbmp[21] << 24);
00014 
00015     /* Read bitmap height */
00016     height = pbmp[22] + (pbmp[23] << 8) + (pbmp[24] << 16)  + (pbmp[25] << 24);
00017 
00018     /* Read bit/pixel */
00019     bit_pixel = pbmp[28] + (pbmp[29] << 8);
00020 
00021     int xSize = BSP_LCD_GetXSize(), ySize = BSP_LCD_GetYSize();
00022     couleur = (uint32_t *)&pbmp[index];
00023     int yDebut;
00024     if (Ypos+height>=ySize) {
00025         yDebut = ySize-1;
00026         couleur += width*(Ypos+height-ySize);
00027     } else {
00028         yDebut = Ypos+height-1;
00029     }
00030     int yFin = (Ypos<0) ? 0 : Ypos;
00031     int xDebut, xDeltaDebut;
00032     if (Xpos<0) {
00033         xDebut = 0;
00034         xDeltaDebut = -Xpos;
00035     } else {
00036         xDebut = Xpos;
00037         xDeltaDebut = 0;
00038     }
00039     int xFin, xDeltaFin;
00040     if (Xpos+width>xSize) {
00041         xFin = xSize-1;
00042         xDeltaFin = Xpos+width - xSize;
00043     } else {
00044         xFin = Xpos+width-1;
00045         xDeltaFin = 0;
00046     }
00047     
00048     for (int ligne=yDebut; ligne>=yFin; ligne--) {
00049         couleur += xDeltaDebut;
00050         for (int colonne=xDebut; colonne<=xFin; colonne++) {
00051             if (transparent & ((*couleur & 0xFF000000)==0xFF000000)) BSP_LCD_DrawPixel(colonne, ligne, *couleur);
00052             couleur++;
00053         }
00054         couleur += xDeltaFin;
00055     }
00056 }
00057