DevIL Manual (1265192), страница 3
Текст из файла (страница 3)
Acceptable formatsare IL_RGB, IL_RGBA, IL_BGR, IL_BGRA and IL_LUMINANCE.Developer’s Image Library Manual 11• Type:The type of the data block in Data. Acceptable types areIL_UNSIGNED_BYTE, IL_BYTE, IL_UNSIGNED_SHORT, IL_SHORT,IL_UNSIGNED_INT and IL_INT. IL_FLOAT and IL_DOUBLE will besupported shortly. For most purposes, IL_UNSIGNED_BYTE is• Data:always acceptable here.A pointer to the data block that you wish to receive the specifiedimage data. If this is NULL, DevIL will set an error ofIL_INVALID_PARAM and return IL_FALSE (please refer to thesection on error handling in DevIL).Setting Image DataThere are two ways to set image data: one is quick and dirty, while the other is moreflexible but slower.
These two functions are ilSetData and ilSetPixels.ILboolean ilSetData(ILvoid *Data);ILvoidilSetPixels( ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width,ILuint Height, ILuint Depth, ILenum Format, ILenumType, ILvoid *Data);Listing 2-5. Syntax of the functions to set image dataThe Quick MethodUse ilSetData to set the image data directly. DevIL will copy the data provided in theData parameter to the image’s data, so you need not worry about DevIL trying to deleteyour pointer later on.
This function is the counterpart to ilGetData.You must provide image data in the exact same format, type, width, height, depth andbpp as the current bound image, since DevIL does no conversions here; it just does asimple memory copy.ilSetData will return IL_FALSE and set an error of IL_INVALID_PARAM if Data isNULL.The Flexible MethodUse ilSetPixels to set a portion of the current bound image’s data or to set the currentimage’s data with data of a different format / type. Specify the data block, where youwant to put it and what kind of data it is, and DevIL takes care of all conversionsautomatically for you.
The data block can range from a single line to a rectangle, all theway to a cube.ilSetPixels has a long parameter list, like ilCopyPixels, so here is a description of theparame ters of ilSetPixels:12 Developer’s Image Library Manual•••XOff:YOff:ZOff:Specifies where to place the block of image data in the x direction.Specifies where to place the block of image data in the y direction.Specifies where to place the block of image data in the z direction.This will be 0 in most cases, unless you are using image volumes.• Width: The width of the data block in Data.• Height: The height of the data block in Data.• Depth: The depth of the data block in Data. This will be 1, unless you areusing image volumes.• Format: The format of the data block in Data.
Acceptable formats areIL_RGB, IL_RGBA, IL_BGR, IL_BGRA and IL_LUMINANCE.• Type:The type of the data block in Data. For acceptable types, refer to thedocumentation on ilTexImage. For most purposes,IL_UNSIGNED_BYTE is always acceptable here.• Data:A pointer to the actual data block. If this is NULL, DevIL will set anerror of IL_INVALID_PARAM and return IL_FALSE (please refer tothe section on error handling in DevIL).If you specify a combination of an offset with a width/height/depth that makes your datablock overreach the edge of the currently bound image, DevIL will clip your data so thatno crashes will occur and that the resulting image will be correctly produced.Copying ImagesDevIL has three functions to copy images: ilCopyImage, ilOverlayImage and ilBlit.ILboolean ilCopyImage(ILuint Src);ILboolean ilOverlayImage(ILuint Src, ILint XCoord, ILint YCoord, ILintZCoord);ILboolean ilBlit(ILuint Src, ILint DestX, ILint DestY, ILint DestZ, ILuint SrcX,ILuint SrcY, ILuint SrcZ, ILuint Width, ILuint Height, ILuintDepth);Listing 2-6.
Syntax of the functions to copy imagesDirect CopyingUse ilCopyImage to create a copy of an image. ilCopyImage will copy the imagespecified by the image name in Src to the currently bound image. ilCopyImage can beuseful when you want to apply an effect to an image but want to preserve the original.The image bound before calling ilCopyImage will still be bound after ilCopyImageexits.If you specify an image name in Src that has not been generated by ilGenImages orilBindImage, ilCopyImage will set the IL_INVALID_PARAM error and returnIL_FALSE.Developer’s Image Library Manual 13BlittingilBlit copies a portion of an image over to another image.
This is similar to blittingperformed in graphics libraries, such as StretchBlt in the Windows API. You can copy arectangular block from anywhere in a source image, specified by Src, to any point in thecurrently bound image. A description of the various ilBlit parameters follows:•••••Src:DestX:DestY:DestZ:SrcX:•SrcY:•SrcZ:•••Width:Height:Depth:The source image name.Specifies where to place the block of image data in the x direction.Specifies where to place the block of image data in the y direction.Specifies where to place the block of image data in the z direction.Specifies where to start copying in the x direction of the sourceimage.Specifies where to start copying in the y direction of the sourceimage.Specifies where to start copying in the z direction of the sourceimage.How many pixels to copy in the x direction of the source image.How many pixels to copy in the y direction of the source image.How many pixels to copy in the z direction of the source image.OverlayingilOverlay is essentially the same as ilBlit, but it copies the entire image over, instead ofjust a portion of the image.
ilOverlay is more of a convenience function, since you canobtain the same results by calling ilBlit with SrcX, SrcY and SrcZ set to zero, with theWidth, Height and Depth parameters set to the source image’s height, width and depth,respectively. ilOverlay is missing six parameters that ilBlit has:••••Src:DestX:DestY:DestZ:The source image name.Specifies where to place the block of image data in the x direction.Specifies where to place the block of image data in the y direction.Specifies where to place the block of image data in the z direction.14 Developer’s Image Library ManualError HandlingDevIL contains error- handling routines to alert the users of this library to any internalproblems in DevIL.
The ilGetError function reports all errors in DevIL.iluErrorString converts error numbers returned from ilGetError to a human-readableformat.ILenumconst char*ilGetError(ILvoid);iluErrorString(ILenum Error);Listing 3-1. Syntax of the error functionsError DetectionProblems can always occur in any software application, and DevIL is no different.DevIL keeps track of all non-fatal errors that have occurred during its operation. Allerrors are kept on a stack maintained by ilGetError. Every time ilGetError is called,the last error is returned and pushed off the top of the stack.
You should call ilGetErroruntil IL_NO_ERROR is returned. IL_NO_ERROR signifies that there are no more errorson the error stack. Most errors reported are not harmful, and DevIL operation cancontinue, except for IL_OUT_OF_MEMORY .All error codes that can be returned by ilGetError are listed in Appendix A.Error StringsiluErrorString returns a human readable error string from any error that ilGetError canreturn.
This is useful for when you want to display what kind of error happened to theuser.Developer’s Image Library Manual 15Image CharacteristicsAll images have a certain set of characteristics: origin of the image, format of the image,type of the image, and more.Origin16 Developer’s Image Library ManualImage ManipulationILU (image library utilities) contains functions to manipulate any type of image in avariety of ways. Some functions filter images, while others perform a wider variety ofoperations, such as scaling an image.
This section will give a comparison of the utilityfunctions against figure 4-1.Figure 4-1. Original, unmodified imageAlienifyingiluAlienify 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, hencethe fabricated term “alienify”. iluAlienify does not accept any parameters. Figure 4-2illustrates this effect on the OpenIL logo.Figure 4-2.