Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

### Added

* Add `Preview.QTGL_WL`, a GPU-accelerated Qt preview that runs as a native Wayland client (as well as X11), avoiding XWayland. See `examples/preview_qtgl_wayland.py`.
* Add `Preview.QTGL_WL_DIRECT`, a native-Wayland Qt preview that renders directly to the window surface (QOpenGLWindow), avoiding the FBO blit of `Preview.QTGL_WL` for higher throughput. See `examples/preview_qtgl_wayland_direct.py`.

### Changed

## 0.3.36 Beta Release 35
Expand Down
26 changes: 26 additions & 0 deletions examples/preview_qtgl_wayland.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/python3

# QtGlPreviewWayland is a GPU-accelerated Qt preview (like QtGlPreview) that
# also works as a *native* Wayland client, not only through XWayland.
#
# QtGlPreview renders raw EGL onto the widget's native window, which only works
# on X11; under a Wayland compositor it falls back to XWayland. QtGlPreviewWayland
# instead renders through Qt's own OpenGL context (QOpenGLWidget), so it needs no
# X server and composites natively. The zero-copy dmabuf import is unchanged.
#
# Select it with Preview.QTGL_WL. Prefer it when running under Wayland (e.g.
# labwc) and you want to avoid XWayland; on X11 the regular Preview.QTGL is the
# usual choice.

import time

from picamera2 import Picamera2, Preview

picam2 = Picamera2()
picam2.start_preview(Preview.QTGL_WL)

preview_config = picam2.create_preview_configuration()
picam2.configure(preview_config)

picam2.start()
time.sleep(5)
24 changes: 24 additions & 0 deletions examples/preview_qtgl_wayland_direct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python3

# QtGlPreviewWaylandDirect is like QtGlPreviewWayland (a native-Wayland,
# GPU-accelerated Qt preview) but renders straight to the window surface using
# a QOpenGLWindow, avoiding the QOpenGLWidget FBO -> window blit. This is the
# fastest option, especially at high resolutions.
#
# Caveat: it uses a container/native window, which always stacks above sibling
# Qt widgets and can't be clipped by non-rectangular masks. For a viewfinder
# that fills its area this is fine (overlays are drawn inside the GL context);
# apps that float Qt widgets over the preview should use Preview.QTGL_WL.

import time

from picamera2 import Picamera2, Preview

picam2 = Picamera2()
picam2.start_preview(Preview.QTGL_WL_DIRECT)

preview_config = picam2.create_preview_configuration()
picam2.configure(preview_config)

picam2.start()
time.sleep(5)
5 changes: 4 additions & 1 deletion picamera2/picamera2.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
#!/usr/bin/python3
"""picamera2 main class"""

import atexit
import contextlib
import json
import logging
import os
import selectors
import sys
import tempfile
import threading
import time
from collections.abc import Callable
from enum import Enum
from functools import partial
from typing import Any, Generic, Literal, Optional, TypedDict, TypeVar, Union, cast, overload

import libcamera
import numpy as np
from libcamera import controls
from numpy.typing import NDArray
from PIL import Image

import picamera2.formats as formats
import picamera2.platform as Platform
import picamera2.utils as utils
from picamera2.allocators import DmaAllocator
from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality
from picamera2.outputs import FileOutput, PyavOutput
from picamera2.previews import DrmPreview, NullPreview, QtGlPreview, QtPreview
from picamera2.previews import (DrmPreview, NullPreview, QtGlPreview, QtGlPreviewWayland,
QtGlPreviewWaylandDirect, QtPreview)

from .configuration import CameraConfiguration
from .controls import Controls
from .job import Job
from .request import CompletedRequest, Helpers
from .sensor_format import SensorFormat

Check failure on line 38 in picamera2/picamera2.py

View workflow job for this annotation

GitHub Actions / Lint and format check

ruff (I001)

picamera2/picamera2.py:4:1: I001 Import block is un-sorted or un-formatted help: Organize imports

STILL = libcamera.StreamRole.StillCapture
RAW = libcamera.StreamRole.Raw
Expand All @@ -52,6 +53,8 @@
DRM = DrmPreview
QT = QtPreview
QTGL = QtGlPreview
QTGL_WL = QtGlPreviewWayland
QTGL_WL_DIRECT = QtGlPreviewWaylandDirect


class GlobalCameraInfo(TypedDict):
Expand Down
2 changes: 1 addition & 1 deletion picamera2/previews/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .drm_preview import DrmPreview
from .null_preview import NullPreview
from .qt_previews import QtGlPreview, QtPreview
from .qt_previews import QtGlPreview, QtGlPreviewWayland, QtGlPreviewWaylandDirect, QtPreview
Loading
Loading