3 * \file GraphicsImageXPM.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS
12 * An instantiation of Image that makes use of libXPM to load and store
13 * the image in memory.
16 #ifndef GRAPHICSIMAGEXPM_H
17 #define GRAPHICSIMAGEXPM_H
19 #include "GraphicsImage.h"
20 #include XPM_H_LOCATION
22 #include <boost/shared_ptr.hpp>
30 class ImageXPM : public Image
33 /// Access to this class is through this static method.
34 static ImagePtr newImage();
36 /// Return the list of loadable formats.
37 static FormatList loadableFormats();
43 Image * clone() const;
46 Pixmap getPixmap() const;
48 /// Get the image width
49 unsigned int getWidth() const;
51 /// Get the image height
52 unsigned int getHeight() const;
54 bool isDrawable() const;
56 /** Load the image file into memory.
57 * In this case (ImageXPM), the process is blocking.
59 void load(string const & filename);
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.
66 bool setPixmap(Params const & params);
68 /// Clip the image using params.
69 void clip(Params const & params);
71 /// Rotate the image using params.
72 void rotate(Params const & params);
74 /// Scale the image using params.
75 void scale(Params const & params);
78 /// Access to the class is through newImage() and clone.
81 ImageXPM(ImageXPM const &);
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.
93 /// Default c-tor. Initialise everything to zero.
97 bool empty() const { return width_ == 0; }
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
105 void reset(XpmImage & image);
107 /// Reset the data struct with this data.
108 void resetData(int width, int height, unsigned int * data);
110 /** Returns a ptr to an initialised block of memory.
111 * the data is initialised to the color "none" entry.
113 unsigned int * initialisedData(int width, int height) const;
115 /** Construct an XpmImage from the stored contents.
116 * To pass to XpmCreatePixmapFromXpmImage.
117 * Efficient, because we only copy the ptrs to the structs.
119 XpmImage get() const;
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(); }
132 unsigned int height_;
134 unsigned int ncolors_;
135 boost::shared_ptr<unsigned int> data_;
136 boost::shared_ptr<XpmColor> colorTable_;
138 unsigned int color_none_id() const;
143 /// The pixmap itself.
146 /// Is the pixmap initialized?
149 PIXMAP_UNINITIALISED,
156 PixmapStatus pixmap_status_;
161 #endif // GRAPHICSIMAGEXPM_H