#include <libexif/exif-data.h>
#include <libexif/exif-entry.h>
-#include <libexif/exif-utils.h>
#include <libexif/exif-loader.h>
+#include <libexif/exif-utils.h>
#include <string>
#include <sstream>
+#include "common/logger.h"
#include "common/platform_exception.h"
#include "common/task-queue.h"
-#include "common/logger.h"
-#include "exif_util.h"
-#include "jpeg_file.h"
-#include "exif_information.h"
-#include "get_exif_info.h"
+#include "exif/exif_information.h"
+#include "exif/exif_util.h"
+#include "exif/get_exif_info.h"
+#include "exif/jpeg_file.h"
namespace extension {
namespace exif {
const double callback_id = args.get("callbackId").get<double>();
auto get = [=](const std::shared_ptr<JsonValue>& response)->void {
- try {
- const std::string file_path = ExifUtil::convertUriToPath(uri);
- LoggerD("file_path = %s\n", file_path.c_str());
-
- JsonValue result_direct = GetExifInfo::LoadFromURI(uri);
- ReportSuccess(result_direct, response->get<picojson::object>());
- }
- catch (const common::PlatformException& e) {
- ReportError(e, response->get<picojson::object>());
- }
+ try {
+ const std::string& file_path = ExifUtil::convertUriToPath(uri);
+ LoggerD("file_path = %s", file_path.c_str());
+
+ JsonValue result_direct = GetExifInfo::LoadFromURI(uri);
+ ReportSuccess(result_direct, response->get<picojson::object>());
+ }
+ catch (const common::PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
};
auto get_response = [callback_id, this](const std::shared_ptr<JsonValue>& response)->void {
- picojson::object& obj = response->get<picojson::object>();
- obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
- LoggerD("callback is %s", response->serialize().c_str());
- PostMessage(response->serialize().c_str());
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
+ PostMessage(response->serialize().c_str());
};
common::TaskQueue::GetInstance().Queue<JsonValue>(
const double callback_id = args.get("callbackId").get<double>();
auto get = [=](const std::shared_ptr<JsonValue>& response)->void {
- try {
- ExifInformationPtr exifInfo(new ExifInformation(args));
- std::string uri = exifInfo->getUri();
- std::string path = ExifUtil::convertUriToPath(uri);
- exifInfo->saveToFile(path);
-
- ReportSuccess(args, response->get<picojson::object>());
- }
- catch (const common::PlatformException& e) {
- ReportError(e, response->get<picojson::object>());
- }
+ try {
+ ExifInformationPtr exifInfo(new ExifInformation(args));
+ const std::string& uri = exifInfo->getUri();
+ const std::string& path = ExifUtil::convertUriToPath(uri);
+ exifInfo->saveToFile(path);
+
+ ReportSuccess(args, response->get<picojson::object>());
+ }
+ catch (const common::PlatformException& e) {
+ ReportError(e, response->get<picojson::object>());
+ }
};
auto get_response = [callback_id, this](const std::shared_ptr<JsonValue>& response)->void {
- picojson::object& obj = response->get<picojson::object>();
- obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
- LoggerD("callback is %s", response->serialize().c_str());
- PostMessage(response->serialize().c_str());
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
+ PostMessage(response->serialize().c_str());
};
common::TaskQueue::GetInstance().Queue<JsonValue>(
const std::string& uri = args.get("uri").get<std::string>();
const double callback_id = args.get("callbackId").get<double>();
- auto get = [=](const std::shared_ptr<JsonValue>& response)->void {
- try {
- const std::string file_path = ExifUtil::convertUriToPath(uri);
- ExifData* exif_data = nullptr;
- JsonValue result = JsonValue(JsonObject());
- JsonObject& result_obj = result.get<JsonObject>();
-
- std::string ext = file_path.substr(file_path.find_last_of(".") + 1);
- std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
-
- if ("jpg" == ext) {
- ext = "jpeg";
- }
+ auto get = [=](const std::shared_ptr<JsonValue> &response) -> void {
+ try {
+ const std::string &file_path = ExifUtil::convertUriToPath(uri);
+ JsonValue result = JsonValue(JsonObject());
+ JsonObject &result_obj = result.get<JsonObject>();
- if ("jpeg" == ext || "png" == ext || "gif" == ext) {
- LoggerD("Get thumbnail from Exif in file: [%s]", file_path.c_str());
+ std::string ext = file_path.substr(file_path.find_last_of(".") + 1);
+ std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
- exif_data = exif_data_new_from_file(file_path.c_str());
- if (!exif_data) {
- LoggerE("Error reading from file [%s]", file_path.c_str());
- throw common::UnknownException("Error reading from file");
+ if ("jpg" == ext) {
+ ext = "jpeg";
}
- if (exif_data->data && exif_data->size) {
- gchar* ch_uri = g_base64_encode(exif_data->data, exif_data->size);
- exif_data_unref(exif_data);
- std::string base64 = "data:image/" + ext + ";base64," + ch_uri;
-
- std::pair<std::string, picojson::value> pair;
- pair = std::make_pair("src", picojson::value(base64));
- result_obj.insert(pair);
+ if ("jpeg" == ext || "png" == ext || "gif" == ext) {
+ LoggerD("Get thumbnail from Exif in file: [%s]", file_path.c_str());
+ ExifData *exif_data = exif_data_new_from_file(file_path.c_str());
+ if (!exif_data) {
+ LoggerE("Error reading from file [%s]", file_path.c_str());
+ throw common::UnknownException("Error reading from file");
+ }
+
+ if (exif_data->data && exif_data->size) {
+ gchar *ch_uri = g_base64_encode(exif_data->data, exif_data->size);
+ exif_data_unref(exif_data);
+ std::string base64 = "data:image/" + ext + ";base64," + ch_uri;
+
+ std::pair<std::string, picojson::value> pair;
+ pair = std::make_pair("src", picojson::value(base64));
+ result_obj.insert(pair);
+ } else {
+ exif_data_unref(exif_data);
+ LoggerE("File [%s] doesn't contain thumbnail", file_path.c_str());
+ throw common::UnknownException("File doesn't contain thumbnail");
+ }
} else {
- exif_data_unref(exif_data);
- LoggerE("File [%s] doesn't contain thumbnail", file_path.c_str());
- throw common::UnknownException("File doesn't contain thumbnail");
+ LoggerE("extension: %s is not valid (jpeg/jpg/png/gif is supported)", ext.c_str());
+ throw common::InvalidValuesException("getThumbnail support only jpeg/jpg/png/gif");
}
- } else {
- LoggerE("extension: %s is not valid (jpeg/jpg/png/gif is supported)", ext.c_str());
- throw common::InvalidValuesException("getThumbnail support only jpeg/jpg/png/gif");
- }
- ReportSuccess(result, response->get<picojson::object>());
- }
- catch (const common::PlatformException& e) {
- ReportError(e, response->get<picojson::object>());
- }
+ ReportSuccess(result, response->get<picojson::object>());
+ }
+ catch (const common::PlatformException &e) {
+ ReportError(e, response->get<picojson::object>());
+ }
};
auto get_response = [callback_id, this](const std::shared_ptr<JsonValue>& response)->void {
- picojson::object& obj = response->get<picojson::object>();
- obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
- LoggerD("callback is %s", response->serialize().c_str());
- PostMessage(response->serialize().c_str());
+ picojson::object& obj = response->get<picojson::object>();
+ obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
+ PostMessage(response->serialize().c_str());
};
common::TaskQueue::GetInstance().Queue<JsonValue>(
// limitations under the License.
//
-#include "get_exif_info.h"
+#include "exif/get_exif_info.h"
#include <math.h>
#include <memory>
#include "common/platform_exception.h"
#include "common/logger.h"
-#include "exif_util.h"
+#include "exif/exif_util.h"
namespace extension {
namespace exif {
return true;
}
-void GetExifInfo::ProcessEntry(ExifEntry* entry, ExifData* exif_data,
+void GetExifInfo::ProcessEntry(ExifEntry* entry,
+ ExifData* exif_data,
JsonObject* result_obj) {
char buf[2000];
exif_entry_get_value(entry, buf, sizeof(buf));
case EXIF_TAG_IMAGE_WIDTH: {
exif_entry_get_value(entry, buf, sizeof(buf));
LoggerD("Setting ExifInformation width to: [%s]", buf);
- pair = std::make_pair("width", picojson::value(std::string(buf)));
+ pair = std::make_pair("width", JsonValue(std::string(buf)));
result_obj->insert(pair);
break;
}
case EXIF_TAG_IMAGE_LENGTH: {
exif_entry_get_value(entry, buf, sizeof(buf));
LoggerD("Setting ExifInformation height to: [%s]", buf);
- pair = std::make_pair("height", picojson::value(std::string(buf)));
+ pair = std::make_pair("height", JsonValue(std::string(buf)));
result_obj->insert(pair);
break;
}
case EXIF_TAG_MAKE: {
exif_entry_get_value(entry, buf, sizeof(buf));
LoggerD("Setting ExifInformation maker to: [%s]", buf);
- pair = std::make_pair("deviceMaker", picojson::value(std::string(buf)));
+ pair = std::make_pair("deviceMaker", JsonValue(std::string(buf)));
result_obj->insert(pair);
break;
}
case EXIF_TAG_MODEL: {
exif_entry_get_value(entry, buf, sizeof(buf));
LoggerD("Setting ExifInformation model to: [%s]", buf);
- pair = std::make_pair("deviceModel", picojson::value(std::string(buf)));
+ pair = std::make_pair("deviceModel", JsonValue(std::string(buf)));
result_obj->insert(pair);
break;
}
static_cast<int>(time));
// convert time_t (number of seconds) to string
pair = std::make_pair("originalTimeSeconds",
- picojson::value(static_cast<double>(time)));
+ JsonValue(static_cast<double>(time)));
result_obj->insert(pair);
break;
}
const ExifByteOrder order = exif_data_get_byte_order(exif_data);
const ExifShort orient(exif_get_short(entry->data, order));
- std::string orientation = ExifUtil::orientationToString(
+ const std::string& orientation = ExifUtil::orientationToString(
static_cast<ImageOrientation>(orient));
- pair = std::make_pair("orientation", picojson::value(orientation));
+ pair = std::make_pair("orientation", JsonValue(orientation));
result_obj->insert(pair);
if (orient < EXIF_ORIENTATION_NORMAL || orient >= EXIF_ORIENTATION_NOT_VALID) {
if (fnumber.isValid()) {
LoggerD("Setting ExifInformation fnumber to: %f (%s)", fnumber.toDouble(),
fnumber.toString().c_str());
- pair = std::make_pair("fNumber", picojson::value(fnumber.toDouble()));
+ pair = std::make_pair("fNumber", JsonValue(fnumber.toDouble()));
result_obj->insert(pair);
} else {
LoggerW("Couldn't set ExifInformation - fnumber is not valid: %s",
const size_t size_per_member =
ExifUtil::getSizeOfExifFormatType(entry->format);
- JsonArray array = picojson::array();
+ JsonArray array = JsonArray();
for (unsigned long i = 0; i < entry->components; ++i) {
ExifShort iso_rating = exif_get_short(read_ptr, order);
- array.push_back(picojson::value(std::to_string(iso_rating)));
+ array.push_back(JsonValue(std::to_string(iso_rating)));
LoggerD("Appending ExifInformation speed ratings with: %d",
static_cast<int>(iso_rating));
read_ptr += size_per_member;
}
- pair = std::make_pair("isoSpeedRatings", picojson::value(array));
+ pair = std::make_pair("isoSpeedRatings", JsonValue(array));
result_obj->insert(pair);
} else {
LoggerE("iso speed ratings: format or components count is invalid!");
LoggerD("Setting ExifInformation exposure time to: %s (%s)",
exp_time.toString().c_str(),
exp_time.toExposureTimeString().c_str());
- pair = std::make_pair("exposureTime", picojson::value(exp_time.toDouble()));
+ pair = std::make_pair("exposureTime", JsonValue(exp_time.toDouble()));
result_obj->insert(pair);
} else {
LoggerD("Couldn't set ExifInformation - exposure time is not valid: %s",
exp_program, buf);
std::string exp_program_string =
ExifUtil::exposureProgramToString(static_cast<ExposureProgram>(exp_program));
- pair = std::make_pair("exposureProgram", picojson::value(exp_program_string));
+ pair = std::make_pair("exposureProgram", JsonValue(exp_program_string));
result_obj->insert(pair);
}
break;
const ExifShort flash = exif_get_short(entry->data, order);
LoggerD("Setting ExifInformation flash to: [%s] flash=%d", buf, flash);
- pair = std::make_pair("flash", picojson::value((flash != 0) ? "true" : "false"));
+ pair = std::make_pair("flash", JsonValue((flash != 0) ? "true" : "false"));
result_obj->insert(pair);
break;
}
if (flength.isValid()) {
LoggerD("Setting ExifInformation focal length to: %f (%s)",
flength.toDouble(), flength.toString().c_str());
- pair = std::make_pair("focalLength", picojson::value(flength.toDouble()));
+ pair = std::make_pair("focalLength", JsonValue(flength.toDouble()));
result_obj->insert(pair);
} else {
LoggerW("Couldn't set ExifInformation - focal length is not valid: %s",
exif_entry_get_value(entry, buf, sizeof(buf));
LoggerD("Setting ExifInformation white balance to: [%s]", buf);
pair = std::make_pair("whiteBalanceValue",
- picojson::value(static_cast<double>(entry->data[0])));
+ JsonValue(static_cast<double>(entry->data[0])));
result_obj->insert(pair);
break;
}
// RATIONAL - 3
GCSPosition longitude;
if (GetGCSPositionFromEntry(entry, exif_data, longitude)) {
- pair = std::make_pair("gpsLongitudeDegrees", picojson::value(longitude.degrees.toDouble()));
+ pair = std::make_pair("gpsLongitudeDegrees", JsonValue(longitude.degrees.toDouble()));
result_obj->insert(pair);
- pair = std::make_pair("gpsLongitudeMinutes", picojson::value(longitude.minutes.toDouble()));
+ pair = std::make_pair("gpsLongitudeMinutes", JsonValue(longitude.minutes.toDouble()));
result_obj->insert(pair);
- pair = std::make_pair("gpsLongitudeSeconds", picojson::value(longitude.seconds.toDouble()));
+ pair = std::make_pair("gpsLongitudeSeconds", JsonValue(longitude.seconds.toDouble()));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps longitude to: %s; %s; %s valid:%d",
longitude.degrees.toString().c_str(),
const char ref = static_cast<char>(entry->data[0]);
if ('E' == ref || 'e' == ref) { // East
- pair = std::make_pair("gpsLongitudeRef", picojson::value("EAST"));
+ pair = std::make_pair("gpsLongitudeRef", JsonValue("EAST"));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps longitude REF to: EAST");
} else if ('W' == ref || 'w' == ref) { // West
- pair = std::make_pair("gpsLongitudeRef", picojson::value("WEST"));
+ pair = std::make_pair("gpsLongitudeRef", JsonValue("WEST"));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps longitude REF to: WEST");
} else {
GCSPosition latitude;
if (GetGCSPositionFromEntry(entry, exif_data, latitude)) {
- pair = std::make_pair("gpsLatitudeDegrees", picojson::value(latitude.degrees.toDouble()));
+ pair = std::make_pair("gpsLatitudeDegrees", JsonValue(latitude.degrees.toDouble()));
result_obj->insert(pair);
- pair = std::make_pair("gpsLatitudeMinutes", picojson::value(latitude.minutes.toDouble()));
+ pair = std::make_pair("gpsLatitudeMinutes", JsonValue(latitude.minutes.toDouble()));
result_obj->insert(pair);
- pair = std::make_pair("gpsLatitudeSeconds", picojson::value(latitude.seconds.toDouble()));
+ pair = std::make_pair("gpsLatitudeSeconds", JsonValue(latitude.seconds.toDouble()));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps latitude to: %s; %s; %s valid:%d",
const char ref = static_cast<char>(entry->data[0]);
if ('N' == ref || 'n' == ref) { // North
- pair = std::make_pair("gpsLatitudeRef", picojson::value("NORTH"));
+ pair = std::make_pair("gpsLatitudeRef", JsonValue("NORTH"));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps latitude REF to: NORTH");
} else if ('S' == ref || 's' == ref) { // South
- pair = std::make_pair("gpsLatitudeRef", picojson::value("SOUTH"));
+ pair = std::make_pair("gpsLatitudeRef", JsonValue("SOUTH"));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps latitude REF to: SOUTH");
} else {
if (gps_altitude.isValid()) {
LoggerD("Setting ExifInformation gps altitude to: %f (%s)",
gps_altitude.toDouble(), gps_altitude.toString().c_str());
- pair = std::make_pair("gpsAltitude", picojson::value(gps_altitude.toDouble()));
+ pair = std::make_pair("gpsAltitude", JsonValue(gps_altitude.toDouble()));
result_obj->insert(pair);
} else {
LoggerW("Couldn't set ExifInformation - gps altitude is not valid: %s",
case EXIF_TAG_GPS_ALTITUDE_REF: {
// BYTE - 1
const ExifByte altitude_ref = static_cast<ExifByte>(entry->data[0]);
- pair = std::make_pair("gpsAltitudeRef", picojson::value(static_cast<double>(altitude_ref)));
+ pair = std::make_pair("gpsAltitudeRef", JsonValue(static_cast<double>(altitude_ref)));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps altitude ref to: %d (%s)",
static_cast<int>(altitude_ref),
if (DecomposeExifUndefined(entry, type, value)) {
LoggerD("Extracted GPSProcessingMethod: [%s], len:%d, type:%s",
value.c_str(), value.length(), type.c_str());
- pair = std::make_pair("gpsProcessingMethod", picojson::value(value));
+ pair = std::make_pair("gpsProcessingMethod", JsonValue(value));
result_obj->insert(pair);
} else {
LoggerW("GPSProcessingMethod tag contains invalid values!");
}
case EXIF_TAG_GPS_DATE_STAMP: {
// ASCII - 11
- pair = std::make_pair("gpsExifDate", picojson::value(std::string(buf)));
+ pair = std::make_pair("gpsExifDate", JsonValue(std::string(buf)));
result_obj->insert(pair);
LoggerD("Setting ExifInformation gps date stamp to %s", std::string(buf).c_str());
break;
Rationals time;
if (GetRationalsFromEntry(entry, exif_data, 3, time)) {
- pair = std::make_pair("gpsExifTimeHours", picojson::value(time[0].toDouble()));
+ pair = std::make_pair("gpsExifTimeHours", JsonValue(time[0].toDouble()));
result_obj->insert(pair);
- pair = std::make_pair("gpsExifTimeMinutes", picojson::value(time[1].toDouble()));
+ pair = std::make_pair("gpsExifTimeMinutes", JsonValue(time[1].toDouble()));
result_obj->insert(pair);
- pair = std::make_pair("gpsExifTimeSeconds", picojson::value(time[2].toDouble()));
+ pair = std::make_pair("gpsExifTimeSeconds", JsonValue(time[2].toDouble()));
result_obj->insert(pair);
}
break;
LoggerD("Extracted UserComment: [%s], len:%d, type:%s",
value.c_str(), value.length(), type.c_str());
- pair = std::make_pair("userComment", picojson::value(value));
+ pair = std::make_pair("userComment", JsonValue(value));
result_obj->insert(pair);
} else {
LoggerW("UserComment tag contains invalid values!");
}
JsonValue GetExifInfo::LoadFromURI(const std::string& uri) {
- const std::string file_path = ExifUtil::convertUriToPath(uri);
+ const std::string& file_path = ExifUtil::convertUriToPath(uri);
ExifData* ed = exif_data_new_from_file(file_path.c_str());
if (!ed) {
LoggerE("Error reading exif from file %s", file_path.c_str());
ed = NULL;
// uri is not taken from jgp Exif, so we add it here
- holder.result_obj_ptr->insert(std::make_pair("uri", picojson::value(uri)));
+ holder.result_obj_ptr->insert(std::make_pair("uri", JsonValue(uri)));
return result;
}