3 * \file GraphicsImageXPM.h
4 * Read the file COPYING
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS
11 * An instantiation of Image that makes use of libXPM to load and store
12 * the image in memory.
15 #ifndef GRAPHICSIMAGEXPM_H
16 #define GRAPHICSIMAGEXPM_H
18 #include "GraphicsImage.h"
19 #include XPM_H_LOCATION
21 #include <boost/shared_ptr.hpp>
29 class ImageXPM : public Image
32 /// Access to this class is through this static method.
33 static ImagePtr newImage();
35 /// Return the list of loadable formats.
36 static FormatList loadableFormats();
42 Image * clone() const;
45 Pixmap getPixmap() const;
47 /// Get the image width
48 unsigned int getWidth() const;
50 /// Get the image height
51 unsigned int getHeight() const;
53 bool isDrawable() const;
55 /** Load the image file into memory.
56 * In this case (ImageXPM), the process is blocking.
58 void load(string const & filename);
60 /** Generate the pixmap, based on the current state of the
61 * xpm_image_ (clipped, rotated, scaled etc).
62 * Uses the params to decide on color, grayscale etc.
63 * Returns true if the pixmap is created.
65 bool setPixmap(Params const & params);
67 /// Clip the image using params.
68 void clip(Params const & params);
70 /// Rotate the image using params.
71 void rotate(Params const & params);
73 /// Scale the image using params.
74 void scale(Params const & params);
77 /// Access to the class is through newImage() and clone.
80 ImageXPM(ImageXPM const &);
82 /** Contains the data read from file.
83 * This class is a wrapper for a XpmImage struct, but all views
84 * of a single file's data will share the same color table.
85 * This is done by ensuring that the color table contains a "none"
86 * c_color together with g_color and m_color entries for each c_color
87 * entry when it is first stored.
92 /// Default c-tor. Initialise everything to zero.
96 bool empty() const { return width_ == 0; }
98 /** Wrap an XpmImage in a nice, clean C++ interface.
99 * Empty the original XpmImage.
100 * Does some analysis of the color table to ensure that
101 * it is suitable for all future eventualities. (See above
104 void reset(XpmImage & image);
106 /// Reset the data struct with this data.
107 void resetData(int width, int height, unsigned int * data);
109 /** Returns a ptr to an initialised block of memory.
110 * the data is initialised to the color "none" entry.
112 unsigned int * initialisedData(int width, int height) const;
114 /** Construct an XpmImage from the stored contents.
115 * To pass to XpmCreatePixmapFromXpmImage.
116 * Efficient, because we only copy the ptrs to the structs.
118 XpmImage get() const;
120 unsigned int width() const { return width_; }
121 unsigned int height() const { return height_; }
122 unsigned int cpp() const { return cpp_; }
123 unsigned int ncolors() const { return ncolors_; }
124 unsigned int const * data() const
125 { return data_.get(); }
126 XpmColor const * colorTable() const
127 { return colorTable_.get(); }
131 unsigned int height_;
133 unsigned int ncolors_;
134 boost::shared_ptr<unsigned int> data_;
135 boost::shared_ptr<XpmColor> colorTable_;
137 unsigned int color_none_id() const;
142 /// The pixmap itself.
145 /// Is the pixmap initialized?
148 PIXMAP_UNINITIALISED,
155 PixmapStatus pixmap_status_;
160 #endif // GRAPHICSIMAGEXPM_H