📄 wreimage.c
字号:
dup = FALSE;
lang.lang = DEF_LANG;
lang.sublang = DEF_SUBLANG;
tname = NULL;
rname = NULL;
ok = ( data && dir && cd && cd->dwBytesInRes );
if ( ok ) {
cursor = (BYTE *)WREMemAlloc( cd->dwBytesInRes );
ok = ( cursor != NULL );
}
if( ok ) {
memcpy( cursor, data + cd->dwImageOffset, cd->dwBytesInRes );
hotspot.xHotspot = cd->wXHotspot;
hotspot.yHotspot = cd->wYHotspot;
size = cd->dwBytesInRes;
ok = WREAddCursorHotspot( &cursor, &size, &hotspot );
}
if( ok ) {
tname = WResIDFromNum( (uint_16)RT_CURSOR );
ok = ( tname != NULL );
}
if( ok ) {
rname = WResIDFromNum( ord );
ok = ( rname != NULL );
}
if( ok ) {
ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
size, dir, &lang, &dup );
}
if( ok ) {
ok = WRFindAndSetData( dir, tname, rname, &lang, cursor );
}
if( !ok ) {
if( cursor != NULL ) {
WREMemFree( cursor );
}
}
if( tname != NULL ) {
WREMemFree( tname );
}
if( rname != NULL ) {
WREMemFree( rname );
}
return( ok );
}
Bool WREGetAndAddIconImage( BYTE *data, WResDir dir,
ICONDIRENTRY *id, int ord )
{
BYTE *icon;
int dup;
WResID *tname;
WResID *rname;
WResLangType lang;
Bool ok;
dup = FALSE;
lang.lang = DEF_LANG;
lang.sublang = DEF_SUBLANG;
tname = NULL;
rname = NULL;
ok = ( data && dir && id && id->dwBytesInRes );
if ( ok ) {
icon = (BYTE *)WREMemAlloc( id->dwBytesInRes );
ok = ( icon != NULL );
}
if( ok ) {
memcpy( icon, data + id->dwImageOffset, id->dwBytesInRes );
tname = WResIDFromNum( (uint_16)RT_ICON );
ok = ( tname != NULL );
}
if( ok ) {
rname = WResIDFromNum( ord );
ok = ( rname != NULL );
}
if ( ok ) {
ok = !WResAddResource( tname, rname, DEF_MEMFLAGS, 0,
id->dwBytesInRes, dir, &lang, &dup );
}
if( ok ) {
ok = WRFindAndSetData( dir, tname, rname, &lang, icon );
}
if( !ok ) {
if( icon != NULL ) {
WREMemFree( icon );
}
}
if( tname != NULL ) {
WREMemFree( tname );
}
if( rname != NULL ) {
WREMemFree( rname );
}
return( ok );
}
Bool WRECreateCursorResHeader( RESCURSORHEADER **rch, uint_32 *rchsize,
BYTE *data, uint_32 data_size )
{
CURSORHEADER *ch;
uint_32 chsize;
ICONHEADER *ih;
uint_32 ihsize;
int i;
Bool ok;
ih = NULL;
ok = ( rch && rchsize && data && data_size );
if( ok ) {
*rch = NULL;
*rchsize = 0;
ch = (CURSORHEADER *) data;
chsize = sizeof(CURSORHEADER);
chsize += sizeof(CURSORDIRENTRY)*(ch->cdCount-1);
ok = WRCreateIconHeader( data + chsize, data_size - chsize, 2,
&ih, &ihsize );
}
if( ok ) {
*rchsize = sizeof(RESCURSORHEADER);
*rchsize += sizeof(RESCURSORDIRENTRY)*(ih->idCount-1);
*rch = (RESCURSORHEADER *) WREMemAlloc( *rchsize );
ok = ( *rch != NULL );
}
if( ok ) {
memcpy( *rch, ch, sizeof(WORD)*3 );
for( i=0; i<ih->idCount ; i++ ) {
(*rch)->cdEntries[i].bWidth = ih->idEntries[i].bWidth;
(*rch)->cdEntries[i].bHeight = ih->idEntries[i].bHeight*2;
(*rch)->cdEntries[i].wPlanes = ih->idEntries[i].wPlanes;
(*rch)->cdEntries[i].wBitCount = ih->idEntries[i].wBitCount;
(*rch)->cdEntries[i].lBytesInRes = ih->idEntries[i].dwBytesInRes;
(*rch)->cdEntries[i].wNameOrdinal = i + 1;
}
}
if( ih != NULL ) {
WREMemFree( ih );
}
return( ok );
}
Bool WRECreateIconResHeader( RESICONHEADER **rih, uint_32 *rihsize,
BYTE *data, uint_32 data_size )
{
ICONHEADER *pih;
uint_32 pihsize;
ICONHEADER *ih;
uint_32 ihsize;
int i;
Bool ok;
ih = NULL;
ok = ( rih && rihsize && data && data_size );
if( ok ) {
pih = (ICONHEADER *) data;
pihsize = sizeof(ICONHEADER);
pihsize += sizeof(ICONDIRENTRY)*(pih->idCount-1);
ok = WRCreateIconHeader( data + pihsize, data_size - pihsize, 1,
&ih, &ihsize );
}
if( ok ) {
*rihsize = sizeof(RESICONHEADER);
*rihsize += sizeof(RESICONDIRENTRY)*(ih->idCount-1);
*rih = (RESICONHEADER *)WREMemAlloc( *rihsize );
ok = ( *rih != NULL );
}
if( ok ) {
memcpy( *rih, pih, sizeof(WORD)*3 );
for( i=0; i<ih->idCount ; i++ ) {
(*rih)->idEntries[i].bWidth = ih->idEntries[i].bWidth;
(*rih)->idEntries[i].bHeight = ih->idEntries[i].bHeight;
(*rih)->idEntries[i].bColorCount = ih->idEntries[i].bColorCount;
(*rih)->idEntries[i].bReserved = 0;
(*rih)->idEntries[i].wPlanes = ih->idEntries[i].wPlanes;
(*rih)->idEntries[i].wBitCount = ih->idEntries[i].wBitCount;
(*rih)->idEntries[i].lBytesInRes = ih->idEntries[i].dwBytesInRes;
(*rih)->idEntries[i].wNameOrdinal = i + 1;
}
}
if( ih != NULL ) {
WREMemFree( ih );
}
return( ok );
}
// 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 );
}
Bool WRECalcAndAddIconDirectory( BYTE **data, uint_32 *size, WORD type )
{
ICONHEADER *ih;
uint_32 ihsize;
if( !WRCreateIconHeader( *data, *size, type, &ih, &ihsize ) ) {
return( FALSE );
}
*data = WREMemRealloc( *data, *size + ihsize );
if( !*data ) {
return( FALSE );
}
memmove( *data + ihsize, *data, *size );
memcpy( *data, ih, ihsize );
*size += ihsize;
WREMemFree( ih );
return( TRUE );
}
Bool WREStripIconDirectory( BYTE **icon, uint_32 *size )
{
ICONHEADER *ih;
uint_32 ihsize;
if( icon && *icon && size ) {
ih = (ICONHEADER *)*icon;
if( ( ih->idType == 1 ) || ( ih->idType == 2 ) ) {
ihsize = sizeof(ICONHEADER);
ihsize += sizeof(ICONDIRENTRY)*(ih->idCount-1);
memmove( *icon, *icon + ihsize, *size - ihsize );
*size -= ihsize;
return( TRUE );
}
}
return( FALSE );
}
Bool WREAddCursorHotspot( BYTE **cursor, uint_32 *size, CURSORHOTSPOT *hs )
{
int hs_size;
hs_size = sizeof(CURSORHOTSPOT);
if( !cursor || !size ) {
return( FALSE );
}
*cursor = WREMemRealloc( *cursor, *size + hs_size );
if( *cursor == NULL ) {
return( FALSE );
}
memmove( *cursor + hs_size, *cursor, *size );
memcpy( *cursor, hs, hs_size );
*size += hs_size;
return( TRUE );
}
Bool WREStripCursorHotspot( BYTE **cursor, uint_32 *size )
{
int hs_size;
hs_size = sizeof(CURSORHOTSPOT);
if( cursor && size && ( *size > hs_size ) ) {
memmove( *cursor, *cursor + hs_size, *size - hs_size );
*size -= hs_size;
return( TRUE );
}
return( FALSE );
}
Bool WREStripCursorDirectory( BYTE **cursor, uint_32 *size )
{
CURSORHEADER *ch;
uint_32 cd_size;
if( cursor && *cursor && size ) {
return( FALSE );
}
ch = (CURSORHEADER *) *cursor;
cd_size = sizeof(CURSORHEADER);
cd_size += sizeof(CURSORDIRENTRY)*(ch->cdCount-1);
memmove( *cursor, *cursor + cd_size, *size - cd_size );
*size -= cd_size;
return( TRUE );
}
Bool WREAddBitmapFileHeader( BYTE **data, uint_32 *size )
{
return( WRAddBitmapFileHeader( data, size ) );
}
Bool WREStripBitmapFileHeader( BYTE **data, uint_32 *size )
{
return( WRStripBitmapFileHeader( data, size ) );
}
Bool WRECreateCursorEntries( WRECurrentResInfo *curr,
void *data, uint_32 size )
{
RESCURSORHEADER *rch;
CURSORHEADER *ch;
uint_16 ord;
uint_32 rchsize;
int i;
Bool ok;
ok = ( curr && curr->info && data && size );
if( ok ) {
if( curr->lang->data ) {
WREMemFree( curr->lang->data );
curr->lang->data = NULL;
}
curr->lang->Info.Length = 0;
ok = WRECreateCursorResHeader( &rch, &rchsize, data, size );
}
if( ok ) {
curr->lang->data = (void *)rch;
curr->lang->Info.Length = rchsize;
ord = 0;
ch = (CURSORHEADER *) data;
for( i = 0; ok && i < rch->cwCount; i++ ) {
ord = WREFindUnusedImageId( curr->info, ord );
ok = ( ord != 0 );
if( ok ) {
rch->cdEntries[i].wNameOrdinal = ord;
ok = WREGetAndAddCursorImage( data, curr->info->info->dir,
&ch->cdEntries[i], ord );
}
}
}
return( ok );
}
Bool WRECreateIconEntries( WRECurrentResInfo *curr,
void *data, uint_32 size )
{
RESICONHEADER *rih;
ICONHEADER *ih;
uint_16 ord;
uint_32 rihsize;
int i;
Bool ok;
ok = ( curr && curr->info && data && size );
if( ok ) {
if( curr->lang->data ) {
WREMemFree( curr->lang->data );
curr->lang->data = NULL;
}
curr->lang->Info.Length = 0;
ok = WRECreateIconResHeader( &rih, &rihsize, data, size );
}
if( ok ) {
curr->lang->data = (void *)rih;
curr->lang->Info.Length = rihsize;
ord = 0;
ih = (ICONHEADER *) data;
for( i = 0; ok && i < rih->cwCount; i++ ) {
ord = WREFindUnusedImageId( curr->info, ord );
ok = ( ord != 0 );
if( ok ) {
rih->idEntries[i].wNameOrdinal = ord;
ok = WREGetAndAddIconImage( data, curr->info->info->dir,
&ih->idEntries[i], ord );
}
}
}
return( ok );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -