summaryrefslogtreecommitdiff
path: root/thirdparty/etc2comp/EtcFile.h
blob: 69bf3b2d3a2ef80f4307b6fb51a3208e7477ee63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Copyright 2015 The Etc2Comp Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include "EtcColorFloatRGBA.h"
#include "EtcImage.h"
#include "Etc.h"

namespace Etc
{
	class FileHeader;
	class SourceImage;

	class File
	{
	public:

		enum class Format
		{
			INFER_FROM_FILE_EXTENSION,
			PKM,
			KTX,
		};

		File(const char *a_pstrFilename, Format a_fileformat, Image::Format a_imageformat,
				unsigned char *a_paucEncodingBits, unsigned int a_uiEncodingBitsBytes,
				unsigned int a_uiSourceWidth, unsigned int a_uiSourceHeight,
				unsigned int a_uiExtendedWidth, unsigned int a_uiExtendedHeight);

		File(const char *a_pstrFilename, Format a_fileformat, Image::Format a_imageformat,
			unsigned int a_uiNumMipmaps, RawImage *pMipmapImages,
			unsigned int a_uiSourceWidth, unsigned int a_uiSourceHeight );

		File(const char *a_pstrFilename, Format a_fileformat);
		~File();
		const char *GetFilename(void) { return m_pstrFilename; }

		void Read(const char *a_pstrFilename);
		void Write(void);

		inline unsigned int GetSourceWidth(void)
		{
			return m_uiSourceWidth;
		}

		inline unsigned int GetSourceHeight(void)
		{
			return m_uiSourceHeight;
		}

		inline unsigned int GetExtendedWidth(unsigned int mipmapIndex = 0)
		{
			if (mipmapIndex < m_uiNumMipmaps)
			{
				return m_pMipmapImages[mipmapIndex].uiExtendedWidth;
			}
			else
			{
				return 0;
			}
		}

		inline unsigned int GetExtendedHeight(unsigned int mipmapIndex = 0)
		{
			if (mipmapIndex < m_uiNumMipmaps)
			{
				return m_pMipmapImages[mipmapIndex].uiExtendedHeight;
			}
			else
			{
				return 0;
			}
		}

		inline Image::Format GetImageFormat()
		{
			return m_imageformat;
		}

		inline unsigned int GetEncodingBitsBytes(unsigned int mipmapIndex = 0)
		{
			if (mipmapIndex < m_uiNumMipmaps)
			{
				return m_pMipmapImages[mipmapIndex].uiEncodingBitsBytes;
			}
			else
			{
				return 0;
			}
		}

		inline unsigned char*  GetEncodingBits(unsigned int mipmapIndex = 0)
		{
			if( mipmapIndex < m_uiNumMipmaps)
			{
				return m_pMipmapImages[mipmapIndex].paucEncodingBits.get();
			}
			else
			{
				return nullptr;
			}
		}

		inline unsigned int GetNumMipmaps() 
		{
			return m_uiNumMipmaps; 
		}

		void UseSingleBlock(int a_iPixelX = -1, int a_iPixelY = -1);
	private:

		char *m_pstrFilename;               // includes directory path and file extension
		Format m_fileformat;
		Image::Format m_imageformat;
		FileHeader *m_pheader;
		unsigned int m_uiNumMipmaps;
		RawImage*	 m_pMipmapImages;
		unsigned int m_uiSourceWidth;
		unsigned int m_uiSourceHeight;
	};

}