int main( void )
{
	led_init();
	timer_init();
	uart_init();
	servo_init();
	ppm_init();
	adc_init();
	input_init();

	sei();

	puts( "$Id: mainloop.c,v 2.14 2003/03/25 17:44:05 tramm Exp $\r\n" );

	while( 1 )
	{
		input_task();
		user_task();

		if( ppm_valid )
		{
			ppm_output();
			ppm_valid = 0;
		}

		/* Every 32768 microseconds */
		if( timer_periodic() == 0 )
			continue;

		adc_output();

	}
}
예제 #2
0
int
main(int argc, char *argv[]) {
    int format;
    int rows, cols;
    pixval maxval;
    int row;
    pixel* pixelrow;
    
    ppm_init(&argc, argv);

    if (argc-1 != 0)
        pm_error("Program takes no arguments.  Input is from Standard Input");

    ppm_readppminit(stdin, &cols, &rows, &maxval, &format);

    ppm_writeppminit(stdout, cols, rows, maxval, 0);

    pixelrow = ppm_allocrow(cols);

    for (row = 0; row < rows; row++) {
        ppm_readppmrow(stdin, pixelrow, cols, maxval, format);
        ppm_writeppmrow(stdout, pixelrow, cols, maxval, 0);
    }
    ppm_freerow(pixelrow);

    pm_close(stdin);

    exit(0);
}
예제 #3
0
int
main(int argc, char ** argv)
{
	struct ppm * picture;
	color_t pixel;
	int i, j;

	picture = ppm_init(WIDTH, HEIGHT);

	for(i = 0; i < WIDTH; i++)
	{
		for(j = 0; j < HEIGHT; j++)
		{
			pixel.red = (float)i * j / (WIDTH * HEIGHT) * 255;
			//i == 2 && j == 2 ? 255 : 0;
			pixel.green = 0;
			pixel.blue = pixel.green;

			ppm_write(picture, i, j, pixel);
		}
	}

	ppm_save(picture, "picture.ppm");

	return 0;
}
예제 #4
0
/********** INIT *************************************************************/
void init_rctx( void ) {
  hw_init();
  sys_time_init();
#ifdef LED
  led_init();
#endif
#ifdef USE_UART1
    Uart1Init();
#endif
#ifdef ADC
  adc_init();
  adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_adc_buf, DEFAULT_AV_NB_SAMPLE);
#endif
#ifdef RADIO_CONTROL
  ppm_init();
#endif
  int_enable();

  /** - wait 0.5s (for modem init ?) */
  uint8_t init_cpt = 30;
  while (init_cpt) {
    if (sys_time_periodic())
      init_cpt--;
  }

#if defined DATALINK
#if DATALINK == XBEE
  xbee_init();
#endif
#endif /* DATALINK */
}
예제 #5
0
int
main(int    argc,
     char * argv[]) {

    struct cmdlineInfo cmdline;
    FILE * ifP;
    unsigned int cols, rows;
    pixval maxval;
    xvPalette xvPalette;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFileName);

    makeXvPalette(&xvPalette);

    readXvHeader(ifP, &cols, &rows, &maxval);

    writePpm(ifP, &xvPalette, cols, rows, maxval, stdout);

    pm_close(ifP);

    return 0;
}
예제 #6
0
파일: ppmmake.c 프로젝트: jhbsz/DIR-850L_A1
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    pixel * pixrow;
    unsigned int row;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ppm_writeppminit(stdout, cmdline.cols, cmdline.rows, cmdline.maxval, 0);
    pixrow = ppm_allocrow(cmdline.cols);

    for (row = 0; row < cmdline.rows; ++row) {
        unsigned int col;
        for (col = 0; col < cmdline.cols; ++col)
            pixrow[col] = cmdline.color;
        ppm_writeppmrow(stdout, pixrow, cmdline.cols, cmdline.maxval, 0);
	}

    ppm_freerow(pixrow);
    pm_close(stdout);

    return 0;
}
예제 #7
0
int main(int argc, char **argv) {
	int i;

	ppm_init(&argc, argv);
	for (i = 1; i < argc; i++)
		process_file(argv[i]);
	return 0;
}
예제 #8
0
int main(int argc, char **argv)
{
    FILE            *ifp;
    pixel           **pixels;
    int             rows, row, cols, col,
                    pal_len, i;
    pixval          maxval;
    struct cmdlineInfo
                    cmdline;
    unsigned char   rgb[NUM_COLORS][3];
    char            ansi_code[NUM_COLORS][MAX_ANSI_STR_LEN];

    
    ppm_init(&argc, argv);    

    parseCommandLine(argc, argv, &cmdline);

    ifp = pm_openr(cmdline.inputFilespec);
    
    pixels = ppm_readppm(ifp, &cols, &rows, &maxval);

    pm_close(ifp);
        
    pal_len=generate_palette(rgb, ansi_code);
    
    for (row = 0; row < rows; ++row) {
        for (col = 0; col < cols; col++) {
            pixval const r=(int)PPM_GETR(pixels[row][col])*255/maxval;
            pixval const g=(int)PPM_GETG(pixels[row][col])*255/maxval;
            pixval const b=(int)PPM_GETB(pixels[row][col])*255/maxval;
            int val, dist;
            
            /*
            The following loop calculates the index that
            corresponds to the minimum color distance
            between the given RGB values and the values
            available in the palette.
            */
            for(i=0, dist=sqr(255)*3, val=0; i<pal_len; i++) {
                pixval const pr=rgb[i][0];
                pixval const pg=rgb[i][1];
                pixval const pb=rgb[i][2];
                unsigned int j;
                if( (j=sqr(r-pr)+sqr(b-pb)+sqr(g-pg))<dist ) {
                    dist=j;
                    val=i;
                }
            }
            printf("%s%c", ansi_code[val],0xB1);
        }
        printf(ESC"\x30m\n");
    }
    printf(ESC"\x30m");

    ppm_freearray(pixels, rows);
    
    exit(0);
}
예제 #9
0
int
main(int argc, char **argv) {

    ppm_init(&argc, argv);

    writeBuiltinFont(stdout);
    
    return 0;
}
예제 #10
0
파일: main.c 프로젝트: pcarrigg/OpenSky-1
void main(void) {
    //leds:
    LED_INIT();

    //init clock source XOSC:
    clocksource_init();

    //init uart
    uart_init();

    //init wdt timer
    wdt_init();

    apa102_init();

    //init storage
    storage_init();

    //enable timeout routines
    timeout_init();

    //apa102_init();

    //init frsky core
    frsky_init();

    //init adc
    adc_init();

    //init output
    #if SBUS_ENABLED
    sbus_init();
    #else
    ppm_init();
    #endif

    //init failsafe
    failsafe_init();

    debug("main: init done\n");

    //run main
    //frsky_frame_sniffer();
    frsky_main();

    LED_RED_ON();
    while (1) {
        LED_RED_ON();
        delay_ms(200);
        LED_RED_OFF();
        delay_ms(200);
    }
}
예제 #11
0
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;

    FILE * ifP;

    /* Parameters of input image: */
    int rows, cols;
    pixval maxval;
    int format;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilename);

    ppm_readppminit(ifP, &cols, &rows, &maxval, &format);
    pbm_writepbminit(stdout, cols, rows, 0);
    {
        pixel * const inputRow = ppm_allocrow(cols);
        bit *   const maskRow  = pbm_allocrow(cols);

        unsigned int numPixelsMasked;

        unsigned int row;
        for (row = 0, numPixelsMasked = 0; row < rows; ++row) {
            int col;
            ppm_readppmrow(ifP, inputRow, cols, maxval, format);
            for (col = 0; col < cols; ++col) {
                if (colorIsInSet(inputRow[col], maxval, cmdline)) {
                    maskRow[col] = PBM_BLACK;
                    ++numPixelsMasked;
                } else 
                    maskRow[col] = PBM_WHITE;
            }
            pbm_writepbmrow(stdout, maskRow, cols, 0);
        }

        if (cmdline.verbose)
            pm_message("%u pixels found matching %u requested colors",
                       numPixelsMasked, cmdline.colorCount);

        pbm_freerow(maskRow);
        ppm_freerow(inputRow);
    }
    pm_close(ifP);

    return 0;
}
예제 #12
0
파일: main.c 프로젝트: OpenUAS/OpenSky
int main(void) {
    // leds:
    led_init();

    // init clock sources:
    clocksource_init();

    // init ios
    io_init();

    // init debug
    debug_init();

    // init wdt timer
    wdt_init();

    // enable timeout routines
    timeout_init();

    // init storage
    storage_init();

    // init frsky core
    frsky_init();

    // init adc
    adc_init();

    // init output
#ifdef SBUS_ENABLED
    sbus_init();
#else  // SBUS_ENABLED
    ppm_init();
#endif  // SBUS_ENABLED

    // init failsafe
    failsafe_init();

    // init telemetry
    telemetry_init();

    // run main
    debug("main: init done\n");

    // frsky_frame_sniffer();
    frsky_main();

    debug("main: frsky main ended?! THIS SHOULD NOT HAPPEN!");
    while (1) {}
}
예제 #13
0
int
main(int argc, char *argv[]) {

    FILE *ifp;
    FILE *alpha_file, *imageout_file;
    pixel *colormap;
    int cols, rows;
    int transparent;  /* value of 'data' that means transparent */
    int *data;
        /* The image as an array of width * height integers, each one
           being an index int colormap[].
        */

    struct cmdline_info cmdline;

    ppm_init(&argc, argv);

    parse_command_line(argc, argv, &cmdline);

    verbose = cmdline.verbose;

    if ( cmdline.input_filespec != NULL ) 
        ifp = pm_openr( cmdline.input_filespec);
    else
        ifp = stdin;

    if (cmdline.alpha_stdout)
        alpha_file = stdout;
    else if (cmdline.alpha_filename == NULL) 
        alpha_file = NULL;
    else {
        alpha_file = pm_openw(cmdline.alpha_filename);
    }

    if (cmdline.alpha_stdout) 
        imageout_file = NULL;
    else
        imageout_file = stdout;

    ReadXPMFile(ifp, &cols, &rows, &colormap, &data, &transparent);
    
    pm_close(ifp);

    writeOutput(imageout_file, alpha_file, cols, rows, colormap, data,
                transparent);

    free(colormap);
    
    return 0;
}
예제 #14
0
파일: main.c 프로젝트: fliedpig/ALF-llvm
void fbw_init(void) {
  uart_init_tx();
  uart_print_string("FBW Booting $Id: main.c,v 1.3 2008/10/22 19:41:19 casse Exp $\n");

#ifndef CTL_BRD_V1_1
  fbw_adc_init();
  fbw_adc_buf_channel(3, &vsupply_adc_buf);
  fbw_adc_buf_channel(6, &vservos_adc_buf);
#endif
  timer_init();
  servo_init();
  ppm_init();
  fbw_spi_init();
  //sei(); //FN
}
예제 #15
0
void fbw_init(void) {
  uart_init_tx();
  uart_print_string("FBW Booting $Id: main.c,v 1.4 2011-01-25 10:42:14 plazar Exp $\n");

#ifndef CTL_BRD_V1_1
  fbw_adc_init();
  fbw_adc_buf_channel(3, &vsupply_adc_buf);
  fbw_adc_buf_channel(6, &vservos_adc_buf);
#endif
  timer_init();
  servo_init();
  ppm_init();
  fbw_spi_init();
  //sei(); //FN
}
예제 #16
0
int
main(int argc, char *argv[]) {

    FILE* ifP;
    const char * inputFilespec;
    int eof;
    
    ppm_init( &argc, argv );

    if (argc-1 > 1)
        pm_error("The only argument is the (optional) input filename");

    if (argc == 2)
        inputFilespec = argv[1];
    else
        inputFilespec = "-";
    
    ifP = pm_openr(inputFilespec);

    eof = FALSE;  /* initial assumption */

    while (!eof) {
        ppm_nextimage(ifP, &eof);
        if (!eof) {
            int rows, cols, format;
            pixval maxval;
            pixel* inputRow;
            gray* outputRow;

            ppm_readppminit(ifP, &cols, &rows, &maxval, &format);
            pgm_writepgminit(stdout, cols, rows, maxval, 0);

            inputRow = ppm_allocrow(cols);
            outputRow = pgm_allocrow(cols);

            convertRaster(ifP, cols, rows, maxval, format, 
                          inputRow, outputRow, stdout);

            ppm_freerow(inputRow);
            pgm_freerow(outputRow);
        }
    }
    pm_close(ifP);
    pm_close(stdout);

    return 0;
}
예제 #17
0
int main(int argc, char **argv) {
	int i;

	ppm_init(&argc, argv);
	for (i = 0; i < 256; i++)
		PPM_ASSIGN(cmap[i], i, i, i);

	i = 1;
	if (argc >= 3 && strncmp(argv[1], "-c", 2) == 0) {
		read_cmp(argv[2]);
		i = 3;
	}
	for (; i < argc; i++)
		process_file(argv[i]);

	return 0;
}
예제 #18
0
int 
main(int argc, char ** argv) {

    struct cmdlineInfo cmdline;

    MS_Ico const MSIconDataP = createIconFile();
    unsigned int iconIndex;
    unsigned int offset;
   
    ppm_init (&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    verbose = cmdline.verbose;

    for (iconIndex = 0; iconIndex < cmdline.iconCount; ++iconIndex) {
        addEntryToIcon(MSIconDataP, cmdline.inputFilespec[iconIndex],
                       cmdline.andpgmFilespec[iconIndex], 
                       cmdline.truetransparent);
    }
    /*
     * Now we have to go through and calculate the offsets.
     * The first infoheader starts at 6 + count*16 bytes.
     */
    offset = (MSIconDataP->count * 16) + 6;
    for (iconIndex = 0; iconIndex < MSIconDataP->count; ++iconIndex) {
        IC_Entry entry = MSIconDataP->entries[iconIndex];
        entry->file_offset = offset;
        /* 
         * Increase the offset by the size of this offset & data.
         * this includes the size of the color data.
         */
        offset += entry->size_in_bytes;
    }
    /*
     * And now, we have to actually SAVE the .ico!
     */
    writeMS_Ico(MSIconDataP, cmdline.output);

    free(cmdline.inputFilespec);
    free(cmdline.andpgmFilespec);

    return 0;
}
예제 #19
0
static void csc_main_init( void ) {

  mcu_init();
  sys_time_init();
  led_init();

  Uart0Init();
  Uart1Init();

  ppm_init();

  // Configure P0.21 as GPIO, output and then pull high as we use it to drive ppm input transistor
  PINSEL1 = PINSEL1 & ~(0x3 << 10);
  IO0DIR = IO0DIR | (0x1 << 21);
  IO0PIN = IO0DIR | (0x1 << 21);

  mcu_int_enable();

}
예제 #20
0
/********** INIT *************************************************************/
void init_fbw( void ) {
  hw_init();
  sys_time_init();
#ifdef LED
  led_init();
#endif
#ifdef USE_UART0
  uart0_init_tx();
#endif
#ifdef USE_UART1
  uart1_init_tx();
#endif
#ifdef ADC
  adc_init();
  adc_buf_channel(ADC_CHANNEL_VSUPPLY, &vsupply_adc_buf, DEFAULT_AV_NB_SAMPLE);
#endif
#ifdef ACTUATORS
  actuators_init();
  /* Load the failsafe defaults */
  SetCommands(commands_failsafe);
#endif
#ifdef RADIO_CONTROL
 ppm_init();
#endif
#ifdef INTER_MCU
 inter_mcu_init();
#endif
#ifdef MCU_SPI_LINK
 spi_init();
 link_mcu_restart();
#endif
#ifdef LINK_IMU
 spi_init();
 link_imu_init();
#endif
#ifdef CTL_GRZ
 ctl_grz_init();
#endif
#ifndef SINGLE_MCU
  int_enable();
#endif
}
예제 #21
0
int
main(int    argc,
     char * argv[]) {

    FILE * ifP;
    struct cmdlineInfo cmdline;
    gray * grayrow;
    pixel * pixelrow;
    int rows, cols, format;
    gray maxval;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilename);

    pgm_readpgminit(ifP, &cols, &rows, &maxval, &format);
    grayrow = pgm_allocrow(cols);
    pixelrow = ppm_allocrow(cols);

    if (cmdline.map)
        convertWithMap(ifP, cols, rows, maxval, format, cmdline.map,
                       stdout, grayrow, pixelrow);
    else
        convertLinear(ifP, cols, rows, maxval, format, 
                      cmdline.colorBlack, cmdline.colorWhite, stdout,
                      grayrow, pixelrow);

    ppm_freerow(pixelrow);
    pgm_freerow(grayrow);
    pm_close(ifP);

    /* If the program failed, it previously aborted with nonzero completion
       code, via various function calls.
    */
    return 0;
}
예제 #22
0
/**
* @brief Initialize the whole system
*
* All functions that need to be called before the first mainloop iteration
* should be placed here.
*/
void main_init_generic(void)
{

	// Reset to safe values
	global_data_reset();

	// Load default eeprom parameters as fallback
	global_data_reset_param_defaults();

	// LOWLEVEL INIT, ONLY VERY BASIC SYSTEM FUNCTIONS
	hw_init();
	enableIRQ();
	led_init();
	led_on(LED_GREEN);
	buzzer_init();
	sys_time_init();
	sys_time_periodic_init();
	sys_time_clock_init();
	ppm_init();
	pwm_init();

	// Lowlevel periphel support init
	adc_init();
	// FIXME SDCARD
//	MMC_IO_Init();
	spi_init();
	i2c_init();

	// Sensor init
	sensors_init();
	debug_message_buffer("Sensor initialized");

	// Shutter init
	shutter_init();
	shutter_control(0);

	// Debug output init
	debug_message_init();
	debug_message_buffer("Text message buffer initialized");

	// MEDIUM LEVEL INIT, INITIALIZE I2C, EEPROM, WAIT FOR MOTOR CONTROLLERS
	// Try to reach the EEPROM
	eeprom_check_start();

	// WAIT FOR 2 SECONDS FOR THE USER TO NOT TOUCH THE UNIT
	while (sys_time_clock_get_time_usec() < 2000000)
	{
	}

	// Do the auto-gyro calibration for 1 second
	// Get current temperature
	led_on(LED_RED);
	gyro_init();

//	uint8_t timeout = 3;
//	// Check for SD card
//	while (sys_time_clock_get_time_usec() < 2000000)
//	{
//		while (GetDriveInformation() != F_OK && timeout--)
//		  {
//		   debug_message_buffer("MMC/SD-Card not found ! retrying..");
//		  }
//	}
//
//	if (GetDriveInformation() == F_OK)
//	{
//		debug_message_buffer("MMC/SD-Card SUCCESS: FOUND");
//	}
//	else
//	{
//		debug_message_buffer("MMC/SD-Card FAILURE: NOT FOUND");
//	}
	//FIXME redo init because of SD driver decreasing speed
	//spi_init();
	led_off(LED_RED);

	// Stop trying to reach the EEPROM - if it has not been found by now, assume
	// there is no EEPROM mounted
	if (eeprom_check_ok())
	{
		param_read_all();
		debug_message_buffer("EEPROM detected - reading parameters from EEPROM");

		for (int i = 0; i < ONBOARD_PARAM_COUNT * 2 + 20; i++)
		{
			param_handler();
			//sleep 1 ms
			sys_time_wait(1000);
		}
	}
	else
	{
		debug_message_buffer("NO EEPROM - reading onboard parameters from FLASH");
	}

	// Set mavlink system
	mavlink_system.compid = MAV_COMP_ID_IMU;
	mavlink_system.sysid = global_data.param[PARAM_SYSTEM_ID];

	//Magnet sensor
	hmc5843_init();
	acc_init();

	// Comm parameter init
	mavlink_system.sysid = global_data.param[PARAM_SYSTEM_ID]; // System ID, 1-255
	mavlink_system.compid = global_data.param[PARAM_COMPONENT_ID]; // Component/Subsystem ID, 1-255

	// Comm init has to be
	// AFTER PARAM INIT
	comm_init(MAVLINK_COMM_0);
	comm_init(MAVLINK_COMM_1);

	// UART initialized, now initialize COMM peripherals
	communication_init();
	gps_init();

	us_run_init();

	servos_init();

	//position_kalman3_init();

	// Calibration starts (this can take a few seconds)
	//	led_on(LED_GREEN);
	//	led_on(LED_RED);

	// Read out first time battery
	global_data.battery_voltage = battery_get_value();

	global_data.state.mav_mode = MAV_MODE_PREFLIGHT;
	global_data.state.status = MAV_STATE_CALIBRATING;

	send_system_state();

	float_vect3 init_state_accel;
	init_state_accel.x = 0.0f;
	init_state_accel.y = 0.0f;
	init_state_accel.z = -1000.0f;
	float_vect3 init_state_magnet;
	init_state_magnet.x = 1.0f;
	init_state_magnet.y = 0.0f;
	init_state_magnet.z = 0.0f;


	//auto_calibration();


	attitude_observer_init(init_state_accel, init_state_magnet);

	debug_message_buffer("Attitude Filter initialized");
	led_on(LED_RED);

	send_system_state();

	debug_message_buffer("System is initialized");

	// Calibration stopped
	led_off(LED_RED);

	global_data.state.mav_mode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
	global_data.state.status = MAV_STATE_STANDBY;

	send_system_state();

	debug_message_buffer("Checking if remote control is switched on:");
	// Initialize remote control status
	remote_control();
	remote_control();
	if (radio_control_status() == RADIO_CONTROL_ON && global_data.state.remote_ok)
	{
		global_data.state.mav_mode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED | MAV_MODE_FLAG_TEST_ENABLED;
		debug_message_buffer("RESULT: remote control switched ON");
		debug_message_buffer("Now in MAV_MODE_TEST2 position hold tobi_laurens");
		led_on(LED_GREEN);
	}
	else
	{
		global_data.state.mav_mode = MAV_MODE_FLAG_MANUAL_INPUT_ENABLED;
		debug_message_buffer("RESULT: remote control switched OFF");
		led_off(LED_GREEN);
	}
}
예제 #23
0
int
main(int argc, char **argv) {

    struct cmdlineInfo cmdline;
    FILE *vf,*uf,*yf;
    int cols, rows;
    pixel *pixelrow1,*pixelrow2;
    int row;
    unsigned char  *y1buf,*y2buf,*ubuf,*vbuf;
    const char * ufname;
    const char * vfname;
    const char * yfname;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);
        
    asprintfN(&ufname, "%s.U", cmdline.filenameBase);
    asprintfN(&vfname, "%s.V", cmdline.filenameBase);
    asprintfN(&yfname, "%s.Y", cmdline.filenameBase);

    uf = pm_openr(ufname);
    vf = pm_openr(vfname);
    yf = pm_openr(yfname);

    ppm_writeppminit(stdout, cmdline.width, cmdline.height, 255, 0);

    if (cmdline.width % 2 != 0) {
        pm_message("Warning: odd width; last column ignored");
        cols = cmdline.width - 1;
    } else
        cols = cmdline.width;

    if (cmdline.height % 2 != 0) {
        pm_message("Warning: odd height; last row ignored");
        rows = cmdline.height - 1;
    } else 
        rows = cmdline.height;

    pixelrow1 = ppm_allocrow(cols);
    pixelrow2 = ppm_allocrow(cols);

    MALLOCARRAY_NOFAIL(y1buf, cmdline.width);
    MALLOCARRAY_NOFAIL(y2buf, cmdline.width);
    MALLOCARRAY_NOFAIL(ubuf,  cmdline.width/2);
    MALLOCARRAY_NOFAIL(vbuf,  cmdline.width/2);

    for (row = 0; row < rows; row += 2) {
        fread(y1buf, cmdline.width,   1, yf);
        fread(y2buf, cmdline.width,   1, yf);
        fread(ubuf,  cmdline.width/2, 1, uf);
        fread(vbuf,  cmdline.width/2, 1, vf);

        computeTwoOutputRows(cols, cmdline.ccir601,
                             y1buf, y2buf, ubuf, vbuf,
                             pixelrow1, pixelrow2);

        ppm_writeppmrow(stdout, pixelrow1, cols, (pixval) 255, 0);
        ppm_writeppmrow(stdout, pixelrow2, cols, (pixval) 255, 0);
    }
    pm_close(stdout);

    strfree(yfname);
    strfree(vfname);
    strfree(ufname);

    pm_close(yf);
    pm_close(uf);
    pm_close(vf);

    exit(0);
}
예제 #24
0
파일: ppmcie.c 프로젝트: Eleanor66613/CS131
int
main(int argc,
     char * argv[]) {

    int argn;
    const char * const usage = "[-[no]black] [-[no]wpoint] [-[no]label] [-no[axes]] [-full]\n\
[-xy|-upvp] [-rec709|-ntsc|-ebu|-smpte|-hdtv|-cie]\n\
[-red <x> <y>] [-green <x> <y>] [-blue <x> <y>]\n\
[-white <x> <y>] [-gamma <g>]\n\
[-size <s>] [-xsize|-width <x>] [-ysize|-height <y>]";
    const struct colorSystem *cs;

    int widspec = FALSE, hgtspec = FALSE;
    int xBias, yBias;
    int upvp = FALSE;             /* xy or u'v' color coordinates? */
    int showWhite = TRUE;             /* Show white point ? */
    int showBlack = TRUE;             /* Show black body curve ? */
    int fullChart = FALSE;            /* Fill entire tongue ? */
    int showLabel = TRUE;             /* Show labels ? */
    int showAxes = TRUE;              /* Plot axes ? */

    ppm_init(&argc, argv);
    argn = 1;

    cs = &Rec709system;  /* default */
    while (argn < argc && argv[argn][0] == '-' && argv[argn][1] != '\0') {
        if (pm_keymatch(argv[argn], "-xy", 2)) {
            upvp = FALSE;
        } else if (pm_keymatch(argv[argn], "-upvp", 1)) {
            upvp = TRUE;
        } else if (pm_keymatch(argv[argn], "-xsize", 1) ||
                   pm_keymatch(argv[argn], "-width", 2)) {
            if (widspec) {
                pm_error("already specified a size/width/xsize");
            }
            argn++;
            if ((argn == argc) || (sscanf(argv[argn], "%d", &sxsize) != 1))
                pm_usage(usage);
            widspec = TRUE;
        } else if (pm_keymatch(argv[argn], "-ysize", 1) ||
                   pm_keymatch(argv[argn], "-height", 2)) {
            if (hgtspec) {
                pm_error("already specified a size/height/ysize");
            }
            argn++;
            if ((argn == argc) || (sscanf(argv[argn], "%d", &sysize) != 1))
                pm_usage(usage);
            hgtspec = TRUE;
        } else if (pm_keymatch(argv[argn], "-size", 2)) {
            if (hgtspec || widspec) {
                pm_error("already specified a size/height/ysize");
            }
            argn++;
            if ((argn == argc) || (sscanf(argv[argn], "%d", &sysize) != 1))
                pm_usage(usage);
            sxsize = sysize;
            hgtspec = widspec = TRUE;
        } else if (pm_keymatch(argv[argn], "-rec709", 1)) {
            cs = &Rec709system;
        } else if (pm_keymatch(argv[argn], "-ntsc", 1)) {
            cs = &NTSCsystem;
        } else if (pm_keymatch(argv[argn], "-ebu", 1)) {
            cs = &EBUsystem;
        } else if (pm_keymatch(argv[argn], "-smpte", 2)) {
            cs = &SMPTEsystem;
        } else if (pm_keymatch(argv[argn], "-hdtv", 2)) {
            cs = &HDTVsystem;                 
        } else if (pm_keymatch(argv[argn], "-cie", 1)) {
            cs = &CIEsystem;                 
        } else if (pm_keymatch(argv[argn], "-black", 3)) {
            showBlack = TRUE;         /* Show black body curve */
        } else if (pm_keymatch(argv[argn], "-wpoint", 2)) {
            showWhite = TRUE;         /* Show white point of color system */
        } else if (pm_keymatch(argv[argn], "-noblack", 3)) {
            showBlack = FALSE;        /* Don't show black body curve */
        } else if (pm_keymatch(argv[argn], "-nowpoint", 3)) {
            showWhite = FALSE;        /* Don't show white point of system */
        } else if (pm_keymatch(argv[argn], "-label", 1)) {
            showLabel = TRUE;         /* Show labels. */
        } else if (pm_keymatch(argv[argn], "-nolabel", 3)) {
            showLabel = FALSE;        /* Don't show labels */
        } else if (pm_keymatch(argv[argn], "-axes", 1)) {
            showAxes = TRUE;          /* Show axes. */
        } else if (pm_keymatch(argv[argn], "-noaxes", 3)) {
            showAxes = FALSE;         /* Don't show axes */
        } else if (pm_keymatch(argv[argn], "-full", 1)) {
            fullChart = TRUE;         /* Fill whole tongue full-intensity */
        } else if (pm_keymatch(argv[argn], "-gamma", 2)) {
            cs = &Customsystem;
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.gamma) != 1))
                pm_usage(usage);
        } else if (pm_keymatch(argv[argn], "-red", 1)) {
            cs = &Customsystem;
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.xRed) != 1))
                pm_usage(usage);
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.yRed) != 1))
                pm_usage(usage);
        } else if (pm_keymatch(argv[argn], "-green", 1)) {
            cs = &Customsystem;
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.xGreen) != 1))
                pm_usage(usage);
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.yGreen) != 1))
                pm_usage(usage);
        } else if (pm_keymatch(argv[argn], "-blue", 1)) {
            cs = &Customsystem;
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.xBlue) != 1))
                pm_usage(usage);
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.yBlue) != 1))
                pm_usage(usage);
        } else if (pm_keymatch(argv[argn], "-white", 1)) {
            cs = &Customsystem;
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.xWhite) != 1))
                pm_usage(usage);
            argn++;
            if ((argn == argc) ||
                (sscanf(argv[argn], "%lf", &Customsystem.yWhite) != 1))
                pm_usage(usage);
        } else {
            pm_usage(usage);
        }
        argn++;
    }

    if (argn != argc) {               /* Extra bogus arguments ? */
        pm_usage(usage);
    }

    pixcols = sxsize;
    pixrows = sysize;

    pixels = ppm_allocarray(pixcols, pixrows);

    /* Partition into plot area and axes and establish subwindow. */

    xBias = Sz(32);
    yBias = Sz(20);

    makeAllBlack(pixels, pixcols, pixrows);

    drawTongueOutline(pixels, pixcols, pixrows, Maxval, upvp, xBias, yBias);

    fillInTongue(pixels, pixcols, pixrows, Maxval, cs, upvp, xBias, yBias,
                 fullChart);

    if (showAxes)
        drawAxes(pixels, pixcols, pixrows, Maxval, upvp, xBias, yBias);

    if (showWhite)
        plotWhitePoint(pixels, pixcols, pixrows, Maxval,
                       cs, upvp, xBias, yBias);

    if (showBlack)
        plotBlackBodyCurve(pixels, pixcols, pixrows, Maxval,
                           upvp, xBias, yBias);

    /* Plot wavelengths around periphery of the tongue. */

    if (showAxes)
        plotMonochromeWavelengths(pixels, pixcols, pixrows, Maxval,
                                  cs, upvp, xBias, yBias);

    if (showLabel)
        writeLabel(pixels, pixcols, pixrows, Maxval, cs);

    ppm_writeppm(stdout, pixels, pixcols, pixrows, Maxval, FALSE);

    return 0;
}
예제 #25
0
파일: ppm3d.c 프로젝트: jhbsz/DIR-850L_A1
int
main (int argc, char *argv[]) {

    int offset; 
    int cols, rows, row;
    pixel* pixelrow;
    pixval maxval;

    FILE* Lifp;
    pixel* Lpixelrow;
    gray* Lgrayrow;
    int Lrows, Lcols, Lformat;
    pixval Lmaxval;
   
    FILE* Rifp;
    pixel* Rpixelrow;
    gray* Rgrayrow;
    int Rrows, Rcols, Rformat;
    pixval Rmaxval;
   
    ppm_init (&argc, argv);

    if (argc-1 > 3 || argc-1 < 2) 
        pm_error("Wrong number of arguments (%d).  Arguments are "
                 "leftppmfile rightppmfile [horizontal_offset]", argc-1);

    Lifp = pm_openr (argv[1]);
    Rifp = pm_openr (argv[2]);

    if (argc-1 >= 3) 
        offset = atoi (argv[3]);
    else
        offset = 30;

    ppm_readppminit (Lifp, &Lcols, &Lrows, &Lmaxval, &Lformat);
    ppm_readppminit (Rifp, &Rcols, &Rrows, &Rmaxval, &Rformat);
    
    if ((Lcols != Rcols) || (Lrows != Rrows) || 
        (Lmaxval != Rmaxval) || 
        (PPM_FORMAT_TYPE(Lformat) != PPM_FORMAT_TYPE(Rformat)))
        pm_error ("Pictures are not of same size and format");
    
    cols = Lcols;
    rows = Lrows;
    maxval = Lmaxval;
   
    ppm_writeppminit (stdout, cols, rows, maxval, 0);
    Lpixelrow = ppm_allocrow (cols);
    Lgrayrow = pgm_allocrow (cols);
    Rpixelrow = ppm_allocrow (cols);
    Rgrayrow = pgm_allocrow (cols);
    pixelrow = ppm_allocrow (cols);

    for (row = 0; row < rows; ++row) {
        ppm_readppmrow(Lifp, Lpixelrow, cols, maxval, Lformat);
        ppm_readppmrow(Rifp, Rpixelrow, cols, maxval, Rformat);

        computeGrayscaleRow(Lpixelrow, Lgrayrow, maxval, cols);
        computeGrayscaleRow(Rpixelrow, Rgrayrow, maxval, cols);
        {
            int col;
            gray* LgP;
            gray* RgP;
            pixel* pP;
            for (col = 0, pP = pixelrow, LgP = Lgrayrow, RgP = Rgrayrow;
                 col < cols + offset;
                 ++col) {
            
                if (col < offset/2)
                    ++LgP;
                else if (col >= offset/2 && col < offset) {
                    const pixval Blue = (pixval) (float) *LgP;
                    const pixval Red = (pixval) 0;
                    PPM_ASSIGN (*pP, Red, Blue, Blue);
                    ++LgP;
                    ++pP;
                } else if (col >= offset && col < cols) {
                    const pixval Red = (pixval) (float) *RgP;
                    const pixval Blue = (pixval) (float) *LgP;
                    PPM_ASSIGN (*pP, Red, Blue, Blue);
                    ++LgP;
                    ++RgP;
                    ++pP;
                } else if (col >= cols && col < cols + offset/2) {
                    const pixval Blue = (pixval) 0;
                    const pixval Red = (pixval) (float) *RgP;
                    PPM_ASSIGN (*pP, Red, Blue, Blue);
                    ++RgP;
                    ++pP;
                } else
                    ++RgP;
            }
        }    
        ppm_writeppmrow(stdout, pixelrow, cols, maxval, 0);
    }

    pm_close(Lifp);
    pm_close(Rifp);
    pm_close(stdout);

    return 0;
}
예제 #26
0
int main(int argc, char *argv[])
{
    bool gui = false;
    QApplication app(argc, argv, gui);
    QProxyStyle * style = new QProxyStyle();
    app.setStyle(style);

    struct statsd_info
    {
        statsd_info() : host("127.0.0.1"), port(8125), ns(std::string(ICHABOD_NAME)+"."), enabled(false) {}
        std::string host;
        int port;
        std::string ns;
        bool enabled;
    };
    statsd_info statsd;

    int port = 9090;
    QStringList args = app.arguments();
    QRegExp rxPort("--port=([0-9]{1,})");
    QRegExp rxVerbose("--verbosity=([0-9]{1,})");
    QRegExp rxEngineVerbose("--engine-verbosity=([0-9]{1,})");
    QRegExp rxConvertVerbose("--convert-verbosity=([0-9]{1,})");
    QRegExp rxSlowResponseMs("--slow-response-ms=([0-9]{1,})");
    QRegExp rxQuantize("--quantize=([a-zA-Z]{1,})");
    QRegExp rxVersion("--version");
    QRegExp rxShortVersion("-v$");
    QRegExp rxStatsdHost("--statsd-host=([^ ]+)");
    QRegExp rxStatsdPort("--statsd-port=([0-9]{1,})");
    QRegExp rxStatsdNs("--statsd-ns=([^ ]+)");

    for (int i = 1; i < args.size(); ++i) {
        if (rxPort.indexIn(args.at(i)) != -1 )
        {
            port =  rxPort.cap(1).toInt();
        }
        else if (rxVerbose.indexIn(args.at(i)) != -1 )
        {
            g_verbosity = rxVerbose.cap(1).toInt();
        }
        else if (rxEngineVerbose.indexIn(args.at(i)) != -1 )
        {
            g_engine_verbosity = rxEngineVerbose.cap(1).toInt();
        }
        else if (rxConvertVerbose.indexIn(args.at(i)) != -1 )
        {
            g_convert_verbosity = rxConvertVerbose.cap(1).toInt();
        }
        else if (rxSlowResponseMs.indexIn(args.at(i)) != -1 )
        {
            g_slow_response_ms = rxSlowResponseMs.cap(1).toInt();
        }
        else if (rxQuantize.indexIn(args.at(i)) != -1 )
        {
            g_quantize = rxQuantize.cap(1);
        }
        else if (rxVersion.indexIn(args.at(i)) != -1 )
        {
            std::cout << ICHABOD_NAME << " version " << ICHABOD_VERSION << std::endl;
            std::cout << "** The GIFLIB distribution is Copyright (c) 1997  Eric S. Raymond" << std::endl;
            std::cout << "** ppmquant is Copyright (C) 1989, 1991 by Jef Poskanzer." << std::endl;
            std::cout << "** statsd-client-cpp is Copyright (c) 2014, Rex" << std::endl;
            std::cout << "**" << std::endl;
            std::cout << "** Permission to use, copy, modify, and distribute this software and its" << std::endl;
            std::cout << "** documentation for any purpose and without fee is hereby granted, provided" << std::endl;
            std::cout << "** that the above copyright notice appear in all copies and that both that" << std::endl;
            std::cout << "** copyright notice and this permission notice appear in supporting" << std::endl;
            std::cout << "** documentation.  This software is provided \"as is\" without express or" << std::endl;
            std::cout << "** implied warranty." << std::endl;
            std::cout << "**" << std::endl;
            ppm_init( &argc, argv );
            return 0;
        }
        else if (rxShortVersion.indexIn(args.at(i)) != -1)
        {
            std::cout << ICHABOD_VERSION << std::endl;
            return 0;
        }
        else if (rxStatsdHost.indexIn(args.at(i)) != -1)
        {
            statsd.host = rxStatsdHost.cap(1).toLocal8Bit().constData();
            statsd.enabled = true;
        }
        else if (rxStatsdPort.indexIn(args.at(i)) != -1)
        {
            statsd.port = rxStatsdPort.cap(1).toInt();
            statsd.enabled = true;
        }
        else if (rxStatsdNs.indexIn(args.at(i)) != -1)
        {
            statsd.ns = rxStatsdNs.cap(1).toLocal8Bit().constData();
            if ( statsd.ns.length() && *statsd.ns.rbegin() != '.' )
            {
                statsd.ns += ".";
            }
            statsd.enabled = true;
        }
        else
        {
            std::cerr << "Unknown arg:" << args.at(i).toLocal8Bit().constData() << std::endl;
            return -1;
        }
    }

    ppm_init( &argc, argv );

    struct mg_server *server = mg_create_server(NULL, ev_handler);

    const char * err = mg_set_option(server, "listening_port", QString::number(port).toLocal8Bit().constData());
    if ( err )
    {
        std::cerr << "Cannot bind to port:" << port << " [" << err << "], exiting." << std::endl;
        return -1;
    }
    std::cout << ICHABOD_NAME << " " << ICHABOD_VERSION
              << " (port:" << mg_get_option(server, "listening_port")
              << " verbosity:" << g_verbosity
              << " engine verbosity:" << g_engine_verbosity
              << " convert verbosity:" << g_convert_verbosity
              << " slow-response:" << g_slow_response_ms << "ms";
    if ( statsd.enabled )
    {
        std::cout << " statsd:" << statsd.host << ":" << statsd.port << "[" << statsd.ns << "]";
        g_statsd.config(statsd.host, statsd.port, statsd.ns);
    }
    std::cout << ")" << std::endl;

    for (;;)
    {
        mg_poll_server(server, 1000);
    }

    mg_destroy_server(&server);

    return 0;
}
예제 #27
0
int
main(int argc, char *argv[]) {

    FILE *ifp;
    int rows, cols;
    unsigned int ncolors;
    bool transparentSomewhere;
    pixval maxval, alphaMaxval;
    colorhash_table cht;
    colorhist_vector chv;

    colorhash_table colornameHash;
        /* Hash table to map colors to their names */
    const char ** colornames;
        /* Table of color names; 'colornameHash' yields an index into this
           array.
        */

    pixel **pixels;
    gray **alpha;

    /* Used for rgb value -> character-pixel string mapping */
    cixel_map *cmap;  /* malloc'ed */
        /* The XPM colormap */
    unsigned int cmapSize;
        /* Number of entries in 'cmap' */
    unsigned int transIndex;
        /* Index into 'cmap' of the transparent color, if there is one */

    unsigned int charsPerPixel;  

    struct cmdlineInfo cmdline;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifp = pm_openr(cmdline.inputFilename);
    pixels = ppm_readppm(ifp, &cols, &rows, &maxval);
    pm_close(ifp);

    if (cmdline.alpha_filename) 
        readAlpha(cmdline.alpha_filename, &alpha, cols, rows, &alphaMaxval);
    else
        alpha = NULL;

    computeColormap(pixels, alpha, cols, rows, alphaMaxval,
                    &chv, &cht, &ncolors, &transparentSomewhere);

    if (cmdline.hexonly)
        colornameHash = NULL;
    else if (cmdline.rgb)
        ppm_readcolornamefile(cmdline.rgb, TRUE, &colornameHash, &colornames);
    else
        ppm_readcolornamefile(NULL, FALSE, &colornameHash, &colornames);

    /* Now generate the character-pixel colormap table. */
    genCmap(chv, ncolors, maxval, 
            colornameHash, colornames, transparentSomewhere, 
            &cmap, &transIndex, &cmapSize, &charsPerPixel);

    writeXpmFile(stdout, pixels, alpha, alphaMaxval,
                 cmdline.name, cols, rows, cmapSize,
                 charsPerPixel, cmap, cht, transIndex);
    
    if (colornameHash) {
        ppm_freecolorhash(colornameHash);
        ppm_freecolornames(colornames);
    }
    destroyCmap(cmap, cmapSize);
    ppm_freearray(pixels, rows);
    if (alpha) pgm_freearray(alpha, rows);

    return 0;
}
예제 #28
0
int
main(int argc, char *argv[]) {

    struct cmdlineInfo cmdline;
    FILE* ifP;
    int rows, cols;
    pixval maxval;
    pixel **pixels;
    struct pcxCmapEntry * pcxcmap;
    colorhash_table cht;
    bool truecolor;
    int colors;

    ppm_init(&argc, argv);

    parseCommandLine(argc, argv, &cmdline);

    ifP = pm_openr(cmdline.inputFilespec);
    pixels = ppm_readppm(ifP, &cols, &rows, &maxval);
    pm_close(ifP);

    if (cmdline.truecolor)
        truecolor = TRUE;
    else {
        if (cmdline.stdpalette) {
            truecolor = FALSE;
            generateStandardPalette(&pcxcmap, maxval, &cht, &colors);
        } else if (cmdline.palette) {
            truecolor = FALSE;
            readPaletteFromFile(&pcxcmap, cmdline.palette, maxval, 
                                &cht, &colors);
        } else {
            bool tooManyColors;
            makePcxColormapFromImage(pixels, cols, rows, maxval,
                                     &pcxcmap, &cht, &colors,
                                     &tooManyColors);
            
            if (tooManyColors) {
                pm_message("too many colors - writing a 24bit PCX file");
                pm_message("if you want a non-24bit file, "
                           " a 'pnmquant %d'", MAXCOLORS);
                truecolor = TRUE;
            } else
                truecolor = FALSE;
        }
    }

    if (truecolor)
        ppmToTruecolorPcx(pixels, cols, rows, maxval, 
                          cmdline.xpos, cmdline.ypos);
    else {
        ppmToPalettePcx(pixels, cols, rows, maxval, 
                        cmdline.xpos, cmdline.ypos,
                        pcxcmap, cht, colors, cmdline.packed, 
                        cmdline.planes, cmdline.use_8_bit);
        
        ppm_freecolorhash(cht);
        free(pcxcmap);
    }
    return 0;
}