| 1 |
|
| #include "regmach.h" |
| 2 |
|
| #include <float.h> |
| 3 |
|
| #include "imageri.h" |
| 4 |
|
| |
| 5 |
|
| /*#define DEBUG*/ |
| 6 |
|
| #ifdef DEBUG |
| 7 |
|
| #define DBG(x) printf x |
| 8 |
|
| #else |
| 9 |
|
| #define DBG(x) |
| 10 |
|
| #endif |
| 11 |
|
| |
| 12 |
|
| static float MAX_EXP_ARG; /* = log(DBL_MAX); */ |
| 13 |
|
| |
| 14 |
|
| |
| 15 |
|
| /* these functions currently assume RGB images - there seems to be some |
| 16 |
|
| support for other color spaces, but I can't tell how you find what |
| 17 |
|
| space an image is using. |
| 18 |
|
| |
| 19 |
|
| HSV conversions from pages 401-403 "Procedural Elements for Computer |
| 20 |
|
| Graphics", 1985, ISBN 0-07-053534-5. The algorithm presents to produce |
| 21 |
|
| an HSV color calculates all components at once - I don't, so I've |
| 22 |
|
| simiplified the algorithm to avoid unnecessary calculation (any errors |
| 23 |
|
| (of which I had a few ;) are mine). |
| 24 |
|
| */ |
| 25 |
|
| |
| 26 |
|
| /* returns the value (brightness) of color from 0 to 1 */ |
| 27 |
1 |
| static double hsv_value(i_color color) { |
| 28 |
1 |
| return i_max(i_max(color.rgb.r, color.rgb.g), color.rgb.b) / 255.0; |
| 29 |
|
| } |
| 30 |
|
| |
| 31 |
|
| /* returns the hue (color) of color from 0 to 360 */ |
| 32 |
1 |
| static double hsv_hue(i_color color) { |
| 33 |
|
| int val; |
| 34 |
|
| int temp; |
| 35 |
1 |
| temp = i_min(i_min(color.rgb.r, color.rgb.g), color.rgb.b); |
| 36 |
1 |
| val = i_max(color.rgb.r, i_max(color.rgb.g, color.rgb.b)); |
| 37 |
1 |
▶ | if (val == 0 || val==temp) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (val == 0 || val==temp) { |
1 |
0 |
1 |
| if (val == 0 || val==temp) { |
0 |
1 |
1 |
|
| 38 |
0 |
| return 0; |
| 39 |
|
| } |
| 40 |
|
| else { |
| 41 |
1 |
| double cr = (val - color.rgb.r) / (double)(val - temp); |
| 42 |
1 |
| double cg = (val - color.rgb.g) / (double)(val - temp); |
| 43 |
1 |
| double cb = (val - color.rgb.b) / (double)(val - temp); |
| 44 |
|
| double hue; |
| 45 |
1 |
▶ | if (color.rgb.r == val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (color.rgb.r == val) { |
1 |
0 |
1 |
|
| 46 |
1 |
| hue = cb-cg; |
| 47 |
|
| } |
| 48 |
0 |
▶ | else if (color.rgb.g == val) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (color.rgb.g == val) { |
0 |
0 |
0 |
|
| 49 |
0 |
| hue = 2.0 + cr-cb; |
| 50 |
|
| } |
| 51 |
|
| else { /* if (blue == val) */ |
| 52 |
0 |
| hue = 4.0 + cg - cr; |
| 53 |
|
| } |
| 54 |
1 |
| hue *= 60.0; /* to degrees */ |
| 55 |
1 |
▶ | if (hue < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hue < 0) |
0 |
1 |
1 |
|
| 56 |
0 |
| hue += 360; |
| 57 |
|
| |
| 58 |
1 |
| return hue; |
| 59 |
|
| } |
| 60 |
|
| } |
| 61 |
|
| |
| 62 |
|
| /* return the saturation of color from 0 to 1 */ |
| 63 |
2 |
| static double hsv_sat(i_color color) { |
| 64 |
2 |
| int value = i_max(i_max(color.rgb.r, color.rgb.g), color.rgb.b); |
| 65 |
2 |
▶ | if (value == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (value == 0) { |
0 |
2 |
2 |
|
| 66 |
0 |
| return 0; |
| 67 |
|
| } |
| 68 |
|
| else { |
| 69 |
2 |
| int temp = i_min(i_min(color.rgb.r, color.rgb.g), color.rgb.b); |
| 70 |
2 |
| return (value - temp) / (double)value; |
| 71 |
|
| } |
| 72 |
|
| } |
| 73 |
|
| |
| 74 |
90004 |
| static i_color make_hsv(double hue, double sat, double val, int alpha) { |
| 75 |
|
| int i; |
| 76 |
|
| i_color c; |
| 77 |
450020 |
▶ | for( i=0; i< MAXCHANNELS; i++) c.channel[i]=0; |
Branch: 1 branch
| Branch | True | False | Total |
| for( i=0; i< MAXCHANNELS; i++) c.channel[i]=0; |
360016 |
90004 |
450020 |
|
| 78 |
|
| DBG(("hsv=%f %f %f\n", hue, sat, val)); |
| 79 |
90004 |
▶ | if (sat <= 0) { /* handle -ve in case someone supplies a bad value */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (sat <= 0) { /* handle -ve in case someone supplies a bad value */ |
1 |
90003 |
90004 |
|
| 80 |
|
| /* should this be * 256? */ |
| 81 |
1 |
| c.rgb.r = c.rgb.g = c.rgb.b = 255 * val; |
| 82 |
|
| } |
| 83 |
|
| else { |
| 84 |
|
| int i, m, n, k, v; |
| 85 |
|
| double f; |
| 86 |
|
| |
| 87 |
90003 |
▶ | if (val < 0) val = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (val < 0) val = 0; |
0 |
90003 |
90003 |
|
| 88 |
90003 |
▶ | if (val > 1) val = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (val > 1) val = 1; |
0 |
90003 |
90003 |
|
| 89 |
90003 |
▶ | if (sat > 1) sat = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (sat > 1) sat = 1; |
0 |
90003 |
90003 |
|
| 90 |
|
| |
| 91 |
|
| /* I want to handle -360 <= hue < 720 so that the caller can |
| 92 |
|
| fiddle with colour |
| 93 |
|
| */ |
| 94 |
90003 |
▶ | if (hue >= 360) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hue >= 360) |
0 |
90003 |
90003 |
|
| 95 |
0 |
| hue -= 360; |
| 96 |
90003 |
▶ | else if (hue < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (hue < 0) |
501 |
89502 |
90003 |
|
| 97 |
501 |
| hue += 360; |
| 98 |
90003 |
| hue /= 60; |
| 99 |
90003 |
| i = hue; /* floor */ |
| 100 |
90003 |
| f = hue - i; |
| 101 |
90003 |
| val *= 255; |
| 102 |
90003 |
| m = val * (1.0 - sat); |
| 103 |
90003 |
| n = val * (1.0 - sat * f); |
| 104 |
90003 |
| k = val * (1.0 - sat * (1 - f)); |
| 105 |
90003 |
| v = val; |
| 106 |
90003 |
| switch (i) { |
| 107 |
18075 |
| case 0: |
| 108 |
18075 |
| c.rgb.r = v; c.rgb.g = k; c.rgb.b = m; |
| 109 |
18075 |
| break; |
| 110 |
18045 |
| case 1: |
| 111 |
18045 |
| c.rgb.r = n; c.rgb.g = v; c.rgb.b = m; |
| 112 |
18045 |
| break; |
| 113 |
17912 |
| case 2: |
| 114 |
17912 |
| c.rgb.r = m; c.rgb.g = v; c.rgb.b = k; |
| 115 |
17912 |
| break; |
| 116 |
17830 |
| case 3: |
| 117 |
17830 |
| c.rgb.r = m; c.rgb.g = n; c.rgb.b = v; |
| 118 |
17830 |
| break; |
| 119 |
17743 |
| case 4: |
| 120 |
17743 |
| c.rgb.r = k; c.rgb.g = m; c.rgb.b = v; |
| 121 |
17743 |
| break; |
| 122 |
398 |
| case 5: |
| 123 |
398 |
| c.rgb.r = v; c.rgb.g = m; c.rgb.b = n; |
| 124 |
398 |
| break; |
| 125 |
|
| } |
| 126 |
|
| } |
| 127 |
90004 |
| c.rgba.a = alpha; |
| 128 |
|
| |
| 129 |
90004 |
| return c; |
| 130 |
|
| } |
| 131 |
|
| |
| 132 |
91080 |
| static i_color make_rgb(int r, int g, int b, int a) { |
| 133 |
|
| i_color c; |
| 134 |
91080 |
▶ | if (r < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r < 0) |
0 |
91080 |
91080 |
|
| 135 |
0 |
| r = 0; |
| 136 |
91080 |
▶ | if (r > 255) |
Branch: 1 branch
| Branch | True | False | Total |
| if (r > 255) |
0 |
91080 |
91080 |
|
| 137 |
0 |
| r = 255; |
| 138 |
91080 |
| c.rgb.r = r; |
| 139 |
91080 |
▶ | if (g < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (g < 0) |
0 |
91080 |
91080 |
|
| 140 |
0 |
| g = 0; |
| 141 |
91080 |
▶ | if (g > 255) |
Branch: 1 branch
| Branch | True | False | Total |
| if (g > 255) |
0 |
91080 |
91080 |
|
| 142 |
0 |
| g = 255; |
| 143 |
91080 |
| c.rgb.g = g; |
| 144 |
91080 |
▶ | if (b < 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (b < 0) |
0 |
91080 |
91080 |
|
| 145 |
0 |
| b = 0; |
| 146 |
91080 |
▶ | if (b > 255) |
Branch: 1 branch
| Branch | True | False | Total |
| if (b > 255) |
0 |
91080 |
91080 |
|
| 147 |
0 |
| b = 255; |
| 148 |
91080 |
| c.rgb.b = b; |
| 149 |
|
| |
| 150 |
91080 |
| c.rgba.a = a; |
| 151 |
|
| |
| 152 |
91080 |
| return c; |
| 153 |
|
| } |
| 154 |
|
| |
| 155 |
|
| /* greatly simplifies the code */ |
| 156 |
|
| #define nout n_regs[codes->rout] |
| 157 |
|
| #define na n_regs[codes->ra] |
| 158 |
|
| #define nb n_regs[codes->rb] |
| 159 |
|
| #define nc n_regs[codes->rc] |
| 160 |
|
| #define nd n_regs[codes->rd] |
| 161 |
|
| #define cout c_regs[codes->rout] |
| 162 |
|
| #define ca c_regs[codes->ra] |
| 163 |
|
| #define cb c_regs[codes->rb] |
| 164 |
|
| #define cc c_regs[codes->rc] |
| 165 |
|
| #define cd c_regs[codes->rd] |
| 166 |
|
| |
| 167 |
|
| /* this is a pretty poor epsilon used for loosening up equality comparisons |
| 168 |
|
| It isn't currently used for inequalities |
| 169 |
|
| */ |
| 170 |
|
| |
| 171 |
|
| #define n_epsilon(x, y) (fabs(x)+fabs(y))*0.001 |
| 172 |
|
| static i_color bcol = {{ 0 }}; |
| 173 |
|
| |
| 174 |
181082 |
| i_color i_rm_run(struct rm_op codes[], size_t code_count, |
| 175 |
|
| double n_regs[], size_t n_regs_count, |
| 176 |
|
| i_color c_regs[], size_t c_regs_count, |
| 177 |
|
| i_img *images[], size_t image_count) { |
| 178 |
|
| double dx, dy; |
| 179 |
181082 |
| struct rm_op *codes_base = codes; |
| 180 |
181082 |
| size_t count_base = code_count; |
| 181 |
|
| |
| 182 |
|
| /* FIXME: add a separate function to validate the code block against |
| 183 |
|
| the number of registers and images |
| 184 |
|
| */ |
| 185 |
|
| (void)n_regs_count; |
| 186 |
|
| (void)c_regs_count; |
| 187 |
|
| (void)image_count; |
| 188 |
|
| |
| 189 |
|
| DBG(("rm_run(%p, %d)\n", codes, code_count)); |
| 190 |
2076111 |
▶ | while (code_count) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (code_count) { |
2076111 |
0 |
2076111 |
|
| 191 |
|
| DBG((" rm_code %d\n", codes->code)); |
| 192 |
2076111 |
| switch (codes->code) { |
| 193 |
273566 |
| case rbc_add: |
| 194 |
273566 |
| nout = na + nb; |
| 195 |
273566 |
| break; |
| 196 |
|
| |
| 197 |
212021 |
| case rbc_subtract: |
| 198 |
212021 |
| nout = na - nb; |
| 199 |
212021 |
| break; |
| 200 |
|
| |
| 201 |
600114 |
| case rbc_mult: |
| 202 |
600114 |
| nout = na * nb; |
| 203 |
600114 |
| break; |
| 204 |
|
| |
| 205 |
2500 |
| case rbc_div: |
| 206 |
2500 |
▶ | if (fabs(nb) < 1e-10) |
Branch: 1 branch
| Branch | True | False | Total |
| if (fabs(nb) < 1e-10) |
0 |
2500 |
2500 |
|
| 207 |
0 |
| nout = 1e10; |
| 208 |
|
| else |
| 209 |
2500 |
| nout = na / nb; |
| 210 |
2500 |
| break; |
| 211 |
|
| |
| 212 |
149041 |
| case rbc_mod: |
| 213 |
149041 |
▶ | if (fabs(nb) > 1e-10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (fabs(nb) > 1e-10) { |
149041 |
0 |
149041 |
|
| 214 |
149041 |
| nout = fmod(na, nb); |
| 215 |
|
| } |
| 216 |
|
| else { |
| 217 |
0 |
| nout = 0; /* close enough ;) */ |
| 218 |
|
| } |
| 219 |
149041 |
| break; |
| 220 |
|
| |
| 221 |
2 |
| case rbc_pow: |
| 222 |
2 |
| nout = pow(na, nb); |
| 223 |
2 |
| break; |
| 224 |
|
| |
| 225 |
1 |
| case rbc_uminus: |
| 226 |
1 |
| nout = -na; |
| 227 |
1 |
| break; |
| 228 |
|
| |
| 229 |
59041 |
| case rbc_multp: |
| 230 |
59041 |
| cout = make_rgb(ca.rgb.r * nb, ca.rgb.g * nb, ca.rgb.b * nb, 255); |
| 231 |
59041 |
| break; |
| 232 |
|
| |
| 233 |
29521 |
| case rbc_addp: |
| 234 |
29521 |
| cout = make_rgb(ca.rgb.r + cb.rgb.r, ca.rgb.g + cb.rgb.g, |
| 235 |
29521 |
| ca.rgb.b + cb.rgb.b, 255); |
| 236 |
29521 |
| break; |
| 237 |
|
| |
| 238 |
1 |
| case rbc_subtractp: |
| 239 |
1 |
| cout = make_rgb(ca.rgb.r - cb.rgb.r, ca.rgb.g - cb.rgb.g, |
| 240 |
1 |
| ca.rgb.b - cb.rgb.b, 255); |
| 241 |
1 |
| break; |
| 242 |
|
| |
| 243 |
119521 |
| case rbc_sin: |
| 244 |
119521 |
| nout = sin(na); |
| 245 |
119521 |
| break; |
| 246 |
|
| |
| 247 |
1 |
| case rbc_cos: |
| 248 |
1 |
| nout = cos(na); |
| 249 |
1 |
| break; |
| 250 |
|
| |
| 251 |
90001 |
| case rbc_atan2: |
| 252 |
90001 |
| nout = atan2(na, nb); |
| 253 |
90001 |
| break; |
| 254 |
|
| |
| 255 |
1 |
| case rbc_sqrt: |
| 256 |
1 |
| nout = sqrt(na); |
| 257 |
1 |
| break; |
| 258 |
|
| |
| 259 |
90001 |
| case rbc_distance: |
| 260 |
90001 |
| dx = na-nc; |
| 261 |
90001 |
| dy = nb-nd; |
| 262 |
90001 |
| nout = sqrt(dx*dx+dy*dy); |
| 263 |
90001 |
| break; |
| 264 |
|
| |
| 265 |
88574 |
| case rbc_getp1: |
| 266 |
88574 |
| i_gpix(images[0], na, nb, c_regs+codes->rout); |
| 267 |
88574 |
▶ | if (images[0]->channels < 4) cout.rgba.a = 255; |
Branch: 1 branch
| Branch | True | False | Total |
| if (images[0]->channels < 4) cout.rgba.a = 255; |
88574 |
0 |
88574 |
|
| 268 |
88574 |
| break; |
| 269 |
|
| |
| 270 |
29520 |
| case rbc_getp2: |
| 271 |
29520 |
| i_gpix(images[1], na, nb, c_regs+codes->rout); |
| 272 |
29520 |
▶ | if (images[1]->channels < 4) cout.rgba.a = 255; |
Branch: 1 branch
| Branch | True | False | Total |
| if (images[1]->channels < 4) cout.rgba.a = 255; |
29520 |
0 |
29520 |
|
| 273 |
29520 |
| break; |
| 274 |
|
| |
| 275 |
0 |
| case rbc_getp3: |
| 276 |
0 |
| i_gpix(images[2], na, nb, c_regs+codes->rout); |
| 277 |
0 |
▶ | if (images[2]->channels < 4) cout.rgba.a = 255; |
Branch: 1 branch
| Branch | True | False | Total |
| if (images[2]->channels < 4) cout.rgba.a = 255; |
0 |
0 |
0 |
|
| 278 |
0 |
| break; |
| 279 |
|
| |
| 280 |
1 |
| case rbc_value: |
| 281 |
1 |
| nout = hsv_value(ca); |
| 282 |
1 |
| break; |
| 283 |
|
| |
| 284 |
1 |
| case rbc_hue: |
| 285 |
1 |
| nout = hsv_hue(ca); |
| 286 |
1 |
| break; |
| 287 |
|
| |
| 288 |
2 |
| case rbc_sat: |
| 289 |
2 |
| nout = hsv_sat(ca); |
| 290 |
2 |
| break; |
| 291 |
|
| |
| 292 |
90004 |
| case rbc_hsv: |
| 293 |
90004 |
| cout = make_hsv(na, nb, nc, 255); |
| 294 |
90004 |
| break; |
| 295 |
|
| |
| 296 |
0 |
| case rbc_hsva: |
| 297 |
0 |
| cout = make_hsv(na, nb, nc, nd); |
| 298 |
0 |
| break; |
| 299 |
|
| |
| 300 |
6 |
| case rbc_red: |
| 301 |
6 |
| nout = ca.rgb.r; |
| 302 |
6 |
| break; |
| 303 |
|
| |
| 304 |
6 |
| case rbc_green: |
| 305 |
6 |
| nout = ca.rgb.g; |
| 306 |
6 |
| break; |
| 307 |
|
| |
| 308 |
4 |
| case rbc_blue: |
| 309 |
4 |
| nout = ca.rgb.b; |
| 310 |
4 |
| break; |
| 311 |
|
| |
| 312 |
0 |
| case rbc_alpha: |
| 313 |
0 |
| nout = ca.rgba.a; |
| 314 |
0 |
| break; |
| 315 |
|
| |
| 316 |
17 |
| case rbc_rgb: |
| 317 |
17 |
| cout = make_rgb(na, nb, nc, 255); |
| 318 |
17 |
| break; |
| 319 |
|
| |
| 320 |
2500 |
| case rbc_rgba: |
| 321 |
2500 |
| cout = make_rgb(na, nb, nc, nd); |
| 322 |
2500 |
| break; |
| 323 |
|
| |
| 324 |
1 |
| case rbc_int: |
| 325 |
1 |
| nout = (int)(na); |
| 326 |
1 |
| break; |
| 327 |
|
| |
| 328 |
2 |
| case rbc_if: |
| 329 |
2 |
▶ | nout = na ? nb : nc; |
Branch: 1 branch
| Branch | True | False | Total |
| nout = na ? nb : nc; |
1 |
1 |
2 |
|
| 330 |
2 |
| break; |
| 331 |
|
| |
| 332 |
1 |
| case rbc_ifp: |
| 333 |
1 |
▶ | cout = na ? cb : cc; |
Branch: 1 branch
| Branch | True | False | Total |
| cout = na ? cb : cc; |
0 |
1 |
1 |
|
| 334 |
1 |
| break; |
| 335 |
|
| |
| 336 |
1 |
| case rbc_le: |
| 337 |
1 |
▶ | nout = na <= nb + n_epsilon(na,nb); |
Branch: 1 branch
| Branch | True | False | Total |
| nout = na <= nb + n_epsilon(na,nb); |
1 |
0 |
1 |
|
| 338 |
1 |
| break; |
| 339 |
|
| |
| 340 |
1 |
| case rbc_lt: |
| 341 |
1 |
▶ | nout = na < nb; |
Branch: 1 branch
| Branch | True | False | Total |
| nout = na < nb; |
0 |
1 |
1 |
|
| 342 |
1 |
| break; |
| 343 |
|
| |
| 344 |
1 |
| case rbc_ge: |
| 345 |
1 |
▶ | nout = na >= nb - n_epsilon(na,nb); |
Branch: 1 branch
| Branch | True | False | Total |
| nout = na >= nb - n_epsilon(na,nb); |
0 |
1 |
1 |
|
| 346 |
1 |
| break; |
| 347 |
|
| |
| 348 |
1 |
| case rbc_gt: |
| 349 |
1 |
▶ | nout = na > nb; |
Branch: 1 branch
| Branch | True | False | Total |
| nout = na > nb; |
1 |
0 |
1 |
|
| 350 |
1 |
| break; |
| 351 |
|
| |
| 352 |
1 |
| case rbc_eq: |
| 353 |
1 |
▶ | nout = fabs(na-nb) <= n_epsilon(na,nb); |
Branch: 1 branch
| Branch | True | False | Total |
| nout = fabs(na-nb) <= n_epsilon(na,nb); |
1 |
0 |
1 |
|
| 354 |
1 |
| break; |
| 355 |
|
| |
| 356 |
1 |
| case rbc_ne: |
| 357 |
1 |
▶ | nout = fabs(na-nb) > n_epsilon(na,nb); |
Branch: 1 branch
| Branch | True | False | Total |
| nout = fabs(na-nb) > n_epsilon(na,nb); |
0 |
1 |
1 |
|
| 358 |
1 |
| break; |
| 359 |
|
| |
| 360 |
1 |
| case rbc_and: |
| 361 |
1 |
▶ | nout = na && nb; |
Branch: 2 branches
| Branch | True | False | Total |
| nout = na && nb; |
1 |
0 |
1 |
| nout = na && nb; |
0 |
1 |
1 |
|
| 362 |
1 |
| break; |
| 363 |
|
| |
| 364 |
1 |
| case rbc_or: |
| 365 |
1 |
▶ | nout = na || nb; |
Branch: 2 branches
| Branch | True | False | Total |
| nout = na || nb; |
0 |
1 |
1 |
| nout = na || nb; |
0 |
0 |
0 |
|
| 366 |
1 |
| break; |
| 367 |
|
| |
| 368 |
1 |
| case rbc_not: |
| 369 |
1 |
▶ | nout = !na; |
Branch: 1 branch
| Branch | True | False | Total |
| nout = !na; |
1 |
0 |
1 |
|
| 370 |
1 |
| break; |
| 371 |
|
| |
| 372 |
3 |
| case rbc_abs: |
| 373 |
3 |
| nout = fabs(na); |
| 374 |
3 |
| break; |
| 375 |
|
| |
| 376 |
181082 |
| case rbc_ret: |
| 377 |
181082 |
| return ca; |
| 378 |
|
| break; |
| 379 |
|
| |
| 380 |
0 |
| case rbc_jump: |
| 381 |
|
| /* yes, order is important here */ |
| 382 |
0 |
| code_count = count_base - codes->ra; |
| 383 |
0 |
| codes = codes_base + codes->ra; |
| 384 |
0 |
| continue; |
| 385 |
|
| |
| 386 |
0 |
| case rbc_jumpz: |
| 387 |
0 |
▶ | if (!na) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!na) { |
0 |
0 |
0 |
|
| 388 |
|
| /* yes, order is important here */ |
| 389 |
0 |
| code_count = count_base - codes->rb; |
| 390 |
0 |
| codes = codes_base + codes->rb; |
| 391 |
0 |
| continue; |
| 392 |
|
| } |
| 393 |
0 |
| break; |
| 394 |
|
| |
| 395 |
0 |
| case rbc_jumpnz: |
| 396 |
0 |
▶ | if (na) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (na) { |
0 |
0 |
0 |
|
| 397 |
|
| /* yes, order is important here */ |
| 398 |
0 |
| code_count = count_base - codes->rb; |
| 399 |
0 |
| codes = codes_base + codes->rb; |
| 400 |
0 |
| continue; |
| 401 |
|
| } |
| 402 |
0 |
| break; |
| 403 |
|
| |
| 404 |
0 |
| case rbc_set: |
| 405 |
0 |
| nout = na; |
| 406 |
0 |
| break; |
| 407 |
|
| |
| 408 |
0 |
| case rbc_setp: |
| 409 |
0 |
| cout = ca; |
| 410 |
0 |
| break; |
| 411 |
|
| |
| 412 |
59041 |
| case rbc_log: |
| 413 |
59041 |
▶ | if (na > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (na > 0) { |
59041 |
0 |
59041 |
|
| 414 |
59041 |
| nout = log(na); |
| 415 |
|
| } |
| 416 |
|
| else { |
| 417 |
0 |
| nout = DBL_MAX; |
| 418 |
|
| } |
| 419 |
59041 |
| break; |
| 420 |
|
| |
| 421 |
2 |
| case rbc_exp: |
| 422 |
2 |
▶ | if (!MAX_EXP_ARG) MAX_EXP_ARG = log(DBL_MAX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!MAX_EXP_ARG) MAX_EXP_ARG = log(DBL_MAX); |
1 |
1 |
2 |
|
| 423 |
2 |
▶ | if (na <= MAX_EXP_ARG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (na <= MAX_EXP_ARG) { |
2 |
0 |
2 |
|
| 424 |
2 |
| nout = exp(na); |
| 425 |
|
| } |
| 426 |
|
| else { |
| 427 |
0 |
| nout = DBL_MAX; |
| 428 |
|
| } |
| 429 |
2 |
| break; |
| 430 |
|
| |
| 431 |
0 |
| case rbc_print: |
| 432 |
0 |
| nout = na; |
| 433 |
0 |
| printf("r%d is %g\n", codes->ra, na); |
| 434 |
0 |
| break; |
| 435 |
|
| |
| 436 |
2 |
| case rbc_det: |
| 437 |
2 |
| nout = na*nd-nb*nc; |
| 438 |
2 |
| break; |
| 439 |
|
| |
| 440 |
0 |
| default: |
| 441 |
|
| /*croak("bad opcode"); */ |
| 442 |
0 |
| printf("bad op %d\n", codes->code); |
| 443 |
0 |
| return bcol; |
| 444 |
|
| } |
| 445 |
1895029 |
| --code_count; |
| 446 |
1895029 |
| ++codes; |
| 447 |
|
| } |
| 448 |
0 |
| return bcol; |
| 449 |
|
| /* croak("no return opcode"); */ |
| 450 |
|
| } |