NetSurf
Data Structures | Macros | Functions | Variables
bitmap.c File Reference

RISC OS implementation of bitmap operations. More...

#include <assert.h>
#include <stdbool.h>
#include <string.h>
#include <swis.h>
#include <rufl.h>
#include <unixlib/local.h>
#include <oslib/colourtrans.h>
#include <oslib/osfile.h>
#include <oslib/osfind.h>
#include <oslib/osgbpb.h>
#include <oslib/osspriteop.h>
#include <oslib/wimp.h>
#include "utils/nsoption.h"
#include "utils/filename.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "netsurf/plotters.h"
#include "netsurf/content.h"
#include "riscos/gui.h"
#include "riscos/image.h"
#include "riscos/palettes.h"
#include "riscos/content-handlers/sprite.h"
#include "riscos/tinct.h"
#include "riscos/bitmap.h"
Include dependency graph for bitmap.c:

Go to the source code of this file.

Data Structures

struct  thumbnail_save_area
 Sprite output context saving. More...
 

Macros

#define OVERLAY_INDEX   0xfe
 Colour in the overlay sprite that allows the bitmap to show through. More...
 
#define SAVE_CHUNK_SIZE   4096
 Size of buffer used when constructing mask data to be saved. More...
 

Functions

static bool bitmap_initialise (struct bitmap *bitmap)
 Initialise a bitmaps sprite area. More...
 
void * riscos_bitmap_create (int width, int height, enum gui_bitmap_flags flags)
 Create a bitmap. More...
 
unsigned char * riscos_bitmap_get_buffer (void *vbitmap)
 Return a pointer to the pixel data in a bitmap. More...
 
static void bitmap_set_opaque (void *vbitmap, bool opaque)
 Sets whether a bitmap should be plotted opaque. More...
 
static size_t bitmap_get_rowstride (void *vbitmap)
 Find the width of a pixel row in bytes. More...
 
bool riscos_bitmap_get_opaque (void *vbitmap)
 Gets whether a bitmap should be plotted opaque. More...
 
void riscos_bitmap_destroy (void *vbitmap)
 Free a bitmap. More...
 
bool riscos_bitmap_save (void *vbitmap, const char *path, unsigned flags)
 Save a bitmap in the platform's native format. More...
 
static void bitmap_modified (void *vbitmap)
 The bitmap image has changed, so flush any persistent cache. More...
 
static int bitmap_get_width (void *vbitmap)
 Get the width of a bitmap. More...
 
static int bitmap_get_height (void *vbitmap)
 Get the height of a bitmap. More...
 
void riscos_bitmap_overlay_sprite (struct bitmap *bitmap, const osspriteop_header *s)
 
static osspriteop_area * thumbnail_create_8bpp (struct bitmap *bitmap)
 Creates an 8bpp canvas. More...
 
static struct thumbnail_save_areathumbnail_switch_output (osspriteop_area *sprite_area, osspriteop_header *sprite_header)
 Switches output to the specified sprite and returns the previous context. More...
 
static void thumbnail_restore_output (struct thumbnail_save_area *save_area)
 Restores output to the specified context, and destroys it. More...
 
osspriteop_area * riscos_bitmap_convert_8bpp (struct bitmap *bitmap)
 Convert a bitmap to 8bpp. More...
 
static void thumbnail_test (void)
 Check to see whether 32bpp sprites are available. More...
 
nserror riscos_bitmap_render (struct bitmap *bitmap, struct hlcache_handle *content)
 Render content into bitmap. More...
 

Variables

static int thumbnail_32bpp_available = -1
 Whether we can use 32bpp sprites. More...
 
static struct gui_bitmap_table bitmap_table
 
struct gui_bitmap_tableriscos_bitmap_table = &bitmap_table
 bitmap operations table More...
 

Detailed Description

RISC OS implementation of bitmap operations.

This implements the interface given by image/bitmap.h using RISC OS sprites.

Definition in file bitmap.c.

Macro Definition Documentation

◆ OVERLAY_INDEX

#define OVERLAY_INDEX   0xfe

Colour in the overlay sprite that allows the bitmap to show through.

Definition at line 57 of file bitmap.c.

◆ SAVE_CHUNK_SIZE

#define SAVE_CHUNK_SIZE   4096

Size of buffer used when constructing mask data to be saved.

Definition at line 60 of file bitmap.c.

Function Documentation

◆ bitmap_get_height()

static int bitmap_get_height ( void *  vbitmap)
static

Get the height of a bitmap.

Parameters
vbitmapA bitmap, as returned by bitmap_create()
Returns
The bitmaps height in pixels.

Definition at line 423 of file bitmap.c.

References bitmap::height.

◆ bitmap_get_rowstride()

static size_t bitmap_get_rowstride ( void *  vbitmap)
static

Find the width of a pixel row in bytes.

Parameters
vbitmapA bitmap, as returned by riscos_bitmap_create()
Returns
width of a pixel row in the bitmap

Definition at line 185 of file bitmap.c.

References bitmap::width.

Referenced by riscos_bitmap_convert_8bpp(), and riscos_bitmap_overlay_sprite().

Here is the caller graph for this function:

◆ bitmap_get_width()

static int bitmap_get_width ( void *  vbitmap)
static

Get the width of a bitmap.

Parameters
vbitmapA bitmap, as returned by bitmap_create()
Returns
The bitmaps width in pixels.

Definition at line 410 of file bitmap.c.

References bitmap::width.

◆ bitmap_initialise()

static bool bitmap_initialise ( struct bitmap bitmap)
static

Initialise a bitmaps sprite area.

Parameters
bitmapthe bitmap to initialise
Returns
true if bitmap initialised else false.

Definition at line 84 of file bitmap.c.

References bitmap::clear, bitmap::height, bitmap::sprite_area, tinct_SPRITE_MODE, and bitmap::width.

Referenced by riscos_bitmap_get_buffer().

Here is the caller graph for this function:

◆ bitmap_modified()

static void bitmap_modified ( void *  vbitmap)
static

The bitmap image has changed, so flush any persistent cache.

Parameters
vbitmapa bitmap, as returned by bitmap_create()

Definition at line 398 of file bitmap.c.

Referenced by riscos_bitmap_render().

Here is the caller graph for this function:

◆ bitmap_set_opaque()

static void bitmap_set_opaque ( void *  vbitmap,
bool  opaque 
)
static

Sets whether a bitmap should be plotted opaque.

Parameters
vbitmapa bitmap, as returned by bitmap_create()
opaquewhether the bitmap should be plotted opaque

Definition at line 170 of file bitmap.c.

References bitmap::opaque.

Referenced by riscos_bitmap_overlay_sprite().

Here is the caller graph for this function:

◆ riscos_bitmap_convert_8bpp()

osspriteop_area * riscos_bitmap_convert_8bpp ( struct bitmap bitmap)

Convert a bitmap to 8bpp.

Convert bitmap to 8bpp sprite.

Parameters
bitmapthe bitmap to convert
Returns
a sprite area containing an 8bpp sprite

Definition at line 633 of file bitmap.c.

References bitmap_get_height(), bitmap_get_rowstride(), bitmap_get_width(), riscos_bitmap_get_buffer(), save_area, bitmap::sprite_area, thumbnail_32bpp_available, thumbnail_create_8bpp(), thumbnail_restore_output(), thumbnail_switch_output(), tinct_ERROR_DIFFUSE, and Tinct_Plot.

Referenced by ro_gui_save_create_thumbnail(), and ro_gui_window_iconise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ riscos_bitmap_create()

void * riscos_bitmap_create ( int  width,
int  height,
enum gui_bitmap_flags  flags 
)

Create a bitmap.

Parameters
widthwidth of image in pixels
heightheight of image in pixels
flagsflags for bitmap creation.
Returns
an opaque struct bitmap, or NULL on memory exhaustion

Definition at line 125 of file bitmap.c.

References bitmap(), BITMAP_CLEAR, BITMAP_OPAQUE, bitmap::clear, bitmap::height, height, bitmap::opaque, bitmap::width, and width.

Referenced by ro_gui_save_create_thumbnail(), and ro_gui_window_iconise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ riscos_bitmap_destroy()

void riscos_bitmap_destroy ( void *  vbitmap)

Free a bitmap.

Parameters
vbitmapa bitmap, as returned by bitmap_create()

Definition at line 202 of file bitmap.c.

References bitmap::sprite_area.

Referenced by ro_gui_save_create_thumbnail(), and ro_gui_window_iconise().

Here is the caller graph for this function:

◆ riscos_bitmap_get_buffer()

unsigned char * riscos_bitmap_get_buffer ( void *  vbitmap)

Return a pointer to the pixel data in a bitmap.

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 riscos_bitmap_get_rowstride().

Parameters
vbitmapA bitmap as returned by riscos_bitmap_create()
Returns
pointer to the pixel buffer

Definition at line 145 of file bitmap.c.

References bitmap_initialise(), and bitmap::sprite_area.

Referenced by riscos_bitmap_convert_8bpp(), riscos_bitmap_overlay_sprite(), riscos_bitmap_render(), riscos_bitmap_save(), and ro_plot_bitmap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ riscos_bitmap_get_opaque()

bool riscos_bitmap_get_opaque ( void *  vbitmap)

Gets whether a bitmap should be plotted opaque.

Parameters
vbitmapA bitmap, as returned by riscos_bitmap_create()

Definition at line 193 of file bitmap.c.

References bitmap::opaque.

Referenced by riscos_bitmap_save(), ro_plot_bitmap(), and thumbnail_create_8bpp().

Here is the caller graph for this function:

◆ riscos_bitmap_overlay_sprite()

void riscos_bitmap_overlay_sprite ( struct bitmap bitmap,
const osspriteop_header *  s 
)

Definition at line 431 of file bitmap.c.

References bitmap_get_rowstride(), bitmap_set_opaque(), default_palette8, bitmap::height, NSLOG, OVERLAY_INDEX, riscos_bitmap_get_buffer(), sprite_bpp(), and bitmap::width.

Referenced by ro_gui_window_iconise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ riscos_bitmap_render()

nserror riscos_bitmap_render ( struct bitmap bitmap,
struct hlcache_handle content 
)

Render content into bitmap.

Parameters
bitmapthe bitmap to draw to
contentcontent structure to render
Returns
true on success and bitmap updated else false

Definition at line 724 of file bitmap.c.

References bitmap_modified(), colourtrans_SET_BG_GCOL, content_scaled_redraw(), bitmap::height, redraw_context::interactive, NSERROR_OK, NSLOG, riscos_bitmap_get_buffer(), ro_plot_origin_x, ro_plot_origin_y, ro_plotters, save_area, bitmap::sprite_area, thumbnail_32bpp_available, thumbnail_create_8bpp(), thumbnail_restore_output(), thumbnail_switch_output(), thumbnail_test(), Tinct_ConvertSprite, and bitmap::width.

Referenced by ro_gui_save_create_thumbnail(), and ro_gui_window_iconise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ riscos_bitmap_save()

bool riscos_bitmap_save ( void *  vbitmap,
const char *  path,
unsigned  flags 
)

Save a bitmap in the platform's native format.

Parameters
vbitmapa bitmap, as returned by bitmap_create()
pathpathname for file
flagsmodify the behaviour of the save
Returns
true on success, false on error and error reported

Definition at line 218 of file bitmap.c.

References BITMAP_SAVE_FULL_ALPHA, height, messages_get(), NSLOG, path(), riscos_bitmap_get_buffer(), riscos_bitmap_get_opaque(), ro_warn_user(), SAVE_CHUNK_SIZE, bitmap::sprite_area, and width.

Referenced by ro_gui_save_object_native().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thumbnail_create_8bpp()

static osspriteop_area * thumbnail_create_8bpp ( struct bitmap bitmap)
static

Creates an 8bpp canvas.

Parameters
bitmapthe bitmap to clone the size of
Returns
a sprite area containing an 8bpp sprite

Definition at line 520 of file bitmap.c.

References bitmap::height, NSLOG, bitmap::opaque, riscos_bitmap_get_opaque(), bitmap::sprite_area, and bitmap::width.

Referenced by riscos_bitmap_convert_8bpp(), and riscos_bitmap_render().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ thumbnail_restore_output()

static void thumbnail_restore_output ( struct thumbnail_save_area save_area)
static

Restores output to the specified context, and destroys it.

Definition at line 614 of file bitmap.c.

References save_area.

Referenced by riscos_bitmap_convert_8bpp(), and riscos_bitmap_render().

Here is the caller graph for this function:

◆ thumbnail_switch_output()

static struct thumbnail_save_area * thumbnail_switch_output ( osspriteop_area *  sprite_area,
osspriteop_header *  sprite_header 
)
static

Switches output to the specified sprite and returns the previous context.

Definition at line 573 of file bitmap.c.

References save_area.

Referenced by riscos_bitmap_convert_8bpp(), and riscos_bitmap_render().

Here is the caller graph for this function:

◆ thumbnail_test()

static void thumbnail_test ( void  )
static

Check to see whether 32bpp sprites are available.

Rather than using Wimp_ReadSysInfo we test if 32bpp sprites are available in case the user has a 3rd party patch to enable them.

Definition at line 697 of file bitmap.c.

References NSLOG, thumbnail_32bpp_available, and tinct_SPRITE_MODE.

Referenced by riscos_bitmap_render().

Here is the caller graph for this function:

Variable Documentation

◆ bitmap_table

struct gui_bitmap_table bitmap_table
static
Initial value:
= {
.set_opaque = bitmap_set_opaque,
.get_opaque = riscos_bitmap_get_opaque,
.get_buffer = riscos_bitmap_get_buffer,
.get_rowstride = bitmap_get_rowstride,
.get_width = bitmap_get_width,
.get_height = bitmap_get_height,
.modified = bitmap_modified,
}
int bitmap_get_width(void *bitmap)
get width of a bitmap.
Definition: bitmap.c:319
int bitmap_get_height(void *bitmap)
get height of a bitmap.
Definition: bitmap.c:336
static void bitmap_set_opaque(void *vbitmap, bool opaque)
Sets whether a bitmap should be plotted opaque.
Definition: bitmap.c:170
void riscos_bitmap_destroy(void *vbitmap)
Free a bitmap.
Definition: bitmap.c:202
unsigned char * riscos_bitmap_get_buffer(void *vbitmap)
Return a pointer to the pixel data in a bitmap.
Definition: bitmap.c:145
static void bitmap_modified(void *vbitmap)
The bitmap image has changed, so flush any persistent cache.
Definition: bitmap.c:398
bool riscos_bitmap_get_opaque(void *vbitmap)
Gets whether a bitmap should be plotted opaque.
Definition: bitmap.c:193
void * riscos_bitmap_create(int width, int height, enum gui_bitmap_flags flags)
Create a bitmap.
Definition: bitmap.c:125
static size_t bitmap_get_rowstride(void *vbitmap)
Find the width of a pixel row in bytes.
Definition: bitmap.c:185
nserror riscos_bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
Render content into bitmap.
Definition: bitmap.c:724

Definition at line 805 of file bitmap.c.

◆ riscos_bitmap_table

struct gui_bitmap_table* riscos_bitmap_table = &bitmap_table

bitmap operations table

Definition at line 818 of file bitmap.c.

Referenced by main().

◆ thumbnail_32bpp_available

int thumbnail_32bpp_available = -1
static

Whether we can use 32bpp sprites.

Definition at line 65 of file bitmap.c.

Referenced by riscos_bitmap_convert_8bpp(), riscos_bitmap_render(), and thumbnail_test().