// REFACTOR: Split this class into one for each distinct functionality category // (e.g. effects, mask operations)? /* Copyright (c) 2003-2007 Clarence Dang All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef KP_PIXMAP_FX_H #define KP_PIXMAP_FX_H #include #include #include #include #include #include #include #include #include #include #include #include class kpAbstractSelection; // // QPixmap (view) Manipulation. // // Anything that is supposed to be manipulating the document contents // (i.e. kpImage), should be moved to kpPainter. // // kpPainter uses us for its Qt backend but we don't use kpPainter. // TODO: We should not use kpColor nor kpImage for the same reason. // class kpPixmapFX { // // Get/Set Parts of Pixmap // public: // // Returns the pixel and mask data found at the in . // static QImage getPixmapAt (const QImage &pm, const QRect &rect); // // Sets the pixel and mask data at in <*destPixmapPtr> // to . Neither 's width nor height are allowed // to be bigger than 's (you can't copy more than you have). // On the other hand, you can copy less than the size of // - no scaling is done. // static void setPixmapAt (QImage *destPixmapPtr, const QRect &destRect, const QImage &srcPixmap); // // Sets the pixel and mask data at the rectangle in <*destPixmapPtr>, // with the top-left and dimensions , // to . // static void setPixmapAt (QImage *destPixmapPtr, const QPoint &destAt, const QImage &srcPixmap); static void setPixmapAt (QImage *destPixmapPtr, int destX, int destY, const QImage &srcPixmap); // // Draws on top of <*destPixmapPtr> at . // The mask of <*destPixmapPtr> is adjusted so that all opaque // pixels in will be opaque in <*destPixmapPtr>. // static void paintPixmapAt (QImage *destPixmapPtr, const QPoint &destAt, const QImage &srcPixmap); static void paintPixmapAt (QImage *destPixmapPtr, int destX, int destY, const QImage &srcPixmap); // // Returns the colour of the pixel at in . // If the pixel is transparent, a value is returned such that // kpTool::isColorTransparent() will return true. // static kpColor getColorAtPixel (const QImage &pm, const QPoint &at); static kpColor getColorAtPixel (const QImage &pm, int x, int y); // // Transforms // public: // // Resizes an image to the given width and height, // filling any new areas with . // static void resize (QImage *destPtr, int w, int h, const kpColor &backgroundColor); static QImage resize (const QImage &pm, int w, int h, const kpColor &backgroundColor); // // Scales an image to the given width and height. // If is true, a smooth scale will be used. // static void scale (QImage *destPtr, int w, int h, bool pretty = false); static QImage scale (const QImage &pm, int w, int h, bool pretty = false); // The minimum difference between 2 angles (in degrees) such that they are // considered different. This gives you at least enough precision to // rotate an image whose width <= 10000 such that its height increases // by just 1 (and similarly with height <= 10000 and width). // // Currently used for skew & rotate operations. static const double AngleInDegreesEpsilon; // // Skews an image. // // horizontal angle clockwise (-90 < x < 90) // vertical angle clockwise (-90 < x < 90) // color to fill new areas with // if > 0, the desired width of the resultant pixmap // if > 0, the desired height of the resultant pixmap // // Using & to generate preview pixmaps is // significantly more efficient than skewing and then scaling yourself. // static QMatrix skewMatrix (int width, int height, double hangle, double vangle); static QMatrix skewMatrix (const QImage &pixmap, double hangle, double vangle); static void skew (QImage *destPixmapPtr, double hangle, double vangle, const kpColor &backgroundColor, int targetWidth = -1, int targetHeight = -1); static QImage skew (const QImage &pm, double hangle, double vangle, const kpColor &backgroundColor, int targetWidth = -1, int targetHeight = -1); // // Rotates an image. // // clockwise angle to rotate by // color to fill new areas with // if > 0, the desired width of the resultant pixmap // if > 0, the desired height of the resultant pixmap // // Using & to generate preview pixmaps is // significantly more efficient than rotating and then scaling yourself. // static QMatrix rotateMatrix (int width, int height, double angle); static QMatrix rotateMatrix (const QImage &pixmap, double angle); static bool isLosslessRotation (double angle); static void rotate (QImage *destPixmapPtr, double angle, const kpColor &backgroundColor, int targetWidth = -1, int targetHeight = -1); static QImage rotate (const QImage &pm, double angle, const kpColor &backgroundColor, int targetWidth = -1, int targetHeight = -1); // // Drawing Shapes // public: // Returns a pen suitable for drawing a rectangle with 90 degree // corners ("MiterJoin"). This is necessary since Qt4 defaults to // "BevelJoin". is passed straight to QPen without modification. static QPen QPainterDrawRectPen (const QColor &color, int qtWidth); // Returns a pen suitable for drawing lines / polylines / polygons / // curves with rounded corners. This is necessary since Qt4 defaults // to square corners ("SquareCap") and "BevelJoin". // is passed straight to QPen without modification. static QPen QPainterDrawLinePen (const QColor &color, int qtWidth); // Draws a line from (x1,y1) to (x2,y2) onto , with // and . The corners are rounded and centred at those // coordinates so if > 1, the line is likely to extend past // a rectangle with those corners. // // If is valid, it draws a stippled line alternating // between long strips of and short strips of . static void drawPolyline (QImage *image, const QPolygon &points, const kpColor &color, int penWidth, const kpColor &stippleColor = kpColor::Invalid); static void drawLine (QImage *image, int x1, int y1, int x2, int y2, const kpColor &color, int penWidth, const kpColor &stippleColor = kpColor::Invalid); // = shape completed else drawing but haven't finalised. // If not , the edge that would form the closure, if the // shape were finalised now, is highlighted specially. // // Odd-even fill. static void drawPolygon (QImage *image, const QPolygon &points, const kpColor &fcolor, int penWidth, const kpColor &bcolor = kpColor::Invalid, bool isFinal = true, const kpColor &fStippleColor = kpColor::Invalid); // Cubic Beizer. static void drawCurve (QImage *image, const QPoint &startPoint, const QPoint &controlPointP, const QPoint &controlPointQ, const QPoint &endPoint, const kpColor &color, int penWidth); static void fillRect (QImage *image, int x, int y, int width, int height, const kpColor &color, const kpColor &stippleColor = kpColor::Invalid); // Draws a rectangle / rounded rectangle / ellipse with top-left at // (x, y) with width and height . Unlike QPainter, // this rectangle will really fit inside x and won't // be one pixel higher or wider etc. // // and must be >= 0. // // must not be invalid. However, may be invalid // to signify an unfilled rectangle / rounded rectangle /ellipse. static void drawRect (QImage *image, int x, int y, int width, int height, const kpColor &fcolor, int penWidth = 1, const kpColor &bcolor = kpColor::Invalid, const kpColor &fStippleColor = kpColor::Invalid); static void drawRoundedRect (QImage *image, int x, int y, int width, int height, const kpColor &fcolor, int penWidth = 1, const kpColor &bcolor = kpColor::Invalid, const kpColor &fStippleColor = kpColor::Invalid); static void drawEllipse (QImage *image, int x, int y, int width, int height, const kpColor &fcolor, int penWidth = 1, const kpColor &bcolor = kpColor::Invalid, const kpColor &fStippleColor = kpColor::Invalid); }; #endif // KP_PIXMAP_FX_H