NCEPLIBS-g2c 1.9.0
Loading...
Searching...
No Matches
dec_jpeg2000.c
Go to the documentation of this file.
1
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include "grib2_int.h"
10#include "jasper/jasper.h"
11
37static int
38int_dec_jpeg2000(char *injpc, g2int bufsize, void *outfld, int out_is_g2int)
39{
40 g2int i, j, k;
41 jas_image_t *image = NULL;
42 jas_stream_t *jpcstream;
43 jas_image_cmpt_t *pcmpt;
44 char *opts = NULL;
45 jas_matrix_t *data;
46 int fmt;
47
48 LOG((3, "int_dec_jpeg2000 bufsize %ld out_is_g2int %d", bufsize, out_is_g2int));
49
50 /* Initialize Jasper. */
51#ifdef JASPER3
52 jas_conf_clear();
53 /* static jas_std_allocator_t allocator; */
54 /* jas_std_allocator_init(&allocator); */
55 /* jas_conf_set_allocator(JAS_CAST(jas_std_allocator_t *, &allocator)); */
56 jas_conf_set_max_mem_usage(G2C_JASPER_MAX_MEM);
57 jas_conf_set_multithread(true);
58 if (jas_init_library())
59 return G2_JASPER_INIT;
60 if (jas_init_thread())
61 return G2_JASPER_INIT;
62#else
63 if (jas_init())
64 return G2_JASPER_INIT;
65#endif /* JASPER3 */
66
67 /* Create jas_stream_t containing input JPEG200 codestream in
68 * memory. */
69 jpcstream = jas_stream_memopen(injpc, bufsize);
70
71 /* Get jasper ID of JPEG encoder. */
72 fmt = jas_image_strtofmt(G2C_JASPER_JPEG_FORMAT_NAME);
73
74 /* Decode JPEG200 codestream into jas_image_t structure. */
75 if (!(image = jas_image_decode(jpcstream, fmt, opts)))
76 return G2_JASPER_DECODE;
77
78 pcmpt = image->cmpts_[0];
79 /*
80 printf(" SAGOUT DECODE:\n");
81 printf(" tlx %d \n", image->tlx_);
82 printf(" tly %d \n", image->tly_);
83 printf(" brx %d \n", image->brx_);
84 printf(" bry %d \n", image->bry_);
85 printf(" numcmpts %d \n", image->numcmpts_);
86 printf(" maxcmpts %d \n", image->maxcmpts_);
87 printf(" colorspace %d \n", image->clrspc_);
88 printf(" inmem %d \n", image->inmem_);
89 printf(" COMPONENT:\n");
90 printf(" tlx %d \n", pcmpt->tlx_);
91 printf(" tly %d \n", pcmpt->tly_);
92 printf(" hstep %d \n", pcmpt->hstep_);
93 printf(" vstep %d \n", pcmpt->vstep_);
94 printf(" width %d \n", pcmpt->width_);
95 printf(" height %d \n", pcmpt->height_);
96 printf(" prec %d \n", pcmpt->prec_);
97 printf(" sgnd %d \n", pcmpt->sgnd_);
98 printf(" cps %d \n", pcmpt->cps_);
99 printf(" type %d \n", pcmpt->type_);
100 */
101
102 /* Expecting jpeg2000 image to be grayscale only. No color components. */
103 if (image->numcmpts_ != 1)
105
106 /* Create a data matrix of grayscale image values decoded from the
107 * jpeg2000 codestream. */
108 data = jas_matrix_create(jas_image_height(image), jas_image_width(image));
109 jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image),
110 jas_image_height(image), data);
111
112
113 LOG((3, "pcmpt->height_ %d pcmpt->width_ %d", pcmpt->height_, pcmpt->width_));
114
115 /* Copy data matrix to output integer array. */
116 k = 0;
117 if (out_is_g2int)
118 {
119 for (i = 0; i < pcmpt->height_; i++)
120 for (j = 0; j < pcmpt->width_; j++)
121 ((g2int *)outfld)[k++] = data->rows_[i][j];
122 }
123 else
124 {
125 for (i = 0; i < pcmpt->height_; i++)
126 for (j = 0; j < pcmpt->width_; j++)
127 ((int *)outfld)[k++] = data->rows_[i][j];
128 }
129
130 /* Clean up JasPer work structures. */
131 jas_matrix_destroy(data);
132 jas_stream_close(jpcstream);
133 jas_image_destroy(image);
134
135 /* Finalize jasper. */
136#ifdef JASPER3
137 jas_cleanup_thread();
138 jas_cleanup_library();
139#else
140 jas_cleanup();
141#endif /* JASPER3 */
142
143 return 0;
144}
145
167int
168g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld)
169{
170 return int_dec_jpeg2000(injpc, bufsize, outfld, 0);
171}
172
194int
195dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
196{
197 return int_dec_jpeg2000(injpc, bufsize, outfld, 1);
198}
199
int g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld)
Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using...
static int int_dec_jpeg2000(char *injpc, g2int bufsize, void *outfld, int out_is_g2int)
Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using...
int dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
Decode a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i.e., ISO/IEC 15444-1) using...
#define G2_JASPER_INIT
In enc_jpeg2000()/dec_jpeg2000() error initializing jasper library.
Definition grib2.h:485
#define G2_JASPER_DECODE
In dec_jpeg2000() error decoding image with jasper.
Definition grib2.h:487
#define G2C_JASPER_MAX_MEM
Maximum size for the Jasper memory buffer.
Definition grib2.h:435
#define G2_JASPER_DECODE_COLOR
In dec_jpeg2000() decoded image had multiple color components.
Definition grib2.h:488
int64_t g2int
Long integer type.
Definition grib2.h:32
Header file with internal function prototypes NCEPLIBS-g2c library.
#define G2C_JASPER_JPEG_FORMAT_NAME
Name of JPEG codec in Jasper.
Definition grib2_int.h:33
#define LOG(e)
Ignore logging to stdout.
Definition grib2_int.h:426