DevIL_manual.info 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681
  1. This is DevIL_manual.info, produced by makeinfo version 4.11 from
  2. DevIL_manual.texi.
  3. This is `DevIL 1.7.8' manual. Last update is from 8 March 2009.
  4. Copyright (C) 2008,2009 Denton Woods, Matěj Týč
  5. Permission is granted to copy, distribute and/or modify this
  6. document under the terms of the GNU Free Documentation License, Version
  7. 1.3 or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  9. Texts. A copy of the license is included in the section entitled "GNU
  10. Free Documentation License".
  11. 
  12. File: DevIL_manual.info, Node: Top, Next: Introduction, Up: (dir)
  13. IL manual
  14. *********
  15. This is a manual describing IL part of `DevIL' - handling images.
  16. * Menu:
  17. * Introduction:: General intro
  18. * Basic usage:: How to write your first code
  19. * Image management:: How to manage images :-)
  20. * Error handling:: If you encounter an error...
  21. * Image manipulation:: How to manipulate with images using ILU
  22. * Common #defines:: #defines you are likely to come across when using DevIL
  23. * Sample program:: If you want to get going quickly
  24. * Functions index:: Index of IL and ILU functions
  25. 
  26. File: DevIL_manual.info, Node: Introduction, Next: Basic usage, Prev: Top, Up: Top
  27. 1 Introduction
  28. **************
  29. 1.1 General introduction
  30. ========================
  31. Developer's Image Library was previously called OpenIL, but due to
  32. trademark issues, `OpenIL' is now known as `DevIL'.
  33. `DevIL' is an Open Source programming library for programmers to
  34. incorporate into their own programs. `DevIL' loads and saves a large
  35. variety of images for use in a software developer's program. This
  36. library is capable of manipulating images in various ways and passing
  37. image information to display APIs, such as OpenGL and Direct3D.
  38. The purpose of this manual is to guide users in coding with the
  39. Developer's Image Library. This manual is for users proficient in C
  40. and with competent knowledge of the integrated development environment
  41. (IDE) or compiler they are using.
  42. 1.2 Library Reference
  43. =====================
  44. Several times throughout this document, the three different
  45. sub-libraries of `DevIL' are referenced as IL, ILU and ILUT. IL refers
  46. to the base library for loading, saving and converting images. ILU
  47. refers to the middle level library for image manipulation. ILUT refers
  48. to the high level library for displaying images. Functions in IL, ILU
  49. and ILUT are prefixed by ‘il', ‘ilu' and ‘ilut', respectively.
  50. 2 Library setup
  51. ***************
  52. 2.1 Microsoft Visual C++ setup
  53. ==============================
  54. `DevIL' setup for Windows is straightforward. Unzip `DevIL' in an
  55. empty directory. If using WinZip, check the "Use folder names" box
  56. before unzipping. Use the -d command line option if using pkunzip.
  57. Then double-click on the ImageLib.sln file in the install directory to
  58. load the `DevIL' workspace in Microsoft Visual C++ (MSVC++).
  59. 2.1.1 Directories
  60. -----------------
  61. You will need to change some directory settings in MSVC++ to get
  62. `DevIL' working.
  63. 1. Navigate to the Tools menu and select Options.
  64. 2. Click on the Directories tab.
  65. 3. Under Show directories for, select "Include files".
  66. 4. Click the New button (to the left of the red 'X')
  67. 5. Type the directory `DevIL' is installed in, plus `\Include'.
  68. For example, if you installed `DevIL' to E:\ImageLib, enter
  69. `E:\ImageLib\Include'. �[image src="images/devil_msvc_include.png"�]
  70. 6. Under Show directories for, click on "Library files".
  71. 7. Click the New button (to the left of the red 'X').
  72. 8. Type the directory `DevIL' is installed in, plus `\Lib'. For
  73. example, if you installed `DevIL' to E:\ImageLib, enter
  74. `E:\ImageLib\Lib'. �[image src="images/devil_msvc_lib.png"�]
  75. 9. Click the New button (to the left of the red ‘X').
  76. 10. Type the directory `DevIL' is installed in, plus `\Lib\Debug'.
  77. In the previous example, you would enter `E:\ImageLib\Lib\Debug'.
  78. 11. Choose OK.
  79. 2.1.2 MSVC++ Bug Workaround
  80. ---------------------------
  81. Microsoft Visual C++ 6.0 has a bug that prevents debugging of a project.
  82. The bug appears to occur when you use a #pragma to link a .lib file and
  83. link it via another method. The header files `il.h', `ilu.h' and
  84. `ilut.h' automatically link the .lib files in via a `#pragma' for
  85. convenience. To prevent this bug, check for and remove these:
  86. * `devil.lib', `devil-d.lib', `ilu.lib', `ilu-d.lib', `ilut.lib' and
  87. `ilut-d.lib' in your project settings (Project – Settings menu).
  88. * `devil.lib', `devil-d.lib', `ilu.lib', `ilu-d.lib', `ilut.lib' and
  89. `ilut-d.lib' in your project's workspace. Some people link
  90. libraries into their project this way, which really should be
  91. discouraged, due to the hardcoded paths.
  92. 2.1.3 Multithreading
  93. --------------------
  94. `DevIL' takes advantage of the multithreaded standard `LIBC' DLLs. To
  95. use file streams with `DevIL', you must change the project settings of
  96. your project. If you do not perform these steps, your program will
  97. crash whenever you attempt to use a `DevIL' file stream.
  98. Generally, `DevIL' is not thread safe. You should make sure that
  99. threads in your application do not use `DevIL' at the same time.
  100. 1. Navigate to the Project menu and choose Settings.
  101. 2. Click the C/C++ tab.
  102. 3. Change the Category drop-down menu to read Code Generation.
  103. 4. Change the Use run-time library drop-down menu to Multithreaded
  104. DLL if the Settings For menu says Win32 Release. Change the Use
  105. run-time library drop-down menu to Debug Multithreaded DLL if the
  106. Settings For menu says Win32 Debug.
  107. 5. Choose OK.
  108. 2.2 `DJGPP' Setup
  109. =================
  110. Setting up `DevIL' in DJGPP requires the following steps:
  111. 1. Unzip `DevIL' in an empty directory. If using WinZip, check the
  112. "Use folder names" box before unzipping. Use the -d command line
  113. option if using pkunzip.
  114. 2. Create a new subdirectory called ‘il' in your `DJGPP' include
  115. directory.
  116. 3. Copy the files to their respective places:
  117. * To use the precompiled libraries, copy `libil.a', `libilu.a'
  118. and `libilut.a' from ImageLib\lib\djgpp to your `DJGPP' lib
  119. directory. Then copy `il.h', `ilu.h' and `ilut.h' from your
  120. ImageLib\lib\il directory to your `DJGPP' include\il
  121. directory.
  122. * To compile the library yourself, change directories to
  123. ImageLib\Makefiles\Djgpp. This folder contains only a
  124. makefile for `DJGPP'. Simply type `make', and the makefile
  125. will compile `DevIL' and copy the files to their respective
  126. locations.
  127. To compile with `DevIL' in DJGPP, add `-lil' to your command line.
  128. To also use ILU and ILUT, use `-lilu' and `-lilut', respectively.
  129. 2.3 General GCC-based (Linux, Cygwin, Max OS X, etc.) Setup
  130. ===========================================================
  131. Setting up `DevIL' in this environment requires the following steps:
  132. 1. Unpack `DevIL' to your favourite build area: Typically this is
  133. done by running `tar -xvvf devil-xxx.tar.gz'
  134. 2. Go to the root devil directory and run `./configure
  135. <your-favourite options>'
  136. TIP: Typically, you will want to specify `--prefix=/usr' (where
  137. to install `DevIL'), `--enable-ILU' and/or `--enable-ILUT' and
  138. probably also `--with-examples'. Running `configure --help'
  139. gives you an exhaustive list of possibilities how to tweak `DevIL'
  140. build.
  141. 3. If no errors occured and you are satisfied with the configure
  142. report, you can compile it by running `make'
  143. TIP: You can run `make -j3' if you have a dual-core processor.
  144. Generally, if you replace the number '3' with 'number of CPU
  145. cores' + 1, you are likely to get the job done in the shortest
  146. time.
  147. 4. Run `make check' to check whether everything works as it should.
  148. *Note tests::, for hints what to do if a test fails.
  149. 5. Install `DevIL' by running `make install' as superuser.
  150. TIP: You can override variables at make time if you forgot to
  151. do that at configure time. For instance, you can install
  152. by `make install prefix=/usr'
  153. In order to link to `DevIL', you may use autotools with `libtool',
  154. which means to link either with `libIL.la' or `libILU.la' or with
  155. `libILUT.la' depending what level of functionality you require. You
  156. may decide to use a monolithic build of the library and you then link
  157. with `libDevIL.la'. The best way is to have this code in your
  158. `configure.ac' file:
  159. ...
  160. dnl Check for libtool (older macro for this is AC_PROG_LIBTOOL)
  161. LT_INIT
  162. ...
  163. # Check for libs we need for our program now
  164. dnl Check that we have the header
  165. AC_CHECK_HEADER([IL/il.h])
  166. dnl Check for the IL part on DevIL on unix-like systems
  167. PKG_CHECK_MODULES([DEVIL],
  168. [IL ILU ILUT])
  169. dnl Check that DevIL library exists (good for Windows)
  170. AC_CHECK_LIB([DevIL], [main], [LIBS_WE_NEED="-lDevIL $LIBS_WE_NEED"])
  171. ...
  172. dnl Now export the variable that contains libraries
  173. dnl so we can use it in makefiles
  174. AC_SUBST([LIBS_WE_NEED])
  175. AC_SUBST([DEVIL_CFLAGS DEVIL_LIBS])
  176. ...
  177. If you are skilled with automake, you may link with the libtool
  178. files directly, which is more portable (`pkg-config' currently breaks
  179. cross-compilation).
  180. If you use an IDE or if you don't like autotools (which is a big
  181. mistake, by the way :-), then you may use `pkg-config' as a program.
  182. This is not recommended if you intend to use `DevIL' in a
  183. cross-platform programs. You can get libraries you need to link to by
  184. running `pkg-config IL --libs'. Again, you decide whether you need
  185. `IL', `ILU' or `ILUT'. Also pass `pkg-config IL --cflags' to the
  186. compiler!
  187. If you are a happy IDE user, you have to write this commands in the
  188. backquotes like ``pkg-config ILUT --libs`' into some text boxes that
  189. allow you to specify additional `LDFLAGS'.
  190. 2.4 Test and examples
  191. =====================
  192. 2.4.1 Test suite
  193. ----------------
  194. `DevIL' now comes with a test suite. If you can use autotools to
  195. configure and compile it, you can also run the test suite by executing
  196. `make check' in the directory where you ran `configure'.
  197. There are following tests available:
  198. * Format test: An image is generated and saved to disc. It is
  199. loaded afterwards and compared to the original. If they are
  200. pretty much the same, the test is passed.
  201. * Format test 2 (coming soon): Some image formats can't be saved.
  202. So a test images are provided and loaded and compared.
  203. 2.4.2 Examples
  204. --------------
  205. `IL' examples:
  206. * Simple
  207. * Read
  208. * Override
  209. Note: Those examples can be linked against `ILU', but this is only
  210. because error report functions.
  211. `ILUT' examples:
  212. * Allegro
  213. * C++ wrapper
  214. * SDL
  215. * Volume
  216. * OpenGL
  217. 
  218. File: DevIL_manual.info, Node: Basic usage, Next: Image management, Prev: Introduction, Up: Top
  219. 3 Basic usage
  220. *************
  221. You must initialize `DevIL', or it will most certainly crash. You need
  222. to initialize each library (IL, ILU, and ILUT) separately. You do not
  223. need to initialize libraries you are not using, but keep in mind that
  224. the higher level libraries are dependent on the lower ones. For
  225. example, ILUT is dependent on ILU and IL, so you have to initialize IL
  226. and ILU as well.
  227. 3.1 Initializing DevIL
  228. ======================
  229. 3.1.1 IL Initialization
  230. -----------------------
  231. Simply call the `ilInit' function with no parameters:
  232. // Initialize IL
  233. ilInit();
  234. 3.1.2 ILU Initialization
  235. ------------------------
  236. Call the `iluInit' function with no parameters:
  237. // Initialize ILU
  238. iluInit();
  239. 3.1.3 ILUT Initialization
  240. -------------------------
  241. ILUT initialization is slightly more complex than IL and ILU
  242. initialization. The function you will use is `ilutRenderer'. You must
  243. call `ilutRenderer' before you use any ILUT functions. This function
  244. initializes ILUT support for the API you desire to use by a single
  245. parameter:
  246. * `ILUT_OPENGL' - Initializes ILUT's OpenGL support.
  247. * `ILUT_ALLEGRO' - Initializes ILUT's Allegro support.
  248. * `ILUT_WIN32' - Initializes ILUT's Windows GDI and DirectX 8
  249. support.
  250. An example of using `ilutRenderer' follows:
  251. // Initialize ILUT with OpenGL support.
  252. ilutRenderer(ILUT_OPENGL);
  253. 3.2 Image Name Handling
  254. =======================
  255. Image names are `DevIL''s way of keeping track of images it is
  256. currently containing. Some other image libraries return structs, but
  257. they generally seem more cluttered than `DevIL''s image name handling.
  258. ILvoid ilGenImages(ILsizei Num, ILuint *Images);
  259. ILvoid ilBindImage(ILuint Image);
  260. ILvoid ilDeleteImages(ILsizei Num, ILuint *Images);
  261. 3.2.1 Generating Image Names
  262. ----------------------------
  263. Use `ilGenImages' to generate a set of image names. `ilGenImages'
  264. accepts an array of ILuint to receive the generated image names. There
  265. are no guarantees about the order of the generated image names or any
  266. other predictable behaviour like this. If `ilDeleteImages' is called
  267. on an image name, `ilGenImages' will return that value afterward, until
  268. all deleted image names are used. This conserves memory and is
  269. generally quick. The only guarantee is that each member of the Images
  270. parameter (up to Num number of them) will have a new, unique value.
  271. 3.2.2 Binding Image Names
  272. -------------------------
  273. `ilBindImage' binds the current image to the image described by the
  274. image name in Image. `DevIL' reserves the number zero for the default
  275. base image. If you pass a value for Image that was not generated by
  276. `ilGenImages', `ilBindImage' automatically creates an image specified
  277. by the image name passed. An image must always be bound before you
  278. call any functions that operate on images and their data.
  279. When `DevIL' creates a new image, the image has the default
  280. properties of with a bit depth of 8. `DevIL' creates a new image when
  281. you call `ilBindImage' with an image name that has not been generated
  282. by `ilGenImages' or when you call `ilGenImages' specifically.
  283. 3.2.3 Deleting Image Names
  284. --------------------------
  285. `ilDeleteImages' is the exact opposite of `ilGenImages' and even
  286. accepts the exact same parameters. `ilDeleteImages' deletes image
  287. names to free memory for subsequent operations. You should always call
  288. `ilDeleteImages' on images that are not in use anymore. When you
  289. delete an image, `DevIL' actually deletes all data and anything
  290. associate with it, so that `ilGenImages' can possibly use the image
  291. name later.
  292. 3.3 File handling - loading images
  293. ==================================
  294. `DevIL''s main purpose is to load images. `DevIL''s loading is
  295. designed to be extremely easy but very powerful.
  296. *Note file_formats::, lists the image types `DevIL' is capable of
  297. loading.
  298. `DevIL' contains four loading functions to support different loading
  299. styles and loading from several different image sources.
  300. ILboolean ilLoadImage(const char *FileName);
  301. ILboolean ilLoad(ILenum Type, const char *FileName);
  302. ILboolean ilLoadF(ILenum Type, ILHANDLE File);
  303. ILboolean ilLoadL(ILenum Type, ILvoid *Lump, ILuint Size);
  304. 3.3.1 Loading from Files - `ilLoadImage'
  305. ----------------------------------------
  306. `ilLoadImage' is the main `DevIL' loading function. All you do is pass
  307. `ilLoadImage' the filename of the image you wish to load.
  308. `ilLoadImage' takes care of the rest. `ilLoadImage' allows users to
  309. transparently load several different image formats uniformly.
  310. `DevIL''s most powerful function is `ilLoadImage' because of this
  311. feature.
  312. Before loading the image, `ilLoadImage' must first determine the
  313. image format of the file. `ilLoadImage' performs the following steps:
  314. 1. Compares the filename's extension to any registered file handlers,
  315. allowing the registered file handlers to take precedence over the
  316. default `DevIL' file handlers. If the extension matches a
  317. registered file handler, `ilLoadImage' passes control to the file
  318. handler and returns. For more information on registering, refer
  319. to the section entitled (*note registration::).
  320. 2. Compares the filename's extension to the extensions natively
  321. supported by `DevIL'. If the extension matches a loading
  322. function's extension, `ilLoadImage' passes control to the file
  323. handler and returns.
  324. 3. Examines the file for a header and tries to match it with a known
  325. type of image header. If a valid image header is found,
  326. `ilLoadImage' passes control to the appropriate file hander and
  327. returns.
  328. 4. Returns `IL_FALSE'.
  329. 3.3.2 Loading from Files - `ilLoad'
  330. -----------------------------------
  331. `DevIL''s other file loading function is `ilLoad'. `ilLoad' is similar
  332. to `ilLoadImage' in many respects but different in other ways.
  333. `ilLoad' accepts two parameters: the type of image and the filename of
  334. the image.
  335. `ilLoad''s type parameter is what differentiates it from
  336. `ilLoadImage'. Type can be any of the values listed in table B-2 in
  337. appendix B or the value `IL_TYPE_UNKNOWN'. If Type is a value from
  338. table B-1, `ilLoad' attempts to load the file as the specified type of
  339. image format. Only use this if you know what type of images you will
  340. be loading and want to bypass `DevIL''s checks.
  341. If `IL_TYPE_UNKNOWN' is specified for Type, `ilLoad' behaves exactly
  342. like `ilLoadImage'. Refer to the previous section for detailed
  343. behaviour of these two functions.
  344. 3.3.3 Loading from File Streams - `ilLoadF'
  345. -------------------------------------------
  346. `DevIL''s file stream loading function is `ilLoadF'. `ilLoadF' is
  347. exactly equivalent to `ilLoad', but instead of accepting a const char
  348. pointer, `ilLoadF' accepts an `ILHANDLE'. `DevIL' defines `ILHANDLE'
  349. as a void pointer via a typedef. Under normal circumstances, File will
  350. be a `FILE' struct pointer defined in `stdio.h'.
  351. *Note registration::, for instructions on how to use your own file
  352. handling functions and file handles.
  353. 3.3.4 Loading from Memory Lumps - `ilLoadL'
  354. -------------------------------------------
  355. `DevIL''s file handling is abstracted to allow loading images from
  356. memory called "lumps". `ilLoadL' handles loading from lumps. You must
  357. specify a valid type as the first parameter and the lump as the second
  358. parameter.
  359. The third parameter that `ilLoadL' accepts is the total size of the
  360. lump. `DevIL' uses this value to perform bounds checking on the input
  361. data. Specify a value of zero for Size if you do not want `ilLoadL' to
  362. perform any bounds checking.
  363. 3.3.5 Saving to Files
  364. ---------------------
  365. `DevIL' also has some powerful saving functions to fully complement the
  366. loading functions.
  367. ILboolean ilSaveImage(const char *FileName);
  368. ILboolean ilSave(ILenum Type, const char *FileName);
  369. ILboolean ilSaveF(ILenum Type, ILHANDLE File);
  370. ILuint ilSaveL(ILenum Type, ILvoid *Lump, ILuint Size);
  371. `DevIL''s saving functions are identical to the loading functions,
  372. despite the fact that they save images instead of load images.
  373. Typically, the user does not know exactly how large the output image
  374. will be. If you pass `NULL' for `Lump' and 0 for `Size' to `ilSaveL',
  375. `ilSaveL' will return the buffer size needed to save an image of `Type'.
  376. When a buffer is passed for `Lump', the return value is how many bytes
  377. were written to the buffer.
  378. Note that not all formats that have load support have also save
  379. support (*note file_formats::)
  380. 
  381. File: DevIL_manual.info, Node: Image management, Next: Error handling, Prev: Basic usage, Up: Top
  382. 4 Image management
  383. ******************
  384. 4.1 Defining Images
  385. ===================
  386. `ilTexImage' is used to give the current bound image new attributes
  387. that you specify. Any image data or attributes previously in the
  388. current bound image are lost after a call to `ilTexImage', so make sure
  389. that you call it only after preserving the image data if need be.
  390. ILboolean ilTexImage(ILuint Width, ILuint Height, ILuint Depth,
  391. ILubyte Bpp, ILenum Format, ILenum Type, ILvoid *Data);
  392. `ilTexImage' has one of the longer parameter lists of the `DevIL'
  393. functions, so we will briefly go over what is expected for each
  394. argument.
  395. - `Width': The width of the image. If this is zero, `DevIL' creates
  396. an image with a width of one.
  397. - `Height': The height of the image. If this is zero, `DevIL'
  398. creates an image with a height of one.
  399. - `Depth': The depth of the image, if it is an image volume. Most
  400. applications should specify 0 or 1 for this parameter.
  401. - `Bpp': The bytes per pixel of the image data. Do not confuse this
  402. with bits per pixel, which is also commonly used. Common bytes
  403. per pixel values are 1, 3 and 4.
  404. - `Format': The format of the image data. *Note format #defines::,
  405. for what you can pass.
  406. - `Type': The type of image data. Usually, this will be
  407. `IL_UNSIGNED_BYTE', unless you want to utilize multiple bytes per
  408. colour channel. *Note type #defines::, for acceptable type.
  409. - `Data': Mainly for convenience, if you already have image data
  410. loaded and ready to put into the newly created image. Specifying
  411. `NULL' for this parameter just results in the image having
  412. unpredictable image data. You can specify image data later using
  413. `ilSetData' or `ilSetPixels'.
  414. 4.2 Getting image data
  415. ======================
  416. There are two ways to set image data: one is quick and dirty, while the
  417. other is more flexible but slower. These two functions are `ilGetData'
  418. and `ilCopyPixels'.
  419. ILubyte *ilGetData(ILvoid);
  420. ILuint ilCopyPixels(ILuint XOff, ILuint YOff, ILuint ZOff,
  421. ILuint Width, ILuint Height, ILuint Depth, ILenum Format,
  422. ILenum Type, ILvoid * Data);
  423. 4.2.1 The Quick Method
  424. ----------------------
  425. Use `ilGetData' to get a direct pointer to the current bound image's
  426. data pointer. Do not ever try to delete this pointer that is returned.
  427. To get information about the image data, use `ilGetInteger'.
  428. `ilGetData' will return `NULL' and set an error of
  429. `IL_ILLEGAL_OPERATION' if there is no currently bound image.
  430. 4.2.2 The Flexible Method
  431. -------------------------
  432. Use `ilCopyPixels' to get a portion of the current bound image's data
  433. or to get the current image's data with in a different format / type.
  434. `DevIL' takes care of all conversions automatically for you to give you
  435. the image data in the format or type that you need. The data block can
  436. range from a single line to a rectangle, all the way to a cube.
  437. `ilCopyPixels' has a long parameter list, like `ilTexImage', so here
  438. is a description of the parameters of `ilCopyPixels':
  439. - `XOff': Specifies where to start copying in the x direction.
  440. - `YOff': Specifies where to start copying in the y direction.
  441. - `ZOff': Specifies where to start copying in the z direction. This
  442. will be 0 in most cases, unless you are using image volumes.
  443. - `Width': Number of pixels to copy in the x direction.
  444. - `Height': Number of pixels to copy in the y direction.
  445. - `Depth': Number of pixels to copy in the z direction. This will
  446. be 1, unless
  447. - `Format, Type, Data': These are basically the same as ones
  448. described above. *note ilTexImage reference::.
  449. 4.3 Setting image Data
  450. ======================
  451. There are two ways to set image data: one is quick and dirty, while the
  452. other is more flexible but slower. These two functions are `ilSetData'
  453. and `ilSetPixels'.
  454. ILboolean ilSetData(ILvoid *Data);
  455. ILvoid ilSetPixels(ILuint XOff, ILuint YOff, ILuint ZOff,
  456. ILuint Width, ILuint Height, ILuint Depth, ILenum Format,
  457. ILenum Type, ILvoid *Data);
  458. 4.3.1 The Quick Method
  459. ----------------------
  460. Use `ilSetData' to set the image data directly. `DevIL' will copy the
  461. data provided in the Data parameter to the image’s data, so you need
  462. not worry about `DevIL' trying to delete your pointer later on. This
  463. function is the counterpart to `ilGetData'.
  464. You must provide image data in the exact same format, type, width,
  465. height, depth and bpp as the current bound image, since `DevIL' does no
  466. conversions here; it just does a simple memory copy.
  467. `ilSetData' will return `IL_FALSE' and set an error of
  468. `IL_INVALID_PARAM' if Data is `NULL'.
  469. 4.3.2 The Flexible Method
  470. -------------------------
  471. Use `ilSetPixels' to set a portion of the current bound image’s data or
  472. to set the current image’s data with data of a different format / type.
  473. Specify the data block, where you want to put it and what kind of data
  474. it is, and `DevIL' takes care of all conversions automatically for you.
  475. The data block can range from a single line to a rectangle, all the way
  476. to a cube.
  477. `ilSetPixels' has a long parameter list, like `ilCopyPixels', so
  478. here is a description of the parameters of `ilSetPixels':
  479. - Previous parameters are the same as in `ilTexImage'
  480. - `Data': A pointer to the actual data block. If this is `NULL',
  481. `DevIL' will set an error of `IL_INVALID_PARAM' and return
  482. `IL_FALSE' (please refer to the section on error handling in
  483. `DevIL').
  484. If you specify a combination of an offset with a width/height/depth
  485. that makes your data block overreach the edge of the currently bound
  486. image, `DevIL' will clip your data so that no crashes will occur and
  487. that the resulting image will be correctly produced.
  488. 4.4 Copying Images
  489. ==================
  490. `DevIL' has three functions to copy images: `ilCopyImage',
  491. `ilOverlayImage' and `ilBlit'.
  492. ILboolean ilCopyImage(ILuint Src);
  493. ILboolean ilOverlayImage(ILuint Src, ILint XCoord, ILint YCoord,
  494. ILint ZCoord);
  495. ILboolean ilBlit(ILuint Src, ILint DestX, ILint DestY, ILint DestZ,
  496. ILuint SrcX, ILuint SrcY, ILuint SrcZ, ILuint Width,
  497. ILuint Height, ILuint Depth);
  498. 4.4.1 Direct Copying
  499. --------------------
  500. Use `ilCopyImage' to create a copy of an image. `ilCopyImage' will
  501. copy the image specified by the image name in Src to the currently
  502. bound image. `ilCopyImage' can be useful when you want to apply an
  503. effect to an image but want to preserve the original. The image bound
  504. before calling `ilCopyImage' will still be bound after `ilCopyImage'
  505. exits.
  506. If you specify an image name in Src that has not been generated by
  507. `ilGenImages' or `ilBindImage', `ilCopyImage' will set the
  508. `IL_INVALID_PARAM' error and return `IL_FALSE'.
  509. 4.4.2 Blitting
  510. --------------
  511. `ilBlit' copies a portion of an image over to another image. This is
  512. similar to blitting performed in graphics libraries, such as StretchBlt
  513. in the Windows API. You can copy a rectangular block from anywhere in
  514. a source image, specified by Src, to any point in the currently bound
  515. image. A description of the various `ilBlit' parameters follows:
  516. - `Src': The source image name.
  517. - `DestX': Specifies where to place the block of image data in the x
  518. direction.
  519. - `DestY': Specifies where to place the block of image data in the y
  520. direction.
  521. - `DestZ': Specifies where to place the block of image data in the z
  522. direction.
  523. - `SrcX': Specifies where to start copying in the x direction of the
  524. source image.
  525. - `SrcY': Specifies where to start copying in the y direction of the
  526. source image.
  527. - `SrcZ': Specifies where to start copying in the z direction of the
  528. source image.
  529. - `Width': How many pixels to copy in the x direction of the source
  530. image.
  531. - `Height': How many pixels to copy in the y direction of the source
  532. image.
  533. - `Depth': How many pixels to copy in the z direction of the source
  534. image.
  535. 4.4.3 Overlaying
  536. ----------------
  537. `ilOverlay' is essentially the same as `ilBlit', but it copies the
  538. entire image over, instead of just a portion of the image. `ilOverlay'
  539. is more of a convenience function, since you can obtain the same
  540. results by calling `ilBlit' with SrcX, SrcY and SrcZ set to zero, with
  541. the Width, Height and Depth parameters set to the source image's
  542. height, width and depth, respectively. `ilOverlay' is missing six
  543. parameters that `ilBlit' has:
  544. - `Src': The source image name.
  545. - `DestX': Specifies where to place the block of image data in the x
  546. direction.
  547. - `DestY': Specifies where to place the block of image data in the y
  548. direction.
  549. - `DestZ': Specifies where to place the block of image data in the z
  550. direction.
  551. 4.4.4 Blit/Overlay Behavior
  552. ---------------------------
  553. By default, `ilBlit' and `ilOverlay' will blend the source with the
  554. destination image if the source has an alpha channel present. If you
  555. need to blit the image without blending, you can use the
  556. `IL_BLIT_BLEND' #define. This behavior can be toggled with `ilEnable'
  557. and `ilDisable'.
  558. ilDisable(IL_BLIT_BLEND); // Turns off blending
  559. ilEnable(IL_BLIT_BLEND); // Turns on blending
  560. 5 Image Characteristics
  561. ***********************
  562. All images have a certain set of characteristics: origin of the image,
  563. format of the image, type of the image, and more.
  564. 5.1 Origin
  565. ==========
  566. Depending on the file format, data can start in the upper left or the
  567. lower left corner of the image. By default, `DevIL' keeps the origin
  568. in the same place as the original image. This can cause your image to
  569. be flipped vertically if the image you are loading has an origin other
  570. than what you expect. To obtain the origin of the image, use
  571. `ilGetInteger'.
  572. ilGetInteger(IL_IMAGE_ORIGIN);
  573. To force `DevIL' to use just one origin, you need to use the
  574. following code:
  575. ilEnable(IL_ORIGIN_SET);
  576. ilSetInteger(_Origin_);
  577. _Origin_ is either `IL_ORIGIN_LOWER_LEFT' or `IL_ORIGIN_UPPER_LEFT'.
  578. Finally, if you need to find out which origin mode is currently set,
  579. use:
  580. ilGetInteger(IL_ORIGIN_MODE);
  581. 5.2 Format
  582. ==========
  583. Format refers to the ordering of the bytes for each pixel.
  584. 5.3 Registration
  585. ================
  586. 
  587. File: DevIL_manual.info, Node: Error handling, Next: Image manipulation, Prev: Image management, Up: Top
  588. 6 Error handling
  589. ****************
  590. `DevIL' contains error-handling routines to alert the users of this
  591. library to any internal problems in `DevIL'. The `ilGetError' function
  592. reports all errors in `DevIL'. `iluErrorString' converts error numbers
  593. returned from `ilGetError' to a human-readable format.
  594. ILenum ilGetError(ILvoid);
  595. const char* iluErrorString(ILenum Error);
  596. 6.1 Error Detection
  597. ===================
  598. Problems can always occur in any software application, and `DevIL' is
  599. no different. `DevIL' keeps track of all non-fatal errors that have
  600. occurred during its operation. All errors are kept on a stack
  601. maintained by `ilGetError'. Every time `ilGetError' is called, the
  602. last error is returned and pushed off the top of the stack. You should
  603. call `ilGetError' until `IL_NO_ERROR' is returned. `IL_NO_ERROR'
  604. signifies that there are no more errors on the error stack. Most
  605. errors reported are not harmful, and `DevIL' operation can continue,
  606. except for `IL_OUT_OF_MEMORY'.
  607. *Note error_codes::, for error codes that can be returned by
  608. `ilGetError'.
  609. 6.2 Error Strings
  610. =================
  611. `iluErrorString' returns a human readable error string from any error
  612. that `ilGetError' can return. This is useful for when you want to
  613. display what kind of error happened to the user.
  614. 6.2.1 Languages
  615. ---------------
  616. The ILU error messages have been translated into multiple languages:
  617. Arabic, Dutch, German, Japanese and Spanish. The default language is
  618. English.
  619. 6.2.2 Selecting a Language
  620. --------------------------
  621. `iluSetLanguage' will change the error string returned by
  622. `iluErrorString' to the language specified in its parameter. Languages
  623. supported are: English, Arabic, Dutch, German, Japanese and Spanish.
  624. *Note language #defines::, for a list of possible values.
  625. Be aware that if the Unicode version of `DevIL' is not being used,
  626. some translations will not display properly. An example is Arabic,
  627. which uses characters outside of the standard ASCII character set.
  628. 
  629. File: DevIL_manual.info, Node: Image manipulation, Next: Common #defines, Prev: Error handling, Up: Top
  630. 7 Image manipulation
  631. ********************
  632. ILU (Image Library Utilities) contains functions to manipulate any type
  633. of image in a variety of ways. Some functions filter images, while
  634. others perform a wider variety of operations, such as scaling an image.
  635. This section will give a comparison of the utility functions against
  636. the below figure.
  637. �[image src="images/original_stairway.jpg"�]
  638. Figure 7.1: Original, unmodified image
  639. This is a crop of a Bertrand Benoit's image taken from Blender art
  640. gallery (http://www.blender.org/features-gallery/gallery/art-gallery/),
  641. and Bertrand has kindly allowed us to use it for demonstrations. You
  642. can check out his website (http://www.bertrand-benoit.com). Thank you,
  643. Bertrand!
  644. The image samples here have a better-than-bad resolution, so you
  645. don't have to be afraid to zoom at them if you wish to see details.
  646. 7.1 Alienifying
  647. ===============
  648. `iluAlienify' is a filter I created purely by accident, when I was
  649. attempting to write colour matrix code. The effect `iluAlienify' gives
  650. to an image is a green and purple tint. On images with humans in them,
  651. `iluAlienify' generally makes the people look green, hence the
  652. fabricated term "alienify". `iluAlienify' does not accept any
  653. parameters. The figure below illustrates this effect on the `DevIL'
  654. logo.
  655. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_alienify.jpg"�]
  656. Figure 7.2: Original and "alienified" image
  657. 7.2 Blurring
  658. ============
  659. ILU has two blurring functions – `iluBlurAverage' and
  660. `iluBlurGaussian'. Blurring can be used for a simple motion blur
  661. effect or something as sophisticated as concealing the identity of a
  662. person in an image. Both of these functions use a convolution filter
  663. and multiple iterations to blur an image. Gaussian blurs look more
  664. natural than averaging blurs, because the center pixel in the
  665. convolution filter "weighs" more. For an in-depth description of
  666. convolution filters, see the excellent _Elementary Digital Filtering_
  667. article at gamedev.net
  668. (http://www.gamedev.net/reference/programming/features/edf/).
  669. `iluBlurAverage' and `iluBlurGaussian' are functionally equivalent.
  670. Both functions accept a single parameter. Call the desired function
  671. with the number of iterations of blurring you wish to be performed on
  672. the image. Increase the number of iterations to increase the
  673. blurriness of an image.
  674. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_blurAvg_10.jpg"�] �[image src="images/ilu_small_stairway_blurGaussian_10.jpg"�]
  675. Figure 7.3: Original image, average blurred and gaussian blurred, both
  676. with 10 iterations applied
  677. 7.3 Contrast
  678. ============
  679. ILU can apply more colour contrast to your image by brightening the
  680. lights and darkening the darks via `iluContrast'. This effect can make
  681. a dull image livelier and "stand out" more.
  682. `iluContrast' accepts a single parameter describing the desired
  683. amount of contrast to modify the image by.
  684. * values from 0.0 to 1.0 decrease the amount of contrast in the
  685. image.
  686. * value of 1.0 does not affect the image.
  687. * values above 1.0 to 1.7 increase the amount of contrast in the
  688. image, with 1.7 increasing the contrast the most.
  689. * values outside of the 0.0 to 1.7 range will give undefined
  690. results. -0.5 to 0.0 will actually create a negative of the image
  691. and increase the contrast.
  692. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_contrast_0.4.jpg"�] �[image src="images/ilu_small_stairway_contrast_1.7.jpg"�]
  693. Figure 7.4: Original image, image with contrast of 0.4 and with
  694. contrast of 1.7
  695. 7.4 Equalization
  696. ================
  697. Sometimes it may be useful to equalize an image – that is, bring the
  698. extreme colour values to a median point. `iluEqualize' darkens the
  699. bright colours and lightens the dark colours, reducing the contrast in
  700. an image or "equalizing" it. The below figure shows the results of
  701. applying `iluEqualize' to the `DevIL' image.
  702. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_equalize.jpg"�]
  703. Figure 7.5: Original image and equalized image
  704. 7.5 Gamma Correction
  705. ====================
  706. `iluGammaCorrect' applies gamma correction to an image using an
  707. exponential curve. The single parameter `iluGammaCorrect' accepts is
  708. the gamma correction factor you wish to use. A gamma correction factor
  709. of 1.0 leaves the image unmodified. Values in the range `0.0 - 1.0'
  710. darken the image. 0.0 leaves a totally black image. Anything above
  711. 1.0 brightens the image, but values too large may saturate the image.
  712. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_gammaCorrect_0.7.jpg"�] �[image src="images/ilu_small_stairway_gammaCorrect_1.6.jpg"�]
  713. Figure 7.6: Original image, image with gamma 0.7 and with with gamma 1.6
  714. 7.6 Negativity
  715. ==============
  716. `iluNegative' is a very basic function that inverts every pixel's
  717. colour in an image. For example, pure white becomes pure black, and
  718. vice-versa. The resulting colour of a pixel can be determined by this
  719. formula: `new_colour = ~old_colour' (where the tilde is the negation of
  720. the set of bits). `iluNegative' does not accept any parameters and is
  721. reversible by calling it again.
  722. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_negative.jpg"�]
  723. Figure 7.7: Original and negative image
  724. 7.7 Noise
  725. =========
  726. ILU can add "random" noise to any image to make it appear noisy. The
  727. function, `iluNoisify', simply uses the standard libc `rand' function
  728. after initializing it with a seed to `srand'. If your program depends
  729. on a different seed to `rand', reset it after calling `iluNoisify'.
  730. The seed ILU uses is the standard `time(NULL)' call. Of course, the
  731. noise added to the image is not totally random, since no such thing
  732. exists, but there should be no repeating, except in extremely large
  733. images.
  734. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_noisify_0.1.jpg"�] �[image src="images/ilu_small_stairway_noisify_0.8.jpg"�]
  735. Figure 7.8: Original image, noisified image 0.1, noisified 0.8
  736. `iluNoisify' accepts a single parameter – the tolerance to use.
  737. This parameter is a clamped (float) value that should be in the range
  738. `0.0f - 1.0f'. Lower values indicate a lower tolerance, while higher
  739. values indicate the opposite. The tolerance indicates just how much of
  740. a mono intensity that `iluNoisify' is allowed to apply to each pixel.
  741. A "random" mono intensity is applied to each pixel so that you will not
  742. end up with totally new colours, just the same colours with a different
  743. luminance value. Colours change by both negative and positive values,
  744. so some pixels may be darker, some may be lighter, and others will
  745. remain the same.
  746. 7.8 Pixelization
  747. ================
  748. `iluPixelize' creates pixelized images by averaging the colour values
  749. of blocks of pixels. The single parameter passed to `iluPixelize'
  750. determines the size of these square blocks. The result is a pixelized
  751. image.
  752. Call `iluPixelize' with values greater than 1 to pixelize the image.
  753. The larger the values, the larger the pixel blocks will be. A value of
  754. 1 will leave the image unchanged. Values less than 1 generate an error.
  755. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_pixelize_5.jpg"�]
  756. Figure 7.9: Pixelization of 5 pixels across
  757. 7.9 Sharpening
  758. ==============
  759. Sharpening sharply defines the outlines in an image. `iluSharpen'
  760. performs this sharpening effect on an image. `iluSharpen' accepts two
  761. parameters: the sharpening factor and the number of iterations to
  762. perform the sharpening effect.
  763. The sharpening factor must be in the range of 0.0 - 2.5.
  764. * values from 0.0 to 1.0 do a type of reverse sharpening, blurring
  765. the image.
  766. * value of 1.0 for the sharpening factor will have no effect on the
  767. image.
  768. * values in the range 1.0 - 2.5 will sharpen the image, with 2.5
  769. having the most pronounced sharpening effect.
  770. * values outside of the 0.0 - 2.5 range produce undefined results.
  771. The number of iterations to perform will usually be 1, but to
  772. achieve more sharpening, increase the number of iterations. This
  773. parameter is similar to the _Iterations_ parameter of the two blurring
  774. functions. The time it takes to run this function is directly
  775. proportional to the number of iterations desired.
  776. �[image src="images/small_stairway.jpg"�] �[image src="images/ilu_small_stairway_sharpen_1.8_2.jpg"�] �[image src="images/ilu_small_stairway_sharpen_2.1_3.jpg"�]
  777. Figure 7.10: Original image, image sharpened by 1.8 in 2 iterations and
  778. sharpened by 2.1 in 3 iterations
  779. 8 Resizing Images
  780. *****************
  781. 8.1 Basic Scaling
  782. =================
  783. To resize images, use the `iluScale' function:
  784. ILboolean iluScale(ILuint Width, ILuint Height, ILuint Depth);
  785. The three parameters are relatively explanatory. Any image can be
  786. resized to a new width, height and depth, provided that you have enough
  787. memory to hold the new image. The new dimensions do not have to be the
  788. same as the original in any way. Aspect ratios of the image do not
  789. even have to be the same. The currently bound image is replaced
  790. entirely by the new scaled image.
  791. If you specify a dimension greater than the original dimension, the
  792. image enlarges in that direction. Alternately, if you specify a
  793. dimension smaller than the original dimension, the image shrinks in
  794. that direction.
  795. 8.2 Advanced Scaling
  796. ====================
  797. ILU also allows you to specify which method you want to use to resize
  798. images. As you can see in the middle figure above, the enlarged image
  799. is very pixelized. The shrunk image is also blocky. This is because a
  800. nearest filter was applied to the image in figure 5.1 to produce
  801. figures 5.2 and 5.3.
  802. ILU allows you to use different filters to produce better scaling
  803. results via `iluImageParameter':
  804. * Nearest filter - `ILU_NEAREST'
  805. * Linear filter - `ILU_LINEAR'
  806. * Bilinear filter - `ILU_BILINEAR'
  807. * Box filter - `ILU_SCALE_BOX'
  808. * Triangle filter - `ILU_SCALE_TRIANGLE'
  809. * Bell filter - `ILU_SCALE_BELL'
  810. * B Spline filter - `ILU_SCALE_BSPLINE'
  811. * Lanczos filter - `ILU_SCALE_LANCZOS3'
  812. * Mitchell filter - `ILU_SCALE_MITCHELL'
  813. Just use the `ILU_FILTER' define as _PName_ in `iluImageParameter'
  814. with the appropriate filter define as _Param_.
  815. ILvoid iluImageParameter(ILenum PName, ILenum Param);
  816. 8.3 Filter Comparisons
  817. ======================
  818. The first three filters (nearest, linear and bilinear) require an
  819. increasing amount of time to resize an image, with nearest being the
  820. quickest and bilinear being the slowest of the three. All the filters
  821. after bilinear are considered the “advanced” scaling functions and
  822. require much more time to complete, but they generally produce much
  823. nicer results.
  824. When minimizing an image, bilinear filtering should be sufficient,
  825. since it uses a four-pixel averaging scheme to create every destination
  826. pixel. Minimized images do not generally have to use higher sampling
  827. schemes to achieve a reasonable image.
  828. Enlarging an image, though, depends quite heavily on how good the
  829. sampling scheme is. ILU provides several filtering functions to let
  830. you choose which one best fits your needs: speed versus image quality.
  831. Below is a comparison of the different types of filters when enlarging
  832. an image.
  833. 9 Sub-Images
  834. ************
  835. 9.1 Mipmaps
  836. ===========
  837. Mipmaps in `DevIL' are successive half-dimensioned power-of-2 images.
  838. The dimensions do not have to be powers of 2 if you generate them
  839. manually, but `DevIL''s mipmap generation facilities assume power-of-2
  840. images.
  841. _All mipmap levels down to 1x1_
  842. 9.1.1 Mipmap Creation
  843. ---------------------
  844. You generate mipmaps for any image using `iluBuildMipmaps'. If the
  845. image already has mipmaps, the previous mipmaps are erased, and new
  846. mipmaps are generated. Otherwise, `iluBuildMipmaps' generates mipmaps
  847. for the image.
  848. The mipmaps built are always powers of 2. If the original image
  849. does not have power-of-2 dimensions, `iluBuildMipmaps' resizes the
  850. original image via `iluScale' to have power-of-2 dimensions.
  851. 9.1.2 Mipmap Access
  852. -------------------
  853. Access mipmaps through the `iluActiveMipmap' function:
  854. ILboolean ilActiveMipmap(ILuint MipNum);
  855. `iluActiveMipmap' sets the current image to the _MipNum_ mipmap
  856. level of the current image. If there are no mipmaps present, then
  857. `iluActiveMipmap' returns `IL_FALSE', else it returns `IL_TRUE'. The
  858. base image is mipmap level 0, so specify 0 for _MipNum_ to return to
  859. the base image. The only other method for setting the current image to
  860. the base image is to call `ilBindImage' again.
  861. 9.2 Animations
  862. ==============
  863. Animations are similar to mipmaps, but instead of being smaller
  864. successive images, the images are the same size but have different data.
  865. The successive animation chains in `DevIL' can be used to create
  866. animations in your programs. File formats that natively support
  867. animations are `.gif' and `.mng'. You can also create your own
  868. sub-images as animations.
  869. 9.2.1 Animation Chain Creation
  870. ------------------------------
  871. To be added...
  872. 9.2.2 Animation Chain Access
  873. ----------------------------
  874. Access animations through the `iluActiveImage' function:
  875. ILboolean ilActiveImage(ILuint ImageNum);
  876. `iluActiveImage' sets the current image to the _ImageNum_ animation
  877. frame of the current image. If there are no animation frames present,
  878. then `iluActiveImage' returns `IL_FALSE', else it returns `IL_TRUE'.
  879. The base image is animation frame 0, so specify 0 for _ImageNum_ to
  880. return to the base image. The only other method for setting the
  881. current image to the base image is to call `ilBindImage' again.
  882. `iluActiveImage' is functionally equivalent to `iluActiveMipmap',
  883. except that it deals with animations and not mipmaps.
  884. 9.3 Layers
  885. ==========
  886. `DevIL' does not have a full layer implementation yet.
  887. 9.4 Sub-Image Mixing
  888. ====================
  889. An image can have both mipmaps and animations at the same time. Every
  890. image in an animation chain can have its own set of mipmaps, though it
  891. is not necessary by any means. If you "activate" an animation image in
  892. the base image's animation chain, the active image becomes the new
  893. "base" image. Therefore, if you call `iluActiveMipmap' after
  894. `iluActiveImage', a mipmap from the selected image in the animation
  895. chain is chosen.
  896. 10 DXTC/S3TC Notes
  897. ******************
  898. 10.1 DDS Loading/Saving
  899. =======================
  900. `DevIL' supports loading and saving of Microsoft .dds files. DDS files
  901. can either be compressed or uncompressed. If they are compressed, DDS
  902. files use DirectX Texture Compression (DXTC). DXTC is also known as
  903. S3TC, since Microsoft licensed the compression technology from S3.
  904. 10.1.1 Keeping DXTC Data
  905. ------------------------
  906. When loading, `DevIL' uncompresses the DXTC. If you call `ilEnable'
  907. with the `IL_KEEP_DXTC_DATA' parameter, `DevIL' will keep an
  908. uncompressed copy of the DXTC data along with the image. Functions
  909. that deal with DXTC data can use this data without having to recompress
  910. the uncompressed data, making these functions operate faster. The only
  911. drawback is the use of more memory.
  912. 10.1.2 Controlling Saving
  913. -------------------------
  914. `DevIL''s DXTC support consists of three different compression formats:
  915. DXT1, DXT3 and DXT5. DXT2 and DXT4 use premultiplied alpha, which not
  916. even OpenGL supports. `DevIL' loads DXT2 and DXT4 textures but
  917. immediately converts them to formats that do not use premultiplied
  918. alpha. To set what format to save DDS files in, use this line:
  919. ilSetInteger(IL_DXTC_FORMAT, Format);
  920. _Format_ can be `IL_DXT1', `IL_DXT3' or `IL_DXT5'.
  921. 10.1.3 Compression Method
  922. -------------------------
  923. `DevIL' can use the nVidia Texture Tools (NVTT) library, the libsquish
  924. library and its own internal compressor to generate DXTC data. By
  925. default, `DevIL' uses its internal compressor. This compressor is fast
  926. but is not very high quality. NVTT is usually CUDA-enabled, meaning
  927. that it can run quickly on computers with GeForce 8-series and higher
  928. cards. libsquish generates images with the highest quality possible,
  929. but it can be very slow.
  930. To enable compression by NVTT or libsquish, use one of the following
  931. lines of code:
  932. ilEnable(IL_NVIDIA_COMPRESS);
  933. ilEnable(IL_SQUISH_COMPRESS);
  934. You can also disable compression by these libraries by using
  935. `ilDisable'. If both are enabled, NVTT is used.
  936. 10.2 Retrieving DXTC Data
  937. =========================
  938. To retrieve a copy of the DXTC data, use `ilGetDXTCData'. To determine
  939. how large Buffer should be, first call `ilGetDXTCData' with the Buffer
  940. parameter as `NULL'. This function will then return the number of
  941. bytes that are required to completely store the DXTC data. Call it a
  942. second time to actually retrieve the data.
  943. ILuint ilGetDXTCData(ILvoid *Buffer, ILuint BufferSize,
  944. ILenum DXTCFormat);
  945. If the DXTC data does not exist in the format that you request,
  946. `DevIL' will automatically compress the data. If `ilGetDXTCData'
  947. returns 0, then the data could not be compressed. To see if a certain
  948. format of DXTC data already exists for the currently bound image, call
  949. `ilGetInteger' with the `IL_DXTC_DATA_FORMAT' parameter.
  950. 10.3 Compressing DXTC Data
  951. ==========================
  952. In the previous section, it was mentioned that `DevIL' can compress the
  953. data of an image with DXT compression. If you have image data in your
  954. program that you want to compress, you can use the `ilCompressDXT'
  955. function.
  956. ILubyte *ilCompressDXT(ILubyte *Data, ILuint Width, ILuint Height,
  957. ILuint Depth, ILenum DXTCFormat, ILuint *DXTCSize);
  958. Data must be in BGRA format for NVTT and `DevIL''s compressor, and
  959. it must be in RGBA format for libsquish. Please keep this in mind when
  960. calling this `ilCompressDXT'. Look at Compression Method in this
  961. section for information on how to use these libraries.
  962. 10.4 OpenGL/Direct3D DXTC Support
  963. =================================
  964. ILUT allows you to directly send the DXTC data to OpenGL or Direct3D.
  965. Several modes in ILUT directly control this behavior.
  966. 10.4.1 OpenGL S3TC Support
  967. --------------------------
  968. OpenGL can use S3TC (DXTC) textures via extensions. If a computer does
  969. not support the S3TC texture extension, `DevIL' will just send the data
  970. normally through `glTexImage2D', as always. Please keep in mind that
  971. DDS files store their data in a top-down format, so if you enable the
  972. OpenGL S3TC support, make certain to set the origins of all images in
  973. the upper left:
  974. ilEnable(IL_ORIGIN_SET);
  975. ilSetInteger(IL_ORIGIN_MODE, IL_ORIGIN_UPPER_LEFT);
  976. To enable the OpenGL S3TC support, use the `ilutEnable' function
  977. with the `ILUT_GL_USE_S3TC' parameter:
  978. ilutEnable(ILUT_GL_USE_S3TC);
  979. Setting this parameter means that ILUT will only use DXTC data from
  980. images that are already compressed with DXTC (e.g. DDS files). To
  981. force ILUT to compress any image it sends to OpenGL, use `ilutEnable'
  982. again:
  983. ilutEnable(ILUT_GL_GEN_S3TC);
  984. This can adversely affect your performance while loading textures,
  985. though, so use it with caution, especially if you are running a
  986. performance-critical application.
  987. 10.4.2 Direct3D DXTC Support
  988. ----------------------------
  989. ILUT's Direct3D (D3D) support works exactly like the OpenGL support,
  990. except you use the `ILUT_D3D_USE_DXTC' and `ILUT_D3D_GEN_DXTC' defines
  991. instead of `ILUT_GL_USE_S3TC' and `ILUT_GL_GEN_S3TC', respectively.
  992. 
  993. File: DevIL_manual.info, Node: Common #defines, Next: Sample program, Prev: Image manipulation, Up: Top
  994. Appendix A Common `DevIL' `#defines'
  995. ************************************
  996. Here goes lists of `DevIL' `#defines' used in functions that manipulate
  997. image data. As you can see, they are self-explanatory.
  998. A.1 `format'-related `#defines'
  999. ===============================
  1000. `IL_COLOUR_INDEX'
  1001. `IL_RGB'
  1002. `IL_RGBA'
  1003. `IL_BGR'
  1004. `IL_BGRA'
  1005. `IL_LUMINANCE'
  1006. A.2 `type'-related `#defines'
  1007. =============================
  1008. `IL_BYTE'
  1009. `IL_UNSIGNED_BYTE'
  1010. `IL_SHORT'
  1011. `IL_UNSIGNED_SHORT'
  1012. `IL_INT'
  1013. `IL_UNSIGNED_INT'
  1014. `IL_FLOAT'
  1015. `IL_DOUBLE'
  1016. A.3 Language-related `#defines'
  1017. ===============================
  1018. `IL_ENGLISH'
  1019. `IL_ARABIC'
  1020. `IL_DUTCH'
  1021. `IL_GERMAN'
  1022. `IL_JAPANESE'
  1023. `IL_SPANISH'
  1024. Appendix B Common `DevIL' Error Codes
  1025. *************************************
  1026. Errors sometimes occur within `DevIL'. To get the error code of the
  1027. last error that occurred, call `ilGetError' with no parameters. To get
  1028. a human-readable string of an error code, call `iluErrorString' with
  1029. the error code. A table of error codes follows:
  1030. Error code `#define' Hex Decimal
  1031. value value
  1032. -----------------------------------------
  1033. `IL_NO_ERROR' `0x000' `0'
  1034. `IL_INVALID_ENUM' `0x501' `1281'
  1035. `IL_OUT_OF_MEMORY' `0x502' `1282'
  1036. `IL_FORMAT_NOT_SUPPORTED' `0x503' `1283'
  1037. `IL_INTERNAL_ERROR' `0x504' `1284'
  1038. `IL_INVALID_VALUE' `0x505' `1285'
  1039. `IL_ILLEGAL_OPERATION' `0x506' `1286'
  1040. `IL_ILLEGAL_FILE_VALUE' `0x507' `1287'
  1041. `IL_INVALID_FILE_HEADER' `0x508' `1288'
  1042. `IL_INVALID_PARAM' `0x509' `1289'
  1043. `IL_COULD_NOT_OPEN_FILE' `0x50A' `1290'
  1044. `IL_INVALID_EXTENSION' `0x50B' `1291'
  1045. `IL_FILE_ALREADY_EXISTS' `0x50C' `1292'
  1046. `IL_OUT_FORMAT_SAME' `0x50D' `1293'
  1047. `IL_STACK_OVERFLOW' `0x50E' `1294'
  1048. `IL_STACK_UNDERFLOW' `0x50F' `1295'
  1049. `IL_INVALID_CONVERSION' `0x510' `1296'
  1050. `IL_BAD_DIMENSIONS' `0x511' `1297'
  1051. `IL_FILE_READ_ERROR' `0x512' `1298'
  1052. `IL_LIB_JPEG_ERROR' `0x5E2' `1506'
  1053. `IL_LIB_PNG_ERROR' `0x5E3' `1507'
  1054. `IL_LIB_TIFF_ERROR' `0x5E4' `1508'
  1055. `IL_LIB_MNG_ERROR' `0x5E5' `1509'
  1056. `IL_LIB_JP2_ERROR' `0x5E6' `1510'
  1057. `IL_LIB_EXR_ERROR' `0x5E7' `1511'
  1058. `IL_UNKNOWN_ERROR' `0x5FF' `1535'
  1059. Appendix C Supported File Formats
  1060. *********************************
  1061. `DevIL' supports loading and saving of a large number of image formats.
  1062. Table lists the formats `DevIL' supports sorted according to `#define'.
  1063. Format name Extension IL `#define' Loading? Saving?
  1064. ---------------------------------------------------------------------------------
  1065. Blizzard texture .blp `IL_BLP' yes no
  1066. Windows bitmap .bmp `IL_BMP' yes yes
  1067. C-style header .h `IL_CHED' no yes
  1068. Dr. Halo Cut File .cut `IL_CUT' yes no
  1069. ZSoft Multi-PCX .dcx `IL_DCX' yes no
  1070. Digital Imaging and .dicom, .dcm `IL_DCM' yes no
  1071. Communications in Medicine
  1072. DirectDraw surface .dds `IL_DDS' yes yes
  1073. Digital Picture Exchange .dpx `IL_DPX' yes no
  1074. DOOM walls/flats .lmp `IL_DOOM', yes no
  1075. `IL_DOOM_FLAT'
  1076. OpenEXR .exr `IL_EXR' yes yes
  1077. Flexible Image Transport .fits, .fit `IL_FITS' yes no
  1078. System
  1079. Heavy Metal: FAKK 2 Texture .ftx `IL_FTX' yes no
  1080. Graphics Interchange Format .gif `IL_GIF' yes no
  1081. Radiance High Dynamic Range .hdr `IL_HDR' yes yes
  1082. Macintosh Icons .icns `IL_ICNS' yes no
  1083. Windows Icons .ico, .cur `IL_ICO' yes no
  1084. Interchange File Format .iff `IL_IFF' yes no
  1085. Infinity Ward Image .iwi `IL_IWI' yes no
  1086. Jpeg Network Graphics .jng `IL_JNG' yes no
  1087. Jpeg 2000 .jp2 `IL_JP2' yes yes
  1088. Jpeg .jpg, .jpe, `IL_JPG' yes yes
  1089. .jpeg
  1090. Interlaced Bitmap .lbm `IL_LBM' yes no
  1091. Homeworld File .lif `IL_LIF' yes no
  1092. Half-Life Model .mdl `IL_MDL' yes no
  1093. Mng Animation .mng `IL_MNG' yes no
  1094. MPEG-1 Audio Layer 3 .mp3 `IL_MP3' yes no
  1095. PhotoCD .pcd `IL_PCD' yes no
  1096. ZSoft PCX .pcx `IL_PCX' yes yes
  1097. Softimage PIC .pic `IL_PIC' yes no
  1098. PIX .pix `IL_PIX' yes no
  1099. Portable Network Graphics .png `IL_PNG' yes yes
  1100. Pnm .pbm, .pgm, `IL_PPM' yes yes
  1101. .ppm, .pnm
  1102. Adobe PhotoShop .psd `IL_PSD' yes yes
  1103. PaintShop Pro .psp `IL_PSP' yes no
  1104. Pixar .pxr `IL_PXR' yes no
  1105. Raw Data * `IL_RAW' yes yes
  1106. Homeworld 2 Texture .rot `IL_ROT' yes no
  1107. Silicon Graphics .sgi, .bw, `IL_SGI' yes yes
  1108. .rgb, .rgba
  1109. Sun RAS .sun, .ras, `IL_SUN' yes no
  1110. .rs, .im*
  1111. Creative Assembly Texture .texture `IL_TEXTURE' yes no
  1112. Targa .tga `IL_TGA' yes yes
  1113. Tagged Image File Format .tif, .tiff `IL_TIF' yes yes
  1114. Gamecube Texture .tpl `IL_TPL' yes no
  1115. Unreal Texture .utx `IL_UTX' yes no
  1116. Valve Texture .vtf `IL_VTF' yes yes
  1117. Quake2 Texture .wal `IL_WAL' yes no
  1118. HD Photo .wdp, .hdp `IL_WDP' yes no
  1119. X Pixel Map .xpm `IL_XPM' yes no
  1120. *Exception:* `IL_JPG' (IJL) type is not supported by `ilLoadF' nor
  1121. by `ilSaveF'. `IL_JPG' (libjpeg) is supported by both.
  1122. 
  1123. File: DevIL_manual.info, Node: Sample program, Next: Functions index, Prev: Common #defines, Up: Top
  1124. Appendix D Sample `DevIL' program
  1125. *********************************
  1126. If you are not used to this approach, you may be grateful for a short
  1127. program demonstrating how to actually use `DevIL':
  1128. #include<IL/il.h>
  1129. #include<stdlib.h> /* because of malloc() etc. */
  1130. int main(int argc, const char * argv[])
  1131. {
  1132. ILuint handle, w, h;
  1133. /* First we initialize the library. */
  1134. /*Do not forget that... */
  1135. ilInit();
  1136. /* We want all images to be loaded in a consistent manner */
  1137. ilEnable(IL_ORIGIN_SET);
  1138. /* In the next section, we load one image */
  1139. ilGenImages(1, & handle);
  1140. ilBindImage(handle);
  1141. ILboolean loaded = ilLoadImage("original_file.jpg");
  1142. if (loaded == IL_FALSE)
  1143. return -1; /* error encountered during loading */
  1144. /* Let's spy on it a little bit */
  1145. w = ilGetInteger(IL_IMAGE_WIDTH); // getting image width
  1146. h = ilGetInteger(IL_IMAGE_HEIGHT); // and height
  1147. printf("Our image resolution: %dx%d\n", w, h);
  1148. /* how much memory will we need? */
  1149. int memory_needed = w * h * 3 * sizeof(unsigned char);
  1150. /* We multiply by 3 here because we want 3 components per pixel */
  1151. ILubyte * data = (ILubyte *)malloc(memory_needed);
  1152. /* finally get the image data */
  1153. ilCopyPixels(0, 0, 0, w, h, 1, IL_RGB, IL_UNSIGNED_BYTE, data);
  1154. /* We want to do something with the image, right? */
  1155. int i;
  1156. for(i = 0; i < memory_needed; i++)
  1157. if(i % 31 == 0) /* vandalise the image */
  1158. data[i] = i % 255;
  1159. /* And maybe we want to save that all... */
  1160. ilSetPixels(0, 0, 0, w, h, 1, IL_RGB, IL_UNSIGNED_BYTE, data);
  1161. /* and dump them to the disc... */
  1162. ilSaveImage("our_result.png");
  1163. /* Finally, clean the mess! */
  1164. ilDeleteImages(1, & handle);
  1165. free(data); data = NULL;
  1166. return 0;
  1167. }
  1168. 
  1169. File: DevIL_manual.info, Node: Functions index, Prev: Sample program, Up: Top
  1170. Functions index
  1171. ***************
  1172. �[index�]
  1173. * Menu:
  1174. * ilBindImage: Basic usage. (line 78)
  1175. * ilBlit: Image management. (line 183)
  1176. * ilCopyImage: Image management. (line 169)
  1177. * ilCopyPixels: Image management. (line 71)
  1178. * ilDeleteImages: Basic usage. (line 93)
  1179. * ilGenImages: Basic usage. (line 66)
  1180. * ilGetData: Image management. (line 61)
  1181. * ilGetError: Error handling. (line 14)
  1182. * ilInit: Basic usage. (line 16)
  1183. * ilLoad: Basic usage. (line 155)
  1184. * ilLoadF: Basic usage. (line 174)
  1185. * ilLoadImage: Basic usage. (line 121)
  1186. * ilLoadL: Basic usage. (line 186)
  1187. * ilOverlay: Image management. (line 223)
  1188. * ilSetData: Image management. (line 114)
  1189. * ilSetPixels: Image management. (line 129)
  1190. * ilTexImage: Image management. (line 6)
  1191. * iluActiveMipmap: Image manipulation. (line 304)
  1192. * iluAlienify: Image manipulation. (line 24)
  1193. * iluBlurAverage: Image manipulation. (line 38)
  1194. * iluBlurGaussian: Image manipulation. (line 38)
  1195. * iluBuildMipmaps: Image manipulation. (line 292)
  1196. * iluContrast: Image manipulation. (line 62)
  1197. * iluEqualize: Image manipulation. (line 89)
  1198. * iluErrorString: Error handling. (line 30)
  1199. * iluGammaCorrect: Image manipulation. (line 101)
  1200. * iluImageParameter: Image manipulation. (line 222)
  1201. * iluInit: Basic usage. (line 24)
  1202. * iluNegative: Image manipulation. (line 114)
  1203. * iluNoisify: Image manipulation. (line 127)
  1204. * iluPixelize: Image manipulation. (line 153)
  1205. * iluScale: Image manipulation. (line 203)
  1206. * iluSharpen: Image manipulation. (line 168)
  1207. 
  1208. Tag Table:
  1209. Node: Top580
  1210. Node: Introduction1176
  1211. Ref: tests10015
  1212. Node: Basic usage10878
  1213. Node: Image management19467
  1214. Ref: ilTexImage reference19611
  1215. Ref: registration29809
  1216. Node: Error handling29844
  1217. Node: Image manipulation31959
  1218. Ref: fig:stairway_original32413
  1219. Ref: fig:stairway_alienified33392
  1220. Ref: fig:stairway_blurred34476
  1221. Ref: fig:stairway_contrast35487
  1222. Ref: fig:stairway_equalized36095
  1223. Ref: fig:stairway_gamma36703
  1224. Ref: fig:stairway_negative37366
  1225. Ref: fig:stairway_noisify38023
  1226. Ref: fig:stairway_pixelize39373
  1227. Ref: fig:stairway_sharpen40529
  1228. Node: Common #defines51684
  1229. Ref: format #defines51999
  1230. Ref: type #defines52173
  1231. Ref: language #defines52394
  1232. Ref: error_codes52572
  1233. Ref: file_formats54103
  1234. Node: Sample program58682
  1235. Node: Functions index60774
  1236. 
  1237. End Tag Table
  1238. 
  1239. Local Variables:
  1240. coding: utf-8
  1241. End: