1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/BufferUnrotate.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include <algorithm> // min & max 1.10 +#include <cstdlib> 1.11 +#include <stdint.h> 1.12 +#include <stdio.h> 1.13 +#include <stdlib.h> 1.14 +#include <string.h> 1.15 + 1.16 +void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight, 1.17 + int aByteStride, int aXBoundary, int aYBoundary) 1.18 +{ 1.19 + if (aXBoundary != 0) { 1.20 + uint8_t* line = new uint8_t[aByteWidth]; 1.21 + uint32_t smallStart = 0; 1.22 + uint32_t smallLen = aXBoundary; 1.23 + uint32_t smallDest = aByteWidth - aXBoundary; 1.24 + uint32_t largeStart = aXBoundary; 1.25 + uint32_t largeLen = aByteWidth - aXBoundary; 1.26 + uint32_t largeDest = 0; 1.27 + if (aXBoundary > aByteWidth / 2) { 1.28 + smallStart = aXBoundary; 1.29 + smallLen = aByteWidth - aXBoundary; 1.30 + smallDest = 0; 1.31 + largeStart = 0; 1.32 + largeLen = aXBoundary; 1.33 + largeDest = smallLen; 1.34 + } 1.35 + 1.36 + for (int y = 0; y < aHeight; y++) { 1.37 + int yOffset = y * aByteStride; 1.38 + memcpy(line, &aBuffer[yOffset + smallStart], smallLen); 1.39 + memmove(&aBuffer[yOffset + largeDest], &aBuffer[yOffset + largeStart], largeLen); 1.40 + memcpy(&aBuffer[yOffset + smallDest], line, smallLen); 1.41 + } 1.42 + 1.43 + delete[] line; 1.44 + } 1.45 + 1.46 + if (aYBoundary != 0) { 1.47 + uint32_t smallestHeight = std::min(aHeight - aYBoundary, aYBoundary); 1.48 + uint32_t largestHeight = std::max(aHeight - aYBoundary, aYBoundary); 1.49 + uint32_t smallOffset = 0; 1.50 + uint32_t largeOffset = aYBoundary * aByteStride; 1.51 + uint32_t largeDestOffset = 0; 1.52 + uint32_t smallDestOffset = largestHeight * aByteStride; 1.53 + if (aYBoundary > aHeight / 2) { 1.54 + smallOffset = aYBoundary * aByteStride; 1.55 + largeOffset = 0; 1.56 + largeDestOffset = smallestHeight * aByteStride; 1.57 + smallDestOffset = 0; 1.58 + } 1.59 + 1.60 + uint8_t* smallestSide = new uint8_t[aByteStride * smallestHeight]; 1.61 + memcpy(smallestSide, &aBuffer[smallOffset], aByteStride * smallestHeight); 1.62 + memmove(&aBuffer[largeDestOffset], &aBuffer[largeOffset], aByteStride * largestHeight); 1.63 + memcpy(&aBuffer[smallDestOffset], smallestSide, aByteStride * smallestHeight); 1.64 + delete[] smallestSide; 1.65 + } 1.66 +} 1.67 +