DevIL Manual
DevIL Manual
Copyright c 2008,2009 Denton Woods, Matj T e yc Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
Table of Contents
IL manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 1.2 General introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Library Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Library setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Microsoft Visual C++ setup. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 MSVC++ Bug Workaround . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.3 Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 DJGPP Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 General GCC-based (Linux, Cygwin, Max OS X, etc.) Setup . . . . 2.4 Test and examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4.1 Test suite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 4 4 5 5 6 6 6
Basic usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1 Initializing DevIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.1.1 IL Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.1.2 ILU Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.1.3 ILUT Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.2 Image Name Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.2.1 Generating Image Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.2.2 Binding Image Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.2.3 Deleting Image Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.3 File handling loading images. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.3.1 Loading from Files ilLoadImage . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.3.2 Loading from Files ilLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.3.3 Loading from File Streams ilLoadF . . . . . . . . . . . . . . . . . . . . 10 3.3.4 Loading from Memory Lumps ilLoadL . . . . . . . . . . . . . . . . . 10 3.3.5 Saving to Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Image management . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.1 4.2 Defining Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Getting image data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2.1 The Quick Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2.2 The Flexible Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Setting image Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.1 The Quick Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3.2 The Flexible Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Copying Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 12 12 13 13 13 13 14
ii 4.4.1 4.4.2 4.4.3 4.4.4 Direct Copying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Blitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Overlaying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Blit/Overlay Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 14 14 15
Image Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . 16
5.1 5.2 5.3 Origin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Error handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
6.1 6.2 Error Detection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Error Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.1 Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2.2 Selecting a Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 17 17 17
Image manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 Alienifying . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Blurring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Contrast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Equalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Gamma Correction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Negativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pixelization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sharpening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 19 20 20 21 21 22 23 23
Resizing Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
8.1 8.2 8.3 Basic Scaling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Advanced Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Filter Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Sub-Images. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
9.1 Mipmaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.1.1 Mipmap Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.1.2 Mipmap Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2 Animations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.1 Animation Chain Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.2.2 Animation Chain Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3 Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4 Sub-Image Mixing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 27 27 27 27 27 28 28
iii
10
DXTC/S3TC Notes . . . . . . . . . . . . . . . . . . . . . . . . . . 29
29 29 29 29 29 30 30 30 30
10.1 DDS Loading/Saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.1 Keeping DXTC Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.2 Controlling Saving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.1.3 Compression Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2 Retrieving DXTC Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.3 Compressing DXTC Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.4 OpenGL/Direct3D DXTC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.4.1 OpenGL S3TC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.4.2 Direct3D DXTC Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Appendix A
Common DevIL Error Codes . . . . . 32 Supported File Formats . . . . . . . . . . 33 Sample DevIL program . . . . . . . . . . . 35
Functions index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
IL manual
IL manual
This is a manual describing IL part of DevIL handling images.
Chapter 1: Introduction
1 Introduction
1.1 General introduction
Developers Image Library was previously called OpenIL, but due to trademark issues, OpenIL is now known as DevIL. DevIL is an Open Source programming library for programmers to incorporate into their own programs. DevIL loads and saves a large variety of images for use in a software developers program. This library is capable of manipulating images in various ways and passing image information to display APIs, such as OpenGL and Direct3D. The purpose of this manual is to guide users in coding with the Developers Image Library. This manual is for users proficient in C and with competent knowledge of the integrated development environment (IDE) or compiler they are using.
2 Library setup
2.1.1 Directories
You will need to change some directory settings in MSVC++ to get DevIL working. 1. Navigate to the Tools menu and select Options. 2. Click on the Directories tab. 3. Under Show directories for, select Include files. 4. Click the New button (to the left of the red X) 5. Type the directory DevIL is installed in, plus \Include. For example, if you installed DevIL to E:\ImageLib, enter E:\ImageLib\Include.
6. Under Show directories for, click on Library files. 7. Click the New button (to the left of the red X). 8. Type the directory DevIL is installed in, plus \Lib. For exam-
ple,
if
you
installed
DevIL
to
E:\ImageLib,
enter
E:\ImageLib\Lib.
9. Click the New button (to the left of the red X). 10. Type the directory DevIL is installed in, plus \Lib\Debug. In the previous example, you would enter E:\ImageLib\Lib\Debug. 11. Choose OK.
2.1.3 Multithreading
DevIL takes advantage of the multithreaded standard LIBC DLLs. To use file streams with DevIL, you must change the project settings of your project. If you do not perform these steps, your program will crash whenever you attempt to use a DevIL file stream. Generally, DevIL is not thread safe. You should make sure that threads in your application do not use DevIL at the same time. 1. Navigate to the Project menu and choose Settings. 2. Click the C/C++ tab. 3. Change the Category drop-down menu to read Code Generation. 4. Change the Use run-time library drop-down menu to Multithreaded DLL if the Settings For menu says Win32 Release. Change the Use run-time library drop-down menu to Debug Multithreaded DLL if the Settings For menu says Win32 Debug.
5. Choose OK.
... dnl Check for libtool (older macro for this is AC_PROG_LIBTOOL) LT_INIT ... # Check for libs we need for our program now dnl Check that we have the header AC_CHECK_HEADER([IL/il.h]) dnl Check for the IL part on DevIL on unix-like systems PKG_CHECK_MODULES([DEVIL], [IL ILU ILUT]) dnl Check that DevIL library exists (good for Windows) AC_CHECK_LIB([DevIL], [main], [LIBS_WE_NEED="-lDevIL $LIBS_WE_NEED"]) ... dnl Now export the variable that contains libraries dnl so we can use it in makefiles AC_SUBST([LIBS_WE_NEED]) AC_SUBST([DEVIL_CFLAGS DEVIL_LIBS]) ... If you are skilled with automake, you may link with the libtool files directly, which is more portable (pkg-config currently breaks cross-compilation). If you use an IDE or if you dont like autotools (which is a big mistake, by the way :-), then you may use pkg-config as a program. This is not recommended if you intend to use DevIL in a cross-platform programs. You can get libraries you need to link to by running pkg-config IL --libs. Again, you decide whether you need IL, ILU or ILUT. Also pass pkg-config IL --cflags to the compiler! If you are a happy IDE user, you have to write this commands in the backquotes like pkg-config ILUT --libs into some text boxes that allow you to specify additional LDFLAGS.
2.4.2 Examples
IL examples: Simple Read
Override Note: Those examples can be linked against ILU, but this is only because error report functions. ILUT examples: Allegro C++ wrapper SDL Volume OpenGL
3 Basic usage
You must initialize DevIL, or it will most certainly crash. You need to initialize each library (IL, ILU, and ILUT) separately. You do not need to initialize libraries you are not using, but keep in mind that the higher level libraries are dependent on the lower ones. For example, ILUT is dependent on ILU and IL, so you have to initialize IL and ILU as well.
is called on an image name, ilGenImages will return that value afterward, until all deleted image names are used. This conserves memory and is generally quick. The only guarantee is that each member of the Images parameter (up to Num number of them) will have a new, unique value.
10
2. Compares the filenames extension to the extensions natively supported by DevIL. If the extension matches a loading functions extension, ilLoadImage passes control to the file handler and returns. 3. Examines the file for a header and tries to match it with a known type of image header. If a valid image header is found, ilLoadImage passes control to the appropriate file hander and returns. 4. Returns IL_FALSE.
11
Typically, the user does not know exactly how large the output image will be. If you pass NULL for Lump and 0 for Size to ilSaveL, ilSaveL will return the buffer size needed to save an image of Type. When a buffer is passed for Lump, the return value is how many bytes were written to the buffer. Note that not all formats that have load support have also save support (see [file formats], page 32)
12
4 Image management
4.1 Defining Images
ilTexImage is used to give the current bound image new attributes that you specify. Any image data or attributes previously in the current bound image are lost after a call to ilTexImage, 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 will briefly go over what is expected for each argument. Width: The width of the image. If this is zero, DevIL creates an image with a width of one. Height: The height of the image. If this is zero, DevIL creates an image with a height of one. Depth: The depth of the image, if it is an image volume. Most applications should specify 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 31, for what you can pass. Type: The type of image data. Usually, this will be IL_UNSIGNED_BYTE, unless you want to utilize multiple bytes per colour channel. See [type #defines], page 31, for acceptable type. Data: Mainly for convenience, if you already have image data loaded and ready to put into the newly created image. Specifying NULL for this parameter just results in the image having unpredictable image data. You can specify image data later using ilSetData or ilSetPixels.
13
14
Data: A pointer to the actual data block. If this is NULL, DevIL will set an error of IL_INVALID_PARAM and return IL_FALSE (please refer to the section on error handling in DevIL). If you specify a combination of an offset with a width/height/depth that makes your data block overreach the edge of the currently bound image, DevIL will clip your data so that no crashes will occur and that the resulting image will be correctly produced.
4.4.2 Blitting
ilBlit copies a portion of an image over to another image. This is similar to blitting performed in graphics libraries, such as StretchBlt in the Windows API. You can copy a rectangular block from anywhere in a source image, specified by Src, to any point in the currently 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. SrcX: 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.4.3 Overlaying
ilOverlay is essentially the same as ilBlit, but it copies the entire image over, instead of just a portion of the image. ilOverlay is more of a convenience function, since you can
15
obtain the same results by calling ilBlit with SrcX, SrcY and SrcZ set to zero, with the Width, Height and Depth parameters set to the source images 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.
16
5 Image Characteristics
All images have a certain set of characteristics: origin of the image, format of the image, type of the image, and more.
5.1 Origin
Depending on the file format, data can start in the upper left or the lower left corner of 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 origin other 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 need to find out which origin mode is currently set, use: ilGetInteger(IL_ORIGIN_MODE);
5.2 Format
Format refers to the ordering of the bytes for each pixel.
5.3 Registration
17
6 Error handling
DevIL contains error-handling routines to alert the users of this library to any internal problems in DevIL. The ilGetError function reports all errors in DevIL. iluErrorString converts error numbers returned from ilGetError to a human-readable format. ILenum ilGetError(ILvoid); const char* iluErrorString(ILenum Error);
6.2.1 Languages
The ILU error messages have been translated into multiple languages: Arabic, Dutch, German, Japanese and Spanish. The default language is English.
18
7 Image manipulation
ILU (Image Library Utilities) contains functions to manipulate any type of image in a variety of 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 against the below figure.
Figure 7.1: Original, unmodified image This is a crop of a Bertrand Benoits image taken from Blender art gallery, and Bertrand has kindly allowed us to use it for demonstrations. You can check out his website. Thank you, Bertrand! The image samples here have a better-than-bad resolution, so you dont have to be afraid to zoom at them if you wish to see details.
7.1 Alienifying
iluAlienify is a filter I created purely by accident, when I was attempting to write colour matrix code. The effect iluAlienify gives to an image is a green and purple tint. On images with humans in them, iluAlienify generally makes the people look green, hence the fabricated term alienify. iluAlienify does not accept any parameters. The figure below illustrates this effect on the DevIL logo.
19
7.2 Blurring
ILU has two blurring functions iluBlurAverage and iluBlurGaussian. Blurring can be used for a simple motion blur effect or something as sophisticated as concealing the identity of a person in an image. Both of these functions use a convolution filter and multiple iterations to blur an image. Gaussian blurs look more natural than averaging blurs, because the center pixel in the convolution filter weighs more. For an in-depth description of convolution filters, see the excellent Elementary Digital Filtering article at gamedev.net. iluBlurAverage and iluBlurGaussian are functionally equivalent. Both functions accept a single parameter. Call the desired function with the number of iterations of blurring you wish to be performed on the image. Increase the number of iterations to increase the blurriness of an image.
Figure 7.3: Original image, average blurred and gaussian blurred, both with 10 iterations applied
20
7.3 Contrast
ILU can apply more colour contrast to your image by brightening the lights and darkening 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 to modify the image by.
values from 0.0 to 1.0 decrease the amount of contrast in the image. value of 1.0 does not affect the image. values above 1.0 to 1.7 increase the amount of contrast in the image, with 1.7 increasing the contrast the most. values outside of the 0.0 to 1.7 range will give undefined results. -0.5 to 0.0 will actually create a negative of the image and increase the contrast.
Figure 7.4: Original image, image with contrast of 0.4 and with contrast of 1.7
7.4 Equalization
Sometimes it may be useful to equalize an image that is, bring the extreme colour values to 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 of applying iluEqualize to the DevIL image.
21
Figure 7.6: Original image, image with gamma 0.7 and with with gamma 1.6
7.6 Negativity
iluNegative is a very basic function that inverts every pixels colour in an image. For example, pure white becomes pure black, and vice-versa. The resulting colour of a pixel can be determined by this formula: new_colour = ~old_colour (where the tilde is the negation of the set of bits). iluNegative does not accept any parameters and is reversible by calling it again.
22
7.7 Noise
ILU 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 to srand. If your program depends on a different seed to rand, reset it after calling iluNoisify. The seed ILU uses is the standard time(NULL) call. Of course, the noise added to the image is not totally random, since no such thing exists, but there should be no repeating, except in extremely large images.
Figure 7.8: Original image, noisified image 0.1, noisified 0.8 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 lower tolerance, while higher values indicate the opposite. The tolerance indicates just how much 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 new colours, just the same colours with a different luminance value. Colours change by both negative
23
and positive values, so some pixels may be darker, some may be lighter, and others will remain the same.
7.8 Pixelization
iluPixelize 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 less than 1 generate an error.
7.9 Sharpening
Sharpening sharply defines the outlines in an image. iluSharpen performs this sharpening effect on an image. iluSharpen accepts two parameters: the sharpening factor and the number of iterations to perform the sharpening effect. The sharpening factor must be in the range of 0.0 - 2.5. values from 0.0 to 1.0 do a type of reverse sharpening, blurring the image. value of 1.0 for the sharpening factor 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 outside of the 0.0 - 2.5 range produce 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 of the two blurring functions. The time it takes to run this function is directly proportional to the number of iterations desired.
24
Figure 7.10: Original image, image sharpened by 1.8 in 2 iterations and sharpened by 2.1 in 3 iterations
25
8 Resizing Images
8.1 Basic Scaling
To 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 new width, 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 of the image do not even have to be the same. The currently bound image is replaced entirely by the new scaled image. If you specify a dimension greater than the original dimension, the image enlarges in that direction. Alternately, if you specify a dimension smaller than the original dimension, the image shrinks in that direction.
26
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 generally 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. 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 when enlarging an image.
Chapter 9: Sub-Images
27
9 Sub-Images
9.1 Mipmaps
Mipmaps in DevIL are successive half-dimensioned power-of-2 images. The dimensions do not have to be powers of 2 if you generate them manually, but DevILs mipmap generation facilities assume power-of-2 images. All mipmap levels down to 1x1
9.2 Animations
Animations are similar to mipmaps, but instead of being smaller successive images, the images are the same size but have different data. The successive animation chains in DevIL can be used to create animations in your programs. File formats that natively support animations are .gif and .mng. You can also create your own sub-images as animations.
Chapter 9: Sub-Images
28
9.3 Layers
DevIL does not have a full layer implementation yet.
29
10 DXTC/S3TC Notes
10.1 DDS Loading/Saving
DevIL supports loading and saving of Microsoft .dds files. DDS files can either be compressed or uncompressed. If they are compressed, DDS files use DirectX Texture Compression (DXTC). DXTC is also known as S3TC, since Microsoft licensed the compression technology from S3.
30
If the DXTC data does not exist in the format that you request, DevIL will automatically compress the data. If ilGetDXTCData returns 0, then the data could not be compressed. To see if a certain format of DXTC data already exists for the currently bound image, call ilGetInteger with the IL_DXTC_DATA_FORMAT parameter.
31
32
33
34
.pxr IL_PXR yes no * IL_RAW yes yes .rot IL_ROT yes no .sgi, .bw, IL_SGI yes yes .rgb, .rgba Sun RAS .sun, .ras, IL_SUN yes no .rs, .im* Creative Assembly Texture .texture IL_TEXTURE yes no Targa .tga IL_TGA yes yes Tagged Image File Format .tif, .tiff IL_TIF yes yes Gamecube Texture .tpl IL_TPL yes no Unreal Texture .utx IL_UTX yes no Valve Texture .vtf IL_VTF yes yes Quake2 Texture .wal IL_WAL yes no HD Photo .wdp, .hdp IL_WDP yes no X Pixel Map .xpm IL_XPM yes yes Exception: IL_JPG (IJL) type is not supported by ilLoadF nor by ilSaveF. IL_JPG (libjpeg) is supported by both.
35
Functions index
36
Functions index
ilBindImage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 ilBlit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 ilCopyImage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 ilCopyPixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 ilDeleteImages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 ilGenImages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 ilGetData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 ilGetError. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 ilInit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 ilLoad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 ilLoadF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 ilLoadImage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 ilLoadL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 ilOverlay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 ilSetData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 ilSetPixels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 ilTexImage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 iluActiveMipmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 iluAlienify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 iluBlurAverage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 iluBlurGaussian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 iluBuildMipmaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 iluContrast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 iluEqualize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 iluErrorString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 iluGammaCorrect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 iluImageParameter. . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 iluInit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 iluNegative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 iluNoisify. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 iluPixelize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 iluScale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 iluSharpen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23