本文整理汇总了C++中ofBuffer::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ofBuffer::size方法的具体用法?C++ ofBuffer::size怎么用?C++ ofBuffer::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofBuffer
的用法示例。
在下文中一共展示了ofBuffer::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadModel
//-------------------------------------------
bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){
normalizeFactor = ofGetWidth() / 2.0;
// only ever give us triangles.
aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT );
aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true);
// aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why.
unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs;
if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph |
aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices |
aiProcess_RemoveRedundantMaterials;
if(scene){
clear();
}
scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension);
if(scene){
calculateDimensions();
loadGLResources();
if(getAnimationCount())
ofLog(OF_LOG_VERBOSE, "scene has animations");
else {
ofLog(OF_LOG_VERBOSE, "no animations");
}
return true;
}else{
ofLog(OF_LOG_ERROR,string("ofxAssimpModelLoader: ") + aiGetErrorString());
return false;
}
}
示例2: load
bool Scene::load(const ofBuffer& buffer, bool optimize, Handedness handness, const char* extension) {
unload();
unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality;
if (optimize) {
flags |= aiProcess_ImproveCacheLocality |
aiProcess_JoinIdenticalVertices |
aiProcess_RemoveRedundantMaterials;
}
if (handness == LEFT_HANDED) {
flags |= aiProcess_ConvertToLeftHanded;
}
scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(),
flags, extension);
string err_str = aiGetErrorString();
if (!err_str.empty())
{
ofLogError("ofxAssimp::Scene::load") << err_str;
}
assert(scene);
setupResources();
setupNodes();
setupAnimations();
return true;
}
示例3: string
string ofxCrypto::base64_encode(ofBuffer &buffer) {
long max = buffer.size();
char *buf = buffer.getBinaryBuffer();
string str = string(buf,max);
return base64_encode(str);
}
示例4: load
bool ofxTurboJpeg::load(const ofBuffer& buf, ofPixels &pix)
{
int w, h;
int subsamp;
int ok = tjDecompressHeader2(handleDecompress, (unsigned char*)buf.getData(), buf.size(), &w, &h, &subsamp);
if (ok != 0)
{
printf("Error in tjDecompressHeader2():\n%s\n", tjGetErrorStr());
return false;
}
pix.allocate(w, h, 3);
tjDecompress(handleDecompress, (unsigned char*)buf.getData(), buf.size(), pix.getData(), w, 0, h, 3, 0);
return true;
}
示例5: loadImageFromMemory
//----------------------------------------------------
bool ofImage::loadImageFromMemory(const ofBuffer & buffer, ofPixels &pix){
int width, height, bpp;
bool bLoaded = false;
FIBITMAP * bmp = NULL;
FIMEMORY *hmem = NULL;
printf("loadImageFromMemory\n");
hmem = FreeImage_OpenMemory((unsigned char*)buffer.getBuffer(), buffer.size());
if (hmem == NULL){
ofLog(OF_LOG_ERROR,"couldn't create memory handle! \n");
return false;
}
//get the file type!
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);
if( fif == -1 ){
ofLog(OF_LOG_ERROR,"unable to guess format", fif);
return false;
FreeImage_CloseMemory(hmem);
}
//make the image!!
bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
if( bmp != NULL ){
bLoaded = true;
ofLog(OF_LOG_VERBOSE,"FreeImage_LoadFromMemory worked!\n");
}
//-----------------------------
if (bLoaded){
putBmpIntoPixels(bmp,pix);
} else {
width = height = bpp = 0;
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
if( hmem != NULL ){
FreeImage_CloseMemory(hmem);
}
return bLoaded;
}
示例6: loadImage
static bool loadImage(ofPixels_<PixelType> & pix, const ofBuffer & buffer, const ofImageLoadSettings &settings){
ofInitFreeImage();
bool bLoaded = false;
FIBITMAP* bmp = nullptr;
FIMEMORY* hmem = nullptr;
hmem = FreeImage_OpenMemory((unsigned char*) buffer.getData(), buffer.size());
if (hmem == nullptr){
ofLogError("ofImage") << "loadImage(): couldn't load image from ofBuffer, opening FreeImage memory failed";
return false;
}
//get the file type!
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);
if( fif == -1 ){
ofLogError("ofImage") << "loadImage(): couldn't load image from ofBuffer, unable to guess image format from memory";
FreeImage_CloseMemory(hmem);
return false;
}
//make the image!!
if(fif == FIF_JPEG) {
int option = getJpegOptionFromImageLoadSetting(settings);
bmp = FreeImage_LoadFromMemory(fif, hmem, option);
} else {
bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
}
if( bmp != nullptr ){
bLoaded = true;
}
//-----------------------------
if (bLoaded){
putBmpIntoPixels(bmp,pix);
}
if (bmp != nullptr){
FreeImage_Unload(bmp);
}
if( hmem != nullptr ){
FreeImage_CloseMemory(hmem);
}
return bLoaded;
}
示例7: loadImage
static bool loadImage(ofPixels_<PixelType> & pix, const ofBuffer & buffer){
ofInitFreeImage();
bool bLoaded = false;
FIBITMAP* bmp = NULL;
FIMEMORY* hmem = NULL;
hmem = FreeImage_OpenMemory((unsigned char*) buffer.getBinaryBuffer(), buffer.size());
if (hmem == NULL){
ofLog(OF_LOG_ERROR, "couldn't create memory handle!");
return false;
}
//get the file type!
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);
if( fif == -1 ){
ofLog(OF_LOG_ERROR, "unable to guess format", fif);
return false;
FreeImage_CloseMemory(hmem);
}
//make the image!!
bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
if( bmp != NULL ){
bLoaded = true;
}
//-----------------------------
if (bLoaded){
putBmpIntoPixels(bmp,pix);
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
if( hmem != NULL ){
FreeImage_CloseMemory(hmem);
}
return bLoaded;
}
示例8: loadImage
static bool loadImage(ofPixels_<PixelType> & pix, const ofBuffer & buffer){
ofInitFreeImage();
bool bLoaded = false;
FIBITMAP* bmp = NULL;
FIMEMORY* hmem = NULL;
hmem = FreeImage_OpenMemory((unsigned char*) buffer.getBinaryBuffer(), buffer.size());
if (hmem == NULL){
ofLogError("ofImage") << "loadImage(): couldn't load image from ofBuffer, opening FreeImage memory failed";
return false;
}
//get the file type!
FREE_IMAGE_FORMAT fif = FreeImage_GetFileTypeFromMemory(hmem);
if( fif == -1 ){
ofLogError("ofImage") << "loadImage(): couldn't load image from ofBuffer, unable to guess image format from memory";
return false;
FreeImage_CloseMemory(hmem);
}
//make the image!!
bmp = FreeImage_LoadFromMemory(fif, hmem, 0);
if( bmp != NULL ){
bLoaded = true;
}
//-----------------------------
if (bLoaded){
putBmpIntoPixels(bmp,pix);
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
if( hmem != NULL ){
FreeImage_CloseMemory(hmem);
}
return bLoaded;
}
示例9: loadModel
//-------------------------------------------
bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){
normalizeFactor = ofGetWidth() / 2.0;
if(scene != NULL){
clear();
}
// only ever give us triangles.
aiSetImportPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE | aiPrimitiveType_POINT );
aiSetImportPropertyInteger(AI_CONFIG_PP_PTV_NORMALIZE, true);
// aiProcess_FlipUVs is for VAR code. Not needed otherwise. Not sure why.
unsigned int flags = aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_Triangulate | aiProcess_FlipUVs;
if(optimize) flags |= aiProcess_ImproveCacheLocality | aiProcess_OptimizeGraph |
aiProcess_OptimizeMeshes | aiProcess_JoinIdenticalVertices |
aiProcess_RemoveRedundantMaterials;
scene = aiImportFileFromMemory(buffer.getBinaryBuffer(), buffer.size(), flags, extension);
if(scene){
calculateDimensions();
loadGLResources();
update();
if(getAnimationCount())
ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): scene has " << getAnimationCount() << "animations";
else {
ofLogVerbose("ofxAssimpModelLoader") << "loadMode(): no animations";
}
ofAddListener(ofEvents().exit,this,&ofxAssimpModelLoader::onAppExit);
return true;
}else{
ofLogError("ofxAssimpModelLoader") << "loadModel(): " + (string) aiGetErrorString();
clear();
return false;
}
}
示例10: sendBinary
//--------------------------------------------------------------
void Server::sendBinary( ofBuffer buffer ){
sendBinary(buffer.getBinaryBuffer(), buffer.size());
}
示例11: postData
// ----------------------------------------------------------------------
ofxHttpResponse ofxHttpUtils::postData(string url, const ofBuffer & data, string contentType){
ofxHttpResponse response;
try{
URI uri( url.c_str() );
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
//HTTPClientSession session(uri.getHost(), uri.getPort());
HTTPRequest req(HTTPRequest::HTTP_POST, path, HTTPMessage::HTTP_1_1);
if(auth.getUsername()!="") auth.authenticate(req);
if(sendCookies){
for(unsigned i=0; i<cookies.size(); i++){
NameValueCollection reqCookies;
reqCookies.add(cookies[i].getName(),cookies[i].getValue());
req.setCookies(reqCookies);
}
}
if(contentType!=""){
req.setContentType(contentType);
}
req.setContentLength(data.size());
HTTPResponse res;
ofPtr<HTTPSession> session;
istream * rs;
if(uri.getScheme()=="https"){
HTTPSClientSession * httpsSession = new HTTPSClientSession(uri.getHost(), uri.getPort());//,context);
httpsSession->setTimeout(Poco::Timespan(20,0));
httpsSession->sendRequest(req) << data;
rs = &httpsSession->receiveResponse(res);
session = ofPtr<HTTPSession>(httpsSession);
}else{
HTTPClientSession * httpSession = new HTTPClientSession(uri.getHost(), uri.getPort());
httpSession->setTimeout(Poco::Timespan(20,0));
httpSession->sendRequest(req) << data;
rs = &httpSession->receiveResponse(res);
session = ofPtr<HTTPSession>(httpSession);
}
response = ofxHttpResponse(res, *rs, url);
if(sendCookies){
cookies.insert(cookies.begin(),response.cookies.begin(),response.cookies.end());
}
if(response.status>=300 && response.status<400){
Poco::URI uri(req.getURI());
uri.resolve(res.get("Location"));
response.location = uri.toString();
}
ofNotifyEvent(newResponseEvent, response, this);
}catch (Exception& exc){
ofLogError("ofxHttpUtils") << "ofxHttpUtils error postData --";
//ofNotifyEvent(notifyNewError, "time out", this);
// for now print error, need to broadcast a response
ofLogError("ofxHttpUtils") << exc.displayText();
response.status = -1;
response.reasonForStatus = exc.displayText();
ofNotifyEvent(newResponseEvent, response, this);
}
return response;
}
示例12: load
vector<Mesh*> Loader::load(const ofBuffer &buffer)
{
return load(buffer.getData(), buffer.size());
}
示例13: decode
void ramTSVCoder::decode(ofBuffer buffer)
{
if (buffer.size())
{
clear();
do
{
string frame = buffer.getNextLine();
vector<string> values = ofSplitString(frame, "\t");
if (values.size() < 2)
throw std::exception();
const string addr = values.at(0);
const string name = values.at(1);
ramNodeArray NA;
if (addr == RAM_OSC_ADDR_ACTOR)
{
ramActor o;
o.setType(RAM_NODEARRAY_TYPE_ACTOR);
o.setName(name);
NA = o;
}
else
{
ramRigidBody o;
o.setType(RAM_NODEARRAY_TYPE_RIGIDBODY);
o.setName(name);
NA = o;
}
const int numNodes = ofToInt(values.at(2));
for (int i=0; i<numNodes; i++)
{
if (values.size() < i*8+3+7)
throw std::exception();
const string nodeName = values.at(i*8 + 0 + 3);
const float vx = ofToFloat( values.at(i*8 + 1 + 3) );
const float vy = ofToFloat( values.at(i*8 + 2 + 3) );
const float vz = ofToFloat( values.at(i*8 + 3 + 3) );
const float qa = ofToFloat( values.at(i*8 + 4 + 3) );
const float ax = ofToFloat( values.at(i*8 + 5 + 3) );
const float ay = ofToFloat( values.at(i*8 + 6 + 3) );
const float az = ofToFloat( values.at(i*8 + 7 + 3) );
const ofVec3f vec(vx, vy, vz);
const ofVec3f axis(ax, ay, az);
const ofQuaternion quat(qa, axis);
ramNode &node = NA.getNode(i);
node.setID(i);
node.setName(nodeName);
node.setPosition(vec);
node.setOrientation(quat);
node.getAccelerometer().update(vec, quat);
}
NA.setTimestamp(ofToFloat( values.at(numNodes*8 + 0 + 3) ));
mSession.appendFrame(NA);
} while (!buffer.isLastLine());
// cout << "[" << __FUNCTION__ << "] " << "File loaded! " << endl;
// cout << "[" << __FUNCTION__ << "] " << "Actor: " << mSession.getNodeArrayName() << endl;
// cout << "[" << __FUNCTION__ << "] " << "Duration: " << mSession.getDuration() << "sec"<< endl;
// cout << "[" << __FUNCTION__ << "] " << "Frames: " << mSession.getNumFrames() << endl << endl;
}
// return mSession;
}
示例14: writeBytes
//----------------------------------------------------------------
long ofSerial::writeBytes(const ofBuffer & buffer){
return writeBytes(buffer.getData(),buffer.size());
}
示例15: loadModel
bool ofxAssimpModelLoader::loadModel(ofBuffer & buffer, bool optimize, const char * extension){
ofLogVerbose("ofxAssimpModelLoader") << "loadModel(): loading from memory buffer \"." << extension << "\"";
if(scene != NULL){
clear();
}
// sets various properties & flags to a default preference
unsigned int flags = initImportProperties(optimize);
// loads scene from memory buffer - note this will not work for multipart files (obj, md3, etc)
scene = shared_ptr<const aiScene>(aiImportFileFromMemoryWithProperties(buffer.getBinaryBuffer(), buffer.size(), flags, extension, store.get()), aiReleaseImport);
bool bOk = processScene();
return bOk;
}