Exemple #1
0
        /// <summary>
        /// Reads the 16 bit color palette from the stream
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
        /// <param name="pixels">The <see cref="PixelAccessor{TColor, TPacked}"/> to assign the palette to.</param>
        /// <param name="width">The width of the bitmap.</param>
        /// <param name="height">The height of the bitmap.</param>
        /// <param name="inverted">Whether the bitmap is inverted.</param>
        private void ReadRgb16 <TColor, TPacked>(PixelAccessor <TColor, TPacked> pixels, int width, int height, bool inverted)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct
        {
            // We divide here as we will store the colors in our floating point format.
            const int ScaleR         = 8; // 256/32
            const int ScaleG         = 4; // 256/64
            const int ComponentCount = 2;

            TColor color = default(TColor);

            using (PixelRow <TColor, TPacked> row = new PixelRow <TColor, TPacked>(width, ComponentOrder.XYZ))
            {
                for (int y = 0; y < height; y++)
                {
                    row.Read(this.currentStream);

                    int newY = Invert(y, height, inverted);

                    int offset = 0;
                    for (int x = 0; x < width; x++)
                    {
                        short temp = BitConverter.ToInt16(row.Bytes, offset);

                        byte r = (byte)(((temp & Rgb16RMask) >> 11) * ScaleR);
                        byte g = (byte)(((temp & Rgb16GMask) >> 5) * ScaleG);
                        byte b = (byte)((temp & Rgb16BMask) * ScaleR);

                        color.PackFromBytes(r, g, b, 255);
                        pixels[x, newY] = color;
                        offset         += ComponentCount;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads the 32 bit color palette from the stream
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
        /// <param name="pixels">The <see cref="PixelAccessor{TColor, TPacked}"/> to assign the palette to.</param>
        /// <param name="width">The width of the bitmap.</param>
        /// <param name="height">The height of the bitmap.</param>
        /// <param name="inverted">Whether the bitmap is inverted.</param>
        private void ReadRgb32 <TColor, TPacked>(PixelAccessor <TColor, TPacked> pixels, int width, int height, bool inverted)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct
        {
            int padding = CalculatePadding(width, 4);

            using (PixelRow <TColor, TPacked> row = new PixelRow <TColor, TPacked>(width, ComponentOrder.ZYXW, padding))
            {
                for (int y = 0; y < height; y++)
                {
                    row.Read(this.currentStream);

                    int newY = Invert(y, height, inverted);
                    pixels.CopyFrom(row, newY);
                }
            }
        }