mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:27:44 +00:00
LibGfx/TIFF: Extract metadata-related definition to their own file
This commit is contained in:
parent
1d1e7abba7
commit
34d91dec5b
2 changed files with 72 additions and 52 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <AK/Endian.h>
|
#include <AK/Endian.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <LibCompress/LZWDecoder.h>
|
#include <LibCompress/LZWDecoder.h>
|
||||||
|
#include <LibGfx/ImageFormats/TIFFMetadata.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
@ -23,13 +24,6 @@ public:
|
||||||
FrameDecoded,
|
FrameDecoded,
|
||||||
};
|
};
|
||||||
|
|
||||||
template<OneOf<u32, i32> x32>
|
|
||||||
struct Rational {
|
|
||||||
using Type = x32;
|
|
||||||
x32 numerator;
|
|
||||||
x32 denominator;
|
|
||||||
};
|
|
||||||
|
|
||||||
TIFFLoadingContext(NonnullOwnPtr<FixedMemoryStream> stream)
|
TIFFLoadingContext(NonnullOwnPtr<FixedMemoryStream> stream)
|
||||||
: m_stream(move(stream))
|
: m_stream(move(stream))
|
||||||
{
|
{
|
||||||
|
@ -77,49 +71,6 @@ private:
|
||||||
BigEndian,
|
BigEndian,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class Type {
|
|
||||||
Byte = 1,
|
|
||||||
ASCII = 2,
|
|
||||||
UnsignedShort = 3,
|
|
||||||
UnsignedLong = 4,
|
|
||||||
UnsignedRational = 5,
|
|
||||||
Undefined = 7,
|
|
||||||
SignedLong = 9,
|
|
||||||
SignedRational = 10,
|
|
||||||
Float = 11,
|
|
||||||
Double = 12,
|
|
||||||
UTF8 = 129,
|
|
||||||
};
|
|
||||||
|
|
||||||
using Value = Variant<u8, String, u16, u32, Rational<u32>, i32, Rational<i32>>;
|
|
||||||
|
|
||||||
// This enum is progessively defined across sections but summarized in:
|
|
||||||
// Appendix A: TIFF Tags Sorted by Number
|
|
||||||
enum class Compression {
|
|
||||||
NoCompression = 1,
|
|
||||||
CCITT = 2,
|
|
||||||
Group3Fax = 3,
|
|
||||||
Group4Fax = 4,
|
|
||||||
LZW = 5,
|
|
||||||
JPEG = 6,
|
|
||||||
PackBits = 32773,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum class Predictor {
|
|
||||||
None = 1,
|
|
||||||
HorizontalDifferencing = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Metadata {
|
|
||||||
IntSize size {};
|
|
||||||
Array<u16, 3> bits_per_sample {};
|
|
||||||
Compression compression {};
|
|
||||||
Predictor predictor {};
|
|
||||||
Vector<u32> strip_offsets {};
|
|
||||||
u32 rows_per_strip {};
|
|
||||||
Vector<u32> strip_bytes_count {};
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename ByteReader>
|
template<typename ByteReader>
|
||||||
ErrorOr<void> loop_over_pixels(ByteReader&& byte_reader, Function<ErrorOr<void>(u32)> initializer = {})
|
ErrorOr<void> loop_over_pixels(ByteReader&& byte_reader, Function<ErrorOr<void>(u32)> initializer = {})
|
||||||
{
|
{
|
||||||
|
@ -677,8 +628,8 @@ ErrorOr<ImageFrameDescriptor> TIFFImageDecoderPlugin::frame(size_t index, Option
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct AK::Formatter<Gfx::TIFF::TIFFLoadingContext::Rational<T>> : Formatter<FormatString> {
|
struct AK::Formatter<Gfx::TIFF::Rational<T>> : Formatter<FormatString> {
|
||||||
ErrorOr<void> format(FormatBuilder& builder, Gfx::TIFF::TIFFLoadingContext::Rational<T> value)
|
ErrorOr<void> format(FormatBuilder& builder, Gfx::TIFF::Rational<T> value)
|
||||||
{
|
{
|
||||||
return Formatter<FormatString>::format(builder, "{} ({}/{})"sv, static_cast<double>(value.numerator) / value.denominator, value.numerator, value.denominator);
|
return Formatter<FormatString>::format(builder, "{} ({}/{})"sv, static_cast<double>(value.numerator) / value.denominator, value.numerator, value.denominator);
|
||||||
}
|
}
|
||||||
|
|
69
Userland/Libraries/LibGfx/ImageFormats/TIFFMetadata.h
Normal file
69
Userland/Libraries/LibGfx/ImageFormats/TIFFMetadata.h
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Variant.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
|
#include <LibGfx/Size.h>
|
||||||
|
|
||||||
|
namespace Gfx {
|
||||||
|
|
||||||
|
namespace TIFF {
|
||||||
|
|
||||||
|
enum class Type {
|
||||||
|
Byte = 1,
|
||||||
|
ASCII = 2,
|
||||||
|
UnsignedShort = 3,
|
||||||
|
UnsignedLong = 4,
|
||||||
|
UnsignedRational = 5,
|
||||||
|
Undefined = 7,
|
||||||
|
SignedLong = 9,
|
||||||
|
SignedRational = 10,
|
||||||
|
Float = 11,
|
||||||
|
Double = 12,
|
||||||
|
UTF8 = 129,
|
||||||
|
};
|
||||||
|
|
||||||
|
template<OneOf<u32, i32> x32>
|
||||||
|
struct Rational {
|
||||||
|
using Type = x32;
|
||||||
|
x32 numerator;
|
||||||
|
x32 denominator;
|
||||||
|
};
|
||||||
|
|
||||||
|
using Value = Variant<u8, String, u16, u32, Rational<u32>, i32, Rational<i32>>;
|
||||||
|
|
||||||
|
// This enum is progessively defined across sections but summarized in:
|
||||||
|
// Appendix A: TIFF Tags Sorted by Number
|
||||||
|
enum class Compression {
|
||||||
|
NoCompression = 1,
|
||||||
|
CCITT = 2,
|
||||||
|
Group3Fax = 3,
|
||||||
|
Group4Fax = 4,
|
||||||
|
LZW = 5,
|
||||||
|
JPEG = 6,
|
||||||
|
PackBits = 32773,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class Predictor {
|
||||||
|
None = 1,
|
||||||
|
HorizontalDifferencing = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Metadata {
|
||||||
|
IntSize size {};
|
||||||
|
Array<u16, 3> bits_per_sample {};
|
||||||
|
TIFF::Compression compression {};
|
||||||
|
TIFF::Predictor predictor {};
|
||||||
|
Vector<u32> strip_offsets {};
|
||||||
|
u32 rows_per_strip {};
|
||||||
|
Vector<u32> strip_bytes_count {};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue