Skip to content

Commit

Permalink
Pictures: Move to exiv2 for image metadata retrieval (exif and iptc)
Browse files Browse the repository at this point in the history
  • Loading branch information
enen92 committed Jun 22, 2024
1 parent c7284f5 commit 197a3e6
Show file tree
Hide file tree
Showing 18 changed files with 996 additions and 1,327 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ set(required_deps ASS>=0.15.0
Cdio
CrossGUID
Curl
Exiv2
FFMPEG
FlatBuffers
Fmt
Expand Down
1 change: 1 addition & 0 deletions tools/depends/target/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DEPENDS = \
brotli \
bzip2 \
dav1d \
exiv2 \
expat \
ffmpeg \
fontconfig \
Expand Down
56 changes: 28 additions & 28 deletions xbmc/addons/ImageDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,63 +113,63 @@ bool CImageDecoder::LoadInfoTag(const std::string& fileName, CPictureInfoTag* ta
* @todo Rework @ref CPictureInfoTag to not limit on fixed structures ExifInfo & IPTCInfo.
*/

tag->m_exifInfo.Width = ifcTag.width;
tag->m_exifInfo.Height = ifcTag.height;
tag->m_exifInfo.Distance = ifcTag.distance;
tag->m_exifInfo.Orientation = ifcTag.orientation;
tag->m_exifInfo.IsColor = ifcTag.color == ADDON_IMG_COLOR_COLORED ? 1 : 0;
tag->m_exifInfo.ApertureFNumber = ifcTag.aperture_f_number;
tag->m_exifInfo.FlashUsed = ifcTag.flash_used ? 1 : 0;
tag->m_exifInfo.LightSource = ifcTag.light_source;
tag->m_exifInfo.FocalLength = ifcTag.focal_length;
tag->m_exifInfo.FocalLength35mmEquiv = ifcTag.focal_length_in_35mm_format;
tag->m_exifInfo.MeteringMode = ifcTag.metering_mode;
tag->m_exifInfo.DigitalZoomRatio = ifcTag.digital_zoom_ratio;
tag->m_exifInfo.ExposureTime = ifcTag.exposure_time;
tag->m_exifInfo.ExposureBias = ifcTag.exposure_bias;
tag->m_exifInfo.ExposureProgram = ifcTag.exposure_program;
tag->m_exifInfo.ExposureMode = ifcTag.exposure_mode;
tag->m_exifInfo.ISOequivalent = static_cast<int>(ifcTag.iso_speed);
tag->m_imageMetadata.exifInfo.Width = ifcTag.width;
tag->m_imageMetadata.exifInfo.Height = ifcTag.height;
tag->m_imageMetadata.exifInfo.Distance = ifcTag.distance;
tag->m_imageMetadata.exifInfo.Orientation = ifcTag.orientation;
tag->m_imageMetadata.exifInfo.IsColor = ifcTag.color == ADDON_IMG_COLOR_COLORED ? 1 : 0;
tag->m_imageMetadata.exifInfo.ApertureFNumber = ifcTag.aperture_f_number;
tag->m_imageMetadata.exifInfo.FlashUsed = ifcTag.flash_used ? 1 : 0;
tag->m_imageMetadata.exifInfo.LightSource = ifcTag.light_source;
tag->m_imageMetadata.exifInfo.FocalLength = ifcTag.focal_length;
tag->m_imageMetadata.exifInfo.FocalLength35mmEquiv = ifcTag.focal_length_in_35mm_format;
tag->m_imageMetadata.exifInfo.MeteringMode = ifcTag.metering_mode;
tag->m_imageMetadata.exifInfo.DigitalZoomRatio = ifcTag.digital_zoom_ratio;
tag->m_imageMetadata.exifInfo.ExposureTime = ifcTag.exposure_time;
tag->m_imageMetadata.exifInfo.ExposureBias = ifcTag.exposure_bias;
tag->m_imageMetadata.exifInfo.ExposureProgram = ifcTag.exposure_program;
tag->m_imageMetadata.exifInfo.ExposureMode = ifcTag.exposure_mode;
tag->m_imageMetadata.exifInfo.ISOequivalent = static_cast<int>(ifcTag.iso_speed);
CDateTime dt;
dt.SetFromUTCDateTime(ifcTag.time_created);
tag->m_iptcInfo.TimeCreated = dt.GetAsLocalizedDateTime();
tag->m_dateTimeTaken = dt;
tag->m_exifInfo.GpsInfoPresent = ifcTag.gps_info_present;
if (tag->m_exifInfo.GpsInfoPresent)
tag->m_imageMetadata.iptcInfo.TimeCreated = dt.GetAsLocalizedDateTime();
tag->m_imageMetadata.exifInfo.GpsInfoPresent = ifcTag.gps_info_present;
if (tag->m_imageMetadata.exifInfo.GpsInfoPresent)
{
tag->m_exifInfo.GpsLat =
tag->m_imageMetadata.exifInfo.GpsLat =
StringUtils::Format("{}{:.0f}°{:.0f}'{:.2f}\"", ifcTag.latitude_ref, ifcTag.latitude[0],
ifcTag.latitude[1], ifcTag.latitude[2]);
tag->m_exifInfo.GpsLong =
tag->m_imageMetadata.exifInfo.GpsLong =
StringUtils::Format("{}{:.0f}°{:.0f}'{:.2f}\"", ifcTag.longitude_ref, ifcTag.longitude[0],
ifcTag.longitude[1], ifcTag.longitude[2]);
tag->m_exifInfo.GpsAlt =
tag->m_imageMetadata.exifInfo.GpsAlt =
StringUtils::Format("{}{:.2f} m", ifcTag.altitude_ref ? '-' : '+', ifcTag.altitude);
}

if (ifcTag.camera_manufacturer)
{
tag->m_exifInfo.CameraMake = ifcTag.camera_manufacturer;
tag->m_imageMetadata.exifInfo.CameraMake = ifcTag.camera_manufacturer;
free(ifcTag.camera_manufacturer);
}
if (ifcTag.camera_model)
{
tag->m_exifInfo.CameraModel = ifcTag.camera_model;
tag->m_imageMetadata.exifInfo.CameraModel = ifcTag.camera_model;
free(ifcTag.camera_model);
}
if (ifcTag.author)
{
tag->m_iptcInfo.Author = ifcTag.author;
tag->m_imageMetadata.iptcInfo.Author = ifcTag.author;
free(ifcTag.author);
}
if (ifcTag.description)
{
tag->m_exifInfo.Description = ifcTag.description;
tag->m_imageMetadata.exifInfo.Description = ifcTag.description;
free(ifcTag.description);
}
if (ifcTag.copyright)
{
tag->m_iptcInfo.CopyrightNotice = ifcTag.copyright;
tag->m_imageMetadata.iptcInfo.CopyrightNotice = ifcTag.copyright;
free(ifcTag.copyright);
}
}
Expand Down
11 changes: 6 additions & 5 deletions xbmc/pictures/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
set(SOURCES ExifParse.cpp
GUIDialogPictureInfo.cpp
set(SOURCES GUIDialogPictureInfo.cpp
GUIViewStatePictures.cpp
GUIWindowPictures.cpp
GUIWindowSlideShow.cpp
IptcParse.cpp
JpegParse.cpp
libexif.cpp
ImageMetadataParser.cpp
Picture.cpp
PictureFolderImageFileLoader.cpp
PictureInfoLoader.cpp
Expand All @@ -16,10 +13,14 @@ set(SOURCES ExifParse.cpp
SlideShowPicture.cpp)

set(HEADERS interfaces/ISlideShowDelegate.h
Exif.h
GUIDialogPictureInfo.h
GUIViewStatePictures.h
GUIWindowPictures.h
GUIWindowSlideShow.h
ImageMetadata.h
ImageMetadataParser.h
Iptc.h
Picture.h
PictureFolderImageFileLoader.h
PictureInfoLoader.h
Expand Down
72 changes: 72 additions & 0 deletions xbmc/pictures/Exif.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (C) 2023 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

#include <string>
#include <vector>

constexpr unsigned int MAX_DATE_COPIES = 10;
constexpr int EXIF_COMMENT_CHARSET_CONVERTED = -1;

struct ExifInfo
{
ExifInfo() = default;
ExifInfo(const ExifInfo&) = default;
ExifInfo(ExifInfo&&) = default;

ExifInfo& operator=(const ExifInfo&) = default;
ExifInfo& operator=(ExifInfo&&) = default;

std::string CameraMake;
std::string CameraModel;
std::string DateTime;
int Height{};
int Width{};
int Orientation{};
int IsColor{};
std::string Process{};
int FlashUsed{};
float FocalLength{};
float ExposureTime{};
float ApertureFNumber{};
float Distance{};
float CCDWidth{};
float ExposureBias{};
float DigitalZoomRatio{};
int FocalLength35mmEquiv{};
int Whitebalance{};
int MeteringMode{};
int ExposureProgram{};
int ExposureMode{};
int ISOequivalent{};
int LightSource{};
//! TODO: Remove me, not needed anymore (still exposed to addon interface)
int CommentsCharset{};
//! TODO: Remove me, not needed anymore (still exposed to addon interface)
int XPCommentsCharset{};
std::string Comments;
std::string FileComment;
std::string XPComment;
std::string Description;

//! TODO: this is not used anywhere, just nuke it
unsigned ThumbnailOffset{};
unsigned ThumbnailSize{};
unsigned LargestExifOffset{};
//! TODO: this is not used anywhere, just nuke it
char ThumbnailAtEnd{};
int ThumbnailSizeOffset{};
//! TODO: this is not used anywhere, just nuke it
std::vector<int> DateTimeOffsets;

int GpsInfoPresent{};
std::string GpsLat;
std::string GpsLong;
std::string GpsAlt;
};
37 changes: 0 additions & 37 deletions xbmc/pictures/ExifParse.h

This file was deleted.

18 changes: 18 additions & 0 deletions xbmc/pictures/ImageMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (C) 2023 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/

#pragma once

#include "Exif.h"
#include "Iptc.h"

struct ImageMetadata
{
ExifInfo exifInfo;
IPTCInfo iptcInfo;
};
Loading

0 comments on commit 197a3e6

Please sign in to comment.