Beispiel #1
0
int
schro_motion_get_mode_prediction (SchroMotion * motion, int x, int y)
{
    SchroMotionVector *mv;

    if (y == 0) {
        if (x == 0) {
            return 0;
        } else {
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, 0);
            return mv->pred_mode;
        }
    } else {
        if (x == 0) {
            mv = SCHRO_MOTION_GET_BLOCK (motion, 0, y - 1);
            return mv->pred_mode;
        } else {
            int a, b, c;

            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y);
            a = mv->pred_mode;
            mv = SCHRO_MOTION_GET_BLOCK (motion, x, y - 1);
            b = mv->pred_mode;
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y - 1);
            c = mv->pred_mode;

            return (a & b) | (b & c) | (c & a);
        }
    }
}
Beispiel #2
0
int
schro_motion_split_prediction (SchroMotion * motion, int x, int y)
{
    SchroMotionVector *mv;

    if (y == 0) {
        if (x == 0) {
            return 0;
        } else {
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 4, 0);
            return mv->split;
        }
    } else {
        if (x == 0) {
            mv = SCHRO_MOTION_GET_BLOCK (motion, x, y - 4);
            return mv->split;
        } else {
            int sum;

            mv = SCHRO_MOTION_GET_BLOCK (motion, x, y - 4);
            sum = mv->split;
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 4, y);
            sum += mv->split;
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 4, y - 4);
            sum += mv->split;

            return (sum + 1) / 3;
        }
    }
}
Beispiel #3
0
int
schro_motion_get_global_prediction (SchroMotion * motion, int x, int y)
{
    SchroMotionVector *mv;
    int sum;

    if (x == 0 && y == 0) {
        return 0;
    }
    if (y == 0) {
        mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, 0);
        return mv->using_global;
    }
    if (x == 0) {
        mv = SCHRO_MOTION_GET_BLOCK (motion, 0, y - 1);
        return mv->using_global;
    }

    sum = 0;
    mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y);
    sum += mv->using_global;
    mv = SCHRO_MOTION_GET_BLOCK (motion, x, y - 1);
    sum += mv->using_global;
    mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y - 1);
    sum += mv->using_global;

    return (sum >= 2);
}
Beispiel #4
0
void
schro_motion_vector_prediction (SchroMotion * motion,
                                int x, int y, int *pred_x, int *pred_y, int mode)
{
    SchroMotionVector *mv;
    int vx[3];
    int vy[3];
    int n = 0;

    SCHRO_ASSERT (mode == 1 || mode == 2);
    if (x > 0) {
        mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y);
        if (mv->using_global == FALSE && (mv->pred_mode & mode)) {
            vx[n] = mv->u.vec.dx[mode - 1];
            vy[n] = mv->u.vec.dy[mode - 1];
            n++;
        }
    }
    if (y > 0) {
        mv = SCHRO_MOTION_GET_BLOCK (motion, x, y - 1);
        if (mv->using_global == FALSE && (mv->pred_mode & mode)) {
            vx[n] = mv->u.vec.dx[mode - 1];
            vy[n] = mv->u.vec.dy[mode - 1];
            n++;
        }
    }
    if (x > 0 && y > 0) {
        mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y - 1);
        if (mv->using_global == FALSE && (mv->pred_mode & mode)) {
            vx[n] = mv->u.vec.dx[mode - 1];
            vy[n] = mv->u.vec.dy[mode - 1];
            n++;
        }
    }
    switch (n) {
    case 0:
        *pred_x = 0;
        *pred_y = 0;
        break;
    case 1:
        *pred_x = vx[0];
        *pred_y = vy[0];
        break;
    case 2:
        *pred_x = (vx[0] + vx[1] + 1) >> 1;
        *pred_y = (vy[0] + vy[1] + 1) >> 1;
        break;
    case 3:
        *pred_x = median3 (vx[0], vx[1], vx[2]);
        *pred_y = median3 (vy[0], vy[1], vy[2]);
        break;
    default:
        SCHRO_ASSERT (0);
    }
}
Beispiel #5
0
void
schro_motion_dc_prediction (SchroMotion * motion, int x, int y, int *pred)
{
    SchroMotionVector *mv;
    int i;

    for (i = 0; i < 3; i++) {
        int sum = 0;
        int n = 0;

        if (x > 0) {
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y);
            if (mv->pred_mode == 0) {
                sum += mv->u.dc.dc[i];
                n++;
            }
        }
        if (y > 0) {
            mv = SCHRO_MOTION_GET_BLOCK (motion, x, y - 1);
            if (mv->pred_mode == 0) {
                sum += mv->u.dc.dc[i];
                n++;
            }
        }
        if (x > 0 && y > 0) {
            mv = SCHRO_MOTION_GET_BLOCK (motion, x - 1, y - 1);
            if (mv->pred_mode == 0) {
                sum += mv->u.dc.dc[i];
                n++;
            }
        }
        switch (n) {
        case 0:
            pred[i] = 0;
            break;
        case 1:
            pred[i] = (short) sum;
            break;
        case 2:
            pred[i] = (sum + 1) >> 1;
            break;
        case 3:
            pred[i] = schro_divide3 (sum + 1);
            break;
        default:
            SCHRO_ASSERT (0);
        }
    }
}
Beispiel #6
0
void
schro_motion_calculate_stats (SchroMotion *motion, SchroEncoderFrame *frame)
{
  int i,j;
  SchroMotionVector *mv;
  int ref1 = 0;
  int ref2 = 0;
  int bidir = 0;

  frame->stats_dc = 0;
  frame->stats_global = 0;
  frame->stats_motion = 0;
  for(j=0;j<motion->params->y_num_blocks;j++){
    for(i=0;i<motion->params->x_num_blocks;i++){
      mv = SCHRO_MOTION_GET_BLOCK(motion,i,j);
      if (mv->pred_mode == 0) {
        frame->stats_dc++;
      } else {
        if (mv->using_global) {
          frame->stats_global++;
        } else {
          frame->stats_motion++;
        }
        if (mv->pred_mode == 1) {
          ref1++;
        } else if (mv->pred_mode == 2) {
          ref2++;
        } else {
          bidir++;
        }
      }
    }
  }
  SCHRO_DEBUG("dc %d global %d motion %d ref1 %d ref2 %d bidir %d",
      frame->stats_dc, frame->stats_global, frame->stats_motion,
      ref1, ref2, bidir);
}