ESA JPIP server  0.1
woi_composer.h
Go to the documentation of this file.
1 #ifndef _JPIP_WOI_COMPOSER_H_
2 #define _JPIP_WOI_COMPOSER_H_
3 
4 
5 #include "woi.h"
6 #include "jpeg2000/packet.h"
8 
9 
10 namespace jpip
11 {
12 
13  using namespace std;
14  using namespace jpeg2000;
15 
16 
28  {
29  private:
32  bool more_packets;
37 
42 
43  public:
48  {
49  more_packets = false;
50  }
51 
55  WOIComposer(const WOIComposer& composer)
56  {
57  *this = composer;
58  }
59 
65  {
66  more_packets = false;
67  this->coding_parameters = coding_parameters;
68  }
69 
77  void Reset(const WOI& woi, CodingParameters::Ptr coding_parameters)
78  {
79  more_packets = true;
80  current_packet = Packet();
81  max_resolution = woi.resolution;
82  this->coding_parameters = coding_parameters;
83 
84  pxy1 = woi.position * (1L << (coding_parameters->num_levels - woi.resolution));
85  pxy2 = (woi.position + woi.size - 1) * (1L << (coding_parameters->num_levels - woi.resolution));
86 
87  min_precinct_xy = coding_parameters->GetPrecincts(current_packet.resolution, pxy1);
88  if (min_precinct_xy.x != 0) min_precinct_xy.x--;
89  if (min_precinct_xy.y != 0) min_precinct_xy.y--;
90 
91  max_precinct_xy = coding_parameters->GetPrecincts(current_packet.resolution, pxy2);
92  if (max_precinct_xy.x != 0) max_precinct_xy.x--;
93  if (max_precinct_xy.y != 0) max_precinct_xy.y--;
94 
95  current_packet.precinct_xy = min_precinct_xy;
96  }
97 
102  {
103  pxy1 = composer.pxy1;
104  pxy2 = composer.pxy2;
105  more_packets = composer.more_packets;
106  max_resolution = composer.max_resolution;
107  current_packet = composer.current_packet;
108  min_precinct_xy = composer.min_precinct_xy;
109  max_precinct_xy = composer.max_precinct_xy;
110  coding_parameters = composer.coding_parameters;
111 
112  return *this;
113  }
114 
119  {
120  return current_packet;
121  }
122 
128  bool GetNextPacket(Packet *packet = NULL)
129  {
130  if(!more_packets) return false;
131  else {
132  if(packet) *packet = current_packet;
133 
134  if (current_packet.precinct_xy.x < max_precinct_xy.x) current_packet.precinct_xy.x++;
135  else
136  {
137  current_packet.precinct_xy.x = min_precinct_xy.x;
138 
139  if (current_packet.precinct_xy.y < max_precinct_xy.y) current_packet.precinct_xy.y++;
140  else
141  {
142  current_packet.precinct_xy.y = min_precinct_xy.y;
143 
144  if (current_packet.component < (coding_parameters->num_components - 1)) current_packet.component++;
145  else
146  {
147  current_packet.component = 0;
148 
149  if (current_packet.resolution < max_resolution) current_packet.resolution++;
150  else
151  {
152  current_packet.resolution = 0;
153 
154  if (current_packet.layer < (coding_parameters->num_layers - 1)) current_packet.layer++;
155  else {
156  more_packets = false;
157  return true;
158  }
159  }
160 
161  min_precinct_xy = coding_parameters->GetPrecincts(current_packet.resolution, pxy1);
162  if (min_precinct_xy.x != 0) min_precinct_xy.x--;
163  if (min_precinct_xy.y != 0) min_precinct_xy.y--;
164 
165  max_precinct_xy = coding_parameters->GetPrecincts(current_packet.resolution, pxy2);
166  if (max_precinct_xy.x != 0) max_precinct_xy.x--;
167  if (max_precinct_xy.y != 0) max_precinct_xy.y--;
168 
169  current_packet.precinct_xy = min_precinct_xy;
170  }
171  }
172  }
173 
174  return true;
175  }
176  }
177 
178  virtual ~WOIComposer()
179  {
180  }
181  };
182 
183 }
184 
185 #endif /* _JPIP_INDEX_MANAGER_H_ */
186 
WOIComposer & operator=(const WOIComposer &composer)
Copy assignment.
Definition: woi_composer.h:101
WOIComposer()
Initializes the object.
Definition: woi_composer.h:47
SHARED_PTR< CodingParameters > Ptr
Pointer to an object of this class.
Definition: coding_parameters.h:97
Class that identifies a WOI (Window Of Interest).
Definition: woi.h:24
bool more_packets
Flag to control the last packet.
Definition: woi_composer.h:32
WOIComposer(CodingParameters::Ptr coding_parameters)
Initializes the object.
Definition: woi_composer.h:64
Point pxy2
Bottom-right corner of the WOI.
Definition: woi_composer.h:31
void Reset(const WOI &woi, CodingParameters::Ptr coding_parameters)
Resets the packets navigation and starts a new one.
Definition: woi_composer.h:77
bool GetNextPacket(Packet *packet=NULL)
Moves to the next packet of the WOI.
Definition: woi_composer.h:128
Packet current_packet
Current packet.
Definition: woi_composer.h:36
Size max_precinct_xy
Maximum precinct.
Definition: woi_composer.h:35
Represents a couple of integer values that can be used to identify a coordinate as well as a size...
Definition: point.h:18
Size size
Size of the WOI (width and height)
Definition: woi.h:27
Point pxy1
Upper-left corner of the WOI.
Definition: woi_composer.h:30
Size min_precinct_xy
Minimum precinct.
Definition: woi_composer.h:34
int max_resolution
Maximum resolution.
Definition: woi_composer.h:33
virtual ~WOIComposer()
Definition: woi_composer.h:178
Packet GetCurrentPacket() const
Returns the current packet.
Definition: woi_composer.h:118
int x
Value X.
Definition: point.h:21
int resolution
Resolution level where the WOI is located (0 == the highest)
Definition: woi.h:29
By means of this class it is possible to find out the which packets of an image are associated to a W...
Definition: woi_composer.h:27
CodingParameters::Ptr coding_parameters
Pointer to the associated coding parameters.
Definition: woi_composer.h:41
Point position
Position of the upper-left corner of the WOI.
Definition: woi.h:28
Contains the information of a packet.
Definition: packet.h:15
WOIComposer(const WOIComposer &composer)
Copy constructor.
Definition: woi_composer.h:55