00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <kdebug.h>
00020 #include <qimage.h>
00021
00022 #include "kis_debug_areas.h"
00023 #include "kis_image.h"
00024 #include "kis_paint_layer.h"
00025 #include "kis_selection.h"
00026 #include "kis_painter.h"
00027 #include "kis_undo_adapter.h"
00028 #include "kis_iterators_pixel.h"
00029 #include "kis_paint_device.h"
00030
00031
00032 KisPaintLayer::KisPaintLayer(KisImage *img, const QString& name, Q_UINT8 opacity, KisPaintDeviceSP dev)
00033 : super(img, name, opacity)
00034 {
00035 Q_ASSERT(img);
00036 Q_ASSERT(dev);
00037 m_paintdev = dev;
00038 m_paintdev->setParentLayer(this);
00039 }
00040
00041
00042 KisPaintLayer::KisPaintLayer(KisImage *img, const QString& name, Q_UINT8 opacity)
00043 : super(img, name, opacity)
00044 {
00045 Q_ASSERT(img);
00046 m_paintdev = new KisPaintDevice(this, img->colorSpace(), name.latin1());
00047 }
00048
00049 KisPaintLayer::KisPaintLayer(KisImage *img, const QString& name, Q_UINT8 opacity, KisColorSpace * colorSpace)
00050 : super(img, name, opacity)
00051 {
00052 Q_ASSERT(img);
00053 Q_ASSERT(colorSpace);
00054 m_paintdev = new KisPaintDevice(this, colorSpace, name.latin1());
00055 }
00056
00057 KisPaintLayer::KisPaintLayer(const KisPaintLayer& rhs) : KisLayer(rhs)
00058 {
00059 m_paintdev = new KisPaintDevice( *rhs.m_paintdev.data() );
00060 m_paintdev->setParentLayer(this);
00061 }
00062
00063 KisLayerSP KisPaintLayer::clone() const
00064 {
00065 return new KisPaintLayer(*this);
00066 }
00067
00068 KisPaintLayer::~KisPaintLayer()
00069 {
00070 if (m_paintdev != 0) {
00071 m_paintdev->setParentLayer(0);
00072 }
00073 }
00074
00075 void KisPaintLayer::paintSelection(QImage &img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
00076 {
00077 if (m_paintdev->hasSelection())
00078 m_paintdev->selection()->paintSelection(img, x, y, w, h);
00079 }
00080
00081 void KisPaintLayer::paintSelection(QImage &img, const QRect& scaledImageRect, const QSize& scaledImageSize, const QSize& imageSize)
00082 {
00083 if (m_paintdev && m_paintdev->hasSelection()) {
00084 m_paintdev->selection()->paintSelection(img, scaledImageRect, scaledImageSize, imageSize);
00085 }
00086 }
00087
00088 void KisPaintLayer::paintMaskInactiveLayers(QImage &img, Q_INT32 x, Q_INT32 y, Q_INT32 w, Q_INT32 h)
00089 {
00090 uchar *j = img.bits();
00091
00092 KisColorSpace *cs = m_paintdev->colorSpace();
00093
00094 for (Q_INT32 y2 = y; y2 < h + y; ++y2) {
00095 KisHLineIteratorPixel it = m_paintdev->createHLineIterator(x, y2, w, false);
00096 while ( ! it.isDone()) {
00097 Q_UINT8 s = cs->getAlpha(it.rawData());
00098 if(s==0)
00099 {
00100 Q_UINT8 g = (*(j + 0) + *(j + 1 ) + *(j + 2 )) / 9;
00101
00102 *(j+0) = 128+g ;
00103 *(j+1) = 165+g;
00104 *(j+2) = 128+g;
00105 }
00106 j+=4;
00107 ++it;
00108 }
00109 }
00110 }
00111
00112 QImage KisPaintLayer::createThumbnail(Q_INT32 w, Q_INT32 h)
00113 {
00114 if (m_paintdev)
00115 return m_paintdev->createThumbnail(w, h);
00116 else
00117 return QImage();
00118 }
00119
00120
00121 Q_INT32 KisPaintLayer::x() const { if (m_paintdev) return m_paintdev->getX(); else return 0; }
00122
00123 void KisPaintLayer::setX(Q_INT32 x)
00124 {
00125 if (m_paintdev)
00126 m_paintdev->setX(x);
00127 }
00128
00129 Q_INT32 KisPaintLayer::y() const { if (m_paintdev) return m_paintdev->getY(); else return 0; }
00130 void KisPaintLayer::setY(Q_INT32 y) { if (m_paintdev) m_paintdev->setY(y); }
00131
00132 QRect KisPaintLayer::extent() const { if (m_paintdev) return m_paintdev->extent(); else return QRect(); }
00133 QRect KisPaintLayer::exactBounds() const { if (m_paintdev) return m_paintdev->exactBounds(); else return QRect(); }
00134
00135 #include "kis_paint_layer.moc"