Ejemplo n.º 1
0
        public void DrawNativeBuffer(byte[] buffer, EinkColor color)
        {
            if (buffer.Length != displayWidth * displayHeight >> 3)
            {
                throw new ArgumentOutOfRangeException();
            }

            sendCommand(new byte[] { color == EinkColor.Black ? (byte)0x10 : (byte)0x13 });

            for (int i = 0; i < buffer.Length; i++)
            {
                sendData(new byte[] { (byte)~buffer[i] });
            }
        }
Ejemplo n.º 2
0
        private void writeImage(byte[] buffer, EinkColor color)
        {
            int  x, y, yBase, red, green, blue, firstByte, secondByte, bitMask;
            byte dataByte;

            for (int byteIndex = 0; byteIndex < displayWidth * displayHeight >> 3; byteIndex++)
            {
                dataByte = 0;
                x        = displayWidth - 1 - byteIndex / 13;
                yBase    = (byteIndex % 13) << 3;
                bitMask  = 1;

                for (int bitIndex = 0; bitIndex < 8; bitIndex++)
                {
                    y = yBase + 7 - bitIndex;

                    firstByte  = buffer[x * 2 + y * displayWidth * 2];
                    secondByte = buffer[x * 2 + y * displayWidth * 2 + 1];

                    red   = secondByte >> 3;
                    green = firstByte >> 5 + (secondByte & 0b00000111) << 3;
                    blue  = firstByte & 0b00011111;

                    if (color == EinkColor.Red && red > 15 && green < 32 && blue < 16)
                    {
                        dataByte += (byte)bitMask;
                    }
                    if (color == EinkColor.Black && red < 16 && green < 32 && blue < 16)
                    {
                        dataByte += (byte)bitMask;
                    }
                    bitMask <<= 1;
                }

                sendData(new byte[] { (byte)~dataByte });
            }
        }