| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <math.h> |
| 12 #include <stdlib.h> |
| 13 #include <stdio.h> |
| 11 | 14 |
| 12 #include "./vpx_config.h" | 15 #include "./vpx_config.h" |
| 13 #include "vpx_scale/yv12config.h" | 16 #include "vpx_scale/yv12config.h" |
| 14 #include "vp9/common/vp9_postproc.h" | 17 #include "vp9/common/vp9_postproc.h" |
| 15 #include "vp9/common/vp9_textblit.h" | 18 #include "vp9/common/vp9_textblit.h" |
| 16 #include "vpx_scale/vpx_scale.h" | 19 #include "vpx_scale/vpx_scale.h" |
| 17 #include "vp9/common/vp9_systemdependent.h" | 20 #include "vp9/common/vp9_systemdependent.h" |
| 18 #include "./vp9_rtcd.h" | 21 #include "./vp9_rtcd.h" |
| 19 #include "./vpx_scale_rtcd.h" | 22 #include "./vpx_scale_rtcd.h" |
| 20 | 23 |
| 21 | |
| 22 #include <math.h> | |
| 23 #include <stdlib.h> | |
| 24 #include <stdio.h> | |
| 25 | |
| 26 #define RGB_TO_YUV(t) \ | 24 #define RGB_TO_YUV(t) \ |
| 27 ( (0.257*(float)(t >> 16)) + (0.504*(float)(t >> 8 & 0xff)) + \ | 25 ( (0.257*(float)(t >> 16)) + (0.504*(float)(t >> 8 & 0xff)) + \ |
| 28 (0.098*(float)(t & 0xff)) + 16), \ | 26 (0.098*(float)(t & 0xff)) + 16), \ |
| 29 (-(0.148*(float)(t >> 16)) - (0.291*(float)(t >> 8 & 0xff)) + \ | 27 (-(0.148*(float)(t >> 16)) - (0.291*(float)(t >> 8 & 0xff)) + \ |
| 30 (0.439*(float)(t & 0xff)) + 128), \ | 28 (0.439*(float)(t & 0xff)) + 128), \ |
| 31 ( (0.439*(float)(t >> 16)) - (0.368*(float)(t >> 8 & 0xff)) - \ | 29 ( (0.439*(float)(t >> 16)) - (0.368*(float)(t >> 8 & 0xff)) - \ |
| 32 (0.071*(float)(t & 0xff)) + 128) | 30 (0.071*(float)(t & 0xff)) + 128) |
| 33 | 31 |
| 34 /* global constants */ | 32 /* global constants */ |
| 35 #if 0 && CONFIG_POSTPROC_VISUALIZER | 33 #if 0 && CONFIG_POSTPROC_VISUALIZER |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 int pitch = src_pixels_per_line; | 146 int pitch = src_pixels_per_line; |
| 149 uint8_t d[8]; | 147 uint8_t d[8]; |
| 150 (void)dst_pixels_per_line; | 148 (void)dst_pixels_per_line; |
| 151 | 149 |
| 152 for (row = 0; row < rows; row++) { | 150 for (row = 0; row < rows; row++) { |
| 153 /* post_proc_down for one row */ | 151 /* post_proc_down for one row */ |
| 154 p_src = src_ptr; | 152 p_src = src_ptr; |
| 155 p_dst = dst_ptr; | 153 p_dst = dst_ptr; |
| 156 | 154 |
| 157 for (col = 0; col < cols; col++) { | 155 for (col = 0; col < cols; col++) { |
| 158 | |
| 159 int kernel = 4; | 156 int kernel = 4; |
| 160 int v = p_src[col]; | 157 int v = p_src[col]; |
| 161 | 158 |
| 162 for (i = -2; i <= 2; i++) { | 159 for (i = -2; i <= 2; i++) { |
| 163 if (abs(v - p_src[col + i * pitch]) > flimit) | 160 if (abs(v - p_src[col + i * pitch]) > flimit) |
| 164 goto down_skip_convolve; | 161 goto down_skip_convolve; |
| 165 | 162 |
| 166 kernel += kernel5[2 + i] * p_src[col + i * pitch]; | 163 kernel += kernel5[2 + i] * p_src[col + i * pitch]; |
| 167 } | 164 } |
| 168 | 165 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 s[c - 8] = d[(c - 8) & 15]; | 247 s[c - 8] = d[(c - 8) & 15]; |
| 251 } | 248 } |
| 252 | 249 |
| 253 s += pitch; | 250 s += pitch; |
| 254 } | 251 } |
| 255 } | 252 } |
| 256 | 253 |
| 257 void vp9_mbpost_proc_down_c(uint8_t *dst, int pitch, | 254 void vp9_mbpost_proc_down_c(uint8_t *dst, int pitch, |
| 258 int rows, int cols, int flimit) { | 255 int rows, int cols, int flimit) { |
| 259 int r, c, i; | 256 int r, c, i; |
| 260 const short *rv3 = &vp9_rv[63 & rand()]; | 257 const short *rv3 = &vp9_rv[63 & rand()]; // NOLINT |
| 261 | 258 |
| 262 for (c = 0; c < cols; c++) { | 259 for (c = 0; c < cols; c++) { |
| 263 uint8_t *s = &dst[c]; | 260 uint8_t *s = &dst[c]; |
| 264 int sumsq = 0; | 261 int sumsq = 0; |
| 265 int sum = 0; | 262 int sum = 0; |
| 266 uint8_t d[16]; | 263 uint8_t d[16]; |
| 267 const short *rv2 = rv3 + ((c * 17) & 127); | 264 const short *rv2 = rv3 + ((c * 17) & 127); |
| 268 | 265 |
| 269 for (i = -8; i <= 6; i++) { | 266 for (i = -8; i <= 6; i++) { |
| 270 sumsq += s[i * pitch] * s[i * pitch]; | 267 sumsq += s[i * pitch] * s[i * pitch]; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 for (i = -32; i < 32; i++) { | 398 for (i = -32; i < 32; i++) { |
| 402 int a = (int)(.5 + 256 * vp9_gaussian(sigma, 0, i)); | 399 int a = (int)(.5 + 256 * vp9_gaussian(sigma, 0, i)); |
| 403 | 400 |
| 404 if (a) { | 401 if (a) { |
| 405 for (j = 0; j < a; j++) { | 402 for (j = 0; j < a; j++) { |
| 406 char_dist[next + j] = (char) i; | 403 char_dist[next + j] = (char) i; |
| 407 } | 404 } |
| 408 | 405 |
| 409 next = next + j; | 406 next = next + j; |
| 410 } | 407 } |
| 411 | |
| 412 } | 408 } |
| 413 | 409 |
| 414 for (; next < 256; next++) | 410 for (; next < 256; next++) |
| 415 char_dist[next] = 0; | 411 char_dist[next] = 0; |
| 416 } | 412 } |
| 417 | 413 |
| 418 for (i = 0; i < 3072; i++) { | 414 for (i = 0; i < 3072; i++) { |
| 419 state->noise[i] = char_dist[rand() & 0xff]; | 415 state->noise[i] = char_dist[rand() & 0xff]; // NOLINT |
| 420 } | 416 } |
| 421 | 417 |
| 422 for (i = 0; i < 16; i++) { | 418 for (i = 0; i < 16; i++) { |
| 423 state->blackclamp[i] = -char_dist[0]; | 419 state->blackclamp[i] = -char_dist[0]; |
| 424 state->whiteclamp[i] = -char_dist[0]; | 420 state->whiteclamp[i] = -char_dist[0]; |
| 425 state->bothclamp[i] = -2 * char_dist[0]; | 421 state->bothclamp[i] = -2 * char_dist[0]; |
| 426 } | 422 } |
| 427 | 423 |
| 428 state->last_q = q; | 424 state->last_q = q; |
| 429 state->last_noise = a; | 425 state->last_noise = a; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 cm->postproc_state.whiteclamp, | 669 cm->postproc_state.whiteclamp, |
| 674 cm->postproc_state.bothclamp, | 670 cm->postproc_state.bothclamp, |
| 675 cm->post_proc_buffer.y_width, | 671 cm->post_proc_buffer.y_width, |
| 676 cm->post_proc_buffer.y_height, | 672 cm->post_proc_buffer.y_height, |
| 677 cm->post_proc_buffer.y_stride); | 673 cm->post_proc_buffer.y_stride); |
| 678 } | 674 } |
| 679 | 675 |
| 680 #if 0 && CONFIG_POSTPROC_VISUALIZER | 676 #if 0 && CONFIG_POSTPROC_VISUALIZER |
| 681 if (flags & VP9D_DEBUG_TXT_FRAME_INFO) { | 677 if (flags & VP9D_DEBUG_TXT_FRAME_INFO) { |
| 682 char message[512]; | 678 char message[512]; |
| 683 sprintf(message, "F%1dG%1dQ%3dF%3dP%d_s%dx%d", | 679 snprintf(message, sizeof(message) -1, |
| 684 (cm->frame_type == KEY_FRAME), | 680 "F%1dG%1dQ%3dF%3dP%d_s%dx%d", |
| 685 cm->refresh_golden_frame, | 681 (cm->frame_type == KEY_FRAME), |
| 686 cm->base_qindex, | 682 cm->refresh_golden_frame, |
| 687 cm->filter_level, | 683 cm->base_qindex, |
| 688 flags, | 684 cm->filter_level, |
| 689 cm->mb_cols, cm->mb_rows); | 685 flags, |
| 686 cm->mb_cols, cm->mb_rows); |
| 690 vp9_blit_text(message, cm->post_proc_buffer.y_buffer, | 687 vp9_blit_text(message, cm->post_proc_buffer.y_buffer, |
| 691 cm->post_proc_buffer.y_stride); | 688 cm->post_proc_buffer.y_stride); |
| 692 } | 689 } |
| 693 | 690 |
| 694 if (flags & VP9D_DEBUG_TXT_MBLK_MODES) { | 691 if (flags & VP9D_DEBUG_TXT_MBLK_MODES) { |
| 695 int i, j; | 692 int i, j; |
| 696 uint8_t *y_ptr; | 693 uint8_t *y_ptr; |
| 697 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer; | 694 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer; |
| 698 int mb_rows = post->y_height >> 4; | 695 int mb_rows = post->y_height >> 4; |
| 699 int mb_cols = post->y_width >> 4; | 696 int mb_cols = post->y_width >> 4; |
| 700 int mb_index = 0; | 697 int mb_index = 0; |
| 701 MODE_INFO *mi = cm->mi; | 698 MODE_INFO *mi = cm->mi; |
| 702 | 699 |
| 703 y_ptr = post->y_buffer + 4 * post->y_stride + 4; | 700 y_ptr = post->y_buffer + 4 * post->y_stride + 4; |
| 704 | 701 |
| 705 /* vp9_filter each macro block */ | 702 /* vp9_filter each macro block */ |
| 706 for (i = 0; i < mb_rows; i++) { | 703 for (i = 0; i < mb_rows; i++) { |
| 707 for (j = 0; j < mb_cols; j++) { | 704 for (j = 0; j < mb_cols; j++) { |
| 708 char zz[4]; | 705 char zz[4]; |
| 709 | 706 |
| 710 sprintf(zz, "%c", mi[mb_index].mbmi.mode + 'a'); | 707 snprintf(zz, sizeof(zz) - 1, "%c", mi[mb_index].mbmi.mode + 'a'); |
| 711 | 708 |
| 712 vp9_blit_text(zz, y_ptr, post->y_stride); | 709 vp9_blit_text(zz, y_ptr, post->y_stride); |
| 713 mb_index++; | 710 mb_index++; |
| 714 y_ptr += 16; | 711 y_ptr += 16; |
| 715 } | 712 } |
| 716 | 713 |
| 717 mb_index++; /* border */ | 714 mb_index++; /* border */ |
| 718 y_ptr += post->y_stride * 16 - post->y_width; | 715 y_ptr += post->y_stride * 16 - post->y_width; |
| 719 | |
| 720 } | 716 } |
| 721 } | 717 } |
| 722 | 718 |
| 723 if (flags & VP9D_DEBUG_TXT_DC_DIFF) { | 719 if (flags & VP9D_DEBUG_TXT_DC_DIFF) { |
| 724 int i, j; | 720 int i, j; |
| 725 uint8_t *y_ptr; | 721 uint8_t *y_ptr; |
| 726 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer; | 722 YV12_BUFFER_CONFIG *post = &cm->post_proc_buffer; |
| 727 int mb_rows = post->y_height >> 4; | 723 int mb_rows = post->y_height >> 4; |
| 728 int mb_cols = post->y_width >> 4; | 724 int mb_cols = post->y_width >> 4; |
| 729 int mb_index = 0; | 725 int mb_index = 0; |
| 730 MODE_INFO *mi = cm->mi; | 726 MODE_INFO *mi = cm->mi; |
| 731 | 727 |
| 732 y_ptr = post->y_buffer + 4 * post->y_stride + 4; | 728 y_ptr = post->y_buffer + 4 * post->y_stride + 4; |
| 733 | 729 |
| 734 /* vp9_filter each macro block */ | 730 /* vp9_filter each macro block */ |
| 735 for (i = 0; i < mb_rows; i++) { | 731 for (i = 0; i < mb_rows; i++) { |
| 736 for (j = 0; j < mb_cols; j++) { | 732 for (j = 0; j < mb_cols; j++) { |
| 737 char zz[4]; | 733 char zz[4]; |
| 738 int dc_diff = !(mi[mb_index].mbmi.mode != I4X4_PRED && | 734 int dc_diff = !(mi[mb_index].mbmi.mode != I4X4_PRED && |
| 739 mi[mb_index].mbmi.mode != SPLITMV && | 735 mi[mb_index].mbmi.mode != SPLITMV && |
| 740 mi[mb_index].mbmi.skip_coeff); | 736 mi[mb_index].mbmi.skip_coeff); |
| 741 | 737 |
| 742 if (cm->frame_type == KEY_FRAME) | 738 if (cm->frame_type == KEY_FRAME) |
| 743 sprintf(zz, "a"); | 739 snprintf(zz, sizeof(zz) - 1, "a"); |
| 744 else | 740 else |
| 745 sprintf(zz, "%c", dc_diff + '0'); | 741 snprintf(zz, sizeof(zz) - 1, "%c", dc_diff + '0'); |
| 746 | 742 |
| 747 vp9_blit_text(zz, y_ptr, post->y_stride); | 743 vp9_blit_text(zz, y_ptr, post->y_stride); |
| 748 mb_index++; | 744 mb_index++; |
| 749 y_ptr += 16; | 745 y_ptr += 16; |
| 750 } | 746 } |
| 751 | 747 |
| 752 mb_index++; /* border */ | 748 mb_index++; /* border */ |
| 753 y_ptr += post->y_stride * 16 - post->y_width; | 749 y_ptr += post->y_stride * 16 - post->y_width; |
| 754 | |
| 755 } | 750 } |
| 756 } | 751 } |
| 757 | 752 |
| 758 if (flags & VP9D_DEBUG_TXT_RATE_INFO) { | 753 if (flags & VP9D_DEBUG_TXT_RATE_INFO) { |
| 759 char message[512]; | 754 char message[512]; |
| 760 snprintf(message, sizeof(message), | 755 snprintf(message, sizeof(message), |
| 761 "Bitrate: %10.2f framerate: %10.2f ", | 756 "Bitrate: %10.2f framerate: %10.2f ", |
| 762 cm->bitrate, cm->framerate); | 757 cm->bitrate, cm->framerate); |
| 763 vp9_blit_text(message, cm->post_proc_buffer.y_buffer, | 758 vp9_blit_text(message, cm->post_proc_buffer.y_buffer, |
| 764 cm->post_proc_buffer.y_stride); | 759 cm->post_proc_buffer.y_stride); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 | 882 |
| 888 x1 = lx0 + (mv->col >> 3); | 883 x1 = lx0 + (mv->col >> 3); |
| 889 y1 = ly0 + (mv->row >> 3); | 884 y1 = ly0 + (mv->row >> 3); |
| 890 | 885 |
| 891 if (x1 != lx0 && y1 != ly0) { | 886 if (x1 != lx0 && y1 != ly0) { |
| 892 constrain_line(lx0, &x1, ly0 - 1, &y1, width, height); | 887 constrain_line(lx0, &x1, ly0 - 1, &y1, width, height); |
| 893 vp9_blit_line(lx0, x1, ly0 - 1, y1, y_buffer, y_stride); | 888 vp9_blit_line(lx0, x1, ly0 - 1, y1, y_buffer, y_stride); |
| 894 | 889 |
| 895 constrain_line(lx0, &x1, ly0 + 1, &y1, width, height); | 890 constrain_line(lx0, &x1, ly0 + 1, &y1, width, height); |
| 896 vp9_blit_line(lx0, x1, ly0 + 1, y1, y_buffer, y_stride); | 891 vp9_blit_line(lx0, x1, ly0 + 1, y1, y_buffer, y_stride); |
| 897 } else | 892 } else { |
| 898 vp9_blit_line(lx0, x1, ly0, y1, y_buffer, y_stride); | 893 vp9_blit_line(lx0, x1, ly0, y1, y_buffer, y_stride); |
| 894 } |
| 899 } | 895 } |
| 900 | 896 |
| 901 mi++; | 897 mi++; |
| 902 } | 898 } |
| 903 mi++; | 899 mi++; |
| 904 } | 900 } |
| 905 } | 901 } |
| 906 | 902 |
| 907 /* Color in block modes */ | 903 /* Color in block modes */ |
| 908 if ((flags & VP9D_DEBUG_CLR_BLK_MODES) | 904 if ((flags & VP9D_DEBUG_CLR_BLK_MODES) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 *dest = cm->post_proc_buffer; | 1005 *dest = cm->post_proc_buffer; |
| 1010 | 1006 |
| 1011 /* handle problem with extending borders */ | 1007 /* handle problem with extending borders */ |
| 1012 dest->y_width = cm->width; | 1008 dest->y_width = cm->width; |
| 1013 dest->y_height = cm->height; | 1009 dest->y_height = cm->height; |
| 1014 dest->uv_width = dest->y_width >> cm->subsampling_x; | 1010 dest->uv_width = dest->y_width >> cm->subsampling_x; |
| 1015 dest->uv_height = dest->y_height >> cm->subsampling_y; | 1011 dest->uv_height = dest->y_height >> cm->subsampling_y; |
| 1016 | 1012 |
| 1017 return 0; | 1013 return 0; |
| 1018 } | 1014 } |
| OLD | NEW |