View Javadoc
1   package org.newdawn.slick.opengl;
2   
3   import java.nio.ByteBuffer;
4   
5   import org.newdawn.slick.opengl.renderer.SGL;
6   
7   /**
8    * A description of any class providing ImageData in a form suitable for OpenGL texture
9    * creation.
10   * 
11   * @author kevin
12   */
13  public interface ImageData {    
14      /**
15       * The format of the image data. This class is used to encapsulate the
16       * different image formats that could be load and used by OpenGL.
17       * 
18       * @author Martin Karing <nitram@illarion.org>
19       */
20      public static enum Format {
21          /** he format for RGB images (no alpha). */
22          RGB(3, 24, false, SGL.GL_RGB),
23  
24          /** he format for RGB images with alpha. */
25          BGRA(4, 32, true, SGL.GL_BGRA),
26  
27          /** he format for RGB images with alpha. */
28          RGBA(4, 32, true, SGL.GL_RGBA),
29          
30          /** The format for alpha-only images. */
31          ALPHA(1, 8, true, SGL.GL_ALPHA),
32  
33          /** he format for grayscale images (no alpha). */
34          GRAY(1, 8, false, SGL.GL_LUMINANCE),
35  
36          /** he format for grayscale images with alpha. */
37          GRAYALPHA(2, 16, true, SGL.GL_LUMINANCE_ALPHA);
38  
39          /**
40           * Stores if this format has a alpha component.
41           */
42          private final boolean alpha;
43          
44          /**
45           * Stores the count of bits used to encode one pixel of the image.
46           */
47          private final int bitdepth;
48          
49          /**
50           * Stores the count of color components (including the alpha channel) of
51           * the image.
52           */
53          private final int components;
54          
55          /**
56           * Contains the best fitting OpenGL format.
57           */
58          private final int OGLtype;
59          
60          /**
61           * Constructor used to create the format instances.
62           * 
63           * @param comp component count
64           * @param depth bit depth per pixel
65           * @param hasAlpha has a alpha channel?
66           * @param openGL openGL format
67           */
68          private Format(final int comp, final int depth, final boolean hasAlpha, final int openGL) {
69              components = comp;
70              bitdepth = depth;
71              alpha = hasAlpha;
72              OGLtype = openGL;
73          }
74          
75          /**
76           * Check if the image with this format has a alpha channel.
77           * 
78           * @return <code>true</code> in case the image has a alpha channel
79           */
80          public boolean hasAlpha() {
81              return alpha;
82          }
83          
84          /**
85           * Get the amount of bits used to encode one pixel in case the image
86           * uses this format.
87           * 
88           * @return bits per pixel
89           */
90          public int getBitPerPixel() {
91              return bitdepth;
92          }
93          
94          /**
95           * Get the count of bits used to encode one color.
96           * 
97           * @return the bits used to encode one color
98           */
99          public int getBitPerColor() {
100             return bitdepth / components;
101         }
102         
103         /**
104          * The amount of color components (including the alpha channel) of the
105          * image using this format.
106          * 
107          * @return the count of color and alpha components of this image
108          */
109         public int getColorComponents() {
110             return components;
111         }
112         
113         /**
114          * The OpenGL type that fits best to load this image.
115          * 
116          * @return the best fitting OpenGL type
117          */
118         public int getOGLType() {
119             return OGLtype;
120         }
121     }
122     
123     /**
124      * Get the format of this image.
125      * 
126      * @return the image format
127      */
128     public Format getFormat();
129 
130     /**
131      * Get the last width read from a TGA
132      *
133      * @return Get the last width in pixels fread from a TGA
134      */
135     public int getWidth();
136 
137     /**
138      * Get the last height read from a TGA
139      *
140      * @return Get the last height in pixels fread from a TGA
141      */
142     public int getHeight();
143 
144     /**
145      * Get the last required texture width for a loaded image
146      *
147      * @return Get the ast required texture width for a loaded image
148      */
149     public int getTexWidth();
150 
151     /**
152      * Get the ast required texture height for a loaded image
153      *
154      * @return Get the ast required texture height for a loaded image
155      */
156     public int getTexHeight();
157 
158     /**
159      * Get the store image
160      *
161      * @return The stored image
162      */
163     public ByteBuffer getImageBufferData();
164 
165 }