コード例 #1
0
ファイル: atari_ntsc.c プロジェクト: OpenEmu/Stella-Core
void atari_ntsc_blit_double( atari_ntsc_t const* ntsc,
    atari_ntsc_in_t const* atari_in1, atari_ntsc_in_t const* atari_in2,
    long in_row_width, int in_width, int in_height,
    void* rgb_out, long out_pitch )
{
  #define TO_DOUBLE(pixel1, pixel2) (((pixel1>>1)<<7)+(pixel2>>1))

  int const chunk_count = (in_width - 1) / atari_ntsc_in_chunk;
  while ( in_height-- )
  {
    atari_ntsc_in_t const* line_in1 = atari_in1;
    atari_ntsc_in_t const* line_in2 = atari_in2;
    ATARI_NTSC_BEGIN_ROW( ntsc,
        TO_DOUBLE(atari_ntsc_black, atari_ntsc_black),
        TO_DOUBLE(line_in1[0], line_in2[0]) );
    atari_ntsc_out_t* restrict line_out = (atari_ntsc_out_t*) rgb_out;
    int n;
    ++line_in1;
    ++line_in2;
    
    for ( n = chunk_count; n; --n )
    {
      /* order of input and output pixels must not be altered */
      ATARI_NTSC_COLOR_IN( 0, ntsc,
          TO_DOUBLE(line_in1[0], line_in2[0]) );
      ATARI_NTSC_RGB_OUT_8888( 0, line_out[0] );
      ATARI_NTSC_RGB_OUT_8888( 1, line_out[1] );
      ATARI_NTSC_RGB_OUT_8888( 2, line_out[2] );
      ATARI_NTSC_RGB_OUT_8888( 3, line_out[3] );
      
      ATARI_NTSC_COLOR_IN( 1, ntsc,
          TO_DOUBLE(line_in1[1], line_in2[1]) );
      ATARI_NTSC_RGB_OUT_8888( 4, line_out[4] );
      ATARI_NTSC_RGB_OUT_8888( 5, line_out[5] );
      ATARI_NTSC_RGB_OUT_8888( 6, line_out[6] );
      
      line_in1 += 2;
      line_in2 += 2;
      line_out += 7;
    }
    
    /* finish final pixels */
    ATARI_NTSC_COLOR_IN( 0, ntsc,
        TO_DOUBLE(atari_ntsc_black, atari_ntsc_black) );
    ATARI_NTSC_RGB_OUT_8888( 0, line_out[0] );
    ATARI_NTSC_RGB_OUT_8888( 1, line_out[1] );
    ATARI_NTSC_RGB_OUT_8888( 2, line_out[2] );
    ATARI_NTSC_RGB_OUT_8888( 3, line_out[3] );
    
    ATARI_NTSC_COLOR_IN( 1, ntsc,
        TO_DOUBLE(atari_ntsc_black, atari_ntsc_black) );
    ATARI_NTSC_RGB_OUT_8888( 4, line_out[4] );
    ATARI_NTSC_RGB_OUT_8888( 5, line_out[5] );
    ATARI_NTSC_RGB_OUT_8888( 6, line_out[6] );
    
    atari_in1 += in_row_width;
    atari_in2 += in_row_width;
    rgb_out = (char*) rgb_out + out_pitch;
  }
}
コード例 #2
0
ファイル: cotd.c プロジェクト: webom2008/BF512.VDK
DOUBLE                            /*{ ret - cotd(x)       }*/
cotd
(
  DOUBLE x                        /*{ (i) - input value x }*/
)
{
    LONG n;
    DOUBLE xn;
    DOUBLE f, g;
    DOUBLE x_int, x_fract;
    DOUBLE result;
    DOUBLE xnum, xden;

    /*{ If x is outside the domain or zero, return 0.0 }*/
    if ((x > COT64_X_MAX) || (x < -COT64_X_MAX) || (x == 0.0L))
    {
        return 0.0L;
    }

    /*{ split x into x_int and x_fract for better argument reduction }*/
    x_int = TO_DOUBLE(TO_LONG(x));
    x_fract = SUBD(x, x_int);

    /*{ Reduce the input to range between -PI/4, PI/4 }*/
    /*{!INDENT}*/
    /*{ n = Rounded long x/(PI/2) }*/
    if (x > 0.0)
    {
        n = TO_LONG(ADDD(MPYD(x, INV_PI_2), 0.5));
    }
    else
    {
        n = TO_LONG(ADDD(MPYD(x, INV_PI_2), -0.5));
    }

    /*{ xn = (double)n }*/
    xn = TO_DOUBLE(n);

    /*{ f = x - xn*PI  }*/
    /* (using higher precision computation) */
    f = SUBD(x_int, MPYD(xn, PI_2_DC1));
    f = ADDD(f, x_fract);
    f = SUBD(f, MPYD(xn, PI_2_DC2));
    f = SUBD(f, MPYD(xn, PI_2_DC3));
    /*{!OUTDENT}*/

    if (f < 0.0L)
    {
        g = -f;
    }
    else
    {
        g = f;
    }
    /*{ If |f| < eps }*/
    if (g < EPS_DOUBLE)
    {
        /*{ if n is odd, return -f }*/
        if (n & 0x0001)
        {
            result = -f;
        }
        /*{ if n is even, return 1/f }*/
        else
        {
            result = DIVD(1.0L, f);
        }            
        return result;
    }

    /*{ g = f * f }*/
    g = MPYD(f, f);

    /*{ Compute sin approximation on reduced argument }*/
    /*{!INDENT}*/
    /*{ xnum = (((g * p3 + p2) * g + p1) * g * f + f }*/
    xnum = MPYD(g, TANDP_COEF3);
    xnum = ADDD(xnum, TANDP_COEF2);
    xnum = MPYD(xnum, g);
    xnum = ADDD(xnum, TANDP_COEF1);
    xnum = MPYD(xnum, g);
    xnum = MPYD(xnum, f);
    xnum = ADDD(xnum, f);

    /*{ xden = (((g * q4 + q3) * g + q2) * g +q1) * g + q0 }*/
    xden = MPYD(g, TANDQ_COEF4);
    xden = ADDD(xden, TANDQ_COEF3);
    xden = MPYD(xden, g);
    xden = ADDD(xden, TANDQ_COEF2);
    xden = MPYD(xden, g);
    xden = ADDD(xden, TANDQ_COEF1);
    xden = MPYD(xden, g);
    xden = ADDD(xden, TANDQ_COEF0);
    /*{!OUTDENT}*/

    /*{ if n is odd, result = -xnum/xden }*/
    if (n & 0x0001)
    {
        xnum = -xnum;
    }
    /*{ else n is even, result = xden/xnum }*/
    else
    {
        result = xden;
        xden = xnum;
        xnum = result;
    }            
    result = DIVD(xnum, xden);

    /*{ return result }*/
    return result;
}
コード例 #3
0
ファイル: test1.c プロジェクト: Afshintm/coreclr
/*
 * NaN: any double with maximum exponent (0x7ff) and non-zero fraction
 */
int __cdecl main(int argc, char *argv[])
{
    UINT64 PosInf=0;
    UINT64 NegInf=0;
    UINT64 val=0;

    /*
     * Initialize the PAL and return FAIL if this fails
     */
    if (0 != (PAL_Initialize(argc, argv)))
    {
        return FAIL;
    }
    /*
     * Try some trivial values
     */
    if (_isnan(0))
    {
        Fail ("_isnan() incorrectly identified %f as NaN!\n", 0);
    }
    if (_isnan(1.2423456))
    {
        Fail ("_isnan() incorrectly identified %f as NaN!\n", 0);
    }
    if (_isnan(42))
    {
        Fail ("_isnan() incorrectly identified %f as NaN!\n", 0);
    }


    PosInf = 0x7ff00000;
    PosInf <<=32;

    NegInf = 0xfff00000;
    NegInf <<=32;

    /*
     * Try positive and negative infinity
     */
    if (_isnan(TO_DOUBLE(PosInf)))
    {
        Fail ("_isnan() incorrectly identified %I64x as NaN!\n", PosInf);
    }

    if (_isnan(TO_DOUBLE(NegInf)))
    {
        Fail ("_isnan() incorrectly identified %I64x as NaN!\n", NegInf);
    }

    /*
     * Try setting the least significant bit of the fraction,
     * positive and negative
     */
    val = PosInf + 1;
    if (!_isnan(TO_DOUBLE(val)))
    {
        Fail ("_isnan() failed to identify %I64x as NaN!\n", val);
    }

    val = NegInf + 1;
    if (!_isnan(TO_DOUBLE(val)))
    {
        Fail ("_isnan() failed to identify %I64x as NaN!\n", val);
    }


    /*
     * Try setting the most significant bit of the fraction,
     * positive and negative
     */
    val = 0x7ff80000;
    val <<=32;
    if (!_isnan(TO_DOUBLE(val)))
    {
        Fail ("_isnan() failed to identify %I64x as NaN!\n", val);
    }

    val = 0xfff80000;
    val <<=32;
    if (!_isnan(TO_DOUBLE(val)))
    {
        Fail ("_isnan() failed to identify %I64x as NaN!\n", val);
    }

    PAL_Terminate();

    return PASS;
}
コード例 #4
0
ファイル: cosd.c プロジェクト: webom2008/BF512.VDK
DOUBLE                            /*{ ret - cosd(x)       }*/
cosd
(
  DOUBLE x                        /*{ (i) - input value x }*/
)
{
    LONG n;
    DOUBLE y;
    DOUBLE xn;
    DOUBLE x_int, x_fract;
    DOUBLE f, g, result;
    int sign = 1;

    /*{ x = |x| (since cos(-x) == cos(x)) }*/
    if (x < 0.0L)
    {
        x = -x;
    }

    /*{ y = |x| + PI/2 }*/
    y = ADDD(x, PI_2);

    /*{ If x is outside domain, return 0.0 }*/
    if (y > COS64_X_MAX)
    {
        return 0.0L;
    }

    /*{ Reduce the input to range between -PI/2, PI/2 }*/
    /*{!INDENT}*/
    /*{ split x into x_int and x_fract for better argument reduction }*/
    x_int = TO_DOUBLE(TO_LONG(x));
    x_fract = SUBD(x, x_int);

    /*{ xn = Rounded long y/PI }*/
    n = TO_LONG(ADDD(MPYD(y, INV_PI), 0.5));
    xn = TO_DOUBLE(n);

    /*{ subtract 0.5 from xn  }*/
    /* (more accurate than adding PI/2 to input argument) */
    xn = SUBD(xn, 0.5L);


    /*{ f = x - xn*PI  }*/
    /* (using higher precision computation) */
    f = SUBD(x_int, MPYD(xn, PI_DC1));
    f = ADDD(f, x_fract);
    f = SUBD(f, MPYD(xn, PI_DC2));
    f = SUBD(f, MPYD(xn, PI_DC3));
    /*{!OUTDENT}*/

    /*{ sign = 1 }*/
    /*{ If n is odd, sign = -1 }*/
    if (n & 0x0001)
    {
        sign = -sign;
    }

    /*{ If |f| < eps, return f }*/
    if (f < 0.0L)
    {
        g = -f;
    }
    else
    {
        g = f;
    }

    if (g < EPS_DOUBLE)
    {
        result = f;
        if (sign < 0)
        {
            result = -result;
        }
        return result;
    }

    /*{ g = f * f }*/
    g = MPYD(f, f);

    /*{ Compute sin approximation }*/
    /*{!INDENT}*/
    /*{ result = ((((((((g * C8 + C7) * g + C6) * g + C5) * g + 
                      C4) * g + C3) * g + C2) * g + C1) * g) * f + f }*/
    result = MPYD(g, SIND_COEF8);
    result = ADDD(result, SIND_COEF7);
    result = MPYD(result, g);
    result = ADDD(result, SIND_COEF6);
    result = MPYD(result, g);
    result = ADDD(result, SIND_COEF5);
    result = MPYD(result, g);
    result = ADDD(result, SIND_COEF4);
    result = MPYD(result, g);
    result = ADDD(result, SIND_COEF3);
    result = MPYD(result, g);
    result = ADDD(result, SIND_COEF2);
    result = MPYD(result, g);
    result = ADDD(result, SIND_COEF1);
    result = MPYD(result, g);

    result = MPYD(result, f);
    result = ADDD(result, f);
    /*{!OUTDENT}*/

    /*{ if sign < 0, result = -result }*/
    if (sign < 0)
    {
        result = -result;
    }
    /* make sure -1.0 <= result <= 1.0 */
    if (result > 1.0L) {
      result = 1.0L;
    }
    else if (result < -1.0L) {
      result = -1.0L;
    }
    /*{ return result }*/
    return (result);
}
コード例 #5
0
static const char *
_edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
                 Edje_Calc_Params *params,
                 const char *text, const char *font, int size,
                 Evas_Coord sw, int *free_text)
{
    Evas_Coord tw = 0, th = 0, p;
    int l, r;
    int i;
    char *buf;
    int uc1 = -1, uc2 = -1, c1 = -1, c2 = -1;
    int loop = 0, extra;
    size_t orig_len;
    FLOAT_T sc;

    sc = ed->scale;
    if (sc == ZERO) sc = _edje_scale;

    *free_text = 0;
    if (sw <= 1) return "";

    if (ep->part->scale) evas_object_scale_set(ep->object, TO_DOUBLE(sc));
    evas_object_text_font_set(ep->object, font, size);
    evas_object_text_text_set(ep->object, text);

    part_get_geometry(ep, &tw, &th);
    evas_object_text_style_pad_get(ep->object, &l, &r, NULL, NULL);

    p = ((sw - tw) * params->type.text.elipsis);

    /* chop chop */
    if (tw > sw)
    {
        if (params->type.text.elipsis != 0.0)
            /* should be the last in text! not the rightmost */
            uc1 = evas_object_text_last_up_to_pos(ep->object,
                                                  -p + l, th / 2);
        if (params->type.text.elipsis != 1.0)
        {
            /* should be the last in text! not the rightmost */
            if ((-p + sw -r) < 0)
                uc2 = evas_object_text_last_up_to_pos(ep->object, 0, th / 2);
            else
                uc2 = evas_object_text_last_up_to_pos(ep->object,
                                                      -p + sw - r, th / 2);
        }
        if ((uc1 < 0) && (uc2 < 0))
        {
            uc1 = 0;
            uc2 = 0;
        }
    }

    if (!(((uc1 >= 0) || (uc2 >= 0)) && (tw > sw)))
        return text;

    if ((uc1 == 0) && (uc2 == 0))
        return text;

    orig_len = strlen(text);

    /* don't overflow orig_len by adding extra
     * FIXME: we might want to set a max string length somewhere...
     */
    extra = 1 + 3 + 3; /* terminator, leading and trailing ellipsis */
    orig_len = MIN(orig_len, ((size_t) 8192 - extra));

    if (!(buf = malloc(orig_len + extra)))
        return text;

    /* Convert uc1, uc2 -> c1, c2 */
    i = 0;
    if (uc1 >= 0)
    {
        c1 = 0;
        for ( ; i < uc1 ; i++)
        {
            c1 = evas_string_char_next_get(text, c1, NULL);
        }
    }
    if (uc2 >= 0)
    {
        if (c1 >= 0)
        {
            c2 = c1;
        }
        else
        {
            c2 = 0;
        }
        for ( ; i < uc2 ; i++)
        {
            c2 = evas_string_char_next_get(text, c2, NULL);
        }
    }

    buf[0] = '\0';

    while (((c1 >= 0) || (c2 >= 0)) && (tw > sw))
    {
        loop++;
        if (sw <= 0.0)
        {
            buf[0] = 0;
            break;
        }
        if ((c1 >= 0) && (c2 >= 0))
        {
            if ((loop & 0x1))
            {
                if (c1 >= 0)
                    c1 = evas_string_char_next_get(text, c1, NULL);
            }
            else
            {
                if (c2 >= 0)
                {
                    c2 = evas_string_char_prev_get(text, c2, NULL);
                    if (c2 < 0)
                    {
                        buf[0] = 0;
                        break;
                    }
                }
            }
        }
        else
        {
            if (c1 >= 0)
                c1 = evas_string_char_next_get(text, c1, NULL);
            else if (c2 >= 0)
            {
                c2 = evas_string_char_prev_get(text, c2, NULL);
                if (c2 < 0)
                {
                    buf[0] = 0;
                    break;
                }
            }
        }
        if ((c1 >= 0) && (c2 >= 0))
        {
            if (c1 >= c2)
            {
                buf[0] = 0;
                break;
            }
        }
        else if ((c1 > 0 && (size_t) c1 >= orig_len) || c2 == 0)
        {
            buf[0] = 0;
            break;
        }

        buf[0] = 0;

        _edje_text_fit_set(buf, text, c1, c2);

        evas_object_text_text_set(ep->object, buf);
        part_get_geometry(ep, &tw, &th);
    }

    *free_text = 1;

    return buf;
}