[Rawstudio-commit] r2009 - trunk/src

Anders Brander anders at brander.dk
Tue Sep 16 19:32:25 CEST 2008


Author: abrander
Date: 2008-09-16 19:32:25 +0200 (Tue, 16 Sep 2008)
New Revision: 2009

Added:
   trunk/src/rs-metadata.c
   trunk/src/rs-metadata.h
Modified:
   trunk/src/Makefile.am
   trunk/src/ciff-meta.c
   trunk/src/mrw-meta.c
   trunk/src/raf-meta.c
   trunk/src/rawstudio.c
   trunk/src/rawstudio.h
   trunk/src/rs-batch.c
   trunk/src/rs-photo.c
   trunk/src/rs-store.c
   trunk/src/tiff-meta.c
Log:
GObject'ified RSMetadata.

Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/Makefile.am	2008-09-16 17:32:25 UTC (rev 2009)
@@ -7,6 +7,7 @@
 
 AM_CFLAGS =\
 	-Wall\
+	-Werror\
 	-O4\
 	-DWITH_GCONF\
 	-DDCRAW_NOMAIN\
@@ -69,6 +70,7 @@
 	rs-pixbuf.c rs-pixbuf.h \
 	rs-external-editor.c rs-external-editor.h \
 	rs-dir-selector.c rs-dir-selector.h \
+	rs-metadata.c rs-metadata.h \
 	rs-exif.cc rs-exif.h
 
 rawstudio_LDADD = @PACKAGE_LIBS@ @LIBJPEG@ @LIBTIFF@ $(INTLLIBS)

Modified: trunk/src/ciff-meta.c
===================================================================
--- trunk/src/ciff-meta.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/ciff-meta.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -24,6 +24,7 @@
 #include "ciff-meta.h"
 #include "adobe-coeff.h"
 #include "rs-utils.h"
+#include "rs-metadata.h"
 
 gboolean raw_crw_walker(RAWFILE *rawfile, guint offset, guint length, RSMetadata *meta);
 
@@ -255,6 +256,6 @@
 		}
 	}
 	raw_close_file(rawfile);
-	rs_metadata_free(m);
+	g_object_unref(m);
 	return(pixbuf);
 }

Modified: trunk/src/mrw-meta.c
===================================================================
--- trunk/src/mrw-meta.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/mrw-meta.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -22,6 +22,7 @@
 #include "rawfile.h"
 #include "mrw-meta.h"
 #include "tiff-meta.h"
+#include "rs-metadata.h"
 
 static void raw_mrw_walker(RAWFILE *rawfile, guint offset, RSMetadata *meta);
 

Modified: trunk/src/raf-meta.c
===================================================================
--- trunk/src/raf-meta.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/raf-meta.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -25,6 +25,7 @@
 #include "tiff-meta.h"
 #include "color.h"
 #include "rs-utils.h"
+#include "rs-metadata.h"
 
 void
 rs_raf_load_meta(const gchar *filename, RSMetadata *meta)

Modified: trunk/src/rawstudio.c
===================================================================
--- trunk/src/rawstudio.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/rawstudio.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -50,6 +50,7 @@
 #include "rs-photo.h"
 #include "rs-math.h"
 #include "rs-exif.h"
+#include "rs-metadata.h"
 
 static void photo_settings_changed(RS_PHOTO *photo, gint mask, RS_BLOB *rs);
 static void photo_spatial_changed(RS_PHOTO *photo, RS_BLOB *rs);
@@ -424,114 +425,7 @@
 	return;
 }
 
-RSMetadata *
-rs_metadata_new(void)
-{
-	RSMetadata *metadata;
-	gint i;
-	metadata = g_malloc(sizeof(RSMetadata));
-	metadata->make = MAKE_UNKNOWN;
-	metadata->make_ascii = NULL;
-	metadata->model_ascii = NULL;
-	metadata->time_ascii = NULL;
-	metadata->timestamp = -1;
-	metadata->orientation = 0;
-	metadata->aperture = -1.0;
-	metadata->iso = 0;
-	metadata->shutterspeed = -1.0;
-	metadata->thumbnail_start = 0;
-	metadata->thumbnail_length = 0;
-	metadata->preview_start = 0;
-	metadata->preview_length = 0;
-	metadata->preview_planar_config = 0;
-	metadata->preview_width = 0;
-	metadata->preview_height = 0;
-	metadata->cam_mul[0] = -1.0;
-	metadata->contrast = -1.0;
-	metadata->saturation = -1.0;
-	metadata->color_tone = -1.0;
-	metadata->focallength = -1;
-	for(i=0;i<4;i++)
-		metadata->cam_mul[i] = 1.0f;
-	matrix4_identity(&metadata->adobe_coeff);
-	return(metadata);
-}
-
-void
-rs_metadata_free(RSMetadata *metadata)
-{
-	if (metadata->make_ascii)
-		g_free(metadata->make_ascii);
-	if (metadata->model_ascii)
-		g_free(metadata->model_ascii);
-	if (metadata->time_ascii)
-		g_free(metadata->time_ascii);
-	g_free(metadata);
-	return;
-}
-
-/**
- * Load metadata from file
- */
 gboolean
-rs_metadata_load(const gchar *filename, RSMetadata *metadata)
-{
-	gboolean ret = FALSE;
-	RS_FILETYPE *filetype;
-
-	g_assert(filename != NULL);
-
-	filetype = rs_filetype_get(filename, TRUE);
-
-	if (filetype && filetype->load_meta)
-	{
-		filetype->load_meta(filename, metadata);
-		ret = TRUE;
-	}
-
-	return ret;
-}
-
-gchar *
-rs_metadata_get_short_description(RSMetadata *metadata)
-{
-	GString *label = g_string_new("");
-	gchar *ret = NULL;
-
-	if (metadata->focallength>0)
-		g_string_append_printf(label, _("%dmm "), metadata->focallength);
-	if (metadata->shutterspeed > 0.0 && metadata->shutterspeed < 4) 
-		g_string_append_printf(label, _("%.1fs "), 1/metadata->shutterspeed);
-	else if (metadata->shutterspeed >= 4)
-		g_string_append_printf(label, _("1/%.0fs "), metadata->shutterspeed);
-	if (metadata->aperture!=0.0)
-		g_string_append_printf(label, _("F/%.1f "), metadata->aperture);
-	if (metadata->iso!=0)
-		g_string_append_printf(label, _("ISO%d"), metadata->iso);
-
-	ret = label->str;
-
-	g_string_free(label, FALSE);
-
-	return ret;
-}
-
-void
-rs_metadata_normalize_wb(RSMetadata *meta)
-{
-	gdouble div;
-	if ((meta->cam_mul[1]+meta->cam_mul[3])!=0.0)
-	{
-		div = 2/(meta->cam_mul[1]+meta->cam_mul[3]);
-		meta->cam_mul[0] *= div;
-		meta->cam_mul[1] = 1.0;
-		meta->cam_mul[2] *= div;
-		meta->cam_mul[3] = 1.0;
-	}
-	return;
-}
-
-gboolean
 rs_photo_save(RS_PHOTO *photo, const gchar *filename, gint filetype, gint width, gint height, gboolean keep_aspect, gdouble scale, gint snapshot, RS_CMS *cms)
 {
 	GdkPixbuf *pixbuf;
@@ -1211,7 +1105,7 @@
 		g_free(basename);
 
 		g_free(filename);
-		rs_metadata_free(metadata);
+		g_object_unref(metadata);
 	}
 	printf("Passed: %d Failed: %d (%d%%)\n", good, bad, (good*100)/(good+bad));
 	g_io_channel_shutdown(io, TRUE, NULL);

Modified: trunk/src/rawstudio.h
===================================================================
--- trunk/src/rawstudio.h	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/rawstudio.h	2008-09-16 17:32:25 UTC (rev 2009)
@@ -182,6 +182,7 @@
 
 typedef struct _metadata {
 	GObject parent;
+	gboolean dispose_has_run;
 	gint make;
 	gchar *make_ascii;
 	gchar *model_ascii;
@@ -277,11 +278,7 @@
 RS_SETTINGS_DOUBLE *rs_settings_double_new(void);
 void rs_settings_double_copy(const RS_SETTINGS_DOUBLE *in, RS_SETTINGS_DOUBLE *out, gint mask);
 void rs_settings_double_free(RS_SETTINGS_DOUBLE *rssd);
-RSMetadata *rs_metadata_new();
-void rs_metadata_free(RSMetadata *metadata);
-gboolean rs_metadata_load(const gchar *filename, RSMetadata *metadata);
 gchar * rs_metadata_get_short_description(RSMetadata *metadata);
-void rs_metadata_normalize_wb(RSMetadata *meta);
 RS_BLOB *rs_new();
 void rs_free(RS_BLOB *rs);
 void rs_set_photo(RS_BLOB *rs, RS_PHOTO *photo);

Modified: trunk/src/rs-batch.c
===================================================================
--- trunk/src/rs-batch.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/rs-batch.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -33,6 +33,7 @@
 #include "rs-color-transform.h"
 #include "rs-image.h"
 #include "rs-photo.h"
+#include "rs-metadata.h"
 
 extern GtkWindow *rawstudio_window;
 
@@ -492,7 +493,7 @@
 			rs_image16_demosaic(photo->input, RS_DEMOSAIC_PPG);
 			if (photo)
 			{
-				rs_metadata_load(filename_in, photo->metadata);
+				rs_metadata_load_from_file(photo->metadata, filename_in);
 				filename = g_string_new(queue->directory);
 				g_string_append(filename, G_DIR_SEPARATOR_S);
 				g_string_append(filename, queue->filename);

Added: trunk/src/rs-metadata.c
===================================================================
--- trunk/src/rs-metadata.c	                        (rev 0)
+++ trunk/src/rs-metadata.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -0,0 +1,176 @@
+/*
+ * Copyright (C) 2006-2008 Anders Brander <anders at brander.dk> and 
+ * Anders Kvist <akv at lnxbx.dk>
+ *
+ * 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 "gettext.h"
+#include "rs-metadata.h"
+#include "rawstudio.h"
+#include "rs-math.h"
+
+G_DEFINE_TYPE (RSMetadata, rs_metadata, G_TYPE_OBJECT)
+
+static void
+rs_metadata_dispose (GObject *object)
+{
+	RSMetadata *metadata = RS_METADATA(object);
+
+	if (!metadata->dispose_has_run)
+	{
+		metadata->dispose_has_run = TRUE;
+	
+		if (metadata->make_ascii)
+			g_free(metadata->make_ascii);
+		if (metadata->model_ascii)
+			g_free(metadata->model_ascii);
+		if (metadata->time_ascii)
+			g_free(metadata->time_ascii);
+	}
+
+	/* Chain up */
+	if (G_OBJECT_CLASS (rs_metadata_parent_class)->dispose)
+		G_OBJECT_CLASS (rs_metadata_parent_class)->dispose (object);
+}
+
+static void
+rs_metadata_finalize (GObject *object)
+{
+	if (G_OBJECT_CLASS (rs_metadata_parent_class)->finalize)
+		G_OBJECT_CLASS (rs_metadata_parent_class)->finalize (object);
+}
+
+static void
+rs_metadata_class_init (RSMetadataClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	object_class->dispose = rs_metadata_dispose;
+	object_class->finalize = rs_metadata_finalize;
+}
+
+static void
+rs_metadata_init (RSMetadata *metadata)
+{
+	gint i;
+
+	metadata->dispose_has_run = FALSE;
+	metadata->make = MAKE_UNKNOWN;
+	metadata->make_ascii = NULL;
+	metadata->model_ascii = NULL;
+	metadata->time_ascii = NULL;
+	metadata->timestamp = -1;
+	metadata->orientation = 0;
+	metadata->aperture = -1.0;
+	metadata->iso = 0;
+	metadata->shutterspeed = -1.0;
+	metadata->thumbnail_start = 0;
+	metadata->thumbnail_length = 0;
+	metadata->preview_start = 0;
+	metadata->preview_length = 0;
+	metadata->preview_planar_config = 0;
+	metadata->preview_width = 0;
+	metadata->preview_height = 0;
+	metadata->cam_mul[0] = -1.0;
+	metadata->contrast = -1.0;
+	metadata->saturation = -1.0;
+	metadata->color_tone = -1.0;
+	metadata->focallength = -1;
+	for(i=0;i<4;i++)
+		metadata->cam_mul[i] = 1.0f;
+	matrix4_identity(&metadata->adobe_coeff);
+}
+
+RSMetadata*
+rs_metadata_new (void)
+{
+	return g_object_new (RS_TYPE_METADATA, NULL);
+}
+
+RSMetadata *
+rs_metadata_new_from_file(const gchar *filename)
+{
+	RSMetadata *metadata = rs_metadata_new();
+
+	rs_metadata_load_from_file(metadata, filename);
+
+	return metadata;
+}
+
+gboolean
+rs_metadata_load_from_file(RSMetadata *metadata, const gchar *filename)
+{
+	gboolean ret = FALSE;
+	RS_FILETYPE *filetype;
+
+	g_assert(filename != NULL);
+	g_assert(RS_IS_METADATA(metadata));
+
+	filetype = rs_filetype_get(filename, TRUE);
+
+	if (filetype && filetype->load_meta)
+	{
+		filetype->load_meta(filename, metadata);
+		ret = TRUE;
+	}
+
+	return ret;
+}
+
+void
+rs_metadata_normalize_wb(RSMetadata *metadata)
+{
+	gdouble div;
+
+	g_assert(RS_IS_METADATA(metadata));
+
+	if ((metadata->cam_mul[1]+metadata->cam_mul[3])!=0.0)
+	{
+		div = 2/(metadata->cam_mul[1]+metadata->cam_mul[3]);
+		metadata->cam_mul[0] *= div;
+		metadata->cam_mul[1] = 1.0;
+		metadata->cam_mul[2] *= div;
+		metadata->cam_mul[3] = 1.0;
+	}
+	return;
+}
+
+gchar *
+rs_metadata_get_short_description(RSMetadata *metadata)
+{
+	GString *label = g_string_new("");
+	gchar *ret = NULL;
+
+	g_assert(RS_IS_METADATA(metadata));
+
+	if (metadata->focallength>0)
+		g_string_append_printf(label, _("%dmm "), metadata->focallength);
+	if (metadata->shutterspeed > 0.0 && metadata->shutterspeed < 4) 
+		g_string_append_printf(label, _("%.1fs "), 1/metadata->shutterspeed);
+	else if (metadata->shutterspeed >= 4)
+		g_string_append_printf(label, _("1/%.0fs "), metadata->shutterspeed);
+	if (metadata->aperture!=0.0)
+		g_string_append_printf(label, _("F/%.1f "), metadata->aperture);
+	if (metadata->iso!=0)
+		g_string_append_printf(label, _("ISO%d"), metadata->iso);
+
+	ret = label->str;
+
+	g_string_free(label, FALSE);
+
+	return ret;
+}

Added: trunk/src/rs-metadata.h
===================================================================
--- trunk/src/rs-metadata.h	                        (rev 0)
+++ trunk/src/rs-metadata.h	2008-09-16 17:32:25 UTC (rev 2009)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2006-2008 Anders Brander <anders at brander.dk> and 
+ * Anders Kvist <akv at lnxbx.dk>
+ *
+ * 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 RS_METADATA_H
+#define RS_METADATA_H
+
+#include <glib-object.h>
+#include "rawstudio.h" /* FIXME: This is so broken! */
+
+G_BEGIN_DECLS
+
+#define RS_TYPE_METADATA rs_metadata_get_type()
+#define RS_METADATA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_METADATA, RSMetadata))
+#define RS_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_METADATA, RSMetadataClass))
+#define RS_IS_METADATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_METADATA))
+#define RS_IS_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), RS_TYPE_METADATA))
+#define RS_METADATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), RS_TYPE_METADATA, RSMetadataClass))
+
+//typedef struct _rs_metadata RSMetadata;
+typedef struct {
+  GObjectClass parent_class;
+} RSMetadataClass;
+
+GType rs_metadata_get_type (void);
+
+extern RSMetadata *rs_metadata_new (void);
+extern RSMetadata *rs_metadata_new_from_file(const gchar *filename);
+extern gboolean rs_metadata_load_from_file(RSMetadata *metadata, const gchar *filename);
+extern void rs_metadata_normalize_wb(RSMetadata *metadata);
+extern gchar *rs_metadata_get_short_description(RSMetadata *metadata);
+
+G_END_DECLS
+
+#endif /* RS_METADATA_H */
+

Modified: trunk/src/rs-photo.c
===================================================================
--- trunk/src/rs-photo.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/rs-photo.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -23,6 +23,7 @@
 #include "rs-cache.h"
 #include "rs-curve.h"
 #include "rs-preload.h"
+#include "rs-metadata.h"
 
 static void rs_photo_class_init (RS_PHOTOClass *klass);
 
@@ -60,7 +61,7 @@
 		g_free(photo->filename);
 
 	if (photo->metadata)
-		rs_metadata_free(photo->metadata);
+		g_object_unref(photo->metadata);
 
 	if (photo->input)
 		g_object_unref(photo->input);
@@ -587,7 +588,7 @@
 			photo->input = image;
 
 			/* Load metadata */
-			if (rs_metadata_load(filename, photo->metadata))
+			if (rs_metadata_load_from_file(photo->metadata, filename))
 			{
 				/* Rotate photo inplace */
 				switch (photo->metadata->orientation)

Modified: trunk/src/rs-store.c
===================================================================
--- trunk/src/rs-store.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/rs-store.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -34,6 +34,7 @@
 #include "eog-pixbuf-cell-renderer.h"
 #include "rs-preload.h"
 #include "rs-photo.h"
+#include "rs-metadata.h"
 
 /* How many different icon views do we have (tabs) */
 #define NUM_VIEWS 6

Modified: trunk/src/tiff-meta.c
===================================================================
--- trunk/src/tiff-meta.c	2008-09-16 17:14:20 UTC (rev 2008)
+++ trunk/src/tiff-meta.c	2008-09-16 17:32:25 UTC (rev 2009)
@@ -27,6 +27,7 @@
 #include "rs-color-transform.h"
 #include "rs-utils.h"
 #include "rs-photo.h"
+#include "rs-metadata.h"
 
 /* It is required having some arbitrary maximum exposure time to prevent borked
  * shutter speed values being interpreted from the tiff.
@@ -1243,7 +1244,7 @@
 		}
 	}
 
-	rs_metadata_free(meta);
+	g_object_unref(meta);
 	raw_close_file(rawfile);
 
 	return(pixbuf);




More information about the Rawstudio-commit mailing list