TIFFLoader.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. /*
  2. * Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "TIFFLoader.h"
  7. #include <AK/ConstrainedStream.h>
  8. #include <AK/Debug.h>
  9. #include <AK/Endian.h>
  10. #include <AK/String.h>
  11. #include <LibCompress/LZWDecoder.h>
  12. #include <LibCompress/PackBitsDecoder.h>
  13. #include <LibCompress/Zlib.h>
  14. #include <LibGfx/ImageFormats/CCITTDecoder.h>
  15. #include <LibGfx/ImageFormats/ExifOrientedBitmap.h>
  16. #include <LibGfx/ImageFormats/TIFFMetadata.h>
  17. namespace Gfx {
  18. namespace TIFF {
  19. class TIFFLoadingContext {
  20. public:
  21. enum class State {
  22. NotDecoded = 0,
  23. Error,
  24. HeaderDecoded,
  25. FrameDecoded,
  26. };
  27. TIFFLoadingContext(NonnullOwnPtr<FixedMemoryStream> stream)
  28. : m_stream(move(stream))
  29. {
  30. }
  31. ErrorOr<void> decode_image_header()
  32. {
  33. TRY(read_image_file_header());
  34. TRY(read_next_image_file_directory());
  35. m_state = State::HeaderDecoded;
  36. return {};
  37. }
  38. ErrorOr<void> ensure_conditional_tags_are_present() const
  39. {
  40. if (m_metadata.photometric_interpretation() == PhotometricInterpretation::RGBPalette && !m_metadata.color_map().has_value())
  41. return Error::from_string_literal("TIFFImageDecoderPlugin: RGBPalette image doesn't contain a color map");
  42. return {};
  43. }
  44. ErrorOr<void> ensure_baseline_tags_are_correct() const
  45. {
  46. if (m_metadata.strip_offsets()->size() != m_metadata.strip_byte_counts()->size())
  47. return Error::from_string_literal("TIFFImageDecoderPlugin: StripsOffset and StripByteCount have different sizes");
  48. if (any_of(*m_metadata.bits_per_sample(), [](auto bit_depth) { return bit_depth == 0 || bit_depth > 32; }))
  49. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid value in BitsPerSample");
  50. return {};
  51. }
  52. ErrorOr<void> decode_frame()
  53. {
  54. TRY(ensure_baseline_tags_are_present(m_metadata));
  55. TRY(ensure_baseline_tags_are_correct());
  56. TRY(ensure_conditional_tags_are_present());
  57. auto maybe_error = decode_frame_impl();
  58. if (maybe_error.is_error()) {
  59. m_state = State::Error;
  60. return maybe_error.release_error();
  61. }
  62. return {};
  63. }
  64. IntSize size() const
  65. {
  66. return ExifOrientedBitmap::oriented_size({ *m_metadata.image_width(), *m_metadata.image_height() }, *m_metadata.orientation());
  67. }
  68. ExifMetadata const& metadata() const
  69. {
  70. return m_metadata;
  71. }
  72. State state() const
  73. {
  74. return m_state;
  75. }
  76. RefPtr<Bitmap> bitmap() const
  77. {
  78. return m_bitmap;
  79. }
  80. private:
  81. enum class ByteOrder {
  82. LittleEndian,
  83. BigEndian,
  84. };
  85. static ErrorOr<u8> read_component(BigEndianInputBitStream& stream, u8 bits)
  86. {
  87. // FIXME: This function truncates everything to 8-bits
  88. auto const value = TRY(stream.read_bits<u32>(bits));
  89. if (bits > 8)
  90. return value >> (bits - 8);
  91. return NumericLimits<u8>::max() * value / ((1 << bits) - 1);
  92. }
  93. u8 samples_for_photometric_interpretation() const
  94. {
  95. switch (*m_metadata.photometric_interpretation()) {
  96. case PhotometricInterpretation::WhiteIsZero:
  97. case PhotometricInterpretation::BlackIsZero:
  98. case PhotometricInterpretation::RGBPalette:
  99. return 1;
  100. case PhotometricInterpretation::RGB:
  101. return 3;
  102. default:
  103. TODO();
  104. }
  105. }
  106. Optional<u8> alpha_channel_index() const
  107. {
  108. if (m_metadata.extra_samples().has_value()) {
  109. auto const extra_samples = m_metadata.extra_samples().value();
  110. for (u8 i = 0; i < extra_samples.size(); ++i) {
  111. if (extra_samples[i] == ExtraSample::UnassociatedAlpha)
  112. return i + samples_for_photometric_interpretation();
  113. }
  114. }
  115. return OptionalNone {};
  116. }
  117. ErrorOr<Color> read_color(BigEndianInputBitStream& stream)
  118. {
  119. auto bits_per_sample = *m_metadata.bits_per_sample();
  120. // Section 7: Additional Baseline TIFF Requirements
  121. // Some TIFF files may have more components per pixel than you think. A Baseline TIFF reader must skip over
  122. // them gracefully, using the values of the SamplesPerPixel and BitsPerSample fields.
  123. auto manage_extra_channels = [&]() -> ErrorOr<u8> {
  124. // Both unknown and alpha channels are considered as extra channels, so let's iterate over
  125. // them, conserve the alpha value (if any) and discard everything else.
  126. auto const number_base_channels = samples_for_photometric_interpretation();
  127. auto const alpha_index = alpha_channel_index();
  128. Optional<u8> alpha {};
  129. for (u8 i = number_base_channels; i < bits_per_sample.size(); ++i) {
  130. if (alpha_index == i)
  131. alpha = TRY(read_component(stream, bits_per_sample[i]));
  132. else
  133. TRY(read_component(stream, bits_per_sample[i]));
  134. }
  135. return alpha.value_or(NumericLimits<u8>::max());
  136. };
  137. if (m_metadata.photometric_interpretation() == PhotometricInterpretation::RGB) {
  138. auto const first_component = TRY(read_component(stream, bits_per_sample[0]));
  139. auto const second_component = TRY(read_component(stream, bits_per_sample[1]));
  140. auto const third_component = TRY(read_component(stream, bits_per_sample[2]));
  141. auto const alpha = TRY(manage_extra_channels());
  142. return Color(first_component, second_component, third_component, alpha);
  143. }
  144. if (m_metadata.photometric_interpretation() == PhotometricInterpretation::RGBPalette) {
  145. auto const index = TRY(stream.read_bits<u16>(bits_per_sample[0]));
  146. auto const alpha = TRY(manage_extra_channels());
  147. // SamplesPerPixel == 1 is a requirement for RGBPalette
  148. // From description of PhotometricInterpretation in Section 8: Baseline Field Reference Guide
  149. // "In a TIFF ColorMap, all the Red values come first, followed by the Green values,
  150. // then the Blue values."
  151. u64 const size = 1ul << (*m_metadata.bits_per_sample())[0];
  152. u64 const red_offset = 0 * size;
  153. u64 const green_offset = 1 * size;
  154. u64 const blue_offset = 2 * size;
  155. auto const color_map = *m_metadata.color_map();
  156. if (blue_offset + index >= color_map.size())
  157. return Error::from_string_literal("TIFFImageDecoderPlugin: Color index is out of range");
  158. // FIXME: ColorMap's values are always 16-bits, stop truncating them when we support 16 bits bitmaps
  159. return Color(
  160. color_map[red_offset + index] >> 8,
  161. color_map[green_offset + index] >> 8,
  162. color_map[blue_offset + index] >> 8,
  163. alpha);
  164. }
  165. if (*m_metadata.photometric_interpretation() == PhotometricInterpretation::WhiteIsZero
  166. || *m_metadata.photometric_interpretation() == PhotometricInterpretation::BlackIsZero) {
  167. auto luminosity = TRY(read_component(stream, bits_per_sample[0]));
  168. if (m_metadata.photometric_interpretation() == PhotometricInterpretation::WhiteIsZero)
  169. luminosity = ~luminosity;
  170. auto const alpha = TRY(manage_extra_channels());
  171. return Color(luminosity, luminosity, luminosity, alpha);
  172. }
  173. return Error::from_string_literal("Unsupported value for PhotometricInterpretation");
  174. }
  175. template<CallableAs<ErrorOr<ReadonlyBytes>, u32> StripDecoder>
  176. ErrorOr<void> loop_over_pixels(StripDecoder&& strip_decoder)
  177. {
  178. auto const strips_offset = *m_metadata.strip_offsets();
  179. auto const strip_byte_counts = *m_metadata.strip_byte_counts();
  180. auto oriented_bitmap = TRY(ExifOrientedBitmap::create(BitmapFormat::BGRA8888, { *metadata().image_width(), *metadata().image_height() }, *metadata().orientation()));
  181. for (u32 strip_index = 0; strip_index < strips_offset.size(); ++strip_index) {
  182. TRY(m_stream->seek(strips_offset[strip_index]));
  183. auto const decoded_bytes = TRY(strip_decoder(strip_byte_counts[strip_index]));
  184. auto decoded_strip = make<FixedMemoryStream>(decoded_bytes);
  185. auto decoded_stream = make<BigEndianInputBitStream>(move(decoded_strip));
  186. for (u32 row = 0; row < *m_metadata.rows_per_strip(); row++) {
  187. auto const scanline = row + *m_metadata.rows_per_strip() * strip_index;
  188. if (scanline >= *m_metadata.image_height())
  189. break;
  190. Optional<Color> last_color {};
  191. for (u32 column = 0; column < *m_metadata.image_width(); ++column) {
  192. auto color = TRY(read_color(*decoded_stream));
  193. if (m_metadata.predictor() == Predictor::HorizontalDifferencing && last_color.has_value()) {
  194. color.set_red(last_color->red() + color.red());
  195. color.set_green(last_color->green() + color.green());
  196. color.set_blue(last_color->blue() + color.blue());
  197. }
  198. last_color = color;
  199. oriented_bitmap.set_pixel(column, scanline, color);
  200. }
  201. decoded_stream->align_to_byte_boundary();
  202. }
  203. }
  204. m_bitmap = oriented_bitmap.bitmap();
  205. return {};
  206. }
  207. ErrorOr<void> ensure_tags_are_correct_for_ccitt() const
  208. {
  209. // Section 8: Baseline Field Reference Guide
  210. // BitsPerSample must be 1, since this type of compression is defined only for bilevel images.
  211. if (m_metadata.bits_per_sample()->size() > 1)
  212. return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT image with BitsPerSample greater than one");
  213. if (m_metadata.photometric_interpretation() != PhotometricInterpretation::WhiteIsZero && m_metadata.photometric_interpretation() != PhotometricInterpretation::BlackIsZero)
  214. return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT compression is used on a non bilevel image");
  215. return {};
  216. }
  217. ErrorOr<void> decode_frame_impl()
  218. {
  219. switch (*m_metadata.compression()) {
  220. case Compression::NoCompression: {
  221. auto identity = [&](u32 num_bytes) {
  222. return m_stream->read_in_place<u8 const>(num_bytes);
  223. };
  224. TRY(loop_over_pixels(move(identity)));
  225. break;
  226. }
  227. case Compression::CCITTRLE: {
  228. TRY(ensure_tags_are_correct_for_ccitt());
  229. ByteBuffer decoded_bytes {};
  230. auto decode_ccitt_rle_strip = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  231. auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
  232. decoded_bytes = TRY(CCITT::decode_ccitt_rle(encoded_bytes, *m_metadata.image_width(), *m_metadata.rows_per_strip()));
  233. return decoded_bytes;
  234. };
  235. TRY(loop_over_pixels(move(decode_ccitt_rle_strip)));
  236. break;
  237. }
  238. case Compression::LZW: {
  239. ByteBuffer decoded_bytes {};
  240. auto decode_lzw_strip = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  241. auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
  242. if (encoded_bytes.is_empty())
  243. return Error::from_string_literal("TIFFImageDecoderPlugin: Unable to read from empty LZW strip");
  244. // Note: AFAIK, there are two common ways to use LZW compression:
  245. // - With a LittleEndian stream and no Early-Change, this is used in the GIF format
  246. // - With a BigEndian stream and an EarlyChange of 1, this is used in the PDF format
  247. // The fun begins when they decided to change from the former to the latter when moving
  248. // from TIFF 5.0 to 6.0, and without including a way for files to be identified.
  249. // Fortunately, as the first byte of a LZW stream is a constant we can guess the endianess
  250. // and deduce the version from it. The first code is 0x100 (9-bits).
  251. if (encoded_bytes[0] == 0x00)
  252. decoded_bytes = TRY(Compress::LZWDecoder<LittleEndianInputBitStream>::decode_all(encoded_bytes, 8, 0));
  253. else
  254. decoded_bytes = TRY(Compress::LZWDecoder<BigEndianInputBitStream>::decode_all(encoded_bytes, 8, -1));
  255. return decoded_bytes;
  256. };
  257. TRY(loop_over_pixels(move(decode_lzw_strip)));
  258. break;
  259. }
  260. case Compression::AdobeDeflate: {
  261. // This is an extension from the Technical Notes from 2002:
  262. // https://web.archive.org/web/20160305055905/http://partners.adobe.com/public/developer/en/tiff/TIFFphotoshop.pdf
  263. ByteBuffer decoded_bytes {};
  264. auto decode_zlib = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  265. auto stream = make<ConstrainedStream>(MaybeOwned<Stream>(*m_stream), num_bytes);
  266. auto decompressed_stream = TRY(Compress::ZlibDecompressor::create(move(stream)));
  267. decoded_bytes = TRY(decompressed_stream->read_until_eof(4096));
  268. return decoded_bytes;
  269. };
  270. TRY(loop_over_pixels(move(decode_zlib)));
  271. break;
  272. }
  273. case Compression::PackBits: {
  274. // Section 9: PackBits Compression
  275. ByteBuffer decoded_bytes {};
  276. auto decode_packbits_strip = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  277. auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
  278. decoded_bytes = TRY(Compress::PackBits::decode_all(encoded_bytes));
  279. return decoded_bytes;
  280. };
  281. TRY(loop_over_pixels(move(decode_packbits_strip)));
  282. break;
  283. }
  284. default:
  285. return Error::from_string_literal("This compression type is not supported yet :^)");
  286. }
  287. return {};
  288. }
  289. template<typename T>
  290. ErrorOr<T> read_value()
  291. {
  292. if (m_byte_order == ByteOrder::LittleEndian)
  293. return TRY(m_stream->read_value<LittleEndian<T>>());
  294. if (m_byte_order == ByteOrder::BigEndian)
  295. return TRY(m_stream->read_value<BigEndian<T>>());
  296. VERIFY_NOT_REACHED();
  297. }
  298. ErrorOr<void> read_next_idf_offset()
  299. {
  300. auto const next_block_position = TRY(read_value<u32>());
  301. if (next_block_position != 0)
  302. m_next_ifd = Optional<u32> { next_block_position };
  303. else
  304. m_next_ifd = OptionalNone {};
  305. dbgln_if(TIFF_DEBUG, "Setting image file directory pointer to {}", m_next_ifd);
  306. return {};
  307. }
  308. ErrorOr<void> read_image_file_header()
  309. {
  310. // Section 2: TIFF Structure - Image File Header
  311. auto const byte_order = TRY(m_stream->read_value<u16>());
  312. switch (byte_order) {
  313. case 0x4949:
  314. m_byte_order = ByteOrder::LittleEndian;
  315. break;
  316. case 0x4D4D:
  317. m_byte_order = ByteOrder::BigEndian;
  318. break;
  319. default:
  320. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid byte order");
  321. }
  322. auto const magic_number = TRY(read_value<u16>());
  323. if (magic_number != 42)
  324. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid magic number");
  325. TRY(read_next_idf_offset());
  326. return {};
  327. }
  328. ErrorOr<void> read_next_image_file_directory()
  329. {
  330. // Section 2: TIFF Structure - Image File Directory
  331. if (!m_next_ifd.has_value())
  332. return Error::from_string_literal("TIFFImageDecoderPlugin: Missing an Image File Directory");
  333. TRY(m_stream->seek(m_next_ifd.value()));
  334. auto const number_of_field = TRY(read_value<u16>());
  335. auto next_tag_offset = TRY(m_stream->tell());
  336. for (u16 i = 0; i < number_of_field; ++i) {
  337. TRY(m_stream->seek(next_tag_offset));
  338. if (auto maybe_error = read_tag(); maybe_error.is_error() && TIFF_DEBUG)
  339. dbgln("Unable to decode tag {}/{}", i + 1, number_of_field);
  340. // Section 2: TIFF Structure
  341. // IFD Entry
  342. // Size of tag(u16) + type(u16) + count(u32) + value_or_offset(u32) = 12
  343. next_tag_offset += 12;
  344. }
  345. TRY(read_next_idf_offset());
  346. return {};
  347. }
  348. ErrorOr<Vector<Value, 1>> read_tiff_value(Type type, u32 count, u32 offset)
  349. {
  350. auto const old_offset = TRY(m_stream->tell());
  351. ScopeGuard reset_offset { [this, old_offset]() { MUST(m_stream->seek(old_offset)); } };
  352. TRY(m_stream->seek(offset));
  353. if (size_of_type(type) * count > m_stream->remaining())
  354. return Error::from_string_literal("TIFFImageDecoderPlugin: Tag size claims to be bigger that remaining bytes");
  355. auto const read_every_values = [this, count]<typename T>() -> ErrorOr<Vector<Value>> {
  356. Vector<Value, 1> result {};
  357. TRY(result.try_ensure_capacity(count));
  358. if constexpr (IsSpecializationOf<T, Rational>) {
  359. for (u32 i = 0; i < count; ++i)
  360. result.empend(T { TRY(read_value<typename T::Type>()), TRY(read_value<typename T::Type>()) });
  361. } else {
  362. for (u32 i = 0; i < count; ++i)
  363. result.empend(typename TypePromoter<T>::Type(TRY(read_value<T>())));
  364. }
  365. return result;
  366. };
  367. switch (type) {
  368. case Type::Byte:
  369. case Type::Undefined: {
  370. Vector<Value, 1> result;
  371. auto buffer = TRY(ByteBuffer::create_uninitialized(count));
  372. TRY(m_stream->read_until_filled(buffer));
  373. result.append(move(buffer));
  374. return result;
  375. }
  376. case Type::ASCII:
  377. case Type::UTF8: {
  378. Vector<Value, 1> result;
  379. // NOTE: No need to include the null terminator
  380. if (count > 0)
  381. --count;
  382. auto string_data = TRY(ByteBuffer::create_uninitialized(count));
  383. TRY(m_stream->read_until_filled(string_data));
  384. result.empend(TRY(String::from_utf8(StringView { string_data.bytes() })));
  385. return result;
  386. }
  387. case Type::UnsignedShort:
  388. return read_every_values.template operator()<u16>();
  389. case Type::IFD:
  390. case Type::UnsignedLong:
  391. return read_every_values.template operator()<u32>();
  392. case Type::UnsignedRational:
  393. return read_every_values.template operator()<Rational<u32>>();
  394. case Type::SignedLong:
  395. return read_every_values.template operator()<i32>();
  396. ;
  397. case Type::SignedRational:
  398. return read_every_values.template operator()<Rational<i32>>();
  399. default:
  400. VERIFY_NOT_REACHED();
  401. }
  402. }
  403. ErrorOr<void> read_tag()
  404. {
  405. auto const tag = TRY(read_value<u16>());
  406. auto const raw_type = TRY(read_value<u16>());
  407. auto const type = TRY(tiff_type_from_u16(raw_type));
  408. auto const count = TRY(read_value<u32>());
  409. Checked<u32> checked_size = size_of_type(type);
  410. checked_size *= count;
  411. if (checked_size.has_overflow())
  412. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid tag with too large data");
  413. auto tiff_value = TRY(([=, this]() -> ErrorOr<Vector<Value>> {
  414. if (checked_size.value() <= 4) {
  415. auto value = TRY(read_tiff_value(type, count, TRY(m_stream->tell())));
  416. TRY(m_stream->discard(4));
  417. return value;
  418. }
  419. auto const offset = TRY(read_value<u32>());
  420. return read_tiff_value(type, count, offset);
  421. }()));
  422. TRY(handle_tag(m_metadata, tag, type, count, move(tiff_value)));
  423. return {};
  424. }
  425. NonnullOwnPtr<FixedMemoryStream> m_stream;
  426. State m_state {};
  427. RefPtr<Bitmap> m_bitmap {};
  428. ByteOrder m_byte_order {};
  429. Optional<u32> m_next_ifd {};
  430. ExifMetadata m_metadata {};
  431. };
  432. }
  433. TIFFImageDecoderPlugin::TIFFImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream> stream)
  434. {
  435. m_context = make<TIFF::TIFFLoadingContext>(move(stream));
  436. }
  437. bool TIFFImageDecoderPlugin::sniff(ReadonlyBytes bytes)
  438. {
  439. if (bytes.size() < 4)
  440. return false;
  441. bool const valid_little_endian = bytes[0] == 0x49 && bytes[1] == 0x49 && bytes[2] == 0x2A && bytes[3] == 0x00;
  442. bool const valid_big_endian = bytes[0] == 0x4D && bytes[1] == 0x4D && bytes[2] == 0x00 && bytes[3] == 0x2A;
  443. return valid_little_endian || valid_big_endian;
  444. }
  445. IntSize TIFFImageDecoderPlugin::size()
  446. {
  447. return m_context->size();
  448. }
  449. ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TIFFImageDecoderPlugin::create(ReadonlyBytes data)
  450. {
  451. auto stream = TRY(try_make<FixedMemoryStream>(data));
  452. auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TIFFImageDecoderPlugin(move(stream))));
  453. TRY(plugin->m_context->decode_image_header());
  454. return plugin;
  455. }
  456. ErrorOr<ImageFrameDescriptor> TIFFImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
  457. {
  458. if (index > 0)
  459. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid frame index");
  460. if (m_context->state() == TIFF::TIFFLoadingContext::State::Error)
  461. return Error::from_string_literal("TIFFImageDecoderPlugin: Decoding failed");
  462. if (m_context->state() < TIFF::TIFFLoadingContext::State::FrameDecoded)
  463. TRY(m_context->decode_frame());
  464. return ImageFrameDescriptor { m_context->bitmap(), 0 };
  465. }
  466. Optional<Metadata const&> TIFFImageDecoderPlugin::metadata()
  467. {
  468. return m_context->metadata();
  469. }
  470. ErrorOr<Optional<ReadonlyBytes>> TIFFImageDecoderPlugin::icc_data()
  471. {
  472. return m_context->metadata().icc_profile().map([](auto const& buffer) -> ReadonlyBytes { return buffer.bytes(); });
  473. }
  474. }