本文整理汇总了C++中MemoryBuffer::getBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryBuffer::getBuffer方法的具体用法?C++ MemoryBuffer::getBuffer怎么用?C++ MemoryBuffer::getBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryBuffer
的用法示例。
在下文中一共展示了MemoryBuffer::getBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect)
{
lockMutex();
if (!this->m_iirgaus) {
MemoryBuffer *newBuf = (MemoryBuffer *)this->m_inputprogram->initializeTileData(rect);
MemoryBuffer *copy = newBuf->duplicate();
FastGaussianBlurOperation::IIR_gauss(copy, this->m_sigma, 0, 3);
if (this->m_overlay == FAST_GAUSS_OVERLAY_MIN) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
if (*src < *dst) {
*dst = *src;
}
}
}
else if (this->m_overlay == FAST_GAUSS_OVERLAY_MAX) {
float *src = newBuf->getBuffer();
float *dst = copy->getBuffer();
for (int i = copy->getWidth() * copy->getHeight(); i != 0; i--, src += COM_NUM_CHANNELS_VALUE, dst += COM_NUM_CHANNELS_VALUE) {
if (*src > *dst) {
*dst = *src;
}
}
}
// newBuf->
this->m_iirgaus = copy;
}
unlockMutex();
return this->m_iirgaus;
}
示例2: executePixel
void GaussianYBlurOperation::executePixel(float output[4], int x, int y, void *data)
{
float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float multiplier_accum = 0.0f;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
int bufferstartx = inputBuffer->getRect()->xmin;
int bufferstarty = inputBuffer->getRect()->ymin;
rcti &rect = *inputBuffer->getRect();
int xmin = max_ii(x, rect.xmin);
int ymin = max_ii(y - m_filtersize, rect.ymin);
int ymax = min_ii(y + m_filtersize + 1, rect.ymax);
int index;
int step = getStep();
const int bufferIndexx = ((xmin - bufferstartx) * 4);
for (int ny = ymin; ny < ymax; ny += step) {
index = (ny - y) + this->m_filtersize;
int bufferindex = bufferIndexx + ((ny - bufferstarty) * 4 * bufferwidth);
const float multiplier = this->m_gausstab[index];
madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier);
multiplier_accum += multiplier;
}
mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum);
}
示例3: executePixel
void GaussianAlphaYBlurOperation::executePixel(float *color, int x, int y, void *data)
{
const bool do_invert = this->m_do_subtract;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
int bufferstartx = inputBuffer->getRect()->xmin;
int bufferstarty = inputBuffer->getRect()->ymin;
int miny = y - this->m_rad;
int maxy = y + this->m_rad;
int minx = x;
int maxx = x;
miny = max(miny, inputBuffer->getRect()->ymin);
minx = max(minx, inputBuffer->getRect()->xmin);
maxy = min(maxy, inputBuffer->getRect()->ymax);
maxx = min(maxx, inputBuffer->getRect()->xmax);
/* *** this is the main part which is different to 'GaussianYBlurOperation' *** */
int step = getStep();
/* gauss */
float alpha_accum = 0.0f;
float multiplier_accum = 0.0f;
/* dilate */
float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int ny = miny; ny < maxy; ny += step) {
int bufferindex = ((minx - bufferstartx) * 4) + ((ny - bufferstarty) * 4 * bufferwidth);
const int index = (ny - y) + this->m_rad;
float value = finv_test(buffer[bufferindex], do_invert);
float multiplier;
/* gauss */
{
multiplier = this->m_gausstab[index];
alpha_accum += value * multiplier;
multiplier_accum += multiplier;
}
/* dilate - find most extreme color */
if (value > value_max) {
multiplier = this->m_distbuf_inv[index];
value *= multiplier;
if (value > value_max) {
value_max = value;
distfacinv_max = multiplier;
}
}
}
/* blend between the max value and gauss blue - gives nice feather */
const float value_blur = alpha_accum / multiplier_accum;
const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max));
color[0] = finv_test(value_final, do_invert);
}
示例4: executePixel
void ErodeDistanceOperation::executePixel(float *color, int x, int y, void *data)
{
const float distance = this->m_distance;
const float mindist = distance * distance;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
rcti *rect = inputBuffer->getRect();
const int minx = max(x - this->m_scope, rect->xmin);
const int miny = max(y - this->m_scope, rect->ymin);
const int maxx = min(x + this->m_scope, rect->xmax);
const int maxy = min(y + this->m_scope, rect->ymax);
const int bufferWidth = rect->xmax - rect->xmin;
int offset;
float value = 1.0f;
for (int yi = miny; yi < maxy; yi++) {
const float dy = yi - y;
offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4;
for (int xi = minx; xi < maxx; xi++) {
const float dx = xi - x;
const float dis = dx * dx + dy * dy;
if (dis <= mindist) {
value = min(buffer[offset], value);
}
offset += 4;
}
}
color[0] = value;
}
示例5: COM_clAttachMemoryBufferToKernelParameter
cl_mem OpenCLDevice::COM_clAttachMemoryBufferToKernelParameter(cl_kernel kernel, int parameterIndex, int offsetIndex,
list<cl_mem> *cleanup, MemoryBuffer **inputMemoryBuffers,
ReadBufferOperation *reader)
{
cl_int error;
MemoryBuffer *result = reader->getInputMemoryBuffer(inputMemoryBuffers);
const cl_image_format imageFormat = {
CL_RGBA,
CL_FLOAT
};
cl_mem clBuffer = clCreateImage2D(this->m_context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &imageFormat, result->getWidth(),
result->getHeight(), 0, result->getBuffer(), &error);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
if (error == CL_SUCCESS) cleanup->push_back(clBuffer);
error = clSetKernelArg(kernel, parameterIndex, sizeof(cl_mem), &clBuffer);
if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); }
COM_clAttachMemoryBufferOffsetToKernelParameter(kernel, offsetIndex, result);
return clBuffer;
}
示例6: executePixel
void GaussianXBlurOperation::executePixel(float output[4], int x, int y, void *data)
{
float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
float multiplier_accum = 0.0f;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
int bufferstartx = inputBuffer->getRect()->xmin;
int bufferstarty = inputBuffer->getRect()->ymin;
int miny = y;
int minx = x - this->m_rad;
int maxx = x + this->m_rad;
miny = max(miny, inputBuffer->getRect()->ymin);
minx = max(minx, inputBuffer->getRect()->xmin);
maxx = min(maxx, inputBuffer->getRect()->xmax - 1);
int step = getStep();
int offsetadd = getOffsetAdd();
int bufferindex = ((minx - bufferstartx) * 4) + ((miny - bufferstarty) * 4 * bufferwidth);
for (int nx = minx, index = (minx - x) + this->m_rad; nx <= maxx; nx += step, index += step) {
const float multiplier = this->m_gausstab[index];
madd_v4_v4fl(color_accum, &buffer[bufferindex], multiplier);
multiplier_accum += multiplier;
bufferindex += offsetadd;
}
mul_v4_v4fl(output, color_accum, 1.0f / multiplier_accum);
}
示例7: getHeight
MemoryBuffer *TextureBaseOperation::createMemoryBuffer(rcti *rect2)
{
int height = getHeight();
int width = getWidth();
DataType datatype = this->getOutputSocket()->getDataType();
int add = 4;
if (datatype == COM_DT_VALUE) {
add = 1;
}
rcti rect;
rect.xmin = 0;
rect.ymin = 0;
rect.xmax = width;
rect.ymax = height;
MemoryBuffer *result = new MemoryBuffer(datatype, &rect);
float *data = result->getBuffer();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++, data += add) {
this->executePixelSampled(data, x, y, COM_PS_NEAREST);
}
}
return result;
}
示例8: executePixel
void BokehBlurOperation::executePixel(float output[4], int x, int y, void *data)
{
float color_accum[4];
float tempBoundingBox[4];
float bokeh[4];
this->m_inputBoundingBoxReader->readSampled(tempBoundingBox, x, y, COM_PS_NEAREST);
if (tempBoundingBox[0] > 0.0f) {
float multiplier_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f};
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
int bufferstartx = inputBuffer->getRect()->xmin;
int bufferstarty = inputBuffer->getRect()->ymin;
const float max_dim = max(this->getWidth(), this->getHeight());
int pixelSize = this->m_size * max_dim / 100.0f;
zero_v4(color_accum);
if (pixelSize < 2) {
this->m_inputProgram->readSampled(color_accum, x, y, COM_PS_NEAREST);
multiplier_accum[0] = 1.0f;
multiplier_accum[1] = 1.0f;
multiplier_accum[2] = 1.0f;
multiplier_accum[3] = 1.0f;
}
int miny = y - pixelSize;
int maxy = y + pixelSize;
int minx = x - pixelSize;
int maxx = x + pixelSize;
miny = max(miny, inputBuffer->getRect()->ymin);
minx = max(minx, inputBuffer->getRect()->xmin);
maxy = min(maxy, inputBuffer->getRect()->ymax);
maxx = min(maxx, inputBuffer->getRect()->xmax);
int step = getStep();
int offsetadd = getOffsetAdd() * COM_NUM_CHANNELS_COLOR;
float m = this->m_bokehDimension / pixelSize;
for (int ny = miny; ny < maxy; ny += step) {
int bufferindex = ((minx - bufferstartx) * COM_NUM_CHANNELS_COLOR) +
((ny - bufferstarty) * COM_NUM_CHANNELS_COLOR * bufferwidth);
for (int nx = minx; nx < maxx; nx += step) {
float u = this->m_bokehMidX - (nx - x) * m;
float v = this->m_bokehMidY - (ny - y) * m;
this->m_inputBokehProgram->readSampled(bokeh, u, v, COM_PS_NEAREST);
madd_v4_v4v4(color_accum, bokeh, &buffer[bufferindex]);
add_v4_v4(multiplier_accum, bokeh);
bufferindex += offsetadd;
}
}
output[0] = color_accum[0] * (1.0f / multiplier_accum[0]);
output[1] = color_accum[1] * (1.0f / multiplier_accum[1]);
output[2] = color_accum[2] * (1.0f / multiplier_accum[2]);
output[3] = color_accum[3] * (1.0f / multiplier_accum[3]);
}
else {
this->m_inputProgram->readSampled(output, x, y, COM_PS_NEAREST);
}
}
示例9: executePixel
void KeyingClipOperation::executePixel(float *color, int x, int y, void *data)
{
const int delta = this->m_kernelRadius;
const float tolerance = this->m_kernelTolerance;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferWidth = inputBuffer->getWidth();
int bufferHeight = inputBuffer->getHeight();
int i, j, count = 0, totalCount = 0;
float value = buffer[(y * bufferWidth + x) * 4];
bool ok = false;
for (i = -delta + 1; i < delta; i++) {
for (j = -delta + 1; j < delta; j++) {
int cx = x + j, cy = y + i;
if (i == 0 && j == 0)
continue;
if (cx >= 0 && cx < bufferWidth && cy >= 0 && cy < bufferHeight) {
int bufferIndex = (cy * bufferWidth + cx) * 4;
float currentValue = buffer[bufferIndex];
if (fabsf(currentValue - value) < tolerance) {
count++;
}
totalCount++;
}
}
}
ok = count >= (float) totalCount * 0.9f;
if (this->m_isEdgeMatte) {
if (ok)
color[0] = 0.0f;
else
color[0] = 1.0f;
}
else {
color[0] = value;
if (ok) {
if (color[0] < this->m_clipBlack)
color[0] = 0.0f;
else if (color[0] >= this->m_clipWhite)
color[0] = 1.0f;
else
color[0] = (color[0] - this->m_clipBlack) / (this->m_clipWhite - this->m_clipBlack);
}
}
}
示例10: executePixel
void GaussianAlphaXBlurOperation::executePixel(float output[4], int x, int y, void *data)
{
const bool do_invert = this->m_do_subtract;
MemoryBuffer *inputBuffer = (MemoryBuffer *)data;
float *buffer = inputBuffer->getBuffer();
int bufferwidth = inputBuffer->getWidth();
int bufferstartx = inputBuffer->getRect()->xmin;
int bufferstarty = inputBuffer->getRect()->ymin;
rcti &rect = *inputBuffer->getRect();
int xmin = max_ii(x - m_filtersize, rect.xmin);
int xmax = min_ii(x + m_filtersize + 1, rect.xmax);
int ymin = max_ii(y, rect.ymin);
/* *** this is the main part which is different to 'GaussianXBlurOperation' *** */
int step = getStep();
int offsetadd = getOffsetAdd();
int bufferindex = ((xmin - bufferstartx) * 4) + ((ymin - bufferstarty) * 4 * bufferwidth);
/* gauss */
float alpha_accum = 0.0f;
float multiplier_accum = 0.0f;
/* dilate */
float value_max = finv_test(buffer[(x * 4) + (y * 4 * bufferwidth)], do_invert); /* init with the current color to avoid unneeded lookups */
float distfacinv_max = 1.0f; /* 0 to 1 */
for (int nx = xmin; nx < xmax; nx += step) {
const int index = (nx - x) + this->m_filtersize;
float value = finv_test(buffer[bufferindex], do_invert);
float multiplier;
/* gauss */
{
multiplier = this->m_gausstab[index];
alpha_accum += value * multiplier;
multiplier_accum += multiplier;
}
/* dilate - find most extreme color */
if (value > value_max) {
multiplier = this->m_distbuf_inv[index];
value *= multiplier;
if (value > value_max) {
value_max = value;
distfacinv_max = multiplier;
}
}
bufferindex += offsetadd;
}
/* blend between the max value and gauss blue - gives nice feather */
const float value_blur = alpha_accum / multiplier_accum;
const float value_final = (value_max * distfacinv_max) + (value_blur * (1.0f - distfacinv_max));
output[0] = finv_test(value_final, do_invert);
}
示例11: ReadBundle
void ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
StringRef FC = Input.getBuffer();
size_t BundleStart = ReadChars;
// Find end of the bundle.
size_t BundleEnd = ReadChars = FC.find(BundleEndString, ReadChars);
StringRef Bundle(&FC.data()[BundleStart], BundleEnd - BundleStart);
OS << Bundle;
}
示例12: MemoryBuffer
voi *InverseSearchRadiusOperation::initializeTileData(rcti *rect)
{
MemoryBuffer * data = new MemoryBuffer(NULL, rect);
float *buffer = data->getBuffer();
int x, y;
int width = this->m_inputRadius->getWidth();
int height = this->m_inputRadius->getHeight();
float temp[4];
int offset = 0;
for (y = rect->ymin; y < rect->ymax ; y++) {
for (x = rect->xmin; x < rect->xmax ; x++) {
int rx = x * DIVIDER;
int ry = y * DIVIDER;
buffer[offset] = MAX2(rx - m_maxBlur, 0);
buffer[offset + 1] = MAX2(ry - m_maxBlur, 0);
buffer[offset + 2] = MIN2(rx + DIVIDER + m_maxBlur, width);
buffer[offset + 3] = MIN2(ry + DIVIDER + m_maxBlur, height);
offset += 4;
}
}
// for (x = rect->xmin; x < rect->xmax ; x++) {
// for (y = rect->ymin; y < rect->ymax ; y++) {
// int rx = x * DIVIDER;
// int ry = y * DIVIDER;
// float radius = 0.0f;
// float maxx = x;
// float maxy = y;
// for (int x2 = 0 ; x2 < DIVIDER ; x2 ++) {
// for (int y2 = 0 ; y2 < DIVIDER ; y2 ++) {
// this->m_inputRadius->read(temp, rx+x2, ry+y2, COM_PS_NEAREST);
// if (radius < temp[0]) {
// radius = temp[0];
// maxx = x2;
// maxy = y2;
// }
// }
// }
// int impactRadius = ceil(radius / DIVIDER);
// for (int x2 = x - impactRadius ; x2 < x + impactRadius ; x2 ++) {
// for (int y2 = y - impactRadius ; y2 < y + impactRadius ; y2 ++) {
// data->read(temp, x2, y2);
// temp[0] = MIN2(temp[0], maxx);
// temp[1] = MIN2(temp[1], maxy);
// temp[2] = MAX2(temp[2], maxx);
// temp[3] = MAX2(temp[3], maxy);
// data->writePixel(x2, y2, temp);
// }
// }
// }
// }
return data;
}
示例13: LoadSerializedDiagnostics
void clang::LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath,
unsigned num_unsaved_files,
struct CXUnsavedFile *unsaved_files,
FileManager &FileMgr,
SourceManager &SourceMgr,
SmallVectorImpl<StoredDiagnostic> &Diags) {
using llvm::MemoryBuffer;
using llvm::StringRef;
MemoryBuffer *F = MemoryBuffer::getFile(DiagnosticsPath.c_str());
if (!F)
return;
// Enter the unsaved files into the file manager.
for (unsigned I = 0; I != num_unsaved_files; ++I) {
const FileEntry *File = FileMgr.getVirtualFile(unsaved_files[I].Filename,
unsaved_files[I].Length,
0);
if (!File) {
// FIXME: Hard to localize when we have no diagnostics engine!
Diags.push_back(StoredDiagnostic(Diagnostic::Fatal,
(Twine("could not remap from missing file ") +
unsaved_files[I].Filename).str()));
delete F;
return;
}
MemoryBuffer *Buffer
= MemoryBuffer::getMemBuffer(unsaved_files[I].Contents,
unsaved_files[I].Contents + unsaved_files[I].Length);
if (!Buffer) {
delete F;
return;
}
SourceMgr.overrideFileContents(File, Buffer);
SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
}
// Parse the diagnostics, emitting them one by one until we've
// exhausted the data.
StringRef Buffer = F->getBuffer();
const char *Memory = Buffer.data(), *MemoryEnd = Memory + Buffer.size();
while (Memory != MemoryEnd) {
StoredDiagnostic Stored = StoredDiagnostic::Deserialize(FileMgr, SourceMgr,
Memory, MemoryEnd);
if (!Stored)
break;
Diags.push_back(Stored);
}
delete F;
}
示例14: ReadBundleEnd
void ReadBundleEnd(MemoryBuffer &Input) final {
StringRef FC = Input.getBuffer();
// Read up to the next new line.
assert(FC[ReadChars] == '\n' && "The bundle should end with a new line.");
size_t TripleEnd = ReadChars = FC.find("\n", ReadChars + 1);
if (TripleEnd == FC.npos)
return;
// Next time we read after the new line.
++ReadChars;
}
示例15: getWidth
MemoryBuffer *GlareBaseOperation::createMemoryBuffer(rcti *rect2)
{
MemoryBuffer *tile = (MemoryBuffer *)this->m_inputProgram->initializeTileData(rect2);
rcti rect;
rect.xmin = 0;
rect.ymin = 0;
rect.xmax = getWidth();
rect.ymax = getHeight();
MemoryBuffer *result = new MemoryBuffer(COM_DT_COLOR, &rect);
float *data = result->getBuffer();
this->generateGlare(data, tile, this->m_settings);
return result;
}