jp2_dec.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /*
  2. * Copyright (c) 1999-2000 Image Power, Inc. and the University of
  3. * British Columbia.
  4. * Copyright (c) 2001-2003 Michael David Adams.
  5. * All rights reserved.
  6. */
  7. /* __START_OF_JASPER_LICENSE__
  8. *
  9. * JasPer License Version 2.0
  10. *
  11. * Copyright (c) 2001-2006 Michael David Adams
  12. * Copyright (c) 1999-2000 Image Power, Inc.
  13. * Copyright (c) 1999-2000 The University of British Columbia
  14. *
  15. * All rights reserved.
  16. *
  17. * Permission is hereby granted, free of charge, to any person (the
  18. * "User") obtaining a copy of this software and associated documentation
  19. * files (the "Software"), to deal in the Software without restriction,
  20. * including without limitation the rights to use, copy, modify, merge,
  21. * publish, distribute, and/or sell copies of the Software, and to permit
  22. * persons to whom the Software is furnished to do so, subject to the
  23. * following conditions:
  24. *
  25. * 1. The above copyright notices and this permission notice (which
  26. * includes the disclaimer below) shall be included in all copies or
  27. * substantial portions of the Software.
  28. *
  29. * 2. The name of a copyright holder shall not be used to endorse or
  30. * promote products derived from the Software without specific prior
  31. * written permission.
  32. *
  33. * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
  34. * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  35. * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
  36. * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
  37. * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  38. * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
  39. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
  40. * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
  41. * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  42. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  43. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
  44. * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
  45. * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
  46. * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
  47. * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
  48. * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
  49. * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
  50. * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
  51. * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
  52. * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
  53. * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
  54. * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
  55. * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
  56. * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
  57. * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
  58. * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
  59. *
  60. * __END_OF_JASPER_LICENSE__
  61. */
  62. /*
  63. * JP2 Library
  64. *
  65. * $Id: jp2_dec.c,v 1.2 2008-05-26 09:40:52 vp153 Exp $
  66. */
  67. /******************************************************************************\
  68. * Includes.
  69. \******************************************************************************/
  70. #include "jasper/jas_image.h"
  71. #include "jasper/jas_stream.h"
  72. #include "jasper/jas_math.h"
  73. #include "jasper/jas_debug.h"
  74. #include "jasper/jas_malloc.h"
  75. #include "jasper/jas_version.h"
  76. #include "jp2_cod.h"
  77. #include "jp2_dec.h"
  78. #define JP2_VALIDATELEN (JAS_MIN(JP2_JP_LEN + 16, JAS_STREAM_MAXPUTBACK))
  79. static jp2_dec_t *jp2_dec_create(void);
  80. static void jp2_dec_destroy(jp2_dec_t *dec);
  81. static int jp2_getcs(jp2_colr_t *colr);
  82. static int fromiccpcs(int cs);
  83. static int jp2_getct(int colorspace, int type, int assoc);
  84. /******************************************************************************\
  85. * Functions.
  86. \******************************************************************************/
  87. jas_image_t *jp2_decode(jas_stream_t *in, char *optstr)
  88. {
  89. jp2_box_t *box;
  90. int found;
  91. jas_image_t *image;
  92. jp2_dec_t *dec;
  93. bool samedtype;
  94. int dtype;
  95. unsigned int i;
  96. jp2_cmap_t *cmapd;
  97. jp2_pclr_t *pclrd;
  98. jp2_cdef_t *cdefd;
  99. unsigned int channo;
  100. int newcmptno;
  101. int_fast32_t *lutents;
  102. #if 0
  103. jp2_cdefchan_t *cdefent;
  104. int cmptno;
  105. #endif
  106. jp2_cmapent_t *cmapent;
  107. jas_icchdr_t icchdr;
  108. jas_iccprof_t *iccprof;
  109. dec = 0;
  110. box = 0;
  111. image = 0;
  112. if (!(dec = jp2_dec_create())) {
  113. goto error;
  114. }
  115. /* Get the first box. This should be a JP box. */
  116. if (!(box = jp2_box_get(in))) {
  117. jas_eprintf("error: cannot get box\n");
  118. goto error;
  119. }
  120. if (box->type != JP2_BOX_JP) {
  121. jas_eprintf("error: expecting signature box\n");
  122. goto error;
  123. }
  124. if (box->data.jp.magic != JP2_JP_MAGIC) {
  125. jas_eprintf("incorrect magic number\n");
  126. goto error;
  127. }
  128. jp2_box_destroy(box);
  129. box = 0;
  130. /* Get the second box. This should be a FTYP box. */
  131. if (!(box = jp2_box_get(in))) {
  132. goto error;
  133. }
  134. if (box->type != JP2_BOX_FTYP) {
  135. jas_eprintf("expecting file type box\n");
  136. goto error;
  137. }
  138. jp2_box_destroy(box);
  139. box = 0;
  140. /* Get more boxes... */
  141. found = 0;
  142. while ((box = jp2_box_get(in))) {
  143. if (jas_getdbglevel() >= 1) {
  144. jas_eprintf("box type %s\n", box->info->name);
  145. }
  146. switch (box->type) {
  147. case JP2_BOX_JP2C:
  148. found = 1;
  149. break;
  150. case JP2_BOX_IHDR:
  151. if (!dec->ihdr) {
  152. dec->ihdr = box;
  153. box = 0;
  154. }
  155. break;
  156. case JP2_BOX_BPCC:
  157. if (!dec->bpcc) {
  158. dec->bpcc = box;
  159. box = 0;
  160. }
  161. break;
  162. case JP2_BOX_CDEF:
  163. if (!dec->cdef) {
  164. dec->cdef = box;
  165. box = 0;
  166. }
  167. break;
  168. case JP2_BOX_PCLR:
  169. if (!dec->pclr) {
  170. dec->pclr = box;
  171. box = 0;
  172. }
  173. break;
  174. case JP2_BOX_CMAP:
  175. if (!dec->cmap) {
  176. dec->cmap = box;
  177. box = 0;
  178. }
  179. break;
  180. case JP2_BOX_COLR:
  181. if (!dec->colr) {
  182. dec->colr = box;
  183. box = 0;
  184. }
  185. break;
  186. }
  187. if (box) {
  188. jp2_box_destroy(box);
  189. box = 0;
  190. }
  191. if (found) {
  192. break;
  193. }
  194. }
  195. if (!found) {
  196. jas_eprintf("error: no code stream found\n");
  197. goto error;
  198. }
  199. if (!(dec->image = jpc_decode(in, optstr))) {
  200. jas_eprintf("error: cannot decode code stream\n");
  201. goto error;
  202. }
  203. /* An IHDR box must be present. */
  204. if (!dec->ihdr) {
  205. jas_eprintf("error: missing IHDR box\n");
  206. goto error;
  207. }
  208. /* Does the number of components indicated in the IHDR box match
  209. the value specified in the code stream? */
  210. if (dec->ihdr->data.ihdr.numcmpts != JAS_CAST(uint, jas_image_numcmpts(dec->image))) {
  211. jas_eprintf("warning: number of components mismatch\n");
  212. }
  213. /* At least one component must be present. */
  214. if (!jas_image_numcmpts(dec->image)) {
  215. jas_eprintf("error: no components\n");
  216. goto error;
  217. }
  218. /* Determine if all components have the same data type. */
  219. samedtype = true;
  220. dtype = jas_image_cmptdtype(dec->image, 0);
  221. for (i = 1; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
  222. if (jas_image_cmptdtype(dec->image, i) != dtype) {
  223. samedtype = false;
  224. break;
  225. }
  226. }
  227. /* Is the component data type indicated in the IHDR box consistent
  228. with the data in the code stream? */
  229. if ((samedtype && dec->ihdr->data.ihdr.bpc != JP2_DTYPETOBPC(dtype)) ||
  230. (!samedtype && dec->ihdr->data.ihdr.bpc != JP2_IHDR_BPCNULL)) {
  231. jas_eprintf("warning: component data type mismatch\n");
  232. }
  233. /* Is the compression type supported? */
  234. if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) {
  235. jas_eprintf("error: unsupported compression type\n");
  236. goto error;
  237. }
  238. if (dec->bpcc) {
  239. /* Is the number of components indicated in the BPCC box
  240. consistent with the code stream data? */
  241. if (dec->bpcc->data.bpcc.numcmpts != JAS_CAST(uint, jas_image_numcmpts(
  242. dec->image))) {
  243. jas_eprintf("warning: number of components mismatch\n");
  244. }
  245. /* Is the component data type information indicated in the BPCC
  246. box consistent with the code stream data? */
  247. if (!samedtype) {
  248. for (i = 0; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
  249. if (jas_image_cmptdtype(dec->image, i) != JP2_BPCTODTYPE(dec->bpcc->data.bpcc.bpcs[i])) {
  250. jas_eprintf("warning: component data type mismatch\n");
  251. }
  252. }
  253. } else {
  254. jas_eprintf("warning: superfluous BPCC box\n");
  255. }
  256. }
  257. /* A COLR box must be present. */
  258. if (!dec->colr) {
  259. jas_eprintf("error: no COLR box\n");
  260. goto error;
  261. }
  262. switch (dec->colr->data.colr.method) {
  263. case JP2_COLR_ENUM:
  264. jas_image_setclrspc(dec->image, jp2_getcs(&dec->colr->data.colr));
  265. break;
  266. case JP2_COLR_ICC:
  267. iccprof = jas_iccprof_createfrombuf(dec->colr->data.colr.iccp,
  268. dec->colr->data.colr.iccplen);
  269. assert(iccprof);
  270. jas_iccprof_gethdr(iccprof, &icchdr);
  271. jas_eprintf("ICC Profile CS %08x\n", icchdr.colorspc);
  272. jas_image_setclrspc(dec->image, fromiccpcs(icchdr.colorspc));
  273. dec->image->cmprof_ = jas_cmprof_createfromiccprof(iccprof);
  274. assert(dec->image->cmprof_);
  275. jas_iccprof_destroy(iccprof);
  276. break;
  277. }
  278. /* If a CMAP box is present, a PCLR box must also be present. */
  279. if (dec->cmap && !dec->pclr) {
  280. jas_eprintf("warning: missing PCLR box or superfluous CMAP box\n");
  281. jp2_box_destroy(dec->cmap);
  282. dec->cmap = 0;
  283. }
  284. /* If a CMAP box is not present, a PCLR box must not be present. */
  285. if (!dec->cmap && dec->pclr) {
  286. jas_eprintf("warning: missing CMAP box or superfluous PCLR box\n");
  287. jp2_box_destroy(dec->pclr);
  288. dec->pclr = 0;
  289. }
  290. /* Determine the number of channels (which is essentially the number
  291. of components after any palette mappings have been applied). */
  292. dec->numchans = dec->cmap ? dec->cmap->data.cmap.numchans : JAS_CAST(uint, jas_image_numcmpts(dec->image));
  293. /* Perform a basic sanity check on the CMAP box if present. */
  294. if (dec->cmap) {
  295. for (i = 0; i < dec->numchans; ++i) {
  296. /* Is the component number reasonable? */
  297. if (dec->cmap->data.cmap.ents[i].cmptno >= JAS_CAST(uint, jas_image_numcmpts(dec->image))) {
  298. jas_eprintf("error: invalid component number in CMAP box\n");
  299. goto error;
  300. }
  301. /* Is the LUT index reasonable? */
  302. if (dec->cmap->data.cmap.ents[i].pcol >= dec->pclr->data.pclr.numchans) {
  303. jas_eprintf("error: invalid CMAP LUT index\n");
  304. goto error;
  305. }
  306. }
  307. }
  308. /* Allocate space for the channel-number to component-number LUT. */
  309. if (!(dec->chantocmptlut = jas_alloc2(dec->numchans, sizeof(uint_fast16_t)))) {
  310. jas_eprintf("error: no memory\n");
  311. goto error;
  312. }
  313. if (!dec->cmap) {
  314. for (i = 0; i < dec->numchans; ++i) {
  315. dec->chantocmptlut[i] = i;
  316. }
  317. } else {
  318. cmapd = &dec->cmap->data.cmap;
  319. pclrd = &dec->pclr->data.pclr;
  320. cdefd = &dec->cdef->data.cdef;
  321. for (channo = 0; channo < cmapd->numchans; ++channo) {
  322. cmapent = &cmapd->ents[channo];
  323. if (cmapent->map == JP2_CMAP_DIRECT) {
  324. dec->chantocmptlut[channo] = channo;
  325. } else if (cmapent->map == JP2_CMAP_PALETTE) {
  326. lutents = jas_alloc2(pclrd->numlutents, sizeof(int_fast32_t));
  327. for (i = 0; i < pclrd->numlutents; ++i) {
  328. lutents[i] = pclrd->lutdata[cmapent->pcol + i * pclrd->numchans];
  329. }
  330. newcmptno = jas_image_numcmpts(dec->image);
  331. jas_image_depalettize(dec->image, cmapent->cmptno, pclrd->numlutents, lutents, JP2_BPCTODTYPE(pclrd->bpc[cmapent->pcol]), newcmptno);
  332. dec->chantocmptlut[channo] = newcmptno;
  333. jas_free(lutents);
  334. #if 0
  335. if (dec->cdef) {
  336. cdefent = jp2_cdef_lookup(cdefd, channo);
  337. if (!cdefent) {
  338. abort();
  339. }
  340. jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), cdefent->type, cdefent->assoc));
  341. } else {
  342. jas_image_setcmpttype(dec->image, newcmptno, jp2_getct(jas_image_clrspc(dec->image), 0, channo + 1));
  343. }
  344. #endif
  345. }
  346. }
  347. }
  348. /* Mark all components as being of unknown type. */
  349. for (i = 0; i < JAS_CAST(uint, jas_image_numcmpts(dec->image)); ++i) {
  350. jas_image_setcmpttype(dec->image, i, JAS_IMAGE_CT_UNKNOWN);
  351. }
  352. /* Determine the type of each component. */
  353. if (dec->cdef) {
  354. for (i = 0; i < dec->numchans; ++i) {
  355. jas_image_setcmpttype(dec->image,
  356. dec->chantocmptlut[dec->cdef->data.cdef.ents[i].channo],
  357. jp2_getct(jas_image_clrspc(dec->image),
  358. dec->cdef->data.cdef.ents[i].type, dec->cdef->data.cdef.ents[i].assoc));
  359. }
  360. } else {
  361. for (i = 0; i < dec->numchans; ++i) {
  362. jas_image_setcmpttype(dec->image, dec->chantocmptlut[i],
  363. jp2_getct(jas_image_clrspc(dec->image), 0, i + 1));
  364. }
  365. }
  366. /* Delete any components that are not of interest. */
  367. for (i = jas_image_numcmpts(dec->image); i > 0; --i) {
  368. if (jas_image_cmpttype(dec->image, i - 1) == JAS_IMAGE_CT_UNKNOWN) {
  369. jas_image_delcmpt(dec->image, i - 1);
  370. }
  371. }
  372. /* Ensure that some components survived. */
  373. if (!jas_image_numcmpts(dec->image)) {
  374. jas_eprintf("error: no components\n");
  375. goto error;
  376. }
  377. #if 0
  378. jas_eprintf("no of components is %d\n", jas_image_numcmpts(dec->image));
  379. #endif
  380. /* Prevent the image from being destroyed later. */
  381. image = dec->image;
  382. dec->image = 0;
  383. jp2_dec_destroy(dec);
  384. return image;
  385. error:
  386. if (box) {
  387. jp2_box_destroy(box);
  388. }
  389. if (dec) {
  390. jp2_dec_destroy(dec);
  391. }
  392. return 0;
  393. }
  394. int jp2_validate(jas_stream_t *in)
  395. {
  396. char buf[JP2_VALIDATELEN];
  397. int i;
  398. int n;
  399. #if 0
  400. jas_stream_t *tmpstream;
  401. jp2_box_t *box;
  402. #endif
  403. assert(JAS_STREAM_MAXPUTBACK >= JP2_VALIDATELEN);
  404. /* Read the validation data (i.e., the data used for detecting
  405. the format). */
  406. if ((n = jas_stream_read(in, buf, JP2_VALIDATELEN)) < 0) {
  407. return -1;
  408. }
  409. /* Put the validation data back onto the stream, so that the
  410. stream position will not be changed. */
  411. for (i = n - 1; i >= 0; --i) {
  412. if (jas_stream_ungetc(in, buf[i]) == EOF) {
  413. return -1;
  414. }
  415. }
  416. /* Did we read enough data? */
  417. if (n < JP2_VALIDATELEN) {
  418. return -1;
  419. }
  420. /* Is the box type correct? */
  421. if (((buf[4] << 24) | (buf[5] << 16) | (buf[6] << 8) | buf[7]) !=
  422. JP2_BOX_JP)
  423. {
  424. return -1;
  425. }
  426. return 0;
  427. }
  428. static jp2_dec_t *jp2_dec_create(void)
  429. {
  430. jp2_dec_t *dec;
  431. if (!(dec = jas_malloc(sizeof(jp2_dec_t)))) {
  432. return 0;
  433. }
  434. dec->ihdr = 0;
  435. dec->bpcc = 0;
  436. dec->cdef = 0;
  437. dec->pclr = 0;
  438. dec->image = 0;
  439. dec->chantocmptlut = 0;
  440. dec->cmap = 0;
  441. dec->colr = 0;
  442. return dec;
  443. }
  444. static void jp2_dec_destroy(jp2_dec_t *dec)
  445. {
  446. if (dec->ihdr) {
  447. jp2_box_destroy(dec->ihdr);
  448. }
  449. if (dec->bpcc) {
  450. jp2_box_destroy(dec->bpcc);
  451. }
  452. if (dec->cdef) {
  453. jp2_box_destroy(dec->cdef);
  454. }
  455. if (dec->pclr) {
  456. jp2_box_destroy(dec->pclr);
  457. }
  458. if (dec->image) {
  459. jas_image_destroy(dec->image);
  460. }
  461. if (dec->cmap) {
  462. jp2_box_destroy(dec->cmap);
  463. }
  464. if (dec->colr) {
  465. jp2_box_destroy(dec->colr);
  466. }
  467. if (dec->chantocmptlut) {
  468. jas_free(dec->chantocmptlut);
  469. }
  470. jas_free(dec);
  471. }
  472. static int jp2_getct(int colorspace, int type, int assoc)
  473. {
  474. if (type == 1 && assoc == 0) {
  475. return JAS_IMAGE_CT_OPACITY;
  476. }
  477. if (type == 0 && assoc >= 1 && assoc <= 65534) {
  478. switch (colorspace) {
  479. case JAS_CLRSPC_FAM_RGB:
  480. switch (assoc) {
  481. case JP2_CDEF_RGB_R:
  482. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_R);
  483. break;
  484. case JP2_CDEF_RGB_G:
  485. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_G);
  486. break;
  487. case JP2_CDEF_RGB_B:
  488. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_RGB_B);
  489. break;
  490. }
  491. break;
  492. case JAS_CLRSPC_FAM_YCBCR:
  493. switch (assoc) {
  494. case JP2_CDEF_YCBCR_Y:
  495. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_Y);
  496. break;
  497. case JP2_CDEF_YCBCR_CB:
  498. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CB);
  499. break;
  500. case JP2_CDEF_YCBCR_CR:
  501. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_YCBCR_CR);
  502. break;
  503. }
  504. break;
  505. case JAS_CLRSPC_FAM_GRAY:
  506. switch (assoc) {
  507. case JP2_CDEF_GRAY_Y:
  508. return JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
  509. break;
  510. }
  511. break;
  512. default:
  513. return JAS_IMAGE_CT_COLOR(assoc - 1);
  514. break;
  515. }
  516. }
  517. return JAS_IMAGE_CT_UNKNOWN;
  518. }
  519. static int jp2_getcs(jp2_colr_t *colr)
  520. {
  521. if (colr->method == JP2_COLR_ENUM) {
  522. switch (colr->csid) {
  523. case JP2_COLR_SRGB:
  524. return JAS_CLRSPC_SRGB;
  525. break;
  526. case JP2_COLR_SYCC:
  527. return JAS_CLRSPC_SYCBCR;
  528. break;
  529. case JP2_COLR_SGRAY:
  530. return JAS_CLRSPC_SGRAY;
  531. break;
  532. }
  533. }
  534. return JAS_CLRSPC_UNKNOWN;
  535. }
  536. static int fromiccpcs(int cs)
  537. {
  538. switch (cs) {
  539. case ICC_CS_RGB:
  540. return JAS_CLRSPC_GENRGB;
  541. break;
  542. case ICC_CS_YCBCR:
  543. return JAS_CLRSPC_GENYCBCR;
  544. break;
  545. case ICC_CS_GRAY:
  546. return JAS_CLRSPC_GENGRAY;
  547. break;
  548. }
  549. return JAS_CLRSPC_UNKNOWN;
  550. }