Re-factor and re-license under the libjpeg BSD-style license. Justification: the accelerated Huffman decoding optimizations in libjpeg-turbo were all developed by me as an independent developer. The structure of the inline Huffman decoding macros was originally borrowed from similar routines in the TurboJPEG/mediaLib codec, which is part of VirtualGL and TurboVNC. Thus, although the code for these macros was not copied verbatim, they were still thought to be a derivative work of TurboJPEG/mediaLib, and I assigned the copyright and license from TurboJPEG/mediaLib to them. I have re-written these routines from first principles by breaking down the libjpeg out-of-line routines. Although the new code bears algorithmic similarities to the TurboJPEG/mediaLib macros, it can now clearly be shown to be derived from the out-of-line routines and thus, in my opinion, it can no longer be considered a derivative of TurboJPEG/mediaLib. -- DRC
This commit is contained in:
122
jdhuff.c
122
jdhuff.c
@@ -2,7 +2,7 @@
|
||||
* jdhuff.c
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Copyright (C) 2010, D. R. Commander.
|
||||
* Copyright (C) 2009-2011, D. R. Commander.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@@ -15,21 +15,6 @@
|
||||
* storage only upon successful completion of an MCU.
|
||||
*/
|
||||
|
||||
/* Performance enhancements:
|
||||
* Copyright (C)2007 Sun Microsystems, Inc.
|
||||
* Copyright (C)2009-2010 D. R. Commander
|
||||
*
|
||||
* This library is free software and may be redistributed and/or modified under
|
||||
* the terms of the wxWindows Library License, Version 3.1 or (at your option)
|
||||
* any later version. The full license is in the LICENSE.txt file included
|
||||
* with this distribution.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* wxWindows Library License for more details.
|
||||
*/
|
||||
|
||||
#define JPEG_INTERNALS
|
||||
#include "jinclude.h"
|
||||
#include "jpeglib.h"
|
||||
@@ -407,6 +392,50 @@ jpeg_fill_bit_buffer (bitread_working_state * state,
|
||||
}
|
||||
|
||||
|
||||
/* Macro version of the above, which performs much better but does not
|
||||
handle markers. We have to hand off any blocks with markers to the
|
||||
slower routines. */
|
||||
|
||||
#define GET_BYTE \
|
||||
{ \
|
||||
register int c0, c1; \
|
||||
c0 = GETJOCTET(*buffer++); \
|
||||
c1 = GETJOCTET(*buffer); \
|
||||
/* Pre-execute most common case */ \
|
||||
get_buffer = (get_buffer << 8) | c0; \
|
||||
bits_left += 8; \
|
||||
if (c0 == 0xFF) { \
|
||||
/* Pre-execute case of FF/00, which represents an FF data byte */ \
|
||||
buffer++; \
|
||||
if (c1 != 0) { \
|
||||
/* Oops, it's actually a marker indicating end of compressed data. */ \
|
||||
cinfo->unread_marker = c1; \
|
||||
/* Back out pre-execution and fill the buffer with zero bits */ \
|
||||
buffer -= 2; \
|
||||
get_buffer &= ~0xFF; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#if __WORDSIZE == 64 || defined(_WIN64)
|
||||
|
||||
/* Pre-fetch 48 bytes, because the holding register is 64-bit */
|
||||
#define FILL_BIT_BUFFER_FAST \
|
||||
if (bits_left < 16) { \
|
||||
GET_BYTE GET_BYTE GET_BYTE GET_BYTE GET_BYTE GET_BYTE \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* Pre-fetch 16 bytes, because the holding register is 32-bit */
|
||||
#define FILL_BIT_BUFFER_FAST \
|
||||
if (bits_left < 16) { \
|
||||
GET_BYTE GET_BYTE \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Out-of-line code for Huffman code decoding.
|
||||
* See jdhuff.h for info about usage.
|
||||
@@ -612,61 +641,6 @@ decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
}
|
||||
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
#define ADD_BYTE { \
|
||||
int val0 = *(buffer++); \
|
||||
int val1 = *(buffer); \
|
||||
\
|
||||
bits_left += 8; \
|
||||
get_buffer = (get_buffer << 8) | (val0); \
|
||||
if (val0 == 0xFF) { \
|
||||
buffer++; \
|
||||
if (val1 != 0) { \
|
||||
cinfo->unread_marker = val1; \
|
||||
buffer -= 2; \
|
||||
get_buffer &= ~0xFF; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
#if __WORDSIZE == 64 || defined(_WIN64)
|
||||
|
||||
#define ENSURE_SHORT \
|
||||
if (bits_left < 16) { \
|
||||
ADD_BYTE ADD_BYTE ADD_BYTE ADD_BYTE ADD_BYTE ADD_BYTE \
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define ENSURE_SHORT if (bits_left < 16) { ADD_BYTE ADD_BYTE }
|
||||
|
||||
#endif
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
#define HUFF_DECODE_FAST(symbol, size, htbl) { \
|
||||
ENSURE_SHORT \
|
||||
symbol = PEEK_BITS(HUFF_LOOKAHEAD); \
|
||||
symbol = htbl->lookup[symbol]; \
|
||||
size = symbol >> 8; \
|
||||
bits_left -= size; \
|
||||
symbol = symbol & ((1 << HUFF_LOOKAHEAD) - 1); \
|
||||
if (size == HUFF_LOOKAHEAD + 1) { \
|
||||
symbol = (get_buffer >> bits_left) & ((1 << (size)) - 1); \
|
||||
while (symbol > htbl->maxcode[size]) { \
|
||||
symbol <<= 1; \
|
||||
symbol |= GET_BITS(1); \
|
||||
size++; \
|
||||
} \
|
||||
symbol = htbl->pub->huffval[ (int) (symbol + htbl->valoffset[size]) & 0xFF ]; \
|
||||
} \
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
LOCAL(boolean)
|
||||
decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
{
|
||||
@@ -690,7 +664,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
|
||||
HUFF_DECODE_FAST(s, l, dctbl);
|
||||
if (s) {
|
||||
ENSURE_SHORT
|
||||
FILL_BIT_BUFFER_FAST
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
}
|
||||
@@ -711,7 +685,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
|
||||
if (s) {
|
||||
k += r;
|
||||
ENSURE_SHORT
|
||||
FILL_BIT_BUFFER_FAST
|
||||
r = GET_BITS(s);
|
||||
s = HUFF_EXTEND(r, s);
|
||||
(*block)[jpeg_natural_order[k]] = (JCOEF) s;
|
||||
@@ -730,7 +704,7 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
|
||||
|
||||
if (s) {
|
||||
k += r;
|
||||
ENSURE_SHORT
|
||||
FILL_BIT_BUFFER_FAST
|
||||
DROP_BITS(s);
|
||||
} else {
|
||||
if (r != 15) break;
|
||||
|
||||
22
jdhuff.h
22
jdhuff.h
@@ -2,7 +2,7 @@
|
||||
* jdhuff.h
|
||||
*
|
||||
* Copyright (C) 1991-1997, Thomas G. Lane.
|
||||
* Copyright (C) 2010, D. R. Commander.
|
||||
* Copyright (C) 2010-2011, D. R. Commander.
|
||||
* This file is part of the Independent JPEG Group's software.
|
||||
* For conditions of distribution and use, see the accompanying README file.
|
||||
*
|
||||
@@ -208,6 +208,26 @@ slowlabel: \
|
||||
} \
|
||||
}
|
||||
|
||||
#define HUFF_DECODE_FAST(s,nb,htbl) \
|
||||
FILL_BIT_BUFFER_FAST; \
|
||||
s = PEEK_BITS(HUFF_LOOKAHEAD); \
|
||||
s = htbl->lookup[s]; \
|
||||
nb = s >> HUFF_LOOKAHEAD; \
|
||||
/* Pre-execute the common case of nb <= HUFF_LOOKAHEAD */ \
|
||||
DROP_BITS(nb); \
|
||||
s = s & ((1 << HUFF_LOOKAHEAD) - 1); \
|
||||
if (nb > HUFF_LOOKAHEAD) { \
|
||||
/* Equivalent of jpeg_huff_decode() */ \
|
||||
/* Don't use GET_BITS() here because we don't want to modify bits_left */ \
|
||||
s = (get_buffer >> bits_left) & ((1 << (nb)) - 1); \
|
||||
while (s > htbl->maxcode[nb]) { \
|
||||
s <<= 1; \
|
||||
s |= GET_BITS(1); \
|
||||
nb++; \
|
||||
} \
|
||||
s = htbl->pub->huffval[ (int) (s + htbl->valoffset[nb]) & 0xFF ]; \
|
||||
}
|
||||
|
||||
/* Out-of-line case for Huffman code fetching */
|
||||
EXTERN(int) jpeg_huff_decode
|
||||
JPP((bitread_working_state * state, register bit_buf_type get_buffer,
|
||||
|
||||
Reference in New Issue
Block a user