本文整理汇总了C++中ofPixels::cropTo方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPixels::cropTo方法的具体用法?C++ ofPixels::cropTo怎么用?C++ ofPixels::cropTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPixels
的用法示例。
在下文中一共展示了ofPixels::cropTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: setImage
//--------------------------------------------------------------
void FaceAugmented::setImage(const ofPixels & pixels) {
pixels.cropTo(image.getPixels(), roi.getX(), roi.getY(), roi.getWidth(), roi.getHeight());
image.update();
}