Closed
Description
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})
}