2011-05-07 00:40:09 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2011 John-Mark Bell <jmb@netsurf-browser.org>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#include <stdbool.h>
|
2015-04-14 01:19:04 +03:00
|
|
|
#include <stdlib.h>
|
2011-08-28 18:29:15 +04:00
|
|
|
|
2016-04-20 01:20:29 +03:00
|
|
|
#include "utils/utils.h"
|
2011-12-30 04:58:35 +04:00
|
|
|
#include "utils/log.h"
|
2015-04-14 01:19:04 +03:00
|
|
|
#include "utils/messages.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2016-05-27 01:01:03 +03:00
|
|
|
#include "netsurf/bitmap.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
|
|
|
#include "desktop/gui_internal.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2016-06-06 16:47:27 +03:00
|
|
|
#include "image/bmp.h"
|
|
|
|
#include "image/gif.h"
|
|
|
|
#include "image/ico.h"
|
|
|
|
#include "image/jpeg.h"
|
|
|
|
#include "image/nssprite.h"
|
|
|
|
#include "image/png.h"
|
|
|
|
#include "image/rsvg.h"
|
|
|
|
#include "image/svg.h"
|
2019-02-17 15:09:17 +03:00
|
|
|
#include "image/webp.h"
|
2016-06-06 16:47:27 +03:00
|
|
|
#include "image/image.h"
|
2011-08-28 18:29:15 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
/**
|
|
|
|
* Initialise image content handlers
|
|
|
|
*
|
|
|
|
* \return NSERROR_OK on success, appropriate error otherwise.
|
|
|
|
*/
|
|
|
|
nserror image_init(void)
|
|
|
|
{
|
2015-06-18 12:26:24 +03:00
|
|
|
nserror error = NSERROR_OK;
|
2011-09-05 03:50:14 +04:00
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_BMP
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nsbmp_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_GIF
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nsgif_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_BMP
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nsico_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_JPEG
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nsjpeg_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_PNG
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nspng_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_NSSPRITE
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nssprite_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
/* Prefer rsvg over libsvgtiny for svgs */
|
2011-08-28 18:29:15 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2011-05-07 00:40:09 +04:00
|
|
|
error = svg_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_RSVG
|
2011-05-07 00:40:09 +04:00
|
|
|
error = nsrsvg_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
2011-08-28 18:29:15 +04:00
|
|
|
#endif
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2019-02-17 15:09:17 +03:00
|
|
|
#ifdef WITH_WEBP
|
|
|
|
error = nswebp_init();
|
|
|
|
if (error != NSERROR_OK)
|
|
|
|
return error;
|
|
|
|
#endif
|
|
|
|
|
2015-06-18 12:26:24 +03:00
|
|
|
return error;
|
2011-05-07 00:40:09 +04:00
|
|
|
}
|
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
|
|
|
|
bool image_bitmap_plot(struct bitmap *bitmap,
|
2015-04-14 01:19:04 +03:00
|
|
|
struct content_redraw_data *data,
|
2011-12-30 04:58:35 +04:00
|
|
|
const struct rect *clip,
|
|
|
|
const struct redraw_context *ctx)
|
|
|
|
{
|
|
|
|
bitmap_flags_t flags = BITMAPF_NONE;
|
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
unsigned char *pixel;
|
|
|
|
plot_style_t fill_style;
|
|
|
|
struct rect area;
|
|
|
|
|
2015-04-14 01:19:04 +03:00
|
|
|
width = guit->bitmap->get_width(bitmap);
|
2011-12-30 04:58:35 +04:00
|
|
|
if (width == 1) {
|
2015-04-14 01:19:04 +03:00
|
|
|
height = guit->bitmap->get_height(bitmap);
|
2011-12-30 04:58:35 +04:00
|
|
|
if (height == 1) {
|
|
|
|
/* optimise 1x1 bitmap plot */
|
2015-04-14 01:19:04 +03:00
|
|
|
pixel = guit->bitmap->get_buffer(bitmap);
|
2011-12-30 04:58:35 +04:00
|
|
|
fill_style.fill_colour = pixel_to_colour(pixel);
|
|
|
|
|
2015-04-14 01:19:04 +03:00
|
|
|
if (guit->bitmap->get_opaque(bitmap) ||
|
2011-12-30 04:58:35 +04:00
|
|
|
((fill_style.fill_colour & 0xff000000) == 0xff000000)) {
|
|
|
|
|
|
|
|
area = *clip;
|
|
|
|
|
|
|
|
if (data->repeat_x != true) {
|
|
|
|
area.x0 = data->x;
|
|
|
|
area.x1 = data->x + data->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data->repeat_y != true) {
|
|
|
|
area.y0 = data->y;
|
|
|
|
area.y1 = data->y + data->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
fill_style.stroke_type = PLOT_OP_TYPE_NONE;
|
|
|
|
fill_style.fill_type = PLOT_OP_TYPE_SOLID;
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
return (ctx->plot->rectangle(ctx,
|
|
|
|
&fill_style,
|
|
|
|
&area) == NSERROR_OK);
|
2011-12-30 04:58:35 +04:00
|
|
|
|
|
|
|
} else if ((fill_style.fill_colour & 0xff000000) == 0) {
|
|
|
|
/* transparent pixel used as spacer, skip it */
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 01:19:04 +03:00
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
/* do the plot */
|
|
|
|
if (data->repeat_x)
|
|
|
|
flags |= BITMAPF_REPEAT_X;
|
|
|
|
if (data->repeat_y)
|
|
|
|
flags |= BITMAPF_REPEAT_Y;
|
|
|
|
|
2017-02-11 16:54:08 +03:00
|
|
|
return (ctx->plot->bitmap(ctx,
|
|
|
|
bitmap,
|
|
|
|
data->x, data->y,
|
|
|
|
data->width, data->height,
|
|
|
|
data->background_colour,
|
|
|
|
flags) == NSERROR_OK);
|
2011-12-30 04:58:35 +04:00
|
|
|
}
|