decode.h 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  1. /* Copyright (c) the JPEG XL Project Authors. All rights reserved.
  2. *
  3. * Use of this source code is governed by a BSD-style
  4. * license that can be found in the LICENSE file.
  5. */
  6. /** @addtogroup libjxl_decoder
  7. * @{
  8. * @file decode.h
  9. * @brief Decoding API for JPEG XL.
  10. */
  11. #ifndef JXL_DECODE_H_
  12. #define JXL_DECODE_H_
  13. #include <jxl/cms_interface.h>
  14. #include <jxl/codestream_header.h>
  15. #include <jxl/color_encoding.h>
  16. #include <jxl/jxl_export.h>
  17. #include <jxl/memory_manager.h>
  18. #include <jxl/parallel_runner.h>
  19. #include <jxl/types.h>
  20. #include <jxl/version.h> // TODO(eustas): remove before v1.0
  21. #include <stddef.h>
  22. #include <stdint.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /**
  27. * Decoder library version.
  28. *
  29. * @return the decoder library version as an integer:
  30. * MAJOR_VERSION * 1000000 + MINOR_VERSION * 1000 + PATCH_VERSION. For example,
  31. * version 1.2.3 would return 1002003.
  32. */
  33. JXL_EXPORT uint32_t JxlDecoderVersion(void);
  34. /** The result of @ref JxlSignatureCheck.
  35. */
  36. typedef enum {
  37. /** Not enough bytes were passed to determine if a valid signature was found.
  38. */
  39. JXL_SIG_NOT_ENOUGH_BYTES = 0,
  40. /** No valid JPEG XL header was found. */
  41. JXL_SIG_INVALID = 1,
  42. /** A valid JPEG XL codestream signature was found, that is a JPEG XL image
  43. * without container.
  44. */
  45. JXL_SIG_CODESTREAM = 2,
  46. /** A valid container signature was found, that is a JPEG XL image embedded
  47. * in a box format container.
  48. */
  49. JXL_SIG_CONTAINER = 3,
  50. } JxlSignature;
  51. /**
  52. * JPEG XL signature identification.
  53. *
  54. * Checks if the passed buffer contains a valid JPEG XL signature. The passed @p
  55. * buf of size
  56. * @p size doesn't need to be a full image, only the beginning of the file.
  57. *
  58. * @return a flag indicating if a JPEG XL signature was found and what type.
  59. * - ::JXL_SIG_NOT_ENOUGH_BYTES if not enough bytes were passed to
  60. * determine if a valid signature is there.
  61. * - ::JXL_SIG_INVALID if no valid signature found for JPEG XL decoding.
  62. * - ::JXL_SIG_CODESTREAM if a valid JPEG XL codestream signature was
  63. * found.
  64. * - ::JXL_SIG_CONTAINER if a valid JPEG XL container signature was found.
  65. */
  66. JXL_EXPORT JxlSignature JxlSignatureCheck(const uint8_t* buf, size_t len);
  67. /**
  68. * Opaque structure that holds the JPEG XL decoder.
  69. *
  70. * Allocated and initialized with @ref JxlDecoderCreate().
  71. * Cleaned up and deallocated with @ref JxlDecoderDestroy().
  72. */
  73. typedef struct JxlDecoderStruct JxlDecoder;
  74. /**
  75. * Creates an instance of @ref JxlDecoder and initializes it.
  76. *
  77. * @p memory_manager will be used for all the library dynamic allocations made
  78. * from this instance. The parameter may be NULL, in which case the default
  79. * allocator will be used. See jxl/memory_manager.h for details.
  80. *
  81. * @param memory_manager custom allocator function. It may be NULL. The memory
  82. * manager will be copied internally.
  83. * @return @c NULL if the instance can not be allocated or initialized
  84. * @return pointer to initialized @ref JxlDecoder otherwise
  85. */
  86. JXL_EXPORT JxlDecoder* JxlDecoderCreate(const JxlMemoryManager* memory_manager);
  87. /**
  88. * Re-initializes a @ref JxlDecoder instance, so it can be re-used for decoding
  89. * another image. All state and settings are reset as if the object was
  90. * newly created with @ref JxlDecoderCreate, but the memory manager is kept.
  91. *
  92. * @param dec instance to be re-initialized.
  93. */
  94. JXL_EXPORT void JxlDecoderReset(JxlDecoder* dec);
  95. /**
  96. * Deinitializes and frees @ref JxlDecoder instance.
  97. *
  98. * @param dec instance to be cleaned up and deallocated.
  99. */
  100. JXL_EXPORT void JxlDecoderDestroy(JxlDecoder* dec);
  101. /**
  102. * Return value for @ref JxlDecoderProcessInput.
  103. * The values from ::JXL_DEC_BASIC_INFO onwards are optional informative
  104. * events that can be subscribed to, they are never returned if they
  105. * have not been registered with @ref JxlDecoderSubscribeEvents.
  106. */
  107. typedef enum {
  108. /** Function call finished successfully, or decoding is finished and there is
  109. * nothing more to be done.
  110. *
  111. * Note that @ref JxlDecoderProcessInput will return ::JXL_DEC_SUCCESS if
  112. * all events that were registered with @ref JxlDecoderSubscribeEvents were
  113. * processed, even before the end of the JPEG XL codestream.
  114. *
  115. * In this case, the return value @ref JxlDecoderReleaseInput will be the same
  116. * as it was at the last signaled event. E.g. if ::JXL_DEC_FULL_IMAGE was
  117. * subscribed to, then all bytes from the end of the JPEG XL codestream
  118. * (including possible boxes needed for jpeg reconstruction) will be returned
  119. * as unprocessed.
  120. */
  121. JXL_DEC_SUCCESS = 0,
  122. /** An error occurred, for example invalid input file or out of memory.
  123. * TODO(lode): add function to get error information from decoder.
  124. */
  125. JXL_DEC_ERROR = 1,
  126. /** The decoder needs more input bytes to continue. Before the next @ref
  127. * JxlDecoderProcessInput call, more input data must be set, by calling @ref
  128. * JxlDecoderReleaseInput (if input was set previously) and then calling @ref
  129. * JxlDecoderSetInput. @ref JxlDecoderReleaseInput returns how many bytes
  130. * are not yet processed, before a next call to @ref JxlDecoderProcessInput
  131. * all unprocessed bytes must be provided again (the address need not match,
  132. * but the contents must), and more bytes must be concatenated after the
  133. * unprocessed bytes.
  134. * In most cases, @ref JxlDecoderReleaseInput will return no unprocessed bytes
  135. * at this event, the only exceptions are if the previously set input ended
  136. * within (a) the raw codestream signature, (b) the signature box, (c) a box
  137. * header, or (d) the first 4 bytes of a `brob`, `ftyp`, or `jxlp` box. In any
  138. * of these cases the number of unprocessed bytes is less than 20.
  139. */
  140. JXL_DEC_NEED_MORE_INPUT = 2,
  141. /** The decoder is able to decode a preview image and requests setting a
  142. * preview output buffer using @ref JxlDecoderSetPreviewOutBuffer. This occurs
  143. * if ::JXL_DEC_PREVIEW_IMAGE is requested and it is possible to decode a
  144. * preview image from the codestream and the preview out buffer was not yet
  145. * set. There is maximum one preview image in a codestream.
  146. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  147. * end of the frame header (including ToC) of the preview frame as
  148. * unprocessed.
  149. */
  150. JXL_DEC_NEED_PREVIEW_OUT_BUFFER = 3,
  151. /** The decoder requests an output buffer to store the full resolution image,
  152. * which can be set with @ref JxlDecoderSetImageOutBuffer or with @ref
  153. * JxlDecoderSetImageOutCallback. This event re-occurs for new frames if
  154. * there are multiple animation frames and requires setting an output again.
  155. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  156. * end of the frame header (including ToC) as unprocessed.
  157. */
  158. JXL_DEC_NEED_IMAGE_OUT_BUFFER = 5,
  159. /** The JPEG reconstruction buffer is too small for reconstructed JPEG
  160. * codestream to fit. @ref JxlDecoderSetJPEGBuffer must be called again to
  161. * make room for remaining bytes. This event may occur multiple times
  162. * after ::JXL_DEC_JPEG_RECONSTRUCTION.
  163. */
  164. JXL_DEC_JPEG_NEED_MORE_OUTPUT = 6,
  165. /** The box contents output buffer is too small. @ref JxlDecoderSetBoxBuffer
  166. * must be called again to make room for remaining bytes. This event may occur
  167. * multiple times after ::JXL_DEC_BOX.
  168. */
  169. JXL_DEC_BOX_NEED_MORE_OUTPUT = 7,
  170. /** Informative event by @ref JxlDecoderProcessInput
  171. * "JxlDecoderProcessInput": Basic information such as image dimensions and
  172. * extra channels. This event occurs max once per image.
  173. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  174. * end of the basic info as unprocessed (including the last byte of basic info
  175. * if it did not end on a byte boundary).
  176. */
  177. JXL_DEC_BASIC_INFO = 0x40,
  178. /** Informative event by @ref JxlDecoderProcessInput
  179. * "JxlDecoderProcessInput": Color encoding or ICC profile from the
  180. * codestream header. This event occurs max once per image and always later
  181. * than ::JXL_DEC_BASIC_INFO and earlier than any pixel data.
  182. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  183. * end of the image header (which is the start of the first frame) as
  184. * unprocessed.
  185. */
  186. JXL_DEC_COLOR_ENCODING = 0x100,
  187. /** Informative event by @ref JxlDecoderProcessInput
  188. * "JxlDecoderProcessInput": Preview image, a small frame, decoded. This
  189. * event can only happen if the image has a preview frame encoded. This event
  190. * occurs max once for the codestream and always later than @ref
  191. * JXL_DEC_COLOR_ENCODING and before ::JXL_DEC_FRAME.
  192. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  193. * end of the preview frame as unprocessed.
  194. */
  195. JXL_DEC_PREVIEW_IMAGE = 0x200,
  196. /** Informative event by @ref JxlDecoderProcessInput
  197. * "JxlDecoderProcessInput": Beginning of a frame. @ref
  198. * JxlDecoderGetFrameHeader can be used at this point. A note on frames:
  199. * a JPEG XL image can have internal frames that are not intended to be
  200. * displayed (e.g. used for compositing a final frame), but this only returns
  201. * displayed frames, unless @ref JxlDecoderSetCoalescing was set to @ref
  202. * JXL_FALSE "JXL_FALSE": in that case, the individual layers are returned,
  203. * without blending. Note that even when coalescing is disabled, only frames
  204. * of type kRegularFrame are returned; frames of type kReferenceOnly
  205. * and kLfFrame are always for internal purposes only and cannot be accessed.
  206. * A displayed frame either has an animation duration or is the only or last
  207. * frame in the image. This event occurs max once per displayed frame, always
  208. * later than ::JXL_DEC_COLOR_ENCODING, and always earlier than any pixel
  209. * data. While JPEG XL supports encoding a single frame as the composition of
  210. * multiple internal sub-frames also called frames, this event is not
  211. * indicated for the internal frames. In this case, @ref
  212. * JxlDecoderReleaseInput will return all bytes from the end of the frame
  213. * header (including ToC) as unprocessed.
  214. */
  215. JXL_DEC_FRAME = 0x400,
  216. /** Informative event by @ref JxlDecoderProcessInput
  217. * "JxlDecoderProcessInput": full frame (or layer, in case coalescing is
  218. * disabled) is decoded. @ref JxlDecoderSetImageOutBuffer must be used after
  219. * getting the basic image information to be able to get the image pixels, if
  220. * not this return status only indicates we're past this point in the
  221. * codestream. This event occurs max once per frame.
  222. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  223. * end of the frame (or if ::JXL_DEC_JPEG_RECONSTRUCTION is subscribed to,
  224. * from the end of the last box that is needed for jpeg reconstruction) as
  225. * unprocessed.
  226. */
  227. JXL_DEC_FULL_IMAGE = 0x1000,
  228. /** Informative event by @ref JxlDecoderProcessInput
  229. * "JxlDecoderProcessInput": JPEG reconstruction data decoded. @ref
  230. * JxlDecoderSetJPEGBuffer may be used to set a JPEG reconstruction buffer
  231. * after getting the JPEG reconstruction data. If a JPEG reconstruction buffer
  232. * is set a byte stream identical to the JPEG codestream used to encode the
  233. * image will be written to the JPEG reconstruction buffer instead of pixels
  234. * to the image out buffer. This event occurs max once per image and always
  235. * before ::JXL_DEC_FULL_IMAGE.
  236. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  237. * end of the `jbrd` box as unprocessed.
  238. */
  239. JXL_DEC_JPEG_RECONSTRUCTION = 0x2000,
  240. /** Informative event by @ref JxlDecoderProcessInput
  241. * "JxlDecoderProcessInput": The header of a box of the container format
  242. * (BMFF) is decoded. The following API functions related to boxes can be used
  243. * after this event:
  244. * - @ref JxlDecoderSetBoxBuffer and @ref JxlDecoderReleaseBoxBuffer
  245. * "JxlDecoderReleaseBoxBuffer": set and release a buffer to get the box
  246. * data.
  247. * - @ref JxlDecoderGetBoxType get the 4-character box typename.
  248. * - @ref JxlDecoderGetBoxSizeRaw get the size of the box as it appears in
  249. * the container file, not decompressed.
  250. * - @ref JxlDecoderSetDecompressBoxes to configure whether to get the box
  251. * data decompressed, or possibly compressed.
  252. *
  253. * Boxes can be compressed. This is so when their box type is
  254. * "brob". In that case, they have an underlying decompressed box
  255. * type and decompressed data. @ref JxlDecoderSetDecompressBoxes allows
  256. * configuring which data to get. Decompressing requires
  257. * Brotli. @ref JxlDecoderGetBoxType has a flag to get the compressed box
  258. * type, which can be "brob", or the decompressed box type. If a box
  259. * is not compressed (its compressed type is not "brob"), then
  260. * the output decompressed box type and data is independent of what
  261. * setting is configured.
  262. *
  263. * The buffer set with @ref JxlDecoderSetBoxBuffer must be set again for each
  264. * next box to be obtained, or can be left unset to skip outputting this box.
  265. * The output buffer contains the full box data when the
  266. * ::JXL_DEC_BOX_COMPLETE (if subscribed to) or subsequent ::JXL_DEC_SUCCESS
  267. * or ::JXL_DEC_BOX event occurs. ::JXL_DEC_BOX occurs for all boxes,
  268. * including non-metadata boxes such as the signature box or codestream boxes.
  269. * To check whether the box is a metadata type for respectively EXIF, XMP or
  270. * JUMBF, use @ref JxlDecoderGetBoxType and check for types "Exif", "xml " and
  271. * "jumb" respectively.
  272. *
  273. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  274. * start of the box header as unprocessed.
  275. */
  276. JXL_DEC_BOX = 0x4000,
  277. /** Informative event by @ref JxlDecoderProcessInput
  278. * "JxlDecoderProcessInput": a progressive step in decoding the frame is
  279. * reached. When calling @ref JxlDecoderFlushImage at this point, the flushed
  280. * image will correspond exactly to this point in decoding, and not yet
  281. * contain partial results (such as partially more fine detail) of a next
  282. * step. By default, this event will trigger maximum once per frame, when a
  283. * 8x8th resolution (DC) image is ready (the image data is still returned at
  284. * full resolution, giving upscaled DC). Use @ref
  285. * JxlDecoderSetProgressiveDetail to configure more fine-grainedness. The
  286. * event is not guaranteed to trigger, not all images have progressive steps
  287. * or DC encoded.
  288. * In this case, @ref JxlDecoderReleaseInput will return all bytes from the
  289. * end of the section that was needed to produce this progressive event as
  290. * unprocessed.
  291. */
  292. JXL_DEC_FRAME_PROGRESSION = 0x8000,
  293. /** The box being decoded is now complete. This is only emitted if a buffer
  294. * was set for the box.
  295. */
  296. JXL_DEC_BOX_COMPLETE = 0x10000,
  297. } JxlDecoderStatus;
  298. /** Types of progressive detail.
  299. * Setting a progressive detail with value N implies all progressive details
  300. * with smaller or equal value. Currently only the following level of
  301. * progressive detail is implemented:
  302. * - @ref kDC (which implies kFrames)
  303. * - @ref kLastPasses (which implies @ref kDC and @ref kFrames)
  304. * - @ref kPasses (which implies @ref kLastPasses, kDC and @ref kFrames)
  305. */
  306. typedef enum {
  307. /**
  308. * after completed kRegularFrames
  309. */
  310. kFrames = 0,
  311. /**
  312. * after completed DC (1:8)
  313. */
  314. kDC = 1,
  315. /**
  316. * after completed AC passes that are the last pass for their resolution
  317. * target.
  318. */
  319. kLastPasses = 2,
  320. /**
  321. * after completed AC passes that are not the last pass for their resolution
  322. * target.
  323. */
  324. kPasses = 3,
  325. /**
  326. * during DC frame when lower resolution are completed (1:32, 1:16)
  327. */
  328. kDCProgressive = 4,
  329. /**
  330. * after completed groups
  331. */
  332. kDCGroups = 5,
  333. /**
  334. * after completed groups
  335. */
  336. kGroups = 6,
  337. } JxlProgressiveDetail;
  338. /** Rewinds decoder to the beginning. The same input must be given again from
  339. * the beginning of the file and the decoder will emit events from the beginning
  340. * again. When rewinding (as opposed to @ref JxlDecoderReset), the decoder can
  341. * keep state about the image, which it can use to skip to a requested frame
  342. * more efficiently with @ref JxlDecoderSkipFrames. Settings such as parallel
  343. * runner or subscribed events are kept. After rewind, @ref
  344. * JxlDecoderSubscribeEvents can be used again, and it is feasible to leave out
  345. * events that were already handled before, such as ::JXL_DEC_BASIC_INFO
  346. * and ::JXL_DEC_COLOR_ENCODING, since they will provide the same information
  347. * as before.
  348. * The difference to @ref JxlDecoderReset is that some state is kept, namely
  349. * settings set by a call to
  350. * - @ref JxlDecoderSetCoalescing,
  351. * - @ref JxlDecoderSetDesiredIntensityTarget,
  352. * - @ref JxlDecoderSetDecompressBoxes,
  353. * - @ref JxlDecoderSetKeepOrientation,
  354. * - @ref JxlDecoderSetUnpremultiplyAlpha,
  355. * - @ref JxlDecoderSetParallelRunner,
  356. * - @ref JxlDecoderSetRenderSpotcolors, and
  357. * - @ref JxlDecoderSubscribeEvents.
  358. *
  359. * @param dec decoder object
  360. */
  361. JXL_EXPORT void JxlDecoderRewind(JxlDecoder* dec);
  362. /** Makes the decoder skip the next `amount` frames. It still needs to process
  363. * the input, but will not output the frame events. It can be more efficient
  364. * when skipping frames, and even more so when using this after @ref
  365. * JxlDecoderRewind. If the decoder is already processing a frame (could
  366. * have emitted ::JXL_DEC_FRAME but not yet ::JXL_DEC_FULL_IMAGE), it
  367. * starts skipping from the next frame. If the amount is larger than the amount
  368. * of frames remaining in the image, all remaining frames are skipped. Calling
  369. * this function multiple times adds the amount to skip to the already existing
  370. * amount.
  371. *
  372. * A frame here is defined as a frame that without skipping emits events such
  373. * as ::JXL_DEC_FRAME and ::JXL_DEC_FULL_IMAGE, frames that are internal
  374. * to the file format but are not rendered as part of an animation, or are not
  375. * the final still frame of a still image, are not counted.
  376. *
  377. * @param dec decoder object
  378. * @param amount the amount of frames to skip
  379. */
  380. JXL_EXPORT void JxlDecoderSkipFrames(JxlDecoder* dec, size_t amount);
  381. /**
  382. * Skips processing the current frame. Can be called after frame processing
  383. * already started, signaled by a ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event,
  384. * but before the corresponding ::JXL_DEC_FULL_IMAGE event. The next signaled
  385. * event will be another ::JXL_DEC_FRAME, or ::JXL_DEC_SUCCESS if there
  386. * are no more frames. If pixel data is required from the already processed part
  387. * of the frame, @ref JxlDecoderFlushImage must be called before this.
  388. *
  389. * @param dec decoder object
  390. * @return ::JXL_DEC_SUCCESS if there is a frame to skip, and @ref
  391. * JXL_DEC_ERROR if the function was not called during frame processing.
  392. */
  393. JXL_EXPORT JxlDecoderStatus JxlDecoderSkipCurrentFrame(JxlDecoder* dec);
  394. /**
  395. * Set the parallel runner for multithreading. May only be set before starting
  396. * decoding.
  397. *
  398. * @param dec decoder object
  399. * @param parallel_runner function pointer to runner for multithreading. It may
  400. * be NULL to use the default, single-threaded, runner. A multithreaded
  401. * runner should be set to reach fast performance.
  402. * @param parallel_runner_opaque opaque pointer for parallel_runner.
  403. * @return ::JXL_DEC_SUCCESS if the runner was set, ::JXL_DEC_ERROR
  404. * otherwise (the previous runner remains set).
  405. */
  406. JXL_EXPORT JxlDecoderStatus
  407. JxlDecoderSetParallelRunner(JxlDecoder* dec, JxlParallelRunner parallel_runner,
  408. void* parallel_runner_opaque);
  409. /**
  410. * Returns a hint indicating how many more bytes the decoder is expected to
  411. * need to make @ref JxlDecoderGetBasicInfo available after the next @ref
  412. * JxlDecoderProcessInput call. This is a suggested large enough value for
  413. * the amount of bytes to provide in the next @ref JxlDecoderSetInput call, but
  414. * it is not guaranteed to be an upper bound nor a lower bound. This number does
  415. * not include bytes that have already been released from the input. Can be used
  416. * before the first @ref JxlDecoderProcessInput call, and is correct the first
  417. * time in most cases. If not, @ref JxlDecoderSizeHintBasicInfo can be called
  418. * again to get an updated hint.
  419. *
  420. * @param dec decoder object
  421. * @return the size hint in bytes if the basic info is not yet fully decoded.
  422. * @return 0 when the basic info is already available.
  423. */
  424. JXL_EXPORT size_t JxlDecoderSizeHintBasicInfo(const JxlDecoder* dec);
  425. /** Select for which informative events, i.e. ::JXL_DEC_BASIC_INFO, etc., the
  426. * decoder should return with a status. It is not required to subscribe to any
  427. * events, data can still be requested from the decoder as soon as it available.
  428. * By default, the decoder is subscribed to no events (events_wanted == 0), and
  429. * the decoder will then only return when it cannot continue because it needs
  430. * more input data or more output buffer. This function may only be be called
  431. * before using @ref JxlDecoderProcessInput.
  432. *
  433. * @param dec decoder object
  434. * @param events_wanted bitfield of desired events.
  435. * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
  436. */
  437. JXL_EXPORT JxlDecoderStatus JxlDecoderSubscribeEvents(JxlDecoder* dec,
  438. int events_wanted);
  439. /** Enables or disables preserving of as-in-bitstream pixeldata
  440. * orientation. Some images are encoded with an Orientation tag
  441. * indicating that the decoder must perform a rotation and/or
  442. * mirroring to the encoded image data.
  443. *
  444. * - If skip_reorientation is ::JXL_FALSE (the default): the decoder
  445. * will apply the transformation from the orientation setting, hence
  446. * rendering the image according to its specified intent. When
  447. * producing a @ref JxlBasicInfo, the decoder will always set the
  448. * orientation field to JXL_ORIENT_IDENTITY (matching the returned
  449. * pixel data) and also align xsize and ysize so that they correspond
  450. * to the width and the height of the returned pixel data.
  451. * - If skip_reorientation is ::JXL_TRUE "JXL_TRUE": the decoder will skip
  452. * applying the transformation from the orientation setting, returning
  453. * the image in the as-in-bitstream pixeldata orientation.
  454. * This may be faster to decode since the decoder doesn't have to apply the
  455. * transformation, but can cause wrong display of the image if the
  456. * orientation tag is not correctly taken into account by the user.
  457. *
  458. * By default, this option is disabled, and the returned pixel data is
  459. * re-oriented according to the image's Orientation setting.
  460. *
  461. * This function must be called at the beginning, before decoding is performed.
  462. *
  463. * @see JxlBasicInfo for the orientation field, and @ref JxlOrientation for the
  464. * possible values.
  465. *
  466. * @param dec decoder object
  467. * @param skip_reorientation JXL_TRUE to enable, JXL_FALSE to disable.
  468. * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
  469. */
  470. JXL_EXPORT JxlDecoderStatus
  471. JxlDecoderSetKeepOrientation(JxlDecoder* dec, JXL_BOOL skip_reorientation);
  472. /**
  473. * Enables or disables preserving of associated alpha channels. If
  474. * unpremul_alpha is set to ::JXL_FALSE then for associated alpha channel,
  475. * the pixel data is returned with premultiplied colors. If it is set to @ref
  476. * JXL_TRUE, The colors will be unpremultiplied based on the alpha channel. This
  477. * function has no effect if the image does not have an associated alpha
  478. * channel.
  479. *
  480. * By default, this option is disabled, and the returned pixel data "as is".
  481. *
  482. * This function must be called at the beginning, before decoding is performed.
  483. *
  484. * @param dec decoder object
  485. * @param unpremul_alpha JXL_TRUE to enable, JXL_FALSE to disable.
  486. * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
  487. */
  488. JXL_EXPORT JxlDecoderStatus
  489. JxlDecoderSetUnpremultiplyAlpha(JxlDecoder* dec, JXL_BOOL unpremul_alpha);
  490. /** Enables or disables rendering spot colors. By default, spot colors
  491. * are rendered, which is OK for viewing the decoded image. If render_spotcolors
  492. * is ::JXL_FALSE, then spot colors are not rendered, and have to be
  493. * retrieved separately using @ref JxlDecoderSetExtraChannelBuffer. This is
  494. * useful for e.g. printing applications.
  495. *
  496. * @param dec decoder object
  497. * @param render_spotcolors JXL_TRUE to enable (default), JXL_FALSE to disable.
  498. * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
  499. */
  500. JXL_EXPORT JxlDecoderStatus
  501. JxlDecoderSetRenderSpotcolors(JxlDecoder* dec, JXL_BOOL render_spotcolors);
  502. /** Enables or disables coalescing of zero-duration frames. By default, frames
  503. * are returned with coalescing enabled, i.e. all frames have the image
  504. * dimensions, and are blended if needed. When coalescing is disabled, frames
  505. * can have arbitrary dimensions, a non-zero crop offset, and blending is not
  506. * performed. For display, coalescing is recommended. For loading a multi-layer
  507. * still image as separate layers (as opposed to the merged image), coalescing
  508. * has to be disabled.
  509. *
  510. * @param dec decoder object
  511. * @param coalescing JXL_TRUE to enable coalescing (default), JXL_FALSE to
  512. * disable it.
  513. * @return ::JXL_DEC_SUCCESS if no error, ::JXL_DEC_ERROR otherwise.
  514. */
  515. JXL_EXPORT JxlDecoderStatus JxlDecoderSetCoalescing(JxlDecoder* dec,
  516. JXL_BOOL coalescing);
  517. /**
  518. * Decodes JPEG XL file using the available bytes. Requires input has been
  519. * set with @ref JxlDecoderSetInput. After @ref JxlDecoderProcessInput, input
  520. * can optionally be released with @ref JxlDecoderReleaseInput and then set
  521. * again to next bytes in the stream. @ref JxlDecoderReleaseInput returns how
  522. * many bytes are not yet processed, before a next call to @ref
  523. * JxlDecoderProcessInput all unprocessed bytes must be provided again (the
  524. * address need not match, but the contents must), and more bytes may be
  525. * concatenated after the unprocessed bytes.
  526. *
  527. * The returned status indicates whether the decoder needs more input bytes, or
  528. * more output buffer for a certain type of output data. No matter what the
  529. * returned status is (other than ::JXL_DEC_ERROR), new information, such
  530. * as @ref JxlDecoderGetBasicInfo, may have become available after this call.
  531. * When the return value is not ::JXL_DEC_ERROR or ::JXL_DEC_SUCCESS, the
  532. * decoding requires more @ref JxlDecoderProcessInput calls to continue.
  533. *
  534. * @param dec decoder object
  535. * @return ::JXL_DEC_SUCCESS when decoding finished and all events handled.
  536. * If you still have more unprocessed input data anyway, then you can still
  537. * continue by using @ref JxlDecoderSetInput and calling @ref
  538. * JxlDecoderProcessInput again, similar to handling @ref
  539. * JXL_DEC_NEED_MORE_INPUT. ::JXL_DEC_SUCCESS can occur instead of @ref
  540. * JXL_DEC_NEED_MORE_INPUT when, for example, the input data ended right at
  541. * the boundary of a box of the container format, all essential codestream
  542. * boxes were already decoded, but extra metadata boxes are still present in
  543. * the next data. @ref JxlDecoderProcessInput cannot return success if all
  544. * codestream boxes have not been seen yet.
  545. * @return ::JXL_DEC_ERROR when decoding failed, e.g. invalid codestream.
  546. * TODO(lode): document the input data mechanism
  547. * @return ::JXL_DEC_NEED_MORE_INPUT when more input data is necessary.
  548. * @return ::JXL_DEC_BASIC_INFO when basic info such as image dimensions is
  549. * available and this informative event is subscribed to.
  550. * @return ::JXL_DEC_COLOR_ENCODING when color profile information is
  551. * available and this informative event is subscribed to.
  552. * @return ::JXL_DEC_PREVIEW_IMAGE when preview pixel information is
  553. * available and output in the preview buffer.
  554. * @return ::JXL_DEC_FULL_IMAGE when all pixel information at highest detail
  555. * is available and has been output in the pixel buffer.
  556. */
  557. JXL_EXPORT JxlDecoderStatus JxlDecoderProcessInput(JxlDecoder* dec);
  558. /**
  559. * Sets input data for @ref JxlDecoderProcessInput. The data is owned by the
  560. * caller and may be used by the decoder until @ref JxlDecoderReleaseInput is
  561. * called or the decoder is destroyed or reset so must be kept alive until then.
  562. * Cannot be called if @ref JxlDecoderSetInput was already called and @ref
  563. * JxlDecoderReleaseInput was not yet called, and cannot be called after @ref
  564. * JxlDecoderCloseInput indicating the end of input was called.
  565. *
  566. * @param dec decoder object
  567. * @param data pointer to next bytes to read from
  568. * @param size amount of bytes available starting from data
  569. * @return ::JXL_DEC_ERROR if input was already set without releasing or @ref
  570. * JxlDecoderCloseInput was already called, ::JXL_DEC_SUCCESS otherwise.
  571. */
  572. JXL_EXPORT JxlDecoderStatus JxlDecoderSetInput(JxlDecoder* dec,
  573. const uint8_t* data,
  574. size_t size);
  575. /**
  576. * Releases input which was provided with @ref JxlDecoderSetInput. Between @ref
  577. * JxlDecoderProcessInput and @ref JxlDecoderReleaseInput, the user may not
  578. * alter the data in the buffer. Calling @ref JxlDecoderReleaseInput is required
  579. * whenever any input is already set and new input needs to be added with @ref
  580. * JxlDecoderSetInput, but is not required before @ref JxlDecoderDestroy or @ref
  581. * JxlDecoderReset. Calling @ref JxlDecoderReleaseInput when no input is set is
  582. * not an error and returns `0`.
  583. *
  584. * @param dec decoder object
  585. * @return The amount of bytes the decoder has not yet processed that are still
  586. * remaining in the data set by @ref JxlDecoderSetInput, or `0` if no input
  587. * is set or @ref JxlDecoderReleaseInput was already called. For a next call to
  588. * @ref JxlDecoderProcessInput, the buffer must start with these unprocessed
  589. * bytes. From this value it is possible to infer the position of certain JPEG
  590. * XL codestream elements (e.g. end of headers, frame start/end). See the
  591. * documentation of individual values of @ref JxlDecoderStatus for more
  592. * information.
  593. */
  594. JXL_EXPORT size_t JxlDecoderReleaseInput(JxlDecoder* dec);
  595. /**
  596. * Marks the input as finished, indicates that no more @ref JxlDecoderSetInput
  597. * will be called. This function allows the decoder to determine correctly if it
  598. * should return success, need more input or error in certain cases. For
  599. * backwards compatibility with a previous version of the API, using this
  600. * function is optional when not using the ::JXL_DEC_BOX event (the decoder
  601. * is able to determine the end of the image frames without marking the end),
  602. * but using this function is required when using ::JXL_DEC_BOX for getting
  603. * metadata box contents. This function does not replace @ref
  604. * JxlDecoderReleaseInput, that function should still be called if its return
  605. * value is needed.
  606. *
  607. * @ref JxlDecoderCloseInput should be called as soon as all known input bytes
  608. * are set (e.g. at the beginning when not streaming but setting all input
  609. * at once), before the final @ref JxlDecoderProcessInput calls.
  610. *
  611. * @param dec decoder object
  612. */
  613. JXL_EXPORT void JxlDecoderCloseInput(JxlDecoder* dec);
  614. /**
  615. * Outputs the basic image information, such as image dimensions, bit depth and
  616. * all other JxlBasicInfo fields, if available.
  617. *
  618. * @param dec decoder object
  619. * @param info struct to copy the information into, or NULL to only check
  620. * whether the information is available through the return value.
  621. * @return ::JXL_DEC_SUCCESS if the value is available, @ref
  622. * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR
  623. * in case of other error conditions.
  624. */
  625. JXL_EXPORT JxlDecoderStatus JxlDecoderGetBasicInfo(const JxlDecoder* dec,
  626. JxlBasicInfo* info);
  627. /**
  628. * Outputs information for extra channel at the given index. The index must be
  629. * smaller than num_extra_channels in the associated @ref JxlBasicInfo.
  630. *
  631. * @param dec decoder object
  632. * @param index index of the extra channel to query.
  633. * @param info struct to copy the information into, or NULL to only check
  634. * whether the information is available through the return value.
  635. * @return ::JXL_DEC_SUCCESS if the value is available, @ref
  636. * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR
  637. * in case of other error conditions.
  638. */
  639. JXL_EXPORT JxlDecoderStatus JxlDecoderGetExtraChannelInfo(
  640. const JxlDecoder* dec, size_t index, JxlExtraChannelInfo* info);
  641. /**
  642. * Outputs name for extra channel at the given index in UTF-8. The index must be
  643. * smaller than `num_extra_channels` in the associated @ref JxlBasicInfo. The
  644. * buffer for name must have at least `name_length + 1` bytes allocated, gotten
  645. * from the associated @ref JxlExtraChannelInfo.
  646. *
  647. * @param dec decoder object
  648. * @param index index of the extra channel to query.
  649. * @param name buffer to copy the name into
  650. * @param size size of the name buffer in bytes
  651. * @return ::JXL_DEC_SUCCESS if the value is available, @ref
  652. * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR
  653. * in case of other error conditions.
  654. */
  655. JXL_EXPORT JxlDecoderStatus JxlDecoderGetExtraChannelName(const JxlDecoder* dec,
  656. size_t index,
  657. char* name,
  658. size_t size);
  659. /** Defines which color profile to get: the profile from the codestream
  660. * metadata header, which represents the color profile of the original image,
  661. * or the color profile from the pixel data produced by the decoder. Both are
  662. * the same if the JxlBasicInfo has uses_original_profile set.
  663. */
  664. typedef enum {
  665. /** Get the color profile of the original image from the metadata.
  666. */
  667. JXL_COLOR_PROFILE_TARGET_ORIGINAL = 0,
  668. /** Get the color profile of the pixel data the decoder outputs. */
  669. JXL_COLOR_PROFILE_TARGET_DATA = 1,
  670. } JxlColorProfileTarget;
  671. /**
  672. * Outputs the color profile as JPEG XL encoded structured data, if available.
  673. * This is an alternative to an ICC Profile, which can represent a more limited
  674. * amount of color spaces, but represents them exactly through enum values.
  675. *
  676. * It is often possible to use @ref JxlDecoderGetColorAsICCProfile as an
  677. * alternative anyway. The following scenarios are possible:
  678. * - The JPEG XL image has an attached ICC Profile, in that case, the encoded
  679. * structured data is not available and this function will return an error
  680. * status. @ref JxlDecoderGetColorAsICCProfile should be called instead.
  681. * - The JPEG XL image has an encoded structured color profile, and it
  682. * represents an RGB or grayscale color space. This function will return it.
  683. * You can still use @ref JxlDecoderGetColorAsICCProfile as well as an
  684. * alternative if desired, though depending on which RGB color space is
  685. * represented, the ICC profile may be a close approximation. It is also not
  686. * always feasible to deduce from an ICC profile which named color space it
  687. * exactly represents, if any, as it can represent any arbitrary space.
  688. * HDR color spaces such as those using PQ and HLG are also potentially
  689. * problematic, in that: while ICC profiles can encode a transfer function
  690. * that happens to approximate those of PQ and HLG (HLG for only one given
  691. * system gamma at a time, and necessitating a 3D LUT if gamma is to be
  692. * different from `1`), they cannot (before ICCv4.4) semantically signal that
  693. * this is the color space that they represent. Therefore, they will
  694. * typically not actually be interpreted as representing an HDR color space.
  695. * This is especially detrimental to PQ which will then be interpreted as if
  696. * the maximum signal value represented SDR white instead of 10000 cd/m^2,
  697. * meaning that the image will be displayed two orders of magnitude (5-7 EV)
  698. * too dim.
  699. * - The JPEG XL image has an encoded structured color profile, and it
  700. * indicates an unknown or xyb color space. In that case, @ref
  701. * JxlDecoderGetColorAsICCProfile is not available.
  702. *
  703. * When rendering an image on a system where ICC-based color management is used,
  704. * @ref JxlDecoderGetColorAsICCProfile should generally be used first as it will
  705. * return a ready-to-use profile (with the aforementioned caveat about HDR).
  706. * When knowledge about the nominal color space is desired if available, @ref
  707. * JxlDecoderGetColorAsEncodedProfile should be used first.
  708. *
  709. * @param dec decoder object
  710. * @param target whether to get the original color profile from the metadata
  711. * or the color profile of the decoded pixels.
  712. * @param color_encoding struct to copy the information into, or NULL to only
  713. * check whether the information is available through the return value.
  714. * @return ::JXL_DEC_SUCCESS if the data is available and returned, @ref
  715. * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR in
  716. * case the encoded structured color profile does not exist in the
  717. * codestream.
  718. */
  719. JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsEncodedProfile(
  720. const JxlDecoder* dec, JxlColorProfileTarget target,
  721. JxlColorEncoding* color_encoding);
  722. /**
  723. * Outputs the size in bytes of the ICC profile returned by @ref
  724. * JxlDecoderGetColorAsICCProfile, if available, or indicates there is none
  725. * available. In most cases, the image will have an ICC profile available, but
  726. * if it does not, @ref JxlDecoderGetColorAsEncodedProfile must be used instead.
  727. *
  728. * @see JxlDecoderGetColorAsEncodedProfile for more information. The ICC
  729. * profile is either the exact ICC profile attached to the codestream metadata,
  730. * or a close approximation generated from JPEG XL encoded structured data,
  731. * depending of what is encoded in the codestream.
  732. *
  733. * @param dec decoder object
  734. * @param target whether to get the original color profile from the metadata
  735. * or the color profile of the decoded pixels.
  736. * @param size variable to output the size into, or NULL to only check the
  737. * return status.
  738. * @return ::JXL_DEC_SUCCESS if the ICC profile is available, @ref
  739. * JXL_DEC_NEED_MORE_INPUT if the decoder has not yet received enough
  740. * input data to determine whether an ICC profile is available or what its
  741. * size is, ::JXL_DEC_ERROR in case the ICC profile is not available and
  742. * cannot be generated.
  743. */
  744. JXL_EXPORT JxlDecoderStatus JxlDecoderGetICCProfileSize(
  745. const JxlDecoder* dec, JxlColorProfileTarget target, size_t* size);
  746. /**
  747. * Outputs ICC profile if available. The profile is only available if @ref
  748. * JxlDecoderGetICCProfileSize returns success. The output buffer must have
  749. * at least as many bytes as given by @ref JxlDecoderGetICCProfileSize.
  750. *
  751. * @param dec decoder object
  752. * @param target whether to get the original color profile from the metadata
  753. * or the color profile of the decoded pixels.
  754. * @param icc_profile buffer to copy the ICC profile into
  755. * @param size size of the icc_profile buffer in bytes
  756. * @return ::JXL_DEC_SUCCESS if the profile was successfully returned,
  757. * ::JXL_DEC_NEED_MORE_INPUT if not yet available, @ref
  758. * JXL_DEC_ERROR if the profile doesn't exist or the output size is not
  759. * large enough.
  760. */
  761. JXL_EXPORT JxlDecoderStatus JxlDecoderGetColorAsICCProfile(
  762. const JxlDecoder* dec, JxlColorProfileTarget target, uint8_t* icc_profile,
  763. size_t size);
  764. /** Sets the desired output color profile of the decoded image by calling
  765. * @ref JxlDecoderSetOutputColorProfile, passing on @c color_encoding and
  766. * setting @c icc_data to NULL. See @ref JxlDecoderSetOutputColorProfile for
  767. * details.
  768. *
  769. * @param dec decoder object
  770. * @param color_encoding the default color encoding to set
  771. * @return ::JXL_DEC_SUCCESS if the preference was set successfully, @ref
  772. * JXL_DEC_ERROR otherwise.
  773. */
  774. JXL_EXPORT JxlDecoderStatus JxlDecoderSetPreferredColorProfile(
  775. JxlDecoder* dec, const JxlColorEncoding* color_encoding);
  776. /** Requests that the decoder perform tone mapping to the peak display luminance
  777. * passed as @c desired_intensity_target, if appropriate.
  778. * @note This is provided for convenience and the exact tone mapping that is
  779. * performed is not meant to be considered authoritative in any way. It may
  780. * change from version to version.
  781. * @param dec decoder object
  782. * @param desired_intensity_target the intended target peak luminance
  783. * @return ::JXL_DEC_SUCCESS if the preference was set successfully, @ref
  784. * JXL_DEC_ERROR otherwise.
  785. */
  786. JXL_EXPORT JxlDecoderStatus JxlDecoderSetDesiredIntensityTarget(
  787. JxlDecoder* dec, float desired_intensity_target);
  788. /**
  789. * Sets the desired output color profile of the decoded image either from a
  790. * color encoding or an ICC profile. Valid calls of this function have either @c
  791. * color_encoding or @c icc_data set to NULL and @c icc_size must be `0` if and
  792. * only if @c icc_data is NULL.
  793. *
  794. * Depending on whether a color management system (CMS) has been set the
  795. * behavior is as follows:
  796. *
  797. * If a color management system (CMS) has been set with @ref JxlDecoderSetCms,
  798. * and the CMS supports output to the desired color encoding or ICC profile,
  799. * then it will provide the output in that color encoding or ICC profile. If the
  800. * desired color encoding or the ICC is not supported, then an error will be
  801. * returned.
  802. *
  803. * If no CMS has been set with @ref JxlDecoderSetCms, there are two cases:
  804. *
  805. * (1) Calling this function with a color encoding will convert XYB images to
  806. * the desired color encoding. In this case, if the requested color encoding has
  807. * a narrower gamut, or the white points differ, then the resulting image can
  808. * have significant color distortion. Non-XYB images will not be converted to
  809. * the desired color space.
  810. *
  811. * (2) Calling this function with an ICC profile will result in an error.
  812. *
  813. * If called with an ICC profile (after a call to @ref JxlDecoderSetCms), the
  814. * ICC profile has to be a valid RGB or grayscale color profile.
  815. *
  816. * Can only be set after the ::JXL_DEC_COLOR_ENCODING event occurred and
  817. * before any other event occurred, and should be used before getting
  818. * ::JXL_COLOR_PROFILE_TARGET_DATA.
  819. *
  820. * This function must not be called before @ref JxlDecoderSetCms.
  821. *
  822. * @param dec decoder object
  823. * @param color_encoding the output color encoding
  824. * @param icc_data bytes of the icc profile
  825. * @param icc_size size of the icc profile in bytes
  826. * @return ::JXL_DEC_SUCCESS if the color profile was set successfully, @ref
  827. * JXL_DEC_ERROR otherwise.
  828. */
  829. JXL_EXPORT JxlDecoderStatus JxlDecoderSetOutputColorProfile(
  830. JxlDecoder* dec, const JxlColorEncoding* color_encoding,
  831. const uint8_t* icc_data, size_t icc_size);
  832. /**
  833. * Sets the color management system (CMS) that will be used for color
  834. * conversion (if applicable) during decoding. May only be set before starting
  835. * decoding and must not be called after @ref JxlDecoderSetOutputColorProfile.
  836. *
  837. * See @ref JxlDecoderSetOutputColorProfile for how color conversions are done
  838. * depending on whether or not a CMS has been set with @ref JxlDecoderSetCms.
  839. *
  840. * @param dec decoder object.
  841. * @param cms structure representing a CMS implementation. See @ref
  842. * JxlCmsInterface for more details.
  843. */
  844. JXL_EXPORT JxlDecoderStatus JxlDecoderSetCms(JxlDecoder* dec,
  845. JxlCmsInterface cms);
  846. // TODO(firsching): add a function JxlDecoderSetDefaultCms() for setting a
  847. // default in case libjxl is build with a CMS.
  848. /**
  849. * Returns the minimum size in bytes of the preview image output pixel buffer
  850. * for the given format. This is the buffer for @ref
  851. * JxlDecoderSetPreviewOutBuffer. Requires the preview header information is
  852. * available in the decoder.
  853. *
  854. * @param dec decoder object
  855. * @param format format of pixels
  856. * @param size output value, buffer size in bytes
  857. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  858. * information not available yet.
  859. */
  860. JXL_EXPORT JxlDecoderStatus JxlDecoderPreviewOutBufferSize(
  861. const JxlDecoder* dec, const JxlPixelFormat* format, size_t* size);
  862. /**
  863. * Sets the buffer to write the low-resolution preview image
  864. * to. The size of the buffer must be at least as large as given by @ref
  865. * JxlDecoderPreviewOutBufferSize. The buffer follows the format described
  866. * by @ref JxlPixelFormat. The preview image dimensions are given by the
  867. * @ref JxlPreviewHeader. The buffer is owned by the caller.
  868. *
  869. * @param dec decoder object
  870. * @param format format of pixels. Object owned by user and its contents are
  871. * copied internally.
  872. * @param buffer buffer type to output the pixel data to
  873. * @param size size of buffer in bytes
  874. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  875. * size too small.
  876. */
  877. JXL_EXPORT JxlDecoderStatus JxlDecoderSetPreviewOutBuffer(
  878. JxlDecoder* dec, const JxlPixelFormat* format, void* buffer, size_t size);
  879. /**
  880. * Outputs the information from the frame, such as duration when have_animation.
  881. * This function can be called when ::JXL_DEC_FRAME occurred for the current
  882. * frame, even when have_animation in the JxlBasicInfo is JXL_FALSE.
  883. *
  884. * @param dec decoder object
  885. * @param header struct to copy the information into, or NULL to only check
  886. * whether the information is available through the return value.
  887. * @return ::JXL_DEC_SUCCESS if the value is available, @ref
  888. * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR in
  889. * case of other error conditions.
  890. */
  891. JXL_EXPORT JxlDecoderStatus JxlDecoderGetFrameHeader(const JxlDecoder* dec,
  892. JxlFrameHeader* header);
  893. /**
  894. * Outputs name for the current frame. The buffer for name must have at least
  895. * `name_length + 1` bytes allocated, gotten from the associated JxlFrameHeader.
  896. *
  897. * @param dec decoder object
  898. * @param name buffer to copy the name into
  899. * @param size size of the name buffer in bytes, including zero termination
  900. * character, so this must be at least @ref JxlFrameHeader.name_length + 1.
  901. * @return ::JXL_DEC_SUCCESS if the value is available, @ref
  902. * JXL_DEC_NEED_MORE_INPUT if not yet available, ::JXL_DEC_ERROR in
  903. * case of other error conditions.
  904. */
  905. JXL_EXPORT JxlDecoderStatus JxlDecoderGetFrameName(const JxlDecoder* dec,
  906. char* name, size_t size);
  907. /**
  908. * Outputs the blend information for the current frame for a specific extra
  909. * channel. This function can be called once the ::JXL_DEC_FRAME event occurred
  910. * for the current frame, even if the `have_animation` field in the @ref
  911. * JxlBasicInfo is @ref JXL_FALSE. This information is only useful if coalescing
  912. * is disabled; otherwise the decoder will have performed blending already.
  913. *
  914. * @param dec decoder object
  915. * @param index the index of the extra channel
  916. * @param blend_info struct to copy the information into
  917. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error
  918. */
  919. JXL_EXPORT JxlDecoderStatus JxlDecoderGetExtraChannelBlendInfo(
  920. const JxlDecoder* dec, size_t index, JxlBlendInfo* blend_info);
  921. /**
  922. * Returns the minimum size in bytes of the image output pixel buffer for the
  923. * given format. This is the buffer for @ref JxlDecoderSetImageOutBuffer.
  924. * Requires that the basic image information is available in the decoder in the
  925. * case of coalescing enabled (default). In case coalescing is disabled, this
  926. * can only be called after the ::JXL_DEC_FRAME event occurs. In that case,
  927. * it will return the size required to store the possibly cropped frame (which
  928. * can be larger or smaller than the image dimensions).
  929. *
  930. * @param dec decoder object
  931. * @param format format of the pixels.
  932. * @param size output value, buffer size in bytes
  933. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  934. * information not available yet.
  935. */
  936. JXL_EXPORT JxlDecoderStatus JxlDecoderImageOutBufferSize(
  937. const JxlDecoder* dec, const JxlPixelFormat* format, size_t* size);
  938. /**
  939. * Sets the buffer to write the full resolution image to. This can be set when
  940. * the ::JXL_DEC_FRAME event occurs, must be set when the @ref
  941. * JXL_DEC_NEED_IMAGE_OUT_BUFFER event occurs, and applies only for the
  942. * current frame. The size of the buffer must be at least as large as given
  943. * by @ref JxlDecoderImageOutBufferSize. The buffer follows the format described
  944. * by @ref JxlPixelFormat. The buffer is owned by the caller.
  945. *
  946. * @param dec decoder object
  947. * @param format format of the pixels. Object owned by user and its contents
  948. * are copied internally.
  949. * @param buffer buffer type to output the pixel data to
  950. * @param size size of buffer in bytes
  951. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  952. * size too small.
  953. */
  954. JXL_EXPORT JxlDecoderStatus JxlDecoderSetImageOutBuffer(
  955. JxlDecoder* dec, const JxlPixelFormat* format, void* buffer, size_t size);
  956. /**
  957. * Function type for @ref JxlDecoderSetImageOutCallback.
  958. *
  959. * The callback may be called simultaneously by different threads when using a
  960. * threaded parallel runner, on different pixels.
  961. *
  962. * @param opaque optional user data, as given to @ref
  963. * JxlDecoderSetImageOutCallback.
  964. * @param x horizontal position of leftmost pixel of the pixel data.
  965. * @param y vertical position of the pixel data.
  966. * @param num_pixels amount of pixels included in the pixel data, horizontally.
  967. * This is not the same as xsize of the full image, it may be smaller.
  968. * @param pixels pixel data as a horizontal stripe, in the format passed to @ref
  969. * JxlDecoderSetImageOutCallback. The memory is not owned by the user, and
  970. * is only valid during the time the callback is running.
  971. */
  972. typedef void (*JxlImageOutCallback)(void* opaque, size_t x, size_t y,
  973. size_t num_pixels, const void* pixels);
  974. /**
  975. * Initialization callback for @ref JxlDecoderSetMultithreadedImageOutCallback.
  976. *
  977. * @param init_opaque optional user data, as given to @ref
  978. * JxlDecoderSetMultithreadedImageOutCallback.
  979. * @param num_threads maximum number of threads that will call the @c run
  980. * callback concurrently.
  981. * @param num_pixels_per_thread maximum number of pixels that will be passed in
  982. * one call to @c run.
  983. * @return a pointer to data that will be passed to the @c run callback, or
  984. * @c NULL if initialization failed.
  985. */
  986. typedef void* (*JxlImageOutInitCallback)(void* init_opaque, size_t num_threads,
  987. size_t num_pixels_per_thread);
  988. /**
  989. * Worker callback for @ref JxlDecoderSetMultithreadedImageOutCallback.
  990. *
  991. * @param run_opaque user data returned by the @c init callback.
  992. * @param thread_id number in `[0, num_threads)` identifying the thread of the
  993. * current invocation of the callback.
  994. * @param x horizontal position of the first (leftmost) pixel of the pixel data.
  995. * @param y vertical position of the pixel data.
  996. * @param num_pixels number of pixels in the pixel data. May be less than the
  997. * full @c xsize of the image, and will be at most equal to the @c
  998. * num_pixels_per_thread that was passed to @c init.
  999. * @param pixels pixel data as a horizontal stripe, in the format passed to @ref
  1000. * JxlDecoderSetMultithreadedImageOutCallback. The data pointed to
  1001. * remains owned by the caller and is only guaranteed to outlive the current
  1002. * callback invocation.
  1003. */
  1004. typedef void (*JxlImageOutRunCallback)(void* run_opaque, size_t thread_id,
  1005. size_t x, size_t y, size_t num_pixels,
  1006. const void* pixels);
  1007. /**
  1008. * Destruction callback for @ref JxlDecoderSetMultithreadedImageOutCallback,
  1009. * called after all invocations of the @c run callback to perform any
  1010. * appropriate clean-up of the @c run_opaque data returned by @c init.
  1011. *
  1012. * @param run_opaque user data returned by the @c init callback.
  1013. */
  1014. typedef void (*JxlImageOutDestroyCallback)(void* run_opaque);
  1015. /**
  1016. * Sets pixel output callback. This is an alternative to @ref
  1017. * JxlDecoderSetImageOutBuffer. This can be set when the ::JXL_DEC_FRAME
  1018. * event occurs, must be set when the ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event
  1019. * occurs, and applies only for the current frame. Only one of @ref
  1020. * JxlDecoderSetImageOutBuffer or @ref JxlDecoderSetImageOutCallback may be used
  1021. * for the same frame, not both at the same time.
  1022. *
  1023. * The callback will be called multiple times, to receive the image
  1024. * data in small chunks. The callback receives a horizontal stripe of pixel
  1025. * data, `1` pixel high, xsize pixels wide, called a scanline. The xsize here is
  1026. * not the same as the full image width, the scanline may be a partial section,
  1027. * and xsize may differ between calls. The user can then process and/or copy the
  1028. * partial scanline to an image buffer. The callback may be called
  1029. * simultaneously by different threads when using a threaded parallel runner, on
  1030. * different pixels.
  1031. *
  1032. * If @ref JxlDecoderFlushImage is not used, then each pixel will be visited
  1033. * exactly once by the different callback calls, during processing with one or
  1034. * more @ref JxlDecoderProcessInput calls. These pixels are decoded to full
  1035. * detail, they are not part of a lower resolution or lower quality progressive
  1036. * pass, but the final pass.
  1037. *
  1038. * If @ref JxlDecoderFlushImage is used, then in addition each pixel will be
  1039. * visited zero or one times during the blocking @ref JxlDecoderFlushImage call.
  1040. * Pixels visited as a result of @ref JxlDecoderFlushImage may represent a lower
  1041. * resolution or lower quality intermediate progressive pass of the image. Any
  1042. * visited pixel will be of a quality at least as good or better than previous
  1043. * visits of this pixel. A pixel may be visited zero times if it cannot be
  1044. * decoded yet or if it was already decoded to full precision (this behavior is
  1045. * not guaranteed).
  1046. *
  1047. * @param dec decoder object
  1048. * @param format format of the pixels. Object owned by user; its contents are
  1049. * copied internally.
  1050. * @param callback the callback function receiving partial scanlines of pixel
  1051. * data.
  1052. * @param opaque optional user data, which will be passed on to the callback,
  1053. * may be NULL.
  1054. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such
  1055. * as @ref JxlDecoderSetImageOutBuffer already set.
  1056. */
  1057. JXL_EXPORT JxlDecoderStatus
  1058. JxlDecoderSetImageOutCallback(JxlDecoder* dec, const JxlPixelFormat* format,
  1059. JxlImageOutCallback callback, void* opaque);
  1060. /** Similar to @ref JxlDecoderSetImageOutCallback except that the callback is
  1061. * allowed an initialization phase during which it is informed of how many
  1062. * threads will call it concurrently, and those calls are further informed of
  1063. * which thread they are occurring in.
  1064. *
  1065. * @param dec decoder object
  1066. * @param format format of the pixels. Object owned by user; its contents are
  1067. * copied internally.
  1068. * @param init_callback initialization callback.
  1069. * @param run_callback the callback function receiving partial scanlines of
  1070. * pixel data.
  1071. * @param destroy_callback clean-up callback invoked after all calls to @c
  1072. * run_callback. May be NULL if no clean-up is necessary.
  1073. * @param init_opaque optional user data passed to @c init_callback, may be NULL
  1074. * (unlike the return value from @c init_callback which may only be NULL if
  1075. * initialization failed).
  1076. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such
  1077. * as @ref JxlDecoderSetImageOutBuffer having already been called.
  1078. */
  1079. JXL_EXPORT JxlDecoderStatus JxlDecoderSetMultithreadedImageOutCallback(
  1080. JxlDecoder* dec, const JxlPixelFormat* format,
  1081. JxlImageOutInitCallback init_callback, JxlImageOutRunCallback run_callback,
  1082. JxlImageOutDestroyCallback destroy_callback, void* init_opaque);
  1083. /**
  1084. * Returns the minimum size in bytes of an extra channel pixel buffer for the
  1085. * given format. This is the buffer for @ref JxlDecoderSetExtraChannelBuffer.
  1086. * Requires the basic image information is available in the decoder.
  1087. *
  1088. * @param dec decoder object
  1089. * @param format format of the pixels. The num_channels value is ignored and is
  1090. * always treated to be `1`.
  1091. * @param size output value, buffer size in bytes
  1092. * @param index which extra channel to get, matching the index used in @ref
  1093. * JxlDecoderGetExtraChannelInfo. Must be smaller than num_extra_channels in
  1094. * the associated @ref JxlBasicInfo.
  1095. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  1096. * information not available yet or invalid index.
  1097. */
  1098. JXL_EXPORT JxlDecoderStatus JxlDecoderExtraChannelBufferSize(
  1099. const JxlDecoder* dec, const JxlPixelFormat* format, size_t* size,
  1100. uint32_t index);
  1101. /**
  1102. * Sets the buffer to write an extra channel to. This can be set when
  1103. * the ::JXL_DEC_FRAME or ::JXL_DEC_NEED_IMAGE_OUT_BUFFER event occurs,
  1104. * and applies only for the current frame. The size of the buffer must be at
  1105. * least as large as given by @ref JxlDecoderExtraChannelBufferSize. The buffer
  1106. * follows the format described by @ref JxlPixelFormat, but where num_channels
  1107. * is `1`. The buffer is owned by the caller. The amount of extra channels is
  1108. * given by the num_extra_channels field in the associated @ref JxlBasicInfo,
  1109. * and the information of individual extra channels can be queried with @ref
  1110. * JxlDecoderGetExtraChannelInfo. To get multiple extra channels, this function
  1111. * must be called multiple times, once for each wanted index. Not all images
  1112. * have extra channels. The alpha channel is an extra channel and can be gotten
  1113. * as part of the color channels when using an RGBA pixel buffer with @ref
  1114. * JxlDecoderSetImageOutBuffer, but additionally also can be gotten
  1115. * separately as extra channel. The color channels themselves cannot be gotten
  1116. * this way.
  1117. *
  1118. *
  1119. * @param dec decoder object
  1120. * @param format format of the pixels. Object owned by user and its contents
  1121. * are copied internally. The num_channels value is ignored and is always
  1122. * treated to be `1`.
  1123. * @param buffer buffer type to output the pixel data to
  1124. * @param size size of buffer in bytes
  1125. * @param index which extra channel to get, matching the index used in @ref
  1126. * JxlDecoderGetExtraChannelInfo. Must be smaller than num_extra_channels in
  1127. * the associated @ref JxlBasicInfo.
  1128. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  1129. * size too small or invalid index.
  1130. */
  1131. JXL_EXPORT JxlDecoderStatus
  1132. JxlDecoderSetExtraChannelBuffer(JxlDecoder* dec, const JxlPixelFormat* format,
  1133. void* buffer, size_t size, uint32_t index);
  1134. /**
  1135. * Sets output buffer for reconstructed JPEG codestream.
  1136. *
  1137. * The data is owned by the caller and may be used by the decoder until @ref
  1138. * JxlDecoderReleaseJPEGBuffer is called or the decoder is destroyed or
  1139. * reset so must be kept alive until then.
  1140. *
  1141. * If a JPEG buffer was set before and released with @ref
  1142. * JxlDecoderReleaseJPEGBuffer, bytes that the decoder has already output
  1143. * should not be included, only the remaining bytes output must be set.
  1144. *
  1145. * @param dec decoder object
  1146. * @param data pointer to next bytes to write to
  1147. * @param size amount of bytes available starting from data
  1148. * @return ::JXL_DEC_ERROR if output buffer was already set and @ref
  1149. * JxlDecoderReleaseJPEGBuffer was not called on it, ::JXL_DEC_SUCCESS
  1150. * otherwise
  1151. */
  1152. JXL_EXPORT JxlDecoderStatus JxlDecoderSetJPEGBuffer(JxlDecoder* dec,
  1153. uint8_t* data, size_t size);
  1154. /**
  1155. * Releases buffer which was provided with @ref JxlDecoderSetJPEGBuffer.
  1156. *
  1157. * Calling @ref JxlDecoderReleaseJPEGBuffer is required whenever
  1158. * a buffer is already set and a new buffer needs to be added with @ref
  1159. * JxlDecoderSetJPEGBuffer, but is not required before @ref
  1160. * JxlDecoderDestroy or @ref JxlDecoderReset.
  1161. *
  1162. * Calling @ref JxlDecoderReleaseJPEGBuffer when no buffer is set is
  1163. * not an error and returns `0`.
  1164. *
  1165. * @param dec decoder object
  1166. * @return the amount of bytes the decoder has not yet written to of the data
  1167. * set by @ref JxlDecoderSetJPEGBuffer, or `0` if no buffer is set or @ref
  1168. * JxlDecoderReleaseJPEGBuffer was already called.
  1169. */
  1170. JXL_EXPORT size_t JxlDecoderReleaseJPEGBuffer(JxlDecoder* dec);
  1171. /**
  1172. * Sets output buffer for box output codestream.
  1173. *
  1174. * The data is owned by the caller and may be used by the decoder until @ref
  1175. * JxlDecoderReleaseBoxBuffer is called or the decoder is destroyed or
  1176. * reset so must be kept alive until then.
  1177. *
  1178. * If for the current box a box buffer was set before and released with @ref
  1179. * JxlDecoderReleaseBoxBuffer, bytes that the decoder has already output
  1180. * should not be included, only the remaining bytes output must be set.
  1181. *
  1182. * The @ref JxlDecoderReleaseBoxBuffer must be used at the next ::JXL_DEC_BOX
  1183. * event or final ::JXL_DEC_SUCCESS event to compute the size of the output
  1184. * box bytes.
  1185. *
  1186. * @param dec decoder object
  1187. * @param data pointer to next bytes to write to
  1188. * @param size amount of bytes available starting from data
  1189. * @return ::JXL_DEC_ERROR if output buffer was already set and @ref
  1190. * JxlDecoderReleaseBoxBuffer was not called on it, ::JXL_DEC_SUCCESS
  1191. * otherwise
  1192. */
  1193. JXL_EXPORT JxlDecoderStatus JxlDecoderSetBoxBuffer(JxlDecoder* dec,
  1194. uint8_t* data, size_t size);
  1195. /**
  1196. * Releases buffer which was provided with @ref JxlDecoderSetBoxBuffer.
  1197. *
  1198. * Calling @ref JxlDecoderReleaseBoxBuffer is required whenever
  1199. * a buffer is already set and a new buffer needs to be added with @ref
  1200. * JxlDecoderSetBoxBuffer, but is not required before @ref
  1201. * JxlDecoderDestroy or @ref JxlDecoderReset.
  1202. *
  1203. * Calling @ref JxlDecoderReleaseBoxBuffer when no buffer is set is
  1204. * not an error and returns `0`.
  1205. *
  1206. * @param dec decoder object
  1207. * @return the amount of bytes the decoder has not yet written to of the data
  1208. * set by @ref JxlDecoderSetBoxBuffer, or `0` if no buffer is set or @ref
  1209. * JxlDecoderReleaseBoxBuffer was already called.
  1210. */
  1211. JXL_EXPORT size_t JxlDecoderReleaseBoxBuffer(JxlDecoder* dec);
  1212. /**
  1213. * Configures whether to get boxes in raw mode or in decompressed mode. In raw
  1214. * mode, boxes are output as their bytes appear in the container file, which may
  1215. * be decompressed, or compressed if their type is "brob". In decompressed mode,
  1216. * "brob" boxes are decompressed with Brotli before outputting them. The size of
  1217. * the decompressed stream is not known before the decompression has already
  1218. * finished.
  1219. *
  1220. * The default mode is raw. This setting can only be changed before decoding, or
  1221. * directly after a ::JXL_DEC_BOX event, and is remembered until the decoder
  1222. * is reset or destroyed.
  1223. *
  1224. * Enabling decompressed mode requires Brotli support from the library.
  1225. *
  1226. * @param dec decoder object
  1227. * @param decompress ::JXL_TRUE to transparently decompress, ::JXL_FALSE
  1228. * to get boxes in raw mode.
  1229. * @return ::JXL_DEC_ERROR if decompressed mode is set and Brotli is not
  1230. * available, ::JXL_DEC_SUCCESS otherwise.
  1231. */
  1232. JXL_EXPORT JxlDecoderStatus JxlDecoderSetDecompressBoxes(JxlDecoder* dec,
  1233. JXL_BOOL decompress);
  1234. /**
  1235. * Outputs the type of the current box, after a ::JXL_DEC_BOX event occurred,
  1236. * as `4` characters without null termination character. In case of a compressed
  1237. * "brob" box, this will return "brob" if the decompressed argument is
  1238. * JXL_FALSE, or the underlying box type if the decompressed argument is
  1239. * JXL_TRUE.
  1240. *
  1241. * The following box types are currently described in ISO/IEC 18181-2:
  1242. * - "Exif": a box with EXIF metadata. Starts with a 4-byte tiff header offset
  1243. * (big-endian uint32) that indicates the start of the actual EXIF data
  1244. * (which starts with a tiff header). Usually the offset will be zero and the
  1245. * EXIF data starts immediately after the offset field. The Exif orientation
  1246. * should be ignored by applications; the JPEG XL codestream orientation
  1247. * takes precedence and libjxl will by default apply the correct orientation
  1248. * automatically (see @ref JxlDecoderSetKeepOrientation).
  1249. * - "xml ": a box with XML data, in particular XMP metadata.
  1250. * - "jumb": a JUMBF superbox (JPEG Universal Metadata Box Format, ISO/IEC
  1251. * 19566-5).
  1252. * - "JXL ": mandatory signature box, must come first, `12` bytes long
  1253. * including the box header
  1254. * - "ftyp": a second mandatory signature box, must come second, `20` bytes
  1255. * long including the box header
  1256. * - "jxll": a JXL level box. This indicates if the codestream is level `5` or
  1257. * level `10` compatible. If not present, it is level `5`. Level `10` allows
  1258. * more features such as very high image resolution and bit-depths above `16`
  1259. * bits per channel. Added automatically by the encoder when
  1260. * @ref JxlEncoderSetCodestreamLevel is used
  1261. * - "jxlc": a box with the image codestream, in case the codestream is not
  1262. * split across multiple boxes. The codestream contains the JPEG XL image
  1263. * itself, including the basic info such as image dimensions, ICC color
  1264. * profile, and all the pixel data of all the image frames.
  1265. * - "jxlp": a codestream box in case it is split across multiple boxes.
  1266. * The contents are the same as in case of a jxlc box, when concatenated.
  1267. * - "brob": a Brotli-compressed box, which otherwise represents an existing
  1268. * type of box such as Exif or "xml ". When @ref JxlDecoderSetDecompressBoxes
  1269. * is set to JXL_TRUE, these boxes will be transparently decompressed by the
  1270. * decoder.
  1271. * - "jxli": frame index box, can list the keyframes in case of a JPEG XL
  1272. * animation allowing the decoder to jump to individual frames more
  1273. * efficiently.
  1274. * - "jbrd": JPEG reconstruction box, contains the information required to
  1275. * byte-for-byte losslessly reconstruct a JPEG-1 image. The JPEG DCT
  1276. * coefficients (pixel content) themselves as well as the ICC profile are
  1277. * encoded in the JXL codestream (jxlc or jxlp) itself. EXIF, XMP and JUMBF
  1278. * metadata is encoded in the corresponding boxes. The jbrd box itself
  1279. * contains information such as the remaining app markers of the JPEG-1 file
  1280. * and everything else required to fit the information together into the
  1281. * exact original JPEG file.
  1282. *
  1283. * Other application-specific boxes can exist. Their typename should not begin
  1284. * with "jxl" or "JXL" or conflict with other existing typenames.
  1285. *
  1286. * The signature, jxl* and jbrd boxes are processed by the decoder and would
  1287. * typically be ignored by applications. The typical way to use this function is
  1288. * to check if an encountered box contains metadata that the application is
  1289. * interested in (e.g. EXIF or XMP metadata), in order to conditionally set a
  1290. * box buffer.
  1291. *
  1292. * @param dec decoder object
  1293. * @param type buffer to copy the type into
  1294. * @param decompressed which box type to get: JXL_FALSE to get the raw box type,
  1295. * which can be "brob", JXL_TRUE, get the underlying box type.
  1296. * @return ::JXL_DEC_SUCCESS if the value is available, ::JXL_DEC_ERROR if
  1297. * not, for example the JPEG XL file does not use the container format.
  1298. */
  1299. JXL_EXPORT JxlDecoderStatus JxlDecoderGetBoxType(JxlDecoder* dec,
  1300. JxlBoxType type,
  1301. JXL_BOOL decompressed);
  1302. /**
  1303. * Returns the size of a box as it appears in the container file, after the @ref
  1304. * JXL_DEC_BOX event. This includes all the box headers.
  1305. *
  1306. * @param dec decoder object
  1307. * @param size raw size of the box in bytes
  1308. * @return ::JXL_DEC_ERROR if no box size is available, ::JXL_DEC_SUCCESS
  1309. * otherwise.
  1310. */
  1311. JXL_EXPORT JxlDecoderStatus JxlDecoderGetBoxSizeRaw(const JxlDecoder* dec,
  1312. uint64_t* size);
  1313. /**
  1314. * Returns the size of the contents of a box, after the @ref
  1315. * JXL_DEC_BOX event. This does not include any of the headers of the box. For
  1316. * compressed "brob" boxes, this is the size of the compressed content. Even
  1317. * when @ref JxlDecoderSetDecompressBoxes is enabled, the return value of
  1318. * function does not change, and the decompressed size is not known before it
  1319. * has already been decompressed and output.
  1320. *
  1321. * @param dec decoder object
  1322. * @param size size of the payload of the box in bytes
  1323. * @return @ref JXL_DEC_ERROR if no box size is available, @ref JXL_DEC_SUCCESS
  1324. * otherwise.
  1325. */
  1326. JXL_EXPORT JxlDecoderStatus JxlDecoderGetBoxSizeContents(const JxlDecoder* dec,
  1327. uint64_t* size);
  1328. /**
  1329. * Configures at which progressive steps in frame decoding these @ref
  1330. * JXL_DEC_FRAME_PROGRESSION event occurs. The default value for the level
  1331. * of detail if this function is never called is `kDC`.
  1332. *
  1333. * @param dec decoder object
  1334. * @param detail at which level of detail to trigger @ref
  1335. * JXL_DEC_FRAME_PROGRESSION
  1336. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  1337. * an invalid value for the progressive detail.
  1338. */
  1339. JXL_EXPORT JxlDecoderStatus
  1340. JxlDecoderSetProgressiveDetail(JxlDecoder* dec, JxlProgressiveDetail detail);
  1341. /**
  1342. * Returns the intended downsampling ratio for the progressive frame produced
  1343. * by @ref JxlDecoderFlushImage after the latest ::JXL_DEC_FRAME_PROGRESSION
  1344. * event.
  1345. *
  1346. * @param dec decoder object
  1347. * @return The intended downsampling ratio, can be `1`, `2`, `4` or `8`.
  1348. */
  1349. JXL_EXPORT size_t JxlDecoderGetIntendedDownsamplingRatio(JxlDecoder* dec);
  1350. /**
  1351. * Outputs progressive step towards the decoded image so far when only partial
  1352. * input was received. If the flush was successful, the buffer set with @ref
  1353. * JxlDecoderSetImageOutBuffer will contain partial image data.
  1354. *
  1355. * Can be called when @ref JxlDecoderProcessInput returns @ref
  1356. * JXL_DEC_NEED_MORE_INPUT, after the ::JXL_DEC_FRAME event already occurred
  1357. * and before the ::JXL_DEC_FULL_IMAGE event occurred for a frame.
  1358. *
  1359. * @param dec decoder object
  1360. * @return ::JXL_DEC_SUCCESS if image data was flushed to the output buffer,
  1361. * or ::JXL_DEC_ERROR when no flush was done, e.g. if not enough image
  1362. * data was available yet even for flush, or no output buffer was set yet.
  1363. * This error is not fatal, it only indicates no flushed image is available
  1364. * right now. Regular decoding can still be performed.
  1365. */
  1366. JXL_EXPORT JxlDecoderStatus JxlDecoderFlushImage(JxlDecoder* dec);
  1367. /**
  1368. * Sets the bit depth of the output buffer or callback.
  1369. *
  1370. * Can be called after @ref JxlDecoderSetImageOutBuffer or @ref
  1371. * JxlDecoderSetImageOutCallback. For float pixel data types, only the default
  1372. * ::JXL_BIT_DEPTH_FROM_PIXEL_FORMAT setting is supported.
  1373. *
  1374. * @param dec decoder object
  1375. * @param bit_depth the bit depth setting of the pixel output
  1376. * @return ::JXL_DEC_SUCCESS on success, ::JXL_DEC_ERROR on error, such as
  1377. * incompatible custom bit depth and pixel data type.
  1378. */
  1379. JXL_EXPORT JxlDecoderStatus
  1380. JxlDecoderSetImageOutBitDepth(JxlDecoder* dec, const JxlBitDepth* bit_depth);
  1381. #ifdef __cplusplus
  1382. }
  1383. #endif
  1384. #endif /* JXL_DECODE_H_ */
  1385. /** @}*/