Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #include "yuv_row.h" |
michael@0 | 6 | |
michael@0 | 7 | #define DCHECK(a) |
michael@0 | 8 | |
michael@0 | 9 | extern "C" { |
michael@0 | 10 | |
michael@0 | 11 | // C reference code that mimic the YUV assembly. |
michael@0 | 12 | #define packuswb(x) ((x) < 0 ? 0 : ((x) > 255 ? 255 : (x))) |
michael@0 | 13 | #define paddsw(x, y) (((x) + (y)) < -32768 ? -32768 : \ |
michael@0 | 14 | (((x) + (y)) > 32767 ? 32767 : ((x) + (y)))) |
michael@0 | 15 | |
michael@0 | 16 | static inline void YuvPixel(uint8 y, |
michael@0 | 17 | uint8 u, |
michael@0 | 18 | uint8 v, |
michael@0 | 19 | uint8* rgb_buf) { |
michael@0 | 20 | |
michael@0 | 21 | int b = kCoefficientsRgbY[256+u][0]; |
michael@0 | 22 | int g = kCoefficientsRgbY[256+u][1]; |
michael@0 | 23 | int r = kCoefficientsRgbY[256+u][2]; |
michael@0 | 24 | int a = kCoefficientsRgbY[256+u][3]; |
michael@0 | 25 | |
michael@0 | 26 | b = paddsw(b, kCoefficientsRgbY[512+v][0]); |
michael@0 | 27 | g = paddsw(g, kCoefficientsRgbY[512+v][1]); |
michael@0 | 28 | r = paddsw(r, kCoefficientsRgbY[512+v][2]); |
michael@0 | 29 | a = paddsw(a, kCoefficientsRgbY[512+v][3]); |
michael@0 | 30 | |
michael@0 | 31 | b = paddsw(b, kCoefficientsRgbY[y][0]); |
michael@0 | 32 | g = paddsw(g, kCoefficientsRgbY[y][1]); |
michael@0 | 33 | r = paddsw(r, kCoefficientsRgbY[y][2]); |
michael@0 | 34 | a = paddsw(a, kCoefficientsRgbY[y][3]); |
michael@0 | 35 | |
michael@0 | 36 | b >>= 6; |
michael@0 | 37 | g >>= 6; |
michael@0 | 38 | r >>= 6; |
michael@0 | 39 | a >>= 6; |
michael@0 | 40 | |
michael@0 | 41 | *reinterpret_cast<uint32*>(rgb_buf) = (packuswb(b)) | |
michael@0 | 42 | (packuswb(g) << 8) | |
michael@0 | 43 | (packuswb(r) << 16) | |
michael@0 | 44 | (packuswb(a) << 24); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | void FastConvertYUVToRGB32Row_C(const uint8* y_buf, |
michael@0 | 48 | const uint8* u_buf, |
michael@0 | 49 | const uint8* v_buf, |
michael@0 | 50 | uint8* rgb_buf, |
michael@0 | 51 | int width, |
michael@0 | 52 | unsigned int x_shift) { |
michael@0 | 53 | for (int x = 0; x < width; x += 2) { |
michael@0 | 54 | uint8 u = u_buf[x >> x_shift]; |
michael@0 | 55 | uint8 v = v_buf[x >> x_shift]; |
michael@0 | 56 | uint8 y0 = y_buf[x]; |
michael@0 | 57 | YuvPixel(y0, u, v, rgb_buf); |
michael@0 | 58 | if ((x + 1) < width) { |
michael@0 | 59 | uint8 y1 = y_buf[x + 1]; |
michael@0 | 60 | if (x_shift == 0) { |
michael@0 | 61 | u = u_buf[x + 1]; |
michael@0 | 62 | v = v_buf[x + 1]; |
michael@0 | 63 | } |
michael@0 | 64 | YuvPixel(y1, u, v, rgb_buf + 4); |
michael@0 | 65 | } |
michael@0 | 66 | rgb_buf += 8; // Advance 2 pixels. |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | // 16.16 fixed point is used. A shift by 16 isolates the integer. |
michael@0 | 71 | // A shift by 17 is used to further subsample the chrominence channels. |
michael@0 | 72 | // & 0xffff isolates the fixed point fraction. >> 2 to get the upper 2 bits, |
michael@0 | 73 | // for 1/65536 pixel accurate interpolation. |
michael@0 | 74 | void ScaleYUVToRGB32Row_C(const uint8* y_buf, |
michael@0 | 75 | const uint8* u_buf, |
michael@0 | 76 | const uint8* v_buf, |
michael@0 | 77 | uint8* rgb_buf, |
michael@0 | 78 | int width, |
michael@0 | 79 | int source_dx) { |
michael@0 | 80 | int x = 0; |
michael@0 | 81 | for (int i = 0; i < width; i += 2) { |
michael@0 | 82 | int y = y_buf[x >> 16]; |
michael@0 | 83 | int u = u_buf[(x >> 17)]; |
michael@0 | 84 | int v = v_buf[(x >> 17)]; |
michael@0 | 85 | YuvPixel(y, u, v, rgb_buf); |
michael@0 | 86 | x += source_dx; |
michael@0 | 87 | if ((i + 1) < width) { |
michael@0 | 88 | y = y_buf[x >> 16]; |
michael@0 | 89 | YuvPixel(y, u, v, rgb_buf+4); |
michael@0 | 90 | x += source_dx; |
michael@0 | 91 | } |
michael@0 | 92 | rgb_buf += 8; |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | void LinearScaleYUVToRGB32Row_C(const uint8* y_buf, |
michael@0 | 97 | const uint8* u_buf, |
michael@0 | 98 | const uint8* v_buf, |
michael@0 | 99 | uint8* rgb_buf, |
michael@0 | 100 | int width, |
michael@0 | 101 | int source_dx) { |
michael@0 | 102 | int x = 0; |
michael@0 | 103 | if (source_dx >= 0x20000) { |
michael@0 | 104 | x = 32768; |
michael@0 | 105 | } |
michael@0 | 106 | for (int i = 0; i < width; i += 2) { |
michael@0 | 107 | int y0 = y_buf[x >> 16]; |
michael@0 | 108 | int y1 = y_buf[(x >> 16) + 1]; |
michael@0 | 109 | int u0 = u_buf[(x >> 17)]; |
michael@0 | 110 | int u1 = u_buf[(x >> 17) + 1]; |
michael@0 | 111 | int v0 = v_buf[(x >> 17)]; |
michael@0 | 112 | int v1 = v_buf[(x >> 17) + 1]; |
michael@0 | 113 | int y_frac = (x & 65535); |
michael@0 | 114 | int uv_frac = ((x >> 1) & 65535); |
michael@0 | 115 | int y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; |
michael@0 | 116 | int u = (uv_frac * u1 + (uv_frac ^ 65535) * u0) >> 16; |
michael@0 | 117 | int v = (uv_frac * v1 + (uv_frac ^ 65535) * v0) >> 16; |
michael@0 | 118 | YuvPixel(y, u, v, rgb_buf); |
michael@0 | 119 | x += source_dx; |
michael@0 | 120 | if ((i + 1) < width) { |
michael@0 | 121 | y0 = y_buf[x >> 16]; |
michael@0 | 122 | y1 = y_buf[(x >> 16) + 1]; |
michael@0 | 123 | y_frac = (x & 65535); |
michael@0 | 124 | y = (y_frac * y1 + (y_frac ^ 65535) * y0) >> 16; |
michael@0 | 125 | YuvPixel(y, u, v, rgb_buf+4); |
michael@0 | 126 | x += source_dx; |
michael@0 | 127 | } |
michael@0 | 128 | rgb_buf += 8; |
michael@0 | 129 | } |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | } // extern "C" |
michael@0 | 133 |