Return-Path: <tiff-admin@remotesensing.org>
Received: from inmx005.isp.belgacom.be (inmx005.isp.belgacom.be [195.238.3.148])
        by six.skynet.be (8.12.9/8.12.9/Skynet-MAILSTORE-2.14) with ESMTP id i34HOPTk013278
        for <joris.at.lebbeke@skynet.be>; Sun, 4 Apr 2004 19:24:26 +0200
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com ([208.24.120.42])
        by inmx005.isp.belgacom.be (8.12.9/8.12.9/Skynet-IN-2.32) with ESMTP id i34HOKq5005861
        for <joris.at.lebbeke@skynet.be>; Sun, 4 Apr 2004 19:24:21 +0200
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com (localhost.localdomain [127.0.0.1])
	by yoda.imagelinks.com (8.11.6/8.11.2) with ESMTP id i34HM4l16752;
	Sun, 4 Apr 2004 13:22:04 -0400
Received: from ahk.pu.ru (ahk.pu.ru [193.124.85.198])
	by yoda.imagelinks.com (8.11.6/8.11.2) with ESMTP id i34HLpl16734
	for <tiff@remotesensing.org>; Sun, 4 Apr 2004 13:21:52 -0400
Received: from wg.pu.ru (wg.pu.ru [193.124.85.219])
	by ahk.pu.ru (8.12.9p2/8.12.9) with ESMTP id i34HLiqv005128;
	Sun, 4 Apr 2004 21:21:44 +0400 (MSD)
	(envelope-from dron@ak4719.spb.edu)
Received: (from uucp@localhost)
	by wg.pu.ru (8.9.1a/8.9.1) with UUCP id RAA12521;
	Sun, 4 Apr 2004 17:21:44 GMT
Received: from ak4719.spb.edu (localhost [127.0.0.1])
	by ak4719.spb.edu (8.12.1/8.12.1/Debian -5) with ESMTP id i34HMgmb016791;
	Sun, 4 Apr 2004 21:22:42 +0400
Received: (from dron@localhost)
	by ak4719.spb.edu (8.12.1/8.12.1/Debian -5) id i34HMgiR016788;
	Sun, 4 Apr 2004 21:22:42 +0400
From: Andrey Kiselev <dron@ak4719.spb.edu>
To: tiff@remotesensing.org
Cc: wendeldrenner@comcast.net
Subject: Re: [Tiff] 16 bit gray scale images and tiff
Message-ID: <20040404172242.GC10695@ak4719.spb.edu>
Mail-Followup-To: tiff@remotesensing.org, wendeldrenner@comcast.net
References: <406D732B.5000001@comcast.net>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="LQksG6bCIzRHxTLp"
Content-Disposition: inline
In-Reply-To: <406D732B.5000001@comcast.net>
X-GnuPG-Key: http://www.srces.spb.org/dron/export.home.key
X-Face: "t+se9s~+y~[XUH]L|pmeO3Pt/Q@DNv**S,d@_1-C=}/,c%<3Qp]eu!ok<"2lYJm$!9qVcg
 F?7o*L;|$`6|Q|>Rt-cU%2_y@6tQ|`!Li}TsvZvEKx;>fuY=fc(=sX^`7Wmw8%SsR`AvM$a;0U/eN\
 P?B\FTyqD,0np$U2!*'z_4D,VPlFf?bN0&zYf"zF0s!7Tl7?$we)xD0@lL>[h|8bhys0i.g|zLnu@C
 Ti@d]i=[!:j1CB\5/TF[m]`lfHfaqSN[0qn@T3zeosV/[LAss{@p_?],x*j8P_9t[}uHD^X-;j~\M!
 gyTly;fj`}&Y~i{<#bN.#QmkE}#T`dxP.I1\.)_MEN{@#W
User-Agent: Mutt/1.5.3i
Sender: tiff-admin@remotesensing.org
Errors-To: tiff-admin@remotesensing.org
X-BeenThere: tiff@remotesensing.org
X-Mailman-Version: 2.0.11
Precedence: bulk
List-Help: <mailto:tiff-request@remotesensing.org?subject=help>
List-Post: <mailto:tiff@remotesensing.org>
List-Subscribe: <http://remotesensing.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=subscribe>
List-Id: TIFF and libtiff discussion <tiff.remotesensing.org>
List-Unsubscribe: <http://remotesensing.org/mailman/listinfo/tiff>,
	<mailto:tiff-request@remotesensing.org?subject=unsubscribe>
List-Archive: <http://remotesensing.org/pipermail/tiff/>
Date: Sun, 4 Apr 2004 21:22:42 +0400
X-UIDL: f09e396c9c8c5256136478e6a8b9201b


--LQksG6bCIzRHxTLp
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

On Fri, Apr 02, 2004 at 09:05:31AM -0500, Wendel Dean Renner wrote:
> The TIFF 6.0 Specification, on page 22, says "Allowable values for
> Baseline TIFF grayscale images are 4 and 8, allowing either 16 or 256
> distinct shades of gray."   Maybe the problem here is the word
> "Baseline".  I don't know what that means.

Well, page 11 of the specification says: "Baseline TIFF is the core of
TIFF, the essentials that all mainstream TIFF developers should support
in their products." TIFF files can contain a lot of extra info used in
complex applications, but simple baseline files should be read by any
TIFF-aware applications, even by simple ones.

> Where in that document is 16 bits per sample allowed?

Look at the BitsPerSample tag description at the page 29.

> In any event I posted a message last week because I could not
> understand how film scanners could be writing 16 bit gray scale images
> in TIFF format (for x-ray film which is black and white)

I have attached a simple application to write 16-bit TIFF. Search
mailing list archives, I have posted sample code to read TIFF images
recently.

> I want to thank the two people who replied to me.  To read a 16 bit
> gray scale I was told to call TIFFReadScanline in the TIFF library,
> and that works.   For each pixel the first byte was the most
> significant byte.
> 
> Do I assume that all images are of this byte order?

No. The byte order is specified in TIFF header and you will get the
properly swapped bytes from the library.

> Another question, is there such a thing as an RGB image with 16 bits
> per sample (and so 3 samples per pixel)?

Yes, and such images are widely used.

> What happens when a 14 bit scanner writes out a color image?   Are
> they truncated to 8 bits per color?

That depends on how the scanner sofware writes image. I believe it
should be written in form of 16-bit files.

> I notice in the TIFF library that TIFFGetR, TIFFGetB and TIFFGetG
> assume RGB is 3 bytes, blue the most significant byte, and so byte
> order is also assumed besides the size of each sample.

Don't use TIFFGetR/G/B functions. They are part of the TIFFRGBAImage
interface which is designed for simple viewers and not suitable for your
needs.

> Lastly, I have a 16 bit TIFF gray scale image file written by Adobe
> PhotoShop that someone sent me, that TIFFOpen bombs on every time (I
> mean the program crashes upon calling TIFFOpen passing in the file
> name as an argument).   Yet the image displays OK if I use some other
> image viewing software.  But I have yet another 16 bit gray scale
> image from PhotoShop.that gets past TIFFOpen and I can read and
> display the image.   I am using a Windows libtiff that I down loaded
> (I can't remember if it was from your site or someplace else). (I also
> run under Linux and have not tried it there yet.)

Please, try the latest libtiff package (3.6.1). If you still get an
error I shall try to fix the bug (but I shall need a sample image to
work).

						Andrey

-- 
Andrey V. Kiselev
Home phone:  +7 812 5274898  ICQ# 26871517

--LQksG6bCIzRHxTLp
Content-Type: text/x-csrc; charset=us-ascii
Content-Disposition: attachment; filename="tiffcreate.c"

#include <stdio.h>
#include "tiffio.h"

#define XSIZE 256
#define YSIZE 256

int main (int argc, char **argv)
{
    uint32 image_width, image_height;
    float xres, yres;
    uint16 spp, bpp, photo, res_unit;
    TIFF *out;
    int i, j;

    uint16 array[XSIZE * YSIZE];

    for (j = 0; j < YSIZE; j++)
            for(i = 0; i < XSIZE; i++)
                    array[j * XSIZE + i] = i * j;

    out = TIFFOpen("out.tif", "w");
    if (!out)
    {
            fprintf (stderr, "Can't open %s for writing\n", argv[1]);
            return 1;
    }
    image_width = XSIZE;
    image_height = YSIZE;
    spp = 1; /* Samples per pixel */
    bpp = 16; /* Bits per sample */
    photo = PHOTOMETRIC_MINISBLACK;
    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, image_width / spp);
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photo);
    TIFFSetField(out, TIFFTAG_ORIENTATION, ORIENTATION_BOTLEFT);
    /* It is good to set resolutions too (but it is not nesessary) */
    xres = yres = 100;
    res_unit = RESUNIT_INCH;
    TIFFSetField(out, TIFFTAG_XRESOLUTION, xres);
    TIFFSetField(out, TIFFTAG_YRESOLUTION, yres);
    TIFFSetField(out, TIFFTAG_RESOLUTIONUNIT, res_unit);

    for (j = 0; j < image_height; j++)
        TIFFWriteScanline(out, &array[j * image_width], j, 0);

    TIFFClose(out);

    return 0;
}


--LQksG6bCIzRHxTLp--
_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://remotesensing.org/mailman/listinfo/tiff
