Coverage for models/rgb/transfer_functions/__init__.py: 6%

1 from __future__ import annotations

2

3 import typing

4 from functools import partial

5

6 if typing.TYPE_CHECKING:

7 from colour.hints import (

8 Any,

9 ArrayLike,

10 NDArrayFloat,

11 NDArrayInt,

12 LiteralLogEncoding,

13 LiteralLogDecoding,

14 LiteralOETF,

15 LiteralOETFInverse,

16 LiteralEOTF,

17 LiteralEOTFInverse,

18 LiteralCCTFEncoding,

19 LiteralCCTFDecoding,

20 LiteralOOTF,

21 LiteralOOTFInverse,

22 )

23

24 from colour.utilities import (

25 CanonicalMapping,

26 filter_kwargs,

27 usage_warning,

28 validate_method,

29)

30

31# isort: split

32

33 from .common import CV_range, full_to_legal, legal_to_full

34 from .gamma import gamma_function

35

36# isort: split

37

38 from .aces import (

39 log_decoding_ACEScc,

40 log_decoding_ACEScct,

41 log_decoding_ACESproxy,

42 log_encoding_ACEScc,

43 log_encoding_ACEScct,

44 log_encoding_ACESproxy,

45)

46 from .apple_log_profile import (

47 log_decoding_AppleLogProfile,

48 log_encoding_AppleLogProfile,

49)

50 from .arib_std_b67 import oetf_ARIBSTDB67, oetf_inverse_ARIBSTDB67

51 from .arri import (

52 log_decoding_ARRILogC3,

53 log_decoding_ARRILogC4,

54 log_encoding_ARRILogC3,

55 log_encoding_ARRILogC4,

56)

57 from .blackmagic_design import (

58 oetf_BlackmagicFilmGeneration5,

59 oetf_inverse_BlackmagicFilmGeneration5,

60)

61 from .canon import (

62 CANON_LOG_2_DECODING_METHODS,

63 CANON_LOG_2_ENCODING_METHODS,

64 CANON_LOG_3_DECODING_METHODS,

65 CANON_LOG_3_ENCODING_METHODS,

66 CANON_LOG_DECODING_METHODS,

67 CANON_LOG_ENCODING_METHODS,

68 log_decoding_CanonLog,

69 log_decoding_CanonLog2,

70 log_decoding_CanonLog3,

71 log_encoding_CanonLog,

72 log_encoding_CanonLog2,

73 log_encoding_CanonLog3,

74)

75 from .cineon import log_decoding_Cineon, log_encoding_Cineon

76 from .davinci_intermediate import (

77 oetf_DaVinciIntermediate,

78 oetf_inverse_DaVinciIntermediate,

79)

80 from .dcdm import eotf_DCDM, eotf_inverse_DCDM

81 from .dicom_gsdf import eotf_DICOMGSDF, eotf_inverse_DICOMGSDF

82 from .dji_d_log import log_decoding_DJIDLog, log_encoding_DJIDLog

83 from .exponent import exponent_function_basic, exponent_function_monitor_curve

84 from .filmic_pro import log_decoding_FilmicPro6, log_encoding_FilmicPro6

85 from .filmlight_t_log import (

86 log_decoding_FilmLightTLog,

87 log_encoding_FilmLightTLog,

88)

89 from .fujifilm_f_log import (

90 log_decoding_FLog,

91 log_decoding_FLog2,

92 log_encoding_FLog,

93 log_encoding_FLog2,

94)

95 from .gopro import log_decoding_Protune, log_encoding_Protune

96 from .itur_bt_601 import oetf_BT601, oetf_inverse_BT601

97 from .itur_bt_709 import oetf_BT709, oetf_inverse_BT709

98 from .itur_bt_1361 import oetf_BT1361, oetf_inverse_BT1361

99 from .itur_bt_1886 import eotf_BT1886, eotf_inverse_BT1886

100 from .itur_bt_2020 import oetf_BT2020, oetf_inverse_BT2020

101

102# isort: split

103

104 from .st_2084 import eotf_inverse_ST2084, eotf_ST2084

105

106# isort: split

107

108 from .itur_bt_2100 import (

109 BT2100_HLG_EOTF_INVERSE_METHODS,

110 BT2100_HLG_EOTF_METHODS,

111 BT2100_HLG_OOTF_INVERSE_METHODS,

112 BT2100_HLG_OOTF_METHODS,

113 eotf_BT2100_HLG,

114 eotf_BT2100_PQ,

115 eotf_inverse_BT2100_HLG,

116 eotf_inverse_BT2100_PQ,

117 oetf_BT2100_HLG,

118 oetf_BT2100_PQ,

119 oetf_inverse_BT2100_HLG,

120 oetf_inverse_BT2100_PQ,

121 ootf_BT2100_HLG,

122 ootf_BT2100_PQ,

123 ootf_inverse_BT2100_HLG,

124 ootf_inverse_BT2100_PQ,

125)

126 from .leica_l_log import log_decoding_LLog, log_encoding_LLog

127 from .linear import linear_function

128 from .log import (

129 log_decoding_Log2,

130 log_encoding_Log2,

131 logarithmic_function_basic,

132 logarithmic_function_camera,

133 logarithmic_function_quasilog,

134)

135 from .nikon_n_log import log_decoding_NLog, log_encoding_NLog

136 from .panalog import log_decoding_Panalog, log_encoding_Panalog

137 from .panasonic_v_log import log_decoding_VLog, log_encoding_VLog

138 from .pivoted_log import log_decoding_PivotedLog, log_encoding_PivotedLog

139 from .red import (

140 LOG3G10_DECODING_METHODS,

141 LOG3G10_ENCODING_METHODS,

142 log_decoding_Log3G10,

143 log_decoding_Log3G12,

144 log_decoding_REDLog,

145 log_decoding_REDLogFilm,

146 log_encoding_Log3G10,

147 log_encoding_Log3G12,

148 log_encoding_REDLog,

149 log_encoding_REDLogFilm,

150)

151 from .rimm_romm_rgb import (

152 cctf_decoding_ProPhotoRGB,

153 cctf_decoding_RIMMRGB,

154 cctf_decoding_ROMMRGB,

155 cctf_encoding_ProPhotoRGB,

156 cctf_encoding_RIMMRGB,

157 cctf_encoding_ROMMRGB,

158 log_decoding_ERIMMRGB,

159 log_encoding_ERIMMRGB,

160)

161 from .smpte_240m import eotf_SMPTE240M, oetf_SMPTE240M

162 from .sony import (

163 log_decoding_SLog,

164 log_decoding_SLog2,

165 log_decoding_SLog3,

166 log_encoding_SLog,

167 log_encoding_SLog2,

168 log_encoding_SLog3,

169)

170 from .srgb import eotf_inverse_sRGB, eotf_sRGB

171 from .viper_log import log_decoding_ViperLog, log_encoding_ViperLog

172 from .xiaomi_mi_log import log_decoding_MiLog, log_encoding_MiLog

173

174# isort: split

175

176 from .itut_h_273 import (

177 eotf_H273_ST428_1,

178 eotf_inverse_H273_ST428_1,

179 oetf_H273_IEC61966_2,

180 oetf_H273_Log,

181 oetf_H273_LogSqrt,

182 oetf_inverse_H273_IEC61966_2,

183 oetf_inverse_H273_Log,

184 oetf_inverse_H273_LogSqrt,

185)

186

187 __all__ = [

188 "CV_range",

189 "full_to_legal",

190 "legal_to_full",

191]

192 __all__ += [

193 "gamma_function",

194]

195 __all__ += [

196 "log_decoding_ACEScc",

197 "log_decoding_ACEScct",

198 "log_decoding_ACESproxy",

199 "log_encoding_ACEScc",

200 "log_encoding_ACEScct",

201 "log_encoding_ACESproxy",

202]

203 __all__ += [

204 "log_decoding_AppleLogProfile",

205 "log_encoding_AppleLogProfile",

206]

207 __all__ += [

208 "oetf_ARIBSTDB67",

209 "oetf_inverse_ARIBSTDB67",

210]

211 __all__ += [

212 "log_decoding_ARRILogC3",

213 "log_decoding_ARRILogC4",

214 "log_encoding_ARRILogC3",

215 "log_encoding_ARRILogC4",

216]

217 __all__ += [

218 "oetf_BlackmagicFilmGeneration5",

219 "oetf_inverse_BlackmagicFilmGeneration5",

220]

221 __all__ += [

222 "CANON_LOG_2_DECODING_METHODS",

223 "CANON_LOG_2_ENCODING_METHODS",

224 "CANON_LOG_3_DECODING_METHODS",

225 "CANON_LOG_3_ENCODING_METHODS",

226 "CANON_LOG_DECODING_METHODS",

227 "CANON_LOG_ENCODING_METHODS",

228 "log_decoding_CanonLog",

229 "log_decoding_CanonLog2",

230 "log_decoding_CanonLog3",

231 "log_encoding_CanonLog",

232 "log_encoding_CanonLog2",

233 "log_encoding_CanonLog3",

234]

235 __all__ += [

236 "log_decoding_Cineon",

237 "log_encoding_Cineon",

238]

239 __all__ += [

240 "oetf_DaVinciIntermediate",

241 "oetf_inverse_DaVinciIntermediate",

242]

243 __all__ += [

244 "eotf_DCDM",

245 "eotf_inverse_DCDM",

246]

247 __all__ += [

248 "eotf_DICOMGSDF",

249 "eotf_inverse_DICOMGSDF",

250]

251 __all__ += [

252 "log_decoding_DJIDLog",

253 "log_encoding_DJIDLog",

254]

255 __all__ += [

256 "exponent_function_basic",

257 "exponent_function_monitor_curve",

258]

259 __all__ += [

260 "log_decoding_FilmicPro6",

261 "log_encoding_FilmicPro6",

262]

263 __all__ += [

264 "log_decoding_FilmLightTLog",

265 "log_encoding_FilmLightTLog",

266]

267 __all__ += [

268 "log_decoding_FLog",

269 "log_decoding_FLog2",

270 "log_encoding_FLog",

271 "log_encoding_FLog2",

272]

273 __all__ += [

274 "log_decoding_Protune",

275 "log_encoding_Protune",

276]

277 __all__ += [

278 "oetf_BT601",

279 "oetf_inverse_BT601",

280]

281 __all__ += [

282 "oetf_BT709",

283 "oetf_inverse_BT709",

284]

285 __all__ += [

286 "oetf_BT1361",

287 "oetf_inverse_BT1361",

288]

289 __all__ += [

290 "eotf_BT1886",

291 "eotf_inverse_BT1886",

292]

293 __all__ += [

294 "oetf_BT2020",

295 "oetf_inverse_BT2020",

296]

297 __all__ += [

298 "eotf_inverse_ST2084",

299 "eotf_ST2084",

300]

301 __all__ += [

302 "BT2100_HLG_EOTF_INVERSE_METHODS",

303 "BT2100_HLG_EOTF_METHODS",

304 "BT2100_HLG_OOTF_INVERSE_METHODS",

305 "BT2100_HLG_OOTF_METHODS",

306 "eotf_BT2100_HLG",

307 "eotf_BT2100_PQ",

308 "eotf_inverse_BT2100_HLG",

309 "eotf_inverse_BT2100_PQ",

310 "oetf_BT2100_HLG",

311 "oetf_BT2100_PQ",

312 "oetf_inverse_BT2100_HLG",

313 "oetf_inverse_BT2100_PQ",

314 "ootf_BT2100_HLG",

315 "ootf_BT2100_PQ",

316 "ootf_inverse_BT2100_HLG",

317 "ootf_inverse_BT2100_PQ",

318]

319 __all__ += [

320 "log_decoding_LLog",

321 "log_encoding_LLog",

322]

323 __all__ += [

324 "linear_function",

325]

326 __all__ += [

327 "log_decoding_Log2",

328 "log_encoding_Log2",

329 "logarithmic_function_basic",

330 "logarithmic_function_camera",

331 "logarithmic_function_quasilog",

332]

333 __all__ += [

334 "log_decoding_NLog",

335 "log_encoding_NLog",

336]

337 __all__ += [

338 "log_decoding_Panalog",

339 "log_encoding_Panalog",

340]

341 __all__ += [

342 "log_decoding_VLog",

343 "log_encoding_VLog",

344]

345 __all__ += [

346 "log_decoding_PivotedLog",

347 "log_encoding_PivotedLog",

348]

349 __all__ += [

350 "LOG3G10_DECODING_METHODS",

351 "LOG3G10_ENCODING_METHODS",

352 "log_decoding_Log3G10",

353 "log_decoding_Log3G12",

354 "log_decoding_REDLog",

355 "log_decoding_REDLogFilm",

356 "log_encoding_Log3G10",

357 "log_encoding_Log3G12",

358 "log_encoding_REDLog",

359 "log_encoding_REDLogFilm",

360]

361 __all__ += [

362 "cctf_decoding_ProPhotoRGB",

363 "cctf_decoding_RIMMRGB",

364 "cctf_decoding_ROMMRGB",

365 "cctf_encoding_ProPhotoRGB",

366 "cctf_encoding_RIMMRGB",

367 "cctf_encoding_ROMMRGB",

368 "log_decoding_ERIMMRGB",

369 "log_encoding_ERIMMRGB",

370]

371 __all__ += [

372 "eotf_SMPTE240M",

373 "oetf_SMPTE240M",

374]

375 __all__ += [

376 "log_decoding_SLog",

377 "log_decoding_SLog2",

378 "log_decoding_SLog3",

379 "log_encoding_SLog",

380 "log_encoding_SLog2",

381 "log_encoding_SLog3",

382]

383 __all__ += [

384 "eotf_inverse_sRGB",

385 "eotf_sRGB",

386]

387 __all__ += [

388 "log_decoding_ViperLog",

389 "log_encoding_ViperLog",

390]

391 __all__ += [

392 "log_decoding_MiLog",

393 "log_encoding_MiLog",

394]

395 __all__ += [

396 "eotf_H273_ST428_1",

397 "eotf_inverse_H273_ST428_1",

398 "oetf_H273_IEC61966_2",

399 "oetf_H273_Log",

400 "oetf_H273_LogSqrt",

401 "oetf_inverse_H273_IEC61966_2",

402 "oetf_inverse_H273_Log",

403 "oetf_inverse_H273_LogSqrt",

404]

405

406 LOG_ENCODINGS: CanonicalMapping = CanonicalMapping(

407 {

408 "ACEScc": log_encoding_ACEScc,

409 "ACEScct": log_encoding_ACEScct,

410 "ACESproxy": log_encoding_ACESproxy,

411 "Apple Log Profile": log_encoding_AppleLogProfile,

412 "ARRI LogC3": log_encoding_ARRILogC3,

413 "ARRI LogC4": log_encoding_ARRILogC4,

414 "Canon Log 2": log_encoding_CanonLog2,

415 "Canon Log 3": log_encoding_CanonLog3,

416 "Canon Log": log_encoding_CanonLog,

417 "Cineon": log_encoding_Cineon,

418 "D-Log": log_encoding_DJIDLog,

419 "ERIMM RGB": log_encoding_ERIMMRGB,

420 "F-Log": log_encoding_FLog,

421 "F-Log2": log_encoding_FLog2,

422 "Filmic Pro 6": log_encoding_FilmicPro6,

423 "L-Log": log_encoding_LLog,

424 "Log2": log_encoding_Log2,

425 "Log3G10": log_encoding_Log3G10,

426 "Log3G12": log_encoding_Log3G12,

427 "Mi-Log": log_encoding_MiLog,

428 "N-Log": log_encoding_NLog,

429 "PLog": log_encoding_PivotedLog,

430 "Panalog": log_encoding_Panalog,

431 "Protune": log_encoding_Protune,

432 "REDLog": log_encoding_REDLog,

433 "REDLogFilm": log_encoding_REDLogFilm,

434 "S-Log": log_encoding_SLog,

435 "S-Log2": log_encoding_SLog2,

436 "S-Log3": log_encoding_SLog3,

437 "T-Log": log_encoding_FilmLightTLog,

438 "V-Log": log_encoding_VLog,

439 "ViperLog": log_encoding_ViperLog,

440 }

441)

442 LOG_ENCODINGS.__doc__ = """

443 Supported *log* encoding functions.

444"""

445

446

447 def log_encoding(

448 value: ArrayLike, function: LiteralLogEncoding | str = "Cineon", **kwargs: Any

449) -> NDArrayFloat | NDArrayInt:

450 """

451 Apply the specified log encoding opto-electronic transfer function (OETF).

452

453 Parameters

454 ----------

455 value

456 Scene-linear value.

457 function

458 *Log* encoding function.

459

460 Other Parameters

461 ----------------

462 kwargs

463 {:func:`colour.models.log_encoding_ACEScc`,

464 :func:`colour.models.log_encoding_ACEScct`,

465 :func:`colour.models.log_encoding_ACESproxy`,

466 :func:`colour.models.log_encoding_AppleLogProfile`,

467 :func:`colour.models.log_encoding_ARRILogC3`,

468 :func:`colour.models.log_encoding_ARRILogC4`,

469 :func:`colour.models.log_encoding_CanonLog2`,

470 :func:`colour.models.log_encoding_CanonLog3`,

471 :func:`colour.models.log_encoding_CanonLog`,

472 :func:`colour.models.log_encoding_Cineon`,

473 :func:`colour.models.log_encoding_DJIDLog`,

474 :func:`colour.models.log_encoding_ERIMMRGB`,

475 :func:`colour.models.log_encoding_FLog`,

476 :func:`colour.models.log_encoding_FLog2`,

477 :func:`colour.models.log_encoding_FilmicPro6`,

478 :func:`colour.models.log_encoding_LLog`,

479 :func:`colour.models.log_encoding_Log2`,

480 :func:`colour.models.log_encoding_Log3G10`,

481 :func:`colour.models.log_encoding_Log3G12`,

482 :func:`colour.models.log_encoding_MiLog`,

483 :func:`colour.models.log_encoding_NLog`,

484 :func:`colour.models.log_encoding_PivotedLog`,

485 :func:`colour.models.log_encoding_Panalog`,

486 :func:`colour.models.log_encoding_Protune`,

487 :func:`colour.models.log_encoding_REDLog`,

488 :func:`colour.models.log_encoding_REDLogFilm`,

489 :func:`colour.models.log_encoding_SLog`,

490 :func:`colour.models.log_encoding_SLog2`,

491 :func:`colour.models.log_encoding_SLog3`,

492 :func:`colour.models.log_encoding_FilmLightTLog`,

493 :func:`colour.models.log_encoding_VLog`,

494 :func:`colour.models.log_encoding_ViperLog`},

495 See the documentation of the previously listed definitions.

496

497 Returns

498 -------

499 :class:`numpy.ndarray`

500 Logarithmic encoded value.

501

502 Examples

503 --------

504 >>> log_encoding(0.18) # doctest: +ELLIPSIS

505 0.4573196...

506 >>> log_encoding(0.18, function="ACEScc") # doctest: +ELLIPSIS

507 0.4135884...

508 >>> log_encoding(0.18, function="PLog", log_reference=400)

509 ... # doctest: +ELLIPSIS

510 0.3910068...

511 >>> log_encoding(0.18, function="S-Log") # doctest: +ELLIPSIS

512 0.3849708...

513 """

514

515 function = validate_method(

516 function,

517 tuple(LOG_ENCODINGS),

518 '"{0}" "log" encoding function is invalid, it must be one of {1}!',

519 )

520

521 callable_ = LOG_ENCODINGS[function]

522

523 return callable_(value, **filter_kwargs(callable_, **kwargs))

524

525

526 LOG_DECODINGS: CanonicalMapping = CanonicalMapping(

527 {

528 "ACEScc": log_decoding_ACEScc,

529 "ACEScct": log_decoding_ACEScct,

530 "ACESproxy": log_decoding_ACESproxy,

531 "Apple Log Profile": log_decoding_AppleLogProfile,

532 "ARRI LogC3": log_decoding_ARRILogC3,

533 "ARRI LogC4": log_decoding_ARRILogC4,

534 "Canon Log 2": log_decoding_CanonLog2,

535 "Canon Log 3": log_decoding_CanonLog3,

536 "Canon Log": log_decoding_CanonLog,

537 "Cineon": log_decoding_Cineon,

538 "D-Log": log_decoding_DJIDLog,

539 "ERIMM RGB": log_decoding_ERIMMRGB,

540 "F-Log": log_decoding_FLog,

541 "F-Log2": log_decoding_FLog2,

542 "Filmic Pro 6": log_decoding_FilmicPro6,

543 "L-Log": log_decoding_LLog,

544 "Log2": log_decoding_Log2,

545 "Log3G10": log_decoding_Log3G10,

546 "Log3G12": log_decoding_Log3G12,

547 "Mi-Log": log_decoding_MiLog,

548 "N-Log": log_decoding_NLog,

549 "PLog": log_decoding_PivotedLog,

550 "Panalog": log_decoding_Panalog,

551 "Protune": log_decoding_Protune,

552 "REDLog": log_decoding_REDLog,

553 "REDLogFilm": log_decoding_REDLogFilm,

554 "S-Log": log_decoding_SLog,

555 "S-Log2": log_decoding_SLog2,

556 "S-Log3": log_decoding_SLog3,

557 "T-Log": log_decoding_FilmLightTLog,

558 "V-Log": log_decoding_VLog,

559 "ViperLog": log_decoding_ViperLog,

560 }

561)

562 LOG_DECODINGS.__doc__ = """

563 Supported *log* decoding functions.

564"""

565

566

567 def log_decoding(

568 value: ArrayLike,

569 function: LiteralLogDecoding | str = "Cineon",

570 **kwargs: Any,

571) -> NDArrayFloat:

572 """

573 Apply the specified log decoding inverse opto-electronic transfer function (OETF).

574

575 Parameters

576 ----------

577 value

578 Logarithmic encoded value.

579 function

580 *Log* decoding function.

581

582 Other Parameters

583 ----------------

584 kwargs

585 {:func:`colour.models.log_decoding_ACEScc`,

586 :func:`colour.models.log_decoding_ACEScct`,

587 :func:`colour.models.log_decoding_ACESproxy`,

588 :func:`colour.models.log_decoding_AppleLogProfile`,

589 :func:`colour.models.log_decoding_ARRILogC3`,

590 :func:`colour.models.log_decoding_ARRILogC4`,

591 :func:`colour.models.log_decoding_CanonLog2`,

592 :func:`colour.models.log_decoding_CanonLog3`,

593 :func:`colour.models.log_decoding_CanonLog`,

594 :func:`colour.models.log_decoding_Cineon`,

595 :func:`colour.models.log_decoding_DJIDLog`,

596 :func:`colour.models.log_decoding_ERIMMRGB`,

597 :func:`colour.models.log_decoding_FLog`,

598 :func:`colour.models.log_decoding_FLog2`,

599 :func:`colour.models.log_decoding_FilmicPro6`,

600 :func:`colour.models.log_decoding_LLog`,

601 :func:`colour.models.log_decoding_Log2`,

602 :func:`colour.models.log_decoding_Log3G10`,

603 :func:`colour.models.log_decoding_Log3G12`,

604 :func:`colour.models.log_decoding_MiLog`,

605 :func:`colour.models.log_decoding_NLog`,

606 :func:`colour.models.log_decoding_PivotedLog`,

607 :func:`colour.models.log_decoding_Panalog`,

608 :func:`colour.models.log_decoding_Protune`,

609 :func:`colour.models.log_decoding_REDLog`,

610 :func:`colour.models.log_decoding_REDLogFilm`,

611 :func:`colour.models.log_decoding_SLog`,

612 :func:`colour.models.log_decoding_SLog2`,

613 :func:`colour.models.log_decoding_SLog3`,

614 :func:`colour.models.log_decoding_FilmLightTLog`,

615 :func:`colour.models.log_decoding_VLog`,

616 :func:`colour.models.log_decoding_ViperLog`},

617 See the documentation of the previously listed definitions.

618

619 Returns

620 -------

621 :class:`numpy.ndarray`

622 Scene-linear value.

623

624 Examples

625 --------

626 >>> log_decoding(0.457319613085418) # doctest: +ELLIPSIS

627 0.1...

628 >>> log_decoding(0.413588402492442, function="ACEScc")

629 ... # doctest: +ELLIPSIS

630 0.1...

631 >>> log_decoding(0.391006842619746, function="PLog", log_reference=400)

632 ... # doctest: +ELLIPSIS

633 0.1...

634 >>> log_decoding(0.376512722254600, function="S-Log")

635 ... # doctest: +ELLIPSIS

636 0.1...

637 """

638

639 function = validate_method(

640 function,

641 tuple(LOG_DECODINGS),

642 '"{0}" "log" decoding function is invalid, it must be one of {1}!',

643 )

644

645 callable_ = LOG_DECODINGS[function]

646

647 return callable_(value, **filter_kwargs(callable_, **kwargs))

648

649

650 __all__ += [

651 "LOG_ENCODINGS",

652 "LOG_DECODINGS",

653]

654 __all__ += [

655 "log_encoding",

656 "log_decoding",

657]

658

659 OETFS: CanonicalMapping = CanonicalMapping(

660 {

661 "ARIB STD-B67": oetf_ARIBSTDB67,

662 "Blackmagic Film Generation 5": oetf_BlackmagicFilmGeneration5,

663 "DaVinci Intermediate": oetf_DaVinciIntermediate,

664 "ITU-R BT.2020": oetf_BT2020,

665 "ITU-R BT.2100 HLG": oetf_BT2100_HLG,

666 "ITU-R BT.2100 PQ": oetf_BT2100_PQ,

667 "ITU-R BT.601": oetf_BT601,

668 "ITU-R BT.709": oetf_BT709,

669 "ITU-T H.273 Log": oetf_H273_Log,

670 "ITU-T H.273 Log Sqrt": oetf_H273_LogSqrt,

671 "ITU-T H.273 IEC 61966-2": oetf_H273_IEC61966_2,

672 "SMPTE 240M": oetf_SMPTE240M,

673 }

674)

675 OETFS.__doc__ = """

676 Supported opto-electrical transfer functions (OETFs / OECFs).

677"""

678

679

680 def oetf(

681 value: ArrayLike, function: LiteralOETF | str = "ITU-R BT.709", **kwargs: Any

682) -> NDArrayFloat:

683 """

684 Apply the specified opto-electronic transfer function (OETF).

685

686 Parameters

687 ----------

688 value

689 Scene-linear value.

690 function

691 Opto-electronic transfer function (OETF).

692

693 Other Parameters

694 ----------------

695 kwargs

696 {:func:`colour.models.oetf_ARIBSTDB67`,

697 :func:`colour.models.oetf_BlackmagicFilmGeneration5`,

698 :func:`colour.models.oetf_DaVinciIntermediate`,

699 :func:`colour.models.oetf_BT2020`,

700 :func:`colour.models.oetf_BT2100_HLG`,

701 :func:`colour.models.oetf_BT2100_PQ`,

702 :func:`colour.models.oetf_BT601`,

703 :func:`colour.models.oetf_BT709`,

704 :func:`colour.models.oetf_SMPTE240M`},

705 See the documentation of the previously listed definitions.

706

707 Returns

708 -------

709 :class:`numpy.ndarray`

710 Non-linear signal value.

711

712 Examples

713 --------

714 >>> oetf(0.18) # doctest: +ELLIPSIS

715 0.4090077...

716 >>> oetf(0.18, function="ITU-R BT.601") # doctest: +ELLIPSIS

717 0.4090077...

718 """

719

720 function = validate_method(

721 function,

722 tuple(OETFS),

723 '"{0}" "OETF" is invalid, it must be one of {1}!',

724 )

725

726 callable_ = OETFS[function]

727

728 return callable_(value, **filter_kwargs(callable_, **kwargs))

729

730

731 OETF_INVERSES: CanonicalMapping = CanonicalMapping(

732 {

733 "ARIB STD-B67": oetf_inverse_ARIBSTDB67,

734 "Blackmagic Film Generation 5": oetf_inverse_BlackmagicFilmGeneration5,

735 "DaVinci Intermediate": oetf_inverse_DaVinciIntermediate,

736 "ITU-R BT.2020": oetf_inverse_BT2020,

737 "ITU-R BT.2100 HLG": oetf_inverse_BT2100_HLG,

738 "ITU-R BT.2100 PQ": oetf_inverse_BT2100_PQ,

739 "ITU-R BT.601": oetf_inverse_BT601,

740 "ITU-R BT.709": oetf_inverse_BT709,

741 "ITU-T H.273 Log": oetf_inverse_H273_Log,

742 "ITU-T H.273 Log Sqrt": oetf_inverse_H273_LogSqrt,

743 "ITU-T H.273 IEC 61966-2": oetf_inverse_H273_IEC61966_2,

744 }

745)

746 OETF_INVERSES.__doc__ = """

747 Supported inverse opto-electrical transfer functions (OETFs / OECFs).

748"""

749

750

751 def oetf_inverse(

752 value: ArrayLike,

753 function: LiteralOETFInverse | str = "ITU-R BT.709",

754 **kwargs: Any,

755) -> NDArrayFloat:

756 """

757 Apply the specified inverse opto-electronic transfer function (OETF).

758

759 Parameters

760 ----------

761 value

762 Non-linear signal value.

763 function

764 Inverse opto-electronic transfer function (OETF).

765

766 Other Parameters

767 ----------------

768 kwargs

769 {:func:`colour.models.oetf_inverse_ARIBSTDB67`,

770 :func:`colour.models.oetf_inverse_BlackmagicFilmGeneration5`,

771 :func:`colour.models.oetf_inverse_DaVinciIntermediate`,

772 :func:`colour.models.oetf_inverse_BT2020`,

773 :func:`colour.models.oetf_inverse_BT2100_HLG`,

774 :func:`colour.models.oetf_inverse_BT2100_PQ`,

775 :func:`colour.models.oetf_inverse_BT601`,

776 :func:`colour.models.oetf_inverse_BT709`},

777 See the documentation of the previously listed definitions.

778

779 Returns

780 -------

781 :class:`numpy.ndarray`

782 Scene-linear value.

783

784 Examples

785 --------

786 >>> oetf_inverse(0.409007728864150) # doctest: +ELLIPSIS

787 0.1...

788 >>> oetf_inverse( # doctest: +ELLIPSIS

789 ... 0.409007728864150, function="ITU-R BT.601"

790 ... )

791 0.1...

792 """

793

794 function = validate_method(

795 function,

796 tuple(OETF_INVERSES),

797 '"{0}" inverse "OETF" is invalid, it must be one of {1}!',

798 )

799

800 callable_ = OETF_INVERSES[function]

801

802 return callable_(value, **filter_kwargs(callable_, **kwargs))

803

804

805 EOTFS: CanonicalMapping = CanonicalMapping(

806 {

807 "DCDM": eotf_DCDM,

808 "DICOM GSDF": eotf_DICOMGSDF,

809 "ITU-R BT.1886": eotf_BT1886,

810 "ITU-R BT.2100 HLG": eotf_BT2100_HLG,

811 "ITU-R BT.2100 PQ": eotf_BT2100_PQ,

812 "ITU-T H.273 ST.428-1": eotf_H273_ST428_1,

813 "SMPTE 240M": eotf_SMPTE240M,

814 "ST 2084": eotf_ST2084,

815 "sRGB": eotf_sRGB,

816 }

817)

818 EOTFS.__doc__ = """

819 Supported electro-optical transfer functions (EOTFs / EOCFs).

820"""

821

822

823 def eotf(

824 value: ArrayLike,

825 function: LiteralEOTF | str = "ITU-R BT.1886",

826 **kwargs: Any,

827) -> NDArrayFloat:

828 """

829 Apply the specified electro-optical transfer function (EOTF).

830

831 Parameters

832 ----------

833 value

834 Non-linear signal value.

835 function

836 Electro-optical transfer function (EOTF).

837

838 Other Parameters

839 ----------------

840 kwargs

841 {:func:`colour.models.eotf_DCDM`,

842 :func:`colour.models.eotf_DICOMGSDF`,

843 :func:`colour.models.eotf_BT1886`,

844 :func:`colour.models.eotf_BT2100_HLG`,

845 :func:`colour.models.eotf_BT2100_PQ`,

846 :func:`colour.models.eotf_SMPTE240M`,

847 :func:`colour.models.eotf_ST2084`,

848 :func:`colour.models.eotf_sRGB`},

849 See the documentation of the previously listed definitions.

850

851 Returns

852 -------

853 :class:`numpy.ndarray`

854 Display-linear value.

855

856 Examples

857 --------

858 >>> eotf(0.461356129500442) # doctest: +ELLIPSIS

859 0.1...

860 >>> eotf(0.182011532850008, function="ST 2084", L_p=1000)

861 ... # doctest: +ELLIPSIS

862 0.1...

863 """

864

865 function = validate_method(

866 function,

867 tuple(EOTFS),

868 '"{0}" "EOTF" is invalid, it must be one of {1}!',

869 )

870

871 callable_ = EOTFS[function]

872

873 return callable_(value, **filter_kwargs(callable_, **kwargs))

874

875

876 EOTF_INVERSES: CanonicalMapping = CanonicalMapping(

877 {

878 "DCDM": eotf_inverse_DCDM,

879 "DICOM GSDF": eotf_inverse_DICOMGSDF,

880 "ITU-R BT.1886": eotf_inverse_BT1886,

881 "ITU-R BT.2100 HLG": eotf_inverse_BT2100_HLG,

882 "ITU-R BT.2100 PQ": eotf_inverse_BT2100_PQ,

883 "ITU-T H.273 ST.428-1": eotf_inverse_H273_ST428_1,

884 "ST 2084": eotf_inverse_ST2084,

885 "sRGB": eotf_inverse_sRGB,

886 }

887)

888 EOTF_INVERSES.__doc__ = """

889 Supported inverse electro-optical transfer functions (EOTFs / EOCFs).

890"""

891

892

893 def eotf_inverse(

894 value: ArrayLike,

895 function: LiteralEOTFInverse | str = "ITU-R BT.1886",

896 **kwargs: Any,

897) -> NDArrayFloat | NDArrayInt:

898 """

899 Apply the specified inverse electro-optical transfer function (EOTF).

900

901 Parameters

902 ----------

903 value

904 Display-linear value.

905 function

906 Inverse electro-optical transfer function (EOTF).

907

908 Other Parameters

909 ----------------

910 kwargs

911 {:func:`colour.models.eotf_inverse_DCDM`,

912 :func:`colour.models.eotf_inverse_DICOMGSDF`,

913 :func:`colour.models.eotf_inverse_BT1886`,

914 :func:`colour.models.eotf_inverse_BT2100_HLG`,

915 :func:`colour.models.eotf_inverse_BT2100_PQ`,

916 :func:`colour.models.eotf_inverse_ST2084`,

917 :func:`colour.models.eotf_inverse_sRGB`},

918 See the documentation of the previously listed definitions.

919

920 Returns

921 -------

922 :class:`numpy.ndarray`

923 Non-linear signal value.

924

925 Examples

926 --------

927 >>> eotf_inverse(0.11699185725296059) # doctest: +ELLIPSIS

928 0.4090077...

929 >>> eotf_inverse( # doctest: +ELLIPSIS

930 ... 0.11699185725296059, function="ITU-R BT.1886"

931 ... )

932 0.4090077...

933 """

934

935 function = validate_method(

936 function,

937 tuple(EOTF_INVERSES),

938 '"{0}" inverse "EOTF" is invalid, it must be one of {1}!',

939 )

940

941 callable_ = EOTF_INVERSES[function]

942

943 return callable_(value, **filter_kwargs(callable_, **kwargs))

944

945

946 __all__ += [

947 "OETFS",

948 "OETF_INVERSES",

949 "EOTFS",

950 "EOTF_INVERSES",

951]

952 __all__ += [

953 "oetf",

954 "oetf_inverse",

955 "eotf",

956 "eotf_inverse",

957]

958

959 CCTF_ENCODINGS: CanonicalMapping = CanonicalMapping(

960 {

961 "Gamma 2.2": partial(gamma_function, exponent=1 / 2.2),

962 "Gamma 2.4": partial(gamma_function, exponent=1 / 2.4),

963 "Gamma 2.6": partial(gamma_function, exponent=1 / 2.6),

964 "ProPhoto RGB": cctf_encoding_ProPhotoRGB,

965 "RIMM RGB": cctf_encoding_RIMMRGB,

966 "ROMM RGB": cctf_encoding_ROMMRGB,

967 }

968)

969 CCTF_ENCODINGS.update(LOG_ENCODINGS)

970 CCTF_ENCODINGS.update(OETFS)

971 CCTF_ENCODINGS.update(EOTF_INVERSES)

972 CCTF_ENCODINGS.__doc__ = """

973 Supported encoding colour component transfer functions (encoding CCTFs), a

974 collection comprising functions from :attr:`colour.LOG_ENCODINGS`,

975:attr:`colour.OETFS`, :attr:`colour.EOTF_INVERSES`,

976:func:`colour.models.cctf_encoding_ProPhotoRGB`,

977:func:`colour.models.cctf_encoding_RIMMRGB`,

978:func:`colour.models.cctf_encoding_ROMMRGB`, and three gamma encoding

979 functions (1/2.2, 1/2.4, 1/2.6).

980

981 Warnings

982--------

983 For *ITU-R BT.2100*, only the inverse electro-optical transfer functions

984(EOTFs) are exposed by this definition, See the :func:`colour.oetf`

985 definition for the opto-electronic transfer functions (OETF).

986"""

987

988

989 def cctf_encoding(

990 value: ArrayLike, function: LiteralCCTFEncoding | str = "sRGB", **kwargs: Any

991) -> NDArrayFloat | NDArrayInt:

992 """

993 Apply the specified encoding colour component transfer function (Encoding

994 CCTF).

995

996 Parameters

997 ----------

998 value

999 Linear RGB value.

1000 function

1001 Encoding colour component transfer function.

1002

1003 Other Parameters

1004 ----------------

1005 kwargs

1006 Keywords arguments for the relevant encoding *CCTF* of the

1007 :attr:`colour.CCTF_ENCODINGS` attribute collection.

1008

1009 Warnings

1010 --------

1011 For *ITU-R BT.2100*, only the inverse electro-optical transfer functions

1012 (EOTFs) are exposed by this definition, See the :func:`colour.oetf`

1013 definition for the opto-electronic transfer functions (OETF).

1014

1015 Returns

1016 -------

1017 :class:`numpy.ndarray`

1018 Non-linear RGB value.

1019

1020 Examples

1021 --------

1022 >>> cctf_encoding(0.18, function="PLog", log_reference=400)

1023 ... # doctest: +ELLIPSIS

1024 0.3910068...

1025 >>> cctf_encoding(0.18, function="ST 2084", L_p=1000)

1026 ... # doctest: +ELLIPSIS

1027 0.1820115...

1028 >>> cctf_encoding( # doctest: +ELLIPSIS

1029 ... 0.11699185725296059, function="ITU-R BT.1886"

1030 ... )

1031 0.4090077...

1032 """

1033

1034 function = validate_method(

1035 function,

1036 tuple(CCTF_ENCODINGS),

1037 '"{0}" encoding "CCTF" is invalid, it must be one of {1}!',

1038 )

1039

1040 if "itu-r bt.2100" in function:

1041 usage_warning(

1042 'With the "ITU-R BT.2100" method, only the inverse '

1043 "electro-optical transfer functions (EOTFs / EOCFs) are exposed "

1044 'by this definition, See the "colour.oetf" definition '

1045 "for the opto-electronic transfer functions (OETF)."

1046 )

1047

1048 callable_ = CCTF_ENCODINGS[function]

1049

1050 return callable_(value, **filter_kwargs(callable_, **kwargs))

1051

1052

1053 CCTF_DECODINGS: CanonicalMapping = CanonicalMapping(

1054 {

1055 "Gamma 2.2": partial(gamma_function, exponent=2.2),

1056 "Gamma 2.4": partial(gamma_function, exponent=2.4),

1057 "Gamma 2.6": partial(gamma_function, exponent=2.6),

1058 "ProPhoto RGB": cctf_decoding_ProPhotoRGB,

1059 "RIMM RGB": cctf_decoding_RIMMRGB,

1060 "ROMM RGB": cctf_decoding_ROMMRGB,

1061 }

1062)

1063 CCTF_DECODINGS.update(LOG_DECODINGS)

1064 CCTF_DECODINGS.update(OETF_INVERSES)

1065 CCTF_DECODINGS.update(EOTFS)

1066 CCTF_DECODINGS.__doc__ = """

1067 Supported decoding colour component transfer functions (decoding CCTFs), a

1068 collection comprising functions from :attr:`colour.LOG_DECODINGS`,

1069:attr:`colour.OETF_INVERSES`, :attr:`colour.EOTFS`,

1070:func:`colour.models.cctf_decoding_ProPhotoRGB`,

1071:func:`colour.models.cctf_decoding_RIMMRGB`,

1072:func:`colour.models.cctf_decoding_ROMMRGB`, and three gamma decoding

1073 functions (2.2, 2.4, 2.6).

1074

1075 Warnings

1076--------

1077 For *ITU-R BT.2100*, only the electro-optical transfer functions

1078(EOTFs) are exposed by this attribute. See :attr:`colour.OETF_INVERSES`

1079 for the inverse opto-electronic transfer functions (OETFs).

1080"""

1081

1082

1083 def cctf_decoding(

1084 value: ArrayLike,

1085 function: LiteralCCTFDecoding | str = "sRGB",

1086 **kwargs: Any,

1087) -> NDArrayFloat:

1088 """

1089 Apply the specified decoding colour component transfer function (Decoding

1090 CCTF).

1091

1092 Parameters

1093 ----------

1094 value

1095 Non-linear RGB value.

1096 function

1097 Decoding colour component transfer function.

1098

1099 Other Parameters

1100 ----------------

1101 kwargs

1102 Keywords arguments for the relevant decoding *CCTF* of the

1103 :attr:`colour.CCTF_DECODINGS` attribute collection.

1104

1105 Warnings

1106 --------

1107 For *ITU-R BT.2100*, only the electro-optical transfer functions

1108 (EOTFs) are exposed by this attribute. See :attr:`colour.OETF_INVERSES`

1109 for the inverse opto-electronic transfer functions (OETFs).

1110

1111 Returns

1112 -------

1113 :class:`numpy.ndarray`

1114 Linear RGB value.

1115

1116 Examples

1117 --------

1118 >>> cctf_decoding(0.391006842619746, function="PLog", log_reference=400)

1119 ... # doctest: +ELLIPSIS

1120 0.1...

1121 >>> cctf_decoding(0.182011532850008, function="ST 2084", L_p=1000)

1122 ... # doctest: +ELLIPSIS

1123 0.1...

1124 >>> cctf_decoding( # doctest: +ELLIPSIS

1125 ... 0.461356129500442, function="ITU-R BT.1886"

1126 ... )

1127 0.1...

1128 """

1129

1130 function = validate_method(

1131 function,

1132 tuple(CCTF_DECODINGS),

1133 '"{0}" decoding "CCTF" is invalid, it must be one of {1}!',

1134 )

1135

1136 if "itu-r bt.2100" in function:

1137 usage_warning(

1138 'With the "ITU-R BT.2100" method, only the electro-optical '

1139 "transfer functions (EOTFs / EOCFs) are exposed by this "

1140 'definition, See the "colour.oetf_inverse" definition '

1141 "for the inverse opto-electronic transfer functions (OETF)."

1142 )

1143

1144 callable_ = CCTF_DECODINGS[function]

1145

1146 return callable_(value, **filter_kwargs(callable_, **kwargs))

1147

1148

1149 __all__ += [

1150 "CCTF_ENCODINGS",

1151 "CCTF_DECODINGS",

1152]

1153 __all__ += [

1154 "cctf_encoding",

1155 "cctf_decoding",

1156]

1157

1158 OOTFS: CanonicalMapping = CanonicalMapping(

1159 {

1160 "ITU-R BT.2100 HLG": ootf_BT2100_HLG,

1161 "ITU-R BT.2100 PQ": ootf_BT2100_PQ,

1162 }

1163)

1164 OOTFS.__doc__ = """

1165 Supported opto-optical transfer functions (OOTFs / OOCFs).

1166"""

1167

1168

1169 def ootf(

1170 value: ArrayLike,

1171 function: LiteralOOTF | str = "ITU-R BT.2100 PQ",

1172 **kwargs: Any,

1173) -> NDArrayFloat:

1174 """

1175 Apply the specified opto-optical transfer function (OOTF).

1176

1177 Parameters

1178 ----------

1179 value

1180 Scene-linear value.

1181 function

1182 Opto-optical transfer function (OOTF).

1183

1184 Other Parameters

1185 ----------------

1186 kwargs

1187 {:func:`colour.models.ootf_BT2100_HLG`,

1188 :func:`colour.models.ootf_BT2100_PQ`},

1189 See the documentation of the previously listed definitions.

1190

1191 Returns

1192 -------

1193 :class:`numpy.ndarray`

1194 Display-linear value.

1195

1196 Examples

1197 --------

1198 >>> ootf(0.1) # doctest: +ELLIPSIS

1199 779.9883608...

1200 >>> ootf(0.1, function="ITU-R BT.2100 HLG") # doctest: +ELLIPSIS

1201 63.0957344...

1202 """

1203

1204 function = validate_method(

1205 function,

1206 tuple(OOTFS),

1207 '"{0}" "OOTF" is invalid, it must be one of {1}!',

1208 )

1209

1210 callable_ = OOTFS[function]

1211

1212 return callable_(value, **filter_kwargs(callable_, **kwargs))

1213

1214

1215 OOTF_INVERSES: CanonicalMapping = CanonicalMapping(

1216 {

1217 "ITU-R BT.2100 HLG": ootf_inverse_BT2100_HLG,

1218 "ITU-R BT.2100 PQ": ootf_inverse_BT2100_PQ,

1219 }

1220)

1221 OOTF_INVERSES.__doc__ = """

1222 Supported inverse opto-optical transfer functions (OOTFs / OOCFs).

1223"""

1224

1225

1226 def ootf_inverse(

1227 value: ArrayLike,

1228 function: LiteralOOTFInverse | str = "ITU-R BT.2100 PQ",

1229 **kwargs: Any,

1230) -> NDArrayFloat:

1231 """

1232 Apply the specified inverse opto-optical transfer function (OOTF).

1233

1234 Parameters

1235 ----------

1236 value

1237 Display-linear value.

1238 function

1239 Inverse opto-optical transfer function (OOTF).

1240

1241 Other Parameters

1242 ----------------

1243 kwargs

1244 {:func:`colour.models.ootf_inverse_BT2100_HLG`,

1245 :func:`colour.models.ootf_inverse_BT2100_PQ`},

1246 See the documentation of the previously listed definitions.

1247

1248 Returns

1249 -------

1250 :class:`numpy.ndarray`

1251 Scene-linear value.

1252

1253 Examples

1254 --------

1255 >>> ootf_inverse(779.988360834115840) # doctest: +ELLIPSIS

1256 0.1000000...

1257 >>> ootf_inverse( # doctest: +ELLIPSIS

1258 ... 63.095734448019336, function="ITU-R BT.2100 HLG"

1259 ... )

1260 0.1000000...

1261 """

1262

1263 function = validate_method(

1264 function,

1265 tuple(OOTF_INVERSES),

1266 '"{0}" inverse "OOTF" is invalid, it must be one of {1}!',

1267 )

1268

1269 callable_ = OOTF_INVERSES[function]

1270

1271 return callable_(value, **filter_kwargs(callable_, **kwargs))

1272

1273

1274 __all__ += [

1275 "OOTFS",

1276 "OOTF_INVERSES",

1277]

1278 __all__ += [

1279 "ootf",

1280 "ootf_inverse",

1281]