[gnome-photos/wip/rishi/buffer-decoder: 10/15] Add PhotosGeglBufferLoaderBuilder
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/buffer-decoder: 10/15] Add PhotosGeglBufferLoaderBuilder
- Date: Fri, 23 Nov 2018 21:22:33 +0000 (UTC)
commit 5bf29c997d07cc6d1931cc13a6eef7a4e4e67b53
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Aug 1 17:16:47 2018 +0200
Add PhotosGeglBufferLoaderBuilder
https://gitlab.gnome.org/GNOME/gnome-photos/issues/63
src/Makefile.am | 2 +
src/meson.build | 1 +
src/photos-gegl-buffer-loader-builder.c | 266 ++++++++++++++++++++++++++++++++
src/photos-gegl-buffer-loader-builder.h | 53 +++++++
4 files changed, 322 insertions(+)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 344761d4..161bcf93 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,6 +30,8 @@ libgnome_photos_la_SOURCES = \
photos-gegl-buffer-codec.h \
photos-gegl-buffer-loader.c \
photos-gegl-buffer-loader.h \
+ photos-gegl-buffer-loader-builder.c \
+ photos-gegl-buffer-loader-builder.h \
photos-jpeg-count.c \
photos-jpeg-count.h \
photos-operation-insta-common.h \
diff --git a/src/meson.build b/src/meson.build
index 9e3caee0..30c58d4c 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,6 +6,7 @@ sources = files(
'photos-gegl.c',
'photos-gegl-buffer-codec.c',
'photos-gegl-buffer-loader.c',
+ 'photos-gegl-buffer-loader-builder.c',
'photos-jpeg-count.c',
'photos-operation-insta-curve.c',
'photos-operation-insta-filter.c',
diff --git a/src/photos-gegl-buffer-loader-builder.c b/src/photos-gegl-buffer-loader-builder.c
new file mode 100644
index 00000000..247d2a4c
--- /dev/null
+++ b/src/photos-gegl-buffer-loader-builder.c
@@ -0,0 +1,266 @@
+/*
+ * 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/>.
+ */
+
+
+#include "config.h"
+
+#include "photos-gegl-buffer-loader-builder.h"
+
+
+struct _PhotosGeglBufferLoaderBuilder
+{
+ GObject parent_instance;
+ GFile *file;
+ gboolean keep_aspect_ratio;
+ gboolean sealed;
+ gint height;
+ gint width;
+};
+
+enum
+{
+ PROP_0,
+ PROP_FILE,
+ PROP_HEIGHT,
+ PROP_KEEP_ASPECT_RATIO,
+ PROP_WIDTH
+};
+
+
+G_DEFINE_TYPE (PhotosGeglBufferLoaderBuilder, photos_gegl_buffer_loader_builder, G_TYPE_OBJECT);
+
+
+static void
+photos_gegl_buffer_loader_builder_dispose (GObject *object)
+{
+ PhotosGeglBufferLoaderBuilder *self = PHOTOS_GEGL_BUFFER_LOADER_BUILDER (object);
+
+ g_clear_object (&self->file);
+
+ G_OBJECT_CLASS (photos_gegl_buffer_loader_builder_parent_class)->dispose (object);
+}
+
+
+static void
+photos_gegl_buffer_loader_builder_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PhotosGeglBufferLoaderBuilder *self = PHOTOS_GEGL_BUFFER_LOADER_BUILDER (object);
+
+ switch (prop_id)
+ {
+ case PROP_FILE:
+ {
+ GFile *file;
+
+ file = G_FILE (g_value_get_object (value));
+ photos_gegl_buffer_loader_builder_set_file (self, file);
+ break;
+ }
+
+ case PROP_HEIGHT:
+ {
+ gint height;
+
+ height = g_value_get_int (value);
+ photos_gegl_buffer_loader_builder_set_height (self, height);
+ break;
+ }
+
+ case PROP_KEEP_ASPECT_RATIO:
+ {
+ gboolean keep_aspect_ratio;
+
+ keep_aspect_ratio = g_value_get_boolean (value);
+ photos_gegl_buffer_loader_builder_set_keep_aspect_ratio (self, keep_aspect_ratio);
+ break;
+ }
+
+ case PROP_WIDTH:
+ {
+ gint width;
+
+ width = g_value_get_int (value);
+ photos_gegl_buffer_loader_builder_set_width (self, width);
+ break;
+ }
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
+photos_gegl_buffer_loader_builder_init (PhotosGeglBufferLoaderBuilder *self)
+{
+}
+
+
+static void
+photos_gegl_buffer_loader_builder_class_init (PhotosGeglBufferLoaderBuilderClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->dispose = photos_gegl_buffer_loader_builder_dispose;
+ object_class->set_property = photos_gegl_buffer_loader_builder_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_FILE,
+ g_param_spec_object ("file",
+ "File",
+ "The file from which to load a GeglBuffer",
+ G_TYPE_FILE,
+ G_PARAM_EXPLICIT_NOTIFY
+ | G_PARAM_STATIC_STRINGS
+ | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_HEIGHT,
+ g_param_spec_int ("height",
+ "Height",
+ "The desired height of the GeglBuffer being loaded",
+ -1,
+ G_MAXINT,
+ -1,
+ G_PARAM_EXPLICIT_NOTIFY
+ | G_PARAM_STATIC_STRINGS
+ | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_KEEP_ASPECT_RATIO,
+ g_param_spec_boolean ("keep-aspect-ratio",
+ "Keep aspect ratio",
+ "Whether to keep the aspect ratio of the GeglBuffer
when "
+ "scaling, or not",
+ TRUE,
+ G_PARAM_EXPLICIT_NOTIFY
+ | G_PARAM_STATIC_STRINGS
+ | G_PARAM_WRITABLE));
+
+ g_object_class_install_property (object_class,
+ PROP_WIDTH,
+ g_param_spec_int ("width",
+ "Width",
+ "The desired width of the GeglBuffer being loaded",
+ -1,
+ G_MAXINT,
+ -1,
+ G_PARAM_EXPLICIT_NOTIFY
+ | G_PARAM_STATIC_STRINGS
+ | G_PARAM_WRITABLE));
+}
+
+
+PhotosGeglBufferLoaderBuilder *
+photos_gegl_buffer_loader_builder_new (void)
+{
+ return g_object_new (PHOTOS_TYPE_GEGL_BUFFER_LOADER_BUILDER, NULL);
+}
+
+
+PhotosGeglBufferLoaderBuilder *
+photos_gegl_buffer_loader_builder_set_file (PhotosGeglBufferLoaderBuilder *self, GFile *file)
+{
+ g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_LOADER_BUILDER (self), NULL);
+ g_return_val_if_fail (!self->sealed, NULL);
+
+ g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+ if (g_set_object (&self->file, file))
+ g_object_notify (G_OBJECT (self), "file");
+
+ return self;
+}
+
+
+PhotosGeglBufferLoaderBuilder *
+photos_gegl_buffer_loader_builder_set_height (PhotosGeglBufferLoaderBuilder *self, gint height)
+{
+ g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_LOADER_BUILDER (self), NULL);
+ g_return_val_if_fail (height >= -1, NULL);
+ g_return_val_if_fail (height != 0, NULL);
+ g_return_val_if_fail (!self->sealed, NULL);
+
+ if (self->height != height)
+ {
+ self->height = height;
+ g_object_notify (G_OBJECT (self), "height");
+ }
+
+ return self;
+}
+
+
+PhotosGeglBufferLoaderBuilder *
+photos_gegl_buffer_loader_builder_set_keep_aspect_ratio (PhotosGeglBufferLoaderBuilder *self,
+ gboolean keep_aspect_ratio)
+{
+ g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_LOADER_BUILDER (self), NULL);
+ g_return_val_if_fail (!self->sealed, NULL);
+
+ if (self->keep_aspect_ratio != keep_aspect_ratio)
+ {
+ self->keep_aspect_ratio = keep_aspect_ratio;
+ g_object_notify (G_OBJECT (self), "keep-aspect-ratio");
+ }
+
+ return self;
+}
+
+
+PhotosGeglBufferLoaderBuilder *
+photos_gegl_buffer_loader_builder_set_width (PhotosGeglBufferLoaderBuilder *self, gint width)
+{
+ g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_LOADER_BUILDER (self), NULL);
+ g_return_val_if_fail (width >= -1, NULL);
+ g_return_val_if_fail (width != 0, NULL);
+ g_return_val_if_fail (!self->sealed, NULL);
+
+ if (self->width != width)
+ {
+ self->width = width;
+ g_object_notify (G_OBJECT (self), "width");
+ }
+
+ return self;
+}
+
+
+PhotosGeglBufferLoader *
+photos_gegl_buffer_loader_builder_to_loader (PhotosGeglBufferLoaderBuilder *self)
+{
+ PhotosGeglBufferLoader *loader;
+
+ g_return_val_if_fail (PHOTOS_IS_GEGL_BUFFER_LOADER_BUILDER (self), NULL);
+ g_return_val_if_fail (!self->sealed, NULL);
+
+ self->sealed = TRUE;
+ loader = g_object_new (PHOTOS_TYPE_GEGL_BUFFER_LOADER,
+ "file", self->file,
+ "height", self->height,
+ "keep-aspect-ratio", self->keep_aspect_ratio,
+ "width", self->width,
+ NULL);
+
+ g_return_val_if_fail (self->sealed, NULL);
+ return loader;
+}
diff --git a/src/photos-gegl-buffer-loader-builder.h b/src/photos-gegl-buffer-loader-builder.h
new file mode 100644
index 00000000..cfb8aac6
--- /dev/null
+++ b/src/photos-gegl-buffer-loader-builder.h
@@ -0,0 +1,53 @@
+/*
+ * 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/>.
+ */
+
+#ifndef PHOTOS_GEGL_BUFFER_LOADER_BUILDER_H
+#define PHOTOS_GEGL_BUFFER_LOADER_BUILDER_H
+
+#include <gio/gio.h>
+
+#include "photos-gegl-buffer-loader.h"
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_GEGL_BUFFER_LOADER_BUILDER (photos_gegl_buffer_loader_builder_get_type ())
+G_DECLARE_FINAL_TYPE (PhotosGeglBufferLoaderBuilder,
+ photos_gegl_buffer_loader_builder,
+ PHOTOS,
+ GEGL_BUFFER_LOADER_BUILDER,
+ GObject);
+
+PhotosGeglBufferLoaderBuilder *photos_gegl_buffer_loader_builder_new (void);
+
+PhotosGeglBufferLoaderBuilder *photos_gegl_buffer_loader_builder_set_file (PhotosGeglBufferLoaderBuilder
*self,
+ GFile *file);
+
+PhotosGeglBufferLoaderBuilder *photos_gegl_buffer_loader_builder_set_height (PhotosGeglBufferLoaderBuilder
*self,
+ gint height);
+
+PhotosGeglBufferLoaderBuilder *photos_gegl_buffer_loader_builder_set_keep_aspect_ratio
(PhotosGeglBufferLoaderBuilder *self,
+ gboolean
keep_aspect_ratio);
+
+PhotosGeglBufferLoaderBuilder *photos_gegl_buffer_loader_builder_set_width (PhotosGeglBufferLoaderBuilder
*self,
+ gint width);
+
+PhotosGeglBufferLoader *photos_gegl_buffer_loader_builder_to_loader (PhotosGeglBufferLoaderBuilder
*self);
+
+G_END_DECLS
+
+#endif /* PHOTOS_GEGL_BUFFER_LOADER_BUILDER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]