STM32 - How does OLED_SetPixel work ?

Thread Starter

Xenon02

Joined Feb 24, 2021
504
Your mistake is in believing that buffor[ ] and bitmap[ ] are the same. They are not the same and they are not compatible.
buffor[ ] has one byte for each pixel. Each pixel can have any one of 256 colours.
bitmap[ ] has one byte for eight pixels. Each pixel is one bit and can have only two colours, white or black.
buffor size if 1024.
The picture is 128x64 which in total is 8 192, now each byte has 8 bits we have in result 1024. The bitmap size is 1024 so each byte has 8 pixels, it also happens that buffor size is also 1024.
The way the buffor stores the information is also shown in post #15, which only shows that the byte is copied.

In other hand the SetPixel is very used for writing char character I won't deny because for 6x8 font used from github link, uses the 2 byte - 1 char thing and not typical 1 byte 1 char (don;t ask me why I don't know). And it has to be decoded from 2 byte into 1 byte and then sent to the buffor so the SetPixel works well there. But in DrawBitmap it is just copy and paste.

For colors it would make sense that 1 byte is just a color for 1 pixel but in the povided code it just copy and paste from provided byte to the buffor byte.
 

MrChips

Joined Oct 2, 2009
34,810
If buffer[ ] and bitmap[ ] are the same size and the data is formatted in the same way then you don't need both and you don't need both OLED_SetPixel( ) and OLED_DrawBitmap( ) functions.

Maybe OLED_DrawBitmap( ) is used to transfer a ready-made text character or icon into the OLED buffer[ ].
 

Thread Starter

Xenon02

Joined Feb 24, 2021
504
If buffer[ ] and bitmap[ ] are the same size and the data is formatted in the same way then you don't need both and you don't need both OLED_SetPixel( ) and OLED_DrawBitmap( ) functions.

Maybe OLED_DrawBitmap( ) is used to transfer a ready-made text character or icon into the OLED buffer[ ].
Maybe maybe, it is just that OLED_DrawBitmap( ) has inside of him OLED_SetPixel( ), which I didn't say to use both OLED_SetPixel( ) and OLED_DrawBitmap( ) seperatelly, I just stated that OLED_DrawBitmap( ) isn't really much necessary.
And could just the array bitmap send straight to the OLED. Which would take less code and less time to terminate the code.

All in all what I was trying to say is that bitmap array doesn't need to be putted into OLED_DrawBitmap( ) because bitmap array is already set to be sent straight to the OLED. OLED_SetPixel( ) might be usefull if the data has more than 1 byte then it has to be changed from n-byte data to 1 byte data for the buffer which makes sense.

Well I think I figured out that OLED_DrawBitmap( ) is just unnecessary.
Or perhaps the only data that is sent to the OLED is only from buffer and no any arrays can be sent in this library which only then makes sense. But still it could be easier done just by doing 1 for statement in which bitmap = buffor, because the buffor is global array so no problem.
 

MrChips

Joined Oct 2, 2009
34,810
I think OLED_DrawBitmap( ) is a useful function.
OLED_SetPixel( ) is used to set or clear individual bits in the OLED display.
OLED_DrawBitmap is used to transfer a rectangular icon, sprite or character of any size over to the OLED display at any defined position. It is used when you have many different characters, etc., not just a single bitmap character.

There is only one OLED buffer[ ]. You can have many different bitmaps of icons or characters. This is why a pointer to the bitmap is passed to OLED_DrawBitmap( ) in the list of arguments.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
504
There is only one OLED buffer[ ]. You can have many different bitmaps of icons or characters. This is why a pointer to the bitmap is passed to OLED_DrawBitmap( ) in the list of arguments.
Okey but still isn't it better to just write buffer = bitmap ? Or am I right that it is the same ?
They have the same content like I've observed. But when it comes to many bitmaps hmmm. It still needs an variable that controlls which bitmap is used and a variable that know when the whole data was transfered (even the OLED_DrawBitmap needs time and my method as well).

My suggestion also is universal for any sprite because it is buffer = bitmap the function OLED_DrawBitmap give literally the same result ;> But has more code which I think takes the code to terminate longer.
 

BobTPH

Joined Jun 5, 2013
11,515
post #24 until you understand what he is saying.
My suggestion also is universal for any sprite because it is buffer = bitmap the function OLED_DrawBitmap give literally the same result ;> But has more code which I think takes the code to terminate longer.
Only if you are drawing the entire screen. Read @MrChips post #24 until you get what he is saying.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
504
Only if you are drawing the entire screen. Read @MrChips post #24 until you get what he is saying.
Well When looking at it when the picture is not on full size which is 128x64 then this OLED_DrawBitmap makes sense if the person want to center the picture or something.
 

Thread Starter

Xenon02

Joined Feb 24, 2021
504
Suppose you wanted to display "Hello World!" on a bit-mapped graphics screen, how would you do it?

View attachment 306100
For Characters they have specific font library I've found, and they have separate function for it so I knew that SetPixel was pretty good there.

But with Bitmap BobTPH said that indeed if it's the full size picture then OLED bitmap function is inecessery but for not full size like less than 128x64 then it makes sense if the person want to center the picture or something.

Doing the single char can be made if we know the size of character. Let's say letter "W", 5 pixel wide and 7 pixel height. So each byte is 8 pixel height so we have 5 byte for 1 letter. 1st byte would be 011111110 , 2nd 00000001, 3rd 00001110, 4th 00000001, 5th 011111110. That's for first letter and manually goes with the rest of the letters but if we have the library for fonts I guess it could work making a special functon for strings and special function for char.

I don't know how it would work for string in a font librabry because each letter is located in different place in the array but basically this is the basic idea if it comes to manual fun for 6x8 font as I can see here.

I can say I understand a bit how bitmap function works and for what it is there (for changing the position of picture in the OLED screen)
 

MrChips

Joined Oct 2, 2009
34,810
We are not discussing string functions or built-in text libraries.
We are discussing drawing any sized bitmap at any location on the graphics screen.
Look at the parameter list of the OLED_DrawBitmap( ) function.

void OLED_DrawBitmap(uint8_t x, uint8_t y, bool invert_color, uint8_t width, uint8_t height, const uint8_t* bitmap)
Why do you think that you need to specify x, y, width and height in the arguments of the call statement?
 
Top