From a505d9806075682aeda990a62aabf3f65f336b77 Mon Sep 17 00:00:00 2001 From: Dennis Gnad Date: Fri, 28 Dec 2012 04:20:58 +0100 Subject: [PATCH] When importing images, try to prevent having a jpg/jpeg as representative of automatically generated groups --- src/common/image.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/common/image.c b/src/common/image.c index 43c68b9..af7b3a4 100644 --- a/src/common/image.c +++ b/src/common/image.c @@ -481,7 +481,21 @@ uint32_t dt_image_import(const int32_t film_id, const char *filename, gboolean o DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, sql_pattern, -1, SQLITE_TRANSIENT); DT_DEBUG_SQLITE3_BIND_INT(stmt, 3, id); int group_id; - if(sqlite3_step(stmt) == SQLITE_ROW) group_id = sqlite3_column_int(stmt, 0); + // set to new representative in case we are not a jpg + // this prevents jpgs from being representatives if there exist other files + if(strcmp(ext, "jpg") != 0 && strcmp(ext, "jpeg") != 0) { + while(sqlite3_step(stmt) == SQLITE_ROW) + { + int other_id = sqlite3_column_int(stmt, 0); + const dt_image_t *cother_img = dt_image_cache_read_get(darktable.image_cache, other_id); + dt_image_t *other_img = dt_image_cache_write_get(darktable.image_cache, cother_img); + other_img->group_id = id; + dt_image_cache_write_release(darktable.image_cache, other_img, DT_IMAGE_CACHE_SAFE); + dt_image_cache_read_release(darktable.image_cache, cother_img); + } + group_id = id; + } + else if(sqlite3_step(stmt) == SQLITE_ROW) group_id = sqlite3_column_int(stmt, 0); else group_id = id; sqlite3_finalize(stmt); DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "update images set group_id = ?1 where id = ?2", -1, &stmt, NULL); -- 1.7.10.4