krita

kis_paintop.cc

00001 /*
00002  *  Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
00003  *  Copyright (c) 2004 Boudewijn Rempt <boud@valdyas.org>
00004  *  Copyright (c) 2004 Clarence Dang <dang@kde.org>
00005  *  Copyright (c) 2004 Adrian Page <adrian@pagenet.plus.com>
00006  *  Copyright (c) 2004 Cyrille Berger <cberger@cberger.net>
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  */
00022 #include "qwidget.h"
00023 #include "kis_painter.h"
00024 #include "kis_layer.h"
00025 #include "kis_types.h"
00026 #include "kis_paintop.h"
00027 #include "kis_alpha_mask.h"
00028 #include "kis_point.h"
00029 #include "kis_colorspace.h"
00030 #include "kis_global.h"
00031 #include "kis_iterators_pixel.h"
00032 #include "kis_color.h"
00033 
00034 KisPaintOp::KisPaintOp(KisPainter * painter) : m_dab(0)
00035 {
00036     m_painter = painter;
00037     setSource(painter->device());
00038 }
00039 
00040 KisPaintOp::~KisPaintOp()
00041 {
00042 }
00043 
00044 KisPaintDeviceSP KisPaintOp::computeDab(KisAlphaMaskSP mask) {
00045     return computeDab(mask, m_painter->device()->colorSpace());
00046 }
00047 
00048 KisPaintDeviceSP KisPaintOp::computeDab(KisAlphaMaskSP mask, KisColorSpace *cs)
00049 {
00050     // XXX: According to the SeaShore source, the Gimp uses a
00051     // temporary layer the size of the layer that is being painted
00052     // on. This layer is cleared between painting actions. Our
00053     // temporary layer, dab, is for every paintAt, composited with
00054     // the target layer. We only use a real temporary layer for things
00055     // like filter tools.
00056 
00057     if(!m_dab || m_dab->colorSpace() != cs)
00058         m_dab = new KisPaintDevice(cs, "dab");
00059     Q_CHECK_PTR(m_dab);
00060 
00061     KisColor kc = m_painter->paintColor();
00062 
00063     KisColorSpace * colorSpace = m_dab->colorSpace();
00064 
00065     Q_INT32 pixelSize = colorSpace->pixelSize();
00066 
00067     Q_INT32 maskWidth = mask->width();
00068     Q_INT32 maskHeight = mask->height();
00069 
00070     // Convert the kiscolor to the right colorspace.
00071     kc.convertTo(colorSpace);
00072 
00073     KisHLineIteratorPixel hiter = m_dab->createHLineIterator(0, 0, maskWidth, true);
00074     for (int y = 0; y < maskHeight; y++)
00075     {
00076         int x=0;
00077         while(! hiter.isDone())
00078         {
00079             // XXX: Set mask
00080             colorSpace->setAlpha(kc.data(), mask->alphaAt(x++, y), 1);
00081             memcpy(hiter.rawData(), kc.data(), pixelSize);
00082             ++hiter;
00083         }
00084         hiter.nextRow();
00085     }
00086 
00087     return m_dab;
00088 }
00089 
00090 void KisPaintOp::splitCoordinate(double coordinate, Q_INT32 *whole, double *fraction)
00091 {
00092     Q_INT32 i = static_cast<Q_INT32>(coordinate);
00093 
00094     if (coordinate < 0) {
00095         // We always want the fractional part to be positive.
00096         // E.g. -1.25 becomes -2 and +0.75
00097         i--;
00098     }
00099 
00100     double f = coordinate - i;
00101 
00102     *whole = i;
00103     *fraction = f;
00104 }
00105 
00106 void KisPaintOp::setSource(KisPaintDeviceSP p) {
00107     Q_ASSERT(p);
00108     m_source = p;
00109 }
00110 
00111 
00112 KisPaintOpSettings* KisPaintOpFactory::settings(QWidget* /*parent*/, const KisInputDevice& /*inputDevice*/) { return 0; }
KDE Home | KDE Accessibility Home | Description of Access Keys