Skip to content

Commit

Permalink
Move lcms dependent code from exif-common to color-man
Browse files Browse the repository at this point in the history
  • Loading branch information
qarkai authored and caclark committed Jan 29, 2025
1 parent b71b071 commit bc481e7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 31 deletions.
26 changes: 26 additions & 0 deletions src/color-man.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,26 @@ void color_man_update()
color_man_cache_reset();
}

const gchar *get_profile_name(const guchar *profile_data, guint profile_len)
{
cmsHPROFILE profile = cmsOpenProfileFromMem(profile_data, profile_len);
if (!profile) return nullptr;

#if HAVE_LCMS2
cmsUInt8Number profileID[17];
profileID[16] = '\0';

cmsGetHeaderProfileID(profile, profileID);
auto *name = reinterpret_cast<gchar *>(profileID);
#else
auto *name = (gchar *) cmsTakeProductName(profile);
#endif

cmsCloseProfile(profile);

return name;
}

#else /* define HAVE_LCMS */
/*** color support not enabled ***/

Expand Down Expand Up @@ -478,5 +498,11 @@ gboolean color_man_get_status(ColorMan *, gchar **, gchar **)
return FALSE;
}

const gchar *get_profile_name(const guchar *, guint)
{
/* no op */
return nullptr;
}

#endif /* define HAVE_LCMS */
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
2 changes: 2 additions & 0 deletions src/color-man.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,7 @@ void color_man_correct_region(ColorMan *cm, GdkPixbuf *pixbuf, gint x, gint y, g

gboolean color_man_get_status(ColorMan *cm, gchar **image_profile, gchar **screen_profile);

const gchar *get_profile_name(const guchar *profile_data, guint profile_len);

#endif
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
37 changes: 6 additions & 31 deletions src/exif-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,8 @@

#include <glib.h>

#if HAVE_LCMS
/*** color support enabled ***/
# if HAVE_LCMS2
# include <lcms2.h>
# else
# include <lcms.h>
# endif
#endif

#include "cache.h"
#include "color-man.h"
#include "exif.h"
/* Required to prevent clang-tidy warnings */
#include "exif-int.h"
Expand All @@ -58,6 +50,7 @@
#include "third-party/zonedetect.h"
#include "typedefs.h"
#include "ui-fileops.h"

struct ExifData;
struct ExifItem;
struct FileCacheData;
Expand Down Expand Up @@ -429,9 +422,6 @@ static gchar *exif_build_formatted_Resolution(ExifData *exif)

static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
{
#if HAVE_LCMS2
cmsUInt8Number profileID[17];
#endif
const gchar *name = "";
const gchar *source = "";
guint profile_len;
Expand Down Expand Up @@ -459,27 +449,12 @@ static gchar *exif_build_formatted_ColorProfile(ExifData *exif)
}
else
{
source = _("embedded");
#if HAVE_LCMS

{
cmsHPROFILE profile;
const gchar *profile_name = get_profile_name(profile_data, profile_len);
if (profile_name) name = profile_name;

profile = cmsOpenProfileFromMem(profile_data, profile_len);
if (profile)
{
#if HAVE_LCMS2
profileID[16] = '\0';
cmsGetHeaderProfileID(profile, profileID);
name = reinterpret_cast<gchar *>(profileID);
#else
name = (gchar *) cmsTakeProductName(profile);
#endif
cmsCloseProfile(profile);
}
}
#endif
source = _("embedded");
}

if (name[0] == 0 && source[0] == 0) return nullptr;
return g_strdup_printf("%s (%s)", name, source);
}
Expand Down

0 comments on commit bc481e7

Please sign in to comment.