% Read DjVu Images. %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
-% http://www.imagemagick.org/script/license.php %
+% https://imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
/*
Include declarations.
*/
-#include "magick/studio.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/cache.h"
-#include "magick/colormap.h"
-#include "magick/constitute.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/list.h"
-#include "magick/magick.h"
-#include "magick/memory_.h"
-#include "magick/monitor.h"
-#include "magick/monitor-private.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/module.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/colormap.h"
+#include "MagickCore/constitute.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image-private.h"
+#include "MagickCore/list.h"
+#include "MagickCore/magick.h"
+#include "MagickCore/memory_.h"
+#include "MagickCore/monitor.h"
+#include "MagickCore/monitor-private.h"
+#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/module.h"
#if defined(MAGICKCORE_DJVU_DELEGATE)
#include <libdjvu/ddjvuapi.h>
#endif
ddjvu_message_t *message;
/* i might check for a condition! */
+ size=0;
while (!(message = ddjvu_message_peek(lc->context))
&& (size = (size_t) ReadBlob(image,(size_t) blocksize,data)) == blocksize) {
ddjvu_stream_write(lc->document, lc->streamid, (char *) data, size);
* we use the RGB format!
*/
static void
-get_page_image(LoadContext *lc, ddjvu_page_t *page, int x, int y, int w, int h, QuantumInfo* quantum_info)
-{
+get_page_image(LoadContext *lc, ddjvu_page_t *page, int x, int y, int w, int h, ExceptionInfo *exception ) {
ddjvu_format_t
*format;
/* stride of this temporary buffer: */
stride = (type == DDJVU_PAGETYPE_BITONAL)?
- (lc->image->columns + 7)/8:
- lc->image->columns *3;
-
- q = (unsigned char *) AcquireQuantumMemory(lc->image->rows,stride);
+ (image->columns + 7)/8 : image->columns *3;
+ q = (unsigned char *) AcquireQuantumMemory(image->rows,stride);
+ if (q == (unsigned char *) NULL)
+ return;
format = ddjvu_format_create(
(type == DDJVU_PAGETYPE_BITONAL)?DDJVU_FORMAT_LSBTOMSB : DDJVU_FORMAT_RGB24,
format,
stride, /* ?? */
(char*)q);
+ (void) ret;
ddjvu_format_release(format);
#if DEBUG
printf("%s: expanding BITONAL page/image\n", __FUNCTION__);
#endif
- register IndexPacket *indexes;
size_t bit, byte;
for (y=0; y < (ssize_t) image->rows; y++)
{
- PixelPacket * o = QueueAuthenticPixels(image,0,y,image->columns,1,&image->exception);
- if (o == (PixelPacket *) NULL)
+ Quantum * o = QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+ if (o == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
bit=0;
byte=0;
{
if (bit == 0) byte= (size_t) q[(y * stride) + (x / 8)];
- indexes[x]=(IndexPacket) (((byte & 0x01) != 0) ? 0x00 : 0x01);
+ SetPixelIndex(image,(Quantum) (((byte & 0x01) != 0) ? 0x00 : 0x01),o);
bit++;
if (bit == 8)
bit=0;
byte>>=1;
+ o+=GetPixelChannels(image);
}
- if (SyncAuthenticPixels(image,&image->exception) == MagickFalse)
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
}
if (!image->ping)
- SyncImage(image);
+ SyncImage(image,exception);
} else {
#if DEBUG
printf("%s: expanding PHOTO page/image\n", __FUNCTION__);
/* old: */
char* r;
#else
- register PixelPacket *r;
+ register Quantum *r;
+ unsigned char *s;
#endif
-
- for (i = 0;i< (ssize_t) lc->image->rows; i++)
+ s=q;
+ for (i = 0;i< (ssize_t) image->rows; i++)
{
#if DEBUG
if (i % 1000 == 0) printf("%d\n",i);
#endif
- r = QueueAuthenticPixels(lc->image,0,i,lc->image->columns,1,&image->exception);
-
- ImportQuantumPixels(lc->image,
- (CacheView *) NULL,
- quantum_info,
- RGBQuantum, /*GrayQuantum*/
- q+i*stride,&image->exception);
- SyncAuthenticPixels(lc->image,&image->exception);
+ r = QueueAuthenticPixels(image,0,i,image->columns,1,exception);
+ if (r == (Quantum *) NULL)
+ break;
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ SetPixelRed(image,ScaleCharToQuantum(*s++),r);
+ SetPixelGreen(image,ScaleCharToQuantum(*s++),r);
+ SetPixelBlue(image,ScaleCharToQuantum(*s++),r);
+ r+=GetPixelChannels(image);
+ }
+
+ (void) SyncAuthenticPixels(image,exception);
}
}
q=(unsigned char *) RelinquishMagickMemory(q);
%
*/
-static inline double MagickMax(const double x,const double y)
-{
- if (x > y)
- return(x);
- return(y);
-}
-
static Image *ReadOneDJVUImage(LoadContext* lc,const int pagenum,
const ImageInfo *image_info,ExceptionInfo *exception)
{
type;
ddjvu_pageinfo_t info;
- QuantumInfo *quantum_info;
ddjvu_message_t *message;
Image *image;
int logging;
int tag;
+ MagickBooleanType status;
/* so, we know that the page is there! Get its dimension, and */
/* Read one DJVU image */
image = lc->image;
- /* register PixelPacket *q; */
+ /* register Quantum *q; */
logging=LogMagickEvent(CoderEvent,GetMagickModule(), " enter ReadOneDJVUImage()");
+ (void) logging;
#if DEBUG
printf("==== Loading the page %d\n", pagenum);
if (tag == 0) break;
ddjvu_message_pop(lc->context);
} while ((message = ddjvu_message_peek(lc->context)));
+ if (tag == 0) break;
} while (!ddjvu_page_decoding_done(lc->page));
ddjvu_document_get_pageinfo(lc->document, pagenum, &info);
- image->x_resolution = (float) info.dpi;
- image->y_resolution =(float) info.dpi;
+ image->resolution.x = (float) info.dpi;
+ image->resolution.y =(float) info.dpi;
if (image_info->density != (char *) NULL)
{
int
Set rendering resolution.
*/
flags=ParseGeometry(image_info->density,&geometry_info);
- image->x_resolution=geometry_info.rho;
- image->y_resolution=geometry_info.sigma;
+ image->resolution.x=geometry_info.rho;
+ image->resolution.y=geometry_info.sigma;
if ((flags & SigmaValue) == 0)
- image->y_resolution=image->x_resolution;
- info.width*=image->x_resolution/info.dpi;
- info.height*=image->y_resolution/info.dpi;
- info.dpi=(ssize_t) MagickMax(image->x_resolution,image->y_resolution);
+ image->resolution.y=image->resolution.x;
+ info.width*=image->resolution.x/info.dpi;
+ info.height*=image->resolution.y/info.dpi;
+ info.dpi=(ssize_t) MagickMax(image->resolution.x,image->resolution.y);
}
type = ddjvu_page_get_type(lc->page);
image->storage_class = PseudoClass;
image->depth = 8UL; /* i only support that? */
image->colors= 2;
- if (AcquireImageColormap(image,image->colors) == MagickFalse)
+ if (AcquireImageColormap(image,image->colors,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,
"MemoryAllocationFailed");
} else {
/* fixme: MAGICKCORE_QUANTUM_DEPTH ?*/
image->depth = 8UL; /* i only support that? */
- image->matte = MagickTrue;
+ image->alpha_trait = BlendPixelTrait;
/* is this useful? */
}
+ status=SetImageExtent(image,image->columns,image->rows,exception);
+ if (status == MagickFalse)
+ return(DestroyImageList(image));
#if DEBUG
printf("now filling %.20g x %.20g\n",(double) image->columns,(double)
image->rows);
#if 1 /* per_line */
- quantum_info=AcquireQuantumInfo(image_info,image);
- if (quantum_info == (QuantumInfo *) NULL)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
/* q = QueueAuthenticPixels(image,0,0,image->columns,image->rows); */
- get_page_image(lc, lc->page, 0, 0, info.width, info.height, quantum_info);
+ get_page_image(lc, lc->page, 0, 0, info.width, info.height, exception);
#else
int i;
for (i = 0;i< image->rows; i++)
#endif
if (!image->ping)
- SyncImage(image);
- quantum_info=DestroyQuantumInfo(quantum_info);
- /* indexes=GetAuthenticIndexQueue(image); */
+ SyncImage(image,exception);
/* mmc: ??? Convert PNM pixels to runlength-encoded MIFF packets. */
/* image->colors = */
#if 0
/* palette */
- if (AcquireImageColormap(image,2) == MagickFalse)
+ if (AcquireImageColormap(image,2,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
/*
Monochrome colormap. mmc: this the default!
* Open image file.
*/
assert(image_info != (const ImageInfo *) NULL);
- assert(image_info->signature == MagickSignature);
+ assert(image_info->signature == MagickCoreSignature);
if (image_info->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
- assert(exception->signature == MagickSignature);
+ assert(exception->signature == MagickCoreSignature);
logging = LogMagickEvent(CoderEvent,GetMagickModule(),"enter ReadDJVUImage()");
+ (void) logging;
- image = AcquireImage(image_info); /* mmc: ?? */
+ image = AcquireImage(image_info,exception); /* mmc: ?? */
lc = (LoadContext *) NULL;
/*
* Initialize members of the MngInfo structure.
*/
- (void) ResetMagickMemory(lc,0,sizeof(LoadContext));
+ (void) memset(lc,0,sizeof(LoadContext));
lc->image = image;
lc->pages = 0;
break;
image->scene=i;
AppendImageToList(&images,CloneImageList(image,exception));
+ images->extent=GetBlobSize(image);
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
}
djvu_close_lc(lc);
- (void) CloseBlob(images);
+ if (images != (Image *) NULL)
+ (void) CloseBlob(images);
if (image != (Image *) NULL)
image=DestroyImageList(image);
ModuleExport size_t RegisterDJVUImage(void)
{
char
- version[MaxTextExtent];
+ version[MagickPathExtent];
MagickInfo
*entry;
*version='\0';
#if defined(DJVU_LIBDJVU_VER_STRING)
- (void) ConcatenateMagickString(version,"libdjvu ",MaxTextExtent);
- (void) ConcatenateMagickString(version,DJVU_LIBDJVU_VER_STRING,MaxTextExtent);
+ (void) ConcatenateMagickString(version,"libdjvu ",MagickPathExtent);
+ (void) ConcatenateMagickString(version,DJVU_LIBDJVU_VER_STRING,MagickPathExtent);
#endif
- entry=SetMagickInfo("DJVU");
+ entry=AcquireMagickInfo("DJVU","DJVU","Deja vu");
#if defined(MAGICKCORE_DJVU_DELEGATE)
entry->decoder=(DecodeImageHandler *) ReadDJVUImage;
#endif
- entry->raw=MagickTrue;
entry->magick=(IsImageFormatHandler *) IsDJVU;
- entry->adjoin=MagickFalse;
- entry->thread_support=MagickTrue;
- entry->description=AcquireString("Déjà vu");
- entry->module=AcquireString("DJVU");
+ entry->flags|=CoderRawSupportFlag;
+ entry->flags^=CoderAdjoinFlag;
if (*version != '\0')
entry->version=AcquireString(version);
entry->note=AcquireString(DJVUNote);