2012-08-16 13:00:16 +00:00
#region Using Statements
2015-11-04 23:35:05 +01:00
using ANX.Framework.Graphics.PackedVector ;
2012-08-16 13:00:16 +00:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
#endregion
// This file is part of the ANX.Framework created by the
// "ANX.Framework developer group" and released under the Ms-PL license.
// For details see: http://anxframework.codeplex.com/license
namespace ANX.Framework.Content.Pipeline.Graphics
{
2015-04-08 14:50:03 +02:00
public abstract class DxtBitmapContent : BitmapContent
2012-08-16 13:00:16 +00:00
{
2015-04-08 14:50:03 +02:00
private int _blockSize ;
private byte [ ] _pixelData ;
2012-08-16 13:00:16 +00:00
protected DxtBitmapContent ( int blockSize , int width , int height )
: base ( width , height )
{
2015-04-08 14:50:03 +02:00
_blockSize = blockSize ;
//http://www.gamedev.net/topic/615440-calculating-pitch-of-a-dxt-compressed-texture/#post_id_4886508
//Data in a DXT texture is compressed in blocks of 4x4 pixels, the block size is the resolution for this blocks.
//The block size is also the reason why width and height must be a multiple of four.
width = ( width + 3 ) / 4 ;
2015-04-26 19:47:26 +02:00
height = ( height + 3 ) / 4 ;
_pixelData = new byte [ width * height * blockSize ] ;
2012-08-16 13:00:16 +00:00
}
public override byte [ ] GetPixelData ( )
{
2015-04-08 14:50:03 +02:00
return ( byte [ ] ) _pixelData . Clone ( ) ;
2012-08-16 13:00:16 +00:00
}
public override void SetPixelData ( byte [ ] sourceData )
{
2015-04-08 14:50:03 +02:00
if ( sourceData = = null )
{
throw new ArgumentNullException ( "sourceData" ) ;
}
if ( sourceData . Length ! = _pixelData . Length )
{
throw new ArgumentException ( string . Format ( "The length of sourceData (Length: {0}) must be equal to the size of the contained data within the {1} (Length: {2})." , sourceData . Length , this . GetType ( ) . FullName , _pixelData . Length ) ) ;
}
_pixelData = ( byte [ ] ) sourceData . Clone ( ) ;
2012-08-16 13:00:16 +00:00
}
protected override bool TryCopyFrom ( BitmapContent sourceBitmap , Rectangle sourceRegion , Rectangle destinationRegion )
{
2015-04-08 14:50:03 +02:00
ValidateCopyArguments ( sourceBitmap , sourceRegion , this , destinationRegion ) ;
2012-08-16 13:00:16 +00:00
throw new NotImplementedException ( ) ;
}
protected override bool TryCopyTo ( BitmapContent destinationBitmap , Rectangle sourceRegion , Rectangle destinationRegion )
{
2015-04-08 14:50:03 +02:00
ValidateCopyArguments ( this , sourceRegion , destinationBitmap , destinationRegion ) ;
2012-08-16 13:00:16 +00:00
throw new NotImplementedException ( ) ;
}
}
}