| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears 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.
- */
- #pragma once
- #include "common/TypeDefine.h"
- #include "common/File.h"
- class TexFile{
- public:
- /**
- * Constructor.
- *
- * @param[in,out] file File with the tex data. The file data will not be modified, but it's
- * offset will.
- */
- TexFile(File file);
- /**
- * Constructor.
- *
- * @param[in] path Path to the tex file.
- */
- TexFile(std::string path);
- /**
- * Destructor.
- */
- ~TexFile();
- /**
- * Saves a fragment of the TEX file as a PNG file.
- *
- * @param[in] file_name Full path of the destination file.
- * @param[in] x X coordinate of the image to extract from the TEX file.
- * @param[in] y Y coordinate of the image to extract from the TEX file.
- * @param[in] w Width of the image to extract from the TEX file.
- * @param[in] h Height of the image to extract from the TEX file.
- * @param[in] palette Index of the color palette to use. For non paletted files it's
- * ignored.
- */
- void SavePng(
- std::string file_name, unsigned int x, unsigned int y, unsigned int w, unsigned int h,
- unsigned int palette = 0
- );
- /**
- * Saves the TEX file as a PNG file.
- *
- * @param[in] file_name Full path of the destination file.
- * @param[in] palette Index of the color palette to use. For non paletted files it's
- * ignored.
- */
- void SavePng(std::string file_name, unsigned int palette = 0);
- /**
- * Saves two fragments of the TEX file as a single PNG image.
- *
- * The second fragment will be at the right of the first one. They must have the same
- * height.
- *
- * @param[in] file_name Full path of the destination file.
- * @param[in] x1 X coordinate of the first image to extract from the TEX file.
- * @param[in] x2 X coordinate of the second image to extract from the TEX file.
- * @param[in] y1 Y coordinate of the first image to extract from the TEX file.
- * @param[in] y2 Y coordinate of the first image to extract from the TEX file.
- * @param[in] w1 Width of the first image to extract from the TEX file.
- * @param[in] w2 Width of the second image to extract from the TEX file.
- * @param[in] h Height of the images to extract from the TEX file.
- * @param[in] palette Index of the color palette to use. For non paletted files it's
- * ignored.
- */
- void SavePng(
- std::string file_name, unsigned int x1, unsigned int x2, unsigned int y1, unsigned int y2,
- unsigned int w1, unsigned int w2, unsigned int h, unsigned int palette = 0
- );
- private:
- /**
- * Reads data from a file.
- *
- * Called from constructors.
- *
- * @param[in] file The file to read from.
- */
- void Read(File file);
- /**
- * File format version. Always 1. 4 bytes.
- */
- u32 version_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_0_;
- /**
- * Color key flag. 4 bytes.
- */
- u32 colour_key_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_1_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_2_;
- /**
- * Minimum bits per color. 4 bytes.
- *
- * Ignored by V-Geas.
- */
- u32 min_bpc_;
- /**
- * Maximum bits per color. 4 bytes.
- *
- * Ignored by V-Geas.
- */
- u32 max_bpc_;
- /**
- * Minimum alpha bits. 4 bytes.
- *
- * Ignored by V-Gears.
- */
- u32 min_alpha_bits_;
- /**
- * Minimum alpha bits. 4 bytes.
- *
- * Ignored by V-Gears.
- */
- u32 max_alpha_bits_;
- /**
- * Minimum bits per pixel. 4 bytes.
- *
- * Ignored by V-Gears.
- */
- u32 min_bpp_;
- /**
- * Maximum bits per pixel. 4 bytes.
- *
- * Ignored by V-Gears.
- */
- u32 max_bpp_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_3_;
- /**
- * Number of colour palettes. 4 bytes.
- */
- u32 palette_count_;
- /**
- * Number of colours per palette. 4 bytes.
- */
- u32 palette_colour_count_;
- /**
- * Bit depth. 4 Bytes.
- *
- * Can be ignores, always follow {@see bpp}.
- */
- u32 bit_depth_;
- /**
- * Image width. 4 bytes
- */
- u32 width_;
- /**
- * Image height. 4 bytes
- */
- u32 height_;
- /**
- * Pitch or bytes per row. 4 bytes.
- *
- * Ignored, use {@see bytes_per_pixel} * {@see width}.
- */
- u32 pitch_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_4_;
- /**
- * Indicates a paletted image. 4 bytes.
- */
- u32 has_palette_;
- /**
- * Bits per index. 4 bytes.
- *
- * For paletted images only. 0 for non-paletted.
- */
- u32 bits_per_index_;
- /**
- * Indexed to 8 bit flag.
- *
- * Ignored by OG and V-Gears.
- */
- u32 indexed_to_8_bit_;
- /**
- * Palette size. 4 bytes.
- *
- * It must match {@see palette_count} * {@see colours_per_palette}.
- */
- u32 palette_size_;
- /**
- * Number of colours per palette. 4 bytes.
- *
- * Ignore, use {@see palette_colour_count}
- */
- u32 colours_per_palette_;
- /**
- * Runtime data.
- *
- * V-gears ignores it.
- */
- u32 run_0_;
- /**
- * Bits per pixel.
- */
- u32 bits_per_pixel_;
- /**
- * Bytes per pixel.
- */
- u32 bytes_per_pixel_;
- // Pixel format 0 for non-paletted images.
- /**
- * Number of red bits.
- */
- u32 bits_red_;
- /**
- * Number of green bits
- */
- u32 bits_green_;
- /**
- * Number of blue bits
- */
- u32 bits_blue_;
- /**
- * Number of alpha bits
- */
- u32 bits_alpha_;
- /**
- * Red shift. 4 bytes.
- */
- u32 bitmask_red_;
- /**
- * Green bitmask. 4 bytes.
- */
- u32 bitmask_green_;
- /**
- * Blue bitmask. 4 bytes.
- */
- u32 bitmask_blue_;
- /**
- * Alpha bitmask. 4 bytes.
- */
- u32 bitmask_alpha_;
- /**
- * Red shift. 4 bytes.
- */
- u32 shift_red_;
- /**
- * Green shift. 4 bytes.
- */
- u32 shift_green_;
- /**
- * Blue shift. 4 bytes.
- */
- u32 shift_blue_;
- /**
- * Alpha shift. 4 bytes.
- */
- u32 shift_alpha_;
- /**
- * Red bits. Always 8. 4 bytes.
- *
- * Unused, use {@see bits_red}.
- */
- u32 bits_red_2_;
- /**
- * Green bits. Always 8. 4 bytes.
- *
- * Unused, use {@see bits_green}.
- */
- u32 bits_green_2_;
- /**
- * Blue bits. Always 8. 4 bytes.
- *
- * Unused, use {@see bits_blue}.
- */
- u32 bits_blue_2_;
- /**
- * Alpha bits. Always 8. 4 bytes.
- *
- * Unused, use {@see bits_alpha}.
- */
- u32 bits_alpha_2_;
- /**
- * Max value for red colour. 4 bytes.
- */
- u32 max_red_;
- /**
- * Max value for green colour. 4 bytes.
- */
- u32 max_green_;
- /**
- * Max value for blue colour. 4 bytes.
- */
- u32 max_blue_;
- /**
- * Max alpha value. 4 bytes.
- */
- u32 max_alpha_;
- // Pixel format end.
- /**
- * Colour key array flag. 4 bytes.
- *
- * Indicates the presence of a color key array,
- */
- u32 colour_k_array_;
- /**
- * Runtime data. 4 bytes.
- *
- * V-Gears ignores it.
- */
- u32 run_1_;
- /**
- * Alpha reference value. 4 bytes.
- *
- * Only applies to paltted images, if the alpha value sampled from the palee is 0xFE, this
- * value should be replaced with the reference alpha.
- */
- u32 ref_alpha_;
- /**
- * Runtime data. 4 bytes.
- *
- * V-Gears ignores it.
- */
- u32 run_2_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_5_;
- /**
- * Palette index. 4 bytes.
- *
- * Runtime data.
- */
- u32 palette_index_;
- /**
- * Runtime data. 4 bytes.
- *
- * V-Gears ignores it.
- */
- u32 run_3_;
- /**
- * Runtime data. 4 bytes.
- *
- * V-Gears ignores it.
- */
- u32 run_4_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_6_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_7_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_8_;
- /**
- * Unknown data. 4 bytes.
- */
- u32 unknown_9_;
- // Palette data.
- /**
- * Palette data. 4 * {@see palette_size} bytes.
- *
- * Used only for paletted images. Blocks of 32-bit BGRA colour format.
- */
- std::vector<std::vector<Ogre::ColourValue>> palettes_;
- // Pixel data.
- /**
- * Pixel data for non paletted images. {@see width} * {@see height}.
- */
- std::vector<Ogre::ColourValue> pixel_colour_;
- /**
- * Pixel data for paletted images. {@see width} * {@see height} * {@see bytes_per pixels}.
- *
- * In paletted images, every byte is a color reference in the palette. For non-paletted
- * images, a pixel format section.
- */
- std::vector<u8> pixel_ref_;
- // Colour key array
- /**
- * Colour key array. {@see palette_count} bytes.
- */
- std::vector<u8> colour_key_array_;
- };
|