* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include "main.h"
#include "image-load.h"
-#include "image-load-cr3.h"
-#include "image-load-gdk.h"
-#include "image-load-jpeg.h"
-#include "image-load-tiff.h"
+
+#include <fcntl.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <cstring>
+
+#include <config.h>
+
+#include "debug.h"
+#include "exif.h"
+#include "filedata.h"
+#include "gq-marshal.h"
+#include "image-load-collection.h"
#include "image-load-dds.h"
-#include "image-load-djvu.h"
+#if HAVE_DJVU
+# include "image-load-djvu.h"
+#endif
#include "image-load-external.h"
-#include "image-load-pdf.h"
-#include "image-load-psd.h"
-#include "image-load-heif.h"
-#include "image-load-ffmpegthumbnailer.h"
-#include "image-load-collection.h"
-#include "image-load-zxscr.h"
-#include "image-load-j2k.h"
-#include "image-load-jpegxl.h"
+#if HAVE_FFMPEGTHUMBNAILER
+# include "image-load-ffmpegthumbnailer.h"
+#endif
+#include "image-load-gdk.h"
+#if HAVE_HEIF
+# include "image-load-heif.h"
+#endif
+#if HAVE_J2K
+# include "image-load-j2k.h"
+#endif
+#if HAVE_JPEG
+# if !HAVE_RAW
+# include "image-load-cr3.h"
+# endif
+# include "image-load-jpeg.h"
+#endif
+#if HAVE_JPEGXL
+# include "image-load-jpegxl.h"
+#endif
#include "image-load-libraw.h"
+#if HAVE_PDF
+# include "image-load-pdf.h"
+#endif
+#include "image-load-psd.h"
#include "image-load-svgz.h"
+#if HAVE_TIFF
+# include "image-load-tiff.h"
+#endif
+#include "image-load-webp.h"
+#include "image-load-zxscr.h"
#include "misc.h"
-
-#include "exif.h"
-#include "filedata.h"
+#include "options.h"
+#include "typedefs.h"
#include "ui-fileops.h"
-#include "gq-marshal.h"
-#include <fcntl.h>
-#include <sys/mman.h>
+struct ExifData;
-#define IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT 4096
-#define IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT 1
+enum {
+ IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT = 4096,
+ IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT = 1
+};
/* image loader class */
static void image_loader_finalize(GObject *object);
static void image_loader_stop(ImageLoader *il);
-GType image_loader_get_type(void)
+GType image_loader_get_type()
{
static GType type = 0;
if (type == 0)
{
static const GTypeInfo info = {
sizeof(ImageLoaderClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc)image_loader_class_init_wrapper, /* class_init */
- NULL, /* class_finalize */
- NULL, /* class_data */
+ nullptr, /* base_init */
+ nullptr, /* base_finalize */
+ static_cast<GClassInitFunc>(image_loader_class_init_wrapper), /* class_init */
+ nullptr, /* class_finalize */
+ nullptr, /* class_data */
sizeof(ImageLoader),
0, /* n_preallocs */
- (GInstanceInitFunc)image_loader_init, /* instance_init */
- NULL /* value_table */
+ static_cast<GInstanceInitFunc>(image_loader_init), /* instance_init */
+ nullptr /* value_table */
};
- type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, 0);
+ type = g_type_register_static(G_TYPE_OBJECT, "ImageLoaderType", &info, static_cast<GTypeFlags>(0));
}
return type;
}
-static void image_loader_init(GTypeInstance *instance, gpointer UNUSED(g_class))
+static void image_loader_init(GTypeInstance *instance, gpointer)
{
- ImageLoader *il = (ImageLoader *)instance;
+ auto il = reinterpret_cast<ImageLoader *>(instance);
- il->pixbuf = NULL;
+ il->pixbuf = nullptr;
il->idle_id = 0;
il->idle_priority = G_PRIORITY_DEFAULT_IDLE;
il->done = FALSE;
- il->loader = NULL;
+ il->loader = nullptr;
il->bytes_read = 0;
il->bytes_total = 0;
il->idle_read_loop_count = IMAGE_LOADER_IDLE_READ_LOOP_COUNT_DEFAULT;
il->read_buffer_size = IMAGE_LOADER_READ_BUFFER_SIZE_DEFAULT;
- il->mapped_file = NULL;
+ il->mapped_file = nullptr;
il->preview = IMAGE_LOADER_PREVIEW_NONE;
il->requested_width = 0;
DEBUG_1("new image loader %p, bufsize=%" G_GSIZE_FORMAT " idle_loop=%u", (void *)il, il->read_buffer_size, il->idle_read_loop_count);
}
-static void image_loader_class_init_wrapper(void *data, void *UNUSED(user_data))
+static void image_loader_class_init_wrapper(void *data, void *)
{
- image_loader_class_init(data);
+ image_loader_class_init(static_cast<ImageLoaderClass *>(data));
}
static void image_loader_class_init(ImageLoaderClass *loader_class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (loader_class);
-// gobject_class->set_property = image_loader_set_property;
-// gobject_class->get_property = image_loader_get_property;
-
gobject_class->finalize = image_loader_finalize;
G_OBJECT_CLASS_TYPE(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
- NULL, NULL,
+ nullptr, nullptr,
gq_marshal_VOID__INT_INT_INT_INT,
G_TYPE_NONE, 4,
G_TYPE_INT,
G_OBJECT_CLASS_TYPE(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(ImageLoaderClass, error),
- NULL, NULL,
+ nullptr, nullptr,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
G_OBJECT_CLASS_TYPE(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(ImageLoaderClass, done),
- NULL, NULL,
+ nullptr, nullptr,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
G_OBJECT_CLASS_TYPE(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(ImageLoaderClass, percent),
- NULL, NULL,
+ nullptr, nullptr,
g_cclosure_marshal_VOID__DOUBLE,
G_TYPE_NONE, 1,
G_TYPE_DOUBLE);
G_OBJECT_CLASS_TYPE(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(ImageLoaderClass, area_ready),
- NULL, NULL,
+ nullptr, nullptr,
gq_marshal_VOID__INT_INT,
G_TYPE_NONE, 2,
G_TYPE_INT,
static void image_loader_finalize(GObject *object)
{
- ImageLoader *il = (ImageLoader *)object;
+ auto il = reinterpret_cast<ImageLoader *>(object);
image_loader_stop(il);
{
ImageLoader *il;
- if (!fd) return NULL;
+ if (!fd) return nullptr;
- il = (ImageLoader *) g_object_new(TYPE_IMAGE_LOADER, NULL);
+ il = static_cast<ImageLoader *>(g_object_new(TYPE_IMAGE_LOADER, nullptr));
il->fd = file_data_ref(fd);
/**************************************************************************************/
/* send signals via idle calbacks - the callback are executed in the main thread */
-typedef struct _ImageLoaderAreaParam ImageLoaderAreaParam;
-struct _ImageLoaderAreaParam {
+struct ImageLoaderAreaParam {
ImageLoader *il;
guint x;
guint y;
static gboolean image_loader_emit_area_ready_cb(gpointer data)
{
- ImageLoaderAreaParam *par = data;
+ auto par = static_cast<ImageLoaderAreaParam *>(data);
ImageLoader *il = par->il;
- guint x, y, w, h;
+ guint x;
+ guint y;
+ guint w;
+ guint h;
g_mutex_lock(il->data_mutex);
il->area_param_list = g_list_remove(il->area_param_list, par);
x = par->x;
g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, x, y, w, h);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean image_loader_emit_done_cb(gpointer data)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
g_signal_emit(il, signals[SIGNAL_DONE], 0);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean image_loader_emit_error_cb(gpointer data)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
g_signal_emit(il, signals[SIGNAL_ERROR], 0);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean image_loader_emit_percent_cb(gpointer data)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il));
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static gboolean image_loader_emit_size_cb(gpointer data)
{
- gint width, height;
- ImageLoader *il = data;
+ gint width;
+ gint height;
+ auto il = static_cast<ImageLoader *>(data);
g_mutex_lock(il->data_mutex);
width = il->actual_width;
height = il->actual_height;
g_mutex_unlock(il->data_mutex);
g_signal_emit(il, signals[SIGNAL_SIZE], 0, width, height);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
static void image_loader_emit_done(ImageLoader *il)
{
- g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, NULL);
+ g_idle_add_full(il->idle_priority, image_loader_emit_done_cb, il, nullptr);
}
static void image_loader_emit_error(ImageLoader *il)
{
- g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, NULL);
+ g_idle_add_full(il->idle_priority, image_loader_emit_error_cb, il, nullptr);
}
static void image_loader_emit_percent(ImageLoader *il)
{
- g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, NULL);
+ g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_percent_cb, il, nullptr);
}
static void image_loader_emit_size(ImageLoader *il)
{
- g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, NULL);
+ g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_size_cb, il, nullptr);
}
static ImageLoaderAreaParam *image_loader_queue_area_ready(ImageLoader *il, GList **list, guint x, guint y, guint w, guint h)
{
if (*list)
{
- ImageLoaderAreaParam *prev_par = (*list)->data;
+ auto prev_par = static_cast<ImageLoaderAreaParam *>((*list)->data);
if (prev_par->x == x && prev_par->w == w &&
prev_par->y + prev_par->h == y)
{
/* we can merge the notifications */
prev_par->h += h;
- return NULL;
+ return nullptr;
}
if (prev_par->x == x && prev_par->w == w &&
y + h == prev_par->y)
/* we can merge the notifications */
prev_par->h += h;
prev_par->y = y;
- return NULL;
+ return nullptr;
}
if (prev_par->y == y && prev_par->h == h &&
prev_par->x + prev_par->w == x)
{
/* we can merge the notifications */
prev_par->w += w;
- return NULL;
+ return nullptr;
}
if (prev_par->y == y && prev_par->h == h &&
x + w == prev_par->x)
/* we can merge the notifications */
prev_par->w += w;
prev_par->x = x;
- return NULL;
+ return nullptr;
}
}
- ImageLoaderAreaParam *par = g_new0(ImageLoaderAreaParam, 1);
+ auto par = g_new0(ImageLoaderAreaParam, 1);
par->il = il;
par->x = x;
par->y = y;
if (par)
{
- g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, NULL);
+ g_idle_add_full(G_PRIORITY_HIGH, image_loader_emit_area_ready_cb, par, nullptr);
}
}
g_mutex_unlock(il->data_mutex);
}
-static void image_loader_area_updated_cb(gpointer UNUSED(loader),
+static void image_loader_area_updated_cb(gpointer,
guint x, guint y, guint w, guint h,
gpointer data)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
if (!image_loader_get_pixbuf(il))
{
static void image_loader_area_prepared_cb(gpointer loader, gpointer data)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
GdkPixbuf *pb;
guchar *pix;
- size_t h, rs;
+ size_t h;
+ size_t rs;
/* a workaround for
https://bugzilla.gnome.org/show_bug.cgi?id=547669
static void image_loader_size_cb(gpointer loader,
gint width, gint height, gpointer data)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
gchar **mime_types;
gboolean scale = FALSE;
gint n;
}
g_mutex_unlock(il->data_mutex);
-#ifdef HAVE_FFMPEGTHUMBNAILER
+#if HAVE_FFMPEGTHUMBNAILER
if (il->fd->format_class == FORMAT_CLASS_VIDEO)
scale = TRUE;
#endif
g_mutex_lock(il->data_mutex);
- gint nw, nh;
+ gint nw;
+ gint nh;
if (width > il->requested_width || height > il->requested_height)
{
- if (((gdouble)il->requested_width / width) < ((gdouble)il->requested_height / height))
+ if ((static_cast<gdouble>(il->requested_width) / width) < (static_cast<gdouble>(il->requested_height) / height))
{
nw = il->requested_width;
- nh = (gdouble)nw / width * height;
+ nh = static_cast<gdouble>(nw) / width * height;
if (nh < 1) nh = 1;
}
else
{
nh = il->requested_height;
- nw = (gdouble)nh / height * width;
+ nw = static_cast<gdouble>(nh) / height * width;
if (nw < 1) nw = 1;
}
if (il->loader)
{
/* some loaders do not have a pixbuf till close, order is important here */
- il->backend.close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */
+ il->backend.close(il->loader, il->error ? nullptr : &il->error); /* we are interested in the first error only */
image_loader_sync_pixbuf(il);
il->backend.free(il->loader);
- il->loader = NULL;
+ il->loader = nullptr;
}
g_mutex_lock(il->data_mutex);
il->done = TRUE;
image_loader_backend_set_external(&il->backend);
}
else
-
-#ifdef HAVE_FFMPEGTHUMBNAILER
- if (il->fd->format_class == FORMAT_CLASS_VIDEO)
{
- DEBUG_1("Using custom ffmpegthumbnailer loader");
- image_loader_backend_set_ft(&il->backend);
- }
- else
+#if HAVE_FFMPEGTHUMBNAILER
+ if (il->fd->format_class == FORMAT_CLASS_VIDEO)
+ {
+ DEBUG_1("Using custom ffmpegthumbnailer loader");
+ image_loader_backend_set_ft(&il->backend);
+ }
+ else
#endif
-#ifdef HAVE_PDF
- if (il->bytes_total >= 4 &&
- (memcmp(il->mapped_file + 0, "%PDF", 4) == 0))
- {
- DEBUG_1("Using custom pdf loader");
- image_loader_backend_set_pdf(&il->backend);
- }
- else
+#if HAVE_PDF
+ if (il->bytes_total >= 4 &&
+ (memcmp(il->mapped_file + 0, "%PDF", 4) == 0))
+ {
+ DEBUG_1("Using custom pdf loader");
+ image_loader_backend_set_pdf(&il->backend);
+ }
+ else
#endif
-#ifdef HAVE_HEIF
- if (il->bytes_total >= 12 &&
- ((memcmp(il->mapped_file + 4, "ftypheic", 8) == 0) ||
- (memcmp(il->mapped_file + 4, "ftypmsf1", 8) == 0) ||
- (memcmp(il->mapped_file + 4, "ftypmif1", 8) == 0) ||
- (memcmp(il->mapped_file + 4, "ftypavif", 8) == 0)))
- {
- DEBUG_1("Using custom heif loader");
- image_loader_backend_set_heif(&il->backend);
- }
- else
+#if HAVE_HEIF
+ if (il->bytes_total >= 12 &&
+ ((memcmp(il->mapped_file + 4, "ftypheic", 8) == 0) ||
+ (memcmp(il->mapped_file + 4, "ftypheix", 8) == 0) ||
+ (memcmp(il->mapped_file + 4, "ftypmsf1", 8) == 0) ||
+ (memcmp(il->mapped_file + 4, "ftypmif1", 8) == 0) ||
+ (memcmp(il->mapped_file + 4, "ftypavif", 8) == 0)))
+ {
+ DEBUG_1("Using custom heif loader");
+ image_loader_backend_set_heif(&il->backend);
+ }
+ else
+ #endif
+ #if HAVE_WEBP
+ if (il->bytes_total >= 12 &&
+ (memcmp(il->mapped_file, "RIFF", 4) == 0) &&
+ (memcmp(il->mapped_file + 8, "WEBP", 4) == 0))
+ {
+ DEBUG_1("Using custom webp loader");
+ image_loader_backend_set_webp(&il->backend);
+ }
+ else
#endif
-#ifdef HAVE_DJVU
- if (il->bytes_total >= 16 &&
- (memcmp(il->mapped_file, "AT&TFORM", 8) == 0) &&
- (memcmp(il->mapped_file + 12, "DJV", 3) == 0))
- {
- DEBUG_1("Using custom djvu loader");
- image_loader_backend_set_djvu(&il->backend);
- }
- else
+#if HAVE_DJVU
+ if (il->bytes_total >= 16 &&
+ (memcmp(il->mapped_file, "AT&TFORM", 8) == 0) &&
+ (memcmp(il->mapped_file + 12, "DJV", 3) == 0))
+ {
+ DEBUG_1("Using custom djvu loader");
+ image_loader_backend_set_djvu(&il->backend);
+ }
+ else
#endif
-#ifdef HAVE_JPEG
- if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
- {
- DEBUG_1("Using custom jpeg loader");
- image_loader_backend_set_jpeg(&il->backend);
- }
-#ifndef HAVE_RAW
- else
- if (il->bytes_total >= 11 &&
- (memcmp(il->mapped_file + 4, "ftypcrx", 7) == 0) &&
- (memcmp(il->mapped_file + 64, "CanonCR3", 8) == 0))
- {
- DEBUG_1("Using custom cr3 loader");
- image_loader_backend_set_cr3(&il->backend);
- }
+#if HAVE_JPEG
+ if (il->bytes_total >= 2 && il->mapped_file[0] == 0xff && il->mapped_file[1] == 0xd8)
+ {
+ DEBUG_1("Using custom jpeg loader");
+ image_loader_backend_set_jpeg(&il->backend);
+ }
+#if !HAVE_RAW
+ else
+ if (il->bytes_total >= 11 &&
+ (memcmp(il->mapped_file + 4, "ftypcrx", 7) == 0) &&
+ (memcmp(il->mapped_file + 64, "CanonCR3", 8) == 0))
+ {
+ DEBUG_1("Using custom cr3 loader");
+ image_loader_backend_set_cr3(&il->backend);
+ }
#endif
- else
+ else
#endif
-#ifdef HAVE_TIFF
- if (il->bytes_total >= 10 &&
- (memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
- memcmp(il->mapped_file, "MM\0+\0\x08\0\0", 8) == 0 ||
- memcmp(il->mapped_file, "II+\0\x08\0\0\0", 8) == 0 ||
- memcmp(il->mapped_file, "II*\0", 4) == 0))
- {
- DEBUG_1("Using custom tiff loader");
- image_loader_backend_set_tiff(&il->backend);
- }
- else
+#if HAVE_TIFF
+ if (il->bytes_total >= 10 &&
+ (memcmp(il->mapped_file, "MM\0*", 4) == 0 ||
+ memcmp(il->mapped_file, "MM\0+\0\x08\0\0", 8) == 0 ||
+ memcmp(il->mapped_file, "II+\0\x08\0\0\0", 8) == 0 ||
+ memcmp(il->mapped_file, "II*\0", 4) == 0))
+ {
+ DEBUG_1("Using custom tiff loader");
+ image_loader_backend_set_tiff(&il->backend);
+ }
+ else
#endif
- if (il->bytes_total >= 3 && il->mapped_file[0] == 0x44 && il->mapped_file[1] == 0x44 && il->mapped_file[2] == 0x53)
- {
- DEBUG_1("Using dds loader");
- image_loader_backend_set_dds(&il->backend);
- }
- else
- if (il->bytes_total >= 6 &&
- (memcmp(il->mapped_file, "8BPS\0\x01", 6) == 0))
- {
- DEBUG_1("Using custom psd loader");
- image_loader_backend_set_psd(&il->backend);
- }
- else
-#ifdef HAVE_J2K
- if (il->bytes_total >= 12 &&
- (memcmp(il->mapped_file, "\0\0\0\x0CjP\x20\x20\x0D\x0A\x87\x0A", 12) == 0))
- {
- DEBUG_1("Using custom j2k loader");
- image_loader_backend_set_j2k(&il->backend);
- }
- else
+ if (il->bytes_total >= 3 && il->mapped_file[0] == 0x44 && il->mapped_file[1] == 0x44 && il->mapped_file[2] == 0x53)
+ {
+ DEBUG_1("Using dds loader");
+ image_loader_backend_set_dds(&il->backend);
+ }
+ else
+ if (il->bytes_total >= 6 &&
+ (memcmp(il->mapped_file, "8BPS\0\x01", 6) == 0))
+ {
+ DEBUG_1("Using custom psd loader");
+ image_loader_backend_set_psd(&il->backend);
+ }
+ else
+#if HAVE_J2K
+ if (il->bytes_total >= 12 &&
+ (memcmp(il->mapped_file, "\0\0\0\x0CjP\x20\x20\x0D\x0A\x87\x0A", 12) == 0))
+ {
+ DEBUG_1("Using custom j2k loader");
+ image_loader_backend_set_j2k(&il->backend);
+ }
+ else
#endif
-#ifdef HAVE_JPEGXL
- if (il->bytes_total >= 12 &&
- (memcmp(il->mapped_file, "\0\0\0\x0C\x4A\x58\x4C\x20\x0D\x0A\x87\x0A", 12) == 0))
- {
- DEBUG_1("Using custom jpeg xl loader");
- image_loader_backend_set_jpegxl(&il->backend);
- }
- else
- if (il->bytes_total >= 2 &&
- (memcmp(il->mapped_file, "\xFF\x0A", 2) == 0))
- {
- DEBUG_1("Using custom jpeg xl loader");
- image_loader_backend_set_jpegxl(&il->backend);
- }
- else
+#if HAVE_JPEGXL
+ if (il->bytes_total >= 12 &&
+ (memcmp(il->mapped_file, "\0\0\0\x0C\x4A\x58\x4C\x20\x0D\x0A\x87\x0A", 12) == 0))
+ {
+ DEBUG_1("Using custom jpeg xl loader");
+ image_loader_backend_set_jpegxl(&il->backend);
+ }
+ else
+ if (il->bytes_total >= 2 &&
+ (memcmp(il->mapped_file, "\xFF\x0A", 2) == 0))
+ {
+ DEBUG_1("Using custom jpeg xl loader");
+ image_loader_backend_set_jpegxl(&il->backend);
+ }
+ else
#endif
- if ((il->bytes_total == 6144 || il->bytes_total == 6912) &&
- (file_extension_match(il->fd->path, ".scr")))
- {
- DEBUG_1("Using custom zxscr loader");
- image_loader_backend_set_zxscr(&il->backend);
- }
- else
- if (il->fd->format_class == FORMAT_CLASS_COLLECTION)
- {
- DEBUG_1("Using custom collection loader");
- image_loader_backend_set_collection(&il->backend);
- }
- else
- if (g_strcmp0(strrchr(il->fd->path, '.'), ".svgz") == 0)
- {
- DEBUG_1("Using custom svgz loader");
- image_loader_backend_set_svgz(&il->backend);
+ if ((il->bytes_total == 6144 || il->bytes_total == 6912) &&
+ (file_extension_match(il->fd->path, ".scr")))
+ {
+ DEBUG_1("Using custom zxscr loader");
+ image_loader_backend_set_zxscr(&il->backend);
+ }
+ else
+ if (il->fd->format_class == FORMAT_CLASS_COLLECTION)
+ {
+ DEBUG_1("Using custom collection loader");
+ image_loader_backend_set_collection(&il->backend);
+ }
+ else
+ if (g_strcmp0(strrchr(il->fd->path, '.'), ".svgz") == 0)
+ {
+ DEBUG_1("Using custom svgz loader");
+ image_loader_backend_set_svgz(&il->backend);
+ }
+ else
+ image_loader_backend_set_default(&il->backend);
}
- else
- image_loader_backend_set_default(&il->backend);
- il->loader = il->backend.loader_new(image_loader_area_updated_cb, image_loader_size_cb, image_loader_area_prepared_cb, il);
+ il->loader = static_cast<void **>(il->backend.loader_new(image_loader_area_updated_cb, image_loader_size_cb, image_loader_area_prepared_cb, il));
-#ifdef HAVE_TIFF
+#if HAVE_TIFF
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "tiff") == 0)
{
g_free(format);
#endif
-#ifdef HAVE_PDF
+#if HAVE_PDF
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "pdf") == 0)
{
g_free(format);
#endif
-#ifdef HAVE_HEIF
+#if HAVE_HEIF
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "heif") == 0)
{
g_free(format);
#endif
-#ifdef HAVE_DJVU
+#if HAVE_DJVU
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "djvu") == 0)
{
gint b;
gint c;
- if (!il) return FALSE;
+ if (!il) return G_SOURCE_REMOVE;
c = il->idle_read_loop_count ? il->idle_read_loop_count : 1;
while (c > 0 && !image_loader_get_stopping(il))
if (b == 0)
{
image_loader_done(il);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
if (b < 0 || (b > 0 && !il->backend.write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
{
image_loader_error(il);
- return FALSE;
+ return G_SOURCE_REMOVE;
}
il->bytes_read += b;
image_loader_emit_percent(il);
}
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
static gboolean image_loader_begin(ImageLoader *il)
return FALSE;
}
-#ifdef HAVE_PDF
+#if HAVE_PDF
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "pdf") == 0)
{
}
g_free(format);
#endif
-#ifdef HAVE_HEIF
+#if HAVE_HEIF
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "heif") == 0)
{
}
g_free(format);
#endif
-#ifdef HAVE_DJVU
+#if HAVE_DJVU
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "djvu") == 0)
{
}
g_free(format);
#endif
-#ifdef HAVE_TIFF
+#if HAVE_TIFF
format = il->backend.get_format_name(il->loader);
if (g_strcmp0(format, "tiff") == 0)
{
if (!il || il->loader || il->mapped_file) return FALSE;
- il->mapped_file = NULL;
+ il->mapped_file = nullptr;
if (il->fd)
{
if (options->thumbnails.use_exif)
{
- il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, il->requested_width, il->requested_height);
+ il->mapped_file = exif_get_preview(exif, reinterpret_cast<guint *>(&il->bytes_total), il->requested_width, il->requested_height);
if (il->mapped_file)
{
}
else
{
- il->mapped_file = libraw_get_preview(il, (guint *)&il->bytes_total);
+ il->mapped_file = libraw_get_preview(il, reinterpret_cast<guint *>(&il->bytes_total));
if (il->mapped_file)
{
/* Both exiv2 and libraw sometimes return a pointer to a file
* section that is not a jpeg */
- if (!(il->mapped_file[0] == 0xFF && il->mapped_file[1] == 0xD8))
+ if (il->mapped_file[0] != 0xFF || il->mapped_file[1] != 0xD8)
{
- il->mapped_file = NULL;
+ il->mapped_file = nullptr;
}
else
{
/* If libraw does not find a thumbnail, try exiv2 */
if (!il->mapped_file)
{
- il->mapped_file = exif_get_preview(exif, (guint *)&il->bytes_total, 0, 0); /* get the largest available preview image or NULL for normal images*/
+ il->mapped_file = exif_get_preview(exif, reinterpret_cast<guint *>(&il->bytes_total), 0, 0); /* get the largest available preview image or NULL for normal images*/
if (il->mapped_file)
{
/* Both exiv2 and libraw sometimes return a pointer to a file
* section that is not a jpeg */
- if (!(il->mapped_file[0] == 0xFF && il->mapped_file[1] == 0xD8))
+ if (il->mapped_file[0] != 0xFF || il->mapped_file[1] != 0xD8)
{
- il->mapped_file = NULL;
+ il->mapped_file = nullptr;
}
else
{
return FALSE;
}
- il->mapped_file = mmap(0, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0);
+ il->mapped_file = static_cast<guchar *>(mmap(nullptr, il->bytes_total, PROT_READ|PROT_WRITE, MAP_PRIVATE, load_fd, 0));
close(load_fd);
if (il->mapped_file == MAP_FAILED)
{
- il->mapped_file = 0;
+ il->mapped_file = nullptr;
return FALSE;
}
il->preview = IMAGE_LOADER_PREVIEW_NONE;
{
munmap(il->mapped_file, il->bytes_total);
}
- il->mapped_file = NULL;
+ il->mapped_file = nullptr;
}
}
if (!enable)
{
/* send delayed */
- GList *list, *work;
+ GList *list;
+ GList *work;
list = g_list_reverse(il->area_param_delayed_list);
- il->area_param_delayed_list = NULL;
+ il->area_param_delayed_list = nullptr;
g_mutex_unlock(il->data_mutex);
work = list;
while (work)
{
- ImageLoaderAreaParam *par = work->data;
+ auto par = static_cast<ImageLoaderAreaParam *>(work->data);
work = work->next;
g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h);
- g_free(par);
}
- g_list_free(list);
+ g_list_free_full(list, g_free);
}
else
{
static gboolean image_loader_idle_cb(gpointer data)
{
- gboolean ret = FALSE;
- ImageLoader *il = data;
+ gboolean ret = G_SOURCE_REMOVE;
+ auto il = static_cast<ImageLoader *>(data);
if (il->idle_id)
{
return ret;
}
-
static gboolean image_loader_start_idle(ImageLoader *il)
{
gboolean ret;
ret = image_loader_begin(il);
- if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, NULL);
+ if (ret && !il->done) il->idle_id = g_idle_add_full(il->idle_priority, image_loader_idle_cb, il, nullptr);
return ret;
}
/**************************************************************************************/
/* execution via thread */
-static GThreadPool *image_loader_thread_pool = NULL;
+static GThreadPool *image_loader_thread_pool = nullptr;
-static GCond *image_loader_prio_cond = NULL;
-static GMutex *image_loader_prio_mutex = NULL;
+static GCond *image_loader_prio_cond = nullptr;
+static GMutex *image_loader_prio_mutex = nullptr;
static gint image_loader_prio_num = 0;
-static void image_loader_thread_enter_high(void)
+static void image_loader_thread_enter_high()
{
g_mutex_lock(image_loader_prio_mutex);
image_loader_prio_num++;
g_mutex_unlock(image_loader_prio_mutex);
}
-static void image_loader_thread_leave_high(void)
+static void image_loader_thread_leave_high()
{
g_mutex_lock(image_loader_prio_mutex);
image_loader_prio_num--;
g_mutex_unlock(image_loader_prio_mutex);
}
-static void image_loader_thread_wait_high(void)
+static void image_loader_thread_wait_high()
{
g_mutex_lock(image_loader_prio_mutex);
while (image_loader_prio_num)
}
-static void image_loader_thread_run(gpointer data, gpointer UNUSED(user_data))
+static void image_loader_thread_run(gpointer data, gpointer)
{
- ImageLoader *il = data;
+ auto il = static_cast<ImageLoader *>(data);
gboolean cont;
gboolean err;
if (!image_loader_thread_pool)
{
- image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, NULL, -1, FALSE, NULL);
+ image_loader_thread_pool = g_thread_pool_new(image_loader_thread_run, nullptr, -1, FALSE, nullptr);
if (!image_loader_prio_cond) image_loader_prio_cond = g_new(GCond, 1);
g_cond_init(image_loader_prio_cond);
if (!image_loader_prio_mutex) image_loader_prio_mutex = g_new(GMutex, 1);
il->can_destroy = FALSE; /* ImageLoader can't be freed until image_loader_thread_run finishes */
- g_thread_pool_push(image_loader_thread_pool, il, NULL);
+ g_thread_pool_push(image_loader_thread_pool, il, nullptr);
DEBUG_1("Thread pool num threads: %d", g_thread_pool_get_num_threads(image_loader_thread_pool));
return TRUE;
GdkPixbuf *image_loader_get_pixbuf(ImageLoader *il)
{
GdkPixbuf *ret;
- if (!il) return NULL;
+ if (!il) return nullptr;
g_mutex_lock(il->data_mutex);
ret = il->pixbuf;
}
else
{
- ret = (gdouble)il->bytes_read / il->bytes_total;
+ ret = static_cast<gdouble>(il->bytes_read) / il->bytes_total;
}
g_mutex_unlock(il->data_mutex);
return ret;
FileData *image_loader_get_fd(ImageLoader *il)
{
FileData *ret;
- if (!il) return NULL;
+ if (!il) return nullptr;
g_mutex_lock(il->data_mutex);
ret = il->fd;
const gchar *image_loader_get_error(ImageLoader *il)
{
- const gchar *ret = NULL;
- if (!il) return NULL;
+ const gchar *ret = nullptr;
+ if (!il) return nullptr;
g_mutex_lock(il->data_mutex);
if (il->error) ret = il->error->message;
g_mutex_unlock(il->data_mutex);
return ret;
}
+
+/**
+ * @FIXME this can be rather slow and blocks until the size is known
+ */
gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
{
+ ImageLoader *il;
gboolean success;
- gint width_file = 0;
- gint height_file = 0;
- gdk_pixbuf_get_file_info(fd->path, &width_file, &height_file);
+ il = image_loader_new(fd);
- if (width_file && height_file)
+ success = image_loader_start_idle(il);
+
+ if (success && il->pixbuf)
{
- *width = width_file;
- *height = height_file;
- success = TRUE;
+ if (width) *width = gdk_pixbuf_get_width(il->pixbuf);
+ if (height) *height = gdk_pixbuf_get_height(il->pixbuf);;
}
else
{
- *width = -1;
- *height = -1;
- success = FALSE;
+ if (width) *width = -1;
+ if (height) *height = -1;
}
+ image_loader_free(il);
+
return success;
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */