Example #1
0
// Set pixel format and other properties based on a paint device.
void QEglProperties::setPaintDeviceFormat(QPaintDevice *dev)
{
    int devType = dev->devType();
    if (devType == QInternal::Image)
        setPixelFormat(static_cast<QImage *>(dev)->format());
    else
        setPixelFormat(QImage::Format_RGB16); // XXX
}
Example #2
0
// Set pixel format and other properties based on a paint device.
void QEglProperties::setPaintDeviceFormat(QPaintDevice *dev)
{
    if (!dev)
        return;

    // Find the QGLScreen for this paint device.
    QScreen *screen = screenForDevice(dev);
    if (!screen)
        return;
    int devType = dev->devType();
    if (devType == QInternal::Image)
        setPixelFormat(static_cast<QImage *>(dev)->format());
    else
        setPixelFormat(screen->pixelFormat());
}
Example #3
0
bool Image::copyPixels(unsigned char* pix, unsigned int w, unsigned int h, unsigned format) {

  if(!setPixelFormat(format)) {
    return false;
  }

  if(pixels) {
    delete[] pixels;
    pixels = NULL;
  }

  setWidth(w);
  setHeight(h);
  setStride(w * (bits_per_pixel / 8));
  unsigned int num_bytes =  h * stride;
  pixels = new unsigned char[num_bytes];

  if(!pixels) {
    RX_ERROR(ERR_IMG_CANNOT_ALLOCATE);
    return false;
  }
  
  memcpy(pixels, pix, num_bytes);

  

  return true;
}
Example #4
0
// This sets up "OpenGL" for us -- If an error occurs the method returns false
// otherwise the method returns true
bool CGLObj::init(HDC win_hdc, GLint colorBits, GLint depthBits)
{
    // Error check
    if(!win_hdc)
        return false;

    // DO NOT allow double initialization
    if(hglrc)
        return false;

    hdc = win_hdc; // Save off the window's HDC

    // Set the pixel format
    if(!setPixelFormat(colorBits, depthBits))
        return false;

    // Set the render context
    if(!setRenderContext())
        return false;

    // Enable flags we want
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable(GL_TEXTURE_2D);
    return true; // OpenGL is up and running :)
}
bool OpenGLWindow::createContext( int colorBits, int depthBits, int stencilBits)
{
	bool	returnValue = false;
	HWND	handle;



	if ( this->getHandle() == NULL )
		handle = ((OpenGLController*)this->getParameters())->getHandle();
	else
		handle = this->getHandle();


	// retrieve a handle to a display device context
	handleDC = GetDC(handle);
	// set pixel format
	if ( !setPixelFormat(this->handleDC, colorBits, depthBits, stencilBits) )
		throw exception("Cannot set a suitable pixel format!");
	else
	{
		// create a new OpenGL rendering context
		handleGLRC = wglCreateContext(this->handleDC);
		returnValue = true;
	}



	ReleaseDC(handle,this->handleDC);
	return returnValue;
};
/*!
    \internal
*/
void QProxyScreen::configure()
{
    if (!realScreen)
        return;

    d = realScreen->depth();
    w = realScreen->width();
    h = realScreen->height();
    dw = realScreen->deviceWidth();
    dh = realScreen->deviceHeight();
    lstep = realScreen->linestep();
    data = realScreen->base();
    lstep = realScreen->linestep();
    size = realScreen->screenSize();
    physWidth = realScreen->physicalWidth();
    physHeight = realScreen->physicalHeight();
    pixeltype = realScreen->pixelType();
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
    setFrameBufferLittleEndian(realScreen->frameBufferLittleEndian());
#endif

    setOffset(realScreen->offset());
    setPixelFormat(realScreen->pixelFormat());

#ifdef QT_QWS_CLIENTBLIT
    setSupportsBlitInClients(realScreen->supportsBlitInClients());
#endif
}
Example #7
0
    void
    VLC::load(const std::string & theFilename) {

        AC_DEBUG << "VLC::load('" << theFilename << "')";

        _EOF = false;
        _playTime = 0;
        
        std::vector<std::string> elements = asl::splitString(theFilename, "#");
        if (elements.size() == 2) {
            _playTime = as<asl::Unsigned64>(elements[1]);
            AC_DEBUG << "parsed playback position at " << _playTime << " milliseconds.";
        }
        
        _mediaURL = elements[0];
        libvlc_media_t *media = libvlc_media_new_location(_libvlc, _mediaURL.c_str());
        libvlc_media_player_set_media(_mediaPlayer, media);
        libvlc_media_release(media);

        libvlc_video_set_callbacks(_mediaPlayer, VLC::lock, VLC::unlock, VLC::display, this);
        _rasterEncoding = BGR;
        setPixelFormat(_rasterEncoding);
        libvlc_video_set_format_callbacks(_mediaPlayer, VLC::setup_video, VLC::cleanup_video);

        libvlc_media_player_play(_mediaPlayer);
        if (_playTime > 0) {
            libvlc_media_player_set_time(_mediaPlayer, _playTime);
        }
    }
    WindowedGLContext (Component* const component_,
                       HGLRC contextToShareWith,
                       const OpenGLPixelFormat& pixelFormat)
        : renderContext (0),
          component (component_),
          dc (0)
    {
        initialiseGLExtensions();
        jassert (component != nullptr);
        createNativeWindow();

        PIXELFORMATDESCRIPTOR pfd;
        initialisePixelFormatDescriptor (pfd, pixelFormat);

        const int format = ChoosePixelFormat (dc, &pfd);

        if (format != 0)
            SetPixelFormat (dc, format, &pfd);

        renderContext = wglCreateContext (dc);

        if (renderContext != 0)
        {
            makeActive();
            initialiseGLExtensions();
            extensions.initialise();
            setPixelFormat (pixelFormat);

            if (contextToShareWith != 0)
                wglShareLists (contextToShareWith, renderContext);
        }
    }
Example #9
0
void ofFadeVid::setup(string filename_in) {
    setPixelFormat(OF_PIXELS_RGBA);
    ofEnableAlphaBlending();
    alpha = 0.0f;
    alphaDest = 1.0f;
    loadMovie(filename_in);
}
void ArchiveClip::setup ( string videoPath )
{
    alpha = 255.0f ;
    setPixelFormat(OF_PIXELS_RGB );
    ofQTKitDecodeMode decodeMode = OF_QTKIT_DECODE_TEXTURE_ONLY;
    path = videoPath ;
}
//--------------------------------------------------------------
ofxThreadedVideo::ofxThreadedVideo(){

    // setup video instances
    videos[0].setUseTexture(false);
    videos[1].setUseTexture(false);
    setPixelFormat(OF_PIXELS_RGB);
    bFrameNew[0] = bFrameNew[1] = false;
    paths[0] = paths[1] = names[0] = names[1] = "";

    // set vars to default values
    loadVideoID = VIDEO_NONE;
    currentVideoID = VIDEO_NONE;
    loadPath = "";

    newPosition[0] = newPosition[1] = -1.0f;
    newFrame[0] = newFrame[1] = -1;
    bPaused[0] = bPaused[1] = false;
    bUseTexture = true;
    volume[0] = volume[1] = 255;
    newSpeed[0] = newSpeed[1] = 1.0f;
    newLoopType[0] = newLoopType[1] = -1;
    frame[0] = frame[1] = 0;

    bUseAutoPlay = true;
    bUseQueue = false;

    prevMillis = ofGetElapsedTimeMillis();
    lastFrameTime = timeNow = timeThen = fps = frameRate = 0;

    // let's go!
    startThread(false, false);
}
Example #12
0
 void createOpenGLContext()
 {
     setPixelFormat(24);
     if (NULL == (mHGLRC = wglCreateContext(mHDC)))
     {
         throw std::exception("Cannot create OpenGL context!");
     }
 }
Example #13
0
	SurfaceSDL::SurfaceSDL(SDL_Surface* surface)
		: surface_(surface)
	{
		ASSERT_LOG(surface_ != nullptr, "Error creating surface: " << SDL_GetError());
		auto pf = std::make_shared<SDLPixelFormat>(surface_->format->format);
		setPixelFormat(PixelFormatPtr(pf));
		createPalette();
	}
Example #14
0
// Set pixel format and other properties based on a paint device.
void QEglProperties::setPaintDeviceFormat(QPaintDevice *dev)
{
    if (!dev)
        return;
    if (dev->devType() == QInternal::Image)
        setPixelFormat(static_cast<QImage *>(dev)->format());
    else
        setVisualFormat(qt_x11Info(dev));
}
Example #15
0
//! [0]
bool SvgalibScreen::connect(const QString &displaySpec)
{
    int mode = vga_getdefaultmode();
    if (mode <= 0) {
        qCritical("SvgalibScreen::connect(): invalid vga mode");
        return false;
    }

    vga_modeinfo *modeinfo = vga_getmodeinfo(mode);

    QScreen::lstep = modeinfo->linewidth;
    QScreen::dw = QScreen::w = modeinfo->width;
    QScreen::dh = QScreen::h = modeinfo->height;
    QScreen::d = getModeDepth(modeinfo);
    QScreen::size = QScreen::lstep * dh;
    QScreen::data = 0;

    switch (depth()) {
    case 32:
        setPixelFormat(QImage::Format_ARGB32_Premultiplied);
        break;
    case 24:
        setPixelFormat(QImage::Format_RGB888);
        break;
    case 16:
        setPixelFormat(QImage::Format_RGB16);
        break;
    case 15:
        setPixelFormat(QImage::Format_RGB555);
        break;
    default:
        break;
    }

    const int dpi = 72;
    QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
    QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);

    const QStringList args = displaySpec.split(QLatin1Char(':'),
                                               QString::SkipEmptyParts);
    grayscale = args.contains(QLatin1String("grayscale"), Qt::CaseInsensitive);

    return true;
}
Example #16
0
	SurfaceSDL::SurfaceSDL(int width, int height, PixelFormat::PF format)
	{
		int bpp;
		uint32_t rmask, gmask, bmask, amask;
		SDL_bool ret = SDL_PixelFormatEnumToMasks(get_sdl_pixel_format(format), &bpp, &rmask, &gmask, &bmask, &amask);
		ASSERT_LOG(ret != SDL_FALSE, "Unable to convert pixel format to masks: " << SDL_GetError());

		surface_ = SDL_CreateRGBSurface(0, width, height, bpp, rmask, gmask, bmask, amask);
		ASSERT_LOG(surface_ != nullptr, "Error creating surface: " << SDL_GetError());
		auto pf = std::make_shared<SDLPixelFormat>(surface_->format->format);
		setPixelFormat(PixelFormatPtr(pf));
		createPalette();
	}
Example #17
0
	void SurfaceSDL::writePixels(int bpp, 
		uint32_t rmask, 
		uint32_t gmask, 
		uint32_t bmask, 
		uint32_t amask,
		const void* pixels)
	{
		SDL_FreeSurface(surface_);
		ASSERT_LOG(pixels != nullptr, "nullptr value for pixels while creating surface.");
		surface_ = SDL_CreateRGBSurfaceFrom(const_cast<void*>(pixels), width(), height(), bpp, rowPitch(), rmask, gmask, bmask, amask);
		ASSERT_LOG(surface_ != nullptr, "Error creating surface: " << SDL_GetError());
		setPixelFormat(PixelFormatPtr(new SDLPixelFormat(surface_->format->format)));
	}
Example #18
0
void VideoFrameDesc::setParameters( const ProfileLoader::Profile& profile )
{
	// width
	if( profile.count( constants::avProfileWidth ) )
		setWidth( atoi( profile.find( constants::avProfileWidth )->second.c_str() ) );
	// height
	if( profile.count( constants::avProfileHeight ) )
		setHeight( atoi( profile.find( constants::avProfileHeight )->second.c_str() ) );
	// pixel format	
	if( profile.count( constants::avProfilePixelFormat ) )
		setPixelFormat( profile.find( constants::avProfilePixelFormat )->second );
	// fps
	if( profile.count( constants::avProfileFrameRate ) )
		setFps( atof( profile.find( constants::avProfileFrameRate )->second.c_str() ) );
}
	virtual bool init() {
		// Work with luminance images
		setPixelFormat(ARToolKitPlus::PIXEL_FORMAT_LUM);
		if ( ! checkPixelFormat()) {	
			if (logger)
				logger->artLog("ARToolKitPlus: Invalid Pixel Format!");
			return false;
		}

		// Memory
		if (marker_infoTWO == NULL)
			marker_infoTWO = ARToolKitPlus::artkp_Alloc<ARToolKitPlus::ARMarkerInfo2>(32);

		// Camera
		Camera *camera = new Camera(screenWidth, screenHeight);
		setCamera(camera, 1, 1000);

		// const ARFloat* mat = getProjectionMatrix();
		// printf("Proj mat\n");
		// for(int j=0; j<4; j++) {
		// 	for(int i=0; i<4; i++) {
		// 		printf ("%f, ", mat[i*4 + j]);
		// 	}
		// 	printf ("\n");
		// }

		// Work at full res
		setImageProcessingMode(ARToolKitPlus::IMAGE_FULL_RES);

		// Set border
		setBorderWidth(0.125);

		// Set threshold and activate automatic threshold
		setThreshold(160);
		activateAutoThreshold(true);
		setNumAutoThresholdRetries(2);

		// Switch to BCH ID based markers
		setMarkerMode(ARToolKitPlus::MARKER_ID_BCH);

		// Choose pose estimator
		setPoseEstimator(ARToolKitPlus::
						 //POSE_ESTIMATOR_ORIGINAL);
						 //POSE_ESTIMATOR_ORIGINAL_CONT);
						 POSE_ESTIMATOR_RPP);

		return true;
	}
// Ref: http://doc.trolltech.com/4.2/qtopiacore-svgalib.html
// http://doc.trolltech.com/main-snapshot/ipc-sharedmemory-dialog-cpp.html
bool DuokanScreen::connect(const QString &displaySpec)
{
    Q_UNUSED(displaySpec);

    // Read environment variables.
    int width = qgetenv("SCREEN_WIDTH").toInt();
    int height = qgetenv("SCREEN_HEIGHT").toInt();

    // Fallback if not available.
    if (width <= 0)
    {
        width = DEFAULT_WIDTH;
    }
    if (height <= 0)
    {
        height = DEFAULT_HEIGHT;
    }

    QScreen::lstep = width;
    QScreen::w = width;
    QScreen::h = height;
    QScreen::dw = width;
    QScreen::dh = height;

    QScreen::d = 8;                     // Color depth.
    QScreen::size = width * height;
    QScreen::grayscale = true;
    QScreen::screencols = 16;

    setPixelFormat(QImage::Format_Indexed8);

    for(int i = 0; i < 256; ++i)
        screenclut[i] = qRgb(i, i, i);

    // When we can not create the shared memory, it could be caused that system manager crashed
    // or killed. On Linux, the shared memory is still there, so we can try to attach to the
    // existing shared memory.
    memory_ = new uchar[QScreen::size];
    QScreen::data = memory_;

    // Maybe need to change the dpi later.
    const int dpi = 72;
    QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
    QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);
    return true;
}
// Ref: http://doc.trolltech.com/4.2/qtopiacore-svgalib.html
// http://doc.trolltech.com/main-snapshot/ipc-sharedmemory-dialog-cpp.html
bool KermitScreen::connect(const QString &displaySpec)
{
    Q_UNUSED(displaySpec);

    // Read environment variables.
    int width = qgetenv("SCREEN_WIDTH").toInt();
    int height = qgetenv("SCREEN_HEIGHT").toInt();

    // Fallback if not available.
    if (width <= 0)
    {
        width = DEFAULT_WIDTH;
    }
    if (height <= 0)
    {
        height = DEFAULT_HEIGHT;
    }

    QScreen::d = 32;                     // Color depth.

    QScreen::lstep = width * d / 8;
    QScreen::w = width;
    QScreen::h = height;
    QScreen::dw = width;
    QScreen::dh = height;

    QScreen::size = lstep * height;
    QScreen::grayscale = false;

    setPixelFormat(QImage::Format_ARGB32);

    if (memory_ == 0)
    {
        memory_ = new uchar[size];
        mapsize = size;
        qDebug("map size is %d in argb", mapsize);
    }
    QScreen::data = memory_;

    // Maybe need to change the dpi later.
    const int dpi = 72;
    QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
    QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);
    return true;
}
Example #22
0
void ProxyScreen::configure()
{
    if (!realScreen)
        return;

    d = realScreen->depth();
    w = realScreen->width();
    h = realScreen->height();
    dw = realScreen->deviceWidth();
    dh = realScreen->deviceHeight();
    lstep = realScreen->linestep();
    data = realScreen->base();
    lstep = realScreen->linestep();
    size = realScreen->screenSize();
    physWidth = realScreen->physicalWidth();
    physHeight = realScreen->physicalHeight();

    setOffset(realScreen->offset());
    setPixelFormat(realScreen->pixelFormat());
}
Example #23
0
ciFlyCap::Obj::Obj()
{

	// Set flags
	mCapturing = false;
	mNewFrame = false;

	// Set default properties
	mCamera = 0;
	mChannelCount = 3;
	mDeviceId = 0;
	mSurfaceChannelOrder = SurfaceChannelOrder::RGB;
	setPixelFormat(PixelFormat::PIXEL_FORMAT_RGB8);

	// Get camera count
	mErr = mBusManager.GetNumOfCameras(&mCameraCount);
	if (mErr != PGRERROR_OK)
		showError();

}
Example #24
0
    unsigned  
    VLC::setup_video(char * chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines) {
        AC_DEBUG << "VLC requesting " << chroma << " " << *width << "x" << *height << " for " << _mediaURL;

        // TODO: we could use our YUV shader here
        AC_INFO << "Can't render " << chroma << ", asking libvlc to convert to RGB";
        memcpy(chroma, "RV24", 4);  
        _rasterEncoding = BGR;
        
        _myFrameWidth = *width;
        _myFrameHeight = *height;
        (*pitches) = getBytesRequired(_myFrameWidth, _rasterEncoding);
        (*lines) = _myFrameHeight;
        
        setPixelFormat(_rasterEncoding);
        setFrameHeight(_myFrameHeight);
        setFrameWidth(_myFrameWidth);

        return 1; // one color plane
    }
//--------------------------------------------------------------------
bool ofVideoGrabber::setup(int w, int h, bool setUseTexture) {

#ifndef OF_VID_GRABBER_TYPE
#error OF_VID_GRABBER_TYPE is not #defined!
#endif

    if(!grabber) {
        setGrabber( shared_ptr<OF_VID_GRABBER_TYPE>(new OF_VID_GRABBER_TYPE) );
    }

    bUseTexture = setUseTexture;

    if( requestedDeviceID >= 0 ) {
        grabber->setDeviceID(requestedDeviceID);
    }

    setPixelFormat(internalPixelFormat); //this safely handles checks for supported format

    if( desiredFramerate!=-1 ) {
        grabber->setDesiredFrameRate(desiredFramerate);
    }

    grabber->setup(w, h);
    width			= (int)grabber->getWidth();
    height			= (int)grabber->getHeight();

    if( grabber->isInitialized() && bUseTexture ) {
        if(!grabber->getTexturePtr()) {
            for(int i=0; i<grabber->getPixels().getNumPlanes(); i++) {
                ofPixels plane = grabber->getPixels().getPlane(i);
                tex.push_back(ofTexture());
                tex[i].allocate(plane);
                if(ofIsGLProgrammableRenderer() && plane.getPixelFormat() == OF_PIXELS_GRAY) {
                    tex[i].setRGToRGBASwizzles(true);
                }
            }
        }
    }

    return grabber->isInitialized();
}
//--------------------------------------------------------------------
bool ofVideoGrabber::initGrabber(int w, int h, bool setUseTexture){

#ifndef OF_VID_GRABBER_TYPE
#error OF_VID_GRABBER_TYPE is not #defined! 
#endif
    
	if( grabber == NULL ){
		setGrabber( ofPtr<OF_VID_GRABBER_TYPE>(new OF_VID_GRABBER_TYPE) );
	}

	bInitialized = true;
	bUseTexture = setUseTexture;

	if( RequestedDeviceID >= 0 ){
		grabber->setDeviceID(RequestedDeviceID);
	}

	setPixelFormat(internalPixelFormat); //this safely handles checks for supported format

	if( desiredFramerate!=-1 ){
		grabber->setDesiredFrameRate(desiredFramerate);
	}

	grabberRunning	= grabber->initGrabber(w, h);
	width			= (int)grabber->getWidth();
	height			= (int)grabber->getHeight();

	if( grabberRunning && bUseTexture ){
		if(!grabber->getTexture()) tex.allocate(width, height, ofGetGLInternalFormatFromPixelFormat(internalPixelFormat));
		if(ofGetGLProgrammableRenderer() && internalPixelFormat == OF_PIXELS_MONO){
			tex.setRGToRGBASwizzles(true);
		}
	}

	return grabberRunning;
}
//--------------------------------------------------------------
ofxThreadedVideo::ofxThreadedVideo(){

    instanceID = ofxThreadedVideoGlobalInstanceID;
    ofxThreadedVideoGlobalInstanceID++;
    

#ifdef OF_VIDEO_PLAYER_GSTREAMER
    setPlayer<ofGstVideoPlayer>();
#else
    initializeQuicktime();
    setPlayer<ofQuickTimePlayer>();
#endif
    
    // setup video instances
    video[0].setUseTexture(false);
    video[1].setUseTexture(false);
    
    setPixelFormat(OF_PIXELS_RGB);
    
    drawTexture.allocate(1, 1, GL_RGB);
    ofPixels p;
    p.allocate(1, 1, OF_IMAGE_COLOR);
    p.set(0);
    drawTexture.loadData(p.getPixels(), 1, 1, GL_RGB);
    pixels = &video[0].getPixelsRef();
    
    // set vars to default values
    currentVideoID = VIDEO_FLIP;
    bCriticalSection = false;
    bLoaded = false;
    
    bUseTexture = true;
    bIsFrameNew = false;
    bIsPlaying = false;
    bIsLoading = false;
    bIsMovieDone = false;
    
    width = 0.0f;
    height = 0.0f;
    
    speed = 0.0f;
    position = 0.0f;
    duration = 0.0f;
    
    volume = 0.0f;
    pan = 0.0f;
    
    loopState = OF_LOOP_NORMAL;
    
    frameCurrent = 0;
    frameTotal = 0;
    
    movieName = "";
    moviePath = "";
    
    fade = 1.0f;
    fades.clear();
    
    prevMillis = ofGetElapsedTimeMillis();
    lastFrameTime = timeNow = timeThen = fps = frameRate = 0;
    
    ofxThreadedVideoNullCommand.setCommand("NULL_COMMAND", -1);
    
    bVerbose = false;
    
    // let's go!
    startThread();
}
Example #28
0
bool PvrEglScreen::connect(const QString &displaySpec)
{
    if (!pvrQwsDisplayOpen())
        return false;

    // Initialize the QScreen properties.
    data = (uchar *)(pvrQwsDisplay.screens[0].mapped);
    w = pvrQwsDisplay.screens[0].screenRect.width;
    h = pvrQwsDisplay.screens[0].screenRect.height;
    lstep = pvrQwsDisplay.screens[0].screenStride;
    dw = w;
    dh = h;
    size = h * lstep;
    mapsize = size;
    switch (pvrQwsDisplay.screens[0].pixelFormat) {
	case PVR2D_RGB565:
            d = 16;
            setPixelFormat(QImage::Format_RGB16);
            break;
	case PVR2D_ARGB4444:
            d = 16;
            setPixelFormat(QImage::Format_ARGB4444_Premultiplied);
            break;
	case PVR2D_ARGB8888:
            d = 32;
            setPixelFormat(QImage::Format_ARGB32_Premultiplied);
            break;
        default:
            pvrQwsDisplayClose();
            qWarning("PvrEglScreen::connect: unsupported pixel format %d", (int)(pvrQwsDisplay.screens[0].pixelFormat));
            return false;
    }

    // Handle display physical size spec.
    QStringList displayArgs = displaySpec.split(QLatin1Char(':'));
    QRegExp mmWidthRx(QLatin1String("mmWidth=?(\\d+)"));
    int dimIdxW = displayArgs.indexOf(mmWidthRx);
    QRegExp mmHeightRx(QLatin1String("mmHeight=?(\\d+)"));
    int dimIdxH = displayArgs.indexOf(mmHeightRx);
    if (dimIdxW >= 0) {
        mmWidthRx.exactMatch(displayArgs.at(dimIdxW));
        physWidth = mmWidthRx.cap(1).toInt();
        if (dimIdxH < 0)
            physHeight = dh*physWidth/dw;
    }
    if (dimIdxH >= 0) {
        mmHeightRx.exactMatch(displayArgs.at(dimIdxH));
        physHeight = mmHeightRx.cap(1).toInt();
        if (dimIdxW < 0)
            physWidth = dw*physHeight/dh;
    }
    if (dimIdxW < 0 && dimIdxH < 0) {
        const int dpi = 72;
        physWidth = qRound(dw * 25.4 / dpi);
        physHeight = qRound(dh * 25.4 / dpi);
    }

    // Find the name of the tty device to use.
    QRegExp ttyRegExp(QLatin1String("tty=(.*)"));
    if (displayArgs.indexOf(ttyRegExp) != -1)
        ttyDevice = ttyRegExp.cap(1);
    if (displayArgs.contains(QLatin1String("nographicsmodeswitch")))
        doGraphicsMode = false;

    // The screen is ready.
    return true;
}
Example #29
0
bool QVFbScreen::connect(const QString &displaySpec)
{
    QStringList displayArgs = displaySpec.split(QLatin1Char(':'));
    if (displayArgs.contains(QLatin1String("Gray")))
        grayscale = true;

    key_t key = ftok(QT_VFB_MOUSE_PIPE(displayId).toLocal8Bit(), 'b');

    if (key == -1)
        return false;

#if Q_BYTE_ORDER == Q_BIG_ENDIAN
#ifndef QT_QWS_FRAMEBUFFER_LITTLE_ENDIAN
    if (displayArgs.contains(QLatin1String("littleendian")))
#endif
        QScreen::setFrameBufferLittleEndian(true);
#endif

    int shmId = shmget(key, 0, 0);
    if (shmId != -1)
        d_ptr->shmrgn = (unsigned char *)shmat(shmId, 0, 0);
    else
        return false;

    if ((long)d_ptr->shmrgn == -1 || d_ptr->shmrgn == 0) {
        qDebug("No shmrgn %ld", (long)d_ptr->shmrgn);
        return false;
    }

    d_ptr->hdr = (QVFbHeader *)d_ptr->shmrgn;
    data = d_ptr->shmrgn + d_ptr->hdr->dataoffset;

    dw = w = d_ptr->hdr->width;
    dh = h = d_ptr->hdr->height;
    d = d_ptr->hdr->depth;

    switch (d) {
    case 1:
        setPixelFormat(QImage::Format_Mono);
        break;
    case 8:
        setPixelFormat(QImage::Format_Indexed8);
        break;
    case 12:
        setPixelFormat(QImage::Format_RGB444);
        break;
    case 15:
        setPixelFormat(QImage::Format_RGB555);
        break;
    case 16:
        setPixelFormat(QImage::Format_RGB16);
        break;
    case 18:
        setPixelFormat(QImage::Format_RGB666);
        break;
    case 24:
        setPixelFormat(QImage::Format_RGB888);
        break;
    case 32:
        setPixelFormat(QImage::Format_ARGB32_Premultiplied);
        break;
    }

    lstep = d_ptr->hdr->linestep;

    // Handle display physical size spec.
    int dimIdxW = -1;
    int dimIdxH = -1;
    for (int i = 0; i < displayArgs.size(); ++i) {
        if (displayArgs.at(i).startsWith(QLatin1String("mmWidth"))) {
            dimIdxW = i;
            break;
        }
    }
    for (int i = 0; i < displayArgs.size(); ++i) {
        if (displayArgs.at(i).startsWith(QLatin1String("mmHeight"))) {
            dimIdxH = i;
            break;
        }
    }
    if (dimIdxW >= 0) {
        bool ok;
        int pos = 7;
        if (displayArgs.at(dimIdxW).at(pos) == QLatin1Char('='))
            ++pos;
        int pw = displayArgs.at(dimIdxW).mid(pos).toInt(&ok);
        if (ok) {
            physWidth = pw;
            if (dimIdxH < 0)
                physHeight = dh*physWidth/dw;
        }
    }
    if (dimIdxH >= 0) {
        bool ok;
        int pos = 8;
        if (displayArgs.at(dimIdxH).at(pos) == QLatin1Char('='))
            ++pos;
        int ph = displayArgs.at(dimIdxH).mid(pos).toInt(&ok);
        if (ok) {
            physHeight = ph;
            if (dimIdxW < 0)
                physWidth = dw*physHeight/dh;
        }
    }
    if (dimIdxW < 0 && dimIdxH < 0) {
        const int dpi = 72;
        physWidth = qRound(dw * 25.4 / dpi);
        physHeight = qRound(dh * 25.4 / dpi);
    }

    qDebug("Connected to VFB server %s: %d x %d x %d %dx%dmm (%dx%ddpi)", displaySpec.toLatin1().data(),
        w, h, d, physWidth, physHeight, qRound(dw*25.4/physWidth), qRound(dh*25.4/physHeight) );

    size = lstep * h;
    mapsize = size;
    screencols = d_ptr->hdr->numcols;
    memcpy(screenclut, d_ptr->hdr->clut, sizeof(QRgb) * screencols);

    connected = this;

    if (qgetenv("QT_QVFB_BGR").toInt())
        pixeltype = BGRPixel;

    return true;
}
Example #30
0
bool QAhiScreen::configure()
{
    AhiSurfInfo_t surfaceInfo;
    AhiSts_t status;

    status = AhiSurfInfo(d_ptr->context, d_ptr->surface, &surfaceInfo);
    if (status != AhiStsOk) {
        qCritical("QAhiScreen::configure(): AhiSurfInfo failed: %x", status);
        return false;
    }

    QScreen::data = 0;
    QScreen::w = QScreen::dw = surfaceInfo.size.cx;
    QScreen::h = QScreen::dh = surfaceInfo.size.cy;
    QScreen::lstep = surfaceInfo.stride;
    QScreen::size = surfaceInfo.sizeInBytes;

    switch (surfaceInfo.pixFmt) {
    case AhiPix1bpp:
        setPixelFormat(QImage::Format_Mono);
        QScreen::d = 1;
        break;
    case AhiPix4bpp:
        QScreen::d = 4;
        break;
    case AhiPix8bpp_332RGB:
    case AhiPix8bpp:
        QScreen::d = 8;
        break;
    case AhiPix16bpp_444RGB:
        setPixelFormat(QImage::Format_RGB444);
        QScreen::d = 12;
        break;
    case AhiPix16bpp_555RGB:
        setPixelFormat(QImage::Format_RGB555);
        QScreen::d = 15;
        break;
    case AhiPix16bpp_565RGB:
        setPixelFormat(QImage::Format_RGB16);
        QScreen::d = 16;
        break;
    case AhiPix2bpp:
        QScreen::d = 2;
        break;
    case AhiPix32bpp_8888ARGB:
        setPixelFormat(QImage::Format_ARGB32);
        // fallthrough
    case AhiPix32bpp_8888BGRA:
        QScreen::d = 32;
        break;
    default:
        qCritical("QAhiScreen::configure(): Unknown pixel format: %x",
                  surfaceInfo.pixFmt);
        return false;
    }

    const int dpi = 72;
    QScreen::physWidth = qRound(QScreen::dw * 25.4 / dpi);
    QScreen::physHeight = qRound(QScreen::dh * 25.4 / dpi);

    return true;
}