Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
TurboGit committed Sep 26, 2024
1 parent 3280a1a commit 108df3b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 58 deletions.
6 changes: 3 additions & 3 deletions src/common/exif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ gboolean dt_exif_get_thumbnail(const char *path,
{
dt_print(DT_DEBUG_LIGHTTABLE,
"[exiv2 dt_exif_get_thumbnail] couldn't find thumbnail for %s", path);
return TRUE;
return FALSE;
}

// Select the largest one
Expand All @@ -2225,15 +2225,15 @@ gboolean dt_exif_get_thumbnail(const char *path,

memcpy(*buffer, tmp, _size);

return FALSE;
return TRUE;
}
catch(Exiv2::AnyError &e)
{
dt_print(DT_DEBUG_IMAGEIO,
"[exiv2 dt_exif_get_thumbnail] %s: %s\n",
path,
e.what());
return TRUE;
return FALSE;
}
}

Expand Down
21 changes: 17 additions & 4 deletions src/common/mipmap_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ static void _init_8(uint8_t *buf,
}

const gboolean altered = dt_image_altered(imgid);
gboolean res = TRUE;
gboolean res = FALSE;

const dt_image_t *cimg = dt_image_cache_get(darktable.image_cache, imgid, 'r');
// the orientation for this camera is not read correctly from exiv2, so we need
Expand All @@ -1433,6 +1433,7 @@ static void _init_8(uint8_t *buf,
{
const dt_image_orientation_t orientation = dt_image_get_orientation(imgid);

printf("=========== 1\n");
// try to load the embedded thumbnail in raw
from_cache = TRUE;
memset(filename, 0, sizeof(filename));
Expand All @@ -1442,6 +1443,7 @@ static void _init_8(uint8_t *buf,
while(*c != '.' && c > filename) c--;
if(!strcasecmp(c, ".jpg"))
{
printf("=========== 2\n");
// try to load jpg
dt_imageio_jpeg_t jpg;
if(!dt_imageio_jpeg_read_header(filename, &jpg))
Expand All @@ -1454,38 +1456,45 @@ static void _init_8(uint8_t *buf,
dt_print(DT_DEBUG_CACHE,
"[mipmap_cache] generate mip %d for ID=%d from jpeg\n", size, imgid);
dt_iop_flip_and_zoom_8(tmp, jpg.width, jpg.height, buf, wd, ht, orientation, width, height);
res = FALSE;
res = TRUE;
}
dt_free_align(tmp);
printf("=========== 3\n");
}
}
else
{
printf("=========== 4\n");
uint8_t *tmp = 0;
int32_t thumb_width, thumb_height;
res = dt_imageio_large_thumbnail(filename, &tmp, &thumb_width, &thumb_height, color_space);
if(res)
{
printf("=========== 5\n");
// if the thumbnail is not large enough, we compute one
const dt_image_t *img2 = dt_image_cache_get(darktable.image_cache, imgid, 'r');
const int imgwd = img2->width;
const int imght = img2->height;
dt_image_cache_read_release(darktable.image_cache, img2);

if(thumb_width < wd
&& thumb_height < ht
&& thumb_width < imgwd - 4
&& thumb_height < imght - 4)
{
printf("=========== 6\n");
res = TRUE;
}
else
{
printf("=========== 7\n");
// scale to fit
dt_print(DT_DEBUG_CACHE,
"[mipmap_cache] generate mip %d for ID=%d from embedded jpeg\n",
size, imgid);
dt_iop_flip_and_zoom_8(tmp, thumb_width, thumb_height,
buf, wd, ht, orientation, width, height);
res = TRUE;
}
dt_free_align(tmp);
}
Expand All @@ -1494,6 +1503,7 @@ static void _init_8(uint8_t *buf,

if(res)
{
printf("=========== 8\n");
//try to generate mip from larger mip
for(dt_mipmap_size_t k = size + 1; k < DT_MIPMAP_F; k++)
{
Expand All @@ -1509,13 +1519,14 @@ static void _init_8(uint8_t *buf,
dt_iop_flip_and_zoom_8(tmp.buf, tmp.width, tmp.height, buf, wd, ht, ORIENTATION_NONE, width, height);

dt_mipmap_cache_release(darktable.mipmap_cache, &tmp);
res = FALSE;
res = TRUE;
break;
}
}

if(res)
{
printf("=========== 9\n");
// try the real thing: rawspeed + pixelpipe
dt_imageio_module_format_t format;
_dummy_data_t dat;
Expand All @@ -1534,6 +1545,7 @@ static void _init_8(uint8_t *buf,
NULL, NULL, 1, 1, NULL, -1);
if(res)
{
printf("=========== 10\n");
dt_print(DT_DEBUG_CACHE,
"[mipmap_cache] generate mip %d for ID=%d from scratch\n",
size, imgid);
Expand All @@ -1551,7 +1563,8 @@ static void _init_8(uint8_t *buf,
// any errors?
if(!res)
{
// dt_print(DT_DEBUG_ALWAYS, "[mipmap_cache] could not process thumbnail!\n");
printf("=========== ERROR\n");
dt_print(DT_DEBUG_ALWAYS, "[mipmap_cache] could not process thumbnail!\n");
*width = *height = 0;
*iscale = 0.0f;
*color_space = DT_COLORSPACE_NONE;
Expand Down
35 changes: 25 additions & 10 deletions src/imageio/imageio.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,28 @@ gboolean dt_imageio_large_thumbnail(const char *filename,
int32_t *height,
dt_colorspaces_color_profile_type_t *color_space)
{
int res = FALSE;
gboolean res = FALSE;

uint8_t *buf = NULL;
char *mime_type = NULL;
size_t bufsize;

printf(" *********** 1\n");
// get the biggest thumb from exif
if(dt_exif_get_thumbnail(filename, &buf, &bufsize, &mime_type))
goto error;
if(!dt_exif_get_thumbnail(filename, &buf, &bufsize, &mime_type))
goto ok;

printf(" *********** 1.1\n");
if(strcmp(mime_type, "image/jpeg") == 0)
{
printf(" *********** 2\n");
// Decompress the JPG into our own memory format
dt_imageio_jpeg_t jpg;
if(dt_imageio_jpeg_decompress_header(buf, bufsize, &jpg))
goto error;
goto ok;

*buffer = dt_alloc_align_uint8(4 * jpg.width * jpg.height);
if(!*buffer) goto error;
if(!*buffer) goto ok;

*width = jpg.width;
*height = jpg.height;
Expand All @@ -182,14 +185,15 @@ gboolean dt_imageio_large_thumbnail(const char *filename,
{
dt_free_align(*buffer);
*buffer = NULL;
goto error;
goto ok;
}

res = TRUE;
}
else
{
#ifdef HAVE_GRAPHICSMAGICK
printf(" *********** 3\n");
ExceptionInfo exception;
Image *image = NULL;
ImageInfo *image_info = NULL;
Expand Down Expand Up @@ -236,17 +240,20 @@ gboolean dt_imageio_large_thumbnail(const char *filename,
}
}

printf(" *********** 4\n");
res = TRUE;

error_gm:
if(image) DestroyImage(image);
if(image_info) DestroyImageInfo(image_info);
DestroyExceptionInfo(&exception);
if(!res) goto error;
if(!res) goto end;
printf(" *********** 4.1\n");
#elif defined HAVE_IMAGEMAGICK
MagickWand *image = NULL;
MagickBooleanType mret;

printf(" *********** 5\n");
image = NewMagickWand();
mret = MagickReadImageBlob(image, buf, bufsize);

Expand Down Expand Up @@ -287,12 +294,15 @@ gboolean dt_imageio_large_thumbnail(const char *filename,
goto error_im;
}

printf(" *********** 6\n");
res = TRUE;

error_im:
DestroyMagickWand(image);
if(!res) goto error;
printf(" *********** 6.1\n");
if(!res) goto end;
#else
printf(" *********** 6.2\n");
dt_print(DT_DEBUG_ALWAYS,
"[dt_imageio_large_thumbnail] error: The thumbnail image is not in "
"JPEG format, and DT was built without neither GraphicsMagick or "
Expand All @@ -301,18 +311,23 @@ gboolean dt_imageio_large_thumbnail(const char *filename,
#endif
}

printf(" *********** 7 (%d)\n", res);

if(!res)
{
dt_print(DT_DEBUG_ALWAYS,
"[dt_imageio_large_thumbnail] error: Not a supported thumbnail "
"image format or broken thumbnail: %s\n",
mime_type);
goto error;
goto end;
}

error:
ok:
res = TRUE;
end:
free(mime_type);
free(buf);
printf(" *********** 8 (%d)\n", res);
return res;
}

Expand Down
70 changes: 35 additions & 35 deletions src/imageio/imageio_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,43 +88,43 @@ dt_imageio_retval_t dt_imageio_open_exotic(dt_image_t *img, const char *filename
struct dt_imageio_module_format_t;
struct dt_imageio_module_data_t;
gboolean dt_imageio_export(const dt_imgid_t imgid,
const char *filename,
struct dt_imageio_module_format_t *format,
struct dt_imageio_module_data_t *format_params,
const gboolean high_quality,
const gboolean upscale,
const gboolean copy_metadata,
const gboolean export_masks,
dt_colorspaces_color_profile_type_t icc_type,
const gchar *icc_filename,
dt_iop_color_intent_t icc_intent,
dt_imageio_module_storage_t *storage,
dt_imageio_module_data_t *storage_params,
int num,
const int total,
dt_export_metadata_t *metadata);
const char *filename,
struct dt_imageio_module_format_t *format,
struct dt_imageio_module_data_t *format_params,
const gboolean high_quality,
const gboolean upscale,
const gboolean copy_metadata,
const gboolean export_masks,
dt_colorspaces_color_profile_type_t icc_type,
const gchar *icc_filename,
dt_iop_color_intent_t icc_intent,
dt_imageio_module_storage_t *storage,
dt_imageio_module_data_t *storage_params,
int num,
const int total,
dt_export_metadata_t *metadata);

gboolean dt_imageio_export_with_flags(const dt_imgid_t imgid, const char *filename,
struct dt_imageio_module_format_t *format,
struct dt_imageio_module_data_t *format_params,
const gboolean ignore_exif,
const gboolean display_byteorder,
const gboolean high_quality,
const gboolean upscale,
const gboolean is_scaling,
const gboolean thumbnail_export,
const char *filter,
const gboolean copy_metadata,
const gboolean export_masks,
dt_colorspaces_color_profile_type_t icc_type,
const gchar *icc_filename,
dt_iop_color_intent_t icc_intent,
dt_imageio_module_storage_t *storage,
dt_imageio_module_data_t *storage_params,
int num,
const int total,
dt_export_metadata_t *metadata,
const int history_end);
struct dt_imageio_module_format_t *format,
struct dt_imageio_module_data_t *format_params,
const gboolean ignore_exif,
const gboolean display_byteorder,
const gboolean high_quality,
const gboolean upscale,
const gboolean is_scaling,
const gboolean thumbnail_export,
const char *filter,
const gboolean copy_metadata,
const gboolean export_masks,
dt_colorspaces_color_profile_type_t icc_type,
const gchar *icc_filename,
dt_iop_color_intent_t icc_intent,
dt_imageio_module_storage_t *storage,
dt_imageio_module_data_t *storage_params,
int num,
const int total,
dt_export_metadata_t *metadata,
const int history_end);

size_t dt_imageio_write_pos(const int i,
const int j,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static GdkPixbuf *_import_get_thumbnail(const gchar *filename)
uint8_t *buffer = NULL;
size_t size = 0;
char *mime_type = NULL;
if(!dt_exif_get_thumbnail(filename, &buffer, &size, &mime_type))
if(dt_exif_get_thumbnail(filename, &buffer, &size, &mime_type))
{
// Scale the image to the correct size
GdkPixbuf *tmp;
Expand Down
10 changes: 5 additions & 5 deletions src/views/tethering.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ static void _expose_tethered_mode(dt_view_t *self,
// histogram process as well as converting to display profile for
// output, eliminating dt_view_image_get_surface() above

if(!dt_imageio_export_with_flags(lib->image_id, "unused",
&format, (dt_imageio_module_data_t *)&dat, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, NULL,
FALSE, FALSE, histogram_type, histogram_filename,
DT_INTENT_PERCEPTUAL, NULL, NULL, 1, 1, NULL, -1))
if(dt_imageio_export_with_flags(lib->image_id, "unused",
&format, (dt_imageio_module_data_t *)&dat, TRUE,
FALSE, FALSE, FALSE, FALSE, FALSE, NULL,
FALSE, FALSE, histogram_type, histogram_filename,
DT_INTENT_PERCEPTUAL, NULL, NULL, 1, 1, NULL, -1))
{
const dt_iop_order_iccprofile_info_t *const histogram_profile =
dt_ioppr_add_profile_info_to_list(darktable.develop, histogram_type,
Expand Down

0 comments on commit 108df3b

Please sign in to comment.