Skip to content

Commit 4a76f9a

Browse files
committed
move jpeg encoding to turbojpeg
1 parent 9c29492 commit 4a76f9a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

picamera2/encoders/jpeg_encoder.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""JPEG encoder functionality"""
22

3-
import simplejpeg
3+
import turbojpeg
44

55
from picamera2.encoders import Quality
66
from picamera2.encoders.multi_encoder import MultiEncoder
@@ -9,12 +9,16 @@
99
class JpegEncoder(MultiEncoder):
1010
"""Uses functionality from MultiEncoder"""
1111

12-
FORMAT_TABLE = {"XBGR8888": "RGBX",
13-
"XRGB8888": "BGRX",
14-
"BGR888": "RGB",
15-
"RGB888": "BGR"}
12+
FORMAT_TABLE = {"XBGR8888": turbojpeg.TJPF_RGBX,
13+
"XRGB8888": turbojpeg.TJPF_BGRX,
14+
"BGR888": turbojpeg.TJPF_RGB,
15+
"RGB888": turbojpeg.TJPF_BGR}
16+
COLOUR_SUBSAMPLING_TABLE = {"420": turbojpeg.TJSAMP_420,
17+
"422": turbojpeg.TJSAMP_422,
18+
"444": turbojpeg.TJSAMP_444}
1619

1720
def __init__(self, num_threads=4, q=None, colour_space=None, colour_subsampling='420'):
21+
self.jpeg = turbojpeg.TurboJPEG()
1822
"""Initialises Jpeg encoder
1923
2024
:param num_threads: Number of threads to use, defaults to 4
@@ -45,8 +49,8 @@ def encode_func(self, request, name):
4549
if self.colour_space is None:
4650
self.colour_space = self.FORMAT_TABLE[request.config[name]["format"]]
4751
array = request.make_array(name)
48-
return simplejpeg.encode_jpeg(array, quality=self.q, colorspace=self.colour_space,
49-
colorsubsampling=self.colour_subsampling)
52+
return self.jpeg.encode(array, quality=self.q, colorspace=self.colour_space,
53+
colorsubsampling=self.COLOUR_SUBSAMPLING_TABLE[self.colour_subsampling])
5054

5155
def _setup(self, quality):
5256
# If an explicit quality was specified, use it, otherwise try to preserve any q value

0 commit comments

Comments
 (0)