mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-07-26 18:00:38 +00:00
chore: use templating for image dumper
This commit is contained in:
@@ -1,106 +0,0 @@
|
||||
#include "ImageDumperIW5.h"
|
||||
|
||||
#include "Image/DdsWriter.h"
|
||||
#include "Image/Dx9TextureLoader.h"
|
||||
#include "Image/ImageCommon.h"
|
||||
#include "Image/IwiLoader.h"
|
||||
#include "Image/IwiWriter8.h"
|
||||
#include "ObjWriting.h"
|
||||
#include "Utils/Logging/Log.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <format>
|
||||
|
||||
using namespace IW5;
|
||||
using namespace image;
|
||||
|
||||
namespace
|
||||
{
|
||||
std::unique_ptr<Texture> LoadImageFromLoadDef(const GfxImage& image)
|
||||
{
|
||||
Dx9TextureLoader textureLoader;
|
||||
|
||||
const auto& loadDef = *image.texture.loadDef;
|
||||
|
||||
textureLoader.Width(image.width).Height(image.height).Depth(image.depth);
|
||||
|
||||
if ((loadDef.flags & image::iwi8::IMG_FLAG_MAPTYPE_MASK) == image::iwi8::IMG_FLAG_MAPTYPE_3D)
|
||||
textureLoader.Type(TextureType::T_3D);
|
||||
else if ((loadDef.flags & image::iwi8::IMG_FLAG_MAPTYPE_MASK) == image::iwi8::IMG_FLAG_MAPTYPE_CUBE)
|
||||
textureLoader.Type(TextureType::T_CUBE);
|
||||
else
|
||||
textureLoader.Type(TextureType::T_2D);
|
||||
|
||||
textureLoader.Format(static_cast<oat::D3DFORMAT>(loadDef.format));
|
||||
textureLoader.HasMipMaps(!(loadDef.flags & image::iwi8::IMG_FLAG_NOMIPMAPS));
|
||||
return textureLoader.LoadTexture(loadDef.data);
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageFromIwi(const GfxImage& image, ISearchPath& searchPath)
|
||||
{
|
||||
const auto imageFileName = image::GetFileNameForAsset(image.name, ".iwi");
|
||||
const auto filePathImage = searchPath.Open(imageFileName);
|
||||
if (!filePathImage.IsOpen())
|
||||
{
|
||||
con::error("Could not find data for image \"{}\"", image.name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto loadResult = image::LoadIwi(*filePathImage.m_stream);
|
||||
return loadResult ? std::move(loadResult->m_texture) : nullptr;
|
||||
}
|
||||
|
||||
std::unique_ptr<Texture> LoadImageData(ISearchPath& searchPath, const GfxImage& image)
|
||||
{
|
||||
if (image.texture.loadDef && image.texture.loadDef->resourceSize > 0)
|
||||
return LoadImageFromLoadDef(image);
|
||||
|
||||
return LoadImageFromIwi(image, searchPath);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace image
|
||||
{
|
||||
DumperIW5::DumperIW5()
|
||||
{
|
||||
switch (ObjWriting::Configuration.ImageOutputFormat)
|
||||
{
|
||||
case ImageOutputFormat_e::DDS:
|
||||
m_writer = std::make_unique<DdsWriter>();
|
||||
break;
|
||||
case ImageOutputFormat_e::IWI:
|
||||
m_writer = std::make_unique<iwi8::IwiWriter>();
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
m_writer = nullptr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DumperIW5::DumpAsset(AssetDumpingContext& context, const XAssetInfo<AssetImage::Type>& asset)
|
||||
{
|
||||
const auto* image = asset.Asset();
|
||||
const auto texture = LoadImageData(context.m_obj_search_path, *image);
|
||||
if (!texture)
|
||||
return;
|
||||
|
||||
if (!m_writer->SupportsImageFormat(texture->GetFormat()))
|
||||
{
|
||||
con::warn("Not dumping image {} as {} does not support the image format {}",
|
||||
image->name,
|
||||
GetImageOutputFormatName(ObjWriting::Configuration.ImageOutputFormat),
|
||||
GetImageFormatName(texture->GetFormat()->GetId()));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto assetFile = context.OpenAssetFile(GetFileNameForAsset(asset.m_name, m_writer->GetFileExtension()));
|
||||
|
||||
if (!assetFile)
|
||||
return;
|
||||
|
||||
auto& stream = *assetFile;
|
||||
m_writer->DumpImage(stream, texture.get());
|
||||
}
|
||||
} // namespace image
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dumping/AbstractAssetDumper.h"
|
||||
#include "Game/IW5/IW5.h"
|
||||
#include "Image/ImageWriter.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace image
|
||||
{
|
||||
class DumperIW5 final : public AbstractAssetDumper<IW5::AssetImage>
|
||||
{
|
||||
public:
|
||||
DumperIW5();
|
||||
|
||||
protected:
|
||||
void DumpAsset(AssetDumpingContext& context, const XAssetInfo<IW5::AssetImage::Type>& asset) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ImageWriter> m_writer;
|
||||
};
|
||||
} // namespace image
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "ObjWriterIW5.h"
|
||||
|
||||
#include "Game/IW5/Image/ImageDumperIW5.h"
|
||||
#include "Game/IW5/Material/MaterialJsonDumperIW5.h"
|
||||
#include "Game/IW5/Techset/PixelShaderDumperIW5.h"
|
||||
#include "Game/IW5/Techset/TechsetDumperIW5.h"
|
||||
#include "Game/IW5/Techset/VertexShaderDumperIW5.h"
|
||||
#include "Game/IW5/XModel/XModelDumperIW5.h"
|
||||
#include "Image/ImageDumperIW5.h"
|
||||
#include "Leaderboard/LeaderboardJsonDumperIW5.h"
|
||||
#include "LightDef/LightDefDumperIW5.h"
|
||||
#include "Localize/LocalizeDumperIW5.h"
|
||||
|
||||
Reference in New Issue
Block a user