本文整理汇总了C++中ofPixels_::getImageType方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPixels_::getImageType方法的具体用法?C++ ofPixels_::getImageType怎么用?C++ ofPixels_::getImageType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPixels_
的用法示例。
在下文中一共展示了ofPixels_::getImageType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: saveImage
static void saveImage(ofPixels_<PixelType> & pix, string fileName, ofImageQualityType qualityLevel) {
ofInitFreeImage();
if (pix.isAllocated() == false){
ofLog(OF_LOG_ERROR,"error saving image - pixels aren't allocated");
return;
}
#ifdef TARGET_LITTLE_ENDIAN
if(sizeof(PixelType) == 1) {
pix.swapRgb();
}
#endif
FIBITMAP * bmp = getBmpFromPixels(pix);
#ifdef TARGET_LITTLE_ENDIAN
if(sizeof(PixelType) == 1) {
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) {
ofLogWarning() << "ofImageCompressionType only applies to JPEG images, ignoring value";
}
if (fif == FIF_GIF) {
FIBITMAP* convertedBmp;
if(pix.getImageType() == OF_IMAGE_COLOR_ALPHA) {
// this just converts the image to grayscale so it can save something
convertedBmp = FreeImage_ConvertTo8Bits(bmp);
} else {
// this will create a 256-color palette from the image
convertedBmp = FreeImage_ColorQuantize(bmp, FIQ_NNQUANT);
}
FreeImage_Save(fif, convertedBmp, fileName.c_str());
if (convertedBmp != NULL){
FreeImage_Unload(convertedBmp);
}
} else {
FreeImage_Save(fif, bmp, fileName.c_str());
}
}
}
if (bmp != NULL){
FreeImage_Unload(bmp);
}
}
示例2:
void ofImage_<PixelType>::setFromPixels(const ofPixels_<PixelType> & pixels){
setFromPixels(pixels.getPixels(),pixels.getWidth(),pixels.getHeight(),pixels.getImageType());
}
示例3: saveImage
static bool saveImage(const ofPixels_<PixelType> & _pix, const std::filesystem::path& _fileName, ofImageQualityType qualityLevel) {
ofInitFreeImage();
if (_pix.isAllocated() == false){
ofLogError("ofImage") << "saveImage(): couldn't save \"" << _fileName << "\", pixels are not allocated";
return false;
}
ofFilePath::createEnclosingDirectory(_fileName);
std::string 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_JPEG && (_pix.getNumChannels()==4 || _pix.getBitsPerChannel() > 8)){
ofPixels pix3 = _pix;
pix3.setNumChannels(3);
return saveImage(pix3,_fileName,qualityLevel);
}
FIBITMAP * bmp = nullptr;
#ifdef TARGET_LITTLE_ENDIAN
if(sizeof(PixelType) == 1 && (_pix.getPixelFormat()==OF_PIXELS_RGB || _pix.getPixelFormat()==OF_PIXELS_RGBA)) { // Make a local copy.
ofPixels_<PixelType> pix = _pix;
pix.swapRgb();
bmp = getBmpFromPixels(pix);
}else{
#endif
bmp = getBmpFromPixels(_pix);
#ifdef TARGET_LITTLE_ENDIAN
}
#endif
bool retValue = false;
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;
}
retValue = FreeImage_Save(fif, bmp, fileName.c_str(), quality);
} else {
if(qualityLevel != OF_IMAGE_QUALITY_BEST) {
ofLogWarning("ofImage") << "saveImage(): ofImageCompressionType only applies to JPEGs,"
<< " ignoring value for \" "<< fileName << "\"";
}
if (fif == FIF_GIF) {
FIBITMAP* convertedBmp;
if(_pix.getImageType() == OF_IMAGE_COLOR_ALPHA) {
// this just converts the image to grayscale so it can save something
convertedBmp = FreeImage_ConvertTo8Bits(bmp);
} else {
// this will create a 256-color palette from the image
convertedBmp = FreeImage_ColorQuantize(bmp, FIQ_NNQUANT);
}
retValue = FreeImage_Save(fif, convertedBmp, fileName.c_str());
if (convertedBmp != nullptr){
FreeImage_Unload(convertedBmp);
}
} else {
retValue = FreeImage_Save(fif, bmp, fileName.c_str());
}
}
}
if (bmp != nullptr){
FreeImage_Unload(bmp);
}
return retValue;
}