Exemple #1
0
int
modif_vector(double *rotation, double *old_vector,
	     double *new_vector, int flag)
{
  if (!rotation || !old_vector || !new_vector)
    return (EXIT_FAILURE);
  new_vector[X] = old_vector[X];
  new_vector[Y] = old_vector[Y];
  new_vector[Z] = old_vector[Z];
  calc_rotation(new_vector, rotation, flag);
  return (EXIT_SUCCESS);
}
Exemple #2
0
int
modif_position(double *position, t_object *object,
	       double *location, int flag)
{
  if (!location || !object || !position)
    return (EXIT_FAILURE);
  location[X] = position[X] - object->position[X];
  location[Y] = position[Y] - object->position[Y];
  location[Z] = position[Z] - object->position[Z];
  calc_rotation(location, object->rotation, flag);
  return (EXIT_SUCCESS);
}
Exemple #3
0
int	calc_direction_vector(t_global *global,
			      double *vector, double x, double y)
{
  if (!vector || !global || !global->scene || !global->scene->camera)
    return (EXIT_FAILURE);
  vector[X] = global->scene->camera->fov;
  vector[Y] = ((double)global->window->x_win / 2.0F) - x;
  vector[Z] = ((double)global->window->y_win / 2.0F) - y;
  vector[X] -= global->scene->camera->position[X];
  vector[Y] -= global->scene->camera->position[Y];
  vector[Z] -= global->scene->camera->position[Z];
  calc_rotation(vector, global->scene->camera->rotation, NORMAL_ROTATION);
  return (EXIT_SUCCESS);
}
Exemple #4
0
/*
 * Calculate the buffer offsets from which the streaming should
 * start. This offset calculation is mainly required because of
 * the VRFB 32 pixels alignment with rotation.
 */
void omap_vout_calculate_vrfb_offset(struct omap_vout_device *vout)
{
	enum dss_rotation rotation;
	bool mirroring = vout->mirror;
	struct v4l2_rect *crop = &vout->crop;
	struct v4l2_pix_format *pix = &vout->pix;
	int *cropped_offset = &vout->cropped_offset;
	int vr_ps = 1, ps = 2, temp_ps = 2;
	int offset = 0, ctop = 0, cleft = 0, line_length = 0;

	rotation = calc_rotation(vout);

	if (V4L2_PIX_FMT_YUYV == pix->pixelformat ||
			V4L2_PIX_FMT_UYVY == pix->pixelformat) {
		if (is_rotation_enabled(vout)) {
			/*
			 * ps    - Actual pixel size for YUYV/UYVY for
			 *         VRFB/Mirroring is 4 bytes
			 * vr_ps - Virtually pixel size for YUYV/UYVY is
			 *         2 bytes
			 */
			ps = 4;
			vr_ps = 2;
		} else {
			ps = 2;	/* otherwise the pixel size is 2 byte */
		}
	} else if (V4L2_PIX_FMT_RGB32 == pix->pixelformat) {
		ps = 4;
	} else if (V4L2_PIX_FMT_RGB24 == pix->pixelformat) {
		ps = 3;
	}
	vout->ps = ps;
	vout->vr_ps = vr_ps;

	if (is_rotation_enabled(vout)) {
		line_length = MAX_PIXELS_PER_LINE;
		ctop = (pix->height - crop->height) - crop->top;
		cleft = (pix->width - crop->width) - crop->left;
	} else {
		line_length = pix->width;
	}
	vout->line_length = line_length;
	switch (rotation) {
	case dss_rotation_90_degree:
		offset = vout->vrfb_context[0].yoffset *
			vout->vrfb_context[0].bytespp;
		temp_ps = ps / vr_ps;
		if (mirroring == 0) {
			*cropped_offset = offset + line_length *
				temp_ps * cleft + crop->top * temp_ps;
		} else {
			*cropped_offset = offset + line_length * temp_ps *
				cleft + crop->top * temp_ps + (line_length *
				((crop->width / (vr_ps)) - 1) * ps);
		}
		break;
	case dss_rotation_180_degree:
		offset = ((MAX_PIXELS_PER_LINE * vout->vrfb_context[0].yoffset *
			vout->vrfb_context[0].bytespp) +
			(vout->vrfb_context[0].xoffset *
			vout->vrfb_context[0].bytespp));
		if (mirroring == 0) {
			*cropped_offset = offset + (line_length * ps * ctop) +
				(cleft / vr_ps) * ps;

		} else {
			*cropped_offset = offset + (line_length * ps * ctop) +
				(cleft / vr_ps) * ps + (line_length *
				(crop->height - 1) * ps);
		}
		break;
	case dss_rotation_270_degree:
		offset = MAX_PIXELS_PER_LINE * vout->vrfb_context[0].xoffset *
			vout->vrfb_context[0].bytespp;
		temp_ps = ps / vr_ps;
		if (mirroring == 0) {
			*cropped_offset = offset + line_length *
			    temp_ps * crop->left + ctop * ps;
		} else {
			*cropped_offset = offset + line_length *
				temp_ps * crop->left + ctop * ps +
				(line_length * ((crop->width / vr_ps) - 1) *
				 ps);
		}
		break;
	case dss_rotation_0_degree:
		if (mirroring == 0) {
			*cropped_offset = (line_length * ps) *
				crop->top + (crop->left / vr_ps) * ps;
		} else {
			*cropped_offset = (line_length * ps) *
				crop->top + (crop->left / vr_ps) * ps +
				(line_length * (crop->height - 1) * ps);
		}
		break;
	default:
		*cropped_offset = (line_length * ps * crop->top) /
			vr_ps + (crop->left * ps) / vr_ps +
			((crop->width / vr_ps) - 1) * ps;
		break;
	}
}
Exemple #5
0
int omap_vout_prepare_vrfb(struct omap_vout_device *vout,
				struct videobuf_buffer *vb)
{
	dma_addr_t dmabuf;
	struct vid_vrfb_dma *tx;
	enum dss_rotation rotation;
	u32 dest_frame_index = 0, src_element_index = 0;
	u32 dest_element_index = 0, src_frame_index = 0;
	u32 elem_count = 0, frame_count = 0, pixsize = 2;

	if (!is_rotation_enabled(vout))
		return 0;

	dmabuf = vout->buf_phy_addr[vb->i];
	/* If rotation is enabled, copy input buffer into VRFB
	 * memory space using DMA. We are copying input buffer
	 * into VRFB memory space of desired angle and DSS will
	 * read image VRFB memory for 0 degree angle
	 */
	pixsize = vout->bpp * vout->vrfb_bpp;
	/*
	 * DMA transfer in double index mode
	 */

	/* Frame index */
	dest_frame_index = ((MAX_PIXELS_PER_LINE * pixsize) -
			(vout->pix.width * vout->bpp)) + 1;

	/* Source and destination parameters */
	src_element_index = 0;
	src_frame_index = 0;
	dest_element_index = 1;
	/* Number of elements per frame */
	elem_count = vout->pix.width * vout->bpp;
	frame_count = vout->pix.height;
	tx = &vout->vrfb_dma_tx;
	tx->tx_status = 0;
	omap_set_dma_transfer_params(tx->dma_ch, OMAP_DMA_DATA_TYPE_S32,
			(elem_count / 4), frame_count, OMAP_DMA_SYNC_ELEMENT,
			tx->dev_id, 0x0);
	/* src_port required only for OMAP1 */
	omap_set_dma_src_params(tx->dma_ch, 0, OMAP_DMA_AMODE_POST_INC,
			dmabuf, src_element_index, src_frame_index);
	/*set dma source burst mode for VRFB */
	omap_set_dma_src_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16);
	rotation = calc_rotation(vout);

	/* dest_port required only for OMAP1 */
	omap_set_dma_dest_params(tx->dma_ch, 0, OMAP_DMA_AMODE_DOUBLE_IDX,
			vout->vrfb_context[vb->i].paddr[0], dest_element_index,
			dest_frame_index);
	/*set dma dest burst mode for VRFB */
	omap_set_dma_dest_burst_mode(tx->dma_ch, OMAP_DMA_DATA_BURST_16);
	omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE, 0x20, 0);

	omap_start_dma(tx->dma_ch);
	wait_event_interruptible_timeout(tx->wait, tx->tx_status == 1,
					 VRFB_TX_TIMEOUT);

	if (tx->tx_status == 0) {
		omap_stop_dma(tx->dma_ch);
		return -EINVAL;
	}
	/* Store buffers physical address into an array. Addresses
	 * from this array will be used to configure DSS */
	vout->queued_buf_addr[vb->i] = (u8 *)
		vout->vrfb_context[vb->i].paddr[rotation];
	return 0;
}
Exemple #6
0
void logic_loop()
{
	printf("f_logic = %d\n", f_logic);

	if (f_logic){

		struct timeval start;
		gettimeofday(&start, 0);

		printf("logic is enabled\n");
		int width = 640;
		int height = 480;

		if (!pic1){
			pic1 = malloc(sizeof(BMP));
			memset(pic1, 0, sizeof(BMP));
			BMP_init(pic1, width, height);
		}
		if (!pic2){
			pic2 = malloc(sizeof(BMP));
			memset(pic2, 0, sizeof(BMP));
			BMP_init(pic2, width, height);
		}

		if (take_both) {
			take_pic(pic1);
			take_pic(pic2);
			take_both = 0;
		} else {
			BMP* bmp = pic2;
			pic2 = pic1;
			take_pic(bmp);
			pic1 = bmp;
		}

		DetectionDiff* diff = motion_detect(pic1, pic2, 50, 5);
		float angles[2];

		if (calc_rotation(diff, angles)) {
			struct timeval end;
			gettimeofday(&end, 0);
			long tdiff = end.tv_sec*1e3 + end.tv_usec/1e3 - start.tv_sec*1e3 - start.tv_usec/1e3;
			printf("cycle length in milliseconds: %ld\n", tdiff);
/*
			motion_detect_mark_frame(pic1, diff);
			motion_detect_mark_frame(pic2, diff);
			motion_detect_mark_frame(diff->first_pass, diff);
			motion_detect_mark_frame(diff->second_pass, diff);

			char name1[256] = {0};
			char name2[256] = {0};
			char name3[256] = {0};
			char name4[256] = {0};

			snprintf(name1, 256, "%d_pic1.bmp", itid);
			snprintf(name2, 256, "%d_pic2.bmp", itid);
			snprintf(name3, 256, "%d_first.bmp", itid);
			snprintf(name4, 256, "%d_second.bmp", itid);

			++itid;

			BMP_write(pic1, name1);
			BMP_write(pic2, name2);
			BMP_write(diff->first_pass, name3);
			BMP_write(diff->second_pass, name4);
*/
			printf("detected motion, horizontal rotation = %f radians\n", angles[0]);
			printf("detected motion, vertical rotation = %f radians\n", angles[1]);

			if (!is_playing()) {
				play_random_sample();
			}

			if (is_playing()) {
				int slept = 0;
				int max_sleep = 3000;
				while (slept < max_sleep && is_playing()) {
					delayms(100);
					slept += 100;
				}

				if (is_playing()) {
					kill(0, SIGINT);
				}
			}

			rotate_x(angles[0]);
			take_both = 1;
		}
		else{
			struct timeval end;
			gettimeofday(&end, 0);
			long tdiff = end.tv_sec*1e3 + end.tv_usec/1e3 - start.tv_sec*1e3 - start.tv_usec/1e3;
			printf("cycle length in milliseconds: %ld\n", tdiff);
		}

		BMP_free(diff->first_pass);
		BMP_free(diff->second_pass);
		free(diff);
	} else {
		printf("logic is disabled\n");
		sleep(1);
	}
}