Example #1
0
        /// <summary>
        /// Send a Bitmap as Byte Array to the Device
        /// </summary>
        /// <param name="scanLine">Int Pointer to the start of the Bytearray</param>
        /// <param name="stride">Length of a ScanLine</param>
        /// <param name="maxX">Max Pixels horizontal</param>
        /// <param name="maxY">Max Pixels Vertical</param>
        internal void SendBitmapToDevice(IntPtr scanLine, int stride, int maxX, int maxY)
        {
            var inputLine = new byte[stride];
            var pixel     = new ByteColor(0, 0, 0);

            for (var y = 0; y < maxY; y++, scanLine += stride)
            {
                Marshal.Copy(scanLine, inputLine, 0, inputLine.Length);

                var xPos = 0;
                for (var x = 0; x < maxX; x++)
                {
                    pixel.SetBGR(inputLine[xPos++], inputLine[xPos++], inputLine[xPos++], IsPalletMonochrome);
                    if (ColorBytesPerPixel > 3)
                    {
                        xPos += ColorBytesPerPixel - 3;
                    }
                    DisplayWriter.Write(GetColorIndex(pixel));
                }

                for (var x = maxX; x < Width; x++)
                {
                    DisplayWriter.WriteBlankPixel();
                }
            }

            // Write blank lines if image is smaller than display.
            for (var y = maxY; y < Height; y++)
            {
                DisplayWriter.WriteBlankLine();
            }

            DisplayWriter.Finish();
        }
Example #2
0
        /// <summary>
        /// Adjust RGB values on a color. Clamping the values between 0 and 255.
        /// </summary>
        /// <param name="color">Color to adjust</param>
        /// <param name="valueR">Red value to add</param>
        /// <param name="valueG">Green value to add</param>
        /// <param name="valueB">Blue value to add</param>
        protected static void AdjustRgb(ref ByteColor color, int valueR, int valueG, int valueB)
        {
            var r = ConvertColorIntToByte(color.R + valueR);
            var g = ConvertColorIntToByte(color.G + valueG);
            var b = ConvertColorIntToByte(color.B + valueB);

            color.SetBGR(b, g, r);
        }
Example #3
0
        /// <summary>
        /// Send a Dithered Bitmap as Byte Array to the Device
        /// </summary>
        /// <param name="scanLine">Int Pointer to the start of the Bytearray</param>
        /// <param name="stride">Length of a ScanLine</param>
        /// <param name="maxX">Max Pixels horizontal</param>
        /// <param name="maxY">Max Pixels Vertical</param>
        internal void SendDitheredBitmapToDevice(IntPtr scanLine, int stride, int maxX, int maxY)
        {
            var data         = new ByteColor[Width, 2];
            var currentLine  = 0;
            var previousLine = 1;

            var inputLine = new byte[stride];
            var pixel     = new ByteColor(0, 0, 0);
            var odd       = false;
            var dither    = false;

            for (var y = 0; y < maxY; y++, scanLine += stride)
            {
                if (odd)
                {
                    previousLine = 0;
                    currentLine  = 1;
                    odd          = false;
                    dither       = true;
                }
                else
                {
                    previousLine = 1;
                    currentLine  = 0;
                    odd          = true;
                }

                Marshal.Copy(scanLine, inputLine, 0, inputLine.Length);

                var xPos = 0;
                for (var x = 0; x < maxX; x++)
                {
                    pixel.SetBGR(inputLine[xPos++], inputLine[xPos++], inputLine[xPos++], IsPalletMonochrome);
                    if (ColorBytesPerPixel > 3)
                    {
                        xPos += ColorBytesPerPixel - 3;
                    }
                    data[x, currentLine] = pixel;
                }

                for (var x = maxX; x < Width; x++)
                {
                    data[x, currentLine] = ByteColors.White;
                }

                if (dither)
                {
                    DitherAndWrite(data, previousLine, currentLine, false);
                }
            }

            // Finish last line
            DitherAndWrite(data, currentLine, previousLine, true);

            // Write blank lines if image is smaller than display.
            for (var y = maxY; y < Height; y++)
            {
                DisplayWriter.WriteBlankLine();
            }

            DisplayWriter.Finish();
        }