سؤال

I have the following code to load textures.

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;
}

The problem is, "colorType" gives me wrong color type. For example a .jpg is reported as rgb24 while it is bgr24, a .dds image that is BRGA32 is reported as RGBA32. A .tga image is reported correctly as RGBA32 though.

Whhat could be the issue?

هل كانت مفيدة؟

المحلول

First of all FreeImage_GetColorType returns bitmap color type (it can differ from original image).

From docs:

Color model A color model is an abstract mathematical model describing the way colors can be represented as tuples of numbers, typically as three or four values or color components (e.g. RGB and CMYK are color models). FreeImage mainly uses the RGB[A] color model to represent pixels in memory.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top