Last active
February 19, 2018 09:16
-
-
Save talaviram/49b0358cd223f943c5c8c8c746515571 to your computer and use it in GitHub Desktop.
Makes a JUCE component grayscale.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================== | |
MonochromeEffect.h | |
Created: 18 Feb 2018 6:47:14pm | |
Author: Tal@SoundRadix | |
============================================================================== | |
*/ | |
#pragma once | |
#include "JuceHeader.h" | |
//============================================================================== | |
/** | |
An effect filter that simple makes image monochrome. | |
(This will only work on images/components that aren't opaque, of course). | |
@see Component::setComponentEffect | |
*/ | |
class MonochromeEffect : public ImageEffectFilter | |
{ | |
public: | |
//============================================================================== | |
/** Creates a default drop-shadow effect. | |
To customise the shadow's appearance, use the setShadowProperties() method. | |
@param backgroundColour (optional) - for some alpha values you might prefer a background (such as black). | |
*/ | |
MonochromeEffect(juce::Colour backgroundColour = juce::Colours::transparentBlack) { bgColour_ = backgroundColour; } | |
/** Destructor. */ | |
~MonochromeEffect() {} | |
//============================================================================== | |
/** @internal */ | |
void applyEffect (juce::Image& image, juce::Graphics& g, float scaleFactor, float alpha) | |
{ | |
g.fillAll(bgColour_); | |
image.desaturate(); | |
g.setOpacity (alpha); | |
g.drawImageAt (image, 0, 0); | |
} | |
private: | |
//============================================================================== | |
juce::Colour bgColour_; | |
JUCE_LEAK_DETECTOR (MonochromeEffect) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment