image/decoders/EXIF.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/decoders/EXIF.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,76 @@
     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_EXIF_H_
    1.10 +#define MOZILLA_IMAGELIB_EXIF_H_
    1.11 +
    1.12 +#include <stdint.h>
    1.13 +#include "mozilla/TypedEnum.h"
    1.14 +#include "nsDebug.h"
    1.15 +
    1.16 +#include "Orientation.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace image {
    1.20 +
    1.21 +MOZ_BEGIN_ENUM_CLASS(ByteOrder, uint8_t)
    1.22 +  Unknown,
    1.23 +  LittleEndian,
    1.24 +  BigEndian
    1.25 +MOZ_END_ENUM_CLASS(ByteOrder)
    1.26 +
    1.27 +struct EXIFData
    1.28 +{
    1.29 +  EXIFData() { }
    1.30 +  explicit EXIFData(Orientation aOrientation) : orientation(aOrientation) { }
    1.31 +
    1.32 +  const Orientation orientation;
    1.33 +};
    1.34 +
    1.35 +class EXIFParser
    1.36 +{
    1.37 +public:
    1.38 +  static EXIFData
    1.39 +  Parse(const uint8_t* aData, const uint32_t aLength)
    1.40 +  {
    1.41 +    EXIFParser parser;
    1.42 +    return parser.ParseEXIF(aData, aLength);
    1.43 +  }
    1.44 +
    1.45 +private:
    1.46 +  EXIFParser()
    1.47 +    : mStart(nullptr)
    1.48 +    , mCurrent(nullptr)
    1.49 +    , mLength(0)
    1.50 +    , mRemainingLength(0)
    1.51 +    , mByteOrder(ByteOrder::Unknown)
    1.52 +  { }
    1.53 +
    1.54 +  EXIFData ParseEXIF(const uint8_t* aData, const uint32_t aLength);
    1.55 +  bool ParseEXIFHeader();
    1.56 +  bool ParseTIFFHeader(uint32_t& aIFD0OffsetOut);
    1.57 +  bool ParseIFD0(Orientation& aOrientationOut);
    1.58 +  bool ParseOrientation(uint16_t aType, uint32_t aCount, Orientation& aOut);
    1.59 +
    1.60 +  bool Initialize(const uint8_t* aData, const uint32_t aLength);
    1.61 +  void Advance(const uint32_t aDistance);
    1.62 +  void JumpTo(const uint32_t aOffset);
    1.63 +
    1.64 +  bool MatchString(const char* aString, const uint32_t aLength);
    1.65 +  bool MatchUInt16(const uint16_t aValue);
    1.66 +  bool ReadUInt16(uint16_t& aOut);
    1.67 +  bool ReadUInt32(uint32_t& aOut);
    1.68 +
    1.69 +  const uint8_t* mStart;
    1.70 +  const uint8_t* mCurrent;
    1.71 +  uint32_t       mLength;
    1.72 +  uint32_t       mRemainingLength;
    1.73 +  ByteOrder      mByteOrder;
    1.74 +};
    1.75 +
    1.76 +}
    1.77 +}
    1.78 +
    1.79 +#endif

mercurial