sharp 0.27.1 → 0.30.5

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.
@@ -51,6 +51,12 @@
51
51
 
52
52
  VIPS_NAMESPACE_START
53
53
 
54
+ /**
55
+ * \namespace vips
56
+ *
57
+ * General docs for the vips namespace.
58
+ */
59
+
54
60
  std::vector<double>
55
61
  to_vectorv( int n, ... )
56
62
  {
@@ -87,7 +93,7 @@ negate( std::vector<double> vector )
87
93
  {
88
94
  std::vector<double> new_vector( vector.size() );
89
95
 
90
- for( unsigned int i = 0; i < vector.size(); i++ )
96
+ for( std::vector<double>::size_type i = 0; i < vector.size(); i++ )
91
97
  new_vector[i] = vector[i] * -1;
92
98
 
93
99
  return( new_vector );
@@ -98,7 +104,7 @@ invert( std::vector<double> vector )
98
104
  {
99
105
  std::vector<double> new_vector( vector.size() );
100
106
 
101
- for( unsigned int i = 0; i < vector.size(); i++ )
107
+ for( std::vector<double>::size_type i = 0; i < vector.size(); i++ )
102
108
  new_vector[i] = 1.0 / vector[i];
103
109
 
104
110
  return( new_vector );
@@ -140,6 +146,20 @@ VOption::set( const char *name, int value )
140
146
  return( this );
141
147
  }
142
148
 
149
+ // input guint64
150
+ VOption *
151
+ VOption::set( const char *name, guint64 value )
152
+ {
153
+ Pair *pair = new Pair( name );
154
+
155
+ pair->input = true;
156
+ g_value_init( &pair->value, G_TYPE_UINT64 );
157
+ g_value_set_uint64( &pair->value, value );
158
+ options.push_back( pair );
159
+
160
+ return( this );
161
+ }
162
+
143
163
  // input double
144
164
  VOption *
145
165
  VOption::set( const char *name, double value )
@@ -167,37 +187,38 @@ VOption::set( const char *name, const char *value )
167
187
  return( this );
168
188
  }
169
189
 
170
- // input image
190
+ // input vips object (image, source, target, etc. etc.)
171
191
  VOption *
172
- VOption::set( const char *name, const VImage value )
192
+ VOption::set( const char *name, const VObject value )
173
193
  {
174
194
  Pair *pair = new Pair( name );
195
+ VipsObject *object = value.get_object();
196
+ GType type = G_OBJECT_TYPE( object );
175
197
 
176
198
  pair->input = true;
177
- g_value_init( &pair->value, VIPS_TYPE_IMAGE );
178
- g_value_set_object( &pair->value, value.get_image() );
199
+ g_value_init( &pair->value, type );
200
+ g_value_set_object( &pair->value, object );
179
201
  options.push_back( pair );
180
202
 
181
203
  return( this );
182
204
  }
183
205
 
184
- // input double array
206
+ // input int array
185
207
  VOption *
186
- VOption::set( const char *name, std::vector<double> value )
208
+ VOption::set( const char *name, std::vector<int> value )
187
209
  {
188
210
  Pair *pair = new Pair( name );
189
211
 
190
- double *array;
191
- unsigned int i;
212
+ int *array;
192
213
 
193
214
  pair->input = true;
194
215
 
195
- g_value_init( &pair->value, VIPS_TYPE_ARRAY_DOUBLE );
196
- vips_value_set_array_double( &pair->value, NULL,
216
+ g_value_init( &pair->value, VIPS_TYPE_ARRAY_INT );
217
+ vips_value_set_array_int( &pair->value, NULL,
197
218
  static_cast< int >( value.size() ) );
198
- array = vips_value_get_array_double( &pair->value, NULL );
219
+ array = vips_value_get_array_int( &pair->value, NULL );
199
220
 
200
- for( i = 0; i < value.size(); i++ )
221
+ for( std::vector<double>::size_type i = 0; i < value.size(); i++ )
201
222
  array[i] = value[i];
202
223
 
203
224
  options.push_back( pair );
@@ -205,23 +226,22 @@ VOption::set( const char *name, std::vector<double> value )
205
226
  return( this );
206
227
  }
207
228
 
208
- // input int array
229
+ // input double array
209
230
  VOption *
210
- VOption::set( const char *name, std::vector<int> value )
231
+ VOption::set( const char *name, std::vector<double> value )
211
232
  {
212
233
  Pair *pair = new Pair( name );
213
234
 
214
- int *array;
215
- unsigned int i;
235
+ double *array;
216
236
 
217
237
  pair->input = true;
218
238
 
219
- g_value_init( &pair->value, VIPS_TYPE_ARRAY_INT );
220
- vips_value_set_array_int( &pair->value, NULL,
239
+ g_value_init( &pair->value, VIPS_TYPE_ARRAY_DOUBLE );
240
+ vips_value_set_array_double( &pair->value, NULL,
221
241
  static_cast< int >( value.size() ) );
222
- array = vips_value_get_array_int( &pair->value, NULL );
242
+ array = vips_value_get_array_double( &pair->value, NULL );
223
243
 
224
- for( i = 0; i < value.size(); i++ )
244
+ for( std::vector<double>::size_type i = 0; i < value.size(); i++ )
225
245
  array[i] = value[i];
226
246
 
227
247
  options.push_back( pair );
@@ -236,7 +256,6 @@ VOption::set( const char *name, std::vector<VImage> value )
236
256
  Pair *pair = new Pair( name );
237
257
 
238
258
  VipsImage **array;
239
- unsigned int i;
240
259
 
241
260
  pair->input = true;
242
261
 
@@ -245,7 +264,7 @@ VOption::set( const char *name, std::vector<VImage> value )
245
264
  static_cast< int >( value.size() ) );
246
265
  array = vips_value_get_array_image( &pair->value, NULL );
247
266
 
248
- for( i = 0; i < value.size(); i++ ) {
267
+ for( std::vector<double>::size_type i = 0; i < value.size(); i++ ) {
249
268
  VipsImage *vips_image = value[i].get_image();
250
269
 
251
270
  array[i] = vips_image;
@@ -466,10 +485,9 @@ VOption::get_operation( VipsOperation *operation )
466
485
  double *array =
467
486
  vips_value_get_array_double( value,
468
487
  &length );
469
- int j;
470
488
 
471
489
  ((*i)->vvector)->resize( length );
472
- for( j = 0; j < length; j++ )
490
+ for( int j = 0; j < length; j++ )
473
491
  (*((*i)->vvector))[j] = array[j];
474
492
  }
475
493
  else if( type == VIPS_TYPE_BLOB ) {
@@ -619,6 +637,22 @@ VImage::new_from_source( VSource source, const char *option_string,
619
637
  return( out );
620
638
  }
621
639
 
640
+ VImage
641
+ VImage::new_from_memory_steal( void *data, size_t size,
642
+ int width, int height, int bands, VipsBandFormat format )
643
+ {
644
+ VipsImage *image;
645
+
646
+ if( !(image = vips_image_new_from_memory( data, size,
647
+ width, height, bands, format )) )
648
+ throw( VError() );
649
+
650
+ g_signal_connect( image, "postclose",
651
+ G_CALLBACK( vips_image_free_buffer ), data);
652
+
653
+ return( VImage( image ) );
654
+ }
655
+
622
656
  VImage
623
657
  VImage::new_matrix( int width, int height )
624
658
  {
@@ -680,17 +714,38 @@ VImage::write_to_buffer( const char *suffix, void **buf, size_t *size,
680
714
  const char *operation_name;
681
715
  VipsBlob *blob;
682
716
 
717
+ /* Save with the new target API if we can. Fall back to the older
718
+ * mechanism in case the saver we need has not been converted yet.
719
+ *
720
+ * We need to hide any errors from this first phase.
721
+ */
683
722
  vips__filename_split8( suffix, filename, option_string );
684
- if( !(operation_name = vips_foreign_find_save_buffer( filename )) ) {
723
+
724
+ vips_error_freeze();
725
+ operation_name = vips_foreign_find_save_target( filename );
726
+ vips_error_thaw();
727
+
728
+ if( operation_name ) {
729
+ VTarget target = VTarget::new_to_memory();
730
+
731
+ call_option_string( operation_name, option_string,
732
+ (options ? options : VImage::option())->
733
+ set( "in", *this )->
734
+ set( "target", target ) );
735
+
736
+ g_object_get( target.get_target(), "blob", &blob, NULL );
737
+ }
738
+ else if( (operation_name = vips_foreign_find_save_buffer( filename )) ) {
739
+ call_option_string( operation_name, option_string,
740
+ (options ? options : VImage::option())->
741
+ set( "in", *this )->
742
+ set( "buffer", &blob ) );
743
+ }
744
+ else {
685
745
  delete options;
686
746
  throw VError();
687
747
  }
688
748
 
689
- call_option_string( operation_name, option_string,
690
- (options ? options : VImage::option())->
691
- set( "in", *this )->
692
- set( "buffer", &blob ) );
693
-
694
749
  if( blob ) {
695
750
  if( buf ) {
696
751
  *buf = VIPS_AREA( blob )->data;
@@ -729,6 +784,7 @@ std::vector<VImage>
729
784
  VImage::bandsplit( VOption *options ) const
730
785
  {
731
786
  std::vector<VImage> b;
787
+ b.reserve(bands());
732
788
 
733
789
  for( int i = 0; i < bands(); i++ )
734
790
  b.push_back( extract_band( i ) );
@@ -60,17 +60,4 @@ VInterpolate::new_from_name( const char *name, VOption *options )
60
60
  return( out );
61
61
  }
62
62
 
63
- VOption *
64
- VOption::set( const char *name, const VInterpolate value )
65
- {
66
- Pair *pair = new Pair( name );
67
-
68
- pair->input = true;
69
- g_value_init( &pair->value, VIPS_TYPE_INTERPOLATE );
70
- g_value_set_object( &pair->value, value.get_interpolate() );
71
- options.push_back( pair );
72
-
73
- return( this );
74
- }
75
-
76
63
  VIPS_NAMESPACE_END
@@ -1,5 +1,5 @@
1
1
  // bodies for vips operations
2
- // Sun 5 Jul 22:36:37 BST 2020
2
+ // Mon Nov 1 03:31:09 PM CET 2021
3
3
  // this file is generated automatically, do not edit!
4
4
 
5
5
  VImage VImage::CMC2LCh( VOption *options ) const
@@ -1065,6 +1065,18 @@ VImage VImage::fitsload( const char *filename, VOption *options )
1065
1065
  return( out );
1066
1066
  }
1067
1067
 
1068
+ VImage VImage::fitsload_source( VSource source, VOption *options )
1069
+ {
1070
+ VImage out;
1071
+
1072
+ call( "fitsload_source",
1073
+ (options ? options : VImage::option())->
1074
+ set( "out", &out )->
1075
+ set( "source", source ) );
1076
+
1077
+ return( out );
1078
+ }
1079
+
1068
1080
  void VImage::fitssave( const char *filename, VOption *options ) const
1069
1081
  {
1070
1082
  call( "fitssave",
@@ -1250,6 +1262,34 @@ VImage VImage::gifload_source( VSource source, VOption *options )
1250
1262
  return( out );
1251
1263
  }
1252
1264
 
1265
+ void VImage::gifsave( const char *filename, VOption *options ) const
1266
+ {
1267
+ call( "gifsave",
1268
+ (options ? options : VImage::option())->
1269
+ set( "in", *this )->
1270
+ set( "filename", filename ) );
1271
+ }
1272
+
1273
+ VipsBlob *VImage::gifsave_buffer( VOption *options ) const
1274
+ {
1275
+ VipsBlob *buffer;
1276
+
1277
+ call( "gifsave_buffer",
1278
+ (options ? options : VImage::option())->
1279
+ set( "in", *this )->
1280
+ set( "buffer", &buffer ) );
1281
+
1282
+ return( buffer );
1283
+ }
1284
+
1285
+ void VImage::gifsave_target( VTarget target, VOption *options ) const
1286
+ {
1287
+ call( "gifsave_target",
1288
+ (options ? options : VImage::option())->
1289
+ set( "in", *this )->
1290
+ set( "target", target ) );
1291
+ }
1292
+
1253
1293
  VImage VImage::globalbalance( VOption *options ) const
1254
1294
  {
1255
1295
  VImage out;
@@ -1656,6 +1696,70 @@ VImage VImage::join( VImage in2, VipsDirection direction, VOption *options ) con
1656
1696
  return( out );
1657
1697
  }
1658
1698
 
1699
+ VImage VImage::jp2kload( const char *filename, VOption *options )
1700
+ {
1701
+ VImage out;
1702
+
1703
+ call( "jp2kload",
1704
+ (options ? options : VImage::option())->
1705
+ set( "out", &out )->
1706
+ set( "filename", filename ) );
1707
+
1708
+ return( out );
1709
+ }
1710
+
1711
+ VImage VImage::jp2kload_buffer( VipsBlob *buffer, VOption *options )
1712
+ {
1713
+ VImage out;
1714
+
1715
+ call( "jp2kload_buffer",
1716
+ (options ? options : VImage::option())->
1717
+ set( "out", &out )->
1718
+ set( "buffer", buffer ) );
1719
+
1720
+ return( out );
1721
+ }
1722
+
1723
+ VImage VImage::jp2kload_source( VSource source, VOption *options )
1724
+ {
1725
+ VImage out;
1726
+
1727
+ call( "jp2kload_source",
1728
+ (options ? options : VImage::option())->
1729
+ set( "out", &out )->
1730
+ set( "source", source ) );
1731
+
1732
+ return( out );
1733
+ }
1734
+
1735
+ void VImage::jp2ksave( const char *filename, VOption *options ) const
1736
+ {
1737
+ call( "jp2ksave",
1738
+ (options ? options : VImage::option())->
1739
+ set( "in", *this )->
1740
+ set( "filename", filename ) );
1741
+ }
1742
+
1743
+ VipsBlob *VImage::jp2ksave_buffer( VOption *options ) const
1744
+ {
1745
+ VipsBlob *buffer;
1746
+
1747
+ call( "jp2ksave_buffer",
1748
+ (options ? options : VImage::option())->
1749
+ set( "in", *this )->
1750
+ set( "buffer", &buffer ) );
1751
+
1752
+ return( buffer );
1753
+ }
1754
+
1755
+ void VImage::jp2ksave_target( VTarget target, VOption *options ) const
1756
+ {
1757
+ call( "jp2ksave_target",
1758
+ (options ? options : VImage::option())->
1759
+ set( "in", *this )->
1760
+ set( "target", target ) );
1761
+ }
1762
+
1659
1763
  VImage VImage::jpegload( const char *filename, VOption *options )
1660
1764
  {
1661
1765
  VImage out;
@@ -1727,6 +1831,70 @@ void VImage::jpegsave_target( VTarget target, VOption *options ) const
1727
1831
  set( "target", target ) );
1728
1832
  }
1729
1833
 
1834
+ VImage VImage::jxlload( const char *filename, VOption *options )
1835
+ {
1836
+ VImage out;
1837
+
1838
+ call( "jxlload",
1839
+ (options ? options : VImage::option())->
1840
+ set( "out", &out )->
1841
+ set( "filename", filename ) );
1842
+
1843
+ return( out );
1844
+ }
1845
+
1846
+ VImage VImage::jxlload_buffer( VipsBlob *buffer, VOption *options )
1847
+ {
1848
+ VImage out;
1849
+
1850
+ call( "jxlload_buffer",
1851
+ (options ? options : VImage::option())->
1852
+ set( "out", &out )->
1853
+ set( "buffer", buffer ) );
1854
+
1855
+ return( out );
1856
+ }
1857
+
1858
+ VImage VImage::jxlload_source( VSource source, VOption *options )
1859
+ {
1860
+ VImage out;
1861
+
1862
+ call( "jxlload_source",
1863
+ (options ? options : VImage::option())->
1864
+ set( "out", &out )->
1865
+ set( "source", source ) );
1866
+
1867
+ return( out );
1868
+ }
1869
+
1870
+ void VImage::jxlsave( const char *filename, VOption *options ) const
1871
+ {
1872
+ call( "jxlsave",
1873
+ (options ? options : VImage::option())->
1874
+ set( "in", *this )->
1875
+ set( "filename", filename ) );
1876
+ }
1877
+
1878
+ VipsBlob *VImage::jxlsave_buffer( VOption *options ) const
1879
+ {
1880
+ VipsBlob *buffer;
1881
+
1882
+ call( "jxlsave_buffer",
1883
+ (options ? options : VImage::option())->
1884
+ set( "in", *this )->
1885
+ set( "buffer", &buffer ) );
1886
+
1887
+ return( buffer );
1888
+ }
1889
+
1890
+ void VImage::jxlsave_target( VTarget target, VOption *options ) const
1891
+ {
1892
+ call( "jxlsave_target",
1893
+ (options ? options : VImage::option())->
1894
+ set( "in", *this )->
1895
+ set( "target", target ) );
1896
+ }
1897
+
1730
1898
  VImage VImage::labelregions( VOption *options ) const
1731
1899
  {
1732
1900
  VImage mask;
@@ -2284,6 +2452,18 @@ VImage VImage::niftiload( const char *filename, VOption *options )
2284
2452
  return( out );
2285
2453
  }
2286
2454
 
2455
+ VImage VImage::niftiload_source( VSource source, VOption *options )
2456
+ {
2457
+ VImage out;
2458
+
2459
+ call( "niftiload_source",
2460
+ (options ? options : VImage::option())->
2461
+ set( "out", &out )->
2462
+ set( "source", source ) );
2463
+
2464
+ return( out );
2465
+ }
2466
+
2287
2467
  void VImage::niftisave( const char *filename, VOption *options ) const
2288
2468
  {
2289
2469
  call( "niftisave",
@@ -2316,6 +2496,18 @@ VImage VImage::openslideload( const char *filename, VOption *options )
2316
2496
  return( out );
2317
2497
  }
2318
2498
 
2499
+ VImage VImage::openslideload_source( VSource source, VOption *options )
2500
+ {
2501
+ VImage out;
2502
+
2503
+ call( "openslideload_source",
2504
+ (options ? options : VImage::option())->
2505
+ set( "out", &out )->
2506
+ set( "source", source ) );
2507
+
2508
+ return( out );
2509
+ }
2510
+
2319
2511
  VImage VImage::pdfload( const char *filename, VOption *options )
2320
2512
  {
2321
2513
  VImage out;
@@ -3388,6 +3580,18 @@ VImage VImage::vipsload( const char *filename, VOption *options )
3388
3580
  return( out );
3389
3581
  }
3390
3582
 
3583
+ VImage VImage::vipsload_source( VSource source, VOption *options )
3584
+ {
3585
+ VImage out;
3586
+
3587
+ call( "vipsload_source",
3588
+ (options ? options : VImage::option())->
3589
+ set( "out", &out )->
3590
+ set( "source", source ) );
3591
+
3592
+ return( out );
3593
+ }
3594
+
3391
3595
  void VImage::vipssave( const char *filename, VOption *options ) const
3392
3596
  {
3393
3597
  call( "vipssave",
@@ -3396,6 +3600,14 @@ void VImage::vipssave( const char *filename, VOption *options ) const
3396
3600
  set( "filename", filename ) );
3397
3601
  }
3398
3602
 
3603
+ void VImage::vipssave_target( VTarget target, VOption *options ) const
3604
+ {
3605
+ call( "vipssave_target",
3606
+ (options ? options : VImage::option())->
3607
+ set( "in", *this )->
3608
+ set( "target", target ) );
3609
+ }
3610
+
3399
3611
  VImage VImage::webpload( const char *filename, VOption *options )
3400
3612
  {
3401
3613
  VImage out;
package/src/metadata.cc CHANGED
@@ -77,6 +77,9 @@ class MetadataWorker : public Napi::AsyncWorker {
77
77
  if (image.get_typeof("heif-compression") == VIPS_TYPE_REF_STRING) {
78
78
  baton->compression = image.get_string("heif-compression");
79
79
  }
80
+ if (image.get_typeof(VIPS_META_RESOLUTION_UNIT) == VIPS_TYPE_REF_STRING) {
81
+ baton->resolutionUnit = image.get_string(VIPS_META_RESOLUTION_UNIT);
82
+ }
80
83
  if (image.get_typeof("openslide.level-count") == VIPS_TYPE_REF_STRING) {
81
84
  int const levels = std::stoi(image.get_string("openslide.level-count"));
82
85
  for (int l = 0; l < levels; l++) {
@@ -86,7 +89,13 @@ class MetadataWorker : public Napi::AsyncWorker {
86
89
  baton->levels.push_back(std::pair<int, int>(width, height));
87
90
  }
88
91
  }
92
+ if (image.get_typeof(VIPS_META_N_SUBIFDS) == G_TYPE_INT) {
93
+ baton->subifds = image.get_int(VIPS_META_N_SUBIFDS);
94
+ }
89
95
  baton->hasProfile = sharp::HasProfile(image);
96
+ if (image.get_typeof("background") == VIPS_TYPE_ARRAY_DOUBLE) {
97
+ baton->background = image.get_array_double("background");
98
+ }
90
99
  // Derived attributes
91
100
  baton->hasAlpha = sharp::HasAlpha(image);
92
101
  baton->orientation = sharp::ExifOrientation(image);
@@ -192,6 +201,9 @@ class MetadataWorker : public Napi::AsyncWorker {
192
201
  if (!baton->compression.empty()) {
193
202
  info.Set("compression", baton->compression);
194
203
  }
204
+ if (!baton->resolutionUnit.empty()) {
205
+ info.Set("resolutionUnit", baton->resolutionUnit == "in" ? "inch" : baton->resolutionUnit);
206
+ }
195
207
  if (!baton->levels.empty()) {
196
208
  int i = 0;
197
209
  Napi::Array levels = Napi::Array::New(env, static_cast<size_t>(baton->levels.size()));
@@ -203,6 +215,20 @@ class MetadataWorker : public Napi::AsyncWorker {
203
215
  }
204
216
  info.Set("levels", levels);
205
217
  }
218
+ if (baton->subifds > 0) {
219
+ info.Set("subifds", baton->subifds);
220
+ }
221
+ if (!baton->background.empty()) {
222
+ if (baton->background.size() == 3) {
223
+ Napi::Object background = Napi::Object::New(env);
224
+ background.Set("r", baton->background[0]);
225
+ background.Set("g", baton->background[1]);
226
+ background.Set("b", baton->background[2]);
227
+ info.Set("background", background);
228
+ } else {
229
+ info.Set("background", baton->background[0]);
230
+ }
231
+ }
206
232
  info.Set("hasProfile", baton->hasProfile);
207
233
  info.Set("hasAlpha", baton->hasAlpha);
208
234
  if (baton->orientation > 0) {
package/src/metadata.h CHANGED
@@ -40,7 +40,10 @@ struct MetadataBaton {
40
40
  std::vector<int> delay;
41
41
  int pagePrimary;
42
42
  std::string compression;
43
+ std::string resolutionUnit;
43
44
  std::vector<std::pair<int, int>> levels;
45
+ int subifds;
46
+ std::vector<double> background;
44
47
  bool hasProfile;
45
48
  bool hasAlpha;
46
49
  int orientation;
@@ -68,6 +71,7 @@ struct MetadataBaton {
68
71
  pageHeight(0),
69
72
  loop(-1),
70
73
  pagePrimary(-1),
74
+ subifds(0),
71
75
  hasProfile(false),
72
76
  hasAlpha(false),
73
77
  orientation(0),