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