Bug 1243538: P2. Add convenience VideoInfo::ScaledImageRect. r?mattwoodrow
It is considered valid for a webm video to return a decoded size different to the metadata values. ScaledImageRect will scale the cropping rectangle according to the original cropping aspect ratio.
MozReview-Commit-ID: BcpoqQhEQB1
--- a/dom/media/MediaInfo.h
+++ b/dom/media/MediaInfo.h
@@ -230,16 +230,37 @@ public:
return mImageRect;
}
void SetImageRect(const nsIntRect& aRect)
{
mImageRect = aRect;
}
+ // Returned the crop rectangle scaled to aWidth/aHeight size relative to
+ // mImage size.
+ // If aWidth and aHeight are identical to the original mImage.width/mImage.height
+ // then the scaling ratio will be 1.
+ // This is used for when the frame size is different from what the container
+ // reports. This is legal in WebM, and we will preserve the ratio of the crop
+ // rectangle as it was reported relative to the picture size reported by the
+ // container.
+ nsIntRect ScaledImageRect(int64_t aWidth, int64_t aHeight) const
+ {
+ if (aWidth == mImage.width && aHeight == mImage.height) {
+ return ImageRect();
+ }
+ nsIntRect imageRect = ImageRect();
+ imageRect.x = (imageRect.x * aWidth) / mImage.width;
+ imageRect.y = (imageRect.y * aHeight) / mImage.height;
+ imageRect.width = (aWidth * imageRect.width) / mImage.width;
+ imageRect.height = (aHeight * imageRect.height) / mImage.height;
+ return imageRect;
+ }
+
// Size in pixels at which the video is rendered. This is after it has
// been scaled by its aspect ratio.
nsIntSize mDisplay;
// Indicates the frame layout for single track stereo videos.
StereoMode mStereoMode;
// Size of the decoded video's image.