gfx/layers/BufferUnrotate.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include <algorithm> // min & max
     7 #include <cstdlib>
     8 #include <stdint.h>
     9 #include <stdio.h>
    10 #include <stdlib.h>
    11 #include <string.h>
    13 void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight,
    14                     int aByteStride, int aXBoundary, int aYBoundary)
    15 {
    16   if (aXBoundary != 0) {
    17     uint8_t* line = new uint8_t[aByteWidth];
    18     uint32_t smallStart = 0;
    19     uint32_t smallLen = aXBoundary;
    20     uint32_t smallDest = aByteWidth - aXBoundary;
    21     uint32_t largeStart = aXBoundary;
    22     uint32_t largeLen = aByteWidth - aXBoundary;
    23     uint32_t largeDest = 0;
    24     if (aXBoundary > aByteWidth / 2) {
    25       smallStart = aXBoundary;
    26       smallLen = aByteWidth - aXBoundary;
    27       smallDest = 0;
    28       largeStart = 0;
    29       largeLen = aXBoundary;
    30       largeDest = smallLen;
    31     }
    33     for (int y = 0; y < aHeight; y++) {
    34       int yOffset = y * aByteStride;
    35       memcpy(line, &aBuffer[yOffset + smallStart], smallLen);
    36       memmove(&aBuffer[yOffset + largeDest], &aBuffer[yOffset + largeStart], largeLen);
    37       memcpy(&aBuffer[yOffset + smallDest], line, smallLen);
    38     }
    40     delete[] line;
    41   }
    43   if (aYBoundary != 0) {
    44     uint32_t smallestHeight = std::min(aHeight - aYBoundary, aYBoundary);
    45     uint32_t largestHeight = std::max(aHeight - aYBoundary, aYBoundary);
    46     uint32_t smallOffset = 0;
    47     uint32_t largeOffset = aYBoundary * aByteStride;
    48     uint32_t largeDestOffset = 0;
    49     uint32_t smallDestOffset = largestHeight * aByteStride;
    50     if (aYBoundary > aHeight / 2) {
    51       smallOffset = aYBoundary * aByteStride;
    52       largeOffset = 0;
    53       largeDestOffset = smallestHeight * aByteStride;
    54       smallDestOffset = 0;
    55     }
    57     uint8_t* smallestSide = new uint8_t[aByteStride * smallestHeight];
    58     memcpy(smallestSide, &aBuffer[smallOffset], aByteStride * smallestHeight);
    59     memmove(&aBuffer[largeDestOffset], &aBuffer[largeOffset], aByteStride * largestHeight);
    60     memcpy(&aBuffer[smallDestOffset], smallestSide, aByteStride * smallestHeight);
    61     delete[] smallestSide;
    62   }
    63 }

mercurial