Pencil2D Animation
Download Community News Docs Contribute
  • Overview
  • Articles
  • Code
  •  
  • Class List
  • Class Index
  • Class Hierarchy
  • Class Members
  • File List
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes | List of all members
BitmapImage Class Reference
+ Inheritance diagram for BitmapImage:
Inheritance graph
[legend]
+ Collaboration diagram for BitmapImage:
Collaboration graph
[legend]

Public Member Functions

 BitmapImage (const BitmapImage &)
 
 BitmapImage (const QRect &rectangle, const QColor &color)
 
 BitmapImage (const QPoint &topLeft, const QImage &image)
 
 BitmapImage (const QPoint &topLeft, const QString &path)
 
BitmapImage & operator= (const BitmapImage &a)
 
BitmapImage * clone () const override
 
void loadFile () override
 
void unloadFile () override
 
bool isLoaded () const override
 
quint64 memoryUsage () override
 
void paintImage (QPainter &painter)
 
void paintImage (QPainter &painter, QImage &image, QRect sourceRect, QRect destRect)
 
QImage * image ()
 
void setImage (QImage *pImg)
 
BitmapImage copy ()
 
BitmapImage copy (QRect rectangle)
 
void paste (BitmapImage *, QPainter::CompositionMode cm=QPainter::CompositionMode_SourceOver)
 
void paste (const TiledBuffer *tiledBuffer, QPainter::CompositionMode cm=QPainter::CompositionMode_SourceOver)
 
void moveTopLeft (QPoint point)
 
void moveTopLeft (QPointF point)
 
void transform (QRect rectangle, bool smoothTransform)
 
void transform (QRectF rectangle, bool smoothTransform)
 
BitmapImage transformed (QRect selection, QTransform transform, bool smoothTransform)
 
BitmapImage transformed (QRect rectangle, bool smoothTransform)
 
BitmapImage transformed (QRectF rectangle, bool smoothTransform)
 
bool contains (QPoint P)
 
bool contains (QPointF P)
 
void autoCrop ()
 Removes any transparent borders by reducing the boundaries.
 
QRgb pixel (int x, int y)
 
QRgb pixel (QPoint p)
 
void setPixel (int x, int y, QRgb color)
 
void setPixel (QPoint p, QRgb color)
 
void fillNonAlphaPixels (const QRgb color)
 
QRgb constScanLine (int x, int y) const
 
void scanLine (int x, int y, QRgb color)
 
void clear ()
 
void clear (QRect rectangle)
 
void clear (QRectF rectangle)
 
void drawLine (QPointF P1, QPointF P2, QPen pen, QPainter::CompositionMode cm, bool antialiasing)
 
void drawRect (QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing)
 
void drawEllipse (QRectF rectangle, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing)
 
void drawPath (QPainterPath path, QPen pen, QBrush brush, QPainter::CompositionMode cm, bool antialiasing)
 
QPoint topLeft ()
 
QPoint topRight ()
 
QPoint bottomLeft ()
 
QPoint bottomRight ()
 
int left ()
 
int right ()
 
int top ()
 
int bottom ()
 
int width ()
 
int height ()
 
QSize size ()
 
BitmapImage * scanToTransparent (BitmapImage *img, int threshold, bool redEnabled, bool greenEnabled, bool blueEnabled)
 
QRect & bounds ()
 
bool isMinimallyBounded () const
 Determines if the BitmapImage is minimally bounded.
 
void enableAutoCrop (bool b)
 
void setOpacity (qreal opacity)
 
qreal getOpacity () const
 
Status writeFile (const QString &filename)
 
- Public Member Functions inherited from KeyFrame
 KeyFrame (const KeyFrame &k2)
 
KeyFrame & operator= (const KeyFrame &k2)
 
int pos () const
 
void setPos (int position)
 
int length () const
 
void setLength (int len)
 
void modification ()
 
void setModified (bool b)
 
bool isModified () const
 
void setSelected (bool b)
 
bool isSelected () const
 
QString fileName () const
 
void setFileName (QString strFileName)
 
void addEventListener (KeyFrameEventListener *)
 
void removeEventListner (KeyFrameEventListener *)
 
virtual KeyFrame * clone () const
 
virtual void loadFile ()
 
virtual void unloadFile ()
 
virtual bool isLoaded () const
 
virtual quint64 memoryUsage ()
 

Static Public Member Functions

static bool floodFill (BitmapImage **replaceImage, const BitmapImage *targetImage, const QRect &cameraRect, const QPoint &point, const QRgb &fillColor, int tolerance, const int expandValue)
 
static bool * floodFillPoints (const BitmapImage *targetImage, const QRect &searchBounds, QPoint point, const int tolerance, QRect &newBounds)
 
static void expandFill (bool *fillPixels, const QRect &searchBounds, const QRect &maxBounds, int expand)
 Finds all pixels closest to the input color and applies the input color to the image.
 
static bool compareColor (QRgb newColor, QRgb oldColor, int tolerance, QHash< QRgb, bool > *cache)
 Compare colors for the purposes of flood filling.
 

Public Attributes

const QRgb transp = qRgba(0, 0, 0, 0)
 
const QRgb blackline = qRgba(1, 1, 1, 255)
 
const QRgb redline = qRgba(254,0,0,255)
 
const QRgb greenline = qRgba(0,254,0,255)
 
const QRgb blueline = qRgba(0,0,254,255)
 

Protected Member Functions

void updateBounds (QRect rectangle)
 Update image bounds.
 
void extend (const QPoint &p)
 
void extend (QRect rectangle)
 
void setCompositionModeBounds (BitmapImage *source, QPainter::CompositionMode cm)
 Updates the bounds after a drawImage operation with the composition mode cm.
 
void setCompositionModeBounds (QRect sourceBounds, bool isSourceMinBounds, QPainter::CompositionMode cm)
 Updates the bounds after a draw operation with the composition mode cm.
 

Private Attributes

QImage mImage
 
QRect mBounds {0, 0, 0, 0}
 
bool mMinBound = true
 
bool mEnableAutoCrop = false
 
const int LOW_THRESHOLD = 30
 
const int COLORDIFF = 5
 
const int GRAYSCALEDIFF = 15
 
qreal mOpacity = 1.0
 

Detailed Description

Definition at line 27 of file bitmapimage.h.

Constructor & Destructor Documentation

◆ BitmapImage() [1/5]

BitmapImage::BitmapImage ( )

Definition at line 31 of file bitmapimage.cpp.

◆ BitmapImage() [2/5]

BitmapImage::BitmapImage ( const BitmapImage &  a)

Definition at line 35 of file bitmapimage.cpp.

◆ BitmapImage() [3/5]

BitmapImage::BitmapImage ( const QRect &  rectangle,
const QColor &  color 
)

Definition at line 44 of file bitmapimage.cpp.

◆ BitmapImage() [4/5]

BitmapImage::BitmapImage ( const QPoint &  topLeft,
const QImage &  image 
)

Definition at line 52 of file bitmapimage.cpp.

◆ BitmapImage() [5/5]

BitmapImage::BitmapImage ( const QPoint &  topLeft,
const QString &  path 
)

Definition at line 59 of file bitmapimage.cpp.

◆ ~BitmapImage()

BitmapImage::~BitmapImage ( )
override

Definition at line 69 of file bitmapimage.cpp.

Member Function Documentation

◆ autoCrop()

void BitmapImage::autoCrop ( )

Removes any transparent borders by reducing the boundaries.

This function reduces the bounds of an image until the top and bottom rows, and the left and right columns of pixels each contain at least one pixel with a non-zero alpha value (i.e. non-transparent pixel). Both mBounds and the size of mImage are updated.

Precondition
mBounds.size() == mImage->size()
Postcondition
Either the first and last rows and columns all contain a pixel with alpha > 0 or mBounds.isEmpty() == true
isMinimallyBounded() == true

Definition at line 431 of file bitmapimage.cpp.

◆ bottom()

int BitmapImage::bottom ( )
inline

Definition at line 106 of file bitmapimage.h.

◆ bottomLeft()

QPoint BitmapImage::bottomLeft ( )
inline

Definition at line 101 of file bitmapimage.h.

◆ bottomRight()

QPoint BitmapImage::bottomRight ( )
inline

Definition at line 102 of file bitmapimage.h.

◆ bounds()

QRect & BitmapImage::bounds ( )
inline

Definition at line 113 of file bitmapimage.h.

◆ clear() [1/3]

void BitmapImage::clear ( )

Definition at line 844 of file bitmapimage.cpp.

◆ clear() [2/3]

void BitmapImage::clear ( QRect  rectangle)

Definition at line 870 of file bitmapimage.cpp.

◆ clear() [3/3]

void BitmapImage::clear ( QRectF  rectangle)
inline

Definition at line 84 of file bitmapimage.h.

◆ clone()

BitmapImage * BitmapImage::clone ( ) const
overridevirtual

Reimplemented from KeyFrame.

Definition at line 98 of file bitmapimage.cpp.

◆ compareColor()

static bool BitmapImage::compareColor ( QRgb  newColor,
QRgb  oldColor,
int  tolerance,
QHash< QRgb, bool > *  cache 
)
inlinestatic

Compare colors for the purposes of flood filling.

Calculates the Eulcidian difference of the RGB channels of the image and compares it to the tolerance

Parameters
[in]newColorThe first color to compare
[in]oldColorThe second color to compare
[in]toleranceThe threshold limit between a matching and non-matching color
[in,out]cacheContains a mapping of previous results of compareColor with rule that cache[someColor] = compareColor(someColor, oldColor, tolerance)
Returns
Returns true if the colors have a similarity below the tolerance level (i.e. if Eulcidian distance squared is <= tolerance)

Definition at line 146 of file bitmapimage.h.

◆ constScanLine()

QRgb BitmapImage::constScanLine ( int  x,
int  y 
) const

Definition at line 852 of file bitmapimage.cpp.

◆ contains() [1/2]

bool BitmapImage::contains ( QPoint  P)
inline

Definition at line 70 of file bitmapimage.h.

◆ contains() [2/2]

bool BitmapImage::contains ( QPointF  P)
inline

Definition at line 71 of file bitmapimage.h.

◆ copy() [1/2]

BitmapImage BitmapImage::copy ( )

Definition at line 180 of file bitmapimage.cpp.

◆ copy() [2/2]

BitmapImage BitmapImage::copy ( QRect  rectangle)

Definition at line 185 of file bitmapimage.cpp.

◆ drawEllipse()

void BitmapImage::drawEllipse ( QRectF  rectangle,
QPen  pen,
QBrush  brush,
QPainter::CompositionMode  cm,
bool  antialiasing 
)

Definition at line 665 of file bitmapimage.cpp.

◆ drawLine()

void BitmapImage::drawLine ( QPointF  P1,
QPointF  P2,
QPen  pen,
QPainter::CompositionMode  cm,
bool  antialiasing 
)

Definition at line 623 of file bitmapimage.cpp.

◆ drawPath()

void BitmapImage::drawPath ( QPainterPath  path,
QPen  pen,
QBrush  brush,
QPainter::CompositionMode  cm,
bool  antialiasing 
)

Definition at line 689 of file bitmapimage.cpp.

◆ drawRect()

void BitmapImage::drawRect ( QRectF  rectangle,
QPen  pen,
QBrush  brush,
QPainter::CompositionMode  cm,
bool  antialiasing 
)

Definition at line 639 of file bitmapimage.cpp.

◆ enableAutoCrop()

void BitmapImage::enableAutoCrop ( bool  b)
inline

Definition at line 126 of file bitmapimage.h.

◆ expandFill()

void BitmapImage::expandFill ( bool *  fillPixels,
const QRect &  searchBounds,
const QRect &  maxBounds,
int  expand 
)
static

Finds all pixels closest to the input color and applies the input color to the image.

An example:

0 is where the color was found 1 is the distance from the nearest pixel of that color

211112 100001 100001 211112

Parameters
bitmapImageImage to search
searchColorColor to find

Definition at line 1045 of file bitmapimage.cpp.

◆ extend() [1/2]

void BitmapImage::extend ( const QPoint &  p)
protected

Definition at line 318 of file bitmapimage.cpp.

◆ extend() [2/2]

void BitmapImage::extend ( QRect  rectangle)
protected

Definition at line 326 of file bitmapimage.cpp.

◆ fillNonAlphaPixels()

void BitmapImage::fillNonAlphaPixels ( const QRgb  color)

Definition at line 615 of file bitmapimage.cpp.

◆ floodFill()

bool BitmapImage::floodFill ( BitmapImage **  replaceImage,
const BitmapImage *  targetImage,
const QRect &  cameraRect,
const QPoint &  point,
const QRgb &  fillColor,
int  tolerance,
const int  expandValue 
)
static

Definition at line 885 of file bitmapimage.cpp.

◆ floodFillPoints()

bool * BitmapImage::floodFillPoints ( const BitmapImage *  targetImage,
const QRect &  searchBounds,
QPoint  point,
const int  tolerance,
QRect &  newBounds 
)
static

Definition at line 943 of file bitmapimage.cpp.

◆ getOpacity()

qreal BitmapImage::getOpacity ( ) const
inline

Definition at line 128 of file bitmapimage.h.

◆ height()

int BitmapImage::height ( )
inline

Definition at line 108 of file bitmapimage.h.

◆ image()

QImage * BitmapImage::image ( )

Definition at line 174 of file bitmapimage.cpp.

◆ isLoaded()

bool BitmapImage::isLoaded ( ) const
overridevirtual

Reimplemented from KeyFrame.

Definition at line 148 of file bitmapimage.cpp.

◆ isMinimallyBounded()

bool BitmapImage::isMinimallyBounded ( ) const
inline

Determines if the BitmapImage is minimally bounded.

A BitmapImage is minimally bounded if all edges contain at least 1 non-transparent pixel (alpha > 0). In other words, the size of the image cannot be decreased without cropping visible data.

Returns
True only if bounds() is the minimal bounding box for the contained image.

Definition at line 125 of file bitmapimage.h.

◆ left()

int BitmapImage::left ( )
inline

Definition at line 103 of file bitmapimage.h.

◆ loadFile()

void BitmapImage::loadFile ( )
overridevirtual

Reimplemented from KeyFrame.

Definition at line 130 of file bitmapimage.cpp.

◆ memoryUsage()

quint64 BitmapImage::memoryUsage ( )
overridevirtual

Reimplemented from KeyFrame.

Definition at line 153 of file bitmapimage.cpp.

◆ moveTopLeft() [1/2]

void BitmapImage::moveTopLeft ( QPoint  point)

Definition at line 236 of file bitmapimage.cpp.

◆ moveTopLeft() [2/2]

void BitmapImage::moveTopLeft ( QPointF  point)
inline

Definition at line 63 of file bitmapimage.h.

◆ operator=()

BitmapImage & BitmapImage::operator= ( const BitmapImage &  a)

Definition at line 82 of file bitmapimage.cpp.

◆ paintImage() [1/2]

void BitmapImage::paintImage ( QPainter &  painter)

Definition at line 162 of file bitmapimage.cpp.

◆ paintImage() [2/2]

void BitmapImage::paintImage ( QPainter &  painter,
QImage &  image,
QRect  sourceRect,
QRect  destRect 
)

Definition at line 167 of file bitmapimage.cpp.

◆ paste() [1/2]

void BitmapImage::paste ( BitmapImage *  bitmapImage,
QPainter::CompositionMode  cm = QPainter::CompositionMode_SourceOver 
)

Definition at line 195 of file bitmapimage.cpp.

◆ paste() [2/2]

void BitmapImage::paste ( const TiledBuffer *  tiledBuffer,
QPainter::CompositionMode  cm = QPainter::CompositionMode_SourceOver 
)

Definition at line 214 of file bitmapimage.cpp.

◆ pixel() [1/2]

QRgb BitmapImage::pixel ( int  x,
int  y 
)

Definition at line 587 of file bitmapimage.cpp.

◆ pixel() [2/2]

QRgb BitmapImage::pixel ( QPoint  p)

Definition at line 592 of file bitmapimage.cpp.

◆ right()

int BitmapImage::right ( )
inline

Definition at line 104 of file bitmapimage.h.

◆ scanLine()

void BitmapImage::scanLine ( int  x,
int  y,
QRgb  color 
)

Definition at line 861 of file bitmapimage.cpp.

◆ scanToTransparent()

BitmapImage * BitmapImage::scanToTransparent ( BitmapImage *  img,
int  threshold,
bool  redEnabled,
bool  greenEnabled,
bool  blueEnabled 
)

Definition at line 736 of file bitmapimage.cpp.

◆ setCompositionModeBounds() [1/2]

void BitmapImage::setCompositionModeBounds ( BitmapImage *  source,
QPainter::CompositionMode  cm 
)
protected

Updates the bounds after a drawImage operation with the composition mode cm.

Parameters
[in]sourceThe source image used for the drawImage call.
[in]cmThe composition mode that will be used for the draw image
See also
BitmapImage::setCompositionModeBounds(BitmapImage, QPainter::CompositionMode)

Definition at line 359 of file bitmapimage.cpp.

◆ setCompositionModeBounds() [2/2]

void BitmapImage::setCompositionModeBounds ( QRect  sourceBounds,
bool  isSourceMinBounds,
QPainter::CompositionMode  cm 
)
protected

Updates the bounds after a draw operation with the composition mode cm.

Parameters
[in]sourceBoundsThe bounds of the source used for drawcall.
[in]isSourceMinBoundsIs sourceBounds the minimal bounds for the source image
[in]cmThe composition mode that will be used for the draw image

For a call to draw image of a QPainter (initialized with mImage) with an argument of source, this function intelligently calculates the bounds. It will attempt to preserve minimum bounds based on the composition mode.

This works baed on the principle that some minimal bounds can be determined solely by the minimal bounds of this and source, depending on the value of cm. Some composition modes only expand, or have no affect on the bounds.

Warning
The draw operation described by the arguments of this function needs to be called after this function is run, or the bounds will be out of sync. If mBounds is null, no draw operation needs to be performed.

Definition at line 386 of file bitmapimage.cpp.

◆ setImage()

void BitmapImage::setImage ( QImage *  pImg)

Definition at line 73 of file bitmapimage.cpp.

◆ setOpacity()

void BitmapImage::setOpacity ( qreal  opacity)
inline

Definition at line 127 of file bitmapimage.h.

◆ setPixel() [1/2]

void BitmapImage::setPixel ( int  x,
int  y,
QRgb  color 
)

Definition at line 600 of file bitmapimage.cpp.

◆ setPixel() [2/2]

void BitmapImage::setPixel ( QPoint  p,
QRgb  color 
)

Definition at line 605 of file bitmapimage.cpp.

◆ size()

QSize BitmapImage::size ( )
inline

Definition at line 109 of file bitmapimage.h.

◆ top()

int BitmapImage::top ( )
inline

Definition at line 105 of file bitmapimage.h.

◆ topLeft()

QPoint BitmapImage::topLeft ( )
inline

Definition at line 99 of file bitmapimage.h.

◆ topRight()

QPoint BitmapImage::topRight ( )
inline

Definition at line 100 of file bitmapimage.h.

◆ transform() [1/2]

void BitmapImage::transform ( QRect  rectangle,
bool  smoothTransform 
)

Definition at line 243 of file bitmapimage.cpp.

◆ transform() [2/2]

void BitmapImage::transform ( QRectF  rectangle,
bool  smoothTransform 
)
inline

Definition at line 65 of file bitmapimage.h.

◆ transformed() [1/3]

BitmapImage BitmapImage::transformed ( QRect  rectangle,
bool  smoothTransform 
)

Definition at line 280 of file bitmapimage.cpp.

◆ transformed() [2/3]

BitmapImage BitmapImage::transformed ( QRect  selection,
QTransform  transform,
bool  smoothTransform 
)

Definition at line 261 of file bitmapimage.cpp.

◆ transformed() [3/3]

BitmapImage BitmapImage::transformed ( QRectF  rectangle,
bool  smoothTransform 
)
inline

Definition at line 68 of file bitmapimage.h.

◆ unloadFile()

void BitmapImage::unloadFile ( )
overridevirtual

Reimplemented from KeyFrame.

Definition at line 140 of file bitmapimage.cpp.

◆ updateBounds()

void BitmapImage::updateBounds ( QRect  newBoundaries)
protected

Update image bounds.

Parameters
[in]newBoundariesthe new bounds

Sets this image's bounds to rectangle. Modifies mBounds and crops mImage.

Definition at line 298 of file bitmapimage.cpp.

◆ width()

int BitmapImage::width ( )
inline

Definition at line 107 of file bitmapimage.h.

◆ writeFile()

Status BitmapImage::writeFile ( const QString &  filename)

Definition at line 818 of file bitmapimage.cpp.

Member Data Documentation

◆ blackline

const QRgb BitmapImage::blackline = qRgba(1, 1, 1, 255)

Definition at line 31 of file bitmapimage.h.

◆ blueline

const QRgb BitmapImage::blueline = qRgba(0,0,254,255)

Definition at line 34 of file bitmapimage.h.

◆ COLORDIFF

const int BitmapImage::COLORDIFF = 5
private

Definition at line 191 of file bitmapimage.h.

◆ GRAYSCALEDIFF

const int BitmapImage::GRAYSCALEDIFF = 15
private

Definition at line 192 of file bitmapimage.h.

◆ greenline

const QRgb BitmapImage::greenline = qRgba(0,254,0,255)

Definition at line 33 of file bitmapimage.h.

◆ LOW_THRESHOLD

const int BitmapImage::LOW_THRESHOLD = 30
private

Definition at line 190 of file bitmapimage.h.

◆ mBounds

QRect BitmapImage::mBounds {0, 0, 0, 0}
private

Definition at line 184 of file bitmapimage.h.

◆ mEnableAutoCrop

bool BitmapImage::mEnableAutoCrop = false
private

Definition at line 188 of file bitmapimage.h.

◆ mImage

QImage BitmapImage::mImage
private

Definition at line 183 of file bitmapimage.h.

◆ mMinBound

bool BitmapImage::mMinBound = true
private
See also
isMinimallyBounded()

Definition at line 187 of file bitmapimage.h.

◆ mOpacity

qreal BitmapImage::mOpacity = 1.0
private

Definition at line 194 of file bitmapimage.h.

◆ redline

const QRgb BitmapImage::redline = qRgba(254,0,0,255)

Definition at line 32 of file bitmapimage.h.

◆ transp

const QRgb BitmapImage::transp = qRgba(0, 0, 0, 0)

Definition at line 30 of file bitmapimage.h.


The documentation for this class was generated from the following files:
  • core_lib/src/graphics/bitmap/bitmapimage.h
  • core_lib/src/graphics/bitmap/bitmapimage.cpp
Generated on Thu May 8 2025 04:47:53 for Pencil2D by doxygen 1.9.6 based on revision 4513250b1d5b1a3676ec0e67b06b7a885ceaae39