Skip to content

Commit

Permalink
Make jasper max memory configurable by env var (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRichert-NOAA authored Sep 26, 2023
1 parent 337c1d1 commit 1d2dd78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/dec_jpeg2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ int_dec_jpeg2000(char *injpc, g2int bufsize, void *outfld, int out_is_g2int)
char *opts = NULL;
jas_matrix_t *data;
int fmt;
char *g2jaspermaxmem;

/* Initialize Jasper. */
#ifdef JASPER3
jas_conf_clear();
/* static jas_std_allocator_t allocator; */
/* jas_std_allocator_init(&allocator); */
/* jas_conf_set_allocator(JAS_CAST(jas_std_allocator_t *, &allocator)); */
jas_conf_set_max_mem_usage(10000000);
if (( g2jaspermaxmem = getenv("G2_JASPER_MAXMEM")) != NULL )
jas_conf_set_max_mem_usage(atoi(g2jaspermaxmem));
else
jas_conf_set_max_mem_usage(1073741824);
jas_conf_set_multithread(true);
if (jas_init_library())
return G2_JASPER_INIT;
Expand Down
6 changes: 5 additions & 1 deletion src/enc_jpeg2000.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits,
jas_image_cmpt_t cmpt, *pcmpt;
char opts[MAXOPTSSIZE];
int fmt;
char *g2jaspermaxmem;

/* Set lossy compression options, if requested. */
if (ltype != 1)
Expand Down Expand Up @@ -139,7 +140,10 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits,
/* static jas_std_allocator_t allocator; */
/* jas_std_allocator_init(&allocator); */
/* jas_conf_set_allocator(JAS_CAST(jas_std_allocator_t *, &allocator)); */
/* jas_conf_set_max_mem_usage(10000000); */
if (( g2jaspermaxmem = getenv("G2_JASPER_MAXMEM")) != NULL )
jas_conf_set_max_mem_usage(atoi(g2jaspermaxmem));
else
jas_conf_set_max_mem_usage(1073741824);
jas_conf_set_multithread(true);
if (jas_init_library())
return G2_JASPER_INIT;
Expand Down

0 comments on commit 1d2dd78

Please sign in to comment.