SCM Library
Spherical Cube Map rendering library
 All Classes Files Functions Variables Friends Pages
scm-file.hpp
Go to the documentation of this file.
1 // Copyright (C) 2011-2012 Robert Kooima
2 //
3 // LIBSCM is free software; you can redistribute it and/or modify it under the
4 // terms of the GNU General Public License as published by the Free Software
5 // Foundation; either version 2 of the License, or (at your option) any later
6 // version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITH-
9 // OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 
13 #ifndef SCM_FILE_HPP
14 #define SCM_FILE_HPP
15 
16 #include <string>
17 #include <vector>
18 
19 #include <tiffio.h>
20 #include <SDL.h>
21 #include <SDL_thread.h>
22 
23 #include "scm-queue.hpp"
24 #include "scm-guard.hpp"
25 #include "scm-task.hpp"
26 #include "scm-sample.hpp"
27 
28 //------------------------------------------------------------------------------
29 
30 typedef std::vector<SDL_Thread *> thread_v;
31 typedef std::vector<SDL_Thread *>::iterator thread_i;
32 
33 //------------------------------------------------------------------------------
34 
36 
37 class scm_file
38 {
39 public:
40 
41  scm_file(const std::string& name);
42 
43  virtual ~scm_file();
44 
45  void activate(scm_cache *);
46  void deactivate();
47  bool is_active() const;
48 
49  bool add_need(scm_task&);
50 
51  virtual bool get_page_status(uint64) const;
52  virtual uint64 get_page_offset(uint64) const;
53  virtual void get_page_bounds(uint64, float&, float&) const;
54  virtual float get_page_sample(const double *);
55 
56  virtual uint32 get_w() const { return w; }
57  virtual uint32 get_h() const { return h; }
58  virtual uint16 get_c() const { return c; }
59  virtual uint16 get_b() const { return b; }
60 
61  const char *get_path() const { return path.c_str(); }
62  const char *get_name() const { return name.c_str(); }
63 
64  uint64 find_page(long long, double&, double&) const;
65 
66 protected:
67 
68  std::string path;
69  std::string name;
70 
71 private:
72 
73  // IO handling and threading data
74 
75  scm_cache *cache;
76  scm_queue<scm_task> needs;
77  scm_guard<bool> active;
78  scm_sample *sampler;
79  thread_v threads;
80 
81  // Image parameters
82 
83  uint32 w;
84  uint32 h;
85  uint16 c;
86  uint16 b;
87 
88  uint64 *xv;
89  uint64 xc;
90 
91  uint64 *ov;
92  uint64 oc;
93 
94  void *av;
95  uint64 ac;
96 
97  void *zv;
98  uint64 zc;
99 
100  float tofloat(const void *, uint64) const;
101  void fromfloat(const void *, uint64, float) const;
102 
103  uint64 toindex(uint64) const;
104 
105  friend int loader(void *);
106 };
107 
108 //------------------------------------------------------------------------------
110 
111 bool scm_load_page(const char *, long long,
112  TIFF *, uint64, int, int, int, int, void *);
113 
114 //------------------------------------------------------------------------------
115 
116 #endif
void activate(scm_cache *)
Launch all loader threads for this file.
Definition: scm-file.cpp:130
An scm_task represents a page load task, as executed by a loader thread.
Definition: scm-task.hpp:34
An scm_file encapsulates an open SCM data file.
Definition: scm-file.hpp:37
bool is_active() const
Return true if loader threads are active on this file.
Definition: scm-file.cpp:163
uint64 find_page(long long, double &, double &) const
Seek the deepest page at this location (x, y) of root page a. Return the file offset of this page and...
Definition: scm-file.cpp:319
bool scm_load_page(const char *, long long, TIFF *, uint64, int, int, int, int, void *)
Load a page from a TIFF file.
Definition: scm-file.cpp:535
void deactivate()
Command all loader threads to exit.
Definition: scm-file.cpp:144
bool add_need(scm_task &)
Insert a new loader task into the needs queue.
Definition: scm-file.cpp:170
friend int loader(void *)
Service page load requests.
Definition: scm-file.cpp:573
An scm_sample samples an SCM TIFF file.
Definition: scm-sample.hpp:42
scm_file(const std::string &name)
Construct a file table entry.
Definition: scm-file.cpp:30
An scm_cache is a virtual texture, demand-paged with threaded data access, represented as a single la...
Definition: scm-cache.hpp:35