示例#1
0
	registry::data_id_type GetDeviceRegistryProperty(
		const sp_devinfo_data &DeviceInfoData,
		spdrp Property,
		com::bstr_t &Buffer) const
	{
		registry::data_id_type PropertyRegDataType;
		dword_t RequiredSize;
		try
		{
			this->GetDeviceRegistryProperty<wchar_t>(
				DeviceInfoData,
				Property,
				PropertyRegDataType,
				byte_range(),
				RequiredSize);
		}
		catch(const windows::exception &E)
		{
			if(E.result()!=windows::exception::insufficient_buffer) throw;
			if(
				PropertyRegDataType!=registry::data_id_type::sz &&
				PropertyRegDataType!=registry::data_id_type::multi_sz)
				throw get_device_registry_property_exception();
		}
		Buffer.resize(RequiredSize/2 - 1);
		this->GetDeviceRegistryProperty<wchar_t>(
			DeviceInfoData,
			Property,
			PropertyRegDataType,
			byte_range(
				(byte_t *)Buffer.c_str(), 
				(byte_t *)(Buffer.c_str() + Buffer.size() + 1)),
			RequiredSize);
		return PropertyRegDataType;
	}
示例#2
0
	scoped_unprotect::scoped_unprotect(byte_range region)
		: _region(region)
	{
		byte *page = reinterpret_cast<byte *>(reinterpret_cast<size_t>(region.begin()) & ~static_cast<size_t>(0x0FFF));
		size_t full_length = region.length() + (region.begin() - page);
		
		_region = byte_range(page, full_length);
		if (mprotect(_region.begin(), _region.length(), PROT_EXEC | PROT_READ | PROT_WRITE))
			throw std::runtime_error("Cannot change protection mode!");
	}
示例#3
0
float* convert_displacements_to_image(
                            /************************************************/
    float  **u,             /* in  : x component of flow field              */
    float  **v,             /* in  : y component of flow field              */
    int    nx,              /* in  : size in x-direction                    */
    int    ny,              /* in  : size in y-direction                    */
    int    bx,              /* in  : boundary size in x-direction           */
    int    by,              /* in  : boundary size in y-direction           */
    float  min_length,      /* in  : treshold for maximum flow              */
    float  max_length      /* in  : treshold for minimum flow              */
                            /************************************************/
)

/* creates image from displacement field*/

{
                  /**********************************************************/
    int   i,j;    /* loop variable                                          */
    int   R,G,B;  /* RGB values                                             */
    float factor; /* scaling factor                                         */
    float tmp;    /* aux variable                                           */
                  /**********************************************************/

    /* compute scaling factor */
    factor=1.0/max_length;
    float * img= new float[3*nx*ny];

    /* original grey value image with color flow field */
    for(i=bx; i < nx+bx;i++)
      for(j=by; j < ny+by;j++)
    	{
    	  /* compute RGB value for current flow vector */
    	  vector_to_RGB(u[i][j]*factor,v[i][j]*factor,&R,&G,&B);
        img[(j-by)*nx*3+(i-bx)*3] = byte_range(R)/255.0;
        img[(j-by)*nx*3+(i-bx)*3+1] = byte_range(G)/255.0;
        img[(j-by)*nx*3+(i-bx)*3+2] = byte_range(B)/255.0;
    	}
    return img;
}
示例#4
0
void store_displacements_to_image
(
                            /************************************************/
    float  **u,             /* in  : x component of flow field              */
    float  **v,             /* in  : y component of flow field              */
    float  **f1,            /* in  : 1st image                              */
    int    nx,              /* in  : size in x-direction                    */
    int    ny,              /* in  : size in y-direction                    */
    int    bx,              /* in  : boundary size in x-direction           */
    int    by,              /* in  : boundary size in y-direction           */
    float  min_length,      /* in  : treshold for maximum flow              */
    float  max_length,      /* in  : treshold for minimum flow              */
    float  ***p6            /* out : RGB image                              */
                            /************************************************/
)

/* creates image from displacement field*/

{
                  /**********************************************************/
    int   i,j;    /* loop variable                                          */
    int   R,G,B;  /* RGB values                                             */
    float factor; /* scaling factor                                         */
    float tmp;    /* aux variable                                           */
                  /**********************************************************/

    /* compute scaling factor */
    factor=1.0/max_length;

    /* original grey value image with color flow field */
    for(i=bx; i < nx+bx;i++)
      for(j=by; j < ny+by;j++)
    	{
    	  /* left side : original image */
    	  p6[i][j][0]=byte_range((int)u[i][j]);
    	  p6[i][j][1]=byte_range((int)v[i][j]);
    	  p6[i][j][2]=byte_range((int)f1[i][j]);
    	}
}
示例#5
0
void copy_refocus_image
(
                            /************************************************/
    float  **f1,            /* in  : 1st image                              */
    float  ***refocus,      /* in  : refocus image                          */
    int    nx,              /* in  : size in x-direction                    */
    int    ny,              /* in  : size in y-direction                    */
    int    bx,              /* in  : boundary size in x-direction           */
    int    by,              /* in  : boundary size in y-direction           */
    float  min_length,      /* in  : treshold for maximum flow              */
    float  max_length,      /* in  : treshold for minimum flow              */
    float  ***p6            /* out : RGB image                              */
                            /************************************************/
)

/* creates image from displacement field*/

{
                  /**********************************************************/
    int   i,j;    /* loop variable                                          */
    int   R,G,B;  /* RGB values                                             */
    float factor; /* scaling factor                                         */
    float tmp;    /* aux variable                                           */
                  /**********************************************************/

    /* compute scaling factor */
    factor=1.0/max_length;

    /* original grey value image with color flow field */
    tmp = 0;
    for(i=bx; i < nx+bx;i++)
      for(j=by; j < ny+by;j++)
	{
	  /* left side : original image */
	  p6[i][j][0]=byte_range((int)f1[i][j]);
	  p6[i][j][1]=byte_range((int)f1[i][j]);
	  p6[i][j][2]=byte_range((int)f1[i][j]);

	  /* compute RGB value for current flow vector */
	  //vector_to_RGB(u[i][j]*factor,v[i][j]*factor,&R,&G,&B);
    if(tmp<refocus[i][j][0])
      tmp = refocus[i][j][0];
    R= (int)(refocus[i][j][0]*255);
    G= (int)(refocus[i][j][1]*255);
    B= (int)(refocus[i][j][2]*255);


	  /* right side : flow field */
	  p6[i+nx][j][0]=(int)byte_range(R);
	  p6[i+nx][j][1]=(int)byte_range(G);
	  p6[i+nx][j][2]=(int)byte_range(B);
	}
  //printf("max channel 0 %f\n",tmp);

}
示例#6
0
std::vector< std::vector<RGBA> > FlowField::getColorImage(){

  // make temporary array
  std::pair<int, int> size = Size();
  std::vector< std::vector<RGBA> > img(size.first, std::vector<RGBA>(size.second));

  double Pi = M_PI;
  double amp;
  double phi;
  double alpha, beta;
  double x, y;

  for (int i = 0; i < size.first; i++){
    for (int j = 0; j < size.second; j++){
      x = u.At(i, j, true);
      y = v.At(i, j, true);

      /* determine amplitude and phase (cut amp at 1) */
      amp = sqrt (x * x + y * y);
      if (amp > 1) amp = 1;
      if (x == 0.0)
        if (y >= 0.0) phi = 0.5 * Pi;
        else phi = 1.5 * Pi;
      else if (x > 0.0)
        if (y >= 0.0) phi = atan (y/x);
        else phi = 2.0 * Pi + atan (y/x);
      else phi = Pi + atan (y/x);
      phi = phi / 2.0;

      img[i][j].a = 255;

      // interpolation between red (0) and blue (0.25 * Pi)
      if ((phi >= 0.0) && (phi < 0.125 * Pi)) {
        beta  = phi / (0.125 * Pi);
        alpha = 1.0 - beta;
        img[i][j].r = (unsigned char)floor(amp * (alpha * 255.0 + beta * 255.0));
        img[i][j].g = (unsigned char)floor(amp * (alpha *   0.0 + beta *   0.0));
        img[i][j].b = (unsigned char)floor(amp * (alpha *   0.0 + beta * 255.0));
      }
      if ((phi >= 0.125 * Pi) && (phi < 0.25 * Pi)) {
        beta  = (phi-0.125 * Pi) / (0.125 * Pi);
        alpha = 1.0 - beta;
        img[i][j].r = (unsigned char)floor(amp * (alpha * 255.0 + beta *  64.0));
        img[i][j].g = (unsigned char)floor(amp * (alpha *   0.0 + beta *  64.0));
        img[i][j].b = (unsigned char)floor(amp * (alpha * 255.0 + beta * 255.0));
      }
      // interpolation between blue (0.25 * Pi) and green (0.5 * Pi)
      if ((phi >= 0.25 * Pi) && (phi < 0.375 * Pi)) {
        beta  = (phi - 0.25 * Pi) / (0.125 * Pi);
        alpha = 1.0 - beta;
        img[i][j].r = (unsigned char)floor(amp * (alpha *  64.0 + beta *   0.0));
        img[i][j].g = (unsigned char)floor(amp * (alpha *  64.0 + beta * 255.0));
        img[i][j].b = (unsigned char)floor(amp * (alpha * 255.0 + beta * 255.0));
      }
      if ((phi >= 0.375 * Pi) && (phi < 0.5 * Pi)) {
        beta  = (phi - 0.375 * Pi) / (0.125 * Pi);
        alpha = 1.0 - beta;
        img[i][j].r = (unsigned char)floor(amp * (alpha *   0.0 + beta *   0.0));
        img[i][j].g = (unsigned char)floor(amp * (alpha * 255.0 + beta * 255.0));
        img[i][j].b = (unsigned char)floor(amp * (alpha * 255.0 + beta *   0.0));
      }
      // interpolation between green (0.5 * Pi) and yellow (0.75 * Pi)
      if ((phi >= 0.5 * Pi) && (phi < 0.75 * Pi)) {
        beta  = (phi - 0.5 * Pi) / (0.25 * Pi);
        alpha = 1.0 - beta;
        img[i][j].r = (unsigned char)floor(amp * (alpha * 0.0   + beta * 255.0));
        img[i][j].g = (unsigned char)floor(amp * (alpha * 255.0 + beta * 255.0));
        img[i][j].b = (unsigned char)floor(amp * (alpha * 0.0   + beta * 0.0));
      }
      // interpolation between yellow (0.75 * Pi) and red (Pi)
      if ((phi >= 0.75 * Pi) && (phi <= Pi)) {
        beta  = (phi - 0.75 * Pi) / (0.25 * Pi);
        alpha = 1.0 - beta;
        img[i][j].r = (unsigned char)floor(amp * (alpha * 255.0 + beta * 255.0));
        img[i][j].g = (unsigned char)floor(amp * (alpha * 255.0 + beta *   0.0));
        img[i][j].b = (unsigned char)floor(amp * (alpha * 0.0   + beta *   0.0));
      }

      /* check RGB range */
      img[i][j].r = byte_range((int)img[i][j].r);
      img[i][j].g = byte_range((int)img[i][j].g);
      img[i][j].b = byte_range((int)img[i][j].b);
    }
  }


  return img;
}