add demux handling (for decoder and record)
[enigma2.git] / lib / gdi / region.h
1 #ifndef __lib_gdi_region_h
2 #define __lib_gdi_region_h
3
4 #include <lib/base/object.h>
5 #include <lib/gdi/erect.h>
6 #include <vector>
7
8 class gRegion
9 {
10 private:
11         inline void FindBand(
12                         std::vector<eRect>::const_iterator r,
13                         std::vector<eRect>::const_iterator &rBandEnd,
14                         std::vector<eRect>::const_iterator rEnd,
15                         int &ry1)
16         {
17                 ry1 = r->y1;
18                 rBandEnd = r+1;
19                 while ((rBandEnd != rEnd) && (rBandEnd->y1 == ry1))
20                         rBandEnd++;
21         }
22         
23         inline void AppendRegions(
24                 std::vector<eRect>::const_iterator r,
25                 std::vector<eRect>::const_iterator rEnd)
26         {
27                 rects.insert(rects.end(), r, rEnd);
28         }
29
30         int do_coalesce(int prevStart, unsigned int curStart);
31         inline void coalesce(int &prevBand, unsigned int curBand)
32         {
33                 if (curBand - prevBand == rects.size() - curBand) {
34                         prevBand = do_coalesce(prevBand, curBand);
35                 } else {
36                         prevBand = curBand;
37                 }
38         };
39         void appendNonO(std::vector<eRect>::const_iterator r, 
40                         std::vector<eRect>::const_iterator rEnd, int y1, int y2);
41
42         void intersectO(
43                         std::vector<eRect>::const_iterator r1,
44                         std::vector<eRect>::const_iterator r1End,
45                         std::vector<eRect>::const_iterator r2,
46                         std::vector<eRect>::const_iterator r2End,
47                         int y1, int y2,
48                         int &overlap);
49         void subtractO(
50                         std::vector<eRect>::const_iterator r1,
51                         std::vector<eRect>::const_iterator r1End,
52                         std::vector<eRect>::const_iterator r2,
53                         std::vector<eRect>::const_iterator r2End,
54                         int y1, int y2,
55                         int &overlap);
56         void mergeO(
57                         std::vector<eRect>::const_iterator r1,
58                         std::vector<eRect>::const_iterator r1End,
59                         std::vector<eRect>::const_iterator r2,
60                         std::vector<eRect>::const_iterator r2End,
61                         int y1, int y2,
62                         int &overlap);
63         void regionOp(const gRegion &reg1, const gRegion &reg2, int opcode, int &overlap);
64 public:
65         std::vector<eRect> rects;
66         eRect extends;
67         
68         enum
69         {
70                         // note: bit 0 and bit 1 have special meanings
71                 OP_INTERSECT = 0,
72                 OP_SUBTRACT  = 1,
73                 OP_UNION     = 3
74         };
75         
76         gRegion(const eRect &rect);
77         gRegion();
78         virtual ~gRegion();
79
80         gRegion operator&(const gRegion &r2) const;
81         gRegion operator-(const gRegion &r2) const;
82         gRegion operator|(const gRegion &r2) const;
83         gRegion &operator&=(const gRegion &r2);
84         gRegion &operator-=(const gRegion &r2);
85         gRegion &operator|=(const gRegion &r2);
86         
87         void intersect(const gRegion &r1, const gRegion &r2);
88         void subtract(const gRegion &r1, const gRegion &r2);
89         void merge(const gRegion &r1, const gRegion &r2);
90         
91         void moveBy(ePoint offset);
92         
93         bool empty() const { return extends.empty(); }
94         bool valid() const { return extends.valid(); }
95         
96         static gRegion invalidRegion() { return gRegion(eRect::invalidRect()); }
97 };
98
99 #endif