/// <summary> /// Encodes an image into the signed BC5 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> /// <returns>The encoded signed BC5 image data.</returns> public BCnImage <BC4SBlock> EncodeBC4S(FloatImage image, int rChan = 0, int gChan = 1) { 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"); } var ret = new BCnImage <BC4SBlock>(image.Width, image.Height); ImageEncodingHelper.EncodeBlocks(ret, () => { var encBC4 = new BC4BlockEncoder(); return((chanData, index, pitch) => { encBC4.LoadBlock(chanData[0], index, pitch); return encBC4.EncodeSigned(); }); }, image, new int[] { rChan, gChan }); return(ret); }
/// <summary> /// Encodes an image into the BC3 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 BC3 image data.</returns> public BCnImage <BC3Block> EncodeBC3(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 <BC3Block>(image.Width, image.Height); ImageEncodingHelper.EncodeBlocks(ret, () => { var encBC1 = new BC1BlockEncoder(); var encBC4 = new BC4BlockEncoder(); encBC1.DitherRgb = DitherRgb; return((chanData, index, pitch) => { encBC1.LoadBlock( chanData[0], index, chanData[1], index, chanData[2], index, pitch); encBC4.LoadBlock(chanData[3], index, pitch); BC3Block block; block.Rgb = encBC1.Encode(); block.A = encBC4.EncodeUnsigned(); return block; }); }, image, new int[] { rChan, gChan, bChan, aChan }); return(ret); }
/// <summary> /// Encodes an image into the unsigned BC5 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> /// <returns>The encoded unsigned BC5 image data.</returns> public BCnImage<BC5UBlock> EncodeBC5U( FloatImage image, int rChan = 0, int gChan = 1 ) { 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" ); var ret = new BCnImage<BC5UBlock>( image.Width, image.Height ); ImageEncodingHelper.EncodeBlocks( ret, () => { var encBC4 = new BC4BlockEncoder(); return ( chanData, index, pitch ) => { BC5UBlock block; encBC4.LoadBlock( chanData[0], index, pitch ); block.R = encBC4.EncodeUnsigned(); encBC4.LoadBlock( chanData[1], index, pitch ); block.G = encBC4.EncodeUnsigned(); return block; }; }, image, new int[] { rChan, gChan } ); return ret; }
/// <summary> /// Encodes an image into the BC3 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 BC3 image data.</returns> public BCnImage<BC3Block> EncodeBC3( 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<BC3Block>( image.Width, image.Height ); ImageEncodingHelper.EncodeBlocks( ret, () => { var encBC1 = new BC1BlockEncoder(); var encBC4 = new BC4BlockEncoder(); encBC1.DitherRgb = DitherRgb; return ( chanData, index, pitch ) => { encBC1.LoadBlock( chanData[0], index, chanData[1], index, chanData[2], index, pitch ); encBC4.LoadBlock( chanData[3], index, pitch ); BC3Block block; block.Rgb = encBC1.Encode(); block.A = encBC4.EncodeUnsigned(); return block; }; }, image, new int[] { rChan, gChan, bChan, aChan } ); return ret; }