OSCMessage& OSCMessage::start(char * _address, uint8_t * buffer, int maximumBytes, int len){ //set the msg data to the beginning of the received buffer setBuffer(buffer); maxBytes(maximumBytes); //the length of the address int addrLen = strlen(_address); //set the address in memory addToBuffer((uint8_t *) _address, addrLen ); //pad address addPadToBuffer(padSize(addrLen)); //comma delimiter addToBuffer(uint8_t(',')); //beginning of type section typePtr = currentBufferPosition(); //jump to beginning of padding msgBytes+=len; //pad the type section addPadToBuffer(padSize(len+1)); //beginning of data section dataPtr = currentBufferPosition(); //number of datum dataSize = len; //read/write position in the message position = 0; return *this; }
QStringList AudioCdRecord::arguments() const { QStringList args; /*! --------------------- Normal Arguments --------------------!*/ args << "-v"; if( publicRead() ) args << "-r"; if( dummy() ) args << "-dummy"; if( force() ) args << "-force"; if( sessionAtOnce() ) args << "-sao"; if( trackAtOnce() ) args << "-tao"; if( swab() ) args << "-swab"; if( multiSession() ) args << "-multi"; if( pad() ) args << "-pad"; if( pad() && padSize() > 0 ) args << QString::number( padSize() ); if( eject() ) args << "-eject"; if( ringBuffer() > 0 ) args << "fs=" + QString::number( ringBuffer() ); if( minimumBuffer() > 0 ) args << "minbuf=" + QString::number( minimumBuffer() ); if( speed() > 0 ) args << "speed=" + QString::number( speed() ); args << "dev=" + currentDevice().toQString(); args << "-audio"; args << files(); /*! -----------------------------------------------------------!*/ return args; }
/* * Implementation of stdlib realloc. */ void * realloc(void *ptr, size_t size) { AllocUnit *au, *newAU; size_t paddedSize; if (size == 0) { free(ptr); return NULL; } paddedSize = padSize(size); if (!init()) { errno = ENOMEM; return NULL; } au = findAU(startHeap, (uintptr_t) ptr); if (au == NULL || ptr == NULL) { return malloc(size); } newAU = reallocate(au, paddedSize); if (newAU == NULL) { errno = ENOMEM; return NULL; } if (debugMalloc()) { printf("MALLOC: realloc(%p,%zu) => (ptr=%p, size=%zu)\n",ptr, size,newAU->memLoc,newAU->size); } return newAU->memLoc; }
void OSCMessage::reset(){ //reset everything back to the beginning position = 0; error = OSC_OK; typePtr = msgData; while(*typePtr++ != ','); dataPtr = typePtr+dataSize+padSize(dataSize+1); }
OSCMessage& OSCMessage::add(char * data) { //first put in the type addType('s'); //then the data addToBuffer((uint8_t *) data, strlen(data)); //pad the string; addPadToBuffer(padSize(strlen(data))); return *this; }
OSCMessage& OSCMessage::add(uint8_t * data, int len) { //first put in the type addType('b'); //then the length addToBuffer(int32_t(len)); //then the data addToBuffer(data, len); //pad the blob; addPadToBuffer(padSize(len)); return *this; }
Matrix2 psf2otf(Matrix& psf, Matrix& outSize) { Matrix psfSize(1, 2); psfSize(0, 0) = psf.size1(); psfSize(0, 1) = psf.size2(); Matrix padSize(1, 2); padSize = outSize - psfSize; psf = padarray(psf, padSize); psf = circshift(psf, -Matfloor(psfSize / 2)); Matrix2 otf = fft2(psf); return otf; }
/* * Implementation of stdlib calloc. */ void * calloc(size_t nmemb, size_t size) { int paddedSize; AllocUnit *au; paddedSize = padSize(nmemb * size); au = allocateNew(paddedSize); if (au == NULL) { errno = ENOMEM; return NULL; } memset(au->memLoc, 0, paddedSize); if (debugMalloc()) { printf("MALLOC: calloc(%zu,%zu) => (ptr=%p, size=%zu)\n",nmemb, size,au->memLoc,au->size); } return au->memLoc; }
/* * Finds a free AllocUnit of the correct size, and returns it. Also creates * the next free AllocUnit if the next AU is NULL with the available space. */ AllocUnit *allocateNew(size_t size) { AllocUnit *freeAU; size_t paddedSize = padSize(size); if (!init()) { return NULL; } freeAU = getFreeAU(startHeap, paddedSize); if (freeAU == NULL) { return NULL; } freeAU = unfreeAU(freeAU, paddedSize); return freeAU; }
bool OSCMessage::parse(){ //start with new stats; position = 0; dataSize = 0; //move typePtr to beginning of types typePtr = msgData; while(*typePtr++ != ','); //count the size uint8_t * counter = typePtr; //count each of the types; while (*counter++) dataSize++; //dataPtr is after the type + padding dataPtr = counter+padSize(dataSize+1)-1; //is the message well-formed? //return check(); return true; }
QImage RichTextRenderer::renderText() { // qDebug()<<itemName()<<"TextBoxWarmingThread::run(): htmlCode:"<<htmlCode; //qDebug() << "RichTextRenderer::renderText(): HTML:"<<html(); //qDebug() << "RichTextRenderer::update(): Update Start..."; //qDebug() << "RichTextRenderer::renderText(): \t in thread:"<<QThread::currentThreadId(); if(m_updateTimer.isActive()) m_updateTimer.stop(); QTime renderTime; renderTime.start(); QTextDocument doc; QTextDocument shadowDoc; if (Qt::mightBeRichText(html())) { doc.setHtml(html()); shadowDoc.setHtml(html()); } else { doc.setPlainText(html()); shadowDoc.setPlainText(html()); } int textWidth = m_textWidth; doc.setTextWidth(textWidth); shadowDoc.setTextWidth(textWidth); // Apply outline pen to the html QTextCursor cursor(&doc); cursor.select(QTextCursor::Document); QTextCharFormat format; QPen p(Qt::NoPen); if(outlineEnabled()) { p = outlinePen(); p.setJoinStyle(Qt::MiterJoin); } format.setTextOutline(p); //format.setForeground(fillEnabled() ? fillBrush() : Qt::NoBrush); //Qt::white); cursor.mergeCharFormat(format); // Setup the shadow text formatting if enabled if(shadowEnabled()) { if(shadowBlurRadius() <= 0.05) { QTextCursor cursor(&shadowDoc); cursor.select(QTextCursor::Document); QTextCharFormat format; format.setTextOutline(Qt::NoPen); format.setForeground(shadowBrush()); cursor.mergeCharFormat(format); } } QSizeF shadowSize = shadowEnabled() ? QSizeF(shadowOffsetX(),shadowOffsetY()) : QSizeF(0,0); QSizeF docSize = doc.size(); QSizeF padSize(12.,12.); QSizeF sumSize = (docSize + shadowSize + padSize);//.toSize(); QSizeF scaledSize = QSizeF(sumSize.width() * m_scaling.x(), sumSize.height() * m_scaling.y()); if(m_scaling.x() != 1. || m_scaling.y() != 1.) { //qDebug() << "RichTextRenderer::renderText(): Orig size:"<<sumSize<<", scaled size:"<<scaledSize<<", scaling:"<<m_scaling; m_rawSize = sumSize; } //qDebug() << "RichTextRenderer::update(): textWidth: "<<textWidth<<", shadowSize:"<<shadowSize<<", docSize:"<<docSize<<", sumSize:"<<sumSize; QImage cache(scaledSize.toSize(),QImage::Format_ARGB32); //_Premultiplied); memset(cache.scanLine(0),0,cache.byteCount()); double padSizeHalfX = padSize.width() / 2; double padSizeHalfY = padSize.height() / 2; QPainter textPainter(&cache); textPainter.scale(m_scaling.x(), m_scaling.y()); //textPainter.fillRect(cache.rect(),Qt::transparent); QAbstractTextDocumentLayout::PaintContext pCtx; //qDebug() << "RichTextRenderer::renderText(): shadowEnabled():"<<shadowEnabled()<<", shadowBlurRadius():"<<shadowBlurRadius(); if(shadowEnabled()) { if(shadowBlurRadius() <= 0.05) { // render a "cheap" version of the shadow using the shadow text document textPainter.save(); textPainter.translate(shadowOffsetX(),shadowOffsetY()); shadowDoc.documentLayout()->draw(&textPainter, pCtx); textPainter.restore(); } else { double radius = shadowBlurRadius(); // create temporary pixmap to hold a copy of the text QSizeF blurSize = ImageFilters::blurredSizeFor(doc.size(), (int)radius); QSizeF scaledBlurSize = QSize(blurSize.width() * m_scaling.x(), blurSize.height() * m_scaling.y()); //QSize docSize = doc.size(); //qDebug() << "RichTextRenderer::renderText(): [shadow] radius:"<<radius<<" blurSize:"<<blurSize<<", scaling:"<<m_scaling<<", scaledBlurSize:"<<scaledBlurSize; //qDebug() << "Blur size:"<<blurSize<<", doc:"<<doc.size()<<", radius:"<<radius; QImage tmpImage(scaledBlurSize.toSize(),QImage::Format_ARGB32_Premultiplied); memset(tmpImage.scanLine(0),0,tmpImage.byteCount()); // render the text QPainter tmpPainter(&tmpImage); tmpPainter.scale(m_scaling.x(), m_scaling.y()); tmpPainter.save(); tmpPainter.translate(radius + padSizeHalfX, radius + padSizeHalfY); doc.documentLayout()->draw(&tmpPainter, pCtx); tmpPainter.restore(); // blacken the text by applying a color to the copy using a QPainter::CompositionMode_DestinationIn operation. // This produces a homogeneously-colored pixmap. QRect rect = tmpImage.rect(); tmpPainter.setCompositionMode(QPainter::CompositionMode_SourceIn); tmpPainter.fillRect(rect, shadowBrush().color()); tmpPainter.end(); // blur the colored text ImageFilters::blurImage(tmpImage, (int)radius); // render the blurred text at an offset into the cache textPainter.save(); textPainter.translate(shadowOffsetX() - radius, shadowOffsetY() - radius); textPainter.drawImage(0, 0, tmpImage); textPainter.restore(); } } textPainter.translate(padSizeHalfX, padSizeHalfY); doc.documentLayout()->draw(&textPainter, pCtx); textPainter.end(); m_image = cache.convertToFormat(QImage::Format_ARGB32); emit textRendered(m_image); //qDebug() << "RichTextRenderer::renderText(): Render finished, elapsed:"<<renderTime.elapsed()<<"ms"; //m_image.save("debug-text.png"); return m_image; }
// allocate unaligned data // TODO test cache-friendly distributions // MLSample* MLSignal::allocateData(int size) { MLSample* newData = 0; newData = new MLSample[padSize(size)]; return newData; }