Page Speed Optimization Libraries
1.6.29.3
|
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 */ 00017 00018 #ifndef NET_INSTAWEB_SPRITER_LIBPNG_IMAGE_LIBRARY_H_ 00019 #define NET_INSTAWEB_SPRITER_LIBPNG_IMAGE_LIBRARY_H_ 00020 00025 00026 extern "C" { 00027 #ifdef USE_SYSTEM_LIBPNG 00028 #include "png.h" 00029 #else 00030 #include "third_party/libpng/png.h" 00031 #endif 00032 } 00033 00034 #include "net/instaweb/spriter/image_library_interface.h" 00035 #include "net/instaweb/util/public/string.h" 00036 00037 namespace net_instaweb { 00038 namespace spriter { 00039 00046 class LibpngImageLibrary : public ImageLibraryInterface { 00047 public: 00048 LibpngImageLibrary(const FilePath& base_input_path, 00049 const FilePath& base_output_path, 00050 Delegate* delegate); 00051 virtual ~LibpngImageLibrary() {} 00052 00053 protected: 00055 class Image : public ImageLibraryInterface::Image { 00056 public: 00058 Image(ImageLibraryInterface* lib, 00059 png_structp png_struct, png_infop png_info, png_bytep* rows); 00060 virtual ~Image(); 00061 00062 virtual bool GetDimensions(int* out_width, int* out_height) const; 00063 const png_bytep* Rows() const; 00064 00065 private: 00066 png_structp png_struct_; 00067 png_infop png_info_; 00068 png_bytep* rows_; 00069 DISALLOW_COPY_AND_ASSIGN(Image); 00070 }; 00071 00074 virtual ImageLibraryInterface::Image* ReadFromFile(const FilePath& path); 00075 00079 class Canvas : public ImageLibraryInterface::Canvas { 00080 public: 00081 Canvas(ImageLibraryInterface* lib, const Delegate* d, 00082 const GoogleString& base_out_path, 00083 int width, int height); 00084 virtual ~Canvas(); 00085 virtual bool DrawImage(const ImageLibraryInterface::Image* image, int x, 00086 int y); 00087 virtual bool WriteToFile(const FilePath& write_path, ImageFormat format); 00088 00089 private: 00090 const Delegate* delegate_; 00091 const GoogleString base_out_path_; 00092 int width_; 00093 int height_; 00094 png_bytep* rows_; 00095 DISALLOW_COPY_AND_ASSIGN(Canvas); 00096 }; 00097 00098 virtual ImageLibraryInterface::Canvas* CreateCanvas(int width, int height); 00099 00100 private: 00101 friend class LibpngImageLibraryTest; 00102 DISALLOW_COPY_AND_ASSIGN(LibpngImageLibrary); 00103 }; 00104 00105 } 00106 } 00107 00108 #endif ///< NET_INSTAWEB_SPRITER_LIBPNG_IMAGE_LIBRARY_H_