@@ -2446,76 +2446,74 @@ void CommandCreate::determineTargetColorSpace(const ImageInput& in, ImageSpec& t
24462446 // 6. Convert transfer function based on convert-tf option value or as
24472447 // described above.
24482448
2449- colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_UNSPECIFIED;
24502449 if (options.assignTF .has_value ()) {
24512450 colorSpaceInfo.usedInputTransferFunction = options.assignTF .value ();
24522451 target.format ().setTransfer (options.assignTF .value ());
24532452 } else {
24542453 // Set image's transfer function as indicated by metadata.
2455- if (spec.format ().transfer () != KHR_DF_TRANSFER_UNSPECIFIED) {
2456- colorSpaceInfo.usedInputTransferFunction = spec.format ().transfer ();
2457- } else if (spec.format ().iccProfileName ().size ()) {
2458- fatal (rc::INVALID_FILE,
2459- " Input file \" {}\" contains unsupported ICC profile \" {}\" . Use --{} to specify a different one." ,
2460- in.filename (), spec.format ().iccProfileName (),
2461- options.kAssignTf );
2462- } else if (spec.format ().oeGamma () > 0 .0f ) {
2463- if (spec.format ().oeGamma () > .45450f && spec.format ().oeGamma () < .45460f ) {
2464- // N.B The previous loader matched oeGamma .45455 to the sRGB
2465- // transfer function and did not do a transformation. In this
2466- // loader we decode and reencode. Previous behavior can be
2467- // obtained with the --assign-tf option.
2468- //
2469- // This change results in 1 bit differences in the LSB of
2470- // some color values noticeable only when directly comparing
2471- // images produced before and after this change of loader.
2472- warning (" Converting gamma 2.2f to sRGB. Use --{} srgb to force treating input as sRGB." ,
2473- options.kAssignTf );
2474- colorSpaceInfo.srcTransferFunction = std::make_unique<TransferFunctionGamma>(spec.format ().oeGamma ());
2475- } else if (spec.format ().oeGamma () == 1.0 ) {
2476- colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_LINEAR;
2454+ colorSpaceInfo.usedInputTransferFunction = spec.format ().transfer ();
2455+ if (spec.format ().transfer () == KHR_DF_TRANSFER_UNSPECIFIED) {
2456+ if (spec.format ().iccProfileName ().size ()) {
2457+ fatal (rc::INVALID_FILE,
2458+ " Input file \" {}\" contains unsupported ICC profile \" {}\" . Use --{} to specify a different one." ,
2459+ in.filename (), spec.format ().iccProfileName (),
2460+ options.kAssignTf );
24772461 } else if (spec.format ().oeGamma () > 0 .0f ) {
2478- // We allow any gamma, there is not really a reason why we could not allow such input
2479- colorSpaceInfo.srcTransferFunction = std::make_unique<TransferFunctionGamma>(spec.format ().oeGamma ());
2480- } else if (spec.format ().oeGamma () == 0 .0f ) {
2481- if (!in.formatName ().compare (" png" )) {
2482- // If 8-bit, treat as sRGB, otherwise treat as linear.
2483- if (spec.format ().channelBitLength () == 8 ) {
2484- colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_SRGB;
2462+ if (spec.format ().oeGamma () > .45450f && spec.format ().oeGamma () < .45460f ) {
2463+ // N.B The previous loader matched oeGamma .45455 to the sRGB
2464+ // transfer function and did not do a transformation. In this
2465+ // loader we decode and reencode. Previous behavior can be
2466+ // obtained with the --assign-tf option.
2467+ //
2468+ // This change results in 1 bit differences in the LSB of
2469+ // some color values noticeable only when directly comparing
2470+ // images produced before and after this change of loader.
2471+ warning (" Converting gamma 2.2f to sRGB. Use --{} srgb to force treating input as sRGB." ,
2472+ options.kAssignTf );
2473+ colorSpaceInfo.srcTransferFunction = std::make_unique<TransferFunctionGamma>(spec.format ().oeGamma ());
2474+ } else if (spec.format ().oeGamma () == 1.0 ) {
2475+ colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_LINEAR;
2476+ } else if (spec.format ().oeGamma () > 0 .0f ) {
2477+ // We allow any gamma, there is no reason why we could not
2478+ // allow such input
2479+ colorSpaceInfo.srcTransferFunction = std::make_unique<TransferFunctionGamma>(spec.format ().oeGamma ());
2480+ } else if (spec.format ().oeGamma () == 0 .0f ) {
2481+ if (!in.formatName ().compare (" png" )) {
2482+ // If 8-bit, treat as sRGB, otherwise treat as linear.
2483+ if (spec.format ().channelBitLength () == 8 ) {
2484+ colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_SRGB;
2485+ } else {
2486+ colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_LINEAR;
2487+ }
2488+ warning (" Ignoring reported gamma of 0.0f in {}-bit PNG input file \" {}\" . Handling as {}." ,
2489+ spec.format ().channelBitLength (), in.filename (), toString (colorSpaceInfo.usedInputTransferFunction ));
24852490 } else {
2486- colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_LINEAR;
2491+ fatal (rc::INVALID_FILE,
2492+ " Input file \" {}\" has gamma 0.0f. Use --{} to specify transfer function." ,
2493+ options.kAssignTf );
24872494 }
2488- warning (" Ignoring reported gamma of 0.0f in {}-bit PNG input file \" {}\" . Handling as {}." ,
2489- spec.format ().channelBitLength (), in.filename (), toString (colorSpaceInfo.usedInputTransferFunction ));
24902495 } else {
2491- fatal (rc::INVALID_FILE,
2492- " Input file \" {}\" has gamma 0.0f. Use --{} to specify transfer function." ,
2493- options.kAssignTf );
2496+ if (!options.convertTF .has_value ()) {
2497+ fatal (rc::INVALID_FILE, " Gamma {} not automatically supported by KTX. Specify handing with "
2498+ " --{} or --{}." , spec.format ().oeGamma (),
2499+ options.kConvertTf , options.kAssignTf );
2500+ }
24942501 }
2495- } else {
2496- if (!options.convertTF .has_value ()) {
2497- fatal (rc::INVALID_FILE, " Gamma {} not automatically supported by KTX. Specify handing with "
2498- " --{} or --{}." , spec.format ().oeGamma (),
2499- options.kConvertTf , options.kAssignTf );
2502+ } else if (!in.formatName ().compare (" png" )) {
2503+ // If 8-bit, treat as sRGB, otherwise treat as linear.
2504+ if (spec.format ().channelBitLength () == 8 ) {
2505+ colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_SRGB;
2506+ } else {
2507+ colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_LINEAR;
25002508 }
2509+ warning (" No transfer function can be determined from {}-bit PNG input file \" {}\" , defaulting to {}. Use --{} to override." ,
2510+ spec.format ().channelBitLength (), in.filename (),
2511+ toString (colorSpaceInfo.usedInputTransferFunction ),
2512+ options.kAssignTf );
25012513 }
2502- } else if (!in.formatName ().compare (" png" )) {
2503- // If 8-bit, treat as sRGB, otherwise treat as linear.
2504- if (spec.format ().channelBitLength () == 8 ) {
2505- colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_SRGB;
2506- } else {
2507- colorSpaceInfo.usedInputTransferFunction = KHR_DF_TRANSFER_LINEAR;
2508- }
2509- warning (" No transfer function can be determined from {}-bit PNG input file \" {}\" , defaulting to {}. Use --{} to override." ,
2510- spec.format ().channelBitLength (), in.filename (),
2511- toString (colorSpaceInfo.usedInputTransferFunction ),
2512- options.kAssignTf );
25132514 }
25142515 }
2515-
25162516 if (colorSpaceInfo.srcTransferFunction == nullptr ) {
2517- assert (colorSpaceInfo.usedInputTransferFunction != KHR_DF_TRANSFER_UNSPECIFIED
2518- && " One of srcTransferFunction or usedInputTransferFunction must be set." );
25192517 switch (colorSpaceInfo.usedInputTransferFunction ) {
25202518 case KHR_DF_TRANSFER_LINEAR:
25212519 colorSpaceInfo.srcTransferFunction = std::make_unique<TransferFunctionLinear>();
@@ -2543,7 +2541,8 @@ void CommandCreate::determineTargetColorSpace(const ImageInput& in, ImageSpec& t
25432541 toString (colorSpaceInfo.usedInputTransferFunction ),
25442542 detail);
25452543 if (!options.assignTF .has_value ())
2546- errorMsg += fmt::format (" or use {} to override it." , options.kAssignTf );
2544+ errorMsg += fmt::format (" or use --{}, with or without --{}, to specify handling." ,
2545+ options.kAssignTf , options.kConvertTf );
25472546 else
25482547 errorMsg += " ." ;
25492548
0 commit comments