Remove APP15-based gainmap support
This never became an official format, and it was a surprise to see that
it hadn't been removed.
Bug: b/338342146
Change-Id: I450eab328e1ff59d54dddb31090c35b4417ce68d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/849336
Commit-Queue: Christopher Cameron <ccameron@google.com>
Reviewed-by: Christopher Cameron <ccameron@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/resources/BUILD.bazel b/resources/BUILD.bazel
index 2e61403..342f941 100644
--- a/resources/BUILD.bazel
+++ b/resources/BUILD.bazel
@@ -157,7 +157,6 @@
"images/grayscale.png",
"images/half-transparent-white-pixel.png",
"images/half-transparent-white-pixel.webp",
- "images/hdrgm.jpg",
"images/icc-v2-gbr.jpg",
"images/iconstrip.png",
"images/index8.png",
diff --git a/resources/images/hdrgm.jpg b/resources/images/hdrgm.jpg
deleted file mode 100644
index ef6d4b0..0000000
--- a/resources/images/hdrgm.jpg
+++ /dev/null
Binary files differ
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index 773a918..5563f67 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -274,7 +274,6 @@
jpeg_save_markers(dinfo, kExifMarker, 0xFFFF);
jpeg_save_markers(dinfo, kICCMarker, 0xFFFF);
jpeg_save_markers(dinfo, kMpfMarker, 0xFFFF);
- jpeg_save_markers(dinfo, kGainmapMarker, 0xFFFF);
}
// Read the jpeg header
@@ -1215,7 +1214,7 @@
SkJpegSourceMgr* sourceMgr,
SkGainmapInfo* info,
std::unique_ptr<SkStream>* gainmapImageStream) {
- // The GContainer and APP15-based HDRGM formats require XMP metadata. Extract it now.
+ // All non-ISO formats require XMP metadata. Extract it now.
std::unique_ptr<SkXmp> xmp = get_xmp_metadata(markerList);
// Let |base_image_info| be the HDRGM gainmap information found in the base image (if any).
@@ -1279,26 +1278,6 @@
SkCodecPrintf("Failed to extract container-specified gainmap.\n");
}
- // Finally, attempt to extract SkGainmapInfo from the primary image's XMP and extract the
- // gainmap from APP15 segments.
- if (xmp && base_image_has_hdrgm) {
- auto gainmapData = read_metadata(markerList,
- kGainmapMarker,
- kGainmapSig,
- sizeof(kGainmapSig),
- /*signaturePadding=*/0,
- kGainmapMarkerIndexSize,
- /*alwaysCopyData=*/true);
- if (gainmapData) {
- *gainmapImageStream = SkMemoryStream::Make(std::move(gainmapData));
- if (*gainmapImageStream) {
- *info = base_image_info;
- return true;
- }
- } else {
- SkCodecPrintf("Parsed HDRGM metadata but did not find image\n");
- }
- }
return false;
}
diff --git a/src/codec/SkJpegConstants.h b/src/codec/SkJpegConstants.h
index cfcbad1..eeb3276 100644
--- a/src/codec/SkJpegConstants.h
+++ b/src/codec/SkJpegConstants.h
@@ -42,13 +42,6 @@
'I', 'C', 'C', '_', 'P', 'R', 'O', 'F', 'I', 'L', 'E', '\0',
};
-// HDR gainmap segment marker and signature.
-static constexpr uint32_t kGainmapMarker = kJpegMarkerAPP0 + 15;
-static constexpr uint32_t kGainmapMarkerIndexSize = 2;
-static constexpr uint8_t kGainmapSig[] = {
- 'H', 'D', 'R', '_', 'G', 'A', 'I', 'N', '_', 'M', 'A', 'P', '\0',
-};
-
// XMP segment marker and signature.
static constexpr uint32_t kXMPMarker = kJpegMarkerAPP0 + 1;
static constexpr uint8_t kXMPStandardSig[] = {
diff --git a/src/encode/SkJpegGainmapEncoder.cpp b/src/encode/SkJpegGainmapEncoder.cpp
index 710f71d..66c2567 100644
--- a/src/encode/SkJpegGainmapEncoder.cpp
+++ b/src/encode/SkJpegGainmapEncoder.cpp
@@ -156,69 +156,6 @@
return s.detachAsData();
}
-// Split an SkData into segments.
-std::vector<sk_sp<SkData>> get_hdrgm_image_segments(sk_sp<SkData> image,
- size_t segmentMaxDataSize) {
- // Compute the total size of the header to a gainmap image segment (not including the 2 bytes
- // for the segment size, which the encoder is responsible for writing).
- constexpr size_t kGainmapHeaderSize = sizeof(kGainmapSig) + 2 * kGainmapMarkerIndexSize;
-
- // Compute the payload size for each segment.
- const size_t kGainmapPayloadSize = segmentMaxDataSize - kGainmapHeaderSize;
-
- // Compute the number of segments we'll need.
- const size_t segmentCount = (image->size() + kGainmapPayloadSize - 1) / kGainmapPayloadSize;
- std::vector<sk_sp<SkData>> result;
- result.reserve(segmentCount);
-
- // Move |imageData| through |image| until it hits |imageDataEnd|.
- const uint8_t* imageData = image->bytes();
- const uint8_t* imageDataEnd = image->bytes() + image->size();
- while (imageData < imageDataEnd) {
- SkDynamicMemoryWStream segmentStream;
-
- // Write the signature.
- segmentStream.write(kGainmapSig, sizeof(kGainmapSig));
-
- // Write the segment index as big-endian.
- size_t segmentIndex = result.size() + 1;
- uint8_t segmentIndexBytes[2] = {
- static_cast<uint8_t>(segmentIndex / 256u),
- static_cast<uint8_t>(segmentIndex % 256u),
- };
- segmentStream.write(segmentIndexBytes, sizeof(segmentIndexBytes));
-
- // Write the segment count as big-endian.
- uint8_t segmentCountBytes[2] = {
- static_cast<uint8_t>(segmentCount / 256u),
- static_cast<uint8_t>(segmentCount % 256u),
- };
- segmentStream.write(segmentCountBytes, sizeof(segmentCountBytes));
-
- // Verify that our header size math is correct.
- SkASSERT(segmentStream.bytesWritten() == kGainmapHeaderSize);
-
- // Write the rest of the segment.
- size_t bytesToWrite =
- std::min(imageDataEnd - imageData, static_cast<intptr_t>(kGainmapPayloadSize));
- segmentStream.write(imageData, bytesToWrite);
- imageData += bytesToWrite;
-
- // Verify that our data size math is correct.
- if (segmentIndex == segmentCount) {
- SkASSERT(segmentStream.bytesWritten() <= segmentMaxDataSize);
- } else {
- SkASSERT(segmentStream.bytesWritten() == segmentMaxDataSize);
- }
- result.push_back(segmentStream.detachAsData());
- }
-
- // Verify that our segment count math was correct.
- SkASSERT(imageData == imageDataEnd);
- SkASSERT(result.size() == segmentCount);
- return result;
-}
-
static sk_sp<SkData> encode_to_data(const SkPixmap& pm,
const SkJpegEncoder::Options& options,
SkData* xmpMetadata) {
diff --git a/tests/JpegGainmapTest.cpp b/tests/JpegGainmapTest.cpp
index 1a2a36d..427ee76 100644
--- a/tests/JpegGainmapTest.cpp
+++ b/tests/JpegGainmapTest.cpp
@@ -479,14 +479,6 @@
std::exp(1.f),
1.f,
2.71828f},
- {"images/hdrgm.jpg",
- SkISize::Make(188, 250),
- 0xFFE9E9E9,
- 0xFFAAAAAA,
- std::exp(-2.209409f),
- std::exp(2.209409f),
- 1.f,
- 9.110335f},
};
TestStream::Type kStreamTypes[] = {