GainMap
The gain map of an Ultra HDR JPEG (#130): a second, small JPEG after the main image that tells an HDR screen how much brighter each area of the photo may be drawn. ImageKodec.readMetadata finds it through the Multi-Picture Format segment of the main image, and an encodeJpeg with the metadata writes it again after the new main image, with an MPF segment that points to it.
A gain map covers the whole main image at any resolution, so it stays valid while the main image keeps its aspect ratio and its orientation. ImageMetadata.upright turns it with the pixels; an encode of a bitmap of another aspect ratio, a crop for one, leaves it out together with the HDR fields of the XMP packet.
Throws
when jpeg is not a JPEG whose size can be read