00001 /* 00002 * Copyright (C) 2007,2008 Alex Shulgin 00003 * 00004 * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 00005 * software; the exact copying conditions are as follows: 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions are met: 00009 * 00010 * 1. Redistributions of source code must retain the above copyright notice, 00011 * this list of conditions and the following disclaimer. 00012 * 00013 * 2. Redistributions in binary form must reproduce the above copyright 00014 * notice, this list of conditions and the following disclaimer in the 00015 * documentation and/or other materials provided with the distribution. 00016 * 00017 * 3. The name of the author may not be used to endorse or promote products 00018 * derived from this software without specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 00021 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00022 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00023 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00025 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 */ 00031 #ifndef PNGPP_STREAMING_BASE_HPP_INCLUDED 00032 #define PNGPP_STREAMING_BASE_HPP_INCLUDED 00033 00034 #include <cassert> 00035 #include "image_info.hpp" 00036 #include "pixel_traits.hpp" 00037 00038 namespace png 00039 { 00040 00045 class def_image_info_holder 00046 { 00047 public: 00048 def_image_info_holder(image_info const& info) 00049 : m_info(info) 00050 { 00051 } 00052 00053 image_info& get_info() 00054 { 00055 return m_info; 00056 } 00057 00058 private: 00059 image_info m_info; 00060 }; 00061 00067 class image_info_ref_holder 00068 { 00069 public: 00070 image_info_ref_holder(image_info& info) 00071 : m_info(info) 00072 { 00073 } 00074 00075 image_info& get_info() 00076 { 00077 return m_info; 00078 } 00079 00080 private: 00081 image_info& m_info; 00082 }; 00083 00089 template< typename pixel, class info_holder > 00090 class streaming_base 00091 { 00092 public: 00093 typedef pixel_traits< pixel > traits; 00094 00095 explicit streaming_base(image_info& info) 00096 : m_info_holder(info) 00097 { 00098 } 00099 00100 streaming_base(size_t width, size_t height) 00101 : m_info_holder(make_image_info< pixel >()) 00102 { 00103 get_info().set_width(width); 00104 get_info().set_height(height); 00105 } 00106 00107 image_info const& get_info() const 00108 { 00109 return m_info_holder.get_info(); 00110 } 00111 00112 protected: 00113 void reset(size_t /*pass*/) 00114 { 00115 // nothing to do in the most general case 00116 } 00117 00118 image_info& get_info() 00119 { 00120 return m_info_holder.get_info(); 00121 } 00122 00123 info_holder m_info_holder; 00124 }; 00125 00126 } // namespace png 00127 00128 #endif // PNGPP_STREAMING_BASE_HPP_INCLUDED