From f209870e7bdb6824740205146dde40ec8a237dac Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 5 Mar 2019 15:35:58 +0000 Subject: [PATCH] start trying to fix autorotate for heif images --- libvips/foreign/heifload.c | 31 +++++++++++++++++++++---------- test/test-suite/test_foreign.py | 4 ++-- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/libvips/foreign/heifload.c b/libvips/foreign/heifload.c index 19256bc1..c80c414f 100644 --- a/libvips/foreign/heifload.c +++ b/libvips/foreign/heifload.c @@ -32,9 +32,10 @@ */ /* +#define DEBUG_VERBOSE + */ #define VIPS_DEBUG #define DEBUG - */ #ifdef HAVE_CONFIG_H #include @@ -323,27 +324,29 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) enum heif_color_profile_type profile_type = heif_image_handle_get_color_profile_type( heif->handle ); + printf( "profile type = " ); switch( profile_type ) { case heif_color_profile_type_not_present: - printf( "no profile\n" ); + printf( "none" ); break; case heif_color_profile_type_nclx: - printf( "nclx profile\n" ); + printf( "nclx" ); break; case heif_color_profile_type_rICC: - printf( "rICC profile\n" ); + printf( "rICC" ); break; case heif_color_profile_type_prof: - printf( "prof profile\n" ); + printf( "prof" ); break; default: - printf( "unknown profile type\n" ); + printf( "unknown" ); break; } + printf( "\n" ); } #endif /*DEBUG*/ @@ -383,8 +386,12 @@ vips_foreign_load_heif_set_header( VipsForeignLoadHeif *heif, VipsImage *out ) #ifdef HAVE_EXIF if( !heif->autorotate ) { if( angle == VIPS_ANGLE_D90 || - angle == VIPS_ANGLE_D270 ) + angle == VIPS_ANGLE_D270 ) { +#ifdef DEBUG + printf( "swapping width/height\n" ); +#endif /*DEBUG*/ VIPS_SWAP( int, image_page_width, image_page_height ); + } } else vips_autorot_remove_angle( out ); @@ -894,6 +901,7 @@ vips_foreign_load_heif_buffer_init( VipsForeignLoadHeifBuffer *buffer ) * * @page: %gint, page (top-level image number) to read * * @n: %gint, load this many pages * * @autorotate: %gboolean, apply image transformations + * * @thumbnail: %gboolean, fetch thumbnail instead of image * * Read a HEIF image file into a VIPS image. * @@ -907,9 +915,12 @@ vips_foreign_load_heif_buffer_init( VipsForeignLoadHeifBuffer *buffer ) * HEIF images have a primary image. The metadata item `heif-primary` gives * the page number of the primary. * - * HEIF images can have trsnaformations like rotate, flip and crop stored in + * HEIF images can have transformations like rotate, flip and crop stored in * the header. Set @autorotate %TRUE to apply these during load. * + * If @thumbnail is %TRUE, then fetch a stored thumbnail rather than the + * image. + * * See also: vips_image_new_from_file(). * * Returns: 0 on success, -1 on error. @@ -939,10 +950,10 @@ vips_heifload( const char *filename, VipsImage **out, ... ) * * @page: %gint, page (top-level image number) to read * * @n: %gint, load this many pages * * @autorotate: %gboolean, apply image transformations + * * @thumbnail: %gboolean, fetch thumbnail instead of image * * Read a HEIF image file into a VIPS image. - * Exactly as - * vips_heifload(), but read from a memory buffer. + * Exactly as vips_heifload(), but read from a memory buffer. * * You must not free the buffer while @out is active. The * #VipsObject::postclose signal on @out is a good place to free. diff --git a/test/test-suite/test_foreign.py b/test/test-suite/test_foreign.py index 35d44c72..e6fca041 100644 --- a/test/test-suite/test_foreign.py +++ b/test/test-suite/test_foreign.py @@ -836,8 +836,8 @@ class TestForeign: def heif_valid(im): a = im(10, 10) assert_almost_equal_objects(a, [75.0, 86.0, 81.0]) - assert im.width == 4032 - assert im.height == 3024 + assert im.width == 3024 + assert im.height == 4032 assert im.bands == 3 self.file_loader("heifload", HEIC_FILE, heif_valid)