camera_cnn

Unnamed repository; edit this file 'description' to name the repository.
git clone anongit@rnpnr.xyz:camera_cnn.git
Log | Files | Refs | Feed | LICENSE

math.c (1188B)


      1 /* See LICENSE for license details. */
      2 function v4
      3 hsv_to_rgb(v4 hsv)
      4 {
      5 	/* f(k(n))   = V - V*S*max(0, min(k, min(4 - k, 1)))
      6 	 * k(n)      = fmod((n + H * 6), 6)
      7 	 * (R, G, B) = (f(n = 5), f(n = 3), f(n = 1))
      8 	 */
      9 	alignas(16) f32 nval[4] = {5.0f, 3.0f, 1.0f, 0.0f};
     10 	f32x4 n   = load_f32x4(nval);
     11 	f32x4 H   = dup_f32x4(hsv.x);
     12 	f32x4 S   = dup_f32x4(hsv.y);
     13 	f32x4 V   = dup_f32x4(hsv.z);
     14 	f32x4 six = dup_f32x4(6);
     15 
     16 	f32x4 t   = add_f32x4(n, mul_f32x4(six, H));
     17 	f32x4 rem = floor_f32x4(div_f32x4(t, six));
     18 	f32x4 k   = sub_f32x4(t, mul_f32x4(rem, six));
     19 
     20 	t = min_f32x4(sub_f32x4(dup_f32x4(4), k), dup_f32x4(1));
     21 	t = max_f32x4(dup_f32x4(0), min_f32x4(k, t));
     22 	t = mul_f32x4(t, mul_f32x4(S, V));
     23 
     24 	v4 rgba;
     25 	store_f32x4(rgba.E, sub_f32x4(V, t));
     26 	rgba.a = hsv.a;
     27 	return rgba;
     28 }
     29 
     30 function f32
     31 ease_in_out_cubic(f32 t)
     32 {
     33 	f32 result;
     34 	if (t < 0.5f) {
     35 		result = 4.0f * t * t * t;
     36 	} else {
     37 		t      = -2.0f * t + 2.0f;
     38 		result =  1.0f - t * t * t / 2.0f;
     39 	}
     40 	return result;
     41 }
     42 
     43 function f32
     44 ease_in_out_quartic(f32 t)
     45 {
     46 	f32 result;
     47 	if (t < 0.5f) {
     48 		result = 8.0f * t * t * t * t;
     49 	} else {
     50 		t      = -2.0f * t + 2.0f;
     51 		result =  1.0f - t * t * t * t / 2.0f;
     52 	}
     53 	return result;
     54 }