#include "debug.h"
#include "image-load.h"
-struct ImageLoaderPSD {
- ImageLoaderBackendCbAreaUpdated area_updated_cb;
- ImageLoaderBackendCbSize size_cb;
- ImageLoaderBackendCbAreaPrepared area_prepared_cb;
+namespace
+{
+
+struct ImageLoaderPSD : public ImageLoaderBackend
+{
+public:
+ ~ImageLoaderPSD() override;
+
+ void init(AreaUpdatedCb area_updated_cb, SizePreparedCb size_prepared_cb, AreaPreparedCb area_prepared_cb, gpointer data) override;
+ gboolean write(const guchar *buf, gsize &chunk_size, gsize count, GError **error) override;
+ GdkPixbuf *get_pixbuf() override;
+ gchar *get_format_name() override;
+ gchar **get_format_mime_types() override;
+
+private:
+ AreaUpdatedCb area_updated_cb;
gpointer data;
+
GdkPixbuf *pixbuf;
- guint requested_width;
- guint requested_height;
- gboolean abort;
};
struct PsdHeader
{
PsdReadState state;
- GdkPixbuf* pixbuf;
- gpointer user_data;
+ GdkPixbuf* pixbuf;
+ gpointer user_data;
guchar* buffer;
guint bytes_read;
};
-static guint16
-read_uint16 (const guchar* buf)
+guint16 read_uint16 (const guchar* buf)
{
return (buf[0] << 8) | buf[1];
}
-static guint32
-read_uint32 (const guchar* buf)
+guint32 read_uint32 (const guchar* buf)
{
return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
}
*
* str is expected to be at least PSD_HEADER_SIZE long
*/
-static PsdHeader
-psd_parse_header (guchar* str)
+PsdHeader psd_parse_header (guchar* str)
{
PsdHeader hd;
* Returns true if there were enough bytes and false otherwise
* (which means we need to call feed_buffer again)
*/
-static gboolean
+gboolean
feed_buffer (guchar* buffer,
guint* bytes_read,
const guchar** data,
* Returns true when finishes consuming block data, otherwise false
* (false means we need to call skip_block again)
*/
-static gboolean
-skip_block (PsdContext* context, const guchar** data, guint* size)
+gboolean skip_block (PsdContext* context, const guchar** data, guint* size)
{
if (!context->bytes_to_skip_known) {
context->bytes_read = 0;
/*
* Decodes RLE-compressed data
*/
-static void
-decompress_line(const guchar* src, guint line_length, guchar* dest)
+void decompress_line(const guchar* src, guint line_length, guchar* dest)
{
guint16 bytes_read = 0;
int k;
}
}
-static void
-reset_context_buffer(PsdContext* ctx)
+void reset_context_buffer(PsdContext* ctx)
{
ctx->bytes_read = 0;
ctx->bytes_to_skip = 0;
ctx->bytes_to_skip_known = FALSE;
}
-static void free_context(PsdContext *ctx)
+void free_context(PsdContext *ctx)
{
g_free(ctx->buffer);
g_free(ctx->lines_lengths);
g_free(ctx);
}
-static gboolean image_loader_psd_load(gpointer loader, const guchar *buf, gsize count, GError **)
+gboolean ImageLoaderPSD::write(const guchar *buf, gsize &chunk_size, gsize count, GError **)
{
- auto ld = static_cast<ImageLoaderPSD *>(loader);
auto ctx = g_new0(PsdContext, 1);
guint i;
guint32 j;
}
}
ctx->finalized = TRUE;
- ld->pixbuf = ctx->pixbuf;
- ld->area_updated_cb(loader, 0, 0, ctx->width, ctx->height, ld->data);
+ pixbuf = ctx->pixbuf;
+ area_updated_cb(nullptr, 0, 0, ctx->width, ctx->height, data);
free_context(ctx);
+ chunk_size = count;
return TRUE;
}
/* ------- Geeqie ------------ */
-static gpointer image_loader_psd_new(ImageLoaderBackendCbAreaUpdated area_updated_cb, ImageLoaderBackendCbSize size_cb, ImageLoaderBackendCbAreaPrepared area_prepared_cb, gpointer data)
+void ImageLoaderPSD::init(AreaUpdatedCb area_updated_cb, SizePreparedCb, AreaPreparedCb, gpointer data)
{
- auto loader = g_new0(ImageLoaderPSD, 1);
- loader->area_updated_cb = area_updated_cb;
- loader->size_cb = size_cb;
- loader->area_prepared_cb = area_prepared_cb;
- loader->data = data;
- return loader;
+ this->area_updated_cb = area_updated_cb;
+ this->data = data;
}
-static void image_loader_psd_set_size(gpointer loader, int width, int height)
+GdkPixbuf *ImageLoaderPSD::get_pixbuf()
{
- auto ld = static_cast<ImageLoaderPSD *>(loader);
- ld->requested_width = width;
- ld->requested_height = height;
+ return pixbuf;
}
-static GdkPixbuf* image_loader_psd_get_pixbuf(gpointer loader)
-{
- auto ld = static_cast<ImageLoaderPSD *>(loader);
- return ld->pixbuf;
-}
-
-static gchar* image_loader_psd_get_format_name(gpointer)
+gchar *ImageLoaderPSD::get_format_name()
{
return g_strdup("psd");
}
-static gchar** image_loader_psd_get_format_mime_types(gpointer)
+gchar **ImageLoaderPSD::get_format_mime_types()
{
static const gchar *mime[] = {"application/psd", nullptr};
return g_strdupv(const_cast<gchar **>(mime));
}
-static gboolean image_loader_psd_close(gpointer, GError **)
+ImageLoaderPSD::~ImageLoaderPSD()
{
- return TRUE;
+ if (pixbuf) g_object_unref(pixbuf);
}
-static void image_loader_psd_abort(gpointer loader)
-{
- auto ld = static_cast<ImageLoaderPSD *>(loader);
- ld->abort = TRUE;
-}
-
-static void image_loader_psd_free(gpointer loader)
-{
- auto ld = static_cast<ImageLoaderPSD *>(loader);
- if (ld->pixbuf) g_object_unref(ld->pixbuf);
- g_free(ld);
-}
+} // namespace
-void image_loader_backend_set_psd(ImageLoaderBackend *funcs)
+std::unique_ptr<ImageLoaderBackend> get_image_loader_backend_psd()
{
- funcs->loader_new = image_loader_psd_new;
- funcs->set_size = image_loader_psd_set_size;
- funcs->load = image_loader_psd_load;
- funcs->write = nullptr;
- funcs->get_pixbuf = image_loader_psd_get_pixbuf;
- funcs->close = image_loader_psd_close;
- funcs->abort = image_loader_psd_abort;
- funcs->free = image_loader_psd_free;
- funcs->get_format_name = image_loader_psd_get_format_name;
- funcs->get_format_mime_types = image_loader_psd_get_format_mime_types;
+ return std::make_unique<ImageLoaderPSD>();
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */