DevIL Manual (1265192), страница 4
Текст из файла (страница 4)
“Alienified” imageBlurringILU has two blurring functions – iluBlurAverage and iluBlurGaussian. Blurring can beused for a simple motion blur effect or something as sophisticated as concealing theidentity of a person in an image. Both of these functions use a convolution filter andmultiple iterations to blur an image. Gaussian blurs look more natural than averagingblurs, because the center pixel in the convolution filter “weighs” more. For an in-depthdescription of convolution filters, see the excellent “Elementary Digital Filtering” articleat http://www.gamedev.net/reference/programming/features/edf/.iluBlurAverage and iluBlurGaussian are functionally equivalent.
Both functions accepta single parameter. Call the desired function with the number of iterations of blurringDeveloper’s Image Library Manual 17you wish to be performed on the image. Increase the number of iterations to increase theblurriness of an image.Figure 4-3. Average blurredwith 10 iterations appliedFigure 4-4. Gaussian blurredwith 10 iterations appliedContrastThe American Heritage Dictionary describes contrast as “The use of opposing elements,such as colors, forms, or lines, in proximity to produce an intensified effect in a work ofart.” ILU can apply more colour contrast to your image by brightening the lights anddarkening the darks via iluContrast. This effect can make a dull image livelier and“stand out” more.iluContrast accepts a single parameter describing the desired amount of contrast tomodify the image by. A value of 1.0 does not affect the image. Values above 1.0 to 1.7increase the amount of contrast in the image, with 1.7 increasing the contrast the most.Values from 0.0 to 1.0 decrease the amount of contrast in the image.
Values outside ofthe 0.0 to 1.7 range will give undefined results. -0.5 to 0.0 will actually create a negativeof the image and increase the contrast.Figure 4-5. Contrast of 1.6Figure 4-6. Contrast of 0.2Figure 4-7. Contrast of -.5Equali zationSometimes it may be useful to equalize an image – that is, bring the extreme colourvalues to a median point. iluEqualize darkens the bright colours and lightens the darkcolours, reducing the contrast in an image or “equalizing” it. Figure 4-8 shows the resultsof applying iluEqualize to the OpenIL image.18 Developer’s Image Library ManualFigure 4-8.
Equalized imageGamma CorrectioniluGammaCorrect applies gamma correction to an image using an exponential curve.The single parameter iluGammaCorrect accepts is the gamma correction factor youwish to use. A gamma correction factor of 1.0 leaves the image unmodified. Values inthe range 0.0 - 1.0 darken the image. 0.0 leaves a totally black image. Anything above1.0 brightens the image, but values too large may saturate the image.Figure 4-9. Result of gammacorrection of 0.5Figure 4-10.
Result of gammacorrection of 1.9NegativityiluNegative is a very basic function that inverts every pixel’s colour in an image. Forexample, pure white becomes pure black, and vice-versa. The resulting colour of a pixelcan be determined by this formula: new_colour = ~old_colour (where the tilde is thenegation of the set of bits).
iluNegative does not accept any parameters and is reversibleby calling it again.Figure 4-11. iluNegative exampleNoiseDevIL can add “random” noise to any image to make it appear noisy. The function,iluNoisify, simply uses the standard libc rand function after initializing it with a seed tosrand.
If your program depends on a different seed to rand, reset it after callingDeveloper’s Image Library Manual 19iluNoisify. The seed DevIL uses is the standard time(NULL) call. Of course, the noiseadded to the image is not totally random, since no such thing exists, but there should beno repeating, except in extremely large images.iluNoisify accepts a single parameter – the tolerance to use.
This parameter is a clamped(float) value that should be in the range 0.0f - 1.0f. Lower values indicate a lowertolerance, while higher values indicate the opposite. The tolerance indicates just howmuch of a mono intensity that iluNoisify is allowed to apply to each pixel. A “random”mono intensity is applied to each pixel so that you will not end up with totally newcolours, just the same colours with a different luminance value.
Colours change by bothnegative and positive values, so some pixels may be darker, some may be lighter, andothers will remain the same.Figure 4-12. Result of iluNoisify with a 0.50 tolerancePixelizationiluPixelize creates pixelized images by averaging the colour values of blocks of pixels.The single parameter passed to iluPixelize determines the size of these square blocks.The result is a pixelized image.Call iluPixelize with values greater than 1 to pixelize the image. The larger the values,the larger the pixel blocks will be.
A value of 1 will leave the image unchanged. Valuesless than 1 generate an error.Figure 4-13. Pixelization of 10 pixels acrossSharpeningSharpening sharply defines the outlines in an image. iluSharpen performs thissharpening effect on an image. iluSharpen accepts two parameters: the sharpeningfactor and the number of iterations to perform the sharpening effect.20 Developer’s Image Library ManualThe sharpening factor must be in the range of 0.0 - 2.5. A value of 1.0 for the sharpeningfactor will have no effect on the image. Values in the range 1.0 - 2.5 will sharpen theimage, with 2.5 having the most pronounced sharpening effect. Values from 0.0 to 1.0 doa type of reverse sharpening, blurring the image.
Values outside of the 0.0 - 2.5 rangeproduce undefined results.The number of iterations to perform will usually be 1, but to achieve more sharpening,increase the number of iterations. This parameter is similar to the Iterations parameter ofthe two blurring functions. The time it takes to run this function is directly proportionalto the number of iterations desired.Figure 4-14. Sharpening of 1.5 with 5 iterationsDeveloper’s Image Library Manual 21Resizing ImagesBasic ScalingTo resize images, use the iluScale function:ILboolean iluScale(ILuint Width, ILuint Height, ILuint Depth);Listing 5.1.
Syntax of the iluScale functionThe three parameters are relatively explanatory. Any image can be resized to a newwidth, height and depth, provided that you have enough memory to hold the new image.The new dimensions do not have to be the same as the original in any way. Aspect ratiosof the image do not even have to be the same. The currently bound image is replacedentirely by the new scaled image.If you specify a dimension greater than the original dimension, the image enlarges in thatdirection. Alternately, if you specify a dimension smaller tha n the original dimension,the image shrinks in that direction.Figure 5.1. Original imageFigure 5.2.
Enlarged imageFigure 5.3. Shrunk imageAdvanced ScalingDevIL also allows you to specify which method you want to use to resize images. Asyou can see in figure 5.2, the enlarged image is very pixelized. In figure 5.3, the shrunkimage is also blocky.
This is because a nearest filter was applied to the image in figure5.1 to produce figures 5.2 and 5.3.DevIL allows you to use different filters to produce better scaling results:•••••••••Nearest filterLinear filterBilinear filterBox filterTriangle filterBell filterB Spline filterLanczos filterMitchell filter-ILU_NEARESTILU_LINEARILU_BILINEARILU_SCALE_BOXILU_SCALE_TRIANGLEILU_SCALE_BELLILU_SCALE_BSPLINEILU_SCALE_LANCZOS3ILU_SCALE_MITCHELL22 Developer’s Image Library ManualJust use the ILU_FILTER define as PName in iluImageParameter with the appropriatefilter define as Param.ILvoid iluImageParameter(ILenum PName, ILenum Param);Listing 5.1. Syntax of the iluImageParameter functionFilter ComparisonsThe first three filters (nearest, linear and bilinear) require an increasing amount of time toresize an image, with nearest being the quickest and bilinear being the slowest of thethree.
All the filters after bilinear are considered the “advanced” scaling functions andrequire much more time to complete, but they generally produce much nicer results.When minimizing an image, bilinear filtering should be sufficient, since it uses a fourpixel averaging scheme to create every destination pixel. Minimized images do notgenerally have to use higher sampling schemes to achieve a reasonable image.Enlarging an image, though, depends quite heavily on how good the sampling scheme is.DevIL provides several filtering functions to let you choose which one best fits yourneeds: speed versus image quality. Below is a comparison of the different types of filterswhen enlarging an image.Figure 5.4.
Original ‘Lena’ imageNearest filterLinear filterBilinear filterBox filterTriangle filterBell filterDeveloper’s Image Library Manual 23B spline filterFigure 5.5. Filter comparisonsLanczos filterMitchell filter24 Developer’s Image Library ManualSub-ImagesMipmapsMipmaps in DevIL are successive half-dimensioned power-of-2 images. The dimensionsdo not have to be powers of 2 if you generate them manually, but DevIL’s mipmapgeneration facilities assume power-of-2 images.Figure 4-1. All mipmap levels down to 1x1Mipmap CreationYou generate mipmaps for any image using iluBuildMipmaps . If the image already hasmipmaps, the previous mipmaps are erased, and new mipmaps are generated.