heif_properties.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * HEIF codec.
  3. * Copyright (c) 2017-2023 Dirk Farin <dirk.farin@gmail.com>
  4. *
  5. * This file is part of libheif.
  6. *
  7. * libheif is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as
  9. * published by the Free Software Foundation, either version 3 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * libheif is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License
  18. * along with libheif. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef LIBHEIF_HEIF_PROPERTIES_H
  21. #define LIBHEIF_HEIF_PROPERTIES_H
  22. #include "heif.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. // ------------------------- item properties -------------------------
  27. enum heif_item_property_type
  28. {
  29. // heif_item_property_unknown = -1,
  30. heif_item_property_type_invalid = 0,
  31. heif_item_property_type_user_description = heif_fourcc('u', 'd', 'e', 's'),
  32. heif_item_property_type_transform_mirror = heif_fourcc('i', 'm', 'i', 'r'),
  33. heif_item_property_type_transform_rotation = heif_fourcc('i', 'r', 'o', 't'),
  34. heif_item_property_type_transform_crop = heif_fourcc('c', 'l', 'a', 'p'),
  35. heif_item_property_type_image_size = heif_fourcc('i', 's', 'p', 'e'),
  36. heif_item_property_type_uuid = heif_fourcc('u', 'u', 'i', 'd')
  37. };
  38. // Get the heif_property_id for a heif_item_id.
  39. // You may specify which property 'type' you want to receive.
  40. // If you specify 'heif_item_property_type_invalid', all properties associated to that item are returned.
  41. // The number of properties is returned, which are not more than 'count' if (out_list != nullptr).
  42. // By setting out_list==nullptr, you can query the number of properties, 'count' is ignored.
  43. LIBHEIF_API
  44. int heif_item_get_properties_of_type(const struct heif_context* context,
  45. heif_item_id id,
  46. enum heif_item_property_type type,
  47. heif_property_id* out_list,
  48. int count);
  49. // Returns all transformative properties in the correct order.
  50. // This includes "irot", "imir", "clap".
  51. // The number of properties is returned, which are not more than 'count' if (out_list != nullptr).
  52. // By setting out_list==nullptr, you can query the number of properties, 'count' is ignored.
  53. LIBHEIF_API
  54. int heif_item_get_transformation_properties(const struct heif_context* context,
  55. heif_item_id id,
  56. heif_property_id* out_list,
  57. int count);
  58. LIBHEIF_API
  59. enum heif_item_property_type heif_item_get_property_type(const struct heif_context* context,
  60. heif_item_id id,
  61. heif_property_id property_id);
  62. // The strings are managed by libheif. They will be deleted in heif_property_user_description_release().
  63. struct heif_property_user_description
  64. {
  65. int version;
  66. // version 1
  67. const char* lang;
  68. const char* name;
  69. const char* description;
  70. const char* tags;
  71. };
  72. // Get the "udes" user description property content.
  73. // Undefined strings are returned as empty strings.
  74. LIBHEIF_API
  75. struct heif_error heif_item_get_property_user_description(const struct heif_context* context,
  76. heif_item_id itemId,
  77. heif_property_id propertyId,
  78. struct heif_property_user_description** out);
  79. // Add a "udes" user description property to the item.
  80. // If any string pointers are NULL, an empty string will be used instead.
  81. LIBHEIF_API
  82. struct heif_error heif_item_add_property_user_description(const struct heif_context* context,
  83. heif_item_id itemId,
  84. const struct heif_property_user_description* description,
  85. heif_property_id* out_propertyId);
  86. // Release all strings and the object itself.
  87. // Only call for objects that you received from heif_item_get_property_user_description().
  88. LIBHEIF_API
  89. void heif_property_user_description_release(struct heif_property_user_description*);
  90. enum heif_transform_mirror_direction
  91. {
  92. heif_transform_mirror_direction_invalid = -1,
  93. heif_transform_mirror_direction_vertical = 0, // flip image vertically
  94. heif_transform_mirror_direction_horizontal = 1 // flip image horizontally
  95. };
  96. // Will return 'heif_transform_mirror_direction_invalid' in case of error.
  97. LIBHEIF_API
  98. enum heif_transform_mirror_direction heif_item_get_property_transform_mirror(const struct heif_context* context,
  99. heif_item_id itemId,
  100. heif_property_id propertyId);
  101. // Returns only 0, 90, 180, or 270 angle values.
  102. // Returns -1 in case of error (but it will only return an error in case of wrong usage).
  103. LIBHEIF_API
  104. int heif_item_get_property_transform_rotation_ccw(const struct heif_context* context,
  105. heif_item_id itemId,
  106. heif_property_id propertyId);
  107. // Returns the number of pixels that should be removed from the four edges.
  108. // Because of the way this data is stored, you have to pass the image size at the moment of the crop operation
  109. // to compute the cropped border sizes.
  110. LIBHEIF_API
  111. void heif_item_get_property_transform_crop_borders(const struct heif_context* context,
  112. heif_item_id itemId,
  113. heif_property_id propertyId,
  114. int image_width, int image_height,
  115. int* left, int* top, int* right, int* bottom);
  116. /**
  117. * @param context
  118. * @param itemId The image item id to which this property belongs.
  119. * @param fourcc_type The short four-cc type of the property to add.
  120. * @param uuid_type If fourcc_type=='uuid', this should point to a 16-byte UUID type. It is ignored otherwise and can be NULL.
  121. * @param data Data to insert for this property (including a full-box header, if required for this box).
  122. * @param size Length of data in bytes.
  123. * @param is_essential Whether this property is essential (boolean).
  124. * @param out_propertyId Outputs the id of the inserted property. Can be NULL.
  125. */
  126. LIBHEIF_API
  127. struct heif_error heif_item_add_raw_property(const struct heif_context* context,
  128. heif_item_id itemId,
  129. uint32_t fourcc_type,
  130. const uint8_t* uuid_type,
  131. const uint8_t* data, size_t size,
  132. int is_essential,
  133. heif_property_id* out_propertyId);
  134. LIBHEIF_API
  135. struct heif_error heif_item_get_property_raw_size(const struct heif_context* context,
  136. heif_item_id itemId,
  137. heif_property_id propertyId,
  138. size_t* out_size);
  139. /**
  140. * @param data_out User-supplied array to write the property data to. The required size of the output array is given by heif_item_get_property_raw_size().
  141. */
  142. LIBHEIF_API
  143. struct heif_error heif_item_get_property_raw_data(const struct heif_context* context,
  144. heif_item_id itemId,
  145. heif_property_id propertyId,
  146. uint8_t* out_data);
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif