basisu_basis_file.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // basisu_basis_file.h
  2. // Copyright (C) 2019 Binomial LLC. All Rights Reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. #pragma once
  16. #include "../transcoder/basisu_file_headers.h"
  17. #include "basisu_backend.h"
  18. namespace basisu
  19. {
  20. class basisu_file
  21. {
  22. BASISU_NO_EQUALS_OR_COPY_CONSTRUCT(basisu_file);
  23. public:
  24. basisu_file()
  25. {
  26. }
  27. void clear()
  28. {
  29. m_comp_data.clear();
  30. clear_obj(m_header);
  31. m_images_descs.clear();
  32. m_header_file_ofs = 0;
  33. m_slice_descs_file_ofs = 0;
  34. m_endpoint_cb_file_ofs = 0;
  35. m_selector_cb_file_ofs = 0;
  36. m_tables_file_ofs = 0;
  37. m_first_image_file_ofs = 0;
  38. m_total_file_size = 0;
  39. }
  40. bool init(const basisu_backend_output& encoder_output, basist::basis_texture_type tex_type, uint32_t userdata0, uint32_t userdata1, bool y_flipped, uint32_t us_per_frame);
  41. const uint8_vec &get_compressed_data() const { return m_comp_data; }
  42. private:
  43. basist::basis_file_header m_header;
  44. basisu::vector<basist::basis_slice_desc> m_images_descs;
  45. uint8_vec m_comp_data;
  46. uint32_t m_header_file_ofs;
  47. uint32_t m_slice_descs_file_ofs;
  48. uint32_t m_endpoint_cb_file_ofs;
  49. uint32_t m_selector_cb_file_ofs;
  50. uint32_t m_tables_file_ofs;
  51. uint32_t m_first_image_file_ofs;
  52. uint32_t m_total_file_size;
  53. void create_header(const basisu_backend_output& encoder_output, basist::basis_texture_type tex_type, uint32_t userdata0, uint32_t userdata1, bool y_flipped, uint32_t us_per_frame);
  54. bool create_image_descs(const basisu_backend_output& encoder_output);
  55. void create_comp_data(const basisu_backend_output& encoder_output);
  56. void fixup_crcs();
  57. };
  58. } // namespace basisu