Skip to content

Commit 6dcbad3

Browse files
committed
add heif_context_set_major_brand() to set user-defined major brand
1 parent 568007a commit 6dcbad3

File tree

5 files changed

+22
-3
lines changed

5 files changed

+22
-3
lines changed

libheif/api/libheif/heif_encoding.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,15 @@ struct heif_error heif_context_set_primary_image(struct heif_context* ctx,
767767
}
768768

769769

770+
void heif_context_set_major_brand(struct heif_context* ctx,
771+
heif_brand2 major_brand)
772+
{
773+
auto ftyp = ctx->context->get_heif_file()->get_ftyp_box();
774+
ftyp->set_major_brand(major_brand);
775+
ftyp->add_compatible_brand(major_brand);
776+
}
777+
778+
770779
void heif_context_add_compatible_brand(struct heif_context* ctx,
771780
heif_brand2 compatible_brand)
772781
{

libheif/api/libheif/heif_encoding.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ LIBHEIF_API
348348
struct heif_error heif_context_set_primary_image(struct heif_context*,
349349
struct heif_image_handle* image_handle);
350350

351+
// Set the major brand of the file.
352+
// If this function is not called, the major brand is determined automatically from
353+
// the image or sequence content.
354+
LIBHEIF_API
355+
void heif_context_set_major_brand(struct heif_context* ctx,
356+
heif_brand2 major_brand);
357+
351358
// Add a compatible brand that is now added automatically by libheif when encoding images (e.g. some application brands like 'geo1').
352359
LIBHEIF_API
353360
void heif_context_add_compatible_brand(struct heif_context* ctx,

libheif/api/libheif/heif_experimental.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,3 @@ struct heif_error heif_context_add_tiled_image(struct heif_context* ctx,
500500
return heif_error_success;
501501
}
502502
#endif
503-

libheif/api/libheif/heif_experimental.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ struct heif_complex64* heif_image_get_channel_complex64(struct heif_image*,
315315
size_t* out_stride);
316316
#endif
317317

318-
319318
#ifdef __cplusplus
320319
}
321320
#endif

libheif/context.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,12 @@ void HeifContext::write(StreamWriter& writer)
371371
// See https://github.com/strukturag/libheif/issues/478
372372

373373
auto ftyp = m_heif_file->get_ftyp_box();
374-
ftyp->set_major_brand(main_brand);
374+
375+
// set major brand if not set manually yet
376+
if (ftyp->get_major_brand() == 0) {
377+
ftyp->set_major_brand(main_brand);
378+
}
379+
375380
ftyp->set_minor_version(0);
376381
for (auto brand : compatible_brands) {
377382
ftyp->add_compatible_brand(brand);

0 commit comments

Comments
 (0)