Skip to content

Commit

Permalink
Image: make several methods const (#310)
Browse files Browse the repository at this point in the history
The Data, RGBData, and AvgColor methods do not modify
any object data but are not marked as const, which
prevents other const methods from calling them. This
change API, so it must be done on the main branch.

Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Feb 10, 2022
1 parent 47e6a3a commit 4256a57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Deprecated code produces compile-time warnings. These warning serve as
notification to users that their code should be upgraded. The next major
release will remove the deprecated code.

## Ignition Common 4.X to 5.X

### Modifications

1. `Image::AvgColor`, `Image::Data` and `Image::RGBData` methods are now `const`.

## Ignition Common 3.X to 4.X

### Modifications
Expand Down
6 changes: 3 additions & 3 deletions graphics/include/ignition/common/Image.hh
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ namespace ignition
/// \brief Get the image as a data array
/// \param[out] _data Pointer to a NULL array of char.
/// \param[out] _count The resulting data array size
public: void Data(unsigned char **_data, unsigned int &_count);
public: void Data(unsigned char **_data, unsigned int &_count) const;

/// \brief Get only the RGB data from the image. This will drop the
/// alpha channel if one is present.
/// \param[out] _data Pointer to a NULL array of char.
/// \param[out] _count The resulting data array size
public: void RGBData(unsigned char **_data, unsigned int &_count);
public: void RGBData(unsigned char **_data, unsigned int &_count) const;

/// \brief Get the width
/// \return The image width
Expand Down Expand Up @@ -166,7 +166,7 @@ namespace ignition

/// \brief Get the average color
/// \return The average color
public: math::Color AvgColor();
public: math::Color AvgColor() const;

/// \brief Get the max color
/// \return The max color
Expand Down
10 changes: 5 additions & 5 deletions graphics/src/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace ignition
/// \param[in] _height Height of the image
/// \return bitmap data with red and blue pixels swapped
public: FIBITMAP* SwapRedBlue(const unsigned int &_width,
const unsigned int &_height);
const unsigned int &_height) const;
};
}
}
Expand Down Expand Up @@ -249,7 +249,7 @@ int Image::Pitch() const
}

//////////////////////////////////////////////////
void Image::RGBData(unsigned char **_data, unsigned int &_count)
void Image::RGBData(unsigned char **_data, unsigned int &_count) const
{
FIBITMAP *tmp = this->dataPtr->bitmap;
FIBITMAP *tmp2 = nullptr;
Expand All @@ -266,7 +266,7 @@ void Image::RGBData(unsigned char **_data, unsigned int &_count)
}

//////////////////////////////////////////////////
void Image::Data(unsigned char **_data, unsigned int &_count)
void Image::Data(unsigned char **_data, unsigned int &_count) const
{
if (this->dataPtr->ShouldSwapRedBlue())
{
Expand Down Expand Up @@ -398,7 +398,7 @@ math::Color Image::Pixel(unsigned int _x, unsigned int _y) const
}

//////////////////////////////////////////////////
math::Color Image::AvgColor()
math::Color Image::AvgColor() const
{
unsigned int x, y;
double rsum, gsum, bsum;
Expand Down Expand Up @@ -582,7 +582,7 @@ bool Image::Implementation::CanSwapRedBlue() const

//////////////////////////////////////////////////
FIBITMAP* Image::Implementation::SwapRedBlue(const unsigned int &_width,
const unsigned int &_height)
const unsigned int &_height) const
{
FIBITMAP *copy = FreeImage_Copy(this->bitmap, 0, 0, _width, _height);

Expand Down

0 comments on commit 4256a57

Please sign in to comment.