This file is indexed.

/usr/include/CharLS/decoderstrategy.h is in libcharls-dev 1.0-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
// 
// (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use. 
// 

#ifndef CHARLS_DECODERSTATEGY
#define CHARLS_DECODERSTATEGY

#include "streams.h"
#include "processline.h"
#include "config.h"
#include "util.h"

// Implements encoding to stream of bits. In encoding mode JpegLsCodec inherits from EncoderStrategy



class DecoderStrategy
{
public:
	DecoderStrategy(const JlsParameters& info) :
		  _info(info),
	      _processLine(0),
		  _readCache(0),
		  _validBits(0),
		  _position(0)
	  {
	  }

	  virtual ~DecoderStrategy()
	  {
	  }

	  virtual void SetPresets(const JlsCustomParameters& presets) = 0;
	  virtual size_t DecodeScan(void* outputData, const JlsRect& size, const void* compressedData, size_t byteCount, bool bCheck) = 0;

	  void Init(BYTE* compressedBytes, size_t byteCount)
	  {
		  _validBits = 0;
		  _readCache = 0;
		  _position = compressedBytes;
		  _endPosition = compressedBytes + byteCount;
		  _nextFFPosition = FindNextFF();
		  MakeValid();
	  }

	  inlinehint void Skip(LONG length)
	  {
		  _validBits -= length;
		  _readCache = _readCache << length; 
	  }

	
	  void OnLineBegin(LONG /*cpixel*/, void* /*ptypeBuffer*/, LONG /*pixelStride*/) 
	  {}


	  void OnLineEnd(LONG pixelCount, const void* ptypeBuffer, LONG pixelStride)
	  {
	  		_processLine->NewLineDecoded(ptypeBuffer, pixelCount, pixelStride);
	  }

	  void EndScan()
	  {
		  if ((*_position) != 0xFF)
		  {
			  ReadBit();

			  if ((*_position) != 0xFF)
				throw JlsException(TooMuchCompressedData);
		  }

		  if (_readCache != 0)
		     throw JlsException(TooMuchCompressedData);
	  }


	  inlinehint bool OptimizedRead()
	  {
		  // Easy & fast: if there is no 0xFF byte in sight, we can read without bitstuffing
		  if (_position < _nextFFPosition - (sizeof(bufType)-1))
		  {
			  _readCache		 |= FromBigEndian<sizeof(bufType)>::Read(_position) >> _validBits;
			  int bytesToRead = (bufferbits - _validBits) >> 3;
			  _position += bytesToRead;
			  _validBits += bytesToRead * 8;
			  ASSERT(_validBits >= bufferbits - 8);
			  return true;
		  }
		  return false;
	  }

	  typedef size_t bufType;

	  enum { 
		  bufferbits = sizeof( bufType ) * 8
	  };
		
	  void MakeValid()
	  {
		  ASSERT(_validBits <=bufferbits - 8);

		  if (OptimizedRead())
			  return;

		  do
		  {
			  if (_position >= _endPosition)
			  {
				  if (_validBits <= 0)
					  throw JlsException(InvalidCompressedData);

				  return;
			  }

			  bufType valnew	  = _position[0];
			  
			  if (valnew == 0xFF)		
			  {
				  // JPEG bitstream rule: no FF may be followed by 0x80 or higher	    			 
				 if (_position == _endPosition - 1 || (_position[1] & 0x80) != 0)
				 {
					 if (_validBits <= 0)
					 	throw JlsException(InvalidCompressedData);
					 
					 return;
			     }
			  }

			  _readCache		 |= valnew << (bufferbits - 8  - _validBits);
			  _position   += 1;				
			  _validBits		 += 8; 

			  if (valnew == 0xFF)		
			  {
				  _validBits--;		
			  }
		  }
		  while (_validBits < bufferbits - 8);

		  _nextFFPosition = FindNextFF();
		  return;

	  }


	  BYTE* FindNextFF()
	  {
		  BYTE* pbyteNextFF = _position;

		  while (pbyteNextFF < _endPosition)
	      {
			  if (*pbyteNextFF == 0xFF) 
			  {				  
				  break;
			  }
    		  pbyteNextFF++;
		  }
		  

		  return pbyteNextFF;
	  }


	  BYTE* GetCurBytePos() const
	  {
		  LONG  validBits = _validBits;
		  BYTE* compressedBytes = _position;

		  for (;;)
		  {
			  LONG cbitLast = compressedBytes[-1] == 0xFF ? 7 : 8;

			  if (validBits < cbitLast )
				  return compressedBytes;

			  validBits -= cbitLast; 
			  compressedBytes--;
		  }	
	  }


	  inlinehint LONG ReadValue(LONG length)
	  {
		  if (_validBits < length)
		  {
			  MakeValid();
			  if (_validBits < length)
				  throw JlsException(InvalidCompressedData);
		  }
		
		  ASSERT(length != 0 && length <= _validBits);
		  ASSERT(length < 32);
		  LONG result = LONG(_readCache >> (bufferbits - length));
		  Skip(length);		
		  return result;
	  }


	  inlinehint LONG PeekByte()
	  { 
		  if (_validBits < 8)
		  {
			  MakeValid();
		  }

		  return _readCache >> (bufferbits - 8); 
	  }



	  inlinehint bool ReadBit()
	  {
		  if (_validBits <= 0)
		  {
			  MakeValid();
		  }

		  bool bSet = (_readCache & (bufType(1) << (bufferbits - 1))) != 0;
		  Skip(1);
		  return bSet;
	  }



	  inlinehint LONG Peek0Bits()
	  {
		  if (_validBits < 16)
		  {
			  MakeValid();
		  }
		  bufType valTest = _readCache;

		  for (LONG count = 0; count < 16; count++)
		  {
			  if ((valTest & (bufType(1) << (bufferbits - 1))) != 0)
				  return count;

			  valTest <<= 1;
		  }
		  return -1;
	  }



	  inlinehint LONG ReadHighbits()
	  {
		  LONG count = Peek0Bits();
		  if (count >= 0)
		  {
			  Skip(count + 1);
			  return count;
		  }
		  Skip(15);

		  for (LONG highbits = 15; ; highbits++)
		  { 
			  if (ReadBit())
				  return highbits;
		  }                 	
	  }


	  LONG ReadLongValue(LONG length)
	  {
		  if (length <= 24)
			  return ReadValue(length);

		  return (ReadValue(length - 24) << 24) + ReadValue(24);
	  }

protected:
	JlsParameters _info;
	std::auto_ptr<ProcessLine> _processLine;

private:
	// decoding
	bufType _readCache;
	LONG _validBits;
	BYTE* _position;
	BYTE* _nextFFPosition;
	BYTE* _endPosition;
};


#endif