M2MConnectionHandlerPimpl::~M2MConnectionHandlerPimpl() { tr_debug("~M2MConnectionHandlerPimpl()"); stop_listening(); delete _security_impl; pal_destroy(); tr_debug("~M2MConnectionHandlerPimpl() - OUT"); }
int gr_load_pal( const char * filename ) { if ( !filename ) return 0; file * fp = file_open( filename, "rb" ) ; char header[8] ; PALETTE * r = NULL ; PALETTE * old_sys_pal = sys_pixel_format->palette ; if ( !fp ) return 0 ; file_read( fp, header, 8 ) ; if ( !strcmp( header, MAP_MAGIC ) ) { file_seek( fp, 48, SEEK_SET ) ; r = gr_read_pal_with_gamma( fp ) ; } else if ( !strcmp( header, FPG_MAGIC ) || !strcmp( header, FNT_MAGIC ) || !strcmp( header, PAL_MAGIC ) ) { r = gr_read_pal_with_gamma( fp ) ; } else if ( memcmp( header, "\x89PNG", 4 ) == 0 ) { GRAPH * graph ; file_close( fp ); fp = NULL; graph = gr_read_png( filename ); if ( graph ) { r = pal_new( graph->format->palette ); bitmap_destroy( graph ); } } if ( r ) { // pal_use( r ); if ( old_sys_pal ) { pal_destroy( old_sys_pal ); sys_pixel_format->palette = pal_new( r ); /* pal_use( sys_pixel_format->palette ); */ palette_changed = 1 ; } } if ( fp ) file_close( fp ) ; return ( int ) r; }
int main(int argc, char** argv) { int rc; const char* port = "80"; struct engine* eng; while ((rc = getopt(argc, argv, "hp:")) != -1) { switch (rc) { case 'p': port = optarg; break; case 'h': usage(0); break; default: usage(2); break; } } if (pal_init(&pal)) return -1; eng = engine_init(&pal); rc = web_init(eng, port); if (rc) { LOG(("Web server failed to start: (%d) %s\n", rc, strerror(rc))); return rc; } LOG(("Running engine\n")); web_run(); engine_run(); web_destroy(); engine_destroy(); pal_destroy(&pal); LOG(("Exited gracefully\n")); return 0; }
/* 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 ; }
static int gr_font_loadfrom( file * fp ) { char header[8]; int bpp; int types, i, id; uint32_t y; FONT * f; PALETTE * pal = NULL; struct { int width ; int height ; int yoffset ; int fileoffset ; } oldchardata[256]; _chardata chardata[256] ; if ( font_count == MAX_FONTS ) return -1 ; /* Read the file header */ if ( !file_read( fp, header, 8 ) ) return -1; if ( memcmp( header, FNT_MAGIC, 7 ) != 0 && memcmp( header, FNX_MAGIC, 7 ) != 0 ) { return -1; } bpp = header[7]; if ( bpp == 0 ) bpp = 8; /* Read or ignore the palette */ if ( bpp == 8 && !( pal = gr_read_pal_with_gamma( fp ) ) ) return -1 ; /* Read the character data (detect old format) */ if ( header[2] == 'x' ) { if ( !file_readSint32( fp, &types ) ) { pal_destroy( pal ); return -1 ; } if ( !file_read( fp, chardata, sizeof( chardata ) ) ) { pal_destroy( pal ); return -1 ; } for ( i = 0 ; i < 256 ; i++ ) { ARRANGE_DWORD( &chardata[i].width ); ARRANGE_DWORD( &chardata[i].height ); ARRANGE_DWORD( &chardata[i].xadvance ); ARRANGE_DWORD( &chardata[i].yadvance ); ARRANGE_DWORD( &chardata[i].xoffset ); ARRANGE_DWORD( &chardata[i].yoffset ); ARRANGE_DWORD( &chardata[i].fileoffset ); } } else { if ( !file_readSint32( fp, &types ) ) { pal_destroy( pal ); return -1 ; } if ( !file_read( fp, oldchardata, sizeof( oldchardata ) ) ) { pal_destroy( pal ); return -1 ; } for ( i = 0 ; i < 256 ; i++ ) { ARRANGE_DWORD( &oldchardata[i].width ); ARRANGE_DWORD( &oldchardata[i].height ); ARRANGE_DWORD( &oldchardata[i].yoffset ); ARRANGE_DWORD( &oldchardata[i].fileoffset ); chardata[i].width = oldchardata[i].width; chardata[i].height = oldchardata[i].height; chardata[i].xoffset = 0; chardata[i].yoffset = oldchardata[i].yoffset; chardata[i].xadvance = oldchardata[i].width; chardata[i].yadvance = oldchardata[i].height + oldchardata[i].yoffset; chardata[i].fileoffset = oldchardata[i].fileoffset; } } /* Create the font */ if ( header[2] == 'x' ) id = gr_font_new( types, header[7] ) ; else id = gr_font_new( CHARSET_CP850, 8 ) ; if ( id == -1 ) { pal_destroy( pal ); return -1 ; } f = fonts[id]; if ( !f ) { gr_font_destroy( id ); pal_destroy( pal ); return -1 ; } /* Load the character bitmaps */ for ( i = 0 ; i < 256 ; i++ ) { GRAPH * gr; uint8_t * ptr; f->glyph[i].xadvance = chardata[i].xadvance ; f->glyph[i].yadvance = chardata[i].yadvance ; if ( chardata[i].fileoffset == 0 || chardata[i].width == 0 || chardata[i].height == 0 ) continue ; f->glyph[i].xoffset = chardata[i].xoffset ; f->glyph[i].yoffset = chardata[i].yoffset ; file_seek( fp, chardata[i].fileoffset, SEEK_SET ) ; f->glyph[i].bitmap = gr = bitmap_new( i, chardata[i].width, chardata[i].height, f->bpp ) ; if ( !gr ) { gr_font_destroy( id ); pal_destroy( pal ); return -1 ; } bitmap_add_cpoint( gr, 0, 0 ) ; gr->format->palette = pal; pal_use( pal ); for ( y = 0, ptr = gr->data; y < gr->height; y++, ptr += gr->pitch ) { if ( !file_read( fp, ptr, gr->widthb ) ) break ; if ( gr->format->depth == 16 ) { ARRANGE_WORDS( ptr, ( int )gr->width ); } else if ( gr->format->depth == 32 ) { ARRANGE_DWORDS( ptr, ( int )gr->width ); } } f->glyph[i].yoffset = chardata[i].yoffset ; } if ( f->glyph[32].xadvance == 0 ) f->glyph[32].xadvance = f->glyph['j'].xadvance ; pal_destroy( pal ); // Elimino la instancia inicial return id ; }