| 1 | /* equaliz0r.cpp |
| 2 | * Copyright (C) 2005 Jean-Sebastien Senecal ([email protected]) |
| 3 | * This file is a Frei0r plugin. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "frei0r.hpp"cxx . . $ `<file>/include/frei0r.hpp`/ |
| 21 | #include "frei0r/math.h"cxx . . $ `<file>/include/frei0r/math.h`/ |
| 22 | #include <string.h> |
| 23 | |
| 24 | #include <cstring> |
| 25 | |
| 26 | class equaliz0rcxx . . $ equaliz0r# : public frei0rcxx . . $ frei0r/::filtercxx . . $ frei0r/filter# |
| 27 | { |
| 28 | // Look-up tables for equaliz0r values. |
| 29 | unsigned char rlutcxx . . $ equaliz0r#rlut.[256]; |
| 30 | unsigned char glutcxx . . $ equaliz0r#glut.[256]; |
| 31 | unsigned char blutcxx . . $ equaliz0r#blut.[256]; |
| 32 | |
| 33 | // Intensity histograms. |
| 34 | unsigned int rhistcxx . . $ equaliz0r#rhist.[256]; |
| 35 | unsigned int ghistcxx . . $ equaliz0r#ghist.[256]; |
| 36 | unsigned int bhistcxx . . $ equaliz0r#bhist.[256]; |
| 37 | |
| 38 | void updateLookUpTablescxx . . $ equaliz0r#updateLookUpTables(74d7fd1de75f7d55).(const uint32_t* in) |
| 39 | { |
| 40 | unsigned int size = widthcxx . . $ frei0r/fx#width.*heightcxx . . $ frei0r/fx#height.; |
| 41 | |
| 42 | // First pass : build histograms. |
| 43 | |
| 44 | // Reset histograms. |
| 45 | memset(rhistcxx . . $ equaliz0r#rhist., 0, 256*sizeof(unsigned int)); |
| 46 | memset(ghistcxx . . $ equaliz0r#ghist., 0, 256*sizeof(unsigned int)); |
| 47 | memset(bhistcxx . . $ equaliz0r#bhist., 0, 256*sizeof(unsigned int)); |
| 48 | |
| 49 | // Update histograms. |
| 50 | const unsigned char *in_ptr = (const unsigned char*) in; |
| 51 | for (unsigned int i=0; i<size; ++i) |
| 52 | { |
| 53 | // update 'em |
| 54 | rhistcxx . . $ equaliz0r#rhist.[*in_ptr++]++; |
| 55 | ghistcxx . . $ equaliz0r#ghist.[*in_ptr++]++; |
| 56 | bhistcxx . . $ equaliz0r#bhist.[*in_ptr++]++; |
| 57 | in_ptr++; // skip alpha |
| 58 | } |
| 59 | |
| 60 | // Second pass : update look-up tables. |
| 61 | in_ptr = (const unsigned char*) in; |
| 62 | |
| 63 | // Cumulative intensities of histograms. |
| 64 | unsigned int |
| 65 | rcum = 0, |
| 66 | gcum = 0, |
| 67 | bcum = 0; |
| 68 | |
| 69 | for (int i=0; i<256; ++i) |
| 70 | { |
| 71 | // update cumulatives |
| 72 | rcum += rhistcxx . . $ equaliz0r#rhist.[i]; |
| 73 | gcum += ghistcxx . . $ equaliz0r#ghist.[i]; |
| 74 | bcum += bhistcxx . . $ equaliz0r#bhist.[i]; |
| 75 | |
| 76 | // update 'em |
| 77 | rlutcxx . . $ equaliz0r#rlut.[i] = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).( (rcum << 8) / size ); // = 256 * rcum / size |
| 78 | glutcxx . . $ equaliz0r#glut.[i] = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).( (gcum << 8) / size ); // = 256 * gcum / size |
| 79 | blutcxx . . $ equaliz0r#blut.[i] = CLAMP0255cxx . . $ CLAMP0255(bc0fba5608a0bfe7).( (bcum << 8) / size ); // = 256 * bcum / size |
| 80 | |
| 81 | in_ptr++; // skip alpha |
| 82 | } |
| 83 | |
| 84 | } |
| 85 | |
| 86 | public: |
| 87 | equaliz0rcxx . . $ equaliz0r#equaliz0r(b4d55b1286ff73e8).(unsigned int width, unsigned int height) |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | virtual void updatecxx . . $ equaliz0r#update(da7b4a17ceb4e697).(double time, |
| 92 | uint32_t* out, |
| 93 | const uint32_t* in) |
| 94 | { |
| 95 | std::copycxx . . $ std/copy(88304b602929f6f4).(in, in + widthcxx . . $ frei0r/fx#width.*heightcxx . . $ frei0r/fx#height., out); |
| 96 | updateLookUpTablescxx . . $ equaliz0r#updateLookUpTables(74d7fd1de75f7d55).(in); |
| 97 | unsigned int size = widthcxx . . $ frei0r/fx#width.*heightcxx . . $ frei0r/fx#height.; |
| 98 | const unsigned char *in_ptr = (const unsigned char*) in; |
| 99 | unsigned char *out_ptr = (unsigned char*) out; |
| 100 | for (unsigned int i=0; i<size; ++i) |
| 101 | { |
| 102 | *out_ptr++ = rlutcxx . . $ equaliz0r#rlut.[*in_ptr++]; |
| 103 | *out_ptr++ = glutcxx . . $ equaliz0r#glut.[*in_ptr++]; |
| 104 | *out_ptr++ = blutcxx . . $ equaliz0r#blut.[*in_ptr++]; |
| 105 | *out_ptr++ = *in_ptr++; // copy alpha |
| 106 | } |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | |
| 111 | frei0rcxx . . $ frei0r/::constructcxx . . $ frei0r/construct#<equaliz0rcxx . . $ equaliz0r#> plugincxx . . $ plugin.("Equaliz0r"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 112 | "Equalizes the intensity histograms"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 113 | "Jean-Sebastien Senecal (Drone)"cxx . . $ std/__cxx11/basic_string#basic_string(e36662616dba894d)., |
| 114 | 0,2, |
| 115 | F0R_COLOR_MODEL_RGBA8888cxx . . $ `include/frei0r.h:308:9`!); |
| 116 |