32 #include <SDL2/SDL_version.h>
34 #include <boost/circular_buffer.hpp>
35 #include <boost/math/constants/constants.hpp>
38 #define ERR_DP LOG_STREAM(err, log_display)
42 SDL_version sdl_version;
43 SDL_GetVersion(&sdl_version);
44 return version_info(sdl_version.major, sdl_version.minor, sdl_version.patch);
51 if(ver.major < major)
return false;
52 if(ver.major > major)
return true;
54 if(ver.minor < minor)
return false;
55 if(ver.minor > minor)
return true;
57 if(ver.patch < patch)
return false;
83 if(
surf ==
nullptr ||
dst ==
nullptr) {
84 PLAIN_LOG <<
"Could not create surface to scale onto";
112 if (
w == 0 ||
h ==0) {
117 if(
surf ==
nullptr ||
dst ==
nullptr) {
118 PLAIN_LOG <<
"Could not create surface to scale onto";
126 const uint32_t*
const src_pixels = src_lock.
pixels();
127 uint32_t*
const dst_pixels = dst_lock.
pixels();
133 for(
int ydst = 0; ydst !=
h; ++ydst, ysrc += yratio) {
135 for(
int xdst = 0; xdst !=
w; ++xdst, xsrc += xratio) {
139 const uint32_t*
const src_word = src_pixels + ysrcint*
surf->w + xsrcint;
140 uint32_t*
const dst_word = dst_pixels + ydst*
dst->w + xdst;
141 const int dx = (xsrcint + 1 <
surf->w) ? 1 : 0;
142 const int dy = (ysrcint + 1 <
surf->h) ?
surf->w : 0;
145 uint32_t rr,gg,bb,aa, temp;
147 uint32_t pix[4], bilin[4];
170 const int32_t
e = 0x000000FF & xsrc;
171 const int32_t
s = 0x000000FF & ysrc;
172 const int32_t
n = 0xFF -
s;
175 const int32_t we = 0xFF -
e;
178 pix[1] = *(src_word + dx);
179 pix[2] = *(src_word + dy);
180 pix[3] = *(src_word + dx + dy);
188 rr = bb = gg = aa = 0;
201 temp = (a * bilin[
loc]);
217 *dst_word = (a << 24) + (r << 16) + (
g << 8) +
b;
238 if(
surf ==
nullptr ||
dst ==
nullptr) {
239 PLAIN_LOG <<
"Could not create surface to scale onto";
247 const uint32_t*
const src_pixels = src_lock.
pixels();
248 uint32_t*
const dst_pixels = dst_lock.
pixels();
254 for(
int ydst = 0; ydst !=
h; ++ydst, ysrc += yratio) {
256 for(
int xdst = 0; xdst !=
w; ++xdst, xsrc += xratio) {
260 const uint32_t*
const src_word = src_pixels + ysrcint*
surf->w + xsrcint;
261 uint32_t*
const dst_word = dst_pixels + ydst*
dst->w + xdst;
262 const int dx = (xsrcint + 1 <
surf->w) ? 1 : 0;
263 const int dy = (ysrcint + 1 <
surf->h) ?
surf->w : 0;
266 uint32_t rr,gg,bb,aa;
267 uint16_t avg_r, avg_g, avg_b;
268 uint32_t pix[4], bilin[4];
282 const int32_t east = 0x000000FF & xsrc;
283 const int32_t south = 0x000000FF & ysrc;
284 const int32_t north = 0xFF - south;
285 const int32_t west = 0xFF - east;
288 pix[1] = *(src_word + dx);
289 pix[2] = *(src_word + dy);
290 pix[3] = *(src_word + dx + dy);
292 bilin[0] = north*west;
293 bilin[1] = north*east;
294 bilin[2] = south*west;
295 bilin[3] = south*east;
301 avg_r = avg_g = avg_b = 0;
330 rr = gg = bb = aa = 0;
337 r =
static_cast<uint8_t
>(avg_r);
338 g =
static_cast<uint8_t
>(avg_g);
339 b =
static_cast<uint8_t
>(avg_b);
341 rr += r * bilin[
loc];
342 gg +=
g * bilin[
loc];
343 bb +=
b * bilin[
loc];
344 aa += a * bilin[
loc];
350 *dst_word = (a << 24) + (r << 16) + (
g << 8) +
b;
360 if(
surf ==
nullptr) {
371 PLAIN_LOG <<
"Could not create surface to scale onto";
375 if(
w == 0 ||
h == 0) {
384 const uint32_t*
const src_pixels = src_lock.
pixels();
385 uint32_t*
const dst_pixels = dst_lock.
pixels();
387 const int src_w =
surf->w;
388 const int src_h =
surf->h;
390 const float xratio =
static_cast<float>(src_w) /
static_cast<float>(
w);
391 const float yratio =
static_cast<float>(src_h) /
static_cast<float>(
h);
392 for(
int ydst = 0; ydst !=
h; ++ydst) {
393 for(
int xdst = 0; xdst !=
w; ++xdst) {
395 const int xsrc = std::floor(
static_cast<float>(xdst) * xratio);
396 const int ysrc = std::floor(
static_cast<float>(ydst) * yratio);
397 dst_pixels[ydst *
dst->w + xdst] = src_pixels[ysrc * src_w + xsrc];
413 r = std::clamp(
static_cast<int>(r) +
red, 0, 255);
414 g = std::clamp(
static_cast<int>(
g) +
green, 0, 255);
415 b = std::clamp(
static_cast<int>(
b) +
blue, 0, 255);
417 pixel = (alpha << 24) + (r << 16) + (
g << 8) +
b;
434 const uint8_t avg =
static_cast<uint8_t
>((
435 77 *
static_cast<uint16_t
>(r) +
436 150 *
static_cast<uint16_t
>(
g) +
437 29 *
static_cast<uint16_t
>(
b) ) / 256);
439 pixel = (alpha << 24) | (avg << 16) | (avg << 8) | avg;
455 uint8_t result =
static_cast<uint8_t
>(0.299 * r + 0.587 *
g + 0.114 *
b) > threshold ? 255 : 0;
457 pixel = (alpha << 24) | (result << 16) | (result << 8) | result;
472 uint8_t outR = std::min(255,
static_cast<int>((r * 0.393) + (
g * 0.769) + (
b * 0.189)));
473 uint8_t outG = std::min(255,
static_cast<int>((r * 0.349) + (
g * 0.686) + (
b * 0.168)));
474 uint8_t outB = std::min(255,
static_cast<int>((r * 0.272) + (
g * 0.534) + (
b * 0.131)));
476 pixel = (alpha << 24) | (outR << 16) | (outG << 8) | (outB);
493 uint8_t newR = r > thresholdR ? 255 - r : r;
494 uint8_t newG =
g > thresholdG ? 255 -
g :
g;
495 uint8_t newB =
b > thresholdB ? 255 -
b :
b;
497 pixel = (alpha << 24) | (newR << 16) | (newG << 8) | (newB);
508 uint8_t alpha = pixel >> 24;
510 pixel = (0xff << 24) | (alpha << 16) | (alpha << 8) | alpha;
521 pixel = 0xff000000 | pixel;
539 uint8_t alpha = pixel >> 24;
543 if(alpha < 255 / 4) {
544 pixel = (alpha * 4) << 24;
559 uint8_t newRed, newGreen, newBlue, newAlpha;
629 pixel = (newAlpha << 24) | (newRed << 16) | (newGreen << 8) | newBlue;
639 if(map_rgb.empty()) {
649 uint8_t old_alpha = color.a;
652 auto iter = map_rgb.find(color);
653 if(iter == map_rgb.end()) {
658 color = iter->second;
661 pixel = color.to_argb_bytes();
670 if (amount < 0) amount = 0;
678 pixel = (alpha << 24) + (r << 16) + (
g << 8) +
b;
685 if(
surf ==
nullptr) {
689 SDL_SetSurfaceAlphaMod(
surf, alpha_mod);
700 alpha = uint8_t(std::clamp(
static_cast<int>(alpha) + amount, 0, 255));
701 pixel = (alpha << 24) + (r << 16) + (
g << 8) +
b;
708 if(nsurf ==
nullptr) {
709 *empty_result =
true;
712 if(nmask ==
nullptr) {
716 if (nsurf->w != nmask->w) {
721 std::stringstream ss;
722 ss <<
"Detected an image with bad dimensions: ";
724 ss << nsurf->w <<
"x" << nsurf->h;
726 PLAIN_LOG <<
"It will not be masked, please use: "<< nmask->w <<
"x" << nmask->h;
735 uint32_t* beg = lock.
pixels();
736 uint32_t* end = beg + nsurf.
area();
737 const uint32_t* mbeg = mlock.
pixels();
738 const uint32_t* mend = mbeg + nmask->w*nmask->h;
740 while(beg != end && mbeg != mend) {
743 uint8_t malpha = (*mbeg) >> 24;
744 if (alpha > malpha) {
750 *beg = (alpha << 24) + (r << 16) + (
g << 8) +
b;
757 *empty_result = empty;
762 if(nsurf ==
nullptr) {
765 if(nmask ==
nullptr){
769 if (nsurf->w != nmask->w || nsurf->h != nmask->h ) {
778 const uint32_t* mbeg = mlock.
pixels();
779 const uint32_t* mend = mbeg + nmask->w*nmask->h;
780 const uint32_t* beg = lock.
pixels();
783 while(mbeg != mend) {
784 uint8_t malpha = (*mbeg) >> 24;
786 uint8_t alpha = (*beg) >> 24;
800 if(nsurf ==
nullptr) {
803 if(lightmap ==
nullptr) {
807 if (nsurf->w != lightmap->w) {
812 PLAIN_LOG <<
"Detected an image with bad dimensions: " << nsurf->w <<
"x" << nsurf->h;
813 PLAIN_LOG <<
"It will not be lighted, please use: "<< lightmap->w <<
"x" << lightmap->h;
820 uint32_t* beg = lock.
pixels();
821 uint32_t* end = beg + nsurf.
area();
822 const uint32_t* lbeg = llock.
pixels();
823 const uint32_t* lend = lbeg + lightmap.
area();
825 while(beg != end && lbeg != lend) {
829 int dr = (
static_cast<int>(lr) - 128) * 2;
830 int dg = (
static_cast<int>(
lg) - 128) * 2;
831 int db = (
static_cast<int>(lb) - 128) * 2;
834 r = std::clamp(r + dr, 0, 255);
835 g = std::clamp(
g + dg, 0, 255);
836 b = std::clamp(
b + db, 0, 255);
838 *beg = (alpha << 24) + (r << 16) + (
g << 8) +
b;
848 if(
surf ==
nullptr) {
852 const int max_blur = 256;
853 if(depth > max_blur) {
857 uint32_t queue[max_blur];
858 const uint32_t* end_queue = queue + max_blur;
860 const uint32_t ff = 0xff;
862 const unsigned pixel_offset =
rect.y *
surf->w +
rect.x;
865 for(
int y = 0; y <
rect.h; ++y) {
866 const uint32_t* front = &queue[0];
867 uint32_t* back = &queue[0];
869 uint32_t*
p = lock.
pixels() + pixel_offset + y *
surf->w;
870 for(
int x = 0; x <= depth && x <
rect.w; ++x, ++
p) {
871 red += ((*p) >> 16)&0xFF;
872 green += ((*p) >> 8)&0xFF;
876 if(back == end_queue) {
882 for(
int x = 0; x <
rect.w; ++x, ++
p) {
884 | (std::min(
red/avg,ff) << 16)
885 | (std::min(
green/avg,ff) << 8)
886 | std::min(
blue/avg,ff);
889 red -= ((*front) >> 16)&0xFF;
890 green -= ((*front) >> 8)&0xFF;
894 if(front == end_queue) {
899 if(x + depth+1 <
rect.w) {
900 uint32_t* q =
p + depth+1;
901 red += ((*q) >> 16)&0xFF;
902 green += ((*q) >> 8)&0xFF;
906 if(back == end_queue) {
913 for(
int x = 0; x <
rect.w; ++x) {
914 const uint32_t* front = &queue[0];
915 uint32_t* back = &queue[0];
917 uint32_t*
p = lock.
pixels() + pixel_offset + x;
918 for(
int y = 0; y <= depth && y <
rect.h; ++y,
p +=
surf->w) {
919 red += ((*p) >> 16)&0xFF;
920 green += ((*p) >> 8)&0xFF;
924 if(back == end_queue) {
929 p = lock.
pixels() + pixel_offset + x;
930 for(
int y = 0; y <
rect.h; ++y,
p +=
surf->w) {
932 | (std::min(
red/avg,ff) << 16)
933 | (std::min(
green/avg,ff) << 8)
934 | std::min(
blue/avg,ff);
937 red -= ((*front) >> 16)&0xFF;
938 green -= ((*front) >> 8)&0xFF;
942 if(front == end_queue) {
947 if(y + depth+1 <
rect.h) {
948 uint32_t* q =
p + (depth+1)*
surf->w;
949 red += ((*q) >> 16)&0xFF;
950 green += ((*q) >> 8)&0xFF;
954 if(back == end_queue) {
968 const int max_blur = 256;
969 if(depth > max_blur) {
979 : alpha(((*
p) >> 24)&0xFF)
980 ,
red(((*
p) >> 16)&0xFF)
991 Average& operator+=(
const Pixel& pix){
992 red += pix.alpha * pix.red;
993 green += pix.alpha * pix.green;
994 blue += pix.alpha * pix.blue;
998 Average& operator-=(
const Pixel& pix){
999 red -= pix.alpha * pix.red;
1000 green -= pix.alpha * pix.green;
1001 blue -= pix.alpha * pix.blue;
1005 uint32_t operator()(
unsigned num){
1006 const uint32_t ff = 0xff;
1010 return (std::min(alpha/num,ff) << 24)
1011 | (std::min(
red/alpha,ff) << 16)
1012 | (std::min(
green/alpha,ff) << 8)
1013 | std::min(
blue/alpha,ff);
1017 boost::circular_buffer<Pixel> queue(depth*2+1);
1022 for(y = 0; y < res->h; ++y) {
1027 uint32_t*
p = lock.
pixels() + y*res->w;
1028 for(x = 0; x <= depth && x < res->w; ++x, ++
p) {
1029 assert(!queue.full());
1030 queue.push_back(Pixel{
p});
1031 avg += queue.back();
1036 for(x = 0; x < res->w; ++x, ++
p) {
1038 const uint32_t num = queue.size();
1043 avg -= queue.front();
1044 assert(!queue.empty());
1049 if(x + depth+1 < res->w) {
1050 uint32_t* q =
p + depth+1;
1051 assert(!queue.full());
1052 queue.push_back(Pixel{q});
1053 avg += queue.back();
1056 assert(
static_cast<int>(queue.size()) == std::min(depth, res->w));
1061 for(x = 0; x < res->w; ++x) {
1066 uint32_t*
p = lock.
pixels() + x;
1067 for(y = 0; y <= depth && y < res->h; ++y,
p += res->w) {
1068 assert(!queue.full());
1069 queue.push_back(Pixel{
p});
1070 avg += queue.back();
1075 for(y = 0; y < res->h; ++y,
p += res->w) {
1077 const uint32_t num = queue.size();
1082 avg -= queue.front();
1083 assert(!queue.empty());
1088 if(y + depth+1 < res->h) {
1089 uint32_t* q =
p + (depth+1)*res->w;
1090 assert(!queue.full());
1091 queue.push_back(Pixel{q});
1092 avg += queue.back();
1095 assert(
static_cast<int>(queue.size()) == std::min(depth, res->h));
1107 if(res ==
nullptr) {
1108 PLAIN_LOG <<
"Could not create a new surface in cut_surface()";
1112 std::size_t sbpp =
surf->format->BytesPerPixel;
1113 std::size_t spitch =
surf->pitch;
1114 std::size_t rbpp = res->format->BytesPerPixel;
1115 std::size_t rpitch = res->pitch;
1118 SDL_Rect src_rect = r;
1119 SDL_Rect dst_rect { 0, 0, r.w, r.h };
1121 if (src_rect.x < 0) {
1122 if (src_rect.x + src_rect.w <= 0)
1124 dst_rect.x -= src_rect.x;
1125 dst_rect.w += src_rect.x;
1126 src_rect.w += src_rect.x;
1129 if (src_rect.y < 0) {
1130 if (src_rect.y + src_rect.h <= 0)
1132 dst_rect.y -= src_rect.y;
1133 dst_rect.h += src_rect.y;
1134 src_rect.h += src_rect.y;
1138 if(src_rect.x >=
surf->w || src_rect.y >=
surf->h)
1144 const uint8_t*
src =
reinterpret_cast<const uint8_t *
>(slock.
pixels());
1145 uint8_t* dest =
reinterpret_cast<uint8_t *
>(rlock.
pixels());
1147 for(
int y = 0; y < src_rect.h && (src_rect.y + y) <
surf->h; ++y) {
1148 const uint8_t* line_src =
src + (src_rect.y + y) * spitch + src_rect.x * sbpp;
1149 uint8_t* line_dest = dest + (dst_rect.y + y) * rpitch + dst_rect.x * rbpp;
1150 std::size_t
size = src_rect.w + src_rect.x <=
surf->w ? src_rect.w :
surf->w - src_rect.x;
1152 assert(rpitch >= src_rect.w * rbpp);
1153 memcpy(line_dest, line_src,
size * rbpp);
1164 uint16_t ratio = amount * 256;
1165 const uint16_t
red = ratio * color.r;
1166 const uint16_t
green = ratio * color.g;
1167 const uint16_t
blue = ratio * color.b;
1168 ratio = 256 - ratio;
1173 r = (ratio * r +
red) >> 8;
1175 b = (ratio *
b +
blue) >> 8;
1177 pixel = (a << 24) | (r << 16) | (
g << 8) |
b;
1189 int src_w, src_h, dst_w, dst_h;
1190 float min_x, min_y, sine, cosine;
1194 const float radians = angle * boost::math::constants::pi<float>() / 180;
1195 cosine = std::cos(radians);
1196 sine = std::sin(radians);
1198 src_w =
surf->w * zoom;
1199 src_h =
surf->h * zoom;
1201 const float point_1x = src_h * -sine;
1202 const float point_1y = src_h * cosine;
1203 const float point_2x = src_w * cosine - src_h * sine;
1204 const float point_2y = src_h * cosine + src_w * sine;
1205 const float point_3x = src_w * cosine;
1206 const float point_3y = src_w * sine;
1210 min_x = std::min(0.0F, std::min(point_1x, std::min(point_2x, point_3x)));
1211 min_y = std::min(0.0F, std::min(point_1y, std::min(point_2y, point_3y)));
1212 max_x = (angle > 90 && angle < 180) ? 0 : std::max(point_1x, std::max(point_2x, point_3x));
1213 max_y = (angle > 180 && angle < 270) ? 0 : std::max(point_1y, std::max(point_2y, point_3y));
1214 dst_w =
static_cast<int>(ceil(std::abs(max_x) - min_x)) / zoom;
1215 dst_h =
static_cast<int>(ceil(std::abs(max_y) - min_y)) / zoom;
1220 uint32_t*
const dst_pixels = dst_lock.
pixels();
1224 const uint32_t*
const src_pixels = src_lock.
pixels();
1226 const float scale = 1.f / zoom;
1227 const int max_x = dst_w * zoom;
1228 const int max_y = dst_h * zoom;
1231 for (
int x = 0; x < max_x; x += offset)
1232 for (
int y = 0; y < max_y; y += offset) {
1234 const float source_x = (x + min_x)*cosine + (y + min_y)*sine;
1235 const float source_y = (y + min_y)*cosine - (x + min_x)*sine;
1237 if (source_x >= 0 && source_x < src_w && source_y >= 0 && source_y < src_h) {
1240 src_pixels[int(source_y) *
src->w + int(source_x)];
1251 if (
surf ==
nullptr )
1256 if ( nsurf ==
nullptr ) {
1257 PLAIN_LOG <<
"could not make neutral surface...";
1263 uint32_t*
const pixels = lock.
pixels();
1267 for (
int y=0; y != nsurf->h/2; ++y) {
1268 for(
int x=0; x != nsurf->w; ++x) {
1269 const int index1 = y*nsurf->w + x;
1270 const int index2 = (nsurf->h-y)*nsurf->w - x - 1;
1271 std::swap(pixels[index1],pixels[index2]);
1275 if (
is_odd(nsurf->h) ) {
1277 for (
int x=0; x != nsurf->w/2; ++x) {
1278 const int index1 = (nsurf->h/2)*nsurf->w + x;
1279 const int index2 = (nsurf->h/2)*nsurf->w + (nsurf->w - x - 1);
1280 std::swap(pixels[index1],pixels[index2]);
1296 if (
surf ==
nullptr ||
dst ==
nullptr ) {
1297 PLAIN_LOG <<
"could not make neutral surface...";
1305 const uint32_t*
const src_pixels = src_lock.
pixels();
1306 uint32_t*
const dst_pixels = dst_lock.
pixels();
1309 for(
int y = 0; y !=
surf->h; ++y) {
1310 for (
int x = 0; x !=
surf->w; ++x ) {
1311 const int src_index = y*
surf->w + x;
1312 const int dst_index = clockwise ?
1313 x*
dst->w + (
dst->w-1-y) :
1315 dst_pixels[dst_index] = src_pixels[src_index];
1327 uint32_t*
const pixels = lock.
pixels();
1329 for(
int y = 0; y != nsurf->h; ++y) {
1330 for(
int x = 0; x != nsurf->w/2; ++x) {
1331 const int index1 = y*nsurf->w + x;
1332 const int index2 = (y+1)*nsurf->w - x - 1;
1333 std::swap(pixels[index1],pixels[index2]);
1343 uint32_t*
const pixels = lock.
pixels();
1345 for(
int x = 0; x != nsurf->w; ++x) {
1346 for(
int y = 0; y != nsurf->h/2; ++y) {
1347 const int index1 = y*nsurf->w + x;
1348 const int index2 = (nsurf->h-y-1)*nsurf->w + x;
1349 std::swap(pixels[index1],pixels[index2]);
1357 if (
src ==
nullptr) {
1362 if(area.x >=
src->w || area.y >=
src->h || area.x + area.w < 0 || area.y + area.h < 0) {
1366 if(area.x + area.w >
src->w) {
1367 area.w =
src->w - area.x;
1369 if(area.y + area.h >
src->h) {
1370 area.h =
src->h - area.y;
1376 if(
dst ==
nullptr) {
1377 PLAIN_LOG <<
"Could not create a new surface in get_surface_portion()";
1382 SDL_BlendMode src_blend;
1383 SDL_GetSurfaceBlendMode(
src, &src_blend);
1384 SDL_SetSurfaceBlendMode(
src, SDL_BLENDMODE_NONE);
1385 SDL_BlitSurface(
src, &area,
dst,
nullptr);
1386 SDL_SetSurfaceBlendMode(
src, src_blend);
1393 constexpr
bool not_alpha(uint32_t pixel)
1395 return (pixel >> 24) != 0x00;
1404 const uint32_t*
const pixels = lock.
pixels();
1407 for(
n = 0;
n != nsurf->h; ++
n) {
1408 const uint32_t*
const start_row = pixels +
n*nsurf->w;
1409 const uint32_t*
const end_row = start_row + nsurf->w;
1411 if(std::find_if(start_row,end_row,not_alpha) != end_row)
1417 for(
n = 0;
n != nsurf->h-res.y; ++
n) {
1418 const uint32_t*
const start_row = pixels + (nsurf->h-
n-1)*nsurf->w;
1419 const uint32_t*
const end_row = start_row + nsurf->w;
1421 if(std::find_if(start_row,end_row,not_alpha) != end_row)
1428 res.h = nsurf->h - res.y -
n;
1430 for(
n = 0;
n != nsurf->w; ++
n) {
1432 for(y = 0; y != nsurf->h; ++y) {
1433 const uint32_t pixel = pixels[y*nsurf->w +
n];
1434 if(not_alpha(pixel))
1444 for(
n = 0;
n != nsurf->w-res.x; ++
n) {
1446 for(y = 0; y != nsurf->h; ++y) {
1447 const uint32_t pixel = pixels[y*nsurf->w + nsurf->w -
n - 1];
1448 if(not_alpha(pixel))
1456 res.w = nsurf->w - res.x -
n;
Helper class for pinning SDL surfaces into memory.
utils::span< pixel_t > pixel_span() const
surface clone() const
Creates a new, duplicate surface in memory using the 'neutral' pixel format.
std::size_t area() const
Total area of the surface in square pixels.
Represents version numbers.
constexpr uint8_t ALPHA_OPAQUE
std::unordered_map< color_t, color_t > color_range_map
void swap(config &lhs, config &rhs)
Implement non-member swap function for std::swap (calls config::swap).
Standard logging facilities (interface).
constexpr int fixed_point_to_int(int32_t n)
If positive, just bit shift.
constexpr bool is_odd(T num)
constexpr unsigned fixed_point_multiply(int32_t n1, int32_t n2)
constexpr int32_t fixed_point_divide(int n1, int n2)
version_info get_version()
Returns the runtime SDL version.
bool runtime_at_least(uint8_t major, uint8_t minor=0, uint8_t patch=0)
Returns true if the runtime SDL version is at or greater than the specified version,...
std::size_t size(std::string_view str)
Length in characters of a UTF-8 string.
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, ColorFormat colFmt, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
const int SCALE_FACTOR_MAX
Contains the SDL_Rect helper code.
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
std::string filename
Filename.
The basic class for representing 8-bit RGB or RGBA colour values.
static constexpr color_t from_argb_bytes(uint32_t c)
Creates a new color_t object from a uint32_t variable.
An abstract description of a rectangle with integer coordinates.
static map_location::direction n
static map_location::direction s
void mask_surface(surface &nsurf, const surface &nmask, bool *empty_result, const std::string &filename)
Applies a mask on a surface.
rect get_non_transparent_portion(const surface &nsurf)
void alpha_to_greyscale(surface &nsurf)
surface scale_surface_legacy(const surface &surf, int w, int h)
Scale a surface using simple bilinear filtering (discarding rgb from source pixels with 0 alpha)
void recolor_image(surface &nsurf, const color_range_map &map_rgb)
Recolors a surface using a map with source and converted palette values.
void wipe_alpha(surface &nsurf)
void brighten_image(surface &nsurf, int32_t amount)
void adjust_surface_alpha(surface &surf, uint8_t alpha_mod)
void sepia_image(surface &nsurf)
void adjust_surface_alpha_add(surface &nsurf, int amount)
void blend_surface(surface &nsurf, const double amount, const color_t color)
Blends a surface with a color.
void swap_channels_image(surface &nsurf, channel r, channel g, channel b, channel a)
void adjust_surface_color(surface &nsurf, int red, int green, int blue)
surface cut_surface(const surface &surf, const SDL_Rect &r)
Cuts a rectangle from a surface.
void negative_image(surface &nsurf, const int thresholdR, const int thresholdG, const int thresholdB)
void shadow_image(surface &surf, int scale)
create an heavy shadow of the image, by blurring, increasing alpha and darkening
static lg::log_domain log_display("display")
void light_surface(surface &nsurf, const surface &lightmap)
Light surf using lightmap.
surface get_surface_portion(const surface &src, SDL_Rect &area)
Get a portion of the screen.
surface scale_surface_xbrz(const surface &surf, std::size_t z)
Scale a surface using xBRZ algorithm.
bool in_mask_surface(const surface &nsurf, const surface &nmask)
Check if a surface fit into a mask.
surface scale_surface_sharp(const surface &surf, int w, int h)
Scale a surface using modified nearest neighbour algorithm.
void blur_alpha_surface(surface &res, int depth)
Cross-fades a surface with alpha channel.
void greyscale_image(surface &nsurf)
void flop_surface(surface &nsurf)
surface rotate_90_surface(const surface &surf, bool clockwise)
Rotates a surface 90 degrees.
surface rotate_180_surface(const surface &surf)
Rotates a surface 180 degrees.
void flip_surface(surface &nsurf)
surface scale_surface(const surface &surf, int w, int h)
Scale a surface using alpha-weighted modified bilinear filtering Note: causes artifacts with alpha gr...
surface rotate_any_surface(const surface &surf, float angle, int zoom, int offset)
Rotates a surface by any degrees.
void monochrome_image(surface &nsurf, const int threshold)
void blur_surface(surface &surf, SDL_Rect rect, int depth)
Cross-fades a surface in place.