Example #1
0
File: tv2x.c Project: cleure/TV4X
/**
* Process value for brightness/contrast filter.
*
* @param    double *f       - Filter, double of 4
* @param    uint32_r value  - Value to process
* @return   double
**/
static double brcn_filter_process(double *f, uint32_t value)
{
    double result;
    
    #define RANGE(i)        i[0]
    #define SCALE(i)        i[1]
    #define SLOPE(i)        i[2]
    #define INTERCEPT(i)    i[3]
    
    result = ((SLOPE(f) * SCALE(f)) * value + INTERCEPT(f)) * RANGE(f);
    if (result > RANGE(f)) {
        result = RANGE(f);
    } else if (result < 0.0) {
        result = 0.0;
    }
    
    #undef RANGE
    #undef SCALE
    #undef SLOPE
    #undef INTERCEPT
    
    return result;
}
Example #2
0
/* determine point of detected intersections  */
static int intpoint(struct vertex *l, struct vertex *m, float *x, float *y, int cond)
{
    struct position ls, le, ms, me, pt1, pt2;
    float m1, m2, c1, c2;

    if (cond <= 0)
	return (0);
    ls = l->pos;
    le = after(l)->pos;
    ms = m->pos;
    me = after(m)->pos;

    switch (cond) {

    case 3:			/* a simple intersection        */
	if (ls.x == le.x) {
	    *x = ls.x;
	    *y = me.y + SLOPE(ms, me) * (*x - me.x);
	} else if (ms.x == me.x) {
	    *x = ms.x;
	    *y = le.y + SLOPE(ls, le) * (*x - le.x);
	} else {
	    m1 = SLOPE(ms, me);
	    m2 = SLOPE(ls, le);
	    c1 = ms.y - (m1 * ms.x);
	    c2 = ls.y - (m2 * ls.x);
	    *x = (c2 - c1) / (m1 - m2);
	    *y = ((m1 * c2) - (c1 * m2)) / (m1 - m2);
	}
	break;

    case 2:			/*     the two lines  have a common segment  */
	if (online(l, m, 0) == -1) {	/* ms between ls and le */
	    pt1 = ms;
	    pt2 =
		(online(m, l, 1) ==
		 -1) ? ((online(m, l, 0) == -1) ? le : ls) : me;
	} else if (online(l, m, 1) == -1) {	/* me between ls and le */
	    pt1 = me;
	    pt2 =
		(online(l, m, 0) ==
		 -1) ? ((online(m, l, 0) == -1) ? le : ls) : ms;
	} else {
	    /* may be degenerate? */
	    if (online(m, l, 0) != -1)
		return 0;
	    pt1 = ls;
	    pt2 = le;
	}

	*x = (pt1.x + pt2.x) / 2;
	*y = (pt1.y + pt2.y) / 2;
	break;

    case 1:			/* a vertex of line m is on line l */
	if ((ls.x - le.x) * (ms.y - ls.y) == (ls.y - le.y) * (ms.x - ls.x)) {
	    *x = ms.x;
	    *y = ms.y;
	} else {
	    *x = me.x;
	    *y = me.y;
	}
    }				/* end switch  */
    return (1);
}