Commit 349eae4
committed
jpeg2000: valid_file implementation, much faster than trying to open
Primary cost of detecting whether a given file is valid jpeg2000 file
is the thread pool initialization and shutdown that
Jpeg2000Input::open does (the actual thread pool part is inside
OpenJpeg code).
So add a dedicated valid_file() implementation that only needs to
check 12 bytes of the header. While at it, I changed already existing
isJp2File() to is_jp2_header() to better match naming conventions
used elsewhere, and instead of trying to handle both little and big
endian cases by manual repetition of two sets of magic integers,
let's do just byte comparisons with memcmp instead.
On my PC (Ryzen 5950X, SSD, Windows VS2022), doing ImageInput::create()
on 1138 files where they are not images at all (so OIIO in turns tries
all the input plugins on them):
- Before: 3.4 seconds spent in Jpeg2000Input::open (1.9s
opj_thread_pool_create, 1.3s opj_thread_pool_destroy)
- After: 33 milliseconds spent in Jpeg2000Input::valid_file1 parent 9ee71c4 commit 349eae4
1 file changed
+33
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| |||
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
211 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
212 | 226 | | |
213 | 227 | | |
214 | 228 | | |
| |||
409 | 423 | | |
410 | 424 | | |
411 | 425 | | |
412 | | - | |
413 | 426 | | |
414 | | - | |
| 427 | + | |
415 | 428 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
428 | 435 | | |
429 | 436 | | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
430 | 443 | | |
431 | 444 | | |
432 | 445 | | |
433 | 446 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
437 | 450 | | |
438 | 451 | | |
439 | 452 | | |
440 | | - | |
441 | | - | |
| 453 | + | |
| 454 | + | |
442 | 455 | | |
443 | 456 | | |
444 | 457 | | |
| |||
0 commit comments