[3519] | 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();
|
---|
[3549] | 18 | inline int XSize() const { return sx_; }
|
---|
| 19 | inline int YSize() const { return sy_; }
|
---|
[3519] | 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 |
|
---|
[3549] | 64 | void SetSize(int sx, int sy);
|
---|
[3519] | 65 |
|
---|
[3549] | 66 | inline int XSize() const { return sx_; }
|
---|
| 67 | inline int YSize() const { return sy_; }
|
---|
| 68 |
|
---|
[3519] | 69 | inline PIPixRGB operator()(int i, int j) const
|
---|
| 70 | { return rgbpix_[j*sx_+i]; }
|
---|
| 71 | inline PIPixRGB& operator()(int i, int j)
|
---|
| 72 | { return rgbpix_[j*sx_+i]; }
|
---|
| 73 |
|
---|
[3549] | 74 | int SaveToFile(const char * filename) const ;
|
---|
[3545] | 75 | int ReadFrFile(const char * filename);
|
---|
[3519] | 76 |
|
---|
| 77 | protected:
|
---|
| 78 | PIPixRGB * rgbpix_;
|
---|
| 79 | int sx_, sy_;
|
---|
| 80 | };
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | #endif /* PIPIXUTILS_H_SEEN */
|
---|
| 84 |
|
---|
| 85 |
|
---|