Repository navigation
Expand file tree
/
Copy pathbitmap.cc
More file actions
133 lines (116 loc) · 3.16 KB
/
Copy pathbitmap.cc
File metadata and controls
133 lines (116 loc) · 3.16 KB
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
128
129
130
131
132
133
/* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
*
* Quadra, an action puzzle game
* Copyright (C) 1998-2000 Ludus Design
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "bitmap.h"
#include <string.h>
#include "types.h"
#include "video.h"
#include "res.h"
#include "image_png.h"
using std::min;
Bitmap* Bitmap::loadPng(const ResName& n) {
Res_doze res(n);
Png png(res);
return new Bitmap(png);
}
Bitmap::Bitmap(int w, int h, int rw):
Clipable(w, h),
realwidth(rw*sizeof(uint8_t)),
zlines(new int[height]),
lines(new uint8_t*[height]),
size(h*rw),
fmem(1) {
initlines();
setmem((void*)new uint8_t[size]);
clear(0);
}
Bitmap::Bitmap(void* m, int w, int h, int rw):
Clipable(w, h),
realwidth(rw),
zlines(new int[height]),
lines(new uint8_t*[height]),
size(h*rw),
fmem(0) {
initlines();
setmem(m);
}
Bitmap::Bitmap(void* m, int w, int h, int rw, int bob):
Clipable(w, h),
realwidth(rw),
zlines(new int[height]),
lines(new uint8_t*[height]),
size(h*rw),
fmem(1) {
initlines();
setmem((void*)new uint8_t[size]);
memcpy(mem, m, size);
}
Bitmap::Bitmap(const Image& raw):
Clipable(raw.width(), raw.height()),
realwidth(width*sizeof(uint8_t)),
zlines(new int[height]),
lines(new uint8_t*[height]),
size(height*realwidth),
fmem(1) {
initlines();
setmem((void*)new uint8_t[size]);
reload(raw);
}
void Bitmap::reload(const Image& raw) {
memcpy(mem, raw.pic(), size);
}
void Bitmap::initlines() {
for(int y(0); y<height; y++)
zlines[y]=y*realwidth;
}
Bitmap::~Bitmap() {
delete[] zlines;
delete[] lines;
if(fmem)
delete[] mem;
}
void Bitmap::clear(const uint8_t color) const {
memset(mem, color, size);
}
void Bitmap::draw(const Bitmap& d, const int dx, const int dy) const {
if(d.clip(dx, dy, this))
return;
for(int y=clip_y1; y<=clip_y2; y++) {
memcpy(d[y]+clip_x1, operator[](y-dy)+(clip_x1-dx), clip_w);
}
}
void Bitmap::draw(const Video_bitmap* d, const int dx, const int dy) const {
d->put_bitmap(*this, dx, dy);
}
void Bitmap::hline(const int y, const int x, const int w, const uint8_t color) const {
if(clip(x, y, w, 1))
return;
memset(operator[](y)+clip_x1, color, clip_w);
}
void Bitmap::vline(const int x, const int y, const int h, const uint8_t color) const {
if(clip(x, y, 1, h))
return;
for(int i=clip_y1; i<=clip_y2; i++)
operator[](i)[x]=color;
}
void Bitmap::put_pel(const int x, const int y, const uint8_t color) const {
if(clip(x, y, 1, 1))
return;
fast_pel(x, y, color);
}