openjpeg.h 63 KB

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