Skip to content

Commit

Permalink
PVR3 meta-data orientation loading. The new preferences option is ena…
Browse files Browse the repository at this point in the history
…bled by default. Updated test suite images for PVR3. Now includes BC test images and images with orientation meta-data set (horizont and vertical).
  • Loading branch information
bluescan committed Dec 30, 2023
1 parent ad71b80 commit c487074
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ void Config::ProfileData::Reset(Viewer::Profile profile, uint32 categories)
MaxUndoSteps = 16;
StrictLoading = false;
ExifOrientLoading = true;
PVR3OrientLoading = true;
DetectAPNGInsidePNG = true;
MipmapFilter = int(tImage::tResampleFilter::Bilinear);
MipmapChaining = true;
Expand Down Expand Up @@ -571,6 +572,7 @@ void Config::ProfileData::Load(tExpression expr)
ReadItem(MaxUndoSteps);
ReadItem(StrictLoading);
ReadItem(ExifOrientLoading);
ReadItem(PVR3OrientLoading);
ReadItem(DetectAPNGInsidePNG);
ReadItem(MipmapFilter);
ReadItem(MipmapChaining);
Expand Down Expand Up @@ -750,6 +752,7 @@ bool Config::ProfileData::Save(tExprWriter& writer) const
WriteItem(MaxUndoSteps);
WriteItem(StrictLoading);
WriteItem(ExifOrientLoading);
WriteItem(PVR3OrientLoading);
WriteItem(DetectAPNGInsidePNG);
WriteItem(MipmapFilter);
WriteItem(MipmapChaining);
Expand Down
1 change: 1 addition & 0 deletions Src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ struct ProfileData
int MaxUndoSteps;
bool StrictLoading; // No attempt to display ill-formed images.
bool ExifOrientLoading; // Reorient images on load if Exif meta-data contains camera orientation information.
bool PVR3OrientLoading; // Reorient images on load if PVR3 meta-data contains orientation information.
bool DetectAPNGInsidePNG; // Look for APNG data (animated) hidden inside a regular PNG file.
int MipmapFilter; // Matches tImage::tResampleFilter. Use None for no mipmaps.
bool MipmapChaining; // True for faster mipmap generation. False for a lot slower and slightly better results.
Expand Down
25 changes: 18 additions & 7 deletions Src/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ bool Image::Load(bool loadParamsFromConfig)
tImageJPG::LoadParams params = LoadParams_JPG;
if (loadParamsFromConfig)
{
params.Reset();
params.Flags =
(profile.StrictLoading ? tImageJPG::LoadFlag_Strict : 0) |
(profile.ExifOrientLoading ? tImageJPG::LoadFlag_ExifOrient : 0);
if (profile.StrictLoading && !(params.Flags & tImageJPG::LoadFlag_Strict))
params.Flags |= tImageJPG::LoadFlag_Strict;
else if (!profile.StrictLoading && (params.Flags & tImageJPG::LoadFlag_Strict))
params.Flags &= ~tImageJPG::LoadFlag_Strict;

if (profile.ExifOrientLoading && !(params.Flags & tImageJPG::LoadFlag_ExifOrient))
params.Flags |= tImageJPG::LoadFlag_ExifOrient;
else if (!profile.ExifOrientLoading && (params.Flags & tImageJPG::LoadFlag_ExifOrient))
params.Flags &= ~tImageJPG::LoadFlag_ExifOrient;
}

bool ok = jpg.Load(Filename, params);
Expand All @@ -349,9 +354,10 @@ bool Image::Load(bool loadParamsFromConfig)
tImagePNG::LoadParams params = LoadParams_PNG;
if (loadParamsFromConfig)
{
params.Reset();
params.Flags =
(!profile.StrictLoading ? tImagePNG::LoadFlag_AllowJPG : 0);
if (profile.StrictLoading && !(params.Flags & tImagePNG::LoadFlag_AllowJPG))
params.Flags |= tImagePNG::LoadFlag_AllowJPG;
else if (!profile.StrictLoading && (params.Flags & tImagePNG::LoadFlag_AllowJPG))
params.Flags &= ~tImagePNG::LoadFlag_AllowJPG;
}

bool ok = png.Load(Filename, params);
Expand Down Expand Up @@ -489,6 +495,11 @@ bool Image::Load(bool loadParamsFromConfig)
params.Flags |= tImagePVR::LoadFlag_StrictLoading;
else if (!profile.StrictLoading && (params.Flags & tImagePVR::LoadFlag_StrictLoading))
params.Flags &= ~tImagePVR::LoadFlag_StrictLoading;

if (profile.PVR3OrientLoading && !(params.Flags & tImagePVR::LoadFlag_MetaDataOrient))
params.Flags |= tImagePVR::LoadFlag_MetaDataOrient;
else if (!profile.PVR3OrientLoading && (params.Flags & tImagePVR::LoadFlag_MetaDataOrient))
params.Flags &= ~tImagePVR::LoadFlag_MetaDataOrient;
}

tImagePVR pvr;
Expand Down
12 changes: 11 additions & 1 deletion Src/Preferences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,17 @@ void Viewer::ShowPreferencesWindow(bool* popen)
CurrImage->Load();
}
ImGui::SameLine();
ShowHelpMark("If Exif meta-data contains camera orientation information this will take it into account\nwhen loading and display the image the correctly oriented/flipped. Mostly affects jpg files.");
ShowHelpMark("If Exif meta-data contains camera orientation information this will take it into account\nwhen loading and displaying the image correctly oriented/flipped. Mostly affects jpg files.");

if (ImGui::Checkbox("PVR3 Orient Loading", &profile.PVR3OrientLoading))
{
// This is not efficient but forces changes to the orient loading to be displayed correctly live.
for (Image* i = Images.First(); i; i = i->Next())
i->Unload(true);
CurrImage->Load();
}
ImGui::SameLine();
ShowHelpMark("If PVR3 meta-data contains orientation information this will take it into account\nwhen loading and displaying the image correctly flipped. Affects pvr files.");

ImGui::Checkbox("Detect APNG Inside PNG", &profile.DetectAPNGInsidePNG); ImGui::SameLine();
ShowHelpMark("Some png image files are really apng files. If detecton is true these png files will be displayed animated.");
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added TestImages/PVR_V3/BC1DXT1_UNORM_SRGB_RGBA_T.pvr
Binary file not shown.
Binary file added TestImages/PVR_V3/BC1DXT1_UNORM_SRGB_RGB_TM.pvr
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added TestImages/PVR_V3/BC4ATI1S_SNORM_LIN_R_T.pvr
Binary file not shown.
Binary file added TestImages/PVR_V3/BC4ATI1U_UNORM_LIN_R_T.pvr
Binary file not shown.
Binary file added TestImages/PVR_V3/BC5ATI2S_SNORM_LIN_RG_T.pvr
Binary file not shown.
Binary file added TestImages/PVR_V3/BC5ATI2U_UNORM_LIN_RG_T.pvr
Binary file not shown.

0 comments on commit c487074

Please sign in to comment.