More logging tweaks; missing noncopyable.
[dcpomatic.git] / src / lib / image_proxy.h
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/lib/image_proxy.h
21  *  @brief ImageProxy and subclasses.
22  */
23
24 #include <boost/shared_ptr.hpp>
25 #include <boost/filesystem.hpp>
26 #include <Magick++.h>
27 #include <libxml++/libxml++.h>
28
29 class Image;
30 class Socket;
31 class Log;
32
33 namespace cxml {
34         class Node;
35 }
36
37 /** @class ImageProxy
38  *  @brief A class which holds an Image, and can produce it on request.
39  *
40  *  This is so that decoding of source images can be postponed until
41  *  the encoder thread, where multi-threading is happening, instead
42  *  of happening in a single-threaded decoder.
43  *
44  *  For example, large TIFFs are slow to decode, so this class will keep
45  *  the TIFF data TIFF until such a time that the actual image is needed.
46  *  At this point, the class decodes the TIFF to an Image.
47  */
48 class ImageProxy : public boost::noncopyable
49 {
50 public:
51         ImageProxy (boost::shared_ptr<Log> log);
52         
53         virtual boost::shared_ptr<Image> image () const = 0;
54         virtual void add_metadata (xmlpp::Node *) const = 0;
55         virtual void send_binary (boost::shared_ptr<Socket>) const = 0;
56
57 protected:
58         boost::shared_ptr<Log> _log;
59 };
60
61 class RawImageProxy : public ImageProxy
62 {
63 public:
64         RawImageProxy (boost::shared_ptr<Image>, boost::shared_ptr<Log> log);
65         RawImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket, boost::shared_ptr<Log> log);
66
67         boost::shared_ptr<Image> image () const;
68         void add_metadata (xmlpp::Node *) const;
69         void send_binary (boost::shared_ptr<Socket>) const;
70         
71 private:
72         boost::shared_ptr<Image> _image;
73 };
74
75 class MagickImageProxy : public ImageProxy
76 {
77 public:
78         MagickImageProxy (boost::filesystem::path, boost::shared_ptr<Log> log);
79         MagickImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket, boost::shared_ptr<Log> log);
80
81         boost::shared_ptr<Image> image () const;
82         void add_metadata (xmlpp::Node *) const;
83         void send_binary (boost::shared_ptr<Socket>) const;
84
85 private:        
86         Magick::Blob _blob;
87         mutable boost::shared_ptr<Image> _image;
88 };
89
90 boost::shared_ptr<ImageProxy> image_proxy_factory (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket, boost::shared_ptr<Log> log);