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