Rework ChoosePylonPosition to simplify the loop
[openttd/fttd.git] / src / blitter / 32bpp_noanim.cpp
blobe198420a3fbdbaf39d9a3fee7edc85e1ba3fc240
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file 32bpp_noanim.cpp 32bpp blitter without animation support. */
10 #include "../stdafx.h"
11 #include "../debug.h"
12 #include "32bpp_noanim.hpp"
14 #include "../table/sprites.h"
16 void Blitter_32bppNoanim::Surface::set_pixel (void *video, int x, int y, uint8 colour)
18 *(this->movep <Colour> (video, x, y)) = LookupColourInPalette (colour);
21 void Blitter_32bppNoanim::Surface::draw_rect (void *video, int width, int height, uint8 colour)
23 Colour colour32 = LookupColourInPalette (colour);
25 do {
26 Colour *dst = (Colour *)video;
27 for (int i = width; i > 0; i--) {
28 *dst = colour32;
29 dst++;
31 video = (uint32 *)video + this->pitch;
32 } while (--height);
35 void Blitter_32bppNoanim::Surface::recolour_rect (void *dst, int width, int height, PaletteID pal)
37 Colour *udst = (Colour *)dst;
39 if (pal == PALETTE_TO_TRANSPARENT) {
40 do {
41 for (int i = 0; i != width; i++) {
42 *udst = MakeTransparent (*udst, 154);
43 udst++;
45 udst = udst - width + this->pitch;
46 } while (--height);
47 return;
49 if (pal == PALETTE_NEWSPAPER) {
50 do {
51 for (int i = 0; i != width; i++) {
52 *udst = MakeGrey (*udst);
53 udst++;
55 udst = udst - width + this->pitch;
56 } while (--height);
57 return;
60 DEBUG(misc, 0, "32bpp blitter doesn't know how to draw this colour table ('%d')", pal);
63 void Blitter_32bppNoanim::Surface::draw_checker (void *video, uint width, uint height, uint8 colour, byte bo)
65 Colour colour32 = LookupColourInPalette (colour);
66 Colour *dst = (Colour *) video;
67 uint i = bo;
68 do {
69 for (i = !(i & 1); i < width; i += 2) dst[i] = colour32;
70 dst += this->pitch;
71 } while (--height > 0);
74 void Blitter_32bppNoanim::Surface::copy (Buffer *dst, int x, int y, uint width, uint height)
76 dst->resize (width, height, sizeof(uint32));
77 /* Only change buffer capacity? */
78 if ((x < 0) || (y < 0)) return;
80 dst->width = width;
81 dst->height = height;
83 byte *udst = &dst->data.front();
84 const uint32 *src = (const uint32 *) this->Blitter_32bppNoanim::Surface::move (this->ptr, x, y);
86 for (; height > 0; height--) {
87 memcpy (udst, src, width * sizeof(uint32));
88 udst += width * sizeof(uint32);
89 src += this->pitch;
92 /* Sanity check that we did not overrun the buffer. */
93 assert (udst <= &dst->data.front() + dst->data.size());
96 void Blitter_32bppNoanim::Surface::paste (const Buffer *src, int x, int y)
98 uint32 *dst = (uint32 *) this->Blitter_32bppNoanim::Surface::move (this->ptr, x, y);
99 const byte *usrc = &src->data.front();
101 const uint width = src->width;
102 for (uint height = src->height; height > 0; height--) {
103 memcpy (dst, usrc, width * sizeof(uint32));
104 usrc += width * sizeof(uint32);
105 dst += this->pitch;