Return-Path: <tiff-admin@remotesensing.org>
Received: from inmx010.isp.belgacom.be (inmx010.isp.belgacom.be [195.238.2.73])
        by six.skynet.be (8.12.9/8.12.9/Skynet-MAILSTORE-2.14) with ESMTP id i2TD6IUt030512
        for <joris.at.lebbeke@skynet.be>; Mon, 29 Mar 2004 15:06:18 +0200
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com ([208.24.120.42])
        by inmx010.isp.belgacom.be (8.12.9/8.12.9/Skynet-IN-2.32) with ESMTP id i2TD67UB029268
        for <joris.at.lebbeke@skynet.be>; Mon, 29 Mar 2004 15:06:10 +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 i2TD2ul17118;
	Mon, 29 Mar 2004 08:02:56 -0500
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 i2TD1hl17063
	for <tiff@remotesensing.org>; Mon, 29 Mar 2004 08:01:43 -0500
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 i2TD1Xqv043875
	for <tiff@remotesensing.org>; Mon, 29 Mar 2004 17:01:39 +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 NAA10235
	for tiff@remotesensing.org; Mon, 29 Mar 2004 13:01:32 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 i2TD1cSI005904
	for <tiff@remotesensing.org>; Mon, 29 Mar 2004 17:01:38 +0400
Received: (from dron@localhost)
	by ak4719.spb.edu (8.12.1/8.12.1/Debian -5) id i2TD1cKj005901
	for tiff@remotesensing.org; Mon, 29 Mar 2004 17:01:38 +0400
From: Andrey Kiselev <dron@ak4719.spb.edu>
To: tiff@remotesensing.org
Subject: Re: [Tiff] Jpeg compressing a file
Message-ID: <20040329130138.GA2260@ak4719.spb.edu>
Mail-Followup-To: tiff@remotesensing.org
References: <BAY8-DAV7K7iolTWgRa0000c8fe@hotmail.com>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="YZ5djTAD1cGYuMQK"
Content-Disposition: inline
In-Reply-To: <BAY8-DAV7K7iolTWgRa0000c8fe@hotmail.com>
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: Mon, 29 Mar 2004 17:01:38 +0400
X-UIDL: 632135c356ce2d5e9a952f4533421934


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

On Mon, Mar 29, 2004 at 05:42:37AM -0600, Carl J. Collin wrote:
> it seems to work for some files, however, the files we are using are
> giving these errors, and they are spitting out alot of them...  Any
> ideas?
> 
> JPEGSetupEncode: PhotometricInterpretation 3 not allowed for JPEG

It is not possible to use paletted images with JPEG compression. But you
can convert that image to RGBA (using TIFFRGBAImage interface) and
compress afterwards.

> test.tif: Compression algorithm does not support random access.

This means that compression algorithm does not support random access :-)

Try the attached code. Most cases should be handled by the libtiff
itself, but remember, that it is _simple_ solution as well, and it
will not work in complex cases.

						Andrey

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

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

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

int main (int argc, char **argv)
{
    unsigned int i;
    TIFF *tif, *out;
    uint32 image_width, image_height;
    char *buf;

    if(argc < 3)
    {
        fprintf(stderr, "\nUSAGE: tiffcopy infile.tif outfile.tif\n");
        return 1;
    }

    tif = TIFFOpen(argv[1], "r");
    if (!tif)
    {
        fprintf (stderr, "Can't open %s for reading\n", argv[1]);
        return 2;
    }

    out = TIFFOpen(argv[2], "w");
    if (!out)
    {
        fprintf (stderr, "Can't open %s for writing\n", argv[2]);
        return 3;
    }

    TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &image_width);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &image_height);
    buf = (char *)_TIFFmalloc(image_width * image_height * sizeof(uint32));
    TIFFReadRGBAImageOriented(tif, image_width, image_height, (u_long *)buf, ORIENTATION_TOPLEFT, 0);

    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, image_width);
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, image_height);
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 4);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
    TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, 0));
    for (i = 0; i < image_height; i++)
        TIFFWriteScanline(out, buf + i * image_width * sizeof(uint32), i, 0);

    _TIFFfree(buf);
    TIFFClose(out);
    TIFFClose(tif);

    return 0;
}



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