Mercurial > repos > SquishWrapper
changeset 0:736ed6707589
Re #9 - migrate to Squish\n * Add SquishWrapper to SVN
author | IBBoard <dev@ibboard.co.uk> |
---|---|
date | Tue, 17 Feb 2009 11:55:47 +0000 |
parents | |
children | 3033227c259b |
files | AssemblyInfo.cs SquishWrapper.cs SquishWrapper.csproj SquishWrapper.csproj.user SquishWrapper.mdp squishinterface_x64.dll squishinterface_x86.dll |
diffstat | 7 files changed, 378 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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\<configuration>. 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("")]
--- /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> + /// Summary description for Class1. + /// </summary> + 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; + } + } +}
--- /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 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ProjectType>Local</ProjectType> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{92658179-ABF8-4BEA-AF6A-DF4F7F64945E}</ProjectGuid> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ApplicationIcon> + </ApplicationIcon> + <AssemblyKeyContainerName> + </AssemblyKeyContainerName> + <AssemblyName>SquishWrapper</AssemblyName> + <AssemblyOriginatorKeyFile> + </AssemblyOriginatorKeyFile> + <DefaultClientScript>JScript</DefaultClientScript> + <DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> + <DefaultTargetSchema>IE50</DefaultTargetSchema> + <DelaySign>false</DelaySign> + <OutputType>Library</OutputType> + <RootNamespace>SquishWrapper</RootNamespace> + <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> + <StartupObject> + </StartupObject> + <FileUpgradeFlags> + </FileUpgradeFlags> + <UpgradeBackupLocation> + </UpgradeBackupLocation> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <OutputPath>C:\Documents and Settings\ibboard\My Documents\Visual Studio 2005\Projects\SquishWrapper\bin\Debug\</OutputPath> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <BaseAddress>285212672</BaseAddress> + <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> + <ConfigurationOverrideFile> + </ConfigurationOverrideFile> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DocumentationFile> + </DocumentationFile> + <DebugSymbols>true</DebugSymbols> + <FileAlignment>4096</FileAlignment> + <NoStdLib>false</NoStdLib> + <NoWarn> + </NoWarn> + <Optimize>false</Optimize> + <RegisterForComInterop>false</RegisterForComInterop> + <RemoveIntegerChecks>false</RemoveIntegerChecks> + <TreatWarningsAsErrors>false</TreatWarningsAsErrors> + <WarningLevel>4</WarningLevel> + <DebugType>full</DebugType> + <ErrorReport>prompt</ErrorReport> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <OutputPath>bin\Release\</OutputPath> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <BaseAddress>285212672</BaseAddress> + <CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> + <ConfigurationOverrideFile> + </ConfigurationOverrideFile> + <DefineConstants>TRACE</DefineConstants> + <DocumentationFile> + </DocumentationFile> + <DebugSymbols>false</DebugSymbols> + <FileAlignment>4096</FileAlignment> + <NoStdLib>false</NoStdLib> + <NoWarn> + </NoWarn> + <Optimize>true</Optimize> + <RegisterForComInterop>false</RegisterForComInterop> + <RemoveIntegerChecks>false</RemoveIntegerChecks> + <TreatWarningsAsErrors>false</TreatWarningsAsErrors> + <WarningLevel>4</WarningLevel> + <DebugType>none</DebugType> + <ErrorReport>prompt</ErrorReport> + </PropertyGroup> + <ItemGroup> + <Reference Include="System"> + <Name>System</Name> + </Reference> + <Reference Include="System.Data"> + <Name>System.Data</Name> + </Reference> + <Reference Include="System.XML"> + <Name>System.XML</Name> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="AssemblyInfo.cs"> + <SubType>Code</SubType> + </Compile> + <Compile Include="SquishWrapper.cs"> + <SubType>Code</SubType> + </Compile> + <Content Include="squishinterface_x64.dll"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + <Content Include="squishinterface_x86.dll"> + <CopyToOutputDirectory>Always</CopyToOutputDirectory> + </Content> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <PropertyGroup> + <PreBuildEvent> + </PreBuildEvent> + <PostBuildEvent> + </PostBuildEvent> + </PropertyGroup> +</Project> \ No newline at end of file
--- /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 @@ +<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <LastOpenVersion>7.10.3077</LastOpenVersion> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ReferencePath>C:\Documents and Settings\Stu\My Documents\Visual Studio Projects\SquishWrapper\</ReferencePath> + <CopyProjectDestinationFolder> + </CopyProjectDestinationFolder> + <CopyProjectUncPath> + </CopyProjectUncPath> + <CopyProjectOption>0</CopyProjectOption> + <ProjectView>ProjectFiles</ProjectView> + <ProjectTrust>0</ProjectTrust> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <EnableASPDebugging>false</EnableASPDebugging> + <EnableASPXDebugging>false</EnableASPXDebugging> + <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging> + <EnableSQLServerDebugging>false</EnableSQLServerDebugging> + <RemoteDebugEnabled>false</RemoteDebugEnabled> + <RemoteDebugMachine> + </RemoteDebugMachine> + <StartAction>Project</StartAction> + <StartArguments> + </StartArguments> + <StartPage> + </StartPage> + <StartProgram> + </StartProgram> + <StartURL> + </StartURL> + <StartWorkingDirectory> + </StartWorkingDirectory> + <StartWithIE>true</StartWithIE> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <EnableASPDebugging>false</EnableASPDebugging> + <EnableASPXDebugging>false</EnableASPXDebugging> + <EnableUnmanagedDebugging>false</EnableUnmanagedDebugging> + <EnableSQLServerDebugging>false</EnableSQLServerDebugging> + <RemoteDebugEnabled>false</RemoteDebugEnabled> + <RemoteDebugMachine> + </RemoteDebugMachine> + <StartAction>Project</StartAction> + <StartArguments> + </StartArguments> + <StartPage> + </StartPage> + <StartProgram> + </StartProgram> + <StartURL> + </StartURL> + <StartWorkingDirectory> + </StartWorkingDirectory> + <StartWithIE>true</StartWithIE> + </PropertyGroup> +</Project> \ No newline at end of file
--- /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 @@ +<Project name="SquishWrapper" fileversion="2.0" language="C#" DefaultNamespace="SquishWrapper" clr-version="Net_1_1" targetFramework="1.1" ctype="DotNetProject"> + <Configurations active="Debug"> + <Configuration name="Debug" ctype="DotNetProjectConfiguration"> + <Output directory="bin/Debug/" assemblyKeyFile="." assembly="SquishWrapper" /> + <Build debugmode="True" target="Library" /> + <Execution runwithwarnings="False" consolepause="True" runtime="MsNet" clr-version="Net_1_1" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + <Configuration name="Release" ctype="DotNetProjectConfiguration"> + <Output directory="bin/Release/" assembly="SquishWrapper" /> + <Build debugmode="False" target="Library" /> + <Execution runwithwarnings="False" consolepause="True" runtime="MsNet" clr-version="Net_1_1" /> + <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="True" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" /> + </Configuration> + </Configurations> + <Contents> + <File name="AssemblyInfo.cs" subtype="Code" buildaction="Compile" /> + <File name="squishinterface_x64.dll" subtype="Code" buildaction="FileCopy" /> + <File name="SquishWrapper.cs" subtype="Code" buildaction="Compile" /> + <File name="squishinterface_x86.dll" subtype="Code" buildaction="Nothing" copyToOutputDirectory="PreserveNewest" /> + </Contents> + <References> + <ProjectReference type="Gac" localcopy="True" refto="System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + <ProjectReference type="Gac" localcopy="True" refto="System.Data, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + <ProjectReference type="Gac" localcopy="True" refto="System.Xml, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> + </References> +</Project> \ No newline at end of file