Page Speed Optimization Libraries
1.3.25.1
|
00001 /* 00002 * Copyright 2011 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_SPRITER_IMAGE_LIBRARY_INTERFACE_H_ 00020 #define NET_INSTAWEB_SPRITER_IMAGE_LIBRARY_INTERFACE_H_ 00021 00022 #include "net/instaweb/util/public/basictypes.h" 00023 #include "net/instaweb/util/public/string.h" 00024 #include "net/instaweb/spriter/public/image_spriter.pb.h" 00025 00028 00029 namespace net_instaweb { 00030 namespace spriter { 00031 00040 00041 class ImageLibraryInterface { 00042 public: 00045 typedef GoogleString FilePath; 00046 00049 class Delegate { 00050 public: 00051 virtual void OnError(const GoogleString& error) const = 0; 00052 virtual ~Delegate() {} 00053 }; 00054 00056 class Image { 00057 public: 00059 virtual bool GetDimensions(int* out_width, int* out_height) const = 0; 00060 virtual ~Image() {} 00061 protected: 00063 explicit Image(ImageLibraryInterface* lib) : lib_(lib) {} 00064 ImageLibraryInterface* lib_; 00065 private: 00066 DISALLOW_COPY_AND_ASSIGN(Image); 00067 }; 00068 00071 virtual Image* ReadFromFile(const FilePath& path) = 0; 00072 00076 class Canvas { 00077 public: 00078 virtual bool DrawImage(const Image* image, int x, int y) = 0; 00079 virtual bool WriteToFile( 00080 const FilePath& write_path, ImageFormat format) = 0; 00081 virtual ~Canvas() {} 00082 protected: 00083 explicit Canvas(ImageLibraryInterface* lib) : lib_(lib) {} 00084 ImageLibraryInterface* lib_; 00085 private: 00086 DISALLOW_COPY_AND_ASSIGN(Canvas); 00087 }; 00088 00089 virtual Canvas* CreateCanvas(int width, int height) = 0; 00090 00093 ImageLibraryInterface(Delegate* delegate) 00094 : delegate_(delegate) { 00095 } 00096 00097 virtual ~ImageLibraryInterface() {} 00098 00100 static ImageLibraryInterface* ImageLibraryInterfaceFactory( 00101 const GoogleString& library_name); 00102 00103 protected: 00105 ImageLibraryInterface(const FilePath& base_input_path, 00106 const FilePath& base_output_path, 00107 Delegate* delegate); 00108 00110 const FilePath& base_input_path() { return base_input_path_; } 00111 const FilePath& base_output_path() { return base_output_path_; } 00112 const Delegate* delegate() { return delegate_; } 00113 00114 private: 00117 FilePath base_input_path_; 00118 00121 FilePath base_output_path_; 00122 00125 const Delegate* delegate_; 00126 00127 DISALLOW_COPY_AND_ASSIGN(ImageLibraryInterface); 00128 }; 00129 00130 } 00131 } 00132 00133 #endif ///< NET_INSTAWEB_SPRITER_IMAGE_LIBRARY_INTERFACE_H_