00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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_