2 // Tizen Web Device API
3 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 #ifndef __TIZEN_EXIF_JPEG_FILE_H_
20 #define __TIZEN_EXIF_JPEG_FILE_H_
27 #include <libexif/exif-data.h>
28 #include <libexif/exif-entry.h>
29 #include <libexif/exif-utils.h>
35 JPEG_MARKER_UNKNOWN = 0x00,
36 JPEG_MARKER_LOWEST_ID = 0xc0,
37 JPEG_MARKER_SOI = 0xd8, //Start Of Image
38 JPEG_MARKER_EOI = 0xd9, //End Of Image
39 JPEG_MARKER_SOS = 0xda, //Start Of Stream
40 JPEG_MARKER_APP1 = 0xe1, //Application Data 1 - for Exif
41 JPEG_MARKER_HIGHEST_ID = 0xfe
44 struct JpegFileSection;
45 typedef std::shared_ptr<JpegFileSection> JpegFileSectionPtr;
47 struct JpegFileSection
50 type(JPEG_MARKER_UNKNOWN),
56 unsigned char* data_ptr;
64 typedef std::shared_ptr<JpegFile> JpegFilePtr;
68 static JpegFilePtr loadFile(const std::string& path);
71 void setNewExifData(ExifData* new_exif_data);
74 * You are responsible to unreference returned data with: exif_data_unref(...)
76 * ExifData* ed = jpeg.getExifData();
79 * exif_data_unref(ed);
82 ExifData* getExifData();
84 void saveToFile(const std::string& out_path);
88 void load(const std::string& path);
89 void generateListOfSections();
91 std::string getPartOfFile(const size_t offset,
92 const size_t num_bytes_before = 10,
93 const size_t num_bytes_after = 10);
95 JpegFileSectionPtr getExifSection();
96 void saveToFilePriv(const std::string& out_path);
99 * Search for first occurence of specific tag inside buffer.
101 * buffer_end is the first byte that should not be checked:
102 * [buffer_start ... buffer_end)
104 * For example EOI - search for first 'ffd9' in buffer
106 static bool searchForTagInBuffer(const unsigned char* buffer_start,
107 const unsigned char* buffer_end,
108 const JpegMarker marker,
111 std::string m_source_file_path;
113 unsigned char* m_in_data;
114 size_t m_in_data_size;
116 unsigned char* m_image_data;
120 * This contains any bytes after EOI.
121 * Usually there should be no extra bytes after EOI unfortunately
122 * some cameras saves extra bytes (for example Android).
124 unsigned char* m_padding_data;
125 size_t m_padding_data_size;
130 typedef std::vector<JpegFileSectionPtr> SectionsVec;
131 SectionsVec m_sections;
136 } // namespace DeviceApi
138 #endif // __TIZEN_EXIF_JPEG_FILE_H_