chalk

kis_paint_device.h
1/*
2 * copyright (c) 2002 patrick julien <freak@codepimps.org>
3 *
4 * this program is free software; you can redistribute it and/or modify
5 * it under the terms of the gnu general public license as published by
6 * the free software foundation; either version 2 of the license, or
7 * (at your option) any later version.
8 *
9 * this program is distributed in the hope that it will be useful,
10 * but without any warranty; without even the implied warranty of
11 * merchantability or fitness for a particular purpose. see the
12 * gnu general public license for more details.
13 *
14 * you should have received a copy of the gnu general public license
15 * along with this program; if not, write to the free software
16 * foundation, inc., 675 mass ave, cambridge, ma 02139, usa.
17 */
18#ifndef KIS_PAINT_DEVICE_IMPL_H_
19#define KIS_PAINT_DEVICE_IMPL_H_
20
21#include <tqcolor.h>
22#include <tqobject.h>
23#include <tqpixmap.h>
24#include <tqptrlist.h>
25#include <tqrect.h>
26#include <tqvaluelist.h>
27#include <tqstring.h>
28
29#include "kis_types.h"
30#include "kdebug.h"
31#include "kis_global.h"
32#include "kis_image.h"
33#include "kis_colorspace.h"
34#include "kis_canvas_controller.h"
35#include "kis_color.h"
36#include <koffice_export.h>
37
38class DCOPObject;
39
40class TQImage;
41class TQSize;
42class TQPoint;
43class TQWMatrix;
44class TQTimer;
45
46class KNamedCommand;
47
48class KoStore;
49
50class KisExifInfo;
52class KisImage;
53class KisRectIteratorPixel;
54class KisVLineIteratorPixel;
55class KisRandomAccessorPixel;
56class KisRandomSubAccessorPixel;
57class KisUndoAdapter;
58class KisFilter;
59class KisDataManager;
60typedef TDESharedPtr<KisDataManager> KisDataManagerSP;
61
62class KisMemento;
63typedef TDESharedPtr<KisMemento> KisMementoSP;
64
65
73class KRITACORE_EXPORT KisPaintDevice
74 : public TQObject
75 , public TDEShared
76{
77
78 TQ_OBJECT
79
80
81public:
82
89 KisPaintDevice(KisColorSpace * colorSpace, const char * name = 0);
90
99 KisPaintDevice(KisLayer *parentLayer, KisColorSpace * colorSpace, const char * name = 0);
100
101 KisPaintDevice(const KisPaintDevice& rhs);
102 virtual ~KisPaintDevice();
103 virtual DCOPObject *dcopObject();
104
105 void lock(bool lock) { m_lock = lock; }
106
107public:
108
112 virtual bool write(KoStore *store);
113
117 virtual bool read(KoStore *store);
118
119public:
120
124 virtual void move(TQ_INT32 x, TQ_INT32 y);
125
129 virtual void move(const TQPoint& pt);
130
135 virtual KNamedCommand * moveCommand(TQ_INT32 x, TQ_INT32 y);
136
140 bool contains(TQ_INT32 x, TQ_INT32 y) const;
141
145 bool contains(const TQPoint& pt) const;
146
153 virtual void extent(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const;
154 virtual TQRect extent() const;
155
163 bool extentIsValid() const;
164
166 void setExtentIsValid(bool isValid);
167
172 virtual void exactBounds(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const;
173 virtual TQRect exactBounds() const;
174 virtual TQRect exactBoundsOldMethod() const;
175 virtual TQRect exactBoundsImprovedOldMethod() const;
176
180 void crop(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
181
183 void crop(TQRect r);
184
188 virtual void clear();
189
193 void fill(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, const TQ_UINT8 *fillPixel);
194
205 virtual void readBytes(TQ_UINT8 * data, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
206
215 virtual void writeBytes(const TQ_UINT8 * data, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h);
216
221 TQ_INT32 numContiguousColumns(TQ_INT32 x, TQ_INT32 minY, TQ_INT32 maxY);
222
227 TQ_INT32 numContiguousRows(TQ_INT32 y, TQ_INT32 minX, TQ_INT32 maxX);
228
233 TQ_INT32 rowStride(TQ_INT32 x, TQ_INT32 y);
234
238 TDE_DEPRECATED const TQ_UINT8* pixel(TQ_INT32 x, TQ_INT32 y);
239
243 TDE_DEPRECATED TQ_UINT8* writablePixel(TQ_INT32 x, TQ_INT32 y);
244
248 virtual void convertTo(KisColorSpace * dstColorSpace, TQ_INT32 renderingIntent = INTENT_PERCEPTUAL);
249
254 virtual void setProfile(KisProfile * profile);
255
260 virtual void convertFromTQImage(const TQImage& img, const TQString &srcProfileName, TQ_INT32 offsetX = 0, TQ_INT32 offsetY = 0);
261
274 virtual TQImage convertToTQImage(KisProfile * dstProfile, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, float exposure = 0.0f);
275
284 virtual TQImage convertToTQImage(KisProfile * dstProfile, float exposure = 0.0f);
285
290
291 KisPaintDeviceSP createThumbnailDevice(TQ_INT32 w, TQ_INT32 h);
292
298 virtual TQImage createThumbnail(TQ_INT32 maxw, TQ_INT32 maxh);
299
300
309 bool pixel(TQ_INT32 x, TQ_INT32 y, TQColor *c, TQ_UINT8 *opacity);
310
311
321 bool pixel(TQ_INT32 x, TQ_INT32 y, KisColor * kc);
322
326 KisColor colorAt(TQ_INT32 x, TQ_INT32 y);
327
343 bool setPixel(TQ_INT32 x, TQ_INT32 y, const TQColor& c, TQ_UINT8 opacity);
344
345 bool setPixel(TQ_INT32 x, TQ_INT32 y, const KisColor& kc);
346
347 KisColorSpace * colorSpace() const;
348
349 KisDataManagerSP dataManager() const;
350
354 void setData(KisDataManagerSP data, KisColorSpace * colorSpace);
355
359 TQ_INT32 getX() const;
360
364 TQ_INT32 getY() const;
365
369 void setX(TQ_INT32 x);
370
374 void setY(TQ_INT32 y);
375
376
380 virtual TQ_INT32 pixelSize() const;
381
385 virtual TQ_INT32 nChannels() const;
386
391 KisImage *image() const;
392
397 KisLayer *parentLayer() const;
398
404
408 virtual void setDirty(const TQRect & rc);
409
413 virtual void setDirty();
414
415
419 void mirrorX();
423 void mirrorY();
424
425 KisMementoSP getMemento();
426 void rollback(KisMementoSP memento);
427 void rollforward(KisMementoSP memento);
428
432 KisRectIteratorPixel createRectIterator(TQ_INT32 left, TQ_INT32 top, TQ_INT32 w, TQ_INT32 h, bool writable);
433
437 KisHLineIteratorPixel createHLineIterator(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, bool writable);
438
442 KisVLineIteratorPixel createVLineIterator(TQ_INT32 x, TQ_INT32 y, TQ_INT32 h, bool writable);
443
450 KisRandomAccessorPixel createRandomAccessor(TQ_INT32 x, TQ_INT32 y, bool writable);
451
455 KisRandomSubAccessorPixel createRandomSubAccessor();
456
458 KisSelectionSP selection();
459
461 void addSelection(KisSelectionSP selection);
462
464 void subtractSelection(KisSelectionSP selection);
465
467 bool hasSelection();
468
470 bool selectionDeselected();
471
473 void deselect();
474
476 void reselect();
477
479 void clearSelection();
480
485 void applySelectionMask(KisSelectionSP mask);
486
492 KisSelectionSP setSelection(KisSelectionSP selection);
493
498
504 void emitSelectionChanged(const TQRect& r);
505
506
507 KisUndoAdapter *undoAdapter() const;
508
513 KisExifInfo* exifInfo();
517 bool hasExifInfo() { return m_exifInfo != 0; }
518signals:
519 void positionChanged(KisPaintDeviceSP device);
520 void ioProgress(TQ_INT8 percentage);
521 void profileChanged(KisProfile * profile);
522
523private slots:
524
525 void runBackgroundFilters();
526
527private:
528 KisPaintDevice& operator=(const KisPaintDevice&);
529
530protected:
531 KisDataManagerSP m_datamanager;
532
533private:
534 /* The KisLayer that contains this paint device, or 0 if this is not
535 * part of a layer.
536 */
537 KisLayer *m_parentLayer;
538
539 bool m_extentIsValid;
540
541 TQ_INT32 m_x;
542 TQ_INT32 m_y;
543 KisColorSpace * m_colorSpace;
544 // Cached for quick access
545 TQ_INT32 m_pixelSize;
546 TQ_INT32 m_nChannels;
547
548 // Whether the selection is active
549 bool m_hasSelection;
550 bool m_selectionDeselected;
551
552 // Contains the actual selection. For now, there can be only
553 // one selection per layer. XXX: is this a limitation?
554 KisSelectionSP m_selection;
555
556 DCOPObject * m_dcop;
557
558 KisExifInfo* m_exifInfo;
559
560 TQValueList<KisFilter*> m_longRunningFilters;
561 TQTimer * m_longRunningFilterTimer;
562
563 bool m_lock;
564};
565
566inline TQ_INT32 KisPaintDevice::pixelSize() const
567{
568 Q_ASSERT(m_pixelSize > 0);
569 return m_pixelSize;
570}
571
572inline TQ_INT32 KisPaintDevice::nChannels() const
573{
574 Q_ASSERT(m_nChannels > 0);
575 return m_nChannels;
576;
577}
578
579inline KisColorSpace * KisPaintDevice::colorSpace() const
580{
581 Q_ASSERT(m_colorSpace != 0);
582 return m_colorSpace;
583}
584
585
586inline TQ_INT32 KisPaintDevice::getX() const
587{
588 return m_x;
589}
590
591inline TQ_INT32 KisPaintDevice::getY() const
592{
593 return m_y;
594}
595
596#endif // KIS_PAINT_DEVICE_IMPL_H_
597
A colorspace is the definition of a certain color model in Chalk.
A KisColor describes a color in a certain colorspace.
Definition kis_color.h:33
KisDataManager defines the interface that modules responsible for storing and retrieving data must in...
Basic interface of a Chalk filter.
Definition kis_filter.h:46
The pixel iterators are high level iterarators.
Abstract class that represents the concept of a Layer in Chalk.
Definition kis_layer.h:42
A paint device contains the actual pixel data and offers methods to read and write pixels.
void mirrorX()
Mirror the device along the X axis.
KisImage * image() const
Return the image that contains this paint device, or 0 if it is not part of an image.
virtual TQImage convertToTQImage(KisProfile *dstProfile, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, float exposure=0.0f)
Create an RGBA TQImage from a rectangle in the paint device.
KisRandomSubAccessorPixel createRandomSubAccessor()
This function create a random accessor which can easily access to sub pixel values.
bool contains(const TQPoint &pt) const
Convenience method for the above.
KisRectIteratorPixel createRectIterator(TQ_INT32 left, TQ_INT32 top, TQ_INT32 w, TQ_INT32 h, bool writable)
This function return an iterator which points to the first pixel of an rectangle.
KisPaintDevice(KisColorSpace *colorSpace, const char *name=0)
Create a new paint device with the specified colorspace.
TQ_INT32 rowStride(TQ_INT32 x, TQ_INT32 y)
Get the row stride at pixel (x, y).
virtual void writeBytes(const TQ_UINT8 *data, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
Copy the bytes in data into the rect specified by x, y, w, h.
bool hasExifInfo()
This function return true if the layer has exif info associated with it.
KisVLineIteratorPixel createVLineIterator(TQ_INT32 x, TQ_INT32 y, TQ_INT32 h, bool writable)
This function return an iterator which points to the first pixel of a vertical line.
virtual bool read(KoStore *store)
Fill this paint device with the pixels from the specified file store.
KisLayer * parentLayer() const
Returns the KisLayer that contains this paint device, or 0 if this is not part of a layer.
virtual void clear()
Complete erase the current paint device.
TDE_DEPRECATED const TQ_UINT8 * pixel(TQ_INT32 x, TQ_INT32 y)
Get a read-only pointer to pixel (x, y).
virtual void readBytes(TQ_UINT8 *data, TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
Read the bytes representing the rectangle described by x, y, w, h into data.
virtual void setProfile(KisProfile *profile)
Changes the profile of the colorspace of this paint device to the given profile.
void deselect()
Deselect the selection for this paintdevice.
KisColor colorAt(TQ_INT32 x, TQ_INT32 y)
Return the KisColor of the pixel at x,y.
KisExifInfo * exifInfo()
Return the exifInfo associated with this layer.
KisSelectionSP selection()
Get the current selection or create one if this paintdevice hasn't got a selection yet.
virtual void setDirty(const TQRect &rc)
Add the specified rect top the parent layer (if present).
void setParentLayer(KisLayer *parentLayer)
Set the KisLayer that contains this paint device, or 0 if this is not part of a layer.
void clearSelection()
Clear the selected pixels from the paint device.
bool contains(TQ_INT32 x, TQ_INT32 y) const
Returns true of x,y is within the extent of this paint device.
void addSelection(KisSelectionSP selection)
Adds the specified selection to the currently active selection for this paintdevice.
bool selectionDeselected()
Whether the previous selection was deselected.
TQ_INT32 getX() const
The X offset of the paint device.
virtual void convertTo(KisColorSpace *dstColorSpace, TQ_INT32 renderingIntent=INTENT_PERCEPTUAL)
Converts the paint device to a different colorspace.
TQ_INT32 numContiguousRows(TQ_INT32 y, TQ_INT32 minX, TQ_INT32 maxX)
Get the number of contiguous rows starting at y, valid for all values of x between minX and maxX.
TQ_INT32 getY() const
The Y offset of the paint device.
virtual KNamedCommand * moveCommand(TQ_INT32 x, TQ_INT32 y)
Move the paint device to the specified location and make it possible to undo the move.
TDE_DEPRECATED TQ_UINT8 * writablePixel(TQ_INT32 x, TQ_INT32 y)
Get a read-write pointer to pixel (x, y).
virtual void convertFromTQImage(const TQImage &img, const TQString &srcProfileName, TQ_INT32 offsetX=0, TQ_INT32 offsetY=0)
Fill this paint device with the data from img; starting at (offsetX, offsetY).
void crop(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h)
Cut the paint device down to the specified rect.
KisPaintDeviceSP createThumbnailDevice(TQ_INT32 w, TQ_INT32 h)
Creates a paint device thumbnail of the paint device, retaining the aspect ratio.
void reselect()
Reinstates the old selection.
bool extentIsValid() const
XXX: This should be a temporay hack, awaiting a proper fix.
virtual TQ_INT32 pixelSize() const
Return the number of bytes a pixel takes.
void setX(TQ_INT32 x)
Return the X offset of the paint device.
virtual bool write(KoStore *store)
Write the pixels of this paint device into the specified file store.
virtual void move(TQ_INT32 x, TQ_INT32 y)
Moves the device to these new coordinates (so no incremental move or so).
void applySelectionMask(KisSelectionSP mask)
Apply a mask to the image data, i.e.
void mirrorY()
Mirror the device along the Y axis.
KisSelectionSP setSelection(KisSelectionSP selection)
Sets the selection of this paint device to the new selection, returns the old selection,...
void setY(TQ_INT32 y)
Return the Y offset of the paint device.
KisHLineIteratorPixel createHLineIterator(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, bool writable)
This function return an iterator which points to the first pixel of a horizontal line.
KisRandomAccessorPixel createRandomAccessor(TQ_INT32 x, TQ_INT32 y, bool writable)
This function creates a random accessor which allow to randomly access any pixels on the paint device...
void emitSelectionChanged()
Notify the owning image that the current selection has changed.
virtual TQ_INT32 nChannels() const
Return the number of channels a pixel takes.
bool setPixel(TQ_INT32 x, TQ_INT32 y, const TQColor &c, TQ_UINT8 opacity)
Set the specified pixel to the specified color.
bool hasSelection()
Whether there is a valid selection for this paintdevice.
void setExtentIsValid(bool isValid)
Convience method for the above.
virtual void extent(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
Retrieve the bounds of the paint device.
TQ_INT32 numContiguousColumns(TQ_INT32 x, TQ_INT32 minY, TQ_INT32 maxY)
Get the number of contiguous columns starting at x, valid for all values of y between minY and maxY.
virtual void exactBounds(TQ_INT32 &x, TQ_INT32 &y, TQ_INT32 &w, TQ_INT32 &h) const
Get the exact bounds of this paint device.
void subtractSelection(KisSelectionSP selection)
Subtracts the specified selection from the currently active selection for this paindevice.
void setData(KisDataManagerSP data, KisColorSpace *colorSpace)
Replace the pixel data, color strategy, and profile.
virtual TQImage createThumbnail(TQ_INT32 maxw, TQ_INT32 maxh)
Creates a thumbnail of the paint device, retaining the aspect ratio.
void fill(TQ_INT32 x, TQ_INT32 y, TQ_INT32 w, TQ_INT32 h, const TQ_UINT8 *fillPixel)
Fill the given rectangle with the given pixel.