Page Speed Optimization Libraries  1.9.32.2
 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"
23 #include "pagespeed/kernel/base/basictypes.h"
24 #include "pagespeed/kernel/base/string.h"
25 
28 
29 namespace net_instaweb {
30 namespace spriter {
31 
40 
42  public:
45  typedef GoogleString FilePath;
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  DISALLOW_COPY_AND_ASSIGN(Image);
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  DISALLOW_COPY_AND_ASSIGN(Canvas);
87  };
88 
89  virtual Canvas* CreateCanvas(int width, int height) = 0;
90 
94  : delegate_(delegate) {
95  }
96 
97  virtual ~ImageLibraryInterface() {}
98 
101  const GoogleString& library_name);
102 
103  protected:
106  const FilePath& base_output_path,
107  Delegate* delegate);
108 
110  const FilePath& base_input_path() { return base_input_path_; }
111  const FilePath& base_output_path() { return base_output_path_; }
112  const Delegate* delegate() { return delegate_; }
113 
114  private:
117  FilePath base_input_path_;
118 
121  FilePath base_output_path_;
122 
125  const Delegate* delegate_;
126 
127  DISALLOW_COPY_AND_ASSIGN(ImageLibraryInterface);
128 };
129 
130 }
131 }
132 
133 #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
Definition: image_library_interface.h:76
const FilePath & base_input_path()
Used by subclasses:
Definition: image_library_interface.h:110
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:38
ImageLibraryInterface(Delegate *delegate)
Definition: image_library_interface.h:93
Definition: image_library_interface.h:49