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

Function image_preprocess_normalize

Source/astcenccli_toplevel.cpp:1418–1452  ·  view source on GitHub ↗

* @brief Create a copy of @c input with forced unit-length normal vectors. * * It is assumed that all normal vectors are stored in the RGB components, and * stored in a packed unsigned range of [0,1] which must be unpacked prior * normalization. Data must then be repacked into this form for handing over to * the core codec. * * @param[in] input The input image. * @param[out] output T

Source from the content-addressed store, hash-verified

1416 * @param[out] output The output image, must use F32 components.
1417 */
1418static void image_preprocess_normalize(
1419 const astcenc_image& input,
1420 astcenc_image& output
1421) {
1422 for (unsigned int z = 0; z < input.dim_z; z++)
1423 {
1424 for (unsigned int y = 0; y < input.dim_y; y++)
1425 {
1426 for (unsigned int x = 0; x < input.dim_x; x++)
1427 {
1428 vfloat4 pixel = image_get_pixel(input, x, y, z);
1429
1430 // Stash alpha component and zero
1431 float a = pixel.lane<3>();
1432 pixel.set_lane<3>(0.0f);
1433
1434 // Decode [0,1] normals to [-1,1]
1435 pixel.set_lane<0>((pixel.lane<0>() * 2.0f) - 1.0f);
1436 pixel.set_lane<1>((pixel.lane<1>() * 2.0f) - 1.0f);
1437 pixel.set_lane<2>((pixel.lane<2>() * 2.0f) - 1.0f);
1438
1439 // Normalize pixel and restore alpha
1440 pixel = normalize(pixel);
1441 pixel.set_lane<3>(a);
1442
1443 // Encode [-1,1] normals to [0,1]
1444 pixel.set_lane<0>((pixel.lane<0>() + 1.0f) / 2.0f);
1445 pixel.set_lane<1>((pixel.lane<1>() + 1.0f) / 2.0f);
1446 pixel.set_lane<2>((pixel.lane<2>() + 1.0f) / 2.0f);
1447
1448 image_set_pixel(output, x, y, z, pixel);
1449 }
1450 }
1451 }
1452}
1453
1454/**
1455 * @brief Linearize an sRGB value.

Callers 1

astcenc_mainFunction · 0.85

Calls 3

image_get_pixelFunction · 0.85
normalizeFunction · 0.85
image_set_pixelFunction · 0.85

Tested by

no test coverage detected