TIFFLoader.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/MemoryStream.h>
  8. #include <AK/NonnullOwnPtr.h>
  9. #include <LibGfx/ImageFormats/ImageDecoder.h>
  10. namespace Gfx {
  11. class ExifMetadata;
  12. // This is a link to the main TIFF specification from 1992
  13. // https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf
  14. // First TIFF Technical notes from 1995
  15. // https://www.awaresystems.be/imaging/tiff/specification/TIFFPM6.pdf
  16. // Second TIFF Technical notes from 1995
  17. // The document is the second (and current) specification for embedded JPEGs in TIFF images.
  18. // https://www.awaresystems.be/imaging/tiff/specification/TIFFTechNote2.txt
  19. // This is also compatible with Exif as it is, basically, another set of TIFF tags:
  20. // The spec is named "Exchangeable image file format for digital still cameras: Exif Version 3.0"
  21. // And it can be found at https://www.cipa.jp/e/std/std-sec.html
  22. namespace TIFF {
  23. class TIFFLoadingContext;
  24. }
  25. class TIFFImageDecoderPlugin : public ImageDecoderPlugin {
  26. public:
  27. static bool sniff(ReadonlyBytes);
  28. static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
  29. static ErrorOr<NonnullOwnPtr<ExifMetadata>> read_exif_metadata(ReadonlyBytes);
  30. virtual ~TIFFImageDecoderPlugin() override = default;
  31. virtual IntSize size() override;
  32. virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
  33. virtual Optional<Metadata const&> metadata() override;
  34. virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
  35. private:
  36. TIFFImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream>);
  37. OwnPtr<TIFF::TIFFLoadingContext> m_context;
  38. };
  39. }