LightWrap++
AC++wrapperfortheLightWave3DSDK
image.h
Go to the documentation of this file.
1 
7 #ifndef LWPP_IMAGE_H
8 #define LWPP_IMAGE_H
9 #include <lwpp/global.h>
10 #include <lwimage.h>
11 #include <lwpp/wrapper.h>
12 #include <lwpp/storeable.h>
13 
14 #ifdef _DEBUG
15 #include <lwpp/debug.h>
16 #endif
17 
18 namespace lwpp
19 {
22  class ImageUtil : public PopUpCallback, protected GlobalBase<LWImageUtil>, public Storeable
23  {
24  private:
25  LWPixmapID pixmap;
26  bool doDestroy;
27  public:
28  ImageUtil(LWPixmapID _pixmap = 0)
29  : pixmap(_pixmap), doDestroy(false)
30  {;}
32 
37  ImageUtil(int w, int h, LWImageType type)
38  : pixmap(0), doDestroy(true)
39  {
40  create(w, h, type);
41  }
44  {
45  if ((pixmap != 0) && doDestroy) globPtr->destroy(pixmap);
46  }
47 
48  ImageUtil(const ImageUtil &iu)
49  {
50  pixmap = iu.pixmap;
51  doDestroy = iu.doDestroy;
52  }
53 
55  {
56  if (&iu != this)
57  {
58  if ((pixmap != 0) && doDestroy) globPtr->destroy(pixmap);
59  pixmap = iu.pixmap;
60  }
61  return *this;
62  }
63 
65  static size_t GetStride(int type);
67  size_t GetStride()
68  {
69  int w,h,type;
70  getInfo(&w,&h,&type);
71  return GetStride(type);
72  }
73  void setDestroy(bool destroy = true)
74  {
75  doDestroy = destroy;
76  }
78  bool isValid()
79  {
80  return pixmap != 0;
81  }
82  void create(int w, int h, LWImageType type)
83  {
84  pixmap = globPtr->create(w, h, type);
85  }
87 
92  void setPixel(int x, int y, void *pix)
93  {
94  globPtr->setPixel(pixmap, x, y, pix);
95  }
97 
102  void getPixel(int x, int y, void *pix)
103  {
104  globPtr->getPixel(pixmap, x, y, pix);
105  }
107 
112  void getInfo(int *w, int *h, int *type)
113  {
114  globPtr->getInfo(pixmap, w, h, type);
115  }
116  static void getInfo(LWPixmapID id, int *w, int *h, int *type)
117  {
118  globPtr->getInfo(id, w, h, type);
119  }
120 
121  LWPixmapID resample(int w, int h, int mode )
122  {
123  return globPtr->resample(pixmap, w, h, mode);
124  }
125 
126  void setPixelTyped(int x, int y, int type, void *pix )
127  {
128  globPtr->setPixelTyped(pixmap, x, y, type, pix);
129  }
130  void getPixelTyped ( int x, int y, int type, void *pix )
131  {
132  globPtr->getPixelTyped(pixmap, x, y, type, pix);
133  }
134  int getIndex8Map( LWPixelRGB24 *map )
135  {
136  return globPtr->getIndex8Map(pixmap, map);
137  }
138  int getAttr ( LWImageParam tag, void* data )
139  {
140  return globPtr->getAttr(pixmap, tag, data);
141  }
142  int getMakerNote ( LWMakerNote tag, void* data )
143  {
144  return globPtr->getMakerNote(pixmap, tag, data);
145  }
146 
148  void save(int saver, const std::string name)
149  {
150  globPtr->save(pixmap, saver, name.c_str());
151  }
152 
154 
157  static int saverCount(void)
158  {
159  return globPtr->saverCount();
160  }
161 
163 
167  static const char *saverName(int n)
168  {
169  return globPtr->saverName(n);
170  }
171 
172  std::string getSaverExtension(int n);
173 
174  int findSaver(std::string name);
175 
176 
177  protected:
178  virtual const char *popName(int n)
179  {
180  return saverName(n);
181  }
182 
183  virtual size_t popCount(void)
184  {
185  return saverCount();
186  }
187  };
188 
191  class Image : public PopUpCallback, public Storeable, protected GlobalBase<LWImageList>
192  {
193  private:
194  LWImageID id;
195  public:
196  virtual const char *popName(int n);
197 
198  virtual size_t popCount(void);
199 
200  Image(LWImageID _id = 0) : id(_id) {;}
201 
202  Image &operator= (const Image &from)
203  {
204  if (this != &from)
205  {
206  id = from.id;
207  }
208  return *this;
209  }
210 
211  void SetID(LWImageID _id) {id = _id;}
212  LWImageID getID() const {return id;}
214  void GetPopUp(int i);
216  int SetPopUp();
217 
218  bool isValid() {return id != 0;}
219  void first(void) {id = globPtr->first();}
220  void next(void) {id = globPtr->next(id);}
221  void clear(void) {globPtr->clear(id);}
222  void load(const char *filename) {id = globPtr->load(filename);}
223  const char *name() const {return globPtr->name(id);}
224  const char *filename(LWFrame frame = 0) const {return globPtr->filename(id, frame);}
225  bool replace (const std::string &newFile)
226  {
227  return globPtr->replace(id, newFile.c_str()) != 0;
228  }
229 
230  LWImageID getNumImage(int n);
231 
232  int getImageNum(LWImageID i);
233 
234  bool isColor (void) const
235  {
236  return (globPtr->isColor(id) != 0);
237  }
238  bool hasAlpha (void) const
239  {
240  return (globPtr->hasAlpha(id) != 0);
241  }
242 
243  void size (int &w, int &h) const
244  {
245  globPtr->size(id, &w, &h);
246  }
247  int getWidth (void) const
248  {
249  int w, h;
250  globPtr->size(id, &w, &h);
251  return w;
252  }
253  int getHeight (void) const
254  {
255  int w, h;
256  globPtr->size(id, &w, &h);
257  return h;
258  }
259 
260 #ifdef WIN32
261 #ifdef RGB
262 #undef RGB
263 #endif
264 #endif
265 
266  void RGB (int x, int y, LWBufferValue val[3]) const
267  {
268  globPtr->RGB(id, x, y, val);
269  }
270  void needAA ()
271  {
272  if (id) globPtr->needAA(id);
273  }
274 
275  void GetRGBSpot (double x, double y, double spotSize, bool blend, double rgb[3])
276  {
277  if (id) globPtr->RGBSpot(id, x, y, spotSize, blend ? 1 : 0, rgb);
278  }
279 
280  double GetAlphaSpot (double x, double y, double spotSize, bool blend)
281  {
282  if (id) return globPtr->alphaSpot(id, x, y, spotSize, blend ? 1 : 0);
283  return 0.0;
284  }
285 
286  double GetLumaSpot (double x, double y, double spotSize, bool blend)
287  {
288  if (id) return globPtr->lumaSpot(id, x, y, spotSize, blend ? 1 : 0);
289  return 0.0;
290  }
291 
292  LWBufferValue alpha (int x, int y) const
293  {
294  return globPtr->alpha(id, x, y);
295  }
296 
297  LWBufferValue luma (int x, int y) const
298  {
299  return globPtr->luma(id, x, y);
300  }
301 
302  LWPixmapID evaluate (LWTime t)
303  {
304  return globPtr->evaluate(id, t);
305  }
306 
307  virtual LWError Load(const LoadState &ls )
308  {
309  LWError err = 0;
310  id = globPtr->sceneLoad(ls.getState());
311  if (id == 0) err = "Could not load image";
312  return err;
313  }
314  virtual LWError Save(const SaveState &ss )
315  {
316  LWError err = 0;
317  globPtr->sceneSave(ss.getState(), id);
318  return err;
319  }
320  };
321 
322  #define IMAGECHANGE_COMRING "lwppImageChange"
323 
324  // register a comRing for image changes
325  /*
326  * The Comring is called "lwppImageChange".
327  * The eventCode is an image change eventCode.
328  * The data payload is the imageID.
329  */
331  // unregister the Comring
333 }
334 #endif // LWPP_IMAGE_H