Grok 20.3.2
PacketLengthCache.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-2026 Grok Image Compression Inc.
3 *
4 * This source code is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License, version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This source code is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Affero General Public License for more details.
12 *
13 * You should have received a copy of the GNU Affero General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#pragma once
19
20#include <vector>
21#include <map>
22
23namespace grk
24{
25
30template<typename T>
32{
33public:
39
43 virtual ~PacketLengthCache();
44
51
56 PLMarker* getMarkers(void) const;
57
61 void deleteMarkers(void);
62
68 T next(void);
69
74 void rewind(void);
75
76private:
81
86};
87
88template<typename T>
91template<typename T>
96
97template<typename T>
99{
100 if(!plMarkers_)
101 plMarkers_ = strm ? new PLMarker(strm) : new PLMarker();
102
103 return plMarkers_;
104}
105
106template<typename T>
108{
109 return plMarkers_;
110}
111
112template<typename T>
114{
115 delete plMarkers_;
116 plMarkers_ = nullptr;
117}
118
119template<typename T>
121{
122 // we don't currently support PLM markers,
123 // so we disable packet length markers if we have both PLT and PLM
124 bool usePlt = plMarkers_ && !cp_->plmMarkers_ && plMarkers_->isEnabled();
125 if(usePlt)
126 {
127 T len = plMarkers_->pop();
128 if(len == 0)
129 grklog.error("PLT marker: missing packet lengths.");
130 return len;
131 }
132 return 0;
133}
134
135template<typename T>
137{
138 // we don't currently support PLM markers,
139 // so we disable packet length markers if we have both PLT and PLM
140 if(plMarkers_ && !cp_->plmMarkers_)
141 plMarkers_->rewind();
142}
143
144} // namespace grk
PLMarker * createMarkers(IStream *strm)
Creates new PL markers.
Definition PacketLengthCache.h:98
T next(void)
Gets next packet info.
Definition PacketLengthCache.h:120
CodingParams * cp_
pointer to CodingParams
Definition PacketLengthCache.h:85
PLMarker * getMarkers(void) const
Gets PL markers.
Definition PacketLengthCache.h:107
virtual ~PacketLengthCache()
Destroys a PacketLengthCache.
Definition PacketLengthCache.h:92
PacketLengthCache(CodingParams *cp)
Constructs a PacketLengthCache.
Definition PacketLengthCache.h:89
PLMarker * plMarkers_
PLMarker storing PL markers
Definition PacketLengthCache.h:80
void deleteMarkers(void)
Deletes PL markers.
Definition PacketLengthCache.h:113
void rewind(void)
rewinds state to be ready to read packet lengths from beginning of Tile packet stream
Definition PacketLengthCache.h:136
ResWindow.
Definition CompressedChunkCache.h:36
ILogger & grklog
Definition Logger.cpp:24
Coding parameters.
Definition CodingParams.h:402
Definition IStream.h:60
Manages raw (uncompressed) PLT and PLM markers.
Definition PLMarker.h:53