Added some missing pixel formats and SDL_GetPixelFormatName()
authorSam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 14:53:23 -0800
changeset 4982660d3a432102
parent 4981 55b82067815b
child 4983 b49d3869ebd2
Added some missing pixel formats and SDL_GetPixelFormatName()
android-project/src/org/libsdl/app/SDLActivity.java
include/SDL_pixels.h
src/video/SDL_pixels.c
test/common.c
     1.1 --- a/android-project/src/org/libsdl/app/SDLActivity.java	Wed Jan 12 14:29:01 2011 -0800
     1.2 +++ b/android-project/src/org/libsdl/app/SDLActivity.java	Wed Jan 12 14:53:23 2011 -0800
     1.3 @@ -24,35 +24,35 @@
     1.4  */
     1.5  public class SDLActivity extends Activity {
     1.6  
     1.7 -    //Main components
     1.8 +    // Main components
     1.9      private static SDLActivity mSingleton;
    1.10      private static SDLSurface mSurface;
    1.11  
    1.12 -    //Audio
    1.13 +    // Audio
    1.14      private static AudioTrack mAudioTrack;
    1.15      private static boolean bAudioIsEnabled;
    1.16  
    1.17 -    //Sensors
    1.18 +    // Sensors
    1.19      private static boolean bAccelIsEnabled;
    1.20  
    1.21 -    //feature IDs. Must match up on the C side as well.
    1.22 +    // feature IDs. Must match up on the C side as well.
    1.23      private static int FEATURE_AUDIO = 1;
    1.24      private static int FEATURE_ACCEL = 2;
    1.25  
    1.26 -    //Load the .so
    1.27 +    // Load the .so
    1.28      static {
    1.29          System.loadLibrary("SDL");
    1.30          System.loadLibrary("main");
    1.31      }
    1.32  
    1.33 -    //Setup
    1.34 +    // Setup
    1.35      protected void onCreate(Bundle savedInstanceState) {
    1.36          super.onCreate(savedInstanceState);
    1.37          
    1.38 -        //So we can call stuff from static callbacks
    1.39 +        // So we can call stuff from static callbacks
    1.40          mSingleton = this;
    1.41  
    1.42 -        //Set up the surface
    1.43 +        // Set up the surface
    1.44          mSurface = new SDLSurface(getApplication());
    1.45          setContentView(mSurface);
    1.46          SurfaceHolder holder = mSurface.getHolder();
    1.47 @@ -60,11 +60,11 @@
    1.48          
    1.49      }
    1.50  
    1.51 -    //Audio
    1.52 +    // Audio
    1.53      public static boolean initAudio(){        
    1.54  
    1.55 -        //blah. Hardcoded things are bad. FIXME when we have more sound stuff
    1.56 -        //working properly. 
    1.57 +        // blah. Hardcoded things are bad. FIXME when we have more sound stuff
    1.58 +        // working properly. 
    1.59          mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
    1.60                      11025,
    1.61                      AudioFormat.CHANNEL_CONFIGURATION_MONO,
    1.62 @@ -75,7 +75,7 @@
    1.63          return true;
    1.64      }
    1.65  
    1.66 -    //Accel
    1.67 +    // Accel
    1.68      public static boolean initAccel(){
    1.69          mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
    1.70          bAccelIsEnabled = true;
    1.71 @@ -110,7 +110,7 @@
    1.72      public static native void onNativeAccel(float x, float y, float z);
    1.73  
    1.74  
    1.75 -    //Java functions called from C
    1.76 +    // Java functions called from C
    1.77      private static void createGLContext() {
    1.78          mSurface.initEGL();
    1.79      }
    1.80 @@ -134,13 +134,13 @@
    1.81      public static void enableFeature(int featureid, int enabled) {
    1.82           Log.v("SDL","Feature " + featureid + " = " + enabled);
    1.83  
    1.84 -        //Yuck. This is all horribly inelegent. If it gets to more than a few
    1.85 -        //'features' I'll rip this out and make something nicer, I promise :)
    1.86 +        // Yuck. This is all horribly inelegent. If it gets to more than a few
    1.87 +        // 'features' I'll rip this out and make something nicer, I promise :)
    1.88          if(featureid == FEATURE_AUDIO){
    1.89              if(enabled == 1){
    1.90                  initAudio();
    1.91              }else{
    1.92 -                //We don't have one of these yet...
    1.93 +                // We don't have one of these yet...
    1.94                  //closeAudio(); 
    1.95              }
    1.96          }
    1.97 @@ -241,11 +241,11 @@
    1.98              break;
    1.99          case PixelFormat.RGBA_4444:
   1.100              Log.v("SDL","pixel format RGBA_4444");
   1.101 -            sdlFormat = 0x85421002; // Doesn't have an SDL constant...
   1.102 +            sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
   1.103              break;
   1.104          case PixelFormat.RGBA_5551:
   1.105              Log.v("SDL","pixel format RGBA_5551");
   1.106 -            sdlFormat = 0x85441002; // Doesn't have an SDL constant...
   1.107 +            sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
   1.108              break;
   1.109          case PixelFormat.RGBA_8888:
   1.110              Log.v("SDL","pixel format RGBA_8888");
   1.111 @@ -278,7 +278,7 @@
   1.112          }
   1.113      }
   1.114  
   1.115 -    //unused
   1.116 +    // unused
   1.117      public void onDraw(Canvas canvas) {}
   1.118  
   1.119  
   1.120 @@ -332,7 +332,7 @@
   1.121  
   1.122              egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
   1.123  
   1.124 -            //drawing here
   1.125 +            // drawing here
   1.126  
   1.127              egl.eglWaitGL();
   1.128  
   1.129 @@ -370,14 +370,14 @@
   1.130          float y = event.getY();
   1.131          float p = event.getPressure();
   1.132  
   1.133 -        //TODO: Anything else we need to pass?        
   1.134 +        // TODO: Anything else we need to pass?        
   1.135          SDLActivity.onNativeTouch(action, x, y, p);
   1.136          return true;
   1.137      }
   1.138  
   1.139      // Sensor events
   1.140      public void enableSensor(int sensortype, boolean enabled) {
   1.141 -        //TODO: This uses getDefaultSensor - what if we have >1 accels?
   1.142 +        // TODO: This uses getDefaultSensor - what if we have >1 accels?
   1.143          if (enabled) {
   1.144              mSensorManager.registerListener(this, 
   1.145                              mSensorManager.getDefaultSensor(sensortype), 
   1.146 @@ -389,7 +389,7 @@
   1.147      }
   1.148      
   1.149      public void onAccuracyChanged(Sensor sensor, int accuracy) {
   1.150 -        //TODO
   1.151 +        // TODO
   1.152      }
   1.153  
   1.154      public void onSensorChanged(SensorEvent event) {
     2.1 --- a/include/SDL_pixels.h	Wed Jan 12 14:29:01 2011 -0800
     2.2 +++ b/include/SDL_pixels.h	Wed Jan 12 14:53:23 2011 -0800
     2.3 @@ -138,6 +138,7 @@
     2.4  #define SDL_ISPIXELFORMAT_FOURCC(format)    \
     2.5      ((format) && !((format) & 0x80000000))
     2.6  
     2.7 +/* Note: If you modify this list, update SDL_GetPixelFormatName() */
     2.8  enum
     2.9  {
    2.10      SDL_PIXELFORMAT_UNKNOWN,
    2.11 @@ -170,15 +171,27 @@
    2.12      SDL_PIXELFORMAT_ARGB4444 =
    2.13          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
    2.14                                 SDL_PACKEDLAYOUT_4444, 16, 2),
    2.15 +    SDL_PIXELFORMAT_RGBA4444 =
    2.16 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
    2.17 +                               SDL_PACKEDLAYOUT_4444, 16, 2),
    2.18      SDL_PIXELFORMAT_ABGR4444 =
    2.19          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
    2.20                                 SDL_PACKEDLAYOUT_4444, 16, 2),
    2.21 +    SDL_PIXELFORMAT_BGRA4444 =
    2.22 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
    2.23 +                               SDL_PACKEDLAYOUT_4444, 16, 2),
    2.24      SDL_PIXELFORMAT_ARGB1555 =
    2.25          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
    2.26                                 SDL_PACKEDLAYOUT_1555, 16, 2),
    2.27 +    SDL_PIXELFORMAT_RGBA5551 =
    2.28 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
    2.29 +                               SDL_PACKEDLAYOUT_5551, 16, 2),
    2.30      SDL_PIXELFORMAT_ABGR1555 =
    2.31          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
    2.32                                 SDL_PACKEDLAYOUT_1555, 16, 2),
    2.33 +    SDL_PIXELFORMAT_BGRA5551 =
    2.34 +        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
    2.35 +                               SDL_PACKEDLAYOUT_5551, 16, 2),
    2.36      SDL_PIXELFORMAT_RGB565 =
    2.37          SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
    2.38                                 SDL_PACKEDLAYOUT_565, 16, 2),
    2.39 @@ -270,6 +283,11 @@
    2.40  } SDL_PixelFormat;
    2.41  
    2.42  /**
    2.43 + * \brief Get the human readable name of a pixel format
    2.44 + */
    2.45 +extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
    2.46 +
    2.47 +/**
    2.48   *  \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
    2.49   *  
    2.50   *  \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
     3.1 --- a/src/video/SDL_pixels.c	Wed Jan 12 14:29:01 2011 -0800
     3.2 +++ b/src/video/SDL_pixels.c	Wed Jan 12 14:53:23 2011 -0800
     3.3 @@ -39,6 +39,50 @@
     3.4  
     3.5  /* Helper functions */
     3.6  
     3.7 +const char*
     3.8 +SDL_GetPixelFormatName(Uint32 format)
     3.9 +{
    3.10 +    switch (format) {
    3.11 +#define CASE(X) case X: return #X;
    3.12 +    CASE(SDL_PIXELFORMAT_INDEX1LSB)
    3.13 +    CASE(SDL_PIXELFORMAT_INDEX1MSB)
    3.14 +    CASE(SDL_PIXELFORMAT_INDEX4LSB)
    3.15 +    CASE(SDL_PIXELFORMAT_INDEX4MSB)
    3.16 +    CASE(SDL_PIXELFORMAT_INDEX8)
    3.17 +    CASE(SDL_PIXELFORMAT_RGB332)
    3.18 +    CASE(SDL_PIXELFORMAT_RGB444)
    3.19 +    CASE(SDL_PIXELFORMAT_RGB555)
    3.20 +    CASE(SDL_PIXELFORMAT_BGR555)
    3.21 +    CASE(SDL_PIXELFORMAT_ARGB4444)
    3.22 +    CASE(SDL_PIXELFORMAT_RGBA4444)
    3.23 +    CASE(SDL_PIXELFORMAT_ABGR4444)
    3.24 +    CASE(SDL_PIXELFORMAT_BGRA4444)
    3.25 +    CASE(SDL_PIXELFORMAT_ARGB1555)
    3.26 +    CASE(SDL_PIXELFORMAT_RGBA5551)
    3.27 +    CASE(SDL_PIXELFORMAT_ABGR1555)
    3.28 +    CASE(SDL_PIXELFORMAT_BGRA5551)
    3.29 +    CASE(SDL_PIXELFORMAT_RGB565)
    3.30 +    CASE(SDL_PIXELFORMAT_BGR565)
    3.31 +    CASE(SDL_PIXELFORMAT_RGB24)
    3.32 +    CASE(SDL_PIXELFORMAT_BGR24)
    3.33 +    CASE(SDL_PIXELFORMAT_RGB888)
    3.34 +    CASE(SDL_PIXELFORMAT_BGR888)
    3.35 +    CASE(SDL_PIXELFORMAT_ARGB8888)
    3.36 +    CASE(SDL_PIXELFORMAT_RGBA8888)
    3.37 +    CASE(SDL_PIXELFORMAT_ABGR8888)
    3.38 +    CASE(SDL_PIXELFORMAT_BGRA8888)
    3.39 +    CASE(SDL_PIXELFORMAT_ARGB2101010)
    3.40 +    CASE(SDL_PIXELFORMAT_YV12)
    3.41 +    CASE(SDL_PIXELFORMAT_IYUV)
    3.42 +    CASE(SDL_PIXELFORMAT_YUY2)
    3.43 +    CASE(SDL_PIXELFORMAT_UYVY)
    3.44 +    CASE(SDL_PIXELFORMAT_YVYU)
    3.45 +#undef CASE
    3.46 +    default:
    3.47 +        return "SDL_PIXELFORMAT_UNKNOWN";
    3.48 +    }
    3.49 +}
    3.50 +
    3.51  SDL_bool
    3.52  SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
    3.53                             Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
     4.1 --- a/test/common.c	Wed Jan 12 14:29:01 2011 -0800
     4.2 +++ b/test/common.c	Wed Jan 12 14:53:23 2011 -0800
     4.3 @@ -11,58 +11,6 @@
     4.4  #define AUDIO_USAGE \
     4.5  "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
     4.6  
     4.7 -struct pformat {
     4.8 -    Uint32 id;
     4.9 -    const char* idstr;
    4.10 -} pixel_format[]={
    4.11 -    {SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"},
    4.12 -    {SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"},
    4.13 -    {SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"},
    4.14 -    {SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"},
    4.15 -    {SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"},
    4.16 -    {SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"},
    4.17 -    {SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"},
    4.18 -    {SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"},
    4.19 -    {SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"},
    4.20 -    {SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"},
    4.21 -    {SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"},
    4.22 -    {SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"},
    4.23 -    {SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"},
    4.24 -    {SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"},
    4.25 -    {SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"},
    4.26 -    {SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"},
    4.27 -    {SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"},
    4.28 -    {SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"},
    4.29 -    {SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"},
    4.30 -    {SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"},
    4.31 -    {SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"},
    4.32 -    {SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"},
    4.33 -    {SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"},
    4.34 -    {SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"},
    4.35 -    {SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"},
    4.36 -    {SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"},
    4.37 -    {SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"},
    4.38 -    {SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"},
    4.39 -    {SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"}
    4.40 -};
    4.41 -
    4.42 -const char* PixelFormatToString(Uint32 pformat)
    4.43 -{
    4.44 -   Uint32 it=0;
    4.45 -
    4.46 -   do {
    4.47 -      if (pixel_format[it].idstr == NULL) {
    4.48 -          break;
    4.49 -      }
    4.50 -      if (pixel_format[it].id == pformat) {
    4.51 -          return pixel_format[it].idstr;
    4.52 -      }
    4.53 -      it++;
    4.54 -   } while(1);
    4.55 -
    4.56 -   return "SDL_PIXELFORMAT_UNKNOWN";
    4.57 -}
    4.58 -
    4.59  CommonState *
    4.60  CommonCreateState(char **argv, Uint32 flags)
    4.61  {
    4.62 @@ -719,7 +667,7 @@
    4.63                  fprintf(stderr,
    4.64                          "  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
    4.65                          mode.w, mode.h, mode.refresh_rate, bpp,
    4.66 -                        PixelFormatToString(mode.format));
    4.67 +                        SDL_GetPixelFormatName(mode.format));
    4.68                  if (Rmask || Gmask || Bmask) {
    4.69                      fprintf(stderr, "      Red Mask   = 0x%.8x\n", Rmask);
    4.70                      fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
    4.71 @@ -741,7 +689,7 @@
    4.72                          fprintf(stderr,
    4.73                                  "    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
    4.74                                  j, mode.w, mode.h, mode.refresh_rate, bpp,
    4.75 -                                PixelFormatToString(mode.format));
    4.76 +                                SDL_GetPixelFormatName(mode.format));
    4.77                          if (Rmask || Gmask || Bmask) {
    4.78                              fprintf(stderr, "        Red Mask   = 0x%.8x\n",
    4.79                                      Rmask);