1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 07:14:58 +00:00
Commit graph

49 commits

Author SHA1 Message Date
Lucas CHOLLET
41c76e6ba6 LibGfx/TIFF: Add Rational::as_double() 2024-02-21 08:31:17 +00:00
Lucas CHOLLET
a30515011a LibGfx/TIFF: Add support for TileOffset and TileByteCounts 2024-02-13 10:13:11 +01:00
Lucas CHOLLET
e327d357d0 LibGfx/TIFF: Read Tile-related tags
-`TileWidth`
-`TileWidth`
-`TileOffsets`
-`TileByteCounts`
2024-02-13 10:13:11 +01:00
Lucas CHOLLET
c4e8e5c4a6 LibGfx/TIFF: Rename ImageHeight => ImageLength
This is the name used in the TIFF specification. No behavior change.
2024-02-13 10:13:11 +01:00
Lucas CHOLLET
720187623b LibGfx/TIFF: Read and honor the FillOrder tag 2024-02-13 00:37:06 +01:00
Lucas CHOLLET
a43793ee0d LibGfx/TIFF: Explore underlying Image File Directories
Every TIFF containers is composed of a main IFD. Some entries of this
one can be a pointer to a sub-IFD. We are now capable of exploring these
underlying structures. Note that we don't do anything with them yet.
2024-02-08 09:03:46 -07:00
Lucas CHOLLET
5dfa660a94 LibGfx/TIFF: Add support for Float and Double types
We previously were considering Float and Doubles as non-supported types.
But this was done in a sneaky way, by letting them hit the default case
in the `read_type` method. So, when I ported this function to the
generator we started to make this types flow into the system without a
proper support there. Since 3124c161, we would have crashes on images
containing tags with a floating point value.
2024-01-22 20:50:06 -07:00
Lucas CHOLLET
12c38035db LibGfx/TIFF: Rename JPEG to OldJPEG and introduce a new JPEG tag
Support for JPEGs embedded in TIFF images was introduced with TIFF 6.0.
However, this implementation had major issues. It was so problematic
that they decided to reimplement it from scratch in 1995, three years
later. The two incarnations are obviously incompatible.

For more details see:
https://www.awaresystems.be/imaging/tiff/specification/TIFFTechNote2.txt
2024-01-22 20:13:53 -07:00
Lucas CHOLLET
c2c7365494 LibGfx/TIFF: Accept images with a single strip and no RowsPerStrip tag
This tag is required by the specification, but some encoders (at least
Krita) don't write it for images with a single strip.

The test file was generated by opening deflate.tiff in Krita and saving
it with the DEFLATE compression.
2024-01-19 14:13:44 +01:00
Lucas CHOLLET
284e785053 LibGfx/TIFF: Accept the PixarDeflate compression tag
I would have liked to avoid adding a deprecated tag but this is the one
currently in use in Krita.
2024-01-19 14:13:44 +01:00
Lucas CHOLLET
26494600c4 LibGfx/TIFF: Parse the T4Options CCITT field
This field is described in: Section 11: CCITT Bilevel Encodings.
2024-01-18 14:00:56 +01:00
Lucas CHOLLET
edffdc35a9 LibGfx/TIFF+CCITT: Clarify naming of compression type 2
Type 2 <=> One-dimensional Group3, customized for TIFF
Type 3 <=> Two-dimensional Group3, uses the original 1D internally
Type 4 <=> Two-dimensional Group4

So let's clarify that this is not Group3 1D but the TIFF variant, which
is called `CCITTRLE` in libtiff. So let's stick with this name to avoid
confusion.
2024-01-18 14:00:56 +01:00
Lucas CHOLLET
a9a5ca6754 LibGfx/TIFF: Expose default value for numerical tags too
Due to the integer -> bool conversion rule, the condition was wrong. We
actually want to test for a not `None` state.
2024-01-18 14:00:56 +01:00
Lucas CHOLLET
b7bce816b2 LibGfx/TIFF: Sort tags in the known_tags list
The intruder comes from 5b62d877.
2024-01-14 15:04:43 -07:00
Lucas CHOLLET
48347d1923 LibGfx/TIFF: Make ExifMetadata inherit from Metadata 2024-01-14 15:04:43 -07:00
Lucas CHOLLET
7962f5e04b LibGfx/TIFF: Parse some pure-metadata tags
This will be useful to test a metadata displayer :^)
2024-01-14 15:04:43 -07:00
Lucas CHOLLET
f47666a93b LibGfx/TIFF: Rename Metadata => ExifMetadata
I originally thought that this would be our global `Metadata` class, but
that won't happen so let's give it a less general name.
2024-01-14 15:04:43 -07:00
Lucas CHOLLET
cc6ca7d873 LibGfx/TIFF: Parse the ExifIFD tag
And add a spec link :^)
2024-01-14 21:17:50 +01:00
Lucas CHOLLET
1d0a762cdb LibGfx/TIFF: Add support for the IFD type
As described in the first edition of the TIFF technical notes, the IFD
type is identical to Long (UnsignedLong) except that it only contains
offset of valid IFDs.

https://www.awaresystems.be/imaging/tiff/specification/TIFFPM6.pdf
2024-01-14 21:17:50 +01:00
Lucas CHOLLET
1de90bf55e LibGfx/TIFF: Generate the function that returns the size of a TIFF::Type 2024-01-14 21:17:50 +01:00
Lucas CHOLLET
3124c1616c LibGfx/TIFF: Generate code for the u16 to TIFF::Type conversion 2024-01-14 21:17:50 +01:00
Lucas CHOLLET
25c3f8cd8e LibGfx/TIFF: Prefer a verbal form over a noun 2024-01-10 23:34:44 +01:00
Lucas CHOLLET
34e9059ae8 LibGfx/TIFF: Honor the default value for single count tags
Some tags have a default value, we should return this value in
Metadata's getters when no value has been read from the input file.

Note that we don't support default values for tags with a count bigger
than one.
2024-01-08 00:07:44 +01:00
Lucas CHOLLET
82d40aab18 LibGfx/TIFF: Don't try to check non-existent values
We were previously only checking the first value, this is wrong for tags
that accept multiple values (e.g. ExtraSamples) and can lead to crashes
on malformed images containing tags with a count of 0.
2023-12-30 23:24:05 +01:00
Lucas CHOLLET
d66a421757 LibGfx/TIFF: Enforce a length of one for more tags
The TIFF spec is constructed in a way that many tags are defined in
multiple places but some of these definitions are partial. If we look
into "Section 8: Baseline Field Reference Guide", we can see that these
tags indeed have an enforced length of 1.
2023-12-30 23:24:05 +01:00
Lucas CHOLLET
73c8b4865e LibGfx/TIFF: Add AdobeDeflate compression support
This new compression is quite popular and uses a basic Zlib compression
to compress strips. Note that this is not part of the original TIFF
specification but in the Technical Notes from 2002:
https://web.archive.org/web/20160305055905/http://partners.adobe.com/public/developer/en/tiff/TIFFphotoshop.pdf

The test case was generated with GIMP.
2023-12-29 20:12:07 +01:00
Lucas CHOLLET
a31b988473 LibGfx/TIFF: Ensure baseline tags presence before decoding
This allows us to reject invalid images before trying to decode them.
The spec requires more tag to be present[1] but as we don't use them for
decoding I don't see the point.

[1] - XResolution, YResolution and ResolutionUnit
2023-12-23 20:54:07 +01:00
Lucas CHOLLET
67522fab2e LibGfx/TIFF: Add support for RGBPalette images
TIFF images with the PhotometricInterpretation tag set to RGBPalette are
based on indexed colors instead of explicitly describing the color for
each pixel. Let's add support for them.

The test case was generated with GIMP using the Indexed image mode after
adding an alpha layer. Not all decoders are able to open this image, but
GIMP can.
2023-12-23 20:41:48 +01:00
Nico Weber
80359517bd LibGfx: Do not use double negation in TIFFGenerator.py
No behavior change.
2023-12-23 12:25:08 -05:00
Lucas CHOLLET
796ece7b35 LibGfx/TIFF: Read the ExtraSamples tag 2023-12-22 08:08:47 +00:00
Lucas CHOLLET
b0e5aadf1a LibGfx/TIFF: Remove an unneeded parameter
This should have been done in f00e9540.
2023-12-20 12:19:30 +01:00
Lucas CHOLLET
5b62d877f2 LibGfx/TIFF: Parse more common tags
These tags are either part of the baseline specification or included by
default by GIMP when exporting TIFF files. Note that we don't add
support for them in the decoder yet. This commit only allows us to parse
the metadata and display it gracefully.
2023-12-18 07:14:11 +01:00
Lucas CHOLLET
64d7e386d2 LibGfx/TIFF: Parse the PhotometricInterpretation tag 2023-12-10 09:45:30 +01:00
Lucas CHOLLET
965da551e3 LibGfx/TIFF: Print the corresponding enum value's name when possible
As an example, for the tag 262 if the value is 5, "LZW" will be
displayed instead of the numeric value.
2023-12-07 11:10:55 +01:00
Lucas CHOLLET
2691651abf LibGfx/TIFF: Generated the code to output debug prints
When the `TIFF_DEBUG` flag is set, the TIFF decoder logs every tag and
their values. This is already useful but require the developer to have
the spec handy in order to decrypt each value to its signification. None
of this information is available at runtime, but this is known by the
Python generator. So by generating these debug logs, we drastically
increase their value.

As a bonus point, most of these functions should be useful when we will
display image's metadata in Serenity.
2023-12-07 11:10:55 +01:00
Lucas CHOLLET
b82f5d7f3e LibGfx/TIFF: Add a C++ formatter for TIFF::Value 2023-12-07 11:10:55 +01:00
Lucas CHOLLET
6e282538cc LibGfx/TIFF: Generate a C++ helper function to print enums
For a given enum value, this function will return its corresponding name
as a `StringView`.
2023-12-07 11:10:55 +01:00
Lucas CHOLLET
f00e9540d5 LibGfx/TIFF: Add an intrinsic way to get the exportable name of Enums
The `TIFFType` enum is exported with a different name to C++. This
change of behavior was handled by manually setting the parameter of a
function. However, we will soon need the exported name in more places,
so let's make it a property of the Enum itself.
2023-12-07 11:10:55 +01:00
Lucas CHOLLET
1d345109c4 LibGfx/TIFF: Move Formatter<Rational>'s definition to TIFFMetadata.h
This will soon be used in TIFFTagHandler.cpp, so the definition needs to
be shared.
2023-12-07 11:10:55 +01:00
Lucas CHOLLET
923d9e834f LibGfx/TIFF: Add support for the SamplesPerPixel tag 2023-12-07 08:17:46 +00:00
Lucas CHOLLET
d9b69c644e LibGfx/TIFF: Allow any number of values for the tag BitsPerSample
Only some specific number of values should be allowed, but let's accept
everything for now and add these checks when the generator will be more
mature.
2023-12-07 08:17:46 +00:00
Lucas CHOLLET
a382ea7c1f LibGfx/TIFF: Consider ASCII and UTF-8 as containers
The generator will now create APIs that return a single `String`
instead of a `Vector<String>`.
2023-12-03 20:27:00 +01:00
Lucas CHOLLET
4994609af0 LibGfx/TIFF: Add support for the ICCProfile tag 2023-12-02 10:36:02 +01:00
Lucas CHOLLET
5622e7d77c LibGfx/TIFF: Support tag names with capitalized acronym
We now turn 'ICCProfile' into 'icc_profile' instead of 'i_c_c_profile'.
2023-12-02 10:36:02 +01:00
Lucas CHOLLET
62f28d9968 LibGfx/TIFF: Teach the generator how to handle tags of type Undefined
This tag type is a bit different as even if it fits in the general
definition given in the TIFF specification. That is the value will be of
one specified type multiplied by a known count. Having a
`Vector<Variant<u8, ...>>` will be very painful to use. So let's deviate
a bit from the normal way and use a `ByteBuffer` directly instead this
complicated type.
2023-12-02 10:36:02 +01:00
Lucas CHOLLET
4280f4d2c7 LibGfx/TIFF: Automatically export all enums associated with tags 2023-12-01 12:45:03 +01:00
Lucas CHOLLET
9090290d11 LibGfx/TIFF: Rename BitPerSample => BitsPerSample
This is the proper name used in the spec.
2023-11-28 10:53:06 +01:00
Nico Weber
b2302ed23f LibGfx: Unbreak building with Python 3.9
Unbreaks building with macOS 13 system python, and is less code too.
No behavior change.
2023-11-27 21:58:16 -05:00
Lucas CHOLLET
9836a9ad0e LibGfx/TIFF: Introduce a code generator
This will allow us to generate code that handle and provide easy access
to metadata stored in TIFF's tags. The generator is a Python script, and
it output both TIFFMetadata.h and TIFFTagHandler.cpp files.

The generator will definitely need some update to support all TIFF and
EXIF tags, but that will still be easier than writing everything
ourselves.

Some small modifications are needed in TIFFLoader.cpp to make it
compatible with the new `Metadata` class.
2023-11-27 09:07:16 -07:00