20#include "kis_random_sub_accessor.h"
22#include "kis_paint_device.h"
24KisRandomSubAccessorPixel::KisRandomSubAccessorPixel(KisPaintDeviceSP device) :
25 m_device(device), m_currentPoint( 0, 0 ), m_randomAccessor(device->createRandomAccessor(0,0, false))
30KisRandomSubAccessorPixel::~KisRandomSubAccessorPixel()
35void KisRandomSubAccessorPixel::sampledOldRawData(TQ_UINT8* dst)
37 const TQ_UINT8* pixels[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);
60void KisRandomSubAccessorPixel::sampledRawData(TQ_UINT8* dst)
62 const TQ_UINT8* pixels[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);