tex_file_info.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <algorithm>
  16. #include <cstdio>
  17. #include <boost/algorithm/string/predicate.hpp>
  18. #include <boost/filesystem.hpp>
  19. #include <boost/filesystem/fstream.hpp>
  20. #include <boost/program_options.hpp>
  21. #include <Ogre/OgreDataStream.h>
  22. #include "data/VGearsTexFile.h"
  23. using std::back_inserter;
  24. using std::copy;
  25. using std::cout;
  26. using std::ifstream;
  27. using std::endl;
  28. using std::vector;
  29. using std::string;
  30. namespace bfs = boost::filesystem;
  31. namespace bpo = boost::program_options;
  32. void pintFileInfo(const bfs::path &tex_path){
  33. cout << endl << "TX Image File Info"
  34. << endl << " filename: " << tex_path.filename().string();
  35. bfs::ifstream *ifs(OGRE_NEW_T(bfs::ifstream, Ogre::MEMCATEGORY_GENERAL)(tex_path, bfs::ifstream::binary));
  36. Ogre::FileStreamDataStream *stream(OGRE_NEW Ogre::FileStreamDataStream(ifs));
  37. Ogre::DataStreamPtr input(stream);
  38. VGears::TexFile tex;
  39. tex.readHeader(input);
  40. cout << endl << " size: "
  41. << tex.m_header.image_data.width
  42. << "x" << tex.m_header.image_data.height
  43. << "x" << tex.m_header.image_data.bit_depth
  44. << endl << " pitch: " << tex.m_header.image_data.pitch
  45. << endl << " color_key_flag: " << tex.m_header.color_key_flag
  46. << endl << "Palette:"
  47. << endl << " type : " << tex.m_header.palette_type
  48. << endl << " count : " << tex.m_header.palette_count
  49. << endl << " index_bits : "
  50. << tex.m_header.palette_data.index_bits
  51. << endl << " flag : " << tex.m_header.palette_data.flag
  52. << endl << " total_color_count : "
  53. << tex.m_header.palette_total_color_count
  54. << endl << " total_color_count : "
  55. << tex.m_header.palette_data.total_color_count
  56. << endl << " colors_per_palette: "
  57. << tex.m_header.palette_data.colors_per_palette
  58. << endl << " unknown_CC : " << tex.m_header.unknown_0xCC;
  59. if (tex.m_header.palette_data.flag){
  60. cout << endl
  61. << " mask_red : " << tex.m_header.pixel_format.bit_mask.red
  62. << endl << " mask_green : "
  63. << tex.m_header.pixel_format.bit_mask.green
  64. << endl << " mask_blue : " << tex.m_header.pixel_format.bit_mask.blue
  65. << endl << " mask_alpha : "
  66. << tex.m_header.pixel_format.bit_mask.alpha;
  67. }
  68. cout << endl;
  69. }
  70. int main(int ac, char *av[]){
  71. const char* PO_HELP("help");
  72. const char* PO_INPUT_PATHS("input-paths");
  73. const string TEX_EXT(".tex");
  74. typedef vector<bfs::path> t_InputPaths;
  75. try {
  76. bpo::options_description generic("Generic options");
  77. generic.add_options()
  78. (PO_HELP, "produce help message")
  79. ;
  80. // Hidden options, will be allowed both on command line and
  81. // in config file, but will not be shown to the user.
  82. bpo::options_description hidden("Hidden options");
  83. hidden.add_options()
  84. (PO_INPUT_PATHS, bpo::value< t_InputPaths >()->required(), "input paths to files or directories")
  85. ;
  86. bpo::positional_options_description p;
  87. p.add(PO_INPUT_PATHS, -1);
  88. bpo::options_description cmdline_options;
  89. cmdline_options.add(generic).add(hidden);
  90. bpo::variables_map vm;
  91. bpo::store(bpo::command_line_parser(ac, av).options(cmdline_options).positional(p).run(), vm);
  92. if (vm.count(PO_HELP)){
  93. bfs::path self(av[0]);
  94. cout << "Usage: " << self.stem().string() << " [options] file|path...\n";
  95. cout << generic << "\n";
  96. return 0;
  97. }
  98. bpo::notify(vm);
  99. if (vm.count(PO_INPUT_PATHS)){
  100. t_InputPaths input(vm[ PO_INPUT_PATHS ].as< t_InputPaths >());
  101. t_InputPaths paths;
  102. for (t_InputPaths::const_iterator it(input.begin()); it != input.end(); ++it){
  103. if(bfs::exists(*it)){
  104. if(bfs::is_directory(*it)){
  105. copy(bfs::recursive_directory_iterator(*it), bfs::recursive_directory_iterator(), back_inserter(paths));
  106. }
  107. else{
  108. paths.push_back(*it);
  109. }
  110. }
  111. }
  112. for (t_InputPaths::const_iterator it(paths.begin()); it != paths.end(); ++it){
  113. if(bfs::is_regular_file(*it)){
  114. string ext(it->extension().string());
  115. if(boost::iequals(ext, TEX_EXT)){
  116. pintFileInfo(*it);
  117. }
  118. }
  119. }
  120. }
  121. }
  122. catch(const bfs::filesystem_error& e){
  123. cout << e.what() << endl;
  124. return 1;
  125. }
  126. return 0;
  127. }