本文整理汇总了C++中ofPixels::swapRgb方法的典型用法代码示例。如果您正苦于以下问题:C++ ofPixels::swapRgb方法的具体用法?C++ ofPixels::swapRgb怎么用?C++ ofPixels::swapRgb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofPixels
的用法示例。
在下文中一共展示了ofPixels::swapRgb方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
}
示例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: putBmpIntoPixels
//----------------------------------------------------
void putBmpIntoPixels(FIBITMAP * bmp, ofPixels &pix, bool swapForLittleEndian = true){
int width = FreeImage_GetWidth(bmp);
int height = FreeImage_GetHeight(bmp);
int bpp = FreeImage_GetBPP(bmp);
FIBITMAP * bmpTemp = NULL;
switch (bpp){
case 8:
if (FreeImage_GetColorType(bmp) == FIC_PALETTE) {
bmpTemp = FreeImage_ConvertTo24Bits(bmp);
bmp = bmpTemp;
bpp = FreeImage_GetBPP(bmp);
} else {
// do nothing we are grayscale
}
break;
case 24:
// do nothing we are color
break;
case 32:
// do nothing we are colorAlpha
break;
default:
bmpTemp = FreeImage_ConvertTo24Bits(bmp);
bmp = bmpTemp;
bpp = FreeImage_GetBPP(bmp);
break;
}
int bytesPerPixel = bpp / 8;
pix.allocate(width, height, bpp);
FreeImage_ConvertToRawBits(pix.getPixels(), bmp, width*bytesPerPixel, bpp, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, true); // get bits
if (bmpTemp != NULL) FreeImage_Unload(bmpTemp);
#ifdef TARGET_LITTLE_ENDIAN
if(swapForLittleEndian)
pix.swapRgb();
#endif
}