google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.06k stars 129 forks source link

RGB/BGR 16 bit treated like RGBA/BGRA? #115

Open pmsoftware78 opened 1 year ago

pmsoftware78 commented 1 year ago

why PNG color_type == 2 (so RGB triple) in the file

https://github.com/google/wuffs/blob/main/std/png/decode_png.wuffs

} else if this.depth == 16 { this.dst_pixfmt = base.PIXEL_FORMATBGRA_NONPREMUL_4X16LE this.src_pixfmt = base.PIXEL_FORMATBGRA_NONPREMUL_4X16LE this.filter_distance = 6 choose filter_and_swizzle = [filter_and_swizzle_tricky] }

is treated like BGRA_NONPREMUL_4X16LE plus swizzle instead of a PIXEL_FORMAT__BGR_16LE?

Best Paolo

nigeltao commented 1 year ago

Because functions like wuffs_base__pixel_buffer__set_color_u32_at support WUFFS_BASE__PIXEL_FORMAT__BGRA_NONPREMUL_4X16LE (see link below) but do not support WUFFS_BASE__PIXEL_FORMAT__BGR_16LE. The latter is rare enough that optimizing for it is not a priority. Supporting N different pixel formats means that the pixel swizzler code (converting from one pixel format to another) needs roughly N*N different code paths.

https://github.com/google/wuffs/blob/bc86394bef64551ce483f6680aab76ef05263c8e/internal/cgen/base/pixconv-submodule.c#L202