位图缩放

此代码来源于microwindows中的代码,将解压出来的位图缩放。

 

#define DEFINE_COPY_ROW(name, type)                    /
static void name(type *src, int src_w, type *dst, int dst_w)        /
{                                    /
    int i;                                /
    int pos, inc;                            /
    type pixel = 0;                            /
                                    /
    pos = 0x10000;                            /
    inc = (src_w << 16) / dst_w;                    /
    for ( i=dst_w; i>0; --i ) {                    /
        while ( pos >= 0x10000L ) {                /
            pixel = *src++;                    /
            pos -= 0x10000L;                /
        }                            /
        *dst++ = pixel;                        /
        pos += inc;                        /
    }                                /
}

//DEFINE_COPY_ROW(copy_row1, unsigned char)
//DEFINE_COPY_ROW(copy_row2, unsigned short)
DEFINE_COPY_ROW(copy_row4, unsigned long)

/*static void copy_row3(unsigned char *src, int src_w, unsigned char *dst,
    int dst_w)
{
    int i;
    int pos, inc;
    unsigned char r = 0;
    unsigned char g = 0;
    unsigned char b = 0;

    pos = 0x10000;
    inc = (src_w << 16) / dst_w;
    for ( i=dst_w; i>0; --i ) {
        while ( pos >= 0x10000L ) {
            b = *src++;
            g = *src++;
            r = *src++;
            pos -= 0x10000L;
        }
        *dst++ = b;
        *dst++ = g;
        *dst++ = r;
        pos += inc;
    }
}*/

//src bytesperpixel equals dst bytesperpixel 
//pSrc      --  source image buffer
//full_src  --  source image actual rect
//srcrect   --  blit source image rect
//pDst      --  destination image buffer
//full_dst  --  destination image actual rect
//dstrect   --  blit destination image rect
void  StretchImage( uint8 *pSrc,  Rect *full_src, Rect *srcrect, uint8 *pDest,  Rect *full_dst, Rect *dstrect)
{
     uint32 pos,inc;
     uint32 src_row, dst_maxrow,dst_row,bytesperpixel,count=0;
     uint8 *dstp,*srcp=0;
   
    if((full_src == NULL) || (full_dst == NULL))
        return ;

    /* Verify the blit rectangles */
    if ( srcrect )
    {
        if ( (srcrect->x < 0) || (srcrect->y < 0) ||
             ((srcrect->x+srcrect->width) > full_src->width) ||
             ((srcrect->y+srcrect->height) > full_src->height) )
        {
             printf(" StretchImage: invalid source rect/n");
            return;
        }
    }
    else
        srcrect = full_src;

    if( dstrect )
    {
        /* if stretching to nothing, return*/
        if (!dstrect->width || !dstrect->height)
            return;
        if ( (dstrect->x < 0) || (dstrect->y < 0) ||
             ((dstrect->x+dstrect->width) > full_dst->width) ||
             ((dstrect->y+dstrect->height) > full_dst->height) )
        {
             printf(" StretchImage: invalid dest rect/n");
            return;
        }
    }
    else
        dstrect = full_dst;

    /* Set up the data... */
       pos = 0x10000L;
    inc = (srcrect->height << 16) / dstrect->height;
    src_row = srcrect->y;
    dst_row = dstrect->y;
    bytesperpixel = 4;

    /* Perform the stretch blit */
     printf((DISABLE,"(%ld,%ld,%ld,%ld),(%ld,%ld,%ld,%ld)/n",
        srcrect->x,srcrect->y,srcrect->width,srcrect->height,
        dstrect->x,dstrect->y,dstrect->width,dstrect->height));
    for ( dst_maxrow = dst_row+dstrect->height; dst_row<dst_maxrow; ++dst_row )
    {
        dstp = pDest + (dst_row*full_dst->width*bytesperpixel) + (dstrect->x * bytesperpixel);
        while ( pos >= 0x10000L ) {
            srcp = pSrc + (src_row*full_src->width*bytesperpixel)
                    + (srcrect->x*bytesperpixel);
            ++src_row;
            pos -= 0x10000L;
        }

        count++;
        copy_row4((unsigned long *)srcp, srcrect->width,
            (unsigned long *)dstp, dstrect->width);
        /*switch (bytesperpixel)
        {
        case 1:
            copy_row1(srcp, src_width, dstp, dst_width);
            break;
        case 2:
            copy_row2((unsigned short *)srcp, src_width,
                (unsigned short *)dstp, dst_width);
            break;
        case 3:
            copy_row3(srcp, src_width, dstp, dst_width);
            break;
        case 4:
            copy_row4((unsigned long *)srcp, src_width,
                (unsigned long *)dstp, dst_width);
            break;
        }*/

        pos += inc;
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值