# HG changeset patch # User IBBoard # Date 1234871747 0 # Node ID 736ed6707589c57b677b9f13beaea4d1455fa303 Re #9 - migrate to Squish\n * Add SquishWrapper to SVN diff -r 000000000000 -r 736ed6707589 AssemblyInfo.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AssemblyInfo.cs Tue Feb 17 11:55:47 2009 +0000 @@ -0,0 +1,58 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +// +[assembly: AssemblyTitle("Squish Wrapper")] +[assembly: AssemblyDescription("A simple wrapper for the Squish libraries based on the DdsSquish.cs file from Dean Ashton's Paint.NET plugin")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Squish Wrapper")] +[assembly: AssemblyCopyright("2007 IBBoard and 2006 Dean Ashton")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.*")] + +// +// In order to sign your assembly you must specify a key to use. Refer to the +// Microsoft .NET Framework documentation for more information on assembly signing. +// +// Use the attributes below to control which key is used for signing. +// +// Notes: +// (*) If no key is specified, the assembly is not signed. +// (*) KeyName refers to a key that has been installed in the Crypto Service +// Provider (CSP) on your machine. KeyFile refers to a file which contains +// a key. +// (*) If the KeyFile and the KeyName values are both specified, the +// following processing occurs: +// (1) If the KeyName can be found in the CSP, that key is used. +// (2) If the KeyName does not exist and the KeyFile does exist, the key +// in the KeyFile is installed into the CSP and used. +// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility. +// When specifying the KeyFile, the location of the KeyFile should be +// relative to the project output directory which is +// %Project Directory%\obj\. For example, if your KeyFile is +// located in the project directory, you would specify the AssemblyKeyFile +// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")] +// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework +// documentation for more information on this. +// +[assembly: AssemblyDelaySign(false)] +[assembly: AssemblyKeyFile("")] +[assembly: AssemblyKeyName("")] diff -r 000000000000 -r 736ed6707589 SquishWrapper.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SquishWrapper.cs Tue Feb 17 11:55:47 2009 +0000 @@ -0,0 +1,128 @@ +//------------------------------------------------------------------------------ +/* + @brief Simple Squish Wrapper, based on DdsSquish.cs from Dean Ashton's Paint.NET plugin + + @note Copyright (c) 2006 Dean Ashton http://www.dmashton.co.uk + @note Copyright (c) 2007 IBBoard http://www.ibboard.co.uk + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +**/ +//------------------------------------------------------------------------------ + +using System; +using System.IO; +using System.Reflection; +using System.Runtime.InteropServices; + +namespace IBBoard.Graphics.SquishWrapper +{ + public enum SquishFlags + { + kDxt1 = ( 1 << 0 ), // Use DXT1 compression. + kDxt3 = ( 1 << 1 ), // Use DXT3 compression. + kDxt5 = ( 1 << 2 ), // Use DXT5 compression. + + kColourClusterFit = ( 1 << 3 ), // Use a slow but high quality colour compressor (the default). + kColourRangeFit = ( 1 << 4 ), // Use a fast but low quality colour compressor. + + kColourMetricPerceptual = ( 1 << 5 ), // Use a perceptual metric for colour error (the default). + kColourMetricUniform = ( 1 << 6 ), // Use a uniform metric for colour error. + + kWeightColourByAlpha = ( 1 << 7 ), // Weight the colour by alpha during cluster fit (disabled by default). + + kColourIterativeClusterFit = ( 1 << 8 ), // Use a very slow but very high quality colour compressor. + } + + /// + /// Summary description for Class1. + /// + public class SquishWrapper + { + private static bool Is64Bit() + { + return ( Marshal.SizeOf( IntPtr.Zero ) == 8 ); + } + + private sealed class SquishInterface_32 + { + [DllImport("squishinterface_x86.dll")] + internal static extern unsafe void CompressImage( byte* rgba, int width, int height, byte* blocks, int flags ); + [DllImport("squishinterface_x86.dll")] + internal static extern unsafe void DecompressImage( byte* rgba, int width, int height, byte* blocks, int flags ); + } + + private sealed class SquishInterface_64 + { + [DllImport("squishinterface_x64.dll")] + internal static extern unsafe void CompressImage( byte* rgba, int width, int height, byte* blocks, int flags ); + [DllImport("squishinterface_x64.dll")] + internal static extern unsafe void DecompressImage( byte* rgba, int width, int height, byte* blocks, int flags ); + } + + private static unsafe void CallCompressImage( byte[] rgba, int width, int height, byte[] blocks, int flags ) + { + fixed ( byte* pRGBA = rgba ) + { + fixed ( byte* pBlocks = blocks ) + { + if ( Is64Bit() ) + { + SquishInterface_64.CompressImage( pRGBA, width, height, pBlocks, flags ); + } + else + { + SquishInterface_32.CompressImage( pRGBA, width, height, pBlocks, flags ); + } + } + } + } + + // --------------------------------------------------------------------------------------- + // CompressImage + // --------------------------------------------------------------------------------------- + // + // Params + // pixelData : Source byte array containing 32-bit RGBA pixel data + // width : Width of the image to be compressed + // height : Height of the image to be compressed + // flags : Flags for squish compression control + // + // Return + // blockData : Array of bytes containing compressed blocks + // + // --------------------------------------------------------------------------------------- + + public static byte[] CompressImage(byte[] pixelData, int width, int height, int squishFlags) + { + // Compute size of compressed block area, and allocate + int blockCount = ( ( width + 3 )/4 ) * ( ( height + 3 )/4 ); + int blockSize = ( ( squishFlags & ( int )SquishFlags.kDxt1 ) != 0 ) ? 8 : 16; + + // Allocate room for compressed blocks + byte[] blockData = new byte[ blockCount * blockSize ]; + + // Invoke squish::CompressImage() with the required parameters + CallCompressImage( pixelData, width, height, blockData, squishFlags ); + + // Return our block data to caller.. + return blockData; + } + } +} diff -r 000000000000 -r 736ed6707589 SquishWrapper.csproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SquishWrapper.csproj Tue Feb 17 11:55:47 2009 +0000 @@ -0,0 +1,108 @@ + + + Local + 8.0.50727 + 2.0 + {92658179-ABF8-4BEA-AF6A-DF4F7F64945E} + Debug + AnyCPU + + + + + SquishWrapper + + + JScript + Grid + IE50 + false + Library + SquishWrapper + OnBuildSuccess + + + + + + + + + C:\Documents and Settings\ibboard\My Documents\Visual Studio 2005\Projects\SquishWrapper\bin\Debug\ + true + 285212672 + false + + + DEBUG;TRACE + + + true + 4096 + false + + + false + false + false + false + 4 + full + prompt + + + bin\Release\ + true + 285212672 + false + + + TRACE + + + false + 4096 + false + + + true + false + false + false + 4 + none + prompt + + + + System + + + System.Data + + + System.XML + + + + + Code + + + Code + + + Always + + + Always + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 736ed6707589 SquishWrapper.csproj.user --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SquishWrapper.csproj.user Tue Feb 17 11:55:47 2009 +0000 @@ -0,0 +1,57 @@ + + + 7.10.3077 + Debug + AnyCPU + C:\Documents and Settings\Stu\My Documents\Visual Studio Projects\SquishWrapper\ + + + + + 0 + ProjectFiles + 0 + + + false + false + false + false + false + + + Project + + + + + + + + + + + true + + + false + false + false + false + false + + + Project + + + + + + + + + + + true + + \ No newline at end of file diff -r 000000000000 -r 736ed6707589 SquishWrapper.mdp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SquishWrapper.mdp Tue Feb 17 11:55:47 2009 +0000 @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 736ed6707589 squishinterface_x64.dll Binary file squishinterface_x64.dll has changed diff -r 000000000000 -r 736ed6707589 squishinterface_x86.dll Binary file squishinterface_x86.dll has changed