本文整理汇总了C++中ofTexture::readToPixels方法的典型用法代码示例。如果您正苦于以下问题:C++ ofTexture::readToPixels方法的具体用法?C++ ofTexture::readToPixels怎么用?C++ ofTexture::readToPixels使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofTexture
的用法示例。
在下文中一共展示了ofTexture::readToPixels方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: publishTexture
void Output::publishTexture(ofTexture &tex)
{
assert(mutex);
if (tex.getWidth() == uiFrameWidth
&& tex.getHeight() == uiFrameHeight)
{
ofPixels pix2;
tex.readToPixels(pix2);
mutex->lock();
if (!back_buffer->isAllocated() ||
back_buffer->getWidth() != tex.getWidth() ||
back_buffer->getHeight() != tex.getHeight()) {
back_buffer->allocate(tex.getWidth(), tex.getHeight(), pix2.getNumChannels());
}
memcpy(&back_buffer->getData()[1], pix2.getData(), pix2.size() - 1);
if (back_buffer->getNumChannels() != 4)
back_buffer->setNumChannels(4);
has_new_frame = true;
mutex->unlock();
}
else
ofLogError("ofxDeckLinkAPI::Output") << "invalid texture size";
}
示例2: preprocess
//--------------------------------------------------------------
void testApp::preprocess(ofTexture &_text){
grayscale.setTexture( _text );
grayscale.update();
blur << grayscale;
blur.update();
normals << blur;
normals.update();
ofPixels normPixels;
normPixels.allocate(normals.getWidth(), normals.getHeight(), 4);
normals.getTextureReference().readToPixels(normPixels);
_text.readToPixels(pixels);
int scaledWidth = width/scale;
int scaledHeight = height/scale;
for(int x = 0; x <= scaledWidth; x++){
for(int y = 0; y <= scaledHeight; y++){
int scaledX = ofClamp(x*scale,0,width-1);
int scaledY = ofClamp(y*scale,0,height-1);
ofFloatColor normalColor = normPixels.getColor(scaledX, scaledY);
int index = x + y * scaledWidth;
ofPoint norm = ofPoint((normalColor.r - 0.5) * 2.0,
(normalColor.g - 0.5) * 2.0, 0.0);
float pct = 0.5;
VF[index] = VF[index]*(1.0-pct) + norm * pct;
}
}
}
示例3: updateOpticalFlow
void FluidKinect::updateOpticalFlow(ofTexture & maskedKinect)
{
maskedKinect.readToPixels(maskPixels);
blurImage.setFromPixels(maskPixels);
blurImage.resize(opFlow.sizeSml.width, opFlow.sizeSml.height);
blurImage.flagImageChanged();
opFlow.update(blurImage);
}
示例4: generateFromTexture
void CloudsVisualSystemMemory::generateFromTexture(ofTexture &_tex){
ofPixels pixels;
_tex.readToPixels(pixels);
int xMargin = 20;
int yMargin = 20;
int width = ofGetWidth()-xMargin*2.0;
int height = ofGetHeight()-yMargin*2.0;
ofRectangle block;
block.width = blockWidth*blockScale;
block.height = blockHeight*blockScale;
xBlocks = (float)width/((blockWidth+margin)*blockScale);
yBlocks = (float)height/((blockHeight+margin)*blockScale);
blocks.clear();
for (int j = 0; j < yBlocks; j++) {
for (int i = 0; i < xBlocks; i++){
int x = xMargin + ((margin + blockWidth)*blockScale)*i ;
int y = yMargin + ((margin + blockHeight)*blockScale)*j ;
Block newBlock;
newBlock.set(block);
newBlock.x = x+block.width*0.5;
newBlock.y = y+block.height*0.5;
ofPoint st = ofPoint( ((float)i)/((float)xBlocks), ((float)j)/((float)yBlocks));
st *= ofPoint(_tex.getWidth(),_tex.getHeight());
newBlock.value = pixels.getColor( st.x, st.y ).r;//.getBrightness() ;
newBlock.color = ofColor( newBlock.value );
newBlock.borderColor = borderColor;
newBlock.bSelected = false;
blocks.push_back(newBlock);
}
}
}
示例5: pickColorFrom
void Brush::pickColorFrom(ofTexture &_tex, float _lerpAmount, float _randAmount){
ofRectangle palleteArea(0,0,_tex.getWidth(),_tex.getHeight());
ofFloatPixels pixels;
pixels.allocate(_tex.getWidth(), _tex.getHeight(), OF_IMAGE_COLOR_ALPHA);
_tex.readToPixels(pixels);
for(int i = 0; i < Bs.size(); i++){
if ( palleteArea.inside( *Bs[i] ) ){
ofFloatColor color = pixels.getColor(Bs[i]->x, Bs[i]->y);
Bs[i]->color.lerp(color, _lerpAmount * color.a);
Bs[i]->color.setHue( Bs[i]->color.getHue() + ofRandom(-_randAmount,_randAmount) );
colors[i].set(Bs[i]->color);
colors[i].a = 1.0;
}
}
}
示例6: endFrame
bool fboRecorder::endFrame(bool _showBuffer){
if(!isRecording()) return false;
if(!useGrabScreen){
if(!bFrameStarted) return false;
fbo.end();
//fbo.getTexture().getTextureData().bFlipTexture = false;
bFrameStarted=false;
}
static ofTexture tmpTex;
int w = ofGetWidth();
int h = ofGetHeight();
if(!tmpTex.isAllocated()){
tmpTex.allocate( w, h, GL_RGBA );
}
switch(fboRecMode){
case VIDEOREC_MODE_FILE_H264 :
case VIDEOREC_MODE_FILE_PNG : {
ofPixels pix;
pix.allocate(fbo.getWidth(),fbo.getHeight(), ofGetImageTypeFromGLType(GL_RGB));
if(useGrabScreen){
tmpTex.loadScreenData(0, 0, w, h);
tmpTex.readToPixels(pix);
}
else {
fbo.readToPixels(pix);
}
ofxVideoRecorder::addFrame(pix);
break;
}
#ifdef KM_ENABLE_SYPHON
case VIDEOREC_MODE_SYPHON: {
//fbo.updateTexture( fbo.getTexture().texData.textureID );
if( useGrabScreen ){
//syphonServer.publishScreen();
tmpTex.loadScreenData(0, 0, ofGetWidth(), ofGetHeight());
//tmpTex = fbo.getTexture();
syphonServer.publishTexture( &tmpTex );
}
else {
//tmpTex = fbo.getTexture();
syphonServer.publishTexture( &fbo.getTexture() );
}
break;
}
#endif
default:
return false;
break;
}
// flush
tmpTex.clear();
if(_showBuffer){
if(!useGrabScreen){
#ifdef KM_ENABLE_SYPHON
if( fboRecMode==VIDEOREC_MODE_SYPHON ){
#else
if(false){
#endif
fbo.draw(0, 0, fbo.getWidth(), fbo.getHeight()); // show recorded image
}
else {
fbo.draw(0, fbo.getHeight(),fbo.getWidth(), -fbo.getHeight()); // show recorded image
}
}
}
return true;
}
// LISTENERS
void fboRecorder::beforeDraw( karmaControllerDrawEventArgs& _args ){
beginFrame();
}
void fboRecorder::afterDraw( karmaControllerDrawEventArgs& _args ){
endFrame(videoRecShowOutput);
}
示例7: generateFromTexture
void CloudsVisualSystemMemory::generateFromTexture(ofTexture &_tex){
ofPixels pixels;
_tex.readToPixels(pixels);
int xMargin = 0;
int yMargin = 0;
//MA: changed ofGetWidth() to getCanvasWidth() and ofGetHeight() to getCanvasHeight()
int width = getCanvasWidth()-xMargin*2.0;
int height = getCanvasHeight()-yMargin*2.0;
ofRectangle block;
block.width = blockWidth*blockScale;
block.height = blockHeight*blockScale;
xBlocks = (float)width/((blockWidth+margin)*blockScale);
yBlocks = (float)height/((blockHeight+margin)*blockScale);
outlineMesh.clear();
outlineMesh.setMode(OF_PRIMITIVE_LINES);
outlineMesh.setUsage(GL_STREAM_DRAW);
fillMesh.clear();
fillMesh.setMode(OF_PRIMITIVE_TRIANGLES);
outlineMesh.setUsage(GL_STATIC_DRAW);
blocks.clear();
for (int j = 0; j < yBlocks; j++) {
for (int i = 0; i < xBlocks; i++){
int x = xMargin + ((margin + blockWidth)*blockScale)*i ;
int y = xMargin + ((margin + blockHeight)*blockScale)*j ;
Block newBlock;
newBlock.set(block);
newBlock.x = x+block.width*0.5;
newBlock.y = y+block.height*0.5;
ofPoint st = ofPoint( ((float)i)/((float)xBlocks), ((float)j)/((float)yBlocks));
st *= ofPoint(_tex.getWidth(),_tex.getHeight());
newBlock.value = pixels.getColor( st.x, st.y ).getBrightness();
// newBlock.color = ofColor( newBlock.value)/brightnessOffset;
if(baseColorRange.min == baseColorRange.max){
newBlock.color = ofFloatColor(baseColorRange.min);
}
else{
newBlock.color = ofFloatColor(ofMap(newBlock.value, 0, 255,
baseColorRange.min,baseColorRange.max), 1.0);
}
newBlock.borderBase = borderBase;
newBlock.borderColor = borderColor;
newBlock.bSelected = false;
newBlock.outlineMesh = &outlineMesh;
newBlock.fillMesh = &fillMesh;
newBlock.setup();
blocks.push_back(newBlock);
}
}
}