Bug 1243538: P2. Add convenience VideoInfo::ScaledImageRect. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 15 Apr 2016 16:39:15 +1000
changeset 331867 0285950622256037c5be511582c43976c54d07a7
parent 331866 7ce9649c759f241dcd104da7dfa28e1f333c6c9d
child 331868 58cf5d2934fb21d321a6a3f6067464b12e953323
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1243538
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.