@@ -127,7 +127,7 @@ - (CVPixelBufferRef)yuvToHDRPixelBufferWithWidth:(NSInteger)width height:(NSInte
127127 (NSString *)kCVPixelBufferCGBitmapContextCompatibilityKey : @YES ,
128128 (NSString *)kCVPixelBufferWidthKey : @(width),
129129 (NSString *)kCVPixelBufferHeightKey : @(height),
130- (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_420YpCbCr10BiPlanarFullRange ),
130+ (NSString *)kCVPixelBufferPixelFormatTypeKey : @(kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange ),
131131 (NSString *)kCVPixelBufferMetalCompatibilityKey : @YES ,
132132 (NSString *)kCVPixelBufferPoolAllocationThresholdKey : @1
133133 };
@@ -136,7 +136,7 @@ - (CVPixelBufferRef)yuvToHDRPixelBufferWithWidth:(NSInteger)width height:(NSInte
136136 CVReturn status = CVPixelBufferCreate (kCFAllocatorDefault ,
137137 width,
138138 height,
139- kCVPixelFormatType_420YpCbCr10BiPlanarFullRange ,
139+ kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange ,
140140 (__bridge CFDictionaryRef)pixelBufferAttributes,
141141 &pixelBuffer);
142142
@@ -197,7 +197,7 @@ - (CVPixelBufferRef)yuvToHDRPixelBufferWithWidth:(NSInteger)width height:(NSInte
197197 free (uPlane);
198198 free (vPlane);
199199 CVPixelBufferUnlockBaseAddress (pixelBuffer, 0 );
200- CVPixelBufferRelease (pixelBuffer);
200+ CVPixelBufferRelease (pixelBuffer);
201201 return NULL ;
202202 }
203203
@@ -212,7 +212,8 @@ - (CVPixelBufferRef)yuvToHDRPixelBufferWithWidth:(NSInteger)width height:(NSInte
212212
213213 // Normalize Y data to [0, 65535]
214214 for (size_t i = 0 ; i < width * height; i++) {
215- yBuffer[i] = (uint16_t )(yBuffer[i] * (65535.0 / 1023.0 )); // Normalize Y component
215+ // yBuffer[i] = (uint16_t)(yBuffer[i] * (65535.0 / 1023.0)); // Full Range
216+ yBuffer[i] = (uint16_t )((yBuffer[i] - 64 ) * (65535.0 / (940 - 64 ))); // Video Range
216217 }
217218
218219 // Process U and V data
@@ -225,11 +226,13 @@ - (CVPixelBufferRef)yuvToHDRPixelBufferWithWidth:(NSInteger)width height:(NSInte
225226
226227 // Normalize U component
227228 uint16_t uValue = uPlane[i]; // U
228- uValue = (uint16_t )((uValue - 512 ) * (65535.0 / 511.0 ) + 32768 );
229+ // uValue = (uint16_t)((uValue - 512) * (65535.0 / 511.0) + 32768);
230+ uValue = (uint16_t )((uValue - 64 ) * (65535.0 / (960 - 64 )));
229231
230232 // Normalize V component
231233 uint16_t vValue = vPlane[i]; // V
232- vValue = (uint16_t )((vValue - 512 ) * (65535.0 / 511.0 ) + 32768 );
234+ // vValue = (uint16_t)((vValue - 512) * (65535.0 / 511.0) + 32768);
235+ vValue = (uint16_t )((vValue - 64 ) * (65535.0 / (960 - 64 )));
233236
234237 // Write back normalized values
235238 uvPlane[i * 2 ] = uValue;
0 commit comments