| 1488 | } |
| 1489 | |
| 1490 | void CommandCreate::executeCreate() { |
| 1491 | const auto warningFn = [this](const std::string& w) { this->warning(w); }; |
| 1492 | |
| 1493 | KTXTexture2 texture{nullptr}; |
| 1494 | targetChannelCount = options.formatDesc.channelCount(); |
| 1495 | |
| 1496 | ImageSpec target; |
| 1497 | ColorSpaceInfo colorSpaceInfo{}; |
| 1498 | |
| 1499 | bool firstImage = true; |
| 1500 | ImageSpec firstImageSpec{}; |
| 1501 | uint32_t maxLevels = 1; |
| 1502 | |
| 1503 | foreachImage(options.formatDesc, [&]( |
| 1504 | const auto& inputFilepath, |
| 1505 | uint32_t levelIndex, |
| 1506 | uint32_t layerIndex, |
| 1507 | uint32_t faceIndex, |
| 1508 | uint32_t depthSliceIndex) { |
| 1509 | |
| 1510 | if (options.raw) { |
| 1511 | if (std::exchange(firstImage, false)) { |
| 1512 | target = ImageSpec{ |
| 1513 | options.width.value_or(1u), |
| 1514 | options.height.value_or(1u), |
| 1515 | options.depth.value_or(1u), |
| 1516 | options.formatDesc}; |
| 1517 | |
| 1518 | if (options.cubemap && target.width() != target.height()) |
| 1519 | fatal(rc::INVALID_FILE, "--cubemap specified but the input image \"{}\" with size {}x{} is not square.", |
| 1520 | fmtInFile(inputFilepath), target.width(), target.height()); |
| 1521 | |
| 1522 | if (options.assignTF.has_value()) |
| 1523 | target.format().setTransfer(options.assignTF.value()); |
| 1524 | |
| 1525 | if (options.assignPrimaries.has_value()) |
| 1526 | target.format().setPrimaries(options.assignPrimaries.value()); |
| 1527 | |
| 1528 | if (options.assignTexcoordOrigin.has_value()) |
| 1529 | target.setOrigin(options.assignTexcoordOrigin.value()); |
| 1530 | |
| 1531 | texture = createTexture(target); |
| 1532 | } |
| 1533 | |
| 1534 | const auto rawData = readRawFile(inputFilepath); |
| 1535 | |
| 1536 | const auto expectedFileSize = ktxTexture_GetImageSize(texture, levelIndex); |
| 1537 | if (rawData.size() != expectedFileSize) |
| 1538 | fatal(rc::INVALID_FILE, "Raw input file \"{}\" with {} bytes for level {} does not match the expected size of {} bytes.", |
| 1539 | fmtInFile(inputFilepath), rawData.size(), levelIndex, expectedFileSize); |
| 1540 | |
| 1541 | const auto ret = ktxTexture_SetImageFromMemory( |
| 1542 | texture, |
| 1543 | levelIndex, |
| 1544 | layerIndex, |
| 1545 | faceIndex + depthSliceIndex, // Faces and Depths are mutually exclusive, Addition is acceptable |
| 1546 | reinterpret_cast<const ktx_uint8_t*>(rawData.data()), |
| 1547 | rawData.size()); |
nothing calls this directly
no test coverage detected