KiCad PCB EDA Suite
Loading...
Searching...
No Matches
bit_stream_writer.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Mark Roszko <[email protected]>
3 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
4 * Copyright (C) 2007 Ecma International (original Java source)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * License info found here:
19 * https://www.loc.gov/preservation/digital/formats/fdd/fdd000491.shtml
20 */
21
22#pragma once
23
24#include <cstdint>
25#include <vector>
28#include <memory>
29#include <string>
30
31namespace U3D
32{
43{
44public:
46
47 void WriteU8( uint8_t aValue );
48
49 void WriteU16( uint16_t uValue );
50
51 void WriteU32( uint32_t uValue );
52
53 void WriteU64( uint64_t uValue );
54
55 void WriteI32( int32_t iValue );
56
57 void WriteF32( float fValue );
58
59 void WriteF64( double aValue );
60
61 void WriteCompressedU32( uint32_t aContext, uint32_t uValue );
62
63 void WriteCompressedU16( uint32_t aContext, uint16_t uValue );
64
65 void WriteCompressedU8( uint32_t aContext, uint8_t uValue );
66
67 void WriteString( const std::string& aStr );
68
69 void AlignToByte();
70
71 void AlignTo4Byte();
72
77 void GetBitCount( int32_t& rCount );
78
79 void WriteDataBlock( std::shared_ptr<DATA_BLOCK> b );
80
81 std::shared_ptr<DATA_BLOCK> GetDataBlock();
82
83private:
84 /*
85 * Stores the local values of the data to the data array
86 */
87 void putLocal();
88
89 /*
90 * Write the given symbol to the datablock in the specified context.
91 * rEscape returns as false if the symbol was written successfully.
92 * rEscape will return true when writing in dynamically compressed
93 * contexts when the symbol to write has not appeared yet in the
94 * context's histogram. In this case, the escape symbol, 0, is
95 * written.
96 */
97 void writeSymbol( uint32_t aContext, uint32_t aSymbol, bool& rEscape );
98
104 void swapBits8( uint32_t& rValue );
105
106 void writeBit( uint32_t aBit );
107
112 void incrementPosition();
113
118 void checkPosition();
119
120
121 std::unique_ptr<CONTEXT_MANAGER> m_contextManager;
122
126 uint32_t m_high;
127 uint32_t m_low;
128
132 uint32_t m_underflow;
140
141 std::vector<uint32_t> m_data;
143
147 uint32_t m_dataLocal;
148
153
158
159 const int32_t m_dataSizeIncrement = 0x000023F8;
160};
161} // namespace U3D
void WriteF64(double aValue)
void swapBits8(uint32_t &rValue)
changes the ordering of an 8 bit value so that the first 4 bits become the last 4 bits and the last 4...
void WriteU8(uint8_t aValue)
uint32_t m_underflow
stores the number of bits of underflow cause dby the limited range of high and low
void GetBitCount(int32_t &rCount)
Returns the number of bits written.
void WriteU16(uint16_t uValue)
void checkPosition()
Checks that the array allocated for writing is large enough.
void WriteI32(int32_t iValue)
void WriteU32(uint32_t uValue)
std::shared_ptr< DATA_BLOCK > GetDataBlock()
void WriteDataBlock(std::shared_ptr< DATA_BLOCK > b)
uint32_t m_high
high and low are the upper and lower limits on the probability
void WriteF32(float fValue)
void WriteString(const std::string &aStr)
void WriteCompressedU16(uint32_t aContext, uint16_t uValue)
std::vector< uint32_t > m_data
uint32_t m_dataLocalNext
The value of the data after m_dataLocal.
void writeSymbol(uint32_t aContext, uint32_t aSymbol, bool &rEscape)
std::unique_ptr< CONTEXT_MANAGER > m_contextManager
void incrementPosition()
Updates the values of the datablock stored in dataLocal and dataLocalNext to the next values in the d...
void WriteU64(uint64_t uValue)
uint32_t m_dataLocal
The local value of the data corresponding to m_dataPosition.
void WriteCompressedU32(uint32_t aContext, uint32_t uValue)
void writeBit(uint32_t aBit)
bool m_compressed
Indicates if a compressed value was written.
int32_t m_dataBitOffset
The offset into data local that the next write occur.
void WriteCompressedU8(uint32_t aContext, uint8_t uValue)
const int32_t m_dataSizeIncrement