00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "../stdafx.h"
00013 #include "32bpp_base.hpp"
00014
00015 void *Blitter_32bppBase::MoveTo(const 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 *((uint32 *)video + x + y * _screen.pitch) = LookupColourInPalette(colour);
00023 }
00024
00025 void Blitter_32bppBase::SetPixelIfEmpty(void *video, int x, int y, uint8 colour)
00026 {
00027 uint32 *dst = (uint32 *)video + x + y * _screen.pitch;
00028 if (*dst == 0) *dst = LookupColourInPalette(colour);
00029 }
00030
00031 void Blitter_32bppBase::DrawRect(void *video, int width, int height, uint8 colour)
00032 {
00033 uint32 colour32 = LookupColourInPalette(colour);
00034
00035 do {
00036 uint32 *dst = (uint32 *)video;
00037 for (int i = width; i > 0; i--) {
00038 *dst = colour32;
00039 dst++;
00040 }
00041 video = (uint32 *)video + _screen.pitch;
00042 } while (--height);
00043 }
00044
00045 void Blitter_32bppBase::DrawLine(void *video, int x, int y, int x2, int y2, int screen_width, int screen_height, uint8 colour)
00046 {
00047 int dy;
00048 int dx;
00049 int stepx;
00050 int stepy;
00051 int frac;
00052
00053 dy = (y2 - y) * 2;
00054 if (dy < 0) {
00055 dy = -dy;
00056 stepy = -1;
00057 } else {
00058 stepy = 1;
00059 }
00060
00061 dx = (x2 - x) * 2;
00062 if (dx < 0) {
00063 dx = -dx;
00064 stepx = -1;
00065 } else {
00066 stepx = 1;
00067 }
00068
00069 if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour);
00070 if (dx > dy) {
00071 frac = dy - (dx / 2);
00072 while (x != x2) {
00073 if (frac >= 0) {
00074 y += stepy;
00075 frac -= dx;
00076 }
00077 x += stepx;
00078 frac += dy;
00079 if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour);
00080 }
00081 } else {
00082 frac = dx - (dy / 2);
00083 while (y != y2) {
00084 if (frac >= 0) {
00085 x += stepx;
00086 frac -= dy;
00087 }
00088 y += stepy;
00089 frac += dx;
00090 if (x >= 0 && y >= 0 && x < screen_width && y < screen_height) this->SetPixel(video, x, y, colour);
00091 }
00092 }
00093 }
00094
00095 void Blitter_32bppBase::CopyFromBuffer(void *video, const void *src, int width, int height)
00096 {
00097 uint32 *dst = (uint32 *)video;
00098 uint32 *usrc = (uint32 *)src;
00099
00100 for (; height > 0; height--) {
00101 memcpy(dst, usrc, width * sizeof(uint32));
00102 usrc += width;
00103 dst += _screen.pitch;
00104 }
00105 }
00106
00107 void Blitter_32bppBase::CopyToBuffer(const void *video, void *dst, int width, int height)
00108 {
00109 uint32 *udst = (uint32 *)dst;
00110 uint32 *src = (uint32 *)video;
00111
00112 for (; height > 0; height--) {
00113 memcpy(udst, src, width * sizeof(uint32));
00114 src += _screen.pitch;
00115 udst += width;
00116 }
00117 }
00118
00119 void Blitter_32bppBase::CopyImageToBuffer(const void *video, void *dst, int width, int height, int dst_pitch)
00120 {
00121 uint32 *udst = (uint32 *)dst;
00122 uint32 *src = (uint32 *)video;
00123
00124 for (; height > 0; height--) {
00125 memcpy(udst, src, width * sizeof(uint32));
00126 src += _screen.pitch;
00127 udst += dst_pitch;
00128 }
00129 }
00130
00131 void Blitter_32bppBase::ScrollBuffer(void *video, int &left, int &top, int &width, int &height, int scroll_x, int scroll_y)
00132 {
00133 const uint32 *src;
00134 uint32 *dst;
00135
00136 if (scroll_y > 0) {
00137
00138 dst = (uint32 *)video + left + (top + height - 1) * _screen.pitch;
00139 src = dst - scroll_y * _screen.pitch;
00140
00141
00142 top += scroll_y;
00143 height -= scroll_y;
00144 assert(height > 0);
00145
00146
00147 if (scroll_x >= 0) {
00148 dst += scroll_x;
00149 left += scroll_x;
00150 width -= scroll_x;
00151 } else {
00152 src -= scroll_x;
00153 width += scroll_x;
00154 }
00155
00156 for (int h = height; h > 0; h--) {
00157 memcpy(dst, src, width * sizeof(uint32));
00158 src -= _screen.pitch;
00159 dst -= _screen.pitch;
00160 }
00161 } else {
00162
00163 dst = (uint32 *)video + left + top * _screen.pitch;
00164 src = dst - scroll_y * _screen.pitch;
00165
00166
00167 height += scroll_y;
00168 assert(height > 0);
00169
00170
00171 if (scroll_x >= 0) {
00172 dst += scroll_x;
00173 left += scroll_x;
00174 width -= scroll_x;
00175 } else {
00176 src -= scroll_x;
00177 width += scroll_x;
00178 }
00179
00180
00181
00182 for (int h = height; h > 0; h--) {
00183 memmove(dst, src, width * sizeof(uint32));
00184 src += _screen.pitch;
00185 dst += _screen.pitch;
00186 }
00187 }
00188 }
00189
00190 int Blitter_32bppBase::BufferSize(int width, int height)
00191 {
00192 return width * height * sizeof(uint32);
00193 }
00194
00195 void Blitter_32bppBase::PaletteAnimate(uint start, uint count)
00196 {
00197
00198 }
00199
00200 Blitter::PaletteAnimation Blitter_32bppBase::UsePaletteAnimation()
00201 {
00202 return Blitter::PALETTE_ANIMATION_NONE;
00203 }