NCEPLIBS-g2  3.4.5
dec_jpeg2000.c
Go to the documentation of this file.
1 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "jasper/jasper.h"
12 #define JAS_1_700_2
13 
14 
15 #ifdef __64BIT__
16  typedef int g2int;
17 #else
18  typedef long g2int;
19 #endif
20 
21 #if defined CRAY90
22  #include <fortran.h>
23  #define SUB_NAME DEC_JPEG2000
24 #elif defined LINUXF90
25  #define SUB_NAME DEC_JPEG2000
26 #elif defined LINUXG95
27  #define SUB_NAME dec_jpeg2000__
28 #elif defined HP || defined AIX
29  #define SUB_NAME dec_jpeg2000
30 #elif defined SGI || defined LINUX || defined VPP5000 || defined APPLE
31  #define SUB_NAME dec_jpeg2000_
32 #endif
33 
52  int SUB_NAME(char *injpc,g2int *bufsize,g2int *outfld)
53 {
54  int ier=0;
55  g2int i,j,k,n;
56  jas_image_t *image=0;
57  jas_stream_t *jpcstream,*istream;
58  jas_image_cmpt_t cmpt,*pcmpt;
59  char *opts=0;
60  jas_matrix_t *data;
61 
62 /* jas_init(); */
63 
64 /*
65 ** Create jas_stream_t containing input JPEG200 codestream in memory.
66 **
67 */
68 
69  jpcstream=jas_stream_memopen(injpc,*bufsize);
70 
71 /*
72 ** Decode JPEG200 codestream into jas_image_t structure.
73 **
74 */
75  image=jpc_decode(jpcstream,opts);
76  if ( image == 0 ) {
77  printf(" jpc_decode return = %d \n",ier);
78  return -3;
79  }
80 
81  pcmpt=image->cmpts_[0];
82 /*
83  printf(" SAGOUT DECODE:\n");
84  printf(" tlx %d \n",image->tlx_);
85  printf(" tly %d \n",image->tly_);
86  printf(" brx %d \n",image->brx_);
87  printf(" bry %d \n",image->bry_);
88  printf(" numcmpts %d \n",image->numcmpts_);
89  printf(" maxcmpts %d \n",image->maxcmpts_);
90 #ifdef JAS_1_500_4
91  printf(" colormodel %d \n",image->colormodel_);
92 #endif
93 #ifdef JAS_1_700_2
94  printf(" colorspace %d \n",image->clrspc_);
95 #endif
96  printf(" inmem %d \n",image->inmem_);
97  printf(" COMPONENT:\n");
98  printf(" tlx %d \n",pcmpt->tlx_);
99  printf(" tly %d \n",pcmpt->tly_);
100  printf(" hstep %d \n",pcmpt->hstep_);
101  printf(" vstep %d \n",pcmpt->vstep_);
102  printf(" width %d \n",pcmpt->width_);
103  printf(" height %d \n",pcmpt->height_);
104  printf(" prec %d \n",pcmpt->prec_);
105  printf(" sgnd %d \n",pcmpt->sgnd_);
106  printf(" cps %d \n",pcmpt->cps_);
107 #ifdef JAS_1_700_2
108  printf(" type %d \n",pcmpt->type_);
109 #endif
110 */
111 
112 /*
113 ** Expecting jpeg2000 image to be grayscale only.
114 ** No color components.
115 **
116 */
117  if (image->numcmpts_ != 1 ) {
118  printf("dec_jpeg2000: Found color image. Grayscale expected.\n");
119  return (-5);
120  }
121 
122 /*
123 ** Create a data matrix of grayscale image values decoded from
124 ** the jpeg2000 codestream.
125 **
126 */
127  data=jas_matrix_create(jas_image_height(image), jas_image_width(image));
128  jas_image_readcmpt(image,0,0,0,jas_image_width(image),
129  jas_image_height(image),data);
130 /*
131 ** Copy data matrix to output integer array.
132 **
133 */
134  k=0;
135  for (i=0;i<pcmpt->height_;i++)
136  for (j=0;j<pcmpt->width_;j++)
137  outfld[k++]=data->rows_[i][j];
138 /*
139 ** Clean up JasPer work structures.
140 **
141 */
142  jas_matrix_destroy(data);
143  ier=jas_stream_close(jpcstream);
144  jas_image_destroy(image);
145 
146  return 0;
147 
148 }
SUB_NAME
int SUB_NAME(char *injpc, g2int *bufsize, g2int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard.
Definition: dec_jpeg2000.c:52
g2int
long g2int
Long Integer type.
Definition: dec_jpeg2000.c:18