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> | 11 #include <math.h> |
12 #include <stdlib.h> | 12 #include <stdlib.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 | 14 |
15 #include "./vpx_config.h" | 15 #include "./vpx_config.h" |
16 #include "./vpx_scale_rtcd.h" | 16 #include "./vpx_scale_rtcd.h" |
17 #include "./vp9_rtcd.h" | 17 #include "./vp9_rtcd.h" |
18 | 18 |
19 #include "vpx_ports/mem.h" | 19 #include "vpx_ports/mem.h" |
| 20 #include "vpx_ports/system_state.h" |
20 #include "vpx_scale/vpx_scale.h" | 21 #include "vpx_scale/vpx_scale.h" |
21 #include "vpx_scale/yv12config.h" | 22 #include "vpx_scale/yv12config.h" |
22 | 23 |
23 #include "vp9/common/vp9_onyxc_int.h" | 24 #include "vp9/common/vp9_onyxc_int.h" |
24 #include "vp9/common/vp9_postproc.h" | 25 #include "vp9/common/vp9_postproc.h" |
25 #include "vp9/common/vp9_systemdependent.h" | |
26 #include "vp9/common/vp9_textblit.h" | 26 #include "vp9/common/vp9_textblit.h" |
27 | 27 |
28 #if CONFIG_VP9_POSTPROC | 28 #if CONFIG_VP9_POSTPROC |
29 static const short kernel5[] = { | 29 static const int16_t kernel5[] = { |
30 1, 1, 4, 1, 1 | 30 1, 1, 4, 1, 1 |
31 }; | 31 }; |
32 | 32 |
33 const short vp9_rv[] = { | 33 const int16_t vp9_rv[] = { |
34 8, 5, 2, 2, 8, 12, 4, 9, 8, 3, | 34 8, 5, 2, 2, 8, 12, 4, 9, 8, 3, |
35 0, 3, 9, 0, 0, 0, 8, 3, 14, 4, | 35 0, 3, 9, 0, 0, 0, 8, 3, 14, 4, |
36 10, 1, 11, 14, 1, 14, 9, 6, 12, 11, | 36 10, 1, 11, 14, 1, 14, 9, 6, 12, 11, |
37 8, 6, 10, 0, 0, 8, 9, 0, 3, 14, | 37 8, 6, 10, 0, 0, 8, 9, 0, 3, 14, |
38 8, 11, 13, 4, 2, 9, 0, 3, 9, 6, | 38 8, 11, 13, 4, 2, 9, 0, 3, 9, 6, |
39 1, 2, 3, 14, 13, 1, 8, 2, 9, 7, | 39 1, 2, 3, 14, 13, 1, 8, 2, 9, 7, |
40 3, 3, 1, 13, 13, 6, 6, 5, 2, 7, | 40 3, 3, 1, 13, 13, 6, 6, 5, 2, 7, |
41 11, 9, 11, 8, 7, 3, 2, 0, 13, 13, | 41 11, 9, 11, 8, 7, 3, 2, 0, 13, 13, |
42 14, 4, 12, 5, 12, 10, 8, 10, 13, 10, | 42 14, 4, 12, 5, 12, 10, 8, 10, 13, 10, |
43 4, 14, 4, 10, 0, 8, 11, 1, 13, 7, | 43 4, 14, 4, 10, 0, 8, 11, 1, 13, 7, |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 void vp9_mbpost_proc_down_c(uint8_t *dst, int pitch, | 313 void vp9_mbpost_proc_down_c(uint8_t *dst, int pitch, |
314 int rows, int cols, int flimit) { | 314 int rows, int cols, int flimit) { |
315 int r, c, i; | 315 int r, c, i; |
316 const short *rv3 = &vp9_rv[63 & rand()]; // NOLINT | 316 const short *rv3 = &vp9_rv[63 & rand()]; // NOLINT |
317 | 317 |
318 for (c = 0; c < cols; c++) { | 318 for (c = 0; c < cols; c++) { |
319 uint8_t *s = &dst[c]; | 319 uint8_t *s = &dst[c]; |
320 int sumsq = 0; | 320 int sumsq = 0; |
321 int sum = 0; | 321 int sum = 0; |
322 uint8_t d[16]; | 322 uint8_t d[16]; |
323 const short *rv2 = rv3 + ((c * 17) & 127); | 323 const int16_t *rv2 = rv3 + ((c * 17) & 127); |
324 | 324 |
325 for (i = -8; i <= 6; i++) { | 325 for (i = -8; i <= 6; i++) { |
326 sumsq += s[i * pitch] * s[i * pitch]; | 326 sumsq += s[i * pitch] * s[i * pitch]; |
327 sum += s[i * pitch]; | 327 sum += s[i * pitch]; |
328 } | 328 } |
329 | 329 |
330 for (r = 0; r < rows + 8; r++) { | 330 for (r = 0; r < rows + 8; r++) { |
331 sumsq += s[7 * pitch] * s[ 7 * pitch] - s[-8 * pitch] * s[-8 * pitch]; | 331 sumsq += s[7 * pitch] * s[ 7 * pitch] - s[-8 * pitch] * s[-8 * pitch]; |
332 sum += s[7 * pitch] - s[-8 * pitch]; | 332 sum += s[7 * pitch] - s[-8 * pitch]; |
333 d[r & 15] = s[0]; | 333 d[r & 15] = s[0]; |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 return 1 / (sigma * sqrt(2.0 * 3.14159265)) * | 537 return 1 / (sigma * sqrt(2.0 * 3.14159265)) * |
538 (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma))); | 538 (exp(-(x - mu) * (x - mu) / (2 * sigma * sigma))); |
539 } | 539 } |
540 | 540 |
541 static void fillrd(struct postproc_state *state, int q, int a) { | 541 static void fillrd(struct postproc_state *state, int q, int a) { |
542 char char_dist[300]; | 542 char char_dist[300]; |
543 | 543 |
544 double sigma; | 544 double sigma; |
545 int ai = a, qi = q, i; | 545 int ai = a, qi = q, i; |
546 | 546 |
547 vp9_clear_system_state(); | 547 vpx_clear_system_state(); |
548 | 548 |
549 sigma = ai + .5 + .6 * (63 - qi) / 63.0; | 549 sigma = ai + .5 + .6 * (63 - qi) / 63.0; |
550 | 550 |
551 /* set up a lookup table of 256 entries that matches | 551 /* set up a lookup table of 256 entries that matches |
552 * a gaussian distribution with sigma determined by q. | 552 * a gaussian distribution with sigma determined by q. |
553 */ | 553 */ |
554 { | 554 { |
555 int next, j; | 555 int next, j; |
556 | 556 |
557 next = 0; | 557 next = 0; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 cm->postproc_state.prev_mip = cm->mip; | 618 cm->postproc_state.prev_mip = cm->mip; |
619 cm->mip = temp; | 619 cm->mip = temp; |
620 | 620 |
621 // Update the upper left visible macroblock ptrs. | 621 // Update the upper left visible macroblock ptrs. |
622 cm->mi = cm->mip + cm->mi_stride + 1; | 622 cm->mi = cm->mip + cm->mi_stride + 1; |
623 cm->postproc_state.prev_mi = cm->postproc_state.prev_mip + cm->mi_stride + 1; | 623 cm->postproc_state.prev_mi = cm->postproc_state.prev_mip + cm->mi_stride + 1; |
624 } | 624 } |
625 | 625 |
626 int vp9_post_proc_frame(struct VP9Common *cm, | 626 int vp9_post_proc_frame(struct VP9Common *cm, |
627 YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *ppflags) { | 627 YV12_BUFFER_CONFIG *dest, vp9_ppflags_t *ppflags) { |
628 const int q = MIN(105, cm->lf.filter_level * 2); | 628 const int q = VPXMIN(105, cm->lf.filter_level * 2); |
629 const int flags = ppflags->post_proc_flag; | 629 const int flags = ppflags->post_proc_flag; |
630 YV12_BUFFER_CONFIG *const ppbuf = &cm->post_proc_buffer; | 630 YV12_BUFFER_CONFIG *const ppbuf = &cm->post_proc_buffer; |
631 struct postproc_state *const ppstate = &cm->postproc_state; | 631 struct postproc_state *const ppstate = &cm->postproc_state; |
632 | 632 |
633 if (!cm->frame_to_show) | 633 if (!cm->frame_to_show) |
634 return -1; | 634 return -1; |
635 | 635 |
636 if (!flags) { | 636 if (!flags) { |
637 *dest = *cm->frame_to_show; | 637 *dest = *cm->frame_to_show; |
638 return 0; | 638 return 0; |
639 } | 639 } |
640 | 640 |
641 vp9_clear_system_state(); | 641 vpx_clear_system_state(); |
642 | 642 |
643 // Alloc memory for prev_mip in the first frame. | 643 // Alloc memory for prev_mip in the first frame. |
644 if (cm->current_video_frame == 1) { | 644 if (cm->current_video_frame == 1) { |
645 cm->postproc_state.last_base_qindex = cm->base_qindex; | 645 cm->postproc_state.last_base_qindex = cm->base_qindex; |
646 cm->postproc_state.last_frame_valid = 1; | 646 cm->postproc_state.last_frame_valid = 1; |
647 ppstate->prev_mip = vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip)); | 647 ppstate->prev_mip = vpx_calloc(cm->mi_alloc_size, sizeof(*cm->mip)); |
648 if (!ppstate->prev_mip) { | 648 if (!ppstate->prev_mip) { |
649 return 1; | 649 return 1; |
650 } | 650 } |
651 ppstate->prev_mi = ppstate->prev_mip + cm->mi_stride + 1; | 651 ppstate->prev_mi = ppstate->prev_mip + cm->mi_stride + 1; |
652 memset(ppstate->prev_mip, 0, | 652 memset(ppstate->prev_mip, 0, |
653 cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); | 653 cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip)); |
654 } | 654 } |
655 | 655 |
656 // Allocate post_proc_buffer_int if needed. | 656 // Allocate post_proc_buffer_int if needed. |
657 if ((flags & VP9D_MFQE) && !cm->post_proc_buffer_int.buffer_alloc) { | 657 if ((flags & VP9D_MFQE) && !cm->post_proc_buffer_int.buffer_alloc) { |
658 if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) { | 658 if ((flags & VP9D_DEMACROBLOCK) || (flags & VP9D_DEBLOCK)) { |
659 const int width = ALIGN_POWER_OF_TWO(cm->width, 4); | 659 const int width = ALIGN_POWER_OF_TWO(cm->width, 4); |
660 const int height = ALIGN_POWER_OF_TWO(cm->height, 4); | 660 const int height = ALIGN_POWER_OF_TWO(cm->height, 4); |
661 | 661 |
662 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer_int, width, height, | 662 if (vpx_alloc_frame_buffer(&cm->post_proc_buffer_int, width, height, |
663 cm->subsampling_x, cm->subsampling_y, | 663 cm->subsampling_x, cm->subsampling_y, |
664 #if CONFIG_VP9_HIGHBITDEPTH | 664 #if CONFIG_VP9_HIGHBITDEPTH |
665 cm->use_highbitdepth, | 665 cm->use_highbitdepth, |
666 #endif // CONFIG_VP9_HIGHBITDEPTH | 666 #endif // CONFIG_VP9_HIGHBITDEPTH |
667 VP9_ENC_BORDER_IN_PIXELS, | 667 VP9_ENC_BORDER_IN_PIXELS, |
668 cm->byte_alignment) < 0) { | 668 cm->byte_alignment) < 0) { |
669 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 669 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
670 "Failed to allocate MFQE framebuffer"); | 670 "Failed to allocate MFQE framebuffer"); |
671 } | 671 } |
672 | 672 |
673 // Ensure that postproc is set to all 0s so that post proc | 673 // Ensure that postproc is set to all 0s so that post proc |
674 // doesn't pull random data in from edge. | 674 // doesn't pull random data in from edge. |
675 memset(cm->post_proc_buffer_int.buffer_alloc, 128, | 675 memset(cm->post_proc_buffer_int.buffer_alloc, 128, |
676 cm->post_proc_buffer.frame_size); | 676 cm->post_proc_buffer.frame_size); |
677 } | 677 } |
678 } | 678 } |
679 | 679 |
680 if (vp9_realloc_frame_buffer(&cm->post_proc_buffer, cm->width, cm->height, | 680 if (vpx_realloc_frame_buffer(&cm->post_proc_buffer, cm->width, cm->height, |
681 cm->subsampling_x, cm->subsampling_y, | 681 cm->subsampling_x, cm->subsampling_y, |
682 #if CONFIG_VP9_HIGHBITDEPTH | 682 #if CONFIG_VP9_HIGHBITDEPTH |
683 cm->use_highbitdepth, | 683 cm->use_highbitdepth, |
684 #endif | 684 #endif |
685 VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment, | 685 VP9_DEC_BORDER_IN_PIXELS, cm->byte_alignment, |
686 NULL, NULL, NULL) < 0) | 686 NULL, NULL, NULL) < 0) |
687 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 687 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
688 "Failed to allocate post-processing buffer"); | 688 "Failed to allocate post-processing buffer"); |
689 | 689 |
690 if ((flags & VP9D_MFQE) && cm->current_video_frame >= 2 && | 690 if ((flags & VP9D_MFQE) && cm->current_video_frame >= 2 && |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 /* handle problem with extending borders */ | 736 /* handle problem with extending borders */ |
737 dest->y_width = cm->width; | 737 dest->y_width = cm->width; |
738 dest->y_height = cm->height; | 738 dest->y_height = cm->height; |
739 dest->uv_width = dest->y_width >> cm->subsampling_x; | 739 dest->uv_width = dest->y_width >> cm->subsampling_x; |
740 dest->uv_height = dest->y_height >> cm->subsampling_y; | 740 dest->uv_height = dest->y_height >> cm->subsampling_y; |
741 | 741 |
742 swap_mi_and_prev_mi(cm); | 742 swap_mi_and_prev_mi(cm); |
743 return 0; | 743 return 0; |
744 } | 744 } |
745 #endif // CONFIG_VP9_POSTPROC | 745 #endif // CONFIG_VP9_POSTPROC |
OLD | NEW |