Claw 1.7.0
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2011 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien.jorge@gamned.org 00024 */ 00031 #include <limits> 00032 #include <iterator> 00033 00034 00035 //********************* targa::writer::file_output_buffer ********************** 00036 00037 00038 00039 00040 /*----------------------------------------------------------------------------*/ 00045 template<typename Pixel> 00046 claw::graphic::targa::writer::file_output_buffer<Pixel>::file_output_buffer 00047 ( std::ostream& os ) 00048 : m_stream(os) 00049 { 00050 00051 } // targa::writer::file_output_buffer::file_output_buffer() 00052 00053 /*----------------------------------------------------------------------------*/ 00059 template<typename Pixel> 00060 void claw::graphic::targa::writer::file_output_buffer<Pixel>::encode 00061 ( unsigned int n, pattern_type pattern ) 00062 { 00063 assert( n <= max_encodable() ); 00064 assert( n >= min_interesting() ); 00065 00066 unsigned char key = (n-1) | 0x80; 00067 00068 m_stream << key; 00069 order_pixel_bytes( pattern ); 00070 } // targa::writer::file_output_buffer::encode() 00071 00072 /*----------------------------------------------------------------------------*/ 00078 template<typename Pixel> 00079 template<typename Iterator> 00080 void claw::graphic::targa::writer::file_output_buffer<Pixel>::raw 00081 ( Iterator first, Iterator last ) 00082 { 00083 unsigned int n = std::distance(first, last); 00084 00085 unsigned int full = n / max_encodable(); 00086 unsigned int remaining = n % max_encodable(); 00087 00088 unsigned char key = max_encodable() - 1; 00089 00090 for (unsigned int i=0; i!=full; ++i) 00091 { 00092 m_stream << key; 00093 00094 for (unsigned int j=0; j!=max_encodable(); ++j, ++first) 00095 order_pixel_bytes( *first ); 00096 } 00097 00098 if (remaining) 00099 { 00100 key = remaining - 1; 00101 m_stream << key; 00102 00103 for (unsigned int j=0; j!=remaining; ++j, ++first) 00104 order_pixel_bytes( *first ); 00105 } 00106 00107 } // targa::writer::file_output_buffer::raw() 00108 00109 /*----------------------------------------------------------------------------*/ 00113 template<typename Pixel> 00114 unsigned int 00115 claw::graphic::targa::writer::file_output_buffer<Pixel>::min_interesting() const 00116 { 00117 return 2; 00118 } // targa::writer::file_output_buffer::min_interesting() 00119 00120 /*----------------------------------------------------------------------------*/ 00124 template<typename Pixel> 00125 unsigned int 00126 claw::graphic::targa::writer::file_output_buffer<Pixel>::max_encodable() const 00127 { 00128 return 0x80; 00129 } // targa::writer::file_output_buffer::max_encodable()