42 #ifndef SDL_BIG_ENDIAN
43 #error missing SDL_endian.h
46 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
47 static unsigned int *
cR =
nullptr;
48 static unsigned int *
cG =
nullptr;
49 static unsigned int *
cB =
nullptr;
67 const int desiredWidth,
72 if (mWindow ==
nullptr ||
74 image->mSDLSurface ==
nullptr)
79 Image *
const tmpImage = image->SDLgetScaledImage(
80 desiredWidth, desiredHeight);
82 if ((tmpImage ==
nullptr) || (tmpImage->mSDLSurface ==
nullptr))
86 const SDL_Rect &bounds = image->mBounds;
104 SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect, mWindow, &dstRect);
119 if (mWindow ==
nullptr ||
121 image->mSDLSurface ==
nullptr)
127 const SDL_Rect &bounds = image->mBounds;
129 SDL_Surface *
const src = image->mSDLSurface;
144 const int maxw = src->w - srcX;
154 const int maxh = src->h - srcY;
158 const SDL_Rect *
const clip = &mWindow->clip_rect;
159 const int clipX = clip->x;
160 const int clipY = clip->y;
161 int dx = clipX - dstX;
168 dx = dstX + w - clipX - clip->w;
172 int dy = clipY - dstY;
179 dy = dstY + h - clipY - clip->h;
201 SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
216 if (mWindow ==
nullptr ||
218 image->mSDLSurface ==
nullptr)
224 const SDL_Rect &bounds = image->mBounds;
226 SDL_Surface *
const src = image->mSDLSurface;
241 const int maxw = src->w - srcX;
251 const int maxh = src->h - srcY;
255 const SDL_Rect *
const clip = &mWindow->clip_rect;
256 const int clipX = clip->x;
257 const int clipY = clip->y;
265 dx =
x + w - clipX - clip->w;
276 dy =
y + h - clipY - clip->h;
298 SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
303 const int x,
const int y,
308 if ((mWindow ==
nullptr) || (image ==
nullptr))
310 if (image->mSDLSurface ==
nullptr)
313 const SDL_Rect &bounds = image->mBounds;
314 const
int iw = bounds.w;
315 const
int ih = bounds.h;
316 if (iw == 0 || ih == 0)
320 const
int xOffset =
top.xOffset +
x;
321 const
int yOffset =
top.yOffset +
y;
322 const
int srcX = bounds.
x;
323 const
int srcY = bounds.
y;
324 SDL_Surface *const src = image->mSDLSurface;
325 const SDL_Rect *const clip = &mWindow->clip_rect;
326 const
int clipX = clip->
x;
327 const
int clipY = clip->
y;
329 for (
int py = 0; py < h; py += ih)
331 const int dh = (py + ih >= h) ? h - py : ih;
332 int dstY = py + yOffset;
341 const int maxh = src->h - y2;
345 int dy = clipY - dstY;
352 dy = dstY + h2 - clipY - clip->h;
358 for (
int px = 0; px < w; px += iw)
360 const int dw = (px + iw >= w) ? w - px : iw;
361 int dstX = px + xOffset;
370 const int maxw = src->w - x2;
374 int dx = clipX - dstX;
381 dx = dstX + w2 - clipX - clip->w;
403 SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
417 const int x,
const int y,
424 const int x,
const int y,
429 if ((mWindow ==
nullptr) || (image ==
nullptr))
431 if (image->mSDLSurface ==
nullptr)
434 const SDL_Rect &bounds = image->mBounds;
435 const
int iw = bounds.w;
436 const
int ih = bounds.h;
437 if (iw == 0 || ih == 0)
441 const
int xOffset =
top.xOffset +
x;
442 const
int yOffset =
top.yOffset +
y;
443 const
int srcX = bounds.
x;
444 const
int srcY = bounds.
y;
445 SDL_Surface *const src = image->mSDLSurface;
446 const SDL_Rect *const clip = &mWindow->clip_rect;
447 const
int clipX = clip->
x;
448 const
int clipY = clip->
y;
450 for (
int py = 0; py < h; py += ih)
452 const int dh = (py + ih >= h) ? h - py : ih;
453 int dstY = py + yOffset;
462 const int maxh = src->h - y2;
466 int dy = clipY - dstY;
473 dy = dstY + h2 - clipY - clip->h;
479 for (
int px = 0; px < w; px += iw)
481 const int dw = (px + iw >= w) ? w - px : iw;
482 int dstX = px + xOffset;
491 const int maxw = src->w - x2;
495 int dx = clipX - dstX;
502 dx = dstX + w2 - clipX - clip->w;
524 SDL_LowerBlit(src, &srcRect, mWindow, &dstRect);
534 const int x,
const int y,
535 const int w,
const int h,
536 const int scaledWidth,
540 if ((mWindow ==
nullptr) || (image ==
nullptr))
542 if (image->mSDLSurface ==
nullptr)
545 if (scaledHeight == 0 || scaledWidth == 0)
548 Image *
const tmpImage = image->SDLgetScaledImage(
549 scaledWidth, scaledHeight);
550 if (tmpImage ==
nullptr)
553 const SDL_Rect &bounds = tmpImage->mBounds;
554 const int iw = bounds.w;
555 const int ih = bounds.h;
556 if (iw == 0 || ih == 0)
560 const int xOffset =
top.xOffset +
x;
561 const int yOffset =
top.yOffset +
y;
562 const int srcX = bounds.x;
563 const int srcY = bounds.y;
565 for (
int py = 0; py < h; py += ih)
567 const int dh = (py + ih >= h) ? h - py : ih;
568 const int dstY = py + yOffset;
570 for (
int px = 0; px < w; px += iw)
572 const int dw = (px + iw >= w) ? w - px : iw;
573 const int dstX = px + xOffset;
591 SDL_BlitSurface(tmpImage->mSDLSurface, &srcRect,
601 const int x,
const int y,
602 const int w,
const int h)
const restrict2
609 const int x,
const int y,
610 const int w,
const int h)
const restrict2
613 if (vert ==
nullptr ||
614 mWindow ==
nullptr ||
616 image->mSDLSurface ==
nullptr)
621 const SDL_Rect &bounds = image->mBounds;
622 const int iw = bounds.w;
623 const int ih = bounds.h;
624 if (iw == 0 || ih == 0)
628 const int xOffset =
top.xOffset +
x;
629 const int yOffset =
top.yOffset +
y;
630 const int srcX = bounds.x;
631 const int srcY = bounds.y;
633 for (
int py = 0; py < h; py += ih)
635 const int dh = (py + ih >= h) ? h - py : ih;
636 const int dstY = py + yOffset;
638 for (
int px = 0; px < w; px += iw)
640 const int dw = (px + iw >= w) ? w - px : iw;
641 const int dstX = px + xOffset;
644 SDL_Rect &srcRect = r->
src;
649 SDL_Rect &dstRect = r->
dst;
653 if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect,
654 mWindow, &dstRect) == 1)
656 vert->sdl.push_back(r);
668 const int x,
const int y,
669 const int w,
const int h)
const restrict2
671 if (vertCol ==
nullptr || image ==
nullptr)
675 if (vertCol->currentImage != image)
678 vertCol->currentImage = image;
679 vertCol->currentVert = vert;
681 vertCol->draws.push_back(vert);
685 vert = vertCol->currentVert;
711 if (vert ==
nullptr ||
712 vert->
image ==
nullptr ||
713 vert->
image->mSDLSurface ==
nullptr)
720 const SDL_Rect &bounds = image->mBounds;
729 if (SDL_FakeUpperBlit(image->mSDLSurface, &rect->
src,
730 mWindow, &rect->
dst) == 1)
732 vert->
sdl.push_back(rect);
744 if (vertCol ==
nullptr)
746 if (vertCol->currentImage != image)
749 vertCol->currentImage = image;
750 vertCol->currentVert = vert;
752 vertCol->draws.push_back(vert);
771 DoubleRects::const_iterator it2 = rects->begin();
772 const DoubleRects::const_iterator it2_end = rects->end();
773 while (it2 != it2_end)
775 SDL_LowerBlit(img->mSDLSurface, &(*it2)->src,
776 mWindow, &(*it2)->dst);
790 DoubleRects::const_iterator it = rects->begin();
791 const DoubleRects::const_iterator it_end = rects->end();
794 SDL_LowerBlit(img->mSDLSurface, &(*it)->src, mWindow, &(*it)->dst);
815 const int x,
const int y,
816 const int w,
const int h,
820 Image *
const image = imgRect.grid[4];
821 if (image ==
nullptr)
823 if (vertCol->currentImage != image)
826 vertCol->currentImage = image;
827 vertCol->currentVert = vert;
829 vertCol->draws.push_back(vert);
833 vert = vertCol->currentVert;
840 const SDL_Surface *
restrict const dst,
849 if ((src ==
nullptr) || (dst ==
nullptr))
852 if ((srcrect ==
nullptr) || (dstrect ==
nullptr))
863 int maxw = src->w - srcx;
875 int maxh = src->h - srcy;
879 const SDL_Rect *
const clip = &dst->clip_rect;
880 const int clipX = clip->x;
881 const int clipY = clip->y;
882 int dx = clipX - dstrect->x;
889 dx = dstrect->x + w - clipX - clip->w;
893 int dy = clipY - dstrect->y;
900 dy = dstrect->y + h - clipY - clip->h;
916 dstrect->w = dstrect->h = 0;
928 Rect area = rectangle;
929 area.
x +=
top.xOffset;
930 area.
y +=
top.yOffset;
932 if (!area.isIntersecting(
top))
937 const int x1 = area.x >
top.x ? area.x :
top.x;
938 const int y1 = area.y >
top.y ? area.y :
top.y;
939 const int x2 = area.x + area.width <
top.x +
top.width ?
940 area.x + area.width :
top.x +
top.width;
941 const int y2 = area.y + area.height <
top.y +
top.height ?
942 area.y + area.height :
top.y +
top.height;
944 SDL_LockSurface(mWindow);
946 const int bpp = mWindow->format->BytesPerPixel;
947 const uint32_t pixel = SDL_MapRGB(mWindow->format,
954 for (
int y = y1;
y < y2;
y++)
956 uint8_t *
const p =
static_cast<uint8_t *
>(mWindow->pixels)
958 for (
int x = x1;
x < x2;
x++)
966 for (
int y = y1;
y < y2;
y++)
968 uint8_t *
const p0 =
static_cast<uint8_t *
>(mWindow->pixels)
970 for (
int x = x1;
x < x2;
x++)
973 *
reinterpret_cast<uint16_t *
>(p) =
SDLAlpha16(
975 *
reinterpret_cast<uint16_t *
>(p),
976 CAST_U8(mColor.a), mWindow->format);
982 const int ca = 255 - mColor.a;
983 const int cr = mColor.r * mColor.a;
984 const int cg = mColor.g * mColor.a;
985 const int cb = mColor.b * mColor.a;
987 for (
int y = y1;
y < y2;
y++)
989 uint8_t *
const p0 =
static_cast<uint8_t *
>(mWindow->pixels)
991 for (
int x = x1;
x < x2;
x++)
994 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
995 p[2] =
CAST_U8((p[2] * ca + cb) >> 8);
996 p[1] =
CAST_U8((p[1] * ca + cg) >> 8);
997 p[0] =
CAST_U8((p[0] * ca + cr) >> 8);
999 p[0] =
CAST_U8((p[0] * ca + cb) >> 8);
1000 p[1] =
CAST_U8((p[1] * ca + cg) >> 8);
1001 p[2] =
CAST_U8((p[2] * ca + cr) >> 8);
1009 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1010 const unsigned pb = (pixel & 0xff) * mColor.a;
1011 const unsigned pg = (pixel & 0xff00) * mColor.a;
1012 const unsigned pr = (pixel & 0xff0000) * mColor.a;
1013 const unsigned a1 = (255 - mColor.a);
1015 for (
int y = y1;
y < y2;
y++)
1017 uint8_t *
const p0 =
static_cast<uint8_t *
>(mWindow->pixels)
1018 +
y * mWindow->pitch;
1019 for (
int x = x1;
x < x2;
x++)
1021 uint8_t *p = p0 +
x * 4;
1022 uint32_t dst = *
reinterpret_cast<uint32_t *
>(p);
1023 const unsigned int b = (pb + (dst & 0xff) * a1) >> 8;
1024 const unsigned int g = (pg + (dst & 0xff00) * a1) >> 8;
1025 const unsigned int r = (pr
1026 + (dst & 0xff0000) * a1) >> 8;
1028 *
reinterpret_cast<uint32_t *
>(p) = ((b & 0xff)
1029 | (g & 0xff00) | (r & 0xff0000));
1035 cR =
new unsigned int[0x100];
1036 cG =
new unsigned int[0x100];
1037 cB =
new unsigned int[0x100];
1039 mOldAlpha = mColor.a;
1042 const SDL_PixelFormat *
const format = mWindow->format;
1043 const unsigned rMask = format->Rmask;
1044 const unsigned gMask = format->Gmask;
1045 const unsigned bMask = format->Bmask;
1047 unsigned rShift = rMask / 0xff;
1048 unsigned gShift = gMask / 0xff;
1049 unsigned bShift = bMask / 0xff;
1056 if (pixel != mOldPixel || mColor.a != mOldAlpha)
1058 const unsigned pb = (pixel & bMask) * mColor.a;
1059 const unsigned pg = (pixel & gMask) * mColor.a;
1060 const unsigned pr = (pixel & rMask) * mColor.a;
1061 const unsigned a0 = 255 - mColor.a;
1063 const unsigned int a1 = a0 * bShift;
1064 const unsigned int a2 = a0 * gShift;
1065 const unsigned int a3 = a0 * rShift;
1067 for (
int f = 0; f <= 0xff; f ++)
1069 cB[f] = ((pb + f * a1) >> 8) & bMask;
1070 cG[f] = ((pg + f * a2) >> 8) & gMask;
1071 cR[f] = ((pr + f * a3) >> 8) & rMask;
1075 mOldAlpha = mColor.a;
1078 for (
int y = y1;
y < y2;
y++)
1080 uint32_t *
const p0 =
reinterpret_cast<uint32_t*
>(
1081 static_cast<uint8_t*
>(mWindow->pixels)
1083 for (
int x = x1;
x < x2;
x++)
1086 const uint32_t dst = *p;
1087 *p =
cB[dst & bMask / bShift]
1088 |
cG[(dst & gMask) / gShift]
1089 |
cR[(dst & rMask) / rShift];
1099 SDL_UnlockSurface(mWindow);
1111 const uint32_t color = SDL_MapRGBA(mWindow->format,
1116 SDL_FillRect(mWindow, &rect, color);
1134 const SDL_Rect rect =
1141 SDL_SetClipRect(mWindow, &rect);
1152 const SDL_Rect rect =
1160 SDL_SetClipRect(
mWindow, &rect);
1165 if (mClipStack.empty())
1173 if (!
top.isPointInRect(
x,
y))
1184 if (mClipStack.empty())
1189 const int xOffset =
top.xOffset;
1194 const int topY =
top.y;
1195 if (y < topY || y >= topY +
top.height)
1205 const int topX =
top.x;
1214 const int sumX = topX +
top.width;
1223 const int bpp = mWindow->format->BytesPerPixel;
1225 SDL_LockSurface(mWindow);
1227 uint8_t *p =
static_cast<uint8_t*
>(mWindow->pixels)
1230 const uint32_t pixel = SDL_MapRGB(mWindow->format,
1237 for (; x1 <= x2; ++x1)
1243 uint16_t* q =
reinterpret_cast<uint16_t*
>(p);
1244 const uint16_t pixel1 =
CAST_U16(pixel);
1245 for (; x1 <= x2; ++x1)
1252 const uint8_t b0 =
CAST_U8((pixel >> 16) & 0xff);
1253 const uint8_t b1 =
CAST_U8((pixel >> 8) & 0xff);
1254 const uint8_t b2 =
CAST_U8(pixel & 0xff);
1255 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1256 for (; x1 <= x2; ++x1)
1264 for (; x1 <= x2; ++x1)
1277 uint32_t *q =
reinterpret_cast<uint32_t*
>(p);
1280 unsigned char a =
CAST_U8(mColor.a);
1281 unsigned char a1 =
CAST_U8(255U - a);
1282 const int b0 = (pixel & 0xff) * a;
1283 const int g0 = (pixel & 0xff00) * a;
1284 const int r0 = (pixel & 0xff0000) * a;
1285 for (; x1 <= x2; ++x1)
1287 const unsigned int b = (b0 + (*q & 0xff) * a1) >> 8;
1288 const unsigned int g = (g0 + (*q & 0xff00) * a1) >> 8;
1289 const unsigned int r = (r0 + (*q & 0xff0000) * a1) >> 8;
1290 *q = (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
1297 for (; x1 <= x2; ++x1)
1306 SDL_UnlockSurface(mWindow);
1311 if (mClipStack.empty())
1316 const int yOffset =
top.yOffset;
1321 if (x < top.x || x >=
top.x +
top.width)
1339 const int sumY =
top.y +
top.height;
1348 const int bpp = mWindow->format->BytesPerPixel;
1350 SDL_LockSurface(mWindow);
1352 uint8_t *p =
static_cast<uint8_t*
>(mWindow->pixels)
1355 const uint32_t pixel = SDL_MapRGB(mWindow->format,
1360 const int pitch = mWindow->pitch;
1364 for (; y1 <= y2; ++y1)
1372 for (; y1 <= y2; ++ y1)
1374 *
reinterpret_cast<uint16_t*
>(p)
1382 const uint8_t b0 =
CAST_U8((pixel >> 16) & 0xff);
1383 const uint8_t b1 =
CAST_U8((pixel >> 8) & 0xff);
1384 const uint8_t b2 =
CAST_U8(pixel & 0xff);
1385 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
1386 for (; y1 <= y2; ++y1)
1394 for (; y1 <= y2; ++y1)
1409 unsigned char a =
CAST_U8(mColor.a);
1410 unsigned char a1 =
CAST_U8(255U - a);
1411 const int b0 = (pixel & 0xff) * a;
1412 const int g0 = (pixel & 0xff00) * a;
1413 const int r0 = (pixel & 0xff0000) * a;
1414 for (; y1 <= y2; ++y1)
1416 const unsigned int dst = *
reinterpret_cast<uint32_t*
>(p);
1417 const unsigned int b = (b0 + (dst & 0xff) * a1) >> 8;
1418 const unsigned int g = (g0 + (dst & 0xff00) * a1) >> 8;
1419 const unsigned int r = (r0 + (dst & 0xff0000) * a1) >> 8;
1420 *
reinterpret_cast<uint32_t*
>(p) =
1421 (b & 0xff) | (g & 0xff00) | (r & 0xff0000);
1428 for (; y1 <= y2; ++y1)
1430 *
reinterpret_cast<uint32_t*
>(p) = pixel;
1441 SDL_UnlockSurface(mWindow);
1446 const int x1 = rectangle.x;
1447 const int x2 = x1 + rectangle.width - 1;
1448 const int y1 = rectangle.y;
1449 const int y2 = y1 + rectangle.height - 1;
1451 drawHLine(x1, y1, x2);
1452 drawHLine(x1, y2, x2);
1454 drawVLine(x1, y1, y2);
1455 drawVLine(x2, y1, y2);
1463 drawVLine(x1, y1, y2);
1468 drawHLine(x1, y1, x2);
1494 getSoftwareFlags())) ==
nullptr)
1508 const int w,
const int h,
1515 const int x,
const int y,
1516 const int w,
const int h,
static SDL_Surface * createWindow(const int w, const int h, const int bpp, const int flags)
virtual void updateScreen()=0
virtual void drawImage(const Image *const image, int dstX, int dstY)=0
virtual void popClipArea()
virtual void drawRescaledPattern(const Image *const image, const int x, const int y, const int w, const int h, const int scaledWidth, const int scaledHeight)=0
virtual void drawTileCollection(const ImageCollection *const vertCol)=0
virtual bool setVideoMode(const int w, const int h, const int scale, const int bpp, const bool fs, const bool hwaccel, const bool resize, const bool noFrame, const bool allowHighDPI)=0
virtual void fillRectangle(const Rect &rectangle)=0
virtual void calcTileCollection(ImageCollection *const vertCol, const Image *const image, int x, int y)=0
virtual void drawImageCached(const Image *const image, int srcX, int srcY)=0
virtual void calcPattern(ImageVertexes *const vert, const Image *const image, const int x, const int y, const int w, const int h) const =0
virtual void calcTileSDL(ImageVertexes *const vert, int x, int y) const
virtual void drawRectangle(const Rect &rectangle)=0
MStack< ClipRect > mClipStack
virtual void calcWindow(ImageCollection *const vertCol, const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
virtual void drawLine(int x1, int y1, int x2, int y2)=0
virtual void calcTileVertexes(ImageVertexes *const vert, const Image *const image, int x, int y) const =0
virtual void drawPattern(const Image *const image, const int x, const int y, const int w, const int h)=0
virtual void drawPoint(int x, int y)=0
virtual void drawImageRect(const int x, const int y, const int w, const int h, const ImageRect &imgRect)=0
virtual void copyImage(const Image *const image, int dstX, int dstY)=0
virtual void pushClipArea(const Rect &area)
virtual void drawTileVertexes(const ImageVertexes *const vert)=0
virtual void drawPatternCached(const Image *const image, const int x, const int y, const int w, const int h)=0
virtual void completeCache()=0
virtual void drawRescaledImage(const Image *const image, int dstX, int dstY, const int desiredWidth, const int desiredHeight)=0
int SDL_FakeUpperBlit(const SDL_Surface *const src, SDL_Rect *const srcrect, const SDL_Surface *const dst, SDL_Rect *dstrect) const
void drawVLine(int x, int y1, int y2)
void drawHLine(int x1, int y, int x2)
const Image *restrict const top
void calcPatternInline(ImageVertexes *restrict const vert, const Image *restrict const image, const int x, const int y, const int w, const int h) const restrict2 A_INLINE
void drawPatternInline(const Image *restrict const image, const int x, const int y, const int w, const int h) restrict2 A_INLINE
void void drawImageInline(const Image *restrict const image, int dstX, int dstY) restrict2 A_INLINE
void calcTileVertexesInline(ImageVertexes *restrict const vert, const Image *restrict const image, int x, int y) const restrict2 A_INLINE A_NONNULL(2
void calcImageRect(ImageVertexes *restrict const vert, int x, int y, int w, int h, const ImageRect &restrict imgRect) restrict2 A_INLINE
std::vector< ImageVertexes * > ImageVertexesVector
std::vector< DoubleRect * > DoubleRects
ImageVertexesVector::const_iterator ImageCollectionCIter
#define FUNC_BLOCK(name, id)
#define BLOCK_START(name)
void SDLputPixelAlpha(SDL_Surface *surface, int x, int y, const Color &color)
void SDLputPixel(SDL_Surface *surface, int x, int y, const Color &color)
unsigned short SDLAlpha16(const unsigned short src, const unsigned short dst, const unsigned char a, const SDL_PixelFormat *const f)
void calcTileSDL(ImageVertexes *restrict const vert, int x, int y) const restrict2 override final