Path: blob/master/thirdparty/astcenc/astcenc_pick_best_endpoint_format.cpp
9896 views
// SPDX-License-Identifier: Apache-2.01// ----------------------------------------------------------------------------2// Copyright 2011-2025 Arm Limited3//4// Licensed under the Apache License, Version 2.0 (the "License"); you may not5// use this file except in compliance with the License. You may obtain a copy6// of the License at:7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13// License for the specific language governing permissions and limitations14// under the License.15// ----------------------------------------------------------------------------1617#if !defined(ASTCENC_DECOMPRESS_ONLY)1819/**20* @brief Functions for finding best endpoint format.21*22* We assume there are two independent sources of error in any given partition:23*24* - Encoding choice errors25* - Quantization errors26*27* Encoding choice errors are caused by encoder decisions. For example:28*29* - Using luminance instead of separate RGB components.30* - Using a constant 1.0 alpha instead of storing an alpha component.31* - Using RGB+scale instead of storing two full RGB endpoints.32*33* Quantization errors occur due to the limited precision we use for storage. These errors generally34* scale with quantization level, but are not actually independent of color encoding. In particular:35*36* - If we can use offset encoding then quantization error is halved.37* - If we can use blue-contraction then quantization error for RG is halved.38* - If we use HDR endpoints the quantization error is higher.39*40* Apart from these effects, we assume the error is proportional to the quantization step size.41*/424344#include "astcenc_internal.h"45#include "astcenc_vecmathlib.h"4647#include <assert.h>4849/**50* @brief Compute the errors of the endpoint line options for one partition.51*52* Uncorrelated data assumes storing completely independent RGBA channels for each endpoint. Same53* chroma data assumes storing RGBA endpoints which pass though the origin (LDR only). RGBL data54* assumes storing RGB + lumashift (HDR only). Luminance error assumes storing RGB channels as a55* single value.56*57*58* @param pi The partition info data.59* @param partition_index The partition index to compule the error for.60* @param blk The image block.61* @param uncor_pline The endpoint line assuming uncorrelated endpoints.62* @param[out] uncor_err The computed error for the uncorrelated endpoint line.63* @param samec_pline The endpoint line assuming the same chroma for both endpoints.64* @param[out] samec_err The computed error for the uncorrelated endpoint line.65* @param rgbl_pline The endpoint line assuming RGB + lumashift data.66* @param[out] rgbl_err The computed error for the RGB + lumashift endpoint line.67* @param l_pline The endpoint line assuming luminance data.68* @param[out] l_err The computed error for the luminance endpoint line.69* @param[out] a_drop_err The computed error for dropping the alpha component.70*/71static void compute_error_squared_rgb_single_partition(72const partition_info& pi,73int partition_index,74const image_block& blk,75const processed_line3& uncor_pline,76float& uncor_err,77const processed_line3& samec_pline,78float& samec_err,79const processed_line3& rgbl_pline,80float& rgbl_err,81const processed_line3& l_pline,82float& l_err,83float& a_drop_err84) {85vfloat4 ews = blk.channel_weight;8687unsigned int texel_count = pi.partition_texel_count[partition_index];88const uint8_t* texel_indexes = pi.texels_of_partition[partition_index];89promise(texel_count > 0);9091vfloatacc a_drop_errv = vfloatacc::zero();92vfloat default_a(blk.get_default_alpha());9394vfloatacc uncor_errv = vfloatacc::zero();95vfloat uncor_bs0(uncor_pline.bs.lane<0>());96vfloat uncor_bs1(uncor_pline.bs.lane<1>());97vfloat uncor_bs2(uncor_pline.bs.lane<2>());9899vfloat uncor_amod0(uncor_pline.amod.lane<0>());100vfloat uncor_amod1(uncor_pline.amod.lane<1>());101vfloat uncor_amod2(uncor_pline.amod.lane<2>());102103vfloatacc samec_errv = vfloatacc::zero();104vfloat samec_bs0(samec_pline.bs.lane<0>());105vfloat samec_bs1(samec_pline.bs.lane<1>());106vfloat samec_bs2(samec_pline.bs.lane<2>());107108vfloatacc rgbl_errv = vfloatacc::zero();109vfloat rgbl_bs0(rgbl_pline.bs.lane<0>());110vfloat rgbl_bs1(rgbl_pline.bs.lane<1>());111vfloat rgbl_bs2(rgbl_pline.bs.lane<2>());112113vfloat rgbl_amod0(rgbl_pline.amod.lane<0>());114vfloat rgbl_amod1(rgbl_pline.amod.lane<1>());115vfloat rgbl_amod2(rgbl_pline.amod.lane<2>());116117vfloatacc l_errv = vfloatacc::zero();118vfloat l_bs0(l_pline.bs.lane<0>());119vfloat l_bs1(l_pline.bs.lane<1>());120vfloat l_bs2(l_pline.bs.lane<2>());121122vint lane_ids = vint::lane_id();123for (unsigned int i = 0; i < texel_count; i += ASTCENC_SIMD_WIDTH)124{125const uint8_t* tix = texel_indexes + i;126127vmask mask = lane_ids < vint(texel_count);128lane_ids += vint(ASTCENC_SIMD_WIDTH);129130// Compute the error that arises from just ditching alpha131vfloat data_a = gatherf_byte_inds<vfloat>(blk.data_a, tix);132vfloat alpha_diff = data_a - default_a;133alpha_diff = alpha_diff * alpha_diff;134135haccumulate(a_drop_errv, alpha_diff, mask);136137vfloat data_r = gatherf_byte_inds<vfloat>(blk.data_r, tix);138vfloat data_g = gatherf_byte_inds<vfloat>(blk.data_g, tix);139vfloat data_b = gatherf_byte_inds<vfloat>(blk.data_b, tix);140141// Compute uncorrelated error142vfloat param = data_r * uncor_bs0143+ data_g * uncor_bs1144+ data_b * uncor_bs2;145146vfloat dist0 = (uncor_amod0 + param * uncor_bs0) - data_r;147vfloat dist1 = (uncor_amod1 + param * uncor_bs1) - data_g;148vfloat dist2 = (uncor_amod2 + param * uncor_bs2) - data_b;149150vfloat error = dist0 * dist0 * ews.lane<0>()151+ dist1 * dist1 * ews.lane<1>()152+ dist2 * dist2 * ews.lane<2>();153154haccumulate(uncor_errv, error, mask);155156// Compute same chroma error - no "amod", its always zero157param = data_r * samec_bs0158+ data_g * samec_bs1159+ data_b * samec_bs2;160161dist0 = (param * samec_bs0) - data_r;162dist1 = (param * samec_bs1) - data_g;163dist2 = (param * samec_bs2) - data_b;164165error = dist0 * dist0 * ews.lane<0>()166+ dist1 * dist1 * ews.lane<1>()167+ dist2 * dist2 * ews.lane<2>();168169haccumulate(samec_errv, error, mask);170171// Compute rgbl error172param = data_r * rgbl_bs0173+ data_g * rgbl_bs1174+ data_b * rgbl_bs2;175176dist0 = (rgbl_amod0 + param * rgbl_bs0) - data_r;177dist1 = (rgbl_amod1 + param * rgbl_bs1) - data_g;178dist2 = (rgbl_amod2 + param * rgbl_bs2) - data_b;179180error = dist0 * dist0 * ews.lane<0>()181+ dist1 * dist1 * ews.lane<1>()182+ dist2 * dist2 * ews.lane<2>();183184haccumulate(rgbl_errv, error, mask);185186// Compute luma error - no "amod", its always zero187param = data_r * l_bs0188+ data_g * l_bs1189+ data_b * l_bs2;190191dist0 = (param * l_bs0) - data_r;192dist1 = (param * l_bs1) - data_g;193dist2 = (param * l_bs2) - data_b;194195error = dist0 * dist0 * ews.lane<0>()196+ dist1 * dist1 * ews.lane<1>()197+ dist2 * dist2 * ews.lane<2>();198199haccumulate(l_errv, error, mask);200}201202a_drop_err = hadd_s(a_drop_errv) * ews.lane<3>();203uncor_err = hadd_s(uncor_errv);204samec_err = hadd_s(samec_errv);205rgbl_err = hadd_s(rgbl_errv);206l_err = hadd_s(l_errv);207}208209/**210* @brief For a given set of input colors and partitioning determine endpoint encode errors.211*212* This function determines the color error that results from RGB-scale encoding (LDR only),213* RGB-lumashift encoding (HDR only), luminance-encoding, and alpha drop. Also determines whether214* the endpoints are eligible for offset encoding or blue-contraction215*216* @param blk The image block.217* @param pi The partition info data.218* @param ep The idealized endpoints.219* @param[out] eci The resulting encoding choice error metrics.220*/221static void compute_encoding_choice_errors(222const image_block& blk,223const partition_info& pi,224const endpoints& ep,225encoding_choice_errors eci[BLOCK_MAX_PARTITIONS])226{227int partition_count = pi.partition_count;228promise(partition_count > 0);229230partition_metrics pms[BLOCK_MAX_PARTITIONS];231232compute_avgs_and_dirs_3_comp_rgb(pi, blk, pms);233234for (int i = 0; i < partition_count; i++)235{236partition_metrics& pm = pms[i];237238line3 uncor_rgb_lines;239line3 samec_rgb_lines; // for LDR-RGB-scale240line3 rgb_luma_lines; // for HDR-RGB-scale241242processed_line3 uncor_rgb_plines;243processed_line3 samec_rgb_plines;244processed_line3 rgb_luma_plines;245processed_line3 luminance_plines;246247float uncorr_rgb_error;248float samechroma_rgb_error;249float rgb_luma_error;250float luminance_rgb_error;251float alpha_drop_error;252253uncor_rgb_lines.a = pm.avg;254uncor_rgb_lines.b = normalize_safe(pm.dir, unit3());255256samec_rgb_lines.a = vfloat4::zero();257samec_rgb_lines.b = normalize_safe(pm.avg, unit3());258259rgb_luma_lines.a = pm.avg;260rgb_luma_lines.b = unit3();261262uncor_rgb_plines.amod = uncor_rgb_lines.a - uncor_rgb_lines.b * dot3(uncor_rgb_lines.a, uncor_rgb_lines.b);263uncor_rgb_plines.bs = uncor_rgb_lines.b;264265// Same chroma always goes though zero, so this is simpler than the others266samec_rgb_plines.amod = vfloat4::zero();267samec_rgb_plines.bs = samec_rgb_lines.b;268269rgb_luma_plines.amod = rgb_luma_lines.a - rgb_luma_lines.b * dot3(rgb_luma_lines.a, rgb_luma_lines.b);270rgb_luma_plines.bs = rgb_luma_lines.b;271272// Luminance always goes though zero, so this is simpler than the others273luminance_plines.amod = vfloat4::zero();274luminance_plines.bs = unit3();275276compute_error_squared_rgb_single_partition(277pi, i, blk,278uncor_rgb_plines, uncorr_rgb_error,279samec_rgb_plines, samechroma_rgb_error,280rgb_luma_plines, rgb_luma_error,281luminance_plines, luminance_rgb_error,282alpha_drop_error);283284// Determine if we can offset encode RGB lanes285vfloat4 endpt0 = ep.endpt0[i];286vfloat4 endpt1 = ep.endpt1[i];287vfloat4 endpt_diff = abs(endpt1 - endpt0);288vmask4 endpt_can_offset = endpt_diff < vfloat4(0.12f * 65535.0f);289bool can_offset_encode = (mask(endpt_can_offset) & 0x7) == 0x7;290291// Store out the settings292eci[i].rgb_scale_error = (samechroma_rgb_error - uncorr_rgb_error) * 0.7f; // empirical293eci[i].rgb_luma_error = (rgb_luma_error - uncorr_rgb_error) * 1.5f; // wild guess294eci[i].luminance_error = (luminance_rgb_error - uncorr_rgb_error) * 3.0f; // empirical295eci[i].alpha_drop_error = alpha_drop_error * 3.0f;296eci[i].can_offset_encode = can_offset_encode;297eci[i].can_blue_contract = !blk.is_luminance();298}299}300301/**302* @brief For a given partition compute the error for every endpoint integer count and quant level.303*304* @param encode_hdr_rgb @c true if using HDR for RGB, @c false for LDR.305* @param encode_hdr_alpha @c true if using HDR for alpha, @c false for LDR.306* @param partition_index The partition index.307* @param pi The partition info.308* @param eci The encoding choice error metrics.309* @param ep The idealized endpoints.310* @param error_weight The resulting encoding choice error metrics.311* @param[out] best_error The best error for each integer count and quant level.312* @param[out] format_of_choice The preferred endpoint format for each integer count and quant level.313*/314static void compute_color_error_for_every_integer_count_and_quant_level(315bool encode_hdr_rgb,316bool encode_hdr_alpha,317int partition_index,318const partition_info& pi,319const encoding_choice_errors& eci,320const endpoints& ep,321vfloat4 error_weight,322float best_error[21][4],323uint8_t format_of_choice[21][4]324) {325int partition_size = pi.partition_texel_count[partition_index];326327static const float baseline_quant_error[21 - QUANT_6] {328(65536.0f * 65536.0f / 18.0f) / (5 * 5),329(65536.0f * 65536.0f / 18.0f) / (7 * 7),330(65536.0f * 65536.0f / 18.0f) / (9 * 9),331(65536.0f * 65536.0f / 18.0f) / (11 * 11),332(65536.0f * 65536.0f / 18.0f) / (15 * 15),333(65536.0f * 65536.0f / 18.0f) / (19 * 19),334(65536.0f * 65536.0f / 18.0f) / (23 * 23),335(65536.0f * 65536.0f / 18.0f) / (31 * 31),336(65536.0f * 65536.0f / 18.0f) / (39 * 39),337(65536.0f * 65536.0f / 18.0f) / (47 * 47),338(65536.0f * 65536.0f / 18.0f) / (63 * 63),339(65536.0f * 65536.0f / 18.0f) / (79 * 79),340(65536.0f * 65536.0f / 18.0f) / (95 * 95),341(65536.0f * 65536.0f / 18.0f) / (127 * 127),342(65536.0f * 65536.0f / 18.0f) / (159 * 159),343(65536.0f * 65536.0f / 18.0f) / (191 * 191),344(65536.0f * 65536.0f / 18.0f) / (255 * 255)345};346347vfloat4 ep0 = ep.endpt0[partition_index];348vfloat4 ep1 = ep.endpt1[partition_index];349350float ep1_min = hmin_rgb_s(ep1);351ep1_min = astc::max(ep1_min, 0.0f);352353float error_weight_rgbsum = hadd_rgb_s(error_weight);354355float range_upper_limit_rgb = encode_hdr_rgb ? 61440.0f : 65535.0f;356float range_upper_limit_alpha = encode_hdr_alpha ? 61440.0f : 65535.0f;357358// It is possible to get endpoint colors significantly outside [0,upper-limit] even if the359// input data are safely contained in [0,upper-limit]; we need to add an error term for this360vfloat4 offset(range_upper_limit_rgb, range_upper_limit_rgb, range_upper_limit_rgb, range_upper_limit_alpha);361vfloat4 ep0_range_error_high = max(ep0 - offset, 0.0f);362vfloat4 ep1_range_error_high = max(ep1 - offset, 0.0f);363364vfloat4 ep0_range_error_low = min(ep0, 0.0f);365vfloat4 ep1_range_error_low = min(ep1, 0.0f);366367vfloat4 sum_range_error =368(ep0_range_error_low * ep0_range_error_low) +369(ep1_range_error_low * ep1_range_error_low) +370(ep0_range_error_high * ep0_range_error_high) +371(ep1_range_error_high * ep1_range_error_high);372373float rgb_range_error = dot3_s(sum_range_error, error_weight)374* 0.5f * static_cast<float>(partition_size);375float alpha_range_error = sum_range_error.lane<3>() * error_weight.lane<3>()376* 0.5f * static_cast<float>(partition_size);377378if (encode_hdr_rgb)379{380381// Collect some statistics382float af, cf;383if (ep1.lane<0>() > ep1.lane<1>() && ep1.lane<0>() > ep1.lane<2>())384{385af = ep1.lane<0>();386cf = ep1.lane<0>() - ep0.lane<0>();387}388else if (ep1.lane<1>() > ep1.lane<2>())389{390af = ep1.lane<1>();391cf = ep1.lane<1>() - ep0.lane<1>();392}393else394{395af = ep1.lane<2>();396cf = ep1.lane<2>() - ep0.lane<2>();397}398399// Estimate of color-component spread in high endpoint color400float bf = af - ep1_min;401vfloat4 prd = (ep1 - vfloat4(cf)).swz<0, 1, 2>();402vfloat4 pdif = prd - ep0.swz<0, 1, 2>();403// Estimate of color-component spread in low endpoint color404float df = hmax_s(abs(pdif));405406int b = static_cast<int>(bf);407int c = static_cast<int>(cf);408int d = static_cast<int>(df);409410// Determine which one of the 6 submodes is likely to be used in case of an RGBO-mode411int rgbo_mode = 5; // 7 bits per component412// mode 4: 8 7 6413if (b < 32768 && c < 16384)414{415rgbo_mode = 4;416}417418// mode 3: 9 6 7419if (b < 8192 && c < 16384)420{421rgbo_mode = 3;422}423424// mode 2: 10 5 8425if (b < 2048 && c < 16384)426{427rgbo_mode = 2;428}429430// mode 1: 11 6 5431if (b < 2048 && c < 1024)432{433rgbo_mode = 1;434}435436// mode 0: 11 5 7437if (b < 1024 && c < 4096)438{439rgbo_mode = 0;440}441442// Determine which one of the 9 submodes is likely to be used in case of an RGB-mode.443int rgb_mode = 8; // 8 bits per component, except 7 bits for blue444445// mode 0: 9 7 6 7446if (b < 16384 && c < 8192 && d < 8192)447{448rgb_mode = 0;449}450451// mode 1: 9 8 6 6452if (b < 32768 && c < 8192 && d < 4096)453{454rgb_mode = 1;455}456457// mode 2: 10 6 7 7458if (b < 4096 && c < 8192 && d < 4096)459{460rgb_mode = 2;461}462463// mode 3: 10 7 7 6464if (b < 8192 && c < 8192 && d < 2048)465{466rgb_mode = 3;467}468469// mode 4: 11 8 6 5470if (b < 8192 && c < 2048 && d < 512)471{472rgb_mode = 4;473}474475// mode 5: 11 6 8 6476if (b < 2048 && c < 8192 && d < 1024)477{478rgb_mode = 5;479}480481// mode 6: 12 7 7 5482if (b < 2048 && c < 2048 && d < 256)483{484rgb_mode = 6;485}486487// mode 7: 12 6 7 6488if (b < 1024 && c < 2048 && d < 512)489{490rgb_mode = 7;491}492493static const float rgbo_error_scales[6] { 4.0f, 4.0f, 16.0f, 64.0f, 256.0f, 1024.0f };494static const float rgb_error_scales[9] { 64.0f, 64.0f, 16.0f, 16.0f, 4.0f, 4.0f, 1.0f, 1.0f, 384.0f };495496float mode7mult = rgbo_error_scales[rgbo_mode] * 0.0015f; // Empirically determined ....497float mode11mult = rgb_error_scales[rgb_mode] * 0.010f; // Empirically determined ....498499500float lum_high = hadd_rgb_s(ep1) * (1.0f / 3.0f);501float lum_low = hadd_rgb_s(ep0) * (1.0f / 3.0f);502float lumdif = lum_high - lum_low;503float mode23mult = lumdif < 960 ? 4.0f : lumdif < 3968 ? 16.0f : 128.0f;504505mode23mult *= 0.0005f; // Empirically determined ....506507// Pick among the available HDR endpoint modes508for (int i = QUANT_2; i < QUANT_16; i++)509{510best_error[i][3] = ERROR_CALC_DEFAULT;511best_error[i][2] = ERROR_CALC_DEFAULT;512best_error[i][1] = ERROR_CALC_DEFAULT;513best_error[i][0] = ERROR_CALC_DEFAULT;514515format_of_choice[i][3] = static_cast<uint8_t>(encode_hdr_alpha ? FMT_HDR_RGBA : FMT_HDR_RGB_LDR_ALPHA);516format_of_choice[i][2] = FMT_HDR_RGB;517format_of_choice[i][1] = FMT_HDR_RGB_SCALE;518format_of_choice[i][0] = FMT_HDR_LUMINANCE_LARGE_RANGE;519}520521for (int i = QUANT_16; i <= QUANT_256; i++)522{523// The base_quant_error should depend on the scale-factor that would be used during524// actual encode of the color value525526float base_quant_error = baseline_quant_error[i - QUANT_6] * static_cast<float>(partition_size);527float rgb_quantization_error = error_weight_rgbsum * base_quant_error * 2.0f;528float alpha_quantization_error = error_weight.lane<3>() * base_quant_error * 2.0f;529float rgba_quantization_error = rgb_quantization_error + alpha_quantization_error;530531// For 8 integers, we have two encodings: one with HDR A and another one with LDR A532533float full_hdr_rgba_error = rgba_quantization_error + rgb_range_error + alpha_range_error;534best_error[i][3] = full_hdr_rgba_error;535format_of_choice[i][3] = static_cast<uint8_t>(encode_hdr_alpha ? FMT_HDR_RGBA : FMT_HDR_RGB_LDR_ALPHA);536537// For 6 integers, we have one HDR-RGB encoding538float full_hdr_rgb_error = (rgb_quantization_error * mode11mult) + rgb_range_error + eci.alpha_drop_error;539best_error[i][2] = full_hdr_rgb_error;540format_of_choice[i][2] = FMT_HDR_RGB;541542// For 4 integers, we have one HDR-RGB-Scale encoding543float hdr_rgb_scale_error = (rgb_quantization_error * mode7mult) + rgb_range_error + eci.alpha_drop_error + eci.rgb_luma_error;544545best_error[i][1] = hdr_rgb_scale_error;546format_of_choice[i][1] = FMT_HDR_RGB_SCALE;547548// For 2 integers, we assume luminance-with-large-range549float hdr_luminance_error = (rgb_quantization_error * mode23mult) + rgb_range_error + eci.alpha_drop_error + eci.luminance_error;550best_error[i][0] = hdr_luminance_error;551format_of_choice[i][0] = FMT_HDR_LUMINANCE_LARGE_RANGE;552}553}554else555{556for (int i = QUANT_2; i < QUANT_6; i++)557{558best_error[i][3] = ERROR_CALC_DEFAULT;559best_error[i][2] = ERROR_CALC_DEFAULT;560best_error[i][1] = ERROR_CALC_DEFAULT;561best_error[i][0] = ERROR_CALC_DEFAULT;562563format_of_choice[i][3] = FMT_RGBA;564format_of_choice[i][2] = FMT_RGB;565format_of_choice[i][1] = FMT_RGB_SCALE;566format_of_choice[i][0] = FMT_LUMINANCE;567}568569float base_quant_error_rgb = error_weight_rgbsum * static_cast<float>(partition_size);570float base_quant_error_a = error_weight.lane<3>() * static_cast<float>(partition_size);571float base_quant_error_rgba = base_quant_error_rgb + base_quant_error_a;572573float error_scale_bc_rgba = eci.can_blue_contract ? 0.625f : 1.0f;574float error_scale_oe_rgba = eci.can_offset_encode ? 0.5f : 1.0f;575576float error_scale_bc_rgb = eci.can_blue_contract ? 0.5f : 1.0f;577float error_scale_oe_rgb = eci.can_offset_encode ? 0.25f : 1.0f;578579// Pick among the available LDR endpoint modes580for (int i = QUANT_6; i <= QUANT_256; i++)581{582// Offset encoding not possible at higher quant levels583if (i >= QUANT_192)584{585error_scale_oe_rgba = 1.0f;586error_scale_oe_rgb = 1.0f;587}588589float base_quant_error = baseline_quant_error[i - QUANT_6];590float quant_error_rgb = base_quant_error_rgb * base_quant_error;591float quant_error_rgba = base_quant_error_rgba * base_quant_error;592593// 8 integers can encode as RGBA+RGBA594float full_ldr_rgba_error = quant_error_rgba595* error_scale_bc_rgba596* error_scale_oe_rgba597+ rgb_range_error598+ alpha_range_error;599600best_error[i][3] = full_ldr_rgba_error;601format_of_choice[i][3] = FMT_RGBA;602603// 6 integers can encode as RGB+RGB or RGBS+AA604float full_ldr_rgb_error = quant_error_rgb605* error_scale_bc_rgb606* error_scale_oe_rgb607+ rgb_range_error608+ eci.alpha_drop_error;609610float rgbs_alpha_error = quant_error_rgba611+ eci.rgb_scale_error612+ rgb_range_error613+ alpha_range_error;614615if (rgbs_alpha_error < full_ldr_rgb_error)616{617best_error[i][2] = rgbs_alpha_error;618format_of_choice[i][2] = FMT_RGB_SCALE_ALPHA;619}620else621{622best_error[i][2] = full_ldr_rgb_error;623format_of_choice[i][2] = FMT_RGB;624}625626// 4 integers can encode as RGBS or LA+LA627float ldr_rgbs_error = quant_error_rgb628+ rgb_range_error629+ eci.alpha_drop_error630+ eci.rgb_scale_error;631632float lum_alpha_error = quant_error_rgba633+ rgb_range_error634+ alpha_range_error635+ eci.luminance_error;636637if (ldr_rgbs_error < lum_alpha_error)638{639best_error[i][1] = ldr_rgbs_error;640format_of_choice[i][1] = FMT_RGB_SCALE;641}642else643{644best_error[i][1] = lum_alpha_error;645format_of_choice[i][1] = FMT_LUMINANCE_ALPHA;646}647648// 2 integers can encode as L+L649float luminance_error = quant_error_rgb650+ rgb_range_error651+ eci.alpha_drop_error652+ eci.luminance_error;653654best_error[i][0] = luminance_error;655format_of_choice[i][0] = FMT_LUMINANCE;656}657}658}659660/**661* @brief For one partition compute the best format and quantization for a given bit count.662*663* @param best_combined_error The best error for each quant level and integer count.664* @param best_combined_format The best format for each quant level and integer count.665* @param bits_available The number of bits available for encoding.666* @param[out] best_quant_level The output best color quant level.667* @param[out] best_format The output best color format.668*669* @return The output error for the best pairing.670*/671static float one_partition_find_best_combination_for_bitcount(672const float best_combined_error[21][4],673const uint8_t best_combined_format[21][4],674int bits_available,675uint8_t& best_quant_level,676uint8_t& best_format677) {678int best_integer_count = 0;679float best_integer_count_error = ERROR_CALC_DEFAULT;680681for (int integer_count = 1; integer_count <= 4; integer_count++)682{683// Compute the quantization level for a given number of integers and a given number of bits684int quant_level = quant_mode_table[integer_count][bits_available];685686// Don't have enough bits to represent a given endpoint format at all!687if (quant_level < QUANT_6)688{689continue;690}691692float integer_count_error = best_combined_error[quant_level][integer_count - 1];693if (integer_count_error < best_integer_count_error)694{695best_integer_count_error = integer_count_error;696best_integer_count = integer_count - 1;697}698}699700int ql = quant_mode_table[best_integer_count + 1][bits_available];701702best_quant_level = static_cast<uint8_t>(ql);703best_format = FMT_LUMINANCE;704705if (ql >= QUANT_6)706{707best_format = best_combined_format[ql][best_integer_count];708}709710return best_integer_count_error;711}712713/**714* @brief For 2 partitions compute the best format combinations for every pair of quant mode and integer count.715*716* @param best_error The best error for a single endpoint quant level and integer count.717* @param best_format The best format for a single endpoint quant level and integer count.718* @param[out] best_combined_error The best combined error pairings for the 2 partitions.719* @param[out] best_combined_format The best combined format pairings for the 2 partitions.720*/721static void two_partitions_find_best_combination_for_every_quantization_and_integer_count(722const float best_error[2][21][4], // indexed by (partition, quant-level, integer-pair-count-minus-1)723const uint8_t best_format[2][21][4],724float best_combined_error[21][7], // indexed by (quant-level, integer-pair-count-minus-2)725uint8_t best_combined_format[21][7][2]726) {727for (int i = QUANT_2; i <= QUANT_256; i++)728{729for (int j = 0; j < 7; j++)730{731best_combined_error[i][j] = ERROR_CALC_DEFAULT;732}733}734735for (int quant = QUANT_6; quant <= QUANT_256; quant++)736{737for (int i = 0; i < 4; i++) // integer-count for first endpoint-pair738{739for (int j = 0; j < 4; j++) // integer-count for second endpoint-pair740{741int low2 = astc::min(i, j);742int high2 = astc::max(i, j);743if ((high2 - low2) > 1)744{745continue;746}747748int intcnt = i + j;749float errorterm = astc::min(best_error[0][quant][i] + best_error[1][quant][j], 1e10f);750if (errorterm <= best_combined_error[quant][intcnt])751{752best_combined_error[quant][intcnt] = errorterm;753best_combined_format[quant][intcnt][0] = best_format[0][quant][i];754best_combined_format[quant][intcnt][1] = best_format[1][quant][j];755}756}757}758}759}760761/**762* @brief For 2 partitions compute the best format and quantization for a given bit count.763*764* @param best_combined_error The best error for each quant level and integer count.765* @param best_combined_format The best format for each quant level and integer count.766* @param bits_available The number of bits available for encoding.767* @param[out] best_quant_level The output best color quant level.768* @param[out] best_quant_level_mod The output best color quant level assuming two more bits are available.769* @param[out] best_formats The output best color formats.770*771* @return The output error for the best pairing.772*/773static float two_partitions_find_best_combination_for_bitcount(774float best_combined_error[21][7],775uint8_t best_combined_format[21][7][2],776int bits_available,777uint8_t& best_quant_level,778uint8_t& best_quant_level_mod,779uint8_t* best_formats780) {781int best_integer_count = 0;782float best_integer_count_error = ERROR_CALC_DEFAULT;783784for (int integer_count = 2; integer_count <= 8; integer_count++)785{786// Compute the quantization level for a given number of integers and a given number of bits787int quant_level = quant_mode_table[integer_count][bits_available];788789// Don't have enough bits to represent a given endpoint format at all!790if (quant_level < QUANT_6)791{792break;793}794795float integer_count_error = best_combined_error[quant_level][integer_count - 2];796if (integer_count_error < best_integer_count_error)797{798best_integer_count_error = integer_count_error;799best_integer_count = integer_count;800}801}802803int ql = quant_mode_table[best_integer_count][bits_available];804int ql_mod = quant_mode_table[best_integer_count][bits_available + 2];805806best_quant_level = static_cast<uint8_t>(ql);807best_quant_level_mod = static_cast<uint8_t>(ql_mod);808809if (ql >= QUANT_6)810{811for (int i = 0; i < 2; i++)812{813best_formats[i] = best_combined_format[ql][best_integer_count - 2][i];814}815}816else817{818for (int i = 0; i < 2; i++)819{820best_formats[i] = FMT_LUMINANCE;821}822}823824return best_integer_count_error;825}826827/**828* @brief For 3 partitions compute the best format combinations for every pair of quant mode and integer count.829*830* @param best_error The best error for a single endpoint quant level and integer count.831* @param best_format The best format for a single endpoint quant level and integer count.832* @param[out] best_combined_error The best combined error pairings for the 3 partitions.833* @param[out] best_combined_format The best combined format pairings for the 3 partitions.834*/835static void three_partitions_find_best_combination_for_every_quantization_and_integer_count(836const float best_error[3][21][4], // indexed by (partition, quant-level, integer-count)837const uint8_t best_format[3][21][4],838float best_combined_error[21][10],839uint8_t best_combined_format[21][10][3]840) {841for (int i = QUANT_2; i <= QUANT_256; i++)842{843for (int j = 0; j < 10; j++)844{845best_combined_error[i][j] = ERROR_CALC_DEFAULT;846}847}848849for (int quant = QUANT_6; quant <= QUANT_256; quant++)850{851for (int i = 0; i < 4; i++) // integer-count for first endpoint-pair852{853for (int j = 0; j < 4; j++) // integer-count for second endpoint-pair854{855int low2 = astc::min(i, j);856int high2 = astc::max(i, j);857if ((high2 - low2) > 1)858{859continue;860}861862for (int k = 0; k < 4; k++) // integer-count for third endpoint-pair863{864int low3 = astc::min(k, low2);865int high3 = astc::max(k, high2);866if ((high3 - low3) > 1)867{868continue;869}870871int intcnt = i + j + k;872float errorterm = astc::min(best_error[0][quant][i] + best_error[1][quant][j] + best_error[2][quant][k], 1e10f);873if (errorterm <= best_combined_error[quant][intcnt])874{875best_combined_error[quant][intcnt] = errorterm;876best_combined_format[quant][intcnt][0] = best_format[0][quant][i];877best_combined_format[quant][intcnt][1] = best_format[1][quant][j];878best_combined_format[quant][intcnt][2] = best_format[2][quant][k];879}880}881}882}883}884}885886/**887* @brief For 3 partitions compute the best format and quantization for a given bit count.888*889* @param best_combined_error The best error for each quant level and integer count.890* @param best_combined_format The best format for each quant level and integer count.891* @param bits_available The number of bits available for encoding.892* @param[out] best_quant_level The output best color quant level.893* @param[out] best_quant_level_mod The output best color quant level assuming two more bits are available.894* @param[out] best_formats The output best color formats.895*896* @return The output error for the best pairing.897*/898static float three_partitions_find_best_combination_for_bitcount(899const float best_combined_error[21][10],900const uint8_t best_combined_format[21][10][3],901int bits_available,902uint8_t& best_quant_level,903uint8_t& best_quant_level_mod,904uint8_t* best_formats905) {906int best_integer_count = 0;907float best_integer_count_error = ERROR_CALC_DEFAULT;908909for (int integer_count = 3; integer_count <= 9; integer_count++)910{911// Compute the quantization level for a given number of integers and a given number of bits912int quant_level = quant_mode_table[integer_count][bits_available];913914// Don't have enough bits to represent a given endpoint format at all!915if (quant_level < QUANT_6)916{917break;918}919920float integer_count_error = best_combined_error[quant_level][integer_count - 3];921if (integer_count_error < best_integer_count_error)922{923best_integer_count_error = integer_count_error;924best_integer_count = integer_count;925}926}927928int ql = quant_mode_table[best_integer_count][bits_available];929int ql_mod = quant_mode_table[best_integer_count][bits_available + 5];930931best_quant_level = static_cast<uint8_t>(ql);932best_quant_level_mod = static_cast<uint8_t>(ql_mod);933934if (ql >= QUANT_6)935{936for (int i = 0; i < 3; i++)937{938best_formats[i] = best_combined_format[ql][best_integer_count - 3][i];939}940}941else942{943for (int i = 0; i < 3; i++)944{945best_formats[i] = FMT_LUMINANCE;946}947}948949return best_integer_count_error;950}951952/**953* @brief For 4 partitions compute the best format combinations for every pair of quant mode and integer count.954*955* @param best_error The best error for a single endpoint quant level and integer count.956* @param best_format The best format for a single endpoint quant level and integer count.957* @param[out] best_combined_error The best combined error pairings for the 4 partitions.958* @param[out] best_combined_format The best combined format pairings for the 4 partitions.959*/960static void four_partitions_find_best_combination_for_every_quantization_and_integer_count(961const float best_error[4][21][4], // indexed by (partition, quant-level, integer-count)962const uint8_t best_format[4][21][4],963float best_combined_error[21][13],964uint8_t best_combined_format[21][13][4]965) {966for (int i = QUANT_2; i <= QUANT_256; i++)967{968for (int j = 0; j < 13; j++)969{970best_combined_error[i][j] = ERROR_CALC_DEFAULT;971}972}973974for (int quant = QUANT_6; quant <= QUANT_256; quant++)975{976for (int i = 0; i < 4; i++) // integer-count for first endpoint-pair977{978for (int j = 0; j < 4; j++) // integer-count for second endpoint-pair979{980int low2 = astc::min(i, j);981int high2 = astc::max(i, j);982if ((high2 - low2) > 1)983{984continue;985}986987for (int k = 0; k < 4; k++) // integer-count for third endpoint-pair988{989int low3 = astc::min(k, low2);990int high3 = astc::max(k, high2);991if ((high3 - low3) > 1)992{993continue;994}995996for (int l = 0; l < 4; l++) // integer-count for fourth endpoint-pair997{998int low4 = astc::min(l, low3);999int high4 = astc::max(l, high3);1000if ((high4 - low4) > 1)1001{1002continue;1003}10041005int intcnt = i + j + k + l;1006float errorterm = astc::min(best_error[0][quant][i] + best_error[1][quant][j] + best_error[2][quant][k] + best_error[3][quant][l], 1e10f);1007if (errorterm <= best_combined_error[quant][intcnt])1008{1009best_combined_error[quant][intcnt] = errorterm;1010best_combined_format[quant][intcnt][0] = best_format[0][quant][i];1011best_combined_format[quant][intcnt][1] = best_format[1][quant][j];1012best_combined_format[quant][intcnt][2] = best_format[2][quant][k];1013best_combined_format[quant][intcnt][3] = best_format[3][quant][l];1014}1015}1016}1017}1018}1019}1020}10211022/**1023* @brief For 4 partitions compute the best format and quantization for a given bit count.1024*1025* @param best_combined_error The best error for each quant level and integer count.1026* @param best_combined_format The best format for each quant level and integer count.1027* @param bits_available The number of bits available for encoding.1028* @param[out] best_quant_level The output best color quant level.1029* @param[out] best_quant_level_mod The output best color quant level assuming two more bits are available.1030* @param[out] best_formats The output best color formats.1031*1032* @return best_error The output error for the best pairing.1033*/1034static float four_partitions_find_best_combination_for_bitcount(1035const float best_combined_error[21][13],1036const uint8_t best_combined_format[21][13][4],1037int bits_available,1038uint8_t& best_quant_level,1039uint8_t& best_quant_level_mod,1040uint8_t* best_formats1041) {1042int best_integer_count = 0;1043float best_integer_count_error = ERROR_CALC_DEFAULT;10441045for (int integer_count = 4; integer_count <= 9; integer_count++)1046{1047// Compute the quantization level for a given number of integers and a given number of bits1048int quant_level = quant_mode_table[integer_count][bits_available];10491050// Don't have enough bits to represent a given endpoint format at all!1051if (quant_level < QUANT_6)1052{1053break;1054}10551056float integer_count_error = best_combined_error[quant_level][integer_count - 4];1057if (integer_count_error < best_integer_count_error)1058{1059best_integer_count_error = integer_count_error;1060best_integer_count = integer_count;1061}1062}10631064int ql = quant_mode_table[best_integer_count][bits_available];1065int ql_mod = quant_mode_table[best_integer_count][bits_available + 8];10661067best_quant_level = static_cast<uint8_t>(ql);1068best_quant_level_mod = static_cast<uint8_t>(ql_mod);10691070if (ql >= QUANT_6)1071{1072for (int i = 0; i < 4; i++)1073{1074best_formats[i] = best_combined_format[ql][best_integer_count - 4][i];1075}1076}1077else1078{1079for (int i = 0; i < 4; i++)1080{1081best_formats[i] = FMT_LUMINANCE;1082}1083}10841085return best_integer_count_error;1086}10871088/* See header for documentation. */1089unsigned int compute_ideal_endpoint_formats(1090const partition_info& pi,1091const image_block& blk,1092const endpoints& ep,1093// bitcounts and errors computed for the various quantization methods1094const int8_t* qwt_bitcounts,1095const float* qwt_errors,1096unsigned int tune_candidate_limit,1097unsigned int start_block_mode,1098unsigned int end_block_mode,1099// output data1100uint8_t partition_format_specifiers[TUNE_MAX_TRIAL_CANDIDATES][BLOCK_MAX_PARTITIONS],1101int block_mode[TUNE_MAX_TRIAL_CANDIDATES],1102quant_method quant_level[TUNE_MAX_TRIAL_CANDIDATES],1103quant_method quant_level_mod[TUNE_MAX_TRIAL_CANDIDATES],1104compression_working_buffers& tmpbuf1105) {1106int partition_count = pi.partition_count;11071108promise(partition_count > 0);11091110bool encode_hdr_rgb = static_cast<bool>(blk.rgb_lns[0]);1111bool encode_hdr_alpha = static_cast<bool>(blk.alpha_lns[0]);11121113// Compute the errors that result from various encoding choices (such as using luminance instead1114// of RGB, discarding Alpha, using RGB-scale in place of two separate RGB endpoints and so on)1115encoding_choice_errors eci[BLOCK_MAX_PARTITIONS];1116compute_encoding_choice_errors(blk, pi, ep, eci);11171118float best_error[BLOCK_MAX_PARTITIONS][21][4];1119uint8_t format_of_choice[BLOCK_MAX_PARTITIONS][21][4];1120for (int i = 0; i < partition_count; i++)1121{1122compute_color_error_for_every_integer_count_and_quant_level(1123encode_hdr_rgb, encode_hdr_alpha, i,1124pi, eci[i], ep, blk.channel_weight, best_error[i],1125format_of_choice[i]);1126}11271128float* errors_of_best_combination = tmpbuf.errors_of_best_combination;1129uint8_t* best_quant_levels = tmpbuf.best_quant_levels;1130uint8_t* best_quant_levels_mod = tmpbuf.best_quant_levels_mod;1131uint8_t (&best_ep_formats)[WEIGHTS_MAX_BLOCK_MODES][BLOCK_MAX_PARTITIONS] = tmpbuf.best_ep_formats;11321133// Ensure that the first iteration understep contains data that will never be picked1134vfloat clear_error(ERROR_CALC_DEFAULT);1135vint clear_quant(0);11361137size_t packed_start_block_mode = round_down_to_simd_multiple_vla(start_block_mode);1138storea(clear_error, errors_of_best_combination + packed_start_block_mode);1139store_nbytes(clear_quant, best_quant_levels + packed_start_block_mode);1140store_nbytes(clear_quant, best_quant_levels_mod + packed_start_block_mode);11411142// Ensure that last iteration overstep contains data that will never be picked1143size_t packed_end_block_mode = round_down_to_simd_multiple_vla(end_block_mode - 1);1144storea(clear_error, errors_of_best_combination + packed_end_block_mode);1145store_nbytes(clear_quant, best_quant_levels + packed_end_block_mode);1146store_nbytes(clear_quant, best_quant_levels_mod + packed_end_block_mode);11471148// Track a scalar best to avoid expensive search at least once ...1149float error_of_best_combination = ERROR_CALC_DEFAULT;1150int index_of_best_combination = -1;11511152// The block contains 1 partition1153if (partition_count == 1)1154{1155for (unsigned int i = start_block_mode; i < end_block_mode; i++)1156{1157if (qwt_errors[i] >= ERROR_CALC_DEFAULT)1158{1159errors_of_best_combination[i] = ERROR_CALC_DEFAULT;1160continue;1161}11621163float error_of_best = one_partition_find_best_combination_for_bitcount(1164best_error[0], format_of_choice[0], qwt_bitcounts[i],1165best_quant_levels[i], best_ep_formats[i][0]);11661167float total_error = error_of_best + qwt_errors[i];1168errors_of_best_combination[i] = total_error;1169best_quant_levels_mod[i] = best_quant_levels[i];11701171if (total_error < error_of_best_combination)1172{1173error_of_best_combination = total_error;1174index_of_best_combination = i;1175}1176}1177}1178// The block contains 2 partitions1179else if (partition_count == 2)1180{1181float combined_best_error[21][7];1182uint8_t formats_of_choice[21][7][2];11831184two_partitions_find_best_combination_for_every_quantization_and_integer_count(1185best_error, format_of_choice, combined_best_error, formats_of_choice);11861187assert(start_block_mode == 0);1188for (unsigned int i = 0; i < end_block_mode; i++)1189{1190if (qwt_errors[i] >= ERROR_CALC_DEFAULT)1191{1192errors_of_best_combination[i] = ERROR_CALC_DEFAULT;1193continue;1194}11951196float error_of_best = two_partitions_find_best_combination_for_bitcount(1197combined_best_error, formats_of_choice, qwt_bitcounts[i],1198best_quant_levels[i], best_quant_levels_mod[i],1199best_ep_formats[i]);12001201float total_error = error_of_best + qwt_errors[i];1202errors_of_best_combination[i] = total_error;12031204if (total_error < error_of_best_combination)1205{1206error_of_best_combination = total_error;1207index_of_best_combination = i;1208}1209}1210}1211// The block contains 3 partitions1212else if (partition_count == 3)1213{1214float combined_best_error[21][10];1215uint8_t formats_of_choice[21][10][3];12161217three_partitions_find_best_combination_for_every_quantization_and_integer_count(1218best_error, format_of_choice, combined_best_error, formats_of_choice);12191220assert(start_block_mode == 0);1221for (unsigned int i = 0; i < end_block_mode; i++)1222{1223if (qwt_errors[i] >= ERROR_CALC_DEFAULT)1224{1225errors_of_best_combination[i] = ERROR_CALC_DEFAULT;1226continue;1227}12281229float error_of_best = three_partitions_find_best_combination_for_bitcount(1230combined_best_error, formats_of_choice, qwt_bitcounts[i],1231best_quant_levels[i], best_quant_levels_mod[i],1232best_ep_formats[i]);12331234float total_error = error_of_best + qwt_errors[i];1235errors_of_best_combination[i] = total_error;12361237if (total_error < error_of_best_combination)1238{1239error_of_best_combination = total_error;1240index_of_best_combination = i;1241}1242}1243}1244// The block contains 4 partitions1245else // if (partition_count == 4)1246{1247assert(partition_count == 4);1248float combined_best_error[21][13];1249uint8_t formats_of_choice[21][13][4];12501251four_partitions_find_best_combination_for_every_quantization_and_integer_count(1252best_error, format_of_choice, combined_best_error, formats_of_choice);12531254assert(start_block_mode == 0);1255for (unsigned int i = 0; i < end_block_mode; i++)1256{1257if (qwt_errors[i] >= ERROR_CALC_DEFAULT)1258{1259errors_of_best_combination[i] = ERROR_CALC_DEFAULT;1260continue;1261}12621263float error_of_best = four_partitions_find_best_combination_for_bitcount(1264combined_best_error, formats_of_choice, qwt_bitcounts[i],1265best_quant_levels[i], best_quant_levels_mod[i],1266best_ep_formats[i]);12671268float total_error = error_of_best + qwt_errors[i];1269errors_of_best_combination[i] = total_error;12701271if (total_error < error_of_best_combination)1272{1273error_of_best_combination = total_error;1274index_of_best_combination = i;1275}1276}1277}12781279int best_error_weights[TUNE_MAX_TRIAL_CANDIDATES];12801281// Fast path the first result and avoid the list search for trial 01282best_error_weights[0] = index_of_best_combination;1283if (index_of_best_combination >= 0)1284{1285errors_of_best_combination[index_of_best_combination] = ERROR_CALC_DEFAULT;1286}12871288// Search the remaining results and pick the best candidate modes for trial 1+1289for (unsigned int i = 1; i < tune_candidate_limit; i++)1290{1291vint vbest_error_index(-1);1292vfloat vbest_ep_error(ERROR_CALC_DEFAULT);12931294// TODO: This should use size_t for the inputs of start/end_block_mode1295// to avoid some of this type conversion, but that propagates and will1296// need a bigger PR to fix1297size_t start_mode = round_down_to_simd_multiple_vla(start_block_mode);1298vint lane_ids = vint::lane_id() + vint_from_size(start_mode);1299for (size_t j = start_mode; j < end_block_mode; j += ASTCENC_SIMD_WIDTH)1300{1301vfloat err = vfloat(errors_of_best_combination + j);1302vmask mask = err < vbest_ep_error;1303vbest_ep_error = select(vbest_ep_error, err, mask);1304vbest_error_index = select(vbest_error_index, lane_ids, mask);1305lane_ids += vint(ASTCENC_SIMD_WIDTH);1306}13071308// Pick best mode from the SIMD result, using lowest matching index to ensure invariance1309vmask lanes_min_error = vbest_ep_error == hmin(vbest_ep_error);1310vbest_error_index = select(vint(0x7FFFFFFF), vbest_error_index, lanes_min_error);13111312int best_error_index = hmin_s(vbest_error_index);13131314best_error_weights[i] = best_error_index;13151316// Max the error for this candidate so we don't pick it again1317if (best_error_index >= 0)1318{1319errors_of_best_combination[best_error_index] = ERROR_CALC_DEFAULT;1320}1321// Early-out if no more candidates are valid1322else1323{1324break;1325}1326}13271328for (unsigned int i = 0; i < tune_candidate_limit; i++)1329{1330if (best_error_weights[i] < 0)1331{1332return i;1333}13341335block_mode[i] = best_error_weights[i];13361337quant_level[i] = static_cast<quant_method>(best_quant_levels[best_error_weights[i]]);1338quant_level_mod[i] = static_cast<quant_method>(best_quant_levels_mod[best_error_weights[i]]);13391340assert(quant_level[i] >= QUANT_6 && quant_level[i] <= QUANT_256);1341assert(quant_level_mod[i] >= QUANT_6 && quant_level_mod[i] <= QUANT_256);13421343for (int j = 0; j < partition_count; j++)1344{1345partition_format_specifiers[i][j] = best_ep_formats[best_error_weights[i]][j];1346}1347}13481349return tune_candidate_limit;1350}13511352#endif135313541355