summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-02-07 15:15:55 -0500
committerLinus Groh <mail@linusgroh.de>2023-02-08 16:35:57 +0000
commit8bd64f001cde327d5c2b6f3ba90d9c31d29d8934 (patch)
tree12d1bb78fb9e6eee90be91d91ed06f160ef55981 /Userland/Libraries
parentcbcf8471a625b485748764886c27012ac6786570 (diff)
downloadserenity-8bd64f001cde327d5c2b6f3ba90d9c31d29d8934.zip
LibGfx+icc: Read signatureType
This isn't used by any mandatory tags, and it's not terribly useful. But jpegs exported by Lightroom Classic write the 'tech' tag, and it seems nice to be able to dump its contents. signatureType stores a single u32 which for different tags with this type means different things. In each case, the value is one from a short table of valid values, suggesting this should be a per-tag enum class instead of a per-tag DistinctFourCC, per the comment at the top of DistincFourCC.h. On the other hand, 3 of the 4 tables have an explicit "It is possible that the ICC will define other signature values in the future" note, which suggests the FourCC might actually be the way to go. For now, just punt on that and manually dump the u32 in fourcc style in icc.cpp and don't add any to_string() methods that return a readable string based on the contents of these tables.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibGfx/ICC/Profile.cpp14
-rw-r--r--Userland/Libraries/LibGfx/ICC/TagTypes.cpp14
-rw-r--r--Userland/Libraries/LibGfx/ICC/TagTypes.h19
3 files changed, 43 insertions, 4 deletions
diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp
index b3f96177e8..f4d5a8cedc 100644
--- a/Userland/Libraries/LibGfx/ICC/Profile.cpp
+++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp
@@ -586,6 +586,8 @@ ErrorOr<NonnullRefPtr<TagData>> Profile::read_tag(ReadonlyBytes bytes, u32 offse
return ParametricCurveTagData::from_bytes(tag_bytes, offset_to_beginning_of_tag_data_element, size_of_tag_data_element);
case S15Fixed16ArrayTagData::Type:
return S15Fixed16ArrayTagData::from_bytes(tag_bytes, offset_to_beginning_of_tag_data_element, size_of_tag_data_element);
+ case SignatureTagData::Type:
+ return SignatureTagData::from_bytes(tag_bytes, offset_to_beginning_of_tag_data_element, size_of_tag_data_element);
case TextDescriptionTagData::Type:
return TextDescriptionTagData::from_bytes(tag_bytes, offset_to_beginning_of_tag_data_element, size_of_tag_data_element);
case TextTagData::Type:
@@ -992,7 +994,8 @@ ErrorOr<void> Profile::check_tag_types()
// ICC v4, 9.2.21 colorimetricIntentImageStateTag
// "Permitted tag types: signatureType"
- // FIXME
+ if (!has_type(colorimetricIntentImageStateTag, { SignatureTagData::Type }, {}))
+ return Error::from_string_literal("ICC::Profile: colorimetricIntentImageStateTag has unexpected type");
// ICC v4, 9.2.22 copyrightTag
// "Permitted tag types: multiLocalizedUnicodeType"
@@ -1154,7 +1157,8 @@ ErrorOr<void> Profile::check_tag_types()
// ICC v4, 9.2.39 perceptualRenderingIntentGamutTag
// "Permitted tag types: signatureType"
- // FIXME
+ if (!has_type(perceptualRenderingIntentGamutTag, { SignatureTagData::Type }, {}))
+ return Error::from_string_literal("ICC::Profile: perceptualRenderingIntentGamutTag has unexpected type");
// ICC v4, 9.2.40 preview0Tag
// "Permitted tag types: lut8Type or lut16Type or lutAToBType or lutBToAType"
@@ -1220,11 +1224,13 @@ ErrorOr<void> Profile::check_tag_types()
// ICC v4, 9.2.48 saturationRenderingIntentGamutTag
// "Permitted tag types: signatureType"
- // FIXME
+ if (!has_type(saturationRenderingIntentGamutTag, { SignatureTagData::Type }, {}))
+ return Error::from_string_literal("ICC::Profile: saturationRenderingIntentGamutTag has unexpected type");
// ICC v4, 9.2.49 technologyTag
// "Permitted tag types: signatureType"
- // FIXME
+ if (!has_type(technologyTag, { SignatureTagData::Type }, {}))
+ return Error::from_string_literal("ICC::Profile: technologyTag has unexpected type");
// ICC v4, 9.2.50 viewingCondDescTag
// "Permitted tag types: multiLocalizedUnicodeType"
diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp
index 7ddf2db61d..d29321a7ea 100644
--- a/Userland/Libraries/LibGfx/ICC/TagTypes.cpp
+++ b/Userland/Libraries/LibGfx/ICC/TagTypes.cpp
@@ -530,6 +530,20 @@ ErrorOr<NonnullRefPtr<TextDescriptionTagData>> TextDescriptionTagData::from_byte
return adopt_ref(*new TextDescriptionTagData(offset, size, TRY(String::from_utf8(ascii_description)), unicode_language_code, move(unicode_description), move(macintosh_description)));
}
+ErrorOr<NonnullRefPtr<SignatureTagData>> SignatureTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
+{
+ // ICC v4, 10.23 signatureType
+ VERIFY(tag_type(bytes) == Type);
+ TRY(check_reserved(bytes));
+
+ if (bytes.size() < 3 * sizeof(u32))
+ return Error::from_string_literal("ICC::Profile: signatureType has not enough data");
+
+ u32 signature = *bit_cast<BigEndian<u32> const*>(bytes.data() + 8);
+
+ return adopt_ref(*new SignatureTagData(offset, size, signature));
+}
+
ErrorOr<NonnullRefPtr<TextTagData>> TextTagData::from_bytes(ReadonlyBytes bytes, u32 offset, u32 size)
{
// ICC v4, 10.24 textType
diff --git a/Userland/Libraries/LibGfx/ICC/TagTypes.h b/Userland/Libraries/LibGfx/ICC/TagTypes.h
index 9fd56484c0..9c3b3969a4 100644
--- a/Userland/Libraries/LibGfx/ICC/TagTypes.h
+++ b/Userland/Libraries/LibGfx/ICC/TagTypes.h
@@ -464,6 +464,25 @@ private:
Optional<String> m_macintosh_description;
};
+// ICC v4, 10.23 signatureType
+class SignatureTagData : public TagData {
+public:
+ static constexpr TagTypeSignature Type { 0x73696720 }; // 'sig '
+
+ static ErrorOr<NonnullRefPtr<SignatureTagData>> from_bytes(ReadonlyBytes, u32 offset, u32 size);
+
+ SignatureTagData(u32 offset, u32 size, u32 signature)
+ : TagData(offset, size, Type)
+ , m_signature(signature)
+ {
+ }
+
+ u32 signature() const { return m_signature; }
+
+private:
+ u32 m_signature;
+};
+
// ICC v4, 10.24 textType
class TextTagData : public TagData {
public: