Return-Path: <tiff-bounces@remotesensing.org>
Received: from inmx015.isp.belgacom.be (inmx015.isp.belgacom.be [195.238.2.218])
        by mailst006.isp.belgacom.be (8.12.11/8.12.11/Skynet-MAILSTORE-2.14) with ESMTP id i5N7FkfE019506
        for <joris.at.lebbeke@skynet.be>; Wed, 23 Jun 2004 09:15:46 +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 inmx015.isp.belgacom.be (8.12.11/8.12.11/Skynet-IN-2.32) with ESMTP id i5N7FDaq005060
        for <joris.at.lebbeke@skynet.be>; Wed, 23 Jun 2004 09:15:20 +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 52356A53C6; Wed, 23 Jun 2004 03:13:49 -0400 (EDT)
X-Original-To: tiff@remotesensing.org
Delivered-To: tiff@remotesensing.org
Received: from blanes.local.icc (correu.icc.es [193.144.250.36])
	by xserve.flids.com (Postfix) with ESMTP id D1340A53AB
	for <tiff@remotesensing.org>; Wed, 23 Jun 2004 03:13:44 -0400 (EDT)
Received: by blanes.local.icc with Internet Mail Service (5.5.2657.72)
	id <K6CWR5A1>; Wed, 23 Jun 2004 09:15:38 +0200
Message-ID: <A07799085DF7D311B2490050043D941A017B0E4B@blanes.local.icc>
From: "Adell, Albert" <aadell@icc.es>
To: "'tiff@remotesensing.org'" <tiff@remotesensing.org>
Subject: [Tiff] Tiff JPEG compression quality factor
Date: Wed, 23 Jun 2004 09:15:28 +0200
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2657.72)
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="===============85603096121643918=="
Sender: tiff-bounces@remotesensing.org
Errors-To: tiff-bounces@remotesensing.org
X-UIDL: fd03ea13c15f079a2f5942a17eb0da2a

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--===============85603096121643918==
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01C458F1.DC7E3DC0"

This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C458F1.DC7E3DC0
Content-Type: text/plain;
	charset="iso-8859-1"

Hi Philip,

I have modified the method JPEGSetupDecode in tiff_jpeg.c file, in order to calculate the Q-factor.
I have acceded to the JPEG struct at this function and I am able to apply the Q-factor computation.

JPEGSetupDecode(TIFF* tif)
{
        ...

        /* Read JPEGTables if it is present */
        if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) {
                TIFFjpeg_tables_src(sp, tif);
                if(TIFFjpeg_read_header(sp,FALSE) != JPEG_HEADER_TABLES_ONLY) {
                        TIFFError("JPEGSetupDecode", "Bogus JPEGTables field");
                        return (0);
                }

                //$$$ QualityFactor begin
                q = sp->cinfo.d.quant_tbl_ptrs[0]->quantval[6];
                if (q > 51)
                        q = (50 * 51 + q / 2) / q;
                else
                        q = (5126 - 50 * q) / 51;
                sp->jpegquality=q;
                //$$$ QualityFactor end
        }

        ...
}

This method is automaticaly called when reading a tile or a strip but I suppose that is more interesting if it could be calculated before. I put the JPEGSetupCode explicit call after an Open call and it seems that works!

Thanks for the qFactor computation its a nice aproximation.

Thanks a lot,

        Albert Adell

________________________________________________________________________

Albert Adell Fern?ndez              Desenvolupament Fotogrametria Digital
Institut Cartografic de Catalunya   Passeig Santa Madrona 45-51
E-08004 Barcelona                   www http://www.icc.es
_________________________________________________________________________






> -----Original Message-----
> From: Phillip Crews [mailto:pcrews@cerious.com]
> Sent: Tuesday, June 01, 2004 8:04 PM
> To: Adell, Albert
> Cc: 'tiff@remotesensing.org'
> Subject: RE: [Tiff] Tiff JPEG compression quality factor
>
>
> Albert,
>
> I haven't used the equation directly with JPEG-compressed
> TIFF files, only
> with JPEG files directly.
>
>  From looking at tif_jpeg.c and the JPEG code, I *think* what
> you'll see in
> the buffer returned using TIFFTAG_JPEGTABLES is:
>
> SOI (0xff, 0xd8), DQT (0xff, 0xdb), (2 byte length of quant table+3),
> (table number & precision, 0x00 or 0x10), table data in
> zig-zag order, each
> value as a 16-bit word in network byte order if the previous
> byte & 0x10 is
> true, or 8-bit bytes if the previous byte & 0x10 is false.
>
> It may be simplest to use libjpeg to parse the tables from
> the JPEGTABLES
> return data. This will parse the JPEG markers and return the table in
> natural (rather than zig-zag) order, something like this:
>
> void *buf;
> unsigned short len;
> jpeg_decompress_struct cinfo = {0};
> jpeg_source_mgr src;
>
> TIFFVGetField(tif, TIFFTAG_JPEGTABLES, &len, &buf);
> jpeg_create_decompress(&cinfo);
> cinfo.src = &src;
>
> /* Set up the libjpeg source manager to read from buffer
>     (crib code from TIF_JPEG.c) */
>
> jpeg_read_header(&cinfo, FALSE);
>
> At this point, cinfo.quant_table_ptrs should work for the
> code I provided.
>
> Don't forget to jpeg_destroy_decompres(&cinfo) when you're done.
>
> I'm sorry I don't have time to provide actual working code
> today. I hope
> this helps. ?Buena suerte!
>
> Kind regards,
> Phillip
>
> At 04:27 AM 6/1/2004 , Adell, Albert wrote:
>
> >Hi Phillip,
> >
> >I've tried to write the code with the formula you provided
> me, but I can't
> >access to the Q-Tables using the LibTiff Library.
> >
> >I've read in a JPEG-compressed TIFF file the following tags:
> >
> >-TIFFTAG_JPEGQTABLES: the library returns code 0 that means
> that this tag
> >does not exist.
> >
> >-TIFFTAG_JPEGTABLES: With this tag I succeed on reading some
> values, but I
> >have no idea what they mean. I've looked for it in Internet
> and I've found
> >that using this tag, the library returns the following:
> >
> >         u_short*,void** count & tables
> >My problem is that I don't how to use the void **, anyway
> the "u_Short"
> >value returns a value of 289... and does not look very good...
> >
> >What am I doing wrong?
> >Which is the right way to get this q-value back using the
> LibTiff (the
> >q-value that you refered in your mail as q =
> >cinfo.quant_tbl_ptrs[0]->quantval[6])?
> >
> >Thank a lot,
> >
> >         Albert
> >
> >-----Original Message-----
> >From: Phillip Crews
> [<mailto:pcrews@cerious.com>mailto:pcrews@cerious.com]
> >Sent: Friday, May 28, 2004 7:32 PM
> >To: Adell, Albert
> >Cc: 'tiff@remotesensing.org'
> >Subject: Re: [Tiff] Tiff JPEG compression quality factor
> >
> >At 08:18 AM 5/28/2004 , Frank Warmerdam wrote:
> >
> > >Adell, Albert wrote:
> > >>Hi,
> > >>I'm using the libtiff v3.6.1 and I can save a tiff file with Jpeg
> > >>compression and quality factor 80, but when i
> > >>try to open it, the jpeg quality factor pseudotag has a
> value of 75. I
> > >>guess I am doing something wrong,
> > >>because I assume that I can read the Jpeg quality factor
> written in
> > >>advance. Is that correct?
> > >
> > >Albert,
> > >
> > >Not that I am too knowledgable about this particular area, but my
> > >understanding
> > >is that the quality "pseudotag" is not really saved with
> the data.  It
> > is just
> > >used to drive the compressor.  So, when you read a TIFF
> the value isn't
> > >derived
> > >from the file, but just set to an initial default value (75).
> > >
> > >In short, I don't think you can read the quality factor
> from an existing
> > >image.
> >
> >I believe Tom Lane provided this method of estimating the Q
> Factor of  a
> >JPEG. It is relatively accurate for images saved using the
> IJG library:
> >
> >    int q = cinfo.quant_tbl_ptrs[0]->quantval[6];
> >    if (q > 51)
> >      q = (50 * 51 + q / 2) / q;
> >    else
> >      q = (5126 - 50 * q) / 51;
> >
> >- Phillip
>

_______________________________________________
Tiff mailing list
Tiff@remotesensing.org
http://xserve.flids.com/mailman/listinfo/tiff




------_=_NextPart_001_01C458F1.DC7E3DC0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2653.12">
<TITLE>[Tiff] Tiff JPEG compression quality factor</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Courier New">Hi Philip,</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">I have modified the method =
JPEGSetupDecode in tiff_jpeg.c file, in order to calculate the =
Q-factor.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">I have acceded to the JPEG =
struct at this function and I am able to apply the Q-factor =
computation.</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">JPEGSetupDecode(TIFF* =
tif)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">{</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">...</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">/* Read JPEGTables if it is present */</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">if (TIFFFieldSet(tif,FIELD_JPEGTABLES)) {</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">TIFFjpeg_tables_src(sp, tif);</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">if(TIFFjpeg_read_header(sp,FALSE) !=3D =
JPEG_HEADER_TABLES_ONLY) {</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">TIFFError(&quot;JPEGSetupDecode&quot;, &quot;Bogus =
JPEGTables field&quot;);</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">return (0);</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">}</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">//$$$ QualityFactor begin</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">q =3D =
sp-&gt;cinfo.d.quant_tbl_ptrs[0]-&gt;quantval[6];</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">if (q &gt; 51)</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">q =3D (50 * 51 + q / 2) / q;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">else</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">q =3D (5126 - 50 * q) / 51;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">sp-&gt;jpegquality=3Dq;</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">//$$$ QualityFactor end</FONT>
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">}</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">...</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">}</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">This method is automaticaly =
called when reading a tile or a strip but I suppose that is more =
interesting if it could be calculated before. I put the JPEGSetupCode =
explicit call after an Open call and it seems that works!</FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">Thanks for the qFactor =
computation its a nice aproximation.</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">Thanks a lot,</FONT>
</P>

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT SIZE=3D2 =
FACE=3D"Courier New">Albert Adell</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier =
New">___________________________________________________________________=
_____</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Courier New">Albert Adell =
Fern=E1ndez&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp; Desenvolupament Fotogrametria Digital</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">Institut Cartografic de =
Catalunya&nbsp;&nbsp; Passeig Santa Madrona 45-51</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">E-08004 =
Barcelona&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; www <A =
HREF=3D"http://www.icc.es" =
TARGET=3D"_blank">http://www.icc.es</A></FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier =
New">___________________________________________________________________=
______</FONT>
</P>
<BR>
<BR>
<BR>

<P><FONT SIZE=3D2 FACE=3D"Courier New">&gt; -----Original =
Message-----</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; From: Phillip Crews [<A =
HREF=3D"mailto:pcrews@cerious.com">mailto:pcrews@cerious.com</A>]</FONT>=

<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Sent: Tuesday, June 01, =
2004 8:04 PM</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; To: Adell, Albert</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Cc: =
'tiff@remotesensing.org'</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Subject: RE: [Tiff] Tiff =
JPEG compression quality factor</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Albert,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; I haven't used the =
equation directly with JPEG-compressed </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; TIFF files, only </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; with JPEG files =
directly.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt;&nbsp; From looking at =
tif_jpeg.c and the JPEG code, I *think* what </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; you'll see in </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; the buffer returned using =
TIFFTAG_JPEGTABLES is:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; SOI (0xff, 0xd8), DQT =
(0xff, 0xdb), (2 byte length of quant table+3), </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; (table number &amp; =
precision, 0x00 or 0x10), table data in </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; zig-zag order, each =
</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; value as a 16-bit word in =
network byte order if the previous </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; byte &amp; 0x10 is </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; true, or 8-bit bytes if =
the previous byte &amp; 0x10 is false.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; It may be simplest to use =
libjpeg to parse the tables from </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; the JPEGTABLES </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; return data. This will =
parse the JPEG markers and return the table in </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; natural (rather than =
zig-zag) order, something like this:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; void *buf;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; unsigned short len;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; jpeg_decompress_struct =
cinfo =3D {0};</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; jpeg_source_mgr =
src;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; TIFFVGetField(tif, =
TIFFTAG_JPEGTABLES, &amp;len, &amp;buf);</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
jpeg_create_decompress(&amp;cinfo);</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; cinfo.src =3D =
&amp;src;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; /* Set up the libjpeg =
source manager to read from buffer</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt;&nbsp;&nbsp;&nbsp;&nbsp; =
(crib code from TIF_JPEG.c) */</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
jpeg_read_header(&amp;cinfo, FALSE);</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; At this point, =
cinfo.quant_table_ptrs should work for the </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; code I provided.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Don't forget to =
jpeg_destroy_decompres(&amp;cinfo) when you're done.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; I'm sorry I don't have =
time to provide actual working code </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; today. I hope </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; this helps. =A1Buena =
suerte!</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Kind regards,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Phillip</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; At 04:27 AM 6/1/2004 , =
Adell, Albert wrote:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;Hi Phillip,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;I've tried to write =
the code with the formula you provided </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; me, but I can't </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;access to the Q-Tables =
using the LibTiff Library.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;I've read in a =
JPEG-compressed TIFF file the following tags:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;-TIFFTAG_JPEGQTABLES: =
the library returns code 0 that means </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; that this tag </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;does not exist.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;-TIFFTAG_JPEGTABLES: =
With this tag I succeed on reading some </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; values, but I </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;have no idea what they =
mean. I've looked for it in Internet </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; and I've found </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;that using this tag, =
the library returns the following:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; u_short*,void** =
count &amp; tables</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;My problem is that I =
don't how to use the void **, anyway </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; the &quot;u_Short&quot; =
</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;value returns a value =
of 289... and does not look very good...</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;What am I doing =
wrong?</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;Which is the right way =
to get this q-value back using the </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; LibTiff (the </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;q-value that you =
refered in your mail as q =3D </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
&gt;cinfo.quant_tbl_ptrs[0]-&gt;quantval[6])?</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;Thank a lot,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Albert</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;-----Original =
Message-----</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;From: Phillip Crews =
</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; [&lt;<A =
HREF=3D"mailto:pcrews@cerious.com">mailto:pcrews@cerious.com</A>&gt;<A =
HREF=3D"mailto:pcrews@cerious.com">mailto:pcrews@cerious.com</A>]</FONT>=

<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;Sent: Friday, May 28, =
2004 7:32 PM</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;To: Adell, =
Albert</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;Cc: =
'tiff@remotesensing.org'</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;Subject: Re: [Tiff] =
Tiff JPEG compression quality factor</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;At 08:18 AM 5/28/2004 =
, Frank Warmerdam wrote:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;Adell, Albert =
wrote:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;Hi,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;I'm using the =
libtiff v3.6.1 and I can save a tiff file with Jpeg</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;compression =
and quality factor 80, but when i</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;try to open =
it, the jpeg quality factor pseudotag has a </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; value of 75. I</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;guess I am =
doing something wrong,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;because I =
assume that I can read the Jpeg quality factor </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; written in</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;&gt;advance. Is =
that correct?</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;Albert,</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;Not that I am too =
knowledgable about this particular area, but my</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; =
&gt;understanding</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;is that the =
quality &quot;pseudotag&quot; is not really saved with </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; the data.&nbsp; It </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; is just</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;used to drive the =
compressor.&nbsp; So, when you read a TIFF </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; the value isn't</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;derived</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;from the file, =
but just set to an initial default value (75).</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;In short, I don't =
think you can read the quality factor </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; from an existing</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt; &gt;image.</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;I believe Tom Lane =
provided this method of estimating the Q </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; Factor of&nbsp; a</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;JPEG. It is relatively =
accurate for images saved using the </FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; IJG library:</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;&nbsp;&nbsp;&nbsp; int =
q =3D cinfo.quant_tbl_ptrs[0]-&gt;quantval[6];</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;&nbsp;&nbsp;&nbsp; if =
(q &gt; 51)</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q =3D (50 * 51 + q / 2) / q;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;&nbsp;&nbsp;&nbsp; =
else</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; =
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; q =3D (5126 - 50 * q) / 51;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; &gt;- Phillip</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Courier New">&gt; </FONT>
</P>

</BODY>
</HTML>
------_=_NextPart_001_01C458F1.DC7E3DC0--

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

--===============85603096121643918==--
