Page Speed Optimization Libraries  1.4.26.1
net/instaweb/spriter/libpng_image_library.h
Go to the documentation of this file.
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 
00021 #include <png.h>
00022 #include "net/instaweb/spriter/image_library_interface.h"
00023 #include "net/instaweb/util/public/string.h"
00024 
00025 namespace net_instaweb {
00026 namespace spriter {
00027 
00034 class LibpngImageLibrary : public ImageLibraryInterface {
00035  public:
00036   LibpngImageLibrary(const FilePath& base_input_path,
00037                      const FilePath& base_output_path,
00038                      Delegate* delegate);
00039   virtual ~LibpngImageLibrary() {}
00040 
00041  protected:
00043   class Image : public ImageLibraryInterface::Image {
00044    public:
00046     Image(ImageLibraryInterface* lib,
00047           png_structp png_struct, png_infop png_info, png_bytep* rows);
00048     virtual ~Image();
00049 
00050     virtual bool GetDimensions(int* out_width, int* out_height) const;
00051     const png_bytep* Rows() const;
00052 
00053    private:
00054     png_structp png_struct_;
00055     png_infop png_info_;
00056     png_bytep* rows_;
00057     DISALLOW_COPY_AND_ASSIGN(Image);
00058   };
00059 
00062   virtual ImageLibraryInterface::Image* ReadFromFile(const FilePath& path);
00063 
00067   class Canvas : public ImageLibraryInterface::Canvas {
00068    public:
00069     Canvas(ImageLibraryInterface* lib, const Delegate* d,
00070            const GoogleString& base_out_path,
00071            int width, int height);
00072     virtual ~Canvas();
00073     virtual bool DrawImage(const ImageLibraryInterface::Image* image, int x,
00074                            int y);
00075     virtual bool WriteToFile(const FilePath& write_path, ImageFormat format);
00076 
00077    private:
00078     const Delegate* delegate_;
00079     const GoogleString base_out_path_;
00080     int width_;
00081     int height_;
00082     png_bytep* rows_;
00083     DISALLOW_COPY_AND_ASSIGN(Canvas);
00084   };
00085 
00086   virtual ImageLibraryInterface::Canvas* CreateCanvas(int width, int height);
00087 
00088  private:
00089   friend class LibpngImageLibraryTest;
00090   DISALLOW_COPY_AND_ASSIGN(LibpngImageLibrary);
00091 };
00092 
00093 }  
00094 }  
00095 
00096 #endif  ///< NET_INSTAWEB_SPRITER_LIBPNG_IMAGE_LIBRARY_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines