예제 #1
0
BOOL fipImage::convertTo4Bits() {
	if(_dib) {
		FIBITMAP *dib4 = FreeImage_ConvertTo4Bits(_dib);
		return replace(dib4);
	}
	return FALSE;
}
/**
 * Helper to encapsulate Bpp conversion using FreeImage, taking into consideration color type. Creates a new bitmap if needed. Can return the same one.
 * @param pHandle		FIBITMAP as defined by the Freeimage library.
 * @param pNewBpp		the new bpp that the supplied FIBITMAP is to be coverted to.
 */
FIBITMAP* FreeImageHelper::convertBpp(FIBITMAP* pHandle, int pNewBpp) {	
	//Convert the bit depth
	FIBITMAP *converted = NULL;
	
	//Convert Bpp only if needed
	if (pNewBpp != static_cast<int>(FreeImage_GetBPP(pHandle))) {
		//Transform bpp to the pixel format
		switch (pNewBpp) {
			case (4):
				converted = FreeImage_ConvertTo4Bits(pHandle);
				break;
			case (8):
				converted = FreeImage_ConvertTo8Bits(pHandle);
				break;
			case(16):
				converted = FreeImage_ConvertTo16Bits565(pHandle);  //There's option of 16Bits555. But leaves unused bits. Chosen 565 because it's most common
				break;
			case(24):
			   converted = FreeImage_ConvertTo24Bits(pHandle);    
			    break;
			case(32): {
			    converted = FreeImage_ConvertTo32Bits (pHandle); 
				}
			    break;
			default:
				converted = NULL;
				break;
		}
	} else {
		//No change, just set 'converted' handle to current one
		converted = pHandle;
	}

	return converted;
}