comparison src/video/SDL_RLEaccel.c @ 526:4314a501d7be

Fixed a crash blitting RLE surfaces to RLE surfaces
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Oct 2002 07:56:36 +0000
parents f6ffac90895c
children 5bb080d35049
comparison
equal deleted inserted replaced
525:f55cdaec12b9 526:4314a501d7be
461 int x, y; 461 int x, y;
462 int w = src->w; 462 int w = src->w;
463 unsigned alpha; 463 unsigned alpha;
464 464
465 /* Lock the destination if necessary */ 465 /* Lock the destination if necessary */
466 if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 466 if ( SDL_MUSTLOCK(dst) ) {
467 SDL_VideoDevice *video = current_video; 467 if ( SDL_LockSurface(dst) < 0 ) {
468 SDL_VideoDevice *this = current_video;
469 if ( video->LockHWSurface(this, dst) < 0 ) {
470 return(-1); 468 return(-1);
471 } 469 }
472 } 470 }
473 471
474 /* Set up the source and destination pointers */ 472 /* Set up the source and destination pointers */
475 x = dstrect->x; 473 x = dstrect->x;
476 y = dstrect->y; 474 y = dstrect->y;
477 dstbuf = (Uint8 *)dst->pixels + dst->offset 475 dstbuf = (Uint8 *)dst->pixels
478 + y * dst->pitch + x * src->format->BytesPerPixel; 476 + y * dst->pitch + x * src->format->BytesPerPixel;
479 srcbuf = (Uint8 *)src->map->sw_data->aux_data; 477 srcbuf = (Uint8 *)src->map->sw_data->aux_data;
480 478
481 { 479 {
482 /* skip lines at the top if neccessary */ 480 /* skip lines at the top if neccessary */
551 #undef RLEBLIT 549 #undef RLEBLIT
552 } 550 }
553 551
554 done: 552 done:
555 /* Unlock the destination if necessary */ 553 /* Unlock the destination if necessary */
556 if ( dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 554 if ( SDL_MUSTLOCK(dst) ) {
557 SDL_VideoDevice *video = current_video; 555 SDL_UnlockSurface(dst);
558 SDL_VideoDevice *this = current_video;
559 video->UnlockHWSurface(this, dst);
560 } 556 }
561 return(0); 557 return(0);
562 } 558 }
563 559
564 #undef OPAQUE_BLIT 560 #undef OPAQUE_BLIT
731 int w = src->w; 727 int w = src->w;
732 Uint8 *srcbuf, *dstbuf; 728 Uint8 *srcbuf, *dstbuf;
733 SDL_PixelFormat *df = dst->format; 729 SDL_PixelFormat *df = dst->format;
734 730
735 /* Lock the destination if necessary */ 731 /* Lock the destination if necessary */
736 if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) { 732 if ( SDL_MUSTLOCK(dst) ) {
737 SDL_VideoDevice *video = current_video; 733 if ( SDL_LockSurface(dst) < 0 ) {
738 SDL_VideoDevice *this = current_video;
739 if(video->LockHWSurface(this, dst) < 0) {
740 return -1; 734 return -1;
741 } 735 }
742 } 736 }
743 737
744 x = dstrect->x; 738 x = dstrect->x;
745 y = dstrect->y; 739 y = dstrect->y;
746 dstbuf = (Uint8 *)dst->pixels + dst->offset 740 dstbuf = (Uint8 *)dst->pixels
747 + y * dst->pitch + x * df->BytesPerPixel; 741 + y * dst->pitch + x * df->BytesPerPixel;
748 srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat); 742 srcbuf = (Uint8 *)src->map->sw_data->aux_data + sizeof(RLEDestFormat);
749 743
750 { 744 {
751 /* skip lines at the top if necessary */ 745 /* skip lines at the top if necessary */
872 } 866 }
873 } 867 }
874 868
875 done: 869 done:
876 /* Unlock the destination if necessary */ 870 /* Unlock the destination if necessary */
877 if(dst->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT)) { 871 if ( SDL_MUSTLOCK(dst) ) {
878 SDL_VideoDevice *video = current_video; 872 SDL_UnlockSurface(dst);
879 SDL_VideoDevice *this = current_video;
880 video->UnlockHWSurface(this, dst);
881 } 873 }
882 return 0; 874 return 0;
883 } 875 }
884 876
885 /* 877 /*
1115 /* Do the actual encoding */ 1107 /* Do the actual encoding */
1116 { 1108 {
1117 int x, y; 1109 int x, y;
1118 int h = surface->h, w = surface->w; 1110 int h = surface->h, w = surface->w;
1119 SDL_PixelFormat *sf = surface->format; 1111 SDL_PixelFormat *sf = surface->format;
1120 Uint32 *src = (Uint32 *)((Uint8 *)surface->pixels + surface->offset); 1112 Uint32 *src = (Uint32 *)surface->pixels;
1121 Uint8 *lastline = dst; /* end of last non-blank line */ 1113 Uint8 *lastline = dst; /* end of last non-blank line */
1122 1114
1123 /* opaque counts are 8 or 16 bits, depending on target depth */ 1115 /* opaque counts are 8 or 16 bits, depending on target depth */
1124 #define ADD_OPAQUE_COUNTS(n, m) \ 1116 #define ADD_OPAQUE_COUNTS(n, m) \
1125 if(df->BytesPerPixel == 4) { \ 1117 if(df->BytesPerPixel == 4) { \
1301 SDL_OutOfMemory(); 1293 SDL_OutOfMemory();
1302 return(-1); 1294 return(-1);
1303 } 1295 }
1304 1296
1305 /* Set up the conversion */ 1297 /* Set up the conversion */
1306 srcbuf = (Uint8 *)surface->pixels+surface->offset; 1298 srcbuf = (Uint8 *)surface->pixels;
1307 curbuf = srcbuf; 1299 curbuf = srcbuf;
1308 maxn = bpp == 4 ? 65535 : 255; 1300 maxn = bpp == 4 ? 65535 : 255;
1309 skip = run = 0; 1301 skip = run = 0;
1310 dst = rlebuf; 1302 dst = rlebuf;
1311 rgbmask = ~surface->format->Amask; 1303 rgbmask = ~surface->format->Amask;
1407 if ( surface->format->BitsPerPixel < 8 ) { 1399 if ( surface->format->BitsPerPixel < 8 ) {
1408 return(-1); 1400 return(-1);
1409 } 1401 }
1410 1402
1411 /* Lock the surface if it's in hardware */ 1403 /* Lock the surface if it's in hardware */
1412 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 1404 if ( SDL_MUSTLOCK(surface) ) {
1413 SDL_VideoDevice *video = current_video; 1405 if ( SDL_LockSurface(surface) < 0 ) {
1414 SDL_VideoDevice *this = current_video;
1415 if ( video->LockHWSurface(this, surface) < 0 ) {
1416 return(-1); 1406 return(-1);
1417 } 1407 }
1418 } 1408 }
1419 1409
1420 /* Encode */ 1410 /* Encode */
1427 else 1417 else
1428 retcode = -1; /* no RLE for per-surface alpha sans ckey */ 1418 retcode = -1; /* no RLE for per-surface alpha sans ckey */
1429 } 1419 }
1430 1420
1431 /* Unlock the surface if it's in hardware */ 1421 /* Unlock the surface if it's in hardware */
1432 if ( surface->flags & (SDL_HWSURFACE|SDL_ASYNCBLIT) ) { 1422 if ( SDL_MUSTLOCK(surface) ) {
1433 SDL_VideoDevice *video = current_video; 1423 SDL_UnlockSurface(surface);
1434 SDL_VideoDevice *this = current_video;
1435 video->UnlockHWSurface(this, surface);
1436 } 1424 }
1437 1425
1438 if(retcode < 0) 1426 if(retcode < 0)
1439 return -1; 1427 return -1;
1440 1428