/* Copyright (C) 1996-1997 Id Software, Inc. Copyright (C) 2017 Eric Wasylishen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA See file, 'COPYING', for details. */ #pragma once #include #include #include #include namespace img { enum class ext { TGA, WAL, MIP }; extern std::vector palette; // Palette void init_palette(const gamedef_t *game); struct texture_meta { std::string name; uint32_t width = 0, height = 0; // extension that we pulled the pixels in from. std::optional extension; // Q2/WAL only surfflags_t flags{}; contentflags_t contents{}; int32_t value = 0; std::string animation; }; struct texture { texture_meta meta{}; // in the case of replacement textures, these may not // the width/height of the metadata. uint32_t width = 0, height = 0; std::vector pixels; // the scale required to map a pixel from the // meta data onto the real size (16x16 onto 32x32 -> 2) float width_scale = 1, height_scale = 1; // This member is only set before insertion into the table // and not calculated by individual load functions. qvec3b averageColor{0}; }; extern std::unordered_map textures; qvec3b calculate_average(const std::vector &pixels); const texture *find(const std::string_view &str); // Load wal std::optional load_wal( const std::string_view &name, const fs::data &file, bool meta_only, const gamedef_t *game); // Load TGA std::optional load_tga( const std::string_view &name, const fs::data &file, bool meta_only, const gamedef_t *game); // Load Quake/Half Life mip (raw data) std::optional load_mip( const std::string_view &name, const fs::data &file, bool meta_only, const gamedef_t *game); // list of supported extensions and their loaders constexpr struct { const char *suffix; ext id; decltype(load_wal) *loader; } extension_list[] = { {".tga", ext::TGA, load_tga}, {".wal", ext::WAL, load_wal}, {".mip", ext::MIP, load_mip}, {"", ext::MIP, load_mip}}; // Attempt to load a texture from the specified name. std::tuple, fs::resolve_result, fs::data> load_texture( const std::string_view &name, bool meta_only, const gamedef_t *game, const settings::common_settings &options); enum class meta_ext { WAL, WAL_JSON }; // Load wal inline std::optional load_wal_meta( const std::string_view &name, const fs::data &file, const gamedef_t *game) { if (auto tex = load_wal(name, file, true, game)) { return tex->meta; } return std::nullopt; } std::optional load_wal_json_meta( const std::string_view &name, const fs::data &file, const gamedef_t *game); // list of supported meta extensions and their loaders constexpr struct { const char *suffix; meta_ext id; decltype(load_wal_meta) *loader; } meta_extension_list[] = { {".wal", meta_ext::WAL, load_wal_meta}, {".wal_json", meta_ext::WAL_JSON, load_wal_json_meta}}; // Attempt to load a texture meta from the specified name. std::tuple, fs::resolve_result, fs::data> load_texture_meta( const std::string_view &name, const gamedef_t *game, const settings::common_settings &options); }; // namespace img