[Rawstudio-commit] r2209 - in trunk: . plugins plugins/output-jpegfile plugins/output-pngfile plugins/output-tifffile
Anders Brander
anders at brander.dk
Sun Feb 22 17:06:59 CET 2009
Author: abrander
Date: 2009-02-22 17:06:59 +0100 (Sun, 22 Feb 2009)
New Revision: 2209
Added:
trunk/plugins/output-jpegfile/
trunk/plugins/output-jpegfile/Makefile.am
trunk/plugins/output-jpegfile/output-jpegfile.c
trunk/plugins/output-pngfile/
trunk/plugins/output-pngfile/Makefile.am
trunk/plugins/output-pngfile/output-pngfile.c
trunk/plugins/output-tifffile/
trunk/plugins/output-tifffile/Makefile.am
trunk/plugins/output-tifffile/output-tifffile.c
Modified:
trunk/configure.in
trunk/plugins/Makefile.am
Log:
Added RSJpegfile, RSPngfile and RSTifffile plugins.
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2009-02-22 16:05:14 UTC (rev 2208)
+++ trunk/configure.in 2009-02-22 16:06:59 UTC (rev 2209)
@@ -89,6 +89,9 @@
plugins/meta-raf/Makefile
plugins/meta-tiff/Makefile
plugins/meta-x3f/Makefile
+plugins/output-jpegfile/Makefile
+plugins/output-pngfile/Makefile
+plugins/output-tifffile/Makefile
plugins/resample/Makefile
plugins/rotate/Makefile
plugins/sharpen/Makefile
Modified: trunk/plugins/Makefile.am
===================================================================
--- trunk/plugins/Makefile.am 2009-02-22 16:05:14 UTC (rev 2208)
+++ trunk/plugins/Makefile.am 2009-02-22 16:06:59 UTC (rev 2209)
@@ -13,6 +13,9 @@
meta-raf \
meta-tiff \
meta-x3f \
+ output-jpegfile \
+ output-pngfile \
+ output-tifffile \
resample \
rotate \
sharpen \
Added: trunk/plugins/output-jpegfile/Makefile.am
===================================================================
--- trunk/plugins/output-jpegfile/Makefile.am (rev 0)
+++ trunk/plugins/output-jpegfile/Makefile.am 2009-02-22 16:06:59 UTC (rev 2209)
@@ -0,0 +1,21 @@
+plugindir = $(libdir)/rawstudio/plugins
+
+AM_CFLAGS =\
+ -Wall\
+ -O4
+
+AM_CXXFLAGS = $(AM_CFLAGS)
+
+INCLUDES = \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ @PACKAGE_CFLAGS@ \
+ -I../../librawstudio/
+
+lib_LTLIBRARIES = output_jpegfile.la
+
+libdir = $(datadir)/rawstudio/plugins/
+
+output_jpegfile_la_LIBADD = @PACKAGE_LIBS@
+output_jpegfile_la_LDFLAGS = -module -avoid-version
+output_jpegfile_la_SOURCES = output-jpegfile.c
Added: trunk/plugins/output-jpegfile/output-jpegfile.c
===================================================================
--- trunk/plugins/output-jpegfile/output-jpegfile.c (rev 0)
+++ trunk/plugins/output-jpegfile/output-jpegfile.c 2009-02-22 16:06:59 UTC (rev 2209)
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2006-2009 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 <rawstudio.h>
+#include <jpeglib.h>
+#include <gettext.h>
+#include "config.h"
+
+/* stat() */
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/* open() */
+#include <fcntl.h>
+
+#define RS_TYPE_JPEGFILE (rs_jpegfile_type)
+#define RS_JPEGFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_JPEGFILE, RSJpegfile))
+#define RS_JPEGFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_JPEGFILE, RSJpegfileClass))
+#define RS_IS_JPEGFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_JPEGFILE))
+
+typedef struct _RSJpegfile RSJpegfile;
+typedef struct _RSJpegfileClass RSJpegfileClass;
+
+struct _RSJpegfile {
+ RSOutput parent;
+
+ gchar *filename;
+ gint quality;
+};
+
+struct _RSJpegfileClass {
+ RSOutputClass parent_class;
+};
+
+RS_DEFINE_OUTPUT(rs_jpegfile, RSJpegfile)
+
+enum {
+ PROP_0,
+ PROP_FILENAME,
+ PROP_QUALITY
+};
+
+static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static gboolean execute8(RSOutput *output, GdkPixbuf *pixbuf);
+
+G_MODULE_EXPORT void
+rs_plugin_load(RSPlugin *plugin)
+{
+ rs_jpegfile_get_type(G_TYPE_MODULE(plugin));
+}
+
+static void
+rs_jpegfile_class_init(RSJpegfileClass *klass)
+{
+ RSOutputClass *output_class = RS_OUTPUT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_FILENAME, g_param_spec_string(
+ "filename", "filename", "Full export path",
+ NULL, G_PARAM_READWRITE)
+ );
+
+ g_object_class_install_property(object_class,
+ PROP_QUALITY, g_param_spec_int(
+ "quality", "JPEG Quality", _("JPEG Quality"),
+ 10, 100, 90, G_PARAM_READWRITE)
+ );
+
+ output_class->execute8 = execute8;
+ output_class->display_name = _("JPEG (Joint Photographic Experts Group)");
+}
+
+static void
+rs_jpegfile_init(RSJpegfile *jpegfile)
+{
+ jpegfile->filename = NULL;
+ jpegfile->quality = 90;
+}
+
+static void
+get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ RSJpegfile *jpegfile = RS_JPEGFILE(object);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ g_value_set_string(value, jpegfile->filename);
+ break;
+ case PROP_QUALITY:
+ g_value_set_int(value, jpegfile->quality);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ RSJpegfile *jpegfile = RS_JPEGFILE(object);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ jpegfile->filename = g_value_dup_string(value);
+ break;
+ case PROP_QUALITY:
+ jpegfile->quality = g_value_get_int(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+/* This following function is an almost verbatim copy from little cms. Thanks Marti, you rock! */
+
+#define ICC_MARKER (JPEG_APP0 + 2) /* JPEG marker code for ICC */
+#define ICC_OVERHEAD_LEN 14 /* size of non-profile data in APP2 */
+#define MAX_BYTES_IN_MARKER 65533 /* maximum data len of a JPEG marker */
+#define MAX_DATA_BYTES_IN_MARKER (MAX_BYTES_IN_MARKER - ICC_OVERHEAD_LEN)
+#define ICC_MARKER_IDENT "ICC_PROFILE"
+
+static void rs_jpeg_write_icc_profile(j_compress_ptr cinfo, const JOCTET *icc_data_ptr, guint icc_data_len);
+
+static void
+rs_jpeg_write_icc_profile(j_compress_ptr cinfo, const JOCTET *icc_data_ptr, guint icc_data_len)
+{
+ gchar *ident = ICC_MARKER_IDENT;
+ guint num_markers; /* total number of markers we'll write */
+ gint cur_marker = 1; /* per spec, counting starts at 1 */
+ guint length; /* number of bytes to write in this marker */
+
+ num_markers = icc_data_len / MAX_DATA_BYTES_IN_MARKER;
+ if (num_markers * MAX_DATA_BYTES_IN_MARKER != icc_data_len)
+ num_markers++;
+ while (icc_data_len > 0)
+ {
+ length = icc_data_len;
+ if (length > MAX_DATA_BYTES_IN_MARKER)
+ length = MAX_DATA_BYTES_IN_MARKER;
+ icc_data_len -= length;
+ jpeg_write_m_header(cinfo, ICC_MARKER, (guint) (length + ICC_OVERHEAD_LEN));
+
+ do {
+ jpeg_write_m_byte(cinfo, *ident);
+ } while(*ident++);
+ jpeg_write_m_byte(cinfo, cur_marker);
+ jpeg_write_m_byte(cinfo, (gint) num_markers);
+
+ while (length--)
+ {
+ jpeg_write_m_byte(cinfo, *icc_data_ptr);
+ icc_data_ptr++;
+ }
+ cur_marker++;
+ }
+ return;
+}
+
+static gboolean
+execute8(RSOutput *output, GdkPixbuf *pixbuf)
+{
+ RSJpegfile *jpegfile = RS_JPEGFILE(output);
+ struct jpeg_compress_struct cinfo;
+ struct jpeg_error_mgr jerr;
+ FILE * outfile;
+ JSAMPROW row_pointer[1];
+ gchar *profile_filename = NULL; /* FIXME: Fix this somehow */
+
+ guchar *buffer;
+ guint len;
+ gint fd;
+
+ cinfo.err = jpeg_std_error(&jerr);
+ jpeg_create_compress(&cinfo);
+ if ((outfile = fopen(jpegfile->filename, "wb")) == NULL)
+ return(FALSE);
+ jpeg_stdio_dest(&cinfo, outfile);
+ cinfo.image_width = gdk_pixbuf_get_width(pixbuf);
+ cinfo.image_height = gdk_pixbuf_get_height(pixbuf);
+ cinfo.input_components = gdk_pixbuf_get_n_channels(pixbuf);
+ cinfo.in_color_space = JCS_RGB;
+ jpeg_set_defaults(&cinfo);
+ jpeg_set_quality(&cinfo, jpegfile->quality, TRUE);
+ jpeg_start_compress(&cinfo, TRUE);
+ if (profile_filename)
+ {
+ struct stat st;
+ stat(profile_filename, &st);
+ if (st.st_size>0)
+ if ((fd = open(profile_filename, O_RDONLY)) != -1)
+ {
+ gint bytes_read = 0;
+ len = st.st_size;
+ buffer = g_malloc(len);
+ while(bytes_read < len)
+ bytes_read += read(fd, buffer+bytes_read, len-bytes_read);
+ close(fd);
+ rs_jpeg_write_icc_profile(&cinfo, buffer, len);
+ g_free(buffer);
+ }
+ }
+ while (cinfo.next_scanline < cinfo.image_height)
+ {
+ row_pointer[0] = GET_PIXBUF_PIXEL(pixbuf, 0, cinfo.next_scanline);
+ if (jpeg_write_scanlines(&cinfo, row_pointer, 1) != 1)
+ break;
+ }
+ jpeg_finish_compress(&cinfo);
+ fclose(outfile);
+ jpeg_destroy_compress(&cinfo);
+ return(TRUE);
+}
Added: trunk/plugins/output-pngfile/Makefile.am
===================================================================
--- trunk/plugins/output-pngfile/Makefile.am (rev 0)
+++ trunk/plugins/output-pngfile/Makefile.am 2009-02-22 16:06:59 UTC (rev 2209)
@@ -0,0 +1,21 @@
+plugindir = $(libdir)/rawstudio/plugins
+
+AM_CFLAGS =\
+ -Wall\
+ -O4
+
+AM_CXXFLAGS = $(AM_CFLAGS)
+
+INCLUDES = \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ @PACKAGE_CFLAGS@ \
+ -I../../librawstudio/
+
+lib_LTLIBRARIES = output_pngfile.la
+
+libdir = $(datadir)/rawstudio/plugins/
+
+output_pngfile_la_LIBADD = @PACKAGE_LIBS@
+output_pngfile_la_LDFLAGS = -module -avoid-version
+output_pngfile_la_SOURCES = output-pngfile.c
Added: trunk/plugins/output-pngfile/output-pngfile.c
===================================================================
--- trunk/plugins/output-pngfile/output-pngfile.c (rev 0)
+++ trunk/plugins/output-pngfile/output-pngfile.c 2009-02-22 16:06:59 UTC (rev 2209)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006-2009 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.
+ */
+
+/* Output plugin tmpl version 1 */
+
+#include <rawstudio.h>
+#include <gettext.h>
+#include "config.h"
+
+#define RS_TYPE_PNGFILE (rs_pngfile_type)
+#define RS_PNGFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_PNGFILE, RSPngfile))
+#define RS_PNGFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_PNGFILE, RSPngfileClass))
+#define RS_IS_PNGFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_PNGFILE))
+
+typedef struct _RSPngfile RSPngfile;
+typedef struct _RSPngfileClass RSPngfileClass;
+
+struct _RSPngfile {
+ RSOutput parent;
+
+ gchar *filename;
+ gint quality;
+};
+
+struct _RSPngfileClass {
+ RSOutputClass parent_class;
+};
+
+RS_DEFINE_OUTPUT(rs_pngfile, RSPngfile)
+
+enum {
+ PROP_0,
+ PROP_FILENAME
+};
+
+static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static gboolean execute8(RSOutput *output, GdkPixbuf *pixbuf);
+
+G_MODULE_EXPORT void
+rs_plugin_load(RSPlugin *plugin)
+{
+ rs_pngfile_get_type(G_TYPE_MODULE(plugin));
+}
+
+static void
+rs_pngfile_class_init(RSPngfileClass *klass)
+{
+ RSOutputClass *output_class = RS_OUTPUT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_FILENAME, g_param_spec_string(
+ "filename", "filename", "Full export path",
+ NULL, G_PARAM_READWRITE)
+ );
+
+ output_class->execute8 = execute8;
+ output_class->display_name = _("PNG (Portable Network Graphics)");
+}
+
+static void
+rs_pngfile_init(RSPngfile *pngfile)
+{
+ pngfile->filename = NULL;
+}
+
+static void
+get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ RSPngfile *pngfile = RS_PNGFILE(object);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ g_value_set_string(value, pngfile->filename);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ RSPngfile *pngfile = RS_PNGFILE(object);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ pngfile->filename = g_value_dup_string(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static gboolean
+execute8(RSOutput *output, GdkPixbuf *pixbuf)
+{
+ RSPngfile *pngfile = RS_PNGFILE(output);
+
+ return gdk_pixbuf_save(pixbuf, pngfile->filename, "png", NULL, NULL);
+}
Added: trunk/plugins/output-tifffile/Makefile.am
===================================================================
--- trunk/plugins/output-tifffile/Makefile.am (rev 0)
+++ trunk/plugins/output-tifffile/Makefile.am 2009-02-22 16:06:59 UTC (rev 2209)
@@ -0,0 +1,21 @@
+plugindir = $(libdir)/rawstudio/plugins
+
+AM_CFLAGS =\
+ -Wall\
+ -O4
+
+AM_CXXFLAGS = $(AM_CFLAGS)
+
+INCLUDES = \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ @PACKAGE_CFLAGS@ \
+ -I../../librawstudio/
+
+lib_LTLIBRARIES = output_tifffile.la
+
+libdir = $(datadir)/rawstudio/plugins/
+
+output_tifffile_la_LIBADD = @PACKAGE_LIBS@
+output_tifffile_la_LDFLAGS = -module -avoid-version
+output_tifffile_la_SOURCES = output-tifffile.c
Added: trunk/plugins/output-tifffile/output-tifffile.c
===================================================================
--- trunk/plugins/output-tifffile/output-tifffile.c (rev 0)
+++ trunk/plugins/output-tifffile/output-tifffile.c 2009-02-22 16:06:59 UTC (rev 2209)
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2006-2009 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 <rawstudio.h>
+#include <tiffio.h>
+#include <gettext.h>
+#include "config.h"
+
+#define RS_TYPE_TIFFFILE (rs_tifffile_type)
+#define RS_TIFFFILE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), RS_TYPE_TIFFFILE, RSTifffile))
+#define RS_TIFFFILE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), RS_TYPE_TIFFFILE, RSTifffileClass))
+#define RS_IS_TIFFFILE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), RS_TYPE_TIFFFILE))
+
+typedef struct _RSTifffile RSTifffile;
+typedef struct _RSTifffileClass RSTifffileClass;
+
+struct _RSTifffile {
+ RSOutput parent;
+
+ gchar *filename;
+ gboolean uncompressed;
+};
+
+struct _RSTifffileClass {
+ RSOutputClass parent_class;
+};
+
+RS_DEFINE_OUTPUT(rs_tifffile, RSTifffile)
+
+enum {
+ PROP_0,
+ PROP_FILENAME,
+ PROP_UNCOMPRESSED
+};
+
+static void get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
+static void set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
+static gboolean execute8(RSOutput *output, GdkPixbuf *pixbuf);
+
+G_MODULE_EXPORT void
+rs_plugin_load(RSPlugin *plugin)
+{
+ rs_tifffile_get_type(G_TYPE_MODULE(plugin));
+}
+
+static void
+rs_tifffile_class_init(RSTifffileClass *klass)
+{
+ RSOutputClass *output_class = RS_OUTPUT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
+
+ object_class->get_property = get_property;
+ object_class->set_property = set_property;
+
+ g_object_class_install_property(object_class,
+ PROP_FILENAME, g_param_spec_string(
+ "filename", "filename", "Full export path",
+ NULL, G_PARAM_READWRITE)
+ );
+
+ g_object_class_install_property(object_class,
+ PROP_UNCOMPRESSED, g_param_spec_boolean(
+ "uncompressed", "Uncompressed TIFF", _("Save uncompressed TIFF"),
+ FALSE, G_PARAM_READWRITE)
+ );
+
+ output_class->execute8 = execute8;
+ output_class->display_name = _("TIFF (Tagged Image File Format)");
+}
+
+static void
+rs_tifffile_init(RSTifffile *tifffile)
+{
+ tifffile->filename = NULL;
+ tifffile->uncompressed = FALSE;
+}
+
+static void
+get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
+{
+ RSTifffile *tifffile = RS_TIFFFILE(object);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ g_value_set_string(value, tifffile->filename);
+ break;
+ case PROP_UNCOMPRESSED:
+ g_value_set_boolean(value, tifffile->uncompressed);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+{
+ RSTifffile *tifffile = RS_TIFFFILE(object);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ tifffile->filename = g_value_dup_string(value);
+ break;
+ case PROP_UNCOMPRESSED:
+ tifffile->uncompressed = g_value_get_boolean(value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void rs_tiff_generic_init(TIFF *output, guint w, guint h, const guint samples_per_pixel, const gchar *profile_filename, gboolean uncompressed);
+
+static void
+rs_tiff_generic_init(TIFF *output, guint w, guint h, const guint samples_per_pixel, const gchar *profile_filename, gboolean uncompressed)
+{
+ TIFFSetField(output, TIFFTAG_IMAGEWIDTH, w);
+ TIFFSetField(output, TIFFTAG_IMAGELENGTH, h);
+ TIFFSetField(output, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
+ TIFFSetField(output, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);
+ TIFFSetField(output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
+ TIFFSetField(output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
+ if (uncompressed)
+ TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
+ else
+ {
+ TIFFSetField(output, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
+ TIFFSetField(output, TIFFTAG_ZIPQUALITY, 9);
+ }
+ if (profile_filename)
+ {
+ gchar *buffer = NULL;
+ gsize length = 0;
+
+ if (g_file_get_contents(profile_filename, &buffer, &length, NULL))
+ TIFFSetField(output, TIFFTAG_ICCPROFILE, length, buffer);
+
+ g_free(buffer);
+ }
+ TIFFSetField(output, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(output, 0));
+}
+
+static gboolean
+execute8(RSOutput *output, GdkPixbuf *pixbuf)
+{
+ RSTifffile *tifffile = RS_TIFFFILE(output);
+ const gchar *profile_filename = NULL;
+ TIFF *tiff;
+ gint row;
+
+ if((tiff = TIFFOpen(tifffile->filename, "w")) == NULL)
+ return(FALSE);
+ rs_tiff_generic_init(tiff, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), 3, profile_filename, tifffile->uncompressed);
+ TIFFSetField(tiff, TIFFTAG_BITSPERSAMPLE, 8);
+ for(row=0;row<gdk_pixbuf_get_height(pixbuf);row++)
+ {
+ guchar *buf = GET_PIXBUF_PIXEL(pixbuf, 0, row);
+ TIFFWriteScanline(tiff, buf, row, 0);
+ }
+ TIFFClose(tiff);
+ return(TRUE);
+}
+#if 0
+/* FIXME: Fix tiff 16 bit .. NOW! */
+static gboolean
+rs_tiff16_save(RS_IMAGE16 *image, const gchar *filename, const gchar *profile_filename, gboolean uncompressed)
+{
+ TIFF *output;
+ gint row;
+
+ if ((!g_file_test(filename, G_FILE_TEST_EXISTS)) && (output = TIFFOpen(filename, "w")))
+ {
+ rs_tiff_generic_init(output, image->w, image->h, image->channels, profile_filename, uncompressed);
+ TIFFSetField(output, TIFFTAG_BITSPERSAMPLE, 16);
+ for(row=0;row<image->h;row++)
+ {
+ gushort *buf = GET_PIXEL(image, 0, row);
+ TIFFWriteScanline(output, buf, row, 0);
+ }
+ TIFFClose(output);
+ }
+ else
+ return FALSE;
+
+ return TRUE;
+}
+#endif
More information about the Rawstudio-commit
mailing list