chalk

kis_random_sub_accessor.cpp
1/*
2 * This file is part of the KDE project
3 *
4 * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#include "kis_random_sub_accessor.h"
21
22#include "kis_paint_device.h"
23
24KisRandomSubAccessorPixel::KisRandomSubAccessorPixel(KisPaintDeviceSP device) :
25 m_device(device), m_currentPoint( 0, 0 ), m_randomAccessor(device->createRandomAccessor(0,0, false))
26{
27}
28
29
30KisRandomSubAccessorPixel::~KisRandomSubAccessorPixel()
31{
32}
33
34
35void KisRandomSubAccessorPixel::sampledOldRawData(TQ_UINT8* dst)
36{
37 const TQ_UINT8* pixels[4];
38 TQ_UINT8 weights[4];
39 int x = (int)floor(m_currentPoint.x());
40 int y = (int)floor(m_currentPoint.y());
41 double hsub = m_currentPoint.x() - x;
42 if(hsub < 0.0 ) hsub = 1.0 + hsub;
43 double vsub = m_currentPoint.y() - y;
44 if(vsub < 0.0 ) vsub = 1.0 + vsub;
45 weights[0] = (int)tqRound( ( 1.0 - hsub) * ( 1.0 - vsub) * 255 );
46 m_randomAccessor.moveTo(x, y);
47 pixels[0] = m_randomAccessor.oldRawData();
48 weights[1] = (int)tqRound( ( 1.0 - vsub) * hsub * 255 );
49 m_randomAccessor.moveTo(x+1, y);
50 pixels[1] = m_randomAccessor.oldRawData();
51 weights[2] = (int)tqRound( vsub * ( 1.0 - hsub) * 255 );
52 m_randomAccessor.moveTo(x, y+1);
53 pixels[2] = m_randomAccessor.oldRawData();
54 weights[3] = (int)tqRound( hsub * vsub * 255 );
55 m_randomAccessor.moveTo(x+1, y+1);
56 pixels[3] = m_randomAccessor.oldRawData();
57 m_device->colorSpace()->mixColors(pixels, weights, 4, dst);
58}
59
60void KisRandomSubAccessorPixel::sampledRawData(TQ_UINT8* dst)
61{
62 const TQ_UINT8* pixels[4];
63 TQ_UINT8 weights[4];
64 int x = (int)floor(m_currentPoint.x());
65 int y = (int)floor(m_currentPoint.y());
66 double hsub = m_currentPoint.x() - x;
67 if(hsub < 0.0 ) hsub = 1.0 + hsub;
68 double vsub = m_currentPoint.y() - y;
69 if(vsub < 0.0 ) vsub = 1.0 + vsub;
70 weights[0] = (int)tqRound( ( 1.0 - hsub) * ( 1.0 - vsub) * 255 );
71 m_randomAccessor.moveTo(x, y);
72 pixels[0] = m_randomAccessor.rawData();
73 weights[1] = (int)tqRound( ( 1.0 - vsub) * hsub * 255 );
74 m_randomAccessor.moveTo(x+1, y);
75 pixels[1] = m_randomAccessor.rawData();
76 weights[2] = (int)tqRound( vsub * ( 1.0 - hsub) * 255 );
77 m_randomAccessor.moveTo(x, y+1);
78 pixels[2] = m_randomAccessor.rawData();
79 weights[3] = (int)tqRound( hsub * vsub * 255 );
80 m_randomAccessor.moveTo(x+1, y+1);
81 pixels[3] = m_randomAccessor.rawData();
82 m_device->colorSpace()->mixColors(pixels, weights, 4, dst);
83}
84