15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2010 Google Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met: 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer. 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * documentation and/or other materials provided with the distribution. 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef ImageOrientation_h 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define ImageOrientation_h 285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 291e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)#include "platform/PlatformExport.h" 301e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 31c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class AffineTransform; 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class FloatSize; 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// This enum intentionally matches the orientation values from the EXIF spec. 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// See JEITA CP-3451, page 18. http://www.exif.org/Exif2-2.PDF 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)enum ImageOrientationEnum { 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // "TopLeft" means that the 0 row starts at the Top, the 0 column starts at the Left. 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginTopLeft = 1, // default 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginTopRight = 2, // mirror along y-axis 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginBottomRight = 3, // 180 degree rotation 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginBottomLeft = 4, // mirror along the x-axis 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginLeftTop = 5, // mirror along x-axis + 270 degree CW rotation 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginRightTop = 6, // 90 degree CW rotation 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginRightBottom = 7, // mirror along x-axis + 90 degree CW rotation 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OriginLeftBottom = 8, // 270 degree CW rotation 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // All other values are "reserved" as of EXIF 2.2 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) DefaultImageOrientation = OriginTopLeft, 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)enum RespectImageOrientationEnum { 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) DoNotRespectImageOrientation = 0, 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) RespectImageOrientation = 1 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 571e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class PLATFORM_EXPORT ImageOrientation { 585c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ImageOrientation(ImageOrientationEnum orientation = DefaultImageOrientation) 605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) : m_orientation(orientation) 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) { 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool usesWidthAsHeight() const 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) { 665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Values 5 through 8 all flip the width/height. 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return m_orientation >= OriginLeftTop; 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // ImageOrientationEnum currently matches EXIF values, however code outside 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // this function should never assume that. 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static ImageOrientation fromEXIFValue(int exifValue) 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) { 745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Values direct from images may be invalid, in which case we use the default. 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) if (exifValue < OriginTopLeft || exifValue > OriginLeftBottom) 765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return DefaultImageOrientation; 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) return static_cast<ImageOrientationEnum>(exifValue); 785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // This transform can be used for drawing an image according to the orientation. 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // It should be used in a right-handed coordinate system. 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) AffineTransform transformFromDefault(const FloatSize& drawnSize) const; 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) inline bool operator==(const ImageOrientation& other) const { return other.m_orientation == m_orientation; } 855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) inline bool operator!=(const ImageOrientation& other) const { return !(*this == other); } 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)private: 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // FIXME: This only needs to be one byte. 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ImageOrientationEnum m_orientation; 905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 92c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // ImageOrientation_h 95