exposurses

Check-in [845d8653eb]
Login

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

Overview
Comment:Implement exposure equations and matching for Aperture menu

Also: More evidence I am in a continual half-daze

- Need to define shutter value as double in `aperture` as otherwise both
arguments will be integers and I'm guessing it'd not going to work out
well. Plus... need to use `fraction_to_double` anyway to feed the
value in.
- Had done the "substring" thing wrong in `strncpy` and was one decimal
place off in getting the paerture value. I.e. would have got "1."
instead of "1.4" from "f/1.4"
- Like the fool I am, in the loop and the copy and paste I'd done, I'd
not changed from `aperture_array[0]` to `aperture_array[n]`

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 845d8653eb0ee84fea90f0555b9c8341900615bdba99c82047d7d836d4bf287f
User & Date: base@atomicules.co.uk 2013-09-02 10:20:03
Context
2013-09-02
13:27
Enable exit key, change help text to suit check-in: 2dc1212485 user: base@atomicules.co.uk tags: origin/master, trunk
10:20
Implement exposure equations and matching for Aperture menu

Also: More evidence I am in a continual half-daze

- Need to define shutter value as double in `aperture` as otherwise both
arguments will be integers and I'm guessing it'd not going to work out
well. Plus... need to use `fraction_to_double` anyway to feed the
value in.
- Had done the "substring" thing wrong in `strncpy` and was one decimal
place off in getting the paerture value. I.e. would have got "1."
instead of "1.4" from "f/1.4"
- Like the fool I am, in the loop and the copy and paste I'd done, I'd
not changed from `aperture_array[0]` to `aperture_array[n]` check-in: 845d8653eb user: base@atomicules.co.uk tags: origin/master, trunk

09:47
I am King of Fail

I mean, just how? I think I need a few years more sleep or something check-in: 506ba48833 user: base@atomicules.co.uk tags: origin/master, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to exposurses.c.

56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
WINDOW *aperture_win;

void selection(char *name);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
int exposure(int iso);
int selection_counter;
double shutter(int exposure, double aperture);
double aperture(int exposure, int shutter);
int nearest_match(double x, int menu);
double fraction_to_double(char *fraction);
/* No one will ever need more than 9 bytes! */
char iso_sel[9] = "";
char shutter_sel[9] = "";
char aperture_sel[9] = "";
int menu_counter = 1;







|







56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
WINDOW *aperture_win;

void selection(char *name);
void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string, chtype color);
int exposure(int iso);
int selection_counter;
double shutter(int exposure, double aperture);
double aperture(int exposure, double shutter);
int nearest_match(double x, int menu);
double fraction_to_double(char *fraction);
/* No one will ever need more than 9 bytes! */
char iso_sel[9] = "";
char shutter_sel[9] = "";
char aperture_sel[9] = "";
int menu_counter = 1;
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
						set_menu_pattern(iso_menu, "200");
						/* Using menu_driver to go up/down to force refresh */
						menu_driver(iso_menu, REQ_DOWN_ITEM);
						menu_driver(iso_menu, REQ_UP_ITEM);
						wrefresh(iso_win);
					}
					if (strcmp("", shutter_sel) == 0) {
						/* Test finding nearest matching value in array? */
						char aperture_sel_[4] = "";
						strncpy(aperture_sel_, aperture_sel+2, 3);
						/* There is probably a nicer way to format the below */
						set_menu_pattern(
							shutter_menu,
							shutter_array[nearest_match(
								shutter(exposure(atoi(iso_sel)), strtod(aperture_sel_, NULL)),
								2
							)]
						);
						menu_driver(shutter_menu, REQ_DOWN_ITEM);
						menu_driver(shutter_menu, REQ_UP_ITEM);
						wrefresh(shutter_win);
					}
					if (strcmp("", aperture_sel) == 0) {
						/* Tests setting to row number */
						set_top_row(aperture_menu, 3);





						menu_driver(aperture_menu, REQ_DOWN_ITEM);
						menu_driver(aperture_menu, REQ_UP_ITEM);
						wrefresh(aperture_win);
					}
					/* clear the selections for next time */
					selection_counter = 0;
					strcpy(iso_sel, "");







<















|
|
>
>
>
>
>







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
						set_menu_pattern(iso_menu, "200");
						/* Using menu_driver to go up/down to force refresh */
						menu_driver(iso_menu, REQ_DOWN_ITEM);
						menu_driver(iso_menu, REQ_UP_ITEM);
						wrefresh(iso_win);
					}
					if (strcmp("", shutter_sel) == 0) {

						char aperture_sel_[4] = "";
						strncpy(aperture_sel_, aperture_sel+2, 3);
						/* There is probably a nicer way to format the below */
						set_menu_pattern(
							shutter_menu,
							shutter_array[nearest_match(
								shutter(exposure(atoi(iso_sel)), strtod(aperture_sel_, NULL)),
								2
							)]
						);
						menu_driver(shutter_menu, REQ_DOWN_ITEM);
						menu_driver(shutter_menu, REQ_UP_ITEM);
						wrefresh(shutter_win);
					}
					if (strcmp("", aperture_sel) == 0) {
						set_menu_pattern(
							aperture_menu,
							aperture_array[nearest_match(
								aperture(exposure(atoi(iso_sel)), fraction_to_double(shutter_sel)),
								3
							)]
						);
						menu_driver(aperture_menu, REQ_DOWN_ITEM);
						menu_driver(aperture_menu, REQ_UP_ITEM);
						wrefresh(aperture_win);
					}
					/* clear the selections for next time */
					selection_counter = 0;
					strcpy(iso_sel, "");
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
}

double shutter (int exposure, double aperture) {
	/* EV = log2 (N^2/t) */
	return pow(aperture, 2) / pow(2, exposure);
}

double aperture (int exposure, int shutter) {
	/* EV = log2 (N^2/t) */
	return sqrt(pow(2, exposure) * shutter);
}

int nearest_match (double x, int menu) {
	/* Need to search array for closest match */
	int n;







|







339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
}

double shutter (int exposure, double aperture) {
	/* EV = log2 (N^2/t) */
	return pow(aperture, 2) / pow(2, exposure);
}

double aperture (int exposure, double shutter) {
	/* EV = log2 (N^2/t) */
	return sqrt(pow(2, exposure) * shutter);
}

int nearest_match (double x, int menu) {
	/* Need to search array for closest match */
	int n;
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
		case 1:
			array_value_db = strtod(iso_array[0], NULL);
			break;
		case 2:
			array_value_db = fraction_to_double(shutter_array[0]);
			break;
		case 3:
			strncpy(array_value_str, aperture_array[0]+2, 3);
			array_value_db = strtod(array_value_str, NULL);
			break;
	}
	diff = fabs(array_value_db - x);
	/* lots of repetition here but pointers to arrays seem to be a bad thing */
	switch(menu) {
		case 1:







|







361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
		case 1:
			array_value_db = strtod(iso_array[0], NULL);
			break;
		case 2:
			array_value_db = fraction_to_double(shutter_array[0]);
			break;
		case 3:
			strncpy(array_value_str, aperture_array[0]+2, 4);
			array_value_db = strtod(array_value_str, NULL);
			break;
	}
	diff = fabs(array_value_db - x);
	/* lots of repetition here but pointers to arrays seem to be a bad thing */
	switch(menu) {
		case 1:
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
					diff_idx = n;
					diff = fabs(array_value_db - x);
				}
			}
			break;
		case 3:
			for ( n = 1; aperture_array[n] != NULL; ++n ) {
				strncpy(array_value_str, aperture_array[0]+2, 3);
				array_value_db = strtod(array_value_str, NULL);
				if (fabs(array_value_db - x) < diff) { 
					diff_idx = n;
					diff = fabs(array_value_db - x);
				}
			}
			break;







|







388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
					diff_idx = n;
					diff = fabs(array_value_db - x);
				}
			}
			break;
		case 3:
			for ( n = 1; aperture_array[n] != NULL; ++n ) {
				strncpy(array_value_str, aperture_array[n]+2, 4);
				array_value_db = strtod(array_value_str, NULL);
				if (fabs(array_value_db - x) < diff) { 
					diff_idx = n;
					diff = fabs(array_value_db - x);
				}
			}
			break;