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 | |
michael@0 | 12 | #include "extend.h" |
michael@0 | 13 | #include "vpx_mem/vpx_mem.h" |
michael@0 | 14 | |
michael@0 | 15 | |
michael@0 | 16 | static void copy_and_extend_plane |
michael@0 | 17 | ( |
michael@0 | 18 | unsigned char *s, /* source */ |
michael@0 | 19 | int sp, /* source pitch */ |
michael@0 | 20 | unsigned char *d, /* destination */ |
michael@0 | 21 | int dp, /* destination pitch */ |
michael@0 | 22 | int h, /* height */ |
michael@0 | 23 | int w, /* width */ |
michael@0 | 24 | int et, /* extend top border */ |
michael@0 | 25 | int el, /* extend left border */ |
michael@0 | 26 | int eb, /* extend bottom border */ |
michael@0 | 27 | int er /* extend right border */ |
michael@0 | 28 | ) |
michael@0 | 29 | { |
michael@0 | 30 | int i; |
michael@0 | 31 | unsigned char *src_ptr1, *src_ptr2; |
michael@0 | 32 | unsigned char *dest_ptr1, *dest_ptr2; |
michael@0 | 33 | int linesize; |
michael@0 | 34 | |
michael@0 | 35 | /* copy the left and right most columns out */ |
michael@0 | 36 | src_ptr1 = s; |
michael@0 | 37 | src_ptr2 = s + w - 1; |
michael@0 | 38 | dest_ptr1 = d - el; |
michael@0 | 39 | dest_ptr2 = d + w; |
michael@0 | 40 | |
michael@0 | 41 | for (i = 0; i < h; i++) |
michael@0 | 42 | { |
michael@0 | 43 | vpx_memset(dest_ptr1, src_ptr1[0], el); |
michael@0 | 44 | vpx_memcpy(dest_ptr1 + el, src_ptr1, w); |
michael@0 | 45 | vpx_memset(dest_ptr2, src_ptr2[0], er); |
michael@0 | 46 | src_ptr1 += sp; |
michael@0 | 47 | src_ptr2 += sp; |
michael@0 | 48 | dest_ptr1 += dp; |
michael@0 | 49 | dest_ptr2 += dp; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | /* Now copy the top and bottom lines into each line of the respective |
michael@0 | 53 | * borders |
michael@0 | 54 | */ |
michael@0 | 55 | src_ptr1 = d - el; |
michael@0 | 56 | src_ptr2 = d + dp * (h - 1) - el; |
michael@0 | 57 | dest_ptr1 = d + dp * (-et) - el; |
michael@0 | 58 | dest_ptr2 = d + dp * (h) - el; |
michael@0 | 59 | linesize = el + er + w; |
michael@0 | 60 | |
michael@0 | 61 | for (i = 0; i < et; i++) |
michael@0 | 62 | { |
michael@0 | 63 | vpx_memcpy(dest_ptr1, src_ptr1, linesize); |
michael@0 | 64 | dest_ptr1 += dp; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | for (i = 0; i < eb; i++) |
michael@0 | 68 | { |
michael@0 | 69 | vpx_memcpy(dest_ptr2, src_ptr2, linesize); |
michael@0 | 70 | dest_ptr2 += dp; |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | |
michael@0 | 75 | void vp8_copy_and_extend_frame(YV12_BUFFER_CONFIG *src, |
michael@0 | 76 | YV12_BUFFER_CONFIG *dst) |
michael@0 | 77 | { |
michael@0 | 78 | int et = dst->border; |
michael@0 | 79 | int el = dst->border; |
michael@0 | 80 | int eb = dst->border + dst->y_height - src->y_height; |
michael@0 | 81 | int er = dst->border + dst->y_width - src->y_width; |
michael@0 | 82 | |
michael@0 | 83 | copy_and_extend_plane(src->y_buffer, src->y_stride, |
michael@0 | 84 | dst->y_buffer, dst->y_stride, |
michael@0 | 85 | src->y_height, src->y_width, |
michael@0 | 86 | et, el, eb, er); |
michael@0 | 87 | |
michael@0 | 88 | et = dst->border >> 1; |
michael@0 | 89 | el = dst->border >> 1; |
michael@0 | 90 | eb = (dst->border >> 1) + dst->uv_height - src->uv_height; |
michael@0 | 91 | er = (dst->border >> 1) + dst->uv_width - src->uv_width; |
michael@0 | 92 | |
michael@0 | 93 | copy_and_extend_plane(src->u_buffer, src->uv_stride, |
michael@0 | 94 | dst->u_buffer, dst->uv_stride, |
michael@0 | 95 | src->uv_height, src->uv_width, |
michael@0 | 96 | et, el, eb, er); |
michael@0 | 97 | |
michael@0 | 98 | copy_and_extend_plane(src->v_buffer, src->uv_stride, |
michael@0 | 99 | dst->v_buffer, dst->uv_stride, |
michael@0 | 100 | src->uv_height, src->uv_width, |
michael@0 | 101 | et, el, eb, er); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | |
michael@0 | 105 | void vp8_copy_and_extend_frame_with_rect(YV12_BUFFER_CONFIG *src, |
michael@0 | 106 | YV12_BUFFER_CONFIG *dst, |
michael@0 | 107 | int srcy, int srcx, |
michael@0 | 108 | int srch, int srcw) |
michael@0 | 109 | { |
michael@0 | 110 | int et = dst->border; |
michael@0 | 111 | int el = dst->border; |
michael@0 | 112 | int eb = dst->border + dst->y_height - src->y_height; |
michael@0 | 113 | int er = dst->border + dst->y_width - src->y_width; |
michael@0 | 114 | int src_y_offset = srcy * src->y_stride + srcx; |
michael@0 | 115 | int dst_y_offset = srcy * dst->y_stride + srcx; |
michael@0 | 116 | int src_uv_offset = ((srcy * src->uv_stride) >> 1) + (srcx >> 1); |
michael@0 | 117 | int dst_uv_offset = ((srcy * dst->uv_stride) >> 1) + (srcx >> 1); |
michael@0 | 118 | |
michael@0 | 119 | /* If the side is not touching the bounder then don't extend. */ |
michael@0 | 120 | if (srcy) |
michael@0 | 121 | et = 0; |
michael@0 | 122 | if (srcx) |
michael@0 | 123 | el = 0; |
michael@0 | 124 | if (srcy + srch != src->y_height) |
michael@0 | 125 | eb = 0; |
michael@0 | 126 | if (srcx + srcw != src->y_width) |
michael@0 | 127 | er = 0; |
michael@0 | 128 | |
michael@0 | 129 | copy_and_extend_plane(src->y_buffer + src_y_offset, |
michael@0 | 130 | src->y_stride, |
michael@0 | 131 | dst->y_buffer + dst_y_offset, |
michael@0 | 132 | dst->y_stride, |
michael@0 | 133 | srch, srcw, |
michael@0 | 134 | et, el, eb, er); |
michael@0 | 135 | |
michael@0 | 136 | et = (et + 1) >> 1; |
michael@0 | 137 | el = (el + 1) >> 1; |
michael@0 | 138 | eb = (eb + 1) >> 1; |
michael@0 | 139 | er = (er + 1) >> 1; |
michael@0 | 140 | srch = (srch + 1) >> 1; |
michael@0 | 141 | srcw = (srcw + 1) >> 1; |
michael@0 | 142 | |
michael@0 | 143 | copy_and_extend_plane(src->u_buffer + src_uv_offset, |
michael@0 | 144 | src->uv_stride, |
michael@0 | 145 | dst->u_buffer + dst_uv_offset, |
michael@0 | 146 | dst->uv_stride, |
michael@0 | 147 | srch, srcw, |
michael@0 | 148 | et, el, eb, er); |
michael@0 | 149 | |
michael@0 | 150 | copy_and_extend_plane(src->v_buffer + src_uv_offset, |
michael@0 | 151 | src->uv_stride, |
michael@0 | 152 | dst->v_buffer + dst_uv_offset, |
michael@0 | 153 | dst->uv_stride, |
michael@0 | 154 | srch, srcw, |
michael@0 | 155 | et, el, eb, er); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | |
michael@0 | 159 | /* note the extension is only for the last row, for intra prediction purpose */ |
michael@0 | 160 | void vp8_extend_mb_row(YV12_BUFFER_CONFIG *ybf, |
michael@0 | 161 | unsigned char *YPtr, |
michael@0 | 162 | unsigned char *UPtr, |
michael@0 | 163 | unsigned char *VPtr) |
michael@0 | 164 | { |
michael@0 | 165 | int i; |
michael@0 | 166 | |
michael@0 | 167 | YPtr += ybf->y_stride * 14; |
michael@0 | 168 | UPtr += ybf->uv_stride * 6; |
michael@0 | 169 | VPtr += ybf->uv_stride * 6; |
michael@0 | 170 | |
michael@0 | 171 | for (i = 0; i < 4; i++) |
michael@0 | 172 | { |
michael@0 | 173 | YPtr[i] = YPtr[-1]; |
michael@0 | 174 | UPtr[i] = UPtr[-1]; |
michael@0 | 175 | VPtr[i] = VPtr[-1]; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | YPtr += ybf->y_stride; |
michael@0 | 179 | UPtr += ybf->uv_stride; |
michael@0 | 180 | VPtr += ybf->uv_stride; |
michael@0 | 181 | |
michael@0 | 182 | for (i = 0; i < 4; i++) |
michael@0 | 183 | { |
michael@0 | 184 | YPtr[i] = YPtr[-1]; |
michael@0 | 185 | UPtr[i] = UPtr[-1]; |
michael@0 | 186 | VPtr[i] = VPtr[-1]; |
michael@0 | 187 | } |
michael@0 | 188 | } |