Use range_for in rle
This commit is contained in:
parent
c2d308807c
commit
2df4bea9b5
|
@ -37,9 +37,15 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
|
||||||
#include "rle.h"
|
#include "rle.h"
|
||||||
#include "byteutil.h"
|
#include "byteutil.h"
|
||||||
|
|
||||||
#define RLE_CODE 0xE0
|
#include "compiler-range_for.h"
|
||||||
#define NOT_RLE_CODE 31
|
|
||||||
#define IS_RLE_CODE(x) (((x) & RLE_CODE) == RLE_CODE)
|
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)
|
#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)
|
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++;
|
color = *src++;
|
||||||
if ( color == RLE_CODE ) return;
|
if ( color == RLE_CODE ) return;
|
||||||
if ( IS_RLE_CODE(color) ) {
|
if ( IS_RLE_CODE(color) ) {
|
||||||
count = color & (~RLE_CODE);
|
count = color & NOT_RLE_CODE;
|
||||||
color = *src++;
|
color = *src++;
|
||||||
} else {
|
} else {
|
||||||
// unique
|
// unique
|
||||||
|
@ -112,7 +118,7 @@ void gr_rle_expand_scanline_masked( ubyte *dest, ubyte *src, int x1, int x2 )
|
||||||
color = *src++;
|
color = *src++;
|
||||||
if ( color == RLE_CODE ) return;
|
if ( color == RLE_CODE ) return;
|
||||||
if ( IS_RLE_CODE(color) ) {
|
if ( IS_RLE_CODE(color) ) {
|
||||||
count = color & (~RLE_CODE);
|
count = color & NOT_RLE_CODE;
|
||||||
color = *src++;
|
color = *src++;
|
||||||
} else {
|
} else {
|
||||||
// unique
|
// unique
|
||||||
|
@ -145,7 +151,7 @@ void gr_rle_expand_scanline( ubyte *dest, ubyte *src, int x1, int x2 )
|
||||||
color = *src++;
|
color = *src++;
|
||||||
if ( color == RLE_CODE ) return;
|
if ( color == RLE_CODE ) return;
|
||||||
if ( IS_RLE_CODE(color) ) {
|
if ( IS_RLE_CODE(color) ) {
|
||||||
count = color & (~RLE_CODE);
|
count = color & NOT_RLE_CODE;
|
||||||
color = *src++;
|
color = *src++;
|
||||||
} else {
|
} else {
|
||||||
// unique
|
// 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 c, oc;
|
||||||
ubyte count;
|
ubyte count;
|
||||||
|
@ -286,7 +292,7 @@ int gr_rle_getsize( int org_size, ubyte *src )
|
||||||
|
|
||||||
int gr_bitmap_rle_compress( grs_bitmap * bmp )
|
int gr_bitmap_rle_compress( grs_bitmap * bmp )
|
||||||
{
|
{
|
||||||
int d1, d;
|
int d1;
|
||||||
int doffset;
|
int doffset;
|
||||||
int large_rle = 0;
|
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) ) ) {
|
if ( ((doffset+d1) > bmp->bm_w*bmp->bm_h) || (d1 > (large_rle?32767:255) ) ) {
|
||||||
return 0;
|
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 );
|
Assert( d==d1 );
|
||||||
doffset += d;
|
doffset += d;
|
||||||
if (large_rle)
|
if (large_rle)
|
||||||
|
@ -351,27 +357,28 @@ void rle_cache_close(void)
|
||||||
{
|
{
|
||||||
if (rle_cache_initialized) {
|
if (rle_cache_initialized) {
|
||||||
rle_cache_initialized = 0;
|
rle_cache_initialized = 0;
|
||||||
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
|
range_for (auto &i, rle_cache)
|
||||||
rle_cache[i].expanded_bitmap.reset();
|
i.expanded_bitmap.reset();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rle_cache_init()
|
static void rle_cache_init()
|
||||||
{
|
{
|
||||||
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
|
range_for (auto &i, rle_cache)
|
||||||
rle_cache[i].rle_bitmap = NULL;
|
{
|
||||||
rle_cache[i].expanded_bitmap = NULL;
|
i.rle_bitmap = NULL;
|
||||||
rle_cache[i].last_used = 0;
|
i.expanded_bitmap = NULL;
|
||||||
|
i.last_used = 0;
|
||||||
}
|
}
|
||||||
rle_cache_initialized = 1;
|
rle_cache_initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rle_cache_flush()
|
void rle_cache_flush()
|
||||||
{
|
{
|
||||||
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
|
range_for (auto &i, rle_cache)
|
||||||
rle_cache[i].rle_bitmap = NULL;
|
{
|
||||||
rle_cache[i].last_used = 0;
|
i.rle_bitmap = NULL;
|
||||||
|
i.last_used = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,9 +415,10 @@ grs_bitmap * rle_expand_texture( grs_bitmap * bmp )
|
||||||
rle_counter = 0;
|
rle_counter = 0;
|
||||||
|
|
||||||
if ( rle_counter < lc ) {
|
if ( rle_counter < lc ) {
|
||||||
for (int i=0; i<MAX_CACHE_BITMAPS; i++ ) {
|
range_for (auto &i, rle_cache)
|
||||||
rle_cache[i].rle_bitmap = NULL;
|
{
|
||||||
rle_cache[i].last_used = 0;
|
i.rle_bitmap = NULL;
|
||||||
|
i.last_used = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,19 +57,19 @@ struct g3s_codes {
|
||||||
};
|
};
|
||||||
|
|
||||||
//flags for point structure
|
//flags for point structure
|
||||||
#define PF_PROJECTED 1 //has been projected, so sx,sy valid
|
const uint8_t PF_PROJECTED = 1; //has been projected, so sx,sy valid
|
||||||
#define PF_OVERFLOW 2 //can't project
|
const uint8_t PF_OVERFLOW = 2; //can't project
|
||||||
#define PF_TEMP_POINT 4 //created during clip
|
const uint8_t PF_TEMP_POINT = 4; //created during clip
|
||||||
#define PF_UVS 8 //has uv values set
|
const uint8_t PF_UVS = 8; //has uv values set
|
||||||
#define PF_LS 16 //has lighting values set
|
const uint8_t PF_LS = 16; //has lighting values set
|
||||||
|
|
||||||
//clipping codes flags
|
//clipping codes flags
|
||||||
|
|
||||||
#define CC_OFF_LEFT 1
|
const uint8_t CC_OFF_LEFT = 1;
|
||||||
#define CC_OFF_RIGHT 2
|
const uint8_t CC_OFF_RIGHT = 2;
|
||||||
#define CC_OFF_BOT 4
|
const uint8_t CC_OFF_BOT = 4;
|
||||||
#define CC_OFF_TOP 8
|
const uint8_t CC_OFF_TOP = 8;
|
||||||
#define CC_BEHIND 0x80
|
const uint8_t CC_BEHIND = 0x80;
|
||||||
|
|
||||||
//Used to store rotated points for mines. Has frame count to indictate
|
//Used to store rotated points for mines. Has frame count to indictate
|
||||||
//if rotated, and flag to indicate if projected.
|
//if rotated, and flag to indicate if projected.
|
||||||
|
|
|
@ -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);
|
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 );
|
int gr_rle_getsize( int org_size, ubyte *src );
|
||||||
ubyte * gr_rle_find_xth_pixel( ubyte *src, int x,int * count, ubyte color );
|
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 );
|
||||||
|
|
Loading…
Reference in a new issue