| 2260 | } |
| 2261 | |
| 2262 | CGU_FLOAT FindBestPattern(BC6H_Encode_local* BC6H_data, CGU_BOOL TwoRegionShapes, CGU_INT8 shape_pattern, CGU_FLOAT quality) |
| 2263 | { |
| 2264 | // Index bit size for the patterns been used. |
| 2265 | // All two zone shapes have 3 bits per color, max index value < 8 |
| 2266 | // All one zone shapes gave 4 bits per color, max index value < 16 |
| 2267 | CGU_INT8 Index_BitSize = TwoRegionShapes ? 8 : 16; |
| 2268 | CGU_INT8 max_subsets = TwoRegionShapes ? 2 : 1; |
| 2269 | CGU_FLOAT direction[NCHANNELS] = {}; |
| 2270 | CGU_FLOAT step = 0; |
| 2271 | |
| 2272 | BC6H_data->region = max_subsets; |
| 2273 | BC6H_data->index = 0; |
| 2274 | BC6H_data->d_shape_index = shape_pattern; |
| 2275 | memset((CGU_UINT8*)BC6H_data->partition, 0, sizeof(BC6H_data->partition)); |
| 2276 | memset((CGU_UINT8*)BC6H_data->shape_indices, 0, sizeof(BC6H_data->shape_indices)); |
| 2277 | |
| 2278 | // Get the pattern to encode with |
| 2279 | Partition(shape_pattern, // Shape pattern we want to get |
| 2280 | BC6H_data->din, // Input data |
| 2281 | BC6H_data->partition, // Returns the patterned shape data |
| 2282 | BC6H_data->entryCount, // counts the number of pixel used in each subset region num of 0's amd 1's |
| 2283 | max_subsets, // Table Shapes to use eithe one regions 1 or two regions 2 |
| 2284 | 3); // rgb no alpha always = 3 |
| 2285 | |
| 2286 | CGU_FLOAT error[MAX_SUBSETS] = {0.0, CMP_FLOAT_MAX, CMP_FLOAT_MAX}; |
| 2287 | CGU_INT BestOutB = 0; |
| 2288 | CGU_FLOAT BestError; //the lowest error from vector direction quantization |
| 2289 | CGU_FLOAT BestError_endpts; //the lowest error from endpoints extracted from the vector direction quantization |
| 2290 | |
| 2291 | CGU_FLOAT outB[2][2][MAX_SUBSET_SIZE][MAX_DIMENSION_BIG] = {}; |
| 2292 | CGU_INT shape_indicesB[2][MAX_SUBSETS][MAX_SUBSET_SIZE] = {}; |
| 2293 | |
| 2294 | for (CGU_INT subset = 0; subset < max_subsets; subset++) |
| 2295 | { |
| 2296 | error[0] += optQuantAnD_d(BC6H_data->partition[subset], // input data |
| 2297 | BC6H_data->entryCount[subset], // number of input points above (not clear about 1, better to avoid) |
| 2298 | Index_BitSize, // number of clusters on the ramp, 8 or 16 |
| 2299 | shape_indicesB[0][subset], // output index, if not all points of the ramp used, 0 may not be assigned |
| 2300 | outB[0][subset], // resulting quantization |
| 2301 | direction, // direction vector of the ramp (check normalization) |
| 2302 | &step, // step size (check normalization) |
| 2303 | 3, // number of channels (always 3 = RGB for BC6H) |
| 2304 | quality // Quality set number of retry to get good end points |
| 2305 | // Max retries = MAX_TRY = 4000 when Quality is 1.0 |
| 2306 | // Min = 0 and default with quality 0.05 is 200 times |
| 2307 | ); |
| 2308 | } |
| 2309 | |
| 2310 | BestError = error[0]; |
| 2311 | BestOutB = 0; |
| 2312 | |
| 2313 | // The following code is almost complete - runs very slow and not sure if % of improvement is justified.. |
| 2314 | #ifdef USE_SHAKERHD |
| 2315 | // Valid only for 2 region shapes |
| 2316 | if ((max_subsets > 1) && (quality > 0.80)) |
| 2317 | { |
| 2318 | CGU_INT tempIndices[MAX_SUBSET_SIZE] = {}; |
| 2319 | // CGU_INT temp_epo_code[2][2][MAX_DIMENSION_BIG]; |
no test coverage detected