Beispiel #1
0
static void LoadGimpPalette(FILE* fp, Palette& pal)
{
    int idx=0;

    char line[256];
    int linenum=0;
    bool gotcookie=false;
    while( fgets( line, sizeof(line), fp ) )
    {
        ++linenum;
        std::vector< std::string > args;
        SplitLine(line, args);
        if( args.empty() )
            continue;

        if( !gotcookie )
        {
            if(args.size()==2 && args[0] == "GIMP" && args[1] == "Palette")
                gotcookie = true;
            else
                throw Exception("not a GIMP palette");
        }

        if( args[0] == "Name:" )
        {
            continue;
        }
        if( args[0] == "Column:" )
        {
            continue;
        }


        if( args.size() >= 3 && idx <=255 )
        {
            RGBx c;
            c.r = atoi( args[0].c_str() );
            c.g = atoi( args[1].c_str() );
            c.b = atoi( args[2].c_str() );
            // ignore name, if there is one

            pal.SetColour(idx,c);
            ++idx;
        }
    }

    if( !feof(fp ) )
    {
        throw Exception( "read error" );
    }

    pal.SetNumColours(idx);
}