mitsuba-af602c6fd98a/src/libcore/bitmap.cpp
/* The code below is only needed for the run-length encoded files.
	   Run length encoding adds considerable complexity but does
	   save some space.  For each scanline, each channel (r,g,b,e) is
	   encoded separately for better compression. */
The code below is only needed for the run-length encoded files.
Run length encoding adds considerable complexity but does
save some space.  For each scanline, each channel (r,g,b,e) is
encoded separately for better compression.
The code below is only needed for the run - length encoded files . Run length encoding adds considerable complexity but does save some space . For each scanline each channel ( r g b e ) is encoded separately for better compression .
static inline void RGBE_WriteBytes_RLE(Stream *stream, uint8_t *data, int numbytes) {
		int cur = 0;
		uint8_t buf[2];
		while (cur < numbytes) {
			int beg_run = cur;
			int run_count = 0, old_run_count = 0;
			while (run_count < 4 && beg_run < numbytes) {
				beg_run += run_count;
				old_run_count = run_count;
				run_count = 1;
				while( (beg_run + run_count < numbytes) && (run_count < 127)
					&& (data[beg_run] == data[beg_run + run_count]))
					run_count++;
			}
			if (old_run_count > 1 && old_run_count == beg_run - cur) {
				buf[0] = 128 + old_run_count;   
				buf[1] = data[cur];
				stream->write(buf, 2);
				cur = beg_run;
			}
			while (cur < beg_run) {
				int nonrun_count = beg_run - cur;
				if (nonrun_count > 128)
					nonrun_count = 128;
				buf[0] = nonrun_count;
				stream->write(buf, 1);
				stream->write(&data[cur], nonrun_count);
				cur += nonrun_count;
			}
			if (run_count >= 4) {
				buf[0] = 128 + run_count;
				buf[1] = data[beg_run];
				stream->write(buf, 2);
				cur += run_count;
			}
		}
	}
static inline void RGBE_WriteBytes_RLE ( Stream * stream , uint8_t * data , int numbytes ) { int cur = 0 ; uint8_t buf [ 2 ] ; while ( cur < numbytes ) { int beg_run = cur ; int run_count = 0 , old_run_count = 0 ; while ( run_count < 4 && beg_run < numbytes ) { beg_run += run_count ; old_run_count = run_count ; run_count = 1 ; while ( ( beg_run + run_count < numbytes ) && ( run_count < 127 ) && ( data [ beg_run ] == data [ beg_run + run_count ] ) ) run_count ++ ; } if ( old_run_count > 1 && old_run_count == beg_run - cur ) { buf [ 0 ] = 128 + old_run_count ; buf [ 1 ] = data [ cur ] ; stream -> write ( buf , 2 ) ; cur = beg_run ; } while ( cur < beg_run ) { int nonrun_count = beg_run - cur ; if ( nonrun_count > 128 ) nonrun_count = 128 ; buf [ 0 ] = nonrun_count ; stream -> write ( buf , 1 ) ; stream -> write ( & data [ cur ] , nonrun_count ) ; cur += nonrun_count ; } if ( run_count >= 4 ) { buf [ 0 ] = 128 + run_count ; buf [ 1 ] = data [ beg_run ] ; stream -> write ( buf , 2 ) ; cur += run_count ; } } }
The code below is only needed for the run-length encoded files.
The code below is only needed for the run - length encoded files .
/* find next run of length at least 4 if one exists */ /* if data before next big run is a short run then write it as such */ /*write short run*/ /* write out bytes until we reach the start of the next run */ /* write out next run if one was found */