-
Notifications
You must be signed in to change notification settings - Fork 0
/
pktriggercord.c
2162 lines (1855 loc) · 68.6 KB
/
pktriggercord.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
pkTriggerCord
Remote control of Pentax DSLR cameras.
Copyright (C) 2011-2014 Andras Salamon <[email protected]>
based on:
PK-Remote: Remote control of Pentax DSLR cameras.
Copyright (C) 2008 Pontus Lidman <[email protected]>
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 <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <math.h>
#include <getopt.h>
#include "pslr.h"
#include "pslr_lens.h"
#ifdef WIN32
#define FILE_ACCESS O_WRONLY | O_CREAT | O_TRUNC | O_BINARY
#else
#define FILE_ACCESS O_WRONLY | O_CREAT | O_TRUNC
#endif
#define GW(name) GTK_WIDGET (gtk_builder_get_object (xml, name))
/* ----------------------------------------------------------------------- */
// status.bufmask
#define MAX_BUFFERS 8*sizeof(uint16_t)
static struct {
char *autosave_path;
} plugin_config;
/* ----------------------------------------------------------------------- */
static gboolean added_quit(gpointer data);
static void my_atexit(void);
//gboolean da_buttonpress(GtkWidget *widget);
int common_init(void);
void init_preview_area(void);
void set_preview_icon(int n, GdkPixbuf *pBuf);
void error_message(const gchar *message);
static gboolean status_poll(gpointer data);
static void update_preview_area(int buffer);
static void update_main_area(int buffer);
static void init_controls(pslr_status *st_new, pslr_status *st_old);
static bool auto_save_check(int format, int buffer);
static void manage_camera_buffers(pslr_status *st_new, pslr_status *st_old);
static void manage_camera_buffers_limited();
static void which_shutter_table(pslr_status *st, pslr_rational_t **table, int *steps);
static void which_iso_table(pslr_status *st, const int **table, int *steps);
static void which_ec_table(pslr_status *st, const int **table, int *steps);
static bool is_inside(int rect_x, int rect_y, int rect_w, int rect_h, int px, int py);
static void save_buffer(int bufno, const char *filename);
/* ----------------------------------------------------------------------- */
#define AF_FAR_LEFT 132
#define AF_LEFT 223
#define AF_CENTER 319
#define AF_RIGHT 415
#define AF_FAR_RIGHT 505 // 283
#define AF_TOP (149+27) // 84
#define AF_MID (213+27)
#define AF_BOTTOM (276+27) // 156
#define AF_CROSS_W 9
#define AF_CROSS_H 10
#define AF_CENTER_W 15
#define AF_CENTER_H 15
#define AF_LINE_W 7
#define AF_LINE_H 21
/* Order of array corresponsds to AF point bitmask, see
* PSLR_AF_POINT_* defines. */
static struct {
int x;
int y;
int w;
int h;
} af_points[] = {
{ AF_LEFT-(AF_CROSS_W/2), AF_TOP-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_CENTER-(AF_CROSS_W/2), AF_TOP-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_RIGHT-(AF_CROSS_W/2), AF_TOP-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_FAR_LEFT - (AF_LINE_W/2), AF_MID - (AF_LINE_H/2) - 1, AF_LINE_W, AF_LINE_H },
{ AF_LEFT-(AF_CROSS_W/2), AF_MID-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_CENTER-(AF_CENTER_W/2), AF_MID-(AF_CENTER_H/2) - 1, AF_CENTER_W, AF_CENTER_H },
{ AF_RIGHT-(AF_CROSS_W/2), AF_MID-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_FAR_RIGHT - (AF_LINE_W/2), AF_MID - (AF_LINE_H/2) - 1, AF_LINE_W, AF_LINE_H },
{ AF_LEFT-(AF_CROSS_W/2), AF_BOTTOM-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_CENTER-(AF_CROSS_W/2), AF_BOTTOM-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
{ AF_RIGHT-(AF_CROSS_W/2), AF_BOTTOM-(AF_CROSS_H/2), AF_CROSS_W, AF_CROSS_H },
};
static uint32_t focus_indicated_af_points;
static uint32_t select_indicated_af_points;
static uint32_t preselect_indicated_af_points;
static bool preselect_reselect = false;
/* 40-220 confirmed */
/* This is the nominator, the denominator is 10 for all confirmed
* apertures */
static const int aperture_tbl[] = {
10, 11, 12, 14, 16, 17, 18,
20, 22, 24, 25, 28, 32, 35,
40, 45, 50, 56, 63, 67, 71,
80, 90, 95, 100, 110, 130, 140,
160, 180, 190, 200, 220, 250, 280,
320, 360, 400, 450, 510, 570
};
static pslr_rational_t shutter_tbl_1_3[] = {
{ 30, 1},{ 25, 1},{ 20, 1},{ 15, 1},{ 13, 1},{ 10, 1},{ 8 , 1},{ 6 , 1},
{ 5 , 1},{ 4 , 1},{ 3 , 1},{ 25, 10},{ 2 , 1},{ 16, 10},{ 13, 10},{ 1 , 1},
{ 8 , 10},{ 6 , 10},{ 5 , 10},{ 4 , 10},{ 3 , 10},{ 1 , 4},{ 1 , 5},{ 1 , 6},
{ 1 , 8},{ 1 , 10},{ 1 , 13},{ 1 , 15},{ 1 , 20},{ 1 , 25},{ 1 , 30},{ 1 , 40},
{ 1 , 50},{ 1 , 60},{ 1 , 80},{ 1 , 100},{ 1 , 125},{ 1 , 160},{ 1 , 200},{ 1 , 250},
{ 1 , 320},{ 1 , 400},{ 1 , 500},{ 1 , 640},{ 1 , 800},{ 1 , 1000},{ 1 , 1250},{ 1 , 1600},
{ 1 , 2000},{ 1 , 2500},{ 1 , 3200},{ 1 , 4000},{1 , 5000}, {1, 6400}, {1, 8000}
};
static pslr_rational_t shutter_tbl_1_2[] = {
{ 30, 1},{ 20, 1},{ 15, 1},{ 10, 1},{ 8 , 1},{ 6 , 1},
{ 4 , 1},{ 3 , 1},{ 2 , 1},{ 15, 10},{ 1 , 1},
{ 7 , 10},{ 5 , 10},{ 3 , 10},{ 1 , 4},{ 1 , 6},
{ 1 , 8},{ 1 , 10},{ 1 , 15},{ 1 , 20},{ 1 , 30},
{ 1 , 45},{ 1 , 60},{ 1 , 90},{ 1 , 125},{ 1 , 180},{ 1 , 250},
{ 1 , 350},{ 1 , 500},{ 1 , 750},{ 1 , 1000},{ 1 , 1500},
{ 1 , 2000},{ 1 , 3000},{ 1 , 4000}, {1, 6400}, {1, 8000}
};
static const int iso_tbl_1_3[] = {
80, 100, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 1250, 1600, 2000, 2500,
3200, 4000, 5000, 6400, 8000, 10000, 12800, 16000, 20000, 25600, 32000, 40000, 51200
};
static const int iso_tbl_1_2[] = {
100, 140, 200, 280, 400, 560, 800, 1100, 1600, 2200, 3200, 4500, 6400, 12800, 25600, 51200
};
static const int iso_tbl_1[] = {
100, 200, 400, 800, 1600, 3200, 6400
};
static const int ec_tbl_1_3[] = {
-30, -27, -23, -20, -17, -13, -10, -7, -3, 0, 3, 7, 10, 13, 17, 20, 23, 27, 30
};
static const int ec_tbl_1_2[]= {
-30, -25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 30
};
/* ----------------------------------------------------------------------- */
static pslr_handle_t camhandle;
static GtkBuilder *xml;
static GtkStatusbar *statusbar;
static guint sbar_connect_ctx;
static guint sbar_download_ctx;
bool need_histogram=false;
static GtkListStore *list_store;
bool debug = false;
static const int THUMBNAIL_WIDTH = 160;
static const int THUMBNAIL_HEIGHT = 120;
static const int HISTOGRAM_WIDTH = 640;
static const int HISTOGRAM_HEIGHT = 480;
void combobox_append( GtkComboBox *combobox, char **items, int item_num ) {
GtkListStore *store = gtk_list_store_new (1, G_TYPE_STRING);
GtkTreeIter iter;
int i;
DPRINT("combobox_append\n");
for (i = 0; i<item_num; i++) {
DPRINT("adding item %s\n", items[i] );
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, items[i], -1);
}
gtk_combo_box_set_model( combobox, GTK_TREE_MODEL(store));
GtkCellRenderer * cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( combobox ), cell, TRUE );
gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( combobox ), cell, "text", 0, NULL );
}
int common_init(void)
{
GtkWidget *widget;
atexit(my_atexit);
gtk_init(0, 0);
gtk_quit_add(0, added_quit, 0);
DPRINT("Create gtk xml\n");
GError* error = NULL;
if (debug) {
xml = gtk_builder_new ();
if (!gtk_builder_add_from_file (xml, "pktriggercord.ui", &error)) {
error = NULL;
if( !gtk_builder_add_from_file (xml, DATADIR "/pktriggercord.ui", &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
return -1;
}
}
} else {
xml = gtk_builder_new ();
if (!gtk_builder_add_from_file (xml, DATADIR "/pktriggercord.ui", &error)) {
error = NULL;
if( !gtk_builder_add_from_file (xml, "pktriggercord.ui", &error)) {
g_warning ("Couldn't load builder file: %s", error->message);
g_error_free (error);
return -1;
}
}
}
init_preview_area();
widget = GTK_WIDGET (gtk_builder_get_object (xml, "mainwindow"));
gchar titlebuf[128];
snprintf(titlebuf, sizeof(titlebuf), "pkTriggerCord %s", VERSION);
gtk_window_set_title( (GtkWindow *)widget, titlebuf);
gtk_builder_connect_signals( xml, NULL );
statusbar = GTK_STATUSBAR(GTK_WIDGET (gtk_builder_get_object (xml, "statusbar1")));
sbar_connect_ctx = gtk_statusbar_get_context_id(statusbar, "connect");
sbar_download_ctx = gtk_statusbar_get_context_id(statusbar, "download");
gtk_statusbar_push(statusbar, sbar_connect_ctx, "No camera connected.");
gdk_window_set_events(widget->window, GDK_ALL_EVENTS_MASK);
GtkComboBox *pw = (GtkComboBox*)GTK_WIDGET (gtk_builder_get_object (xml, "file_format_combo"));
int numfileformats = sizeof(file_formats) / sizeof (file_formats[0]);
char **fileformatnames = malloc( numfileformats * sizeof(char*) );
int i;
for (i = 0; i<numfileformats; i++) {
fileformatnames[i] = malloc( strlen(file_formats[i].file_format_name)+1);
memset( fileformatnames[i], '\0', strlen(file_formats[i].file_format_name)+1);
strncpy( fileformatnames[i], file_formats[i].file_format_name, strlen( file_formats[i].file_format_name ));
}
combobox_append( pw, fileformatnames, numfileformats );
init_controls(NULL, NULL);
g_timeout_add(1000, status_poll, 0);
gtk_widget_show(widget);
gtk_main();
return 0;
}
static int get_jpeg_property_shift() {
return (pslr_get_model_jpeg_property_levels( camhandle )-1) / 2;
}
void shutter_speed_table_init(pslr_status *st) {
// check valid shutter speeds for the camera
int max_valid_shutter_speed_index=0;
int i;
pslr_rational_t *tbl;
int steps;
which_shutter_table( st, &tbl, &steps);
int fastest_shutter_speed = pslr_get_model_fastest_shutter_speed(camhandle);
for(i=0; i<steps; i++) {
if( tbl[i].nom == 1 &&
tbl[i].denom <= fastest_shutter_speed) {
max_valid_shutter_speed_index = i;
}
}
if( tbl[max_valid_shutter_speed_index].denom != fastest_shutter_speed ) {
// not an exact match
++max_valid_shutter_speed_index;
tbl[max_valid_shutter_speed_index].denom = fastest_shutter_speed;
}
GtkWidget *pw;
pw = GTK_WIDGET (gtk_builder_get_object (xml, "shutter_scale"));
//printf("range 0-%f\n", (float) sizeof(shutter_tbl)/sizeof(shutter_tbl[0]));
gtk_range_set_range(GTK_RANGE(pw), 0.0, max_valid_shutter_speed_index);
gtk_range_set_increments(GTK_RANGE(pw), 1.0, 1.0);
}
void iso_speed_table_init(pslr_status *st) {
GtkWidget *pw;
pw = GTK_WIDGET (gtk_builder_get_object (xml, "iso_scale"));
const int *tbl = 0;
int steps = 0;
which_iso_table(st, &tbl, &steps);
int min_iso_index=0;
int max_iso_index=steps-1;
int i;
// cannot determine if base or extended iso is set.
// use extended iso range
for(i=0; i<steps; i++) {
if( tbl[i] < pslr_get_model_extended_iso_min(camhandle)) {
min_iso_index = i+1;
}
if( tbl[i] <= pslr_get_model_extended_iso_max(camhandle)) {
max_iso_index = i;
}
}
gtk_range_set_range(GTK_RANGE(pw), (gdouble)(min_iso_index), (gdouble) (max_iso_index));
}
void camera_specific_init() {
gtk_range_set_range( GTK_RANGE(GW("jpeg_hue_scale")), -get_jpeg_property_shift(), get_jpeg_property_shift());
gtk_range_set_range( GTK_RANGE(GW("jpeg_sharpness_scale")), -get_jpeg_property_shift(), get_jpeg_property_shift());
gtk_range_set_range( GTK_RANGE(GW("jpeg_saturation_scale")), -get_jpeg_property_shift(), get_jpeg_property_shift());
gtk_range_set_range( GTK_RANGE(GW("jpeg_contrast_scale")), -get_jpeg_property_shift(), get_jpeg_property_shift());
int *resolutions = pslr_get_model_jpeg_resolutions( camhandle );
int resindex=0;
// gchar buf[256];
char **str_resolutions = malloc( MAX_RESOLUTION_SIZE * sizeof( char * ));
while( resindex < MAX_RESOLUTION_SIZE ) {
str_resolutions[resindex] = malloc( 10 );
sprintf( str_resolutions[resindex], "%dM", resolutions[resindex]);
++resindex;
}
combobox_append( GTK_COMBO_BOX(GW("jpeg_resolution_combo")), str_resolutions, MAX_RESOLUTION_SIZE );
int starindex= pslr_get_model_max_jpeg_stars( camhandle) ;
const char ch[] = "*********";
char **str_jpegstars = malloc( starindex * sizeof( char * ));
int num_stars = starindex;
int index=0;
while( starindex > 0 ) {
str_jpegstars[index] = malloc(10);
sprintf( str_jpegstars[index], "%.*s", starindex,ch);
// gtk_combo_box_insert_text( GTK_COMBO_BOX(GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_quality_combo"))), resindex, buf);
--starindex;
++index;
}
combobox_append( GTK_COMBO_BOX(GW("jpeg_quality_combo")), str_jpegstars, num_stars );
// jpeg image tone
int max_supported_image_tone = pslr_get_model_max_supported_image_tone( camhandle );
GtkComboBox *pw = (GtkComboBox*)GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_image_tone_combo"));
char **imagetones = malloc( max_supported_image_tone * sizeof(char*) );
int i;
for (i = 0; i<max_supported_image_tone; i++) {
DPRINT("get tone %s\n", get_pslr_jpeg_image_tone_str( i ) );
imagetones[i] = malloc( strlen( get_pslr_jpeg_image_tone_str( i ))+1);
memset(imagetones[i], '\0', strlen( get_pslr_jpeg_image_tone_str( i ))+1);
strncpy( imagetones[i], get_pslr_jpeg_image_tone_str( i ), strlen( get_pslr_jpeg_image_tone_str( i ) ));
}
combobox_append( pw, imagetones, max_supported_image_tone );
gtk_widget_set_sensitive( GTK_WIDGET(pw), max_supported_image_tone > -1 );
}
static void init_controls(pslr_status *st_new, pslr_status *st_old)
{
GtkWidget *pw;
int min_ap=-1, max_ap=-1, current_ap = -1;
int current_iso = -1;
int idx;
int i;
bool disable = false;
if (st_new == NULL)
disable = true;
/* Aperture scale */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "aperture_scale"));
if (st_new) {
for (i=0; i<sizeof(aperture_tbl)/sizeof(aperture_tbl[0]); i++) {
if (st_new->lens_min_aperture.nom == aperture_tbl[i])
min_ap = i;
if (st_new->lens_max_aperture.nom == aperture_tbl[i])
max_ap = i;
if (st_new->set_aperture.nom == aperture_tbl[i])
current_ap = i;
}
gtk_range_set_increments(GTK_RANGE(pw), 1.0, 1.0);
if (min_ap >= 0 && max_ap >= 0 && current_ap >= 0) {
//printf("range %f-%f (%f)\n", (float) min_ap, (float)max_ap, (float)current_ap);
gtk_range_set_range(GTK_RANGE(pw), min_ap, max_ap);
gtk_range_set_value(GTK_RANGE(pw), current_ap);
gtk_widget_set_sensitive(pw, TRUE);
}
}
if (disable || min_ap < 0 || max_ap < 0 || current_ap < 0) {
gtk_widget_set_sensitive(pw, FALSE);
} else {
gtk_widget_set_sensitive(pw, TRUE);
}
/* Shutter speed scale */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "shutter_scale"));
if (st_new) {
idx = -1;
pslr_rational_t *tbl = 0;
int steps = 0;
which_shutter_table( st_new, &tbl, &steps );
for (i=0; i<steps; i++) {
if (st_new->set_shutter_speed.nom == tbl[i].nom
&& st_new->set_shutter_speed.denom == tbl[i].denom) {
idx = i;
}
}
if (idx >= 0) {
gtk_range_set_value(GTK_RANGE(pw), idx);
}
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* Bulb */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "bulb_exp_value"));
gtk_widget_set_sensitive(pw, st_new != NULL);
/* ISO scale */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "iso_scale"));
if (st_new) {
const int *tbl = 0;
int steps = 0;
which_iso_table(st_new, &tbl, &steps);
for (i=0; i<steps; i++) {
if (tbl[i] >= st_new->fixed_iso) {
current_iso = i;
break;
}
}
if (current_iso >= 0) {
//printf("set value for ISO slider, new = %d old = %d\n",
// st_new->set_iso, st_old ? st_old->set_iso : -1);
gtk_range_set_value(GTK_RANGE(pw), current_iso);
}
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* EC scale */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "ec_scale"));
if (st_new) {
const int *tbl;
int steps;
which_ec_table( st_new, &tbl, &steps);
idx = -1;
for (i=0; i<steps; i++) {
if (tbl[i] == st_new->ec.nom)
idx = i;
}
if (!st_old || st_old->custom_ev_steps != st_new->custom_ev_steps)
gtk_range_set_range(GTK_RANGE(pw), 0.0, steps-1);
if (!st_old || st_old->ec.nom != st_new->ec.nom
|| st_old->ec.denom != st_new->ec.denom)
gtk_range_set_value(GTK_RANGE(pw), idx);
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* JPEG contrast */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_contrast_scale"));
if (st_new) {
gtk_range_set_value(GTK_RANGE(pw), st_new->jpeg_contrast - get_jpeg_property_shift());
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* JPEG hue */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_hue_scale"));
if (st_new) {
gtk_range_set_value(GTK_RANGE(pw), st_new->jpeg_hue - get_jpeg_property_shift());
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* JPEG saturation */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_saturation_scale"));
if (st_new)
gtk_range_set_value(GTK_RANGE(pw), st_new->jpeg_saturation - get_jpeg_property_shift());
gtk_widget_set_sensitive(pw, st_new != NULL);
/* JPEG sharpness */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_sharpness_scale"));
if (st_new) {
gtk_range_set_value(GTK_RANGE(pw), st_new->jpeg_sharpness - get_jpeg_property_shift());
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* JPEG quality */
pw = GW("jpeg_quality_combo");
if (st_new) {
GtkTreeModel *jpeg_quality_model = gtk_combo_box_get_model(GTK_COMBO_BOX(pw));
gint jpeg_quality_num = gtk_tree_model_iter_n_children( jpeg_quality_model, NULL );
int hw_jpeg_quality = get_hw_jpeg_quality(camhandle, st_new->jpeg_quality);
if( hw_jpeg_quality >= jpeg_quality_num ) {
hw_jpeg_quality = 0;
}
gtk_combo_box_set_active(GTK_COMBO_BOX(pw), hw_jpeg_quality);
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* JPEG resolution */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_resolution_combo"));
if (st_new)
gtk_combo_box_set_active(GTK_COMBO_BOX(pw), st_new->jpeg_resolution);
gtk_widget_set_sensitive(pw, st_new != NULL);
/* Image tone */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "jpeg_image_tone_combo"));
if (st_new ) {
gtk_combo_box_set_active(GTK_COMBO_BOX(pw), st_new->jpeg_image_tone);
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* USER mode selector */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "user_mode_combo"));
if (st_new) {
if (!st_old || st_old->exposure_mode != st_new->exposure_mode) {
gtk_combo_box_set_active(GTK_COMBO_BOX(pw), st_new->exposure_mode);
}
}
gtk_widget_set_sensitive(pw, st_new != NULL && st_new->user_mode_flag);
/* Format selector */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "file_format_combo"));
if (st_new) {
int val = get_user_file_format(st_new);
gtk_combo_box_set_active(GTK_COMBO_BOX(pw), val);
}
gtk_widget_set_sensitive(pw, st_new != NULL);
/* Buttons */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "shutter_button"));
gtk_widget_set_sensitive(pw, st_new != NULL);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "focus_button"));
gtk_widget_set_sensitive(pw, st_new != NULL);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "status_button"));
gtk_widget_set_sensitive(pw, st_new != NULL);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "quick_gimp_button"));
gtk_widget_set_sensitive(pw, st_new != NULL);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "green_button"));
gtk_widget_set_sensitive(pw, st_new != NULL);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "ae_lock_button"));
if (st_new) {
bool lock;
lock = (st_new->light_meter_flags & PSLR_LIGHT_METER_AE_LOCK) != 0;
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pw), lock);
}
gtk_widget_set_sensitive(pw, st_new != NULL);
}
static pslr_status cam_status[2];
static pslr_status *status_new = NULL;
static pslr_status *status_old = NULL;
static gboolean status_poll(gpointer data)
{
GtkWidget *pw;
gchar buf[256];
pslr_status *tmp;
int ret;
static bool status_poll_inhibit = false;
if (status_poll_inhibit)
return TRUE;
/* Do not recursively status poll */
status_poll_inhibit = true;
if (!camhandle) {
camhandle = pslr_init( NULL, NULL );
if (camhandle) {
/* Try to reconnect */
gtk_statusbar_pop(statusbar, sbar_connect_ctx);
gtk_statusbar_push(statusbar, sbar_connect_ctx, "Connecting...");
/* Allow the message to be seen */
while (gtk_events_pending())
gtk_main_iteration();
/* Connect */
pslr_connect(camhandle);
}
gtk_statusbar_pop(statusbar, sbar_connect_ctx);
if (camhandle) {
camera_specific_init();
const char *name;
name = pslr_camera_name(camhandle);
snprintf(buf, sizeof(buf), "Connected: %s", name);
buf[sizeof(buf)-1] = '\0';
gtk_statusbar_push(statusbar, sbar_connect_ctx, buf);
} else {
gtk_statusbar_push(statusbar, sbar_connect_ctx, "No camera connected.");
}
status_poll_inhibit = false;
return TRUE;
}
tmp = status_new;
status_new = status_old;
status_old = tmp;
if (status_new == NULL) {
if (status_old == NULL)
status_new = &cam_status[0];
else
status_new = &cam_status[1];
}
ret = pslr_get_status(camhandle, status_new);
// one time init of camera and status specific fields
shutter_speed_table_init( status_new );
iso_speed_table_init( status_new );
if (ret != PSLR_OK) {
if (ret == PSLR_DEVICE_ERROR) {
/* Camera disconnected */
camhandle = NULL;
}
DPRINT("pslr_get_status: %d\n", ret);
status_new = NULL;
}
/* aperture label */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_aperture"));
if (status_new && status_new->current_aperture.denom) {
float aper = (float)status_new->current_aperture.nom / (float)status_new->current_aperture.denom;
sprintf(buf, "f/%.1f", aper);
gtk_label_set_text(GTK_LABEL(pw), buf);
}
/* shutter speed label */
if (status_new && (status_new->exposure_mode == PSLR_GUI_EXPOSURE_MODE_B)) {
sprintf(buf, "BULB");
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_shutter"));
gtk_label_set_text(GTK_LABEL(pw), buf);
/* inhibit shutter exposure slide */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "shutter_scale"));
gtk_widget_set_visible(pw, FALSE);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label2"));
gtk_widget_set_visible(pw, FALSE);
} else if (status_new && status_new->current_shutter_speed.denom) {
if (status_new->current_shutter_speed.nom == 1) {
sprintf(buf, "1/%ds", status_new->current_shutter_speed.denom);
} else if (status_new->current_shutter_speed.denom == 1) {
sprintf(buf, "%ds", status_new->current_shutter_speed.nom);
} else {
sprintf(buf, "%.1fs", (float)status_new->current_shutter_speed.nom / (float) status_new->current_shutter_speed.denom);
}
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_shutter"));
gtk_label_set_text(GTK_LABEL(pw), buf);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "shutter_scale"));
gtk_widget_set_visible(pw, TRUE);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label2"));
gtk_widget_set_visible(pw, TRUE);
}
/* ISO label */
if (status_new) {
sprintf(buf, "ISO %d", status_new->current_iso);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_iso"));
gtk_label_set_text(GTK_LABEL(pw), buf);
}
/* EV label */
if (status_new && status_new->current_aperture.denom
&& status_new->current_shutter_speed.denom) {
float ev, a, s;
a = (float)status_new->current_aperture.nom/(float)status_new->current_aperture.denom;
s = (float)status_new->current_shutter_speed.nom/(float)status_new->current_shutter_speed.denom;
ev = log(a*a/s)/M_LN2 - log(status_new->current_iso/100)/M_LN2;
sprintf(buf, "<span size=\"xx-large\">EV %.2f</span>", ev);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_ev"));
gtk_label_set_markup(GTK_LABEL(pw), buf);
}
/* Zoom label */
if (status_new && status_new->zoom.denom) {
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_zoom"));
sprintf(buf, "%d mm", status_new->zoom.nom / status_new->zoom.denom);
gtk_label_set_text(GTK_LABEL(pw), buf);
}
/* Focus label */
if (status_new) {
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_focus"));
sprintf(buf, "focus: %d", status_new->focus);
gtk_label_set_text(GTK_LABEL(pw), buf);
}
/* Lens label */
if (status_new) {
pw = GTK_WIDGET (gtk_builder_get_object (xml, "label_lens"));
sprintf(buf, "%s", get_lens_name(status_new->lens_id1, status_new->lens_id2));
gtk_label_set_text(GTK_LABEL(pw), buf);
}
/* Other controls */
init_controls(status_new, status_old);
/* AF point indicators */
pw = GTK_WIDGET (gtk_builder_get_object (xml, "main_drawing_area"));
if (status_new) {
if (!status_old || status_old->focused_af_point != status_new->focused_af_point) {
/* Change in focused AF points */
focus_indicated_af_points |= status_new->focused_af_point;
gdk_window_invalidate_rect(pw->window, &pw->allocation, FALSE);
} else {
/* Same as previous check, stop indicating */
focus_indicated_af_points = 0;
gdk_window_invalidate_rect(pw->window, &pw->allocation, FALSE);
}
if (!status_old || status_old->selected_af_point != status_new->selected_af_point) {
/* Change in selected AF points */
select_indicated_af_points = status_new->selected_af_point;
gdk_window_invalidate_rect(pw->window, &pw->allocation, FALSE);
} else {
/* Same as previous check, stop indicating */
select_indicated_af_points = 0;
gdk_window_invalidate_rect(pw->window, &pw->allocation, FALSE);
}
preselect_indicated_af_points = 0;
preselect_reselect = false;
}
/* Camera buffer checks */
manage_camera_buffers(status_new, status_old);
DPRINT("end poll\n");
status_poll_inhibit = false;
return TRUE;
}
static void manage_camera_buffers(pslr_status *st_new, pslr_status *st_old)
{
uint32_t new_pictures;
bool deleted;
int new_picture;
int format;
int i;
if (!st_new) {
for (i=0; i<MAX_BUFFERS; i++) {
set_preview_icon(i, NULL);
}
return;
}
if (st_old && st_new->bufmask == st_old->bufmask) {
return;
}
if (st_old) {
new_pictures = (st_new->bufmask ^ st_old->bufmask) & st_new->bufmask;
} else {
new_pictures = st_new->bufmask;
}
if (!new_pictures) {
return;
}
/* Show the newest picture in the main area */
for (new_picture=MAX_BUFFERS; new_picture>=0; --new_picture) {
if (new_pictures & (1<<new_picture)) {
break;
}
}
if (new_picture >= 0) {
update_main_area(new_picture);
}
format = get_user_file_format(st_new);
/* auto-save check buffers */
for (i=0; i<MAX_BUFFERS; i++) {
if (new_pictures & (1<<i)) {
deleted = auto_save_check(format, i);
if (deleted) {
new_pictures &= ~(1<<i);
}
}
}
/* Update buffer window for buffers that were not deleted by
* auto_save_check */
for (i=0; i<MAX_BUFFERS; i++) {
if (new_pictures & (1<<i)) {
update_preview_area(i);
}
}
/* Select the new picture in the buffer window */
GtkWidget *pw;
pw = GTK_WIDGET (gtk_builder_get_object (xml, "preview_icon_view"));
GtkTreePath *path;
path = gtk_tree_path_new_from_indices (new_picture, -1);
gtk_icon_view_unselect_all( GTK_ICON_VIEW(pw) );
gtk_icon_view_select_path( GTK_ICON_VIEW(pw), path );
gtk_tree_path_free (path);
}
static void manage_camera_buffers_limited() {
update_main_area(0);
update_preview_area(0);
}
G_MODULE_EXPORT void auto_save_folder_button_clicked_cb(GtkAction *action)
{
GtkWidget *pw;
char *filename;
int res;
pw = GTK_WIDGET (gtk_builder_get_object (xml, "auto_save_folder_dialog"));
res = gtk_dialog_run(GTK_DIALOG(pw));
DPRINT("Run folder dialog -> %d\n", res);
gtk_widget_hide(pw);
if (res == 1) {
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (pw));
DPRINT("Selected path: %s\n", filename);
if (plugin_config.autosave_path)
g_free(plugin_config.autosave_path);
plugin_config.autosave_path = g_strdup(filename);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "auto_folder_entry"));
gtk_entry_set_text(GTK_ENTRY(pw), plugin_config.autosave_path);
} else {
DPRINT("Cancelled.\n");
}
}
G_MODULE_EXPORT void auto_folder_entry_changed_cb(GtkAction *action)
{
GtkEntry *widget = GTK_ENTRY(GW("auto_folder_entry"));
DPRINT("Auto folder changed to %s\n", gtk_entry_get_text(widget));
if (plugin_config.autosave_path)
g_free(plugin_config.autosave_path);
plugin_config.autosave_path = g_strdup(gtk_entry_get_text(widget));
}
static bool auto_save_check(int format, int buffer)
{
GtkWidget *pw;
gboolean autosave;
gboolean autodelete;
const gchar *filebase;
gint counter;
int ret;
GtkSpinButton *spin;
char *old_path = NULL;
GtkProgressBar *pbar;
bool deleted = false;
char filename[256];
pw = GTK_WIDGET (gtk_builder_get_object (xml, "auto_save_check"));
autosave = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pw));
if (!autosave)
return false;
pbar = GTK_PROGRESS_BAR(GTK_WIDGET (gtk_builder_get_object (xml, "download_progress")));
pw = GTK_WIDGET (gtk_builder_get_object (xml, "auto_delete_check"));
autodelete = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pw));
spin = GTK_SPIN_BUTTON(GTK_WIDGET (gtk_builder_get_object (xml, "auto_name_spin")));
counter = gtk_spin_button_get_value_as_int(spin);
DPRINT("Counter = %d\n", counter);
pw = GTK_WIDGET (gtk_builder_get_object (xml, "auto_name_entry"));
filebase = gtk_entry_get_text(GTK_ENTRY(pw));
/* Change to auto-save path */
if (plugin_config.autosave_path) {
old_path = getcwd(NULL, 0);
if (chdir(plugin_config.autosave_path) == -1) {
char msg[256];
snprintf(msg, sizeof(msg), "Could not save in folder %s: %s",
plugin_config.autosave_path, strerror(errno));
error_message(msg);
free(old_path);
return false;
}
}
gtk_statusbar_push(statusbar, sbar_download_ctx, "Auto-saving");
while (gtk_events_pending())
gtk_main_iteration();
snprintf(filename, sizeof(filename), "%s%04d.%s", filebase, counter, file_formats[format].extension);
DPRINT("Save buffer %d\n", buffer);
gtk_progress_bar_set_text(pbar, filename);
save_buffer(buffer, filename);
gtk_progress_bar_set_text(pbar, NULL);
if (autodelete) {
int retry;
pslr_status st;
/* Init bufmask to 1's so that we don't see buffer as deleted
* if we never got a good status. */
st.bufmask = ~0;
DPRINT("Delete buffer %d\n", buffer);
for (retry = 0; retry < 5; retry++) {
ret = pslr_delete_buffer(camhandle, buffer);
if (ret == PSLR_OK)
break;
DPRINT("Could not delete buffer %d: %d\n", buffer, ret);
usleep(100000);
}
for (retry=0; retry<5; retry++) {
pslr_get_status(camhandle, &st);
if ((st.bufmask & (1<<buffer))==0)
break;
DPRINT("Buffer not gone - wait\n");
}
set_preview_icon(buffer, NULL);
if ((st.bufmask & (1<<buffer)) == 0) {
deleted = true;
}
}
counter++;
DPRINT("Set counter -> %d\n", counter);
gtk_spin_button_set_value(spin, counter);
if (old_path) {
chdir(old_path);
free(old_path);
}
gtk_statusbar_pop(statusbar, sbar_download_ctx);
//printf("auto_save_check done\n");
return deleted;
}
bool buf_updated = false;
GdkPixbuf *pMainPixbuf = NULL;
//static GdkPixbuf *pThumbPixbuf[MAX_BUFFERS];
static void update_main_area(int buffer)
{
GError *pError;