2 /* This file is part of
3 * =================================================
5 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich.
7 * Copyright 1995-2001 The LyX Team.
9 * ================================================= */
19 #include "boost/utility.hpp"
24 /** ImageLoader is a base class for all image loaders. An ImageLoader instance is
25 * platform dependent, and knows how to load some image formats into a memory
26 * representation (LyXImage).
28 * It may do the image loading asynchronously.
30 * @Author Baruch Even, <baruch.even@writeme.com>
32 class ImageLoader : boost::noncopyable {
34 /// Errors that can be returned from this class.
37 ImageFormatUnknown, // This loader doesn't know how to load this file.
38 NoFile, // File doesn't exists.
39 ErrorWhileLoading // Unknown error when loading.
42 /// A list of supported formats.
43 typedef std::vector<string> FormatList;
48 virtual ~ImageLoader();
50 /// Start loading the image file.
51 ImageLoader::Result loadImage(string const & filename);
53 /** Get the last rendered pixmap. Returns 0 if no image is ready.
55 * It is a one time operation, that is, after you get the image
56 * you are completely responsible to destroy it and the ImageLoader
57 * will not know about the image.
59 * This way we avoid deleting the image if you still use it and the
60 * ImageLoader is destructed, and if you don't use it we get to
61 * destruct the image to avoid memory leaks.
63 LyXImage * getImage();
65 /// Return the list of loadable formats.
66 virtual FormatList const loadableFormats() const;
69 /// Verify that the file is one that we can handle.
70 virtual bool isImageFormatOK(string const & filename) const = 0;
72 /// Do the actual image loading.
73 virtual Result runImageLoader(string const & filename) = 0;
75 /// Set the image that was loaded.
76 void setImage(LyXImage * image);
79 /// Free the loaded image.
82 /// The loaded image. An auto_ptr would be great here, but it's not
83 /// available everywhere (gcc 2.95.2 doesnt have it).