lwillmeth / ASCII_Art

Convert a single image to ASCII artwork
GNU General Public License v3.0
2 stars 1 forks source link

Graphics with transparent backgrounds cause ascii to look bad. #13

Open lwillmeth opened 10 years ago

lwillmeth commented 10 years ago

The transparent part should be interpreted as white, otherwise it looks funky.

lwillmeth commented 10 years ago

I'm pretty sure the problem is that convertImageToAscii() is not properly ignoring the alpha bits even though it looks to me as though it should be.

I believe the problem lies in this line: block_avg += (((rgb>>16)&0xFF) + ((rgb>>8)&0xFF) + (rgb&0xFF) )/3;

I thought by bit shifting 16 bits to the right, I would discard green and blue, and by masking with 0xFF I would discard the bit to the left, leaving me with just red. But I suspect the problem is that's not what's happening. The alpha channel is somehow being included and it's raising the average until every block with an alpha background becomes very near to the 'darkest' character, '@'.

I need to do some testing to figure this out for sure, just leaving a note for posterity.

lwillmeth commented 10 years ago

I temporarily fixed the problem by interpreting fully transparent pixels as pure white, but the problem remains for partially transparent pixels. I think the problem could be better fixed by multiplying the color by the alpha channel to interpret the color as a reduced percentage of the original, so if nearly white is 250 and it's half translucent (~125) it would be 250*(256/125)=~125

The problem with that is, 125 is actually "darker" than 256, so we need a formula that trends towards 256, not away from it. I haven't come up with such a formula yet, but I'm thinking it over.