av1/encoder/tune_vmaf.c
// A callback function used to pass data to VMAF.
// Returns 0 after reading a frame.
// Returns 2 when there is no more frame to read.
A callback function used to pass data to VMAF.
Returns 0 after reading a frame.
Returns 2 when there is no more frame to read.
A callback function used to pass data to VMAF . Returns 0 after reading a frame . Returns 2 when there is no more frame to read .
static int update_frame(float *ref_data, float *main_data, float *temp_data,
                        int stride, void *user_data) {
  FrameData *frames = (FrameData *)user_data;
  const int width = frames->source->y_width;
  const int height = frames->source->y_height;
  const int row = frames->row;
  const int col = frames->col;
  const int num_rows = frames->num_rows;
  const int num_cols = frames->num_cols;
  const int block_w = frames->block_w;
  const int block_h = frames->block_h;
  const YV12_BUFFER_CONFIG *source = frames->source;
  const YV12_BUFFER_CONFIG *blurred = frames->blurred;
  const int bit_depth = frames->bit_depth;
  const float scale_factor = 1.0f / (float)(1 << (bit_depth - 8));
  (void)temp_data;
  stride /= (int)sizeof(*ref_data);
  for (int i = 0; i < height; ++i) {
    float *ref, *main;
    ref = ref_data + i * stride;
    main = main_data + i * stride;
    if (bit_depth == 8) {
      uint8_t *src;
      src = source->y_buffer + i * source->y_stride;
      for (int j = 0; j < width; ++j) {
        ref[j] = main[j] = (float)src[j];
      }
    } else {
      uint16_t *src;
      src = CONVERT_TO_SHORTPTR(source->y_buffer) + i * source->y_stride;
      for (int j = 0; j < width; ++j) {
        ref[j] = main[j] = scale_factor * (float)src[j];
      }
    }
  }
  if (row < num_rows && col < num_cols) {
    const int row_offset = row * block_h;
    const int col_offset = col * block_w;
    const int block_width = AOMMIN(width - col_offset, block_w);
    const int block_height = AOMMIN(height - row_offset, block_h);
    float *main_buf = main_data + col_offset + row_offset * stride;
    if (bit_depth == 8) {
      uint8_t *blurred_buf =
          blurred->y_buffer + row_offset * blurred->y_stride + col_offset;
      for (int i = 0; i < block_height; ++i) {
        for (int j = 0; j < block_width; ++j) {
          main_buf[j] = (float)blurred_buf[j];
        }
        main_buf += stride;
        blurred_buf += blurred->y_stride;
      }
    } else {
      uint16_t *blurred_buf = CONVERT_TO_SHORTPTR(blurred->y_buffer) +
                              row_offset * blurred->y_stride + col_offset;
      for (int i = 0; i < block_height; ++i) {
        for (int j = 0; j < block_width; ++j) {
          main_buf[j] = scale_factor * (float)blurred_buf[j];
        }
        main_buf += stride;
        blurred_buf += blurred->y_stride;
      }
    }
    frames->col++;
    if (frames->col >= num_cols) {
      frames->col = 0;
      frames->row++;
    }
    return 0;
  } else {
    return 2;
  }
}
static int update_frame ( float * ref_data , float * main_data , float * temp_data , int stride , void * user_data ) { FrameData * frames = ( FrameData * ) user_data ; const int width = frames -> source -> y_width ; const int height = frames -> source -> y_height ; const int row = frames -> row ; const int col = frames -> col ; const int num_rows = frames -> num_rows ; const int num_cols = frames -> num_cols ; const int block_w = frames -> block_w ; const int block_h = frames -> block_h ; const YV12_BUFFER_CONFIG * source = frames -> source ; const YV12_BUFFER_CONFIG * blurred = frames -> blurred ; const int bit_depth = frames -> bit_depth ; const float scale_factor = 1.0f / ( float ) ( 1 << ( bit_depth - 8 ) ) ; ( void ) temp_data ; stride /= ( int ) sizeof ( * ref_data ) ; for ( int i = 0 ; i < height ; ++ i ) { float * ref , * main ; ref = ref_data + i * stride ; main = main_data + i * stride ; if ( bit_depth == 8 ) { uint8_t * src ; src = source -> y_buffer + i * source -> y_stride ; for ( int j = 0 ; j < width ; ++ j ) { ref [ j ] = main [ j ] = ( float ) src [ j ] ; } } else { uint16_t * src ; src = CONVERT_TO_SHORTPTR ( source -> y_buffer ) + i * source -> y_stride ; for ( int j = 0 ; j < width ; ++ j ) { ref [ j ] = main [ j ] = scale_factor * ( float ) src [ j ] ; } } } if ( row < num_rows && col < num_cols ) { const int row_offset = row * block_h ; const int col_offset = col * block_w ; const int block_width = AOMMIN ( width - col_offset , block_w ) ; const int block_height = AOMMIN ( height - row_offset , block_h ) ; float * main_buf = main_data + col_offset + row_offset * stride ; if ( bit_depth == 8 ) { uint8_t * blurred_buf = blurred -> y_buffer + row_offset * blurred -> y_stride + col_offset ; for ( int i = 0 ; i < block_height ; ++ i ) { for ( int j = 0 ; j < block_width ; ++ j ) { main_buf [ j ] = ( float ) blurred_buf [ j ] ; } main_buf += stride ; blurred_buf += blurred -> y_stride ; } } else { uint16_t * blurred_buf = CONVERT_TO_SHORTPTR ( blurred -> y_buffer ) + row_offset * blurred -> y_stride + col_offset ; for ( int i = 0 ; i < block_height ; ++ i ) { for ( int j = 0 ; j < block_width ; ++ j ) { main_buf [ j ] = scale_factor * ( float ) blurred_buf [ j ] ; } main_buf += stride ; blurred_buf += blurred -> y_stride ; } } frames -> col ++ ; if ( frames -> col >= num_cols ) { frames -> col = 0 ; frames -> row ++ ; } return 0 ; } else { return 2 ; } }
A callback function used to pass data to VMAF.
A callback function used to pass data to VMAF .
// Set current block