Beispiel #1
0
static int _decode_segment(PG_DISPLAY_SET *s, PES_BUFFER *p)
{
    BITBUFFER bb;
    bb_init(&bb, p->buf, p->len);

    uint8_t type   =    bb_read(&bb, 8);
    /*uint16_t len = */ bb_read(&bb, 16);

    switch (type) {
        case PGS_OBJECT:
            return _decode_ods(s, &bb, p);

        case PGS_PALETTE:
            return _decode_pds(s, &bb, p);

        case PGS_WINDOW:
            return _decode_wds(s, &bb, p);

        case PGS_PG_COMPOSITION:
            return _decode_pcs(s, &bb, p);

        case PGS_IG_COMPOSITION:
            return _decode_ics(s, &bb, p);

        case PGS_END_OF_DISPLAY:
            s->complete = 1;
            return 1;

        default:
            BD_DEBUG(DBG_DECODE | DBG_CRIT, "unknown segment type 0x%x\n", type);
            break;
    }

    return 0;
}
Beispiel #2
0
/**
 * Returns a new byte-buffer. The cursor is set to the first byte.
 *
 * @param[in]  buf      Pointer to the data buffer. The client must not free
 *                      until the byte-buffer is no longer needed.
 * @param[in]  size     Size of the data buffer in bytes.
 * @retval     NULL     Memory allocation failure.
 * @return              Pointer to the new byte-buffer. The client should call
 *                      \c bb_free(ByteBuf*) when the byte-buffer is no longer
 *                      needed.
 */
ByteBuf* bb_new(
    const unsigned char* const  buf,
    const size_t                size)
{
    ByteBuf*     bb = (ByteBuf*)malloc(sizeof(ByteBuf));

    if (bb)
        bb_init(bb, buf, size);

    return bb;
}
Beispiel #3
0
void bs_seek( BITSTREAM *bs, int64_t off, int whence)
{
    int64_t b;

    switch (whence) {
        case SEEK_CUR:
            off = bs->pos * 8 + (bs->bb.p - bs->bb.p_start) * 8 + off;
            break;
        case SEEK_END:
            off = bs->end * 8 - off;
            break;
        case SEEK_SET:
        default:
            break;
    }
    b = off >> 3;
    if (b >= bs->end)
    {
        if (BF_BUF_SIZE < bs->end) {
            bs->pos = bs->end - BF_BUF_SIZE;
            file_seek(bs->fp, BF_BUF_SIZE, SEEK_END);
        } else {
            bs->pos = 0;
            file_seek(bs->fp, 0, SEEK_SET);
        }
        bs->size = file_read(bs->fp, bs->buf, BF_BUF_SIZE);
        bb_init(&bs->bb, bs->buf, bs->size);
        bs->bb.p = bs->bb.p_end;
    } else if (b < bs->pos || b >= (bs->pos + BF_BUF_SIZE)) {
        file_seek(bs->fp, b, SEEK_SET);
        bs->pos = b;
        bs->size = file_read(bs->fp, bs->buf, BF_BUF_SIZE);
        bb_init(&bs->bb, bs->buf, bs->size);
    } else {
        b -= bs->pos;
        bs->bb.p = &bs->bb.p_start[b];
        bs->bb.i_left = 8 - (off & 0x07);
    }
}
Beispiel #4
0
void bs_init( BITSTREAM *bs, BD_FILE_H *fp )
{
    int64_t size = file_size(fp);;
    bs->fp = fp;
    bs->pos = 0;
    bs->end = (size < 0) ? 0 : size;
    bs->size = file_read(bs->fp, bs->buf, BF_BUF_SIZE);
    if (bs->size == 0 || bs->size > BF_BUF_SIZE) {
        bs->size = 0;
        bs->end = 0;
        BD_DEBUG(DBG_FILE|DBG_CRIT, "bs_init(): read error!\n");
    }
    bb_init(&bs->bb, bs->buf, bs->size);
}
Beispiel #5
0
int main()
{
	char buf[1024];
	unsigned grid[81], i;
	bb_init();
	while(fgets(buf, 1024, stdin) != 0) {
		if (strlen(buf) < 81) continue;
		for (i = 0; i < 81; ++i)
			grid[i] = buf[i] >= '1' && buf[i] <= '9'? buf[i] - '0' : 0;
		printf("%d\n", bb_solver(grid));
		//for (i = 0; i < 81; ++i) putchar(SolGrid[i] + '0');
		//putchar('\n');
	}
	return 0;
}
Beispiel #6
0
int main(int argc, char** argv)
{
  // based on settings from GIT hub
  BoundingBox test;
  Config.model.minwin = 24;
  Config.p_par_init.num_closest = 10;
  bb_init(&test,287,35,312,77);

  // same as bb_scan
  Grid * grid = new Grid(470,310, test);

  //number of overlapping Pos and Neg entries
  int p_overlap;
  int n_overlap;
  //pointer to index (points to Grid obj memory)
  int * p_idx;
  int * n_idx;

  //overlap % of the grid
  //points to Grid obj memory
  //thresholds taken from GIT hub
  const float * overlaps = grid->overlap(test, 0.6,&p_idx,&p_overlap,0.2,&n_idx,&n_overlap);

  //sort the positive data by overlap amount
  bb_sort(p_idx,overlaps,p_overlap,bb_weight_cmp_gt);
  
  //build a Hull with the first 10 items from the overlap data
  BoundingBox hull = bb_hull(grid->getGrid(),p_idx,10);

  //take the highest % item as BBP0
  //doesn't implement (lowest ID, highest % yet)
  BoundingBox BBP0 = grid->getGrid()[p_idx[0]];

  //data to compare with against MatLab TLD
  // is 0-indexed instead of 1-indexed, so all values are -1 different
  printf("Re-Alignment Box:\n\t");
  printBoundingBox(BBP0);
  printf("Initial Hull:\n\t");
  printBoundingBox(hull);
  return 0;
}
void InitNetwork()
{
	if(bb_init())
	{
		perror("Babonet Init\n");
		return;
	}
	else
	{
		printf("BaboNet Loaded\n");
	}


	//let's start the server hosting
	if(bb_serverCreate(false,1020,11207))
	{
		perror("bb_serverCreate");
	}
	else
	{
		printf("Server up n running\n");
	}
}
Beispiel #8
0
void mobj_parse_cmd(uint8_t *buf, MOBJ_CMD *cmd)
{
    BITBUFFER bb;
    bb_init(&bb, buf, 12);

    cmd->insn.op_cnt     = bb_read(&bb, 3);
    cmd->insn.grp        = bb_read(&bb, 2);
    cmd->insn.sub_grp    = bb_read(&bb, 3);

    cmd->insn.imm_op1    = bb_read(&bb, 1);
    cmd->insn.imm_op2    = bb_read(&bb, 1);
    bb_skip(&bb, 2);    /* reserved */
    cmd->insn.branch_opt = bb_read(&bb, 4);

    bb_skip(&bb, 4);    /* reserved */
    cmd->insn.cmp_opt    = bb_read(&bb, 4);

    bb_skip(&bb, 3);    /* reserved */
    cmd->insn.set_opt    = bb_read(&bb, 5);

    cmd->dst = bb_read(&bb, 32);
    cmd->src = bb_read(&bb, 32);
}
Beispiel #9
0
/* return 1 if segment is ready for decoding, 0 if more data is needed */
static int _join_segment_fragments(struct pes_buffer_s *p)
{
    uint8_t type = p->buf[0];
    unsigned id_pos = 0, id_len = 3, sd_pos = 6, data_pos = 0;

    if (p->len < 3) {
        return 1;
    }

    /* check segment type */

    if (type == PGS_OBJECT) {
        id_pos = 3;
        sd_pos = 6;
        data_pos = 7;
    }
    else if (type == PGS_IG_COMPOSITION) {
        id_pos = 8;
        sd_pos = 11;
        data_pos = 12;
    }
    else {
        return 1;
    }

    /* check sequence descriptor - is segment complete ? */

    BD_PG_SEQUENCE_DESCRIPTOR sd;
    BITBUFFER bb;
    bb_init(&bb, p->buf + sd_pos, 3);
    pg_decode_sequence_descriptor(&bb, &sd);

    if (sd.last_in_seq) {
        return 1;
    }
    if (!sd.first_in_seq) {
        return 1;
    }

    /* find next fragment(s) */

    PES_BUFFER *next;
    while (NULL != (next = _find_segment_by_idv(p->next, p->buf[0], id_pos, p->buf + id_pos, id_len))) {

        bb_init(&bb, next->buf + sd_pos, 3);
        pg_decode_sequence_descriptor(&bb, &sd);

        _join_fragments(p, next, data_pos);

        pes_buffer_remove(&p, next);

        if (sd.last_in_seq) {
            /* set first + last in sequence descriptor */
            p->buf[sd_pos] = 0xff;
            return 1;
        }
    }

    /* do not delay decoding if there are other segments queued (missing fragment ?) */
    return !!p->next;
}
Beispiel #10
0
//
// D_DoomMain
//
void D_DoomMain (void)
{
    int             p;
    char                    file[256];

    bb_init();
    bb_load_cal();

    FindResponseFile ();
	
    IdentifyVersion ();
	
    setbuf (stdout, NULL);
    modifiedgame = false;
	
    nomonsters = M_CheckParm ("-nomonsters");
    respawnparm = M_CheckParm ("-respawn");
    fastparm = M_CheckParm ("-fast");
    devparm = M_CheckParm ("-devparm");
    if (M_CheckParm ("-altdeath"))
	deathmatch = 2;
    else if (M_CheckParm ("-deathmatch"))
	deathmatch = 1;

    switch ( gamemode )
    {
      case retail:
	sprintf (title,
		 "                         "
		 "The Ultimate DOOM Startup v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
      case shareware:
	sprintf (title,
		 "                            "
		 "DOOM Shareware Startup v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
      case registered:
	sprintf (title,
		 "                            "
		 "DOOM Registered Startup v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
      case commercial:
	sprintf (title,
		 "                         "
		 "DOOM 2: Hell on Earth v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
/*FIXME
       case pack_plut:
	sprintf (title,
		 "                   "
		 "DOOM 2: Plutonia Experiment v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
      case pack_tnt:
	sprintf (title,
		 "                     "
		 "DOOM 2: TNT - Evilution v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
*/
      default:
	sprintf (title,
		 "                     "
		 "Public DOOM - v%i.%i"
		 "                           ",
		 VERSION/100,VERSION%100);
	break;
    }
    
    printf ("%s\n",title);

    if (devparm)
	printf(D_DEVSTR);
    
    if (M_CheckParm("-cdrom"))
    {
	printf(D_CDROM);
	mkdir("c:\\doomdata",0);
	strcpy (basedefault,"c:/doomdata/default.cfg");
    }	
    
    // turbo option
    if ( (p=M_CheckParm ("-turbo")) )
    {
	int     scale = 200;
	extern int forwardmove[2];
	extern int sidemove[2];
	
	if (p<myargc-1)
	    scale = atoi (myargv[p+1]);
	if (scale < 10)
	    scale = 10;
	if (scale > 400)
	    scale = 400;
	printf ("turbo scale: %i%%\n",scale);
	forwardmove[0] = forwardmove[0]*scale/100;
	forwardmove[1] = forwardmove[1]*scale/100;
	sidemove[0] = sidemove[0]*scale/100;
	sidemove[1] = sidemove[1]*scale/100;
    }
    
    // add any files specified on the command line with -file wadfile
    // to the wad list
    //
    // convenience hack to allow -wart e m to add a wad file
    // prepend a tilde to the filename so wadfile will be reloadable
    p = M_CheckParm ("-wart");
    if (p)
    {
	myargv[p][4] = 'p';     // big hack, change to -warp

	// Map name handling.
	switch (gamemode )
	{
	  case shareware:
	  case retail:
	  case registered:
	    sprintf (file,"~"DEVMAPS"E%cM%c.wad",
		     myargv[p+1][0], myargv[p+2][0]);
	    printf("Warping to Episode %s, Map %s.\n",
		   myargv[p+1],myargv[p+2]);
	    break;
	    
	  case commercial:
	  default:
	    p = atoi (myargv[p+1]);
	    if (p<10)
	      sprintf (file,"~"DEVMAPS"cdata/map0%i.wad", p);
	    else
	      sprintf (file,"~"DEVMAPS"cdata/map%i.wad", p);
	    break;
	}
	D_AddFile (file);
    }
	
    p = M_CheckParm ("-file");
    if (p)
    {
	// the parms after p are wadfile/lump names,
	// until end of parms or another - preceded parm
	modifiedgame = true;            // homebrew levels
	while (++p != myargc && myargv[p][0] != '-')
	    D_AddFile (myargv[p]);
    }

    p = M_CheckParm ("-playdemo");

    if (!p)
	p = M_CheckParm ("-timedemo");

    if (p && p < myargc-1)
    {
	sprintf (file,"%s.lmp", myargv[p+1]);
	D_AddFile (file);
	printf("Playing demo %s.lmp.\n",myargv[p+1]);
    }
    
    // get skill / episode / map from parms
    startskill = sk_medium;
    startepisode = 1;
    startmap = 1;
    autostart = false;

		
    p = M_CheckParm ("-skill");
    if (p && p < myargc-1)
    {
	startskill = myargv[p+1][0]-'1';
	autostart = true;
    }

    p = M_CheckParm ("-episode");
    if (p && p < myargc-1)
    {
	startepisode = myargv[p+1][0]-'0';
	startmap = 1;
	autostart = true;
    }
	
    p = M_CheckParm ("-timer");
    if (p && p < myargc-1 && deathmatch)
    {
	int     time;
	time = atoi(myargv[p+1]);
	printf("Levels will end after %d minute",time);
	if (time>1)
	    printf("s");
	printf(".\n");
    }

    p = M_CheckParm ("-avg");
    if (p && p < myargc-1 && deathmatch)
	printf("Austin Virtual Gaming: Levels will end after 20 minutes\n");

    p = M_CheckParm ("-warp");
    if (p && p < myargc-1)
    {
	if (gamemode == commercial)
	    startmap = atoi (myargv[p+1]);
	else
	{
	    startepisode = myargv[p+1][0]-'0';
	    startmap = myargv[p+2][0]-'0';
	}
	autostart = true;
    }
    
    // init subsystems
    printf ("V_Init: allocate screens.\n");
    V_Init ();

    printf ("M_LoadDefaults: Load system defaults.\n");
    M_LoadDefaults ();              // load before initing other systems

    printf ("Z_Init: Init zone memory allocation daemon. \n");
    Z_Init ();

    printf ("W_Init: Init WADfiles.\n");
    W_InitMultipleFiles (wadfiles);
    

    // Check for -file in shareware
    if (modifiedgame)
    {
	// These are the lumps that will be checked in IWAD,
	// if any one is not present, execution will be aborted.
	char name[23][8]=
	{
	    "e2m1","e2m2","e2m3","e2m4","e2m5","e2m6","e2m7","e2m8","e2m9",
	    "e3m1","e3m3","e3m3","e3m4","e3m5","e3m6","e3m7","e3m8","e3m9",
	    "dphoof","bfgga0","heada1","cybra1","spida1d1"
	};
	int i;
	
	if ( gamemode == shareware)
	    I_Error("\nYou cannot -file with the shareware "
		    "version. Register!");

	// Check for fake IWAD with right name,
	// but w/o all the lumps of the registered version. 
	if (gamemode == registered)
	    for (i = 0;i < 23; i++)
		if (W_CheckNumForName(name[i])<0)
		    I_Error("\nThis is not the registered version.");
    }
    
    // Iff additonal PWAD files are used, print modified banner
    if (modifiedgame)
    {
	/*m*/printf (
	    "===========================================================================\n"
	    "ATTENTION:  This version of DOOM has been modified.  If you would like to\n"
	    "get a copy of the original game, call 1-800-IDGAMES or see the readme file.\n"
	    "        You will not receive technical support for modified games.\n"
	    "                      press enter to continue\n"
	    "===========================================================================\n"
	    );
	getchar ();
    }
	

    // Check and print which version is executed.
    switch ( gamemode )
    {
      case shareware:
      case indetermined:
	printf (
	    "===========================================================================\n"
	    "                                Shareware!\n"
	    "===========================================================================\n"
	);
	break;
      case registered:
      case retail:
      case commercial:
	printf (
	    "===========================================================================\n"
	    "                 Commercial product - do not distribute!\n"
	    "         Please report software piracy to the SPA: 1-800-388-PIR8\n"
	    "===========================================================================\n"
	);
	break;
	
      default:
	// Ouch.
	break;
    }

    printf ("M_Init: Init miscellaneous info.\n");
    M_Init ();

    printf ("R_Init: Init DOOM refresh daemon - ");
    R_Init ();

    printf ("\nP_Init: Init Playloop state.\n");
    P_Init ();

    printf ("I_Init: Setting up machine state.\n");
    I_Init ();

    printf ("D_CheckNetGame: Checking network game status.\n");
    D_CheckNetGame ();

    printf ("S_Init: Setting up sound.\n");
    S_Init (snd_SfxVolume /* *8 */, snd_MusicVolume /* *8*/ );

    printf ("HU_Init: Setting up heads up display.\n");
    HU_Init ();

    printf ("ST_Init: Init status bar.\n");
    ST_Init ();

    // check for a driver that wants intermission stats
    p = M_CheckParm ("-statcopy");
    if (p && p<myargc-1)
    {
	// for statistics driver
	extern  void*	statcopy;                            

	statcopy = (void*)atoi(myargv[p+1]);
	printf ("External statistics registered.\n");
    }
    
    // start the apropriate game based on parms
    p = M_CheckParm ("-record");

    if (p && p < myargc-1)
    {
	G_RecordDemo (myargv[p+1]);
	autostart = true;
    }
	
    p = M_CheckParm ("-playdemo");
    if (p && p < myargc-1)
    {
	singledemo = true;              // quit after one demo
	G_DeferedPlayDemo (myargv[p+1]);
	D_DoomLoop ();  // never returns
    }
	
    p = M_CheckParm ("-timedemo");
    if (p && p < myargc-1)
    {
	G_TimeDemo (myargv[p+1]);
	D_DoomLoop ();  // never returns
    }
	
    p = M_CheckParm ("-loadgame");
    if (p && p < myargc-1)
    {
	if (M_CheckParm("-cdrom"))
	    sprintf(file, "c:\\doomdata\\"SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
	else
	    sprintf(file, SAVEGAMENAME"%c.dsg",myargv[p+1][0]);
	G_LoadGame (file);
    }
	

    if ( gameaction != ga_loadgame )
    {
	if (autostart || netgame)
	    G_InitNew (startskill, startepisode, startmap);
	else
	    D_StartTitle ();                // start up intro loop

    }

    D_DoomLoop ();  // never returns
}