home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !SDL / man / SDL_PixelFormat.3 < prev    next >
Encoding:
Text File  |  2006-09-20  |  5.4 KB  |  176 lines

  1. <!-- manual page source format generated by PolyglotMan v3.0.8+X.Org, -->
  2. <!-- available at http://polyglotman.sourceforge.net/ -->
  3.  
  4. <html>
  5. <head>
  6. <title>"SDL_PixelFormat"("3") manual page</title>
  7. </head>
  8. <body bgcolor='#efefef' text='black' link='blue' vlink='#551A8B' alink='red'>
  9. <a href='#toc'>Table of Contents</a><p>
  10.  
  11. <h2><a name='sect0' href='#toc0'>Name</a></h2>
  12. SDL_PixelFormat- Stores surface format information 
  13. <h2><a name='sect1' href='#toc1'>Structure Definition</a></h2>
  14. <p>
  15. <br>
  16. <pre>CWtypedef struct SDL_PixelFormat {
  17.   SDL_Palette *palette;
  18.   Uint8  BitsPerPixel;
  19.   Uint8  BytesPerPixel;
  20.   Uint8  Rloss, Gloss, Bloss, Aloss;
  21.   Uint8  Rshift, Gshift, Bshift, Ashift;
  22.   Uint32 Rmask, Gmask, Bmask, Amask;
  23.   Uint32 colorkey;
  24.   Uint8  alpha;
  25. } SDL_PixelFormat;
  26. </pre><p>
  27.  
  28. <h2><a name='sect2' href='#toc2'>Structure Data</a></h2>
  29.  
  30. <dl>
  31.  
  32. <dt><b>palette</b> </dt>
  33. <dd>Pointer to the <i>palette</i>, or <b>NULL</b> if the <b>BitsPerPixel</b>>8
  34. </dd>
  35.  
  36. <dt><b>BitsPerPixel</b> </dt>
  37. <dd>The number of bits used to represent each pixel in a surface.
  38. Usually 8, 16, 24 or 32. </dd>
  39.  
  40. <dt><b>BytesPerPixel</b> </dt>
  41. <dd>The number of bytes used to represent
  42. each pixel in a surface. Usually one to four. </dd>
  43.  
  44. <dt><b>[RGBA]mask</b> </dt>
  45. <dd>Binary mask used
  46. to retrieve individual color values </dd>
  47.  
  48. <dt><b>[RGBA]loss</b> </dt>
  49. <dd>Precision loss of each color
  50. component (2^[RGBA]loss) </dd>
  51.  
  52. <dt><b>[RGBA]shift</b> </dt>
  53. <dd>Binary left shift of each color component
  54. in the pixel value </dd>
  55.  
  56. <dt><b>colorkey</b> </dt>
  57. <dd>Pixel value of transparent pixels </dd>
  58.  
  59. <dt><b>alpha</b> </dt>
  60. <dd>Overall
  61. surface alpha value </dd>
  62. </dl>
  63.  
  64. <h2><a name='sect3' href='#toc3'>Description</a></h2>
  65. <p>
  66. A <b>SDL_PixelFormat</b> describes the format of
  67. the pixel data stored at the <b>pixels</b> field of a <i><b>SDL_Surface</b></i>. Every surface
  68. stores a <b>SDL_PixelFormat</b> in the <b>format</b> field. <p>
  69. If you wish to do pixel level
  70. modifications on a surface, then understanding how SDL stores its color
  71. information is essential. <p>
  72. 8-bit pixel formats are the easiest to understand.
  73. Since its an 8-bit format, we have 8 <b>BitsPerPixel</b> and 1 <b>BytesPerPixel</b>. Since
  74. <b>BytesPerPixel</b> is 1, all pixels are represented by a Uint8 which contains
  75. an index into <b>palette</b>-><b>colors</b>. So, to determine the color of a pixel in a
  76. 8-bit surface: we read the color index from <b>surface</b>-><b>pixels</b> and we use that
  77. index to read the <i><b>SDL_Color</b></i> structure from <b>surface</b>-><b>format</b>-><b>palette</b>-><b>colors</b>. Like
  78. so:  <p>
  79. <br>
  80. <pre>CWSDL_Surface *surface;
  81. SDL_PixelFormat *fmt;
  82. SDL_Color *color;
  83. Uint8 index;
  84. .
  85. .
  86. /* Create surface */
  87. .
  88. .
  89. fmt=surface->format;
  90. /* Check the bitdepth of the surface */
  91. if(fmt->BitsPerPixel!=8){
  92.   fprintf(stderr, "Not an 8-bit surface.
  93. ");
  94.   return(-1);
  95. }
  96. /* Lock the surface */
  97. SDL_LockSurface(surface);
  98. /* Get the topleft pixel */
  99. index=*(Uint8 *)surface->pixels;
  100. color=fmt->palette->colors[index];
  101. /* Unlock the surface */
  102. SDL_UnlockSurface(surface);
  103. printf("Pixel Color-> Red: %d, Green: %d, Blue: %d. Index: %d
  104. ",
  105.           color->r, color->g, color->b, index);
  106. .
  107. .
  108. </pre><p>
  109. <p>
  110. Pixel formats above 8-bit are an entirely different experience. They are
  111. considered to be "TrueColor" formats and the color information is stored
  112. in the pixels themselves, not in a palette. The mask, shift and loss fields
  113. tell us how the color information is encoded. The mask fields allow us to
  114. isolate each color component, the shift fields tell us the number of bits
  115. to the right of each component in the pixel value and the loss fields tell
  116. us the number of bits lost from each component when packing 8-bit color
  117. component in a pixel.  <p>
  118. <br>
  119. <pre>CW/* Extracting color components from a 32-bit color value */
  120. SDL_PixelFormat *fmt;
  121. SDL_Surface *surface;
  122. Uint32 temp, pixel;
  123. Uint8 red, green, blue, alpha;
  124. .
  125. .
  126. .
  127. fmt=surface->format;
  128. SDL_LockSurface(surface);
  129. pixel=*((Uint32*)surface->pixels);
  130. SDL_UnlockSurface(surface);
  131. /* Get Red component */
  132. temp=pixel&fmt->Rmask; /* Isolate red component */
  133. temp=temp>>fmt->Rshift;/* Shift it down to 8-bit */
  134. temp=temp<<fmt->Rloss; /* Expand to a full 8-bit number */
  135. red=(Uint8)temp;
  136. /* Get Green component */
  137. temp=pixel&fmt->Gmask; /* Isolate green component */
  138. temp=temp>>fmt->Gshift;/* Shift it down to 8-bit */
  139. temp=temp<<fmt->Gloss; /* Expand to a full 8-bit number */
  140. green=(Uint8)temp;
  141. /* Get Blue component */
  142. temp=pixel&fmt->Bmask; /* Isolate blue component */
  143. temp=temp>>fmt->Bshift;/* Shift it down to 8-bit */
  144. temp=temp<<fmt->Bloss; /* Expand to a full 8-bit number */
  145. blue=(Uint8)temp;
  146. /* Get Alpha component */
  147. temp=pixel&fmt->Amask; /* Isolate alpha component */
  148. temp=temp>>fmt->Ashift;/* Shift it down to 8-bit */
  149. temp=temp<<fmt->Aloss; /* Expand to a full 8-bit number */
  150. alpha=(Uint8)temp;
  151. printf("Pixel Color -> R: %d,  G: %d,  B: %d,  A: %d
  152. ", red, green, blue, alpha);
  153. .
  154. .
  155. .
  156. </pre><p>
  157.  
  158. <h2><a name='sect4' href='#toc4'>See Also</a></h2>
  159. <p>
  160. <i><b>SDL_Surface</b></i>, <i><b>SDL_MapRGB</b></i> 
  161. <!--
  162.   
  163.  <p>
  164.  
  165. <hr><p>
  166. <a name='toc'><b>Table of Contents</b></a><p>
  167. <ul>
  168. <li><a name='toc0' href='#sect0'>Name</a></li>
  169. <li><a name='toc1' href='#sect1'>Structure Definition</a></li>
  170. <li><a name='toc2' href='#sect2'>Structure Data</a></li>
  171. <li><a name='toc3' href='#sect3'>Description</a></li>
  172. <li><a name='toc4' href='#sect4'>See Also</a></li>
  173. </ul>
  174. </body>
  175. </html>
  176.