DevIL Manual (1265192), страница 2
Текст из файла (страница 2)
Syntax of the image name functionsGenerating Image NamesUse ilGenImages to generate a set of image names. ilGenImages accepts an array ofILuint to receive the generated image names. There are no guarantees about the order ofthe generated image names or any other predictable behaviour like this.
IfilDeleteImages is called on an image name, ilGenImages will return that valueafterward, until all deleted image names are used. This conserves memory and isgenerally quick. The only guarantee is that each member of the Images parameter (up toNum number of them) will have a new, unique value.Binding Image NamesilBindImage binds the current image to the image described by the image name inImage. DevIL reserves the number zero for the default base image. If you pass a valuefor Image that was not generated by ilGenImages, ilBindImage automatically creates animage specified by the image name passed.
An image must always be bound before youcall any functions that operate on images and their data.When DevIL creates a new image, the image has the default properties of 1x1x1 with abit depth of 8. DevIL creates a new image when you call ilBindImage with an imagename that has not been generated by ilGenImages or when you call ilGenImagesspecifically.Deleting Image NamesilDeleteImages is the exact opposite of ilGenImages and even accepts the exact sameparameters. ilDeleteImages deletes image names to free memory for subsequentoperations. You should always call ilDeleteImages on images that are not in useanymore. When you delete an image, DevIL actually deletes all data and anythingassociate with it, so that ilGenImages can possibly use the image name later.File HandlingLoading ImagesDevIL’s main purpose is to load images.
DevIL’s loading is designed to be extremelyeasy but very powerful. Appendix B lists the image types DevIL is capable of loading.Developer’s Image Library Manual 7ILboolean ilLoadImage(const char *FileName);ILboolean ilLoad(ILenum Type, const char *FileName);ILboolean ilLoadF(ILenum Type, ILHANDLE File);ILboolean ilLoadL(ILenum Type, ILvoid *Lump, ILuint Size);Listing 2-2.
Syntax of the loading functionsDevIL contains four loading functions to support different loading styles and loadingfrom several different image sources.Loading from Files - ilLoadImageilLoadImage is the main DevIL loading function. All you do is pass ilLoadImage thefilename of the image you wish to load. ilLoadImage takes care of the rest.ilLoadImage allows users to transparently load several different image formatsuniformly. DevIL’s most powerful function is ilLoadImage because of this feature.Before loading the image, ilLoadImage must first determine the image format of the file.ilLoadImage performs the following steps:1. Compares the filename’s extension to any registered file handlers, allowing theregistered file handlers to take precedence over the default DevIL file handlers.
If theextension matches a registered file handler, ilLoadImage passes control to the filehandler and returns. For more information on registering, refer to the section entitled“Registration”.2. Compares the filename’s extension to the extensions natively supported by DevIL. Ifthe extension matches a loading function’s extension, ilLoadImage passes control tothe file handler and returns.3. Examines the file for a header and tries to match it with a known type of imageheader. If a valid image header is found, ilLoadImage passes control to theappropriate file hander and returns.4. Returns IL_FALSE.Loading from Files - ilLoadDevIL’s other file loading function is ilLoad.
ilLoad is similar to ilLoadImage in manyrespects but different in other ways. ilLoad accepts two parameters: the type of imageand the filename of the image.ilLoad’s type parameter is what differentiates it from ilLoadImage. Type can be any ofthe values listed in table B-2 in appendix B or the value IL_TYPE_UNKNOWN. If Typeis a value from table B-1, ilLoad attempts to load the file as the specified type of imageformat. Only use this if you know what type of images you will be loading and want tobypass DevIL’s checks.8Developer’s Image Library ManualIf IL_TYPE_UNKNOWN is specified for Type, ilLoad behaves exactly likeilLoadImage.
Refer to the previous section for detailed behaviour of these twofunctions.Loading from File Streams - ilLoadFDevIL’s file stream loading function is ilLoadF. ilLoadF is exactly equivalent toilLoad, but instead of accepting a const char pointer, ilLoadF accepts an ILHANDLE.DevIL defines ILHANDLE as a void pointer via a typedef. Under normal circumstances,File will be a FILE struct pointer defined in stdio.h.Refer to the section entitled “Registration” for instructions on how to use your own filehandling functions and file handles.Loading from Memory Lumps - ilLoadLDevIL’s file handling is abstracted to allow loading images from memory called “lumps”.ilLoadL handles loading from lumps.
You must specify a valid type as the firstparameter and the lump as the second parameter.The third parameter that ilLoadL accepts is the total size of the lump. DevIL uses thisvalue to perform bounds checking on the input data. Specify a value of zero for Size ifyou do not want ilLoadL to perform any bounds checking.Saving ImagesDevIL also has some powerful saving functions to fully complement the loadingfunctions.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);Listing 2-3. Syntax of the saving functionsDevIL’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 supportedsaving formats are located in Appendix B.Image ManagementDeveloper’s Image Library Manual 9Defining 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);Listing 2-4.
Syntax of the ilTexImage functionilTexImage 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 awidth of one.Height: The height of the image. If this is zero, DevIL creates an image witha height of one.Depth: The depth of the image, if it is an image volume. Most applicationsshould specify 0 or 1 for this parameter.Bpp:The bytes per pixel of the image data. Do not confuse this with bitsper pixel, which is also commonly used. Common bytes per pixelvalues are 1, 3 and 4.Format: The format of the image data. Formats accepted are listed here andare self-explanatory:IL_COLOUR_INDEXIL_RGBIL_RGBAIL_BGRIL_BGRAIL_LUMINANCE•Type:The type of image data.
Usually, this will be IL_UNSIGNED_BYTE,unless you want to utilize multiple bits per colour channel. Typeaccepted are listed here:IL_BYTEIL_UNSIGNED_BYTEIL_SHORTIL_UNSIGNED_SHORTIL_INTIL_UNSIGNED_INTIL_FLOATIL_DOUBLE•Data:Mainly for convenience, if you already have image data loaded andready to put into the newly created image.
Specifying NULL for this10 Developer’s Image Library Manualparameter just results in the image having unpredictable image data.You can specify image data later using ilSetData or ilSetPixels.Getting 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 ilGetData and ilCopyPixels.ILubyte*ILuintilGetData(ILvoid);ilCopyPixels( ILuint XOff, ILuint YOff, ILuint ZOff, ILuint Width,ILuint Height, ILuint Depth, ILenum Format, ILenumType, ILvoid *Data);Listing 2-6. Syntax of the functions to get image dataThe 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.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 conversionsautomatically for you to give you the image data in the format or type that you need. Thedata block 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:YOff:ZOff:Specifies where to start copying in the x direction.Specifies where to start copying in the y direction.Specifies where to start copying in the z direction.
This will be 0 inmost 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, unlessyou are using image volumes.• Format: The format of the returned data that you desire.