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