From: Konrad Zdunczyk Date: Tue, 13 Jan 2015 09:51:44 +0000 (+0100) Subject: [Exif] Fixed coding-style X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~637 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1c84e94647dbcb7fe168a7b0e10579af2247cd1b;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Exif] Fixed coding-style Change-Id: I887b0fb9fa1e98054011e9c22536f108521adf26 Signed-off-by: Konrad Zdunczyk --- diff --git a/src/exif/ExifGPSLocation.cpp b/src/exif/ExifGPSLocation.cpp deleted file mode 100644 index b1f5b0b9..00000000 --- a/src/exif/ExifGPSLocation.cpp +++ /dev/null @@ -1,237 +0,0 @@ -// -// Tizen Web Device API -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#include "ExifGPSLocation.h" - -#include -#include - -#include "common/platform_exception.h" -#include "common/logger.h" - -namespace extension { -namespace exif { - -GCSPosition::GCSPosition() -{ -} - -GCSPosition::GCSPosition(Rational _degrees, Rational _minutes, Rational _seconds) : - degrees(_degrees), - minutes(_minutes), - seconds(_seconds) { -} - -bool GCSPosition::isValid() const { - if (!(degrees.isValid() && minutes.isValid() && seconds.isValid())) { - return false; - } - - if ((degrees.toDouble() > 180.0f) || - (minutes.toDouble() > 60.0f) || - (seconds.toDouble() > 60.0f)) { - return false; - } - - return toDouble() <= 180.0f; -} - -double GCSPosition::toDouble() const { - const double degrees_value = degrees.toDouble(); - const double minutes_value = minutes.toDouble(); - const double seconds_value = seconds.toDouble(); - return (degrees_value + (minutes_value/60.0) + (seconds_value/3600.0)); -} - -Rationals GCSPosition::toRationalsVector() const { - Rationals vec; - vec.push_back(degrees); - vec.push_back(minutes); - vec.push_back(seconds); - return vec; -} - -std::string GCSPosition::toDebugString() const { - std::stringstream ss; - ss << degrees.toString() << "d "; - ss << minutes.toString() << "m "; - ss << seconds.toString() << "s"; - return ss.str(); -} - -GCSPosition GCSPosition::createFromDouble(double value) { - LoggerD("Entered value:%f"); - if (value < 0) { - LoggerW("Trying to create GCSPosition with double < 0: %f", value); - return GCSPosition(); - } - - if (value > 180.0) { - LoggerW("Trying to create GCSPosition with double > 180.0: %f", value); - return GCSPosition(); - } - - double d_degrees = floor(value); - double left = value - d_degrees; - - double d_minutes = floor(left * 60.0); - left -= d_minutes / 60.0; - - double d_seconds = round(left * 3600.0); - - if (d_seconds >= 60.0) { - d_seconds -= 60.0; - d_minutes++; - } - - if (d_minutes >= 60.0) { - d_minutes -= 60.0; - d_degrees++; - } - - assert(d_degrees <= 180.0); - - LoggerD("d_degrees:%f d_minutes:%f d_seconds:%f", - d_degrees, d_minutes, d_seconds); - - GCSPosition pos; - pos.degrees = Rational(static_cast(d_degrees), 1); - pos.minutes = Rational(static_cast(d_minutes), 1); - pos.seconds = Rational::createFromDouble(d_seconds); - - return pos; -} - -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) { - 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) { - m_is_set[i] = false; - } - - setLongitude(GCSPosition::createFromDouble(longitude)); - setLatitude(GCSPosition::createFromDouble(latitude)); - - if (longitude < 0) { - setLongitudeRef(GPS_LOCATION_WEST); - } else { - setLongitudeRef(GPS_LOCATION_EAST); - } - - if (latitude < 0) { - setLatitudeRef(GPS_LOCATION_SOUTH); - } else { - setLatitudeRef(GPS_LOCATION_NORTH); - } -} - -void ExifGPSLocation::setLongitude(const GCSPosition& longitude) { - if (!longitude.isValid()) { - LoggerW("longitude is not valid!"); - return; - } - - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE] = true; - m_longitude = longitude; -} - -const GCSPosition& ExifGPSLocation::getLongitude() const { - return m_longitude; -} - -void ExifGPSLocation::setLongitudeRef(GPSLocationDirectionLongitude ref) { - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF] = true; - m_longitude_ref = ref; -} - -GPSLocationDirectionLongitude ExifGPSLocation::getLongitudeRef() const { - return m_longitude_ref; -} - -void ExifGPSLocation::setLatitude(const GCSPosition& latitude) { - if (!latitude.isValid()) { - LOGW("latitude is not valid!"); - return; - } - - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE] = true; - m_latitude = latitude; -} - -const GCSPosition& ExifGPSLocation::getLatitude() const { - return m_latitude; -} - -void ExifGPSLocation::setLatitudeRef(GPSLocationDirectionLatitude ref) { - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF] = true; - m_latitude_ref = ref; -} - -GPSLocationDirectionLatitude ExifGPSLocation::getLatitudeRef() const { - return m_latitude_ref; -} - -bool ExifGPSLocation::isSet(ExifGPSLocationAttributes attribute) const { - return m_is_set[attribute]; -} - -void ExifGPSLocation::unset(ExifGPSLocationAttributes attribute) { - m_is_set[attribute] = false; -} - -void ExifGPSLocation::unsetAll() { - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE] = false; - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF] = false; - m_longitude = GCSPosition(); - - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE] = false; - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF] = false; - m_latitude = GCSPosition(); -} - -bool ExifGPSLocation::isComplete() const { - return m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE] && - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF] && - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE] && - m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF]; -} - - -bool ExifGPSLocation::isValid() const { - return isComplete() && m_latitude.isValid() && m_longitude.isValid(); -} - -double ExifGPSLocation::getLongitudeValue() const { - 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 = m_latitude.toDouble() * latitude_dir; - return latitude; -} -} // namespace exif -} // namespace extension diff --git a/src/exif/ExifGPSLocation.h b/src/exif/ExifGPSLocation.h deleted file mode 100644 index 64f69596..00000000 --- a/src/exif/ExifGPSLocation.h +++ /dev/null @@ -1,135 +0,0 @@ -// -// Tizen Web Device API -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Apache License, Version 2.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -#ifndef EXIF_EXIF_EXIFGPSLOCATION_H_ -#define EXIF_EXIF_EXIFGPSLOCATION_H_ - -#include -#include - -#include "exif_util.h" -#include "rational.h" - -namespace extension { -namespace exif { - -enum GPSLocationDirectionLongitude { - GPS_LOCATION_WEST, - GPS_LOCATION_EAST -}; - -enum GPSLocationDirectionLatitude { - GPS_LOCATION_NORTH, - GPS_LOCATION_SOUTH -}; - -enum ExifGPSLocationAttributes { - EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE = 0, - EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF, - EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE, - EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF, - EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES -}; - -/** - * This class represents Global Coordinate System using - * three Rational numbers (as stored in Exif) - */ -struct GCSPosition { - GCSPosition(); - GCSPosition(Rational degrees, Rational minutes, Rational seconds); - - /** - * Create GCSPosition from degrees represented as double value - */ - static GCSPosition createFromDouble(double value); - - /** - * Verify that all components are valid Rational numbers and - * each component is within valid range. Sum of degrees, - * minutes and seconds should not be bigger then 180.0 - */ - bool isValid() const; - - /** - * Return position in degrees - */ - double toDouble() const; - - /** - * Return vector of three rationals: degrees, minutes, seconds - */ - Rationals toRationalsVector() const; - - /** - * Return string for debugging purposes - */ - std::string toDebugString() const; - - Rational degrees; - Rational minutes; - Rational seconds; -}; - -class ExifGPSLocation { - public: - ExifGPSLocation(); - ExifGPSLocation(double longitude, double latitude); - - void setLongitude(const GCSPosition& longitude); - const GCSPosition& getLongitude() const; - - void setLongitudeRef(GPSLocationDirectionLongitude ref); - GPSLocationDirectionLongitude getLongitudeRef() const; - - void setLatitude(const GCSPosition& latitude); - const GCSPosition& getLatitude() const; - - void setLatitudeRef(GPSLocationDirectionLatitude ref); - GPSLocationDirectionLatitude getLatitudeRef() const; - - bool isSet(ExifGPSLocationAttributes attribute) const; - void unset(ExifGPSLocationAttributes attribute); - void unsetAll(); - - /** - * Returns true only if all components are set. - */ - bool isComplete() const; - - /** - * Returns true only if all components are set and valid. - */ - bool isValid() const; - - private: - double getLongitudeValue() const; - double getLatitudeValue() const; - - GCSPosition m_longitude; - GPSLocationDirectionLongitude m_longitude_ref; - - GCSPosition m_latitude; - GPSLocationDirectionLatitude m_latitude_ref; - - bool m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES]; -}; - -} // namespace exif -} // namespace extension - -#endif // EXIF_EXIF_EXIFGPSLOCATION_H_ diff --git a/src/exif/exif.gyp b/src/exif/exif.gyp index bbbd3f7f..6346ac80 100644 --- a/src/exif/exif.gyp +++ b/src/exif/exif.gyp @@ -26,8 +26,8 @@ 'jpeg_file.h', 'rational.cc', 'rational.h', - 'ExifGPSLocation.cpp', - 'ExifGPSLocation.h', + 'exif_gps_location.cc', + 'exif_gps_location.h', ], 'conditions': [ [ 'tizen == 1', { diff --git a/src/exif/exif_extension.cc b/src/exif/exif_extension.cc index fa878c18..782d12d2 100644 --- a/src/exif/exif_extension.cc +++ b/src/exif/exif_extension.cc @@ -8,7 +8,7 @@ namespace { const char kExtensionName[] = "tizen.exif"; const char kExifInformationEntryPoint[] = "tizen.ExifInformation"; -} +} // namespace common::Extension* CreateExtension() { return new ExifExtension; diff --git a/src/exif/exif_gps_location.cc b/src/exif/exif_gps_location.cc new file mode 100644 index 00000000..83017b95 --- /dev/null +++ b/src/exif/exif_gps_location.cc @@ -0,0 +1,240 @@ +// +// Tizen Web Device API +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#include "exif_gps_location.h" + +#include +#include +#include + +#include "common/platform_exception.h" +#include "common/logger.h" + +namespace extension { +namespace exif { + +GCSPosition::GCSPosition() { +} + +GCSPosition::GCSPosition(Rational _degrees, Rational _minutes, + Rational _seconds) : + degrees(_degrees), + minutes(_minutes), + seconds(_seconds) { +} + +bool GCSPosition::isValid() const { + if (!(degrees.isValid() && minutes.isValid() && seconds.isValid())) { + return false; + } + + if ((degrees.toDouble() > 180.0f) || + (minutes.toDouble() > 60.0f) || + (seconds.toDouble() > 60.0f)) { + return false; + } + + return toDouble() <= 180.0f; +} + +double GCSPosition::toDouble() const { + const double degrees_value = degrees.toDouble(); + const double minutes_value = minutes.toDouble(); + const double seconds_value = seconds.toDouble(); + return (degrees_value + (minutes_value/60.0) + (seconds_value/3600.0)); +} + +Rationals GCSPosition::toRationalsVector() const { + Rationals vec; + vec.push_back(degrees); + vec.push_back(minutes); + vec.push_back(seconds); + return vec; +} + +std::string GCSPosition::toDebugString() const { + std::stringstream ss; + ss << degrees.toString() << "d "; + ss << minutes.toString() << "m "; + ss << seconds.toString() << "s"; + return ss.str(); +} + +GCSPosition GCSPosition::createFromDouble(double value) { + LoggerD("Entered value:%f"); + if (value < 0) { + LoggerW("Trying to create GCSPosition with double < 0: %f", value); + return GCSPosition(); + } + + if (value > 180.0) { + LoggerW("Trying to create GCSPosition with double > 180.0: %f", value); + return GCSPosition(); + } + + double d_degrees = floor(value); + double left = value - d_degrees; + + double d_minutes = floor(left * 60.0); + left -= d_minutes / 60.0; + + double d_seconds = round(left * 3600.0); + + if (d_seconds >= 60.0) { + d_seconds -= 60.0; + d_minutes++; + } + + if (d_minutes >= 60.0) { + d_minutes -= 60.0; + d_degrees++; + } + + assert(d_degrees <= 180.0); + + LoggerD("d_degrees:%f d_minutes:%f d_seconds:%f", + d_degrees, d_minutes, d_seconds); + + GCSPosition pos; + pos.degrees = Rational(static_cast(d_degrees), 1); + pos.minutes = Rational(static_cast(d_minutes), 1); + pos.seconds = Rational::createFromDouble(d_seconds); + + return pos; +} + +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) { + 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) { + m_is_set[i] = false; + } + + setLongitude(GCSPosition::createFromDouble(longitude)); + setLatitude(GCSPosition::createFromDouble(latitude)); + + if (longitude < 0) { + setLongitudeRef(GPS_LOCATION_WEST); + } else { + setLongitudeRef(GPS_LOCATION_EAST); + } + + if (latitude < 0) { + setLatitudeRef(GPS_LOCATION_SOUTH); + } else { + setLatitudeRef(GPS_LOCATION_NORTH); + } +} + +void ExifGPSLocation::setLongitude(const GCSPosition& longitude) { + if (!longitude.isValid()) { + LoggerW("longitude is not valid!"); + return; + } + + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE] = true; + m_longitude = longitude; +} + +const GCSPosition& ExifGPSLocation::getLongitude() const { + return m_longitude; +} + +void ExifGPSLocation::setLongitudeRef(GPSLocationDirectionLongitude ref) { + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF] = true; + m_longitude_ref = ref; +} + +GPSLocationDirectionLongitude ExifGPSLocation::getLongitudeRef() const { + return m_longitude_ref; +} + +void ExifGPSLocation::setLatitude(const GCSPosition& latitude) { + if (!latitude.isValid()) { + LoggerW("latitude is not valid!"); + return; + } + + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE] = true; + m_latitude = latitude; +} + +const GCSPosition& ExifGPSLocation::getLatitude() const { + return m_latitude; +} + +void ExifGPSLocation::setLatitudeRef(GPSLocationDirectionLatitude ref) { + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF] = true; + m_latitude_ref = ref; +} + +GPSLocationDirectionLatitude ExifGPSLocation::getLatitudeRef() const { + return m_latitude_ref; +} + +bool ExifGPSLocation::isSet(ExifGPSLocationAttributes attribute) const { + return m_is_set[attribute]; +} + +void ExifGPSLocation::unset(ExifGPSLocationAttributes attribute) { + m_is_set[attribute] = false; +} + +void ExifGPSLocation::unsetAll() { + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE] = false; + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF] = false; + m_longitude = GCSPosition(); + + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE] = false; + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF] = false; + m_latitude = GCSPosition(); +} + +bool ExifGPSLocation::isComplete() const { + return m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE] && + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF] && + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE] && + m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF]; +} + + +bool ExifGPSLocation::isValid() const { + return isComplete() && m_latitude.isValid() && m_longitude.isValid(); +} + +double ExifGPSLocation::getLongitudeValue() const { + 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 = m_latitude.toDouble() * latitude_dir; + return latitude; +} +} // namespace exif +} // namespace extension diff --git a/src/exif/exif_gps_location.h b/src/exif/exif_gps_location.h new file mode 100644 index 00000000..058df061 --- /dev/null +++ b/src/exif/exif_gps_location.h @@ -0,0 +1,135 @@ +// +// Tizen Web Device API +// Copyright (c) 2014 Samsung Electronics Co., Ltd. +// +// Licensed under the Apache License, Version 2.0 (the License); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +#ifndef EXIF_EXIF_GPS_LOCATION_H_ +#define EXIF_EXIF_GPS_LOCATION_H_ + +#include +#include + +#include "exif_util.h" +#include "rational.h" + +namespace extension { +namespace exif { + +enum GPSLocationDirectionLongitude { + GPS_LOCATION_WEST, + GPS_LOCATION_EAST +}; + +enum GPSLocationDirectionLatitude { + GPS_LOCATION_NORTH, + GPS_LOCATION_SOUTH +}; + +enum ExifGPSLocationAttributes { + EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE = 0, + EXIF_GPS_LOCATION_ATTRIBUTE_LONGITUDE_REF, + EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE, + EXIF_GPS_LOCATION_ATTRIBUTE_LATITUDE_REF, + EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES +}; + +/** + * This class represents Global Coordinate System using + * three Rational numbers (as stored in Exif) + */ +struct GCSPosition { + GCSPosition(); + GCSPosition(Rational degrees, Rational minutes, Rational seconds); + + /** + * Create GCSPosition from degrees represented as double value + */ + static GCSPosition createFromDouble(double value); + + /** + * Verify that all components are valid Rational numbers and + * each component is within valid range. Sum of degrees, + * minutes and seconds should not be bigger then 180.0 + */ + bool isValid() const; + + /** + * Return position in degrees + */ + double toDouble() const; + + /** + * Return vector of three rationals: degrees, minutes, seconds + */ + Rationals toRationalsVector() const; + + /** + * Return string for debugging purposes + */ + std::string toDebugString() const; + + Rational degrees; + Rational minutes; + Rational seconds; +}; + +class ExifGPSLocation { + public: + ExifGPSLocation(); + ExifGPSLocation(double longitude, double latitude); + + void setLongitude(const GCSPosition& longitude); + const GCSPosition& getLongitude() const; + + void setLongitudeRef(GPSLocationDirectionLongitude ref); + GPSLocationDirectionLongitude getLongitudeRef() const; + + void setLatitude(const GCSPosition& latitude); + const GCSPosition& getLatitude() const; + + void setLatitudeRef(GPSLocationDirectionLatitude ref); + GPSLocationDirectionLatitude getLatitudeRef() const; + + bool isSet(ExifGPSLocationAttributes attribute) const; + void unset(ExifGPSLocationAttributes attribute); + void unsetAll(); + + /** + * Returns true only if all components are set. + */ + bool isComplete() const; + + /** + * Returns true only if all components are set and valid. + */ + bool isValid() const; + + private: + double getLongitudeValue() const; + double getLatitudeValue() const; + + GCSPosition m_longitude; + GPSLocationDirectionLongitude m_longitude_ref; + + GCSPosition m_latitude; + GPSLocationDirectionLatitude m_latitude_ref; + + bool m_is_set[EXIF_GPS_LOCATION_ATTRIBUTE_NUMBER_OF_ATTRIBUTES]; +}; + +} // namespace exif +} // namespace extension + +#endif // EXIF_EXIF_GPS_LOCATION_H_ diff --git a/src/exif/exif_information.cc b/src/exif/exif_information.cc index eaaed31b..1badf3f6 100644 --- a/src/exif/exif_information.cc +++ b/src/exif/exif_information.cc @@ -18,16 +18,16 @@ #include "exif_information.h" #include -#include - -#include "exif_tag_saver.h" -#include "exif_util.h" -#include "jpeg_file.h" +#include #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 { @@ -64,13 +64,15 @@ IsoSpeedRatingsVector jsonArray2vector(const picojson::value& a) { } // 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(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(attr)); } @@ -258,8 +260,9 @@ const Rational& ExifInformation::getFocalLength() const { 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; } @@ -313,7 +316,8 @@ const Rational& ExifInformation::getGpsAltitude() const { 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; } @@ -336,7 +340,7 @@ void ExifInformation::setGpsAltitudeWithRef(double gps_altitude) { 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); @@ -509,72 +513,92 @@ void ExifInformation::set(std::string attributeName, const picojson::value& v) { LoggerD("Entered | name: %s", attributeName.c_str()); switch (str2int(attributeName.c_str())) { - case str2int(EI_URI): + case str2int(EI_URI): { setUri(v.get()); break; - case str2int(EI_WIDTH): + } + case str2int(EI_WIDTH): { setWidth(static_cast(v.get())); break; - case str2int(EI_HEIGHT): + } + case str2int(EI_HEIGHT): { setHeight(static_cast(v.get())); break; - case str2int(EI_DEVICE_MAKER): + } + case str2int(EI_DEVICE_MAKER): { setDeviceMaker(v.get()); break; - case str2int(EI_DEVICE_MODEL): + } + case str2int(EI_DEVICE_MODEL): { setDeviceModel(v.get()); break; - case str2int(EI_ORIGINAL_TIME): + } + case str2int(EI_ORIGINAL_TIME): { setOriginalTime(static_cast(v.get())); break; - case str2int(EI_ORIENTATION): + } + case str2int(EI_ORIENTATION): { setOrientation(v.get()); break; - case str2int(EI_FNUMBER): + } + case str2int(EI_FNUMBER): { setFNumber(Rational::createFromDouble(v.get())); 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())); break; - case str2int(EI_EXPOSURE_PROGRAM): + } + case str2int(EI_EXPOSURE_PROGRAM): { setExposureProgram(v.get()); break; - case str2int(EI_FLASH): + } + case str2int(EI_FLASH): { setFlash(v.get()); break; - case str2int(EI_FOCAL_LENGTH): + } + case str2int(EI_FOCAL_LENGTH): { setFocalLength(Rational::createFromDouble(v.get())); break; - case str2int(EI_WHITE_BALANCE): + } + case str2int(EI_WHITE_BALANCE): { setWhiteBalanceMode(v.get()); break; - case str2int(EI_GPS_LOCATION): + } + case str2int(EI_GPS_LOCATION): { setGPSLocation(ExifGPSLocation(v.get("longitude").get(), v.get("latitude").get())); break; - case str2int(EI_GPS_ALTITUDE): + } + case str2int(EI_GPS_ALTITUDE): { setGpsAltitudeWithRef(v.get()); break; - case str2int(EI_GPS_PROCESSING_METHOD): + } + case str2int(EI_GPS_PROCESSING_METHOD): { setGpsProcessingMethod(EXIF_UNDEFINED_TYPE_ASCII, v.get()); break; - case str2int(EI_GPS_TIME): + } + case str2int(EI_GPS_TIME): { setGpsTime(static_cast(v.get())); - break; - case str2int(EI_USER_COMMENT): + break; + } + case str2int(EI_USER_COMMENT): { setUserComment(EXIF_UNDEFINED_TYPE_ASCII, v.get()); 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) { @@ -585,8 +609,7 @@ bool getGCSPositionFromEntry(ExifEntry *entry, ExifData* exif_data, GCSPosition& out_pos.seconds = Rational(exif_get_rational( entry->data + 2*ExifTypeInfo::RationalSize, order)); return true; - } - else { + } else { return false; } } @@ -600,36 +623,38 @@ bool getRationalsFromEntry(ExifEntry *entry, ExifData* exif_data, 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; } @@ -652,53 +677,53 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { switch (static_cast(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(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(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(orient)); } @@ -706,21 +731,21 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { } 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) { @@ -729,7 +754,7 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_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", @@ -737,18 +762,16 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { 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)); @@ -757,72 +780,68 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { 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(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); @@ -831,38 +850,35 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { 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(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(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; @@ -873,54 +889,50 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { 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(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(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(entry->data[0]); - if(static_cast(GPS_ALTITUDE_REF_ABOVE_SEA) == altitude_ref || + if (static_cast(GPS_ALTITUDE_REF_ABOVE_SEA) == altitude_ref || static_cast(GPS_ALTITUDE_REF_BELOW_SEA) == altitude_ref) { setGpsAltitudeRef(static_cast(altitude_ref)); - LoggerD( "Setting ExifInformation gps altitude ref to: %d (%s)", + LoggerD("Setting ExifInformation gps altitude ref to: %d (%s)", static_cast(altitude_ref), (altitude_ref > 0) ? "below sea" : "above sea"); } else { @@ -930,64 +942,66 @@ void ExifInformation::processEntry(ExifEntry* entry, ExifData* exif_data) { 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))); + } } } @@ -996,8 +1010,10 @@ struct ExifInfoAndDataHolder { ExifData* exif_data; }; -void ExifInformation::contentForeachFunctionProxy(ExifEntry *entry, void *user_data) { - ExifInfoAndDataHolder* holder = static_cast(user_data); +void ExifInformation::contentForeachFunctionProxy(ExifEntry *entry, + void *user_data) { + ExifInfoAndDataHolder* holder = + static_cast(user_data); if (!holder) { LoggerE("holder is NULL"); } @@ -1024,7 +1040,8 @@ void ExifInformation::contentForeachFunctionProxy(ExifEntry *entry, void *user_d } } -void ExifInformation::dataForeachFunction(ExifContent *content, void *user_data) { +void ExifInformation::dataForeachFunction(ExifContent *content, + void *user_data) { exif_content_foreach_entry(content, contentForeachFunctionProxy, user_data); } @@ -1034,11 +1051,10 @@ ExifInformationPtr ExifInformation::loadFromURI(const std::string& uri) { 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"); @@ -1046,7 +1062,8 @@ ExifInformationPtr ExifInformation::loadFromURI(const std::string& uri) { ExifInfoAndDataHolder holder; holder.exif_info = exif_info; holder.exif_data = ed; - exif_data_foreach_content(ed, dataForeachFunction, static_cast(&holder)); + exif_data_foreach_content(ed, dataForeachFunction, + static_cast(&holder)); LoggerD("exif_data_foreach_content END"); @@ -1058,8 +1075,8 @@ ExifInformationPtr ExifInformation::loadFromURI(const std::string& uri) { 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"); } @@ -1098,7 +1115,8 @@ void ExifInformation::removeNulledAttributesFromExifData(ExifData* exif_data) { } 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"); @@ -1124,7 +1142,7 @@ void ExifInformation::removeNulledAttributesFromExifData(ExifData* exif_data) { if (!isSet(EXIF_INFORMATION_ATTRIBUTE_GPS_ALTITUDE)) { LoggerD("Removing gps altitude"); ExifTagSaver::removeExifEntryWithTag( - static_cast(EXIF_TAG_GPS_ALTITUDE), exif_data); + static_cast(EXIF_TAG_GPS_ALTITUDE), exif_data); } if (!isSet(EXIF_INFORMATION_ATTRIBUTE_GPS_ALTITUDE_REF)) { LoggerD("Removing gps altitude ref"); @@ -1164,7 +1182,7 @@ void ExifInformation::removeNulledAttributesFromExifData(ExifData* exif_data) { 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"); } @@ -1190,7 +1208,8 @@ void ExifInformation::updateAttributesInExifData(ExifData* exif_data) { EXIF_TAG_ORIENTATION, exif_data); } if (isSet(EXIF_INFORMATION_ATTRIBUTE_EXPOSURE_PROGRAM)) { - LoggerD("Saving exposure program: %d", static_cast(getExposureProgram())); + LoggerD("Saving exposure program: %d", + static_cast(getExposureProgram())); ExifTagSaver::saveToExif(getExposureProgram(), EXIF_TAG_EXPOSURE_PROGRAM, exif_data); } @@ -1201,7 +1220,8 @@ void ExifInformation::updateAttributesInExifData(ExifData* exif_data) { EXIF_TAG_ISO_SPEED_RATINGS, exif_data); } if (isSet(EXIF_INFORMATION_ATTRIBUTE_WHITE_BALANCE)) { - LoggerD("Saving white balance: %d", static_cast(getWhiteBalanceMode())); + LoggerD("Saving white balance: %d", + static_cast(getWhiteBalanceMode())); ExifTagSaver::saveToExif(getWhiteBalanceMode(), EXIF_TAG_WHITE_BALANCE, exif_data); } @@ -1212,9 +1232,10 @@ void ExifInformation::updateAttributesInExifData(ExifData* 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(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(o_time), o_time_str.c_str()); ExifTagSaver::saveToExif(o_time_str, EXIF_TAG_DATE_TIME_ORIGINAL, exif_data); @@ -1260,9 +1281,9 @@ void ExifInformation::updateAttributesInExifData(ExifData* exif_data) { static_cast(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(m_gps_altitude_ref), (static_cast(m_gps_altitude_ref) > 0) ? "below sea" : "above sea"); @@ -1276,7 +1297,8 @@ void ExifInformation::updateAttributesInExifData(ExifData* exif_data) { 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, @@ -1287,20 +1309,21 @@ void ExifInformation::updateAttributesInExifData(ExifData* exif_data) { 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(gps_time)); ExifTagSaver::saveToExif(gps_time_vec, - static_cast(EXIF_TAG_GPS_TIME_STAMP), exif_data); + static_cast(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(EXIF_TAG_GPS_DATE_STAMP), exif_data, EXIF_FORMAT_ASCII, false); + static_cast(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()); @@ -1312,15 +1335,17 @@ void ExifInformation::updateAttributesInExifData(ExifData* exif_data) { 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); @@ -1339,16 +1364,16 @@ void ExifInformation::saveToFile(const std::string& file_path) { 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); } diff --git a/src/exif/exif_information.h b/src/exif/exif_information.h index e5c74f2c..62ca1dd1 100644 --- a/src/exif/exif_information.h +++ b/src/exif/exif_information.h @@ -15,15 +15,15 @@ // 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 #include #include #include -#include "ExifGPSLocation.h" +#include "exif_gps_location.h" #include "common/picojson.h" namespace extension { @@ -253,4 +253,4 @@ class ExifInformation { } // namespace exif } // namespace extension -#endif // EXIF_EXIF_EXIFINFORMATION_H_ +#endif // EXIF_EXIF_INFORMATION_H_ diff --git a/src/exif/exif_instance.cc b/src/exif/exif_instance.cc index b6878c0d..534061d9 100644 --- a/src/exif/exif_instance.cc +++ b/src/exif/exif_instance.cc @@ -31,7 +31,7 @@ namespace { const char kGetExifInfoCmd[] = "Exif_getExifInfo"; const char kSaveExifInfoCmd[] = "Exif_saveExifInfo"; const char kGetThumbnailCmd[] = "Exif_getThumbnail"; -} +} // namespace ExifInstance::ExifInstance() { using namespace std::placeholders; @@ -139,7 +139,7 @@ void ExifInstance::getExifInfo(const picojson::value& args, } void ExifInstance::saveExifInfo(const picojson::value& args, - picojson::object& out) { + picojson::object& out) { const std::string& uri = args.get("uri").get(); const double callback_id = args.get("callbackId").get(); @@ -157,12 +157,12 @@ void ExifInstance::saveExifInfo(const picojson::value& args, }; auto get_response = - [callback_id, this](const std::shared_ptr& response) -> void { - picojson::object& obj = response->get(); - 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& response) -> void { + picojson::object& obj = response->get(); + 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( get, get_response, @@ -170,7 +170,7 @@ void ExifInstance::saveExifInfo(const picojson::value& args, } void ExifInstance::getThumbnail(const picojson::value& args, - picojson::object& out) { + picojson::object& out) { LoggerE("getThumbnail is not implemented (c++)"); } diff --git a/src/exif/exif_tag_saver.cc b/src/exif/exif_tag_saver.cc index 9f9a1dbb..573b47a5 100644 --- a/src/exif/exif_tag_saver.cc +++ b/src/exif/exif_tag_saver.cc @@ -29,7 +29,8 @@ 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) { @@ -40,7 +41,8 @@ void ExifTagSaver::removeExifEntryWithTag(const ExifTag tag, ExifData* exif_data 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); @@ -48,20 +50,25 @@ void ExifTagSaver::saveToExif(long int value, ExifTag tag, ExifData* 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(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); + } } } @@ -70,7 +77,6 @@ void ExifTagSaver::saveToExif(const std::string& value, ExifTag tag, bool add_zero_character) { ExifEntry* entry = prepareEntry(exif_data, tag); if (!value.empty()) { - if (entry->data) { free(entry->data); entry->data = NULL; @@ -93,7 +99,8 @@ void ExifTagSaver::saveToExif(const std::string& value, ExifTag tag, } } -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; @@ -117,7 +124,8 @@ void ExifTagSaver::saveToExif(const Rational& value, ExifTag tag, ExifData* exif 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; @@ -135,8 +143,7 @@ void ExifTagSaver::saveToExif(const Rationals& value, ExifTag tag, ExifData* exi } 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; @@ -144,8 +151,9 @@ void ExifTagSaver::saveToExif(const Rationals& value, ExifTag tag, ExifData* exi } } -void ExifTagSaver::saveToExif(std::vector& value, ExifFormat store_as, - ExifTag tag, ExifData* exif_data) { +void ExifTagSaver::saveToExif(std::vector& 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); @@ -180,12 +188,11 @@ void ExifTagSaver::saveToExif(std::vector& value, ExifFormat stor 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(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, @@ -193,7 +200,6 @@ void ExifTagSaver::saveToExif(std::vector& value, ExifFormat stor } break; } - case EXIF_FORMAT_SSHORT: { for (size_t i = 0; i < num_elements; ++i) { exif_set_sshort(entry->data + i * size_per_member, order, @@ -201,7 +207,6 @@ void ExifTagSaver::saveToExif(std::vector& value, ExifFormat stor } break; } - case EXIF_FORMAT_LONG: { for (size_t i = 0; i < num_elements; ++i) { exif_set_long(entry->data + i * size_per_member, order, @@ -209,26 +214,23 @@ void ExifTagSaver::saveToExif(std::vector& value, ExifFormat stor } 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(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()); @@ -241,11 +243,10 @@ void ExifTagSaver::saveGpsLocationToExif(const ExifGPSLocation& gps_info, (gps_info.getLatitudeRef() == GPS_LOCATION_NORTH) ? "N" : "S"; LoggerD("Saving latitude ref: %s", lat_ref.c_str()); saveToExif(lat_ref, static_cast(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(), @@ -257,7 +258,7 @@ void ExifTagSaver::saveGpsLocationToExif(const ExifGPSLocation& gps_info, (gps_info.getLongitudeRef() == GPS_LOCATION_WEST) ? "W" : "E"; LoggerD("Saving longitude ref: %s", long_ref.c_str()); saveToExif(long_ref, static_cast(EXIF_TAG_GPS_LONGITUDE_REF), - exif_data, EXIF_FORMAT_ASCII, false); + exif_data, EXIF_FORMAT_ASCII, false); } } @@ -267,12 +268,12 @@ ExifEntry* ExifTagSaver::prepareEntry(ExifData* exif_data, ExifTag tag) { 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); @@ -281,7 +282,7 @@ ExifEntry* ExifTagSaver::prepareEntry(ExifData* exif_data, ExifTag 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(); @@ -294,7 +295,7 @@ ExifEntry* ExifTagSaver::createNewTag(ExifData* exif_data, ExifIfd ifd, ExifIfd ExifTagSaver::deduceIfdSection(ExifTag tag) { switch (static_cast(tag)) { - //Tags in IFD_0 Section + // Tags in IFD_0 Section case EXIF_TAG_MAKE: case EXIF_TAG_MODEL: case EXIF_TAG_IMAGE_WIDTH: @@ -302,7 +303,7 @@ ExifIfd ExifTagSaver::deduceIfdSection(ExifTag tag) { 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: @@ -314,7 +315,7 @@ ExifIfd ExifTagSaver::deduceIfdSection(ExifTag tag) { 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: @@ -326,32 +327,32 @@ ExifIfd ExifTagSaver::deduceIfdSection(ExifTag tag) { 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(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: @@ -360,7 +361,7 @@ ExifFormat ExifTagSaver::deduceDataFormat(ExifTag tag) { 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: @@ -371,15 +372,15 @@ ExifFormat ExifTagSaver::deduceDataFormat(ExifTag tag) { 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"); } } diff --git a/src/exif/exif_tag_saver.h b/src/exif/exif_tag_saver.h index 692f1c39..8d7766cc 100644 --- a/src/exif/exif_tag_saver.h +++ b/src/exif/exif_tag_saver.h @@ -19,15 +19,15 @@ * @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 #include #include -#include "ExifGPSLocation.h" +#include "exif_gps_location.h" namespace extension { namespace exif { @@ -36,17 +36,14 @@ class ExifTagSaver { 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& value, ExifFormat store_as, ExifTag tag, ExifData* exif_data); static void saveGpsLocationToExif(const ExifGPSLocation& gps_info, @@ -57,10 +54,10 @@ class ExifTagSaver { 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_ diff --git a/src/exif/exif_util.cc b/src/exif/exif_util.cc index a3fb017a..ecc3b410 100644 --- a/src/exif/exif_util.cc +++ b/src/exif/exif_util.cc @@ -49,11 +49,11 @@ const std::string EXPOSURE_PROGRAM_ACTION_PROGRAM = "ACTION_PROGRAM"; 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; @@ -132,7 +132,8 @@ const std::string& ExifUtil::orientationToString(ImageOrientation orientation) { } } -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; @@ -219,30 +220,32 @@ bool ExifUtil::isValidAbsoluteURI(const std::string& uri) { } 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()); } @@ -257,8 +260,7 @@ std::string ExifUtil::convertUriToPath(const std::string& str) { if (prefix == URI_PREFIX) { return path.substr(URI_PREFIX.size()); - } - else { + } else { return path; } } @@ -271,10 +273,10 @@ std::string ExifUtil::ltrim(const std::string& s) { break; } } + if (i == str.end()) { str.clear(); - } - else { + } else { str.erase(str.begin(), i); } return str; @@ -283,7 +285,7 @@ std::string ExifUtil::ltrim(const std::string& s) { 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); } @@ -295,12 +297,12 @@ std::string ExifUtil::timeTToExifDateTimeOriginal(time_t time) { 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(); } @@ -331,8 +333,8 @@ std::string ExifUtil::timeTToExifGpsDateStamp(time_t time) { 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()); @@ -388,16 +390,15 @@ void ExifUtil::printExifEntryInfo(ExifEntry* entry, ExifData* exif_data) { 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; } @@ -408,15 +409,15 @@ void ExifUtil::printExifEntryInfo(ExifEntry* entry, ExifData* exif_data) { 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(entry->size), + static_cast(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; @@ -428,7 +429,7 @@ void ExifUtil::extractFromTimeT(const time_t time, } 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; @@ -439,8 +440,8 @@ time_t ExifUtil::convertToTimeT(int year, int month, int day, 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); } diff --git a/src/exif/jpeg_file.cc b/src/exif/jpeg_file.cc index f7c5d0f5..24f564b0 100644 --- a/src/exif/jpeg_file.cc +++ b/src/exif/jpeg_file.cc @@ -23,7 +23,7 @@ #include #include -#include +#include #include #include "common/platform_exception.h" @@ -42,7 +42,8 @@ const unsigned int MAX_JPEG_SECTION_DATA_SIZE = 65535; * 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; @@ -88,7 +89,8 @@ JpegFile::~JpegFile() { 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) { @@ -171,8 +173,8 @@ void JpegFile::load(const std::string& path) { } 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(offset) - num_bytes_before; if (start < 0) { start = 0; @@ -185,7 +187,7 @@ std::string JpegFile::getPartOfFile(const size_t offset, 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(m_in_data[i]); } return ss.str(); @@ -195,33 +197,33 @@ std::string JpegFile::getPartOfFile(const size_t offset, 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; @@ -237,21 +239,21 @@ void JpegFile::generateListOfSections() { 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; { @@ -273,35 +275,36 @@ void JpegFile::generateListOfSections() { 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"); } @@ -315,12 +318,12 @@ void JpegFile::generateListOfSections() { } 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" @@ -329,23 +332,28 @@ void JpegFile::generateListOfSections() { 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; @@ -354,13 +362,14 @@ void JpegFile::generateListOfSections() { 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); @@ -368,10 +377,10 @@ void JpegFile::generateListOfSections() { 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); } } @@ -380,10 +389,10 @@ void JpegFile::generateListOfSections() { 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); } } } @@ -393,19 +402,20 @@ bool JpegFile::searchForTagInBuffer(const unsigned char* buffer_start, 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; } @@ -413,10 +423,9 @@ bool JpegFile::searchForTagInBuffer(const unsigned char* buffer_start, LoggerD("Bytes to scan: %d", static_cast(buffer_end - buffer_start)); const unsigned char marker_uchar = static_cast(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(ptr - buffer_start); return true; } @@ -453,8 +462,7 @@ void JpegFile::setNewExifData(ExifData* new_exif_data) { 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; } } @@ -464,23 +472,22 @@ void JpegFile::setNewExifData(ExifData* new_exif_data) { 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; } @@ -506,16 +513,15 @@ void JpegFile::saveToFile(const std::string& out_path) { 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! " @@ -545,14 +551,14 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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; @@ -570,12 +576,10 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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"); @@ -590,12 +594,12 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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; } @@ -604,8 +608,8 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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; @@ -635,7 +639,8 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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) { @@ -667,8 +672,8 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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"); } } @@ -676,9 +681,10 @@ void JpegFile::saveToFilePriv(const std::string& out_path) { 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); } } @@ -686,21 +692,23 @@ JpegFileSectionPtr JpegFile::getExifSection() { 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!"); } } } diff --git a/src/exif/rational.cc b/src/exif/rational.cc index 9426402b..2f1f9627 100644 --- a/src/exif/rational.cc +++ b/src/exif/rational.cc @@ -17,15 +17,14 @@ #include "rational.h" -#include "math.h" +#include +#include #include "common/platform_exception.h" #include "common/logger.h" #include "exif_util.h" -#include - namespace extension { namespace exif { @@ -57,7 +56,7 @@ Rational Rational::createFromDouble(const double value, const long precision) { if (value < 0.000000001) { LoggerD("Skipping calculation returning: Rational(0,1)"); - return Rational(0,1); + return Rational(0, 1); } long m[2][2]; @@ -70,10 +69,10 @@ Rational Rational::createFromDouble(const double value, const long precision) { 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(x); - if(m[1][0] * ai + m[1][1] > precision) { + if (m[1][0] * ai + m[1][1] > precision) { break; } @@ -93,12 +92,13 @@ Rational Rational::createFromDouble(const double value, const long precision) { 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(m[0][0]) / static_cast(m[1][0])); const long numerator0 = m[0][0]; const long denominator0 = m[1][0]; @@ -111,16 +111,15 @@ Rational Rational::createFromDouble(const double value, const long precision) { double error1m = startx - (static_cast(m[0][0]) / static_cast(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]; } @@ -132,21 +131,20 @@ Rational Rational::createFromDouble(const double value, const long precision) { 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; } } @@ -156,14 +154,15 @@ double Rational::toDouble() const { return NAN; } - return (double)nominator / (double)denominator; + return static_cast(nominator) / static_cast(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; @@ -172,8 +171,7 @@ Rational Rational::createFromExposureTimeString(const std::string& exp_time) { 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; @@ -185,20 +183,19 @@ Rational Rational::createFromExposureTimeString(const std::string& exp_time) { 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; @@ -209,7 +206,8 @@ Rational Rational::createFromExposureTimeString(const std::string& exp_time) { } 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(); @@ -217,10 +215,11 @@ Rational Rational::createFromExposureTimeString(const std::string& exp_time) { } nominator += denominator * integer_value; - LoggerD("%d/%d -> %f", nominator, denominator, (float)nominator / denominator); + LoggerD("%d/%d -> %f", + nominator, denominator, static_cast(nominator) / denominator); if (0 == nominator) { - //Exposure time = 0 is invalid value + // Exposure time = 0 is invalid value return Rational::createInvalid(); } @@ -243,13 +242,11 @@ std::string Rational::toExposureTimeString() const { 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; diff --git a/src/exif/rational.h b/src/exif/rational.h index f2fadcb3..f2206d8b 100644 --- a/src/exif/rational.h +++ b/src/exif/rational.h @@ -36,7 +36,8 @@ typedef std::shared_ptr RationalsPtr; /** * 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: @@ -53,7 +54,8 @@ class Rational { 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; @@ -62,7 +64,6 @@ class Rational { /** * Returns string in format: nominator/denominator, * for example: "1/4", "1/1", "5/3". - * */ std::string toString() const;