From 98e80903e067923c78dcc149c00c98cbf8e13ef9 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 28 May 2015 16:19:32 +0100 Subject: [PATCH] metadata was not being saved to vips files broken by the rewind changes a few weeks ago added a test too --- TODO | 18 ++++++++++++++++++ libvips/iofuncs/generate.c | 11 ++++++++--- test/test_foreign.py | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 1e1ac37e..dd46da2d 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,21 @@ +- extra character in exif-data? + + try: + + $ cd test + $ vipsheader -a images/IMG_4618.jpg | grep exif-data + exif-data: VIPS_TYPE_BLOB, data = 0x16e0a20, length = 6626 + $ vips copy images/IMG_4618.jpg x.v + $ vipsheader -a x.v | grep exif-data + exif-data: VIPS_TYPE_BLOB, data = 0x20679f0, length = 6627 + + one byte longer! + + fix, and add a test for exif length to test/test_foreign.py + + + + - how about something like vips_grid() which turns a tall thin one-band image into a much smaller many-band image? diff --git a/libvips/iofuncs/generate.c b/libvips/iofuncs/generate.c index fe61ee9a..41a6c3da 100644 --- a/libvips/iofuncs/generate.c +++ b/libvips/iofuncs/generate.c @@ -703,6 +703,9 @@ vips_image_generate( VipsImage *image, VIPS_DEBUG_MSG( "vips_image_generate: " "attaching partial callbacks\n" ); + + if( vips_image_written( image ) ) + return( -1 ); break; @@ -742,6 +745,11 @@ vips_image_generate( VipsImage *image, if( res ) return( -1 ); + /* Must come before we rewind. + */ + if( vips_image_written( image ) ) + return( -1 ); + /* We've written to image ... rewind it ready for reading. */ if( vips_image_pio_input( image ) ) @@ -759,8 +767,5 @@ vips_image_generate( VipsImage *image, return( -1 ); } - if( vips_image_written( image ) ) - return( -1 ); - return( 0 ); } diff --git a/test/test_foreign.py b/test/test_foreign.py index ca16b5aa..ad116c02 100755 --- a/test/test_foreign.py +++ b/test/test_foreign.py @@ -104,6 +104,21 @@ class TestForeign(unittest.TestCase): self.assertEqual(im.bands, x.bands) self.assertLessEqual((im - x).abs().max(), max_diff) + def test_vips(self): + self.save_load_file("test.v", "", self.colour, 0) + + # check we can save and restore metadata + self.colour.write_to_file("test.v") + x = Vips.Image.new_from_file("test.v") + before_exif = self.colour.get_value("exif-data") + after_exif = x.get_value("exif-data") + + for i in range(len(before_exif)): + self.assertEqual(before_exif[i], after_exif[i]) + + x = None + os.unlink("test.v") + def test_jpeg(self): x = Vips.type_find("VipsForeign", "jpegload") if not x.is_instantiatable():