1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #include "jasper/jasper.h" |
---|
5 | #include "proto.h" |
---|
6 | #define JAS_1_700_2 |
---|
7 | |
---|
8 | #ifdef __64BIT__ |
---|
9 | typedef int g2int; |
---|
10 | #else |
---|
11 | typedef long g2int; |
---|
12 | #endif |
---|
13 | |
---|
14 | #ifndef CRAY |
---|
15 | # ifdef NOUNDERSCORE |
---|
16 | # define DEC_JPEG2000 dec_jpeg2000 |
---|
17 | # else |
---|
18 | # ifdef F2CSTYLE |
---|
19 | # define DEC_JPEG2000 dec_jpeg2000__ |
---|
20 | # else |
---|
21 | # define DEC_JPEG2000 dec_jpeg2000_ |
---|
22 | # endif |
---|
23 | # endif |
---|
24 | #endif |
---|
25 | |
---|
26 | int DEC_JPEG2000(char *injpc,g2int *bufsize,g2int *outfld) |
---|
27 | /*$$$ SUBPROGRAM DOCUMENTATION BLOCK |
---|
28 | * . . . . |
---|
29 | * SUBPROGRAM: dec_jpeg2000 Decodes JPEG2000 code stream |
---|
30 | * PRGMMR: Gilbert ORG: W/NP11 DATE: 2002-12-02 |
---|
31 | * |
---|
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/. |
---|
37 | * |
---|
38 | * PROGRAM HISTORY LOG: |
---|
39 | * 2002-12-02 Gilbert |
---|
40 | * |
---|
41 | * USAGE: int dec_jpeg2000(char *injpc,g2int *bufsize,g2int *outfld) |
---|
42 | * |
---|
43 | * INPUT ARGUMENTS: |
---|
44 | * injpc - Input JPEG2000 code stream. |
---|
45 | * bufsize - Length (in bytes) of the input JPEG2000 code stream. |
---|
46 | * |
---|
47 | * INPUT ARGUMENTS: |
---|
48 | * outfld - Output matrix of grayscale image values. |
---|
49 | * |
---|
50 | * RETURN 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. |
---|
55 | * |
---|
56 | * REMARKS: |
---|
57 | * |
---|
58 | * Requires JasPer Software version 1.500.4 or 1.700.2 |
---|
59 | * |
---|
60 | * ATTRIBUTES: |
---|
61 | * LANGUAGE: C |
---|
62 | * MACHINE: IBM SP |
---|
63 | * |
---|
64 | *$$$*/ |
---|
65 | |
---|
66 | { |
---|
67 | int ier; |
---|
68 | g2int i,j,k,n; |
---|
69 | jas_image_t *image=0; |
---|
70 | jas_stream_t *jpcstream,*istream; |
---|
71 | jas_image_cmpt_t cmpt,*pcmpt; |
---|
72 | char *opts=0; |
---|
73 | jas_matrix_t *data; |
---|
74 | |
---|
75 | /* jas_init(); */ |
---|
76 | |
---|
77 | /* |
---|
78 | Create jas_stream_t containing input JPEG200 codestream in memory. |
---|
79 | */ |
---|
80 | |
---|
81 | jpcstream=jas_stream_memopen(injpc,*bufsize); |
---|
82 | |
---|
83 | /* |
---|
84 | Decode JPEG200 codestream into jas_image_t structure. |
---|
85 | */ |
---|
86 | image=jpc_decode(jpcstream,opts); |
---|
87 | if ( image == 0 ) { |
---|
88 | printf(" jpc_decode return = %d \n",ier); |
---|
89 | return -3; |
---|
90 | } |
---|
91 | |
---|
92 | pcmpt=image->cmpts_[0]; |
---|
93 | /* |
---|
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_); |
---|
101 | #ifdef JAS_1_500_4 |
---|
102 | printf(" colormodel %d \n",image->colormodel_); |
---|
103 | #endif |
---|
104 | #ifdef JAS_1_700_2 |
---|
105 | printf(" colorspace %d \n",image->clrspc_); |
---|
106 | #endif |
---|
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_); |
---|
118 | #ifdef JAS_1_700_2 |
---|
119 | printf(" type %d \n",pcmpt->type_); |
---|
120 | #endif |
---|
121 | */ |
---|
122 | |
---|
123 | /* Expecting jpeg2000 image to be grayscale only. |
---|
124 | No color components. |
---|
125 | */ |
---|
126 | if (image->numcmpts_ != 1 ) { |
---|
127 | printf("dec_jpeg2000: Found color image. Grayscale expected.\n"); |
---|
128 | return (-5); |
---|
129 | } |
---|
130 | |
---|
131 | /* |
---|
132 | Create a data matrix of grayscale image values decoded from |
---|
133 | the jpeg2000 codestream. |
---|
134 | */ |
---|
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); |
---|
138 | /* |
---|
139 | Copy data matrix to output integer array. |
---|
140 | */ |
---|
141 | k=0; |
---|
142 | for (i=0;i<pcmpt->height_;i++) |
---|
143 | for (j=0;j<pcmpt->width_;j++) |
---|
144 | outfld[k++]=data->rows_[i][j]; |
---|
145 | /* |
---|
146 | Clean up JasPer work structures. |
---|
147 | */ |
---|
148 | jas_matrix_destroy(data); |
---|
149 | ier=jas_stream_close(jpcstream); |
---|
150 | jas_image_destroy(image); |
---|
151 | |
---|
152 | return 0; |
---|
153 | |
---|
154 | } |
---|