9 #include "jasper/jasper.h"
11 #define MAXOPTSSIZE 1024
57 jas_stream_t *jpcstream, *istream;
58 jas_image_cmpt_t cmpt, *pcmpt;
66 snprintf(opts,
MAXOPTSSIZE,
"mode=real\nrate=%f",1.0/(
float)ratio);
69 strcat(opts,
"\nnumgbits=4");
75 image.brx_ = (jas_image_coord_t)width;
76 image.bry_ = (jas_image_coord_t)height;
79 image.clrspc_ = JAS_CLRSPC_SGRAY;
86 cmpt.width_ = (jas_image_coord_t)width;
87 cmpt.height_ = (jas_image_coord_t)height;
88 cmpt.type_ = JAS_IMAGE_CT_COLOR(JAS_CLRSPC_CHANIND_GRAY_Y);
91 cmpt.cps_ = (nbits + 7) / 8;
94 image.cmpts_ = &pcmpt;
102 jas_conf_set_max_mem_usage(10000000);
103 jas_conf_set_multithread(
true);
104 if (jas_init_library())
106 if (jas_init_thread())
114 istream = jas_stream_memopen((
char *)cin, height * width * cmpt.cps_);
115 cmpt.stream_ = istream;
119 jpcstream = jas_stream_memopen(outjpc, (
int)jpclen);
125 if ((ier = jas_image_encode(&image, jpcstream, fmt, opts)))
130 rwcnt = jpcstream->rwcnt_;
133 ier = jas_stream_close(istream);
134 ier = jas_stream_close(jpcstream);
138 jas_cleanup_thread();
139 jas_cleanup_library();