Xinyuan-LilyGO / LilyGo-EPD47

GNU General Public License v3.0
379 stars 119 forks source link

Only images from example drawimages are working at this moment #84

Closed DjamesSuhanko closed 1 year ago

DjamesSuhanko commented 1 year ago

Hi! I'm Djames Suhanko, blogger of dobitaobyte.com.br. I would like to know which algorithm I should use to convert a RGB32 or RGB24 to grayscale 4 bits, as recommended in the sketch drawimage, included in examples directory. Another doubt related to that is on header of drawimages.ino sketch: Simple firmware for a ESP32 displaying a static image on an EPaper Screen. Write an image into a header file using a 3...2...1...0 format per pixel, for 4 bits color (16 colors - well, greys.) MSB first. At 80 MHz, screen clears execute in 1.075 seconds and images are drawn in 1.531 seconds. What this means? Do I need to shift right the most significant bits? To finish the main points, I saw in pic2.h (used as example here) the bytes values are very big to be for bits: pic2_data[(960*576)/2] = { 0xAA,... I made a program to convert RGB888 to RGB565, grayscale 8bits and monochrome and I will do articles and videos using this display to exemplify the grayscale usage. To exemplify monochrome I will use the TTGO and LilyGO T-Display. The program is free, I need only finish this conversion to share with all.

My program is made in Qt and I tried two types of grayscale, 8 and 16. So, I decided to write a loop to access pixels directly and my choice to do the conversion was luminance: QRgb target = this->localImage.pixel(i, j); QRgb lum = 0.2126f * qRed(target) + 0.7152f * qGreen(target) + 0.0722f * qBlue(target); After that, I shifted 4 bits to right: lum = (lum >> 4) This way, I have only 16 values. Ok, so, I write this value back to image, and now it's no more a RGB, as expected. Resuming: My Image is a array of a single byte for pixel. Where is my mistake? Could you help me to solve that, please?

asozio commented 1 year ago

Not 100% sure, but noticed you mentioned grayscale 4 bits (nibble), but your lum value is 16 values (single byte) Before writing the file, wouldn't you need to either convert your single byte lum into nibbles (4 bits) or merge two lum values (each 4 bits) into a single byte?

(Some examples of nibble/byte packing on https://stackoverflow.com/questions/23435258/fastest-way-to-pack-two-nibbles-into-one-byte)

DjamesSuhanko commented 1 year ago

Wow, I thank you for answer, asozio. It's a light to me, because I don't have idea how to convert it correctly. I will start read the link right now and back here to say what happened after try it.

DjamesSuhanko commented 1 year ago

Yupi! It's working! Thank you, @asozio ! My image is flipped but I will take a look better now. I didn't know about name "nibbles". Thank you for share this important knowledge with me!! display-working

asozio commented 1 year ago

Yupi! It's working! Thank you, @asozio ! My image is flipped but I will take a look better now. I didn't know about name "nibbles". Thank you for share this important knowledge with me!!

Glad I could help!

G6EJD commented 1 year ago

MSB first means Bigenden that means literally to send the MSB first, then next MSB and finally LSB