NetSurf
Data Structures | Macros | Enumerations | Functions | Variables
bitmap.c File Reference
#include "amiga/os3support.h"
#include <stdlib.h>
#include <string.h>
#include <proto/exec.h>
#include <graphics/gfxbase.h>
#include <proto/datatypes.h>
#include <datatypes/pictureclass.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/utility.h>
#include <proto/guigfx.h>
#include <guigfx/guigfx.h>
#include <render/render.h>
#include <inline/guigfx.h>
#include "assert.h"
#include "utils/log.h"
#include "utils/nsoption.h"
#include "utils/nsurl.h"
#include "utils/messages.h"
#include "netsurf/bitmap.h"
#include "netsurf/content.h"
#include "amiga/gui.h"
#include "amiga/bitmap.h"
#include "amiga/plotters.h"
#include "amiga/memory.h"
#include "amiga/misc.h"
#include "amiga/rtg.h"
#include "amiga/schedule.h"
Include dependency graph for bitmap.c:

Go to the source code of this file.

Data Structures

struct  bitmap
 RISC OS wimp toolkit bitmap. More...
 
struct  vertex
 

Macros

#define VTX(I, X, Y, S, T)   vtx[I].x = X; vtx[I].y = Y; vtx[I].s = S; vtx[I].t = T; vtx[I].w = 1.0f;
 
#define VTX_RECT(SX, SY, SW, SH, DX, DY, DW, DH)
 

Enumerations

enum  { AMI_NSBM_NONE = 0 , AMI_NSBM_TRUECOLOUR , AMI_NSBM_PALETTEMAPPED }
 

Functions

void * amiga_bitmap_create (int width, int height, enum gui_bitmap_flags flags)
 Create a bitmap. More...
 
static void amiga_bitmap_unmap_buffer (void *p)
 
unsigned char * amiga_bitmap_get_buffer (void *bitmap)
 Return a pointer to the pixel data in a bitmap. More...
 
size_t amiga_bitmap_get_rowstride (void *bitmap)
 Find the width of a pixel row in bytes. More...
 
void amiga_bitmap_destroy (void *bitmap)
 Free a bitmap. More...
 
bool amiga_bitmap_save (void *bitmap, const char *path, unsigned flags)
 Save a bitmap in the platform's native format. More...
 
void amiga_bitmap_modified (void *bitmap)
 The bitmap image has changed, so flush any persistant cache. More...
 
void amiga_bitmap_set_opaque (void *bitmap, bool opaque)
 Sets whether a bitmap should be plotted opaque. More...
 
bool amiga_bitmap_get_opaque (void *bitmap)
 Gets whether a bitmap should be plotted opaque. More...
 
int bitmap_get_width (void *bitmap)
 get width of a bitmap. More...
 
int bitmap_get_height (void *bitmap)
 get height of a bitmap. More...
 
Object * ami_datatype_object_from_bitmap (struct bitmap *bitmap)
 
struct bitmapami_bitmap_from_datatype (char *filename)
 
static struct BitMap * ami_bitmap_get_guigfx (struct bitmap *bitmap, int width, int height, struct BitMap *restrict friendbm, int type, colour bg)
 
static struct BitMap * ami_bitmap_get_generic (struct bitmap *bitmap, int width, int height, struct BitMap *restrict friendbm, int type, colour bg)
 
static struct BitMap * ami_bitmap_get_truecolour (struct bitmap *bitmap, int width, int height, struct BitMap *friendbm, colour bg)
 
PLANEPTR ami_bitmap_get_mask (struct bitmap *bitmap, int width, int height, struct BitMap *n_bm)
 
static struct BitMap * ami_bitmap_get_palettemapped (struct bitmap *bitmap, int width, int height, struct BitMap *friendbm, colour bg)
 
struct BitMap * ami_bitmap_get_native (struct bitmap *bitmap, int width, int height, bool palette_mapped, struct BitMap *friendbm, colour bg)
 
void ami_bitmap_fini (void)
 Cleanup bitmap allocations. More...
 
static nserror bitmap_render (struct bitmap *bitmap, struct hlcache_handle *content)
 
void ami_bitmap_set_url (struct bitmap *bm, struct nsurl *url)
 Set bitmap URL. More...
 
void ami_bitmap_set_title (struct bitmap *bm, const char *title)
 Set bitmap title. More...
 
void ami_bitmap_set_icondata (struct bitmap *bm, ULONG *icondata)
 Set an icondata pointer. More...
 
void ami_bitmap_free_icondata (struct bitmap *bm)
 Free an icondata pointer. More...
 
bool ami_bitmap_is_nativebm (struct bitmap *bm, struct BitMap *nbm)
 Test if a BitMap is owned by a bitmap. More...
 

Variables

static APTR pool_bitmap = NULL
 
static bool guigfx_warned = false
 
static struct gui_bitmap_table bitmap_table
 
struct gui_bitmap_tableamiga_bitmap_table = &bitmap_table
 

Macro Definition Documentation

◆ VTX

#define VTX (   I,
  X,
  Y,
  S,
 
)    vtx[I].x = X; vtx[I].y = Y; vtx[I].s = S; vtx[I].t = T; vtx[I].w = 1.0f;

Definition at line 99 of file bitmap.c.

◆ VTX_RECT

#define VTX_RECT (   SX,
  SY,
  SW,
  SH,
  DX,
  DY,
  DW,
  DH 
)
Value:
VTX(0, DX, DY, SX, SY); \
VTX(1, DX + DW, DY, SX + SW, SY); \
VTX(2, DX, DY + DH, SX, SY + SH); \
VTX(3, DX + DW, DY, SX + SW, SY); \
VTX(4, DX, DY + DH, SX, SY + SH); \
VTX(5, DX + DW, DY + DH, SX + SW, SY + SH);
#define VTX(I, X, Y, S, T)
Definition: bitmap.c:99

Definition at line 100 of file bitmap.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
AMI_NSBM_NONE 
AMI_NSBM_TRUECOLOUR 
AMI_NSBM_PALETTEMAPPED 

Definition at line 88 of file bitmap.c.

Function Documentation

◆ ami_bitmap_fini()

void ami_bitmap_fini ( void  )

Cleanup bitmap allocations.

Definition at line 748 of file bitmap.c.

References ami_memory_itempool_delete, and pool_bitmap.

Referenced by main().

Here is the caller graph for this function:

◆ ami_bitmap_free_icondata()

void ami_bitmap_free_icondata ( struct bitmap bm)

Free an icondata pointer.

Parameters
bma bitmap, as returned by bitmap_create()

This function probably shouldn't be here!

Definition at line 807 of file bitmap.c.

References bitmap::icondata.

Referenced by amiga_icon_free().

Here is the caller graph for this function:

◆ ami_bitmap_from_datatype()

struct bitmap * ami_bitmap_from_datatype ( char *  filename)

Definition at line 407 of file bitmap.c.

References amiga_bitmap_create(), amiga_bitmap_get_buffer(), amiga_bitmap_get_rowstride(), amiga_bitmap_set_opaque(), bitmap_test_opaque(), bitmap::dto, IDoMethod, and PDTA_PromoteMask.

Referenced by ami_theme_throbber_setup().

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

◆ ami_bitmap_get_generic()

static struct BitMap * ami_bitmap_get_generic ( struct bitmap bitmap,
int  width,
int  height,
struct BitMap *restrict  friendbm,
int  type,
colour  bg 
)
inlinestatic

Definition at line 534 of file bitmap.c.

References AMI_BITMAP_FORMAT, ami_bitmap_get_guigfx(), ami_gui_get_screen(), AMI_NSBM_NONE, AMI_NSBM_PALETTEMAPPED, AMI_NSBM_TRUECOLOUR, ami_rtg_allocbitmap(), ami_rtg_freebitmap(), ami_rtg_writepixelarray(), amiga_bitmap_get_buffer(), amiga_bitmap_modified(), bitmap::bg, bitmap::height, height, bitmap::native, bitmap::nativebm, bitmap::nativebmheight, bitmap::nativebmwidth, NSLOG, nsoption_bool, nsoption_int, bitmap::opaque, scrn, type, VTX_RECT, bitmap::width, and width.

Referenced by ami_bitmap_get_palettemapped(), and ami_bitmap_get_truecolour().

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

◆ ami_bitmap_get_guigfx()

static struct BitMap * ami_bitmap_get_guigfx ( struct bitmap bitmap,
int  width,
int  height,
struct BitMap *restrict  friendbm,
int  type,
colour  bg 
)
inlinestatic

Definition at line 435 of file bitmap.c.

References AMI_BITMAP_FORMAT, ami_gui_get_screen(), AMI_NSBM_PALETTEMAPPED, AMI_NSBM_TRUECOLOUR, ami_rtg_allocbitmap(), amiga_bitmap_get_buffer(), amiga_warn_user(), bitmap::bg, colour_rb_swap, bitmap::drawhandle, guigfx_warned, bitmap::height, height, bitmap::native, bitmap::nativebm, bitmap::nativebmheight, bitmap::nativebmwidth, NS_TRANSPARENT, nsoption_bool, nsoption_int, bitmap::opaque, scrn, type, bitmap::width, and width.

Referenced by ami_bitmap_get_generic().

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

◆ ami_bitmap_get_mask()

PLANEPTR ami_bitmap_get_mask ( struct bitmap bitmap,
int  width,
int  height,
struct BitMap *  n_bm 
)

Definition at line 696 of file bitmap.c.

References amiga_bitmap_get_buffer(), amiga_bitmap_get_opaque(), bitmap::height, height, bitmap::native_mask, nsoption_int, SetMem, bitmap::width, and width.

Referenced by ami_bitmap(), ami_bitmap_tile(), and gui_window_set_icon().

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

◆ ami_bitmap_get_native()

struct BitMap * ami_bitmap_get_native ( struct bitmap bitmap,
int  width,
int  height,
bool  palette_mapped,
struct BitMap *  friendbm,
colour  bg 
)

Definition at line 736 of file bitmap.c.

References ami_bitmap_get_palettemapped(), ami_bitmap_get_truecolour(), height, palette_mapped, and width.

Referenced by ami_bitmap(), ami_bitmap_tile(), ami_theme_throbber_setup(), amiga_icon_from_bitmap(), amiga_icon_superimpose_favicon_internal(), gui_search_web_provider_update(), and gui_window_set_icon().

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

◆ ami_bitmap_get_palettemapped()

static struct BitMap * ami_bitmap_get_palettemapped ( struct bitmap bitmap,
int  width,
int  height,
struct BitMap *  friendbm,
colour  bg 
)
inlinestatic

Definition at line 726 of file bitmap.c.

References ami_bitmap_get_generic(), AMI_NSBM_NONE, AMI_NSBM_PALETTEMAPPED, amiga_bitmap_modified(), height, bitmap::native, and width.

Referenced by ami_bitmap_get_native().

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

◆ ami_bitmap_get_truecolour()

static struct BitMap * ami_bitmap_get_truecolour ( struct bitmap bitmap,
int  width,
int  height,
struct BitMap *  friendbm,
colour  bg 
)
inlinestatic

Definition at line 686 of file bitmap.c.

References ami_bitmap_get_generic(), AMI_NSBM_NONE, AMI_NSBM_TRUECOLOUR, amiga_bitmap_modified(), height, bitmap::native, and width.

Referenced by ami_bitmap_get_native().

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

◆ ami_bitmap_is_nativebm()

bool ami_bitmap_is_nativebm ( struct bitmap bm,
struct BitMap *  nbm 
)

Test if a BitMap is owned by a bitmap.

Parameters
bma bitmap, as returned by bitmap_create()
nbma BitMap, as created by AllocBitMap()
Returns
true if the BitMap is owned by the bitmap

Definition at line 813 of file bitmap.c.

References bitmap::nativebm.

Referenced by ami_bitmap(), and ami_bitmap_tile().

Here is the caller graph for this function:

◆ ami_bitmap_set_icondata()

void ami_bitmap_set_icondata ( struct bitmap bm,
ULONG *  icondata 
)

Set an icondata pointer.

Parameters
bma bitmap, as returned by bitmap_create()
icondataa pointer to memory

This function probably shouldn't be here!

Definition at line 802 of file bitmap.c.

References bitmap::icondata.

Referenced by amiga_icon_from_bitmap().

Here is the caller graph for this function:

◆ ami_bitmap_set_title()

void ami_bitmap_set_title ( struct bitmap bm,
const char *  title 
)

Set bitmap title.

Parameters
bma bitmap, as returned by bitmap_create()
titlea pointer to a title string

This is copied by the bitmap object. The title can only ever be set once for a bitmap.

Definition at line 796 of file bitmap.c.

References bitmap::title.

Referenced by ami_file_save(), and HOOKF().

Here is the caller graph for this function:

◆ ami_bitmap_set_url()

void ami_bitmap_set_url ( struct bitmap bm,
struct nsurl url 
)

Set bitmap URL.

Parameters
bma bitmap, as returned by bitmap_create()
urlthe url for the bitmap

A reference will be kept by the bitmap object. The URL can only ever be set once for a bitmap.

Definition at line 790 of file bitmap.c.

References nsurl_ref(), and bitmap::url.

Referenced by ami_file_save(), and HOOKF().

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

◆ ami_datatype_object_from_bitmap()

Object * ami_datatype_object_from_bitmap ( struct bitmap bitmap)

Definition at line 369 of file bitmap.c.

References amiga_bitmap_get_buffer(), amiga_bitmap_get_opaque(), amiga_bitmap_get_rowstride(), bitmap_get_height(), bitmap_get_width(), bitmap::dto, IDoMethod, messages_get(), nsurl_access(), bitmap::title, and bitmap::url.

Referenced by ami_easy_clipboard_bitmap(), and amiga_bitmap_save().

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

◆ amiga_bitmap_create()

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

Create a bitmap.

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

Definition at line 112 of file bitmap.c.

References AllocSysObjectTags, ami_memory_clear_alloc(), ami_memory_itempool_alloc, ami_memory_itempool_create, AMI_NSBM_NONE, amiga_bitmap_get_buffer(), bitmap(), BITMAP_OPAQUE, bitmap::drawhandle, bitmap::height, height, bitmap::icondata, bitmap::iextmem, bitmap::native, bitmap::native_mask, bitmap::nativebm, bitmap::nativebmheight, bitmap::nativebmwidth, nsoption_bool, bitmap::opaque, bitmap::pixdata, pool_bitmap, bitmap::size, bitmap::title, bitmap::url, bitmap::width, and width.

Referenced by ami_bitmap_from_datatype().

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

◆ amiga_bitmap_destroy()

void amiga_bitmap_destroy ( void *  bitmap)

Free a bitmap.

Parameters
bitmapa bitmap, as returned by bitmap_create()

Definition at line 214 of file bitmap.c.

References ami_memory_clear_free, ami_memory_itempool_free, ami_rtg_freebitmap(), ami_schedule(), amiga_bitmap_unmap_buffer(), bitmap(), bitmap::drawhandle, FreeSysObject(), bitmap::height, bitmap::iextmem, bitmap::native_mask, bitmap::nativebm, nsoption_bool, nsurl_unref(), bitmap::pixdata, pool_bitmap, bitmap::title, bitmap::url, and bitmap::width.

Referenced by ami_theme_throbber_free().

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

◆ amiga_bitmap_get_buffer()

unsigned char * amiga_bitmap_get_buffer ( void *  bitmap)

Return a pointer to the pixel data in a bitmap.

Parameters
bitmapa bitmap, as returned by bitmap_create()
Returns
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().

Definition at line 175 of file bitmap.c.

References ami_schedule(), amiga_bitmap_unmap_buffer(), bitmap(), bitmap::iextmem, NSLOG, nsoption_bool, bitmap::pixdata, and bitmap::size.

Referenced by ami_bitmap_from_datatype(), ami_bitmap_get_generic(), ami_bitmap_get_guigfx(), ami_bitmap_get_mask(), ami_datatype_object_from_bitmap(), and amiga_bitmap_create().

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

◆ amiga_bitmap_get_opaque()

bool amiga_bitmap_get_opaque ( void *  bitmap)

Gets whether a bitmap should be plotted opaque.

Parameters
bitmapa bitmap, as returned by bitmap_create()

Definition at line 309 of file bitmap.c.

References bitmap(), and bitmap::opaque.

Referenced by ami_bitmap(), ami_bitmap_get_mask(), ami_bitmap_tile(), ami_datatype_object_from_bitmap(), and gui_window_set_icon().

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

◆ amiga_bitmap_get_rowstride()

size_t amiga_bitmap_get_rowstride ( void *  bitmap)

Find the width of a pixel row in bytes.

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

Definition at line 198 of file bitmap.c.

References bitmap(), and bitmap::width.

Referenced by ami_bitmap_from_datatype(), and ami_datatype_object_from_bitmap().

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

◆ amiga_bitmap_modified()

void amiga_bitmap_modified ( void *  bitmap)

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

Parameters
bitmapa bitmap, as returned by bitmap_create()

Definition at line 282 of file bitmap.c.

References AMI_NSBM_NONE, ami_rtg_freebitmap(), ami_schedule(), amiga_bitmap_unmap_buffer(), bitmap(), bitmap::height, bitmap::native, bitmap::native_mask, bitmap::nativebm, and bitmap::width.

Referenced by ami_bitmap_get_generic(), ami_bitmap_get_palettemapped(), and ami_bitmap_get_truecolour().

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

◆ amiga_bitmap_save()

bool amiga_bitmap_save ( void *  bitmap,
const char *  path,
unsigned  flags 
)

Save a bitmap in the platform's native format.

Parameters
bitmapa bitmap, as returned by bitmap_create()
pathpathname for file
flagsflags controlling how the bitmap is saved.
Returns
true on success, false on error and error reported

Definition at line 257 of file bitmap.c.

References AMI_BITMAP_SCALE_ICON, ami_datatype_object_from_bitmap(), bitmap::dto, IDoMethod, path(), and SaveDTObjectA.

Referenced by ami_file_save(), and ami_gui_cache_favicon().

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

◆ amiga_bitmap_set_opaque()

void amiga_bitmap_set_opaque ( void *  bitmap,
bool  opaque 
)

Sets whether a bitmap should be plotted opaque.

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

Definition at line 300 of file bitmap.c.

References bitmap(), and bitmap::opaque.

Referenced by ami_bitmap_from_datatype(), and bitmap_render().

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

◆ amiga_bitmap_unmap_buffer()

static void amiga_bitmap_unmap_buffer ( void *  p)
static

Definition at line 158 of file bitmap.c.

References bitmap::iextmem, NSLOG, nsoption_bool, bitmap::pixdata, and bitmap::size.

Referenced by amiga_bitmap_destroy(), amiga_bitmap_get_buffer(), and amiga_bitmap_modified().

Here is the caller graph for this function:

◆ bitmap_get_height()

int bitmap_get_height ( void *  bitmap)

get height of a bitmap.

Return the height of a bitmap.

Definition at line 336 of file bitmap.c.

References bitmap(), and bitmap::height.

Referenced by ami_bitmap_tile(), ami_datatype_object_from_bitmap(), ami_theme_throbber_get_height(), ami_theme_throbber_setup(), and riscos_bitmap_convert_8bpp().

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

◆ bitmap_get_width()

int bitmap_get_width ( void *  bitmap)

get width of a bitmap.

Return the width of a bitmap.

Definition at line 319 of file bitmap.c.

References bitmap(), and bitmap::width.

Referenced by ami_bitmap_tile(), ami_datatype_object_from_bitmap(), ami_theme_throbber_get_width(), ami_theme_throbber_setup(), and riscos_bitmap_convert_8bpp().

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

◆ bitmap_render()

static nserror bitmap_render ( struct bitmap bitmap,
struct hlcache_handle content 
)
static
Todo:
In theory we should be able to move the bitmap to our native area to try to avoid re-conversion (at the expense of memory)

Definition at line 754 of file bitmap.c.

References AMI_BITMAP_FORMAT, ami_clearclipreg(), ami_plot_ra_alloc(), ami_plot_ra_free(), ami_plot_ra_get_bitmap(), ami_rtg_readpixelarray(), amiga_bitmap_set_opaque(), amiplot, content_get_width(), content_scaled_redraw(), bitmap::height, redraw_context::interactive, MIN, NSERROR_OK, NSLOG, bitmap::pixdata, and bitmap::width.

Here is the call graph for this function:

Variable Documentation

◆ amiga_bitmap_table

struct gui_bitmap_table* amiga_bitmap_table = &bitmap_table

Definition at line 833 of file bitmap.c.

Referenced by main().

◆ bitmap_table

struct gui_bitmap_table bitmap_table
static
Initial value:
= {
.set_opaque = amiga_bitmap_set_opaque,
.get_opaque = amiga_bitmap_get_opaque,
.get_buffer = amiga_bitmap_get_buffer,
.get_rowstride = amiga_bitmap_get_rowstride,
.get_width = bitmap_get_width,
.get_height = bitmap_get_height,
.modified = amiga_bitmap_modified,
.render = bitmap_render,
}
size_t amiga_bitmap_get_rowstride(void *bitmap)
Find the width of a pixel row in bytes.
Definition: bitmap.c:198
void * amiga_bitmap_create(int width, int height, enum gui_bitmap_flags flags)
Create a bitmap.
Definition: bitmap.c:112
int bitmap_get_width(void *bitmap)
get width of a bitmap.
Definition: bitmap.c:319
static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
Definition: bitmap.c:754
int bitmap_get_height(void *bitmap)
get height of a bitmap.
Definition: bitmap.c:336
void amiga_bitmap_modified(void *bitmap)
The bitmap image has changed, so flush any persistant cache.
Definition: bitmap.c:282
void amiga_bitmap_set_opaque(void *bitmap, bool opaque)
Sets whether a bitmap should be plotted opaque.
Definition: bitmap.c:300
bool amiga_bitmap_get_opaque(void *bitmap)
Gets whether a bitmap should be plotted opaque.
Definition: bitmap.c:309
unsigned char * amiga_bitmap_get_buffer(void *bitmap)
Return a pointer to the pixel data in a bitmap.
Definition: bitmap.c:175
void amiga_bitmap_destroy(void *bitmap)
Free a bitmap.
Definition: bitmap.c:214

Definition at line 820 of file bitmap.c.

◆ guigfx_warned

bool guigfx_warned = false
static

Definition at line 109 of file bitmap.c.

Referenced by ami_bitmap_get_guigfx().

◆ pool_bitmap

APTR pool_bitmap = NULL
static

Definition at line 108 of file bitmap.c.

Referenced by ami_bitmap_fini(), amiga_bitmap_create(), and amiga_bitmap_destroy().