]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsImageXPM.h
compile fix in XPM image loader; fix opaque handling; remove warnings; fix turkish...
[lyx.git] / src / graphics / GraphicsImageXPM.h
1 // -*- C++ -*-
2 /**
3  *  \file GraphicsImageXPM.h
4  *  Copyright 2002 the LyX Team
5  *  Read the file COPYING
6  *
7  *  \author Baruch Even <baruch.even@writeme.com>
8  *  \author Angus Leeming <leeming@lyx.org>
9  *
10  *  An instantiation of Image that makes use of libXPM to load and store
11  *  the image in memory.
12  */
13
14 #ifndef GRAPHICSIMAGEXPM_H
15 #define GRAPHICSIMAGEXPM_H
16
17 #include "GraphicsImage.h"
18 #include XPM_H_LOCATION
19 #include "support/smart_ptr.h"
20
21 #ifdef __GNUG__
22 #pragma interface
23 #endif
24
25 namespace grfx {
26
27 class ImageXPM : public Image
28 {
29 public:
30         /// Access to this class is through this static method.
31         static ImagePtr newImage();
32
33         /// Return the list of loadable formats.
34         static FormatList loadableFormats();
35
36         ///
37         ~ImageXPM();
38
39         /// Create a copy
40         Image * clone() const;
41
42         ///
43         Pixmap getPixmap() const;
44
45         /// Get the image width
46         unsigned int getWidth() const;
47
48         /// Get the image height
49         unsigned int getHeight() const;
50
51         bool isDrawable() const;
52
53         /** Load the image file into memory.
54          *  In this case (ImageXPM), the process is blocking.
55          */
56         void load(string const & filename);
57
58         /** Generate the pixmap, based on the current state of the
59          *  xpm_image_ (clipped, rotated, scaled etc).
60          *  Uses the params to decide on color, grayscale etc.
61          *  Returns true if the pixmap is created.
62          */
63         bool setPixmap(Params const & params);
64
65         /// Clip the image using params.
66         void clip(Params const & params);
67
68         /// Rotate the image using params.
69         void rotate(Params const & params);
70
71         /// Scale the image using params.
72         void scale(Params const & params);
73
74 private:
75         /// Access to the class is through newImage() and clone.
76         ImageXPM();
77         ///
78         ImageXPM(ImageXPM const &);
79
80         /** Contains the data read from file.
81          *  This class is a wrapper for a XpmImage struct, but all views
82          *  of a single file's data will share the same color table.
83          *  This is done by ensuring that the color table contains a "none"
84          *  c_color together with g_color and m_color entries for each c_color
85          *  entry when it is first stored.
86          */
87         class Data
88         {
89         public:
90                 /// Default c-tor. Initialise everything to zero.
91                 Data();
92                 ~Data();
93
94                 bool empty() const { return width_ == 0; }
95
96                 /** Wrap an XpmImage in a nice, clean C++ interface.
97                  *  Empty the original XpmImage.
98                  *  Does some analysis of the color table to ensure that
99                  *  it is suitable for all future eventualities. (See above
100                  *  description.)
101                  */
102                 void reset(XpmImage & image);
103
104                 /// Reset the data struct with this data.
105                 void resetData(int width, int height, unsigned int * data);
106
107                 /** Returns a ptr to an initialised block of memory.
108                  *  the data is initialised to the color "none" entry.
109                  */
110                 unsigned int * initialisedData(int width, int height) const;
111
112                 /** Construct an XpmImage from the stored contents.
113                  *  To pass to XpmCreatePixmapFromXpmImage.
114                  *  Efficient, because we only copy the ptrs to the structs.
115                  */
116                 XpmImage get() const;
117
118                 unsigned int width()   const { return width_; }
119                 unsigned int height()  const { return height_; }
120                 unsigned int cpp()     const { return cpp_; }
121                 unsigned int ncolors() const { return ncolors_; }
122                 unsigned int const * data() const
123                         { return data_.get(); }
124                 XpmColor const * colorTable() const
125                         { return colorTable_.get(); }
126
127         private:
128                 unsigned int width_;
129                 unsigned int height_;
130                 unsigned int cpp_;
131                 unsigned int ncolors_;
132                 lyx::shared_c_ptr<unsigned int> data_;
133                 lyx::shared_c_ptr<XpmColor> colorTable_;
134
135                 unsigned int color_none_id() const;
136         };
137
138         Data image_;
139
140         /// The pixmap itself.
141         Pixmap pixmap_;
142
143         /// Is the pixmap initialized?
144         enum PixmapStatus {
145                 ///
146                 PIXMAP_UNINITIALISED,
147                 ///
148                 PIXMAP_FAILED,
149                 ///
150                 PIXMAP_SUCCESS
151         };
152
153         PixmapStatus pixmap_status_;
154 };
155
156 } // namespace grfx
157
158 #endif // GRAPHICSIMAGEXPM_H