Exemplo n.º 1
0
        /// <summary>
        /// Converts the specified 24-bit RGB value to a native binary value for the specified <see cref="DisplayPixelFormat"/>.
        /// </summary>
        /// <param name="format">
        /// The desired <see cref="DisplayPixelFormat"/> output format.
        /// </param>
        /// <param name="red">
        /// The 8-bit red component.
        /// </param>
        /// <param name="green">
        /// The 8-bit green component.
        /// </param>
        /// <param name="blue">
        /// The 8-bit blue component.
        /// </param>
        /// <returns>
        /// The converted value.
        /// </returns>
        static public ushort GetNativeColor(DisplayPixelFormat format, byte red, byte green, byte blue)
        {
            int redBits, greenBits, blueBits; // bits per color

            switch (format)
            {
            case DisplayPixelFormat.OneBit:
                // Just return 1 if any color is greater than black
                if ((red > 0) || (green > 0) || (blue > 0))
                {
                    return(1);
                }
                else
                {
                    return(0);
                }

            case DisplayPixelFormat.Rgb444:
                redBits = greenBits = blueBits = 4;
                break;

            case DisplayPixelFormat.Rgb565:
                redBits   = blueBits = 5;                   // Red and Blue have 5 bits
                greenBits = 6;                              // Green has 6 bits
                break;

            case DisplayPixelFormat.Rgb666:
                redBits = greenBits = blueBits = 6;
                break;

            default:
                throw new InvalidOperationException(string.Format(Strings.UnknownPixelFormat, format));
            }

            int x = 0;

            if ((red > 0) && (green > 0) && (blue > 0))
            {
                x++;
            }

            // Apply mask // TODO: Faster algorithm?
            red   >>= (8 - redBits);
            green >>= (8 - greenBits);
            blue  >>= (8 - blueBits);

            // Shift and build
            ushort color = blue;

            color <<= greenBits;
            color  |= green;
            color <<= redBits;
            color  |= red;
            return(color);
        }
Exemplo n.º 2
0
        public static ushort GetNativeColor(DisplayPixelFormat format, byte red, byte green, byte blue)
        {
            int redBits, greenBits, blueBits; // bits per color
            switch (format)
            {
                case DisplayPixelFormat.OneBit:
                    // Just return 1 if any color is greater than black
                    if ((red > 0) || (green > 0) || (blue > 0))
                    {
                        return 1;
                    }
                    else
                    {
                        return 0;
                    }
                case DisplayPixelFormat.Rgb444:
                    redBits = greenBits = blueBits = 4;
                    break;
                case DisplayPixelFormat.Rgb565:
                    redBits = blueBits = 5;                 // Red and Blue have 5 bits
                    greenBits = 6;                          // Green has 6 bits
                    break;
                case DisplayPixelFormat.Rgb666:
                    redBits = greenBits = blueBits = 6;
                    break;
                default:
                    throw new InvalidOperationException(string.Format(Strings.UnknownPixelFormat, format));
            }

            int x = 0;
            if ((red > 0) && (green > 0) && (blue > 0))
            {
                x++;
            }

            // Apply mask // TODO: Faster algorithm?
            red >>= (8 - redBits);
            green >>= (8 - greenBits);
            blue >>= (8 - blueBits);

            // Shift and build
            ushort color = blue;
            color <<= greenBits;
            color |= green;
            color <<= redBits;
            color |= red;
            return color;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the total bits per pixels for the specified format.
 /// </summary>
 /// <param name="format">
 /// The format used to obtain the bit count.
 /// </param>
 /// <returns>
 /// The number of bits per pixel.
 /// </returns>
 public static int GetBitsPerPixel(DisplayPixelFormat format)
 {
     switch (format)
     {
         case DisplayPixelFormat.OneBit:
             return 1;
         case DisplayPixelFormat.Rgb444:
             return 12;
         case DisplayPixelFormat.Rgb565:
             return 16;
         case DisplayPixelFormat.Rgb666:
             return 18;
         default:
             throw new InvalidOperationException(string.Format(Strings.UnknownPixelFormat, format));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Gets the total bits per pixels for the specified format.
        /// </summary>
        /// <param name="format">
        /// The format used to obtain the bit count.
        /// </param>
        /// <returns>
        /// The number of bits per pixel.
        /// </returns>
        static public int GetBitsPerPixel(DisplayPixelFormat format)
        {
            switch (format)
            {
            case DisplayPixelFormat.OneBit:
                return(1);

            case DisplayPixelFormat.Rgb444:
                return(12);

            case DisplayPixelFormat.Rgb565:
                return(16);

            case DisplayPixelFormat.Rgb666:
                return(18);

            default:
                throw new InvalidOperationException(string.Format(Strings.UnknownPixelFormat, format));
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Converts the specified color to a native binary value for the specified <see cref="DisplayPixelFormat"/>.
 /// </summary>
 /// <param name="format">
 /// The desired <see cref="DisplayPixelFormat"/> output format.
 /// </param>
 /// <param name="color">
 /// The color to convert.
 /// </param>
 /// <returns>
 /// The converted value.
 /// </returns>
 static public ushort GetNativeColor(DisplayPixelFormat format, Color color)
 {
     return(GetNativeColor(format, color.R, color.G, color.B));
 }
Exemplo n.º 6
0
 public static ushort GetNativeColor(DisplayPixelFormat format, Color color)
 {
     return GetNativeColor(format, color.R, color.G, color.B);
 }