]> granicus.if.org Git - imagemagick/commitdiff
Added missing checks.
authorDirk Lemstra <dirk@git.imagemagick.org>
Sat, 17 Jun 2017 21:05:40 +0000 (23:05 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sat, 17 Jun 2017 21:05:40 +0000 (23:05 +0200)
MagickCore/vision.c

index f8e1c115267def195022571b28827a91a8aec57a..c53bdd2cecc2bff102cb025a5f67e3d83b745333 100644 (file)
@@ -398,8 +398,10 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
       object[id].color.red+=QuantumScale*GetPixelRed(image,p);
       object[id].color.green+=QuantumScale*GetPixelGreen(image,p);
       object[id].color.blue+=QuantumScale*GetPixelBlue(image,p);
-      object[id].color.black+=QuantumScale*GetPixelBlack(image,p);
-      object[id].color.alpha+=QuantumScale*GetPixelAlpha(image,p);
+      if (image->alpha_trait != UndefinedPixelTrait)
+        object[id].color.alpha+=QuantumScale*GetPixelAlpha(image,p);
+      if (image->colorspace == CMYKColorspace)
+        object[id].color.black+=QuantumScale*GetPixelBlack(image,p);
       object[id].centroid.x+=x;
       object[id].centroid.y+=y;
       object[id].area++;
@@ -439,8 +441,10 @@ MagickExport Image *ConnectedComponentsImage(const Image *image,
     object[i].color.red=QuantumRange*(object[i].color.red/object[i].area);
     object[i].color.green=QuantumRange*(object[i].color.green/object[i].area);
     object[i].color.blue=QuantumRange*(object[i].color.blue/object[i].area);
-    object[i].color.alpha=QuantumRange*(object[i].color.alpha/object[i].area);
-    object[i].color.black=QuantumRange*(object[i].color.black/object[i].area);
+    if (image->alpha_trait != UndefinedPixelTrait)
+      object[i].color.alpha=QuantumRange*(object[i].color.alpha/object[i].area);
+    if (image->colorspace == CMYKColorspace)
+      object[i].color.black=QuantumRange*(object[i].color.black/object[i].area);
     object[i].centroid.x=object[i].centroid.x/object[i].area;
     object[i].centroid.y=object[i].centroid.y/object[i].area;
   }