浏览代码

LibGfx/TIFF: Add an alternative entry point to only request metadata

A lot of images format use Exif to store there metadata. As Exif is
based on the TIFF structure, the TIFF decoder can, without modification
be able to decode the metadata. We only need a new API to explicitly
mention that we only need the metadata.
Lucas CHOLLET 1 年之前
父节点
当前提交
f6f647bf13

+ 8 - 0
Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp

@@ -622,4 +622,12 @@ ErrorOr<Optional<ReadonlyBytes>> TIFFImageDecoderPlugin::icc_data()
     return m_context->metadata().icc_profile().map([](auto const& buffer) -> ReadonlyBytes { return buffer.bytes(); });
     return m_context->metadata().icc_profile().map([](auto const& buffer) -> ReadonlyBytes { return buffer.bytes(); });
 }
 }
 
 
+ErrorOr<NonnullOwnPtr<ExifMetadata>> TIFFImageDecoderPlugin::read_exif_metadata(ReadonlyBytes data)
+{
+    auto stream = TRY(try_make<FixedMemoryStream>(data));
+    auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TIFFImageDecoderPlugin(move(stream))));
+    TRY(plugin->m_context->decode_image_header());
+    return try_make<ExifMetadata>(plugin->m_context->metadata());
+}
+
 }
 }

+ 4 - 0
Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.h

@@ -7,10 +7,13 @@
 #pragma once
 #pragma once
 
 
 #include <AK/MemoryStream.h>
 #include <AK/MemoryStream.h>
+#include <AK/NonnullOwnPtr.h>
 #include <LibGfx/ImageFormats/ImageDecoder.h>
 #include <LibGfx/ImageFormats/ImageDecoder.h>
 
 
 namespace Gfx {
 namespace Gfx {
 
 
+class ExifMetadata;
+
 // This is a link to the main TIFF specification from 1992
 // This is a link to the main TIFF specification from 1992
 // https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf
 // https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf
 
 
@@ -33,6 +36,7 @@ class TIFFImageDecoderPlugin : public ImageDecoderPlugin {
 public:
 public:
     static bool sniff(ReadonlyBytes);
     static bool sniff(ReadonlyBytes);
     static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
     static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
+    static ErrorOr<NonnullOwnPtr<ExifMetadata>> read_exif_metadata(ReadonlyBytes);
 
 
     virtual ~TIFFImageDecoderPlugin() override = default;
     virtual ~TIFFImageDecoderPlugin() override = default;