Пример #1
0
tuple2<double, double> *rgb_to_hls(double r, double g, double b) {
    double bc, gc, h, l, maxc, minc, rc, s;

    maxc = ___max(3, ((double)(0)), r, g, b);
    minc = ___min(3, ((double)(0)), r, g, b);
    l = ((minc+maxc)/2.0);
    if ((minc==maxc)) {
        return (new tuple2<double, double>(3,0.0,l,0.0));
    }
    if ((l<=0.5)) {
        s = ((maxc-minc)/(maxc+minc));
    }
    else {
        s = ((maxc-minc)/((2.0-maxc)-minc));
    }
    rc = ((maxc-r)/(maxc-minc));
    gc = ((maxc-g)/(maxc-minc));
    bc = ((maxc-b)/(maxc-minc));
    if ((r==maxc)) {
        h = (bc-gc);
    }
    else if ((g==maxc)) {
        h = ((2.0+rc)-bc);
    }
    else {
        h = ((4.0+gc)-rc);
    }
    h = __mods((h/6.0), 1.0);
    return (new tuple2<double, double>(3,h,l,s));
}
Пример #2
0
tuple2<double, double> *hsv_to_rgb(double h, double s, double v) {
    double f, p, q, t;
    __ss_int i;

    if ((s==0.0)) {
        return (new tuple2<double, double>(3,v,v,v));
    }
    i = __int((h*6.0));
    f = ((h*6.0)-i);
    p = (v*(1.0-s));
    q = (v*(1.0-(s*f)));
    t = (v*(1.0-(s*(1.0-f))));
    i = __mods(i, (__ss_int)6);
    if ((i==0)) {
        return (new tuple2<double, double>(3,v,t,p));
    }
    if ((i==1)) {
        return (new tuple2<double, double>(3,q,v,p));
    }
    if ((i==2)) {
        return (new tuple2<double, double>(3,p,v,t));
    }
    if ((i==3)) {
        return (new tuple2<double, double>(3,p,q,v));
    }
    if ((i==4)) {
        return (new tuple2<double, double>(3,t,p,v));
    }
    if ((i==5)) {
        return (new tuple2<double, double>(3,v,p,q));
    }
    return 0;
}
Пример #3
0
tuple2<double, double> *rgb_to_hsv(double r, double g, double b) {
    double bc, gc, h, maxc, minc, rc, s, v;

    maxc = ___max(3, ((double)(0)), r, g, b);
    minc = ___min(3, ((double)(0)), r, g, b);
    v = maxc;
    if ((minc==maxc)) {
        return (new tuple2<double, double>(3,0.0,0.0,v));
    }
    s = ((maxc-minc)/maxc);
    rc = ((maxc-r)/(maxc-minc));
    gc = ((maxc-g)/(maxc-minc));
    bc = ((maxc-b)/(maxc-minc));
    if ((r==maxc)) {
        h = (bc-gc);
    }
    else if ((g==maxc)) {
        h = ((2.0+rc)-bc);
    }
    else {
        h = ((4.0+gc)-rc);
    }
    h = __mods((h/6.0), 1.0);
    return (new tuple2<double, double>(3,h,s,v));
}
Пример #4
0
double _v(double m1, double m2, double hue) {
    
    hue = __mods(hue, 1.0);
    if ((hue<ONE_SIXTH)) {
        return (m1+(((m2-m1)*hue)*6.0));
    }
    if ((hue<0.5)) {
        return m2;
    }
    if ((hue<TWO_THIRD)) {
        return (m1+(((m2-m1)*(TWO_THIRD-hue))*6.0));
    }
    return m1;
}
Пример #5
0
str *DynamInt::__mul__(DynamInt *num) {
    /**
    Overloaded add function
    Adds an existing DynamInt to this one
    @param  num reference to an existing DynamInt
    @return added DynamInt
    */
    str *bottom, *product, *top;
    int __2, __3, carry, i, j, k, n, resultSize, tempProduct;

    if (__gt(this, num)) {
        top = this->data;
        bottom = num->data;
    }
    else {
        top = num->data;
        bottom = this->data;
    }
    tempProduct = 0;
    product = const_0;
    resultSize = (this->size+num->size);

    FAST_FOR(n,0,resultSize,1,2,3)
        product = (const_1)->__add__(product);
    END_FOR

    i = (len(bottom)-1);

    while ((i>=0)) {
        carry = 0;
        j = (len(top)-1);

        while ((j>=0)) {
            k = (i+j);
            tempProduct = __int((((__int(top->__getitem__(j))*__int(bottom->__getitem__(i)))+__int(product->__getitem__(k)))+carry));
            product = __add_strs(3, product->__slice__(2, 0, (k+1), 0), __str(__mods(tempProduct, 10)), product->__slice__(1, (k+2), 0, 0));
            carry = __int(__divs(tempProduct, 10));
            j = (j-1);
        }
        if ((carry!=0)) {
            product = __add_strs(3, product->__slice__(2, 0, i, 0), __str(carry), product->__slice__(1, (i+1), 0, 0));
        }
        i = (i-1);
    }
    return product;
    return 0;
}
Пример #6
0
template<> inline tuple2<int, int> *divmod(int a, int b) {
    return new tuple2<int, int>(2, __floordiv(a,b), __mods(a,b));
}
Пример #7
0
template<> inline tuple2<double, double> *divmod(double a, double b) {
    return new tuple2<double, double>(2, __floordiv(a,b), __mods(a,b));
}
Пример #8
0
template<> inline double __mods(double a, int b) { return __mods(a, (double)b); }
Пример #9
0
template<> inline double __mods(int a, double b) { return __mods((double)a, b); }
Пример #10
0
str *DynamInt::__add__(DynamInt *num) {
    /**
    Overloaded add function
    Adds an existing DynamInt to this one
    @param  num reference to an existing DynamInt
    @return added DynamInt
    */
    str *bottom, *sum, *top;
    int carryover, i, j, tempSum;

    /**
    Basically, this selects what should be added to what
    it is based on primary school addition techniques
    i.e
    to add 1234 to 12345, the code makes a configuration similar to
    
            1  2  3  4  5
            +  1  2  3  4
            -------------
            1  3  5  7  9
            -------------
    The larger number goes on top while the smaller goes below
    */
    if (__gt(this, num)) {
        top = this->data;
        bottom = num->data;
    }
    else {
        top = num->data;
        bottom = this->data;
    }
    /**
    Temporary Variables used in addition process
    tempSum     ----- Stores partial subtraction
    j           ----- Stores length of bottom number
    i           ----- Stores length of top number
    sum         ----- Stores final sum string
    carryover   ----- A flag that determines if there is a carryover to the next digit
    */
    tempSum = 0;
    j = (len(bottom)-1);
    i = (len(top)-1);
    sum = const_0;
    carryover = 0;

    while ((i>=0)) {
        /**
         Have we run out of bottom digits ? 
        */
        if ((j>=0)) {
            tempSum = ((__int(top->__getitem__(i))+__int(bottom->__getitem__(j)))+carryover);
            j = (j-1);
        }
        else {
            /**
             No more bottom digits, add any leftover carryover
            */
            tempSum = (__int(top->__getitem__(i))+carryover);
        }
        if ((tempSum>=10)) {
            /**
             do we have a remainder to carryover ? 
            */
            tempSum = __mods(tempSum, 10);
            carryover = 1;
        }
        else {
            carryover = 0;
        }
        /**
         lets concatenate the main sum outputed 
        */
        sum = (__str(tempSum))->__add__(sum);
        i = (i-1);
    }
    if ((carryover==1)) {
        sum = (__str(carryover))->__add__(sum);
    }
    return sum;
}