djvViewContext::djvViewContext(QObject * parent) : djvGuiContext(parent), _p(new djvViewContextPrivate) { //DJV_DEBUG("djvViewContext::djvViewContext"); // Load translators. loadTranslator("djvViewLib"); // Load preferences. DJV_LOG(debugLog(), "djvViewContext", "Load the preferences..."); _p->filePrefs = new djvViewFilePrefs(this); _p->imagePrefs = new djvViewImagePrefs(this); _p->inputPrefs = new djvViewInputPrefs(this); _p->playbackPrefs = new djvViewPlaybackPrefs(this); _p->shortcutPrefs = new djvViewShortcutPrefs(this); _p->viewPrefs = new djvViewViewPrefs(this); _p->windowPrefs = new djvViewWindowPrefs(this); DJV_LOG(debugLog(), "djvViewContext", ""); // Initialize objects. DJV_LOG(debugLog(), "djvViewContext", "Initialize objects..."); _p->fileCache = new djvViewFileCache(this); _p->fileSave = new djvViewFileSave(this); DJV_LOG(debugLog(), "djvViewContext", ""); }
void djvFileBrowserModel::imageLoadCallback() { //DJV_DEBUG("djvFileBrowserModel::imageLoadCallback"); QFutureWatcher<Image> * watcher = dynamic_cast<QFutureWatcher<Image> *>(sender()); const QFuture<Image> & future = watcher->future(); const Image & image = future.result(); //DJV_DEBUG_PRINT("image = " << image.image); if (image.row < _p->items.count() && image.item == &_p->items[image.row] && image.valid) { QPixmap thumbnail; try { // Scale the image. djvImage tmp(djvPixelDataInfo( image.item->thumbnailSize(), image.image.pixel())); djvOpenGlImageOptions options; options.xform.scale = djvVector2f(tmp.size()) / (djvVector2f(image.image.size() * djvPixelDataUtil::proxyScale(image.image.info().proxy))); options.colorProfile = image.image.colorProfile; if (djvFileBrowserModel::THUMBNAILS_HIGH == _p->thumbnails) { options.filter = djvOpenGlImageFilter::filterHighQuality(); } djvOpenGlImage::copy(image.image, tmp, options); thumbnail = djvPixelDataUtil::toQt(tmp); } catch (const djvError & error) { DJV_LOG("djvFileBrowserModel", djvErrorUtil::format(error).join("\n")); } _p->items[image.row].setThumbnail(thumbnail); const QModelIndex index = this->index(image.row, 0); Q_EMIT dataChanged(index, index); } watcher->deleteLater(); }
void djvImageView::paintGL() { djvOpenGlWidget::paintGL(); //DJV_DEBUG("djvImageView::draw"); //DJV_DEBUG_PRINT("valid = " << valid()); //DJV_DEBUG_PRINT("view pos = " << _viewPos); //DJV_DEBUG_PRINT("view zoom = " << _viewZoom); const int devicePixelRatio = this->devicePixelRatio(); //DJV_DEBUG_PRINT("devicePixelRatio = " << devicePixelRatio); const djvBox2i geom( width () * devicePixelRatio, height() * devicePixelRatio); //DJV_DEBUG_PRINT("geom = " << geom.size); //if (! valid()) //{ djvOpenGlUtil::ortho(djvVector2i(geom.w, geom.h)); glViewport(0, 0, geom.w, geom.h); //} djvColor background(djvPixel::RGB_F32); djvColorUtil::convert(_p->options.background, background); glClearColor( background.f32(0), background.f32(1), background.f32(2), 0.0); //glClearColor(0, 1, 0, 0); glClear(GL_COLOR_BUFFER_BIT); if (! _p->data) return; //DJV_DEBUG_PRINT("data = " << *_p->data); djvOpenGlImageOptions options = _p->options; options.xform.position += _p->viewPos; options.xform.scale *= _p->viewZoom * devicePixelRatio; try { djvOpenGlImage::draw(*_p->data, options, &_p->state); } catch (const djvError & error) { DJV_LOG("djvImageView", djvErrorUtil::format(error).join("\n")); } }
djvWglContext::djvWglContext(djvCoreContext * context) throw (djvError) : djvOpenGlContext(context), _p(new djvWglContextPrivate) { # if defined(DJV_WINDOWS) //DJV_DEBUG("djvWglContext::djvWglContext"); // Create a dummy window and OpenGL context for glewInit. // According to the docs, glewInit can be called just once per-process? DJV_LOG(context->debugLog(), "djvWglContext", "Creating dummy window..."); HINSTANCE hinstance = GetModuleHandle(0); if (! hinstance) { throw djvError( "djvWglContext", errorLabels()[ERROR_MODULE_HANDLE].arg(int(GetLastError()))); } static const char name [] = "djv"; WNDCLASS wc; if (! GetClassInfo(hinstance, name, &wc)) { wc.style = CS_OWNDC; //wc.lpfnWndProc = (WNDPROC)MainWndProc; wc.lpfnWndProc = DefWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hinstance; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hbrBackground = 0; wc.lpszMenuName = 0; wc.lpszClassName = name; if (! RegisterClass(&wc)) { throw djvError( "djvWglContext", errorLabels()[ERROR_REGISTER_CLASS].arg(int(GetLastError()))); } } _p->id = CreateWindow(name, 0, 0, 0, 0, 0, 0, 0, 0, hinstance, 0); if (! _p->id) { throw djvError( "djvWglContext", errorLabels()[ERROR_CREATE_WINDOW].arg(int(GetLastError()))); } _p->device = GetDC(_p->id); if (! _p->device) { throw djvError( "djvWglContext", errorLabels()[ERROR_GET_DC].arg(int(GetLastError()))); } PIXELFORMATDESCRIPTOR pixelFormatInfo; const int pixelFormatCount = DescribePixelFormat(_p->device, 0, 0, 0); //DJV_DEBUG_PRINT("pixel format count = " << pixelFormatCount); DJV_LOG(context->debugLog(), "djvWglContext", QString("Pixel format count: %1").arg(pixelFormatCount)); for (int i = 1; i < pixelFormatCount; ++i) { DescribePixelFormat( _p->device, i, sizeof(PIXELFORMATDESCRIPTOR), &pixelFormatInfo); //DJV_DEBUG_PRINT(" id " << i << ": " << // ((PFD_SUPPORT_OPENGL & pixelFormatInfo.dwFlags) ? "gl " : "") << // ((PFD_GENERIC_FORMAT & pixelFormatInfo.dwFlags) ? "" : "accel ") << // ((PFD_TYPE_RGBA == pixelFormatInfo.iPixelType) ? "rgba " : "") << // "depth = " << pixelFormatInfo.cColorBits << "/" << // pixelFormatInfo.cRedBits << "/" << // pixelFormatInfo.cGreenBits << "/" << // pixelFormatInfo.cBlueBits << "/" << // pixelFormatInfo.cAlphaBits << " "); QStringList tmp; if (PFD_SUPPORT_OPENGL & pixelFormatInfo.dwFlags) tmp += "gl"; if (! (PFD_GENERIC_FORMAT & pixelFormatInfo.dwFlags)) tmp += "accel"; if (PFD_TYPE_RGBA == pixelFormatInfo.iPixelType) tmp += "rgba"; DJV_LOG(context->debugLog(), "djvWglContext", QString("Pixel format %1: %2 %3/%4/%5/%6/%7"). arg(i). arg(tmp.join(" ")). arg(pixelFormatInfo.cColorBits). arg(pixelFormatInfo.cRedBits). arg(pixelFormatInfo.cGreenBits). arg(pixelFormatInfo.cBlueBits). arg(pixelFormatInfo.cAlphaBits)); } PIXELFORMATDESCRIPTOR pixelFormat = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0 }; int pixelFormatId = ChoosePixelFormat(_p->device, &pixelFormat); //DJV_DEBUG_PRINT("pixel format = " << pixelFormatId); DJV_LOG(context->debugLog(), "djvWglContext", QString("Chosen pixel format: %1").arg(pixelFormatId)); if (! pixelFormatId) { throw djvError( "djvWglContext", errorLabels()[ERROR_GET_PIXEL_FORMAT].arg(int(GetLastError()))); } if (! SetPixelFormat(_p->device, pixelFormatId, &pixelFormat)) { throw djvError( "djvWglContext", errorLabels()[ERROR_SET_PIXEL_FORMAT].arg(int(GetLastError()))); } // Create OpengGL context. DJV_LOG(context->debugLog(), "djvWglContext", "Creating OpenGL context..."); _p->context = wglCreateContext(_p->device); if (! _p->context) { throw djvError( "djvWglContext", errorLabels()[ERROR_CREATE_CONTEXT].arg(int(GetLastError()))); } if (! wglMakeCurrent(_p->device, _p->context)) { throw djvError( "djvWglContext", errorLabels()[ERROR_BIND_CONTEXT].arg(int(GetLastError()))); } // Initialize GLEW. DJV_LOG(context->debugLog(), "djvWglContext", "Initializing GLEW..."); GLenum err = glewInit(); if (err != GLEW_OK) { throw djvError( "djvWglContext", errorLabels()[ERROR_INIT_GLEW].arg((char *)glewGetErrorString(err))); } setVendor(QString((const char *)glGetString(GL_VENDOR))); setRenderer(QString((const char *)glGetString(GL_RENDERER))); setVersion(QString((const char *)glGetString(GL_VERSION))); //DJV_DEBUG_PRINT("OpenGL vendor string = " << vendor()); //DJV_DEBUG_PRINT("OpenGL renderer string = " << renderer()); //DJV_DEBUG_PRINT("OpenGL version string = " << version()); //DJV_DEBUG_PRINT("OpenGL extensions = " << // (const char *)glGetString(GL_EXTENSIONS)); //DJV_DEBUG_PRINT("glu version = " << // (const char *)gluGetString(GLU_VERSION)); //DJV_DEBUG_PRINT("glu extensions = " << // (const char *)gluGetString(GLU_EXTENSIONS)); DJV_LOG(context->debugLog(), "djvWglContext", QString("GL vendor: \"%1\"").arg(vendor())); DJV_LOG(context->debugLog(), "djvWglContext", QString("GL renderer: \"%1\"").arg(renderer())); DJV_LOG(context->debugLog(), "djvWglContext", QString("GL version: \"%1\"").arg(version())); # endif // DJV_WINDOWS }