MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / determineTargetColorSpace

Method determineTargetColorSpace

tools/ktx/command_create.cpp:2757–2804  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2755}
2756
2757void CommandCreate::determineTargetColorSpace(const ImageInput& in, ImageSpec& target, ColorSpaceInfo& colorSpaceInfo) {
2758 // Primaries handling:
2759 //
2760 // 1. Use assign-primaries option value, if set.
2761 // 2. Use primaries info given by plugin.
2762 // 3. If no primaries info and input is PNG use PNG spec.
2763 // recommendation of BT709/sRGB otherwise leave as
2764 // UNSPECIFIED.
2765 // 4. If convert-primaries is specified but no primaries info is
2766 // given by the plugin then fail.
2767 // 5. If convert-primaries is specified and primaries info determined
2768 // above is different then set up conversion.
2769
2770 determineSourceColorSpace(in, colorSpaceInfo.src);
2771
2772 // Set Primaries
2773
2774 // If convert-primaries is specified and primaries info determined
2775 // above is different then set up conversion.
2776 if (options.convertPrimaries.has_value()) {
2777 assert(colorSpaceInfo.src.usedPrimaries != KHR_DF_PRIMARIES_UNSPECIFIED
2778 && "determineSourceColorSpace failed to check for UNSPECIFIED.");
2779 target.format().setPrimaries(options.convertPrimaries.value());
2780 // Okay to set this even if no conversion needed.
2781 colorSpaceInfo.dst.colorPrimaries = createColorPrimaries(target.format().primaries());
2782 } else {
2783 target.format().setPrimaries(colorSpaceInfo.src.usedPrimaries);
2784 }
2785
2786 // target transfer is set from the --format value or --assignTF or --convertTF.
2787 if (options.assignTF.has_value())
2788 target.format().setTransfer(options.assignTF.value());
2789
2790 if (options.convertTF.has_value())
2791 target.format().setTransfer(options.convertTF.value());
2792
2793 switch (target.format().transfer()) {
2794 case KHR_DF_TRANSFER_LINEAR:
2795 colorSpaceInfo.dst.transferFunction = std::make_unique<TransferFunctionLinear>();
2796 break;
2797 case KHR_DF_TRANSFER_SRGB:
2798 colorSpaceInfo.dst.transferFunction = std::make_unique<TransferFunctionSRGB>();
2799 break;
2800 default:
2801 // Lack of will be handled if color transformation attempted.
2802 colorSpaceInfo.dst.transferFunction = nullptr;
2803 }
2804}
2805
2806void CommandCreate::determineSourceOrigin(const ImageInput& in, ImageSpec::Origin& usedSourceOrigin) {
2807

Callers

nothing calls this directly

Calls 8

assertFunction · 0.85
createColorPrimariesFunction · 0.85
setTransferMethod · 0.80
setPrimariesMethod · 0.45
formatMethod · 0.45
valueMethod · 0.45
primariesMethod · 0.45
transferMethod · 0.45

Tested by

no test coverage detected