JPEGLoader.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) 2020, the SerenityOS developers.
  3. * Copyright (c) 2022-2023, Lucas Chollet <lucas.chollet@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/MemoryStream.h>
  9. #include <LibGfx/ImageFormats/ImageDecoder.h>
  10. namespace Gfx {
  11. struct JPEGLoadingContext;
  12. // For the specification, see: https://www.w3.org/Graphics/JPEG/itu-t81.pdf
  13. struct JPEGDecoderOptions {
  14. enum class CMYK {
  15. // For standalone jpeg files.
  16. Normal,
  17. // For jpeg data embedded in PDF files.
  18. PDF,
  19. };
  20. CMYK cmyk { CMYK::Normal };
  21. };
  22. class JPEGImageDecoderPlugin : public ImageDecoderPlugin {
  23. public:
  24. static bool sniff(ReadonlyBytes);
  25. static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
  26. static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create_with_options(ReadonlyBytes, JPEGDecoderOptions = {});
  27. virtual ~JPEGImageDecoderPlugin() override;
  28. virtual IntSize size() override;
  29. virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
  30. virtual Optional<Metadata const&> metadata() override;
  31. virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
  32. virtual NaturalFrameFormat natural_frame_format() const override;
  33. virtual ErrorOr<NonnullRefPtr<CMYKBitmap>> cmyk_frame() override;
  34. private:
  35. JPEGImageDecoderPlugin(NonnullOwnPtr<JPEGLoadingContext>);
  36. NonnullOwnPtr<JPEGLoadingContext> m_context;
  37. };
  38. }