#pragma once
#include <optional>
#include <string>
#include <whiteout/interfaces.h>
#include <whiteout/textures/texture.h>
namespace whiteout::textures::bcn {
constexpr bool isCompressed(PixelFormat fmt) {
return fmt == PixelFormat::BC1 || fmt == PixelFormat::BC2 || fmt == PixelFormat::BC3 ||
fmt == PixelFormat::BC4 || fmt == PixelFormat::BC5 || fmt == PixelFormat::BC6H ||
fmt == PixelFormat::BC7;
}
constexpr PixelFormat decoded_format(PixelFormat fmt) {
if (fmt == PixelFormat::BC4)
return PixelFormat::R8;
if (fmt == PixelFormat::BC5)
return PixelFormat::RG8;
if (fmt == PixelFormat::BC6H)
return PixelFormat::RGBA32F;
if (isCompressed(fmt))
return PixelFormat::RGBA8;
return fmt;
}
constexpr bool can_encode(PixelFormat source, PixelFormat target) {
if (!isCompressed(target))
return false;
if (target == PixelFormat::BC4)
return source == PixelFormat::R8;
if (target == PixelFormat::BC5)
return source == PixelFormat::RG8;
if (target == PixelFormat::BC6H)
return source == PixelFormat::RGBA32F;
return source == PixelFormat::RGBA8;
}
std::optional<Texture> encode(const Texture& src, PixelFormat target,
std::string* out_error = nullptr,
interfaces::WorkerPool* pool = nullptr);
std::optional<Texture> decode(const Texture& src, std::string* out_error = nullptr,
interfaces::WorkerPool* pool = nullptr);
}
namespace whiteout {
namespace bcn = textures::bcn;
}