Skip to content

Commit

Permalink
Merge pull request openframeworks#3593 from nykwil/master
Browse files Browse the repository at this point in the history
Allow access to pixel color through index (like setColor)
  • Loading branch information
arturoc committed Feb 2, 2015
2 parents 9044784 + cb70636 commit f59b22d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions libs/openFrameworks/graphics/ofImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,12 @@ ofColor_<PixelType> ofImage_<PixelType>::getColor(int x, int y) const {
return pixels.getColor(x, y);
}

//------------------------------------
template<typename PixelType>
ofColor_<PixelType> ofImage_<PixelType>::getColor(int index) const {
return pixels.getColor(index);
}

//------------------------------------
template<typename PixelType>
void ofImage_<PixelType>::setColor(int x, int y, const ofColor_<PixelType>& color) {
Expand Down
8 changes: 7 additions & 1 deletion libs/openFrameworks/graphics/ofImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,13 @@ class ofImage_ : public ofBaseImage_<PixelType>{
/// \param y y position of pixel
/// \returns The ofColor representing the pixels at the x and y position passed in.
ofColor_<PixelType> getColor(int x, int y) const;


/// \brief This returns the ofColor representing the pixels at the index
/// passed in.
/// \param index index into pixel data
/// \returns The ofColor representing the pixels at the index position passed in.
ofColor_<PixelType> getColor(int index) const;

/// \brief Get height of image as a float.
/// \returns Height of image as float.
float getHeight() const;
Expand Down
8 changes: 6 additions & 2 deletions libs/openFrameworks/graphics/ofPixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,8 @@ int ofPixels_<PixelType>::getPixelIndex(int x, int y) const {
}

template<typename PixelType>
ofColor_<PixelType> ofPixels_<PixelType>::getColor(int x, int y) const {
ofColor_<PixelType> ofPixels_<PixelType>::getColor(int index) const {
ofColor_<PixelType> c;
int index = getPixelIndex(x, y);

switch(pixelFormat){
case OF_PIXELS_RGB:
Expand Down Expand Up @@ -556,6 +555,11 @@ ofColor_<PixelType> ofPixels_<PixelType>::getColor(int x, int y) const {
return c;
}

template<typename PixelType>
ofColor_<PixelType> ofPixels_<PixelType>::getColor(int x, int y) const {
return getColor(getPixelIndex(x, y));
}

template<typename PixelType>
void ofPixels_<PixelType>::setColor(int index, const ofColor_<PixelType>& color) {

Expand Down
3 changes: 3 additions & 0 deletions libs/openFrameworks/graphics/ofPixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class ofPixels_ {

/// \brief Get the color at a x,y position
ofColor_<PixelType> getColor(int x, int y) const;

/// \brief Get the color at a specific index
ofColor_<PixelType> getColor(int index) const;

/// \brief Set the color of the pixel at the x,y location
void setColor(int x, int y, const ofColor_<PixelType>& color);
Expand Down

0 comments on commit f59b22d

Please sign in to comment.