平铺图像缓冲区中的平铺缓冲区索引计算问题

本文关键字:缓冲区 计算 问题 索引 图像 | 更新日期: 2023-09-27 18:22:04

我在用正方形大小的平铺缓冲区平铺图像缓冲区时遇到问题。请指出,我做错了什么。

该想法是在一定条件下获得用预定义的正方形Tile缓冲区填充的图像缓冲区。这样输出图像缓冲区就可以用Tile进行适当的倾斜,记住,图像可以是矩形(而不是正方形)

谢谢。

我试过这个。

static int imgwidth = 150; static int imgheight=100;
    static int gl_fxf = 4;//4*n
    byte[] img_byte8rgbbuff = new byte[imgwidth*imgheight*3];// variable size
    byte[] tile_byte8rgbbuff = new byte[gl_fxf * gl_fxf * 3];// can be of any size 4nX4n
    public byte[] fillwithtile(byte[] in_Image, byte[] Tile)
    {
        byte[] img_byte8rgbbuff_OUT = new byte[in_Image.Length];

        int someMainIndex;

        Action<int, int, int> TFfxMethod = (int a_h, int b_w, int in_indx) =>
        {
            int t_indx;
            //int t_indx2;
            int counter = 0;
            for (int j = a_h; j < a_h + gl_fxf; j++)
                for (int i = b_w; i < b_w + gl_fxf; i++)
                {
                    t_indx = j * 3 * imgwidth + i * 3;
                    // SOMETHING WRONG IN INDEX CALCULATION FOR ARRAYS
                    if (in_Image[in_indx] == 255)// EX. some condition in_Image[in_indx] == 255 RED component
                    {
                        img_byte8rgbbuff_OUT[t_indx] = Tile[counter];
                        img_byte8rgbbuff_OUT[t_indx+1] = Tile[counter+1];
                        img_byte8rgbbuff_OUT[t_indx+2] = Tile[counter+2];
                    }
                    counter = counter + 1;
                }
        };

        for (int palboxH = 0; palboxH <= imgheight; palboxH = palboxH + gl_fxf)
            for (int palboxW = 0; palboxW <= imgwidth; palboxW = palboxW + gl_fxf)
            {
                someMainIndex = palboxH * 3 * gl_fxf * imgwidth + palboxW * 3 * gl_fxf;
                TFfxMethod(palboxH, palboxW, someMainIndex);

            }
return img_byte8rgbbuff_OUT;
    }// 

平铺图像缓冲区中的平铺缓冲区索引计算问题

自己想出来的

计数器应遵循代码并且不需要in_indx

 counter = counter +3;