Skip to content

Commit

Permalink
fix empty argument string
Browse files Browse the repository at this point in the history
  • Loading branch information
dnasdw committed Jul 27, 2017
1 parent 1d5d830 commit 8416ad4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 51 deletions.
102 changes: 51 additions & 51 deletions src/bflim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand All @@ -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<u8*>((*a_pPVRTexture)->getDataPtr());
u8* pData = static_cast<u8*>((*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;
Expand Down Expand Up @@ -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<u8*>(pPVRTexture->getDataPtr(l));
u8* pAlpha = nullptr;
if (a_nFormat == kTextureFormatETC1_A4)
Expand All @@ -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++)
{
Expand All @@ -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++)
{
Expand All @@ -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++)
{
Expand All @@ -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++)
{
Expand All @@ -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++)
{
Expand All @@ -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)
{
Expand All @@ -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++)
{
Expand All @@ -994,32 +994,32 @@ 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++)
{
pMipmapBuffer[8 + i * 16 + 7 - j] = pTemp[i * 8 + j];
}
}
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++)
{
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/bflimtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(strlen(a_pArgv[i]));
if (nArgpc == 0)
{
continue;
}
int nIndex = i;
if (a_pArgv[i][0] != '-')
{
Expand Down

0 comments on commit 8416ad4

Please sign in to comment.