Skip to content

Commit 232a4c2

Browse files
jdv_cpjdv_cp
authored andcommitted
Force creation of LSE marker for images with 12+ bit depth (for better JAI compatibility). Removed redundant type.
1 parent 932fe52 commit 232a4c2

File tree

9 files changed

+60
-86
lines changed

9 files changed

+60
-86
lines changed

..svnbridge/.svnbridge

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>debug
2-
jpeg_ls_v2.2
3-
jpegls_0.04.981012
4-
junk
5-
release
6-
*.user
7-
CharLS.suo
8-
CharLS.ncb
9-
bin
10-
CMakeFiles
11-
xx
12-
</Value></Property><Property><Name>svn:ignore</Name><Value>debug
13-
jpeg_ls_v2.2
14-
jpegls_0.04.981012
15-
junk
16-
release
17-
*.user
18-
CharLS.suo
19-
CharLS.ncb
20-
bin
21-
CMakeFiles
22-
xx
23-
Debug
24-
CMakeCache.txt
25-
</Value></Property><Property><Name>svn:ignore</Name><Value>debug
26-
jpeg_ls_v2.2
27-
jpegls_0.04.981012
28-
junk
29-
release
30-
*.user
31-
CharLS.suo
32-
CharLS.ncb
33-
bin
34-
CMakeFiles
35-
xx
36-
Debug
37-
CMakeCache.txt
38-
_ReSharper.CharLS
1+
<?xml version="1.0" encoding="utf-8"?><ItemProperties xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Properties><Property><Name>svn:ignore</Name><Value>*.suo
392
</Value></Property><Property><Name>svn:ignore</Name><Value>debug
403
jpeg_ls_v2.2
414
jpegls_0.04.981012
@@ -51,4 +14,6 @@ Debug
5114
CMakeCache.txt
5215
_ReSharper.CharLS
5316
Release
17+
x64
18+
ipch
5419
</Value></Property></Properties></ItemProperties>

header.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ bool IsDefault(const JlsCustomParameters* pcustom)
3636
}
3737

3838

39+
LONG CLAMP(LONG i, LONG j, LONG MAXVAL)
40+
{
41+
if (i > MAXVAL || i < j)
42+
return j;
43+
44+
return i;
45+
}
46+
47+
48+
JlsCustomParameters ComputeDefault(LONG MAXVAL, LONG NEAR)
49+
{
50+
JlsCustomParameters preset = JlsCustomParameters();
51+
52+
LONG FACTOR = (MIN(MAXVAL, 4095) + 128)/256;
53+
54+
preset.T1 = CLAMP(FACTOR * (BASIC_T1 - 2) + 2 + 3*NEAR, NEAR + 1, MAXVAL);
55+
preset.T2 = CLAMP(FACTOR * (BASIC_T2 - 3) + 3 + 5*NEAR, preset.T1, MAXVAL);
56+
preset.T3 = CLAMP(FACTOR * (BASIC_T3 - 4) + 4 + 7*NEAR, preset.T2, MAXVAL);
57+
preset.MAXVAL = MAXVAL;
58+
preset.RESET = BASIC_RESET;
59+
return preset;
60+
}
61+
62+
3963
JLS_ERROR CheckParameterCoherent(const JlsParameters* pparams)
4064
{
4165
if (pparams->bitspersample < 6 || pparams->bitspersample > 16)
@@ -550,6 +574,11 @@ void JLSOutputStream::AddScan(const void* compareData, const JlsParameters* ppar
550574
{
551575
_segments.push_back(CreateLSE(&pparams->custom));
552576
}
577+
else if (pparams->bitspersample > 12)
578+
{
579+
JlsCustomParameters preset = ComputeDefault((1 << pparams->bitspersample) - 1, pparams->allowedlossyerror);
580+
_segments.push_back(CreateLSE(&preset));
581+
}
553582

554583
_icompLast += 1;
555584
_segments.push_back(EncodeStartOfScan(pparams,pparams->ilv == ILV_NONE ? _icompLast : -1));

header.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
#define JPEG_APP8 0xE8 // colorXForm
2424

2525

26+
27+
// Default bin sizes for JPEG-LS statistical modeling. Can be overriden at compression time, however this is rarely done.
28+
const int BASIC_T1 = 3;
29+
const int BASIC_T2 = 7;
30+
const int BASIC_T3 = 21;
31+
32+
const LONG BASIC_RESET = 64;
33+
2634
class JLSOutputStream;
2735

2836

@@ -37,6 +45,7 @@ class JlsCodecFactory
3745

3846
JLS_ERROR CheckParameterCoherent(const JlsParameters* pparams);
3947

48+
JlsCustomParameters ComputeDefault(LONG MAXVAL, LONG NEAR);
4049

4150
//
4251
// JpegSegment

jpegls.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ signed char* JlsContext::_tableC = CreateTableC();
2828
// used to determine how large runs should be encoded at a time.
2929
const int J[32] = {0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15};
3030

31-
// Default bin sizes for JPEG-LS statistical modeling. Can be overriden at compression time, however this is rarely done.
32-
const int BASIC_T1 = 3;
33-
const int BASIC_T2 = 7;
34-
const int BASIC_T3 = 21;
31+
3532

3633
#include "losslesstraits.h"
3734
#include "defaulttraits.h"
3835

3936
#include "scan.h"
4037

41-
signed char QuantizeGratientOrg(const Presets& preset, LONG NEAR, LONG Di)
38+
signed char QuantizeGratientOrg(const JlsCustomParameters& preset, LONG NEAR, LONG Di)
4239
{
4340
if (Di <= -preset.T3) return -4;
4441
if (Di <= -preset.T2) return -3;
@@ -56,7 +53,7 @@ signed char QuantizeGratientOrg(const Presets& preset, LONG NEAR, LONG Di)
5653

5754
std::vector<signed char> CreateQLutLossless(LONG cbit)
5855
{
59-
Presets preset = ComputeDefault((1 << cbit) - 1, 0);
56+
JlsCustomParameters preset = ComputeDefault((1 << cbit) - 1, 0);
6057
LONG range = preset.MAXVAL + 1;
6158

6259
std::vector<signed char> lut(range * 2);

losslesstraits.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef CHARLS_LOSSLESSTRAITS
88
#define CHARLS_LOSSLESSTRAITS
99

10+
#include "header.h"
11+
1012
//
1113
// optimized trait classes for lossless compression of 8 bit color and 8/16 bit monochrome images.
1214
// This class is assumes MAXVAL correspond to a whole number of bits, and no custom RESET value is set when encoding.

scan.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,6 @@ inlinehint LONG ApplySign(LONG i, LONG sign)
2727
{ return (sign ^ i) - sign; }
2828

2929

30-
LONG CLAMP(LONG i, LONG j, LONG MAXVAL)
31-
{
32-
if (i > MAXVAL || i < j)
33-
return j;
34-
35-
return i;
36-
}
37-
38-
Presets ComputeDefault(LONG MAXVAL, LONG NEAR)
39-
{
40-
Presets preset;
41-
42-
LONG FACTOR = (MIN(MAXVAL, 4095) + 128)/256;
43-
44-
preset.T1 = CLAMP(FACTOR * (BASIC_T1 - 2) + 2 + 3*NEAR, NEAR + 1, MAXVAL);
45-
preset.T2 = CLAMP(FACTOR * (BASIC_T2 - 3) + 3 + 5*NEAR, preset.T1, MAXVAL);
46-
preset.T3 = CLAMP(FACTOR * (BASIC_T3 - 4) + 4 + 7*NEAR, preset.T2, MAXVAL);
47-
preset.MAXVAL = MAXVAL;
48-
preset.RESET = BASIC_RESET;
49-
return preset;
50-
}
51-
5230

5331
// Two alternatives for GetPredictedValue() (second is slightly faster due to reduced branching)
5432

@@ -153,8 +131,7 @@ class JlsCodec : public STRATEGY
153131

154132
void SetPresets(const JlsCustomParameters& presets)
155133
{
156-
157-
Presets presetDefault = ComputeDefault(traits.MAXVAL, traits.NEAR);
134+
JlsCustomParameters presetDefault = ComputeDefault(traits.MAXVAL, traits.NEAR);
158135

159136
InitParams(presets.T1 != 0 ? presets.T1 : presetDefault.T1,
160137
presets.T2 != 0 ? presets.T2 : presetDefault.T2,
@@ -390,7 +367,7 @@ void JlsCodec<TRAITS,STRATEGY>::InitQuantizationLUT()
390367
// for lossless mode with default parameters, we have precomputed te luts for bitcounts 8,10,12 and 16
391368
if (traits.NEAR == 0 && traits.MAXVAL == (1 << traits.bpp) - 1)
392369
{
393-
Presets presets = ComputeDefault(traits.MAXVAL, traits.NEAR);
370+
JlsCustomParameters presets = ComputeDefault(traits.MAXVAL, traits.NEAR);
394371
if (presets.T1 == T1 && presets.T2 == T2 && presets.T3 == T3)
395372
{
396373
if (traits.bpp == 8)

streams.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,6 @@ class JLSOutputStream
9797
};
9898

9999

100-
101-
struct Presets : public JlsCustomParameters
102-
{
103-
public:
104-
Presets()
105-
{
106-
MAXVAL = 0;
107-
T1 = 0;
108-
T2 = 0;
109-
T3 = 0;
110-
RESET = 0;
111-
}
112-
};
113-
114-
115100
//
116101
// JLSInputStream: minimal implementation to read JPEG header streams
117102
//

test/..svnbridge/.svnbridge

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ rgb8bit
3737
jlsimage
3838
incorrect_images
3939
compsamples_jpegls
40+
</Value></Property><Property><Name>svn:ignore</Name><Value>Debug
41+
mars
42+
Release
43+
*.user
44+
CMakeFiles
45+
CMakeCache.txt
46+
rgb16bit
47+
rgb8bit
48+
jlsimage
49+
incorrect_images
50+
compsamples_jpegls
51+
x64
4052
</Value></Property></Properties></ItemProperties>

util.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#endif
2121

2222

23-
const LONG BASIC_RESET = 64;
24-
2523
inline LONG log_2(LONG n)
2624
{
2725
LONG x = 0;

0 commit comments

Comments
 (0)