示例#1
0
        private static int PaintRle(Painter painter, ImgSize size, byte[] imgBytes, int x, int y, int last_pos, int rleLength)
        {
            int rleCounter = 0;

            while ((rleCounter < rleLength) && (y < size.Height))
            {
                if (size.InRange(x, y))
                {
                    byte currentByte = imgBytes[last_pos];
                    painter[x, y] = currentByte;
                }
                else
                {
                    throw new Exception("RLE length overrun on output");
                }

                y++;
                rleCounter++;
            }

            return(rleCounter);
        }
示例#2
0
        private static void ExecutePaintInstruction(Painter painter, ImgSize size, byte[] imgBytes, int x, int rle_val, int paintInstructionsLength, ref int y, ref int n_r)
        {
            if (imgBytes[n_r] >= rle_val)
            {
                // { Run Length Encoding }
                int last_pos  = n_r + 1;
                int rleLength = CalculateRleLength(size, imgBytes, y, rle_val, n_r);

                y += PaintRle(painter, size, imgBytes, x, y, last_pos, rleLength);

                n_r += 2;
            }
            else
            {
                // { Regular single pixel }
                if (size.InRange(x, y))
                {
                    painter[x, y] = imgBytes[n_r];
                }

                n_r++;
                y++;
            }
        }