This file is indexed.

/usr/include/CharLS/encoderstrategy.h is in libcharls-dev 1.1.0+dfsg-2.

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
// 
// (C) Jan de Vaan 2007-2010, all rights reserved. See the accompanying "License.txt" for licensed use. 
// 

#ifndef CHARLS_ENCODERSTRATEGY
#define CHARLS_ENCODERSTRATEGY

#include "processline.h"
#include "decoderstrategy.h"

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

class EncoderStrategy
{

public:
	explicit EncoderStrategy(const JlsParameters& info) :
		 _info(info),
		 valcurrent(0),
		 bitpos(0),
		 _compressedLength(0),
		 _position(0),
		 _isFFWritten(false),
		 _bytesWritten(0),
		 _compressedStream(NULL)
	{
	}

	virtual ~EncoderStrategy() 
	{
	}

	LONG PeekByte();

	void OnLineBegin(LONG cpixel, void* ptypeBuffer, LONG pixelStride)
	{
		_processLine->NewLineRequested(ptypeBuffer, cpixel, pixelStride);
	}

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

	virtual void SetPresets(const JlsCustomParameters& presets) = 0;

	virtual size_t EncodeScan(std::auto_ptr<ProcessLine> rawData, ByteStreamInfo* compressedData, void* pvoidCompare) = 0;

	virtual ProcessLine* CreateProcess(ByteStreamInfo rawStreamInfo) = 0;

protected:

	void Init(ByteStreamInfo* compressedStream)
	{
		bitpos = 32;
		valcurrent = 0;

		if (compressedStream->rawStream == NULL)
		{
			_position = compressedStream->rawData;
			_compressedLength = compressedStream->count;
		}
		else
		{
			_compressedStream = compressedStream->rawStream;
			_buffer.resize(4000);
			_position = (BYTE*)&_buffer[0];
			_compressedLength = _buffer.size();
		}
	}


	void AppendToBitStream(LONG value, LONG length)
	{
		ASSERT(length < 32 && length >= 0);

		ASSERT((_qdecoder.get() == NULL) || (length == 0 && value == 0) ||( _qdecoder->ReadLongValue(length) == value));

#ifndef NDEBUG
		if (length < 32)
		{
			int mask = (1 << (length)) - 1;
			ASSERT((value | mask) == mask);
		}
#endif

		bitpos -= length;
		if (bitpos >= 0)
		{
			valcurrent = valcurrent | (value << bitpos);
			return;
		}

		valcurrent |= value >> -bitpos;
		Flush();

		// A second flush may be required if extra marker-detect bits were needed and not all bits could be written.
		if (bitpos < 0)
		{
			valcurrent |= value >> -bitpos;
			Flush();
		}

		ASSERT(bitpos >=0);
		valcurrent |= value << bitpos;
	}

	void EndScan()
	{
		Flush();

		// if a 0xff was written, Flush() will force one unset bit anyway
		if (_isFFWritten)
			AppendToBitStream(0, (bitpos - 1) % 8);
		else
			AppendToBitStream(0, bitpos % 8);

		Flush();
		ASSERT(bitpos == 0x20);

		if (_compressedStream != NULL)
		{
			OverFlow();
		}
	}

	void OverFlow()
	{
		if (_compressedStream == NULL)
			throw JlsException(CompressedBufferTooSmall);

		size_t bytesCount = _position-(BYTE*)&_buffer[0];
		size_t bytesWritten = (size_t)_compressedStream->sputn((char*)&_buffer[0], _position - (BYTE*)&_buffer[0]);

		if (bytesWritten != bytesCount)
			throw JlsException(CompressedBufferTooSmall);

		_position = (BYTE*)&_buffer[0];
		_compressedLength = _buffer.size();
	}

	void Flush()
	{
		if (_compressedLength < 4)
		{
			OverFlow();
		}

		for (LONG i = 0; i < 4; ++i)
		{
			if (bitpos >= 32)
				break;

			if (_isFFWritten)
			{
				// JPEG-LS requirement (T.87, A.1) to detect markers: after a xFF value a single 0 bit needs to be inserted.
				*_position = BYTE(valcurrent >> 25);
				valcurrent = valcurrent << 7;
				bitpos += 7;
			}
			else
			{
				*_position = BYTE(valcurrent >> 24);
				valcurrent = valcurrent << 8;
				bitpos += 8;
			}

			_isFFWritten = *_position == 0xFF;
			_position++;
			_compressedLength--;
			_bytesWritten++;
		}
	}

	size_t GetLength() 
	{
		return _bytesWritten - (bitpos -32)/8; 
	}

	inlinehint void AppendOnesToBitStream(LONG length)
	{
		AppendToBitStream((1 << length) - 1, length);	
	}


	std::auto_ptr<DecoderStrategy> _qdecoder; 

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

private:
	unsigned int valcurrent;
	LONG bitpos;
	size_t _compressedLength;


	// encoding
	BYTE* _position;
	bool _isFFWritten;
	size_t _bytesWritten;

	std::vector<BYTE> _buffer;
	std::basic_streambuf<char>* _compressedStream;
};

#endif