@@ -211,6 +211,32 @@ typedef struct _VipsForeignLoadHeif {
211
211
212
212
} VipsForeignLoadHeif ;
213
213
214
+ #ifdef HAVE_HEIF_INIT
215
+ static void *
216
+ vips__heif_init_once (void * client )
217
+ {
218
+ struct heif_error error ;
219
+
220
+ error = heif_init (NULL );
221
+ if (error .code )
222
+ g_warning ("heif_init: %s (%d.%d)\n" ,
223
+ error .message ? error .message : "(null)" ,
224
+ error .code , error .subcode );
225
+
226
+ return NULL ;
227
+ }
228
+ #endif /*HAVE_HEIF_INIT*/
229
+
230
+ void
231
+ vips__heif_init (void )
232
+ {
233
+ #ifdef HAVE_HEIF_INIT
234
+ static GOnce once = G_ONCE_INIT ;
235
+
236
+ VIPS_ONCE (& once , vips__heif_init_once , NULL );
237
+ #endif /*HAVE_HEIF_INIT*/
238
+ }
239
+
214
240
void
215
241
vips__heif_error (struct heif_error * error )
216
242
{
@@ -220,6 +246,69 @@ vips__heif_error(struct heif_error *error)
220
246
error -> code , error -> subcode );
221
247
}
222
248
249
+ #ifdef DEBUG
250
+ void
251
+ vips__heif_image_print (struct heif_image * img )
252
+ {
253
+ const static enum heif_channel channel [] = {
254
+ heif_channel_Y ,
255
+ heif_channel_Cb ,
256
+ heif_channel_Cr ,
257
+ heif_channel_R ,
258
+ heif_channel_G ,
259
+ heif_channel_B ,
260
+ heif_channel_Alpha ,
261
+ heif_channel_interleaved
262
+ };
263
+
264
+ const static char * channel_name [] = {
265
+ "heif_channel_Y" ,
266
+ "heif_channel_Cb" ,
267
+ "heif_channel_Cr" ,
268
+ "heif_channel_R" ,
269
+ "heif_channel_G" ,
270
+ "heif_channel_B" ,
271
+ "heif_channel_Alpha" ,
272
+ "heif_channel_interleaved"
273
+ };
274
+
275
+ int i ;
276
+
277
+ printf ("vips__heif_image_print:\n" );
278
+ for (i = 0 ; i < VIPS_NUMBER (channel ); i ++ ) {
279
+ if (!heif_image_has_channel (img , channel [i ]))
280
+ continue ;
281
+
282
+ printf ("\t%s:\n" , channel_name [i ]);
283
+ printf ("\t\twidth = %d\n" ,
284
+ heif_image_get_width (img , channel [i ]));
285
+ printf ("\t\theight = %d\n" ,
286
+ heif_image_get_height (img , channel [i ]));
287
+ printf ("\t\tbits = %d\n" ,
288
+ heif_image_get_bits_per_pixel (img , channel [i ]));
289
+ }
290
+ }
291
+ #endif /*DEBUG*/
292
+
293
+ /* Pick a chroma format. Shared with heifsave.
294
+ */
295
+ int
296
+ vips__heif_chroma (int bits_per_pixel , gboolean has_alpha )
297
+ {
298
+ if (bits_per_pixel == 8 ) {
299
+ if (has_alpha )
300
+ return heif_chroma_interleaved_RGBA ;
301
+ else
302
+ return heif_chroma_interleaved_RGB ;
303
+ }
304
+ else {
305
+ if (has_alpha )
306
+ return heif_chroma_interleaved_RRGGBBAA_BE ;
307
+ else
308
+ return heif_chroma_interleaved_RRGGBB_BE ;
309
+ }
310
+ }
311
+
223
312
typedef struct _VipsForeignLoadHeifClass {
224
313
VipsForeignLoadClass parent_class ;
225
314
@@ -847,69 +936,6 @@ vips_foreign_load_heif_header(VipsForeignLoad *load)
847
936
return 0 ;
848
937
}
849
938
850
- #ifdef DEBUG
851
- void
852
- vips__heif_image_print (struct heif_image * img )
853
- {
854
- const static enum heif_channel channel [] = {
855
- heif_channel_Y ,
856
- heif_channel_Cb ,
857
- heif_channel_Cr ,
858
- heif_channel_R ,
859
- heif_channel_G ,
860
- heif_channel_B ,
861
- heif_channel_Alpha ,
862
- heif_channel_interleaved
863
- };
864
-
865
- const static char * channel_name [] = {
866
- "heif_channel_Y" ,
867
- "heif_channel_Cb" ,
868
- "heif_channel_Cr" ,
869
- "heif_channel_R" ,
870
- "heif_channel_G" ,
871
- "heif_channel_B" ,
872
- "heif_channel_Alpha" ,
873
- "heif_channel_interleaved"
874
- };
875
-
876
- int i ;
877
-
878
- printf ("vips__heif_image_print:\n" );
879
- for (i = 0 ; i < VIPS_NUMBER (channel ); i ++ ) {
880
- if (!heif_image_has_channel (img , channel [i ]))
881
- continue ;
882
-
883
- printf ("\t%s:\n" , channel_name [i ]);
884
- printf ("\t\twidth = %d\n" ,
885
- heif_image_get_width (img , channel [i ]));
886
- printf ("\t\theight = %d\n" ,
887
- heif_image_get_height (img , channel [i ]));
888
- printf ("\t\tbits = %d\n" ,
889
- heif_image_get_bits_per_pixel (img , channel [i ]));
890
- }
891
- }
892
- #endif /*DEBUG*/
893
-
894
- /* Pick a chroma format. Shared with heifsave.
895
- */
896
- int
897
- vips__heif_chroma (int bits_per_pixel , gboolean has_alpha )
898
- {
899
- if (bits_per_pixel == 8 ) {
900
- if (has_alpha )
901
- return heif_chroma_interleaved_RGBA ;
902
- else
903
- return heif_chroma_interleaved_RGB ;
904
- }
905
- else {
906
- if (has_alpha )
907
- return heif_chroma_interleaved_RRGGBBAA_BE ;
908
- else
909
- return heif_chroma_interleaved_RRGGBB_BE ;
910
- }
911
- }
912
-
913
939
static int
914
940
vips_foreign_load_heif_generate (VipsRegion * out_region ,
915
941
void * seq , void * a , void * b , gboolean * stop )
@@ -1051,6 +1077,8 @@ vips_foreign_load_heif_class_init(VipsForeignLoadHeifClass *class)
1051
1077
VipsObjectClass * object_class = (VipsObjectClass * ) class ;
1052
1078
VipsForeignLoadClass * load_class = (VipsForeignLoadClass * ) class ;
1053
1079
1080
+ vips__heif_init ();
1081
+
1054
1082
gobject_class -> dispose = vips_foreign_load_heif_dispose ;
1055
1083
gobject_class -> set_property = vips_object_set_property ;
1056
1084
gobject_class -> get_property = vips_object_get_property ;
0 commit comments