We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f62f4a4 commit daea622Copy full SHA for daea622
8 files changed
Makefile
@@ -18,4 +18,3 @@ ruff:
18
19
flake8:
20
flake8 ./src/python/
21
-
src/python/app/command/parser.py
@@ -34,8 +34,7 @@ def get_parser() -> ArgumentParser:
34
subparser = parser.add_subparsers(required=True,
35
help='Command to be performed on an image')
36
37
- operation_class: type[Operation]
38
- for operation_class in [Rotate90Operation, IdentityOperation, FlipOperation, BGR2RGBOperation, RollOperation, GrayscaleOperation, HistogramEqualizationOperation]:
+ for operation_class in available_commands():
39
operation = operation_class()
40
41
operation_parser = subparser.add_parser(name=operation_class.name(),
@@ -46,6 +45,7 @@ def get_parser() -> ArgumentParser:
46
45
47
return parser
48
+
49
def prepare_command(command: Operation) -> Callable[[Namespace], int]:
50
51
def wrapper(args: Namespace) -> int:
@@ -61,3 +61,15 @@ def wrapper(args: Namespace) -> int:
61
return 0
62
63
return wrapper
64
65
66
+def available_commands():
67
+ return [
68
+ Rotate90Operation,
69
+ IdentityOperation,
70
+ FlipOperation,
71
+ BGR2RGBOperation,
72
+ RollOperation,
73
+ GrayscaleOperation,
74
+ HistogramEqualizationOperation,
75
+ ]
src/python/app/imcli.py
@@ -1,9 +1,12 @@
1
+"""Main entrypoint for imcli program"""
2
3
from app.command.parser import get_parser
4
5
6
def main() -> None:
7
args = get_parser().parse_args()
8
return args.func(args)
9
10
11
if __name__ == '__main__':
12
main()
src/python/app/io/bmp.py
@@ -46,7 +46,8 @@ def read_format(self, file: BinaryIO) -> Image:
assert panes == 1
assert bits_per_pixel in (1, 4, 8, 16, 24, 32)
- compression_method, raw_bitmap_data_size, horizontal_resolution, vertical_resolution, num_colors, num_important_colors = \
+ compression_method, raw_bitmap_data_size, horizontal_resolution, vertical_resolution, \
+ num_colors, num_important_colors = \
struct.unpack('IIiiII', dib_header_no_size[12:])
52
assert compression_method == 0
53
assert raw_bitmap_data_size != 0
@@ -61,7 +62,8 @@ def read_format(self, file: BinaryIO) -> Image:
num_colors_end = bits_per_pixel // 8
return Image(data=np.flip(
np.flip(
- np.frombuffer(bytes(image_bytes), dtype=np.uint8).reshape(image_height, image_width, num_colors_end)[:, :, ::-1],
+ np.frombuffer(bytes(image_bytes),
+ dtype=np.uint8).reshape(image_height, image_width, num_colors_end)[:, :, ::-1],
axis=0
),
axis=1)
src/python/app/io/format_factory.py
@@ -1,5 +1,4 @@
import enum
-from typing import Self
from app.error.unknown_format_exception import UnknownFormatException
from app.io.bmp import BMPReader, BMPWriter
@@ -11,7 +10,7 @@ class KnownFormat(enum.Enum):
BMP = 0
13
@classmethod
14
- def from_string(cls, data_format: str) -> Self:
+ def from_string(cls, data_format: str) -> 'KnownFormat':
15
match data_format:
16
case 'bmp':
17
return cls.BMP
@@ -24,7 +23,7 @@ def get_available_formats(cls) -> list[str]:
24
23
return [e.name.lower() for e in cls]
25
26
27
- def default(cls) -> Self:
+ def default(cls) -> 'KnownFormat':
28
return KnownFormat.BMP
29
30
@@ -37,6 +36,7 @@ def get_reader_from_format(data_format: KnownFormat) -> FormatReader:
case _:
assert False, "unreachable"
def get_writer_from_format(data_format: KnownFormat) -> FormatWriter:
42
src/python/app/io/format_reader.py
@@ -1,8 +1,6 @@
from abc import abstractmethod, ABC
from typing import BinaryIO
-import numpy as np
from app.image.image import Image
src/python/app/operation/histogram_equalization.py
@@ -37,4 +37,4 @@ def equalize_chanel(self, image: np.ndarray) -> np.ndarray:
cdf = (256 - 1) * cdf / cdf[-1]
image_equalized = np.interp(image.flatten(), bins[:-1], cdf)
- return image_equalized.reshape(image.shape)
+ return image_equalized.reshape(image.shape)
src/python/app/operation/operation.py
@@ -1,8 +1,5 @@
from abc import ABC, abstractmethod
from argparse import Namespace, ArgumentParser
-from typing import final
0 commit comments