Esempio n. 1
0
void VFilter( const TwoDArray<unsigned char>& pic_data, TwoDArray<unsigned char>& out_data, const OneDArray<int>& filter, const int bits )
{
    const int offset = (1<<(bits-1));

    int sum, j, jout;

    // Do the first bit
    for (j=0, jout=0; j<filter.Last(); j+=2, jout++)
    {

        for (int i=0; i<pic_data.LengthX(); ++i)
        {
            sum = offset;
            for (int k=filter.Last(); k>=filter.First(); --k)
                sum += filter[k]*static_cast<int>( pic_data[std::max(j-k,0)][i] );
            sum >>= bits;
            sum = std::min( 255, std::max( 0, sum) );
            out_data[jout][i] = static_cast<unsigned char>( sum );
        }// i

    }// j

    // Do the middle bit
    for (; j<=pic_data.LastY()+filter.First(); j+=2, jout++)
    {

        for (int i=0; i<pic_data.LengthX(); ++i)
        {
            sum = offset;
            for (int k=filter.Last(); k>=filter.First(); --k)
                sum += filter[k]*static_cast<int>( pic_data[j-k][i] );
            sum >>= bits;
            sum = std::min( 255, std::max( 0, sum) );
            out_data[jout][i] = static_cast<unsigned char>( sum );
        }// i

    }// j

    // Do the last bit
    for (; j<pic_data.LengthY(); j+=2, jout++)
    {

        for (int i=0; i<pic_data.LengthX(); ++i)
        {
            sum = offset;
            for (int k=filter.Last(); k>=filter.First(); --k)
                sum += filter[k]*static_cast<int>( pic_data[std::min(j-k,pic_data.LastY())][i] );
            sum >>= bits;
            sum = std::min( 255, std::max( 0, sum) );
            out_data[jout][i] = static_cast<unsigned char>( sum );
        }// i

    }// j
}
Esempio n. 2
0
void HFilter( const TwoDArray<unsigned char>& pic_data, TwoDArray<unsigned char>& out_data, const OneDArray<int>& filter, const int bits )
{
    unsigned char* line_data;
    const int offset = (1<<(bits-1));

    int sum;
    int i, iout;

    for (int j=0; j<pic_data.LengthY(); ++j)
    {
        line_data = out_data[j];
        // Do the first bit
        for (i=0, iout=0; i<filter.Last(); i+=2, iout++)
        {
            sum = offset;
            for (int k=filter.Last(); k>=filter.First(); --k)
                sum += filter[k]*static_cast<int>(pic_data[j][std::max(i-k,0)]);
            sum >>= bits;
            sum = std::min( 255, std::max( 0, sum) );
            line_data[iout] = static_cast<unsigned char>( sum );
        }// i
        // Do the middle bit
        for (; i<=pic_data.LastX()+filter.First(); i+=2, iout++)
        {
            sum = offset;
            for (int k=filter.Last(); k>=filter.First(); --k)
                sum += filter[k]*static_cast<int>( pic_data[j][i-k] );
            sum >>= bits;
            sum = std::min( 255, std::max( 0, sum) );
            line_data[iout] = static_cast<unsigned char>( sum );
        }// i
        // Do the last bit
	for (; i<pic_data.LengthX(); i+=2, iout++)
	{
            sum = offset;
            for (int k=filter.Last(); k>=filter.First(); --k)
                sum += filter[k]*static_cast<int>( pic_data[j][std::min(i-k,pic_data.LastX())] );
            sum >>= bits;
            sum = std::min( 255, std::max( 0, sum) );
            line_data[iout] = static_cast<unsigned char>( sum );
        }// i
    }// j

}