void FEMorphology::platformApplySoftware() { FilterEffect* in = inputEffect(0); ByteArray* dstPixelArray = createPremultipliedImageResult(); if (!dstPixelArray) return; setIsAlphaImage(in->isAlphaImage()); if (m_radiusX <= 0 || m_radiusY <= 0) { dstPixelArray->clear(); return; } Filter* filter = this->filter(); int radiusX = static_cast<int>(floorf(filter->applyHorizontalScale(m_radiusX))); int radiusY = static_cast<int>(floorf(filter->applyVerticalScale(m_radiusY))); IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect()); RefPtr<ByteArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect); PaintingData paintingData; paintingData.srcPixelArray = srcPixelArray.get(); paintingData.dstPixelArray = dstPixelArray; paintingData.width = effectDrawingRect.width(); paintingData.height = effectDrawingRect.height(); paintingData.radiusX = min(effectDrawingRect.width() - 1, radiusX); paintingData.radiusY = min(effectDrawingRect.height() - 1, radiusY); platformApply(&paintingData); }
void ModificationMap::applyModifications(UpdatableByteContainer &ubc) { if(isEmpty()) { return; } Iterator<Entry<__int64, BytePair> > it = entrySet().getIterator(); Entry<__int64, BytePair> &e = it.next(); __int64 seqStartAddr = e.getKey(); __int64 lastAddr = seqStartAddr; ByteArray byteSequence; byteSequence.append(e.getValue().getTo()); while(it.hasNext()) { Entry<__int64, BytePair> &e1 = it.next(); const __int64 addr = e1.getKey(); if(addr != lastAddr+1) { ubc.putBytes(seqStartAddr, byteSequence); byteSequence.clear(); seqStartAddr = addr; } byteSequence.append(e1.getValue().getTo()); lastAddr = addr; } ubc.putBytes(seqStartAddr, byteSequence); // byteSequence is NOT empty }
bool ReadList(MyTokenizer &st, ByteArray &a, wxString &nextToken) { uint8 val; a.clear(); nextToken = st.GetNextToken(); while (ReadUserNumber(nextToken, val)) { a.push_back(val); nextToken = st.GetNextToken(); } return a.size() > 0; }
void FETurbulence::platformApplySoftware() { ByteArray* pixelArray = createUnmultipliedImageResult(); if (!pixelArray) return; if (absolutePaintRect().isEmpty()) { pixelArray->clear(); return; } PaintingData paintingData(m_seed, roundedIntSize(filterPrimitiveSubregion().size())); initPaint(paintingData); #if ENABLE(PARALLEL_JOBS) int optimalThreadNumber = (absolutePaintRect().width() * absolutePaintRect().height()) / s_minimalRectDimension; if (optimalThreadNumber > 1) { // Initialize parallel jobs ParallelJobs<FillRegionParameters> parallelJobs(&WebCore::FETurbulence::fillRegionWorker, optimalThreadNumber); // Fill the parameter array int i = parallelJobs.numberOfJobs(); if (i > 1) { int startY = 0; int stepY = absolutePaintRect().height() / i; for (; i > 0; --i) { FillRegionParameters& params = parallelJobs.parameter(i-1); params.filter = this; params.pixelArray = pixelArray; params.paintingData = &paintingData; params.startY = startY; if (i != 1) { params.endY = startY + stepY; startY = startY + stepY; } else params.endY = absolutePaintRect().height(); } // Execute parallel jobs parallelJobs.execute(); return; } } // Fallback to sequential mode if there is no room for a new thread or the paint area is too small #endif // ENABLE(PARALLEL_JOBS) fillRegion(pixelArray, paintingData, 0, absolutePaintRect().height()); }
TEST(ByteArrayTest, Clear) { ByteArray ba = "This is a test"; ba.clear(); ASSERT_FALSE(ba.isNull()); ASSERT_TRUE(ba.isEmpty()); ba = "This is a test"; ByteArray clone = ba; ba.clear(); ASSERT_FALSE(ba.isNull()); ASSERT_TRUE(ba.isEmpty()); ASSERT_FALSE(clone.isNull()); ASSERT_FALSE(clone.isEmpty()); clone.clear(); ASSERT_FALSE(clone.isNull()); ASSERT_TRUE(clone.isEmpty()); }
size_t Buffer::readByteArray(ByteArray& _dst, size_t _size, size_t _offset) { if(_offset != npos) _pf_readOffset = _offset; _pm_checkIfEnoughBytesToRead(_size, _pf_readOffset); _dst.clear(); _dst.reserve(_size); std::copy(_pf_buffer.begin() + _offset, _pf_buffer.begin() + _offset + _size, _dst.begin()); _pf_readOffset += _size; return _pf_readOffset; }
ByteArray jDataSegment::getData() { ByteArray data; jbyteArray dataArr = getByteArray(this, "data"); jsize length = env->GetArrayLength(dataArr); jbyte *data_ptr = env->GetByteArrayElements(dataArr, NULL); if (data_ptr != NULL) { data.resize(length); copy(data_ptr, data_ptr + length, data.begin()); env->ReleaseByteArrayElements(dataArr, data_ptr, JNI_ABORT); } else { data.clear(); } env->DeleteLocalRef(dataArr); return data; }
void Process::handleOutput(int fd, ByteArray& buffer, int& index, signalslot::Signal0& signal) { //printf("Process::handleOutput %d\n", fd); enum { BufSize = 1024, MaxSize = (1024 * 1024 * 16) }; char buf[BufSize]; int total = 0; for (;;) { int r; eintrwrap(r, ::read(fd, buf, BufSize)); if (r == -1) { //printf("Process::handleOutput %d returning -1, errno %d %s\n", fd, errno, strerror(errno)); break; } else if (r == 0) { // file descriptor closed, remove it //printf("Process::handleOutput %d returning 0\n", fd); EventLoop::instance()->removeFileDescriptor(fd); break; } else { //printf("Process::handleOutput in loop %d\n", fd); //printf("data: '%s'\n", std::string(buf, r).c_str()); int sz = buffer.size(); if (sz + r > MaxSize) { if (sz + r - index > MaxSize) { error("Process::handleOutput, buffer too big, dropping data"); buffer.clear(); index = sz = 0; } else { sz = buffer.size() - index; memmove(buffer.data(), buffer.data() + index, sz); buffer.resize(sz); index = 0; } } buffer.resize(sz + r); memcpy(buffer.data() + sz, buf, r); total += r; } } //printf("total data '%s'\n", buffer.nullTerminated()); if (total) signal(); }
void File::Read( ByteArray& buffer, uint size ) { if( m_fd < 0 ) { THROW_ERROR( "Can't read from a closed file" ); } buffer.clear(); char inbuf[UTIL_FILE_READBUF_SIZE]; while( size > 0 ) { size_t max_read; if( size > sizeof(inbuf) ) { max_read = sizeof(inbuf); } else { max_read = size; } ssize_t n = read( m_fd, inbuf, max_read ); if( n < 0 ) { if( errno == EINTR ) continue; THROW_ERROR( "Failed to read data from the file (Error=%s)", strerror(errno) ); } buffer.append( inbuf, n ); size -= n; if( (size_t)n < max_read ) break; } }
static bool read_property(Display *dpy, Window win, Atom property, bool deleteProperty, ByteArray & buffer, int *size, Atom *type, int *format, bool nullterm) { int maxsize = max_selection_incr(dpy); unsigned long bytes_left; unsigned long length; unsigned char *data; Atom dummy_type; int dummy_format; if (!type) type = &dummy_type; if (!format) format = &dummy_format; // Don't read anything but get the size of the property data if (XGetWindowProperty(dpy, win, property, 0, 0, False, AnyPropertyType, type, format, &length, &bytes_left, &data) != Success) { buffer.clear(); return false; } XFree(data); int offset = 0, buffer_offset = 0, format_inc = 1, proplen = bytes_left; switch (*format) { case 16: format_inc = sizeof(short) / 2; proplen *= format_inc; break; case 32: format_inc = sizeof(long) / 4; proplen *= format_inc; break; } buffer.resize(proplen + (nullterm ? 1 : 0)); while (bytes_left) { if (XGetWindowProperty(dpy, win, property, offset, maxsize / 4, False, AnyPropertyType, type, format, &length, &bytes_left, &data) != Success) break; offset += length / (32 / *format); length *= format_inc * (*format / 8); memcpy(buffer.data() + buffer_offset, data, length); buffer_offset += length; XFree(data); } if (nullterm) buffer[buffer_offset] = '\0'; if (size) *size = buffer_offset; if (deleteProperty) XDeleteProperty(dpy, win, property); XFlush(dpy); return true; }