Esempio n. 1
0
File: tray.c Progetto: guns/subtle
void
subTrayConfigure(SubTray *t)
{
  long supplied = 0;
  XSizeHints *hints = NULL;

  assert(t);

  /* Size hints */
  if(!(hints = XAllocSizeHints()))
    {
      subSharedLogError("Can't alloc memory. Exhausted?\n");
      abort();
    }

  XGetWMNormalHints(subtle->dpy, t->win, hints, &supplied);
  if(0 < supplied)
    {
      if(hints->flags & (USSize|PSize)) ///< User/program size
        t->width = MINMAX(hints->width, subtle->ph, 2 * subtle->ph);
      else if(hints->flags & PBaseSize) ///< Base size
        t->width = MINMAX(hints->base_width, subtle->ph, 2 * subtle->ph);
      else if(hints->flags & PMinSize) ///< Min size
        t->width = MINMAX(hints->min_width, subtle->ph, 2 * subtle->ph);
    }
  XFree(hints);

  subSharedLogDebug("Tray: width=%d, supplied=%ld\n", t->width, supplied);
} /* }}} */
Esempio n. 2
0
static void
adjust_min_max(
    xCharInfo  *minc,
    xCharInfo  *maxc,
    xCharInfo  *tmp)
{
#define MINMAX(field,ci) \
	if (minc->field > (ci)->field) \
	     minc->field = (ci)->field; \
	if (maxc->field < (ci)->field) \
	    maxc->field = (ci)->field;

    MINMAX(ascent, tmp);
    MINMAX(descent, tmp);
    MINMAX(leftSideBearing, tmp);
    MINMAX(rightSideBearing, tmp);
    MINMAX(characterWidth, tmp);

    if ((INT16)minc->attributes > (INT16)tmp->attributes)
	minc->attributes = tmp->attributes;
    if ((INT16)maxc->attributes < (INT16)tmp->attributes)
	maxc->attributes = tmp->attributes;

#undef	MINMAX
}
Esempio n. 3
0
void LCD_pos(Lcd *x, long row, long col)
{
	EnterCallback();
	x->lcd_row = MINMAX((short)row,0,x->rows-1);
	x->lcd_col = MINMAX((short)col,0,x->cols-1);
	ExitCallback();
}
Esempio n. 4
0
/*
 * function added for the D-Link DSC 350F - written by Mark Slemko - [email protected]
 * This function correctly adjusts the color and orientation of the image
 */
int dlink_dsc350f_postprocessing_and_flip_both (int width, int height, unsigned char* rgb) {
	unsigned char *start, *end, c;

	int whichcolor = 0;
	int lowred=255, lowgreen=255, lowblue=255;
	int hired=0, higreen=0, hiblue=0;
	
	GP_DEBUG("flipping byte order");
	
	/* flip image left/right and top/bottom (actually reverse byte order) */
	start = rgb;
	end = start + ((width * height) * 3);
	
	while (start < end) {
		c = *start;
		
		/* validation - debugging info - collect the color range info 
		 * for first half of image.
		 */
		switch (whichcolor % 3) {
			case 0: // blue
				MINMAX((int)c,lowblue,hiblue);
				break;
			case 1: // green
				MINMAX((int)c,lowgreen,higreen);
				break;
			default: // red
				MINMAX((int)c,lowred,hired);
				break;
		}
		
		/* adjust color magnitude, since it appears that the 350f only had 7 bits of color info */
		*start++ = *--end << 1;
		*end = c << 1;
		
		whichcolor++;
	}
	
	/* // could do more color processing here 
	GP_DEBUG("adjusting color");
	
	// adjust image colours
	start = rgb;
	end = start + ((width * height) * 3);
	
	while (start < end) {
		c = *start++;
	}
	*/
	
	/* show the color range of image in debug mode. */
	GP_DEBUG("\nred low = %d high = %d\ngreen low = %d high = %d\nblue low = %d high = %d\n", lowred,hired, lowgreen,higreen, lowblue,hiblue);
	return GP_OK;
}
Esempio n. 5
0
unsigned char* cubic_spline_interpolation(unsigned char *points, int count_p, int size) {
    unsigned char*items = (unsigned char*)malloc(size * sizeof(char));
    double* sd = calculate_second_derivative(points, count_p);

    int i;
    for (i = 0; i < size; i ++) {
        items[i] = (unsigned char)points[1];
    }
    for (i = 0; i < count_p - 1; i++) {
        unsigned char current_x = points[i * 2], current_y = points[i * 2 + 1], next_x = points[i * 2 + 2], next_y = points[i * 2 + 2 + 1], x;
        for (x = current_x; x < next_x; x++) {
            double t = (double)(x - current_x) / (next_x - current_x),
                   a = 1 - t,
                   b = t,
                   h = next_x - current_x,
                   y = a * current_y + b * next_y + (h * h / 6) * ((a * a * a - a) * sd[i] + (b * b * b - b) * sd[i + 1]);

            items[x] = (unsigned char)(MINMAX(round(y), 0, 255));
        }
    }
    for (i = points[count_p * 2 - 2]; i<size; i++){
        items[i] = points[count_p * 2 - 1];
    }
    free(sd);
    return items;
}
Esempio n. 6
0
void LCD_posToRC(Lcd *x, Point pt)
{
	Rect	r;
	short		hor,ver;

	r = x->lcd_box.b_rect;
	
	x->lcd_row = (short)(ceil(1.0*(pt.v-r.top-(2*BORDER_HEIGHT))/x->f_height))-1;
	x->lcd_col = (short)(ceil(1.0*(pt.h-r.left-(2*BORDER_WIDTH))/x->f_width));

	x->lcd_row = MINMAX(x->lcd_row,0,x->rows-1);
	x->lcd_col = MINMAX(x->lcd_col,0,x->cols-1);
	
	x->lcd_where.h = pt.h-r.left;
	x->lcd_where.v = pt.v-r.top;
}
Esempio n. 7
0
CBaLog* CBaLog::commonCreate(std::string name, std::string path, EBaLogPrio prioFilt,
      EBaLogOut out, int32_t maxFileSizeB, uint16_t maxNoFiles, uint16_t maxBufLength,
      uint16_t fileCnt, int32_t fileSizeB, bool fromCfg, bool disableThread)  {

   if (name.empty() || !init(disableThread)) {
      return 0;
   }

   // Check if already exists
   auto logger = sLoggers.find(name);
   if (logger != sLoggers.end()) {
      logger->second->mOpenCnt++;
      return logger->second;
   }

   // Set default
   if (path == "") {
      path = LOGDIR;
   }

   // Limit the priorities
   prioFilt = MINMAX(prioFilt, eBaLogPrio_Trace, eBaLogPrio_UpsCrash);

   // //////////////// Create //////////////
   // If windows, remove the trailing '\' because it generates problems with the
   // when the path is saved with the IniParser
#ifdef __WIN32
   if (path.back() == '\\') {
      path.resize(path.length() - 1);
   }
#endif

   CBaLog *p = new CBaLog(name, path, prioFilt, out, maxFileSizeB, maxNoFiles, maxBufLength, fileCnt,
         fileSizeB);
   if (!p) {
      SysLog(TAG, __LINE__, "Could not create logger");
      return 0;
   }
   // //////////////// Create //////////////

   p->mFullPath = BaPath::Concatenate(p->mPath, p->mName) + ".log";
   std::ios_base::openmode om = std::ios_base::binary | std::ios_base::out;
   if (fromCfg) {
      om |= std::ios_base::app;
   }

   // //////////////// Open ////////////////
   p->mLog.open(p->mFullPath, om);
   if (p->mLog.fail()) {
      BASYSLOG(TAG, "Cannot open log file: %s", p->mFullPath.c_str());
      delete p;
      return 0;
   }
   // //////////////// Open ////////////////

   sLoggers[p->mName] = p;
   return p;
}
Esempio n. 8
0
int CGuildManager::GetRanking(DWORD dwGID)
{
	itertype(map_kLadderPointRankingByGID) it = map_kLadderPointRankingByGID.find(dwGID);

	if (it == map_kLadderPointRankingByGID.end())
		return GUILD_RANK_MAX_NUM;

	return MINMAX(0, it->second, GUILD_RANK_MAX_NUM);
}
void input2darray_to_matches( image_t *match_x, image_t *match_y, image_t *match_z, const mxArray *p){
    const int nmatch = mxGetM(p);
    const int w = match_x->width, h = match_x->height, s = match_x->stride;
    float *data = (float*) mxGetData(p);
    image_erase(match_x); image_erase(match_y); image_erase(match_z);
    for( int i=0 ; i<nmatch ; i++){
        float x1 = data[0*nmatch+i], y1 = data[1*nmatch+i], x2 = data[2*nmatch+i], y2 = data[3*nmatch+i];
        if( x1<0 || y1<0 || x2<0 || y2<0 || x1>=w || y1>=h || x2>=w || y2>=h){
            fprintf(stderr, "Warning: match out of bound: %f %f -> %f %f\n", x1, y1, x2, y2);
            x1 = MINMAX(x1,w);
            x2 = MINMAX(x2,w);
            y1 = MINMAX(y1,h);
            y2 = MINMAX(y2,h);
        }
        int pos = (int) (y1*s+x1);
        match_x->data[ pos ] = x2-x1;
        match_y->data[ pos ] = y2-y1;
        match_z->data[ pos ] = 1.0f;       
    }
}
Esempio n. 10
0
void CItem::SetAccessorySocketGrade(int iGrade) 
{ 
	SetSocket(0, MINMAX(0, iGrade, GetAccessorySocketMaxGrade())); 

	int iDownTime = aiAccessorySocketDegradeTime[GetAccessorySocketGrade()];

	//if (test_server)
	//	iDownTime /= 60;

	SetAccessorySocketDownGradeTime(iDownTime);
}
Esempio n. 11
0
void
fb_clear(int x, int y, int w, int h, int q)
{
	uint8_t *p;
	int i, j, k, xend, yend;

	if (!fb.active)
		return;

	x = MINMAX(x, 0, FB_WIDTH);
	y = MINMAX(y, 0, FB_HEIGHT);
	xend = MINMAX(x + w, 0, FB_WIDTH);
	yend = MINMAX(y + h , 0, FB_HEIGHT);

	p = (uint8_t *)fb.fb_addr + x + y * FB_LINEBYTES;

	j = xend - x;
	k = j + FB_LINEBYTES - w;
	for (i = y; i < yend; i++, p+= k)
		memset(p, q, j);
}
Esempio n. 12
0
	int horse_get_stamina_pct(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		int pct = MINMAX(0, ch->GetHorseStamina() * 100 / ch->GetHorseMaxStamina(), 100);
		sys_log(1, "horse.get_stamina_pct %d", pct);

		if (ch->GetHorseLevel())
			lua_pushnumber(L, pct);
		else
			lua_pushnumber(L, 0);

		return 1;
	}
Esempio n. 13
0
	int horse_set_level(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();

		if (!lua_isnumber(L, 1))
			return 0;

		int newlevel = MINMAX(0, (int)lua_tonumber(L, 1), HORSE_MAX_LEVEL);
		ch->SetHorseLevel(newlevel);
		ch->ComputePoints();
		ch->SkillLevelPacket();
		return 0;
	}
Esempio n. 14
0
void LCD_doascii(Lcd *x, Symbol *s, short argc, Atom *argv)
{
	short i;
	char	stng[256];
	
	EnterCallback();
	
	stng[1] = '\0';
	for (i=0;i<argc;i++) {

		switch(argv[i].a_type) {
			case A_LONG:
				switch (stng[0] = (char)argv[i].a_w.w_long) {
					case BACKSPACE:
						stng[0] = 32;
						x->lcd_col--;
						x->lcd_col = MINMAX(x->lcd_col,0,x->cols-1);
						LCD_drawTxt(x,stng);
						x->lcd_col--;
						x->lcd_col = MINMAX(x->lcd_col,0,x->cols-1);
						break;
					case CR:
						x->lcd_row++;
						x->lcd_row = MINMAX(x->lcd_row,0,x->rows-1);
						x->lcd_col = 0;
						break;
					case LEFT_ARROW:
						x->lcd_col--;
						x->lcd_col = MINMAX(x->lcd_col,0,x->cols-1);
						break;
					case RIGHT_ARROW:
						x->lcd_col++;
						x->lcd_col = MINMAX(x->lcd_col,0,x->cols-1);
						break;
					case UP_ARROW:
						x->lcd_row--;
						x->lcd_row = MINMAX(x->lcd_row,0,x->rows-1);
						break;
					case DOWN_ARROW:
						x->lcd_row++;
						x->lcd_row = MINMAX(x->lcd_row,0,x->rows-1);
						break;
					default:
						LCD_drawTxt(x,stng);
						break;
				}						
				break;
			case A_SYM:
			case A_FLOAT:
				break;
		}
	}
	ExitCallback();
}
Esempio n. 15
0
/**
 * gts_bbox_point_distance2:
 * @bb: a #GtsBBox.
 * @p: a #GtsPoint.
 * @min: a pointer on a gdouble.
 * @max: a pointer on a gdouble.
 * 
 * Sets @min and @max to lower and upper bounds for the square of the
 * Euclidean distance between the object contained in @bb and @p. For these
 * bounds to make any sense the bounding box must be "tight" i.e. each of the
 * 6 faces of the box must at least be touched by one point of the bounded
 * object.
 */
void gts_bbox_point_distance2 (GtsBBox * bb, GtsPoint * p,
			       gdouble * min, gdouble * max)
{
  gdouble x1, y1, z1, x2, y2, z2, x, y, z;
  gdouble dmin, dmax, xd1, xd2, yd1, yd2, zd1, zd2;
  gdouble mx, Mx, my, My, mz, Mz;
    
  g_return_if_fail (bb != NULL);
  g_return_if_fail (p != NULL);
  g_return_if_fail (min != NULL);
  g_return_if_fail (max != NULL);

  x1 = bb->x1; y1 = bb->y1; z1 = bb->z1; 
  x2 = bb->x2; y2 = bb->y2; z2 = bb->z2;
  x = p->x; y = p->y; z = p->z;

  xd1 = (x1 - x)*(x1 - x);
  xd2 = (x - x2)*(x - x2);
  yd1 = (y1 - y)*(y1 - y);
  yd2 = (y - y2)*(y - y2);
  zd1 = (z1 - z)*(z1 - z);
  zd2 = (z - z2)*(z - z2);
  
  dmin = x < x1 ? xd1 : x > x2 ? xd2 : 0.0;
  dmin += y < y1 ? yd1 : y > y2 ? yd2 : 0.0;
  dmin += z < z1 ? zd1 : z > z2 ? zd2 : 0.0;

  MINMAX (xd1, xd2, mx, Mx);
  MINMAX (yd1, yd2, my, My);
  MINMAX (zd1, zd2, mz, Mz);
  
  dmax = mx + My + Mz;
  dmax = MIN (dmax, Mx + my + Mz);
  dmax = MIN (dmax, Mx + My + mz);
  
  *min = dmin;
  *max = dmax;
}
Esempio n. 16
0
/* 19595  38470   7471
  -11071 -21736  32807
   32756 -27429  -5327 */
static int
rfx_encode_rgb_to_ycbcr(uint8 *y_r_buf, uint8 *cb_g_buf, uint8 *cr_b_buf)
{
    int i;
    sint32 r, g, b;
    sint32 y, cb, cr;

    for (i = 0; i < 4096; i++)
    {
        r = y_r_buf[i];
        g = cb_g_buf[i];
        b = cr_b_buf[i];

        y =  (r *  19595 + g *  38470 + b *   7471) >> 16;
        cb = (r * -11071 + g * -21736 + b *  32807) >> 16;
        cr = (r *  32756 + g * -27429 + b *  -5327) >> 16;

        y_r_buf[i] = MINMAX(y, 0, 255);
        cb_g_buf[i] = MINMAX(cb + 128, 0, 255);
        cr_b_buf[i] = MINMAX(cr + 128, 0, 255);

    }
    return 0;
}
Esempio n. 17
0
int normalize(int width, int height, unsigned char* rgb)
{
	int
		x,y,
		red_min=255, red_max=0, 
		blue_min=255, blue_max=0, 
		green_min=255, green_max=0;
	double
		min, max, amplify; 

	/* determine min and max per color... */

	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			MINMAX( RED(rgb,x,y,width), red_min,   red_max  );
			MINMAX( GREEN(rgb,x,y,width), green_min, green_max);
			MINMAX( BLUE(rgb,x,y,width), blue_min,  blue_max );
		}
	}

	/* determine min and max per color... */

	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			MINMAX( RED(rgb,x,y,width), red_min,   red_max  );
			MINMAX( GREEN(rgb,x,y,width), green_min, green_max);
			MINMAX( BLUE(rgb,x,y,width), blue_min,  blue_max );
		}
	}

	/* Normalize brightness ... */

	max = MAX( MAX( red_max, green_max ), blue_max);
	min = MIN( MIN( red_min, green_min ), blue_min);
	amplify = 255.0/(max-min);


	printf("min=%f max=%f amplify=%f\n",min,max,amplify);
	if (max == 255)
		printf("max is already max'ed at 255. Exiting from normalize()\n");
		return 0;



	for( y=0; y<height; y++){
		for( x=0; x<width; x++ ){
			RED(rgb,x,y,width)= MIN(amplify*(double)(RED(rgb,x,y,width)-min),255);
			GREEN(rgb,x,y,width)= MIN(amplify*(double)(GREEN(rgb,x,y,width)-min),255);
			BLUE(rgb,x,y,width)= MIN(amplify*(double)(BLUE(rgb,x,y,width)-min),255);
		}
	}

	return 0;
}
Esempio n. 18
0
bool CBaLog::log(EBaLogPrio prio, const char* tag, const char* msg) {
   if (!msg) {
      return false;
   }

   // Generate time stamp with priority
   // Get the prio
   prio = MINMAX(prio, eBaLogPrio_Trace, eBaLogPrio_UpsCrash);


   // Priority filter. Only log things equal or higher prio than the filter
   if (prio < mPrioFilt) {
      return true;
   }

   // Get the tag
   reTag(tag, mTag);

   // Put everything together
   BaCoreGetTStamp(&mTs);
   std::string entry(BaCoreTStampToStr(&mTs, mStrTStamp));
   entry.append( "|" + sPrioTochar[prio] + "|" + mTag + "| " + msg);


   // ////////////////// Write to buffer if it is not full /////////////////////
   if (mOut & eBaLogOut_Log) {
      if (!mMaxBufLength || mBuf.size() < mMaxBufLength) {
         mBuf.push_back(entry);
      } else {
         // todo: else? log error?
         return false;
      }
   }
   // //////////////////////////////////////////////////////////////////////////


   // Write to console if desired
   if (mOut & eBaLogOut_Console) {
      std::cout << entry << std::endl;
   }

   return true;
}
Esempio n. 19
0
void PIDzp_Update(float dt)
{
  float tempz = 0.003f;
  _ERRzp=ERRzp;
  ERRzp=CONSTRAIN(rx_value[5]-height, MAX_DELTA_Z);
  ERRzpI=CONSTRAIN(ERRzp*dt+ERRzpI, I_H_MAX);
  RateZ=CONSTRAIN((ERRzp-_ERRzp)/dt,MAX_Z_RATE);

  P_Temp=PID_Value[12]*ERRzp;
  I_Temp=PID_Value[13]*ERRzpI;
  D_Temp=CONSTRAIN(PID_Value[14]*RateZ,PG_MAX);

  PIDzp=(int)MINMAX((P_Temp+I_Temp+D_Temp)+100,100,PID_H_OUT_MAX);
  /*myprintf("ErrZ:%f\tErrZI:%f\tRateZ:%f\t\r\n",ERRzp,ERRzpI,RateZ);*/
  /*myprintf("P:%f\tI:%f\tD:%f\t\r\n",P_Temp,I_Temp,D_Temp);*/
  /*myprintf("PID:%f\r\n",PIDzp);*/
  throttle=tempz*PIDzp;
  avg_height = (height + _height) * 0.5f;
  _height = height;
}
Esempio n. 20
0
void
fb_copy(int x0, int y0, int x1, int y1, int w, int h)
{
	int x1end, y1end, i, j, k;
	uint8_t *p, *q;

	if (!fb.active)
		return;

	x0 = MINMAX(x0, 0, FB_WIDTH);
	y0 = MINMAX(y0, 0, FB_HEIGHT);
	x1 = MINMAX(x1, 0, FB_WIDTH);
	y1 = MINMAX(y1, 0, FB_HEIGHT);
	x1end = MINMAX(x1 + w, 0, FB_WIDTH);
	y1end = MINMAX(y1 + h, 0, FB_HEIGHT);

	p = fb.fb_addr + x1 + y1 * FB_LINEBYTES;
	q = fb.fb_addr + x0 + y0 * FB_LINEBYTES;

	j = x1end - x1;
	k = j + FB_LINEBYTES - w;
	for (i = y1; i < y1end; i++, p += k, q += k)
		memmove(p, q, j);
}
Esempio n. 21
0
int CItem::GetAccessorySocketGrade()
{
   	return MINMAX(0, GetSocket(0), GetAccessorySocketMaxGrade()); 
}
Esempio n. 22
0
void CItem::SetAccessorySocketMaxGrade(int iMaxGrade) 
{ 
	SetSocket(1, MINMAX(0, iMaxGrade, ITEM_ACCESSORY_SOCKET_MAX_NUM)); 
}
Esempio n. 23
0
int fastmath_tan(int angle)
{
  int s = fastmath_sin(angle);
  int c = fastmath_cos(angle);
  return (c) ? MINMAX((s << TRI_SHIFT)/c, MAX_TAN_VALUE) : ((s>0) ? MAX_TAN_VALUE : -MAX_TAN_VALUE);
}
Esempio n. 24
0
/* ------------------------------------------------------------------------- */
pstatus_t general_RGBToYCbCr_16s16s_P3P3(
	const INT16 *pSrc[3],  INT32 srcStep,
	INT16 *pDst[3],  INT32 dstStep,
	const prim_size_t *roi)	/* region of interest */
{
	/* The encoded YCbCr coefficients are represented as 11.5 fixed-point
	 * numbers:
	 *
	 * 1 sign bit + 10 integer bits + 5 fractional bits
	 *
	 * However only 7 integer bits will be actually used since the value
	 * range is [-128.0, 127.0].  In other words, the encoded coefficients
	 * is scaled by << 5 when interpreted as INT16.
	 * It will be scaled down to original during the quantization phase.
	 */
	const INT16 *rptr = pSrc[0];
	const INT16 *gptr = pSrc[1];
	const INT16 *bptr = pSrc[2];
	INT16 *yptr  = pDst[0];
	INT16 *cbptr = pDst[1];
	INT16 *crptr = pDst[2];
	int srcbump = (srcStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16);
	int dstbump = (dstStep - (roi->width * sizeof(UINT16))) / sizeof(UINT16);
	int y;

	for (y=0; y<roi->height; y++)
	{
		int x;
		for (x=0; x<roi->width; ++x)
		{
			/* INT32 is used intentionally because we calculate with
			 * shifted factors!
			 */
			INT32 r = (INT32) (*rptr++);
			INT32 g = (INT32) (*gptr++);
			INT32 b = (INT32) (*bptr++);

			/* We scale the factors by << 15 into 32-bit integers in order
			 * to avoid slower floating point multiplications.  Since the
			 * terms need to be scaled by << 5 we simply scale the final
			 * sum by >> 10
			 *
			 * Y:  0.299000 << 15 = 9798,  0.587000 << 15 = 19235, 
			 *     0.114000 << 15 = 3735
			 * Cb: 0.168935 << 15 = 5535,  0.331665 << 15 = 10868, 
			 *     0.500590 << 15 = 16403
			 * Cr: 0.499813 << 15 = 16377, 0.418531 << 15 = 13714,
			 *     0.081282 << 15 = 2663
			 */
			INT32 y  = (r *  9798 + g *  19235 + b *  3735) >> 10;
			INT32 cb = (r * -5535 + g * -10868 + b * 16403) >> 10;
			INT32 cr = (r * 16377 + g * -13714 + b * -2663) >> 10;

			*yptr++  = (INT16) MINMAX(y - 4096, -4096, 4095);
			*cbptr++ = (INT16) MINMAX(cb, -4096, 4095);
			*crptr++ = (INT16) MINMAX(cr, -4096, 4095);
		}
		yptr  += srcbump;
		cbptr += srcbump;
		crptr += srcbump;
		rptr += dstbump;
		gptr += dstbump;
		bptr += dstbump;
	}
	return PRIMITIVES_SUCCESS;
}
Esempio n. 25
0
/*****************************************************************************
*
*   functionName:   wsockClientDecodeData
*   Description:
*
*   Comments:
*
******************************************************************************/
int wsockClientDecodeData( InterSenseTrackerType *tracker )
{
    unsigned i;
    unsigned char cSum;
    unsigned char *buf;

    ItComSensorStateType *station;
    udpStationPacketType  stationData;
    udpCameraPacketType   cameraData;


    buf = tracker->wsock.data.cmdbuf;

    if(*buf++ != UDP_START_BYTE) return FALSE;

    switch(*buf--)
    {
    case UDP_STATION_DATA:

        memcpy((void *)&stationData, buf, sizeof(udpStationPacketType));
        buf = (unsigned char *) &stationData + 4;

        for(cSum = 0, i = 0; i < sizeof(udpStationPacketType) - 4; i++)
        {
            cSum += *buf++;
        }
        if(stationData.CheckSum != cSum)
        {
           return FALSE;
        }
        if(stationData.StationNum !=
            MINMAX(1, stationData.StationNum, MAX_NUM_STATIONS)) return FALSE;

        station = &tracker->station[stationData.StationNum - 1];

        station->Orientation[0] = byteOrderFloat((char *)&stationData.Yaw);
        station->Orientation[1] = byteOrderFloat((char *)&stationData.Pitch);
        station->Orientation[2] = byteOrderFloat((char *)&stationData.Roll);
        station->Position[0]    = byteOrderFloat((char *)&stationData.PosX);
        station->Position[1]    = byteOrderFloat((char *)&stationData.PosY);
        station->Position[2]    = byteOrderFloat((char *)&stationData.PosZ);
        station->Status         = stationData.Status;
        station->TimeStamp      = byteOrderFloat((char *)&stationData.TimeStamp);

        tracker->hardware = ISD_PRECISION_SERIES;
        tracker->state.hardwareVersion = stationData.Model;
        tracker->station[stationData.StationNum - 1].state = ON;
        tracker->station[stationData.StationNum - 1].NewData = TRUE;

        for(i = 0; i < UDP_MAX_ANALOG_CHANNELS; i++)
        {
            station->AnalogData[i] = (short) stationData.AnalogData[i];
        }
        for(i = 0; i < MAX_NUM_BUTTONS; i++)
        {
            if(stationData.ButtonState & (1 << i))
                station->ButtonState[i] = 1;
            else
                station->ButtonState[i] = 0;
        }

        break;

    case UDP_CAMERA_DATA:

        memcpy((void *)&cameraData, buf, sizeof(udpCameraPacketType));
        buf = (unsigned char *) &cameraData + 4;

        for(cSum = 0, i = 0; i < sizeof(udpCameraPacketType) - 4; i++)
        {
            cSum += *buf++;
        }
        if(cameraData.CheckSum != cSum) return FALSE;

        if(cameraData.StationNum !=
            MINMAX(1, cameraData.StationNum, MAX_NUM_STATIONS)) return FALSE;

        station = &tracker->station[cameraData.StationNum - 1];

        station->Timecode         = byteOrderULong((char *)&cameraData.Timecode);
        station->ApetureEncoder   = byteOrderLong ((char *)&cameraData.ApetureEncoder);
        station->FocusEncoder     = byteOrderLong ((char *)&cameraData.FocusEncoder);
        station->ZoomEncoder      = byteOrderLong ((char *)&cameraData.ZoomEncoder);
        station->TimeCodeUserBits = byteOrderULong((char *)&cameraData.TimeCodeUserBits);
        station->Apeture          = byteOrderFloat((char *)&cameraData.Apeture);
        station->Focus            = byteOrderFloat((char *)&cameraData.Focus);
        station->FOV              = byteOrderFloat((char *)&cameraData.FOV);
        station->NodalPoint       = byteOrderFloat((char *)&cameraData.NodalPoint);

        break;

    default:
        return FALSE;
    }

    return TRUE;
}
Esempio n. 26
0
int do_gsc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	const char *model = getenv("model");

	i2c_set_bus_num(0);
	read_hwmon("Temp",     GSC_HWMON_TEMP, 2, 0, 9000);
	read_hwmon("VIN",      GSC_HWMON_VIN, 3, 8000, 60000);
	read_hwmon("VBATT",    GSC_HWMON_VBATT, 3, 1800, 3500);
	read_hwmon("VDD_3P3",  GSC_HWMON_VDD_3P3, 3, MINMAX(3300, 10));
	read_hwmon("VDD_HIGH", GSC_HWMON_VDD_HIGH, 3, MINMAX(3000, 10));
	read_hwmon("VDD_DDR",  GSC_HWMON_VDD_DDR, 3, MINMAX(1500, 10));
	read_hwmon("VDD_5P0",  GSC_HWMON_VDD_5P0, 3, MINMAX(5000, 10));
	read_hwmon("VDD_2P5",  GSC_HWMON_VDD_2P5, 3, MINMAX(2500, 10));
	read_hwmon("VDD_1P8",  GSC_HWMON_VDD_1P8, 3, MINMAX(1800, 10));

	switch (model[3]) {
	case '1': /* GW51xx */
		read_hwmon("VDD_CORE", GSC_HWMON_VDD_CORE, 3, MINMAX(1175, 10));
		read_hwmon("VDD_SOC",  GSC_HWMON_VDD_SOC, 3, MINMAX(1175, 10));
		break;
	case '2': /* GW52xx */
	case '3': /* GW53xx */
		read_hwmon("VDD_CORE", GSC_HWMON_VDD_CORE, 3, MINMAX(1175, 10));
		read_hwmon("VDD_SOC",  GSC_HWMON_VDD_SOC, 3, MINMAX(1175, 10));
		read_hwmon("VDD_1P0",  GSC_HWMON_VDD_1P0, 3, MINMAX(1000, 10));
		break;
	case '4': /* GW54xx */
		read_hwmon("VDD_CORE", GSC_HWMON_VDD_CORE, 3, MINMAX(1375, 10));
		read_hwmon("VDD_SOC",  GSC_HWMON_VDD_SOC, 3, MINMAX(1375, 10));
		read_hwmon("VDD_1P0",  GSC_HWMON_VDD_1P0, 3, MINMAX(1000, 10));
		break;
	case '5': /* GW55xx */
		read_hwmon("VDD_CORE", GSC_HWMON_VDD_CORE, 3, MINMAX(1175, 10));
		read_hwmon("VDD_SOC",  GSC_HWMON_VDD_SOC, 3, MINMAX(1175, 10));
		break;
	}
	return 0;
}
bool ITEM_MANAGER::ReadMonsterDropItemGroup(const char * c_pszFileName)
{
	CTextFileLoader loader;

	if (!loader.Load(c_pszFileName))
		return false;

	for (DWORD i = 0; i < loader.GetChildNodeCount(); ++i)
	{
		std::string stName("");

		loader.GetCurrentNodeName(&stName);

		if (strncmp (stName.c_str(), "kr_", 3) == 0)
		{
			if (LC_IsYMIR())
			{
				stName.assign(stName, 3, stName.size() - 3);
			}
			else
			{
				continue;
			}
		}

		loader.SetChildNode(i);

		int iMobVnum = 0;
		int iKillDrop = 0;
		int iLevelLimit = 0;

		std::string strType("");

		if (!loader.GetTokenString("type", &strType))
		{
			sys_err("ReadMonsterDropItemGroup : Syntax error %s : no type (kill|drop), node %s", c_pszFileName, stName.c_str());
			loader.SetParentNode();
			return false;
		}

		if (!loader.GetTokenInteger("mob", &iMobVnum))
		{
			sys_err("ReadMonsterDropItemGroup : Syntax error %s : no mob vnum, node %s", c_pszFileName, stName.c_str());
			loader.SetParentNode();
			return false;
		}

		if (strType == "kill")
		{
			if (!loader.GetTokenInteger("kill_drop", &iKillDrop))
			{
				sys_err("ReadMonsterDropItemGroup : Syntax error %s : no kill drop count, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return false;
			}
		}
		else
		{
			iKillDrop = 1;
		}

		if ( strType == "limit" )
		{
			if ( !loader.GetTokenInteger("level_limit", &iLevelLimit) )
			{
				sys_err("ReadmonsterDropItemGroup : Syntax error %s : no level_limit, node %s", c_pszFileName, stName.c_str());
				loader.SetParentNode();
				return false;
			}
		}
		else
		{
			iLevelLimit = 0;
		}

		sys_log(0,"MOB_ITEM_GROUP %s [%s] %d %d", stName.c_str(), strType.c_str(), iMobVnum, iKillDrop);

		if (iKillDrop == 0)
		{
			loader.SetParentNode();
			continue;
		}

		TTokenVector* pTok = NULL;

		if (strType == "kill")
		{
			CMobItemGroup * pkGroup = M2_NEW CMobItemGroup(iMobVnum, iKillDrop, stName);

			for (int k = 1; k < 256; ++k)
			{
				char buf[4];
				snprintf(buf, sizeof(buf), "%d", k);

				if (loader.GetTokenVector(buf, &pTok))
				{
					//sys_log(1, "               %s %s", pTok->at(0).c_str(), pTok->at(1).c_str());
					std::string& name = pTok->at(0);
					DWORD dwVnum = 0;

					if (!GetVnumByOriginalName(name.c_str(), dwVnum))
					{
						str_to_number(dwVnum, name.c_str());
						if (!ITEM_MANAGER::instance().GetTable(dwVnum))
						{
							sys_err("ReadMonsterDropItemGroup : there is no item %s : node %s : vnum %d", name.c_str(), stName.c_str(), dwVnum);
							return false;
						}
					}

					int iCount = 0;
					str_to_number(iCount, pTok->at(1).c_str());

					if (iCount<1)
					{
						sys_err("ReadMonsterDropItemGroup : there is no count for item %s : node %s : vnum %d, count %d", name.c_str(), stName.c_str(), dwVnum, iCount);
						return false;
					}

					int iPartPct = 0;
					str_to_number(iPartPct, pTok->at(2).c_str());

					if (iPartPct == 0)
					{
						sys_err("ReadMonsterDropItemGroup : there is no drop percent for item %s : node %s : vnum %d, count %d, pct %d", name.c_str(), stName.c_str(), iPartPct);
						return false;
					}

					int iRarePct = 0;
					str_to_number(iRarePct, pTok->at(3).c_str());
					iRarePct = MINMAX(0, iRarePct, 100);

					sys_log(0,"        %s count %d rare %d", name.c_str(), iCount, iRarePct);
					pkGroup->AddItem(dwVnum, iCount, iPartPct, iRarePct);
					continue;
				}

				break;
			}
			m_map_pkMobItemGroup.insert(std::map<DWORD, CMobItemGroup*>::value_type(iMobVnum, pkGroup));

		}
		else if (strType == "drop")
		{
			CDropItemGroup* pkGroup;
			bool bNew = true;
			itertype(m_map_pkDropItemGroup) it = m_map_pkDropItemGroup.find (iMobVnum);
			if (it == m_map_pkDropItemGroup.end())
			{
				pkGroup = M2_NEW CDropItemGroup(0, iMobVnum, stName);
			}
			else
			{
				bNew = false;
				CDropItemGroup* pkGroup = it->second;
			}

			for (int k = 1; k < 256; ++k)
			{
				char buf[4];
				snprintf(buf, sizeof(buf), "%d", k);

				if (loader.GetTokenVector(buf, &pTok))
				{
					std::string& name = pTok->at(0);
					DWORD dwVnum = 0;

					if (!GetVnumByOriginalName(name.c_str(), dwVnum))
					{
						str_to_number(dwVnum, name.c_str());
						if (!ITEM_MANAGER::instance().GetTable(dwVnum))
						{
							sys_err("ReadDropItemGroup : there is no item %s : node %s", name.c_str(), stName.c_str());
							M2_DELETE(pkGroup);

							return false;
						}
					}

					int iCount = 0;
					str_to_number(iCount, pTok->at(1).c_str());

					if (iCount < 1)
					{
						sys_err("ReadMonsterDropItemGroup : there is no count for item %s : node %s", name.c_str(), stName.c_str());
						M2_DELETE(pkGroup);

						return false;
					}

					float fPercent = atof(pTok->at(2).c_str());

					DWORD dwPct = (DWORD)(10000.0f * fPercent);

					sys_log(0,"        name %s pct %d count %d", name.c_str(), dwPct, iCount);
					pkGroup->AddItem(dwVnum, dwPct, iCount);

					continue;
				}

				break;
			}
			if (bNew)
				m_map_pkDropItemGroup.insert(std::map<DWORD, CDropItemGroup*>::value_type(iMobVnum, pkGroup));

		}
		else if ( strType == "limit" )
		{
			CLevelItemGroup* pkLevelItemGroup = M2_NEW CLevelItemGroup(iLevelLimit);

			for ( int k=1; k < 256; k++ )
			{
				char buf[4];
				snprintf(buf, sizeof(buf), "%d", k);

				if ( loader.GetTokenVector(buf, &pTok) )
				{
					std::string& name = pTok->at(0);
					DWORD dwItemVnum = 0;

					if (false == GetVnumByOriginalName(name.c_str(), dwItemVnum))
					{
						str_to_number(dwItemVnum, name.c_str());
						if ( !ITEM_MANAGER::instance().GetTable(dwItemVnum) )
						{
							M2_DELETE(pkLevelItemGroup);
							return false;
						}
					}

					int iCount = 0;
					str_to_number(iCount, pTok->at(1).c_str());

					if (iCount < 1)
					{
						M2_DELETE(pkLevelItemGroup);
						return false;
					}

					float fPct = atof(pTok->at(2).c_str());
					DWORD dwPct = (DWORD)(10000.0f * fPct);

					pkLevelItemGroup->AddItem(dwItemVnum, dwPct, iCount);

					continue;
				}

				break;
			}

			m_map_pkLevelItemGroup.insert(std::map<DWORD, CLevelItemGroup*>::value_type(iMobVnum, pkLevelItemGroup));
		}
		else if (strType == "thiefgloves")
		{
			CBuyerThiefGlovesItemGroup* pkGroup = M2_NEW CBuyerThiefGlovesItemGroup(0, iMobVnum, stName);

			for (int k = 1; k < 256; ++k)
			{
				char buf[4];
				snprintf(buf, sizeof(buf), "%d", k);

				if (loader.GetTokenVector(buf, &pTok))
				{
					std::string& name = pTok->at(0);
					DWORD dwVnum = 0;

					if (!GetVnumByOriginalName(name.c_str(), dwVnum))
					{
						str_to_number(dwVnum, name.c_str());
						if (!ITEM_MANAGER::instance().GetTable(dwVnum))
						{
							sys_err("ReadDropItemGroup : there is no item %s : node %s", name.c_str(), stName.c_str());
							M2_DELETE(pkGroup);

							return false;
						}
					}

					int iCount = 0;
					str_to_number(iCount, pTok->at(1).c_str());

					if (iCount < 1)
					{
						sys_err("ReadMonsterDropItemGroup : there is no count for item %s : node %s", name.c_str(), stName.c_str());
						M2_DELETE(pkGroup);

						return false;
					}

					float fPercent = atof(pTok->at(2).c_str());

					DWORD dwPct = (DWORD)(10000.0f * fPercent);

					sys_log(0,"        name %s pct %d count %d", name.c_str(), dwPct, iCount);
					pkGroup->AddItem(dwVnum, dwPct, iCount);

					continue;
				}

				break;
			}

			m_map_pkGloveItemGroup.insert(std::map<DWORD, CBuyerThiefGlovesItemGroup*>::value_type(iMobVnum, pkGroup));
		}
		else
		{
			sys_err("ReadMonsterDropItemGroup : Syntax error %s : invalid type %s (kill|drop), node %s", c_pszFileName, strType.c_str(), stName.c_str());
			loader.SetParentNode();
			return false;
		}

		loader.SetParentNode();
	}

	return true;
}
Esempio n. 28
0
int CItem::GetAccessorySocketMaxGrade()
{
   	return MINMAX(0, GetSocket(1), ITEM_ACCESSORY_SOCKET_MAX_NUM);
}
Esempio n. 29
0
int CItem::GetAccessorySocketDownGradeTime()
{
	return MINMAX(0, GetSocket(2), aiAccessorySocketDegradeTime[GetAccessorySocketGrade()]);
}
Esempio n. 30
0
void
ssesort16d(double keys[16])
{
    __m128d t, temp[8];

    // MINMAX(a, b): [a, b] := [min(a, b), max(a, b)]
#   define MINMAX(a, b) \
        temp[a] = _mm_min_pd(t = LOAD(a), LOAD(b)), \
        temp[b] = _mm_max_pd(t, LOAD(b))

    // Initially load from keys[]
#   define LOAD(i) _mm_loadu_pd(keys + 2*(i))
    // Bitonic step #1:
    MINMAX(0, 1); MINMAX(2, 3); MINMAX(4, 5); MINMAX(6, 7);

    // Switch to loading (aligned) from temp[]
#   undef  LOAD
#   define LOAD(i) temp[i]

    // Bitonic step #2:
    MINMAX(0, 3); MINMAX(1, 2); MINMAX(4, 7); MINMAX(5, 6);
    MINMAX(0, 1); MINMAX(2, 3); MINMAX(4, 5); MINMAX(6, 7);

    // Bitonic step #3:
    MINMAX(0, 7); MINMAX(1, 6); MINMAX(2, 5); MINMAX(3, 4);
    MINMAX(0, 2); MINMAX(1, 3); MINMAX(4, 6); MINMAX(5, 7);
    MINMAX(0, 1); MINMAX(2, 3); MINMAX(4, 5); MINMAX(6, 7);

    // Linear merge of (temp.d[0,2,4,6], temp.d[1,3,5,7]) => keys:
#if 1
    double a, *tp, *zp = keys, *ap = (double *)temp, *bp = ap + 1, b = *bp;

    do {
        a = *ap;
        if (a > b) {
            tp = ap, ap = bp, bp = tp;
            *zp++ = b;
            b = a;
        } else {
            *zp++ = a;
        }
    } while ((ap += 2) < (double *)temp + 16);

    do *zp++ = *bp;
    while ((bp += 2) < (double *)temp + 16);
#else
    // Odd-even merge => keys
    // This is included as a curiosity only; the linear merge is faster.
    double  d[4];

#   define LOADLO(x,d) (temp[x] = _mm_loadl_pd(temp[x], &(d)))
#   define SAVELO(d,x) _mm_storel_pd(&(d), temp[x])
#   define SAVEHI(d,x) _mm_storeh_pd(&(d), temp[x])
    // I have no idea why SSE2 calls it UNpack.
#   define PACKHI(a,b) (temp[a] = (__m128d)_mm_unpackhi_epi64((XMM)temp[a], (XMM)temp[b]))
#   define PACKLO(a,b) (temp[a] = (__m128d)_mm_unpacklo_epi64((XMM)temp[a], (XMM)temp[b]))

    // At the end of the bitonic sort, registers (X0..X7)
    // hold two sorted 8-element seqs: [0..7] and [8..f].
    // These are represented (in comments below) as
    //  e.g. '19' for (lo=1,hi=9)

    // MINMAX ops need values in different seqs to be
    // in different regs; or to put it another way, (lo) and
    // (hi) of each reg must come from the same seq.
    // MINMAX steps before the final step need adjacent pairs of
    // each seq be in the same reg (e.g 01,23,.., 89,ab,..)

    // Chhugani(sic) et al ("Effic Impl of Sort on Multi-Core
    // SIMD CPU Arch" ?2009?) imply 2 shuffles per minmax for
    // bitonic sort. The following has 26 shuffle ops for 13
    // minmaxes (39 ops).

    // In the following, '_' stands for a don't-care position.
    // X0 X1 X2 X3 X4 X5 X6 X7 
    // 08 19 2a 3b 4c 5d 6e 7f
    // ops=19 for SHUFFLE#1

    SAVEHI(d[0], 0);            // 0_ 19 2a 3b 4c 5d 6e 7f
    SAVEHI(d[1], 2);            // 0_ 19 2_ 3b 4c 5d 6e 7f
    SAVEHI(d[2], 4);            // 0_ 19 2_ 3b 4_ 5d 6e 7f
    SAVEHI(d[3], 6);            // 0_ 19 2_ 3b 4_ 5d 6_ 7f

    PACKLO(0, 1);               // 01 _9 2_ 3b 4_ 5d 6_ 7f
    PACKLO(2, 3);               // 01 _9 23 _b 4_ 5d 6_ 7f
    PACKLO(4, 5);               // 01 _9 23 _b 45 _d 6_ 7f
    PACKLO(6, 7);               // 01 _9 23 _b 45 _d 67 _f

    LOADLO(1, d[0]);            // 01 89 23 _b 45 _d 67 _f
    LOADLO(3, d[1]);            // 01 89 23 ab 45 _d 67 _f
    LOADLO(5, d[2]);            // 01 89 23 ab 45 cd 67 _f
    LOADLO(7, d[3]);            // 01 89 23 ab 45 cd 67 ef

    // ops=29 for (MINMAX#1 + SAVE + MINMAX#2):

    // MINMAX#1
    MINMAX(0, 1);               // 01:89
    MINMAX(2, 3);               // 23:ab
    MINMAX(4, 5);               // 45:cd
    MINMAX(6, 7);               // 67:ef

    // The min of the first of each series (0:8) is the min of
    //  the final result. Likewise the max of the last of each
    //  (7:f).
    // SAVE keys[0,15]
    SAVELO(keys[0], 0);         // _1 89 23 ab 45 cd 67 ef
    SAVEHI(keys[15], 7);        // _1 89 23 ab 45 cd 67 e_

    // MINMAX#2
    MINMAX(4, 1);               // 45:89
    MINMAX(6, 3);               // 67:ab
    MINMAX(2, 4);               // 23:45
    MINMAX(6, 1);               // 67:89
    MINMAX(3, 5);               // ab:cd

    // ops=7 for SHUFFLE#2:
    PACKHI(0, 2);               // 13 89 2_ ab 45 cd 67 e_
    PACKLO(2, 4);               // 13 89 24 ab _5 cd 67 e_
    PACKHI(4, 6);               // 13 89 24 ab 57 cd 6_ e_
    PACKLO(6, 1);               // 13 _9 24 ab 57 cd 68 e_
    PACKHI(1, 3);               // 13 9b 24 a_ 57 cd 68 e_
    PACKLO(3, 5);               // 13 9b 24 ac 57 _d 68 e_
    PACKHI(5, 5);               // 13 9b 24 ac 57 d_ 68 e_

    // ops=26 for (MINMAX#3 + SAVE keys[1..14])

    // MINMAX#3
    MINMAX(0, 2);               // 13:24
    MINMAX(4, 6);               // 57:68
    MINMAX(1, 3);               // 9b:ac
    MINMAX(5, 7);               // d_:e_ only lo part used

    // SAVE->keys[1..14]. Compiler reorders these much:
    SAVELO(keys[1], 0);
    SAVEHI(keys[3], 0);
    SAVELO(keys[2], 2);
    SAVEHI(keys[4], 2);
    SAVELO(keys[5], 4);
    SAVEHI(keys[7], 4);
    SAVELO(keys[6], 6);
    SAVEHI(keys[8], 6);
    SAVELO(keys[9], 1);
    SAVEHI(keys[11], 1);
    SAVELO(keys[10], 3);
    SAVEHI(keys[12], 3);
    SAVELO(keys[13], 5);
    SAVELO(keys[14], 7);
#endif
}