comparison libinterp/corefcn/__tiff__.cc @ 31192:6a2bb6f4e41e

__tiff__.cc (F__tiff_imread__): fixed bug where file was not closed on errors.
author magedrifaat <magedrifaat@gmail.com>
date Sat, 27 Aug 2022 16:23:59 +0200
parents 8ada1e68d961
children c142c153034c
comparison
equal deleted inserted replaced
31191:8ada1e68d961 31192:6a2bb6f4e41e
3555 error ("No filename provided\n"); 3555 error ("No filename provided\n");
3556 3556
3557 uint16_t offset = 1; 3557 uint16_t offset = 1;
3558 3558
3559 TIFF *tif = TIFFOpen (args(0).string_value ().c_str (), "r"); 3559 TIFF *tif = TIFFOpen (args(0).string_value ().c_str (), "r");
3560 if (! tif)
3561 error ("Failed to open file %s", args(0).string_value ().c_str ());
3562
3563 // A simple way to make sure the file will be closed when the function
3564 // returns or when an error occurs as the destructor will always be called
3565 octave_tiff_handle tiff_handle (tif);
3566
3560 uint16_t dir_count = TIFFNumberOfDirectories (tif); 3567 uint16_t dir_count = TIFFNumberOfDirectories (tif);
3561 uint16_t page = 1; 3568 uint16_t page = 1;
3562 3569
3563 // Handle unpaired index parameter 3570 // Handle unpaired index parameter
3564 if (nargin > 1 && ! args(1).is_string ()) 3571 if (nargin > 1 && ! args(1).is_string ())
3610 // Obtain image info 3617 // Obtain image info
3611 tiff_image_data image_data (tif); 3618 tiff_image_data image_data (tif);
3612 3619
3613 // Set the default region 3620 // Set the default region
3614 uint32NDArray row_region (dim_vector (1, 3)); 3621 uint32NDArray row_region (dim_vector (1, 3));
3615 row_region(0) = 0; 3622 row_region(0) = 1;
3616 row_region(1) = 1; 3623 row_region(1) = 1;
3617 row_region(2) = image_data.height; 3624 row_region(2) = image_data.height;
3618 uint32NDArray col_region (dim_vector (1, 3)); 3625 uint32NDArray col_region (dim_vector (1, 3));
3619 col_region(0) = 0; 3626 col_region(0) = 1;
3620 col_region(1) = 1; 3627 col_region(1) = 1;
3621 col_region(2) = image_data.width; 3628 col_region(2) = image_data.width;
3622 3629
3623 // Obtain and validate other params (pixelregion, info) 3630 // Obtain and validate other params (pixelregion, info)
3624 for (uint16_t arg_idx = offset; arg_idx < nargin; arg_idx+=2) 3631 for (uint16_t arg_idx = offset; arg_idx < nargin; arg_idx+=2)