NetSurf
image.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdbool.h>
20#include <stdlib.h>
21
22#include "utils/utils.h"
23#include "utils/log.h"
24#include "utils/messages.h"
25#include "netsurf/plotters.h"
26#include "netsurf/bitmap.h"
27#include "netsurf/content.h"
29#include "desktop/bitmap.h"
30
31#include "image/bmp.h"
32#include "image/gif.h"
33#include "image/ico.h"
34#include "image/jpeg.h"
35#include "image/jpegxl.h"
36#include "image/nssprite.h"
37#include "image/png.h"
38#include "image/rsvg.h"
39#include "image/svg.h"
40#include "image/webp.h"
41#include "image/image.h"
42
43/**
44 * Initialise image content handlers
45 *
46 * \return NSERROR_OK on success, appropriate error otherwise.
47 */
49{
50 nserror error = NSERROR_OK;
51
52#ifdef WITH_BMP
53 error = nsbmp_init();
54 if (error != NSERROR_OK)
55 return error;
56#endif
57
58#ifdef WITH_GIF
59 error = nsgif_init();
60 if (error != NSERROR_OK)
61 return error;
62#endif
63
64#ifdef WITH_BMP
65 error = nsico_init();
66 if (error != NSERROR_OK)
67 return error;
68#endif
69
70#ifdef WITH_JPEG
71 error = nsjpeg_init();
72 if (error != NSERROR_OK)
73 return error;
74#endif
75
76#ifdef WITH_JPEGXL
77 error = nsjpegxl_init();
78 if (error != NSERROR_OK)
79 return error;
80#endif
81
82#ifdef WITH_PNG
83 error = nspng_init();
84 if (error != NSERROR_OK)
85 return error;
86#endif
87
88#ifdef WITH_NSSPRITE
89 error = nssprite_init();
90 if (error != NSERROR_OK)
91 return error;
92#endif
93
94 /* Prefer rsvg over libsvgtiny for svgs */
95#ifdef WITH_NS_SVG
96 error = svg_init();
97 if (error != NSERROR_OK)
98 return error;
99#endif
100#ifdef WITH_RSVG
101 error = nsrsvg_init();
102 if (error != NSERROR_OK)
103 return error;
104#endif
105
106#ifdef WITH_WEBP
107 error = nswebp_init();
108 if (error != NSERROR_OK)
109 return error;
110#endif
111
112 return error;
113}
114
115
117 struct content_redraw_data *data,
118 const struct rect *clip,
119 const struct redraw_context *ctx)
120{
122
123 int width;
124 int height;
125 unsigned char *pixel;
126 plot_style_t fill_style;
127 struct rect area;
128
130 if (width == 1) {
132 if (height == 1) {
133 /* optimise 1x1 bitmap plot */
134 pixel = guit->bitmap->get_buffer(bitmap);
135 fill_style.fill_colour = bitmap_pixel_to_colour(pixel);
136
137 if (guit->bitmap->get_opaque(bitmap) ||
138 ((fill_style.fill_colour & 0xff000000) == 0xff000000)) {
139
140 area = *clip;
141
142 if (data->repeat_x != true) {
143 area.x0 = data->x;
144 area.x1 = data->x + data->width;
145 }
146
147 if (data->repeat_y != true) {
148 area.y0 = data->y;
149 area.y1 = data->y + data->height;
150 }
151
152 fill_style.stroke_type = PLOT_OP_TYPE_NONE;
153 fill_style.fill_type = PLOT_OP_TYPE_SOLID;
154
155 return (ctx->plot->rectangle(ctx,
156 &fill_style,
157 &area) == NSERROR_OK);
158
159 } else if ((fill_style.fill_colour & 0xff000000) == 0) {
160 /* transparent pixel used as spacer, skip it */
161 return true;
162 }
163 }
164 }
165
166 /* do the plot */
167 if (data->repeat_x)
168 flags |= BITMAPF_REPEAT_X;
169 if (data->repeat_y)
170 flags |= BITMAPF_REPEAT_Y;
171
172 return (ctx->plot->bitmap(ctx,
173 bitmap,
174 data->x, data->y,
175 data->width, data->height,
176 data->background_colour,
177 flags) == NSERROR_OK);
178}
interface to image/bmp content handler initialisation.
nserror nsbmp_init(void)
bool image_bitmap_plot(struct bitmap *bitmap, struct content_redraw_data *data, const struct rect *clip, const struct redraw_context *ctx)
Common image content handler bitmap plot call.
Definition: image.c:116
nserror image_init(void)
Initialise image content handlers.
Definition: image.c:48
Initialisation/finalisation of image handlers.
Internal core bitmap interface.
static colour bitmap_pixel_to_colour(const uint8_t *pixel)
Convert a bitmap pixel to a NetSurf colour (0xAARRGGBB).
Definition: bitmap.h:53
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
Content for image/gif (interface).
nserror nsgif_init(void)
struct netsurf_table * guit
The global interface table.
Definition: gui_factory.c:49
Interface to core interface table.
Content for image/ico (interface).
nserror nsico_init(void)
Generic bitmap handling interface.
Public content interface.
Target independent plotting interface.
#define BITMAPF_REPEAT_X
Definition: plotters.h:38
#define BITMAPF_REPEAT_Y
Definition: plotters.h:39
unsigned long bitmap_flags_t
Definition: plotters.h:36
#define BITMAPF_NONE
Definition: plotters.h:37
Content for image/jpeg (interface).
nserror nsjpeg_init(void)
Content for image/jpegxl (interface).
nserror nsjpegxl_init(void)
Localised message support (interface).
Content for image/x-riscos-sprite (librosprite interface).
nserror nssprite_init(void)
@ PLOT_OP_TYPE_NONE
No operation.
Definition: plot_style.h:66
@ PLOT_OP_TYPE_SOLID
Solid colour.
Definition: plot_style.h:67
nserror nspng_init(void)
int width
Definition: gui.c:159
int height
Definition: gui.c:160
Content handler for image/svg using librsvg (interface).
nserror nsrsvg_init(void)
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
parameters to content redraw
Definition: content.h:40
int height
vertical dimension
Definition: content.h:48
bool repeat_y
whether content is tiled in y direction
Definition: content.h:59
bool repeat_x
whether content is tiled in x direction
Definition: content.h:58
int y
coordinate for top-left of redraw
Definition: content.h:42
int x
coordinate for top-left of redraw
Definition: content.h:41
colour background_colour
The background colour.
Definition: content.h:51
int width
dimensions to render content at (for scaling contents with intrinsic dimensions)
Definition: content.h:47
int(* get_height)(void *bitmap)
Get the bitmap height.
Definition: bitmap.h:193
int(* get_width)(void *bitmap)
Get the bitmap width.
Definition: bitmap.h:185
bool(* get_opaque)(void *bitmap)
Get the opacity of a bitmap.
Definition: bitmap.h:159
unsigned char *(* get_buffer)(void *bitmap)
Get the image buffer from a bitmap.
Definition: bitmap.h:169
struct gui_bitmap_table * bitmap
Bitmap table.
Definition: gui_table.h:144
Plot style for stroke/fill plotters.
Definition: plot_style.h:76
colour fill_colour
Colour of fill.
Definition: plot_style.h:81
plot_operation_type_t fill_type
Fill plot type.
Definition: plot_style.h:80
plot_operation_type_t stroke_type
Stroke plot type.
Definition: plot_style.h:77
nserror(* rectangle)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *rectangle)
Plots a rectangle.
Definition: plotters.h:188
nserror(* bitmap)(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.
Definition: plotters.h:257
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
const struct plotter_table * plot
Current plot operation table.
Definition: plotters.h:73
Content for image/svg (interface).
nserror svg_init(void)
Interface to a number of general purpose functionality.
Interface to image/webp content handlers.
nserror nswebp_init(void)
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357