9 #include "jasper/jasper.h"
11 #define MAXOPTSSIZE 1024
52 int ltype,
int ratio,
int retry,
char *outjpc,
55 g2int width8 = width, height8 = height, nbits8 = nbits, ltype8 = ltype;
56 g2int ratio8 = ratio, retry8 = retry, jpclen8 = jpclen;
58 return enc_jpeg2000(cin, width8, height8, nbits8, ltype8, ratio8, retry8,
106 jas_stream_t *jpcstream, *istream;
107 jas_image_cmpt_t cmpt, *pcmpt;
111 LOG((3,
"enc_jpeg2000 width %ld height %ld nbits %ld ltype %ld ratio %ld retry %ld jpclen %d",
112 width, height, nbits, ltype, ratio, retry, jpclen));
118 snprintf(opts,
MAXOPTSSIZE,
"mode=real\nrate=%f",1.0/(
float)ratio);
121 strcat(opts,
"\nnumgbits=4");
127 image.brx_ = (jas_image_coord_t)width;
128 image.bry_ = (jas_image_coord_t)height;
131 image.clrspc_ = JAS_CLRSPC_SGRAY;
138 cmpt.width_ = (jas_image_coord_t)width;
139 cmpt.height_ = (jas_image_coord_t)height;
140 cmpt.type_ = JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
143 cmpt.cps_ = (nbits + 7) / 8;
146 image.cmpts_ = &pcmpt;
154 jas_conf_set_max_mem_usage(10000000);
155 jas_conf_set_multithread(
true);
156 if (jas_init_library())
158 if (jas_init_thread())
166 istream = jas_stream_memopen((
char *)cin, height * width * cmpt.cps_);
167 cmpt.stream_ = istream;
171 jpcstream = jas_stream_memopen(outjpc, (
int)jpclen);
177 if ((ier = jas_image_encode(&image, jpcstream, fmt, opts)))
182 rwcnt = jpcstream->rwcnt_;
185 ier = jas_stream_close(istream);
186 ier = jas_stream_close(jpcstream);
190 jas_cleanup_thread();
191 jas_cleanup_library();
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.
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 G2_JASPER_INIT
In enc_jpeg2000()/dec_jpeg2000() error initializing jasper library.
#define G2_JASPER_ENCODE
In enc_jpeg2000() error encoding image with jasper.
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.