~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to .pc/kubuntu_01_arm_needs_qreal.diff/krita/plugins/filters/colors/kis_color_to_alpha.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of Krita
 
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; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#include "kis_color_to_alpha.h"
 
22
#include <qcheckbox.h>
 
23
#include <qspinbox.h>
 
24
 
 
25
#include <kcolorbutton.h>
 
26
 
 
27
#include <KoProgressUpdater.h>
 
28
#include <KoUpdater.h>
 
29
 
 
30
#include <kis_iterators_pixel.h>
 
31
#include <kis_paint_device.h>
 
32
#include <kis_selection.h>
 
33
#include <filter/kis_filter_configuration.h>
 
34
#include <kis_processing_information.h>
 
35
 
 
36
#include "ui_wdgcolortoalphabase.h"
 
37
#include "kis_wdg_color_to_alpha.h"
 
38
 
 
39
KisFilterColorToAlpha::KisFilterColorToAlpha() : KisFilter(id(), categoryColors(), i18n("&Color to Alpha..."))
 
40
{
 
41
    setSupportsPainting(true);
 
42
    setSupportsPreview(true);
 
43
    setSupportsIncrementalPainting(false);
 
44
    setSupportsAdjustmentLayers(false);
 
45
    setColorSpaceIndependence(FULLY_INDEPENDENT);
 
46
}
 
47
 
 
48
KisConfigWidget * KisFilterColorToAlpha::createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP, const KisImageWSP image) const
 
49
{
 
50
    Q_UNUSED(image);
 
51
    return new KisWdgColorToAlpha(parent);
 
52
}
 
53
 
 
54
KisFilterConfiguration* KisFilterColorToAlpha::factoryConfiguration(const KisPaintDeviceSP) const
 
55
{
 
56
    KisFilterConfiguration* config = new KisFilterConfiguration("colortoalpha", 1);
 
57
    config->setProperty("targetcolor", QColor(255, 255, 255));
 
58
    config->setProperty("threshold", 0);
 
59
    return config;
 
60
}
 
61
 
 
62
void KisFilterColorToAlpha::process(KisConstProcessingInformation srcInfo,
 
63
                                    KisProcessingInformation dstInfo,
 
64
                                    const QSize& size,
 
65
                                    const KisFilterConfiguration* config,
 
66
                                    KoUpdater* progressUpdater
 
67
                                   ) const
 
68
{
 
69
    const KisPaintDeviceSP src = srcInfo.paintDevice();
 
70
    KisPaintDeviceSP dst = dstInfo.paintDevice();
 
71
    QPoint dstTopLeft = dstInfo.topLeft();
 
72
    QPoint srcTopLeft = srcInfo.topLeft();
 
73
    Q_ASSERT(src != 0);
 
74
    Q_ASSERT(dst != 0);
 
75
 
 
76
    if (config == 0) config = new KisFilterConfiguration("colortoalpha", 1);
 
77
 
 
78
    QVariant value;
 
79
    QColor cTA = (config->getProperty("targetcolor", value)) ? value.value<QColor>() : QColor(255, 255, 255);
 
80
    int threshold = (config->getProperty("threshold", value)) ? value.toInt() : 0;
 
81
    qreal thresholdF = threshold;
 
82
 
 
83
    KisRectIteratorPixel dstIt = dst->createRectIterator(dstTopLeft.x(), dstTopLeft.y(), size.width(), size.height(), dstInfo.selection());
 
84
    KisRectConstIteratorPixel srcIt = src->createRectConstIterator(srcTopLeft.x(), srcTopLeft.y(), size.width(), size.height(), srcInfo.selection());
 
85
 
 
86
    int totalCost = size.width() * size.height() / 100;
 
87
    if (totalCost == 0) totalCost = 1;
 
88
    int currentProgress = 0;
 
89
 
 
90
    const KoColorSpace * cs = src->colorSpace();
 
91
    qint32 pixelsize = cs->pixelSize();
 
92
 
 
93
    quint8* color = new quint8[pixelsize];
 
94
    cs->fromQColor(cTA, color);
 
95
 
 
96
    while (! srcIt.isDone()) {
 
97
        if (srcIt.isSelected()) {
 
98
            quint8 d = cs->difference(color, srcIt.oldRawData());
 
99
            if (d >= threshold) {
 
100
                cs->setOpacity(dstIt.rawData(), 1.0, 1);
 
101
            } else {
 
102
                cs->setOpacity(dstIt.rawData(), d / thresholdF, 1);
 
103
            }
 
104
        }
 
105
        if (progressUpdater) progressUpdater->setProgress((++currentProgress) / totalCost);
 
106
        ++srcIt;
 
107
        ++dstIt;
 
108
    }
 
109
    delete[] color;
 
110
}