1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:57:46 +00:00

LibPDF: Add initial image display support

After adding support for XObject Form rendering, the next was to display
XObject images. This commit adds this initial support,

Images come in many shapes and forms: encodings: color spaces, bits per
component, width, height, etc. This initial support is constrained to
the color spaces we currently support, to images that use 8 bits per
component, to images that do *not* use the JPXDecode filter, and that
are not Masks. There are surely other constraints that aren't considered
in this initial support, so expect breakage here and there.

In addition to supporting images, we also support applying an alpha mask
(SMask) on them. Additionally, a new rendering preference allows to skip
image loading and rendering altogether, instead showing an empty
rectangle as a placeholder (useful for when actual images are not
supported). Since RenderingPreferences is becoming a bit more complex,
we add a hash option that will allow us to keep track of different
preferences (e.g., in a HashMap).
This commit is contained in:
Rodrigo Tobar 2022-11-25 02:01:53 +08:00 committed by Andreas Kling
parent 2331fe5e68
commit adc45635e9
3 changed files with 148 additions and 5 deletions

View file

@ -86,6 +86,12 @@ struct GraphicsState {
struct RenderingPreferences {
bool show_clipping_paths { false };
bool show_images { true };
unsigned hash() const
{
return static_cast<unsigned>(show_clipping_paths) | static_cast<unsigned>(show_images) << 1;
}
};
class Renderer {
@ -109,6 +115,9 @@ private:
void end_path_paint();
PDFErrorOr<void> set_graphics_state_from_dict(NonnullRefPtr<DictObject>);
void show_text(DeprecatedString const&);
PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> load_image(NonnullRefPtr<StreamObject>);
PDFErrorOr<void> show_image(NonnullRefPtr<StreamObject>);
void show_empty_image(int width, int height);
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space_from_resources(Value const&, NonnullRefPtr<DictObject>);
PDFErrorOr<NonnullRefPtr<ColorSpace>> get_color_space_from_document(NonnullRefPtr<Object>);
@ -127,6 +136,7 @@ private:
ALWAYS_INLINE Gfx::Rect<T> map(Gfx::Rect<T>) const;
Gfx::AffineTransform const& calculate_text_rendering_matrix();
Gfx::AffineTransform calculate_image_space_transformation(int width, int height);
RefPtr<Document> m_document;
RefPtr<Gfx::Bitmap> m_bitmap;