7#include "jasper/jasper.h"
12#define MAXOPTSSIZE 1024
46 int ltype,
int ratio,
int retry,
char *outjpc,
49 g2int width8 = width, height8 = height, nbits8 = nbits, ltype8 = ltype;
50 g2int ratio8 = ratio, retry8 = retry, jpclen8 = jpclen;
52 return enc_jpeg2000(cin, width8, height8, nbits8, ltype8, ratio8, retry8,
100 jas_stream_t *jpcstream, *istream;
101 jas_image_cmpt_t cmpt, *pcmpt;
105 LOG((3,
"enc_jpeg2000 width %ld height %ld nbits %ld ltype %ld ratio %ld retry %ld jpclen %d",
106 width, height, nbits, ltype, ratio, retry, jpclen));
112 snprintf(opts,
MAXOPTSSIZE,
"mode=real\nrate=%f", 1.0 / (
float)ratio);
115 strcat(opts,
"\nnumgbits=4");
121 image.brx_ = (jas_image_coord_t)width;
122 image.bry_ = (jas_image_coord_t)height;
125 image.clrspc_ = JAS_CLRSPC_SGRAY;
132 cmpt.width_ = (jas_image_coord_t)width;
133 cmpt.height_ = (jas_image_coord_t)height;
134 cmpt.type_ = JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
137 cmpt.cps_ = (nbits + 7) / 8;
140 image.cmpts_ = &pcmpt;
148 jas_conf_set_max_mem_usage(10000000);
149 jas_conf_set_multithread(
true);
150 if (jas_init_library())
152 if (jas_init_thread())
160 istream = jas_stream_memopen((
char *)cin, height * width * cmpt.cps_);
161 cmpt.stream_ = istream;
165 jpcstream = jas_stream_memopen(outjpc, (
int)jpclen);
171 if ((ier = jas_image_encode(&image, jpcstream, fmt, opts)))
176 rwcnt = jpcstream->rwcnt_;
179 ier = jas_stream_close(istream);
180 ier = jas_stream_close(jpcstream);
184 jas_cleanup_thread();
185 jas_cleanup_library();
223 jas_image_t *image = NULL;
224 jas_stream_t *jpcstream;
225 jas_image_cmpt_t *pcmpt;
230 LOG((3,
"int_dec_jpeg2000 bufsize %ld out_is_g2int %d", bufsize, out_is_g2int));
239 jas_conf_set_multithread(
true);
240 if (jas_init_library())
242 if (jas_init_thread())
251 jpcstream = jas_stream_memopen(injpc, bufsize);
257 if (!(image = jas_image_decode(jpcstream, fmt, opts)))
260 pcmpt = image->cmpts_[0];
285 if (image->numcmpts_ != 1)
290 data = jas_matrix_create(jas_image_height(image), jas_image_width(image));
291 jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image),
292 jas_image_height(image), data);
294 LOG((3,
"pcmpt->height_ %d pcmpt->width_ %d", pcmpt->height_, pcmpt->width_));
300 for (i = 0; i < pcmpt->height_; i++)
301 for (j = 0; j < pcmpt->width_; j++)
302 ((
g2int *)outfld)[k++] = data->rows_[i][j];
306 for (i = 0; i < pcmpt->height_; i++)
307 for (j = 0; j < pcmpt->width_; j++)
308 ((
int *)outfld)[k++] = data->rows_[i][j];
312 jas_matrix_destroy(data);
313 jas_stream_close(jpcstream);
314 jas_image_destroy(image);
318 jas_cleanup_thread();
319 jas_cleanup_library();
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...
int g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits, int ltype, int ratio, int retry, char *outjpc, size_t jpclen)
Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
#define MAXOPTSSIZE
Maximum size of options.
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...
int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen)
Encode a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
#define G2_JASPER_INIT
In enc_jpeg2000()/dec_jpeg2000() error initializing jasper library.
#define G2_JASPER_ENCODE
In enc_jpeg2000() error encoding image with jasper.
#define G2_JASPER_DECODE
In dec_jpeg2000() error decoding image with jasper.
#define G2C_JASPER_MAX_MEM
Maximum size for the Jasper memory buffer.
#define G2_JASPER_DECODE_COLOR
In dec_jpeg2000() decoded image had multiple color components.
int64_t g2int
Long integer type.
Header file with internal function prototypes NCEPLIBS-g2c library.
#define G2C_JASPER_JPEG_FORMAT_NAME
Name of JPEG codec in Jasper.
#define LOG(e)
Ignore logging to stdout.