From 27d1e03d7bdf8fcfe7292c06e40bc3e2fca9158e Mon Sep 17 00:00:00 2001 From: Denis Oliver Kropp Date: Tue, 19 Oct 2010 15:56:15 +0200 Subject: pluggit --- src/classes.cpp | 4047 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 4047 insertions(+) create mode 100644 src/classes.cpp (limited to 'src/classes.cpp') diff --git a/src/classes.cpp b/src/classes.cpp new file mode 100644 index 0000000..a0ecb67 --- /dev/null +++ b/src/classes.cpp @@ -0,0 +1,4047 @@ +# 1 "classes.h" +#define DIRECT_ENABLE_DEBUG + + +#include +#include + +using namespace std; + + +/* + * ++DFB + */ +#include <++dfb.h> + + + +/* + * Direct + */ +extern "C" { +#include + +#include +#include +#include +#include +#include +#include + +#include +} + + +/* + * Win32 + */ +#ifdef __WIN32__ +#define CreateWindow CreateWindowWin32 +#include +#include +#include +#include "videodriver.h" +#undef CreateWindow + +#else + +/* + * X11 + */ +extern "C" { +#include /* fundamentals X datas structures */ +#include /* datas definitions for various functions */ +#include /* for a perfect use of keyboard events */ +#include +#include + +#include +#include +#include +#include +} + +#endif + +class Exception; +class OutOfMemoryException; +class Clock; +class FPS; +class Options; +class Random; +class Updates; +class Runnable; +class Thread; +class Scaler; +class View; +class Source; +class SourceWin32; +class Main; +# 1 "Exception.cxx" +# 1 "" +# 1 "" +# 1 "Exception.cxx" +namespace PluggIt { + +class Exception +{ + private: string m_message; + + + public: Exception( string message ) { + m_message = message; + } + + public: Exception( const char *format, ... ) D_FORMAT_PRINTF(2) { + va_list args; + int len; + char buf[200]; + char *ptr = buf; + + va_start( args, format ); + len = vsnprintf( buf, sizeof(buf), format, args ); + va_end( args ); + + if (len < 0) + abort(); + + if (len >= (int)sizeof(buf)) { + ptr = (char*) malloc( len+1 ); + if (!ptr) + abort(); + + va_start( args, format ); + len = vsnprintf( ptr, len+1, format, args ); + va_end( args ); + + if (len < 0) { + free( ptr ); + abort(); + } + } + + m_message = string( ptr ); + + if (ptr != buf) + free( ptr ); + } + + public: string getMessage() { + return m_message; + } + + + friend std::ostream &operator << (std::ostream &stream, Exception *ex) { + stream << ex->getMessage(); + + return stream; + } +}; + +} +# 1 "OutOfMemoryException.cxx" +# 1 "" +# 1 "" +# 1 "OutOfMemoryException.cxx" +namespace PluggIt { + +class OutOfMemoryException :public Exception +{ + public: OutOfMemoryException() : Exception( "Out of memory!" ) { + } +}; + +} +# 1 "Clock.cxx" +# 1 "" +# 1 "" +# 1 "Clock.cxx" +namespace PluggIt { + +class Clock +{ + private: long long base; + private: char str[20]; + + public: Clock() { + Reset(); + } + + public: void Reset() { + base = direct_clock_get_micros(); + } + + public: float GetTime() { + return (direct_clock_get_micros() - base) / 1000000.0f; + } + + public: const char *GetString() { + float time = GetTime(); + int seconds = (int) time; + int minutes = seconds / 60; + + snprintf( str, sizeof(str), "%02d:%02d", minutes, seconds ); + + return str; + } +}; + +} +# 1 "FPS.cxx" +# 1 "" +# 1 "" +# 1 "FPS.cxx" +namespace PluggIt { + +class FPS +{ + private: int frames; + private: char str[20]; + + private: Clock clock; + + + public: FPS() { + Reset(); + } + + public: void Reset() { + frames = 0; + str[0] = 0; + + clock.Reset(); + } + + public: void Count( float interval ) { + float time = clock.GetTime(); + + frames++; + + if (time >= interval) { + float fps = frames / time; + + snprintf( str, sizeof(str), "%.1f", fps ); + + frames = 0; + clock.Reset(); + } + } + + public: const char *GetFPS() { + return str; + } +}; + +} +# 1 "Options.cxx" +# 1 "" +# 1 "" +# 1 "Options.cxx" +namespace PluggIt { + +static const DirectFBPixelFormatNames(m_formats); + +class Options +{ + class Option { + friend class Options; + + protected: const char *m_short_name; + protected: const char *m_long_name; + protected: const char *m_arg_name; + protected: const char *m_arg_desc; + protected: bool m_need_arg; + + public: Option( const char *short_name, + const char *long_name, + const char *arg_name, + const char *arg_desc ) + { + m_short_name = short_name; + m_long_name = long_name; + m_arg_name = arg_name; + m_arg_desc = arg_desc; + m_need_arg = true; + } + + public: virtual bool Parse( const char *arg ) = 0; + }; + + public: class OptionBool :public Option { + private: bool &m_value; + + public: OptionBool( const char *short_name, + const char *long_name, + const char *arg_name, + const char *arg_desc, + bool &value ) : Option( short_name, long_name, arg_name, arg_desc ), m_value( value ) + { + m_need_arg = false; + } + + public: virtual bool Parse( const char *arg ) { + m_value = true; + + return true; + } + }; + + public: class OptionLong :public Option { + private: long &m_value; + private: int m_base; + + public: OptionLong( const char *short_name, + const char *long_name, + const char *arg_name, + const char *arg_desc, + long &value, + int base = 10 ) : Option( short_name, long_name, arg_name, arg_desc ), m_value( value ) + { + m_base = base; + } + + public: virtual bool Parse( const char *arg ) { + long ret; + char *end; + + ret = strtol( arg, &end, m_base ); + + if (*end) { + D_ERROR( "Option/Long: Invalid argument to '%s' or '%s'!\n", m_short_name, m_long_name ); + return false; + } + + m_value = ret; + + return true; + } + }; + + public: class OptionULong :public Option { + private: unsigned long &m_value; + private: int m_base; + + public: OptionULong( const char *short_name, + const char *long_name, + const char *arg_name, + const char *arg_desc, + unsigned long &value, + int base = 10 ) : Option( short_name, long_name, arg_name, arg_desc ), m_value( value ) + { + m_base = base; + } + + public: virtual bool Parse( const char *arg ) { + unsigned long ret; + char *end; + + ret = strtoul( arg, &end, m_base ); + + if (*end) { + D_ERROR( "Option/ULong: Invalid argument to '%s' or '%s'!\n", m_short_name, m_long_name ); + return false; + } + + m_value = ret; + + return true; + } + }; + + public: class OptionFormat :public Option { + private: DFBSurfacePixelFormat &m_value; + + public: OptionFormat( const char *short_name, + const char *long_name, + const char *arg_name, + const char *arg_desc, + DFBSurfacePixelFormat &value ) : Option( short_name, long_name, arg_name, arg_desc ), m_value( value ) + { + } + + public: virtual bool Parse( const char *arg ) { + unsigned int i; + + for (i=0; i m_options; + + public: void addOption( Option *option ) { + m_options.push_back( option ); + } + + public: bool parseCommandLine( int argc, char *argv[] ) { + int n; + + for (n = 1; n < argc; n++) { + bool ok = false; + const char *arg = argv[n]; + + if (strcmp (arg, "-h") == 0 || strcmp (arg, "--help") == 0) { + printUsage (argv[0]); + return false; + } + + if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) { + + return false; + } + + vector::iterator itr = m_options.begin(); + + for (; itr != m_options.end(); itr++) { + Option *option = *itr; + + if (!strcmp (arg, option->m_short_name) || !strcmp (arg, option->m_long_name)) { + if (option->m_need_arg && ++n == argc) { + printUsage (argv[0]); + return false; + } + + if (!option->Parse( argv[n] )) + return false; + + ok = true; + + break; + } + } + + if (!ok) { + printUsage (argv[0]); + return false; + } + } + + return true; + } + + public: void printUsage( const char *prg_name ) { + + fprintf (stderr, "Usage: %s [options]\n\n", prg_name); + fprintf (stderr, "Options:\n"); + fprintf (stderr, " -h --help Show this help message\n"); + fprintf (stderr, " -v --version Print version information\n"); + + + vector::const_iterator itr = m_options.begin(); + + for (; itr != m_options.end(); itr++) { + const Option *option = *itr; + + fprintf( stderr, " %-3s %-16s %-12s %s\n", + option->m_short_name, option->m_long_name, option->m_arg_name, option->m_arg_desc ); + } + + fprintf( stderr, "\n" ); + } +}; + +} +# 1 "Random.cxx" +# 1 "" +# 1 "" +# 1 "Random.cxx" +namespace PluggIt { + +class Random +{ + public: static float nextFloat( float min, float max ) { + return min + rand() * (max - min) / (float) RAND_MAX; + } +}; + +} +# 1 "Updates.cxx" +# 1 "" +# 1 "" +# 1 "Updates.cxx" +namespace PluggIt { + +class Updates +{ + private: DFBUpdates m_updates; + private: DFBRegion *m_regions; + + public: Updates( unsigned int max_regions = 8 ) { + m_regions = (DFBRegion*) D_CALLOC( max_regions ?: 1, sizeof(DFBRegion) ); + + dfb_updates_init( &m_updates, m_regions, max_regions ); + } + + virtual ~Updates() { + dfb_updates_deinit( &m_updates ); + + D_FREE( m_regions ); + } + + + public: void addRegion( const DFBRegion ®ion ) { + dfb_updates_add( &m_updates, ®ion ); + } + + public: DFBRegion bounding() const { + return m_updates.bounding; + } + + public: void get_rectangles( DFBRectangle *ret_rects, int *ret_num ) { + dfb_updates_get_rectangles( &m_updates, ret_rects, ret_num ); + } + + public: unsigned int num_regions() const { + return m_updates.num_regions; + } + + public: void reset() { + dfb_updates_reset( &m_updates ); + } + + + public: void GetRectangles( vector &rects ) { + D_MAGIC_ASSERT( &m_updates, DFBUpdates ); + D_ASSERT( m_updates.regions != NULL ); + D_ASSERT( m_updates.num_regions >= 0 ); + D_ASSERT( m_updates.num_regions <= m_updates.max_regions ); + + switch (m_updates.num_regions) { + case 0: + break; + + default: { + int n, d, total, bounding; + + dfb_updates_stat( &m_updates, &total, &bounding ); + + n = m_updates.max_regions - m_updates.num_regions + 1; + d = n + 1; + + + if (total < bounding * n / d) { + for (n=0; n" +# 1 "" +# 1 "Runnable.cxx" +namespace PluggIt { + +class Runnable +{ + public: virtual void run() = 0; +}; + +} +# 1 "Thread.cxx" +# 1 "" +# 1 "" +# 1 "Thread.cxx" +namespace PluggIt { + +class Thread +{ + private: Runnable *m_target; + private: string m_name; + + private: DirectThread *m_thread; + private: volatile bool m_interrupted; + + + public: Thread( Runnable *target, string name = "" ) { + m_target = target; + m_name = name; + + m_thread = NULL; + m_interrupted = false; + } + + virtual ~Thread() { + if (m_thread) + direct_thread_destroy( m_thread ); + } + + public: bool start() { + if (m_thread) + return false; + + m_thread = direct_thread_create( DTT_DEFAULT, main, m_target, m_name.c_str() ); + + return m_thread != NULL; + } + + public: bool interrupt() { + if (!m_thread) + return false; + + m_interrupted = true; + + return true; + } + + public: bool isInterrupted() { + return m_interrupted; + } + + public: bool join() { + if (!m_thread) + return false; + + direct_thread_join( m_thread ); + direct_thread_destroy( m_thread ); + + m_thread = NULL; + m_interrupted = false; + + return true; + } + + + private: static void *main( DirectThread *thread, void *arg ) { + Runnable *target = (Runnable*) arg; + + target->run(); + + return NULL; + } +}; + +} +# 1 "Scaler.cxx" +# 1 "" +# 1 "" +# 1 "Scaler.cxx" +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 ); +# 47 "Scaler.cxx" +# 1 "stretch_up_down_16.h" 1 +# 20 "stretch_up_down_16.h" +# 1 "stretch_hvx_N.h" 1 +# 9 "stretch_hvx_N.h" +static void stretch_hvx_RGB16_up____DSPF_RGB16 +# 1 "stretch_hvx_16.h" 1 +# 35 "stretch_hvx_16.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y, r = 0; + long head = ((((unsigned long) dst) & 2) >> 1) ^ (ctx->clip.x1 & 1); + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long tail = (cw - head) & 1; + long w2 = (cw - head) / 2; + long hfraq = ((long)(width - 1) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 1) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = 0 + ctx->clip.x1 * hfraq; + long point = point0; + long line = 0 + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + + u32 _lbT[w2+8]; + u32 _lbB[w2+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; x> (18-6) ); + + point += hfraq; + } + + do {} while (0); + + + dst = (void*)((char*) dst + ctx->clip.x1 * 2 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + if (head) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*) dst; + + point = point0; + + for (y=0; y> (18-5) ); + + const u16 *srcT = (const u16 *)((char*) src + spitch * ( (((line)) >> 18) )); + const u16 *srcB = (const u16 *)((char*) src + spitch * ( (((line)) >> 18) + 1 )); + + + + + long pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 138 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + + + point0 += hfraq; + dst32 = (u32*)((char*) dst + 2); + + + line = 0 + ctx->clip.y1 * vfraq; + } + + + + + for (y=0; y> 18) ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R, dpT, dpB; + const u16 *srcT = (const u16 *)((char*) src + spitch * nlT); + const u16 *srcB = (const u16 *)((char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, r=head, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbT[x] = dpT; + lbB[x] = dpB; + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, r=head, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbB[x] = dpB; + } + } + + lineT = nlT; + } + + + + + X = ( ((line) & 0x3ffff) >> (18-5) ); + + for (x=0; x> 5) + (lbT[x] & ((0x07e0<<16) | 0xf81f))) & ((0x07e0<<16) | 0xf81f)) + + ((((((lbB[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)) - ((lbT[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)))*X) + (lbT[x] & ((0xf81f<<16) | 0x07e0))) & ((0xf81f<<16) | 0x07e0)); + + + } + + dst32 += dp4; + line += vfraq; + } + + if (tail) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*)((char*) dst + cw * 2 - 2); + + + line = 0 + ctx->clip.y1 * vfraq; + + for (y=0; y> (18-5) ); + + const u16 *srcT = (const u16 *)((char*) src + spitch * ( (((line)) >> 18) )); + const u16 *srcB = (const u16 *)((char*) src + spitch * ( (((line)) >> 18) + 1 )); + + + + + long pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 434 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + } +} +# 11 "stretch_hvx_N.h" 2 +# 20 "stretch_hvx_N.h" +static void stretch_hvx_RGB16_up____DSPF_RGB32 +# 1 "stretch_hvx_16.h" 1 +# 35 "stretch_hvx_16.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y, r = 0; + long head = ((((unsigned long) dst) & 2) >> 1) ^ (ctx->clip.x1 & 1); + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long tail = (cw - head) & 1; + long w2 = (cw - head) / 2; + long hfraq = ((long)(width - 1) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 1) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = 0 + ctx->clip.x1 * hfraq; + long point = point0; + long line = 0 + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + + u32 _lbT[w2+8]; + u32 _lbB[w2+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; x> (18-6) ); + + point += hfraq; + } + + do {} while (0); + + + dst = (void*)((char*) dst + ctx->clip.x1 * 2 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + if (head) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*) dst; + + point = point0; + + for (y=0; y> (18-5) ); + + const u32 *srcT = (const u32 *)((char*) src + spitch * ( (((line)) >> 18) )); + const u32 *srcB = (const u32 *)((char*) src + spitch * ( (((line)) >> 18) + 1 )); + + + + + long pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 138 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + + + point0 += hfraq; + dst32 = (u32*)((char*) dst + 2); + + + line = 0 + ctx->clip.y1 * vfraq; + } + + + + + for (y=0; y> 18) ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R, dpT, dpB; + const u32 *srcT = (const u32 *)((char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, r=head, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbT[x] = dpT; + lbB[x] = dpB; + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, r=head, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbB[x] = dpB; + } + } + + lineT = nlT; + } + + + + + X = ( ((line) & 0x3ffff) >> (18-5) ); + + for (x=0; x> 5) + (lbT[x] & ((0x07e0<<16) | 0xf81f))) & ((0x07e0<<16) | 0xf81f)) + + ((((((lbB[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)) - ((lbT[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)))*X) + (lbT[x] & ((0xf81f<<16) | 0x07e0))) & ((0xf81f<<16) | 0x07e0)); + + + } + + dst32 += dp4; + line += vfraq; + } + + if (tail) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*)((char*) dst + cw * 2 - 2); + + + line = 0 + ctx->clip.y1 * vfraq; + + for (y=0; y> (18-5) ); + + const u32 *srcT = (const u32 *)((char*) src + spitch * ( (((line)) >> 18) )); + const u32 *srcB = (const u32 *)((char*) src + spitch * ( (((line)) >> 18) + 1 )); + + + + + long pl = ( (((point)) >> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 434 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + } +} +# 22 "stretch_hvx_N.h" 2 +# 21 "stretch_up_down_16.h" 2 +# 49 "stretch_up_down_16.h" +# 1 "stretch_hvx_N.h" 1 +# 9 "stretch_hvx_N.h" +static void stretch_hvx_RGB16_down____DSPF_RGB16 +# 1 "stretch_hvx_16.h" 1 +# 35 "stretch_hvx_16.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y, r = 0; + long head = ((((unsigned long) dst) & 2) >> 1) ^ (ctx->clip.x1 & 1); + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long tail = (cw - head) & 1; + long w2 = (cw - head) / 2; + long hfraq = ((long)(width - 0) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 0) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = hfraq + ctx->clip.x1 * hfraq; + long point = point0; + long line = vfraq + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + + u32 _lbT[w2+8]; + u32 _lbB[w2+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; xclip.x1 * 2 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + if (head) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*) dst; + + point = point0; + + for (y=0; y> 18) - 1 )); + const u16 *srcB = (const u16 *)((char*) src + spitch * ( (((line)-1) >> 18) )); + + + + + long pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 138 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + + + point0 += hfraq; + dst32 = (u32*)((char*) dst + 2); + + + line = vfraq + ctx->clip.y1 * vfraq; + } + + + + + for (y=0; y> 18) - 1 ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R, dpT, dpB; + const u16 *srcT = (const u16 *)((char*) src + spitch * nlT); + const u16 *srcB = (const u16 *)((char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, r=head, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbT[x] = dpT; + lbB[x] = dpB; + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, r=head, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbB[x] = dpB; + } + } + + lineT = nlT; + } + + + + + X = ( (((((line)) & 0x3ffff) ? : 0x40000) << 5) / (vfraq) ); + + for (x=0; x> 5) + (lbT[x] & ((0x07e0<<16) | 0xf81f))) & ((0x07e0<<16) | 0xf81f)) + + ((((((lbB[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)) - ((lbT[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)))*X) + (lbT[x] & ((0xf81f<<16) | 0x07e0))) & ((0xf81f<<16) | 0x07e0)); + + + } + + dst32 += dp4; + line += vfraq; + } + + if (tail) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*)((char*) dst + cw * 2 - 2); + + + line = vfraq + ctx->clip.y1 * vfraq; + + for (y=0; y> 18) - 1 )); + const u16 *srcB = (const u16 *)((char*) src + spitch * ( (((line)-1) >> 18) )); + + + + + long pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = (srcT[pl]); + R = (srcT[pl+1]); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = (srcB[pl]); + R = (srcB[pl+1]); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 434 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + } +} +# 11 "stretch_hvx_N.h" 2 +# 20 "stretch_hvx_N.h" +static void stretch_hvx_RGB16_down____DSPF_RGB32 +# 1 "stretch_hvx_16.h" 1 +# 35 "stretch_hvx_16.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y, r = 0; + long head = ((((unsigned long) dst) & 2) >> 1) ^ (ctx->clip.x1 & 1); + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long tail = (cw - head) & 1; + long w2 = (cw - head) / 2; + long hfraq = ((long)(width - 0) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 0) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = hfraq + ctx->clip.x1 * hfraq; + long point = point0; + long line = vfraq + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + + u32 _lbT[w2+8]; + u32 _lbB[w2+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; xclip.x1 * 2 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + if (head) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*) dst; + + point = point0; + + for (y=0; y> 18) - 1 )); + const u32 *srcB = (const u32 *)((char*) src + spitch * ( (((line)-1) >> 18) )); + + + + + long pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 138 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + + + point0 += hfraq; + dst32 = (u32*)((char*) dst + 2); + + + line = vfraq + ctx->clip.y1 * vfraq; + } + + + + + for (y=0; y> 18) - 1 ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R, dpT, dpB; + const u32 *srcT = (const u32 *)((char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, r=head, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbT[x] = dpT; + lbB[x] = dpB; + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, r=head, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + >> 6; + + + point += hfraq; + r++; + + + pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB |= (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) + + + + << (16-6); + + + point += hfraq; + r++; + + + lbB[x] = dpB; + } + } + + lineT = nlT; + } + + + + + X = ( (((((line)) & 0x3ffff) ? : 0x40000) << 5) / (vfraq) ); + + for (x=0; x> 5) + (lbT[x] & ((0x07e0<<16) | 0xf81f))) & ((0x07e0<<16) | 0xf81f)) + + ((((((lbB[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)) - ((lbT[x]>>5) & (((0xf81f<<16) | 0x07e0)>>5)))*X) + (lbT[x] & ((0xf81f<<16) | 0x07e0))) & ((0xf81f<<16) | 0x07e0)); + + + } + + dst32 += dp4; + line += vfraq; + } + + if (tail) { + u32 dpT, dpB, L, R; + + u16 *dst16 = (u16*)((char*) dst + cw * 2 - 2); + + + line = vfraq + ctx->clip.y1 * vfraq; + + for (y=0; y> 18) - 1 )); + const u32 *srcB = (const u32 *)((char*) src + spitch * ( (((line)-1) >> 18) )); + + + + + long pl = ( (((point)-1) >> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + L = ( (((((srcT[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcT[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcT[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcT[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpT = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; + + L = ( (((((srcB[pl]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl]) & 0x0000ff))&0xF8) >> 3) ); + R = ( (((((srcB[pl+1]) & 0xff0000) >> 16)&0xF8) << 8) | (((((srcB[pl+1]) & 0x00ff00) >> 8)&0xFC) << 3) | (((((srcB[pl+1]) & 0x0000ff))&0xF8) >> 3) ); + + dpB = (((((R & 0xf81f)-(L & 0xf81f))*ratios[r] + ((L & 0xf81f)<<6)) & (0xf81f<<6)) + + ((((R & 0x07e0)-(L & 0x07e0))*ratios[r] + ((L & 0x07e0)<<6)) & (0x07e0<<6))) >> 6; +# 434 "stretch_hvx_16.h" + dst16[0] = ((((((dpB & 0xf81f) - (dpT & 0xf81f))*X) >> 5) + (dpT & 0xf81f)) & 0xf81f) + + ((((((dpB>>5) & (0x07e0>>5)) - ((dpT>>5) & (0x07e0>>5)))*X) + (dpT & 0x07e0)) & 0x07e0); + + + dst16 += dpitch / 2; + line += vfraq; + } + } +} +# 22 "stretch_hvx_N.h" 2 +# 50 "stretch_up_down_16.h" 2 +# 48 "Scaler.cxx" 2 +# 73 "Scaler.cxx" +# 1 "stretch_up_down_32.h" 1 +# 20 "stretch_up_down_32.h" +# 1 "stretch_hvx_N.h" 1 +# 9 "stretch_hvx_N.h" +static void stretch_hvx_ARGB_up____DSPF_ARGB +# 1 "stretch_hvx_32.h" 1 +# 11 "stretch_hvx_32.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y = 0; + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long hfraq = ((long)(width - 1) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 1) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = 0 + ctx->clip.x1 * hfraq; + long point = point0; + long line = 0 + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + u32 _lbT[cw+8]; + u32 _lbB[cw+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; x> (18-8) ); + + point += hfraq; + } + + do {} while (0); + + dst = (void*)((char*) dst + ctx->clip.x1 * 4 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + + + + for (y=0; y> 18) ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R; + const u32 *srcT = (const u32 *)((const char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((const char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcT[pl]); + R = (srcT[pl+1]); + + lbT[x]= ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + + lineT = nlT; + } + + + + + X = ( ((line) & 0x3ffff) >> (18-8) ); + + for (x=0; x> 8) + (lbT[x] & 0x00ff00ff)) & 0x00ff00ff) + + ((((((lbB[x]>>8) & 0x00ff00ff) - ((lbT[x]>>8) & 0x00ff00ff))*X) + (lbT[x] & 0xff00ff00)) & 0xff00ff00); + + } + + dst32 += dp4; + line += vfraq; + } +} +# 11 "stretch_hvx_N.h" 2 +# 33 "stretch_hvx_N.h" +static void stretch_hvx_ARGB_up____DSPF_RGB32 +# 1 "stretch_hvx_32.h" 1 +# 11 "stretch_hvx_32.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y = 0; + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long hfraq = ((long)(width - 1) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 1) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = 0 + ctx->clip.x1 * hfraq; + long point = point0; + long line = 0 + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + u32 _lbT[cw+8]; + u32 _lbB[cw+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; x> (18-8) ); + + point += hfraq; + } + + do {} while (0); + + dst = (void*)((char*) dst + ctx->clip.x1 * 4 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + + + + for (y=0; y> 18) ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R; + const u32 *srcT = (const u32 *)((const char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((const char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ((srcT[pl]) | 0xff000000); + R = ((srcT[pl+1]) | 0xff000000); + + lbT[x]= ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + + L = ((srcB[pl]) | 0xff000000); + R = ((srcB[pl+1]) | 0xff000000); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ((srcB[pl]) | 0xff000000); + R = ((srcB[pl+1]) | 0xff000000); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + + lineT = nlT; + } + + + + + X = ( ((line) & 0x3ffff) >> (18-8) ); + + for (x=0; x> 8) + (lbT[x] & 0x00ff00ff)) & 0x00ff00ff) + + ((((((lbB[x]>>8) & 0x00ff00ff) - ((lbT[x]>>8) & 0x00ff00ff))*X) + (lbT[x] & 0xff00ff00)) & 0xff00ff00); + + } + + dst32 += dp4; + line += vfraq; + } +} +# 35 "stretch_hvx_N.h" 2 +# 21 "stretch_up_down_32.h" 2 +# 49 "stretch_up_down_32.h" +# 1 "stretch_hvx_N.h" 1 +# 9 "stretch_hvx_N.h" +static void stretch_hvx_ARGB_down____DSPF_ARGB +# 1 "stretch_hvx_32.h" 1 +# 11 "stretch_hvx_32.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y = 0; + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long hfraq = ((long)(width - 0) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 0) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = hfraq + ctx->clip.x1 * hfraq; + long point = point0; + long line = vfraq + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + u32 _lbT[cw+8]; + u32 _lbB[cw+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; xclip.x1 * 4 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + + + + for (y=0; y> 18) - 1 ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R; + const u32 *srcT = (const u32 *)((const char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((const char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcT[pl]); + R = (srcT[pl+1]); + + lbT[x]= ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + + lineT = nlT; + } + + + + + X = ( (((((line)) & 0x3ffff) ? : 0x40000) << 8) / (vfraq) ); + + for (x=0; x> 8) + (lbT[x] & 0x00ff00ff)) & 0x00ff00ff) + + ((((((lbB[x]>>8) & 0x00ff00ff) - ((lbT[x]>>8) & 0x00ff00ff))*X) + (lbT[x] & 0xff00ff00)) & 0xff00ff00); + + } + + dst32 += dp4; + line += vfraq; + } +} +# 11 "stretch_hvx_N.h" 2 +# 33 "stretch_hvx_N.h" +static void stretch_hvx_ARGB_down____DSPF_RGB32 +# 1 "stretch_hvx_32.h" 1 +# 11 "stretch_hvx_32.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y = 0; + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long hfraq = ((long)(width - 0) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 0) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = hfraq + ctx->clip.x1 * hfraq; + long point = point0; + long line = vfraq + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + u32 _lbT[cw+8]; + u32 _lbB[cw+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; xclip.x1 * 4 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + + + + for (y=0; y> 18) - 1 ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R; + const u32 *srcT = (const u32 *)((const char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((const char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ((srcT[pl]) | 0xff000000); + R = ((srcT[pl+1]) | 0xff000000); + + lbT[x]= ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + + L = ((srcB[pl]) | 0xff000000); + R = ((srcB[pl+1]) | 0xff000000); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = ((srcB[pl]) | 0xff000000); + R = ((srcB[pl+1]) | 0xff000000); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0xff00ff00)) & 0xff00ff00); + } + } + + lineT = nlT; + } + + + + + X = ( (((((line)) & 0x3ffff) ? : 0x40000) << 8) / (vfraq) ); + + for (x=0; x> 8) + (lbT[x] & 0x00ff00ff)) & 0x00ff00ff) + + ((((((lbB[x]>>8) & 0x00ff00ff) - ((lbT[x]>>8) & 0x00ff00ff))*X) + (lbT[x] & 0xff00ff00)) & 0xff00ff00); + + } + + dst32 += dp4; + line += vfraq; + } +} +# 35 "stretch_hvx_N.h" 2 +# 50 "stretch_up_down_32.h" 2 +# 74 "Scaler.cxx" 2 +# 99 "Scaler.cxx" +# 1 "stretch_up_down_32.h" 1 +# 20 "stretch_up_down_32.h" +# 1 "stretch_hvx_N.h" 1 +# 9 "stretch_hvx_N.h" +static void stretch_hvx_RGB32_up____DSPF_RGB32 +# 1 "stretch_hvx_32.h" 1 +# 11 "stretch_hvx_32.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y = 0; + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long hfraq = ((long)(width - 1) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 1) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = 0 + ctx->clip.x1 * hfraq; + long point = point0; + long line = 0 + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + u32 _lbT[cw+8]; + u32 _lbB[cw+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; x> (18-8) ); + + point += hfraq; + } + + do {} while (0); + + dst = (void*)((char*) dst + ctx->clip.x1 * 4 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + + + + for (y=0; y> 18) ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R; + const u32 *srcT = (const u32 *)((const char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((const char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcT[pl]); + R = (srcT[pl+1]); + + lbT[x]= ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0x0000ff00)) & 0x0000ff00); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0x0000ff00)) & 0x0000ff00); + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, point=point0; x> 18) ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0x0000ff00)) & 0x0000ff00); + } + } + + lineT = nlT; + } + + + + + X = ( ((line) & 0x3ffff) >> (18-8) ); + + for (x=0; x> 8) + (lbT[x] & 0x00ff00ff)) & 0x00ff00ff) + + ((((((lbB[x]>>8) & 0x00ff00ff) - ((lbT[x]>>8) & 0x00ff00ff))*X) + (lbT[x] & 0x0000ff00)) & 0x0000ff00); + + } + + dst32 += dp4; + line += vfraq; + } +} +# 11 "stretch_hvx_N.h" 2 +# 21 "stretch_up_down_32.h" 2 +# 49 "stretch_up_down_32.h" +# 1 "stretch_hvx_N.h" 1 +# 9 "stretch_hvx_N.h" +static void stretch_hvx_RGB32_down____DSPF_RGB32 +# 1 "stretch_hvx_32.h" 1 +# 11 "stretch_hvx_32.h" + ( void *dst, + int dpitch, + const void *src, + int spitch, + int width, + int height, + int dst_width, + int dst_height, + const StretchCtx *ctx ) +{ + long x, y = 0; + long cw = ctx->clip.x2 - ctx->clip.x1 + 1; + long ch = ctx->clip.y2 - ctx->clip.y1 + 1; + long hfraq = ((long)(width - 0) << 18) / (long)(dst_width); + long vfraq = ((long)(height - 0) << 18) / (long)(dst_height); + long dp4 = dpitch / 4; + long point0 = hfraq + ctx->clip.x1 * hfraq; + long point = point0; + long line = vfraq + ctx->clip.y1 * vfraq; + long ratios[cw]; + u32 *dst32; + + + + + + u32 _lbT[cw+8]; + u32 _lbB[cw+8]; + + u32 *lbX; + u32 *lbT = (u32*)((((unsigned long)(&_lbT[0])) + 31) & ~31); + u32 *lbB = (u32*)((((unsigned long)(&_lbB[0])) + 31) & ~31); + + long lineT = -2000; + + for (x=0; xclip.x1 * 4 + ctx->clip.y1 * dpitch); + + dst32 = (u32*) dst; + + + + + for (y=0; y> 18) - 1 ); + + D_ASSERT( nlT >= 0 ); + D_ASSERT( nlT < height-1 ); + + + + + if (nlT != lineT) { + u32 L, R; + const u32 *srcT = (const u32 *)((const char*) src + spitch * nlT); + const u32 *srcB = (const u32 *)((const char*) src + spitch * (nlT + 1)); + long diff = nlT - lineT; + + if (diff > 1) { + + + + for (x=0, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcT[pl]); + R = (srcT[pl+1]); + + lbT[x]= ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0x0000ff00)) & 0x0000ff00); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0x0000ff00)) & 0x0000ff00); + } + } + else { + + lbX = lbT; + lbT = lbB; + lbB = lbX; + + + + + for (x=0, point=point0; x> 18) - 1 ); + do {} while (0); + + D_ASSERT( pl >= 0 ); + D_ASSERT( pl < width-1 ); + + L = (srcB[pl]); + R = (srcB[pl+1]); + + lbB[x] = ((((((R & 0x00ff00ff) - (L & 0x00ff00ff))*ratios[x]) >> 8) + (L & 0x00ff00ff)) & 0x00ff00ff) + + ((((((R>>8) & 0x00ff00ff) - ((L>>8) & 0x00ff00ff))*ratios[x]) + (L & 0x0000ff00)) & 0x0000ff00); + } + } + + lineT = nlT; + } + + + + + X = ( (((((line)) & 0x3ffff) ? : 0x40000) << 8) / (vfraq) ); + + for (x=0; x> 8) + (lbT[x] & 0x00ff00ff)) & 0x00ff00ff) + + ((((((lbB[x]>>8) & 0x00ff00ff) - ((lbT[x]>>8) & 0x00ff00ff))*X) + (lbT[x] & 0x0000ff00)) & 0x0000ff00); + + } + + dst32 += dp4; + line += vfraq; + } +} +# 11 "stretch_hvx_N.h" 2 +# 50 "stretch_up_down_32.h" 2 +# 100 "Scaler.cxx" 2 +# 112 "Scaler.cxx" +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; + } + } +}; + + + +} +# 1 "View.cxx" +# 1 "" +# 1 "" +# 1 "View.cxx" +namespace PluggIt { + +class View +{ + public: virtual void config( DFBDimension &size ) = 0; + + public: virtual void update( const vector &rects, + void *ptr, + int pitch ) = 0; +}; + +} +# 1 "Source.cxx" +# 1 "" +# 1 "" +# 1 "Source.cxx" +namespace PluggIt { + +class Source +{ + protected: class Config { + protected: Config() {} + }; + + + protected: View *m_view; + protected: const Config &m_config; + + public: Source( View *view, const Config &config ) : m_config(config) { + m_view = view; + } + + + public: virtual int MainLoop() = 0; +}; + +} +# 1 "SourceWin32.cxx" +# 1 "" +# 1 "" +# 1 "SourceWin32.cxx" +namespace PluggIt { + +D_DEBUG_DOMAIN( PluggIt_SourceWin32, "PluggIt/SourceWin32", "PluggIt Source Win32" ); + + +# 1 "ScreenHooks.h" 1 +# 28 "ScreenHooks.h" +extern "C" +{ + __attribute__((dllexport)) bool setHook(HWND targedWinHwnd); + __attribute__((dllexport)) bool unsetHook(); +} +# 7 "SourceWin32.cxx" 2 + +const UINT specIpcCode = RegisterWindowMessage("HOOK.MESSAGE.CODE"); + + +class SourceWin32 :public Source, Runnable +{ + private: HINSTANCE m_hInstance; + + private: HWND m_root; + private: HWND m_window; + + private: DFBPoint m_position; + private: DFBDimension m_size; + + private: HBITMAP m_bitmap; + private: void *m_pixels; + private: int m_pitch; + + private: HBITMAP m_bitmap2; + private: void *m_pixels2; + private: int m_pitch2; + + private: HDC m_window_dc; + private: HDC m_bitmap_dc; + private: HDC m_bitmap_dc2; + + private: Thread *m_thread; + + private: Updates m_updates; + + private: VIDEODRIVER m_driver; + private: bool m_using_driver; + + private: pthread_mutex_t m_lock; + private: pthread_cond_t m_cond; + + + public: class Config :public Source::Config { + friend class SourceWin32; + + public: typedef enum { + WINDOW_SELECTION_NONE, + WINDOW_SELECTION_TITLE, + WINDOW_SELECTION_INTERACTIVE + } WindowSelection; + + private: WindowSelection m_selection; + private: std::string m_title; + private: bool m_updating; + private: bool m_use_driver; + + + public: Config( WindowSelection selection, + const std::string &title = std::string(), + bool updating = false, bool use_driver = true ) + { + m_selection = selection; + m_title = title; + m_updating = updating; + m_use_driver = use_driver; + } + }; + + + public: SourceWin32( View *view, const Config &config ) : Source( view, config ), m_updates(16) { + D_DEBUG_AT( PluggIt_SourceWin32, "%s( %p )\n", __FUNCTION__, view ); + + m_hInstance = GetModuleHandle( NULL ); + + D_DEBUG_AT( PluggIt_SourceWin32, " -> hInstance %p\n", m_hInstance ); + + + m_root = GetDesktopWindow(); + + switch (config.m_selection) { + case Config::WINDOW_SELECTION_NONE: + m_window = m_root; + break; + + case Config::WINDOW_SELECTION_TITLE: + m_window = findWindow( config.m_title ); + if (m_window == 0) + throw new Exception( "Could not find window with title containing '%s'\n", config.m_title.c_str() ); + break; + + case Config::WINDOW_SELECTION_INTERACTIVE: + pickWindow(); + if (m_window == 0) + throw new Exception( "Could not interactively pick a window\n" ); + break; + + default: + throw new Exception( "Invalid window selection method\n" ); + } + + + RECT rect; + + GetClientRect( m_window, &rect ); + + m_position.x = rect.left; + m_position.y = rect.top; + + m_size.w = rect.right - rect.left; + m_size.h = rect.bottom - rect.top; + + queueUpdate( 0, 0, m_size.w - 1, m_size.h - 1 ); + + + std::string t = getWindowTitle( m_window ); + + D_INFO( "Source/Win32: Window %d,%d-%ux%u, name '%s'\n", + m_position.x, m_position.y, m_size.w, m_size.h, t.c_str() ); + + if (config.m_use_driver) + m_driver.VIDEODRIVER_start( m_position.x, m_position.y, m_size.w, m_size.h ); + + m_using_driver = m_driver.mypchangebuf != NULL; + + m_view->config( m_size ); + + + m_window_dc = GetDC( m_window ); + m_bitmap_dc = CreateCompatibleDC( m_window_dc ); + m_bitmap_dc2 = CreateCompatibleDC( m_window_dc ); + + + BITMAPINFO bitmap_info = {{ + biSize: sizeof(BITMAPINFOHEADER), + biWidth: m_size.w, + biHeight: m_size.h, + biPlanes: 1, + biBitCount: 32, + biCompression: BI_RGB, + biSizeImage: 0, + biXPelsPerMeter: 0, + biYPelsPerMeter: 0, + biClrUsed: 0, + biClrImportant: 0, + }}; + + m_bitmap = CreateDIBSection( m_window_dc, &bitmap_info, DIB_RGB_COLORS, &m_pixels, NULL, 0 ); + m_bitmap2 = CreateDIBSection( m_window_dc, &bitmap_info, DIB_RGB_COLORS, &m_pixels2, NULL, 0 ); + + + BITMAP bitmap; + + GetObject( m_bitmap, sizeof(BITMAP), &bitmap ); + + m_pitch = bitmap.bmWidthBytes; + + GetObject( m_bitmap2, sizeof(BITMAP), &bitmap ); + + m_pitch2 = bitmap.bmWidthBytes; + + + SelectObject( m_bitmap_dc, m_bitmap ); + SelectObject( m_bitmap_dc2, m_bitmap2 ); + + + pthread_mutex_init( &m_lock, NULL ); + pthread_cond_init( &m_cond, NULL ); + + + if (!m_using_driver) { + HWND w; + + WNDCLASSEX wndClass; + + ZeroMemory( &wndClass, sizeof(wndClass) ); + + wndClass.cbSize = sizeof(wndClass); + wndClass.style = CS_HREDRAW | CS_VREDRAW; + wndClass.lpfnWndProc = MsgWndProc; + wndClass.cbClsExtra = 0; + wndClass.cbWndExtra = 0; + wndClass.hInstance = GetModuleHandle(NULL); + wndClass.hIcon = NULL; + wndClass.hIconSm = NULL; + wndClass.hCursor = LoadCursor( NULL, IDC_UPARROW ); + wndClass.hbrBackground = (HBRUSH) GetStockObject( NULL_BRUSH ); + wndClass.lpszMenuName = NULL; + wndClass.lpszClassName = "MsgWindow"; + + if (!RegisterClassEx( &wndClass )) + throw new Exception( "RegisterClassEx() failed!" ); + + + w = CreateWindowEx( 0, + "MsgWindow", + "MsgWindow", + WS_POPUP, + CW_USEDEFAULT, + CW_USEDEFAULT, + 1, + 1, + NULL, + NULL, + GetModuleHandle(NULL), + this ); + + if (!setHook( w )) + throw new Exception( "Failed to set hooks!" ); + } + + + + m_thread = new Thread( this, "SourceWin32" ); + + m_thread->start(); + } + + virtual ~SourceWin32() { + m_thread->interrupt(); + m_thread->join(); + delete m_thread; + + pthread_mutex_destroy( &m_lock ); + pthread_cond_destroy( &m_cond ); + + DeleteDC( m_window_dc ); + DeleteDC( m_bitmap_dc ); + DeleteDC( m_bitmap_dc2 ); + + DeleteObject( m_bitmap ); + DeleteObject( m_bitmap2 ); + } + + private: void addRect( const RECT &rect ) { + if (rect.left >= rect.right) + return; + + if (rect.top >= rect.bottom) + return; + + DFBRegion region( rect.left, + rect.top, + rect.right - 1, + rect.bottom - 1 ); + + m_updates.addRegion( region ); + } + + private: void run() { + if (m_using_driver) { + D_ASSERT( m_driver.mypchangebuf != NULL ); + + unsigned int counter = m_driver.mypchangebuf->counter; + unsigned int i; + + long long last_time = direct_clock_get_abs_millis(); + + D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ ); + + while (!m_thread->isInterrupted()) { + if (m_driver.mypchangebuf->counter < 1 || + m_driver.mypchangebuf->counter >= MAXCHANGES_BUF || + counter == m_driver.mypchangebuf->counter) + usleep( 10000 ); + + if (counter != m_driver.mypchangebuf->counter) { + D_DEBUG_AT( PluggIt_SourceWin32, " -> counter: %d -> %d\n", counter, m_driver.mypchangebuf->counter ); + + if (counter < m_driver.mypchangebuf->counter) { + for (i=counter+1; i<=m_driver.mypchangebuf->counter; i++) { + addRect( m_driver.mypchangebuf->pointrect[i].rect ); + } + } + else if (counter > m_driver.mypchangebuf->counter) { + for (i=counter+1; ipointrect[i].rect ); + } + for (i=1; i<=m_driver.mypchangebuf->counter; i++) { + addRect( m_driver.mypchangebuf->pointrect[i].rect ); + } + } + + counter = m_driver.mypchangebuf->counter; + } + + if (direct_clock_get_abs_millis() - last_time > 2000) { + DFBRegion region( 0, + 0, + m_size.w - 1, + m_size.h - 1 ); + + m_updates.addRegion( region ); + + last_time = direct_clock_get_abs_millis(); + } + + if (m_updates.num_regions() > 0) { + vector rects; + + m_updates.GetRectangles( rects ); + + + const DFBRegion &bounding = m_updates.bounding(); + + D_DEBUG_AT( PluggIt_SourceWin32, " -> %4d,%4d-%4dx%4d (%d regions, %d rectangles)\n", + DFB_RECTANGLE_VALS_FROM_REGION( &bounding ), m_updates.num_regions(), rects.size() ); + + m_updates.reset(); + + flushUpdates( rects ); + } + } + } + else { + D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ ); + + long long last_time = direct_clock_get_abs_millis(); + + while (!m_thread->isInterrupted()) { + if (((const Config&)m_config).m_updating) { + usleep( 100000 ); + + queueUpdate( 0, 0, m_size.w - 1, m_size.h - 1 ); + + pthread_mutex_lock( &m_lock ); + } + else { + pthread_mutex_lock( &m_lock ); + + if (m_updates.num_regions() == 0) + usleep( 10000 ); + + } + + if (direct_clock_get_abs_millis() - last_time > 2000) { + DFBRegion region( 0, + 0, + m_size.w - 1, + m_size.h - 1 ); + + m_updates.addRegion( region ); + + last_time = direct_clock_get_abs_millis(); + } + + + vector rects; + + if (m_updates.num_regions() > 0) { + m_updates.GetRectangles( rects ); + + + const DFBRegion &bounding = m_updates.bounding(); + + D_DEBUG_AT( PluggIt_SourceWin32, " -> %4d,%4d-%4dx%4d (%d regions, %d rectangles)\n", + DFB_RECTANGLE_VALS_FROM_REGION( &bounding ), m_updates.num_regions(), rects.size() ); + + m_updates.reset(); + } + + pthread_mutex_unlock( &m_lock ); + + if (!rects.empty()) + flushUpdates( rects ); + } + } + } + + + + private: void queueUpdate( int x1, int y1, int x2, int y2 ) { + D_DEBUG_AT( PluggIt_SourceWin32, "%s( %d,%d-%dx%d )\n", __FUNCTION__, x1, y1, x2 - x1 + 1, y2 - y1 + 1 ); + + pthread_mutex_lock( &m_lock ); + + DFBRegion damage( x1, y1, x2, y2 ); + + m_updates.addRegion( damage ); + + pthread_mutex_unlock( &m_lock ); + + pthread_cond_signal( &m_cond ); + } + + private: bool flushUpdates( vector &rects ) { + D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ ); + + if (m_using_driver) { + m_view->update( rects, m_driver.myframebuffer, m_pitch ); + } + else { + for (unsigned int i=0; iupdate( rects, (void*)((char*) m_pixels + m_pitch * (m_size.h - 1)), - m_pitch ); + } + + D_DEBUG_AT( PluggIt_SourceWin32, " -> flush done\n" ); + + return true; + } + + + + + + private: static std::string getWindowTitle( HWND window ) { + char buf[1024] = { 0 }; + + GetWindowText( window, buf, sizeof(buf) ); + + D_DEBUG_AT( PluggIt_SourceWin32, "%s( %p ) -> '%s'\n", __FUNCTION__, window, buf ); + + return buf; + } + + + + + class EnumContext { + public: const std::string &title; + public: HWND window; + + public: EnumContext( const std::string &title ) : title(title), window(0) {} + }; + + private: static BOOL CALLBACK enumWindowsProc( HWND hwnd, + LPARAM lParam ) + { + EnumContext *ctx = reinterpret_cast( lParam ); + + D_DEBUG_AT( PluggIt_SourceWin32, "%s( %p )\n", __FUNCTION__, hwnd ); + + std::string title = getWindowTitle( hwnd ); + + if (title == ctx->title || title.find( ctx->title ) < title.size()) + ctx->window = hwnd; + + return ctx->window == NULL; + } + + private: HWND findWindow( const std::string &title ) { + D_DEBUG_AT( PluggIt_SourceWin32, "%s( %s )\n", __FUNCTION__, title.c_str() ); + + EnumContext ctx( title ); + + EnumWindows( enumWindowsProc, reinterpret_cast( &ctx ) ); + + return ctx.window; + } + + + + + static LRESULT CALLBACK WndProc( HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam ) + { + static SourceWin32 *thiz; + POINT point; + CREATESTRUCT *create; + + switch (uMsg) { + case WM_CREATE: + create = reinterpret_cast( lParam ); + thiz = reinterpret_cast( create->lpCreateParams ); + + SetCursor( LoadCursor( NULL, IDC_CROSS ) ); + break; + + case WM_LBUTTONDOWN: + ShowWindow( hwnd, SW_HIDE ); + + + GetCursorPos( &point ); + + D_DEBUG_AT( PluggIt_SourceWin32, " -> Cursor position is %ld,%ld\n", point.x, point.y ); + + + thiz->m_window = WindowFromPoint( point ); + if (thiz->m_window) { + HWND parent; + + while ((parent = GetParent( thiz->m_window )) != NULL) + thiz->m_window = parent; + } + + D_DEBUG_AT( PluggIt_SourceWin32, " -> Window at cursor is %p: %s\n", + thiz->m_window, getWindowTitle( thiz->m_window ).c_str() ); + + DestroyWindow( hwnd ); + break; + + case WM_TIMER: + if (wParam == 666) + DestroyWindow( hwnd ); + break; + + case WM_DESTROY: + KillTimer( hwnd, 666 ); + PostQuitMessage( 0 ); + break; + + default: + SetTimer( hwnd, 666, 5000, NULL ); + + return DefWindowProc( hwnd, uMsg, wParam, lParam ); + } + + return 0; + } + + private: void pickWindow() { + D_DEBUG_AT( PluggIt_SourceWin32, "%s()\n", __FUNCTION__ ); + + HDC hdc; + + hdc = GetDC( NULL ); + if (!hdc) + throw new Exception( "GetDC() returned NULL" ); + + RECT rect; + + GetClipBox( hdc, &rect ); + + D_DEBUG_AT( PluggIt_SourceWin32, " -> Desktop size: %ldx%ld\n", + rect.right - rect.left, rect.bottom - rect.top ); + + ReleaseDC( NULL, hdc ); + + + + WNDCLASSEX wndClass; + + ZeroMemory( &wndClass, sizeof(wndClass) ); + + wndClass.cbSize = sizeof(wndClass); + wndClass.style = CS_HREDRAW | CS_VREDRAW; + wndClass.lpfnWndProc = WndProc; + wndClass.cbClsExtra = 0; + wndClass.cbWndExtra = 0; + wndClass.hInstance = m_hInstance; + wndClass.hIcon = NULL; + wndClass.hIconSm = NULL; + wndClass.hCursor = LoadCursor( NULL, IDC_UPARROW ); + wndClass.hbrBackground = (HBRUSH) GetStockObject( NULL_BRUSH ); + wndClass.lpszMenuName = NULL; + wndClass.lpszClassName = "GrabWindow"; + + if (!RegisterClassEx( &wndClass )) + throw new Exception( "RegisterClassEx() failed!\n" ); + + + AdjustWindowRect( &rect, WS_CAPTION, FALSE ); + + + HWND grabwin; + + grabwin = CreateWindowEx( 0, + "GrabWindow", + "GrabWindow", + WS_POPUP, + CW_USEDEFAULT, + CW_USEDEFAULT, + rect.right - rect.left, + rect.bottom - rect.top, + NULL, + NULL, + m_hInstance, + this ); + + SetWindowLong( grabwin, GWL_EXSTYLE, + GetWindowLong( grabwin, GWL_EXSTYLE ) | WS_EX_TRANSPARENT | WS_EX_TOPMOST ); + + ShowWindow( grabwin, SW_SHOW ); + + + + MSG msg; + + while (GetMessage( &msg, 0, 0, 0 )) { + TranslateMessage( &msg ); + + D_DEBUG_AT( PluggIt_SourceWin32, " -> Dispatching event (id %u)...\n", msg.message ); + + DispatchMessage( &msg ); + } + } + + + + static LRESULT CALLBACK MsgWndProc( HWND hwnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam ) + { + static SourceWin32 *thiz; + CREATESTRUCT *create; + + switch (uMsg) { + case WM_CREATE: + create = reinterpret_cast( lParam ); + thiz = reinterpret_cast( create->lpCreateParams ); + break; + + case WM_DESTROY: + PostQuitMessage( 0 ); + break; + + default: + if (uMsg == specIpcCode) { + int x1 = wParam >> 16; + int y1 = wParam & 0xffff; + int x2 = lParam >> 16; + int y2 = lParam & 0xffff; + + if (x1 < x2 && y1 < y2) + thiz->queueUpdate( x1, y1, x2 - 1, y2 - 1 ); + + break; + } + + return DefWindowProc( hwnd, uMsg, wParam, lParam ); + } + + return 0; + } + + public: virtual int MainLoop() { + MSG msg; + + while (GetMessage( &msg, 0, 0, 0 )) { + TranslateMessage( &msg ); + DispatchMessage( &msg ); + } + + return 0; + } +}; + +} +# 1 "Main.cxx" +# 1 "" +# 1 "" +# 1 "Main.cxx" +namespace PluggIt { + +D_DEBUG_DOMAIN( PluggIt_Main, "PluggIt/Main", "PluggIt Main" ); +D_DEBUG_DOMAIN( PluggIt_View, "PluggIt/View", "PluggIt View" ); + +class Main :public View +{ + class Config { + public: DFBDimension m_size; + public: DFBPoint m_offset; + public: DFBDimension m_resolution; + public: DFBSurfacePixelFormat m_format; + public: std::string m_title; + public: bool m_interactive; + public: bool m_updating; + public: bool m_use_driver; + + public: Config() : + m_format(DSPF_UNKNOWN), + m_interactive(false), + m_updating(false) + { + } + }; + + + private: Config m_config; + private: Options m_options; + private: Scaler m_scaler; + + private: IDirectFB m_dfb; + private: IDirectFBDisplayLayer m_layer; + private: IDirectFBWindow m_window; + private: IDirectFBSurface m_surface; + private: IDirectFBEventBuffer m_events; + + private: Source *m_source; + + private: DFBDimension m_source_resolution; + + private: DFBDimension m_view_size; + private: DFBDimension m_view_resolution; + private: bool m_view_visible; + private: DFBSurfacePixelFormat m_view_format; + + + public: Main() : + m_source(NULL), + m_view_visible(false) + { + D_DEBUG_AT( PluggIt_Main, "%s()\n", __FUNCTION__ ); + + m_options.addOption( new Options::OptionDimension( "-s", "--size", "x", "Size of view", m_config.m_size ) ); + m_options.addOption( new Options::OptionPoint ( "-o", "--offset", ",", "Offset of view", m_config.m_offset ) ); + m_options.addOption( new Options::OptionDimension( "-r", "--resolution", "x", "Resolution of view", m_config.m_resolution ) ); + m_options.addOption( new Options::OptionFormat ( "-f", "--format", "", "Pixel format of view", m_config.m_format ) ); + m_options.addOption( new Options::OptionString ( "-t", "--title", "", "Title of window to show", m_config.m_title ) ); + m_options.addOption( new Options::OptionBool ( "-i", "--interactive", "", "Use interactive window picking", m_config.m_interactive ) ); + m_options.addOption( new Options::OptionBool ( "-u", "--updating", "", "Update continuously", m_config.m_updating ) ); + m_options.addOption( new Options::OptionBool ( "-d", "--driver", "", "Use driver mode", m_config.m_use_driver ) ); + } + + public: void main( int argc, char *argv[] ) { + D_DEBUG_AT( PluggIt_Main, "%s()\n", __FUNCTION__ ); + + try { + + DirectFB::Init( &argc, &argv ); + + if (!m_options.parseCommandLine( argc, argv )) + return; + + initDFB(); + initSource(); + + run(); + } + catch (DFBException *e) { + cerr << endl; + cerr << "Caught exception!" << endl; + cerr << " ==> " << e << endl; + } + catch (Exception *e) { + cerr << endl; + cerr << "Caught exception!" << endl; + cerr << " ==> " << e << endl; + } + } + + private: void initDFB() { + D_DEBUG_AT( PluggIt_Main, "%s()\n", __FUNCTION__ ); + + + m_dfb = DirectFB::Create(); + + m_layer = m_dfb.GetDisplayLayer( DLID_PRIMARY ); + + m_events = m_dfb.CreateEventBuffer(); + } + + private: void initSource() { + D_DEBUG_AT( PluggIt_Main, "%s()\n", __FUNCTION__ ); + + + SourceWin32::Config config( m_config.m_interactive ? + SourceWin32::Config::WINDOW_SELECTION_INTERACTIVE : + (m_config.m_title.size() > 0 ? + SourceWin32::Config::WINDOW_SELECTION_TITLE : + SourceWin32::Config::WINDOW_SELECTION_NONE), m_config.m_title, + m_config.m_updating, m_config.m_use_driver ); + + m_source = new SourceWin32( this, config ); +# 122 "Main.cxx" + } + + private: void run() { + m_source->MainLoop(); + } + + public: virtual void config( DFBDimension &source_resolution ) { + D_DEBUG_AT( PluggIt_View, "%s( %u, %u )\n", __FUNCTION__, source_resolution.w, source_resolution.h ); + + + if (m_source_resolution == source_resolution) { + D_DEBUG_AT( PluggIt_View, " -> unchanged source size\n" ); + return; + } + + m_source_resolution = source_resolution; + + + + DFBDimension resolution = m_config.m_resolution; + + if (!resolution.w) { + if (!resolution.h) { + resolution = source_resolution; + + D_DEBUG_AT( PluggIt_View, " -> no width/height\n" ); + } + else { + resolution.w = resolution.h * source_resolution.w / source_resolution.h; + + D_DEBUG_AT( PluggIt_View, " -> no width\n" ); + } + } + else if (!resolution.h) { + resolution.h = resolution.w * source_resolution.h / source_resolution.w; + + D_DEBUG_AT( PluggIt_View, " -> no height\n" ); + } + + D_DEBUG_AT( PluggIt_View, " -> resolution %ux%u\n", resolution.w, resolution.h ); + + + + DFBDimension size = m_config.m_size; + + if (!size.w) { + if (!size.h) { + size = resolution; + + D_DEBUG_AT( PluggIt_View, " -> no width/height\n" ); + } + else { + size.w = size.h * resolution.w / resolution.h; + + D_DEBUG_AT( PluggIt_View, " -> no width\n" ); + } + } + else if (!size.h) { + size.h = size.w * resolution.h / resolution.w; + + D_DEBUG_AT( PluggIt_View, " -> no height\n" ); + } + + D_DEBUG_AT( PluggIt_View, " -> %ux%u\n", size.w, size.h ); + + + if (m_view_resolution == resolution) + D_DEBUG_AT( PluggIt_View, " -> unchanged view resolution\n" ); + + if (m_view_size == size) { + D_DEBUG_AT( PluggIt_View, " -> unchanged view size\n" ); + return; + } + + if (m_window) + m_window.Resize( size.w, size.h ); + else { + + DFBWindowDescription desc; + + desc.flags = (DFBWindowDescriptionFlags)( DWDESC_POSX | DWDESC_POSY | + DWDESC_WIDTH | DWDESC_HEIGHT | DWDESC_PIXELFORMAT ); + desc.posx = 0; + desc.posy = 0; + desc.width = size.w; + desc.height = size.h; + desc.pixelformat = m_config.m_format; + + m_window = m_layer.CreateWindow( desc ); + + m_surface = m_window.GetSurface(); + + m_view_format = m_surface.GetPixelFormat(); + + m_window.AttachEventBuffer( m_events ); + } + + m_view_size = size; + m_view_resolution = resolution; + + + D_DEBUG_AT( PluggIt_View, " -> view size %4ux%4u\n", m_view_size.w, m_view_size.h ); + D_DEBUG_AT( PluggIt_View, " -> view resolution %4ux%4u\n", m_view_resolution.w, m_view_resolution.h ); + D_DEBUG_AT( PluggIt_View, " -> source resolution %4ux%4u\n", m_source_resolution.w, m_source_resolution.h ); + } + + public: virtual void update( const vector &rects, + void *ptr, + int pitch ) + { + unsigned int i; + DFBRegion clip( m_view_size ); + const DFBPoint &offset = m_config.m_offset; + bool first = true; + DFBRegion flip; + + D_DEBUG_AT( PluggIt_View, "%s( [%u], %p, %d )\n", __FUNCTION__, rects.size(), ptr, pitch ); + + D_ASSERT( rects.size() > 0 ); + D_ASSERT( ptr != NULL ); + + + + if (m_source_resolution == m_view_resolution) { + D_DEBUG_AT( PluggIt_View, " -> unscaled %4dx%4d\n", + m_source_resolution.w, m_source_resolution.h ); + + if (m_view_format == DSPF_RGB16) { + int tp = ((m_view_size.w * 2) + 7) & ~7; + void *tmp = malloc( tp * m_view_size.h ); + + for (i=0; i [%2d] %4d,%4d-%4dx%4d (original)\n", + i, DFB_RECTANGLE_VALS( &rects[i] ) ); + + DFBRegion region( DFBRectangle(rects[i]) - offset ); + + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (translated)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + ptr = (void*)((char*) ptr + offset.x * 4 + offset.y * pitch); + + + if (dfb_region_region_intersect( ®ion, &clip )) { + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (clipped update)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + DFBRectangle rect( region ); + + dfb_convert_to_rgb16( DSPF_RGB32, + (void*)((char*) ptr + rect.x * 4 + rect.y * pitch), pitch, + m_view_size.h, (u16*) tmp, tp, rect.w, rect.h ); + + m_surface.Write( (char*) tmp + DFB_BYTES_PER_LINE( m_view_format, region.x1 ) + region.y1 * tp, tp, &rect ); + + if (first) { + first = false; + flip = region; + } + else + flip.unionWith( region ); + + } + } + + free( tmp ); + } + else { + for (i=0; i [%2d] %4d,%4d-%4dx%4d (original)\n", + i, DFB_RECTANGLE_VALS( &rects[i] ) ); + + DFBRegion region( DFBRectangle(rects[i]) - offset ); + + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (translated)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + ptr = (void*)((char*) ptr + offset.x * 4 + offset.y * pitch); + + + if (dfb_region_region_intersect( ®ion, &clip )) { + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (clipped update)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + DFBRectangle rect( region ); + + if (m_view_format == DSPF_ARGB) { + u32 *p = (u32*)((char*) ptr + rect.x * 4 + rect.y * pitch); + + for (int y=0; y Write...\n" ); + m_surface.Write( (char*) ptr + DFB_BYTES_PER_LINE( m_view_format, region.x1 ) + region.y1 * pitch, pitch, &rect ); + D_DEBUG_AT( PluggIt_View, " -> Write done.\n" ); + + if (first) { + first = false; + flip = region; + } + else + flip.unionWith( region ); + + } + } + } + } + else { + int tp = ((m_view_size.w * 4) + 7) & ~7; + void *tmp = malloc( tp * m_view_size.h ); + + D_DEBUG_AT( PluggIt_View, " -> scaled %4dx%4d => %4dx%4d\n", + m_source_resolution.w, m_source_resolution.h, + m_view_resolution.w, m_view_resolution.h ); + + for (i=0; i [%2d] %4d,%4d-%4dx%4d (original)\n", + i, DFB_RECTANGLE_VALS( &rects[i] ) ); + + DFBRegion region( DFBRectangle(rects[i]) - offset ); + + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (translated)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + ptr = (void*)((char*) ptr + offset.x * 4 + offset.y * pitch); + + + region.x1 = region.x1 * m_view_resolution.w / m_source_resolution.w; + region.y1 = region.y1 * m_view_resolution.h / m_source_resolution.h; + region.x2 = region.x2 * m_view_resolution.w / m_source_resolution.w; + region.y2 = region.y2 * m_view_resolution.h / m_source_resolution.h; + + if (region.x1 > 0) + region.x1--; + + if (region.y1 > 0) + region.y1--; + + if (region.x2 < m_view_resolution.w-1) + region.x2++; + if (region.x2 < m_view_resolution.w-1) + region.x2++; + + if (region.y2 < m_view_resolution.h-1) + region.y2++; + if (region.y2 < m_view_resolution.h-1) + region.y2++; + + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (scaled)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + + if (dfb_region_region_intersect( ®ion, &clip )) { + D_DEBUG_AT( PluggIt_View, " -> %4d,%4d-%4dx%4d (clipped)\n", + DFB_RECTANGLE_VALS_FROM_REGION( ®ion ) ); + + DFBRectangle rect( region ); + + m_scaler.scale( m_view_format, tmp, tp, ptr, pitch, + m_source_resolution.w, m_source_resolution.h, + m_view_resolution.w, m_view_resolution.h, region ); + + m_surface.Write( (char*) tmp + DFB_BYTES_PER_LINE( m_view_format, region.x1 ) + region.y1 * tp, tp, &rect ); + + if (first) { + first = false; + flip = region; + } + else + flip.unionWith( region ); + + } + } + + free( tmp ); + } + + m_surface.Flip( &flip ); + + if (!m_view_visible) { + m_window.SetOpacity( 0xff ); + + m_view_visible = true; + } + } +}; + +} +extern "C" { +# 1 "main.c" +# 1 "" +# 1 "" +# 1 "main.c" + +int +main( int argc, char *argv[] ) +{ + PluggIt::Main *main = new PluggIt::Main(); + + main->main( argc, argv ); + + delete main; +} +} -- cgit