gecko-dev/gfx/2d/BufferUnrotate.cpp
Chris Peterson e77882620f Bug 1528881 - Part 4: gfx/2d: Make some global functions static. r=lsalzman
And #include "BufferUnrotate.h" in BufferUnrotate.cpp for BufferUnrotate() function prototype.

clang's -Wmissing-prototypes option identifies global functions that can be made static (because they're only called from one compilation unit) or removed (if they're never called).

gfx/2d/BufferUnrotate.cpp:17:6 [-Wmissing-prototypes] no previous prototype for function 'BufferUnrotate'
gfx/2d/DrawTargetCairo.cpp:195:6 [-Wmissing-prototypes] no previous prototype for function 'ReleaseData'
gfx/2d/DrawTargetCairo.cpp:201:18 [-Wmissing-prototypes] no previous prototype for function 'CopyToImageSurface'
gfx/2d/DrawTargetCairo.cpp:239:18 [-Wmissing-prototypes] no previous prototype for function 'GetAsImageSurface'
gfx/2d/DrawTargetCairo.cpp:251:18 [-Wmissing-prototypes] no previous prototype for function 'CreateSubImageForData'
gfx/2d/DrawTargetCairo.cpp:272:18 [-Wmissing-prototypes] no previous prototype for function 'ExtractSubImage'
gfx/2d/DrawTargetCairo.cpp:308:18 [-Wmissing-prototypes] no previous prototype for function 'GetCairoSurfaceForSourceSurface'
gfx/2d/DrawTargetRecording.cpp:26:6 [-Wmissing-prototypes] no previous prototype for function 'RecordingSourceSurfaceUserDataFunc'
gfx/2d/DrawTargetRecording.cpp:272:6 [-Wmissing-prototypes] no previous prototype for function 'RecordingFontUserDataDestroyFunc'
gfx/2d/DrawTargetWrapAndRecord.cpp:26:6 [-Wmissing-prototypes] no previous prototype for function 'WrapAndRecordSourceSurfaceUserDataFunc'
gfx/2d/DrawTargetWrapAndRecord.cpp:358:6 [-Wmissing-prototypes] no previous prototype for function 'WrapAndRecordFontUserDataDestroyFunc'
gfx/2d/FilterNodeSoftware.cpp:1816:6 [-Wmissing-prototypes] no previous prototype for function 'IsAllZero'
gfx/2d/FilterNodeSoftware.cpp:183:37 [-Wmissing-prototypes] no previous prototype for function 'CloneAligned'
gfx/2d/MacIOSurface.cpp:442:6 [-Wmissing-prototypes] no previous prototype for function 'MacIOSurfaceBufferDeallocator'
gfx/2d/QuartzSupport.mm:38:6 [-Wmissing-prototypes] no previous prototype for function 'cgdata_release_callback'
gfx/2d/ScaledFontMac.cpp:191:10 [-Wmissing-prototypes] no previous prototype for function 'CalcTableChecksum'
gfx/2d/ScaledFontMac.cpp:224:5 [-Wmissing-prototypes] no previous prototype for function 'maxPow2LessThan'
gfx/2d/unittest/TestCairo.cpp:12:6 [-Wmissing-prototypes] no previous prototype for function 'TryCircle'

Differential Revision: https://phabricator.services.mozilla.com/D20263

--HG--
extra : rebase_source : b42bce33ed899caeb89e462d99a5cde29a9bb559
extra : intermediate-source : 7923cc86a6394bcd2fb3b7e38f458a5180d31e11
extra : source : 02388f2454e8842d2c023bf9f9fab222d8130093
2019-02-16 18:08:30 -08:00

75 lines
2.4 KiB
C++

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