/* * Copyright (c) 2010 The WebM project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
staticvoid yv12_copy_partial_frame(YV12_BUFFER_CONFIG *src_ybc,
YV12_BUFFER_CONFIG *dst_ybc) { unsignedchar *src_y, *dst_y; int yheight; int ystride; int yoffset; int linestocopy;
/* number of MB rows to use in partial filtering */
linestocopy = (yheight >> 4) / PARTIAL_FRAME_FRACTION;
linestocopy = linestocopy ? linestocopy << 4 : 16; /* 16 lines per MB */
/* Copy extra 4 so that full filter context is available if filtering done * on the copied partial frame and not original. Partial filter does mb * filtering for top row also, which can modify3 pixels above.
*/
linestocopy += 4; /* partial image starts at ~middle of frame (macroblock border)*/
yoffset = ystride * (((yheight >> 5) * 16) - 4);
src_y = src_ybc->y_buffer + yoffset;
dst_y = dst_ybc->y_buffer + yoffset;
// The border will be used in vp8_loop_filter_partial_frame so it needs to be // extended to avoid a valgrind warning. constunsignedchar *const top_row = src_ybc->y_buffer; for (int i = yoffset; i < 0; i += ystride, --linestocopy) {
memcpy(dst_y, top_row, ystride);
dst_y += ystride;
src_y += ystride;
}
memcpy(dst_y, src_y, ystride * linestocopy);
}
staticint calc_partial_ssl_err(YV12_BUFFER_CONFIG *source,
YV12_BUFFER_CONFIG *dest) { int i, j; int Total = 0; int srcoffset, dstoffset; unsignedchar *src = source->y_buffer; unsignedchar *dst = dest->y_buffer;
int linestocopy;
/* number of MB rows to use in partial filtering */
linestocopy = (source->y_height >> 4) / PARTIAL_FRAME_FRACTION;
linestocopy = linestocopy ? linestocopy << 4 : 16; /* 16 lines per MB */
/* Loop through the Y plane raw and reconstruction data summing * (square differences)
*/ for (i = 0; i < linestocopy; i += 16) { for (j = 0; j < source->y_width; j += 16) { unsignedint sse;
Total += vpx_mse16x16(src + j, source->y_stride, dst + j, dest->y_stride,
&sse);
}
/* Enforce a maximum filter level based upon baseline Q */ staticint get_max_filter_level(VP8_COMP *cpi, int base_qindex) { /* PGW August 2006: Highest filter values almost always a bad idea */
/* jbb chg: 20100118 - not so any more with this overquant stuff allow * high values with lots of intra coming in.
*/ int max_filter_level = MAX_LOOP_FILTER;
(void)base_qindex;
int best_err = 0; int filt_err = 0; int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); int max_filter_level = get_max_filter_level(cpi, cm->base_qindex); int filt_val; int best_filt_val;
YV12_BUFFER_CONFIG *saved_frame = cm->frame_to_show;
/* Replace unfiltered frame buffer with a new one */
cm->frame_to_show = &cpi->pick_lf_lvl_frame;
/* Start the search at the previous frame filter level unless it is * now out of range.
*/ if (cm->filter_level < min_filter_level) {
cm->filter_level = min_filter_level;
} elseif (cm->filter_level > max_filter_level) {
cm->filter_level = max_filter_level;
}
/* Get the err using the previous frame's filter value. */
/* Copy the unfiltered / processed recon buffer to the new buffer */
yv12_copy_partial_frame(saved_frame, cm->frame_to_show);
vp8_loop_filter_partial_frame(cm, &cpi->mb.e_mbd, filt_val);
/* Get the err for filtered frame */
filt_err = calc_partial_ssl_err(sd, cm->frame_to_show);
/* Update the best case record or exit loop. */ if (filt_err < best_err) { /* Do not raise filter level if improvement is < 1 part * in 4096
*/
best_err = filt_err - (filt_err >> 10);
/* Stub function for now Alt LF not used */ void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val) {
MACROBLOCKD *mbd = &cpi->mb.e_mbd;
(void)filt_val;
int best_err = 0; int filt_err = 0; int min_filter_level = get_min_filter_level(cpi, cm->base_qindex); int max_filter_level = get_max_filter_level(cpi, cm->base_qindex);
int filter_step; int filt_high = 0; int filt_mid; int filt_low = 0; int filt_best; int filt_direction = 0;
/* Bias against raising loop filter and in favor of lowering it */ int Bias = 0;
/* If value is close to the best so far then bias towards a * lower loop filter value.
*/ if ((filt_err - Bias) < best_err) { /* Was it actually better than the previous best? */ if (filt_err < best_err) best_err = filt_err;
filt_best = filt_low;
}
}
/* Now look at filt_high */ if ((filt_direction >= 0) && (filt_high != filt_mid)) { if (ss_err[filt_high] == 0) {
vpx_yv12_copy_y(saved_frame, cm->frame_to_show);
vp8cx_set_alt_lf_level(cpi, filt_high);
vp8_loop_filter_frame_yonly(cm, &cpi->mb.e_mbd, filt_high);
/* Was it better than the previous best? */ if (filt_err < (best_err - Bias)) {
best_err = filt_err;
filt_best = filt_high;
}
}
/* Half the step distance if the best filter value was the same * as last time
*/ if (filt_best == filt_mid) {
filter_step = filter_step / 2;
filt_direction = 0;
} else {
filt_direction = (filt_best < filt_mid) ? -1 : 1;
filt_mid = filt_best;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.