77
88import { describe , expect , it , vi } from "vitest" ;
99import type { ExtractionResult , VideoColorSpace } from "@hyperframes/engine" ;
10- import { findRenderHdrAutoPromotionTrigger , resolveEffectiveHdrMode } from "./hdrMode.js" ;
10+ import {
11+ findRenderHdrAutoPromotionTrigger ,
12+ rendersSdrOnly ,
13+ resolveEffectiveHdrMode ,
14+ } from "./hdrMode.js" ;
15+
16+ const NO_MEDIA = { videos : [ ] , images : [ ] } ;
17+ const GRADED_VIDEO = { videos : [ { graded : true } , { } ] , images : [ ] } ;
1118
1219function makeLog ( ) {
1320 return { error : vi . fn ( ) , warn : vi . fn ( ) , info : vi . fn ( ) , debug : vi . fn ( ) } ;
@@ -37,9 +44,41 @@ const HDR_PQ: VideoColorSpace = {
3744} ;
3845
3946describe ( "resolveEffectiveHdrMode" , ( ) => {
47+ it ( "keeps an auto render with graded media SDR when an HDR source would promote it, and says why" , ( ) => {
48+ const log = makeLog ( ) ;
49+ const result = resolveEffectiveHdrMode ( {
50+ media : GRADED_VIDEO ,
51+ hdrMode : "auto" ,
52+ outputFormat : "mp4" ,
53+ extractionResult : extractionWith ( [ HDR_PQ ] ) ,
54+ imageColorSpaces : [ ] ,
55+ log,
56+ } ) ;
57+ expect ( result ) . toBeUndefined ( ) ;
58+ expect ( log . warn ) . toHaveBeenCalledWith ( expect . stringContaining ( "color grading is SDR-only" ) ) ;
59+ expect ( log . warn ) . not . toHaveBeenCalledWith ( expect . stringContaining ( "auto-promotion" ) ) ;
60+ } ) ;
61+
62+ it ( "keeps --hdr with graded media HDR and warns that the grades are SDR" , ( ) => {
63+ const log = makeLog ( ) ;
64+ const result = resolveEffectiveHdrMode ( {
65+ media : { videos : [ ] , images : [ { graded : true } ] } ,
66+ hdrMode : "force-hdr" ,
67+ outputFormat : "mp4" ,
68+ extractionResult : extractionWith ( [ HDR_PQ ] ) ,
69+ imageColorSpaces : [ ] ,
70+ log,
71+ } ) ;
72+ expect ( result ) . toEqual ( { transfer : "pq" } ) ;
73+ expect ( log . warn ) . toHaveBeenCalledWith (
74+ expect . stringContaining ( "graded elements are graded in SDR" ) ,
75+ ) ;
76+ } ) ;
77+
4078 it ( "returns undefined when force-sdr is set, regardless of HDR sources" , ( ) => {
4179 const log = makeLog ( ) ;
4280 const result = resolveEffectiveHdrMode ( {
81+ media : NO_MEDIA ,
4382 hdrMode : "force-sdr" ,
4483 outputFormat : "mp4" ,
4584 extractionResult : extractionWith ( [ HDR_PQ ] ) ,
@@ -53,6 +92,7 @@ describe("resolveEffectiveHdrMode", () => {
5392 it ( "auto-detects HDR from video sources when format=mp4" , ( ) => {
5493 const log = makeLog ( ) ;
5594 const result = resolveEffectiveHdrMode ( {
95+ media : NO_MEDIA ,
5696 hdrMode : undefined ,
5797 outputFormat : "mp4" ,
5898 extractionResult : extractionWith ( [ HDR_PQ ] ) ,
@@ -71,6 +111,7 @@ describe("resolveEffectiveHdrMode", () => {
71111 it ( "auto-detects SDR with no HDR sources" , ( ) => {
72112 const log = makeLog ( ) ;
73113 const result = resolveEffectiveHdrMode ( {
114+ media : NO_MEDIA ,
74115 hdrMode : "auto" ,
75116 outputFormat : "mp4" ,
76117 extractionResult : extractionWith ( [ ] ) ,
@@ -84,6 +125,7 @@ describe("resolveEffectiveHdrMode", () => {
84125 it ( "force-hdr without sources falls back to HLG and warns" , ( ) => {
85126 const log = makeLog ( ) ;
86127 const result = resolveEffectiveHdrMode ( {
128+ media : NO_MEDIA ,
87129 hdrMode : "force-hdr" ,
88130 outputFormat : "mp4" ,
89131 extractionResult : extractionWith ( [ ] ) ,
@@ -99,6 +141,7 @@ describe("resolveEffectiveHdrMode", () => {
99141 it ( "force-hdr uses the dominant probed transfer when sources are HDR" , ( ) => {
100142 const log = makeLog ( ) ;
101143 const result = resolveEffectiveHdrMode ( {
144+ media : NO_MEDIA ,
102145 hdrMode : "force-hdr" ,
103146 outputFormat : "mp4" ,
104147 extractionResult : extractionWith ( [ HDR_PQ ] ) ,
@@ -113,6 +156,7 @@ describe("resolveEffectiveHdrMode", () => {
113156 for ( const fmt of [ "webm" , "mov" , "png-sequence" ] as const ) {
114157 const log = makeLog ( ) ;
115158 const result = resolveEffectiveHdrMode ( {
159+ media : NO_MEDIA ,
116160 hdrMode : "auto" ,
117161 outputFormat : fmt ,
118162 extractionResult : extractionWith ( [ HDR_PQ ] ) ,
@@ -135,6 +179,7 @@ describe("resolveEffectiveHdrMode", () => {
135179 it ( "downgrades auto-detected HDR on hls with an SDR-only reason, not the alpha one" , ( ) => {
136180 const log = makeLog ( ) ;
137181 const result = resolveEffectiveHdrMode ( {
182+ media : NO_MEDIA ,
138183 hdrMode : "auto" ,
139184 outputFormat : "hls" ,
140185 extractionResult : extractionWith ( [ HDR_PQ ] ) ,
@@ -154,6 +199,7 @@ describe("resolveEffectiveHdrMode", () => {
154199 it ( "force-hdr without sources + non-mp4 format: still downgrades, two warns fire" , ( ) => {
155200 const log = makeLog ( ) ;
156201 const result = resolveEffectiveHdrMode ( {
202+ media : NO_MEDIA ,
157203 hdrMode : "force-hdr" ,
158204 outputFormat : "webm" ,
159205 extractionResult : extractionWith ( [ ] ) ,
@@ -202,3 +248,11 @@ describe("findRenderHdrAutoPromotionTrigger", () => {
202248 ) . toBe ( "assets/hero.png" ) ;
203249 } ) ;
204250} ) ;
251+
252+ describe ( "rendersSdrOnly" , ( ) => {
253+ it ( "is true for an auto render with graded media, so HDR sources are tone-mapped before the grade" , ( ) => {
254+ expect ( rendersSdrOnly ( { hdrMode : undefined , format : "mp4" } , GRADED_VIDEO ) ) . toBe ( true ) ;
255+ expect ( rendersSdrOnly ( { hdrMode : "auto" , format : "mp4" } , NO_MEDIA ) ) . toBe ( false ) ;
256+ expect ( rendersSdrOnly ( { hdrMode : "force-hdr" , format : "mp4" } , GRADED_VIDEO ) ) . toBe ( false ) ;
257+ } ) ;
258+ } ) ;
0 commit comments