AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

Thread

2004.03.15 23:58 "[Tiff] libtiff and streams", by Dimitar Gospodinov
2004.03.16 00:14 "Re: [Tiff] libtiff and streams", by Bob Friesenhahn
2004.03.16 00:43 "Re: [Tiff] libtiff and streams", by Joris
2004.03.16 01:38 "Re: [Tiff] libtiff and streams", by Dimitar Gospodinov
2004.03.16 02:08 "Re: [Tiff] libtiff and streams", by Joris
2004.03.16 06:56 "Re: [Tiff] libtiff and streams", by Andrey Kiselev
2004.03.16 12:16 "Re: Re: [Tiff] libtiff and streams", by dimitar
2004.03.16 04:30 "Re: [Tiff] libtiff and streams", by Frank Warmerdam
2004.03.16 08:00 "Re: [Tiff] libtiff and streams", by Rob van den Tillaart
2004.03.16 08:25 "Re: [Tiff] libtiff and streams", by Andrey Kiselev
2004.03.25 15:56 "Re: [Tiff] Jpeg compressing a file", by Andrey Kiselev
2004.03.29 11:42 "[Tiff] Jpeg compressing a file", by Carl J. Collin
2004.03.29 13:01 "Re: [Tiff] Jpeg compressing a file", by Andrey Kiselev

2004.03.29 13:01 "Re: [Tiff] Jpeg compressing a file", by Andrey Kiselev

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

#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);