summaryrefslogtreecommitdiff
path: root/monkey/bitmap.c
blob: 31d2a23dc23b14d6225e057740c58b72e6aacd1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
 *
 * This file is part of NetSurf, http://www.netsurf-browser.org/
 *
 * NetSurf is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 2 of the License.
 *
 * NetSurf is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <stdbool.h>
#include <stdio.h>

#include "image/bitmap.h"

struct bitmap {
  void *ptr;
  size_t rowstride;
  int width;
  int height;
  unsigned int state;
};

void *bitmap_create(int width, int height, unsigned int state)
{
  struct bitmap *ret = calloc(sizeof(*ret), 1);
  if (ret == NULL)
    return NULL;
  
  ret->width = width;
  ret->height = height;
  ret->state = state;
  
  ret->ptr = calloc(width, height * 4);
  
  if (ret->ptr == NULL) {
    free(ret);
    return NULL;
  }
  
  return ret;
}

void bitmap_destroy(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  free(bmap->ptr);
  free(bmap);
}

void bitmap_set_opaque(void *bitmap, bool opaque)
{
  struct bitmap *bmap = bitmap;
  
  if (opaque)
    bmap->state |= (BITMAP_OPAQUE);
  else
    bmap->state &= ~(BITMAP_OPAQUE);
}

bool bitmap_test_opaque(void *bitmap)
{
  return false;
}

bool bitmap_get_opaque(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  
  return (bmap->state & BITMAP_OPAQUE) == BITMAP_OPAQUE;
}

unsigned char *bitmap_get_buffer(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  
  return (unsigned char *)(bmap->ptr);
}

size_t bitmap_get_rowstride(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  return bmap->width * 4;
}

size_t bitmap_get_bpp(void *bitmap)
{
  /* OMG?! */
  return 4;
}

bool bitmap_save(void *bitmap, const char *path, unsigned flags)
{
  return true;
}

void bitmap_modified(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  bmap->state |= BITMAP_MODIFIED;
}

void bitmap_set_suspendable(void *bitmap, void *private_word,
                            void (*invalidate)(void *bitmap, void *private_word))
{
  
}

int bitmap_get_width(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  return bmap->width;
}

int bitmap_get_height(void *bitmap)
{
  struct bitmap *bmap = bitmap;
  return bmap->height;
}