See header for documentation. */
| 343 | |
| 344 | /* See header for documentation. */ |
| 345 | void store_image_block( |
| 346 | astcenc_image& img, |
| 347 | const image_block& blk, |
| 348 | const block_size_descriptor& bsd, |
| 349 | size_t pos_x, |
| 350 | size_t pos_y, |
| 351 | size_t pos_z, |
| 352 | const astcenc_swizzle& swz |
| 353 | ) { |
| 354 | size_t size_x = img.dim_x; |
| 355 | size_t start_x = pos_x; |
| 356 | size_t end_x = astc::min(size_x, pos_x + bsd.dim_x); |
| 357 | size_t count_x = end_x - start_x; |
| 358 | size_t nudge_x = bsd.dim_x - count_x; |
| 359 | |
| 360 | size_t size_y = img.dim_y; |
| 361 | size_t start_y = pos_y; |
| 362 | size_t end_y = astc::min(size_y, pos_y + bsd.dim_y); |
| 363 | size_t count_y = end_y - start_y; |
| 364 | size_t nudge_y = (bsd.dim_y - count_y) * bsd.dim_x; |
| 365 | |
| 366 | size_t size_z = img.dim_z; |
| 367 | size_t start_z = pos_z; |
| 368 | size_t end_z = astc::min(size_z, pos_z + bsd.dim_z); |
| 369 | |
| 370 | size_t idx = 0; |
| 371 | |
| 372 | // True if any non-identity swizzle |
| 373 | bool needs_swz = (swz.r != ASTCENC_SWZ_R) || (swz.g != ASTCENC_SWZ_G) || |
| 374 | (swz.b != ASTCENC_SWZ_B) || (swz.a != ASTCENC_SWZ_A); |
| 375 | |
| 376 | // True if any swizzle uses Z reconstruct |
| 377 | bool needs_z = (swz.r == ASTCENC_SWZ_Z) || (swz.g == ASTCENC_SWZ_Z) || |
| 378 | (swz.b == ASTCENC_SWZ_Z) || (swz.a == ASTCENC_SWZ_Z); |
| 379 | |
| 380 | if (img.data_type == ASTCENC_TYPE_U8) |
| 381 | { |
| 382 | for (size_t z = start_z; z < end_z; z++) |
| 383 | { |
| 384 | // Fetch the image plane |
| 385 | uint8_t* data8 = static_cast<uint8_t*>(img.data[z]); |
| 386 | |
| 387 | for (size_t y = start_y; y < end_y; y++) |
| 388 | { |
| 389 | uint8_t* data8_row = data8 + (4 * size_x * y) + (4 * start_x); |
| 390 | |
| 391 | for (size_t x = 0; x < count_x; x += ASTCENC_SIMD_WIDTH) |
| 392 | { |
| 393 | size_t max_texels = ASTCENC_SIMD_WIDTH; |
| 394 | size_t used_texels = astc::min(count_x - x, max_texels); |
| 395 | |
| 396 | // Unaligned load as rows are not always SIMD_WIDTH long |
| 397 | vfloat data_r(blk.data_r + idx); |
| 398 | vfloat data_g(blk.data_g + idx); |
| 399 | vfloat data_b(blk.data_b + idx); |
| 400 | vfloat data_a(blk.data_a + idx); |
| 401 | |
| 402 | // Clamp values to [0.0, 1.0] range before unorm conversion |
no test coverage detected