2020-05-18 13:28:27 +05:30
|
|
|
/*
|
2021-04-28 22:46:44 +02:00
|
|
|
* Copyright (c) 2020, the SerenityOS developers.
|
2023-04-21 20:17:50 -04:00
|
|
|
* Copyright (c) 2022-2023, Lucas Chollet <lucas.chollet@serenityos.org>
|
2020-05-18 13:28:27 +05:30
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-05-18 13:28:27 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2023-03-18 16:56:36 -04:00
|
|
|
#include <AK/MemoryStream.h>
|
2023-03-21 14:58:06 -04:00
|
|
|
#include <LibGfx/ImageFormats/ImageDecoder.h>
|
2020-05-18 13:28:27 +05:30
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
2023-02-18 16:09:16 -05:00
|
|
|
struct JPEGLoadingContext;
|
2020-05-18 13:28:27 +05:30
|
|
|
|
2023-02-19 11:34:05 -05:00
|
|
|
// For the specification, see: https://www.w3.org/Graphics/JPEG/itu-t81.pdf
|
|
|
|
|
|
2023-11-15 12:58:06 -05:00
|
|
|
struct JPEGDecoderOptions {
|
|
|
|
|
enum class CMYK {
|
|
|
|
|
// For standalone jpeg files.
|
|
|
|
|
Normal,
|
|
|
|
|
|
|
|
|
|
// For jpeg data embedded in PDF files.
|
|
|
|
|
PDF,
|
|
|
|
|
};
|
|
|
|
|
CMYK cmyk { CMYK::Normal };
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-18 16:09:16 -05:00
|
|
|
class JPEGImageDecoderPlugin : public ImageDecoderPlugin {
|
2020-05-18 13:28:27 +05:30
|
|
|
public:
|
2023-02-26 18:02:50 +00:00
|
|
|
static bool sniff(ReadonlyBytes);
|
2023-01-20 10:13:14 +02:00
|
|
|
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create(ReadonlyBytes);
|
2023-11-15 12:58:06 -05:00
|
|
|
static ErrorOr<NonnullOwnPtr<ImageDecoderPlugin>> create_with_options(ReadonlyBytes, JPEGDecoderOptions = {});
|
2023-01-20 10:13:14 +02:00
|
|
|
|
2023-02-18 16:09:16 -05:00
|
|
|
virtual ~JPEGImageDecoderPlugin() override;
|
2020-05-18 13:28:27 +05:30
|
|
|
virtual IntSize size() override;
|
2023-07-07 18:37:46 -04:00
|
|
|
|
2023-07-02 22:20:06 +01:00
|
|
|
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
|
2024-01-21 15:25:00 -05:00
|
|
|
|
|
|
|
|
virtual Optional<Metadata const&> metadata() override;
|
|
|
|
|
|
2023-01-26 07:23:59 -05:00
|
|
|
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
|
2020-05-18 13:28:27 +05:30
|
|
|
|
2024-01-07 21:49:03 -05:00
|
|
|
virtual NaturalFrameFormat natural_frame_format() const override;
|
|
|
|
|
virtual ErrorOr<NonnullRefPtr<CMYKBitmap>> cmyk_frame() override;
|
|
|
|
|
|
2020-05-18 13:28:27 +05:30
|
|
|
private:
|
2023-10-29 10:31:04 +00:00
|
|
|
JPEGImageDecoderPlugin(NonnullOwnPtr<JPEGLoadingContext>);
|
2023-01-20 10:13:14 +02:00
|
|
|
|
2023-10-29 10:31:04 +00:00
|
|
|
NonnullOwnPtr<JPEGLoadingContext> m_context;
|
2020-05-18 13:28:27 +05:30
|
|
|
};
|
2023-01-26 07:23:59 -05:00
|
|
|
|
2020-05-18 13:28:27 +05:30
|
|
|
}
|