| 1 | #include "frei0r.hpp" |
| 2 | |
| 3 | #include <algorithm> |
| 4 | |
| 5 | class xfade0r : public frei0r::mixer2 |
| 6 | { |
| 7 | public: |
| 8 | xfade0r(unsigned int width, unsigned int height) |
| 9 | { |
| 10 | fader = 0.0; |
| 11 | register_param(fader,"fader","the fader position"); |
| 12 | } |
| 13 | |
| 14 | struct fade_fun |
| 15 | { |
| 16 | fade_fun(double pos) |
| 17 | { |
| 18 | fader_pos=uint8_t(std::max(0.,std::min(255.,pos*255.))); |
| 19 | } |
| 20 | |
| 21 | uint8_t operator()(uint8_t in1,uint8_t in2) |
| 22 | { |
| 23 | return ((255-fader_pos)*in1 + fader_pos*in2) / 256; |
| 24 | } |
| 25 | |
| 26 | uint8_t fader_pos; |
| 27 | }; |
| 28 | |
| 29 | void update(double time, |
| 30 | uint32_t* out, |
| 31 | const uint32_t* in1, |
| 32 | const uint32_t* in2) |
| 33 | { |
| 34 | std::transform(reinterpret_cast<const uint8_t*>(in1), |
| 35 | reinterpret_cast<const uint8_t*>(in1)+(width*height*4), |
| 36 | reinterpret_cast<const uint8_t*>(in2), |
| 37 | reinterpret_cast<uint8_t*>(out), |
| 38 | fade_fun(fader)); |
| 39 | } |
| 40 | |
| 41 | private: |
| 42 | double fader; |
| 43 | }; |
| 44 | |
| 45 | |
| 46 | frei0r::construct<xfade0r> plugin("xfade0r", |
| 47 | "a simple xfader", |
| 48 | "Martin Bayer", |
| 49 | 0,2); |
| 50 |