3 * \file GraphicsImage.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 abstract base class for the images themselves.
11 * Allows the user to retrieve the pixmap, once loaded and to issue commands
14 * The signals newImage and loadableFormats are connected to the approriate
15 * derived classes elsewhere, allowing the graphics cache to access them
16 * without knowing anything about their instantiation.
18 * The loading process can be asynchronous, but cropping, rotating and
19 * scaling block execution.
22 #ifndef GRAPHICSIMAGE_H
23 #define GRAPHICSIMAGE_H
27 #include <boost/shared_ptr.hpp>
28 #include <boost/function/function0.hpp>
29 #include <boost/signals/signal1.hpp>
31 #include <X11/X.h> // for Pixmap :-(
46 /** This is to be connected to a function that will return a new
47 * instance of a viable derived class.
49 typedef boost::shared_ptr<Image> ImagePtr;
51 static boost::function0<ImagePtr> newImage;
53 /// Return the list of loadable formats.
54 typedef std::vector<string> FormatList;
56 static boost::function0<FormatList> loadableFormats;
58 /// Must define default c-tor explicitly as we define a copy c-tor.
60 /// Don't copy the signal finishedLoading
61 Image(Image const &) {}
66 virtual Image * clone() const = 0;
69 virtual Pixmap getPixmap() const = 0;
71 /// Get the image width
72 virtual unsigned int getWidth() const = 0;
74 /// Get the image height
75 virtual unsigned int getHeight() const = 0;
77 /** At the end of the loading process inform the outside world
78 * by emitting a signal.
80 typedef boost::signal1<void, bool> SignalType;
82 SignalType finishedLoading;
84 /** Start loading the image file.
85 * The caller should expect this process to be asynchronous and
86 * so should connect to the "finished" signal above.
88 virtual void load(string const & filename) = 0;
90 /** Generate the pixmap.
91 * Uses the params to decide on color, grayscale etc.
92 * Returns true if the pixmap is created.
94 virtual bool setPixmap(Params const & params) = 0;
96 /// Clip the image using params.
97 virtual void clip(Params const & params) = 0;
99 /// Rotate the image using params.
100 virtual void rotate(Params const & params) = 0;
102 /// Scale the image using params.
103 virtual void scale(Params const & params) = 0;
106 /** Uses the params to ascertain the dimensions of the scaled image.
107 * Returned as make_pair(width, height).
108 * If something goes wrong, returns make_pair(getWidth(), getHeight())
110 std::pair<unsigned int, unsigned int>
111 getScaledDimensions(Params const & params) const;
116 #endif // GRAPHICSIMAGE_H