int try_enter(dt_view_t *self)
{
dt_print_t *prt=(dt_print_t*)self->data;
// now check that there is at least one selected image
prt->image_id = -1;
int selected = dt_control_get_mouse_over_id();
if(selected < 0)
{
// try last selected
sqlite3_stmt *stmt;
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db), "select * from selected_images", -1, &stmt,
NULL);
if(sqlite3_step(stmt) == SQLITE_ROW) selected = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt);
// Leave as selected only the image being edited
DT_DEBUG_SQLITE3_EXEC(dt_database_get(darktable.db), "delete from selected_images", NULL, NULL, NULL);
DT_DEBUG_SQLITE3_PREPARE_V2(dt_database_get(darktable.db),
"insert or ignore into selected_images values (?1)", -1, &stmt, NULL);
DT_DEBUG_SQLITE3_BIND_INT(stmt, 1, selected);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
if(selected < 0)
{
// fail :(
dt_control_log(_("no image selected!"));
return 1;
}
// this loads the image from db if needed:
const dt_image_t *img = dt_image_cache_get(darktable.image_cache, selected, 'r');
// get image and check if it has been deleted from disk first!
char imgfilename[PATH_MAX] = { 0 };
gboolean from_cache = TRUE;
dt_image_full_path(img->id, imgfilename, sizeof(imgfilename), &from_cache);
if(!g_file_test(imgfilename, G_FILE_TEST_IS_REGULAR))
{
dt_control_log(_("image `%s' is currently unavailable"), img->filename);
// dt_image_remove(selected);
dt_image_cache_read_release(darktable.image_cache, img);
return 1;
}
// and drop the lock again.
dt_image_cache_read_release(darktable.image_cache, img);
prt->image_id = selected;
return 0;
}
开发者ID:CarVac,项目名称:darktable,代码行数:53,代码来源:print.c
示例10: write_image
// FIXME: we can't rely on darktable to avoid file overwriting -- it doesn't know the filename (extension).
int write_image(dt_imageio_module_data_t *data, const char *filename, const void *in,
dt_colorspaces_color_profile_type_t over_type, const char *over_filename,
void *exif, int exif_len, int imgid, int num, int total, struct dt_dev_pixelpipe_t *pipe)
{
int status = 1;
gboolean from_cache = TRUE;
char sourcefile[PATH_MAX];
char *targetfile = NULL;
char *xmpfile = NULL;
char *content = NULL;
FILE *fin = NULL;
FILE *fout = NULL;
dt_image_full_path(imgid, sourcefile, sizeof(sourcefile), &from_cache);
char *extension = g_strrstr(sourcefile, ".");
if(extension == NULL) goto END;
targetfile = g_strconcat(filename, ++extension, NULL);
if(!strcmp(sourcefile, targetfile)) goto END;
fin = g_fopen(sourcefile, "rb");
fout = g_fopen(targetfile, "wb");
if(fin == NULL || fout == NULL) goto END;
fseek(fin, 0, SEEK_END);
size_t end = ftell(fin);
rewind(fin);
content = (char *)g_malloc_n(end, sizeof(char));
if(content == NULL) goto END;
if(fread(content, sizeof(char), end, fin) != end) goto END;
if(fwrite(content, sizeof(char), end, fout) != end) goto END;
// we got a copy of the file, now write the xmp data
xmpfile = g_strconcat(targetfile, ".xmp", NULL);
if(dt_exif_xmp_write(imgid, xmpfile) != 0)
{
// something went wrong, unlink the copied image.
g_unlink(targetfile);
goto END;
}
status = 0;
END:
g_free(targetfile);
g_free(xmpfile);
g_free(content);
if(fin) fclose(fin);
if(fout) fclose(fout);
return status;
}
int
store (dt_imageio_module_storage_t *self, dt_imageio_module_data_t *sdata, const int imgid, dt_imageio_module_format_t *format, dt_imageio_module_data_t *fdata,
const int num, const int total, const gboolean high_quality)
{
dt_imageio_email_t *d = (dt_imageio_email_t *)sdata;
_email_attachment_t *attachment = ( _email_attachment_t *)g_malloc(sizeof(_email_attachment_t));
attachment->imgid = imgid;
/* construct a temporary file name */
char tmpdir[4096]= {0};
dt_loc_get_tmp_dir (tmpdir,4096);
char dirname[4096];
dt_image_full_path(imgid, dirname, 1024);
const gchar * filename = g_path_get_basename( dirname );
gchar * end = g_strrstr( filename,".")+1;
g_strlcpy( end, format->extension(fdata), sizeof(dirname)-(end-dirname));
attachment->file = g_build_filename( tmpdir, filename, (char *)NULL );
if(dt_imageio_export(imgid, attachment->file, format, fdata, high_quality) != 0)
{
fprintf(stderr, "[imageio_storage_email] could not export to file: `%s'!\n", attachment->file);
dt_control_log(_("could not export to file `%s'!"), attachment->file);
g_free(attachment);
return 1;
}
char *trunc = attachment->file + strlen(attachment->file) - 32;
if(trunc < attachment->file) trunc = attachment->file;
dt_control_log(_("%d/%d exported to `%s%s'"), num, total, trunc != filename ? ".." : "", trunc);
#ifdef _OPENMP // store can be called in parallel, so synch access to shared memory
#pragma omp critical
#endif
d->images = g_list_append( d->images, attachment );
return 0;
}
开发者ID:bleader,项目名称:darktable,代码行数:41,代码来源:email.c
示例14: dt_control_merge_hdr_job_run
//.........这里部分代码省略.........
pixels = (float *)malloc(sizeof(float)*image.width*image.height);
weight = (float *)malloc(sizeof(float)*image.width*image.height);
memset(pixels, 0x0, sizeof(float)*image.width*image.height);
memset(weight, 0x0, sizeof(float)*image.width*image.height);
wd = image.width;
ht = image.height;
}
else if(image.width != wd || image.height != ht)
{
dt_control_log(_("images have to be of same size!"));
free(pixels);
free(weight);
dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf);
goto error;
}
// if no valid exif data can be found, assume peleng fisheye at f/16, 8mm, with half of the light lost in the system => f/22
const float eap = image.exif_aperture > 0.0f ? image.exif_aperture : 22.0f;
const float efl = image.exif_focal_length > 0.0f ? image.exif_focal_length : 8.0f;
const float rad = .5f * efl/eap;
const float aperture = M_PI * rad * rad;
const float iso = image.exif_iso > 0.0f ? image.exif_iso : 100.0f;
const float exp = image.exif_exposure > 0.0f ? image.exif_exposure : 1.0f;
const float cal = 100.0f/(aperture*exp*iso);
// about proportional to how many photons we can expect from this shot:
const float photoncnt = 100.0f*aperture*exp/iso;
// stupid, but we don't know the real sensor saturation level:
uint16_t saturation = 0;
for(int k=0; k<wd*ht; k++)
saturation = MAX(saturation, ((uint16_t *)buf.buf)[k]);
// seems to be around 64500--64700 for 5dm2
// fprintf(stderr, "saturation: %u\n", saturation);
whitelevel = fmaxf(whitelevel, saturation*cal);
#ifdef _OPENMP
#pragma omp parallel for schedule(static) default(none) shared(buf, pixels, weight, wd, ht, saturation)
#endif
for(int k=0; k<wd*ht; k++)
{
const uint16_t in = ((uint16_t *)buf.buf)[k];
// weights based on siggraph 12 poster
// zijian zhu, zhengguo li, susanto rahardja, pasi fraenti
// 2d denoising factor for high dynamic range imaging
float w = envelope(in/(float)saturation) * photoncnt;
// in case we are black and drop to zero weight, give it something
// just so numerics don't collapse. blown out whites are handled below.
if(w < 1e-3f && in < saturation/3) w = 1e-3f;
pixels[k] += w * in * cal;
weight[k] += w;
}
t = g_list_delete_link(t, t);
/* update backgroundjob ui plate */
fraction+=1.0/total;
dt_control_backgroundjobs_progress(darktable.control, jid, fraction);
dt_mipmap_cache_read_release(darktable.mipmap_cache, &buf);
}
// normalize by white level to make clipping at 1.0 work as expected (to be sure, scale down one more stop, thus the 0.5):
#ifdef _OPENMP
#pragma omp parallel for schedule(static) default(none) shared(pixels, wd, ht, weight, whitelevel)
#endif
for(int k=0; k<wd*ht; k++)
{
// in case w == 0, all pixels were overexposed (too dark would have been clamped to w >= eps above)
if(weight[k] < 1e-3f)
pixels[k] = 1.f; // mark as blown out.
else // normalize:
pixels[k] = fmaxf(0.0f, pixels[k]/(whitelevel*weight[k]));
}
// output hdr as digital negative with exif data.
uint8_t exif[65535];
char pathname[DT_MAX_PATH_LEN];
dt_image_full_path(first_imgid, pathname, DT_MAX_PATH_LEN);
// last param is dng mode
const int exif_len = dt_exif_read_blob(exif, pathname, first_imgid, 0, wd, ht, 1);
char *c = pathname + strlen(pathname);
while(*c != '.' && c > pathname) c--;
g_strlcpy(c, "-hdr.dng", sizeof(pathname)-(c-pathname));
dt_imageio_write_dng(pathname, pixels, wd, ht, exif, exif_len, filter, 1.0f);
dt_control_backgroundjobs_progress(darktable.control, jid, 1.0f);
while(*c != '/' && c > pathname) c--;
dt_control_log(_("wrote merged hdr `%s'"), c+1);
// import new image
gchar *directory = g_path_get_dirname((const gchar *)pathname);
dt_film_t film;
const int filmid = dt_film_new(&film, directory);
dt_image_import(filmid, pathname, TRUE);
g_free (directory);
free(pixels);
free(weight);
error:
dt_control_backgroundjobs_destroy(darktable.control, jid);
dt_control_queue_redraw_center();
return 0;
}
请发表评论