* @brief Create a copy of @c input with premultiplied color data. * * If we are compressing sRGB data we linearize the data prior to * premultiplication and re-gamma-encode afterwards. * * @param[in] input The input image. * @param[out] output The output image, must use F32 components. * @param profile The encoding profile. */
| 1494 | * @param profile The encoding profile. |
| 1495 | */ |
| 1496 | static void image_preprocess_premultiply( |
| 1497 | const astcenc_image& input, |
| 1498 | astcenc_image& output, |
| 1499 | astcenc_profile profile |
| 1500 | ) { |
| 1501 | for (unsigned int z = 0; z < input.dim_z; z++) |
| 1502 | { |
| 1503 | for (unsigned int y = 0; y < input.dim_y; y++) |
| 1504 | { |
| 1505 | for (unsigned int x = 0; x < input.dim_x; x++) |
| 1506 | { |
| 1507 | vfloat4 pixel = image_get_pixel(input, x, y, z); |
| 1508 | |
| 1509 | // Linearize sRGB |
| 1510 | if (profile == ASTCENC_PRF_LDR_SRGB) |
| 1511 | { |
| 1512 | pixel.set_lane<0>(srgb_to_linear(pixel.lane<0>())); |
| 1513 | pixel.set_lane<1>(srgb_to_linear(pixel.lane<1>())); |
| 1514 | pixel.set_lane<2>(srgb_to_linear(pixel.lane<2>())); |
| 1515 | } |
| 1516 | |
| 1517 | // Premultiply pixel in linear-space |
| 1518 | pixel.set_lane<0>(pixel.lane<0>() * pixel.lane<3>()); |
| 1519 | pixel.set_lane<1>(pixel.lane<1>() * pixel.lane<3>()); |
| 1520 | pixel.set_lane<2>(pixel.lane<2>() * pixel.lane<3>()); |
| 1521 | |
| 1522 | // Gamma-encode sRGB |
| 1523 | if (profile == ASTCENC_PRF_LDR_SRGB) |
| 1524 | { |
| 1525 | pixel.set_lane<0>(linear_to_srgb(pixel.lane<0>())); |
| 1526 | pixel.set_lane<1>(linear_to_srgb(pixel.lane<1>())); |
| 1527 | pixel.set_lane<2>(linear_to_srgb(pixel.lane<2>())); |
| 1528 | } |
| 1529 | |
| 1530 | image_set_pixel(output, x, y, z, pixel); |
| 1531 | } |
| 1532 | } |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | /** |
| 1537 | * @brief Populate a single diagnostic image showing aspects of the encoding. |
no test coverage detected