small rad cleanups

This commit is contained in:
John Cupitt 2013-11-05 14:51:24 +00:00
parent 20410b79ef
commit 9a06b2cea7
2 changed files with 28 additions and 45 deletions

9
TODO
View File

@ -1,11 +1,4 @@
- check rad write again - drag display control slider, broken
vips copy x.jpg x.hdr
vips copy x.hdr x2.jpg
should this be an identity op?
drag display control slider, broken
- do conv and morph quickly as simple wrappers over the vips7 operations - do conv and morph quickly as simple wrappers over the vips7 operations

View File

@ -11,7 +11,7 @@
* 4/11/13 * 4/11/13
* - support sequential read * - support sequential read
* 5/11/13 * 5/11/13
* - rewritten read and write, now much faster * - rewritten scanline encode and decode, now much faster
*/ */
/* /*
@ -803,62 +803,52 @@ scanline_write( COLR *scanline, int width, FILE *fp )
PUTC( width >> 8 ); PUTC( width >> 8 );
PUTC( width & 255 ); PUTC( width & 255 );
cnt = 1;
for( i = 0; i < 4; i++ ) { for( i = 0; i < 4; i++ ) {
for( j = 0; j < width; j += cnt ) { for( j = 0; j < width; ) {
/* Search for next run. /* Set beg / cnt to the start and length of the next
* run longer than MINRUN.
*/ */
for( beg = j; beg < width; beg += cnt ) { for( beg = j; beg < width; beg += cnt ) {
for( cnt = 1; cnt < 127 && for( cnt = 1;
cnt < 127 &&
beg + cnt < width && beg + cnt < width &&
scanline[beg + cnt][i] == scanline[beg + cnt][i] ==
scanline[beg][i]; cnt++ ) scanline[beg][i];
cnt++ )
; ;
if( cnt >= MINRUN ) if( cnt >= MINRUN )
break; break;
} }
if( beg - j > 1 && /* Code pixels leading up to the run as a set of
beg - j < MINRUN ) { * non-runs.
c2 = j + 1;
while( scanline[c2++][i] == scanline[j][i] )
if( c2 == beg ) {
/* Short run.
*/ */
PUTC( 128 + beg - j );
PUTC( scanline[j][i] );
j = beg;
break;
}
}
while( j < beg ) { while( j < beg ) {
/* Non-run. int len = VIPS_MIN( 128, beg - j );
*/ COLR *p = scanline + j;
c2 = VIPS_MIN( beg - j, 128 );
PUTC( c2 ); int k;
while( c2-- )
PUTC( scanline[j++][i] ); PUTC( len );
for( k = 0; k < len; k++ )
PUTC( p[k][i] );
j += len;
} }
if( cnt >= MINRUN ) { /* Code the run we found, if any
/* Run.
*/ */
if( cnt >= MINRUN ) {
PUTC( 128 + cnt ); PUTC( 128 + cnt );
PUTC( scanline[beg][i] ); PUTC( scanline[j][i] );
j += cnt;
} }
else
cnt = 0;
} }
} }
return( fwrite( buffer, 1, buffer_pos, fp ) - buffer_pos ); return( fwrite( buffer, 1, buffer_pos, fp ) - buffer_pos );
} }
/* What we track during radiance file read. /* What we track during radiance file read.
*/ */
typedef struct { typedef struct {
@ -899,6 +889,7 @@ read_destroy( VipsObject *object, Read *read )
{ {
VIPS_FREE( read->filename ); VIPS_FREE( read->filename );
VIPS_FREEF( fclose, read->fin ); VIPS_FREEF( fclose, read->fin );
buffer_init( NULL );
} }
static Read * static Read *
@ -1047,7 +1038,6 @@ rad2vips_generate( VipsRegion *or,
void *seq, void *a, void *b, gboolean *stop ) void *seq, void *a, void *b, gboolean *stop )
{ {
VipsRect *r = &or->valid; VipsRect *r = &or->valid;
Read *read = (Read *) a;
int y; int y;
@ -1216,8 +1206,8 @@ vips2rad_put_data_block( VipsRegion *region, Rect *area, void *a )
for( i = 0; i < area->height; i++ ) { for( i = 0; i < area->height; i++ ) {
VipsPel *p = VIPS_REGION_ADDR( region, 0, area->top + i ); VipsPel *p = VIPS_REGION_ADDR( region, 0, area->top + i );
//if( fwritecolrs( p, area->width, write->fout ) )
if( scanline_write( (COLR *) p, area->width, write->fout ) ) if( scanline_write( (COLR *) p, area->width, write->fout ) )
//if( scanline_write_old( (COLR *) p, area->width, write->fout ) )
return( -1 ); return( -1 );
} }