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 <a.leeming@ic.ac.uk>
10 * An instantiation of GImage 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 GImageXPM : public GImage
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 GImage * 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 /** Load the image file into memory.
52 * In this case (GImageXPM), the process is blocking.
54 void load(string const & filename, SignalTypePtr);
56 /** Generate the pixmap, based on the current state of the
57 * xpm_image_ (clipped, rotated, scaled etc).
58 * Uses the params to decide on color, grayscale etc.
59 * Returns true if the pixmap is created.
61 bool setPixmap(GParams const & params);
63 /// Clip the image using params.
64 void clip(GParams const & params);
66 /// Rotate the image using params.
67 void rotate(GParams const & params);
69 /// Scale the image using params.
70 void scale(GParams const & params);
73 /// Access to the class is through newImage() and clone.
76 GImageXPM(GImageXPM const &);
78 /** Contains the data read from file.
79 * This class is a wrapper for a XpmImage struct, but all views
80 * of a single file's data will share the same color table.
81 * This is done by ensuring that the color table contains a "none"
82 * c_color together with g_color and m_color entries for each c_color
83 * entry when it is first stored.
88 /// Default c-tor. Initialise everything to zero.
92 bool empty() const { return width_ == 0; }
94 /** Wrap an XpmImage in a nice, clean C++ interface.
95 * Empty the original XpmImage.
96 * Does some analysis of the color table to ensure that
97 * it is suitable for all future eventualities. (See above
100 void reset(XpmImage & image);
102 /// Reset the data struct with this data.
103 void resetData(int width, int height, unsigned int * data);
105 /** Returns a ptr to an initialised block of memory.
106 * the data is initialised to the color "none" entry.
108 unsigned int * initialisedData(int width, int height) const;
110 /** Construct an XpmImage from the stored contents.
111 * To pass to XpmCreatePixmapFromXpmImage.
112 * Efficient, because we only copy the ptrs to the structs.
114 XpmImage get() const;
116 unsigned int width() const { return width_; }
117 unsigned int height() const { return height_; }
118 unsigned int cpp() const { return cpp_; }
119 unsigned int ncolors() const { return ncolors_; }
120 unsigned int const * data() const
121 { return data_.get(); }
122 XpmColor const * colorTable() const
123 { return colorTable_.get(); }
127 unsigned int height_;
129 unsigned int ncolors_;
130 lyx::shared_c_ptr<unsigned int> data_;
131 lyx::shared_c_ptr<XpmColor> colorTable_;
133 unsigned int color_none_id() const;
138 /// The pixmap itself.
141 /// Is the pixmap initialized?
144 PIXMAP_UNINITIALISED,
151 PixmapStatus pixmap_status_;
156 #endif // GRAPHICSIMAGEXPM_H