示例#1
0
        /// <summary>
        /// Encodes an image into the BC2 format.
        /// </summary>
        /// <param name="image">The image to encode.</param>
        /// <param name="rChan">The channel to pull red values from.</param>
        /// <param name="gChan">The channel to pull green values from.</param>
        /// <param name="bChan">The channel to pull blue values from.</param>
        /// <param name="aChan">The channel to pull alpha values from.</param>
        /// <returns>The encoded BC2 image data.</returns>
        public BCnImage <BC2Block> EncodeBC2(FloatImage image,
                                             int rChan = 0, int gChan = 1, int bChan = 2, int aChan = 3)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (rChan < 0 || rChan >= image.ChannelCount)
            {
                throw new ArgumentOutOfRangeException("rChan");
            }
            if (gChan < 0 || gChan >= image.ChannelCount)
            {
                throw new ArgumentOutOfRangeException("gChan");
            }
            if (bChan < 0 || bChan >= image.ChannelCount)
            {
                throw new ArgumentOutOfRangeException("bChan");
            }
            if (aChan < 0 || aChan >= image.ChannelCount)
            {
                throw new ArgumentOutOfRangeException("aChan");
            }

            var ret = new BCnImage <BC2Block>(image.Width, image.Height);

            ImageEncodingHelper.EncodeBlocks(ret,
                                             () =>
            {
                var encBC1  = new BC1BlockEncoder();
                var encBC2A = new BC2ABlockEncoder();

                encBC1.DitherRgb = DitherRgb;
                encBC2A.Dither   = DitherAlpha;

                return((chanData, index, pitch) =>
                {
                    encBC1.LoadBlock(
                        chanData[0], index,
                        chanData[1], index,
                        chanData[2], index,
                        pitch);
                    encBC2A.LoadBlock(chanData[3], index, pitch);

                    BC2Block block;

                    block.Rgb = encBC1.Encode();
                    block.A = encBC2A.Encode();

                    return block;
                });
            },
                                             image, new int[] { rChan, gChan, bChan, aChan });

            return(ret);
        }
示例#2
0
        /// <summary>
        /// Encodes an image into the BC2 format.
        /// </summary>
        /// <param name="image">The image to encode.</param>
        /// <param name="rChan">The channel to pull red values from.</param>
        /// <param name="gChan">The channel to pull green values from.</param>
        /// <param name="bChan">The channel to pull blue values from.</param>
        /// <param name="aChan">The channel to pull alpha values from.</param>
        /// <returns>The encoded BC2 image data.</returns>
        public BCnImage<BC2Block> EncodeBC2( FloatImage image,
			int rChan = 0, int gChan = 1, int bChan = 2, int aChan = 3 )
        {
            if( image == null )
                throw new ArgumentNullException( "image" );
            if( rChan < 0 || rChan >= image.ChannelCount )
                throw new ArgumentOutOfRangeException( "rChan" );
            if( gChan < 0 || gChan >= image.ChannelCount )
                throw new ArgumentOutOfRangeException( "gChan" );
            if( bChan < 0 || bChan >= image.ChannelCount )
                throw new ArgumentOutOfRangeException( "bChan" );
            if( aChan < 0 || aChan >= image.ChannelCount )
                throw new ArgumentOutOfRangeException( "aChan" );

            var ret = new BCnImage<BC2Block>( image.Width, image.Height );

            ImageEncodingHelper.EncodeBlocks( ret,
                () =>
                {
                    var encBC1 = new BC1BlockEncoder();
                    var encBC2A = new BC2ABlockEncoder();

                    encBC1.DitherRgb = DitherRgb;
                    encBC2A.Dither = DitherAlpha;

                    return ( chanData, index, pitch ) =>
                    {
                        encBC1.LoadBlock(
                            chanData[0], index,
                            chanData[1], index,
                            chanData[2], index,
                            pitch );
                        encBC2A.LoadBlock( chanData[3], index, pitch );

                        BC2Block block;

                        block.Rgb = encBC1.Encode();
                        block.A = encBC2A.Encode();

                        return block;
                    };
                },
                image, new int[] { rChan, gChan, bChan, aChan } );

            return ret;
        }