Return-Path: <tiff-bounces@remotesensing.org>
Received: from inav007.isp.belgacom.be (inav007.isp.belgacom.be [195.238.2.76])
        by mailst035.isp.belgacom.be (8.12.11/8.12.11/Skynet-MAILSTORE-2.14) with ESMTP id iA3JqA4B012496
        for <joris.at.lebbeke@skynet.be>; Wed, 3 Nov 2004 20:52:10 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from inas001.isp.belgacom.be (localhost [127.0.0.1])
        by inav007.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AV-3.00) with ESMTP id iA3Jq5SE012426
        for <joris.at.lebbeke@skynet.be>; Wed, 3 Nov 2004 20:52:06 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from inmx006.isp.belgacom.be (inmx006.isp.belgacom.be [195.238.2.106])
        by inas001.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-AS-2.03) with ESMTP id iA3Jpxqa025009
        for <joris.at.lebbeke@skynet.be>; Wed, 3 Nov 2004 20:52:00 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from xserve.flids.com (adsl-065-083-169-202.sip.mco.bellsouth.net [65.83.169.202])
        by inmx006.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id iA3JpkhZ020249
        for <joris.at.lebbeke@skynet.be>; Wed, 3 Nov 2004 20:51:49 +0100
        (envelope-from <tiff-bounces@remotesensing.org>)
Received: from adsl-065-083-169-202.sip.mco.bellsouth.net (localhost [127.0.0.1])
	by xserve.flids.com (Postfix) with ESMTP
	id 5AEB2442CCA; Wed,  3 Nov 2004 14:51:15 -0500 (EST)
X-Original-To: tiff@remotesensing.org
Delivered-To: tiff@remotesensing.org
Received: from mail.sidefx.com (tor149-99-58-193.dedicated.sprintdsl.ca
	[149.99.58.193])
	by xserve.flids.com (Postfix) with ESMTP id DE979442CA7
	for <tiff@remotesensing.org>; Wed,  3 Nov 2004 14:51:11 -0500 (EST)
Received: from [192.168.237.144] (crete.ithaca.sidefx.com[192.168.237.144])
	by mail.sidefx.com (Smail-3.2.0.111 2000-Feb-17 #5; 2004-May-20)
	(7635 bytes) via sendmail with /P:esmtp/R:inet_hosts/T:smtp
	id <m1CPR9z-004OnhC@mail.sidefx.com> (sender <edward@sidefx.com>)
	for <tiff@remotesensing.org>; Wed, 3 Nov 2004 14:51:11 -0500 (EST)
Message-ID: <418936AE.1010504@sidefx.com>
Date: Wed, 03 Nov 2004 14:51:10 -0500
From: Edward Lam <edward@sidefx.com>
User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913)
X-Accept-Language: en-us, en
MIME-Version: 1.0
To: tiff@remotesensing.org
Content-Type: multipart/mixed; boundary="------------070506040008000008030903"
Subject: [Tiff] [Patch] TIFFStreamOpen()
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.1.2
Precedence: list
List-Id: TIFF and libtiff discussion  <tiff.remotesensing.org>
List-Unsubscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=unsubscribe>
List-Archive: <http://xserve.flids.com/pipermail/tiff>
List-Post: <mailto:tiff@remotesensing.org>
List-Help: <mailto:tiff-request@remotesensing.org?subject=help>
List-Subscribe: <http://xserve.flids.com/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=subscribe>
Sender: tiff-bounces@remotesensing.org
Errors-To: tiff-bounces@remotesensing.org
X-UIDL: 83d7579c4a268c96e2bddf7fa2bb91bc

This is a multi-part message in MIME format.
--------------070506040008000008030903
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

These changes have been sitting in our baseline for quite a while (since 3.4) 
now and so I might as well submit them as others might find it useful. And if 
it's gets accepted, it saves me work the next time I upgrade. :)

The patch was created against CVS HEAD. It modifies tiffio.h and adds a new 
file, tif_stream.C. It adds two new functions to support reading/writing tiff 
files via C++ streams. tiffio.h is modified to include the two new prototypes 
like so:

#if defined(c_plusplus) || defined(__cplusplus)
   #include <iostream.h>
   extern	TIFF* TIFFStreamOpen(const char*, ostream *);
   extern	TIFF* TIFFStreamOpen(const char*, istream *);
+#endif

The first version allows one to write a tiff file to the given ostream using the 
name given in the first parameter. The second one allows you to read from the 
given istream. They were written to provide an easy way in C++ to read and write 
tiff images embedded in other files. These are implemented in the new 
tif_stream.C file.

Thanks,
-Edward



--------------070506040008000008030903
Content-Type: text/plain;
 name="TIFFStreamOpen.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="TIFFStreamOpen.patch"

Index: tiffio.h
===================================================================
RCS file: /cvs/maptools/cvsroot/libtiff/libtiff/tiffio.h,v
retrieving revision 1.36
diff -u -d -p -r1.36 tiffio.h
--- tiffio.h	24 Sep 2004 15:18:57 -0000	1.36
+++ tiffio.h	3 Nov 2004 19:39:26 -0000
@@ -492,6 +492,13 @@ extern  void TIFFSetClientInfo( TIFF *, 
 #if defined(__cplusplus)
 }
 #endif
+
+#if defined(c_plusplus) || defined(__cplusplus)
+#include <iostream.h>
+extern	TIFF* TIFFStreamOpen(const char*, ostream *);
+extern	TIFF* TIFFStreamOpen(const char*, istream *);
+#endif
+
 #endif /* _TIFFIO_ */
 
 /* vim: set ts=8 sts=8 sw=8 noet: */
--- /dev/null	Wed Nov 03 14:39:44 2004
+++ tif_stream.C	Wed Nov 03 11:38:00 2004
@@ -0,0 +1,214 @@
+
+/*
+ * Copyright (c) 1988-1996 Sam Leffler
+ * Copyright (c) 1991-1996 Silicon Graphics, Inc.
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and 
+ * its documentation for any purpose is hereby granted without fee, provided
+ * that (i) the above copyright notices and this permission notice appear in
+ * all copies of the software and related documentation, and (ii) the names of
+ * Sam Leffler and Silicon Graphics may not be used in any advertising or
+ * publicity relating to the software without the specific, prior written
+ * permission of Sam Leffler and Silicon Graphics.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
+ * 
+ * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
+ * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
+ * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+ * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
+ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
+ * OF THIS SOFTWARE.
+ */
+
+/*
+ * TIFF Library UNIX-specific Routines.
+ */
+#include <iostream.h>
+#include "tiffiop.h"
+
+class tiffis_data
+{
+public:
+    istream	*myIS;
+    long	 myStreamStartPos;
+};
+
+static tsize_t
+_tiffosReadProc(thandle_t, tdata_t, tsize_t)
+{
+    return 0;
+}
+
+static tsize_t
+_tiffisReadProc(thandle_t fd, tdata_t buf, tsize_t size)
+{
+    tiffis_data	*data = (tiffis_data *)fd;
+
+    data->myIS->read((char *)buf, size);
+
+    return data->myIS->gcount();
+}
+
+static tsize_t
+_tiffosWriteProc(thandle_t fd, tdata_t buf, tsize_t size)
+{
+    ostream	*os = (ostream *)fd;
+    int		 pos = os->tellp();
+
+    os->write((const char *)buf, size);
+
+    return ((int)os->tellp()) - pos;
+}
+
+static tsize_t
+_tiffisWriteProc(thandle_t, tdata_t, tsize_t)
+{
+    return 0;
+}
+
+static toff_t
+_tiffosSeekProc(thandle_t fd, toff_t off, int whence)
+{
+    ostream	*os = (ostream *)fd;
+
+    switch( whence )
+    {
+	case SEEK_SET:
+	    os->seekp(off, ios::beg);
+	    break;
+	case SEEK_CUR:
+	    os->seekp(off, ios::cur);
+	    break;
+	case SEEK_END:
+	    os->seekp(off, ios::end);
+	    break;
+    }
+
+    return os->tellp();
+}
+
+static toff_t
+_tiffisSeekProc(thandle_t fd, toff_t off, int whence)
+{
+    tiffis_data	*data = (tiffis_data *)fd;
+
+    switch( whence )
+    {
+	case SEEK_SET:
+	    data->myIS->seekg(data->myStreamStartPos + off, ios::beg);
+	    break;
+	case SEEK_CUR:
+	    data->myIS->seekg(off, ios::cur);
+	    break;
+	case SEEK_END:
+	    data->myIS->seekg(off, ios::end);
+	    break;
+    }
+
+    return ((long)data->myIS->tellg()) - data->myStreamStartPos;
+}
+
+static toff_t
+_tiffosSizeProc(thandle_t fd)
+{
+    ostream	*os = (ostream *)fd;
+    int		 pos = os->tellp();
+    int		 len;
+
+    os->seekp(0, ios::end);
+    len = os->tellp();
+    os->seekp(pos);
+
+    return len;
+}
+
+static toff_t
+_tiffisSizeProc(thandle_t fd)
+{
+    tiffis_data	*data = (tiffis_data *)fd;
+    int		 pos = data->myIS->tellg();
+    int		 len;
+
+    data->myIS->seekg(0, ios::end);
+    len = data->myIS->tellg();
+    data->myIS->seekg(pos);
+
+    return len;
+}
+
+static int
+_tiffosCloseProc(thandle_t fd)
+{
+    // Our stream was not allocated by us, so it shouldn't be closed by us.
+    return 0;
+}
+
+static int
+_tiffisCloseProc(thandle_t fd)
+{
+    // Our stream was not allocated by us, so it shouldn't be closed by us.
+    delete (tiffis_data *)fd;
+    return 0;
+}
+
+static int
+_tiffDummyMapProc(thandle_t , tdata_t* , toff_t* )
+{
+	return (0);
+}
+
+static void
+_tiffDummyUnmapProc(thandle_t , tdata_t , toff_t )
+{
+}
+
+/*
+ * Open a TIFF file descriptor for read/writing.
+ */
+static TIFF*
+_tiffStreamOpen(const char* name, const char* mode, void *fd)
+{
+	TIFF*	    tif;
+
+	if( strchr(mode, 'w') )
+	{
+	    // Open for writing.
+	    tif = TIFFClientOpen(name, mode,
+		(thandle_t) fd,
+		_tiffosReadProc, _tiffosWriteProc,
+		_tiffosSeekProc, _tiffosCloseProc, _tiffosSizeProc,
+		_tiffDummyMapProc, _tiffDummyUnmapProc);
+	}
+	else
+	{
+	    tiffis_data	*data = new tiffis_data;
+	    data->myIS = (istream *)fd;
+	    data->myStreamStartPos = data->myIS->tellg();
+	    // Open for reading.
+	    tif = TIFFClientOpen(name, mode,
+		(thandle_t) data,
+		_tiffisReadProc, _tiffisWriteProc,
+		_tiffisSeekProc, _tiffisCloseProc, _tiffisSizeProc,
+		_tiffDummyMapProc, _tiffDummyUnmapProc);
+	}
+
+	return (tif);
+}
+
+TIFF*
+TIFFStreamOpen(const char* name, ostream *os)
+{
+	// NB: We don't support mapped files with streams
+	return _tiffStreamOpen(name, "wm", os);
+}
+
+TIFF*
+TIFFStreamOpen(const char* name, istream *is)
+{
+	// NB: We don't support mapped files with streams
+	return _tiffStreamOpen(name, "rm", is);
+}
+

--------------070506040008000008030903
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://xserve.flids.com/mailman/listinfo/tiff

--------------070506040008000008030903--
