1 #ifndef IMAGE_IO_JPEG_JPEG_SEGMENT_INFO_H_ // NOLINT 2 #define IMAGE_IO_JPEG_JPEG_SEGMENT_INFO_H_ // NOLINT 3 4 #include <string> 5 #include <vector> 6 7 #include "image_io/base/data_range.h" 8 #include "image_io/base/types.h" 9 10 namespace photos_editing_formats { 11 namespace image_io { 12 13 /// Interesting segment types. 14 const char kExif[] = "Exif"; 15 const char kJfif[] = "JFIF"; 16 const char kMpf[] = "MPF"; 17 18 /// A class that holds interesting information about a JpegSegment. 19 class JpegSegmentInfo { 20 public: 21 /// @param image_index The index of the image in a @c DataSource that contains 22 /// the segment. 23 /// @param data_range The range in the segment in the @c DataSource. 24 /// @param type The type of segment. JpegSegmentInfo(size_t image_index,const DataRange & data_range,const std::string & type)25 JpegSegmentInfo(size_t image_index, const DataRange& data_range, 26 const std::string& type) 27 : image_index_(image_index), data_range_(data_range), type_(type) {} 28 29 /// Constructs an empty, invalid segment info. JpegSegmentInfo()30 JpegSegmentInfo() : image_index_(0) {} 31 32 JpegSegmentInfo(const JpegSegmentInfo&) = default; 33 JpegSegmentInfo& operator=(const JpegSegmentInfo&) = default; 34 35 /// @param rhs The segment info to compare with this one. 36 /// @return Whether the segment infos are equal 37 bool operator==(const JpegSegmentInfo& rhs) const { 38 return image_index_ == rhs.image_index_ && data_range_ == rhs.data_range_ && 39 type_ == rhs.type_ && bytes_ == rhs.bytes_; 40 } 41 42 /// @param rhs The segment info to compare with this one. 43 /// @return Whether the segment infos are not equal 44 bool operator!=(const JpegSegmentInfo& rhs) const { 45 return !(*this == rhs); 46 } 47 48 /// @return Whether the segment info is valid. IsValid()49 bool IsValid() const { return !type_.empty() && data_range_.IsValid(); } 50 51 /// @return The image index of the segment info. GetImageIndex()52 size_t GetImageIndex() const { return image_index_; } 53 54 /// @return The data range of the segment info. GetDataRange()55 const DataRange& GetDataRange() const { return data_range_; } 56 57 /// @return The type of the segment info. GetType()58 const std::string& GetType() const { return type_; } 59 60 /// @return The (optional) bytes of the segment to which the info refers. The 61 /// vector will be empty unless the GetMutableBytes() function has been 62 /// and the vector filled with the segment contents. GetBytes()63 const std::vector<Byte>& GetBytes() const { return bytes_; } 64 65 /// @return A non-const pointer to the bytes vector. GetMutableBytes()66 std::vector<Byte>* GetMutableBytes() { return &bytes_; } 67 68 private: 69 // The image index where the segment is located. 70 size_t image_index_; 71 72 // The data range of the segment. 73 DataRange data_range_; 74 75 // The type of segment. 76 std::string type_; 77 78 // The (optional) bytes of the segment. 79 std::vector<Byte> bytes_; 80 }; 81 82 } // namespace image_io 83 } // namespace photos_editing_formats 84 85 #endif // IMAGE_IO_JPEG_JPEG_SEGMENT_INFO_H_ // NOLINT 86