Grok  9.7.5
LengthCache.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2022 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 #pragma once
18 #include <vector>
19 #include <map>
20 
21 namespace grk
22 {
23 struct MarkerInfo
24 {
25  MarkerInfo(uint16_t _id, uint64_t _pos, uint32_t _len);
26  MarkerInfo();
27  void dump(FILE* outputFileStream);
28  uint16_t id;
30  uint64_t pos;
32  uint32_t len;
33 };
35 {
36  TilePartInfo(uint64_t start, uint64_t endHeader, uint64_t end);
37  TilePartInfo(void);
38  void dump(FILE* outputFileStream, uint8_t tilePart);
40  uint64_t startPosition;
44  uint64_t endPosition;
45 };
46 struct TileInfo
47 {
48  TileInfo(void);
49  ~TileInfo(void);
50  bool checkResize(void);
51  bool hasTilePartInfo(void);
52  bool update(uint16_t tileIndex, uint8_t currentTilePart, uint8_t numTileParts);
53  TilePartInfo* getTilePartInfo(uint8_t tilePart);
54  void dump(FILE* outputFileStream, uint16_t tileNum);
55  uint16_t tileno;
56  uint8_t numTileParts;
58  uint8_t currentTilePart;
59 
60  private:
61  // TilePartInfo array
63 
64  // MarkerInfo array
66  uint32_t numMarkers;
67  uint32_t allocatedMarkers;
68 };
70 {
72  virtual ~CodeStreamInfo();
73  bool allocTileInfo(uint16_t numTiles);
74  bool updateTileInfo(uint16_t tileIndex, uint8_t currentTilePart, uint8_t numTileParts);
75  TileInfo* getTileInfo(uint16_t tileIndex);
76  void dump(FILE* outputFileStream);
77  void pushMarker(uint16_t id, uint64_t pos, uint32_t len);
78  uint64_t getMainHeaderStart(void);
79  void setMainHeaderStart(uint64_t start);
80  uint64_t getMainHeaderEnd(void);
81  void setMainHeaderEnd(uint64_t end);
82  bool seekToFirstTilePart(uint16_t tileIndex);
83 
84  private:
86  uint64_t mainHeaderStart;
88  uint64_t mainHeaderEnd;
89  std::vector<MarkerInfo*> marker;
90  // TileInfo array
92  uint16_t numTiles;
94 };
96 {
97  explicit TilePartLengthInfo();
98  TilePartLengthInfo(uint16_t tileno, uint32_t len);
99  uint16_t tileIndex_;
100  uint32_t length_;
101 };
102 
103 typedef std::vector<TilePartLengthInfo> TL_INFO_VEC;
104 typedef std::map<uint16_t, TL_INFO_VEC*> TL_MAP;
105 
107 {
111 
112  bool read(uint8_t* headerData, uint16_t header_size);
113  void rewind(void);
115  void invalidate(void);
116  bool valid(void);
117  bool seekTo(uint16_t skipTileIndex, IBufferedStream* stream, uint64_t firstSotPos);
118  bool writeBegin(uint16_t numTilePartsTotal);
119  void push(uint16_t tileIndex, uint32_t tile_part_size);
120  bool writeEnd(void);
129  static bool addTileMarkerInfo(uint16_t tileno, CodeStreamInfo* codeStreamInfo, uint16_t type,
130  uint64_t pos, uint32_t len);
131 
132  private:
133  void push(uint8_t i_TLM, TilePartLengthInfo curr_vec);
135  TL_MAP::iterator markerIt_;
139  uint64_t streamStart;
140  bool valid_;
142  // used to track tile index when there are no tile indices
143  // stored in markers
144  uint16_t tileCount_;
145 };
146 
148 {
149  PacketInfo(void);
150  uint32_t getPacketDataLength(void);
151  // header length only available when packet header is parsed
152  // not available from PL marker
153  uint32_t headerLength;
154  uint32_t packetLength;
156 };
157 
159 {
162 
163  std::vector<PacketInfo*> packetInfo;
164 };
165 
166 } // namespace grk
Copyright (C) 2016-2022 Grok Image Compression Inc.
Definition: ICacheable.h:20
std::map< uint16_t, TL_INFO_VEC * > TL_MAP
Definition: LengthCache.h:104
std::vector< TilePartLengthInfo > TL_INFO_VEC
Definition: LengthCache.h:103
Definition: LengthCache.h:70
IBufferedStream * stream
Definition: LengthCache.h:93
uint64_t mainHeaderStart
main header start position (SOC position)
Definition: LengthCache.h:86
uint64_t getMainHeaderStart(void)
Definition: LengthCache.cpp:233
void pushMarker(uint16_t id, uint64_t pos, uint32_t len)
Definition: LengthCache.cpp:229
bool seekToFirstTilePart(uint16_t tileIndex)
Definition: LengthCache.cpp:249
bool updateTileInfo(uint16_t tileIndex, uint8_t currentTilePart, uint8_t numTileParts)
Definition: LengthCache.cpp:187
bool allocTileInfo(uint16_t numTiles)
Definition: LengthCache.cpp:179
virtual ~CodeStreamInfo()
Definition: LengthCache.cpp:173
void setMainHeaderEnd(uint64_t end)
Definition: LengthCache.cpp:245
void dump(FILE *outputFileStream)
Definition: LengthCache.cpp:200
uint16_t numTiles
Definition: LengthCache.h:92
uint64_t getMainHeaderEnd(void)
Definition: LengthCache.cpp:241
std::vector< MarkerInfo * > marker
Definition: LengthCache.h:89
TileInfo * getTileInfo(uint16_t tileIndex)
Definition: LengthCache.cpp:193
void setMainHeaderStart(uint64_t start)
Definition: LengthCache.cpp:237
CodeStreamInfo(IBufferedStream *str)
Definition: LengthCache.cpp:170
TileInfo * tileInfo
Definition: LengthCache.h:91
uint64_t mainHeaderEnd
main header end position (first SOT position)
Definition: LengthCache.h:88
Definition: IBufferedStream.h:20
Definition: LengthCache.h:24
MarkerInfo()
Definition: LengthCache.cpp:24
void dump(FILE *outputFileStream)
Definition: LengthCache.cpp:27
uint16_t id
Definition: LengthCache.h:28
uint32_t len
length (marker id included)
Definition: LengthCache.h:32
uint64_t pos
position in code stream
Definition: LengthCache.h:30
Definition: LengthCache.h:159
~PacketInfoCache()
Definition: LengthCache.cpp:536
std::vector< PacketInfo * > packetInfo
Definition: LengthCache.h:163
Definition: LengthCache.h:148
uint32_t packetLength
Definition: LengthCache.h:154
uint32_t headerLength
Definition: LengthCache.h:153
bool parsedData
Definition: LengthCache.h:155
PacketInfo(void)
Definition: LengthCache.cpp:535
uint32_t getPacketDataLength(void)
Definition: LengthCache.cpp:541
Definition: LengthCache.h:47
TilePartInfo * getTilePartInfo(uint8_t tilePart)
Definition: LengthCache.cpp:150
uint32_t numMarkers
Definition: LengthCache.h:66
void dump(FILE *outputFileStream, uint16_t tileNum)
Definition: LengthCache.cpp:156
bool hasTilePartInfo(void)
Definition: LengthCache.cpp:81
MarkerInfo * markerInfo
Definition: LengthCache.h:65
uint8_t numTileParts
Definition: LengthCache.h:56
uint8_t currentTilePart
Definition: LengthCache.h:58
~TileInfo(void)
Definition: LengthCache.cpp:52
uint8_t allocatedTileParts
Definition: LengthCache.h:57
bool update(uint16_t tileIndex, uint8_t currentTilePart, uint8_t numTileParts)
Definition: LengthCache.cpp:85
uint16_t tileno
Definition: LengthCache.h:55
bool checkResize(void)
Definition: LengthCache.cpp:57
TileInfo(void)
Definition: LengthCache.cpp:44
TilePartInfo * tilePartInfo
Definition: LengthCache.h:62
uint32_t allocatedMarkers
Definition: LengthCache.h:67
Definition: LengthCache.h:107
bool seekTo(uint16_t skipTileIndex, IBufferedStream *stream, uint64_t firstSotPos)
Definition: LengthCache.cpp:455
bool valid(void)
Definition: LengthCache.cpp:293
void push(uint16_t tileIndex, uint32_t tile_part_size)
Definition: LengthCache.cpp:498
TL_MAP::iterator markerIt_
Definition: LengthCache.h:135
bool writeEnd(void)
Definition: LengthCache.cpp:502
TL_INFO_VEC * curr_vec_
Definition: LengthCache.h:137
void invalidate(void)
Definition: LengthCache.cpp:297
bool writeBegin(uint16_t numTilePartsTotal)
Definition: LengthCache.cpp:474
TL_MAP * markers_
Definition: LengthCache.h:134
bool hasTileIndices_
Definition: LengthCache.h:141
uint16_t tileCount_
Definition: LengthCache.h:144
uint16_t markerTilePartIndex_
Definition: LengthCache.h:136
void rewind(void)
Definition: LengthCache.cpp:416
static bool addTileMarkerInfo(uint16_t tileno, CodeStreamInfo *codeStreamInfo, uint16_t type, uint64_t pos, uint32_t len)
Add tile header marker information.
Definition: LengthCache.cpp:519
TilePartLengthInfo * getNext(void)
Definition: LengthCache.cpp:427
TileLengthMarkers()
Definition: LengthCache.cpp:271
~TileLengthMarkers()
Definition: LengthCache.cpp:280
bool read(uint8_t *headerData, uint16_t header_size)
Definition: LengthCache.cpp:302
uint64_t streamStart
Definition: LengthCache.h:139
bool valid_
Definition: LengthCache.h:140
IBufferedStream * stream_
Definition: LengthCache.h:138
Definition: LengthCache.h:35
uint64_t startPosition
start position of tile part
Definition: LengthCache.h:40
uint64_t endHeaderPosition
end position of tile part header
Definition: LengthCache.h:42
uint64_t endPosition
end position of tile part
Definition: LengthCache.h:44
void dump(FILE *outputFileStream, uint8_t tilePart)
Definition: LengthCache.cpp:35
TilePartInfo(void)
Definition: LengthCache.cpp:34
Definition: LengthCache.h:96
TilePartLengthInfo()
Definition: LengthCache.cpp:267
uint32_t length_
Definition: LengthCache.h:100
uint16_t tileIndex_
Definition: LengthCache.h:99