From kde-kimageshop Fri Oct 10 15:23:33 2003 From: Boudewijn Rempt Date: Fri, 10 Oct 2003 15:23:33 +0000 To: kde-kimageshop Subject: That time of the day again... X-MARC-Message: https://marc.info/?l=kde-kimageshop&m=106579948813453 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1254056981==" --===============1254056981== Content-Type: multipart/signed; protocol="application/pgp-signature"; micalg=pgp-sha1; boundary="Boundary-02=_57sh/Qmn1yq624f"; charset="us-ascii" Content-Transfer-Encoding: 7bit --Boundary-02=_57sh/Qmn1yq624f Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Content-Description: signed data Content-Disposition: inline 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=20 amusing glitch that I don't have time to look into now), then paint the=20 pixels on that layer, and composite it with the real image. In theory,=20 because I use the bitblt that knows about tiles to composite the image,=20 undo/redo should be possible, but it isn't yet. Oh well, time for a beer and dinner. =2D------------------------------------------------------------------------= =2D---- QRect r =3D 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() >=3D m_device->width() ) r.setLeft( m_device->width() - 1= ); if ( r.bottom() >=3D m_device->height() ) r.setBottom( m_device->heigh= t() -=20 1); if ( r.right() >=3D m_device->width() ) r.setRight( m_device->width() -= 1); if ( r.top() >=3D m_device->height() ) r.setTop( m_device->height() - 1= ); // XXX: should paint a single dot if ( r.left() =3D=3D r.right() && r.top() =3D=3D r.bottom() ) return; if ( 1 ) { // Create a layer the size of the dab KisLayerSP layer =3D new KisLayer( m_device->image(), r.width(), r.height(), "dab", OPACITY_TRANSPARENT); KisTileMgrSP tileMgr =3D 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 =3D new KisPixelData; pd -> mgr =3D 0; pd -> tile =3D 0; pd -> mode =3D TILEMODE_READ; pd -> x1 =3D 0; pd -> x2 =3D r.width() - 1; pd -> y1 =3D 0; pd -> y2 =3D r.height() - 1; pd -> width =3D pd -> x2 - pd -> x1 + 1; pd -> height =3D pd -> y2 - pd -> y1 + 1; pd -> depth =3D tileMgr -> depth(); pd -> stride =3D pd -> depth * pd -> width; pd -> owner =3D false; // Read the blank pixels from the dab layer into the pixeldata // Assumes RGBA pd -> data =3D new QUANTUM[pd->width * pd->height * 4]; tileMgr -> readPixelData(pd); // Convert to a QImage. This assumes RGBA QImage img =3D 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 =3D 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 =3D buffer.convertToImage(); // Back into the pixeldata pd-> data =3D 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 ); =2D =2D-=20 Boudewijn Rempt | http://www.valdyas.org/index2.html --Boundary-02=_57sh/Qmn1yq624f Content-Type: application/pgp-signature Content-Description: signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux) iD8DBQA/hs75daCcgCmN5d8RAiaWAJ9AF289gBgG6UTwhjLIlSH+LQaFQwCgxW2v 5KIML+EZLuYaPFR5BGERV5w= =arLn -----END PGP SIGNATURE----- --Boundary-02=_57sh/Qmn1yq624f-- --===============1254056981== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ kimageshop mailing list kimageshop@mail.kde.org http://mail.kde.org/mailman/listinfo/kimageshop --===============1254056981==--