From 912253ab005c34d18f33a2024ea921b07a46205e Mon Sep 17 00:00:00 2001 From: Kp Date: Thu, 29 Jan 2015 04:27:37 +0000 Subject: [PATCH] Pass gr_bitmap_rle_compress arg by & --- common/2d/rle.cpp | 26 +++++++++++++------------- common/include/rle.h | 3 ++- similar/main/piggy.cpp | 9 ++++++--- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/common/2d/rle.cpp b/common/2d/rle.cpp index 3c505ea20..41f4ae7e7 100644 --- a/common/2d/rle.cpp +++ b/common/2d/rle.cpp @@ -289,7 +289,7 @@ static unsigned gr_rle_getsize(int org_size, const uint8_t *src) return dest_size; } -int gr_bitmap_rle_compress( grs_bitmap * bmp ) +int gr_bitmap_rle_compress(grs_bitmap &bmp) { int d1; int doffset; @@ -297,8 +297,8 @@ int gr_bitmap_rle_compress( grs_bitmap * bmp ) // first must check to see if this is large bitmap. - for (int y=0; ybm_h; y++ ) { - d1= gr_rle_getsize( bmp->bm_w, &bmp->bm_data[bmp->bm_w*y] ); + for (int y=0; y 255) { large_rle = 1; break; @@ -306,19 +306,19 @@ int gr_bitmap_rle_compress( grs_bitmap * bmp ) } RAIIdmem rle_data; - MALLOC(rle_data, uint8_t[], MAX_BMP_SIZE(bmp->bm_w, bmp->bm_h)); + MALLOC(rle_data, uint8_t[], MAX_BMP_SIZE(bmp.bm_w, bmp.bm_h)); if (!rle_data) return 0; if (!large_rle) - doffset = 4 + bmp->bm_h; + doffset = 4 + bmp.bm_h; else - doffset = 4 + (2 * bmp->bm_h); // each row of rle'd bitmap has short instead of byte offset now + doffset = 4 + (2 * bmp.bm_h); // each row of rle'd bitmap has short instead of byte offset now - for (int y=0; ybm_h; y++ ) { - d1= gr_rle_getsize( bmp->bm_w, &bmp->bm_data[bmp->bm_w*y] ); - if ( ((doffset+d1) > bmp->bm_w*bmp->bm_h) || (d1 > (large_rle?32767:255) ) ) { + for (int y=0; y bmp.bm_w*bmp.bm_h) || (d1 > (large_rle?32767:255) ) ) { return 0; } - const auto d = gr_rle_encode( bmp->bm_w, &bmp->get_bitmap_data()[bmp->bm_w*y], &rle_data[doffset] ); + const auto d = gr_rle_encode( bmp.bm_w, &bmp.get_bitmap_data()[bmp.bm_w*y], &rle_data[doffset] ); Assert( d==d1 ); doffset += d; if (large_rle) @@ -327,10 +327,10 @@ int gr_bitmap_rle_compress( grs_bitmap * bmp ) rle_data[y+4] = d; } memcpy( rle_data, &doffset, 4 ); - memcpy(bmp->get_bitmap_data(), rle_data, doffset ); - bmp->bm_flags |= BM_FLAG_RLE; + memcpy(bmp.get_bitmap_data(), rle_data, doffset ); + bmp.bm_flags |= BM_FLAG_RLE; if (large_rle) - bmp->bm_flags |= BM_FLAG_RLE_BIG; + bmp.bm_flags |= BM_FLAG_RLE_BIG; return 1; } diff --git a/common/include/rle.h b/common/include/rle.h index be91509e8..2e3f0e83f 100644 --- a/common/include/rle.h +++ b/common/include/rle.h @@ -61,9 +61,10 @@ static inline rle_position_t rle_end(const T1 &src, T2 &dst) return {end(src), end(dst)}; } +__attribute_warn_unused_result rle_position_t gr_rle_decode(rle_position_t b, const rle_position_t e); ubyte * gr_rle_find_xth_pixel( ubyte *src, int x,int * count, ubyte color ); -int gr_bitmap_rle_compress( grs_bitmap * bmp ); +int gr_bitmap_rle_compress(grs_bitmap &bmp); void gr_rle_expand_scanline_masked(uint8_t *dest, const uint8_t *src, int x1, int x2); void gr_rle_expand_scanline(uint8_t *dest, const uint8_t *src, int x1, int x2); grs_bitmap *_rle_expand_texture(const grs_bitmap &bmp); diff --git a/similar/main/piggy.cpp b/similar/main/piggy.cpp index a58443395..c5be574a9 100644 --- a/similar/main/piggy.cpp +++ b/similar/main/piggy.cpp @@ -291,7 +291,8 @@ bitmap_index piggy_register_bitmap( grs_bitmap * bmp, const char * name, int in_ swap_0_255( bmp ); #endif #endif - if ( GameArg.DbgNoCompressPigBitmap ) gr_bitmap_rle_compress( bmp ); + if (GameArg.DbgNoCompressPigBitmap) + gr_bitmap_rle_compress(*bmp); Num_bitmap_files_new++; } #if defined(DXX_BUILD_DESCENT_II) @@ -869,7 +870,8 @@ void piggy_new_pigfile(char *pigname) if ( GameArg.EdiMacData ) swap_0_255( bm[fnum].get() ); - if ( GameArg.DbgNoCompressPigBitmap ) gr_bitmap_rle_compress( bm[fnum].get() ); + if (GameArg.DbgNoCompressPigBitmap) + gr_bitmap_rle_compress(*bm[fnum].get()); if (bm[fnum]->bm_flags & BM_FLAG_RLE) size = *((int *) bm[fnum]->bm_data); @@ -915,7 +917,8 @@ void piggy_new_pigfile(char *pigname) if ( GameArg.EdiMacData ) swap_0_255( &n ); - if ( GameArg.DbgNoCompressPigBitmap ) gr_bitmap_rle_compress( &n ); + if (GameArg.DbgNoCompressPigBitmap) + gr_bitmap_rle_compress(n); if (n.bm_flags & BM_FLAG_RLE) size = *((int *) n.bm_data);