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