Exemplo n.º 1
0
        private void Encode_A8(byte[] bgrData)
        {
            if (bgrData.Length != 3 * Width * Height)
            {
                throw new ArgumentException("RGB Data size is invalid", nameof(bgrData));
            }

            var gscData = new byte[bgrData.Length];

            Buffer.BlockCopy(bgrData, 0, gscData, 0, bgrData.Length);

            GraphicUtils.BgrDataToGrayScale(gscData);
            GraphicUtils.RotatebgrDataCounterClockwise(gscData, 3 * Width);

            var p = GreatestCommonMultiple(Width, 8) / 8;

            if (p == 0)
            {
                p = 1;
            }

            for (uint i = 0; i < Data.Length; i += 1)
            {
                uint x, y;
                DecToCoord(i % 64, out x, out y);
                uint tile = i / 64;

                x += (uint)(tile % p) * 8;
                y += (uint)(tile / p) * 8;

                var idx = 3 * (y * Width + x);
                var g   = gscData[idx + 0];
                Data[i] = g;
            }
        }
Exemplo n.º 2
0
        private byte[] Decode_A8()
        {
            var bgrData = new byte[Width * Height * 3];

            var p = GreatestCommonMultiple(Width, 8) / 8;

            if (p == 0)
            {
                p = 1;
            }

            for (uint i = 0; i < Data.Length; i += 1)
            {
                byte a = Data[i + 0]; // 8

                uint x, y;
                DecToCoord(i % 64, out x, out y);
                uint tile = i / 64;

                x += (uint)(tile % p) * 8;
                y += (uint)(tile / p) * 8;

                var idx = 3 * (y * Width + x);

                bgrData[idx + 0] = a;
                bgrData[idx + 1] = a;
                bgrData[idx + 2] = a;
            }
            GraphicUtils.RotatebgrDataClockwise(bgrData, 3 * Width);
            return(bgrData);
        }