1 | // This may look like C code, but it is really -*- C++ -*-
|
---|
2 | // Classes utilitaires pour representation de pixels et couleurs RGB pour PI
|
---|
3 | // R. Ansari 09/2008
|
---|
4 | // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA
|
---|
5 |
|
---|
6 | #ifndef PIPIXUTILS_H_SEEN
|
---|
7 | #define PIPIXUTILS_H_SEEN
|
---|
8 |
|
---|
9 | // ======= Classes utilitaires pour PIPixmap / PIImage =====
|
---|
10 | //
|
---|
11 | // Definition d'un tableau pour gerer des index de couleurs en 8 bits / 16 bits
|
---|
12 | //
|
---|
13 | class PIPixColIdx
|
---|
14 | {
|
---|
15 | public:
|
---|
16 | PIPixColIdx();
|
---|
17 | ~PIPixColIdx();
|
---|
18 | inline int XSize() { return sx_; }
|
---|
19 | inline int YSize() { return sy_; }
|
---|
20 |
|
---|
21 | void AllocateByte(int sx, int sy);
|
---|
22 | void AllocateShort(int sx, int sy);
|
---|
23 | inline void DeAlloc() { AllocateByte(0,0); }
|
---|
24 |
|
---|
25 | inline unsigned char GetByte(int i, int j) const
|
---|
26 | { return pix8[j*sx_+i]; }
|
---|
27 | inline unsigned char & GetByte(int i, int j)
|
---|
28 | { return pix8[j*sx_+i]; }
|
---|
29 |
|
---|
30 | inline unsigned short GetShort(int i, int j) const
|
---|
31 | { return pix16[j*sx_+i]; }
|
---|
32 | inline unsigned short & GetShort(int i, int j)
|
---|
33 | { return pix16[j*sx_+i]; }
|
---|
34 |
|
---|
35 | inline unsigned char* BytePointer() { return pix8; }
|
---|
36 | inline unsigned short* ShortPointer() { return pix16; }
|
---|
37 |
|
---|
38 | protected:
|
---|
39 | unsigned char * pix8;
|
---|
40 | unsigned short * pix16;
|
---|
41 | int sx_, sy_;
|
---|
42 | };
|
---|
43 |
|
---|
44 |
|
---|
45 | //
|
---|
46 | // Definition de pixel et tableau de pixel RGB de 8 bits (byte)
|
---|
47 | //
|
---|
48 |
|
---|
49 | // Cette structure DOIT avoir la taille d'un entier de 4 bytes
|
---|
50 | struct PIPixRGB {
|
---|
51 | unsigned char red;
|
---|
52 | unsigned char green;
|
---|
53 | unsigned char blue;
|
---|
54 | unsigned char alpha; // non utilise pour le moment
|
---|
55 | };
|
---|
56 |
|
---|
57 | class PIPixRGBArray
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | PIPixRGBArray(int sx, int sy);
|
---|
61 | PIPixRGBArray(const char * filename);
|
---|
62 | ~PIPixRGBArray();
|
---|
63 |
|
---|
64 | inline int XSize() { return sx_; }
|
---|
65 | inline int YSize() { return sy_; }
|
---|
66 |
|
---|
67 | inline PIPixRGB operator()(int i, int j) const
|
---|
68 | { return rgbpix_[j*sx_+i]; }
|
---|
69 | inline PIPixRGB& operator()(int i, int j)
|
---|
70 | { return rgbpix_[j*sx_+i]; }
|
---|
71 |
|
---|
72 | void SaveToFile(const char * filename);
|
---|
73 |
|
---|
74 | protected:
|
---|
75 | PIPixRGB * rgbpix_;
|
---|
76 | int sx_, sy_;
|
---|
77 | };
|
---|
78 |
|
---|
79 |
|
---|
80 | #endif /* PIPIXUTILS_H_SEEN */
|
---|
81 |
|
---|
82 |
|
---|