'jpeg_file.h',
'rational.cc',
'rational.h',
- 'ExifGPSLocation.cpp',
- 'ExifGPSLocation.h',
+ 'exif_gps_location.cc',
+ 'exif_gps_location.h',
],
'conditions': [
[ 'tizen == 1', {
namespace {
const char kExtensionName[] = "tizen.exif";
const char kExifInformationEntryPoint[] = "tizen.ExifInformation";
-}
+} // namespace
common::Extension* CreateExtension() {
return new ExifExtension;
// limitations under the License.
//
-#include "ExifGPSLocation.h"
+#include "exif_gps_location.h"
+#include <string>
#include <sstream>
-#include <math.h>
+#include <cmath>
#include "common/platform_exception.h"
#include "common/logger.h"
namespace extension {
namespace exif {
-GCSPosition::GCSPosition()
-{
+GCSPosition::GCSPosition() {
}
-GCSPosition::GCSPosition(Rational _degrees, Rational _minutes, Rational _seconds) :
+GCSPosition::GCSPosition(Rational _degrees, Rational _minutes,
+ Rational _seconds) :
degrees(_degrees),
minutes(_minutes),
seconds(_seconds) {
assert(d_degrees <= 180.0);
LoggerD("d_degrees:%f d_minutes:%f d_seconds:%f",
- d_degrees, d_minutes, d_seconds);
+ d_degrees, d_minutes, d_seconds);
GCSPosition pos;
pos.degrees = Rational(static_cast<ExifLong>(d_degrees), 1);
ExifGPSLocation::ExifGPSLocation() :
m_longitude_ref(GPS_LOCATION_WEST),
m_latitude_ref(GPS_LOCATION_NORTH) {
- for(int i = 0; i < EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; ++i) {
+ for (int i = 0; i < EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; ++i) {
m_is_set[i] = false;
}
LoggerE("ExifGPSLocation::ExifGPSLocation()");
}
ExifGPSLocation::ExifGPSLocation(double longitude, double latitude) {
- for(int i = 0; i < EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; ++i) {
+ for (int i = 0; i < EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; ++i) {
m_is_set[i] = false;
}
void ExifGPSLocation::setLatitude(const GCSPosition& latitude) {
if (!latitude.isValid()) {
- LOGW("latitude is not valid!");
+ LoggerW("latitude is not valid!");
return;
}
}
double ExifGPSLocation::getLongitudeValue() const {
- const double longitude_dir = (m_longitude_ref == GPS_LOCATION_WEST) ? -1.0f : 1.0f;
+ const double longitude_dir =
+ (m_longitude_ref == GPS_LOCATION_WEST) ? -1.0f : 1.0f;
const double longitude = m_longitude.toDouble() * longitude_dir;
return longitude;
}
double ExifGPSLocation::getLatitudeValue() const {
- const double latitude_dir = (m_latitude_ref == GPS_LOCATION_SOUTH) ? -1.0f : 1.0f;
+ const double latitude_dir =
+ (m_latitude_ref == GPS_LOCATION_SOUTH) ? -1.0f : 1.0f;
const double latitude = m_latitude.toDouble() * latitude_dir;
return latitude;
}
// limitations under the License.
//
-#ifndef EXIF_EXIF_EXIFGPSLOCATION_H_
-#define EXIF_EXIF_EXIFGPSLOCATION_H_
+#ifndef EXIF_EXIF_GPS_LOCATION_H_
+#define EXIF_EXIF_GPS_LOCATION_H_
#include <string>
#include <vector>
} // namespace exif
} // namespace extension
-#endif // EXIF_EXIF_EXIFGPSLOCATION_H_
+#endif // EXIF_EXIF_GPS_LOCATION_H_
#include "exif_information.h"
#include <memory>
-#include <math.h>
-
-#include "exif_tag_saver.h"
-#include "exif_util.h"
-#include "jpeg_file.h"
+#include <cmath>
#include "common/platform_exception.h"
#include "common/converter.h"
#include "common/logger.h"
+#include "exif_tag_saver.h"
+#include "exif_util.h"
+#include "jpeg_file.h"
+
namespace extension {
namespace exif {
} // namespace
ExifInformation::ExifInformation() {
- for (int attr = 0; attr < EXIF_INFORMATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; attr++) {
+ for (int attr = 0;
+ attr < EXIF_INFORMATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; attr++) {
unset(static_cast<ExifInformationAttribute>(attr));
}
}
ExifInformation::ExifInformation(const picojson::value& args) {
- for (int attr = 0; attr < EXIF_INFORMATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; attr++) {
+ for (int attr = 0;
+ attr < EXIF_INFORMATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES; attr++) {
unset(static_cast<ExifInformationAttribute>(attr));
}
void ExifInformation::setFocalLength(Rational focal_length) {
LoggerD("Entered");
- if(!focal_length.isValid()) {
- LoggerW("Trying to set invalid focal length: %s", focal_length.toString().c_str());
+ if (!focal_length.isValid()) {
+ LoggerW("Trying to set invalid focal length: %s",
+ focal_length.toString().c_str());
return;
}
void ExifInformation::setGpsAltitude(Rational gps_altitude) {
LoggerD("Entered");
if (!gps_altitude.isValid()) {
- LoggerW("Trying to set invalid gps altitude: %s", gps_altitude.toString().c_str());
+ LoggerW("Trying to set invalid gps altitude: %s",
+ gps_altitude.toString().c_str());
return;
}
LoggerD("Entered");
setGpsAltitude(Rational::createFromDouble(fabs(gps_altitude)));
- if(gps_altitude >= 0.0) {
+ if (gps_altitude >= 0.0) {
setGpsAltitudeRef(GPS_ALTITUDE_REF_ABOVE_SEA);
} else {
setGpsAltitudeRef(GPS_ALTITUDE_REF_BELOW_SEA);
LoggerD("Entered | name: %s", attributeName.c_str());
switch (str2int(attributeName.c_str())) {
- case str2int(EI_URI):
+ case str2int(EI_URI): {
setUri(v.get<std::string>());
break;
- case str2int(EI_WIDTH):
+ }
+ case str2int(EI_WIDTH): {
setWidth(static_cast<int>(v.get<double>()));
break;
- case str2int(EI_HEIGHT):
+ }
+ case str2int(EI_HEIGHT): {
setHeight(static_cast<int>(v.get<double>()));
break;
- case str2int(EI_DEVICE_MAKER):
+ }
+ case str2int(EI_DEVICE_MAKER): {
setDeviceMaker(v.get<std::string>());
break;
- case str2int(EI_DEVICE_MODEL):
+ }
+ case str2int(EI_DEVICE_MODEL): {
setDeviceModel(v.get<std::string>());
break;
- case str2int(EI_ORIGINAL_TIME):
+ }
+ case str2int(EI_ORIGINAL_TIME): {
setOriginalTime(static_cast<unsigned long long>(v.get<double>()));
break;
- case str2int(EI_ORIENTATION):
+ }
+ case str2int(EI_ORIENTATION): {
setOrientation(v.get<std::string>());
break;
- case str2int(EI_FNUMBER):
+ }
+ case str2int(EI_FNUMBER): {
setFNumber(Rational::createFromDouble(v.get<double>()));
break;
- case str2int(EI_ISO_SPEED_RATINGS):
+ }
+ case str2int(EI_ISO_SPEED_RATINGS): {
setIsoSpeedRatings(jsonArray2vector(v));
break;
- case str2int(EI_EXPOSURE_TIME):
+ }
+ case str2int(EI_EXPOSURE_TIME): {
setExposureTime(
Rational::createFromExposureTimeString(v.get<std::string>()));
break;
- case str2int(EI_EXPOSURE_PROGRAM):
+ }
+ case str2int(EI_EXPOSURE_PROGRAM): {
setExposureProgram(v.get<std::string>());
break;
- case str2int(EI_FLASH):
+ }
+ case str2int(EI_FLASH): {
setFlash(v.get<bool>());
break;
- case str2int(EI_FOCAL_LENGTH):
+ }
+ case str2int(EI_FOCAL_LENGTH): {
setFocalLength(Rational::createFromDouble(v.get<double>()));
break;
- case str2int(EI_WHITE_BALANCE):
+ }
+ case str2int(EI_WHITE_BALANCE): {
setWhiteBalanceMode(v.get<std::string>());
break;
- case str2int(EI_GPS_LOCATION):
+ }
+ case str2int(EI_GPS_LOCATION): {
setGPSLocation(ExifGPSLocation(v.get("longitude").get<double>(),
v.get("latitude").get<double>()));
break;
- case str2int(EI_GPS_ALTITUDE):
+ }
+ case str2int(EI_GPS_ALTITUDE): {
setGpsAltitudeWithRef(v.get<double>());
break;
- case str2int(EI_GPS_PROCESSING_METHOD):
+ }
+ case str2int(EI_GPS_PROCESSING_METHOD): {
setGpsProcessingMethod(EXIF_UNDEFINED_TYPE_ASCII, v.get<std::string>());
break;
- case str2int(EI_GPS_TIME):
+ }
+ case str2int(EI_GPS_TIME): {
setGpsTime(static_cast<unsigned long long>(v.get<double>()));
- break;
- case str2int(EI_USER_COMMENT):
+ break;
+ }
+ case str2int(EI_USER_COMMENT): {
setUserComment(EXIF_UNDEFINED_TYPE_ASCII, v.get<std::string>());
break;
+ }
default:
break;
}
}
-bool getGCSPositionFromEntry(ExifEntry *entry, ExifData* exif_data, GCSPosition& out_pos) {
- //RATIONAL - 3
+bool getGCSPositionFromEntry(ExifEntry *entry, ExifData* exif_data,
+ GCSPosition& out_pos) {
+ // RATIONAL - 3
if (EXIF_FORMAT_RATIONAL == entry->format &&
entry->components >= 3 &&
entry->data) {
out_pos.seconds = Rational(exif_get_rational(
entry->data + 2*ExifTypeInfo::RationalSize, order));
return true;
- }
- else {
+ } else {
return false;
}
}
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
unsigned char* ptr = entry->data;
- for(unsigned long i = 0; i < required_count; ++i) {
+ for (unsigned long i = 0; i < required_count; ++i) {
out_rationals.push_back(Rational(exif_get_rational(ptr, order)));
ptr += ExifTypeInfo::RationalSize;
}
return true;
- }
- else {
+ } else {
return false;
}
}
Rational getRationalFromEntry(ExifEntry *entry, ExifData* exif_data) {
- if (EXIF_FORMAT_RATIONAL == entry->format && entry->components >= 1 && entry->data) {
+ if (EXIF_FORMAT_RATIONAL == entry->format &&
+ entry->components >= 1 &&
+ entry->data) {
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
return Rational(exif_get_rational(entry->data, order));
- }
- else {
+ } else {
return Rational::createInvalid();
}
}
-bool decomposeExifUndefined(ExifEntry* entry, std::string& type, std::string& value) {
- if(!entry || !entry->data) {
+bool decomposeExifUndefined(ExifEntry* entry, std::string& type,
+ std::string& value) {
+ if (!entry || !entry->data) {
LoggerW("exif entry is NULL/empty");
return false;
}
- if(entry->size < EXIF_UNDEFINED_TYPE_LENGTH) {
- LoggerW("entry size is invalid %d < EXIF_UNDEFINED_TYPE_LENGTH", entry->size);
+ if (entry->size < EXIF_UNDEFINED_TYPE_LENGTH) {
+ LoggerW("entry size is invalid %d < EXIF_UNDEFINED_TYPE_LENGTH",
+ entry->size);
return false;
}
switch (static_cast<unsigned int>(entry->tag)) {
case EXIF_TAG_IMAGE_WIDTH: {
- //SHORT or LONG - 1
+ // SHORT or LONG - 1
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation width to: [%s]", buf );
+ LoggerD("Setting ExifInformation width to: [%s]", buf);
setWidth(atol(buf));
break;
}
case EXIF_TAG_IMAGE_LENGTH: {
- //SHORT or LONG - 1
+ // SHORT or LONG - 1
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation height to: [%s]", buf );
+ LoggerD("Setting ExifInformation height to: [%s]", buf);
setHeight(atol(buf));
break;
}
case EXIF_TAG_MAKE: {
- //ASCII - Any
+ // ASCII - Any
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation maker to: [%s]", buf );
+ LoggerD("Setting ExifInformation maker to: [%s]", buf);
setDeviceMaker(std::string(buf));
break;
}
case EXIF_TAG_MODEL: {
- //ASCII - Any
+ // ASCII - Any
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation model to: [%s]", buf );
+ LoggerD("Setting ExifInformation model to: [%s]", buf);
setDeviceModel(std::string(buf));
break;
}
case EXIF_TAG_DATE_TIME_ORIGINAL: {
- //ASCII - 20
+ // ASCII - 20
exif_entry_get_value(entry, buf, sizeof(buf));
const time_t time = ExifUtil::exifDateTimeOriginalToTimeT(
reinterpret_cast<const char*>(entry->data));
- LoggerD( "Setting ExifInformation time original to: [%s] time_t:%d", buf,
- (int)time);
+ LoggerD("Setting ExifInformation time original to: [%s] time_t:%d", buf,
+ static_cast<int>(time));
setOriginalTime(time);
}
case EXIF_TAG_ORIENTATION: {
- //SHORT - 1
+ // SHORT - 1
exif_entry_get_value(entry, buf, sizeof(buf));
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
const ExifShort orient(exif_get_short(entry->data, order));
- if(orient < EXIF_ORIENTATION_NORMAL || orient >= EXIF_ORIENTATION_NOT_VALID) {
- LoggerW("Couldn't set ExifInformation - orientation is not valid: %d (%s)",
- orient, buf);
- }
- else {
+ if (orient < EXIF_ORIENTATION_NORMAL ||
+ orient >= EXIF_ORIENTATION_NOT_VALID) {
+ LoggerW("Couldn't set ExifInformation - orientation"
+ " is not valid: %d (%s)", orient, buf);
+ } else {
LoggerD("Setting ExifInformation orientation to: %d [%s]", orient, buf);
setOrientation(static_cast<ImageOrientation>(orient));
}
}
case EXIF_TAG_FNUMBER:
{
- //RATIONAL - 1
+ // RATIONAL - 1
Rational fnumber = getRationalFromEntry(entry, exif_data);
- if(fnumber.isValid()) {
- LOGD("Setting ExifInformation fnumber to: %f (%s)", fnumber.toDouble(),
- fnumber.toString().c_str());
+ if (fnumber.isValid()) {
+ LoggerD("Setting ExifInformation fnumber to: %f (%s)",
+ fnumber.toDouble(),
+ fnumber.toString().c_str());
setFNumber(fnumber);
- }
- else {
- LOGW("Couldn't set ExifInformation - fnumber is not valid: %s",
+ } else {
+ LoggerW("Couldn't set ExifInformation - fnumber is not valid: %s",
fnumber.toString().c_str());
}
break;
}
case EXIF_TAG_ISO_SPEED_RATINGS: {
- //SHORT - Any
+ // SHORT - Any
if (EXIF_FORMAT_SHORT == entry->format &&
entry->components > 0 &&
entry->data) {
const size_t size_per_member =
ExifUtil::getSizeOfExifFormatType(entry->format);
- for(unsigned long i = 0; i < entry->components; ++i) {
+ for (unsigned long i = 0; i < entry->components; ++i) {
ExifShort iso_rating = exif_get_short(read_ptr, order);
LoggerD("Appending ExifInformation speed ratings with: %d",
read_ptr += size_per_member;
}
- }
- else {
+ } else {
LoggerE("iso speed ratings: format or components count is invalid!");
}
break;
}
case EXIF_TAG_EXPOSURE_TIME: {
- //RATIONAL - 1
+ // RATIONAL - 1
if (EXIF_FORMAT_RATIONAL == entry->format &&
entry->components > 0 &&
entry->data) {
-
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
const Rational exp_time(exif_get_rational(entry->data, order));
exp_time.toString().c_str(),
exp_time.toExposureTimeString().c_str());
setExposureTime(exp_time);
- }
- else {
- LoggerD("Couldn't set ExifInformation - exposure time is not valid: %s",
+ } else {
+ LoggerD("Couldn't set ExifInformation"
+ " - exposure time is not valid: %s",
exp_time.toString().c_str());
}
- }
- else {
+ } else {
LoggerE("exposure time: format or components count is invalid!");
}
break;
}
case EXIF_TAG_EXPOSURE_PROGRAM: {
- //SHORT - 1
+ // SHORT - 1
exif_entry_get_value(entry, buf, sizeof(buf));
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
const ExifShort exp_program = exif_get_short(entry->data, order);
- if(exp_program >= EXIF_EXPOSURE_PROGRAM_NOT_VALID) {
+ if (exp_program >= EXIF_EXPOSURE_PROGRAM_NOT_VALID) {
LoggerW("ExposureProgram: %d (%s) is not valid!", exp_program, buf);
- }
- else {
+ } else {
LoggerD("Setting ExifInformation exposure program to: %d [%s]",
- exp_program, buf );
+ exp_program, buf);
setExposureProgram(static_cast<ExposureProgram>(exp_program));
}
break;
}
case EXIF_TAG_FLASH: {
- //SHORT - 1
+ // SHORT - 1
exif_entry_get_value(entry, buf, sizeof(buf));
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
const ExifShort flash = exif_get_short(entry->data, order);
- LoggerD( "Setting ExifInformation flash to: [%s] flash=%d", buf, flash);
+ LoggerD("Setting ExifInformation flash to: [%s] flash=%d", buf, flash);
setFlash(flash != 0);
break;
}
case EXIF_TAG_FOCAL_LENGTH: {
- //RATIONAL - 1
+ // RATIONAL - 1
Rational flength = getRationalFromEntry(entry, exif_data);
- if(flength.isValid()) {
+ if (flength.isValid()) {
LoggerD("Setting ExifInformation focal length to: %f (%s)",
flength.toDouble(), flength.toString().c_str());
setFocalLength(flength);
- }
- else {
+ } else {
LoggerW("Couldn't set ExifInformation - focal length is not valid: %s",
flength.toString().c_str());
}
break;
}
case EXIF_TAG_WHITE_BALANCE: {
- //SHORT - 1
+ // SHORT - 1
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation white balance to: [%s]", buf );
+ LoggerD("Setting ExifInformation white balance to: [%s]", buf);
if (entry->data[0]) {
setWhiteBalanceMode(EXIF_WHITE_BALANCE_MODE_MANUAL);
- }
- else {
+ } else {
setWhiteBalanceMode(EXIF_WHITE_BALANCE_MODE_AUTO);
}
break;
}
case EXIF_TAG_GPS_LONGITUDE: {
- //RATIONAL - 3
+ // RATIONAL - 3
GCSPosition longitude;
if (getGCSPositionFromEntry(entry, exif_data, longitude)) {
m_gps_location.setLongitude(longitude);
longitude.minutes.toString().c_str(),
longitude.seconds.toString().c_str(),
longitude.isValid());
- }
- else {
+ } else {
exif_entry_get_value(entry, buf, sizeof(buf));
LoggerW("Couldn't set longitude pos - data is not valid: [%s]", buf);
}
break;
}
case EXIF_TAG_GPS_LONGITUDE_REF: {
- //ASCII - 2
- if(entry->size < 1) {
+ // ASCII - 2
+ if (entry->size < 1) {
LoggerW("Longtitude ref entry do not contain enought data!");
break;
}
const char ref = static_cast<char>(entry->data[0]);
- if ('E' == ref || 'e' == ref) { //East
+ if ('E' == ref || 'e' == ref) { // East
m_gps_location.setLongitudeRef(GPS_LOCATION_EAST);
LoggerD("Setting ExifInformation gps longitude REF to: EAST");
- }
- else if ('W' == ref || 'w' == ref) { //West
+ } else if ('W' == ref || 'w' == ref) { // West
m_gps_location.setLongitudeRef(GPS_LOCATION_WEST);
LoggerD("Setting ExifInformation gps longitude REF to: WEST");
- }
- else {
+ } else {
LoggerW("Unknown longitude ref: %c (0x%x)", ref, static_cast<int>(ref));
}
break;
}
case EXIF_TAG_GPS_LATITUDE: {
- //RATIONAL - 3
+ // RATIONAL - 3
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation latitude to: [%s], tag->%s",
+ LoggerD("Setting ExifInformation latitude to: [%s], tag->%s",
buf, exif_tag_get_name(entry->tag) );
GCSPosition latitude;
latitude.minutes.toString().c_str(),
latitude.seconds.toString().c_str(),
latitude.isValid());
- }
- else {
+ } else {
LoggerW("Couldn't set latitude pos - data is not valid!");
}
break;
}
case EXIF_TAG_GPS_LATITUDE_REF: {
- //ASCII - 2
- if(entry->size < 1) {
+ // ASCII - 2
+ if (entry->size < 1) {
LoggerW("Latitude ref entry do not contain enought data!");
break;
}
const char ref = static_cast<char>(entry->data[0]);
- if ('N' == ref || 'n' == ref) { //North
+ if ('N' == ref || 'n' == ref) { // North
m_gps_location.setLatitudeRef(GPS_LOCATION_NORTH);
LoggerD("Setting ExifInformation gps latitude REF to: NORTH");
- }
- else if ('S' == ref || 's' == ref) { //South
+ } else if ('S' == ref || 's' == ref) { // South
m_gps_location.setLatitudeRef(GPS_LOCATION_SOUTH);
LoggerD("Setting ExifInformation gps latitude REF to: SOUTH");
- }
- else {
+ } else {
LoggerW("Unknown latitude ref: %c (0x%x)", ref, static_cast<int>(ref));
}
break;
}
case EXIF_TAG_GPS_ALTITUDE: {
- //RATIONAL - 1
+ // RATIONAL - 1
Rational gps_altitude = getRationalFromEntry(entry, exif_data);
- if(gps_altitude.isValid()) {
+ if (gps_altitude.isValid()) {
LoggerD("Setting ExifInformation gps altitude to: %f (%s)",
gps_altitude.toDouble(), gps_altitude.toString().c_str());
setGpsAltitude(gps_altitude);
- }
- else {
+ } else {
LoggerW("Couldn't set ExifInformation - gps altitude is not valid: %s",
gps_altitude.toString().c_str());
}
break;
}
case EXIF_TAG_GPS_ALTITUDE_REF: {
- //BYTE - 1
+ // BYTE - 1
const ExifByte altitude_ref = static_cast<ExifByte>(entry->data[0]);
- if(static_cast<ExifByte>(GPS_ALTITUDE_REF_ABOVE_SEA) == altitude_ref ||
+ if (static_cast<ExifByte>(GPS_ALTITUDE_REF_ABOVE_SEA) == altitude_ref ||
static_cast<ExifByte>(GPS_ALTITUDE_REF_BELOW_SEA) == altitude_ref) {
setGpsAltitudeRef(static_cast<GpsAltitudeRef>(altitude_ref));
- LoggerD( "Setting ExifInformation gps altitude ref to: %d (%s)",
+ LoggerD("Setting ExifInformation gps altitude ref to: %d (%s)",
static_cast<int>(altitude_ref),
(altitude_ref > 0) ? "below sea" : "above sea");
} else {
break;
}
case EXIF_TAG_GPS_PROCESSING_METHOD: {
- //UNDEFINED - Any
+ // UNDEFINED - Any
std::string type, value;
- if(decomposeExifUndefined(entry, type, value)) {
+ if (decomposeExifUndefined(entry, type, value)) {
LoggerD("Extracted GPSProcessingMethod: [%s], len:%d, type:%s",
value.c_str(), value.length(), type.c_str());
setGpsProcessingMethod(type, value);
- LoggerD("Setting ExifInformation processing method to: [%s], len:%d, type:%s",
+ LoggerD("Setting ExifInformation processing method"
+ " to: [%s], len:%d, type:%s",
m_gps_processing_method.c_str(),
m_gps_processing_method.length(),
m_gps_processing_method_type.c_str());
- }
- else {
+ } else {
LoggerW("GPSProcessingMethod tag contains invalid values!");
}
break;
}
case EXIF_TAG_GPS_DATE_STAMP: {
- //ASCII - 11
+ // ASCII - 11
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation gps date stamp to: [%s]", buf );
- //m_exif_gps_time.setDate(buf);
+ LoggerD("Setting ExifInformation gps date stamp to: [%s]", buf);
+ // m_exif_gps_time.setDate(buf);
break;
}
case EXIF_TAG_GPS_TIME_STAMP: {
- //Rational - 3
+ // Rational - 3
exif_entry_get_value(entry, buf, sizeof(buf));
- LoggerD( "Setting ExifInformation gps time stamp to: [%s]", buf);
+ LoggerD("Setting ExifInformation gps time stamp to: [%s]", buf);
Rationals time;
if (getRationalsFromEntry(entry, exif_data, 3, time)) {
- //m_exif_gps_time.setTime(time);
+ // m_exif_gps_time.setTime(time);
}
break;
}
case EXIF_TAG_USER_COMMENT: {
- //UNDEFINED - Any
+ // UNDEFINED - Any
std::string type, value;
- if(decomposeExifUndefined(entry, type, value)) {
+ if (decomposeExifUndefined(entry, type, value)) {
LoggerD("Extracted UserComment: [%s], len:%d, type:%s",
value.c_str(), value.length(), type.c_str());
setUserComment(type, value);
- LoggerD("Setting ExifInformation user comment to: [%s], len:%d, type:%s",
+ LoggerD("Setting ExifInformation user comment"
+ " to: [%s], len:%d, type:%s",
m_user_comment.c_str(),
m_user_comment.length(),
m_user_comment_type.c_str());
- }
- else {
+ } else {
LoggerW("UserComment tag contains invalid values!");
}
break;
}
- default:
- LoggerD("Field of tag:%x.H [%s] is not supported, value: [%s]", entry->tag,
+ default: {
+ LoggerD("Field of tag:%x.H [%s] is not supported, value: [%s]",
+ entry->tag,
exif_tag_get_name_in_ifd(entry->tag, cur_ifd),
exif_entry_get_value(entry, buf, sizeof(buf)));
+ }
}
}
ExifData* exif_data;
};
-void ExifInformation::contentForeachFunctionProxy(ExifEntry *entry, void *user_data) {
- ExifInfoAndDataHolder* holder = static_cast<ExifInfoAndDataHolder*>(user_data);
+void ExifInformation::contentForeachFunctionProxy(ExifEntry *entry,
+ void *user_data) {
+ ExifInfoAndDataHolder* holder =
+ static_cast<ExifInfoAndDataHolder*>(user_data);
if (!holder) {
LoggerE("holder is NULL");
}
}
}
-void ExifInformation::dataForeachFunction(ExifContent *content, void *user_data) {
+void ExifInformation::dataForeachFunction(ExifContent *content,
+ void *user_data) {
exif_content_foreach_entry(content, contentForeachFunctionProxy, user_data);
}
exif_info->setUri(uri);
const std::string file_path = ExifUtil::convertUriToPath(uri);
- ExifData* ed = exif_data_new_from_file (file_path.c_str());
+ ExifData* ed = exif_data_new_from_file(file_path.c_str());
if (!ed) {
LoggerE("Error reading exif from file %s", file_path.c_str());
- LoggerE("Error reading exif from file %s", file_path.c_str());
- //throw NotFoundException("Error reading exif from file");
+ // throw NotFoundException("Error reading exif from file");
}
LoggerD("exif_data_foreach_content START");
ExifInfoAndDataHolder holder;
holder.exif_info = exif_info;
holder.exif_data = ed;
- exif_data_foreach_content(ed, dataForeachFunction, static_cast<void*>(&holder));
+ exif_data_foreach_content(ed, dataForeachFunction,
+ static_cast<void*>(&holder));
LoggerD("exif_data_foreach_content END");
void ExifInformation::removeNulledAttributesFromExifData(ExifData* exif_data) {
- LOGD("Entered");
- if(!exif_data) {
+ LoggerD("Entered");
+ if (!exif_data) {
LoggerE("exif_data is NULL");
throw common::UnknownException("Invalid Exif provided");
}
}
if (!isSet(EXIF_INFORMATION_ATTRIBUTE_ORIGINAL_TIME)) {
LoggerD("Removing original time");
- ExifTagSaver::removeExifEntryWithTag(EXIF_TAG_DATE_TIME_ORIGINAL, exif_data);
+ ExifTagSaver::removeExifEntryWithTag(
+ EXIF_TAG_DATE_TIME_ORIGINAL, exif_data);
}
if (!isSet(EXIF_INFORMATION_ATTRIBUTE_EXPOSURE_TIME)) {
LoggerD("Removing exposure time");
if (!isSet(EXIF_INFORMATION_ATTRIBUTE_GPS_ALTITUDE)) {
LoggerD("Removing gps altitude");
ExifTagSaver::removeExifEntryWithTag(
- static_cast<ExifTag>(EXIF_TAG_GPS_ALTITUDE), exif_data);
+ static_cast<ExifTag>(EXIF_TAG_GPS_ALTITUDE), exif_data);
}
if (!isSet(EXIF_INFORMATION_ATTRIBUTE_GPS_ALTITUDE_REF)) {
LoggerD("Removing gps altitude ref");
void ExifInformation::updateAttributesInExifData(ExifData* exif_data) {
LoggerD("Entered");
- if(!exif_data) {
+ if (!exif_data) {
LoggerE("exif_data is NULL");
throw common::UnknownException("Invalid Exif provided");
}
EXIF_TAG_ORIENTATION, exif_data);
}
if (isSet(EXIF_INFORMATION_ATTRIBUTE_EXPOSURE_PROGRAM)) {
- LoggerD("Saving exposure program: %d", static_cast<int>(getExposureProgram()));
+ LoggerD("Saving exposure program: %d",
+ static_cast<int>(getExposureProgram()));
ExifTagSaver::saveToExif(getExposureProgram(),
EXIF_TAG_EXPOSURE_PROGRAM, exif_data);
}
EXIF_TAG_ISO_SPEED_RATINGS, exif_data);
}
if (isSet(EXIF_INFORMATION_ATTRIBUTE_WHITE_BALANCE)) {
- LoggerD("Saving white balance: %d", static_cast<int>(getWhiteBalanceMode()));
+ LoggerD("Saving white balance: %d",
+ static_cast<int>(getWhiteBalanceMode()));
ExifTagSaver::saveToExif(getWhiteBalanceMode(),
EXIF_TAG_WHITE_BALANCE, exif_data);
}
}
if (isSet(EXIF_INFORMATION_ATTRIBUTE_ORIGINAL_TIME)) {
const time_t o_time = getOriginalTime();
- const std::string o_time_str = ExifUtil::timeTToExifDateTimeOriginal(o_time);
- LoggerD("Saving original time time_t:%d, format:%s", static_cast<int>(o_time),
- o_time_str.c_str());
+ const std::string o_time_str =
+ ExifUtil::timeTToExifDateTimeOriginal(o_time);
+ LoggerD("Saving original time time_t:%d, format:%s",
+ static_cast<int>(o_time), o_time_str.c_str());
ExifTagSaver::saveToExif(o_time_str,
EXIF_TAG_DATE_TIME_ORIGINAL, exif_data);
static_cast<ExifTag>(EXIF_TAG_GPS_ALTITUDE), exif_data);
}
if (isSet(EXIF_INFORMATION_ATTRIBUTE_GPS_ALTITUDE_REF)) {
- //Exif spec:
- //0 = Sea level
- //1 = Sea level reference (negative value)
+ // Exif spec:
+ // 0 = Sea level
+ // 1 = Sea level reference (negative value)
LoggerD("Saving gps altitude ref:%d (%s)",
static_cast<int>(m_gps_altitude_ref),
(static_cast<int>(m_gps_altitude_ref) > 0) ? "below sea" : "above sea");
LoggerD("Saving gps processing method: [%s] type:%s",
getGpsProcessingMethod().c_str(), getGpsProcessingMethodType().c_str());
- const std::string joined = getGpsProcessingMethodType() + getGpsProcessingMethod();
+ const std::string joined = getGpsProcessingMethodType() +
+ getGpsProcessingMethod();
LoggerD("joined: [%s]", joined.c_str());
ExifTagSaver::saveToExif(joined,
const time_t gps_time = getGpsTime();
const Rationals gps_time_vec = ExifUtil::timeTToExifGpsTimeStamp(gps_time);
const std::string gps_date_str =
- ExifUtil::timeTToExifGpsDateStamp(gps_time);
+ ExifUtil::timeTToExifGpsDateStamp(gps_time);
LoggerD("Saving gps time stamp time_t: %d", static_cast<int>(gps_time));
ExifTagSaver::saveToExif(gps_time_vec,
- static_cast<ExifTag>(EXIF_TAG_GPS_TIME_STAMP), exif_data);
+ static_cast<ExifTag>(EXIF_TAG_GPS_TIME_STAMP), exif_data);
LoggerD("Saving gps date stamp: %s", gps_date_str.c_str());
ExifTagSaver::saveToExif(gps_date_str,
- static_cast<ExifTag>(EXIF_TAG_GPS_DATE_STAMP), exif_data, EXIF_FORMAT_ASCII, false);
+ static_cast<ExifTag>(EXIF_TAG_GPS_DATE_STAMP), exif_data,
+ EXIF_FORMAT_ASCII, false);
}
if (isSet(EXIF_INFORMATION_ATTRIBUTE_USER_COMMENT)) {
LoggerD("Saving user comment: %s (type:%s)", getUserComment().c_str(),
- getUserCommentType().c_str());
+ getUserCommentType().c_str());
const std::string joined = getUserCommentType() + getUserComment();
LoggerD("joined: [%s]", joined.c_str());
void ExifInformation::saveToFile(const std::string& file_path) {
LoggerD("Entered");
- LoggerD("Using JpegFile to read: [%s] and Exif if present", file_path.c_str());
+ LoggerD("Using JpegFile to read: [%s] and Exif if present",
+ file_path.c_str());
bool exif_data_is_new = false;
JpegFilePtr jpg_file = JpegFile::loadFile(file_path);
ExifData* exif_data = jpg_file->getExifData();
- //Exif is not present in file - create new ExifData
+ // Exif is not present in file - create new ExifData
if (!exif_data) {
- LoggerD("Exif is not present in file: [%s] creating new", file_path.c_str());
+ LoggerD("Exif is not present in file: [%s] creating new",
+ file_path.c_str());
exif_data = exif_data_new();
exif_data_set_option(exif_data, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
exif_data_set_option(exif_data, EXIF_DATA_OPTION_FOLLOW_SPECIFICATION);
try {
- //If we have created new ExifData there is nothing to remove
- if(!exif_data_is_new) {
- //Remove attributes that have been nulled
+ // If we have created new ExifData there is nothing to remove
+ if (!exif_data_is_new) {
+ // Remove attributes that have been nulled
removeNulledAttributesFromExifData(exif_data);
}
updateAttributesInExifData(exif_data);
- LOGD("Using JpegFile to save new Exif in: [%s]", file_path.c_str());
- if(exif_data_is_new) {
+ LoggerD("Using JpegFile to save new Exif in: [%s]", file_path.c_str());
+ if (exif_data_is_new) {
jpg_file->setNewExifData(exif_data);
}
// limitations under the License.
//
-#ifndef EXIF_EXIF_EXIFINFORMATION_H_
-#define EXIF_EXIF_EXIFINFORMATION_H_
+#ifndef EXIF_EXIF_INFORMATION_H_
+#define EXIF_EXIF_INFORMATION_H_
#include <libexif/exif-loader.h>
#include <string>
#include <vector>
#include <map>
-#include "ExifGPSLocation.h"
+#include "exif_gps_location.h"
#include "common/picojson.h"
namespace extension {
} // namespace exif
} // namespace extension
-#endif // EXIF_EXIF_EXIFINFORMATION_H_
+#endif // EXIF_EXIF_INFORMATION_H_
const char kGetExifInfoCmd[] = "Exif_getExifInfo";
const char kSaveExifInfoCmd[] = "Exif_saveExifInfo";
const char kGetThumbnailCmd[] = "Exif_getThumbnail";
-}
+} // namespace
ExifInstance::ExifInstance() {
using namespace std::placeholders;
}
void ExifInstance::saveExifInfo(const picojson::value& args,
- picojson::object& out) {
+ picojson::object& out) {
const std::string& uri = args.get("uri").get<std::string>();
const double callback_id = args.get("callbackId").get<double>();
};
auto get_response =
- [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
- picojson::object& obj = response->get<picojson::object>();
- obj.insert(std::make_pair("callbackId", callback_id));
- LoggerD("callback is %s", response->serialize().c_str());
- PostMessage(response->serialize().c_str());
- };
+ [callback_id, this](const std::shared_ptr<JsonValue>& response) -> void {
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", callback_id));
+ LoggerD("callback is %s", response->serialize().c_str());
+ PostMessage(response->serialize().c_str());
+ };
common::TaskQueue::GetInstance().Queue<JsonValue>(
get, get_response,
}
void ExifInstance::getThumbnail(const picojson::value& args,
- picojson::object& out) {
+ picojson::object& out) {
LoggerE("getThumbnail is not implemented (c++)");
}
namespace extension {
namespace exif {
-void ExifTagSaver::removeExifEntryWithTag(const ExifTag tag, ExifData* exif_data) {
+void ExifTagSaver::removeExifEntryWithTag(const ExifTag tag,
+ ExifData* exif_data) {
LoggerD("Entered tag:%d (0x%x)", tag, tag);
ExifEntry* exif_entry = exif_data_get_entry(exif_data, tag);
if (!exif_entry) {
exif_content_remove_entry(exif_entry->parent, exif_entry);
}
-void ExifTagSaver::saveToExif(long int value, ExifTag tag, ExifData* exif_data) {
+void ExifTagSaver::saveToExif(long int value, ExifTag tag,
+ ExifData* exif_data) {
ExifEntry* entry = prepareEntry(exif_data, tag);
ExifByteOrder order = exif_data_get_byte_order(exif_data);
LoggerD("EXIF_FORMAT_BYTE: %d", EXIF_FORMAT_BYTE);
switch (entry->format) {
- case EXIF_FORMAT_BYTE:
+ case EXIF_FORMAT_BYTE: {
entry->data[0] = static_cast<unsigned char>(value);
break;
- case EXIF_FORMAT_SHORT:
- exif_set_short (entry->data, order, value);
+ }
+ case EXIF_FORMAT_SHORT: {
+ exif_set_short(entry->data, order, value);
break;
- case EXIF_FORMAT_LONG:
- exif_set_long (entry->data, order, value);
+ }
+ case EXIF_FORMAT_LONG: {
+ exif_set_long(entry->data, order, value);
break;
- case EXIF_FORMAT_SLONG:
- exif_set_slong (entry->data, order, value);
+ }
+ case EXIF_FORMAT_SLONG: {
+ exif_set_slong(entry->data, order, value);
break;
- default:
- LoggerE("Error: wrong format: %d \n", entry->format );
+ }
+ default: {
+ LoggerE("Error: wrong format: %d \n", entry->format);
+ }
}
}
bool add_zero_character) {
ExifEntry* entry = prepareEntry(exif_data, tag);
if (!value.empty()) {
-
if (entry->data) {
free(entry->data);
entry->data = NULL;
}
}
-void ExifTagSaver::saveToExif(const Rational& value, ExifTag tag, ExifData* exif_data) {
+void ExifTagSaver::saveToExif(const Rational& value, ExifTag tag,
+ ExifData* exif_data) {
ExifEntry* entry = prepareEntry(exif_data, tag);
entry->format = EXIF_FORMAT_RATIONAL;
exif_set_rational(entry->data, order, r);
}
-void ExifTagSaver::saveToExif(const Rationals& value, ExifTag tag, ExifData* exif_data) {
+void ExifTagSaver::saveToExif(const Rationals& value, ExifTag tag,
+ ExifData* exif_data) {
ExifEntry* entry = prepareEntry(exif_data, tag);
ExifByteOrder order = exif_data_get_byte_order(exif_data);
entry->format = EXIF_FORMAT_RATIONAL;
}
entry->components = value.size();
- for (size_t i = 0; i < value.size(); ++i)
- {
+ for (size_t i = 0; i < value.size(); ++i) {
ExifRational r;
r.numerator = value[i].nominator;
r.denominator = value[i].denominator;
}
}
-void ExifTagSaver::saveToExif(std::vector<long long int>& value, ExifFormat store_as,
- ExifTag tag, ExifData* exif_data) {
+void ExifTagSaver::saveToExif(std::vector<long long int>& value,
+ ExifFormat store_as,
+ ExifTag tag, ExifData* exif_data) {
ExifEntry* entry = prepareEntry(exif_data, tag);
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
switch (store_as) {
case EXIF_FORMAT_BYTE: {
- for(size_t i = 0; i < num_elements; ++i) {
+ for (size_t i = 0; i < num_elements; ++i) {
entry->data[i] = static_cast<ExifByte>(value[i]);
}
break;
}
-
case EXIF_FORMAT_SHORT: {
for (size_t i = 0; i < num_elements; ++i) {
exif_set_short(entry->data + i * size_per_member, order,
}
break;
}
-
case EXIF_FORMAT_SSHORT: {
for (size_t i = 0; i < num_elements; ++i) {
exif_set_sshort(entry->data + i * size_per_member, order,
}
break;
}
-
case EXIF_FORMAT_LONG: {
for (size_t i = 0; i < num_elements; ++i) {
exif_set_long(entry->data + i * size_per_member, order,
}
break;
}
-
case EXIF_FORMAT_SLONG: {
- for(size_t i = 0; i < num_elements; ++i) {
+ for (size_t i = 0; i < num_elements; ++i) {
exif_set_slong(entry->data + i * size_per_member, order,
static_cast<ExifSLong>(value[i]));
}
break;
}
-
default:
break;
}
-
LoggerD("entry after save:");
ExifUtil::printExifEntryInfo(entry, exif_data);
}
void ExifTagSaver::saveGpsLocationToExif(const ExifGPSLocation& gps_info,
- ExifData* exif_data) {
+ ExifData* exif_data) {
if (gps_info.isSet(EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE)) {
auto latitude = gps_info.getLatitude();
LoggerD("Saving latitude: %s", latitude.toDebugString().c_str());
(gps_info.getLatitudeRef() == GPS_LOCATION_NORTH) ? "N" : "S";
LoggerD("Saving latitude ref: %s", lat_ref.c_str());
saveToExif(lat_ref, static_cast<ExifTag>(EXIF_TAG_GPS_LATITUDE_REF),
- exif_data, EXIF_FORMAT_ASCII, false);
+ exif_data, EXIF_FORMAT_ASCII, false);
}
if (gps_info.isSet(EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE)) {
-
auto longitude = gps_info.getLongitude();
LoggerD("Saving longitude: %s", longitude.toDebugString().c_str());
saveToExif(longitude.toRationalsVector(),
(gps_info.getLongitudeRef() == GPS_LOCATION_WEST) ? "W" : "E";
LoggerD("Saving longitude ref: %s", long_ref.c_str());
saveToExif(long_ref, static_cast<ExifTag>(EXIF_TAG_GPS_LONGITUDE_REF),
- exif_data, EXIF_FORMAT_ASCII, false);
+ exif_data, EXIF_FORMAT_ASCII, false);
}
}
ExifEntry* exif_entry = exif_data_get_entry(exif_data, tag);
if (!exif_entry) {
exif_entry = createNewTag(exif_data, deduceIfdSection(tag),
- deduceDataFormat(tag), tag );
+ deduceDataFormat(tag), tag);
}
if (!exif_entry) {
LoggerE("Couldn't create new Exif tag");
- //throw UnknownException("Could not save Exif to file");
+ // throw UnknownException("Could not save Exif to file");
}
exif_entry_initialize(exif_entry, tag);
}
ExifEntry* ExifTagSaver::createNewTag(ExifData* exif_data, ExifIfd ifd,
- ExifFormat format, ExifTag tag) {
+ ExifFormat format, ExifTag tag) {
LoggerD("Creating new tag: %d", tag);
ExifEntry* new_entry = exif_entry_new();
ExifIfd ExifTagSaver::deduceIfdSection(ExifTag tag) {
switch (static_cast<unsigned int>(tag)) {
- //Tags in IFD_0 Section
+ // Tags in IFD_0 Section
case EXIF_TAG_MAKE:
case EXIF_TAG_MODEL:
case EXIF_TAG_IMAGE_WIDTH:
case EXIF_TAG_ORIENTATION:
return EXIF_IFD_0;
- //Tags in IFD_EXIF Section
+ // Tags in IFD_EXIF Section
case EXIF_TAG_USER_COMMENT:
case EXIF_TAG_DATE_TIME_ORIGINAL:
case EXIF_TAG_EXPOSURE_TIME:
case EXIF_TAG_FOCAL_LENGTH:
return EXIF_IFD_EXIF;
- //Tags in IFD_GPS Section
+ // Tags in IFD_GPS Section
case EXIF_TAG_GPS_LATITUDE_REF:
case EXIF_TAG_GPS_LONGITUDE_REF:
case EXIF_TAG_GPS_LATITUDE:
case EXIF_TAG_GPS_DATE_STAMP:
return EXIF_IFD_GPS;
- //Tags in other sections
+ // Tags in other sections
default:
LoggerE("Unsupported tag: %d", tag);
- //throw UnknownException("Unsupported tag");
+ // throw UnknownException("Unsupported tag");
}
}
ExifFormat ExifTagSaver::deduceDataFormat(ExifTag tag) {
switch (static_cast<unsigned int>(tag)) {
- //Tags with byte type:
+ // Tags with byte type:
case EXIF_TAG_GPS_ALTITUDE_REF:
return EXIF_FORMAT_BYTE;
- //Tags with long type:
+ // Tags with long type:
case EXIF_TAG_IMAGE_WIDTH:
case EXIF_TAG_IMAGE_LENGTH:
return EXIF_FORMAT_LONG;
- //Tags with short type:
+ // Tags with short type:
case EXIF_TAG_ORIENTATION:
case EXIF_TAG_EXPOSURE_PROGRAM:
case EXIF_TAG_WHITE_BALANCE:
case EXIF_TAG_FLASH:
return EXIF_FORMAT_SHORT;
- //Tags with ASCII type:
+ // Tags with ASCII type:
case EXIF_TAG_MAKE:
case EXIF_TAG_MODEL:
case EXIF_TAG_DATE_TIME_ORIGINAL:
case EXIF_TAG_GPS_DATE_STAMP:
return EXIF_FORMAT_ASCII;
- //Tags with rational type:
+ // Tags with rational type:
case EXIF_TAG_EXPOSURE_TIME:
case EXIF_TAG_FNUMBER:
case EXIF_TAG_FOCAL_LENGTH:
case EXIF_TAG_ISO_SPEED_RATINGS:
return EXIF_FORMAT_RATIONAL;
- //Tags with undefined type:
+ // Tags with undefined type:
case EXIF_TAG_USER_COMMENT:
case EXIF_TAG_GPS_PROCESSING_METHOD:
return EXIF_FORMAT_UNDEFINED;
- //Unsupported tags:
+ // Unsupported tags:
default:
LoggerE("Unsupported tag: %d", tag);
- //throw UnknownException("Unsupported tag");
+ // throw UnknownException("Unsupported tag");
}
}
* @file exif_tag_saver.h
*/
-#ifndef EXIF_EXIF_TAG_SAVER_H__
-#define EXIF_EXIF_TAG_SAVER_H__
+#ifndef EXIF_EXIF_TAG_SAVER_H_
+#define EXIF_EXIF_TAG_SAVER_H_
#include <libexif/exif-data.h>
#include <string>
#include <vector>
-#include "ExifGPSLocation.h"
+#include "exif_gps_location.h"
namespace extension {
namespace exif {
public:
static void removeExifEntryWithTag(const ExifTag tag, ExifData* exif_data);
- static void saveToExif(long int value,
- ExifTag tag,
- ExifData* exif_data);
+ static void saveToExif(long int value, ExifTag tag, ExifData* exif_data);
static void saveToExif(const std::string& value, ExifTag tag,
- ExifData* exif_data,
- ExifFormat format = EXIF_FORMAT_ASCII,
- bool add_zero_character = true);
+ ExifData* exif_data, ExifFormat format = EXIF_FORMAT_ASCII,
+ bool add_zero_character = true);
static void saveToExif(const Rational& value, ExifTag tag,
- ExifData* exif_data);
+ ExifData* exif_data);
static void saveToExif(const Rationals& value, ExifTag tag,
- ExifData* exif_data);
+ ExifData* exif_data);
static void saveToExif(std::vector<long long int>& value, ExifFormat store_as,
ExifTag tag, ExifData* exif_data);
static void saveGpsLocationToExif(const ExifGPSLocation& gps_info,
static ExifIfd deduceIfdSection(ExifTag tag);
static ExifFormat deduceDataFormat(ExifTag tag);
static ExifEntry* createNewTag(ExifData* exif_data, ExifIfd ifd,
- ExifFormat format, ExifTag tag);
+ ExifFormat format, ExifTag tag);
};
} // namespace exif
} // namespace extension
-#endif // EXIF_EXIF_TAG_SAVER_H__
+#endif // EXIF_EXIF_TAG_SAVER_H_
const std::string EXPOSURE_PROGRAM_PORTRAIT_MODE = "PORTRAIT_MODE";
const std::string EXPOSURE_PROGRAM_LANDSCAPE_MODE = "LANDSCAPE_MODE";
-const std::string DUMMY = ""; // For unexpected input handling
+const std::string DUMMY = ""; // For unexpected input handling
const std::string URI_PREFIX = "file://";
const std::string URI_ABSOLUTE_PREFIX = "file:///";
-}
+} // namespace
const size_t ExifTypeInfo::ByteSize = 1;
const size_t ExifTypeInfo::ASCIISize = 1;
}
}
-WhiteBalanceMode ExifUtil::stringToWhiteBalance(const std::string& white_balance) {
+WhiteBalanceMode ExifUtil::stringToWhiteBalance(
+ const std::string& white_balance) {
LoggerD("Entered");
if (WHITE_BALANCE_MODE_AUTO == white_balance) {
return WhiteBalanceMode::EXIF_WHITE_BALANCE_MODE_AUTO;
}
void ExifUtil::getURIInfo(const std::string& uri,
- //const Filesystem::NodeType expected_type,
+ // const Filesystem::NodeType expected_type,
const std::string& required_permission,
bool& out_exists,
- //Filesystem::NodeType& out_type,
+ // Filesystem::NodeType& out_type,
bool& out_permission_granted) {
const std::string absolute_path = ExifUtil::convertUriToPath(uri);
out_exists = false;
out_permission_granted = false;
try {
- //Filesystem::PathPtr path = Filesystem::Path::create(absolute_path);
- //Filesystem::NodePtr node = Filesystem::Node::resolve(path);
- //out_type = node->getType();
- //out_exists = true;
-
- //if (expected_type == out_type) {
- // out_permission_granted = node->checkPermission(path, required_permission,
+ // Filesystem::PathPtr path = Filesystem::Path::create(absolute_path);
+ // Filesystem::NodePtr node = Filesystem::Node::resolve(path);
+ // out_type = node->getType();
+ // out_exists = true;
+
+ // if (expected_type == out_type) {
+ // out_permission_granted = node->checkPermission(path,
+ // required_permission,
// expected_type);
- //}
+ // }
}
- /*catch (const common::BasePlatformException &err) {
- LoggerE("Couldn't resolve path: %s, got:%s (%s)", absolute_path.c_str(),
+ /* catch (const common::BasePlatformException &err) {
+ LoggerE("Couldn't resolve path: %s, got:%s (%s)", absolute_path.c_str(),
(err.getName()).c_str(), (err.getMessage()).c_str());
- }*/
+ }
+ */
catch(...) {
LoggerE("Couldn't resolve path: %s", absolute_path.c_str());
}
if (prefix == URI_PREFIX) {
return path.substr(URI_PREFIX.size());
- }
- else {
+ } else {
return path;
}
}
break;
}
}
+
if (i == str.end()) {
str.clear();
- }
- else {
+ } else {
str.erase(str.begin(), i);
}
return str;
time_t ExifUtil::exifDateTimeOriginalToTimeT(const char* string) {
int year, month, day, hour, min, sec;
if (sscanf(string, "%d:%d:%d %d:%d:%d",
- &year, &month, &day, &hour, &min, &sec) >= 6) {
+ &year, &month, &day, &hour, &min, &sec) >= 6) {
return convertToTimeT(year, month, day, hour, min, sec);
}
extractFromTimeT(time, year, month, day, hour, min, sec);
std::ostringstream ss;
- ss << std::setfill('0') << std::setw(4) << year << ':' ;
- ss << std::setfill('0') << std::setw(2) << month << ':' ;
- ss << std::setfill('0') << std::setw(2) << day << ' ' ;
+ ss << std::setfill('0') << std::setw(4) << year << ':';
+ ss << std::setfill('0') << std::setw(2) << month << ':';
+ ss << std::setfill('0') << std::setw(2) << day << ' ';
- ss << std::setfill('0') << std::setw(2) << hour << ':' ;
- ss << std::setfill('0') << std::setw(2) << min << ':' ;
+ ss << std::setfill('0') << std::setw(2) << hour << ':';
+ ss << std::setfill('0') << std::setw(2) << min << ':';
ss << std::setfill('0') << std::setw(2) << sec;
return ss.str();
}
LoggerD("day: %d", day);
std::ostringstream ss;
- ss << std::setfill('0') << std::setw(4) << year << ':' ;
- ss << std::setfill('0') << std::setw(2) << month << ':' ;
+ ss << std::setfill('0') << std::setw(4) << year << ':';
+ ss << std::setfill('0') << std::setw(2) << month << ':';
ss << std::setfill('0') << std::setw(2) << day;
LoggerD("SS: %s", ss.str().c_str());
size_t size_per_member = getSizeOfExifFormatType(entry->format);
if (0 == size_per_member) {
- size_per_member = 1; //display as array of bytes
+ size_per_member = 1; // display as array of bytes
}
- for(unsigned long compi = 0; compi < entry->components; ++compi) {
-
+ for (unsigned long compi = 0; compi < entry->components; ++compi) {
if (compi > 0) {
ss << " ";
}
- for(size_t i = 0; i < size_per_member; ++i) {
+ for (size_t i = 0; i < size_per_member; ++i) {
unsigned int value = read_buf_ptr[i];
ss << std::hex << std::setw(2) << std::setfill('0') << value;
}
LoggerD("Entry{name:%s type:%s size:%d components:%d value:%s RAW DATA:[%s]}",
exif_tag_get_name(entry->tag),
exif_format_get_name(entry->format),
- (int)entry->size,
- (int)entry->components,
+ static_cast<int>(entry->size),
+ static_cast<int>(entry->components),
exif_entry_get_value(entry, buf, sizeof(buf)),
ss.str().c_str());
}
void ExifUtil::extractFromTimeT(const time_t time,
- int& out_year, int& out_month, int& out_day,
- int& out_hour, int& out_min, int& out_sec) {
+ int& out_year, int& out_month, int& out_day,
+ int& out_hour, int& out_min, int& out_sec) {
struct tm* utc = gmtime(&time);
out_year = utc->tm_year + 1900;
}
time_t ExifUtil::convertToTimeT(int year, int month, int day,
- int hour, int min, int sec) {
+ int hour, int min, int sec) {
time_t tmp_time = 0;
struct tm* timeinfo = localtime(&tmp_time);
timeinfo->tm_year = year - 1900;
timeinfo->tm_min = min;
timeinfo->tm_sec = sec;
- //From mktime documentation:
- //"The values of the members tm_wday and tm_yday of timeptr are ignored"
+ // From mktime documentation:
+ // "The values of the members tm_wday and tm_yday of timeptr are ignored"
return timegm(timeinfo);
}
#include <iomanip>
#include <limits>
-#include <stdio.h>
+#include <cstdio>
#include <sstream>
#include "common/platform_exception.h"
* JPEG's section data length includes 2 bytes for length therefore we need to
* substract 2 from MAX_JPEG_SECTION_DATA_SIZE
*/
-const unsigned int MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE = MAX_JPEG_SECTION_DATA_SIZE - 2;
+const unsigned int MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE =
+ MAX_JPEG_SECTION_DATA_SIZE - 2;
bool isJpegMarker(const int value) {
return value >= JPEG_MARKER_LOWEST_ID && value <= JPEG_MARKER_HIGHEST_ID;
m_padding_data = NULL;
m_padding_data_size = 0;
- for(SectionsVec::iterator it = m_sections.begin(); it != m_sections.end(); ++it) {
+ for (SectionsVec::iterator it = m_sections.begin();
+ it != m_sections.end(); ++it) {
JpegFileSectionPtr cur = *it;
if (cur->exif_data) {
}
std::string JpegFile::getPartOfFile(const size_t offset,
- const size_t num_bytes_before,
- const size_t num_bytes_after) {
+ const size_t num_bytes_before,
+ const size_t num_bytes_after) {
long long int start = static_cast<long long int>(offset) - num_bytes_before;
if (start < 0) {
start = 0;
std::stringstream ss;
ss << std::setfill('0') << std::setw(2) << std::hex;
- for(long long int i = start; i <= end; ++i) {
+ for (long long int i = start; i <= end; ++i) {
ss << static_cast<int>(m_in_data[i]);
}
return ss.str();
void JpegFile::generateListOfSections() {
LoggerD("Entered");
- //JPEG starts with:
- //FFD8 (2 bytes) - SOI Marker
+ // JPEG starts with:
+ // FFD8 (2 bytes) - SOI Marker
//
- //then:
- //N sections - format of section:
- //0xFF(1 byte) + Marker Number(1 byte) + Data size(2 bytes) + Data
+ // then:
+ // N sections - format of section:
+ // 0xFF(1 byte) + Marker Number(1 byte) + Data size(2 bytes) + Data
//
- //then:
- //SOS 0xFF(1 byte) + Marker Number(1 byte) + Data size(2 bytes) + Data
+ // then:
+ // SOS 0xFF(1 byte) + Marker Number(1 byte) + Data size(2 bytes) + Data
//
- //Image data
+ // Image data
//
- //FFD9 (2 bytes) - EOI Marker
+ // FFD9 (2 bytes) - EOI Marker
//
- //Warning: some images taken on Android contains some extra data at the end
- //we will keep it in m_padding_data
+ // Warning: some images taken on Android contains some extra data at the end
+ // we will keep it in m_padding_data
m_padding_data = NULL;
m_padding_data_size = 0;
- for(size_t offset = 0, iterration = 0; offset < m_in_data_size;++iterration) {
-
+ for (size_t offset = 0, iterration = 0;
+ offset < m_in_data_size; ++iterration) {
LoggerD("offset:%d | Starting iteration: %d", offset, iterration);
const size_t search_len = 10;
size_t search_offset = 0;
- for(search_offset = 0; search_offset < search_len; ++search_offset) {
- //Skip bytes until first no 0xff
+ for (search_offset = 0; search_offset < search_len; ++search_offset) {
+ // Skip bytes until first no 0xff
unsigned char& tmp_marker = m_in_data[offset + search_offset];
if (tmp_marker != 0xff) {
break;
const size_t section_offset = offset + search_offset - 1;
unsigned char* section_begin = m_in_data + section_offset;
- offset = section_offset; //Move to section begin
+ offset = section_offset; // Move to section begin
LoggerD("offset:%d | Moved to section begin", offset);
if (!isJpegMarker(section_begin[1])) {
LoggerE("offset:%d | Is not valid marker: 0x%x RAW DATA:{%s}", offset,
- section_begin[1], getPartOfFile(section_offset,0,4).c_str());
+ section_begin[1], getPartOfFile(section_offset, 0, 4).c_str());
throw common::UnknownException("JPEG file is invalid");
}
const JpegMarker cur_marker = castToJpegMarker(section_begin[1]);
LoggerD("offset:%d | Found valid marker: 0x%x RAW DATA:{%s}", offset,
cur_marker,
- getPartOfFile(section_offset,0,4).c_str());
+ getPartOfFile(section_offset, 0, 4).c_str());
- offset += 2; //Read 0xffxx marker tag - 2 bytes
+ offset += 2; // Read 0xffxx marker tag - 2 bytes
JpegFileSectionPtr section;
{
offset);
if (cur_marker == JPEG_MARKER_EOI && m_padding_data != NULL) {
- LoggerW("Padding data have been found - do not try to parse end of file");
+ LoggerW("Padding data have been found"
+ " - do not try to parse end of file");
break;
}
- }
- else {
- //From JPEG/EXIF info:
+ } else {
+ // From JPEG/EXIF info:
// Please notice that "Data" contains Data size descriptor, if there is
// a Marker like this;
//
// FF C1 00 0C
// It means this Marker(0xFFC1) has 0x000C(equal 12)bytes of data. But the
- // data size '12' includes "Data size" descriptor, it follows only 10 bytes of
- // data after 0x000C.
- //
+ // data size '12' includes "Data size" descriptor,
+ // it follows only 10 bytes of data after 0x000C.
- const long total_section_len = readUShortBE(section_begin + 2); //Include data
- //size 2 bytes
+ // Include data
+ // size 2 bytes
+ const long total_section_len = readUShortBE(section_begin + 2);
- const long section_data_len = total_section_len - 2; //Exclude data
- //size 2 bytes
+ // Exclude data
+ // size 2 bytes
+ const long section_data_len = total_section_len - 2;
LoggerD("offset:%d tag:0x%x | Read total_section_len:%d (data len:%d)",
section_offset, cur_marker, total_section_len, section_data_len);
- offset += 2; //Read data size - 2 bytes
+ offset += 2; // Read data size - 2 bytes
if (total_section_len < 0) {
- LoggerE("offset:%d tag:0x%x | Error: total_section_len is: %d < 0", offset,
- cur_marker, total_section_len);
+ LoggerE("offset:%d tag:0x%x | Error: total_section_len is: %d < 0",
+ offset, cur_marker, total_section_len);
throw common::UnknownException("JPEG file is invalid");
}
}
if (JPEG_MARKER_APP1 == cur_marker) {
- //TODO: verify this
- //-4 --> 0xFF(1 byte)+Marker Number(1 byte)+Data size(2 bytes))
- //const unsigned int exif_data_size = section_length - 4;
+ // TODO(Unknown): verify this
+ // -4 --> 0xFF(1 byte)+Marker Number(1 byte)+Data size(2 bytes))
+ // const unsigned int exif_data_size = section_length - 4;
const unsigned int exif_data_size = total_section_len + 2;
- section->exif_data = exif_data_new_from_data (section_begin,
+ section->exif_data = exif_data_new_from_data(section_begin,
exif_data_size);
LoggerD("offset:%d tag:0x%x | Loading exif from offset:%d"
section->exif_data);
if (!section->exif_data) {
- LoggerW("offset:%d tag:0x%x | Couldn't load Exif!", offset, cur_marker);
+ LoggerW("offset:%d tag:0x%x | Couldn't load Exif!",
+ offset, cur_marker);
}
}
- //This just saves pointer not copying data
- section->data_ptr = section_begin + 2 + 2; //2 bytes marker + 2 bytes data size
- section->size = section_data_len; //Exclude data size
+ // This just saves pointer not copying data
+ // 2 bytes marker + 2 bytes data size
+ section->data_ptr = section_begin + 2 + 2;
+ section->size = section_data_len; // Exclude data size
if (JPEG_MARKER_SOS == cur_marker) {
- //Calculate offset of first image data which is just after this SOS section
+ // Calculate offset of first image data which
+ // is just after this SOS section
const size_t image_data_offset = section_offset + 2 + total_section_len;
- //Calculate size of image data from start to expected EOI at end of file.
+ // Calculate size of image data from start
+ // to expected EOI at end of file.
//
- //-2 (exclude ending EOI marker (2 bytes)
+ // -2 (exclude ending EOI marker (2 bytes)
size_t image_size = m_in_data_size - image_data_offset - 2;
- LoggerW("offset:%d tag:0x%x | Image data offset:%d Estimated image size:%d",
+ LoggerW("offset:%d tag:0x%x"
+ " | Image data offset:%d Estimated image size:%d",
offset, cur_marker, image_data_offset, image_size);
m_image_data = m_in_data + image_data_offset;
bool found_eoi_tag = searchForTagInBuffer(m_in_data + image_data_offset,
m_in_data + m_in_data_size, JPEG_MARKER_EOI, eoi_tag_index);
if (!found_eoi_tag) {
- LoggerE("Could not find EOI tag! Assume that there is no EOI and rest of "
+ LoggerE("Could not find EOI tag!"
+ " Assume that there is no EOI and rest of "
"JPEG file contains image data stream: image_size+= 2");
- image_size += 2; //Skip expected EOI tag which is not present
+ image_size += 2; // Skip expected EOI tag which is not present
} else {
LoggerD("EOI tag found at offset: %d from SOS data", eoi_tag_index);
- if(eoi_tag_index != image_size) {
+ if (eoi_tag_index != image_size) {
LoggerW("Estimated image size:%d doesn't match EOI tag index:%d"
" delta:%d", image_size, eoi_tag_index,
image_size - eoi_tag_index);
LoggerW("Setting image_size to EOI tag: %d", eoi_tag_index);
image_size = eoi_tag_index;
- m_padding_data = m_image_data + image_size + 2; //(skip EOI tag)
+ m_padding_data = m_image_data + image_size + 2; // (skip EOI tag)
m_padding_data_size = (m_in_data + m_in_data_size) - m_padding_data;
LoggerW("Saving padding data from offset:%d with size:%d",
- m_padding_data - m_in_data, m_padding_data_size);
+ m_padding_data - m_in_data, m_padding_data_size);
}
}
offset = image_data_offset + image_size;
LoggerD("offset:%d tag:0x%x | SOS Offset moved to next marker", offset,
cur_marker);
- }
- else {
+ } else {
offset += section_data_len;
- LoggerD("offset:%d tag:0x%x | Offset moved to next marker", offset, cur_marker);
+ LoggerD("offset:%d tag:0x%x | Offset moved to next marker",
+ offset, cur_marker);
}
}
}
const unsigned char* buffer_end,
const JpegMarker marker,
size_t& out_index) {
- LoggerD("Entered start:%p end:%p marker:0x%x", buffer_start, buffer_end, marker);
+ LoggerD("Entered start:%p end:%p marker:0x%x",
+ buffer_start, buffer_end, marker);
- if(!buffer_start) {
+ if (!buffer_start) {
LoggerE("buffer_start is NULL");
return false;
}
- if(!buffer_end) {
+ if (!buffer_end) {
LoggerE("buffer_end is NULL");
return false;
}
- if(buffer_end <= buffer_start) {
+ if (buffer_end <= buffer_start) {
LoggerE("buffer_end: %p <= buffer_start: %p", buffer_end, buffer_start);
return false;
}
LoggerD("Bytes to scan: %d", static_cast<size_t>(buffer_end - buffer_start));
const unsigned char marker_uchar = static_cast<unsigned char>(marker);
- for(const unsigned char* ptr = buffer_start; ptr < buffer_end; ++ptr) {
-
- if((0xff == *ptr) && (ptr+1 < buffer_end)) {
- if(marker_uchar == *(ptr+1)) {
+ for (const unsigned char* ptr = buffer_start; ptr < buffer_end; ++ptr) {
+ if ((0xff == *ptr) && (ptr+1 < buffer_end)) {
+ if (marker_uchar == *(ptr+1)) {
out_index = static_cast<size_t>(ptr - buffer_start);
return true;
}
if (insert_it != m_sections.end()) {
if ((*insert_it)->type != JPEG_MARKER_SOI) {
LoggerW("First section is not SOI - Start Of Image!");
- }
- else {
+ } else {
soi_is_present = true;
}
}
throw common::UnknownException("JPEG file is invalid");
}
- //Insert new Exif sections just after SOI
+ // Insert new Exif sections just after SOI
++insert_it;
if (insert_it != m_sections.begin()) {
m_sections.insert(insert_it, exif);
- }
- else {
- //This shouldn't happen since we at lest need SOS and EOI sections
+ } else {
+ // This shouldn't happen since we at lest need SOS and EOI sections
m_sections.push_back(exif);
}
}
- //We don't want to save old data
+ // We don't want to save old data
exif->data_ptr = NULL;
exif->size = 0;
exif_data_unref(exif->exif_data);
- exif_data_ref (new_exif_data);
+ exif_data_ref(new_exif_data);
exif->exif_data = new_exif_data;
}
out_path.c_str());
if (out_path == m_source_file_path) {
-
LoggerD("Trying to recover broken JPEG file: [%s]", out_path.c_str());
- //We were writing to source file and since something went wrong let's
- //restore old file - we have it in m_in_data
+ // We were writing to source file and since something went wrong let's
+ // restore old file - we have it in m_in_data
FILE* outf = fopen(out_path.c_str(), "wb");
if (!outf) {
- LoggerE("Couldn't open output file: [%s] - JPEG file will not be restored!");
- }
- else {
+ LoggerE("Couldn't open output file:"
+ " [%s] - JPEG file will not be restored!", out_path.c_str());
+ } else {
size_t bytes_wrote = fwrite(m_in_data, 1, m_in_data_size, outf);
if (bytes_wrote != m_in_data_size) {
LoggerE("Couldn't restore whole JPEG! "
size_t offset = 0;
int section_index = 0;
- for(SectionsVec::iterator it = m_sections.begin();
+ for (SectionsVec::iterator it = m_sections.begin();
it != m_sections.end();
- ++it, ++ section_index) {
-
+ ++it, ++section_index) {
JpegFileSectionPtr cur = *it;
const JpegMarker cur_marker = cur->type;
- LoggerD("offset:%d | Section: %d marker 0x%x", offset, section_index, cur_marker);
+ LoggerD("offset:%d | Section: %d marker 0x%x",
+ offset, section_index, cur_marker);
size_t bytes_to_write = 0;
size_t bytes_wrote = 0;
if (cur_marker != JPEG_MARKER_SOI &&
cur_marker != JPEG_MARKER_EOI) {
-
unsigned short section_size = 2;
if (JPEG_MARKER_APP1 && cur->exif_data) {
-
unsigned char* tmp = NULL;
- exif_data_save_data (cur->exif_data, &tmp, &exif_output_size);
+ exif_data_save_data(cur->exif_data, &tmp, &exif_output_size);
if (!tmp || 0 == exif_output_size) {
LoggerE("Couldn't generate RAW Exif data!");
throw common::UnknownException("Could not save Exif in JPEG file");
LoggerE("exif_output_size:%d is greater then maximum JPEG section"
"data block size: %d", exif_output_size,
MAX_AVAILABLE_JPEG_SECTION_DATA_SIZE);
- throw common::UnknownException("Exif data is to big to be saved in JPEG file");
+ throw common::UnknownException(
+ "Exif data is to big to be saved in JPEG file");
}
section_size += exif_output_size;
write_exif_data = true;
- }
- else {
+ } else {
section_size += cur->size;
write_section_data = true;
}
bytes_to_write += 2;
}
- LoggerD("offset:%d | Writing section: marker:0x%x size:%d", offset, cur_marker,
- cur->size);
+ LoggerD("offset:%d | Writing section:"
+ " marker:0x%x size:%d", offset, cur_marker, cur->size);
bytes_wrote = fwrite(tmp_buf, 1, bytes_to_write, m_out_file);
offset += bytes_wrote;
exif_output_size);
bytes_to_write = exif_output_size;
- bytes_wrote = fwrite(exif_output_data.get(), 1, bytes_to_write, m_out_file);
+ bytes_wrote = fwrite(exif_output_data.get(), 1, bytes_to_write,
+ m_out_file);
offset += bytes_wrote;
if (bytes_wrote != bytes_to_write) {
m_out_file);
if (bytes_wrote != m_padding_data_size) {
- LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote", m_padding_data_size,
- bytes_wrote);
+ LoggerE("Couldn't wrote %d bytes! Only %d bytes wrote",
+ m_padding_data_size, bytes_wrote);
throw common::UnknownException("Could not write JPEG file");
}
}
if (fclose(m_out_file) == EOF) {
LoggerE("Couldn't close output file: %s", out_path.c_str());
m_out_file = NULL;
- } else {
+ } else {
m_out_file = NULL;
- LoggerD("Closed output file: %s wrote:%d bytes: %d", out_path.c_str(), offset);
+ LoggerD("Closed output file: %s wrote:%d bytes: %d",
+ out_path.c_str(), offset);
}
}
size_t num_exif_sections = 0;
JpegFileSectionPtr first_exif_section;
- for (SectionsVec::iterator it = m_sections.begin(); it != m_sections.end(); ++it) {
+ for (SectionsVec::iterator it = m_sections.begin();
+ it != m_sections.end(); ++it) {
JpegFileSectionPtr cur = *it;
if (JPEG_MARKER_APP1 == cur->type) {
if (!cur->exif_data) {
- LoggerW("Warning: found APP1 section but exif_data is NULL (Not Exif?)");
+ LoggerW("Warning: found APP1 section but exif_data is NULL"
+ " (Not Exif?)");
continue;
}
++num_exif_sections;
if (!first_exif_section) {
first_exif_section = cur;
- }
- else {
- LoggerW("Warning: found %d APP1/Exif sections - only first is currently supported!");
+ } else {
+ LoggerW("Warning: found %d APP1/Exif sections -"
+ " only first is currently supported!");
}
}
}
#include "rational.h"
-#include "math.h"
+#include <cmath>
+#include <sstream>
#include "common/platform_exception.h"
#include "common/logger.h"
#include "exif_util.h"
-#include <sstream>
-
namespace extension {
namespace exif {
if (value < 0.000000001) {
LoggerD("Skipping calculation returning: Rational(0,1)");
- return Rational(0,1);
+ return Rational(0, 1);
}
long m[2][2];
m[0][0] = m[1][1] = 1;
m[0][1] = m[1][0] = 0;
- //loop finding terms until daemon gets too big
+ // loop finding terms until daemon gets too big
do {
ai = static_cast<long>(x);
- if(m[1][0] * ai + m[1][1] > precision) {
+ if (m[1][0] * ai + m[1][1] > precision) {
break;
}
if (x > DOUBLE_ERROR_REPRESENTATION) {
break; // AF: representation failure
}
- } while(1);
+ } while (1);
// now remaining x is between 0 and 1/ai
// approx as either 0 or 1/m where m is max that will fit in precision
// first try zero
- const double error0 = startx - ((double) m[0][0] / (double) m[1][0]);
+ const double error0 =
+ startx - (static_cast<double>(m[0][0]) / static_cast<double>(m[1][0]));
const long numerator0 = m[0][0];
const long denominator0 = m[1][0];
double error1m = startx -
(static_cast<double>(m[0][0]) / static_cast<double>(m[1][0]));
- LoggerD("%ld/%ld, error = %e\n", m[0][0], m[1][0], error1m );
+ LoggerD("%ld/%ld, error = %e\n", m[0][0], m[1][0], error1m);
long result_numerator = 0;
long result_denominator = 0;
- if (error0 < error1m ) {
+ if (error0 < error1m) {
result_numerator = numerator0;
result_denominator = denominator0;
- }
- else {
+ } else {
result_numerator = m[0][0];
result_denominator = m[1][0];
}
result_denominator *= -1;
}
- LoggerD("Rational(%d, %d) error0 < error1m:%d", result_numerator, result_denominator,
- error0 < error1m);
+ LoggerD("Rational(%d, %d) error0 < error1m:%d",
+ result_numerator, result_denominator, error0 < error1m);
return Rational(numerator0, denominator0);
}
Rational Rational::createInvalid() {
- return Rational(0,0);
+ return Rational(0, 0);
}
bool Rational::isValid() const {
if (0 == denominator) {
return false;
- }
- else {
+ } else {
return true;
}
}
return NAN;
}
- return (double)nominator / (double)denominator;
+ return static_cast<double>(nominator) / static_cast<double>(denominator);
}
Rational Rational::createFromExposureTimeString(const std::string& exp_time) {
LoggerD("Entered");
if (exp_time.length() == 0) {
- return Rational::createInvalid(); //lets assume that empty string means 0,
- //however exposure time = 0 is not valid value
+ return Rational::createInvalid(); // lets assume that empty string means 0,
+ // however exposure time = 0 is
+ // not valid value
}
std::string integer_part;
int first_space_at = -1;
int first_slash_at = -1;
- for(size_t i=0; i < exp_time.size(); ++i) {
-
+ for (size_t i = 0; i < exp_time.size(); ++i) {
const char& cur = exp_time[i];
if (first_space_at < 0 && ' ' == cur) {
first_space_at = i;
if (first_slash_at > 0) {
if (first_space_at > 0) {
- integer_part = exp_time.substr(0,first_space_at);
- fraction_part = exp_time.substr(first_space_at+1,
- exp_time.size() - (first_space_at+1));
- }
- else {
+ integer_part = exp_time.substr(0, first_space_at);
+ fraction_part = exp_time.substr(first_space_at + 1,
+ exp_time.size() - (first_space_at + 1));
+ } else {
fraction_part = exp_time;
}
- }
- else {
+ } else {
integer_part = exp_time;
}
LoggerD("first_space_at: %d first_slash_at:%d int: [%s] , frac: [%s]",
- first_space_at, first_slash_at, integer_part.c_str(), fraction_part.c_str());
+ first_space_at, first_slash_at,
+ integer_part.c_str(), fraction_part.c_str());
long integer_value = 0;
long nominator = 0;
}
if (fraction_part.length() > 0) {
- if (sscanf(fraction_part.c_str(), "%ld/%ld", &nominator, &denominator) != 2) {
+ if (sscanf(
+ fraction_part.c_str(), "%ld/%ld", &nominator, &denominator) != 2) {
LoggerD("Failed to parse nominator/denominator string: [%s]",
fraction_part.c_str());
return Rational::createInvalid();
}
nominator += denominator * integer_value;
- LoggerD("%d/%d -> %f", nominator, denominator, (float)nominator / denominator);
+ LoggerD("%d/%d -> %f",
+ nominator, denominator, static_cast<float>(nominator) / denominator);
if (0 == nominator) {
- //Exposure time = 0 is invalid value
+ // Exposure time = 0 is invalid value
return Rational::createInvalid();
}
if (nominator < denominator) {
output_str = toString();
- }
- else if (nominator % denominator == 0) {
+ } else if (nominator % denominator == 0) {
std::stringstream ss;
ss << nominator / denominator;
output_str = ss.str();
- }
- else {
+ } else {
ExifLong new_nominator = nominator % denominator;
ExifLong new_denominator = denominator;
ExifLong integer_value = nominator / denominator;
/**
* This class represents fraction as nominator/denominator - two ExifLong values
- * Rational type is present in Exif specification - used for example in GPS coordinates
+ * Rational type is present in Exif specification - used for example
+ * in GPS coordinates
*/
class Rational {
public:
static Rational createInvalid();
/**
- * Returns true if denominator is valid (!= 0) and therefore whole Rational is valid
+ * Returns true if denominator is valid (!= 0) and therefore whole Rational
+ * is valid
*/
bool isValid() const;
/**
* Returns string in format: nominator/denominator,
* for example: "1/4", "1/1", "5/3".
- *
*/
std::string toString() const;