author | glx |
Mon, 26 May 2008 17:40:33 +0000 | |
branch | noai |
changeset 10718 | 7e9d9e40e16f |
parent 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 |
|
10455
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9723
diff
changeset
|
3 |
/** @file 32bpp_base.cpp Implementation of base for 32 bpp blitters. */ |
22c441f5adf9
(svn r12997) [NoAI] -Sync: with trunk r12895:12996.
rubidium
parents:
9723
diff
changeset
|
4 |
|
9628 | 5 |
#include "../stdafx.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9704
diff
changeset
|
6 |
#include "../gfx_func.h" |
9628 | 7 |
#include "32bpp_base.hpp" |
8 |
||
9 |
void *Blitter_32bppBase::MoveTo(const void *video, int x, int y) |
|
10 |
{ |
|
11 |
return (uint32 *)video + x + y * _screen.pitch; |
|
12 |
} |
|
13 |
||
14 |
void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8 color) |
|
15 |
{ |
|
16 |
*((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(color); |
|
17 |
} |
|
18 |
||
19 |
void Blitter_32bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 color) |
|
20 |
{ |
|
21 |
uint32 *dst = (uint32 *)video + x + y * _screen.pitch; |
|
22 |
if (*dst == 0) *dst = LookupColourInPalette(color); |
|
23 |
} |
|
24 |
||
9629 | 25 |
void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 color) |
9628 | 26 |
{ |
27 |
uint32 color32 = LookupColourInPalette(color); |
|
28 |
||
9629 | 29 |
do { |
30 |
uint32 *dst = (uint32 *)video; |
|
31 |
for (int i = width; i > 0; i--) { |
|
32 |
*dst = color32; |
|
33 |
dst++; |
|
34 |
} |
|
35 |
video = (uint32 *)video + _screen.pitch; |
|
36 |
} while (--height); |
|
37 |
} |
|
38 |
||
39 |
void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 color) |
|
40 |
{ |
|
41 |
int dy; |
|
42 |
int dx; |
|
43 |
int stepx; |
|
44 |
int stepy; |
|
45 |
int frac; |
|
46 |
||
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_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height) |
9628 | 90 |
{ |
91 |
uint32 *dst = (uint32 *)video; |
|
92 |
uint32 *usrc = (uint32 *)src; |
|
93 |
||
94 |
for (; height > 0; height--) { |
|
95 |
memcpy(dst, usrc, width * sizeof(uint32)); |
|
9629 | 96 |
usrc += width; |
97 |
dst += _screen.pitch; |
|
9628 | 98 |
} |
99 |
} |
|
100 |
||
9629 | 101 |
void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height) |
9628 | 102 |
{ |
103 |
uint32 *udst = (uint32 *)dst; |
|
104 |
uint32 *src = (uint32 *)video; |
|
105 |
||
106 |
for (; height > 0; height--) { |
|
107 |
memcpy(udst, src, width * sizeof(uint32)); |
|
9629 | 108 |
src += _screen.pitch; |
109 |
udst += width; |
|
9628 | 110 |
} |
111 |
} |
|
112 |
||
9629 | 113 |
void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch) |
9628 | 114 |
{ |
9629 | 115 |
uint32 *udst = (uint32 *)dst; |
116 |
uint32 *src = (uint32 *)video; |
|
9628 | 117 |
|
118 |
for (; height > 0; height--) { |
|
9629 | 119 |
memcpy(udst, src, width * sizeof(uint32)); |
9628 | 120 |
src += _screen.pitch; |
9629 | 121 |
udst += dst_pitch; |
122 |
} |
|
123 |
} |
|
124 |
||
125 |
void Blitter_32bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y) |
|
126 |
{ |
|
127 |
const uint32 *src; |
|
128 |
uint32 *dst; |
|
129 |
||
130 |
if (scroll_y > 0) { |
|
131 |
/*Calculate pointers */ |
|
132 |
dst = (uint32 *)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(uint32)); |
|
152 |
src -= _screen.pitch; |
|
153 |
dst -= _screen.pitch; |
|
154 |
} |
|
155 |
} else { |
|
156 |
/* Calculate pointers */ |
|
157 |
dst = (uint32 *)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(uint32)); |
|
178 |
src += _screen.pitch; |
|
179 |
dst += _screen.pitch; |
|
180 |
} |
|
9628 | 181 |
} |
182 |
} |
|
183 |
||
184 |
int Blitter_32bppBase::BufferSize(int width, int height) |
|
185 |
{ |
|
186 |
return width * height * sizeof(uint32); |
|
187 |
} |
|
9629 | 188 |
|
189 |
void Blitter_32bppBase::PaletteAnimate(uint start, uint count) |
|
190 |
{ |
|
191 |
/* By default, 32bpp doesn't have palette animation */ |
|
192 |
} |
|
193 |
||
194 |
Blitter::PaletteAnimation Blitter_32bppBase::UsePaletteAnimation() |
|
195 |
{ |
|
196 |
return Blitter::PALETTE_ANIMATION_NONE; |
|
197 |
} |