krita
kis_random_sub_accessor.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
|