5 #include "jasper/jasper.h"
7 #endif /* USE_JPEG2000 */
16 #if defined _UNDERSCORE
17 #define dec_jpeg2000 dec_jpeg2000_
18 #elif defined _DOUBLEUNDERSCORE
19 #define dec_jpeg2000 dec_jpeg2000__
22 int dec_jpeg2000(char *injpc
,g2int
*bufsize
,g2int
*outfld
)
23 /*$$$ SUBPROGRAM DOCUMENTATION BLOCK
25 * SUBPROGRAM: dec_jpeg2000 Decodes JPEG2000 code stream
26 * PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-02
28 * ABSTRACT: This Function decodes a JPEG2000 code stream specified in the
29 * JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer
30 * Software version 1.500.4 (or 1.700.2) written by the University of British
31 * Columbia and Image Power Inc, and others.
32 * JasPer is available at http://www.ece.uvic.ca/~mdadams/jasper/.
34 * PROGRAM HISTORY LOG:
37 * USAGE: int dec_jpeg2000(char *injpc,g2int *bufsize,g2int *outfld)
40 * injpc - Input JPEG2000 code stream.
41 * bufsize - Length (in bytes) of the input JPEG2000 code stream.
44 * outfld - Output matrix of grayscale image values.
47 * 0 = Successful decode
48 * -3 = Error decode jpeg2000 code stream.
49 * -5 = decoded image had multiple color components.
50 * Only grayscale is expected.
54 * Requires JasPer Software version 1.500.4 or 1.700.2
67 jas_stream_t
*jpcstream
,*istream
;
68 jas_image_cmpt_t cmpt
,*pcmpt
;
75 * Create jas_stream_t containing input JPEG200 codestream in memory.
78 jpcstream
=jas_stream_memopen(injpc
,*bufsize
);
81 * Decode JPEG200 codestream into jas_image_t structure.
83 image
=jpc_decode(jpcstream
,opts
);
85 printf(" jpc_decode return = %d \n",ier
);
89 pcmpt
=image
->cmpts_
[0];
91 printf(" SAGOUT DECODE:\n");
92 printf(" tlx %d \n",image->tlx_);
93 printf(" tly %d \n",image->tly_);
94 printf(" brx %d \n",image->brx_);
95 printf(" bry %d \n",image->bry_);
96 printf(" numcmpts %d \n",image->numcmpts_);
97 printf(" maxcmpts %d \n",image->maxcmpts_);
99 printf(" colormodel %d \n",image->colormodel_);
102 printf(" colorspace %d \n",image->clrspc_);
104 printf(" inmem %d \n",image->inmem_);
105 printf(" COMPONENT:\n");
106 printf(" tlx %d \n",pcmpt->tlx_);
107 printf(" tly %d \n",pcmpt->tly_);
108 printf(" hstep %d \n",pcmpt->hstep_);
109 printf(" vstep %d \n",pcmpt->vstep_);
110 printf(" width %d \n",pcmpt->width_);
111 printf(" height %d \n",pcmpt->height_);
112 printf(" prec %d \n",pcmpt->prec_);
113 printf(" sgnd %d \n",pcmpt->sgnd_);
114 printf(" cps %d \n",pcmpt->cps_);
116 printf(" type %d \n",pcmpt->type_);
120 /* Expecting jpeg2000 image to be grayscale only.
121 * No color components.
123 if (image
->numcmpts_
!= 1 ) {
124 printf("dec_jpeg2000: Found color image. Grayscale expected.\n");
129 * Create a data matrix of grayscale image values decoded from
130 * the jpeg2000 codestream.
132 data
=jas_matrix_create(jas_image_height(image
), jas_image_width(image
));
133 jas_image_readcmpt(image
,0,0,0,jas_image_width(image
),
134 jas_image_height(image
),data
);
136 * Copy data matrix to output integer array.
139 for (i
=0;i
<pcmpt
->height_
;i
++)
140 for (j
=0;j
<pcmpt
->width_
;j
++)
141 outfld
[k
++]=data
->rows_
[i
][j
];
143 * Clean up JasPer work structures.
145 jas_matrix_destroy(data
);
146 ier
=jas_stream_close(jpcstream
);
147 jas_image_destroy(image
);
149 #endif /* USE_JPEG2000 */