NetSurf
Functions | Variables
bitmap.c File Reference

Internal core bitmap interface. More...

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "utils/log.h"
#include "utils/errors.h"
#include "desktop/bitmap.h"
#include "desktop/gui_internal.h"
Include dependency graph for bitmap.c:

Go to the source code of this file.

Functions

static struct bitmap_colour_layout bitmap__get_colour_layout (const bitmap_fmt_t *fmt)
 Get the colour layout for the given bitmap format. More...
 
static const char * bitmap__layout_to_str (enum bitmap_layout layout)
 Get string for given pixel layout. More...
 
void bitmap_set_format (const bitmap_fmt_t *bitmap_format)
 Set client bitmap format. More...
 
static void bitmap__format_convert (int width, int height, uint8_t *buffer, size_t rowstride, struct bitmap_colour_layout to, struct bitmap_colour_layout from)
 Swap colour component order. More...
 
static void bitmap__format_convert_to_pma (int width, int height, uint8_t *buffer, size_t rowstride, struct bitmap_colour_layout to, struct bitmap_colour_layout from)
 Convert plain alpha to premultiplied alpha. More...
 
static void bitmap__format_convert_from_pma (int width, int height, uint8_t *buffer, size_t rowstride, struct bitmap_colour_layout to, struct bitmap_colour_layout from)
 Convert from premultiplied alpha to plain alpha. More...
 
void bitmap_format_convert (void *bitmap, const bitmap_fmt_t *fmt_from, const bitmap_fmt_t *fmt_to)
 Convert bitmap from one format to another. More...
 
bool bitmap_test_opaque (void *bitmap)
 Test whether a bitmap is completely opaque (no transparency). More...
 

Variables

bitmap_fmt_t bitmap_fmt
 The client bitmap format. More...
 
struct bitmap_colour_layout bitmap_layout
 The client bitmap colour channel layout. More...
 

Detailed Description

Internal core bitmap interface.

Definition in file bitmap.c.

Function Documentation

◆ bitmap__format_convert()

static void bitmap__format_convert ( int  width,
int  height,
uint8_t *  buffer,
size_t  rowstride,
struct bitmap_colour_layout  to,
struct bitmap_colour_layout  from 
)
inlinestatic

Swap colour component order.

Parameters
[in]widthBitmap width in pixels.
[in]heightBitmap height in pixels.
[in]bufferPixel buffer.
[in]rowstridePixel buffer row stride in bytes.
[in]toPixel layout to convert to.
[in]fromPixel layout to convert from.

Definition at line 146 of file bitmap.c.

References buffer, from, height, to, and width.

Referenced by bitmap_format_convert().

Here is the caller graph for this function:

◆ bitmap__format_convert_from_pma()

static void bitmap__format_convert_from_pma ( int  width,
int  height,
uint8_t *  buffer,
size_t  rowstride,
struct bitmap_colour_layout  to,
struct bitmap_colour_layout  from 
)
inlinestatic

Convert from premultiplied alpha to plain alpha.

Parameters
[in]widthBitmap width in pixels.
[in]heightBitmap height in pixels.
[in]bufferPixel buffer.
[in]rowstridePixel buffer row stride in bytes.
[in]toPixel layout to convert to.
[in]fromPixel layout to convert from.

Definition at line 233 of file bitmap.c.

References bitmap_colour_layout::a, bitmap_colour_layout::b, buffer, from, bitmap_colour_layout::g, height, bitmap_colour_layout::r, to, and width.

Referenced by bitmap_format_convert().

Here is the caller graph for this function:

◆ bitmap__format_convert_to_pma()

static void bitmap__format_convert_to_pma ( int  width,
int  height,
uint8_t *  buffer,
size_t  rowstride,
struct bitmap_colour_layout  to,
struct bitmap_colour_layout  from 
)
inlinestatic

Convert plain alpha to premultiplied alpha.

Parameters
[in]widthBitmap width in pixels.
[in]heightBitmap height in pixels.
[in]bufferPixel buffer.
[in]rowstridePixel buffer row stride in bytes.
[in]toPixel layout to convert to.
[in]fromPixel layout to convert from.

Definition at line 183 of file bitmap.c.

References bitmap_colour_layout::a, bitmap_colour_layout::b, buffer, from, bitmap_colour_layout::g, height, bitmap_colour_layout::r, to, and width.

Referenced by bitmap_format_convert().

Here is the caller graph for this function:

◆ bitmap__get_colour_layout()

static struct bitmap_colour_layout bitmap__get_colour_layout ( const bitmap_fmt_t fmt)
static

Get the colour layout for the given bitmap format.

Parameters
[in]fmtPixel format to get channel layout for,
Returns
channel layout structure.

Definition at line 50 of file bitmap.c.

References BITMAP_LAYOUT_A8B8G8R8, BITMAP_LAYOUT_A8R8G8B8, BITMAP_LAYOUT_B8G8R8A8, and BITMAP_LAYOUT_R8G8B8A8.

Referenced by bitmap_format_convert(), and bitmap_set_format().

Here is the caller graph for this function:

◆ bitmap__layout_to_str()

static const char * bitmap__layout_to_str ( enum bitmap_layout  layout)
static

Get string for given pixel layout.

Parameters
[in]layoutThe pixel layout to get string for,
Returns
String for given layout.

Definition at line 96 of file bitmap.c.

References BITMAP_LAYOUT_A8B8G8R8, BITMAP_LAYOUT_A8R8G8B8, BITMAP_LAYOUT_ABGR8888, BITMAP_LAYOUT_ARGB8888, BITMAP_LAYOUT_B8G8R8A8, BITMAP_LAYOUT_BGRA8888, BITMAP_LAYOUT_R8G8B8A8, and BITMAP_LAYOUT_RGBA8888.

Referenced by bitmap_set_format().

Here is the caller graph for this function:

◆ bitmap_format_convert()

void bitmap_format_convert ( void *  bitmap,
const bitmap_fmt_t from,
const bitmap_fmt_t to 
)

Convert bitmap from one format to another.

Note that both formats should be sanitised.

Parameters
[in]bitmapThe bitmap to convert.
[in]fromThe current bitmap format specifier.
[in]toThe bitmap format to convert to.

Definition at line 278 of file bitmap.c.

References netsurf_table::bitmap, bitmap__format_convert(), bitmap__format_convert_from_pma(), bitmap__format_convert_to_pma(), bitmap__get_colour_layout(), buffer, from, gui_bitmap_table::get_buffer, gui_bitmap_table::get_height, gui_bitmap_table::get_opaque, gui_bitmap_table::get_rowstride, gui_bitmap_table::get_width, guit, height, bitmap_fmt::layout, NSLOG, bitmap_fmt::pma, to, and width.

Referenced by bitmap_format_from_client(), and bitmap_format_to_client().

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

◆ bitmap_set_format()

void bitmap_set_format ( const bitmap_fmt_t bitmap_format)

Set client bitmap format.

Set this to ensure that the bitmaps decoded by the core are in the correct format for the front end.

Parameters
[in]bitmap_formatThe bitmap format specification to set.

Definition at line 118 of file bitmap.c.

References bitmap__get_colour_layout(), bitmap__layout_to_str(), bitmap_sanitise_bitmap_layout(), bitmap_fmt::layout, NSLOG, and bitmap_fmt::pma.

Referenced by ami_plot_ra_alloc(), and nsgtk_setup().

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

◆ bitmap_test_opaque()

bool bitmap_test_opaque ( void *  bitmap)

Test whether a bitmap is completely opaque (no transparency).

Parameters
[in]bitmapThe bitmap to test.
Returns
Returns true if the bitmap is opaque, false otherwise.

Definition at line 316 of file bitmap.c.

References netsurf_table::bitmap, buffer, gui_bitmap_table::get_buffer, gui_bitmap_table::get_height, gui_bitmap_table::get_rowstride, gui_bitmap_table::get_width, guit, height, and width.

Referenced by ami_bitmap_from_datatype(), gif_create_gif_data(), nspng_convert(), and png_cache_convert().

Here is the caller graph for this function:

Variable Documentation

◆ bitmap_fmt

The client bitmap format.

Definition at line 34 of file bitmap.c.

◆ bitmap_layout

Initial value:
= {
.r = 0,
.g = 1,
.b = 2,
.a = 3,
}

The client bitmap colour channel layout.

Definition at line 37 of file bitmap.c.