/* -*- 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/. */
inline uint32_t Avg2x2(uint32_t a, uint32_t b, uint32_t c, uint32_t d) { // Prepare half-adder work
uint32_t sum = a ^ b ^ c;
uint32_t carry = (a & b) | (a & c) | (b & c);
// Before shifting, mask lower order bits of each byte to avoid underflow.
uint32_t mask = 0xfefefefe;
// Add d to sum and divide by 2.
sum = (((sum ^ d) & mask) >> 1) + (sum & d);
// Sum is now shifted into place relative to carry, add them together. return (((sum ^ carry) & mask) >> 1) + (sum & carry);
}
inline uint32_t Avg2(uint32_t a, uint32_t b) { // Prepare half-adder work
uint32_t sum = a ^ b;
uint32_t carry = (a & b);
// Before shifting, mask lower order bits of each byte to avoid underflow.
uint32_t mask = 0xfefefefe;
// Add d to sum and divide by 2. return ((sum & mask) >> 1) + carry;
}
size_t bufLen = 0;
mStride = GetAlignedStride<16>(internalSurfSize.width, 4); if (mStride > 0) { // Allocate 15 bytes extra to make sure we can get 16 byte alignment. We // should add tools for this, see bug 751696.
bufLen =
BufferSizeFromStrideAndHeight(mStride, internalSurfSize.height, 15);
}
if (bufLen == 0) {
mSize.SizeTo(0, 0);
mDataStorage = nullptr; return;
}
mDataStorage = new uint8_t[bufLen];
if (uintptr_t(mDataStorage) % 16) { // Our storage does not start at a 16-byte boundary. Make sure mData does!
mData = (uint8_t*)(uintptr_t(mDataStorage) +
(16 - (uintptr_t(mDataStorage) % 16)));
} else {
mData = mDataStorage;
}
mSize = scaleSize;
/* The surface we sample from might not be even sized, if it's not we will * ignore the last row/column. This means we lose some data but it keeps the * code very simple. There's also no perfect answer that provides a better * solution.
*/
IntSize currentSampledSize = mOrigSize;
uint32_t currentSampledStride = mOrigStride;
uint8_t* currentSampledData = mOrigData;
while (verticalDownscales && horizontalDownscales) { if (currentSampledSize.width % 2) {
currentSampledSize.width -= 1;
} if (currentSampledSize.height % 2) {
currentSampledSize.height -= 1;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.