Esempio n. 1
0
/*
 * OutlineLine - outline the line before it is drawn
 */
void OutlineLine( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt,
                  WPI_POINT *prev_pt, BOOL firsttime )
{
    WPI_POINT   startpt;
    WPI_POINT   endpt;
    WPI_POINT   prevpt;
    int         prevROP2;
    HPEN        holdpen;
    HPEN        hwhitepen;
    WPI_PRES    pres;

    CheckBounds( hwnd, start_pt );
    CheckBounds( hwnd, end_pt );
    startpt.x = MAKELOGPTX( start_pt->x ) + pointSize.x / 2;
    startpt.y = MAKELOGPTY( start_pt->y ) + pointSize.y / 2;
    endpt.x = MAKELOGPTX( end_pt->x ) + pointSize.x / 2;
    endpt.y = MAKELOGPTY( end_pt->y ) + pointSize.y / 2;

    pres = _wpi_getpres( hwnd );
    _wpi_torgbmode( pres );
    hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE );
    holdpen = _wpi_selectobject( pres, hwhitepen );

    prevROP2 = _wpi_setrop2( pres, R2_XORPEN );

    if( !firsttime ) {
        CheckBounds( hwnd, prev_pt );
        prevpt.x = MAKELOGPTX( prev_pt->x ) + pointSize.x / 2;
        prevpt.y = MAKELOGPTY( prev_pt->y ) + pointSize.y / 2;
        _wpi_movetoex( pres, &startpt, NULL );
        _wpi_lineto( pres, &prevpt );
    }

    _wpi_movetoex( pres, &startpt, NULL );
    _wpi_lineto( pres, &endpt );

    _wpi_setrop2( pres, prevROP2 );
    _wpi_selectobject( pres, holdpen );
    _wpi_deleteobject( hwhitepen );

    _wpi_releasepres( hwnd, pres );

}  /* OutlineLine */
Esempio n. 2
0
void csRectRegionDebug::Exclude(const csRect &rect)
{
  CS_ASSERT(CheckBounds(rect));
  for(int i = rect.xmin; i < rect.xmax; i++)
  {
    for(int j = rect.ymin; j < rect.ymax; j++)
    {
      area[i][j] = false;
    }
  }
}
Esempio n. 3
0
static void FixUpELF(unsigned char *data, size_t data_size) {
  Elf_Ehdr *header;
  int index;

  header = (Elf_Ehdr *) data;
  CheckBounds(data, data_size, header, sizeof(*header));
  CHECK(memcmp(header->e_ident, ELFMAG, strlen(ELFMAG)) == 0);

  for (index = 0; index < header->e_shnum; index++) {
    Elf_Shdr *section = (Elf_Shdr *) (data + header->e_shoff +
                                      header->e_shentsize * index);
    CheckBounds(data, data_size, section, sizeof(*section));

    if ((section->sh_flags & SHF_EXECINSTR) != 0) {
      CheckBounds(data, data_size,
                  data + section->sh_offset, section->sh_size);
      FixUpSection(section->sh_addr,
                   data + section->sh_offset, section->sh_size);
    }
  }
}
Esempio n. 4
0
/**
   set the i-th component of the vector
  */
void aVector::SetAComp(int i, double p_val)
{
#ifdef CHECKBOUNDS_ON
   CheckBounds(i);
#endif

   pv_p[i] = p_val;

// recompute magnitude and nullity
   ComputeMagnitude();
   pv_is_null = isNullVector();
}
Esempio n. 5
0
void CImageProcess::Sample(string path, float (*trainData)[MAX_TRAIN_COLS], int row)
{
	//test(path);
	IplImage*	pOSource = cvLoadImage(path.c_str());
	m_mapImage.insert(std::pair<string, IplImage*>(m_sName, pOSource));
	//opencv  灰度化
	IplImage* pOGray = cvCreateImage(cvGetSize(pOSource), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("gray", pOGray));
	cvCvtColor(pOSource, pOGray, CV_BGR2GRAY);
	//opencv 二值化
	IplImage*	pOBinary = cvCreateImage(cvGetSize(pOGray), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("binary", pOBinary));
	//cvThreshold(pOGray, pOBinary, 175, 255, CV_THRESH_BINARY_INV);
	ExcuteThreshold(pOGray, 175, true);

	vector<CvRect> rect = CheckBounds(pOGray);
	vector<IplImage*> image;
	CutImage(pOGray, rect, &image);

	vector<IplImage*>::iterator it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
		InverseImage(*it);
	}

	vector<IplImage*> dst;
	ZoomImage_16(&image, &dst);

	it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
			//char c[10]={0};
			//itoa(i,c,10);
			//cvNamedWindow(c,1); 
			//cvShowImage(c,*it);  
		cvReleaseImage(&(*it));
	}
	

	//ofstream fsave;
	//fsave.open("./sources/feature.txt", ios_base::out | ios_base::ate | ios_base::app);
	it=dst.begin();
	for(; it!=dst.end(); it++){
		ANN_ExtractFeature(*it , trainData, MAX_SAMPLES, MAX_TRAIN_COLS, row);
	//	ExtractFeature(*it, 1, 24, &fsave);
	}
	//fsave.close();

	//ANN_GetSample();
	//cvNamedWindow("二值图像",1);    
	//cvShowImage("二值图像",pOBinary);   
	//cvWaitKey(0);  
	//cvDestroyAllWindows();  
	//cvReleaseImage(&pOBinary);  
}
Esempio n. 6
0
bool BaseAtom::ReadString(string &val, uint64_t size) {
	if (!CheckBounds(size))
		return false;
	char *pTemp = new char[(uint32_t) size + 1];
	memset(pTemp, 0, (uint32_t) size + 1);
	bool result = _pDoc->GetMediaFile().ReadBuffer((uint8_t *) pTemp, size);
	if (result)
		val = string(pTemp, (uint32_t) size);
	else
		val = "";
	delete[] pTemp;
	return result;
}
Esempio n. 7
0
// For taking mouse clicks
void
WorldCursor::SetPos(coord newX, coord newY, bool syncVP)
{
	uint32 tileX,tileY;
	WorldMap	*pWorldMap = ADerefAs(WorldMap, pWorld->gWorldMap);

	tileX = ((newX) - pWorldMap->worldRect.x1) / UNIT_WIDTH;
	tileY = ((newY) - pWorldMap->worldRect.y1) / UNIT_HEIGHT;

	// find legal tile
	CheckBounds(&tileX,&tileY);

	SetTile(tileX,tileY,syncVP);
}
Esempio n. 8
0
Button::State Button::MouseButtonDown(SDL_MouseButtonEvent const& event) {
	//if out of bounds, exit
	if (!CheckBounds(event.x, event.y)) {
		return state = State::IDLE;
	}

	//if in bounds, check button
	if (event.button == SDL_BUTTON_LEFT) {
		return state = State::PRESSED;
	}

	//NOTE: if not left button down, ignore
	return State::HOVER;
}
Esempio n. 9
0
void ME_CCEventAtEditCursor (COMMAND_T* ct, int val, int valhw, int relmode, HWND hwnd)
{
	BR_MouseInfo mouseInfo(BR_MouseInfo::MODE_MIDI_EDITOR_ALL);
	if (mouseInfo.GetMidiEditor())
	{
		if (MediaItem_Take* take = MIDIEditor_GetTake(mouseInfo.GetMidiEditor()))
		{
			double startLimit, endLimit;
			double positionPPQ = GetOriginalPpqPos(take, MIDI_GetPPQPosFromProjTime(take, GetCursorPositionEx(NULL)), NULL, &startLimit, &endLimit);
			if (!CheckBounds(positionPPQ, startLimit, endLimit))
				return;

			int lane, value;
			if (mouseInfo.GetCCLane(&lane, &value, NULL) && value >= 0)
			{
				if (lane == CC_TEXT_EVENTS || lane == CC_SYSEX || lane == CC_BANK_SELECT || lane == CC_VELOCITY || lane == CC_VELOCITY_OFF)
					MessageBox((HWND)mouseInfo.GetMidiEditor(), __LOCALIZE("Can't insert in velocity, text, sysex and bank select lanes","sws_mbox"), __LOCALIZE("SWS/BR - Warning","sws_mbox"), MB_OK);
				else
				{
					bool do14bit    = (lane >= CC_14BIT_START) ? true : false;
					int type        = (lane == CC_PROGRAM) ? (STATUS_PROGRAM) : (lane == CC_CHANNEL_PRESSURE ? STATUS_CHANNEL_PRESSURE : (lane == CC_PITCH ? STATUS_PITCH : STATUS_CC));
					int channel     = MIDIEditor_GetSetting_int(mouseInfo.GetMidiEditor(), "default_note_chan");
					int msg2        = CheckBounds(lane, 0, 127) ? ((value >> 7) | 0) : (value & 0x7F);
					int msg3        = CheckBounds(lane, 0, 127) ? (value & 0x7F)     : ((value >> 7) | 0);

					int targetLane  = (do14bit) ? lane - CC_14BIT_START : lane;
					int targetLane2 = (do14bit) ? targetLane + 32       : lane;

					MIDI_InsertCC(take, true, false, positionPPQ, type,	channel, (CheckBounds(targetLane, 0, 127) ? targetLane : msg2), msg3);
					if (do14bit)
						MIDI_InsertCC(take, true, false, positionPPQ, type, channel, targetLane2, msg2);

					Undo_OnStateChangeEx2(NULL, SWS_CMD_SHORTNAME(ct), UNDO_STATE_ITEMS, -1);
				}
			}
		}
	}
void tShapeOpp::rotateRight(double timeChange, OIS::Keyboard* mKeyboard,vector<vector<vector<Cube*>>>  & array3D)
{
	
			if(  directionFacing == right)
			{
					xDirection = -4;
					zDirection = 4; 
					directionFacing = backwards; 
					
			} 

			else if( directionFacing == backwards)
			{ 
					xDirection = -4;
					zDirection = -4; 
					directionFacing = left;
					

			} 
			else if( directionFacing == left)
			{ 
					xDirection = 4;
					zDirection = -4; 
					directionFacing = forwards;				

			} 

			else if( directionFacing == forwards)
			{ 
					xDirection = 4;
					zDirection = 4; 
					directionFacing = right;				

			} 


		Ogre::Vector3 newPos =   Ogre::Vector3(cubes[1]->m_position.x + xDirection,cubes[1]->m_position.y ,cubes[1]->m_position.z +  zDirection);
			cubes[1]->setPosition(newPos);
			cubes[1]->targetNode->setPosition(newPos);
			cubes[1]->gridPosX = cubes[1]->gridPosX + (xDirection/4);
			cubes[1]->gridPosZ = cubes[1]->gridPosZ + (zDirection/4);

			xDirection = -xDirection;
			zDirection = -zDirection;
			CheckBounds();

			

}
Esempio n. 11
0
void PairCopulaInvVfun_VecPar(int family, const double *theta, double *U, double *V, double *u, unsigned int n)
{
    unsigned int i;
    
    switch(family){
        case 2:
        {
            // 1 Parameter: AsymFGM
            
            double UU, VV;
            for (i=0;i<n;i++)
            {
                UU = CheckBounds(U[i]);
                VV = CheckBounds(V[i]);
                u[i] = invvfun_bisect(family,theta[i],UU,VV,n);
                
            }
            break;
        }
        case 16: case 17:
        {
            // 2 Parameters: Tawn1, Tawn2
            
            double UU, VV;
            for (i=0;i<n;i++)
            {
                UU = CheckBounds(U[i]);
                VV = CheckBounds(V[i]);
                u[i] = invvfun_bisect(family,theta[i],theta[i+n],UU,VV,n);
                
            }
            break;
        }
        case 18:
        {
            // 3 Parameters: Tawn
            
            double UU, VV;
            for (i=0;i<n;i++)
            {
                UU = CheckBounds(U[i]);
                VV = CheckBounds(V[i]);
                u[i] = invvfun_bisect(family,theta[i],theta[i+n],theta[i+2*n],UU,VV,n);
                
            }
            break;
        }
        default:
        {
            // symmetric copulas
            PairCopulaInvHfun_VecPar(family, theta, V, U, u, n);
            break;
        }
    }
    return;
}
Esempio n. 12
0
// For converting mouse clicks to tile coords
void
WorldCursor::GetTilePos(uint32 newX, uint32 newY, uint32 *pTileX, uint32 *pTileY, bool fCheckBounds)
{
	uint32 tileX,tileY;
	WorldMap	*pWorldMap = ADerefAs(WorldMap, pWorld->gWorldMap);

	tileX = ((newX) - pWorldMap->worldRect.x1) / UNIT_WIDTH;
	tileY = ((newY) - pWorldMap->worldRect.y1) / UNIT_HEIGHT;

	// find legal tile
	if(fCheckBounds)
		CheckBounds(&tileX,&tileY);

	*pTileX = tileX;
	*pTileY = tileY;
}
Esempio n. 13
0
File: typemgr.c Progetto: xyuan/ug
static int RecursiveRegister (TYPE_DESC *desc,
                              int i, DDD_TYPE typ, int offs, int argno)
{
  TYPE_DESC *d2 = &(theTypeDefs[typ]);
  int j;
  char       *errtxt;

  /* inherit elements of other ddd-type */
  for(j=0; j<d2->nElements && i<MAX_ELEMDESC; j++, i++)
  {
    ConstructEl(&desc->element[i],
                d2->element[j].type,
                d2->element[j].offset + offs,
                d2->element[j].size,
                EDESC_REFTYPE(&(d2->element[j])));
    if (CheckBounds(desc, &desc->element[i], argno) == ERROR)
      return(ERROR);
  }

  /* inherit other properties */
  desc->nPointers += d2->nPointers;
  if (d2->hasHeader)
  {
    if (!desc->hasHeader)
    {
      desc->hasHeader = TRUE;
      desc->offsetHeader = d2->offsetHeader + offs;
    }
    else
    {
      if (desc->offsetHeader == d2->offsetHeader+offs)
      {
        errtxt=RegisterError(desc,argno, "two DDD_HDRs, same offset");
        DDD_PrintError('W', 2408, errtxt);
      }
      else
      {
        errtxt=RegisterError(desc,argno, "only one DDD_HDR allowed");
        DDD_PrintError('E', 2409, errtxt);
        return(ERROR);
      }
    }
  }

  return i;
}
Esempio n. 14
0
Button::State Button::MouseMotion(SDL_MouseMotionEvent const& event) {
	//if out of bounds, exit
	if (!CheckBounds(event.x, event.y)) {
		return state = State::IDLE;
	}

	//if in bounds, check button
	if (event.state & SDL_BUTTON_LMASK && state == State::PRESSED) {
		//stay pressed
//		state = State::PRESSED;
	}
	else {
		state = State::HOVER;
	}

	return state;
}
Esempio n. 15
0
Button::State Button::MouseButtonUp(SDL_MouseButtonEvent const& event) {
	//if out of bounds, exit
	if (!CheckBounds(event.x, event.y)) {
		return state = State::IDLE;
	}

	//if not left button up, ignore
	if (event.button != SDL_BUTTON_LEFT) {
		return state;
	}

	//if in bounds and left button up, send release signal
	if (state == State::PRESSED) {
		state = State::HOVER;
		return State::RELEASED;
	}

	return state;
}
Esempio n. 16
0
void CImageProcess::Sample(string path, float *obj, int cols)
{
	IplImage*	pOSource = cvLoadImage(path.c_str());
	m_mapImage.insert(std::pair<string, IplImage*>(m_sName, pOSource));
	//opencv  灰度化
	IplImage* pOGray = cvCreateImage(cvGetSize(pOSource), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("gray", pOGray));
	cvCvtColor(pOSource, pOGray, CV_BGR2GRAY);
	//opencv 二值化
	IplImage*	pOBinary = cvCreateImage(cvGetSize(pOGray), IPL_DEPTH_8U, 1);
	m_mapImage.insert(std::pair<string, IplImage*>("binary", pOBinary));
	//cvThreshold(pOGray, pOBinary, 175, 255, CV_THRESH_BINARY_INV);
	ExcuteThreshold(pOGray, 175, true);

	vector<CvRect> rect = CheckBounds(pOGray);
	vector<IplImage*> image;
	CutImage(pOGray, rect, &image);

	vector<IplImage*>::iterator it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
		InverseImage(*it);
	}

	vector<IplImage*> dst;
	ZoomImage_16(&image, &dst);

	it = image.begin();
	for(int i=0; it != image.end(); it++,i++){
		//char c[10]={0};
		//itoa(i,c,10);
		//cvNamedWindow(c,1); 
		//cvShowImage(c,*it);  
		cvReleaseImage(&(*it));
	}


	//ofstream fsave;
	//fsave.open("./sources/feature.txt", ios_base::out | ios_base::ate | ios_base::app);
	it=dst.begin();
	if(it != dst.end()){
		ANN_ExtractFeature(*it , obj, cols);
	}
}
Esempio n. 17
0
File: typemgr.c Progetto: xyuan/ug
static int RecursiveRegister (TYPE_DESC *desc,
                              int i, DDD_TYPE typ, char *adr, int argno)
{
  TYPE_DESC *d2 = &(theTypeDefs[typ]);
  char       *errtxt;

  if (CPP_ARRAY(d2))
  {
    errtxt=RegisterError(desc,argno,
                         "cannot include array-like type into array-like type");
    DDD_PrintError('W', 2410, errtxt);
    return(ERROR);
  }

  ConstructEl(&desc->element[i], typ, adr, d2->size, 0);
  if (CheckBounds(desc, &desc->element[i], argno) == ERROR)
    return(ERROR);

  desc->size += d2->size;

  /* inherit other properties */
  desc->nPointers += d2->nPointers;
  if (d2->hasHeader)
  {
    if (!desc->hasHeader)
    {
      desc->hasHeader = TRUE;
      desc->elemHeader = i;
      desc->offsetHeader = d2->offsetHeader;
    }
    else
    {
      errtxt=RegisterError(desc,argno, "only one DDD_HDR allowed");
      DDD_PrintError('E', 2411, errtxt);
      return(ERROR);
    }
  }

  return i+1;
}
Esempio n. 18
0
void csRectRegionDebug::AssertEqual(const csRectRegion &r)
{
  int i,j,k;
  for(i = 0; i < r.Count(); i++)
  {
    csRect rect = r.RectAt(i);
    CS_ASSERT(CheckBounds(rect));
    for(j = rect.xmin; j < rect.xmax; j++)
    {
      for(k = rect.ymin; k < rect.ymax; k++)
      {
        CS_ASSERT(area[j][k] == true);
        area[j][k] = false;
      }
    }
  }

  for(i = 0; i < CS_RECT_REG_SIZE; i++)
  {
    for(j = 0; j < CS_RECT_REG_SIZE; j++)
    {
      CS_ASSERT(area[i][j] == false);
    }
  }

  for(i = 0; i < r.Count(); i++)
  {
    csRect rect = r.RectAt(i);
    for(j = rect.xmin; j < rect.xmax; j++)
    {
      for(int k = rect.ymin; k < rect.ymax; k++)
      {
        area[j][k] = true;
      }
    }
  }

  num_tests_complete++;
}
Esempio n. 19
0
/*
 * OutlineRegion - displays the potential region (rectangle or ellipse)
 *                 on the draw area.
 */
void OutlineRegion( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt,
                                        WPI_POINT *prev_pt, BOOL firsttime )
{
    WPI_POINT   topleft;
    WPI_POINT   bottomright;
    WPI_POINT   prevtl;                 // previous top left point
    WPI_POINT   prevbr;                 // previous bottom right point
    int         prevROP2;
    HBRUSH      hbrush;
    HBRUSH      holdbrush;
    HPEN        hwhitepen;
    HPEN        holdpen;
    int         temp;
    WPI_PRES    pres;

    CheckBounds( hwnd, start_pt );
    CheckBounds( hwnd, end_pt );
    CheckBounds( hwnd, prev_pt );
    _wpi_setpoint(&topleft, MAKELOGPTX(start_pt->x), MAKELOGPTY(start_pt->y));
    _wpi_setpoint(&bottomright, MAKELOGPTX(end_pt->x), MAKELOGPTY(end_pt->y));

    if (topleft.x > bottomright.x) {
        temp = (short)bottomright.x;
        bottomright.x = topleft.x + pointSize.x;
        topleft.x = temp;
    } else {
        bottomright.x += pointSize.x;
    }
    if (topleft.y > bottomright.y) {
        temp = (int)bottomright.y;
        bottomright.y = topleft.y + pointSize.y;
        topleft.y = temp;
    } else {
        bottomright.y += pointSize.y;
    }

    prevtl.x = MAKELOGPTX( start_pt->x );
    prevtl.y = MAKELOGPTY( start_pt->y );
    prevbr.x = MAKELOGPTX( prev_pt->x );
    prevbr.y = MAKELOGPTY( prev_pt->y );

    if (prevtl.x > prevbr.x) {
        temp = (int)prevbr.x;
        prevbr.x = prevtl.x + pointSize.x;
        prevtl.x = temp;
    } else {
        prevbr.x += pointSize.x;
    }

    if (prevtl.y > prevbr.y) {
        temp = (int)prevbr.y;
        prevbr.y = prevtl.y + pointSize.y;
        prevtl.y = temp;
    } else {
        prevbr.y += pointSize.y;
    }

    ++prevtl.x;
    ++prevtl.y;
    ++topleft.x;
    ++topleft.y;

    pres = _wpi_getpres( hwnd );
    _wpi_torgbmode( pres );
    prevROP2 = _wpi_setrop2( pres, R2_XORPEN );
    hbrush = _wpi_createsolidbrush( BLACK );
    hwhitepen = _wpi_createpen( PS_SOLID, 0, WHITE );

    holdbrush = _wpi_selectobject( pres, hbrush );
    holdpen = _wpi_selectobject( pres, hwhitepen );

    if (!firsttime) {
        if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) {
            _wpi_ellipse( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y );
        } else {
            _wpi_rectangle( pres, prevtl.x, prevtl.y, prevbr.x, prevbr.y );
        }
    }

    if ((toolType == IMGED_CIRCLEO) || (toolType == IMGED_CIRCLEF)) {
        _wpi_ellipse( pres, topleft.x, topleft.y, bottomright.x, bottomright.y );
    } else {
        _wpi_rectangle( pres, topleft.x, topleft.y, bottomright.x, bottomright.y );
    }
    _wpi_selectobject( pres, holdpen );
    _wpi_selectobject( pres, holdbrush );

    _wpi_deleteobject( hwhitepen );
    _wpi_deleteobject( hbrush );
    _wpi_setrop2( pres, prevROP2 );
    _wpi_releasepres( hwnd, pres );
} /* OutlineRegion */
Esempio n. 20
0
int ValidateFile(const char *filename, int repeat_count) {
  size_t data_size;
  uint8_t *data;
  ReadFile(filename, &data, &data_size);

  int count;
  if (data[4] == 1) {
    for (count = 0; count < repeat_count; ++count) {
      Elf32_Ehdr *header;
      int index;

      header = (Elf32_Ehdr *) data;
      CheckBounds(data, data_size, header, sizeof(*header));
      assert(memcmp(header->e_ident, ELFMAG, strlen(ELFMAG)) == 0);

      for (index = 0; index < header->e_shnum; ++index) {
	Elf32_Shdr *section = (Elf32_Shdr *) (data + header->e_shoff +
						   header->e_shentsize * index);
	CheckBounds(data, data_size, section, sizeof(*section));

	if ((section->sh_flags & SHF_EXECINSTR) != 0) {
	  struct ValidateState state;
	  state.offset = data + section->sh_offset - section->sh_addr;
	  if (section->sh_size <= 0xfff) {
	    state.width = 4;
	  } else if (section->sh_size <= 0xfffffff) {
	    state.width = 8;
	  } else {
	    state.width = 12;
	  }
	  CheckBounds(data, data_size,
		      data + section->sh_offset, section->sh_size);
	  int res = ValidateChunkIA32(data + section->sh_offset,
					section->sh_size, ProcessError, &state);
	  if (res != 0) {
	    return res;
	  }
	}
      }
    }
  } else if (data[4] == 2) {
    for (count = 0; count < repeat_count; ++count) {
      Elf64_Ehdr *header;
      int index;

      header = (Elf64_Ehdr *) data;
      CheckBounds(data, data_size, header, sizeof(*header));
      assert(memcmp(header->e_ident, ELFMAG, strlen(ELFMAG)) == 0);

      for (index = 0; index < header->e_shnum; ++index) {
	Elf64_Shdr *section = (Elf64_Shdr *) (data + header->e_shoff +
						   header->e_shentsize * index);
	CheckBounds(data, data_size, section, sizeof(*section));

	if ((section->sh_flags & SHF_EXECINSTR) != 0) {
	  struct ValidateState state;
	  state.offset = data + section->sh_offset - section->sh_addr;
	  if (section->sh_size <= 0xfff) {
	    state.width = 4;
	  } else if (section->sh_size <= 0xfffffff) {
	    state.width = 8;
	  } else if (section->sh_size <= 0xfffffffffffLL) {
	    state.width = 12;
	  } else {
	    state.width = 16;
	  }
	  CheckBounds(data, data_size,
		      data + section->sh_offset, section->sh_size);
	  int res = ValidateChunkAMD64(data + section->sh_offset,
					section->sh_size, ProcessError, &state);
	  if (res != 0) {
	    return res;
	  }
	}
      }
    }
  } else {
    printf("Unknown ELF class: %s\n", filename);
    exit(1);
  }
  return 0;
}
Esempio n. 21
0
/* ----------------------------- MNI Header -----------------------------------
@NAME       : 
@INPUT      : 
@OUTPUT     : 
@RETURNS    : 
@DESCRIPTION: 
@METHOD     : 
@GLOBAL     : 
@CALLS      : 
@CREATED    : 
@MODIFIED   : 
---------------------------------------------------------------------------- */
int main (int argc, char *argv [])
{
   ImageInfoRec   ImInfo;
   long        Slice[MAX_WRITEABLE];
   long        Frame[MAX_WRITEABLE];
   long        NumSlices;
   long        NumFrames;
   FILE        *InFile;
   int         Result;
#ifdef DEBUG
   int         i;               /* loop to print out all slices and */
                                /* frames selected */
   ncopts = 0;
#endif

   ncopts = NC_VERBOSE;
   ErrMsg = (char *) malloc (256);

/* strcpy (ErrMsg, "Hello! I am an error message!"); */

   if (argc != NUM_ARGS + 1)        /* +1 because argv[0] counts! */
   {
      ErrAbort ("Incorrect number of arguments", TRUE, ERR_ARGS);
   }

#ifdef DEBUG
   printf ("Passing slice list %s to GetVector\n", SLICE_VECTOR);
   printf ("Passing frame list %s to GetVector\n", FRAME_VECTOR);
#endif

   /*
    * Parse the two lists of numbers first off
    */

   NumSlices = GetVector (SLICE_VECTOR, Slice, MAX_WRITEABLE);
   if (NumSlices < 0)
   {
      GVErrMsg (ErrMsg, "slices", NumSlices);
      ErrAbort (ErrMsg, TRUE, ERR_ARGS);
   }

   NumFrames = GetVector (FRAME_VECTOR, Frame, MAX_WRITEABLE);
   if (NumFrames < 0)
   {
      GVErrMsg (ErrMsg, "frames", NumFrames);
      ErrAbort (ErrMsg, TRUE, ERR_ARGS);
   }

#ifdef DEBUG
   printf ("Slices specified: ");
   for (i = 0; i < NumSlices; i++)
   {
      printf ("%8ld", Slice[i]);
   }
   printf ("\n");
   
   printf ("Frames specified: ");
   for (i = 0; i < NumFrames; i++)
   {
/*      printf ("i = %d, &(Frame) = %p, &(Frame[d]) = %p\n",
	      i, &Frame, &(Frame[i]));  */
      printf ("%8ld", Frame[i]); 
   }
   printf ("\n");
#endif

   if ((NumSlices > 1) && (NumFrames > 1))
   {
      ErrAbort ("Cannot specify both multiple frames and multiple slices", 
                TRUE, ERR_ARGS);
   }

   Result = OpenImage (MINC_FILE, &ImInfo, NC_WRITE, CreateNaN());
   if (Result != ERR_NONE)
   {
      ErrAbort (ErrMsg, TRUE, Result);
   }

   if (!CheckBounds (Slice, Frame, NumSlices, NumFrames, &ImInfo))
   {
      ErrAbort (ErrMsg, TRUE, ERR_ARGS);
   }

   if ((ImInfo.MaxID == MI_ERROR) || (ImInfo.MinID == MI_ERROR))
   {
      sprintf (ErrMsg, "Missing image-max or image-min variable in file %s", 
               MINC_FILE);
      ErrAbort (ErrMsg, TRUE, ERR_IN_MINC);
   }

   InFile = OpenTempFile (TEMP_FILE);
   if (InFile == NULL)
   {
      ErrAbort (ErrMsg, TRUE, ERR_IN_TEMP);
   }

   Result = WriteImages (InFile, &ImInfo, Slice, Frame, NumSlices, NumFrames);
   if (Result != ERR_NONE)
   {
      ErrAbort (ErrMsg, TRUE, Result);
   }

   fclose (InFile);

   miicv_free (ImInfo.ICV);
   ncclose (ImInfo.CDF);
   return (ERR_NONE);

}     /* main */
Esempio n. 22
0
/**
 * Advances a fling by an interpolated amount based on the Android OverScroller.
 * This should be called whenever sampling the content transform for this
 * frame. Returns true if the fling animation should be advanced by one frame,
 * or false if there is no fling or the fling has ended.
 */
bool
AndroidFlingAnimation::DoSample(FrameMetrics& aFrameMetrics,
                                const TimeDuration& aDelta)
{
  bool shouldContinueFling = true;

  mOverScroller->ComputeScrollOffset(&shouldContinueFling);
  // OverScroller::GetCurrVelocity will sometimes return NaN. So need to externally
  // calculate current velocity and not rely on what the OverScroller calculates.
  // mOverScroller->GetCurrVelocity(&speed);
  int32_t currentX = 0;
  int32_t currentY = 0;
  mOverScroller->GetCurrX(&currentX);
  mOverScroller->GetCurrY(&currentY);
  ParentLayerPoint offset((float)currentX, (float)currentY);

  bool hitBoundX = CheckBounds(mApzc.mX, offset.x, mFlingDirection.x, &(offset.x));
  bool hitBoundY = CheckBounds(mApzc.mY, offset.y, mFlingDirection.y, &(offset.y));

  ParentLayerPoint velocity = mPreviousVelocity;

  // Sometimes the OverScroller fails to update the offset for a frame.
  // If the frame can still scroll we just use the velocity from the previous
  // frame. However, if the frame can no longer scroll in the direction
  // of the fling, then end the animation.
  if (offset != mPreviousOffset) {
    if (aDelta.ToMilliseconds() > 0) {
      velocity = (offset - mPreviousOffset) / (float)aDelta.ToMilliseconds();
      mPreviousVelocity = velocity;
    }
  } else if (hitBoundX || hitBoundY) {
    // We have reached the end of the scroll in one of the directions being scrolled and the offset has not
    // changed so end animation.
    shouldContinueFling = false;
  }

  float speed = velocity.Length();

  // gfxPrefs::APZFlingStoppedThreshold is only used in tests.
  if (!shouldContinueFling || (speed < gfxPrefs::APZFlingStoppedThreshold())) {
    if (shouldContinueFling) {
      // The OverScroller thinks it should continue but the speed is below
      // the stopping threshold so abort the animation.
      mOverScroller->AbortAnimation();
    }
    // This animation is going to end. If DeferHandleFlingOverscroll
    // has not been called and there is still some velocity left,
    // call it so that fling hand off may occur if applicable.
    if (!mSentBounceX && !mSentBounceY && (speed > 0.0f)) {
      DeferHandleFlingOverscroll(velocity);
    }
    return false;
  }

  mPreviousOffset = offset;

  mApzc.SetVelocityVector(velocity);
  aFrameMetrics.SetScrollOffset(offset / aFrameMetrics.GetZoom());

  // If we hit a bounds while flinging, send the velocity so that the bounce
  // animation can play.
  if (hitBoundX || hitBoundY) {
    ParentLayerPoint bounceVelocity = velocity;

    if (!mSentBounceX && hitBoundX && fabsf(offset.x - mStartOffset.x) > BOUNDS_EPSILON) {
      mSentBounceX = true;
    } else {
      bounceVelocity.x = 0.0f;
    }

    if (!mSentBounceY && hitBoundY && fabsf(offset.y - mStartOffset.y) > BOUNDS_EPSILON) {
      mSentBounceY = true;
    } else {
      bounceVelocity.y = 0.0f;
    }
    if (!IsZero(bounceVelocity)) {
      DeferHandleFlingOverscroll(bounceVelocity);
    }
  }

  return true;
}
Esempio n. 23
0
bool BaseAtom::SkipBytes(uint64_t count) {
	if (!CheckBounds(count))
		return false;
	return _pDoc->GetMediaFile().SeekAhead(count);
}
Esempio n. 24
0
bool BaseAtom::ReadInt64(int64_t &val, bool networkOrder) {
	if (!CheckBounds(8))
		return false;
	return _pDoc->GetMediaFile().ReadI64(&val, networkOrder);
}
Esempio n. 25
0
bool BaseAtom::ReadUInt32(uint32_t &val, bool networkOrder) {
	if (!CheckBounds(4))
		return false;
	return _pDoc->GetMediaFile().ReadUI32(&val, networkOrder);
}
Esempio n. 26
0
bool BaseAtom::ReadUInt8(uint8_t &val) {
	if (!CheckBounds(1))
		return false;
	return _pDoc->GetMediaFile().ReadUI8(& val);
}
Esempio n. 27
0
bool BaseAtom::ReadArray(uint8_t *pBuffer, uint64_t length) {
	if (!CheckBounds(length))
		return false;
	return _pDoc->GetMediaFile().ReadBuffer(pBuffer, length);
}
Esempio n. 28
0
/*
 * OutlineClip - displays the potential region to be clipped to the clip board
 */
void OutlineClip( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt,
                                        WPI_POINT *prev_pt, BOOL firsttime )
{
    WPI_RECT    newpos;
    WPI_RECT    oldpos;
    short       temp;
    WPI_PRES    pres;
    IMGED_DIM   left;
    IMGED_DIM   top;
    IMGED_DIM   right;
    IMGED_DIM   bottom;

    CheckBounds( hwnd, start_pt );
    CheckBounds( hwnd, end_pt );
    CheckBounds( hwnd, prev_pt );
    left = (IMGED_DIM)MAKELOGPTX(start_pt->x);
    top = (IMGED_DIM)MAKELOGPTY(start_pt->y);
    right = (IMGED_DIM)MAKELOGPTX(end_pt->x);
    bottom = (IMGED_DIM)MAKELOGPTY(end_pt->y);

    if (left > right) {
        temp = right;
        right = left + pointSize.x;
        left = temp;
    } else {
        right += pointSize.x;
    }
    if (top > bottom) {
        temp = bottom;
        bottom = top + pointSize.y;
        top = temp;
    } else {
        bottom += pointSize.y;
    }
    _wpi_setrectvalues( &newpos, left, top, right, bottom );

    left = (IMGED_DIM)MAKELOGPTX( start_pt->x );
    top = (IMGED_DIM)MAKELOGPTY( start_pt->y );
    right = (IMGED_DIM)MAKELOGPTX( prev_pt->x );
    bottom = (IMGED_DIM)MAKELOGPTY( prev_pt->y );

    if (left > right) {
        temp = right;
        right = left + pointSize.x;
        left = temp;
    } else {
        right += pointSize.x;
    }
    if (top > bottom) {
        temp = bottom;
        bottom = top + pointSize.y;
        top = temp;
    } else {
        bottom += pointSize.y;
    }
    _wpi_setrectvalues( &oldpos, left, top, right, bottom );

    pres = _wpi_getpres( hwnd );
    OutlineRectangle( firsttime, pres, &oldpos, &newpos );
    _wpi_releasepres( hwnd, pres );
} /* OutlineClip */
Esempio n. 29
0
/*
 * DisplayRegion - Draws the region (rectangle or ellipse) first in the view
 *              window, then in the draw area.
 */
void DisplayRegion( HWND hwnd, WPI_POINT *start_pt, WPI_POINT *end_pt, int mousebutton )
{
    COLORREF    colour;
    COLORREF    dithered;
    COLORREF    solid;
    WPI_POINT   imgstart_pt;
    WPI_POINT   imgend_pt;
    WPI_RECT    rect;
    BOOL        dofillrgn;
    BOOL        is_rect;
    wie_clrtype type;
    img_node    *node;

    CheckBounds( hwnd, start_pt );
    CheckBounds( hwnd, end_pt );
    imgstart_pt.x = min(start_pt->x / pointSize.x, end_pt->x / pointSize.x);
    imgend_pt.x = max(start_pt->x / pointSize.x, end_pt->x / pointSize.x);
#ifdef __OS2_PM__
    imgstart_pt.y = max(start_pt->y / pointSize.y, end_pt->y / pointSize.y);
    imgend_pt.y = min(start_pt->y / pointSize.y, end_pt->y / pointSize.y) - 1;
#else
    imgstart_pt.y = min(start_pt->y / pointSize.y, end_pt->y / pointSize.y);
    imgend_pt.y = max(start_pt->y / pointSize.y, end_pt->y / pointSize.y) + 1;
#endif

    imgend_pt.x += 1;

    dithered = GetSelectedColour(mousebutton, &solid, &type);
    switch (toolType) {
    case IMGED_RECTO:
        dofillrgn = FALSE;
        is_rect = TRUE;
        colour = solid;
        break;

    case IMGED_RECTF:
        dofillrgn = TRUE;
        is_rect = TRUE;
        colour = dithered;
        break;

    case IMGED_CIRCLEO:
        dofillrgn = FALSE;
        is_rect = FALSE;
        colour = solid;
        break;

    case IMGED_CIRCLEF:
        dofillrgn = TRUE;
        is_rect = FALSE;
        colour = dithered;
        break;

    default:
        return;
    }

    _wpi_setrectvalues(&rect, imgstart_pt.x, imgstart_pt.y, imgend_pt.x,
                                                        imgend_pt.y);
    if (type == SCREEN_CLR) {
        RegionXorAnd(BLACK, WHITE, dofillrgn, &rect, is_rect);
    } else if (type == INVERSE_CLR) {
        RegionXorAnd(WHITE, WHITE, dofillrgn, &rect, is_rect);
    } else {
        RegionXorAnd(colour, BLACK, dofillrgn, &rect, is_rect);
    }

    node = GetCurrentNode();
    InvalidateRect( node->viewhwnd, NULL, FALSE );
    BlowupImage( hwnd, NULL );
} /* DisplayRegion */
Esempio n. 30
0
/*
 * DrawSinglePoint - needed for when the mouse button is initially pressed.
 */
void DrawSinglePoint( HWND hwnd, WPI_POINT *pt, short mousebutton )
{
    HBRUSH      colourbrush;
    HBRUSH      oldbrush;
    HPEN        colourpen;
    HPEN        oldpen;
    COLORREF    selected_colour;
    COLORREF    dithered;
    short       truncated_x;
    short       truncated_y;
    short       i;
    short       j;
    WPI_POINT   logical_pt;
    WPI_RECT    rcclient;
    short       width;
    short       height;
    short       wndwidth;
    short       wndheight;
    wie_clrtype type;
    WPI_PRES    pres;
    int         brushsize;
    BOOL        gridvisible;

    GetClientRect( hwnd, &rcclient );
    wndwidth = _wpi_getwidthrect( rcclient );
    wndheight = _wpi_getheightrect( rcclient );
    brushsize = ImgedConfigInfo.brush_size;

    CheckBounds( hwnd, pt );

    gridvisible = ImgedConfigInfo.grid_on && (pointSize.x >= POINTSIZE_MIN &&
                                                pointSize.y >= POINTSIZE_MIN);
    if (gridvisible) {
        if (toolType == IMGED_BRUSH) {
            truncated_x = max(0, (pt->x/pointSize.x - brushsize/2)) * pointSize.x+1;
            truncated_y = max(0, (pt->y/pointSize.y - brushsize/2)) * pointSize.y+1;
            width = (short)(pointSize.x - 1);
            height = (short)(pointSize.y - 1);
            /*
             * We just have to check that we don't spill over the image dimensions
             */
            truncated_x = min(truncated_x, wndwidth-pointSize.x*brushsize+1);
            truncated_y = min(truncated_y, wndheight-pointSize.y*brushsize+1);
        } else {
            truncated_x = ( pt->x / pointSize.x) * pointSize.x + 1;
            truncated_y = ( pt->y / pointSize.y) * pointSize.y + 1;
            width = (short)(pointSize.x - 1);
            height = (short)(pointSize.y - 1);
        }
    } else {
        if (toolType == IMGED_BRUSH) {
            truncated_x = max(0, (pt->x / pointSize.x - brushsize/2)) * pointSize.x;
            truncated_y = max(0, (pt->y / pointSize.y - brushsize/2)) * pointSize.y;
            width = (short)(pointSize.x * brushsize);
            height = (short)(pointSize.y * brushsize);
            /*
             * We just have to check that we don't spill over the image dimensions
             */
            truncated_x = min( truncated_x, wndwidth-width );
            truncated_y = min( truncated_y, wndheight-width );
        } else {
            truncated_x = ( pt->x / pointSize.x) * pointSize.x;
            truncated_y = ( pt->y / pointSize.y) * pointSize.y;
            width = (short)pointSize.x;
            height = (short)pointSize.y;
        }
    }
    logical_pt.x = truncated_x / pointSize.x;
    logical_pt.y = truncated_y / pointSize.y;

    pres = _wpi_getpres( hwnd );
    _wpi_torgbmode( pres );
    dithered = GetSelectedColour(mousebutton, &selected_colour, &type);
    colourbrush = _wpi_createsolidbrush( selected_colour );
    oldbrush = _wpi_selectobject( pres, colourbrush );
    colourpen = _wpi_createpen( PS_SOLID, 0, selected_colour );
    oldpen = _wpi_selectobject( pres, colourpen );

    if (gridvisible && (toolType == IMGED_BRUSH)) {
        for (i=0; i < brushsize; ++i) {
            for (j=0; j < brushsize; ++j) {
                _wpi_patblt(pres, truncated_x+i*pointSize.x,
                                  truncated_y+j*pointSize.y,
                                  width, height, PATCOPY);
            }
        }
    } else {
        _wpi_patblt(pres, truncated_x, truncated_y, width, height, PATCOPY);
    }

    _wpi_selectobject( pres, oldbrush );
    _wpi_selectobject( pres, oldpen );
    _wpi_releasepres( hwnd, pres );

    _wpi_deleteobject( colourbrush );
    _wpi_deleteobject( colourpen );

    /*
     * draws the points in the view window
     */
    if (toolType == IMGED_BRUSH) {
        if (type == SCREEN_CLR) {
            BrushThePoints(selected_colour, BLACK, WHITE, &logical_pt,
                                                                brushsize);
        } else if (type == INVERSE_CLR) {
            BrushThePoints(selected_colour, WHITE, WHITE, &logical_pt,
                                                                brushsize);
        } else {
            BrushThePoints(selected_colour, selected_colour, BLACK,
                                                    &logical_pt, brushsize);
        }
    } else {
        if (type == SCREEN_CLR) {
            DrawThePoints(selected_colour, BLACK, WHITE, &logical_pt);
        } else if (type == INVERSE_CLR) {
            DrawThePoints(selected_colour, WHITE, WHITE, &logical_pt);
        } else {
            DrawThePoints(selected_colour, selected_colour, BLACK, &logical_pt);
        }
    }
} /* DrawSinglePoint */