Return-Path: <tiff-admin@remotesensing.org>
Received: from inav004.isp.belgacom.be (inav004.isp.belgacom.be [195.238.3.237])
        by six.skynet.be (8.12.9/8.12.9/Skynet-MAILSTORE-2.14) with ESMTP id i2PG3pMB019764
        for <joris.at.lebbeke@skynet.be>; Thu, 25 Mar 2004 17:03:51 +0100
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from inmx012.isp.belgacom.be (inmx012.isp.belgacom.be [195.238.3.90])
        by inav004.isp.belgacom.be (8.12.9/8.12.9/Skynet-IN-AV-2.02) with ESMTP id i2PG3UfT032748
        for <joris.at.lebbeke@skynet.be>; Thu, 25 Mar 2004 17:03:33 +0100
        (envelope-from <tiff-admin@remotesensing.org>)
Received: from yoda.imagelinks.com ([208.24.120.42])
        by inmx012.isp.belgacom.be (8.12.9/8.12.9/Skynet-IN-2.32) with ESMTP id i2PG3Qix004568
        for <joris.at.lebbeke@skynet.be>; Thu, 25 Mar 2004 17:03:27 +0100
        (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 i2PG1Ol32453;
	Thu, 25 Mar 2004 11:01:24 -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 i2PG0Ml32415
	for <tiff@remotesensing.org>; Thu, 25 Mar 2004 11:00:22 -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 i2PG0Jqv001297
	for <tiff@remotesensing.org>; Thu, 25 Mar 2004 19:00:19 +0300 (MSK)
	(envelope-from dron@ak4719.spb.edu)
Received: (from uucp@localhost)
	by wg.pu.ru (8.9.1a/8.9.1) with UUCP id QAA18105
	for tiff@remotesensing.org; Thu, 25 Mar 2004 16:00:19 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 i2PFuZDw017402
	for <tiff@remotesensing.org>; Thu, 25 Mar 2004 18:56:35 +0300
Received: (from dron@localhost)
	by ak4719.spb.edu (8.12.1/8.12.1/Debian -5) id i2PFuZ1V017399
	for tiff@remotesensing.org; Thu, 25 Mar 2004 18:56:35 +0300
From: Andrey Kiselev <dron@ak4719.spb.edu>
To: tiff@remotesensing.org
Subject: Re: [Tiff] Jpeg compressing a file
Message-ID: <20040325155635.GA16265@ak4719.spb.edu>
Mail-Followup-To: tiff@remotesensing.org
References: <BAY8-DAV57TyfPefLJG000043d4@hotmail.com>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="ReaqsoxgOBHFXBhH"
Content-Disposition: inline
In-Reply-To: <BAY8-DAV57TyfPefLJG000043d4@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: Thu, 25 Mar 2004 18:56:35 +0300
X-RAVMilter-Version: 8.4.3(snapshot 20030212) (inav004.isp.belgacom.be)
X-UIDL: ecbc3d43d289479b83d8005c6a01b2e4


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

On Thu, Mar 25, 2004 at 08:44:29AM -0600, Carl J. Collin wrote:
> What I want to do is take a TIFF file that is currently uncompressed
> and compress it using the jpeg compression schema.  I know this is
> sorta possible because tiffcp does it but it creates a second file, I
> need to open a file, compress it, and close the file. Is this
> possible?

Of course, it is possible, but you can't read the header only. I mage
data should be read too and written in the new file. It is not possible
to compress the file in place.

So you should read data from the one file and write to another. There
are two ways to do it: the simple one and the right one. The simple one
illustrated by the attached source code. The right one is more complex
and requires handling of arbitrary data types and data organization
schemes (stripes and tiles). tiffcp implements the right way, that is
why it is so complex.

						Andrey

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

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

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

int main (int argc, char **argv)
{
    unsigned int i;
    TIFF *tif, *out;
    uint16 spp, bpp, photo;
    uint32 image_width, image_height, scansize;
    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_IMAGELENGTH, &image_width);
    TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &image_height);
    TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bpp);
    TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &spp);
    TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photo);
    scansize = TIFFScanlineSize(tif);
    buf = _TIFFmalloc(scansize * image_height);
    for (i = 0; i < image_height; i++)
        TIFFReadScanline(tif, buf + i * scansize, i, 0);

    TIFFSetField(out, TIFFTAG_IMAGEWIDTH, image_width);
    TIFFSetField(out, TIFFTAG_IMAGELENGTH, image_height);
    TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, bpp);
    TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, spp);
    TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
    TIFFSetField(out, TIFFTAG_PHOTOMETRIC, photo);
    TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_JPEG);
    TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, TIFFDefaultStripSize(out, 0));
    for (i = 0; i < image_height; i++)
        TIFFWriteScanline(out, buf + i * scansize, i, 0);

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

    return 0;
}



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