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
|
|
|
|
2011-12-30 04:58:35 +04:00
|
|
|
#include "utils/log.h"
|
2015-04-14 01:19:04 +03:00
|
|
|
#include "utils/messages.h"
|
2014-05-19 02:16:46 +04:00
|
|
|
#include "content/content.h"
|
2015-04-14 01:19:04 +03:00
|
|
|
#include "desktop/plotters.h"
|
|
|
|
#include "desktop/gui_internal.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2015-04-14 01:19:04 +03:00
|
|
|
#include "image/bitmap.h"
|
2011-05-07 00:40:09 +04: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"
|
2011-12-30 04:58:35 +04: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
|
|
|
|
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;
|
|
|
|
|
2015-04-14 01:19:04 +03:00
|
|
|
return ctx->plot->rectangle(area.x0, area.y0,
|
|
|
|
area.x1, area.y1,
|
2011-12-30 04:58:35 +04:00
|
|
|
&fill_style);
|
|
|
|
|
|
|
|
} 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;
|
|
|
|
|
|
|
|
return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
|
|
|
|
bitmap, data->background_colour, flags);
|
|
|
|
}
|