raw简单插值算法

这篇博客主要介绍了如何使用RGBinfo BMPbuffer进行插值操作,该缓冲区可以是静态二维数组或动态内存分配的二维数组。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

函数定义

struct RGBinfo{
               BYTE B;
               BYTE G;
               BYTE R;
               };

RGBinfo** bmpbuffer是一个静态二维数组或者动态分配内存的二维数组

void CbmpView::RawInterpolation(RGBinfo** bmpbuffer,unsigned short** rawbuffer, UINT InterpolationMode,UINT rawBit,UINT rawWidth,UINT rawHeight)
{


    switch (InterpolationMode)
    { 
    case RG:
        for (UINT i = 0; i< rawHeight; i++)
        {
            for (UINT j = 0; j < rawWidth; j++)
            {
                if (i % 2 == 0 && j % 2 == 0)
                {
                    bmpbuffer[i][j].R = rawbuffer[i][j] >> (rawBit - 8);
                    bmpbuffer[i][j].B = 0;
                    bmpbuffer[i][j].G = 0;
                }
                else if (i % 2 == 1 && j % 2 == 1)
                {
                    bmpbuffer[i][j].B = rawbuffer[i][j] >> (rawBit - 8);
                    bmpbuffer[i][j].R = 0;
                    bmpbuffer[i][j].G = 0;
                }
                else
                {
                    bmpbuffer[i][j].G = rawbuffer[i][j] >> (rawBit-8);
                    bmpbuffer[i][j].R = 0;
                    bmpbuffer[i][j].B = 0;
                }
            }
        }
        for (UINT i = 0; i < rawHeight; i++)
        {
            for (UINT j = 0; j < rawWidth; j++)
            {
                bmpbuffer[0][0].G = (bmpbuffer[0][1].G+bmpbuffer[1][0].G)/2;//R   the frist pixel
                bmpbuffer[0][0].B = bmpbuffer[1][1].B;//R
                bmpbuffer[0][rawWidth - 1].R = bmpbuffer[0][rawWidth - 2].R;//the last pixel of frist line  G
                bmpbuffer[0][rawWidth - 1].B = bmpbuffer[1][rawWidth - 1].B;

                bmpbuffer[rawHeight - 1][0].B = bmpbuffer[rawHeight - 1][1].B;//G
                bmpbuffer[rawHeight - 1][0].R = bmpbuffer[rawHeight - 2][0].R;
                bmpbuffer[rawHeight - 1][rawWidth - 1].R = bmpbuffer[rawHeight - 2][rawWidth - 2].R;//B
                bmpbuffer[rawHeight - 1][rawWidth - 1].G = (bmpbuffer[rawHeight - 1][rawWidth - 2].G+bmpbuffer[rawHeight-2][rawWidth-1].G)/2;
                if (i == 0 && j != 0 && j != rawWidth - 1)//the frist line  RGRGRGRGRG
                {                                                        // GBGBGBGBGB
                    if (j % 2 == 1)//G
                    {
                        bmpbuffer[i][j].R = (bmpbuffer[i][j - 1].R + bmpbuffer[i][j + 1].R) / 2;
                        bmpbuffer[i][j].B = bmpbuffer[i + 1][j].B;
                    }
                    else//R
                    {
                        bmpbuffer[i][j].G = (bmpbuffer[i][j - 1].G + bmpbuffer[i][j + 1].G+bmpbuffer[i+1][j].G) / 3;
                        bmpbuffer[i][j].B = (bmpbuffer[i + 1][j-1].B+bmpbuffer[i+1][j+1].B)/2;
                    }
                }

                if (i == rawHeight - 1 && j != 0 && j != rawWidth - 1)//the last line
                {
                    if (j % 2 == 1)//B
                    {
                        bmpbuffer[i][j].R = (bmpbuffer[i-1][j-1].R + bmpbuffer[i-1][j+1].R) / 2;
                        bmpbuffer[i][j].G = (bmpbuffer[i-1][j].G+bmpbuffer[i][j-1].G+bmpbuffer[i][j+1].G) / 3;
                    }
                    else//G
                    {
                        bmpbuffer[i][j].B = (bmpbuffer[i][j-1].B+bmpbuffer[i][j+1].B) / 2;
                        bmpbuffer[i][j].R = bmpbuffer[i - 1][j].R;
                    }
                }

                if (j == 0 && i != 0 && i != rawHeight - 1)//the frist row   RGRG
                {                                                        //  GBGB
                    if (i % 2 == 1)//G                                       RGRG
                    {                  //                                    GBGB
                        bmpbuffer[i][j].B = bmpbuffer[i][j + 1].B;
                        bmpbuffer[i][j].R = (bmpbuffer[i-1][j].R+bmpbuffer[i+1][j].R) / 2;
                    }
                    else//R
                    {
                        bmpbuffer[i][j].G = (bmpbuffer[i][j + 1].G+bmpbuffer[i-1][j].G+bmpbuffer[i+1][j].G)/3;
                        bmpbuffer[i][j].B = (bmpbuffer[i - 1][j+1].B + bmpbuffer[i + 1][j+1].B) / 2;
                    }
                }

                if (j == rawWidth - 1 && i != 0 && i != rawHeight - 1)//the last row
                {
                    if (i % 2 == 1)//B
                    {
                        bmpbuffer[i][j].G = (bmpbuffer[i][j - 1].G+bmpbuffer[i-1][j].G+bmpbuffer[i+1][j].G)/3;
                        bmpbuffer[i][j].R = (bmpbuffer[i - 1][j-1].R + bmpbuffer[i + 1][j-1].R) / 2;
                    }
                    else//G
                    {
                        bmpbuffer[i][j].R = bmpbuffer[i][j-1].R;
                        bmpbuffer[i][j].B = (bmpbuffer[i - 1][j].B + bmpbuffer[i + 1][j].B) / 2;
                    }
                }

                if (i > 0 && i < rawHeight - 1 && j>0 && j < rawWidth - 1)//RGRGRG
                {                                                         //GBGBGB
                    if (i % 2 == 0 && j % 2 == 1)//G                      //RGRGRG
                    {                                                     //GBGBGB
                        bmpbuffer[i][j].R = (bmpbuffer[i][j-1].R+bmpbuffer[i][j+1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值