diff --git a/src/bflim.cpp b/src/bflim.cpp index 4909901..ae7e7b8 100644 --- a/src/bflim.cpp +++ b/src/bflim.cpp @@ -2,8 +2,8 @@ #include #include -const u32 CBflim::s_uSignatureBflim = CONVERT_ENDIAN('FLIM'); -const u32 CBflim::s_uSignatureImage = CONVERT_ENDIAN('imag'); +const u32 CBflim::s_uSignatureBflim = SDW_CONVERT_ENDIAN32('FLIM'); +const u32 CBflim::s_uSignatureImage = SDW_CONVERT_ENDIAN32('imag'); const int CBflim::s_nBPP[] = { 8, 8, 8, 16, 16, 16, 24, 16, 16, 32, 4, 8, 0, 0, 0, 0, 0, 0, 4, 4 }; const int CBflim::s_nDecodeTransByte[64] = { @@ -47,14 +47,14 @@ void CBflim::SetVerbose(bool a_bVerbose) bool CBflim::DecodeFile() { bool bResult = true; - m_fpBflim = FFopen(m_pFileName, "rb"); + m_fpBflim = Fopen(m_pFileName, "rb"); if (m_fpBflim == nullptr) { return false; } - FFseek(m_fpBflim, 0, SEEK_END); - n64 nFileSize = FFtell(m_fpBflim); - FFseek(m_fpBflim, 0, SEEK_SET); + Fseek(m_fpBflim, 0, SEEK_END); + n64 nFileSize = Ftell(m_fpBflim); + Fseek(m_fpBflim, 0, SEEK_SET); u8* pBin = new u8[static_cast(nFileSize)]; fread(pBin, 1, static_cast(nFileSize), m_fpBflim); fclose(m_fpBflim); @@ -90,7 +90,7 @@ bool CBflim::DecodeFile() pvrtexture::CPVRTexture* pPVRTexture = nullptr; if (decode(pBin, nWidth, nHeight, pImageBlock->Format, pImageBlock->Rotate, &pPVRTexture) == 0) { - FILE* fp = FFopen(m_pPngName, "wb"); + FILE* fp = Fopen(m_pPngName, "wb"); if (fp == nullptr) { delete pPVRTexture; @@ -154,14 +154,14 @@ bool CBflim::DecodeFile() bool CBflim::EncodeFile() { bool bResult = true; - m_fpBflim = FFopen(m_pFileName, "rb"); + m_fpBflim = Fopen(m_pFileName, "rb"); if (m_fpBflim == nullptr) { return false; } - FFseek(m_fpBflim, 0, SEEK_END); - n64 nFileSize = FFtell(m_fpBflim); - FFseek(m_fpBflim, 0, SEEK_SET); + Fseek(m_fpBflim, 0, SEEK_END); + n64 nFileSize = Ftell(m_fpBflim); + Fseek(m_fpBflim, 0, SEEK_SET); u8* pBin = new u8[static_cast(nFileSize)]; fread(pBin, 1, static_cast(nFileSize), m_fpBflim); fclose(m_fpBflim); @@ -194,7 +194,7 @@ bool CBflim::EncodeFile() { printf("INFO: width: %X(%X), height: %X(%X), checksize: %X, size: %X, bpp: %d, format: %0X\n", nWidth, pImageBlock->Width, nHeight, pImageBlock->Height, nCheckSize, pImageBlock->ImageSize, pImageBlock->ImageSize * 8 / nWidth / nHeight, pImageBlock->Format); } - FILE* fp = FFopen(m_pPngName, "rb"); + FILE* fp = Fopen(m_pPngName, "rb"); if (fp == nullptr) { bResult = false; @@ -297,7 +297,7 @@ bool CBflim::EncodeFile() delete pPVRTexture; if (!bSame) { - m_fpBflim = FFopen(m_pFileName, "wb"); + m_fpBflim = Fopen(m_pFileName, "wb"); if (m_fpBflim != nullptr) { u8* pBuffer = nullptr; @@ -325,18 +325,18 @@ bool CBflim::EncodeFile() bool CBflim::IsBflimFile(const char* a_pFileName) { - FILE* fp = FFopen(a_pFileName, "rb"); + FILE* fp = Fopen(a_pFileName, "rb"); if (fp == nullptr) { return false; } - FFseek(fp, 0, SEEK_END); - n64 nFileSize = FFtell(fp); + Fseek(fp, 0, SEEK_END); + n64 nFileSize = Ftell(fp); if (nFileSize < sizeof(SBflimHeader) + sizeof(SImageBlock)) { return false; } - FFseek(fp, nFileSize - (sizeof(SBflimHeader) + sizeof(SImageBlock)), SEEK_SET); + Fseek(fp, nFileSize - (sizeof(SBflimHeader) + sizeof(SImageBlock)), SEEK_SET); SBflimHeader bflimHeader; fread(&bflimHeader, sizeof(bflimHeader), 1, fp); fclose(fp); diff --git a/src/bflim.h b/src/bflim.h index f4d4db7..50214fd 100644 --- a/src/bflim.h +++ b/src/bflim.h @@ -1,14 +1,14 @@ #ifndef BFLIM_H_ #define BFLIM_H_ -#include "utility.h" +#include namespace pvrtexture { class CPVRTexture; } -#include MSC_PUSH_PACKED +#include SDW_MSC_PUSH_PACKED struct SBflimHeader { u32 Signature; @@ -18,7 +18,7 @@ struct SBflimHeader u32 FileSize; u16 DataBlocks; u16 Reserved; -} GNUC_PACKED; +} SDW_GNUC_PACKED; struct SImageBlock { @@ -30,8 +30,8 @@ struct SImageBlock u8 Format; u8 Rotate; u32 ImageSize; -} GNUC_PACKED; -#include MSC_POP_PACKED +} SDW_GNUC_PACKED; +#include SDW_MSC_POP_PACKED class CBflim { diff --git a/src/bflimtool.cpp b/src/bflimtool.cpp index 9ec621e..87b1f04 100644 --- a/src/bflimtool.cpp +++ b/src/bflimtool.cpp @@ -263,7 +263,7 @@ bool CBflimTool::encodeFile() int main(int argc, char* argv[]) { - FSetLocale(); + SetLocale(); CBflimTool tool; if (tool.ParseOptions(argc, argv) != 0) { diff --git a/src/bflimtool.h b/src/bflimtool.h index 25fab3c..80ee9eb 100644 --- a/src/bflimtool.h +++ b/src/bflimtool.h @@ -1,7 +1,7 @@ #ifndef BFLIMTOOL_H_ #define BFLIMTOOL_H_ -#include "utility.h" +#include class CBflimTool { diff --git a/src/utility.cpp b/src/utility.cpp deleted file mode 100644 index 8bd6fb6..0000000 --- a/src/utility.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "utility.h" - -#if BFLIMTOOL_COMPILER != COMPILER_MSC -string g_sLocaleName = ""; -#endif - -void FSetLocale() -{ - string sLocale = setlocale(LC_ALL, ""); -#if BFLIMTOOL_COMPILER != COMPILER_MSC - vector vLocale = FSSplit(sLocale, "."); - if (!vLocale.empty()) - { - g_sLocaleName = vLocale.back(); - } -#endif -} - -n32 FSToN32(const string& a_sString) -{ - return static_cast(strtol(a_sString.c_str(), nullptr, 10)); -} - -FILE* FFopenA(const char* a_pFileName, const char* a_pMode) -{ - FILE* fp = fopen(a_pFileName, a_pMode); - if (fp == nullptr) - { - printf("ERROR: open file %s failed\n\n", a_pFileName); - } - return fp; -} diff --git a/src/utility.h b/src/utility.h deleted file mode 100644 index aef830c..0000000 --- a/src/utility.h +++ /dev/null @@ -1,81 +0,0 @@ -#ifndef UTILITY_H_ -#define UTILITY_H_ - -#define COMPILER_MSC 1 -#define COMPILER_GNUC 2 - -#if defined(_MSC_VER) -#define BFLIMTOOL_COMPILER COMPILER_MSC -#else -#define BFLIMTOOL_COMPILER COMPILER_GNUC -#endif - -#if BFLIMTOOL_COMPILER == COMPILER_MSC -#define WIN32_LEAN_AND_MEAN -#include -#endif -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -typedef int8_t n8; -typedef int16_t n16; -typedef int32_t n32; -typedef int64_t n64; -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; - -#if BFLIMTOOL_COMPILER == COMPILER_MSC -#define FFopen FFopenA -#define FFseek _fseeki64 -#define FFtell _ftelli64 -#define MSC_PUSH_PACKED -#define MSC_POP_PACKED -#define GNUC_PACKED -#else -#define FFopen FFopenA -#define FFseek fseeko -#define FFtell ftello -#define MSC_PUSH_PACKED -#define MSC_POP_PACKED -#define GNUC_PACKED __attribute__((packed)) -#endif - -#define CONVERT_ENDIAN(n) (((n) >> 24 & 0xFF) | ((n) >> 8 & 0xFF00) | (((n) & 0xFF00) << 8) | (((n) & 0xFF) << 24)) - -void FSetLocale(); - -n32 FSToN32(const string& a_sString); - -template -vector FSSplit(const T& a_sString, const T& a_sSeparator) -{ - vector vString; - for (typename T::size_type nOffset = 0; nOffset < a_sString.size(); nOffset += a_sSeparator.size()) - { - typename T::size_type nPos = a_sString.find(a_sSeparator, nOffset); - if (nPos != T::npos) - { - vString.push_back(a_sString.substr(nOffset, nPos - nOffset)); - nOffset = nPos; - } - else - { - vString.push_back(a_sString.substr(nOffset)); - break; - } - } - return vString; -} - -FILE* FFopenA(const char* a_pFileName, const char* a_pMode); - -#endif // UTILITY_H_