Forum index VCMI Project - Heroes 3: WoG recreated
Forum of the project aiming to recreate best turn-based strategy ever!

FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  StatisticsStatistics
RegisterRegister  Log inLog in  AlbumAlbum  DownloadDownload

Previous topic :: Next topic
loadBitmapFromDir parameter question
Author Message
krs


Joined: 04 Sep 2012
Posts: 374
Posted: 2017-01-29, 22:34   loadBitmapFromDir parameter question

SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname, bool setKey)

what is setKey used for?

Code:
SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname, bool setKey)
{
    if(!fname.size())
    {
        logGlobal->warnStream() << "Call to loadBitmap with void fname!";
        return nullptr;
    }
    if (!CResourceHandler::get()->existsResource(ResourceID(path + fname, EResType::IMAGE)))
    {
        return nullptr;
    }

    SDL_Surface * ret=nullptr;

    auto readFile = CResourceHandler::get()->load(ResourceID(path + fname, EResType::IMAGE))->readAll();

    if (isPCX(readFile.first.get()))
    {//H3-style PCX
        ret = loadH3PCX(readFile.first.get(), readFile.second);
        if (ret)
        {
            if(ret->format->BytesPerPixel == 1  &&  setKey)
            {
                CSDL_Ext::setColorKey(ret,ret->format->palette->colors[0]);
            }
        }
        else
        {
            logGlobal->errorStream()<<"Failed to open "<<fname<<" as H3 PCX!";
            return nullptr;
        }
    }
    else
    { //loading via SDL_Image
        ret = IMG_Load_RW(
                  //create SDL_RW with our data (will be deleted by SDL)
                  SDL_RWFromConstMem((void*)readFile.first.get(), readFile.second),
                  1); // mark it for auto-deleting
        if (ret)
        {
            if (ret->format->palette)
            {
                //set correct value for alpha\unused channel
                for (int i=0; i < ret->format->palette->ncolors; i++)
                    ret->format->palette->colors[i].a = SDL_ALPHA_OPAQUE;
            }
        }
        else
        {
            logGlobal->errorStream() << "Failed to open " << fname << " via SDL_Image";
            logGlobal->errorStream() << "Reason: " << IMG_GetError();
            return nullptr;
        }
    }

    // When modifying anything here please check two use cases:
    // 1) Vampire mansion in Necropolis (not 1st color is transparent)
    // 2) Battle background when fighting on grass/dirt, topmost sky part (NO transparent color)
    // 3) New objects that may use 24-bit images for icons (e.g. witchking arts)
    if (ret->format->palette)
    {
        CSDL_Ext::setDefaultColorKeyPresize(ret);
    }
    else if (ret->format->Amask)
    {
        SDL_SetSurfaceBlendMode(ret, SDL_BLENDMODE_BLEND);
    }
    else // always set
    {
        CSDL_Ext::setDefaultColorKey(ret);
    }
    return ret;
}
 
     
AVS 

Joined: 25 Feb 2011
Posts: 561
Location: Russia
Posted: 2017-01-30, 03:53   

I think this parameter is useless now.
 
     
Display posts from previous:   
Reply to topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Add this topic to your bookmarks
Printable version

Jump to:  

Powered by phpBB modified by Przemo © 2003 phpBB Group

Hosting provided by DigitalOcean
Page generated in 0.02 second. SQL queries: 12