示例#1
0
文件: tga.cpp 项目: bbrrck/libigl
IGL_INLINE void igl::opengl::writeTGA( igl::opengl::gliGenericImage* image, FILE *fp) {

  assert(!image->cmap); // we do not deal with color map images
    
  if(image->components == 3 || image->components == 4) 
    fwrite(TGAHeaderColor, 12, sizeof(unsigned char),fp);
  else { 
    if(image->components == 1 ) 
      fwrite(TGAHeaderBW, 12, sizeof(unsigned char),fp);        
    else { fprintf(stderr,"Supported component number: 1,3 or 4\n"); exit(1); }
  }

  write16bit(image->width,fp);  
  write16bit(image->height,fp);  
  switch (image->components ) { 
  case 1: 
    putc(8,fp);
    break;
  case 3: 
    putc(24,fp); 
    break;
  case 4:
    putc(32,fp);
    break;
  default: fprintf(stderr,"Supported component number: 1,3 or 4\n"); exit(1); 
  };
  
  if(image-> components == 4) 
    putc(0x04,fp); // bottom left image (0x00) + 8 bit alpha (0x4)
  else 
    putc(0x00,fp);

  fwrite(image->pixels, image->height*image->width*image->components, sizeof(char),fp);
}
示例#2
0
static void pwm1Pins(_t_pwm_pol pol)
{
	if (pol==PWM_NORMAL_A)
	{
		cbi(TCCR1A, COM1A0);
		sbi(TCCR1A, COM1A1);
		write16bit(0, &OCR1AH, &OCR1AL);
		sbi(DDRB, DDB1);
		cbi(PORTB, PORTB1); /* out low */
		pwmPol1A = pol;
	}
	else if (pol==PWM_INVERT_A)
	{
		sbi(TCCR1A, COM1A0);
		sbi(TCCR1A, COM1A1);
		write16bit(0, &OCR1AH, &OCR1AL);
		sbi(DDRB, DDB1);
		cbi(PORTB, PORTB1); /* out low */
		pwmPol1A = pol;
	}
	if (pol==PWM_NORMAL_B)
	{
		cbi(TCCR1A, COM1B0);
		sbi(TCCR1A, COM1B1);
		write16bit(0, &OCR1BH, &OCR1BL);
		sbi(DDRB, DDB2);
		cbi(PORTB, PORTB2); /* out low */
		pwmPol1A = pol;
	}
	else if (pol==PWM_INVERT_B)
	{
		sbi(TCCR1A, COM1B0);
		sbi(TCCR1A, COM1B1);
		write16bit(0, &OCR1BH, &OCR1BL);
		sbi(DDRB, DDB2);
		cbi(PORTB, PORTB2); /* out low */
		pwmPol1B = pol;
	}
	else
	{
		/* Usi futuri: funzionalità di toggle di OC0A*/
	}
}
示例#3
0
void setDutyPWM1(uint16_t duty, uint8_t pwmType) 
{
	if (pwmType == PWM_A)
	{
		if (duty == 0)
		{
			/* Fix per glitch quando a 0% */
			pwm1Pins(PWM_INVERT_A);
			write16bit(0xffff, &OCR1AH, &OCR1AL);
		}
		else
		{
			pwm1Pins(pwmPol1A);
			write16bit(duty, &OCR1AH, &OCR1AL);
		}
		write16bit(duty, &OCR1AH, &OCR1AL);
	}
	else if (pwmType == PWM_B)
	{
		if (duty == 0)
		{
			/* Fix per glitch quando a 0% */
			pwm1Pins(PWM_INVERT_B);
			write16bit(0xffff, &OCR1BH, &OCR1BL);
		}
		else
		{
			pwm1Pins(pwmPol1B);
			write16bit(duty, &OCR1BH, &OCR1BL);
		}
	}
	else
	{
		
	}
}
示例#4
0
void writeTimer1(uint16_t val)
{
	write16bit(val, &TCNT1H, &TCNT1L);
}
示例#5
0
/**@brief Chiamabile più volte per inizializzare moduli A e B */
void initCompare1 (uint16_t comp_val, _t_compare_sel comp, uint16_t prescaler, _t_edge edge, _t_timer_clock clock, uint8_t timer_int)
{
	initTimer1(prescaler, edge, COMPARE_MATCH, clock, timer_int);
	switch (comp)
	{
		case COMP_A_TOGGLE:
		sbi(TCCR1A, COM1A0);
		cbi(TCCR1A, COM1A1);
		sbi(DDRB, DDB1);
		write16bit(comp_val, &OCR1AH, &OCR1AL);
		OCR1A = comp_val;
		break;
		
		case COMP_A_CLEAR:
		cbi(TCCR1A, COM1A0);
		sbi(TCCR1A, COM1A1);
		sbi(DDRB, DDB1);
		write16bit(comp_val, &OCR1AH, &OCR1AL);
		break;
		
		case COMP_A_SET:
		sbi(TCCR1A, COM1A0);
		sbi(TCCR1A, COM1A1);
		sbi(DDRB, DDB1);
		write16bit(comp_val, &OCR1AH, &OCR1AL);
		break;
		
		case COMP_B_TOGGLE:
		sbi(TCCR1A, COM1B0);
		cbi(TCCR1A, COM1B1);
		sbi(DDRB, DDB2);
		write16bit(comp_val, &OCR1BH, &OCR1BL);
		break;
		
		case COMP_B_CLEAR:
		cbi(TCCR1A, COM1B0);
		sbi(TCCR1A, COM1B1);
		sbi(DDRB, DDB2);
		write16bit(comp_val, &OCR1BH, &OCR1BL);
		break;
		
		case COMP_B_SET:
		sbi(TCCR1A, COM1B0);
		sbi(TCCR1A, COM1B1);
		sbi(DDRB, DDB2);
		write16bit(comp_val, &OCR1BH, &OCR1BL);
		break;
		
		case COMP_A_DISCONNECT:
		cbi(TCCR1A, COM1A0);
		cbi(TCCR1A, COM1A1);
		write16bit(comp_val, &OCR1AH, &OCR1AL);
		break;
		
		case COMP_B_DISCONNECT:
		cbi(TCCR1A, COM1B0);
		cbi(TCCR1A, COM1B1);
		write16bit(comp_val, &OCR1BH, &OCR1BL);
		break;
		
		default:
		/* lascia OCnx sconnesso come lo è da initTimer0*/
		cbi(TCCR1A, COM1B0);
		cbi(TCCR1A, COM1B1);
		cbi(TCCR1A, COM1A0);
		cbi(TCCR1A, COM1A1);
		break;
	}
	
	switch (timer_int)
	{
		case INT_ON:
		/* Non devo chiamare questa funzione se uso il normale */
		if ((comp == COMP_A_CLEAR) || (comp == COMP_A_SET) ||(comp == COMP_A_TOGGLE)||(comp == COMP_A_DISCONNECT))
		{
			sbi(TIMSK1, OCIE1A);
		}
		if ((comp == COMP_B_CLEAR) || (comp == COMP_B_SET) ||(comp == COMP_B_TOGGLE)||(comp == COMP_B_DISCONNECT))
		{
			sbi(TIMSK1, OCIE1B);
		}
		break;
		
		case INT_OFF:
		if ((comp == COMP_A_CLEAR) || (comp == COMP_A_SET) ||(comp == COMP_A_TOGGLE)||(comp == COMP_A_DISCONNECT))
		{
			cbi(TIMSK1, OCIE1A);
		}
		if ((comp == COMP_B_CLEAR) || (comp == COMP_B_SET) ||(comp == COMP_B_TOGGLE)||(comp == COMP_B_DISCONNECT))
		{
			cbi(TIMSK1, OCIE1B);
		}
		break;
		
		default:
		cbi(TIMSK1, OCIE1A);
		cbi(TIMSK1, OCIE1B);
		break;
	}
	
}