本文整理汇总了C++中buffer函数的典型用法代码示例。如果您正苦于以下问题:C++ buffer函数的具体用法?C++ buffer怎么用?C++ buffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: throw_if_disposed
void GL1TextureProvider::set_texture_image3d(
GLuint target,
PixelBuffer &image,
int image_depth,
int level)
{
throw_if_disposed();
GL1TextureStateTracker state_tracker(texture_type, handle);
GLint gl_internal_format;
GLenum gl_pixel_format;
to_opengl_textureformat(image.get_format(), gl_internal_format, gl_pixel_format);
// check out if the original texture needs or doesn't need an alpha channel
bool needs_alpha = image.has_transparency();
GLenum format;
GLenum type;
bool conv_needed = !to_opengl_pixelformat(image, format, type);
// also check for the pitch (GL1 can only skip pixels, not bytes)
if (!conv_needed)
{
const int bytesPerPixel = image.get_bytes_per_pixel();
if (image.get_pitch() % bytesPerPixel != 0)
conv_needed = true;
}
// no conversion needed
if (!conv_needed)
{
// Upload to GL1:
// change alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int bytesPerPixel = image.get_bytes_per_pixel();
#ifndef __ANDROID__
glPixelStorei(GL_UNPACK_ROW_LENGTH, image.get_pitch() / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
char *data = (char *) image.get_data();
int image_width = image.get_width();
int image_height = image.get_height() / image_depth;
glTexImage3D(
target, // target
level, // level
gl_internal_format, // internalformat
image_width, // width
image_height, // height
image_depth, // depth
0, // border
format, // format
type, // type
data); // texels
}
// conversion needed
else
{
bool big_endian = Endian::is_system_big();
PixelBuffer buffer(
image.get_width(), image.get_height(),
needs_alpha ? tf_rgba8 : tf_rgb8);
buffer.set_image(image);
format = needs_alpha ? GL_RGBA : GL_RGB;
// Upload to OpenGL:
// change alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
const int bytesPerPixel = buffer.get_bytes_per_pixel();
#ifndef __ANDROID__
glPixelStorei(GL_UNPACK_ROW_LENGTH, buffer.get_pitch() / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
#endif
int image_width = image.get_width();
int image_height = image.get_height() / image_depth;
// upload
glTexImage3D(
target, // target
level, // level
gl_internal_format, // internalformat
image_width, // width
image_height, // height
image_depth, // depth
0, // border
format, // format
GL_UNSIGNED_BYTE, // type
buffer.get_data()); // texels
}
}
示例2: _T
//.........这里部分代码省略.........
hSess = pHttpApi->OpenSession2(L"king_guard_softmgr", szProxy);
}
else
{
hSess = pHttpApi->OpenSession(L"king_guard_softmgr");
}
if(hSess == NULL) break;
pHttpApi->SetTimeouts(hSess, QUERY_TIMEOUT, QUERY_TIMEOUT, QUERY_TIMEOUT, QUERY_TIMEOUT);
hConn = pHttpApi->Connect(hSess, QUERY_SERVER_NAME, INTERNET_DEFAULT_PORT);
if(hConn == NULL) break;
hHttp = pHttpApi->OpenRequest(hConn, L"POST", QUERY_OBJECT_NAME, INTERNET_SCHEME_HTTP);
if(hHttp == NULL) break;
string bodyContent;
BOOL result = CombineBodyContent(queryInfoList, bodyContent);
if(!result) break;
result = pHttpApi->AddRequestHeaders(hHttp, pContentType);
if(!result) break;
//
// 设置代理用户名与密码
//
if(type == 1 && validate == 1)
{
if(pHttpApi->IsWinHttp())
{
pHttpApi->SetOption(hHttp, WINHTTP_OPTION_PROXY_USERNAME, szUser, wcslen(szUser));
pHttpApi->SetOption(hHttp, WINHTTP_OPTION_PROXY_PASSWORD, szPwd, wcslen(szPwd));
}
else
{
pHttpApi->SetOption(hHttp, INTERNET_OPTION_PROXY_USERNAME, szUser, wcslen(szUser));
pHttpApi->SetOption(hHttp, INTERNET_OPTION_PROXY_PASSWORD, szPwd, wcslen(szPwd));
}
}
result = pHttpApi->SendRequest(hHttp, &bodyContent[0], static_cast<DWORD>(bodyContent.size()));
if(!result) break;
result = pHttpApi->EndRequest(hHttp);
if(!result) break;
DWORD cbReturn = 0;
DWORD cbSize = sizeof(cbReturn);
result = pHttpApi->QueryInfo(hHttp, WINHTTP_QUERY_CONTENT_LENGTH | WINHTTP_QUERY_FLAG_NUMBER, reinterpret_cast<char*>(&cbReturn), &cbSize);
if(!result || cbReturn == 0) break;
auto_buffer<char> buffer(cbReturn + 2 + 1);
if(buffer.empty()) break;
DWORD cbRecved = 0;
result = pHttpApi->ReadData(hHttp, &buffer[0], cbReturn, &cbRecved);
if(!result || cbRecved != cbReturn) break;
// 在结尾加\r\n\0空字符
buffer[cbReturn] = '\r';
buffer[cbReturn + 1] = '\n';
buffer[cbReturn + 2] = '\0';
// 开始解析
TiXmlDocument xmlDoc;
if(xmlDoc.Parse(&buffer[0]) == NULL) break;
TiXmlHandle hRoot(xmlDoc.FirstChildElement("r"));
for(TiXmlElement *pElem = hRoot.FirstChildElement("sid").Element(); pElem != NULL; pElem = pElem->NextSiblingElement())
{
LPCSTR pId = pElem->Attribute("id");
if(pId == NULL) continue;
LONG id = atol(pId);
if(id == 0) continue;
TiXmlElement *ppElem = pElem->FirstChildElement("grade");
if(ppElem == NULL) continue;
LPCSTR pGrade = ppElem->GetText();
if(pGrade == NULL) continue;
resultList.push_back(SoftInfo2(id, wstring(CA2W(pGrade))));
}
succeeded = TRUE;
}
while(FALSE);
if(hHttp != NULL)
pHttpApi->CloseInternetHandle(hHttp);
if(hConn != NULL)
pHttpApi->CloseInternetHandle(hConn);
if(hSess != NULL)
pHttpApi->CloseInternetHandle(hSess);
return succeeded;
}
示例3: byteOffset
PassRefPtr<DataView> JSDataView::typedImpl()
{
return DataView::create(buffer(), byteOffset(), length());
}
示例4: glCreateShader
ShaderProgram::ShaderProgram(const char *vertex, const char *fragment, const ShaderFlags &flags)
{
File::uptr vs, fs;
v = glCreateShader(GL_VERTEX_SHADER);
f = glCreateShader(GL_FRAGMENT_SHADER);
uint64 size;
vs = File::map(vertex, File::Read, &size);
std::unique_ptr<char[]> vs1(new char[size + 1]);
memcpy(vs1.get(), vs.get(), size * sizeof(char));
vs1[size] = 0;
fs = File::map(fragment, File::Read, &size);
std::unique_ptr<char[]> fs1(new char[size + 1]);
memcpy(fs1.get(), fs.get(), size * sizeof(char));
fs1[size] = 0;
//TODO: Może troszkę to ulepszyć... (Chodzi o to, że header trzeba dokleić po #version)
const char * vv = vs1.get();
std::string fscode = fs1.get();
size_t ver = fscode.find("#version");
ver = fscode.find("\n", ver);
std::string ffs = fscode.substr(0, ver) + "\n" + flags.getHeader() + fscode.substr(ver + 1);
const char * ff = ffs.c_str();
glShaderSource(v, 1, &vv, NULL);
glShaderSource(f, 1, &ff, NULL);
GLint status;
glCompileShader(v);
glGetShaderiv(v, GL_INFO_LOG_LENGTH, &status);
std::unique_ptr<GLchar[]> buffer(new GLchar[status]);
glGetShaderInfoLog(v, status, &status, buffer.get());
glGetShaderiv(v, GL_COMPILE_STATUS, &status);
if(status != GL_TRUE)
RAISE(ShaderException, "Error while compiling Vertex Shader!", buffer.get());
else
LOG(errorLogger, "Vertex Shader Info Log:%s\n", buffer.get());
glCompileShader(f);
glGetShaderiv(f, GL_INFO_LOG_LENGTH, &status);
buffer = std::unique_ptr<GLchar[]>(new GLchar[status]);
glGetShaderInfoLog(f, status, &status, buffer.get());
glGetShaderiv(f, GL_COMPILE_STATUS, &status);
if(status != GL_TRUE)
RAISE(ShaderException, "Error while compiling Fragment Shader!", buffer.get());
else
LOG(errorLogger, "Fragment Shader Info Log:%s\n", buffer.get());
p = glCreateProgram();
glAttachShader(p, v);
glAttachShader(p, f);
glLinkProgram(p);
glValidateProgram(p);
glGetProgramiv(p, GL_INFO_LOG_LENGTH, &status);
buffer = std::unique_ptr<GLchar[]>(new GLchar[status]);
glGetProgramInfoLog(p, status, &status, buffer.get());
glGetProgramiv(p, GL_VALIDATE_STATUS, &status);
if(status != GL_TRUE)
RAISE(ShaderException, "Error while linking / validating Shader Program!", buffer.get());
else
LOG(errorLogger, "Shader Program Info Log:%s\n", buffer.get());
HASSERT(p && v && f);
}
示例5: buffer_size
friend inline size_t buffer_size(const scoped_buffer_type& _buffer)
{
return boost::asio::buffer_size(buffer(_buffer));
}
示例6: throw
void BufferedSocket::threadRead() throw(SocketException) {
if(state != RUNNING)
return;
DownloadManager *dm = DownloadManager::getInstance();
size_t readsize = inbuf.size();
bool throttling = false;
if(mode == MODE_DATA)
{
uint32_t getMaximum;
throttling = dm->throttle();
if (throttling)
{
getMaximum = dm->throttleGetSlice();
readsize = (uint32_t)min((int64_t)inbuf.size(), (int64_t)getMaximum);
if (readsize <= 0 || readsize > inbuf.size()) { // FIX
sleep(dm->throttleCycleTime());
return;
}
}
}
int left = sock->read(&inbuf[0], (int)readsize);
if(left == -1) {
// EWOULDBLOCK, no data received...
return;
} else if(left == 0) {
// This socket has been closed...
throw SocketException(_("Connection closed"));
}
string::size_type pos = 0;
// always uncompressed data
string l;
int bufpos = 0, total = left;
while (left > 0) {
switch (mode) {
case MODE_ZPIPE: {
const int BUF_SIZE = 1024;
// Special to autodetect nmdc connections...
string::size_type pos = 0;
boost::scoped_array<char> buffer(new char[BUF_SIZE]);
l = line;
// decompress all input data and store in l.
while (left) {
size_t in = BUF_SIZE;
size_t used = left;
bool ret = (*filterIn) (&inbuf[0] + total - left, used, &buffer[0], in);
left -= used;
l.append (&buffer[0], in);
// if the stream ends before the data runs out, keep remainder of data in inbuf
if (!ret) {
bufpos = total-left;
setMode (MODE_LINE, rollback);
break;
}
}
// process all lines
while ((pos = l.find(separator)) != string::npos) {
fire(BufferedSocketListener::Line(), l.substr(0, pos));
l.erase (0, pos + 1 /* separator char */);
}
// store remainder
line = l;
break;
}
case MODE_LINE:
// Special to autodetect nmdc connections...
if(separator == 0) {
if(inbuf[0] == '$') {
separator = '|';
} else {
separator = '\n';
}
}
l = line + string ((char*)&inbuf[bufpos], left);
while ((pos = l.find(separator)) != string::npos) {
fire(BufferedSocketListener::Line(), l.substr(0, pos));
l.erase (0, pos + 1 /* separator char */);
if (l.length() < (size_t)left) left = l.length();
if (mode != MODE_LINE) {
// we changed mode; remainder of l is invalid.
l.clear();
bufpos = total - left;
break;
}
}
if (pos == string::npos)
left = 0;
line = l;
break;
case MODE_DATA:
while(left > 0) {
if(dataBytes == -1) {
fire(BufferedSocketListener::Data(), &inbuf[bufpos], left);
bufpos += (left - rollback);
left = rollback;
rollback = 0;
} else {
int high = (int)min(dataBytes, (int64_t)left);
//.........这里部分代码省略.........
示例7: contentType
void PostRouteHandler::handleRequest(ServerEventArgs& evt)
{
try
{
Poco::Net::HTTPServerResponse& response = evt.getResponse();
// This uuid helps us track form progress updates.
std::string postId = Poco::UUIDGenerator::defaultGenerator().createOne().toString();
// Get the content type header (already checked in parent route).
Poco::Net::MediaType contentType(evt.getRequest().get("Content-Type", ""));
if (contentType.matches(POST_CONTENT_TYPE_URLENCODED) ||
contentType.matches(POST_CONTENT_TYPE_MULTIPART))
{
// Prepare the upload directory if needed.
if (contentType.matches(POST_CONTENT_TYPE_MULTIPART))
{
ofDirectory _uploadFolder(getRoute().getSettings().getUploadFolder());
if (!_uploadFolder.exists())
{
ofLogError("PostRouteHandler::handleRequest") << "Upload folder does not exist and cannot be created.";
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
getRoute().handleRequest(evt);
return;
}
}
PostRouteFileHandler postRoutePartHandler(getRoute(),
evt,
postId);
Poco::Net::HTMLForm form(contentType.toString());
form.setFieldLimit(getRoute().getSettings().getFieldLimit());
form.load(evt.getRequest(), evt.getRequest().stream(), postRoutePartHandler);
PostFormEventArgs args(evt,
postId,
form);
ofNotifyEvent(getRoute().events.onHTTPFormEvent, args, &getRoute());
if (form.has("destination") && !form.get("destination").empty())
{
response.redirect(form.get("destination"));
return;
}
}
else
{
// Poco::Net::HTMLForm, like php does not handle text/plain because
// it cannot be unambiguously encoded. Here we simply return
// the raw text with the event.
std::string result;
Poco::StreamCopier::copyToString(evt.getRequest().stream(),
result);
ofBuffer buffer(result);
PostEventArgs args(evt,
postId,
buffer);
ofNotifyEvent(getRoute().events.onHTTPPostEvent, args, &getRoute());
}
if (response.sent())
{
return;
}
else if (!getRoute().getSettings().getUploadRedirect().empty())
{
response.redirect(getRoute().getSettings().getUploadRedirect());
return;
}
else
{
// done
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_OK);
response.setContentLength(0);
response.send();
return;
}
}
catch (const Poco::Exception& exc)
{
evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, exc.displayText());
}
catch (const std::exception& exc)
{
evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR, exc.what());
}
catch (...)
{
evt.getResponse().setStatusAndReason(Poco::Net::HTTPResponse::HTTP_INTERNAL_SERVER_ERROR);
}
}
示例8: BOOST_ASIO_INITFN_RESULT_TYPE
template <typename Stream>
template <typename WriteHandler>
BOOST_ASIO_INITFN_RESULT_TYPE(WriteHandler,
void (boost::system::error_code, std::size_t))
buffered_write_stream<Stream>::async_flush(
BOOST_ASIO_MOVE_ARG(WriteHandler) handler)
{
// If you get an error on the following line it means that your handler does
// not meet the documented type requirements for a WriteHandler.
BOOST_ASIO_WRITE_HANDLER_CHECK(WriteHandler, handler) type_check;
async_completion<WriteHandler,
void (boost::system::error_code, std::size_t)> init(handler);
async_write(next_layer_, buffer(storage_.data(), storage_.size()),
detail::buffered_flush_handler<BOOST_ASIO_HANDLER_TYPE(
WriteHandler, void (boost::system::error_code, std::size_t))>(
storage_, init.completion_handler));
return init.result.get();
}
template <typename Stream>
template <typename ConstBufferSequence>
std::size_t buffered_write_stream<Stream>::write_some(
const ConstBufferSequence& buffers)
{
using boost::asio::buffer_size;
if (buffer_size(buffers) == 0)
return 0;
示例9: ReadBinary
// Read a block binary data
template< class T > std::vector<T> ReadBinary( u32 count ) {
std::vector<T> buffer(count);
if( stream.is_open() )
stream.read( (char*)buffer.data(), count * sizeof(T) );
return buffer;
}
示例10: selectionModel
void ExtendedTableWidget::paste()
{
// Get list of selected items
QItemSelectionModel* selection = selectionModel();
QModelIndexList indices = selection->selectedIndexes();
// Abort if there's nowhere to paste
if(indices.isEmpty())
return;
SqliteTableModel* m = qobject_cast<SqliteTableModel*>(model());
// We're also checking for system clipboard data first. Only if the data in the system clipboard is not ours, we use the system
// clipboard, otherwise we prefer the internal buffer. That's because the data in the internal buffer is easier to parse and more
// accurate, too. However, if we always preferred the internal copy-paste buffer there would be no way to copy data from other
// applications in here once the internal buffer has been filled.
// If clipboard contains an image and no text, just insert the image
const QMimeData* mimeClipboard = qApp->clipboard()->mimeData();
if (mimeClipboard->hasImage() && !mimeClipboard->hasText()) {
QImage img = qApp->clipboard()->image();
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
img.save(&buffer, "PNG"); // We're always converting the image format to PNG here. TODO: Is that correct?
buffer.close();
m->setData(indices.first(), ba);
return;
}
// Get the clipboard text
QString clipboard = qApp->clipboard()->text();
// If data in system clipboard is ours and the internal copy-paste buffer is filled, use the internal buffer; otherwise parse the
// system clipboard contents (case for data copied by other application).
QList<QByteArrayList> clipboardTable;
QList<QByteArrayList>* source;
if(mimeClipboard->hasHtml() && mimeClipboard->html().contains(m_generatorStamp) && !m_buffer.isEmpty())
{
source = &m_buffer;
} else {
clipboardTable = parseClipboard(clipboard);
source = &clipboardTable;
}
// Stop here if there's nothing to paste
if(!source->size())
return;
// Starting from assumption that selection is rectangular, and then first index is upper-left corner and last is lower-right.
int rows = source->size();
int columns = source->first().size();
int firstRow = indices.front().row();
int firstColumn = indices.front().column();
int selectedRows = indices.back().row() - firstRow + 1;
int selectedColumns = indices.back().column() - firstColumn + 1;
// If last row and column are after table size, clamp it
int lastRow = qMin(firstRow + rows - 1, m->rowCount() - 1);
int lastColumn = qMin(firstColumn + columns - 1, m->columnCount() - 1);
// Special case: if there is only one cell of data to be pasted, paste it into all selected fields
if(rows == 1 && columns == 1)
{
QByteArray data = source->first().first();
for(int row=firstRow;row<firstRow+selectedRows;row++)
{
for(int column=firstColumn;column<firstColumn+selectedColumns;column++)
m->setData(m->index(row, column), data);
}
return;
}
// If more than one cell was selected, check if the selection matches the cliboard dimensions
if(selectedRows != rows || selectedColumns != columns)
{
// Ask user if they are sure about this
if(QMessageBox::question(this, QApplication::applicationName(),
tr("The content of the clipboard is bigger than the range selected.\nDo you want to insert it anyway?"),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
{
// If the user doesn't want to paste the clipboard data anymore, stop now
return;
}
}
// If we get here, we can definitely start pasting: either the ranges match in their size or the user agreed to paste anyway
// Copy the data cell by cell and as-is from the source buffer to the table
int row = firstRow;
for(const QByteArrayList& source_row : *source)
{
int column = firstColumn;
for(const QByteArray& source_cell : source_row)
{
//.........这里部分代码省略.........
示例11: main
int main(int argc, char** argv)
{
std::cout << "Image from string..." << std::endl;
if (argc!=3)
{
std::cout << "Usage:" << argv[0] << " <path-to-image-file> <num_runs>" << std::endl;
return 1;
}
unsigned NUM_RUNS = std::atoi(argv[2]);
std::string filename(argv[1]);
// node-blend
{
std::cerr << "========== Node-blend ImageReader FROM FILE" << std::endl;
std::cout << "NUM_RUNS="<<NUM_RUNS << std::endl;
boost::timer::auto_cpu_timer t;
for (unsigned count=0; count < NUM_RUNS; ++count)
{
std::ifstream is(filename.c_str() , std::ios::binary);
std::string buffer((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
const std::unique_ptr<ImageReader> layer(ImageReader::create((uint8_t*)buffer.data(),buffer.size()));
layer->decode();
}
}
{ // mapnik
std::cerr << "========== Mapnik image_reader FROM FILE" << std::endl;
std::cout << "NUM_RUNS="<<NUM_RUNS << std::endl;
boost::timer::auto_cpu_timer t;
for (unsigned count=0; count < NUM_RUNS; ++count)
{
try {
const std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(filename));
unsigned width = reader->width();
unsigned height = reader->height();
mapnik::image_data_32 buffer(width,height);
reader->read(0,0,buffer);
}
catch (mapnik::image_reader_exception const& ex)
{
std::cerr << ex.what() << std::endl;
}
catch( std::exception const& ex)
{
std::cerr << ex.what() << std::endl;
}
}
}
std::ifstream is(filename.c_str() , std::ios::binary);
std::string buffer((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
// node-blend
{
std::cerr << "========== Node-blend ImageReader FROM MEM BUFFER" << std::endl;
std::cout << "NUM_RUNS="<<NUM_RUNS << std::endl;
boost::timer::auto_cpu_timer t;
for (unsigned count=0; count < NUM_RUNS; ++count)
{
const std::unique_ptr<ImageReader> layer(ImageReader::create((uint8_t*)buffer.data(),buffer.size()));
layer->decode();
}
}
{ // mapnik
std::cerr << "========== Mapnik image_reader FROM MEM BUFFER" << std::endl;
std::cout << "NUM_RUNS="<<NUM_RUNS << std::endl;
boost::timer::auto_cpu_timer t;
for (unsigned count=0; count < NUM_RUNS; ++count)
{
try {
const std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(buffer.data(), buffer.size()));
unsigned width = reader->width();
unsigned height = reader->height();
mapnik::image_data_32 buffer(width,height);
reader->read(0,0,buffer);
}
catch (mapnik::image_reader_exception const& ex)
{
std::cerr << ex.what() << std::endl;
}
catch( std::exception const& ex)
{
std::cerr << ex.what() << std::endl;
}
}
}
return 0;
}
示例12: buffer
void SkFlatPaint::dump() const {
SkPaint defaultPaint;
SkFlattenableReadBuffer buffer(fPaintData);
SkTypeface* typeface = (SkTypeface*) buffer.readPtr();
char pBuffer[DUMP_BUFFER_SIZE];
char* bufferPtr = pBuffer;
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"paint: ");
if (typeface != defaultPaint.getTypeface())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"typeface:%p ", typeface);
SkScalar textSize = buffer.readScalar();
if (textSize != defaultPaint.getTextSize())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"textSize:%g ", SkScalarToFloat(textSize));
SkScalar textScaleX = buffer.readScalar();
if (textScaleX != defaultPaint.getTextScaleX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"textScaleX:%g ", SkScalarToFloat(textScaleX));
SkScalar textSkewX = buffer.readScalar();
if (textSkewX != defaultPaint.getTextSkewX())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"textSkewX:%g ", SkScalarToFloat(textSkewX));
const SkPathEffect* pathEffect = (const SkPathEffect*) buffer.readFlattenable();
if (pathEffect != defaultPaint.getPathEffect())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"pathEffect:%p ", pathEffect);
SkDELETE(pathEffect);
const SkShader* shader = (const SkShader*) buffer.readFlattenable();
if (shader != defaultPaint.getShader())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"shader:%p ", shader);
SkDELETE(shader);
const SkXfermode* xfermode = (const SkXfermode*) buffer.readFlattenable();
if (xfermode != defaultPaint.getXfermode())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"xfermode:%p ", xfermode);
SkDELETE(xfermode);
const SkMaskFilter* maskFilter = (const SkMaskFilter*) buffer.readFlattenable();
if (maskFilter != defaultPaint.getMaskFilter())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"maskFilter:%p ", maskFilter);
SkDELETE(maskFilter);
const SkColorFilter* colorFilter = (const SkColorFilter*) buffer.readFlattenable();
if (colorFilter != defaultPaint.getColorFilter())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"colorFilter:%p ", colorFilter);
SkDELETE(colorFilter);
const SkRasterizer* rasterizer = (const SkRasterizer*) buffer.readFlattenable();
if (rasterizer != defaultPaint.getRasterizer())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"rasterizer:%p ", rasterizer);
SkDELETE(rasterizer);
const SkDrawLooper* drawLooper = (const SkDrawLooper*) buffer.readFlattenable();
if (drawLooper != defaultPaint.getLooper())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"drawLooper:%p ", drawLooper);
SkDELETE(drawLooper);
unsigned color = buffer.readU32();
if (color != defaultPaint.getColor())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"color:0x%x ", color);
SkScalar strokeWidth = buffer.readScalar();
if (strokeWidth != defaultPaint.getStrokeWidth())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"strokeWidth:%g ", SkScalarToFloat(strokeWidth));
SkScalar strokeMiter = buffer.readScalar();
if (strokeMiter != defaultPaint.getStrokeMiter())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"strokeMiter:%g ", SkScalarToFloat(strokeMiter));
unsigned flags = buffer.readU16();
if (flags != defaultPaint.getFlags())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"flags:0x%x ", flags);
int align = buffer.readU8();
if (align != defaultPaint.getTextAlign())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"align:0x%x ", align);
int strokeCap = buffer.readU8();
if (strokeCap != defaultPaint.getStrokeCap())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"strokeCap:0x%x ", strokeCap);
int strokeJoin = buffer.readU8();
if (strokeJoin != defaultPaint.getStrokeJoin())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"align:0x%x ", strokeJoin);
int style = buffer.readU8();
if (style != defaultPaint.getStyle())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"style:0x%x ", style);
int textEncoding = buffer.readU8();
if (textEncoding != defaultPaint.getTextEncoding())
bufferPtr += snprintf(bufferPtr, DUMP_BUFFER_SIZE - (bufferPtr - pBuffer),
"textEncoding:0x%x ", textEncoding);
SkDebugf("%s\n", pBuffer);
}
示例13: read_with_bom
std::u32string read_with_bom(std::istream & src)
{
enum encoding {
encoding_utf32be = 0,
encoding_utf32le,
encoding_utf16be,
encoding_utf16le,
encoding_utf8,
encoding_ascii,
};
std::vector<std::string> boms = {
std::string("\x00\x00\xFE\xFF", 4),
std::string("\xFF\xFE\x00\x00", 4),
std::string("\xFE\xFF", 2),
std::string("\xFF\xFE", 2),
std::string("\xEF\xBB\xBF", 3)
};
std::string buffer((std::istreambuf_iterator<char>(src)), std::istreambuf_iterator<char>());
encoding enc = encoding_ascii;
for (unsigned int i = 0; i < boms.size(); ++i) {
std::string testBom = boms[i];
if (buffer.compare(0, testBom.length(), testBom) == 0) {
enc = encoding(i);
buffer = buffer.substr(testBom.length());
break;
}
}
switch (enc) {
case encoding_utf32be:
{
if (buffer.length() % 4 != 0) {
throw std::logic_error("size in bytes must be a multiple of 4");
}
int count = buffer.length() / 4;
std::u32string temp = std::u32string(count, 0);
for (int i = 0; i < count; ++i) {
temp[i] = static_cast<char32_t>(buffer[i * 4 + 3] << 0 | buffer[i * 4 + 2] << 8 | buffer[i * 4 + 1] << 16 | buffer[i * 4 + 0] << 24);
}
return temp;
}
case encoding_utf32le:
{
if (buffer.length() % 4 != 0) {
throw std::logic_error("size in bytes must be a multiple of 4");
}
int count = buffer.length() / 4;
std::u32string temp = std::u32string(count, 0);
for (int i = 0; i < count; ++i) {
temp[i] = static_cast<char32_t>(buffer[i * 4 + 0] << 0 | buffer[i * 4 + 1] << 8 | buffer[i * 4 + 2] << 16 | buffer[i * 4 + 3] << 24);
}
return temp;
}
case encoding_utf16be:
{
if (buffer.length() % 2 != 0) {
throw std::logic_error("size in bytes must be a multiple of 2");
}
int count = buffer.length() / 2;
std::u16string temp = std::u16string(count, 0);
for (int i = 0; i < count; ++i) {
temp[i] = static_cast<char16_t>(buffer[i * 2 + 1] << 0 | buffer[i * 2 + 0] << 8);
}
return to_utf32(temp);
}
case encoding_utf16le:
{
if (buffer.length() % 2 != 0) {
throw std::logic_error("size in bytes must be a multiple of 2");
}
int count = buffer.length() / 2;
std::u16string temp = std::u16string(count, 0);
for (int i = 0; i < count; ++i) {
temp[i] = static_cast<char16_t>(buffer[i * 2 + 0] << 0 | buffer[i * 2 + 1] << 8);
}
return to_utf32(temp);
}
default:
return to_utf32(buffer);
}
}
示例14: buffer
void NoGhostGameofLife::update_neighbor_values_with_remote_elements()
{
stk::CommSparse buffer(m_bulkData->parallel());
send_num_active_neighbors_of_remote_elem_keys(buffer);
recieve_num_active_neighbors_of_local_elements(buffer);;
}
示例15: ASSERT
bool AudioBufferSourceNode::renderFromBuffer(ContextRenderLock& r, AudioBus* bus, unsigned destinationFrameOffset, size_t numberOfFrames)
{
if (!r.context())
return false;
// Basic sanity checking
ASSERT(bus);
ASSERT(buffer());
if (!bus || !buffer())
return false;
unsigned numChannels = numberOfChannels(r);
unsigned busNumberOfChannels = bus->numberOfChannels();
bool channelCountGood = numChannels && numChannels == busNumberOfChannels;
ASSERT(channelCountGood);
if (!channelCountGood)
return false;
// Sanity check destinationFrameOffset, numberOfFrames.
size_t destinationLength = bus->length();
bool isLengthGood = destinationLength <= 4096 && numberOfFrames <= 4096;
ASSERT(isLengthGood);
if (!isLengthGood)
return false;
bool isOffsetGood = destinationFrameOffset <= destinationLength && destinationFrameOffset + numberOfFrames <= destinationLength;
ASSERT(isOffsetGood);
if (!isOffsetGood)
return false;
// Potentially zero out initial frames leading up to the offset.
if (destinationFrameOffset) {
for (unsigned i = 0; i < numChannels; ++i)
memset(m_destinationChannels[i], 0, sizeof(float) * destinationFrameOffset);
}
// Offset the pointers to the correct offset frame.
unsigned writeIndex = destinationFrameOffset;
size_t bufferLength = buffer()->length();
double bufferSampleRate = buffer()->sampleRate();
// Avoid converting from time to sample-frames twice by computing
// the grain end time first before computing the sample frame.
unsigned endFrame = m_isGrain ? AudioUtilities::timeToSampleFrame(m_grainOffset + m_grainDuration, bufferSampleRate) : bufferLength;
// This is a HACK to allow for HRTF tail-time - avoids glitch at end.
// FIXME: implement tailTime for each AudioNode for a more general solution to this problem.
// https://bugs.webkit.org/show_bug.cgi?id=77224
if (m_isGrain)
endFrame += 512;
// Do some sanity checking.
if (endFrame > bufferLength)
endFrame = bufferLength;
if (m_virtualReadIndex >= endFrame)
m_virtualReadIndex = 0; // reset to start
// If the .loop attribute is true, then values of m_loopStart == 0 && m_loopEnd == 0 implies
// that we should use the entire buffer as the loop, otherwise use the loop values in m_loopStart and m_loopEnd.
double virtualEndFrame = endFrame;
double virtualDeltaFrames = endFrame;
if (loop() && (m_loopStart || m_loopEnd) && m_loopStart >= 0 && m_loopEnd > 0 && m_loopStart < m_loopEnd) {
// Convert from seconds to sample-frames.
double loopStartFrame = m_loopStart * buffer()->sampleRate();
double loopEndFrame = m_loopEnd * buffer()->sampleRate();
virtualEndFrame = std::min(loopEndFrame, virtualEndFrame);
virtualDeltaFrames = virtualEndFrame - loopStartFrame;
}
double pitchRate = totalPitchRate(r);
// Sanity check that our playback rate isn't larger than the loop size.
if (fabs(pitchRate) >= virtualDeltaFrames)
return false;
// Get local copy.
double virtualReadIndex = m_virtualReadIndex;
// Render loop - reading from the source buffer to the destination using linear interpolation.
int framesToProcess = numberOfFrames;
const float** sourceChannels = m_sourceChannels.get();
float** destinationChannels = m_destinationChannels.get();
// Optimize for the very common case of playing back with pitchRate == 1.
// We can avoid the linear interpolation.
if (pitchRate == 1 && virtualReadIndex == floor(virtualReadIndex)
&& virtualDeltaFrames == floor(virtualDeltaFrames)
&& virtualEndFrame == floor(virtualEndFrame)) {
unsigned readIndex = static_cast<unsigned>(virtualReadIndex);
unsigned deltaFrames = static_cast<unsigned>(virtualDeltaFrames);
endFrame = static_cast<unsigned>(virtualEndFrame);
while (framesToProcess > 0) {
int framesToEnd = endFrame - readIndex;
//.........这里部分代码省略.........