自由图像报告图像颜色类型错误



我有以下代码来加载纹理。

PackageTexture AssetImporter::ProcessTexture(const boost::filesystem::path& assetPath, const TextureType textureType)
{
    PackageTexture texture;
    const std::string filename = assetPath.filename().string();
    FREE_IMAGE_FORMAT imageFormat = FreeImage_GetFileType(filename.c_str());
    if (imageFormat == FIF_UNKNOWN) 
        imageFormat = FreeImage_GetFIFFromFilename(filename.c_str());
    if (imageFormat == FIF_UNKNOWN || !FreeImage_FIFSupportsReading(imageFormat))
        return texture;
    FIBITMAP* bitmap = FreeImage_Load(imageFormat, assetPath.string().c_str());
    if (!bitmap || !FreeImage_GetBits(bitmap) || !FreeImage_GetWidth(bitmap) || !FreeImage_GetHeight(bitmap))
        return texture;
    FREE_IMAGE_COLOR_TYPE colorType = FreeImage_GetColorType(bitmap);
    uint32_t bitsPerPixel           = FreeImage_GetBPP(bitmap);
    uint32_t widthInPixels          = FreeImage_GetWidth(bitmap);
    uint32_t heightInPixels         = FreeImage_GetHeight(bitmap);
    ....
    FreeImage_Unload(bitmap);
    return texture;
}

问题是,"颜色类型"给了我错误的颜色类型。例如,.jpg报告为 rgb24,而它是 bgr24,而 BRGA32 的.dds图像报告为 RGBA32。不过,.tga图像被正确报告为 RGBA32。

问题可能出在哪里?

首先,FreeImage_GetColorType返回位图颜色类型(它可以与原始图像不同)。

从文档中:

颜色模型颜色模型是一种抽象的数学模型,描述了颜色可以存在的方式表示为数字元组,通常表示为三个或四个值或颜色分量(例如RGB和CMYK是颜色模型)。FreeImage 主要使用 RGB[A] 颜色模型来表示内存中的像素。

最新更新