__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]; if ((channel&RedChannel)!=0) { setRed(&p,ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getRed(p),noise_type,attenuate))); } if ((channel&GreenChannel)!=0) { setGreen(&p,ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getGreen(p),noise_type,attenuate))); } if ((channel&BlueChannel)!=0) { setBlue(&p,ClampToQuantum(mwcGenerateDifferentialNoise(&rng,getBlue(p),noise_type,attenuate))); } 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; } }