vp9_aq_360.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #include <math.h>
  11. #include "vpx_ports/mem.h"
  12. #include "vpx_ports/system_state.h"
  13. #include "vp9/encoder/vp9_aq_360.h"
  14. #include "vp9/encoder/vp9_aq_variance.h"
  15. #include "vp9/common/vp9_seg_common.h"
  16. #include "vp9/encoder/vp9_ratectrl.h"
  17. #include "vp9/encoder/vp9_rd.h"
  18. #include "vp9/encoder/vp9_segmentation.h"
  19. static const double rate_ratio[MAX_SEGMENTS] = { 1.0, 0.75, 0.6, 0.5,
  20. 0.4, 0.3, 0.25 };
  21. // Sets segment id 0 for the equatorial region, 1 for temperate region
  22. // and 2 for the polar regions
  23. unsigned int vp9_360aq_segment_id(int mi_row, int mi_rows) {
  24. if (mi_row < mi_rows / 8 || mi_row > mi_rows - mi_rows / 8)
  25. return 2;
  26. else if (mi_row < mi_rows / 4 || mi_row > mi_rows - mi_rows / 4)
  27. return 1;
  28. else
  29. return 0;
  30. }
  31. void vp9_360aq_frame_setup(VP9_COMP *cpi) {
  32. VP9_COMMON *cm = &cpi->common;
  33. struct segmentation *seg = &cm->seg;
  34. int i;
  35. if (frame_is_intra_only(cm) || cpi->force_update_segmentation ||
  36. cm->error_resilient_mode) {
  37. vp9_enable_segmentation(seg);
  38. vp9_clearall_segfeatures(seg);
  39. seg->abs_delta = SEGMENT_DELTADATA;
  40. vpx_clear_system_state();
  41. for (i = 0; i < MAX_SEGMENTS; ++i) {
  42. int qindex_delta =
  43. vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type, cm->base_qindex,
  44. rate_ratio[i], cm->bit_depth);
  45. // We don't allow qindex 0 in a segment if the base value is not 0.
  46. // Q index 0 (lossless) implies 4x4 encoding only and in AQ mode a segment
  47. // Q delta is sometimes applied without going back around the rd loop.
  48. // This could lead to an illegal combination of partition size and q.
  49. if ((cm->base_qindex != 0) && ((cm->base_qindex + qindex_delta) == 0)) {
  50. qindex_delta = -cm->base_qindex + 1;
  51. }
  52. // No need to enable SEG_LVL_ALT_Q for this segment.
  53. if (rate_ratio[i] == 1.0) {
  54. continue;
  55. }
  56. vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, qindex_delta);
  57. vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
  58. }
  59. }
  60. }