@@ -929,6 +929,27 @@ ImagingLibTiffSetField(ImagingCodecState state, ttag_t tag, ...) {
929
929
return status ;
930
930
}
931
931
932
+ int
933
+ ImagingLibTiffEncodeCleanup (ImagingCodecState state ) {
934
+ TIFFSTATE * clientstate = (TIFFSTATE * )state -> context ;
935
+ TIFF * tiff = clientstate -> tiff ;
936
+
937
+ if (!tiff ) {
938
+ return 0 ;
939
+ }
940
+ // TIFFClose in libtiff calls tif_closeproc and TIFFCleanup
941
+ if (clientstate -> fp ) {
942
+ // Python will manage the closing of the file rather than libtiff
943
+ // So only call TIFFCleanup
944
+ TIFFCleanup (tiff );
945
+ } else {
946
+ // When tif_closeproc refers to our custom _tiffCloseProc though,
947
+ // that is fine, as it does not close the file
948
+ TIFFClose (tiff );
949
+ }
950
+ return 0 ;
951
+ }
952
+
932
953
int
933
954
ImagingLibTiffEncode (Imaging im , ImagingCodecState state , UINT8 * buffer , int bytes ) {
934
955
/* One shot encoder. Encode everything to the tiff in the clientstate.
@@ -1010,16 +1031,6 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
1010
1031
TRACE (("Encode Error, row %d\n" , state -> y ));
1011
1032
state -> errcode = IMAGING_CODEC_BROKEN ;
1012
1033
1013
- // TIFFClose in libtiff calls tif_closeproc and TIFFCleanup
1014
- if (clientstate -> fp ) {
1015
- // Python will manage the closing of the file rather than libtiff
1016
- // So only call TIFFCleanup
1017
- TIFFCleanup (tiff );
1018
- } else {
1019
- // When tif_closeproc refers to our custom _tiffCloseProc though,
1020
- // that is fine, as it does not close the file
1021
- TIFFClose (tiff );
1022
- }
1023
1034
if (!clientstate -> fp ) {
1024
1035
free (clientstate -> data );
1025
1036
}
@@ -1036,22 +1047,11 @@ ImagingLibTiffEncode(Imaging im, ImagingCodecState state, UINT8 *buffer, int byt
1036
1047
TRACE (("Error flushing the tiff" ));
1037
1048
// likely reason is memory.
1038
1049
state -> errcode = IMAGING_CODEC_MEMORY ;
1039
- if (clientstate -> fp ) {
1040
- TIFFCleanup (tiff );
1041
- } else {
1042
- TIFFClose (tiff );
1043
- }
1044
1050
if (!clientstate -> fp ) {
1045
1051
free (clientstate -> data );
1046
1052
}
1047
1053
return -1 ;
1048
1054
}
1049
- TRACE (("Closing \n" ));
1050
- if (clientstate -> fp ) {
1051
- TIFFCleanup (tiff );
1052
- } else {
1053
- TIFFClose (tiff );
1054
- }
1055
1055
// reset the clientstate metadata to use it to read out the buffer.
1056
1056
clientstate -> loc = 0 ;
1057
1057
clientstate -> size = clientstate -> eof ; // redundant?
0 commit comments