Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* |
michael@0 | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
michael@0 | 3 | * |
michael@0 | 4 | * Use of this source code is governed by a BSD-style license |
michael@0 | 5 | * that can be found in the LICENSE file in the root of the source |
michael@0 | 6 | * tree. An additional intellectual property rights grant can be found |
michael@0 | 7 | * in the file PATENTS. All contributing project authors may |
michael@0 | 8 | * be found in the AUTHORS file in the root of the source tree. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #include <assert.h> |
michael@0 | 12 | #include "./vpx_config.h" |
michael@0 | 13 | #include "vpx/vpx_integer.h" |
michael@0 | 14 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 15 | #include "vpx_scale/yv12config.h" |
michael@0 | 16 | |
michael@0 | 17 | static void extend_plane(uint8_t *const src, int src_stride, |
michael@0 | 18 | int width, int height, |
michael@0 | 19 | int extend_top, int extend_left, |
michael@0 | 20 | int extend_bottom, int extend_right) { |
michael@0 | 21 | int i; |
michael@0 | 22 | const int linesize = extend_left + extend_right + width; |
michael@0 | 23 | |
michael@0 | 24 | /* copy the left and right most columns out */ |
michael@0 | 25 | uint8_t *src_ptr1 = src; |
michael@0 | 26 | uint8_t *src_ptr2 = src + width - 1; |
michael@0 | 27 | uint8_t *dst_ptr1 = src - extend_left; |
michael@0 | 28 | uint8_t *dst_ptr2 = src + width; |
michael@0 | 29 | |
michael@0 | 30 | for (i = 0; i < height; ++i) { |
michael@0 | 31 | vpx_memset(dst_ptr1, src_ptr1[0], extend_left); |
michael@0 | 32 | vpx_memset(dst_ptr2, src_ptr2[0], extend_right); |
michael@0 | 33 | src_ptr1 += src_stride; |
michael@0 | 34 | src_ptr2 += src_stride; |
michael@0 | 35 | dst_ptr1 += src_stride; |
michael@0 | 36 | dst_ptr2 += src_stride; |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | /* Now copy the top and bottom lines into each line of the respective |
michael@0 | 40 | * borders |
michael@0 | 41 | */ |
michael@0 | 42 | src_ptr1 = src - extend_left; |
michael@0 | 43 | src_ptr2 = src + src_stride * (height - 1) - extend_left; |
michael@0 | 44 | dst_ptr1 = src + src_stride * -extend_top - extend_left; |
michael@0 | 45 | dst_ptr2 = src + src_stride * height - extend_left; |
michael@0 | 46 | |
michael@0 | 47 | for (i = 0; i < extend_top; ++i) { |
michael@0 | 48 | vpx_memcpy(dst_ptr1, src_ptr1, linesize); |
michael@0 | 49 | dst_ptr1 += src_stride; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | for (i = 0; i < extend_bottom; ++i) { |
michael@0 | 53 | vpx_memcpy(dst_ptr2, src_ptr2, linesize); |
michael@0 | 54 | dst_ptr2 += src_stride; |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | void vp8_yv12_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf) { |
michael@0 | 59 | assert(ybf->y_height - ybf->y_crop_height < 16); |
michael@0 | 60 | assert(ybf->y_width - ybf->y_crop_width < 16); |
michael@0 | 61 | assert(ybf->y_height - ybf->y_crop_height >= 0); |
michael@0 | 62 | assert(ybf->y_width - ybf->y_crop_width >= 0); |
michael@0 | 63 | |
michael@0 | 64 | extend_plane(ybf->y_buffer, ybf->y_stride, |
michael@0 | 65 | ybf->y_crop_width, ybf->y_crop_height, |
michael@0 | 66 | ybf->border, ybf->border, |
michael@0 | 67 | ybf->border + ybf->y_height - ybf->y_crop_height, |
michael@0 | 68 | ybf->border + ybf->y_width - ybf->y_crop_width); |
michael@0 | 69 | |
michael@0 | 70 | extend_plane(ybf->u_buffer, ybf->uv_stride, |
michael@0 | 71 | (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, |
michael@0 | 72 | ybf->border / 2, ybf->border / 2, |
michael@0 | 73 | (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, |
michael@0 | 74 | (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); |
michael@0 | 75 | |
michael@0 | 76 | extend_plane(ybf->v_buffer, ybf->uv_stride, |
michael@0 | 77 | (ybf->y_crop_width + 1) / 2, (ybf->y_crop_height + 1) / 2, |
michael@0 | 78 | ybf->border / 2, ybf->border / 2, |
michael@0 | 79 | (ybf->border + ybf->y_height - ybf->y_crop_height + 1) / 2, |
michael@0 | 80 | (ybf->border + ybf->y_width - ybf->y_crop_width + 1) / 2); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | #if CONFIG_VP9 |
michael@0 | 84 | static void extend_frame(YV12_BUFFER_CONFIG *const ybf, |
michael@0 | 85 | int subsampling_x, int subsampling_y, |
michael@0 | 86 | int ext_size) { |
michael@0 | 87 | const int c_w = ybf->uv_crop_width; |
michael@0 | 88 | const int c_h = ybf->uv_crop_height; |
michael@0 | 89 | const int c_ext_size = ext_size >> 1; |
michael@0 | 90 | const int c_et = c_ext_size; |
michael@0 | 91 | const int c_el = c_ext_size; |
michael@0 | 92 | const int c_eb = c_ext_size + ybf->uv_height - ybf->uv_crop_height; |
michael@0 | 93 | const int c_er = c_ext_size + ybf->uv_width - ybf->uv_crop_width; |
michael@0 | 94 | |
michael@0 | 95 | assert(ybf->y_height - ybf->y_crop_height < 16); |
michael@0 | 96 | assert(ybf->y_width - ybf->y_crop_width < 16); |
michael@0 | 97 | assert(ybf->y_height - ybf->y_crop_height >= 0); |
michael@0 | 98 | assert(ybf->y_width - ybf->y_crop_width >= 0); |
michael@0 | 99 | |
michael@0 | 100 | extend_plane(ybf->y_buffer, ybf->y_stride, |
michael@0 | 101 | ybf->y_crop_width, ybf->y_crop_height, |
michael@0 | 102 | ext_size, ext_size, |
michael@0 | 103 | ext_size + ybf->y_height - ybf->y_crop_height, |
michael@0 | 104 | ext_size + ybf->y_width - ybf->y_crop_width); |
michael@0 | 105 | |
michael@0 | 106 | extend_plane(ybf->u_buffer, ybf->uv_stride, |
michael@0 | 107 | c_w, c_h, c_et, c_el, c_eb, c_er); |
michael@0 | 108 | |
michael@0 | 109 | extend_plane(ybf->v_buffer, ybf->uv_stride, |
michael@0 | 110 | c_w, c_h, c_et, c_el, c_eb, c_er); |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | void vp9_extend_frame_borders_c(YV12_BUFFER_CONFIG *ybf, |
michael@0 | 114 | int subsampling_x, int subsampling_y) { |
michael@0 | 115 | extend_frame(ybf, subsampling_x, subsampling_y, ybf->border); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | void vp9_extend_frame_inner_borders_c(YV12_BUFFER_CONFIG *ybf, |
michael@0 | 119 | int subsampling_x, int subsampling_y) { |
michael@0 | 120 | const int inner_bw = (ybf->border > VP9INNERBORDERINPIXELS) ? |
michael@0 | 121 | VP9INNERBORDERINPIXELS : ybf->border; |
michael@0 | 122 | extend_frame(ybf, subsampling_x, subsampling_y, inner_bw); |
michael@0 | 123 | } |
michael@0 | 124 | #endif // CONFIG_VP9 |
michael@0 | 125 | |
michael@0 | 126 | // Copies the source image into the destination image and updates the |
michael@0 | 127 | // destination's UMV borders. |
michael@0 | 128 | // Note: The frames are assumed to be identical in size. |
michael@0 | 129 | void vp8_yv12_copy_frame_c(const YV12_BUFFER_CONFIG *src_ybc, |
michael@0 | 130 | YV12_BUFFER_CONFIG *dst_ybc) { |
michael@0 | 131 | int row; |
michael@0 | 132 | const uint8_t *src = src_ybc->y_buffer; |
michael@0 | 133 | uint8_t *dst = dst_ybc->y_buffer; |
michael@0 | 134 | |
michael@0 | 135 | #if 0 |
michael@0 | 136 | /* These assertions are valid in the codec, but the libvpx-tester uses |
michael@0 | 137 | * this code slightly differently. |
michael@0 | 138 | */ |
michael@0 | 139 | assert(src_ybc->y_width == dst_ybc->y_width); |
michael@0 | 140 | assert(src_ybc->y_height == dst_ybc->y_height); |
michael@0 | 141 | #endif |
michael@0 | 142 | |
michael@0 | 143 | for (row = 0; row < src_ybc->y_height; ++row) { |
michael@0 | 144 | vpx_memcpy(dst, src, src_ybc->y_width); |
michael@0 | 145 | src += src_ybc->y_stride; |
michael@0 | 146 | dst += dst_ybc->y_stride; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | src = src_ybc->u_buffer; |
michael@0 | 150 | dst = dst_ybc->u_buffer; |
michael@0 | 151 | |
michael@0 | 152 | for (row = 0; row < src_ybc->uv_height; ++row) { |
michael@0 | 153 | vpx_memcpy(dst, src, src_ybc->uv_width); |
michael@0 | 154 | src += src_ybc->uv_stride; |
michael@0 | 155 | dst += dst_ybc->uv_stride; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | src = src_ybc->v_buffer; |
michael@0 | 159 | dst = dst_ybc->v_buffer; |
michael@0 | 160 | |
michael@0 | 161 | for (row = 0; row < src_ybc->uv_height; ++row) { |
michael@0 | 162 | vpx_memcpy(dst, src, src_ybc->uv_width); |
michael@0 | 163 | src += src_ybc->uv_stride; |
michael@0 | 164 | dst += dst_ybc->uv_stride; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | vp8_yv12_extend_frame_borders_c(dst_ybc); |
michael@0 | 168 | } |
michael@0 | 169 | |
michael@0 | 170 | void vpx_yv12_copy_y_c(const YV12_BUFFER_CONFIG *src_ybc, |
michael@0 | 171 | YV12_BUFFER_CONFIG *dst_ybc) { |
michael@0 | 172 | int row; |
michael@0 | 173 | const uint8_t *src = src_ybc->y_buffer; |
michael@0 | 174 | uint8_t *dst = dst_ybc->y_buffer; |
michael@0 | 175 | |
michael@0 | 176 | for (row = 0; row < src_ybc->y_height; ++row) { |
michael@0 | 177 | vpx_memcpy(dst, src, src_ybc->y_width); |
michael@0 | 178 | src += src_ybc->y_stride; |
michael@0 | 179 | dst += dst_ybc->y_stride; |
michael@0 | 180 | } |
michael@0 | 181 | } |