コード例 #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
        private BCnImage <BC1Block> InternalEncodeBC1(FloatImage image,
                                                      int rChan, int gChan, int bChan, int aChan)
        {
            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 != -1 && (aChan < 0 || aChan >= image.ChannelCount))
            {
                throw new ArgumentOutOfRangeException("aChan");
            }

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

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

                encBC1.DitherRgb   = DitherRgb;
                encBC1.DitherAlpha = DitherAlpha;

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

                    if (chanData[3] != null)
                    {
                        encBC1.LoadAlphaMask(chanData[3], index, 0.5F, pitch);
                    }

                    return encBC1.Encode();
                });
            },
                                             image, new int[] { rChan, gChan, bChan, aChan });

            return(ret);
        }
コード例 #3
0
ファイル: ImageEncoder.cs プロジェクト: pdjonov/BCn
        /// <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;
        }
コード例 #4
0
ファイル: ImageEncoder.cs プロジェクト: pdjonov/BCn
        private BCnImage<BC1Block> InternalEncodeBC1( FloatImage image,
			int rChan, int gChan, int bChan, int aChan )
        {
            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 != -1 && (aChan < 0 || aChan >= image.ChannelCount) )
                throw new ArgumentOutOfRangeException( "aChan" );

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

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

                    encBC1.DitherRgb = DitherRgb;
                    encBC1.DitherAlpha = DitherAlpha;

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

                            if( chanData[3] != null )
                                encBC1.LoadAlphaMask( chanData[3], index, 0.5F, pitch );

                            return encBC1.Encode();
                        };
                },
                image, new int[] { rChan, gChan, bChan, aChan } );

            return ret;
        }