konifar / android-material-design-icon-generator-plugin

This plugin help you to set material design icon to your project.
Apache License 2.0
2.41k stars 239 forks source link

Fix unsupported png format issue #47

Closed yaeda closed 8 years ago

yaeda commented 8 years ago

Fix #40

My rough investigation found png file format difference and ImageIO's strange behavior, and I added a tiny workaround for this issue.

Icon PNG File Format

PNG has several formats to optimize file size. Following table shows Bit Depth and Color Type of ic_add_white_<xx>dp.png under src/com/konifar/material_icon_generator/icons/content/drawable-xxhdpi

File 18dp 24dp 36dp 48 dp
Size 54x54 72x72 108x108 144x144
Bit Depth 8 1 4 1
Color Type 4 0 3 0

Color Type 4 means grayscale + alpha Color Type 3 means indexed color with pallet Color Type 0 means just grayscale (alpha information stored in tRNS chunk)

Please look ic_add_white_24dp.png and ic_add_white_48dp.png. They have only two kind of pixels. 0x00FFFFFF or 0xFF000000.

ImageIO behavior

All material icons have alpha channel, but it disappears for some files such as ic_add_white_24dp and 48dp. hasAlpha() returns false.

I didn't check all of icons but I think this issue occurs in the file which has 0 color type.

Workaround

I think there are three options to fix this issue.

  1. Convert material icon png format using ffmpeg (or other good tool)
  2. Use third party png library instead of ImageIO
  3. Add tiny workaround

This PR realizes option 3 like this,

If getAlpha() returns false, check 0xFF000000 or not to calculate alpha value.

Reference

Thanks for reading and sorry for my loooong explanation.... :bow:

konifar commented 8 years ago

:eyes:

konifar commented 8 years ago

I'm sorry for late review :bow: And thanks for your detailed explanation and great fix! To be honest, I'm not sure that this fix is the best or not. But I could check that some icons are fixed.

So I'll merge this PR! Thanks again!