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

486 commits

Author SHA1 Message Date
Nico Weber
187862ebe0 LibGfx: Add a .pam loader
.pam is a "portrable arbitrarymap" as documented at
https://netpbm.sourceforge.net/doc/pam.html

It's very similar to .pbm, .pgm, and .ppm, so this uses the
PortableImageMapLoader framework. The header is slightly different,
so this has a custom header parsing function.

Also, .pam only exixts in binary form, so the ascii form support
becomes optional.
2024-01-26 07:36:53 +01:00
Nico Weber
c6eac16d00 LibGfx: Remove unused parameter from cmyk_frame() 2024-01-25 15:53:44 +01:00
Lucas CHOLLET
a17041fe7f LibGfx/TIFF: Add support for CMYK
The test case has been generated with Krita.
2024-01-24 22:16:22 -07:00
Lucas CHOLLET
984272d83e LibGfx/TIFF: Put manage_extra_channels in its own function 2024-01-24 22:16:22 -07:00
Lucas CHOLLET
3f4bf7a0c7 LibGfx/ExifOrientedBitmap: Add support for CMYKBitmap 2024-01-24 22:16:22 -07:00
Lucas CHOLLET
c80b2cf782 LibGfx/ExifOrientedBitmap: Use scanline instead of set_pixel()
The former has the advantage to be available in CMYKBitmap too.

No behavior change.
2024-01-24 22:16:22 -07:00
Lucas CHOLLET
8229a19081 LibGfx/ExifOrientedBitmap: Reorganize create parameters
No behavior change.
2024-01-24 22:16:22 -07:00
Lucas CHOLLET
09b2b3539b LibGfx/JPEG+CMYKBitmap: Extract the CMYK to RGB conversion code
Right now, the JPEG decoder is the only one supporting CMYK, but that
won't last for long. So, let's move the conversion to CMYKBitmap.
2024-01-24 22:16:22 -07:00
Lucas CHOLLET
0462858247 LibGfx/JPEG: Keep the original CMYK data in memory
When decoding a CMYK image and asked for a normal `frame()`, the decoder
would convert the CMYK bitmap into an RGB bitmap. Calling `cmyk_frame()`
after that point will provoke a null-dereference.
2024-01-24 22:16:22 -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
6eb574a2b6 LibGfx/JPEG: Expose the Exif metadata
The Exif metadata is contained in the APP1 segment. We only need to
call the TIFF decoder to get the metadata back :^).
2024-01-22 20:16:32 -07:00
Lucas CHOLLET
f6f647bf13 LibGfx/TIFF: Add an alternative entry point to only request metadata
A lot of images format use Exif to store there metadata. As Exif is
based on the TIFF structure, the TIFF decoder can, without modification
be able to decode the metadata. We only need a new API to explicitly
mention that we only need the metadata.
2024-01-22 20:16:32 -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
1faf9bb44f LibGfx/TIFF: Apply the HorizontalDifferencing on the alpha channel
When present, the alpha channel is also affected by the horizontal
differencing predictor.

The test case was generated with GIMP with the following steps:
 - Open an RGB image
 - Add a transparency layer
 - Export as TIFF with the LZW compression scheme
2024-01-22 20:10:48 -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
75d87ccf5f LibGfx/TIFF+CCITT: Start to decode CCITT Group 3 images
We currently only support 1D Group 3, but that's a start.

The test case was generated with GIMP (it happens to be 1D by chance).
2024-01-18 14:00:56 +01:00
Lucas CHOLLET
1cc10a6245 LibGfx/CCITT: Extract the code to decode a single CCITT3 1D line
This will be handy for the pure CCITT Group 3 decoder too :^)
2024-01-18 14:00:56 +01:00
Lucas CHOLLET
6a94b09029 LibGfx/TIFF: Make strip decoders take the strip height
While most decoders do not require it, it is necessary for the CCITT
Group 3 decoder.
2024-01-18 14:00:56 +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
9b50b5793b LibGfx/TIFF: Factorize code to verify that CCITT images are correct 2024-01-18 14:00:56 +01:00
Nicolas Ramz
534eeb6c4b LibGfx/ILBMLoader: Properly display images with a bitplane mask
Images with a display mask ("stencil" as it's called in DPaint) add
an extra bitplane which acts as a mask. For now, at least skip it
properly. Later we should render masked pixels as transparent, but
this requires some refactoring.
2024-01-18 13:59:17 +01:00
kleines Filmröllchen
eb305c6974 LibGfx: Simplify ISOBMFF enums with RIFF ChunkID
RIFF ChunkID can (and should) be used as "just" a FourCC type, which
simplifies this code greatly.
2024-01-15 23:23:26 -07:00
kleines Filmröllchen
19a1369a70 LibGfx: Use LibRIFF for WebP loading 2024-01-15 23:23:26 -07:00
kleines Filmröllchen
60c3a1a77b LibGfx: Use LibRIFF for IFF parsing 2024-01-15 23:23:26 -07:00
Nico Weber
cf95910ae2 LibGfx/JPEG: Simplify loops walking all pixels in all macroblocks
When we want to walk everything, we can just do a linear walk.

No behavior change.
2024-01-15 23:04:56 -07:00
Nico Weber
5efe38ccd7 LibGfx/JPEG: Remove a silly initializer
SamplingFactors already has default initializers for its field,
so no need to have an explicit one for the first of the two fields.

No behavior change.
2024-01-15 23:04:56 -07:00
Nico Weber
6713ed483b LibGfx/PNG: Spec comment for PNGImageDecoderPlugin::unfilter_scanline()
Every time I read this, I'm like "wait, this does the wrong thing for
images with bpp != 8". It doesn't, though.
2024-01-15 23:42:45 +01:00
Nico Weber
fbde901614 LibGfx: Use read_effective_chunk_size() in skip_segment()
We missed this one in d184e6014ccd8.

No behavior change in valid JPEGs. No silent underflow in invalid ones.
2024-01-15 19:46:03 +00:00
Nico Weber
3616d14c80 LibGfx/JPEG: Allow decoding more subsampling factors
We now allow all subsampling factors where the subsampling factors
of follow-on components evenly decode the ones of the first component.

In practice, this allows YCCK 2111, CMYK 2112, and CMYK 2111.
2024-01-15 11:20:11 -07:00
Nico Weber
d99d086da3 LibGfx/JPEG: Move subsample-undoing to a separate function
Previously, we handled sampling factors as part of ycbcr_to_rgb().
That meant it worked ok for code paths that used YCbCr ("normal"
jpegs, and the YCC part of YCCK jpegs), but it didn't work for
example for the K channel in YCCK jpegs, nor for CMYK.

By making this a separate pass, it should now work for all cases.
It also makes it easier to support more subsampling arrangements
in the future, and to use something better than nearest neighbor
for upsampling subsampled blocks.
2024-01-15 11:20:11 -07:00
Lucas CHOLLET
383be5e49c LibGfx/TIFF: Override ImageDecoderPlugin::metadata() 2024-01-14 15:04:43 -07:00
Lucas CHOLLET
e3f976f17a LibGfx: Add an API to retrieve metadata from images
All the data is passed using the `Metadata` object, which has a
`main_tags` method. This method should be used when displaying only a
few main tags, for example to fill the property window of a file
manager. Another method returning the entire list of tags will be
implemented later on.
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
Nicolas Ramz
a1255cb6c9 LibGfx/ILBMLoader: Don't decode bits once full row has been decoded
We were potentially decoding more bits than needed: this could
trash the next lines if decoder didn't zero the extra bits.
2024-01-14 20:41:25 +01:00
Nicolas Ramz
1593ff2d4c LibGfx/ILBMLoader: Don't throw too early when decoding bitplanes
We were (again) throwing even though the image could be decoded.
2024-01-10 23:41:15 +01:00
Lucas CHOLLET
f6b86096a5 LibGfx/TIFF: Prevent the CCITT decoder to run on non bilevel image 2024-01-10 23:34:44 +01:00
Lucas CHOLLET
0ef449a588 LibGfx/TIFF: Don't crash on invalid indices inside RGBPalette images
We were previously accessing a Vector's element using a user-provided
value as index input.
2024-01-10 23:34:44 +01:00
Lucas CHOLLET
58bdca96cd LibGfx/TIFF: Use a wider type for palette indices to prevent overflow
We refuse any image with a sample depth greater than 32, storing these
value as `u64` prevent any overflows. This is probably overkill as no
one in their right mind will use a 32 bits color table.
2024-01-10 23:34:44 +01:00
Lucas CHOLLET
4d1c99e414 LibGfx/TIFF: Don't crash on RGBPalette images without a ColorMap 2024-01-10 23:34:44 +01:00
Lucas CHOLLET
25c3f8cd8e LibGfx/TIFF: Prefer a verbal form over a noun 2024-01-10 23:34:44 +01:00
Nico Weber
d8ada20bae LibGfx: Allow images to report that they are originally grayscale
...and implement it in JPEGLoader.

Since it's easy to get the grayscale data off a Bitmap, don't
add a grayscale_frame() accessor.
2024-01-10 09:39:00 +01:00
Nico Weber
239da5132d LibGfx/JPEG: Make it possible to obtain raw CMYK data from JPEGs
frame() still returns a regular RGB Bitmap (now lazily converted
from internal CMYK data), but JPEGImageDecoderPlugin now also
implements cmyk_frame().
2024-01-10 09:39:00 +01:00
Nico Weber
51d5397e92 LibGfx: Give ImageDecoder an API for getting raw CMYK data
frame() still returns a regular RGB Bitmap, but it's possible to also
get at raw CMYK data instead if desired, for image formats that can
store that.
2024-01-10 09:39:00 +01:00
Nico Weber
c997ee7b9d LibGfx+ImageViewer: Replace ImageDecoder::is_vector() with an enum
That makes it easier to extend to other special frame formats.
2024-01-10 09:39:00 +01:00