9628
|
1 |
#include "../stdafx.h"
|
|
2 |
#include "../gfx.h"
|
|
3 |
#include "8bpp_base.hpp"
|
|
4 |
|
|
5 |
void Blitter_8bppBase::DrawColorMappingRect(void *dst, int width, int height, int pal)
|
|
6 |
{
|
|
7 |
const uint8 *ctab = GetNonSprite(pal) + 1;
|
|
8 |
|
|
9 |
do {
|
|
10 |
for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
|
|
11 |
dst = (uint8 *)dst + _screen.pitch;
|
9629
|
12 |
} while (--height);
|
9628
|
13 |
}
|
|
14 |
|
|
15 |
void *Blitter_8bppBase::MoveTo(const void *video, int x, int y)
|
|
16 |
{
|
|
17 |
return (uint8 *)video + x + y * _screen.pitch;
|
|
18 |
}
|
|
19 |
|
|
20 |
void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8 color)
|
|
21 |
{
|
|
22 |
*((uint8 *)video + x + y * _screen.pitch) = color;
|
|
23 |
}
|
|
24 |
|
|
25 |
void Blitter_8bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 color)
|
|
26 |
{
|
|
27 |
uint8 *dst = (uint8 *)video + x + y * _screen.pitch;
|
|
28 |
if (*dst == 0) *dst = color;
|
|
29 |
}
|
|
30 |
|
9629
|
31 |
void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8 color)
|
9628
|
32 |
{
|
9629
|
33 |
do {
|
|
34 |
memset(video, color, width);
|
|
35 |
video = (uint8 *)video + _screen.pitch;
|
|
36 |
} while (--height);
|
9628
|
37 |
}
|
|
38 |
|
9629
|
39 |
void Blitter_8bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color)
|
9628
|
40 |
{
|
9629
|
41 |
int dy;
|
|
42 |
int dx;
|
|
43 |
int stepx;
|
|
44 |
int stepy;
|
|
45 |
int frac;
|
9628
|
46 |
|
9629
|
47 |
dy = (y2 - y) * 2;
|
|
48 |
if (dy < 0) {
|
|
49 |
dy = -dy;
|
|
50 |
stepy = -1;
|
|
51 |
} else {
|
|
52 |
stepy = 1;
|
|
53 |
}
|
|
54 |
|
|
55 |
dx = (x2 - x) * 2;
|
|
56 |
if (dx < 0) {
|
|
57 |
dx = -dx;
|
|
58 |
stepx = -1;
|
|
59 |
} else {
|
|
60 |
stepx = 1;
|
|
61 |
}
|
|
62 |
|
9704
|
63 |
if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
9629
|
64 |
if (dx > dy) {
|
|
65 |
frac = dy - (dx / 2);
|
|
66 |
while (x != x2) {
|
|
67 |
if (frac >= 0) {
|
|
68 |
y += stepy;
|
|
69 |
frac -= dx;
|
|
70 |
}
|
|
71 |
x += stepx;
|
|
72 |
frac += dy;
|
9704
|
73 |
if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
9629
|
74 |
}
|
|
75 |
} else {
|
|
76 |
frac = dx - (dy / 2);
|
|
77 |
while (y != y2) {
|
|
78 |
if (frac >= 0) {
|
|
79 |
x += stepx;
|
|
80 |
frac -= dy;
|
|
81 |
}
|
|
82 |
y += stepy;
|
|
83 |
frac += dx;
|
9704
|
84 |
if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, color);
|
9629
|
85 |
}
|
9628
|
86 |
}
|
|
87 |
}
|
|
88 |
|
9629
|
89 |
void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
|
9628
|
90 |
{
|
9629
|
91 |
uint8 *dst = (uint8 *)video;
|
|
92 |
uint8 *usrc = (uint8 *)src;
|
|
93 |
|
|
94 |
for (; height > 0; height--) {
|
|
95 |
memcpy(dst, usrc, width * sizeof(uint8));
|
|
96 |
usrc += width;
|
|
97 |
dst += _screen.pitch;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
|
|
102 |
{
|
9628
|
103 |
uint8 *udst = (uint8 *)dst;
|
|
104 |
uint8 *src = (uint8 *)video;
|
|
105 |
|
|
106 |
for (; height > 0; height--) {
|
9629
|
107 |
memcpy(udst, src, width * sizeof(uint8));
|
|
108 |
src += _screen.pitch;
|
|
109 |
udst += width;
|
9628
|
110 |
}
|
|
111 |
}
|
|
112 |
|
9629
|
113 |
void Blitter_8bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
|
9628
|
114 |
{
|
9629
|
115 |
uint8 *udst = (uint8 *)dst;
|
|
116 |
uint8 *src = (uint8 *)video;
|
9628
|
117 |
|
|
118 |
for (; height > 0; height--) {
|
9629
|
119 |
memcpy(udst, src, width * sizeof(uint8));
|
9628
|
120 |
src += _screen.pitch;
|
9629
|
121 |
udst += dst_pitch;
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
void Blitter_8bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
|
|
126 |
{
|
|
127 |
const uint8 *src;
|
|
128 |
uint8 *dst;
|
|
129 |
|
|
130 |
if (scroll_y > 0) {
|
|
131 |
/*Calculate pointers */
|
|
132 |
dst = (uint8 *)video + left + (top + height - 1) * _screen.pitch;
|
|
133 |
src = dst - scroll_y * _screen.pitch;
|
|
134 |
|
|
135 |
/* Decrease height and increase top */
|
|
136 |
top += scroll_y;
|
|
137 |
height -= scroll_y;
|
|
138 |
assert(height > 0);
|
|
139 |
|
|
140 |
/* Adjust left & width */
|
|
141 |
if (scroll_x >= 0) {
|
|
142 |
dst += scroll_x;
|
|
143 |
left += scroll_x;
|
|
144 |
width -= scroll_x;
|
|
145 |
} else {
|
|
146 |
src -= scroll_x;
|
|
147 |
width += scroll_x;
|
|
148 |
}
|
|
149 |
|
|
150 |
for (int h = height; h > 0; h--) {
|
|
151 |
memcpy(dst, src, width * sizeof(uint8));
|
|
152 |
src -= _screen.pitch;
|
|
153 |
dst -= _screen.pitch;
|
|
154 |
}
|
|
155 |
} else {
|
|
156 |
/* Calculate pointers */
|
|
157 |
dst = (uint8 *)video + left + top * _screen.pitch;
|
|
158 |
src = dst - scroll_y * _screen.pitch;
|
|
159 |
|
|
160 |
/* Decrese height. (scroll_y is <=0). */
|
|
161 |
height += scroll_y;
|
|
162 |
assert(height > 0);
|
|
163 |
|
|
164 |
/* Adjust left & width */
|
|
165 |
if (scroll_x >= 0) {
|
|
166 |
dst += scroll_x;
|
|
167 |
left += scroll_x;
|
|
168 |
width -= scroll_x;
|
|
169 |
} else {
|
|
170 |
src -= scroll_x;
|
|
171 |
width += scroll_x;
|
|
172 |
}
|
|
173 |
|
|
174 |
/* the y-displacement may be 0 therefore we have to use memmove,
|
|
175 |
* because source and destination may overlap */
|
|
176 |
for (int h = height; h > 0; h--) {
|
|
177 |
memmove(dst, src, width * sizeof(uint8));
|
|
178 |
src += _screen.pitch;
|
|
179 |
dst += _screen.pitch;
|
|
180 |
}
|
9628
|
181 |
}
|
|
182 |
}
|
|
183 |
|
|
184 |
int Blitter_8bppBase::BufferSize(int width, int height)
|
|
185 |
{
|
|
186 |
return width * height;
|
|
187 |
}
|
9629
|
188 |
|
|
189 |
void Blitter_8bppBase::PaletteAnimate(uint start, uint count)
|
|
190 |
{
|
|
191 |
/* Video backend takes care of the palette animation */
|
|
192 |
}
|
|
193 |
|
|
194 |
Blitter::PaletteAnimation Blitter_8bppBase::UsePaletteAnimation()
|
|
195 |
{
|
|
196 |
return Blitter::PALETTE_ANIMATION_VIDEO_BACKEND;
|
|
197 |
}
|