OpenTTD
32bpp_base.cpp
Go to the documentation of this file.
1 /* $Id: 32bpp_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 "32bpp_base.hpp"
14 
15 #include "../safeguards.h"
16 
17 void *Blitter_32bppBase::MoveTo(void *video, int x, int y)
18 {
19  return (uint32 *)video + x + y * _screen.pitch;
20 }
21 
22 void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8 colour)
23 {
24  *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour);
25 }
26 
27 void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 colour)
28 {
29  Colour colour32 = LookupColourInPalette(colour);
30 
31  do {
32  Colour *dst = (Colour *)video;
33  for (int i = width; i > 0; i--) {
34  *dst = colour32;
35  dst++;
36  }
37  video = (uint32 *)video + _screen.pitch;
38  } while (--height);
39 }
40 
41 void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
42 {
43  uint32 *dst = (uint32 *)video;
44  const uint32 *usrc = (const uint32 *)src;
45 
46  for (; height > 0; height--) {
47  memcpy(dst, usrc, width * sizeof(uint32));
48  usrc += width;
49  dst += _screen.pitch;
50  }
51 }
52 
53 void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
54 {
55  uint32 *udst = (uint32 *)dst;
56  const uint32 *src = (const uint32 *)video;
57 
58  for (; height > 0; height--) {
59  memcpy(udst, src, width * sizeof(uint32));
60  src += _screen.pitch;
61  udst += width;
62  }
63 }
64 
65 void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
66 {
67  uint32 *udst = (uint32 *)dst;
68  const uint32 *src = (const uint32 *)video;
69 
70  for (; height > 0; height--) {
71  memcpy(udst, src, width * sizeof(uint32));
72  src += _screen.pitch;
73  udst += dst_pitch;
74  }
75 }
76 
77 void Blitter_32bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
78 {
79  const uint32 *src;
80  uint32 *dst;
81 
82  if (scroll_y > 0) {
83  /* Calculate pointers */
84  dst = (uint32 *)video + left + (top + height - 1) * _screen.pitch;
85  src = dst - scroll_y * _screen.pitch;
86 
87  /* Decrease height and increase top */
88  top += scroll_y;
89  height -= scroll_y;
90  assert(height > 0);
91 
92  /* Adjust left & width */
93  if (scroll_x >= 0) {
94  dst += scroll_x;
95  left += scroll_x;
96  width -= scroll_x;
97  } else {
98  src -= scroll_x;
99  width += scroll_x;
100  }
101 
102  for (int h = height; h > 0; h--) {
103  memcpy(dst, src, width * sizeof(uint32));
104  src -= _screen.pitch;
105  dst -= _screen.pitch;
106  }
107  } else {
108  /* Calculate pointers */
109  dst = (uint32 *)video + left + top * _screen.pitch;
110  src = dst - scroll_y * _screen.pitch;
111 
112  /* Decrease height. (scroll_y is <=0). */
113  height += scroll_y;
114  assert(height > 0);
115 
116  /* Adjust left & width */
117  if (scroll_x >= 0) {
118  dst += scroll_x;
119  left += scroll_x;
120  width -= scroll_x;
121  } else {
122  src -= scroll_x;
123  width += scroll_x;
124  }
125 
126  /* the y-displacement may be 0 therefore we have to use memmove,
127  * because source and destination may overlap */
128  for (int h = height; h > 0; h--) {
129  memmove(dst, src, width * sizeof(uint32));
130  src += _screen.pitch;
131  dst += _screen.pitch;
132  }
133  }
134 }
135 
136 int Blitter_32bppBase::BufferSize(int width, int height)
137 {
138  return width * height * sizeof(uint32);
139 }
140 
142 {
143  /* By default, 32bpp doesn't have palette animation */
144 }
145 
147 {
149 }