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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
|
// SPDX-License-Identifier: Apache-2.0
// ----------------------------------------------------------------------------
// Copyright 2011-2021 Arm Limited
//
// 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.
// ----------------------------------------------------------------------------
/**
* @brief Functions and data declarations.
*/
#ifndef ASTCENCCLI_INTERNAL_INCLUDED
#define ASTCENCCLI_INTERNAL_INCLUDED
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include "astcenc.h"
#include "astcenc_mathlib.h"
/**
* @brief The payload stored in a compressed ASTC image.
*/
struct astc_compressed_image
{
/** @brief The block width in texels. */
unsigned int block_x;
/** @brief The block height in texels. */
unsigned int block_y;
/** @brief The block depth in texels. */
unsigned int block_z;
/** @brief The image width in texels. */
unsigned int dim_x;
/** @brief The image height in texels. */
unsigned int dim_y;
/** @brief The image depth in texels. */
unsigned int dim_z;
/** @brief The binary data payload. */
uint8_t* data;
/** @brief The binary data length in bytes. */
size_t data_len;
};
/**
* @brief Config options that have been read from command line.
*/
struct cli_config_options
{
/** @brief The number of threads to use for processing. */
unsigned int thread_count;
/** @brief The number of repeats to execute for benchmarking. */
unsigned int repeat_count;
/** @brief The number of image slices to load for a 3D image. */
unsigned int array_size;
/** @brief @c true if running in silent mode with minimal output. */
bool silentmode;
/** @brief @c true if the images should be y-flipped. */
bool y_flip;
/** @brief @c true if diagnostic images should be stored. */
bool diagnostic_images;
/** @brief The low exposure fstop for error computation. */
int low_fstop;
/** @brief The high exposure fstop for error computation. */
int high_fstop;
/** @brief The pre-encode swizzle. */
astcenc_swizzle swz_encode;
/** @brief The post-decode swizzle. */
astcenc_swizzle swz_decode;
};
/**
* @brief Load uncompressed image.
*
* @param filename The file path on disk.
* @param y_flip Should this image be Y flipped?
* @param[out] is_hdr Is the loaded image HDR?
* @param[out] component_count The number of components in the loaded image.
*
* @return The astc image file, or nullptr on error.
*/
astcenc_image* load_ncimage(
const char* filename,
bool y_flip,
bool& is_hdr,
unsigned int& component_count);
/**
* @brief Load uncompressed PNG image.
*
* @param filename The file path on disk.
* @param y_flip Should this image be Y flipped?
* @param[out] is_hdr Is the loaded image HDR?
* @param[out] component_count The number of components in the loaded image.
*
* @return The astc image file, or nullptr on error.
*/
astcenc_image* load_png_with_wuffs(
const char* filename,
bool y_flip,
bool& is_hdr,
unsigned int& component_count);
/**
* @brief Save an uncompressed image.
*
* @param img The source data for the image.
* @param filename The name of the file to save.
* @param y_flip Should the image be vertically flipped?
*
* @return @c true if the image saved OK, @c false on error.
*/
bool store_ncimage(
const astcenc_image* img,
const char* filename,
int y_flip);
/**
* @brief Check if the output file type requires a specific bitness.
*
* @param filename The file name, containing hte extension to check.
*
* @return Valid values are:
* * -1 - error - unknown file type.
* * 0 - no enforced bitness.
* * 8 - enforced 8-bit UNORM.
* * 16 - enforced 16-bit FP16.
*/
int get_output_filename_enforced_bitness(
const char* filename);
/**
* @brief Allocate a new image in a canonical format.
*
* Allocated images must be freed with a @c free_image() call.
*
* @param bitness The number of bits per component (8, 16, or 32).
* @param dim_x The width of the image, in texels.
* @param dim_y The height of the image, in texels.
* @param dim_z The depth of the image, in texels.
*
* @return The allocated image, or @c nullptr on error.
*/
astcenc_image* alloc_image(
unsigned int bitness,
unsigned int dim_x,
unsigned int dim_y,
unsigned int dim_z);
/**
* @brief Free an image.
*
* @param img The image to free.
*/
void free_image(
astcenc_image* img);
/**
* @brief Determine the number of active components in an image.
*
* @param img The image to analyze.
*
* @return The number of active components in the image.
*/
int determine_image_components(
const astcenc_image* img);
/**
* @brief Load a compressed .astc image.
*
* @param filename The file to load.
* @param img The image to populate with loaded data.
*
* @return Non-zero on error, zero on success.
*/
int load_cimage(
const char* filename,
astc_compressed_image& img);
/**
* @brief Store a compressed .astc image.
*
* @param img The image to store.
* @param filename The file to save.
*
* @return Non-zero on error, zero on success.
*/
int store_cimage(
const astc_compressed_image& img,
const char* filename);
/**
* @brief Load a compressed .ktx image.
*
* @param filename The file to load.
* @param is_srgb Is this an sRGB encoded file?
* @param img The image to populate with loaded data.
*
* @return Non-zero on error, zero on success.
*/
bool load_ktx_compressed_image(
const char* filename,
bool& is_srgb,
astc_compressed_image& img) ;
/**
* @brief Store a compressed .ktx image.
*
* @param img The image to store.
* @param filename The file to store.
* @param is_srgb Is this an sRGB encoded file?
*
* @return Non-zero on error, zero on success.
*/
bool store_ktx_compressed_image(
const astc_compressed_image& img,
const char* filename,
bool is_srgb);
/**
* @brief Create an image from a 2D float data array.
*
* @param data The raw input data.
* @param dim_x The width of the image, in texels.
* @param dim_y The height of the image, in texels.
* @param y_flip Should this image be vertically flipped?
*
* @return The populated image.
*/
astcenc_image* astc_img_from_floatx4_array(
const float* data,
unsigned int dim_x,
unsigned int dim_y,
bool y_flip);
/**
* @brief Create an image from a 2D byte data array.
*
* @param data The raw input data.
* @param dim_x The width of the image, in texels.
* @param dim_y The height of the image, in texels.
* @param y_flip Should this image be vertically flipped?
*
* @return The populated image.
*/
astcenc_image* astc_img_from_unorm8x4_array(
const uint8_t* data,
unsigned int dim_x,
unsigned int dim_y,
bool y_flip);
/**
* @brief Create a flattened RGBA FLOAT32 data array from an image structure.
*
* The returned data array is allocated with @c new[] and must be freed with a @c delete[] call.
*
* @param img The input image.
* @param y_flip Should the data in the array be Y flipped?
*
* @return The data array.
*/
float* floatx4_array_from_astc_img(
const astcenc_image* img,
bool y_flip);
/**
* @brief Create a flattened RGBA UNORM8 data array from an image structure.
*
* The returned data array is allocated with @c new[] and must be freed with a @c delete[] call.
*
* @param img The input image.
* @param y_flip Should the data in the array be Y flipped?
*
* @return The data array.
*/
uint8_t* unorm8x4_array_from_astc_img(
const astcenc_image* img,
bool y_flip);
/* ============================================================================
Functions for printing build info and help messages
============================================================================ */
/**
* @brief Print the tool copyright and version header to stdout.
*/
void astcenc_print_header();
/**
* @brief Print the tool copyright, version, and short-form help to stdout.
*/
void astcenc_print_shorthelp();
/**
* @brief Print the tool copyright, version, and long-form help to stdout.
*/
void astcenc_print_longhelp();
/**
* @brief Compute error metrics comparing two images.
*
* @param compute_hdr_metrics True if HDR metrics should be computed.
* @param compute_normal_metrics True if normal map metrics should be computed.
* @param input_components The number of input color components.
* @param img1 The original image.
* @param img2 The compressed image.
* @param fstop_lo The low exposure fstop (HDR only).
* @param fstop_hi The high exposure fstop (HDR only).
*/
void compute_error_metrics(
bool compute_hdr_metrics,
bool compute_normal_metrics,
int input_components,
const astcenc_image* img1,
const astcenc_image* img2,
int fstop_lo,
int fstop_hi);
/**
* @brief Get the current time.
*
* @return The current time in seconds since arbitrary epoch.
*/
double get_time();
/**
* @brief Get the number of CPU cores.
*
* @return The number of online or onlineable CPU cores in the system.
*/
int get_cpu_count();
/**
* @brief Launch N worker threads and wait for them to complete.
*
* All threads run the same thread function, and have the same thread payload, but are given a
* unique thread ID (0 .. N-1) as a parameter to the run function to allow thread-specific behavior.
*
|* @param thread_count The number of threads to spawn.
* @param func The function to execute. Must have the signature:
* void (int thread_count, int thread_id, void* payload)
* @param payload Pointer to an opaque thread payload object.
*/
void launch_threads(
int thread_count,
void (*func)(int, int, void*),
void *payload);
#endif
|