8000 Support different encodings in Image.toByteData() · Issue #16635 · flutter/flutter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Support different encodings in Image.toByteData() #16635
Closed
flutter/engine
#5060
@tvolkert

Description

@tvolkert

Use case A: raw bytes in their native form

Image.toByteData() currently returns the raw image bytes in RGBA form. For images that are encoded in a different native format (e.g. grayscale), this means we go through a potentially expensive and wasteful conversion to RGBA.

Use case B: encoded bytes (PNG)

Further, there's a chance we could support PNG encoding and tree-shake Skia's support for the other encoders (jpeg, gif, webp, etc.), thus avoiding significant binary size bloat that would otherwise come with taking on the dependency on image encoding (for history, flutter/engine#4762 added Image.toByteData() with encoding support, but the encoding support was removed due to #16537).

Proposal

We could satisfy both these uses with the following API:

enum ImageEncodingFormat {
  /// Unencoded bytes, in RGBA form (kRGBA_8888_SkColorType)
  rawRgba,

  /// Unencoded bytes, in whatever form they exist within the image
  /// (e.g. kGray_8_SkColorType)
  rawNative,

   /// PNG encoding
  png,
}

class Image {
  Future<ByteData> toByteData({ImageEncodingFormat format: ImageEncodingFormat.rawRgba})
}

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityengineflutter/engine repository. See also e: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0