% July 1992 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2012 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 %
/*
Include declarations.
*/
-#include "magick/studio.h"
-#include "magick/property.h"
-#include "magick/blob.h"
-#include "magick/blob-private.h"
-#include "magick/cache.h"
-#include "magick/color.h"
-#include "magick/colormap-private.h"
-#include "magick/color-private.h"
-#include "magick/constitute.h"
-#include "magick/enhance.h"
-#include "magick/exception.h"
-#include "magick/exception-private.h"
-#include "magick/image.h"
-#include "magick/image-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/option.h"
-#include "magick/resource_.h"
-#include "magick/quantum-private.h"
-#include "magick/static.h"
-#include "magick/string_.h"
-#include "magick/string-private.h"
-#include "magick/module.h"
+#include "MagickCore/studio.h"
+#include "MagickCore/property.h"
+#include "MagickCore/blob.h"
+#include "MagickCore/blob-private.h"
+#include "MagickCore/cache.h"
+#include "MagickCore/color.h"
+#include "MagickCore/color-private.h"
+#include "MagickCore/colormap.h"
+#include "MagickCore/colormap-private.h"
+#include "MagickCore/constitute.h"
+#include "MagickCore/enhance.h"
+#include "MagickCore/exception.h"
+#include "MagickCore/exception-private.h"
+#include "MagickCore/image.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/option.h"
+#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/resource_.h"
+#include "MagickCore/quantum-private.h"
+#include "MagickCore/static.h"
+#include "MagickCore/string_.h"
+#include "MagickCore/string-private.h"
+#include "MagickCore/module.h"
\f
/*
Dicom medical image declarations.
static unsigned short ReadDCMLSBShort(DCMStreamInfo *stream_info,Image *image)
{
+ int
+ shift;
+
unsigned short
value;
if (image->compression != RLECompression)
return(ReadBlobLSBShort(image));
+ shift=image->depth < 16 ? 4 : 8;
value=ReadDCMByte(stream_info,image) | (unsigned short)
- (ReadDCMByte(stream_info,image) << 4);
+ (ReadDCMByte(stream_info,image) << shift);
return(value);
}
static unsigned short ReadDCMMSBShort(DCMStreamInfo *stream_info,Image *image)
{
+ int
+ shift;
unsigned short
value;
if (image->compression != RLECompression)
return(ReadBlobMSBShort(image));
- value=(ReadDCMByte(stream_info,image) << 4) | (unsigned short)
+ shift=image->depth < 16 ? 4 : 8;
+ value=(ReadDCMByte(stream_info,image) << shift) | (unsigned short)
ReadDCMByte(stream_info,image);
return(value);
}
*image;
int
+ *bluemap,
+ datum,
+ *greenmap,
*graymap,
- index;
-
- long
- element,
- group,
- scene,
- window_center,
- y;
+ index,
+ *redmap;
MagickBooleanType
explicit_file,
Quantum
*scale;
- register IndexPacket
- *indexes;
-
- register long
+ register ssize_t
i,
x;
- register PixelPacket
+ register Quantum
*q;
register unsigned char
*p;
- ssize_t
- count;
-
size_t
- length;
-
- unsigned char
- *data;
-
- unsigned long
bits_allocated,
bytes_per_pixel,
- datum,
+ colors,
+ depth,
height,
- high_bit,
+ length,
mask,
max_value,
number_scenes,
width,
window_width;
+ ssize_t
+ count,
+ element,
+ group,
+ scene,
+ window_center,
+ y;
+
+
+ unsigned char
+ *data;
+
/*
Open image file.
*/
image_info->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
- image=AcquireImage(image_info);
+ image=AcquireImage(image_info,exception);
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
{
/*
Read DCM preamble.
*/
- stream_info=(DCMStreamInfo *) AcquireAlignedMemory(1,sizeof(*stream_info));
+ stream_info=(DCMStreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
if (stream_info == (DCMStreamInfo *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) ResetMagickMemory(stream_info,0,sizeof(*stream_info));
(void) CopyMagickString(photometric,"MONOCHROME1 ",MaxTextExtent);
bits_allocated=8;
bytes_per_pixel=1;
- high_bit=0;
polarity=MagickFalse;
data=(unsigned char *) NULL;
+ depth=8;
element=0;
explicit_vr[2]='\0';
explicit_file=MagickFalse;
+ colors=0;
+ redmap=(int *) NULL;
+ greenmap=(int *) NULL;
+ bluemap=(int *) NULL;
graymap=(int *) NULL;
height=0;
max_value=255UL;
/*
Read a group.
*/
- image->offset=(long) TellBlob(image);
- group=(long) ReadBlobLSBShort(image);
- element=(long) ReadBlobLSBShort(image);
+ image->offset=(ssize_t) TellBlob(image);
+ group=(ssize_t) ReadBlobLSBShort(image);
+ element=(ssize_t) ReadBlobLSBShort(image);
quantum=0;
/*
Find corresponding VR for this group and element.
*/
for (i=0; dicom_info[i].group < 0xffff; i++)
- if ((group == (long) dicom_info[i].group) &&
- (element == (long) dicom_info[i].element))
+ if ((group == (ssize_t) dicom_info[i].group) &&
+ (element == (ssize_t) dicom_info[i].element))
break;
(void) CopyMagickString(implicit_vr,dicom_info[i].vr,MaxTextExtent);
count=ReadBlob(image,2,(unsigned char *) explicit_vr);
}
datum=0;
if (quantum == 4)
- datum=(unsigned long) ReadBlobLSBLong(image);
+ datum=(int) ReadBlobLSBLong(image);
else
if (quantum == 2)
- datum=(unsigned long) ReadBlobLSBShort(image);
+ datum=(int) ReadBlobLSBShort(image);
quantum=0;
length=1;
if (datum != 0)
quantum=1;
else
quantum=8;
- if (datum != ~0U)
+ if (datum != ~0)
length=(size_t) datum/quantum;
else
{
if (use_explicit == MagickFalse)
explicit_vr[0]='\0';
for (i=0; dicom_info[i].description != (char *) NULL; i++)
- if ((group == (long) dicom_info[i].group) &&
- (element == (long) dicom_info[i].element))
+ if ((group == (ssize_t) dicom_info[i].group) &&
+ (element == (ssize_t) dicom_info[i].element))
break;
- (void) fprintf(stdout,"0x%04lX %4ld %s-%s (0x%04lx,0x%04lx)",
+ (void) FormatLocaleFile(stdout,"0x%04lX %4ld %s-%s (0x%04lx,0x%04lx)",
(unsigned long) image->offset,(long) length,implicit_vr,
explicit_vr,(unsigned long) group,(unsigned long) element);
if (dicom_info[i].description != (char *) NULL)
- (void) fprintf(stdout," %s",dicom_info[i].description);
- (void) fprintf(stdout,": ");
+ (void) FormatLocaleFile(stdout," %s",dicom_info[i].description);
+ (void) FormatLocaleFile(stdout,": ");
}
if ((group == 0x7FE0) && (element == 0x0010))
{
if (image_info->verbose != MagickFalse)
- (void) fprintf(stdout,"\n");
+ (void) FormatLocaleFile(stdout,"\n");
break;
}
/*
*/
data=(unsigned char *) NULL;
if ((length == 1) && (quantum == 1))
- datum=(unsigned long) ReadBlobByte(image);
+ datum=(int) ReadBlobByte(image);
else
if ((length == 1) && (quantum == 2))
- datum=(unsigned long) ReadBlobLSBShort(image);
+ datum=(int) ReadBlobLSBShort(image);
else
if ((length == 1) && (quantum == 4))
- datum=(unsigned long) ReadBlobLSBLong(image);
+ datum=(int) ReadBlobLSBLong(image);
else
if ((quantum != 0) && (length != 0))
{
count=ReadBlob(image,(size_t) quantum*length,data);
if (count != (ssize_t) (quantum*length))
{
- (void) fprintf(stderr,"count=%d quantum=%d length=%d "
- "group=%d\n",(int) count,(int) quantum,(int) length,(int)
- group);
+ (void) FormatLocaleFile(stdout,"count=%d quantum=%d "
+ "length=%d group=%d\n",(int) count,(int) quantum,(int)
+ length,(int) group);
ThrowReaderException(CorruptImageError,
"InsufficientImageDataInFile");
}
group=0;
element=0;
if (image_info->verbose != MagickFalse)
- (void) fprintf(stderr,
+ (void) FormatLocaleFile(stdout,
"Corrupted image - trying explicit format\n");
break;
}
(void) CopyMagickString(transfer_syntax,(char *) data,
MaxTextExtent);
if (image_info->verbose != MagickFalse)
- (void) fprintf(stderr,"transfer_syntax=%s\n",(const char*)
- transfer_syntax);
+ (void) FormatLocaleFile(stdout,"transfer_syntax=%s\n",
+ (const char*) transfer_syntax);
if (strncmp(transfer_syntax,"1.2.840.10008.1.2",17) == 0)
{
int
/*
Photometric interpretation.
*/
- for (i=0; i < (long) MagickMin(length,MaxTextExtent-1); i++)
+ for (i=0; i < (ssize_t) MagickMin(length,MaxTextExtent-1); i++)
photometric[i]=(char) data[i];
photometric[i]='\0';
polarity=LocaleCompare(photometric,"MONOCHROME1 ") == 0 ?
bytes_per_pixel=1;
if (datum > 8)
bytes_per_pixel=2;
- image->depth=bits_allocated;
- if (image->depth > 32)
+ depth=bits_allocated;
+ if (depth > 32)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
max_value=(1UL << bits_allocated)-1;
break;
bytes_per_pixel=1;
if (significant_bits > 8)
bytes_per_pixel=2;
- image->depth=significant_bits;
- if (image->depth > 32)
+ depth=significant_bits;
+ if (depth > 32)
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
max_value=(1UL << significant_bits)-1;
- mask=(unsigned long) GetQuantumRange(significant_bits);
+ mask=(size_t) GetQuantumRange(significant_bits);
break;
}
case 0x0102:
/*
Visible pixel range: center.
*/
- window_center=StringToLong((char *) data);
+ if (data != (unsigned char *) NULL)
+ window_center=StringToLong((char *) data);
break;
}
case 0x1051:
/*
Visible pixel range: width.
*/
- window_width=StringToUnsignedLong((char *) data);
+ if (data != (unsigned char *) NULL)
+ window_width=StringToUnsignedLong((char *) data);
break;
}
case 0x1200:
case 0x3006:
{
- unsigned long
- colors;
-
/*
- Populate image colormap.
+ Populate graymap.
*/
if (data == (unsigned char *) NULL)
break;
- colors=(unsigned long) (length/bytes_per_pixel);
- datum=colors;
+ colors=(size_t) (length/bytes_per_pixel);
+ datum=(int) colors;
graymap=(int *) AcquireQuantumMemory((size_t) colors,
sizeof(*graymap));
if (graymap == (int *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- for (i=0; i < (long) colors; i++)
+ for (i=0; i < (ssize_t) colors; i++)
if (bytes_per_pixel == 1)
graymap[i]=(int) data[i];
else
break;
}
case 0x1201:
+ {
+ unsigned short
+ index;
+
+ /*
+ Populate redmap.
+ */
+ if (data == (unsigned char *) NULL)
+ break;
+ colors=(size_t) (length/2);
+ datum=(int) colors;
+ redmap=(int *) AcquireQuantumMemory((size_t) colors,
+ sizeof(*redmap));
+ if (redmap == (int *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ p=data;
+ for (i=0; i < (ssize_t) colors; i++)
+ {
+ if (image->endian != LSBEndian)
+ index=(unsigned short) ((*p << 8) | *(p+1));
+ else
+ index=(unsigned short) (*p | (*(p+1) << 8));
+ redmap[i]=(int) index;
+ p+=2;
+ }
+ break;
+ }
case 0x1202:
- case 0x1203:
{
- MagickBooleanType
- status;
+ unsigned short
+ index;
+ /*
+ Populate greenmap.
+ */
+ if (data == (unsigned char *) NULL)
+ break;
+ colors=(size_t) (length/2);
+ datum=(int) colors;
+ greenmap=(int *) AcquireQuantumMemory((size_t) colors,
+ sizeof(*greenmap));
+ if (greenmap == (int *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ p=data;
+ for (i=0; i < (ssize_t) colors; i++)
+ {
+ if (image->endian != LSBEndian)
+ index=(unsigned short) ((*p << 8) | *(p+1));
+ else
+ index=(unsigned short) (*p | (*(p+1) << 8));
+ greenmap[i]=(int) index;
+ p+=2;
+ }
+ break;
+ }
+ case 0x1203:
+ {
unsigned short
index;
/*
- Initialize colormap.
+ Populate bluemap.
*/
- if (image->columns == 0)
+ if (data == (unsigned char *) NULL)
break;
- status=AcquireImageColormap(image,(unsigned long) (length+1)/2);
- if (status == MagickFalse)
- ThrowReaderException(ResourceLimitError,"UnableToCreateColormap");
+ colors=(size_t) (length/2);
+ datum=(int) colors;
+ bluemap=(int *) AcquireQuantumMemory((size_t) colors,
+ sizeof(*bluemap));
+ if (bluemap == (int *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
p=data;
- for (i=0; i < (long) image->colors; i++)
+ for (i=0; i < (ssize_t) colors; i++)
{
- index=(unsigned short) ((*p) | (*(p+1)) << 8);
- if (element == 0x1201)
- image->colormap[i].red=ScaleShortToQuantum(index);
- if (element == 0x1202)
- image->colormap[i].green=ScaleShortToQuantum(index);
- if (element == 0x1203)
- image->colormap[i].blue=ScaleShortToQuantum(index);
+ if (image->endian != LSBEndian)
+ index=(unsigned short) ((*p << 8) | *(p+1));
+ else
+ index=(unsigned short) (*p | (*(p+1) << 8));
+ bluemap[i]=(int) index;
p+=2;
}
break;
*attribute;
for (i=0; dicom_info[i].description != (char *) NULL; i++)
- if ((group == (long) dicom_info[i].group) &&
- (element == (long) dicom_info[i].element))
+ if ((group == (ssize_t) dicom_info[i].group) &&
+ (element == (ssize_t) dicom_info[i].element))
break;
attribute=AcquireString("dcm:");
(void) ConcatenateString(&attribute,dicom_info[i].description);
- for (i=0; i < (long) MagickMax(length,4); i++)
+ for (i=0; i < (ssize_t) MagickMax(length,4); i++)
if (isprint((int) data[i]) == MagickFalse)
break;
- if ((i == (long) length) || (length > 4))
+ if ((i == (ssize_t) length) || (length > 4))
{
(void) SubstituteString(&attribute," ","");
- (void) SetImageProperty(image,attribute,(char *) data);
+ (void) SetImageProperty(image,attribute,(char *) data,exception);
}
attribute=DestroyString(attribute);
- data=(unsigned char *) RelinquishMagickMemory(data);
}
if (image_info->verbose != MagickFalse)
{
if (data == (unsigned char *) NULL)
- (void) fprintf(stdout,"%lu\n",datum);
+ (void) FormatLocaleFile(stdout,"%d\n",datum);
else
{
/*
Display group data.
*/
- for (i=0; i < (long) MagickMax(length,4); i++)
+ for (i=0; i < (ssize_t) MagickMax(length,4); i++)
if (isprint((int) data[i]) == MagickFalse)
break;
- if ((i != (long) length) && (length <= 4))
+ if ((i != (ssize_t) length) && (length <= 4))
{
- long
+ ssize_t
j;
datum=0;
- for (j=(long) length-1; j >= 0; j--)
+ for (j=(ssize_t) length-1; j >= 0; j--)
datum=(256*datum+data[j]);
- (void) fprintf(stdout,"%lu",datum);
+ (void) FormatLocaleFile(stdout,"%d",datum);
}
else
- for (i=0; i < (long) length; i++)
+ for (i=0; i < (ssize_t) length; i++)
if (isprint((int) data[i]) != MagickFalse)
- (void) fprintf(stdout,"%c",data[i]);
+ (void) FormatLocaleFile(stdout,"%c",data[i]);
else
- (void) fprintf(stdout,"%c",'.');
- (void) fprintf(stdout,"\n");
+ (void) FormatLocaleFile(stdout,"%c",'.');
+ (void) FormatLocaleFile(stdout,"\n");
}
}
+ if (data != (unsigned char *) NULL)
+ data=(unsigned char *) RelinquishMagickMemory(data);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
}
if ((width == 0) || (height == 0))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
- image->columns=(unsigned long) width;
- image->rows=(unsigned long) height;
+ image->columns=(size_t) width;
+ image->rows=(size_t) height;
if (signed_data == 0xffff)
- signed_data=(unsigned long) (significant_bits == 16 ? 1 : 0);
+ signed_data=(size_t) (significant_bits == 16 ? 1 : 0);
if ((image->compression == JPEGCompression) ||
(image->compression == JPEG2000Compression))
{
/*
Read offset table.
*/
- for (i=0; i < (long) stream_info->remaining; i++)
+ for (i=0; i < (ssize_t) stream_info->remaining; i++)
(void) ReadBlobByte(image);
tag=(ReadBlobLSBShort(image) << 16) | ReadBlobLSBShort(image);
+ (void) tag;
length=(size_t) ReadBlobLSBLong(image);
stream_info->offset_count=length >> 2;
if (stream_info->offset_count != 0)
stream_info->offset_count,sizeof(*stream_info->offsets));
if (stream_info->offsets == (ssize_t *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- for (i=0; i < (long) stream_info->offset_count; i++)
- stream_info->offsets[i]=(ssize_t) ReadBlobLSBLong(image);
+ for (i=0; i < (ssize_t) stream_info->offset_count; i++)
+ stream_info->offsets[i]=(int) ReadBlobLSBLong(image);
offset=TellBlob(image);
- for (i=0; i < (long) stream_info->offset_count; i++)
+ for (i=0; i < (ssize_t) stream_info->offset_count; i++)
stream_info->offsets[i]+=offset;
}
/*
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
images=NewImageList();
- for (scene=0; scene < (long) number_scenes; scene++)
+ for (scene=0; scene < (ssize_t) number_scenes; scene++)
{
char
filename[MaxTextExtent];
(void) fputc(c,file);
}
(void) fclose(file);
- (void) FormatMagickString(read_info->filename,MaxTextExtent,
+ (void) FormatLocaleString(read_info->filename,MaxTextExtent,
"jpeg:%s",filename);
if (image->compression == JPEG2000Compression)
- (void) FormatMagickString(read_info->filename,MaxTextExtent,
+ (void) FormatLocaleString(read_info->filename,MaxTextExtent,
"jp2:%s",filename);
jpeg_image=ReadImage(read_info,exception);
if (jpeg_image != (Image *) NULL)
while (property != (const char *) NULL)
{
(void) SetImageProperty(jpeg_image,property,
- GetImageProperty(image,property));
+ GetImageProperty(image,property,exception),exception);
property=GetNextImageProperty(image);
}
AppendImageToList(&images,jpeg_image);
image=DestroyImage(image);
return(GetFirstImageInList(images));
}
- if (image->depth != (1UL*MAGICKCORE_QUANTUM_DEPTH))
+ if (depth != (1UL*MAGICKCORE_QUANTUM_DEPTH))
{
QuantumAny
range;
/*
Compute pixel scaling table.
*/
- length=(size_t) (GetQuantumRange(image->depth)+1);
+ length=(size_t) (GetQuantumRange(depth)+1);
scale=(Quantum *) AcquireQuantumMemory(length,sizeof(*scale));
if (scale == (Quantum *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- range=GetQuantumRange(image->depth);
- for (i=0; i < (long) (GetQuantumRange(image->depth)+1); i++)
- scale[i]=ScaleAnyToQuantum((unsigned long) i,range);
+ range=GetQuantumRange(depth);
+ for (i=0; i < (ssize_t) (GetQuantumRange(depth)+1); i++)
+ scale[i]=ScaleAnyToQuantum((size_t) i,range);
}
if (image->compression == RLECompression)
{
- unsigned int
- tag;
-
size_t
length;
+ unsigned int
+ tag;
+
/*
Read RLE offset table.
*/
- for (i=0; i < (long) stream_info->remaining; i++)
+ for (i=0; i < (ssize_t) stream_info->remaining; i++)
(void) ReadBlobByte(image);
tag=(ReadBlobLSBShort(image) << 16) | ReadBlobLSBShort(image);
+ (void) tag;
length=(size_t) ReadBlobLSBLong(image);
stream_info->offset_count=length >> 2;
if (stream_info->offset_count != 0)
stream_info->offset_count,sizeof(*stream_info->offsets));
if (stream_info->offsets == (ssize_t *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
- for (i=0; i < (long) stream_info->offset_count; i++)
- stream_info->offsets[i]=(ssize_t) ReadBlobLSBLong(image);
+ for (i=0; i < (ssize_t) stream_info->offset_count; i++)
+ stream_info->offsets[i]=(int) ReadBlobLSBLong(image);
offset=TellBlob(image);
- for (i=0; i < (long) stream_info->offset_count; i++)
+ for (i=0; i < (ssize_t) stream_info->offset_count; i++)
stream_info->offsets[i]+=offset;
}
}
- for (scene=0; scene < (long) number_scenes; scene++)
+ for (scene=0; scene < (ssize_t) number_scenes; scene++)
{
if (image_info->ping != MagickFalse)
break;
+ image->columns=(size_t) width;
+ image->rows=(size_t) height;
+ image->depth=depth;
+ if ((image->colormap == (PixelInfo *) NULL) && (samples_per_pixel == 1))
+ {
+ size_t
+ one;
+
+ one=1;
+ if (colors == 0)
+ colors=one << depth;
+ if (AcquireImageColormap(image,one << depth,exception) == MagickFalse)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ if (redmap != (int *) NULL)
+ for (i=0; i < (ssize_t) colors; i++)
+ {
+ index=redmap[i];
+ if ((scale != (Quantum *) NULL) && (index <= (int) max_value))
+ index=(int) scale[index];
+ image->colormap[i].red=index;
+ }
+ if (greenmap != (int *) NULL)
+ for (i=0; i < (ssize_t) colors; i++)
+ {
+ index=greenmap[i];
+ if ((scale != (Quantum *) NULL) && (index <= (int) max_value))
+ index=(int) scale[index];
+ image->colormap[i].green=index;
+ }
+ if (bluemap != (int *) NULL)
+ for (i=0; i < (ssize_t) colors; i++)
+ {
+ index=bluemap[i];
+ if ((scale != (Quantum *) NULL) && (index <= (int) max_value))
+ index=(int) scale[index];
+ image->colormap[i].blue=index;
+ }
+ if (graymap != (int *) NULL)
+ for (i=0; i < (ssize_t) colors; i++)
+ {
+ index=graymap[i];
+ if ((scale != (Quantum *) NULL) && (index <= (int) max_value))
+ index=(int) scale[index];
+ image->colormap[i].red=index;
+ image->colormap[i].green=index;
+ image->colormap[i].blue=index;
+ }
+ }
if (image->compression == RLECompression)
{
unsigned int
/*
Read RLE segment table.
*/
- for (i=0; i < (long) stream_info->remaining; i++)
+ for (i=0; i < (ssize_t) stream_info->remaining; i++)
(void) ReadBlobByte(image);
tag=(ReadBlobLSBShort(image) << 16) | ReadBlobLSBShort(image);
stream_info->remaining=(size_t) ReadBlobLSBLong(image);
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
stream_info->count=0;
stream_info->segment_count=ReadBlobLSBLong(image);
+ if (stream_info->segment_count > 1)
+ {
+ bytes_per_pixel=1;
+ depth=8;
+ }
for (i=0; i < 15; i++)
- stream_info->segments[i]=(ssize_t) ReadBlobLSBLong(image);
+ stream_info->segments[i]=(int) ReadBlobLSBLong(image);
stream_info->remaining-=64;
}
- image->columns=(unsigned long) width;
- image->rows=(unsigned long) height;
- if ((image->colormap == (PixelPacket *) NULL) && (samples_per_pixel == 1))
- if (AcquireImageColormap(image,MaxColormapSize) == MagickFalse)
- ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if ((samples_per_pixel > 1) && (image->interlace == PlaneInterlace))
{
/*
Convert Planar RGB DCM Medical image to pixel packets.
*/
- for (i=0; i < (long) samples_per_pixel; i++)
+ for (i=0; i < (ssize_t) samples_per_pixel; i++)
{
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
switch ((int) i)
{
case 0:
{
- q->red=ScaleCharToQuantum((unsigned char)
- ReadDCMByte(stream_info,image));
+ SetPixelRed(image,ScaleCharToQuantum((unsigned char)
+ ReadDCMByte(stream_info,image)),q);
break;
}
case 1:
{
- q->green=ScaleCharToQuantum((unsigned char)
- ReadDCMByte(stream_info,image));
+ SetPixelGreen(image,ScaleCharToQuantum((unsigned char)
+ ReadDCMByte(stream_info,image)),q);
break;
}
case 2:
{
- q->blue=ScaleCharToQuantum((unsigned char)
- ReadDCMByte(stream_info,image));
+ SetPixelBlue(image,ScaleCharToQuantum((unsigned char)
+ ReadDCMByte(stream_info,image)),q);
break;
}
case 3:
{
- q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(
- (unsigned char) ReadDCMByte(stream_info,image)));
+ SetPixelAlpha(image,ScaleCharToQuantum((unsigned char)
+ ReadDCMByte(stream_info,image)),q);
break;
}
default:
break;
}
- q++;
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
int
byte;
- LongPixelPacket
+ PixelPacket
pixel;
/*
byte=0;
i=0;
if ((window_center != 0) && (window_width == 0))
- window_width=(unsigned long) window_center;
+ window_width=(size_t) window_center;
option=GetImageOption(image_info,"dcm:display-range");
if (option != (const char *) NULL)
{
window_width=0;
}
(void) ResetMagickMemory(&pixel,0,sizeof(pixel));
- for (y=0; y < (long) image->rows; y++)
+ for (y=0; y < (ssize_t) image->rows; y++)
{
q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
- if (q == (PixelPacket *) NULL)
+ if (q == (Quantum *) NULL)
break;
- indexes=GetAuthenticIndexQueue(image);
- for (x=0; x < (long) image->columns; x++)
+ for (x=0; x < (ssize_t) image->columns; x++)
{
if (samples_per_pixel == 1)
{
pixel_value=(int) (polarity != MagickFalse ? (max_value-
ReadDCMLSBShort(stream_info,image)) :
ReadDCMLSBShort(stream_info,image));
- if (signed_data == 1)
- pixel_value=((signed short) pixel_value);
}
else
{
}
else
{
- long
+ ssize_t
window_max,
window_min;
- window_min=(long) (window_center-(window_width-1)/2.0-0.5);
- window_max=(long) (window_center+(window_width-1)/2.0-0.5);
- if ((long) pixel_value <= window_min)
+ window_min=(ssize_t) ceil(window_center-(window_width-1)/
+ 2.0-0.5);
+ window_max=(ssize_t) floor(window_center+(window_width-1)/
+ 2.0+0.5);
+ if ((ssize_t) pixel_value <= window_min)
index=0;
else
- if ((long) pixel_value > window_max)
+ if ((ssize_t) pixel_value > window_max)
index=(int) max_value;
else
index=(int) (max_value*(((pixel_value-window_center-
0.5)/(window_width-1))+0.5));
}
index&=mask;
- if (graymap != (int *) NULL)
- index=graymap[index];
- if ((scale != (Quantum *) NULL) && (index <= (int) max_value))
- index=(int) scale[index];
- index=(int) ConstrainColormapIndex(image,(unsigned long) index);
- indexes[x]=(IndexPacket) index;
+ index=(int) ConstrainColormapIndex(image,(size_t) index,
+ exception);
+ SetPixelIndex(image,index,q);
pixel.red=1UL*image->colormap[index].red;
pixel.green=1UL*image->colormap[index].green;
pixel.blue=1UL*image->colormap[index].blue;
{
if (bytes_per_pixel == 1)
{
- pixel.red=(unsigned long) ReadDCMByte(stream_info,image);
- pixel.green=(unsigned long) ReadDCMByte(stream_info,image);
- pixel.blue=(unsigned long) ReadDCMByte(stream_info,image);
+ pixel.red=(size_t) ReadDCMByte(stream_info,image);
+ pixel.green=(size_t) ReadDCMByte(stream_info,image);
+ pixel.blue=(size_t) ReadDCMByte(stream_info,image);
}
else
{
pixel.blue=scale[pixel.blue];
}
}
- q->red=(Quantum) pixel.red;
- q->green=(Quantum) pixel.green;
- q->blue=(Quantum) pixel.blue;
- q++;
+ SetPixelRed(image,pixel.red,q);
+ SetPixelGreen(image,pixel.green,q);
+ SetPixelBlue(image,pixel.blue,q);
+ q+=GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,y,image->rows);
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
if (status == MagickFalse)
break;
}
}
+ if (stream_info->segment_count > 1)
+ for (y=0; y < (ssize_t) image->rows; y++)
+ {
+ q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
+ if (q == (Quantum *) NULL)
+ break;
+ for (x=0; x < (ssize_t) image->columns; x++)
+ {
+ if (samples_per_pixel == 1)
+ {
+ int
+ pixel_value;
+
+ if (bytes_per_pixel == 1)
+ pixel_value=polarity != MagickFalse ?
+ ((int) max_value-ReadDCMByte(stream_info,image)) :
+ ReadDCMByte(stream_info,image);
+ else
+ if ((bits_allocated != 12) || (significant_bits != 12))
+ {
+ if (image->endian == MSBEndian)
+ pixel_value=(int) (polarity != MagickFalse ?
+ (max_value-ReadDCMMSBShort(stream_info,image)) :
+ ReadDCMMSBShort(stream_info,image));
+ else
+ pixel_value=(int) (polarity != MagickFalse ?
+ (max_value-ReadDCMLSBShort(stream_info,image)) :
+ ReadDCMLSBShort(stream_info,image));
+ if (signed_data == 1)
+ pixel_value=((signed short) pixel_value);
+ }
+ else
+ {
+ if ((i & 0x01) != 0)
+ pixel_value=(ReadDCMByte(stream_info,image) << 8) |
+ byte;
+ else
+ {
+ if (image->endian == MSBEndian)
+ pixel_value=(int) ReadDCMMSBShort(stream_info,
+ image);
+ else
+ pixel_value=(int) ReadDCMLSBShort(stream_info,
+ image);
+ byte=(int) (pixel_value & 0x0f);
+ pixel_value>>=4;
+ }
+ i++;
+ }
+ index=pixel_value;
+ if (window_width == 0)
+ {
+ if (signed_data == 1)
+ index=pixel_value-32767;
+ }
+ else
+ {
+ ssize_t
+ window_max,
+ window_min;
+
+ window_min=(ssize_t) ceil(window_center-(window_width-1)/
+ 2.0-0.5);
+ window_max=(ssize_t) floor(window_center+(window_width-1)/
+ 2.0+0.5);
+ if ((ssize_t) pixel_value <= window_min)
+ index=0;
+ else
+ if ((ssize_t) pixel_value > window_max)
+ index=(int) max_value;
+ else
+ index=(int) (max_value*(((pixel_value-window_center-
+ 0.5)/(window_width-1))+0.5));
+ }
+ index&=mask;
+ index=(int) ConstrainColormapIndex(image,(size_t) index,
+ exception);
+ SetPixelIndex(image,(((size_t) GetPixelIndex(image,q)) |
+ (((size_t) index) << 8)),q);
+ pixel.red=1UL*image->colormap[index].red;
+ pixel.green=1UL*image->colormap[index].green;
+ pixel.blue=1UL*image->colormap[index].blue;
+ }
+ else
+ {
+ if (bytes_per_pixel == 1)
+ {
+ pixel.red=(size_t) ReadDCMByte(stream_info,image);
+ pixel.green=(size_t) ReadDCMByte(stream_info,image);
+ pixel.blue=(size_t) ReadDCMByte(stream_info,image);
+ }
+ else
+ {
+ if (image->endian == MSBEndian)
+ {
+ pixel.red=ReadDCMMSBShort(stream_info,image);
+ pixel.green=ReadDCMMSBShort(stream_info,image);
+ pixel.blue=ReadDCMMSBShort(stream_info,image);
+ }
+ else
+ {
+ pixel.red=ReadDCMLSBShort(stream_info,image);
+ pixel.green=ReadDCMLSBShort(stream_info,image);
+ pixel.blue=ReadDCMLSBShort(stream_info,image);
+ }
+ }
+ pixel.red&=mask;
+ pixel.green&=mask;
+ pixel.blue&=mask;
+ if (scale != (Quantum *) NULL)
+ {
+ pixel.red=scale[pixel.red];
+ pixel.green=scale[pixel.green];
+ pixel.blue=scale[pixel.blue];
+ }
+ }
+ SetPixelRed(image,(((size_t) GetPixelRed(image,q)) |
+ (((size_t) pixel.red) << 8)),q);
+ SetPixelGreen(image,(((size_t) GetPixelGreen(image,q)) |
+ (((size_t) pixel.green) << 8)),q);
+ SetPixelBlue(image,(((size_t) GetPixelBlue(image,q)) |
+ (((size_t) pixel.blue) << 8)),q);
+ q+=GetPixelChannels(image);
+ }
+ if (SyncAuthenticPixels(image,exception) == MagickFalse)
+ break;
+ if (image->previous == (Image *) NULL)
+ {
+ status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (status == MagickFalse)
+ break;
+ }
+ }
}
if (EOFBlob(image) != MagickFalse)
{
if (image_info->number_scenes != 0)
if (image->scene >= (image_info->scene+image_info->number_scenes-1))
break;
- if (scene < (long) (number_scenes-1))
+ if (scene < (ssize_t) (number_scenes-1))
{
/*
Allocate next image structure.
*/
- AcquireNextImage(image_info,image);
+ AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);
scale=(Quantum *) RelinquishMagickMemory(scale);
if (graymap != (int *) NULL)
graymap=(int *) RelinquishMagickMemory(graymap);
+ if (bluemap != (int *) NULL)
+ bluemap=(int *) RelinquishMagickMemory(bluemap);
+ if (greenmap != (int *) NULL)
+ greenmap=(int *) RelinquishMagickMemory(greenmap);
+ if (redmap != (int *) NULL)
+ redmap=(int *) RelinquishMagickMemory(redmap);
(void) CloseBlob(image);
return(GetFirstImageInList(image));
}
%
% The format of the RegisterDCMImage method is:
%
-% unsigned long RegisterDCMImage(void)
+% size_t RegisterDCMImage(void)
%
*/
-ModuleExport unsigned long RegisterDCMImage(void)
+ModuleExport size_t RegisterDCMImage(void)
{
MagickInfo
*entry;