Share

libjpeg

Tracker: Bugs

5 12bit default huffman tables - ID: 2809979
Last Update: Comment added ( warmerda )

The std_huff_tables() function only provides default huffman tables for
8bit images, not 12bit since the specification did not include default
tables for 12bit. However, in some environments like libtiff it is
difficult to compute optimal huffman tables for an image before writing it.
For that reason it is desirable to have appropriate 12bit huffman tables
when built with BITS_IN_JSAMPLE=12 mode.


Frank Warmerdam ( warmerda ) - 2009-06-21 20:04

5

Closed

Fixed

Frank Warmerdam

Core Library

None

Public


Comments ( 4 )




Date: 2009-07-25 04:20
Sender: warmerdaProject Admin

I have regenerated the tables in such a way as to build broader "dc"
tables. The new generator code is as follows, and the optimal table was
generated with a quality of 99.

#ifndef generate_universal_tables
long total = 0;
int has_over_15 = 0;

for( i = 0; i < 256; i++ )
{
if( freq[i] > 0 )
printf( "freq[%d] = %d\n", i, freq[i] );

total += freq[i];

if( i > 15 && freq[i] > 0 )
has_over_15 = 1;
}
printf( "total = %d\n", total );
printf( "has_over_15 = %d\n", has_over_15 );

for( i = 0; i < 256; i++ )
{
if( i < 16 || has_over_15 )
{
freq[i] += 1;
}
}
#endif

The change is commited in jcparam.c:1.2.

This was seemingly necessary to handle high quality values.




Date: 2009-06-23 13:36
Sender: warmerdaProject Admin

There was no objection, so I have committed this in jcparam.c 1.2.



Date: 2009-06-21 20:09
Sender: warmerdaProject Admin

For reference, I used the following additional code in
jpeg_gen_optimal_table() to try and make the resulting tables handle all
symbols.

Index: jchuff.c
===================================================================
RCS file: /cvsroot/libjpeg/libjpeg/jchuff.c,v
retrieving revision 1.1
diff -r1.1 jchuff.c
714a715,737
> #ifdef generate_universal_tables
> long total = 0;
> int has_over_12 = 0;
>
> for( i = 0; i < 256; i++ )
> {
> if( freq[i] > 0 )
> printf( "freq[%d] = %d\n", i, freq[i] );
>
> total += freq[i];
>
> if( i > 12 && freq[i] > 0 )
> has_over_12 = 1;
> }
> printf( "total = %d\n", total );
> printf( "has_over_12 = %d\n", has_over_12 );
> for( i = 0; i < 256; i++ )
> {
> if( i < 13 || has_over_12 )
> freq[i] += 1;
> }
> #endif
>



Date: 2009-06-21 20:07
Sender: warmerdaProject Admin

I developed a set of huffman by bulding a symbol histogram for the mandrill
image, adding one to every bucket in the histogram, and computing an
optional table for the resulting histogram. This table seems to handle all
possible symbols and presumably is at least vaguely efficient for images
like the mandrill. I'm not sure how great a choice it is overall. I will
attach a patch to incorporate it in 12bit mode.



Log in to comment.




Attached File ( 1 )

Filename Description Download
std.patch patch aginst jcparam.c to add 12bit table. Download

Changes ( 4 )

Field Old Value Date By
close_date - 2009-06-23 13:36 warmerda
resolution_id None 2009-06-23 13:36 warmerda
status_id Open 2009-06-23 13:36 warmerda
File Added 331824: std.patch 2009-06-21 20:07 warmerda