Use range_for in rle

This commit is contained in:
Kp 2014-11-15 03:10:09 +00:00
parent c2d308807c
commit 2df4bea9b5
3 changed files with 40 additions and 33 deletions

View file

@ -37,9 +37,15 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
#include "rle.h"
#include "byteutil.h"
#define RLE_CODE 0xE0
#define NOT_RLE_CODE 31
#define IS_RLE_CODE(x) (((x) & RLE_CODE) == RLE_CODE)
#include "compiler-range_for.h"
const uint8_t RLE_CODE = 0xe0;
const uint8_t NOT_RLE_CODE = 0x1f;
static_assert((RLE_CODE | NOT_RLE_CODE) == 0xff, "RLE mask error");
static inline int IS_RLE_CODE(const uint8_t &x)
{
return (x & RLE_CODE) == RLE_CODE;
}
#define rle_stosb(_dest, _len, _color) memset(_dest,_color,_len)
rle_position_t gr_rle_decode(rle_position_t b, const rle_position_t e)
@ -85,7 +91,7 @@ void gr_rle_expand_scanline_masked( ubyte *dest, ubyte *src, int x1, int x2 )
color = *src++;
if ( color == RLE_CODE ) return;
if ( IS_RLE_CODE(color) ) {
count = color & (~RLE_CODE);
count = color & NOT_RLE_CODE;
color = *src++;
} else {
// unique
@ -112,7 +118,7 @@ void gr_rle_expand_scanline_masked( ubyte *dest, ubyte *src, int x1, int x2 )
color = *src++;
if ( color == RLE_CODE ) return;
if ( IS_RLE_CODE(color) ) {
count = color & (~RLE_CODE);
count = color & NOT_RLE_CODE;
color = *src++;
} else {
// unique
@ -145,7 +151,7 @@ void gr_rle_expand_scanline( ubyte *dest, ubyte *src, int x1, int x2 )
color = *src++;
if ( color == RLE_CODE ) return;
if ( IS_RLE_CODE(color) ) {
count = color & (~RLE_CODE);
count = color & NOT_RLE_CODE;
color = *src++;
} else {
// unique
@ -191,7 +197,7 @@ void gr_rle_expand_scanline( ubyte *dest, ubyte *src, int x1, int x2 )
}
}
int gr_rle_encode( int org_size, ubyte *src, ubyte *dest )
static std::ptrdiff_t gr_rle_encode( int org_size, const uint8_t *src, ubyte *dest )
{
ubyte c, oc;
ubyte count;
@ -286,7 +292,7 @@ int gr_rle_getsize( int org_size, ubyte *src )
int gr_bitmap_rle_compress( grs_bitmap * bmp )
{
int d1, d;
int d1;
int doffset;
int large_rle = 0;
@ -313,7 +319,7 @@ int gr_bitmap_rle_compress( grs_bitmap * bmp )
if ( ((doffset+d1) > bmp->bm_w*bmp->bm_h) || (d1 > (large_rle?32767:255) ) ) {
return 0;
}
d = gr_rle_encode( bmp->bm_w, &bmp->bm_data[bmp->bm_w*y], &rle_data[doffset] );
const auto d = gr_rle_encode( bmp->bm_w, &bmp->bm_data[bmp->bm_w*y], &rle_data[doffset] );
Assert( d==d1 );
doffset += d;
if (large_rle)
@ -351,27 +357,28 @@ void rle_cache_close(void)
{
if (rle_cache_initialized) {
rle_cache_initialized = 0;
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
rle_cache[i].expanded_bitmap.reset();
}
range_for (auto &i, rle_cache)
i.expanded_bitmap.reset();
}
}
static void rle_cache_init()
{
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
rle_cache[i].rle_bitmap = NULL;
rle_cache[i].expanded_bitmap = NULL;
rle_cache[i].last_used = 0;
range_for (auto &i, rle_cache)
{
i.rle_bitmap = NULL;
i.expanded_bitmap = NULL;
i.last_used = 0;
}
rle_cache_initialized = 1;
}
void rle_cache_flush()
{
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
rle_cache[i].rle_bitmap = NULL;
rle_cache[i].last_used = 0;
range_for (auto &i, rle_cache)
{
i.rle_bitmap = NULL;
i.last_used = 0;
}
}
@ -408,9 +415,10 @@ grs_bitmap * rle_expand_texture( grs_bitmap * bmp )
rle_counter = 0;
if ( rle_counter < lc ) {
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
rle_cache[i].rle_bitmap = NULL;
rle_cache[i].last_used = 0;
range_for (auto &i, rle_cache)
{
i.rle_bitmap = NULL;
i.last_used = 0;
}
}

View file

@ -57,19 +57,19 @@ struct g3s_codes {
};
//flags for point structure
#define PF_PROJECTED 1 //has been projected, so sx,sy valid
#define PF_OVERFLOW 2 //can't project
#define PF_TEMP_POINT 4 //created during clip
#define PF_UVS 8 //has uv values set
#define PF_LS 16 //has lighting values set
const uint8_t PF_PROJECTED = 1; //has been projected, so sx,sy valid
const uint8_t PF_OVERFLOW = 2; //can't project
const uint8_t PF_TEMP_POINT = 4; //created during clip
const uint8_t PF_UVS = 8; //has uv values set
const uint8_t PF_LS = 16; //has lighting values set
//clipping codes flags
#define CC_OFF_LEFT 1
#define CC_OFF_RIGHT 2
#define CC_OFF_BOT 4
#define CC_OFF_TOP 8
#define CC_BEHIND 0x80
const uint8_t CC_OFF_LEFT = 1;
const uint8_t CC_OFF_RIGHT = 2;
const uint8_t CC_OFF_BOT = 4;
const uint8_t CC_OFF_TOP = 8;
const uint8_t CC_BEHIND = 0x80;
//Used to store rotated points for mines. Has frame count to indictate
//if rotated, and flag to indicate if projected.

View file

@ -62,7 +62,6 @@ static inline rle_position_t rle_end(const T1 &src, T2 &dst)
}
rle_position_t gr_rle_decode(rle_position_t b, const rle_position_t e);
int gr_rle_encode( int org_size, ubyte *src, ubyte *dest );
int gr_rle_getsize( int org_size, ubyte *src );
ubyte * gr_rle_find_xth_pixel( ubyte *src, int x,int * count, ubyte color );
int gr_bitmap_rle_compress( grs_bitmap * bmp );