Skip to content

Commit

Permalink
use DebugLog in exif
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 committed Nov 2, 2024
1 parent 5ad771c commit c489fe8
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
86 changes: 43 additions & 43 deletions exif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ ExifFormat::print_buff(const char* buf, int sz, const char* cmt)
{
int i;

printf("%s: ", cmt);
db.log("%s: ", cmt);
for (i = 0; i < sz; i++) {
printf("%02x ", buf[i] & 0xFF);
db.log("%02x ", buf[i] & 0xFF);
}
for (i = 0; i < sz; i++) {
char c = buf[i];
Expand All @@ -147,7 +147,7 @@ ExifFormat::print_buff(const char* buf, int sz, const char* cmt)
} else if (! isprint(c)) {
c = '.';
}
printf("%c", c);
db.log("%c", c);
}
}

Expand Down Expand Up @@ -320,12 +320,12 @@ ExifFormat::exif_load_apps()
app->marker = gbfgetuint16(fin_);
app->len = gbfgetuint16(fin_);
if (global_opts.debug_level >= 3) {
printf("api = %02X, len = %u (0x%04x), offs = 0x%08X\n", app->marker & 0xFF, app->len, app->len, gbftell(fin_));
db.log("api = %02X, len = %u (0x%04x), offs = 0x%08X\n", app->marker & 0xFF, app->len, app->len, gbftell(fin_));
}
if (exif_app_ || (app->marker == 0xFFDA)) { /* compressed data */
gbfcopyfrom(app->fcache, fin_, 0x7FFFFFFF);
if (global_opts.debug_level >= 3) {
printf("compressed data size = %u\n", gbftell(app->fcache));
db.log("compressed data size = %u\n", gbftell(app->fcache));
}
} else {
gbfcopyfrom(app->fcache, fin_, app->len - 2);
Expand Down Expand Up @@ -401,7 +401,7 @@ ExifFormat::exif_read_ifd(ExifApp* app, const uint16_t ifd_nr, const gbsize_t of
name = "private";
break;
}
printf("offs 0x%08X: Number of items in IFD%d \"%s\" = %d (0x%04x)\n",
db.log("offs 0x%08X: Number of items in IFD%d \"%s\" = %d (0x%04x)\n",
offs, ifd_nr, name, ifd->count, ifd->count);
}
if (ifd->count == 0) {
Expand Down Expand Up @@ -520,57 +520,57 @@ ExifFormat::exif_read_ifd(ExifApp* app, const uint16_t ifd_nr, const gbsize_t of
}
}
if (global_opts.debug_level >= 3) {
printf("offs 0x%08X: ifd=%d id=0x%04X t=0x%04X c=%4u s=%4u",
db.log("offs 0x%08X: ifd=%d id=0x%04X t=0x%04X c=%4u s=%4u",
tag->tag_offset, ifd->nr, tag->id, tag->type, tag->count, tag->size);
if (tag->size > 4) {
printf(" o=0x%08X", tag->offset);
db.log(" o=0x%08X", tag->offset);
} else {
printf(" v=0x%02X%02X%02X%02X", tag->raw[0], tag->raw[1], tag->raw[2], tag->raw[3]);
db.log(" v=0x%02X%02X%02X%02X", tag->raw[0], tag->raw[1], tag->raw[2], tag->raw[3]);
}
if (tag->type == EXIF_TYPE_ASCII) {
QByteArray str = exif_read_str(tag);
printf(" \"%s\"", str.constData());
db.log(" \"%s\"", str.constData());
} else {
for (unsigned idx = 0; idx < std::min(tag->count, 4u); ++idx) {
if (tag->type == EXIF_TYPE_BYTE) {
printf(" %u", tag->data.at(0).toByteArray().at(idx));
db.log(" %u", tag->data.at(0).toByteArray().at(idx));
} else if (tag->type == EXIF_TYPE_SBYTE) {
printf(" %d", tag->data.at(0).toByteArray().at(idx));
db.log(" %d", tag->data.at(0).toByteArray().at(idx));
} else if (tag->type == EXIF_TYPE_UNK) {
printf(" 0x%02X", tag->data.at(0).toByteArray().at(idx));
db.log(" 0x%02X", tag->data.at(0).toByteArray().at(idx));
} else if (tag->type == EXIF_TYPE_RAT) {
printf(" %+#g(%u/%u)", exif_read_double(tag, idx), tag->data.at(idx * 2).value<uint32_t>(), tag->data.at((idx * 2) + 1).value<uint32_t>());
db.log(" %+#g(%u/%u)", exif_read_double(tag, idx), tag->data.at(idx * 2).value<uint32_t>(), tag->data.at((idx * 2) + 1).value<uint32_t>());
} else if (tag->type == EXIF_TYPE_SRAT) {
printf(" %+#g(%d/%d)", exif_read_double(tag, idx), tag->data.at(idx * 2).value<int32_t>(), tag->data.at((idx * 2) + 1).value<int32_t>());
db.log(" %+#g(%d/%d)", exif_read_double(tag, idx), tag->data.at(idx * 2).value<int32_t>(), tag->data.at((idx * 2) + 1).value<int32_t>());
} else if (tag->type == EXIF_TYPE_SHORT) {
printf(" %u", tag->data.at(idx).value<uint16_t>());
db.log(" %u", tag->data.at(idx).value<uint16_t>());
} else if (tag->type == EXIF_TYPE_SSHORT) {
printf(" %d", tag->data.at(idx).value<int16_t>());
db.log(" %d", tag->data.at(idx).value<int16_t>());
} else if (tag->type == EXIF_TYPE_LONG) {
printf(" %u", tag->data.at(idx).value<uint32_t>());
db.log(" %u", tag->data.at(idx).value<uint32_t>());
} else if (tag->type == EXIF_TYPE_SLONG) {
printf(" %d", tag->data.at(idx).value<int32_t>());
db.log(" %d", tag->data.at(idx).value<int32_t>());
} else if (tag->type == EXIF_TYPE_FLOAT) {
printf(" %+#g", tag->data.at(idx).value<float>());
db.log(" %+#g", tag->data.at(idx).value<float>());
} else if (tag->type == EXIF_TYPE_DOUBLE) {
printf(" %+#g", tag->data.at(idx).value<double>());
db.log(" %+#g", tag->data.at(idx).value<double>());
} else {
printf(" 0x%0*X", 2 * exif_type_size(tag->type), tag->data.at(idx).value<uint32_t>());
db.log(" 0x%0*X", 2 * exif_type_size(tag->type), tag->data.at(idx).value<uint32_t>());
}
}
if (tag->count > 4) {
printf(" ...");
db.log(" ...");
}
}
printf("\n");
db.log("\n");
}
#ifndef NDEBUG
exif_validate_tag_structure(tag);
#endif
}

if (global_opts.debug_level >= 3) {
printf("offs 0x%08X: Next IFD=0x%08X\n", next_ifd_offs, ifd->next_ifd);
db.log("offs 0x%08X: Next IFD=0x%08X\n", next_ifd_offs, ifd->next_ifd);
}

return ifd;
Expand All @@ -587,9 +587,9 @@ ExifFormat::exif_read_app(ExifApp* app)
gbfile* fin = app->fexif;

if (global_opts.debug_level >= 3) {
printf("read_app...\n");
db.log("read_app...\n");
print_buff((const char*)fin->handle.mem, 8, "offs 0x00000000: Image File Header");
printf("\n");
db.log("\n");
}
exif_ifd_ofs = gps_ifd_ofs = inter_ifd_ofs = 0;

Expand Down Expand Up @@ -633,7 +633,7 @@ ExifFormat::exif_examine_app(ExifApp* app)
uint16_t endianness = gbfgetint16(ftmp);

if (global_opts.debug_level >= 3) {
printf("endianness = 0x%04X\n", endianness);
db.log("endianness = 0x%04X\n", endianness);
}
if (endianness == 0x4949) {
ftmp->big_endian = 0;
Expand Down Expand Up @@ -680,7 +680,7 @@ ExifFormat::exif_find_tag(ExifApp* app, const uint16_t ifd_nr, const uint16_t ta
}

QDateTime
ExifFormat::exif_get_exif_time(ExifApp* app) const
ExifFormat::exif_get_exif_time(ExifApp* app)
{
QDateTime res;

Expand Down Expand Up @@ -755,7 +755,7 @@ ExifFormat::exif_get_exif_time(ExifApp* app) const
}

Waypoint*
ExifFormat::exif_waypt_from_exif_app(ExifApp* app) const
ExifFormat::exif_waypt_from_exif_app(ExifApp* app)
{
ExifTag* tag;
char lat_ref = '\0';
Expand Down Expand Up @@ -848,8 +848,8 @@ ExifFormat::exif_waypt_from_exif_app(ExifApp* app) const
}

if (global_opts.debug_level >= 3) {
printf("GPSLatitude = %12.7f\n", wpt->latitude);
printf("GPSLongitude = %12.7f\n", wpt->longitude);
db.log("GPSLatitude = %12.7f\n", wpt->latitude);
db.log("GPSLongitude = %12.7f\n", wpt->longitude);
}
if (!datum.isEmpty()) {
int idatum = gt_lookup_datum_index(datum);
Expand Down Expand Up @@ -879,7 +879,7 @@ ExifFormat::exif_waypt_from_exif_app(ExifApp* app) const
}
wpt->altitude = sign * alt;
if (global_opts.debug_level >= 3) {
printf("GPSAltitude = %12.7f m\n", wpt->altitude);
db.log("GPSAltitude = %12.7f m\n", wpt->altitude);
}
}

Expand All @@ -900,7 +900,7 @@ ExifFormat::exif_waypt_from_exif_app(ExifApp* app) const
}
if (global_opts.debug_level >= 3) {
if (wpt->speed_has_value()) {
printf("GPSSpeed = %12.2f m/s\n", wpt->speed_value());
db.log("GPSSpeed = %12.2f m/s\n", wpt->speed_value());
}
}
}
Expand All @@ -920,7 +920,7 @@ ExifFormat::exif_waypt_from_exif_app(ExifApp* app) const
gps_datetime = QDateTime(datestamp, timestamp, QtUTC);
if (gps_datetime.isValid()) {
if (global_opts.debug_level >= 3) {
printf("GPSTimeStamp = %s\n", qPrintable(gps_datetime.toString(Qt::ISODateWithMs)));
db.log("GPSTimeStamp = %s\n", qPrintable(gps_datetime.toString(Qt::ISODateWithMs)));
}
wpt->SetCreationTime(gps_datetime);
} else {
Expand Down Expand Up @@ -1005,7 +1005,7 @@ ExifFormat::Rational<int32_t> ExifFormat::exif_dec2frac(double val, double toler
}

ExifFormat::ExifTag*
ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16_t type, const int count, const int index, const void* data) const
ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16_t type, const int count, const int index, const void* data)
{
ExifTag* tag = nullptr;
uint16_t size;
Expand Down Expand Up @@ -1108,7 +1108,7 @@ ExifFormat::exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16


void
ExifFormat::exif_put_double(const int ifd_nr, const int tag_id, const int index, const double val) const
ExifFormat::exif_put_double(const int ifd_nr, const int tag_id, const int index, const double val)
{
// TODO: It seems wrong to throw away the sign.
double d = fabs(val);
Expand All @@ -1117,14 +1117,14 @@ ExifFormat::exif_put_double(const int ifd_nr, const int tag_id, const int index,


void
ExifFormat::exif_put_str(const int ifd_nr, const int tag_id, const char* val) const
ExifFormat::exif_put_str(const int ifd_nr, const int tag_id, const char* val)
{
int len = (val) ? strlen(val) + 1 : 0;
exif_put_value(ifd_nr, tag_id, EXIF_TYPE_ASCII, len, 0, val);
}

void
ExifFormat::exif_put_coord(const int ifd_nr, const int tag_id, const double val) const
ExifFormat::exif_put_coord(const int ifd_nr, const int tag_id, const double val)
{
double vdeg;
double vmin;
Expand All @@ -1140,19 +1140,19 @@ ExifFormat::exif_put_coord(const int ifd_nr, const int tag_id, const double val)
}

void
ExifFormat::exif_put_long(const int ifd_nr, const int tag_id, const int index, const int32_t val) const
ExifFormat::exif_put_long(const int ifd_nr, const int tag_id, const int index, const int32_t val)
{
exif_put_value(ifd_nr, tag_id, EXIF_TYPE_LONG, 1, index, &val);
}

void
ExifFormat::exif_put_short(const int ifd_nr, const int tag_id, const int index, const int16_t val) const
ExifFormat::exif_put_short(const int ifd_nr, const int tag_id, const int index, const int16_t val)
{
exif_put_value(ifd_nr, tag_id, EXIF_TYPE_SHORT, 1, index, &val);
}

void
ExifFormat::exif_remove_tag(const int ifd_nr, const int tag_id) const
ExifFormat::exif_remove_tag(const int ifd_nr, const int tag_id)
{
exif_put_value(ifd_nr, tag_id, EXIF_TYPE_BYTE, 0, 0, nullptr);
}
Expand Down Expand Up @@ -1307,7 +1307,7 @@ ExifFormat::exif_write_ifd(ExifIfd* ifd, const char next, gbfile* fout)
}

void
ExifFormat::exif_write_apps() const
ExifFormat::exif_write_apps()
{
gbfputuint16(0xFFD8, fout_);

Expand Down
39 changes: 20 additions & 19 deletions exif.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,45 +155,46 @@ class ExifFormat : public Format

/* Member Functions */

static void print_buff(const char* buf, int sz, const char* cmt);
void print_buff(const char* buf, int sz, const char* cmt);
static uint16_t exif_type_size(uint16_t type);
static QString exif_time_str(const QDateTime& time);
static QByteArray exif_read_str(ExifTag* tag);
static double exif_read_double(const ExifTag* tag, int index);
static double exif_read_coord(const ExifTag* tag);
static QTime exif_read_timestamp(const ExifTag* tag);
double exif_read_coord(const ExifTag* tag);
QTime exif_read_timestamp(const ExifTag* tag);
static QDate exif_read_datestamp(const ExifTag* tag);
void exif_release_apps();
static uint32_t exif_ifd_size(ExifIfd* ifd);
ExifApp* exif_load_apps();
#ifndef NDEBUG
static void exif_validate_tag_structure(const ExifTag* tag);
void exif_validate_tag_structure(const ExifTag* tag);
#endif
static ExifIfd* exif_read_ifd(ExifApp* app, uint16_t ifd_nr, gbsize_t offs, uint32_t* exif_ifd_ofs, uint32_t* gps_ifd_ofs, uint32_t* inter_ifd_ofs);
static void exif_read_app(ExifApp* app);
static void exif_examine_app(ExifApp* app);
ExifIfd* exif_read_ifd(ExifApp* app, uint16_t ifd_nr, gbsize_t offs, uint32_t* exif_ifd_ofs, uint32_t* gps_ifd_ofs, uint32_t* inter_ifd_ofs);
void exif_read_app(ExifApp* app);
void exif_examine_app(ExifApp* app);
static ExifIfd* exif_find_ifd(ExifApp* app, uint16_t ifd_nr);
static ExifTag* exif_find_tag(ExifApp* app, uint16_t ifd_nr, uint16_t tag_id);
QDateTime exif_get_exif_time(ExifApp* app) const;
Waypoint* exif_waypt_from_exif_app(ExifApp* app) const;
ExifTag* exif_find_tag(ExifApp* app, uint16_t ifd_nr, uint16_t tag_id);
QDateTime exif_get_exif_time(ExifApp* app);
Waypoint* exif_waypt_from_exif_app(ExifApp* app);
static Rational<int> exif_dec2frac(double val, double tolerance);
ExifTag* exif_put_value(int ifd_nr, uint16_t tag_id, uint16_t type, int count, int index, const void* data) const;
void exif_put_double(int ifd_nr, int tag_id, int index, double val) const;
void exif_put_str(int ifd_nr, int tag_id, const char* val) const;
void exif_put_coord(int ifd_nr, int tag_id, double val) const;
void exif_put_long(int ifd_nr, int tag_id, int index, int32_t val) const;
void exif_put_short(int ifd_nr, int tag_id, int index, int16_t val) const;
void exif_remove_tag(int ifd_nr, int tag_id) const;
ExifTag* exif_put_value(int ifd_nr, uint16_t tag_id, uint16_t type, int count, int index, const void* data);
void exif_put_double(int ifd_nr, int tag_id, int index, double val);
void exif_put_str(int ifd_nr, int tag_id, const char* val);
void exif_put_coord(int ifd_nr, int tag_id, double val);
void exif_put_long(int ifd_nr, int tag_id, int index, int32_t val);
void exif_put_short(int ifd_nr, int tag_id, int index, int16_t val);
void exif_remove_tag(int ifd_nr, int tag_id);
void exif_find_wpt_by_time(const Waypoint* wpt);
void exif_find_wpt_by_name(const Waypoint* wpt);
static bool exif_sort_tags_cb(const ExifTag& A, const ExifTag& B);
static bool exif_sort_ifds_cb(const ExifIfd& A, const ExifIfd& B);
static void exif_write_value(ExifTag* tag, gbfile* fout);
static void exif_write_ifd(ExifIfd* ifd, char next, gbfile* fout);
void exif_write_apps() const;
void exif_write_ifd(ExifIfd* ifd, char next, gbfile* fout);
void exif_write_apps();

/* Data Members */

DebugLog db;
gbfile* fin_{};
gbfile* fout_{};
QList<ExifApp*>* exif_apps{};
Expand Down

0 comments on commit c489fe8

Please sign in to comment.