michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include // min & max michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: void BufferUnrotate(uint8_t* aBuffer, int aByteWidth, int aHeight, michael@0: int aByteStride, int aXBoundary, int aYBoundary) michael@0: { michael@0: if (aXBoundary != 0) { michael@0: uint8_t* line = new uint8_t[aByteWidth]; michael@0: uint32_t smallStart = 0; michael@0: uint32_t smallLen = aXBoundary; michael@0: uint32_t smallDest = aByteWidth - aXBoundary; michael@0: uint32_t largeStart = aXBoundary; michael@0: uint32_t largeLen = aByteWidth - aXBoundary; michael@0: uint32_t largeDest = 0; michael@0: if (aXBoundary > aByteWidth / 2) { michael@0: smallStart = aXBoundary; michael@0: smallLen = aByteWidth - aXBoundary; michael@0: smallDest = 0; michael@0: largeStart = 0; michael@0: largeLen = aXBoundary; michael@0: largeDest = smallLen; michael@0: } michael@0: michael@0: for (int y = 0; y < aHeight; y++) { michael@0: int yOffset = y * aByteStride; michael@0: memcpy(line, &aBuffer[yOffset + smallStart], smallLen); michael@0: memmove(&aBuffer[yOffset + largeDest], &aBuffer[yOffset + largeStart], largeLen); michael@0: memcpy(&aBuffer[yOffset + smallDest], line, smallLen); michael@0: } michael@0: michael@0: delete[] line; michael@0: } michael@0: michael@0: if (aYBoundary != 0) { michael@0: uint32_t smallestHeight = std::min(aHeight - aYBoundary, aYBoundary); michael@0: uint32_t largestHeight = std::max(aHeight - aYBoundary, aYBoundary); michael@0: uint32_t smallOffset = 0; michael@0: uint32_t largeOffset = aYBoundary * aByteStride; michael@0: uint32_t largeDestOffset = 0; michael@0: uint32_t smallDestOffset = largestHeight * aByteStride; michael@0: if (aYBoundary > aHeight / 2) { michael@0: smallOffset = aYBoundary * aByteStride; michael@0: largeOffset = 0; michael@0: largeDestOffset = smallestHeight * aByteStride; michael@0: smallDestOffset = 0; michael@0: } michael@0: michael@0: uint8_t* smallestSide = new uint8_t[aByteStride * smallestHeight]; michael@0: memcpy(smallestSide, &aBuffer[smallOffset], aByteStride * smallestHeight); michael@0: memmove(&aBuffer[largeDestOffset], &aBuffer[largeOffset], aByteStride * largestHeight); michael@0: memcpy(&aBuffer[smallDestOffset], smallestSide, aByteStride * smallestHeight); michael@0: delete[] smallestSide; michael@0: } michael@0: } michael@0: