Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Black for Formatting #94

Closed
wants to merge 2 commits into from
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
7 changes: 4 additions & 3 deletions .github/workflows/style-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ on:

jobs:
style-check:

runs-on: [ self-hosted ]
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
Expand All @@ -15,4 +14,6 @@ jobs:
clean: true

- name: Check style
run: ${{github.workspace}}/tools/checkstyle.py $(git log --format=%P -1 | awk '{print $1 ".." $2}')
run: |
pip3 install black
black --check --diff picamera2
14 changes: 9 additions & 5 deletions picamera2/converters.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import numpy as np


YUV2RGB_JPEG = np.array([[1.0, 1.0, 1.0 ], [0.0, -0.344, 1.772], [1.402, -0.714, 0.0]])
YUV2RGB_SMPTE170M = np.array([[1.164, 1.164, 1.164], [0.0, -0.392, 2.017], [1.596, -0.813, 0.0]])
YUV2RGB_REC709 = np.array([[1.164, 1.164, 1.164], [0.0, -0.213, 2.112], [1.793, -0.533, 0.0]])
YUV2RGB_JPEG = np.array([[1.0, 1.0, 1.0], [0.0, -0.344, 1.772], [1.402, -0.714, 0.0]])
YUV2RGB_SMPTE170M = np.array(
[[1.164, 1.164, 1.164], [0.0, -0.392, 2.017], [1.596, -0.813, 0.0]]
)
YUV2RGB_REC709 = np.array(
[[1.164, 1.164, 1.164], [0.0, -0.213, 2.112], [1.793, -0.533, 0.0]]
)

Copy link
Collaborator

@naushir naushir May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer the original formatting. Or possibly all 3 matrices to look something like:

YUV2RGB_REC709 = np.array(
    [ [1.164,  1.164, 1.164],
      [0.0,   -0.213, 2.112],
      [1.793, -0.533, 0.0] ]
)


def YUV420_to_RGB(YUV_in, size, matrix=YUV2RGB_JPEG, rb_swap=True, final_width=0):
Expand All @@ -19,8 +23,8 @@ def YUV420_to_RGB(YUV_in, size, matrix=YUV2RGB_JPEG, rb_swap=True, final_width=0

YUV = np.empty((h2, w2, 3), dtype=int)
YUV[:, :, 0] = YUV_in[:n].reshape(h, w)[0::2, 0::2]
YUV[:, :, 1] = YUV_in[n:n + n4].reshape(h2, w2) - 128.0
YUV[:, :, 2] = YUV_in[n + n4:n + n2].reshape(h2, w2) - 128.0
YUV[:, :, 1] = YUV_in[n : n + n4].reshape(h2, w2) - 128.0
YUV[:, :, 2] = YUV_in[n + n4 : n + n2].reshape(h2, w2) - 128.0

if rb_swap:
matrix = matrix[:, [2, 1, 0]]
Expand Down
2 changes: 1 addition & 1 deletion picamera2/encoders/encoder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from v4l2 import *
from ..outputs import Output

class Encoder:

class Encoder:
def __init__(self):
self._width = 0
self._height = 0
Expand Down
6 changes: 4 additions & 2 deletions picamera2/encoders/jpeg_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@


class JpegEncoder(MultiEncoder):
def __init__(self, num_threads=4, q=85, colour_space='RGBX'):
def __init__(self, num_threads=4, q=85, colour_space="RGBX"):
super().__init__(num_threads=num_threads)
self.q = q
self.colour_space = colour_space

def encode_func(self, request, name):
array = request.make_array(name)
return simplejpeg.encode_jpeg(array, quality=self.q, colorspace=self.colour_space)
return simplejpeg.encode_jpeg(
array, quality=self.q, colorspace=self.colour_space
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how I feel about the formatting here and in all the other places where the function arguments are put on the next line. The original reads easier to me.

1 change: 1 addition & 0 deletions picamera2/encoders/multi_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MultiEncoder(Encoder):
num_threads - the number of parallel threads to use. Probably match this to the
number of cores available for best performance.
"""

def __init__(self, num_threads=4):
super().__init__()
self.threads = ThreadPoolExecutor(num_threads)
Expand Down
22 changes: 17 additions & 5 deletions picamera2/encoders/v4l2_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ def __init__(self, bitrate, pixformat):

def _start(self):
super()._start()
self.vd = open('/dev/video11', 'rb+', buffering=0)
self.vd = open("/dev/video11", "rb+", buffering=0)

self.buf_available = queue.Queue()
self.buf_frame = queue.Queue()

self.thread = threading.Thread(target=self.thread_poll, args=(self.buf_available,))
self.thread = threading.Thread(
target=self.thread_poll, args=(self.buf_available,)
)
self.thread.setDaemon(True)
self.thread.start()

Expand Down Expand Up @@ -101,8 +103,16 @@ def _start(self):
buffer.length = 1
buffer.m.planes = planes
ret = fcntl.ioctl(self.vd, VIDIOC_QUERYBUF, buffer)
self.bufs[i] = (mmap.mmap(self.vd.fileno(), buffer.m.planes[0].length, mmap.PROT_READ | mmap.PROT_WRITE, mmap.MAP_SHARED,
offset=buffer.m.planes[0].m.mem_offset), buffer.m.planes[0].length)
self.bufs[i] = (
mmap.mmap(
self.vd.fileno(),
buffer.m.planes[0].length,
mmap.PROT_READ | mmap.PROT_WRITE,
mmap.MAP_SHARED,
offset=buffer.m.planes[0].m.mem_offset,
),
buffer.m.planes[0].length,
)
ret = fcntl.ioctl(self.vd, VIDIOC_QBUF, buffer)

typev = v4l2_buf_type(V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
Expand Down Expand Up @@ -158,7 +168,9 @@ def thread_poll(self, buf_available):
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
buf.memory = V4L2_MEMORY_MMAP
buf.length = 1
ctypes.memset(planes, 0, ctypes.sizeof(v4l2_plane) * VIDEO_MAX_PLANES)
ctypes.memset(
planes, 0, ctypes.sizeof(v4l2_plane) * VIDEO_MAX_PLANES
)
buf.m.planes = planes
ret = fcntl.ioctl(self.vd, VIDIOC_DQBUF, buf)
keyframe = (buf.flags & V4L2_BUF_FLAG_KEYFRAME) != 0
Expand Down
Loading