| 1 | #cxx . . $ `<file>/src/filter/pixs0r/pixs0r.cc`/include <random> |
| 2 | #include <cstdint> |
| 3 | |
| 4 | struct pixshift0rcxx . . $ pixshift0r# |
| 5 | { |
| 6 | unsigned int m_widthcxx . . $ pixshift0r#m_width.; |
| 7 | unsigned int m_heightcxx . . $ pixshift0r#m_height.; |
| 8 | |
| 9 | unsigned int m_shift_intensitycxx . . $ pixshift0r#m_shift_intensity.; |
| 10 | unsigned int m_block_heightcxx . . $ pixshift0r#m_block_height.; |
| 11 | |
| 12 | // If m_block_height == 0, then these bound block heights |
| 13 | unsigned int m_block_height_mincxx . . $ pixshift0r#m_block_height_min.; |
| 14 | unsigned int m_block_height_maxcxx . . $ pixshift0r#m_block_height_max.; |
| 15 | |
| 16 | stdcxx . . $ std/::mt19937cxx . . $ std/mt19937# m_rngcxx . . $ pixshift0r#m_rng.; |
| 17 | |
| 18 | stdcxx . . $ std/::uniform_int_distributioncxx . . $ std/uniform_int_distribution#<int64_t> m_shift_rngcxx . . $ pixshift0r#m_shift_rng.; |
| 19 | stdcxx . . $ std/::uniform_int_distributioncxx . . $ std/uniform_int_distribution#<unsigned int> m_block_height_rngcxx . . $ pixshift0r#m_block_height_rng.; |
| 20 | |
| 21 | pixshift0rcxx . . $ pixshift0r#pixshift0r(b4d55b1286ff73e8).(unsigned int width, unsigned int height) |
| 22 | : m_widthcxx . . $ pixshift0r#m_width.(width), m_heightcxx . . $ pixshift0r#m_height.(height), m_block_heightcxx . . $ pixshift0r#m_block_height.(0), |
| 23 | m_shift_intensitycxx . . $ pixshift0r#m_shift_intensity.(0), m_block_height_mincxx . . $ pixshift0r#m_block_height_min.(1), m_block_height_maxcxx . . $ pixshift0r#m_block_height_max.(1), |
| 24 | m_rngcxx . . $ pixshift0r#m_rng.(stdcxx . . $ std/random_device#random_device(49f6e7a06ebc5aa8).::random_devicecxx . . $ std/random_device#{}(cxx . . $ std/random_device#`operator()`(db52760e79bf9054).)), |
| 25 | m_shift_rngcxx . . $ pixshift0r#m_shift_rng.(0, 0), m_block_height_rngcxx . . $ pixshift0r#m_block_height_rng.(1, 1) {} |
| 26 | |
| 27 | void processcxx . . $ pixshift0r#process(400e083a04eff154).(const uint32_tcxx . . $ uint32_t# *inframe, uint32_tcxx . . $ uint32_t# *outframe) |
| 28 | { |
| 29 | for (unsigned int b = 0; b < m_heightcxx . . $ pixshift0r#m_height.;) |
| 30 | { |
| 31 | unsigned int block_height = m_block_heightcxx . . $ pixshift0r#m_block_height. ? m_block_heightcxx . . $ pixshift0r#m_block_height. : m_block_height_rngcxx . . $ pixshift0r#m_block_height_rng.(cxx . . $ std/uniform_int_distribution#`operator()`(bd98775284160f6b).m_rngcxx . . $ pixshift0r#m_rng.); |
| 32 | |
| 33 | // Number of rows to shift is either block size or |
| 34 | // what we can *safely* operate on (avoids corruption). |
| 35 | block_height = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a).(block_height, m_heightcxx . . $ pixshift0r#m_height. - b); |
| 36 | |
| 37 | // Ensure we always make progress |
| 38 | if (block_height == 0) |
| 39 | block_height = 1; |
| 40 | |
| 41 | int64_t shift = m_shift_intensitycxx . . $ pixshift0r#m_shift_intensity. ? m_shift_rngcxx . . $ pixshift0r#m_shift_rng.(cxx . . $ std/uniform_int_distribution#`operator()`(bd98775284160f6b).m_rngcxx . . $ pixshift0r#m_rng.) : 0; |
| 42 | |
| 43 | for (unsigned int j = 0; j < block_height; ++j) |
| 44 | { |
| 45 | // NOTE: Faulty implementations, such as FFmpeg don't |
| 46 | // check for (width % 8 == 0 && height % 8 == 0). |
| 47 | // |
| 48 | // A possible workaround for all filters, is a scale filter: |
| 49 | // (e.g "scale=round(in_w/8)*8:round(in_h/8)*8:flags=neighbor"). |
| 50 | // |
| 51 | // https://ffmpeg.org/doxygen/trunk/vf__frei0r_8c_source.html#l00352 |
| 52 | size_t pitch = static_cast<size_t>(b + j) * m_widthcxx . . $ pixshift0r#m_width.; |
| 53 | |
| 54 | const uint32_tcxx . . $ uint32_t# *inrow = inframe + pitch; |
| 55 | uint32_tcxx . . $ uint32_t# *outrow = outframe + pitch; |
| 56 | |
| 57 | if (shift > 0) |
| 58 | { |
| 59 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4). (inrow, inrow + m_widthcxx . . $ pixshift0r#m_width. - shift, outrow + shift); |
| 60 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4). (inrow + m_widthcxx . . $ pixshift0r#m_width. - shift, inrow + m_widthcxx . . $ pixshift0r#m_width., outrow); |
| 61 | } |
| 62 | else if (shift < 0) |
| 63 | { |
| 64 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4). (inrow, inrow - shift, outrow + m_widthcxx . . $ pixshift0r#m_width. + shift); |
| 65 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4). (inrow - shift, inrow + m_widthcxx . . $ pixshift0r#m_width., outrow); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | stdcxx . . $ std/::copycxx . . $ std/copy(88304b602929f6f4). (inrow, inrow + m_widthcxx . . $ pixshift0r#m_width., outrow); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | b += block_height; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void set_block_height_rangecxx . . $ pixshift0r#set_block_height_range(b4d55b1286ff73e8).(unsigned int min_bh, unsigned int max_bh) |
| 78 | { |
| 79 | this->m_block_height_mincxx . . $ pixshift0r#m_block_height_min. = min_bh; |
| 80 | this->m_block_height_maxcxx . . $ pixshift0r#m_block_height_max. = max_bh; |
| 81 | |
| 82 | auto rng_params = decltypecxx . . $ std/uniform_int_distribution#param_type#param_type(249673c20e2b8d5).(this->m_block_height_rng)::param_typecxx . . $ std/uniform_int_distribution#param_type#(min_bh, max_bh); |
| 83 | |
| 84 | this->m_block_height_rngcxx . . $ pixshift0r#m_block_height_rng..paramcxx . . $ std/uniform_int_distribution#param(dc6881523d5f4776).(rng_params); |
| 85 | } |
| 86 | |
| 87 | void set_shift_intensitycxx . . $ pixshift0r#set_shift_intensity(cb2f890c2fdad230).(unsigned int shift_intensity) |
| 88 | { |
| 89 | this->m_shift_intensitycxx . . $ pixshift0r#m_shift_intensity. = shift_intensity; |
| 90 | |
| 91 | int64_t intensity = static_cast<int64_t>(shift_intensity); |
| 92 | |
| 93 | auto rng_params = decltypecxx . . $ std/uniform_int_distribution#param_type#param_type(249673c20e2b8d5).(this->m_shift_rng)::param_typecxx . . $ std/uniform_int_distribution#param_type#(-intensity, intensity); |
| 94 | |
| 95 | this->m_shift_rngcxx . . $ pixshift0r#m_shift_rng..paramcxx . . $ std/uniform_int_distribution#param(dc6881523d5f4776).(rng_params); |
| 96 | } |
| 97 | }; |
| 98 | |
| 99 | extern "C" { |
| 100 | #include <frei0r.h>cxx . . $ `<file>/include/frei0r.h`/ |
| 101 | |
| 102 | int f0r_init() |
| 103 | { |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | f0r_instance_t f0r_construct(unsigned int width, unsigned int height) |
| 108 | { |
| 109 | pixshift0rcxx . . $ pixshift0r# *instance = new pixshift0rcxx . . $ pixshift0r#(width, height); |
| 110 | |
| 111 | instance->set_shift_intensitycxx . . $ pixshift0r#set_shift_intensity(cb2f890c2fdad230).(width / 100); |
| 112 | instance->set_block_height_rangecxx . . $ pixshift0r#set_block_height_range(b4d55b1286ff73e8).(stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(1u, height / 100), stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(1u, height / 10)); |
| 113 | |
| 114 | return instance; |
| 115 | } |
| 116 | |
| 117 | void f0r_get_plugin_info(f0r_plugin_info_t *info) |
| 118 | { |
| 119 | info->name = "pixs0r"; |
| 120 | info->author = "xsbee"; |
| 121 | info->explanation = "Glitch image shifting rows to and fro"; |
| 122 | info->major_version = 1; |
| 123 | info->minor_version = 0; |
| 124 | info->frei0r_version = FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!; |
| 125 | |
| 126 | info->color_model = F0R_COLOR_MODEL_PACKED32cxx . . $ `include/frei0r.h:322:9`!; |
| 127 | info->plugin_type = F0R_PLUGIN_TYPE_FILTERcxx . . $ `include/frei0r.h:247:9`!; |
| 128 | info->num_params = 4; |
| 129 | } |
| 130 | |
| 131 | void f0r_get_param_info (f0r_param_info_t *info, int param_index) |
| 132 | { |
| 133 | switch (param_index) |
| 134 | { |
| 135 | case 0: |
| 136 | info->name = "shift_intensity"; |
| 137 | info->type = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 138 | info->explanation = "Aggressiveness of row/column-shifting"; |
| 139 | break; |
| 140 | |
| 141 | case 1: |
| 142 | info->name = "block_height"; |
| 143 | info->type = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 144 | info->explanation = "Height of each block whose shift is invariant (0 = random)"; |
| 145 | break; |
| 146 | |
| 147 | case 2: |
| 148 | info->name = "block_height_min"; |
| 149 | info->type = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 150 | info->explanation = "Minimum height of block (if random mode)"; |
| 151 | break; |
| 152 | |
| 153 | case 3: |
| 154 | info->name = "block_height_max"; |
| 155 | info->type = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 156 | info->explanation = "Maximum height of block (if random mode)"; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void f0r_get_param_value( |
| 162 | f0r_instance_t instance, |
| 163 | f0r_param_t param, |
| 164 | int param_index |
| 165 | ) |
| 166 | { |
| 167 | pixshift0rcxx . . $ pixshift0r#* context = (pixshift0rcxx . . $ pixshift0r#*)instance; |
| 168 | |
| 169 | switch (param_index) { |
| 170 | case 0: |
| 171 | *static_cast<double*>(param) = static_cast<double>(context->m_shift_intensitycxx . . $ pixshift0r#m_shift_intensity.) / context->m_widthcxx . . $ pixshift0r#m_width.; |
| 172 | break; |
| 173 | case 1: |
| 174 | *static_cast<double*>(param) = static_cast<double>(context->m_block_heightcxx . . $ pixshift0r#m_block_height.) / context->m_heightcxx . . $ pixshift0r#m_height.; |
| 175 | break; |
| 176 | case 2: |
| 177 | *static_cast<double*>(param) = static_cast<double>(context->m_block_height_mincxx . . $ pixshift0r#m_block_height_min.) / context->m_heightcxx . . $ pixshift0r#m_height.; |
| 178 | break; |
| 179 | case 3: |
| 180 | *static_cast<double*>(param) = static_cast<double>(context->m_block_height_maxcxx . . $ pixshift0r#m_block_height_max.) / context->m_heightcxx . . $ pixshift0r#m_height.; |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void f0r_set_param_value( |
| 186 | f0r_instance_t instance, |
| 187 | f0r_param_t param, |
| 188 | int param_index |
| 189 | ) |
| 190 | { |
| 191 | pixshift0rcxx . . $ pixshift0r#* context = (pixshift0rcxx . . $ pixshift0r#*)instance; |
| 192 | |
| 193 | switch (param_index) { |
| 194 | case 0: |
| 195 | context->set_shift_intensitycxx . . $ pixshift0r#set_shift_intensity(cb2f890c2fdad230). (*static_cast<double*>(param) * context->m_widthcxx . . $ pixshift0r#m_width.); |
| 196 | break; |
| 197 | case 1: |
| 198 | context->m_block_heightcxx . . $ pixshift0r#m_block_height. = *static_cast<double*>(param) * context->m_heightcxx . . $ pixshift0r#m_height.; |
| 199 | break; |
| 200 | case 2: |
| 201 | context->set_block_height_rangecxx . . $ pixshift0r#set_block_height_range(b4d55b1286ff73e8). (*static_cast<double*>(param) * context->m_heightcxx . . $ pixshift0r#m_height., context->m_block_height_maxcxx . . $ pixshift0r#m_block_height_max.); |
| 202 | break; |
| 203 | case 3: |
| 204 | context->set_block_height_rangecxx . . $ pixshift0r#set_block_height_range(b4d55b1286ff73e8). (context->m_block_height_mincxx . . $ pixshift0r#m_block_height_min., *static_cast<double*>(param) * context->m_heightcxx . . $ pixshift0r#m_height.); |
| 205 | break; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void f0r_update ( |
| 210 | f0r_instance_t instance, |
| 211 | double, |
| 212 | const uint32_tcxx . . $ uint32_t# *inframe, |
| 213 | uint32_tcxx . . $ uint32_t# *outframe |
| 214 | ) |
| 215 | { |
| 216 | static_cast<pixshift0rcxx . . $ pixshift0r#*>(instance)->processcxx . . $ pixshift0r#process(400e083a04eff154).(inframe, outframe); |
| 217 | } |
| 218 | |
| 219 | void f0r_deinit() {} |
| 220 | |
| 221 | void f0r_destruct (f0r_instance_t instance) |
| 222 | { |
| 223 | delete static_cast<pixshift0rcxx . . $ pixshift0r#*>(instance); |
| 224 | } |
| 225 | } |