aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorjmarshallnz <jmarshallnz@svn>2009-10-04 07:11:33 +0000
committerjmarshallnz <jmarshallnz@svn>2009-10-04 07:11:33 +0000
commit7387b0b8aca2c2b59d1a7a2f640756f6f8b2339e (patch)
tree0e1c4a699c9161fe0e600e304e0c764f3497d5a9 /tools
parent3bf0d309365b7e34c857682a1b5664ab6113f0e6 (diff)
added: MakeDDS win32 target for conversion to .DDS format (DXT1 or DXT5) for a single file. Needs makefile love on Linux/OS X.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23404 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'tools')
-rw-r--r--tools/TexturePacker/MakeDDS.cpp182
-rw-r--r--tools/TexturePacker/Win32/MakeDDS.vcproj209
-rw-r--r--tools/TexturePacker/Win32/TexturePacker.sln6
3 files changed, 397 insertions, 0 deletions
diff --git a/tools/TexturePacker/MakeDDS.cpp b/tools/TexturePacker/MakeDDS.cpp
new file mode 100644
index 0000000000..2d9ecf5ff0
--- /dev/null
+++ b/tools/TexturePacker/MakeDDS.cpp
@@ -0,0 +1,182 @@
+/*
+ * Copyright (C) 2005-2009 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, write to
+ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include <sys/types.h>
+#include <squish.h>
+#include <string>
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+#include "cmdlineargs.h"
+#ifdef _WIN32
+#define strncasecmp strnicmp
+#endif
+#include "DDSImage.h"
+#include "XBTF.h"
+
+#undef main
+
+const char *GetFormatString(unsigned int format)
+{
+ switch (format)
+ {
+ case squish::kDxt1:
+ return "DXT1 ";
+ case squish::kDxt5:
+ return "YCoCg";
+ default:
+ return "?????";
+ }
+}
+
+void CompressImage(const squish::u8 *brga, int width, int height, squish::u8 *compressed, unsigned int flags, double &colorMSE, double &alphaMSE)
+{
+ squish::CompressImage(brga, width, height, compressed, flags | squish::kSourceBGRA);
+ squish::ComputeMSE(brga, width, height, compressed, flags | squish::kSourceBGRA, colorMSE, alphaMSE);
+}
+
+void CompressToDDS(SDL_Surface* image, unsigned int format, CDDSImage &out)
+{
+ // Convert to ARGB
+ SDL_PixelFormat argbFormat;
+ memset(&argbFormat, 0, sizeof(SDL_PixelFormat));
+ argbFormat.BitsPerPixel = 32;
+ argbFormat.BytesPerPixel = 4;
+
+#if SDL_BYTEORDER == SDL_LIL_ENDIAN
+ argbFormat.Amask = 0xff000000;
+ argbFormat.Ashift = 24;
+ argbFormat.Rmask = 0x00ff0000;
+ argbFormat.Rshift = 16;
+ argbFormat.Gmask = 0x0000ff00;
+ argbFormat.Gshift = 8;
+ argbFormat.Bmask = 0x000000ff;
+ argbFormat.Bshift = 0;
+#else
+ argbFormat.Amask = 0x000000ff;
+ argbFormat.Ashift = 0;
+ argbFormat.Rmask = 0x0000ff00;
+ argbFormat.Rshift = 8;
+ argbFormat.Gmask = 0x00ff0000;
+ argbFormat.Gshift = 16;
+ argbFormat.Bmask = 0xff000000;
+ argbFormat.Bshift = 24;
+#endif
+
+ SDL_Surface *argbImage = SDL_ConvertSurface(image, &argbFormat, 0);
+
+ double colorMSE, alphaMSE;
+ if (format == XB_FMT_DXT1)
+ CompressImage((squish::u8 *)argbImage->pixels, image->w, image->h, out.GetData(), squish::kDxt1, colorMSE, alphaMSE);
+ else if (format == XB_FMT_DXT5)
+ CompressImage((squish::u8 *)argbImage->pixels, image->w, image->h, out.GetData(), squish::kDxt5, colorMSE, alphaMSE);
+
+ // print some info about the resulting image
+ printf("Size: %dx%d %s in %u bytes. Quality: %5.2f\n", image->w, image->h, GetFormatString(format), out.GetSize(), colorMSE);
+
+ SDL_FreeSurface(argbImage);
+}
+
+void Usage()
+{
+ puts("Usage: MakeDDS [-oN] input [output]");
+ puts(" -o1 for DXT1");
+ puts(" -o5 for DXT5");
+}
+
+void createDDS(const std::string& inputFile, const std::string& outputFile, unsigned int format)
+{
+ // Load the image
+ SDL_Surface* image = IMG_Load(inputFile.c_str());
+ if (!image)
+ {
+ printf("...unable to load image %s\n", inputFile.c_str());
+ return;
+ }
+
+ CDDSImage dds(image->w, image->h, format);
+ CompressToDDS(image, format, dds);
+
+ // write to a DDS file
+ dds.WriteFile(outputFile);
+
+ SDL_FreeSurface(image);
+}
+
+int main(int argc, char* argv[])
+{
+ bool valid = false;
+ CmdLineArgs args(argc, (const char**)argv);
+
+ if (args.size() == 1)
+ {
+ Usage();
+ return 1;
+ }
+
+ std::string inputFile;
+ std::string outputFile;
+
+ unsigned int format = squish::kDxt1;
+ for (unsigned int i = 1; i < args.size(); ++i)
+ {
+ if (!stricmp(args[i], "--help") || !stricmp(args[i], "-?") || !stricmp(args[i], "?"))
+ {
+ Usage();
+ return 1;
+ }
+ else if (!strncasecmp(args[i], "-o1", 3))
+ format = XB_FMT_DXT1;
+ else if (!strncasecmp(args[i], "-o5", 3))
+ format = XB_FMT_DXT5;
+ else if (!inputFile.size())
+ {
+ inputFile = args[i];
+ valid = true;
+ }
+ else if (!outputFile.size())
+ {
+ outputFile = args[i];
+ valid = true;
+ }
+ else
+ {
+ printf("Unrecognized command line flag: %s\n", args[i]);
+ }
+ }
+
+ if (outputFile.empty())
+ { // construct output file from input - rename to .dds
+ size_t pos = inputFile.find_last_of('.');
+ if (pos != std::string::npos)
+ {
+ outputFile = inputFile.substr(0, pos);
+ outputFile += ".dds";
+ }
+ }
+
+ if (!valid)
+ {
+ Usage();
+ return 1;
+ }
+
+ createDDS(inputFile, outputFile, format);
+}
diff --git a/tools/TexturePacker/Win32/MakeDDS.vcproj b/tools/TexturePacker/Win32/MakeDDS.vcproj
new file mode 100644
index 0000000000..814c2339a5
--- /dev/null
+++ b/tools/TexturePacker/Win32/MakeDDS.vcproj
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="MakeDDS"
+ ProjectGUID="{E85454A0-D9CF-4480-A9AE-AE2A7C3FBAD6}"
+ RootNamespace="MakeDDS"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="0"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories="..\..\..\xbmc\win32;..\..\..\guilib;..\..\..\xbmc\lib\libsquish"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="SDL.lib SDL_image.lib ..\..\..\xbmc\lib\libsquish\lib\squishd.lib"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="1"
+ CharacterSet="0"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ AdditionalIncludeDirectories="..\..\..\xbmc\win32;..\..\..\guilib;..\..\..\xbmc\lib\libsquish"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ RuntimeLibrary="2"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="SDL.lib SDL_image.lib ..\..\..\xbmc\lib\libsquish\lib\squish.lib"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\..\..\guilib\DDSImage.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\MakeDDS.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\..\..\guilib\DDSImage.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/tools/TexturePacker/Win32/TexturePacker.sln b/tools/TexturePacker/Win32/TexturePacker.sln
index e2f63546b0..4f1744f579 100644
--- a/tools/TexturePacker/Win32/TexturePacker.sln
+++ b/tools/TexturePacker/Win32/TexturePacker.sln
@@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TexturePacker", "TexturePacker.vcproj", "{57EC0A84-7E0C-4EEA-9E63-BB4EBF2310D7}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MakeDDS", "MakeDDS.vcproj", "{E85454A0-D9CF-4480-A9AE-AE2A7C3FBAD6}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -13,6 +15,10 @@ Global
{57EC0A84-7E0C-4EEA-9E63-BB4EBF2310D7}.Debug|Win32.Build.0 = Debug|Win32
{57EC0A84-7E0C-4EEA-9E63-BB4EBF2310D7}.Release|Win32.ActiveCfg = Release|Win32
{57EC0A84-7E0C-4EEA-9E63-BB4EBF2310D7}.Release|Win32.Build.0 = Release|Win32
+ {E85454A0-D9CF-4480-A9AE-AE2A7C3FBAD6}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E85454A0-D9CF-4480-A9AE-AE2A7C3FBAD6}.Debug|Win32.Build.0 = Debug|Win32
+ {E85454A0-D9CF-4480-A9AE-AE2A7C3FBAD6}.Release|Win32.ActiveCfg = Release|Win32
+ {E85454A0-D9CF-4480-A9AE-AE2A7C3FBAD6}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE