FIBITMAP* DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear) { FIBITMAP *dst = NULL; if(!FreeImage_HasPixels(src)) return NULL; // convert from src_type to dst_type const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(src); if(src_type == dst_type) { return FreeImage_Clone(src); } const unsigned src_bpp = FreeImage_GetBPP(src); switch(src_type) { case FIT_BITMAP: switch(dst_type) { case FIT_UINT16: dst = FreeImage_ConvertToUINT16(src); break; case FIT_INT16: dst = (src_bpp == 8) ? convertByteToShort.convert(src, dst_type) : NULL; break; case FIT_UINT32: dst = (src_bpp == 8) ? convertByteToULong.convert(src, dst_type) : NULL; break; case FIT_INT32: dst = (src_bpp == 8) ? convertByteToLong.convert(src, dst_type) : NULL; break; case FIT_FLOAT: dst = FreeImage_ConvertToFloat(src); break; case FIT_DOUBLE: dst = (src_bpp == 8) ? convertByteToDouble.convert(src, dst_type) : NULL; break; case FIT_COMPLEX: dst = (src_bpp == 8) ? convertByteToComplex.convert(src) : NULL; break; case FIT_RGB16: dst = FreeImage_ConvertToRGB16(src); break; case FIT_RGBA16: dst = FreeImage_ConvertToRGBA16(src); break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: dst = FreeImage_ConvertToRGBAF(src); break; } break; case FIT_UINT16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = FreeImage_ConvertToFloat(src); break; case FIT_DOUBLE: dst = convertUShortToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertUShortToComplex.convert(src); break; case FIT_RGB16: dst = FreeImage_ConvertToRGB16(src); break; case FIT_RGBA16: dst = FreeImage_ConvertToRGBA16(src); break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: dst = FreeImage_ConvertToRGBAF(src); break; } break; case FIT_INT16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = convertShortToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertShortToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertShortToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_UINT32: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_INT32: break; case FIT_FLOAT: dst = convertULongToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertULongToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertULongToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_INT32: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_FLOAT: dst = convertLongToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertLongToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertLongToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_FLOAT: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_DOUBLE: dst = convertFloatToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertFloatToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: dst = FreeImage_ConvertToRGBAF(src); break; } break; case FIT_DOUBLE: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_COMPLEX: dst = convertDoubleToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_COMPLEX: switch(dst_type) { case FIT_BITMAP: break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_DOUBLE: break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_RGB16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertTo24Bits(src); break; case FIT_UINT16: dst = FreeImage_ConvertToUINT16(src); break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = FreeImage_ConvertToFloat(src); break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGBA16: dst = FreeImage_ConvertToRGBA16(src); break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: dst = FreeImage_ConvertToRGBAF(src); break; } break; case FIT_RGBA16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertTo32Bits(src); break; case FIT_UINT16: dst = FreeImage_ConvertToUINT16(src); break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = FreeImage_ConvertToFloat(src); break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGB16: dst = FreeImage_ConvertToRGB16(src); break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: dst = FreeImage_ConvertToRGBAF(src); break; } break; case FIT_RGBF: switch(dst_type) { case FIT_BITMAP: break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = FreeImage_ConvertToFloat(src); break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBAF: dst = FreeImage_ConvertToRGBAF(src); break; } break; case FIT_RGBAF: switch(dst_type) { case FIT_BITMAP: break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = FreeImage_ConvertToFloat(src); break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; } break; } if(NULL == dst) { FreeImage_OutputMessageProc(FIF_UNKNOWN, "FREE_IMAGE_TYPE: Unable to convert from type %d to type %d.\n No such conversion exists.", src_type, dst_type); } return dst; }
FIBITMAP* DLL_CALLCONV FreeImage_ConvertToType(FIBITMAP *src, FREE_IMAGE_TYPE dst_type, BOOL scale_linear) { FIBITMAP *dst = NULL; if(!src) return NULL; // convert from src_type to dst_type const FREE_IMAGE_TYPE src_type = FreeImage_GetImageType(src); if(src_type == dst_type) { return FreeImage_Clone(src); } if(src_type == FIT_BITMAP) { const unsigned src_bpp = FreeImage_GetBPP(src); if(((src_bpp == 24) || (src_bpp == 32)) && (dst_type != FIT_RGBF)) { FreeImage_OutputMessageProc(FIF_UNKNOWN, "FREE_IMAGE_TYPE: Only 24-/32-bit dib can be converted to type %d.", dst_type); return NULL; } else if(src_bpp != 8) { FreeImage_OutputMessageProc(FIF_UNKNOWN, "FREE_IMAGE_TYPE: Only 8-bit dib can be converted to type %d.", dst_type); return NULL; } } switch(src_type) { case FIT_BITMAP: switch(dst_type) { case FIT_UINT16: dst = convertByteToUShort.convert(src, dst_type); break; case FIT_INT16: dst = convertByteToShort.convert(src, dst_type); break; case FIT_UINT32: dst = convertByteToULong.convert(src, dst_type); break; case FIT_INT32: dst = convertByteToLong.convert(src, dst_type); break; case FIT_FLOAT: dst = convertByteToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertByteToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertByteToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: break; } break; case FIT_UINT16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = convertUShortToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertUShortToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertUShortToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_INT16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: dst = convertShortToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertShortToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertShortToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_UINT32: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_INT32: break; case FIT_FLOAT: dst = convertULongToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertULongToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertULongToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_INT32: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_FLOAT: dst = convertLongToFloat.convert(src, dst_type); break; case FIT_DOUBLE: dst = convertLongToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertLongToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_FLOAT: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_DOUBLE: dst = convertFloatToDouble.convert(src, dst_type); break; case FIT_COMPLEX: dst = convertFloatToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_DOUBLE: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertToStandardType(src, scale_linear); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_COMPLEX: dst = convertDoubleToComplex.convert(src); break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_COMPLEX: switch(dst_type) { case FIT_BITMAP: break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_DOUBLE: break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: break; case FIT_RGBAF: break; } break; case FIT_RGB16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertTo24Bits(src); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGBA16: break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: break; } break; case FIT_RGBA16: switch(dst_type) { case FIT_BITMAP: dst = FreeImage_ConvertTo32Bits(src); break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGB16: break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; case FIT_RGBAF: break; } break; case FIT_RGBF: switch(dst_type) { case FIT_BITMAP: break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBAF: break; } break; case FIT_RGBAF: switch(dst_type) { case FIT_BITMAP: break; case FIT_UINT16: break; case FIT_INT16: break; case FIT_UINT32: break; case FIT_INT32: break; case FIT_FLOAT: break; case FIT_DOUBLE: break; case FIT_COMPLEX: break; case FIT_RGB16: break; case FIT_RGBA16: break; case FIT_RGBF: dst = FreeImage_ConvertToRGBF(src); break; } break; } if(NULL == dst) { FreeImage_OutputMessageProc(FIF_UNKNOWN, "FREE_IMAGE_TYPE: Unable to convert from type %d to type %d.\n No such conversion exists.", src_type, dst_type); } else { // copy metadata from src to dst FreeImage_CloneMetadata(dst, src); } return dst; }