NetSurf
bitmap.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <stdbool.h>
20#include <stdio.h>
21#include <stdlib.h>
22
23#include "utils/errors.h"
24#include "netsurf/bitmap.h"
25
26#include "monkey/output.h"
27#include "monkey/bitmap.h"
28
29struct bitmap {
30 void *ptr;
31 size_t rowstride;
32 int width;
33 int height;
34 bool opaque;
35};
36
37static void *bitmap_create(int width, int height, enum gui_bitmap_flags flags)
38{
39 struct bitmap *ret = calloc(1, sizeof(*ret));
40 if (ret == NULL)
41 return NULL;
42
43 ret->width = width;
44 ret->height = height;
45 ret->opaque = (flags & BITMAP_OPAQUE) == BITMAP_OPAQUE;
46
47 ret->ptr = calloc(width, height * 4);
48
49 if (ret->ptr == NULL) {
50 free(ret);
51 return NULL;
52 }
53
54 return ret;
55}
56
57static void bitmap_destroy(void *bitmap)
58{
59 struct bitmap *bmap = bitmap;
60 free(bmap->ptr);
61 free(bmap);
62}
63
64static void bitmap_set_opaque(void *bitmap, bool opaque)
65{
66 struct bitmap *bmap = bitmap;
67
68 bmap->opaque = opaque;
69}
70
71static bool bitmap_get_opaque(void *bitmap)
72{
73 struct bitmap *bmap = bitmap;
74
75 return bmap->opaque;
76}
77
78static unsigned char *bitmap_get_buffer(void *bitmap)
79{
80 struct bitmap *bmap = bitmap;
81
82 return (unsigned char *)(bmap->ptr);
83}
84
85static size_t bitmap_get_rowstride(void *bitmap)
86{
87 struct bitmap *bmap = bitmap;
88 return bmap->width * 4;
89}
90
91static void bitmap_modified(void *bitmap)
92{
93 return;
94}
95
96static int bitmap_get_width(void *bitmap)
97{
98 struct bitmap *bmap = bitmap;
99 return bmap->width;
100}
101
102static int bitmap_get_height(void *bitmap)
103{
104 struct bitmap *bmap = bitmap;
105 return bmap->height;
106}
107
109 struct hlcache_handle *content)
110{
111 moutf(MOUT_GENERIC, "BITMAP RENDER");
112 return NSERROR_OK;
113}
114
117 .destroy = bitmap_destroy,
118 .set_opaque = bitmap_set_opaque,
119 .get_opaque = bitmap_get_opaque,
120 .get_buffer = bitmap_get_buffer,
121 .get_rowstride = bitmap_get_rowstride,
122 .get_width = bitmap_get_width,
123 .get_height = bitmap_get_height,
124 .modified = bitmap_modified,
125 .render = bitmap_render,
126};
127
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
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 struct gui_bitmap_table bitmap_table
Definition: bitmap.c:115
static void bitmap_modified(void *bitmap)
Definition: bitmap.c:91
static size_t bitmap_get_rowstride(void *bitmap)
Definition: bitmap.c:85
static nserror bitmap_render(struct bitmap *bitmap, struct hlcache_handle *content)
Definition: bitmap.c:108
struct gui_bitmap_table * monkey_bitmap_table
Definition: bitmap.c:128
static unsigned char * bitmap_get_buffer(void *bitmap)
Definition: bitmap.c:78
static void bitmap_set_opaque(void *bitmap, bool opaque)
Definition: bitmap.c:64
static bool bitmap_get_opaque(void *bitmap)
Definition: bitmap.c:71
static void * bitmap_create(int width, int height, enum gui_bitmap_flags flags)
Definition: bitmap.c:37
static void bitmap_destroy(void *bitmap)
Definition: bitmap.c:57
Generic bitmap handling interface.
gui_bitmap_flags
Bitmap creation flags.
Definition: bitmap.h:36
@ BITMAP_OPAQUE
image is opaque
Definition: bitmap.h:38
int moutf(enum monkey_output_type mout_type, const char *fmt,...)
Definition: output.c:39
@ MOUT_GENERIC
Definition: output.h:26
int width
Definition: gui.c:160
int height
Definition: gui.c:161
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
void * ptr
Definition: bitmap.c:30
int width
width of bitmap
Definition: bitmap.c:69
int height
height of bitmap
Definition: bitmap.c:70
bool opaque
Whether the bitmap is opaque.
Definition: bitmap.c:74
size_t rowstride
Definition: bitmap.h:65
Content which corresponds to a single URL.
Bitmap operations.
Definition: bitmap.h:125
void *(* create)(int width, int height, enum gui_bitmap_flags flags)
Create a new bitmap.
Definition: bitmap.h:136
High-level cache handle.
Definition: hlcache.c:66
static nserror bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.
Definition: plot.c:857