Hash :
af618ffe
Author :
Date :
2022-11-08T15:01:18
Clean up the lossless JPEG feature
- Rename jpeg_simple_lossless() to jpeg_enable_lossless() and modify the
function so that it stores the lossless parameters directly in the Ss
and Al fields of jpeg_compress_struct rather than using a scan script.
- Move the cjpeg -lossless switch into "Switches for advanced users".
- Document the libjpeg API and run-time features that are unavailable in
lossless mode, and ensure that all parameters, functions, and switches
related to unavailable features are ignored or generate errors in
lossless mode.
- Defer any action that depends on whether lossless mode is enabled
until jpeg_start_compress()/jpeg_start_decompress() is called.
- Document the purpose of the point transform value.
- "Codec" stands for coder/decoder, so it is a bit awkward to say
"lossless compression codec" and "lossless decompression codec".
Use "lossless compressor" and "lossless decompressor" instead.
- Restore backward API/ABI compatibility with libjpeg v6b:
* Move the new 'lossless' field from the exposed jpeg_compress_struct
and jpeg_decompress_struct structures into the opaque
jpeg_comp_master and jpeg_decomp_master structures, and allocate the
master structures in the body of jpeg_create_compress() and
jpeg_create_decompress().
* Remove the new 'process' field from jpeg_compress_struct and
jpeg_decompress_struct and replace it with the old
'progressive_mode' field and the new 'lossless' field.
* Remove the new 'data_unit' field from jpeg_compress_struct and
jpeg_decompress_struct and replace it with a locally-computed
data unit variable.
* Restore the names of macros and fields that refer to DCT blocks, and
document that they have a different meaning in lossless mode. (Most
of them aren't very meaningful in lossless mode anyhow.)
* Remove the new alloc_darray() method from jpeg_memory_mgr and
replace it with an internal macro that wraps the alloc_sarray()
method.
* Move the JDIFF* data types from jpeglib.h and jmorecfg.h into
jpegint.h.
* Remove the new 'codec' field from jpeg_compress_struct and
jpeg_decompress_struct and instead reuse the existing internal
coefficient control, forward/inverse DCT, and entropy
encoding/decoding structures for lossless compression/decompression.
* Repurpose existing error codes rather than introducing new ones.
(The new JERR_BAD_RESTART and JWRN_MUST_DOWNSCALE codes remain,
although JWRN_MUST_DOWNSCALE will probably be removed in
libjpeg-turbo, since we have a different way of handling multiple
data precisions.)
- Automatically enable lossless mode when a scan script with parameters
that are only valid for lossless mode is detected, and document the
use of scan scripts to generate lossless JPEG images.
- Move the sequential and shared Huffman routines back into jchuff.c and
jdhuff.c, and document that those routines are shared with jclhuff.c
and jdlhuff.c as well as with jcphuff.c and jdphuff.c.
- Move MAX_DIFF_BITS from jchuff.h into jclhuff.c, the only place where
it is used.
- Move the predictor and scaler code into jclossls.c and jdlossls.c.
- Streamline register usage in the [un]differencers (inspired by similar
optimizations in the color [de]converters.)
- Restructure the logic in a few places to reduce duplicated code.
- Ensure that all lossless-specific code is guarded by
C_LOSSLESS_SUPPORTED or D_LOSSLESS_SUPPORTED and that the library can
be built successfully if either or both of those macros is undefined.
- Remove all short forms of external names introduced by the lossless
JPEG patch. (These will not be needed by libjpeg-turbo, so there is
no use cleaning them up.)
- Various wordsmithing, formatting, and punctuation tweaks
- Eliminate various compiler warnings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/*
* jlossls.h
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1998, Thomas G. Lane.
* Lossless JPEG Modifications:
* Copyright (C) 1999, Ken Murchison.
* libjpeg-turbo Modifications:
* Copyright (C) 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
* This include file contains common declarations for the lossless JPEG
* codec modules.
*/
#ifndef JLOSSLS_H
#define JLOSSLS_H
#if defined(C_LOSSLESS_SUPPORTED) || defined(D_LOSSLESS_SUPPORTED)
#define JPEG_INTERNALS
#include "jpeglib.h"
#include "jsamplecomp.h"
#define ALLOC_DARRAY(pool_id, diffsperrow, numrows) \
(JDIFFARRAY)(*cinfo->mem->alloc_sarray) \
((j_common_ptr)cinfo, pool_id, \
(diffsperrow) * sizeof(JDIFF) / sizeof(_JSAMPLE), numrows)
/*
* Table H.1: Predictors for lossless coding.
*/
#define PREDICTOR1 Ra
#define PREDICTOR2 Rb
#define PREDICTOR3 Rc
#define PREDICTOR4 (int)((JLONG)Ra + (JLONG)Rb - (JLONG)Rc)
#define PREDICTOR5 (int)((JLONG)Ra + RIGHT_SHIFT((JLONG)Rb - (JLONG)Rc, 1))
#define PREDICTOR6 (int)((JLONG)Rb + RIGHT_SHIFT((JLONG)Ra - (JLONG)Rc, 1))
#define PREDICTOR7 (int)RIGHT_SHIFT((JLONG)Ra + (JLONG)Rb, 1)
#endif
#ifdef C_LOSSLESS_SUPPORTED
typedef void (*predict_difference_method_ptr) (j_compress_ptr cinfo, int ci,
_JSAMPROW input_buf,
_JSAMPROW prev_row,
JDIFFROW diff_buf,
JDIMENSION width);
/* Lossless compressor */
typedef struct {
struct jpeg_forward_dct pub; /* public fields */
/* It is useful to allow each component to have a separate diff method. */
predict_difference_method_ptr predict_difference[MAX_COMPONENTS];
/* MCU rows left in the restart interval for each component */
unsigned int restart_rows_to_go[MAX_COMPONENTS];
/* Sample scaling */
void (*scaler_scale) (j_compress_ptr cinfo, _JSAMPROW input_buf,
_JSAMPROW output_buf, JDIMENSION width);
} jpeg_lossless_compressor;
typedef jpeg_lossless_compressor *lossless_comp_ptr;
#endif /* C_LOSSLESS_SUPPORTED */
#ifdef D_LOSSLESS_SUPPORTED
typedef void (*predict_undifference_method_ptr) (j_decompress_ptr cinfo,
int comp_index,
JDIFFROW diff_buf,
JDIFFROW prev_row,
JDIFFROW undiff_buf,
JDIMENSION width);
/* Lossless decompressor */
typedef struct {
struct jpeg_inverse_dct pub; /* public fields */
/* It is useful to allow each component to have a separate undiff method. */
predict_undifference_method_ptr predict_undifference[MAX_COMPONENTS];
/* Sample scaling */
void (*scaler_scale) (j_decompress_ptr cinfo, JDIFFROW diff_buf,
_JSAMPROW output_buf, JDIMENSION width);
} jpeg_lossless_decompressor;
typedef jpeg_lossless_decompressor *lossless_decomp_ptr;
#endif /* D_LOSSLESS_SUPPORTED */
#endif /* JLOSSLS_H */