diff options
Diffstat (limited to 'src/Scaler.cxx')
-rw-r--r-- | src/Scaler.cxx | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/src/Scaler.cxx b/src/Scaler.cxx new file mode 100644 index 0000000..9e9af3c --- /dev/null +++ b/src/Scaler.cxx @@ -0,0 +1,170 @@ +namespace PluggIt { + +D_DEBUG_DOMAIN( PluggIt_Scaler, "PluggIt/Scaler", "PluggIt Scaler" ); + + +typedef struct { + DFBRegion clip; + const void *colors; + unsigned long protect; + unsigned long key; +} StretchCtx; + +typedef void (*StretchHVx)( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ); + +#define STRETCH_NONE 0 +#define STRETCH_SRCKEY 1 +#define STRETCH_PROTECT 2 +#define STRETCH_SRCKEY_PROTECT 3 +#define STRETCH_NUM 4 + +#define PIXEL_RGB16(r,g,b) ( (((r)&0xF8) << 8) | \ + (((g)&0xFC) << 3) | \ + (((b)&0xF8) >> 3) ) + +/**********************************************************************************************************************/ +/*** 16 bit RGB 565 scalers *******************************************************************************************/ +/**********************************************************************************************************************/ + +#define DST_FORMAT DSPF_RGB16 +#define TABLE_NAME stretch_hvx_RGB16 +#define FUNC_NAME(UPDOWN,K,P,F) stretch_hvx_RGB16_ ## UPDOWN ## _ ## K ## P ## _ ## F +#define SHIFT_R5 5 +#define SHIFT_R6 6 +#define X_F81F 0xf81f +#define X_07E0 0x07e0 +#define MASK_RGB 0xffff + +#define FORMAT_RGB16 +#include "stretch_up_down_16.h" +#undef FORMAT_RGB16 + +#undef DST_FORMAT +#undef TABLE_NAME +#undef FUNC_NAME +#undef SHIFT_R5 +#undef SHIFT_R6 +#undef X_F81F +#undef X_07E0 +#undef MASK_RGB + +/**********************************************************************************************************************/ +/*** 32 bit RGB 8888 scalers ******************************************************************************************/ +/**********************************************************************************************************************/ + +#define DST_FORMAT DSPF_ARGB +#define TABLE_NAME stretch_hvx_ARGB +#define FUNC_NAME(UPDOWN,K,P,F) stretch_hvx_ARGB_ ## UPDOWN ## _ ## K ## P ## _ ## F +#define SHIFT_R8 8 +#define SHIFT_L8 8 +#define X_00FF00FF 0x00ff00ff +#define X_FF00FF00 0xff00ff00 +#define MASK_RGB 0x00ffffff + +#define FORMAT_ARGB +#include "stretch_up_down_32.h" +#undef FORMAT_ARGB + +#undef DST_FORMAT +#undef TABLE_NAME +#undef FUNC_NAME +#undef SHIFT_R8 +#undef SHIFT_L8 +#undef X_00FF00FF +#undef X_FF00FF00 +#undef MASK_RGB + +/**********************************************************************************************************************/ +/*** 32 bit RGB 8888 scalers ******************************************************************************************/ +/**********************************************************************************************************************/ + +#define DST_FORMAT DSPF_RGB32 +#define TABLE_NAME stretch_hvx_RGB32 +#define FUNC_NAME(UPDOWN,K,P,F) stretch_hvx_RGB32_ ## UPDOWN ## _ ## K ## P ## _ ## F +#define SHIFT_R8 8 +#define SHIFT_L8 8 +#define X_00FF00FF 0x00ff00ff +#define X_FF00FF00 0x0000ff00 +#define MASK_RGB 0x00ffffff + +#define FORMAT_RGB32 +#include "stretch_up_down_32.h" +#undef FORMAT_RGB32 + +#undef DST_FORMAT +#undef TABLE_NAME +#undef FUNC_NAME +#undef SHIFT_R8 +#undef SHIFT_L8 +#undef X_00FF00FF +#undef X_FF00FF00 +#undef MASK_RGB + + +class Scaler +{ + + public Scaler() { + } + + public void scale( DFBSurfacePixelFormat format, + void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const DFBRegion &clip ) + { + D_DEBUG_AT( PluggIt_Scaler, "%s( %s, %p [%d], %p [%d], %dx%d -> %dx%d, clip %4d,%4d-%4dx%4d )\n", + __FUNCTION__, dfb_pixelformat_name( format ), dst, dpitch, src, spitch, width, height, + dst_width, dst_height, DFB_RECTANGLE_VALS_FROM_REGION( &clip ) ); + + + StretchCtx ctx; + + ctx.clip = clip; + + switch (format) { + case DSPF_RGB16: + if (width <= dst_width || height <= dst_height) + stretch_hvx_RGB16_up____DSPF_RGB32( dst, dpitch, src, spitch, width, height, dst_width, dst_height, &ctx ); + else + stretch_hvx_RGB16_down____DSPF_RGB32( dst, dpitch, src, spitch, width, height, dst_width, dst_height, &ctx ); + break; + + case DSPF_RGB32: + if (width <= dst_width || height <= dst_height) + stretch_hvx_RGB32_up____DSPF_RGB32( dst, dpitch, src, spitch, width, height, dst_width, dst_height, &ctx ); + else + stretch_hvx_RGB32_down____DSPF_RGB32( dst, dpitch, src, spitch, width, height, dst_width, dst_height, &ctx ); + break; + + case DSPF_ARGB: + if (width <= dst_width || height <= dst_height) + stretch_hvx_ARGB_up____DSPF_RGB32( dst, dpitch, src, spitch, width, height, dst_width, dst_height, &ctx ); + else + stretch_hvx_ARGB_down____DSPF_RGB32( dst, dpitch, src, spitch, width, height, dst_width, dst_height, &ctx ); + break; + + default: + D_UNIMPLEMENTED(); + break; + } + } +}; + + + +} + |