% Read DICOM Image Format %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
-% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 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 "MagickCore/studio.h"
-#include "MagickCore/property.h"
+#include "MagickCore/artifact.h"
+#include "MagickCore/attribute.h"
#include "MagickCore/blob.h"
#include "MagickCore/blob-private.h"
#include "MagickCore/cache.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/option.h"
#include "MagickCore/pixel-accessor.h"
+#include "MagickCore/property.h"
#include "MagickCore/resource_.h"
#include "MagickCore/quantum-private.h"
#include "MagickCore/static.h"
MagickBooleanType
explicit_file,
- use_explicit,
explicit_retry,
- polarity;
+ polarity,
+ sequence,
+ use_explicit;
MagickOffsetType
offset;
window_center,
y;
-
unsigned char
*data;
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)
{
number_scenes=1;
samples_per_pixel=1;
scale=(Quantum *) NULL;
+ sequence=MagickFalse;
signed_data=(~0UL);
significant_bits=0;
use_explicit=MagickFalse;
width=0;
window_center=0;
window_width=0;
- for (group=0; (group != 0x7FE0) || (element != 0x0010); )
+ for (group=0; (group != 0x7FE0) || (element != 0x0010) ||
+ (sequence != MagickFalse); )
{
/*
Read a group.
Check for "explicitness", but meta-file headers always explicit.
*/
if ((explicit_file == MagickFalse) && (group != 0x0002))
- explicit_file=(isupper((int) *explicit_vr) != MagickFalse) &&
- (isupper((int) *(explicit_vr+1)) != MagickFalse) ? MagickTrue :
- MagickFalse;
+ explicit_file=(isupper((unsigned char) *explicit_vr) != MagickFalse) &&
+ (isupper((unsigned char) *(explicit_vr+1)) != MagickFalse) ?
+ MagickTrue : MagickFalse;
use_explicit=((group == 0x0002) && (explicit_retry == MagickFalse)) ||
(explicit_file != MagickFalse) ? MagickTrue : MagickFalse;
if ((use_explicit != MagickFalse) && (strcmp(implicit_vr,"xs") == 0))
(void) FormatLocaleFile(stdout," %s",dicom_info[i].description);
(void) FormatLocaleFile(stdout,": ");
}
- if ((group == 0x7FE0) && (element == 0x0010))
+ if ((sequence == MagickFalse) && (group == 0x7FE0) && (element == 0x0010))
{
if (image_info->verbose != MagickFalse)
(void) FormatLocaleFile(stdout,"\n");
count=ReadBlob(image,(size_t) quantum*length,data);
if (count != (ssize_t) (quantum*length))
{
- (void) FormatLocaleFile(stdout,"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");
}
data[length*quantum]='\0';
}
+ else
+ if ((unsigned int) datum == 0xFFFFFFFFU)
+ {
+ sequence=MagickTrue;
+ continue;
+ }
+
+ if (((group << 16) | element) == 0xFFFEE0DD)
+ {
+ sequence=MagickFalse;
+ continue;
+ }
+
+ if (sequence != MagickFalse)
+ continue;
+
switch (group)
{
case 0x0002:
p=data;
for (i=0; i < (ssize_t) colors; i++)
{
- if (image->endian != LSBEndian)
+ if (image->endian == MSBEndian)
index=(unsigned short) ((*p << 8) | *(p+1));
else
index=(unsigned short) (*p | (*(p+1) << 8));
p=data;
for (i=0; i < (ssize_t) colors; i++)
{
- if (image->endian != LSBEndian)
+ if (image->endian == MSBEndian)
index=(unsigned short) ((*p << 8) | *(p+1));
else
index=(unsigned short) (*p | (*(p+1) << 8));
p=data;
for (i=0; i < (ssize_t) colors; i++)
{
- if (image->endian != LSBEndian)
- index=(unsigned short) ((*p << 8) | *(p+1));
- else
+ if (image->endian == MSBEndian)
+ index=(unsigned short) ((*p << 8) | *(p+1)); else
index=(unsigned short) (*p | (*(p+1) << 8));
bluemap[i]=(int) index;
p+=2;
}
break;
}
+ default:
+ break;
}
break;
}
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);
}
"jpeg:%s",filename);
if (image->compression == JPEG2000Compression)
(void) FormatLocaleString(read_info->filename,MaxTextExtent,
- "jp2:%s",filename);
+ "j2k:%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->columns=(size_t) width;
image->rows=(size_t) height;
image->depth=depth;
- if ((image->colormap == (PixelPacket *) NULL) && (samples_per_pixel == 1))
+ image->colorspace=RGBColorspace;
+ if ((image->colormap == (PixelInfo *) NULL) && (samples_per_pixel == 1))
{
size_t
one;
one=1;
if (colors == 0)
colors=one << depth;
- if (AcquireImageColormap(image,colors,exception) == MagickFalse)
+ if (AcquireImageColormap(image,one << depth,exception) == MagickFalse)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
if (redmap != (int *) NULL)
for (i=0; i < (ssize_t) colors; i++)
tag=(ReadBlobLSBShort(image) << 16) | ReadBlobLSBShort(image);
stream_info->remaining=(size_t) ReadBlobLSBLong(image);
if ((tag != 0xFFFEE000) || (stream_info->remaining <= 64) ||
- (EOFBlob(image) == MagickTrue))
+ (EOFBlob(image) != MagickFalse))
ThrowReaderException(CorruptImageError,"ImproperImageHeader");
stream_info->count=0;
stream_info->segment_count=ReadBlobLSBLong(image);
int
byte;
- LongPixelPacket
+ PixelPacket
pixel;
/*
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);
- if (significant_bits == 12)
- pixel_value>>=4;
}
else
{
0.5)/(window_width-1))+0.5));
}
index&=mask;
- index=(int) ConstrainColormapIndex(image,(size_t) 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;
0.5)/(window_width-1))+0.5));
}
index&=mask;
- index=(int) ConstrainColormapIndex(image,(size_t) index);
+ 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;
}
}
}
+ if (IsImageGray(image,exception) != MagickFalse)
+ (void) SetImageColorspace(image,GRAYColorspace,exception);
if (EOFBlob(image) != MagickFalse)
{
ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
/*
Allocate next image structure.
*/
- AcquireNextImage(image_info,image);
+ AcquireNextImage(image_info,image,exception);
if (GetNextImageInList(image) == (Image *) NULL)
{
image=DestroyImageList(image);