Common AlphaBitmap manipulations in Scol » History » Version 1
  iri, 09/26/2012 01:10 AM 
  
| 1 | 1 | iri | h1. Common AlphaBitmap manipulations in Scol | 
|---|---|---|---|
| 2 | |||
| 3 | An *AlphaBitmap* Scol object is a bitmap with an alpha channel. This alpha can be nil. | ||
| 4 | It can be created from a bitmap object or it can be loaded from a PNG resource file. | ||
| 5 | All functions of this API are described "here":http://www.scolring.org/files/doc_html/alpha_bitmap.html. | ||
| 6 | |||
| 7 | h2. Create an AlphaBitmap | ||
| 8 | |||
| 9 | h3. The ObjBitmap8 object | ||
| 10 | |||
| 11 | This is 8-bits bitmap object insteaf of the 24-bits for the ObjBitmap. Lonely, it is rarely used but it can be an alpha channel. | ||
| 12 | This API is near than the ObjBitmap API, see [[Common bitmap manipulations in Scol]]. | ||
| 13 | |||
| 14 | We can create it from a resource file (8-bits BMP file, *_LDbitmap8*) or from ex-nihilo (*_CRbitmap8*). Like ObjBitmap, don't forget to destroy them when you no longer needed (*_DSbitmap8*). | ||
| 15 | |||
| 16 | h3. AlphaBitmap | ||
| 17 | |||
| 18 | The AlphaBitmap type is an opaque Scol type. | ||
| 19 | Use the Scol function *_CRalphaBitmap* or *_LDalphaBitmap* to create a such object. | ||
| 20 | |||
| 21 | @AlphaBitmap _CRalphaBitmap <channel> <bitmap_object> <bitmap8_object> <background_color> <transparency_color>@ | ||
| 22 | The <bitmap_object> is in 24-bits (RVB), <bitmap8_object> is in 8-bits and it is the alpha channel. | ||
| 23 | See "_CRalphaBitmap":http://www.scolring.org/files/doc_html/_cralphabitmap.html | ||
| 24 | |||
| 25 | @AlphaBitmap _LDalphaBitmap <channel> <reference_reading_png_file> | ||
| 26 | |||
| 27 | h2. Destruction | ||
| 28 | |||
| 29 | When a such object is no longer needed, you should quickly destroy it with *_DSalphaBitmap*. | ||
| 30 | |||
| 31 | h2. How to load a graphic resource file in Scol ? | ||
| 32 | |||
| 33 | Two near ways enough near if you want to have an ObjBitmap or an AlphaBitmap. | ||
| 34 | This function is helpful and you should get in your common library. | ||
| 35 | |||
| 36 | <pre> | ||
| 37 | /* | ||
| 38 | Load a graphic resource file | ||
| 39 | pfile : P : the reading-reference file | ||
| 40 | channel : channel to loading | ||
| 41 | return the object to create | ||
| 42 | fun [P Chn] ObjBitmap | ||
| 43 | fun [P Chn] AlphaBitmap | ||
| 44 | */ | ||
| 45 | |||
| 46 | fun loadRscFile2ObjBitmap (pFile, channel)= | ||
| 47 | if pFile == nil then | ||
| 48 | nil | ||
| 49 | else | ||
| 50 | let _LDbitmap channel pFile -> bmp in | ||
| 51 | if bmp == nil then | ||
| 52 | let _LDjpeg channel pFile -> jpeg in | ||
| 53 | if jpeg == nil then | ||
| 54 | let _LDtga channel pFile -> tga in | ||
| 55 | if tga == nil then | ||
| 56 | let _GETalphaBitmaps _LDalphaBitmap channel pFile -> [png _] in | ||
| 57 | png | ||
| 58 | else | ||
| 59 | tga | ||
| 60 | else | ||
| 61 | jpeg | ||
| 62 | else | ||
| 63 | bmp;; | ||
| 64 | |||
| 65 | fun loadRscFile2AlphaBitmap (pFile, channel)= | ||
| 66 | if pFile == nil then | ||
| 67 | nil | ||
| 68 | else | ||
| 69 | let _LDbitmap channel pFile -> bmp in | ||
| 70 | if bmp == nil then | ||
| 71 | let _LDjpeg channel pFile -> jpeg in | ||
| 72 | if jpeg == nil then | ||
| 73 | let _LDtga channel pFile -> tga in | ||
| 74 | if tga == nil then | ||
| 75 | _LDalphaBitmap channel pFile | ||
| 76 | else | ||
| 77 | _CRalphaBitmap channel tga nil nil nil | ||
| 78 | else | ||
| 79 | _CRalphaBitmap channel jpeg nil nil nil | ||
| 80 | else | ||
| 81 | _CRalphaBitmap channel bmp nil nil nil;; | ||
| 82 | </pre> | ||
| 83 | |||
| 84 | |||
| 85 |