本文整理汇总了C++中ofPixels::isAllocated方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPixels::isAllocated方法的具体用法?C++ ofPixels::isAllocated怎么用?C++ ofPixels::isAllocated使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPixels
的用法示例。
在下文中一共展示了ofPixels::isAllocated方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
ofPixels::ofPixels(const ofPixels & mom){
bAllocated = false;
pixels = NULL;
if(mom.isAllocated()){
allocate(mom.getWidth(),mom.getHeight(),mom.getImageType());
memcpy(pixels,mom.getPixels(),mom.getWidth()*mom.getHeight()*mom.getBytesPerPixel());
}
}
示例2: saveImageFromPixels
//----------------------------------------------------------------
void ofImage::saveImageFromPixels(string fileName, ofPixels &pix){
if (pix.isAllocated() == false){
ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
return;
}
#ifdef TARGET_LITTLE_ENDIAN
pix.swapRgb();
#endif
FIBITMAP * bmp = getBmpFromPixels(pix);
#ifdef TARGET_LITTLE_ENDIAN
pix.swapRgb();
#endif
fileName = ofToDataPath(fileName);
if (pix.isAllocated()){
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
fif = FreeImage_GetFileType(fileName.c_str(), 0);
if(fif == FIF_UNKNOWN) {
// or guess via filename
fif = FreeImage_GetFIFFromFilename(fileName.c_str());
}
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
if((FREE_IMAGE_FORMAT)fif != FIF_JPEG)
FreeImage_Save(fif, bmp, fileName.c_str());
else
FreeImage_Save(fif, bmp, fileName.c_str(),JPEG_QUALITYSUPERB);
}
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
}
示例3: ofSaveImage
//----------------------------------------------------------------
void ofSaveImage(ofPixels & pix, string fileName, ofImageQualityType qualityLevel) {
if (pix.isAllocated() == false){
ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
return;
}
#ifdef TARGET_LITTLE_ENDIAN
pix.swapRgb();
#endif
FIBITMAP * bmp = getBmpFromPixels(pix);
#ifdef TARGET_LITTLE_ENDIAN
pix.swapRgb();
#endif
fileName = ofToDataPath(fileName);
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
fif = FreeImage_GetFileType(fileName.c_str(), 0);
if(fif == FIF_UNKNOWN) {
// or guess via filename
fif = FreeImage_GetFIFFromFilename(fileName.c_str());
}
if((fif != FIF_UNKNOWN) && FreeImage_FIFSupportsReading(fif)) {
if(fif == FIF_JPEG) {
int quality = JPEG_QUALITYSUPERB;
switch(qualityLevel) {
case OF_IMAGE_QUALITY_WORST: quality = JPEG_QUALITYBAD; break;
case OF_IMAGE_QUALITY_LOW: quality = JPEG_QUALITYAVERAGE; break;
case OF_IMAGE_QUALITY_MEDIUM: quality = JPEG_QUALITYNORMAL; break;
case OF_IMAGE_QUALITY_HIGH: quality = JPEG_QUALITYGOOD; break;
case OF_IMAGE_QUALITY_BEST: quality = JPEG_QUALITYSUPERB; break;
}
FreeImage_Save(fif, bmp, fileName.c_str(), quality);
} else {
if(qualityLevel != OF_IMAGE_QUALITY_BEST) {
ofLog(OF_LOG_WARNING, "ofImageCompressionType only applies to JPEG images, ignoring value.");
}
FreeImage_Save(fif, bmp, fileName.c_str());
}
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
}
示例4: critical
//----------
void Decoder::operator<<(const ofPixels& pixels) {
if (frame == 0) {
data.allocate(pixels.getWidth(), pixels.getHeight(), payload->getWidth(), payload->getHeight());
}
if (frame > payload->getFrameCount() - 1) {
#pragma omp critical(ofLog)
ofLogWarning("ofxGraycode") << "Can't add more frames, we've already captured a full set. please clear()";
return;
}
if (!pixels.isAllocated()) {
ofLogError("ofxGraycode") << "Cannot add this capture as the pixels object is empty";
return;
}
const ofPixels* greyPixels;
if (pixels.getNumChannels() > 1) {
ofPixels* downsample = new ofPixels();
downsample->allocate(pixels.getWidth(), pixels.getHeight(), OF_PIXELS_MONO);
downsample->set(0, 0);
const uint8_t* in = pixels.getData();
uint8_t* out = downsample->getData();
for (int i = 0; i < pixels.size(); i++, out += (i % pixels.getNumChannels() == 0)) {
*out += *in++ / pixels.getNumChannels();
}
greyPixels = downsample;
}
else
greyPixels = &pixels;
if (this->payload->isOffline())
captures.push_back(*greyPixels);
else
payload->readPixels(frame, *greyPixels);
frame++;
if (frame >= payload->getFrameCount()) {
calc();
frame = payload->getFrameCount();
}
if (greyPixels != &pixels)
delete greyPixels;
}
示例5: pushFrame
//------------------------------------------------------------------------------
void ofxIpVideoServerRoute::pushFrame(ofPixels& pix) {
if(pix.isAllocated()) {
unsigned long long timestamp = ofGetElapsedTimeMillis();
ofPixels pixels(pix); // copy the pixels
ofSaveImage(pixels, buffer, OF_IMAGE_FORMAT_JPEG, settings.quality);
vector<ofxIpVideoServerFrameQueue*>::iterator iter = queues.begin();
ofxIpVideoServerFrame::Settings settings;
settings.quality = settings.quality;
ofxIpVideoServerFramePtr frame = ofxIpVideoServerFramePtr(new ofxIpVideoServerFrame(buffer,
timestamp,
settings));
while(iter != queues.end()) {
if((*iter) != NULL && (*iter)->isActive()) {
(*iter)->push(frame);
}
++iter;
}
} else {
ofLogError("ofxIpVideoServerRoute::pushFrame") << "Pushing unallocated pixels.";
}
}