-
Notifications
You must be signed in to change notification settings - Fork 38
/
pslr_enum.c
352 lines (301 loc) · 9.74 KB
/
pslr_enum.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
pkTriggerCord
Copyright (C) 2011-2019 Andras Salamon <[email protected]>
Remote control of Pentax DSLR cameras.
Support for K200D added by Jens Dreyer <[email protected]> 04/2011
Support for K-r added by Vincenc Podobnik <[email protected]> 06/2011
Support for K-30 added by Camilo Polymeris <[email protected]> 09/2012
Support for K-01 added by Ethan Queen <[email protected]> 01/2013
Support for K-3 added by Tao Wang <[email protected]> 01/2016
based on:
PK-Remote
Remote control of Pentax DSLR cameras.
Copyright (C) 2008 Pontus Lidman <[email protected]>
PK-Remote for Windows
Copyright (C) 2010 Tomasz Kos
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU General Public License
and GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "pslr_enum.h"
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
const char* pslr_color_space_str[PSLR_COLOR_SPACE_MAX] = {
"sRGB",
"AdobeRGB"
};
const char* pslr_af_mode_str[PSLR_AF_MODE_MAX] = {
"MF",
"AF.S",
"AF.C",
"AF.A"
};
const char* pslr_ae_metering_str[PSLR_AE_METERING_MAX] = {
"Multi",
"Center",
"Spot"
};
const char* pslr_flash_mode_str[PSLR_FLASH_MODE_MAX] = {
"Manual",
"Manual-RedEye",
"Slow",
"Slow-RedEye",
"TrailingCurtain",
"Auto",
"Auto-RedEye",
"TrailingCurtain", /* maybe in manual mode?? */
"Wireless"
};
const char* pslr_drive_mode_str[PSLR_DRIVE_MODE_MAX] = {
"Single", /* Bracketing also returns Single */
"Continuous-HI",
"SelfTimer-12",
"SelfTimer-2",
"Remote",
"Remote-3",
"Continuous-LO"
};
const char* pslr_af_point_sel_str[PSLR_AF_POINT_SEL_MAX] = {
"Auto-5",
"Select",
"Spot",
"Auto-11",
"Expanded"
};
const char* pslr_af11_point_str[11] = {
"topleft",
"topmiddle",
"topright",
"farleft",
"middleleft",
"middlemiddle",
"middleright",
"farright",
"bottomleft",
"bottommiddle",
"bottomright"
};
const char* pslr_jpeg_image_tone_str[PSLR_JPEG_IMAGE_TONE_MAX] = {
"Natural",
"Bright",
"Portrait",
"Landscape",
"Vibrant",
"Monochrome",
"Muted",
"ReversalFilm",
"BleachBypass",
"Radiant",
"CrossProcessing",
"Flat",
"Auto"
};
const char* pslr_white_balance_mode_str[PSLR_WHITE_BALANCE_MODE_MAX] = {
"Auto",
"Daylight",
"Shade",
"Cloudy",
"Fluorescent_D",
"Fluorescent_N",
"Fluorescent_W",
"Tungsten",
"Flash",
"Manual", /* sometimes called Manual1 */
"Manual2",
"Manual3",
"Kelvin1",
"Kelvin2",
"Kelvin3",
"Fluorescent_L",
"CTE",
"MultiAuto"
};
const char* pslr_custom_ev_steps_str[PSLR_CUSTOM_EV_STEPS_MAX] = {
"1/2",
"1/3"
};
const char* pslr_custom_sensitivity_steps_str[PSLR_CUSTOM_SENSITIVITY_STEPS_MAX] = {
"1",
"As"
};
const char* pslr_image_format_str[PSLR_IMAGE_FORMAT_MAX] = {
"JPEG",
"RAW",
"RAW+"
};
const char* pslr_raw_format_str[PSLR_RAW_FORMAT_MAX] = {
"PEF",
"DNG"
};
const char* pslr_scene_mode_str[PSLR_SCENE_MODE_MAX] = {
"NONE",
"HISPEED",
"DOF",
"MTF",
"STANDARD",
"PORTRAIT",
"LANDSCAPE",
"MACRO",
"SPORT",
"NIGHTSCENEPORTRAIT",
"NOFLASH",
"NIGHTSCENE",
"SURFANDSNOW",
"TEXT",
"SUNSET",
"KIDS",
"PET",
"CANDLELIGHT",
"MUSEUM",
"19",
"FOOD",
"STAGE",
"NIGHTSNAP",
"SWALLOWDOF",
"24",
"NIGHTSCENEHDR",
"BLUESKY",
"FOREST",
"28",
"BLACKLIGHTSILHOUETTE"
};
/* case insenstive comparison - strnicmp */
int str_comparison_i (const char *s1, const char *s2, int n) {
if ( s1 == NULL ) {
return s2 == NULL ? 0 : -(*s2);
}
if (s2 == NULL) {
return *s1;
}
char c1='\0', c2='\0';
int length=0;
while ( length<n && (c1 = tolower (*s1)) == (c2 = tolower (*s2))) {
if (*s1 == '\0') {
break;
}
++s1;
++s2;
++length;
}
return c1 - c2;
}
int find_in_array( const char** array, int length, char* str ) {
int i;
int found_index=-1;
size_t found_index_length=0;
size_t string_length;
for ( i = 0; i<length; ++i ) {
string_length = strlen(array[i]);
if ( (str_comparison_i( array[i], str, string_length ) == 0) && (string_length > found_index_length) ) {
found_index_length = string_length;
found_index = i;
}
}
return found_index;
}
static
const char *get_pslr_str( const char** array, int length, int value ) {
if (value >=0 && value < length) {
return array[value];
} else {
char *ret = malloc(128);
sprintf (ret, "Unknown value: %d", value);
return ret;
}
}
pslr_color_space_t pslr_get_color_space( char *str ) {
return find_in_array( pslr_color_space_str, sizeof(pslr_color_space_str)/sizeof(pslr_color_space_str[0]),str);
}
const char *pslr_get_color_space_str( pslr_color_space_t value ) {
return get_pslr_str( pslr_color_space_str, sizeof(pslr_color_space_str)/sizeof(pslr_color_space_str[0]),value);
}
pslr_af_mode_t pslr_get_af_mode( char *str ) {
return find_in_array( pslr_af_mode_str, sizeof(pslr_af_mode_str)/sizeof(pslr_af_mode_str[0]),str);
}
const char *pslr_get_af_mode_str( pslr_af_mode_t value ) {
return get_pslr_str( pslr_af_mode_str, sizeof(pslr_af_mode_str)/sizeof(pslr_af_mode_str[0]),value);
}
pslr_ae_metering_t pslr_get_ae_metering( char *str ) {
return find_in_array( pslr_ae_metering_str, sizeof(pslr_ae_metering_str)/sizeof(pslr_ae_metering_str[0]),str);
}
const char *pslr_get_ae_metering_str( pslr_ae_metering_t value ) {
return get_pslr_str( pslr_ae_metering_str, sizeof(pslr_ae_metering_str)/sizeof(pslr_ae_metering_str[0]),value);
}
pslr_flash_mode_t pslr_get_flash_mode( char *str ) {
return find_in_array( pslr_flash_mode_str, sizeof(pslr_flash_mode_str)/sizeof(pslr_flash_mode_str[0]),str);
}
const char *pslr_get_flash_mode_str( pslr_flash_mode_t value ) {
return get_pslr_str( pslr_flash_mode_str, sizeof(pslr_flash_mode_str)/sizeof(pslr_flash_mode_str[0]),value);
}
pslr_drive_mode_t pslr_get_drive_mode( char *str ) {
return find_in_array( pslr_drive_mode_str, sizeof(pslr_drive_mode_str)/sizeof(pslr_drive_mode_str[0]),str);
}
const char *pslr_get_drive_mode_str( pslr_drive_mode_t value ) {
return get_pslr_str( pslr_drive_mode_str, sizeof(pslr_drive_mode_str)/sizeof(pslr_drive_mode_str[0]),value);
}
pslr_af_point_sel_t pslr_get_af_point_sel( char *str ) {
return find_in_array( pslr_af_point_sel_str, sizeof(pslr_af_point_sel_str)/sizeof(pslr_af_point_sel_str[0]),str);
}
const char *pslr_get_af_point_sel_str( pslr_af_point_sel_t value ) {
return get_pslr_str( pslr_af_point_sel_str, sizeof(pslr_af_point_sel_str)/sizeof(pslr_af_point_sel_str[0]),value);
}
char *pslr_get_af11_point_str( uint32_t value ) {
if (value==0) {
return "none";
}
int bitidx=0;
char *ret = malloc(1024);
int pos = sprintf(ret, "%s", "");
while (value>0 && bitidx<11) {
if ((value & 0x01) == 1) {
int written = sprintf(ret + pos, "%s%s", pos == 0 ? "" : ",", pslr_af11_point_str[bitidx]);
if (written < 0) {
return ret;
}
pos += written;
}
value >>= 1;
++bitidx;
}
if (value>0) {
sprintf(ret, "%s", "invalid");
}
return ret;
}
pslr_jpeg_image_tone_t pslr_get_jpeg_image_tone( char *str ) {
return find_in_array( pslr_jpeg_image_tone_str, sizeof(pslr_jpeg_image_tone_str)/sizeof(pslr_jpeg_image_tone_str[0]),str);
}
const char *pslr_get_jpeg_image_tone_str( pslr_jpeg_image_tone_t value ) {
return get_pslr_str( pslr_jpeg_image_tone_str, sizeof(pslr_jpeg_image_tone_str)/sizeof(pslr_jpeg_image_tone_str[0]),value);
}
pslr_white_balance_mode_t pslr_get_white_balance_mode( char *str ) {
return find_in_array( pslr_white_balance_mode_str, sizeof(pslr_white_balance_mode_str)/sizeof(pslr_white_balance_mode_str[0]),str);
}
const char *pslr_get_white_balance_mode_str( pslr_white_balance_mode_t value ) {
return get_pslr_str( pslr_white_balance_mode_str, sizeof(pslr_white_balance_mode_str)/sizeof(pslr_white_balance_mode_str[0]),value);
}
const char *pslr_get_custom_ev_steps_str( pslr_custom_ev_steps_t value ) {
return get_pslr_str( pslr_custom_ev_steps_str, sizeof(pslr_custom_ev_steps_str)/sizeof(pslr_custom_ev_steps_str[0]),value);
}
const char *pslr_get_custom_sensitivity_steps_str( pslr_custom_sensitivity_steps_t value ) {
return get_pslr_str( pslr_custom_sensitivity_steps_str, sizeof(pslr_custom_sensitivity_steps_str)/sizeof(pslr_custom_sensitivity_steps_str[0]),value);
}
const char *pslr_get_image_format_str( pslr_image_format_t value ) {
return get_pslr_str( pslr_image_format_str, sizeof(pslr_image_format_str)/sizeof(pslr_image_format_str[0]),value);
}
const char *pslr_get_raw_format_str( pslr_raw_format_t value ) {
return get_pslr_str( pslr_raw_format_str, sizeof(pslr_raw_format_str)/sizeof(pslr_raw_format_str[0]),value);
}
const char *pslr_get_scene_mode_str( pslr_scene_mode_t value ) {
return get_pslr_str( pslr_scene_mode_str, sizeof(pslr_scene_mode_str)/sizeof(pslr_scene_mode_str[0]),value);
}