Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image_library_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_SPRITER_IMAGE_LIBRARY_INTERFACE_H_
20 #define NET_INSTAWEB_SPRITER_IMAGE_LIBRARY_INTERFACE_H_
21 
22 #include "net/instaweb/spriter/public/image_spriter.pb.h"
25 
28 
29 namespace net_instaweb {
30 namespace spriter {
31 
40 
42  public:
46 
49  class Delegate {
50  public:
51  virtual void OnError(const GoogleString& error) const = 0;
52  virtual ~Delegate() {}
53  };
54 
56  class Image {
57  public:
59  virtual bool GetDimensions(int* out_width, int* out_height) const = 0;
60  virtual ~Image() {}
61  protected:
63  explicit Image(ImageLibraryInterface* lib) : lib_(lib) {}
65  private:
66 
67  };
68 
71  virtual Image* ReadFromFile(const FilePath& path) = 0;
72 
76  class Canvas {
77  public:
78  virtual bool DrawImage(const Image* image, int x, int y) = 0;
79  virtual bool WriteToFile(
80  const FilePath& write_path, ImageFormat format) = 0;
81  virtual ~Canvas() {}
82  protected:
83  explicit Canvas(ImageLibraryInterface* lib) : lib_(lib) {}
85  private:
86 
87  };
88 
89  virtual Canvas* CreateCanvas(int width, int height) = 0;
90 
93  explicit ImageLibraryInterface(Delegate* delegate) : delegate_(delegate) {}
94 
95  virtual ~ImageLibraryInterface() {}
96 
99  const GoogleString& library_name);
100 
101  protected:
104  const FilePath& base_output_path,
105  Delegate* delegate);
106 
108  const FilePath& base_input_path() { return base_input_path_; }
109  const FilePath& base_output_path() { return base_output_path_; }
110  const Delegate* delegate() { return delegate_; }
111 
112  private:
115  FilePath base_input_path_;
116 
119  FilePath base_output_path_;
120 
123  const Delegate* delegate_;
124 
125 
126 };
127 
128 }
129 }
130 
131 #endif
Definition: image_library_interface.h:41
static ImageLibraryInterface * ImageLibraryInterfaceFactory(const GoogleString &library_name)
Use this factory method to get a usable image library object.
Images are immutable rectangular regions of pixels.
Definition: image_library_interface.h:56
Image(ImageLibraryInterface *lib)
Only methods of ImageLibraryInterface may create images.
Definition: image_library_interface.h:63
virtual Image * ReadFromFile(const FilePath &path)=0
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: image_library_interface.h:76
const FilePath & base_input_path()
Used by subclasses:
Definition: image_library_interface.h:108
virtual bool GetDimensions(int *out_width, int *out_height) const =0
Get the width and height of an image.
GoogleString FilePath
Definition: image_library_interface.h:45
Definition: image.h:39
ImageLibraryInterface(Delegate *delegate)
Definition: image_library_interface.h:93
Definition: image_library_interface.h:49