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 <stdio.h> | 12 #include <stdio.h> |
13 #include <limits.h> | 13 #include <limits.h> |
14 | 14 |
15 #include "./vp9_rtcd.h" | 15 #include "./vp9_rtcd.h" |
16 #include "./vpx_config.h" | 16 #include "./vpx_config.h" |
17 #include "./vpx_dsp_rtcd.h" | 17 #include "./vpx_dsp_rtcd.h" |
18 #include "./vpx_scale_rtcd.h" | 18 #include "./vpx_scale_rtcd.h" |
19 #include "vpx/internal/vpx_psnr.h" | 19 #include "vpx/internal/vpx_psnr.h" |
| 20 #include "vpx_dsp/vpx_dsp_common.h" |
20 #include "vpx_dsp/vpx_filter.h" | 21 #include "vpx_dsp/vpx_filter.h" |
21 #if CONFIG_INTERNAL_STATS | 22 #if CONFIG_INTERNAL_STATS |
22 #include "vpx_dsp/ssim.h" | 23 #include "vpx_dsp/ssim.h" |
23 #endif | 24 #endif |
24 #include "vpx_ports/mem.h" | 25 #include "vpx_ports/mem.h" |
25 #include "vpx_ports/system_state.h" | 26 #include "vpx_ports/system_state.h" |
26 #include "vpx_ports/vpx_timer.h" | 27 #include "vpx_ports/vpx_timer.h" |
27 | 28 |
28 #include "vp9/common/vp9_alloccommon.h" | 29 #include "vp9/common/vp9_alloccommon.h" |
29 #include "vp9/common/vp9_filter.h" | 30 #include "vp9/common/vp9_filter.h" |
(...skipping 1415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1445 // And a place holder structure is the coding context | 1446 // And a place holder structure is the coding context |
1446 // for use if we want to save and restore it | 1447 // for use if we want to save and restore it |
1447 vpx_free(cpi->coding_context.last_frame_seg_map_copy); | 1448 vpx_free(cpi->coding_context.last_frame_seg_map_copy); |
1448 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, | 1449 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, |
1449 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1450 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
1450 } | 1451 } |
1451 | 1452 |
1452 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { | 1453 void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) { |
1453 VP9_COMMON *const cm = &cpi->common; | 1454 VP9_COMMON *const cm = &cpi->common; |
1454 RATE_CONTROL *const rc = &cpi->rc; | 1455 RATE_CONTROL *const rc = &cpi->rc; |
| 1456 int last_w = cpi->oxcf.width; |
| 1457 int last_h = cpi->oxcf.height; |
1455 | 1458 |
1456 if (cm->profile != oxcf->profile) | 1459 if (cm->profile != oxcf->profile) |
1457 cm->profile = oxcf->profile; | 1460 cm->profile = oxcf->profile; |
1458 cm->bit_depth = oxcf->bit_depth; | 1461 cm->bit_depth = oxcf->bit_depth; |
1459 cm->color_space = oxcf->color_space; | 1462 cm->color_space = oxcf->color_space; |
1460 | 1463 |
1461 if (cm->profile <= PROFILE_1) | 1464 if (cm->profile <= PROFILE_1) |
1462 assert(cm->bit_depth == VPX_BITS_8); | 1465 assert(cm->bit_depth == VPX_BITS_8); |
1463 else | 1466 else |
1464 assert(cm->bit_depth > VPX_BITS_8); | 1467 assert(cm->bit_depth > VPX_BITS_8); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1497 vp9_new_framerate(cpi, cpi->framerate); | 1500 vp9_new_framerate(cpi, cpi->framerate); |
1498 | 1501 |
1499 // Set absolute upper and lower quality limits | 1502 // Set absolute upper and lower quality limits |
1500 rc->worst_quality = cpi->oxcf.worst_allowed_q; | 1503 rc->worst_quality = cpi->oxcf.worst_allowed_q; |
1501 rc->best_quality = cpi->oxcf.best_allowed_q; | 1504 rc->best_quality = cpi->oxcf.best_allowed_q; |
1502 | 1505 |
1503 cm->interp_filter = cpi->sf.default_interp_filter; | 1506 cm->interp_filter = cpi->sf.default_interp_filter; |
1504 | 1507 |
1505 cm->display_width = cpi->oxcf.width; | 1508 cm->display_width = cpi->oxcf.width; |
1506 cm->display_height = cpi->oxcf.height; | 1509 cm->display_height = cpi->oxcf.height; |
1507 cm->width = cpi->oxcf.width; | 1510 if (last_w != cpi->oxcf.width || last_h != cpi->oxcf.height) { |
1508 cm->height = cpi->oxcf.height; | 1511 cm->width = cpi->oxcf.width; |
| 1512 cm->height = cpi->oxcf.height; |
| 1513 } |
1509 | 1514 |
1510 if (cpi->initial_width) { | 1515 if (cpi->initial_width) { |
1511 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { | 1516 if (cm->width > cpi->initial_width || cm->height > cpi->initial_height) { |
1512 vp9_free_context_buffers(cm); | 1517 vp9_free_context_buffers(cm); |
1513 alloc_compressor_data(cpi); | 1518 alloc_compressor_data(cpi); |
1514 realloc_segmentation_maps(cpi); | 1519 realloc_segmentation_maps(cpi); |
1515 cpi->initial_width = cpi->initial_height = 0; | 1520 cpi->initial_width = cpi->initial_height = 0; |
1516 } | 1521 } |
1517 } | 1522 } |
1518 update_frame_size(cpi); | 1523 update_frame_size(cpi); |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2240 return total_sse; | 2245 return total_sse; |
2241 } | 2246 } |
2242 #endif // CONFIG_VP9_HIGHBITDEPTH | 2247 #endif // CONFIG_VP9_HIGHBITDEPTH |
2243 | 2248 |
2244 typedef struct { | 2249 typedef struct { |
2245 double psnr[4]; // total/y/u/v | 2250 double psnr[4]; // total/y/u/v |
2246 uint64_t sse[4]; // total/y/u/v | 2251 uint64_t sse[4]; // total/y/u/v |
2247 uint32_t samples[4]; // total/y/u/v | 2252 uint32_t samples[4]; // total/y/u/v |
2248 } PSNR_STATS; | 2253 } PSNR_STATS; |
2249 | 2254 |
2250 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, | |
2251 PSNR_STATS *psnr) { | |
2252 static const double peak = 255.0; | |
2253 const int widths[3] = { | |
2254 a->y_crop_width, a->uv_crop_width, a->uv_crop_width}; | |
2255 const int heights[3] = { | |
2256 a->y_crop_height, a->uv_crop_height, a->uv_crop_height}; | |
2257 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer}; | |
2258 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; | |
2259 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer}; | |
2260 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; | |
2261 int i; | |
2262 uint64_t total_sse = 0; | |
2263 uint32_t total_samples = 0; | |
2264 | |
2265 for (i = 0; i < 3; ++i) { | |
2266 const int w = widths[i]; | |
2267 const int h = heights[i]; | |
2268 const uint32_t samples = w * h; | |
2269 const uint64_t sse = get_sse(a_planes[i], a_strides[i], | |
2270 b_planes[i], b_strides[i], | |
2271 w, h); | |
2272 psnr->sse[1 + i] = sse; | |
2273 psnr->samples[1 + i] = samples; | |
2274 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, peak, (double)sse); | |
2275 | |
2276 total_sse += sse; | |
2277 total_samples += samples; | |
2278 } | |
2279 | |
2280 psnr->sse[0] = total_sse; | |
2281 psnr->samples[0] = total_samples; | |
2282 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, | |
2283 (double)total_sse); | |
2284 } | |
2285 | |
2286 #if CONFIG_VP9_HIGHBITDEPTH | 2255 #if CONFIG_VP9_HIGHBITDEPTH |
2287 static void calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, | 2256 static void calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, |
2288 const YV12_BUFFER_CONFIG *b, | 2257 const YV12_BUFFER_CONFIG *b, |
2289 PSNR_STATS *psnr, | 2258 PSNR_STATS *psnr, |
2290 unsigned int bit_depth, | 2259 unsigned int bit_depth, |
2291 unsigned int in_bit_depth) { | 2260 unsigned int in_bit_depth) { |
2292 const int widths[3] = | 2261 const int widths[3] = |
2293 {a->y_crop_width, a->uv_crop_width, a->uv_crop_width }; | 2262 {a->y_crop_width, a->uv_crop_width, a->uv_crop_width }; |
2294 const int heights[3] = | 2263 const int heights[3] = |
2295 {a->y_crop_height, a->uv_crop_height, a->uv_crop_height}; | 2264 {a->y_crop_height, a->uv_crop_height, a->uv_crop_height}; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2328 | 2297 |
2329 total_sse += sse; | 2298 total_sse += sse; |
2330 total_samples += samples; | 2299 total_samples += samples; |
2331 } | 2300 } |
2332 | 2301 |
2333 psnr->sse[0] = total_sse; | 2302 psnr->sse[0] = total_sse; |
2334 psnr->samples[0] = total_samples; | 2303 psnr->samples[0] = total_samples; |
2335 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, | 2304 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, |
2336 (double)total_sse); | 2305 (double)total_sse); |
2337 } | 2306 } |
| 2307 |
| 2308 #else // !CONFIG_VP9_HIGHBITDEPTH |
| 2309 |
| 2310 static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, |
| 2311 PSNR_STATS *psnr) { |
| 2312 static const double peak = 255.0; |
| 2313 const int widths[3] = { |
| 2314 a->y_crop_width, a->uv_crop_width, a->uv_crop_width}; |
| 2315 const int heights[3] = { |
| 2316 a->y_crop_height, a->uv_crop_height, a->uv_crop_height}; |
| 2317 const uint8_t *a_planes[3] = {a->y_buffer, a->u_buffer, a->v_buffer}; |
| 2318 const int a_strides[3] = {a->y_stride, a->uv_stride, a->uv_stride}; |
| 2319 const uint8_t *b_planes[3] = {b->y_buffer, b->u_buffer, b->v_buffer}; |
| 2320 const int b_strides[3] = {b->y_stride, b->uv_stride, b->uv_stride}; |
| 2321 int i; |
| 2322 uint64_t total_sse = 0; |
| 2323 uint32_t total_samples = 0; |
| 2324 |
| 2325 for (i = 0; i < 3; ++i) { |
| 2326 const int w = widths[i]; |
| 2327 const int h = heights[i]; |
| 2328 const uint32_t samples = w * h; |
| 2329 const uint64_t sse = get_sse(a_planes[i], a_strides[i], |
| 2330 b_planes[i], b_strides[i], |
| 2331 w, h); |
| 2332 psnr->sse[1 + i] = sse; |
| 2333 psnr->samples[1 + i] = samples; |
| 2334 psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, peak, (double)sse); |
| 2335 |
| 2336 total_sse += sse; |
| 2337 total_samples += samples; |
| 2338 } |
| 2339 |
| 2340 psnr->sse[0] = total_sse; |
| 2341 psnr->samples[0] = total_samples; |
| 2342 psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, peak, |
| 2343 (double)total_sse); |
| 2344 } |
2338 #endif // CONFIG_VP9_HIGHBITDEPTH | 2345 #endif // CONFIG_VP9_HIGHBITDEPTH |
2339 | 2346 |
2340 static void generate_psnr_packet(VP9_COMP *cpi) { | 2347 static void generate_psnr_packet(VP9_COMP *cpi) { |
2341 struct vpx_codec_cx_pkt pkt; | 2348 struct vpx_codec_cx_pkt pkt; |
2342 int i; | 2349 int i; |
2343 PSNR_STATS psnr; | 2350 PSNR_STATS psnr; |
2344 #if CONFIG_VP9_HIGHBITDEPTH | 2351 #if CONFIG_VP9_HIGHBITDEPTH |
2345 calc_highbd_psnr(cpi->Source, cpi->common.frame_to_show, &psnr, | 2352 calc_highbd_psnr(cpi->Source, cpi->common.frame_to_show, &psnr, |
2346 cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); | 2353 cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); |
2347 #else | 2354 #else |
(...skipping 2380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4728 if (flags & VP8_EFLAG_NO_UPD_ARF) | 4735 if (flags & VP8_EFLAG_NO_UPD_ARF) |
4729 upd ^= VP9_ALT_FLAG; | 4736 upd ^= VP9_ALT_FLAG; |
4730 | 4737 |
4731 vp9_update_reference(cpi, upd); | 4738 vp9_update_reference(cpi, upd); |
4732 } | 4739 } |
4733 | 4740 |
4734 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { | 4741 if (flags & VP8_EFLAG_NO_UPD_ENTROPY) { |
4735 vp9_update_entropy(cpi, 0); | 4742 vp9_update_entropy(cpi, 0); |
4736 } | 4743 } |
4737 } | 4744 } |
OLD | NEW |