/usr/include/CharLS/encoderstrategy.h is in libcharls-dev 1.0-1.
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 | //
// (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) :
_qdecoder(0),
_info(info),
_processLine(0),
valcurrent(0),
bitpos(0),
_isFFWritten(false),
_bytesWritten(0)
{
}
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(const void* pvoid, void* pvoidOut, size_t byteCount, void* pvoidCompare) = 0;
protected:
void Init(BYTE* compressedBytes, size_t byteCount)
{
bitpos = 32;
valcurrent = 0;
_position = compressedBytes;
_compressedLength = byteCount;
}
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();
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);
}
void Flush()
{
for (LONG i = 0; i < 4; ++i)
{
if (bitpos >= 32)
break;
if (_isFFWritten)
{
// insert highmost bit
*_position = BYTE(valcurrent >> 25);
valcurrent = valcurrent << 7;
bitpos += 7;
_isFFWritten = false;
}
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;
};
#endif
|