22 #ifndef AGS_LIB_ALLEGRO_SURFACE_H 23 #define AGS_LIB_ALLEGRO_SURFACE_H 25 #include "graphics/managed_surface.h" 26 #include "ags/lib/allegro/base.h" 27 #include "ags/lib/allegro/color.h" 28 #include "common/array.h" 57 unsigned char *getPixels()
const {
58 return (
unsigned char *)_owner->
getPixels();
61 unsigned char *getBasePtr(uint16 x, uint16 y)
const {
62 return (
unsigned char *)_owner->
getBasePtr(x, y);
65 uint getTransparentColor()
const {
78 int getpixel(
int x,
int y)
const;
99 void hLine(
int x,
int y,
int x2, uint32 color) {
100 _owner->
hLine(x, y, x2, color);
106 void vLine(
int x,
int y,
int y2, uint32 color) {
107 _owner->
vLine(x, y, y2, color);
114 int dstX,
int dstY,
bool horizFlip,
bool vertFlip,
115 bool skipTrans,
int srcAlpha,
int tintRed = -1,
int tintGreen = -1,
122 const Common::Rect &destRect,
bool skipTrans,
int srcAlpha);
124 inline bool isSubBitmap()
const {
134 void blendPixel(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha,
bool useTint, byte *destVal)
const;
136 inline void rgbBlend(uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
143 uint32 x = ((uint32)rSrc << 16) | ((uint32)gSrc << 8) | (uint32)bSrc;
144 uint32 y = ((uint32)rDest << 16) | ((uint32)gDest << 8) | (uint32)bDest;
146 uint32 res = ((x & 0xFF00FF) - (y & 0xFF00FF)) * alpha / 256 + y;
149 uint32 g = (x - y) * alpha / 256 + y;
151 rDest = (res >> 16) & 0xff;
152 gDest = (g >> 8) & 0xff;
156 inline void argbBlend(uint32 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest)
const {
171 double sAlpha = (double)(aSrc & 0xff) / 255.0;
172 double dAlpha = (double)aDest / 255.0;
173 dAlpha *= (1.0 - sAlpha);
174 rDest =
static_cast<uint8
>((rSrc * sAlpha + rDest * dAlpha) / (sAlpha + dAlpha));
175 gDest =
static_cast<uint8
>((gSrc * sAlpha + gDest * dAlpha) / (sAlpha + dAlpha));
176 bDest =
static_cast<uint8
>((bSrc * sAlpha + bDest * dAlpha) / (sAlpha + dAlpha));
177 aDest =
static_cast<uint8
>(255. * (sAlpha + dAlpha));
181 inline void blendRgbToRgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
183 rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, alpha);
190 inline void blendPreserveAlpha(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
193 rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, alpha);
198 inline void blendArgbToArgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
203 alpha = aSrc * ((alpha & 0xff) + 1) / 256;
205 argbBlend(alpha, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest);
209 inline void blendRgbToArgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
211 if (alpha == 0 || alpha == 0xff) {
217 argbBlend(alpha, rSrc, gSrc, bSrc, aDest, rDest, gDest, bDest);
221 inline void blendArgbToRgb(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
226 alpha = aSrc * ((alpha & 0xff) + 1) / 256;
227 rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, alpha);
234 inline void blendOpaque(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
243 inline void blendSourceAlpha(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
246 rgbBlend(rSrc, gSrc, bSrc, rDest, gDest, bDest, aSrc);
253 inline void blendAdditiveAlpha(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha)
const {
258 uint32 a = (uint32)aSrc + (uint32)aDest;
262 aDest =
static_cast<uint8
>(a);
266 void blendTintSprite(uint8 aSrc, uint8 rSrc, uint8 gSrc, uint8 bSrc, uint8 &aDest, uint8 &rDest, uint8 &gDest, uint8 &bDest, uint32 alpha,
bool light)
const;
268 friend class DrawInnerImpl_AVX2;
269 friend class DrawInnerImpl_SSE2;
270 friend class DrawInnerImpl_NEON;
272 constexpr
static int SCALE_THRESHOLD_BITS = 8;
273 constexpr
static int SCALE_THRESHOLD = 1 << SCALE_THRESHOLD_BITS;
274 struct DrawInnerArgs {
275 const bool useTint, horizFlip, vertFlip, skipTrans;
276 bool sameFormat, shouldDraw;
277 int xStart, yStart, srcAlpha, tintRed, tintGreen, tintBlue, scaleX, scaleY;
278 uint32 transColor, alphaMask;
281 BlenderMode blenderMode;
285 const ::Graphics::ManagedSurface &src;
288 DrawInnerArgs(
BITMAP *dstBitmap,
const BITMAP *srcBitmap,
290 bool skipTrans,
int srcAlpha,
bool horizFlip,
291 bool vertFlip,
int tintRed,
int tintGreen,
int tintBlue,
296 void drawGeneric(DrawInnerArgs &args);
299 void drawNEON(DrawInnerArgs &args);
303 void drawSSE2(DrawInnerArgs &args);
307 void drawAVX2(DrawInnerArgs &args);
309 template<
int DestBytesPerPixel,
int SrcBytesPerPixel,
bool Scale>
310 void drawInnerGeneric(DrawInnerArgs &args);
312 inline uint32 getColor(
const byte *data, byte bpp)
const {
317 return *(
const uint16 *)data;
319 return *(
const uint32 *)data;
321 error(
"Unsupported format in BITMAP::getColor");
335 setTransparentColor(pixelFormat.
RGBToColor(255, 0, 255));
343 ~Surface()
override {
347 BITMAP *create_bitmap(
int width,
int height);
348 BITMAP *create_bitmap_ex(
int color_depth,
int width,
int height);
349 BITMAP *create_sub_bitmap(
BITMAP *parent,
int x,
int y,
int width,
int height);
350 BITMAP *create_video_bitmap(
int width,
int height);
351 BITMAP *create_system_bitmap(
int width,
int height);
352 void destroy_bitmap(
BITMAP *bitmap);
void clear(uint32 color=0)
Definition: managed_surface.h:51
void floodfill(int x, int y, int color)
DisposeAfterUse::Flag disposeAfterUse() const
Definition: managed_surface.h:217
const void * getBasePtr(int x, int y) const
Definition: managed_surface.h:250
void vLine(int x, int y, int y2, uint32 color)
Definition: surface.h:106
void vLine(int x, int y, int y2, uint32 color)
Definition: managed_surface.h:746
void hLine(int x, int y, int x2, uint32 color)
Definition: surface.h:99
void draw(const BITMAP *srcBitmap, const Common::Rect &srcRect, int dstX, int dstY, bool horizFlip, bool vertFlip, bool skipTrans, int srcAlpha, int tintRed=-1, int tintGreen=-1, int tintBlue=-1)
void * getPixels()
Definition: managed_surface.h:269
Definition: surface.h:329
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
const Common::Point getOffsetFromOwner() const
Definition: managed_surface.h:321
void circlefill(int x, int y, int radius, int color)
PixelFormat & format
Definition: managed_surface.h:120
void hLine(int x, int y, int x2, uint32 color)
Definition: managed_surface.h:738
void stretchDraw(const BITMAP *srcBitmap, const Common::Rect &srcRect, const Common::Rect &destRect, bool skipTrans, int srcAlpha)