OpenGL ES SDK for Android ARM Developer Center
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ETCHeader.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2014-2017, ARM Limited and Contributors
2  *
3  * SPDX-License-Identifier: MIT
4  *
5  * Permission is hereby granted, free of charge,
6  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
9  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
14  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 #include "ETCHeader.h"
22 
23 namespace MaliSDK
24 {
26  {}
27 
28  ETCHeader::ETCHeader(unsigned char *data)
29  {
30  /*
31  * Load from a ETC compressed pkm image file.
32  * First 6 bytes are the name of the file format and version/packing type.
33  * Bytes 7 and 8 are blank.
34  */
35  /* Beware endianess issues with most/least significant bits of the height and width. */
36  paddedWidthMSB = data[8];
37  paddedWidthLSB = data[9];
38  paddedHeightMSB = data[10];
39  paddedHeightLSB = data[11];
40  widthMSB = data[12];
41  widthLSB = data[13];
42  heightMSB = data[14];
43  heightLSB = data[15];
44  }
45 
46  unsigned short ETCHeader::getWidth(void)
47  {
48  return (widthMSB << 8) | widthLSB;
49  }
50 
51  unsigned short ETCHeader::getHeight(void)
52  {
53  return (heightMSB << 8) | heightLSB;
54  }
55 
56  unsigned short ETCHeader::getPaddedWidth(void)
57  {
58  return (paddedWidthMSB << 8) | paddedWidthLSB;
59  }
60 
61  unsigned short ETCHeader::getPaddedHeight(void)
62  {
63  return (paddedHeightMSB << 8) | paddedHeightLSB;
64  }
65 
66  GLsizei ETCHeader::getSize(GLenum internalFormat)
67  {
68  if (internalFormat != GL_COMPRESSED_RG11_EAC && internalFormat != GL_COMPRESSED_SIGNED_RG11_EAC &&
69  internalFormat != GL_COMPRESSED_RGBA8_ETC2_EAC && internalFormat != GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC)
70  {
71  return (getPaddedWidth() * getPaddedHeight()) >> 1;
72  }
73  else
74  {
75  return (getPaddedWidth() * getPaddedHeight());
76  }
77  }
78 }
unsigned short getPaddedHeight(void)
The height of the compressed texture with the padding added.
Definition: ETCHeader.cpp:63
unsigned char heightLSB
Definition: ETCHeader.h:48
unsigned char paddedHeightMSB
Definition: ETCHeader.h:43
unsigned char paddedWidthLSB
Definition: ETCHeader.h:42
unsigned short getHeight(void)
The height of the original texture.
Definition: ETCHeader.cpp:53
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
Definition: gl2ext.h:179
unsigned char heightMSB
Definition: ETCHeader.h:47
unsigned short getPaddedWidth(void)
The width of the compressed texture with the padding added.
Definition: ETCHeader.cpp:58
unsigned char widthMSB
Definition: ETCHeader.h:45
unsigned char widthLSB
Definition: ETCHeader.h:46
unsigned char paddedWidthMSB
Definition: ETCHeader.h:41
typedef GLenum(GL_APIENTRYP PFNGLGETGRAPHICSRESETSTATUSKHRPROC)(void)
unsigned short getWidth(void)
The width of the original texture.
Definition: ETCHeader.cpp:48
GLsizei getSize(GLenum internalFormat)
The size of the compressed texture with the padding added.
Definition: ETCHeader.cpp:66
unsigned char paddedHeightLSB
Definition: ETCHeader.h:44
ETCHeader()
Default constructor.
Definition: ETCHeader.cpp:25