3 * \file GraphicsImageXPM.h
4 * Copyright 2002 the LyX Team
5 * Read the file COPYING
7 * \author Baruch Even <baruch.even@writeme.com>
8 * \author Angus Leeming <leeming@lyx.org>
10 * An instantiation of Image that makes use of libXPM to load and store
11 * the image in memory.
14 #ifndef GRAPHICSIMAGEXPM_H
15 #define GRAPHICSIMAGEXPM_H
17 #include "GraphicsImage.h"
18 #include XPM_H_LOCATION
19 #include "support/smart_ptr.h"
27 class ImageXPM : public Image
30 /// Access to this class is through this static method.
31 static ImagePtr newImage();
33 /// Return the list of loadable formats.
34 static FormatList loadableFormats();
40 Image * clone() const;
43 Pixmap getPixmap() const;
45 /// Get the image width
46 unsigned int getWidth() const;
48 /// Get the image height
49 unsigned int getHeight() const;
51 bool isDrawable() const;
53 /** Load the image file into memory.
54 * In this case (ImageXPM), the process is blocking.
56 void load(string const & filename);
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.
63 bool setPixmap(Params const & params);
65 /// Clip the image using params.
66 void clip(Params const & params);
68 /// Rotate the image using params.
69 void rotate(Params const & params);
71 /// Scale the image using params.
72 void scale(Params const & params);
75 /// Access to the class is through newImage() and clone.
78 ImageXPM(ImageXPM const &);
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.
90 /// Default c-tor. Initialise everything to zero.
94 bool empty() const { return width_ == 0; }
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
102 void reset(XpmImage & image);
104 /// Reset the data struct with this data.
105 void resetData(int width, int height, unsigned int * data);
107 /** Returns a ptr to an initialised block of memory.
108 * the data is initialised to the color "none" entry.
110 unsigned int * initialisedData(int width, int height) const;
112 /** Construct an XpmImage from the stored contents.
113 * To pass to XpmCreatePixmapFromXpmImage.
114 * Efficient, because we only copy the ptrs to the structs.
116 XpmImage get() const;
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(); }
129 unsigned int height_;
131 unsigned int ncolors_;
132 lyx::shared_c_ptr<unsigned int> data_;
133 lyx::shared_c_ptr<XpmColor> colorTable_;
135 unsigned int color_none_id() const;
140 /// The pixmap itself.
143 /// Is the pixmap initialized?
146 PIXMAP_UNINITIALISED,
153 PixmapStatus pixmap_status_;
158 #endif // GRAPHICSIMAGEXPM_H