[patch] Pentax raw file suport
"Petr Kovar" <[email protected]> Tue, 7 Nov 2006 16:13:37 +0100
| Newsgroups | gmane.comp.gnome.apps.gqview.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi, I am owner of Pentax K100D camera and happy GQview user. Unfortunately GQview hasn't support for Pentax raw format (.pef). GQview can read Exif data but can not read thumbnails from .pef files. I found out that it is possibe to use the same method like for Nikon files. Patch is included. If you, John, need .pef files for testing I can send you some. With regards. -- Petr Kovar <[email protected]> ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Gqview-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gqview-devel
gqview-2.1.4-pentax.patch
(text/x-patch, 7.2 KB)
diff -ruN gqview-2.1.4/src/filelist.c gqview-2.1.4-pentax/src/filelist.c
--- gqview-2.1.4/src/filelist.c 2006-10-19 11:50:36.000000000 +0200
+++ gqview-2.1.4-pentax/src/filelist.c 2006-11-07 14:56:13.000000000 +0100
@@ -215,6 +215,7 @@
filter_add_if_missing("crw", "Canon raw format", ".crw;.cr2", TRUE);
filter_add_if_missing("raf", "Fujifilm raw format", ".raf", TRUE);
filter_add_if_missing("nef", "Nikon raw format", ".nef", TRUE);
+ filter_add_if_missing("pef", "Pentax raw format", ".pef", TRUE);
}
static GList *filter_to_list(const gchar *extensions)
diff -ruN gqview-2.1.4/src/format_pentax.c gqview-2.1.4-pentax/src/format_pentax.c
--- gqview-2.1.4/src/format_pentax.c 1970-01-01 01:00:00.000000000 +0100
+++ gqview-2.1.4-pentax/src/format_pentax.c 2006-11-07 14:56:13.000000000 +0100
@@ -0,0 +1,157 @@
+/*
+ * GQView
+ * (C) 2005 John Ellis
+ *
+ * Authors:
+ * Raw NEF jpeg extraction based on nefextract.c by Joseph Heled,
+ * in addition nefextract.c is based on dcraw by Dave Coffin.
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "intl.h"
+
+#include "format_pentax.h"
+
+#include "exif.h"
+
+
+/*
+ *-----------------------------------------------------------------------------
+ * Raw PEF embedded jpeg extraction for Pentax
+ *-----------------------------------------------------------------------------
+ */
+
+static guint pentax_tiff_table(unsigned char *data, const guint len, guint offset, ExifByteOrder bo,
+ gint level,
+ guint *image_offset, guint *jpeg_len);
+
+
+static void pentax_tiff_entry(unsigned char *data, const guint len, guint offset, ExifByteOrder bo,
+ gint level,
+ guint *image_offset, guint *image_length, guint *jpeg_start, guint *jpeg_len)
+{
+ guint tag;
+ guint type;
+ guint count;
+ guint segment;
+ guint seg_len;
+
+ tag = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_TAG, bo);
+ type = exif_byte_get_int16(data + offset + EXIF_TIFD_OFFSET_FORMAT, bo);
+ count = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_COUNT, bo);
+
+ /* so far, we only care about tags with type long */
+ if (type != EXIF_FORMAT_LONG_UNSIGNED && type != EXIF_FORMAT_LONG) return;
+
+ seg_len = ExifFormatList[type].size * count;
+ if (seg_len > 4)
+ {
+ segment = exif_byte_get_int32(data + offset + EXIF_TIFD_OFFSET_DATA, bo);
+ if (segment + seg_len > len) return;
+ }
+ else
+ {
+ segment = offset + EXIF_TIFD_OFFSET_DATA;
+ }
+
+ if (tag == 0x14a)
+ {
+ /* sub IFD table */
+ gint i;
+
+ for (i = 0; i < count; i++)
+ {
+ guint subset;
+
+ subset = exif_byte_get_int32(data + segment + i * 4, bo);
+ pentax_tiff_table(data, len, subset, bo, level + 1, image_offset, image_length);
+ }
+
+ }
+ else if (tag == 0x201)
+ {
+ /* jpeg data start offset */
+ *jpeg_start = exif_byte_get_int32(data + segment, bo);
+ }
+ else if (tag == 0x202)
+ {
+ /* jpeg data length */
+ *jpeg_len = exif_byte_get_int32(data + segment, bo);
+ }
+}
+
+static guint pentax_tiff_table(unsigned char *data, const guint len, guint offset, ExifByteOrder bo,
+ gint level,
+ guint *image_offset, guint *image_length)
+{
+ guint count;
+ guint i;
+ guint jpeg_start = 0;
+ guint jpeg_len = 0;
+
+ /* limit damage from infinite loops */
+ if (level > EXIF_TIFF_MAX_LEVELS) return 0;
+
+ if (len < offset + 2) return FALSE;
+
+ count = exif_byte_get_int16(data + offset, bo);
+ offset += 2;
+ if (len < offset + count * EXIF_TIFD_SIZE + 4) return 0;
+
+ for (i = 0; i < count; i++)
+ {
+ pentax_tiff_entry(data, len, offset + i * EXIF_TIFD_SIZE, bo, level,
+ image_offset, image_length, &jpeg_start, &jpeg_len);
+ }
+
+ if (jpeg_start > 0 &&
+ jpeg_len > *image_length)
+ {
+ *image_offset = jpeg_start;
+ *image_length = jpeg_len;
+ }
+
+ return exif_byte_get_int32(data + offset + count * EXIF_TIFD_SIZE, bo);
+}
+
+gint format_pentax_raw(unsigned char *data, const guint len,
+ guint *image_offset, guint *exif_offset)
+{
+ guint i_off = 0;
+ guint i_len = 0;
+ ExifByteOrder bo;
+ guint offset;
+ gint level;
+
+ if (!exif_tiff_directory_offset(data, len, &offset, &bo)) return FALSE;
+
+ level = 0;
+ while (offset && level < EXIF_TIFF_MAX_LEVELS)
+ {
+ offset = pentax_tiff_table(data, len, offset, bo, 0, &i_off, &i_len);
+ level++;
+ }
+
+ if (i_off != 0)
+ {
+ if (image_offset) *image_offset = i_off;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
diff -ruN gqview-2.1.4/src/format_pentax.h gqview-2.1.4-pentax/src/format_pentax.h
--- gqview-2.1.4/src/format_pentax.h 1970-01-01 01:00:00.000000000 +0100
+++ gqview-2.1.4-pentax/src/format_pentax.h 2006-11-07 14:56:13.000000000 +0100
@@ -0,0 +1,24 @@
+/*
+ * GQView
+ * (C) 2005 John Ellis
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#ifndef __FORMAT_PENTAX_H
+#define __FORMAT_PENTAX_H
+
+
+#include "exif.h"
+
+gint format_pentax_raw(unsigned char *data, const guint len,
+ guint *image_offset, guint *exif_offset);
+
+#define FORMAT_RAW_PENTAX { "pef", \
+ FORMAT_RAW_MATCH_MAGIC, 242, "PENTAX Corporation", 18, \
+ "Pentax raw", format_pentax_raw }
+
+#endif
+
diff -ruN gqview-2.1.4/src/format_raw.c gqview-2.1.4-pentax/src/format_raw.c
--- gqview-2.1.4/src/format_raw.c 2005-06-13 01:25:08.000000000 +0200
+++ gqview-2.1.4-pentax/src/format_raw.c 2006-11-07 14:56:13.000000000 +0100
@@ -31,6 +31,7 @@
#include "format_canon.h"
#include "format_fuji.h"
#include "format_nikon.h"
+#include "format_pentax.h"
#include "format_olympus.h"
@@ -53,6 +54,7 @@
FORMAT_RAW_CANON,
FORMAT_RAW_FUJI,
FORMAT_RAW_NIKON,
+ FORMAT_RAW_PENTAX,
{ NULL, 0, 0, NULL, 0, NULL, NULL }
};
diff -ruN gqview-2.1.4/src/Makefile.am gqview-2.1.4-pentax/src/Makefile.am
--- gqview-2.1.4/src/Makefile.am 2005-06-10 19:10:14.000000000 +0200
+++ gqview-2.1.4-pentax/src/Makefile.am 2006-11-07 14:56:13.000000000 +0100
@@ -90,6 +90,8 @@
format_fuji.h \
format_nikon.c \
format_nikon.h \
+ format_pentax.c \
+ format_pentax.h \
format_olympus.c \
format_olympus.h \
format_raw.c \
diff -ruN gqview-2.1.4/src/Makefile.in gqview-2.1.4-pentax/src/Makefile.in
--- gqview-2.1.4/src/Makefile.in 2006-11-04 23:14:39.000000000 +0100
+++ gqview-2.1.4-pentax/src/Makefile.in 2006-11-07 14:56:13.000000000 +0100
@@ -60,7 +60,7 @@
collect-table.$(OBJEXT) dnd.$(OBJEXT) dupe.$(OBJEXT) \
editors.$(OBJEXT) exif.$(OBJEXT) filelist.$(OBJEXT) \
format_canon.$(OBJEXT) format_fuji.$(OBJEXT) \
- format_nikon.$(OBJEXT) format_olympus.$(OBJEXT) \
+ format_nikon.$(OBJEXT) format_pentax.$(OBJEXT) format_olympus.$(OBJEXT) \
format_raw.$(OBJEXT) fullscreen.$(OBJEXT) globals.$(OBJEXT) \
image.$(OBJEXT) image-load.$(OBJEXT) image-overlay.$(OBJEXT) \
img-view.$(OBJEXT) info.$(OBJEXT) layout.$(OBJEXT) \
@@ -270,6 +270,8 @@
format_fuji.h \
format_nikon.c \
format_nikon.h \
+ format_pentax.c \
+ format_pentax.h \
format_olympus.c \
format_olympus.h \
format_raw.c \