~josejuan-sanchez/esajpip/debian

« back to all changes in this revision

Viewing changes to src/jpeg2000/file_manager.h

  • Committer: José Juan Sánchez Hernández
  • Date: 2013-04-02 18:14:26 UTC
  • Revision ID: josejuan.sanchez@gmail.com-20130402181426-07xn3djblburck53
Version for Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _JPEG2000_FILE_MANAGER_H_
 
2
#define _JPEG2000_FILE_MANAGER_H_
 
3
 
 
4
 
 
5
#include <sys/stat.h>
 
6
#include "data/serialize.h"
 
7
#include "image_info.h"
 
8
 
 
9
 
 
10
namespace jpeg2000
 
11
{
 
12
 
 
13
  /**
 
14
   * Manages the image files of a repository, allowing read their
 
15
   * indexing information, with a caching mechanism for efficiency.
 
16
   */
 
17
  class FileManager
 
18
  {
 
19
  private:
 
20
    string root_dir_;   ///< Root directory of the repository
 
21
    string cache_dir_;  ///< Caching directory
 
22
 
 
23
    /**
 
24
     * Returns <code>true</code> if the cache file exists and it is updated.
 
25
     * @param path_image_file Path of the image file.
 
26
     * @param path_cache_file Receives the path of the associated cache file.
 
27
     */
 
28
    bool ExistCacheImage(const string& path_image_file, string *path_cache_file);
 
29
 
 
30
    /**
 
31
     * Reads the header information. of a JP2/JPX box.
 
32
     * @param fim Image file.
 
33
     * @param type_box Receives the type of the box.
 
34
     * @param length_box Receives the length of the box.
 
35
     * @return <code>true</code> if successful.
 
36
     */
 
37
    bool ReadBoxHeader(const File &fim, uint32_t *type_box, uint64_t *length_box);
 
38
 
 
39
    /**
 
40
     * Reads the information of a codestream.
 
41
     * @param file Image file.
 
42
     * @param params Receives the coding parameters.
 
43
     * @param index Receives the indexing information.
 
44
     * @return <code>true</code> if successful.
 
45
     */
 
46
    bool ReadCodestream(const File& file, CodingParameters *params, CodestreamIndex *index);
 
47
 
 
48
    /**
 
49
     * Reads the information of a SIZ marker.
 
50
     * @param file Image file.
 
51
     * @param params Pointer to the coding parameters to update.
 
52
     * @return <code>true</code> if successful.
 
53
     */
 
54
    bool ReadSIZMarker(const File& file, CodingParameters *params);
 
55
 
 
56
    /**
 
57
     * Reads the information of a COD marker.
 
58
     * @param file Image file.
 
59
     * @param params Pointer to the coding parameters to update.
 
60
     * @return <code>true</code> if successful.
 
61
     */
 
62
    bool ReadCODMarker(const File& file, CodingParameters *params);
 
63
 
 
64
    /**
 
65
     * Reads the information of a SOT marker.
 
66
     * @param file Image file.
 
67
     * @param index Pointer to the indexing information to update.
 
68
     * @return <code>true</code> if successful.
 
69
     */
 
70
    bool ReadSOTMarker(const File& file, CodestreamIndex *index);
 
71
 
 
72
    /**
 
73
     * Reads the information of a PLT marker.
 
74
     * @param file Image file.
 
75
     * @param index Pointer to the indexing information to update.
 
76
     * @return <code>true</code> if successful.
 
77
     */
 
78
    bool ReadPLTMarker(const File& file, CodestreamIndex *index);
 
79
 
 
80
    /**
 
81
     * Reads the information of a SOD marker.
 
82
     * @param file Image file.
 
83
     * @param index Pointer to the indexing information to update.
 
84
     * @return <code>true</code> if successful.
 
85
     */
 
86
    bool ReadSODMarker(const File& file, CodestreamIndex *index);
 
87
 
 
88
    /**
 
89
     * Reads the information of a JP2 image file.
 
90
     * @param file Image file.
 
91
     * @param image_info Receives the image information.
 
92
     * @return <code>true</code> if successful.
 
93
     */
 
94
    bool ReadJP2(const File& file, ImageInfo *image_info);
 
95
 
 
96
    /**
 
97
     * Reads the information of a JPX image file.
 
98
     * @param file Image file.
 
99
     * @param image_info Receives the image information.
 
100
     * @return <code>true</code> if successful.
 
101
     */
 
102
    bool ReadJPX(const File& file, ImageInfo *image_info);
 
103
 
 
104
    /**
 
105
     * Reads the information of a NLST box.
 
106
     * @param file Image file.
 
107
     * @param num_codestream Receives the number of codestream read.
 
108
     * @param length_box Box length in bytes.
 
109
     * @return <code>true</code> if successful.
 
110
     */
 
111
    bool ReadNlstBox(const File& file, int *num_codestream, int length_box);
 
112
 
 
113
    /**
 
114
     * Reads the information of a FLST box.
 
115
     * @param file Image file.
 
116
     * @param length_box Box length in bytes.
 
117
     * @param data_reference Receives the data reference.
 
118
     * @return <code>true</code> if successful.
 
119
     */
 
120
    bool ReadFlstBox(const File& file, uint64_t length_box, uint16_t *data_reference);
 
121
 
 
122
    /**
 
123
     * Reads the information of a URL box.
 
124
     * @param file Image file.
 
125
     * @param length_box Box length in bytes.
 
126
     * @param path_file Receives the URL path read.
 
127
     * @return <code>true</code> if successful.
 
128
     */
 
129
    bool ReadUrlBox(const File& file, uint64_t length_box, string *path_file);
 
130
 
 
131
  public:
 
132
    /**
 
133
     * Returns the cache file name equivalent to the given
 
134
     * image file name.
 
135
     */
 
136
    string GetCacheFileName(const string& path_image_file);
 
137
 
 
138
    /**
 
139
     * Initializes the object.
 
140
     */
 
141
    FileManager()
 
142
    {
 
143
      root_dir_ = "./";
 
144
      cache_dir_ = "./";
 
145
    }
 
146
 
 
147
    /**
 
148
     * Initializes the object.
 
149
     * @param root_dir Root directory of the image repository.
 
150
     * @param cache_dir Directory for caching.
 
151
     */
 
152
    FileManager(string root_dir, string cache_dir)
 
153
    {
 
154
      assert(Init(root_dir, cache_dir));
 
155
    }
 
156
 
 
157
    /**
 
158
     * Initializes the object.
 
159
     * @param root_dir Root directory of the image repository.
 
160
     * @param cache_dir Directory for caching.
 
161
     * @return <code>true</code> if successful
 
162
     */
 
163
    bool Init(string root_dir = "./", string cache_dir = "./")
 
164
    {
 
165
      if((root_dir.size() <= 0) || (cache_dir.size() < 0)) return false;
 
166
      else {
 
167
        root_dir_ = root_dir;
 
168
        cache_dir_ = cache_dir;
 
169
 
 
170
        if(root_dir_.at(root_dir_.size() - 1) != '/')
 
171
          root_dir_ += '/';
 
172
 
 
173
        if(cache_dir_.at(cache_dir_.size() - 1) != '/')
 
174
          cache_dir_ += '/';
 
175
 
 
176
        return true;
 
177
      }
 
178
    }
 
179
 
 
180
    /**
 
181
     * Returns the root directory of the image repository.
 
182
     */
 
183
    string root_dir() const
 
184
    {
 
185
      return root_dir_;
 
186
    }
 
187
 
 
188
    /**
 
189
     * Returns the directory used for caching.
 
190
     */
 
191
    string cache_dir() const
 
192
    {
 
193
      return cache_dir_;
 
194
    }
 
195
 
 
196
    /**
 
197
     * Reads an image file and creates the associated cache file if
 
198
     * it does not exist yet.
 
199
     * @param name_image_file File name of the image.
 
200
     * @param image_info Receives the information of the image.
 
201
     * @return <code>true</code> if successful.
 
202
     */
 
203
    bool ReadImage(const string& name_image_file, ImageInfo *image_info);
 
204
 
 
205
 
 
206
    virtual ~FileManager()
 
207
    {
 
208
    }
 
209
 
 
210
 
 
211
  };
 
212
}
 
213
 
 
214
#endif /* _JPEG2000_FILE_MANAGER_H_ */
 
215