// This is basically the same as dt_image_remove() from common/image.c.
// It just does the iteration over all images in the SQL statement
void dt_film_remove(const int id)
{
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"update tagxtag set count = count - 1 where "
"(id2 in (select tagid from tagged_images where imgid in "
"(select id from images where film_id = ?1))) or (id1 in "
"(select tagid from tagged_images where imgid in "
"(select id from images where film_id = ?1)))", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from tagged_images where imgid in "
"(select id from images where film_id = ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from history where imgid in "
"(select id from images where film_id = ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from color_labels where imgid in "
"(select id from images where film_id = ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from meta_data where id in "
"(select id from images where film_id = ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from selected_images where imgid in "
"(select id from images where film_id = ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from images where film_id = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
while(sqlite3_step(stmt) == SQLITE_ROW)
{
const uint32_t imgid = sqlite3_column_int(stmt, 0);
dt_mipmap_cache_remove(darktable.mipmap_cache, imgid);
dt_image_cache_remove (darktable.image_cache, imgid);
}
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from images where id in "
"(select id from images where film_id = ?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"delete from film_rolls where id = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
// dt_control_update_recent_films();
dt_control_signal_raise(darktable.signals , DT_SIGNAL_FILMROLLS_CHANGED);
}
void dt_styles_apply_to_image(const char *name, gboolean duplicate, int32_t imgid)
{
int id = 0;
sqlite3_stmt *stmt;
int32_t newimgid;
if((id = dt_styles_get_id_by_name(name)) != 0)
{
/* check if we should make a duplicate before applying style */
if(duplicate)
{
newimgid = dt_image_duplicate(imgid);
if(newimgid != -1) dt_history_copy_and_paste_on_image(imgid, newimgid, FALSE, NULL);
}
else
newimgid = imgid;
/* merge onto history stack, let's find history offest in destination image */
/* first trim the stack to get rid of whatever is above the selected entry */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"DELETE FROM main.history WHERE imgid = ?1 AND num >= (SELECT history_end "
"FROM main.images WHERE id = imgid)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newimgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
/* in sqlite ROWID starts at 1, while our num column starts at 0 */
int32_t offs = -1;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"SELECT IFNULL(MAX(num), -1) FROM main.history WHERE imgid = ?1", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newimgid);
if(sqlite3_step(stmt) == SQLITE_ROW) offs = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
/* delete all items from the temp styles_items, this table is used only to get a ROWNUM of the results */
DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "DELETE FROM memory.style_items", NULL, NULL, NULL);
/* copy history items from styles onto temp table */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "INSERT INTO memory.style_items SELECT * FROM "
"data.style_items WHERE styleid=?1 ORDER BY "
"multi_priority DESC",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
/* copy the style items into the history */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"INSERT INTO main.history "
"(imgid,num,module,operation,op_params,enabled,blendop_params,blendop_"
"version,multi_priority,multi_name) SELECT "
"?1,?2+rowid,module,operation,op_params,enabled,blendop_params,blendop_"
"version,multi_priority,multi_name FROM memory.style_items",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newimgid);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, offs);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
/* always make the whole stack active */
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"UPDATE main.images SET history_end = (SELECT MAX(num) + 1 FROM main.history "
"WHERE imgid = ?1) WHERE id = ?1",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, newimgid);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
/* add tag */
guint tagid = 0;
gchar ntag[512] = { 0 };
g_snprintf(ntag, sizeof(ntag), "darktable|style|%s", name);
if(dt_tag_new(ntag, &tagid)) dt_tag_attach(tagid, newimgid);
if(dt_tag_new("darktable|changed", &tagid)) dt_tag_attach(tagid, newimgid);
/* if current image in develop reload history */
if(dt_dev_is_current_image(darktable.develop, newimgid))
{
dt_dev_reload_history_items(darktable.develop);
dt_dev_modulegroups_set(darktable.develop, dt_dev_modulegroups_get(darktable.develop));
}
/* update xmp file */
dt_image_synch_xmp(newimgid);
/* remove old obsolete thumbnails */
dt_mipmap_cache_remove(darktable.mipmap_cache, newimgid);
/* if we have created a duplicate, reset collected images */
if(duplicate) dt_control_signal_raise(darktable.signals, DT_SIGNAL_COLLECTION_CHANGED);
/* redraw center view to update visible mipmaps */
dt_control_queue_redraw_center();
}
}
void dt_film_import1(dt_film_t *film)
{
gboolean recursive = dt_conf_get_bool("ui_last/import_recursive");
/* first of all gather all images to import */
GList *images = NULL;
images = _film_recursive_get_files(film->dirname, recursive, &images);
if(g_list_length(images) == 0)
{
dt_control_log(_("no supported images were found to be imported"));
return;
}
/* we got ourself a list of images, lets sort and start import */
images = g_list_sort(images,(GCompareFunc)_film_filename_cmp);
/* let's start import of images */
gchar message[512] = {0};
double fraction = 0;
uint32_t total = g_list_length(images);
g_snprintf(message, sizeof(message) - 1,
ngettext("importing %d image","importing %d images", total), total);
const guint *jid = dt_control_backgroundjobs_create(darktable.control, 0, message);
/* loop thru the images and import to current film roll */
dt_film_t *cfr = film;
GList *image = g_list_first(images);
do
{
gchar *cdn = g_path_get_dirname((const gchar *)image->data);
/* check if we need to initialize a new filmroll */
if(!cfr || g_strcmp0(cfr->dirname, cdn) != 0)
{
#if GLIB_CHECK_VERSION (2, 26, 0)
if(cfr && cfr->dir)
{
/* check if we can find a gpx data file to be auto applied
to images in the jsut imported filmroll */
g_dir_rewind(cfr->dir);
const gchar *dfn = NULL;
while ((dfn = g_dir_read_name(cfr->dir)) != NULL)
{
/* check if we have a gpx to be auto applied to filmroll */
if(strcmp(dfn+strlen(dfn)-4,".gpx") == 0 ||
strcmp(dfn+strlen(dfn)-4,".GPX") == 0)
{
gchar *gpx_file = g_build_path (G_DIR_SEPARATOR_S, cfr->dirname, dfn, NULL);
dt_control_gpx_apply(gpx_file, cfr->id, dt_conf_get_string("plugins/lighttable/geotagging/tz"));
g_free(gpx_file);
}
}
}
#endif
/* cleanup previously imported filmroll*/
if(cfr && cfr!=film)
{
if(dt_film_is_empty(cfr->id))
{
dt_film_remove(cfr->id);
}
dt_film_cleanup(cfr);
g_free(cfr);
cfr = NULL;
}
/* initialize and create a new film to import to */
cfr = g_malloc(sizeof(dt_film_t));
dt_film_init(cfr);
dt_film_new(cfr, cdn);
}
/* import image */
dt_image_import(cfr->id, (const gchar *)image->data, FALSE);
fraction+=1.0/total;
dt_control_backgroundjobs_progress(darktable.control, jid, fraction);
}
while( (image = g_list_next(image)) != NULL);
// only redraw at the end, to not spam the cpu with exposure events
dt_control_queue_redraw_center();
dt_control_signal_raise(darktable.signals,DT_SIGNAL_TAG_CHANGED);
dt_control_backgroundjobs_destroy(darktable.control, jid);
dt_control_signal_raise(darktable.signals , DT_SIGNAL_FILMROLLS_IMPORTED,film->id);
#if GLIB_CHECK_VERSION (2, 26, 0)
if(cfr && cfr->dir)
{
/* check if we can find a gpx data file to be auto applied
to images in the just imported filmroll */
g_dir_rewind(cfr->dir);
const gchar *dfn = NULL;
while ((dfn = g_dir_read_name(cfr->dir)) != NULL)
{
/* check if we have a gpx to be auto applied to filmroll */
//.........这里部分代码省略.........
// This is basically the same as dt_image_remove() from common/image.c.
// It just does the iteration over all images in the SQL statement
void dt_film_remove(const int id)
{
// only allowed if local copies have their original accessible
sqlite3_stmt *stmt;
gboolean remove_ok = TRUE;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id FROM main.images WHERE film_id = ?1", -1,
&stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
while(sqlite3_step(stmt) == SQLITE_ROW)
{
int imgid = sqlite3_column_int(stmt, 0);
if(!dt_image_safe_remove(imgid))
{
remove_ok = FALSE;
break;
}
}
sqlite3_finalize(stmt);
if(!remove_ok)
{
dt_control_log(_("cannot remove film roll having local copies with non accessible originals"));
return;
}
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.tagged_images WHERE imgid IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.history WHERE imgid IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.masks_history WHERE imgid IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.color_labels WHERE imgid IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.meta_data WHERE id IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.selected_images WHERE imgid IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "SELECT id FROM main.images WHERE film_id = ?1", -1,
&stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
while(sqlite3_step(stmt) == SQLITE_ROW)
{
const uint32_t imgid = sqlite3_column_int(stmt, 0);
dt_image_local_copy_reset(imgid);
dt_mipmap_cache_remove(darktable.mipmap_cache, imgid);
dt_image_cache_remove(darktable.image_cache, imgid);
}
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.images WHERE id IN "
"(SELECT id FROM main.images WHERE film_id = ?1)",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "DELETE FROM main.film_rolls WHERE id = ?1", -1,
&stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
// dt_control_update_recent_films();
dt_tag_update_used_tags();
dt_control_signal_raise(darktable.signals, DT_SIGNAL_FILMROLLS_CHANGED);
}
开发者ID:AlicVB,项目名称:darktable,代码行数:97,代码来源:film.c
示例10: dt_image_import
//.........这里部分代码省略.........
rc = sqlite3_step(stmt);
if (rc != SQLITE_DONE) fprintf(stderr, "sqlite3 error %d\n", rc);
sqlite3_finalize(stmt);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"select id from images where film_id = ?1 and filename = ?2",
-1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, film_id);
DT_DEBUG_SQLITE3_BIND_TEXT(stmt, 2, imgfname, strlen(imgfname),
SQLITE_STATIC);
if(sqlite3_step(stmt) == SQLITE_ROW) id = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
// Try to find out if this should be grouped already.
gchar *basename = g_strdup(imgfname);
gchar *cc2 = basename + strlen(basename);
for(; *cc2!='.'&&cc2>basename; cc2--);
*cc2='\0';
gchar *sql_pattern = g_strconcat(basename, ".%", NULL);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select group_id from images where film_id = ?1 and filename like ?2 and id != ?3", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, film_id);
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);
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);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, group_id);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 2, id);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
// printf("[image_import] importing `%s' to img id %d\n", imgfname, id);
// lock as shortly as possible:
const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, id);
dt_image_t *img = dt_image_cache_write_get(darktable.image_cache, cimg);
img->group_id = group_id;
// read dttags and exif for database queries!
(void) dt_exif_read(img, filename);
char dtfilename[DT_MAX_PATH_LEN];
g_strlcpy(dtfilename, filename, DT_MAX_PATH_LEN);
dt_image_path_append_version(id, dtfilename, DT_MAX_PATH_LEN);
char *c = dtfilename + strlen(dtfilename);
sprintf(c, ".xmp");
(void)dt_exif_xmp_read(img, dtfilename, 0);
// write through to db, but not to xmp.
dt_image_cache_write_release(darktable.image_cache, img, DT_IMAGE_CACHE_RELAXED);
dt_image_cache_read_release(darktable.image_cache, img);
// add a tag with the file extension
guint tagid = 0;
char tagname[512];
snprintf(tagname, 512, "darktable|format|%s", ext);
g_free(ext);
dt_tag_new(tagname, &tagid);
dt_tag_attach(tagid,id);
// Search for sidecar files and import them if found.
glob_t *globbuf = g_malloc(sizeof(glob_t));
// Add version wildcard
gchar *fname = g_strdup(filename);
gchar pattern[DT_MAX_PATH_LEN];
g_snprintf(pattern, DT_MAX_PATH_LEN, "%s", filename);
char *c1 = pattern + strlen(pattern);
while(*c1 != '.' && c1 > pattern) c1--;
snprintf(c1, pattern + DT_MAX_PATH_LEN - c1, "_*");
char *c2 = fname + strlen(fname);
while(*c2 != '.' && c2 > fname) c2--;
snprintf(c1+2, pattern + DT_MAX_PATH_LEN - c1 - 2, "%s.xmp", c2);
if (!glob(pattern, 0, NULL, globbuf))
{
for (int i=0; i < globbuf->gl_pathc; i++)
{
int newid = -1;
newid = dt_image_duplicate(id);
const dt_image_t *cimg = dt_image_cache_read_get(darktable.image_cache, newid);
dt_image_t *img = dt_image_cache_write_get(darktable.image_cache, cimg);
(void)dt_exif_xmp_read(img, globbuf->gl_pathv[i], 0);
dt_image_cache_write_release(darktable.image_cache, img, DT_IMAGE_CACHE_RELAXED);
dt_image_cache_read_release(darktable.image_cache, img);
}
globfree(globbuf);
}
g_free(imgfname);
g_free(fname);
g_free(basename);
g_free(sql_pattern);
g_free(globbuf);
dt_control_signal_raise(darktable.signals,DT_SIGNAL_IMAGE_IMPORT,id);
return id;
}
开发者ID:jcsogo,项目名称:darktable,代码行数:101,代码来源:image.c
示例11: async_redraw
static gboolean async_redraw(gpointer data)
{
dt_control_signal_raise(darktable.signals, DT_SIGNAL_FILMROLLS_CHANGED); // just for good measure
dt_control_queue_redraw();
return false;
}
请发表评论