Exemple #1
0
        void init(RawImage img, uint x, uint y)
        {
            if (img == null)
            {
                throw new ArgumentNullException("img");
            }

            uint bw = Math.Min(img.Width - x, 4U);
            uint bh = Math.Min(img.Height - y, 4U);

            if (bw == 0 || bh == 0)
            {
                throw new InvalidOperationException("bw and bh have to be > 0)");
            }

            uint[] remainder =
            {
                0, 0, 0, 0,
                0, 1, 0, 1,
                0, 1, 2, 0,
                0, 1, 2, 3
            };

            // Blocks that are smaller than 4x4 are handled by repeating the pixels.
            // @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :(

            for (uint i = 0; i < 4; i++)
            {
                //const int by = i % bh;
                uint by = remainder[(bh - 1) * 4 + i];
                for (uint e = 0; e < 4; e++)
                {
                    //const int bx = e % bw;
                    uint bx = remainder[(bw - 1) * 4 + e];
                    Data[i * 4 + e] = img.Pixel(x + bx, y + by);
                }
            }
        }
        void init(RawImage img, uint x, uint y)
        {
            if (img == null)
                throw new ArgumentNullException("img");

            uint bw = Math.Min(img.Width - x, 4U);
            uint bh = Math.Min(img.Height - y, 4U);

            if (bw == 0 || bh == 0)
                throw new InvalidOperationException("bw and bh have to be > 0)");

            uint[] remainder = {
                    0, 0, 0, 0,
                    0, 1, 0, 1,
                    0, 1, 2, 0,
                    0, 1, 2, 3 };

            // Blocks that are smaller than 4x4 are handled by repeating the pixels.
            // @@ Thats only correct when block size is 1, 2 or 4, but not with 3. :(

            for (uint i = 0; i < 4; i++)
            {
                //const int by = i % bh;
                uint by = remainder[(bh - 1) * 4 + i];
                for (uint e = 0; e < 4; e++)
                {
                    //const int bx = e % bw;
                    uint bx = remainder[(bw - 1) * 4 + e];
                    Data[i * 4 + e] = img.Pixel(x + bx, y + by);
                }
            }
        }