MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / ParseVideoFrameCopyToOptions

Function ParseVideoFrameCopyToOptions

src/video_frame.ts:503–539  ·  view source on GitHub ↗
(
	frame: VideoFramePolyfill,
	options: VideoFrameCopyToOptions,
)

Source from the content-addressed store, hash-verified

501};
502
503const ParseVideoFrameCopyToOptions = (
504 frame: VideoFramePolyfill,
505 options: VideoFrameCopyToOptions,
506): CombinedBufferLayout => {
507 // 1. Let defaultRect be the result of performing the getter steps for visibleRect.
508 const defaultRect = frame.visibleRect!;
509
510 // 2. Let overrideRect be undefined.
511 // 3. If options.rect exists, assign the value of options.rect to overrideRect.
512 const overrideRect = options.rect;
513
514 // 4. Let parsedRect be the result of running the Parse Visible Rect algorithm...
515 const parsedRect = ParseVisibleRect(defaultRect, overrideRect, frame.codedWidth, frame.codedHeight, frame.format);
516
517 // 5. If parsedRect is an exception, return parsedRect. (Handled by throw)
518
519 // 6. Let optLayout be undefined.
520 // 7. If options.layout exists, assign its value to optLayout.
521 const optLayout = options.layout;
522
523 // 8. Let format be undefined.
524 let format: VideoPixelFormat | undefined;
525
526 // 9. If options.format does not exist, assign [[format]] to format.
527 if (!options.format) {
528 format = frame.format!;
529 } else if (['RGBA', 'RGBX', 'BGRA', 'BGRX'].includes(options.format)) {
530 // 10. Otherwise, if options.format is equal to one of RGBA, RGBX, BGRA, BGRX, then assign options.format
531 // to format...
532 format = options.format;
533 } else {
534 throw new Error('NotSupportedError: Invalid destination format');
535 }
536
537 // 11. Let combinedLayout be the result of running the Compute Layout and Allocation Size algorithm...
538 return ComputeLayoutAndAllocationSize(parsedRect, format, optLayout);
539};
540
541const ConvertToRGBFrame = async (
542 frame: VideoFramePolyfill,

Callers 2

allocationSizeMethod · 0.85
copyToMethod · 0.85

Calls 2

ParseVisibleRectFunction · 0.85

Tested by

no test coverage detected