Commit graph

405 commits

Author SHA1 Message Date
Linus Groh
e4bba2fab9 LibGfx: Keep alpha value of previous pixel for QOI_OP_RGB chunk
I accidentally skipped this part of the spec in the QOI decoder:

> The alpha value remains unchanged from the previous pixel.

This led to incorrect rendering of some images with transparency,
visible in form of a horizontal line of non-transparent pixels (that
shouldn't exist), e.g. for the following chunk sequence:

- QOI_OP_RGBA with alpha = 0
- QOI_OP_RGB
- QOI_OP_RUN

The QOI_OP_RGB should 'inherit' the alpha value of the previous
QOI_OP_RGBA chunk, instead of always setting it to 255.
I'm unsure why the encoder added the QOI_OP_RGB chunk to the specific
image where the bug was noticed in the first place - they effectively
both had fully transparent color values.
2021-12-22 01:12:51 +01:00
Nick Johnson
08e4a1a4dc AK+Everywhere: Replace __builtin bit functions
In order to reduce our reliance on __builtin_{ffs, clz, ctz, popcount},
this commit removes all calls to these functions and replaces them with
the equivalent functions in AK/BuiltinWrappers.h.
2021-12-21 22:13:51 +01:00
Linus Groh
a00a3fa1ef LibGfx: Remove 'QOIImageDecoderPlugin: ' prefix from error messages
What the component which did the actual decoding is called is not
relevant for the error, and would be rather distracting once we show
decoding error messages e.g. in ImageViewer (instead of just silently
failing).
Also makes them more consistent as many already don't include it - a
mistake which is now turned into a feature :^)
2021-12-21 17:37:10 +01:00
Linus Groh
0356ee95bc LibGfx: Add support for "The Quite OK Image Format" (QOI)
The spec had its first stable release today, so I figured we should
support it as well!
As usual, by using the regular LibGfx image decoder plugin architecture,
we immediately get support for it everywhere: ImageViewer, FileManager
thumbnails, PixelPaint, and (with a small change in the subsequent
commit) even the Browser :^)
2021-12-21 13:27:27 +01:00
Brian Gianforcaro
c710d52afa LibGfx: Handle malformed Platform ID during TTF parsing
This should fix one of the OSS Fuzz crashes that occurs during
TTF file format parsing.

See: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=37263
2021-12-16 18:50:02 +01:00
thankyouverycool
e29abc5395 LibGfx+FontEditor: Consolidate BitmapFont width and height limits
And make them more self-documenting. Previously these constraints
were duplicated across multiple files.
2021-11-30 10:51:51 +01:00
thankyouverycool
edf86af4f4 LibGfx+FontEditor: Add helper to determine raw glyph presence
GlyphBitmaps are considered present if they have a width greater
than zero. This adds a counterpart method for raw (unmasked) glyphs
and makes intent more explicit throughout FontEditor.
2021-11-30 10:51:51 +01:00
Hendiadyoin1
51cf35988b LibGfx: Link against LibIPC
Gfx::Color implements an IPC::[en|de]code function, but we did not
actually link against LibIPC to resolve the needed Symbols for that and
were relying on LibGui or others to link against it for us.

Having this linkage is unfortunate, but static inlining the functions in
question is sadly not possible, due needed includes leading the IPC
pipeline to initialize multiple times then, which leads to a compilation
error.
2021-11-29 23:17:05 +03:30
Hendiadyoin1
9e7c16d0a4 LibGfx: Load default font lazily
This is required when trying to use a Painter from lagom, due to
/res/font not being present
2021-11-29 23:17:05 +03:30
Andreas Kling
cb9cac4e40 LibIPC+IPCCompiler+AK: Make IPC value decoders return ErrorOr<void>
This allows us to use TRY() in decoding helpers, leading to a nice
reduction in line count.
2021-11-28 23:14:19 +01:00
thankyouverycool
781bc67a96 LibGfx: Correct BitmapFont row indexing when un/masking fonts
Now indexes by total bytes per glyph to account for changes made
to row's pointer type in 3ca00c8. Fixes glyphs not showing and
saving correctly in FontEditor.
2021-11-24 16:05:40 +03:30
Andreas Kling
adb9b86807 LibGfx: Use Core::System::open() in Gfx::Bitmap :^) 2021-11-23 12:23:54 +01:00
Andreas Kling
58fb3ebf66 LibCore+AK: Move MappedFile from AK to LibCore
MappedFile is strictly a userspace thing, so it doesn't belong in AK
(which is supposed to be user/kernel agnostic.)
2021-11-23 11:33:36 +01:00
Ali Mohammad Pur
3ca00c8ae6 LibGfx: Avoid unaligned loads and stores in GlyphBitmap 2021-11-22 21:10:25 -08:00
Andreas Kling
b6359b211d LibGfx: Use StringView for header constants in the GIF decoder 2021-11-21 20:22:48 +01:00
Andreas Kling
88da7cc383 LibGfx: Use ErrorOr<void> more internally in PNGImageDecoderPlugin 2021-11-21 20:22:48 +01:00
Andreas Kling
5a79c69b02 LibGfx: Make ImageDecoderPlugin::frame() return ErrorOr<>
This is a first step towards better error propagation from image codecs.
2021-11-21 20:22:48 +01:00
Andreas Kling
2b866e3c9b LibGfx: Remove ImageDecoderPlugin::bitmap() in favor of frame(index)
To encourage proper support for multi-frame images throughout the
system, get rid of the single-frame convenience bitmap() API.
2021-11-18 21:11:30 +01:00
Andreas Kling
216e21a1fa AK: Convert AK::Format formatting helpers to returning ErrorOr<void>
This isn't a complete conversion to ErrorOr<void>, but a good chunk.
The end goal here is to propagate buffer allocation failures to the
caller, and allow the use of TRY() with formatting functions.
2021-11-17 00:21:13 +01:00
Karol Kosek
c3256a51cb LibGfx: Remove scale factor option from try_load_from_fd_and_close()
... and bring it back to try_load_from_file().

Prior to this change, changing the scaling option to x2 in the Display
Settings resulted in the following crash:

  WindowServer(15:15): ASSERTION FAILED: bitmap->width() % scale_factor
  == 0 ./Userland/Libraries/LibGfx/Bitmap.cpp:126

That was caused by two minor overlooked yaks:

- First, Bitmap::try_load_from_fd_and_close() tried to respect your
  scale factor.

  While requesting a bitmap from file can make a switcheroo to give you
  a higher resolution bitmap, doing the same when you already have an fd
  might violate the unveil agreement.
  ... but, it didn't do that.

  It read bitmaps from requested fds, but also pretended all system
  bitmaps in /res/ are the HiDPI ones when you enabled that mode.

- d85d741c59 used this function to deduplicate try_load_from_file().

  It actually made this bug a lot easier to replicate!


Closes #10920
2021-11-16 01:07:37 +00:00
Andreas Kling
47edd6ae89 LibGfx: Remove all load_FORMAT_from_memory() decoder wrappers
There are no more clients of these APIs, now that everyone has been made
to use ImageDecoderPlugin objects instead.
2021-11-13 00:55:07 +01:00
Timothy Flynn
7cc50d614c LibGfx: Include Vector.h in PNGLoader.cpp
This was being transitively included from Deflate.h on SerenityOS builds
but not on Lagom builds.
2021-11-11 12:46:48 +00:00
Andreas Kling
2bd0ef0c76 LibGfx: Remove now-unused load_gif_from_memory() 2021-11-11 11:45:32 +01:00
Andreas Kling
880fafd2c5 LibGfx: Use ImageDecoder in Bitmap::try_load_from_fd_and_close()
Before this patch, both Bitmap and ImageDecoder had logic for guessing
which image codec to use for a chunk of data. Bitmap now defers to
ImageDecoder so that we only have to do this in one place.

There's room for improvement in the ImageDecoder heuristic, but that's
outside the scope of this change.
2021-11-11 11:43:08 +01:00
Andreas Kling
10add3f4c2 LibGfx: Remove load_FORMAT() image codec wrappers
We had a bunch of old unused wrapper functions for each image codec that
would load a supported image with a given path. Nobody actually used
them, so let's just get rid of load_png(), load_gif(), etc.
2021-11-11 11:32:22 +01:00
Andreas Kling
80d4e830a0 Everywhere: Pass AK::ReadonlyBytes by value 2021-11-11 01:27:46 +01:00
Andreas Kling
8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling
a15ed8743d AK: Make ByteBuffer::try_* functions return ErrorOr<void>
Same as Vector, ByteBuffer now also signals allocation failure by
returning an ENOMEM Error instead of a bool, allowing us to use the
TRY() and MUST() patterns.
2021-11-10 21:58:58 +01:00
Andreas Kling
5f7d008791 AK+Everywhere: Stop including Vector.h from StringView.h
Preparation for using Error.h from Vector.h. This required moving some
things out of line.
2021-11-10 21:58:58 +01:00
Andreas Kling
a7f1f1c34b LibCore: Use ErrorOr<T> for Core::File::open() 2021-11-08 00:35:27 +01:00
Andreas Kling
0f5477c721 AK: Use ErrorOr<T> for MappedFile factories
Replace Result<T, E> with ErrorOr<T> and propagate the error to callers.
2021-11-08 00:35:27 +01:00
Andreas Kling
6e255b262f LibGfx: Use ErrorOr<T> for try_create_from_serialized_byte_buffer() 2021-11-08 00:35:27 +01:00
Andreas Kling
0de33b3d6c LibGfx: Use ErrorOr<T> for Bitmap::try_create()
Another one that was used in a fajillion places.
2021-11-08 00:35:27 +01:00
Andreas Kling
235f39e449 LibGfx: Use ErrorOr<T> for Bitmap::try_load_from_file()
This was used in a lot of places, so this patch makes liberal use of
ErrorOr<T>::release_value_but_fixme_should_propagate_errors().
2021-11-08 00:35:27 +01:00
Andreas Kling
16f064d9be LibGfx: Convert Gfx::Bitmap to east const style 2021-11-08 00:35:27 +01:00
Andreas Kling
d85d741c59 LibGfx: Deduplicate code in Bitmap::try_load_from_file()
This can share logic with try_load_from_fd_and_close(), we just need to
open the file first. :^)
2021-11-08 00:35:27 +01:00
Andreas Kling
09cba7c780 LibGfx: Use ErrorOr<T> for Bitmap infrastructure used by ShareableBitmap
This also allows us to get rid of the ShareableBitmap(Bitmap)
constructor which was easy to misuse. Everyone now uses Bitmap's
to_shareable_bitmap() helper instead.
2021-11-08 00:35:27 +01:00
Andreas Kling
8262bbf624 LibGfx: Use ErrorOr<T> for Bitmap::cropped() 2021-11-08 00:35:27 +01:00
Andreas Kling
5e41c70e83 LibGfx: Use ErrorOr<T> for Bitmap::scaled() 2021-11-08 00:35:27 +01:00
Andreas Kling
db90b4554e LibGfx: Use ErrorOr<T> for Bitmap::flipped() 2021-11-08 00:35:27 +01:00
Andreas Kling
69c4614a94 LibGfx: Use ErrorOr<T> for Bitmap::rotated() 2021-11-08 00:35:27 +01:00
Andreas Kling
2da4cfcc80 LibGfx: Use ErrorOr<T> for Bitmap::clone() 2021-11-08 00:35:27 +01:00
Andreas Kling
c417820bff LibGfx: Use ErrorOr<T> for Bitmap::try_create_shareable() 2021-11-08 00:35:27 +01:00
Andreas Kling
83d1460ee8 LibGfx: Use ErrorOr<T> for Bitmap::try_create_wrapper() 2021-11-08 00:35:27 +01:00
Andreas Kling
f23f99d51b LibGfx: Use ErrorOr<T> for Bitmap::try_create_with_anonymous_buffer() 2021-11-08 00:35:27 +01:00
Andreas Kling
e5dde37e24 AK: Bring AK::Error into the global namespace 2021-11-08 00:35:27 +01:00
Andreas Kling
af562c857e LibGfx: Use ErrorOr<T> for Gfx::Bitmap::allocate_backing_store() 2021-11-08 00:35:27 +01:00
Andreas Kling
e2eabb4132 LibCore: Use ErrorOr<T> in Core::AnonymousBuffer 2021-11-08 00:35:27 +01:00
Sam Atkins
f22043a225 LibGfx: Add FlagRole to GUI::Variant 2021-11-05 23:34:22 +01:00
Sam Atkins
d68268f791 LibGfx: Use read_bool_entry() to read theme flags
I didn't notice this function existed the first time around. Oops!
2021-11-05 23:34:22 +01:00