jxlload: simplify rewinding (#3170)

This partially reverts commit e88db2ce.
This commit is contained in:
Kleis Auke Wolthuizen 2022-11-18 12:55:55 +01:00 committed by GitHub
parent e24cee4e22
commit 567c44e2ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -158,6 +158,14 @@ vips_foreign_load_jxl_build( VipsObject *object )
jxl->runner = JxlThreadParallelRunnerCreate( NULL,
vips_concurrency_get() );
jxl->decoder = JxlDecoderCreate( NULL );
if( JxlDecoderSetParallelRunner( jxl->decoder,
JxlThreadParallelRunner, jxl->runner ) ) {
vips_foreign_load_jxl_error( jxl,
"JxlDecoderSetParallelRunner" );
return( -1 );
}
if( VIPS_OBJECT_CLASS( vips_foreign_load_jxl_parent_class )->
build( object ) )
@ -493,24 +501,19 @@ vips_foreign_load_jxl_header( VipsForeignLoad *load )
printf( "vips_foreign_load_jxl_header:\n" );
#endif /*DEBUG*/
/* Build the decoder we will use for the header.
*/
jxl->decoder = JxlDecoderCreate( NULL );
if( JxlDecoderSubscribeEvents( jxl->decoder,
JXL_DEC_COLOR_ENCODING |
JXL_DEC_BASIC_INFO ) ) {
vips_foreign_load_jxl_error( jxl, "JxlDecoderSubscribeEvents" );
if( vips_source_rewind( jxl->source ) )
return( -1 );
}
if( JxlDecoderSetParallelRunner( jxl->decoder,
JxlThreadParallelRunner, jxl->runner ) ) {
vips_foreign_load_jxl_error( jxl,
"JxlDecoderSetParallelRunner" );
JxlDecoderRewind( jxl->decoder );
if( JxlDecoderSubscribeEvents( jxl->decoder,
JXL_DEC_COLOR_ENCODING |
JXL_DEC_BASIC_INFO ) ) {
vips_foreign_load_jxl_error( jxl,
"JxlDecoderSubscribeEvents" );
return( -1 );
}
if( vips_source_rewind( jxl->source ) ||
vips_foreign_load_jxl_fill_input( jxl, 0 ) )
if( vips_foreign_load_jxl_fill_input( jxl, 0 ) )
return( -1 );
JxlDecoderSetInput( jxl->decoder,
jxl->input_buffer, jxl->bytes_in_buffer );
@ -620,26 +623,21 @@ vips_foreign_load_jxl_load( VipsForeignLoad *load )
if( vips_foreign_load_jxl_set_header( jxl, t[0] ) )
return( -1 );
/* We have to make a new decoder ... we can't be certain the header
* decoder left the input in the correct place.
*/
VIPS_FREEF( JxlDecoderDestroy, jxl->decoder );
/* We have to rewind ... we can't be certain the header
* decoder left the input in the correct place.
*/
if( vips_source_rewind( jxl->source ) )
return( -1 );
jxl->decoder = JxlDecoderCreate( NULL );
JxlDecoderRewind( jxl->decoder );
if( JxlDecoderSubscribeEvents( jxl->decoder,
JXL_DEC_FULL_IMAGE ) ) {
vips_foreign_load_jxl_error( jxl, "JxlDecoderSubscribeEvents" );
return( -1 );
}
if( JxlDecoderSetParallelRunner( jxl->decoder,
JxlThreadParallelRunner, jxl->runner ) ) {
vips_foreign_load_jxl_error( jxl,
"JxlDecoderSetParallelRunner" );
vips_foreign_load_jxl_error( jxl,
"JxlDecoderSubscribeEvents" );
return( -1 );
}
if( vips_source_rewind( jxl->source ) ||
vips_foreign_load_jxl_fill_input( jxl, 0 ) )
if( vips_foreign_load_jxl_fill_input( jxl, 0 ) )
return( -1 );
JxlDecoderSetInput( jxl->decoder,
jxl->input_buffer, jxl->bytes_in_buffer );