Beispiel #1
0
int isImageFile(const char *filename)
{
    const char* ext = getFileNameExt(filename);
    int lenExt = strlen(ext);

    if (lenExt==3)
    {
        if (
            ((ext[0]=='b' || ext[0]=='B') && (ext[1]=='m' || ext[1]=='M') && (ext[2]=='p' || ext[2]=='P') ) ||
            ((ext[0]=='j' || ext[0]=='J') && (ext[1]=='p' || ext[1]=='P') && (ext[2]=='g' || ext[2]=='G') ) ||
            ((ext[0]=='p' || ext[0]=='P') && (ext[1]=='n' || ext[1]=='N') && (ext[2]=='g' || ext[2]=='G') )
        )
        {
            return 1;
        }
    }
    else if (lenExt==4)
    {
        if (
            ((ext[0]=='j' || ext[0]=='J') && (ext[1]=='p' || ext[1]=='P') && (ext[2]=='e' || ext[2]=='E') && (ext[3]=='g' || ext[3]=='G') )
        )
        {
            return 1;
        }
    }

    return 0;
}
Beispiel #2
0
int isSigFile(const char *filename)
{
    const char* ext = getFileNameExt(filename);
    size_t lenExt = strlen(ext);

    if (lenExt==3)
    {
        if (
            ((ext[0]=='s' || ext[0]=='S') && (ext[1]=='i' || ext[1]=='I') && (ext[2]=='g' || ext[2]=='G') ) )
        {
            return 1;
        }
    }
    return 0;
}
Beispiel #3
0
int isDscFile(const char *filename)
{
    const char* ext = getFileNameExt(filename);
    size_t lenExt = strlen(ext);

    if (lenExt==3)
    {
        if (
            ((ext[0]=='d' || ext[0]=='D') && (ext[1]=='s' || ext[1]=='S') && (ext[2]=='c' || ext[2]=='c') ) )
        {
            return 1;
        }
    }
    return 0;
}
//--------------------------------------------------------------------------------------
// entry function to initialize an image from a .DDS texture
//--------------------------------------------------------------------------------------
INT32 ModelTexture::LoadImageMipSetFromFile(const WCHAR *pFilename, void *pluginManager)
{
    CleanMipSet();

    try
    {
        // get the ext and load image with amd compressonator image plugin
        char *fileExt;
        wstring ws(pFilename);
        string sFilename(ws.begin(), ws.end());
        size_t dot = sFilename.find_last_of('.');
        std::string temp;

        if (dot != std::string::npos) {
            temp = (sFilename.substr(dot + 1, sFilename.size() - dot));
            std::transform(temp.begin(), temp.end(), temp.begin(), toupper);
            fileExt = (char*)temp.data();
        }

        pMipSet = new MipSet();

        if (pMipSet == NULL)
        {
            CleanMipSet();
            if (m_CMIPS)
            {
                m_CMIPS->Print("Error loading file: Out of memory for MipSet data");
            }
            return -1;
        }

        memset(pMipSet, 0, sizeof(MipSet));

        if (m_CMIPS)
        {
            char fname[_MAX_FNAME];
            getFileNameExt(sFilename.c_str(), fname, _MAX_FNAME);
            m_CMIPS->SetProgress(0);
            if (m_CMIPS->m_canceled)
                return -1;
            m_CMIPS->Print("Loading: %s", fname);
        }

        if (AMDLoadMIPSTextureImage(sFilename.c_str(), pMipSet, false, pluginManager) != 0)
        {
            CleanMipSet();
            if (m_CMIPS)
            {
                m_CMIPS->Print("Error: reading image, data type not supported");
            }
            return -1;
        }

        if (pMipSet)
        {
            if (pMipSet->m_format == CMP_FORMAT_Unknown)
            {
                pMipSet->m_format = GetFormat(pMipSet);
            }

            pMipSet->m_swizzle = KeepSwizzle(pMipSet->m_format);

            if (pMipSet->m_compressed || (pMipSet->m_ChannelFormat == CF_Compressed))
            {
                pMipSet->m_compressed = true;
                Config configsetting;
                configsetting.swizzle = pMipSet->m_swizzle;
                pMipSet = DecompressMIPSet(pMipSet, GPUDecode_INVALID, &configsetting, NULL);
                if (pMipSet == NULL)
                {
                    if (m_CMIPS)
                    {
                        m_CMIPS->Print("Error: reading compressed image");
                    }
                    return -1;
                }
            }
            if (pMipSet->m_swizzle)
                SwizzleMipMap(pMipSet);
        }
        else
        {
            CleanMipSet();
            if (m_CMIPS)
            {
                m_CMIPS->Print("Error: reading image, data type not supported");
            }
            return -1;
        }

    }
    catch (std::bad_alloc)
    {
        if (m_CMIPS)
        {
            CleanMipSet();
            m_CMIPS->m_canceled = true;
            m_CMIPS->Print("Error: Out of Memory while loading textures!");
        }
        return -1;
    }

    return 0;
}