Return-Path: <tiff-bounces@remotesensing.org>
Received: from inmx014.isp.belgacom.be (inmx014.isp.belgacom.be [195.238.2.217])
        by mailst034.isp.belgacom.be (8.12.11/8.12.11/Skynet-MAILSTORE-2.14) with ESMTP id i8SFSVNA000800
        for <joris.at.lebbeke@skynet.be>; Tue, 28 Sep 2004 17:28:32 +0200
        (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 inmx014.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id i8SFSBCx015649
        for <joris.at.lebbeke@skynet.be>; Tue, 28 Sep 2004 17:28:14 +0200
        (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 1F4033328D0; Tue, 28 Sep 2004 11:27:35 -0400 (EDT)
X-Original-To: tiff@remotesensing.org
Delivered-To: tiff@remotesensing.org
Received: from Alias.com (mail.alias.com [209.167.159.11])
	by xserve.flids.com (Postfix) with ESMTP id 058933328C0
	for <tiff@remotesensing.org>; Tue, 28 Sep 2004 11:27:33 -0400 (EDT)
Received: from ([192.75.21.156])
	by ironmail.Alias.com with ESMTP  id KP-ADYT0.7477400;
	Tue, 28 Sep 2004 11:26:44 -0400
Received: from mailsrv1.tor.aw.sgi.com (mailsrv1.tor.aw.sgi.com [192.75.20.57])
	by alias-relay.tor.aw.sgi.com (SGI-8.12.5/8.12.5) with ESMTP id
	i8SFQire10025335
	for <tiff@remotesensing.org>; Tue, 28 Sep 2004 11:26:44 -0400 (EDT)
Received: from pc-ian.alias.com by mailsrv1.tor.aw.sgi.com (SGI-8.12.5/8.6.9)
	with ESMTP id i8SFQi6F5950438 for <tiff@remotesensing.org>;
	Tue, 28 Sep 2004 11:26:44 -0400 (EDT)
Message-Id: <4.3.2.7.2.20040928110855.01757788@mailsrv1>
X-Sender: ameline@mailsrv1
X-Mailer: QUALCOMM Windows Eudora Version 4.3.2
Date: Tue, 28 Sep 2004 11:26:29 -0400
To: <tiff@remotesensing.org>
From: Ian Ameline <iameline@alias.com>
In-Reply-To: <002901c4a4c8$f8c82fe0$48cbc950@dfgrrxsknr4e>
References: <4.3.2.7.2.20040914173217.017dc7a0@mailsrv1>
	<4.3.2.7.2.20040927150814.01720f18@mailsrv1>
Mime-Version: 1.0
Subject: [Tiff] TIFF *TIFFOpenW(const wchar_t *name, const char *mode);
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>
Content-Type: multipart/mixed; boundary="===============30519456698117553=="
Sender: tiff-bounces@remotesensing.org
Errors-To: tiff-bounces@remotesensing.org
X-UIDL: 157bcc0522cce739a4b92f0861f1d724

--===============30519456698117553==
Content-Type: multipart/alternative;
	boundary="=====================_82555125==_.ALT"

--=====================_82555125==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

Hi again everyone,

While updating the version of LbTIFF that Sketchbook uses to 3.6.1, I once 
again noticed that besides the configuration and LZW stuff, there was one 
place where I was merging code -- A new function we have implemented called 
TIFFOpenW;

We produce a Japanese version of Alias Sketchbook, and on windows, to 
create or open files with Japanese filenames, you need to use wide 
characters. On Mac, we don't need to do this -- we just call TIFFOpen with 
a UTF8 character string and everything works nicely. Not so on Windows. So 
we created a function TIFFOpenW which is identical to TIFFOpen, but taking 
wchar_t * instead of char *. TIFFOpen becomes pretty vestigial in that it 
converts it's char string to wchar and calls TIFFOpenW.

I was wondering what everyone thought of rolling this up into libtiff 3.7.0 
as a windows only function? (Saving me the work of merging again in the 
future :-)

Code from tif_win32.c follows;

/*
  * Open a TIFF file for read/writing.
  */
TIFF*
TIFFOpen(const char* name, const char* mode)
{
     wchar_t wname[MAX_PATH];
     mbstowcs(wname, name, MAX_PATH);
     return TIFFOpenW(wname, mode);
}

/*
  * Open a TIFF file, with a Unicode filename, for read/writing.
  */
TIFF*
TIFFOpenW(const wchar_t* name, const char* mode)
{
     static const char module[] = "TIFFOpen";
     thandle_t fd;
     int       m;
     DWORD     dwMode;
     int       mbsize;
     char     *mbname;
     TIFF     *tif;

     m = _TIFFgetMode(mode, module);

     switch(m)   {
         case O_RDONLY:               dwMode = OPEN_EXISTING; break;
         case O_RDWR:                 dwMode = OPEN_ALWAYS;   break;
         case O_RDWR|O_CREAT:         dwMode = OPEN_ALWAYS;   break;
         case O_RDWR|O_TRUNC:         dwMode = CREATE_ALWAYS; break;
         case O_RDWR|O_CREAT|O_TRUNC: dwMode = CREATE_ALWAYS; break;
         default: return ((TIFF*)0);
     }

     fd = (thandle_t)CreateFileW(name, (m == O_RDONLY) ? GENERIC_READ :
                        (GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ, 
NULL, dwMode,
                        (m == O_RDONLY) ? FILE_ATTRIBUTE_READONLY : 
FILE_ATTRIBUTE_NORMAL, NULL);
     if (fd == INVALID_HANDLE_VALUE) {
         TIFFError(module, "%S: Cannot open", name);
         return ((TIFF *)0);
     }

     mbname = NULL;
     mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1, NULL, 0, NULL, NULL);
     if (mbsize > 0) {
         mbname = malloc(mbsize);
         if (mbname != NULL) {
             WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, NULL, 
NULL);
         }
     }

     tif = TIFFFdOpen((int)fd, (mbname != NULL) ? mbname : "<unknown>", mode);

     if (mbname != NULL) {
         free(mbname);
     }

     return tif;
}

--
Regards,
Ian Ameline,
Software Architect,
Alias SketchBook Technical Lead.

-- Always do the right thing. This will gratify
some people and astonish the rest. -- Mark Twain.

--=====================_82555125==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<font size=3>Hi again everyone,<br>
<br>
While updating the version of LbTIFF that Sketchbook uses to 3.6.1, I
once again noticed that besides the configuration and LZW stuff, there
was one place where I was merging code -- A new function we have
implemented called TIFFOpenW;<br>
<br>
We produce a Japanese version of Alias Sketchbook, and on windows, to
create or open files with Japanese filenames, you need to use wide
characters. On Mac, we don't need to do this -- we just call TIFFOpen
with a UTF8 character string and everything works nicely. Not so on
Windows. So we created a function TIFFOpenW which is identical to
TIFFOpen, but taking wchar_t * instead of char *. TIFFOpen becomes pretty
vestigial in that it converts it's char string to wchar and calls
TIFFOpenW.<br>
<br>
I was wondering what everyone thought of rolling this up into libtiff
3.7.0 as a windows only function? (Saving me the work of merging again in
the future :-)<br>
<br>
Code from tif_win32.c follows;<br>
<br>
/*<br>
&nbsp;* Open a TIFF file for read/writing.<br>
&nbsp;*/<br>
TIFF*<br>
TIFFOpen(const char* name, const char* mode)<br>
{<br>
&nbsp;&nbsp;&nbsp; wchar_t wname[MAX_PATH];<br>
&nbsp;&nbsp;&nbsp; mbstowcs(wname, name, MAX_PATH);<br>
&nbsp;&nbsp;&nbsp; return TIFFOpenW(wname, mode);<br>
}<br>
<br>
/*<br>
&nbsp;* Open a TIFF file, with a Unicode filename, for 
read/writing.<br>
&nbsp;*/<br>
TIFF*<br>
TIFFOpenW(const wchar_t* name, const char* mode)<br>
{<br>
&nbsp;&nbsp;&nbsp; static const char module[] =
&quot;TIFFOpen&quot;;<br>
&nbsp;&nbsp;&nbsp; thandle_t fd;<br>
&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m;<br>
&nbsp;&nbsp;&nbsp; DWORD&nbsp;&nbsp;&nbsp;&nbsp; dwMode;<br>
&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mbsize;<br>
&nbsp;&nbsp;&nbsp; char&nbsp;&nbsp;&nbsp;&nbsp; *mbname;<br>
&nbsp;&nbsp;&nbsp; TIFF&nbsp;&nbsp;&nbsp;&nbsp; *tif;<br>
<br>
&nbsp;&nbsp;&nbsp; m = _TIFFgetMode(mode, module);<br>
<br>
&nbsp;&nbsp;&nbsp; switch(m)<x-tab>&nbsp;&nbsp;&nbsp;</x-tab>{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case
O_RDONLY:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dwMode = OPEN_EXISTING; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case
O_RDWR:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
dwMode = OPEN_ALWAYS;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case
O_RDWR|O_CREAT:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dwMode =
OPEN_ALWAYS;&nbsp;&nbsp; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case
O_RDWR|O_TRUNC:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dwMode =
CREATE_ALWAYS; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case O_RDWR|O_CREAT|O_TRUNC:
dwMode = CREATE_ALWAYS; break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default: return
((TIFF*)0);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; fd = (thandle_t)CreateFileW(name, (m == O_RDONLY) ?
GENERIC_READ :<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(GENERIC_READ | GENERIC_WRITE), FILE_SHARE_READ, NULL, dwMode,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(m == O_RDONLY) ? FILE_ATTRIBUTE_READONLY : FILE_ATTRIBUTE_NORMAL,
NULL);<br>
&nbsp;&nbsp;&nbsp; if (fd == INVALID_HANDLE_VALUE) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIFFError(module, &quot;%S:
Cannot open&quot;, name);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return ((TIFF *)0);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; mbname = NULL;<br>
&nbsp;&nbsp;&nbsp; mbsize = WideCharToMultiByte(CP_ACP, 0, name, -1,
NULL, 0, NULL, NULL);<br>
&nbsp;&nbsp;&nbsp; if (mbsize &gt; 0) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mbname = malloc(mbsize);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (mbname != NULL) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
WideCharToMultiByte(CP_ACP, 0, name, -1, mbname, mbsize, NULL,
NULL);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; tif = TIFFFdOpen((int)fd, (mbname != NULL) ? mbname :
&quot;&lt;unknown&gt;&quot;, mode);<br>
<br>
&nbsp;&nbsp;&nbsp; if (mbname != NULL) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; free(mbname);<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
&nbsp;&nbsp;&nbsp; return tif;<br>
}<br>
</font><br>
<div>--</div>
<div>Regards,<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab></div>
<div>Ian
Ameline,<x-tab>&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab><x-tab>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</x-tab></div>
<div>Software Architect, </div>
<div>Alias SketchBook Technical Lead.</div>
<br>
<div>-- Always do the right thing. This will gratify&nbsp; </div>
<div>some people and astonish the rest. -- Mark Twain.</div>
</html>

--=====================_82555125==_.ALT--


--===============30519456698117553==
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

--===============30519456698117553==--

