-
Notifications
You must be signed in to change notification settings - Fork 8
/
ufraw.c
155 lines (145 loc) · 4.45 KB
/
ufraw.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* UFRaw - Unidentified Flying Raw converter for digital camera images
*
* ufraw.c - The standalone interface to UFRaw.
* Copyright 2004-2016 by Udi Fuchs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include "ufraw.h"
#include "uf_gtk.h"
#include <stdlib.h> /* for exit */
#include <errno.h> /* for errno */
#include <string.h>
#include <glib/gi18n.h>
char *ufraw_binary;
int main(int argc, char **argv)
{
ufraw_data *uf;
conf_data rc, cmd, conf;
int status;
GtkWidget *dummyWindow = NULL;
int optInd;
int plugin = 0;
#if !GLIB_CHECK_VERSION(2,31,0)
g_thread_init(NULL);
#endif
#ifndef _WIN32
gdk_threads_init();
gdk_threads_enter();
#endif
char *argFile = uf_win32_locale_to_utf8(argv[0]);
ufraw_binary = g_path_get_basename(argFile);
uf_init_locale(argFile);
uf_win32_locale_free(argFile);
char *gtkrcfile = g_build_filename(uf_get_home_dir(),
".ufraw-gtkrc", NULL);
gtk_rc_add_default_file(gtkrcfile);
g_free(gtkrcfile);
gtk_init(&argc, &argv);
ufraw_icons_init();
#ifdef _WIN32
dummyWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_icon_name(GTK_WINDOW(dummyWindow), "ufraw");
ufraw_message(UFRAW_SET_PARENT, (char *)dummyWindow);
#endif
/* Load $HOME/.ufrawrc */
conf_load(&rc, NULL);
/* Half interpolation is an option only for the GIMP plug-in.
* For the stand-alone tool it is disabled */
if (rc.interpolation == half_interpolation)
rc.interpolation = ahd_interpolation;
if (!rc.RememberOutputPath)
g_strlcpy(rc.outputPath, "", max_path);
g_strlcpy(rc.inputFilename, "", max_path);
g_strlcpy(rc.outputFilename, "", max_path);
/* Put the command-line options in cmd */
optInd = ufraw_process_args(&argc, &argv, &cmd, &rc);
if (strlen(cmd.outputFilename) != 0) {
plugin = 3;
}
if (cmd.silent) {
ufraw_message(UFRAW_ERROR,
_("The --silent option is only valid with 'ufraw-batch'"));
optInd = -1;
}
if (cmd.embeddedImage) {
ufraw_message(UFRAW_ERROR,
_("The --embedded-image option is only valid with 'ufraw-batch'"));
optInd = -1;
}
if (optInd < 0) {
#ifndef _WIN32
gdk_threads_leave();
#endif
exit(1);
}
if (optInd == 0) {
#ifndef _WIN32
gdk_threads_leave();
#endif
exit(0);
}
/* Create a dummyWindow for the GUI error messenger */
if (dummyWindow == NULL) {
dummyWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_icon_name(GTK_WINDOW(dummyWindow), "ufraw");
ufraw_message(UFRAW_SET_PARENT, (char *)dummyWindow);
}
conf_file_load(&conf, cmd.inputFilename);
if (optInd == argc) {
ufraw_chooser(&rc, &conf, &cmd, NULL);
// ufraw_close(cmd.darkframe);
#ifndef _WIN32
gdk_threads_leave();
#endif
exit(0);
}
/* If there only one argument and it is a directory, use it as the
* default directory for the file-chooser */
argFile = uf_win32_locale_to_utf8(argv[optInd]);
if (optInd == argc - 1 && g_file_test(argFile, G_FILE_TEST_IS_DIR)) {
ufraw_chooser(&rc, &conf, &cmd, argFile);
uf_win32_locale_free(argFile);
// ufraw_close(cmd.darkframe);
#ifndef _WIN32
gdk_threads_leave();
#endif
exit(0);
}
uf_win32_locale_free(argFile);
int exitCode = 0;
for (; optInd < argc; optInd++) {
argFile = uf_win32_locale_to_utf8(argv[optInd]);
uf = ufraw_open(argFile);
uf_win32_locale_free(argFile);
if (uf == NULL) {
exitCode = 1;
ufraw_message(UFRAW_REPORT, NULL);
continue;
}
status = ufraw_config(uf, &rc, &conf, &cmd);
if (status == UFRAW_ERROR) {
ufraw_close_darkframe(uf->conf);
ufraw_close(uf);
g_free(uf);
#ifndef _WIN32
gdk_threads_leave();
#endif
exit(1);
}
ufraw_preview(uf, &rc, plugin, NULL);
g_free(uf);
}
if (dummyWindow != NULL) gtk_widget_destroy(dummyWindow);
// ufraw_close(cmd.darkframe);
ufobject_delete(cmd.ufobject);
ufobject_delete(rc.ufobject);
#ifndef _WIN32
gdk_threads_leave();
#endif
exit(exitCode);
}