示例#1
0
		bool encode_frame(analysis_filter* filter, int total_bits) {
			if (false == in.has_more_data())
				return false;
			this->total_bits = total_bits;
			try {
				filter_data(filter, in);
				calc_scale();
				for (int c = 0; NUMBER_CHANNELS != c; ++c)
					model[c]->calc_smr(in[c], scale[c], smr[c], NUMBER_PARTS);
				calc_allocation();
				encode_config();
				encode_sideinfo();
				encode_data();
				while (this->total_bits > 0)
					if (this->total_bits >= 8) {
						str.write_bits(0, 8);
						this->total_bits -= 8;
					}
					else {
						str.write_bits(0, this->total_bits);
						this->total_bits = 0;
					}
				return true;
			}
			catch (stream_exception) {
				return false;
			}
		}
示例#2
0
 void init(double minx, double miny, double minz, double maxx, double maxy, double maxz) {
   dx = calc_delta(minx, maxx); minx -= dx; maxx -= dx;
   dy = calc_delta(miny, maxy); miny -= dy; maxy -= dy;
   dz = calc_delta(minz, maxz); minz -= dz; maxz -= dz;
   scale = calc_scale(std::max(std::max(fabs(minz), fabs(maxz)),
                               std::max(std::max(fabs(minx), fabs(maxx)),
                                        std::max(fabs(miny), fabs(maxy)))));
 }
示例#3
0
文件: draw.c 项目: vasik041/openlab
void draw(double csq)
{
    calc_scale(csq);
    gtk_widget_queue_draw_area(drawing_area,0,0,WIDTH,HEIGHT);
}
示例#4
0
static gboolean
prepare_photo_id (GtkWindow *parent, gchar *path, gchar **result, GError **error)
{
    GdkPixbuf *pixbuf = NULL;
    GdkPixbuf *sampled;
    GdkPixbufFormat *format;
    gint width, height;
    gboolean rewrite = FALSE;
    gboolean resample = FALSE;
    gboolean suggest = FALSE;
    gboolean r;
    gchar *name;
    struct stat sb;
    int fd;
    
    g_assert (path);
    g_assert (result);
    g_assert (!error || !*error);
    
    *result = NULL;
   
    format = gdk_pixbuf_get_file_info (path, &width, &height);
    if (!format) {
        g_set_error (error, SEAHORSE_ERROR, -1, 
                     _("This is not a image file, or an unrecognized kind of image file. Try to use a JPEG image."));
        return FALSE;
    }
    
    /* Check if it's a JPEG */
    name = gdk_pixbuf_format_get_name (format);
    r = g_strcmp0 (name, "jpeg") == 0;
    g_free (name);
    
    /* JPEGs we can use straight up */
    if (r) {
        
        /* If so we may just be able to use it straight up */
        if (stat (path, &sb) != -1) {
            
            /* Large file size, suggest resampling */
            if (sb.st_size > 8192) 
                suggest = TRUE;
        }
        
    /* Other formats */
    } else {
        rewrite = TRUE;
        
        /* Check for large, but allow strange orientations */
        if ((width + height) > (LARGE_WIDTH + LARGE_HEIGHT))
            suggest = TRUE;
    }
    
    /* Suggest to the user that we resize the photo */
    if (suggest) {
        switch (suggest_resize (parent)) {
        case GTK_RESPONSE_ACCEPT:
            resample = TRUE;
            rewrite = TRUE;
            break;
        case GTK_RESPONSE_REJECT:
            resample = FALSE;
            break;
        default:
            /* FALSE with error not set = cancel */
            return FALSE;
        }
    }
    
    /* No rewrite */
    if (!rewrite)
        return TRUE;

    /* Load the photo if necessary */
    pixbuf = gdk_pixbuf_new_from_file (path, error);
    if (!pixbuf)
        return FALSE;
    
    /* Resize it properly */
    if (resample && calc_scale (&width, &height)) {
        sampled = gdk_pixbuf_scale_simple (pixbuf, width, height, 
                                           GDK_INTERP_BILINEAR);
        g_object_unref (pixbuf);
        
        g_return_val_if_fail (sampled != NULL, FALSE);
        pixbuf = sampled;
        sampled = NULL;
    }
    
    /* And write it out to a temp */
    fd = g_file_open_tmp ("seahorse-photo.XXXXXX", result, error);
    if (fd == -1) {
        g_object_unref (pixbuf);
        return FALSE;
    }
    
    r = gdk_pixbuf_save_to_callback (pixbuf, save_to_fd, GINT_TO_POINTER (fd),
                                     "jpeg", error, "quality", "75", NULL);
    
    close (fd);
    g_object_unref (pixbuf);
    
    if (!r) {
        g_free (*result);
        *result = NULL;
        return FALSE;
    }
    
    return TRUE;
}
示例#5
0
static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
				 struct v4l2_format *f)
{
	struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
	struct sh_mobile_ceu_dev *pcdev = ici->priv;
	struct sh_mobile_ceu_cam *cam = icd->host_priv;
	struct v4l2_pix_format *pix = &f->fmt.pix;
	struct v4l2_format cam_f = *f;
	struct v4l2_pix_format *cam_pix = &cam_f.fmt.pix;
	struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
	struct device *dev = icd->dev.parent;
	__u32 pixfmt = pix->pixelformat;
	const struct soc_camera_format_xlate *xlate;
	struct v4l2_crop cam_crop;
	struct v4l2_rect *cam_rect = &cam_crop.c, cam_subrect, ceu_rect;
	unsigned int scale_cam_h, scale_cam_v;
	u16 scale_v, scale_h;
	int ret;
	bool is_interlaced, image_mode;

	switch (pix->field) {
	case V4L2_FIELD_INTERLACED:
		is_interlaced = true;
		break;
	case V4L2_FIELD_ANY:
	default:
		pix->field = V4L2_FIELD_NONE;
		
	case V4L2_FIELD_NONE:
		is_interlaced = false;
		break;
	}

	xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
	if (!xlate) {
		dev_warn(dev, "Format %x not found\n", pixfmt);
		return -EINVAL;
	}

	
	cam_crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	ret = client_g_rect(sd, cam_rect);
	if (ret < 0)
		return ret;

	ret = get_camera_scales(sd, cam_rect, &scale_cam_h, &scale_cam_v);
	if (ret < 0)
		return ret;

	dev_geo(dev, "1: camera scales %u:%u\n", scale_cam_h, scale_cam_v);

	
	ret = get_camera_subwin(icd, &cam_subrect, scale_cam_h, scale_cam_v);
	if (ret < 0)
		return ret;

	dev_geo(dev, "2: subwin %ux%u@%u:%u\n",
		cam_subrect.width, cam_subrect.height,
		cam_subrect.left, cam_subrect.top);

	
	scale_h = calc_generic_scale(cam_subrect.width, pix->width);
	scale_v = calc_generic_scale(cam_subrect.height, pix->height);

	dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);

	
	cam_pix->width = scale_down(cam_rect->width, scale_h);
	cam_pix->height = scale_down(cam_rect->height, scale_v);
	cam_pix->pixelformat = xlate->cam_fmt->fourcc;

	switch (pixfmt) {
	case V4L2_PIX_FMT_NV12:
	case V4L2_PIX_FMT_NV21:
	case V4L2_PIX_FMT_NV16:
	case V4L2_PIX_FMT_NV61:
		image_mode = true;
		break;
	default:
		image_mode = false;
	}

	dev_geo(dev, "4: camera output %ux%u\n",
		cam_pix->width, cam_pix->height);

	
	ret = client_scale(icd, cam_rect, &cam_subrect, &ceu_rect, &cam_f,
			   image_mode && !is_interlaced);

	dev_geo(dev, "5-9: client scale %d\n", ret);

	

	dev_dbg(dev, "Camera %d fmt %ux%u, requested %ux%u\n",
		ret, cam_pix->width, cam_pix->height, pix->width, pix->height);
	if (ret < 0)
		return ret;

	

	
	if (pix->width > cam_pix->width)
		pix->width = cam_pix->width;
	if (pix->width > ceu_rect.width)
		pix->width = ceu_rect.width;

	if (pix->height > cam_pix->height)
		pix->height = cam_pix->height;
	if (pix->height > ceu_rect.height)
		pix->height = ceu_rect.height;

	
	scale_h = calc_scale(ceu_rect.width, &pix->width);
	scale_v = calc_scale(ceu_rect.height, &pix->height);

	dev_geo(dev, "10: W: %u : 0x%x = %u, H: %u : 0x%x = %u\n",
		ceu_rect.width, scale_h, pix->width,
		ceu_rect.height, scale_v, pix->height);

	pcdev->cflcr = scale_h | (scale_v << 16);

	icd->buswidth = xlate->buswidth;
	icd->current_fmt = xlate->host_fmt;
	cam->camera_fmt = xlate->cam_fmt;
	cam->ceu_rect = ceu_rect;

	pcdev->is_interlaced = is_interlaced;
	pcdev->image_mode = image_mode;

	return 0;
}
示例#6
0
static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
				  struct v4l2_crop *a)
{
	struct v4l2_rect *rect = &a->c;
	struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
	struct sh_mobile_ceu_dev *pcdev = ici->priv;
	struct v4l2_crop cam_crop;
	struct sh_mobile_ceu_cam *cam = icd->host_priv;
	struct v4l2_rect *cam_rect = &cam_crop.c, *ceu_rect = &cam->ceu_rect;
	struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
	struct device *dev = icd->dev.parent;
	struct v4l2_format f;
	struct v4l2_pix_format *pix = &f.fmt.pix;
	unsigned int scale_comb_h, scale_comb_v, scale_ceu_h, scale_ceu_v,
		out_width, out_height;
	u32 capsr, cflcr;
	int ret;

	
	ret = get_scales(icd, &scale_comb_h, &scale_comb_v);
	if (ret < 0)
		return ret;

	dev_geo(dev, "1: combined scales %u:%u\n", scale_comb_h, scale_comb_v);

	
	ret = client_s_crop(sd, a, &cam_crop);
	if (ret < 0)
		return ret;

	dev_geo(dev, "2: camera cropped to %ux%u@%u:%u\n",
		cam_rect->width, cam_rect->height,
		cam_rect->left, cam_rect->top);

	

	
	out_width	= scale_down(rect->width, scale_comb_h);
	out_height	= scale_down(rect->height, scale_comb_v);

	if (out_width > 2560)
		out_width = 2560;
	else if (out_width < 2)
		out_width = 2;

	if (out_height > 1920)
		out_height = 1920;
	else if (out_height < 4)
		out_height = 4;

	dev_geo(dev, "3: Adjusted output %ux%u\n", out_width, out_height);

	

	
	pix->width		= scale_down(cam_rect->width, scale_comb_h);
	pix->height		= scale_down(cam_rect->height, scale_comb_v);

	dev_geo(dev, "5: camera target %ux%u\n", pix->width, pix->height);

	
	pix->pixelformat	= cam->camera_fmt->fourcc;
	pix->colorspace		= cam->camera_fmt->colorspace;

	capsr = capture_save_reset(pcdev);
	dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr);

	
	rect->left		-= cam_rect->left;
	rect->top		-= cam_rect->top;

	f.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

	ret = client_scale(icd, cam_rect, rect, ceu_rect, &f,
			   pcdev->image_mode && !pcdev->is_interlaced);

	dev_geo(dev, "6-9: %d\n", ret);

	
	sh_mobile_ceu_set_rect(icd, out_width, out_height);

	dev_geo(dev, "10: CEU cropped to %ux%u@%u:%u\n",
		ceu_rect->width, ceu_rect->height,
		ceu_rect->left, ceu_rect->top);

	
	scale_ceu_h = calc_scale(ceu_rect->width, &out_width);
	scale_ceu_v = calc_scale(ceu_rect->height, &out_height);

	dev_geo(dev, "11: CEU scales %u:%u\n", scale_ceu_h, scale_ceu_v);

	
	cflcr = scale_ceu_h | (scale_ceu_v << 16);
	if (cflcr != pcdev->cflcr) {
		pcdev->cflcr = cflcr;
		ceu_write(pcdev, CFLCR, cflcr);
	}

	
	if (pcdev->active)
		capsr |= 1;
	capture_restore(pcdev, capsr);

	icd->user_width = out_width;
	icd->user_height = out_height;

	
	return ret;
}
示例#7
0
void Master::Run() {

  // Event loop
  while(_exitFlag == false) {

    // Wait for a new connection from 
    _userInterfaceServer.Accept();

    // Client error
    int error = USER_INTERFACE_SERVER_OK;

    // Loop getting commands from user as long as a client is connected
    while (error != USER_INTERFACE_SERVER_ERROR) {

      // Get command from client
      error = _userInterfaceServer.GetCommand();

      // If client received a command call barrier
      if (error == USER_INTERFACE_SERVER_OK) {
        _communicator -> Barrier();
      }

#ifdef SAGE

      // SAGE message
      sageMessage msg;

      // Check for SAGE message
      if (_sageInf.checkMsg(msg, false) > 0) {

        // Get SAGE message data
        char* data = (char*) msg.getData();

        // Determine message
        switch(msg.getCode()) {
          
        // Quit
        case APP_QUIT:
          
          // Send exit command to UI
          _userInterfaceServer.SendCommandExit();

          // Send exit command
          UpdateCommandExit();         

          // Stop this loop
          error = USER_INTERFACE_SERVER_ERROR;
          
          break;
        

        // Click event
        case EVT_CLICK: {

          // Click event x and y location normalized to size of window
          float clickX, clickY;

          // Ckick device Id, button Id, and is down flag
          int clickDeviceId, clickButtonId, clickIsDown, clickEvent;

          // Parse message
          sscanf(data, 
                 "%d %f %f %d %d %d", 
                 &clickDeviceId, &clickX, &clickY, 
                 &clickButtonId, &clickIsDown, &clickEvent);

          // If down event for EVT_PAN
          if (clickIsDown && clickEvent == EVT_PAN) {

            // Set initial position of click event
            _translatePosition[0] = clickX;
            _translatePosition[1] = clickY;

          }

          // If down event for EVT_ZOOM
          if (clickIsDown && clickEvent == EVT_ZOOM) {

            // Set initial position of click event
            _scalePosition[0] = clickX;
            _scalePosition[1] = clickY;

            // Calculate the location of the device in world space
            float initX = 
              (_scalePosition[0] * 
               (_totalDisplayFrustum[1] - _totalDisplayFrustum[0])) +
              _totalDisplayFrustum[0];
            float initY =
              (_scalePosition[1] * 
               (_totalDisplayFrustum[3] - _totalDisplayFrustum[2])) +
              _totalDisplayFrustum[2];

            // Calculate the location of the device with respect to the
            // untransfomred object in world space
            initX -= _worldTranslate[0];
            initY -= _worldTranslate[1];
            initX /= _worldScale[0];
            initY /= _worldScale[1];

            // Keep these values
            _scalePositionUntransformed[0] = initX;
            _scalePositionUntransformed[1] = initY;
            
          }

          // If down event for EVT_ROTATE
          if (clickIsDown && clickEvent == EVT_ROTATE) {

            // Set inital position
            _rotatePosition[0] = clickX;
            _rotatePosition[1] = clickY;

            // Normalize object's translation to (-1.0, 1.0)
            float nTx = (_worldTranslate[0] - _totalDisplayFrustum[0]) /
              (_totalDisplayFrustum[1] - _totalDisplayFrustum[0]);
            nTx = (nTx * 2.0) - 1.0;
            float nTy = (_worldTranslate[1] - _totalDisplayFrustum[2]) /
              (_totalDisplayFrustum[3] - _totalDisplayFrustum[2]);
            nTy = (nTy * 2.0) - 1.0;
        
            // Normalize puck's position to (-1.0, 1.0)
            float nXpos = (clickX * 2.0) - 1.0;
            float nYpos = (clickY * 2.0) - 1.0;
        
            // Start trackball
            _eventTrackball.Start(nXpos - nTx, nYpos - nTy);

          }

          // If up event
          if (clickIsDown == 0) {

            // Force the renderer to update
            UpdateCommandRender();
            _communicator -> Barrier();
            UpdateCommandRender();
            _communicator -> Barrier();
            UpdateCommandRender();
            _communicator -> Barrier();
            UpdateCommandRender();
            _communicator -> Barrier();
            UpdateCommandRender();
            _communicator -> Barrier();

          }

          // Done with EVT_CLICK case
          break;

        }
        

        // Pan event
        case EVT_PAN: {

          // Pan event properties
          int panDeviceId;
          
          // Pan event x and y location and change in x, y and z direction
          // normalized to size of window
          float panX, panY, panDX, panDY, panDZ;
          sscanf(data, 
                 "%d %f %f %f %f %f", 
                 &panDeviceId, &panX, &panY, &panDX, &panDY, &panDZ);

          // Print event
          //fprintf(stderr,
          //        "PAN MESSAGE: %f %f %f %f %f\n",
          //        panX, panY, panDX, panDY, panDZ);

          // Calculate amount the device has moved in world space since it 
          // was clicked.
          float deltaT[2] = {((_translatePosition[0]-
                               (_translatePosition[0] + panDX)) * 
                              (_totalDisplayFrustum[1] - 
                               _totalDisplayFrustum[0])), 
                             ((_translatePosition[1]-
                               (_translatePosition[1] + panDY)) *
                              (_totalDisplayFrustum[3] - 
                               _totalDisplayFrustum[2]))};
          
          // Add the offset
          _worldTranslate[0] -= deltaT[0];
          _worldTranslate[1] -= deltaT[1];
          
          // Determine translation matrix
          float T[16];
          calc_trans(T, 
                     _worldTranslate[0], 
                     _worldTranslate[1], 
                     0.0);
          
          // Send translation matrix to UI
          _userInterfaceServer.SendTranslationMatrix(T);

          // Set the translation matrix
          UpdateTranslationMatrix(T);
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();

          // Update translate device position
          _translatePosition[0] += panDX;
          _translatePosition[1] += panDY;
          
          // Done with EVT_PAN case
          break;

        }

        // Zoom event
        case EVT_ZOOM: {

          // Zoom event properties
          int zoomDeviceId;
          
          // Zoom event x and y location and change in x, y and z direction
          // normalized to size of window
          float zoomX, zoomY, zoomDX, zoomDY, zoomDZ;
          sscanf(data, 
                 "%d %f %f %f %f %f", 
                 &zoomDeviceId, &zoomX, &zoomY, &zoomDX, &zoomDY, &zoomDZ);

          // Print event
          //fprintf(stderr,
          //        "ZOOM MESSAGE: %f %f %f %f %f\n",
          //        zoomX, zoomY, zoomDX, zoomDY, zoomDZ);

          // Calcualte amount the device has moved
          float deltaZ[2] = {-zoomDX, -zoomDY};

          // Update world scale by delta
          _worldScale[0] *= 1.0 - (deltaZ[0] + deltaZ[1]);
          _worldScale[1] *= 1.0 - (deltaZ[0] + deltaZ[1]);
          _worldScale[2] *= 1.0 - (deltaZ[0] + deltaZ[1]);

          // Don't let world scale go below 1.0
          if (_worldScale[0] < 1.0) _worldScale[0] = 1.0;
          if (_worldScale[1] < 1.0) _worldScale[1] = 1.0;
          if (_worldScale[2] < 1.0) _worldScale[2] = 1.0;

          // Determine scale matrix
          float S[16];
          calc_scale(S, 
                     _worldScale[0], 
                     _worldScale[1], 
                     _worldScale[2]);

          // Calculate the initial location of the device in world space
          float initX = 
            (zoomX * 
             (_totalDisplayFrustum[1] - _totalDisplayFrustum[0])) +
            _totalDisplayFrustum[0];
          float initY =
            (zoomY * 
             (_totalDisplayFrustum[3] - _totalDisplayFrustum[2])) +
            _totalDisplayFrustum[2];

          // Determine new translation based on scale
          _worldTranslate[0] = 
            initX - (_scalePositionUntransformed[0] * _worldScale[0]);
          _worldTranslate[1] = 
            initY - (_scalePositionUntransformed[1] * _worldScale[1]);

          // Determine new translation matrix
          float T[16];
          calc_trans(T, 
                     _worldTranslate[0], 
                     _worldTranslate[1], 
                     0.0);

          // Send scale matrix to UI
          _userInterfaceServer.SendScaleMatrix(S);

          // Send translation matrix to UI
          _userInterfaceServer.SendTranslationMatrix(T);

          // Set the scale and translation matrices
          UpdateScaleMatrix(S);
          _communicator -> Barrier();
          UpdateTranslationMatrix(T);
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();

          // Done with EVT_ZOOM case
          break;
             
        }

        // Rotate event
        case EVT_ROTATE: {

          // Rotate event properties
          int rotateDeviceId;
          
          // Rotate event x and y location and change in x, y and z direction
          // normalized to size of window
          float rotateX, rotateY, rotateDX, rotateDY, rotateDZ;
          sscanf(data, 
                 "%d %f %f %f %f %f", 
                 &rotateDeviceId, &rotateX, &rotateY, 
                 &rotateDX, &rotateDY, &rotateDZ);

          //fprintf(stderr, "EVT_ROTATE: %f %f %f %f %f\n",
          //        rotateX, rotateY, rotateDX, rotateDY, rotateDZ);

          // Normalize object's translation to (-1.0, 1.0)
          float nTx = (_worldTranslate[0] - _totalDisplayFrustum[0]) /
            (_totalDisplayFrustum[1] - _totalDisplayFrustum[0]);
          nTx = (nTx * 2.0) - 1.0;
          float nTy = (_worldTranslate[1] - _totalDisplayFrustum[2]) /
            (_totalDisplayFrustum[3] - _totalDisplayFrustum[2]);
          nTy = (nTy * 2.0) - 1.0;

          // Normalize puck's position to (-1.0, 1.0)
          float nXpos = (_rotatePosition[0] * 2.0) - 1.0;
          float nYpos = (_rotatePosition[1] * 2.0) - 1.0;

          // Update trackball
          _eventTrackball.Update(nXpos - nTx, nYpos - nTy);
      
          // Get rotation from trackball
          float R[16];
          _eventTrackball.GetRotationMatrix(R);

          // Send rotation matrix to UI
          _userInterfaceServer.SendRotationMatrix(R);

          // Set the rotation matrix
          UpdateRotationMatrix(R);
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();
          UpdateCommandRender();
          _communicator -> Barrier();

          _rotatePosition[0] += rotateDX;
          _rotatePosition[1] += rotateDY;

          // Done with EVT_ZOOM case
          break;

        }

        }
        
      }

#endif

    }

  }

  // One last barrier
  _communicator -> Barrier();

}