2
* Copyright (C) 2010 Google Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
#ifndef ImageOrientation_h
27
#define ImageOrientation_h
31
class AffineTransform;
34
// This enum intentionally matches the orientation values from the EXIF spec.
35
// See JEITA CP-3451, page 18. http://www.exif.org/Exif2-2.PDF
36
enum ImageOrientationEnum {
37
// "TopLeft" means that the 0 row starts at the Top, the 0 column starts at the Left.
38
OriginTopLeft = 1, // default
39
OriginTopRight = 2, // mirror along y-axis
40
OriginBottomRight = 3, // 180 degree rotation
41
OriginBottomLeft = 4, // mirror along the x-axis
42
OriginLeftTop = 5, // mirror along x-axis + 270 degree CW rotation
43
OriginRightTop = 6, // 90 degree CW rotation
44
OriginRightBottom = 7, // mirror along x-axis + 90 degree CW rotation
45
OriginLeftBottom = 8, // 270 degree CW rotation
46
// All other values are "reserved" as of EXIF 2.2
47
DefaultImageOrientation = OriginTopLeft,
50
enum RespectImageOrientationEnum {
51
DoNotRespectImageOrientation = 0,
52
RespectImageOrientation = 1
55
class ImageOrientation {
57
ImageOrientation(ImageOrientationEnum orientation = DefaultImageOrientation)
58
: m_orientation(orientation)
62
bool usesWidthAsHeight() const
64
// Values 5 through 8 all flip the width/height.
65
return m_orientation >= OriginLeftTop;
68
// ImageOrientationEnum currently matches EXIF values, however code outside
69
// this function should never assume that.
70
static ImageOrientation fromEXIFValue(int exifValue)
72
// Values direct from images may be invalid, in which case we use the default.
73
if (exifValue < OriginTopLeft || exifValue > OriginLeftBottom)
74
return DefaultImageOrientation;
75
return static_cast<ImageOrientationEnum>(exifValue);
78
// This transform can be used for drawing an image according to the orientation.
79
// It should be used in a right-handed coordinate system.
80
AffineTransform transformFromDefault(const FloatSize& drawnSize) const;
82
inline bool operator==(const ImageOrientation& other) const { return other.m_orientation == m_orientation; }
83
inline bool operator!=(const ImageOrientation& other) const { return !(*this == other); }
86
// FIXME: This only needs to be one byte.
87
ImageOrientationEnum m_orientation;
90
} // namespace WebCore
92
#endif // ImageOrientation_h