Pencil2D  ff90c0872e88be3bf81c548cd60f01983012ec49
Pencil2D is an animation software for both bitmap and vector graphics. It is free, multi-platform, and open source.
 All Classes Functions
bitmapimage.h
1 /*
2 
3 Pencil - Traditional Animation Software
4 Copyright (C) 2005-2007 Patrick Corrieri & Pascal Naidon
5 Copyright (C) 2012-2017 Matthew Chiawen Chang
6 
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; version 2 of the License.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15 
16 */
17 #ifndef BITMAP_IMAGE_H
18 #define BITMAP_IMAGE_H
19 
20 #include <memory>
21 #include <QtXml>
22 #include <QPainter>
23 #include "keyframe.h"
24 
25 
26 class BitmapImage : public KeyFrame
27 {
28 public:
29  BitmapImage();
30  BitmapImage( const BitmapImage& );
31  BitmapImage( const QRect& boundaries, const QColor& colour );
32  BitmapImage( const QRect& boundaries, const QImage& image );
33  BitmapImage( const QString& path, const QPoint& topLeft );
34 
35  ~BitmapImage();
36  BitmapImage& operator=( const BitmapImage& a );
37 
38  void paintImage( QPainter& painter );
39 
40  QImage* image() { return mImage.get(); }
41  void setImage( QImage* pImg );
42 
43  BitmapImage copy();
44  BitmapImage copy( QRect rectangle );
45  void paste( BitmapImage* );
46  void paste( BitmapImage*, QPainter::CompositionMode cm );
47 
48  void add( BitmapImage* );
49  void compareAlpha( BitmapImage* );
50  void moveTopLeft( QPoint point );
51  void moveTopLeft( QPointF point ) { moveTopLeft( point.toPoint() ); }
52  void transform( QRect rectangle, bool smoothTransform );
53  void transform( QRectF rectangle, bool smoothTransform ) { transform( rectangle.toRect(), smoothTransform ); }
54  BitmapImage transformed( QRect selection, QTransform transform, bool smoothTransform );
55  BitmapImage transformed( QRect rectangle, bool smoothTransform );
56  BitmapImage transformed( QRectF rectangle, bool smoothTransform ) { return transformed( rectangle.toRect(), smoothTransform ); }
57 
58  bool contains( QPoint P ) { return mBounds.contains( P ); }
59  bool contains( QPointF P ) { return contains( P.toPoint() ); }
60  void extend( QPoint P );
61  void extend( QRect rectangle );
62 
63  QRgb pixel( int x, int y );
64  QRgb pixel( QPoint P );
65  void setPixel( int x, int y, QRgb colour );
66  void setPixel( QPoint P, QRgb colour );
67  QRgb constScanLine(int x, int y);
68  void scanLine( int x, int y, QRgb colour);
69  void clear();
70  void clear( QRect rectangle );
71  void clear( QRectF rectangle ) { clear( rectangle.toRect() ); }
72 
73  static int pow( int );
74  static bool compareColor(QRgb color1, QRgb color2, int tolerance);
75  static void floodFill(BitmapImage* targetImage, QRect cameraRect, QPoint point, QRgb oldColor, QRgb newColor, int tolerance );
76 
77  void drawLine( QPointF P1, QPointF P2, QPen pen, QPainter::CompositionMode cm, bool antialiasing );
78  void drawRect( QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing );
79  void drawEllipse( QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing );
80  void drawPath( QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing );
81 
82  QPoint topLeft() { return mBounds.topLeft(); }
83  QPoint topRight() { return mBounds.topRight(); }
84  QPoint bottomLeft() { return mBounds.bottomLeft(); }
85  QPoint bottomRight() { return mBounds.bottomRight(); }
86  int left() { return mBounds.left(); }
87  int right() { return mBounds.right(); }
88  int top() { return mBounds.top(); }
89  int bottom() { return mBounds.bottom(); }
90  int width() { return mBounds.width(); }
91  int height() { return mBounds.height(); }
92 
93  QRect& bounds() { return mBounds; }
94 
95 private:
96  std::shared_ptr< QImage > mImage;
97  QRect mBounds;
98  bool mExtendable = true;
99 };
100 
101 #endif