aboutsummaryrefslogtreecommitdiff
path: root/tools/TexturePacker
diff options
context:
space:
mode:
authorS. Davilla <davilla@4pi.com>2011-04-24 15:36:44 -0400
committerS. Davilla <davilla@4pi.com>2011-04-30 14:31:28 -0400
commitd1db2b156c01031612ea57558189f4220502f154 (patch)
treef66640842d6fb2702f909366b1eaf6d23de46097 /tools/TexturePacker
parentc22adfa0f3099d308484ef29f807945dc31e36aa (diff)
refactor TexturePacker
Diffstat (limited to 'tools/TexturePacker')
-rw-r--r--tools/TexturePacker/Makefile.in35
-rw-r--r--tools/TexturePacker/SDL_anigif.cpp (renamed from tools/TexturePacker/SDL_anigif.c)2
-rw-r--r--tools/TexturePacker/XBMCTex.cpp318
-rw-r--r--tools/TexturePacker/md5.cpp (renamed from tools/TexturePacker/md5.c)0
4 files changed, 210 insertions, 145 deletions
diff --git a/tools/TexturePacker/Makefile.in b/tools/TexturePacker/Makefile.in
index 2d0dfe5bf3..8fb6fdd1c6 100644
--- a/tools/TexturePacker/Makefile.in
+++ b/tools/TexturePacker/Makefile.in
@@ -1,17 +1,24 @@
-ARCH=@ARCH@
-DEFINES =
-ifeq ($(findstring osx,$(ARCH)),osx)
-LIBS = @abs_top_srcdir@/lib/libsquish/libsquish.a -L/Users/Shared/xbmc-depends/osx-10.4_i386/lib -lSDL_image -lSDL -llzo2
-else
-LIBS = @abs_top_srcdir@/lib/libsquish/libsquish.a -lSDL_image -lSDL -llzo2
+DEFINES += -D_LINUX -DUSE_LZO_PACKING
+ifneq ($(or $(findstring powerpc,arm-osx),$(findstring ppc, arm-osx)),)
+DEFINES += -DHOST_BIGENDIAN
endif
-OBJS = \
- SDL_anigif.o \
- XBTFWriter.o \
- XBMCTex.o \
- md5.o \
- @abs_top_srcdir@/xbmc/guilib/XBTF.o
+CXXFLAGS+= \
+ -I. \
+ -I@abs_top_srcdir@/lib \
+ -I@abs_top_srcdir@/xbmc \
+ -I@abs_top_srcdir@/xbmc/linux
+
+LIBS += -L@abs_top_srcdir@/lib/libsquish -lsquish
+LIBS += -lSDL_image -lSDL -llzo2
+
+SRCS = \
+ md5.cpp \
+ SDL_anigif.cpp \
+ XBTFWriter.cpp \
+ XBMCTex.cpp \
+ @abs_top_srcdir@/xbmc/guilib/XBTF.cpp
+
TARGET = TexturePacker
CLEAN_FILES=$(TARGET)
@@ -20,5 +27,5 @@ all: $(TARGET)
include @abs_top_srcdir@/Makefile.include
-$(TARGET): $(OBJS)
- $(CXX) $(CXXFLAGS) $(OBJS) $(LDFLAGS) $(LIBS) -o $(TARGET)
+$(TARGET): $(SRCS)
+ $(CXX) $(CXXFLAGS) $(DEFINES) $(INCLUDES) $(SRCS) $(LDFLAGS) $(LIBS) -o $(TARGET)
diff --git a/tools/TexturePacker/SDL_anigif.c b/tools/TexturePacker/SDL_anigif.cpp
index 91d31f8af3..4269e31634 100644
--- a/tools/TexturePacker/SDL_anigif.c
+++ b/tools/TexturePacker/SDL_anigif.cpp
@@ -290,7 +290,7 @@ int AG_LoadGIF_RW( SDL_RWops* src, AG_Frame* frames, int maxFrames )
if ( src == NULL )
return 0;
- gd = malloc( sizeof(*gd) );
+ gd = (gifdata*)malloc( sizeof(*gd) );
memset( gd, 0, sizeof(*gd) );
gd->src = src;
diff --git a/tools/TexturePacker/XBMCTex.cpp b/tools/TexturePacker/XBMCTex.cpp
index a6448b569e..3ff0f49d6e 100644
--- a/tools/TexturePacker/XBMCTex.cpp
+++ b/tools/TexturePacker/XBMCTex.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2009 Team XBMC
+ * Copyright (C) 2005-2010 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
@@ -19,47 +19,61 @@
*
*/
-#include <sys/types.h>
-#include <sys/stat.h>
+//#include <sys/types.h>
+//#include <sys/stat.h>
+//#include <string>
+#include <cerrno>
+//#include <cstring>
+//#include <inttypes.h>
#include <dirent.h>
#include <map>
-#include <libsquish/squish.h>
-#include <string>
-#define __STDC_FORMAT_MACROS
-#include <inttypes.h>
+
+//#define __STDC_FORMAT_MACROS
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
-#include <cerrno>
-#include <cstring>
+#undef main
+
#include "guilib/XBTF.h"
#include "XBTFWriter.h"
+#include "md5.h"
#include "SDL_anigif.h"
#include "cmdlineargs.h"
+#include "libsquish/squish.h"
+
#ifdef _WIN32
#define strncasecmp strnicmp
#endif
-#ifdef _LINUX
-#include <lzo/lzo1x.h>
-#else
+#ifdef USE_LZO_PACKING
+#ifdef _WIN32
#include "../../lib/win32/liblzo/LZO1X.H"
+#else
+#include <lzo/lzo1x.h>
+#endif
#endif
-#define DIR_SEPARATOR "/"
-#define DIR_SEPARATOR_CHAR '/'
+using namespace std;
#define FLAGS_USE_LZO 1
#define FLAGS_ALLOW_YCOCG 2
+#define FLAGS_USE_DXT 4
+#define FLAGS_USE_ETC 8
+#define FLAGS_USE_PVR 16
-#undef main
+#define DIR_SEPARATOR "/"
+#define DIR_SEPARATOR_CHAR '/'
-extern "C"
+int NP2( unsigned x )
{
-#include "md5.h"
+ --x;
+ x |= x >> 1;
+ x |= x >> 2;
+ x |= x >> 4;
+ x |= x >> 8;
+ x |= x >> 16;
+ return ++x;
}
-using namespace std;
-
const char *GetFormatString(unsigned int format)
{
switch (format)
@@ -120,48 +134,50 @@ void CreateSkeletonHeaderImpl(CXBTF& xbtf, std::string fullPath, std::string rel
if (dirp)
{
- while ((dp = readdir(dirp)) != NULL)
- {
- if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
+ while ((dp = readdir(dirp)) != NULL)
{
- continue;
- }
-
- //stat to check for dir type (reiserfs fix)
- std::string fileN = fullPath + "/" + dp->d_name;
- stat(fileN.c_str(), &stat_p);
-
- if (dp->d_type == DT_DIR || stat_p.st_mode & S_IFDIR)
- {
- std::string tmpPath = relativePath;
- if (tmpPath.size() > 0)
+ if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)
{
- tmpPath += "/";
+ continue;
}
- CreateSkeletonHeaderImpl(xbtf, fullPath + DIR_SEPARATOR + dp->d_name, tmpPath + dp->d_name);
- }
- else if (IsGraphicsFile(dp->d_name))
- {
- std::string fileName = "";
- if (relativePath.size() > 0)
+ //stat to check for dir type (reiserfs fix)
+ std::string fileN = fullPath + "/" + dp->d_name;
+ stat(fileN.c_str(), &stat_p);
+
+ if (dp->d_type == DT_DIR || stat_p.st_mode & S_IFDIR)
{
- fileName += relativePath;
- fileName += "/";
+ std::string tmpPath = relativePath;
+ if (tmpPath.size() > 0)
+ {
+ tmpPath += "/";
+ }
+
+ CreateSkeletonHeaderImpl(xbtf, fullPath + DIR_SEPARATOR + dp->d_name, tmpPath + dp->d_name);
}
+ else if (IsGraphicsFile(dp->d_name))
+ {
+ std::string fileName = "";
+ if (relativePath.size() > 0)
+ {
+ fileName += relativePath;
+ fileName += "/";
+ }
- fileName += dp->d_name;
+ fileName += dp->d_name;
- CXBTFFile file;
- file.SetPath(fileName);
- xbtf.GetFiles().push_back(file);
+ CXBTFFile file;
+ file.SetPath(fileName);
+ xbtf.GetFiles().push_back(file);
+ }
}
- }
- closedir(dirp);
+ closedir(dirp);
}
else
+ {
printf("Error opening %s (%s)\n", fullPath.c_str(), strerror(errno));
+ }
}
void CreateSkeletonHeader(CXBTF& xbtf, std::string fullPath)
@@ -173,35 +189,37 @@ void CreateSkeletonHeader(CXBTF& xbtf, std::string fullPath)
CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned char *data, unsigned int size, unsigned int format, unsigned int flags)
{
CXBTFFrame frame;
- lzo_uint compressedSize = size;
+ unsigned int packedSize = size;
+#ifdef USE_LZO_PACKING
if ((flags & FLAGS_USE_LZO) == FLAGS_USE_LZO)
{
// grab a temporary buffer for unpacking into
- squish::u8 *compressed = new squish::u8[size + size / 16 + 64 + 3]; // see simple.c in lzo
- squish::u8 *working = new squish::u8[LZO1X_999_MEM_COMPRESS];
- if (compressed && working)
+ unsigned char *packed = new unsigned char[size + size / 16 + 64 + 3]; // see simple.c in lzo
+ unsigned char *working = new unsigned char[LZO1X_999_MEM_COMPRESS];
+ if (packed && working)
{
- if (lzo1x_999_compress(data, size, compressed, (lzo_uint*)&compressedSize, working) != LZO_E_OK || compressedSize > size)
+ if (lzo1x_999_compress(data, size, packed, (lzo_uint*)&packedSize, working) != LZO_E_OK || packedSize > size)
{
// compression failed, or compressed size is bigger than uncompressed, so store as uncompressed
- compressedSize = size;
+ packedSize = size;
writer.AppendContent(data, size);
}
else
{ // success
lzo_uint optimSize = size;
- lzo1x_optimize(compressed, compressedSize, data, &optimSize, NULL);
- writer.AppendContent(compressed, compressedSize);
+ lzo1x_optimize(packed, packedSize, data, &optimSize, NULL);
+ writer.AppendContent(packed, packedSize);
}
delete[] working;
- delete[] compressed;
+ delete[] packed;
}
}
else
+#endif
{
writer.AppendContent(data, size);
}
- frame.SetPackedSize(compressedSize);
+ frame.SetPackedSize(packedSize);
frame.SetUnpackedSize(size);
frame.SetWidth(width);
frame.SetHeight(height);
@@ -225,16 +243,7 @@ CXBTFFrame createXBTFFrame(SDL_Surface* image, CXBTFWriter& writer, double maxMS
argbFormat.BytesPerPixel = 4;
// For DXT5 we need RGBA
-#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
+#if defined(HOST_BIGENDIAN)
argbFormat.Amask = 0x000000ff;
argbFormat.Ashift = 0;
argbFormat.Rmask = 0x0000ff00;
@@ -243,82 +252,103 @@ CXBTFFrame createXBTFFrame(SDL_Surface* image, CXBTFWriter& writer, double maxMS
argbFormat.Gshift = 16;
argbFormat.Bmask = 0xff000000;
argbFormat.Bshift = 24;
+#else
+ argbFormat.Amask = 0xff000000;
+ argbFormat.Ashift = 24;
+ argbFormat.Rmask = 0x00ff0000;
+ argbFormat.Rshift = 16;
+ argbFormat.Gmask = 0x0000ff00;
+ argbFormat.Gshift = 8;
+ argbFormat.Bmask = 0x000000ff;
+ argbFormat.Bshift = 0;
#endif
- SDL_Surface *argbImage = SDL_ConvertSurface(image, &argbFormat, 0);
-
+ int width, height;
unsigned int format = 0;
- double colorMSE, alphaMSE;
- squish::u8* argb = (squish::u8 *)argbImage->pixels;
-#ifndef __arm__
- unsigned int compressedSize = squish::GetStorageRequirements(image->w, image->h, squish::kDxt5);
- squish::u8* compressed = new squish::u8[compressedSize];
- // first try DXT1, which is only 4bits/pixel
- CompressImage(argb, image->w, image->h, compressed, squish::kDxt1, colorMSE, alphaMSE);
- if (colorMSE < maxMSE && alphaMSE < maxMSE)
- { // success - use it
- compressedSize = squish::GetStorageRequirements(image->w, image->h, squish::kDxt1);
- format = XB_FMT_DXT1;
- }
- if (!format && alphaMSE == 0 && (flags & FLAGS_ALLOW_YCOCG) == FLAGS_ALLOW_YCOCG)
- { // no alpha channel, so DXT5YCoCg is going to be the best DXT5 format
-/* CompressImage(argb, image->w, image->h, compressed, squish::kDxt5 | squish::kUseYCoCg, colorMSE, alphaMSE);
+ SDL_Surface *argbImage = SDL_ConvertSurface(image, &argbFormat, 0);
+ unsigned char* argb = (unsigned char*)argbImage->pixels;
+ unsigned int compressedSize = 0;
+ unsigned char* compressed = NULL;
+
+ width = image->w;
+ height = image->h;
+
+ if (flags & FLAGS_USE_DXT)
+ {
+ double colorMSE, alphaMSE;
+ compressedSize = squish::GetStorageRequirements(width, height, squish::kDxt5);
+ compressed = new unsigned char[compressedSize];
+ // first try DXT1, which is only 4bits/pixel
+ CompressImage(argb, width, height, compressed, squish::kDxt1, colorMSE, alphaMSE);
if (colorMSE < maxMSE && alphaMSE < maxMSE)
{ // success - use it
- compressedSize = squish::GetStorageRequirements(image->w, image->h, squish::kDxt5);
- format = XB_FMT_DXT5_YCoCg;
+ compressedSize = squish::GetStorageRequirements(width, height, squish::kDxt1);
+ format = XB_FMT_DXT1;
}
- */
- }
- if (!format)
- { // try DXT3 and DXT5 - use whichever is better (color is the same, but alpha will be different)
- CompressImage(argb, image->w, image->h, compressed, squish::kDxt3, colorMSE, alphaMSE);
- if (colorMSE < maxMSE)
- { // color is fine, test DXT5 as well
- double dxt5MSE;
- squish::u8* compressed2 = new squish::u8[squish::GetStorageRequirements(image->w, image->h, squish::kDxt5)];
- CompressImage(argb, image->w, image->h, compressed2, squish::kDxt5, colorMSE, dxt5MSE);
- if (alphaMSE < maxMSE && alphaMSE < dxt5MSE)
- { // DXT3 passes and is best
- compressedSize = squish::GetStorageRequirements(image->w, image->h, squish::kDxt3);
- format = XB_FMT_DXT3;
+ /*
+ if (!format && alphaMSE == 0 && (flags & FLAGS_ALLOW_YCOCG) == FLAGS_ALLOW_YCOCG)
+ {
+ // no alpha channel, so DXT5YCoCg is going to be the best DXT5 format
+ CompressImage(argb, width, height, compressed, squish::kDxt5 | squish::kUseYCoCg, colorMSE, alphaMSE);
+ if (colorMSE < maxMSE && alphaMSE < maxMSE)
+ { // success - use it
+ compressedSize = squish::GetStorageRequirements(width, height, squish::kDxt5);
+ format = XB_FMT_DXT5_YCoCg;
}
- else if (dxt5MSE < maxMSE)
- { // DXT5 passes
- compressedSize = squish::GetStorageRequirements(image->w, image->h, squish::kDxt5);
- memcpy(compressed, compressed2, compressedSize);
- format = XB_FMT_DXT5;
+ }
+ */
+ if (!format)
+ { // try DXT3 and DXT5 - use whichever is better (color is the same, but alpha will be different)
+ CompressImage(argb, width, height, compressed, squish::kDxt3, colorMSE, alphaMSE);
+ if (colorMSE < maxMSE)
+ { // color is fine, test DXT5 as well
+ double dxt5MSE;
+ squish::u8* compressed2 = new squish::u8[squish::GetStorageRequirements(width, height, squish::kDxt5)];
+ CompressImage(argb, width, height, compressed2, squish::kDxt5, colorMSE, dxt5MSE);
+ if (alphaMSE < maxMSE && alphaMSE < dxt5MSE)
+ { // DXT3 passes and is best
+ compressedSize = squish::GetStorageRequirements(width, height, squish::kDxt3);
+ format = XB_FMT_DXT3;
+ }
+ else if (dxt5MSE < maxMSE)
+ { // DXT5 passes
+ compressedSize = squish::GetStorageRequirements(width, height, squish::kDxt5);
+ memcpy(compressed, compressed2, compressedSize);
+ format = XB_FMT_DXT5;
+ }
+ delete[] compressed2;
}
- delete[] compressed2;
}
}
+
CXBTFFrame frame;
- if (!format)
- { // none of the compressed stuff works for us, so we use 32bit texture
- format = XB_FMT_A8R8G8B8;
- frame = appendContent(writer, image->w, image->h, argb, image->w * image->h * 4, format, flags);
+ if (format)
+ {
+ frame = appendContent(writer, width, height, compressed, compressedSize, format, flags);
+ if (compressedSize)
+ delete[] compressed;
}
else
{
- frame = appendContent(writer, image->w, image->h, compressed, compressedSize, format, flags);
+ // none of the compressed stuff works for us, so we use 32bit texture
+ format = XB_FMT_A8R8G8B8;
+ frame = appendContent(writer, width, height, argb, (width * height * 4), format, flags);
}
- delete[] compressed;
- SDL_FreeSurface(argbImage);
- return frame;
-#else // For ARM, dont use DXT compression!!!
- CXBTFFrame frame = appendContent(writer, image->w, image->h, argb, image->w * image->h * 4, XB_FMT_A8R8G8B8, flags);
+
SDL_FreeSurface(argbImage);
return frame;
-#endif
}
void Usage()
{
puts("Usage:");
puts(" -help Show this screen.");
- puts(" -dupecheck Enable duplicate file detection. Reduces output file size.");
puts(" -input <dir> Input directory. Default: current dir");
puts(" -output <dir> Output directory/filename. Default: Textures.xpr");
+ puts(" -dupecheck Enable duplicate file detection. Reduces output file size. Default: on");
+ puts(" -use_lzo Use lz0 packing. Default: on");
+ puts(" -use_dxt Use DXT compression. Default: on");
+ puts(" -use_none Use No compression. Default: off");
}
static bool checkDupe(struct MD5Context* ctx,
@@ -401,8 +431,7 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou
{
printf("**** duplicate of %s\n", files[dupes[i]].GetPath());
file.GetFrames().insert(file.GetFrames().end(),
- files[dupes[i]].GetFrames().begin(),
- files[dupes[i]].GetFrames().end());
+ files[dupes[i]].GetFrames().begin(), files[dupes[i]].GetFrames().end());
skip = true;
}
}
@@ -411,7 +440,8 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou
{
CXBTFFrame frame = createXBTFFrame(image, writer, maxMSE, flags);
- printf("%s (%d,%d @ %"PRIu64" bytes)\n", GetFormatString(frame.GetFormat()), frame.GetWidth(), frame.GetHeight(), frame.GetUnpackedSize());
+ printf("%s (%d,%d @ %"PRIu64" bytes)\n", GetFormatString(frame.GetFormat()),
+ frame.GetWidth(), frame.GetHeight(), frame.GetUnpackedSize());
file.SetLoop(0);
file.GetFrames().push_back(frame);
@@ -429,16 +459,15 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou
if (dupecheck)
{
for (int j = 0; j < gnAG; j++)
- MD5Update(&ctx,(const uint8_t*)gpAG[j].surface->pixels,
- gpAG[j].surface->h*
- gpAG[j].surface->pitch);
+ MD5Update(&ctx,
+ (const uint8_t*)gpAG[j].surface->pixels,
+ gpAG[j].surface->h * gpAG[j].surface->pitch);
if (checkDupe(&ctx,hashes,dupes,i))
{
printf("**** duplicate of %s\n", files[dupes[i]].GetPath());
file.GetFrames().insert(file.GetFrames().end(),
- files[dupes[i]].GetFrames().begin(),
- files[dupes[i]].GetFrames().end());
+ files[dupes[i]].GetFrames().begin(), files[dupes[i]].GetFrames().end());
skip = true;
}
}
@@ -451,7 +480,8 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou
CXBTFFrame frame = createXBTFFrame(gpAG[j].surface, writer, maxMSE, flags);
frame.SetDuration(gpAG[j].delay);
file.GetFrames().push_back(frame);
- printf("%s (%d,%d @ %"PRIu64" bytes)\n", GetFormatString(frame.GetFormat()), frame.GetWidth(), frame.GetHeight(), frame.GetUnpackedSize());
+ printf("%s (%d,%d @ %"PRIu64" bytes)\n", GetFormatString(frame.GetFormat()),
+ frame.GetWidth(), frame.GetHeight(), frame.GetUnpackedSize());
}
}
AG_FreeSurfaces(gpAG, gnAG);
@@ -478,13 +508,22 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou
int main(int argc, char* argv[])
{
+#ifdef USE_LZO_PACKING
if (lzo_init() != LZO_E_OK)
return 1;
-
+#endif
bool valid = false;
+ unsigned int flags = 0;
bool dupecheck = false;
CmdLineArgs args(argc, (const char**)argv);
+ // setup some defaults, lzo post compression,
+ // dxt unless compiled with prv, then use pvr
+ flags = FLAGS_USE_DXT;
+#ifdef USE_LZO_PACKING
+ flags |= FLAGS_USE_LZO;
+#endif
+
if (args.size() == 1)
{
Usage();
@@ -507,7 +546,9 @@ int main(int argc, char* argv[])
valid = true;
}
else if (!strcmp(args[i], "-dupecheck"))
+ {
dupecheck = true;
+ }
else if (!stricmp(args[i], "-output") || !stricmp(args[i], "-o"))
{
OutputFilename = args[++i];
@@ -517,6 +558,24 @@ int main(int argc, char* argv[])
while ((c = (char *)strchr(OutputFilename.c_str(), '\\')) != NULL) *c = '/';
#endif
}
+ else if (!stricmp(args[i], "-use_none"))
+ {
+ flags &= ~FLAGS_USE_DXT;
+ flags &= ~FLAGS_USE_ETC;
+ flags &= ~FLAGS_USE_PVR;
+ }
+ else if (!stricmp(args[i], "-use_dxt"))
+ {
+ flags &= ~FLAGS_USE_ETC;
+ flags &= ~FLAGS_USE_PVR;
+ flags |= FLAGS_USE_DXT;
+ }
+#ifdef USE_LZO_PACKING
+ else if (!stricmp(args[i], "-use_lzo"))
+ {
+ flags |= FLAGS_USE_LZO;
+ }
+#endif
else
{
printf("Unrecognized command line flag: %s\n", args[i]);
@@ -534,6 +593,5 @@ int main(int argc, char* argv[])
InputDir += DIR_SEPARATOR;
double maxMSE = 1.5; // HQ only please
- unsigned int flags = FLAGS_USE_LZO; // TODO: currently no YCoCg (commandline option?)
createBundle(InputDir, OutputFilename, maxMSE, flags, dupecheck);
}
diff --git a/tools/TexturePacker/md5.c b/tools/TexturePacker/md5.cpp
index ce0c310963..ce0c310963 100644
--- a/tools/TexturePacker/md5.c
+++ b/tools/TexturePacker/md5.cpp