ESA JPIP server  0.1
coding_parameters.h
Go to the documentation of this file.
1 #ifndef _JPEG2000_CODING_PARAMETERS_H_
2 #define _JPEG2000_CODING_PARAMETERS_H_
3 
4 
5 #include <vector>
6 #include <math.h>
7 
8 #include "tr1_compat.h"
9 
10 #include "base.h"
11 #include "point.h"
12 #include "trace.h"
13 #include "packet.h"
14 
15 
16 namespace jpeg2000
17 {
18 
24  {
25  private:
30  vector<int> total_precincts;
31 
36 
45  int GetProgressionIndexRPCL(int l, int r, int c, int px, int py)
46  {
47  Size precinct_point = GetPrecincts(r, size);
48  return (total_precincts[r] * num_components * num_layers) + (py * precinct_point.x * num_components * num_layers) +
49  (px * num_components * num_layers) + (c * num_layers) + l;
50  }
51 
60  int GetProgressionIndexRLCP(int l, int r, int c, int px, int py)
61  {
62  Size precinct_point = GetPrecincts(r, size);
63  return (total_precincts[r] * num_components * num_layers) + (l * num_components * precinct_point.x * precinct_point.y) +
64  (c * precinct_point.x * precinct_point.y) + (py * precinct_point.x) + px;
65  }
66 
75  int GetProgressionIndexLRCP(int l, int r, int c, int px, int py)
76  {
77  Size precinct_point = GetPrecincts(r, size);
79  (c * precinct_point.x * precinct_point.y) + (py * precinct_point.x) + px;
80  }
81 
82  public:
84  int num_levels;
85  int num_layers;
88 
92  vector<Size> precinct_size;
93 
97  typedef SHARED_PTR<CodingParameters> Ptr;
98 
103  enum
104  {
110  };
111 
116  {
117  num_levels = 0;
118  num_layers = 0;
119  progression = 0;
120  num_components = 0;
121  }
122 
127  {
128  *this = cod_params;
129  }
130 
134  const CodingParameters& operator=(const CodingParameters& cod_params)
135  {
136  size = cod_params.size;
137  num_levels = cod_params.num_levels;
138  num_layers = cod_params.num_layers;
139  progression = cod_params.progression;
140  num_components = cod_params.num_components;
143 
144  return *this;
145  }
146 
147  template<typename T> T& SerializeWith(T& stream)
148  {
150  }
151 
152  friend ostream& operator <<(ostream &out, const CodingParameters &params)
153  {
154  out << "Progression: " <<
155  (params.progression == LRCP_PROGRESSION ? "LRCP" :
156  (params.progression == RLCP_PROGRESSION ? "RLCP" :
157  (params.progression == RPCL_PROGRESSION ? "RPCL" :
158  (params.progression == PCRL_PROGRESSION ? "PCRL" :
159  (params.progression == CPRL_PROGRESSION ? "CPRL" : "UNKOWN"))))) << endl
160  << "Size: " << params.size << endl << "Num. of levels: " << params.num_levels << endl
161  << "Num. of layers: " << params.num_layers << endl
162  << "Num. of components: " << params.num_components << endl << "Precinct size: { ";
163 
164  for (vector<Size>::const_iterator i = params.precinct_size.begin(); i != params.precinct_size.end(); i++)
165  out << *i << " ";
166 
167  out << "}" << endl;
168 
169  return out;
170  }
171 
176  {
178  }
179 
185  Size GetPrecincts(int r, const Size& point)
186  {
187  return Size(
188  ceil(ceil((double)point.x / (1L << (num_levels - r))) / (double)precinct_size[r].x),
189  ceil(ceil((double)point.y / (1L << (num_levels - r))) / (double)precinct_size[r].y)
190  );
191  }
192 
198  int GetProgressionIndex(const Packet& packet)
199  {
200  if(total_precincts.size() == 0)
202 
204  return GetProgressionIndexRPCL(packet.layer, packet.resolution, packet.component, packet.precinct_xy.x, packet.precinct_xy.y);
205 
206  } else if(progression == RLCP_PROGRESSION) {
207  return GetProgressionIndexRLCP(packet.layer, packet.resolution, packet.component, packet.precinct_xy.x, packet.precinct_xy.y);
208 
209  } else if(progression == LRCP_PROGRESSION) {
210  return GetProgressionIndexLRCP(packet.layer, packet.resolution, packet.component, packet.precinct_xy.x, packet.precinct_xy.y);
211 
212  } else {
213  ERROR("Progression (" << progression << ") not supported");
214  return 0;
215  }
216  }
217 
223  int GetPrecinctDataBinId(const Packet& packet)
224  {
225  if(total_precincts.size() == 0)
227 
228  Size precinct_point = GetPrecincts(packet.resolution, size);
229  int s = total_precincts[packet.resolution] + (precinct_point.x * packet.precinct_xy.y) + packet.precinct_xy.x;
230  return (packet.component + (s * num_components));
231  }
232 
240  int GetClosestResolution(const Size& res_size, Size *res_image_size);
241 
249  int GetRoundUpResolution(const Size& res_size, Size *res_image_size);
250 
258  int GetRoundDownResolution(const Size& res_size, Size *res_image_size);
259 
260 
262  {
263  }
264  };
265 
266 }
267 
268 #endif /* _JPEG2000_CODING_PARAMETERS_H_ */
int num_layers
Number of quality layers.
Definition: coding_parameters.h:85
static void copy(std::vector< T > &dest, const std::vector< T > &src)
Copies a vector.
Definition: base.h:30
RPCL.
Definition: coding_parameters.h:107
Point Size
It is a synonymous of the class Point.
Definition: point.h:247
SHARED_PTR< CodingParameters > Ptr
Pointer to an object of this class.
Definition: coding_parameters.h:97
LRCP.
Definition: coding_parameters.h:105
int progression
Progression order.
Definition: coding_parameters.h:86
friend ostream & operator<<(ostream &out, const CodingParameters &params)
Definition: coding_parameters.h:152
#define ERROR(a)
Definition: trace.h:79
int num_levels
Number of resolution levels.
Definition: coding_parameters.h:84
Size size
Image size.
Definition: coding_parameters.h:83
int GetRoundUpResolution(const Size &res_size, Size *res_image_size)
Returns the resolution level according to the given size and the round-up round policy.
Definition: coding_parameters.cc:58
CPRL.
Definition: coding_parameters.h:109
vector< int > total_precincts
Contains the number of precincts of each resolution level.
Definition: coding_parameters.h:30
int GetRoundDownResolution(const Size &res_size, Size *res_image_size)
Returns the resolution level according to the given size and the round-down round policy...
Definition: coding_parameters.cc:80
int GetClosestResolution(const Size &res_size, Size *res_image_size)
Returns the resolution level according to the given size and the closest round policy.
Definition: coding_parameters.cc:23
Size GetPrecincts(int r, const Size &point)
Returns a precinct coordinate adjusted to a given resolution level.
Definition: coding_parameters.h:185
int GetPrecinctDataBinId(const Packet &packet)
Returns the data-bin identifier associated to the given packet.
Definition: coding_parameters.h:223
Contains the coding parameters of a JPEG2000 image codestream.
Definition: coding_parameters.h:23
virtual ~CodingParameters()
Definition: coding_parameters.h:261
Represents a couple of integer values that can be used to identify a coordinate as well as a size...
Definition: point.h:18
int GetProgressionIndexRLCP(int l, int r, int c, int px, int py)
Returns the index of a packet according to the RLCP progression.
Definition: coding_parameters.h:60
int layer
Quality layer.
Definition: packet.h:18
int y
Value Y.
Definition: point.h:22
int GetProgressionIndexLRCP(int l, int r, int c, int px, int py)
Returns the index of a packet according to the LRCP progression.
Definition: coding_parameters.h:75
int GetProgressionIndexRPCL(int l, int r, int c, int px, int py)
Returns the index of a packet according to the RPCL progression.
Definition: coding_parameters.h:45
int x
Value X.
Definition: point.h:21
int component
Component number.
Definition: packet.h:19
RLCP.
Definition: coding_parameters.h:106
const CodingParameters & operator=(const CodingParameters &cod_params)
Copy assignment.
Definition: coding_parameters.h:134
int resolution
Resolution level.
Definition: packet.h:20
int num_components
Number of components.
Definition: coding_parameters.h:87
CodingParameters()
Initializes the object.
Definition: coding_parameters.h:115
CodingParameters(const CodingParameters &cod_params)
Copy constructor.
Definition: coding_parameters.h:126
Point precinct_xy
Precinct coordinate.
Definition: packet.h:21
PCRL.
Definition: coding_parameters.h:108
void FillTotalPrecinctsVector()
Fills the vector total_precincts.
Definition: coding_parameters.cc:7
bool IsResolutionProgression() const
Returns true if the progression is RLCP or RPCL.
Definition: coding_parameters.h:175
vector< Size > precinct_size
Precinct sizes of each resolution level.
Definition: coding_parameters.h:92
T & SerializeWith(T &stream)
Definition: coding_parameters.h:147
Contains the information of a packet.
Definition: packet.h:15
int GetProgressionIndex(const Packet &packet)
Returns the index of a packet according to the progression order.
Definition: coding_parameters.h:198