aboutsummaryrefslogtreecommitdiff
path: root/fiv-thumbnail.c
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-03-15 03:31:30 +0100
committerPřemysl Eric Janouch <p@janouch.name>2023-03-15 05:52:32 +0100
commit796b05c9a5f04aba87e26c5a8384d84edee20b77 (patch)
tree74b1dbda5521bb39bcf9215c3e884499fca215d2 /fiv-thumbnail.c
parent9286858573ef5e430ac2fb24c274a6fcd41a1edd (diff)
downloadfiv-796b05c9a5f04aba87e26c5a8384d84edee20b77.tar.gz
fiv-796b05c9a5f04aba87e26c5a8384d84edee20b77.tar.xz
fiv-796b05c9a5f04aba87e26c5a8384d84edee20b77.zip
Integrate online reverse image search
This makes use of our image processing capabilities in order to turn arbitrary image files into normalized thumbnails, upload them to a temporary host, and pass the resulting URI to a search provider. In future, fiv should ideally run the upload itself, so that its status and any errors are obvious to the user, as well as to get rid of the script's dependency on jq.
Diffstat (limited to 'fiv-thumbnail.c')
-rw-r--r--fiv-thumbnail.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/fiv-thumbnail.c b/fiv-thumbnail.c
index d0ec91a..1f6897f 100644
--- a/fiv-thumbnail.c
+++ b/fiv-thumbnail.c
@@ -1,7 +1,7 @@
//
// fiv-thumbnail.c: thumbnail management
//
-// Copyright (c) 2021 - 2022, Přemysl Eric Janouch <p@janouch.name>
+// Copyright (c) 2021 - 2023, Přemysl Eric Janouch <p@janouch.name>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted.
@@ -421,6 +421,29 @@ save_thumbnail(cairo_surface_t *thumbnail, const char *path, GString *thum)
WebPDataClear(&assembled);
}
+cairo_surface_t *
+fiv_thumbnail_produce_for_search(
+ GFile *target, FivThumbnailSize max_size, GError **error)
+{
+ g_return_val_if_fail(max_size >= FIV_THUMBNAIL_SIZE_MIN &&
+ max_size <= FIV_THUMBNAIL_SIZE_MAX, NULL);
+
+ GBytes *data = g_file_load_bytes(target, NULL, NULL, error);
+ if (!data)
+ return NULL;
+
+ gboolean color_managed = FALSE;
+ cairo_surface_t *surface = render(target, data, &color_managed, error);
+ if (!surface)
+ return NULL;
+
+ // TODO(p): Might want to keep this a square.
+ cairo_surface_t *result =
+ adjust_thumbnail(surface, fiv_thumbnail_sizes[max_size].size);
+ cairo_surface_destroy(surface);
+ return result;
+}
+
static cairo_surface_t *
produce_fallback(GFile *target, FivThumbnailSize size, GError **error)
{
@@ -459,7 +482,7 @@ cairo_surface_t *
fiv_thumbnail_produce(GFile *target, FivThumbnailSize max_size, GError **error)
{
g_return_val_if_fail(max_size >= FIV_THUMBNAIL_SIZE_MIN &&
- max_size <= FIV_THUMBNAIL_SIZE_MAX, FALSE);
+ max_size <= FIV_THUMBNAIL_SIZE_MAX, NULL);
// Don't save thumbnails for FUSE mounts, such as sftp://.
// Moreover, it doesn't make sense to save thumbnails of thumbnails.