public override void Draw(IVncPixelGetter a_pixelGetter, MatOfByte3 a_mat)
        {
            Scalar background = (Scalar)a_pixelGetter.GetPixelVec3b(Background, 0);

            a_mat.Rectangle(new Rect(X, Y, Width, Height), background, -1 /* Fill */);

            foreach (var v in Subrectangle)
            {
                Scalar pixelValue = (Scalar)a_pixelGetter.GetPixelVec3b(v.PixelBinary, 0);
                a_mat.Rectangle(new Rect(X + v.X, Y + v.Y, v.Width, v.Height), pixelValue, -1 /* Fill */);
            }
        }
        public void DrawHexTile(int a_x, int a_y, int a_width, int a_height, IVncPixelGetter a_pixelGetter, MatOfByte3 a_mat)
        {
            Scalar background = (Scalar)a_pixelGetter.GetPixelVec3b(Background, 0);

            a_mat.Rectangle(new Rect(a_x, a_y, a_width, a_height), background, -1 /* Fill */);

            foreach (var v in Subrects)
            {
                Scalar color = (Scalar)a_pixelGetter.GetPixelVec3b(v.SubrectsColor, 0);
                a_mat.Rectangle(new Rect(a_x + v.X, a_y + v.Y, v.Width, v.Height), color, -1 /* Fill */);
            }
        }
示例#3
0
        public override void Draw(IVncPixelGetter a_pixelGetter, MatOfByte3 a_mat)
        {
            if (m_unzippedData == null)
            {
                m_unzippedData = m_zrleReader.Read(m_zlibData, m_offset, m_length);
            }

            int readPos = 0;

            for (int y = Y; y < Y + Height; y += 64)
            {
                int h = (Y + Height - y) > 64 ? 64 : (Y + Height - y);
                for (int x = X; x < X + Width; x += 64)
                {
                    int w = (X + Width - x) > 64 ? 64 : (X + Width - x);
                    int subencodingType = m_unzippedData[readPos++];
                    if (subencodingType == 0)
                    {
                        var indexer  = a_mat.GetIndexer();
                        int byteSize = a_pixelGetter.GetPixelByteSize();
                        for (int posY = y; posY < y + h; ++posY)
                        {
                            for (int posX = x; posX < x + w; ++posX)
                            {
                                indexer[posY, posX] = a_pixelGetter.GetPixelVec3b(m_unzippedData, readPos);
                                readPos            += byteSize;
                            }
                        }
                    }
                    else if (subencodingType == 1)
                    {
                        Scalar background = (Scalar)a_pixelGetter.GetPixelVec3b(m_unzippedData, readPos);
                        readPos += a_pixelGetter.GetPixelByteSize();

                        a_mat.Rectangle(new Rect(x, y, w, h), background, -1 /* Fill */);
                    }
                    else if (2 <= subencodingType && subencodingType <= 16)
                    {
                        Vec3b[] palette = new Vec3b[subencodingType];
                        for (int i = 0; i < subencodingType; ++i)
                        {
                            palette[i] = a_pixelGetter.GetPixelVec3b(m_unzippedData, readPos);
                            readPos   += a_pixelGetter.GetPixelByteSize();
                        }

                        var   indexer  = a_mat.GetIndexer();
                        int   byteSize = a_pixelGetter.GetPixelByteSize();
                        int[] ppa      = createPackedPixelsArray(w, h, m_unzippedData, readPos, subencodingType);
                        for (int i = 0, posY = y; posY < y + h; ++posY)
                        {
                            for (int posX = x; posX < x + w; ++posX)
                            {
                                indexer[posY, posX] = palette[ppa[i]];
                                ++i;
                            }
                        }

                        readPos += getPackedPixelsBytesSize(w, h, subencodingType);
                    }
                    else if (17 <= subencodingType && subencodingType <= 127)
                    {
                        throw new NotSupportedException($"SubencodingType ({subencodingType}) is not supported.");
                    }
                    else if (subencodingType == 128)
                    {
                        var indexer = a_mat.GetIndexer();
                        int posX    = x;
                        int posY    = y;

                        int totalLen = 0;
                        int size     = w * h;
                        while (totalLen < size)
                        {
                            Vec3b pixel = a_pixelGetter.GetPixelVec3b(m_unzippedData, readPos);
                            readPos += a_pixelGetter.GetPixelByteSize();

                            // count length
                            int b;
                            int len = 1;
                            do
                            {
                                b    = m_unzippedData[readPos++];
                                len += b;
                            } while (b == 255);

                            // set pixel
                            for (int i = 0; i < len; ++i)
                            {
                                indexer[posY, posX] = pixel;

                                // to next position
                                ++posX;
                                if (posX >= x + w)
                                {
                                    posX = x;
                                    ++posY;
                                }
                            }

                            totalLen += len;
                        }
                    }
                    else if (subencodingType == 129)
                    {
                        throw new NotSupportedException($"SubencodingType ({subencodingType}) is not supported.");
                    }
                    else if (130 <= subencodingType && subencodingType <= 255)
                    {
                        // create palette
                        int     paletteSize = subencodingType - 128;
                        Vec3b[] palette     = new Vec3b[paletteSize];
                        for (int i = 0; i < paletteSize; ++i)
                        {
                            palette[i] = a_pixelGetter.GetPixelVec3b(m_unzippedData, readPos);
                            readPos   += a_pixelGetter.GetPixelByteSize();
                        }

                        var indexer = a_mat.GetIndexer();
                        int posX    = x;
                        int posY    = y;

                        int totalLen = 0;
                        int size     = w * h;
                        while (totalLen < size)
                        {
                            int paletteIndex = m_unzippedData[readPos++];
                            if ((paletteIndex & 0b10000000) == 0)
                            {
                                // length is 1
                                indexer[posY, posX] = palette[paletteIndex];
                                ++totalLen;

                                // to next position
                                ++posX;
                                if (posX >= x + w)
                                {
                                    posX = x;
                                    ++posY;
                                }
                            }
                            else
                            {
                                int b;
                                int len = 1;
                                do
                                {
                                    b    = m_unzippedData[readPos++];
                                    len += b;
                                } while (b == 255);

                                for (int i = 0; i < len; ++i)
                                {
                                    indexer[posY, posX] = palette[paletteIndex & 0x7F];

                                    // to next position
                                    ++posX;
                                    if (posX >= x + w)
                                    {
                                        posX = x;
                                        ++posY;
                                    }
                                }

                                totalLen += len;
                            }
                        }
                    }