MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
compress.c
Go to the documentation of this file.
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-2018 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://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 
40 /*
41  Include declarations.
42 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/attribute.h"
45 #include "MagickCore/blob.h"
48 #include "MagickCore/cache.h"
49 #include "MagickCore/compress.h"
50 #include "MagickCore/constitute.h"
51 #include "MagickCore/exception.h"
54 #include "MagickCore/list.h"
55 #include "MagickCore/memory_.h"
56 #include "MagickCore/monitor.h"
58 #include "MagickCore/option.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
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 
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
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
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
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
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
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 
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 
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 
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 
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 */
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 
408  **mb_hash,
409  **mw_hash;
410 
411  int
412  byte;
413 
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  {
460  if (mb_hash != (HuffmanTable **) NULL)
461  mw_hash=(HuffmanTable **) RelinquishMagickMemory(mw_hash);
462  if (mw_hash != (HuffmanTable **) NULL)
463  mb_hash=(HuffmanTable **) RelinquishMagickMemory(mb_hash);
464  if (scanline != (unsigned char *) NULL)
465  scanline=(unsigned char *) RelinquishMagickMemory(scanline);
466  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
467  image->filename);
468  }
469  /*
470  Initialize Huffman tables.
471  */
472  for (i=0; i < HashSize; i++)
473  {
474  mb_hash[i]=(HuffmanTable *) NULL;
475  mw_hash[i]=(HuffmanTable *) NULL;
476  }
483  /*
484  Uncompress 1D Huffman to runlength encoded pixels.
485  */
486  byte=0;
487  mask=0;
488  null_lines=0;
489  runlength=0;
490  while (runlength < 11)
491  InputBit(bit);
492  do { InputBit(bit); } while ((int) bit == 0);
493  image->resolution.x=204.0;
494  image->resolution.y=196.0;
496  image_view=AcquireAuthenticCacheView(image,exception);
497  for (y=0; ((y < (ssize_t) image->rows) && (null_lines < 3)); )
498  {
499  register Quantum
500  *magick_restrict q;
501 
502  register ssize_t
503  x;
504 
505  /*
506  Initialize scanline to white.
507  */
508  ResetMagickMemory(scanline,0,sizeof(*scanline)*image->columns);
509  /*
510  Decode Huffman encoded scanline.
511  */
512  color=MagickTrue;
513  code=0;
514  count=0;
515  length=0;
516  runlength=0;
517  x=0;
518  for ( ; ; )
519  {
520  if (byte == EOF)
521  break;
522  if (x >= (ssize_t) image->columns)
523  {
524  while (runlength < 11)
525  InputBit(bit);
526  do { InputBit(bit); } while ((int) bit == 0);
527  break;
528  }
529  bail=MagickFalse;
530  do
531  {
532  if (runlength < 11)
533  InputBit(bit)
534  else
535  {
536  InputBit(bit);
537  if ((int) bit != 0)
538  {
539  null_lines++;
540  if (x != 0)
541  null_lines=0;
542  bail=MagickTrue;
543  break;
544  }
545  }
546  code=(code << 1)+(size_t) bit;
547  length++;
548  } while (code == 0);
549  if (bail != MagickFalse)
550  break;
551  if (length > 13)
552  {
553  while (runlength < 11)
554  InputBit(bit);
555  do { InputBit(bit); } while ((int) bit == 0);
556  break;
557  }
558  if (color != MagickFalse)
559  {
560  if (length < 4)
561  continue;
562  entry=mw_hash[((length+MWHashA)*(code+MWHashB)) % HashSize];
563  }
564  else
565  {
566  if (length < 2)
567  continue;
568  entry=mb_hash[((length+MBHashA)*(code+MBHashB)) % HashSize];
569  }
570  if (entry == (const HuffmanTable *) NULL)
571  continue;
572  if ((entry->length != length) || (entry->code != code))
573  continue;
574  switch (entry->id)
575  {
576  case TWId:
577  case TBId:
578  {
579  count+=(ssize_t) entry->count;
580  if ((x+count) > (ssize_t) image->columns)
581  count=(ssize_t) image->columns-x;
582  if (count > 0)
583  {
584  if (color != MagickFalse)
585  {
586  x+=count;
587  count=0;
588  }
589  else
590  for ( ; count > 0; count--)
591  scanline[x++]=(unsigned char) 1;
592  }
593  color=(unsigned int)
594  ((color == MagickFalse) ? MagickTrue : MagickFalse);
595  break;
596  }
597  case MWId:
598  case MBId:
599  case EXId:
600  {
601  count+=(ssize_t) entry->count;
602  break;
603  }
604  default:
605  break;
606  }
607  code=0;
608  length=0;
609  }
610  /*
611  Transfer scanline to image pixels.
612  */
613  p=scanline;
614  q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
615  if (q == (Quantum *) NULL)
616  break;
617  for (x=0; x < (ssize_t) image->columns; x++)
618  {
619  index=(Quantum) (*p++);
620  SetPixelIndex(image,index,q);
621  SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
622  q+=GetPixelChannels(image);
623  }
624  if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
625  break;
626  proceed=SetImageProgress(image,LoadImageTag,y,image->rows);
627  if (proceed == MagickFalse)
628  break;
629  y++;
630  }
631  image_view=DestroyCacheView(image_view);
632  image->rows=(size_t) MagickMax((size_t) y-3,1);
634  /*
635  Free decoder memory.
636  */
637  mw_hash=(HuffmanTable **) RelinquishMagickMemory(mw_hash);
638  mb_hash=(HuffmanTable **) RelinquishMagickMemory(mb_hash);
639  scanline=(unsigned char *) RelinquishMagickMemory(scanline);
640  return(MagickTrue);
641 }
642 
643 /*
644 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
645 % %
646 % %
647 % %
648 % H u f f m a n E n c o d e I m a g e %
649 % %
650 % %
651 % %
652 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
653 %
654 % HuffmanEncodeImage() compresses an image via Huffman-coding.
655 %
656 % The format of the HuffmanEncodeImage method is:
657 %
658 % MagickBooleanType HuffmanEncodeImage(const ImageInfo *image_info,
659 % Image *image,Image *inject_image,ExceptionInfo *exception)
660 %
661 % A description of each parameter follows:
662 %
663 % o image_info: the image info..
664 %
665 % o image: the image.
666 %
667 % o inject_image: inject into the image stream.
668 %
669 % o exception: return any errors or warnings in this structure.
670 %
671 */
673  Image *image,Image *inject_image,ExceptionInfo *exception)
674 {
675 #define HuffmanOutputCode(entry) \
676 { \
677  mask=one << (entry->length-1); \
678  while (mask != 0) \
679  { \
680  OutputBit(((entry->code & mask) != 0 ? 1 : 0)); \
681  mask>>=1; \
682  } \
683 }
684 
685 #define OutputBit(count) \
686 { \
687 DisableMSCWarning(4127) \
688  if (count > 0) \
689  byte=byte | bit; \
690 RestoreMSCWarning \
691  bit>>=1; \
692  if ((int) (bit & 0xff) == 0) \
693  { \
694  if (LocaleCompare(image_info->magick,"FAX") == 0) \
695  (void) WriteBlobByte(image,(unsigned char) byte); \
696  else \
697  Ascii85Encode(image,byte); \
698  byte='\0'; \
699  bit=(unsigned char) 0x80; \
700  } \
701 }
702 
703  const HuffmanTable
704  *entry;
705 
706  int
707  k,
708  runlength;
709 
710  Image
711  *huffman_image;
712 
714  proceed;
715 
716  register ssize_t
717  i,
718  x;
719 
720  register const Quantum
721  *p;
722 
723  register unsigned char
724  *q;
725 
726  size_t
727  mask,
728  one,
729  width;
730 
731  ssize_t
732  n,
733  y;
734 
735  unsigned char
736  byte,
737  bit,
738  *scanline;
739 
740  /*
741  Allocate scanline buffer.
742  */
743  assert(image_info != (ImageInfo *) NULL);
744  assert(image_info->signature == MagickCoreSignature);
745  assert(image != (Image *) NULL);
746  assert(image->signature == MagickCoreSignature);
747  if (image->debug != MagickFalse)
748  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
749  assert(inject_image != (Image *) NULL);
750  assert(inject_image->signature == MagickCoreSignature);
751  one=1;
752  width=inject_image->columns;
753  if (LocaleCompare(image_info->magick,"FAX") == 0)
754  width=(size_t) MagickMax(inject_image->columns,1728);
755  scanline=(unsigned char *) AcquireQuantumMemory((size_t) width+1UL,
756  sizeof(*scanline));
757  if (scanline == (unsigned char *) NULL)
758  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
759  inject_image->filename);
760  (void) ResetMagickMemory(scanline,0,width*sizeof(*scanline));
761  huffman_image=CloneImage(inject_image,0,0,MagickTrue,exception);
762  if (huffman_image == (Image *) NULL)
763  {
764  scanline=(unsigned char *) RelinquishMagickMemory(scanline);
765  return(MagickFalse);
766  }
767  (void) SetImageType(huffman_image,BilevelType,exception);
768  byte='\0';
769  bit=(unsigned char) 0x80;
770  if (LocaleCompare(image_info->magick,"FAX") != 0)
771  Ascii85Initialize(image);
772  else
773  {
774  /*
775  End of line.
776  */
777  for (k=0; k < 11; k++)
778  OutputBit(0);
779  OutputBit(1);
780  }
781  /*
782  Compress to 1D Huffman pixels.
783  */
784  q=scanline;
785  for (y=0; y < (ssize_t) huffman_image->rows; y++)
786  {
787  p=GetVirtualPixels(huffman_image,0,y,huffman_image->columns,1,exception);
788  if (p == (const Quantum *) NULL)
789  break;
790  for (x=0; x < (ssize_t) huffman_image->columns; x++)
791  {
792  *q++=(unsigned char) (GetPixelIntensity(huffman_image,p) >=
793  ((double) QuantumRange/2.0) ? 0 : 1);
794  p+=GetPixelChannels(huffman_image);
795  }
796  /*
797  Huffman encode scanline.
798  */
799  q=scanline;
800  for (n=(ssize_t) width; n > 0; )
801  {
802  /*
803  Output white run.
804  */
805  for (runlength=0; ((n > 0) && (*q == 0)); n--)
806  {
807  q++;
808  runlength++;
809  }
810  if (runlength >= 64)
811  {
812  if (runlength < 1792)
813  entry=MWTable+((runlength/64)-1);
814  else
815  entry=EXTable+(MagickMin((size_t) runlength,2560)-1792)/64;
816  runlength-=(long) entry->count;
817  HuffmanOutputCode(entry);
818  }
819  entry=TWTable+MagickMin((size_t) runlength,63);
820  HuffmanOutputCode(entry);
821  if (n != 0)
822  {
823  /*
824  Output black run.
825  */
826  for (runlength=0; ((*q != 0) && (n > 0)); n--)
827  {
828  q++;
829  runlength++;
830  }
831  if (runlength >= 64)
832  {
833  entry=MBTable+((runlength/64)-1);
834  if (runlength >= 1792)
835  entry=EXTable+(MagickMin((size_t) runlength,2560)-1792)/64;
836  runlength-=(long) entry->count;
837  HuffmanOutputCode(entry);
838  }
839  entry=TBTable+MagickMin((size_t) runlength,63);
840  HuffmanOutputCode(entry);
841  }
842  }
843  /*
844  End of line.
845  */
846  for (k=0; k < 11; k++)
847  OutputBit(0);
848  OutputBit(1);
849  q=scanline;
850  if (GetPreviousImageInList(huffman_image) == (Image *) NULL)
851  {
852  proceed=SetImageProgress(huffman_image,LoadImageTag,y,
853  huffman_image->rows);
854  if (proceed == MagickFalse)
855  break;
856  }
857  }
858  /*
859  End of page.
860  */
861  for (i=0; i < 6; i++)
862  {
863  for (k=0; k < 11; k++)
864  OutputBit(0);
865  OutputBit(1);
866  }
867  /*
868  Flush bits.
869  */
870  if (((int) bit != 0x80) != 0)
871  {
872  if (LocaleCompare(image_info->magick,"FAX") == 0)
873  (void) WriteBlobByte(image,byte);
874  else
875  Ascii85Encode(image,byte);
876  }
877  if (LocaleCompare(image_info->magick,"FAX") != 0)
878  Ascii85Flush(image);
879  huffman_image=DestroyImage(huffman_image);
880  scanline=(unsigned char *) RelinquishMagickMemory(scanline);
881  return(MagickTrue);
882 }
883 
884 /*
885 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
886 % %
887 % %
888 % %
889 % L Z W E n c o d e I m a g e %
890 % %
891 % %
892 % %
893 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
894 %
895 % LZWEncodeImage() compresses an image via LZW-coding specific to Postscript
896 % Level II or Portable Document Format.
897 %
898 % The format of the LZWEncodeImage method is:
899 %
900 % MagickBooleanType LZWEncodeImage(Image *image,const size_t length,
901 % unsigned char *magick_restrict pixels,ExceptionInfo *exception)
902 %
903 % A description of each parameter follows:
904 %
905 % o image: the image.
906 %
907 % o length: A value that specifies the number of pixels to compress.
908 %
909 % o pixels: the address of an unsigned array of characters containing the
910 % pixels to compress.
911 %
912 % o exception: return any errors or warnings in this structure.
913 %
914 */
916  unsigned char *magick_restrict pixels,ExceptionInfo *exception)
917 {
918 #define LZWClr 256UL /* Clear Table Marker */
919 #define LZWEod 257UL /* End of Data marker */
920 #define OutputCode(code) \
921 { \
922  accumulator+=code << (32-code_width-number_bits); \
923  number_bits+=code_width; \
924  while (number_bits >= 8) \
925  { \
926  (void) WriteBlobByte(image,(unsigned char) (accumulator >> 24)); \
927  accumulator=accumulator << 8; \
928  number_bits-=8; \
929  } \
930 }
931 
932  typedef struct _TableType
933  {
934  ssize_t
935  prefix,
936  suffix,
937  next;
938  } TableType;
939 
940  register ssize_t
941  i;
942 
943  size_t
944  accumulator,
945  number_bits,
946  code_width,
947  last_code,
948  next_index;
949 
950  ssize_t
951  index;
952 
953  TableType
954  *table;
955 
956  /*
957  Allocate string table.
958  */
959  assert(image != (Image *) NULL);
960  assert(image->signature == MagickCoreSignature);
961  if (image->debug != MagickFalse)
962  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
963  assert(pixels != (unsigned char *) NULL);
964  assert(exception != (ExceptionInfo *) NULL);
965  assert(exception->signature == MagickCoreSignature);
966  table=(TableType *) AcquireQuantumMemory(1UL << 12,sizeof(*table));
967  if (table == (TableType *) NULL)
968  return(MagickFalse);
969  /*
970  Initialize variables.
971  */
972  accumulator=0;
973  code_width=9;
974  number_bits=0;
975  last_code=0;
977  for (index=0; index < 256; index++)
978  {
979  table[index].prefix=(-1);
980  table[index].suffix=(short) index;
981  table[index].next=(-1);
982  }
983  next_index=LZWEod+1;
984  code_width=9;
985  last_code=(size_t) pixels[0];
986  for (i=1; i < (ssize_t) length; i++)
987  {
988  /*
989  Find string.
990  */
991  index=(ssize_t) last_code;
992  while (index != -1)
993  if ((table[index].prefix != (ssize_t) last_code) ||
994  (table[index].suffix != (ssize_t) pixels[i]))
995  index=table[index].next;
996  else
997  {
998  last_code=(size_t) index;
999  break;
1000  }
1001  if (last_code != (size_t) index)
1002  {
1003  /*
1004  Add string.
1005  */
1006  OutputCode(last_code);
1007  table[next_index].prefix=(ssize_t) last_code;
1008  table[next_index].suffix=(short) pixels[i];
1009  table[next_index].next=table[last_code].next;
1010  table[last_code].next=(ssize_t) next_index;
1011  next_index++;
1012  /*
1013  Did we just move up to next bit width?
1014  */
1015  if ((next_index >> code_width) != 0)
1016  {
1017  code_width++;
1018  if (code_width > 12)
1019  {
1020  /*
1021  Did we overflow the max bit width?
1022  */
1023  code_width--;
1024  OutputCode(LZWClr);
1025  for (index=0; index < 256; index++)
1026  {
1027  table[index].prefix=(-1);
1028  table[index].suffix=index;
1029  table[index].next=(-1);
1030  }
1031  next_index=LZWEod+1;
1032  code_width=9;
1033  }
1034  }
1035  last_code=(size_t) pixels[i];
1036  }
1037  }
1038  /*
1039  Flush tables.
1040  */
1041  OutputCode(last_code);
1042  OutputCode(LZWEod);
1043  if (number_bits != 0)
1044  (void) WriteBlobByte(image,(unsigned char) (accumulator >> 24));
1045  table=(TableType *) RelinquishMagickMemory(table);
1046  return(MagickTrue);
1047 }
1048 
1049 /*
1050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1051 % %
1052 % %
1053 % %
1054 % P a c k b i t s E n c o d e I m a g e %
1055 % %
1056 % %
1057 % %
1058 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1059 %
1060 % PackbitsEncodeImage() compresses an image via Macintosh Packbits encoding
1061 % specific to Postscript Level II or Portable Document Format. To ensure
1062 % portability, the binary Packbits bytes are encoded as ASCII Base-85.
1063 %
1064 % The format of the PackbitsEncodeImage method is:
1065 %
1066 % MagickBooleanType PackbitsEncodeImage(Image *image,const size_t length,
1067 % unsigned char *magick_restrict pixels)
1068 %
1069 % A description of each parameter follows:
1070 %
1071 % o image: the image.
1072 %
1073 % o length: A value that specifies the number of pixels to compress.
1074 %
1075 % o pixels: the address of an unsigned array of characters containing the
1076 % pixels to compress.
1077 %
1078 */
1080  const size_t length,unsigned char *magick_restrict pixels,
1081  ExceptionInfo *exception)
1082 {
1083  int
1084  count;
1085 
1086  register ssize_t
1087  i,
1088  j;
1089 
1090  unsigned char
1091  *packbits;
1092 
1093  /*
1094  Compress pixels with Packbits encoding.
1095  */
1096  assert(image != (Image *) NULL);
1097  assert(image->signature == MagickCoreSignature);
1098  if (image->debug != MagickFalse)
1099  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1100  assert(pixels != (unsigned char *) NULL);
1101  packbits=(unsigned char *) AcquireQuantumMemory(128UL,sizeof(*packbits));
1102  if (packbits == (unsigned char *) NULL)
1103  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1104  image->filename);
1105  for (i=(ssize_t) length; i != 0; )
1106  {
1107  switch (i)
1108  {
1109  case 1:
1110  {
1111  i--;
1112  (void) WriteBlobByte(image,(unsigned char) 0);
1113  (void) WriteBlobByte(image,*pixels);
1114  break;
1115  }
1116  case 2:
1117  {
1118  i-=2;
1119  (void) WriteBlobByte(image,(unsigned char) 1);
1120  (void) WriteBlobByte(image,*pixels);
1121  (void) WriteBlobByte(image,pixels[1]);
1122  break;
1123  }
1124  case 3:
1125  {
1126  i-=3;
1127  if ((*pixels == *(pixels+1)) && (*(pixels+1) == *(pixels+2)))
1128  {
1129  (void) WriteBlobByte(image,(unsigned char) ((256-3)+1));
1130  (void) WriteBlobByte(image,*pixels);
1131  break;
1132  }
1133  (void) WriteBlobByte(image,(unsigned char) 2);
1134  (void) WriteBlobByte(image,*pixels);
1135  (void) WriteBlobByte(image,pixels[1]);
1136  (void) WriteBlobByte(image,pixels[2]);
1137  break;
1138  }
1139  default:
1140  {
1141  if ((*pixels == *(pixels+1)) && (*(pixels+1) == *(pixels+2)))
1142  {
1143  /*
1144  Packed run.
1145  */
1146  count=3;
1147  while (((ssize_t) count < i) && (*pixels == *(pixels+count)))
1148  {
1149  count++;
1150  if (count >= 127)
1151  break;
1152  }
1153  i-=count;
1154  (void) WriteBlobByte(image,(unsigned char) ((256-count)+1));
1155  (void) WriteBlobByte(image,*pixels);
1156  pixels+=count;
1157  break;
1158  }
1159  /*
1160  Literal run.
1161  */
1162  count=0;
1163  while ((*(pixels+count) != *(pixels+count+1)) ||
1164  (*(pixels+count+1) != *(pixels+count+2)))
1165  {
1166  packbits[count+1]=pixels[count];
1167  count++;
1168  if (((ssize_t) count >= (i-3)) || (count >= 127))
1169  break;
1170  }
1171  i-=count;
1172  *packbits=(unsigned char) (count-1);
1173  for (j=0; j <= (ssize_t) count; j++)
1174  (void) WriteBlobByte(image,packbits[j]);
1175  pixels+=count;
1176  break;
1177  }
1178  }
1179  }
1180  (void) WriteBlobByte(image,(unsigned char) 128); /* EOD marker */
1181  packbits=(unsigned char *) RelinquishMagickMemory(packbits);
1182  return(MagickTrue);
1183 }
1184 
1185 #if defined(MAGICKCORE_ZLIB_DELEGATE)
1186 /*
1187 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1188 % %
1189 % %
1190 % %
1191 % Z L I B E n c o d e I m a g e %
1192 % %
1193 % %
1194 % %
1195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196 %
1197 % ZLIBEncodeImage compresses an image via ZLIB-coding specific to
1198 % Postscript Level II or Portable Document Format.
1199 %
1200 % The format of the ZLIBEncodeImage method is:
1201 %
1202 % MagickBooleanType ZLIBEncodeImage(Image *image,const size_t length,
1203 % unsigned char *magick_restrict pixels,ExceptionInfo *exception)
1204 %
1205 % A description of each parameter follows:
1206 %
1207 % o file: the address of a structure of type FILE. ZLIB encoded pixels
1208 % are written to this file.
1209 %
1210 % o length: A value that specifies the number of pixels to compress.
1211 %
1212 % o pixels: the address of an unsigned array of characters containing the
1213 % pixels to compress.
1214 %
1215 % o exception: return any errors or warnings in this structure.
1216 %
1217 */
1218 
1219 static voidpf AcquireZIPMemory(voidpf context,unsigned int items,
1220  unsigned int size)
1221 {
1222  (void) context;
1223  return((voidpf) AcquireQuantumMemory(items,size));
1224 }
1225 
1226 static void RelinquishZIPMemory(voidpf context,voidpf memory)
1227 {
1228  (void) context;
1229  memory=RelinquishMagickMemory(memory);
1230 }
1231 
1232 MagickExport MagickBooleanType ZLIBEncodeImage(Image *image,const size_t length,
1233  unsigned char *magick_restrict pixels,ExceptionInfo *exception)
1234 {
1235  int
1236  status;
1237 
1238  register ssize_t
1239  i;
1240 
1241  size_t
1242  compress_packets;
1243 
1244  unsigned char
1245  *compress_pixels;
1246 
1247  z_stream
1248  stream;
1249 
1250  assert(image != (Image *) NULL);
1251  assert(image->signature == MagickCoreSignature);
1252  if (image->debug != MagickFalse)
1253  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1254  compress_packets=(size_t) (1.001*length+12);
1255  compress_pixels=(unsigned char *) AcquireQuantumMemory(compress_packets,
1256  sizeof(*compress_pixels));
1257  if (compress_pixels == (unsigned char *) NULL)
1258  ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
1259  image->filename);
1260  stream.next_in=pixels;
1261  stream.avail_in=(unsigned int) length;
1262  stream.next_out=compress_pixels;
1263  stream.avail_out=(unsigned int) compress_packets;
1264  stream.zalloc=AcquireZIPMemory;
1265  stream.zfree=RelinquishZIPMemory;
1266  stream.opaque=(voidpf) NULL;
1267  status=deflateInit(&stream,(int) (image->quality ==
1268  UndefinedCompressionQuality ? 7 : MagickMin(image->quality/10,9)));
1269  if (status == Z_OK)
1270  {
1271  status=deflate(&stream,Z_FINISH);
1272  if (status == Z_STREAM_END)
1273  status=deflateEnd(&stream);
1274  else
1275  (void) deflateEnd(&stream);
1276  compress_packets=(size_t) stream.total_out;
1277  }
1278  if (status != Z_OK)
1279  ThrowBinaryException(CoderError,"UnableToZipCompressImage",image->filename)
1280  for (i=0; i < (ssize_t) compress_packets; i++)
1281  (void) WriteBlobByte(image,compress_pixels[i]);
1282  compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels);
1283  return(MagickTrue);
1284 }
1285 #else
1287  const size_t magick_unused(length),unsigned char *magick_unused(pixels),
1288  ExceptionInfo *exception)
1289 {
1290  magick_unreferenced(length);
1291  magick_unreferenced(pixels);
1292  assert(image != (Image *) NULL);
1293  assert(image->signature == MagickCoreSignature);
1294  if (image->debug != MagickFalse)
1295  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1297  "DelegateLibrarySupportNotBuiltIn","'%s' (ZIP)",image->filename);
1298  return(MagickFalse);
1299 }
1300 #endif
size_t rows
Definition: image.h:172
#define magick_restrict
Definition: MagickCore.h:41
struct HuffmanTable HuffmanTable
MagickExport CacheView * DestroyCacheView(CacheView *cache_view)
Definition: cache-view.c:252
size_t code
Definition: compress.c:82
MagickExport MagickBooleanType PackbitsEncodeImage(Image *image, const size_t length, unsigned char *magick_restrict pixels, ExceptionInfo *exception)
Definition: compress.c:1079
size_t signature
Definition: image.h:479
MagickExport MagickBooleanType HuffmanDecodeImage(Image *image, ExceptionInfo *exception)
Definition: compress.c:366
static MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
PixelInfo * colormap
Definition: image.h:179
Ascii85Info * ascii85
Definition: image.h:309
char magick[MagickPathExtent]
Definition: image.h:471
MagickExport void Ascii85Initialize(Image *image)
Definition: compress.c:264
static const HuffmanTable TBTable[]
Definition: compress.c:148
size_t length
Definition: compress.c:82
#define MWId
Definition: compress.c:92
#define MBHashA
#define ThrowFatalException(severity, tag)
size_t signature
Definition: exception.h:123
#define TBId
Definition: compress.c:93
#define TWId
Definition: compress.c:91
ssize_t offset
Definition: compress.c:72
#define MBId
Definition: compress.c:94
MagickExport ssize_t WriteBlob(Image *, const size_t, const void *)
MagickExport const char LoadImageTag[]
Definition: image.c:115
#define LZWClr
static void SetPixelViaPixelInfo(const Image *magick_restrict image, const PixelInfo *magick_restrict pixel_info, Quantum *magick_restrict pixel)
ResolutionType units
Definition: image.h:198
MagickExport MagickBooleanType HuffmanEncodeImage(const ImageInfo *image_info, Image *image, Image *inject_image, ExceptionInfo *exception)
Definition: compress.c:672
#define MBHashB
CompressionType compression
Definition: image.h:160
#define ThrowBinaryException(severity, tag, context)
Definition: log.h:52
Definition: image.h:151
MagickExport Image * GetPreviousImageInList(const Image *images)
Definition: list.c:784
#define MWHashA
double x
Definition: geometry.h:122
#define MagickCoreSignature
MagickExport MagickBooleanType SetImageType(Image *image, const ImageType type, ExceptionInfo *exception)
Definition: attribute.c:1230
unsigned char buffer[10]
Definition: compress.c:76
MagickBooleanType
Definition: magick-type.h:156
#define InitializeHashTable(hash, table, a, b)
MagickExport void * ResetMagickMemory(void *memory, int byte, const size_t size)
Definition: memory.c:1164
MagickExport ssize_t WriteBlobByte(Image *, const unsigned char)
MagickExport const Quantum * GetVirtualPixels(const Image *image, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache.c:3154
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:529
static const HuffmanTable MBTable[]
Definition: compress.c:98
MagickExport void Ascii85Flush(Image *image)
Definition: compress.c:278
double y
Definition: geometry.h:122
#define magick_unused(x)
#define UndefinedCompressionQuality
Definition: image-private.h:36
MagickExport Quantum * QueueCacheViewAuthenticPixels(CacheView *cache_view, const ssize_t x, const ssize_t y, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: cache-view.c:977
MagickExport void Ascii85Encode(Image *image, const unsigned char code)
Definition: compress.c:302
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1058
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1397
static char * Ascii85Tuple(unsigned char *data)
Definition: compress.c:230
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
#define LZWEod
#define MagickMax(x, y)
Definition: image-private.h:26
static const HuffmanTable EXTable[]
Definition: compress.c:117
size_t quality
Definition: image.h:163
#define EXId
Definition: compress.c:95
ssize_t line_break
Definition: compress.c:72
static size_t GetPixelChannels(const Image *magick_restrict image)
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1409
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
size_t count
Definition: compress.c:82
#define MWHashB
unsigned short Quantum
Definition: magick-type.h:82
MagickExport void * AcquireMagickMemory(const size_t size)
Definition: memory.c:458
size_t id
Definition: compress.c:82
#define OutputCode(code)
static void SetPixelIndex(const Image *magick_restrict image, const Quantum index, Quantum *magick_restrict pixel)
#define MagickMin(x, y)
Definition: image-private.h:27
#define OutputBit(count)
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1038
PointInfo resolution
Definition: image.h:209
#define magick_unreferenced(x)
#define HuffmanOutputCode(entry)
#define MaxLineExtent
Definition: compress.c:228
MagickExport MagickBooleanType ZLIBEncodeImage(Image *image, const size_t magick_unused(length), unsigned char *magick_unused(pixels), ExceptionInfo *exception)
Definition: compress.c:1286
#define MagickExport
MagickExport MagickBooleanType SyncCacheViewAuthenticPixels(CacheView *magick_restrict cache_view, ExceptionInfo *exception)
Definition: cache-view.c:1100
MagickExport CacheView * AcquireAuthenticCacheView(const Image *image, ExceptionInfo *exception)
Definition: cache-view.c:112
#define InputBit(bit)
static const HuffmanTable MWTable[]
Definition: compress.c:129
#define HashSize
static const HuffmanTable TWTable[]
Definition: compress.c:175
MagickExport MagickRealType GetPixelIntensity(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
Definition: pixel.c:2356
MagickExport Image * DestroyImage(Image *image)
Definition: image.c:1182
MagickExport Image * CloneImage(const Image *image, const size_t columns, const size_t rows, const MagickBooleanType detach, ExceptionInfo *exception)
Definition: image.c:799
MagickExport MagickBooleanType LZWEncodeImage(Image *image, const size_t length, unsigned char *magick_restrict pixels, ExceptionInfo *exception)
Definition: compress.c:915
#define QuantumRange
Definition: magick-type.h:83
MagickBooleanType debug
Definition: image.h:334