TIFFLoader.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. Metadata 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> decode_frame_impl()
  208. {
  209. switch (*m_metadata.compression()) {
  210. case Compression::NoCompression: {
  211. auto identity = [&](u32 num_bytes) {
  212. return m_stream->read_in_place<u8 const>(num_bytes);
  213. };
  214. TRY(loop_over_pixels(move(identity)));
  215. break;
  216. }
  217. case Compression::CCITT: {
  218. // Section 8: Baseline Field Reference Guide
  219. // BitsPerSample must be 1, since this type of compression is defined only for bilevel images.
  220. if (m_metadata.bits_per_sample()->size() > 1)
  221. return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT image with BitsPerSample greater than one");
  222. if (m_metadata.photometric_interpretation() != PhotometricInterpretation::WhiteIsZero && m_metadata.photometric_interpretation() != PhotometricInterpretation::BlackIsZero)
  223. return Error::from_string_literal("TIFFImageDecoderPlugin: CCITT compression is used on a non bilevel image");
  224. ByteBuffer decoded_bytes {};
  225. auto decode_ccitt_1D_strip = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  226. auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
  227. decoded_bytes = TRY(CCITT::decode_ccitt3_1d(encoded_bytes, *m_metadata.image_width(), *m_metadata.rows_per_strip()));
  228. return decoded_bytes;
  229. };
  230. TRY(loop_over_pixels(move(decode_ccitt_1D_strip)));
  231. break;
  232. }
  233. case Compression::LZW: {
  234. ByteBuffer decoded_bytes {};
  235. auto decode_lzw_strip = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  236. auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
  237. if (encoded_bytes.is_empty())
  238. return Error::from_string_literal("TIFFImageDecoderPlugin: Unable to read from empty LZW strip");
  239. // Note: AFAIK, there are two common ways to use LZW compression:
  240. // - With a LittleEndian stream and no Early-Change, this is used in the GIF format
  241. // - With a BigEndian stream and an EarlyChange of 1, this is used in the PDF format
  242. // The fun begins when they decided to change from the former to the latter when moving
  243. // from TIFF 5.0 to 6.0, and without including a way for files to be identified.
  244. // Fortunately, as the first byte of a LZW stream is a constant we can guess the endianess
  245. // and deduce the version from it. The first code is 0x100 (9-bits).
  246. if (encoded_bytes[0] == 0x00)
  247. decoded_bytes = TRY(Compress::LZWDecoder<LittleEndianInputBitStream>::decode_all(encoded_bytes, 8, 0));
  248. else
  249. decoded_bytes = TRY(Compress::LZWDecoder<BigEndianInputBitStream>::decode_all(encoded_bytes, 8, -1));
  250. return decoded_bytes;
  251. };
  252. TRY(loop_over_pixels(move(decode_lzw_strip)));
  253. break;
  254. }
  255. case Compression::AdobeDeflate: {
  256. // This is an extension from the Technical Notes from 2002:
  257. // https://web.archive.org/web/20160305055905/http://partners.adobe.com/public/developer/en/tiff/TIFFphotoshop.pdf
  258. ByteBuffer decoded_bytes {};
  259. auto decode_zlib = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  260. auto stream = make<ConstrainedStream>(MaybeOwned<Stream>(*m_stream), num_bytes);
  261. auto decompressed_stream = TRY(Compress::ZlibDecompressor::create(move(stream)));
  262. decoded_bytes = TRY(decompressed_stream->read_until_eof(4096));
  263. return decoded_bytes;
  264. };
  265. TRY(loop_over_pixels(move(decode_zlib)));
  266. break;
  267. }
  268. case Compression::PackBits: {
  269. // Section 9: PackBits Compression
  270. ByteBuffer decoded_bytes {};
  271. auto decode_packbits_strip = [&](u32 num_bytes) -> ErrorOr<ReadonlyBytes> {
  272. auto const encoded_bytes = TRY(m_stream->read_in_place<u8 const>(num_bytes));
  273. decoded_bytes = TRY(Compress::PackBits::decode_all(encoded_bytes));
  274. return decoded_bytes;
  275. };
  276. TRY(loop_over_pixels(move(decode_packbits_strip)));
  277. break;
  278. }
  279. default:
  280. return Error::from_string_literal("This compression type is not supported yet :^)");
  281. }
  282. return {};
  283. }
  284. template<typename T>
  285. ErrorOr<T> read_value()
  286. {
  287. if (m_byte_order == ByteOrder::LittleEndian)
  288. return TRY(m_stream->read_value<LittleEndian<T>>());
  289. if (m_byte_order == ByteOrder::BigEndian)
  290. return TRY(m_stream->read_value<BigEndian<T>>());
  291. VERIFY_NOT_REACHED();
  292. }
  293. ErrorOr<void> read_next_idf_offset()
  294. {
  295. auto const next_block_position = TRY(read_value<u32>());
  296. if (next_block_position != 0)
  297. m_next_ifd = Optional<u32> { next_block_position };
  298. else
  299. m_next_ifd = OptionalNone {};
  300. dbgln_if(TIFF_DEBUG, "Setting image file directory pointer to {}", m_next_ifd);
  301. return {};
  302. }
  303. ErrorOr<void> read_image_file_header()
  304. {
  305. // Section 2: TIFF Structure - Image File Header
  306. auto const byte_order = TRY(m_stream->read_value<u16>());
  307. switch (byte_order) {
  308. case 0x4949:
  309. m_byte_order = ByteOrder::LittleEndian;
  310. break;
  311. case 0x4D4D:
  312. m_byte_order = ByteOrder::BigEndian;
  313. break;
  314. default:
  315. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid byte order");
  316. }
  317. auto const magic_number = TRY(read_value<u16>());
  318. if (magic_number != 42)
  319. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid magic number");
  320. TRY(read_next_idf_offset());
  321. return {};
  322. }
  323. ErrorOr<void> read_next_image_file_directory()
  324. {
  325. // Section 2: TIFF Structure - Image File Directory
  326. if (!m_next_ifd.has_value())
  327. return Error::from_string_literal("TIFFImageDecoderPlugin: Missing an Image File Directory");
  328. TRY(m_stream->seek(m_next_ifd.value()));
  329. auto const number_of_field = TRY(read_value<u16>());
  330. auto next_tag_offset = TRY(m_stream->tell());
  331. for (u16 i = 0; i < number_of_field; ++i) {
  332. TRY(m_stream->seek(next_tag_offset));
  333. if (auto maybe_error = read_tag(); maybe_error.is_error() && TIFF_DEBUG)
  334. dbgln("Unable to decode tag {}/{}", i + 1, number_of_field);
  335. // Section 2: TIFF Structure
  336. // IFD Entry
  337. // Size of tag(u16) + type(u16) + count(u32) + value_or_offset(u32) = 12
  338. next_tag_offset += 12;
  339. }
  340. TRY(read_next_idf_offset());
  341. return {};
  342. }
  343. ErrorOr<Vector<Value, 1>> read_tiff_value(Type type, u32 count, u32 offset)
  344. {
  345. auto const old_offset = TRY(m_stream->tell());
  346. ScopeGuard reset_offset { [this, old_offset]() { MUST(m_stream->seek(old_offset)); } };
  347. TRY(m_stream->seek(offset));
  348. if (size_of_type(type) * count > m_stream->remaining())
  349. return Error::from_string_literal("TIFFImageDecoderPlugin: Tag size claims to be bigger that remaining bytes");
  350. auto const read_every_values = [this, count]<typename T>() -> ErrorOr<Vector<Value>> {
  351. Vector<Value, 1> result {};
  352. TRY(result.try_ensure_capacity(count));
  353. if constexpr (IsSpecializationOf<T, Rational>) {
  354. for (u32 i = 0; i < count; ++i)
  355. result.empend(T { TRY(read_value<typename T::Type>()), TRY(read_value<typename T::Type>()) });
  356. } else {
  357. for (u32 i = 0; i < count; ++i)
  358. result.empend(typename TypePromoter<T>::Type(TRY(read_value<T>())));
  359. }
  360. return result;
  361. };
  362. switch (type) {
  363. case Type::Byte:
  364. case Type::Undefined: {
  365. Vector<Value, 1> result;
  366. auto buffer = TRY(ByteBuffer::create_uninitialized(count));
  367. TRY(m_stream->read_until_filled(buffer));
  368. result.append(move(buffer));
  369. return result;
  370. }
  371. case Type::ASCII:
  372. case Type::UTF8: {
  373. Vector<Value, 1> result;
  374. // NOTE: No need to include the null terminator
  375. if (count > 0)
  376. --count;
  377. auto string_data = TRY(ByteBuffer::create_uninitialized(count));
  378. TRY(m_stream->read_until_filled(string_data));
  379. result.empend(TRY(String::from_utf8(StringView { string_data.bytes() })));
  380. return result;
  381. }
  382. case Type::UnsignedShort:
  383. return read_every_values.template operator()<u16>();
  384. case Type::IFD:
  385. case Type::UnsignedLong:
  386. return read_every_values.template operator()<u32>();
  387. case Type::UnsignedRational:
  388. return read_every_values.template operator()<Rational<u32>>();
  389. case Type::SignedLong:
  390. return read_every_values.template operator()<i32>();
  391. ;
  392. case Type::SignedRational:
  393. return read_every_values.template operator()<Rational<i32>>();
  394. default:
  395. VERIFY_NOT_REACHED();
  396. }
  397. }
  398. ErrorOr<void> read_tag()
  399. {
  400. auto const tag = TRY(read_value<u16>());
  401. auto const raw_type = TRY(read_value<u16>());
  402. auto const type = TRY(tiff_type_from_u16(raw_type));
  403. auto const count = TRY(read_value<u32>());
  404. Checked<u32> checked_size = size_of_type(type);
  405. checked_size *= count;
  406. if (checked_size.has_overflow())
  407. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid tag with too large data");
  408. auto tiff_value = TRY(([=, this]() -> ErrorOr<Vector<Value>> {
  409. if (checked_size.value() <= 4) {
  410. auto value = TRY(read_tiff_value(type, count, TRY(m_stream->tell())));
  411. TRY(m_stream->discard(4));
  412. return value;
  413. }
  414. auto const offset = TRY(read_value<u32>());
  415. return read_tiff_value(type, count, offset);
  416. }()));
  417. TRY(handle_tag(m_metadata, tag, type, count, move(tiff_value)));
  418. return {};
  419. }
  420. NonnullOwnPtr<FixedMemoryStream> m_stream;
  421. State m_state {};
  422. RefPtr<Bitmap> m_bitmap {};
  423. ByteOrder m_byte_order {};
  424. Optional<u32> m_next_ifd {};
  425. Metadata m_metadata {};
  426. };
  427. }
  428. TIFFImageDecoderPlugin::TIFFImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream> stream)
  429. {
  430. m_context = make<TIFF::TIFFLoadingContext>(move(stream));
  431. }
  432. bool TIFFImageDecoderPlugin::sniff(ReadonlyBytes bytes)
  433. {
  434. if (bytes.size() < 4)
  435. return false;
  436. bool const valid_little_endian = bytes[0] == 0x49 && bytes[1] == 0x49 && bytes[2] == 0x2A && bytes[3] == 0x00;
  437. bool const valid_big_endian = bytes[0] == 0x4D && bytes[1] == 0x4D && bytes[2] == 0x00 && bytes[3] == 0x2A;
  438. return valid_little_endian || valid_big_endian;
  439. }
  440. IntSize TIFFImageDecoderPlugin::size()
  441. {
  442. return m_context->size();
  443. }
  444. ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> TIFFImageDecoderPlugin::create(ReadonlyBytes data)
  445. {
  446. auto stream = TRY(try_make<FixedMemoryStream>(data));
  447. auto plugin = TRY(adopt_nonnull_own_or_enomem(new (nothrow) TIFFImageDecoderPlugin(move(stream))));
  448. TRY(plugin->m_context->decode_image_header());
  449. return plugin;
  450. }
  451. ErrorOr<ImageFrameDescriptor> TIFFImageDecoderPlugin::frame(size_t index, Optional<IntSize>)
  452. {
  453. if (index > 0)
  454. return Error::from_string_literal("TIFFImageDecoderPlugin: Invalid frame index");
  455. if (m_context->state() == TIFF::TIFFLoadingContext::State::Error)
  456. return Error::from_string_literal("TIFFImageDecoderPlugin: Decoding failed");
  457. if (m_context->state() < TIFF::TIFFLoadingContext::State::FrameDecoded)
  458. TRY(m_context->decode_frame());
  459. return ImageFrameDescriptor { m_context->bitmap(), 0 };
  460. }
  461. ErrorOr<Optional<ReadonlyBytes>> TIFFImageDecoderPlugin::icc_data()
  462. {
  463. return m_context->metadata().icc_profile().map([](auto const& buffer) -> ReadonlyBytes { return buffer.bytes(); });
  464. }
  465. }