53 switch (fmt->layout) {
98 const char *
const str[] = {
109 if ((
size_t)layout >= (
sizeof(str)) /
sizeof(*str) ||
110 str[layout] == NULL) {
122 NSLOG(netsurf, INFO,
"Setting core bitmap format to: %s%s",
124 bitmap_format->
pma ?
" pre multiplied alpha" :
"");
129 NSLOG(netsurf, INFO,
"Sanitised layout to: %s",
155 for (
int y = 0; y <
height; y++) {
158 for (
int x = 0; x <
width; x++) {
159 const uint32_t px = *((uint32_t *)(
void *) row);
161 row[
to.r] = ((
const uint8_t *) &px)[
from.r];
162 row[
to.g] = ((
const uint8_t *) &px)[
from.g];
163 row[
to.b] = ((
const uint8_t *) &px)[
from.b];
164 row[
to.a] = ((
const uint8_t *) &px)[
from.a];
166 row +=
sizeof(uint32_t);
191 for (
int y = 0; y <
height; y++) {
194 for (
int x = 0; x <
width; x++) {
195 const uint32_t px = *((uint32_t *)(
void *) row);
198 r = ((
const uint8_t *) &px)[
from.r];
199 g = ((
const uint8_t *) &px)[
from.g];
200 b = ((
const uint8_t *) &px)[
from.b];
201 a = ((
const uint8_t *) &px)[
from.a];
204 r = ((
r * (
a + 1)) >> 8) & 0xff;
205 g = ((
g * (
a + 1)) >> 8) & 0xff;
206 b = ((
b * (
a + 1)) >> 8) & 0xff;
216 row +=
sizeof(uint32_t);
241 for (
int y = 0; y <
height; y++) {
244 for (
int x = 0; x <
width; x++) {
245 const uint32_t px = *((uint32_t *)(
void *) row);
248 r = ((
const uint8_t *) &px)[
from.r];
249 g = ((
const uint8_t *) &px)[
from.g];
250 b = ((
const uint8_t *) &px)[
from.b];
251 a = ((
const uint8_t *) &px)[
from.a];
258 r = (
r > 255) ? 255 :
r;
259 g = (
g > 255) ? 255 :
g;
260 b = (
b > 255) ? 255 :
b;
270 row +=
sizeof(uint32_t);
290 NSLOG(netsurf, DEEPDEBUG,
"%p: format conversion (%u%s --> %u%s)",
292 fmt_from->
layout, fmt_from->
pma ?
" pma" :
"",
293 fmt_to->
layout, fmt_to->
pma ?
" pma" :
"");
295 if (fmt_from->
pma == fmt_to->
pma) {
301 }
else if (opaque ==
false) {
323 width *=
sizeof(uint32_t);
325 for (
int y = 0; y <
height; y++) {
326 const uint8_t *row =
buffer;
329 if (row[x] != 0xff) {
static osspriteop_area * buffer
The buffer characteristics.
static const char * bitmap__layout_to_str(enum bitmap_layout layout)
Get string for given pixel layout.
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.
bool bitmap_test_opaque(void *bitmap)
Test whether a bitmap is completely opaque (no transparency).
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.
bitmap_fmt_t bitmap_fmt
The client bitmap format.
void bitmap_set_format(const bitmap_fmt_t *bitmap_format)
Set client bitmap format.
static struct bitmap_colour_layout bitmap__get_colour_layout(const bitmap_fmt_t *fmt)
Get the colour layout for the given bitmap format.
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.
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.
Internal core bitmap interface.
static enum bitmap_layout bitmap_sanitise_bitmap_layout(enum bitmap_layout layout)
Sanitise bitmap pixel component layout.
struct netsurf_table * guit
The global interface table.
Interface to core interface table.
bitmap_layout
NetSurf bitmap pixel layout.
@ BITMAP_LAYOUT_ABGR8888
32-bit BGRA (0xAABBGGRR).
@ BITMAP_LAYOUT_BGRA8888
32-bit BGRA (0xBBGGRRAA).
@ BITMAP_LAYOUT_ARGB8888
32-bit ARGB (0xAARRGGBB).
@ BITMAP_LAYOUT_B8G8R8A8
Bite-wise BGRA: Byte order: 0xBB, 0xGG, 0xRR, 0xAA.
@ BITMAP_LAYOUT_R8G8B8A8
Bite-wise RGBA: Byte order: 0xRR, 0xGG, 0xBB, 0xAA.
@ BITMAP_LAYOUT_A8B8G8R8
Bite-wise ABGR: Byte order: 0xAA, 0xBB, 0xGG, 0xRR.
@ BITMAP_LAYOUT_A8R8G8B8
Bite-wise ARGB: Byte order: 0xAA, 0xRR, 0xGG, 0xBB.
@ BITMAP_LAYOUT_RGBA8888
32-bit RGBA (0xRRGGBBAA).
#define NSLOG(catname, level, logmsg, args...)
Pixel format: colour component order.
uint8_t g
Byte offset within pixel to green component.
uint8_t b
Byte offset within pixel to blue component.
uint8_t a
Byte offset within pixel to alpha component.
uint8_t r
Byte offset within pixel to red component.
bool pma
Premultiplied alpha.
enum bitmap_layout layout
Colour component layout.
RISC OS wimp toolkit bitmap.
int(* get_height)(void *bitmap)
Get the bitmap height.
int(* get_width)(void *bitmap)
Get the bitmap width.
size_t(* get_rowstride)(void *bitmap)
Get the number of bytes per row of the image.
bool(* get_opaque)(void *bitmap)
Get the opacity of a bitmap.
unsigned char *(* get_buffer)(void *bitmap)
Get the image buffer from a bitmap.
struct gui_bitmap_table * bitmap
Bitmap table.
char from[32]
Encoding name to convert from.
char to[32]
Encoding name to convert to.