1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Rosegarden
A MIDI and audio sequencer and musical notation editor.
This program is Copyright 2000-2008
Guillaume Laurent <[email protected]>,
Chris Cannam <[email protected]>,
Richard Bown <[email protected]>
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
Bown to claim authorship of this work have been asserted.
Other copyrights also apply to some parts of this work. Please
see the AUTHORS file and individual file headers for details.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#include "PixmapFunctions.h"
#include <tqbitmap.h>
#include <tqcolor.h>
#include <tqimage.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <iostream>
namespace Rosegarden
{
TQBitmap
PixmapFunctions::generateMask(const TQPixmap &map, const TQRgb &px)
{
TQImage i(map.convertToImage());
TQImage im(i.width(), i.height(), 1, 2, TQImage::LittleEndian);
for (int y = 0; y < i.height(); ++y) {
for (int x = 0; x < i.width(); ++x) {
if (i.pixel(x, y) != px) {
im.setPixel(x, y, 1);
} else {
im.setPixel(x, y, 0);
}
}
}
TQBitmap m;
m.convertFromImage(im);
return m;
}
TQBitmap
PixmapFunctions::generateMask(const TQPixmap &map)
{
TQImage i(map.convertToImage());
TQImage im(i.width(), i.height(), 1, 2, TQImage::LittleEndian);
TQRgb px0(i.pixel(0, 0));
TQRgb px1(i.pixel(i.width() - 1, 0));
TQRgb px2(i.pixel(i.width() - 1, i.height() - 1));
TQRgb px3(i.pixel(0, i.height() - 1));
TQRgb px(px0);
if (px0 != px2 && px1 == px3)
px = px1;
for (int y = 0; y < i.height(); ++y) {
for (int x = 0; x < i.width(); ++x) {
if (i.pixel(x, y) != px) {
im.setPixel(x, y, 1);
} else {
im.setPixel(x, y, 0);
}
}
}
TQBitmap m;
m.convertFromImage(im);
return m;
}
TQPixmap
PixmapFunctions::colourPixmap(const TQPixmap &map, int hue, int minValue)
{
// assumes pixmap is currently in shades of grey; maps black ->
// solid colour and greys -> shades of colour
TQImage image = map.convertToImage();
int s, v;
bool warned = false;
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
TQColor pixel(image.pixel(x, y));
int oldHue;
pixel.hsv(&oldHue, &s, &v);
if (oldHue >= 0) {
if (!warned) {
std::cerr << "PixmapFunctions::recolour: Not a greyscale pixmap "
<< "(found rgb value " << pixel.red() << ","
<< pixel.green() << "," << pixel.blue()
<< "), hoping for the best" << std::endl;
warned = true;
}
}
image.setPixel
(x, y, TQColor(hue,
255 - v,
v > minValue ? v : minValue,
TQColor::Hsv).rgb());
}
}
TQPixmap rmap;
rmap.convertFromImage(image);
if (map.tqmask())
rmap.setMask(*map.tqmask());
return rmap;
}
TQPixmap
PixmapFunctions::shadePixmap(const TQPixmap &map)
{
TQImage image = map.convertToImage();
int h, s, v;
for (int y = 0; y < image.height(); ++y) {
for (int x = 0; x < image.width(); ++x) {
TQColor pixel(image.pixel(x, y));
pixel.hsv(&h, &s, &v);
image.setPixel
(x, y, TQColor(h,
s,
255 - ((255 - v) / 2),
TQColor::Hsv).rgb());
}
}
TQPixmap rmap;
rmap.convertFromImage(image);
if (map.tqmask())
rmap.setMask(*map.tqmask());
return rmap;
}
TQPixmap
PixmapFunctions::flipVertical(const TQPixmap &map)
{
TQPixmap rmap;
TQImage i(map.convertToImage());
rmap.convertFromImage(i.mirror(false, true));
if (map.tqmask()) {
TQImage im(map.tqmask()->convertToImage());
TQBitmap newMask;
newMask.convertFromImage(im.mirror(false, true));
rmap.setMask(newMask);
}
return rmap;
}
TQPixmap
PixmapFunctions::flipHorizontal(const TQPixmap &map)
{
TQPixmap rmap;
TQImage i(map.convertToImage());
rmap.convertFromImage(i.mirror(true, false));
if (map.tqmask()) {
TQImage im(map.tqmask()->convertToImage());
TQBitmap newMask;
newMask.convertFromImage(im.mirror(true, false));
rmap.setMask(newMask);
}
return rmap;
}
std::pair<TQPixmap, TQPixmap>
PixmapFunctions::splitPixmap(const TQPixmap &pixmap, int x)
{
TQPixmap left(x, pixmap.height(), pixmap.depth());
TQBitmap leftMask(left.width(), left.height());
TQPixmap right(pixmap.width() - x, pixmap.height(), pixmap.depth());
TQBitmap rightMask(right.width(), right.height());
TQPainter paint;
paint.begin(&left);
paint.drawPixmap(0, 0, pixmap, 0, 0, left.width(), left.height());
paint.end();
paint.begin(&leftMask);
paint.drawPixmap(0, 0, *pixmap.tqmask(), 0, 0, left.width(), left.height());
paint.end();
left.setMask(leftMask);
paint.begin(&right);
paint.drawPixmap(0, 0, pixmap, left.width(), 0, right.width(), right.height());
paint.end();
paint.begin(&rightMask);
paint.drawPixmap(0, 0, *pixmap.tqmask(), left.width(), 0, right.width(), right.height());
paint.end();
right.setMask(rightMask);
return std::pair<TQPixmap, TQPixmap>(left, right);
}
void
PixmapFunctions::drawPixmapMasked(TQPixmap &dest, TQBitmap &destMask,
int x0, int y0,
const TQPixmap &src)
{
TQImage idp(dest.convertToImage());
TQImage idm(destMask.convertToImage());
TQImage isp(src.convertToImage());
TQImage ism(src.tqmask()->convertToImage());
for (int y = 0; y < isp.height(); ++y) {
for (int x = 0; x < isp.width(); ++x) {
if (x >= ism.width())
continue;
if (y >= ism.height())
continue;
if (ism.depth() == 1 && ism.pixel(x, y) == 0)
continue;
if (ism.pixel(x, y) == TQt::white.rgb())
continue;
int x1 = x + x0;
int y1 = y + y0;
if (x1 < 0 || x1 >= idp.width())
continue;
if (y1 < 0 || y1 >= idp.height())
continue;
idp.setPixel(x1, y1, isp.pixel(x, y));
idm.setPixel(x1, y1, 1);
}
}
dest.convertFromImage(idp);
destMask.convertFromImage(idm);
}
}
|