summaryrefslogtreecommitdiff
path: root/Build/source/utils/asymptote/drawimage.h
blob: 1f2c28175a05eea6da1f9bf614c5bc84398d31d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*****
 * drawimage.h
 * John Bowman
 *
 * Stores a image that has been added to a picture.
 *****/

#ifndef DRAWIMAGE_H
#define DRAWIMAGE_H

#include "drawelement.h"
#include "array.h"

namespace camp {

enum imagetype {PALETTE, NOPALETTE, RAW};
  
class drawImage : public drawElement {
  vm::array image,palette;
  unsigned char *raw; // For internal use; not buffered, may be overwritten.
  size_t width,height;
  transform t;
  bool antialias;
  imagetype type;
public:
  drawImage(const vm::array& image, const vm::array& palette,
            const transform& t, bool antialias, imagetype type=PALETTE)
    : image(image), palette(palette), t(t), antialias(antialias), type(type) {}
  
  drawImage(const vm::array& image, const transform& t, bool antialias)
    : image(image), t(t), antialias(antialias), type(NOPALETTE) {}
  drawImage(unsigned char *raw, size_t width, size_t height, const transform& t,
            bool antialias)
    : raw(raw), width(width), height(height), t(t), antialias(antialias),
      type(RAW) {}
  
  virtual ~drawImage() {}

  void bounds(bbox& b, iopipestream&, boxvector&, bboxlist&) {
    b += t*pair(0,0);
    b += t*pair(1,1);
  }

  bool draw(psfile *out) {
    out->gsave();
    out->concat(t);
    switch(type) {
      case PALETTE:
        out->image(image,palette,antialias);
        break;
      case NOPALETTE:
        out->image(image,antialias);
        break;
      case RAW:
        out->rawimage(raw,width,height,antialias);
        break;
    }
    
    out->grestore();
    
    return true;
  }

  bool svg() {return true;}
  bool svgpng() {return true;}

  drawElement *transformed(const transform& T) {
    return new drawImage(image,palette,T*t,antialias,type);
  }
};

}

#endif