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