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