merge standard release WRF/WPS V3.0.1.1 into wrffire
[wrffire.git] / wrfv2_fire / external / io_grib2 / g2lib / dec_jpeg2000.c
blob7149dc255c327449a71e6e4c991b358022c21c95
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
8 #ifdef __64BIT__
9 typedef int g2int;
10 #else
11 typedef long g2int;
12 #endif
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
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
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:
39 * 2002-12-02 Gilbert
41 * USAGE: int dec_jpeg2000(char *injpc,g2int *bufsize,g2int *outfld)
43 * INPUT ARGUMENTS:
44 * injpc - Input JPEG2000 code stream.
45 * bufsize - Length (in bytes) of the input JPEG2000 code stream.
47 * INPUT ARGUMENTS:
48 * outfld - Output matrix of grayscale image values.
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.
56 * REMARKS:
58 * Requires JasPer Software version 1.500.4 or 1.700.2
60 * ATTRIBUTES:
61 * LANGUAGE: C
62 * MACHINE: IBM SP
64 *$$$*/
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;
75 /* jas_init(); */
77 /*
78 Create jas_stream_t containing input JPEG200 codestream in memory.
79 */
81 jpcstream=jas_stream_memopen(injpc,*bufsize);
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;
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_);
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
123 /* Expecting jpeg2000 image to be grayscale only.
124 No color components.
126 if (image->numcmpts_ != 1 ) {
127 printf("dec_jpeg2000: Found color image. Grayscale expected.\n");
128 return (-5);
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.
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];
146 Clean up JasPer work structures.
148 jas_matrix_destroy(data);
149 ier=jas_stream_close(jpcstream);
150 jas_image_destroy(image);
152 return 0;