Added some missing pixel formats and SDL_GetPixelFormatName()
authorSam Lantinga <slouken@libsdl.org>
Wed, 12 Jan 2011 14:53:23 -0800
changeset 4982 660d3a432102
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
--- a/android-project/src/org/libsdl/app/SDLActivity.java	Wed Jan 12 14:29:01 2011 -0800
+++ b/android-project/src/org/libsdl/app/SDLActivity.java	Wed Jan 12 14:53:23 2011 -0800
@@ -24,35 +24,35 @@
 */
 public class SDLActivity extends Activity {
 
-    //Main components
+    // Main components
     private static SDLActivity mSingleton;
     private static SDLSurface mSurface;
 
-    //Audio
+    // Audio
     private static AudioTrack mAudioTrack;
     private static boolean bAudioIsEnabled;
 
-    //Sensors
+    // Sensors
     private static boolean bAccelIsEnabled;
 
-    //feature IDs. Must match up on the C side as well.
+    // feature IDs. Must match up on the C side as well.
     private static int FEATURE_AUDIO = 1;
     private static int FEATURE_ACCEL = 2;
 
-    //Load the .so
+    // Load the .so
     static {
         System.loadLibrary("SDL");
         System.loadLibrary("main");
     }
 
-    //Setup
+    // Setup
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         
-        //So we can call stuff from static callbacks
+        // So we can call stuff from static callbacks
         mSingleton = this;
 
-        //Set up the surface
+        // Set up the surface
         mSurface = new SDLSurface(getApplication());
         setContentView(mSurface);
         SurfaceHolder holder = mSurface.getHolder();
@@ -60,11 +60,11 @@
         
     }
 
-    //Audio
+    // Audio
     public static boolean initAudio(){        
 
-        //blah. Hardcoded things are bad. FIXME when we have more sound stuff
-        //working properly. 
+        // blah. Hardcoded things are bad. FIXME when we have more sound stuff
+        // working properly. 
         mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
                     11025,
                     AudioFormat.CHANNEL_CONFIGURATION_MONO,
@@ -75,7 +75,7 @@
         return true;
     }
 
-    //Accel
+    // Accel
     public static boolean initAccel(){
         mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
         bAccelIsEnabled = true;
@@ -110,7 +110,7 @@
     public static native void onNativeAccel(float x, float y, float z);
 
 
-    //Java functions called from C
+    // Java functions called from C
     private static void createGLContext() {
         mSurface.initEGL();
     }
@@ -134,13 +134,13 @@
     public static void enableFeature(int featureid, int enabled) {
          Log.v("SDL","Feature " + featureid + " = " + enabled);
 
-        //Yuck. This is all horribly inelegent. If it gets to more than a few
-        //'features' I'll rip this out and make something nicer, I promise :)
+        // Yuck. This is all horribly inelegent. If it gets to more than a few
+        // 'features' I'll rip this out and make something nicer, I promise :)
         if(featureid == FEATURE_AUDIO){
             if(enabled == 1){
                 initAudio();
             }else{
-                //We don't have one of these yet...
+                // We don't have one of these yet...
                 //closeAudio(); 
             }
         }
@@ -241,11 +241,11 @@
             break;
         case PixelFormat.RGBA_4444:
             Log.v("SDL","pixel format RGBA_4444");
-            sdlFormat = 0x85421002; // Doesn't have an SDL constant...
+            sdlFormat = 0x85421002; // SDL_PIXELFORMAT_RGBA4444
             break;
         case PixelFormat.RGBA_5551:
             Log.v("SDL","pixel format RGBA_5551");
-            sdlFormat = 0x85441002; // Doesn't have an SDL constant...
+            sdlFormat = 0x85441002; // SDL_PIXELFORMAT_RGBA5551
             break;
         case PixelFormat.RGBA_8888:
             Log.v("SDL","pixel format RGBA_8888");
@@ -278,7 +278,7 @@
         }
     }
 
-    //unused
+    // unused
     public void onDraw(Canvas canvas) {}
 
 
@@ -332,7 +332,7 @@
 
             egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);
 
-            //drawing here
+            // drawing here
 
             egl.eglWaitGL();
 
@@ -370,14 +370,14 @@
         float y = event.getY();
         float p = event.getPressure();
 
-        //TODO: Anything else we need to pass?        
+        // TODO: Anything else we need to pass?        
         SDLActivity.onNativeTouch(action, x, y, p);
         return true;
     }
 
     // Sensor events
     public void enableSensor(int sensortype, boolean enabled) {
-        //TODO: This uses getDefaultSensor - what if we have >1 accels?
+        // TODO: This uses getDefaultSensor - what if we have >1 accels?
         if (enabled) {
             mSensorManager.registerListener(this, 
                             mSensorManager.getDefaultSensor(sensortype), 
@@ -389,7 +389,7 @@
     }
     
     public void onAccuracyChanged(Sensor sensor, int accuracy) {
-        //TODO
+        // TODO
     }
 
     public void onSensorChanged(SensorEvent event) {
--- a/include/SDL_pixels.h	Wed Jan 12 14:29:01 2011 -0800
+++ b/include/SDL_pixels.h	Wed Jan 12 14:53:23 2011 -0800
@@ -138,6 +138,7 @@
 #define SDL_ISPIXELFORMAT_FOURCC(format)    \
     ((format) && !((format) & 0x80000000))
 
+/* Note: If you modify this list, update SDL_GetPixelFormatName() */
 enum
 {
     SDL_PIXELFORMAT_UNKNOWN,
@@ -170,15 +171,27 @@
     SDL_PIXELFORMAT_ARGB4444 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
                                SDL_PACKEDLAYOUT_4444, 16, 2),
+    SDL_PIXELFORMAT_RGBA4444 =
+        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
+                               SDL_PACKEDLAYOUT_4444, 16, 2),
     SDL_PIXELFORMAT_ABGR4444 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
                                SDL_PACKEDLAYOUT_4444, 16, 2),
+    SDL_PIXELFORMAT_BGRA4444 =
+        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
+                               SDL_PACKEDLAYOUT_4444, 16, 2),
     SDL_PIXELFORMAT_ARGB1555 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ARGB,
                                SDL_PACKEDLAYOUT_1555, 16, 2),
+    SDL_PIXELFORMAT_RGBA5551 =
+        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_RGBA,
+                               SDL_PACKEDLAYOUT_5551, 16, 2),
     SDL_PIXELFORMAT_ABGR1555 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_ABGR,
                                SDL_PACKEDLAYOUT_1555, 16, 2),
+    SDL_PIXELFORMAT_BGRA5551 =
+        SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_BGRA,
+                               SDL_PACKEDLAYOUT_5551, 16, 2),
     SDL_PIXELFORMAT_RGB565 =
         SDL_DEFINE_PIXELFORMAT(SDL_PIXELTYPE_PACKED16, SDL_PACKEDORDER_XRGB,
                                SDL_PACKEDLAYOUT_565, 16, 2),
@@ -270,6 +283,11 @@
 } SDL_PixelFormat;
 
 /**
+ * \brief Get the human readable name of a pixel format
+ */
+extern DECLSPEC const char* SDLCALL SDL_GetPixelFormatName(Uint32 format);
+
+/**
  *  \brief Convert one of the enumerated pixel formats to a bpp and RGBA masks.
  *  
  *  \return SDL_TRUE, or SDL_FALSE if the conversion wasn't possible.
--- a/src/video/SDL_pixels.c	Wed Jan 12 14:29:01 2011 -0800
+++ b/src/video/SDL_pixels.c	Wed Jan 12 14:53:23 2011 -0800
@@ -39,6 +39,50 @@
 
 /* Helper functions */
 
+const char*
+SDL_GetPixelFormatName(Uint32 format)
+{
+    switch (format) {
+#define CASE(X) case X: return #X;
+    CASE(SDL_PIXELFORMAT_INDEX1LSB)
+    CASE(SDL_PIXELFORMAT_INDEX1MSB)
+    CASE(SDL_PIXELFORMAT_INDEX4LSB)
+    CASE(SDL_PIXELFORMAT_INDEX4MSB)
+    CASE(SDL_PIXELFORMAT_INDEX8)
+    CASE(SDL_PIXELFORMAT_RGB332)
+    CASE(SDL_PIXELFORMAT_RGB444)
+    CASE(SDL_PIXELFORMAT_RGB555)
+    CASE(SDL_PIXELFORMAT_BGR555)
+    CASE(SDL_PIXELFORMAT_ARGB4444)
+    CASE(SDL_PIXELFORMAT_RGBA4444)
+    CASE(SDL_PIXELFORMAT_ABGR4444)
+    CASE(SDL_PIXELFORMAT_BGRA4444)
+    CASE(SDL_PIXELFORMAT_ARGB1555)
+    CASE(SDL_PIXELFORMAT_RGBA5551)
+    CASE(SDL_PIXELFORMAT_ABGR1555)
+    CASE(SDL_PIXELFORMAT_BGRA5551)
+    CASE(SDL_PIXELFORMAT_RGB565)
+    CASE(SDL_PIXELFORMAT_BGR565)
+    CASE(SDL_PIXELFORMAT_RGB24)
+    CASE(SDL_PIXELFORMAT_BGR24)
+    CASE(SDL_PIXELFORMAT_RGB888)
+    CASE(SDL_PIXELFORMAT_BGR888)
+    CASE(SDL_PIXELFORMAT_ARGB8888)
+    CASE(SDL_PIXELFORMAT_RGBA8888)
+    CASE(SDL_PIXELFORMAT_ABGR8888)
+    CASE(SDL_PIXELFORMAT_BGRA8888)
+    CASE(SDL_PIXELFORMAT_ARGB2101010)
+    CASE(SDL_PIXELFORMAT_YV12)
+    CASE(SDL_PIXELFORMAT_IYUV)
+    CASE(SDL_PIXELFORMAT_YUY2)
+    CASE(SDL_PIXELFORMAT_UYVY)
+    CASE(SDL_PIXELFORMAT_YVYU)
+#undef CASE
+    default:
+        return "SDL_PIXELFORMAT_UNKNOWN";
+    }
+}
+
 SDL_bool
 SDL_PixelFormatEnumToMasks(Uint32 format, int *bpp, Uint32 * Rmask,
                            Uint32 * Gmask, Uint32 * Bmask, Uint32 * Amask)
--- a/test/common.c	Wed Jan 12 14:29:01 2011 -0800
+++ b/test/common.c	Wed Jan 12 14:53:23 2011 -0800
@@ -11,58 +11,6 @@
 #define AUDIO_USAGE \
 "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]"
 
-struct pformat {
-    Uint32 id;
-    const char* idstr;
-} pixel_format[]={
-    {SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"},
-    {SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"},
-    {SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"},
-    {SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"},
-    {SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"},
-    {SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"},
-    {SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"},
-    {SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"},
-    {SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"},
-    {SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"},
-    {SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"},
-    {SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"},
-    {SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"},
-    {SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"},
-    {SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"},
-    {SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"},
-    {SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"},
-    {SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"},
-    {SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"},
-    {SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"},
-    {SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"},
-    {SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"},
-    {SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"},
-    {SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"},
-    {SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"},
-    {SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"},
-    {SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"},
-    {SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"},
-    {SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"}
-};
-
-const char* PixelFormatToString(Uint32 pformat)
-{
-   Uint32 it=0;
-
-   do {
-      if (pixel_format[it].idstr == NULL) {
-          break;
-      }
-      if (pixel_format[it].id == pformat) {
-          return pixel_format[it].idstr;
-      }
-      it++;
-   } while(1);
-
-   return "SDL_PIXELFORMAT_UNKNOWN";
-}
-
 CommonState *
 CommonCreateState(char **argv, Uint32 flags)
 {
@@ -719,7 +667,7 @@
                 fprintf(stderr,
                         "  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
                         mode.w, mode.h, mode.refresh_rate, bpp,
-                        PixelFormatToString(mode.format));
+                        SDL_GetPixelFormatName(mode.format));
                 if (Rmask || Gmask || Bmask) {
                     fprintf(stderr, "      Red Mask   = 0x%.8x\n", Rmask);
                     fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
@@ -741,7 +689,7 @@
                         fprintf(stderr,
                                 "    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
                                 j, mode.w, mode.h, mode.refresh_rate, bpp,
-                                PixelFormatToString(mode.format));
+                                SDL_GetPixelFormatName(mode.format));
                         if (Rmask || Gmask || Bmask) {
                             fprintf(stderr, "        Red Mask   = 0x%.8x\n",
                                     Rmask);