@@ -88,7 +88,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
8888 compress_type = context -> compress_type ;
8989 }
9090
91+ #ifdef HAVE_ZLIBNG
92+ err = zng_deflateInit2 (
93+ #else
9194 err = deflateInit2 (
95+ #endif
9296 & context -> z_stream ,
9397 /* compression level */
9498 compress_level ,
@@ -106,7 +110,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
106110 }
107111
108112 if (context -> dictionary && context -> dictionary_size > 0 ) {
113+ #ifdef HAVE_ZLIBNG
114+ err = zng_deflateSetDictionary (
115+ #else
109116 err = deflateSetDictionary (
117+ #endif
110118 & context -> z_stream ,
111119 (unsigned char * )context -> dictionary ,
112120 context -> dictionary_size
@@ -126,7 +134,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
126134 context -> z_stream .avail_out = bytes ;
127135 if (context -> z_stream .next_in && context -> z_stream .avail_in > 0 ) {
128136 /* We have some data from previous round, deflate it first */
137+ #ifdef HAVE_ZLIBNG
138+ err = zng_deflate (& context -> z_stream , Z_NO_FLUSH );
139+ #else
129140 err = deflate (& context -> z_stream , Z_NO_FLUSH );
141+ #endif
130142
131143 if (err < 0 ) {
132144 /* Something went wrong inside the compression library */
@@ -142,7 +154,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
142154 free (context -> up );
143155 free (context -> prior );
144156 free (context -> previous );
157+ #ifdef HAVE_ZLIBNG
158+ zng_deflateEnd (& context -> z_stream );
159+ #else
145160 deflateEnd (& context -> z_stream );
161+ #endif
146162 return -1 ;
147163 }
148164 }
@@ -279,7 +295,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
279295 context -> z_stream .next_in = context -> output ;
280296 context -> z_stream .avail_in = state -> bytes + 1 ;
281297
298+ #ifdef HAVE_ZLIBNG
299+ err = zng_deflate (& context -> z_stream , Z_NO_FLUSH );
300+ #else
282301 err = deflate (& context -> z_stream , Z_NO_FLUSH );
302+ #endif
283303
284304 if (err < 0 ) {
285305 /* Something went wrong inside the compression library */
@@ -295,7 +315,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
295315 free (context -> up );
296316 free (context -> prior );
297317 free (context -> previous );
318+ #ifdef HAVE_ZLIBNG
319+ zng_deflateEnd (& context -> z_stream );
320+ #else
298321 deflateEnd (& context -> z_stream );
322+ #endif
299323 ImagingSectionLeave (& cookie );
300324 return -1 ;
301325 }
@@ -315,7 +339,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
315339 /* End of image data; flush compressor buffers */
316340
317341 while (context -> z_stream .avail_out > 0 ) {
342+ #ifdef HAVE_ZLIBNG
343+ err = zng_deflate (& context -> z_stream , Z_FINISH );
344+ #else
318345 err = deflate (& context -> z_stream , Z_FINISH );
346+ #endif
319347
320348 if (err == Z_STREAM_END ) {
321349 free (context -> paeth );
@@ -324,7 +352,11 @@ ImagingZipEncode(Imaging im, ImagingCodecState state, UINT8 *buf, int bytes) {
324352 free (context -> prior );
325353 free (context -> previous );
326354
355+ #ifdef HAVE_ZLIBNG
356+ zng_deflateEnd (& context -> z_stream );
357+ #else
327358 deflateEnd (& context -> z_stream );
359+ #endif
328360
329361 state -> errcode = IMAGING_CODEC_END ;
330362
@@ -364,7 +396,11 @@ ImagingZipEncodeCleanup(ImagingCodecState state) {
364396
365397const char *
366398ImagingZipVersion (void ) {
399+ #ifdef HAVE_ZLIBNG
400+ return zlibng_version ();
401+ #else
367402 return zlibVersion ();
403+ #endif
368404}
369405
370406#endif
0 commit comments