summaryrefslogtreecommitdiff
path: root/image
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2011-12-30 00:58:35 +0000
committerVincent Sanders <vince@netsurf-browser.org>2011-12-30 00:58:35 +0000
commitdf18a971435c35963bb8ea94efc0d5326ad66ff0 (patch)
tree0f0ccea83c6f4cd82d7195478d7bd35f7ae89e31 /image
parent4dd695c156879ad845a33ad8ef9748b0f54a4f1a (diff)
downloadnetsurf-df18a971435c35963bb8ea94efc0d5326ad66ff0.tar.gz
netsurf-df18a971435c35963bb8ea94efc0d5326ad66ff0.tar.bz2
Change GTK plotting to use cairo surfaces throughout
svn path=/trunk/netsurf/; revision=13354
Diffstat (limited to 'image')
-rw-r--r--image/gif.c13
-rw-r--r--image/image.c69
-rw-r--r--image/image.h13
-rw-r--r--image/image_cache.c17
-rw-r--r--image/png.c4
5 files changed, 89 insertions, 27 deletions
diff --git a/image/gif.c b/image/gif.c
index 098287573..8cb89c7d7 100644
--- a/image/gif.c
+++ b/image/gif.c
@@ -39,6 +39,7 @@
#include "content/hlcache.h"
#include "desktop/options.h"
#include "desktop/plotters.h"
+#include "image/image.h"
#include "image/bitmap.h"
#include "image/gif.h"
#include "utils/log.h"
@@ -337,7 +338,6 @@ static bool nsgif_redraw(struct content *c, struct content_redraw_data *data,
const struct rect *clip, const struct redraw_context *ctx)
{
nsgif_content *gif = (nsgif_content *) c;
- bitmap_flags_t flags = BITMAPF_NONE;
if (gif->current_frame != gif->gif->decoded_frame) {
if (nsgif_get_frame(gif) != GIF_OK) {
@@ -345,16 +345,7 @@ static bool nsgif_redraw(struct content *c, struct content_redraw_data *data,
}
}
- if ((data->width == -1) && (data->height == -1))
- return true;
-
- 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,
- gif->gif->frame_image, data->background_colour, flags);
+ return image_bitmap_plot(gif->gif->frame_image, data, clip, ctx);
}
diff --git a/image/image.c b/image/image.c
index cf5badc4d..becf221b9 100644
--- a/image/image.c
+++ b/image/image.c
@@ -22,8 +22,11 @@
#include <string.h>
#include "utils/errors.h"
+#include "utils/config.h"
+#include "utils/log.h"
+#include "desktop/plotters.h"
+#include "image/bitmap.h"
-#include "image/image.h"
#include "image/bmp.h"
#include "image/gif.h"
#include "image/ico.h"
@@ -35,7 +38,7 @@
#include "image/svg.h"
#include "image/webp.h"
-#include "utils/config.h"
+#include "image/image.h"
/**
* Initialise image content handlers
@@ -114,3 +117,65 @@ nserror image_init(void)
return NSERROR_OK;
}
+
+bool image_bitmap_plot(struct bitmap *bitmap,
+ struct content_redraw_data *data,
+ 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;
+
+ width = bitmap_get_width(bitmap);
+ if (width == 1) {
+ height = bitmap_get_height(bitmap);
+ if (height == 1) {
+ /* optimise 1x1 bitmap plot */
+ pixel = bitmap_get_buffer(bitmap);
+ fill_style.fill_colour = pixel_to_colour(pixel);
+
+ if (bitmap_get_opaque(bitmap) ||
+ ((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;
+
+ return ctx->plot->rectangle(area.x0, area.y0,
+ area.x1, area.y1,
+ &fill_style);
+
+ } else if ((fill_style.fill_colour & 0xff000000) == 0) {
+ /* transparent pixel used as spacer, skip it */
+ return true;
+ }
+ }
+ }
+
+ /* 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);
+
+
+}
diff --git a/image/image.h b/image/image.h
index 7a698e54e..eb9482583 100644
--- a/image/image.h
+++ b/image/image.h
@@ -25,6 +25,19 @@
#include "utils/errors.h"
+/** Initialise the content handlers for image types.
+ */
nserror image_init(void);
+/** Common image content handler bitmap plot call.
+ *
+ * This plots the specified bitmap controlled by the redraw context
+ * and specific content redraw data. It is a helper specifically
+ * provided for image content handlers redraw callback.
+ */
+bool image_bitmap_plot(struct bitmap *bitmap,
+ struct content_redraw_data *data,
+ const struct rect *clip,
+ const struct redraw_context *ctx);
+
#endif
diff --git a/image/image_cache.c b/image/image_cache.c
index 354aee2ce..c31d3e964 100644
--- a/image/image_cache.c
+++ b/image/image_cache.c
@@ -22,13 +22,12 @@
#include <stdbool.h>
#include <string.h>
-#include "utils/errors.h"
-#include "utils/utils.h"
-#include "utils/log.h"
-#include "utils/config.h"
#include "utils/schedule.h"
+#include "utils/log.h"
#include "content/content_protected.h"
+
#include "image/image_cache.h"
+#include "image/image.h"
/** Age of an entry within the cache
*
@@ -712,7 +711,6 @@ bool image_cache_redraw(struct content *c,
const struct rect *clip,
const struct redraw_context *ctx)
{
- bitmap_flags_t flags = BITMAPF_NONE;
struct image_cache_entry_s *centry;
/* get the cache entry */
@@ -746,14 +744,7 @@ bool image_cache_redraw(struct content *c,
centry->redraw_count++;
centry->redraw_age = image_cache->current_age;
- /* 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,
- centry->bitmap, data->background_colour, flags);
+ return image_bitmap_plot(centry->bitmap, data, clip, ctx);
}
void image_cache_destroy(struct content *content)
diff --git a/image/png.c b/image/png.c
index fefb956b2..7c0aa56f1 100644
--- a/image/png.c
+++ b/image/png.c
@@ -498,7 +498,9 @@ png_cache_convert_error:
free((png_bytep *) row_pointers);
- return (struct bitmap *) bitmap;
+ bitmap_modified((struct bitmap *)bitmap);
+
+ return (struct bitmap *)bitmap;
}
static bool nspng_convert(struct content *c)