aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorjmarshallnz <jmarshallnz@svn>2010-09-15 00:30:37 +0000
committerjmarshallnz <jmarshallnz@svn>2010-09-15 00:30:37 +0000
commit6d368804f9534e4f3ab93649ca5c2bb4059c7bf0 (patch)
treea0658c589c9bde98dd5b1546efcb4316fa8254b9 /tools
parent14ac82d6063f7246d170a3da8cbe9b333dbb6bfb (diff)
changed: TexturePacker - don't write to a temporary file, keep it in memory instead.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@33815 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'tools')
-rw-r--r--tools/TexturePacker/TexturePacker.exebin86528 -> 86528 bytes
-rw-r--r--tools/TexturePacker/XBTFWriter.cpp55
-rw-r--r--tools/TexturePacker/XBTFWriter.h5
3 files changed, 31 insertions, 29 deletions
diff --git a/tools/TexturePacker/TexturePacker.exe b/tools/TexturePacker/TexturePacker.exe
index 9a96102b46..6da10b0889 100644
--- a/tools/TexturePacker/TexturePacker.exe
+++ b/tools/TexturePacker/TexturePacker.exe
Binary files differ
diff --git a/tools/TexturePacker/XBTFWriter.cpp b/tools/TexturePacker/XBTFWriter.cpp
index d5beb143d7..6435734d91 100644
--- a/tools/TexturePacker/XBTFWriter.cpp
+++ b/tools/TexturePacker/XBTFWriter.cpp
@@ -34,7 +34,9 @@
CXBTFWriter::CXBTFWriter(CXBTF& xbtf, const std::string& outputFile) : m_xbtf(xbtf)
{
m_outputFile = outputFile;
- m_file = m_tempFile = NULL;
+ m_file = NULL;
+ m_data = NULL;
+ m_size = 0;
}
bool CXBTFWriter::Create()
@@ -45,52 +47,49 @@ bool CXBTFWriter::Create()
return false;
}
- m_tempFile = fopen(TEMP_FILE, "wb");
- if (m_tempFile == NULL)
- {
- return false;
- }
-
return true;
}
bool CXBTFWriter::Close()
{
- if (m_file == NULL || m_tempFile == NULL)
+ if (m_file == NULL || m_data == NULL)
{
return false;
}
- fclose(m_tempFile);
- m_tempFile = fopen(TEMP_FILE, "rb");
- if (m_tempFile == NULL)
- {
- return false;
- }
-
- unsigned char* tmp = new unsigned char[10*1024*1024];
- size_t bytesRead;
- while ((bytesRead = fread(tmp, 1, TEMP_SIZE, m_tempFile)) > 0)
- {
- fwrite(tmp, bytesRead, 1, m_file);
- }
- delete[] tmp;
+ fwrite(m_data, 1, m_size, m_file);
- fclose(m_file);
- fclose(m_tempFile);
- unlink(TEMP_FILE);
+ Cleanup();
return true;
}
-bool CXBTFWriter::AppendContent(unsigned char const* data, size_t length)
+void CXBTFWriter::Cleanup()
{
- if (m_tempFile == NULL)
+ free(m_data);
+ m_data = NULL;
+ m_size = 0;
+ if (m_file)
{
+ fclose(m_file);
+ m_file = NULL;
+ }
+}
+
+bool CXBTFWriter::AppendContent(unsigned char const* data, size_t length)
+{
+ unsigned char *new_data = (unsigned char *)realloc(m_data, m_size + length);
+
+ if (new_data == NULL)
+ { // OOM - cleanup and fail
+ Cleanup();
return false;
}
- fwrite(data, length, 1, m_tempFile);
+ m_data = new_data;
+
+ memcpy(m_data + m_size, data, length);
+ m_size += length;
return true;
}
diff --git a/tools/TexturePacker/XBTFWriter.h b/tools/TexturePacker/XBTFWriter.h
index d86094e449..f7f06ee3f2 100644
--- a/tools/TexturePacker/XBTFWriter.h
+++ b/tools/TexturePacker/XBTFWriter.h
@@ -37,10 +37,13 @@ public:
bool UpdateHeader(const std::vector<unsigned int>& dupes);
private:
+ void Cleanup();
+
CXBTF& m_xbtf;
std::string m_outputFile;
FILE* m_file;
- FILE* m_tempFile;
+ unsigned char *m_data;
+ size_t m_size;
};
#endif