filters

kis_tiff_stream.cc

00001 /*
00002  *  Copyright (c) 2005-2006 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019  
00020 #include "kis_tiff_stream.h"
00021 
00022 TIFFStreamContigBase::TIFFStreamContigBase( uint8* src, uint16 depth, uint32 lineSize ) : TIFFStreamBase(depth), m_src(src), m_lineSize(lineSize) { restart(); }
00023 
00024 void TIFFStreamContigBase::restart()
00025 {
00026     m_srcit = m_src;
00027     m_posinc = 8;
00028 }
00029 
00030 void TIFFStreamContigBase::moveToLine(uint32 lineNumber)
00031 {
00032     m_srcit = m_src + lineNumber * m_lineSize;
00033     m_posinc = 8;
00034 }
00035 
00036 uint32 TIFFStreamContigBelow16::nextValue()
00037 {
00038     register uint8 remain;
00039     register uint32 value;
00040     remain = m_depth;
00041     value = 0;
00042     while (remain > 0)
00043     {
00044         register uint8 toread;
00045         toread = remain;
00046         if (toread > m_posinc) toread = m_posinc;
00047         remain -= toread;
00048         m_posinc -= toread;
00049         value = (value << toread) | (( (*m_srcit) >> (m_posinc) ) & ( ( 1 << toread ) - 1 ) );
00050         if (m_posinc == 0)
00051         {
00052             m_srcit++;
00053             m_posinc=8;
00054         }
00055     }
00056     return value;
00057 }
00058 
00059 uint32 TIFFStreamContigBelow32::nextValue()
00060 {
00061     register uint8 remain;
00062     register uint32 value;
00063     remain = m_depth;
00064     value = 0;
00065     while (remain > 0)
00066     {
00067         register uint8 toread;
00068         toread = remain;
00069         if (toread > m_posinc) toread = m_posinc;
00070         remain -= toread;
00071         m_posinc -= toread;
00072         value = (value) | ( (( (*m_srcit) >> (m_posinc) ) & ( ( 1 << toread ) - 1 ) ) << ( m_depth - 8 - remain ) );
00073         if (m_posinc == 0)
00074         {
00075             m_srcit++;
00076             m_posinc=8;
00077         }
00078     }
00079     return value;
00080 }
00081 
00082 uint32 TIFFStreamContigAbove32::nextValue()
00083 {
00084     register uint8 remain;
00085     register uint32 value;
00086     remain = m_depth;
00087     value = 0;
00088     while (remain > 0)
00089     {
00090         register uint8 toread;
00091         toread = remain;
00092         if (toread > m_posinc) toread = m_posinc;
00093         remain -= toread;
00094         m_posinc -= toread;
00095         if(remain < 32 )
00096         {
00097             value = (value) | ( (( (*m_srcit) >> (m_posinc) ) & ( ( 1 << toread ) - 1 ) ) << ( 24 - remain ) );
00098         }
00099         if (m_posinc == 0)
00100         {
00101             m_srcit++;
00102             m_posinc=8;
00103         }
00104     }
00105     return value;
00106 }
00107 
00108 TIFFStreamSeperate::TIFFStreamSeperate( uint8** srcs, uint8 nb_samples ,uint16 depth, uint32* lineSize) : TIFFStreamBase(depth), m_nb_samples(nb_samples)
00109 {
00110     streams = new TIFFStreamContigBase*[nb_samples];
00111     if(depth < 16)
00112     {
00113         for(uint8 i = 0; i < m_nb_samples; i++)
00114         {
00115             streams[i] = new TIFFStreamContigBelow16(srcs[i], depth, lineSize[i]);
00116         }
00117     } else if( depth < 32 )
00118     {
00119         for(uint8 i = 0; i < m_nb_samples; i++)
00120         {
00121             streams[i] = new TIFFStreamContigBelow32(srcs[i], depth, lineSize[i]);
00122         }
00123     } else {
00124         for(uint8 i = 0; i < m_nb_samples; i++)
00125         {
00126             streams[i] = new TIFFStreamContigAbove32(srcs[i], depth, lineSize[i]);
00127         }
00128     }
00129     restart();
00130 }
00131 
00132 TIFFStreamSeperate::~TIFFStreamSeperate()
00133 {
00134     for(uint8 i = 0; i < m_nb_samples; i++)
00135     {
00136         delete streams[i];
00137     }
00138     delete[] streams;
00139 }
00140 
00141 uint32 TIFFStreamSeperate::nextValue()
00142 {
00143     uint32 value = streams[ m_current_sample ]->nextValue();
00144     if( (++m_current_sample) >= m_nb_samples)
00145         m_current_sample = 0;
00146     return value;
00147 }
00148 
00149 void TIFFStreamSeperate::restart()
00150 {
00151     m_current_sample = 0;
00152     for(uint8 i = 0; i < m_nb_samples; i++)
00153     {
00154         streams[i]->restart();
00155     }
00156 }
00157 
00158 void TIFFStreamSeperate::moveToLine(uint32 lineNumber)
00159 {
00160     for(uint8 i = 0; i < m_nb_samples; i++)
00161     {
00162         streams[i]->moveToLine(lineNumber);
00163     }
00164 }
KDE Home | KDE Accessibility Home | Description of Access Keys