blob: 282aff9413d86c53ec40b300bd2ef164418d217d [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% JJJJJ BBBB IIIII GGGG %
7% J B B I G %
8% J BBBB I G GG %
9% J J B B I G G %
10% JJJ BBBB IIIII GGG %
11% %
12% %
13% Read/Write JBIG Image Format %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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/*
40 Include declarations.
41*/
cristy4c08aed2011-07-01 19:47:50 +000042#include "MagickCore/studio.h"
cristy597d3d82012-06-17 18:44:49 +000043#include "MagickCore/attribute.h"
cristy4c08aed2011-07-01 19:47:50 +000044#include "MagickCore/blob.h"
45#include "MagickCore/blob-private.h"
46#include "MagickCore/cache.h"
47#include "MagickCore/color-private.h"
48#include "MagickCore/colormap.h"
49#include "MagickCore/colorspace.h"
cristyd15d8e02011-07-07 00:17:15 +000050#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000051#include "MagickCore/constitute.h"
52#include "MagickCore/exception.h"
53#include "MagickCore/exception-private.h"
54#include "MagickCore/geometry.h"
55#include "MagickCore/image.h"
56#include "MagickCore/image-private.h"
57#include "MagickCore/list.h"
58#include "MagickCore/magick.h"
59#include "MagickCore/memory_.h"
60#include "MagickCore/monitor.h"
61#include "MagickCore/monitor-private.h"
cristy2c5fc272012-02-22 01:27:46 +000062#include "MagickCore/nt-base-private.h"
cristy4c08aed2011-07-01 19:47:50 +000063#include "MagickCore/pixel-accessor.h"
64#include "MagickCore/quantum-private.h"
65#include "MagickCore/static.h"
66#include "MagickCore/string_.h"
cristy196372d2011-11-05 00:07:32 +000067#include "MagickCore/string-private.h"
cristy4c08aed2011-07-01 19:47:50 +000068#include "MagickCore/module.h"
cristy3ed852e2009-09-05 21:47:34 +000069#if defined(MAGICKCORE_JBIG_DELEGATE)
cristy64291042015-05-31 15:25:17 +000070#if defined(__cplusplus) || defined(c_plusplus)
71extern "C" {
72#endif
cristy3ed852e2009-09-05 21:47:34 +000073#include "jbig.h"
cristy64291042015-05-31 15:25:17 +000074#if defined(__cplusplus) || defined(c_plusplus)
75}
76#endif
cristy3ed852e2009-09-05 21:47:34 +000077#endif
78
79/*
80 Forward declarations.
81*/
82#if defined(MAGICKCORE_JBIG_DELEGATE)
83static MagickBooleanType
cristy1e178e72011-08-28 19:44:34 +000084 WriteJBIGImage(const ImageInfo *,Image *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +000085#endif
86
87#if defined(MAGICKCORE_JBIG_DELEGATE)
88/*
89%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90% %
91% %
92% %
93% R e a d J B I G I m a g e %
94% %
95% %
96% %
97%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98%
99% ReadJBIGImage() reads a JBIG image file and returns it. It
100% allocates the memory necessary for the new Image structure and returns a
101% pointer to the new image.
102%
103% The format of the ReadJBIGImage method is:
104%
105% Image *ReadJBIGImage(const ImageInfo *image_info,
106% ExceptionInfo *exception)
107%
108% A description of each parameter follows:
109%
110% o image_info: the image info.
111%
112% o exception: return any errors or warnings in this structure.
113%
114*/
115static Image *ReadJBIGImage(const ImageInfo *image_info,
116 ExceptionInfo *exception)
117{
118 Image
119 *image;
120
cristy50f1ebc2011-06-05 01:35:34 +0000121 MagickStatusType
cristy3ed852e2009-09-05 21:47:34 +0000122 status;
123
cristy4c08aed2011-07-01 19:47:50 +0000124 Quantum
125 index;
cristy3ed852e2009-09-05 21:47:34 +0000126
cristybb503372010-05-27 20:51:26 +0000127 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000128 x;
129
cristy4c08aed2011-07-01 19:47:50 +0000130 register Quantum
cristy3ed852e2009-09-05 21:47:34 +0000131 *q;
132
133 register unsigned char
134 *p;
135
136 ssize_t
cristy524222d2011-04-25 00:37:06 +0000137 length,
138 y;
cristy3ed852e2009-09-05 21:47:34 +0000139
140 struct jbg_dec_state
141 jbig_info;
142
143 unsigned char
144 bit,
145 *buffer,
146 byte;
147
148 /*
149 Open image file.
150 */
151 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000152 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000153 if (image_info->debug != MagickFalse)
154 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
155 image_info->filename);
156 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000157 assert(exception->signature == MagickCoreSignature);
cristy9950d572011-10-01 18:22:35 +0000158 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000159 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
160 if (status == MagickFalse)
161 {
162 image=DestroyImageList(image);
163 return((Image *) NULL);
164 }
165 /*
166 Initialize JBIG toolkit.
167 */
168 jbg_dec_init(&jbig_info);
cristyf6fe0a12010-05-30 00:44:47 +0000169 jbg_dec_maxsize(&jbig_info,(unsigned long) image->columns,(unsigned long)
cristy3ed852e2009-09-05 21:47:34 +0000170 image->rows);
171 image->columns=jbg_dec_getwidth(&jbig_info);
172 image->rows=jbg_dec_getheight(&jbig_info);
173 image->depth=8;
174 image->storage_class=PseudoClass;
175 image->colors=2;
176 /*
177 Read JBIG file.
178 */
179 buffer=(unsigned char *) AcquireQuantumMemory(MagickMaxBufferExtent,
180 sizeof(*buffer));
181 if (buffer == (unsigned char *) NULL)
cristy7ed14052015-01-13 15:26:30 +0000182 {
183 jbg_dec_free(&jbig_info);
184 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
185 }
cristy3ed852e2009-09-05 21:47:34 +0000186 status=JBG_EAGAIN;
187 do
188 {
cristybb503372010-05-27 20:51:26 +0000189 length=(ssize_t) ReadBlob(image,MagickMaxBufferExtent,buffer);
cristy3ed852e2009-09-05 21:47:34 +0000190 if (length == 0)
191 break;
192 p=buffer;
cristy3ed852e2009-09-05 21:47:34 +0000193 while ((length > 0) && ((status == JBG_EAGAIN) || (status == JBG_EOK)))
194 {
195 size_t
196 count;
197
198 status=jbg_dec_in(&jbig_info,p,length,&count);
199 p+=count;
cristybb503372010-05-27 20:51:26 +0000200 length-=(ssize_t) count;
cristy3ed852e2009-09-05 21:47:34 +0000201 }
202 } while ((status == JBG_EAGAIN) || (status == JBG_EOK));
203 /*
204 Create colormap.
205 */
206 image->columns=jbg_dec_getwidth(&jbig_info);
207 image->rows=jbg_dec_getheight(&jbig_info);
cristy6d5e20f2011-04-25 13:48:54 +0000208 image->compression=JBIG2Compression;
cristy018f07f2011-09-04 21:15:19 +0000209 if (AcquireImageColormap(image,2,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000210 {
cristy7ed14052015-01-13 15:26:30 +0000211 jbg_dec_free(&jbig_info);
cristy3ed852e2009-09-05 21:47:34 +0000212 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
213 ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
214 }
215 image->colormap[0].red=0;
216 image->colormap[0].green=0;
217 image->colormap[0].blue=0;
218 image->colormap[1].red=QuantumRange;
219 image->colormap[1].green=QuantumRange;
220 image->colormap[1].blue=QuantumRange;
cristy2a11bef2011-10-28 18:33:11 +0000221 image->resolution.x=300;
222 image->resolution.y=300;
cristy3ed852e2009-09-05 21:47:34 +0000223 if (image_info->ping != MagickFalse)
224 {
cristy7ed14052015-01-13 15:26:30 +0000225 jbg_dec_free(&jbig_info);
226 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
cristy3ed852e2009-09-05 21:47:34 +0000227 (void) CloseBlob(image);
228 return(GetFirstImageInList(image));
229 }
cristyacabb842014-12-14 23:36:33 +0000230 status=SetImageExtent(image,image->columns,image->rows,exception);
231 if (status == MagickFalse)
cristy7ed14052015-01-13 15:26:30 +0000232 {
233 jbg_dec_free(&jbig_info);
234 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
235 return(DestroyImageList(image));
236 }
cristy3ed852e2009-09-05 21:47:34 +0000237 /*
238 Convert X bitmap image to pixel packets.
239 */
240 p=jbg_dec_getimage(&jbig_info,0);
cristybb503372010-05-27 20:51:26 +0000241 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000242 {
243 q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +0000244 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000245 break;
cristy3ed852e2009-09-05 21:47:34 +0000246 bit=0;
247 byte=0;
cristybb503372010-05-27 20:51:26 +0000248 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000249 {
250 if (bit == 0)
251 byte=(*p++);
252 index=(byte & 0x80) ? 0 : 1;
253 bit++;
254 byte<<=1;
255 if (bit == 8)
256 bit=0;
cristy4c08aed2011-07-01 19:47:50 +0000257 SetPixelIndex(image,index,q);
cristy11a06d32015-01-04 12:03:27 +0000258 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
cristyed231572011-07-14 02:18:59 +0000259 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000260 }
261 if (SyncAuthenticPixels(image,exception) == MagickFalse)
262 break;
cristycee97112010-05-28 00:44:52 +0000263 status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
cristy524222d2011-04-25 00:37:06 +0000264 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000265 if (status == MagickFalse)
266 break;
267 }
268 /*
269 Free scale resource.
270 */
271 jbg_dec_free(&jbig_info);
272 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
273 (void) CloseBlob(image);
274 return(GetFirstImageInList(image));
275}
276#endif
277
278/*
279%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
280% %
281% %
282% %
283% R e g i s t e r J B I G I m a g e %
284% %
285% %
286% %
287%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
288%
289% RegisterJBIGImage() adds attributes for the JBIG image format to
290% the list of supported formats. The attributes include the image format
291% tag, a method to read and/or write the format, whether the format
292% supports the saving of more than one frame to the same file or blob,
293% whether the format supports native in-memory I/O, and a brief
294% description of the format.
295%
296% The format of the RegisterJBIGImage method is:
297%
cristybb503372010-05-27 20:51:26 +0000298% size_t RegisterJBIGImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000299%
300*/
cristybb503372010-05-27 20:51:26 +0000301ModuleExport size_t RegisterJBIGImage(void)
cristy3ed852e2009-09-05 21:47:34 +0000302{
303#define JBIGDescription "Joint Bi-level Image experts Group interchange format"
304
305 char
cristy151b66d2015-04-15 10:50:31 +0000306 version[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +0000307
308 MagickInfo
309 *entry;
310
311 *version='\0';
312#if defined(JBG_VERSION)
cristy151b66d2015-04-15 10:50:31 +0000313 (void) CopyMagickString(version,JBG_VERSION,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000314#endif
dirk06b627a2015-04-06 18:59:17 +0000315 entry=AcquireMagickInfo("JBIG","BIE",JBIGDescription);
cristy3ed852e2009-09-05 21:47:34 +0000316#if defined(MAGICKCORE_JBIG_DELEGATE)
317 entry->decoder=(DecodeImageHandler *) ReadJBIGImage;
318 entry->encoder=(EncodeImageHandler *) WriteJBIGImage;
319#endif
dirk08e9a112015-02-22 01:51:41 +0000320 entry->flags^=CoderAdjoinFlag;
cristy3ed852e2009-09-05 21:47:34 +0000321 if (*version != '\0')
322 entry->version=ConstantString(version);
cristy3ed852e2009-09-05 21:47:34 +0000323 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +0000324 entry=AcquireMagickInfo("JBIG","JBG",JBIGDescription);
cristy3ed852e2009-09-05 21:47:34 +0000325#if defined(MAGICKCORE_JBIG_DELEGATE)
326 entry->decoder=(DecodeImageHandler *) ReadJBIGImage;
327 entry->encoder=(EncodeImageHandler *) WriteJBIGImage;
328#endif
cristy3ed852e2009-09-05 21:47:34 +0000329 if (*version != '\0')
330 entry->version=ConstantString(version);
cristy3ed852e2009-09-05 21:47:34 +0000331 (void) RegisterMagickInfo(entry);
dirk06b627a2015-04-06 18:59:17 +0000332 entry=AcquireMagickInfo("JBIG","JBIG",JBIGDescription);
cristy3ed852e2009-09-05 21:47:34 +0000333#if defined(MAGICKCORE_JBIG_DELEGATE)
334 entry->decoder=(DecodeImageHandler *) ReadJBIGImage;
335 entry->encoder=(EncodeImageHandler *) WriteJBIGImage;
336#endif
cristy3ed852e2009-09-05 21:47:34 +0000337 if (*version != '\0')
338 entry->version=ConstantString(version);
cristy3ed852e2009-09-05 21:47:34 +0000339 (void) RegisterMagickInfo(entry);
340 return(MagickImageCoderSignature);
341}
342
343/*
344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345% %
346% %
347% %
348% U n r e g i s t e r J B I G I m a g e %
349% %
350% %
351% %
352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353%
354% UnregisterJBIGImage() removes format registrations made by the
355% JBIG module from the list of supported formats.
356%
357% The format of the UnregisterJBIGImage method is:
358%
359% UnregisterJBIGImage(void)
360%
361*/
362ModuleExport void UnregisterJBIGImage(void)
363{
364 (void) UnregisterMagickInfo("BIE");
365 (void) UnregisterMagickInfo("JBG");
366 (void) UnregisterMagickInfo("JBIG");
367}
368
369#if defined(MAGICKCORE_JBIG_DELEGATE)
370/*
371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
372% %
373% %
374% %
375% W r i t e J B I G I m a g e %
376% %
377% %
378% %
379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380%
381% WriteJBIGImage() writes an image in the JBIG encoded image format.
382%
383% The format of the WriteJBIGImage method is:
384%
cristy1e178e72011-08-28 19:44:34 +0000385% MagickBooleanType WriteJBIGImage(const ImageInfo *image_info,
386% Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000387%
388% A description of each parameter follows.
389%
390% o image_info: the image info.
391%
392% o image: The image.
393%
cristy1e178e72011-08-28 19:44:34 +0000394% o exception: return any errors or warnings in this structure.
cristy3ed852e2009-09-05 21:47:34 +0000395%
396*/
397
398static void JBIGEncode(unsigned char *pixels,size_t length,void *data)
399{
400 Image
401 *image;
402
403 image=(Image *) data;
404 (void) WriteBlob(image,length,pixels);
405}
406
407static MagickBooleanType WriteJBIGImage(const ImageInfo *image_info,
cristy1e178e72011-08-28 19:44:34 +0000408 Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000409{
410 double
411 version;
412
cristy3ed852e2009-09-05 21:47:34 +0000413 MagickBooleanType
414 status;
415
416 MagickOffsetType
417 scene;
418
cristy0553bd52013-06-30 15:53:50 +0000419 MemoryInfo
420 *pixel_info;
421
cristy4c08aed2011-07-01 19:47:50 +0000422 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +0000423 *p;
424
cristybb503372010-05-27 20:51:26 +0000425 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000426 x;
427
428 register unsigned char
429 *q;
430
cristy524222d2011-04-25 00:37:06 +0000431 size_t
432 number_packets;
433
434 ssize_t
435 y;
436
cristy3ed852e2009-09-05 21:47:34 +0000437 struct jbg_enc_state
438 jbig_info;
439
440 unsigned char
441 bit,
442 byte,
443 *pixels;
444
cristy3ed852e2009-09-05 21:47:34 +0000445 /*
446 Open image file.
447 */
448 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000449 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000450 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000451 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000452 if (image->debug != MagickFalse)
453 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3a37efd2011-08-28 20:31:03 +0000454 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000455 assert(exception->signature == MagickCoreSignature);
cristy1e178e72011-08-28 19:44:34 +0000456 status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
cristy3ed852e2009-09-05 21:47:34 +0000457 if (status == MagickFalse)
458 return(status);
cristydbdd0e32011-11-04 23:29:40 +0000459 version=StringToDouble(JBG_VERSION,(char **) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000460 scene=0;
461 do
462 {
463 /*
464 Allocate pixel data.
465 */
cristyaf8d3912014-02-21 14:50:33 +0000466 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000467 number_packets=(image->columns+7)/8;
cristy0553bd52013-06-30 15:53:50 +0000468 pixel_info=AcquireVirtualMemory(number_packets,image->rows*sizeof(*pixels));
469 if (pixel_info == (MemoryInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000470 ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
cristy0553bd52013-06-30 15:53:50 +0000471 pixels=(unsigned char *) GetVirtualMemoryBlob(pixel_info);
cristy3ed852e2009-09-05 21:47:34 +0000472 /*
473 Convert pixels to a bitmap.
474 */
cristy018f07f2011-09-04 21:15:19 +0000475 (void) SetImageType(image,BilevelType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000476 q=pixels;
cristybb503372010-05-27 20:51:26 +0000477 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000478 {
cristy1e178e72011-08-28 19:44:34 +0000479 p=GetVirtualPixels(image,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000480 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000481 break;
cristy3ed852e2009-09-05 21:47:34 +0000482 bit=0;
483 byte=0;
cristybb503372010-05-27 20:51:26 +0000484 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000485 {
486 byte<<=1;
cristyd0323222013-04-07 16:13:21 +0000487 if (GetPixelLuma(image,p) < (QuantumRange/2.0))
cristy3ed852e2009-09-05 21:47:34 +0000488 byte|=0x01;
489 bit++;
490 if (bit == 8)
491 {
492 *q++=byte;
493 bit=0;
494 byte=0;
495 }
cristyed231572011-07-14 02:18:59 +0000496 p+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +0000497 }
498 if (bit != 0)
499 *q++=byte << (8-bit);
500 if (image->previous == (Image *) NULL)
501 {
cristycee97112010-05-28 00:44:52 +0000502 status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
cristy524222d2011-04-25 00:37:06 +0000503 image->rows);
cristy3ed852e2009-09-05 21:47:34 +0000504 if (status == MagickFalse)
505 break;
506 }
507 }
508 /*
509 Initialize JBIG info structure.
510 */
cristyf6fe0a12010-05-30 00:44:47 +0000511 jbg_enc_init(&jbig_info,(unsigned long) image->columns,(unsigned long)
512 image->rows,1,&pixels,(void (*)(unsigned char *,size_t,void *))
513 JBIGEncode,image);
cristy3ed852e2009-09-05 21:47:34 +0000514 if (image_info->scene != 0)
515 jbg_enc_layers(&jbig_info,(int) image_info->scene);
516 else
517 {
cristybb503372010-05-27 20:51:26 +0000518 size_t
cristy3ed852e2009-09-05 21:47:34 +0000519 x_resolution,
520 y_resolution;
521
522 x_resolution=640;
523 y_resolution=480;
cristy3ed852e2009-09-05 21:47:34 +0000524 if (image_info->density != (char *) NULL)
525 {
526 GeometryInfo
527 geometry_info;
528
529 MagickStatusType
530 flags;
531
532 flags=ParseGeometry(image_info->density,&geometry_info);
533 x_resolution=geometry_info.rho;
534 y_resolution=geometry_info.sigma;
535 if ((flags & SigmaValue) == 0)
536 y_resolution=x_resolution;
537 }
538 if (image->units == PixelsPerCentimeterResolution)
539 {
cristybb503372010-05-27 20:51:26 +0000540 x_resolution=(size_t) (100.0*2.54*x_resolution+0.5)/100.0;
541 y_resolution=(size_t) (100.0*2.54*y_resolution+0.5)/100.0;
cristy3ed852e2009-09-05 21:47:34 +0000542 }
cristyf6fe0a12010-05-30 00:44:47 +0000543 (void) jbg_enc_lrlmax(&jbig_info,(unsigned long) x_resolution,
544 (unsigned long) y_resolution);
cristy3ed852e2009-09-05 21:47:34 +0000545 }
546 (void) jbg_enc_lrange(&jbig_info,-1,-1);
547 jbg_enc_options(&jbig_info,JBG_ILEAVE | JBG_SMID,JBG_TPDON | JBG_TPBON |
548 JBG_DPON,version < 1.6 ? -1 : 0,-1,-1);
549 /*
550 Write JBIG image.
551 */
552 jbg_enc_out(&jbig_info);
553 jbg_enc_free(&jbig_info);
cristy0553bd52013-06-30 15:53:50 +0000554 pixel_info=RelinquishVirtualMemory(pixel_info);
cristy3ed852e2009-09-05 21:47:34 +0000555 if (GetNextImageInList(image) == (Image *) NULL)
556 break;
557 image=SyncNextImageInList(image);
558 status=SetImageProgress(image,SaveImagesTag,scene++,
559 GetImageListLength(image));
560 if (status == MagickFalse)
561 break;
562 } while (image_info->adjoin != MagickFalse);
563 (void) CloseBlob(image);
564 return(MagickTrue);
565}
566#endif