*image;
int
+ *bluemap,
+ *greenmap,
*graymap,
- index;
+ index,
+ *redmap;
long
element,
unsigned long
bits_allocated,
bytes_per_pixel,
+ colors,
datum,
height,
high_bit,
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;
case 0x1200:
case 0x3006:
{
- unsigned long
- colors;
-
/*
- Populate image colormap.
+ Populate graymap.
*/
if (data == (unsigned char *) NULL)
break;
break;
}
case 0x1201:
+ {
+ unsigned short
+ index;
+
+ /*
+ Populate redmap.
+ */
+ if (data == (unsigned char *) NULL)
+ break;
+ colors=(unsigned long) (length/2);
+ datum=colors;
+ redmap=(int *) AcquireQuantumMemory((size_t) colors,
+ sizeof(*redmap));
+ if (redmap == (int *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ p=data;
+ for (i=0; i < (long) 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=(unsigned long) (length/2);
+ datum=colors;
+ greenmap=(int *) AcquireQuantumMemory((size_t) colors,
+ sizeof(*greenmap));
+ if (greenmap == (int *) NULL)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ p=data;
+ for (i=0; i < (long) 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->colormap == (PixelPacket *) NULL)
- {
- status=AcquireImageColormap(image,(unsigned long) length/2);
- if (status == MagickFalse)
- ThrowReaderException(ResourceLimitError,
- "UnableToCreateColormap");
- }
- else
- if ((length/2) != image->colors)
- ThrowReaderException(ResourceLimitError,
- "UnableToCreateColormap");
+ if (data == (unsigned char *) NULL)
+ break;
+ colors=(unsigned long) (length/2);
+ datum=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 < (long) colors; i++)
{
if (image->endian != LSBEndian)
index=(unsigned short) ((*p << 8) | *(p+1));
else
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);
+ bluemap[i]=(int) index;
p+=2;
}
break;
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 (colors == 0)
+ colors=MagickMin(1UL << image->depth,MaxColormapSize);
+ if (AcquireImageColormap(image,colors) == MagickFalse)
+ ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+ if (redmap != (int *) NULL)
+ for (i=0; i < (long) 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 < (long) 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 < (long) 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 < (long) 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 ((samples_per_pixel > 1) && (image->interlace == PlaneInterlace))
{
/*
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);
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));
}