efficiency improvements and CMake WIN32 flags

This commit is contained in:
Syping 2021-10-24 05:03:14 +02:00
parent b5b96a841c
commit 1d48cd0fbd
5 changed files with 11 additions and 11 deletions

View File

@ -43,7 +43,7 @@ else()
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto) pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
endif() endif()
add_executable(ragephoto-gtkviewer ${GTKVIEWER_HEADERS} ${GTKVIEWER_SOURCES}) add_executable(ragephoto-gtkviewer WIN32 ${GTKVIEWER_HEADERS} ${GTKVIEWER_SOURCES})
target_compile_options(ragephoto-gtkviewer PRIVATE ${GTKMM_CFLAGS} ${RAGEPHOTO_CFLAGS}) target_compile_options(ragephoto-gtkviewer PRIVATE ${GTKMM_CFLAGS} ${RAGEPHOTO_CFLAGS})
target_link_libraries(ragephoto-gtkviewer PRIVATE ${GTKMM_LIBRARIES} ${RAGEPHOTO_LIBRARIES}) target_link_libraries(ragephoto-gtkviewer PRIVATE ${GTKMM_LIBRARIES} ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0") if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")

View File

@ -44,7 +44,7 @@ else()
pkg_check_modules(RAGEPHOTO REQUIRED ragephoto) pkg_check_modules(RAGEPHOTO REQUIRED ragephoto)
endif() endif()
add_executable(ragephoto-qtviewer ${QTVIEWER_SOURCES}) add_executable(ragephoto-qtviewer WIN32 ${QTVIEWER_SOURCES})
target_compile_options(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_CFLAGS}) target_compile_options(ragephoto-qtviewer PRIVATE ${RAGEPHOTO_CFLAGS})
target_link_libraries(ragephoto-qtviewer PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${RAGEPHOTO_LIBRARIES}) target_link_libraries(ragephoto-qtviewer PRIVATE Qt${QT_VERSION_MAJOR}::Widgets ${RAGEPHOTO_LIBRARIES})
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0") if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.13.0")

View File

@ -95,7 +95,7 @@ bool RagePhoto::load(const char *data, size_t length)
} }
#ifdef CODECVT_COMPATIBLE #ifdef CODECVT_COMPATIBLE
std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>,char16_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
p_photoString = convert.to_bytes(reinterpret_cast<char16_t*>(photoHeader)); p_photoString = convert.to_bytes(reinterpret_cast<char16_t*>(photoHeader));
#elif defined ICONV_COMPATIBLE #elif defined ICONV_COMPATIBLE
iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE"); iconv_t iconv_in = iconv_open("UTF-8", "UTF-16LE");
@ -444,7 +444,7 @@ bool RagePhoto::save(char *data, PhotoFormat photoFormat)
if (photoFormat == PhotoFormat::GTA5 || photoFormat == PhotoFormat::RDR2) { if (photoFormat == PhotoFormat::GTA5 || photoFormat == PhotoFormat::RDR2) {
#if defined CODECVT_COMPATIBLE || defined ICONV_COMPATIBLE #if defined CODECVT_COMPATIBLE || defined ICONV_COMPATIBLE
#ifdef CODECVT_COMPATIBLE #ifdef CODECVT_COMPATIBLE
std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>,char16_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
std::u16string photoString = convert.from_bytes(p_photoString); std::u16string photoString = convert.from_bytes(p_photoString);
const size_t photoHeader_size = photoString.size() * 2; const size_t photoHeader_size = photoString.size() * 2;
if (photoHeader_size > 256) { if (photoHeader_size > 256) {
@ -796,7 +796,7 @@ void RagePhoto::moveOffsets()
p_endOfFile = p_descOffset + p_descBuffer + 12; p_endOfFile = p_descOffset + p_descBuffer + 12;
} }
size_t RagePhoto::readBuffer(const char *input, char *output, size_t *pos, size_t len, size_t inputLen) size_t RagePhoto::readBuffer(const char *input, void *output, size_t *pos, size_t len, size_t inputLen)
{ {
size_t readLen = 0; size_t readLen = 0;
if (*pos >= inputLen) if (*pos >= inputLen)
@ -804,12 +804,12 @@ size_t RagePhoto::readBuffer(const char *input, char *output, size_t *pos, size_
readLen = inputLen - *pos; readLen = inputLen - *pos;
if (readLen > len) if (readLen > len)
readLen = len; readLen = len;
memcpy(output, &input[*pos], readLen); memcpy(output, reinterpret_cast<const void*>(&input[*pos]), readLen);
*pos = *pos + readLen; *pos = *pos + readLen;
return readLen; return readLen;
} }
size_t RagePhoto::writeBuffer(const char *input, char *output, size_t *pos, size_t len, size_t inputLen) size_t RagePhoto::writeBuffer(const void *input, char *output, size_t *pos, size_t len, size_t inputLen)
{ {
const size_t maxLen = len - *pos; const size_t maxLen = len - *pos;
size_t writeLen = inputLen; size_t writeLen = inputLen;
@ -817,7 +817,7 @@ size_t RagePhoto::writeBuffer(const char *input, char *output, size_t *pos, size
return 0; return 0;
if (inputLen > maxLen) if (inputLen > maxLen)
writeLen = maxLen; writeLen = maxLen;
memcpy(&output[*pos], input, writeLen); memcpy(reinterpret_cast<void*>(&output[*pos]), input, writeLen);
*pos = *pos + writeLen; *pos = *pos + writeLen;
return writeLen; return writeLen;
} }

View File

@ -147,8 +147,8 @@ public:
protected: protected:
inline void moveOffsets(); inline void moveOffsets();
inline size_t readBuffer(const char *input, char *output, size_t *pos, size_t len, size_t inputLen); inline size_t readBuffer(const char *input, void *output, size_t *pos, size_t len, size_t inputLen);
inline size_t writeBuffer(const char *input, char *output, size_t *pos, size_t len, size_t inputLen); inline size_t writeBuffer(const void *input, char *output, size_t *pos, size_t len, size_t inputLen);
inline uint32_t charToUInt32LE(char *x); inline uint32_t charToUInt32LE(char *x);
inline void uInt32ToCharLE(uint32_t x, char *y); inline void uInt32ToCharLE(uint32_t x, char *y);
bool p_photoLoaded; bool p_photoLoaded;

View File

@ -57,7 +57,7 @@ int main(int argc, char *argv[])
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
std::wstring_convert<std::codecvt_utf8_utf16<char16_t, 0x10ffff, std::little_endian>,char16_t> convert; std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
std::string photoString = convert.to_bytes(reinterpret_cast<char16_t*>(photoHeader)); std::string photoString = convert.to_bytes(reinterpret_cast<char16_t*>(photoHeader));
return strcmp(photoString.c_str(), "PHOTO - 02/01/17 08:42:44"); return strcmp(photoString.c_str(), "PHOTO - 02/01/17 08:42:44");
} }