diff options
author | Jonathan Marshall <jmarshall@never.you.mind> | 2011-07-26 09:53:48 +1200 |
---|---|---|
committer | Jonathan Marshall <jmarshall@never.you.mind> | 2011-07-26 15:55:58 +1200 |
commit | 94c9c13c2e7e7533c0a60c6cbda0bef7bbf9f92a (patch) | |
tree | aa1c296da8fa801ed15d0bba4671ff60b61dc122 /tools | |
parent | 96ecf5ae8b8471aa7aa9e44f12c541b94aefa907 (diff) |
add flagging of opaque images in XBT files
Diffstat (limited to 'tools')
-rw-r--r-- | tools/TexturePacker/XBMCTex.cpp | 24 | ||||
-rw-r--r-- | tools/TexturePacker/XBTFWriter.cpp | 2 |
2 files changed, 19 insertions, 7 deletions
diff --git a/tools/TexturePacker/XBMCTex.cpp b/tools/TexturePacker/XBMCTex.cpp index b1c0105f61..63da7486ab 100644 --- a/tools/TexturePacker/XBMCTex.cpp +++ b/tools/TexturePacker/XBMCTex.cpp @@ -186,7 +186,7 @@ void CreateSkeletonHeader(CXBTF& xbtf, std::string fullPath) CreateSkeletonHeaderImpl(xbtf, fullPath, temp); } -CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned char *data, unsigned int size, unsigned int format, unsigned int flags) +CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned char *data, unsigned int size, unsigned int format, bool hasAlpha, unsigned int flags) { CXBTFFrame frame; #ifdef USE_LZO_PACKING @@ -226,7 +226,7 @@ CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned ch frame.SetUnpackedSize(size); frame.SetWidth(width); frame.SetHeight(height); - frame.SetFormat(format); + frame.SetFormat(hasAlpha ? format : format | XB_FMT_OPAQUE); frame.SetDuration(0); return frame; } @@ -237,6 +237,17 @@ void CompressImage(const squish::u8 *brga, int width, int height, squish::u8 *co squish::ComputeMSE(brga, width, height, compressed, flags | squish::kSourceBGRA, colorMSE, alphaMSE); } +bool HasAlpha(unsigned char *argb, unsigned int width, unsigned int height) +{ + unsigned char *p = argb + 3; // offset of alpha + for (unsigned int i = 0; i < 4*width*height; i += 4) + { + if (p[i] != 0xff) + return true; + } + return false; +} + CXBTFFrame createXBTFFrame(SDL_Surface* image, CXBTFWriter& writer, double maxMSE, unsigned int flags) { // Convert to ARGB @@ -275,6 +286,7 @@ CXBTFFrame createXBTFFrame(SDL_Surface* image, CXBTFWriter& writer, double maxMS width = image->w; height = image->h; + bool hasAlpha = HasAlpha(argb, width, height); if (flags & FLAGS_USE_DXT) { @@ -327,7 +339,7 @@ CXBTFFrame createXBTFFrame(SDL_Surface* image, CXBTFWriter& writer, double maxMS CXBTFFrame frame; if (format) { - frame = appendContent(writer, width, height, compressed, compressedSize, format, flags); + frame = appendContent(writer, width, height, compressed, compressedSize, format, hasAlpha, flags); if (compressedSize) delete[] compressed; } @@ -335,7 +347,7 @@ CXBTFFrame createXBTFFrame(SDL_Surface* image, CXBTFWriter& writer, double maxMS { // 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); + frame = appendContent(writer, width, height, argb, (width * height * 4), format, hasAlpha, flags); } SDL_FreeSurface(argbImage); @@ -443,7 +455,7 @@ 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()), + printf("%s%c (%d,%d @ %"PRIu64" bytes)\n", GetFormatString(frame.GetFormat()), frame.HasAlpha() ? ' ' : '*', frame.GetWidth(), frame.GetHeight(), frame.GetUnpackedSize()); file.SetLoop(0); @@ -483,7 +495,7 @@ 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()), + printf("%s%c (%d,%d @ %"PRIu64" bytes)\n", GetFormatString(frame.GetFormat()), frame.HasAlpha() ? ' ' : '*', frame.GetWidth(), frame.GetHeight(), frame.GetUnpackedSize()); } } diff --git a/tools/TexturePacker/XBTFWriter.cpp b/tools/TexturePacker/XBTFWriter.cpp index 4e9ce8dddb..78b47fe810 100644 --- a/tools/TexturePacker/XBTFWriter.cpp +++ b/tools/TexturePacker/XBTFWriter.cpp @@ -140,7 +140,7 @@ bool CXBTFWriter::UpdateHeader(const std::vector<unsigned int>& dupes) WRITE_U32(frame.GetWidth(), m_file); WRITE_U32(frame.GetHeight(), m_file); - WRITE_U32(frame.GetFormat(), m_file); + WRITE_U32(frame.GetFormat(true), m_file); WRITE_U64(frame.GetPackedSize(), m_file); WRITE_U64(frame.GetUnpackedSize(), m_file); WRITE_U32(frame.GetDuration(), m_file); |