bool cHueLoader::load(std::string filename)
{
	std::ifstream huefile;
	huefile.open(filename.c_str(), std::ios::in | std::ios::binary);

	if(!huefile.is_open()) {
		pDebug.Log("Couldn't open hues.mul in cHueLoader::load();", __FILE__,
			__LINE__, LEVEL_ERROR);
		return false;
	}

	unsigned int i = 0;
	bool first = true;

	// Read as many fonts as we can
	while (!huefile.eof()) {
		huefile.seekg(4, std::ios::cur);

		for (unsigned int j = 0; j < 8; ++j) {
			unsigned short hueId = i * 8 + j;

			stHue hue;

			// 32 Color Values
			for (unsigned int k = 0; k < 32; ++k) {
				unsigned short color15;

				huefile.read((char *) &color15, 2);

				// Swap Bytes to 32 bits
				hue.colors[k] = color15to32(color15);
			}

			// Two other bytes, tablestart and tableend
			unsigned short tableStart, tableEnd;

			huefile.read((char *) &tableStart, 2);
			huefile.read((char *) &tableEnd, 2);

			hue.tableEnd = color15to32(tableEnd);
			hue.tableStart = color15to32(tableStart);

			hues.push_back(hue);
			/*if (!first)
			
			else
				first = false;*/

			// Skip the Name
			huefile.seekg(20, std::ios::cur);
		}

		i++;

	}

	huefile.close();

	return true;
}
Ejemplo n.º 2
0
void FontManager::AddMulFont( std::string sFileName )
{   PROFILE
    std::ifstream FontStream;

    FontStream.open( sFileName.c_str(), std::ios::in | std::ios::binary );

    if ( !FontStream.is_open() )
    {
        THROWEXCEPTION( "Couldn't open " + sFileName );
    }

    // Header
    unsigned char header;

    stFont kFont;

    // Index
    unsigned short Index = 0;

    // Read as many fonts as we can
    while ( !FontStream.eof() )
    {
        FontStream.get( reinterpret_cast<char &>( header ) );

        // The only valid header in found is an one
        if ( header != 1 )
        {
            break;
        }

        // Read in the 224 characters
        kFont.maxHeight = 0;

        for ( int i = 0; i < 224; ++i )
        {
            // Width + Height + Header
            FontStream.get( reinterpret_cast<char &>( kFont.chars[i].width ) );
            FontStream.get( reinterpret_cast<char &>( kFont.chars[i].height ) );
            FontStream.get( reinterpret_cast<char &>( kFont.chars[i].header ) );

            if ( kFont.chars[i].height > kFont.maxHeight )
            {
                kFont.maxHeight = kFont.chars[i].height;
            }

            // Real Character Data
            kFont.chars[i].pixels = new unsigned int[kFont.chars[i].width * kFont.chars[i].height];
            kFont.chars[i].redmask = new unsigned char[kFont.chars[i].width * kFont.chars[i].height];

            unsigned short *pixels = new unsigned short[kFont.chars[i].width * kFont.chars[i].height];
            FontStream.read( reinterpret_cast<char *>( pixels ),
                             kFont.chars[i].width * kFont.chars[i].height * 2 );

            for ( int j = 0; j < kFont.chars[i].width * kFont.chars[i].height; ++j )
            {
                if ( IRIS_SwapU16( pixels[j] ) == 0 )
                {
                    kFont.chars[i].pixels[j] = 0;
                    kFont.chars[i].redmask[j] = 0;
                }
                else
                {
                    kFont.chars[i].pixels[j] = color15to32( IRIS_SwapU16( pixels[j] ) );
                    kFont.chars[i].redmask[j] = ( IRIS_SwapU16( pixels[j] ) >> 10 ) & 0x1F;
                }
            }

            SAFE_DELETE_ARRAY( pixels );
        }

        m_mFonts.insert( std::make_pair( Index++, kFont ) );
    }

    FontStream.close();
}