javl / image2cpp

GNU General Public License v3.0
529 stars 156 forks source link

Small image issue #21

Closed msigman closed 5 years ago

msigman commented 5 years ago

First off, great tool and thanks for making it available to us. I see there have been a few similar issues in the past but I couldn't find a resolution, and I appear to be having the same issue.

Trying to convert an image into a small icon and display on a tiny 128x32 OLED driven by an ESP8266 via Adafruit GFX library. I've verified some other images work as expected, but can't get the one I actually want to work.

Icon size after conversion by your tool is 17x13.

Original image: stock-vector-wifi-icon-wifi-icon-vector-in-trendy-flat-style-isolated-on-white-background-wifi-icon-image-745294486

The converted output from your tool (scaled down and inverted colors): download

And the byte code:

const unsigned char PROGMEM wifi2 [] = {
  0x07, 0xf0, 0x0f, 0xfe, 0x1f, 0x07, 0xde, 0x00, 0xf4, 0x00, 0x10, 0x3f, 0x80, 0x7f, 0xf0, 0x18,
  0x30, 0x00, 0x00, 0x01, 0xf0, 0x00, 0x70, 0x00, 0x10, 0x00, 0x00, 0x07
};
display.drawBitmap(110, 19, wifi2, 17, 13, WHITE);

However the actual output from my OLED is below. I tried Horizontal and Vertical already. Any thoughts? img_0033

javl commented 5 years ago

You mentioned other images did work; were they the same size, on the same device and generated with the same tool?

Could you try something for me: can you try the image on a couple of sizes to see if the problem appears below a certain size? Maybe try it at 32x32 to start with for instance. The scaled image won't look good, but you should be able to see if the drawn image looks the same as in the tool.

msigman commented 5 years ago

No -- the other ones were either different sizes or ones I grabbed from your other troubleshooting threads to test with. Per your request I ran the same image I started with through several sizes...

32x32 = Works 16x16 = Works 17x12 = Failed 19x12 = Failed 19x19 = Failed 22x16 = Failed 32x32 = Reconfirmed works 30x30 = Failed 31x31 = Failed 16x11 = Works

I can't find a pattern but the dimensions clearly make a difference on whether it renders or not...

javl commented 5 years ago

All non-square images you tried are horizontal (width > height), could you try one or two more with the numbers flipped? Like 12x17? I'll see if I can hook up a display here and give it a quick try. Getting tired of these small images not working and really want to get it fixed ;)

javl commented 5 years ago

At 32x32 the image works fine, but when I use 31x32 you can clearly see the problem; some offset gets introduced, distorting the image. image

javl commented 5 years ago

Weird, it seems only values that are multiples of 8 work. Technically this make sense, as the script converts every 8 bits of color into a byte, but how was this never caught by anyone else? Not sure if this is something that was introduced in an update or if it has always worked like this.

edit: ok, just confirmed this error has been there all along.

javl commented 5 years ago

This should finally fix the problem with small images getting distorted. Problem appears to have been that with some sizes (basically everything that wasn't divisible by 8) the last part of a row would be merged with the first part of the next row, creating an offset that increased with every next row.

This update pads every last byte of a row with zeros to fill out to 8 bits.

@msigman A clear description of the problem, the used image and a photo of the result on your display, together with testing some different sizes for me really helped me realize what the problem. was. Thanks!

msigman commented 5 years ago

Glad we got it solved! (Confirmed working now)

Cheers