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) 
00035     : m_dab(0)
00036 {
00037     m_painter = painter;
00038     setSource(painter->device());
00039 }
00040 
00041 KisPaintOp::~KisPaintOp()
00042 {
00043 }
00044 
00045 KisPaintDeviceSP KisPaintOp::computeDab(KisAlphaMaskSP mask) {
00046     return computeDab(mask, m_painter->device()->colorSpace());
00047 }
00048 
00049 KisPaintDeviceSP KisPaintOp::computeDab(KisAlphaMaskSP mask, KisColorSpace *cs)
00050 {
00051     // XXX: According to the SeaShore source, the Gimp uses a
00052     // temporary layer the size of the layer that is being painted
00053     // on. This layer is cleared between painting actions. Our
00054     // temporary layer, dab, is for every paintAt, composited with
00055     // the target layer. We only use a real temporary layer for things
00056     // like filter tools.
00057 
00058     if(!m_dab || m_dab->colorSpace() != cs)
00059         m_dab = new KisPaintDevice(cs, "dab");
00060     Q_CHECK_PTR(m_dab);
00061 
00062     KisColor kc = m_painter->paintColor();
00063 
00064     KisColorSpace * colorSpace = m_dab->colorSpace();
00065 
00066     Q_INT32 pixelSize = colorSpace->pixelSize();
00067 
00068     Q_INT32 maskWidth = mask->width();
00069     Q_INT32 maskHeight = mask->height();
00070 
00071     // Convert the kiscolor to the right colorspace.
00072     kc.convertTo(colorSpace);
00073 
00074     KisHLineIteratorPixel hiter = m_dab->createHLineIterator(0, 0, maskWidth, true);
00075     for (int y = 0; y < maskHeight; y++)
00076     {
00077         int x=0;
00078         while(! hiter.isDone())
00079         {
00080             // XXX: Set mask
00081             colorSpace->setAlpha(kc.data(), mask->alphaAt(x++, y), 1);
00082             memcpy(hiter.rawData(), kc.data(), pixelSize);
00083             ++hiter;
00084         }
00085         hiter.nextRow();
00086     }
00087 
00088     return m_dab;
00089 }
00090 
00091 void KisPaintOp::splitCoordinate(double coordinate, Q_INT32 *whole, double *fraction)
00092 {
00093     Q_INT32 i = static_cast<Q_INT32>(coordinate);
00094 
00095     if (coordinate < 0) {
00096         // We always want the fractional part to be positive.
00097         // E.g. -1.25 becomes -2 and +0.75
00098         i--;
00099     }
00100 
00101     double f = coordinate - i;
00102 
00103     *whole = i;
00104     *fraction = f;
00105 }
00106 
00107 void KisPaintOp::setSource(KisPaintDeviceSP p) {
00108     Q_ASSERT(p);
00109     m_source = p;
00110 }
00111 
00112 
00113 KisPaintOpSettings* KisPaintOpFactory::settings(QWidget* /*parent*/, const KisInputDevice& /*inputDevice*/) { return 0; }
KDE Home | KDE Accessibility Home | Description of Access Keys