MagickCore 7.1.2-37
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
compress.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% CCCC OOO M M PPPP RRRR EEEEE SSSSS SSSSS %
7% C O O MM MM P P R R E SS SS %
8% C O O M M M PPPP RRRR EEE SSS SSS %
9% C O O M M P R R E SS SS %
10% CCCC OOO M M P R R EEEEE SSSSS SSSSS %
11% %
12% %
13% MagickCore Image Compression/Decompression Methods %
14% %
15% Software Design %
16% Cristy %
17% May 1993 %
18% %
19% %
20% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
21% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% https://imagemagick.org/license/ %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39␌
40/*
41 Include declarations.
42*/
43#include "MagickCore/studio.h"
44#include "MagickCore/attribute.h"
45#include "MagickCore/blob.h"
46#include "MagickCore/blob-private.h"
47#include "MagickCore/color-private.h"
48#include "MagickCore/cache.h"
49#include "MagickCore/compress.h"
50#include "MagickCore/constitute.h"
51#include "MagickCore/exception.h"
52#include "MagickCore/exception-private.h"
53#include "MagickCore/image-private.h"
54#include "MagickCore/list.h"
55#include "MagickCore/memory_.h"
56#include "MagickCore/monitor.h"
57#include "MagickCore/monitor-private.h"
58#include "MagickCore/option.h"
59#include "MagickCore/pixel-accessor.h"
60#include "MagickCore/resource_.h"
61#include "MagickCore/string_.h"
62#if defined(MAGICKCORE_ZLIB_DELEGATE)
63#include "zlib.h"
64#endif
65␌
66/*
67 Typedef declarations.
68*/
70{
71 ssize_t
72 offset,
73 line_break;
74
75 char
76 tuple[6];
77
78 unsigned char
79 buffer[10];
80};
81
82typedef struct HuffmanTable
83{
84 size_t
85 id,
86 code,
87 length,
88 count;
90␌
91/*
92 Huffman coding declarations.
93*/
94#define TWId 23L
95#define MWId 24L
96#define TBId 25L
97#define MBId 26L
98#define EXId 27L
99
100static const HuffmanTable
101 MBTable[]=
102 {
103 { MBId, 0x0f, 10, 64 }, { MBId, 0xc8, 12, 128 },
104 { MBId, 0xc9, 12, 192 }, { MBId, 0x5b, 12, 256 },
105 { MBId, 0x33, 12, 320 }, { MBId, 0x34, 12, 384 },
106 { MBId, 0x35, 12, 448 }, { MBId, 0x6c, 13, 512 },
107 { MBId, 0x6d, 13, 576 }, { MBId, 0x4a, 13, 640 },
108 { MBId, 0x4b, 13, 704 }, { MBId, 0x4c, 13, 768 },
109 { MBId, 0x4d, 13, 832 }, { MBId, 0x72, 13, 896 },
110 { MBId, 0x73, 13, 960 }, { MBId, 0x74, 13, 1024 },
111 { MBId, 0x75, 13, 1088 }, { MBId, 0x76, 13, 1152 },
112 { MBId, 0x77, 13, 1216 }, { MBId, 0x52, 13, 1280 },
113 { MBId, 0x53, 13, 1344 }, { MBId, 0x54, 13, 1408 },
114 { MBId, 0x55, 13, 1472 }, { MBId, 0x5a, 13, 1536 },
115 { MBId, 0x5b, 13, 1600 }, { MBId, 0x64, 13, 1664 },
116 { MBId, 0x65, 13, 1728 }, { MBId, 0x00, 0, 0 }
117 };
118
119static const HuffmanTable
120 EXTable[]=
121 {
122 { EXId, 0x08, 11, 1792 }, { EXId, 0x0c, 11, 1856 },
123 { EXId, 0x0d, 11, 1920 }, { EXId, 0x12, 12, 1984 },
124 { EXId, 0x13, 12, 2048 }, { EXId, 0x14, 12, 2112 },
125 { EXId, 0x15, 12, 2176 }, { EXId, 0x16, 12, 2240 },
126 { EXId, 0x17, 12, 2304 }, { EXId, 0x1c, 12, 2368 },
127 { EXId, 0x1d, 12, 2432 }, { EXId, 0x1e, 12, 2496 },
128 { EXId, 0x1f, 12, 2560 }, { EXId, 0x00, 0, 0 }
129 };
130
131static const HuffmanTable
132 MWTable[]=
133 {
134 { MWId, 0x1b, 5, 64 }, { MWId, 0x12, 5, 128 },
135 { MWId, 0x17, 6, 192 }, { MWId, 0x37, 7, 256 },
136 { MWId, 0x36, 8, 320 }, { MWId, 0x37, 8, 384 },
137 { MWId, 0x64, 8, 448 }, { MWId, 0x65, 8, 512 },
138 { MWId, 0x68, 8, 576 }, { MWId, 0x67, 8, 640 },
139 { MWId, 0xcc, 9, 704 }, { MWId, 0xcd, 9, 768 },
140 { MWId, 0xd2, 9, 832 }, { MWId, 0xd3, 9, 896 },
141 { MWId, 0xd4, 9, 960 }, { MWId, 0xd5, 9, 1024 },
142 { MWId, 0xd6, 9, 1088 }, { MWId, 0xd7, 9, 1152 },
143 { MWId, 0xd8, 9, 1216 }, { MWId, 0xd9, 9, 1280 },
144 { MWId, 0xda, 9, 1344 }, { MWId, 0xdb, 9, 1408 },
145 { MWId, 0x98, 9, 1472 }, { MWId, 0x99, 9, 1536 },
146 { MWId, 0x9a, 9, 1600 }, { MWId, 0x18, 6, 1664 },
147 { MWId, 0x9b, 9, 1728 }, { MWId, 0x00, 0, 0 }
148 };
149
150static const HuffmanTable
151 TBTable[]=
152 {
153 { TBId, 0x37, 10, 0 }, { TBId, 0x02, 3, 1 }, { TBId, 0x03, 2, 2 },
154 { TBId, 0x02, 2, 3 }, { TBId, 0x03, 3, 4 }, { TBId, 0x03, 4, 5 },
155 { TBId, 0x02, 4, 6 }, { TBId, 0x03, 5, 7 }, { TBId, 0x05, 6, 8 },
156 { TBId, 0x04, 6, 9 }, { TBId, 0x04, 7, 10 }, { TBId, 0x05, 7, 11 },
157 { TBId, 0x07, 7, 12 }, { TBId, 0x04, 8, 13 }, { TBId, 0x07, 8, 14 },
158 { TBId, 0x18, 9, 15 }, { TBId, 0x17, 10, 16 }, { TBId, 0x18, 10, 17 },
159 { TBId, 0x08, 10, 18 }, { TBId, 0x67, 11, 19 }, { TBId, 0x68, 11, 20 },
160 { TBId, 0x6c, 11, 21 }, { TBId, 0x37, 11, 22 }, { TBId, 0x28, 11, 23 },
161 { TBId, 0x17, 11, 24 }, { TBId, 0x18, 11, 25 }, { TBId, 0xca, 12, 26 },
162 { TBId, 0xcb, 12, 27 }, { TBId, 0xcc, 12, 28 }, { TBId, 0xcd, 12, 29 },
163 { TBId, 0x68, 12, 30 }, { TBId, 0x69, 12, 31 }, { TBId, 0x6a, 12, 32 },
164 { TBId, 0x6b, 12, 33 }, { TBId, 0xd2, 12, 34 }, { TBId, 0xd3, 12, 35 },
165 { TBId, 0xd4, 12, 36 }, { TBId, 0xd5, 12, 37 }, { TBId, 0xd6, 12, 38 },
166 { TBId, 0xd7, 12, 39 }, { TBId, 0x6c, 12, 40 }, { TBId, 0x6d, 12, 41 },
167 { TBId, 0xda, 12, 42 }, { TBId, 0xdb, 12, 43 }, { TBId, 0x54, 12, 44 },
168 { TBId, 0x55, 12, 45 }, { TBId, 0x56, 12, 46 }, { TBId, 0x57, 12, 47 },
169 { TBId, 0x64, 12, 48 }, { TBId, 0x65, 12, 49 }, { TBId, 0x52, 12, 50 },
170 { TBId, 0x53, 12, 51 }, { TBId, 0x24, 12, 52 }, { TBId, 0x37, 12, 53 },
171 { TBId, 0x38, 12, 54 }, { TBId, 0x27, 12, 55 }, { TBId, 0x28, 12, 56 },
172 { TBId, 0x58, 12, 57 }, { TBId, 0x59, 12, 58 }, { TBId, 0x2b, 12, 59 },
173 { TBId, 0x2c, 12, 60 }, { TBId, 0x5a, 12, 61 }, { TBId, 0x66, 12, 62 },
174 { TBId, 0x67, 12, 63 }, { TBId, 0x00, 0, 0 }
175 };
176
177static const HuffmanTable
178 TWTable[]=
179 {
180 { TWId, 0x35, 8, 0 }, { TWId, 0x07, 6, 1 }, { TWId, 0x07, 4, 2 },
181 { TWId, 0x08, 4, 3 }, { TWId, 0x0b, 4, 4 }, { TWId, 0x0c, 4, 5 },
182 { TWId, 0x0e, 4, 6 }, { TWId, 0x0f, 4, 7 }, { TWId, 0x13, 5, 8 },
183 { TWId, 0x14, 5, 9 }, { TWId, 0x07, 5, 10 }, { TWId, 0x08, 5, 11 },
184 { TWId, 0x08, 6, 12 }, { TWId, 0x03, 6, 13 }, { TWId, 0x34, 6, 14 },
185 { TWId, 0x35, 6, 15 }, { TWId, 0x2a, 6, 16 }, { TWId, 0x2b, 6, 17 },
186 { TWId, 0x27, 7, 18 }, { TWId, 0x0c, 7, 19 }, { TWId, 0x08, 7, 20 },
187 { TWId, 0x17, 7, 21 }, { TWId, 0x03, 7, 22 }, { TWId, 0x04, 7, 23 },
188 { TWId, 0x28, 7, 24 }, { TWId, 0x2b, 7, 25 }, { TWId, 0x13, 7, 26 },
189 { TWId, 0x24, 7, 27 }, { TWId, 0x18, 7, 28 }, { TWId, 0x02, 8, 29 },
190 { TWId, 0x03, 8, 30 }, { TWId, 0x1a, 8, 31 }, { TWId, 0x1b, 8, 32 },
191 { TWId, 0x12, 8, 33 }, { TWId, 0x13, 8, 34 }, { TWId, 0x14, 8, 35 },
192 { TWId, 0x15, 8, 36 }, { TWId, 0x16, 8, 37 }, { TWId, 0x17, 8, 38 },
193 { TWId, 0x28, 8, 39 }, { TWId, 0x29, 8, 40 }, { TWId, 0x2a, 8, 41 },
194 { TWId, 0x2b, 8, 42 }, { TWId, 0x2c, 8, 43 }, { TWId, 0x2d, 8, 44 },
195 { TWId, 0x04, 8, 45 }, { TWId, 0x05, 8, 46 }, { TWId, 0x0a, 8, 47 },
196 { TWId, 0x0b, 8, 48 }, { TWId, 0x52, 8, 49 }, { TWId, 0x53, 8, 50 },
197 { TWId, 0x54, 8, 51 }, { TWId, 0x55, 8, 52 }, { TWId, 0x24, 8, 53 },
198 { TWId, 0x25, 8, 54 }, { TWId, 0x58, 8, 55 }, { TWId, 0x59, 8, 56 },
199 { TWId, 0x5a, 8, 57 }, { TWId, 0x5b, 8, 58 }, { TWId, 0x4a, 8, 59 },
200 { TWId, 0x4b, 8, 60 }, { TWId, 0x32, 8, 61 }, { TWId, 0x33, 8, 62 },
201 { TWId, 0x34, 8, 63 }, { TWId, 0x00, 0, 0 }
202 };
203␌
204/*
205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206% %
207% %
208% %
209% A S C I I 8 5 E n c o d e %
210% %
211% %
212% %
213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214%
215% ASCII85Encode() encodes data in ASCII base-85 format. ASCII base-85
216% encoding produces five ASCII printing characters from every four bytes of
217% binary data.
218%
219% The format of the ASCII85Encode method is:
220%
221% void Ascii85Encode(Image *image,const size_t code)
222%
223% A description of each parameter follows:
224%
225% o code: a binary unsigned char to encode to ASCII 85.
226%
227% o file: write the encoded ASCII character to this file.
228%
229%
230*/
231static inline void Ascii85Tuple(Ascii85Info *ascii85_info,
232 const unsigned char *magick_restrict data)
233{
234#define MaxLineExtent 36L
235
236 size_t
237 code,
238 i,
239 quantum,
240 x;
241
242 code=((((size_t) data[0] << 8) | (size_t) data[1]) << 16) |
243 ((size_t) data[2] << 8) | (size_t) data[3];
244 if (code == 0L)
245 {
246 ascii85_info->tuple[0]='z';
247 ascii85_info->tuple[1]='\0';
248 return;
249 }
250 quantum=85UL*85UL*85UL*85UL;
251 for (i=0; i < 4; i++)
252 {
253 x=(code/quantum);
254 code-=quantum*x;
255 ascii85_info->tuple[i]=(char) (x+(int) '!');
256 quantum/=85L;
257 }
258 ascii85_info->tuple[4]=(char) ((code % 85L)+(int) '!');
259 ascii85_info->tuple[5]='\0';
260}
261
262MagickExport void Ascii85Initialize(Image *image)
263{
264 /*
265 Allocate image structure.
266 */
267 if (image->ascii85 == (Ascii85Info *) NULL)
268 image->ascii85=(Ascii85Info *) AcquireCriticalMemory(
269 sizeof(*image->ascii85));
270 (void) memset(image->ascii85,0,sizeof(*image->ascii85));
271 image->ascii85->line_break=(ssize_t) (MaxLineExtent << 1);
272 image->ascii85->offset=0;
273}
274
275static MagickBooleanType Ascii85FlushInternal(Image *image)
276{
277 assert(image != (Image *) NULL);
278 assert(image->signature == MagickCoreSignature);
279 assert(image->ascii85 != (Ascii85Info *) NULL);
280 if (IsEventLogging() != MagickFalse)
281 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
282 if (image->ascii85->offset > 0)
283 {
284 image->ascii85->buffer[image->ascii85->offset]='\0';
285 image->ascii85->buffer[image->ascii85->offset+1]='\0';
286 image->ascii85->buffer[image->ascii85->offset+2]='\0';
287 Ascii85Tuple(image->ascii85,image->ascii85->buffer);
288 if (WriteBlob(image,(size_t) image->ascii85->offset+1,
289 (const unsigned char *) (*image->ascii85->tuple == 'z' ? "!!!!" :
290 image->ascii85->tuple)) != (ssize_t) (image->ascii85->offset+1))
291 return(MagickFalse);
292 }
293 if (WriteBlobByte(image,'~') != 1)
294 return(MagickFalse);
295 if (WriteBlobByte(image,'>') != 1)
296 return(MagickFalse);
297 if (WriteBlobByte(image,'\n') != 1)
298 return(MagickFalse);
299 return(MagickTrue);
300}
301
302MagickExport void Ascii85Flush(Image *image)
303{
304 (void) Ascii85FlushInternal(image);
305}
306
307static MagickBooleanType Ascii85EncodeInternal(Image *image,
308 const unsigned char code)
309{
310 char
311 *q;
312
313 MagickBooleanType
314 status;
315
316 unsigned char
317 *p;
318
319 ssize_t
320 n;
321
322 assert(image != (Image *) NULL);
323 assert(image->signature == MagickCoreSignature);
324 assert(image->ascii85 != (Ascii85Info *) NULL);
325 image->ascii85->buffer[image->ascii85->offset]=code;
326 image->ascii85->offset++;
327 if (image->ascii85->offset < 4)
328 return(MagickTrue);
329 status=MagickTrue;
330 p=image->ascii85->buffer;
331 for (n=image->ascii85->offset; n >= 4; n-=4)
332 {
333 Ascii85Tuple(image->ascii85,p);
334 for (q=image->ascii85->tuple; *q != '\0'; q++)
335 {
336 image->ascii85->line_break--;
337 if ((image->ascii85->line_break < 0) && (*q != '%'))
338 {
339 if (WriteBlobByte(image,'\n') != 1)
340 {
341 status=MagickFalse;
342 break;
343 }
344 image->ascii85->line_break=2*MaxLineExtent;
345 }
346 if (WriteBlobByte(image,(unsigned char) *q) != 1)
347 {
348 status=MagickFalse;
349 break;
350 }
351 }
352 p+=(ptrdiff_t) 8;
353 }
354 image->ascii85->offset=n;
355 p-=(ptrdiff_t)4;
356 for (n=0; n < 4; n++)
357 image->ascii85->buffer[n]=(*p++);
358 return(status);
359}
360
361MagickExport void Ascii85Encode(Image *image,const unsigned char code)
362{
363 (void) Ascii85EncodeInternal(image,code);
364}
365␌
366/*
367%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
368% %
369% %
370% %
371% H u f f m a n D e c o d e I m a g e %
372% %
373% %
374% %
375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376%
377% HuffmanDecodeImage() uncompresses an image via Huffman-coding.
378%
379% The format of the HuffmanDecodeImage method is:
380%
381% MagickBooleanType HuffmanDecodeImage(Image *image,
382% ExceptionInfo *exception)
383%
384% A description of each parameter follows:
385%
386% o image: the image.
387%
388% o exception: return any errors or warnings in this structure.
389%
390*/
391MagickExport MagickBooleanType HuffmanDecodeImage(Image *image,
392 ExceptionInfo *exception)
393{
394#define HashSize 1021L
395#define MBHashA 293L
396#define MBHashB 2695L
397#define MWHashA 3510L
398#define MWHashB 1178L
399
400#define InitializeHashTable(hash,table,a,b) \
401{ \
402 entry=table; \
403 while (entry->code != 0) \
404 { \
405 hash[((entry->length+a)*(entry->code+b)) % HashSize]=(HuffmanTable *) entry; \
406 entry++; \
407 } \
408}
409
410#define InputBit(bit) \
411{ \
412 if ((mask & 0xff) == 0) \
413 { \
414 byte=ReadBlobByte(image); \
415 if (byte == EOF) \
416 break; \
417 mask=0x80; \
418 } \
419 runlength++; \
420 bit=(size_t) ((byte & mask) != 0 ? 0x01 : 0x00); \
421 mask>>=1; \
422 if (bit != 0) \
423 runlength=0; \
424}
425
426 CacheView
427 *image_view;
428
429 const HuffmanTable
430 *entry;
431
433 **mb_hash,
434 **mw_hash;
435
436 int
437 byte,
438 mask;
439
440 MagickBooleanType
441 proceed;
442
443 Quantum
444 index;
445
446 size_t
447 bit,
448 code,
449 length,
450 null_lines,
451 runlength;
452
453 ssize_t
454 count,
455 i,
456 y;
457
458 unsigned char
459 *p,
460 *scanline;
461
462 unsigned int
463 bail,
464 color;
465
466 /*
467 Allocate buffers.
468 */
469 assert(image != (Image *) NULL);
470 assert(image->signature == MagickCoreSignature);
471 if (IsEventLogging() != MagickFalse)
472 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
473 if (image->blob == (BlobInfo *) NULL)
474 ThrowBinaryException(BlobError,"UnableToOpenBlob",image->filename);
475 mb_hash=(HuffmanTable **) AcquireQuantumMemory(HashSize,sizeof(*mb_hash));
476 mw_hash=(HuffmanTable **) AcquireQuantumMemory(HashSize,sizeof(*mw_hash));
477 scanline=(unsigned char *) AcquireQuantumMemory((size_t) image->columns,
478 sizeof(*scanline));
479 if ((mb_hash == (HuffmanTable **) NULL) ||
480 (mw_hash == (HuffmanTable **) NULL) ||
481 (scanline == (unsigned char *) NULL))
482 {
483 if (mb_hash != (HuffmanTable **) NULL)
484 mb_hash=(HuffmanTable **) RelinquishMagickMemory(mb_hash);
485 if (mw_hash != (HuffmanTable **) NULL)
486 mw_hash=(HuffmanTable **) RelinquishMagickMemory(mw_hash);
487 if (scanline != (unsigned char *) NULL)
488 scanline=(unsigned char *) RelinquishMagickMemory(scanline);
489 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
490 image->filename);
491 }
492 /*
493 Initialize Huffman tables.
494 */
495 for (i=0; i < HashSize; i++)
496 {
497 mb_hash[i]=(HuffmanTable *) NULL;
498 mw_hash[i]=(HuffmanTable *) NULL;
499 }
500 InitializeHashTable(mw_hash,TWTable,MWHashA,MWHashB);
501 InitializeHashTable(mw_hash,MWTable,MWHashA,MWHashB);
502 InitializeHashTable(mw_hash,EXTable,MWHashA,MWHashB);
503 InitializeHashTable(mb_hash,TBTable,MBHashA,MBHashB);
504 InitializeHashTable(mb_hash,MBTable,MBHashA,MBHashB);
505 InitializeHashTable(mb_hash,EXTable,MBHashA,MBHashB);
506 /*
507 Uncompress 1D Huffman to runlength encoded pixels.
508 */
509 byte=0;
510 mask=0;
511 null_lines=0;
512 runlength=0;
513 while (runlength < 11)
514 InputBit(bit);
515 do { InputBit(bit); } while ((int) bit == 0);
516 image->resolution.x=204.0;
517 image->resolution.y=196.0;
518 image->units=PixelsPerInchResolution;
519 image_view=AcquireAuthenticCacheView(image,exception);
520 for (y=0; ((y < (ssize_t) image->rows) && (null_lines < 3)); )
521 {
522 Quantum
523 *magick_restrict q;
524
525 ssize_t
526 x;
527
528 /*
529 Initialize scanline to white.
530 */
531 memset(scanline,0,sizeof(*scanline)*image->columns);
532 /*
533 Decode Huffman encoded scanline.
534 */
535 color=MagickTrue;
536 code=0;
537 count=0;
538 length=0;
539 runlength=0;
540 x=0;
541 for ( ; ; )
542 {
543 if (byte == EOF)
544 break;
545 if (x >= (ssize_t) image->columns)
546 {
547 while (runlength < 11)
548 InputBit(bit);
549 do { InputBit(bit); } while ((int) bit == 0);
550 break;
551 }
552 bail=MagickFalse;
553 do
554 {
555 if (runlength < 11)
556 InputBit(bit)
557 else
558 {
559 InputBit(bit);
560 if ((int) bit != 0)
561 {
562 null_lines++;
563 if (x != 0)
564 null_lines=0;
565 bail=MagickTrue;
566 break;
567 }
568 }
569 code=(code << 1)+(size_t) bit;
570 length++;
571 } while (code == 0);
572 if (bail != MagickFalse)
573 break;
574 if (length > 13)
575 {
576 while (runlength < 11)
577 InputBit(bit);
578 do { InputBit(bit); } while ((int) bit == 0);
579 break;
580 }
581 if (color != MagickFalse)
582 {
583 if (length < 4)
584 continue;
585 entry=mw_hash[((length+MWHashA)*(code+MWHashB)) % HashSize];
586 }
587 else
588 {
589 if (length < 2)
590 continue;
591 entry=mb_hash[((length+MBHashA)*(code+MBHashB)) % HashSize];
592 }
593 if (entry == (const HuffmanTable *) NULL)
594 continue;
595 if ((entry->length != length) || (entry->code != code))
596 continue;
597 switch (entry->id)
598 {
599 case TWId:
600 case TBId:
601 {
602 count+=(ssize_t) entry->count;
603 if ((x+count) > (ssize_t) image->columns)
604 count=(ssize_t) image->columns-x;
605 if (count > 0)
606 {
607 if (color != MagickFalse)
608 {
609 x+=count;
610 count=0;
611 }
612 else
613 for ( ; count > 0; count--)
614 if ((x >= 0) && (x < (ssize_t) image->columns))
615 scanline[x++]=(unsigned char) 1;
616 }
617 color=(unsigned int)
618 ((color == MagickFalse) ? MagickTrue : MagickFalse);
619 break;
620 }
621 case MWId:
622 case MBId:
623 case EXId:
624 {
625 count+=(ssize_t) entry->count;
626 break;
627 }
628 default:
629 break;
630 }
631 code=0;
632 length=0;
633 }
634 /*
635 Transfer scanline to image pixels.
636 */
637 p=scanline;
638 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
639 if (q == (Quantum *) NULL)
640 break;
641 for (x=0; x < (ssize_t) image->columns; x++)
642 {
643 index=(Quantum) (*p++);
644 SetPixelIndex(image,index,q);
645 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
646 q+=(ptrdiff_t) GetPixelChannels(image);
647 }
648 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
649 break;
650 proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
651 image->rows);
652 if (proceed == MagickFalse)
653 break;
654 y++;
655 }
656 image_view=DestroyCacheView(image_view);
657 image->rows=(size_t) MagickMax((size_t) y-3,1);
658 image->compression=FaxCompression;
659 /*
660 Free decoder memory.
661 */
662 mw_hash=(HuffmanTable **) RelinquishMagickMemory(mw_hash);
663 mb_hash=(HuffmanTable **) RelinquishMagickMemory(mb_hash);
664 scanline=(unsigned char *) RelinquishMagickMemory(scanline);
665 return(MagickTrue);
666}
667␌
668/*
669%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
670% %
671% %
672% %
673% H u f f m a n E n c o d e I m a g e %
674% %
675% %
676% %
677%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
678%
679% HuffmanEncodeImage() compresses an image via Huffman-coding.
680%
681% The format of the HuffmanEncodeImage method is:
682%
683% MagickBooleanType HuffmanEncodeImage(const ImageInfo *image_info,
684% Image *image,Image *inject_image,ExceptionInfo *exception)
685%
686% A description of each parameter follows:
687%
688% o image_info: the image info..
689%
690% o image: the image.
691%
692% o inject_image: inject into the image stream.
693%
694% o exception: return any errors or warnings in this structure.
695%
696*/
697MagickExport MagickBooleanType HuffmanEncodeImage(const ImageInfo *image_info,
698 Image *image,Image *inject_image,ExceptionInfo *exception)
699{
700#define HuffmanOutputCode(entry) \
701{ \
702 mask=one << (entry->length-1); \
703 while (mask != 0) \
704 { \
705 if (status == MagickFalse) \
706 break; \
707 OutputBit(((entry->code & mask) != 0 ? 1 : 0)); \
708 mask>>=1; \
709 } \
710}
711
712#define OutputBit(count) \
713{ \
714DisableMSCWarning(4127) \
715 if (count > 0) \
716 byte=byte | bit; \
717RestoreMSCWarning \
718 bit>>=1; \
719 if ((status != MagickFalse) && ((int) (bit & 0xff) == 0)) \
720 { \
721 if (LocaleCompare(image_info->magick,"FAX") == 0) \
722 { \
723 if (WriteBlobByte(image,(unsigned char) byte) != 1) \
724 status=MagickFalse; \
725 } \
726 else \
727 status=Ascii85EncodeInternal(image,byte); \
728 byte='\0'; \
729 bit=(unsigned char) 0x80; \
730 } \
731}
732
733 const HuffmanTable
734 *entry;
735
736 int
737 k,
738 runlength;
739
740 Image
741 *huffman_image;
742
743 MagickBooleanType
744 status;
745
746 ssize_t
747 i,
748 x;
749
750 const Quantum
751 *p;
752
753 unsigned char
754 *q;
755
756 size_t
757 mask,
758 one,
759 width;
760
761 ssize_t
762 n,
763 y;
764
765 unsigned char
766 byte,
767 bit,
768 *scanline;
769
770 /*
771 Allocate scanline buffer.
772 */
773 assert(image_info != (ImageInfo *) NULL);
774 assert(image_info->signature == MagickCoreSignature);
775 assert(image != (Image *) NULL);
776 assert(image->signature == MagickCoreSignature);
777 if (IsEventLogging() != MagickFalse)
778 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
779 assert(inject_image != (Image *) NULL);
780 assert(inject_image->signature == MagickCoreSignature);
781 one=1;
782 status=MagickTrue;
783 width=inject_image->columns;
784 if (LocaleCompare(image_info->magick,"FAX") == 0)
785 width=(size_t) MagickMax(inject_image->columns,1728);
786 scanline=(unsigned char *) AcquireQuantumMemory((size_t) width+1UL,
787 sizeof(*scanline));
788 if (scanline == (unsigned char *) NULL)
789 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
790 inject_image->filename);
791 (void) memset(scanline,0,width*sizeof(*scanline));
792 huffman_image=CloneImage(inject_image,0,0,MagickTrue,exception);
793 if (huffman_image == (Image *) NULL)
794 {
795 scanline=(unsigned char *) RelinquishMagickMemory(scanline);
796 return(MagickFalse);
797 }
798 (void) SetImageType(huffman_image,BilevelType,exception);
799 byte='\0';
800 bit=(unsigned char) 0x80;
801 if (LocaleCompare(image_info->magick,"FAX") != 0)
802 Ascii85Initialize(image);
803 else
804 {
805 /*
806 End of line.
807 */
808 for (k=0; k < 11; k++)
809 OutputBit(0);
810 OutputBit(1);
811 }
812 /*
813 Compress to 1D Huffman pixels.
814 */
815 q=scanline;
816 for (y=0; y < (ssize_t) huffman_image->rows; y++)
817 {
818 if (status == MagickFalse)
819 break;
820 p=GetVirtualPixels(huffman_image,0,y,huffman_image->columns,1,exception);
821 if (p == (const Quantum *) NULL)
822 break;
823 for (x=0; x < (ssize_t) huffman_image->columns; x++)
824 {
825 *q++=(unsigned char) (GetPixelIntensity(huffman_image,p) >=
826 ((double) QuantumRange/2.0) ? 0 : 1);
827 p+=(ptrdiff_t) GetPixelChannels(huffman_image);
828 }
829 /*
830 Huffman encode scanline.
831 */
832 q=scanline;
833 for (n=(ssize_t) width; n > 0; )
834 {
835 if (status == MagickFalse)
836 break;
837 /*
838 Output white run.
839 */
840 for (runlength=0; ((n > 0) && (*q == 0)); n--)
841 {
842 q++;
843 runlength++;
844 }
845 if (runlength >= 64)
846 {
847 if (runlength < 1792)
848 entry=MWTable+((runlength/64)-1);
849 else
850 entry=EXTable+(MagickMin((size_t) runlength,2560)-1792)/64;
851 runlength-=(long) entry->count;
852 HuffmanOutputCode(entry);
853 }
854 entry=TWTable+MagickMin((size_t) runlength,63);
855 HuffmanOutputCode(entry);
856 if (n != 0)
857 {
858 /*
859 Output black run.
860 */
861 for (runlength=0; ((*q != 0) && (n > 0)); n--)
862 {
863 q++;
864 runlength++;
865 }
866 if (runlength >= 64)
867 {
868 entry=MBTable+((runlength/64)-1);
869 if (runlength >= 1792)
870 entry=EXTable+(MagickMin((size_t) runlength,2560)-1792)/64;
871 runlength-=(long) entry->count;
872 HuffmanOutputCode(entry);
873 }
874 entry=TBTable+MagickMin((size_t) runlength,63);
875 HuffmanOutputCode(entry);
876 }
877 }
878 if (status == MagickFalse)
879 break;
880 /*
881 End of line.
882 */
883 for (k=0; k < 11; k++)
884 OutputBit(0);
885 OutputBit(1);
886 if (status == MagickFalse)
887 break;
888 q=scanline;
889 if (GetPreviousImageInList(huffman_image) == (Image *) NULL)
890 {
891 status=SetImageProgress(huffman_image,LoadImageTag,
892 (MagickOffsetType) y,huffman_image->rows);
893 if (status == MagickFalse)
894 break;
895 }
896 }
897 /*
898 End of page.
899 */
900 for (i=0; i < 6; i++)
901 {
902 if (status == MagickFalse)
903 break;
904 for (k=0; k < 11; k++)
905 OutputBit(0);
906 OutputBit(1);
907 }
908 /*
909 Flush bits.
910 */
911 if ((status != MagickFalse) && (((int) bit != 0x80) != 0))
912 {
913 if (LocaleCompare(image_info->magick,"FAX") == 0)
914 {
915 if (WriteBlobByte(image,byte) != 1)
916 status=MagickFalse;
917 }
918 else
919 status=Ascii85EncodeInternal(image,byte);
920 }
921 if ((status != MagickFalse) &&
922 (LocaleCompare(image_info->magick,"FAX") != 0))
923 status=Ascii85FlushInternal(image);
924 huffman_image=DestroyImage(huffman_image);
925 scanline=(unsigned char *) RelinquishMagickMemory(scanline);
926 return(status);
927}
928␌
929/*
930%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
931% %
932% %
933% %
934% L Z W E n c o d e I m a g e %
935% %
936% %
937% %
938%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
939%
940% LZWEncodeImage() compresses an image via LZW-coding specific to Postscript
941% Level II or Portable Document Format.
942%
943% The format of the LZWEncodeImage method is:
944%
945% MagickBooleanType LZWEncodeImage(Image *image,const size_t length,
946% unsigned char *magick_restrict pixels,ExceptionInfo *exception)
947%
948% A description of each parameter follows:
949%
950% o image: the image.
951%
952% o length: A value that specifies the number of pixels to compress.
953%
954% o pixels: the address of an unsigned array of characters containing the
955% pixels to compress.
956%
957% o exception: return any errors or warnings in this structure.
958%
959*/
960MagickExport MagickBooleanType LZWEncodeImage(Image *image,const size_t length,
961 unsigned char *magick_restrict pixels,ExceptionInfo *exception)
962{
963#define LZWClr 256UL /* Clear Table Marker */
964#define LZWEod 257UL /* End of Data marker */
965#define OutputCode(code) \
966{ \
967 accumulator+=code << (32-code_width-number_bits); \
968 number_bits+=code_width; \
969 while (number_bits >= 8) \
970 { \
971 (void) WriteBlobByte(image,(unsigned char) (accumulator >> 24)); \
972 accumulator=accumulator << 8; \
973 number_bits-=8; \
974 } \
975}
976
977 typedef struct _TableType
978 {
979 ssize_t
980 prefix,
981 suffix,
982 next;
983 } TableType;
984
985 ssize_t
986 i;
987
988 size_t
989 accumulator,
990 number_bits,
991 code_width,
992 last_code,
993 next_index;
994
995 ssize_t
996 index;
997
998 TableType
999 *table;
1000
1001 /*
1002 Allocate string table.
1003 */
1004 assert(image != (Image *) NULL);
1005 assert(image->signature == MagickCoreSignature);
1006 assert(pixels != (unsigned char *) NULL);
1007 assert(exception != (ExceptionInfo *) NULL);
1008 assert(exception->signature == MagickCoreSignature);
1009 if (IsEventLogging() != MagickFalse)
1010 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1011 table=(TableType *) AcquireQuantumMemory(1UL << 12,sizeof(*table));
1012 if (table == (TableType *) NULL)
1013 ThrowBinaryException(ResourceLimitWarning,"MemoryAllocationFailed",
1014 image->filename);
1015 /*
1016 Initialize variables.
1017 */
1018 accumulator=0;
1019 code_width=9;
1020 number_bits=0;
1021 last_code=0;
1022 OutputCode(LZWClr);
1023 for (index=0; index < 256; index++)
1024 {
1025 table[index].prefix=(-1);
1026 table[index].suffix=(ssize_t) index;
1027 table[index].next=(-1);
1028 }
1029 next_index=LZWEod+1;
1030 code_width=9;
1031 last_code=(size_t) pixels[0];
1032 for (i=1; i < (ssize_t) length; i++)
1033 {
1034 /*
1035 Find string.
1036 */
1037 index=(ssize_t) last_code;
1038 while (index != -1)
1039 if ((table[index].prefix != (ssize_t) last_code) ||
1040 (table[index].suffix != (ssize_t) pixels[i]))
1041 index=table[index].next;
1042 else
1043 {
1044 last_code=(size_t) index;
1045 break;
1046 }
1047 if (last_code != (size_t) index)
1048 {
1049 /*
1050 Add string.
1051 */
1052 OutputCode(last_code);
1053 table[next_index].prefix=(ssize_t) last_code;
1054 table[next_index].suffix=(ssize_t) pixels[i];
1055 table[next_index].next=table[last_code].next;
1056 table[last_code].next=(ssize_t) next_index;
1057 next_index++;
1058 /*
1059 Did we just move up to next bit width?
1060 */
1061 if ((next_index >> code_width) != 0)
1062 {
1063 code_width++;
1064 if (code_width > 12)
1065 {
1066 /*
1067 Did we overflow the max bit width?
1068 */
1069 code_width--;
1070 OutputCode(LZWClr);
1071 for (index=0; index < 256; index++)
1072 {
1073 table[index].prefix=(-1);
1074 table[index].suffix=index;
1075 table[index].next=(-1);
1076 }
1077 next_index=LZWEod+1;
1078 code_width=9;
1079 }
1080 }
1081 last_code=(size_t) pixels[i];
1082 }
1083 }
1084 /*
1085 Flush tables.
1086 */
1087 OutputCode(last_code);
1088 OutputCode(LZWEod);
1089 if (number_bits != 0)
1090 (void) WriteBlobByte(image,(unsigned char) (accumulator >> 24));
1091 table=(TableType *) RelinquishMagickMemory(table);
1092 return(MagickTrue);
1093}
1094␌
1095/*
1096%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1097% %
1098% %
1099% %
1100% P a c k b i t s E n c o d e I m a g e %
1101% %
1102% %
1103% %
1104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1105%
1106% PackbitsEncodeImage() compresses an image via Macintosh Packbits encoding
1107% specific to Postscript Level II or Portable Document Format. To ensure
1108% portability, the binary Packbits bytes are encoded as ASCII Base-85.
1109%
1110% The format of the PackbitsEncodeImage method is:
1111%
1112% MagickBooleanType PackbitsEncodeImage(Image *image,const size_t length,
1113% unsigned char *magick_restrict pixels)
1114%
1115% A description of each parameter follows:
1116%
1117% o image: the image.
1118%
1119% o length: A value that specifies the number of pixels to compress.
1120%
1121% o pixels: the address of an unsigned array of characters containing the
1122% pixels to compress.
1123%
1124*/
1125MagickExport MagickBooleanType PackbitsEncodeImage(Image *image,
1126 const size_t length,unsigned char *magick_restrict pixels,
1127 ExceptionInfo *exception)
1128{
1129 int
1130 count;
1131
1132 ssize_t
1133 i,
1134 j;
1135
1136 unsigned char
1137 *packbits;
1138
1139 /*
1140 Compress pixels with Packbits encoding.
1141 */
1142 assert(image != (Image *) NULL);
1143 assert(image->signature == MagickCoreSignature);
1144 assert(pixels != (unsigned char *) NULL);
1145 if (IsEventLogging() != MagickFalse)
1146 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1147 packbits=(unsigned char *) AcquireQuantumMemory(128UL,sizeof(*packbits));
1148 if (packbits == (unsigned char *) NULL)
1149 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1150 image->filename);
1151 for (i=(ssize_t) length; i != 0; )
1152 {
1153 switch (i)
1154 {
1155 case 1:
1156 {
1157 i--;
1158 (void) WriteBlobByte(image,(unsigned char) 0);
1159 (void) WriteBlobByte(image,*pixels);
1160 break;
1161 }
1162 case 2:
1163 {
1164 i-=2;
1165 (void) WriteBlobByte(image,(unsigned char) 1);
1166 (void) WriteBlobByte(image,*pixels);
1167 (void) WriteBlobByte(image,pixels[1]);
1168 break;
1169 }
1170 case 3:
1171 {
1172 i-=3;
1173 if ((*pixels == *(pixels+1)) && (*(pixels+1) == *(pixels+2)))
1174 {
1175 (void) WriteBlobByte(image,(unsigned char) ((256-3)+1));
1176 (void) WriteBlobByte(image,*pixels);
1177 break;
1178 }
1179 (void) WriteBlobByte(image,(unsigned char) 2);
1180 (void) WriteBlobByte(image,*pixels);
1181 (void) WriteBlobByte(image,pixels[1]);
1182 (void) WriteBlobByte(image,pixels[2]);
1183 break;
1184 }
1185 default:
1186 {
1187 if ((*pixels == *(pixels+1)) && (*(pixels+1) == *(pixels+2)))
1188 {
1189 /*
1190 Packed run.
1191 */
1192 count=3;
1193 while (((ssize_t) count < i) && (*pixels == *(pixels+count)))
1194 {
1195 count++;
1196 if (count >= 127)
1197 break;
1198 }
1199 i-=count;
1200 (void) WriteBlobByte(image,(unsigned char) ((256-count)+1));
1201 (void) WriteBlobByte(image,*pixels);
1202 pixels+=count;
1203 break;
1204 }
1205 /*
1206 Literal run.
1207 */
1208 count=0;
1209 while ((*(pixels+count) != *(pixels+count+1)) ||
1210 (*(pixels+count+1) != *(pixels+count+2)))
1211 {
1212 packbits[count+1]=pixels[count];
1213 count++;
1214 if (((ssize_t) count >= (i-3)) || (count >= 127))
1215 break;
1216 }
1217 i-=count;
1218 *packbits=(unsigned char) (count-1);
1219 for (j=0; j <= (ssize_t) count; j++)
1220 (void) WriteBlobByte(image,packbits[j]);
1221 pixels+=count;
1222 break;
1223 }
1224 }
1225 }
1226 (void) WriteBlobByte(image,(unsigned char) 128); /* EOD marker */
1227 packbits=(unsigned char *) RelinquishMagickMemory(packbits);
1228 return(MagickTrue);
1229}
1230␌
1231#if defined(MAGICKCORE_ZLIB_DELEGATE)
1232/*
1233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234% %
1235% %
1236% %
1237% Z L I B E n c o d e I m a g e %
1238% %
1239% %
1240% %
1241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1242%
1243% ZLIBEncodeImage compresses an image via ZLIB-coding specific to
1244% Postscript Level II or Portable Document Format.
1245%
1246% The format of the ZLIBEncodeImage method is:
1247%
1248% MagickBooleanType ZLIBEncodeImage(Image *image,const size_t length,
1249% unsigned char *magick_restrict pixels,ExceptionInfo *exception)
1250%
1251% A description of each parameter follows:
1252%
1253% o file: the address of a structure of type FILE. ZLIB encoded pixels
1254% are written to this file.
1255%
1256% o length: A value that specifies the number of pixels to compress.
1257%
1258% o pixels: the address of an unsigned array of characters containing the
1259% pixels to compress.
1260%
1261% o exception: return any errors or warnings in this structure.
1262%
1263*/
1264
1265static voidpf AcquireZIPMemory(voidpf context,unsigned int items,
1266 unsigned int size)
1267{
1268 (void) context;
1269 return((voidpf) AcquireQuantumMemory(items,size));
1270}
1271
1272static void RelinquishZIPMemory(voidpf context,voidpf memory)
1273{
1274 (void) context;
1275 memory=RelinquishMagickMemory(memory);
1276}
1277
1278MagickExport MagickBooleanType ZLIBEncodeImage(Image *image,const size_t length,
1279 unsigned char *magick_restrict pixels,ExceptionInfo *exception)
1280{
1281 int
1282 status;
1283
1284 ssize_t
1285 i;
1286
1287 size_t
1288 compress_packets;
1289
1290 unsigned char
1291 *compress_pixels;
1292
1293 z_stream
1294 stream;
1295
1296 assert(image != (Image *) NULL);
1297 assert(image->signature == MagickCoreSignature);
1298 if (IsEventLogging() != MagickFalse)
1299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1300 compress_packets=(size_t) (1.001*length+12);
1301 compress_pixels=(unsigned char *) AcquireQuantumMemory(compress_packets,
1302 sizeof(*compress_pixels));
1303 if (compress_pixels == (unsigned char *) NULL)
1304 ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1305 image->filename);
1306 (void) memset(&stream,0,sizeof(stream));
1307 stream.next_in=pixels;
1308 stream.avail_in=(unsigned int) length;
1309 stream.next_out=compress_pixels;
1310 stream.avail_out=(unsigned int) compress_packets;
1311 stream.zalloc=AcquireZIPMemory;
1312 stream.zfree=RelinquishZIPMemory;
1313 stream.opaque=(voidpf) NULL;
1314 status=deflateInit(&stream,(int) (image->quality ==
1315 UndefinedCompressionQuality ? 7 : MagickMin(image->quality/10,9)));
1316 if (status == Z_OK)
1317 {
1318 status=deflate(&stream,Z_FINISH);
1319 if (status == Z_STREAM_END)
1320 status=deflateEnd(&stream);
1321 else
1322 (void) deflateEnd(&stream);
1323 compress_packets=(size_t) stream.total_out;
1324 }
1325 if (status != Z_OK)
1326 ThrowBinaryException(CoderError,"UnableToZipCompressImage",image->filename)
1327 for (i=0; i < (ssize_t) compress_packets; i++)
1328 (void) WriteBlobByte(image,compress_pixels[i]);
1329 compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
1330 return(MagickTrue);
1331}
1332#else
1333MagickExport MagickBooleanType ZLIBEncodeImage(Image *image,
1334 const size_t magick_unused(length),unsigned char *magick_unused(pixels),
1335 ExceptionInfo *exception)
1336{
1337 magick_unreferenced(length);
1338 magick_unreferenced(pixels);
1339 assert(image != (Image *) NULL);
1340 assert(image->signature == MagickCoreSignature);
1341 if (IsEventLogging() != MagickFalse)
1342 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1343 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
1344 "DelegateLibrarySupportNotBuiltIn","'%s' (ZIP)",image->filename);
1345 return(MagickFalse);
1346}
1347#endif