source: trunk/WRF.COMMON/WRFV2/external/io_grib2/g2lib/dec_jpeg2000.c

Last change on this file was 11, checked in by aslmd, 14 years ago

spiga@svn-planeto:ajoute le modele meso-echelle martien

File size: 3.8 KB
Line 
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   int DEC_JPEG2000(char *injpc,g2int *bufsize,g2int *outfld)
15/*$$$  SUBPROGRAM DOCUMENTATION BLOCK
16*                .      .    .                                       .
17* SUBPROGRAM:    dec_jpeg2000      Decodes JPEG2000 code stream
18*   PRGMMR: Gilbert          ORG: W/NP11     DATE: 2002-12-02
19*
20* ABSTRACT: This Function decodes a JPEG2000 code stream specified in the
21*   JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using JasPer
22*   Software version 1.500.4 (or 1.700.2) written by the University of British
23*   Columbia and Image Power Inc, and others.
24*   JasPer is available at http://www.ece.uvic.ca/~mdadams/jasper/.
25*
26* PROGRAM HISTORY LOG:
27* 2002-12-02  Gilbert
28*
29* USAGE:     int dec_jpeg2000(char *injpc,g2int *bufsize,g2int *outfld)
30*
31*   INPUT ARGUMENTS:
32*      injpc - Input JPEG2000 code stream.
33*    bufsize - Length (in bytes) of the input JPEG2000 code stream.
34*
35*   INPUT ARGUMENTS:
36*     outfld - Output matrix of grayscale image values.
37*
38*   RETURN VALUES :
39*          0 = Successful decode
40*         -3 = Error decode jpeg2000 code stream.
41*         -5 = decoded image had multiple color components.
42*              Only grayscale is expected.
43*
44* REMARKS:
45*
46*      Requires JasPer Software version 1.500.4 or 1.700.2
47*
48* ATTRIBUTES:
49*   LANGUAGE: C
50*   MACHINE:  IBM SP
51*
52*$$$*/
53
54{
55    int ier;
56    g2int i,j,k,n;
57    jas_image_t *image=0;
58    jas_stream_t *jpcstream,*istream;
59    jas_image_cmpt_t cmpt,*pcmpt;
60    char *opts=0;
61    jas_matrix_t *data;
62
63//    jas_init();
64
65//   
66//     Create jas_stream_t containing input JPEG200 codestream in memory.
67//       
68
69    jpcstream=jas_stream_memopen(injpc,*bufsize);
70
71//   
72//     Decode JPEG200 codestream into jas_image_t structure.
73//       
74    image=jpc_decode(jpcstream,opts);
75    if ( image == 0 ) {
76       printf(" jpc_decode return = %d \n",ier);
77       return -3;
78    }
79   
80    pcmpt=image->cmpts_[0];
81/*
82    printf(" SAGOUT DECODE:\n");
83    printf(" tlx %d \n",image->tlx_);
84    printf(" tly %d \n",image->tly_);
85    printf(" brx %d \n",image->brx_);
86    printf(" bry %d \n",image->bry_);
87    printf(" numcmpts %d \n",image->numcmpts_);
88    printf(" maxcmpts %d \n",image->maxcmpts_);
89#ifdef JAS_1_500_4
90    printf(" colormodel %d \n",image->colormodel_);
91#endif
92#ifdef JAS_1_700_2
93    printf(" colorspace %d \n",image->clrspc_);
94#endif
95    printf(" inmem %d \n",image->inmem_);
96    printf(" COMPONENT:\n");
97    printf(" tlx %d \n",pcmpt->tlx_);
98    printf(" tly %d \n",pcmpt->tly_);
99    printf(" hstep %d \n",pcmpt->hstep_);
100    printf(" vstep %d \n",pcmpt->vstep_);
101    printf(" width %d \n",pcmpt->width_);
102    printf(" height %d \n",pcmpt->height_);
103    printf(" prec %d \n",pcmpt->prec_);
104    printf(" sgnd %d \n",pcmpt->sgnd_);
105    printf(" cps %d \n",pcmpt->cps_);
106#ifdef JAS_1_700_2
107    printf(" type %d \n",pcmpt->type_);
108#endif
109*/
110
111//   Expecting jpeg2000 image to be grayscale only.
112//   No color components.
113//
114    if (image->numcmpts_ != 1 ) {
115       printf("dec_jpeg2000: Found color image.  Grayscale expected.\n");
116       return (-5);
117    }
118
119//
120//    Create a data matrix of grayscale image values decoded from
121//    the jpeg2000 codestream.
122//
123    data=jas_matrix_create(jas_image_height(image), jas_image_width(image));
124    jas_image_readcmpt(image,0,0,0,jas_image_width(image),
125                       jas_image_height(image),data);
126//
127//    Copy data matrix to output integer array.
128//
129    k=0;
130    for (i=0;i<pcmpt->height_;i++) 
131      for (j=0;j<pcmpt->width_;j++) 
132        outfld[k++]=data->rows_[i][j];
133//
134//     Clean up JasPer work structures.
135//
136    jas_matrix_destroy(data);
137    ier=jas_stream_close(jpcstream);
138    jas_image_destroy(image);
139
140    return 0;
141
142}
Note: See TracBrowser for help on using the repository browser.