Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/libsdl/video/SDLPixelFormat.java


1   
2   
3   package org.libsdl.video;
4   
5   import org.libsdl.SDLStruct;
6   
7   /**
8    * The <code>SDLPixelFormat</code> class represents an SDL_PixelFormat C struct.
9    * The class extends <code>SDLStruct</code> and thus represents a native
10   * C structure.  The <code>SDLPixelFormat</code> class typically represents the 
11   * properties of <code>an SDLSurface</code>, such as bit depth, palette, masks,
12   * and shifts (to name a few).
13   * <p>
14   * A <code>SDLPixelFormat</code> cannot be instantiated directly.  It must be
15   * created by the surface that it represents.
16   * <p>
17   * ------ EXAMPLE ------
18   * <p><blockquote><pre>
19   *     SDL sdl = SDL.getInstance();
20   *     SDLVideo video = sdl.getVideo();
21   *     SDLVideoInfo vidinfo = video.getVideoInfo();
22   *     SDLPixelFormat format = vidinfo.getPixelFormat();
23   *     short bpp = format.bitsPerPixel();  // etc...
24   * </pre></blockquote><p>
25   * ------ EXAMPLE ------
26   * <p><blockquote><pre>
27   *     SDLSurface surf = ...
28   *     SDLPixelFormat format = surf.getPixelFormat();
29   *     short bpp = format.bitsPerPixel();  // etc...
30   * </pre></blockquote><p>
31   *
32   * @author  Eric Wittmann
33   * @version $revision$
34   * @see     org.libsdl.video.SDLVideoInfo#getPixelFormat()
35   * @see     org.libsdl.video.SDLSurface#getPixelFormat()
36   */
37  public class SDLPixelFormat extends SDLStruct
38  {
39      protected SDLPixelFormat(int l) {
40          super(l);
41      }
42  
43      /**
44       * Get this <code>SDLPixelFormat</code>'s palette.
45       * @return   SDLPalette - the pixel format's palette
46       */
47      public native SDLPalette palette();
48      /**
49       * Get the bit depth.
50       * @return   Short - bits per pixel
51       */
52      public native short bitsPerPixel();
53      /**
54       * Get the byte depth.
55       * @return   Short - bytes per pixel
56       */
57      public native short bytesPerPixel();
58      /**
59       * Get the red mask
60       * @return   Integer - red mask
61       */
62      public native int redMask();
63      /**
64       * Get the green mask
65       * @return   Integer - green mask
66       */
67      public native int greenMask();
68      /**
69       * Get the blue mask
70       * @return   Integer - blue mask
71       */
72      public native int blueMask();
73      /**
74       * Get the alpha mask
75       * @return   Integer - alpha mask
76       */
77      public native int alphaMask();
78      /**
79       * Get the red shift
80       * @return   Short - red shift
81       */
82      public native short redShift();
83      /**
84       * Get the green shift
85       * @return   Short - green shift
86       */
87      public native short greenShift();
88      /**
89       * Get the blue shift
90       * @return   Short - blue shift
91       */
92      public native short blueShift();
93      /**
94       * Get the alpha shift
95       * @return   Short - alpha shift
96       */
97      public native short alphaShift();
98      /**
99       * Get the red loss
100      * @return   Short - red loss
101      */
102     public native short redLoss();
103     /**
104      * Get the green loss
105      * @return   Short - green loss
106      */
107     public native short greenLoss();
108     /**
109      * Get the blue loss
110      * @return   Short - blue loss
111      */
112     public native short blueLoss();
113     /**
114      * Get the alpha loss
115      * @return   Short - alpha loss
116      */
117     public native short alphaLoss();
118     /**
119      * Get the color key
120      * @return   Integer - color key
121      */
122     public native int colorKey();
123     /**
124      * Get the alpha loss
125      * @return   Short - alpha loss
126      */
127     public native short alpha();
128 
129     /**
130      * Converts a 32 bit integer pixel into an <code>SDLRGB</code> object
131      * <p>
132      * <b>Corresponds</b>:<blockquote><code>SDL_GetRGB()</code></blockquote>
133      * <p>
134      * @param  pixel  Integer - a pixel to convert into an <code>SDLRGB</code> object
135      * @return   SDLRGB - an <code>SDLRGB</code> object representing the pixel
136      */
137     public native SDLRGB getRGB(int pixel);
138     /**
139      * Converts a 32 bit integer pixel into an <code>SDLRGBA</code> object
140      * <p>
141      * <b>Corresponds</b>:<blockquote><code>SDL_GetRGBA()</code></blockquote>
142      * <p>
143      * @param  pixel  Integer - a pixel to convert into an <code>SDLRGBA</code> object
144      * @return   SDLRGBA - an <code>SDLRGBA</code> object representing the pixel
145      */
146     public native SDLRGBA getRGBA(int pixel);
147     /**
148      * Converts red, green, and blue components into a 32 bit integer pixel.
149      * <p>
150      * <b>Corresponds</b>:<blockquote><code>SDL_MapRGB()</code></blockquote>
151      * <p>
152      * @param  r  Short - red component
153      * @param  g  Short - green component
154      * @param  b  Short - blue component
155      * @return   Integer - the 32 bit integer pixel
156      */
157     public native int mapRGB(short r, short g, short b);
158     /**
159      * Converts red, green, blue, and alpha components into a 32 bit integer pixel.
160      * <p>
161      * <b>Corresponds</b>:<blockquote><code>SDL_MapRGBA()</code></blockquote>
162      * <p>
163      * @param  r  Short - red component
164      * @param  g  Short - green component
165      * @param  b  Short - blue component
166      * @param  a  Short - alpha component
167      * @return   Integer - the 32 bit integer pixel
168      */
169     public native int mapRGBA(short r, short g, short b, short a);
170 
171     /**
172      * Converts an <code>SDLRGB</code> object into a 32 bit integer pixel.
173      * @param  rgb  SDLRGB - object to map
174      * @return   Integer - the 32 bit integer pixel
175      */
176     public int mapRGB(SDLRGB rgb) {
177         return mapRGB(rgb.red(), rgb.green(), rgb.blue());
178     }
179     /**
180      * Converts an <code>SDLRGBA</code> object into a 32 bit integer pixel.
181      * @param  rgb  SDLRGBA - object to map
182      * @return   Integer - the 32 bit integer pixel
183      */
184     public int mapRGBA(SDLRGBA rgba) {
185         return mapRGBA(rgba.red(), rgba.green(), rgba.blue(), rgba.alpha());
186     }
187 }