DevIL_manual (1265195), страница 3
Текст из файла (страница 3)
Specify a value of zero for Size if youdo not want ilLoadL to perform any bounds checking.3.3.5 Saving to FilesDevIL also has some powerful saving functions to fully complement the loading functions.ILboolean ilSaveImage(const char *FileName);ILboolean ilSave(ILenum Type, const char *FileName);ILboolean ilSaveF(ILenum Type, ILHANDLE File);ILboolean ilSaveL(ILenum Type, ILvoid *Lump, ILuint Size);DevIL’s saving functions are identical to the loading functions, despite the fact that theysave images instead of load images.
Lists of possible values for Type and supported savingformats are located in Appendix B.Chapter 4: Image Management84 Image Management4.1 Defining ImagesilTexImage is used to give the current bound image new attributes that you specify. Anyimage data or attributes previously in the current bound image are lost after a call toilTexImage, so make sure that you call it only after preserving the image data if need be.ILboolean ilTexImage(ILuint Width, ILuint Height, ILuint Depth,ILubyte Bpp, ILenum Format, ILenum Type, ILvoid *Data);ilTexImage has one of the longer parameter lists of the DevIL functions, so we willbriefly go over what is expected for each argument.− Width: The width of the image. If this is zero, DevIL creates an image with a widthof one.− Height: The height of the image.
If this is zero, DevIL creates an image with a heightof one.− Depth: The depth of the image, if it is an image volume. Most applications shouldspecify 0 or 1 for this parameter.− Bpp: The bytes per pixel of the image data. Do not confuse this with bits per pixel,which is also commonly used. Common bytes per pixel values are 1, 3 and 4.− Format: The format of the image data. See [format #defines], page 23 for what youcan pass.− Type: The type of image data.
Usually, this will be IL_UNSIGNED_BYTE, unless youwant to utilize multiple bytes per colour channel. See [type #defines], page 23 foracceptable type.− Data: Mainly for convenience, if you already have image data loaded and ready toput into the newly created image. Specifying NULL for this parameter just results inthe image having unpredictable image data. You can specify image data later usingilSetData or ilSetPixels.4.2 Getting Image DataThere are two ways to set image data: one is quick and dirty, while the other is more flexiblebut slower.
These two functions are ilGetData and ilCopyPixels.ILubyte *ilGetData(ILvoid);ILuint ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff,ILuint Width, ILuint Height, ILuint Depth, ILenum Format,ILenum Type, ILvoid * Data);4.2.1 The Quick MethodUse ilGetData to get a direct pointer to the current bound image’s data pointer. Do notever try to delete this pointer that is returned. To get information about the image data,use ilGetInteger.ilGetData will return NULL and set an error of IL_ILLEGAL_OPERATION if there is nocurrently bound image.Chapter 4: Image Management94.2.2 The Flexible MethodUse ilCopyPixels to get a portion of the current bound image’s data or to get the currentimage’s data with in a different format / type.
DevIL takes care of all conversions automatically for you to give you the image data in the format or type that you need. The datablock can range from a single line to a rectangle, all the way to a cube.ilCopyPixels has a long parameter list, like ilTexImage, so here is a description of theparameters of ilCopyPixels:− XOff: Specifies where to start copying in the x direction.− YOff: Specifies where to start copying in the y direction.− ZOff: Specifies where to start copying in the z direction. This will be 0 in most cases,unless you are using image volumes.− Width: Number of pixels to copy in the x direction.− Height: Number of pixels to copy in the y direction.− Depth: Number of pixels to copy in the z direction. This will be 1, unless− Format, Type, Data: These are basically the same as ones described above.
see [ilTexImage reference], page 8.4.3 Copying ImagesDevIL has three functions to copy images: ilCopyImage, ilOverlayImage and ilBlit.ILboolean ilCopyImage(ILuint Src);ILboolean ilOverlayImage(ILuint Src, ILint XCoord, ILint YCoord,ILint ZCoord);ILboolean ilBlit(ILuint Src, ILint DestX, ILint DestY, ILint DestZ,ILuint SrcX, ILuint SrcY, ILuint SrcZ, ILuint Width,ILuint Height, ILuint Depth);4.3.1 Direct CopyingUse ilCopyImage to create a copy of an image. ilCopyImage will copy the image specifiedby the image name in Src to the currently bound image.
ilCopyImage can be useful whenyou want to apply an effect to an image but want to preserve the original. The image boundbefore calling ilCopyImage will still be bound after ilCopyImage exits.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 return IL_FALSE.4.3.2 BlittingilBlit 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: The source image name.− DestX: Specifies where to place the block of image data in the x direction.− DestY: Specifies where to place the block of image data in the y direction.− DestZ: Specifies where to place the block of image data in the z direction.Chapter 4: Image Management−−−−−−10SrcX: Specifies where to start copying in the x direction of the source image.SrcY: Specifies where to start copying in the y direction of the source image.SrcZ: Specifies where to start copying in the z direction of the source image.Width: How many pixels to copy in the x direction of the source image.Height: How many pixels to copy in the y direction of the source image.Depth: How many pixels to copy in the z direction of the source image.4.3.3 OverlayingilOverlay is essentially the same as ilBlit, but it copies the entire image over, insteadof just 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: The source image name.− DestX: Specifies where to place the block of image data in the x direction.− DestY: Specifies where to place the block of image data in the y direction.− DestZ: Specifies where to place the block of image data in the z direction.4.3.4 Blit/Overlay BehaviorBy default, ilBlit and ilOverlay will blend the source with the destination image if thesource has an alpha channel present. If you need to blit the image without blending, youcan use the IL_BLIT_BLEND #define.
This behavior can be toggled with ilEnable andilDisable.ilDisable(IL_BLIT_BLEND); // Turns off blendingilEnable(IL_BLIT_BLEND); // Turns on blendingChapter 5: Image Characteristics115 Image CharacteristicsAll images have a certain set of characteristics: origin of the image, format of the image,type of the image, and more.5.1 OriginDepending on the image format, data can start in the upper left or the lower left cornerof the image. By default, DevIL keeps the origin in the same place as the original image.This can cause your image to be flipped vertically if the image you are loading has an originother than what you expect. To obtain the origin of the image, use ilGetInteger.ilGetInteger(IL_IMAGE_ORIGIN);To force DevIL to use just one origin, you need to use the following code:ilEnable(IL_ORIGIN_SET);ilSetInteger(Origin );Origin is either IL_ORIGIN_LOWER_LEFT or IL_ORIGIN_UPPER_LEFT.
Finally, if you needto find out which origin mode is currently set, use:ilGetInteger(IL_ORIGIN_MODE);5.2 FormatChapter 6: Error Handling126 Error 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. iluErrorStringconverts error numbers returned from ilGetError to a human-readable format.ILenum ilGetError(ILvoid);const char* iluErrorString(ILenum Error);6.1 Error DetectionProblems can always occur in any software application, and DevIL is no different.
DevILkeeps track of all non-fatal errors that have occurred during its operation. All errors arekept on a stack maintained by ilGetError. Every time ilGetError is called, the lasterror is returned and pushed off the top of the stack. You should call ilGetError untilIL_NO_ERROR is returned. IL_NO_ERROR signifies that there are no more errors on the errorstack. Most errors reported are not harmful, and DevIL operation can continue, except forIL_OUT_OF_MEMORY.All error codes that can be returned by ilGetError are listed in Appendix A.6.2 Error StringsiluErrorString returns a human readable error string from any error that ilGetErrorcan return.
This is useful for when you want to display what kind of error happened to theuser.6.2.1 LanguagesThe ILU error messages have been translated into multiple languages: Arabic, Dutch,German, Japanese and Spanish. The default language is English.6.2.2 Selecting a LanguageiluSetLanguage will change the error string returned by iluErrorString to the languagespecified in its parameter. Languages supported are: English, Arabic, Dutch, German,Japanese and Spanish.