| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3023 人关注过本帖
标题:图片旋转
只看楼主 加入收藏
狼性执行
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2012-2-29
收藏
 问题点数:0 回复次数:5 
图片旋转
如何将一张图片按任意角度旋转,用C语言求解!~
这个是图片旋转函数,我没看懂,谁能帮我注释下。
static void so_graphics_drawImage_rotate_ext(so_graphics_t * g, so_image_t * image, S32 x, S32 y, S32 angle)
{
    S32 left, top, right, bottom, src_width;
    _FIXED_22_10 size, cx, cy, fixed_x, fixed_y, sizex, sizey, sin_value, cos_value;
    _FIXED_22_10 width_border, height_border;
    S32 i, j, dst_offset, src_offset, flr_x, flr_y;
    U16 * src_rgb_buf, *rgb_buf, * dst_buf, dst_color;
    U16 color1, color2, color3, color4, rob1, ogo1, rob3, ogo3;
    U16 color5;
    U16 transparentColor = so_graphics_getTransparentColor();
   
    cx = _TO_FIXED_22_10(x);
    cy = _TO_FIXED_22_10(y);
    size = _TO_FIXED_22_10(SO_MATH_MAX(image->width, image->height)) / 2 + _TO_FIXED_22_10(2);
    left = SO_MATH_MAX(_FIXED_22_10_FLOOR(cx - size), g->clipX);
    top = SO_MATH_MAX(_FIXED_22_10_FLOOR(cy - size), g->clipY);
    right = SO_MATH_MIN(_FIXED_22_10_CEIL(cx + size), g->clipX + g->clipWidth);
    bottom = SO_MATH_MIN(_FIXED_22_10_CEIL(cy + size), g->clipY + g->clipHeight);
    if (left >= right || top >= bottom)
        return;

    src_width = image->width;
    width_border = _TO_FIXED_22_10(image->width - 1);
    sizex = _TO_FIXED_22_10(image->width) / 2;
    height_border = _TO_FIXED_22_10(image->height - 1);
    sizey = _TO_FIXED_22_10(image->height) / 2;

    so_math_fixed_sincos((270 - angle) * 10, &sin_value, &cos_value);

    src_rgb_buf = image->buffer;
   
    dst_buf = (U16 *)g->buffer + top * g->width + left;
    dst_offset = g->width - (right - left);
    for (i = top; i < bottom; i ++)
    {
        fixed_x = (((_TO_FIXED_22_10(left) - cx) * cos_value -
            (_TO_FIXED_22_10(i) - cy) * sin_value) >> 10) + sizex;
        fixed_y = (((_TO_FIXED_22_10(left) - cx) * sin_value +
            (_TO_FIXED_22_10(i) - cy) * cos_value) >> 10) + sizey;
        for (j = left; j < right; j ++,
            dst_buf ++, fixed_x += cos_value, fixed_y += sin_value)
        {
            if (!(fixed_x < 0 || fixed_y < 0 || fixed_x >= width_border ||
                fixed_y >= height_border))
            {
                src_offset = _FIXED_22_10_FLOOR(fixed_y) * src_width + _FIXED_22_10_FLOOR(fixed_x);
                flr_x = (fixed_x & 0x3FF) >> 6;
                flr_y = (fixed_y & 0x3FF) >> 6;
               
                // 计算平均混合色
                // 4次取址
                rgb_buf = src_rgb_buf + src_offset;
                color1 = *rgb_buf;
                if (color1 == transparentColor)
                    continue;
               
                rgb_buf ++;
                color2 = *rgb_buf;
                if (color2 == transparentColor)
                    continue;
               
                rgb_buf += src_width;
                color4 = *rgb_buf;
                if (color4 == transparentColor)
                    continue;
               
                rgb_buf --;
                color3 = *rgb_buf;
                if (color3 == transparentColor)
                    continue;
               
                #if 0
                if(color1 == transparentColor){
                    if(color2 != transparentColor){
                        color1 = color2;
                    }else if(color3 != transparentColor){
                        color1 = color3;
                    }else if(color4 != transparentColor){
                        color1 = color4;
                    }
                }
                if(color2 == transparentColor){
                    if(color1 != transparentColor){
                        color2 = color1;
                    }else if(color3 != transparentColor){
                        color2 = color3;
                    }else if(color4 != transparentColor){
                        color2 = color4;
                    }
                }
                if(color3 == transparentColor){
                    if(color2 != transparentColor){
                        color3 = color2;
                    }else if(color1 != transparentColor){
                        color3 = color1;
                    }else if(color4 != transparentColor){
                        color3 = color4;
                    }
                }
                if(color4 == transparentColor){
                    if(color2 != transparentColor){
                        color4 = color2;
                    }else if(color3 != transparentColor){
                        color4 = color3;
                    }else if(color1 != transparentColor){
                        color4 = color1;
                    }
                }
                #endif
                // 6次混合乘法
                rob1 = ((((color1 & 0xF81F) << 4) + ((color2 & 0xF81F) - (color1 & 0xF81F)) * flr_x) >> 4) & 0xF81F;
                ogo1 = ((((color1 & 0x07E0) << 4) + ((color2 & 0x07E0) - (color1 & 0x07E0)) * flr_x) >> 4) & 0x07E0;
                rob3 = ((((color3 & 0xF81F) << 4) + ((color4 & 0xF81F) - (color3 & 0xF81F)) * flr_x) >> 4) & 0xF81F;
                ogo3 = ((((color3 & 0x07E0) << 4) + ((color4 & 0x07E0) - (color3 & 0x07E0)) * flr_x) >> 4) & 0x07E0;
                rob1 = (((rob1 << 4) + (rob3 - rob1) * flr_y) >> 4) & 0xF81F;
                ogo1 = (((ogo1 << 4) + (ogo3 - ogo1) * flr_y) >> 4) & 0x07E0;
               
                color5 = rob1 | ogo1;

                dst_color = *dst_buf;
                //alpha
                if (color5 != transparentColor) {
                    *dst_buf = color5 ;
                }
            }
        }
        dst_buf += dst_offset;
    }
}


[ 本帖最后由 狼性执行 于 2012-3-2 10:16 编辑 ]
搜索更多相关主题的帖子: 图片 旋转 bottom C语言 angle 
2012-03-01 17:39
icysky
Rank: 5Rank: 5
来 自:心灵世界
等 级:职业侠客
威 望:1
帖 子:172
专家分:399
注 册:2011-5-17
收藏
得分:0 
OpenGL么?

不管怎么走、总有一个终点...
2012-03-01 17:41
狼性执行
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2012-2-29
收藏
得分:0 
回复 2楼 icysky
不是,就是 自己读取图片,按照坐标变化,实现图片旋转
2012-03-01 19:39
beyondyf
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:103
帖 子:3282
专家分:12654
注 册:2008-1-21
收藏
得分:0 
我不知道你是想问如何读取图片呢,还是读取后如何旋转形成新图片?

重剑无锋,大巧不工
2012-03-01 20:23
狼性执行
Rank: 1
等 级:新手上路
帖 子:4
专家分:1
注 册:2012-2-29
收藏
得分:0 
回复 4楼 beyondyf
你帮我看下 我发的 代码吧,我看的不是很明白
2012-03-02 10:18
Yzs_think
Rank: 1
来 自:河南南阳
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-8
收藏
得分:0 
你这个是在fb上旋转图片
2012-10-22 20:58
快速回复:图片旋转
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041111 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved