krita

kis_random_sub_accessor.cpp

00001 /*
00002  *  This file is part of the KDE project
00003  *
00004  *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kis_random_sub_accessor.h"
00021 
00022 #include "kis_paint_device.h"
00023 
00024 KisRandomSubAccessorPixel::KisRandomSubAccessorPixel(KisPaintDeviceSP device) :
00025     m_device(device), m_currentPoint( 0, 0 ), m_randomAccessor(device->createRandomAccessor(0,0, false))
00026 {
00027 }
00028 
00029 
00030 KisRandomSubAccessorPixel::~KisRandomSubAccessorPixel()
00031 {
00032 }
00033 
00034 
00035 void KisRandomSubAccessorPixel::sampledOldRawData(Q_UINT8* dst)
00036 {
00037     const Q_UINT8* pixels[4];
00038     Q_UINT8 weights[4];
00039     int x = (int)floor(m_currentPoint.x());
00040     int y = (int)floor(m_currentPoint.y());
00041     double hsub = m_currentPoint.x() - x;
00042     if(hsub < 0.0 ) hsub = 1.0 + hsub;
00043     double vsub = m_currentPoint.y() - y;
00044     if(vsub < 0.0 ) vsub = 1.0 + vsub;
00045     weights[0] = (int)qRound( ( 1.0 - hsub) * ( 1.0 - vsub) * 255 );
00046     m_randomAccessor.moveTo(x, y);
00047     pixels[0] = m_randomAccessor.oldRawData();
00048     weights[1] = (int)qRound( ( 1.0 - vsub) * hsub * 255 );
00049     m_randomAccessor.moveTo(x+1, y);
00050     pixels[1] = m_randomAccessor.oldRawData();
00051     weights[2] = (int)qRound( vsub * ( 1.0 - hsub) * 255 );
00052     m_randomAccessor.moveTo(x, y+1);
00053     pixels[2] = m_randomAccessor.oldRawData();
00054     weights[3] = (int)qRound( hsub * vsub * 255 );
00055     m_randomAccessor.moveTo(x+1, y+1);
00056     pixels[3] = m_randomAccessor.oldRawData();
00057     m_device->colorSpace()->mixColors(pixels, weights, 4, dst);
00058 }
00059 
00060 void KisRandomSubAccessorPixel::sampledRawData(Q_UINT8* dst)
00061 {
00062     const Q_UINT8* pixels[4];
00063     Q_UINT8 weights[4];
00064     int x = (int)floor(m_currentPoint.x());
00065     int y = (int)floor(m_currentPoint.y());
00066     double hsub = m_currentPoint.x() - x;
00067     if(hsub < 0.0 ) hsub = 1.0 + hsub;
00068     double vsub = m_currentPoint.y() - y;
00069     if(vsub < 0.0 ) vsub = 1.0 + vsub;
00070     weights[0] = (int)qRound( ( 1.0 - hsub) * ( 1.0 - vsub) * 255 );
00071     m_randomAccessor.moveTo(x, y);
00072     pixels[0] = m_randomAccessor.rawData();
00073     weights[1] = (int)qRound( ( 1.0 - vsub) * hsub * 255 );
00074     m_randomAccessor.moveTo(x+1, y);
00075     pixels[1] = m_randomAccessor.rawData();
00076     weights[2] = (int)qRound( vsub * ( 1.0 - hsub) * 255 );
00077     m_randomAccessor.moveTo(x, y+1);
00078     pixels[2] = m_randomAccessor.rawData();
00079     weights[3] = (int)qRound( hsub * vsub * 255 );
00080     m_randomAccessor.moveTo(x+1, y+1);
00081     pixels[3] = m_randomAccessor.rawData();
00082     m_device->colorSpace()->mixColors(pixels, weights, 4, dst);
00083 }
00084 
KDE Home | KDE Accessibility Home | Description of Access Keys