openjpeg.h 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779
  1. /*
  2. * The copyright in this software is being made available under the 2-clauses
  3. * BSD License, included below. This software may be subject to other third
  4. * party and contributor rights, including patent rights, and no such rights
  5. * are granted under this license.
  6. *
  7. * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
  8. * Copyright (c) 2002-2014, Professor Benoit Macq
  9. * Copyright (c) 2001-2003, David Janssens
  10. * Copyright (c) 2002-2003, Yannick Verschueren
  11. * Copyright (c) 2003-2007, Francois-Olivier Devaux
  12. * Copyright (c) 2003-2014, Antonin Descampe
  13. * Copyright (c) 2005, Herve Drolon, FreeImage Team
  14. * Copyright (c) 2006-2007, Parvatha Elangovan
  15. * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
  16. * Copyright (c) 2010-2011, Kaori Hagihara
  17. * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
  18. * Copyright (c) 2012, CS Systemes d'Information, France
  19. * All rights reserved.
  20. *
  21. * Redistribution and use in source and binary forms, with or without
  22. * modification, are permitted provided that the following conditions
  23. * are met:
  24. * 1. Redistributions of source code must retain the above copyright
  25. * notice, this list of conditions and the following disclaimer.
  26. * 2. Redistributions in binary form must reproduce the above copyright
  27. * notice, this list of conditions and the following disclaimer in the
  28. * documentation and/or other materials provided with the distribution.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
  31. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  32. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  36. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  37. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  38. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  39. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGE.
  41. */
  42. #ifndef OPENJPEG_H
  43. #define OPENJPEG_H
  44. /*
  45. ==========================================================
  46. Compiler directives
  47. ==========================================================
  48. */
  49. /*
  50. The inline keyword is supported by C99 but not by C90.
  51. Most compilers implement their own version of this keyword ...
  52. */
  53. #ifndef INLINE
  54. #if defined(_MSC_VER)
  55. #define INLINE __forceinline
  56. #elif defined(__GNUC__)
  57. #define INLINE __inline__
  58. #elif defined(__MWERKS__)
  59. #define INLINE inline
  60. #else
  61. /* add other compilers here ... */
  62. #define INLINE
  63. #endif /* defined(<Compiler>) */
  64. #endif /* INLINE */
  65. /* deprecated attribute */
  66. #ifdef __GNUC__
  67. #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
  68. #elif defined(_MSC_VER)
  69. #define OPJ_DEPRECATED(func) __declspec(deprecated) func
  70. #else
  71. #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
  72. #define OPJ_DEPRECATED(func) func
  73. #endif
  74. #if defined(__GNUC__) && __GNUC__ >= 6
  75. #define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) __attribute__ ((deprecated(msg))) memb
  76. #else
  77. #define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) memb
  78. #endif
  79. #if defined(OPJ_STATIC) || !defined(_WIN32)
  80. /* http://gcc.gnu.org/wiki/Visibility */
  81. # if !defined(_WIN32) && __GNUC__ >= 4
  82. # if defined(OPJ_STATIC) /* static library uses "hidden" */
  83. # define OPJ_API __attribute__ ((visibility ("hidden")))
  84. # else
  85. # define OPJ_API __attribute__ ((visibility ("default")))
  86. # endif
  87. # define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
  88. # else
  89. # define OPJ_API
  90. # define OPJ_LOCAL
  91. # endif
  92. # define OPJ_CALLCONV
  93. #else
  94. # define OPJ_CALLCONV __stdcall
  95. /*
  96. The following ifdef block is the standard way of creating macros which make exporting
  97. from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
  98. symbol defined on the command line. this symbol should not be defined on any project
  99. that uses this DLL. This way any other project whose source files include this file see
  100. OPJ_API functions as being imported from a DLL, whereas this DLL sees symbols
  101. defined with this macro as being exported.
  102. */
  103. # if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
  104. # define OPJ_API __declspec(dllexport)
  105. # else
  106. # define OPJ_API __declspec(dllimport)
  107. # endif /* OPJ_EXPORTS */
  108. #endif /* !OPJ_STATIC || !_WIN32 */
  109. typedef int OPJ_BOOL;
  110. #define OPJ_TRUE 1
  111. #define OPJ_FALSE 0
  112. typedef char OPJ_CHAR;
  113. typedef float OPJ_FLOAT32;
  114. typedef double OPJ_FLOAT64;
  115. typedef unsigned char OPJ_BYTE;
  116. #include <stdint.h>
  117. typedef int8_t OPJ_INT8;
  118. typedef uint8_t OPJ_UINT8;
  119. typedef int16_t OPJ_INT16;
  120. typedef uint16_t OPJ_UINT16;
  121. typedef int32_t OPJ_INT32;
  122. typedef uint32_t OPJ_UINT32;
  123. typedef int64_t OPJ_INT64;
  124. typedef uint64_t OPJ_UINT64;
  125. typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */
  126. #include <stdio.h>
  127. typedef size_t OPJ_SIZE_T;
  128. #include "opj_config.h"
  129. /* Avoid compile-time warning because parameter is not used */
  130. #define OPJ_ARG_NOT_USED(x) (void)(x)
  131. /*
  132. ==========================================================
  133. Useful constant definitions
  134. ==========================================================
  135. */
  136. #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
  137. #define OPJ_J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
  138. #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
  139. #define OPJ_J2K_DEFAULT_NB_SEGS 10
  140. #define OPJ_J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
  141. #define OPJ_J2K_DEFAULT_HEADER_SIZE 1000
  142. #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS 10
  143. #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS 10
  144. /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
  145. #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
  146. #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
  147. #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
  148. #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
  149. #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
  150. #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
  151. #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
  152. #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
  153. /* <<UniPG */
  154. /**
  155. * EXPERIMENTAL FOR THE MOMENT
  156. * Supported options about file information used only in j2k_dump
  157. */
  158. #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
  159. #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
  160. #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
  161. #define OPJ_J2K_TCH_INFO 8 /**< Tile/Component information of all tiles */
  162. #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
  163. #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
  164. /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
  165. #define OPJ_JP2_INFO 128 /**< JP2 file information */
  166. #define OPJ_JP2_IND 256 /**< JP2 file index */
  167. /**
  168. * JPEG 2000 Profiles, see Table A.10 from 15444-1 (updated in various AMD)
  169. * These values help choosing the RSIZ value for the J2K codestream.
  170. * The RSIZ value triggers various encoding options, as detailed in Table A.10.
  171. * If OPJ_PROFILE_PART2 is chosen, it has to be combined with one or more extensions
  172. * described hereunder.
  173. * Example: rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT;
  174. * For broadcast profiles, the OPJ_PROFILE value has to be combined with the targeted
  175. * mainlevel (3-0 LSB, value between 0 and 11):
  176. * Example: rsiz = OPJ_PROFILE_BC_MULTI | 0x0005; (here mainlevel 5)
  177. * For IMF profiles, the OPJ_PROFILE value has to be combined with the targeted mainlevel
  178. * (3-0 LSB, value between 0 and 11) and sublevel (7-4 LSB, value between 0 and 9):
  179. * Example: rsiz = OPJ_PROFILE_IMF_2K | 0x0040 | 0x0005; (here main 5 and sublevel 4)
  180. * */
  181. #define OPJ_PROFILE_NONE 0x0000 /** no profile, conform to 15444-1 */
  182. #define OPJ_PROFILE_0 0x0001 /** Profile 0 as described in 15444-1,Table A.45 */
  183. #define OPJ_PROFILE_1 0x0002 /** Profile 1 as described in 15444-1,Table A.45 */
  184. #define OPJ_PROFILE_PART2 0x8000 /** At least 1 extension defined in 15444-2 (Part-2) */
  185. #define OPJ_PROFILE_CINEMA_2K 0x0003 /** 2K cinema profile defined in 15444-1 AMD1 */
  186. #define OPJ_PROFILE_CINEMA_4K 0x0004 /** 4K cinema profile defined in 15444-1 AMD1 */
  187. #define OPJ_PROFILE_CINEMA_S2K 0x0005 /** Scalable 2K cinema profile defined in 15444-1 AMD2 */
  188. #define OPJ_PROFILE_CINEMA_S4K 0x0006 /** Scalable 4K cinema profile defined in 15444-1 AMD2 */
  189. #define OPJ_PROFILE_CINEMA_LTS 0x0007 /** Long term storage cinema profile defined in 15444-1 AMD2 */
  190. #define OPJ_PROFILE_BC_SINGLE 0x0100 /** Single Tile Broadcast profile defined in 15444-1 AMD3 */
  191. #define OPJ_PROFILE_BC_MULTI 0x0200 /** Multi Tile Broadcast profile defined in 15444-1 AMD3 */
  192. #define OPJ_PROFILE_BC_MULTI_R 0x0300 /** Multi Tile Reversible Broadcast profile defined in 15444-1 AMD3 */
  193. #define OPJ_PROFILE_IMF_2K 0x0400 /** 2K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
  194. #define OPJ_PROFILE_IMF_4K 0x0500 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
  195. #define OPJ_PROFILE_IMF_8K 0x0600 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
  196. #define OPJ_PROFILE_IMF_2K_R 0x0700 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
  197. #define OPJ_PROFILE_IMF_4K_R 0x0800 /** 4K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
  198. #define OPJ_PROFILE_IMF_8K_R 0x0900 /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
  199. /**
  200. * JPEG 2000 Part-2 extensions
  201. * */
  202. #define OPJ_EXTENSION_NONE 0x0000 /** No Part-2 extension */
  203. #define OPJ_EXTENSION_MCT 0x0100 /** Custom MCT support */
  204. /**
  205. * JPEG 2000 profile macros
  206. * */
  207. #define OPJ_IS_CINEMA(v) (((v) >= OPJ_PROFILE_CINEMA_2K)&&((v) <= OPJ_PROFILE_CINEMA_S4K))
  208. #define OPJ_IS_STORAGE(v) ((v) == OPJ_PROFILE_CINEMA_LTS)
  209. #define OPJ_IS_BROADCAST(v) (((v) >= OPJ_PROFILE_BC_SINGLE)&&((v) <= ((OPJ_PROFILE_BC_MULTI_R) | (0x000b))))
  210. #define OPJ_IS_IMF(v) (((v) >= OPJ_PROFILE_IMF_2K)&&((v) <= ((OPJ_PROFILE_IMF_8K_R) | (0x009b))))
  211. #define OPJ_IS_PART2(v) ((v) & OPJ_PROFILE_PART2)
  212. #define OPJ_GET_IMF_PROFILE(v) ((v) & 0xff00) /** Extract IMF profile without mainlevel/sublevel */
  213. #define OPJ_GET_IMF_MAINLEVEL(v) ((v) & 0xf) /** Extract IMF main level */
  214. #define OPJ_GET_IMF_SUBLEVEL(v) (((v) >> 4) & 0xf) /** Extract IMF sub level */
  215. #define OPJ_IMF_MAINLEVEL_MAX 11 /** Maximum main level */
  216. /** Max. Components Sampling Rate (MSamples/sec) per IMF main level */
  217. #define OPJ_IMF_MAINLEVEL_1_MSAMPLESEC 65 /** MSamples/sec for IMF main level 1 */
  218. #define OPJ_IMF_MAINLEVEL_2_MSAMPLESEC 130 /** MSamples/sec for IMF main level 2 */
  219. #define OPJ_IMF_MAINLEVEL_3_MSAMPLESEC 195 /** MSamples/sec for IMF main level 3 */
  220. #define OPJ_IMF_MAINLEVEL_4_MSAMPLESEC 260 /** MSamples/sec for IMF main level 4 */
  221. #define OPJ_IMF_MAINLEVEL_5_MSAMPLESEC 520 /** MSamples/sec for IMF main level 5 */
  222. #define OPJ_IMF_MAINLEVEL_6_MSAMPLESEC 1200 /** MSamples/sec for IMF main level 6 */
  223. #define OPJ_IMF_MAINLEVEL_7_MSAMPLESEC 2400 /** MSamples/sec for IMF main level 7 */
  224. #define OPJ_IMF_MAINLEVEL_8_MSAMPLESEC 4800 /** MSamples/sec for IMF main level 8 */
  225. #define OPJ_IMF_MAINLEVEL_9_MSAMPLESEC 9600 /** MSamples/sec for IMF main level 9 */
  226. #define OPJ_IMF_MAINLEVEL_10_MSAMPLESEC 19200 /** MSamples/sec for IMF main level 10 */
  227. #define OPJ_IMF_MAINLEVEL_11_MSAMPLESEC 38400 /** MSamples/sec for IMF main level 11 */
  228. /** Max. compressed Bit Rate (Mbits/s) per IMF sub level */
  229. #define OPJ_IMF_SUBLEVEL_1_MBITSSEC 200 /** Mbits/s for IMF sub level 1 */
  230. #define OPJ_IMF_SUBLEVEL_2_MBITSSEC 400 /** Mbits/s for IMF sub level 2 */
  231. #define OPJ_IMF_SUBLEVEL_3_MBITSSEC 800 /** Mbits/s for IMF sub level 3 */
  232. #define OPJ_IMF_SUBLEVEL_4_MBITSSEC 1600 /** Mbits/s for IMF sub level 4 */
  233. #define OPJ_IMF_SUBLEVEL_5_MBITSSEC 3200 /** Mbits/s for IMF sub level 5 */
  234. #define OPJ_IMF_SUBLEVEL_6_MBITSSEC 6400 /** Mbits/s for IMF sub level 6 */
  235. #define OPJ_IMF_SUBLEVEL_7_MBITSSEC 12800 /** Mbits/s for IMF sub level 7 */
  236. #define OPJ_IMF_SUBLEVEL_8_MBITSSEC 25600 /** Mbits/s for IMF sub level 8 */
  237. #define OPJ_IMF_SUBLEVEL_9_MBITSSEC 51200 /** Mbits/s for IMF sub level 9 */
  238. /**
  239. * JPEG 2000 codestream and component size limits in cinema profiles
  240. * */
  241. #define OPJ_CINEMA_24_CS 1302083 /** Maximum codestream length for 24fps */
  242. #define OPJ_CINEMA_48_CS 651041 /** Maximum codestream length for 48fps */
  243. #define OPJ_CINEMA_24_COMP 1041666 /** Maximum size per color component for 2K & 4K @ 24fps */
  244. #define OPJ_CINEMA_48_COMP 520833 /** Maximum size per color component for 2K @ 48fps */
  245. /*
  246. ==========================================================
  247. enum definitions
  248. ==========================================================
  249. */
  250. /**
  251. * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
  252. * Rsiz Capabilities
  253. * */
  254. typedef enum RSIZ_CAPABILITIES {
  255. OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
  256. OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
  257. OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
  258. OPJ_MCT = 0x8100
  259. } OPJ_RSIZ_CAPABILITIES;
  260. /**
  261. * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
  262. * Digital cinema operation mode
  263. * */
  264. typedef enum CINEMA_MODE {
  265. OPJ_OFF = 0, /** Not Digital Cinema*/
  266. OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
  267. OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
  268. OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
  269. } OPJ_CINEMA_MODE;
  270. /**
  271. * Progression order
  272. * */
  273. typedef enum PROG_ORDER {
  274. OPJ_PROG_UNKNOWN = -1, /**< place-holder */
  275. OPJ_LRCP = 0, /**< layer-resolution-component-precinct order */
  276. OPJ_RLCP = 1, /**< resolution-layer-component-precinct order */
  277. OPJ_RPCL = 2, /**< resolution-precinct-component-layer order */
  278. OPJ_PCRL = 3, /**< precinct-component-resolution-layer order */
  279. OPJ_CPRL = 4 /**< component-precinct-resolution-layer order */
  280. } OPJ_PROG_ORDER;
  281. /**
  282. * Supported image color spaces
  283. */
  284. typedef enum COLOR_SPACE {
  285. OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
  286. OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
  287. OPJ_CLRSPC_SRGB = 1, /**< sRGB */
  288. OPJ_CLRSPC_GRAY = 2, /**< grayscale */
  289. OPJ_CLRSPC_SYCC = 3, /**< YUV */
  290. OPJ_CLRSPC_EYCC = 4, /**< e-YCC */
  291. OPJ_CLRSPC_CMYK = 5 /**< CMYK */
  292. } OPJ_COLOR_SPACE;
  293. /**
  294. * Supported codec
  295. */
  296. typedef enum CODEC_FORMAT {
  297. OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
  298. OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
  299. OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
  300. OPJ_CODEC_JP2 = 2, /**< JP2 file format : read/write */
  301. OPJ_CODEC_JPP = 3, /**< JPP-stream (JPEG 2000, JPIP) : to be coded */
  302. OPJ_CODEC_JPX = 4 /**< JPX file format (JPEG 2000 Part-2) : to be coded */
  303. } OPJ_CODEC_FORMAT;
  304. /*
  305. ==========================================================
  306. event manager typedef definitions
  307. ==========================================================
  308. */
  309. /**
  310. * Callback function prototype for events
  311. * @param msg Event message
  312. * @param client_data Client object where will be return the event message
  313. * */
  314. typedef void (*opj_msg_callback)(const char *msg, void *client_data);
  315. /*
  316. ==========================================================
  317. codec typedef definitions
  318. ==========================================================
  319. */
  320. #ifndef OPJ_UINT32_SEMANTICALLY_BUT_INT32
  321. #define OPJ_UINT32_SEMANTICALLY_BUT_INT32 OPJ_INT32
  322. #endif
  323. /**
  324. * Progression order changes
  325. *
  326. */
  327. typedef struct opj_poc {
  328. /** Resolution num start, Component num start, given by POC */
  329. OPJ_UINT32 resno0, compno0;
  330. /** Layer num end,Resolution num end, Component num end, given by POC */
  331. OPJ_UINT32 layno1, resno1, compno1;
  332. /** Layer num start,Precinct num start, Precinct num end */
  333. OPJ_UINT32 layno0, precno0, precno1;
  334. /** Progression order enum*/
  335. OPJ_PROG_ORDER prg1, prg;
  336. /** Progression order string*/
  337. OPJ_CHAR progorder[5];
  338. /** Tile number (starting at 1) */
  339. OPJ_UINT32 tile;
  340. /** Start and end values for Tile width and height*/
  341. OPJ_UINT32_SEMANTICALLY_BUT_INT32 tx0, tx1, ty0, ty1;
  342. /** Start value, initialised in pi_initialise_encode*/
  343. OPJ_UINT32 layS, resS, compS, prcS;
  344. /** End value, initialised in pi_initialise_encode */
  345. OPJ_UINT32 layE, resE, compE, prcE;
  346. /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
  347. OPJ_UINT32 txS, txE, tyS, tyE, dx, dy;
  348. /** Temporary values for Tile parts, initialised in pi_create_encode */
  349. OPJ_UINT32 lay_t, res_t, comp_t, prc_t, tx0_t, ty0_t;
  350. } opj_poc_t;
  351. /**
  352. * Compression parameters
  353. * */
  354. typedef struct opj_cparameters {
  355. /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
  356. OPJ_BOOL tile_size_on;
  357. /** XTOsiz */
  358. int cp_tx0;
  359. /** YTOsiz */
  360. int cp_ty0;
  361. /** XTsiz */
  362. int cp_tdx;
  363. /** YTsiz */
  364. int cp_tdy;
  365. /** allocation by rate/distortion */
  366. int cp_disto_alloc;
  367. /** allocation by fixed layer */
  368. int cp_fixed_alloc;
  369. /** allocation by fixed quality (PSNR) */
  370. int cp_fixed_quality;
  371. /** fixed layer */
  372. int *cp_matrice;
  373. /** comment for coding */
  374. char *cp_comment;
  375. /** csty : coding style */
  376. int csty;
  377. /** progression order (default OPJ_LRCP) */
  378. OPJ_PROG_ORDER prog_order;
  379. /** progression order changes */
  380. opj_poc_t POC[32];
  381. /** number of progression order changes (POC), default to 0 */
  382. OPJ_UINT32 numpocs;
  383. /** number of layers */
  384. int tcp_numlayers;
  385. /** rates of layers - might be subsequently limited by the max_cs_size field.
  386. * Should be decreasing. 1 can be
  387. * used as last value to indicate the last layer is lossless. */
  388. float tcp_rates[100];
  389. /** different psnr for successive layers. Should be increasing. 0 can be
  390. * used as last value to indicate the last layer is lossless. */
  391. float tcp_distoratio[100];
  392. /** number of resolutions */
  393. int numresolution;
  394. /** initial code block width, default to 64 */
  395. int cblockw_init;
  396. /** initial code block height, default to 64 */
  397. int cblockh_init;
  398. /** mode switch (cblk_style) */
  399. int mode;
  400. /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
  401. int irreversible;
  402. /** region of interest: affected component in [0..3], -1 means no ROI */
  403. int roi_compno;
  404. /** region of interest: upshift value */
  405. int roi_shift;
  406. /* number of precinct size specifications */
  407. int res_spec;
  408. /** initial precinct width */
  409. int prcw_init[OPJ_J2K_MAXRLVLS];
  410. /** initial precinct height */
  411. int prch_init[OPJ_J2K_MAXRLVLS];
  412. /**@name command line encoder parameters (not used inside the library) */
  413. /*@{*/
  414. /** input file name */
  415. char infile[OPJ_PATH_LEN];
  416. /** output file name */
  417. char outfile[OPJ_PATH_LEN];
  418. /** DEPRECATED. Index generation is now handled with the opj_encode_with_info() function. Set to NULL */
  419. int index_on;
  420. /** DEPRECATED. Index generation is now handled with the opj_encode_with_info() function. Set to NULL */
  421. char index[OPJ_PATH_LEN];
  422. /** subimage encoding: origin image offset in x direction */
  423. int image_offset_x0;
  424. /** subimage encoding: origin image offset in y direction */
  425. int image_offset_y0;
  426. /** subsampling value for dx */
  427. int subsampling_dx;
  428. /** subsampling value for dy */
  429. int subsampling_dy;
  430. /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
  431. int decod_format;
  432. /** output file format 0: J2K, 1: JP2, 2: JPT */
  433. int cod_format;
  434. /*@}*/
  435. /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
  436. /**@name JPWL encoding parameters */
  437. /*@{*/
  438. /** enables writing of EPC in MH, thus activating JPWL */
  439. OPJ_BOOL jpwl_epc_on;
  440. /** error protection method for MH (0,1,16,32,37-128) */
  441. int jpwl_hprot_MH;
  442. /** tile number of header protection specification (>=0) */
  443. int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
  444. /** error protection methods for TPHs (0,1,16,32,37-128) */
  445. int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
  446. /** tile number of packet protection specification (>=0) */
  447. int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
  448. /** packet number of packet protection specification (>=0) */
  449. int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
  450. /** error protection methods for packets (0,1,16,32,37-128) */
  451. int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
  452. /** enables writing of ESD, (0=no/1/2 bytes) */
  453. int jpwl_sens_size;
  454. /** sensitivity addressing size (0=auto/2/4 bytes) */
  455. int jpwl_sens_addr;
  456. /** sensitivity range (0-3) */
  457. int jpwl_sens_range;
  458. /** sensitivity method for MH (-1=no,0-7) */
  459. int jpwl_sens_MH;
  460. /** tile number of sensitivity specification (>=0) */
  461. int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
  462. /** sensitivity methods for TPHs (-1=no,0-7) */
  463. int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
  464. /*@}*/
  465. /* <<UniPG */
  466. /**
  467. * DEPRECATED: use RSIZ, OPJ_PROFILE_* and MAX_COMP_SIZE instead
  468. * Digital Cinema compliance 0-not compliant, 1-compliant
  469. * */
  470. OPJ_CINEMA_MODE cp_cinema;
  471. /**
  472. * Maximum size (in bytes) for each component.
  473. * If == 0, component size limitation is not considered
  474. * */
  475. int max_comp_size;
  476. /**
  477. * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
  478. * Profile name
  479. * */
  480. OPJ_RSIZ_CAPABILITIES cp_rsiz;
  481. /** Tile part generation*/
  482. char tp_on;
  483. /** Flag for Tile part generation*/
  484. char tp_flag;
  485. /** MCT (multiple component transform) */
  486. char tcp_mct;
  487. /** Enable JPIP indexing*/
  488. OPJ_BOOL jpip_on;
  489. /** Naive implementation of MCT restricted to a single reversible array based
  490. encoding without offset concerning all the components. */
  491. void * mct_data;
  492. /**
  493. * Maximum size (in bytes) for the whole codestream.
  494. * If == 0, codestream size limitation is not considered
  495. * If it does not comply with tcp_rates, max_cs_size prevails
  496. * and a warning is issued.
  497. * */
  498. int max_cs_size;
  499. /** RSIZ value
  500. To be used to combine OPJ_PROFILE_*, OPJ_EXTENSION_* and (sub)levels values. */
  501. OPJ_UINT16 rsiz;
  502. } opj_cparameters_t;
  503. #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
  504. #define OPJ_DPARAMETERS_DUMP_FLAG 0x0002
  505. /**
  506. * Decompression parameters
  507. * */
  508. typedef struct opj_dparameters {
  509. /**
  510. Set the number of highest resolution levels to be discarded.
  511. The image resolution is effectively divided by 2 to the power of the number of discarded levels.
  512. The reduce factor is limited by the smallest total number of decomposition levels among tiles.
  513. if != 0, then original dimension divided by 2^(reduce);
  514. if == 0 or not used, image is decoded to the full resolution
  515. */
  516. OPJ_UINT32 cp_reduce;
  517. /**
  518. Set the maximum number of quality layers to decode.
  519. If there are less quality layers than the specified number, all the quality layers are decoded.
  520. if != 0, then only the first "layer" layers are decoded;
  521. if == 0 or not used, all the quality layers are decoded
  522. */
  523. OPJ_UINT32 cp_layer;
  524. /**@name command line decoder parameters (not used inside the library) */
  525. /*@{*/
  526. /** input file name */
  527. char infile[OPJ_PATH_LEN];
  528. /** output file name */
  529. char outfile[OPJ_PATH_LEN];
  530. /** input file format 0: J2K, 1: JP2, 2: JPT */
  531. int decod_format;
  532. /** output file format 0: PGX, 1: PxM, 2: BMP */
  533. int cod_format;
  534. /** Decoding area left boundary */
  535. OPJ_UINT32 DA_x0;
  536. /** Decoding area right boundary */
  537. OPJ_UINT32 DA_x1;
  538. /** Decoding area up boundary */
  539. OPJ_UINT32 DA_y0;
  540. /** Decoding area bottom boundary */
  541. OPJ_UINT32 DA_y1;
  542. /** Verbose mode */
  543. OPJ_BOOL m_verbose;
  544. /** tile number of the decoded tile */
  545. OPJ_UINT32 tile_index;
  546. /** Nb of tile to decode */
  547. OPJ_UINT32 nb_tile_to_decode;
  548. /*@}*/
  549. /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
  550. /**@name JPWL decoding parameters */
  551. /*@{*/
  552. /** activates the JPWL correction capabilities */
  553. OPJ_BOOL jpwl_correct;
  554. /** expected number of components */
  555. int jpwl_exp_comps;
  556. /** maximum number of tiles */
  557. int jpwl_max_tiles;
  558. /*@}*/
  559. /* <<UniPG */
  560. unsigned int flags;
  561. } opj_dparameters_t;
  562. /**
  563. * JPEG2000 codec V2.
  564. * */
  565. typedef void * opj_codec_t;
  566. /*
  567. ==========================================================
  568. I/O stream typedef definitions
  569. ==========================================================
  570. */
  571. /**
  572. * Stream open flags.
  573. * */
  574. /** The stream was opened for reading. */
  575. #define OPJ_STREAM_READ OPJ_TRUE
  576. /** The stream was opened for writing. */
  577. #define OPJ_STREAM_WRITE OPJ_FALSE
  578. /*
  579. * Callback function prototype for read function
  580. */
  581. typedef OPJ_SIZE_T(* opj_stream_read_fn)(void * p_buffer, OPJ_SIZE_T p_nb_bytes,
  582. void * p_user_data) ;
  583. /*
  584. * Callback function prototype for write function
  585. */
  586. typedef OPJ_SIZE_T(* opj_stream_write_fn)(void * p_buffer,
  587. OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
  588. /*
  589. * Callback function prototype for skip function
  590. */
  591. typedef OPJ_OFF_T(* opj_stream_skip_fn)(OPJ_OFF_T p_nb_bytes,
  592. void * p_user_data) ;
  593. /*
  594. * Callback function prototype for seek function
  595. */
  596. typedef OPJ_BOOL(* opj_stream_seek_fn)(OPJ_OFF_T p_nb_bytes,
  597. void * p_user_data) ;
  598. /*
  599. * Callback function prototype for free user data function
  600. */
  601. typedef void (* opj_stream_free_user_data_fn)(void * p_user_data) ;
  602. /*
  603. * JPEG2000 Stream.
  604. */
  605. typedef void * opj_stream_t;
  606. /*
  607. ==========================================================
  608. image typedef definitions
  609. ==========================================================
  610. */
  611. /**
  612. * Defines a single image component
  613. * */
  614. typedef struct opj_image_comp {
  615. /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
  616. OPJ_UINT32 dx;
  617. /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
  618. OPJ_UINT32 dy;
  619. /** data width */
  620. OPJ_UINT32 w;
  621. /** data height */
  622. OPJ_UINT32 h;
  623. /** x component offset compared to the whole image */
  624. OPJ_UINT32 x0;
  625. /** y component offset compared to the whole image */
  626. OPJ_UINT32 y0;
  627. /** precision: number of bits per component per pixel */
  628. OPJ_UINT32 prec;
  629. /** obsolete: use prec instead */
  630. OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead");
  631. /** signed (1) / unsigned (0) */
  632. OPJ_UINT32 sgnd;
  633. /** number of decoded resolution */
  634. OPJ_UINT32 resno_decoded;
  635. /** number of division by 2 of the out image compared to the original size of image */
  636. OPJ_UINT32 factor;
  637. /** image component data */
  638. OPJ_INT32 *data;
  639. /** alpha channel */
  640. OPJ_UINT16 alpha;
  641. } opj_image_comp_t;
  642. /**
  643. * Defines image data and characteristics
  644. * */
  645. typedef struct opj_image {
  646. /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
  647. OPJ_UINT32 x0;
  648. /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
  649. OPJ_UINT32 y0;
  650. /** Xsiz: width of the reference grid */
  651. OPJ_UINT32 x1;
  652. /** Ysiz: height of the reference grid */
  653. OPJ_UINT32 y1;
  654. /** number of components in the image */
  655. OPJ_UINT32 numcomps;
  656. /** color space: sRGB, Greyscale or YUV */
  657. OPJ_COLOR_SPACE color_space;
  658. /** image components */
  659. opj_image_comp_t *comps;
  660. /** 'restricted' ICC profile */
  661. OPJ_BYTE *icc_profile_buf;
  662. /** size of ICC profile */
  663. OPJ_UINT32 icc_profile_len;
  664. } opj_image_t;
  665. /**
  666. * Component parameters structure used by the opj_image_create function
  667. * */
  668. typedef struct opj_image_comptparm {
  669. /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
  670. OPJ_UINT32 dx;
  671. /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
  672. OPJ_UINT32 dy;
  673. /** data width */
  674. OPJ_UINT32 w;
  675. /** data height */
  676. OPJ_UINT32 h;
  677. /** x component offset compared to the whole image */
  678. OPJ_UINT32 x0;
  679. /** y component offset compared to the whole image */
  680. OPJ_UINT32 y0;
  681. /** precision: number of bits per component per pixel */
  682. OPJ_UINT32 prec;
  683. /** obsolete: use prec instead */
  684. OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead");
  685. /** signed (1) / unsigned (0) */
  686. OPJ_UINT32 sgnd;
  687. } opj_image_cmptparm_t;
  688. /*
  689. ==========================================================
  690. Information on the JPEG 2000 codestream
  691. ==========================================================
  692. */
  693. /* QUITE EXPERIMENTAL FOR THE MOMENT */
  694. /**
  695. * Index structure : Information concerning a packet inside tile
  696. * */
  697. typedef struct opj_packet_info {
  698. /** packet start position (including SOP marker if it exists) */
  699. OPJ_OFF_T start_pos;
  700. /** end of packet header position (including EPH marker if it exists)*/
  701. OPJ_OFF_T end_ph_pos;
  702. /** packet end position */
  703. OPJ_OFF_T end_pos;
  704. /** packet distorsion */
  705. double disto;
  706. } opj_packet_info_t;
  707. /* UniPG>> */
  708. /**
  709. * Marker structure
  710. * */
  711. typedef struct opj_marker_info {
  712. /** marker type */
  713. unsigned short int type;
  714. /** position in codestream */
  715. OPJ_OFF_T pos;
  716. /** length, marker val included */
  717. int len;
  718. } opj_marker_info_t;
  719. /* <<UniPG */
  720. /**
  721. * Index structure : Information concerning tile-parts
  722. */
  723. typedef struct opj_tp_info {
  724. /** start position of tile part */
  725. int tp_start_pos;
  726. /** end position of tile part header */
  727. int tp_end_header;
  728. /** end position of tile part */
  729. int tp_end_pos;
  730. /** start packet of tile part */
  731. int tp_start_pack;
  732. /** number of packets of tile part */
  733. int tp_numpacks;
  734. } opj_tp_info_t;
  735. /**
  736. * Index structure : information regarding tiles
  737. */
  738. typedef struct opj_tile_info {
  739. /** value of thresh for each layer by tile cfr. Marcela */
  740. double *thresh;
  741. /** number of tile */
  742. int tileno;
  743. /** start position */
  744. int start_pos;
  745. /** end position of the header */
  746. int end_header;
  747. /** end position */
  748. int end_pos;
  749. /** precinct number for each resolution level (width) */
  750. int pw[33];
  751. /** precinct number for each resolution level (height) */
  752. int ph[33];
  753. /** precinct size (in power of 2), in X for each resolution level */
  754. int pdx[33];
  755. /** precinct size (in power of 2), in Y for each resolution level */
  756. int pdy[33];
  757. /** information concerning packets inside tile */
  758. opj_packet_info_t *packet;
  759. /** number of pixels of the tile */
  760. int numpix;
  761. /** distortion of the tile */
  762. double distotile;
  763. /** number of markers */
  764. int marknum;
  765. /** list of markers */
  766. opj_marker_info_t *marker;
  767. /** actual size of markers array */
  768. int maxmarknum;
  769. /** number of tile parts */
  770. int num_tps;
  771. /** information concerning tile parts */
  772. opj_tp_info_t *tp;
  773. } opj_tile_info_t;
  774. /**
  775. * Index structure of the codestream
  776. */
  777. typedef struct opj_codestream_info {
  778. /** maximum distortion reduction on the whole image (add for Marcela) */
  779. double D_max;
  780. /** packet number */
  781. int packno;
  782. /** writing the packet in the index with t2_encode_packets */
  783. int index_write;
  784. /** image width */
  785. int image_w;
  786. /** image height */
  787. int image_h;
  788. /** progression order */
  789. OPJ_PROG_ORDER prog;
  790. /** tile size in x */
  791. int tile_x;
  792. /** tile size in y */
  793. int tile_y;
  794. /** */
  795. int tile_Ox;
  796. /** */
  797. int tile_Oy;
  798. /** number of tiles in X */
  799. int tw;
  800. /** number of tiles in Y */
  801. int th;
  802. /** component numbers */
  803. int numcomps;
  804. /** number of layer */
  805. int numlayers;
  806. /** number of decomposition for each component */
  807. int *numdecompos;
  808. /* UniPG>> */
  809. /** number of markers */
  810. int marknum;
  811. /** list of markers */
  812. opj_marker_info_t *marker;
  813. /** actual size of markers array */
  814. int maxmarknum;
  815. /* <<UniPG */
  816. /** main header position */
  817. int main_head_start;
  818. /** main header position */
  819. int main_head_end;
  820. /** codestream's size */
  821. int codestream_size;
  822. /** information regarding tiles inside image */
  823. opj_tile_info_t *tile;
  824. } opj_codestream_info_t;
  825. /* <----------------------------------------------------------- */
  826. /* new output management of the codestream information and index */
  827. /**
  828. * Tile-component coding parameters information
  829. */
  830. typedef struct opj_tccp_info {
  831. /** component index */
  832. OPJ_UINT32 compno;
  833. /** coding style */
  834. OPJ_UINT32 csty;
  835. /** number of resolutions */
  836. OPJ_UINT32 numresolutions;
  837. /** log2 of code-blocks width */
  838. OPJ_UINT32 cblkw;
  839. /** log2 of code-blocks height */
  840. OPJ_UINT32 cblkh;
  841. /** code-block coding style */
  842. OPJ_UINT32 cblksty;
  843. /** discrete wavelet transform identifier: 0 = 9-7 irreversible, 1 = 5-3 reversible */
  844. OPJ_UINT32 qmfbid;
  845. /** quantisation style */
  846. OPJ_UINT32 qntsty;
  847. /** stepsizes used for quantization */
  848. OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
  849. /** stepsizes used for quantization */
  850. OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
  851. /** number of guard bits */
  852. OPJ_UINT32 numgbits;
  853. /** Region Of Interest shift */
  854. OPJ_INT32 roishift;
  855. /** precinct width */
  856. OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
  857. /** precinct height */
  858. OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
  859. }
  860. opj_tccp_info_t;
  861. /**
  862. * Tile coding parameters information
  863. */
  864. typedef struct opj_tile_v2_info {
  865. /** number (index) of tile */
  866. int tileno;
  867. /** coding style */
  868. OPJ_UINT32 csty;
  869. /** progression order */
  870. OPJ_PROG_ORDER prg;
  871. /** number of layers */
  872. OPJ_UINT32 numlayers;
  873. /** multi-component transform identifier */
  874. OPJ_UINT32 mct;
  875. /** information concerning tile component parameters*/
  876. opj_tccp_info_t *tccp_info;
  877. } opj_tile_info_v2_t;
  878. /**
  879. * Information structure about the codestream (FIXME should be expand and enhance)
  880. */
  881. typedef struct opj_codestream_info_v2 {
  882. /* Tile info */
  883. /** tile origin in x = XTOsiz */
  884. OPJ_UINT32 tx0;
  885. /** tile origin in y = YTOsiz */
  886. OPJ_UINT32 ty0;
  887. /** tile size in x = XTsiz */
  888. OPJ_UINT32 tdx;
  889. /** tile size in y = YTsiz */
  890. OPJ_UINT32 tdy;
  891. /** number of tiles in X */
  892. OPJ_UINT32 tw;
  893. /** number of tiles in Y */
  894. OPJ_UINT32 th;
  895. /** number of components*/
  896. OPJ_UINT32 nbcomps;
  897. /** Default information regarding tiles inside image */
  898. opj_tile_info_v2_t m_default_tile_info;
  899. /** information regarding tiles inside image */
  900. opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
  901. } opj_codestream_info_v2_t;
  902. /**
  903. * Index structure about a tile part
  904. */
  905. typedef struct opj_tp_index {
  906. /** start position */
  907. OPJ_OFF_T start_pos;
  908. /** end position of the header */
  909. OPJ_OFF_T end_header;
  910. /** end position */
  911. OPJ_OFF_T end_pos;
  912. } opj_tp_index_t;
  913. /**
  914. * Index structure about a tile
  915. */
  916. typedef struct opj_tile_index {
  917. /** tile index */
  918. OPJ_UINT32 tileno;
  919. /** number of tile parts */
  920. OPJ_UINT32 nb_tps;
  921. /** current nb of tile part (allocated)*/
  922. OPJ_UINT32 current_nb_tps;
  923. /** current tile-part index */
  924. OPJ_UINT32 current_tpsno;
  925. /** information concerning tile parts */
  926. opj_tp_index_t *tp_index;
  927. /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
  928. /** number of markers */
  929. OPJ_UINT32 marknum;
  930. /** list of markers */
  931. opj_marker_info_t *marker;
  932. /** actual size of markers array */
  933. OPJ_UINT32 maxmarknum;
  934. /* <<UniPG */
  935. /** packet number */
  936. OPJ_UINT32 nb_packet;
  937. /** information concerning packets inside tile */
  938. opj_packet_info_t *packet_index;
  939. } opj_tile_index_t;
  940. /**
  941. * Index structure of the codestream (FIXME should be expand and enhance)
  942. */
  943. typedef struct opj_codestream_index {
  944. /** main header start position (SOC position) */
  945. OPJ_OFF_T main_head_start;
  946. /** main header end position (first SOT position) */
  947. OPJ_OFF_T main_head_end;
  948. /** codestream's size */
  949. OPJ_UINT64 codestream_size;
  950. /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
  951. /** number of markers */
  952. OPJ_UINT32 marknum;
  953. /** list of markers */
  954. opj_marker_info_t *marker;
  955. /** actual size of markers array */
  956. OPJ_UINT32 maxmarknum;
  957. /* <<UniPG */
  958. /** */
  959. OPJ_UINT32 nb_of_tiles;
  960. /** */
  961. opj_tile_index_t *tile_index; /* FIXME not used for the moment */
  962. } opj_codestream_index_t;
  963. /* -----------------------------------------------------------> */
  964. /*
  965. ==========================================================
  966. Metadata from the JP2file
  967. ==========================================================
  968. */
  969. /**
  970. * Info structure of the JP2 file
  971. * EXPERIMENTAL FOR THE MOMENT
  972. */
  973. typedef struct opj_jp2_metadata {
  974. /** */
  975. OPJ_INT32 not_used;
  976. } opj_jp2_metadata_t;
  977. /**
  978. * Index structure of the JP2 file
  979. * EXPERIMENTAL FOR THE MOMENT
  980. */
  981. typedef struct opj_jp2_index {
  982. /** */
  983. OPJ_INT32 not_used;
  984. } opj_jp2_index_t;
  985. #ifdef __cplusplus
  986. extern "C" {
  987. #endif
  988. /*
  989. ==========================================================
  990. openjpeg version
  991. ==========================================================
  992. */
  993. /* Get the version of the openjpeg library*/
  994. OPJ_API const char * OPJ_CALLCONV opj_version(void);
  995. /*
  996. ==========================================================
  997. image functions definitions
  998. ==========================================================
  999. */
  1000. /**
  1001. * Create an image
  1002. *
  1003. * @param numcmpts number of components
  1004. * @param cmptparms components parameters
  1005. * @param clrspc image color space
  1006. * @return returns a new image structure if successful, returns NULL otherwise
  1007. * */
  1008. OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts,
  1009. opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
  1010. /**
  1011. * Deallocate any resources associated with an image
  1012. *
  1013. * @param image image to be destroyed
  1014. */
  1015. OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
  1016. /**
  1017. * Creates an image without allocating memory for the image (used in the new version of the library).
  1018. *
  1019. * @param numcmpts the number of components
  1020. * @param cmptparms the components parameters
  1021. * @param clrspc the image color space
  1022. *
  1023. * @return a new image structure if successful, NULL otherwise.
  1024. */
  1025. OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts,
  1026. opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
  1027. /**
  1028. * Allocator for opj_image_t->comps[].data
  1029. * To be paired with opj_image_data_free.
  1030. *
  1031. * @param size number of bytes to allocate
  1032. *
  1033. * @return a new pointer if successful, NULL otherwise.
  1034. * @since 2.2.0
  1035. */
  1036. OPJ_API void* OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size);
  1037. /**
  1038. * Destructor for opj_image_t->comps[].data
  1039. * To be paired with opj_image_data_alloc.
  1040. *
  1041. * @param ptr Pointer to free
  1042. *
  1043. * @since 2.2.0
  1044. */
  1045. OPJ_API void OPJ_CALLCONV opj_image_data_free(void* ptr);
  1046. /*
  1047. ==========================================================
  1048. stream functions definitions
  1049. ==========================================================
  1050. */
  1051. /**
  1052. * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
  1053. *
  1054. * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
  1055. *
  1056. * @return a stream object.
  1057. */
  1058. OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(
  1059. OPJ_BOOL p_is_input);
  1060. /**
  1061. * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
  1062. *
  1063. * @param p_buffer_size FIXME DOC
  1064. * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
  1065. *
  1066. * @return a stream object.
  1067. */
  1068. OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,
  1069. OPJ_BOOL p_is_input);
  1070. /**
  1071. * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
  1072. * close its own implementation of the stream.
  1073. *
  1074. * @param p_stream the stream to destroy.
  1075. */
  1076. OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
  1077. /**
  1078. * Sets the given function to be used as a read function.
  1079. * @param p_stream the stream to modify
  1080. * @param p_function the function to use a read function.
  1081. */
  1082. OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream,
  1083. opj_stream_read_fn p_function);
  1084. /**
  1085. * Sets the given function to be used as a write function.
  1086. * @param p_stream the stream to modify
  1087. * @param p_function the function to use a write function.
  1088. */
  1089. OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream,
  1090. opj_stream_write_fn p_function);
  1091. /**
  1092. * Sets the given function to be used as a skip function.
  1093. * @param p_stream the stream to modify
  1094. * @param p_function the function to use a skip function.
  1095. */
  1096. OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream,
  1097. opj_stream_skip_fn p_function);
  1098. /**
  1099. * Sets the given function to be used as a seek function, the stream is then seekable,
  1100. * using SEEK_SET behavior.
  1101. * @param p_stream the stream to modify
  1102. * @param p_function the function to use a skip function.
  1103. */
  1104. OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream,
  1105. opj_stream_seek_fn p_function);
  1106. /**
  1107. * Sets the given data to be used as a user data for the stream.
  1108. * @param p_stream the stream to modify
  1109. * @param p_data the data to set.
  1110. * @param p_function the function to free p_data when opj_stream_destroy() is called.
  1111. */
  1112. OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream,
  1113. void * p_data, opj_stream_free_user_data_fn p_function);
  1114. /**
  1115. * Sets the length of the user data for the stream.
  1116. *
  1117. * @param p_stream the stream to modify
  1118. * @param data_length length of the user_data.
  1119. */
  1120. OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(
  1121. opj_stream_t* p_stream, OPJ_UINT64 data_length);
  1122. /**
  1123. * Create a stream from a file identified with its filename with default parameters (helper function)
  1124. * @param fname the filename of the file to stream
  1125. * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
  1126. */
  1127. OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream(
  1128. const char *fname, OPJ_BOOL p_is_read_stream);
  1129. /** Create a stream from a file identified with its filename with a specific buffer size
  1130. * @param fname the filename of the file to stream
  1131. * @param p_buffer_size size of the chunk used to stream
  1132. * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
  1133. */
  1134. OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream(
  1135. const char *fname,
  1136. OPJ_SIZE_T p_buffer_size,
  1137. OPJ_BOOL p_is_read_stream);
  1138. /*
  1139. ==========================================================
  1140. event manager functions definitions
  1141. ==========================================================
  1142. */
  1143. /**
  1144. * Set the info handler use by openjpeg.
  1145. * @param p_codec the codec previously initialise
  1146. * @param p_callback the callback function which will be used
  1147. * @param p_user_data client object where will be returned the message
  1148. */
  1149. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec,
  1150. opj_msg_callback p_callback,
  1151. void * p_user_data);
  1152. /**
  1153. * Set the warning handler use by openjpeg.
  1154. * @param p_codec the codec previously initialise
  1155. * @param p_callback the callback function which will be used
  1156. * @param p_user_data client object where will be returned the message
  1157. */
  1158. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
  1159. opj_msg_callback p_callback,
  1160. void * p_user_data);
  1161. /**
  1162. * Set the error handler use by openjpeg.
  1163. * @param p_codec the codec previously initialise
  1164. * @param p_callback the callback function which will be used
  1165. * @param p_user_data client object where will be returned the message
  1166. */
  1167. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
  1168. opj_msg_callback p_callback,
  1169. void * p_user_data);
  1170. /*
  1171. ==========================================================
  1172. codec functions definitions
  1173. ==========================================================
  1174. */
  1175. /**
  1176. * Creates a J2K/JP2 decompression structure
  1177. * @param format Decoder to select
  1178. *
  1179. * @return Returns a handle to a decompressor if successful, returns NULL otherwise
  1180. * */
  1181. OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(
  1182. OPJ_CODEC_FORMAT format);
  1183. /**
  1184. * Destroy a decompressor handle
  1185. *
  1186. * @param p_codec decompressor handle to destroy
  1187. */
  1188. OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
  1189. /**
  1190. * Read after the codestream if necessary
  1191. * @param p_codec the JPEG2000 codec to read.
  1192. * @param p_stream the JPEG2000 stream.
  1193. */
  1194. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress(opj_codec_t *p_codec,
  1195. opj_stream_t *p_stream);
  1196. /**
  1197. * Set decoding parameters to default values
  1198. * @param parameters Decompression parameters
  1199. */
  1200. OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(
  1201. opj_dparameters_t *parameters);
  1202. /**
  1203. * Setup the decoder with decompression parameters provided by the user and with the message handler
  1204. * provided by the user.
  1205. *
  1206. * @param p_codec decompressor handler
  1207. * @param parameters decompression parameters
  1208. *
  1209. * @return true if the decoder is correctly set
  1210. */
  1211. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
  1212. opj_dparameters_t *parameters);
  1213. /**
  1214. * Set strict decoding parameter for this decoder. If strict decoding is enabled, partial bit
  1215. * streams will fail to decode. If strict decoding is disabled, the decoder will decode partial
  1216. * bitstreams as much as possible without erroring
  1217. *
  1218. * @param p_codec decompressor handler
  1219. * @param strict OPJ_TRUE to enable strict decoding, OPJ_FALSE to disable
  1220. *
  1221. * @return true if the decoder is correctly set
  1222. */
  1223. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec,
  1224. OPJ_BOOL strict);
  1225. /**
  1226. * Allocates worker threads for the compressor/decompressor.
  1227. *
  1228. * By default, only the main thread is used. If this function is not used,
  1229. * but the OPJ_NUM_THREADS environment variable is set, its value will be
  1230. * used to initialize the number of threads. The value can be either an integer
  1231. * number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called,
  1232. * this function will override the behaviour of the environment variable.
  1233. *
  1234. * This function must be called after opj_setup_decoder() and
  1235. * before opj_read_header() for the decoding side, or after opj_setup_encoder()
  1236. * and before opj_start_compress() for the encoding side.
  1237. *
  1238. * @param p_codec decompressor or compressor handler
  1239. * @param num_threads number of threads.
  1240. *
  1241. * @return OPJ_TRUE if the function is successful.
  1242. */
  1243. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec,
  1244. int num_threads);
  1245. /**
  1246. * Decodes an image header.
  1247. *
  1248. * @param p_stream the jpeg2000 stream.
  1249. * @param p_codec the jpeg2000 codec to read.
  1250. * @param p_image the image structure initialized with the characteristics of encoded image.
  1251. *
  1252. * @return true if the main header of the codestream and the JP2 header is correctly read.
  1253. */
  1254. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream,
  1255. opj_codec_t *p_codec,
  1256. opj_image_t **p_image);
  1257. /** Restrict the number of components to decode.
  1258. *
  1259. * This function should be called after opj_read_header().
  1260. *
  1261. * This function enables to restrict the set of decoded components to the
  1262. * specified indices.
  1263. * Note that the current implementation (apply_color_transforms == OPJ_FALSE)
  1264. * is such that neither the multi-component transform at codestream level,
  1265. * nor JP2 channel transformations will be applied.
  1266. * Consequently the indices are relative to the codestream.
  1267. *
  1268. * Note: opj_decode_tile_data() should not be used together with opj_set_decoded_components().
  1269. *
  1270. * @param p_codec the jpeg2000 codec to read.
  1271. * @param numcomps Size of the comps_indices array.
  1272. * @param comps_indices Array of numcomps values representing the indices
  1273. * of the components to decode (relative to the
  1274. * codestream, starting at 0)
  1275. * @param apply_color_transforms Whether multi-component transform at codestream level
  1276. * or JP2 channel transformations should be applied.
  1277. * Currently this parameter should be set to OPJ_FALSE.
  1278. * Setting it to OPJ_TRUE will result in an error.
  1279. *
  1280. * @return OPJ_TRUE in case of success.
  1281. */
  1282. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec,
  1283. OPJ_UINT32 numcomps,
  1284. const OPJ_UINT32* comps_indices,
  1285. OPJ_BOOL apply_color_transforms);
  1286. /**
  1287. * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
  1288. *
  1289. * The coordinates passed to this function should be expressed in the reference grid,
  1290. * that is to say at the highest resolution level, even if requesting the image at lower
  1291. * resolution levels.
  1292. *
  1293. * Generally opj_set_decode_area() should be followed by opj_decode(), and the
  1294. * codec cannot be re-used.
  1295. * In the particular case of an image made of a single tile, several sequences of
  1296. * calls to opoj_set_decode_area() and opj_decode() are allowed, and will bring
  1297. * performance improvements when reading an image by chunks.
  1298. *
  1299. * @param p_codec the jpeg2000 codec.
  1300. * @param p_image the decoded image previously set by opj_read_header
  1301. * @param p_start_x the left position of the rectangle to decode (in image coordinates).
  1302. * @param p_end_x the right position of the rectangle to decode (in image coordinates).
  1303. * @param p_start_y the up position of the rectangle to decode (in image coordinates).
  1304. * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
  1305. *
  1306. * @return true if the area could be set.
  1307. */
  1308. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec,
  1309. opj_image_t* p_image,
  1310. OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
  1311. OPJ_INT32 p_end_x, OPJ_INT32 p_end_y);
  1312. /**
  1313. * Decode an image from a JPEG-2000 codestream
  1314. *
  1315. * @param p_decompressor decompressor handle
  1316. * @param p_stream Input buffer stream
  1317. * @param p_image the decoded image
  1318. * @return true if success, otherwise false
  1319. * */
  1320. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor,
  1321. opj_stream_t *p_stream,
  1322. opj_image_t *p_image);
  1323. /**
  1324. * Get the decoded tile from the codec
  1325. *
  1326. * @param p_codec the jpeg2000 codec.
  1327. * @param p_stream input stream
  1328. * @param p_image output image
  1329. * @param tile_index index of the tile which will be decode
  1330. *
  1331. * @return true if success, otherwise false
  1332. */
  1333. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(opj_codec_t *p_codec,
  1334. opj_stream_t *p_stream,
  1335. opj_image_t *p_image,
  1336. OPJ_UINT32 tile_index);
  1337. /**
  1338. * Set the resolution factor of the decoded image
  1339. * @param p_codec the jpeg2000 codec.
  1340. * @param res_factor resolution factor to set
  1341. *
  1342. * @return true if success, otherwise false
  1343. */
  1344. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(
  1345. opj_codec_t *p_codec, OPJ_UINT32 res_factor);
  1346. /**
  1347. * Writes a tile with the given data.
  1348. *
  1349. * @param p_codec the jpeg2000 codec.
  1350. * @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
  1351. * @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
  1352. * @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of
  1353. * tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
  1354. * @param p_stream the stream to write data to.
  1355. *
  1356. * @return true if the data could be written.
  1357. */
  1358. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec,
  1359. OPJ_UINT32 p_tile_index,
  1360. OPJ_BYTE * p_data,
  1361. OPJ_UINT32 p_data_size,
  1362. opj_stream_t *p_stream);
  1363. /**
  1364. * Reads a tile header. This function is compulsory and allows one to know the size of the tile that will be decoded.
  1365. * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
  1366. *
  1367. * @param p_codec the jpeg2000 codec.
  1368. * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
  1369. * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
  1370. * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
  1371. * as depicted in opj_write_tile.
  1372. * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
  1373. * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
  1374. * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
  1375. * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
  1376. * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
  1377. * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
  1378. * codestream is over at the time of the call, the value will be set to false. The user should then stop
  1379. * the decoding.
  1380. * @param p_stream the stream to decode.
  1381. * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
  1382. * returning false may be the result of a shortage of memory or an internal error.
  1383. */
  1384. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec,
  1385. opj_stream_t * p_stream,
  1386. OPJ_UINT32 * p_tile_index,
  1387. OPJ_UINT32 * p_data_size,
  1388. OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
  1389. OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
  1390. OPJ_UINT32 * p_nb_comps,
  1391. OPJ_BOOL * p_should_go_on);
  1392. /**
  1393. * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
  1394. * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
  1395. *
  1396. * Note: opj_decode_tile_data() should not be used together with opj_set_decoded_components().
  1397. *
  1398. * @param p_codec the jpeg2000 codec.
  1399. * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
  1400. * @param p_data pointer to a memory block that will hold the decoded data.
  1401. * @param p_data_size size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
  1402. * @param p_stream the stream to decode.
  1403. *
  1404. * @return true if the data could be decoded.
  1405. */
  1406. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec,
  1407. OPJ_UINT32 p_tile_index,
  1408. OPJ_BYTE * p_data,
  1409. OPJ_UINT32 p_data_size,
  1410. opj_stream_t *p_stream);
  1411. /* COMPRESSION FUNCTIONS*/
  1412. /**
  1413. * Creates a J2K/JP2 compression structure
  1414. * @param format Coder to select
  1415. * @return Returns a handle to a compressor if successful, returns NULL otherwise
  1416. */
  1417. OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
  1418. /**
  1419. Set encoding parameters to default values, that means :
  1420. <ul>
  1421. <li>Lossless
  1422. <li>1 tile
  1423. <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
  1424. <li>Size of code-block : 64 x 64
  1425. <li>Number of resolutions: 6
  1426. <li>No SOP marker in the codestream
  1427. <li>No EPH marker in the codestream
  1428. <li>No sub-sampling in x or y direction
  1429. <li>No mode switch activated
  1430. <li>Progression order: LRCP
  1431. <li>No index file
  1432. <li>No ROI upshifted
  1433. <li>No offset of the origin of the image
  1434. <li>No offset of the origin of the tiles
  1435. <li>Reversible DWT 5-3
  1436. </ul>
  1437. @param parameters Compression parameters
  1438. */
  1439. OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(
  1440. opj_cparameters_t *parameters);
  1441. /**
  1442. * Setup the encoder parameters using the current image and using user parameters.
  1443. * @param p_codec Compressor handle
  1444. * @param parameters Compression parameters
  1445. * @param image Input filled image
  1446. */
  1447. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
  1448. opj_cparameters_t *parameters,
  1449. opj_image_t *image);
  1450. /**
  1451. * Specify extra options for the encoder.
  1452. *
  1453. * This may be called after opj_setup_encoder() and before opj_start_compress()
  1454. *
  1455. * This is the way to add new options in a fully ABI compatible way, without
  1456. * extending the opj_cparameters_t structure.
  1457. *
  1458. * Currently supported options are:
  1459. * <ul>
  1460. * <li>PLT=YES/NO. Defaults to NO. If set to YES, PLT marker segments,
  1461. * indicating the length of each packet in the tile-part header, will be
  1462. * written. Since 2.4.0</li>
  1463. * <li>TLM=YES/NO. Defaults to NO (except for Cinema and IMF profiles).
  1464. * If set to YES, TLM marker segments, indicating the length of each
  1465. * tile-part part will be written. Since 2.4.0</li>
  1466. * <li>GUARD_BITS=value. Number of guard bits in [0,7] range. Default value is 2.
  1467. * 1 may be used sometimes (like in SMPTE DCP Bv2.1 Application Profile for 2K images).
  1468. * Since 2.5.0</li>
  1469. * </ul>
  1470. *
  1471. * @param p_codec Compressor handle
  1472. * @param p_options Compression options. This should be a NULL terminated
  1473. * array of strings. Each string is of the form KEY=VALUE.
  1474. *
  1475. * @return OPJ_TRUE in case of success.
  1476. * @since 2.4.0
  1477. */
  1478. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options(
  1479. opj_codec_t *p_codec,
  1480. const char* const* p_options);
  1481. /**
  1482. * Start to compress the current image.
  1483. * @param p_codec Compressor handle
  1484. * @param p_image Input filled image
  1485. * @param p_stream Input stgream
  1486. */
  1487. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec,
  1488. opj_image_t * p_image,
  1489. opj_stream_t *p_stream);
  1490. /**
  1491. * End to compress the current image.
  1492. * @param p_codec Compressor handle
  1493. * @param p_stream Input stgream
  1494. */
  1495. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec,
  1496. opj_stream_t *p_stream);
  1497. /**
  1498. * Encode an image into a JPEG-2000 codestream
  1499. * @param p_codec compressor handle
  1500. * @param p_stream Output buffer stream
  1501. *
  1502. * @return Returns true if successful, returns false otherwise
  1503. */
  1504. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
  1505. opj_stream_t *p_stream);
  1506. /*
  1507. ==========================================================
  1508. codec output functions definitions
  1509. ==========================================================
  1510. */
  1511. /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
  1512. /**
  1513. Destroy Codestream information after compression or decompression
  1514. @param cstr_info Codestream information structure
  1515. */
  1516. OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t
  1517. **cstr_info);
  1518. /**
  1519. * Dump the codec information into the output stream
  1520. *
  1521. * @param p_codec the jpeg2000 codec.
  1522. * @param info_flag type of information dump.
  1523. * @param output_stream output stream where dump the information gotten from the codec.
  1524. *
  1525. */
  1526. OPJ_API void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec,
  1527. OPJ_INT32 info_flag,
  1528. FILE* output_stream);
  1529. /**
  1530. * Get the codestream information from the codec
  1531. *
  1532. * @param p_codec the jpeg2000 codec.
  1533. *
  1534. * @return a pointer to a codestream information structure.
  1535. *
  1536. */
  1537. OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(
  1538. opj_codec_t *p_codec);
  1539. /**
  1540. * Get the codestream index from the codec
  1541. *
  1542. * @param p_codec the jpeg2000 codec.
  1543. *
  1544. * @return a pointer to a codestream index structure.
  1545. *
  1546. */
  1547. OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(
  1548. opj_codec_t *p_codec);
  1549. OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t
  1550. **p_cstr_index);
  1551. /**
  1552. * Get the JP2 file information from the codec FIXME
  1553. *
  1554. * @param p_codec the jpeg2000 codec.
  1555. *
  1556. * @return a pointer to a JP2 metadata structure.
  1557. *
  1558. */
  1559. OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(
  1560. opj_codec_t *p_codec);
  1561. /**
  1562. * Get the JP2 file index from the codec FIXME
  1563. *
  1564. * @param p_codec the jpeg2000 codec.
  1565. *
  1566. * @return a pointer to a JP2 index structure.
  1567. *
  1568. */
  1569. OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
  1570. /*
  1571. ==========================================================
  1572. MCT functions
  1573. ==========================================================
  1574. */
  1575. /**
  1576. * Sets the MCT matrix to use.
  1577. *
  1578. * @param parameters the parameters to change.
  1579. * @param pEncodingMatrix the encoding matrix.
  1580. * @param p_dc_shift the dc shift coefficients to use.
  1581. * @param pNbComp the number of components of the image.
  1582. *
  1583. * @return true if the parameters could be set.
  1584. */
  1585. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
  1586. OPJ_FLOAT32 * pEncodingMatrix,
  1587. OPJ_INT32 * p_dc_shift,
  1588. OPJ_UINT32 pNbComp);
  1589. /*
  1590. ==========================================================
  1591. Thread functions
  1592. ==========================================================
  1593. */
  1594. /** Returns if the library is built with thread support.
  1595. * OPJ_TRUE if mutex, condition, thread, thread pool are available.
  1596. */
  1597. OPJ_API OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void);
  1598. /** Return the number of virtual CPUs */
  1599. OPJ_API int OPJ_CALLCONV opj_get_num_cpus(void);
  1600. #ifdef __cplusplus
  1601. }
  1602. #endif
  1603. #endif /* OPENJPEG_H */