Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use scaled integer array (ifld) in OpenJPEG version of enc_jpeg2000 #510

Merged
merged 4 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/decenc_openjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,9 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits,
{
(void)retry;
int iret = 0;
int nbytes = 0;
const int numcomps = 1;
g2int *ifld = NULL;

opj_codec_t *codec = NULL;
opj_image_t *image = NULL;
Expand Down Expand Up @@ -438,9 +440,14 @@ enc_jpeg2000(unsigned char *cin, g2int width, g2int height, g2int nbits,

assert(cmptparm.prec <= sizeof(image->comps[0].data[0]) * 8 - 1); /* BR: -1 because I don't know what happens if the sign bit is set */

ifld = malloc(width * height * sizeof(g2int));
nbytes = (nbits + 7) / 8;
gbits(cin, ifld, 0, nbytes * 8, 0, width * height);
/* Simple packing */
for (int i = 0; i < width * height; i++)
image->comps[0].data[i] = cin[i];
for (int i = 0; i < width * height; i++) {
image->comps[0].data[i] = ifld[i];
}
free(ifld);

/* get a J2K compressor handle */
codec = opj_create_compress(OPJ_CODEC_J2K);
Expand Down
6 changes: 3 additions & 3 deletions tests/tst_jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ main()

printf("Testing jpcpack()/jpcunpack() call...");
{
float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0};
float fld[DATA_LEN] = {100.0, 200.0, 300.0, 0.0};
float fld_in[DATA_LEN];
g2int lcpack = PACKED_LEN;
g2int idrstmpl[7] = {0, 1, 1, 16, 0, 0, 0};
Expand All @@ -103,7 +103,7 @@ main()
printf("ok!\n");
printf("Testing g2c_jpcpackd()/g2c_jpcunpackd() call...");
{
double fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0};
double fld[DATA_LEN] = {10000.0, 20000.0, 30000.0, 0.0};
double fld_in[DATA_LEN];
size_t lcpack_st = PACKED_LEN;
int idrstmpl[7] = {0, 1, 1, 16, 0, 0, 0};
Expand All @@ -125,7 +125,7 @@ main()
printf("ok!\n");
printf("Testing g2c_jpcpackf()/g2c_jpcunpackf() call...");
{
float fld[DATA_LEN] = {1.0, 2.0, 3.0, 0.0};
float fld[DATA_LEN] = {1000.0, 2000.0, 3000.0, 0.0};
float fld_in[DATA_LEN];
size_t lcpack_st = PACKED_LEN;
int idrstmpl[7] = {0, 1, 1, 16, 0, 0, 0};
Expand Down
Loading