How to draw bitmap LPCXpresso54608

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to draw bitmap LPCXpresso54608

1,162 Views
oscarniño
Contributor III

Well this is an old question of course, I have read a bitmap from sd, but using a big bitmap(480x272 in my case) my ram gets stock, I know that there is a way drawing an image with GUI_BMP_DrawEx() as user and reference manual says, it do not have to be read into the memory but it use a variable as buffer. The problem is the same. Some examples of emWin use window library and I cannot found it. I have check some questions made before and I have downloaded some examples of them. I´m using MCUXpresso IDE, I would like to share my way to read an image from sd, I was wondering if someone has an example without using window library or telling me how to include it in my project. I would like to draw BMP, JPG, PNG and GIF image I have read reference manual UM03001.pdf but I´m stock in How to read file without  GUI_BMP_Draw() function. I mean; I have modified some examples in old question like this one, these are my functions:

static void _ShowBMP(const TCHAR* sFilename)
{
    int XSize, YSize, XPos, YPos;
    FIL    hFile;
    FRESULT error;
    error = f_open(&hFile, sFilename, (FA_READ | FA_OPEN_EXISTING));
    if (error == FR_OK)
    {
        GUI_ClearRect(0, 0, 480, 272);
        XSize = GUI_BMP_GetXSizeEx(_GetData, &hFile);
        YSize = GUI_BMP_GetYSizeEx(_GetData, &hFile);
        XPos = (XSize > 480) ?  0 : 160 - (XSize / 2);
        YPos = (YSize > 272) ? 60 : 150 - (YSize / 2);
        if (!GUI_BMP_DrawEx(_GetData, &hFile, XPos, YPos))
        {
             GUI_Delay(2000);
        }
        f_close(&hFile);
    }
}

and my getdata function

static int _GetData(void * p, const U8 ** ppData, unsigned NumBytesReq, U32 Off)
{
 static char _acBuffer[0x200];
 unsigned int NumBytesRead;
 FIL * phFile;
 phFile = (FIL *)p;
 //
 // Check buffer size
 //
 if (NumBytesReq > sizeof(_acBuffer))
 {
  NumBytesReq = sizeof(_acBuffer);
 }
 //
 // Set file pointer to the offset location
 //
 f_lseek(phFile, 0U);
 //
 // Read data into buffer
 //
 f_read(phFile, _acBuffer, sizeof(_acBuffer), &NumBytesRead);
// NumBytesRead = FS_FRead(_acBuffer, sizeof(char), NumBytesReq, phFile);
 //
 // Set data pointer to the beginning of the buffer
 //
 *ppData = _acBuffer;   <----------------------------------THIS IS THE BUFFER
 //
 // Return number of available bytes
 //
 return NumBytesRead;
}
It is important to say that open function returns a FR_OK parameter that indicates that file has been loaded, but when draw bitmap function is called there is not image showed.
Finally, these files are the way that I use to show bitmap image from sd but it has the problema when I read big images(my RAM ends).
If somebody could help me I will apreciate it so much. I think this is the same way to draw gif, jpg and png images
Labels (1)
Tags (1)
0 Kudos
5 Replies

811 Views
oscarniño
Contributor III

Hi

I cannot resolved the problema about draw bitmap with GUI_BMP_DrawEx() function, so I had to read about bitmap files and I resolved in this way, I would like to share this metod. If someone has a way to avoid the sweep image(showing pixel per pixel) I would apreciated it

first:

6.10 Ejemplo: leer información de un fichero BMP - AprendeAProgramar.com 

INFORMATION TYPE                        BYTE POSITION

File Type (BM)                                     0-1
File Size                                                2-5
Reserved                                            6-7
Reserved                                           8-9
Offset (start image)                              10-13

Header Size                                          14-17
Xsize(píxels)                                    18-21
Ysize(píxels)                                     22-25
Number of layers                               26-27
Bits per pixel                                 28-29
Compression                                 30-33
Image Size                                     34-37
Horizontal resolution                         38-41
Vertical resolution                              42-45
Table color size                               46-49
Importan colors counter                50-53

So based on this:

FRESULT drawBitmap(const TCHAR* path, uint16_t posX, uint16_t posY)
{
 FRESULT error;
 FIL g_fileObject;
 uint32_t bytesRead;
 uint8_t bufHeader[HEADER_SIZE];
 bmpFile imageToDraw;
 error = f_open(&g_fileObject, path, (FA_READ | FA_OPEN_EXISTING));
 if (error != FR_OK)
 {
  return error;
 }
 error = f_lseek(&g_fileObject, 0U);
 if (error != FR_OK)
 {
  return error;
 }
 error = f_read(&g_fileObject, bufHeader, HEADER_SIZE, &bytesRead); //Read header
 if (error)
 {
  return error;
 }
 fillBmpInfo(&imageToDraw, bufHeader);
 drawBmpPerLine(&g_fileObject,&imageToDraw, 0, 0);
 error = f_close (&g_fileObject);
 if (error)
 {
  return error;
 }
 return FR_OK;
}
void fillBmpInfo(bmpFile *f, uint8_t *buf)
{
 f->typeFile = (WORD)((buf[1] << 8) + buf[0]);
 f->bmpSize = (WORD)((buf[5] << 24) + (buf[4] << 16) + (buf[3] << 8) + buf[2]);
 f->offset = (WORD)((buf[13] << 24) + (buf[12] << 16) + (buf[11] << 8) + buf[10]);
 f->headerSize = (WORD)((buf[17] << 24) + (buf[16] << 16) + (buf[15] << 8) + buf[14]);
 f->xSize = (WORD)((buf[21] << 24) + (buf[20] << 16) + (buf[19] << 8) + buf[18]);
 f->ySize = (WORD)((buf[25] << 24) + (buf[24] << 16) + (buf[23] << 8) + buf[22]);
 f->bpp = (WORD)((buf[29] << 8) + buf[28]);
}
void drawBmpPerLine(FIL* fp,bmpFile *f, uint16_t posX, uint16_t posY)
{
 uint16_t bytesLineSize = f->xSize*3;
 uint32_t remainBytes = f->imageSize;
// uint8_t bufferPerLine[bytesLineSize];
 uint8_t *bufferPerLine = (uint8_t *)SDRAM_BASE_ADDR;
 bufferPerLine = malloc(bytesLineSize);
 uint32_t RGBcolor;
 UINT bytesRead;
 uint32_t offSet = f->offset;
 uint16_t Xindex;
 uint16_t Yindex;
 uint32_t bufIndex;
 uint8_t X = posX;
 uint8_t Y;
 uint16_t stepPixel = f->bpp/8;
 for(Yindex = f->ySize; Yindex >= 0; Yindex--)
 {
  f_lseek(fp, offSet);
  f_read(fp, bufferPerLine, bytesLineSize, &bytesRead);
  bufIndex = 0;
  for(Xindex = 0; Xindex < f->xSize; Xindex++)
  {
   RGBcolor = (WORD)((bufferPerLine[bufIndex+2] << 16) + (bufferPerLine[bufIndex+1] << 8) + bufferPerLine[bufIndex]);
   GUI_SetColor(RGBcolor);
   GUI_DrawPixel(posX+Xindex, posY+Yindex);
   bufIndex += stepPixel;
  }
  offSet += bytesLineSize;
 }
}
I hope this could be helpfully for someone.
Beast regards
0 Kudos

811 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Oscar Nino,

    Do you have tried the small bin picture, whether it works OK on your side? Just make sure your problem is the RAM problem or the emwin using problem.

    You mentioned :window library , could you give me more information about it, where you find these library information. Is it from NXP or Segger emwin?

    About the emwin problem, I think you also can post the question in segger, because it is the segger's product, their engineer will be more familiar with it. The link is:

Technical Support | SEGGER - The Embedded Experts 

    About the RAM size problem, I think you can consider to add an external SRAM which can connected to the EMC module, just like this:

pastedImage_1.png

Then the external RAM will have the according address in the LPC54608, you can call that memory directly.

Wish it helps you!
Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

811 Views
oscarniño
Contributor III

Hi Kerry Zhou

Thanks for reply, about BIN picture I haven´t , I have tried small picture using GUI_BMP_Draw() function. About problema I think it is both, SDRAM I can´t use it, I have seen and debug examples of this but when I implement it in my code it doesn´t work.

This is how I use SDRAM:

First way.-

void *g_bufferRead = (void *)SDRAM_BASE_ADDR; /*SDRAM starting address*/

then:

sizeImage = g_fileObject.obj.objsize - g_fileObject.fptr;

g_bufferRead = malloc(sizeImage);

to reserve memory

and finally

error = f_read(&g_fileObject, g_bufferRead, sizeof(sizeImage), &bytesRead);

Second way.-

uint8_t (*g_bufferRead)[0x80000] = (uint8_t(*)[0x80000])SDRAM_BASE_ADDR; /*SDRAM starting address*/

then:

sizeImage = g_fileObject.obj.objsize - g_fileObject.fptr;

error = f_read(&g_fileObject, g_bufferRead, sizeof(sizeImage), &bytesRead);

Third way.-

UINT *g_bufferRead[g_fileObject.obj.objsize - g_fileObject.fptr] = (UINT*)SDRAM_BASE_ADDR[g_fileObject.obj.objsize - g_fileObject.fptr];

error = f_read(&g_fileObject, g_bufferRead, (g_fileObject.obj.objsize - g_fileObject.fptr), &bytesRead);

but any of them work

About Windows library, I have check some examples from emwin: "2DGL_DrawBMP.c" in this example appears windows library (I attached this file)

Finally aboud SRAM or SDRAM Im using LPCXpresso54608 board, I suppose it has SDRAM because  examples lcd_accel_tft16bpp and emc_sdram use it.

I attach some examples uploaded by someone else here(DRAW_BMP_JPG_PNG_0.c).

To correspond to my request I would like to share an emwin project that works on the LPCXpresso54608 board Space Evader, you just have to créate an emwin example project in MCUXpreso and copy this files into rar file over source folder in the mentioned example.

Could any body help me?

I would like to see an example of doing this with GUI_BMP_DrawEx() function

0 Kudos

811 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Oscar Nino,

   Thanks for your updated information!

   Please also provide the original BMP picture,I also need to check whether the data is correct.

  Then I will test it on my LPC54608 board.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

811 Views
oscarniño
Contributor III

Hi Kerry Zhou

Thanks for reply, I attached my MCUXpresso project and bitmap files.

Best regards

0 Kudos