Skip to content

Commit

Permalink
expand image info display
Browse files Browse the repository at this point in the history
  - white balance
  - flash
  - exposure program
  - metering mode

fix SQL error

recreate view v_images
  • Loading branch information
zisoft committed Mar 15, 2024
1 parent 3a244e3 commit 291065e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 3 deletions.
27 changes: 25 additions & 2 deletions src/common/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -2754,12 +2754,35 @@ static int _upgrade_library_schema_step(dt_database_t *db, int version)
" FROM images",
"[init] can't populate new images table\n");

// NOTE: datetime_taken is in nano-second since "0001-01-01 00:00:00"
TRY_EXEC("DROP VIEW v_images",
"[init] can't drop v_images view\n");

TRY_EXEC("DROP TABLE images",
"[init] can't drop table images\n");

TRY_EXEC("ALTER TABLE images_new RENAME TO images",
"[init] can't rename images\n");

TRY_EXEC
("CREATE VIEW v_images AS"
" SELECT mi.id AS id, mk.name AS maker, md.name AS model, ln.name AS lens,"
" cm.maker || ' ' || cm.model AS normalized_camera, "
" cm.alias AS camera_alias,"
" exposure, aperture, iso,"
" datetime(datetime_taken/1000000"
" + unixepoch('0001-01-01 00:00:00'), 'unixepoch') AS datetime,"
" fr.folder AS folders, filename"
" FROM images AS mi,"
" makers AS mk, models AS md, lens AS ln, cameras AS cm, film_rolls AS fr"
" WHERE mi.maker_id = mk.id"
" AND mi.model_id = md.id"
" AND mi.lens_id = ln.id"
" AND mi.camera_id = cm.id"
" AND mi.film_id = fr.id"
" ORDER BY normalized_camera, folders",
"[init] can't create view v_images\n");

// recreate the indexesx
TRY_EXEC("CREATE INDEX image_position_index ON images (position)",
"[init] can't add image_position_index\n");
Expand Down Expand Up @@ -3193,11 +3216,11 @@ static void _create_library_schema(dt_database_t *db)
"FOREIGN KEY(lens_id) REFERENCES lens(id) ON DELETE CASCADE ON UPDATE CASCADE, "
"FOREIGN KEY(camera_id) REFERENCES cameras(id) ON DELETE CASCADE ON UPDATE CASCADE, "
"FOREIGN KEY(film_id) REFERENCES film_rolls(id) ON DELETE CASCADE ON UPDATE CASCADE, "
"FOREIGN KEY(group_id) REFERENCES images(id) ON DELETE RESTRICT ON UPDATE CASCADE), "
"FOREIGN KEY(group_id) REFERENCES images(id) ON DELETE RESTRICT ON UPDATE CASCADE, "
"FOREIGN KEY(whitebalance_id) REFERENCES whitebalance(id) ON DELETE CASCADE ON UPDATE CASCADE, "
"FOREIGN KEY(flash_id) REFERENCES flash(id) ON DELETE CASCADE ON UPDATE CASCADE, "
"FOREIGN KEY(exposure_program_id) REFERENCES exposure_program(id) ON DELETE CASCADE ON UPDATE CASCADE, "
"FOREIGN KEY(metering_mode_id) REFERENCES metering_mode(id) ON DELETE CASCADE ON UPDATE CASCADE",
"FOREIGN KEY(metering_mode_id) REFERENCES metering_mode(id) ON DELETE CASCADE ON UPDATE CASCADE)",
NULL, NULL, NULL);
sqlite3_exec(db->handle,
"CREATE INDEX main.images_group_id_index ON images (group_id, id)",
Expand Down
16 changes: 15 additions & 1 deletion src/common/image_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ static void _image_cache_allocate(void *data,
" longitude, latitude, altitude, color_matrix, colorspace, version,"
" raw_black, raw_maximum, aspect_ratio, exposure_bias,"
" import_timestamp, change_timestamp, export_timestamp, print_timestamp,"
" output_width, output_height, cm.maker, cm.model, cm.alias"
" output_width, output_height, cm.maker, cm.model, cm.alias,"
" wb.name, fl.name, ep.name, mm.name"
" FROM main.images AS mi"
" LEFT JOIN main.cameras AS cm ON cm.id = mi.camera_id"
" LEFT JOIN main.makers AS mk ON mk.id = mi.maker_id"
" LEFT JOIN main.models AS md ON md.id = mi.model_id"
" LEFT JOIN main.lens AS ln ON ln.id = mi.lens_id"
" LEFT JOIN main.whitebalance AS wb ON wb.id = mi.whitebalance_id"
" LEFT JOIN main.flash AS fl ON fl.id = mi.flash_id"
" LEFT JOIN main.exposure_program AS ep ON ep.id = mi.exposure_program_id"
" LEFT JOIN main.metering_mode AS mm ON mm.id = mi.metering_mode_id"
" WHERE mi.id = ?1",
-1, &stmt, NULL);
// clang-format on
Expand Down Expand Up @@ -140,6 +145,15 @@ static void _image_cache_allocate(void *data,
str = (char *)sqlite3_column_text(stmt, 37);
if(str) g_strlcpy(img->camera_alias, str, sizeof(img->camera_alias));

str = (char *)sqlite3_column_text(stmt, 38);
if(str) g_strlcpy(img->exif_whitebalance, str, sizeof(img->exif_whitebalance));
str = (char *)sqlite3_column_text(stmt, 39);
if(str) g_strlcpy(img->exif_flash, str, sizeof(img->exif_flash));
str = (char *)sqlite3_column_text(stmt, 40);
if(str) g_strlcpy(img->exif_exposure_program, str, sizeof(img->exif_exposure_program));
str = (char *)sqlite3_column_text(stmt, 41);
if(str) g_strlcpy(img->exif_metering_mode, str, sizeof(img->exif_metering_mode));

dt_color_harmony_get(entry->key, &img->color_harmony_guide);

// buffer size? colorspace?
Expand Down
28 changes: 28 additions & 0 deletions src/libs/metadata_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ enum
md_exif_aperture,
md_exif_exposure,
md_exif_exposure_bias,
md_exif_exposure_program,
md_exif_whitebalance,
md_exif_flash,
md_exif_metering_mode,
md_exif_focal_length,
md_exif_focal_length_ff,
md_exif_crop_factor,
Expand Down Expand Up @@ -142,6 +146,10 @@ static const char *_labels[] = {
N_("aperture"),
N_("exposure"),
N_("exposure bias"),
N_("exposure program"),
N_("white balance"),
N_("flash"),
N_("metering mode"),
N_("focal length"),
N_("35mm equiv focal length"),
N_("crop factor"),
Expand Down Expand Up @@ -528,6 +536,10 @@ void gui_update(dt_lib_module_t *self)
"COUNT(DISTINCT aperture), "
"COUNT(DISTINCT exposure), "
"COUNT(DISTINCT IFNULL(exposure_bias, '')), "
"COUNT(DISTINCT IFNULL(exposure_program_id, '')), "
"COUNT(DISTINCT IFNULL(whitebalance_id, '')), "
"COUNT(DISTINCT IFNULL(flash_id, '')), "
"COUNT(DISTINCT IFNULL(metering_mode_id, '')), "
"COUNT(DISTINCT focal_length), "
"COUNT(DISTINCT focus_distance), "
"COUNT(DISTINCT iso), "
Expand Down Expand Up @@ -733,6 +745,22 @@ void gui_update(dt_lib_module_t *self)
_metadata_update_value(md_exif_exposure_bias, text, self);
break;

case md_exif_exposure_program:
_metadata_update_value(md_exif_exposure_program, img->exif_exposure_program, self);
break;

case md_exif_whitebalance:
_metadata_update_value(md_exif_whitebalance, img->exif_whitebalance, self);
break;

case md_exif_flash:
_metadata_update_value(md_exif_flash, img->exif_flash, self);
break;

case md_exif_metering_mode:
_metadata_update_value(md_exif_metering_mode, img->exif_metering_mode, self);
break;

case md_exif_focal_length:
(void)g_snprintf(text, sizeof(text), _("%.1f mm"), (double)img->exif_focal_length);
_metadata_update_value(md_exif_focal_length, text, self);
Expand Down

0 comments on commit 291065e

Please sign in to comment.