[rust png] Round-trip `kOpaque_SkAlphaType` when encoding.
This CL makes 2 related changes in `SkPngRustEncoderImpl.cpp`:
* It changes how `rustEncoderColorType` is calculated so that RGB
encoding is used when the input is an opaque RGBA image. This mimics
similar code in `SkPngEncoderMgr::setHeader` in
`src/encode/SkPngEncoderImpl.cpp` - see
https://source.chromium.org/chromium/chromium/src/+/main:third_party/skia/src/encode/SkPngEncoderImpl.cpp;l=138-139;drc=25bba45c7b253ed3a735ae6c6d32173fbf5cc9e7
* It changes `SkPngRustEncoderImpl::onEncodeRow` to transform RGBA/RGBX
pixels into RGB pixels before feeding them into the encoder. This
mimics (at least at the conceptutal level) how
`SkPngEncoderMgr::writeInfo` uses `png_set_filler` to ask `libpng` to
perform the same transformation.
Note that the RGBA/RGBX=>RGB transformation used to be handled in the
`SkPngEncoderBase::onEncodeRows` layer (before
https://crrev.com/c/6489030 - see https://crbug.com/419011374#comment3).
This is difficult to do today, because `SkColorType` (as part of
`SkPngEncoderBase::TargetInfo::fDstRowInfo`) doesn't have a
variant/enumerator that represents RGB - this means that when
`SkPngEncoderBase::onEncodeRows` calls `SkConvertPixels` it is unable to
ask for the transformation that we need.
These changes are needed to pass the
`PNGCodec.EncoderSavesImagesWithAllOpaquePixelsAsOpaque` test in
Chromium's `gfx_unittests` when Rust PNG is used everywhere by default.
Bug: chromium:419011374
Change-Id: I9d6ecccf15f43c166836390642504ddc1781df5f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/997836
Reviewed-by: Florin Malita <fmalita@google.com>
Reviewed-by: Daniel Dilan <danieldilan@google.com>
Commit-Queue: Ćukasz Anforowicz <lukasza@google.com>
3 files changed