Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Added some missing pixel formats and SDL_GetPixelFormatName()

  • Loading branch information
slouken committed Jan 12, 2011
1 parent fa851fd commit 2e10259910c0f15b148f3da8d059fe3d627f4a1a
Showing with 87 additions and 77 deletions.
  1. +23 −23 android-project/src/org/libsdl/app/SDLActivity.java
  2. +18 −0 include/SDL_pixels.h
  3. +44 −0 src/video/SDL_pixels.c
  4. +2 −54 test/common.c
@@ -24,47 +24,47 @@
*/
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();
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);

}

//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 @@ public static boolean initAudio(){
return true;
}

//Accel
// Accel
public static boolean initAccel(){
mSurface.enableSensor(Sensor.TYPE_ACCELEROMETER, true);
bAccelIsEnabled = true;
@@ -110,7 +110,7 @@ public static native void onNativeTouch(int action, float x,
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 updateAudio(byte [] buf) {
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 @@ public void surfaceChanged(SurfaceHolder holder,
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 @@ public void surfaceChanged(SurfaceHolder holder,
}
}

//unused
// unused
public void onDraw(Canvas canvas) {}


@@ -332,7 +332,7 @@ public void flipEGL() {

egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null);

//drawing here
// drawing here

egl.eglWaitGL();

@@ -370,14 +370,14 @@ public boolean onTouch(View v, MotionEvent event) {
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 enableSensor(int sensortype, boolean enabled) {
}

public void onAccuracyChanged(Sensor sensor, int accuracy) {
//TODO
// TODO
}

public void onSensorChanged(SensorEvent event) {
@@ -138,6 +138,7 @@ enum
#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 @@ enum
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),
@@ -269,6 +282,11 @@ typedef struct SDL_PixelFormat
Uint32 Amask;
} 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.
*
@@ -39,6 +39,50 @@ struct SDL_PaletteWatch

/* 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)
@@ -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 @@ CommonInit(CommonState * state)
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 @@ CommonInit(CommonState * state)
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);

0 comments on commit 2e10259

Please sign in to comment.