@@ -175,7 +175,7 @@ PixelFormatYUV::PixelFormatYUV(const std::string_view name)
175175 auto bitdepthStr = sm.str (3 );
176176 size_t sz;
177177 int bitDepth = std::stoi (bitdepthStr, &sz);
178- if (sz > 0 && bitDepth >= 8 && bitDepth <= 16 )
178+ if (sz > 0 && bitDepth >= 8 && bitDepth <= 32 )
179179 newFormat.bitsPerSample = bitDepth;
180180 }
181181
@@ -318,7 +318,7 @@ bool PixelFormatYUV::canConvertToRGB(Size imageSize, std::string *whyNot) const
318318 // Check the bit depth
319319 const int bps = this ->bitsPerSample ;
320320 bool canConvert = true ;
321- if (bps < 8 || bps > 16 )
321+ if (bps < 8 || bps > 32 )
322322 {
323323 if (whyNot)
324324 {
@@ -383,28 +383,28 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
383383 }
384384
385385 int64_t bytes = 0 ;
386+ const auto bytesPerSample = get_min_standard_bytes (this ->bitsPerSample ); // Round to bytes
386387
387388 if (this ->planar || !this ->bytePacking )
388389 {
389390 // Add the bytes of the 3 (or 4) planes.
390391 // This also works for packed formats without byte packing. For these formats the number of
391392 // bytes are identical to the not packed formats, the bytes are just sorted in another way.
392393
393- const auto bytesPerSample = (this ->bitsPerSample + 7 ) / 8 ; // Round to bytes
394- bytes += frameSize.width * frameSize.height * bytesPerSample; // Luma plane
394+ bytes += (int64_t )frameSize.width * frameSize.height * bytesPerSample; // Luma plane
395395 if (this ->subsampling == Subsampling::YUV_444 )
396- bytes += frameSize.width * frameSize.height * bytesPerSample * 2 ; // U/V planes
396+ bytes += ( int64_t ) frameSize.width * frameSize.height * bytesPerSample * 2 ; // U/V planes
397397 else if (this ->subsampling == Subsampling::YUV_422 || this ->subsampling == Subsampling::YUV_440 )
398398 bytes +=
399- (frameSize.width / 2 ) * frameSize.height * bytesPerSample * 2 ; // U/V planes, half the width
399+ (int64_t )( frameSize.width / 2 ) * frameSize.height * bytesPerSample * 2 ; // U/V planes, half the width
400400 else if (this ->subsampling == Subsampling::YUV_420 )
401- bytes += (frameSize.width / 2 ) * (frameSize.height / 2 ) * bytesPerSample *
401+ bytes += (int64_t )( frameSize.width / 2 ) * (frameSize.height / 2 ) * bytesPerSample *
402402 2 ; // U/V planes, half the width and height
403403 else if (this ->subsampling == Subsampling::YUV_410 )
404- bytes += (frameSize.width / 4 ) * (frameSize.height / 4 ) * bytesPerSample *
404+ bytes += (int64_t )( frameSize.width / 4 ) * (frameSize.height / 4 ) * bytesPerSample *
405405 2 ; // U/V planes, half the width and height
406406 else if (this ->subsampling == Subsampling::YUV_411 )
407- bytes += (frameSize.width / 4 ) * frameSize.height * bytesPerSample *
407+ bytes += (int64_t )( frameSize.width / 4 ) * frameSize.height * bytesPerSample *
408408 2 ; // U/V planes, quarter the width
409409 else if (this ->subsampling == Subsampling::YUV_400 )
410410 bytes += 0 ; // No chroma components
@@ -414,30 +414,29 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
414414 if (this ->planar &&
415415 (this ->planeOrder == PlaneOrder::YUVA || this ->planeOrder == PlaneOrder::YVUA ))
416416 // There is an additional alpha plane. The alpha plane is not subsampled
417- bytes += frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
417+ bytes += ( int64_t ) frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
418418 if (!this ->planar && this ->subsampling == Subsampling::YUV_444 &&
419419 (this ->packingOrder == PackingOrder::AYUV || this ->packingOrder == PackingOrder::YUVA ||
420420 this ->packingOrder == PackingOrder::VUYA ))
421421 // There is an additional alpha plane. The alpha plane is not subsampled
422- bytes += frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
422+ bytes += ( int64_t ) frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
423423 }
424424 else
425425 {
426426 // This is a packed format with byte packing
427427 if (this ->subsampling == Subsampling::YUV_422 )
428428 {
429429 // All packing orders have 4 values per packed value (which has 2 Y samples)
430- const auto bitsPerPixel = this ->bitsPerSample * 4 ;
431- return ((bitsPerPixel + 7 ) / 8 ) * (frameSize.width / 2 ) * frameSize.height ;
430+ return 4 * bytesPerSample * (frameSize.width / 2 ) * frameSize.height ;
432431 }
433432 // This is a packed format. The added number of bytes might be lower because of the packing.
434433 if (this ->subsampling == Subsampling::YUV_444 )
435434 {
436- auto bitsPerPixel = this -> bitsPerSample * 3 ;
435+ auto channels = 3 ;
437436 if (this ->packingOrder == PackingOrder::AYUV || this ->packingOrder == PackingOrder::YUVA ||
438437 this ->packingOrder == PackingOrder::VUYA )
439- bitsPerPixel += this -> bitsPerSample ;
440- return ((bitsPerPixel + 7 ) / 8 ) * frameSize.width * frameSize.height ;
438+ channels += 1 ;
439+ return channels * bytesPerSample * frameSize.width * frameSize.height ;
441440 }
442441 // else if (subsampling == Subsampling::YUV_422 || subsampling == Subsampling::YUV_440)
443442 // {
0 commit comments