summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx
AgeCommit message (Collapse)Author
2023-04-13LibGfx: Add Rect::interpolated_to functionTom
This function interpolates the edges between the rectangle and another rectangle based on a percentage value.
2023-04-12Everywhere: Fix a few typosNico Weber
Some even user-visible!
2023-04-12LibGfx/WebP: Don't assert when size in header is smaller than headerNico Weber
read_webp_first_chunk() sensibly assumes that if decode_webp_header() succeeds, there are at least sizeof(WebPFileHeader) bytes available. But if the file size in the header was less than the size of the header, decode_webp_header() would truncate the data to less than that and happily report success. Now it no longer does that. Found by clusterfuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=57843&sort=-opened&can=1&q=proj%3Aserenity
2023-04-12LibGfx/ICC: Use mix() in CurveTagData::evaluate()Nico Weber
No behavior change. (Well, technically mix() uses the other simple implementation of lerp and the two have slightly different behavior if the arguments are of very different magnitude and in various corner cases. But in practice, for ICC profiles, it shouldn't matter. For a few profiles I tested, it didn't have a measurable effect.)
2023-04-12LibGfx: Add AffineTransform::skew_radians()MacDue
2023-04-12LibGfx: Optimize Painter::draw_scaled_bitmap_with_transform()MacDue
This now applies clipping to the destination bounding box before painting, which cuts out a load of clipped computation and allows using the faster set_physical_pixel() method. Alongside this it also combines the source_transform and inverse_transform outside the hot loop (which might cut things down a little). The `destination_quad.contains()` check is also removed in favour of just checking if the mapped point is inside the source rect, which takes less work to compute than checking the bounding box. This takes this method down from 98% of the time to 10% of the time when painting Google Street View (with no obvious issues).
2023-04-11LibGfx/ICC: Add evaluate() member functions to both curve typesNico Weber
2023-04-11LibGfx/ICC: Extract sRGB_curve() functionNico Weber
This returns just the tone reproduction curve of the sRGB profile.
2023-04-09Everywhere: Remove unused DeprecatedString includesBen Wiederhake
2023-04-09LibGfx: Floor draw origin in fill path implementationMacDue
This is done to be consistent with enclosing_int_rect() which is used elsewhere to work out offsets in PaintStyles. Without this, you can get an off-by-one in painting.
2023-04-09LibGfx: Add Point::to_floored<T>()MacDue
2023-04-09LibGfx: Fix crash due to vector resize in close_all_subpaths()MacDue
Since close_all_subpaths() appends while iterating, the vector can end up being resized and the iterator invalidated. Previously, this led to a crash/UAF in some cases.
2023-04-09LibGfx: Add BitmapPaintStyleMacDue
This is a simple paint style for filling a path with a bitmap.
2023-04-09LibGfx: Limit ICC-size-is-multiple-of-4 check to v4 filesNico Weber
The v2 spec doesn't require it, and it's not true in practice (e.g. Compact-ICC-Profiles/profiles/sRGB-v2-nano.icc has size 410).
2023-04-09LibGfx: Remove some of the noisier logging from webp lossless decoderNico Weber
Prefix code decoding seems to work fairly well and produces a ton of log output with `#define WEBP_DEBUG 1`, so remove the log lines. (If needed it's always possible to just locally revert this commit.) No behavior change, since WEBP_DEBUG isn't usually defined.
2023-04-09LibGfx: Correctly decode webp lossless with small palette and odd widthNico Weber
WebP lossless files that use a color indexing transform with <= 16 colors use pixel bundling to pack 2, 4, or 8 pixels into a single pixel. If the image's width doesn't happen to be an exact multiple of the bundling factor, we need to: 1. Use ceil_div() instead of just dividing the width by the bundling factor 2. Remember the original width and use it instead of computing reduced width times bundling factor This does these changes, and adds a simple test for it -- it at least checks that the decoded images have the right size. (I created these images myself in Photoshop, and used the same technique as for Tests/LibGfx/test-inputs/catdog-alert-*.webp to create images with a certain number of colors.)
2023-04-08LibGfx: Implement color index pixel bundling in webp decoderNico Weber
See the lengthy comment added in this commit for details. With this, the webp lossless decoder is feature complete :^) (...except for bug fixes and performance improvements, as always.)
2023-04-08LibGfx: Enable webp lossless Transform to return new bitmapNico Weber
...in addition to modifying in-place. This is needed for bitpacking support for the color indexing transform (and it could also be used to make the color indexing transform return an indexed bitmap, which is something we could do if that's the last transform that's applied). No behavior change.
2023-04-08LibGfx: Add some more dbgln_if()s to webp decoderNico Weber
2023-04-08LibGfx: Give PrefixCodeGroup a deleted copy ctorNico Weber
This makes the accidental copy fixed in 2125ccdc19 a compile error. No behavior change.
2023-04-08LibGfx: Make webp lossless decoder 6 times as fastNico Weber
Reduces the time to run Build/lagom/image ~/src/libwebp/webp_js/test_webp_wasm.webp -o tmp.png from 0.5s to 0.25s. Before, 60% of the time was spent decoding webp and 40% writing png. Now, 16% of the time was spent decoding webp and 84% writing png. That means png writing takes 0.2s, and webp decoding time went from 0.3s to 0.05s. A template expression without explicit return type deduces its return type as if for a function whose return type is declared auto. That does deduce return-by-value, while `decltype(auto)` would deduce return-by-reference. Explictly saying `decltype(auto)` would work too, but writing out the type is maybe easier to understand. No behavior change other than being much faster.
2023-04-08LibGfx: Second attempt to handle max_symbol correctly in webp decoderNico Weber
The previous attempt was in commit e5e9d3b877c, where I thought max_symbol describes how many code lengths should be read. But it looks like it instead describes how many code length input symbols should be read. (The two aren't the same since one code length input symbol can produce several code lengths.) I still agree with the commit description of e5e9d3b877c that the spec isn't very clear on this :) This time I've found a file that sets max_symbol and with this change here, that file decodes correctly. (It's Qpalette.webp, which I'm about to add as a test case.)
2023-04-08LibGfx: Implement most of COLOR_INDEXING_TRANSFORM for webp decoderNico Weber
Doesn't yet implement pixel packing for when the palette has fewer than 16 colors.
2023-04-08LibGfx: Extract free add_argb32() function in webp decoderNico Weber
2023-04-08LibGfx: Make a webp error message more detailedNico Weber
Now that lossless decoding mostly works, make it clear that only lossy decoding isn't implemented yet.
2023-04-07LibGfx: Implement meta prefix code support in webp decoderNico Weber
2023-04-07LibGfx: Implement COLOR_TRANSFORM for webp lossless decoderNico Weber
2023-04-07LibGfx: Implement PREDICTOR_TRANSFORM for webp lossless decoderNico Weber
Very much not written for performance at this point.
2023-04-07LibGfx: Add CanonicalCode wrapper to webp lossless decoderNico Weber
WebP lossless differs from deflate in how it handles 1-element codes. Deflate consumes one bit from the bitstream to produce the element, while webp lossless consumes 0 bits. Add a wrapper class to handle this case.
2023-04-07LibGfx: Implement SUBTRACT_GREEN_TRANSFORM for webp lossless decoderNico Weber
2023-04-07LibGfx: Add scaffolding for applying transforms to webp lossless decoderNico Weber
Each of the four transforms will inherit from this class.
2023-04-07LibGfx: Add more dbgln_if()s to webp decoderNico Weber
They were useful while debugging the decoder. Keep them in for a bit.
2023-04-07LibGfx: In webp decoder, check that each transform is used only onceNico Weber
2023-04-07LibGfx: Correctly handle more than one PrefixCodeGroup in webp decoderNico Weber
The `static` here meant we always kept the alphabet sizes of the first image we happened to load -- and a single webp lossless image can store several helper images used during decoding. Usually, the helper images wouldn't use a color cache but the main image would, but the main image would then use the first entry from the helper images due to the `static`, which led us to not decoding the codes for the color cache symbols.
2023-04-06LibGfx/JPEG: Use a smaller type to store coefficientsLucas CHOLLET
No need to store them in `i32`, the JPEG norm specifies that they are not bigger than 16 bits for extended JPEGs. So, in this patch, we replace `i32` with `i16`. It almost divides memory usage by two :^)
2023-04-06LibGfx: Fix out of bounds read in BitmapFont::masked_character_set()Julian Offenhäuser
When creating a copy of the font containing only the glyphs that are in use, we previously looped over all possible code points, instead of the range of code points that are actually in use (and allocated) in the font. This is a problem, since we index into the array of widths to find out if a given glyph is used. This array is only as long as the number of glyphs the font was created with, causing an out of bounds read when that number is less than our maximum.
2023-04-06LibGfx: Pass in format and size to webp image decoding functionNico Weber
2023-04-06LibGfx: Teach webp image reading function to read entropy coded imagesNico Weber
2023-04-06LibGfx: Move webp image decoding function up a bitNico Weber
Pure code move, no changes (except that this allows removing the explicit prototype for this function, so it removes that).
2023-04-06LibGfx: Move webp bitmap decoding code into its own functionNico Weber
2023-04-06LibGfx: Implement hopefully correct max_symbol handling in webp decoderNico Weber
The spec is at best misleading here, suggesting that max_symbol should be set to "num_code_lengths" if it's not explicitly stored. But num_code_lengths doesn't mean the num_code_lengths mentioned a few lines further up in the spec, but alphabet_size! (I had to cheat and look at libwebp instead of the spec for this: See vp8l_dec.c, ReadHuffmanCode() which passes alphabet_size to ReadHuffmanCodeLengths() as num_symbols, and ReadHuffmanCodeLengths() then sets max_symbol to that.) I haven't yet found a file that uses max_symbol, so this isn't actually tested. But it's close to what's in libwebp, so maybe it works!
2023-04-06LibGfx: Read transform type in webp lossless decoderNico Weber
Doesn't do anything with it yet, so this only makes the "not yet implemented" message a bit more detailed.
2023-04-06LibGfx: Remove some noisy dbgln_if()s in webp decoderNico Weber
Pixel decoding mostly works, so there's no need to log all this data.
2023-04-05LibGfx: Add some support for decoding lossless webp filesNico Weber
Missing: * Transform support (used by virtually all lossless webp files) * Meta prefix / entropy image support Working: * Decoding of regular image streams * Color cache This happens to be enough to be able to decode Tests/LibGfx/test-inputs/extended-lossless.webp The canonical prefix code is very similar to deflate's, enough so that this can use Compress::CanonicalCode (and take advantage of all the recent performance improvements there).
2023-04-05LibGfx: Add Bitmap::begin() / Bitmap::end()Nico Weber
Useful for accessing a bitmap like a linear container.
2023-04-05LibGfx: Read webp lossless header using LittleEndianInputBitStreamNico Weber
No behavior change. Covered by existing webp decoder tests :^)
2023-04-03LibGfx/JPEG: Add YCCK and CMYK to RGB color transformationsLucas CHOLLET
It means that we now fully support JPEGs with four components :^).
2023-04-03LibGfx/JPEG: Support for images with four componentsLucas CHOLLET
This patch adds support for properly read images with four components, basically CMYK or YCCK. However, we still lack color spaces transformations for this type of image. So, it just postpones failure.
2023-04-03LibGfx/JPEG: Replace C-style array by `Array`Lucas CHOLLET
2023-04-03LibGfx/JPEG: Bring IDCT and YCbCr conversion closer to specificationLucas CHOLLET
As mentioned in F.2.1.5 - Inverse DCT (IDCT), the decoder needs to perform a level shift by adding 128. This used to be done in `ycbcr_to_rgb` after the conversion. Now, we do it in `inverse_dct` in order to ensure that the task is done unconditionally. Consequences of this are that we are no longer required to explicitly do it for RGB images and also, the `ycbcr_to_rgb` function is exactly like the specification.