Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
utility.h
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2010-2011 Henrik Andersson.
4 Copyright (C) 2010 johannes hanika.
5 Copyright (C) 2010-2011, 2013-2017 Tobias Ellinghaus.
6 Copyright (C) 2011 Moritz Lipp.
7 Copyright (C) 2012 Jérémy Rosen.
8 Copyright (C) 2012 Richard Wonka.
9 Copyright (C) 2013 Antony Dovgal.
10 Copyright (C) 2013, 2020 Pascal Obry.
11 Copyright (C) 2013 Simon Spannagel.
12 Copyright (C) 2015 Bruce Guenter.
13 Copyright (C) 2015-2016 Roman Lebedev.
14 Copyright (C) 2019, 2021 Philippe Weyland.
15 Copyright (C) 2020 Alexis Mousset.
16 Copyright (C) 2020 hatsunearu.
17 Copyright (C) 2020 Ralf Brown.
18 Copyright (C) 2021 Benjamin Grimm-Lebsanft.
19 Copyright (C) 2021 Hanno Schwalm.
20 Copyright (C) 2021 Marco Carrarini.
21 Copyright (C) 2021 RSL.
22 Copyright (C) 2022 Martin Bařinka.
23 Copyright (C) 2022 Nicolas Auffray.
24 Copyright (C) 2024 Aurélien PIERRE.
25 Copyright (C) 2024-2025 Guillaume Stutin.
26 Copyright (C) 2025 Alynx Zhou.
27
28 darktable is free software: you can redistribute it and/or modify
29 it under the terms of the GNU General Public License as published by
30 the Free Software Foundation, either version 3 of the License, or
31 (at your option) any later version.
32
33 darktable is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 GNU General Public License for more details.
37
38 You should have received a copy of the GNU General Public License
39 along with darktable. If not, see <http://www.gnu.org/licenses/>.
40*/
41
42#ifndef DT_COMMON_UTILITY_H
43#define DT_COMMON_UTILITY_H
44
45#include <gtk/gtk.h>
46#include <string.h>
47#include <librsvg/rsvg.h>
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
59size_t safe_strlen(const char *str);
60
62gchar *dt_util_dstrcat(gchar *str, const gchar *format, ...) __attribute__((format(printf, 2, 3)));
63
65gchar *dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute);
67guint dt_util_str_occurence(const gchar *haystack, const gchar *needle);
69gchar *dt_util_glist_to_str(const gchar *separator, GList *items);
71GList *dt_util_str_to_glist(const gchar *separator, const gchar *text);
73GList *dt_util_glist_uniq(GList *items);
75gchar *dt_util_fix_path(const gchar *path);
76size_t dt_utf8_strlcpy(char *dest, const char *src, size_t n);
78gboolean dt_util_test_image_file(const char *filename);
80gboolean dt_util_test_writable_dir(const char *path);
82gboolean dt_util_dir_exist(const char *dir);
84gboolean dt_util_is_dir_empty(const char *dirname);
86gchar *dt_util_foo_to_utf8(const char *string);
88guint dt_util_string_count_char(const char *text, const char needle);
89/* helper function to convert en float numbers to local based numbers for scanf */
91
99
102
103cairo_surface_t *dt_util_get_logo(const float size);
104cairo_surface_t *dt_util_get_logo_text(const float size);
105
106gchar *dt_util_latitude_str(float latitude);
107gchar *dt_util_longitude_str(float longitude);
108gchar *dt_util_elevation_str(float elevation);
109double dt_util_gps_string_to_number(const gchar *input);
110gboolean dt_util_gps_rationale_to_number(const double r0_1, const double r0_2, const double r1_1,
111 const double r1_2, const double r2_1, const double r2_2, char sign,
112 double *result);
113gboolean dt_util_gps_elevation_to_number(const double r_1, const double r_2, char sign, double *result);
114
115// make paths absolute and try to normalize on Windows. also deal with character encoding on Windows.
116gchar *dt_util_normalize_path(const gchar *input);
117
118#ifdef WIN32
119// returns TRUE if the path is a Windows UNC (\\server\share\...\file)
120const gboolean dt_util_path_is_UNC(const gchar *filename);
121#endif
122
123// gets the directory components of a file name, like g_path_get_dirname(), but works also with Windows networks paths (\\hostname\share\file)
124gchar *dt_util_path_get_dirname(const gchar *filename);
125
126// format exposure time string
127gchar *dt_util_format_exposure(const float exposuretime);
128
129// read the contents of the given file into a malloc'ed buffer
130// returns NULL if unable to read file or alloc memory; sets filesize to the number of bytes returned
131char *dt_read_file(const char *filename, size_t *filesize);
132
133// copy the contents of the given file to a new file
134void dt_copy_file(const char *src, const char *dst);
135
136// copy the contents of a file in dt's data directory to a new file
137void dt_copy_resource_file(const char *src, const char *dst);
138
139// returns the RsvgDimensionData of a supplied RsvgHandle
140RsvgDimensionData dt_get_svg_dimension(RsvgHandle *svg);
141
142// renders svg data
143void dt_render_svg(RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y);
144
145// check if the path + basenames are the same (<=> only differ by the extension)
146gboolean dt_has_same_path_basename(const char *filename1, const char *filename2);
147
148// set the filename2 extension to filename1 - return NULL if fails - result should be freed
149char *dt_copy_filename_extension(const char *filename1, const char *filename2);
150
151// replaces all occurences of a substring in a string
152gchar *dt_str_replace(const char *string, const char *search, const char *replace);
153
154// Checks for the opposite separator in a string and replace it by the needed one by the current OS
155gchar *dt_cleanup_separators(gchar *string);
156
157gchar *dt_util_remove_whitespace(const gchar *path);
158
159// Get the datetime of modification for a given file, identified by its full path
160GDateTime *dt_util_get_file_datetime(const char *const path);
161
162#ifdef __cplusplus
163}
164#endif
165
166#endif // DT_COMMON_UTILITY_H
167
168// clang-format off
169// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
170// vim: shiftwidth=2 expandtab tabstop=2 cindent
171// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
172// clang-format on
const dt_collection_sort_t items[]
Definition filter.c:102
uint32_t width
Definition mipmap_cache.c:0
uint32_t height
Definition mipmap_cache.c:1
size_t size
Definition mipmap_cache.c:3
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Apply one channel's tone curve to each of the three colour channels, or pass the channel through unto...
Definition simd.h:55
static const dt_aligned_pixel_simd_t sign
Definition simd.h:118
gboolean dt_util_gps_elevation_to_number(const double r_1, const double r_2, char sign, double *result)
Definition utility.c:665
guint dt_util_string_count_char(const char *text, const char needle)
Definition utility.c:814
gchar * dt_util_longitude_str(float longitude)
Definition utility.c:572
gchar * dt_str_replace(const char *string, const char *search, const char *replace)
Definition utility.c:1050
gboolean dt_has_same_path_basename(const char *filename1, const char *filename2)
Definition utility.c:1011
void dt_util_str_to_loc_numbers_format(char *data)
Definition utility.c:825
gchar * dt_cleanup_separators(gchar *string)
Definition utility.c:1059
gchar * dt_util_elevation_str(float elevation)
Definition utility.c:590
gboolean dt_util_dir_exist(const char *dir)
Definition utility.c:371
dt_logo_season_t dt_util_get_logo_season(void)
Definition utility.c:438
RsvgDimensionData dt_get_svg_dimension(RsvgHandle *svg)
Definition utility.c:961
cairo_surface_t * dt_util_get_logo_text(const float size)
Definition utility.c:536
GDateTime * dt_util_get_file_datetime(const char *const path)
Definition utility.c:792
GList * dt_util_str_to_glist(const gchar *separator, const gchar *text)
Definition utility.c:833
gboolean dt_util_test_image_file(const char *filename)
Definition utility.c:322
gchar * dt_util_format_exposure(const float exposuretime)
Definition utility.c:868
char * dt_read_file(const char *filename, size_t *filesize)
Definition utility.c:896
void dt_copy_resource_file(const char *src, const char *dst)
Definition utility.c:952
gchar gchar * dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute)
Definition utility.c:140
guint dt_util_str_occurence(const gchar *haystack, const gchar *needle)
Definition utility.c:123
gchar * dt_util_normalize_path(const gchar *input)
Definition utility.c:683
double dt_util_gps_string_to_number(const gchar *input)
Definition utility.c:609
gchar * dt_util_path_get_dirname(const gchar *filename)
Definition utility.c:777
dt_logo_season_t
Definition utility.h:93
@ DT_LOGO_SEASON_HALLOWEEN
Definition utility.h:95
@ DT_LOGO_SEASON_XMAS
Definition utility.h:96
@ DT_LOGO_SEASON_EASTER
Definition utility.h:97
@ DT_LOGO_SEASON_NONE
Definition utility.h:94
gboolean dt_util_is_dir_empty(const char *dirname)
Definition utility.c:379
size_t dt_utf8_strlcpy(char *dest, const char *src, size_t n)
Definition utility.c:293
size_t safe_strlen(const char *str)
check if the string is empty or NULL before calling strlen()
Definition utility.c:94
gboolean dt_util_test_writable_dir(const char *path)
Definition utility.c:348
gboolean dt_util_gps_rationale_to_number(const double r0_1, const double r0_2, const double r1_1, const double r1_2, const double r2_1, const double r2_2, char sign, double *result)
Definition utility.c:627
gchar * dt_util_fix_path(const gchar *path)
Definition utility.c:226
void dt_copy_file(const char *src, const char *dst)
Definition utility.c:920
gchar * dt_util_foo_to_utf8(const char *string)
Definition utility.c:396
gchar * dt_util_latitude_str(float latitude)
Definition utility.c:554
gchar * dt_util_remove_whitespace(const gchar *path)
Definition utility.c:1070
void dt_render_svg(RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y)
Definition utility.c:994
gchar * dt_util_dstrcat(gchar *str, const gchar *format,...) __attribute__((format(printf
gchar * dt_util_glist_to_str(const gchar *separator, GList *items)
Definition utility.c:170
char * dt_copy_filename_extension(const char *filename1, const char *filename2)
Definition utility.c:1030
GList * dt_util_glist_uniq(GList *items)
Definition utility.c:197
cairo_surface_t * dt_util_get_logo(const float size)
Definition utility.c:524