Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1681016
  • 博文数量: 1493
  • 博客积分: 38
  • 博客等级: 民兵
  • 技术积分: 5834
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 17:28
文章分类

全部博文(1493)

文章存档

2016年(11)

2015年(38)

2014年(137)

2013年(253)

2012年(1054)

2011年(1)

分类:

2012-06-20 13:31:51

原文地址:RGB格式等比例缩放 作者:wotaiqile

原理为:将原始图像的每个像素通过一个比例关系式映射到相应的位置。

/*
 lrgb:   input 24bits rgb buffer
 srgb:   output 24bits rgb buffer
 width:  input width
 height: input height
 xscale: changed vector
 yscale: changed vector
 */
int lrgbtosrgb(unsigned char *lrgb, unsigned char *srgb, int width, int height, float xscale, float yscale)
{
        int in = 0, out = 0;
        int ox, oy;     //the pixel site is after changed
        int rx, ry;     //the pixel site is before changed
        int temp = 0;   //turn site(x,y) to memory storage
        int outwidth = width * xscale;      //after changed width
        int outheight = height * yscale;    //after changed height

        //rx = ox/xscale + 0.5;     // out--to--input
        //ry = oy/yscale + 0.5;     // out--to--input

        for(oy = 0; oy < outheight; oy++)
        {
                ry = (int)(oy/0.5 + 0.5);
                if(ry >= height)
                        ry--;
                temp = ry * width *3;   //origion pixel site of which width

                for(ox = 0; ox < outwidth; ox++)
                {
                        rx = (int)(ox/0.5 + 0.5);
                        if(rx >= width)
                                rx--;
                        in = temp + rx * 3;     //change site(x,y) to storage

                        srgb[out+0] = lrgb[in+0];
                        srgb[out+1] = lrgb[in+1];
                        srgb[out+2] = lrgb[in+2];

                        out += 3;
                }
        }
        return 0;
}
阅读(255) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~