心情颇好!分享个16位图二次插值图像缩放!(转)

[经验分享] 心情颇好!分享个16位图二次插值图像缩放!     [复制链接]

Rank: 75Rank: 75Rank: 75

资源分
61  
激情
0  
可用分
7635  
积分
10098 
UID
10736 

贡献勋章

1#
yaliaos 发表于 2009-4-29 09:13 |只看该作者 |倒序浏览 |打印
本帖最后由 yaliaos 于 2009-7-17 11:23 编辑

本帖隐藏的内容

自己移植的!有错误指点!
typedef char            Int8;
typedef unsigned char   UInt8;
typedef short           Int16;
typedef unsigned short  UInt16;
typedef long            Int32;
typedef unsigned long   UInt32;

//图像数据区的描述信息
struct TPixels32Ref{
    TUint16*    pdata;        //图像数据区首地址  即 y==0行的颜色首地址
    long        byte_width;   //一行图像数据的字节宽度  正负值都有可能
    long        width;        //图像宽度
    long        height;       //图像高度
   };

下面是转换函数
void CDynamicContainer::Bilinear_Fast_Common(TUint16* PColor0,TUint16* PColor1,unsigned long u_8,unsigned long v_8,TUint16* result)
        {
        unsigned long pm3_8=(u_8*v_8)>>4;
        unsigned long pm2_8=u_8-pm3_8;
        unsigned long pm1_8=v_8-pm3_8;
        unsigned long pm0_8=16-pm1_8-pm2_8-pm3_8;

        unsigned long Color=*(unsigned short*)(PColor0);//565
        unsigned long BR=(Color & 0xF81F)*pm0_8;
        unsigned long GA=((Color & 0x7E0)>>5)*pm0_8;
        Color=((unsigned short*)(PColor0))[1];
        GA+=((Color & 0x7E0)>>5)*pm2_8;
        BR+=(Color & 0xF81F)*pm2_8;
        Color=*(unsigned short*)(PColor1);
        GA+=((Color & 0x7E0)>>5)*pm1_8;
        BR+=(Color & 0xF81F)*pm1_8;
        Color=((unsigned short*)(PColor1))[1];
        GA+=((Color & 0x7E0)>>5)*pm3_8;
        BR+=(Color & 0xF81F)*pm3_8;

        *result=((GA & 0x3F0)<<1)|((BR & 0xF81F0)>>4);
        }


void CDynamicContainer::PicZoom_ftBilinear_Common(const TPixels32Ref& Dst,const TPixels32Ref& Src)
        {
        if (  (0==Dst.width)||(0==Dst.height)
                        ||(2>Src.width)||(2>Src.height)) return;

        long xrIntdouble_16=((Src.width-1)<<8)/Dst.width;
        long yrIntdouble_16=((Src.height-1)<<8)/Dst.height;

        long dst_width=Dst.width;
        long Src_byte_width=Src.byte_width;
        TUint16* pDstLine=Dst.pdata;
        long srcy_16=0;
        for (long y=0;y<Dst.height;++y)
                {
                unsigned long v_8=(srcy_16 & 0xFF)>>4;//16位图时精度4位
                TUint16* PSrcLineColor= (TUint16*)((UInt8*)(Src.pdata)+Src_byte_width*(srcy_16>>8)) ;
                long srcx_16=0;
                for (long x=0;x<dst_width;++x)
                        {
                        TUint16* PColor0=&PSrcLineColor[srcx_16>>8];
                        Bilinear_Fast_Common(PColor0,(TUint16*)((UInt8*)(PColor0)+Src_byte_width),(srcx_16 & 0xFF)>>4,v_8,&pDstLine[x]);
                        srcx_16+=xrIntdouble_16;
                        }
                srcy_16+=yrIntdouble_16;
                ((UInt8*&)pDstLine)+=Dst.byte_width;
                }
        }


void CDynamicContainer::Zoom(CFbsBitmap* Dst, CFbsBitmap* src)
        {
        TPixels32Ref srcPic;
        TPixels32Ref dstPic;

        if(src->IsLargeBitmap())
            src->LockHeap();
        srcPic.pdata=NULL;
        srcPic.width=src->SizeInPixels().iWidth;
        srcPic.height=src->SizeInPixels().iHeight;
        srcPic.byte_width=srcPic.width*sizeof(TUint16);
        if(srcPic.pdata)
                {
                delete[] (TUint16*)srcPic.pdata;
                srcPic.pdata=0;
                }
        srcPic.pdata=(TUint16*)(new UInt8[srcPic.byte_width*srcPic.height]);
        memcpy(srcPic.pdata,src->DataAddress(),srcPic.byte_width*srcPic.height);
        if(src->IsLargeBitmap())
                src->UnlockHeap();

        if(Dst->IsLargeBitmap())
                Dst->LockHeap();
        dstPic.pdata=(TUint16*)(Dst->DataAddress());
        dstPic.width=Dst->SizeInPixels().iWidth;
        dstPic.height=Dst->SizeInPixels().iHeight;
        dstPic.byte_width=dstPic.width*sizeof(TUint16);

        PicZoom_ftBilinear_Common(dstPic,srcPic);
        if(Dst->IsLargeBitmap())
                Dst->UnlockHeap();
        if(srcPic.pdata)
                {
                delete[] (TUint16*)srcPic.pdata;
                srcPic.pdata=0;
                }
        }

N73真机测试比系统的缩放函数快1/5!不知道这数据有没有错误


改的简单了点。让兄弟们看起来好理解些!。之前的程序只支持3版的。现在改过后2版上也能跑了![/hide]
posted @ 2011-01-16 16:29  冰岛  阅读(504)  评论(0编辑  收藏  举报