Bug 1732115 - Part 2. Move OrientedPixel and related to image/Orientation.h. r=tnikkel

Differential Revision: https://phabricator.services.mozilla.com/D126380
This commit is contained in:
Andrew Osmond 2021-10-06 14:41:17 +00:00
parent 1afab525ff
commit e2050d4c94
2 changed files with 39 additions and 20 deletions

View File

@ -7,8 +7,31 @@
#define mozilla_image_Orientation_h
#include <stdint.h>
#include "mozilla/gfx/Rect.h"
namespace mozilla {
// Pixel values in an image considering orientation metadata, such as the size
// of an image as seen by consumers of the image.
//
// Any public methods on RasterImage that use untyped units are interpreted as
// oriented pixels.
struct OrientedPixel {};
template <>
struct IsPixel<OrientedPixel> : std::true_type {};
typedef gfx::IntPointTyped<OrientedPixel> OrientedIntPoint;
typedef gfx::IntSizeTyped<OrientedPixel> OrientedIntSize;
typedef gfx::IntRectTyped<OrientedPixel> OrientedIntRect;
// Pixel values in an image ignoring orientation metadata, such as are stored
// in surfaces and the raw pixel data in the image.
struct UnorientedPixel {};
template <>
struct IsPixel<UnorientedPixel> : std::true_type {};
typedef gfx::IntPointTyped<UnorientedPixel> UnorientedIntPoint;
typedef gfx::IntSizeTyped<UnorientedPixel> UnorientedIntSize;
typedef gfx::IntRectTyped<UnorientedPixel> UnorientedIntRect;
namespace image {
enum class Angle : uint8_t { D0, D90, D180, D270 };
@ -50,6 +73,22 @@ struct Orientation {
return !(*this == aOther);
}
OrientedIntSize ToOriented(const UnorientedIntSize& aSize) const {
if (SwapsWidthAndHeight()) {
return OrientedIntSize(aSize.height, aSize.width);
} else {
return OrientedIntSize(aSize.width, aSize.height);
}
}
UnorientedIntSize ToUnoriented(const OrientedIntSize& aSize) const {
if (SwapsWidthAndHeight()) {
return UnorientedIntSize(aSize.height, aSize.width);
} else {
return UnorientedIntSize(aSize.width, aSize.height);
}
}
static Angle InvertAngle(Angle aAngle) {
switch (aAngle) {
case Angle::D90:

View File

@ -125,26 +125,6 @@ class nsIRequest;
*/
namespace mozilla {
// Pixel values in an image considering orientation metadata, such as the size
// of an image as seen by consumers of the image.
//
// Any public methods on RasterImage that use untyped units are interpreted as
// oriented pixels.
struct OrientedPixel {};
template <>
struct IsPixel<OrientedPixel> : std::true_type {};
typedef gfx::IntSizeTyped<OrientedPixel> OrientedIntSize;
typedef gfx::IntRectTyped<OrientedPixel> OrientedIntRect;
// Pixel values in an image ignoring orientation metadata, such as are stored
// in surfaces and the raw pixel data in the image.
struct UnorientedPixel {};
template <>
struct IsPixel<UnorientedPixel> : std::true_type {};
typedef gfx::IntSizeTyped<UnorientedPixel> UnorientedIntSize;
typedef gfx::IntRectTyped<UnorientedPixel> UnorientedIntRect;
namespace layers {
class ImageContainer;
class Image;