| 1 | /* |
| 2 | This frei0r plugin generates isingnoise images |
| 3 | |
| 4 | Copyright (C) 2004 Georg Seidel <[email protected]> |
| 5 | |
| 6 | This library is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU Lesser General Public |
| 8 | License as published by the Free Software Foundation; either |
| 9 | version 2.1 of the License, or (at your option) any later version. |
| 10 | |
| 11 | This library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Lesser General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Lesser General Public |
| 17 | License along with this library; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <assert.h> |
| 23 | #include <math.h> |
| 24 | #include <string.h> |
| 25 | #if defined(_MSC_VER) |
| 26 | #define __STDC_LIMIT_MACROS |
| 27 | #endif /* _MSC_VER */ |
| 28 | #include "frei0r.h"cxx . . $ `<file>/include/frei0r.h`/ |
| 29 | |
| 30 | //------------------------------------------------------------------------- |
| 31 | |
| 32 | struct IsingFieldcxx . . $ IsingField# { |
| 33 | char* scxx . . $ IsingField#s.; |
| 34 | int xsizecxx . . $ IsingField#xsize.; |
| 35 | int ysizecxx . . $ IsingField#ysize.; |
| 36 | }; |
| 37 | |
| 38 | static void set_bfcxx . . $ set_bf(ba0adeb1a86b8d02).(uint32_tcxx . . $ uint32_t# bf[3], double t, double b, double s); |
| 39 | static void init_fieldcxx . . $ init_field(c71cc0fa96d8e752).(struct IsingFieldcxx . . $ IsingField#* f, int xsize, int ysize); |
| 40 | static void destroy_fieldcxx . . $ destroy_field(80a009ff43975502).(struct IsingFieldcxx . . $ IsingField#* f); |
| 41 | static void do_stepcxx . . $ do_step(959fd19580f0d723).(struct IsingFieldcxx . . $ IsingField#* f, uint32_tcxx . . $ uint32_t# bf[3]); |
| 42 | static void copy_fieldcxx . . $ copy_field(922532612043a1cb).(const struct IsingFieldcxx . . $ IsingField#* f, uint32_tcxx . . $ uint32_t#* framebuffer); |
| 43 | |
| 44 | //------------------------------------------------------------------------- |
| 45 | |
| 46 | #define MY_RAND_MAXcxx . . $ `src/generator/ising0r/ising0r.c:46:9`! UINT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:124:10`! |
| 47 | |
| 48 | static uint32_tcxx . . $ uint32_t# rnd_lcg1_xncxx . . $ rnd_lcg1_xn. = 1; |
| 49 | |
| 50 | inline static uint32_tcxx . . $ uint32_t# rnd_lcg1cxx . . $ rnd_lcg1(f0be770dcc0b0316).() |
| 51 | { |
| 52 | rnd_lcg1_xncxx . . $ rnd_lcg1_xn. *= 3039177861U; |
| 53 | |
| 54 | return rnd_lcg1_xncxx . . $ rnd_lcg1_xn.; |
| 55 | } |
| 56 | |
| 57 | #define my_randcxx . . $ `src/generator/ising0r/ising0r.c:57:9`!() rnd_lcg1() |
| 58 | |
| 59 | |
| 60 | typedef struct ising0r_instancecxx . . $ ising0r_instance# |
| 61 | { |
| 62 | unsigned int widthcxx . . $ ising0r_instance#width.; |
| 63 | unsigned int heightcxx . . $ ising0r_instance#height.; |
| 64 | |
| 65 | double tempcxx . . $ ising0r_instance#temp.; |
| 66 | double border_growthcxx . . $ ising0r_instance#border_growth.; |
| 67 | double spont_growthcxx . . $ ising0r_instance#spont_growth.; |
| 68 | |
| 69 | struct IsingFieldcxx . . $ IsingField# fcxx . . $ ising0r_instance#f.; |
| 70 | uint32_tcxx . . $ uint32_t# bfcxx . . $ ising0r_instance#bf.[3]; |
| 71 | } ising0r_instance_tcxx . . $ ising0r_instance_t#; |
| 72 | |
| 73 | int f0r_initcxx . . $ f0r_init(b126dc7c1de90089).() |
| 74 | { |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | void f0r_deinitcxx . . $ f0r_deinit(49f6e7a06ebc5aa8).() |
| 79 | { /* no initialization required */ } |
| 80 | |
| 81 | void f0r_get_plugin_infocxx . . $ f0r_get_plugin_info(35d753456c0ea59c).(f0r_plugin_info_tcxx . . $ f0r_plugin_info_t#* nois0rInfo) |
| 82 | { |
| 83 | nois0rInfo->namecxx . . $ f0r_plugin_info#name. = "Ising0r"; |
| 84 | nois0rInfo->authorcxx . . $ f0r_plugin_info#author. = "Gephex crew"; |
| 85 | nois0rInfo->plugin_typecxx . . $ f0r_plugin_info#plugin_type. = F0R_PLUGIN_TYPE_SOURCEcxx . . $ `include/frei0r.h:249:9`!; |
| 86 | nois0rInfo->color_modelcxx . . $ f0r_plugin_info#color_model. = F0R_COLOR_MODEL_PACKED32cxx . . $ `include/frei0r.h:322:9`!; |
| 87 | nois0rInfo->frei0r_versioncxx . . $ f0r_plugin_info#frei0r_version. = FREI0R_MAJOR_VERSIONcxx . . $ `include/frei0r.h:217:9`!; |
| 88 | nois0rInfo->major_versioncxx . . $ f0r_plugin_info#major_version. = 0; |
| 89 | nois0rInfo->minor_versioncxx . . $ f0r_plugin_info#minor_version. = 9; |
| 90 | nois0rInfo->num_paramscxx . . $ f0r_plugin_info#num_params. = 3; |
| 91 | nois0rInfo->explanationcxx . . $ f0r_plugin_info#explanation. = "Generates ising noise"; |
| 92 | } |
| 93 | |
| 94 | void f0r_get_param_infocxx . . $ f0r_get_param_info(a9f9aa7954cc4a37).(f0r_param_info_tcxx . . $ f0r_param_info_t#* info, int param_index) |
| 95 | { |
| 96 | switch (param_index) |
| 97 | { |
| 98 | case 0: |
| 99 | info->namecxx . . $ f0r_param_info#name. = "Temperature"; |
| 100 | info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 101 | info->explanationcxx . . $ f0r_param_info#explanation. = "Noise Temperature"; break; |
| 102 | case 1: |
| 103 | info->namecxx . . $ f0r_param_info#name. = "Border Growth"; |
| 104 | info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 105 | info->explanationcxx . . $ f0r_param_info#explanation. = "Border Growth"; break; |
| 106 | case 2: |
| 107 | info->namecxx . . $ f0r_param_info#name. = "Spontaneous Growth"; |
| 108 | info->typecxx . . $ f0r_param_info#type. = F0R_PARAM_DOUBLEcxx . . $ `include/frei0r.h:383:9`!; |
| 109 | info->explanationcxx . . $ f0r_param_info#explanation. = "Spontaneous Growth"; break; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | f0r_instance_tcxx . . $ f0r_instance_t# f0r_constructcxx . . $ f0r_construct(da3f471cd007a696).(unsigned int width, unsigned int height) |
| 114 | { |
| 115 | ising0r_instance_tcxx . . $ ising0r_instance_t#* inst = (ising0r_instance_tcxx . . $ ising0r_instance_t#*)calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*inst)); |
| 116 | inst->widthcxx . . $ ising0r_instance#width. = width; |
| 117 | inst->heightcxx . . $ ising0r_instance#height. = height; |
| 118 | |
| 119 | init_fieldcxx . . $ init_field(c71cc0fa96d8e752).(&inst->fcxx . . $ ising0r_instance#f., width, height); |
| 120 | |
| 121 | return (f0r_instance_tcxx . . $ f0r_instance_t#)inst; |
| 122 | } |
| 123 | |
| 124 | void f0r_destructcxx . . $ f0r_destruct(5d22bdacc48458e8).(f0r_instance_tcxx . . $ f0r_instance_t# instance) |
| 125 | { |
| 126 | ising0r_instance_tcxx . . $ ising0r_instance_t#* inst = (ising0r_instance_tcxx . . $ ising0r_instance_t#*)instance; |
| 127 | destroy_fieldcxx . . $ destroy_field(80a009ff43975502).(&inst->fcxx . . $ ising0r_instance#f.); |
| 128 | freecxx . . $ free(5d22bdacc48458e8).(inst); |
| 129 | } |
| 130 | |
| 131 | void f0r_set_param_valuecxx . . $ f0r_set_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance, |
| 132 | f0r_param_tcxx . . $ f0r_param_t# param, int param_index) |
| 133 | { |
| 134 | ising0r_instance_tcxx . . $ ising0r_instance_t#* inst = (ising0r_instance_tcxx . . $ ising0r_instance_t#*)instance; |
| 135 | |
| 136 | f0r_param_doublecxx . . $ f0r_param_double#* p = (f0r_param_doublecxx . . $ f0r_param_double#*) param; |
| 137 | |
| 138 | switch (param_index) |
| 139 | { |
| 140 | case 0: |
| 141 | inst->tempcxx . . $ ising0r_instance#temp. = *p *6; break; |
| 142 | case 1: |
| 143 | inst->border_growthcxx . . $ ising0r_instance#border_growth. = (1.0 - *p)*100; break; |
| 144 | case 2: |
| 145 | inst->spont_growthcxx . . $ ising0r_instance#spont_growth. = (1.0 - *p)*100; break; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void f0r_get_param_valuecxx . . $ f0r_get_param_value(5be095a8278d2bf5).(f0r_instance_tcxx . . $ f0r_instance_t# instance, |
| 150 | f0r_param_tcxx . . $ f0r_param_t# param, int param_index) |
| 151 | { |
| 152 | ising0r_instance_tcxx . . $ ising0r_instance_t#* inst = (ising0r_instance_tcxx . . $ ising0r_instance_t#*)instance; |
| 153 | |
| 154 | f0r_param_doublecxx . . $ f0r_param_double#* p = (f0r_param_doublecxx . . $ f0r_param_double#*) param; |
| 155 | |
| 156 | switch (param_index) |
| 157 | { |
| 158 | case 0: |
| 159 | *p = inst->tempcxx . . $ ising0r_instance#temp. / 6; break; |
| 160 | case 1: |
| 161 | *p = 1.0 - inst->border_growthcxx . . $ ising0r_instance#border_growth. / 100; break; |
| 162 | case 2: |
| 163 | *p = 1.0 - inst->spont_growthcxx . . $ ising0r_instance#spont_growth. / 100; break; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | |
| 168 | void f0r_updatecxx . . $ f0r_update(96cd7b27f2fca8a7).(f0r_instance_tcxx . . $ f0r_instance_t# instance, double time, |
| 169 | const uint32_tcxx . . $ uint32_t#* inframe, uint32_tcxx . . $ uint32_t#* outframe) |
| 170 | { |
| 171 | assertcxx . . $ `<external>/4398592474888995393/assert.h:77:11`!(instance); |
| 172 | ising0r_instance_tcxx . . $ ising0r_instance_t#* inst = (ising0r_instance_tcxx . . $ ising0r_instance_t#*)instance; |
| 173 | |
| 174 | set_bfcxx . . $ set_bf(ba0adeb1a86b8d02).(inst->bfcxx . . $ ising0r_instance#bf., inst->tempcxx . . $ ising0r_instance#temp., inst->border_growthcxx . . $ ising0r_instance#border_growth., inst->spont_growthcxx . . $ ising0r_instance#spont_growth.); |
| 175 | |
| 176 | do_stepcxx . . $ do_step(959fd19580f0d723).(&inst->fcxx . . $ ising0r_instance#f., inst->bfcxx . . $ ising0r_instance#bf.); |
| 177 | |
| 178 | copy_fieldcxx . . $ copy_field(922532612043a1cb).(&inst->fcxx . . $ ising0r_instance#f., outframe); |
| 179 | } |
| 180 | |
| 181 | //------------------------------------------------------------------------- |
| 182 | |
| 183 | static void set_bfcxx . . $ set_bf(ba0adeb1a86b8d02).(uint32_tcxx . . $ uint32_t# bf[3], double t, double b, double s) |
| 184 | { |
| 185 | /* { |
| 186 | char buffer[128]; |
| 187 | |
| 188 | snprintf(buffer, sizeof(buffer), "Changing bf: (t,b,s)=(%f,%f,%f)\n", |
| 189 | t, b, s); |
| 190 | |
| 191 | s_log(2, buffer); |
| 192 | }*/ |
| 193 | |
| 194 | bf[0] = (uint32_tcxx . . $ uint32_t#) (0.5 * MY_RAND_MAXcxx . . $ `src/generator/ising0r/ising0r.c:46:9`!); |
| 195 | |
| 196 | if (t > 0) |
| 197 | { |
| 198 | bf[1] = (uint32_tcxx . . $ uint32_t#) (exp(-b/t)*MY_RAND_MAXcxx . . $ `src/generator/ising0r/ising0r.c:46:9`!); |
| 199 | bf[2] = (uint32_tcxx . . $ uint32_t#) (exp(-s/t)*MY_RAND_MAXcxx . . $ `src/generator/ising0r/ising0r.c:46:9`!); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | bf[1] = bf[2] = 0; |
| 204 | } |
| 205 | |
| 206 | } |
| 207 | |
| 208 | static void init_fieldcxx . . $ init_field(c71cc0fa96d8e752).(struct IsingFieldcxx . . $ IsingField#* f, int xsize, int ysize) |
| 209 | { |
| 210 | int x, y; |
| 211 | f->scxx . . $ IsingField#s. = (char*) malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(xsize*ysize); |
| 212 | |
| 213 | f->xsizecxx . . $ IsingField#xsize. = xsize; |
| 214 | f->ysizecxx . . $ IsingField#ysize. = ysize; |
| 215 | |
| 216 | // memset( |
| 217 | |
| 218 | for (y = 1; y < ysize-1; ++y) |
| 219 | { |
| 220 | int y_base = y*xsize; |
| 221 | for (x = 1; x < xsize-1; ++x) |
| 222 | { |
| 223 | f->scxx . . $ IsingField#s.[x + y_base] = (my_randcxx . . $ `src/generator/ising0r/ising0r.c:57:9`!() < MY_RAND_MAXcxx . . $ `src/generator/ising0r/ising0r.c:46:9`!/2) ? -1 : 1; |
| 224 | } |
| 225 | f->scxx . . $ IsingField#s.[y_base] = f->scxx . . $ IsingField#s.[xsize-1 + y_base] = 1; |
| 226 | } |
| 227 | |
| 228 | // set first and last line to black |
| 229 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(f->scxx . . $ IsingField#s., 1, xsize); |
| 230 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(f->scxx . . $ IsingField#s. + (ysize-1)*xsize, 1, xsize); |
| 231 | } |
| 232 | |
| 233 | static void destroy_fieldcxx . . $ destroy_field(80a009ff43975502).(struct IsingFieldcxx . . $ IsingField#* f) |
| 234 | { |
| 235 | if (f->scxx . . $ IsingField#s. != 0) |
| 236 | { |
| 237 | freecxx . . $ free(5d22bdacc48458e8).(f->scxx . . $ IsingField#s.); |
| 238 | f->scxx . . $ IsingField#s. = 0; |
| 239 | // plain paranoia... |
| 240 | f->xsizecxx . . $ IsingField#xsize. = 0; |
| 241 | f->ysizecxx . . $ IsingField#ysize. = 0; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | static void do_stepcxx . . $ do_step(959fd19580f0d723).(struct IsingFieldcxx . . $ IsingField#* f, uint32_tcxx . . $ uint32_t# bf[3]) |
| 246 | { |
| 247 | int x, y; |
| 248 | int xsize = f->xsizecxx . . $ IsingField#xsize.; |
| 249 | int ysize = f->ysizecxx . . $ IsingField#ysize.; |
| 250 | |
| 251 | // start on second pixel of the second line (f->s[1][1]): |
| 252 | int8_tcxx . . $ int8_t#* current = f->scxx . . $ IsingField#s. + xsize + 1; |
| 253 | |
| 254 | for (y = ysize-2; y > 0; --y) |
| 255 | { |
| 256 | for (x = xsize-2; x > 0; --x) |
| 257 | { |
| 258 | int sum = |
| 259 | current[-xsize] + current[xsize] + |
| 260 | current[-1] + current[1]; |
| 261 | |
| 262 | int e = *current * sum; |
| 263 | |
| 264 | if (e < 0 || my_randcxx . . $ `src/generator/ising0r/ising0r.c:57:9`!() < bf[e>>1]) |
| 265 | { |
| 266 | *current *= -1; |
| 267 | } |
| 268 | |
| 269 | ++current; |
| 270 | } |
| 271 | // skip last pixel of this line and first pixel of next line: |
| 272 | current += 2; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | static void copy_fieldcxx . . $ copy_field(922532612043a1cb).(const struct IsingFieldcxx . . $ IsingField#* f, uint32_tcxx . . $ uint32_t#* framebuffer) |
| 277 | { |
| 278 | int i; |
| 279 | char* s = f->scxx . . $ IsingField#s.; |
| 280 | uint32_tcxx . . $ uint32_t#* fr = framebuffer; |
| 281 | |
| 282 | for (i = (f->xsizecxx . . $ IsingField#xsize.)*(f->ysizecxx . . $ IsingField#ysize.)-1; i >= 0; --i) |
| 283 | { |
| 284 | *(fr++) = *(s++); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | //------------------------------------------------------------------------- |
| 289 |