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