dicom.h 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805
  1. #include <stdbool.h>
  2. #include <stdint.h>
  3. #include <stdio.h>
  4. #include "version.h"
  5. #ifndef DCM_INCLUDED
  6. #define DCM_INCLUDED
  7. #ifdef _WIN32
  8. #if DCM_STATIC
  9. #define DCM_EXTERN extern
  10. #elif defined(BUILDING_LIBDICOM)
  11. #define DCM_EXTERN __declspec(dllexport) extern
  12. #else
  13. #define DCM_EXTERN __declspec(dllimport) extern
  14. #endif
  15. #else
  16. #define DCM_EXTERN __attribute__((visibility("default"))) extern
  17. #endif
  18. /**
  19. * Maximum number of characters in values with Value Representation AE.
  20. */
  21. #define DCM_CAPACITY_AE 16
  22. /**
  23. * Maximum number of characters in values with Value Representation AS.
  24. */
  25. #define DCM_CAPACITY_AS 4
  26. /**
  27. * Maximum number of characters in values with Value Representation AT.
  28. */
  29. #define DCM_CAPACITY_AT 4
  30. /**
  31. * Maximum number of characters in values with Value Representation CS.
  32. */
  33. #define DCM_CAPACITY_CS 16
  34. /**
  35. * Maximum number of characters in values with Value Representation DA.
  36. */
  37. #define DCM_CAPACITY_DA 8
  38. /**
  39. * Maximum number of characters in values with Value Representation DS.
  40. */
  41. #define DCM_CAPACITY_DS 16
  42. /**
  43. * Maximum number of characters in values with Value Representation DT.
  44. */
  45. #define DCM_CAPACITY_DT 26
  46. /**
  47. * Maximum number of characters in values with Value Representation IS.
  48. */
  49. #define DCM_CAPACITY_IS 12
  50. /**
  51. * Maximum number of characters in values with Value Representation LO.
  52. */
  53. #define DCM_CAPACITY_LO 64
  54. /**
  55. * Maximum number of characters in values with Value Representation LT.
  56. */
  57. #define DCM_CAPACITY_LT 10240
  58. /**
  59. * Maximum number of characters in values with Value Representation PN.
  60. */
  61. #define DCM_CAPACITY_PN 64
  62. /**
  63. * Maximum number of characters in values with Value Representation SH.
  64. */
  65. #define DCM_CAPACITY_SH 16
  66. /**
  67. * Maximum number of characters in values with Value Representation ST.
  68. */
  69. #define DCM_CAPACITY_ST 1024
  70. /**
  71. * Maximum number of characters in values with Value Representation TM.
  72. */
  73. #define DCM_CAPACITY_TM 14
  74. /**
  75. * Maximum number of characters in values with Value Representation UC.
  76. */
  77. #define DCM_CAPACITY_UC 4294967294
  78. /**
  79. * Maximum number of characters in values with Value Representation UI.
  80. */
  81. #define DCM_CAPACITY_UI 64
  82. /**
  83. * Maximum number of characters in values with Value Representation UR.
  84. */
  85. #define DCM_CAPACITY_UR 4294967294
  86. /**
  87. * Maximum number of characters in values with Value Representation UT.
  88. */
  89. #define DCM_CAPACITY_UT 4294967294
  90. /* We need forward references for these types.
  91. */
  92. typedef struct _DcmSequence DcmSequence;
  93. /**
  94. * Start up libdicom.
  95. *
  96. * Call this from the main thread during program startup for libdicom to be
  97. * threadsafe.
  98. *
  99. * If you don't do this, libdicom will attempt to call it for you in a safe
  100. * way, but cannot guarantee this on all platforms and with all compilers, and
  101. * therefore cannot guarantee thread safety.
  102. *
  103. * This function can be called many times.
  104. */
  105. DCM_EXTERN
  106. void dcm_init(void);
  107. /* Our copy of getopt, since non-glibc platforms are missing this.
  108. * Used by our tools.
  109. */
  110. DCM_EXTERN
  111. char *dcm_optarg;
  112. DCM_EXTERN
  113. int dcm_optind, dcm_opterr, dcm_optopt, dcm_optreset;
  114. DCM_EXTERN
  115. int dcm_getopt(int nargc, char * const nargv[], const char *ostr);
  116. /**
  117. * Error return object.
  118. */
  119. typedef struct _DcmError DcmError;
  120. /**
  121. * Enumeration of error codes.
  122. */
  123. typedef enum _DcmErrorCode {
  124. /** Out of memory */
  125. DCM_ERROR_CODE_NOMEM = 1,
  126. /** Invalid parameter */
  127. DCM_ERROR_CODE_INVALID = 2,
  128. /** Parse error */
  129. DCM_ERROR_CODE_PARSE = 3,
  130. /** IO error */
  131. DCM_ERROR_CODE_IO = 4,
  132. /** Missing frame */
  133. DCM_ERROR_CODE_MISSING_FRAME = 5,
  134. } DcmErrorCode;
  135. /**
  136. * Convert an error code to a human-readable string.
  137. *
  138. * :param code: The error code
  139. *
  140. * :return: A string that can be displayed to users
  141. */
  142. DCM_EXTERN
  143. const char *dcm_error_code_str(DcmErrorCode code);
  144. /**
  145. * Get a symbolic name for a DcmErrorCode.
  146. *
  147. * :param code: The error code
  148. *
  149. * :return: A symbolic name for the code.
  150. */
  151. DCM_EXTERN
  152. const char *dcm_error_code_name(DcmErrorCode code);
  153. /**
  154. * Set an error.
  155. *
  156. * Create a new DcmError object and store the pointer in error.
  157. *
  158. * You can't set error twice -- always check the error state and return
  159. * immediately if set.
  160. *
  161. * :param error: Pointer to store the new error object in
  162. * :param code: Numeric error code
  163. * :param summary: Summary of error
  164. * :param format: printf-style format string
  165. * :param ...: Format string arguments
  166. */
  167. DCM_EXTERN
  168. void dcm_error_set(DcmError **error, DcmErrorCode code,
  169. const char *summary, const char *format, ...);
  170. /**
  171. * Clear an error, if set.
  172. *
  173. * :param error: Pointer holding the error object
  174. */
  175. DCM_EXTERN
  176. void dcm_error_clear(DcmError **error);
  177. /**
  178. * Get a summary of the error.
  179. *
  180. * Do not free this result. The pointer will be valid as long as error is
  181. * valid.
  182. *
  183. * :param error: DcmError to read the error from
  184. *
  185. * :return: Short description of the error
  186. */
  187. DCM_EXTERN
  188. const char *dcm_error_get_summary(DcmError *error);
  189. /**
  190. * Get the error message.
  191. *
  192. * Do not free this result. The pointer will be valid as long as error is
  193. * valid.
  194. *
  195. * :param error: Error object
  196. *
  197. * :return: Message stored in a error object
  198. */
  199. DCM_EXTERN
  200. const char *dcm_error_get_message(DcmError *error);
  201. /**
  202. * Get the error code.
  203. *
  204. * :param error: Error object
  205. *
  206. * :return: Error code
  207. */
  208. DCM_EXTERN
  209. DcmErrorCode dcm_error_get_code(DcmError *error);
  210. /**
  211. * Log an error message using information stored on the error object.
  212. *
  213. * :param error: Error object
  214. */
  215. DCM_EXTERN
  216. void dcm_error_log(DcmError *error);
  217. /**
  218. * Print an error message to stderr.
  219. *
  220. * :param error: Error object
  221. */
  222. DCM_EXTERN
  223. void dcm_error_print(DcmError *error);
  224. /**
  225. * Free an allocated memory area.
  226. *
  227. * Any memory allocated by libdicom and returned to the calling program
  228. * should be freed with this.
  229. *
  230. * :param pointer: Memory area to free
  231. */
  232. DCM_EXTERN
  233. void dcm_free(void *pointer);
  234. /**
  235. * Allocate and zero an area of memory.
  236. *
  237. * Any memory which you pass to libdicom and which you ask libdicom to manage
  238. * with a "steal" flag should be allcoatyed with one of the libdicom memory
  239. * allocators.
  240. *
  241. * :param error: Pointer to error object
  242. * :param n: Number of items to allocate
  243. * :param size: Size of each item in bytes
  244. *
  245. * :return: Pointer to memory area
  246. */
  247. DCM_EXTERN
  248. void *dcm_calloc(DcmError **error, uint64_t n, uint64_t size);
  249. /**
  250. * Enumeration of log levels
  251. */
  252. typedef enum _DcmLogLevel {
  253. /** Critical */
  254. DCM_LOG_CRITICAL = 50,
  255. /** Error */
  256. DCM_LOG_ERROR = 40,
  257. /** Warning */
  258. DCM_LOG_WARNING = 30,
  259. /** Info */
  260. DCM_LOG_INFO = 20,
  261. /** Debug */
  262. DCM_LOG_DEBUG = 10,
  263. /** Not set (no logging) */
  264. DCM_LOG_NOTSET = 0,
  265. } DcmLogLevel;
  266. /**
  267. * Set the log level.
  268. *
  269. * :param log_level: New log level.
  270. * :return: previous log level
  271. */
  272. DCM_EXTERN
  273. DcmLogLevel dcm_log_set_level(DcmLogLevel log_level);
  274. /**
  275. * Log function. See dcm_log_set_logf().
  276. */
  277. typedef void (*DcmLogf)(const char *level, const char *format, va_list args);
  278. /**
  279. * Set the log function.
  280. *
  281. * This function will be used to log any error or warning messages from the
  282. * library. The default DcmLogf function prints messages to stderr. Set to
  283. * NULL to disable all logging.
  284. *
  285. * :param logf: New log function.
  286. * :return: previous log function
  287. */
  288. DCM_EXTERN
  289. DcmLogf dcm_log_set_logf(DcmLogf logf);
  290. /**
  291. * Write critical log message to stderr stream.
  292. *
  293. * :param format: printf-style format string
  294. * :param ...: Format string arguments
  295. */
  296. DCM_EXTERN
  297. void dcm_log_critical(const char *format, ...);
  298. /**
  299. * Write error log message to stderr stream.
  300. *
  301. * :param format: printf-style format string
  302. * :param ...: Format string arguments
  303. */
  304. DCM_EXTERN
  305. void dcm_log_error(const char *format, ...);
  306. /**
  307. * Write warning log message to stderr stream.
  308. *
  309. * :param format: printf-style format string
  310. * :param ...: Format string arguments
  311. */
  312. DCM_EXTERN
  313. void dcm_log_warning(const char *format, ...);
  314. /**
  315. * Write info log message to stderr stream.
  316. *
  317. * :param format: printf-style format string
  318. * :param ...: Format string arguments
  319. */
  320. DCM_EXTERN
  321. void dcm_log_info(const char *format, ...);
  322. /**
  323. * Write debug log message to stderr stream.
  324. *
  325. * :param format: printf-style format string
  326. * :param ...: Format string arguments
  327. */
  328. DCM_EXTERN
  329. void dcm_log_debug(const char *format, ...);
  330. /**
  331. * Get the version of the library.
  332. *
  333. * :return: semantic version string
  334. */
  335. DCM_EXTERN
  336. const char *dcm_get_version(void);
  337. /**
  338. * An enum of Value Representations.
  339. *
  340. * Value Representations which are not known to libdicom will be coded as
  341. * DCM_VR_ERROR (unknown Value Representation).
  342. *
  343. * Note to maintainers: this enum must match the table in dicom-dict.c, and
  344. * the DcmVRTag enum. As the DICOM standard evolves, numbering must be
  345. * maintained for ABI compatibility.
  346. */
  347. typedef enum _DcmVR {
  348. // error value, returned for eg. unknown SR strings
  349. DCM_VR_ERROR = -1,
  350. // allowed VRs for DcmElement
  351. DCM_VR_AE = 0,
  352. DCM_VR_AS,
  353. DCM_VR_AT,
  354. DCM_VR_CS,
  355. DCM_VR_DA,
  356. DCM_VR_DS,
  357. DCM_VR_DT,
  358. DCM_VR_FL,
  359. DCM_VR_FD,
  360. DCM_VR_IS,
  361. DCM_VR_LO,
  362. DCM_VR_LT,
  363. DCM_VR_OB,
  364. DCM_VR_OD,
  365. DCM_VR_OF,
  366. DCM_VR_OW,
  367. DCM_VR_PN,
  368. DCM_VR_SH,
  369. DCM_VR_SL,
  370. DCM_VR_SQ,
  371. DCM_VR_SS,
  372. DCM_VR_ST,
  373. DCM_VR_TM,
  374. DCM_VR_UI,
  375. DCM_VR_UL,
  376. DCM_VR_UN,
  377. DCM_VR_US,
  378. DCM_VR_UT,
  379. DCM_VR_UR,
  380. DCM_VR_UC,
  381. DCM_VR_OL,
  382. DCM_VR_OV,
  383. DCM_VR_SV,
  384. DCM_VR_UV,
  385. // used to check enums for range errors, add new VRs before this
  386. DCM_VR_LAST
  387. } DcmVR;
  388. /**
  389. * The general class of the value associated with a Value Representation.
  390. *
  391. * DCM_VR_CLASS_STRING_MULTI -- one or more null-terminated strings, cannot
  392. * contain backslash
  393. *
  394. * DCM_VR_CLASS_STRING_SINGLE -- a single null-terminated string, backslash
  395. * allowed
  396. *
  397. * DCM_VR_CLASS_NUMERIC_DECIMAL -- one or more binary floating point numeric
  398. * values, other fields give sizeof(type)
  399. *
  400. * DCM_VR_CLASS_NUMERIC_INTEGER -- one or more binary integer numeric
  401. * values, other fields give sizeof(type)
  402. *
  403. * DCM_VR_CLASS_BINARY -- an uninterpreted array of bytes, length in the
  404. * element header
  405. *
  406. * DCM_VR_CLASS_SEQUENCE -- Value Representation is a sequence
  407. */
  408. typedef enum _DcmVRClass {
  409. DCM_VR_CLASS_ERROR,
  410. DCM_VR_CLASS_STRING_MULTI,
  411. DCM_VR_CLASS_STRING_SINGLE,
  412. DCM_VR_CLASS_NUMERIC_DECIMAL,
  413. DCM_VR_CLASS_NUMERIC_INTEGER,
  414. DCM_VR_CLASS_BINARY,
  415. DCM_VR_CLASS_SEQUENCE
  416. } DcmVRClass;
  417. /**
  418. * Find the general class for a particular Value Representation.
  419. *
  420. * :param vr: The Value Representation
  421. *
  422. * :return: The general class of that Value Representation
  423. */
  424. DCM_EXTERN
  425. DcmVRClass dcm_dict_vr_class(DcmVR vr);
  426. /**
  427. * Turn a string Value Representation into an enum value.
  428. *
  429. * :param vr: The Value Representation as a two character string.
  430. *
  431. * :return: the enum for that Value Representation
  432. */
  433. DCM_EXTERN
  434. DcmVR dcm_dict_vr_from_str(const char *vr);
  435. /**
  436. * Turn an enum Value Representation into a character string.
  437. *
  438. * :param vr: The Value Representation as an enum value.
  439. *
  440. * :return: the string representation of that Value Representation, or NULL
  441. */
  442. DCM_EXTERN
  443. const char *dcm_dict_str_from_vr(DcmVR vr);
  444. /**
  445. * Look up the Keyword of an Attribute in the Dictionary.
  446. *
  447. * Returns NULL if the tag is not recognised.
  448. *
  449. * :param tag: Attribute Tag
  450. *
  451. * :return: attribute Keyword
  452. */
  453. DCM_EXTERN
  454. const char *dcm_dict_keyword_from_tag(uint32_t tag);
  455. /**
  456. * Look up the tag of an Attribute in the Dictionary.
  457. *
  458. * Returns ``0xffffffff`` if the keyword is not recognised.
  459. *
  460. * :param tag: Attribute keyword
  461. *
  462. * :return: attribute tag
  463. */
  464. DCM_EXTERN
  465. uint32_t dcm_dict_tag_from_keyword(const char *keyword);
  466. /**
  467. * Find the Value Representation for a tag.
  468. *
  469. * This will return DCM_VR_ERROR if the tag is unknown, or does not have a
  470. * unique Value Representation.
  471. *
  472. * :param tag: Attribute Tag
  473. *
  474. * :return: the unique Value Representation for this tag, or DCM_VR_ERROR
  475. */
  476. DCM_EXTERN
  477. DcmVR dcm_vr_from_tag(uint32_t tag);
  478. /**
  479. * Determine whether a Tag is public.
  480. *
  481. * A Tag is public if it is defined in the Dictionary.
  482. *
  483. * :param tag: Attribute Tag
  484. *
  485. * :return: Yes/no answer
  486. */
  487. DCM_EXTERN
  488. bool dcm_is_public_tag(uint32_t tag);
  489. /**
  490. * Determine whether a Tag is private.
  491. *
  492. * :param tag: Attribute Tag
  493. *
  494. * :return: Yes/no answer
  495. */
  496. DCM_EXTERN
  497. bool dcm_is_private_tag(uint32_t tag);
  498. /**
  499. * Determine whether a Tag is valid.
  500. *
  501. * :param tag: Attribute Tag
  502. *
  503. * :return: Yes/no answer
  504. */
  505. DCM_EXTERN
  506. bool dcm_is_valid_tag(uint32_t tag);
  507. /**
  508. * Determine whether a Value Representation is valid.
  509. *
  510. * :param vr: Attribute Value Representation
  511. *
  512. * :return: Yes/no answer
  513. */
  514. DCM_EXTERN
  515. bool dcm_is_valid_vr(const char *vr);
  516. /**
  517. * Determine whether a Value Representation is valid.
  518. *
  519. * :param vr: Attribute Value Representation
  520. *
  521. * :return: Yes/no answer
  522. */
  523. DCM_EXTERN
  524. bool dcm_is_valid_vr_for_tag(DcmVR vr, uint32_t tag);
  525. /**
  526. * Determine whether a Transfer Syntax is encapsulated.
  527. *
  528. * :param transfer_syntax_uid: Transfer Syntax UID
  529. *
  530. * :return: Yes/no answer
  531. */
  532. DCM_EXTERN
  533. bool dcm_is_encapsulated_transfer_syntax(const char *transfer_syntax_uid);
  534. /**
  535. * Data Element.
  536. */
  537. typedef struct _DcmElement DcmElement;
  538. /**
  539. * Create a Data Element for a tag.
  540. *
  541. * After creating a Data Element, you must
  542. * attach an appropriate value using one of the setting functions.
  543. * See for example :c:func:`dcm_element_set_value_string`.
  544. *
  545. * :param error: Pointer to error object
  546. * :param tag: Tag
  547. * :param vr: The Value Representation for this Data Element
  548. *
  549. * :return: Pointer to Data Element
  550. */
  551. DCM_EXTERN
  552. DcmElement *dcm_element_create(DcmError **error, uint32_t tag, DcmVR vr);
  553. /**
  554. * Get group number (first part of Tag) of a Data Element.
  555. *
  556. * :param element: Pointer to Data Element
  557. *
  558. * :return: Tag group number
  559. */
  560. DCM_EXTERN
  561. uint16_t dcm_element_get_group_number(const DcmElement *element);
  562. /**
  563. * Get Element Number (second part of Tag) of a Data Element.
  564. *
  565. * :param element: Pointer to Data Element
  566. *
  567. * :return: Tag Element Number
  568. */
  569. DCM_EXTERN
  570. uint16_t dcm_element_get_element_number(const DcmElement *element);
  571. /**
  572. * Get Tag of a Data Element.
  573. *
  574. * :param element: Pointer to Data Element
  575. *
  576. * :return: Tag
  577. */
  578. DCM_EXTERN
  579. uint32_t dcm_element_get_tag(const DcmElement *element);
  580. /**
  581. * Get the Value Representation of a Data Element.
  582. *
  583. * :param element: Pointer to Data Element
  584. *
  585. * :return: Value Representation
  586. */
  587. DCM_EXTERN
  588. DcmVR dcm_element_get_vr(const DcmElement *element);
  589. /**
  590. * Get length of the entire value of a Data Element.
  591. *
  592. * :param element: Pointer to Data Element
  593. *
  594. * :return: Length of value of Data Element
  595. */
  596. DCM_EXTERN
  597. uint32_t dcm_element_get_length(const DcmElement *element);
  598. /**
  599. * Get Value Multiplicity of a Data Element.
  600. *
  601. * :param element: Pointer to Data Element
  602. *
  603. * :return: Value Multiplicity
  604. */
  605. DCM_EXTERN
  606. uint32_t dcm_element_get_vm(const DcmElement *element);
  607. /**
  608. * Determine whether a Data Element has a Value Multiplicity greater than one.
  609. *
  610. * :param element: Pointer to Data Element
  611. *
  612. * :return: Yes/no answer
  613. */
  614. DCM_EXTERN
  615. bool dcm_element_is_multivalued(const DcmElement *element);
  616. /**
  617. * Clone (i.e., create a deep copy of) a Data Element.
  618. *
  619. * :param error: Pointer to error object
  620. * :param element: Pointer to Data Element
  621. *
  622. * :return: Pointer to clone of Data Element
  623. */
  624. DCM_EXTERN
  625. DcmElement *dcm_element_clone(DcmError **error, const DcmElement *element);
  626. /**
  627. * Get a string from a string-valued Data Element.
  628. *
  629. * :param error: Pointer to error object
  630. * :param element: Pointer to Data Element
  631. * :param index: Zero-based index of value within the Data Element
  632. * :param value: Pointer to return location for value
  633. *
  634. * :return: true on success
  635. */
  636. DCM_EXTERN
  637. bool dcm_element_get_value_string(DcmError **error,
  638. const DcmElement *element,
  639. uint32_t index,
  640. const char **value);
  641. /**
  642. * Set the value of a Data Element to a character string.
  643. *
  644. * The Data Element must have a Tag that allows for a
  645. * character string Value Representation.
  646. * If that is not the case, the function will fail.
  647. *
  648. * On success, if `steal` is true, ownership of `value` passes to
  649. * `element`, i.e. it will be freed when `element` is destroyed. If `steal` is
  650. * false, then a copy is made of `value` and ownership is not transferred.
  651. *
  652. * :param error: Pointer to error object
  653. * :param element: Pointer to Data Element
  654. * :param value: String value
  655. * :param steal: if true, ownership of value passes to element
  656. *
  657. * :return: true on success
  658. */
  659. DCM_EXTERN
  660. bool dcm_element_set_value_string(DcmError **error,
  661. DcmElement *element,
  662. char *value,
  663. bool steal);
  664. /**
  665. * Set the value of a Data Element to an array of character strings.
  666. *
  667. * The Data Element must have a Tag that allows for a
  668. * character string Value Representation and for a
  669. * Value Multiplicity greater than one.
  670. * If that is not the case, the function will fail.
  671. *
  672. * On success, if `steal` is true, ownership of `value` passes to
  673. * `element`, i.e. it will be freed when `element` is destroyed. If `steal` is
  674. * false, then a copy is made of `value` and ownership is not transferred.
  675. *
  676. * :param error: Pointer to error object
  677. * :param element: Pointer to Data Element
  678. * :param values: Pointer to memory location where values are written to
  679. * :param vm: Number of values
  680. * :param steal: if true, ownership of values passes to element
  681. *
  682. * :return: true on success
  683. */
  684. DCM_EXTERN
  685. bool dcm_element_set_value_string_multi(DcmError **error,
  686. DcmElement *element,
  687. char **values,
  688. uint32_t vm,
  689. bool steal);
  690. /**
  691. * Get an integer from a 16, 32 or 64-bit integer-valued Data Element.
  692. *
  693. * The integer held in the Element will be cast to int64_t for return.
  694. *
  695. * :param error: Pointer to error object
  696. * :param element: Pointer to Data Element
  697. * :param index: Zero-based index of value within the Data Element
  698. * :param value: Pointer to return location for value
  699. *
  700. * :return: true on success
  701. */
  702. DCM_EXTERN
  703. bool dcm_element_get_value_integer(DcmError **error,
  704. const DcmElement *element,
  705. uint32_t index,
  706. int64_t *value);
  707. /**
  708. * Set the value of a Data Element to an integer.
  709. *
  710. * The Data Element must have a Tag that allows for a
  711. * integer Value Representation.
  712. * If that is not the case, the function will fail.
  713. *
  714. * :param error: Pointer to error object
  715. * :param element: Pointer to Data Element
  716. * :param value: Integer value
  717. *
  718. * :return: true on success
  719. */
  720. DCM_EXTERN
  721. bool dcm_element_set_value_integer(DcmError **error,
  722. DcmElement *element,
  723. int64_t value);
  724. /**
  725. * Set the value of a Data Element to a number.
  726. *
  727. * The Data Element must have a Tag that allows for a
  728. * numeric Value Representation.
  729. * If that is not the case, the function will fail.
  730. *
  731. * Although the value passed is `void*`, it should
  732. * be a pointer to an array of 16- to 64-bit numeric values of the
  733. * appropriate type for the Data Element Value Representation.
  734. *
  735. * On success, if `steal` is true, ownership of `values` passes to
  736. * `element`, i.e. it will be freed when `element` is destroyed. If `steal` is
  737. * false, then a copy is made of `values` and ownership is not transferred.
  738. *
  739. * :param error: Pointer to error object
  740. * :param element: Pointer to Data Element
  741. * :param values: Array of values
  742. * :param vm: Number of values
  743. * :param steal: if true, ownership of values passes to element
  744. *
  745. * :return: true on success
  746. */
  747. DCM_EXTERN
  748. bool dcm_element_set_value_numeric_multi(DcmError **error,
  749. DcmElement *element,
  750. void *values,
  751. uint32_t vm,
  752. bool steal);
  753. /**
  754. * Get a floating-point value from a Data Element.
  755. *
  756. * The Data Element Value Reepresentation may be either single- or
  757. * double-precision floating point.
  758. *
  759. * :param error: Pointer to error object
  760. * :param element: Pointer to Data Element
  761. * :param index: Zero-based index of value within the Data Element
  762. * :param value: Pointer to return location for value
  763. *
  764. * :return: true on success
  765. */
  766. DCM_EXTERN
  767. bool dcm_element_get_value_decimal(DcmError **error,
  768. const DcmElement *element,
  769. uint32_t index,
  770. double *value);
  771. /**
  772. * Set the value of a Data Element to a floating-point.
  773. *
  774. * The Data Element must have a Tag that allows for a
  775. * floating-point Value Representation.
  776. * If that is not the case, the function will fail.
  777. *
  778. * :param error: Pointer to error object
  779. * :param element: Pointer to Data Element
  780. * :param value: Floating point value
  781. *
  782. * :return: true on success
  783. */
  784. DCM_EXTERN
  785. bool dcm_element_set_value_decimal(DcmError **error,
  786. DcmElement *element,
  787. double value);
  788. /**
  789. * Get a binary value from a Data Element.
  790. *
  791. * Use :c:func:`dcm_element_length` to get the length of the binary value.
  792. *
  793. * :param error: Pointer to error object
  794. * :param element: Pointer to Data Element
  795. * :param value: Pointer to return location for value
  796. *
  797. * :return: true on success
  798. */
  799. DCM_EXTERN
  800. bool dcm_element_get_value_binary(DcmError **error,
  801. const DcmElement *element,
  802. const void **value);
  803. /**
  804. * Set the value of a Data Element to binary data.
  805. *
  806. * The Data Element must have a Tag that allows for a binary Value
  807. * Representation. If that is not the case, the function will fail.
  808. *
  809. * On success, if `steal` is true, ownership of `value` passes to
  810. * `element`, i.e. it will be freed when `element` is destroyed. If `steal` is
  811. * false, then a copy is made of `value` and ownership is not transferred.
  812. *
  813. * :param error: Pointer to error object
  814. * :param element: Pointer to Data Element
  815. * :param value: Pointer to binary value
  816. * :param length: Length in bytes of the binary value
  817. * :param steal: if true, ownership of the value passes to element
  818. *
  819. * :return: true on success
  820. */
  821. DCM_EXTERN
  822. bool dcm_element_set_value_binary(DcmError **error,
  823. DcmElement *element,
  824. void *value,
  825. uint32_t length,
  826. bool steal);
  827. /* Set a value for an Element from a generic byte buffer. The byte buffer must
  828. * have been correctly formatted for the VR of this Element.
  829. *
  830. * :param error: Pointer to error object
  831. * :param element: Pointer to Data Element
  832. * :param value: Pointer to value
  833. * :param length: Length in bytes of the value
  834. * :param steal: if true, ownership of the value passes to element
  835. *
  836. * :return: true on success
  837. */
  838. bool dcm_element_set_value(DcmError **error,
  839. DcmElement *element,
  840. char *value,
  841. uint32_t length,
  842. bool steal);
  843. /**
  844. * Get a sequence value from a Data Element.
  845. *
  846. * :param error: Pointer to error object
  847. * :param element: Pointer to Data Element
  848. * :param value: Pointer to return location for value
  849. *
  850. * :return: true on success
  851. */
  852. DCM_EXTERN
  853. bool dcm_element_get_value_sequence(DcmError **error,
  854. const DcmElement *element,
  855. DcmSequence **value);
  856. /**
  857. * Set the value of a Data Element to a Sequence.
  858. *
  859. * The Data Element must have a Tag that allows for
  860. * Value Representation ``"SQ"``.
  861. * If that is not the case, the function will fail.
  862. *
  863. * The Data Element takes ownership of the value pointer on success.
  864. *
  865. * :param error: Pointer to error object
  866. * :param element: Pointer to Data Element
  867. * :param value: Pointer to Sequence
  868. *
  869. * :return: true on success
  870. */
  871. DCM_EXTERN
  872. bool dcm_element_set_value_sequence(DcmError **error,
  873. DcmElement *element,
  874. DcmSequence *value);
  875. /**
  876. * Make a string suitable for display to a user from the value of an element.
  877. *
  878. * The return result must be freed with free(). The result may be NULL.
  879. *
  880. * :return: string to display
  881. */
  882. DCM_EXTERN
  883. char *dcm_element_value_to_string(const DcmElement *element);
  884. /**
  885. * Print a Data Element.
  886. *
  887. * :param element: Pointer to Data Element
  888. * :param indentation: Number of white spaces before text
  889. */
  890. DCM_EXTERN
  891. void dcm_element_print(const DcmElement *element, int indentation);
  892. /**
  893. * Destroy a Data Element.
  894. *
  895. * :param element: Pointer to Data Element
  896. */
  897. DCM_EXTERN
  898. void dcm_element_destroy(DcmElement *element);
  899. /**
  900. * Data Set
  901. */
  902. typedef struct _DcmDataSet DcmDataSet;
  903. /**
  904. * Create an empty Data Set.
  905. *
  906. * :param error: Pointer to error object
  907. */
  908. DCM_EXTERN
  909. DcmDataSet *dcm_dataset_create(DcmError **error);
  910. /**
  911. * Clone (i.e., create a deep copy of) a Data Set.
  912. *
  913. * :param error: Pointer to error object
  914. * :param dataset: Pointer to Data Set
  915. *
  916. * :return: Pointer to clone of Data Set
  917. */
  918. DCM_EXTERN
  919. DcmDataSet *dcm_dataset_clone(DcmError **error, const DcmDataSet *dataset);
  920. /**
  921. * Insert a Data Element into a Data Set.
  922. *
  923. * :param error: Pointer to error object
  924. * :param dataset: Pointer to Data Set
  925. * :param element: Pointer to Data Element
  926. *
  927. * The object takes over ownership of the memory referenced by `element`
  928. * and frees it when the object is destroyed or if the insert operation fails.
  929. *
  930. * :return: Whether insert operation was successful
  931. */
  932. DCM_EXTERN
  933. bool dcm_dataset_insert(DcmError **error,
  934. DcmDataSet *dataset, DcmElement *element);
  935. /**
  936. * Remove a Data Element from a Data Set.
  937. *
  938. * :param error: Pointer to error object
  939. * :param dataset: Pointer to Data Set
  940. * :param tag: Attribute Tag of a Data Element
  941. *
  942. * :return: Whether remove operation was successful
  943. */
  944. DCM_EXTERN
  945. bool dcm_dataset_remove(DcmError **error, DcmDataSet *dataset, uint32_t tag);
  946. /**
  947. * Get a Data Element from a Data Set.
  948. *
  949. * :param error: Pointer to error object
  950. * :param dataset: Pointer to Data Set
  951. * :param tag: Attribute Tag of a Data Element
  952. *
  953. * :return: Pointer to Data Element
  954. */
  955. DCM_EXTERN
  956. DcmElement *dcm_dataset_get(DcmError **error,
  957. const DcmDataSet *dataset, uint32_t tag);
  958. /**
  959. * Get a clone (deep copy) of a Data Element from a Data Set.
  960. *
  961. * :param error: Pointer to error object
  962. * :param dataset: Pointer to Data Set
  963. * :param tag: Attribute Tag of a Data Element
  964. *
  965. * :return: Pointer to clone of Data Element
  966. */
  967. DCM_EXTERN
  968. DcmElement *dcm_dataset_get_clone(DcmError **error,
  969. const DcmDataSet *dataset, uint32_t tag);
  970. /**
  971. * Iterate over Data Elements in a Data Set.
  972. *
  973. * The user function should return true to continue looping, or false to
  974. * terminate the loop early.
  975. *
  976. * The result is true if the whole Data Set returned true, or false if one
  977. * call requested early termination.
  978. *
  979. * The function must not modify the Data Set.
  980. *
  981. * :param seq: Pointer to Data Set
  982. * :param fn: Pointer to function that should be called for each Data Element
  983. * :param client: Client data for function
  984. *
  985. * :return: true if all functions return true
  986. */
  987. DCM_EXTERN
  988. bool dcm_dataset_foreach(const DcmDataSet *dataset,
  989. bool (*fn)(const DcmElement *element, void *client),
  990. void *client);
  991. /**
  992. * Fetch a Data Element from a Data Set, or NULL if not present.
  993. *
  994. * :param dataset: Pointer to Data Set
  995. * :param tag: Attribute Tag of a Data Element
  996. *
  997. * :return: Data Element, or NULL if not present
  998. */
  999. DCM_EXTERN
  1000. DcmElement *dcm_dataset_contains(const DcmDataSet *dataset, uint32_t tag);
  1001. /**
  1002. * Count the number of Data Elements in a Data Set.
  1003. *
  1004. * :param dataset: Pointer to Data Set
  1005. *
  1006. * :return: Number of Data Elements
  1007. */
  1008. DCM_EXTERN
  1009. uint32_t dcm_dataset_count(const DcmDataSet *dataset);
  1010. /**
  1011. * Obtain a copy of the Tag of each Data Element in a Data Set.
  1012. *
  1013. * The tags will be sorted in ascending order.
  1014. *
  1015. * :param dataset: Pointer to Data Set
  1016. * :param tags: Pointer to memory location to of the array into which to copy
  1017. * tags. Number of items in the array must match the number of
  1018. * Data Elements in the Data Set as determined by
  1019. * :c:func:`dcm_dataset_count`.
  1020. * :param n: Number of items in the array.
  1021. *
  1022. * Ownership of the memory allocated for `tags` remains with the caller.
  1023. * Specifically, the function does not free the memory allocated for `tags` if
  1024. * the copy operation fails.
  1025. */
  1026. DCM_EXTERN
  1027. void dcm_dataset_copy_tags(const DcmDataSet *dataset,
  1028. uint32_t *tags,
  1029. uint32_t n);
  1030. /**
  1031. * Lock a Data Set to prevent modification.
  1032. *
  1033. * :param dataset: Pointer to Data Set
  1034. */
  1035. DCM_EXTERN
  1036. void dcm_dataset_lock(DcmDataSet *dataset);
  1037. /**
  1038. * Check whether a Data Set is locked.
  1039. *
  1040. * :param dataset: Pointer to Data Set
  1041. *
  1042. * :return: Yes/no answer
  1043. */
  1044. DCM_EXTERN
  1045. bool dcm_dataset_is_locked(const DcmDataSet *dataset);
  1046. /**
  1047. * Print a Data Set.
  1048. *
  1049. * :param error: Pointer to error object
  1050. * :param dataset: Pointer to Data Set
  1051. * :param indentation: Number of white spaces before text
  1052. */
  1053. DCM_EXTERN
  1054. void dcm_dataset_print(const DcmDataSet *dataset, int indentation);
  1055. /**
  1056. * Destroy a Data Set.
  1057. *
  1058. * :param dataset: Pointer to Data Set
  1059. */
  1060. DCM_EXTERN
  1061. void dcm_dataset_destroy(DcmDataSet *dataset);
  1062. /**
  1063. * Sequence
  1064. */
  1065. /**
  1066. * Create a Sequence, i.e., an ordered list of Data Set items that represent
  1067. * the value of a Data Element with Value Representation SQ (Sequence).
  1068. *
  1069. * Note that created object represents the value of a Data Element rather
  1070. * than a Data Element itself.
  1071. *
  1072. * :param error: Pointer to error object
  1073. * :return: Pointer to Sequence
  1074. */
  1075. DCM_EXTERN
  1076. DcmSequence *dcm_sequence_create(DcmError **error);
  1077. /**
  1078. * Append a Data Set item to a Sequence.
  1079. *
  1080. * :param error: Pointer to error object
  1081. * :param seq: Pointer to Sequence
  1082. * :param item: Data Set item
  1083. *
  1084. * The object takes over ownership of the memory referenced by `item`
  1085. * and frees it when the object is destroyed or if the append operation fails.
  1086. *
  1087. * :return: Whether append operation was successful
  1088. */
  1089. DCM_EXTERN
  1090. bool dcm_sequence_append(DcmError **error,
  1091. DcmSequence *seq, DcmDataSet *item);
  1092. /**
  1093. * Get a Data Set item from a Sequence.
  1094. *
  1095. * :param error: Pointer to error object
  1096. * :param seq: Pointer to Sequence
  1097. * :param index: Zero-based index of the Data Set item in the Sequence
  1098. *
  1099. * :return: Pointer to Data Set item
  1100. */
  1101. DCM_EXTERN
  1102. DcmDataSet *dcm_sequence_get(DcmError **error,
  1103. const DcmSequence *seq, uint32_t index);
  1104. /**
  1105. * Iterate over Data Sets in a Sequence.
  1106. *
  1107. * The user function should return true to continue looping, or false to
  1108. * terminate the loop early.
  1109. *
  1110. * The result is true if the whole sequence returned true, or false if one
  1111. * call requested early termination.
  1112. *
  1113. * The function must not modify the seqeucence.
  1114. *
  1115. * :param seq: Pointer to Sequence
  1116. * :param fn: Pointer to function that should be called for each Data Set
  1117. * :param client: Client data for function
  1118. *
  1119. * :return: Pointer to Data Set item
  1120. */
  1121. DCM_EXTERN
  1122. bool dcm_sequence_foreach(const DcmSequence *seq,
  1123. bool (*fn)(const DcmDataSet *dataset,
  1124. uint32_t index, void *client),
  1125. void *client);
  1126. /**
  1127. * Remove a Data Set item from a Sequence.
  1128. *
  1129. * :param error: Pointer to error object
  1130. * :param seq: Pointer to Sequence
  1131. * :param index: Zero-based index of the Data Set item in the Sequence
  1132. *
  1133. * :return: Whether remove operation was successful
  1134. */
  1135. DCM_EXTERN
  1136. bool dcm_sequence_remove(DcmError **error, DcmSequence *seq, uint32_t index);
  1137. /**
  1138. * Count the number of Data Set items in a Sequence.
  1139. *
  1140. * :param seq: Pointer to Sequence
  1141. *
  1142. * :return: number of Data Set items
  1143. */
  1144. DCM_EXTERN
  1145. uint32_t dcm_sequence_count(const DcmSequence *seq);
  1146. /**
  1147. * Lock a Sequence to prevent modification.
  1148. *
  1149. * :param seq: Pointer to Sequence
  1150. */
  1151. DCM_EXTERN
  1152. void dcm_sequence_lock(DcmSequence *seq);
  1153. /**
  1154. * Check whether a Sequence is locked.
  1155. *
  1156. * :param seq: Pointer to Sequence
  1157. *
  1158. * :return: Yes/no answer
  1159. */
  1160. DCM_EXTERN
  1161. bool dcm_sequence_is_locked(const DcmSequence *seq);
  1162. /**
  1163. * Destroy a Sequence.
  1164. *
  1165. * :param seq: Pointer to Sequence
  1166. */
  1167. DCM_EXTERN
  1168. void dcm_sequence_destroy(DcmSequence *seq);
  1169. /**
  1170. * Frame Item of Pixel Data Element
  1171. *
  1172. * Encoded pixels of an individual pixel matrix and associated
  1173. * descriptive metadata.
  1174. */
  1175. typedef struct _DcmFrame DcmFrame;
  1176. /**
  1177. * Create a Frame.
  1178. *
  1179. * :param error: Pointer to error object
  1180. * :param index: Index of the Frame within the Pixel Data Element
  1181. * :param data: Pixel data of the Frame
  1182. * :param length: Size of the Frame (number of bytes)
  1183. * :param rows: Number of rows in pixel matrix
  1184. * :param columns: Number of columns in pixel matrix
  1185. * :param samples_per_pixel: Number of samples per pixel
  1186. * :param bits_allocated: Number of bits allocated per pixel
  1187. * :param bits_stored: Number of bits stored per pixel
  1188. * :param pixel_representation: Representation of pixels
  1189. * (unsigned integers or 2's complement)
  1190. * :param planar_configuration: Configuration of samples
  1191. * (color-by-plane or color-by-pixel)
  1192. * :param photometric_interpretation: Interpretation of pixels
  1193. * (monochrome, RGB, etc.)
  1194. * :param transfer_syntax_uid: UID of transfer syntax in which data is encoded
  1195. *
  1196. * The object takes over ownership of the memory referenced by `data`,
  1197. * `photometric_interpretation`, and `transfer_syntax_uid`
  1198. * and frees it when the object is destroyed or if the creation fails.
  1199. *
  1200. * :return: Frame Item
  1201. */
  1202. DCM_EXTERN
  1203. DcmFrame *dcm_frame_create(DcmError **error,
  1204. uint32_t number,
  1205. const char *data,
  1206. uint32_t length,
  1207. uint16_t rows,
  1208. uint16_t columns,
  1209. uint16_t samples_per_pixel,
  1210. uint16_t bits_allocated,
  1211. uint16_t bits_stored,
  1212. uint16_t pixel_representation,
  1213. uint16_t planar_configuration,
  1214. const char *photometric_interpretation,
  1215. const char *transfer_syntax_uid);
  1216. /**
  1217. * Get number of a Frame Item within the Pixel Data Element.
  1218. *
  1219. * :param frame: Frame
  1220. *
  1221. * :return: number (one-based index)
  1222. */
  1223. DCM_EXTERN
  1224. uint32_t dcm_frame_get_number(const DcmFrame *frame);
  1225. /**
  1226. * Get length of a Frame Item.
  1227. *
  1228. * :param frame: Frame
  1229. *
  1230. * :return: number of bytes
  1231. */
  1232. DCM_EXTERN
  1233. uint32_t dcm_frame_get_length(const DcmFrame *frame);
  1234. /**
  1235. * Get Rows of a Frame.
  1236. *
  1237. * :param frame: Frame
  1238. *
  1239. * :return: number of rows in pixel matrix
  1240. */
  1241. DCM_EXTERN
  1242. uint16_t dcm_frame_get_rows(const DcmFrame *frame);
  1243. /**
  1244. * Get Columns of a Frame.
  1245. *
  1246. * :param frame: Frame
  1247. *
  1248. * :return: number of columns in pixel matrix
  1249. */
  1250. DCM_EXTERN
  1251. uint16_t dcm_frame_get_columns(const DcmFrame *frame);
  1252. /**
  1253. * Get Samples per Pixel of a Frame.
  1254. *
  1255. * :param frame: Frame
  1256. *
  1257. * :return: number of samples (color channels) per pixel
  1258. */
  1259. DCM_EXTERN
  1260. uint16_t dcm_frame_get_samples_per_pixel(const DcmFrame *frame);
  1261. /**
  1262. * Get Bits Allocated of a Frame.
  1263. *
  1264. * :param frame: Frame
  1265. *
  1266. * :return: number of bits allocated per pixel
  1267. */
  1268. DCM_EXTERN
  1269. uint16_t dcm_frame_get_bits_allocated(const DcmFrame *frame);
  1270. /**
  1271. * Get Bits Stored of a Frame.
  1272. *
  1273. * :param frame: Frame
  1274. *
  1275. * :return: number of bits stored per pixel
  1276. */
  1277. DCM_EXTERN
  1278. uint16_t dcm_frame_get_bits_stored(const DcmFrame *frame);
  1279. /**
  1280. * Get High Bit of a Frame.
  1281. *
  1282. * :param frame: Frame
  1283. *
  1284. * :return: most significant bit of pixels
  1285. */
  1286. DCM_EXTERN
  1287. uint16_t dcm_frame_get_high_bit(const DcmFrame *frame);
  1288. /**
  1289. * Get Pixel Representation of a Frame.
  1290. *
  1291. * :param frame: Frame
  1292. *
  1293. * :return: representation of pixels (unsigned integers or 2's complement)
  1294. */
  1295. DCM_EXTERN
  1296. uint16_t dcm_frame_get_pixel_representation(const DcmFrame *frame);
  1297. /**
  1298. * Get Planar Configuration of a Frame.
  1299. *
  1300. * :param frame: Frame
  1301. *
  1302. * :return: configuration of samples (color-by-plane or color-by-pixel)
  1303. */
  1304. DCM_EXTERN
  1305. uint16_t dcm_frame_get_planar_configuration(const DcmFrame *frame);
  1306. /**
  1307. * Get Photometric Interpretation of a Frame.
  1308. *
  1309. * :param frame: Frame
  1310. *
  1311. * :return: interpretation of pixels (monochrome, RGB, etc.)
  1312. */
  1313. DCM_EXTERN
  1314. const char *dcm_frame_get_photometric_interpretation(const DcmFrame *frame);
  1315. /**
  1316. * Get Transfer Syntax UID for a Frame.
  1317. *
  1318. * :param frame: Frame
  1319. *
  1320. * :return: UID of the transfer syntax in which frame is encoded
  1321. */
  1322. DCM_EXTERN
  1323. const char *dcm_frame_get_transfer_syntax_uid(const DcmFrame *frame);
  1324. /**
  1325. * Get pixel data of a Frame.
  1326. *
  1327. * :param frame: Frame
  1328. *
  1329. * :return: pixel data
  1330. */
  1331. DCM_EXTERN
  1332. const char *dcm_frame_get_value(const DcmFrame *frame);
  1333. /**
  1334. * Destroy a Frame.
  1335. *
  1336. * :param frame: Frame
  1337. */
  1338. DCM_EXTERN
  1339. void dcm_frame_destroy(DcmFrame *frame);
  1340. /**
  1341. * Part 10 File
  1342. */
  1343. typedef struct _DcmFilehandle DcmFilehandle;
  1344. typedef struct _DcmIOMethods DcmIOMethods;
  1345. /**
  1346. * An object we can read from.
  1347. */
  1348. typedef struct _DcmIO {
  1349. const DcmIOMethods *methods;
  1350. // more private fields follow
  1351. } DcmIO;
  1352. /**
  1353. * A set of IO methods, see dcm_io_create().
  1354. */
  1355. struct _DcmIOMethods {
  1356. /** Open an IO object */
  1357. DcmIO *(*open)(DcmError **error, void *client);
  1358. /** Close an IO object */
  1359. void (*close)(DcmIO *io);
  1360. /** Read from an IO object, semantics as POSIX read() */
  1361. int64_t (*read)(DcmError **error, DcmIO *io, char *buffer, int64_t length);
  1362. /** Seek an IO object, semantics as POSIX seek() */
  1363. int64_t (*seek)(DcmError **error, DcmIO *io, int64_t offset, int whence);
  1364. };
  1365. /**
  1366. * Create an IO object using a set of IO methods.
  1367. *
  1368. * :param error: Error structure pointer
  1369. * :param io: Set of read methods
  1370. * :param client: Client data for read methods
  1371. *
  1372. * :return: IO object
  1373. */
  1374. DCM_EXTERN
  1375. DcmIO *dcm_io_create(DcmError **error,
  1376. const DcmIOMethods *methods,
  1377. void *client);
  1378. /**
  1379. * Open a file on disk for IO.
  1380. *
  1381. * :param error: Error structure pointer
  1382. * :param filename: Path to the file on disk
  1383. *
  1384. * :return: IO object
  1385. */
  1386. DCM_EXTERN
  1387. DcmIO *dcm_io_create_from_file(DcmError **error, const char *filename);
  1388. /**
  1389. * Open an area of memory for IO.
  1390. *
  1391. * :param error: Error structure pointer
  1392. * :param buffer: Pointer to memory area
  1393. * :param length: Length of memory area in bytes
  1394. *
  1395. * :return: IO object
  1396. */
  1397. DCM_EXTERN
  1398. DcmIO *dcm_io_create_from_memory(DcmError **error, const char *buffer,
  1399. int64_t length);
  1400. /**
  1401. * Close an IO object.
  1402. *
  1403. * :param io: Pointer to IO object
  1404. */
  1405. DCM_EXTERN
  1406. void dcm_io_close(DcmIO *io);
  1407. /**
  1408. * Read from an IO object.
  1409. *
  1410. * Read up to length bytes from the IO object. Returns the number of bytes
  1411. * read, or -1 for an error. A return of 0 indicates end of file.
  1412. *
  1413. * :param error: Pointer to error object
  1414. * :param io: Pointer to IO object
  1415. * :param buffer: Memory area to read to
  1416. * :param length: Size of memory area
  1417. *
  1418. * :return: Number of bytes read
  1419. */
  1420. DCM_EXTERN
  1421. int64_t dcm_io_read(DcmError **error, DcmIO *io, char *buffer, int64_t length);
  1422. /**
  1423. * Seek an IO object.
  1424. *
  1425. * Set whence to `SEEK_CUR` to seek relative to the current file position,
  1426. * `SEEK_END` to seek relative to the end of the file, or `SEEK_SET` to seek
  1427. * relative to the start.
  1428. *
  1429. * Returns the new absolute read position, or -1 for IO error.
  1430. *
  1431. * :param error: Error structure pointer
  1432. * :param io: Pointer to IO object
  1433. * :param offset: Seek offset
  1434. * :param whence: Seek mode
  1435. *
  1436. * :return: New read position
  1437. */
  1438. DCM_EXTERN
  1439. int64_t dcm_io_seek(DcmError **error, DcmIO *io, int64_t offset, int whence);
  1440. /**
  1441. * Create a representation of a DICOM File using an IO object.
  1442. *
  1443. * The File object tracks information like the transfer syntax and the byte
  1444. * ordering.
  1445. *
  1446. * :param error: Error structure pointer
  1447. * :param io: IO object to read from
  1448. *
  1449. * :return: filehandle
  1450. */
  1451. DCM_EXTERN
  1452. DcmFilehandle *dcm_filehandle_create(DcmError **error, DcmIO *io);
  1453. /**
  1454. * Open a file on disk as a DcmFilehandle.
  1455. *
  1456. * :param error: Error structure pointer
  1457. * :param filepath: Path to the file on disk
  1458. *
  1459. * :return: filehandle
  1460. */
  1461. DCM_EXTERN
  1462. DcmFilehandle *dcm_filehandle_create_from_file(DcmError **error,
  1463. const char *filepath);
  1464. /**
  1465. * Open an area of memory as a DcmFilehandle.
  1466. *
  1467. * :param error: Error structure pointer
  1468. * :param buffer: Pointer to memory area
  1469. * :param length: Length of memory area in bytes
  1470. *
  1471. * :return: filehandle
  1472. */
  1473. DCM_EXTERN
  1474. DcmFilehandle *dcm_filehandle_create_from_memory(DcmError **error,
  1475. const char *buffer,
  1476. int64_t length);
  1477. /**
  1478. * Destroy a Filehandle.
  1479. *
  1480. * :param filehandle: File
  1481. */
  1482. DCM_EXTERN
  1483. void dcm_filehandle_destroy(DcmFilehandle *filehandle);
  1484. /**
  1485. * Get File Meta Information from a File.
  1486. *
  1487. * Reads the File Meta Information and saves it in the File handle. Returns a
  1488. * reference to this internal copy of the File Meta Information.
  1489. *
  1490. * The return result must not be destroyed. Make a clone of it with
  1491. * :c:func:`dcm_dataset_clone()` if you need it to remain valid after
  1492. * closing the File handle.
  1493. *
  1494. * After calling this function, the filehandle read point is always
  1495. * positioned at the start of the File metadata.
  1496. *
  1497. * It is safe to call this function many times.
  1498. *
  1499. * :param error: Pointer to error object
  1500. * :param filehandle: Pointer to file handle
  1501. *
  1502. * :return: File Meta Information
  1503. */
  1504. DCM_EXTERN
  1505. const DcmDataSet *dcm_filehandle_get_file_meta(DcmError **error,
  1506. DcmFilehandle *filehandle);
  1507. /**
  1508. * Get Transfer Syntax UID for a fileahndle.
  1509. *
  1510. * :param filehandle: File
  1511. *
  1512. * :return: UID of the transfer syntax for this File.
  1513. */
  1514. DCM_EXTERN
  1515. const char *dcm_filehandle_get_transfer_syntax_uid(const DcmFilehandle *filehandle);
  1516. /**
  1517. * Read metadata from a File.
  1518. *
  1519. * Read slide metadata, stopping when one of the tags in the stop list is
  1520. * seen. If the stop list pointer is NULL, it will stop on any of the pixel
  1521. * data tags.
  1522. *
  1523. * The return result must be destroyed with :c:func:`dcm_dataset_destroy()`.
  1524. *
  1525. * After calling this function, the filehandle read point is always
  1526. * positioned at the tag that stopped the read. You can call this function
  1527. * again with a different stop set to read more of the metadata.
  1528. *
  1529. * :param error: Pointer to error object
  1530. * :param filehandle: File
  1531. * :param stop_tags: NULL, or Zero-terminated array of tags to stop on
  1532. *
  1533. * :return: metadata
  1534. */
  1535. DCM_EXTERN
  1536. DcmDataSet *dcm_filehandle_read_metadata(DcmError **error,
  1537. DcmFilehandle *filehandle,
  1538. const uint32_t *stop_tags);
  1539. /**
  1540. * Get a fast subset of metadata from a File.
  1541. *
  1542. * Gets a subset of the File's metadata and saves it in the File handle.
  1543. * Returns a reference to this internal copy of the File metadata.
  1544. *
  1545. * The subset is the part of the DICOM metadata that can be read quickly. It
  1546. * is missing tags such as PerFrameFunctionalGroupSequence. Use
  1547. * dcm_filehandle_read_metadata() if you need all file metadata.
  1548. *
  1549. * The return result must not be destroyed. Make a clone of it with
  1550. * :c:func:`dcm_dataset_clone()` if you need it to remain valid after
  1551. * closing the File handle.
  1552. *
  1553. * After calling this function, the filehandle read point is always
  1554. * positioned at the tag that stopped the read.
  1555. *
  1556. * It is safe to call this function many times.
  1557. *
  1558. * :param error: Pointer to error object
  1559. * :param filehandle: File
  1560. *
  1561. * :return: metadata
  1562. */
  1563. DCM_EXTERN
  1564. const DcmDataSet *dcm_filehandle_get_metadata_subset(DcmError **error,
  1565. DcmFilehandle *filehandle);
  1566. /**
  1567. * Read everything necessary to fetch frames from the file.
  1568. *
  1569. * Scans the PixelData sequence and loads the PerFrameFunctionalGroupSequence,
  1570. * if present.
  1571. *
  1572. * This function will be called automatically on the first call to
  1573. * :c:func:`dcm_filehandle_read_frame_position()` or
  1574. * :c:func:`dcm_filehandle_read_frame()`. It can take some time to execute,
  1575. * so it is available as a separate function call in case this delay needs
  1576. * to be managed.
  1577. *
  1578. * After calling this function, the filehandle read point is always
  1579. * positioned at the PixelData tag.
  1580. *
  1581. * It is safe to call this function many times.
  1582. *
  1583. * :param error: Pointer to error object
  1584. * :param filehandle: File
  1585. *
  1586. * :return: true on success
  1587. */
  1588. DCM_EXTERN
  1589. bool dcm_filehandle_prepare_read_frame(DcmError **error,
  1590. DcmFilehandle *filehandle);
  1591. /**
  1592. * Read an individual Frame from a File.
  1593. *
  1594. * Frames are numbered from 1 in the order they appear in the PixelData element.
  1595. *
  1596. * :param error: Pointer to error object
  1597. * :param filehandle: File
  1598. * :param index: One-based frame number
  1599. *
  1600. * :return: Frame
  1601. */
  1602. DCM_EXTERN
  1603. DcmFrame *dcm_filehandle_read_frame(DcmError **error,
  1604. DcmFilehandle *filehandle,
  1605. uint32_t frame_number);
  1606. /**
  1607. * Read the frame at a position in a File.
  1608. *
  1609. * Read a frame from a File at a specified (column, row), numbered from zero.
  1610. * This takes account of any frame positioning given in
  1611. * PerFrameFunctionalGroupSequence.
  1612. *
  1613. * If the frame is missing, perhaps because this is a sparse file, this
  1614. * function returns NULL and sets the error
  1615. * :c:enum:`DCM_ERROR_CODE_MISSING_FRAME`. Applications can detect
  1616. * this and render a background image.
  1617. *
  1618. * :param error: Pointer to error object
  1619. * :param filehandle: File
  1620. * :param column: Column number, from 0
  1621. * :param row: Row number, from 0
  1622. *
  1623. * :return: Frame
  1624. */
  1625. DCM_EXTERN
  1626. DcmFrame *dcm_filehandle_read_frame_position(DcmError **error,
  1627. DcmFilehandle *filehandle,
  1628. uint32_t column,
  1629. uint32_t row);
  1630. /**
  1631. * Scan a file and print the entire structure to stdout.
  1632. *
  1633. * :param error: Pointer to error object
  1634. * :param filehandle: File
  1635. *
  1636. * :return: true on successful parse, false otherwise.
  1637. */
  1638. DCM_EXTERN
  1639. bool dcm_filehandle_print(DcmError **error,
  1640. DcmFilehandle *filehandle);
  1641. #endif