From 8416ad49d63ff6ac9f26593d6f50dc55e86ea965 Mon Sep 17 00:00:00 2001 From: Sun Daowen Date: Thu, 27 Jul 2017 13:23:17 +0800 Subject: [PATCH] fix empty argument string --- src/bflim.cpp | 102 +++++++++++++++++++++++----------------------- src/bflimtool.cpp | 4 ++ 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/bflim.cpp b/src/bflim.cpp index 9d5fecd..4909901 100644 --- a/src/bflim.cpp +++ b/src/bflim.cpp @@ -587,7 +587,6 @@ int CBflim::decode(u8* a_pBuffer, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n3 break; } PVRTextureHeaderV3 pvrTextureHeaderV3; - MetaDataBlock metaDataBlock; switch (a_nFormat) { case kTextureFormatRGBA8888: @@ -635,6 +634,7 @@ int CBflim::decode(u8* a_pBuffer, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n3 } pvrTextureHeaderV3.u32Height = nHeight; pvrTextureHeaderV3.u32Width = nWidth; + MetaDataBlock metaDataBlock; metaDataBlock.DevFOURCC = PVRTEX3_IDENT; metaDataBlock.u32Key = ePVRTMetaDataTextureOrientation; metaDataBlock.u32DataSize = 3; @@ -648,12 +648,12 @@ int CBflim::decode(u8* a_pBuffer, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n3 pvrtexture::Transcode(**a_pPVRTexture, pvrtexture::PVRStandard8PixelType, ePVRTVarTypeUnsignedByteNorm, ePVRTCSpacelRGB); if (a_nFormat == kTextureFormatETC1_A4) { - u8* data = static_cast((*a_pPVRTexture)->getDataPtr()); + u8* pData = static_cast((*a_pPVRTexture)->getDataPtr()); for (n32 i = 0; i < nHeight; i++) { for (n32 j = 0; j < nWidth; j++) { - data[(i * nWidth + j) * 4 + 3] = pAlpha[i * nWidth + j]; + pData[(i * nWidth + j) * 4 + 3] = pAlpha[i * nWidth + j]; } } delete[] pAlpha; @@ -805,8 +805,8 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 *a_pBuffer = new u8[nTotalSize]; for (n32 l = 0; l < a_nMipmapLevel; l++) { - n32 mipmapWidth = nWidth >> l; - n32 mipmapHeight = nHeight >> l; + n32 nMipmapWidth = nWidth >> l; + n32 nMipmapHeight = nHeight >> l; u8* pRGBA = static_cast(pPVRTexture->getDataPtr(l)); u8* pAlpha = nullptr; if (a_nFormat == kTextureFormatETC1_A4) @@ -817,19 +817,19 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 { case kTextureFormatRGBA8888: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight * 4]; - for (n32 i = 0; i < mipmapHeight; i++) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight * 4]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { for (n32 k = 0; k < 4; k++) { - pTemp[(((i / 8) * (mipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 4 + k] = pRGBA[(i * mipmapWidth + j) * 4 + k]; + pTemp[(((i / 8) * (nMipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 4 + k] = pRGBA[(i * nMipmapWidth + j) * 4 + k]; } } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 64; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 64; i++) { for (n32 j = 0; j < 64; j++) { @@ -844,19 +844,19 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 break; case kTextureFormatRGB888: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight * 3]; - for (n32 i = 0; i < mipmapHeight; i++) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight * 3]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { for (n32 k = 0; k < 3; k++) { - pTemp[(((i / 8) * (mipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 3 + k] = pRGBA[(i * mipmapWidth + j) * 3 + k]; + pTemp[(((i / 8) * (nMipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 3 + k] = pRGBA[(i * nMipmapWidth + j) * 3 + k]; } } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 64; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 64; i++) { for (n32 j = 0; j < 64; j++) { @@ -873,19 +873,19 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 case kTextureFormatRGB565: case kTextureFormatRGBA4444: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight * 2]; - for (n32 i = 0; i < mipmapHeight; i++) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight * 2]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { for (n32 k = 0; k < 2; k++) { - pTemp[(((i / 8) * (mipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 2 + k] = pRGBA[(i * mipmapWidth + j) * 2 + k]; + pTemp[(((i / 8) * (nMipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 2 + k] = pRGBA[(i * nMipmapWidth + j) * 2 + k]; } } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 64; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 64; i++) { for (n32 j = 0; j < 64; j++) { @@ -901,19 +901,19 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 case kTextureFormatLA88: case kTextureFormatHL8: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight * 2]; - for (n32 i = 0; i < mipmapHeight; i++) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight * 2]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { for (n32 k = 0; k < 2; k++) { - pTemp[(((i / 8) * (mipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 2 + k] = pRGBA[(i * mipmapWidth + j) * 2 + k]; + pTemp[(((i / 8) * (nMipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8) * 2 + k] = pRGBA[(i * nMipmapWidth + j) * 2 + k]; } } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 64; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 64; i++) { for (n32 j = 0; j < 64; j++) { @@ -930,16 +930,16 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 case kTextureFormatA8: case kTextureFormatLA44: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight]; - for (n32 i = 0; i < mipmapHeight; i++) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { - pTemp[((i / 8) * (mipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8] = pRGBA[i * mipmapWidth + j]; + pTemp[((i / 8) * (nMipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8] = pRGBA[i * nMipmapWidth + j]; } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 64; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 64; i++) { for (n32 j = 0; j < 64; j++) { @@ -952,16 +952,16 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 case kTextureFormatL4: case kTextureFormatA4: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight]; - for (n32 i = 0; i < mipmapHeight; i++) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { - pTemp[((i / 8) * (mipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8] = pRGBA[i * mipmapWidth + j]; + pTemp[((i / 8) * (nMipmapWidth / 8) + j / 8) * 64 + i % 8 * 8 + j % 8] = pRGBA[i * nMipmapWidth + j]; } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 64; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 64; i++) { for (n32 j = 0; j < 64; j += 2) { @@ -973,16 +973,16 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 break; case kTextureFormatETC1: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight / 2]; - for (n32 i = 0; i < mipmapHeight; i += 4) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight / 2]; + for (n32 i = 0; i < nMipmapHeight; i += 4) { - for (n32 j = 0; j < mipmapWidth; j += 4) + for (n32 j = 0; j < nMipmapWidth; j += 4) { - memcpy(pTemp + (((i / 8) * (mipmapWidth / 8) + j / 8) * 4 + (i % 8 / 4 * 2 + j % 8 / 4)) * 8, pRGBA + ((i / 4) * (mipmapWidth / 4) + j / 4) * 8, 8); + memcpy(pTemp + (((i / 8) * (nMipmapWidth / 8) + j / 8) * 4 + (i % 8 / 4 * 2 + j % 8 / 4)) * 8, pRGBA + ((i / 4) * (nMipmapWidth / 4) + j / 4) * 8, 8); } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 2 / 8; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 2 / 8; i++) { for (n32 j = 0; j < 8; j++) { @@ -994,16 +994,16 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 break; case kTextureFormatETC1_A4: { - u8* pTemp = new u8[mipmapWidth * mipmapHeight / 2]; - for (n32 i = 0; i < mipmapHeight; i += 4) + u8* pTemp = new u8[nMipmapWidth * nMipmapHeight / 2]; + for (n32 i = 0; i < nMipmapHeight; i += 4) { - for (n32 j = 0; j < mipmapWidth; j += 4) + for (n32 j = 0; j < nMipmapWidth; j += 4) { - memcpy(pTemp + (((i / 8) * (mipmapWidth / 8) + j / 8) * 4 + (i % 8 / 4 * 2 + j % 8 / 4)) * 8, pRGBA + ((i / 4) * (mipmapWidth / 4) + j / 4) * 8, 8); + memcpy(pTemp + (((i / 8) * (nMipmapWidth / 8) + j / 8) * 4 + (i % 8 / 4 * 2 + j % 8 / 4)) * 8, pRGBA + ((i / 4) * (nMipmapWidth / 4) + j / 4) * 8, 8); } } u8* pMipmapBuffer = *a_pBuffer + nCurrentSize; - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 2 / 8; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 2 / 8; i++) { for (n32 j = 0; j < 8; j++) { @@ -1011,15 +1011,15 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 } } delete[] pTemp; - pTemp = new u8[mipmapWidth * mipmapHeight]; - for (n32 i = 0; i < mipmapHeight; i++) + pTemp = new u8[nMipmapWidth * nMipmapHeight]; + for (n32 i = 0; i < nMipmapHeight; i++) { - for (n32 j = 0; j < mipmapWidth; j++) + for (n32 j = 0; j < nMipmapWidth; j++) { - pTemp[(((i / 8) * (mipmapWidth / 8) + j / 8) * 4 + i % 8 / 4 * 2 + j % 8 / 4) * 16 + i % 4 * 4 + j % 4] = pAlpha[i * mipmapWidth + j]; + pTemp[(((i / 8) * (nMipmapWidth / 8) + j / 8) * 4 + i % 8 / 4 * 2 + j % 8 / 4) * 16 + i % 4 * 4 + j % 4] = pAlpha[i * nMipmapWidth + j]; } } - for (n32 i = 0; i < mipmapWidth * mipmapHeight / 16; i++) + for (n32 i = 0; i < nMipmapWidth * nMipmapHeight / 16; i++) { for (n32 j = 0; j < 4; j++) { @@ -1031,7 +1031,7 @@ void CBflim::encode(u8* a_pData, n32 a_nWidth, n32 a_nHeight, n32 a_nFormat, n32 } break; } - nCurrentSize += mipmapWidth * mipmapHeight * a_nBPP / 8; + nCurrentSize += nMipmapWidth * nMipmapHeight * a_nBPP / 8; } delete pPVRTexture; if (a_nFormat == kTextureFormatETC1_A4) diff --git a/src/bflimtool.cpp b/src/bflimtool.cpp index 13682c6..9ec621e 100644 --- a/src/bflimtool.cpp +++ b/src/bflimtool.cpp @@ -33,6 +33,10 @@ int CBflimTool::ParseOptions(int a_nArgc, char* a_pArgv[]) for (int i = 1; i < a_nArgc; i++) { int nArgpc = static_cast(strlen(a_pArgv[i])); + if (nArgpc == 0) + { + continue; + } int nIndex = i; if (a_pArgv[i][0] != '-') {