1
#ifndef _JPEG2000_INDEX_NODE_H_
2
#define _JPEG2000_INDEX_NODE_H_
12
#include "image_info.h"
13
#include "packet_index.h"
14
#include "ipc/rdwr_lock.h"
25
* Contains the indexing information of a JPEG2000 image file that
26
* is managed by the index manager. This class can be printed.
28
* Maintains a read/write lock for controlling the multi-thread
29
* access to the indexing information. For instance, by default
30
* all the threads usually want to read the information. The
31
* packet index built on demand, so only when a thread wants to
32
* create a new level of the packet index, it needs to write.
39
friend class IndexManager;
44
RdWrLock::Ptr rdwr_lock;
47
vector<int> last_packet;
48
vector<uint64_t> last_offset_PLT;
49
vector<uint64_t> last_offset_packet;
51
string path_name; ///< Image file name
52
Metadata meta_data; ///< Image Metadata
53
int num_references; ///< Number of references
54
vector<int> max_resolution; ///< Maximum resolution number
56
vector<PacketIndex> packet_indexes; ///< Code-stream packet index
57
vector<CodestreamIndex> codestreams; ///< Image code-streams
59
CodingParameters::Ptr coding_parameters; ///< Image coding parameters
60
vector<list<ImageIndex>::iterator> hyper_links; ///< Image hyperlinks
64
* Gets the packet lengths from a PLT marker.
65
* @param file File where to read the data from.
66
* @param ind_codestream Codestream index.
67
* @param length_packet It is returned the length of the packet.
68
* @return <code>true</code> if successful.
70
bool GetPLTLength(const File& file, int ind_codestream, uint64_t *length_packet);
73
* Gets the packet offsets.
74
* @param file File where to read the data from.
75
* @param ind_codestream Codestream index.
76
* @param length_packet Packet length.
77
* @return <code>true</code> if successful.
79
void GetOffsetPacket(const File& file, int ind_codestream, uint64_t length_packet);
82
* Builds the required index for the required resolution levels.
83
* @param ind_codestream Codestream index.
84
* @param max_index Maximum resolution level.
85
* @return <code>true</code> if successful
87
bool BuildIndex(int ind_codestream, int max_index);
90
* Initializes the object.
91
* @param path_name Path name of the image.
92
* @param image_info Indexing image information.
93
* @return <code>true</code> if successful
95
bool Init(const string& path_name, const ImageInfo& image_info);
98
* Initializes the object.
99
* @param path_name Path name of the image.
100
* @param coding_parameters Coding parameters.
101
* @param image_info Indexing image information.
102
* @param index Image index.
103
* @return <code>true</code> if successful
105
bool Init(const string& path_name, CodingParameters::Ptr coding_parameters,
106
const ImageInfo& image_info, int index);
109
* Empty constructor. Only the index manager can
110
* use this constructor.
116
* Pointer of an object of this class.
118
typedef list<ImageIndex>::iterator Ptr;
124
ImageIndex(const ImageIndex& image_index)
130
* Returns the number of codestreams.
132
int GetNumCodestreams() const
134
if(codestreams.size() > 0) return codestreams.size();
135
else return hyper_links.size();
139
* Returns the number of meta-data blocks.
141
int GetNumMetadatas() const
143
return meta_data.meta_data.size();
147
* Gets the lock for reading, for a specific range of
149
* @return <code>true</code> if successful
151
bool ReadLock(const Range& range = Range(0, 0));
154
* Releases the lock for reading, for a specific range of
156
* @return <code>true</code> if successful
158
bool ReadUnlock(const Range& range = Range(0, 0));
161
* Returns the path name of the image.
163
string GetPathName() const
169
* Returns the path name of a given codestream, if it is
170
* a hyperlinked codestream.
171
* @param num_codestream Codestream number.
173
string GetPathName(int num_codestream) const
175
if(codestreams.size() > 0) return path_name;
176
else return hyper_links[num_codestream]->path_name;
180
* Returns the file segment the main header of a given
182
* @param num_codestream Codestream number
184
FileSegment GetMainHeader(int num_codestream) const
186
if(codestreams.size() > 0) return codestreams[num_codestream].header;
187
else return hyper_links[num_codestream]->codestreams.back().header;
191
* Returns the file segment of a meta-data block.
192
* @param num_metadata Meta-data number.
194
FileSegment GetMetadata(int num_metadata) const
196
return meta_data.meta_data[num_metadata];
200
* Returns the information of a place-holder.
201
* @param num_placeholder Place-holder number.
203
PlaceHolder GetPlaceHolder(int num_placeholder) const
205
return meta_data.place_holders[num_placeholder];
209
* Returns the file segment of a packet.
210
* @param num_codestream Codestream number.
211
* @param packet Packet information.
212
* @param offset If it is not <code>NULL</code> receives the
213
* offset of the packet.
215
FileSegment GetPacket(int num_codestream, const Packet& packet, int *offset = NULL);
218
* Returns a pointer to the coding parameters.
220
CodingParameters::Ptr GetCodingParameters() const
222
return coding_parameters;
226
* Returns <code>true</code> if the image contains
229
bool IsHyperLinked(int num_codestream) const
231
return (num_codestream < (int)hyper_links.size());
235
* Returns a pointer to a hyperlink.
236
* @param num_codestream Number of the hyperlink (codestream).
238
Ptr GetHyperLink(int num_codestream) const
240
return hyper_links[num_codestream];
244
* Returns the number of hyperlinks.
246
int GetNumHyperLinks() const
248
return (int)hyper_links.size();
251
operator CodingParameters::Ptr() const
253
return coding_parameters;
256
ImageIndex& operator=(const ImageIndex& image_index)
258
rdwr_lock = image_index.rdwr_lock;
260
meta_data = image_index.meta_data;
261
path_name = image_index.path_name;
262
num_references = image_index.num_references;
263
coding_parameters = image_index.coding_parameters;
265
base::copy(max_resolution, image_index.max_resolution);
266
base::copy(last_plt, image_index.last_plt);
267
base::copy(last_packet, image_index.last_packet);
268
base::copy(codestreams, image_index.codestreams);
269
base::copy(hyper_links, image_index.hyper_links);
270
base::copy(packet_indexes, image_index.packet_indexes);
271
base::copy(last_offset_PLT, image_index.last_offset_PLT);
272
base::copy(last_offset_packet, image_index.last_offset_packet);
277
friend ostream& operator <<(ostream &out, const ImageIndex &info_node)
279
out << "Image file name: " << info_node.path_name << endl
280
<< *(info_node.coding_parameters)
281
<< "Coding parameters ref: " << info_node.coding_parameters.use_count() << endl
282
<< "Max resolution: ";
283
for (vector<int>::const_iterator i = info_node.max_resolution.begin(); i != info_node.max_resolution.end(); i++)
288
for (vector<CodestreamIndex>::const_iterator i = info_node.codestreams.begin(); i != info_node.codestreams.end(); i++)
289
out << "Codestream index: " << endl << "----------------- " << endl << *i << endl << endl;
291
out << "Packet indexes: " << endl << "--------------- " << endl;
293
for (vector<PacketIndex>::const_iterator i = info_node.packet_indexes.begin(); i != info_node.packet_indexes.end(); i++)
294
for (int j = 0; j < i->Size(); j++)
295
out << j << " - " << (*i)[j] << endl;
297
out << endl << "Num. Hyperlinks: " << info_node.hyper_links.size() << endl;
299
for (vector<list<ImageIndex>::iterator>::const_iterator i = info_node.hyper_links.begin(); i != info_node.hyper_links.end(); i++)
300
out << "Hyperlinks: " << endl << "----------- " << endl << **i << endl << "----------- " << endl;
302
out << endl << "Meta-data: ";
303
out << endl << info_node.meta_data;
305
out << endl << "Num. References: " << info_node.num_references << endl;
310
virtual ~ImageIndex()
312
TRACE("Destroying the image index of '" << path_name << "'");
318
#endif /* _JPEG2000_INDEX_NODE_H_ */