@@ -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,14 +382,14 @@ 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
393393 bytes += frameSize.width * frameSize.height * bytesPerSample; // Luma plane
394394 if (this ->subsampling == Subsampling::YUV_444)
395395 bytes += frameSize.width * frameSize.height * bytesPerSample * 2 ; // U/V planes
@@ -426,17 +426,16 @@ int64_t PixelFormatYUV::bytesPerFrame(const Size &frameSize) const
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