diff --git a/EtcTool/EtcSourceImage.cpp b/EtcTool/EtcSourceImage.cpp index fcb1ac0..954fb0d 100644 --- a/EtcTool/EtcSourceImage.cpp +++ b/EtcTool/EtcSourceImage.cpp @@ -286,6 +286,26 @@ namespace Etc } + // ---------------------------------------------------------------------------------------------------- + // Flip the image in Y + void SourceImage::FlipY(void) + { + const size_t rowSizeBytes = sizeof(ColorFloatRGBA) * m_uiWidth; + char *pacRow = new char[rowSizeBytes]; + assert(pacRow); + + for (int iY = 0; iY < m_uiHeight / 2; ++iY) + { + ColorFloatRGBA *row1 = m_pafrgbaPixels + m_uiWidth * iY; + ColorFloatRGBA *row2 = m_pafrgbaPixels + m_uiWidth * (m_uiHeight - 1 - iY); + memcpy(pacRow, row1, rowSizeBytes); + memcpy(row1, row2, rowSizeBytes); + memcpy(row2, pacRow, rowSizeBytes); + } + + delete [] pacRow; + } + // ---------------------------------------------------------------------------------------------------- // diff --git a/EtcTool/EtcSourceImage.h b/EtcTool/EtcSourceImage.h index 0e57e6e..8306d38 100644 --- a/EtcTool/EtcSourceImage.h +++ b/EtcTool/EtcSourceImage.h @@ -36,6 +36,7 @@ namespace Etc void SetName(const char *a_pstrFilename); void NormalizeXYZ(void); + void FlipY(void); inline const char *GetFilename(void) { diff --git a/EtcTool/EtcTool.cpp b/EtcTool/EtcTool.cpp index 1b52778..e2b1ab7 100644 --- a/EtcTool/EtcTool.cpp +++ b/EtcTool/EtcTool.cpp @@ -90,6 +90,7 @@ class Commands i_vPixel = -1; verboseOutput = false; boolNormalizeXYZ = false; + boolFlipY = false; mipmaps = 1; mipFilterFlags = Etc::FILTER_WRAP_NONE; } @@ -114,6 +115,7 @@ class Commands int i_hPixel; int i_vPixel; bool boolNormalizeXYZ; + bool boolFlipY; int mipmaps; unsigned int mipFilterFlags; }; @@ -152,6 +154,10 @@ int main(int argc, const char * argv[]) { sourceimage.NormalizeXYZ(); } + if (commands.boolFlipY) + { + sourceimage.FlipY(); + } unsigned int uiSourceWidth = sourceimage.GetWidth(); unsigned int uiSourceHeight = sourceimage.GetHeight(); @@ -628,6 +634,11 @@ bool Commands::ProcessCommandLineArguments(int a_iArgs, const char *a_apstrArgs[ { boolNormalizeXYZ = true; } + else if (strcmp(a_apstrArgs[iArg], "-flipy") == 0 || + strcmp(a_apstrArgs[iArg], "-flipY") == 0) + { + boolFlipY = true; + } else if (strcmp(a_apstrArgs[iArg], "-output") == 0) { ++iArg; @@ -800,6 +811,7 @@ void Commands::PrintUsageMessage(void) printf(" -help prints this message\n"); printf(" -jobs or -j specifies the number of threads (default=1)\n"); printf(" -normalizexyz normalize RGB to have a length of 1\n"); + printf(" -flipy flip the image vertically\n"); printf(" -verbose or -v shows status information during the encoding\n"); printf(" process\n"); printf(" -mipmaps or -m sets the maximum number of mipaps to generate (default=1)\n");