|
7 | 7 | import logging
|
8 | 8 | import sys
|
9 | 9 | import os
|
| 10 | +import platform |
10 | 11 | import glob
|
11 | 12 | import numpy as np
|
12 | 13 | from numpy import pi
|
13 | 14 |
|
| 15 | +IsWin = platform.system() == 'Windows' |
| 16 | +if not IsWin: |
| 17 | + import pyvips |
| 18 | + |
14 | 19 | from kubi import __version__
|
15 | 20 |
|
16 | 21 | __author__ = "Keim, Stefan"
|
|
28 | 33 |
|
29 | 34 |
|
30 | 35 | def kubi(args):
|
31 |
| - os.environ['PATH'] = 'C:/Program Files/vips-dev-8.10/bin' + ';' + os.environ['PATH'] |
32 | 36 |
|
33 |
| - if args.vips: |
34 |
| - os.environ['PATH'] = args.vips + ';' + os.environ['PATH'] |
35 |
| - |
36 |
| - import pyvips |
| 37 | + if IsWin: |
| 38 | + if args.vips: |
| 39 | + os.environ['PATH'] = args.vips + ';' + os.environ['PATH'] |
| 40 | + import pyvips |
37 | 41 |
|
38 | 42 | src_names = None
|
| 43 | + if args.src: |
| 44 | + src_names = glob.glob(args.src,recursive=True) |
| 45 | + src_count = len(src_names) |
| 46 | + src_multi = src_count > 1 |
| 47 | + |
| 48 | + if src_count == 0: |
| 49 | + print(f'{args.src}: No such file or directory') |
| 50 | + return |
| 51 | + |
39 | 52 | if args.ii == None:
|
40 | 53 | _logger.info('Generating index')
|
41 | 54 |
|
42 | 55 | size = -1
|
43 | 56 | if args.size:
|
44 | 57 | size = args.size
|
45 |
| - elif args.src: |
46 |
| - src_names = glob.glob(args.src,recursive=True) |
47 |
| - src_count = len(src_names) |
48 |
| - src_multi = src_count > 1 |
49 |
| - |
50 |
| - if src_count == 0: |
51 |
| - print(f'{args.src}: No such file or directory') |
52 |
| - return |
| 58 | + elif src_names is not None: |
53 | 59 | for name in src_names:
|
54 | 60 | image = pyvips.Image.new_from_file(name)
|
55 | 61 | size = max(size, int(image.width / 4))
|
@@ -100,7 +106,8 @@ def kubi(args):
|
100 | 106 | index = None
|
101 | 107 | idxA = idx
|
102 | 108 | else:
|
103 |
| - index = pyvips.Image.arrayjoin(idx, across=6 if args.layout == "row" else 1) |
| 109 | + across = 6 if args.layout == "row" else 1 |
| 110 | + index = pyvips.Image.arrayjoin(idx, across = across) |
104 | 111 | else:
|
105 | 112 | s0 = 0
|
106 | 113 | s1 = size
|
@@ -155,11 +162,17 @@ def kubi(args):
|
155 | 162 |
|
156 | 163 | idx = None
|
157 | 164 |
|
158 |
| - if args.src: |
159 |
| - if src_names is None: |
160 |
| - src_names = glob.glob(args.src, recursive=True) |
161 |
| - src_count = len(src_names) |
162 |
| - src_multi = src_count > 1 |
| 165 | + |
| 166 | + if src_names is not None: |
| 167 | + |
| 168 | +# # # # has no effect on performance |
| 169 | +# |
| 170 | +# if src_multi: |
| 171 | +# if index is None: |
| 172 | +# for f in range(6): |
| 173 | +# idxA[f] = idxA[f].copy_memory() |
| 174 | +# else: |
| 175 | +# index = index.copy_memory() |
163 | 176 |
|
164 | 177 | dst_suffix = '_'+ args.transform
|
165 | 178 | dst_folder = dst_name = dst_ext = None
|
@@ -196,7 +209,6 @@ def kubi(args):
|
196 | 209 | dst = f'{dst_folder}/{dst_name}{dst_suffix}'
|
197 | 210 |
|
198 | 211 | fac = img.width/4
|
199 |
| - |
200 | 212 |
|
201 | 213 | if index is None:
|
202 | 214 | for f in range(6):
|
@@ -266,10 +278,12 @@ def parse_args(args):
|
266 | 278 | """)
|
267 | 279 | parser.add_argument('-f', '--facenames', metavar="<str>", nargs=6 ,help='suffixes for +X, -X, +Y, -Y, +Z, -Z (e.g. -n r l u d f b)')
|
268 | 280 | parser.add_argument('-co', dest='co', metavar='<NAME=VALUE>*', action='append', help='create options (more info in the epilog)')
|
269 |
| - parser.add_argument('--vips', help='path to the VIPS bin directory (usefull if VIPS is not added to PATH; e.g. on Windows)') |
270 | 281 | parser.add_argument('--io', dest='io', help='index file output', metavar='dstindex')
|
271 | 282 | parser.add_argument('--ii', dest='ii', help='index file input', metavar='srcindex')
|
272 | 283 |
|
| 284 | + if IsWin: |
| 285 | + parser.add_argument('--vips', help='path to the VIPS bin directory (usefull if VIPS is not added to PATH)') |
| 286 | + |
273 | 287 | args = parser.parse_args(args)
|
274 | 288 |
|
275 | 289 | if args.src is None:
|
|
0 commit comments