Пример #1
0
        /// <summary>
        /// Requires <see cref="Rows"/>, <see cref="Columns"/>, <see cref="IsInteger"/>, <see cref="IsNormalized"/>, <see cref="IsUnsigned"/>, <see cref="BitsPerComponent"/>, <see cref="IsReversed"/>.
        /// </summary>
        /// <returns></returns>
        FormatChannelCollection GetFormatChannels()
        {
            FormatChannel[,] channels = new FormatChannel[Rows, Columns];

            FormatChannelType type;

            if (IsInteger)
            {
                type = IsUnsigned ? FormatChannelType.UnsignedInteger : FormatChannelType.SignedInteger;
            }
            else if (IsNormalized)
            {
                type = IsUnsigned ? FormatChannelType.UnsignedNormalized : FormatChannelType.SignedNormalized;
            }
            else
            {
                type = FormatChannelType.Float;
            }

            for (int column = 0; column < Columns; column++)
            {
                for (int row = 0; row < Rows; row++)
                {
                    FormatChannelIndex channelIndex = Columns == 1 ? FormatChannelVectorIndices[IsReversed ? 3 - row : row] : FormatChannelIndex.Cell;
                    FormatChannel      channel      = new FormatChannel(channelIndex, type, BitsPerComponent)
                    {
                        format = this,
                        column = column,
                        row    = row,
                    };
                    channels[row, column] = channel;
                }
            }

            return(new FormatChannelCollection(channels));
        }
Пример #2
0
        internal Format(PixelInternalFormat?internalFormat, PixelFormat format, PixelType?type, int rows, int columns, FormatChannelType channelType, int channelBits)
            : this(internalFormat, format, type)
        {
            int realCount = (rows == -1 || rows == -2) ? 1 : (rows == -3) ? 2 : rows;

            FormatChannel[,] channels = new FormatChannel[rows, columns];

            if (rows == -1)
            {
                channels[0, 0] = new FormatChannel(FormatChannelIndex.Depth, channelType, channelBits);
            }
            else if (rows == -2)
            {
                channels[1, 0] = new FormatChannel(FormatChannelIndex.Stencil, channelType, channelBits);
            }
            else if (rows < 0)
            {
                throw new Exception();
            }
            else
            {
                for (int column = 0; column < columns; column++)
                {
                    for (int row = 0; row < rows; row++)
                    {
                        FormatChannelIndex index;

                        if (columns > 1)
                        {
                            index = FormatChannelIndex.Cell;
                        }
                        else if (format == PixelFormat.Bgr || format == PixelFormat.Bgra)
                        {
                            switch (row)
                            {
                            case 0: index = FormatChannelIndex.Blue; break;

                            case 1: index = FormatChannelIndex.Green; break;

                            case 2: index = FormatChannelIndex.Red; break;

                            case 3: index = FormatChannelIndex.Alpha; break;

                            default: throw new Exception();
                            }
                        }
                        else
                        {
                            switch (row)
                            {
                            case 0: index = FormatChannelIndex.Red; break;

                            case 1: index = FormatChannelIndex.Green; break;

                            case 2: index = FormatChannelIndex.Blue; break;

                            case 3: index = FormatChannelIndex.Alpha; break;

                            default: throw new Exception();
                            }
                        }

                        channels[row, column] = new FormatChannel(index, channelType, channelBits);
                    }
                }
            }

            this.channels = new FormatChannelCollection(channels);
            SetupChannels();
        }