3 * \file GraphicsImage.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 abstract base class for the images themselves.
13 * Allows the user to retrieve the pixmap, once loaded and to issue commands
16 * The boost::functions newImage and loadableFormats are connected to the
17 * appropriate derived classes elsewhere, allowing the graphics cache to
18 * access them without knowing anything about their instantiation.
20 * The loading process can be asynchronous, but cropping, rotating and
21 * scaling block execution.
24 #ifndef GRAPHICSIMAGE_H
25 #define GRAPHICSIMAGE_H
29 #include <boost/shared_ptr.hpp>
30 #include <boost/function/function0.hpp>
31 #include <boost/signals/signal1.hpp>
43 /** This is to be connected to a function that will return a new
44 * instance of a viable derived class.
46 typedef boost::shared_ptr<Image> ImagePtr;
48 static boost::function0<ImagePtr> newImage;
50 /// Return the list of loadable formats.
51 typedef std::vector<string> FormatList;
53 static boost::function0<FormatList> loadableFormats;
55 /// Must define default c-tor explicitly as we define a copy c-tor.
57 /// Don't copy the signal finishedLoading
58 Image(Image const &) {}
63 virtual Image * clone() const = 0;
65 /// Get the image width
66 virtual unsigned int getWidth() const = 0;
68 /// Get the image height
69 virtual unsigned int getHeight() const = 0;
71 /// is the image drawable ?
72 virtual bool isDrawable() const = 0;
74 /** At the end of the loading process inform the outside world
75 * by emitting a signal.
77 typedef boost::signal1<void, bool> SignalType;
79 SignalType finishedLoading;
81 /** Start loading the image file.
82 * The caller should expect this process to be asynchronous and
83 * so should connect to the "finished" signal above.
85 virtual void load(string const & filename) = 0;
87 /** Generate the pixmap.
88 * Uses the params to decide on color, grayscale etc.
89 * Returns true if the pixmap is created.
91 virtual bool setPixmap(Params const & params) = 0;
93 /// Clip the image using params.
94 virtual void clip(Params const & params) = 0;
96 /// Rotate the image using params.
97 virtual void rotate(Params const & params) = 0;
99 /// Scale the image using params.
100 virtual void scale(Params const & params) = 0;
103 /** Uses the params to ascertain the dimensions of the scaled image.
104 * Returned as make_pair(width, height).
105 * If something goes wrong, returns make_pair(getWidth(), getHeight())
107 std::pair<unsigned int, unsigned int>
108 getScaledDimensions(Params const & params) const;
111 } // namespace graphics
114 #endif // GRAPHICSIMAGE_H