"colorRGBA" is a four component RGBA floating-point color value if the image channel data type is not an unnormalized signed and unsigned integer type, is a four component signed integer value if the image channel data type is an unnormalized signed integer type and is a four component unsigned integer value if the image channel data type is an unormalized unsigned integer type.
| 1401 | // an unnormalized signed integer type and is a four component unsigned integer |
| 1402 | // value if the image channel data type is an unormalized unsigned integer type. |
| 1403 | void Image::Format::formatColor(const void* colorRGBA, void* colorFormat) const { |
| 1404 | union t565 { |
| 1405 | struct { |
| 1406 | uint16_t r_ : 5; |
| 1407 | uint16_t g_ : 6; |
| 1408 | uint16_t b_ : 5; |
| 1409 | }; |
| 1410 | uint16_t rgba_; |
| 1411 | }; |
| 1412 | |
| 1413 | union t555 { |
| 1414 | struct { |
| 1415 | uint16_t r_ : 5; |
| 1416 | uint16_t g_ : 5; |
| 1417 | uint16_t b_ : 5; |
| 1418 | uint16_t a_ : 1; |
| 1419 | }; |
| 1420 | uint16_t rgba_; |
| 1421 | }; |
| 1422 | |
| 1423 | union t101010 { |
| 1424 | struct { |
| 1425 | uint32_t b_ : 10; |
| 1426 | uint32_t g_ : 10; |
| 1427 | uint32_t r_ : 10; |
| 1428 | uint32_t a_ : 2; |
| 1429 | }; |
| 1430 | uint32_t rgba_; |
| 1431 | }; |
| 1432 | |
| 1433 | const float* colorRGBAf = reinterpret_cast<const float*>(colorRGBA); |
| 1434 | const int32_t* colorRGBAi = reinterpret_cast<const int32_t*>(colorRGBA); |
| 1435 | const uint32_t* colorRGBAui = reinterpret_cast<const uint32_t*>(colorRGBA); |
| 1436 | |
| 1437 | size_t chCount = getNumChannels(); |
| 1438 | uint8_t chOrder[4]; |
| 1439 | getChannelOrder(chOrder); |
| 1440 | |
| 1441 | bool allChannels = false; |
| 1442 | for (size_t i = 0; i < chCount && !allChannels; ++i) { |
| 1443 | switch (image_channel_data_type) { |
| 1444 | case CL_SNORM_INT8: { |
| 1445 | int8_t* color = reinterpret_cast<int8_t*>(colorFormat); |
| 1446 | color[i] = round_to_even(INT8_MAX * colorRGBAf[chOrder[i]]); |
| 1447 | } break; |
| 1448 | case CL_SNORM_INT16: { |
| 1449 | int16_t* color = reinterpret_cast<int16_t*>(colorFormat); |
| 1450 | color[i] = round_to_even(INT16_MAX * colorRGBAf[chOrder[i]]); |
| 1451 | } break; |
| 1452 | case CL_UNORM_INT8: { |
| 1453 | uint8_t* color = reinterpret_cast<uint8_t*>(colorFormat); |
| 1454 | color[i] = round_to_even(UINT8_MAX * colorRGBAf[chOrder[i]]); |
| 1455 | } break; |
| 1456 | case CL_UNORM_INT16: { |
| 1457 | uint16_t* color = reinterpret_cast<uint16_t*>(colorFormat); |
| 1458 | color[i] = round_to_even(UINT16_MAX * colorRGBAf[chOrder[i]]); |
| 1459 | } break; |
| 1460 | case CL_UNORM_SHORT_565: { |
no test coverage detected