int gr_load_pcx( const char * mapname ) { GRAPH * gr = gr_read_pcx( mapname ) ; if ( !gr ) return 0 ; gr->code = bitmap_next_code() ; grlib_add_map( 0, gr ) ; return gr->code ; }
/* Static convenience function */ static int gr_read_lib( file * fp ) { char header[8] ; short int px, py ; int bpp, libid, code; uint32_t y ; unsigned c; GRLIB * lib ; GRAPH * gr ; PALETTE * pal = NULL ; int st = 0; libid = grlib_new() ; if ( libid < 0 ) return -1 ; lib = grlib_get( libid ); if ( !lib ) { grlib_destroy( libid ) ; return -1 ; } file_read( fp, header, 8 ) ; if ( strcmp( header, F32_MAGIC ) == 0 ) bpp = 32 ; else if ( strcmp( header, F16_MAGIC ) == 0 ) bpp = 16 ; else if ( strcmp( header, FPG_MAGIC ) == 0 ) bpp = 8 ; else if ( strcmp( header, F01_MAGIC ) == 0 ) bpp = 1 ; else { grlib_destroy( libid ) ; return -1 ; } if ( bpp == 8 && !( pal = gr_read_pal_with_gamma( fp ) ) ) { grlib_destroy( libid ) ; return -1 ; } while ( !file_eof( fp ) ) { if ( !file_read( fp, &chunk, 64 ) ) break ; ARRANGE_DWORD( &chunk.code ) ; ARRANGE_DWORD( &chunk.regsize ) ; ARRANGE_DWORD( &chunk.width ) ; ARRANGE_DWORD( &chunk.height ) ; ARRANGE_DWORD( &chunk.flags ) ; /* Cabecera del gráfico */ gr = bitmap_new( chunk.code, chunk.width, chunk.height, bpp ) ; if ( !gr ) { grlib_destroy( libid ) ; if ( bpp == 8 ) pal_destroy( pal ) ; // Elimino la instancia inicial return -1 ; } memcpy( gr->name, chunk.name, 32 ) ; gr->name[31] = 0 ; gr->ncpoints = chunk.flags ; gr->modified = 2 ; // bitmap_analize( gr ); /* Puntos de control */ if ( gr->ncpoints ) { gr->cpoints = ( CPOINT * ) malloc( gr->ncpoints * sizeof( CPOINT ) ) ; if ( !gr->cpoints ) { bitmap_destroy( gr ) ; grlib_destroy( libid ) ; if ( bpp == 8 ) pal_destroy( pal ) ; return -1 ; } for ( c = 0 ; c < gr->ncpoints ; c++ ) { file_readSint16( fp, &px ) ; file_readSint16( fp, &py ) ; if ( px == -1 && py == -1 ) { gr->cpoints[c].x = CPOINT_UNDEFINED ; gr->cpoints[c].y = CPOINT_UNDEFINED ; } else { gr->cpoints[c].x = px ; gr->cpoints[c].y = py ; } } } else gr->cpoints = 0 ; /* Datos del gráfico */ for ( y = 0 ; y < gr->height ; y++ ) { uint8_t * line = ( uint8_t * )gr->data + gr->pitch * y; switch ( bpp ) { case 32: st = file_readUint32A( fp, ( uint32_t * ) line, gr->width ); break; case 16: st = file_readUint16A( fp, ( uint16_t * ) line, gr->width ); break; case 8: case 1: st = file_read( fp, line, gr->widthb ); break; } if ( !st ) { bitmap_destroy( gr ); grlib_destroy( libid ) ; if ( bpp == 8 ) pal_destroy( pal ); return -1 ; } } code = grlib_add_map( libid, gr ) ; if ( bpp == 8 ) pal_map_assign( libid, code, pal ) ; } if ( bpp == 8 ) pal_destroy( pal ) ; // Elimino la instancia inicial return libid ; }