That time of the day again...

Boudewijn Rempt boud at valdyas.org
Fri Oct 10 18:23:33 CEST 2003


An alternative way of painting, more like the gimp. First create a small
empty, transparent, layer -- really small, you can see how small because of an 
amusing glitch that I don't have time to look into now), then paint the 
pixels on that layer, and composite it with the real image. In theory, 
because I use the bitblt that knows about tiles to composite the image, 
undo/redo should be possible, but it isn't yet.

Oh well, time for a beer and dinner.

------------------------------------------------------------------------------
    QRect r = polyline.boundingRect();

    if ( r.left() < 0 ) r.setLeft( 1 );
    if ( r.bottom() < 0 ) r.setBottom( 1 );
    if ( r.right() < 0 ) r.setRight( 1 );
    if ( r.top() < 0 ) r.setTop( 1 );

    if ( r.left() >= m_device->width() ) r.setLeft( m_device->width() - 1);
    if ( r.bottom() >= m_device->height() ) r.setBottom(  m_device->height() - 
1);
    if ( r.right() >= m_device->width() ) r.setRight( m_device->width() - 1);
    if ( r.top() >= m_device->height() ) r.setTop( m_device->height() - 1);

    // XXX: should paint a single dot
    if ( r.left() == r.right() && r.top() == r.bottom() ) return;

if ( 1 ) {
    // Create a layer the size of the dab
    KisLayerSP layer = new KisLayer( m_device->image(),
                                     r.width(), r.height(),
                                     "dab",
                                     OPACITY_TRANSPARENT);

    KisTileMgrSP tileMgr = layer -> data();

    // If that succeeded, fill it with transparent black pixels
    if ( layer ) {
        layer -> visible( false );
        KisPainter gc( layer.data() );
        gc.fillRect( 0,  0,
                     layer->width(),  layer->height(),
                     KoColor::black(),
                     OPACITY_TRANSPARENT );
        gc.end();
    }

    // Construct a PixelData structure
    KisPixelDataSP pd = new KisPixelData;

    pd -> mgr = 0;
    pd -> tile = 0;
    pd -> mode = TILEMODE_READ;
    pd -> x1 = 0;
    pd -> x2 = r.width() - 1;
    pd -> y1 = 0;
    pd -> y2 = r.height() - 1;
    pd -> width = pd -> x2 - pd -> x1 + 1;
    pd -> height = pd -> y2 - pd -> y1 + 1;
    pd -> depth = tileMgr -> depth();
    pd -> stride = pd -> depth * pd -> width;
    pd -> owner = false;

    // Read the blank pixels from the dab layer into the pixeldata
    // Assumes RGBA
    pd -> data = new QUANTUM[pd->width * pd->height * 4];
    tileMgr -> readPixelData(pd);

    // Convert to a QImage. This assumes RGBA
    QImage img = QImage(pd -> data,
                        r.width(), r.height(),
                        layer -> data() -> depth() * CHAR_BIT,
                        0, 0,
                        QImage::LittleEndian);

    // Create a QPixmap -- i.e. a Qt paintdevice, because Trolltech
    // has done all the Foley & Dam, Newman & Sproull and Hearn reading
    // for us and done the graphics primitives that I'm too lazy to
    // code.
    QPixmap buffer = QPixmap( img );

    QPainter p;
    p.begin(&buffer);
    p.translate( -r.x(),  -r.y() );
    // Get currently selected brush or pattern, color and use
    // that as the pen
    p.drawPolyline( polyline, index, npoints );
    p.end();

    // Convert back to a QImage. Hope nothing bad happened to the alpha
    img = buffer.convertToImage();

    // Back into the pixeldata
    pd-> data = img.bits();

    // And back into the layer
    layer -> data() -> writePixelData( pd );

    // Composite the layer on the image. This is undo/redo-able.
    bitBlt( r.x(),  r.y(), COMPOSITE_OVER, layer.data(), OPACITY_OPAQUE );

-

-- 
Boudewijn Rempt | http://www.valdyas.org/index2.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: signature
Url : http://mail.kde.org/pipermail/kimageshop/attachments/20031010/a0de17e7/attachment.bin


More information about the kimageshop mailing list