pyanime4k 3.0.0__cp38-cp38-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pyanime4k/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .image_io import *
2
+ from .info import *
3
+ from .processor import *
4
+ from .upscale import *
pyanime4k/image_io.py ADDED
@@ -0,0 +1,9 @@
1
+ import numpy
2
+
3
+ from . import pyac
4
+
5
+ def imread(filename: str) -> numpy.ndarray:
6
+ return pyac.core.imread(filename, pyac.core.IMREAD_UNCHANGED)
7
+
8
+ def imwrite(filename: str, image: numpy.ndarray) -> bool:
9
+ return pyac.core.imwrite(filename, image)
pyanime4k/info.py ADDED
@@ -0,0 +1,13 @@
1
+ from . import pyac
2
+
3
+ def print_model_list():
4
+ for name, description in zip(pyac.specs.ModelNameList, pyac.specs.ModelDescriptionList):
5
+ print(f"{name}\t\t{description}")
6
+
7
+ def print_processor_list():
8
+ for name, description in zip(pyac.specs.ProcessorNameList, pyac.specs.ProcessorDescriptionList):
9
+ print(f"{name}\t\t{description}")
10
+
11
+ def print_device_list():
12
+ for info in pyac.core.Processor.InfoList:
13
+ print(info, end="")
pyanime4k/processor.py ADDED
@@ -0,0 +1,27 @@
1
+ import numpy
2
+
3
+ from . import pyac
4
+
5
+ class Processor:
6
+ def __init__(self, processor_name: str = "cpu", device_id:int = 0, model_name: str = "acnet-hdn0"):
7
+ self.processor_name = processor_name.lower()
8
+ if self.processor_name == "opencl" :
9
+ processor_type = pyac.core.Processor.OpenCL
10
+ if self.processor_name == "cuda":
11
+ processor_type = pyac.core.Processor.CUDA
12
+ else:
13
+ self.processor_name = "cpu"
14
+ processor_type = pyac.core.Processor.CPU
15
+
16
+ self.processor = pyac.core.Processor(processor_type = processor_type, device = device_id, model = model_name)
17
+ if not self.processor.ok():
18
+ raise RuntimeError(self.processor.error())
19
+
20
+ def __call__(self, src: numpy.ndarray, factor: float = 2.0) -> numpy.ndarray:
21
+ dst = self.processor.process(src = src, factor = factor)
22
+ if not self.processor.ok():
23
+ raise RuntimeError(self.processor.error())
24
+ return dst
25
+
26
+ def __str__(self):
27
+ return f"{self.processor_nam}: {self.processor.name()}"
@@ -0,0 +1 @@
1
+ from .pyac import *
Binary file
pyanime4k/upscale.py ADDED
@@ -0,0 +1,29 @@
1
+ from itertools import zip_longest, islice
2
+ from pathlib import Path
3
+
4
+ from .image_io import imread, imwrite
5
+ from .processor import Processor
6
+
7
+ def upscale_images(
8
+ inputs: list,
9
+ outputs: list = [],
10
+ output_suffix: str = "_output",
11
+ factor: float = 2.0,
12
+ processor_name: str = "cpu",
13
+ device_id:int = 0,
14
+ model_name: str = "acnet-hdn0"
15
+ ):
16
+ if isinstance(inputs, str):
17
+ inputs = [inputs]
18
+
19
+ processor = Processor(processor_name, device_id, model_name)
20
+
21
+ for input, output in islice(zip_longest(inputs, outputs, fillvalue=None), len(inputs)):
22
+ if output is None:
23
+ input_path = Path(input)
24
+ output = str(input_path.with_stem(input_path.stem + output_suffix))
25
+
26
+ src = imread(input)
27
+ dst = processor(src, factor)
28
+ if not imwrite(output, dst):
29
+ raise IOError(f"Failed to save image to {output}")
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 TianZer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyanime4k
3
+ Version: 3.0.0
4
+ License: MIT
5
+ Requires-Python: >=3.8
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+
9
+ # PyAnime4K
10
+
11
+ PyAnime4K is a high performance anime image upscaler based on [Anime4KCPP](https://github.com/TianZerL/Anime4KCPP).
12
+
13
+ # Install
14
+ PyAnime4K can be installed easily through pip.
15
+ ```shell
16
+ pip install pyanime4k
17
+ ```
18
+
19
+ You can also build the wheel by yourself.
20
+ ```shell
21
+ # sudo apt install ocl-icd-opencl-dev cmake build-essential
22
+ get clone https://github.com/TianZerL/pyanime4k.git
23
+ cd pyanime4k
24
+ python setup.py bdist_wheel
25
+ ```
26
+
27
+ # Usages
28
+ ## Printing Info
29
+ ```python
30
+ import pyanime4k
31
+
32
+ # Print supported model
33
+ pyanime4k.print_model_list()
34
+
35
+ # Print supported processor
36
+ pyanime4k.print_processor_list()
37
+
38
+ # Print supported devices for image processing
39
+ pyanime4k.print_device_list()
40
+ ```
41
+ ## Upscaling Images
42
+ ```python
43
+ import pyanime4k
44
+
45
+ # with OpenCL acceleration, if possible
46
+ processor_name = "opencl"
47
+
48
+ # upscale a single image
49
+ pyanime4k.upscale_images("image1.png", processor_name = processor_name)
50
+
51
+ # upscale a list of images
52
+ pyanime4k.upscale_images(["image1.png", "image2.png"], processor_name = processor_name)
53
+ ```
54
+ ## Manual Upscaling
55
+ ```python
56
+ import pyanime4k
57
+
58
+ # Create a processor
59
+ processor = pyanime4k.Processor(
60
+ processor_name="cpu",
61
+ device_id=0,
62
+ model_name="acnet-hdn0"
63
+ )
64
+ # Print processor info
65
+ print(processor)
66
+ # Read an image
67
+ src = pyanime4k.imread("image1.png")
68
+ # Process it
69
+ dst = processor(src=src, factor=2.0)
70
+ # Write to disk
71
+ pyanime4k.imwrite("image1_outout.png", dst)
72
+ ```
73
+ ## OpenCV
74
+ ``` Python
75
+ import cv2, pyanime4k
76
+
77
+ img = cv2.imread("image.png")
78
+
79
+ processor = pyanime4k.Processor(
80
+ processor_name="cpu",
81
+ device_id=0,
82
+ model_name="acnet-hdn0"
83
+ )
84
+
85
+ # opencv load image as BGR, but we need an RGB image
86
+ src = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
87
+
88
+ dst = processor(src)
89
+
90
+ img = cv2.cvtColor(dst, cv2.COLOR_RGB2BGR)
91
+
92
+ cv2.imshow("pyanime4k", img)
93
+ cv2.waitKey()
94
+ ```
95
+ ## Pillow
96
+ ```python
97
+ from PIL import Image
98
+ import numpy, pyanime4k
99
+
100
+ img = Image.open("D:/temp/p1.png")
101
+
102
+ processor = pyanime4k.Processor(
103
+ processor_name="cpu",
104
+ device_id=0,
105
+ model_name="acnet-hdn0"
106
+ )
107
+
108
+ # We need a numpy array
109
+ src = numpy.asarray(img)
110
+ dst = processor(src)
111
+ img = Image.fromarray(dst)
112
+
113
+ img.show()
114
+ ```
@@ -0,0 +1,12 @@
1
+ pyanime4k/__init__.py,sha256=a0P3gyxYbvjRm8m3suGuv_VK4wXoMeaqIEcOp7jI3jg,96
2
+ pyanime4k/image_io.py,sha256=SRADSi197gcWcMPPljh5-tV-qBXcl-drRmWua2ff1Vg,258
3
+ pyanime4k/info.py,sha256=nkNPTJM99bnWY-pG7UsfD2Ce_efB3FN-HFxfC6-MM9k,464
4
+ pyanime4k/processor.py,sha256=xLASpJaRnCGA96F0N4uxSmDqLn3CDkqJzUc72tLCMPc,1099
5
+ pyanime4k/upscale.py,sha256=c8tYsFHaH-ujdCXc0WRLdeZZT643TzCIqYvV7b_XFnc,913
6
+ pyanime4k/pyac/__init__.py,sha256=zPAeBR1mdz2q_I3Ruk5uaIptB7DjT8P9G20oGEKFJ1c,21
7
+ pyanime4k/pyac/pyac.cp38-win_amd64.pyd,sha256=CawgQb_eYa2k6GkYHjHaiWWoVqw-jrwCBpkbHok7yqA,1595392
8
+ pyanime4k-3.0.0.dist-info/LICENSE,sha256=Y1LqP77JBqrXWO4jJ_2bg6N-hHoU_JGgxQnYqxw1f3U,1085
9
+ pyanime4k-3.0.0.dist-info/METADATA,sha256=9M6u16ID4LGZ2ZFyfZ2VSERss3tfEbgBUX8qD1ZzQJk,2380
10
+ pyanime4k-3.0.0.dist-info/WHEEL,sha256=fE_NFyeaM8vcDHEZHjUwuIwCfAX272sKvaz9mWJ3HC4,94
11
+ pyanime4k-3.0.0.dist-info/top_level.txt,sha256=fPnXpjwQ6pB0I-OoT611DbqcY50uFsaMw4BdYnAmVq0,10
12
+ pyanime4k-3.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: skbuild 0.18.1
3
+ Root-Is-Purelib: false
4
+ Tag: cp38-cp38-win_amd64
5
+
@@ -0,0 +1 @@
1
+ pyanime4k