本文整理汇总了C++中ofPixels::allocate方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPixels::allocate方法的具体用法?C++ ofPixels::allocate怎么用?C++ ofPixels::allocate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPixels
的用法示例。
在下文中一共展示了ofPixels::allocate方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getData
//----------
bool Message::getData(ofPixels & data) const {
auto & header = this->getHeader<Header::Pixels>();
if (this->hasHeader<Header::Pixels>()) {
const auto & header = this->getHeader<Header::Pixels>();
auto bodySize = this->getBodySize();
ofPixelFormat pixelFormat = (ofPixelFormat)header.pixelFormat;
//reallocate if we need to
if (data.getWidth() != header.width || data.getHeight() != header.height || data.getPixelFormat() != pixelFormat) {
data.allocate(header.width, header.height, pixelFormat);
}
if (data.size() != bodySize) {
OFXSQUASHBUDDIES_ERROR << "Message body is of wrong size to fill pixels. Maybe a bug in sender?";
return false;
}
else {
memcpy(data.getData(), this->getBodyData(), bodySize);
return true;
}
}
else {
OFXSQUASHBUDDIES_WARNING << "Message Header doesn't match Pixels type";
return false;
}
}
示例2: readToPixels
//----------------------------------------------------------
void ofTexture::readToPixels(ofPixels & pixels){
#ifndef TARGET_OPENGLES
pixels.allocate(texData.width,texData.height,ofGetImageTypeFromGLType(texData.glTypeInternal));
bind();
glGetTexImage(texData.textureTarget,0,ofGetGlFormat(pixels),GL_UNSIGNED_BYTE, pixels.getPixels());
unbind();
#endif
}
示例3: readToPixels
//----------------------------------------------------------
void ofTexture::readToPixels(ofPixels & pixels) const {
#ifndef TARGET_OPENGLES
pixels.allocate(texData.width,texData.height,ofGetImageTypeFromGLType(texData.glInternalFormat));
ofSetPixelStoreiAlignment(GL_PACK_ALIGNMENT,pixels.getWidth(),pixels.getBytesPerChannel(),pixels.getNumChannels());
glBindTexture(texData.textureTarget,texData.textureID);
glGetTexImage(texData.textureTarget,0,ofGetGlFormat(pixels),GL_UNSIGNED_BYTE, pixels.getData());
glBindTexture(texData.textureTarget,0);
#endif
}
示例4: readToPixels
//----------------------------------------------------------
void ofFbo::readToPixels(ofPixels & pixels, int attachmentPoint) const{
if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
getTexture(attachmentPoint).readToPixels(pixels);
#else
pixels.allocate(settings.width,settings.height,ofGetImageTypeFromGLType(settings.internalformat));
bind();
int format = ofGetGLFormatFromInternal(settings.internalformat);
glReadPixels(0,0,settings.width, settings.height, format, GL_UNSIGNED_BYTE, pixels.getData());
unbind();
#endif
}
示例5: alterColorRGB
ofPixels ofxImageTS::alterColorRGB(ofPixels pixels,float R, float G, float B){
pixels.allocate(pixels.getWidth(), pixels.getHeight(), OF_PIXELS_RGB);
ofPixels copy;
copy = pixels;
for(int i = 0; i < pixels.size()-3; i += 3){
copy[i] = R * pixels[i];
copy[i+1] = G * pixels[i+1];
copy[i+2] = B * pixels[i+2];
}
return copy;
}
示例6: invertRB
ofPixels ofxImageTS::invertRB(ofPixels pixels){
pixels.allocate(pixels.getWidth(), pixels.getHeight(), OF_PIXELS_RGBA);
ofPixels copy;
copy = pixels;
for(int i = 0; i < pixels.size()-3; i += 4){
copy[i] = pixels[i+2];
copy[i+1] = pixels[i+1];
copy[i+2] = pixels[i];
copy[i+3] = pixels[i+3];
}
return copy;
}
示例7: 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;
}
示例8: prepareBitmapTexture
//---------------------------------------------------------------------
static void prepareBitmapTexture(){
if (!bBitmapTexturePrepared){
myLetterPixels.allocate(16*16, 16*16, 4); // letter size:8x14pixels, texture size:16x8letters, gl_rgba: 4bytes/1pixel
myLetterPixels.set(0);
bitmappedFontTexture.allocate(16*16, 16*16, GL_RGBA, false);
bBitmapTexturePrepared = true;
for (int i = 0; i < 256; i++) {
const unsigned char * face = bmpChar_8x13_Map[i];
for (int j = 1; j < 15; j++){
for (int k = 0; k < 8; k++){
if ( ((face[15-j] << k) & (128)) > 0 ){
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4] = 255;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+1] = 255;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+2] = 255;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+3] = 255;
}else{
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4] = 0;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+1] = 0;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+2] = 0;
myLetterPixels[(((int)(i/16))*16*16*16+(i%16)*16 + (j-1)*16*16 + k)*4+3] = 0;
}
}
}
}
bitmappedFontTexture.loadData(myLetterPixels);
bitmappedFontTexture.setTextureMinMagFilter(GL_LINEAR,GL_NEAREST);
charMesh.setMode(OF_PRIMITIVE_TRIANGLES);
}
}
示例9: putBmpIntoPixels
//----------------------------------------------------
void putBmpIntoPixels(FIBITMAP * bmp, ofPixels &pix, bool swapForLittleEndian = true){
int width = FreeImage_GetWidth(bmp);
int height = FreeImage_GetHeight(bmp);
int bpp = FreeImage_GetBPP(bmp);
FIBITMAP * bmpTemp = NULL;
switch (bpp){
case 8:
if (FreeImage_GetColorType(bmp) == FIC_PALETTE) {
bmpTemp = FreeImage_ConvertTo24Bits(bmp);
bmp = bmpTemp;
bpp = FreeImage_GetBPP(bmp);
} else {
// do nothing we are grayscale
}
break;
case 24:
// do nothing we are color
break;
case 32:
// do nothing we are colorAlpha
break;
default:
bmpTemp = FreeImage_ConvertTo24Bits(bmp);
bmp = bmpTemp;
bpp = FreeImage_GetBPP(bmp);
break;
}
int bytesPerPixel = bpp / 8;
pix.allocate(width, height, bpp);
FreeImage_ConvertToRawBits(pix.getPixels(), bmp, width*bytesPerPixel, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true); // get bits
if (bmpTemp != NULL) FreeImage_Unload(bmpTemp);
#ifdef TARGET_LITTLE_ENDIAN
if(swapForLittleEndian)
pix.swapRgb();
#endif
}
示例10: toPixels
// get pixels from a fbo or texture // untested
void ftUtil::toPixels(ofTexture& _tex, ofPixels& _pixels) {
ofTextureData& texData = _tex.getTextureData();
int format = texData.glInternalFormat;
int readFormat, numChannels;
switch(format){
case GL_R8: readFormat = GL_RED, numChannels = 1; break; // or is it GL_R
case GL_RG8: readFormat = GL_RG, numChannels = 2; break;
case GL_RGB8: readFormat = GL_RGB, numChannels = 3; break;
case GL_RGBA8: readFormat = GL_RGBA, numChannels = 4; break;
default:
ofLogWarning("ftUtil") << "toPixels: " << "can only read char texturs to ofPixels";
return;
}
if (_pixels.getWidth() != texData.width || _pixels.getHeight() != texData.height || _pixels.getNumChannels() != numChannels) {
_pixels.allocate(texData.width, texData.height, numChannels);
}
ofSetPixelStoreiAlignment(GL_PACK_ALIGNMENT, texData.width, 1, numChannels);
glBindTexture(texData.textureTarget, texData.textureID);
glGetTexImage(texData.textureTarget, 0, readFormat, GL_UNSIGNED_BYTE, _pixels.getData());
glBindTexture(texData.textureTarget, 0);
}
示例11: setup
// Set up our sketch.
void setup()
{
ofSetWindowShape(1280, 720); // Set the window size.
grabber.initGrabber(1280, 720); // Set the grabber size.
pixels.allocate(1280, 720, OF_PIXELS_RGB); // Allocate memory for our pixels.
}