示例#1
0
void CCImageRenderer::convert_data(const ByteArray &data)
{
	DPTR_D(CCImageRenderer);
	if (!d.scale_in) {
		/*if lock is required, do not use locker in if() scope, it will unlock outside the scope*/
		d.mutex_.lock();
		//qDebug("data address = %p, %p", data.data(), d.data.data());
#if QT_VERSION >= QT_VERSION_CHECK(4, 0, 0)
		d.image = *&QImage((uchar*)data.data(), d.src_width, d.src_height, QImage::Format_RGB32);
#else
		d.image = QImage((uchar*)d.data.data(), d.src_width, d.src_height, 16, NULL, 0, QImage::IgnoreEndian);
#endif
		d.mutex_.unlock();
	}
	else {
		//qDebug("data address = %p", data.data());
#if QT_VERSION >= QT_VERSION_CHECK(4, 0, 0)
		d.image = *&QImage((uchar*)data.data(), d.src_width, d.src_height, QImage::Format_RGB32);
#else
		d.image = QImage((uchar*)data.data(), d.src_width, d.src_height, 16, NULL, 0, QImage::IgnoreEndian);
#endif
	}
// #if QT_VERSION >= QT_VERSION_CHECK(4, 0, 0)
// 	d.image = *&QImage((uchar*)data.data(), d.src_width, d.src_height, QImage::Format_RGB32);
// #else
// 	d.image = QImage((uchar*)data.data(), d.src_width, d.src_height, 16, NULL, 0, QImage::IgnoreEndian);
// #endif
}
		size_t Send(const ByteArray &inputData)
		{
			size_t r = std::min(Buffer.size(), inputData.size());
			std::copy(inputData.data(), inputData.data() + r, Buffer.data());
			KernelUrb.buffer_length = r;
			return r;
		}
示例#3
0
Directory Directory::applicationDir()
{
#ifdef CAESARIA_PLATFORM_WIN
  unsigned int pathSize=512;
  ByteArray tmpPath;
  tmpPath.resize( pathSize );
  GetModuleFileNameA( 0, tmpPath.data(), pathSize);
  Directory tmp( std::string( tmpPath.data() ) );
  tmp = tmp.up();
  return tmp;
#elif defined(CAESARIA_PLATFORM_LINUX)
  char exe_path[PATH_MAX] = {0};
  sprintf(exe_path, "/proc/%d/exe", ::getpid());
  readlink(exe_path, exe_path, sizeof(exe_path));
  vfs::Directory wdir = vfs::Path( exe_path ).directory();
  //dir_path = dirname(exe_path);
  return wdir;
/*#elif defined(CAESARIA_PLATFORM_HAIKU)
  char exe_path[PATH_MAX] = {0};
  sprintf(exe_path, "/proc/%d/exe", getpid());
  readlink(exe_path, exe_path, sizeof(exe_path));
  dirname(exe_path);
  return Path( exe_path );*/
#elif defined(CAESARIA_PLATFORM_MACOSX)
  char exe_path[PROC_PIDPATHINFO_MAXSIZE];
  int ret = proc_pidpath(getpid(), exe_path, sizeof(exe_path));
  if (ret <= 0)
  {
    THROW("Cannot get application executable file path");
  }
  return Path(dirname(exe_path));
#endif

  return Path( "." );
}
示例#4
0
FileDir FileDir::getApplicationDir()
{
#ifdef WIN32
  unsigned int pathSize=512;
  ByteArray tmpPath;
  tmpPath.resize( pathSize );
  GetModuleFileName( 0, tmpPath.data(), pathSize);
  FilePath tmp = tmpPath.data();

  tmp = tmp.getUpDir();
  //delete tmpPath;

  return tmp;
#elif defined(__linux__)
  char exe_path[PATH_MAX] = {0};
  char * dir_path;
  sprintf(exe_path, "/proc/%d/exe", getpid());
  readlink(exe_path, exe_path, sizeof(exe_path));
  dir_path = dirname(exe_path);
  return FilePath(dir_path);
#elif defined(__APPLE__)
  char exe_path[PROC_PIDPATHINFO_MAXSIZE];
  int ret = proc_pidpath(getpid(), exe_path, sizeof(exe_path));
  if (ret <= 0)
  {
    THROW("Cannot get application executable file path");
  }
  return FilePath(dirname(exe_path));
#endif

  return FilePath( "." );
}
示例#5
0
bool operator==(const ByteArray& op1, const ByteArray& op2)
{
    if (op1.size() != op2.size())
        return false;

    if (op1.data() == op2.data())
        return true;

    return (memcmp(op1.data(), op2.data(), op1.size()) == 0);
}
示例#6
0
/*
 * Class:     im_tox_tox4j_impl_ToxCoreJni
 * Method:    toxFriendAdd
 * Signature: (I[B[B)I
 */
TOX_METHOD (jint, FriendAdd,
  jint instanceNumber, jbyteArray address, jbyteArray message)
{
  ByteArray messageData (env, message);
  ByteArray addressData (env, address);
  tox4j_assert (!address || addressData.size () == TOX_ADDRESS_SIZE);
  return instances.with_instance_err (env, instanceNumber,
    identity,
    tox_friend_add, addressData.data (), messageData.data (), messageData.size ()
  );
}
示例#7
0
std::vector<PsxLibEntry> loadPsxLibrary(const std::wstring& inputName)
{
	ByteArray input = ByteArray::fromFile(inputName);
	std::vector<PsxLibEntry> result;

	if (input.size() == 0)
		return result;

	if (memcmp(input.data(),psxObjectFileMagicNum,sizeof(psxObjectFileMagicNum)) == 0)
	{
		PsxLibEntry entry;
		entry.name = getFileNameFromPath(inputName);
		entry.data = input;
		result.push_back(entry);
		return result;
	}
	
	if (memcmp(input.data(),"LIB\x01",4) != 0)
		return result;

	int pos = 4;
	while (pos < input.size())
	{
		PsxLibEntry entry;
		
		for (int i = 0; i < 16 && input[pos+i] != ' '; i++)
		{
			entry.name += input[pos+i];
		}

		int size = input.getDoubleWord(pos+16);
		int skip = 20;

		while (input[pos+skip] != 0)
		{
			skip += input[pos+skip++];
		}

		skip++;

		entry.data = input.mid(pos+skip,size-skip);
		pos += size;

		result.push_back(entry);
	}

	return result;
}
示例#8
0
int FileNative::write( const ByteArray& bArray )
{
    if( !isOpen() )
        return 0;

    return (int)fwrite( bArray.data(), 1, bArray.size(), _file );
}
	void testReadBytestream() {
		TestHelper helper;
		connection->onDataSent.connect(boost::bind(&TestHelper::handleConnectionDataWritten, &helper, _1));

		SOCKS5BytestreamClientSession::ref clientSession = boost::make_shared<SOCKS5BytestreamClientSession>(connection, destinationAddressPort, destination, timerFactory);
		clientSession->onSessionReady.connect(boost::bind(&TestHelper::handleSessionReady, &helper, _1));

		clientSession->start();
		eventLoop->processEvents();

		helper.unprocessedInput.clear();
		serverRespondHelloOK();
		eventLoop->processEvents();

		helper.unprocessedInput.clear();
		serverRespondRequestOK();
		eventLoop->processEvents();
		CPPUNIT_ASSERT_EQUAL(true, helper.sessionReadyCalled);
		CPPUNIT_ASSERT_EQUAL(false, helper.sessionReadyError);

		helper.unprocessedInput.clear();
		ByteArray transferData = generateRandomByteArray(1024);
		boost::shared_ptr<ByteArrayReadBytestream> input = boost::make_shared<ByteArrayReadBytestream>(transferData);
		clientSession->startSending(input);
		eventLoop->processEvents();

		CPPUNIT_ASSERT_EQUAL(createByteArray(transferData.data(), transferData.size()), helper.unprocessedInput);
	}
		size_t Send(const IObjectInputStreamPtr &inputStream)
		{
			size_t r = inputStream->Read(Buffer.data(), Buffer.size());
			//HexDump("write", ByteArray(Buffer.data(), Buffer.data() + r));
			KernelUrb.buffer_length = r;
			return r;
		}
	void Device::WriteControl(u8 type, u8 req, u16 value, u16 index, const ByteArray &data, bool interruptCurrentTransaction, int timeout)
	{
		usbdevfs_ctrltransfer ctrl = { };
		ctrl.bRequestType = type;
		ctrl.bRequest = req;
		ctrl.wValue = value;
		ctrl.wIndex = index;
		ctrl.wLength = data.size();
		ctrl.data = const_cast<u8 *>(data.data());
		ctrl.timeout = timeout;

		int fd = _fd.Get();

		_controls.push(
		[fd, ctrl, interruptCurrentTransaction]()
		{
			int r = ioctl(fd, USBDEVFS_CONTROL, &ctrl);
			if (r >= 0)
			{
				if (interruptCurrentTransaction)
					throw std::runtime_error("transaction aborted");
				else
					return;
			}
			else if (errno == EAGAIN)
				throw TimeoutException("timeout sending control transfer");
			else
				throw Exception("ioctl");
		});
	}
示例#12
0
/** @deprecated : use createGPUmodulefromfile
 */
CUmodule * CudaCompiler::compileFromFile(const String fileName, GPU * gpu)
{
    if(fileName == NULL) { return 0; }
    QFileInfo cu( fileName );
    if (! cu.isReadable()) { return 0; }
    else
    {
        /* Get filename */
        int result;
        String res;
        compileCUtoPTX( &fileName, result, &res );
        if(result != NVCC_OK ) {
            qDebug() << "Error during compilation from file " << fileName << " [" << result <<"]";
            return 0;
        }
        else {
            qDebug()<< " cu -> ptx ok";
        }
        String ptxfile = cu.baseName() + ".ptx";
        QFile file(ptxfile);
        QFileInfo ptx(ptxfile);
        if (ptx.isReadable()) {

            ByteArray * bar = ptxDump(&file);
            return compilePTX((uchar*) bar->data(), gpu);
            delete bar;
        }
    }
    return NULL;
}
示例#13
0
ByteArray ByteArray::fromFile(const std::wstring& fileName, int start, int size)
{
	ByteArray ret;
	
	FILE* input = openFile(fileName,OpenFileMode::ReadBinary);
	if (input == NULL)
		return ret;

	fseek(input,0,SEEK_END);
	int fileSize = ftell(input);

	if (start >= fileSize)
	{
		fclose(input);
		return ret;
	}

	if (size == -1 || start+size > fileSize)
		size = fileSize-start;

	fseek(input,start,SEEK_SET);

	ret.grow(size);
	ret.size_ = size;

	fread(ret.data(),1,size,input);
	fclose(input);

	return ret;
}
示例#14
0
/*
 * Class:     im_tox_tox4j_impl_ToxCoreJni
 * Method:    toxFriendSendLosslessPacket
 * Signature: (II[B)V
 */
TOX_METHOD (void, FriendSendLosslessPacket,
  jint instanceNumber, jint friendNumber, jbyteArray packet)
{
  ByteArray packetData (env, packet);
  return instances.with_instance_ign (env, instanceNumber,
    tox_friend_send_lossless_packet, friendNumber, packetData.data (), packetData.size ()
  );
}
		Urb(int fd, u8 type, const EndpointPtr & ep): Fd(fd), Buffer(PacketsPerBuffer(type) * ep->GetMaxPacketSize()), KernelUrb()
		{
			usbdevfs_urb &urb	= KernelUrb;
			urb.type			= type;
			urb.endpoint		= ep->GetAddress();
			urb.buffer			= Buffer.data();
			urb.buffer_length	= Buffer.size();
		}
示例#16
0
void VirtualKPA::saveRig(const VirtualRig& rig, const QString& rigName)
{
  ByteArray kiprBlob;
  rig.createKIPR(kiprBlob);
  QFile kiprFile(rigName);
  kiprFile.open(QIODevice::WriteOnly);
  QDataStream stream(&kiprFile);
  stream.writeRawData((char*)kiprBlob.data(), kiprBlob.size());
}
示例#17
0
/*
 * Class:     im_tox_tox4j_impl_jni_ToxCryptoImpl__
 * Method:    hash
 * Signature: ([B)[B
 */
JNIEXPORT jbyteArray JNICALL Java_im_tox_tox4j_impl_jni_ToxCryptoImpl_00024_hash
  (JNIEnv *env, jobject, jbyteArray dataArray)
{
  ByteArray data (env, dataArray);
  std::vector<uint8_t> hash (TOX_HASH_LENGTH);
  bool result = tox_hash (hash.data (), data.data (), data.size ());
  tox4j_assert (result);
  return toJavaArray (env, hash);
}
示例#18
0
int ByteArray::append(const ByteArray& other)
{
	int oldSize = size();
	int otherSize = other.size();
	grow(size()+otherSize);
	memcpy(&data_[size_],other.data(),otherSize);
	size_ += otherSize;
	return oldSize;
}
示例#19
0
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();
}
示例#20
0
ByteArray MemoryFile::read(unsigned int sizeToRead)
{
    ByteArray ret;
    ret.resize( sizeToRead );
    int bytesRead = read( ret.data(), sizeToRead );

    ret.resize( bytesRead );

    return ret;
}
示例#21
0
bool getFromByteArray(const ByteArray& byteArray, size_t startIndex,
		void* arrayData, size_t size)
{
	if (byteArray.size() < size + startIndex - 1)
		return false;

	memcpy((char*) arrayData, byteArray.data() + startIndex, size);

	return true;
}
示例#22
0
/*
 * Class:     im_tox_tox4j_impl_jni_ToxCoreJni
 * Method:    invokeFileRecv
 * Signature: (IIIIJ[B)V
 */
JNIEXPORT void JNICALL Java_im_tox_tox4j_impl_jni_ToxCoreJni_invokeFileRecv
  (JNIEnv *env, jclass, jint instanceNumber, jint friend_number, jint file_number, jint kind, jlong file_size, jbyteArray filename)
{
  return instances.with_instance (env, instanceNumber,
    [=] (Tox *tox, Events &events)
      {
        ByteArray filenameArray (env, filename);
        tox4j_file_recv_cb (tox, friend_number, file_number, kind, file_size, filenameArray.data (), filenameArray.size (), events);
      }
  );
}
示例#23
0
/*
 * Class:     im_tox_tox4j_impl_jni_ToxCoreJni
 * Method:    invokeFileRecvChunk
 * Signature: (IIIJ[B)V
 */
JNIEXPORT void JNICALL Java_im_tox_tox4j_impl_jni_ToxCoreJni_invokeFileRecvChunk
  (JNIEnv *env, jclass, jint instanceNumber, jint friend_number, jint file_number, jlong position, jbyteArray data)
{
  return instances.with_instance (env, instanceNumber,
    [=] (Tox *tox, Events &events)
      {
        ByteArray dataArray (env, data);
        tox4j_file_recv_chunk_cb (tox, friend_number, file_number, position, dataArray.data (), dataArray.size (), events);
      }
  );
}
示例#24
0
/*
 * Class:     im_tox_tox4j_impl_jni_ToxCoreJni
 * Method:    invokeFriendLossyPacket
 * Signature: (II[B)V
 */
JNIEXPORT void JNICALL Java_im_tox_tox4j_impl_jni_ToxCoreJni_invokeFriendLossyPacket
  (JNIEnv *env, jclass, jint instanceNumber, jint friend_number, jbyteArray data)
{
  return instances.with_instance (env, instanceNumber,
    [=] (Tox *tox, Events &events)
      {
        ByteArray dataArray (env, data);
        tox4j_friend_lossy_packet_cb (tox, friend_number, dataArray.data (), dataArray.size (), events);
      }
  );
}
示例#25
0
/*
 * Class:     im_tox_tox4j_impl_jni_ToxCoreJni
 * Method:    invokeFriendStatusMessage
 * Signature: (II[B)V
 */
JNIEXPORT void JNICALL Java_im_tox_tox4j_impl_jni_ToxCoreJni_invokeFriendStatusMessage
  (JNIEnv *env, jclass, jint instanceNumber, jint friend_number, jbyteArray message)
{
  return instances.with_instance (env, instanceNumber,
    [=] (Tox *tox, Events &events)
      {
        ByteArray messageArray (env, message);
        tox4j_friend_status_message_cb (tox, friend_number, messageArray.data (), messageArray.size (), events);
      }
  );
}
	void Device::ReadControl(IOUSBDeviceType **dev, u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout)
	{
		IOUSBDevRequest request = {};
		request.bmRequestType = type;
		request.bRequest = req;
		request.wValue = value;
		request.wIndex = index;
		request.pData = data.data();
		request.wLength = data.size();
		USB_CALL((*dev)->DeviceRequest(dev, &request));
		data.resize(request.wLenDone);
	}
示例#27
0
/*
 * Class:     im_tox_tox4j_impl_jni_ToxCoreJni
 * Method:    invokeFriendRequest
 * Signature: (I[BI[B)V
 */
JNIEXPORT void JNICALL Java_im_tox_tox4j_impl_jni_ToxCoreJni_invokeFriendRequest
  (JNIEnv *env, jclass, jint instanceNumber, jbyteArray public_key, jint time_delta, jbyteArray message)
{
  return instances.with_instance (env, instanceNumber,
    [=] (Tox *tox, Events &events)
      {
        ByteArray public_keyArray (env, public_key);
        ByteArray messageArray (env, message);
        tox4j_friend_request_cb (tox, public_keyArray.data (), /*time_delta, */ messageArray.data (), messageArray.size (), events);
      }
  );
}
示例#28
0
void TCPConnection::send(ByteArray message, std::chrono::milliseconds timeout) const {
    try {
        socket_->SendData((const int8_t*)message.data(), message.size(), static_cast<uint32_t>(timeout.count()));
    } catch (const IVDA::SocketConnectionException& err) {
        throw ConnectionClosedError("Connection to peer " + socket_->GetPeerAddress() + " lost during send operation (internal error: " +
                                        err.what() + ")",
                                    identifier(), __FILE__, __LINE__);
    } catch (const IVDA::SocketException& err) {
        std::string internalError = mocca::joinString(err.what(), ", ", err.internalError());
        throw NetworkError("Network error in send operation (internal error: " + internalError + ")", __FILE__, __LINE__);
    }
}
示例#29
0
void FECustomFilter::platformApplySoftware()
{
    ByteArray* dstPixelArray = createPremultipliedImageResult();
    if (!dstPixelArray)
        return;

    FilterEffect* in = inputEffect(0);
    IntRect effectDrawingRect = requestedRegionOfInputImageData(in->absolutePaintRect());
    RefPtr<ByteArray> srcPixelArray = in->asPremultipliedImage(effectDrawingRect);
    
    IntSize newContextSize(effectDrawingRect.size());
    bool hadContext = m_context;
    if (!m_context)
        initializeContext(newContextSize);
    
    if (!hadContext || m_contextSize != newContextSize)
        resizeContext(newContextSize);
    
    // Do not draw the filter if the input image cannot fit inside a single GPU texture.
    if (m_inputTexture->tiles().numTilesX() != 1 || m_inputTexture->tiles().numTilesY() != 1)
        return;
    
    // The shader had compiler errors. We cannot draw anything.
    if (!m_shader->isInitialized())
        return;
    
    m_context->clearColor(0, 0, 0, 0);
    m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT | GraphicsContext3D::DEPTH_BUFFER_BIT);
    
    bindProgramAndBuffers(srcPixelArray.get());
    
    m_context->drawElements(GraphicsContext3D::TRIANGLES, m_mesh->indicesCount(), GraphicsContext3D::UNSIGNED_SHORT, 0);
    
    m_drawingBuffer->commit();

    RefPtr<ImageData> imageData = m_context->paintRenderingResultsToImageData(m_drawingBuffer.get());
    ByteArray* gpuResult = imageData->data()->data();
    ASSERT(gpuResult->length() == dstPixelArray->length());
    memcpy(dstPixelArray->data(), gpuResult->data(), gpuResult->length());
}
示例#30
0
void CDirectiveIncbin::Encode()
{
	if (loadSize != 0)
	{
		ByteArray data = ByteArray::fromFile(fileName,startAddress,loadSize);
		if (data.size() == 0)
		{
			Logger::printError(Logger::Error,L"Could not read file \"%s\"",fileName);
			return;
		}
		g_fileManager->write(data.data(),data.size());
	}
}