heif.h 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324
  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_H
  21. #define LIBHEIF_HEIF_H
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. /*! \file heif.h
  26. *
  27. * Public API for libheif.
  28. */
  29. #include <stddef.h>
  30. #include <stdint.h>
  31. #include <libheif/heif_version.h>
  32. // API versions table
  33. //
  34. // release dec.options enc.options heif_reader heif_writer depth.rep col.profile
  35. // ------------------------------------------------------------------------------------------
  36. // 1.0 1 N/A N/A N/A 1 N/A
  37. // 1.1 1 N/A N/A 1 1 N/A
  38. // 1.3 1 1 1 1 1 N/A
  39. // 1.4 1 1 1 1 1 1
  40. // 1.7 2 1 1 1 1 1
  41. // 1.9.2 2 2 1 1 1 1
  42. // 1.10 2 3 1 1 1 1
  43. // 1.11 2 4 1 1 1 1
  44. // 1.13 3 4 1 1 1 1
  45. // 1.14 3 5 1 1 1 1
  46. // 1.15 4 5 1 1 1 1
  47. // 1.16 5 6 1 1 1 1
  48. #if defined(_MSC_VER) && !defined(LIBHEIF_STATIC_BUILD)
  49. #ifdef LIBHEIF_EXPORTS
  50. #define LIBHEIF_API __declspec(dllexport)
  51. #else
  52. #define LIBHEIF_API __declspec(dllimport)
  53. #endif
  54. #elif defined(HAVE_VISIBILITY) && HAVE_VISIBILITY
  55. #ifdef LIBHEIF_EXPORTS
  56. #define LIBHEIF_API __attribute__((__visibility__("default")))
  57. #else
  58. #define LIBHEIF_API
  59. #endif
  60. #else
  61. #define LIBHEIF_API
  62. #endif
  63. #define heif_fourcc(a, b, c, d) ((uint32_t)((a<<24) | (b<<16) | (c<<8) | d))
  64. /* === version numbers === */
  65. // Version string of linked libheif library.
  66. LIBHEIF_API const char* heif_get_version(void);
  67. // Numeric version of linked libheif library, encoded as 0xHHMMLL00 = hh.mm.ll, where hh, mm, ll is the decimal representation of HH, MM, LL.
  68. // For example: 0x02150300 is version 2.21.3
  69. LIBHEIF_API uint32_t heif_get_version_number(void);
  70. // Numeric part "HH" from above. Returned as a decimal number.
  71. LIBHEIF_API int heif_get_version_number_major(void);
  72. // Numeric part "MM" from above. Returned as a decimal number.
  73. LIBHEIF_API int heif_get_version_number_minor(void);
  74. // Numeric part "LL" from above. Returned as a decimal number.
  75. LIBHEIF_API int heif_get_version_number_maintenance(void);
  76. // Helper macros to check for given versions of libheif at compile time.
  77. #define LIBHEIF_MAKE_VERSION(h, m, l) ((h) << 24 | (m) << 16 | (l) << 8)
  78. #define LIBHEIF_HAVE_VERSION(h, m, l) (LIBHEIF_NUMERIC_VERSION >= LIBHEIF_MAKE_VERSION(h, m, l))
  79. struct heif_context;
  80. struct heif_image_handle;
  81. struct heif_image;
  82. enum heif_error_code
  83. {
  84. // Everything ok, no error occurred.
  85. heif_error_Ok = 0,
  86. // Input file does not exist.
  87. heif_error_Input_does_not_exist = 1,
  88. // Error in input file. Corrupted or invalid content.
  89. heif_error_Invalid_input = 2,
  90. // Input file type is not supported.
  91. heif_error_Unsupported_filetype = 3,
  92. // Image requires an unsupported decoder feature.
  93. heif_error_Unsupported_feature = 4,
  94. // Library API has been used in an invalid way.
  95. heif_error_Usage_error = 5,
  96. // Could not allocate enough memory.
  97. heif_error_Memory_allocation_error = 6,
  98. // The decoder plugin generated an error
  99. heif_error_Decoder_plugin_error = 7,
  100. // The encoder plugin generated an error
  101. heif_error_Encoder_plugin_error = 8,
  102. // Error during encoding or when writing to the output
  103. heif_error_Encoding_error = 9,
  104. // Application has asked for a color profile type that does not exist
  105. heif_error_Color_profile_does_not_exist = 10,
  106. // Error loading a dynamic plugin
  107. heif_error_Plugin_loading_error = 11
  108. };
  109. enum heif_suberror_code
  110. {
  111. // no further information available
  112. heif_suberror_Unspecified = 0,
  113. // --- Invalid_input ---
  114. // End of data reached unexpectedly.
  115. heif_suberror_End_of_data = 100,
  116. // Size of box (defined in header) is wrong
  117. heif_suberror_Invalid_box_size = 101,
  118. // Mandatory 'ftyp' box is missing
  119. heif_suberror_No_ftyp_box = 102,
  120. heif_suberror_No_idat_box = 103,
  121. heif_suberror_No_meta_box = 104,
  122. heif_suberror_No_hdlr_box = 105,
  123. heif_suberror_No_hvcC_box = 106,
  124. heif_suberror_No_pitm_box = 107,
  125. heif_suberror_No_ipco_box = 108,
  126. heif_suberror_No_ipma_box = 109,
  127. heif_suberror_No_iloc_box = 110,
  128. heif_suberror_No_iinf_box = 111,
  129. heif_suberror_No_iprp_box = 112,
  130. heif_suberror_No_iref_box = 113,
  131. heif_suberror_No_pict_handler = 114,
  132. // An item property referenced in the 'ipma' box is not existing in the 'ipco' container.
  133. heif_suberror_Ipma_box_references_nonexisting_property = 115,
  134. // No properties have been assigned to an item.
  135. heif_suberror_No_properties_assigned_to_item = 116,
  136. // Image has no (compressed) data
  137. heif_suberror_No_item_data = 117,
  138. // Invalid specification of image grid (tiled image)
  139. heif_suberror_Invalid_grid_data = 118,
  140. // Tile-images in a grid image are missing
  141. heif_suberror_Missing_grid_images = 119,
  142. heif_suberror_Invalid_clean_aperture = 120,
  143. // Invalid specification of overlay image
  144. heif_suberror_Invalid_overlay_data = 121,
  145. // Overlay image completely outside of visible canvas area
  146. heif_suberror_Overlay_image_outside_of_canvas = 122,
  147. heif_suberror_Auxiliary_image_type_unspecified = 123,
  148. heif_suberror_No_or_invalid_primary_item = 124,
  149. heif_suberror_No_infe_box = 125,
  150. heif_suberror_Unknown_color_profile_type = 126,
  151. heif_suberror_Wrong_tile_image_chroma_format = 127,
  152. heif_suberror_Invalid_fractional_number = 128,
  153. heif_suberror_Invalid_image_size = 129,
  154. heif_suberror_Invalid_pixi_box = 130,
  155. heif_suberror_No_av1C_box = 131,
  156. heif_suberror_Wrong_tile_image_pixel_depth = 132,
  157. heif_suberror_Unknown_NCLX_color_primaries = 133,
  158. heif_suberror_Unknown_NCLX_transfer_characteristics = 134,
  159. heif_suberror_Unknown_NCLX_matrix_coefficients = 135,
  160. // Invalid specification of region item
  161. heif_suberror_Invalid_region_data = 136,
  162. // Image has no ispe property
  163. heif_suberror_No_ispe_property = 137,
  164. heif_suberror_Camera_intrinsic_matrix_undefined = 138,
  165. heif_suberror_Camera_extrinsic_matrix_undefined = 139,
  166. // Invalid JPEG 2000 codestream - usually a missing marker
  167. heif_suberror_Invalid_J2K_codestream = 140,
  168. heif_suberror_No_vvcC_box = 141,
  169. // icbr is only needed in some situations, this error is for those cases
  170. heif_suberror_No_icbr_box = 142,
  171. // Decompressing generic compression or header compression data failed (e.g. bitstream corruption)
  172. heif_suberror_Decompression_invalid_data = 150,
  173. // --- Memory_allocation_error ---
  174. // A security limit preventing unreasonable memory allocations was exceeded by the input file.
  175. // Please check whether the file is valid. If it is, contact us so that we could increase the
  176. // security limits further.
  177. heif_suberror_Security_limit_exceeded = 1000,
  178. // There was an error from the underlying compression / decompression library.
  179. // One possibility is lack of resources (e.g. memory).
  180. heif_suberror_Compression_initialisation_error = 1001,
  181. // --- Usage_error ---
  182. // An item ID was used that is not present in the file.
  183. heif_suberror_Nonexisting_item_referenced = 2000, // also used for Invalid_input
  184. // An API argument was given a NULL pointer, which is not allowed for that function.
  185. heif_suberror_Null_pointer_argument = 2001,
  186. // Image channel referenced that does not exist in the image
  187. heif_suberror_Nonexisting_image_channel_referenced = 2002,
  188. // The version of the passed plugin is not supported.
  189. heif_suberror_Unsupported_plugin_version = 2003,
  190. // The version of the passed writer is not supported.
  191. heif_suberror_Unsupported_writer_version = 2004,
  192. // The given (encoder) parameter name does not exist.
  193. heif_suberror_Unsupported_parameter = 2005,
  194. // The value for the given parameter is not in the valid range.
  195. heif_suberror_Invalid_parameter_value = 2006,
  196. // Error in property specification
  197. heif_suberror_Invalid_property = 2007,
  198. // Image reference cycle found in iref
  199. heif_suberror_Item_reference_cycle = 2008,
  200. // --- Unsupported_feature ---
  201. // Image was coded with an unsupported compression method.
  202. heif_suberror_Unsupported_codec = 3000,
  203. // Image is specified in an unknown way, e.g. as tiled grid image (which is supported)
  204. heif_suberror_Unsupported_image_type = 3001,
  205. heif_suberror_Unsupported_data_version = 3002,
  206. // The conversion of the source image to the requested chroma / colorspace is not supported.
  207. heif_suberror_Unsupported_color_conversion = 3003,
  208. heif_suberror_Unsupported_item_construction_method = 3004,
  209. heif_suberror_Unsupported_header_compression_method = 3005,
  210. // Generically compressed data used an unsupported compression method
  211. heif_suberror_Unsupported_generic_compression_method = 3006,
  212. // --- Encoder_plugin_error ---
  213. heif_suberror_Unsupported_bit_depth = 4000,
  214. // --- Encoding_error ---
  215. heif_suberror_Cannot_write_output_data = 5000,
  216. heif_suberror_Encoder_initialization = 5001,
  217. heif_suberror_Encoder_encoding = 5002,
  218. heif_suberror_Encoder_cleanup = 5003,
  219. heif_suberror_Too_many_regions = 5004,
  220. // --- Plugin loading error ---
  221. heif_suberror_Plugin_loading_error = 6000, // a specific plugin file cannot be loaded
  222. heif_suberror_Plugin_is_not_loaded = 6001, // trying to remove a plugin that is not loaded
  223. heif_suberror_Cannot_read_plugin_directory = 6002, // error while scanning the directory for plugins
  224. heif_suberror_No_matching_decoder_installed = 6003 // no decoder found for that compression format
  225. };
  226. struct heif_error
  227. {
  228. // main error category
  229. enum heif_error_code code;
  230. // more detailed error code
  231. enum heif_suberror_code subcode;
  232. // textual error message (is always defined, you do not have to check for NULL)
  233. const char* message;
  234. };
  235. // Default success return value. Intended for use in user-supplied callback functions.
  236. LIBHEIF_API extern const struct heif_error heif_error_success;
  237. typedef uint32_t heif_item_id;
  238. typedef uint32_t heif_property_id;
  239. // ========================= enum types ======================
  240. /**
  241. * libheif known compression formats.
  242. */
  243. enum heif_compression_format
  244. {
  245. /**
  246. * Unspecified / undefined compression format.
  247. *
  248. * This is used to mean "no match" or "any decoder" for some parts of the
  249. * API. It does not indicate a specific compression format.
  250. */
  251. heif_compression_undefined = 0,
  252. /**
  253. * HEVC compression, used for HEIC images.
  254. *
  255. * This is equivalent to H.265.
  256. */
  257. heif_compression_HEVC = 1,
  258. /**
  259. * AVC compression. (Currently unused in libheif.)
  260. *
  261. * The compression is defined in ISO/IEC 14496-10. This is equivalent to H.264.
  262. *
  263. * The encapsulation is defined in ISO/IEC 23008-12:2022 Annex E.
  264. */
  265. heif_compression_AVC = 2,
  266. /**
  267. * JPEG compression.
  268. *
  269. * The compression format is defined in ISO/IEC 10918-1. The encapsulation
  270. * of JPEG is specified in ISO/IEC 23008-12:2022 Annex H.
  271. */
  272. heif_compression_JPEG = 3,
  273. /**
  274. * AV1 compression, used for AVIF images.
  275. *
  276. * The compression format is provided at https://aomediacodec.github.io/av1-spec/
  277. *
  278. * The encapsulation is defined in https://aomediacodec.github.io/av1-avif/
  279. */
  280. heif_compression_AV1 = 4,
  281. /**
  282. * VVC compression. (Currently unused in libheif.)
  283. *
  284. * The compression format is defined in ISO/IEC 23090-3. This is equivalent to H.266.
  285. *
  286. * The encapsulation is defined in ISO/IEC 23008-12:2022 Annex L.
  287. */
  288. heif_compression_VVC = 5,
  289. /**
  290. * EVC compression. (Currently unused in libheif.)
  291. *
  292. * The compression format is defined in ISO/IEC 23094-1. This is equivalent to H.266.
  293. *
  294. * The encapsulation is defined in ISO/IEC 23008-12:2022 Annex M.
  295. */
  296. heif_compression_EVC = 6,
  297. /**
  298. * JPEG 2000 compression.
  299. *
  300. * The encapsulation of JPEG 2000 is specified in ISO/IEC 15444-16:2021.
  301. * The core encoding is defined in ISO/IEC 15444-1, or ITU-T T.800.
  302. */
  303. heif_compression_JPEG2000 = 7,
  304. /**
  305. * Uncompressed encoding.
  306. *
  307. * This is defined in ISO/IEC 23001-17:2023 (Final Draft International Standard).
  308. */
  309. heif_compression_uncompressed = 8,
  310. /**
  311. * Mask image encoding.
  312. *
  313. * See ISO/IEC 23008-12:2022 Section 6.10.2
  314. */
  315. heif_compression_mask = 9,
  316. /**
  317. * High Throughput JPEG 2000 (HT-J2K) compression.
  318. *
  319. * The encapsulation of HT-J2K is specified in ISO/IEC 15444-16:2021.
  320. * The core encoding is defined in ISO/IEC 15444-15, or ITU-T T.814.
  321. */
  322. heif_compression_HTJ2K = 10
  323. };
  324. enum heif_chroma
  325. {
  326. heif_chroma_undefined = 99,
  327. heif_chroma_monochrome = 0,
  328. heif_chroma_420 = 1,
  329. heif_chroma_422 = 2,
  330. heif_chroma_444 = 3,
  331. heif_chroma_interleaved_RGB = 10,
  332. heif_chroma_interleaved_RGBA = 11,
  333. heif_chroma_interleaved_RRGGBB_BE = 12, // HDR, big endian.
  334. heif_chroma_interleaved_RRGGBBAA_BE = 13, // HDR, big endian.
  335. heif_chroma_interleaved_RRGGBB_LE = 14, // HDR, little endian.
  336. heif_chroma_interleaved_RRGGBBAA_LE = 15 // HDR, little endian.
  337. };
  338. // DEPRECATED ENUM NAMES
  339. #define heif_chroma_interleaved_24bit heif_chroma_interleaved_RGB
  340. #define heif_chroma_interleaved_32bit heif_chroma_interleaved_RGBA
  341. enum heif_colorspace
  342. {
  343. heif_colorspace_undefined = 99,
  344. // heif_colorspace_YCbCr should be used with one of these heif_chroma values:
  345. // * heif_chroma_444
  346. // * heif_chroma_422
  347. // * heif_chroma_420
  348. heif_colorspace_YCbCr = 0,
  349. // heif_colorspace_RGB should be used with one of these heif_chroma values:
  350. // * heif_chroma_444 (for planar RGB)
  351. // * heif_chroma_interleaved_RGB
  352. // * heif_chroma_interleaved_RGBA
  353. // * heif_chroma_interleaved_RRGGBB_BE
  354. // * heif_chroma_interleaved_RRGGBBAA_BE
  355. // * heif_chroma_interleaved_RRGGBB_LE
  356. // * heif_chroma_interleaved_RRGGBBAA_LE
  357. heif_colorspace_RGB = 1,
  358. // heif_colorspace_monochrome should only be used with heif_chroma = heif_chroma_monochrome
  359. heif_colorspace_monochrome = 2
  360. };
  361. enum heif_channel
  362. {
  363. heif_channel_Y = 0,
  364. heif_channel_Cb = 1,
  365. heif_channel_Cr = 2,
  366. heif_channel_R = 3,
  367. heif_channel_G = 4,
  368. heif_channel_B = 5,
  369. heif_channel_Alpha = 6,
  370. heif_channel_interleaved = 10
  371. };
  372. // ========================= library initialization ======================
  373. struct heif_init_params
  374. {
  375. int version;
  376. // currently no parameters
  377. };
  378. /**
  379. * Initialise library.
  380. *
  381. * You should call heif_init() when you start using libheif and heif_deinit() when you are finished.
  382. * These calls are reference counted. Each call to heif_init() should be matched by one call to heif_deinit().
  383. *
  384. * For backwards compatibility, it is not really necessary to call heif_init(), but some library memory objects
  385. * will never be freed if you do not call heif_init()/heif_deinit().
  386. *
  387. * heif_init() will load the external modules installed in the default plugin path. Thus, you need it when you
  388. * want to load external plugins from the default path.
  389. * Codec plugins that are compiled into the library directly (selected by the compile-time parameters of libheif)
  390. * will be available even without heif_init().
  391. *
  392. * Make sure that you do not have one part of your program use heif_init()/heif_deinit() and another part that does
  393. * not use it as the latter may try to use an uninitialized library. If in doubt, enclose everything with init/deinit.
  394. *
  395. * You may pass nullptr to get default parameters. Currently, no parameters are supported.
  396. */
  397. LIBHEIF_API
  398. struct heif_error heif_init(struct heif_init_params*);
  399. /**
  400. * Deinitialise and clean up library.
  401. *
  402. * You should call heif_init() when you start using libheif and heif_deinit() when you are finished.
  403. * These calls are reference counted. Each call to heif_init() should be matched by one call to heif_deinit().
  404. *
  405. * \sa heif_init()
  406. */
  407. LIBHEIF_API
  408. void heif_deinit(void);
  409. // --- Plugins are currently only supported on Unix platforms.
  410. enum heif_plugin_type
  411. {
  412. heif_plugin_type_encoder,
  413. heif_plugin_type_decoder
  414. };
  415. struct heif_plugin_info
  416. {
  417. int version; // version of this info struct
  418. enum heif_plugin_type type;
  419. const void* plugin;
  420. void* internal_handle; // for internal use only
  421. };
  422. LIBHEIF_API
  423. struct heif_error heif_load_plugin(const char* filename, struct heif_plugin_info const** out_plugin);
  424. LIBHEIF_API
  425. struct heif_error heif_load_plugins(const char* directory,
  426. const struct heif_plugin_info** out_plugins,
  427. int* out_nPluginsLoaded,
  428. int output_array_size);
  429. LIBHEIF_API
  430. struct heif_error heif_unload_plugin(const struct heif_plugin_info* plugin);
  431. // Get a NULL terminated array of the plugin directories that are searched by libheif.
  432. // This includes the paths specified in the environment variable LIBHEIF_PLUGIN_PATHS and the built-in path
  433. // (if not overridden by the environment variable).
  434. LIBHEIF_API
  435. const char*const* heif_get_plugin_directories(void);
  436. LIBHEIF_API
  437. void heif_free_plugin_directories(const char*const*);
  438. // ========================= file type check ======================
  439. enum heif_filetype_result
  440. {
  441. heif_filetype_no,
  442. heif_filetype_yes_supported, // it is heif and can be read by libheif
  443. heif_filetype_yes_unsupported, // it is heif, but cannot be read by libheif
  444. heif_filetype_maybe // not sure whether it is an heif, try detection with more input data
  445. };
  446. // input data should be at least 12 bytes
  447. LIBHEIF_API
  448. enum heif_filetype_result heif_check_filetype(const uint8_t* data, int len);
  449. /**
  450. * Check the filetype box content for a supported file type.
  451. *
  452. * <p>The data is assumed to start from the start of the `ftyp` box.
  453. *
  454. * <p>This function checks the compatible brands.
  455. *
  456. * @returns heif_error_ok if a supported brand is found, or other error if not.
  457. */
  458. LIBHEIF_API
  459. struct heif_error heif_has_compatible_filetype(const uint8_t* data, int len);
  460. LIBHEIF_API
  461. int heif_check_jpeg_filetype(const uint8_t* data, int len);
  462. // DEPRECATED, use heif_brand2 and the heif_brand2_* constants below instead
  463. enum heif_brand
  464. {
  465. heif_unknown_brand,
  466. heif_heic, // HEIF image with h265
  467. heif_heix, // 10bit images, or anything that uses h265 with range extension
  468. heif_hevc, heif_hevx, // brands for image sequences
  469. heif_heim, // multiview
  470. heif_heis, // scalable
  471. heif_hevm, // multiview sequence
  472. heif_hevs, // scalable sequence
  473. heif_mif1, // image, any coding algorithm
  474. heif_msf1, // sequence, any coding algorithm
  475. heif_avif, // HEIF image with AV1
  476. heif_avis,
  477. heif_vvic, // VVC image
  478. heif_vvis, // VVC sequence
  479. heif_evbi, // EVC image
  480. heif_evbs, // EVC sequence
  481. heif_j2ki, // JPEG2000 image
  482. heif_j2is, // JPEG2000 image sequence
  483. };
  484. // input data should be at least 12 bytes
  485. // DEPRECATED, use heif_read_main_brand() instead
  486. LIBHEIF_API
  487. enum heif_brand heif_main_brand(const uint8_t* data, int len);
  488. typedef uint32_t heif_brand2;
  489. /**
  490. * HEVC image (`heic`) brand.
  491. *
  492. * Image conforms to HEVC (H.265) Main or Main Still profile.
  493. *
  494. * See ISO/IEC 23008-12:2022 Section B.4.1.
  495. */
  496. #define heif_brand2_heic heif_fourcc('h','e','i','c')
  497. /**
  498. * HEVC image (`heix`) brand.
  499. *
  500. * Image conforms to HEVC (H.265) Main 10 profile.
  501. *
  502. * See ISO/IEC 23008-12:2022 Section B.4.1.
  503. */
  504. #define heif_brand2_heix heif_fourcc('h','e','i','x')
  505. /**
  506. * HEVC image sequence (`hevc`) brand.
  507. *
  508. * Image sequence conforms to HEVC (H.265) Main profile.
  509. *
  510. * See ISO/IEC 23008-12:2022 Section B.4.2.
  511. */
  512. #define heif_brand2_hevc heif_fourcc('h','e','v','c')
  513. /**
  514. * HEVC image sequence (`hevx`) brand.
  515. *
  516. * Image sequence conforms to HEVC (H.265) Main 10 profile.
  517. *
  518. * See ISO/IEC 23008-12:2022 Section B.4.2.
  519. */
  520. #define heif_brand2_hevx heif_fourcc('h','e','v','x')
  521. /**
  522. * HEVC layered image (`heim`) brand.
  523. *
  524. * Image layers conform to HEVC (H.265) Main or Multiview Main profile.
  525. *
  526. * See ISO/IEC 23008-12:2022 Section B.4.3.
  527. */
  528. #define heif_brand2_heim heif_fourcc('h','e','i','m')
  529. /**
  530. * HEVC layered image (`heis`) brand.
  531. *
  532. * Image layers conform to HEVC (H.265) Main, Main 10, Scalable Main
  533. * or Scalable Main 10 profile.
  534. *
  535. * See ISO/IEC 23008-12:2022 Section B.4.3.
  536. */
  537. #define heif_brand2_heis heif_fourcc('h','e','i','s')
  538. /**
  539. * HEVC layered image sequence (`hevm`) brand.
  540. *
  541. * Image sequence layers conform to HEVC (H.265) Main or Multiview Main profile.
  542. *
  543. * See ISO/IEC 23008-12:2022 Section B.4.4.
  544. */
  545. #define heif_brand2_hevm heif_fourcc('h','e','v','m')
  546. /**
  547. * HEVC layered image sequence (`hevs`) brand.
  548. *
  549. * Image sequence layers conform to HEVC (H.265) Main, Main 10, Scalable Main
  550. * or Scalable Main 10 profile.
  551. *
  552. * See ISO/IEC 23008-12:2022 Section B.4.4.
  553. */
  554. #define heif_brand2_hevs heif_fourcc('h','e','v','s')
  555. /**
  556. * AV1 image (`avif`) brand.
  557. *
  558. * See https://aomediacodec.github.io/av1-avif/#image-and-image-collection-brand
  559. */
  560. #define heif_brand2_avif heif_fourcc('a','v','i','f')
  561. /**
  562. * AV1 image sequence (`avis`) brand.
  563. *
  564. * See https://aomediacodec.github.io/av1-avif/#image-sequence-brand
  565. */
  566. #define heif_brand2_avis heif_fourcc('a','v','i','s') // AVIF sequence
  567. /**
  568. * HEIF image structural brand (`mif1`).
  569. *
  570. * This does not imply a specific coding algorithm.
  571. *
  572. * See ISO/IEC 23008-12:2022 Section 10.2.2.
  573. */
  574. #define heif_brand2_mif1 heif_fourcc('m','i','f','1')
  575. /**
  576. * HEIF image structural brand (`mif2`).
  577. *
  578. * This does not imply a specific coding algorithm. `mif2` extends
  579. * the requirements of `mif1` to include the `rref` and `iscl` item
  580. * properties.
  581. *
  582. * See ISO/IEC 23008-12:2022 Section 10.2.3.
  583. */
  584. #define heif_brand2_mif2 heif_fourcc('m','i','f','2')
  585. /**
  586. * HEIF image sequence structural brand (`msf1`).
  587. *
  588. * This does not imply a specific coding algorithm.
  589. *
  590. * See ISO/IEC 23008-12:2022 Section 10.3.1.
  591. */
  592. #define heif_brand2_msf1 heif_fourcc('m','s','f','1')
  593. /**
  594. * VVC image (`vvic`) brand.
  595. *
  596. * See ISO/IEC 23008-12:2022 Section L.4.1.
  597. */
  598. #define heif_brand2_vvic heif_fourcc('v','v','i','c')
  599. /**
  600. * VVC image sequence (`vvis`) brand.
  601. *
  602. * See ISO/IEC 23008-12:2022 Section L.4.2.
  603. */
  604. #define heif_brand2_vvis heif_fourcc('v','v','i','s')
  605. /**
  606. * EVC baseline image (`evbi`) brand.
  607. *
  608. * See ISO/IEC 23008-12:2022 Section M.4.1.
  609. */
  610. #define heif_brand2_evbi heif_fourcc('e','v','b','i')
  611. /**
  612. * EVC main profile image (`evmi`) brand.
  613. *
  614. * See ISO/IEC 23008-12:2022 Section M.4.2.
  615. */
  616. #define heif_brand2_evmi heif_fourcc('e','v','m','i')
  617. /**
  618. * EVC baseline image sequence (`evbs`) brand.
  619. *
  620. * See ISO/IEC 23008-12:2022 Section M.4.3.
  621. */
  622. #define heif_brand2_evbs heif_fourcc('e','v','b','s')
  623. /**
  624. * EVC main profile image sequence (`evms`) brand.
  625. *
  626. * See ISO/IEC 23008-12:2022 Section M.4.4.
  627. */
  628. #define heif_brand2_evms heif_fourcc('e','v','m','s')
  629. /**
  630. * JPEG image (`jpeg`) brand.
  631. *
  632. * See ISO/IEC 23008-12:2022 Annex H.4
  633. */
  634. #define heif_brand2_jpeg heif_fourcc('j','p','e','g')
  635. /**
  636. * JPEG image sequence (`jpgs`) brand.
  637. *
  638. * See ISO/IEC 23008-12:2022 Annex H.5
  639. */
  640. #define heif_brand2_jpgs heif_fourcc('j','p','g','s')
  641. /**
  642. * JPEG 2000 image (`j2ki`) brand.
  643. *
  644. * See ISO/IEC 15444-16:2021 Section 6.5
  645. */
  646. #define heif_brand2_j2ki heif_fourcc('j','2','k','i')
  647. /**
  648. * JPEG 2000 image sequence (`j2is`) brand.
  649. *
  650. * See ISO/IEC 15444-16:2021 Section 7.6
  651. */
  652. #define heif_brand2_j2is heif_fourcc('j','2','i','s')
  653. /**
  654. * Multi-image application format (MIAF) brand.
  655. *
  656. * This is HEIF with additional constraints for interoperability.
  657. *
  658. * See ISO/IEC 23000-22.
  659. */
  660. #define heif_brand2_miaf heif_fourcc('m','i','a','f')
  661. /**
  662. * Single picture file brand.
  663. *
  664. * This is a compatible brand indicating the file contains a single intra-coded picture.
  665. *
  666. * See ISO/IEC 23008-12:2022 Section 10.2.5.
  667. */
  668. #define heif_brand2_1pic heif_fourcc('1','p','i','c')
  669. // input data should be at least 12 bytes
  670. LIBHEIF_API
  671. heif_brand2 heif_read_main_brand(const uint8_t* data, int len);
  672. // 'brand_fourcc' must be 4 character long, but need not be 0-terminated
  673. LIBHEIF_API
  674. heif_brand2 heif_fourcc_to_brand(const char* brand_fourcc);
  675. // the output buffer must be at least 4 bytes long
  676. LIBHEIF_API
  677. void heif_brand_to_fourcc(heif_brand2 brand, char* out_fourcc);
  678. // 'brand_fourcc' must be 4 character long, but need not be 0-terminated
  679. // returns 1 if file includes the brand, and 0 if it does not
  680. // returns -1 if the provided data is not sufficient
  681. // (you should input at least as many bytes as indicated in the first 4 bytes of the file, usually ~50 bytes will do)
  682. // returns -2 on other errors
  683. LIBHEIF_API
  684. int heif_has_compatible_brand(const uint8_t* data, int len, const char* brand_fourcc);
  685. // Returns an array of compatible brands. The array is allocated by this function and has to be freed with 'heif_free_list_of_compatible_brands()'.
  686. // The number of entries is returned in out_size.
  687. LIBHEIF_API
  688. struct heif_error heif_list_compatible_brands(const uint8_t* data, int len, heif_brand2** out_brands, int* out_size);
  689. LIBHEIF_API
  690. void heif_free_list_of_compatible_brands(heif_brand2* brands_list);
  691. // Returns one of these MIME types:
  692. // - image/heic HEIF file using h265 compression
  693. // - image/heif HEIF file using any other compression
  694. // - image/heic-sequence HEIF image sequence using h265 compression
  695. // - image/heif-sequence HEIF image sequence using any other compression
  696. // - image/avif AVIF image
  697. // - image/avif-sequence AVIF sequence
  698. // - image/jpeg JPEG image
  699. // - image/png PNG image
  700. // If the format could not be detected, an empty string is returned.
  701. //
  702. // Provide at least 12 bytes of input. With less input, its format might not
  703. // be detected. You may also provide more input to increase detection accuracy.
  704. //
  705. // Note that JPEG and PNG images cannot be decoded by libheif even though the
  706. // formats are detected by this function.
  707. LIBHEIF_API
  708. const char* heif_get_file_mime_type(const uint8_t* data, int len);
  709. // ========================= heif_context =========================
  710. // A heif_context represents a HEIF file that has been read.
  711. // In the future, you will also be able to add pictures to a heif_context
  712. // and write it into a file again.
  713. // Allocate a new context for reading HEIF files.
  714. // Has to be freed again with heif_context_free().
  715. LIBHEIF_API
  716. struct heif_context* heif_context_alloc(void);
  717. // Free a previously allocated HEIF context. You should not free a context twice.
  718. LIBHEIF_API
  719. void heif_context_free(struct heif_context*);
  720. struct heif_reading_options;
  721. enum heif_reader_grow_status
  722. {
  723. heif_reader_grow_status_size_reached, // requested size has been reached, we can read until this point
  724. heif_reader_grow_status_timeout, // size has not been reached yet, but it may still grow further
  725. heif_reader_grow_status_size_beyond_eof // size has not been reached and never will. The file has grown to its full size
  726. };
  727. struct heif_reader
  728. {
  729. // API version supported by this reader
  730. int reader_api_version;
  731. // --- version 1 functions ---
  732. int64_t (* get_position)(void* userdata);
  733. // The functions read(), and seek() return heif_error_ok on success.
  734. // Generally, libheif will make sure that we do not read past the file size.
  735. int (* read)(void* data,
  736. size_t size,
  737. void* userdata);
  738. int (* seek)(int64_t position,
  739. void* userdata);
  740. // When calling this function, libheif wants to make sure that it can read the file
  741. // up to 'target_size'. This is useful when the file is currently downloaded and may
  742. // grow with time. You may, for example, extract the image sizes even before the actual
  743. // compressed image data has been completely downloaded.
  744. //
  745. // Even if your input files will not grow, you will have to implement at least
  746. // detection whether the target_size is above the (fixed) file length
  747. // (in this case, return 'size_beyond_eof').
  748. enum heif_reader_grow_status (* wait_for_file_size)(int64_t target_size, void* userdata);
  749. };
  750. // Read a HEIF file from a named disk file.
  751. // The heif_reading_options should currently be set to NULL.
  752. LIBHEIF_API
  753. struct heif_error heif_context_read_from_file(struct heif_context*, const char* filename,
  754. const struct heif_reading_options*);
  755. // Read a HEIF file stored completely in memory.
  756. // The heif_reading_options should currently be set to NULL.
  757. // DEPRECATED: use heif_context_read_from_memory_without_copy() instead.
  758. LIBHEIF_API
  759. struct heif_error heif_context_read_from_memory(struct heif_context*,
  760. const void* mem, size_t size,
  761. const struct heif_reading_options*);
  762. // Same as heif_context_read_from_memory() except that the provided memory is not copied.
  763. // That means, you will have to keep the memory area alive as long as you use the heif_context.
  764. LIBHEIF_API
  765. struct heif_error heif_context_read_from_memory_without_copy(struct heif_context*,
  766. const void* mem, size_t size,
  767. const struct heif_reading_options*);
  768. LIBHEIF_API
  769. struct heif_error heif_context_read_from_reader(struct heif_context*,
  770. const struct heif_reader* reader,
  771. void* userdata,
  772. const struct heif_reading_options*);
  773. // Number of top-level images in the HEIF file. This does not include the thumbnails or the
  774. // tile images that are composed to an image grid. You can get access to the thumbnails via
  775. // the main image handle.
  776. LIBHEIF_API
  777. int heif_context_get_number_of_top_level_images(struct heif_context* ctx);
  778. LIBHEIF_API
  779. int heif_context_is_top_level_image_ID(struct heif_context* ctx, heif_item_id id);
  780. // Fills in image IDs into the user-supplied int-array 'ID_array', preallocated with 'count' entries.
  781. // Function returns the total number of IDs filled into the array.
  782. LIBHEIF_API
  783. int heif_context_get_list_of_top_level_image_IDs(struct heif_context* ctx,
  784. heif_item_id* ID_array,
  785. int count);
  786. LIBHEIF_API
  787. struct heif_error heif_context_get_primary_image_ID(struct heif_context* ctx, heif_item_id* id);
  788. // Get a handle to the primary image of the HEIF file.
  789. // This is the image that should be displayed primarily when there are several images in the file.
  790. LIBHEIF_API
  791. struct heif_error heif_context_get_primary_image_handle(struct heif_context* ctx,
  792. struct heif_image_handle**);
  793. // Get the image handle for a known image ID.
  794. LIBHEIF_API
  795. struct heif_error heif_context_get_image_handle(struct heif_context* ctx,
  796. heif_item_id id,
  797. struct heif_image_handle**);
  798. // Print information about the boxes of a HEIF file to file descriptor.
  799. // This is for debugging and informational purposes only. You should not rely on
  800. // the output having a specific format. At best, you should not use this at all.
  801. LIBHEIF_API
  802. void heif_context_debug_dump_boxes_to_file(struct heif_context* ctx, int fd);
  803. LIBHEIF_API
  804. void heif_context_set_maximum_image_size_limit(struct heif_context* ctx, int maximum_width);
  805. // If the maximum threads number is set to 0, the image tiles are decoded in the main thread.
  806. // This is different from setting it to 1, which will generate a single background thread to decode the tiles.
  807. // Note that this setting only affects libheif itself. The codecs itself may still use multi-threaded decoding.
  808. // You can use it, for example, in cases where you are decoding several images in parallel anyway you thus want
  809. // to minimize parallelism in each decoder.
  810. LIBHEIF_API
  811. void heif_context_set_max_decoding_threads(struct heif_context* ctx, int max_threads);
  812. // ========================= heif_image_handle =========================
  813. // An heif_image_handle is a handle to a logical image in the HEIF file.
  814. // To get the actual pixel data, you have to decode the handle to an heif_image.
  815. // An heif_image_handle also gives you access to the thumbnails and Exif data
  816. // associated with an image.
  817. // Once you obtained an heif_image_handle, you can already release the heif_context,
  818. // since it is internally ref-counted.
  819. // Release image handle.
  820. LIBHEIF_API
  821. void heif_image_handle_release(const struct heif_image_handle*);
  822. // Check whether the given image_handle is the primary image of the file.
  823. LIBHEIF_API
  824. int heif_image_handle_is_primary_image(const struct heif_image_handle* handle);
  825. LIBHEIF_API
  826. heif_item_id heif_image_handle_get_item_id(const struct heif_image_handle* handle);
  827. // Get the resolution of an image.
  828. LIBHEIF_API
  829. int heif_image_handle_get_width(const struct heif_image_handle* handle);
  830. LIBHEIF_API
  831. int heif_image_handle_get_height(const struct heif_image_handle* handle);
  832. LIBHEIF_API
  833. int heif_image_handle_has_alpha_channel(const struct heif_image_handle*);
  834. LIBHEIF_API
  835. int heif_image_handle_is_premultiplied_alpha(const struct heif_image_handle*);
  836. // Returns -1 on error, e.g. if this information is not present in the image.
  837. LIBHEIF_API
  838. int heif_image_handle_get_luma_bits_per_pixel(const struct heif_image_handle*);
  839. // Returns -1 on error, e.g. if this information is not present in the image.
  840. LIBHEIF_API
  841. int heif_image_handle_get_chroma_bits_per_pixel(const struct heif_image_handle*);
  842. // Return the colorspace that libheif proposes to use for decoding.
  843. // Usually, these will be either YCbCr or Monochrome, but it may also propose RGB for images
  844. // encoded with matrix_coefficients=0.
  845. // It may also return *_undefined if the file misses relevant information to determine this without decoding.
  846. LIBHEIF_API
  847. struct heif_error heif_image_handle_get_preferred_decoding_colorspace(const struct heif_image_handle* image_handle,
  848. enum heif_colorspace* out_colorspace,
  849. enum heif_chroma* out_chroma);
  850. // Get the image width from the 'ispe' box. This is the original image size without
  851. // any transformations applied to it. Do not use this unless you know exactly what
  852. // you are doing.
  853. LIBHEIF_API
  854. int heif_image_handle_get_ispe_width(const struct heif_image_handle* handle);
  855. LIBHEIF_API
  856. int heif_image_handle_get_ispe_height(const struct heif_image_handle* handle);
  857. // This gets the context associated with the image handle.
  858. // Note that you have to release the returned context with heif_context_free() in any case.
  859. //
  860. // This means: when you have several image-handles that originate from the same file and you get the
  861. // context of each of them, the returned pointer may be different even though it refers to the same
  862. // logical context. You have to call heif_context_free() on all those context pointers.
  863. // After you freed a context pointer, you can still use the context through a different pointer that you
  864. // might have acquired from elsewhere.
  865. LIBHEIF_API
  866. struct heif_context* heif_image_handle_get_context(const struct heif_image_handle* handle);
  867. // ------------------------- depth images -------------------------
  868. LIBHEIF_API
  869. int heif_image_handle_has_depth_image(const struct heif_image_handle*);
  870. LIBHEIF_API
  871. int heif_image_handle_get_number_of_depth_images(const struct heif_image_handle* handle);
  872. LIBHEIF_API
  873. int heif_image_handle_get_list_of_depth_image_IDs(const struct heif_image_handle* handle,
  874. heif_item_id* ids, int count);
  875. LIBHEIF_API
  876. struct heif_error heif_image_handle_get_depth_image_handle(const struct heif_image_handle* handle,
  877. heif_item_id depth_image_id,
  878. struct heif_image_handle** out_depth_handle);
  879. enum heif_depth_representation_type
  880. {
  881. heif_depth_representation_type_uniform_inverse_Z = 0,
  882. heif_depth_representation_type_uniform_disparity = 1,
  883. heif_depth_representation_type_uniform_Z = 2,
  884. heif_depth_representation_type_nonuniform_disparity = 3
  885. };
  886. struct heif_depth_representation_info
  887. {
  888. uint8_t version;
  889. // version 1 fields
  890. uint8_t has_z_near;
  891. uint8_t has_z_far;
  892. uint8_t has_d_min;
  893. uint8_t has_d_max;
  894. double z_near;
  895. double z_far;
  896. double d_min;
  897. double d_max;
  898. enum heif_depth_representation_type depth_representation_type;
  899. uint32_t disparity_reference_view;
  900. uint32_t depth_nonlinear_representation_model_size;
  901. uint8_t* depth_nonlinear_representation_model;
  902. // version 2 fields below
  903. };
  904. LIBHEIF_API
  905. void heif_depth_representation_info_free(const struct heif_depth_representation_info* info);
  906. // Returns true when there is depth_representation_info available
  907. // Note 1: depth_image_id is currently unused because we support only one depth channel per image, but
  908. // you should still provide the correct ID for future compatibility.
  909. // Note 2: Because of an API bug before v1.11.0, the function also works when 'handle' is the handle of the depth image.
  910. // However, you should pass the handle of the main image. Please adapt your code if needed.
  911. LIBHEIF_API
  912. int heif_image_handle_get_depth_image_representation_info(const struct heif_image_handle* handle,
  913. heif_item_id depth_image_id,
  914. const struct heif_depth_representation_info** out);
  915. // ------------------------- thumbnails -------------------------
  916. // List the number of thumbnails assigned to this image handle. Usually 0 or 1.
  917. LIBHEIF_API
  918. int heif_image_handle_get_number_of_thumbnails(const struct heif_image_handle* handle);
  919. LIBHEIF_API
  920. int heif_image_handle_get_list_of_thumbnail_IDs(const struct heif_image_handle* handle,
  921. heif_item_id* ids, int count);
  922. // Get the image handle of a thumbnail image.
  923. LIBHEIF_API
  924. struct heif_error heif_image_handle_get_thumbnail(const struct heif_image_handle* main_image_handle,
  925. heif_item_id thumbnail_id,
  926. struct heif_image_handle** out_thumbnail_handle);
  927. // ------------------------- auxiliary images -------------------------
  928. #define LIBHEIF_AUX_IMAGE_FILTER_OMIT_ALPHA (1UL<<1)
  929. #define LIBHEIF_AUX_IMAGE_FILTER_OMIT_DEPTH (2UL<<1)
  930. // List the number of auxiliary images assigned to this image handle.
  931. LIBHEIF_API
  932. int heif_image_handle_get_number_of_auxiliary_images(const struct heif_image_handle* handle,
  933. int aux_filter);
  934. LIBHEIF_API
  935. int heif_image_handle_get_list_of_auxiliary_image_IDs(const struct heif_image_handle* handle,
  936. int aux_filter,
  937. heif_item_id* ids, int count);
  938. // You are responsible to deallocate the returned buffer with heif_image_handle_release_auxiliary_type().
  939. LIBHEIF_API
  940. struct heif_error heif_image_handle_get_auxiliary_type(const struct heif_image_handle* handle,
  941. const char** out_type);
  942. LIBHEIF_API
  943. void heif_image_handle_release_auxiliary_type(const struct heif_image_handle* handle,
  944. const char** out_type);
  945. // DEPRECATED (because typo in function name). Use heif_image_handle_release_auxiliary_type() instead.
  946. LIBHEIF_API
  947. void heif_image_handle_free_auxiliary_types(const struct heif_image_handle* handle,
  948. const char** out_type);
  949. // Get the image handle of an auxiliary image.
  950. LIBHEIF_API
  951. struct heif_error heif_image_handle_get_auxiliary_image_handle(const struct heif_image_handle* main_image_handle,
  952. heif_item_id auxiliary_id,
  953. struct heif_image_handle** out_auxiliary_handle);
  954. // ------------------------- metadata (Exif / XMP) -------------------------
  955. // How many metadata blocks are attached to an image. If you only want to get EXIF data,
  956. // set the type_filter to "Exif". Otherwise, set the type_filter to NULL.
  957. LIBHEIF_API
  958. int heif_image_handle_get_number_of_metadata_blocks(const struct heif_image_handle* handle,
  959. const char* type_filter);
  960. // 'type_filter' can be used to get only metadata of specific types, like "Exif".
  961. // If 'type_filter' is NULL, it will return all types of metadata IDs.
  962. LIBHEIF_API
  963. int heif_image_handle_get_list_of_metadata_block_IDs(const struct heif_image_handle* handle,
  964. const char* type_filter,
  965. heif_item_id* ids, int count);
  966. // Return a string indicating the type of the metadata, as specified in the HEIF file.
  967. // Exif data will have the type string "Exif".
  968. // This string will be valid until the next call to a libheif function.
  969. // You do not have to free this string.
  970. LIBHEIF_API
  971. const char* heif_image_handle_get_metadata_type(const struct heif_image_handle* handle,
  972. heif_item_id metadata_id);
  973. // For EXIF, the content type is empty.
  974. // For XMP, the content type is "application/rdf+xml".
  975. LIBHEIF_API
  976. const char* heif_image_handle_get_metadata_content_type(const struct heif_image_handle* handle,
  977. heif_item_id metadata_id);
  978. // Get the size of the raw metadata, as stored in the HEIF file.
  979. LIBHEIF_API
  980. size_t heif_image_handle_get_metadata_size(const struct heif_image_handle* handle,
  981. heif_item_id metadata_id);
  982. // 'out_data' must point to a memory area of the size reported by heif_image_handle_get_metadata_size().
  983. // The data is returned exactly as stored in the HEIF file.
  984. // For Exif data, you probably have to skip the first four bytes of the data, since they
  985. // indicate the offset to the start of the TIFF header of the Exif data.
  986. LIBHEIF_API
  987. struct heif_error heif_image_handle_get_metadata(const struct heif_image_handle* handle,
  988. heif_item_id metadata_id,
  989. void* out_data);
  990. // Only valid for item type == "uri ", an absolute URI
  991. LIBHEIF_API
  992. const char* heif_image_handle_get_metadata_item_uri_type(const struct heif_image_handle* handle,
  993. heif_item_id metadata_id);
  994. // ------------------------- color profiles -------------------------
  995. enum heif_color_profile_type
  996. {
  997. heif_color_profile_type_not_present = 0,
  998. heif_color_profile_type_nclx = heif_fourcc('n', 'c', 'l', 'x'),
  999. heif_color_profile_type_rICC = heif_fourcc('r', 'I', 'C', 'C'),
  1000. heif_color_profile_type_prof = heif_fourcc('p', 'r', 'o', 'f')
  1001. };
  1002. // Returns 'heif_color_profile_type_not_present' if there is no color profile.
  1003. // If there is an ICC profile and an NCLX profile, the ICC profile is returned.
  1004. // TODO: we need a new API for this function as images can contain both NCLX and ICC at the same time.
  1005. // However, you can still use heif_image_handle_get_raw_color_profile() and
  1006. // heif_image_handle_get_nclx_color_profile() to access both profiles.
  1007. LIBHEIF_API
  1008. enum heif_color_profile_type heif_image_handle_get_color_profile_type(const struct heif_image_handle* handle);
  1009. LIBHEIF_API
  1010. size_t heif_image_handle_get_raw_color_profile_size(const struct heif_image_handle* handle);
  1011. // Returns 'heif_error_Color_profile_does_not_exist' when there is no ICC profile.
  1012. LIBHEIF_API
  1013. struct heif_error heif_image_handle_get_raw_color_profile(const struct heif_image_handle* handle,
  1014. void* out_data);
  1015. enum heif_color_primaries
  1016. {
  1017. heif_color_primaries_ITU_R_BT_709_5 = 1, // g=0.3;0.6, b=0.15;0.06, r=0.64;0.33, w=0.3127,0.3290
  1018. heif_color_primaries_unspecified = 2,
  1019. heif_color_primaries_ITU_R_BT_470_6_System_M = 4,
  1020. heif_color_primaries_ITU_R_BT_470_6_System_B_G = 5,
  1021. heif_color_primaries_ITU_R_BT_601_6 = 6,
  1022. heif_color_primaries_SMPTE_240M = 7,
  1023. heif_color_primaries_generic_film = 8,
  1024. heif_color_primaries_ITU_R_BT_2020_2_and_2100_0 = 9,
  1025. heif_color_primaries_SMPTE_ST_428_1 = 10,
  1026. heif_color_primaries_SMPTE_RP_431_2 = 11,
  1027. heif_color_primaries_SMPTE_EG_432_1 = 12,
  1028. heif_color_primaries_EBU_Tech_3213_E = 22
  1029. };
  1030. enum heif_transfer_characteristics
  1031. {
  1032. heif_transfer_characteristic_ITU_R_BT_709_5 = 1,
  1033. heif_transfer_characteristic_unspecified = 2,
  1034. heif_transfer_characteristic_ITU_R_BT_470_6_System_M = 4,
  1035. heif_transfer_characteristic_ITU_R_BT_470_6_System_B_G = 5,
  1036. heif_transfer_characteristic_ITU_R_BT_601_6 = 6,
  1037. heif_transfer_characteristic_SMPTE_240M = 7,
  1038. heif_transfer_characteristic_linear = 8,
  1039. heif_transfer_characteristic_logarithmic_100 = 9,
  1040. heif_transfer_characteristic_logarithmic_100_sqrt10 = 10,
  1041. heif_transfer_characteristic_IEC_61966_2_4 = 11,
  1042. heif_transfer_characteristic_ITU_R_BT_1361 = 12,
  1043. heif_transfer_characteristic_IEC_61966_2_1 = 13,
  1044. heif_transfer_characteristic_ITU_R_BT_2020_2_10bit = 14,
  1045. heif_transfer_characteristic_ITU_R_BT_2020_2_12bit = 15,
  1046. heif_transfer_characteristic_ITU_R_BT_2100_0_PQ = 16,
  1047. heif_transfer_characteristic_SMPTE_ST_428_1 = 17,
  1048. heif_transfer_characteristic_ITU_R_BT_2100_0_HLG = 18
  1049. };
  1050. enum heif_matrix_coefficients
  1051. {
  1052. heif_matrix_coefficients_RGB_GBR = 0,
  1053. heif_matrix_coefficients_ITU_R_BT_709_5 = 1, // TODO: or 709-6 according to h.273
  1054. heif_matrix_coefficients_unspecified = 2,
  1055. heif_matrix_coefficients_US_FCC_T47 = 4,
  1056. heif_matrix_coefficients_ITU_R_BT_470_6_System_B_G = 5,
  1057. heif_matrix_coefficients_ITU_R_BT_601_6 = 6, // TODO: or 601-7 according to h.273
  1058. heif_matrix_coefficients_SMPTE_240M = 7,
  1059. heif_matrix_coefficients_YCgCo = 8,
  1060. heif_matrix_coefficients_ITU_R_BT_2020_2_non_constant_luminance = 9,
  1061. heif_matrix_coefficients_ITU_R_BT_2020_2_constant_luminance = 10,
  1062. heif_matrix_coefficients_SMPTE_ST_2085 = 11,
  1063. heif_matrix_coefficients_chromaticity_derived_non_constant_luminance = 12,
  1064. heif_matrix_coefficients_chromaticity_derived_constant_luminance = 13,
  1065. heif_matrix_coefficients_ICtCp = 14
  1066. };
  1067. struct heif_color_profile_nclx
  1068. {
  1069. // === version 1 fields
  1070. uint8_t version;
  1071. enum heif_color_primaries color_primaries;
  1072. enum heif_transfer_characteristics transfer_characteristics;
  1073. enum heif_matrix_coefficients matrix_coefficients;
  1074. uint8_t full_range_flag;
  1075. // --- decoded values (not used when saving nclx)
  1076. float color_primary_red_x, color_primary_red_y;
  1077. float color_primary_green_x, color_primary_green_y;
  1078. float color_primary_blue_x, color_primary_blue_y;
  1079. float color_primary_white_x, color_primary_white_y;
  1080. };
  1081. LIBHEIF_API
  1082. struct heif_error heif_nclx_color_profile_set_color_primaries(struct heif_color_profile_nclx* nclx, uint16_t cp);
  1083. LIBHEIF_API
  1084. struct heif_error heif_nclx_color_profile_set_transfer_characteristics(struct heif_color_profile_nclx* nclx, uint16_t transfer_characteristics);
  1085. LIBHEIF_API
  1086. struct heif_error heif_nclx_color_profile_set_matrix_coefficients(struct heif_color_profile_nclx* nclx, uint16_t matrix_coefficients);
  1087. // Returns 'heif_error_Color_profile_does_not_exist' when there is no NCLX profile.
  1088. // TODO: This function does currently not return an NCLX profile if it is stored in the image bitstream.
  1089. // Only NCLX profiles stored as colr boxes are returned. This may change in the future.
  1090. LIBHEIF_API
  1091. struct heif_error heif_image_handle_get_nclx_color_profile(const struct heif_image_handle* handle,
  1092. struct heif_color_profile_nclx** out_data);
  1093. // Returned color profile has 'version' field set to the maximum allowed.
  1094. // Do not fill values for higher versions as these might be outside the allocated structure size.
  1095. // May return NULL.
  1096. LIBHEIF_API
  1097. struct heif_color_profile_nclx* heif_nclx_color_profile_alloc(void);
  1098. LIBHEIF_API
  1099. void heif_nclx_color_profile_free(struct heif_color_profile_nclx* nclx_profile);
  1100. LIBHEIF_API
  1101. enum heif_color_profile_type heif_image_get_color_profile_type(const struct heif_image* image);
  1102. LIBHEIF_API
  1103. size_t heif_image_get_raw_color_profile_size(const struct heif_image* image);
  1104. LIBHEIF_API
  1105. struct heif_error heif_image_get_raw_color_profile(const struct heif_image* image,
  1106. void* out_data);
  1107. LIBHEIF_API
  1108. struct heif_error heif_image_get_nclx_color_profile(const struct heif_image* image,
  1109. struct heif_color_profile_nclx** out_data);
  1110. // ------------------------- intrinsic and extrinsic matrices -------------------------
  1111. struct heif_camera_intrinsic_matrix
  1112. {
  1113. double focal_length_x;
  1114. double focal_length_y;
  1115. double principal_point_x;
  1116. double principal_point_y;
  1117. double skew;
  1118. };
  1119. LIBHEIF_API
  1120. int heif_image_handle_has_camera_intrinsic_matrix(const struct heif_image_handle* handle);
  1121. LIBHEIF_API
  1122. struct heif_error heif_image_handle_get_camera_intrinsic_matrix(const struct heif_image_handle* handle,
  1123. struct heif_camera_intrinsic_matrix* out_matrix);
  1124. struct heif_camera_extrinsic_matrix;
  1125. LIBHEIF_API
  1126. int heif_image_handle_has_camera_extrinsic_matrix(const struct heif_image_handle* handle);
  1127. LIBHEIF_API
  1128. struct heif_error heif_image_handle_get_camera_extrinsic_matrix(const struct heif_image_handle* handle,
  1129. struct heif_camera_extrinsic_matrix** out_matrix);
  1130. LIBHEIF_API
  1131. void heif_camera_extrinsic_matrix_release(struct heif_camera_extrinsic_matrix*);
  1132. LIBHEIF_API
  1133. struct heif_error heif_camera_extrinsic_matrix_get_rotation_matrix(const struct heif_camera_extrinsic_matrix*,
  1134. double* out_matrix_row_major);
  1135. // ========================= heif_image =========================
  1136. // An heif_image contains a decoded pixel image in various colorspaces, chroma formats,
  1137. // and bit depths.
  1138. // Note: when converting images to an interleaved chroma format, the resulting
  1139. // image contains only a single channel of type channel_interleaved with, e.g., 3 bytes per pixel,
  1140. // containing the interleaved R,G,B values.
  1141. // Planar RGB images are specified as heif_colorspace_RGB / heif_chroma_444.
  1142. enum heif_progress_step
  1143. {
  1144. heif_progress_step_total = 0,
  1145. heif_progress_step_load_tile = 1
  1146. };
  1147. enum heif_chroma_downsampling_algorithm
  1148. {
  1149. heif_chroma_downsampling_nearest_neighbor = 1,
  1150. heif_chroma_downsampling_average = 2,
  1151. // Combine with 'heif_chroma_upsampling_bilinear' for best quality.
  1152. // Makes edges look sharper when using YUV 420 with bilinear chroma upsampling.
  1153. heif_chroma_downsampling_sharp_yuv = 3
  1154. };
  1155. enum heif_chroma_upsampling_algorithm
  1156. {
  1157. heif_chroma_upsampling_nearest_neighbor = 1,
  1158. heif_chroma_upsampling_bilinear = 2
  1159. };
  1160. struct heif_color_conversion_options
  1161. {
  1162. uint8_t version;
  1163. // --- version 1 options
  1164. enum heif_chroma_downsampling_algorithm preferred_chroma_downsampling_algorithm;
  1165. enum heif_chroma_upsampling_algorithm preferred_chroma_upsampling_algorithm;
  1166. // When set to 'false' libheif may also use a different algorithm if the preferred one is not available
  1167. // or using a different algorithm is computationally less complex. Note that currently (v1.17.0) this
  1168. // means that for RGB input it will usually choose nearest-neighbor sampling because this is computationally
  1169. // the simplest.
  1170. // Set this field to 'true' if you want to make sure that the specified algorithm is used even
  1171. // at the cost of slightly higher computation times.
  1172. uint8_t only_use_preferred_chroma_algorithm;
  1173. };
  1174. struct heif_decoding_options
  1175. {
  1176. uint8_t version;
  1177. // version 1 options
  1178. // Ignore geometric transformations like cropping, rotation, mirroring.
  1179. // Default: false (do not ignore).
  1180. uint8_t ignore_transformations;
  1181. void (* start_progress)(enum heif_progress_step step, int max_progress, void* progress_user_data);
  1182. void (* on_progress)(enum heif_progress_step step, int progress, void* progress_user_data);
  1183. void (* end_progress)(enum heif_progress_step step, void* progress_user_data);
  1184. void* progress_user_data;
  1185. // version 2 options
  1186. uint8_t convert_hdr_to_8bit;
  1187. // version 3 options
  1188. // When enabled, an error is returned for invalid input. Otherwise, it will try its best and
  1189. // add decoding warnings to the decoded heif_image. Default is non-strict.
  1190. uint8_t strict_decoding;
  1191. // version 4 options
  1192. // name_id of the decoder to use for the decoding.
  1193. // If set to NULL (default), the highest priority decoder is chosen.
  1194. // The priority is defined in the plugin.
  1195. const char* decoder_id;
  1196. // version 5 options
  1197. struct heif_color_conversion_options color_conversion_options;
  1198. };
  1199. // Allocate decoding options and fill with default values.
  1200. // Note: you should always get the decoding options through this function since the
  1201. // option structure may grow in size in future versions.
  1202. LIBHEIF_API
  1203. struct heif_decoding_options* heif_decoding_options_alloc(void);
  1204. LIBHEIF_API
  1205. void heif_decoding_options_free(struct heif_decoding_options*);
  1206. // Decode an heif_image_handle into the actual pixel image and also carry out
  1207. // all geometric transformations specified in the HEIF file (rotation, cropping, mirroring).
  1208. //
  1209. // If colorspace or chroma is set to heif_colorspace_undefined or heif_chroma_undefined,
  1210. // respectively, the original colorspace is taken.
  1211. // Decoding options may be NULL. If you want to supply options, always use
  1212. // heif_decoding_options_alloc() to get the structure.
  1213. LIBHEIF_API
  1214. struct heif_error heif_decode_image(const struct heif_image_handle* in_handle,
  1215. struct heif_image** out_img,
  1216. enum heif_colorspace colorspace,
  1217. enum heif_chroma chroma,
  1218. const struct heif_decoding_options* options);
  1219. // Get the colorspace format of the image.
  1220. LIBHEIF_API
  1221. enum heif_colorspace heif_image_get_colorspace(const struct heif_image*);
  1222. // Get the chroma format of the image.
  1223. LIBHEIF_API
  1224. enum heif_chroma heif_image_get_chroma_format(const struct heif_image*);
  1225. /**
  1226. * Get the width of a specified image channel.
  1227. *
  1228. * @param img the image to get the width for
  1229. * @param channel the channel to select
  1230. * @return the width of the channel in pixels, or -1 the channel does not exist in the image
  1231. */
  1232. LIBHEIF_API
  1233. int heif_image_get_width(const struct heif_image* img, enum heif_channel channel);
  1234. /**
  1235. * Get the height of a specified image channel.
  1236. *
  1237. * @param img the image to get the height for
  1238. * @param channel the channel to select
  1239. * @return the height of the channel in pixels, or -1 the channel does not exist in the image
  1240. */
  1241. LIBHEIF_API
  1242. int heif_image_get_height(const struct heif_image* img, enum heif_channel channel);
  1243. /**
  1244. * Get the width of the main channel.
  1245. *
  1246. * This is the Y channel in YCbCr or mono, or any in RGB.
  1247. *
  1248. * @param img the image to get the primary width for
  1249. * @return the width in pixels
  1250. */
  1251. LIBHEIF_API
  1252. int heif_image_get_primary_width(const struct heif_image* img);
  1253. /**
  1254. * Get the height of the main channel.
  1255. *
  1256. * This is the Y channel in YCbCr or mono, or any in RGB.
  1257. *
  1258. * @param img the image to get the primary height for
  1259. * @return the height in pixels
  1260. */
  1261. LIBHEIF_API
  1262. int heif_image_get_primary_height(const struct heif_image* img);
  1263. LIBHEIF_API
  1264. struct heif_error heif_image_crop(struct heif_image* img,
  1265. int left, int right, int top, int bottom);
  1266. // Get the number of bits per pixel in the given image channel. Returns -1 if
  1267. // a non-existing channel was given.
  1268. // Note that the number of bits per pixel may be different for each color channel.
  1269. // This function returns the number of bits used for storage of each pixel.
  1270. // Especially for HDR images, this is probably not what you want. Have a look at
  1271. // heif_image_get_bits_per_pixel_range() instead.
  1272. LIBHEIF_API
  1273. int heif_image_get_bits_per_pixel(const struct heif_image*, enum heif_channel channel);
  1274. // Get the number of bits per pixel in the given image channel. This function returns
  1275. // the number of bits used for representing the pixel value, which might be smaller
  1276. // than the number of bits used in memory.
  1277. // For example, in 12bit HDR images, this function returns '12', while still 16 bits
  1278. // are reserved for storage. For interleaved RGBA with 12 bit, this function also returns
  1279. // '12', not '48' or '64' (heif_image_get_bits_per_pixel returns 64 in this case).
  1280. LIBHEIF_API
  1281. int heif_image_get_bits_per_pixel_range(const struct heif_image*, enum heif_channel channel);
  1282. LIBHEIF_API
  1283. int heif_image_has_channel(const struct heif_image*, enum heif_channel channel);
  1284. // Get a pointer to the actual pixel data.
  1285. // The 'out_stride' is returned as "bytes per line".
  1286. // When out_stride is NULL, no value will be written.
  1287. // Returns NULL if a non-existing channel was given.
  1288. LIBHEIF_API
  1289. const uint8_t* heif_image_get_plane_readonly(const struct heif_image*,
  1290. enum heif_channel channel,
  1291. int* out_stride);
  1292. LIBHEIF_API
  1293. uint8_t* heif_image_get_plane(struct heif_image*,
  1294. enum heif_channel channel,
  1295. int* out_stride);
  1296. struct heif_scaling_options;
  1297. // Currently, heif_scaling_options is not defined yet. Pass a NULL pointer.
  1298. LIBHEIF_API
  1299. struct heif_error heif_image_scale_image(const struct heif_image* input,
  1300. struct heif_image** output,
  1301. int width, int height,
  1302. const struct heif_scaling_options* options);
  1303. // The color profile is not attached to the image handle because we might need it
  1304. // for color space transform and encoding.
  1305. LIBHEIF_API
  1306. struct heif_error heif_image_set_raw_color_profile(struct heif_image* image,
  1307. const char* profile_type_fourcc_string,
  1308. const void* profile_data,
  1309. const size_t profile_size);
  1310. LIBHEIF_API
  1311. struct heif_error heif_image_set_nclx_color_profile(struct heif_image* image,
  1312. const struct heif_color_profile_nclx* color_profile);
  1313. // TODO: this function does not make any sense yet, since we currently cannot modify existing HEIF files.
  1314. //LIBHEIF_API
  1315. //void heif_image_remove_color_profile(struct heif_image* image);
  1316. // Fills the image decoding warnings into the provided 'out_warnings' array.
  1317. // The size of the array has to be provided in max_output_buffer_entries.
  1318. // If max_output_buffer_entries==0, the number of decoder warnings is returned.
  1319. // The function fills the warnings into the provided buffer, starting with 'first_warning_idx'.
  1320. // It returns the number of warnings filled into the buffer.
  1321. // Note: you can iterate through all warnings by using 'max_output_buffer_entries=1' and iterate 'first_warning_idx'.
  1322. LIBHEIF_API
  1323. int heif_image_get_decoding_warnings(struct heif_image* image,
  1324. int first_warning_idx,
  1325. struct heif_error* out_warnings,
  1326. int max_output_buffer_entries);
  1327. // This function is only for decoder plugin implementors.
  1328. LIBHEIF_API
  1329. void heif_image_add_decoding_warning(struct heif_image* image,
  1330. struct heif_error err);
  1331. // Release heif_image.
  1332. LIBHEIF_API
  1333. void heif_image_release(const struct heif_image*);
  1334. // Note: a value of 0 for any of these values indicates that the value is undefined.
  1335. // The unit of these values is Candelas per square meter.
  1336. struct heif_content_light_level
  1337. {
  1338. uint16_t max_content_light_level;
  1339. uint16_t max_pic_average_light_level;
  1340. };
  1341. LIBHEIF_API
  1342. int heif_image_has_content_light_level(const struct heif_image*);
  1343. LIBHEIF_API
  1344. void heif_image_get_content_light_level(const struct heif_image*, struct heif_content_light_level* out);
  1345. LIBHEIF_API
  1346. void heif_image_set_content_light_level(const struct heif_image*, const struct heif_content_light_level* in);
  1347. // Note: color coordinates are defined according to the CIE 1931 definition of x as specified in ISO 11664-1 (see also ISO 11664-3 and CIE 15).
  1348. struct heif_mastering_display_colour_volume
  1349. {
  1350. uint16_t display_primaries_x[3];
  1351. uint16_t display_primaries_y[3];
  1352. uint16_t white_point_x;
  1353. uint16_t white_point_y;
  1354. uint32_t max_display_mastering_luminance;
  1355. uint32_t min_display_mastering_luminance;
  1356. };
  1357. // The units for max_display_mastering_luminance and min_display_mastering_luminance is Candelas per square meter.
  1358. struct heif_decoded_mastering_display_colour_volume
  1359. {
  1360. float display_primaries_x[3];
  1361. float display_primaries_y[3];
  1362. float white_point_x;
  1363. float white_point_y;
  1364. double max_display_mastering_luminance;
  1365. double min_display_mastering_luminance;
  1366. };
  1367. LIBHEIF_API
  1368. int heif_image_has_mastering_display_colour_volume(const struct heif_image*);
  1369. LIBHEIF_API
  1370. void heif_image_get_mastering_display_colour_volume(const struct heif_image*, struct heif_mastering_display_colour_volume* out);
  1371. LIBHEIF_API
  1372. void heif_image_set_mastering_display_colour_volume(const struct heif_image*, const struct heif_mastering_display_colour_volume* in);
  1373. // Converts the internal numeric representation of heif_mastering_display_colour_volume to the
  1374. // normalized values, collected in heif_decoded_mastering_display_colour_volume.
  1375. // Values that are out-of-range are decoded to 0, indicating an undefined value (as specified in ISO/IEC 23008-2).
  1376. LIBHEIF_API
  1377. struct heif_error heif_mastering_display_colour_volume_decode(const struct heif_mastering_display_colour_volume* in,
  1378. struct heif_decoded_mastering_display_colour_volume* out);
  1379. LIBHEIF_API
  1380. void heif_image_get_pixel_aspect_ratio(const struct heif_image*, uint32_t* aspect_h, uint32_t* aspect_v);
  1381. LIBHEIF_API
  1382. void heif_image_set_pixel_aspect_ratio(struct heif_image*, uint32_t aspect_h, uint32_t aspect_v);
  1383. // ====================================================================================================
  1384. // Encoding API
  1385. LIBHEIF_API
  1386. struct heif_error heif_context_write_to_file(struct heif_context*,
  1387. const char* filename);
  1388. struct heif_writer
  1389. {
  1390. // API version supported by this writer
  1391. int writer_api_version;
  1392. // --- version 1 functions ---
  1393. struct heif_error (* write)(struct heif_context* ctx, // TODO: why do we need this parameter?
  1394. const void* data,
  1395. size_t size,
  1396. void* userdata);
  1397. };
  1398. LIBHEIF_API
  1399. struct heif_error heif_context_write(struct heif_context*,
  1400. struct heif_writer* writer,
  1401. void* userdata);
  1402. // Add a compatible brand that is now added automatically by libheif when encoding images (e.g. some application brands like 'geo1').
  1403. LIBHEIF_API
  1404. void heif_context_add_compatible_brand(struct heif_context* ctx,
  1405. heif_brand2 compatible_brand);
  1406. // ----- encoder -----
  1407. // The encoder used for actually encoding an image.
  1408. struct heif_encoder;
  1409. // A description of the encoder's capabilities and name.
  1410. struct heif_encoder_descriptor;
  1411. // A configuration parameter of the encoder. Each encoder implementation may have a different
  1412. // set of parameters. For the most common settings (e.q. quality), special functions to set
  1413. // the parameters are provided.
  1414. struct heif_encoder_parameter;
  1415. struct heif_decoder_descriptor;
  1416. // Get a list of available decoders. You can filter the encoders by compression format.
  1417. // Use format_filter==heif_compression_undefined to get all available decoders.
  1418. // The returned list of decoders is sorted by their priority (which is a plugin property).
  1419. // The number of decoders is returned, which are not more than 'count' if (out_decoders != nullptr).
  1420. // By setting out_decoders==nullptr, you can query the number of decoders, 'count' is ignored.
  1421. LIBHEIF_API
  1422. int heif_get_decoder_descriptors(enum heif_compression_format format_filter,
  1423. const struct heif_decoder_descriptor** out_decoders,
  1424. int count);
  1425. // Return a long, descriptive name of the decoder (including version information).
  1426. LIBHEIF_API
  1427. const char* heif_decoder_descriptor_get_name(const struct heif_decoder_descriptor*);
  1428. // Return a short, symbolic name for identifying the decoder.
  1429. // This name should stay constant over different decoder versions.
  1430. // Note: the returned ID may be NULL for old plugins that don't support this yet.
  1431. LIBHEIF_API
  1432. const char* heif_decoder_descriptor_get_id_name(const struct heif_decoder_descriptor*);
  1433. // DEPRECATED: use heif_get_encoder_descriptors() instead.
  1434. // Get a list of available encoders. You can filter the encoders by compression format and name.
  1435. // Use format_filter==heif_compression_undefined and name_filter==NULL as wildcards.
  1436. // The returned list of encoders is sorted by their priority (which is a plugin property).
  1437. // The number of encoders is returned, which are not more than 'count' if (out_encoders != nullptr).
  1438. // By setting out_encoders==nullptr, you can query the number of encoders, 'count' is ignored.
  1439. // Note: to get the actual encoder from the descriptors returned here, use heif_context_get_encoder().
  1440. LIBHEIF_API
  1441. int heif_context_get_encoder_descriptors(struct heif_context*, // TODO: why do we need this parameter?
  1442. enum heif_compression_format format_filter,
  1443. const char* name_filter,
  1444. const struct heif_encoder_descriptor** out_encoders,
  1445. int count);
  1446. // Get a list of available encoders. You can filter the encoders by compression format and name.
  1447. // Use format_filter==heif_compression_undefined and name_filter==NULL as wildcards.
  1448. // The returned list of encoders is sorted by their priority (which is a plugin property).
  1449. // The number of encoders is returned, which are not more than 'count' if (out_encoders != nullptr).
  1450. // By setting out_encoders==nullptr, you can query the number of encoders, 'count' is ignored.
  1451. // Note: to get the actual encoder from the descriptors returned here, use heif_context_get_encoder().
  1452. LIBHEIF_API
  1453. int heif_get_encoder_descriptors(enum heif_compression_format format_filter,
  1454. const char* name_filter,
  1455. const struct heif_encoder_descriptor** out_encoders,
  1456. int count);
  1457. // Return a long, descriptive name of the encoder (including version information).
  1458. LIBHEIF_API
  1459. const char* heif_encoder_descriptor_get_name(const struct heif_encoder_descriptor*);
  1460. // Return a short, symbolic name for identifying the encoder.
  1461. // This name should stay constant over different encoder versions.
  1462. LIBHEIF_API
  1463. const char* heif_encoder_descriptor_get_id_name(const struct heif_encoder_descriptor*);
  1464. LIBHEIF_API
  1465. enum heif_compression_format
  1466. heif_encoder_descriptor_get_compression_format(const struct heif_encoder_descriptor*);
  1467. LIBHEIF_API
  1468. int heif_encoder_descriptor_supports_lossy_compression(const struct heif_encoder_descriptor*);
  1469. LIBHEIF_API
  1470. int heif_encoder_descriptor_supports_lossless_compression(const struct heif_encoder_descriptor*);
  1471. // Get an encoder instance that can be used to actually encode images from a descriptor.
  1472. LIBHEIF_API
  1473. struct heif_error heif_context_get_encoder(struct heif_context* context,
  1474. const struct heif_encoder_descriptor*,
  1475. struct heif_encoder** out_encoder);
  1476. // Quick check whether there is a decoder available for the given format.
  1477. // Note that the decoder still may not be able to decode all variants of that format.
  1478. // You will have to query that further (todo) or just try to decode and check the returned error.
  1479. LIBHEIF_API
  1480. int heif_have_decoder_for_format(enum heif_compression_format format);
  1481. // Quick check whether there is an enoder available for the given format.
  1482. // Note that the encoder may be limited to a certain subset of features (e.g. only 8 bit, only lossy).
  1483. // You will have to query the specific capabilities further.
  1484. LIBHEIF_API
  1485. int heif_have_encoder_for_format(enum heif_compression_format format);
  1486. // Get an encoder for the given compression format. If there are several encoder plugins
  1487. // for this format, the encoder with the highest plugin priority will be returned.
  1488. LIBHEIF_API
  1489. struct heif_error heif_context_get_encoder_for_format(struct heif_context* context,
  1490. enum heif_compression_format format,
  1491. struct heif_encoder**);
  1492. // You have to release the encoder after use.
  1493. LIBHEIF_API
  1494. void heif_encoder_release(struct heif_encoder*);
  1495. // Get the encoder name from the encoder itself.
  1496. LIBHEIF_API
  1497. const char* heif_encoder_get_name(const struct heif_encoder*);
  1498. // --- Encoder Parameters ---
  1499. // Libheif supports settings parameters through specialized functions and through
  1500. // generic functions by parameter name. Sometimes, the same parameter can be set
  1501. // in both ways.
  1502. // We consider it best practice to use the generic parameter functions only in
  1503. // dynamically generated user interfaces, as no guarantees are made that some specific
  1504. // parameter names are supported by all plugins.
  1505. // Set a 'quality' factor (0-100). How this is mapped to actual encoding parameters is
  1506. // encoder dependent.
  1507. LIBHEIF_API
  1508. struct heif_error heif_encoder_set_lossy_quality(struct heif_encoder*, int quality);
  1509. LIBHEIF_API
  1510. struct heif_error heif_encoder_set_lossless(struct heif_encoder*, int enable);
  1511. // level should be between 0 (= none) to 4 (= full)
  1512. LIBHEIF_API
  1513. struct heif_error heif_encoder_set_logging_level(struct heif_encoder*, int level);
  1514. // Get a generic list of encoder parameters.
  1515. // Each encoder may define its own, additional set of parameters.
  1516. // You do not have to free the returned list.
  1517. LIBHEIF_API
  1518. const struct heif_encoder_parameter* const* heif_encoder_list_parameters(struct heif_encoder*);
  1519. // Return the parameter name.
  1520. LIBHEIF_API
  1521. const char* heif_encoder_parameter_get_name(const struct heif_encoder_parameter*);
  1522. enum heif_encoder_parameter_type
  1523. {
  1524. heif_encoder_parameter_type_integer = 1,
  1525. heif_encoder_parameter_type_boolean = 2,
  1526. heif_encoder_parameter_type_string = 3
  1527. };
  1528. // Return the parameter type.
  1529. LIBHEIF_API
  1530. enum heif_encoder_parameter_type heif_encoder_parameter_get_type(const struct heif_encoder_parameter*);
  1531. // DEPRECATED. Use heif_encoder_parameter_get_valid_integer_values() instead.
  1532. LIBHEIF_API
  1533. struct heif_error heif_encoder_parameter_get_valid_integer_range(const struct heif_encoder_parameter*,
  1534. int* have_minimum_maximum,
  1535. int* minimum, int* maximum);
  1536. // If integer is limited by a range, have_minimum and/or have_maximum will be != 0 and *minimum, *maximum is set.
  1537. // If integer is limited by a fixed set of values, *num_valid_values will be >0 and *out_integer_array is set.
  1538. LIBHEIF_API
  1539. struct heif_error heif_encoder_parameter_get_valid_integer_values(const struct heif_encoder_parameter*,
  1540. int* have_minimum, int* have_maximum,
  1541. int* minimum, int* maximum,
  1542. int* num_valid_values,
  1543. const int** out_integer_array);
  1544. LIBHEIF_API
  1545. struct heif_error heif_encoder_parameter_get_valid_string_values(const struct heif_encoder_parameter*,
  1546. const char* const** out_stringarray);
  1547. LIBHEIF_API
  1548. struct heif_error heif_encoder_set_parameter_integer(struct heif_encoder*,
  1549. const char* parameter_name,
  1550. int value);
  1551. LIBHEIF_API
  1552. struct heif_error heif_encoder_get_parameter_integer(struct heif_encoder*,
  1553. const char* parameter_name,
  1554. int* value);
  1555. // TODO: name should be changed to heif_encoder_get_valid_integer_parameter_range
  1556. LIBHEIF_API // DEPRECATED.
  1557. struct heif_error heif_encoder_parameter_integer_valid_range(struct heif_encoder*,
  1558. const char* parameter_name,
  1559. int* have_minimum_maximum,
  1560. int* minimum, int* maximum);
  1561. LIBHEIF_API
  1562. struct heif_error heif_encoder_set_parameter_boolean(struct heif_encoder*,
  1563. const char* parameter_name,
  1564. int value);
  1565. LIBHEIF_API
  1566. struct heif_error heif_encoder_get_parameter_boolean(struct heif_encoder*,
  1567. const char* parameter_name,
  1568. int* value);
  1569. LIBHEIF_API
  1570. struct heif_error heif_encoder_set_parameter_string(struct heif_encoder*,
  1571. const char* parameter_name,
  1572. const char* value);
  1573. LIBHEIF_API
  1574. struct heif_error heif_encoder_get_parameter_string(struct heif_encoder*,
  1575. const char* parameter_name,
  1576. char* value, int value_size);
  1577. // returns a NULL-terminated list of valid strings or NULL if all values are allowed
  1578. LIBHEIF_API
  1579. struct heif_error heif_encoder_parameter_string_valid_values(struct heif_encoder*,
  1580. const char* parameter_name,
  1581. const char* const** out_stringarray);
  1582. LIBHEIF_API
  1583. struct heif_error heif_encoder_parameter_integer_valid_values(struct heif_encoder*,
  1584. const char* parameter_name,
  1585. int* have_minimum, int* have_maximum,
  1586. int* minimum, int* maximum,
  1587. int* num_valid_values,
  1588. const int** out_integer_array);
  1589. // Set a parameter of any type to the string value.
  1590. // Integer values are parsed from the string.
  1591. // Boolean values can be "true"/"false"/"1"/"0"
  1592. //
  1593. // x265 encoder specific note:
  1594. // When using the x265 encoder, you may pass any of its parameters by
  1595. // prefixing the parameter name with 'x265:'. Hence, to set the 'ctu' parameter,
  1596. // you will have to set 'x265:ctu' in libheif.
  1597. // Note that there is no checking for valid parameters when using the prefix.
  1598. LIBHEIF_API
  1599. struct heif_error heif_encoder_set_parameter(struct heif_encoder*,
  1600. const char* parameter_name,
  1601. const char* value);
  1602. // Get the current value of a parameter of any type as a human readable string.
  1603. // The returned string is compatible with heif_encoder_set_parameter().
  1604. LIBHEIF_API
  1605. struct heif_error heif_encoder_get_parameter(struct heif_encoder*,
  1606. const char* parameter_name,
  1607. char* value_ptr, int value_size);
  1608. // Query whether a specific parameter has a default value.
  1609. LIBHEIF_API
  1610. int heif_encoder_has_default(struct heif_encoder*,
  1611. const char* parameter_name);
  1612. // The orientation values are defined equal to the EXIF Orientation tag.
  1613. enum heif_orientation
  1614. {
  1615. heif_orientation_normal = 1,
  1616. heif_orientation_flip_horizontally = 2,
  1617. heif_orientation_rotate_180 = 3,
  1618. heif_orientation_flip_vertically = 4,
  1619. heif_orientation_rotate_90_cw_then_flip_horizontally = 5,
  1620. heif_orientation_rotate_90_cw = 6,
  1621. heif_orientation_rotate_90_cw_then_flip_vertically = 7,
  1622. heif_orientation_rotate_270_cw = 8
  1623. };
  1624. struct heif_encoding_options
  1625. {
  1626. uint8_t version;
  1627. // version 1 options
  1628. uint8_t save_alpha_channel; // default: true
  1629. // version 2 options
  1630. // DEPRECATED. This option is not required anymore. Its value will be ignored.
  1631. uint8_t macOS_compatibility_workaround;
  1632. // version 3 options
  1633. uint8_t save_two_colr_boxes_when_ICC_and_nclx_available; // default: false
  1634. // version 4 options
  1635. // Set this to the NCLX parameters to be used in the output image or set to NULL
  1636. // when the same parameters as in the input image should be used.
  1637. struct heif_color_profile_nclx* output_nclx_profile;
  1638. uint8_t macOS_compatibility_workaround_no_nclx_profile;
  1639. // version 5 options
  1640. // libheif will generate irot/imir boxes to match these orientations
  1641. enum heif_orientation image_orientation;
  1642. // version 6 options
  1643. struct heif_color_conversion_options color_conversion_options;
  1644. // version 7 options
  1645. // Set this to true to use compressed form of uncC where possible
  1646. uint8_t prefer_uncC_short_form;
  1647. };
  1648. LIBHEIF_API
  1649. struct heif_encoding_options* heif_encoding_options_alloc(void);
  1650. LIBHEIF_API
  1651. void heif_encoding_options_free(struct heif_encoding_options*);
  1652. // Compress the input image.
  1653. // Returns a handle to the coded image in 'out_image_handle' unless out_image_handle = NULL.
  1654. // 'options' should be NULL for now.
  1655. // The first image added to the context is also automatically set the primary image, but
  1656. // you can change the primary image later with heif_context_set_primary_image().
  1657. LIBHEIF_API
  1658. struct heif_error heif_context_encode_image(struct heif_context*,
  1659. const struct heif_image* image,
  1660. struct heif_encoder* encoder,
  1661. const struct heif_encoding_options* options,
  1662. struct heif_image_handle** out_image_handle);
  1663. /**
  1664. * @brief Encodes an array of images into a grid.
  1665. *
  1666. * @param ctx The file context
  1667. * @param tiles User allocated array of images that will form the grid.
  1668. * @param rows The number of rows in the grid.
  1669. * @param columns The number of columns in the grid.
  1670. * @param encoder Defines the encoder to use. See heif_context_get_encoder_for_format()
  1671. * @param input_options Optional, may be nullptr.
  1672. * @param out_image_handle Returns a handle to the grid. The caller is responsible for freeing it.
  1673. * @return Returns an error if ctx, tiles, or encoder is nullptr. If rows or columns is 0.
  1674. */
  1675. LIBHEIF_API
  1676. struct heif_error heif_context_encode_grid(struct heif_context* ctx,
  1677. struct heif_image** tiles,
  1678. uint16_t rows,
  1679. uint16_t columns,
  1680. struct heif_encoder* encoder,
  1681. const struct heif_encoding_options* input_options,
  1682. struct heif_image_handle** out_image_handle);
  1683. LIBHEIF_API
  1684. struct heif_error heif_context_set_primary_image(struct heif_context*,
  1685. struct heif_image_handle* image_handle);
  1686. // Encode the 'image' as a scaled down thumbnail image.
  1687. // The image is scaled down to fit into a square area of width 'bbox_size'.
  1688. // If the input image is already so small that it fits into this bounding box, no thumbnail
  1689. // image is encoded and NULL is returned in 'out_thumb_image_handle'.
  1690. // No error is returned in this case.
  1691. // The encoded thumbnail is automatically assigned to the 'master_image_handle'. Hence, you
  1692. // do not have to call heif_context_assign_thumbnail().
  1693. LIBHEIF_API
  1694. struct heif_error heif_context_encode_thumbnail(struct heif_context*,
  1695. const struct heif_image* image,
  1696. const struct heif_image_handle* master_image_handle,
  1697. struct heif_encoder* encoder,
  1698. const struct heif_encoding_options* options,
  1699. int bbox_size,
  1700. struct heif_image_handle** out_thumb_image_handle);
  1701. enum heif_metadata_compression
  1702. {
  1703. heif_metadata_compression_off = 0,
  1704. heif_metadata_compression_auto = 1,
  1705. heif_metadata_compression_unknown = 2, // only used when reading unknown method from input file
  1706. heif_metadata_compression_deflate = 3,
  1707. heif_metadata_compression_zlib = 4, // do not use for header data
  1708. heif_metadata_compression_brotli = 5
  1709. };
  1710. // Assign 'thumbnail_image' as the thumbnail image of 'master_image'.
  1711. LIBHEIF_API
  1712. struct heif_error heif_context_assign_thumbnail(struct heif_context*,
  1713. const struct heif_image_handle* master_image,
  1714. const struct heif_image_handle* thumbnail_image);
  1715. // Add EXIF metadata to an image.
  1716. LIBHEIF_API
  1717. struct heif_error heif_context_add_exif_metadata(struct heif_context*,
  1718. const struct heif_image_handle* image_handle,
  1719. const void* data, int size);
  1720. // Add XMP metadata to an image.
  1721. LIBHEIF_API
  1722. struct heif_error heif_context_add_XMP_metadata(struct heif_context*,
  1723. const struct heif_image_handle* image_handle,
  1724. const void* data, int size);
  1725. // New version of heif_context_add_XMP_metadata() with data compression (experimental).
  1726. LIBHEIF_API
  1727. struct heif_error heif_context_add_XMP_metadata2(struct heif_context*,
  1728. const struct heif_image_handle* image_handle,
  1729. const void* data, int size,
  1730. enum heif_metadata_compression compression);
  1731. // Add generic, proprietary metadata to an image. You have to specify an 'item_type' that will
  1732. // identify your metadata. 'content_type' can be an additional type, or it can be NULL.
  1733. // For example, this function can be used to add IPTC metadata (IIM stream, not XMP) to an image.
  1734. // Although not standard, we propose to store IPTC data with item type="iptc", content_type=NULL.
  1735. LIBHEIF_API
  1736. struct heif_error heif_context_add_generic_metadata(struct heif_context* ctx,
  1737. const struct heif_image_handle* image_handle,
  1738. const void* data, int size,
  1739. const char* item_type, const char* content_type);
  1740. // Add generic metadata with item_type "uri ". Items with this type do not have a content_type, but
  1741. // an item_uri_type and they have no content_encoding (they are always stored uncompressed).
  1742. LIBHEIF_API
  1743. struct heif_error heif_context_add_generic_uri_metadata(struct heif_context* ctx,
  1744. const struct heif_image_handle* image_handle,
  1745. const void* data, int size,
  1746. const char* item_uri_type,
  1747. heif_item_id* out_item_id);
  1748. // --- heif_image allocation
  1749. /**
  1750. * Create a new image of the specified resolution and colorspace.
  1751. *
  1752. * <p>This does not allocate memory for the image data. Use {@link heif_image_add_plane} to
  1753. * add the corresponding planes to match the specified {@code colorspace} and {@code chroma}.
  1754. *
  1755. * @param width the width of the image in pixels
  1756. * @param height the height of the image in pixels
  1757. * @param colorspace the colorspace of the image
  1758. * @param chroma the chroma of the image
  1759. * @param out_image pointer to pointer of the resulting image
  1760. * @return whether the creation succeeded or there was an error
  1761. */
  1762. LIBHEIF_API
  1763. struct heif_error heif_image_create(int width, int height,
  1764. enum heif_colorspace colorspace,
  1765. enum heif_chroma chroma,
  1766. struct heif_image** out_image);
  1767. /**
  1768. * Add an image plane to the image.
  1769. *
  1770. * <p>The image plane needs to match the colorspace and chroma of the image. Note
  1771. * that this does not need to be a single "planar" format - interleaved pixel channels
  1772. * can also be used if the chroma is interleaved.
  1773. *
  1774. * <p>The indicated bit_depth corresponds to the bit depth per channel. For example,
  1775. * with an interleaved format like RRGGBB where each color is represented by 10 bits,
  1776. * the {@code bit_depth} would be {@code 10} rather than {@code 30}.
  1777. *
  1778. * <p>For backward compatibility, one can also specify 24bits for RGB and 32bits for RGBA,
  1779. * instead of the preferred 8 bits. However, this use is deprecated.
  1780. *
  1781. * @param image the parent image to add the channel plane to
  1782. * @param channel the channel of the plane to add
  1783. * @param width the width of the plane
  1784. * @param height the height of the plane
  1785. * @param bit_depth the bit depth per color channel
  1786. * @return whether the addition succeeded or there was an error
  1787. *
  1788. * @note The width and height are usually the same as the parent image, but can be
  1789. * less for subsampling.
  1790. *
  1791. * @note The specified width can differ from the row stride of the resulting image plane.
  1792. * Always use the result of {@link heif_image_get_plane} or {@link heif_image_get_plane_readonly}
  1793. * to determine row stride.
  1794. */
  1795. LIBHEIF_API
  1796. struct heif_error heif_image_add_plane(struct heif_image* image,
  1797. enum heif_channel channel,
  1798. int width, int height, int bit_depth);
  1799. // Signal that the image is premultiplied by the alpha pixel values.
  1800. LIBHEIF_API
  1801. void heif_image_set_premultiplied_alpha(struct heif_image* image,
  1802. int is_premultiplied_alpha);
  1803. LIBHEIF_API
  1804. int heif_image_is_premultiplied_alpha(struct heif_image* image);
  1805. // This function extends the padding of the image so that it has at least the given physical size.
  1806. // The padding border is filled with the pixels along the right/bottom border.
  1807. // This function may be useful if you want to process the image, but have some external padding requirements.
  1808. // The image size will not be modified if it is already larger/equal than the given physical size.
  1809. // I.e. you cannot assume that after calling this function, the stride will be equal to min_physical_width.
  1810. LIBHEIF_API
  1811. struct heif_error heif_image_extend_padding_to_size(struct heif_image* image, int min_physical_width, int min_physical_height);
  1812. // --- register plugins
  1813. struct heif_decoder_plugin;
  1814. struct heif_encoder_plugin;
  1815. // DEPRECATED. Use heif_register_decoder_plugin(const struct heif_decoder_plugin*) instead.
  1816. LIBHEIF_API
  1817. struct heif_error heif_register_decoder(struct heif_context* heif, const struct heif_decoder_plugin*);
  1818. LIBHEIF_API
  1819. struct heif_error heif_register_decoder_plugin(const struct heif_decoder_plugin*);
  1820. LIBHEIF_API
  1821. struct heif_error heif_register_encoder_plugin(const struct heif_encoder_plugin*);
  1822. // DEPRECATED, typo in function name
  1823. LIBHEIF_API
  1824. int heif_encoder_descriptor_supportes_lossy_compression(const struct heif_encoder_descriptor*);
  1825. // DEPRECATED, typo in function name
  1826. LIBHEIF_API
  1827. int heif_encoder_descriptor_supportes_lossless_compression(const struct heif_encoder_descriptor*);
  1828. #ifdef __cplusplus
  1829. }
  1830. #endif
  1831. #endif