2021-12-28 19:58:14 +01:00
|
|
|
//
|
|
|
|
// fiv-thumbnail.h: thumbnail management
|
|
|
|
//
|
2023-03-15 03:31:30 +01:00
|
|
|
// Copyright (c) 2021 - 2023, Přemysl Eric Janouch <p@janouch.name>
|
2021-12-28 19:58:14 +01:00
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
|
|
|
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
|
|
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
|
|
|
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cairo.h>
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
// And this is how you avoid glib-mkenums.
|
|
|
|
typedef enum _FivThumbnailSize {
|
|
|
|
#define FIV_THUMBNAIL_SIZES(XX) \
|
|
|
|
XX(SMALL, 128, "normal") \
|
|
|
|
XX(NORMAL, 256, "large") \
|
|
|
|
XX(LARGE, 512, "x-large") \
|
|
|
|
XX(HUGE, 1024, "xx-large")
|
|
|
|
#define XX(name, value, dir) FIV_THUMBNAIL_SIZE_ ## name,
|
|
|
|
FIV_THUMBNAIL_SIZES(XX)
|
|
|
|
#undef XX
|
|
|
|
FIV_THUMBNAIL_SIZE_COUNT,
|
|
|
|
|
|
|
|
FIV_THUMBNAIL_SIZE_MIN = 0,
|
|
|
|
FIV_THUMBNAIL_SIZE_MAX = FIV_THUMBNAIL_SIZE_COUNT - 1
|
|
|
|
} FivThumbnailSize;
|
|
|
|
|
|
|
|
GType fiv_thumbnail_size_get_type(void) G_GNUC_CONST;
|
|
|
|
#define FIV_TYPE_THUMBNAIL_SIZE (fiv_thumbnail_size_get_type())
|
|
|
|
|
|
|
|
typedef struct _FivThumbnailSizeInfo {
|
|
|
|
int size; ///< Nominal size in pixels
|
|
|
|
const char *thumbnail_spec_name; ///< thumbnail-spec directory name
|
|
|
|
} FivThumbnailSizeInfo;
|
|
|
|
|
|
|
|
enum { FIV_THUMBNAIL_WIDE_COEFFICIENT = 2 };
|
|
|
|
|
2022-06-06 15:22:23 +02:00
|
|
|
extern FivThumbnailSizeInfo fiv_thumbnail_sizes[FIV_THUMBNAIL_SIZE_COUNT];
|
|
|
|
|
2021-12-28 19:58:14 +01:00
|
|
|
/// If non-NULL, indicates a thumbnail of insufficient quality.
|
|
|
|
extern cairo_user_data_key_t fiv_thumbnail_key_lq;
|
|
|
|
|
2022-06-07 04:21:04 +02:00
|
|
|
/// Attempts to extract any low-quality thumbnail from fast targets.
|
2022-06-08 02:45:45 +02:00
|
|
|
/// If `max_size` is a valid value, the image will be downscaled as appropriate.
|
|
|
|
cairo_surface_t *fiv_thumbnail_extract(
|
|
|
|
GFile *target, FivThumbnailSize max_size, GError **error);
|
2022-06-07 04:21:04 +02:00
|
|
|
|
2021-12-28 19:58:14 +01:00
|
|
|
/// Generates wide thumbnails of up to the specified size, saves them in cache.
|
2022-06-07 04:21:04 +02:00
|
|
|
/// Returns the surface used for the maximum size, or an error.
|
|
|
|
cairo_surface_t *fiv_thumbnail_produce(
|
|
|
|
GFile *target, FivThumbnailSize max_size, GError **error);
|
2021-12-28 19:58:14 +01:00
|
|
|
|
2023-03-15 03:31:30 +01:00
|
|
|
/// Like fiv_thumbnail_produce(), but skips the cache.
|
|
|
|
cairo_surface_t *fiv_thumbnail_produce_for_search(
|
|
|
|
GFile *target, FivThumbnailSize max_size, GError **error);
|
|
|
|
|
2021-12-28 19:58:14 +01:00
|
|
|
/// Retrieves a thumbnail of the most appropriate quality and resolution
|
|
|
|
/// for the target file.
|
2022-06-04 15:06:10 +02:00
|
|
|
cairo_surface_t *fiv_thumbnail_lookup(
|
Support opening collections of files
Implement a process-local VFS to enable grouping together arbitrary
URIs passed via program arguments, DnD, or the file open dialog.
This VFS contains FivCollectionFile objects, which act as "simple"
proxies over arbitrary GFiles. Their true URIs may be retrieved
through the "standard::target-uri" attribute, in a similar way to
GVfs's "recent" and "trash" backends.
(The main reason we proxy rather than just hackishly return foreign
GFiles from the VFS is that loading them would switch the current
directory, and break iteration as a result.
We could also keep the collection outside of GVfs, but that would
result in considerable special-casing, and the author wouldn't gain
intimate knowledge of GIO.)
There is no perceived need to keep old collections when opening
new ones, so we simply change and reload the contents when needed.
Similarly, there is no intention to make the VFS writeable.
The process-locality of this and other URI schemes has proven to be
rather annoying when passing files to other applications,
however most of the resulting complexity appears to be essential
rather than accidental.
Note that the GTK+ file chooser widget is retarded, and doesn't
recognize URIs that lack the authority part in the location bar.
2022-07-28 00:37:36 +02:00
|
|
|
const char *uri, gint64 mtime_msec, FivThumbnailSize size);
|
2022-02-20 13:13:49 +01:00
|
|
|
|
|
|
|
/// Invalidate the wide thumbnail cache. May write to standard streams.
|
|
|
|
void fiv_thumbnail_invalidate(void);
|