Page 1 of 3
picture rendering
Posted: Thu Jun 14, 2012 7:16 am
by Tectu
Hello Folks,
I've never done anything related to pictures, but I guess we want to be able to draw some pictures on the display as well, right?
I know that it shouldn't be that hard to draw a BMP file to the display. Did anyone ever do this, or would someone like to implement this feature into the library?
I once used a pre-made KS0108 library (GLCD, Black/White, 128x64 pixels) on an AVR. There you first had to convert the picture into a C array. I guess It shouldn't be a problem to read a "real BMP" from an SD card or any other external memory, right?
How does it look like with other picture formats. Would it take to much CPU power to draw a JPG or PNG?
~ Tectu
Re: picture rendering
Posted: Thu Jun 14, 2012 7:20 am
by Abhishek
You asked it, you got it!
Check out my code in the rep:
https://github.com/abhishek-kakkar/STM32F4PlayerIt also includes a demo to display a full-screen image from the SD Card. I've got a image converter written in C# to convert an image to RGB565 Big-Endian format.
I'll put more details.
PS: look into the main.c file for a function display_image(char* fn, uint16_t x, uint16_t y).
Re: picture rendering
Posted: Thu Jun 14, 2012 7:24 am
by Tectu
Nice, I'll take a closer look this evening.
Can I take this code, edit and put it in the library?

~ Tectu
Re: picture rendering
Posted: Thu Jun 14, 2012 7:38 am
by Abhishek
Sorry, It's just a demo right now. If you like, you may give it a try, but we'll talk about implementation in the library later.
I was just about to open this topic for discussion today. You gave it a head start!
We would need a lcdBlt() [Block Transfer function] in the API for this. Discussion in the driver section.
Regarding the performance, I measured the performance of my function with the HAL counter.
As of now, it takes about 20081596 cycles or about 120ms (~8.4 fps) for a full screen image, running on a F4Discovery @ 168MHz with a 2048 byte buffer. Pretty slow, considering max possible refresh rate as I mentioned earlier is 234fps. Actually before it was about 35000000 cycles, I optimized it by doing block-aligned reads from the SD Card. Increasing the buffer size definitely leads to a improvement in performance, with a 16K Buffer, it goes down to about 16007733 cycles (95 ms, 10.5 fps).
We need a better way out.
For JPEG files, I found a nice library from Chan, the maker of FatFS. Its called TJpgDec,
http://elm-chan.org/fsw/tjpgd/00index.htmlI'm looking forward to trying it out. Will share my code then.
Cheers!
Abhishek
Re: picture rendering
Posted: Thu Jun 14, 2012 7:44 am
by Tectu
I took a look at your code - I agree, we cannot directly use that.
Would you like to start developing some useful picture drawing function? It would be enough to take a pointer to a .bmp on an SD card first. Other features like scaling etc. are for the future.
I guess the first implementation of a bmp drawing function without special features shouldn't be that hard, right?
Feel free to add any neccessarry API, like the BlockTransferFunction. Please just try to keep the naming convention

I'd go with lcdWriteBlock(); or something similar.
~ Tectu
Re: picture rendering
Posted: Fri Jun 15, 2012 7:33 am
by Abhishek
I've been able to read and display 24-bit bitmaps from an SD Card onto the display.
As of now, the code is in a pretty rudimentary stage, however I am able to display full screen images successfully without any color abrupts, or missing pixels.
Bitmap implementation is quirky because the pixel data stored in the file starts from the bottom left corner after the header and goes up to the top right. Unlike the normal way, we're going top left to bottom right (which is more natural). Also there is padding to make rows aligned at a 4-byte boundary. This roughly means that unless you have width of bitmap a multiple of 4, it will cause trouble with the current implementation.
Also, rendering time has become about 1.5 times than what it was previously, proportionally. Looks like the SD Card is proving to be a bottleneck.
I will do a cleanup of code and push it soon.
Abhishek
Re: picture rendering
Posted: Mon Jun 25, 2012 1:31 pm
by Tectu
Do we have any process here yet, Abhishek?
~ Tectu
Re: picture rendering
Posted: Thu Jun 28, 2012 1:29 pm
by Anubirux
Hello guys !
I developed a function drawing a bmp file from sd card. Now it works only with 565 bitmaps however it's quite fast. Maximum refresh rate with my config (stm32f103@72MHz) using FSMC is around 83 fps (11-12 ms for 240*320 clear screen). My function needs around 25 ms to draw full screen image, so it gives refresh rate around 40 fps using 16kB circular buffer. It is still not completely optimized and a little messy but as I see it's much faster then yours previous functions ;P . I attach c file with it and prototype function
lcdStartWriteBuffer, for now it's just thread which preforms write to lcd but I plane to do it with DMA. Naming is different then in yours, cuz it's part from my own graph lib but I think that is not problem

If you have any problems with understanding code feel free to ask
https://dl.dropbox.com/u/14958487/drawBMP.c
Re: picture rendering
Posted: Thu Jun 28, 2012 1:44 pm
by Tectu
This is nice work! Thank you very much for sharing your code.
Maybe you could fork the repo
https://github.com/Tectu/ChibiOS-LCD-Driver, implement a working drawing function as best as you can and send a pull request?
You might talk to Abhishek. He begun to work on the same thing. Maybe you guys can work together.
~ Tectu
Re: picture rendering
Posted: Thu Jun 28, 2012 6:22 pm
by Abhishek
Hi Anubirux,
Nice to see some superfast bitmap rendering!
However IMHO, the only bottleneck that limits the speed of bitmap rendering is just the SD Card itself [With my current setup at 21MHz SPI, I can't expect to do more than the theoretically possible 2.625 MB/s, I just achieve about 1.5 MB/sec and that too with a 16K buffer

, so the slow speed ]. It isn't about the way we code (except ensuring that read occurs only at 512 byte sector or 'block' boundaries a.k.a "Block aligned reads" - which your code does pretty well, otherwise reading becomes toooo slow, read my previous posts to get an idea, and I'm sure you must also have experienced it while coding), remember, we're using a sufficiently fast ARM Processor!
So using your metrics, for 40fps bitmap rendering, and considering that a full screen 16bpp bitmap image is around 150KB in size, the read speed works out to about 6 MB/sec = 48 mbits/sec, assuming that writing each block to the LCD takes negligible time (not exactly, raw transfer rate should be faster). It's impossible with a SPI interface (only 18Mbits/sec on an F1 ). This definitely means, the performance improvement (no, jump) you're seeing is due to the simple fact that your SD card is connected via SDIO bus, not SPI

.
Also, to display 24-bit bitmaps, we'll have to process 1.5 times more data for the same image (convert RGB888 to RGB565 on the fly). That means on your set-up, refresh rate for a 24-bit bitmap should be about 26 fps.
This means I definitely need SDIO support on F4 discovery

, will consider a separate topic for this tomorrow, maybe in the support section.
Regards
Abhishek