MCPcopy Create free account
hub / github.com/ARM-software/astc-encoder / determine_image_components

Function determine_image_components

Source/astcenccli_image.cpp:115–194  ·  view source on GitHub ↗

See header for documentation. */

Source from the content-addressed store, hash-verified

113
114/* See header for documentation. */
115unsigned int determine_image_components(
116 const astcenc_image * img
117) {
118 unsigned int dim_x = img->dim_x;
119 unsigned int dim_y = img->dim_y;
120 unsigned int dim_z = img->dim_z;
121
122 // Scan through the image data to determine how many color components the image has
123 bool is_luma = true;
124 bool has_alpha = false;
125
126 if (img->data_type == ASTCENC_TYPE_U8)
127 {
128 for (unsigned int z = 0; z < dim_z; z++)
129 {
130 uint8_t* data8 = static_cast<uint8_t*>(img->data[z]);
131
132 for (unsigned int y = 0; y < dim_y; y++)
133 {
134 for (unsigned int x = 0; x < dim_x; x++)
135 {
136 int r = data8[(4 * dim_x * y) + (4 * x )];
137 int g = data8[(4 * dim_x * y) + (4 * x + 1)];
138 int b = data8[(4 * dim_x * y) + (4 * x + 2)];
139 int a = data8[(4 * dim_x * y) + (4 * x + 3)];
140
141 is_luma = is_luma && (r == g) && (r == b);
142 has_alpha = has_alpha || (a != 0xFF);
143 }
144 }
145 }
146 }
147 else if (img->data_type == ASTCENC_TYPE_F16)
148 {
149 for (unsigned int z = 0; z < dim_z; z++)
150 {
151 uint16_t* data16 = static_cast<uint16_t*>(img->data[z]);
152
153 for (unsigned int y = 0; y < dim_y; y++)
154 {
155 for (unsigned int x = 0; x < dim_x; x++)
156 {
157 int r = data16[(4 * dim_x * y) + (4 * x )];
158 int g = data16[(4 * dim_x * y) + (4 * x + 1)];
159 int b = data16[(4 * dim_x * y) + (4 * x + 2)];
160 int a = data16[(4 * dim_x * y) + (4 * x + 3)];
161
162 is_luma = is_luma && (r == g) && (r == b);
163 has_alpha = has_alpha || ((a ^ 0xC3FF) != 0xFFFF);
164 // a ^ 0xC3FF returns FFFF if and only if the input is 1.0
165 }
166 }
167 }
168 }
169 else // if (img->data_type == ASTCENC_TYPE_F32)
170 {
171 assert(img->data_type == ASTCENC_TYPE_F32);
172

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected