[gnome-photos/wip/rishi/misc-fixes] Add a sink to guess the size of a GeglBuffer after JPEG compression



commit a9ecea072c02f51182c03c5284be3fed1b6d6edf
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Dec 23 11:10:42 2015 +0100

    Add a sink to guess the size of a GeglBuffer after JPEG compression

 src/photos-operation-jpg-guess-sizes.c |  154 ++++++++++++++++++++++++++++++++
 src/photos-operation-jpg-guess-sizes.h |   45 +++++++++
 2 files changed, 199 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-operation-jpg-guess-sizes.c b/src/photos-operation-jpg-guess-sizes.c
new file mode 100644
index 0000000..b4e04d3
--- /dev/null
+++ b/src/photos-operation-jpg-guess-sizes.c
@@ -0,0 +1,154 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <babl/babl.h>
+#include <gegl.h>
+#include <gegl-plugin.h>
+
+#include "photos-operation-jpg-guess-sizes.h"
+
+
+struct _PhotosOperationJpgGuessSizes
+{
+  GeglOperationSink parent_instance;
+  gboolean progressive;
+  gint quality;
+};
+
+struct _PhotosOperationJpgGuessSizesClass
+{
+  GeglOperationSinkClass parent_class;
+};
+
+enum
+{
+  PROP_0,
+  PROP_PROGRESSIVE,
+  PROP_QUALITY
+};
+
+
+G_DEFINE_TYPE (PhotosOperationJpgGuessSizes, photos_operation_jpg_guess_sizes, GEGL_TYPE_OPERATION_SINK);
+
+
+static gboolean
+photos_operation_jpg_guess_sizes_process (GeglOperation *operation,
+                                          GeglBuffer *input,
+                                          const GeglRectangle *roi,
+                                          gint level)
+{
+  return TRUE;
+}
+
+
+static void
+photos_operation_jpg_guess_sizes_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec 
*pspec)
+{
+  PhotosOperationJpgGuessSizes *self = PHOTOS_OPERATION_JPG_GUESS_SIZES (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROGRESSIVE:
+      g_value_set_boolean (value, self->progressive);
+      break;
+
+    case PROP_QUALITY:
+      g_value_set_int (value, self->quality);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_jpg_guess_sizes_set_property (GObject *object,
+                                               guint prop_id,
+                                               const GValue *value,
+                                               GParamSpec *pspec)
+{
+  PhotosOperationJpgGuessSizes *self = PHOTOS_OPERATION_JPG_GUESS_SIZES (object);
+
+  switch (prop_id)
+    {
+    case PROP_PROGRESSIVE:
+      self->progressive = g_value_get_boolean (value);
+      break;
+
+    case PROP_QUALITY:
+      self->quality = g_value_get_int (value);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+static void
+photos_operation_jpg_guess_sizes_init (PhotosOperationJpgGuessSizes *self)
+{
+}
+
+
+static void
+photos_operation_jpg_guess_sizes_class_init (PhotosOperationJpgGuessSizesClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (class);
+  GeglOperationSinkClass *sink_class = GEGL_OPERATION_SINK_CLASS (class);
+
+  operation_class->opencl_support = FALSE;
+  sink_class->needs_full = TRUE;
+
+  object_class->get_property = photos_operation_jpg_guess_sizes_get_property;
+  object_class->set_property = photos_operation_jpg_guess_sizes_set_property;
+  sink_class->process = photos_operation_jpg_guess_sizes_process;
+
+  g_object_class_install_property (object_class,
+                                   PROP_PROGRESSIVE,
+                                   g_param_spec_int ("progressive",
+                                                     "Progressive",
+                                                     "Create progressive JPEG images",
+                                                     TRUE,
+                                                     G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_QUALITY,
+                                   g_param_spec_int ("quality",
+                                                     "Quality",
+                                                     "JPEG compression quality (between 1 and 100)",
+                                                     1,
+                                                     100,
+                                                     90,
+                                                     G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  gegl_operation_class_set_keys (operation_class,
+                                 "name", "photos:jpg-guess-sizes",
+                                 "title", "JPEG Guess Sizes",
+                                 "description", "Guesses the size of a GeglBuffer after applying JPEG 
compression",
+                                 NULL);
+}
diff --git a/src/photos-operation-jpg-guess-sizes.h b/src/photos-operation-jpg-guess-sizes.h
new file mode 100644
index 0000000..1259c65
--- /dev/null
+++ b/src/photos-operation-jpg-guess-sizes.h
@@ -0,0 +1,45 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_OPERATION_JPG_GUESS_SIZES_H
+#define PHOTOS_OPERATION_JPG_GUESS_SIZES_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_OPERATION_JPG_GUESS_SIZES (photos_operation_jpg_guess_sizes_get_type ())
+
+#define PHOTOS_OPERATION_JPG_GUESS_SIZES(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_OPERATION_JPG_GUESS_SIZES, PhotosOperationJpgGuessSizes))
+
+#define PHOTOS_IS_OPERATION_JPG_GUESS_SIZES(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_OPERATION_JPG_GUESS_SIZES))
+
+typedef struct _PhotosOperationJpgGuessSizes      PhotosOperationJpgGuessSizes;
+typedef struct _PhotosOperationJpgGuessSizesClass PhotosOperationJpgGuessSizesClass;
+
+GType            photos_operation_jpg_guess_sizes_get_type       (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_OPERATION_JPG_GUESS_SIZES_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]