Ejemplo n.º 1
0
void select_glDrawElements(const pointer_state_t* vtx, GLenum mode, GLuint count, GLenum type, GLvoid * indices) {
	if (count == 0) return;
	if (vtx->pointer == NULL) return;

	GLushort *sind = (GLushort*)((type==GL_UNSIGNED_SHORT)?indices:NULL);
	GLuint *iind = (GLuint*)((type==GL_UNSIGNED_INT)?indices:NULL);

	GLsizei min, max;
	if(sind)
		getminmax_indices_us(sind, &max, &min, count);
	else
		getminmax_indices_ui(iind, &max, &min, count);
    max++;
	GLfloat *vert = copy_gl_array(vtx->pointer, vtx->type, 
			vtx->size, vtx->stride,
			GL_FLOAT, 4, 0, max);
	GLfloat zmin=1e10f, zmax=-10e6f;
	int found = 0;
	for (int i=min; i<max; i++) {
		select_transform(vert+i*4);
		ZMinMax(&glstate->selectbuf.zminoverall, &glstate->selectbuf.zmaxoverall, vert+i*4);
	}

	#define FOUND()	{ 				\
		found = 1;					\
		glstate->selectbuf.hit = 1; \
		}

	if(sind) {
		for (int i=0; i<count; i++) {
			switch (mode) {
				case GL_POINTS:
					if (select_point_in_viewscreen(vert+sind[i]*4)) {
						ZMinMax(&zmin, &zmax, vert+sind[i]*4);
						FOUND();
					}
					break;
				case GL_LINES:
					if (i%2==1) {
						if (select_segment_in_viewscreen(vert+sind[(i-1)]*4, vert+sind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+sind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_LINE_STRIP:
				case GL_LINE_LOOP:		//FIXME: the last "loop" segment is missing here
					if (i>0) {
						if (select_segment_in_viewscreen(vert+sind[(i-1)]*4, vert+sind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+sind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_TRIANGLES:
					if (i%3==2) {
						if (select_triangle_in_viewscreen(vert+sind[(i-2)]*4, vert+sind[(i-1)]*4, vert+sind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+sind[i-2]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_TRIANGLE_STRIP:
					if (i>1) {
						if (select_triangle_in_viewscreen(vert+sind[(i-2)]*4, vert+sind[(i-1)]*4, vert+sind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+sind[i-2]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_TRIANGLE_FAN:
					if (i>1) {
						if (select_triangle_in_viewscreen(vert+sind[0]*4, vert+sind[(i-1)]*4, vert+sind[i]*4))
							ZMinMax(&zmin, &zmax, vert+sind[0]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+sind[i]*4);
							FOUND();
					}
					break;
				default:
					return;		// Should never go there!
			}
		} 
	} else {
		for (int i=0; i<count; i++) {
			switch (mode) {
				case GL_POINTS:
					if (select_point_in_viewscreen(vert+iind[i]*4)) {
						ZMinMax(&zmin, &zmax, vert+iind[i]*4);
						FOUND();
					}
					break;
				case GL_LINES:
					if (i%2==1) {
						if (select_segment_in_viewscreen(vert+iind[(i-1)]*4, vert+iind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+iind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_LINE_STRIP:
				case GL_LINE_LOOP:		//FIXME: the last "loop" segment is missing here
					if (i>0) {
						if (select_segment_in_viewscreen(vert+iind[(i-1)]*4, vert+iind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+iind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_TRIANGLES:
					if (i%3==2) {
						if (select_triangle_in_viewscreen(vert+iind[(i-2)]*4, vert+iind[(i-1)]*4, vert+iind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+iind[i-2]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_TRIANGLE_STRIP:
					if (i>1) {
						if (select_triangle_in_viewscreen(vert+iind[(i-2)]*4, vert+iind[(i-1)]*4, vert+iind[i]*4)) {
							ZMinMax(&zmin, &zmax, vert+iind[i-2]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i]*4);
							FOUND();
						}
					}
					break;
				case GL_TRIANGLE_FAN:
					if (i>1) {
						if (select_triangle_in_viewscreen(vert+iind[0]*4, vert+iind[(i-1)]*4, vert+iind[i]*4))
							ZMinMax(&zmin, &zmax, vert+iind[0]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i-1]*4);
							ZMinMax(&zmin, &zmax, vert+iind[i]*4);
							FOUND();
					}
					break;
				default:
					return;		// Should never go there!
			}
		}
	}
	free(vert);
	if(found) {
		if (zmin<glstate->selectbuf.zmin) 	glstate->selectbuf.zmin=zmin;
		if (zmax>glstate->selectbuf.zmax) 	glstate->selectbuf.zmax=zmax;
	}

	#undef FOUND
}
Ejemplo n.º 2
0
parse_switches (j_compress_ptr cinfo, int argc, char **argv,
		int last_file_arg_seen, boolean for_real)
/* Parse optional switches.
 * Returns argv[] index of first file-name argument (== argc if none).
 * Any file names with indexes <= last_file_arg_seen are ignored;
 * they have presumably been processed in a previous iteration.
 * (Pass 0 for last_file_arg_seen on the first or only iteration.)
 * for_real is FALSE on the first (dummy) pass; we may skip any expensive
 * processing.
 */
{
  int argn;
  char * arg;
  boolean simple_progressive;
  char * scansarg = NULL;	/* saves -scans parm if any */

  /* Set up default JPEG parameters. */
  simple_progressive = FALSE;
  outfilename = NULL;
  copyoption = JCOPYOPT_DEFAULT;
  transformoption.transform = JXFORM_NONE;
  transformoption.trim = FALSE;
  transformoption.force_grayscale = FALSE;
  cinfo->err->trace_level = 0;

  /* Scan command line options, adjust parameters */

  for (argn = 1; argn < argc; argn++) {
    arg = argv[argn];
    if (*arg != '-') {
      /* Not a switch, must be a file name argument */
      if (argn <= last_file_arg_seen) {
	outfilename = NULL;	/* -outfile applies to just one input file */
	continue;		/* ignore this name if previously processed */
      }
      break;			/* else done parsing switches */
    }
    arg++;			/* advance past switch marker character */

    if (keymatch(arg, "arithmetic", 1)) {
      /* Use arithmetic coding. */
#ifdef C_ARITH_CODING_SUPPORTED
      cinfo->arith_code = TRUE;
#else
      fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "copy", 1)) {
      /* Select which extra markers to copy. */
      if (++argn >= argc)	/* advance to next argument */
	usage();
      if (keymatch(argv[argn], "none", 1)) {
	copyoption = JCOPYOPT_NONE;
      } else if (keymatch(argv[argn], "comments", 1)) {
	copyoption = JCOPYOPT_COMMENTS;
      } else if (keymatch(argv[argn], "all", 1)) {
	copyoption = JCOPYOPT_ALL;
      } else
	usage();

    } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
      /* Enable debug printouts. */
      /* On first -d, print version identification */
      static boolean printed_version = FALSE;

      if (! printed_version) {
	fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n",
		JVERSION, JCOPYRIGHT);
	printed_version = TRUE;
      }
      cinfo->err->trace_level++;

    } else if (keymatch(arg, "flip", 1)) {
      /* Mirror left-right or top-bottom. */
      if (++argn >= argc)	/* advance to next argument */
	usage();
      if (keymatch(argv[argn], "horizontal", 1))
	select_transform(JXFORM_FLIP_H);
      else if (keymatch(argv[argn], "vertical", 1))
	select_transform(JXFORM_FLIP_V);
      else
	usage();

    } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
      /* Force to grayscale. */
#if TRANSFORMS_SUPPORTED
      transformoption.force_grayscale = TRUE;
#else
      select_transform(JXFORM_NONE);	/* force an error */
#endif

    } else if (keymatch(arg, "maxmemory", 3)) {
      /* Maximum memory in Kb (or Mb with 'm'). */
      long lval;
      char ch = 'x';

      if (++argn >= argc)	/* advance to next argument */
	usage();
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
	usage();
      if (ch == 'm' || ch == 'M')
	lval *= 1000L;
      cinfo->mem->max_memory_to_use = lval * 1000L;

    } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
      /* Enable entropy parm optimization. */
#ifdef ENTROPY_OPT_SUPPORTED
      cinfo->optimize_coding = TRUE;
#else
      fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "outfile", 4)) {
      /* Set output file name. */
      if (++argn >= argc)	/* advance to next argument */
	usage();
      outfilename = argv[argn];	/* save it away for later use */

    } else if (keymatch(arg, "progressive", 1)) {
      /* Select simple progressive mode. */
#ifdef C_PROGRESSIVE_SUPPORTED
      simple_progressive = TRUE;
      /* We must postpone execution until num_components is known. */
#else
      fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "restart", 1)) {
      /* Restart interval in MCU rows (or in MCUs with 'b'). */
      long lval;
      char ch = 'x';

      if (++argn >= argc)	/* advance to next argument */
	usage();
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
	usage();
      if (lval < 0 || lval > 65535L)
	usage();
      if (ch == 'b' || ch == 'B') {
	cinfo->restart_interval = (unsigned int) lval;
	cinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */
      } else {
	cinfo->restart_in_rows = (int) lval;
	/* restart_interval will be computed during startup */
      }

    } else if (keymatch(arg, "rotate", 2)) {
      /* Rotate 90, 180, or 270 degrees (measured clockwise). */
      if (++argn >= argc)	/* advance to next argument */
	usage();
      if (keymatch(argv[argn], "90", 2))
	select_transform(JXFORM_ROT_90);
      else if (keymatch(argv[argn], "180", 3))
	select_transform(JXFORM_ROT_180);
      else if (keymatch(argv[argn], "270", 3))
	select_transform(JXFORM_ROT_270);
      else
	usage();

    } else if (keymatch(arg, "scans", 1)) {
      /* Set scan script. */
#ifdef C_MULTISCAN_FILES_SUPPORTED
      if (++argn >= argc)	/* advance to next argument */
	usage();
      scansarg = argv[argn];
      /* We must postpone reading the file in case -progressive appears. */
#else
      fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "transpose", 1)) {
      /* Transpose (across UL-to-LR axis). */
      select_transform(JXFORM_TRANSPOSE);

    } else if (keymatch(arg, "transverse", 6)) {
      /* Transverse transpose (across UR-to-LL axis). */
      select_transform(JXFORM_TRANSVERSE);

    } else if (keymatch(arg, "trim", 3)) {
      /* Trim off any partial edge MCUs that the transform can't handle. */
      transformoption.trim = TRUE;

    } else {
      usage();			/* bogus switch */
    }
  }

  /* Post-switch-scanning cleanup */

  if (for_real) {

#ifdef C_PROGRESSIVE_SUPPORTED
    if (simple_progressive)	/* process -progressive; -scans can override */
      jpeg_simple_progression(cinfo);
#endif

#ifdef C_MULTISCAN_FILES_SUPPORTED
    if (scansarg != NULL)	/* process -scans if it was present */
      if (! read_scan_script(cinfo, scansarg))
	usage();
#endif
  }

  return argn;			/* return index of next arg (file name) */
}
Ejemplo n.º 3
0
void select_glDrawArrays(const pointer_state_t* vtx, GLenum mode, GLuint first, GLuint count) {
	if (count == 0) return;
	if (vtx->pointer == NULL) return;
	if (glstate->selectbuf.buffer == NULL) return;
	GLfloat *vert = copy_gl_array(vtx->pointer, vtx->type, 
			vtx->size, vtx->stride,
			GL_FLOAT, 4, 0, count+first);
	GLfloat zmin=1e10f, zmax=-1e10f;
	int found = 0;

	#define FOUND()	{ 				\
		found = 1;					\
		glstate->selectbuf.hit = 1; \
	}

    // transform the points
	for (int i=first; i<count+first; i++) {
		select_transform(vert+i*4);
		ZMinMax(&glstate->selectbuf.zminoverall, &glstate->selectbuf.zmaxoverall, vert+i*4);
    }
    // intersect with screen now
    GLfloat *vert2 = vert + first*4;
	for (int i=0; i<count; i++) {
		switch (mode) {
			case GL_POINTS:
				if (select_point_in_viewscreen(vert2+i*4)) {
					ZMinMax(&zmin, &zmax, vert+i*4);
					FOUND();
				}
				break;
			case GL_LINES:
				if (i%2==1) {
					if (select_segment_in_viewscreen(vert2+(i-1)*4, vert2+i*4)) {
						ZMinMax(&zmin, &zmax, vert+(i-1)*4);
						ZMinMax(&zmin, &zmax, vert+i*4);
						FOUND();
					}
				}
				break;
			case GL_LINE_STRIP:
			case GL_LINE_LOOP:		//FIXME: the last "loop" segment is missing here
				if (i>0) {
					if (select_segment_in_viewscreen(vert2+(i-1)*4, vert2+i*4)) {
						ZMinMax(&zmin, &zmax, vert+(i-1)*4);
						ZMinMax(&zmin, &zmax, vert+i*4);
						FOUND();
					}
				}
				break;
			case GL_TRIANGLES:
				if (i%3==2) {
					if (select_triangle_in_viewscreen(vert2+(i-2)*4, vert2+(i-1)*4, vert2+i*4)) {
						ZMinMax(&zmin, &zmax, vert+(i-2)*4);
						ZMinMax(&zmin, &zmax, vert+(i-1)*4);
						ZMinMax(&zmin, &zmax, vert+i*4);
						FOUND();
					}
				}
				break;
			case GL_TRIANGLE_STRIP:
				if (i>1) {
					if (select_triangle_in_viewscreen(vert2+(i-2)*4, vert2+(i-1)*4, vert2+i*4)) {
						ZMinMax(&zmin, &zmax, vert+(i-2)*4);
						ZMinMax(&zmin, &zmax, vert+(i-1)*4);
						ZMinMax(&zmin, &zmax, vert+i*4);
						FOUND();
					}
				}
				break;
			case GL_TRIANGLE_FAN:
				if (i>1) {
					if (select_triangle_in_viewscreen(vert2, vert2+(i-1)*4, vert2+i*4)) {
						ZMinMax(&zmin, &zmax, vert);
						ZMinMax(&zmin, &zmax, vert+(i-1)*4);
						ZMinMax(&zmin, &zmax, vert+i*4);
						FOUND();
					}
				}
				break;
			default:
				return;		// Should never go there!
		}
	}
	free(vert);
	if(found) {
		if (zmin<glstate->selectbuf.zmin) 	glstate->selectbuf.zmin=zmin;
		if (zmax>glstate->selectbuf.zmax) 	glstate->selectbuf.zmax=zmax;
	}
	#undef FOUND
}
static int add_sensor (int dev_num, int catalog_index, int mode)
{
	int s;
	int sensor_type;
	int retval;
	char sysfs_path[PATH_MAX];
	const char* prefix;
        float scale;
	int c;
	float opt_scale;
	const char* ch_name;
	int num_channels;
	char suffix[MAX_NAME_SIZE + 8];
	int calib_bias;
	int buffer_length;

	if (sensor_count == MAX_SENSORS) {
		ALOGE("Too many sensors!\n");
		return -1;
	}

	sensor_type = sensor_catalog[catalog_index].type;

	/*
	 * At this point we could check that the expected sysfs attributes are
	 * present ; that would enable having multiple catalog entries with the
	 * same sensor type, accomodating different sets of sysfs attributes.
	 */

	s = sensor_count;

	sensor[s].dev_num	= dev_num;
	sensor[s].catalog_index	= catalog_index;
	sensor[s].type		= sensor_type;
	sensor[s].mode		= mode;
	sensor[s].trigger_nr = -1;	/* -1 means no trigger - we'll populate these at a later time */

        num_channels = sensor_catalog[catalog_index].num_channels;

        if (mode == MODE_POLL)
                sensor[s].num_channels = 0;
        else
                sensor[s].num_channels = num_channels;

	/* Populate the quirks array */
	sensor_get_quirks(s);

	/* Reject interfaces that may have been disabled through a quirk for this driver */
	if ((mode == MODE_EVENT   && (sensor[s].quirks & QUIRK_NO_EVENT_MODE)) ||
	    (mode == MODE_TRIGGER && (sensor[s].quirks & QUIRK_NO_TRIG_MODE )) ||
            (mode == MODE_POLL    && (sensor[s].quirks & QUIRK_NO_POLL_MODE ))) {
		memset(&sensor[s], 0, sizeof(sensor[0]));
		return -1;
	}

	prefix = sensor_catalog[catalog_index].tag;

	/*
	 * receiving the illumination sensor calibration inputs from
	 * the Android properties and setting it within sysfs
	 */
	if (sensor_type == SENSOR_TYPE_INTERNAL_ILLUMINANCE) {
		retval = sensor_get_illumincalib(s);
                if (retval > 0) {
			sprintf(sysfs_path, ILLUMINATION_CALIBPATH, dev_num);
			sysfs_write_int(sysfs_path, retval);
                }
	}

        /*
         * See if we have optional calibration biases for each of the channels of this sensor. These would be expressed using properties like
         * iio.accel.y.calib_bias = -1, or possibly something like iio.temp.calib_bias if the sensor has a single channel. This value gets stored in the
         * relevant calibbias sysfs file if that file can be located and then used internally by the iio sensor driver.
         */

        if (num_channels) {
		for (c = 0; c < num_channels; c++) {
			ch_name = sensor_catalog[catalog_index].channel[c].name;
			sprintf(suffix, "%s.calib_bias", ch_name);
			if (!sensor_get_prop(s, suffix, &calib_bias) && calib_bias) {
				sprintf(suffix, "%s_%s", prefix, sensor_catalog[catalog_index].channel[c].name);
				sprintf(sysfs_path, SENSOR_CALIB_BIAS_PATH, dev_num, suffix);
				sysfs_write_int(sysfs_path, calib_bias);
			}
		}
        } else
		if (!sensor_get_prop(s, "calib_bias", &calib_bias) && calib_bias) {
				sprintf(sysfs_path, SENSOR_CALIB_BIAS_PATH, dev_num, prefix);
				sysfs_write_int(sysfs_path, calib_bias);
			}

	/* Change buffer length according to the property or use default value */
	if (mode == MODE_TRIGGER) {
                if (sensor_get_prop(s, "buffer_length", &buffer_length)) {
                        buffer_length = BUFFER_LENGTH;
                }

                sprintf(sysfs_path, BUFFER_LENGTH_PATH, dev_num);

                if (sysfs_write_int(sysfs_path, buffer_length) <= 0) {
                        ALOGE("Failed to set buffer length on dev%d", dev_num);
                }
        }

	/* Read name attribute, if available */
	sprintf(sysfs_path, NAME_PATH, dev_num);
	sysfs_read_str(sysfs_path, sensor[s].internal_name, MAX_NAME_SIZE);

	/* See if we have general offsets and scale values for this sensor */

	sprintf(sysfs_path, SENSOR_OFFSET_PATH, dev_num, prefix);
	sysfs_read_float(sysfs_path, &sensor[s].offset);

	sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
	if (!sensor_get_fl_prop(s, "scale", &scale)) {
		/*
		 * There is a chip preferred scale specified,
		 * so try to store it in sensor's scale file
		 */
		if (sysfs_write_float(sysfs_path, scale) == -1 && errno == ENOENT) {
			ALOGE("Failed to store scale[%g] into %s - file is missing", scale, sysfs_path);
			/* Store failed, try to store the scale into channel specific file */
	                for (c = 0; c < num_channels; c++)
		        {
			        sprintf(sysfs_path, BASE_PATH "%s", dev_num,
					sensor_catalog[catalog_index].channel[c].scale_path);
				if (sysfs_write_float(sysfs_path, scale) == -1)
					ALOGE("Failed to store scale[%g] into %s", scale, sysfs_path);
                        }
                }
	}

	sprintf(sysfs_path, SENSOR_SCALE_PATH, dev_num, prefix);
	if (!sysfs_read_float(sysfs_path, &scale)) {
                sensor[s].scale = scale;
		ALOGV("Scale path:%s scale:%g dev_num:%d\n",
                                        sysfs_path, scale, dev_num);
	} else {
                sensor[s].scale = 1;

                /* Read channel specific scale if any*/
                for (c = 0; c < num_channels; c++)
                {
                        sprintf(sysfs_path, BASE_PATH "%s", dev_num,
                           sensor_catalog[catalog_index].channel[c].scale_path);

                        if (!sysfs_read_float(sysfs_path, &scale)) {
                                sensor[s].channel[c].scale = scale;
			        sensor[s].scale = 0;

			        ALOGV(  "Scale path:%s "
					"channel scale:%g dev_num:%d\n",
                                        sysfs_path, scale, dev_num);
                        }
                }
        }

        /* Set default scaling - if num_channels is zero, we have one channel */

	sensor[s].channel[0].opt_scale = 1;

	for (c = 1; c < num_channels; c++)
		sensor[s].channel[c].opt_scale = 1;

	for (c = 0; c < num_channels; c++) {
		/* Check the presence of the channel's input_path */
		sprintf(sysfs_path, BASE_PATH "%s", dev_num,
			sensor_catalog[catalog_index].channel[c].input_path);
		sensor[s].channel[c].input_path_present = (access(sysfs_path, R_OK) != -1);
		/* Check the presence of the channel's raw_path */
		sprintf(sysfs_path, BASE_PATH "%s", dev_num,
			sensor_catalog[catalog_index].channel[c].raw_path);
		sensor[s].channel[c].raw_path_present = (access(sysfs_path, R_OK) != -1);
	}

	sensor_get_available_frequencies(s);

	if (sensor_get_mounting_matrix(s, sensor[s].mounting_matrix))
		sensor[s].quirks |= QUIRK_MOUNTING_MATRIX;
	else
		/* Read ACPI _PLD attributes for this sensor, if there are any */
		decode_placement_information(dev_num, num_channels, s);

	/*
	 * See if we have optional correction scaling factors for each of the
	 * channels of this sensor. These would be expressed using properties
	 * like iio.accel.y.opt_scale = -1. In case of a single channel we also
	 * support things such as iio.temp.opt_scale = -1. Note that this works
	 * for all types of sensors, and whatever transform is selected, on top
	 * of any previous conversions.
	 */

	if (num_channels) {
		for (c = 0; c < num_channels; c++) {
			ch_name = sensor_catalog[catalog_index].channel[c].name;
			sprintf(suffix, "%s.opt_scale", ch_name);
			if (!sensor_get_fl_prop(s, suffix, &opt_scale))
				sensor[s].channel[c].opt_scale = opt_scale;
		}
        } else {
		if (!sensor_get_fl_prop(s, "opt_scale", &opt_scale))
			sensor[s].channel[0].opt_scale = opt_scale;
        }

	populate_descriptors(s, sensor_type);

	if (sensor[s].internal_name[0] == '\0') {
		/*
		 * In case the kernel-mode driver doesn't expose a name for
		 * the iio device, use (null)-dev%d as the trigger name...
		 * This can be considered a kernel-mode iio driver bug.
		 */
		ALOGW("Using null trigger on sensor %d (dev %d)\n", s, dev_num);
		strcpy(sensor[s].internal_name, "(null)");
	}

	switch (sensor_type) {
		case SENSOR_TYPE_ACCELEROMETER:
			/* Only engage accelerometer bias compensation if really needed */
			if (sensor_get_quirks(s) & QUIRK_BIASED)
				sensor[s].cal_data = calloc(1, sizeof(accel_cal_t));
			break;

			case SENSOR_TYPE_GYROSCOPE:
			sensor[s].cal_data = malloc(sizeof(gyro_cal_t));
			break;

		case SENSOR_TYPE_MAGNETIC_FIELD:
			sensor[s].cal_data = malloc(sizeof(compass_cal_t));
			break;
	}

	sensor[s].max_cal_level = sensor_get_cal_steps(s);

	/* Select one of the available sensor sample processing styles */
	select_transform(s);

	/* Initialize fields related to sysfs reads offloading */
	sensor[s].thread_data_fd[0]  = -1;
	sensor[s].thread_data_fd[1]  = -1;
	sensor[s].acquisition_thread = -1;

	/* Check if we have a special ordering property on this sensor */
	if (sensor_get_order(s, sensor[s].order))
		sensor[s].quirks |= QUIRK_FIELD_ORDERING;

	sensor[s].needs_enable = get_needs_enable(dev_num, sensor_catalog[catalog_index].tag);

	sensor_count++;
	return 0;
}
Ejemplo n.º 5
0
parse_switches (j_compress_ptr cinfo, int argc, char **argv,
		int last_file_arg_seen, boolean for_real)
{
  int argn;
  char * arg;
  boolean simple_progressive;
  char * scansarg = NULL;	

  
  simple_progressive = FALSE;
  outfilename = NULL;
  copyoption = JCOPYOPT_DEFAULT;
  transformoption.transform = JXFORM_NONE;
  transformoption.trim = FALSE;
  transformoption.force_grayscale = FALSE;
  cinfo->err->trace_level = 0;

  

  for (argn = 1; argn < argc; argn++) {
    arg = argv[argn];
    if (*arg != '-') {
      
      if (argn <= last_file_arg_seen) {
	outfilename = NULL;	
	continue;		
      }
      break;			
    }
    arg++;			

    if (keymatch(arg, "arithmetic", 1)) {
      
#ifdef C_ARITH_CODING_SUPPORTED
      cinfo->arith_code = TRUE;
#else
      fprintf(stderr, "%s: sorry, arithmetic coding not supported\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "copy", 1)) {
      
      if (++argn >= argc)	
	usage();
      if (keymatch(argv[argn], "none", 1)) {
	copyoption = JCOPYOPT_NONE;
      } else if (keymatch(argv[argn], "comments", 1)) {
	copyoption = JCOPYOPT_COMMENTS;
      } else if (keymatch(argv[argn], "all", 1)) {
	copyoption = JCOPYOPT_ALL;
      } else
	usage();

    } else if (keymatch(arg, "debug", 1) || keymatch(arg, "verbose", 1)) {
      
      
      static boolean printed_version = FALSE;

      if (! printed_version) {
	fprintf(stderr, "Independent JPEG Group's JPEGTRAN, version %s\n%s\n",
		JVERSION, JCOPYRIGHT);
	printed_version = TRUE;
      }
      cinfo->err->trace_level++;

    } else if (keymatch(arg, "flip", 1)) {
      
      if (++argn >= argc)	
	usage();
      if (keymatch(argv[argn], "horizontal", 1))
	select_transform(JXFORM_FLIP_H);
      else if (keymatch(argv[argn], "vertical", 1))
	select_transform(JXFORM_FLIP_V);
      else
	usage();

    } else if (keymatch(arg, "grayscale", 1) || keymatch(arg, "greyscale",1)) {
      
#if TRANSFORMS_SUPPORTED
      transformoption.force_grayscale = TRUE;
#else
      select_transform(JXFORM_NONE);	
#endif

    } else if (keymatch(arg, "maxmemory", 3)) {
      
      long lval;
      char ch = 'x';

      if (++argn >= argc)	
	usage();
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
	usage();
      if (ch == 'm' || ch == 'M')
	lval *= 1000L;
      cinfo->mem->max_memory_to_use = lval * 1000L;

    } else if (keymatch(arg, "optimize", 1) || keymatch(arg, "optimise", 1)) {
      
#ifdef ENTROPY_OPT_SUPPORTED
      cinfo->optimize_coding = TRUE;
#else
      fprintf(stderr, "%s: sorry, entropy optimization was not compiled\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "outfile", 4)) {
      
      if (++argn >= argc)	
	usage();
      outfilename = argv[argn];	

    } else if (keymatch(arg, "progressive", 1)) {
      
#ifdef C_PROGRESSIVE_SUPPORTED
      simple_progressive = TRUE;
      
#else
      fprintf(stderr, "%s: sorry, progressive output was not compiled\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "restart", 1)) {
      
      long lval;
      char ch = 'x';

      if (++argn >= argc)	
	usage();
      if (sscanf(argv[argn], "%ld%c", &lval, &ch) < 1)
	usage();
      if (lval < 0 || lval > 65535L)
	usage();
      if (ch == 'b' || ch == 'B') {
	cinfo->restart_interval = (unsigned int) lval;
	cinfo->restart_in_rows = 0; 
      } else {
	cinfo->restart_in_rows = (int) lval;
	
      }

    } else if (keymatch(arg, "rotate", 2)) {
      
      if (++argn >= argc)	
	usage();
      if (keymatch(argv[argn], "90", 2))
	select_transform(JXFORM_ROT_90);
      else if (keymatch(argv[argn], "180", 3))
	select_transform(JXFORM_ROT_180);
      else if (keymatch(argv[argn], "270", 3))
	select_transform(JXFORM_ROT_270);
      else
	usage();

    } else if (keymatch(arg, "scans", 1)) {
      
#ifdef C_MULTISCAN_FILES_SUPPORTED
      if (++argn >= argc)	
	usage();
      scansarg = argv[argn];
      
#else
      fprintf(stderr, "%s: sorry, multi-scan output was not compiled\n",
	      progname);
      exit(EXIT_FAILURE);
#endif

    } else if (keymatch(arg, "transpose", 1)) {
      
      select_transform(JXFORM_TRANSPOSE);

    } else if (keymatch(arg, "transverse", 6)) {
      
      select_transform(JXFORM_TRANSVERSE);

    } else if (keymatch(arg, "trim", 3)) {
      
      transformoption.trim = TRUE;

    } else {
      usage();			
    }
  }

  

  if (for_real) {

#ifdef C_PROGRESSIVE_SUPPORTED
    if (simple_progressive)	
      jpeg_simple_progression(cinfo);
#endif

#ifdef C_MULTISCAN_FILES_SUPPORTED
    if (scansarg != NULL)	
      if (! read_scan_script(cinfo, scansarg))
	usage();
#endif
  }

  return argn;			
}
Ejemplo n.º 6
0
void select_glDrawElements(const pointer_state_t* vtx, GLenum mode, GLuint count, GLenum type, GLvoid * indices) {
	if (count == 0) return;
	if (vtx->pointer == NULL) return;

	GLushort *ind = (GLushort*)indices;

	GLsizei min, max;
	getminmax_indices(indices, &max, &min, count);
    max++;
	GLfloat *vert = copy_gl_array(vtx->pointer, vtx->type, 
			vtx->size, vtx->stride,
			GL_FLOAT, 3, 0, max);
	GLfloat tmp[3];
	init_select();
	GLfloat zmin=1.0f, zmax=0.0f;
	for (int i=min; i<max; i++) {
		select_transform(vert+i*3);
		if (vert[i*3+2]<zmin) zmin=vert[i*3+2];
		if (vert[i*3+2]>zmax) zmax=vert[i*3+2];
	}
	if (zmin<0.0f) zmin = 0.0f;
	if (zmax>1.0f) zmax = 1.0f;

	#define FOUND()	{ 		\
		if (zmin<state.selectbuf.zmin) 	state.selectbuf.zmin=zmin;	\
		if (zmax>state.selectbuf.zmax) 	state.selectbuf.zmax=zmax;	\
		state.selectbuf.hit = 1; \
        free(vert);              \
        return;                  \
		}

	for (int i=0; i<count; i++) {
		switch (mode) {
			case GL_POINTS:
				if (select_point_in_viewscreen(vert+ind[i]*3))
					FOUND();
				break;
			case GL_LINES:
				if (i%2==1) {
					if (select_segment_in_viewscreen(vert+ind[(i-1)]*3, vert+ind[i]*3))
						FOUND();
				}
				break;
			case GL_LINE_STRIP:
			case GL_LINE_LOOP:		//FIXME: the last "loop" segment is missing here
				if (i>0) {
					if (select_segment_in_viewscreen(vert+ind[(i-1)]*3, vert+ind[i]*3))
						FOUND();
				}
				break;
			case GL_TRIANGLES:
				if (i%3==2) {
					if (select_triangle_in_viewscreen(vert+ind[(i-2)]*3, vert+ind[(i-1)]*3, vert+ind[i]*3))
						FOUND();
				}
				break;
			case GL_TRIANGLE_STRIP:
				if (i>1) {
					if (select_triangle_in_viewscreen(vert+ind[(i-2)]*3, vert+ind[(i-1)]*3, vert+ind[i]*3))
						FOUND();
				}
				break;
			case GL_TRIANGLE_FAN:
				if (i>1) {
					if (select_triangle_in_viewscreen(vert+ind[0]*3, vert+ind[(i-1)]*3, vert+ind[i]*3))
						FOUND();
				}
				break;
			default:
				return;		// Should never go there!
		}
	}
	free(vert);
	#undef FOUND
}
Ejemplo n.º 7
0
void select_glDrawArrays(const pointer_state_t* vtx, GLenum mode, GLuint first, GLuint count) {
	if (count == 0) return;
	if (vtx->pointer == NULL) return;
	if (state.selectbuf.buffer == NULL) return;
	GLfloat *vert = copy_gl_array(vtx->pointer, vtx->type, 
			vtx->size, vtx->stride,
			GL_FLOAT, 3, 0, count+first);
	GLfloat tmp[3];
	GLfloat zmin=1.0f, zmax=0.0f;
	init_select();

	#define FOUND()	{ 		\
		if (zmin<state.selectbuf.zmin) 	state.selectbuf.zmin=zmin;	\
		if (zmax>state.selectbuf.zmax) 	state.selectbuf.zmax=zmax;	\
		state.selectbuf.hit = 1;                        \
        free(vert);         \
        return;                                         \
		}
    // transform the points
	for (int i=first; i<count+first; i++) {
		select_transform(vert+i*3);
		if (vert[i*3+2]<zmin) zmin=vert[i*3+2];
		if (vert[i*3+2]>zmax) zmax=vert[i*3+2];
    }
    // intersect with screen now
    GLfloat *vert2 = vert + first*3;
	for (int i=0; i<count; i++) {
		switch (mode) {
			case GL_POINTS:
				if (select_point_in_viewscreen(vert2+i*3))
					FOUND();
				break;
			case GL_LINES:
				if (i%2==1) {
					if (select_segment_in_viewscreen(vert2+(i-1)*3, vert2+i*3))
						FOUND();
				}
				break;
			case GL_LINE_STRIP:
			case GL_LINE_LOOP:		//FIXME: the last "loop" segment is missing here
				if (i>0) {
					if (select_segment_in_viewscreen(vert2+(i-1)*3, vert2+i*3))
						FOUND();
				}
				break;
			case GL_TRIANGLES:
				if (i%3==2) {
					if (select_triangle_in_viewscreen(vert2+(i-2)*3, vert2+(i-1)*3, vert2+i*3))
						FOUND();
				}
				break;
			case GL_TRIANGLE_STRIP:
				if (i>1) {
					if (select_triangle_in_viewscreen(vert2+(i-2)*3, vert2+(i-1)*3, vert2+i*3))
						FOUND();
				}
				break;
			case GL_TRIANGLE_FAN:
				if (i>1) {
					if (select_triangle_in_viewscreen(vert2, vert2+(i-1)*3, vert2+i*3))
						FOUND();
				}
				break;
			default:
				return;		// Should never go there!
		}
	}
	free(vert);
	#undef FOUND
}