reduce the number of copy() ops

reduce the number of copy() ops issued during colour conversion
This commit is contained in:
John Cupitt 2016-02-26 14:05:35 +00:00
parent cc9517df20
commit 35650c2244
3 changed files with 62 additions and 22 deletions

3
TODO
View File

@ -10,6 +10,9 @@
no better, strange
- we have a buffer reserve list on each image ... could we junk this on
"minimise"?
- try SEQ_UNBUFFERED on jpg source, get out of order error?
- add reduceh > 3 warning for wtc shrink to 1280x1280

View File

@ -321,10 +321,16 @@ vips_colour_build( VipsObject *object )
in[i], colour->input_bands ) )
return( -1 );
if( vips_extract_band( in[i], &new_in[i], 0,
"n", colour->input_bands,
NULL ) )
return( -1 );
if( in[i]->Bands > colour->input_bands ) {
if( vips_extract_band( in[i], &new_in[i], 0,
"n", colour->input_bands,
NULL ) )
return( -1 );
}
else {
new_in[i] = in[i];
g_object_ref( new_in[i] );
}
if( in[i]->Bands > colour->input_bands )
if( vips_extract_band( in[i], &extra_bands[i],
@ -445,8 +451,15 @@ vips_colour_transform_build( VipsObject *object )
/* We only process float.
*/
if( vips_cast_float( transform->in, &t[0], NULL ) )
return( -1 );
if( transform->in &&
transform->in->BandFmt != VIPS_FORMAT_FLOAT ) {
if( vips_cast_float( transform->in, &t[0], NULL ) )
return( -1 );
}
else {
t[0] = transform->in;
g_object_ref( t[0] );
}
/* We always do 3 bands -> 3 bands.
*/
@ -527,7 +540,8 @@ vips_colour_code_build( VipsObject *object )
if( in &&
code->input_coding == VIPS_CODING_NONE &&
code->input_format != VIPS_FORMAT_NOTSET ) {
code->input_format != VIPS_FORMAT_NOTSET &&
in->BandFmt != code->input_format ) {
if( vips_cast( in, &t[3], code->input_format, NULL ) )
return( -1 );
in = t[3];
@ -535,7 +549,8 @@ vips_colour_code_build( VipsObject *object )
if( in &&
code->input_coding == VIPS_CODING_NONE &&
code->input_interpretation != VIPS_INTERPRETATION_ERROR ) {
code->input_interpretation != VIPS_INTERPRETATION_ERROR &&
in->Type != code->input_interpretation ) {
if( vips_colourspace( in, &t[4],
code->input_interpretation, NULL ) )
return( -1 );
@ -616,21 +631,37 @@ vips_colour_difference_build( VipsObject *object )
*/
colour->input_bands = 3;
if( vips_colourspace( left, &t[6], difference->interpretation, NULL ) )
return( -1 );
left = t[6];
if( vips_colourspace( right, &t[7], difference->interpretation, NULL ) )
return( -1 );
right = t[7];
if( left &&
left->Type != difference->interpretation ) {
if( vips_colourspace( left, &t[6],
difference->interpretation, NULL ) )
return( -1 );
left = t[6];
}
if( right &&
right->Type != difference->interpretation ) {
if( vips_colourspace( right, &t[7],
difference->interpretation, NULL ) )
return( -1 );
right = t[7];
}
/* We only process float.
*/
if( vips_cast_float( left, &t[8], NULL ) )
return( -1 );
left = t[8];
if( vips_cast_float( right, &t[9], NULL ) )
return( -1 );
right = t[9];
if( left &&
left->BandFmt != VIPS_FORMAT_FLOAT ) {
if( vips_cast_float( left, &t[8], NULL ) )
return( -1 );
left = t[8];
}
if( right &&
right->BandFmt != VIPS_FORMAT_FLOAT ) {
if( vips_cast_float( right, &t[9], NULL ) )
return( -1 );
right = t[9];
}
if( vips__sizealike( left, right, &t[10], &t[11] ) )
return( -1 );

View File

@ -192,8 +192,14 @@ vips_sRGB2scRGB_build( VipsObject *object )
format = in->Type == VIPS_INTERPRETATION_RGB16 ?
VIPS_FORMAT_USHORT : VIPS_FORMAT_UCHAR;
if( vips_cast( in, &t[0], format, NULL ) )
return( -1 );
if( in->BandFmt != format ) {
if( vips_cast( in, &t[0], format, NULL ) )
return( -1 );
}
else {
t[0] = in;
g_object_ref( t[0] );
}
in = t[0];
out = vips_image_new();