4 #include "jasper/jasper.h"
16 # define DEC_JPEG2000 dec_jpeg2000
19 # define DEC_JPEG2000 dec_jpeg2000__
21 # define DEC_JPEG2000 dec_jpeg2000_
26 int DEC_JPEG2000(char *injpc
,g2int
*bufsize
,g2int
*outfld
)
27 /*$$$ SUBPROGRAM DOCUMENTATION BLOCK
29 * SUBPROGRAM: dec_jpeg2000 Decodes JPEG2000 code stream
30 * PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-02
32 * ABSTRACT: This Function decodes a JPEG2000 code stream specified in the
33 * JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer
34 * Software version 1.500.4 (or 1.700.2) written by the University of British
35 * Columbia and Image Power Inc, and others.
36 * JasPer is available at http://www.ece.uvic.ca/~mdadams/jasper/.
38 * PROGRAM HISTORY LOG:
41 * USAGE: int dec_jpeg2000(char *injpc,g2int *bufsize,g2int *outfld)
44 * injpc - Input JPEG2000 code stream.
45 * bufsize - Length (in bytes) of the input JPEG2000 code stream.
48 * outfld - Output matrix of grayscale image values.
51 * 0 = Successful decode
52 * -3 = Error decode jpeg2000 code stream.
53 * -5 = decoded image had multiple color components.
54 * Only grayscale is expected.
58 * Requires JasPer Software version 1.500.4 or 1.700.2
70 jas_stream_t
*jpcstream
,*istream
;
71 jas_image_cmpt_t cmpt
,*pcmpt
;
78 Create jas_stream_t containing input JPEG200 codestream in memory.
81 jpcstream
=jas_stream_memopen(injpc
,*bufsize
);
84 Decode JPEG200 codestream into jas_image_t structure.
86 image
=jpc_decode(jpcstream
,opts
);
88 printf(" jpc_decode return = %d \n",ier
);
92 pcmpt
=image
->cmpts_
[0];
94 printf(" SAGOUT DECODE:\n");
95 printf(" tlx %d \n",image->tlx_);
96 printf(" tly %d \n",image->tly_);
97 printf(" brx %d \n",image->brx_);
98 printf(" bry %d \n",image->bry_);
99 printf(" numcmpts %d \n",image->numcmpts_);
100 printf(" maxcmpts %d \n",image->maxcmpts_);
102 printf(" colormodel %d \n",image->colormodel_);
105 printf(" colorspace %d \n",image->clrspc_);
107 printf(" inmem %d \n",image->inmem_);
108 printf(" COMPONENT:\n");
109 printf(" tlx %d \n",pcmpt->tlx_);
110 printf(" tly %d \n",pcmpt->tly_);
111 printf(" hstep %d \n",pcmpt->hstep_);
112 printf(" vstep %d \n",pcmpt->vstep_);
113 printf(" width %d \n",pcmpt->width_);
114 printf(" height %d \n",pcmpt->height_);
115 printf(" prec %d \n",pcmpt->prec_);
116 printf(" sgnd %d \n",pcmpt->sgnd_);
117 printf(" cps %d \n",pcmpt->cps_);
119 printf(" type %d \n",pcmpt->type_);
123 /* Expecting jpeg2000 image to be grayscale only.
126 if (image
->numcmpts_
!= 1 ) {
127 printf("dec_jpeg2000: Found color image. Grayscale expected.\n");
132 Create a data matrix of grayscale image values decoded from
133 the jpeg2000 codestream.
135 data
=jas_matrix_create(jas_image_height(image
), jas_image_width(image
));
136 jas_image_readcmpt(image
,0,0,0,jas_image_width(image
),
137 jas_image_height(image
),data
);
139 Copy data matrix to output integer array.
142 for (i
=0;i
<pcmpt
->height_
;i
++)
143 for (j
=0;j
<pcmpt
->width_
;j
++)
144 outfld
[k
++]=data
->rows_
[i
][j
];
146 Clean up JasPer work structures.
148 jas_matrix_destroy(data
);
149 ier
=jas_stream_close(jpcstream
);
150 jas_image_destroy(image
);