예제 #1
0
        private static void ShowImage <TPixel>(this Ht1632 ht1632, Image <TPixel> image, int com, int row, BrightnessConvertor brightnessConvertor)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            if (image.Width < com || image.Height < row)
            {
                throw new Exception($"Image is too small. Width: {image.Width}/{com}, height: {image.Height}/{row}.");
            }

            var data = new byte[row * com / 4];

            for (var y = 0; y < row; y++)
            {
                for (var x = 0; x < com; x += 4)
                {
                    var value = (byte)(
                        (brightnessConvertor(image[x + 0, y]) ? 0b_1000 : 0) |
                        (brightnessConvertor(image[x + 1, y]) ? 0b_0100 : 0) |
                        (brightnessConvertor(image[x + 2, y]) ? 0b_0010 : 0) |
                        (brightnessConvertor(image[x + 3, y]) ? 0b_0001 : 0));
                    var index = (x + com * y) / 4;
                    data[index] = value;
                }
            }

            ht1632.WriteData(0, data);
        }
예제 #2
0
 /// <summary>
 /// Show image with 16-Com mode
 /// </summary>
 /// <param name="ht1632">HT1632 device</param>
 /// <param name="image">Image to show. Width at least 16 pixels, height at least 24 pixels </param>
 /// <param name="brightnessConvertor">Method for whether pixel is lit or not. Use <see cref="LinearBrightnessConvertor"/> if null.</param>
 public static void ShowImageWith16Com <TPixel>(this Ht1632 ht1632, Image <TPixel> image, BrightnessConvertor?brightnessConvertor = null)
     where TPixel : unmanaged, IPixel <TPixel> => ht1632.ShowImage(image, 16, 24, brightnessConvertor ?? LinearBrightnessConvertor);