本文整理汇总了C++中ofPixels::getPixelFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPixels::getPixelFormat方法的具体用法?C++ ofPixels::getPixelFormat怎么用?C++ ofPixels::getPixelFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPixels
的用法示例。
在下文中一共展示了ofPixels::getPixelFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: allocate
//----------------------------------------------------------
void ofTexture::allocate(const ofPixels& pix, bool bUseARBExtention){
allocate(pix.getWidth(), pix.getHeight(), ofGetGlInternalFormat(pix), bUseARBExtention, ofGetGlFormat(pix), ofGetGlType(pix));
if((pix.getPixelFormat()==OF_PIXELS_GRAY || pix.getPixelFormat()==OF_PIXELS_GRAY_ALPHA) && ofIsGLProgrammableRenderer()){
setRGToRGBASwizzles(true);
}
loadData(pix);
}
示例2: 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;
}
}
示例3: ofGetGlType
//---------------------------------
int ofGetGlType(const ofPixels & pixels) {
#ifndef TARGET_OPENGLES
if(pixels.getPixelFormat()==OF_PIXELS_RGB565){
return GL_UNSIGNED_SHORT_5_6_5;
}else{
#endif
return GL_UNSIGNED_BYTE;
#ifndef TARGET_OPENGLES
}
#endif
}
示例4: setData
//----------
void Message::setData(const ofPixels & data) {
const auto headerSize = sizeof(Header::Pixels);
const auto bodySize = data.size(); // inner payload
this->headerAndData.resize(headerSize + bodySize);
auto & header = this->getHeader<Header::Pixels>(true);
header.width = data.getWidth();
header.height = data.getHeight();
header.pixelFormat = data.getPixelFormat();
auto body = this->getBodyData();
memcpy(body, data.getData(), bodySize);
}
示例5: draw
//--------------------------------------------
void ofCairoRenderer::draw(const ofPixels & raw, float x, float y, float z, float w, float h, float sx, float sy, float sw, float sh) const{
bool shouldCrop = sx != 0 || sy != 0 || sw != w || sh != h;
ofPixels cropped;
if(shouldCrop) {
cropped.allocate(sw, sh, raw.getPixelFormat());
raw.cropTo(cropped, sx, sy, sw, sh);
}
const ofPixels & pix = shouldCrop ? cropped : raw;
ofCairoRenderer * mut_this = const_cast<ofCairoRenderer*>(this);
mut_this->pushMatrix();
mut_this->translate(x,y,z);
mut_this->scale(w/pix.getWidth(),h/pix.getHeight());
cairo_surface_t *image;
int stride=0;
int picsize = pix.getWidth()* pix.getHeight();
const unsigned char *imgPix = pix.getData();
vector<unsigned char> swapPixels;
switch(pix.getImageType()){
case OF_IMAGE_COLOR:
#ifdef TARGET_LITTLE_ENDIAN
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*3 +2];
swapPixels[p*4 +1] = imgPix[p*3 +1];
swapPixels[p*4 +2] = imgPix[p*3];
}
#else
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*3];
swapPixels[p*4 +1] = imgPix[p*3 +1];
swapPixels[p*4 +2] = imgPix[p*3 +2];
}
#endif
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_RGB24, pix.getWidth(), pix.getHeight(), stride);
break;
case OF_IMAGE_COLOR_ALPHA:
#ifdef TARGET_LITTLE_ENDIAN
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p*4+2];
swapPixels[p*4 +1] = imgPix[p*4+1];
swapPixels[p*4 +2] = imgPix[p*4];
swapPixels[p*4 +3] = imgPix[p*4+3];
}
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_ARGB32, pix.getWidth(), pix.getHeight(), stride);
#else
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32, pix.getWidth());
image = cairo_image_surface_create_for_data(pix.getData(), CAIRO_FORMAT_ARGB32, pix.getWidth(), pix.getHeight(), stride);
#endif
break;
case OF_IMAGE_GRAYSCALE:
swapPixels.resize(picsize * 4);
for(int p= 0; p<picsize; p++) {
swapPixels[p*4] = imgPix[p];
swapPixels[p*4 +1] = imgPix[p];
swapPixels[p*4 +2] = imgPix[p];
}
stride = cairo_format_stride_for_width (CAIRO_FORMAT_RGB24, pix.getWidth());
image = cairo_image_surface_create_for_data(&swapPixels[0], CAIRO_FORMAT_RGB24, pix.getWidth(), pix.getHeight(), stride);
break;
case OF_IMAGE_UNDEFINED:
default:
ofLogError("ofCairoRenderer") << "draw(): trying to draw undefined image type " << pix.getImageType();
mut_this->popMatrix();
return;
break;
}
cairo_set_source_surface (cr, image, 0,0);
cairo_paint (cr);
cairo_surface_flush(image);
cairo_surface_destroy (image);
mut_this->popMatrix();
}
示例6: ofGetGlInternalFormat
//---------------------------------
int ofGetGlInternalFormat(const ofPixels& pix) {
return ofGetGLInternalFormatFromPixelFormat(pix.getPixelFormat());
}