8 #include "jasper/jasper.h"
11 #define MAXOPTSSIZE 1024
50 jas_stream_t *jpcstream, *istream;
51 jas_image_cmpt_t cmpt, *pcmpt;
60 snprintf(opts,
MAXOPTSSIZE,
"mode=real\nrate=%f",1.0/(
float)ratio);
63 strcat(opts,
"\nnumgbits=4");
69 image.brx_ = (jas_image_coord_t)width;
70 image.bry_ = (jas_image_coord_t)height;
73 image.clrspc_ = JAS_CLRSPC_SGRAY;
80 cmpt.width_ = (jas_image_coord_t)width;
81 cmpt.height_ = (jas_image_coord_t)height;
82 cmpt.type_ = JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
85 cmpt.cps_ = (nbits + 7) / 8;
88 image.cmpts_ = &pcmpt;
96 if (( g2jaspermaxmem = getenv(
"G2_JASPER_MAXMEM")) != NULL )
97 jas_conf_set_max_mem_usage(atoi(g2jaspermaxmem));
100 jas_conf_set_multithread(
true);
101 if (jas_init_library())
103 if (jas_init_thread())
111 istream = jas_stream_memopen((
char *)cin, height * width * cmpt.cps_);
112 cmpt.stream_ = istream;
116 jpcstream = jas_stream_memopen(outjpc, (
int)jpclen);
122 if ((ier = jas_image_encode(&image, jpcstream, fmt, opts)))
127 rwcnt = jpcstream->rwcnt_;
130 ier = jas_stream_close(istream);
131 ier = jas_stream_close(jpcstream);
135 jas_cleanup_thread();
136 jas_cleanup_library();
177 int ltype,
int ratio,
int retry,
char *outjpc,
180 g2int width8 = width, height8 = height, nbits8 = nbits, ltype8 = ltype;
181 g2int ratio8 = ratio, retry8 = retry, jpclen8 = jpclen;
183 return enc_jpeg2000(cin, width8, height8, nbits8, ltype8, ratio8, retry8,
215 jas_image_t *image = NULL;
216 jas_stream_t *jpcstream;
217 jas_image_cmpt_t *pcmpt;
221 char *g2jaspermaxmem;
229 if (( g2jaspermaxmem = getenv(
"G2_JASPER_MAXMEM")) != NULL )
230 jas_conf_set_max_mem_usage(atoi(g2jaspermaxmem));
233 jas_conf_set_multithread(
true);
234 if (jas_init_library())
236 if (jas_init_thread())
245 jpcstream = jas_stream_memopen(injpc, bufsize);
251 if (!(image = jas_image_decode(jpcstream, fmt, opts)))
254 pcmpt = image->cmpts_[0];
279 if (image->numcmpts_ != 1)
284 data = jas_matrix_create(jas_image_height(image), jas_image_width(image));
285 jas_image_readcmpt(image, 0, 0, 0, jas_image_width(image),
286 jas_image_height(image), data);
292 for (i = 0; i < pcmpt->height_; i++)
293 for (
j = 0;
j < pcmpt->width_;
j++)
294 ((
g2int *)outfld)[k++] = data->rows_[i][
j];
298 for (i = 0; i < pcmpt->height_; i++)
299 for (
j = 0;
j < pcmpt->width_;
j++)
300 ((
int *)outfld)[k++] = data->rows_[i][
j];
304 jas_matrix_destroy(data);
305 jas_stream_close(jpcstream);
306 jas_image_destroy(image);
310 jas_cleanup_thread();
311 jas_cleanup_library();
int g2c_dec_jpeg2000(char *injpc, size_t bufsize, int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
int g2c_enc_jpeg2000(unsigned char *cin, int width, int height, int nbits, int ltype, int ratio, int retry, char *outjpc, size_t jpclen)
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 ...
#define MAXOPTSSIZE
Maximum size of options.
static int int_dec_jpeg2000(char *injpc, g2int bufsize, void *outfld, int out_is_g2int)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
int dec_jpeg2000(char *injpc, g2int bufsize, g2int *outfld)
This Function decodes a JPEG2000 code stream specified in the JPEG2000 Part-1 standard (i....
int enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits, g2int ltype, g2int ratio, g2int retry, char *outjpc, g2int jpclen)
This Function encodes a grayscale image into a JPEG2000 code stream specified in the JPEG2000 Part-1 ...
#define G2C_JASPER_JPEG_FORMAT_NAME
Name of JPEG codec in Jasper.
#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 G2C_JASPER_MAX_MEMORY
Max memory size setting for Jasper.
#define G2_JASPER_DECODE
In dec_jpeg2000() error decoding image with jasper.
#define G2_JASPER_DECODE_COLOR
In dec_jpeg2000() decoded image had multiple color components.