NCEPLIBS-g2c  1.6.4
dec_jpeg2000.c
Go to the documentation of this file.
1 
6 #ifndef USE_JPEG2000
12 void dummy(void) {}
13 #else /* USE_JPEG2000 */
14 
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include "grib2.h"
19 #include "jasper/jasper.h"
20 #define JAS_1_700_2
21 
41 int
42 dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
43 {
44  g2int i, j, k;
45  jas_image_t *image = NULL;
46  jas_stream_t *jpcstream;
47  jas_image_cmpt_t *pcmpt;
48  char *opts = NULL;
49  jas_matrix_t *data;
50 
51  /* Create jas_stream_t containing input JPEG200 codestream in
52  * memory. */
53  jpcstream = jas_stream_memopen(injpc, bufsize);
54 
55  /* Decode JPEG200 codestream into jas_image_t structure. */
56  if (!(image = jpc_decode(jpcstream, opts)))
57  {
58  printf(" jpc_decode return\n");
59  return -3;
60  }
61 
62  pcmpt = image->cmpts_[0];
63  /*
64  printf(" SAGOUT DECODE:\n");
65  printf(" tlx %d \n", image->tlx_);
66  printf(" tly %d \n", image->tly_);
67  printf(" brx %d \n", image->brx_);
68  printf(" bry %d \n", image->bry_);
69  printf(" numcmpts %d \n", image->numcmpts_);
70  printf(" maxcmpts %d \n", image->maxcmpts_);
71  #ifdef JAS_1_500_4
72  printf(" colormodel %d \n", image->colormodel_);
73  #endif
74  #ifdef JAS_1_700_2
75  printf(" colorspace %d \n", image->clrspc_);
76  #endif
77  printf(" inmem %d \n", image->inmem_);
78  printf(" COMPONENT:\n");
79  printf(" tlx %d \n", pcmpt->tlx_);
80  printf(" tly %d \n", pcmpt->tly_);
81  printf(" hstep %d \n", pcmpt->hstep_);
82  printf(" vstep %d \n", pcmpt->vstep_);
83  printf(" width %d \n", pcmpt->width_);
84  printf(" height %d \n", pcmpt->height_);
85  printf(" prec %d \n", pcmpt->prec_);
86  printf(" sgnd %d \n", pcmpt->sgnd_);
87  printf(" cps %d \n", pcmpt->cps_);
88  #ifdef JAS_1_700_2
89  printf(" type %d \n", pcmpt->type_);
90  #endif
91  */
92 
93  /* Expecting jpeg2000 image to be grayscale only. No color components. */
94  if (image->numcmpts_ != 1)
95  {
96  printf("dec_jpeg2000: Found color image. Grayscale expected.\n");
97  return (-5);
98  }
99 
100  /* Create a data matrix of grayscale image values decoded from the
101  * jpeg2000 codestream. */
102  data = jas_matrix_create(jas_image_height(image), jas_image_width(image));
103  jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image),
104  jas_image_height(image), data);
105 
106  /* Copy data matrix to output integer array. */
107  k = 0;
108  for (i = 0; i < pcmpt->height_; i++)
109  for (j = 0; j < pcmpt->width_; j++)
110  outfld[k++] = data->rows_[i][j];
111 
112  /* Clean up JasPer work structures. */
113  jas_matrix_destroy(data);
114  jas_stream_close(jpcstream);
115  jas_image_destroy(image);
116 
117  return 0;
118 }
119 #endif /* USE_JPEG2000 */
int dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
Definition: dec_jpeg2000.c:42
Header file for NCEPLIBS-g2c library.
int64_t g2int
Long integer type.
Definition: grib2.h:20