[gnome-photos/wip/rishi/buffer-decoder: 2/5] Add PhotosGeglBufferCodecPng
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/buffer-decoder: 2/5] Add PhotosGeglBufferCodecPng
- Date: Wed, 12 Sep 2018 11:54:22 +0000 (UTC)
commit 919b4a72dc317b9ab6b5bfd561f36aabe6491818
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Sep 8 01:02:14 2018 +0200
Add PhotosGeglBufferCodecPng
https://gitlab.gnome.org/GNOME/gnome-photos/issues/63
src/photos-gegl-buffer-codec-png.c | 723 +++++++++++++++++++++++++++++++++++++
src/photos-gegl-buffer-codec-png.h | 39 ++
2 files changed, 762 insertions(+)
---
diff --git a/src/photos-gegl-buffer-codec-png.c b/src/photos-gegl-buffer-codec-png.c
new file mode 100644
index 00000000..998690ba
--- /dev/null
+++ b/src/photos-gegl-buffer-codec-png.c
@@ -0,0 +1,723 @@
+g/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 1999 The Free Software Foundation
+ * Copyright © 1999 Mark Crichton
+ * Copyright © 2018 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on code from:
+ * + GdkPixbuf
+ * + GEGL
+ */
+
+
+#include "config.h"
+
+#include <gegl.h>
+#include <glib/gi18n.h>
+#include <png.h>
+
+#include "photos-debug.h"
+#include "photos-error.h"
+#include "photos-gegl.h"
+#include "photos-gegl-buffer-codec-png.h"
+
+
+struct _PhotosGeglBufferCodecPng
+{
+ PhotosGeglBufferCodec parent_instance;
+ gboolean fatal_error_occurred;
+ gint first_pass_seen_in_chunk;
+ gint first_row_seen_in_chunk;
+ gint last_pass_seen_in_chunk;
+ gint last_row_seen_in_chunk;
+ gint max_row_seen_in_chunk;
+ png_structp png_read_ptr;
+};
+
+enum
+{
+ PROP_0,
+ PROP_BUFFER,
+ PROP_CAN_SET_SIZE
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosGeglBufferCodecPng, photos_gegl_buffer_codec_png,
PHOTOS_TYPE_GEGL_BUFFER_CODEC,
+ photos_gegl_ensure_extension_points ();
+ g_io_extension_point_implement (PHOTOS_GEGL_BUFFER_CODEC_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ "png",
+ 0));
+
+
+static const gchar *MIME_TYPES[] =
+{
+ "image/png",
+ NULL
+};
+
+
+static void
+photos_gegl_buffer_codec_png_error (png_structp png_read_ptr, png_const_charp error_message)
+{
+ PhotosGeglBufferCodecPng *self;
+ jmp_buf setjmp_buffer;
+
+ self = png_get_error_ptr (png_read_ptr);
+ self->fatal_error_occurred = TRUE;
+
+ /* Check for *error == NULL for robustness against crappy PNG
+ * library.
+ */
+ if (self->error && *self->error == NULL)
+ g_set_error (self->error, PHOTOS_ERROR, 0, _("Error reading PNG image: %s"), error_message);
+
+ setjmp_buffer = png_jmpbuf (png_read_ptr);
+ longjmp (setjmp_buffer, 1);
+
+ g_assert_not_reached ();
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_png_fill_input_buffer (j_decompress_ptr cinfo)
+{
+ return FALSE;
+}
+
+
+static void
+photos_gegl_buffer_codec_png_init_source (j_decompress_ptr cinfo)
+{
+ PhotosPngSourceMgr *src = (PhotosPngSourceMgr *) cinfo->src;
+ src->skip_next = 0;
+}
+
+
+static void
+photos_gegl_buffer_codec_png_output_message (j_common_ptr cinfo)
+{
+}
+
+
+static void
+photos_gegl_buffer_codec_png_skip_input_data (j_decompress_ptr cinfo, glong num_bytes)
+{
+ PhotosPngSourceMgr *src = (PhotosPngSourceMgr *) cinfo->src;
+ glong num_can_do;
+
+ if (num_bytes > 0)
+ {
+ num_can_do = MIN (src->pub.bytes_in_buffer, (gsize) num_bytes);
+ src->pub.next_input_byte += (gsize) num_can_do;
+ src->pub.bytes_in_buffer -= (gsize) num_can_do;
+ src->skip_next = (gsize) (num_bytes - num_can_do);
+ }
+}
+
+
+static void
+photos_gegl_buffer_codec_png_term_source (j_decompress_ptr cinfo)
+{
+}
+
+
+static void
+photos_gegl_buffer_codec_png_warning (png_structp png_read_ptr, png_const_charp warning_msg)
+{
+}
+
+
+static GeglBuffer *
+photos_gegl_buffer_codec_png_get_buffer (PhotosGeglBufferCodec *codec)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (codec);
+ return self->buffer;
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_png_load_begin (PhotosGeglBufferCodec *codec, GError **error)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (codec);
+
+ g_return_val_if_fail (!self->decoding, FALSE);
+
+ self->fatal_error_occurred = FALSE;
+ self->first_pass_seen_in_chunk = -1;
+ self->first_row_seen_in_chunk = -1;
+ self->last_pass_seen_in_chunk = -1;
+ self->last_row_seen_in_chunk = -1;
+ self->max_row_seen_in_chunk = -1;
+
+ self->png_read_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
+ self,
+ photos_gegl_buffer_codec_png_error,
+ photos_gegl_buffer_codec_png_warning);
+
+ if (sigsetjmp (self->jerr.setjmp_buffer, 1))
+ {
+ png_destroy_decompress (&self->cinfo);
+ self->decoding = FALSE;
+ goto out;
+ }
+
+ png_create_decompress (&self->cinfo);
+ self->decoding = TRUE;
+
+ self->cinfo.src = (struct png_source_mgr *) &self->src;
+ self->src.pub.init_source = photos_gegl_buffer_codec_png_init_source;
+ self->src.pub.fill_input_buffer = photos_gegl_buffer_codec_png_fill_input_buffer;
+ self->src.pub.skip_input_data = photos_gegl_buffer_codec_png_skip_input_data;
+ self->src.pub.resync_to_restart = png_resync_to_restart;
+ self->src.pub.term_source = photos_gegl_buffer_codec_png_term_source;
+
+ self->jerr.error = NULL;
+
+ g_return_val_if_fail (self->decoding, FALSE);
+
+ out:
+ return self->decoding;
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_png_load_increment (PhotosGeglBufferCodec *codec,
+ const guchar *buf,
+ gsize count,
+ GError **error)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (codec);
+ gboolean first;
+ gboolean ret_val = FALSE;
+ gsize last_bytes_left;
+ gsize last_num_left;
+ gsize num_left;
+ guint spinguard;
+ const guchar *bufhd;
+
+ g_return_val_if_fail (self->decoding, FALSE);
+
+ self->jerr.error = error;
+
+ if (sigsetjmp (self->jerr.setjmp_buffer, 1))
+ {
+ ret_val = FALSE;
+ goto out;
+ }
+
+ if (self->src_initialized && self->src.skip_next > 0)
+ {
+ if (self->src.skip_next > count)
+ {
+ self->src.skip_next -= count;
+ ret_val = TRUE;
+ goto out;
+ }
+
+ num_left = count - self->src.skip_next;
+ bufhd = buf + self->src.skip_next;
+ self->src.skip_next = 0;
+ }
+ else
+ {
+ num_left = count;
+ bufhd = buf;
+ }
+
+ if (num_left == 0)
+ {
+ ret_val = TRUE;
+ goto out;
+ }
+
+ last_num_left = num_left;
+ last_bytes_left = 0;
+ spinguard = 0;
+ first = TRUE;
+
+ while (TRUE)
+ {
+ if (num_left > 0)
+ {
+ gsize num_copy;
+
+ if (self->src.pub.bytes_in_buffer > 0 && self->src.pub.next_input_byte != self->src.buffer)
+ memmove (self->src.buffer, self->src.pub.next_input_byte, self->src.pub.bytes_in_buffer);
+
+ num_copy = MIN (SOURCE_BUF_SIZE - self->src.pub.bytes_in_buffer, num_left);
+ memcpy (self->src.buffer + self->src.pub.bytes_in_buffer, bufhd, num_copy);
+ self->src.pub.next_input_byte = self->src.buffer;
+ self->src.pub.bytes_in_buffer += num_copy;
+ bufhd += num_copy;
+ num_left -= num_copy;
+ }
+
+ if (first)
+ {
+ last_bytes_left = self->src.pub.bytes_in_buffer;
+ first = FALSE;
+ }
+ else if (self->src.pub.bytes_in_buffer == last_bytes_left && num_left == last_num_left)
+ {
+ spinguard++;
+ }
+ else
+ {
+ last_bytes_left = self->src.pub.bytes_in_buffer;
+ last_num_left = num_left;
+ }
+
+ if (spinguard > 2)
+ {
+ ret_val = TRUE;
+ goto out;
+ }
+
+ if (!self->got_header)
+ {
+ const Babl *format = NULL;
+ GeglRectangle bbox;
+ g_autofree JOCTET *icc_profile = NULL;
+ gdouble target_height;
+ gdouble target_width;
+ gint format_components;
+ gint rc;
+ guint icc_profile_len;
+ guint target_height_rounded;
+ guint target_width_rounded;
+
+ png_save_markers (&self->cinfo, PNG_APP0 + 1, 0xffff);
+ png_save_markers (&self->cinfo, PNG_APP0 + 2, 0xffff);
+ png_save_markers (&self->cinfo, PNG_COM, 0xffff);
+ rc = png_read_header (&self->cinfo, TRUE);
+ self->src_initialized = TRUE;
+
+ if (rc == PNG_SUSPENDED)
+ continue;
+
+ self->got_header = TRUE;
+
+ photos_gegl_buffer_codec_png_parse_exif (self);
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Original size: %u×%u",
+ (guint) self->cinfo.image_width,
+ (guint) self->cinfo.image_height);
+
+ self->can_set_size = TRUE;
+ g_signal_emit_by_name (self,
+ "size-prepared",
+ (guint) self->cinfo.image_width,
+ (guint) self->cinfo.image_height);
+ self->can_set_size = FALSE;
+
+ target_height = photos_gegl_buffer_codec_get_height (PHOTOS_GEGL_BUFFER_CODEC (self));
+ target_width = photos_gegl_buffer_codec_get_width (PHOTOS_GEGL_BUFFER_CODEC (self));
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Target size: %f×%f",
+ target_width,
+ target_height);
+
+ if (target_height <= 0 || target_width <= 0)
+ {
+ g_set_error_literal (error, PHOTOS_ERROR, 0, _("Transformed PNG has invalid width or height"));
+ ret_val = FALSE;
+ goto out;
+ }
+
+ target_height_rounded = (guint) (target_height + 0.5);
+ target_width_rounded = (guint) (target_width + 0.5);
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Target size rounded: %u×%u",
+ target_width_rounded,
+ target_height_rounded);
+
+ if (target_height_rounded == 0 || target_width_rounded == 0)
+ {
+ g_set_error_literal (error, PHOTOS_ERROR, 0, _("Transformed PNG has zero width or height"));
+ ret_val = FALSE;
+ goto out;
+ }
+
+ self->cinfo.scale_num = 1;
+ for (self->cinfo.scale_denom = 2; self->cinfo.scale_denom <= 8; self->cinfo.scale_denom *= 2)
+ {
+ png_calc_output_dimensions (&self->cinfo);
+ if ((guint) self->cinfo.output_height < target_height_rounded
+ || (guint) self->cinfo.output_width < target_width_rounded)
+ {
+ self->cinfo.scale_denom /= 2;
+ break;
+ }
+ }
+
+ png_calc_output_dimensions (&self->cinfo);
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Mipmap size: %u×%u",
+ (guint) self->cinfo.output_width,
+ (guint) self->cinfo.output_height);
+
+ png_read_icc_profile (&self->cinfo, &icc_profile, &icc_profile_len);
+ format = photos_gegl_buffer_codec_png_get_format (self->cinfo.out_color_space,
+ icc_profile,
+ icc_profile_len);
+ if (format == NULL)
+ {
+ const gchar *colorspace_name;
+
+ colorspace_name = photos_gegl_buffer_codec_png_get_colorspace_name
(self->cinfo.out_color_space);
+ g_set_error (error, PHOTOS_ERROR, 0, _("Unsupported PNG color space (%s)"), colorspace_name);
+ goto out;
+ }
+
+ format_components = babl_format_get_n_components (format);
+ g_assert_cmpint (format_components, ==, self->cinfo.output_components);
+
+ g_assert_null (self->buffer);
+ g_assert_null (self->buffer_mipmap);
+ g_assert_null (self->buffer_zoom_from_mipmap);
+
+ gegl_rectangle_set (&bbox, 0, 0, (guint) self->cinfo.output_width, (guint)
self->cinfo.output_height);
+ self->buffer_mipmap = gegl_buffer_new (&bbox, format);
+
+ if ((guint) self->cinfo.output_height == target_height_rounded
+ && (guint) self->cinfo.output_width == target_width_rounded)
+ {
+ self->buffer_zoom_from_mipmap = g_object_ref (self->buffer_mipmap);
+ self->buffer = g_object_ref (self->buffer_zoom_from_mipmap);
+ }
+ else
+ {
+ gdouble aspect_ratio = (gdouble) self->cinfo.image_width / (gdouble) self->cinfo.image_height;
+ gdouble target_aspect_ratio = target_width / target_height;
+
+ self->zoom_from_mipmap_x = (gdouble) target_width_rounded / (gdouble) self->cinfo.output_width;
+ self->zoom_from_mipmap_y = (gdouble) target_height_rounded / (gdouble)
self->cinfo.output_height;
+
+ if (G_APPROX_VALUE (aspect_ratio, target_aspect_ratio, PHOTOS_EPSILON))
+ {
+ gint x;
+ gint y;
+ guint zoom_from_mipmap_height;
+ guint zoom_from_mipmap_width;
+
+ self->zoom_from_mipmap_x = MAX (self->zoom_from_mipmap_x, self->zoom_from_mipmap_y);
+ self->zoom_from_mipmap_y = self->zoom_from_mipmap_x;
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Keep aspect ratio: Zoom from mipmap: %f×%f",
+ self->zoom_from_mipmap_x,
+ self->zoom_from_mipmap_y);
+
+ zoom_from_mipmap_height = (guint) (self->zoom_from_mipmap_y * (gdouble)
self->cinfo.output_height
+ + 0.5);
+ zoom_from_mipmap_width = (guint) (self->zoom_from_mipmap_x * (gdouble)
self->cinfo.output_width
+ + 0.5);
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Keep aspect ratio: Zoom from mipmap size: %u×%u",
+ zoom_from_mipmap_width,
+ zoom_from_mipmap_height);
+
+ g_assert_cmpuint (zoom_from_mipmap_height, >=, target_height_rounded);
+ g_assert_cmpuint (zoom_from_mipmap_width, >=, target_width_rounded);
+
+ gegl_rectangle_set (&bbox, 0, 0, zoom_from_mipmap_width, zoom_from_mipmap_height);
+ self->buffer_zoom_from_mipmap = gegl_buffer_new (&bbox, format);
+
+ x = (zoom_from_mipmap_width - target_width_rounded) / 2;
+ y = (zoom_from_mipmap_height - target_height_rounded) / 2;
+ gegl_rectangle_set (&bbox, x, y, target_width_rounded, target_height_rounded);
+ self->buffer = gegl_buffer_create_sub_buffer (self->buffer_zoom_from_mipmap, &bbox);
+ }
+ else
+ {
+ GeglMatrix3 affine;
+ GeglMatrix3 inverse_affine;
+
+ gegl_rectangle_set (&bbox, 0, 0, target_width_rounded, target_height_rounded);
+ self->buffer_zoom_from_mipmap = gegl_buffer_new (&bbox, format);
+ self->buffer = g_object_ref (self->buffer_zoom_from_mipmap);
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Don't keep aspect ratio: Zoom from mipmap: %f×%f",
+ self->zoom_from_mipmap_x,
+ self->zoom_from_mipmap_y);
+
+ gegl_matrix3_identity (&affine);
+ affine.coeff[0][0] = self->zoom_from_mipmap_x;
+ affine.coeff[1][1] = self->zoom_from_mipmap_y;
+
+ gegl_matrix3_copy_into (&inverse_affine, &affine);
+ gegl_matrix3_invert (&inverse_affine);
+
+ self->inverse_jacobian.coeff[0][0] = inverse_affine.coeff[0][0];
+ self->inverse_jacobian.coeff[0][1] = inverse_affine.coeff[0][1];
+ self->inverse_jacobian.coeff[1][0] = inverse_affine.coeff[1][0];
+ self->inverse_jacobian.coeff[1][1] = inverse_affine.coeff[1][1];
+
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Don't keep aspect ratio: Inverse Jacobian: %f, %f",
+ self->inverse_jacobian.coeff[0][0],
+ self->inverse_jacobian.coeff[0][1]);
+ photos_debug (PHOTOS_DEBUG_GEGL,
+ "GeglBufferCodecPng: Don't keep aspect ratio: Inverse Jacobian: %f, %f",
+ self->inverse_jacobian.coeff[1][0],
+ self->inverse_jacobian.coeff[1][1]);
+
+ self->sampler = gegl_buffer_sampler_new (self->buffer_mipmap, format, GEGL_SAMPLER_LINEAR);
+ }
+
+ g_object_get (self->buffer_zoom_from_mipmap,
+ "tile-height", &self->tile_height,
+ "tile-width", &self->tile_width,
+ NULL);
+
+ self->tile_stride = self->cinfo.output_components * self->tile_width;
+ self->tile_memory = g_malloc0_n (self->tile_height, self->tile_stride);
+
+ self->mipmap_height_needed_for_zoom = (gint) ((gdouble) self->tile_height
+ * (gdouble) self->cinfo.output_height
+ / (gdouble) target_height_rounded
+ + 0.5);
+ }
+
+ g_object_notify (G_OBJECT (self), "buffer");
+
+ g_assert_null (self->lines);
+
+ if (self->cinfo.output_components > 0
+ && self->cinfo.output_width > 0
+ && self->cinfo.output_width > G_MAXUINT / (guint) self->cinfo.output_components)
+ {
+ g_set_error (error,
+ PHOTOS_ERROR,
+ 0,
+ _("Overflow calculating row stride (%u×%u)"),
+ self->cinfo.output_components,
+ self->cinfo.output_width);
+ goto out;
+ }
+
+ self->stride_mipmap = (JDIMENSION) self->cinfo.output_components * self->cinfo.output_width;
+ if (self->stride_mipmap % 2 == 1)
+ self->stride_mipmap++;
+
+ self->lines = self->cinfo.mem->alloc_sarray ((j_common_ptr) &self->cinfo,
+ JPOOL_IMAGE,
+ self->stride_mipmap,
+ (JDIMENSION) self->cinfo.rec_outbuf_height);
+
+ self->scanline = 0;
+ }
+ else if (!self->did_prescan)
+ {
+ gint rc;
+
+ self->cinfo.buffered_image = self->cinfo.progressive_mode;
+ rc = png_start_decompress (&self->cinfo);
+ self->cinfo.do_fancy_upsampling = FALSE;
+ self->cinfo.do_block_smoothing = FALSE;
+
+ if (rc == PNG_SUSPENDED)
+ continue;
+
+ self->did_prescan = TRUE;
+ }
+ else if (!self->cinfo.buffered_image)
+ {
+ if (!photos_gegl_buffer_codec_png_load_lines (self, error))
+ goto out;
+
+ if (self->cinfo.output_scanline >= self->cinfo.output_height)
+ {
+ ret_val = TRUE;
+ goto out;
+ }
+ }
+ else
+ {
+ while (!png_input_complete (&self->cinfo))
+ {
+ if (!self->in_output)
+ {
+ if (png_start_output (&self->cinfo, self->cinfo.input_scan_number))
+ {
+ self->in_output = TRUE;
+ self->scanline = 0;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (!photos_gegl_buffer_codec_png_load_lines (self, error))
+ goto out;
+
+ if (self->cinfo.output_scanline >= self->cinfo.output_height && png_finish_output
(&self->cinfo))
+ self->in_output = FALSE;
+ else
+ break;
+ }
+
+ if (png_input_complete (&self->cinfo))
+ {
+ ret_val = TRUE;
+ goto out;
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+
+ out:
+ return ret_val;
+}
+
+
+static gboolean
+photos_gegl_buffer_codec_png_load_stop (PhotosGeglBufferCodec *codec, GError **error)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (codec);
+ gboolean ret_val = FALSE;
+
+ g_return_val_if_fail (self->decoding, FALSE);
+
+ self->jerr.error = error;
+
+ if (!sigsetjmp (self->jerr.setjmp_buffer, 1))
+ {
+ if (self->buffer != NULL && self->cinfo.output_scanline < self->cinfo.output_height)
+ {
+ if (self->src.skip_next < sizeof (self->src.buffer) - 2)
+ {
+ self->src.buffer[self->src.skip_next] = (JOCTET) 0xFF;
+ self->src.buffer[self->src.skip_next + 1] = (JOCTET) PNG_EOI;
+ self->src.pub.next_input_byte = &self->src.buffer[self->src.skip_next];
+ self->src.pub.bytes_in_buffer = 2;
+
+ photos_gegl_buffer_codec_png_load_lines (self, NULL);
+ }
+ }
+ }
+
+ /* FIXME: This thing needs to report errors if we have unused image
+ * data.
+ */
+
+ self->jerr.error = error;
+
+ if (sigsetjmp (self->jerr.setjmp_buffer, 1))
+ {
+ ret_val = FALSE;
+ }
+ else
+ {
+ png_finish_decompress (&self->cinfo);
+ ret_val = TRUE;
+ }
+
+ png_destroy_decompress (&self->cinfo);
+ self->decoding = FALSE;
+
+ g_return_val_if_fail (!self->decoding, FALSE);
+
+ return ret_val;
+}
+
+
+static void
+photos_gegl_buffer_codec_png_dispose (GObject *object)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (object);
+
+ g_clear_object (&self->buffer);
+ g_clear_object (&self->buffer_mipmap);
+ g_clear_object (&self->buffer_zoom_from_mipmap);
+ g_clear_object (&self->sampler);
+
+ G_OBJECT_CLASS (photos_gegl_buffer_codec_png_parent_class)->dispose (object);
+}
+
+
+static void
+photos_gegl_buffer_codec_png_finalize (GObject *object)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (object);
+
+ if (self->decoding)
+ png_destroy_decompress (&self->cinfo);
+
+ g_free (self->tile_memory);
+
+ G_OBJECT_CLASS (photos_gegl_buffer_codec_png_parent_class)->finalize (object);
+}
+
+
+static void
+photos_gegl_buffer_codec_png_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ PhotosGeglBufferCodecPng *self = PHOTOS_GEGL_BUFFER_CODEC_PNG (object);
+
+ switch (prop_id)
+ {
+ case PROP_BUFFER:
+ g_value_set_object (value, self->buffer);
+ break;
+
+ case PROP_CAN_SET_SIZE:
+ g_value_set_boolean (value, self->can_set_size);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_gegl_buffer_codec_png_init (PhotosGeglBufferCodecPng *self)
+{
+}
+
+
+static void
+photos_gegl_buffer_codec_png_class_init (PhotosGeglBufferCodecPngClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+ PhotosGeglBufferCodecClass *buffer_codec_class = PHOTOS_GEGL_BUFFER_CODEC_CLASS (class);
+
+ buffer_codec_class->mime_types = (GStrv) MIME_TYPES;
+
+ object_class->dispose = photos_gegl_buffer_codec_png_dispose;
+ object_class->finalize = photos_gegl_buffer_codec_png_finalize;
+ object_class->get_property = photos_gegl_buffer_codec_png_get_property;
+ buffer_codec_class->get_buffer = photos_gegl_buffer_codec_png_get_buffer;
+ buffer_codec_class->load_begin = photos_gegl_buffer_codec_png_load_begin;
+ buffer_codec_class->load_increment = photos_gegl_buffer_codec_png_load_increment;
+ buffer_codec_class->load_stop = photos_gegl_buffer_codec_png_load_stop;
+
+ g_object_class_override_property (object_class, PROP_BUFFER, "buffer");
+ g_object_class_override_property (object_class, PROP_CAN_SET_SIZE, "can-set-size");
+}
diff --git a/src/photos-gegl-buffer-codec-png.h b/src/photos-gegl-buffer-codec-png.h
new file mode 100644
index 00000000..08c8749b
--- /dev/null
+++ b/src/photos-gegl-buffer-codec-png.h
@@ -0,0 +1,39 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2018 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* Based on code from:
+ * + GdkPixbuf
+ */
+
+#ifndef PHOTOS_GEGL_BUFFER_CODEC_PNG_H
+#define PHOTOS_GEGL_BUFFER_CODEC_PNG_H
+
+#include "photos-gegl-buffer-codec.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_GEGL_BUFFER_CODEC_PNG (photos_gegl_buffer_codec_png_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosGeglBufferCodecPng,
+ photos_gegl_buffer_codec_png,
+ PHOTOS,
+ GEGL_BUFFER_CODEC_PNG,
+ PhotosGeglBufferCodec);
+
+G_END_DECLS
+
+#endif /* PHOTOS_GEGL_BUFFER_CODEC_JPEG_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]