comparison src/video/SDL_RLEaccel.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children 396a35389351
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
778 /* 778 /*
779 * This takes care of the case when the surface is clipped on the left and/or 779 * This takes care of the case when the surface is clipped on the left and/or
780 * right. Top clipping has already been taken care of. 780 * right. Top clipping has already been taken care of.
781 */ 781 */
782 static void 782 static void
783 RLEClipBlit (int w, Uint8 * srcbuf, SDL_Surface * dst, 783 RLEClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
784 Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha) 784 Uint8 * dstbuf, SDL_Rect * srcrect, unsigned alpha)
785 { 785 {
786 SDL_PixelFormat *fmt = dst->format; 786 SDL_PixelFormat *fmt = dst->format;
787 787
788 #define RLECLIPBLIT(bpp, Type, do_blit) \ 788 #define RLECLIPBLIT(bpp, Type, do_blit) \
789 do { \ 789 do { \
827 break; \ 827 break; \
828 } \ 828 } \
829 } \ 829 } \
830 } while(0) 830 } while(0)
831 831
832 CHOOSE_BLIT (RLECLIPBLIT, alpha, fmt); 832 CHOOSE_BLIT(RLECLIPBLIT, alpha, fmt);
833 833
834 #undef RLECLIPBLIT 834 #undef RLECLIPBLIT
835 835
836 } 836 }
837 837
838 838
839 /* blit a colorkeyed RLE surface */ 839 /* blit a colorkeyed RLE surface */
840 int 840 int
841 SDL_RLEBlit (SDL_Surface * src, SDL_Rect * srcrect, 841 SDL_RLEBlit(SDL_Surface * src, SDL_Rect * srcrect,
842 SDL_Surface * dst, SDL_Rect * dstrect) 842 SDL_Surface * dst, SDL_Rect * dstrect)
843 { 843 {
844 Uint8 *dstbuf; 844 Uint8 *dstbuf;
845 Uint8 *srcbuf; 845 Uint8 *srcbuf;
846 int x, y; 846 int x, y;
847 int w = src->w; 847 int w = src->w;
848 unsigned alpha; 848 unsigned alpha;
849 849
850 /* Lock the destination if necessary */ 850 /* Lock the destination if necessary */
851 if (SDL_MUSTLOCK (dst)) { 851 if (SDL_MUSTLOCK(dst)) {
852 if (SDL_LockSurface (dst) < 0) { 852 if (SDL_LockSurface(dst) < 0) {
853 return (-1); 853 return (-1);
854 } 854 }
855 } 855 }
856 856
857 /* Set up the source and destination pointers */ 857 /* Set up the source and destination pointers */
885 } \ 885 } \
886 } 886 }
887 887
888 switch (src->format->BytesPerPixel) { 888 switch (src->format->BytesPerPixel) {
889 case 1: 889 case 1:
890 RLESKIP (1, Uint8); 890 RLESKIP(1, Uint8);
891 break; 891 break;
892 case 2: 892 case 2:
893 RLESKIP (2, Uint8); 893 RLESKIP(2, Uint8);
894 break; 894 break;
895 case 3: 895 case 3:
896 RLESKIP (3, Uint8); 896 RLESKIP(3, Uint8);
897 break; 897 break;
898 case 4: 898 case 4:
899 RLESKIP (4, Uint16); 899 RLESKIP(4, Uint16);
900 break; 900 break;
901 } 901 }
902 902
903 #undef RLESKIP 903 #undef RLESKIP
904 904
907 907
908 alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA 908 alpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA
909 ? src->format->alpha : 255; 909 ? src->format->alpha : 255;
910 /* if left or right edge clipping needed, call clip blit */ 910 /* if left or right edge clipping needed, call clip blit */
911 if (srcrect->x || srcrect->w != src->w) { 911 if (srcrect->x || srcrect->w != src->w) {
912 RLEClipBlit (w, srcbuf, dst, dstbuf, srcrect, alpha); 912 RLEClipBlit(w, srcbuf, dst, dstbuf, srcrect, alpha);
913 } else { 913 } else {
914 SDL_PixelFormat *fmt = src->format; 914 SDL_PixelFormat *fmt = src->format;
915 915
916 #define RLEBLIT(bpp, Type, do_blit) \ 916 #define RLEBLIT(bpp, Type, do_blit) \
917 do { \ 917 do { \
935 break; \ 935 break; \
936 } \ 936 } \
937 } \ 937 } \
938 } while(0) 938 } while(0)
939 939
940 CHOOSE_BLIT (RLEBLIT, alpha, fmt); 940 CHOOSE_BLIT(RLEBLIT, alpha, fmt);
941 941
942 #undef RLEBLIT 942 #undef RLEBLIT
943 } 943 }
944 944
945 done: 945 done:
946 /* Unlock the destination if necessary */ 946 /* Unlock the destination if necessary */
947 if (SDL_MUSTLOCK (dst)) { 947 if (SDL_MUSTLOCK(dst)) {
948 SDL_UnlockSurface (dst); 948 SDL_UnlockSurface(dst);
949 } 949 }
950 return (0); 950 return (0);
951 } 951 }
952 952
953 #undef OPAQUE_BLIT 953 #undef OPAQUE_BLIT
1021 Uint32 Amask; 1021 Uint32 Amask;
1022 } RLEDestFormat; 1022 } RLEDestFormat;
1023 1023
1024 /* blit a pixel-alpha RLE surface clipped at the right and/or left edges */ 1024 /* blit a pixel-alpha RLE surface clipped at the right and/or left edges */
1025 static void 1025 static void
1026 RLEAlphaClipBlit (int w, Uint8 * srcbuf, SDL_Surface * dst, 1026 RLEAlphaClipBlit(int w, Uint8 * srcbuf, SDL_Surface * dst,
1027 Uint8 * dstbuf, SDL_Rect * srcrect) 1027 Uint8 * dstbuf, SDL_Rect * srcrect)
1028 { 1028 {
1029 SDL_PixelFormat *df = dst->format; 1029 SDL_PixelFormat *df = dst->format;
1030 /* 1030 /*
1031 * clipped blitter: Ptype is the destination pixel type, 1031 * clipped blitter: Ptype is the destination pixel type,
1032 * Ctype the translucent count type, and do_blend the macro 1032 * Ctype the translucent count type, and do_blend the macro
1101 } while(0) 1101 } while(0)
1102 1102
1103 switch (df->BytesPerPixel) { 1103 switch (df->BytesPerPixel) {
1104 case 2: 1104 case 2:
1105 if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0) 1105 if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 || df->Bmask == 0x07e0)
1106 RLEALPHACLIPBLIT (Uint16, Uint8, BLIT_TRANSL_565); 1106 RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_565);
1107 else 1107 else
1108 RLEALPHACLIPBLIT (Uint16, Uint8, BLIT_TRANSL_555); 1108 RLEALPHACLIPBLIT(Uint16, Uint8, BLIT_TRANSL_555);
1109 break; 1109 break;
1110 case 4: 1110 case 4:
1111 RLEALPHACLIPBLIT (Uint32, Uint16, BLIT_TRANSL_888); 1111 RLEALPHACLIPBLIT(Uint32, Uint16, BLIT_TRANSL_888);
1112 break; 1112 break;
1113 } 1113 }
1114 } 1114 }
1115 1115
1116 /* blit a pixel-alpha RLE surface */ 1116 /* blit a pixel-alpha RLE surface */
1117 int 1117 int
1118 SDL_RLEAlphaBlit (SDL_Surface * src, SDL_Rect * srcrect, 1118 SDL_RLEAlphaBlit(SDL_Surface * src, SDL_Rect * srcrect,
1119 SDL_Surface * dst, SDL_Rect * dstrect) 1119 SDL_Surface * dst, SDL_Rect * dstrect)
1120 { 1120 {
1121 int x, y; 1121 int x, y;
1122 int w = src->w; 1122 int w = src->w;
1123 Uint8 *srcbuf, *dstbuf; 1123 Uint8 *srcbuf, *dstbuf;
1124 SDL_PixelFormat *df = dst->format; 1124 SDL_PixelFormat *df = dst->format;
1125 1125
1126 /* Lock the destination if necessary */ 1126 /* Lock the destination if necessary */
1127 if (SDL_MUSTLOCK (dst)) { 1127 if (SDL_MUSTLOCK(dst)) {
1128 if (SDL_LockSurface (dst) < 0) { 1128 if (SDL_LockSurface(dst) < 0) {
1129 return -1; 1129 return -1;
1130 } 1130 }
1131 } 1131 }
1132 1132
1133 x = dstrect->x; 1133 x = dstrect->x;
1134 y = dstrect->y; 1134 y = dstrect->y;
1135 dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel; 1135 dstbuf = (Uint8 *) dst->pixels + y * dst->pitch + x * df->BytesPerPixel;
1136 srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof (RLEDestFormat); 1136 srcbuf = (Uint8 *) src->map->sw_data->aux_data + sizeof(RLEDestFormat);
1137 1137
1138 { 1138 {
1139 /* skip lines at the top if necessary */ 1139 /* skip lines at the top if necessary */
1140 int vskip = srcrect->y; 1140 int vskip = srcrect->y;
1141 if (vskip) { 1141 if (vskip) {
1196 } 1196 }
1197 } 1197 }
1198 1198
1199 /* if left or right edge clipping needed, call clip blit */ 1199 /* if left or right edge clipping needed, call clip blit */
1200 if (srcrect->x || srcrect->w != src->w) { 1200 if (srcrect->x || srcrect->w != src->w) {
1201 RLEAlphaClipBlit (w, srcbuf, dst, dstbuf, srcrect); 1201 RLEAlphaClipBlit(w, srcbuf, dst, dstbuf, srcrect);
1202 } else { 1202 } else {
1203 1203
1204 /* 1204 /*
1205 * non-clipped blitter. Ptype is the destination pixel type, 1205 * non-clipped blitter. Ptype is the destination pixel type,
1206 * Ctype the translucent count type, and do_blend the 1206 * Ctype the translucent count type, and do_blend the
1253 1253
1254 switch (df->BytesPerPixel) { 1254 switch (df->BytesPerPixel) {
1255 case 2: 1255 case 2:
1256 if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0 1256 if (df->Gmask == 0x07e0 || df->Rmask == 0x07e0
1257 || df->Bmask == 0x07e0) 1257 || df->Bmask == 0x07e0)
1258 RLEALPHABLIT (Uint16, Uint8, BLIT_TRANSL_565); 1258 RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_565);
1259 else 1259 else
1260 RLEALPHABLIT (Uint16, Uint8, BLIT_TRANSL_555); 1260 RLEALPHABLIT(Uint16, Uint8, BLIT_TRANSL_555);
1261 break; 1261 break;
1262 case 4: 1262 case 4:
1263 RLEALPHABLIT (Uint32, Uint16, BLIT_TRANSL_888); 1263 RLEALPHABLIT(Uint32, Uint16, BLIT_TRANSL_888);
1264 break; 1264 break;
1265 } 1265 }
1266 } 1266 }
1267 1267
1268 done: 1268 done:
1269 /* Unlock the destination if necessary */ 1269 /* Unlock the destination if necessary */
1270 if (SDL_MUSTLOCK (dst)) { 1270 if (SDL_MUSTLOCK(dst)) {
1271 SDL_UnlockSurface (dst); 1271 SDL_UnlockSurface(dst);
1272 } 1272 }
1273 return 0; 1273 return 0;
1274 } 1274 }
1275 1275
1276 /* 1276 /*
1283 * highly optimised. 1283 * highly optimised.
1284 */ 1284 */
1285 1285
1286 /* encode 32bpp rgb + a into 16bpp rgb, losing alpha */ 1286 /* encode 32bpp rgb + a into 16bpp rgb, losing alpha */
1287 static int 1287 static int
1288 copy_opaque_16 (void *dst, Uint32 * src, int n, 1288 copy_opaque_16(void *dst, Uint32 * src, int n,
1289 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) 1289 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
1290 { 1290 {
1291 int i; 1291 int i;
1292 Uint16 *d = dst; 1292 Uint16 *d = dst;
1293 for (i = 0; i < n; i++) { 1293 for (i = 0; i < n; i++) {
1294 unsigned r, g, b; 1294 unsigned r, g, b;
1295 RGB_FROM_PIXEL (*src, sfmt, r, g, b); 1295 RGB_FROM_PIXEL(*src, sfmt, r, g, b);
1296 PIXEL_FROM_RGB (*d, dfmt, r, g, b); 1296 PIXEL_FROM_RGB(*d, dfmt, r, g, b);
1297 src++; 1297 src++;
1298 d++; 1298 d++;
1299 } 1299 }
1300 return n * 2; 1300 return n * 2;
1301 } 1301 }
1302 1302
1303 /* decode opaque pixels from 16bpp to 32bpp rgb + a */ 1303 /* decode opaque pixels from 16bpp to 32bpp rgb + a */
1304 static int 1304 static int
1305 uncopy_opaque_16 (Uint32 * dst, void *src, int n, 1305 uncopy_opaque_16(Uint32 * dst, void *src, int n,
1306 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) 1306 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
1307 { 1307 {
1308 int i; 1308 int i;
1309 Uint16 *s = src; 1309 Uint16 *s = src;
1310 unsigned alpha = dfmt->Amask ? 255 : 0; 1310 unsigned alpha = dfmt->Amask ? 255 : 0;
1311 for (i = 0; i < n; i++) { 1311 for (i = 0; i < n; i++) {
1312 unsigned r, g, b; 1312 unsigned r, g, b;
1313 RGB_FROM_PIXEL (*s, sfmt, r, g, b); 1313 RGB_FROM_PIXEL(*s, sfmt, r, g, b);
1314 PIXEL_FROM_RGBA (*dst, dfmt, r, g, b, alpha); 1314 PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, alpha);
1315 s++; 1315 s++;
1316 dst++; 1316 dst++;
1317 } 1317 }
1318 return n * 2; 1318 return n * 2;
1319 } 1319 }
1320 1320
1321 1321
1322 1322
1323 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */ 1323 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 565 */
1324 static int 1324 static int
1325 copy_transl_565 (void *dst, Uint32 * src, int n, 1325 copy_transl_565(void *dst, Uint32 * src, int n,
1326 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) 1326 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
1327 { 1327 {
1328 int i; 1328 int i;
1329 Uint32 *d = dst; 1329 Uint32 *d = dst;
1330 for (i = 0; i < n; i++) { 1330 for (i = 0; i < n; i++) {
1331 unsigned r, g, b, a; 1331 unsigned r, g, b, a;
1332 Uint16 pix; 1332 Uint16 pix;
1333 RGBA_FROM_8888 (*src, sfmt, r, g, b, a); 1333 RGBA_FROM_8888(*src, sfmt, r, g, b, a);
1334 PIXEL_FROM_RGB (pix, dfmt, r, g, b); 1334 PIXEL_FROM_RGB(pix, dfmt, r, g, b);
1335 *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0); 1335 *d = ((pix & 0x7e0) << 16) | (pix & 0xf81f) | ((a << 2) & 0x7e0);
1336 src++; 1336 src++;
1337 d++; 1337 d++;
1338 } 1338 }
1339 return n * 4; 1339 return n * 4;
1340 } 1340 }
1341 1341
1342 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */ 1342 /* encode 32bpp rgb + a into 32bpp G0RAB format for blitting into 555 */
1343 static int 1343 static int
1344 copy_transl_555 (void *dst, Uint32 * src, int n, 1344 copy_transl_555(void *dst, Uint32 * src, int n,
1345 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) 1345 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
1346 { 1346 {
1347 int i; 1347 int i;
1348 Uint32 *d = dst; 1348 Uint32 *d = dst;
1349 for (i = 0; i < n; i++) { 1349 for (i = 0; i < n; i++) {
1350 unsigned r, g, b, a; 1350 unsigned r, g, b, a;
1351 Uint16 pix; 1351 Uint16 pix;
1352 RGBA_FROM_8888 (*src, sfmt, r, g, b, a); 1352 RGBA_FROM_8888(*src, sfmt, r, g, b, a);
1353 PIXEL_FROM_RGB (pix, dfmt, r, g, b); 1353 PIXEL_FROM_RGB(pix, dfmt, r, g, b);
1354 *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0); 1354 *d = ((pix & 0x3e0) << 16) | (pix & 0xfc1f) | ((a << 2) & 0x3e0);
1355 src++; 1355 src++;
1356 d++; 1356 d++;
1357 } 1357 }
1358 return n * 4; 1358 return n * 4;
1359 } 1359 }
1360 1360
1361 /* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */ 1361 /* decode translucent pixels from 32bpp GORAB to 32bpp rgb + a */
1362 static int 1362 static int
1363 uncopy_transl_16 (Uint32 * dst, void *src, int n, 1363 uncopy_transl_16(Uint32 * dst, void *src, int n,
1364 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) 1364 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
1365 { 1365 {
1366 int i; 1366 int i;
1367 Uint32 *s = src; 1367 Uint32 *s = src;
1368 for (i = 0; i < n; i++) { 1368 for (i = 0; i < n; i++) {
1369 unsigned r, g, b, a; 1369 unsigned r, g, b, a;
1370 Uint32 pix = *s++; 1370 Uint32 pix = *s++;
1371 a = (pix & 0x3e0) >> 2; 1371 a = (pix & 0x3e0) >> 2;
1372 pix = (pix & ~0x3e0) | pix >> 16; 1372 pix = (pix & ~0x3e0) | pix >> 16;
1373 RGB_FROM_PIXEL (pix, sfmt, r, g, b); 1373 RGB_FROM_PIXEL(pix, sfmt, r, g, b);
1374 PIXEL_FROM_RGBA (*dst, dfmt, r, g, b, a); 1374 PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
1375 dst++; 1375 dst++;
1376 } 1376 }
1377 return n * 4; 1377 return n * 4;
1378 } 1378 }
1379 1379
1380 /* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ 1380 /* encode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
1381 static int 1381 static int
1382 copy_32 (void *dst, Uint32 * src, int n, 1382 copy_32(void *dst, Uint32 * src, int n,
1383 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt) 1383 SDL_PixelFormat * sfmt, SDL_PixelFormat * dfmt)
1384 { 1384 {
1385 int i; 1385 int i;
1386 Uint32 *d = dst; 1386 Uint32 *d = dst;
1387 for (i = 0; i < n; i++) { 1387 for (i = 0; i < n; i++) {
1388 unsigned r, g, b, a; 1388 unsigned r, g, b, a;
1389 Uint32 pixel; 1389 Uint32 pixel;
1390 RGBA_FROM_8888 (*src, sfmt, r, g, b, a); 1390 RGBA_FROM_8888(*src, sfmt, r, g, b, a);
1391 PIXEL_FROM_RGB (pixel, dfmt, r, g, b); 1391 PIXEL_FROM_RGB(pixel, dfmt, r, g, b);
1392 *d++ = pixel | a << 24; 1392 *d++ = pixel | a << 24;
1393 src++; 1393 src++;
1394 } 1394 }
1395 return n * 4; 1395 return n * 4;
1396 } 1396 }
1397 1397
1398 /* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */ 1398 /* decode 32bpp rgba into 32bpp rgba, keeping alpha (dual purpose) */
1399 static int 1399 static int
1400 uncopy_32 (Uint32 * dst, void *src, int n, 1400 uncopy_32(Uint32 * dst, void *src, int n,
1401 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt) 1401 RLEDestFormat * sfmt, SDL_PixelFormat * dfmt)
1402 { 1402 {
1403 int i; 1403 int i;
1404 Uint32 *s = src; 1404 Uint32 *s = src;
1405 for (i = 0; i < n; i++) { 1405 for (i = 0; i < n; i++) {
1406 unsigned r, g, b, a; 1406 unsigned r, g, b, a;
1407 Uint32 pixel = *s++; 1407 Uint32 pixel = *s++;
1408 RGB_FROM_PIXEL (pixel, sfmt, r, g, b); 1408 RGB_FROM_PIXEL(pixel, sfmt, r, g, b);
1409 a = pixel >> 24; 1409 a = pixel >> 24;
1410 PIXEL_FROM_RGBA (*dst, dfmt, r, g, b, a); 1410 PIXEL_FROM_RGBA(*dst, dfmt, r, g, b, a);
1411 dst++; 1411 dst++;
1412 } 1412 }
1413 return n * 4; 1413 return n * 4;
1414 } 1414 }
1415 1415
1418 #define ISTRANSL(pixel, fmt) \ 1418 #define ISTRANSL(pixel, fmt) \
1419 ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U) 1419 ((unsigned)((((pixel) & fmt->Amask) >> fmt->Ashift) - 1U) < 254U)
1420 1420
1421 /* convert surface to be quickly alpha-blittable onto dest, if possible */ 1421 /* convert surface to be quickly alpha-blittable onto dest, if possible */
1422 static int 1422 static int
1423 RLEAlphaSurface (SDL_Surface * surface) 1423 RLEAlphaSurface(SDL_Surface * surface)
1424 { 1424 {
1425 SDL_Surface *dest; 1425 SDL_Surface *dest;
1426 SDL_PixelFormat *df; 1426 SDL_PixelFormat *df;
1427 int maxsize = 0; 1427 int maxsize = 0;
1428 int max_opaque_run; 1428 int max_opaque_run;
1485 break; 1485 break;
1486 default: 1486 default:
1487 return -1; /* anything else unsupported right now */ 1487 return -1; /* anything else unsupported right now */
1488 } 1488 }
1489 1489
1490 maxsize += sizeof (RLEDestFormat); 1490 maxsize += sizeof(RLEDestFormat);
1491 rlebuf = (Uint8 *) SDL_malloc (maxsize); 1491 rlebuf = (Uint8 *) SDL_malloc(maxsize);
1492 if (!rlebuf) { 1492 if (!rlebuf) {
1493 SDL_OutOfMemory (); 1493 SDL_OutOfMemory();
1494 return -1; 1494 return -1;
1495 } 1495 }
1496 { 1496 {
1497 /* save the destination format so we can undo the encoding later */ 1497 /* save the destination format so we can undo the encoding later */
1498 RLEDestFormat *r = (RLEDestFormat *) rlebuf; 1498 RLEDestFormat *r = (RLEDestFormat *) rlebuf;
1507 r->Rmask = df->Rmask; 1507 r->Rmask = df->Rmask;
1508 r->Gmask = df->Gmask; 1508 r->Gmask = df->Gmask;
1509 r->Bmask = df->Bmask; 1509 r->Bmask = df->Bmask;
1510 r->Amask = df->Amask; 1510 r->Amask = df->Amask;
1511 } 1511 }
1512 dst = rlebuf + sizeof (RLEDestFormat); 1512 dst = rlebuf + sizeof(RLEDestFormat);
1513 1513
1514 /* Do the actual encoding */ 1514 /* Do the actual encoding */
1515 { 1515 {
1516 int x, y; 1516 int x, y;
1517 int h = surface->h, w = surface->w; 1517 int h = surface->h, w = surface->w;
1541 /* First encode all opaque pixels of a scan line */ 1541 /* First encode all opaque pixels of a scan line */
1542 x = 0; 1542 x = 0;
1543 do { 1543 do {
1544 int run, skip, len; 1544 int run, skip, len;
1545 skipstart = x; 1545 skipstart = x;
1546 while (x < w && !ISOPAQUE (src[x], sf)) 1546 while (x < w && !ISOPAQUE(src[x], sf))
1547 x++; 1547 x++;
1548 runstart = x; 1548 runstart = x;
1549 while (x < w && ISOPAQUE (src[x], sf)) 1549 while (x < w && ISOPAQUE(src[x], sf))
1550 x++; 1550 x++;
1551 skip = runstart - skipstart; 1551 skip = runstart - skipstart;
1552 if (skip == w) 1552 if (skip == w)
1553 blankline = 1; 1553 blankline = 1;
1554 run = x - runstart; 1554 run = x - runstart;
1555 while (skip > max_opaque_run) { 1555 while (skip > max_opaque_run) {
1556 ADD_OPAQUE_COUNTS (max_opaque_run, 0); 1556 ADD_OPAQUE_COUNTS(max_opaque_run, 0);
1557 skip -= max_opaque_run; 1557 skip -= max_opaque_run;
1558 } 1558 }
1559 len = MIN (run, max_opaque_run); 1559 len = MIN(run, max_opaque_run);
1560 ADD_OPAQUE_COUNTS (skip, len); 1560 ADD_OPAQUE_COUNTS(skip, len);
1561 dst += copy_opaque (dst, src + runstart, len, sf, df); 1561 dst += copy_opaque(dst, src + runstart, len, sf, df);
1562 runstart += len; 1562 runstart += len;
1563 run -= len; 1563 run -= len;
1564 while (run) { 1564 while (run) {
1565 len = MIN (run, max_opaque_run); 1565 len = MIN(run, max_opaque_run);
1566 ADD_OPAQUE_COUNTS (0, len); 1566 ADD_OPAQUE_COUNTS(0, len);
1567 dst += copy_opaque (dst, src + runstart, len, sf, df); 1567 dst += copy_opaque(dst, src + runstart, len, sf, df);
1568 runstart += len; 1568 runstart += len;
1569 run -= len; 1569 run -= len;
1570 } 1570 }
1571 } 1571 }
1572 while (x < w); 1572 while (x < w);
1577 /* Next, encode all translucent pixels of the same scan line */ 1577 /* Next, encode all translucent pixels of the same scan line */
1578 x = 0; 1578 x = 0;
1579 do { 1579 do {
1580 int run, skip, len; 1580 int run, skip, len;
1581 skipstart = x; 1581 skipstart = x;
1582 while (x < w && !ISTRANSL (src[x], sf)) 1582 while (x < w && !ISTRANSL(src[x], sf))
1583 x++; 1583 x++;
1584 runstart = x; 1584 runstart = x;
1585 while (x < w && ISTRANSL (src[x], sf)) 1585 while (x < w && ISTRANSL(src[x], sf))
1586 x++; 1586 x++;
1587 skip = runstart - skipstart; 1587 skip = runstart - skipstart;
1588 blankline &= (skip == w); 1588 blankline &= (skip == w);
1589 run = x - runstart; 1589 run = x - runstart;
1590 while (skip > max_transl_run) { 1590 while (skip > max_transl_run) {
1591 ADD_TRANSL_COUNTS (max_transl_run, 0); 1591 ADD_TRANSL_COUNTS(max_transl_run, 0);
1592 skip -= max_transl_run; 1592 skip -= max_transl_run;
1593 } 1593 }
1594 len = MIN (run, max_transl_run); 1594 len = MIN(run, max_transl_run);
1595 ADD_TRANSL_COUNTS (skip, len); 1595 ADD_TRANSL_COUNTS(skip, len);
1596 dst += copy_transl (dst, src + runstart, len, sf, df); 1596 dst += copy_transl(dst, src + runstart, len, sf, df);
1597 runstart += len; 1597 runstart += len;
1598 run -= len; 1598 run -= len;
1599 while (run) { 1599 while (run) {
1600 len = MIN (run, max_transl_run); 1600 len = MIN(run, max_transl_run);
1601 ADD_TRANSL_COUNTS (0, len); 1601 ADD_TRANSL_COUNTS(0, len);
1602 dst += copy_transl (dst, src + runstart, len, sf, df); 1602 dst += copy_transl(dst, src + runstart, len, sf, df);
1603 runstart += len; 1603 runstart += len;
1604 run -= len; 1604 run -= len;
1605 } 1605 }
1606 if (!blankline) 1606 if (!blankline)
1607 lastline = dst; 1607 lastline = dst;
1609 while (x < w); 1609 while (x < w);
1610 1610
1611 src += surface->pitch >> 2; 1611 src += surface->pitch >> 2;
1612 } 1612 }
1613 dst = lastline; /* back up past trailing blank lines */ 1613 dst = lastline; /* back up past trailing blank lines */
1614 ADD_OPAQUE_COUNTS (0, 0); 1614 ADD_OPAQUE_COUNTS(0, 0);
1615 } 1615 }
1616 1616
1617 #undef ADD_OPAQUE_COUNTS 1617 #undef ADD_OPAQUE_COUNTS
1618 #undef ADD_TRANSL_COUNTS 1618 #undef ADD_TRANSL_COUNTS
1619 1619
1620 /* Now that we have it encoded, release the original pixels */ 1620 /* Now that we have it encoded, release the original pixels */
1621 if ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC 1621 if ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
1622 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { 1622 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
1623 SDL_free (surface->pixels); 1623 SDL_free(surface->pixels);
1624 surface->pixels = NULL; 1624 surface->pixels = NULL;
1625 } 1625 }
1626 1626
1627 /* realloc the buffer to release unused memory */ 1627 /* realloc the buffer to release unused memory */
1628 { 1628 {
1629 Uint8 *p = SDL_realloc (rlebuf, dst - rlebuf); 1629 Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
1630 if (!p) 1630 if (!p)
1631 p = rlebuf; 1631 p = rlebuf;
1632 surface->map->sw_data->aux_data = p; 1632 surface->map->sw_data->aux_data = p;
1633 } 1633 }
1634 1634
1635 return 0; 1635 return 0;
1636 } 1636 }
1637 1637
1638 static Uint32 1638 static Uint32
1639 getpix_8 (Uint8 * srcbuf) 1639 getpix_8(Uint8 * srcbuf)
1640 { 1640 {
1641 return *srcbuf; 1641 return *srcbuf;
1642 } 1642 }
1643 1643
1644 static Uint32 1644 static Uint32
1645 getpix_16 (Uint8 * srcbuf) 1645 getpix_16(Uint8 * srcbuf)
1646 { 1646 {
1647 return *(Uint16 *) srcbuf; 1647 return *(Uint16 *) srcbuf;
1648 } 1648 }
1649 1649
1650 static Uint32 1650 static Uint32
1651 getpix_24 (Uint8 * srcbuf) 1651 getpix_24(Uint8 * srcbuf)
1652 { 1652 {
1653 #if SDL_BYTEORDER == SDL_LIL_ENDIAN 1653 #if SDL_BYTEORDER == SDL_LIL_ENDIAN
1654 return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16); 1654 return srcbuf[0] + (srcbuf[1] << 8) + (srcbuf[2] << 16);
1655 #else 1655 #else
1656 return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2]; 1656 return (srcbuf[0] << 16) + (srcbuf[1] << 8) + srcbuf[2];
1657 #endif 1657 #endif
1658 } 1658 }
1659 1659
1660 static Uint32 1660 static Uint32
1661 getpix_32 (Uint8 * srcbuf) 1661 getpix_32(Uint8 * srcbuf)
1662 { 1662 {
1663 return *(Uint32 *) srcbuf; 1663 return *(Uint32 *) srcbuf;
1664 } 1664 }
1665 1665
1666 typedef Uint32 (*getpix_func) (Uint8 *); 1666 typedef Uint32(*getpix_func) (Uint8 *);
1667 1667
1668 static getpix_func getpixes[4] = { 1668 static getpix_func getpixes[4] = {
1669 getpix_8, getpix_16, getpix_24, getpix_32 1669 getpix_8, getpix_16, getpix_24, getpix_32
1670 }; 1670 };
1671 1671
1672 static int 1672 static int
1673 RLEColorkeySurface (SDL_Surface * surface) 1673 RLEColorkeySurface(SDL_Surface * surface)
1674 { 1674 {
1675 Uint8 *rlebuf, *dst; 1675 Uint8 *rlebuf, *dst;
1676 int maxn; 1676 int maxn;
1677 int y; 1677 int y;
1678 Uint8 *srcbuf, *curbuf, *lastline; 1678 Uint8 *srcbuf, *curbuf, *lastline;
1701 maxsize = surface->h * (4 * (surface->w / 65535 + 1) 1701 maxsize = surface->h * (4 * (surface->w / 65535 + 1)
1702 + surface->w * 4) + 4; 1702 + surface->w * 4) + 4;
1703 break; 1703 break;
1704 } 1704 }
1705 1705
1706 rlebuf = (Uint8 *) SDL_malloc (maxsize); 1706 rlebuf = (Uint8 *) SDL_malloc(maxsize);
1707 if (rlebuf == NULL) { 1707 if (rlebuf == NULL) {
1708 SDL_OutOfMemory (); 1708 SDL_OutOfMemory();
1709 return (-1); 1709 return (-1);
1710 } 1710 }
1711 1711
1712 /* Set up the conversion */ 1712 /* Set up the conversion */
1713 srcbuf = (Uint8 *) surface->pixels; 1713 srcbuf = (Uint8 *) surface->pixels;
1740 int run, skip, len; 1740 int run, skip, len;
1741 int runstart; 1741 int runstart;
1742 int skipstart = x; 1742 int skipstart = x;
1743 1743
1744 /* find run of transparent, then opaque pixels */ 1744 /* find run of transparent, then opaque pixels */
1745 while (x < w && (getpix (srcbuf + x * bpp) & rgbmask) == ckey) 1745 while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) == ckey)
1746 x++; 1746 x++;
1747 runstart = x; 1747 runstart = x;
1748 while (x < w && (getpix (srcbuf + x * bpp) & rgbmask) != ckey) 1748 while (x < w && (getpix(srcbuf + x * bpp) & rgbmask) != ckey)
1749 x++; 1749 x++;
1750 skip = runstart - skipstart; 1750 skip = runstart - skipstart;
1751 if (skip == w) 1751 if (skip == w)
1752 blankline = 1; 1752 blankline = 1;
1753 run = x - runstart; 1753 run = x - runstart;
1754 1754
1755 /* encode segment */ 1755 /* encode segment */
1756 while (skip > maxn) { 1756 while (skip > maxn) {
1757 ADD_COUNTS (maxn, 0); 1757 ADD_COUNTS(maxn, 0);
1758 skip -= maxn; 1758 skip -= maxn;
1759 } 1759 }
1760 len = MIN (run, maxn); 1760 len = MIN(run, maxn);
1761 ADD_COUNTS (skip, len); 1761 ADD_COUNTS(skip, len);
1762 SDL_memcpy (dst, srcbuf + runstart * bpp, len * bpp); 1762 SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1763 dst += len * bpp; 1763 dst += len * bpp;
1764 run -= len; 1764 run -= len;
1765 runstart += len; 1765 runstart += len;
1766 while (run) { 1766 while (run) {
1767 len = MIN (run, maxn); 1767 len = MIN(run, maxn);
1768 ADD_COUNTS (0, len); 1768 ADD_COUNTS(0, len);
1769 SDL_memcpy (dst, srcbuf + runstart * bpp, len * bpp); 1769 SDL_memcpy(dst, srcbuf + runstart * bpp, len * bpp);
1770 dst += len * bpp; 1770 dst += len * bpp;
1771 runstart += len; 1771 runstart += len;
1772 run -= len; 1772 run -= len;
1773 } 1773 }
1774 if (!blankline) 1774 if (!blankline)
1777 while (x < w); 1777 while (x < w);
1778 1778
1779 srcbuf += surface->pitch; 1779 srcbuf += surface->pitch;
1780 } 1780 }
1781 dst = lastline; /* back up bast trailing blank lines */ 1781 dst = lastline; /* back up bast trailing blank lines */
1782 ADD_COUNTS (0, 0); 1782 ADD_COUNTS(0, 0);
1783 1783
1784 #undef ADD_COUNTS 1784 #undef ADD_COUNTS
1785 1785
1786 /* Now that we have it encoded, release the original pixels */ 1786 /* Now that we have it encoded, release the original pixels */
1787 if ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC 1787 if ((surface->flags & SDL_PREALLOC) != SDL_PREALLOC
1788 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) { 1788 && (surface->flags & SDL_HWSURFACE) != SDL_HWSURFACE) {
1789 SDL_free (surface->pixels); 1789 SDL_free(surface->pixels);
1790 surface->pixels = NULL; 1790 surface->pixels = NULL;
1791 } 1791 }
1792 1792
1793 /* realloc the buffer to release unused memory */ 1793 /* realloc the buffer to release unused memory */
1794 { 1794 {
1795 /* If realloc returns NULL, the original block is left intact */ 1795 /* If realloc returns NULL, the original block is left intact */
1796 Uint8 *p = SDL_realloc (rlebuf, dst - rlebuf); 1796 Uint8 *p = SDL_realloc(rlebuf, dst - rlebuf);
1797 if (!p) 1797 if (!p)
1798 p = rlebuf; 1798 p = rlebuf;
1799 surface->map->sw_data->aux_data = p; 1799 surface->map->sw_data->aux_data = p;
1800 } 1800 }
1801 1801
1802 return (0); 1802 return (0);
1803 } 1803 }
1804 1804
1805 int 1805 int
1806 SDL_RLESurface (SDL_Surface * surface) 1806 SDL_RLESurface(SDL_Surface * surface)
1807 { 1807 {
1808 int retcode; 1808 int retcode;
1809 1809
1810 /* Clear any previous RLE conversion */ 1810 /* Clear any previous RLE conversion */
1811 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 1811 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
1812 SDL_UnRLESurface (surface, 1); 1812 SDL_UnRLESurface(surface, 1);
1813 } 1813 }
1814 1814
1815 /* We don't support RLE encoding of bitmaps */ 1815 /* We don't support RLE encoding of bitmaps */
1816 if (surface->format->BitsPerPixel < 8) { 1816 if (surface->format->BitsPerPixel < 8) {
1817 return (-1); 1817 return (-1);
1818 } 1818 }
1819 1819
1820 /* Lock the surface if it's in hardware */ 1820 /* Lock the surface if it's in hardware */
1821 if (SDL_MUSTLOCK (surface)) { 1821 if (SDL_MUSTLOCK(surface)) {
1822 if (SDL_LockSurface (surface) < 0) { 1822 if (SDL_LockSurface(surface) < 0) {
1823 return (-1); 1823 return (-1);
1824 } 1824 }
1825 } 1825 }
1826 1826
1827 /* Encode */ 1827 /* Encode */
1828 if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { 1828 if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
1829 retcode = RLEColorkeySurface (surface); 1829 retcode = RLEColorkeySurface(surface);
1830 } else { 1830 } else {
1831 if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA 1831 if ((surface->flags & SDL_SRCALPHA) == SDL_SRCALPHA
1832 && surface->format->Amask != 0) 1832 && surface->format->Amask != 0)
1833 retcode = RLEAlphaSurface (surface); 1833 retcode = RLEAlphaSurface(surface);
1834 else 1834 else
1835 retcode = -1; /* no RLE for per-surface alpha sans ckey */ 1835 retcode = -1; /* no RLE for per-surface alpha sans ckey */
1836 } 1836 }
1837 1837
1838 /* Unlock the surface if it's in hardware */ 1838 /* Unlock the surface if it's in hardware */
1839 if (SDL_MUSTLOCK (surface)) { 1839 if (SDL_MUSTLOCK(surface)) {
1840 SDL_UnlockSurface (surface); 1840 SDL_UnlockSurface(surface);
1841 } 1841 }
1842 1842
1843 if (retcode < 0) 1843 if (retcode < 0)
1844 return -1; 1844 return -1;
1845 1845
1854 * This may not give back exactly the image before RLE-encoding; all 1854 * This may not give back exactly the image before RLE-encoding; all
1855 * completely transparent pixels will be lost, and colour and alpha depth 1855 * completely transparent pixels will be lost, and colour and alpha depth
1856 * may have been reduced (when encoding for 16bpp targets). 1856 * may have been reduced (when encoding for 16bpp targets).
1857 */ 1857 */
1858 static SDL_bool 1858 static SDL_bool
1859 UnRLEAlpha (SDL_Surface * surface) 1859 UnRLEAlpha(SDL_Surface * surface)
1860 { 1860 {
1861 Uint8 *srcbuf; 1861 Uint8 *srcbuf;
1862 Uint32 *dst; 1862 Uint32 *dst;
1863 SDL_PixelFormat *sf = surface->format; 1863 SDL_PixelFormat *sf = surface->format;
1864 RLEDestFormat *df = surface->map->sw_data->aux_data; 1864 RLEDestFormat *df = surface->map->sw_data->aux_data;
1874 uncopy_transl = uncopy_transl_16; 1874 uncopy_transl = uncopy_transl_16;
1875 } else { 1875 } else {
1876 uncopy_opaque = uncopy_transl = uncopy_32; 1876 uncopy_opaque = uncopy_transl = uncopy_32;
1877 } 1877 }
1878 1878
1879 surface->pixels = SDL_malloc (surface->h * surface->pitch); 1879 surface->pixels = SDL_malloc(surface->h * surface->pitch);
1880 if (!surface->pixels) { 1880 if (!surface->pixels) {
1881 return (SDL_FALSE); 1881 return (SDL_FALSE);
1882 } 1882 }
1883 /* fill background with transparent pixels */ 1883 /* fill background with transparent pixels */
1884 SDL_memset (surface->pixels, 0, surface->h * surface->pitch); 1884 SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
1885 1885
1886 dst = surface->pixels; 1886 dst = surface->pixels;
1887 srcbuf = (Uint8 *) (df + 1); 1887 srcbuf = (Uint8 *) (df + 1);
1888 for (;;) { 1888 for (;;) {
1889 /* copy opaque pixels */ 1889 /* copy opaque pixels */
1898 ofs += ((Uint16 *) srcbuf)[0]; 1898 ofs += ((Uint16 *) srcbuf)[0];
1899 run = ((Uint16 *) srcbuf)[1]; 1899 run = ((Uint16 *) srcbuf)[1];
1900 srcbuf += 4; 1900 srcbuf += 4;
1901 } 1901 }
1902 if (run) { 1902 if (run) {
1903 srcbuf += uncopy_opaque (dst + ofs, srcbuf, run, df, sf); 1903 srcbuf += uncopy_opaque(dst + ofs, srcbuf, run, df, sf);
1904 ofs += run; 1904 ofs += run;
1905 } else if (!ofs) 1905 } else if (!ofs)
1906 return (SDL_TRUE); 1906 return (SDL_TRUE);
1907 } 1907 }
1908 while (ofs < w); 1908 while (ofs < w);
1917 unsigned run; 1917 unsigned run;
1918 ofs += ((Uint16 *) srcbuf)[0]; 1918 ofs += ((Uint16 *) srcbuf)[0];
1919 run = ((Uint16 *) srcbuf)[1]; 1919 run = ((Uint16 *) srcbuf)[1];
1920 srcbuf += 4; 1920 srcbuf += 4;
1921 if (run) { 1921 if (run) {
1922 srcbuf += uncopy_transl (dst + ofs, srcbuf, run, df, sf); 1922 srcbuf += uncopy_transl(dst + ofs, srcbuf, run, df, sf);
1923 ofs += run; 1923 ofs += run;
1924 } 1924 }
1925 } 1925 }
1926 while (ofs < w); 1926 while (ofs < w);
1927 dst += surface->pitch >> 2; 1927 dst += surface->pitch >> 2;
1929 /* Make the compiler happy */ 1929 /* Make the compiler happy */
1930 return (SDL_TRUE); 1930 return (SDL_TRUE);
1931 } 1931 }
1932 1932
1933 void 1933 void
1934 SDL_UnRLESurface (SDL_Surface * surface, int recode) 1934 SDL_UnRLESurface(SDL_Surface * surface, int recode)
1935 { 1935 {
1936 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) { 1936 if ((surface->flags & SDL_RLEACCEL) == SDL_RLEACCEL) {
1937 surface->flags &= ~SDL_RLEACCEL; 1937 surface->flags &= ~SDL_RLEACCEL;
1938 1938
1939 if (recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC 1939 if (recode && (surface->flags & SDL_PREALLOC) != SDL_PREALLOC
1941 if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) { 1941 if ((surface->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
1942 SDL_Rect full; 1942 SDL_Rect full;
1943 unsigned alpha_flag; 1943 unsigned alpha_flag;
1944 1944
1945 /* re-create the original surface */ 1945 /* re-create the original surface */
1946 surface->pixels = SDL_malloc (surface->h * surface->pitch); 1946 surface->pixels = SDL_malloc(surface->h * surface->pitch);
1947 if (!surface->pixels) { 1947 if (!surface->pixels) {
1948 /* Oh crap... */ 1948 /* Oh crap... */
1949 surface->flags |= SDL_RLEACCEL; 1949 surface->flags |= SDL_RLEACCEL;
1950 return; 1950 return;
1951 } 1951 }
1952 1952
1953 /* fill it with the background colour */ 1953 /* fill it with the background colour */
1954 SDL_FillRect (surface, NULL, surface->format->colorkey); 1954 SDL_FillRect(surface, NULL, surface->format->colorkey);
1955 1955
1956 /* now render the encoded surface */ 1956 /* now render the encoded surface */
1957 full.x = full.y = 0; 1957 full.x = full.y = 0;
1958 full.w = surface->w; 1958 full.w = surface->w;
1959 full.h = surface->h; 1959 full.h = surface->h;
1960 alpha_flag = surface->flags & SDL_SRCALPHA; 1960 alpha_flag = surface->flags & SDL_SRCALPHA;
1961 surface->flags &= ~SDL_SRCALPHA; /* opaque blit */ 1961 surface->flags &= ~SDL_SRCALPHA; /* opaque blit */
1962 SDL_RLEBlit (surface, &full, surface, &full); 1962 SDL_RLEBlit(surface, &full, surface, &full);
1963 surface->flags |= alpha_flag; 1963 surface->flags |= alpha_flag;
1964 } else { 1964 } else {
1965 if (!UnRLEAlpha (surface)) { 1965 if (!UnRLEAlpha(surface)) {
1966 /* Oh crap... */ 1966 /* Oh crap... */
1967 surface->flags |= SDL_RLEACCEL; 1967 surface->flags |= SDL_RLEACCEL;
1968 return; 1968 return;
1969 } 1969 }
1970 } 1970 }
1971 } 1971 }
1972 1972
1973 if (surface->map && surface->map->sw_data->aux_data) { 1973 if (surface->map && surface->map->sw_data->aux_data) {
1974 SDL_free (surface->map->sw_data->aux_data); 1974 SDL_free(surface->map->sw_data->aux_data);
1975 surface->map->sw_data->aux_data = NULL; 1975 surface->map->sw_data->aux_data = NULL;
1976 } 1976 }
1977 } 1977 }
1978 } 1978 }
1979 1979