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 {
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     KisPaintDeviceSP dab = new KisPaintDevice(cs, "dab");
00058     Q_CHECK_PTR(dab);
00059 
00060     KisColor kc = m_painter->paintColor();
00061 
00062     KisColorSpace * colorSpace = dab->colorSpace();
00063 
00064     Q_INT32 pixelSize = colorSpace->pixelSize();
00065 
00066     Q_INT32 maskWidth = mask->width();
00067     Q_INT32 maskHeight = mask->height();
00068 
00069     // Convert the kiscolor to the right colorspace.
00070     kc.convertTo(colorSpace);
00071 
00072     for (int y = 0; y < maskHeight; y++)
00073     {
00074         KisHLineIteratorPixel hiter = dab->createHLineIterator(0, y, maskWidth, true);
00075         int x=0;
00076         while(! hiter.isDone())
00077         {
00078             // XXX: Set mask
00079             colorSpace->setAlpha(kc.data(), mask->alphaAt(x++, y), 1);
00080             memcpy(hiter.rawData(), kc.data(), pixelSize);
00081             ++hiter;
00082         }
00083     }
00084 
00085     return dab;
00086 }
00087 
00088 void KisPaintOp::splitCoordinate(double coordinate, Q_INT32 *whole, double *fraction)
00089 {
00090     Q_INT32 i = static_cast<Q_INT32>(coordinate);
00091 
00092     if (coordinate < 0) {
00093         // We always want the fractional part to be positive.
00094         // E.g. -1.25 becomes -2 and +0.75
00095         i--;
00096     }
00097 
00098     double f = coordinate - i;
00099 
00100     *whole = i;
00101     *fraction = f;
00102 }
00103 
00104 void KisPaintOp::setSource(KisPaintDeviceSP p) {
00105     Q_ASSERT(p);
00106     m_source = p;
00107 }
00108 
00109 
00110 KisPaintOpSettings* KisPaintOpFactory::settings(QWidget* /*parent*/, const KisInputDevice& /*inputDevice*/) { return 0; }
00111 
KDE Home | KDE Accessibility Home | Description of Access Keys