diff options
-rw-r--r-- | debug/debug_bitmap.c | 226 | ||||
-rw-r--r-- | desktop/plotters.h | 98 | ||||
-rw-r--r-- | gtk/gtk_bitmap.c | 282 | ||||
-rw-r--r-- | gtk/gtk_plotters.c | 458 | ||||
-rw-r--r-- | image/bitmap.h | 74 | ||||
-rw-r--r-- | riscos/bitmap.c | 380 |
6 files changed, 759 insertions, 759 deletions
diff --git a/debug/debug_bitmap.c b/debug/debug_bitmap.c index 8ac52f3ff..a4a7021ce 100644 --- a/debug/debug_bitmap.c +++ b/debug/debug_bitmap.c @@ -1,113 +1,113 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Generic bitmap handling (dummy debug implementation).
- *
- * This implements the interface given by desktop/bitmap.h using a simple
- * buffer.
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include "netsurf/image/bitmap.h"
-
-
-struct bitmap {
- int width;
- char pixels[1];
-};
-
-
-/**
- * Create a bitmap.
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-
-struct bitmap *bitmap_create(int width, int height)
-{
- struct bitmap *bitmap;
- bitmap = calloc(sizeof *bitmap + width * height * 4, 1);
- if (bitmap)
- bitmap->width = width;
- return bitmap;
-}
-
-
-/**
- * Return a pointer to the pixel data in a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return pointer to the pixel buffer
- *
- * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end
- * of rows. The width of a row in bytes is given by bitmap_get_rowstride().
- */
-
-char *bitmap_get_buffer(struct bitmap *bitmap)
-{
- assert(bitmap);
- return bitmap->pixels;
-}
-
-
-/**
- * Find the width of a pixel row in bytes.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return width of a pixel row in the bitmap
- */
-
-size_t bitmap_get_rowstride(struct bitmap *bitmap)
-{
- assert(bitmap);
- return bitmap->width * 4;
-}
-
-
-/**
- * Free a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-
-void bitmap_destroy(struct bitmap *bitmap)
-{
- assert(bitmap);
- free(bitmap);
-}
-
-
-/**
- * Render a bitmap.
- */
-
-bool bitmap_redraw(struct content *c, int x, int y,
- int width, int height,
- int clip_x0, int clip_y0, int clip_x1, int clip_y1,
- float scale, unsigned long background_colour)
-{
- return true;
-}
-
-
-/**
- * Save a bitmap in the platform's native format.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param path pathname for file
- * \return true on success, false on error and error reported
- */
-
-bool bitmap_save(struct bitmap *bitmap, const char *path)
-{
- return true;
-}
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Generic bitmap handling (dummy debug implementation). + * + * This implements the interface given by desktop/bitmap.h using a simple + * buffer. + */ + +#include <assert.h> +#include <stdbool.h> +#include <stdlib.h> +#include "netsurf/image/bitmap.h" + + +struct bitmap { + int width; + char pixels[1]; +}; + + +/** + * Create a bitmap. + * + * \param width width of image in pixels + * \param height width of image in pixels + * \return an opaque struct bitmap, or NULL on memory exhaustion + */ + +struct bitmap *bitmap_create(int width, int height) +{ + struct bitmap *bitmap; + bitmap = calloc(sizeof *bitmap + width * height * 4, 1); + if (bitmap) + bitmap->width = width; + return bitmap; +} + + +/** + * Return a pointer to the pixel data in a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return pointer to the pixel buffer + * + * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end + * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). + */ + +char *bitmap_get_buffer(struct bitmap *bitmap) +{ + assert(bitmap); + return bitmap->pixels; +} + + +/** + * Find the width of a pixel row in bytes. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return width of a pixel row in the bitmap + */ + +size_t bitmap_get_rowstride(struct bitmap *bitmap) +{ + assert(bitmap); + return bitmap->width * 4; +} + + +/** + * Free a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ + +void bitmap_destroy(struct bitmap *bitmap) +{ + assert(bitmap); + free(bitmap); +} + + +/** + * Render a bitmap. + */ + +bool bitmap_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, + float scale, unsigned long background_colour) +{ + return true; +} + + +/** + * Save a bitmap in the platform's native format. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param path pathname for file + * \return true on success, false on error and error reported + */ + +bool bitmap_save(struct bitmap *bitmap, const char *path) +{ + return true; +} diff --git a/desktop/plotters.h b/desktop/plotters.h index 60465f3e8..5cf94f39b 100644 --- a/desktop/plotters.h +++ b/desktop/plotters.h @@ -1,49 +1,49 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Target independent plotting (interface).
- */
-
-#ifndef _NETSURF_DESKTOP_PLOTTERS_H_
-#define _NETSURF_DESKTOP_PLOTTERS_H_
-
-#include <stdbool.h>
-#include "netsurf/css/css.h"
-
-
-struct bitmap;
-struct font_data;
-
-
-/** Set of target specific plotting functions. */
-struct plotter_table {
- bool (*clg)(colour c);
- bool (*rectangle)(int x0, int y0, int width, int height,
- int line_width, colour c, bool dotted, bool dashed);
- bool (*line)(int x0, int y0, int x1, int y1, int width,
- colour c, bool dotted, bool dashed);
- bool (*polygon)(int *p, unsigned int n, colour fill);
- bool (*fill)(int x0, int y0, int x1, int y1, colour c);
- bool (*clip)(int x0, int y0, int x1, int y1);
- bool (*text)(int x, int y, struct font_data *font, const char *text,
- size_t length, colour bg, colour c);
- bool (*disc)(int x, int y, int radius, colour c);
- bool (*bitmap)(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg);
- bool (*bitmap_tile)(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y);
- bool (*group_start)(const char *name);
- bool (*group_end)(void);
-};
-
-/** Current plotters, must be assigned before use. */
-extern struct plotter_table plot;
-
-
-#endif
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Target independent plotting (interface). + */ + +#ifndef _NETSURF_DESKTOP_PLOTTERS_H_ +#define _NETSURF_DESKTOP_PLOTTERS_H_ + +#include <stdbool.h> +#include "netsurf/css/css.h" + + +struct bitmap; +struct font_data; + + +/** Set of target specific plotting functions. */ +struct plotter_table { + bool (*clg)(colour c); + bool (*rectangle)(int x0, int y0, int width, int height, + int line_width, colour c, bool dotted, bool dashed); + bool (*line)(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed); + bool (*polygon)(int *p, unsigned int n, colour fill); + bool (*fill)(int x0, int y0, int x1, int y1, colour c); + bool (*clip)(int x0, int y0, int x1, int y1); + bool (*text)(int x, int y, struct font_data *font, const char *text, + size_t length, colour bg, colour c); + bool (*disc)(int x, int y, int radius, colour c); + bool (*bitmap)(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg); + bool (*bitmap_tile)(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y); + bool (*group_start)(const char *name); + bool (*group_end)(void); +}; + +/** Current plotters, must be assigned before use. */ +extern struct plotter_table plot; + + +#endif diff --git a/gtk/gtk_bitmap.c b/gtk/gtk_bitmap.c index ae9fd1695..0121963fe 100644 --- a/gtk/gtk_bitmap.c +++ b/gtk/gtk_bitmap.c @@ -1,141 +1,141 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Generic bitmap handling (GDK / GTK+ implementation).
- *
- * This implements the interface given by desktop/bitmap.h using GdkPixbufs.
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <string.h>
-#include <gdk/gdk.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
-#include "netsurf/content/content.h"
-#include "netsurf/image/bitmap.h"
-
-
-extern GdkDrawable *current_drawable;
-extern GdkGC *current_gc;
-
-
-struct bitmap;
-
-
-/**
- * Create a bitmap.
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-
-struct bitmap *bitmap_create(int width, int height)
-{
- GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8,
- width, height);
- return (struct bitmap *) pixbuf;
-}
-
-
-/**
- * Sets whether a bitmap should be plotted opaque
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param opaque whether the bitmap should be plotted opaque
- */
-void bitmap_set_opaque(struct bitmap *bitmap, bool opaque)
-{
- assert(bitmap);
-/* todo: set bitmap as opaque */
-}
-
-
-/**
- * Tests whether a bitmap has an opaque alpha channel
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return whether the bitmap is opaque
- */
-bool bitmap_test_opaque(struct bitmap *bitmap)
-{
- assert(bitmap);
-/* todo: test if bitmap as opaque */
- return false;
-}
-
-
-/**
- * Gets whether a bitmap should be plotted opaque
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-bool bitmap_get_opaque(struct bitmap *bitmap)
-{
- assert(bitmap);
-/* todo: get whether bitmap is opaque */
- return false;
-}
-
-
-/**
- * Return a pointer to the pixel data in a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return pointer to the pixel buffer
- *
- * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end
- * of rows. The width of a row in bytes is given by bitmap_get_rowstride().
- */
-
-char *bitmap_get_buffer(struct bitmap *bitmap)
-{
- assert(bitmap);
- return gdk_pixbuf_get_pixels((GdkPixbuf *) bitmap);
-}
-
-
-/**
- * Find the width of a pixel row in bytes.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return width of a pixel row in the bitmap
- */
-
-size_t bitmap_get_rowstride(struct bitmap *bitmap)
-{
- assert(bitmap);
- return gdk_pixbuf_get_rowstride((GdkPixbuf *) bitmap);
-}
-
-
-/**
- * Free a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-
-void bitmap_destroy(struct bitmap *bitmap)
-{
- assert(bitmap);
- g_object_unref((GdkPixbuf *) bitmap);
-}
-
-
-/**
- * Save a bitmap in the platform's native format.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param path pathname for file
- * \return true on success, false on error and error reported
- */
-
-bool bitmap_save(struct bitmap *bitmap, const char *path)
-{
- return true;
-}
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Generic bitmap handling (GDK / GTK+ implementation). + * + * This implements the interface given by desktop/bitmap.h using GdkPixbufs. + */ + +#include <assert.h> +#include <stdbool.h> +#include <string.h> +#include <gdk/gdk.h> +#include <gdk-pixbuf/gdk-pixbuf.h> +#include "netsurf/content/content.h" +#include "netsurf/image/bitmap.h" + + +extern GdkDrawable *current_drawable; +extern GdkGC *current_gc; + + +struct bitmap; + + +/** + * Create a bitmap. + * + * \param width width of image in pixels + * \param height width of image in pixels + * \return an opaque struct bitmap, or NULL on memory exhaustion + */ + +struct bitmap *bitmap_create(int width, int height) +{ + GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, + width, height); + return (struct bitmap *) pixbuf; +} + + +/** + * Sets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param opaque whether the bitmap should be plotted opaque + */ +void bitmap_set_opaque(struct bitmap *bitmap, bool opaque) +{ + assert(bitmap); +/* todo: set bitmap as opaque */ +} + + +/** + * Tests whether a bitmap has an opaque alpha channel + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return whether the bitmap is opaque + */ +bool bitmap_test_opaque(struct bitmap *bitmap) +{ + assert(bitmap); +/* todo: test if bitmap as opaque */ + return false; +} + + +/** + * Gets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +bool bitmap_get_opaque(struct bitmap *bitmap) +{ + assert(bitmap); +/* todo: get whether bitmap is opaque */ + return false; +} + + +/** + * Return a pointer to the pixel data in a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return pointer to the pixel buffer + * + * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end + * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). + */ + +char *bitmap_get_buffer(struct bitmap *bitmap) +{ + assert(bitmap); + return gdk_pixbuf_get_pixels((GdkPixbuf *) bitmap); +} + + +/** + * Find the width of a pixel row in bytes. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return width of a pixel row in the bitmap + */ + +size_t bitmap_get_rowstride(struct bitmap *bitmap) +{ + assert(bitmap); + return gdk_pixbuf_get_rowstride((GdkPixbuf *) bitmap); +} + + +/** + * Free a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ + +void bitmap_destroy(struct bitmap *bitmap) +{ + assert(bitmap); + g_object_unref((GdkPixbuf *) bitmap); +} + + +/** + * Save a bitmap in the platform's native format. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param path pathname for file + * \return true on success, false on error and error reported + */ + +bool bitmap_save(struct bitmap *bitmap, const char *path) +{ + return true; +} diff --git a/gtk/gtk_plotters.c b/gtk/gtk_plotters.c index 3af8033a1..94d39fdd4 100644 --- a/gtk/gtk_plotters.c +++ b/gtk/gtk_plotters.c @@ -1,229 +1,229 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Target independent plotting (GDK / GTK+ implementation).
- */
-
-#include <gdk/gdk.h>
-#include <gtk/gtk.h>
-#include "netsurf/desktop/plotters.h"
-#include "netsurf/render/font.h"
-#include "netsurf/utils/log.h"
-
-
-extern GtkWidget *current_widget;
-extern GdkDrawable *current_drawable;
-extern GdkGC *current_gc;
-
-
-static bool nsgtk_plot_clg(colour c);
-static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height,
- colour c, bool dotted);
-static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width,
- colour c, bool dotted, bool dashed);
-static bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill);
-static bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c);
-static bool nsgtk_plot_clip(int clip_x0, int clip_y0,
- int clip_x1, int clip_y1);
-static bool nsgtk_plot_text(int x, int y, struct font_data *font,
- const char *text, size_t length, colour bg, colour c);
-static bool nsgtk_plot_disc(int x, int y, int radius, colour colour);
-static bool nsgtk_plot_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg);
-static bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y);
-static bool nsgtk_plot_group_start(const char *name);
-static bool nsgtk_plot_group_end(void);
-static void nsgtk_set_colour(colour c);
-
-
-
-struct plotter_table plot;
-
-const struct plotter_table nsgtk_plotters = {
- nsgtk_plot_clg,
- nsgtk_plot_rectangle,
- nsgtk_plot_line,
- nsgtk_plot_polygon,
- nsgtk_plot_fill,
- nsgtk_plot_clip,
- nsgtk_plot_text,
- nsgtk_plot_disc,
- nsgtk_plot_bitmap,
- nsgtk_plot_bitmap_tile,
- nsgtk_plot_group_start,
- nsgtk_plot_group_end
-};
-
-
-bool nsgtk_plot_clg(colour c)
-{
- return true;
-}
-
-
-bool nsgtk_plot_rectangle(int x0, int y0, int width, int height,
- colour c, bool dotted)
-{
- nsgtk_set_colour(c);
- gdk_draw_rectangle(current_drawable, current_gc,
- FALSE, x0, y0, width, height);
- return true;
-}
-
-
-bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width,
- colour c, bool dotted, bool dashed)
-{
- nsgtk_set_colour(c);
- gdk_draw_line(current_drawable, current_gc,
- x0, y0, x1, y1);
- return true;
-}
-
-
-bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill)
-{
- unsigned int i;
- GdkPoint q[n];
- for (i = 0; i != n; i++) {
- q[i].x = p[i * 2];
- q[i].y = p[i * 2 + 1];
- }
- nsgtk_set_colour(fill);
- gdk_draw_polygon(current_drawable, current_gc,
- TRUE, q, n);
- return true;
-}
-
-
-bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c)
-{
- nsgtk_set_colour(c);
- gdk_draw_rectangle(current_drawable, current_gc,
- TRUE, x0, y0, x1 - x0, y1 - y0);
- return true;
-}
-
-
-bool nsgtk_plot_clip(int clip_x0, int clip_y0,
- int clip_x1, int clip_y1)
-{
- GdkRectangle clip = { clip_x0, clip_y0,
- clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1 };
- gdk_gc_set_clip_rectangle(current_gc, &clip);
- return true;
-}
-
-
-bool nsgtk_plot_text(int x, int y, struct font_data *font,
- const char *text, size_t length, colour bg, colour c)
-{
- PangoContext *context;
- PangoLayout *layout;
- PangoLayoutLine *line;
- GdkColor colour = { 0,
- ((c & 0xff) << 8) | (c & 0xff),
- (c & 0xff00) | (c & 0xff00 >> 8),
- ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) };
-
- context = gtk_widget_get_pango_context(current_widget);
- layout = pango_layout_new(context);
- pango_layout_set_font_description(layout,
- (const PangoFontDescription *) font->id);
- pango_layout_set_text(layout, text, length);
-
- line = pango_layout_get_line(layout, 0);
-
- gdk_draw_layout_line_with_colors(current_drawable, current_gc,
- x, y, line, &colour, 0);
-
- g_object_unref(layout);
-
- return true;
-}
-
-
-bool nsgtk_plot_disc(int x, int y, int radius, colour colour)
-{
- return true;
-}
-
-
-bool nsgtk_plot_bitmap(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg)
-{
- GdkPixbuf *pixbuf = (GdkPixbuf *) bitmap;
-
- if (gdk_pixbuf_get_width(pixbuf) == width &&
- gdk_pixbuf_get_height(pixbuf) == height) {
- gdk_draw_pixbuf(current_drawable, current_gc,
- pixbuf,
- 0, 0,
- x, y,
- width, height,
- GDK_RGB_DITHER_NORMAL, 0, 0);
-
- } else {
- GdkPixbuf *scaled;
- scaled = gdk_pixbuf_scale_simple(pixbuf,
- width, height,
- GDK_INTERP_BILINEAR);
- if (!scaled)
- return false;
-
- gdk_draw_pixbuf(current_drawable, current_gc,
- scaled,
- 0, 0,
- x, y,
- width, height,
- GDK_RGB_DITHER_NORMAL, 0, 0);
-
- g_object_unref(scaled);
- }
-
- return true;
-}
-
-
-bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height,
- struct bitmap *bitmap, colour bg,
- bool repeat_x, bool repeat_y)
-{
- return true;
-}
-
-bool nsgtk_plot_group_start(const char *name)
-{
- return true;
-}
-
-bool nsgtk_plot_group_end(void)
-{
- return true;
-}
-
-void nsgtk_set_colour(colour c)
-{
- int r, g, b;
- GdkColor colour;
-
- r = c & 0xff;
- g = (c & 0xff00) >> 8;
- b = (c & 0xff0000) >> 16;
-
- colour.red = r | (r << 8);
- colour.green = g | (g << 8);
- colour.blue = b | (b << 8);
- colour.pixel = (r << 16) | (g << 8) | b;
-
- gdk_color_alloc(gtk_widget_get_colormap(current_widget),
- &colour);
- gdk_gc_set_foreground(current_gc, &colour);
-}
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Target independent plotting (GDK / GTK+ implementation). + */ + +#include <gdk/gdk.h> +#include <gtk/gtk.h> +#include "netsurf/desktop/plotters.h" +#include "netsurf/render/font.h" +#include "netsurf/utils/log.h" + + +extern GtkWidget *current_widget; +extern GdkDrawable *current_drawable; +extern GdkGC *current_gc; + + +static bool nsgtk_plot_clg(colour c); +static bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, + colour c, bool dotted); +static bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed); +static bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill); +static bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c); +static bool nsgtk_plot_clip(int clip_x0, int clip_y0, + int clip_x1, int clip_y1); +static bool nsgtk_plot_text(int x, int y, struct font_data *font, + const char *text, size_t length, colour bg, colour c); +static bool nsgtk_plot_disc(int x, int y, int radius, colour colour); +static bool nsgtk_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg); +static bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y); +static bool nsgtk_plot_group_start(const char *name); +static bool nsgtk_plot_group_end(void); +static void nsgtk_set_colour(colour c); + + + +struct plotter_table plot; + +const struct plotter_table nsgtk_plotters = { + nsgtk_plot_clg, + nsgtk_plot_rectangle, + nsgtk_plot_line, + nsgtk_plot_polygon, + nsgtk_plot_fill, + nsgtk_plot_clip, + nsgtk_plot_text, + nsgtk_plot_disc, + nsgtk_plot_bitmap, + nsgtk_plot_bitmap_tile, + nsgtk_plot_group_start, + nsgtk_plot_group_end +}; + + +bool nsgtk_plot_clg(colour c) +{ + return true; +} + + +bool nsgtk_plot_rectangle(int x0, int y0, int width, int height, + colour c, bool dotted) +{ + nsgtk_set_colour(c); + gdk_draw_rectangle(current_drawable, current_gc, + FALSE, x0, y0, width, height); + return true; +} + + +bool nsgtk_plot_line(int x0, int y0, int x1, int y1, int width, + colour c, bool dotted, bool dashed) +{ + nsgtk_set_colour(c); + gdk_draw_line(current_drawable, current_gc, + x0, y0, x1, y1); + return true; +} + + +bool nsgtk_plot_polygon(int *p, unsigned int n, colour fill) +{ + unsigned int i; + GdkPoint q[n]; + for (i = 0; i != n; i++) { + q[i].x = p[i * 2]; + q[i].y = p[i * 2 + 1]; + } + nsgtk_set_colour(fill); + gdk_draw_polygon(current_drawable, current_gc, + TRUE, q, n); + return true; +} + + +bool nsgtk_plot_fill(int x0, int y0, int x1, int y1, colour c) +{ + nsgtk_set_colour(c); + gdk_draw_rectangle(current_drawable, current_gc, + TRUE, x0, y0, x1 - x0, y1 - y0); + return true; +} + + +bool nsgtk_plot_clip(int clip_x0, int clip_y0, + int clip_x1, int clip_y1) +{ + GdkRectangle clip = { clip_x0, clip_y0, + clip_x1 - clip_x0 + 1, clip_y1 - clip_y0 + 1 }; + gdk_gc_set_clip_rectangle(current_gc, &clip); + return true; +} + + +bool nsgtk_plot_text(int x, int y, struct font_data *font, + const char *text, size_t length, colour bg, colour c) +{ + PangoContext *context; + PangoLayout *layout; + PangoLayoutLine *line; + GdkColor colour = { 0, + ((c & 0xff) << 8) | (c & 0xff), + (c & 0xff00) | (c & 0xff00 >> 8), + ((c & 0xff0000) >> 8) | (c & 0xff0000 >> 16) }; + + context = gtk_widget_get_pango_context(current_widget); + layout = pango_layout_new(context); + pango_layout_set_font_description(layout, + (const PangoFontDescription *) font->id); + pango_layout_set_text(layout, text, length); + + line = pango_layout_get_line(layout, 0); + + gdk_draw_layout_line_with_colors(current_drawable, current_gc, + x, y, line, &colour, 0); + + g_object_unref(layout); + + return true; +} + + +bool nsgtk_plot_disc(int x, int y, int radius, colour colour) +{ + return true; +} + + +bool nsgtk_plot_bitmap(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg) +{ + GdkPixbuf *pixbuf = (GdkPixbuf *) bitmap; + + if (gdk_pixbuf_get_width(pixbuf) == width && + gdk_pixbuf_get_height(pixbuf) == height) { + gdk_draw_pixbuf(current_drawable, current_gc, + pixbuf, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_NORMAL, 0, 0); + + } else { + GdkPixbuf *scaled; + scaled = gdk_pixbuf_scale_simple(pixbuf, + width, height, + GDK_INTERP_BILINEAR); + if (!scaled) + return false; + + gdk_draw_pixbuf(current_drawable, current_gc, + scaled, + 0, 0, + x, y, + width, height, + GDK_RGB_DITHER_NORMAL, 0, 0); + + g_object_unref(scaled); + } + + return true; +} + + +bool nsgtk_plot_bitmap_tile(int x, int y, int width, int height, + struct bitmap *bitmap, colour bg, + bool repeat_x, bool repeat_y) +{ + return true; +} + +bool nsgtk_plot_group_start(const char *name) +{ + return true; +} + +bool nsgtk_plot_group_end(void) +{ + return true; +} + +void nsgtk_set_colour(colour c) +{ + int r, g, b; + GdkColor colour; + + r = c & 0xff; + g = (c & 0xff00) >> 8; + b = (c & 0xff0000) >> 16; + + colour.red = r | (r << 8); + colour.green = g | (g << 8); + colour.blue = b | (b << 8); + colour.pixel = (r << 16) | (g << 8) | b; + + gdk_color_alloc(gtk_widget_get_colormap(current_widget), + &colour); + gdk_gc_set_foreground(current_gc, &colour); +} diff --git a/image/bitmap.h b/image/bitmap.h index 484e64599..9d442c214 100644 --- a/image/bitmap.h +++ b/image/bitmap.h @@ -1,37 +1,37 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Generic bitmap handling (interface).
- *
- * This interface wraps the native platform-specific image format, so that
- * portable image convertors can be written.
- *
- * The bitmap format is either RGBA.
- */
-
-#ifndef _NETSURF_IMAGE_BITMAP_H_
-#define _NETSURF_IMAGE_BITMAP_H_
-
-#include <stdbool.h>
-#include <stdlib.h>
-
-struct content;
-
-/** An opaque image. */
-struct bitmap;
-
-struct bitmap *bitmap_create(int width, int height);
-void bitmap_set_opaque(struct bitmap *bitmap, bool opaque);
-bool bitmap_test_opaque(struct bitmap *bitmap);
-bool bitmap_get_opaque(struct bitmap *bitmap);
-char *bitmap_get_buffer(struct bitmap *bitmap);
-size_t bitmap_get_rowstride(struct bitmap *bitmap);
-void bitmap_destroy(struct bitmap *bitmap);
-bool bitmap_save(struct bitmap *bitmap, const char *path);
-
-#endif
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Generic bitmap handling (interface). + * + * This interface wraps the native platform-specific image format, so that + * portable image convertors can be written. + * + * The bitmap format is either RGBA. + */ + +#ifndef _NETSURF_IMAGE_BITMAP_H_ +#define _NETSURF_IMAGE_BITMAP_H_ + +#include <stdbool.h> +#include <stdlib.h> + +struct content; + +/** An opaque image. */ +struct bitmap; + +struct bitmap *bitmap_create(int width, int height); +void bitmap_set_opaque(struct bitmap *bitmap, bool opaque); +bool bitmap_test_opaque(struct bitmap *bitmap); +bool bitmap_get_opaque(struct bitmap *bitmap); +char *bitmap_get_buffer(struct bitmap *bitmap); +size_t bitmap_get_rowstride(struct bitmap *bitmap); +void bitmap_destroy(struct bitmap *bitmap); +bool bitmap_save(struct bitmap *bitmap, const char *path); + +#endif diff --git a/riscos/bitmap.c b/riscos/bitmap.c index 397668e6d..f30f43957 100644 --- a/riscos/bitmap.c +++ b/riscos/bitmap.c @@ -1,190 +1,190 @@ -/*
- * This file is part of NetSurf, http://netsurf.sourceforge.net/
- * Licensed under the GNU General Public License,
- * http://www.opensource.org/licenses/gpl-license
- * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
- */
-
-/** \file
- * Generic bitmap handling (RISC OS implementation).
- *
- * This implements the interface given by desktop/bitmap.h using RISC OS
- * sprites.
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <string.h>
-#include "oslib/osspriteop.h"
-#include "netsurf/content/content.h"
-#include "netsurf/image/bitmap.h"
-#include "netsurf/riscos/bitmap.h"
-#include "netsurf/riscos/image.h"
-#include "netsurf/utils/log.h"
-#include "netsurf/utils/utils.h"
-
-
-/**
- * Create a bitmap.
- *
- * \param width width of image in pixels
- * \param height width of image in pixels
- * \return an opaque struct bitmap, or NULL on memory exhaustion
- */
-
-struct bitmap *bitmap_create(int width, int height)
-{
- unsigned int area_size;
- struct bitmap *bitmap;
- osspriteop_area *sprite_area;
- osspriteop_header *sprite;
-
- if (width == 0 || height == 0)
- return NULL;
-
- area_size = 16 + 44 + width * height * 4;
- bitmap = calloc(sizeof(struct bitmap) + area_size, 1);
- if (!bitmap)
- return NULL;
-
- bitmap->width = width;
- bitmap->height = height;
- bitmap->opaque = false;
-
- /* area control block */
- sprite_area = &bitmap->sprite_area;
- sprite_area->size = area_size;
- sprite_area->sprite_count = 1;
- sprite_area->first = 16;
- sprite_area->used = area_size;
-
- /* sprite control block */
- sprite = (osspriteop_header *) (sprite_area + 1);
- sprite->size = area_size - 16;
-/* memset(sprite->name, 0x00, 12); */
- strncpy(sprite->name, "bitmap", 12);
- sprite->width = width - 1;
- sprite->height = height - 1;
- sprite->left_bit = 0;
- sprite->right_bit = 31;
- sprite->image = sprite->mask = 44;
- sprite->mode = (os_mode) 0x301680b5;
-
- return bitmap;
-}
-
-
-/**
- * Sets whether a bitmap should be plotted opaque
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param opaque whether the bitmap should be plotted opaque
- */
-void bitmap_set_opaque(struct bitmap *bitmap, bool opaque)
-{
- assert(bitmap);
- bitmap->opaque = opaque;
-}
-
-
-/**
- * Tests whether a bitmap has an opaque alpha channel
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return whether the bitmap is opaque
- */
-bool bitmap_test_opaque(struct bitmap *bitmap)
-{
- assert(bitmap);
- char *sprite = bitmap_get_buffer(bitmap);
- unsigned int width = bitmap_get_rowstride(bitmap);
- osspriteop_header *sprite_header =
- (osspriteop_header *) (&(bitmap->sprite_area) + 1);
- unsigned int height = (sprite_header->height + 1);
- unsigned int size = width * height;
- for (unsigned int i = 3; i < size; i += 4)
- if (sprite[i] != 0xff)
- return false;
- return true;
-}
-
-
-/**
- * Gets whether a bitmap should be plotted opaque
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-bool bitmap_get_opaque(struct bitmap *bitmap)
-{
- assert(bitmap);
- return (bitmap->opaque);
-}
-
-
-/**
- * Return a pointer to the pixel data in a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return pointer to the pixel buffer
- *
- * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end
- * of rows. The width of a row in bytes is given by bitmap_get_rowstride().
- */
-
-char *bitmap_get_buffer(struct bitmap *bitmap)
-{
- assert(bitmap);
- return ((char *) (&(bitmap->sprite_area))) + 16 + 44;
-}
-
-
-/**
- * Find the width of a pixel row in bytes.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \return width of a pixel row in the bitmap
- */
-
-size_t bitmap_get_rowstride(struct bitmap *bitmap)
-{
- osspriteop_header *sprite;
- assert(bitmap);
- sprite = (osspriteop_header *) (&(bitmap->sprite_area) + 1);
- return (sprite->width + 1) * 4;
-}
-
-
-/**
- * Free a bitmap.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- */
-
-void bitmap_destroy(struct bitmap *bitmap)
-{
- assert(bitmap);
- free(bitmap);
-}
-
-
-/**
- * Save a bitmap in the platform's native format.
- *
- * \param bitmap a bitmap, as returned by bitmap_create()
- * \param path pathname for file
- * \return true on success, false on error and error reported
- */
-
-bool bitmap_save(struct bitmap *bitmap, const char *path)
-{
- os_error *error;
- error = xosspriteop_save_sprite_file(osspriteop_USER_AREA,
- &(bitmap->sprite_area), path);
- if (error) {
- LOG(("xosspriteop_save_sprite_file: 0x%x: %s",
- error->errnum, error->errmess));
- warn_user("SaveError", error->errmess);
- return false;
- }
- return true;
-}
+/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 James Bursa <bursa@users.sourceforge.net> + */ + +/** \file + * Generic bitmap handling (RISC OS implementation). + * + * This implements the interface given by desktop/bitmap.h using RISC OS + * sprites. + */ + +#include <assert.h> +#include <stdbool.h> +#include <string.h> +#include "oslib/osspriteop.h" +#include "netsurf/content/content.h" +#include "netsurf/image/bitmap.h" +#include "netsurf/riscos/bitmap.h" +#include "netsurf/riscos/image.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/utils.h" + + +/** + * Create a bitmap. + * + * \param width width of image in pixels + * \param height width of image in pixels + * \return an opaque struct bitmap, or NULL on memory exhaustion + */ + +struct bitmap *bitmap_create(int width, int height) +{ + unsigned int area_size; + struct bitmap *bitmap; + osspriteop_area *sprite_area; + osspriteop_header *sprite; + + if (width == 0 || height == 0) + return NULL; + + area_size = 16 + 44 + width * height * 4; + bitmap = calloc(sizeof(struct bitmap) + area_size, 1); + if (!bitmap) + return NULL; + + bitmap->width = width; + bitmap->height = height; + bitmap->opaque = false; + + /* area control block */ + sprite_area = &bitmap->sprite_area; + sprite_area->size = area_size; + sprite_area->sprite_count = 1; + sprite_area->first = 16; + sprite_area->used = area_size; + + /* sprite control block */ + sprite = (osspriteop_header *) (sprite_area + 1); + sprite->size = area_size - 16; +/* memset(sprite->name, 0x00, 12); */ + strncpy(sprite->name, "bitmap", 12); + sprite->width = width - 1; + sprite->height = height - 1; + sprite->left_bit = 0; + sprite->right_bit = 31; + sprite->image = sprite->mask = 44; + sprite->mode = (os_mode) 0x301680b5; + + return bitmap; +} + + +/** + * Sets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param opaque whether the bitmap should be plotted opaque + */ +void bitmap_set_opaque(struct bitmap *bitmap, bool opaque) +{ + assert(bitmap); + bitmap->opaque = opaque; +} + + +/** + * Tests whether a bitmap has an opaque alpha channel + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return whether the bitmap is opaque + */ +bool bitmap_test_opaque(struct bitmap *bitmap) +{ + assert(bitmap); + char *sprite = bitmap_get_buffer(bitmap); + unsigned int width = bitmap_get_rowstride(bitmap); + osspriteop_header *sprite_header = + (osspriteop_header *) (&(bitmap->sprite_area) + 1); + unsigned int height = (sprite_header->height + 1); + unsigned int size = width * height; + for (unsigned int i = 3; i < size; i += 4) + if (sprite[i] != 0xff) + return false; + return true; +} + + +/** + * Gets whether a bitmap should be plotted opaque + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ +bool bitmap_get_opaque(struct bitmap *bitmap) +{ + assert(bitmap); + return (bitmap->opaque); +} + + +/** + * Return a pointer to the pixel data in a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return pointer to the pixel buffer + * + * The pixel data is packed as BITMAP_FORMAT, possibly with padding at the end + * of rows. The width of a row in bytes is given by bitmap_get_rowstride(). + */ + +char *bitmap_get_buffer(struct bitmap *bitmap) +{ + assert(bitmap); + return ((char *) (&(bitmap->sprite_area))) + 16 + 44; +} + + +/** + * Find the width of a pixel row in bytes. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \return width of a pixel row in the bitmap + */ + +size_t bitmap_get_rowstride(struct bitmap *bitmap) +{ + osspriteop_header *sprite; + assert(bitmap); + sprite = (osspriteop_header *) (&(bitmap->sprite_area) + 1); + return (sprite->width + 1) * 4; +} + + +/** + * Free a bitmap. + * + * \param bitmap a bitmap, as returned by bitmap_create() + */ + +void bitmap_destroy(struct bitmap *bitmap) +{ + assert(bitmap); + free(bitmap); +} + + +/** + * Save a bitmap in the platform's native format. + * + * \param bitmap a bitmap, as returned by bitmap_create() + * \param path pathname for file + * \return true on success, false on error and error reported + */ + +bool bitmap_save(struct bitmap *bitmap, const char *path) +{ + os_error *error; + error = xosspriteop_save_sprite_file(osspriteop_USER_AREA, + &(bitmap->sprite_area), path); + if (error) { + LOG(("xosspriteop_save_sprite_file: 0x%x: %s", + error->errnum, error->errmess)); + warn_user("SaveError", error->errmess); + return false; + } + return true; +} |