Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for WEBP or PNG with transparency to Tiles image helpers #251

Open
yschimke opened this issue Jun 20, 2022 · 3 comments
Open
Labels
good first issue Good for newcomers Tiles Tile related (templates, images, previews)

Comments

@yschimke
Copy link
Collaborator

yschimke commented Jun 20, 2022

The current conversion code for bitmaps and canvas elements to Tile ImageResources, uses RGB_565.

public fun Bitmap.toImageResource(): ImageResource {

This is safe format, but requires extra work and also does not support alpha channel.

We should add a flag to support other formats including png, webp.

This probably involves removing hard coded format when flag is set

setFormat(ResourceBuilders.IMAGE_FORMAT_RGB_565)

and use, or other conversion code.

    val bytes = ByteArrayOutputStream().apply {
        compress(Bitmap.CompressFormat.PNG, 100, this)
    }.toByteArray()

We can assume Coil for our conversion code if it helps, and to start with avoiding conversions, but to be confirmed.

A later change might be also this code path https://github.com/google/horologist/blob/2f15272f92291bcdbdacd66b1042e42802c45cb7/tiles/src/main/java/com/google/android/horologist/tiles/canvas/canvas.kt

@yschimke
Copy link
Collaborator Author

cc @ataulm

@yschimke yschimke added the good first issue Good for newcomers label Jul 10, 2022
@yschimke
Copy link
Collaborator Author

We should make this a flag, useRgb565?

Current logic when useRgb565.

When not useRgb565, remove setFormat, and pass through the existing bytes. Tile rendering should ask the system to decode.

Samples should show a png, webp or jpg working without conversion.

@ataulm
Copy link
Contributor

ataulm commented Jul 11, 2022

I think for a "good first issue" this needs more context:

  • what's the problem and which APIs does this affect currently?
  • Are we talking only about this function? Or will further changes need to be made elsewhere?
  • is this something that we can do without exposing a flag/new API? e.g. detect the type of the image and convert it with the correct compression?
  • are there similar APIs in well-established libraries like Coil, Glide and Picasso that we should follow?

@yschimke yschimke added the Tiles Tile related (templates, images, previews) label Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers Tiles Tile related (templates, images, previews)
Projects
None yet
Development

No branches or pull requests

2 participants