Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 3620 → Rev 3621

/programs/network/netsurf/include/cursor.h
0,0 → 1,41
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the *internal* interface for the cursor.
*/
 
#ifndef CURSOR_H
#define CURSOR_H 1
 
struct nsfb_cursor_s {
bool plotted;
nsfb_bbox_t loc;
 
/* current cursor image */
const nsfb_colour_t *pixel;
int bmp_width;
int bmp_height;
int bmp_stride;
int hotspot_x;
int hotspot_y;
 
/* current saved image */
nsfb_bbox_t savloc;
nsfb_colour_t *sav;
int sav_size;
int sav_width;
int sav_height;
 
};
 
/** Plot the cursor saving the image underneath. */
bool nsfb_cursor_plot(nsfb_t *nsfb, struct nsfb_cursor_s *cursor);
 
/** Clear the cursor restoring the image underneath */
bool nsfb_cursor_clear(nsfb_t *nsfb, struct nsfb_cursor_s *cursor);
 
#endif /* CURSOR_H */
/programs/network/netsurf/include/libnsbmp.h
0,0 → 1,112
/*
* Copyright 2006 Richard Wilson <richard.wilson@netsurf-browser.org>
* Copyright 2008 Sean Fox <dyntryx@gmail.com>
*
* This file is part of NetSurf's libnsbmp, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
 
/** \file
* BMP file decoding (interface).
*/
 
#ifndef libnsbmp_h_
#define libnsbmp_h_
 
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
 
/* bmp flags */
#define BMP_NEW 0
#define BMP_OPAQUE (1 << 0) /** image is opaque (as opposed to having an alpha mask) */
#define BMP_CLEAR_MEMORY (1 << 1) /** memory should be wiped */
 
/* error return values */
typedef enum {
BMP_OK = 0,
BMP_INSUFFICIENT_MEMORY = 1,
BMP_INSUFFICIENT_DATA = 2,
BMP_DATA_ERROR = 3
} bmp_result;
 
/* encoding types */
typedef enum {
BMP_ENCODING_RGB = 0,
BMP_ENCODING_RLE8 = 1,
BMP_ENCODING_RLE4 = 2,
BMP_ENCODING_BITFIELDS = 3
} bmp_encoding;
 
/* API for Bitmap callbacks
*/
typedef void* (*bmp_bitmap_cb_create)(int width, int height, unsigned int state);
typedef void (*bmp_bitmap_cb_destroy)(void *bitmap);
typedef unsigned char* (*bmp_bitmap_cb_get_buffer)(void *bitmap);
typedef size_t (*bmp_bitmap_cb_get_bpp)(void *bitmap);
 
/* The Bitmap callbacks function table
*/
typedef struct bmp_bitmap_callback_vt_s {
bmp_bitmap_cb_create bitmap_create; /**< Create a bitmap. */
bmp_bitmap_cb_destroy bitmap_destroy; /**< Free a bitmap. */
bmp_bitmap_cb_get_buffer bitmap_get_buffer; /**< Return a pointer to the pixel data in a bitmap. */
bmp_bitmap_cb_get_bpp bitmap_get_bpp; /**< Find the width of a pixel row in bytes. */
} bmp_bitmap_callback_vt;
 
typedef struct bmp_image {
bmp_bitmap_callback_vt bitmap_callbacks; /**< callbacks for bitmap functions */
uint8_t *bmp_data; /** pointer to BMP data */
uint32_t width; /** width of BMP (valid after _analyse) */
uint32_t height; /** heigth of BMP (valid after _analyse) */
bool decoded; /** whether the image has been decoded */
void *bitmap; /** decoded image */
/** Internal members are listed below
*/
uint32_t buffer_size; /** total number of bytes of BMP data available */
bmp_encoding encoding; /** pixel encoding type */
uint32_t bitmap_offset; /** offset of bitmap data */
uint16_t bpp; /** bits per pixel */
uint32_t colours; /** number of colours */
uint32_t *colour_table; /** colour table */
bool limited_trans; /** whether to use bmp's limited transparency */
uint32_t trans_colour; /** colour to display for "transparent" pixels when
* using limited transparency */
bool reversed; /** scanlines are top to bottom */
bool ico; /** image is part of an ICO, mask follows */
bool opaque; /** true if the bitmap does not contain an alpha channel */
uint32_t mask[4]; /** four bitwise mask */
int32_t shift[4]; /** four bitwise shifts */
uint32_t transparent_index; /** colour representing "transparency" in the bitmap */
} bmp_image;
 
typedef struct ico_image {
bmp_image bmp;
struct ico_image *next;
} ico_image;
 
typedef struct ico_collection {
bmp_bitmap_callback_vt bitmap_callbacks; /**< callbacks for bitmap functions */
uint16_t width; /** width of largest BMP */
uint16_t height; /** heigth of largest BMP */
/** Internal members are listed below
*/
uint8_t *ico_data; /** pointer to ICO data */
uint32_t buffer_size; /** total number of bytes of ICO data available */
ico_image *first;
} ico_collection;
 
void bmp_create(bmp_image *bmp, bmp_bitmap_callback_vt *bitmap_callbacks);
void ico_collection_create(ico_collection *ico,
bmp_bitmap_callback_vt *bitmap_callbacks);
bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data);
bmp_result bmp_decode(bmp_image *bmp);
bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t transparent_colour);
void bmp_finalise(bmp_image *bmp);
 
bmp_result ico_analyse(ico_collection *ico, size_t size, uint8_t *data);
bmp_image *ico_find(ico_collection *ico, uint16_t width, uint16_t height);
void ico_finalise(ico_collection *ico);
 
#endif
/programs/network/netsurf/include/libnsfb.h
0,0 → 1,161
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the exported interface for the libnsfb graphics library.
*/
 
#ifndef _LIBNSFB_H
#define _LIBNSFB_H 1
 
#include <stdint.h>
 
typedef struct nsfb_palette_s nsfb_palette_t;
typedef struct nsfb_cursor_s nsfb_cursor_t;
typedef struct nsfb_s nsfb_t;
typedef struct nsfb_event_s nsfb_event_t;
 
/** co-ordinate for plotting operations */
typedef struct nsfb_point_s {
int x;
int y;
} nsfb_point_t;
 
/** bounding box for plotting operations */
typedef struct nsfb_bbox_s {
int x0;
int y0;
int x1;
int y1;
} nsfb_bbox_t;
 
/** The type of framebuffer surface. */
enum nsfb_type_e {
NSFB_SURFACE_NONE = 0, /**< No surface */
NSFB_SURFACE_RAM, /**< RAM surface */
NSFB_SURFACE_SDL, /**< SDL surface */
NSFB_SURFACE_LINUX, /**< Linux framebuffer surface */
NSFB_SURFACE_VNC, /**< VNC surface */
NSFB_SURFACE_ABLE, /**< ABLE framebuffer surface */
NSFB_SURFACE_X, /**< X windows surface */
NSFB_SURFACE_KOLIBRI
};
 
enum nsfb_format_e {
NSFB_FMT_ANY = 0, /* No specific format - use surface default */
NSFB_FMT_XBGR8888, /* 32bpp Blue Green Red */
NSFB_FMT_XRGB8888, /* 32bpp Red Green Blue */
NSFB_FMT_ABGR8888, /* 32bpp Alpga Blue Green Red */
NSFB_FMT_ARGB8888, /* 32bpp Alpga Red Green Blue */
NSFB_FMT_RGB888, /* 24 bpp Alpga Red Green Blue */
NSFB_FMT_ARGB1555, /* 16 bpp 555 */
NSFB_FMT_RGB565, /* 16 bpp 565 */
NSFB_FMT_I8, /* 8bpp indexed */
NSFB_FMT_I4, /* 4bpp indexed */
NSFB_FMT_I1, /* black and white */
};
 
/** Select frontend type from a name.
*
* @param name The name to select a frontend.
* @return The surface type or NSFB_SURFACE_NONE if frontend with specified
* name was not available
*/
enum nsfb_type_e nsfb_type_from_name(const char *name);
 
/** Create a nsfb context.
*
* This creates a framebuffer surface context.
*
* @param surface_type The type of surface to create a context for.
*/
nsfb_t *nsfb_new(const enum nsfb_type_e surface_type);
 
/** Initialise selected surface context.
*
* @param nsfb The context returned from ::nsfb_init
*/
int nsfb_init(nsfb_t *nsfb);
 
/** Free nsfb context.
*
* This shuts down and releases all resources associated with an nsfb context.
*
* @param nsfb The context returned from ::nsfb_new to free
*/
int nsfb_free(nsfb_t *nsfb);
 
/** Claim an area of screen to be redrawn.
*
* Informs the nsfb library that an area of screen will be directly
* updated by the user program. This is neccisarry so the library can
* ensure the soft cursor plotting is correctly handled. After the
* update has been perfomed ::nsfb_update should be called.
*
* @param box The bounding box of the area which might be altered.
*/
int nsfb_claim(nsfb_t *nsfb, nsfb_bbox_t *box);
 
/** Update an area of screen which has been redrawn.
*
* Informs the nsfb library that an area of screen has been directly
* updated by the user program. Some surfaces only show the update on
* notification. The area updated does not neccisarrily have to
* corelate with a previous ::nsfb_claim bounding box, however if the
* redrawn area is larger than the claimed area pointer plotting
* artifacts may occour.
*
* @param box The bounding box of the area which has been altered.
*/
int nsfb_update(nsfb_t *nsfb, nsfb_bbox_t *box);
 
/** Obtain the geometry of a nsfb context.
*
* @param width a variable to store the framebuffer width in or NULL
* @param height a variable to store the framebuffer height in or NULL
* @param format a variable to store the framebuffer format in or NULL
*/
int nsfb_get_geometry(nsfb_t *nsfb, int *width, int *height, enum nsfb_format_e *format);
 
/** Alter the geometry of a surface
*
* @param nsfb The context to alter.
* @param width The new display width.
* @param height The new display height.
* @param format The desired surface format.
*/
int nsfb_set_geometry(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format);
 
/** Set parameters a surface
*
* Some surface types can take additional parameters for
* attributes. For example the linux surface uses this to allow the
* setting of a different output device
*
* @param nsfb The surface to alter.
* @param parameters The parameters for the surface.
*/
int nsfb_set_parameters(nsfb_t *nsfb, const char *parameters);
 
/** Obtain the buffer memory base and stride.
*
* @param nsfb The context to read.
*/
int nsfb_get_buffer(nsfb_t *nsfb, uint8_t **ptr, int *linelen);
 
/** Dump the surface to fd in PPM format
*/
bool nsfb_dump(nsfb_t *nsfb, int fd);
 
 
#endif
 
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* End:
*/
/programs/network/netsurf/include/libnsfb_cursor.h
0,0 → 1,48
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the exported interface for the libnsfb graphics library.
*/
 
#ifndef _LIBNSFB_CURSOR_H
#define _LIBNSFB_CURSOR_H 1
 
/** Initialise the cursor.
*/
bool nsfb_cursor_init(nsfb_t *nsfb);
 
/** Set cursor parameters.
*
* Set a cursor bitmap, the cursor will be shown at the location set by
* nsfb_cursor_loc_set. The pixel data may be referenced untill the cursor
* is altered or cleared
*
* @param nsfb The frambuffer context
* @param pixel The cursor bitmap data
* @param bmp_width The width of the cursor bitmap
* @param bmp_height The height of the cursor bitmap
* @param bmp_stride The cursor bitmap's row stride
* @param hotspot_x Coordinate within cursor image to place over cursor loc
* @param hotspot_y Coordinate within cursor image to place over cursor loc
*
* (hot_spot_x, hot_spot_y) is from top left. (0, 0) means top left pixel of
* cursor bitmap is to be rendered over the cursor location.
*/
bool nsfb_cursor_set(nsfb_t *nsfb, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, int hotspot_x, int hotspot_y);
 
/** Set cursor location.
*
* @param nsfb The frambuffer context.
* @param loc The location of the cursor
*/
bool nsfb_cursor_loc_set(nsfb_t *nsfb, const nsfb_bbox_t *loc);
 
/** get the cursor location */
bool nsfb_cursor_loc_get(nsfb_t *nsfb, nsfb_bbox_t *loc);
 
 
#endif
/programs/network/netsurf/include/libnsfb_event.h
0,0 → 1,219
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the exported interface for the libnsfb graphics library.
*/
 
#ifndef _LIBNSFB_EVENT_H
#define _LIBNSFB_EVENT_H 1
 
enum nsfb_event_type_e {
NSFB_EVENT_NONE,
NSFB_EVENT_CONTROL,
NSFB_EVENT_KEY_DOWN,
NSFB_EVENT_KEY_UP,
NSFB_EVENT_MOVE_RELATIVE,
NSFB_EVENT_MOVE_ABSOLUTE,
};
 
 
/** keycodes which mostly map to ascii chars */
enum nsfb_key_code_e {
NSFB_KEY_UNKNOWN = 0,
NSFB_KEY_BACKSPACE = 8,
NSFB_KEY_TAB = 9,
NSFB_KEY_LF = 10,
NSFB_KEY_CLEAR = 12,
NSFB_KEY_RETURN = 13,
NSFB_KEY_PAUSE = 19,
NSFB_KEY_ESCAPE = 27,
NSFB_KEY_SPACE = 32,
NSFB_KEY_EXCLAIM = 33,
NSFB_KEY_QUOTEDBL = 34,
NSFB_KEY_HASH = 35,
NSFB_KEY_DOLLAR = 36,
NSFB_KEY_AMPERSAND = 38,
NSFB_KEY_QUOTE = 39,
NSFB_KEY_LEFTPAREN = 40,
NSFB_KEY_RIGHTPAREN = 41,
NSFB_KEY_ASTERISK = 42,
NSFB_KEY_PLUS = 43,
NSFB_KEY_COMMA = 44,
NSFB_KEY_MINUS = 45,
NSFB_KEY_PERIOD = 46,
NSFB_KEY_SLASH = 47,
NSFB_KEY_0 = 48,
NSFB_KEY_1 = 49,
NSFB_KEY_2 = 50,
NSFB_KEY_3 = 51,
NSFB_KEY_4 = 52,
NSFB_KEY_5 = 53,
NSFB_KEY_6 = 54,
NSFB_KEY_7 = 55,
NSFB_KEY_8 = 56,
NSFB_KEY_9 = 57,
NSFB_KEY_COLON = 58,
NSFB_KEY_SEMICOLON = 59,
NSFB_KEY_LESS = 60,
NSFB_KEY_EQUALS = 61,
NSFB_KEY_GREATER = 62,
NSFB_KEY_QUESTION = 63,
NSFB_KEY_AT = 64,
NSFB_KEY_LEFTBRACKET = 91,
NSFB_KEY_BACKSLASH = 92,
NSFB_KEY_RIGHTBRACKET = 93,
NSFB_KEY_CARET = 94,
NSFB_KEY_UNDERSCORE = 95,
NSFB_KEY_BACKQUOTE = 96,
NSFB_KEY_a = 97,
NSFB_KEY_b = 98,
NSFB_KEY_c = 99,
NSFB_KEY_d = 100,
NSFB_KEY_e = 101,
NSFB_KEY_f = 102,
NSFB_KEY_g = 103,
NSFB_KEY_h = 104,
NSFB_KEY_i = 105,
NSFB_KEY_j = 106,
NSFB_KEY_k = 107,
NSFB_KEY_l = 108,
NSFB_KEY_m = 109,
NSFB_KEY_n = 110,
NSFB_KEY_o = 111,
NSFB_KEY_p = 112,
NSFB_KEY_q = 113,
NSFB_KEY_r = 114,
NSFB_KEY_s = 115,
NSFB_KEY_t = 116,
NSFB_KEY_u = 117,
NSFB_KEY_v = 118,
NSFB_KEY_w = 119,
NSFB_KEY_x = 120,
NSFB_KEY_y = 121,
NSFB_KEY_z = 122,
NSFB_KEY_DELETE = 127,
 
NSFB_KEY_KP0 = 256,
NSFB_KEY_KP1 = 257,
NSFB_KEY_KP2 = 258,
NSFB_KEY_KP3 = 259,
NSFB_KEY_KP4 = 260,
NSFB_KEY_KP5 = 261,
NSFB_KEY_KP6 = 262,
NSFB_KEY_KP7 = 263,
NSFB_KEY_KP8 = 264,
NSFB_KEY_KP9 = 265,
NSFB_KEY_KP_PERIOD = 266,
NSFB_KEY_KP_DIVIDE = 267,
NSFB_KEY_KP_MULTIPLY = 268,
NSFB_KEY_KP_MINUS = 269,
NSFB_KEY_KP_PLUS = 270,
NSFB_KEY_KP_ENTER = 271,
NSFB_KEY_KP_EQUALS = 272,
 
NSFB_KEY_UP = 273,
NSFB_KEY_DOWN = 274,
NSFB_KEY_RIGHT = 275,
NSFB_KEY_LEFT = 276,
NSFB_KEY_INSERT = 277,
NSFB_KEY_HOME = 278,
NSFB_KEY_END = 279,
NSFB_KEY_PAGEUP = 280,
NSFB_KEY_PAGEDOWN = 281,
 
/* Function keys */
NSFB_KEY_F1 = 282,
NSFB_KEY_F2 = 283,
NSFB_KEY_F3 = 284,
NSFB_KEY_F4 = 285,
NSFB_KEY_F5 = 286,
NSFB_KEY_F6 = 287,
NSFB_KEY_F7 = 288,
NSFB_KEY_F8 = 289,
NSFB_KEY_F9 = 290,
NSFB_KEY_F10 = 291,
NSFB_KEY_F11 = 292,
NSFB_KEY_F12 = 293,
NSFB_KEY_F13 = 294,
NSFB_KEY_F14 = 295,
NSFB_KEY_F15 = 296,
 
/* Key state modifier keys */
NSFB_KEY_NUMLOCK = 300,
NSFB_KEY_CAPSLOCK = 301,
NSFB_KEY_SCROLLOCK = 302,
NSFB_KEY_RSHIFT = 303,
NSFB_KEY_LSHIFT = 304,
NSFB_KEY_RCTRL = 305,
NSFB_KEY_LCTRL = 306,
NSFB_KEY_RALT = 307,
NSFB_KEY_LALT = 308,
NSFB_KEY_RMETA = 309,
NSFB_KEY_LMETA = 310,
NSFB_KEY_LSUPER = 311,
NSFB_KEY_RSUPER = 312,
NSFB_KEY_MODE = 313,
NSFB_KEY_COMPOSE = 314,
 
/* Miscellaneous function keys */
NSFB_KEY_HELP = 315,
NSFB_KEY_PRINT = 316,
NSFB_KEY_SYSREQ = 317,
NSFB_KEY_BREAK = 318,
NSFB_KEY_MENU = 319,
NSFB_KEY_POWER = 320,
NSFB_KEY_EURO = 321,
NSFB_KEY_UNDO = 322,
 
/* mouse buttons */
NSFB_KEY_MOUSE_1 = 401,
NSFB_KEY_MOUSE_2 = 402,
NSFB_KEY_MOUSE_3 = 403,
NSFB_KEY_MOUSE_4 = 404,
NSFB_KEY_MOUSE_5 = 405,
 
};
 
enum nsfb_control_e {
NSFB_CONTROL_NONE,
NSFB_CONTROL_TIMEOUT, /* timeout event */
NSFB_CONTROL_QUIT, /* surface handler quit event */
};
 
struct nsfb_event_s {
enum nsfb_event_type_e type;
union {
enum nsfb_key_code_e keycode;
enum nsfb_control_e controlcode;
struct {
int x;
int y;
int z;
} vector;
} value;
};
 
/** Process input events.
*
* Gather events from a frontend.
*
* @param nsfb The library handle.
* @param event The event structure to fill.
* @param timeout The number of milliseconds to wait for input, -1 is wait
* forever, 0 returns immediately.
* @return If the /a event structure is updated true else false.
*/
bool nsfb_event(nsfb_t *nsfb, nsfb_event_t *event, int timeout);
 
#endif
 
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* End:
*/
/programs/network/netsurf/include/libnsfb_plot.h
0,0 → 1,169
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the exported plotter interface for the libnsfb graphics library.
*/
 
#ifndef _LIBNSFB_PLOT_H
#define _LIBNSFB_PLOT_H 1
 
/** representation of a colour.
*
* The colour value comprises of four components arranged in the order ABGR:
* bits 24-31 are the alpha value and represent the opacity. 0 is
* transparent i.e. there would be no change in the target surface if
* this colour were to be used and 0xFF is opaque.
*
* bits 16-23 are the Blue component of the colour.
*
* bits 8-15 are the Green component of the colour.
*
* bits 0-7 are the Red component of the colour.
*/
typedef uint32_t nsfb_colour_t;
 
/**
* Type of plot operation
*/
typedef enum nsfb_plot_optype_e {
NFSB_PLOT_OPTYPE_NONE = 0, /**< No operation */
NFSB_PLOT_OPTYPE_SOLID, /**< Solid colour */
NFSB_PLOT_OPTYPE_PATTERN, /**< Pattern plot */
} nsfb_plot_optype_t;
 
/** pen colour and raster operation for plotting primatives. */
typedef struct nsfb_plot_pen_s {
nsfb_plot_optype_t stroke_type; /**< Stroke plot type */
int stroke_width; /**< Width of stroke, in pixels */
nsfb_colour_t stroke_colour; /**< Colour of stroke */
uint32_t stroke_pattern;
nsfb_plot_optype_t fill_type; /**< Fill plot type */
nsfb_colour_t fill_colour; /**< Colour of fill */
} nsfb_plot_pen_t;
 
/** path operation type. */
typedef enum nsfb_plot_pathop_type_e {
NFSB_PLOT_PATHOP_MOVE,
NFSB_PLOT_PATHOP_LINE,
NFSB_PLOT_PATHOP_QUAD,
NFSB_PLOT_PATHOP_CUBIC,
} nsfb_plot_pathop_type_t;
 
/** path element */
typedef struct nsfb_plot_pathop_s {
nsfb_plot_pathop_type_t operation;
nsfb_point_t point;
} nsfb_plot_pathop_t;
 
/** Sets a clip rectangle for subsequent plots.
*
* Sets a clipping area which constrains all subsequent plotting operations.
* The clipping area must lie within the framebuffer visible screen or false
* will be returned and the new clipping area not set.
*/
bool nsfb_plot_set_clip(nsfb_t *nsfb, nsfb_bbox_t *clip);
 
/** Get the previously set clipping region.
*/
bool nsfb_plot_get_clip(nsfb_t *nsfb, nsfb_bbox_t *clip);
 
/** Clears plotting area to a flat colour.
*/
bool nsfb_plot_clg(nsfb_t *nsfb, nsfb_colour_t c);
 
/** Plots a rectangle outline.
*
* The line can be solid, dotted or dashed. Top left corner at (x0,y0) and
* rectangle has given width and height.
*/
bool nsfb_plot_rectangle(nsfb_t *nsfb, nsfb_bbox_t *rect, int line_width, nsfb_colour_t c, bool dotted, bool dashed);
 
/** Plots a filled rectangle. Top left corner at (x0,y0), bottom
* right corner at (x1,y1). Note: (x0,y0) is inside filled area,
* but (x1,y1) is below and to the right. See diagram below.
*/
bool nsfb_plot_rectangle_fill(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c);
 
/** Plots a line.
*
* Draw a line from (x0,y0) to (x1,y1). Coordinates are at centre of line
* width/thickness.
*/
bool nsfb_plot_line(nsfb_t *nsfb, nsfb_bbox_t *line, nsfb_plot_pen_t *pen);
 
/** Plots a number of lines.
*
* Draw a series of lines.
*/
bool nsfb_plot_lines(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen);
 
/** Plots a number of connected lines.
*
* Draw a series of connected lines.
*/
bool nsfb_plot_polylines(nsfb_t *nsfb, int pointc, const nsfb_point_t *points, nsfb_plot_pen_t *pen);
 
/** Plots a filled polygon.
*
* Plots a filled polygon with straight lines between points. The lines around
* the edge of the ploygon are not plotted. The polygon is filled with a
* non-zero winding rule.
*
*
*/
bool nsfb_plot_polygon(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t fill);
 
/** Plot an ellipse.
*/
bool nsfb_plot_ellipse(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
 
/** Plot a filled ellipse.
*/
bool nsfb_plot_ellipse_fill(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
 
/** Plots an arc.
*
* around (x,y), from anticlockwise from angle1 to angle2. Angles are measured
* anticlockwise from horizontal, in degrees.
*/
bool nsfb_plot_arc(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c);
 
/** Plots an alpha blended pixel.
*
* plots an alpha blended pixel.
*/
bool nsfb_plot_point(nsfb_t *nsfb, int x, int y, nsfb_colour_t c);
 
bool nsfb_plot_cubic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_plot_pen_t *pen);
 
bool nsfb_plot_quadratic_bezier(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_plot_pen_t *pen);
 
bool nsfb_plot_path(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen);
 
/** copy an area of screen
*
* Copy an area of the display.
*/
bool nsfb_plot_copy(nsfb_t *srcfb, nsfb_bbox_t *srcbox, nsfb_t *dstfb, nsfb_bbox_t *dstbox);
 
/** Plot bitmap.
*/
bool nsfb_plot_bitmap(nsfb_t *nsfb, const nsfb_bbox_t *loc, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha);
 
/** Plot an 8 bit glyph.
*/
bool nsfb_plot_glyph8(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c);
 
 
/** Plot an 1 bit glyph.
*/
bool nsfb_plot_glyph1(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c);
 
/* read rectangle into buffer */
bool nsfb_plot_readrect(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer);
 
#endif /* _LIBNSFB_PLOT_H */
/programs/network/netsurf/include/libnsfb_plot_util.h
0,0 → 1,48
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the exported interface for the libnsfb graphics library.
*/
 
#ifndef _LIBNSFB_PLOT_UTIL_H
#define _LIBNSFB_PLOT_UTIL_H 1
 
 
/* alpha blend two pixels together */
static inline nsfb_colour_t
nsfb_plot_ablend(nsfb_colour_t pixel, nsfb_colour_t scrpixel)
{
int opacity = pixel >> 24;
int transp = 0x100 - opacity;
uint32_t rb, g;
 
rb = ((pixel & 0xFF00FF) * opacity +
(scrpixel & 0xFF00FF) * transp) >> 8;
g = ((pixel & 0x00FF00) * opacity +
(scrpixel & 0x00FF00) * transp) >> 8;
 
return (rb & 0xFF00FF) | (g & 0xFF00);
}
 
 
bool nsfb_plot_clip(const nsfb_bbox_t * clip, nsfb_bbox_t * rect);
 
bool nsfb_plot_clip_ctx(nsfb_t *nsfb, nsfb_bbox_t * rect);
 
bool nsfb_plot_clip_line(const nsfb_bbox_t * clip, nsfb_bbox_t * line);
 
bool nsfb_plot_clip_line_ctx(nsfb_t *nsfb, nsfb_bbox_t * line);
 
/** Obtain a bounding box which is the superset of two source boxes.
*
*/
bool nsfb_plot_add_rect(const nsfb_bbox_t *box1, const nsfb_bbox_t *box2, nsfb_bbox_t *result);
 
/** Find if two boxes intersect. */
bool nsfb_plot_bbox_intersect(const nsfb_bbox_t *box1, const nsfb_bbox_t *box2);
 
#endif /* _LIBNSFB_PLOT_UTIL_H */
/programs/network/netsurf/include/libnsgif.h
0,0 → 1,108
/*
* Copyright 2004 Richard Wilson <richard.wilson@netsurf-browser.org>
* Copyright 2008 Sean Fox <dyntryx@gmail.com>
*
* This file is part of NetSurf's libnsgif, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
 
/** \file
* Progressive animated GIF file decoding (interface).
*/
 
#ifndef _LIBNSGIF_H_
#define _LIBNSGIF_H_
 
#include <stdbool.h>
#include <inttypes.h>
 
/* Error return values
*/
typedef enum {
GIF_WORKING = 1,
GIF_OK = 0,
GIF_INSUFFICIENT_FRAME_DATA = -1,
GIF_FRAME_DATA_ERROR = -2,
GIF_INSUFFICIENT_DATA = -3,
GIF_DATA_ERROR = -4,
GIF_INSUFFICIENT_MEMORY = -5,
GIF_FRAME_NO_DISPLAY = -6,
GIF_END_OF_FRAME = -7
} gif_result;
 
/* The GIF frame data
*/
typedef struct gif_frame {
bool display; /**< whether the frame should be displayed/animated */
unsigned int frame_delay; /**< delay (in cs) before animating the frame */
/** Internal members are listed below
*/
unsigned int frame_pointer; /**< offset (in bytes) to the GIF frame data */
bool virgin; /**< whether the frame has previously been used */
bool opaque; /**< whether the frame is totally opaque */
bool redraw_required; /**< whether a forcable screen redraw is required */
unsigned char disposal_method; /**< how the previous frame should be disposed; affects plotting */
bool transparency; /**< whether we acknoledge transparency */
unsigned char transparency_index; /**< the index designating a transparent pixel */
unsigned int redraw_x; /**< x co-ordinate of redraw rectangle */
unsigned int redraw_y; /**< y co-ordinate of redraw rectangle */
unsigned int redraw_width; /**< width of redraw rectangle */
unsigned int redraw_height; /**< height of redraw rectangle */
} gif_frame;
 
/* API for Bitmap callbacks
*/
typedef void* (*gif_bitmap_cb_create)(int width, int height);
typedef void (*gif_bitmap_cb_destroy)(void *bitmap);
typedef unsigned char* (*gif_bitmap_cb_get_buffer)(void *bitmap);
typedef void (*gif_bitmap_cb_set_opaque)(void *bitmap, bool opaque);
typedef bool (*gif_bitmap_cb_test_opaque)(void *bitmap);
typedef void (*gif_bitmap_cb_modified)(void *bitmap);
 
/* The Bitmap callbacks function table
*/
typedef struct gif_bitmap_callback_vt {
gif_bitmap_cb_create bitmap_create; /**< Create a bitmap. */
gif_bitmap_cb_destroy bitmap_destroy; /**< Free a bitmap. */
gif_bitmap_cb_get_buffer bitmap_get_buffer; /**< Return a pointer to the pixel data in a bitmap. */
/** Members below are optional
*/
gif_bitmap_cb_set_opaque bitmap_set_opaque; /**< Sets whether a bitmap should be plotted opaque. */
gif_bitmap_cb_test_opaque bitmap_test_opaque; /**< Tests whether a bitmap has an opaque alpha channel. */
gif_bitmap_cb_modified bitmap_modified; /**< The bitmap image has changed, so flush any persistant cache. */
} gif_bitmap_callback_vt;
 
/* The GIF animation data
*/
typedef struct gif_animation {
gif_bitmap_callback_vt bitmap_callbacks; /**< callbacks for bitmap functions */
unsigned char *gif_data; /**< pointer to GIF data */
unsigned int width; /**< width of GIF (may increase during decoding) */
unsigned int height; /**< heigth of GIF (may increase during decoding) */
unsigned int frame_count; /**< number of frames decoded */
unsigned int frame_count_partial; /**< number of frames partially decoded */
gif_frame *frames; /**< decoded frames */
int decoded_frame; /**< current frame decoded to bitmap */
void *frame_image; /**< currently decoded image; stored as bitmap from bitmap_create callback */
int loop_count; /**< number of times to loop animation */
gif_result current_error; /**< current error type, or 0 for none*/
/** Internal members are listed below
*/
unsigned int buffer_position; /**< current index into GIF data */
unsigned int buffer_size; /**< total number of bytes of GIF data available */
unsigned int frame_holders; /**< current number of frame holders */
unsigned int background_index; /**< index in the colour table for the background colour */
unsigned int aspect_ratio; /**< image aspect ratio (ignored) */
unsigned int colour_table_size; /**< size of colour table (in entries) */
bool global_colours; /**< whether the GIF has a global colour table */
unsigned int *global_colour_table; /**< global colour table */
unsigned int *local_colour_table; /**< local colour table */
} gif_animation;
 
void gif_create(gif_animation *gif, gif_bitmap_callback_vt *bitmap_callbacks);
gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data);
gif_result gif_decode_frame(gif_animation *gif, unsigned int frame);
void gif_finalise(gif_animation *gif);
 
#endif
/programs/network/netsurf/include/nsfb.h
0,0 → 1,49
/*
* Copyright 2009 Vincent Sanders <vince@simtec.co.uk>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the internal interface for the libnsfb graphics library.
*/
 
#ifndef _NSFB_H
#define _NSFB_H 1
 
#include <stdint.h>
 
 
/** NS Framebuffer context
*/
struct nsfb_s {
int width; /**< Visible width. */
int height; /**< Visible height. */
 
char *parameters;
 
enum nsfb_format_e format; /**< Framebuffer format */
int bpp; /**< Bits per pixel - distinct from format */
 
uint8_t *ptr; /**< Base of video memory. */
int linelen; /**< length of a video line. */
 
struct nsfb_palette_s *palette; /**< palette for index modes */
nsfb_cursor_t *cursor; /**< cursor */
 
struct nsfb_surface_rtns_s *surface_rtns; /**< surface routines. */
void *surface_priv; /**< surface opaque data. */
 
nsfb_bbox_t clip; /**< current clipping rectangle for plotters */
struct nsfb_plotter_fns_s *plotter_fns; /**< Plotter methods */
};
 
 
#endif
 
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* End:
*/
/programs/network/netsurf/include/palette.h
0,0 → 1,231
/*
* Copyright 2012 Michael Drake <tlsa@netsurf-browser.org>
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*
* This is the *internal* interface for the cursor.
*/
 
#ifndef PALETTE_H
#define PALETTE_H 1
 
#include <stdint.h>
#include <limits.h>
 
#include "libnsfb.h"
#include "libnsfb_plot.h"
 
enum nsfb_palette_type_e {
NSFB_PALETTE_EMPTY, /**< empty palette object */
NSFB_PALETTE_NSFB_8BPP, /**< libnsfb's own 8bpp palette */
NSFB_PALETTE_OTHER /**< any other palette */
};
 
struct nsfb_palette_s {
enum nsfb_palette_type_e type; /**< Palette type */
uint8_t last; /**< Last used palette index */
nsfb_colour_t data[256]; /**< Palette for index modes */
 
bool dither; /**< Whether to use error diffusion */
struct {
int width; /**< Length of error value buffer ring*/
int current; /**< Current pos in ring buffer*/
int *data; /**< Ring buffer error values */
int data_len; /**< Max size of ring */
} dither_ctx;
};
 
 
/** Create an empty palette object. */
bool nsfb_palette_new(struct nsfb_palette_s **palette, int width);
 
/** Free a palette object. */
void nsfb_palette_free(struct nsfb_palette_s *palette);
 
/** Init error diffusion for a plot. */
void nsfb_palette_dither_init(struct nsfb_palette_s *palette, int width);
 
/** Finalise error diffusion after a plot. */
void nsfb_palette_dither_fini(struct nsfb_palette_s *palette);
 
/** Generate libnsfb 8bpp default palette. */
void nsfb_palette_generate_nsfb_8bpp(struct nsfb_palette_s *palette);
 
/** Find best palette match for given colour. */
static inline uint8_t nsfb_palette_best_match(struct nsfb_palette_s *palette,
nsfb_colour_t c, int *r_error, int *g_error, int *b_error)
{
uint8_t best_col = 0;
 
nsfb_colour_t palent;
int col;
int dr, dg, db; /* delta red, green blue values */
 
int cur_distance;
int best_distance = INT_MAX;
 
switch (palette->type) {
case NSFB_PALETTE_NSFB_8BPP:
/* Index into colour cube part */
dr = ((( c & 0xFF) * 5) + 128) / 256;
dg = ((((c >> 8) & 0xFF) * 7) + 128) / 256;
db = ((((c >> 16) & 0xFF) * 4) + 128) / 256;
col = 40 * dr + 5 * dg + db;
 
palent = palette->data[col];
dr = ( c & 0xFF) - ( palent & 0xFF);
dg = ((c >> 8) & 0xFF) - ((palent >> 8 ) & 0xFF);
db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
 
best_col = col;
best_distance = cur_distance;
*r_error = dr;
*g_error = dg;
*b_error = db;
 
/* Index into grayscale part */
col = (( c & 0xFF) +
((c >> 8) & 0xFF) +
((c >> 16) & 0xFF) + (45 / 2)) / (15 * 3) - 1 + 240;
palent = palette->data[col];
 
dr = ( c & 0xFF) - ( palent & 0xFF);
dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
if (cur_distance < best_distance) {
best_distance = cur_distance;
best_col = col;
*r_error = dr;
*g_error = dg;
*b_error = db;
}
break;
 
case NSFB_PALETTE_OTHER:
/* Try all colours in palette */
for (col = 0; col <= palette->last; col++) {
palent = palette->data[col];
 
dr = ( c & 0xFF) - ( palent & 0xFF);
dg = ((c >> 8) & 0xFF) - ((palent >> 8) & 0xFF);
db = ((c >> 16) & 0xFF) - ((palent >> 16) & 0xFF);
cur_distance = (dr * dr) + (dg * dg) + (db * db);
if (cur_distance < best_distance) {
best_distance = cur_distance;
best_col = col;
*r_error = dr;
*g_error = dg;
*b_error = db;
}
}
break;
 
default:
break;
}
 
return best_col;
}
 
/** Find best palette match for given colour, with error diffusion. */
static inline uint8_t nsfb_palette_best_match_dither(
struct nsfb_palette_s *palette, nsfb_colour_t c)
{
int r, g, b;
int current;
int error;
int width = palette->dither_ctx.width;
uint8_t best_col_index;
 
if (palette == NULL)
return 0;
 
if (palette->dither == false)
return nsfb_palette_best_match(palette, c, &r, &g, &b);
 
current = palette->dither_ctx.current;
 
/* Get RGB components of colour, and apply error */
r = ( c & 0xFF) + palette->dither_ctx.data[current ];
g = ((c >> 8) & 0xFF) + palette->dither_ctx.data[current + 1];
b = ((c >> 16) & 0xFF) + palette->dither_ctx.data[current + 2];
 
/* Clamp new RGB components to range */
if (r < 0) r = 0;
if (r > 255) r = 255;
if (g < 0) g = 0;
if (g > 255) g = 255;
if (b < 0) b = 0;
if (b > 255) b = 255;
 
/* Reset error diffusion slots to 0 */
palette->dither_ctx.data[current ] = 0;
palette->dither_ctx.data[current + 1] = 0;
palette->dither_ctx.data[current + 2] = 0;
 
/* Rebuild colour from modified components */
c = r + (g << 8) + (b << 16);
 
/* Get best match for pixel, and find errors for each component */
best_col_index = nsfb_palette_best_match(palette, c, &r, &g, &b);
 
/* Advance one set of error diffusion slots */
current += 3;
if (current >= width)
current = 0;
palette->dither_ctx.current = current;
 
/* Save errors
*
* [*]-[N]
* / | \
* [l]-[m]-[r]
*/
error = current;
 
/* Error for [N] (next) */
if (error != 0) {
/* The pixel exists */
palette->dither_ctx.data[error ] += r * 7 / 16;
palette->dither_ctx.data[error + 1] += g * 7 / 16;
palette->dither_ctx.data[error + 2] += b * 7 / 16;
}
 
error += width - 2 * 3;
if (error >= width)
error -= width;
/* Error for [l] (below, left) */
if (error >= 0 && error != 3) {
/* The pixel exists */
palette->dither_ctx.data[error ] += r * 3 / 16;
palette->dither_ctx.data[error + 1] += g * 3 / 16;
palette->dither_ctx.data[error + 2] += b * 3 / 16;
}
 
error += 3;
if (error >= width)
error -= width;
/* Error for [m] (below, middle) */
palette->dither_ctx.data[error ] += r * 5 / 16;
palette->dither_ctx.data[error + 1] += g * 5 / 16;
palette->dither_ctx.data[error + 2] += b * 5 / 16;
 
error += 3;
if (error >= width)
error -= width;
/* Error for [r] (below, right) */
if (error != 0) {
/* The pixel exists */
palette->dither_ctx.data[error ] += r / 16;
palette->dither_ctx.data[error + 1] += g / 16;
palette->dither_ctx.data[error + 2] += b / 16;
}
 
return best_col_index;
}
 
#endif /* PALETTE_H */
/programs/network/netsurf/include/plot.h
0,0 → 1,124
 
 
/** Clears plotting area to a flat colour (if needed)
*/
typedef bool (nsfb_plotfn_clg_t)(nsfb_t *nsfb, nsfb_colour_t c);
 
/** Plots a rectangle outline. The line can be solid, dotted or
* dashed. Top left corner at (x0,y0) and rectangle has given
* width and height.
*/
typedef bool (nsfb_plotfn_rectangle_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, int line_width, nsfb_colour_t c, bool dotted, bool dashed);
 
/** Plots a line using a given pen.
*/
typedef bool (nsfb_plotfn_line_t)(nsfb_t *nsfb, int linec, nsfb_bbox_t *line, nsfb_plot_pen_t *pen);
 
/** Plots a filled polygon with straight lines between points.
* The lines around the edge of the ploygon are not plotted. The
* polygon is filled with the non-zero winding rule.
*/
typedef bool (nsfb_plotfn_polygon_t)(nsfb_t *nsfb, const int *p, unsigned int n, nsfb_colour_t fill);
 
/** Plots a filled rectangle. Top left corner at (x0,y0), bottom
* right corner at (x1,y1). Note: (x0,y0) is inside filled area,
* but (x1,y1) is below and to the right. See diagram below.
*/
typedef bool (nsfb_plotfn_fill_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t c);
 
/** Clipping operations.
*/
typedef bool (nsfb_plotfn_clip_t)(nsfb_t *nsfb, nsfb_bbox_t *clip);
 
/** Plots an arc, around (x,y), from anticlockwise from angle1 to
* angle2. Angles are measured anticlockwise from horizontal, in
* degrees.
*/
typedef bool (nsfb_plotfn_arc_t)(nsfb_t *nsfb, int x, int y, int radius, int angle1, int angle2, nsfb_colour_t c);
 
/** Plots a point.
*
* Plot a single alpha blended pixel.
*/
typedef bool (nsfb_plotfn_point_t)(nsfb_t *nsfb, int x, int y, nsfb_colour_t c);
 
/** Plot an ellipse.
*
* plot an ellipse outline, note if teh bounding box is square this will plot a
* circle.
*/
typedef bool (nsfb_plotfn_ellipse_t)(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
 
/** Plot a filled ellipse.
*
* plot a filled ellipse, note if the bounding box is square this will plot a
* circle.
*/
typedef bool (nsfb_plotfn_ellipse_fill_t)(nsfb_t *nsfb, nsfb_bbox_t *ellipse, nsfb_colour_t c);
 
 
/** Plot bitmap
*/
typedef bool (nsfb_plotfn_bitmap_t)(nsfb_t *nsfb, const nsfb_bbox_t *loc, const nsfb_colour_t *pixel, int bmp_width, int bmp_height, int bmp_stride, bool alpha);
 
 
/** Copy an area of screen
*
* Copy an area of the display.
*/
typedef bool (nsfb_plotfn_copy_t)(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox);
 
 
/** Plot an 8 bit per pixel glyph.
*/
typedef bool (nsfb_plotfn_glyph8_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c);
 
 
/** Plot an 1 bit per pixel glyph.
*/
typedef bool (nsfb_plotfn_glyph1_t)(nsfb_t *nsfb, nsfb_bbox_t *loc, const uint8_t *pixel, int pitch, nsfb_colour_t c);
 
/** Read rectangle of screen into buffer
*/
typedef bool (nsfb_plotfn_readrect_t)(nsfb_t *nsfb, nsfb_bbox_t *rect, nsfb_colour_t *buffer);
 
/** Plot quadratic bezier spline
*/
typedef bool (nsfb_plotfn_quadratic_bezier_t)(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_plot_pen_t *pen);
 
/** Plot cubic bezier spline
*/
typedef bool (nsfb_plotfn_cubic_bezier_t)(nsfb_t *nsfb, nsfb_bbox_t *curve, nsfb_point_t *ctrla, nsfb_point_t *ctrlb, nsfb_plot_pen_t *pen);
 
typedef bool (nsfb_plotfn_polylines_t)(nsfb_t *nsfb, int pointc, const nsfb_point_t *points, nsfb_plot_pen_t *pen);
 
/** plot path */
typedef bool (nsfb_plotfn_path_t)(nsfb_t *nsfb, int pathc, nsfb_plot_pathop_t *pathop, nsfb_plot_pen_t *pen);
 
/** plotter function table. */
typedef struct nsfb_plotter_fns_s {
nsfb_plotfn_clg_t *clg;
nsfb_plotfn_rectangle_t *rectangle;
nsfb_plotfn_line_t *line;
nsfb_plotfn_polygon_t *polygon;
nsfb_plotfn_fill_t *fill;
nsfb_plotfn_clip_t *get_clip;
nsfb_plotfn_clip_t *set_clip;
nsfb_plotfn_ellipse_t *ellipse;
nsfb_plotfn_ellipse_fill_t *ellipse_fill;
nsfb_plotfn_arc_t *arc;
nsfb_plotfn_bitmap_t *bitmap;
nsfb_plotfn_point_t *point;
nsfb_plotfn_copy_t *copy;
nsfb_plotfn_glyph8_t *glyph8;
nsfb_plotfn_glyph1_t *glyph1;
nsfb_plotfn_readrect_t *readrect;
nsfb_plotfn_quadratic_bezier_t *quadratic;
nsfb_plotfn_cubic_bezier_t *cubic;
nsfb_plotfn_path_t *path;
nsfb_plotfn_polylines_t *polylines;
} nsfb_plotter_fns_t;
 
 
bool select_plotters(nsfb_t *nsfb);
 
/programs/network/netsurf/include/surface.h
0,0 → 1,65
/* libnsfb framebuffer surface support */
 
#include "libnsfb.h"
#include "libnsfb_plot.h"
#include "nsfb.h"
 
/* surface default options */
typedef int (nsfb_surfacefn_defaults_t)(nsfb_t *nsfb);
 
/* surface init */
typedef int (nsfb_surfacefn_init_t)(nsfb_t *nsfb);
 
/* surface finalise */
typedef int (nsfb_surfacefn_fini_t)(nsfb_t *nsfb);
 
/* surface set geometry */
typedef int (nsfb_surfacefn_geometry_t)(nsfb_t *nsfb, int width, int height, enum nsfb_format_e format);
 
/* surface set parameters */
typedef int (nsfb_surfacefn_parameters_t)(nsfb_t *nsfb, const char *parameters);
 
/* surface input */
typedef bool (nsfb_surfacefn_input_t)(nsfb_t *nsfb, nsfb_event_t *event, int timeout);
 
/* surface area claim */
typedef int (nsfb_surfacefn_claim_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
 
/* surface area update */
typedef int (nsfb_surfacefn_update_t)(nsfb_t *nsfb, nsfb_bbox_t *box);
 
/* surface cursor display */
typedef int (nsfb_surfacefn_cursor_t)(nsfb_t *nsfb, struct nsfb_cursor_s *cursor);
 
typedef struct nsfb_surface_rtns_s {
nsfb_surfacefn_defaults_t *defaults;
nsfb_surfacefn_init_t *initialise;
nsfb_surfacefn_fini_t *finalise;
nsfb_surfacefn_geometry_t *geometry;
nsfb_surfacefn_parameters_t *parameters;
nsfb_surfacefn_input_t *input;
nsfb_surfacefn_claim_t *claim;
nsfb_surfacefn_update_t *update;
nsfb_surfacefn_cursor_t *cursor;
} nsfb_surface_rtns_t;
 
void _nsfb_register_surface(const enum nsfb_type_e type, const nsfb_surface_rtns_t *rtns, const char *name);
 
 
/* macro which adds a builtin command with no argument limits */
#define NSFB_SURFACE_DEF(__name, __type, __rtns) \
static void __name##_register_surface(void) __attribute__((constructor)); \
void __name##_register_surface(void) { \
_nsfb_register_surface(__type, __rtns, #__name); \
}
 
/** Obtain routines for a surface
*
* Obtain a vlist of methods for a surface type.
*
* @param type The surface type.
* @return A vtable of routines which teh caller must deallocate or
* NULL on error
*/
nsfb_surface_rtns_t *nsfb_surface_get_rtns(enum nsfb_type_e type);
 
/programs/network/netsurf/libnsfb/include/libnsfb.h
40,7 → 40,8
NSFB_SURFACE_LINUX, /**< Linux framebuffer surface */
NSFB_SURFACE_VNC, /**< VNC surface */
NSFB_SURFACE_ABLE, /**< ABLE framebuffer surface */
NSFB_SURFACE_X /**< X windows surface */
NSFB_SURFACE_X, /**< X windows surface */
NSFB_SURFACE_KOLIBRI
};
 
enum nsfb_format_e {
/programs/network/netsurf/libnsfb/src/surface/kolibri.c
0,0 → 1,383
/*
* Copyright 2013 SoUrcerer sourcerer@bk.ru
*
* This file is part of libnsfb, http://www.netsurf-browser.org/
* Licenced under the MIT License,
* http://www.opensource.org/licenses/mit-license.php
*/
 
#include <stdbool.h>
#include <stdlib.h>
 
#include "libnsfb.h"
#include "libnsfb_event.h"
#include "libnsfb_plot.h"
#include "libnsfb_plot_util.h"
 
#include "nsfb.h"
#include "surface.h"
#include "palette.h"
#include "plot.h"
#include "cursor.h"
 
 
#include <menuet/os.h>
 
 
 
unsigned char * pixels;
 
inline void f65(unsigned x, unsigned y, unsigned w, unsigned h, char *d)
{
asm("pusha");
asm ("nop"::"D"(0), "c"(w*65536+h), "d"(x*65536+y), "b"(d));
asm ("xor %eax, %eax");
asm ("movl %eax, %ebp");
asm ("pushl $32");
asm ("popl %esi");
asm ("int $0x40"::"a"(65));
asm("popa");
}
 
 
void kolibri_redraw(nsfb_t *nsfb){
__menuet__window_redraw(1);
__menuet__define_window(100,100,nsfb->width,nsfb->height,0x43000080,0x800000FF,0x000080);
__menuet__write_text(3,3,0xFFFFFF,"Netsurf",7);
__menuet__debug_out("f65 is mighty!\n");
 
//here put image pixels! it's 32bpp
f65(0,0, nsfb->width, nsfb->height, pixels);
__menuet__window_redraw(2);
}
 
 
static bool
kolibricopy(nsfb_t *nsfb, nsfb_bbox_t *srcbox, nsfb_bbox_t *dstbox)
{
char *pixels = nsfb->surface_priv;
nsfb_bbox_t allbox;
struct nsfb_cursor_s *cursor = nsfb->cursor;
 
nsfb_plot_add_rect(srcbox, dstbox, &allbox);
 
int x,y,w,h;
x = srcbox->x0;
y = srcbox->y0;
w = srcbox->x1 - srcbox->x0;
h = srcbox->y1 - srcbox->y0;
int tx, ty, tw, th;
tx = dstbox->x0;
ty = dstbox->y0;
tw = dstbox->x1 - dstbox->x0;
th = dstbox->y1 - dstbox->y0;
char pst[255];
sprintf (pst, "Src %d,%d %dx%d Dst %d,%d %dx%d \n", x,y,w,h,tx,ty,tw,th);
__menuet__debug_out(pst);
int px, py, pp;
 
for (px=x; px<w; px++)
for (py=y;py<h;py++)
for (pp=0; pp<4; pp++) {
pixels[4*(px+tx)*nsfb->width+4*(py+ty)+pp]=pixels[4*px*nsfb->width+4*py+pp];
}
kolibri_redraw(nsfb);
 
return true;
 
}
 
static int kolibri_set_geometry(nsfb_t *nsfb, int width, int height,
enum nsfb_format_e format)
{
if (nsfb->surface_priv != NULL)
return -1; /* fail if surface already initialised */
 
nsfb->width = width;
nsfb->height = height;
nsfb->format = format;
pixels=(char *)malloc(width*height*4);
/* select default sw plotters for format */
select_plotters(nsfb);
 
//nsfb->plotter_fns->copy = kolibricopy;
 
return 0;
}
unsigned pz, pb;
 
static int kolibri_initialise(nsfb_t *nsfb)
{
enum nsfb_format_e fmt;
 
pz=0;
pb=0;
 
__menuet__debug_out("Start UI\n");
 
if (nsfb->surface_priv != NULL)
return -1;
 
/* sanity checked depth. */
if ((nsfb->bpp != 32) ) {
__menuet__debug_out("Wrong bpp\n");
return -1; }
 
fmt = NSFB_FMT_XRGB8888;
/* If we didn't get what we asked for, reselect plotters */
if (nsfb->format != fmt) {
nsfb->format = fmt;
 
if (kolibri_set_geometry(nsfb, nsfb->width, nsfb->height,
nsfb->format) != 0) {
__menuet__debug_out("can't set geometry\n");
return -1;
}
}
 
nsfb->surface_priv = pixels;
 
nsfb->ptr = pixels;
nsfb->linelen = (nsfb->width * nsfb->bpp) / 8;
__menuet__debug_out("Redraw\n");
kolibri_redraw(nsfb);
__menuet__set_bitfield_for_wanted_events(EVENT_REDRAW|EVENT_KEY|EVENT_BUTTON|EVENT_MOUSE_CHANGE);
 
return 0;
}
 
 
 
static int kolibri_finalise(nsfb_t *nsfb)
{
nsfb=nsfb;
__menuet__sys_exit();
return 0;
}
 
 
unsigned kol_mouse_posw()
{
unsigned error;
asm volatile ("int $0x40":"=a"(error):"a"(37), "b"(1));
return error;
}
 
 
unsigned kol_mouse_btn()
{
unsigned error;
asm volatile ("int $0x40":"=a"(error):"a"(37), "b"(2));
return error;
}
 
 
 
static bool kolibri_input(nsfb_t *nsfb, nsfb_event_t *event, int timeout)
{
int got_event;
 
nsfb = nsfb; /* unused */
 
got_event = __menuet__check_for_event();
 
if (got_event == 0) {
return false;
}
 
event->type = NSFB_EVENT_NONE;
 
if (got_event==1) { //key pressed
kolibri_redraw(nsfb);
}
 
if (got_event==2) { //key pressed
event->type = NSFB_EVENT_KEY_UP;
event->value.keycode = __menuet__getkey();
return true;
}
if (got_event==3) { //key pressed
if (__menuet__get_button_id()==1) kolibri_finalise(nsfb);
return true;
}
if (got_event==6) { //key pressed
unsigned z=kol_mouse_posw();
unsigned b=kol_mouse_btn();
if (pz!=z) {
event->type = NSFB_EVENT_MOVE_ABSOLUTE;
event->value.vector.x = (z&0xffff0000)>>16; //sdlevent.motion.x;
event->value.vector.y = z&0xffff; //sdlevent.motion.y;
event->value.vector.z = 0;
pz=z;
return true;
}
if (pb!=b) {
unsigned t=b&1;
if (t==0) {
event->type = NSFB_EVENT_KEY_UP;
event->value.keycode = NSFB_KEY_MOUSE_1;
} else {
event->type = NSFB_EVENT_KEY_DOWN;
event->value.keycode = NSFB_KEY_MOUSE_1;
}
pb=b;
return true;
}
}
 
/*
 
case SDL_MOUSEBUTTONDOWN:
event->type = NSFB_EVENT_KEY_DOWN;
 
switch (sdlevent.button.button) {
 
case SDL_BUTTON_LEFT:
event->value.keycode = NSFB_KEY_MOUSE_1;
break;
 
case SDL_BUTTON_MIDDLE:
event->value.keycode = NSFB_KEY_MOUSE_2;
break;
 
case SDL_BUTTON_RIGHT:
event->value.keycode = NSFB_KEY_MOUSE_3;
break;
 
}
break;
 
case SDL_MOUSEBUTTONUP:
event->type = NSFB_EVENT_KEY_UP;
 
switch (sdlevent.button.button) {
 
case SDL_BUTTON_LEFT:
event->value.keycode = NSFB_KEY_MOUSE_1;
break;
 
case SDL_BUTTON_MIDDLE:
event->value.keycode = NSFB_KEY_MOUSE_2;
break;
 
case SDL_BUTTON_RIGHT:
event->value.keycode = NSFB_KEY_MOUSE_3;
break;
 
}
break;
 
case SDL_MOUSEMOTION:
event->type = NSFB_EVENT_MOVE_ABSOLUTE;
event->value.vector.x = sdlevent.motion.x;
event->value.vector.y = sdlevent.motion.y;
event->value.vector.z = 0;
break;
 
case SDL_QUIT:
event->type = NSFB_EVENT_CONTROL;
event->value.controlcode = NSFB_CONTROL_QUIT;
break;
 
case SDL_USEREVENT:
event->type = NSFB_EVENT_CONTROL;
event->value.controlcode = NSFB_CONTROL_TIMEOUT;
break;
 
}
*/
return true;
}
 
 
static int kolibri_claim(nsfb_t *nsfb, nsfb_bbox_t *box)
{
/*
if ((cursor != NULL) &&
(cursor->plotted == true) &&
(nsfb_plot_bbox_intersect(box, &cursor->loc))) {
nsfb_cursor_clear(nsfb, cursor);
} */
return 0; //stub yet
}
 
static int kolibri_cursor(nsfb_t *nsfb, struct nsfb_cursor_s *cursor)
{
return true; //stub yet
}
 
 
 
static int kolibri_update(nsfb_t *nsfb, nsfb_bbox_t *box)
{
/*SDL_Surface *sdl_screen = nsfb->surface_priv;
struct nsfb_cursor_s *cursor = nsfb->cursor;
 
if ((cursor != NULL) &&
(cursor->plotted == false)) {
nsfb_cursor_plot(nsfb, cursor);
}
 
SDL_UpdateRect(sdl_screen,
box->x0,
box->y0,
box->x1 - box->x0,
box->y1 - box->y0);
*/
//Ask for window redraw here!
kolibri_redraw(nsfb);
return 0;
}
 
const nsfb_surface_rtns_t kolibri_rtns = {
.initialise = kolibri_initialise,
.finalise = kolibri_finalise,
.input = kolibri_input,
.claim = kolibri_claim,
.update = kolibri_update,
.cursor = kolibri_cursor,
.geometry = kolibri_set_geometry,
};
 
NSFB_SURFACE_DEF(kolibri, NSFB_SURFACE_KOLIBRI, &kolibri_rtns)
 
/*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* End:
*/