exposurses

Check-in [7312ab2b6f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add under/over exposure indication in to the shutter/aperture menus Keeping the NULLs in makes array indices very confusing, but this seems to be the right thing to do.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 7312ab2b6fc9fee492c9f7e8ed50abeef074a5051e38a8a3c9d5674f837df4f4
User & Date: base@atomicules.co.uk 2013-09-18 12:48:35
Context
2013-09-18
12:49
Ignore selection of OVER/UNDER in shutter/aperture menus Since this seems easier than trying to prevent selection. check-in: 4cc8e33f3c user: base@atomicules.co.uk tags: origin/master, trunk
12:48
Add under/over exposure indication in to the shutter/aperture menus Keeping the NULLs in makes array indices very confusing, but this seems to be the right thing to do. check-in: 7312ab2b6f user: base@atomicules.co.uk tags: origin/master, trunk
11:01
Fix menu numbering (from adding exposure menu in) Didn't change functionality (it was still working), but just gives better consistency to the code. check-in: 4a3cabadc2 user: base@atomicules.co.uk tags: origin/master, trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to exposurses.c.

    27     27   	"9",		
    28     28   	"10",		
    29     29   	"11",		
    30     30   	"12",		
    31     31   	"13",		
    32     32   	"14",		
    33     33   	"15",		
    34         -	"16",		
           34  +	"16",
    35     35   	NULL
    36     36   };
    37     37   
    38     38   char *iso_array[] = {
    39     39   	"50",
    40     40   	"100",
    41     41   	"200",
................................................................................
    43     43   	"800",
    44     44   	"1600",
    45     45   	"3200",
    46     46   	NULL
    47     47   };
    48     48   
    49     49   char *shutter_array[] = {
           50  +	"OVER",
    50     51   	"1/1000",
    51     52   	"1/500",
    52     53   	"1/250",
    53     54   	"1/125",
    54     55   	"1/60",
    55     56   	"1/30",
    56     57   	"1/15",
    57     58   	"1/8",
    58     59   	"1/4",
    59     60   	"1/2",
    60     61   	"1",
           62  +	"UNDER",
    61     63   	NULL
    62     64   };
    63     65   
    64     66   char *aperture_array[] = {
           67  +	"UNDER",
    65     68   	"f/1.4",
    66     69   	"f/2",
    67     70   	"f/2.8",
    68     71   	"f/4",
    69     72   	"f/5.6",
    70     73   	"f/8",
    71     74   	"f/11",
    72     75   	"f/16",
           76  +	"OVER",
    73     77   	NULL
    74     78   };
    75     79   
    76     80   ITEM **exposure_items;
    77     81   ITEM **iso_items;
    78     82   ITEM **shutter_items;
    79     83   ITEM **aperture_items;
................................................................................
    90     94   void remove_menu(ITEM **items, MENU *men, int n);
    91     95   void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
    92     96   MENU *add_menu(char **array, ITEM **items, int n);
    93     97   WINDOW *add_window(int xpos, char *title);
    94     98   int exposure(int iso);
    95     99   double shutter(int exposure, double aperture);
    96    100   double aperture(int exposure, double shutter);
    97         -int nearest_match(double x, int menu);
          101  +int nearest_match(double x, int menu, int n_array);
    98    102   double fraction_to_double(char *fraction);
    99    103   /* No one will ever need more than 9 bytes! */
   100    104   char exposure_sel[9] = "";
   101    105   char iso_sel[9] = "";
   102    106   char shutter_sel[9] = "";
   103    107   char aperture_sel[9] = "";
   104    108   int selection_counter = 1;
................................................................................
   228    232   							menu_driver(shutter_menu, REQ_SCR_UPAGE);
   229    233   							menu_driver(shutter_menu, REQ_SCR_DPAGE);
   230    234   							/* There is probably a nicer way to format the below */
   231    235   							set_menu_pattern(
   232    236   								shutter_menu,
   233    237   								shutter_array[nearest_match(
   234    238   									shutter(exposure(atoi(iso_sel)), strtod(aperture_sel_, NULL)),
   235         -									3
          239  +									3,
          240  +									n_shutter
   236    241   								)]
   237    242   							);
   238    243   							menu_driver(shutter_menu, REQ_DOWN_ITEM);
   239    244   							menu_driver(shutter_menu, REQ_UP_ITEM);
   240    245   							wrefresh(shutter_win);
   241    246   						}
   242    247   						if (strcmp("", aperture_sel) == 0) {
   243    248   							menu_driver(aperture_menu, REQ_SCR_UPAGE);
   244    249   							menu_driver(aperture_menu, REQ_SCR_DPAGE);
   245    250   							set_menu_pattern(
   246    251   								aperture_menu,
   247    252   								aperture_array[nearest_match(
   248    253   									aperture(exposure(atoi(iso_sel)), fraction_to_double(shutter_sel)),
   249         -									4
          254  +									4,
          255  +									n_aperture
   250    256   								)]
   251    257   							);
   252    258   							menu_driver(aperture_menu, REQ_DOWN_ITEM);
   253    259   							menu_driver(aperture_menu, REQ_UP_ITEM);
   254    260   							wrefresh(aperture_win);
   255    261   						}
   256    262   						/* clear the selections for next time */
................................................................................
   371    377   }
   372    378   
   373    379   double aperture (int exposure, double shutter) {
   374    380   	/* EV = log2 (N^2/t) */
   375    381   	return sqrt(pow(2, exposure) * shutter);
   376    382   }
   377    383   
   378         -int nearest_match (double x, int menu) {
          384  +int nearest_match (double x, int menu, int n_array) {
   379    385   	/* Need to search array for closest match */
   380    386   	int n;
   381         -	int diff_idx = 0;
          387  +	int diff_idx = 1;
   382    388   	char array_value_str[9];
   383    389   	double array_value_db;
   384    390   	double diff;
   385    391   
   386    392   	/* Need a starting value for difference */
   387    393   	switch(menu) {
   388    394   		case 3:
   389         -			array_value_db = fraction_to_double(shutter_array[0]);
          395  +			array_value_db = fraction_to_double(shutter_array[1]);
   390    396   			break;
   391    397   		case 4:
   392         -			strncpy(array_value_str, aperture_array[0]+2, 4);
          398  +			strncpy(array_value_str, aperture_array[1]+2, 4);
   393    399   			array_value_db = strtod(array_value_str, NULL);
   394    400   			break;
   395    401   	}
   396    402   	diff = fabs(array_value_db - x);
   397    403   	/* lots of repetition here but pointers to arrays seem to be a bad thing */
          404  +	/* Could do from n = 3 (2 above) until != under/over
          405  +	 * but also need to do something like if diff is more than twice max/min then under/over */
   398    406   	switch(menu) {
   399    407   		case 3:
   400         -			for ( n = 1; shutter_array[n] != NULL; ++n ) {
          408  +			for ( n = 2; n < n_array-2; ++n ) {
   401    409   				array_value_db = fraction_to_double(shutter_array[n]);
   402    410   				if (fabs(array_value_db - x) < diff) {
   403    411   					diff_idx = n;
   404    412   					diff = fabs(array_value_db - x);
   405    413   				}
          414  +			}
          415  +			/* Check if at extremities and then if under/over exposed */
          416  +			if (diff_idx == 1) {
          417  +				if (diff >= fraction_to_double(shutter_array[1])/2) { /* diff is greater than diff of next one down minus max/min */
          418  +					diff_idx = 0;
          419  +				}
          420  +			}
          421  +			if (diff_idx == n_array-3) {
          422  +				if (diff >= fraction_to_double(shutter_array[n_array-3])*2) {
          423  +					diff_idx = n_array-2;	
          424  +				}
   406    425   			}
   407    426   			break;
   408    427   		case 4:
   409         -			for ( n = 1; aperture_array[n] != NULL; ++n ) {
          428  +			for ( n = 2; n < n_array-2; ++n ) {
   410    429   				strncpy(array_value_str, aperture_array[n]+2, 4);
   411    430   				array_value_db = strtod(array_value_str, NULL);
   412    431   				if (fabs(array_value_db - x) < diff) { 
   413    432   					diff_idx = n;
   414    433   					diff = fabs(array_value_db - x);
   415    434   				}
   416    435   			}
          436  +			/* Apertures similarly. Although progression is fiddlier.*/
          437  +			if (diff_idx == 1) {
          438  +				strncpy(array_value_str, aperture_array[1]+2, 4);
          439  +				array_value_db = strtod(array_value_str, NULL);
          440  +				if (diff >= array_value_db/sqrt(2.0)) { /* diff is greater than diff of next one down minus max/min */
          441  +					diff_idx = 0;
          442  +				}
          443  +			}
          444  +			if (diff_idx == n_array-3) {
          445  +				strncpy(array_value_str, aperture_array[n_array-3]+2, 4);
          446  +				array_value_db = strtod(array_value_str, NULL);
          447  +				if (diff >= array_value_db*sqrt(2.0)) {
          448  +					diff_idx = n_array-2;	
          449  +				}
          450  +			}
          451  +
   417    452   			break;
   418    453   	}
   419    454   	return diff_idx;
   420    455   }
   421    456   
   422    457   double fraction_to_double(char *fraction) {
   423    458   	double fraction_as_db;