X-Git-Url: http://code.vuplus.com/gitweb/?p=vuplus_dvbapp;a=blobdiff_plain;f=lib%2Fgdi%2Fgpixmap.cpp;h=bcdd8346716e29fc2b66fa45734dd56a4ed5d531;hp=9e8219a5e588caeae6e11b6938722a9c38895ca1;hb=7a0ae4549fab001e4902dc8616def3bcbd153a1f;hpb=78c828aae07db0b15a66577d9230cb848fe536fa diff --git a/lib/gdi/gpixmap.cpp b/lib/gdi/gpixmap.cpp old mode 100644 new mode 100755 index 9e8219a..bcdd834 --- a/lib/gdi/gpixmap.cpp +++ b/lib/gdi/gpixmap.cpp @@ -1,5 +1,13 @@ +#include +#include #include #include +#include +#include + +#ifndef BYTE_ORDER +#error "no BYTE_ORDER defined!" +#endif gLookup::gLookup() :size(0), lookup(0) @@ -48,48 +56,83 @@ void gLookup::build(int _size, const gPalette &pal, const gRGB &start, const gRG } } -gSurface::~gSurface() +gSurface::gSurface() { + x = 0; + y = 0; + bpp = 0; + bypp = 0; + stride = 0; + data = 0; + data_phys = 0; + clut.colors = 0; + clut.data = 0; + type = 0; } -gSurfaceSystem::gSurfaceSystem(eSize size, int _bpp) +gSurface::gSurface(eSize size, int _bpp, int accel) { - x=size.width(); - y=size.height(); - bpp=_bpp; + x = size.width(); + y = size.height(); + bpp = _bpp; + switch (bpp) { case 8: - bypp=1; + bypp = 1; break; case 15: case 16: - bypp=2; + bypp = 2; break; case 24: // never use 24bit mode case 32: - bypp=4; + bypp = 4; break; default: - bypp=(bpp+7)/8; + bypp = (bpp+7)/8; } - stride=x*bypp; - if (bpp==8) - { - clut.colors=256; - clut.data=new gRGB[clut.colors]; - } else + + stride = x*bypp; + + data = 0; + data_phys = 0; + + if (accel) { - clut.colors=0; - clut.data=0; + stride += 63; + stride &=~63; + + int pal_size = 0; + if (bpp == 8) + pal_size = 256 * 4; + + if (gAccel::getInstance()) + eDebug("accel memory: %d", gAccel::getInstance()->accelAlloc(data, data_phys, y * stride + pal_size)); + else + eDebug("no accel available"); } - data=malloc(x*y*bypp); + + clut.colors = 0; + clut.data = 0; + + if (!data) + data = new unsigned char [y * stride]; + + type = 1; } -gSurfaceSystem::~gSurfaceSystem() +gSurface::~gSurface() { - free(data); - delete[] clut.data; + if (type) + { + if (data_phys) + gAccel::getInstance()->accelFree(data_phys); + else + delete [] (unsigned char*)data; + + delete [] clut.data; + } } gPixmap *gPixmap::lock() @@ -109,55 +152,316 @@ void gPixmap::fill(const gRegion ®ion, const gColor &color) for (i=0; ibpp == 8) { for (int y=area.top(); ydata)+y*surface->stride+area.left(), color.color, area.width()); + } else if (surface->bpp == 16) + { + __u32 icol; + + if (surface->clut.data && color < surface->clut.colors) + icol=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b); + else + icol=0x10101*color; +#if BYTE_ORDER == LITTLE_ENDIAN + __u16 col = bswap_16(((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19); +#else + __u16 col = ((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19; +#endif + for (int y=area.top(); ydata)+y*surface->stride+area.left()*surface->bypp); + int x=area.width(); + while (x--) + *dst++=col; + } } else if (surface->bpp == 32) + { + __u32 col; + + if (surface->clut.data && color < surface->clut.colors) + col=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b); + else + col=0x10101*color; + + col^=0xFF000000; + + if (surface->data_phys && gAccel::getInstance()) + if (!gAccel::getInstance()->fill(surface, area, col)) + continue; + for (int y=area.top(); ydata)+y*surface->stride+area.left()*surface->bypp); int x=area.width(); - __u32 col; - - if (surface->clut.data && color < surface->clut.colors) - col=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b); - else - col=0x10101*color; - col^=0xFF000000; while (x--) *dst++=col; } - else + } else eWarning("couldn't fill %d bpp", surface->bpp); } } -void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag) +void gPixmap::fill(const gRegion ®ion, const gRGB &color) { + unsigned int i; + for (i=0; ibpp == 32) + { + __u32 col; + + col = color.argb(); + col^=0xFF000000; + + if (surface->data_phys && gAccel::getInstance()) + if (!gAccel::getInstance()->fill(surface, area, col)) + continue; + + for (int y=area.top(); ydata)+y*surface->stride+area.left()*surface->bypp); + int x=area.width(); + while (x--) + *dst++=col; + } + } else if (surface->bpp == 16) + { + __u32 icol = color.argb(); +#if BYTE_ORDER == LITTLE_ENDIAN + __u16 col = bswap_16(((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19); +#else + __u16 col = ((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19; +#endif + for (int y=area.top(); ydata)+y*surface->stride+area.left()*surface->bypp); + int x=area.width(); + while (x--) + *dst++=col; + } + } else + eWarning("couldn't rgbfill %d bpp", surface->bpp); + } +} + +static inline void blit_8i_to_32(__u32 *dst, __u8 *src, __u32 *pal, int width) +{ + while (width--) + *dst++=pal[*src++]; +} + +static inline void blit_8i_to_32_at(__u32 *dst, __u8 *src, __u32 *pal, int width) +{ + while (width--) + { + if (!(pal[*src]&0x80000000)) + { + src++; + dst++; + } else + *dst++=pal[*src++]; + } +} + +static inline void blit_8i_to_16(__u16 *dst, __u8 *src, __u32 *pal, int width) +{ + while (width--) + *dst++=pal[*src++] & 0xFFFF; +} + +static inline void blit_8i_to_16_at(__u16 *dst, __u8 *src, __u32 *pal, int width) +{ + while (width--) + { + if (!(pal[*src]&0x80000000)) + { + src++; + dst++; + } else + *dst++=pal[*src++] & 0xFFFF; + } +} + + /* WARNING, this function is not endian safe! */ +static void blit_8i_to_32_ab(__u32 *dst, __u8 *src, __u32 *pal, int width) +{ + while (width--) + { +#define BLEND(x, y, a) (y + (((x-y) * a)>>8)) + __u32 srccol = pal[*src++]; + __u32 dstcol = *dst; + unsigned char sb = srccol & 0xFF; + unsigned char sg = (srccol >> 8) & 0xFF; + unsigned char sr = (srccol >> 16) & 0xFF; + unsigned char sa = (srccol >> 24) & 0xFF; + + unsigned char db = dstcol & 0xFF; + unsigned char dg = (dstcol >> 8) & 0xFF; + unsigned char dr = (dstcol >> 16) & 0xFF; + unsigned char da = (dstcol >> 24) & 0xFF; + + da = BLEND(0xFF, da, sa) & 0xFF; + dr = BLEND(sr, dr, sa) & 0xFF; + dg = BLEND(sg, dg, sa) & 0xFF; + db = BLEND(sb, db, sa) & 0xFF; + +#undef BLEND + *dst++ = db | (dg << 8) | (dr << 16) | (da << 24); + } +} + +#define FIX 0x10000 + + +void gPixmap::blit(const gPixmap &src, const eRect &_pos, const gRegion &clip, int flag) +{ +// eDebug("blit: -> %d.%d %d:%d -> %d.%d %d:%d, flags=%d", +// _pos.x(), _pos.y(), _pos.width(), _pos.height(), +// clip.extends.x(), clip.extends.y(), clip.extends.width(), clip.extends.height(), +// flag); + eRect pos = _pos; + +// eDebug("source size: %d %d", src.size().width(), src.size().height()); + + if (!(flag & blitScale)) /* pos' size is valid only when scaling */ + pos = eRect(pos.topLeft(), src.size()); + else if (pos.size() == src.size()) /* no scaling required */ + flag &= ~blitScale; + + int scale_x = FIX, scale_y = FIX; + + if (flag & blitScale) + { + ASSERT(src.size().width()); + ASSERT(src.size().height()); + scale_x = pos.size().width() * FIX / src.size().width(); + scale_y = pos.size().height() * FIX / src.size().height(); + } + +// eDebug("SCALE %x %x", scale_x, scale_y); + for (unsigned int i=0; idata_phys && src.surface->data_phys) && (gAccel::getInstance())) + if (!gAccel::getInstance()->blit(surface, src.surface, area, srcarea, flag)) + continue; + + if (flag & blitScale) + { + eWarning("unimplemented: scale on non-accel surfaces"); + continue; + } + +#ifdef SET_RIGHT_HALF_VFD_SKIN if ((surface->bpp == 8) && (src.surface->bpp==8)) { __u8 *srcptr=(__u8*)src.surface->data; __u8 *dstptr=(__u8*)surface->data; - + __u8 *nomptr = new __u8[area.width()]; + unsigned char gray_max = 0; + unsigned char gray_min = 255; + unsigned char index = 0; + unsigned char gray_value = 0; + gRGB pixdata; +// printf("[bilt]srcarea.left:%d, src.surface->bypp : %d,srcarea.top() :%d,src.surface->stride : %d\n",srcarea.left(),src.surface->bypp,srcarea.top(),src.surface->stride); srcptr+=srcarea.left()*src.surface->bypp+srcarea.top()*src.surface->stride; +// nomptr+=srcarea.left()*src.surface->bypp+srcarea.top()*src.surface->stride; dstptr+=area.left()*surface->bypp+area.top()*surface->stride; for (int y=0; ystride)); + pixdata = src.surface->clut.data[index]; + gray_value = ((pixdata.r+pixdata.g +pixdata.b)/3); +// printf("%3d ",gray_value); + if(gray_value > gray_max) + gray_max = gray_value; + if(gray_value < gray_min) + gray_min = gray_value; + } +// printf("\n"); + } +// printf("\n[bilt] ### gray_min : %d, gray_max : %d\n\n",gray_min,gray_max); + for (int y=0; yclut.data[*(srcptr+x)]; + gray_value = ((pixdata.r+pixdata.g +pixdata.b)/3); + if(gray_max==gray_min) + *(nomptr+x)=gray_value; + else if(y == 0 || y == area.height()-1 || x == 0 || x == area.width()-1) + *(nomptr+x) = 255; + else + *(nomptr+x)=( ((gray_value - gray_min)*255)/(gray_max-gray_min) ); +// printf("%3d ",*(nomptr+x)); + } +// printf("\n"); + if (flag & (blitAlphaTest|blitAlphaBlend)) + { + // no real alphatest yet + int width=area.width(); +// unsigned char *src=(unsigned char*)srcptr; + unsigned char *src=(unsigned char*)nomptr; + unsigned char *dst=(unsigned char*)dstptr; + // use duff's device here! + while (width--) + { + if (!*src) + { + src++; + dst++; + } else + *dst++=*src++; + } + } else +// memcpy(dstptr, srcptr, area.width()*surface->bypp); + memcpy(dstptr, nomptr, area.width()*surface->bypp); + srcptr+=src.surface->stride; + dstptr+=surface->stride; + } + delete [] nomptr; +#else + if ((surface->bpp == 8) && (src.surface->bpp==8)) + { + __u8 *srcptr=(__u8*)src.surface->data; + __u8 *dstptr=(__u8*)surface->data; + + srcptr+=srcarea.left()*src.surface->bypp+srcarea.top()*src.surface->stride; + dstptr+=area.left()*surface->bypp+area.top()*surface->stride; + for (int y=0; ystride; dstptr+=surface->stride; } +#endif + } else if ((surface->bpp == 32) && (src.surface->bpp==32)) + { + __u32 *srcptr=(__u32*)src.surface->data; + __u32 *dstptr=(__u32*)surface->data; + + srcptr+=srcarea.left()+srcarea.top()*src.surface->stride/4; + dstptr+=area.left()+area.top()*surface->stride/4; + for (int y=0; ybypp); + srcptr+=src.surface->stride/4; + dstptr+=surface->stride/4; + } } else if ((surface->bpp == 32) && (src.surface->bpp==8)) { __u8 *srcptr=(__u8*)src.surface->data; @@ -192,49 +556,124 @@ void gPixmap::blit(const gPixmap &src, ePoint pos, const gRegion &clip, int flag pal[i]=0x010101*i; pal[i]^=0xFF000000; } - + + srcptr+=srcarea.left()*src.surface->bypp+srcarea.top()*src.surface->stride; + dstptr+=area.left()*surface->bypp+area.top()*surface->stride; + for (int y=0; ystride; + dstptr+=surface->stride; + } + } else if ((surface->bpp == 16) && (src.surface->bpp==8)) + { + __u8 *srcptr=(__u8*)src.surface->data; + __u8 *dstptr=(__u8*)surface->data; // !! + __u32 pal[256]; + + for (int i=0; i<256; ++i) + { + __u32 icol; + if (src.surface->clut.data && (iclut.colors)) + icol=(src.surface->clut.data[i].a<<24)|(src.surface->clut.data[i].r<<16)|(src.surface->clut.data[i].g<<8)|(src.surface->clut.data[i].b); + else + icol=0x010101*i; +#if BYTE_ORDER == LITTLE_ENDIAN + pal[i] = bswap_16(((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19); +#else + pal[i] = ((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19; +#endif + pal[i]^=0xFF000000; + } + srcptr+=srcarea.left()*src.surface->bypp+srcarea.top()*src.surface->stride; dstptr+=area.left()*surface->bypp+area.top()*surface->stride; + + if (flag & blitAlphaBlend) + eWarning("ignore unsupported 8bpp -> 16bpp alphablend!"); + + for (int y=0; ystride; + dstptr+=surface->stride; + } + } else if ((surface->bpp == 16) && (src.surface->bpp==32)) + { + __u8 *srcptr=(__u8*)src.surface->data; + __u8 *dstptr=(__u8*)surface->data; + + srcptr+=srcarea.left()+srcarea.top()*src.surface->stride; + dstptr+=area.left()+area.top()*surface->stride; + + if (flag & blitAlphaBlend) + eWarning("ignore unsupported 32bpp -> 16bpp alphablend!"); + for (int y=0; y> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19); +#else + *dstp++ = ((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19; +#endif + } } } else { - int width=area.width(); - unsigned char *src=(unsigned char*)srcptr; - __u32 *dst=(__u32*)dstptr; while (width--) - *dst++=pal[*src++]; + { + __u32 icol = *srcp++; +#if BYTE_ORDER == LITTLE_ENDIAN + *dstp++ = bswap_16(((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19); +#else + *dstp++ = ((icol & 0xFF) >> 3) << 11 | ((icol & 0xFF00) >> 10) << 5 | (icol & 0xFF0000) >> 19; +#endif + } } srcptr+=src.surface->stride; dstptr+=surface->stride; } } else - eFatal("cannot blit %dbpp from %dbpp", surface->bpp, src.surface->bpp); + eWarning("cannot blit %dbpp from %dbpp", surface->bpp, src.surface->bpp); } } +#undef FIX + void gPixmap::mergePalette(const gPixmap &target) { - eDebug("merge palette! %p %p", surface, target.surface); if ((!surface->clut.colors) || (!target.surface->clut.colors)) return; -#if 0 + gColor *lookup=new gColor[surface->clut.colors]; for (int i=0; iclut.colors; i++) @@ -255,7 +694,6 @@ void gPixmap::mergePalette(const gPixmap &target) } delete [] lookup; -#endif } static inline int sgn(int a) @@ -271,27 +709,34 @@ static inline int sgn(int a) void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color) { __u8 *srf8 = 0; - __u32 *srf32 = 0; + __u16 *srf16 = 0; + __u32 *srf32 = 0; int stride = surface->stride; - + if (clip.rects.empty()) return; - - __u32 col; + + __u16 col16; + __u32 col = 0; if (surface->bpp == 8) - { srf8 = (__u8*)surface->data; - } else if (surface->bpp == 32) + else { srf32 = (__u32*)surface->data; - if (surface->clut.data && color < surface->clut.colors) col=(surface->clut.data[color].a<<24)|(surface->clut.data[color].r<<16)|(surface->clut.data[color].g<<8)|(surface->clut.data[color].b); else col=0x10101*color; - col^=0xFF000000; + col^=0xFF000000; } - + + if (surface->bpp == 16) +#if BYTE_ORDER == LITTLE_ENDIAN + col16=bswap_16(((col & 0xFF) >> 3) << 11 | ((col & 0xFF00) >> 10) << 5 | (col & 0xFF0000) >> 19); +#else + col16=((col & 0xFF) >> 3) << 11 | ((col & 0xFF00) >> 10) << 5 | (col & 0xFF0000) >> 19; +#endif + int xa = start.x(), ya = start.y(), xb = dst.x(), yb = dst.y(); int dx, dy, x, y, s1, s2, e, temp, swap, i; dy=abs(yb-ya); @@ -309,7 +754,7 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color) } else swap=0; e = 2*dy-dx; - + int lasthit = 0; for(i=1; i<=dx; i++) { @@ -336,7 +781,7 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color) do { ++a; - if (a == clip.rects.size()) + if ((unsigned int)a == clip.rects.size()) a = 0; if (a == lasthit) { @@ -346,20 +791,25 @@ void gPixmap::line(const gRegion &clip, ePoint start, ePoint dst, gColor color) } while (!clip.rects[a].contains(x, y)); lasthit = a; } - + if (srf8) srf8[y * stride + x] = color; - if (srf32) + else if (srf16) + srf16[y * stride/2 + x] = col16; + else srf32[y * stride/4 + x] = col; fail: while (e>=0) { - if (swap==1) x+=s1; - else y+=s2; + if (swap==1) + x+=s1; + else + y+=s2; e-=2*dx; } - if (swap==1) - y+=s2; + + if (swap==1) + y+=s2; else x+=s1; e+=2*dy; @@ -368,6 +818,10 @@ fail: gColor gPalette::findColor(const gRGB &rgb) const { + /* grayscale? */ + if (!data) + return (rgb.r + rgb.g + rgb.b) / 3; + int difference=1<<30, best_choice=0; for (int t=0; t