Esempio n. 1
0
	FHEADER_INLINE void FHeaderElement::mouseMoveEvent(Event::FMouseEvent* e)
	{
		if (isSizable() 
			&& LeftButton == e->button 
			&& FHeaderElement_SizeMode)
		{
			int nWidth = e->mouse.x - FHeaderElement_Rect.left + (FHeaderElement_Rect.right - FHeaderElement_MouseX);
			if (nWidth < 0) nWidth = 0;
			if (getMinWidth() > nWidth) nWidth = getMinWidth();
			if (getMaxWidth() > 0 && getMaxWidth() < nWidth) nWidth = getMaxWidth();

			FHeader *pHeader = NULL;
			if (NULL != getParent())
			{
				pHeader = static_cast<FHeader*>(getParent()->getInterface(FOOWC_HEADER));
			}

			setWidth(nWidth);
			if (NULL != pHeader)
			{
				pHeader->elementWidthChanged(this, nWidth);
			}
		}

		__super::mouseMoveEvent(e);
	}
Esempio n. 2
0
void Window::saveWindowState()
{
    // Saving X, Y and Width and Height for resizables in the config
    if (!mWindowName.empty() && mWindowName != "window")
    {
        config.setValue(mWindowName + "WinX", getX());
        config.setValue(mWindowName + "WinY", getY());

        if (mSaveVisible)
            config.setValue(mWindowName + "Visible", isVisible());

        if (mStickyButton)
            config.setValue(mWindowName + "Sticky", isSticky());

        if (mGrip)
        {
            if (getMinWidth() > getWidth())
                setWidth(getMinWidth());
            else if (getMaxWidth() < getWidth())
                setWidth(getMaxWidth());
            if (getMinHeight() > getHeight())
                setHeight(getMinHeight());
            else if (getMaxHeight() < getHeight())
                setHeight(getMaxHeight());

            config.setValue(mWindowName + "WinWidth", getWidth());
            config.setValue(mWindowName + "WinHeight", getHeight());
        }
    }
}
Esempio n. 3
0
void SmartString::setWidth(int w) {
    m_width = w;
    if(abs(m_width) < getMaxWidth() * 0.2) {
        setColors(E::P.C400);
    } else if(abs(m_width) < getMaxWidth() * 0.4) {
        setColors(E::P.C300);
    } else if(abs(m_width) < getMaxWidth() * 0.6) {
        setColors(E::P.C200);
    } else if(abs(m_width) < getMaxWidth() * 0.7) {
        setColors(E::P.C100);
    } else {
        setColors(E::P.C50);
    }
    m_speed = 3 * getMaxWidth() / (abs(m_width) + 128);
    if(m_width > getMaxWidth()) {
        m_width = getMaxWidth();
    }
    if(m_width < - getMaxWidth()) {
        m_width = - getMaxWidth();
    }
    if(m_width < 0) {
        m_width = -m_width;
        this->setPositionX(m_startingPoint.x-m_width);
    }
    m_middle->setScaleX(m_width / this->getScale());
    _updatePosition();
}
Esempio n. 4
0
void Crowd::binsort()
{
	int i,j,k,l;
	double ndiv,factx,facty,factz;
	deque<int> ibin;
	Node* nd;
	int num;

	/*////
	   double stx,sty,stz;
	   stx = stdpt.getX()/stdrate;
	   sty = stdpt.getY()/stdrate;
	   stz = stdpt.getZ()/stdrate;
	 */                                                                                                                    /////

	///binlist.clear();
	num = getSize();
	///for(i=0;i<num;i++) binlist.push_back(i);

	ndiv = (int)pow((double)num,0.1);
	factx = ndiv / ((getXWidth()) * 1.01 / getMaxWidth());
	facty = ndiv / ((getYWidth()) * 1.01 / getMaxWidth());
	factz = ndiv / ((getZWidth()) * 1.01 / getMaxWidth());

	for(l = 0; l < num; l++)
	{
		nd = getNode(l);
		i = (int)((nd->getX()) * factx);
		j = (int)((nd->getY()) * factz);
		k = (int)((nd->getZ()) * facty);
		//////
		//i = (int)((nd->getX()-stx)*factx);
		//j = (int)((nd->getY()-sty)*factz);
		//k = (int)((nd->getZ()-stz)*facty);
		///////////
		if((k % 2) == 0)
		{
			if((j % 2) == 0)
				ibin.push_back((int)(k * ndiv * ndiv + j * ndiv + i + 1));
			else
				ibin.push_back((int)(k * ndiv * ndiv + (j + 1) * ndiv - i));
		}
		else
		{
			if((j % 2) == 0)
				ibin.push_back((int)(k * ndiv * ndiv + (ndiv - j) * ndiv - i));
			else
				ibin.push_back((int)(k * ndiv * ndiv +
				                     (ndiv - j - 1) * ndiv + i + 1));
		}
	}

	dtm::quickSort(0,num - 1,binlist,ibin);
}
Esempio n. 5
0
/* Driver program to test above functions*/
int main()
{
  struct node *root = newNode(1);
  root->left        = newNode(2);
  root->right       = newNode(3);
  root->left->left  = newNode(4);
  root->left->right = newNode(5);
  root->right->right = newNode(8);
  root->right->right->left  = newNode(6);
  root->right->right->right  = newNode(7);
 
  /*
   Constructed bunary tree is:
          1
        /  \
       2    3
     /  \     \
    4   5     8
              /  \
             6   7
  */
  printf("Maximum width is %d \n", getMaxWidth(root));
  getchar();
  return 0;
}
Esempio n. 6
0
void Map::determineCellTileForMap() {
  for (int x = 0; x < getMaxHeight(); x++) {
    for (int y = 0; y < getMaxWidth(); y++) {
       determineCellTile(getCell(x, y));
    }
  }
}
Esempio n. 7
0
void Window::setContentSize(int width, int height)
{
    width = width + 2 * getPadding();
    height = height + getPadding() + getTitleBarHeight();

    if (getMinWidth() > width)
        width = getMinWidth();
    else if (getMaxWidth() < width)
        width = getMaxWidth();
    if (getMinHeight() > height)
        height = getMinHeight();
    else if (getMaxHeight() < height)
        height = getMaxHeight();

    setSize(width, height);
}
Esempio n. 8
0
void Popup::setContentSize(int width, int height)
{
    width += 2 * getPadding();
    height += 2 * getPadding();

    if (getMinWidth() > width)
        width = getMinWidth();
    else if (getMaxWidth() < width)
        width = getMaxWidth();
    if (getMinHeight() > height)
        height = getMinHeight();
    else if (getMaxHeight() < height)
        height = getMaxHeight();

    setSize(width, height);
    mRedraw = true;
}
Esempio n. 9
0
void Window::setDefaultSize(int defaultX, int defaultY,
                            int defaultWidth, int defaultHeight)
{
    if (getMinWidth() > defaultWidth)
        defaultWidth = getMinWidth();
    else if (getMaxWidth() < defaultWidth)
        defaultWidth = getMaxWidth();
    if (getMinHeight() > defaultHeight)
        defaultHeight = getMinHeight();
    else if (getMaxHeight() < defaultHeight)
        defaultHeight = getMaxHeight();

    mDefaultX = defaultX;
    mDefaultY = defaultY;
    mDefaultWidth = defaultWidth;
    mDefaultHeight = defaultHeight;
}
Esempio n. 10
0
void MyGLWindow::paintGL()
{

  float r=(float)rand()/(float)RAND_MAX;
  float g=(float)rand()/(float)RAND_MAX;
  float b=(float)rand()/(float)RAND_MAX;

  // set the clear colour
  glClearColor(r,g,b,1);

  // clear screen
  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // setup fragment shader variables
  glUseProgram(_program);
  GLint unif_resolution, unif_time, unif_tex0;

  unif_time = glGetUniformLocation(_program, "time");
  float deltaTimeS = getDeltaTimeS();
  glUniform1f(unif_time, deltaTimeS);  
  
  unif_resolution = glGetUniformLocation(_program, "resolution");
  glUniform2f(unif_resolution, getMaxWidth(), getMaxHeight());

  unif_tex0 = glGetUniformLocation(_program, "tex0");
  if (unif_tex0 != -1)
  {
    if (_texture0 != 0)
    {
      glUniform1i(unif_tex0, 0);
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, _texture0);
    }
  }

  /* Describe our vertices array to OpenGL */
  glBindBuffer(GL_ARRAY_BUFFER, _vbo_quad);
  glVertexAttribPointer(
    _attribute_coord2d, // attribute
    2,                 // number of elements per vertex, here (x,y)
    GL_FLOAT,          // the type of each element
    GL_FALSE,          // take our values as-is
    0,                 // no extra data between each position
    0                  // offset of first element
  );
  glEnableVertexAttribArray(_attribute_coord2d);

  /* Push each element in buffer_vertices to the vertex shader */
  glDrawArrays(GL_TRIANGLES, 0, 6);

  glDisableVertexAttribArray(_attribute_coord2d);

  // Swap back buffer to front
  swapBuffers();
}
//initializes the framebuffer
void info_ennowelbers_proxyframebuffer_driver::initFB()
{
	if(fbuffer==NULL)
	{
		//IOLog("StartFramebuffer %d %d\n",width,height);
		//lookahead: there is a framebuffer->thisclassuserclient->userspace path to get the screen capture
		//but the framebuffer memory is not a valid image (it contains more than the normal raw image data)
		//therefore we init a buffer to copy the image into. However, we're getting 
		//a memory footprint of twice maxresolution*3, or at least near that scale 
		//(i assume it's even worse, actually... just keep reading my comments)
		unsigned int size=getMaxWidth()*getMaxHeight()*3;
		buffer=IOBufferMemoryDescriptor::withCapacity(size, kIODirectionInOut);
		//IOLog("buffer=%d\n",buffer);
		
		//yes, i'm not using IOKit's matching system here, i simply instanciate on my own.
		//yes, that's NOT the way they want ist, but 
		//now i can control easily whether the framebuffer gets instanciated or not.
		//and all nessecary dictionary keys are documented.
		fbuffer=new info_ennowelbers_proxyframebuffer_fbuffer();
		
		OSDictionary *dict=OSDictionary::withCapacity(5);
		OSString *bundle=OSString::withCString("info.ennowelbers.syphon.framebuffer");
		OSString *classname=OSString::withCString("info_ennowelbers_syphon_proxyframebuffer_fbuffer");
		OSNumber *debug=OSNumber::withNumber(65535, 32);
		OSString *provider=OSString::withCString("info_ennowelbers_syphon_proxyframebuffer_driver");
		OSString *userclient=OSString::withCString("IOFramebufferUserClient");
		
		dict->setObject("CFBundleIdentifier", bundle);
		dict->setObject("IOClass", classname);
		dict->setObject("IOKitDebug", debug);
		dict->setObject("IOProviderClass", provider);
		dict->setObject("IOUserClientClass", userclient);
		
		bundle->release();
		classname->release();
		debug->release();
		provider->release();
		userclient->release();
		
		fbuffer->init(dict);
		IOLog("EWProxyFrameBuffer: fbuffer retain count: %d\n",fbuffer->getRetainCount());
		dict->release();
		//i forgot why i did this, maybe to ensure that
		//iokit does not mess up with me... 
		//however this is kernel development, trying will keep you rebooting.
		requestProbe(0);
		//attach the framebuffer to this.
		fbuffer->attach(this);
		SInt32 score;
		fbuffer->probe(this, &score);
		fbuffer->start(this);
	}
}
Esempio n. 12
0
bool Snake::colisionWall(){
    SnakePart* head = getHead();
    if( head->direction() == LEFT && head->x() - partSize < 0)
        return true;
    if(head->direction() == RIGHT && head->x() + partSize > getMaxWidth())
        return true;
    if(head->direction() == DOWN && head->y() + 2*partSize > getMaxHeight())
        return true;
    if(head->direction() == UP && head->y() - partSize < 0)
        return true;
    return false;
}
Esempio n. 13
0
void Window::loadWindowState()
{
    const std::string &name = mWindowName;
    assert(!name.empty());

    setPosition((int) config.getValue(name + "WinX", mDefaultX),
                (int) config.getValue(name + "WinY", mDefaultY));

    if (mSaveVisible)
        setVisible((bool) config.getValue(name + "Visible", mDefaultVisible));

    if (mStickyButton)
        setSticky((bool) config.getValue(name + "Sticky", isSticky()));

    if (mGrip)
    {
        int width = (int) config.getValue(name + "WinWidth", mDefaultWidth);
        int height = (int) config.getValue(name + "WinHeight", mDefaultHeight);

        if (getMinWidth() > width)
            width = getMinWidth();
        else if (getMaxWidth() < width)
            width = getMaxWidth();
        if (getMinHeight() > height)
            height = getMinHeight();
        else if (getMaxHeight() < height)
            height = getMaxHeight();

        setSize(width, height);
    }
    else
    {
        setSize(mDefaultWidth, mDefaultHeight);
    }

    // Check if the window is off screen...
    checkIfIsOffScreen();
}
Esempio n. 14
0
void Window::setDefaultSize(int defaultWidth, int defaultHeight,
                            ImageRect::ImagePosition position,
                            int offsetX, int offsetY)
{
    if (getMinWidth() > defaultWidth)
        defaultWidth = getMinWidth();
    else if (getMaxWidth() < defaultWidth)
        defaultWidth = getMaxWidth();
    if (getMinHeight() > defaultHeight)
        defaultHeight = getMinHeight();
    else if (getMaxHeight() < defaultHeight)
        defaultHeight = getMaxHeight();

    int posX = 0, posY = 0;

    getRelativeOffset(position, posX, posY, defaultWidth, defaultHeight, 0, 0);

    mDefaultWidth = defaultWidth;
    mDefaultHeight = defaultHeight;
    mDefaultPosition = position;
    mDefaultOffsetX = posX - offsetX;
    mDefaultOffsetY = posY - offsetY;
}
Esempio n. 15
0
    void TransparentScrollBarV::updatePosition()
    {
        auto scrollButton = qobject_cast<TransparentScrollButtonV*>(getScrollButton());

        const auto ratio = calcScrollBarRatio();

        if (ratio < 0)
        {
            scrollButton->hide();
            hide();
            return;
        }

        if (!L::is_show_with_small_content && ratio >= 1)
        {
            scrollButton->hide();
            hide();
            return;
        }
        else
        {
            scrollButton->show();
            show();
            if (!scrollButton->isVisible())
            {
                fadeIn();
            }
        }

        scrollButton->setFixedSize(scrollButton->width(), calcButtonHeight());
        const auto scrollBar = getDefaultScrollBar();
        const auto val = scrollBar->value();
        const auto max = scrollBar->maximum();
        const auto x = pos().x() + (width() - scrollButton->getMaxWidth()) / 2;

        if (max == 0)
        {
            scrollButton->move(x, pos().y());
            return;
        }

        const auto maxY = height() - scrollButton->height();
        const auto y = (maxY * val) / max + pos().y();

        scrollButton->move(x, y);
    }
Esempio n. 16
0
void UIComponent::renderChar(int x, int y, char c)
{
	if(mParent == NULL)
	{
		WINDOW *wnd = getWindow();
		if(wnd != NULL)
		{
			mvwaddch(wnd, y + getY(), x + getX(), c);
		}
	}
	else
	{
		if(x > getMaxWidth() || y > getMaxHeight())
		{
			return;
		}
		mParent->renderChar(x + getX(), y + getY(), c);
	}
}
bool info_ennowelbers_proxyframebuffer_driver::start(IOService *provider)
{
	bool res=super::start(provider);
	if(res)
	{
		//in order to get a framebuffer up and working, we need to correctly configure powermanagement.
		//we're setting up three power states: off, on and usable.
		PMinit();
		getProvider()->joinPMtree(this);
		static IOPMPowerState myPowerStates[3];
		myPowerStates[0].version=1;
		myPowerStates[0].capabilityFlags=0;
		myPowerStates[0].outputPowerCharacter=0;
		myPowerStates[0].inputPowerRequirement=0;
		myPowerStates[1].version=1;
		myPowerStates[1].capabilityFlags=0;
		myPowerStates[1].outputPowerCharacter=0;
		myPowerStates[1].inputPowerRequirement=IOPMPowerOn;
		myPowerStates[2].version=1;
		myPowerStates[2].capabilityFlags=IOPMDeviceUsable;
		myPowerStates[2].outputPowerCharacter=IOPMPowerOn;
		myPowerStates[2].inputPowerRequirement=IOPMPowerOn;
		registerPowerDriver(this, myPowerStates, 3);
		//and we're switching to power state USABLE
		changePowerStateTo(2);
		//you need to to this AFTER setting power configuration.
		//at least that's what i recall
		registerService();
		IOLog("EWProxyFrameBuffer: start with maximum resolution %dx%d\n",getMaxWidth(),getMaxHeight());
		if(shouldInitFB())
		{
			IOLog("EWProxyFrameBuffer: Initializing Framebuffer. Unload from this point is impossible.\n");
			initFB();
		}
		else
		{
			IOLog("EWProxyFrameBuffer: Framebuffer initialization deactivated.\n");
		}
		//StartFramebuffer(640, 480);
	}
	//IOLog("Starting\n");
	return res;
}
Esempio n. 18
0
int32_t CBC_PDF417Reader::getMaxCodewordWidth(CFX_PtrArray& p) {
  int32_t a =
      getMaxWidth((CBC_ResultPoint*)p.GetAt(6), (CBC_ResultPoint*)p.GetAt(2)) *
      CBC_PDF417Common::MODULES_IN_CODEWORD /
      CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
  int32_t b =
      getMaxWidth((CBC_ResultPoint*)p.GetAt(7), (CBC_ResultPoint*)p.GetAt(3)) *
      CBC_PDF417Common::MODULES_IN_CODEWORD /
      CBC_PDF417Common::MODULES_IN_STOP_PATTERN;
  int32_t c = getMaxWidth((CBC_ResultPoint*)p.GetAt(0),
                          (CBC_ResultPoint*)p.GetAt(4)) < a
                  ? getMaxWidth((CBC_ResultPoint*)p.GetAt(0),
                                (CBC_ResultPoint*)p.GetAt(4))
                  : a;
  int32_t d = getMaxWidth((CBC_ResultPoint*)p.GetAt(1),
                          (CBC_ResultPoint*)p.GetAt(5)) < b
                  ? getMaxWidth((CBC_ResultPoint*)p.GetAt(1),
                                (CBC_ResultPoint*)p.GetAt(5))
                  : b;
  return c < d ? c : d;
}
double AggregatedFeaturesExtractor::getMinScaleFactor(const Mat& image) {
	double minScaleFactor = static_cast<double>(patchSizeInPixels.width) / getMaxWidth(image);
	int maxLayerIndex = static_cast<int>(std::log(minScaleFactor) / std::log(featurePyramid->getIncrementalScaleFactor()));
	return std::pow(featurePyramid->getIncrementalScaleFactor(), maxLayerIndex);
}
Esempio n. 20
0
/*!
  Dump fp_Line information
  \param fp File where the dump should be written to
*/
void fp_Line::__dump(FILE * fp) const
{
	fprintf(fp,"Line: %p Col=%p X=%d Y=%d H=%d W=%d\n",
			static_cast<const void*>(this), static_cast<void*>(getContainer()),
			getX(), getY(), getHeight(), getMaxWidth());
}
Esempio n. 21
0
void Window::loadWindowState()
{
    const std::string &name = mWindowName;
    const std::string skinName = config.getValue(name + "Skin",
                                                 mSkin->getFilePath());
    assert(!name.empty());

    if (mGrip)
    {
        int width = (int) config.getValue(name + "WinWidth", mDefaultWidth);
        int height = (int) config.getValue(name + "WinHeight", mDefaultHeight);

        if (getMinWidth() > width)
            width = getMinWidth();
        else if (getMaxWidth() < width)
            width = getMaxWidth();
        if (getMinHeight() > height)
            height = getMinHeight();
        else if (getMaxHeight() < height)
            height = getMaxHeight();

        setSize(width, height);
    }
    else
    {
        setSize(mDefaultWidth, mDefaultHeight);
    }

    int x = (int) config.getValue(name + "WinX", -1);
    int y = (int) config.getValue(name + "WinY", -1);

    if (x != -1 || y != -1)
    {
        // These two tags are deprecated. Convert them to the new system, then
        // remove them to avoid client coordinate confusion.
        config.removeValue(mWindowName + "WinX");
        config.removeValue(mWindowName + "WinY");
        saveRelativeLocation(x, y);
    }

    int position = (int) config.getValue(name + "Position", -1);
    mOffsetX = (int) config.getValue(name + "OffsetX", mDefaultOffsetX);
    mOffsetY = (int) config.getValue(name + "OffsetY", mDefaultOffsetY);

    if (position != -1)
    {
        mPosition = (ImageRect::ImagePosition) position;
        setLocationRelativeTo(mPosition, mOffsetX, mOffsetY);
    }
    else
    {
        setLocationRelativeTo(mDefaultPosition, mDefaultOffsetX, mDefaultOffsetY);
    }

    if (mSaveVisibility)
    {
        setVisible((bool) config.getValue(name + "Visible", mDefaultVisible));
        mOldVisibility = (bool) config.getValue(name + "Hidden", false);
    }

    if (skinName.compare(mSkin->getFilePath()) != 0)
    {
        mSkin->instances--;
        mSkin = skinLoader->load(skinName, mDefaultSkinPath);
    }
}
Esempio n. 22
0
JNIEXPORT jint JNICALL Java_FTAGUI_FTACanvas_nativeGetMaxWidth(JNIEnv *env, jobject obj){
	jint maxWidth;

	maxWidth = getMaxWidth();
	return maxWidth;
}
Esempio n. 23
0
bool ZDvidDataSliceHelper::hasMaxSize(int width, int height) const
{
  return getMaxWidth() == width && getMaxHeight() == height;
}
Esempio n. 24
0
bool ZDvidDataSliceHelper::getMaxArea() const
{
  return getMaxWidth() * getMaxHeight();
}
Esempio n. 25
0
int  main()
{
	int width;
	char* bayer[] = {"RG","BG","GR","GB"};
	char* controls[MAX_CONTROL] = {"Exposure", "Gain", "Gamma", "WB_R", "WB_B", "Brightness", "USB Traffic"};

	int height;
	int i;
	char c;
	bool bresult;

	int time1,time2;
	int count=0;

	char buf[128]={0};

	int CamNum=0;
	
	///long exposure, exp_min, exp_max, exp_step, exp_flag, exp_default;
	//long gain, gain_min, gain_max,gain_step, gain_flag, gain_default;

	IplImage *pRgb;


	int numDevices = getNumberOfConnectedCameras();
	if(numDevices <= 0)
	{
		printf("no camera connected, press any key to exit\n");
		getchar();
		return -1;
	}
	else
		printf("attached cameras:\n");

	for(i = 0; i < numDevices; i++)
		printf("%d %s\n",i, getCameraModel(i));

	printf("\nselect one to privew\n");
	scanf("%d", &CamNum);


	bresult = openCamera(CamNum);
	if(!bresult)
	{
		printf("OpenCamera error,are you root?,press any key to exit\n");
		getchar();
		return -1;
	}

	printf("%s information\n",getCameraModel(CamNum));
	int iMaxWidth, iMaxHeight;
	iMaxWidth = getMaxWidth();
	iMaxHeight =  getMaxHeight();
	printf("resolution:%dX%d\n", iMaxWidth, iMaxHeight);
	if(isColorCam())
		printf("Color Camera: bayer pattern:%s\n",bayer[getColorBayer()]);
	else
		printf("Mono camera\n");
	
	for( i = 0; i < MAX_CONTROL; i++)
	{
			if(isAvailable((Control_TYPE)i))
				printf("%s support:Yes\n", controls[i]);
			else
				printf("%s support:No\n", controls[i]);
	}

	printf("\nPlease input the <width height bin image_type> with one space, ie. 640 480 2 0. use max resolution if input is 0. Press ESC when video window is focused to quit capture\n");
	int bin = 1, Image_type;
	scanf("%d %d %d %d", &width, &height, &bin, &Image_type);
	if(width == 0 || height == 0)
	{
		width = iMaxWidth;
		height = iMaxHeight;
	}

	initCamera(); //this must be called before camera operation. and it only need init once
	printf("sensor temperature:%02f\n", getSensorTemp());

//	IMG_TYPE image_type;
	
	while(!setImageFormat(width, height, bin, (IMG_TYPE)Image_type))//IMG_RAW8
	{
		printf("Set format error, please check the width and height\n ASI120's data size(width*height) must be integer multiple of 1024\n");
		printf("Please input the width and height again£¬ie. 640 480\n");
		scanf("%d %d %d %d", &width, &height, &bin, &Image_type);
	}
	printf("\nset image format %d %d %d %d success, start privew, press ESC to stop \n", width, height, bin, Image_type);

	
	if(Image_type == IMG_RAW16)
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1);
	else if(Image_type == IMG_RGB24)
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3);
	else
		pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1);

	setValue(CONTROL_EXPOSURE, 100*1000, false); //ms//auto
	setValue(CONTROL_GAIN,getMin(CONTROL_GAIN), false); 
	setValue(CONTROL_BANDWIDTHOVERLOAD, getMin(CONTROL_BANDWIDTHOVERLOAD), false); //low transfer speed

	setValue(CONTROL_WB_B, 90, false);
 	setValue(CONTROL_WB_R, 48, false);
  	setAutoPara(getMax(CONTROL_GAIN)/2,10,150); //max auto gain and exposure and target brightness
//	EnableDarkSubtract("dark.bmp"); //dark subtract will be disabled when exposure set auto and exposure below 500ms
	startCapture(); //start privew


	

	bDisplay = 1;
#ifdef _LIN
	pthread_t thread_display;
	pthread_create(&thread_display, NULL, Display, (void*)pRgb);
#elif defined _WINDOWS
	HANDLE thread_setgainexp;
	thread_setgainexp = (HANDLE)_beginthread(Display,  NULL, (void*)pRgb);
#endif

	time1 = GetTickCount();
	int iStrLen = 0, iTextX = 40, iTextY = 60;
	void* retval;
//	int time0, iWaitMs = -1;
//	bool bGetImg;
	while(bMain)
	{

//		time0 = GetTickCount();
		getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, 200);

//		bGetImg = getImageData((unsigned char*)pRgb->imageData, pRgb->imageSize, iWaitMs);
		time2 = GetTickCount();
//		printf("waitMs%d, deltaMs%d, %d\n", iWaitMs, time2 - time0, bGetImg);
		count++;
		
		if(time2-time1 > 1000 )
		{
			sprintf(buf, "fps:%d dropped frames:%lu ImageType:%d",count, getDroppedFrames(), (int)getImgType());

			count = 0;
			time1=GetTickCount();	
			printf(buf);
			printf("\n");

		}
		if(Image_type != IMG_RGB24 && Image_type != IMG_RAW16)
		{
			iStrLen = strlen(buf);
			CvRect rect = cvRect(iTextX, iTextY - 15, iStrLen* 11, 20);
			cvSetImageROI(pRgb , rect);
			cvSet(pRgb, CV_RGB(180, 180, 180)); 
			cvResetImageROI(pRgb);
		}
		cvText(pRgb, buf, iTextX,iTextY );

		if(bChangeFormat)
		{
			bChangeFormat = 0;
			bDisplay = false;
			pthread_join(thread_display, &retval);
			cvReleaseImage(&pRgb);
			stopCapture();
			
			switch(change)
			{
				 case change_imagetype:
					Image_type++;
					if(Image_type > 3)
						Image_type = 0;
					
					break;
				case change_bin:
					if(bin == 1)
					{
						bin = 2;
						width/=2;
						height/=2;
					}
					else 
					{
						bin = 1;
						width*=2;
						height*=2;
					}
					break;
				case change_size_smaller:
					if(width > 320 && height > 240)
					{
						width/= 2;
						height/= 2;
					}
					break;
				
				case change_size_bigger:
				
					if(width*2*bin <= iMaxWidth && height*2*bin <= iMaxHeight)
					{
						width*= 2;
						height*= 2;
					}
					break;
			}
			setImageFormat(width, height, bin, (IMG_TYPE)Image_type);
			if(Image_type == IMG_RAW16)
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_16U, 1);
			else if(Image_type == IMG_RGB24)
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 3);
			else
				pRgb=cvCreateImage(cvSize(getWidth(),getHeight()), IPL_DEPTH_8U, 1);
			bDisplay = 1;
			pthread_create(&thread_display, NULL, Display, (void*)pRgb);
			startCapture(); //start privew
		}
	}
END:
	
	if(bDisplay)
	{
		bDisplay = 0;
#ifdef _LIN
   		pthread_join(thread_display, &retval);
#elif defined _WINDOWS
		Sleep(50);
#endif
	}
	
	stopCapture();
	closeCamera();
	cvReleaseImage(&pRgb);
	printf("main function over\n");
	return 1;
}