From a83872e2b346db04e4c60a3282c302e5462c30ac Mon Sep 17 00:00:00 2001 From: dirk Date: Fri, 22 Aug 2014 18:40:58 +0000 Subject: [PATCH] Newlines. --- MagickCore/accelerate-private.h | 502 ++++++++++++++++---------------- 1 file changed, 251 insertions(+), 251 deletions(-) diff --git a/MagickCore/accelerate-private.h b/MagickCore/accelerate-private.h index d5afd755f..2b4547b9c 100644 --- a/MagickCore/accelerate-private.h +++ b/MagickCore/accelerate-private.h @@ -1325,93 +1325,93 @@ const char* accelerateKernels = ) - STRINGIFY( - __kernel void UnsharpMask(__global CLPixelType *im, __global CLPixelType *filtered_im, - __constant float *filter, - const unsigned int width, - const unsigned int imageColumns, const unsigned int imageRows, - __local float4 *pixels, - const float gain, const float threshold, const unsigned int justBlur) - { - const int x = get_global_id(0); - const int y = get_global_id(1); - - const unsigned int radius = (width - 1) / 2; - - int row = y - radius; - int baseRow = get_group_id(1) * get_local_size(1) - radius; - int endRow = (get_group_id(1) + 1) * get_local_size(1) + radius; - - while (row < endRow) { - int srcy = (row < 0) ? -row : row; // mirror pad - srcy = (srcy >= imageRows) ? (2 * imageRows - srcy - 1) : srcy; - - float4 value = 0.0f; - - int ix = x - radius; - int i = 0; - - while (i + 7 < width) { - for (int j = 0; j < 8; ++j) { // unrolled - int srcx = ix + j; - srcx = (srcx < 0) ? -srcx : srcx; - srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx; - value += filter[i + j] * convert_float4(im[srcx + srcy * imageColumns]); - } - ix += 8; - i += 8; - } - - while (i < width) { - int srcx = (ix < 0) ? -ix : ix; // mirror pad - srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx; - value += filter[i] * convert_float4(im[srcx + srcy * imageColumns]); - ++i; - ++ix; - } - pixels[(row - baseRow) * get_local_size(0) + get_local_id(0)] = value; - row += get_local_size(1); - } - - - barrier(CLK_LOCAL_MEM_FENCE); - - - const int px = get_local_id(0); - const int py = get_local_id(1); - const int prp = get_local_size(0); - float4 value = (float4)(0.0f); - - int i = 0; - while (i + 7 < width) { // unrolled - value += (float4)(filter[i]) * pixels[px + (py + i) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 1) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 2) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 3) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 4) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 5) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 6) * prp]; - value += (float4)(filter[i]) * pixels[px + (py + i + 7) * prp]; - i += 8; - } - while (i < width) { - value += (float4)(filter[i]) * pixels[px + (py + i) * prp]; - ++i; - } - - if (justBlur == 0) { // apply sharpening - float4 srcPixel = convert_float4(im[x + y * imageColumns]); - float4 diff = srcPixel - value; - - float quantumThreshold = QuantumRange*threshold; - - int4 mask = isless(fabs(2.0f * diff), (float4)quantumThreshold); - value = select(srcPixel + diff * gain, srcPixel, mask); - } - - if ((x < imageColumns) && (y < imageRows)) - filtered_im[x + y * imageColumns] = (CLPixelType)(ClampToQuantum(value.s0), ClampToQuantum(value.s1), ClampToQuantum(value.s2), ClampToQuantum(value.s3)); - } + STRINGIFY( + __kernel void UnsharpMask(__global CLPixelType *im, __global CLPixelType *filtered_im, + __constant float *filter, + const unsigned int width, + const unsigned int imageColumns, const unsigned int imageRows, + __local float4 *pixels, + const float gain, const float threshold, const unsigned int justBlur) + { + const int x = get_global_id(0); + const int y = get_global_id(1); + + const unsigned int radius = (width - 1) / 2; + + int row = y - radius; + int baseRow = get_group_id(1) * get_local_size(1) - radius; + int endRow = (get_group_id(1) + 1) * get_local_size(1) + radius; + + while (row < endRow) { + int srcy = (row < 0) ? -row : row; // mirror pad + srcy = (srcy >= imageRows) ? (2 * imageRows - srcy - 1) : srcy; + + float4 value = 0.0f; + + int ix = x - radius; + int i = 0; + + while (i + 7 < width) { + for (int j = 0; j < 8; ++j) { // unrolled + int srcx = ix + j; + srcx = (srcx < 0) ? -srcx : srcx; + srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx; + value += filter[i + j] * convert_float4(im[srcx + srcy * imageColumns]); + } + ix += 8; + i += 8; + } + + while (i < width) { + int srcx = (ix < 0) ? -ix : ix; // mirror pad + srcx = (srcx >= imageColumns) ? (2 * imageColumns - srcx - 1) : srcx; + value += filter[i] * convert_float4(im[srcx + srcy * imageColumns]); + ++i; + ++ix; + } + pixels[(row - baseRow) * get_local_size(0) + get_local_id(0)] = value; + row += get_local_size(1); + } + + + barrier(CLK_LOCAL_MEM_FENCE); + + + const int px = get_local_id(0); + const int py = get_local_id(1); + const int prp = get_local_size(0); + float4 value = (float4)(0.0f); + + int i = 0; + while (i + 7 < width) { // unrolled + value += (float4)(filter[i]) * pixels[px + (py + i) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 1) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 2) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 3) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 4) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 5) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 6) * prp]; + value += (float4)(filter[i]) * pixels[px + (py + i + 7) * prp]; + i += 8; + } + while (i < width) { + value += (float4)(filter[i]) * pixels[px + (py + i) * prp]; + ++i; + } + + if (justBlur == 0) { // apply sharpening + float4 srcPixel = convert_float4(im[x + y * imageColumns]); + float4 diff = srcPixel - value; + + float quantumThreshold = QuantumRange*threshold; + + int4 mask = isless(fabs(2.0f * diff), (float4)quantumThreshold); + value = select(srcPixel + diff * gain, srcPixel, mask); + } + + if ((x < imageColumns) && (y < imageRows)) + filtered_im[x + y * imageColumns] = (CLPixelType)(ClampToQuantum(value.s0), ClampToQuantum(value.s1), ClampToQuantum(value.s2), ClampToQuantum(value.s3)); + } ) @@ -2759,8 +2759,8 @@ STRINGIFY( Part of MWC64X by David Thomas, dt10@imperial.ac.uk This is provided under BSD, full license is with the main package. See http://www.doc.ic.ac.uk/~dt10/research -*/ - +*/ + // Pre: ax ^ s->c; MWC64X_Step(s); return res; -} - -// -// End of MWC64X excerpt -// - - - typedef enum - { - UndefinedNoise, - UniformNoise, - GaussianNoise, - MultiplicativeGaussianNoise, - ImpulseNoise, - LaplacianNoise, - PoissonNoise, - RandomNoise - } NoiseType; - - - float mwcReadPseudoRandomValue(mwc64x_state_t* rng) { - return (1.0f * MWC64X_NextUint(rng)) / (float)(0xffffffff); // normalized to 1.0 - } - - - float mwcGenerateDifferentialNoise(mwc64x_state_t* r, CLQuantum pixel, NoiseType noise_type, float attenuate) { - - float - alpha, - beta, - noise, - sigma; - - noise = 0.0f; - alpha=mwcReadPseudoRandomValue(r); - switch(noise_type) { - case UniformNoise: - default: - { - noise=(pixel+QuantumRange*SigmaUniform*(alpha-0.5f)); - break; - } - case GaussianNoise: - { - float - gamma, - tau; - - if (alpha == 0.0f) - alpha=1.0f; - beta=mwcReadPseudoRandomValue(r); - gamma=sqrt(-2.0f*log(alpha)); - sigma=gamma*cospi((2.0f*beta)); - tau=gamma*sinpi((2.0f*beta)); - noise=(float)(pixel+sqrt((float) pixel)*SigmaGaussian*sigma+ - QuantumRange*TauGaussian*tau); - break; - } - - - case ImpulseNoise: - { - if (alpha < (SigmaImpulse/2.0f)) - noise=0.0f; - else - if (alpha >= (1.0f-(SigmaImpulse/2.0f))) - noise=(float)QuantumRange; - else - noise=(float)pixel; - break; - } - case LaplacianNoise: - { - if (alpha <= 0.5f) - { - if (alpha <= MagickEpsilon) - noise=(float) (pixel-QuantumRange); - else - noise=(float) (pixel+QuantumRange*SigmaLaplacian*log(2.0f*alpha)+ - 0.5f); - break; - } - beta=1.0f-alpha; - if (beta <= (0.5f*MagickEpsilon)) - noise=(float) (pixel+QuantumRange); - else - noise=(float) (pixel-QuantumRange*SigmaLaplacian*log(2.0f*beta)+0.5f); - break; - } - case MultiplicativeGaussianNoise: - { - sigma=1.0f; - if (alpha > MagickEpsilon) - sigma=sqrt(-2.0f*log(alpha)); - beta=mwcReadPseudoRandomValue(r); - noise=(float) (pixel+pixel*SigmaMultiplicativeGaussian*sigma* - cospi((float) (2.0f*beta))/2.0f); - break; - } - case PoissonNoise: - { - float - poisson; - unsigned int i; - poisson=exp(-SigmaPoisson*QuantumScale*pixel); - for (i=0; alpha > poisson; i++) - { - beta=mwcReadPseudoRandomValue(r); - alpha*=beta; - } - noise=(float) (QuantumRange*i/SigmaPoisson); - break; - } - case RandomNoise: - { - noise=(float) (QuantumRange*SigmaRandom*alpha); - break; - } - - }; - return noise; - } - - - - - - __kernel - void GenerateNoiseImage(const __global CLPixelType* inputImage, __global CLPixelType* filteredImage - ,const unsigned int inputPixelCount, const unsigned int pixelsPerWorkItem - ,const ChannelType channel - ,const NoiseType noise_type, const float attenuate - ,const unsigned int seed0, const unsigned int seed1 - ,const unsigned int numRandomNumbersPerPixel) { - +} + +// +// End of MWC64X excerpt +// + + + typedef enum + { + UndefinedNoise, + UniformNoise, + GaussianNoise, + MultiplicativeGaussianNoise, + ImpulseNoise, + LaplacianNoise, + PoissonNoise, + RandomNoise + } NoiseType; + + + float mwcReadPseudoRandomValue(mwc64x_state_t* rng) { + return (1.0f * MWC64X_NextUint(rng)) / (float)(0xffffffff); // normalized to 1.0 + } + + + float mwcGenerateDifferentialNoise(mwc64x_state_t* r, CLQuantum pixel, NoiseType noise_type, float attenuate) { + + float + alpha, + beta, + noise, + sigma; + + noise = 0.0f; + alpha=mwcReadPseudoRandomValue(r); + switch(noise_type) { + case UniformNoise: + default: + { + noise=(pixel+QuantumRange*SigmaUniform*(alpha-0.5f)); + break; + } + case GaussianNoise: + { + float + gamma, + tau; + + if (alpha == 0.0f) + alpha=1.0f; + beta=mwcReadPseudoRandomValue(r); + gamma=sqrt(-2.0f*log(alpha)); + sigma=gamma*cospi((2.0f*beta)); + tau=gamma*sinpi((2.0f*beta)); + noise=(float)(pixel+sqrt((float) pixel)*SigmaGaussian*sigma+ + QuantumRange*TauGaussian*tau); + break; + } + + + case ImpulseNoise: + { + if (alpha < (SigmaImpulse/2.0f)) + noise=0.0f; + else + if (alpha >= (1.0f-(SigmaImpulse/2.0f))) + noise=(float)QuantumRange; + else + noise=(float)pixel; + break; + } + case LaplacianNoise: + { + if (alpha <= 0.5f) + { + if (alpha <= MagickEpsilon) + noise=(float) (pixel-QuantumRange); + else + noise=(float) (pixel+QuantumRange*SigmaLaplacian*log(2.0f*alpha)+ + 0.5f); + break; + } + beta=1.0f-alpha; + if (beta <= (0.5f*MagickEpsilon)) + noise=(float) (pixel+QuantumRange); + else + noise=(float) (pixel-QuantumRange*SigmaLaplacian*log(2.0f*beta)+0.5f); + break; + } + case MultiplicativeGaussianNoise: + { + sigma=1.0f; + if (alpha > MagickEpsilon) + sigma=sqrt(-2.0f*log(alpha)); + beta=mwcReadPseudoRandomValue(r); + noise=(float) (pixel+pixel*SigmaMultiplicativeGaussian*sigma* + cospi((float) (2.0f*beta))/2.0f); + break; + } + case PoissonNoise: + { + float + poisson; + unsigned int i; + poisson=exp(-SigmaPoisson*QuantumScale*pixel); + for (i=0; alpha > poisson; i++) + { + beta=mwcReadPseudoRandomValue(r); + alpha*=beta; + } + noise=(float) (QuantumRange*i/SigmaPoisson); + break; + } + case RandomNoise: + { + noise=(float) (QuantumRange*SigmaRandom*alpha); + break; + } + + }; + return noise; + } + + + + + + __kernel + void GenerateNoiseImage(const __global CLPixelType* inputImage, __global CLPixelType* filteredImage + ,const unsigned int inputPixelCount, const unsigned int pixelsPerWorkItem + ,const ChannelType channel + ,const NoiseType noise_type, const float attenuate + ,const unsigned int seed0, const unsigned int seed1 + ,const unsigned int numRandomNumbersPerPixel) { + mwc64x_state_t rng; rng.x = seed0; - rng.c = seed1; - - uint span = pixelsPerWorkItem * numRandomNumbersPerPixel; // length of RNG substream each workitem will use - uint offset = span * get_local_size(0) * get_group_id(0); // offset of this workgroup's RNG substream (in master stream); - - MWC64X_SeedStreams(&rng, offset, span); // Seed the RNG streams - - uint pos = get_local_size(0) * get_group_id(0) * pixelsPerWorkItem + get_local_id(0); // pixel to process - - uint count = pixelsPerWorkItem; - - while (count > 0) { - if (pos < inputPixelCount) { - CLPixelType p = inputImage[pos]; - + rng.c = seed1; + + uint span = pixelsPerWorkItem * numRandomNumbersPerPixel; // length of RNG substream each workitem will use + uint offset = span * get_local_size(0) * get_group_id(0); // offset of this workgroup's RNG substream (in master stream); + + MWC64X_SeedStreams(&rng, offset, span); // Seed the RNG streams + + uint pos = get_local_size(0) * get_group_id(0) * pixelsPerWorkItem + get_local_id(0); // pixel to process + + uint count = pixelsPerWorkItem; + + while (count > 0) { + if (pos < inputPixelCount) { + CLPixelType p = inputImage[pos]; + if ((channel&RedChannel)!=0) { setRed(&p,ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getRed(p),noise_type,attenuate))); } @@ -3035,15 +3035,15 @@ uint MWC64X_NextUint(mwc64x_state_t *s) if ((channel & OpacityChannel) != 0) { setOpacity(&p,ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getOpacity(p),noise_type,attenuate))); - } - - filteredImage[pos] = p; - //filteredImage[pos] = (CLPixelType)(MWC64X_NextUint(&rng) % 256, MWC64X_NextUint(&rng) % 256, MWC64X_NextUint(&rng) % 256, 255); - } - pos += get_local_size(0); - --count; - } - } + } + + filteredImage[pos] = p; + //filteredImage[pos] = (CLPixelType)(MWC64X_NextUint(&rng) % 256, MWC64X_NextUint(&rng) % 256, MWC64X_NextUint(&rng) % 256, 255); + } + pos += get_local_size(0); + --count; + } + } ) -- 2.40.0