Commit 1ba8c13
authored
Treat maxDPI as a ceiling rather than the render resolution (#7824)
## Description of Changes
`system.maxDPI` (default **500**) is a *safety ceiling* for
user-supplied DPI — `PdfUtils.convertFromPdf`, `ScannerEffectController`
and `ConvertPdfToVideoController` all correctly reject values above it.
But six other places used it as **the working render resolution**, so
every one of them rasterises at 500 DPI on a default install.
The giveaway is that each site declares a sensible constant and then
throws it away — the fallback only applies when `ApplicationProperties`
is *absent*, which never happens in a running app:
| Call site | Intended | Actual (default) | CPU overshoot (∝ DPI²) |
|---|---|---|---|
| `BlankPageController` | 30 | 500 | **278×** |
| `FlattenController` (no `renderDpi` sent) | 100 | 500 | 25× |
| `PdfUtils.convertPdfToPdfImage` — watermark→image, redact, manual
redact | 300 | 500 | 2.8× |
| `OCRController` | 300 | 500 | 2.8× |
| `ExtractImageScansController` | 300 | 500 | 2.8× |
| `InvertFullColorStrategy` | 300 | 500 | 2.8× |
Blank-page detection is the standout: it renders at 500 DPI purely to
compute a white-pixel percentage and throw the image away.
### What changed
Each site now uses `Math.min(<its own target>, maxDPI)`, so `maxDPI`
clamps but never raises. This is the idiom `AutoRotateController` and
`FormUtils` already use. Targets are named constants rather than inline
literals.
`FlattenController`'s explicit-`renderDpi` path was already correct and
is untouched; only its no-request default changed.
### Chosen values
- **300** for everything that rasterises output a user keeps
(watermark→image, redact, flatten, invert, extract-image-scans) — the
print standard, consistent with the DPI default in #7823.
- **300** for OCR — Tesseract's own recommended minimum. More pixels
cost time without improving recognition.
- **150** for blank-page detection, *not* the author's 30. See below.
### Why blank detection is 150, not 30
I measured it rather than trusting the constant. Rendering scan-like
pages and running `isBlankImage`'s statistic (threshold 10, blank at
≥99.9% white):
```
content 30dpi 50dpi 72dpi 100dpi 150dpi 300dpi 500dpi
empty BLANK BLANK BLANK BLANK BLANK BLANK BLANK
specks BLANK BLANK BLANK BLANK BLANK BLANK BLANK
thin-line BLANK keep BLANK keep keep keep keep
one-word BLANK BLANK BLANK BLANK BLANK BLANK BLANK
paragraph keep keep keep keep keep keep keep
```
**At 30 DPI a page containing a thin rule is classified blank and
deleted** — a thin line antialiases into near-white. 72 flips the same
way. 150 matches the 300/500 verdict on every case, so it preserves
today's behaviour exactly at 1/11th the pixels. Using the author's 30
would have shipped data loss.
(Unrelated but visible above: `one-word` is already classified blank at
*every* DPI including today's 500. That is a threshold weakness, not a
DPI one, and is out of scope here.)
## Verification
`PdfUtilsMoreTest.ConvertPdfToPdfImageDpi` renders a one-inch-square
page so the embedded image's pixel width *is* the effective DPI:
- `capsAtPrintQuality` — with `maxDPI=500`, asserts 300. **Confirmed it
catches the regression**: reverting the `Math.min` fails it with
`expected: 300 but was: 500`.
- `respectsLowerCeiling` — with `maxDPI=150`, asserts 150, so the
ceiling still clamps downward.
Full suites for PdfUtils, blank-page, flatten, OCR, extract-image-scans,
invert-colour, watermark and redact all pass unchanged.
## Checklist
- [x] I have read the [Contribution
Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md)
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective
- [x] New and existing unit tests pass locally with my changes1 parent d6bcf58 commit 1ba8c13
7 files changed
Lines changed: 86 additions & 18 deletions
File tree
- app
- common/src
- main/java/stirling/software/common/util
- misc
- test/java/stirling/software/common/util
- core/src/main/java/stirling/software/SPDF/controller/api/misc
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
370 | 373 | | |
371 | 374 | | |
372 | 375 | | |
373 | | - | |
374 | | - | |
| 376 | + | |
| 377 | + | |
375 | 378 | | |
376 | 379 | | |
377 | 380 | | |
378 | | - | |
| 381 | + | |
379 | 382 | | |
380 | 383 | | |
381 | 384 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
55 | | - | |
56 | | - | |
| 58 | + | |
| 59 | + | |
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | | - | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| |||
Lines changed: 46 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
153 | 153 | | |
154 | 154 | | |
155 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
156 | 202 | | |
157 | 203 | | |
158 | 204 | | |
| |||
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
| |||
130 | 134 | | |
131 | 135 | | |
132 | 136 | | |
133 | | - | |
134 | | - | |
| 137 | + | |
| 138 | + | |
135 | 139 | | |
136 | 140 | | |
137 | 141 | | |
138 | | - | |
| 142 | + | |
139 | 143 | | |
140 | 144 | | |
141 | 145 | | |
| |||
app/core/src/main/java/stirling/software/SPDF/controller/api/misc/ExtractImageScansController.java
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
56 | 59 | | |
57 | 60 | | |
58 | 61 | | |
| |||
112 | 115 | | |
113 | 116 | | |
114 | 117 | | |
115 | | - | |
116 | | - | |
| 118 | + | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
120 | | - | |
| 123 | + | |
121 | 124 | | |
122 | 125 | | |
123 | 126 | | |
| |||
Lines changed: 6 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| |||
82 | 85 | | |
83 | 86 | | |
84 | 87 | | |
85 | | - | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| |||
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | | - | |
| 98 | + | |
97 | 99 | | |
98 | 100 | | |
99 | | - | |
| 101 | + | |
| 102 | + | |
100 | 103 | | |
101 | 104 | | |
102 | 105 | | |
| |||
Lines changed: 9 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| |||
392 | 395 | | |
393 | 396 | | |
394 | 397 | | |
395 | | - | |
396 | | - | |
| 398 | + | |
| 399 | + | |
397 | 400 | | |
398 | 401 | | |
399 | | - | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
400 | 406 | | |
401 | 407 | | |
402 | 408 | | |
| |||
0 commit comments