Bug 1243538: P2. Add convenience VideoInfo::ScaledImageRect. r?mattwoodrow draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 15 Apr 2016 16:39:15 +1000
changeset 352918 b44b7873f89dd23ab153a71d3027eaccc4e49738
parent 352917 d373d7ba54b3c2017e6cf08287d080a01d5aae12
child 352919 e086de0745e866c6a6a0ec50db9426c5585a39c8
push id15841
push userbmo:jyavenard@mozilla.com
push dateTue, 19 Apr 2016 00:09:30 +0000
reviewersmattwoodrow
bugs1243538
milestone48.0a1
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
dom/media/MediaInfo.h
--- 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.