From 56f131550fc5d4d8d97d511dae5c654b16b6461f Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Thu, 29 Aug 2024 13:49:00 +0300 Subject: [PATCH] Create pixutils.formats module --- pixutils/__init__.py | 4 ---- pixutils/conv/conv.py | 3 +-- pixutils/conv/qt.py | 4 ++-- pixutils/conv/raw.py | 2 +- pixutils/conv/rgb.py | 2 +- pixutils/conv/yuv.py | 3 ++- pixutils/formats/__init__.py | 3 +++ pixutils/{ => formats}/fourcc_str.py | 0 pixutils/{ => formats}/metaformats.py | 0 pixutils/{ => formats}/pixelformats.py | 0 tests/test_conv.py | 3 +-- tests/test_dummy.py | 12 ++++++------ tests/view.py | 3 +-- 13 files changed, 18 insertions(+), 21 deletions(-) create mode 100644 pixutils/formats/__init__.py rename pixutils/{ => formats}/fourcc_str.py (100%) rename pixutils/{ => formats}/metaformats.py (100%) rename pixutils/{ => formats}/pixelformats.py (100%) diff --git a/pixutils/__init__.py b/pixutils/__init__.py index 916f2e8..e69de29 100644 --- a/pixutils/__init__.py +++ b/pixutils/__init__.py @@ -1,4 +0,0 @@ -from __future__ import annotations - -from .pixelformats import * -from .metaformats import * diff --git a/pixutils/conv/conv.py b/pixutils/conv/conv.py index e1d2eb2..d3a02c5 100644 --- a/pixutils/conv/conv.py +++ b/pixutils/conv/conv.py @@ -6,8 +6,7 @@ import numpy as np import numpy.typing as npt -from pixutils import PixelFormat -from pixutils.pixelformats import PixelColorEncoding +from pixutils.formats import PixelFormat, PixelColorEncoding from .yuv import yuv_to_bgr888 from .rgb import rgb_to_bgr888 diff --git a/pixutils/conv/qt.py b/pixutils/conv/qt.py index a85174a..b83d4e5 100644 --- a/pixutils/conv/qt.py +++ b/pixutils/conv/qt.py @@ -7,8 +7,8 @@ from __future__ import annotations from PyQt6 import QtGui -from pixutils import PixelFormat -from .conv import PixelFormats, buffer_to_bgr888 +from pixutils.formats import PixelFormat, PixelFormats +from .conv import buffer_to_bgr888 def bgr888_to_pix(rgb): # QImage doesn't seem to like a numpy view diff --git a/pixutils/conv/raw.py b/pixutils/conv/raw.py index c39a415..0e9816f 100644 --- a/pixutils/conv/raw.py +++ b/pixutils/conv/raw.py @@ -5,7 +5,7 @@ import numpy as np import numpy.typing as npt -from pixutils import PixelFormat +from pixutils.formats import PixelFormat __all__ = [ 'raw_to_bgr888' ] diff --git a/pixutils/conv/rgb.py b/pixutils/conv/rgb.py index 90e09d6..4b924a4 100644 --- a/pixutils/conv/rgb.py +++ b/pixutils/conv/rgb.py @@ -4,7 +4,7 @@ import numpy as np import numpy.typing as npt -from pixutils import PixelFormat, PixelFormats +from pixutils.formats import PixelFormat, PixelFormats def rgb_to_bgr888(fmt: PixelFormat, w, h, data: npt.NDArray[np.uint8]): if fmt == PixelFormats.RGB888: diff --git a/pixutils/conv/yuv.py b/pixutils/conv/yuv.py index 7d1305e..b491174 100644 --- a/pixutils/conv/yuv.py +++ b/pixutils/conv/yuv.py @@ -3,7 +3,8 @@ import numpy as np import numpy.typing as npt -from pixutils import PixelFormats + +from pixutils.formats import PixelFormats YCBCR_VALUES = { 'bt601': { diff --git a/pixutils/formats/__init__.py b/pixutils/formats/__init__.py new file mode 100644 index 0000000..cd6b466 --- /dev/null +++ b/pixutils/formats/__init__.py @@ -0,0 +1,3 @@ +from .pixelformats import * +from .metaformats import * +from .fourcc_str import * diff --git a/pixutils/fourcc_str.py b/pixutils/formats/fourcc_str.py similarity index 100% rename from pixutils/fourcc_str.py rename to pixutils/formats/fourcc_str.py diff --git a/pixutils/metaformats.py b/pixutils/formats/metaformats.py similarity index 100% rename from pixutils/metaformats.py rename to pixutils/formats/metaformats.py diff --git a/pixutils/pixelformats.py b/pixutils/formats/pixelformats.py similarity index 100% rename from pixutils/pixelformats.py rename to pixutils/formats/pixelformats.py diff --git a/tests/test_conv.py b/tests/test_conv.py index eb75896..be0bbb4 100755 --- a/tests/test_conv.py +++ b/tests/test_conv.py @@ -5,9 +5,8 @@ import unittest import numpy as np -from pixutils import PixelFormats +from pixutils.formats import PixelFormats, str_to_fourcc from pixutils.conv import buffer_to_bgr888 -from pixutils.fourcc_str import str_to_fourcc TEST_PATH = os.path.dirname(os.path.abspath(__file__)) diff --git a/tests/test_dummy.py b/tests/test_dummy.py index 395566f..066e7da 100755 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -2,20 +2,20 @@ import unittest import pixutils -import pixutils.fourcc_str +import pixutils.formats class TestDummy(unittest.TestCase): def test_dummy(self): - self.assertEqual(pixutils.PixelFormats.RGB888.name, 'RGB888') + self.assertEqual(pixutils.formats.PixelFormats.RGB888.name, 'RGB888') class TestFourcc(unittest.TestCase): def test_fourcc(self): - self.assertEqual(pixutils.fourcc_str.str_to_fourcc('XR24'), 0x34325258) - self.assertEqual(pixutils.fourcc_str.fourcc_to_str(0x34325258), 'XR24') + self.assertEqual(pixutils.formats.fourcc_str.str_to_fourcc('XR24'), 0x34325258) + self.assertEqual(pixutils.formats.fourcc_str.fourcc_to_str(0x34325258), 'XR24') with self.assertRaises(ValueError): - pixutils.fourcc_str.str_to_fourcc('ABCDE') + pixutils.formats.fourcc_str.str_to_fourcc('ABCDE') with self.assertRaises(ValueError): - pixutils.fourcc_str.str_to_fourcc('ABC') + pixutils.formats.fourcc_str.str_to_fourcc('ABC') if __name__ == '__main__': unittest.main() diff --git a/tests/view.py b/tests/view.py index f68c381..fa00751 100755 --- a/tests/view.py +++ b/tests/view.py @@ -11,10 +11,9 @@ from PyQt6.QtCore import Qt from PyQt6 import QtWidgets -from pixutils import PixelFormats +from pixutils.formats import PixelFormats, str_to_fourcc from pixutils.conv import buffer_to_bgr888 from pixutils.conv.qt import bgr888_to_pix -from pixutils.fourcc_str import str_to_fourcc TEST_PATH = os.path.dirname(os.path.abspath(__file__))