Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake added and some support for color profile identification. #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ demo
*.exe
*.out
*.app

# Idea
.idea/**

# build dirs
cmake-build-*/**
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.7)
project(easyexif)

if(VERBOSE)
add_definitions(-DDEBUG_COUT)
endif()

set(CMAKE_CXX_STANDARD 14)

add_executable(demo demo.cpp exif.cpp exif.h)
2 changes: 2 additions & 0 deletions demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ int main(int argc, char *argv[]) {
}

// Dump EXIF information
printf("InteropIndex : %s\n", result.InteropIndex.c_str());
printf("Camera make : %s\n", result.Make.c_str());
printf("Camera model : %s\n", result.Model.c_str());
printf("Software : %s\n", result.Software.c_str());
printf("Bits per sample : %d\n", result.BitsPerSample);
printf("Color Space : %d\n", result.ColorSpace);
printf("Image width : %d\n", result.ImageWidth);
printf("Image height : %d\n", result.ImageHeight);
printf("Image description : %s\n", result.ImageDescription.c_str());
Expand Down
45 changes: 43 additions & 2 deletions exif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
offs += 2;
unsigned exif_sub_ifd_offset = len;
unsigned gps_sub_ifd_offset = len;
unsigned interop_ifd_offset = len;
while (--num_entries >= 0) {
IFEntry result =
parseIFEntry(buf, offs, alignIntel, tiff_header_start, len);
Expand Down Expand Up @@ -577,6 +578,11 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
// EXIF SubIFD offset
exif_sub_ifd_offset = tiff_header_start + result.data();
break;
default:
#ifdef DEBUG_COUT
std::cout << "Unknown tag: " << result.tag() << std::endl;
#endif
break;
}
}

Expand Down Expand Up @@ -675,7 +681,13 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
if (result.format() == 2)
this->SubSecTimeOriginal = result.val_string();
break;

case 0xa001:
// Color Space info
if (result.format() == 3 && result.val_short().size()) {
uint16_t data = result.val_short().front();
this->ColorSpace = data;
}
break;
case 0xa002:
// EXIF Image width
if (result.format() == 4 && result.val_long().size())
Expand All @@ -691,7 +703,9 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
if (result.format() == 3 && result.val_short().size())
this->ImageHeight = result.val_short().front();
break;

case 0xa005:
interop_ifd_offset = tiff_header_start + result.data();
break;
case 0xa20e:
// EXIF Focal plane X-resolution
if (result.format() == 5) {
Expand Down Expand Up @@ -747,6 +761,31 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,
this->LensInfo.Model = result.val_string();
}
break;
default:
#ifdef DEBUG_COUT
std::cout << "Unknown tag: " << result.tag() << std::endl;
#endif
break;
}
offs += 12;
}
}

// Jump to the Interop SubIFD if it exists and parse all the information
// there. Note that it's possible that the Interop SubIFD doesn't exist.
if (interop_ifd_offset + 4 <= len) {
offs = interop_ifd_offset;
int num_entries = parse_value<uint16_t>(buf + offs, alignIntel);
if (offs + 6 + 12 * num_entries > len) return PARSE_EXIF_ERROR_CORRUPT;
offs += 2;
while (--num_entries >= 0) {
IFEntry result =
parseIFEntry(buf, offs, alignIntel, tiff_header_start, len);
switch(result.tag()) {
case 0x01:
// InteropIndex
if(result.format() == 2) this->InteropIndex = result.val_string();
break;
}
offs += 12;
}
Expand Down Expand Up @@ -859,6 +898,7 @@ int easyexif::EXIFInfo::parseFromEXIFSegment(const unsigned char *buf,

void easyexif::EXIFInfo::clear() {
// Strings
InteropIndex = "";
ImageDescription = "";
Make = "";
Model = "";
Expand Down Expand Up @@ -887,6 +927,7 @@ void easyexif::EXIFInfo::clear() {
FlashReturnedLight = 0;
FlashMode = 0;
MeteringMode = 0;
ColorSpace = 0;
ImageWidth = 0;
ImageHeight = 0;

Expand Down
5 changes: 5 additions & 0 deletions exif.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#define __EXIF_H

#include <string>
#ifdef DEBUG_COUT
#include <iostream>
#endif

namespace easyexif {

Expand Down Expand Up @@ -62,6 +65,7 @@ class EXIFInfo {

// Data fields filled out by parseFrom()
char ByteAlign; // 0 = Motorola byte alignment, 1 = Intel
std::string InteropIndex; // InteropIndex. Used to detect sRGB vs AdobeRGB
std::string ImageDescription; // Image description
std::string Make; // Camera manufacturer's name
std::string Model; // Camera model
Expand Down Expand Up @@ -114,6 +118,7 @@ class EXIFInfo {
// 3: spot
// 4: multi-spot
// 5: multi-segment
unsigned ColorSpace; // Color Spaced reported in EXIF data
unsigned ImageWidth; // Image width reported in EXIF data
unsigned ImageHeight; // Image height reported in EXIF data
struct Geolocation_t { // GPS information embedded in file
Expand Down
Binary file added test-images/AdobeRGB.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions test-images/AdobeRGB.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
InteropIndex : R03
Camera make : Canon
Camera model : Canon EOS 600D
Software :
Bits per sample : 0
Color Space : 65535
Image width : 5184
Image height : 3456
Image description :
Image orientation : 1
Image copyright :
Image date/time : 2019:03:13 17:44:36
Original date/time : 2019:03:13 17:44:36
Digitize date/time : 2019:03:13 17:44:36
Subsecond time : 26
Exposure time : 1/3 s
F-stop : f/13.0
Exposure program : 1
ISO speed : 400
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 0
Flash returned light : 0
Flash mode : 2
Metering mode : 3
Lens focal length : 50.000000 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 50.000000 mm
Lens max focal length: 50.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model : EF50mm f/1.8 STM
Focal plane XRes : 5728.176796
Focal plane YRes : 5808.403361
2 changes: 2 additions & 0 deletions test-images/bb-android.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : QCOM-AA
Camera model : QCAM-AA
Software : IMX230-S-21
Bits per sample : 0
Color Space : 1
Image width : 3672
Image height : 4896
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/down-mirrored.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make :
Camera model :
Software :
Bits per sample : 0
Color Space : 0
Image width : 0
Image height : 0
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/evil1.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : Canon
Camera model : Canon PowerShot S400
Software : Adobe Photoshop 7.0
Bits per sample : 0
Color Space : 1
Image width : 400
Image height : 300
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/lens_info.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make :
Camera model :
Software :
Bits per sample : 0
Color Space : 65535
Image width : 0
Image height : 0
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/lukas12p.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : OLYMPUS IMAGING CORP.
Camera model : E-510
Software : ACD Systems Digital Imaging
Bits per sample : 0
Color Space : 0
Image width : 912
Image height : 684
Image description : OLYMPUS DIGITAL CAMERA
Expand Down
2 changes: 2 additions & 0 deletions test-images/right.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make :
Camera model :
Software :
Bits per sample : 0
Color Space : 0
Image width : 0
Image height : 0
Image description :
Expand Down
Binary file added test-images/sRGB.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions test-images/sRGB.jpg.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
InteropIndex : R98
Camera make : Canon
Camera model : Canon EOS 600D
Software :
Bits per sample : 0
Color Space : 1
Image width : 5184
Image height : 3456
Image description :
Image orientation : 1
Image copyright :
Image date/time : 2019:03:13 17:44:29
Original date/time : 2019:03:13 17:44:29
Digitize date/time : 2019:03:13 17:44:29
Subsecond time : 02
Exposure time : 1/3 s
F-stop : f/13.0
Exposure program : 1
ISO speed : 400
Subject distance : 0.000000 m
Exposure bias : 0.000000 EV
Flash used? : 0
Flash returned light : 0
Flash mode : 2
Metering mode : 3
Lens focal length : 50.000000 mm
35mm focal length : 0 mm
GPS Latitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Longitude : 0.000000 deg (0.000000 deg, 0.000000 min, 0.000000 sec ?)
GPS Altitude : 0.000000 m
GPS Precision (DOP) : 0.000000
Lens min focal length: 50.000000 mm
Lens max focal length: 50.000000 mm
Lens f-stop min : f/0.0
Lens f-stop max : f/0.0
Lens make :
Lens model : EF50mm f/1.8 STM
Focal plane XRes : 5728.176796
Focal plane YRes : 5808.403361
2 changes: 2 additions & 0 deletions test-images/short-ascii-II.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : XIAOMI
Camera model : MI3
Software :
Bits per sample : 0
Color Space : 1
Image width : 4208
Image height : 3120
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/short-ascii-MM.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex : R98
Camera make : Canon
Camera model : S40
Software :
Bits per sample : 0
Color Space : 1
Image width : 2272
Image height : 1704
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/sony-alpha-6000.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex : R98
Camera make : SONY
Camera model : ILCE-6000
Software : ILCE-6000 v1.00
Bits per sample : 0
Color Space : 1
Image width : 6000
Image height : 4000
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/test1.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : Apple
Camera model : iPhone 4S
Software : 6.1
Bits per sample : 0
Color Space : 1
Image width : 3264
Image height : 2448
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/test2.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : Apple
Camera model : iPhone 4S
Software : 6.0.1
Bits per sample : 0
Color Space : 1
Image width : 1319
Image height : 1040
Image description :
Expand Down
2 changes: 2 additions & 0 deletions test-images/test3.jpg.expected
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
InteropIndex :
Camera make : Apple
Camera model : iPhone 4S
Software : 6.0.1
Bits per sample : 0
Color Space : 1
Image width : 3264
Image height : 2448
Image description :
Expand Down