OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

8bpp_base.cpp
Go to the documentation of this file.
1 /* $Id: 8bpp_base.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD 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.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #include "../stdafx.h"
13 #include "../gfx_func.h"
14 #include "8bpp_base.hpp"
15
16 #include "../safeguards.h"
17
18 void Blitter_8bppBase::DrawColourMappingRect(void *dst, int width, int height, PaletteID pal)
19 {
20 const uint8 *ctab = GetNonSprite(pal, ST_RECOLOUR) + 1;
21
22 do {
23 for (int i = 0; i != width; i++) *((uint8 *)dst + i) = ctab[((uint8 *)dst)[i]];
24 dst = (uint8 *)dst + _screen.pitch;
25 } while (--height);
26 }
27
28 void *Blitter_8bppBase::MoveTo(void *video, int x, int y)
29 {
30 return (uint8 *)video + x + y * _screen.pitch;
31 }
32
33 void Blitter_8bppBase::SetPixel(void *video, int x, int y, uint8 colour)
34 {
35 *((uint8 *)video + x + y * _screen.pitch) = colour;
36 }
37
38 void Blitter_8bppBase::DrawRect(void *video, int width, int height, uint8 colour)
39 {
40 do {
41 memset(video, colour, width);
42 video = (uint8 *)video + _screen.pitch;
43 } while (--height);
44 }
45
46 void Blitter_8bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
47 {
48 uint8 *dst = (uint8 *)video;
49 const uint8 *usrc = (const uint8 *)src;
50
51 for (; height > 0; height--) {
52 memcpy(dst, usrc, width * sizeof(uint8));
53 usrc += width;
54 dst += _screen.pitch;
55 }
56 }
57
58 void Blitter_8bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
59 {
60 uint8 *udst = (uint8 *)dst;
61 const uint8 *src = (const uint8 *)video;
62
63 for (; height > 0; height--) {
64 memcpy(udst, src, width * sizeof(uint8));
65 src += _screen.pitch;
66 udst += width;
67 }
68 }
69
70 void Blitter_8bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
71 {
72 uint8 *udst = (uint8 *)dst;
73 const uint8 *src = (const uint8 *)video;
74
75 for (; height > 0; height--) {
76 memcpy(udst, src, width * sizeof(uint8));
77 src += _screen.pitch;
78 udst += dst_pitch;
79 }
80 }
81
82 void Blitter_8bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
83 {
84 const uint8 *src;
85 uint8 *dst;
86
87 if (scroll_y > 0) {
88 /* Calculate pointers */
89 dst = (uint8 *)video + left + (top + height - 1) * _screen.pitch;
90 src = dst - scroll_y * _screen.pitch;
91
92 /* Decrease height and increase top */
93 top += scroll_y;
94 height -= scroll_y;
95 assert(height > 0);
96
97 /* Adjust left & width */
98 if (scroll_x >= 0) {
99 dst += scroll_x;
100 left += scroll_x;
101 width -= scroll_x;
102 } else {
103 src -= scroll_x;
104 width += scroll_x;
105 }
106
107 for (int h = height; h > 0; h--) {
108 memcpy(dst, src, width * sizeof(uint8));
109 src -= _screen.pitch;
110 dst -= _screen.pitch;
111 }
112 } else {
113 /* Calculate pointers */
114 dst = (uint8 *)video + left + top * _screen.pitch;
115 src = dst - scroll_y * _screen.pitch;
116
117 /* Decrease height. (scroll_y is <=0). */
118 height += scroll_y;
119 assert(height > 0);
120
121 /* Adjust left & width */
122 if (scroll_x >= 0) {
123 dst += scroll_x;
124 left += scroll_x;
125 width -= scroll_x;
126 } else {
127 src -= scroll_x;
128 width += scroll_x;
129 }
130
131 /* the y-displacement may be 0 therefore we have to use memmove,
132 * because source and destination may overlap */
133 for (int h = height; h > 0; h--) {
134 memmove(dst, src, width * sizeof(uint8));
135 src += _screen.pitch;
136 dst += _screen.pitch;
137 }
138 }
139 }
140
141 int Blitter_8bppBase::BufferSize(int width, int height)
142 {
143 return width * height;
144 }
145
146 void Blitter_8bppBase::PaletteAnimate(const Palette &palette)
147 {
148 /* Video backend takes care of the palette animation */
149 }
150
151 Blitter::PaletteAnimation Blitter_8bppBase::UsePaletteAnimation()
152 {
153 return Blitter::PALETTE_ANIMATION_VIDEO_BACKEND;
154 }