Beispiel #1
0
bool WRAPI WRCreateIconHeader( BYTE *data, uint_32 size, WORD type,
                                  ICONHEADER **ih, uint_32 *ihsize )
{
    BITMAPINFOHEADER    *bih;
    WORD                count;
    uint_32             pos;
    int                 i;

    if( data == NULL || size == 0 || ih == NULL || ihsize == NULL ) {
        return( false );
    }

    count = WRCountIconImages( data, size );
    if( count == 0 ) {
        return( false );
    }

    *ihsize = sizeof( ICONHEADER ) + sizeof( ICONDIRENTRY ) * (count - 1);
    *ih = MemAlloc( *ihsize );
    if( *ih == NULL ) {
        return( false );
    }

    (*ih)->idReserved = 0;
    (*ih)->idType = type;
    (*ih)->idCount = count;

    for( i = 0, pos = 0; i < count; i++ ) {
        bih = (BITMAPINFOHEADER *)(data + pos);
        (*ih)->idEntries[i].bWidth = bih->biWidth;
        (*ih)->idEntries[i].bHeight = bih->biHeight / 2;
        if( type == 1 ) {
            (*ih)->idEntries[i].bColorCount = 1 << bih->biBitCount;
        } else {
            (*ih)->idEntries[i].bColorCount = 0;
        }
        (*ih)->idEntries[i].bReserved = 0;
        (*ih)->idEntries[i].wPlanes = bih->biPlanes;
        (*ih)->idEntries[i].wBitCount = bih->biBitCount;
        (*ih)->idEntries[i].dwBytesInRes = WRSizeOfImage( bih );
        if( i == 0 ) {
            (*ih)->idEntries[i].dwImageOffset = *ihsize;
        } else {
            (*ih)->idEntries[i].dwImageOffset = (*ih)->idEntries[i - 1].dwImageOffset +
                                                (*ih)->idEntries[i - 1].dwBytesInRes;
        }
        pos += (*ih)->idEntries[i].dwBytesInRes;
    }

    return( true );
}
Beispiel #2
0
// This function assumes that the data represents icon data WITHOUT
// an icon directory
WORD WRECountIconImages( BYTE *data, uint_32 size )
{
    BITMAPINFOHEADER    *bih;
    WORD                count;
    uint_32             pos;

    pos = 0;
    count = 0;
    while( pos < size ) {
        bih = (BITMAPINFOHEADER *)(data + pos);
        count++;
        pos += WRSizeOfImage( bih );
        // if we overrun do not count this block
        if( pos > size ) {
            count--;
        }
    }

    return( count );
}