From: george82 Date: Wed, 16 Mar 2005 16:07:47 +0000 (+0000) Subject: Added PlayerOptions::setPF(). This function calculates all PixelFormat X-Git-Tag: v0.0.90~384^2~587 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7b1ebaea1467d981af59d0aff5429662f810b8fa;p=tigervnc.git Added PlayerOptions::setPF(). This function calculates all PixelFormat struct properties by rgb order, rm, gm, bm. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@248 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- diff --git a/rfbplayer/PlayerOptions.cxx b/rfbplayer/PlayerOptions.cxx index fc38c2de..aea0efea 100644 --- a/rfbplayer/PlayerOptions.cxx +++ b/rfbplayer/PlayerOptions.cxx @@ -72,4 +72,71 @@ void PlayerOptions::writeDefaults() { loopPlayback = DEFAULT_LOOP_PLAYBACK; askPixelFormat = DEFAULT_ASK_PF; autoStoreSettings = DEFAULT_STORE_SETTINGS; +} + +void PlayerOptions::setPF(PixelFormat *newPF) { + memcpy(&PF, newPF, sizeof(PixelFormat)); +} + +bool PlayerOptions::setPF(int rgb_order, int rm, int gm, int bm, bool big_endian) { + PixelFormat newPF; + + // Calculate the colour bits per pixel + int bpp = rm + gm + bm; + if (bpp < 0) { + return false; + } else if (bpp <= 8 ) { + newPF.bpp = 8; + } else if (bpp <= 16) { + newPF.bpp = 16; + } else if (bpp <= 32) { + newPF.bpp = 32; + } else { + return false; + } + newPF.depth = bpp; + + // Calculate the r, g and b bits shifts + switch (rgb_order) { + case RGB_ORDER: + newPF.redShift = gm + bm; + newPF.greenShift = bm; + newPF.blueShift = 0; + break; + case RBG_ORDER: + newPF.redShift = bm + gm; + newPF.blueShift = gm; + newPF.greenShift = 0; + break; + case GRB_ORDER: + newPF.greenShift = rm + bm; + newPF.redShift = bm; + newPF.blueShift = 0; + break; + case GBR_ORDER: + newPF.greenShift = bm + rm; + newPF.blueShift = rm; + newPF.redShift = 0; + break; + case BGR_ORDER: + newPF.blueShift = gm + rm; + newPF.greenShift = rm; + newPF.redShift = 0; + break; + case BRG_ORDER: + newPF.blueShift = rm + gm; + newPF.redShift = gm; + newPF.greenShift = 0; + break; + default: + return false; + } + + newPF.trueColour = true; + newPF.bigEndian = big_endian; + newPF.redMax = (1 << rm) - 1; + newPF.greenMax = (1 << gm) - 1; + newPF.blueMax = (1 << bm) - 1; + setPF(&newPF); + return true; } \ No newline at end of file diff --git a/rfbplayer/PlayerOptions.h b/rfbplayer/PlayerOptions.h index 79930c2c..2a56b3fe 100644 --- a/rfbplayer/PlayerOptions.h +++ b/rfbplayer/PlayerOptions.h @@ -23,6 +23,8 @@ #include +#include + #include // Supported pixel formats @@ -32,6 +34,14 @@ #define PF_D24_RGB888 3 #define PF_MODES 3 +// The R, G and B values order in the pixel +#define RGB_ORDER 0 +#define RBG_ORDER 1 +#define GRB_ORDER 2 +#define GBR_ORDER 3 +#define BGR_ORDER 4 +#define BRG_ORDER 5 + // Default options values #define DEFAULT_PF PF_AUTO #define DEFAULT_INIT_TIME -1 @@ -45,17 +55,22 @@ #define DEFAULT_FULL_SCREEN FALSE #define DEFAULT_STORE_SETTINGS FALSE +using namespace rfb; + class PlayerOptions { public: PlayerOptions(); void readFromRegistry(); void writeToRegistry(); void writeDefaults(); + void setPF(PixelFormat *pf); + bool setPF(int rgb_order, int rm, int gm, int bm, bool big_endian=false); long initTime; double playbackSpeed; bool autoPlay; bool fullScreen; long pixelFormat; + PixelFormat PF; bool acceptBell; bool acceptCutText; bool loopPlayback;