source: Sophya/trunk/SophyaPI/PI/pipixutils.h@ 3549

Last change on this file since 3549 was 3549, checked in by ansari, 17 years ago

Petite amelioration classe PIPixRGBArray, et ajout methode PIWdg::ExportToRGB(PIPixRGBArray & rgba) avec implementation X11 - Reza 13/12/2008

  • Property svn:executable set to *
File size: 2.1 KB
Line 
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//
13class PIPixColIdx
14{
15public:
16 PIPixColIdx();
17 ~PIPixColIdx();
18 inline int XSize() const { return sx_; }
19 inline int YSize() const { 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
38protected:
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
50struct PIPixRGB {
51 unsigned char red;
52 unsigned char green;
53 unsigned char blue;
54 unsigned char alpha; // non utilise pour le moment
55};
56
57class PIPixRGBArray
58{
59public:
60 PIPixRGBArray(int sx, int sy);
61 PIPixRGBArray(const char * filename);
62 ~PIPixRGBArray();
63
64 void SetSize(int sx, int sy);
65
66 inline int XSize() const { return sx_; }
67 inline int YSize() const { return sy_; }
68
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
74 int SaveToFile(const char * filename) const ;
75 int ReadFrFile(const char * filename);
76
77protected:
78 PIPixRGB * rgbpix_;
79 int sx_, sy_;
80};
81
82
83#endif /* PIPIXUTILS_H_SEEN */
84
85
Note: See TracBrowser for help on using the repository browser.