00001 #ifndef OSDSURFACE_H_
00002 #define OSDSURFACE_H_
00003
00004 #include <qregion.h>
00005 #include <qmutex.h>
00006 #include "blend.h"
00007
00008 #define MAX_NEG_CROP 1024
00009
00010 static inline unsigned char blendColorsAlpha(int src, int dest, int alpha)
00011 {
00012 int tmp1, tmp2;
00013
00014 tmp1 = (src - dest) * alpha;
00015 tmp2 = dest + ((tmp1 + (tmp1 >> 8) + 0x80) >> 8);
00016 return tmp2 & 0xff;
00017 }
00018
00019 class OSDSurface
00020 {
00021 public:
00022 OSDSurface(int w, int h);
00023 ~OSDSurface();
00024
00025 void Clear(void);
00026 void ClearUsed(void);
00027 bool IsClear();
00028
00029 bool IntersectsDrawn(QRect &newrect);
00030 void AddRect(QRect &newrect);
00031
00032 bool Changed(void) { return changed; }
00033 void SetChanged(bool change)
00034 {
00035 changed = change;
00036 if (change)
00037 ++revision;
00038 }
00039 int GetRevision() { return revision; }
00040
00041 void BlendToYV12(unsigned char *yptr,
00042 unsigned char *uptr,
00043 unsigned char *vptr,
00044 int ystride, int ustride, int vstride) const;
00045 void BlendToARGB(unsigned char *argbptr,
00046 uint stride, uint height, bool blendtoblack=false,
00047 uint threshold = 0) const;
00048 void DitherToI44(unsigned char *outbuf, bool ifirst,
00049 uint stride, uint height) const;
00050 void DitherToIA44(unsigned char* outbuf, uint stride, uint height) const;
00051 void DitherToAI44(unsigned char* outbuf, uint stride, uint height) const;
00052
00053 int revision;
00054
00055 unsigned char *yuvbuffer;
00056
00057
00058 unsigned char *y;
00059 unsigned char *u;
00060 unsigned char *v;
00061
00062 unsigned char *alpha;
00063
00064 int width;
00065 int height;
00066 int size;
00067
00068 QRegion usedRegions;
00069 mutable QMutex usedRegionsLock;
00070
00071 #ifdef MMX
00072 short int rec_lut[256];
00073 #else
00074 short int * rec_lut;
00075 #endif
00076 unsigned char pow_lut[256][256];
00077
00078 blendregion_ptr blendregionfunc;
00079 blendcolumn2_ptr blendcolumn2func;
00080 blendcolumn_ptr blendcolumnfunc;
00081 blendcolor_ptr blendcolorfunc;
00082 blendconst_ptr blendconstfunc;
00083
00084 bool changed;
00085
00086 bool usemmx;
00087
00088 unsigned char cropTbl[256 + 2 * MAX_NEG_CROP];
00089 unsigned char *cm;
00090 };
00091
00092 typedef void (*blendtoyv12_8_fun)(unsigned char *src, unsigned char *dest,
00093 unsigned char *alpha, bool uvplane);
00094
00095 blendtoyv12_8_fun blendtoyv12_8_init(const OSDSurface *surface);
00096
00097 typedef void (*blendtoargb_8_fun)(const OSDSurface *surf, unsigned char *src,
00098 unsigned char *usrc, unsigned char *vsrc,
00099 unsigned char *alpha, unsigned char *dest);
00100
00101 blendtoargb_8_fun blendtoargb_8_init(const OSDSurface *surface);
00102
00103
00104 struct dither8_context;
00105
00106 typedef void (*dithertoia44_8_fun)(unsigned char *src, unsigned char *dest,
00107 unsigned char *alpha,
00108 const unsigned char *dmp, int xpos,
00109 dither8_context *context);
00110
00111 dithertoia44_8_fun dithertoia44_8_init(const OSDSurface *surface);
00112 dither8_context *init_dithertoia44_8_context(bool first);
00113 void delete_dithertoia44_8_context(dither8_context *context);
00114
00115 #define SCALEBITS 10
00116 #define ONE_HALF (1 << (SCALEBITS - 1))
00117 #define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
00118
00119 #define YUV_TO_RGB1(cb1, cr1)\
00120 {\
00121 cb = ((int)cb1) - 128;\
00122 cr = ((int)cr1) - 128;\
00123 r_add = FIX(1.40200) * cr + ONE_HALF;\
00124 g_add = - FIX(0.34414) * cb - FIX(0.71414) * cr + ONE_HALF;\
00125 b_add = FIX(1.77200) * cb + ONE_HALF;\
00126 }
00127
00128 #define YUV_TO_RGB2(r, g, b, y1)\
00129 {\
00130 y0 = ((int)y1) << SCALEBITS;\
00131 r = cm[(y0 + r_add) >> SCALEBITS];\
00132 g = cm[(y0 + g_add) >> SCALEBITS];\
00133 b = cm[(y0 + b_add) >> SCALEBITS];\
00134 }
00135
00136 #define RGBA_OUT(d, r, g, b, a)\
00137 {\
00138 ((unsigned int *)(d))[0] = ((a) << 24) | \
00139 ((r) << 16) | \
00140 ((g) << 8) | \
00141 (b);\
00142 }
00143
00144 #endif