@@ -394,6 +394,45 @@ namespace sharp {
394
394
imageType == ImageType::HEIF;
395
395
}
396
396
397
+ /*
398
+ Format-specific options builder
399
+ */
400
+ vips::VOption* GetOptionsForImageType (ImageType imageType, InputDescriptor *descriptor) {
401
+ vips::VOption *option = VImage::option ()
402
+ ->set (" access" , descriptor->access )
403
+ ->set (" fail_on" , descriptor->failOn );
404
+ if (descriptor->unlimited && ImageTypeSupportsUnlimited (imageType)) {
405
+ option->set (" unlimited" , true );
406
+ }
407
+ if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
408
+ option->set (" dpi" , descriptor->density );
409
+ }
410
+ if (imageType == ImageType::MAGICK) {
411
+ option->set (" density" , std::to_string (descriptor->density ).data ());
412
+ }
413
+ if (ImageTypeSupportsPage (imageType)) {
414
+ option->set (" n" , descriptor->pages );
415
+ option->set (" page" , descriptor->page );
416
+ }
417
+ if (imageType == ImageType::SVG) {
418
+ option->set (" stylesheet" , descriptor->svgStylesheet .data ());
419
+ option->set (" high_bitdepth" , descriptor->svgHighBitdepth );
420
+ }
421
+ if (imageType == ImageType::OPENSLIDE) {
422
+ option->set (" level" , descriptor->level );
423
+ }
424
+ if (imageType == ImageType::TIFF) {
425
+ option->set (" subifd" , descriptor->subifd );
426
+ }
427
+ if (imageType == ImageType::PDF) {
428
+ option->set (" background" , descriptor->pdfBackground );
429
+ }
430
+ if (imageType == ImageType::JP2) {
431
+ option->set (" oneshot" , descriptor->jp2Oneshot );
432
+ }
433
+ return option;
434
+ }
435
+
397
436
/*
398
437
Open an image from the given InputDescriptor (filesystem, compressed buffer, raw pixel data)
399
438
*/
@@ -420,38 +459,7 @@ namespace sharp {
420
459
imageType = DetermineImageType (descriptor->buffer , descriptor->bufferLength );
421
460
if (imageType != ImageType::UNKNOWN) {
422
461
try {
423
- vips::VOption *option = VImage::option ()
424
- ->set (" access" , descriptor->access )
425
- ->set (" fail_on" , descriptor->failOn );
426
- if (descriptor->unlimited && ImageTypeSupportsUnlimited (imageType)) {
427
- option->set (" unlimited" , true );
428
- }
429
- if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
430
- option->set (" dpi" , descriptor->density );
431
- }
432
- if (imageType == ImageType::MAGICK) {
433
- option->set (" density" , std::to_string (descriptor->density ).data ());
434
- }
435
- if (ImageTypeSupportsPage (imageType)) {
436
- option->set (" n" , descriptor->pages );
437
- option->set (" page" , descriptor->page );
438
- }
439
- if (imageType == ImageType::SVG) {
440
- option->set (" stylesheet" , descriptor->svgStylesheet .data ());
441
- option->set (" high_bitdepth" , descriptor->svgHighBitdepth );
442
- }
443
- if (imageType == ImageType::OPENSLIDE) {
444
- option->set (" level" , descriptor->level );
445
- }
446
- if (imageType == ImageType::TIFF) {
447
- option->set (" subifd" , descriptor->subifd );
448
- }
449
- if (imageType == ImageType::PDF) {
450
- option->set (" background" , descriptor->pdfBackground );
451
- }
452
- if (imageType == ImageType::JP2) {
453
- option->set (" oneshot" , descriptor->jp2Oneshot );
454
- }
462
+ vips::VOption *option = GetOptionsForImageType (imageType, descriptor);
455
463
image = VImage::new_from_buffer (descriptor->buffer , descriptor->bufferLength , nullptr , option);
456
464
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
457
465
image = SetDensity (image, descriptor->density );
@@ -534,34 +542,7 @@ namespace sharp {
534
542
}
535
543
if (imageType != ImageType::UNKNOWN) {
536
544
try {
537
- vips::VOption *option = VImage::option ()
538
- ->set (" access" , descriptor->access )
539
- ->set (" fail_on" , descriptor->failOn );
540
- if (descriptor->unlimited && ImageTypeSupportsUnlimited (imageType)) {
541
- option->set (" unlimited" , true );
542
- }
543
- if (imageType == ImageType::SVG || imageType == ImageType::PDF) {
544
- option->set (" dpi" , descriptor->density );
545
- }
546
- if (imageType == ImageType::MAGICK) {
547
- option->set (" density" , std::to_string (descriptor->density ).data ());
548
- }
549
- if (ImageTypeSupportsPage (imageType)) {
550
- option->set (" n" , descriptor->pages );
551
- option->set (" page" , descriptor->page );
552
- }
553
- if (imageType == ImageType::OPENSLIDE) {
554
- option->set (" level" , descriptor->level );
555
- }
556
- if (imageType == ImageType::TIFF) {
557
- option->set (" subifd" , descriptor->subifd );
558
- }
559
- if (imageType == ImageType::PDF) {
560
- option->set (" background" , descriptor->pdfBackground );
561
- }
562
- if (imageType == ImageType::JP2) {
563
- option->set (" oneshot" , descriptor->jp2Oneshot );
564
- }
545
+ vips::VOption *option = GetOptionsForImageType (imageType, descriptor);
565
546
image = VImage::new_from_file (descriptor->file .data (), option);
566
547
if (imageType == ImageType::SVG || imageType == ImageType::PDF || imageType == ImageType::MAGICK) {
567
548
image = SetDensity (image, descriptor->density );
0 commit comments