1 /* 2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> 3 * (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com> 4 * 5 * This file is part of lsp-plugins 6 * Created on: 21 нояб. 2018 г. 7 * 8 * lsp-plugins is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * any later version. 12 * 13 * lsp-plugins is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public License 19 * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef DSP_ARCH_NATIVE_GRAPHICS_EFFECTS_H_ 23 #define DSP_ARCH_NATIVE_GRAPHICS_EFFECTS_H_ 24 25 #ifndef __DSP_NATIVE_IMPL 26 #error "This header should not be included directly" 27 #endif /* __DSP_NATIVE_IMPL */ 28 29 namespace native 30 { eff_hsla_hue(float * dst,const float * v,const dsp::hsla_hue_eff_t * eff,size_t count)31 void eff_hsla_hue(float *dst, const float *v, const dsp::hsla_hue_eff_t *eff, size_t count) 32 { 33 float value, hue, alpha; 34 float t = 1.0f - eff->thresh; 35 float kt = 1.0f / eff->thresh; 36 37 for (size_t i=0; i<count; ++i, dst += 4) 38 { 39 value = v[i]; 40 value = (value >= 0.0f) ? 1.0f - value : 1.0f + value; 41 42 if (value < t) 43 { 44 hue = eff->h + value; 45 alpha = 0.0f; 46 } 47 else 48 { 49 hue = eff->h + t; 50 alpha = ((value - t) * kt); 51 } 52 53 dst[0] = (hue > 1.0f) ? hue - 1.0f : hue; 54 dst[1] = eff->s; 55 dst[2] = eff->l; 56 dst[3] = alpha; 57 } 58 } 59 eff_hsla_alpha(float * dst,const float * v,const dsp::hsla_alpha_eff_t * eff,size_t count)60 void eff_hsla_alpha(float *dst, const float *v, const dsp::hsla_alpha_eff_t *eff, size_t count) 61 { 62 float value; 63 64 for (size_t i=0; i<count; ++i, dst += 4) 65 { 66 value = v[i]; 67 value = (value >= 0.0f) ? 1.0f - value : 1.0f + value; 68 69 dst[0] = eff->h; 70 dst[1] = eff->s; 71 dst[2] = eff->l; 72 dst[3] = value; // Fill alpha channel 73 } 74 } 75 eff_hsla_sat(float * dst,const float * v,const dsp::hsla_sat_eff_t * eff,size_t count)76 void eff_hsla_sat(float *dst, const float *v, const dsp::hsla_sat_eff_t *eff, size_t count) 77 { 78 float value; 79 float kt = 1.0f / eff->thresh; 80 81 for (size_t i=0; i<count; ++i, dst += 4) 82 { 83 value = v[i]; 84 value = (value >= 0.0f) ? value : -value; 85 86 if (value >= eff->thresh) 87 { 88 dst[0] = eff->h; 89 dst[1] = eff->s * value; 90 dst[2] = eff->l; 91 dst[3] = 0.0f; 92 } 93 else 94 { 95 dst[0] = eff->h; 96 dst[1] = eff->s * eff->thresh; 97 dst[2] = eff->l; 98 dst[3] = (eff->thresh - value) * kt; 99 } 100 } 101 } 102 eff_hsla_light(float * dst,const float * v,const dsp::hsla_light_eff_t * eff,size_t count)103 void eff_hsla_light(float *dst, const float *v, const dsp::hsla_light_eff_t *eff, size_t count) 104 { 105 float value; 106 float kt = 1.0f / eff->thresh; 107 108 for (size_t i=0; i<count; ++i, dst += 4) 109 { 110 value = v[i]; 111 value = (value >= 0.0f) ? value : -value; 112 113 if (value >= eff->thresh) 114 { 115 dst[0] = eff->h; 116 dst[1] = eff->s; 117 dst[2] = eff->l * value; 118 dst[3] = 0.0f; 119 } 120 else 121 { 122 dst[0] = eff->h; 123 dst[1] = eff->s; 124 dst[2] = eff->l * eff->thresh; 125 dst[3] = (eff->thresh - value) * kt; 126 } 127 } 128 } 129 } 130 131 #endif /* DSP_ARCH_NATIVE_GRAPHICS_EFFECTS_H_ */ 132