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#pragma once
43
44#include <gtk/gtk.h>
45#include <string.h>
46#include <librsvg/rsvg.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
58size_t safe_strlen(const char *str);
59
61gchar *dt_util_dstrcat(gchar *str, const gchar *format, ...) __attribute__((format(printf, 2, 3)));
62
64gchar *dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute);
66guint dt_util_str_occurence(const gchar *haystack, const gchar *needle);
68gchar *dt_util_glist_to_str(const gchar *separator, GList *items);
70GList *dt_util_str_to_glist(const gchar *separator, const gchar *text);
72GList *dt_util_glist_uniq(GList *items);
74gchar *dt_util_fix_path(const gchar *path);
75size_t dt_utf8_strlcpy(char *dest, const char *src, size_t n);
77gboolean dt_util_test_image_file(const char *filename);
79gboolean dt_util_test_writable_dir(const char *path);
81gboolean dt_util_dir_exist(const char *dir);
83gboolean dt_util_is_dir_empty(const char *dirname);
85gchar *dt_util_foo_to_utf8(const char *string);
87guint dt_util_string_count_char(const char *text, const char needle);
88/* helper function to convert en float numbers to local based numbers for scanf */
90
98
101
102cairo_surface_t *dt_util_get_logo(const float size);
103cairo_surface_t *dt_util_get_logo_text(const float size);
104
105gchar *dt_util_latitude_str(float latitude);
106gchar *dt_util_longitude_str(float longitude);
107gchar *dt_util_elevation_str(float elevation);
108double dt_util_gps_string_to_number(const gchar *input);
109gboolean dt_util_gps_rationale_to_number(const double r0_1, const double r0_2, const double r1_1,
110 const double r1_2, const double r2_1, const double r2_2, char sign,
111 double *result);
112gboolean dt_util_gps_elevation_to_number(const double r_1, const double r_2, char sign, double *result);
113
114// make paths absolute and try to normalize on Windows. also deal with character encoding on Windows.
115gchar *dt_util_normalize_path(const gchar *input);
116
117#ifdef WIN32
118// returns TRUE if the path is a Windows UNC (\\server\share\...\file)
119const gboolean dt_util_path_is_UNC(const gchar *filename);
120#endif
121
122// gets the directory components of a file name, like g_path_get_dirname(), but works also with Windows networks paths (\\hostname\share\file)
123gchar *dt_util_path_get_dirname(const gchar *filename);
124
125// format exposure time string
126gchar *dt_util_format_exposure(const float exposuretime);
127
128// read the contents of the given file into a malloc'ed buffer
129// returns NULL if unable to read file or alloc memory; sets filesize to the number of bytes returned
130char *dt_read_file(const char *filename, size_t *filesize);
131
132// copy the contents of the given file to a new file
133void dt_copy_file(const char *src, const char *dst);
134
135// copy the contents of a file in dt's data directory to a new file
136void dt_copy_resource_file(const char *src, const char *dst);
137
138// returns the RsvgDimensionData of a supplied RsvgHandle
139RsvgDimensionData dt_get_svg_dimension(RsvgHandle *svg);
140
141// renders svg data
142void dt_render_svg(RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y);
143
144// check if the path + basenames are the same (<=> only differ by the extension)
145gboolean dt_has_same_path_basename(const char *filename1, const char *filename2);
146
147// set the filename2 extension to filename1 - return NULL if fails - result should be freed
148char *dt_copy_filename_extension(const char *filename1, const char *filename2);
149
150// replaces all occurences of a substring in a string
151gchar *dt_str_replace(const char *string, const char *search, const char *replace);
152
153// Checks for the opposite separator in a string and replace it by the needed one by the current OS
154gchar *dt_cleanup_separators(gchar *string);
155
156gchar *dt_util_remove_whitespace(const gchar *path);
157
158// Get the datetime of modification for a given file, identified by its full path
159GDateTime *dt_util_get_file_datetime(const char *const path);
160
161#ifdef __cplusplus
162}
163#endif
164
165// clang-format off
166// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
167// vim: shiftwidth=2 expandtab tabstop=2 cindent
168// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
169// clang-format on
int width
Definition bilateral.h:1
int height
Definition bilateral.h:1
const float n
Definition colorspaces_inline_conversions.h:929
float dt_aligned_pixel_simd_t __attribute__((vector_size(16), aligned(16)))
Multi-tap smudge source sample with directional jitter.
Definition darktable.h:448
static const dt_aligned_pixel_simd_t sign
Definition darktable.h:475
const dt_collection_sort_t items[]
Definition filter.c:103
size_t size
Definition mipmap_cache.c:3
gboolean dt_util_gps_elevation_to_number(const double r_1, const double r_2, char sign, double *result)
Definition utility.c:662
guint dt_util_string_count_char(const char *text, const char needle)
Definition utility.c:811
gchar * dt_util_longitude_str(float longitude)
Definition utility.c:569
gchar * dt_str_replace(const char *string, const char *search, const char *replace)
Definition utility.c:1039
gboolean dt_has_same_path_basename(const char *filename1, const char *filename2)
Definition utility.c:1000
void dt_util_str_to_loc_numbers_format(char *data)
Definition utility.c:822
gchar * dt_cleanup_separators(gchar *string)
Definition utility.c:1048
gchar * dt_util_elevation_str(float elevation)
Definition utility.c:587
gboolean dt_util_dir_exist(const char *dir)
Definition utility.c:367
dt_logo_season_t dt_util_get_logo_season(void)
Definition utility.c:434
RsvgDimensionData dt_get_svg_dimension(RsvgHandle *svg)
Definition utility.c:950
cairo_surface_t * dt_util_get_logo_text(const float size)
Definition utility.c:533
GDateTime * dt_util_get_file_datetime(const char *const path)
Definition utility.c:789
GList * dt_util_str_to_glist(const gchar *separator, const gchar *text)
Definition utility.c:830
gboolean dt_util_test_image_file(const char *filename)
Definition utility.c:318
gchar * dt_util_format_exposure(const float exposuretime)
Definition utility.c:865
char * dt_read_file(const char *filename, size_t *filesize)
Definition utility.c:893
void dt_copy_resource_file(const char *src, const char *dst)
Definition utility.c:941
gchar gchar * dt_util_str_replace(const gchar *string, const gchar *pattern, const gchar *substitute)
Definition utility.c:136
guint dt_util_str_occurence(const gchar *haystack, const gchar *needle)
Definition utility.c:119
gchar * dt_util_normalize_path(const gchar *input)
Definition utility.c:680
double dt_util_gps_string_to_number(const gchar *input)
Definition utility.c:606
gchar * dt_util_path_get_dirname(const gchar *filename)
Definition utility.c:774
dt_logo_season_t
Definition utility.h:92
@ DT_LOGO_SEASON_HALLOWEEN
Definition utility.h:94
@ DT_LOGO_SEASON_XMAS
Definition utility.h:95
@ DT_LOGO_SEASON_EASTER
Definition utility.h:96
@ DT_LOGO_SEASON_NONE
Definition utility.h:93
gboolean dt_util_is_dir_empty(const char *dirname)
Definition utility.c:375
size_t dt_utf8_strlcpy(char *dest, const char *src, size_t n)
Definition utility.c:289
size_t safe_strlen(const char *str)
check if the string is empty or NULL before calling strlen()
Definition utility.c:90
gboolean dt_util_test_writable_dir(const char *path)
Definition utility.c:344
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:624
gchar * dt_util_fix_path(const gchar *path)
Definition utility.c:222
void dt_copy_file(const char *src, const char *dst)
Definition utility.c:917
gchar * dt_util_foo_to_utf8(const char *string)
Definition utility.c:392
gchar * dt_util_latitude_str(float latitude)
Definition utility.c:551
gchar * dt_util_remove_whitespace(const gchar *path)
Definition utility.c:1059
void dt_render_svg(RsvgHandle *svg, cairo_t *cr, double width, double height, double offset_x, double offset_y)
Definition utility.c:983
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:166
char * dt_copy_filename_extension(const char *filename1, const char *filename2)
Definition utility.c:1019
GList * dt_util_glist_uniq(GList *items)
Definition utility.c:193
cairo_surface_t * dt_util_get_logo(const float size)
Definition utility.c:521