diff --git a/MagickCore/quantize.c b/MagickCore/quantize.c index 90d5f35e59..327147d0fc 100644 --- a/MagickCore/quantize.c +++ b/MagickCore/quantize.c @@ -2382,6 +2382,8 @@ MagickExport MagickBooleanType KmeansImage(Image *image, const double max_distortion,ExceptionInfo *exception) { #define KmeansImageTag "Kmeans/Image" +#define RandomPixel(random_info) \ + (QuantumRange*GetPseudoRandomValue(random_info)) CacheView *image_view; @@ -2482,15 +2484,16 @@ MagickExport MagickBooleanType KmeansImage(Image *image, /* Seed with random pixels in image. */ - image_view=AcquireAuthenticCacheView(image,exception); random_info=AcquireRandomInfo(); for ( ; n < (ssize_t) image->colors; n++) - (void) GetOneCacheViewVirtualPixelInfo(image_view, - (ssize_t) (GetPseudoRandomValue(random_info)*image->columns), - (ssize_t) (GetPseudoRandomValue(random_info)*image->rows), - kmeans_colormap+n,exception); + { + kmeans_colormap[n].red=RandomPixel(random_info); + kmeans_colormap[n].green=RandomPixel(random_info); + kmeans_colormap[n].blue=RandomPixel(random_info); + kmeans_colormap[n].alpha=RandomPixel(random_info); + kmeans_colormap[n].black=RandomPixel(random_info); + } random_info=DestroyRandomInfo(random_info); - image_view=DestroyCacheView(image_view); } } (void) memcpy(image->colormap,kmeans_colormap,image->colors* diff --git a/MagickCore/random.c b/MagickCore/random.c index 7ca7fffbaa..b99dd63a7f 100644 --- a/MagickCore/random.c +++ b/MagickCore/random.c @@ -182,7 +182,7 @@ MagickExport RandomInfo *AcquireRandomInfo(void) random_info->reservoir=AcquireStringInfo(GetSignatureDigestsize( random_info->signature_info)); ResetStringInfo(random_info->reservoir); - random_info->normalize=1.0/MagickULLConstant(~0); + random_info->normalize=1.0/(double) MagickULLConstant(~0); random_info->seed[0]=MagickULLConstant(0xd2a98b26625eee7b); random_info->seed[1]=MagickULLConstant(0xdddf9b1090aa7ac1); random_info->secret_key=secret_key; @@ -239,7 +239,7 @@ MagickExport RandomInfo *AcquireRandomInfo(void) FinalizeSignature(signature_info); digest=GetSignatureDigest(signature_info); (void) memcpy(random_info->seed,GetStringInfoDatum(digest), - MagickMin(GetSignatureDigestsize(signature_info), + MagickMin((size_t) GetSignatureDigestsize(signature_info), sizeof(*random_info->seed))); signature_info=DestroySignatureInfo(signature_info); } @@ -410,8 +410,8 @@ static StringInfo *GenerateEntropicChaos(RandomInfo *random_info) if (gettimeofday(&timer,(struct timezone *) NULL) == 0) { - seconds=timer.tv_sec; - nanoseconds=1000UL*timer.tv_usec; + seconds=(size_t) timer.tv_sec; + nanoseconds=(size_t) (1000UL*timer.tv_usec); } } #endif @@ -621,7 +621,7 @@ MagickExport double GetPseudoRandomValue(RandomInfo *random_info) seed1^=seed0; random_info->seed[0]=RandomROTL(seed0,24) ^ seed1 ^ (seed1 << 16); random_info->seed[1]=RandomROTL(seed1,37); - return(random_info->normalize*value); + return(random_info->normalize*(double) value); } /*