| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #ifndef AVFILTER_PRESERVE_COLOR_H | ||
| 20 | #define AVFILTER_PRESERVE_COLOR_H | ||
| 21 | |||
| 22 | #include <math.h> | ||
| 23 | |||
| 24 | #include "libavutil/macros.h" | ||
| 25 | |||
| 26 | enum { | ||
| 27 | P_NONE, | ||
| 28 | P_LUM, | ||
| 29 | P_MAX, | ||
| 30 | P_AVG, | ||
| 31 | P_SUM, | ||
| 32 | P_NRM, | ||
| 33 | P_PWR, | ||
| 34 | NB_PRESERVE | ||
| 35 | }; | ||
| 36 | |||
| 37 | ✗ | static inline float normalize(float r, float g, float b, float max) | |
| 38 | { | ||
| 39 | ✗ | r /= max; | |
| 40 | ✗ | g /= max; | |
| 41 | ✗ | b /= max; | |
| 42 | ✗ | return sqrtf(r * r + g * g + b * b); | |
| 43 | } | ||
| 44 | |||
| 45 | ✗ | static inline float power(float r, float g, float b, float max) | |
| 46 | { | ||
| 47 | ✗ | r /= max; | |
| 48 | ✗ | g /= max; | |
| 49 | ✗ | b /= max; | |
| 50 | ✗ | return cbrtf(r * r * r + g * g * g + b * b * b); | |
| 51 | } | ||
| 52 | |||
| 53 | ✗ | static inline void preserve_color(int preserve_color, | |
| 54 | float ir, float ig, float ib, | ||
| 55 | float r, float g, float b, | ||
| 56 | float max, | ||
| 57 | float *icolor, float *ocolor) | ||
| 58 | { | ||
| 59 | ✗ | switch (preserve_color) { | |
| 60 | ✗ | case P_LUM: | |
| 61 | ✗ | *icolor = FFMAX3(ir, ig, ib) + FFMIN3(ir, ig, ib); | |
| 62 | ✗ | *ocolor = FFMAX3( r, g, b) + FFMIN3( r, g, b); | |
| 63 | ✗ | break; | |
| 64 | ✗ | case P_MAX: | |
| 65 | ✗ | *icolor = FFMAX3(ir, ig, ib); | |
| 66 | ✗ | *ocolor = FFMAX3( r, g, b); | |
| 67 | ✗ | break; | |
| 68 | ✗ | case P_AVG: | |
| 69 | ✗ | *icolor = (ir + ig + ib + 1.f) / 3.f; | |
| 70 | ✗ | *ocolor = ( r + g + b + 1.f) / 3.f; | |
| 71 | ✗ | break; | |
| 72 | ✗ | case P_SUM: | |
| 73 | ✗ | *icolor = ir + ig + ib; | |
| 74 | ✗ | *ocolor = r + g + b; | |
| 75 | ✗ | break; | |
| 76 | ✗ | case P_NRM: | |
| 77 | ✗ | *icolor = normalize(ir, ig, ib, max); | |
| 78 | ✗ | *ocolor = normalize( r, g, b, max); | |
| 79 | ✗ | break; | |
| 80 | ✗ | case P_PWR: | |
| 81 | ✗ | *icolor = power(ir, ig, ib, max); | |
| 82 | ✗ | *ocolor = power( r, g, b, max); | |
| 83 | ✗ | break; | |
| 84 | } | ||
| 85 | ✗ | } | |
| 86 | |||
| 87 | #endif /* AVFILTER_PRESERVE_COLOR_H */ | ||
| 88 |