DevIL_manual (1265195), страница 4
Текст из файла (страница 4)
See [language #defines], page 23 for a list of possible values.Be aware that if the Unicode version of DevIL is not being used, some translations willnot display properly. An example is Arabic, which uses characters outside of the standardASCII character set.Chapter 7: Image Manipulation137 Image ManipulationILU (Image Library Utilities) contains functions to manipulate any type of image in a varietyof ways. Some functions filter images, while others perform a wider variety of operations,such as scaling an image.
This section will give a comparison of the utility functions againstthe below figure.Original, unmodified image7.1 AlienifyingiluAlienify is a filter I created purely by accident, when I was attempting to write colourmatrix code. The effect iluAlienify gives to an image is a green and purple tint. Onimages with humans in them, iluAlienify generally makes the people look green, hence thefabricated term “alienify”.
iluAlienify does not accept any parameters. The figure belowillustrates this effect on the DevIL logo.“Alienified” image7.2 BlurringILU has two blurring functions iluBlurAverage and iluBlurGaussian. Blurring canbe used 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 article athttp://www.gamedev.net/reference/programming/features/edf/.iluBlurAverage and iluBlurGaussian are functionally equivalent. Both functions accept a single parameter. Call the desired function with the number of iterations of blurringyou wish to be performed on the image. Increase the number of iterations to increase theblurriness of an image.Average blurred with 10 iterations appliedChapter 7: Image Manipulation14Gaussian blurred with 10 iterations applied7.3 ContrastILU can apply more colour contrast to your image by brightening the lights and darkeningthe 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 of the0.0 to 1.7 range will give undefined results. -0.5 to 0.0 will actually create a negative of theimage and increase the contrast.Contrast of 0.1Contrast of 1.77.4 EqualizationSometimes it may be useful to equalize an image that is, bring the extreme colour valuesto a median point.
iluEqualize darkens the bright colours and lightens the dark colours,reducing the contrast in an image or “equalizing” it. The below figure shows the results ofapplying iluEqualize to the DevIL image.Equalized image7.5 Gamma CorrectioniluGammaCorrect applies gamma correction to an image using an exponential curve. Thesingle parameter iluGammaCorrect accepts is the gamma correction factor you wish to use.A gamma correction factor of 1.0 leaves the image unmodified. Values in the range 0.0 1.0 darken the image. 0.0 leaves a totally black image.
Anything above 1.0 brightens theimage, but values too large may saturate the image.Chapter 7: Image Manipulation15Result of gamma correction of 0.5Result of gamma correction of 2.07.6 NegativityiluNegative 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 pixel canbe determined by this formula: new colour = ~old colour (where the tilde is the negationof the set of bits).
iluNegative does not accept any parameters and is reversible by callingit again.iluNegative example7.7 NoiseILU 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 seedto srand. If your program depends on a different seed to rand, reset it after callingiluNoisify. The seed ILU 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 aclamped (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 how muchof a mono intensity that iluNoisify is allowed to apply to each pixel.
A “random” monointensity is applied to each pixel so that you will not end up with totally new colours, justthe same colours with a different luminance value. Colours change by both negative andpositive values, so some pixels may be darker, some may be lighter, and others will remainthe same.Result of iluNoisify with a0.50 toleranceResult of iluNoisify with a1.0 toleranceChapter 7: Image Manipulation167.8 PixelizationiluPixelize 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.
Values lessthan 1 generate an error.Pixelization of 5 pixels across7.9 SharpeningSharpening sharply defines the outlines in an image. iluSharpen performs this sharpeningeffect on an image. iluSharpen accepts two parameters: the sharpening factor and thenumber of iterations to perform the sharpening effect.The 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 the image,with 2.5 having the most pronounced sharpening effect. Values from 0.0 to 1.0 do a typeof reverse sharpening, blurring the image. Values outside of the 0.0 - 2.5 range produceundefined 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.Sharpening of 2.5Chapter 8: Resizing Images178 Resizing Images8.1 Basic ScalingTo resize images, use the iluScale function:ILboolean iluScale(ILuint Width, ILuint Height, ILuint Depth);The 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 ratios ofthe image do not even have to be the same. The currently bound image is replaced entirelyby the new scaled image.If you specify a dimension greater than the original dimension, the image enlarges inthat direction. Alternately, if you specify a dimension smaller than the original dimension,the image shrinks in that direction.Original imageEnlarged imageShrunk image8.2 Advanced ScalingILU also allows you to specify which method you want to use to resize images. As you cansee in the middle figure above, the enlarged image is very pixelized.
The shrunk image isalso blocky. This is because a nearest filter was applied to the image in figure 5.1 to producefigures 5.2 and 5.3.ILU allows you to use different filters to produce better scaling results viailuImageParameter:• Nearest filter - ILU_NEAREST• Linear filter - ILU_LINEAR• Bilinear filter - ILU_BILINEAR• Box filter - ILU_SCALE_BOX• Triangle filter - ILU_SCALE_TRIANGLE• Bell filter - ILU_SCALE_BELL• B Spline filter - ILU_SCALE_BSPLINE• Lanczos filter - ILU_SCALE_LANCZOS3• Mitchell filter - ILU_SCALE_MITCHELLJust use the ILU_FILTER define as PName in iluImageParameter with the appropriatefilter define as Param.ILvoid iluImageParameter(ILenum PName, ILenum Param);Chapter 8: Resizing Images188.3 Filter 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 the three.All the filters after bilinear are considered the advanced scaling functions and require muchmore 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 not generallyhave to use higher sampling schemes to achieve a reasonable image.Enlarging an image, though, depends quite heavily on how good the sampling schemeis. ILU provides several filtering functions to let you choose which one best fits your needs:speed versus image quality. Below is a comparison of the different types of filters whenenlarging an image.Nearest filterLinear filterBilinear filterBox filterTriangle filterBell filterB spline filterLanczos filterMitchell filterChapter 9: Sub-Images199 Sub-Images9.1 MipmapsMipmaps in DevIL are successive half-dimensioned power-of-2 images. The dimensions donot have to be powers of 2 if you generate them manually, but DevIL’s mipmap generationfacilities assume power-of-2 images.All mipmap levels down to 1x19.1.1 Mipmap CreationYou generate mipmaps for any image using iluBuildMipmaps.