1 /** 2 * Copyright: Mike Wey 2011 3 * License: zlib (See accompanying LICENSE file) 4 * Authors: Mike Wey 5 * 6 * This is an translation of the sigmoidal contrast example 7 * that can be found on the ImageMagick website: 8 * http://www.imagemagick.org/source/core/sigmoidal-contrast.c 9 * 10 * Mainly to demonstrate the parallel execution of the foreach 11 * over the ImageView, normaly you whould use Image.sigmoidalContrast. 12 */ 13 14 module examples.sigmoidalContrast; 15 16 import std.math; 17 import std.stdio; 18 19 import dmagick.ColorRGB; 20 import dmagick.Image; 21 22 void main(string[] args) 23 { 24 if ( args.length != 3 ) 25 { 26 writefln("Usage: %s image sigmoidal-image", args[0]); 27 return; 28 } 29 30 Image image = new Image(args[1]); 31 32 //The Body of this loop is executed in parallel. 33 foreach ( row; image.view ) 34 { 35 foreach ( ColorRGB pixel; row ) 36 { 37 pixel.red = SigmoidalContrast(pixel.red); 38 pixel.green = SigmoidalContrast(pixel.green); 39 pixel.blue = SigmoidalContrast(pixel.blue); 40 pixel.opacity = SigmoidalContrast(pixel.opacity); 41 } 42 } 43 44 image.write(args[2]); 45 } 46 47 double SigmoidalContrast(double q) 48 { 49 return ((1.0/(1+exp(10.0*(0.5-q)))-0.0066928509)*1.0092503); 50 }