targa_writer.tpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #include <limits>
00032 #include <iterator>
00033
00034
00035
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 }
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 }
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 }
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 }
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 }