Skip to content

Commit

Permalink
gust_g1t: add swizzling support for textures with more than one mipmap
Browse files Browse the repository at this point in the history
* Closes #23
  • Loading branch information
VitaSmith committed Sep 4, 2021
1 parent 5ad8905 commit d2be1f9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .vs/gust_g1t.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>ps4\cnn_battlehelp_image001.g1t</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>br_vita\PC00_Scl</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>ps4\cnn_battlehelp_image001.g1t</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>br_vita\PC00_Scl</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>ps4\cnn_battlehelp_image001.g1t</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>br_vita\PC00_Scl</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>ps4\cnn_battlehelp_image001.g1t</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>br_vita\PC00_Scl</LocalDebuggerCommandArguments>
<LocalDebuggerWorkingDirectory>$(SolutionDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
Expand Down
26 changes: 18 additions & 8 deletions gust_g1t.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,15 @@ int main_utf8(int argc, char** argv)
mo = (int16_t)log2(min(dds_header->width / wf, dds_header->height / hf));
break;
}
mortonize(bpp * wf * hf, mo, dds_header->width / wf, dds_header->height / hf,
dds_payload, dds_size);
uint32_t highest_mipmap_size = (dds_header->width * dds_header->height * bpp) / 8;
uint32_t offset = 0, morton_size = highest_mipmap_size;
for (int j = 1; j <= tex.mipmaps && mo != 0; j++) {
mortonize(bpp * wf * hf, mo, dds_header->width / wf / j, dds_header->height / hf / j,
&dds_payload[offset], morton_size);
offset += morton_size;
morton_size = highest_mipmap_size / ((j * 2) * (j * 2));
mo += (mo > 0) ? -1 : +1;
}
}
if (texture_format >= DDS_FORMAT_ABGR && texture_format <= DDS_FORMAT_RGBA)
rgba_convert(bpp, "ARGB", argb_name[texture_format], dds_payload, dds_size);
Expand Down Expand Up @@ -800,10 +807,6 @@ int main_utf8(int argc, char** argv)
fprintf(stderr, "ERROR: Unsupported texture type (0x%02X)\n", tex->type);
continue;
}
if (swizzled && tex->mipmaps != 1) {
fprintf(stderr, "ERROR: Swizzled textures with multiple mipmaps are not supported\n");
continue;
}
uint32_t highest_mipmap_size = (width * height * bpp) / 8;
uint32_t texture_size = highest_mipmap_size;
for (int j = 0; j < tex->mipmaps - 1; j++)
Expand Down Expand Up @@ -880,8 +883,8 @@ int main_utf8(int argc, char** argv)
default:
break;
}
int16_t mo; // Morton order
if (swizzled) {
int16_t mo; // Morton order
switch (hdr->platform) {
case SONY_PS4:
case NINTENDO_3DS:
Expand All @@ -892,7 +895,14 @@ int main_utf8(int argc, char** argv)
mo = -1 * (int16_t)log2(min(height / hf, width / wf));
break;
}
mortonize(bpp * wf * hf, mo, width / wf, height / hf, &buf[pos], texture_size);
uint32_t offset = 0, morton_size = highest_mipmap_size;
for (int j = 1; j <= tex->mipmaps && mo != 0; j++) {
mortonize(bpp * wf * hf, mo, width / wf / j, height / hf / j,
&buf[pos + offset], morton_size);
offset += morton_size;
morton_size = highest_mipmap_size / ((j * 2) * (j * 2));
mo += (mo > 0) ? -1 : +1;
}
}
if (flip_image || ((hdr->platform == NINTENDO_3DS) && (tex->type == 0x09 || tex->type == 0x45)))
flip(bpp, &buf[pos], texture_size, width);
Expand Down
45 changes: 33 additions & 12 deletions test_g1t.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,44 @@ setlocal EnableDelayedExpansion
call build.cmd g1t
if %ERRORLEVEL% neq 0 goto err

set list=type_01_sw type_08_ps3 type_09_ps4 type_10_psv type_12_psv type_12_psv_2^
type_21_sw type_3c_3ds type_3d_3ds type_45_3ds type_59_win type_59_win_2^
type_5b_win type_5f_win type_5f_win_2 type_60_ps4 type_62_ps4 type_62_ps4_2
set list=^
type_01_sw^
type_08_ps3^
type_09_ps4^
type_10_psv^
type_10_psv_2^
type_12_psv^
type_12_psv_2^
type_21_sw^
type_3c_3ds^
type_3d_3ds^
type_45_3ds^
type_59_win^
type_59_win_2^
type_5b_win^
type_5f_win^
type_5f_win_2^
type_60_ps4^
type_62_ps4^
type_62_ps4_2

for %%a in (%list%) do (
if exist %%a.g1t.bak move /y %%a.g1t.bak %%a.g1t >NUL 2>&1
)

for %%a in (%list%) do (
echo | set /p PrintName=* %%a.g1t...
gust_g1t.exe %%a.g1t >NUL 2>&1
if !ERRORLEVEL! neq 0 goto err
gust_g1t.exe %%a >NUL 2>&1
if !ERRORLEVEL! neq 0 goto err
fc /b %%a.g1t %%a.g1t.bak >NUL 2>&1
if !ERRORLEVEL! neq 0 goto err
echo [PASS]
echo | set /p PrintName=* %%a.g1t...
if exist %%a.g1t (
gust_g1t.exe %%a.g1t >NUL 2>&1
if !ERRORLEVEL! neq 0 goto err
gust_g1t.exe %%a >NUL 2>&1
if !ERRORLEVEL! neq 0 goto err
fc /b %%a.g1t %%a.g1t.bak >NUL 2>&1
if !ERRORLEVEL! neq 0 goto err
echo [PASS]
) else (
echo [SKIP]
)
)

echo [ALL TESTS PASSED]
Expand All @@ -35,5 +56,5 @@ echo [FAIL]

:out
for %%a in (%list%) do (
if exist %%a.g1t.bak move /y %%a.g1t.bak %%a.g1t >NUL 2>&1
if exist %%a.g1t.bak move /y %%a.g1t.bak %%a.g1t >NUL 2>&1
)

0 comments on commit d2be1f9

Please sign in to comment.