32bpp_base.cpp

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "../stdafx.h"
00013 #include "32bpp_base.hpp"
00014 
00015 void *Blitter_32bppBase::MoveTo(void *video, int x, int y)
00016 {
00017   return (uint32 *)video + x + y * _screen.pitch;
00018 }
00019 
00020 void Blitter_32bppBase::SetPixel(void *video, int x, int y, uint8 colour)
00021 {
00022   *((Colour *)video + x + y * _screen.pitch) = LookupColourInPalette(colour);
00023 }
00024 
00025 void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 colour)
00026 {
00027   Colour colour32 = LookupColourInPalette(colour);
00028 
00029   do {
00030     Colour *dst = (Colour *)video;
00031     for (int i = width; i > 0; i--) {
00032       *dst = colour32;
00033       dst++;
00034     }
00035     video = (uint32 *)video + _screen.pitch;
00036   } while (--height);
00037 }
00038 
00039 void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
00040 {
00041   uint32 *dst = (uint32 *)video;
00042   const uint32 *usrc = (const uint32 *)src;
00043 
00044   for (; height > 0; height--) {
00045     memcpy(dst, usrc, width * sizeof(uint32));
00046     usrc += width;
00047     dst += _screen.pitch;
00048   }
00049 }
00050 
00051 void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
00052 {
00053   uint32 *udst = (uint32 *)dst;
00054   const uint32 *src = (const uint32 *)video;
00055 
00056   for (; height > 0; height--) {
00057     memcpy(udst, src, width * sizeof(uint32));
00058     src += _screen.pitch;
00059     udst += width;
00060   }
00061 }
00062 
00063 void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
00064 {
00065   uint32 *udst = (uint32 *)dst;
00066   const uint32 *src = (const uint32 *)video;
00067 
00068   for (; height > 0; height--) {
00069     memcpy(udst, src, width * sizeof(uint32));
00070     src += _screen.pitch;
00071     udst += dst_pitch;
00072   }
00073 }
00074 
00075 void Blitter_32bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
00076 {
00077   const uint32 *src;
00078   uint32 *dst;
00079 
00080   if (scroll_y > 0) {
00081     /* Calculate pointers */
00082     dst = (uint32 *)video + left + (top + height - 1) * _screen.pitch;
00083     src = dst - scroll_y * _screen.pitch;
00084 
00085     /* Decrease height and increase top */
00086     top += scroll_y;
00087     height -= scroll_y;
00088     assert(height > 0);
00089 
00090     /* Adjust left & width */
00091     if (scroll_x >= 0) {
00092       dst += scroll_x;
00093       left += scroll_x;
00094       width -= scroll_x;
00095     } else {
00096       src -= scroll_x;
00097       width += scroll_x;
00098     }
00099 
00100     for (int h = height; h > 0; h--) {
00101       memcpy(dst, src, width * sizeof(uint32));
00102       src -= _screen.pitch;
00103       dst -= _screen.pitch;
00104     }
00105   } else {
00106     /* Calculate pointers */
00107     dst = (uint32 *)video + left + top * _screen.pitch;
00108     src = dst - scroll_y * _screen.pitch;
00109 
00110     /* Decrese height. (scroll_y is <=0). */
00111     height += scroll_y;
00112     assert(height > 0);
00113 
00114     /* Adjust left & width */
00115     if (scroll_x >= 0) {
00116       dst += scroll_x;
00117       left += scroll_x;
00118       width -= scroll_x;
00119     } else {
00120       src -= scroll_x;
00121       width += scroll_x;
00122     }
00123 
00124     /* the y-displacement may be 0 therefore we have to use memmove,
00125      * because source and destination may overlap */
00126     for (int h = height; h > 0; h--) {
00127       memmove(dst, src, width * sizeof(uint32));
00128       src += _screen.pitch;
00129       dst += _screen.pitch;
00130     }
00131   }
00132 }
00133 
00134 int Blitter_32bppBase::BufferSize(int width, int height)
00135 {
00136   return width * height * sizeof(uint32);
00137 }
00138 
00139 void Blitter_32bppBase::PaletteAnimate(const Palette &palette)
00140 {
00141   /* By default, 32bpp doesn't have palette animation */
00142 }
00143 
00144 Blitter::PaletteAnimation Blitter_32bppBase::UsePaletteAnimation()
00145 {
00146   return Blitter::PALETTE_ANIMATION_NONE;
00147 }