image/src/Orientation.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/src/Orientation.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_IMAGELIB_ORIENTATION_H_
    1.10 +#define MOZILLA_IMAGELIB_ORIENTATION_H_
    1.11 +
    1.12 +#include <stdint.h>
    1.13 +#include "mozilla/TypedEnum.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace image {
    1.17 +
    1.18 +MOZ_BEGIN_ENUM_CLASS(Angle, uint8_t)
    1.19 +  D0,
    1.20 +  D90,
    1.21 +  D180,
    1.22 +  D270
    1.23 +MOZ_END_ENUM_CLASS(Angle)
    1.24 +
    1.25 +MOZ_BEGIN_ENUM_CLASS(Flip, uint8_t)
    1.26 +  Unflipped,
    1.27 +  Horizontal
    1.28 +MOZ_END_ENUM_CLASS(Flip)
    1.29 +
    1.30 +/**
    1.31 + * A struct that describes an image's orientation as a rotation optionally
    1.32 + * followed by a reflection. This may be used to be indicate an image's inherent
    1.33 + * orientation or a desired orientation for the image.
    1.34 + */
    1.35 +struct Orientation
    1.36 +{
    1.37 +  Orientation(Angle aRotation = Angle::D0, Flip mFlip = Flip::Unflipped)
    1.38 +    : rotation(aRotation)
    1.39 +    , flip(mFlip)
    1.40 +  { }
    1.41 +
    1.42 +  bool IsIdentity() const {
    1.43 +    return (rotation == Angle::D0) && (flip == Flip::Unflipped);
    1.44 +  }
    1.45 +
    1.46 +  bool SwapsWidthAndHeight() const {
    1.47 +    return (rotation == Angle::D90) || (rotation == Angle::D270);
    1.48 +  }
    1.49 +
    1.50 +  bool operator==(const Orientation& aOther) const {
    1.51 +    return (rotation == aOther.rotation) && (flip == aOther.flip);
    1.52 +  }
    1.53 +
    1.54 +  bool operator!=(const Orientation& aOther) const {
    1.55 +    return !(*this == aOther);
    1.56 +  }
    1.57 +
    1.58 +  Angle rotation;
    1.59 +  Flip  flip;
    1.60 +};
    1.61 +
    1.62 +}
    1.63 +}
    1.64 +
    1.65 +#endif

mercurial