@@ -174,7 +174,7 @@ PixelFormatYUV::PixelFormatYUV(const std::string &name)
174174 auto bitdepthStr = sm.str (3 );
175175 size_t sz;
176176 int bitDepth = std::stoi (bitdepthStr, &sz);
177- if (sz > 0 && bitDepth >= 8 && bitDepth <= 16 )
177+ if (sz > 0 && bitDepth >= 8 && bitDepth <= 32 )
178178 newFormat.bitsPerSample = bitDepth;
179179 }
180180
@@ -317,7 +317,7 @@ bool PixelFormatYUV::canConvertToRGB(Size imageSize, std::string *whyNot) const
317317 // Check the bit depth
318318 const int bps = this ->bitsPerSample ;
319319 bool canConvert = true ;
320- if (bps < 8 || bps > 16 )
320+ if (bps < 8 || bps > 32 )
321321 {
322322 if (whyNot)
323323 {
@@ -382,28 +382,28 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
382382 }
383383
384384 int64_t bytes = 0 ;
385+ const auto bytesPerSample = get_min_standard_bytes (this ->bitsPerSample ); // Round to bytes
385386
386387 if (this ->planar || !this ->bytePacking )
387388 {
388389 // Add the bytes of the 3 (or 4) planes.
389390 // This also works for packed formats without byte packing. For these formats the number of
390391 // bytes are identical to the not packed formats, the bytes are just sorted in another way.
391392
392- const auto bytesPerSample = (this ->bitsPerSample + 7 ) / 8 ; // Round to bytes
393- bytes += frameSize.width * frameSize.height * bytesPerSample; // Luma plane
393+ bytes += (int64_t )frameSize.width * frameSize.height * bytesPerSample; // Luma plane
394394 if (this ->subsampling == Subsampling::YUV_444 )
395- bytes += frameSize.width * frameSize.height * bytesPerSample * 2 ; // U/V planes
395+ bytes += ( int64_t ) frameSize.width * frameSize.height * bytesPerSample * 2 ; // U/V planes
396396 else if (this ->subsampling == Subsampling::YUV_422 || this ->subsampling == Subsampling::YUV_440 )
397- bytes += (frameSize.width / 2 ) * frameSize.height * bytesPerSample *
397+ bytes += (int64_t )( frameSize.width / 2 ) * frameSize.height * bytesPerSample *
398398 2 ; // U/V planes, half the width
399399 else if (this ->subsampling == Subsampling::YUV_420 )
400- bytes += (frameSize.width / 2 ) * (frameSize.height / 2 ) * bytesPerSample *
400+ bytes += (int64_t )( frameSize.width / 2 ) * (frameSize.height / 2 ) * bytesPerSample *
401401 2 ; // U/V planes, half the width and height
402402 else if (this ->subsampling == Subsampling::YUV_410 )
403- bytes += (frameSize.width / 4 ) * (frameSize.height / 4 ) * bytesPerSample *
403+ bytes += (int64_t )( frameSize.width / 4 ) * (frameSize.height / 4 ) * bytesPerSample *
404404 2 ; // U/V planes, half the width and height
405405 else if (this ->subsampling == Subsampling::YUV_411 )
406- bytes += (frameSize.width / 4 ) * frameSize.height * bytesPerSample *
406+ bytes += (int64_t )( frameSize.width / 4 ) * frameSize.height * bytesPerSample *
407407 2 ; // U/V planes, quarter the width
408408 else if (this ->subsampling == Subsampling::YUV_400 )
409409 bytes += 0 ; // No chroma components
@@ -413,30 +413,29 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
413413 if (this ->planar &&
414414 (this ->planeOrder == PlaneOrder::YUVA || this ->planeOrder == PlaneOrder::YVUA ))
415415 // There is an additional alpha plane. The alpha plane is not subsampled
416- bytes += frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
416+ bytes += ( int64_t ) frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
417417 if (!this ->planar && this ->subsampling == Subsampling::YUV_444 &&
418418 (this ->packingOrder == PackingOrder::AYUV || this ->packingOrder == PackingOrder::YUVA ||
419419 this ->packingOrder == PackingOrder::VUYA ))
420420 // There is an additional alpha plane. The alpha plane is not subsampled
421- bytes += frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
421+ bytes += ( int64_t ) frameSize.width * frameSize.height * bytesPerSample; // Alpha plane
422422 }
423423 else
424424 {
425425 // This is a packed format with byte packing
426426 if (this ->subsampling == Subsampling::YUV_422 )
427427 {
428428 // All packing orders have 4 values per packed value (which has 2 Y samples)
429- const auto bitsPerPixel = this ->bitsPerSample * 4 ;
430- return ((bitsPerPixel + 7 ) / 8 ) * (frameSize.width / 2 ) * frameSize.height ;
429+ return 4 * bytesPerSample * (frameSize.width / 2 ) * frameSize.height ;
431430 }
432431 // This is a packed format. The added number of bytes might be lower because of the packing.
433432 if (this ->subsampling == Subsampling::YUV_444 )
434433 {
435- auto bitsPerPixel = this -> bitsPerSample * 3 ;
434+ auto channels = 3 ;
436435 if (this ->packingOrder == PackingOrder::AYUV || this ->packingOrder == PackingOrder::YUVA ||
437436 this ->packingOrder == PackingOrder::VUYA )
438- bitsPerPixel += this -> bitsPerSample ;
439- return ((bitsPerPixel + 7 ) / 8 ) * frameSize.width * frameSize.height ;
437+ channels += 1 ;
438+ return channels * bytesPerSample * frameSize.width * frameSize.height ;
440439 }
441440 // else if (subsampling == Subsampling::YUV_422 || subsampling == Subsampling::YUV_440)
442441 // {
0 commit comments