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()); } }
//---------------------------------------------------------------- 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); } }
//---------------------------------------------------------------- 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); } }
//---------- 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; }
//------------------------------------------------------------------------------ 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."; } }
void ofPixels::operator=(const ofPixels & mom){ if(mom.isAllocated()){ allocate(mom.getWidth(),mom.getHeight(),mom.getImageType()); memcpy(pixels,mom.getPixels(),mom.getWidth()*mom.getHeight()*mom.getBytesPerPixel()); } }