Add SkJpegGainmapEncoder::EncodeJpegR and EncodeHDRGM

Reland this patch with a default second argument for
skjpeg_destination_mgr, to avoid breaking code that uses that
interface.

Add a SkJpegGainmapEncoder class that is a friend of SkJpegEncoder and
add the functions SkJpegGainmapEncoder::EncodeJpegR and EncodeHDRGM.

This requires adding two new pieces of data to the SkJpegEncoder.
First is a list of new segments. For both JpegR and HDRGM, this
includes the XMP metadata. For HDRM this includes segments for the
encoded gainmap image. Second is a "suffix" to append to the end of
the base image. For JpegR, this is the encoded gainmap image.

Send the new segments to jpeg_write_marker (just like is currently
done for the ICC profile).

Plumb the "suffix" through to the skjpeg_destination_mgr, to be
appended after image is done writing (but before the stream is
flushed).

In both EncodeJpegR and EncodeHDRGM function, hard-code the XMP
metadata string (rather than constructing and serializing an SkDOM).

Include the math to transcode from any gainmap representation to
JpegR.

Add a test that transcodes an MPF gainmap image to a JpegR and
HDRGM image, and ensures that the rendered results are the same (up
to rounding error).

Bug: skia:14031
Change-Id: Ife54b83f703b785ae151106d5f7a01010d21a1d1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/633459
Commit-Queue: Christopher Cameron <ccameron@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
8 files changed