Changeset View
Changeset View
Standalone View
Standalone View
plugins/paintops/colorsmudge/kis_smudge_radius_option.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | class KisRandomConstAccessorNG; | 43 | class KisRandomConstAccessorNG; | ||
44 | 44 | | |||
45 | KisSmudgeRadiusOption::KisSmudgeRadiusOption(): | 45 | KisSmudgeRadiusOption::KisSmudgeRadiusOption(): | ||
46 | KisRateOption("SmudgeRadius", KisPaintOpOption::GENERAL, true) | 46 | KisRateOption("SmudgeRadius", KisPaintOpOption::GENERAL, true) | ||
47 | { | 47 | { | ||
48 | setValueRange(0.0,300.0); | 48 | setValueRange(0.0,300.0); | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | void KisSmudgeRadiusOption::apply(KisPainter& painter, | 51 | QRect KisSmudgeRadiusOption::sampleRect(const KisPaintInformation& info, | ||
52 | qreal diameter, | ||||
53 | const QPoint &pos) const | ||||
54 | { | ||||
55 | const qreal sliderValue = computeSizeLikeValue(info); | ||||
56 | const int smudgeRadius = ((sliderValue * diameter) * 0.5) / 100.0; | ||||
57 | | ||||
58 | return kisGrowRect(QRect(pos, QSize(1,1)), smudgeRadius + 1); | ||||
59 | } | ||||
60 | | ||||
61 | void KisSmudgeRadiusOption::apply(KoColor *resultColor, | ||||
52 | const KisPaintInformation& info, | 62 | const KisPaintInformation& info, | ||
53 | qreal diameter, | 63 | qreal diameter, | ||
54 | qreal posx, | 64 | qreal posx, | ||
55 | qreal posy, | 65 | qreal posy, | ||
56 | KisPaintDeviceSP dev) const | 66 | KisPaintDeviceSP dev) const | ||
57 | { | 67 | { | ||
58 | if (!isChecked()) return; | 68 | if (!isChecked()) return; | ||
59 | 69 | | |||
60 | qreal sliderValue = computeSizeLikeValue(info); | 70 | qreal sliderValue = computeSizeLikeValue(info); | ||
61 | 71 | | |||
62 | int smudgeRadius = ((sliderValue * diameter) * 0.5) / 100.0; | 72 | int smudgeRadius = ((sliderValue * diameter) * 0.5) / 100.0; | ||
63 | 73 | | |||
64 | 74 | | |||
65 | KoColor color = painter.paintColor(); | 75 | KoColor color(Qt::transparent, dev->colorSpace()); | ||
76 | | ||||
66 | if (smudgeRadius == 1) { | 77 | if (smudgeRadius == 1) { | ||
67 | dev->pixel(posx, posy, &color); | 78 | dev->pixel(posx, posy, &color); | ||
68 | painter.setPaintColor(color); | | |||
69 | } else { | 79 | } else { | ||
70 | 80 | | |||
71 | const KoColorSpace* cs = dev->colorSpace(); | 81 | const KoColorSpace* cs = dev->colorSpace(); | ||
72 | int pixelSize = cs->pixelSize(); | 82 | const int pixelSize = cs->pixelSize(); | ||
73 | 83 | | |||
74 | quint8* data = new quint8[pixelSize]; | 84 | quint8* data = new quint8[pixelSize]; | ||
75 | static quint8** pixels = new quint8*[2]; | 85 | quint8* pixels[2]; | ||
76 | qint16 weights[2]; | 86 | qint16 weights[2]; | ||
77 | 87 | | |||
78 | pixels[1] = new quint8[pixelSize]; | 88 | pixels[1] = new quint8[pixelSize]; | ||
79 | pixels[0] = new quint8[pixelSize]; | 89 | pixels[0] = new quint8[pixelSize]; | ||
80 | 90 | | |||
81 | int loop_increment = 1; | 91 | int loop_increment = 1; | ||
82 | if(smudgeRadius >= 8) | 92 | if(smudgeRadius >= 8) | ||
83 | { | 93 | { | ||
84 | loop_increment = (2*smudgeRadius)/16; | 94 | loop_increment = (2*smudgeRadius)/16; | ||
85 | } | 95 | } | ||
86 | int i = 0; | 96 | int i = 0; | ||
87 | int k = 0; | 97 | int k = 0; | ||
88 | int j = 0; | 98 | int j = 0; | ||
99 | | ||||
89 | KisRandomConstAccessorSP accessor = dev->createRandomConstAccessorNG(0, 0); | 100 | KisRandomConstAccessorSP accessor = dev->createRandomConstAccessorNG(0, 0); | ||
90 | KisCrossDeviceColorPickerInt colorPicker(painter.device(), color); | 101 | accessor->moveTo(posx, posy); | ||
91 | colorPicker.pickColor(posx, posy, color.data()); | 102 | memcpy(color.data(), accessor->rawDataConst(), pixelSize); | ||
92 | 103 | | |||
93 | for (int y = 0; y <= smudgeRadius; y = y + loop_increment) { | 104 | for (int y = 0; y <= smudgeRadius; y = y + loop_increment) { | ||
94 | for (int x = 0; x <= smudgeRadius; x = x + loop_increment) { | 105 | for (int x = 0; x <= smudgeRadius; x = x + loop_increment) { | ||
95 | 106 | | |||
96 | for(j = 0;j < 2;j++) | 107 | for(j = 0;j < 2;j++) | ||
97 | { | 108 | { | ||
98 | if(j == 1) | 109 | if(j == 1) | ||
99 | { | 110 | { | ||
Show All 34 Lines | |||||
134 | } | 145 | } | ||
135 | x = x*(-1); | 146 | x = x*(-1); | ||
136 | } | 147 | } | ||
137 | y = y*(-1); | 148 | y = y*(-1); | ||
138 | } | 149 | } | ||
139 | 150 | | |||
140 | } | 151 | } | ||
141 | 152 | | |||
142 | KoColor color = KoColor(pixels[0],cs); | 153 | color = KoColor(pixels[0],cs); | ||
143 | painter.setPaintColor(color); | | |||
144 | 154 | | |||
145 | for (int l = 0; l < 2; l++){ | 155 | for (int l = 0; l < 2; l++){ | ||
146 | delete[] pixels[l]; | 156 | delete[] pixels[l]; | ||
147 | } | 157 | } | ||
148 | // delete[] pixels; | | |||
149 | delete[] data; | 158 | delete[] data; | ||
150 | } | 159 | } | ||
151 | 160 | | |||
152 | 161 | *resultColor = color.convertedTo(resultColor->colorSpace()); | |||
153 | } | 162 | } | ||
154 | 163 | | |||
155 | void KisSmudgeRadiusOption::writeOptionSetting(KisPropertiesConfigurationSP setting) const | 164 | void KisSmudgeRadiusOption::writeOptionSetting(KisPropertiesConfigurationSP setting) const | ||
156 | { | 165 | { | ||
157 | KisCurveOption::writeOptionSetting(setting); | 166 | KisCurveOption::writeOptionSetting(setting); | ||
158 | } | 167 | } | ||
159 | 168 | | |||
160 | void KisSmudgeRadiusOption::readOptionSetting(const KisPropertiesConfigurationSP setting) | 169 | void KisSmudgeRadiusOption::readOptionSetting(const KisPropertiesConfigurationSP setting) | ||
161 | { | 170 | { | ||
162 | KisCurveOption::readOptionSetting(setting); | 171 | KisCurveOption::readOptionSetting(setting); | ||
163 | } | 172 | } |