Skip to content

Commit

Permalink
refactor CXBTFFrame, CXBTFFile and CXBTFReader and get rid of CXBTF
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Aug 11, 2015
1 parent cee6a32 commit ef1b60a
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 211 deletions.
8 changes: 6 additions & 2 deletions tools/depends/native/TexturePacker/src/Makefile.am
Expand Up @@ -2,7 +2,7 @@ AUTOMAKE_OPTIONS = subdir-objects

AM_CFLAGS = -DTARGET_POSIX -DUSE_LZO_PACKING
AM_CFLAGS += @EXTRA_DEFINES@
AM_CXXFLAGS = $(AM_CFLAGS)
AM_CXXFLAGS = $(AM_CFLAGS) -std=c++11

AM_CPPFLAGS = \
-I. \
Expand All @@ -25,7 +25,11 @@ TexturePacker_SOURCES = md5.cpp \
decoder/JPGDecoder.cpp \
decoder/GifHelper.cpp \
decoder/GIFDecoder.cpp \
XBTF.cpp
XBTF.cpp \
XBTFReader.cpp

XBTF.cpp:
@cp @KODI_SRC_DIR@/xbmc/guilib/XBTF.cpp .

XBTFReader.cpp:
@cp @KODI_SRC_DIR@/xbmc/guilib/XBTFReader.cpp .
26 changes: 14 additions & 12 deletions tools/depends/native/TexturePacker/src/TexturePacker.cpp
Expand Up @@ -32,6 +32,7 @@
#include <map>

#include "guilib/XBTF.h"
#include "guilib/XBTFReader.h"

#include "DecoderManager.h"

Expand Down Expand Up @@ -81,7 +82,7 @@ const char *GetFormatString(unsigned int format)
}
}

void CreateSkeletonHeaderImpl(CXBTF& xbtf, std::string fullPath, std::string relativePath)
void CreateSkeletonHeaderImpl(CXBTFReader& xbtfReader, std::string fullPath, std::string relativePath)
{
struct dirent* dp;
struct stat stat_p;
Expand All @@ -108,7 +109,7 @@ void CreateSkeletonHeaderImpl(CXBTF& xbtf, std::string fullPath, std::string rel
tmpPath += "/";
}

CreateSkeletonHeaderImpl(xbtf, fullPath + DIR_SEPARATOR + dp->d_name, tmpPath + dp->d_name);
CreateSkeletonHeaderImpl(xbtfReader, fullPath + DIR_SEPARATOR + dp->d_name, tmpPath + dp->d_name);
}
else if (DecoderManager::IsSupportedGraphicsFile(dp->d_name))
{
Expand All @@ -123,7 +124,7 @@ void CreateSkeletonHeaderImpl(CXBTF& xbtf, std::string fullPath, std::string rel

CXBTFFile file;
file.SetPath(fileName);
xbtf.GetFiles().push_back(file);
xbtfReader.AddFile(file);
}
}
}
Expand All @@ -136,10 +137,10 @@ void CreateSkeletonHeaderImpl(CXBTF& xbtf, std::string fullPath, std::string rel
}
}

void CreateSkeletonHeader(CXBTF& xbtf, std::string fullPath)
void CreateSkeletonHeader(CXBTFReader& xbtfReader, std::string fullPath)
{
std::string temp;
CreateSkeletonHeaderImpl(xbtf, fullPath, temp);
CreateSkeletonHeaderImpl(xbtfReader, fullPath, temp);
}

CXBTFFrame appendContent(CXBTFWriter &writer, int width, int height, unsigned char *data, unsigned int size, unsigned int format, bool hasAlpha, unsigned int flags)
Expand Down Expand Up @@ -322,23 +323,24 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou
{
map<string,unsigned int> hashes;
vector<unsigned int> dupes;
CXBTF xbtf;
CreateSkeletonHeader(xbtf, InputDir);
dupes.resize(xbtf.GetFiles().size());
CXBTFReader xbtfReader;
CreateSkeletonHeader(xbtfReader, InputDir);

std::vector<CXBTFFile> files = xbtfReader.GetFiles();
dupes.resize(files.size());
if (!dupecheck)
{
for (unsigned int i=0;i<dupes.size();++i)
dupes[i] = i;
}

CXBTFWriter writer(xbtf, OutputFile);
CXBTFWriter writer(xbtfReader, OutputFile);
if (!writer.Create())
{
fprintf(stderr, "Error creating file\n");
return 1;
}

std::vector<CXBTFFile>& files = xbtf.GetFiles();
for (size_t i = 0; i < files.size(); i++)
{
struct MD5Context ctx;
Expand All @@ -358,7 +360,7 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou

if (!loaded)
{
fprintf(stderr, "...unable to load image %s\n", file.GetPath());
fprintf(stderr, "...unable to load image %s\n", file.GetPath().c_str());
continue;
}

Expand All @@ -373,7 +375,7 @@ int createBundle(const std::string& InputDir, const std::string& OutputFile, dou

if (checkDupe(&ctx,hashes,dupes,i))
{
printf("**** duplicate of %s\n", files[dupes[i]].GetPath());
printf("**** duplicate of %s\n", files[dupes[i]].GetPath().c_str());
file.GetFrames().insert(file.GetFrames().end(),
files[dupes[i]].GetFrames().begin(),
files[dupes[i]].GetFrames().end());
Expand Down
Expand Up @@ -99,6 +99,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\..\..\xbmc\guilib\XBTFReader.cpp" />
<ClCompile Include="..\DecoderManager.cpp" />
<ClCompile Include="..\decoder\GIFDecoder.cpp" />
<ClCompile Include="..\decoder\GifHelper.cpp" />
Expand All @@ -111,6 +112,7 @@
<ClCompile Include="..\XBTFWriter.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\..\..\xbmc\guilib\XBTFReader.h" />
<ClInclude Include="..\cmdlineargs.h" />
<ClInclude Include="..\DecoderManager.h" />
<ClInclude Include="..\decoder\GIFDecoder.h" />
Expand Down
Expand Up @@ -48,6 +48,9 @@
<ClCompile Include="..\DecoderManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\..\..\xbmc\guilib\XBTFReader.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\cmdlineargs.h">
Expand Down Expand Up @@ -92,6 +95,9 @@
<ClInclude Include="..\DecoderManager.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\..\..\xbmc\guilib\XBTFReader.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
Expand Down
24 changes: 11 additions & 13 deletions tools/depends/native/TexturePacker/src/XBTFWriter.cpp
Expand Up @@ -22,6 +22,7 @@
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include "guilib/XBTF.h"
#include "guilib/XBTFReader.h"
#include "utils/EndianSwap.h"
#if defined(TARGET_FREEBSD) || defined(TARGET_DARWIN)
#include <stdlib.h>
Expand All @@ -34,7 +35,7 @@
#define WRITE_U32(i, file) { uint32_t _n = Endian_SwapLE32(i); fwrite(&_n, 4, 1, file); }
#define WRITE_U64(i, file) { uint64_t _n = i; _n = Endian_SwapLE64(i); fwrite(&_n, 8, 1, file); }

CXBTFWriter::CXBTFWriter(CXBTF& xbtf, const std::string& outputFile) : m_xbtf(xbtf)
CXBTFWriter::CXBTFWriter(CXBTFReader& xbtfReader, const std::string& outputFile) : m_xbtfReader(xbtfReader)
{
m_outputFile = outputFile;
m_file = NULL;
Expand Down Expand Up @@ -104,26 +105,23 @@ bool CXBTFWriter::UpdateHeader(const std::vector<unsigned int>& dupes)
return false;
}

uint64_t offset = m_xbtf.GetHeaderSize();
uint64_t offset = m_xbtfReader.GetHeaderSize();

WRITE_STR(XBTF_MAGIC, 4, m_file);
WRITE_STR(XBTF_VERSION, 1, m_file);
WRITE_STR(XBTF_MAGIC.c_str(), 4, m_file);
WRITE_STR(XBTF_VERSION.c_str(), 1, m_file);

std::vector<CXBTFFile>& files = m_xbtf.GetFiles();
std::vector<CXBTFFile> files = m_xbtfReader.GetFiles();
WRITE_U32(files.size(), m_file);
for (size_t i = 0; i < files.size(); i++)
{
CXBTFFile& file = files[i];

// Convert path to lower case
char* ch = file.GetPath();
while (*ch)
{
std::string path = file.GetPath();
for (std::string::iterator ch = path.begin(); ch != path.end(); ++ch)
*ch = tolower(*ch);
ch++;
}

WRITE_STR(file.GetPath(), 256, m_file);
WRITE_STR(path.c_str(), 256, m_file);
WRITE_U32(file.GetLoop(), m_file);

std::vector<CXBTFFrame>& frames = file.GetFrames();
Expand Down Expand Up @@ -151,9 +149,9 @@ bool CXBTFWriter::UpdateHeader(const std::vector<unsigned int>& dupes)

// Sanity check
int64_t pos = ftell(m_file);
if (pos != (int64_t)m_xbtf.GetHeaderSize())
if (pos != (int64_t)m_xbtfReader.GetHeaderSize())
{
printf("Expected header size (%" PRId64 ") != actual size (%" PRId64 ")\n", m_xbtf.GetHeaderSize(), pos);
printf("Expected header size (%" PRId64 ") != actual size (%" PRId64 ")\n", m_xbtfReader.GetHeaderSize(), pos);
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions tools/depends/native/TexturePacker/src/XBTFWriter.h
Expand Up @@ -25,12 +25,12 @@
#include <string>
#include <stdio.h>

class CXBTF;
class CXBTFReader;

class CXBTFWriter
{
public:
CXBTFWriter(CXBTF& xbtf, const std::string& outputFile);
CXBTFWriter(CXBTFReader& xbtfReader, const std::string& outputFile);
bool Create();
bool Close();
bool AppendContent(unsigned char const* data, size_t length);
Expand All @@ -39,7 +39,7 @@ class CXBTFWriter
private:
void Cleanup();

CXBTF& m_xbtf;
CXBTFReader& m_xbtfReader;
std::string m_outputFile;
FILE* m_file;
unsigned char *m_data;
Expand Down
26 changes: 13 additions & 13 deletions xbmc/guilib/TextureBundleXBT.cpp
Expand Up @@ -122,7 +122,7 @@ void CTextureBundleXBT::GetTexturesFromPath(const std::string &path, std::vector
std::string testPath = Normalize(path);
URIUtils::AddSlashAtEnd(testPath);

std::vector<CXBTFFile>& files = m_XBTFReader.GetFiles();
std::vector<CXBTFFile> files = m_XBTFReader.GetFiles();
for (size_t i = 0; i < files.size(); i++)
{
std::string path = files[i].GetPath();
Expand All @@ -136,14 +136,14 @@ bool CTextureBundleXBT::LoadTexture(const std::string& Filename, CBaseTexture**
{
std::string name = Normalize(Filename);

CXBTFFile* file = m_XBTFReader.Find(name);
if (!file)
CXBTFFile file;
if (!m_XBTFReader.Get(name, file))
return false;

if (file->GetFrames().size() == 0)
if (file.GetFrames().size() == 0)
return false;

CXBTFFrame& frame = file->GetFrames().at(0);
CXBTFFrame& frame = file.GetFrames().at(0);
if (!ConvertFrameToTexture(Filename, frame, ppTexture))
{
return false;
Expand All @@ -160,20 +160,20 @@ int CTextureBundleXBT::LoadAnim(const std::string& Filename, CBaseTexture*** ppT
{
std::string name = Normalize(Filename);

CXBTFFile* file = m_XBTFReader.Find(name);
if (!file)
CXBTFFile file;
if (!m_XBTFReader.Get(name, file))
return false;

if (file->GetFrames().size() == 0)
if (file.GetFrames().size() == 0)
return false;

size_t nTextures = file->GetFrames().size();
size_t nTextures = file.GetFrames().size();
*ppTextures = new CBaseTexture*[nTextures];
*ppDelays = new int[nTextures];

for (size_t i = 0; i < nTextures; i++)
{
CXBTFFrame& frame = file->GetFrames().at(i);
CXBTFFrame& frame = file.GetFrames().at(i);

if (!ConvertFrameToTexture(Filename, frame, &((*ppTextures)[i])))
{
Expand All @@ -183,9 +183,9 @@ int CTextureBundleXBT::LoadAnim(const std::string& Filename, CBaseTexture*** ppT
(*ppDelays)[i] = frame.GetDuration();
}

width = file->GetFrames().at(0).GetWidth();
height = file->GetFrames().at(0).GetHeight();
nLoops = file->GetLoop();
width = file.GetFrames().at(0).GetWidth();
height = file.GetFrames().at(0).GetHeight();
nLoops = file.GetLoop();

return nTextures;
}
Expand Down

0 comments on commit ef1b60a

Please sign in to comment.