@@ -790,28 +790,24 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
790790
791791 if (!is_core_tag ) {
792792 // Register field for non core tags.
793+ if (type == TIFF_BYTE ) {
794+ is_var_length = 1 ;
795+ }
793796 if (ImagingLibTiffMergeFieldInfo (& encoder -> state , type , key_int , is_var_length )) {
794797 continue ;
795798 }
796799 }
797800
798- if (is_var_length ) {
801+ if (type == TIFF_BYTE ) {
802+ status = ImagingLibTiffSetField (& encoder -> state ,
803+ (ttag_t ) key_int ,
804+ PyBytes_Size (value ), PyBytes_AsString (value ));
805+ } else if (is_var_length ) {
799806 Py_ssize_t len ,i ;
800807 TRACE (("Setting from Tuple: %d \n" , key_int ));
801808 len = PyTuple_Size (value );
802809
803- if (type == TIFF_BYTE ) {
804- UINT8 * av ;
805- /* malloc check ok, calloc checks for overflow */
806- av = calloc (len , sizeof (UINT8 ));
807- if (av ) {
808- for (i = 0 ;i < len ;i ++ ) {
809- av [i ] = (UINT8 )PyLong_AsLong (PyTuple_GetItem (value ,i ));
810- }
811- status = ImagingLibTiffSetField (& encoder -> state , (ttag_t ) key_int , len , av );
812- free (av );
813- }
814- } else if (type == TIFF_SHORT ) {
810+ if (type == TIFF_SHORT ) {
815811 UINT16 * av ;
816812 /* malloc check ok, calloc checks for overflow */
817813 av = calloc (len , sizeof (UINT16 ));
@@ -914,10 +910,6 @@ PyImaging_LibTiffEncoderNew(PyObject* self, PyObject* args)
914910 status = ImagingLibTiffSetField (& encoder -> state ,
915911 (ttag_t ) key_int ,
916912 (FLOAT64 )PyFloat_AsDouble (value ));
917- } else if (type == TIFF_BYTE ) {
918- status = ImagingLibTiffSetField (& encoder -> state ,
919- (ttag_t ) key_int ,
920- (UINT8 )PyLong_AsLong (value ));
921913 } else if (type == TIFF_SBYTE ) {
922914 status = ImagingLibTiffSetField (& encoder -> state ,
923915 (ttag_t ) key_int ,
0 commit comments