Beispiel #1
0
inline void sad_exec( ia_seq_t* s, ia_filter_param_t* fp, ia_image_t** iaim, ia_image_t* iar )
{
    int i, j, h, k;
    //const double op = 1.0 / (s->param->i_mb_size*s->param->i_mb_size);

    assert( s->param->i_maxrefs > 1 );

    for( i = 0; i < s->param->i_height; i++ )
    {
        for( j = 0; j < s->param->i_width; j++ )
        {
            const int cr = offset(s->param->i_width,j,i,0);
            const int cg = cr + 1;
            const int cb = cg + 1;

            iar->pix[cr] =
            iar->pix[cg] =
            iar->pix[cb] = 0;

            if( i <= s->param->i_mb_size/2 || j <= s->param->i_mb_size/2
                || i >= s->param->i_height - s->param->i_mb_size/2
                || j >= s->param->i_width  - s->param->i_mb_size/2 )
            {
                continue;
            }

            for( h = i - s->param->i_mb_size/2; h <= i + s->param->i_mb_size/2; h++ )
            {
                for( k = j - s->param->i_mb_size/2; k <= j + s->param->i_mb_size/2; k++ )
                {
                    const int lr = offset( s->param->i_width,k,h,0 );
                    const int lg = lr + 1;
                    const int lb = lg + 1;

                    iar->pix[cr] += fabs(iaim[0]->pix[lr] - iaim[1]->pix[lr]);
                    iar->pix[cg] += fabs(iaim[0]->pix[lg] - iaim[1]->pix[lg]);
                    iar->pix[cb] += fabs(iaim[0]->pix[lb] - iaim[1]->pix[lb]);
                }
            }

            iar->pix[cr] = clip_uint8( iar->pix[cr] ); //op;
            iar->pix[cg] = clip_uint8( iar->pix[cg] ); //op;
            iar->pix[cb] = clip_uint8( iar->pix[cb] ); //op;
        }
    }
    fp = fp;
}
Beispiel #2
0
void fstderiv_exec( ia_seq_t* s, ia_filter_param_t* fp, ia_image_t** iaim, ia_image_t* iar )
{
    ia_image_t* iaf = iaim[0];
    //const double op = 255/sqrt(pow(255*3,2)*2); //  = max / (lmax - lmin)
    int i, j;
    int pitch = iar->i_pitch;

    for( i = 0; i < pitch*s->param->i_height; i++ ) {
        iar->pix[i] = 0;
    }

    for( j = 0; j < s->param->i_height; j++ )
    {
        for( i = 1; i < s->param->i_width; i++ )
        {
            int ci, cj, pix;
            double dx[3] = {0}; // {r, g, b}
            double dy[3] = {0}; // {r, g, b}

            if( i == 0 || j == 0 || i == s->param->i_width-1 || j == s->param->i_height-1 )
                continue;

            for( pix = 0; pix < 3; pix++ ) {

                // left and right
                for( cj = j-1; cj < j+1; cj++ ) {
                    dx[pix] -= iaf->pix[o(i-1,cj,pix)]; // left
                    dx[pix] += iaf->pix[o(i+1,cj,pix)]; // right
                }

                // top and bottom
                for( ci = i-1; ci < i+1; ci++ ) {
                    dy[pix] += iaf->pix[o(ci,j-1,pix)]; // top
                    dy[pix] -= iaf->pix[o(ci,j+1,pix)]; // bottom
                }

                // to scale the resultant pixel down to its appropriate value it
                // should be multiplied by op, but visually, it looks better to
                // clip it... this may change in the future.
                iar->pix[o(i,j,pix)] = clip_uint8( sqrt(pow(dx[pix],2)+pow(dy[pix],2)) );
            }
        }
    }
    fp = fp;
}
Beispiel #3
0
int edges_proc_exec (plugin_context*    ctx,
                     int                thread_id,
                     image_t**          src_data,
                     image_t**          dst_data)
{
    image_t* im;
    image_t* dim;
/*    const double op = 255/sqrt(pow(255*3,2)*2); //  = max / (lmax - lmin) */
    int i, j;
    int pitch;

    (void) ctx;
    (void) thread_id;

    /* make sure inputs are valid */
    if (
        NULL == (im = *src_data) ||
        NULL != *dst_data ||
        NULL == (dim = calloc (1, sizeof(image_t))))
    {
        return -1;
    }

    /* allocate output image */
    dim->pix = calloc (im->height*im->width*im->bpp/8 * 3, sizeof(uint8_t));
    dim->width = im->width;
    dim->height = im->height;
    dim->bpp = im->bpp;
    dim->fmt = FMT_RGB24;
    dim->frame = im->frame;

    pitch = im->width*im->bpp/8;

    for( j = 0; j < im->height; j++ )
    {
        for( i = 1; i < im->width; i++ )
        {
            int ci, cj, pix;
            double dx[3] = {0}; /* {r, g, b} */
            double dy[3] = {0}; /* {r, g, b} */

            if( i == 0 || j == 0 || i == im->width-1 || j == im->height-1 )
                continue;

            for( pix = 0; pix < 3; pix++ ) {

                /* left and right */
                for( cj = j-1; cj < j+1; cj++ ) {
                    dx[pix] -= im->pix[o(i-1,cj,pix)]; /* left */
                    dx[pix] += im->pix[o(i+1,cj,pix)]; /* right */
                }

                /* top and bottom */
                for( ci = i-1; ci < i+1; ci++ ) {
                    dy[pix] += im->pix[o(ci,j-1,pix)]; /* top */
                    dy[pix] -= im->pix[o(ci,j+1,pix)]; /* bottom */
                }

                /* to scale the resultant pixel down to its appropriate value it
                 * should be multiplied by op, but visually, it looks better to
                 * clip it... this may change in the future. */
                dim->pix[o(i,j,pix)] = clip_uint8( sqrt(pow(dx[pix],2)+pow(dy[pix],2)) );
            }
        }
    }

    /* pass the output image along */
    *dst_data = dim;

    return 0;
}