EtcFile.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2015 The Etc2Comp Authors.
  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. */
  16. #pragma once
  17. #include "EtcColorFloatRGBA.h"
  18. #include "EtcImage.h"
  19. #include "Etc.h"
  20. namespace Etc
  21. {
  22. class FileHeader;
  23. class SourceImage;
  24. class File
  25. {
  26. public:
  27. enum class Format
  28. {
  29. INFER_FROM_FILE_EXTENSION,
  30. PKM,
  31. KTX,
  32. };
  33. File(const char *a_pstrFilename, Format a_fileformat, Image::Format a_imageformat,
  34. unsigned char *a_paucEncodingBits, unsigned int a_uiEncodingBitsBytes,
  35. unsigned int a_uiSourceWidth, unsigned int a_uiSourceHeight,
  36. unsigned int a_uiExtendedWidth, unsigned int a_uiExtendedHeight);
  37. File(const char *a_pstrFilename, Format a_fileformat, Image::Format a_imageformat,
  38. unsigned int a_uiNumMipmaps, RawImage *pMipmapImages,
  39. unsigned int a_uiSourceWidth, unsigned int a_uiSourceHeight );
  40. File(const char *a_pstrFilename, Format a_fileformat);
  41. ~File();
  42. const char *GetFilename(void) { return m_pstrFilename; }
  43. void Read(const char *a_pstrFilename);
  44. void Write(void);
  45. inline unsigned int GetSourceWidth(void)
  46. {
  47. return m_uiSourceWidth;
  48. }
  49. inline unsigned int GetSourceHeight(void)
  50. {
  51. return m_uiSourceHeight;
  52. }
  53. inline unsigned int GetExtendedWidth(unsigned int mipmapIndex = 0)
  54. {
  55. if (mipmapIndex < m_uiNumMipmaps)
  56. {
  57. return m_pMipmapImages[mipmapIndex].uiExtendedWidth;
  58. }
  59. else
  60. {
  61. return 0;
  62. }
  63. }
  64. inline unsigned int GetExtendedHeight(unsigned int mipmapIndex = 0)
  65. {
  66. if (mipmapIndex < m_uiNumMipmaps)
  67. {
  68. return m_pMipmapImages[mipmapIndex].uiExtendedHeight;
  69. }
  70. else
  71. {
  72. return 0;
  73. }
  74. }
  75. inline Image::Format GetImageFormat()
  76. {
  77. return m_imageformat;
  78. }
  79. inline unsigned int GetEncodingBitsBytes(unsigned int mipmapIndex = 0)
  80. {
  81. if (mipmapIndex < m_uiNumMipmaps)
  82. {
  83. return m_pMipmapImages[mipmapIndex].uiEncodingBitsBytes;
  84. }
  85. else
  86. {
  87. return 0;
  88. }
  89. }
  90. inline unsigned char* GetEncodingBits(unsigned int mipmapIndex = 0)
  91. {
  92. if( mipmapIndex < m_uiNumMipmaps)
  93. {
  94. return m_pMipmapImages[mipmapIndex].paucEncodingBits.get();
  95. }
  96. else
  97. {
  98. return nullptr;
  99. }
  100. }
  101. inline unsigned int GetNumMipmaps()
  102. {
  103. return m_uiNumMipmaps;
  104. }
  105. void UseSingleBlock(int a_iPixelX = -1, int a_iPixelY = -1);
  106. private:
  107. char *m_pstrFilename; // includes directory path and file extension
  108. Format m_fileformat;
  109. Image::Format m_imageformat;
  110. FileHeader *m_pheader;
  111. unsigned int m_uiNumMipmaps;
  112. RawImage* m_pMipmapImages;
  113. unsigned int m_uiSourceWidth;
  114. unsigned int m_uiSourceHeight;
  115. };
  116. }