Added IdentifyImageType that returns the potential type of the image, GetImageType will no longer do this.
Added IdentifyPaletteImage that checks if the image has 256 unique colors or less, IsPaletteImage will no longer do this.
Moved SetImageGray and SetImageMonochrome to colorspace.c
Renamed determineType to identifyType in Magick++
diff --git a/coders/ept.c b/coders/ept.c
index 0fae7ea..f87f7a7 100644
--- a/coders/ept.c
+++ b/coders/ept.c
@@ -429,8 +429,8 @@
EPT preview requires that the image is colormapped.
*/
GetQuantizeInfo(&quantize_info);
- quantize_info.dither_method=IsPaletteImage(write_image,exception) ==
- MagickFalse ? RiemersmaDitherMethod : NoDitherMethod;
+ quantize_info.dither_method=IdentifyPaletteImage(write_image,
+ exception) == MagickFalse ? RiemersmaDitherMethod : NoDitherMethod;
(void) QuantizeImage(&quantize_info,write_image,exception);
}
write_info->compression=NoCompression;
diff --git a/coders/json.c b/coders/json.c
index bd335e0..404e68c 100644
--- a/coders/json.c
+++ b/coders/json.c
@@ -697,6 +697,7 @@
user_time;
ImageType
+ base_type,
type;
MagickBooleanType
@@ -728,7 +729,6 @@
p=GetVirtualPixels(image,0,0,1,1,exception);
ping=p == (const Quantum *) NULL ? MagickTrue : MagickFalse;
(void) ping;
- type=GetImageType(image,exception);
(void) SignatureImage(image,exception);
JsonFormatLocaleFile(file,"{\n \"image\": {\n \"name\": %s,\n",
image->filename);
@@ -776,11 +776,17 @@
}
JsonFormatLocaleFile(file," \"units\": %s,\n",CommandOptionToMnemonic(
MagickResolutionOptions,(ssize_t) image->units));
+ colorspace=image->colorspace;
+ type=IdentifyImageType(image,exception);
+ if ((type == BilevelType) || (type == GrayscaleType) ||
+ (type == GrayscaleAlphaType))
+ colorspace=GRAYColorspace;
JsonFormatLocaleFile(file," \"type\": %s,\n",CommandOptionToMnemonic(
MagickTypeOptions,(ssize_t) type));
- if (image->type != UndefinedType)
+ base_type=GetImageType(image);
+ if (type != base_type)
JsonFormatLocaleFile(file," \"baseType\": %s,\n",
- CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) image->type));
+ CommandOptionToMnemonic(MagickTypeOptions,(ssize_t) base_type));
JsonFormatLocaleFile(file," \"endianess\": %s,\n",
CommandOptionToMnemonic(MagickEndianOptions,(ssize_t) image->endian));
locate=GetImageArtifact(image,"identify:locate");
@@ -811,9 +817,6 @@
channel_statistics=GetLocationStatistics(image,type,exception);
if (channel_statistics == (ChannelStatistics *) NULL)
return(MagickFalse);
- colorspace=image->colorspace;
- if (SetImageGray(image,exception) != MagickFalse)
- colorspace=GRAYColorspace;
(void) FormatLocaleFile(file," \"channel%s\": {\n",locate);
if (image->alpha_trait != UndefinedPixelTrait)
(void) PrintChannelLocations(file,image,AlphaPixelChannel,"Alpha",
@@ -864,7 +867,6 @@
channel_moments=(ChannelMoments *) NULL;
channel_phash=(ChannelPerceptualHash *) NULL;
channel_features=(ChannelFeatures *) NULL;
- colorspace=image->colorspace;
scale=1;
channel_statistics=GetImageStatistics(image,exception);
if (channel_statistics == (ChannelStatistics *) NULL)
@@ -890,8 +892,6 @@
(void) FormatLocaleFile(file," \"baseDepth\": %.20g,\n",(double)
image->depth);
(void) FormatLocaleFile(file," \"channelDepth\": {\n");
- if (SetImageGray(image,exception) != MagickFalse)
- colorspace=GRAYColorspace;
if (image->alpha_trait != UndefinedPixelTrait)
(void) FormatLocaleFile(file," \"alpha\": %.20g,\n",(double)
channel_statistics[AlphaPixelChannel].depth);
diff --git a/coders/map.c b/coders/map.c
index 15c1cdc..3b2bd1d 100644
--- a/coders/map.c
+++ b/coders/map.c
@@ -380,7 +380,7 @@
/*
Allocate colormap.
*/
- if (IsPaletteImage(image,exception) == MagickFalse)
+ if (IsPaletteImage(image) == MagickFalse)
(void) SetImageType(image,PaletteType,exception);
depth=GetImageQuantumDepth(image,MagickTrue);
packet_size=(size_t) (depth/8);
diff --git a/coders/palm.c b/coders/palm.c
index a245f9a..f616771 100644
--- a/coders/palm.c
+++ b/coders/palm.c
@@ -804,7 +804,7 @@
{
if (flags & PALM_HAS_COLORMAP_FLAG) /* Write out colormap */
{
- quantize_info->dither_method=IsPaletteImage(image,exception)
+ quantize_info->dither_method=IdentifyPaletteImage(image,exception)
== MagickFalse ? RiemersmaDitherMethod : NoDitherMethod;
quantize_info->number_colors=image->colors;
(void) QuantizeImage(quantize_info,image,exception);
diff --git a/coders/pdb.c b/coders/pdb.c
index 0e4d1ef..1104be5 100644
--- a/coders/pdb.c
+++ b/coders/pdb.c
@@ -759,8 +759,7 @@
if (status == MagickFalse)
return(status);
(void) TransformImageColorspace(image,sRGBColorspace,exception);
- if ((image->colors <= 2) ||
- (GetImageType(image,exception ) == BilevelType)) {
+ if (SetImageMonochrome(image,exception) != MagickFalse) {
bits_per_pixel=1;
} else if (image->colors <= 4) {
bits_per_pixel=2;
diff --git a/coders/svg.c b/coders/svg.c
index e8717ca..9cd1d6c 100644
--- a/coders/svg.c
+++ b/coders/svg.c
@@ -3444,7 +3444,8 @@
*/
fitting_options=at_fitting_opts_new();
output_options=at_output_opts_new();
- type=GetImageType(image,exception);
+ (void) SetImageGray(image,exception);
+ type=GetImageType(image);
number_planes=3;
if ((type == BilevelType) || (type == GrayscaleType))
number_planes=1;