pieusb 0.3.0__tar.gz → 0.3.2__tar.gz

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.
@@ -1,5 +1,12 @@
1
- # Unreleased
1
+ # v0.3.1
2
2
 
3
+ - **Breaking:** `UpdateData.scanned_lines`/`total_lines` are replaced by a single
4
+ `progress` float, 0.0 -> 1.0 within the current `phase`. Line counts only ever
5
+ meant anything during SCANNING, which left every other phase reporting `None`
6
+ and each consumer writing the same division; a fraction is what a progress
7
+ indicator wants and it now applies to every phase. CALIBRATING reports the
8
+ shading read's fraction and WARMING_UP its progress through the START SCAN
9
+ retry budget; phases whose length the device does not announce report 0.0
3
10
  - **Breaking:** the `calibrate` option is replaced by `reuse_calibration`, with
4
11
  the opposite polarity and the same default behaviour (`calibrate=True` is
5
12
  `reuse_calibration=False`, still the default). The old name promised something
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pieusb
3
- Version: 0.3.0
3
+ Version: 0.3.2
4
4
  Summary: Interface and acquire images from the Reflecta (a.k.a PacificImage) line of film scanners.
5
5
  Project-URL: Homepage, https://github.com/davide-b/pieusb
6
6
  Project-URL: Issues, https://github.com/davide-b/pieusb/issues
@@ -64,16 +64,13 @@ pip install pieusb
64
64
  import numpy
65
65
  import pieusb
66
66
  from pieusb.scanner import Scanner
67
- from pieusb.types import ScanPhase
68
67
 
69
68
  for info in pieusb.get_devices():
70
69
  print(info.vendor, info.model)
71
70
 
72
71
  def on_update(data):
73
- if data.phase == ScanPhase.SCANNING:
74
- print(f"{data.scanned_lines}/{data.total_lines}")
75
- else:
76
- print(data.phase)
72
+ # progress runs 0.0 -> 1.0 within each phase, not across the scan
73
+ print(f"{data.phase}: {data.progress * 100:.1f}%")
77
74
 
78
75
  def on_complete(result):
79
76
  if result.error:
@@ -119,6 +116,14 @@ determines whether a pass pays for its own calibration, never whether the image
119
116
  gets corrected. Since the cache lives on the `Scanner`, a fresh one starts cold:
120
117
  a loop that opens a `Scanner` per frame is correct but calibrates every time.
121
118
 
119
+ ## Status of verification
120
+
121
+ ### Verified on hardware
122
+
123
+ - ProScan 10T
124
+
125
+ That's it for now
126
+
122
127
  # WARNING
123
128
 
124
129
  No guarantees are made as far as hardware safety goes.
@@ -48,16 +48,13 @@ pip install pieusb
48
48
  import numpy
49
49
  import pieusb
50
50
  from pieusb.scanner import Scanner
51
- from pieusb.types import ScanPhase
52
51
 
53
52
  for info in pieusb.get_devices():
54
53
  print(info.vendor, info.model)
55
54
 
56
55
  def on_update(data):
57
- if data.phase == ScanPhase.SCANNING:
58
- print(f"{data.scanned_lines}/{data.total_lines}")
59
- else:
60
- print(data.phase)
56
+ # progress runs 0.0 -> 1.0 within each phase, not across the scan
57
+ print(f"{data.phase}: {data.progress * 100:.1f}%")
61
58
 
62
59
  def on_complete(result):
63
60
  if result.error:
@@ -103,6 +100,14 @@ determines whether a pass pays for its own calibration, never whether the image
103
100
  gets corrected. Since the cache lives on the `Scanner`, a fresh one starts cold:
104
101
  a loop that opens a `Scanner` per frame is correct but calibrates every time.
105
102
 
103
+ ## Status of verification
104
+
105
+ ### Verified on hardware
106
+
107
+ - ProScan 10T
108
+
109
+ That's it for now
110
+
106
111
  # WARNING
107
112
 
108
113
  No guarantees are made as far as hardware safety goes.
@@ -252,7 +252,7 @@ def generate_options(inq: InquiryResponse) -> OptionsTable:
252
252
  name='resolution',
253
253
  type=int,
254
254
  unit=Unit.NONE,
255
- validate=lambda v: v < min(inq.max_resolution_x, inq.max_resolution_y),
255
+ validate=lambda v: v <= min(inq.max_resolution_x, inq.max_resolution_y),
256
256
  default=300
257
257
  )))
258
258
 
@@ -582,4 +582,4 @@ def set_options(dev: UASDevice, options: OptionsTable, *,
582
582
  payload[13] = LINE_THRESHOLD
583
583
  payload[14] = 0x10 # Unexplained, but sent unconditionally by the C backend
584
584
  # (pieusb_scancmd.c:797) and present in the cyberview capture
585
- dev.command(SCSI_MODE_SELECT, out_data=bytes(payload), cdb_length=16)
585
+ dev.command(SCSI_MODE_SELECT, out_data=bytes(payload), cdb_length=16)
@@ -232,10 +232,15 @@ class Scanner:
232
232
  log.debug(f"[scan] {label}: {done}/{total_lines} lines read (remaining {remaining})")
233
233
  yield chunk, lines_this_read
234
234
 
235
- def _get_scanned_lines(self, total_lines, bytes_per_line, label="lines") -> bytes:
235
+ def _get_scanned_lines(self, total_lines, bytes_per_line, label="lines",
236
+ report: Callable[[float], None] | None = None) -> bytes:
236
237
  collected = bytearray()
237
- for chunk, _ in self._iter_scanned_lines(total_lines, bytes_per_line, label):
238
+ done = 0
239
+ for chunk, n_lines in self._iter_scanned_lines(total_lines, bytes_per_line, label):
238
240
  collected.extend(chunk)
241
+ done += n_lines
242
+ if report is not None:
243
+ report(done / total_lines)
239
244
  return bytes(collected)
240
245
 
241
246
  def _get_shading_parms(self) -> list[dict]:
@@ -359,8 +364,8 @@ class Scanner:
359
364
  """Emit a pass's update relabelled as the metering pass.
360
365
 
361
366
  The metering pass runs the same sequence as the real one, so its updates
362
- would otherwise arrive labelled SCANNING and sweep 0->100% before the
363
- real scan started again from 0. Line counts are kept: the pass is a real
367
+ would otherwise arrive labelled SCANNING and sweep 0->1 before the real
368
+ scan started again from 0. `progress` is kept as it is: the pass is a real
364
369
  scan and a progress bar can follow it.
365
370
  """
366
371
  self._emit(replace(update, phase=ScanPhase.METERING))
@@ -600,7 +605,10 @@ class Scanner:
600
605
  break
601
606
  except CheckCondition as e:
602
607
  if e.warming_up:
603
- emit(UpdateData(phase=ScanPhase.WARMING_UP))
608
+ # Progress against the retry budget, which is all we know: the
609
+ # scanner does not say how much warming up it has left.
610
+ emit(UpdateData(phase=ScanPhase.WARMING_UP,
611
+ progress=attempt / START_SCAN_ATTEMPTS))
604
612
  log.debug(f"[scan] still warming up, waiting {START_SCAN_RETRY_S}s "
605
613
  f"(attempt {attempt + 1}/{START_SCAN_ATTEMPTS})...")
606
614
  time.sleep(START_SCAN_RETRY_S)
@@ -646,7 +654,10 @@ class Scanner:
646
654
  log.debug(f"[scan] reading shading reference ({total_shading_lines} lines, "
647
655
  f"{total_shading_lines * shading_bytes_per_line} bytes)...")
648
656
  shading_raw = self._get_scanned_lines(
649
- total_shading_lines, shading_bytes_per_line, label="shading"
657
+ total_shading_lines, shading_bytes_per_line, label="shading",
658
+ report=lambda frac: emit(
659
+ UpdateData(phase=ScanPhase.CALIBRATING, progress=frac)
660
+ ),
650
661
  )
651
662
  self.wait_ready()
652
663
  else:
@@ -683,7 +694,7 @@ class Scanner:
683
694
 
684
695
  log.debug(f"[scan] reading {n_planes} planes x {height} lines "
685
696
  f"({raw_bytes_per_line} bytes/line incl. 2-byte tag)...")
686
- emit(UpdateData(phase=ScanPhase.SCANNING, scanned_lines=0, total_lines=total_lines))
697
+ emit(UpdateData(phase=ScanPhase.SCANNING, progress=0.0))
687
698
 
688
699
  # Planes arrive as sequential blocks -- all R lines, then all G, and so
689
700
  # on -- but the 255-line read cap does not align to those boundaries, so
@@ -714,9 +725,7 @@ class Scanner:
714
725
  chunk, dtype=sample_dtype, count=width, offset=off + 2
715
726
  )
716
727
  done += n_lines
717
- emit(UpdateData(
718
- phase=ScanPhase.SCANNING, scanned_lines=done, total_lines=total_lines
719
- ))
728
+ emit(UpdateData(phase=ScanPhase.SCANNING, progress=done / total_lines))
720
729
 
721
730
  if self.cancel_requested.is_set():
722
731
  log.debug(f"[scan] cancelled after {done}/{total_lines} lines; stopping")
@@ -79,7 +79,7 @@ class DeviceInfo:
79
79
 
80
80
  class ScanPhase(StrEnum):
81
81
  # Every phase of the auto-exposure preview pass reports as METERING, so a
82
- # progress bar sees one 0->100% sweep for it and a second for the real scan,
82
+ # progress bar sees one 0->1 sweep for it and a second for the real scan,
83
83
  # rather than two indistinguishable SCANNING sweeps.
84
84
  METERING = 'Metering'
85
85
  CONFIGURING = 'Configuring'
@@ -90,9 +90,17 @@ class ScanPhase(StrEnum):
90
90
 
91
91
  @dataclass(frozen=True)
92
92
  class UpdateData:
93
+ '''Progress within one phase of a scan, delivered to scan()'s on_update.
94
+
95
+ `progress` runs 0.0 -> 1.0 within `phase` and says nothing about the scan as a
96
+ whole: each phase sweeps the range again, and how many phases a scan has
97
+ depends on the options (auto-exposure adds a metering pass, a reused
98
+ calibration removes CALIBRATING). A phase whose length the device does not
99
+ tell us in advance reports 0.0 throughout, so treat a phase change as the
100
+ real event and `progress` as detail within it.
101
+ '''
93
102
  phase: ScanPhase
94
- scanned_lines: int | None = None
95
- total_lines: int | None = None
103
+ progress: float = 0.0
96
104
 
97
105
  @dataclass(frozen=True)
98
106
  class ScanResult:
@@ -201,27 +201,26 @@ class Progress:
201
201
  self.phase_started = now
202
202
  header = f"[{now - self.started:7.1f}s] {u.phase}"
203
203
  # Without a TTY the bar cannot be rewritten in place, so the header
204
- # gets its own line and only the final count is reported.
205
- keep_open = self.tty and u.scanned_lines is not None
206
- print(header, end='' if keep_open else '\n', flush=True)
207
- self.line_open = keep_open
204
+ # gets its own line and only the phase's last update is reported.
205
+ print(header, end='' if self.tty else '\n', flush=True)
206
+ self.line_open = self.tty
208
207
 
209
- if u.scanned_lines is None or not u.total_lines:
208
+ # Phases the device gives no length for sit at 0.0 throughout; the header
209
+ # above is all there is to show for them.
210
+ if u.progress <= 0:
210
211
  return
211
212
 
212
- frac = u.scanned_lines / u.total_lines
213
213
  elapsed = now - self.phase_started
214
- eta = (elapsed / frac - elapsed) if frac > 0 else 0
214
+ eta = elapsed / u.progress - elapsed
215
215
  bar_w = 28
216
- filled = int(bar_w * frac)
216
+ filled = int(bar_w * u.progress)
217
217
  line = (f"[{now - self.started:7.1f}s] {u.phase} "
218
218
  f"[{'#' * filled}{'.' * (bar_w - filled)}] "
219
- f"{u.scanned_lines}/{u.total_lines} lines "
220
- f"{frac * 100:5.1f}% ETA {eta:5.1f}s")
219
+ f"{u.progress * 100:5.1f}% ETA {eta:5.1f}s")
221
220
  if self.tty:
222
221
  print('\r' + line, end='', flush=True)
223
222
  self.line_open = True
224
- elif u.scanned_lines == u.total_lines:
223
+ elif u.progress >= 1.0:
225
224
  print(line, flush=True)
226
225
 
227
226
  def _finish_line(self) -> None:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes