Compare commits

...

5 Commits

Author SHA1 Message Date
Antonin Descampe
0febbff19e processed all c/h files through astyle with opj_astyle.cfg 2016-01-25 23:22:06 +01:00
Antonin Descampe
bede1568b1 Merge branch 'master' into codingstyle 2016-01-25 22:43:03 +01:00
Antonin Descampe
6ec68a27f8 modified astyle config 2016-01-25 15:03:21 +01:00
Antonin Descampe
4b927ecea3 modified style cfg 2016-01-24 19:00:31 +01:00
Antonin Descampe
0efb2f5293 adding astyle and uncrustify config files 2016-01-24 18:54:13 +01:00
261 changed files with 71174 additions and 71149 deletions

View File

@ -76,15 +76,22 @@ static void sycc_to_rgb(int offset, int upb, int y, int cb, int cr,
{ {
int r, g, b; int r, g, b;
cb -= offset; cr -= offset; cb -= offset;
cr -= offset;
r = y + (int)(1.402 * (float)cr); r = y + (int)(1.402 * (float)cr);
if(r < 0) r = 0; else if(r > upb) r = upb; *out_r = r; if(r < 0) r = 0;
else if(r > upb) r = upb;
*out_r = r;
g = y - (int)(0.344 * (float)cb + 0.714 * (float)cr); g = y - (int)(0.344 * (float)cb + 0.714 * (float)cr);
if(g < 0) g = 0; else if(g > upb) g = upb; *out_g = g; if(g < 0) g = 0;
else if(g > upb) g = upb;
*out_g = g;
b = y + (int)(1.772 * (float)cb); b = y + (int)(1.772 * (float)cb);
if(b < 0) b = 0; else if(b > upb) b = upb; *out_b = b; if(b < 0) b = 0;
else if(b > upb) b = upb;
*out_b = b;
} }
static void sycc444_to_rgb(opj_image_t *img) static void sycc444_to_rgb(opj_image_t *img)
@ -95,9 +102,11 @@ static void sycc444_to_rgb(opj_image_t *img)
int offset, upb; int offset, upb;
upb = (int)img->comps[0].prec; upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1); upb = (1<<upb)-1; offset = 1<<(upb - 1);
upb = (1<<upb)-1;
maxw = (unsigned int)img->comps[0].w; maxh = (unsigned int)img->comps[0].h; maxw = (unsigned int)img->comps[0].w;
maxh = (unsigned int)img->comps[0].h;
max = maxw * maxh; max = maxw * maxh;
y = img->comps[0].data; y = img->comps[0].data;
@ -108,14 +117,21 @@ static void sycc444_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i = 0U; i < max; ++i) for(i = 0U; i < max; ++i) {
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++cb; ++cr; ++r; ++g; ++b; ++y;
++cb;
++cr;
++r;
++g;
++b;
} }
free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[0].data);
free(img->comps[1].data); img->comps[1].data = d1; img->comps[0].data = d0;
free(img->comps[2].data); img->comps[2].data = d2; free(img->comps[1].data);
img->comps[1].data = d1;
free(img->comps[2].data);
img->comps[2].data = d2;
}/* sycc444_to_rgb() */ }/* sycc444_to_rgb() */
@ -128,9 +144,11 @@ static void sycc422_to_rgb(opj_image_t *img)
unsigned int i, j; unsigned int i, j;
upb = (int)img->comps[0].prec; upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1); upb = (1<<upb)-1; offset = 1<<(upb - 1);
upb = (1<<upb)-1;
maxw = (unsigned int)img->comps[0].w; maxh = (unsigned int)img->comps[0].h; maxw = (unsigned int)img->comps[0].w;
maxh = (unsigned int)img->comps[0].h;
max = maxw * maxh; max = maxw * maxh;
y = img->comps[0].data; y = img->comps[0].data;
@ -141,30 +159,48 @@ static void sycc422_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0U; i < maxh; ++i) for(i=0U; i < maxh; ++i) {
{ for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) {
for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++y;
++r;
++g;
++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr; ++y;
++r;
++g;
++b;
++cb;
++cr;
} }
if (j < maxw) { if (j < maxw) {
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr; ++y;
++r;
++g;
++b;
++cb;
++cr;
} }
} }
free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[0].data);
free(img->comps[1].data); img->comps[1].data = d1; img->comps[0].data = d0;
free(img->comps[2].data); img->comps[2].data = d2; free(img->comps[1].data);
img->comps[1].data = d1;
free(img->comps[2].data);
img->comps[2].data = d2;
#if defined(USE_JPWL) || defined(USE_MJ2) #if defined(USE_JPWL) || defined(USE_MJ2)
img->comps[1].w = maxw; img->comps[1].h = maxh; img->comps[1].w = maxw;
img->comps[2].w = maxw; img->comps[2].h = maxh; img->comps[1].h = maxh;
img->comps[2].w = maxw;
img->comps[2].h = maxh;
#else #else
img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; img->comps[1].w = (OPJ_UINT32)maxw;
img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw;
img->comps[2].h = (OPJ_UINT32)maxh;
#endif #endif
img->comps[1].dx = img->comps[0].dx; img->comps[1].dx = img->comps[0].dx;
img->comps[2].dx = img->comps[0].dx; img->comps[2].dx = img->comps[0].dx;
@ -182,9 +218,11 @@ static void sycc420_to_rgb(opj_image_t *img)
unsigned int i, j; unsigned int i, j;
upb = (int)img->comps[0].prec; upb = (int)img->comps[0].prec;
offset = 1<<(upb - 1); upb = (1<<upb)-1; offset = 1<<(upb - 1);
upb = (1<<upb)-1;
maxw = (unsigned int)img->comps[0].w; maxh = (unsigned int)img->comps[0].h; maxw = (unsigned int)img->comps[0].w;
maxh = (unsigned int)img->comps[0].h;
max = maxw * maxh; max = maxw * maxh;
y = img->comps[0].data; y = img->comps[0].data;
@ -195,61 +233,97 @@ static void sycc420_to_rgb(opj_image_t *img)
d1 = g = (int*)malloc(sizeof(int) * (size_t)max); d1 = g = (int*)malloc(sizeof(int) * (size_t)max);
d2 = b = (int*)malloc(sizeof(int) * (size_t)max); d2 = b = (int*)malloc(sizeof(int) * (size_t)max);
for(i=0U; i < (maxh & ~(unsigned int)1U); i += 2U) for(i=0U; i < (maxh & ~(unsigned int)1U); i += 2U) {
{
ny = y + maxw; ny = y + maxw;
nr = r + maxw; ng = g + maxw; nb = b + maxw; nr = r + maxw;
ng = g + maxw;
nb = b + maxw;
for(j=0; j < (maxw & ~(unsigned int)1U); j += 2U) for(j=0; j < (maxw & ~(unsigned int)1U); j += 2U) {
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++y;
++r;
++g;
++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++y;
++r;
++g;
++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++ny;
++nr;
++ng;
++nb;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr; ++ny;
++nr;
++ng;
++nb;
++cb;
++cr;
} }
if(j < maxw) if(j < maxw) {
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++y;
++r;
++g;
++b;
sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb); sycc_to_rgb(offset, upb, *ny, *cb, *cr, nr, ng, nb);
++ny; ++nr; ++ng; ++nb; ++cb; ++cr; ++ny;
++nr;
++ng;
++nb;
++cb;
++cr;
} }
y += maxw; r += maxw; g += maxw; b += maxw; y += maxw;
r += maxw;
g += maxw;
b += maxw;
} }
if(i < maxh) if(i < maxh) {
{ for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U) {
for(j=0U; j < (maxw & ~(unsigned int)1U); j += 2U)
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++y;
++r;
++g;
++b;
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
++y; ++r; ++g; ++b; ++cb; ++cr; ++y;
++r;
++g;
++b;
++cb;
++cr;
} }
if(j < maxw) if(j < maxw) {
{
sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b); sycc_to_rgb(offset, upb, *y, *cb, *cr, r, g, b);
} }
} }
free(img->comps[0].data); img->comps[0].data = d0; free(img->comps[0].data);
free(img->comps[1].data); img->comps[1].data = d1; img->comps[0].data = d0;
free(img->comps[2].data); img->comps[2].data = d2; free(img->comps[1].data);
img->comps[1].data = d1;
free(img->comps[2].data);
img->comps[2].data = d2;
#if defined(USE_JPWL) || defined(USE_MJ2) #if defined(USE_JPWL) || defined(USE_MJ2)
img->comps[1].w = maxw; img->comps[1].h = maxh; img->comps[1].w = maxw;
img->comps[2].w = maxw; img->comps[2].h = maxh; img->comps[1].h = maxh;
img->comps[2].w = maxw;
img->comps[2].h = maxh;
#else #else
img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; img->comps[1].w = (OPJ_UINT32)maxw;
img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; img->comps[1].h = (OPJ_UINT32)maxh;
img->comps[2].w = (OPJ_UINT32)maxw;
img->comps[2].h = (OPJ_UINT32)maxh;
#endif #endif
img->comps[1].dx = img->comps[0].dx; img->comps[1].dx = img->comps[0].dx;
img->comps[2].dx = img->comps[0].dx; img->comps[2].dx = img->comps[0].dx;
@ -260,8 +334,7 @@ static void sycc420_to_rgb(opj_image_t *img)
void color_sycc_to_rgb(opj_image_t *img) void color_sycc_to_rgb(opj_image_t *img)
{ {
if(img->numcomps < 3) if(img->numcomps < 3) {
{
img->color_space = OPJ_CLRSPC_GRAY; img->color_space = OPJ_CLRSPC_GRAY;
return; return;
} }
@ -271,32 +344,23 @@ void color_sycc_to_rgb(opj_image_t *img)
&& (img->comps[2].dx == 2) && (img->comps[2].dx == 2)
&& (img->comps[0].dy == 1) && (img->comps[0].dy == 1)
&& (img->comps[1].dy == 2) && (img->comps[1].dy == 2)
&& (img->comps[2].dy == 2))/* horizontal and vertical sub-sample */ && (img->comps[2].dy == 2)) { /* horizontal and vertical sub-sample */
{
sycc420_to_rgb(img); sycc420_to_rgb(img);
} } else if((img->comps[0].dx == 1)
else
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 2) && (img->comps[1].dx == 2)
&& (img->comps[2].dx == 2) && (img->comps[2].dx == 2)
&& (img->comps[0].dy == 1) && (img->comps[0].dy == 1)
&& (img->comps[1].dy == 1) && (img->comps[1].dy == 1)
&& (img->comps[2].dy == 1))/* horizontal sub-sample only */ && (img->comps[2].dy == 1)) { /* horizontal sub-sample only */
{
sycc422_to_rgb(img); sycc422_to_rgb(img);
} } else if((img->comps[0].dx == 1)
else
if((img->comps[0].dx == 1)
&& (img->comps[1].dx == 1) && (img->comps[1].dx == 1)
&& (img->comps[2].dx == 1) && (img->comps[2].dx == 1)
&& (img->comps[0].dy == 1) && (img->comps[0].dy == 1)
&& (img->comps[1].dy == 1) && (img->comps[1].dy == 1)
&& (img->comps[2].dy == 1))/* no sub-sample */ && (img->comps[2].dy == 1)) { /* no sub-sample */
{
sycc444_to_rgb(img); sycc444_to_rgb(img);
} } else {
else
{
fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__); fprintf(stderr,"%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__,__LINE__);
return; return;
} }
@ -353,39 +417,27 @@ void color_apply_icc_profile(opj_image_t *image)
prec = (int)image->comps[0].prec; prec = (int)image->comps[0].prec;
oldspace = image->color_space; oldspace = image->color_space;
if(out_space == cmsSigRgbData) /* enumCS 16 */ if(out_space == cmsSigRgbData) { /* enumCS 16 */
{ if( prec <= 8 ) {
if( prec <= 8 )
{
in_type = TYPE_RGB_8; in_type = TYPE_RGB_8;
out_type = TYPE_RGB_8; out_type = TYPE_RGB_8;
} } else {
else
{
in_type = TYPE_RGB_16; in_type = TYPE_RGB_16;
out_type = TYPE_RGB_16; out_type = TYPE_RGB_16;
} }
out_prof = cmsCreate_sRGBProfile(); out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB; image->color_space = OPJ_CLRSPC_SRGB;
} } else if(out_space == cmsSigGrayData) { /* enumCS 17 */
else
if(out_space == cmsSigGrayData) /* enumCS 17 */
{
in_type = TYPE_GRAY_8; in_type = TYPE_GRAY_8;
out_type = TYPE_RGB_8; out_type = TYPE_RGB_8;
out_prof = cmsCreate_sRGBProfile(); out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB; image->color_space = OPJ_CLRSPC_SRGB;
} } else if(out_space == cmsSigYCbCrData) { /* enumCS 18 */
else
if(out_space == cmsSigYCbCrData) /* enumCS 18 */
{
in_type = TYPE_YCbCr_16; in_type = TYPE_YCbCr_16;
out_type = TYPE_RGB_16; out_type = TYPE_RGB_16;
out_prof = cmsCreate_sRGBProfile(); out_prof = cmsCreate_sRGBProfile();
image->color_space = OPJ_CLRSPC_SRGB; image->color_space = OPJ_CLRSPC_SRGB;
} } else {
else
{
#ifdef DEBUG_PROFILE #ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown " fprintf(stderr,"%s:%d: color_apply_icc_profile\n\tICC Profile has unknown "
"output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n", "output colorspace(%#x)(%c%c%c%c)\n\tICC Profile ignored.\n",
@ -429,8 +481,7 @@ fprintf(stderr,"\trender_intent (%u)\n\t"
cmsCloseProfile(out_prof); cmsCloseProfile(out_prof);
#endif #endif
if(transform == NULL) if(transform == NULL) {
{
#ifdef DEBUG_PROFILE #ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
"ICC Profile ignored.\n",__FILE__,__LINE__); "ICC Profile ignored.\n",__FILE__,__LINE__);
@ -443,10 +494,8 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
return; return;
} }
if(image->numcomps > 2)/* RGB, RGBA */ if(image->numcomps > 2) { /* RGB, RGBA */
{ if( prec <= 8 ) {
if( prec <= 8 )
{
unsigned char *inbuf, *outbuf, *in, *out; unsigned char *inbuf, *outbuf, *in, *out;
max = max_w * max_h; max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char); nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char);
@ -457,8 +506,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
g = image->comps[1].data; g = image->comps[1].data;
b = image->comps[2].data; b = image->comps[2].data;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
*in++ = (unsigned char)*r++; *in++ = (unsigned char)*r++;
*in++ = (unsigned char)*g++; *in++ = (unsigned char)*g++;
*in++ = (unsigned char)*b++; *in++ = (unsigned char)*b++;
@ -470,16 +518,14 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
g = image->comps[1].data; g = image->comps[1].data;
b = image->comps[2].data; b = image->comps[2].data;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
*r++ = (int)*out++; *r++ = (int)*out++;
*g++ = (int)*out++; *g++ = (int)*out++;
*b++ = (int)*out++; *b++ = (int)*out++;
} }
free(inbuf); free(outbuf); free(inbuf);
} free(outbuf);
else } else {
{
unsigned short *inbuf, *outbuf, *in, *out; unsigned short *inbuf, *outbuf, *in, *out;
max = max_w * max_h; max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short); nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short);
@ -490,8 +536,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
g = image->comps[1].data; g = image->comps[1].data;
b = image->comps[2].data; b = image->comps[2].data;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
*in++ = (unsigned short)*r++; *in++ = (unsigned short)*r++;
*in++ = (unsigned short)*g++; *in++ = (unsigned short)*g++;
*in++ = (unsigned short)*b++; *in++ = (unsigned short)*b++;
@ -503,17 +548,15 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
g = image->comps[1].data; g = image->comps[1].data;
b = image->comps[2].data; b = image->comps[2].data;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
*r++ = (int)*out++; *r++ = (int)*out++;
*g++ = (int)*out++; *g++ = (int)*out++;
*b++ = (int)*out++; *b++ = (int)*out++;
} }
free(inbuf); free(outbuf); free(inbuf);
free(outbuf);
} }
} } else { /* GRAY, GRAYA */
else /* GRAY, GRAYA */
{
unsigned char *in, *inbuf, *out, *outbuf; unsigned char *in, *inbuf, *out, *outbuf;
max = max_w * max_h; max = max_w * max_h;
nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char); nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char);
@ -536,8 +579,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
r = image->comps[0].data; r = image->comps[0].data;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
*in++ = (unsigned char)*r++; *in++ = (unsigned char)*r++;
} }
cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max);
@ -546,11 +588,13 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. "
g = image->comps[1].data; g = image->comps[1].data;
b = image->comps[2].data; b = image->comps[2].data;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{ *r++ = (int)*out++;
*r++ = (int)*out++; *g++ = (int)*out++; *b++ = (int)*out++; *g++ = (int)*out++;
*b++ = (int)*out++;
} }
free(inbuf); free(outbuf); free(inbuf);
free(outbuf);
}/* if(image->numcomps */ }/* if(image->numcomps */
@ -571,8 +615,7 @@ void color_cielab_to_rgb(opj_image_t *image)
numcomps = (int)image->numcomps; numcomps = (int)image->numcomps;
if(numcomps != 3) if(numcomps != 3) {
{
fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n", fprintf(stderr,"%s:%d:\n\tnumcomps %d not handled. Quitting.\n",
__FILE__,__LINE__,numcomps); __FILE__,__LINE__,numcomps);
return; return;
@ -581,8 +624,7 @@ void color_cielab_to_rgb(opj_image_t *image)
row = (int*)image->icc_profile_buf; row = (int*)image->icc_profile_buf;
enumcs = row[0]; enumcs = row[0];
if(enumcs == 14) /* CIELab */ if(enumcs == 14) { /* CIELab */
{
int *L, *a, *b, *red, *green, *blue; int *L, *a, *b, *red, *green, *blue;
int *src0, *src1, *src2, *dst0, *dst1, *dst2; int *src0, *src1, *src2, *dst0, *dst1, *dst2;
double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2; double rl, ol, ra, oa, rb, ob, prec0, prec1, prec2;
@ -603,8 +645,7 @@ void color_cielab_to_rgb(opj_image_t *image)
cmsCloseProfile(in); cmsCloseProfile(in);
cmsCloseProfile(out); cmsCloseProfile(out);
#endif #endif
if(transform == NULL) if(transform == NULL) {
{
#ifdef OPJ_HAVE_LIBLCMS1 #ifdef OPJ_HAVE_LIBLCMS1
cmsCloseProfile(in); cmsCloseProfile(in);
cmsCloseProfile(out); cmsCloseProfile(out);
@ -617,17 +658,20 @@ void color_cielab_to_rgb(opj_image_t *image)
default_type = (unsigned int)row[1]; default_type = (unsigned int)row[1];
if(default_type == 0x44454600)/* DEF : default */ if(default_type == 0x44454600) { /* DEF : default */
{ rl = 100;
rl = 100; ra = 170; rb = 200; ra = 170;
rb = 200;
ol = 0; ol = 0;
oa = pow(2, prec1 - 1); oa = pow(2, prec1 - 1);
ob = pow(2, prec2 - 2) + pow(2, prec2 - 3); ob = pow(2, prec2 - 2) + pow(2, prec2 - 3);
} } else {
else rl = row[2];
{ ra = row[4];
rl = row[2]; ra = row[4]; rb = row[6]; rb = row[6];
ol = row[3]; oa = row[5]; ob = row[7]; ol = row[3];
oa = row[5];
ob = row[7];
} }
L = src0 = image->comps[0].data; L = src0 = image->comps[0].data;
@ -649,11 +693,13 @@ void color_cielab_to_rgb(opj_image_t *image)
minb = -(rb * ob)/(pow(2, prec2)-1); minb = -(rb * ob)/(pow(2, prec2)-1);
maxb = minb + rb; maxb = minb + rb;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{ Lab.L = minL + (double)(*L) * (maxL - minL)/(pow(2, prec0)-1);
Lab.L = minL + (double)(*L) * (maxL - minL)/(pow(2, prec0)-1); ++L; ++L;
Lab.a = mina + (double)(*a) * (maxa - mina)/(pow(2, prec1)-1); ++a; Lab.a = mina + (double)(*a) * (maxa - mina)/(pow(2, prec1)-1);
Lab.b = minb + (double)(*b) * (maxb - minb)/(pow(2, prec2)-1); ++b; ++a;
Lab.b = minb + (double)(*b) * (maxb - minb)/(pow(2, prec2)-1);
++b;
cmsDoTransform(transform, &Lab, RGB, 1); cmsDoTransform(transform, &Lab, RGB, 1);
@ -666,9 +712,12 @@ void color_cielab_to_rgb(opj_image_t *image)
cmsCloseProfile(in); cmsCloseProfile(in);
cmsCloseProfile(out); cmsCloseProfile(out);
#endif #endif
free(src0); image->comps[0].data = dst0; free(src0);
free(src1); image->comps[1].data = dst1; image->comps[0].data = dst0;
free(src2); image->comps[2].data = dst2; free(src1);
image->comps[1].data = dst1;
free(src2);
image->comps[2].data = dst2;
image->color_space = OPJ_CLRSPC_SRGB; image->color_space = OPJ_CLRSPC_SRGB;
image->comps[0].prec = 16; image->comps[0].prec = 16;
@ -701,8 +750,7 @@ void color_cmyk_to_rgb(opj_image_t *image)
sY = 1.0F / (float)((1 << image->comps[2].prec) - 1); sY = 1.0F / (float)((1 << image->comps[2].prec) - 1);
sK = 1.0F / (float)((1 << image->comps[3].prec) - 1); sK = 1.0F / (float)((1 << image->comps[3].prec) - 1);
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
/* CMYK values from 0 to 1 */ /* CMYK values from 0 to 1 */
C = (float)(image->comps[0].data[i]) * sC; C = (float)(image->comps[0].data[i]) * sC;
M = (float)(image->comps[1].data[i]) * sM; M = (float)(image->comps[1].data[i]) * sM;
@ -721,7 +769,8 @@ void color_cmyk_to_rgb(opj_image_t *image)
image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */ image->comps[2].data[i] = (int)(255.0F * Y * K); /* B */
} }
free(image->comps[3].data); image->comps[3].data = NULL; free(image->comps[3].data);
image->comps[3].data = NULL;
image->comps[0].prec = 8; image->comps[0].prec = 8;
image->comps[1].prec = 8; image->comps[1].prec = 8;
image->comps[2].prec = 8; image->comps[2].prec = 8;
@ -754,10 +803,11 @@ void color_esycc_to_rgb(opj_image_t *image)
max = w * h; max = w * h;
for(i = 0; i < max; ++i) for(i = 0; i < max; ++i) {
{
y = image->comps[0].data[i]; cb = image->comps[1].data[i]; cr = image->comps[2].data[i]; y = image->comps[0].data[i];
cb = image->comps[1].data[i];
cr = image->comps[2].data[i];
if( !sign1) cb -= flip_value; if( !sign1) cb -= flip_value;
if( !sign2) cr -= flip_value; if( !sign2) cr -= flip_value;
@ -766,21 +816,24 @@ void color_esycc_to_rgb(opj_image_t *image)
((float)y - (float)0.0000368 * (float)cb ((float)y - (float)0.0000368 * (float)cb
+ (float)1.40199 * (float)cr + (float)0.5); + (float)1.40199 * (float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0; if(val > max_value) val = max_value;
else if(val < 0) val = 0;
image->comps[0].data[i] = val; image->comps[0].data[i] = val;
val = (int) val = (int)
((float)1.0003 * (float)y - (float)0.344125 * (float)cb ((float)1.0003 * (float)y - (float)0.344125 * (float)cb
- (float)0.7141128 * (float)cr + (float)0.5); - (float)0.7141128 * (float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0; if(val > max_value) val = max_value;
else if(val < 0) val = 0;
image->comps[1].data[i] = val; image->comps[1].data[i] = val;
val = (int) val = (int)
((float)0.999823 * (float)y + (float)1.77204 * (float)cb ((float)0.999823 * (float)y + (float)1.77204 * (float)cb
- (float)0.000008 *(float)cr + (float)0.5); - (float)0.000008 *(float)cr + (float)0.5);
if(val > max_value) val = max_value; else if(val < 0) val = 0; if(val > max_value) val = max_value;
else if(val < 0) val = 0;
image->comps[2].data[i] = val; image->comps[2].data[i] = val;
} }
image->color_space = OPJ_CLRSPC_SRGB; image->color_space = OPJ_CLRSPC_SRGB;

View File

@ -54,7 +54,8 @@ int opj_opterr = 1, /* if error message should be printed */
static char EMSG[]= {""}; static char EMSG[]= {""};
/* As this class remembers its values from one Java call to the other, reset the values before each use */ /* As this class remembers its values from one Java call to the other, reset the values before each use */
void opj_reset_options_reading(void) { void opj_reset_options_reading(void)
{
opj_opterr = 1; opj_opterr = 1;
opj_optind = 1; opj_optind = 1;
} }
@ -63,7 +64,8 @@ void opj_reset_options_reading(void) {
* getopt -- * getopt --
* Parse argc/argv argument vector. * Parse argc/argv argument vector.
*/ */
int opj_getopt(int nargc, char *const *nargv, const char *ostr) { int opj_getopt(int nargc, char *const *nargv, const char *ostr)
{
# define __progname nargv[0] # define __progname nargv[0]
static char *place = EMSG; /* option letter processing */ static char *place = EMSG; /* option letter processing */
const char *oli = NULL; /* option letter list index */ const char *oli = NULL; /* option letter list index */
@ -123,7 +125,8 @@ int opj_getopt(int nargc, char *const *nargv, const char *ostr) {
int opj_getopt_long(int argc, char * const argv[], const char *optstring, int opj_getopt_long(int argc, char * const argv[], const char *optstring,
const opj_option_t *longopts, int totlen) { const opj_option_t *longopts, int totlen)
{
static int lastidx,lastofs; static int lastidx,lastofs;
const char *tmp; const char *tmp;
int i,len; int i,len;
@ -136,12 +139,10 @@ again:
if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) { if (argv[opj_optind][0]=='-' && argv[opj_optind][1]==0) {
if(opj_optind >= (argc - 1)) { /* no more input parameters */ if(opj_optind >= (argc - 1)) { /* no more input parameters */
param = 0; param = 0;
} } else { /* more input parameters */
else{ /* more input parameters */
if(argv[opj_optind + 1][0] == '-') { if(argv[opj_optind + 1][0] == '-') {
param = 0; /* Missing parameter after '-' */ param = 0; /* Missing parameter after '-' */
} } else {
else{
param = 2; param = 2;
} }
} }
@ -161,8 +162,7 @@ again:
if (param > 1) { if (param > 1) {
arg = argv[opj_optind+1]; arg = argv[opj_optind+1];
opj_optind++; opj_optind++;
} } else
else
arg = argv[opj_optind]+1; arg = argv[opj_optind]+1;
if(strlen(arg)>1) { if(strlen(arg)>1) {
@ -205,7 +205,8 @@ again:
} else { /*Single character input parameter*/ } else { /*Single character input parameter*/
if (*optstring==':') return ':'; if (*optstring==':') return ':';
if (lastidx!=opj_optind) { if (lastidx!=opj_optind) {
lastidx=opj_optind; lastofs=0; lastidx=opj_optind;
lastofs=0;
} }
opj_optopt=argv[opj_optind][lastofs+1]; opj_optopt=argv[opj_optind][lastofs+1];
if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/ if ((tmp=strchr(optstring,opj_optopt))) {/*Found input parameter in list*/

View File

@ -3,8 +3,7 @@
#ifndef _GETOPT_H_ #ifndef _GETOPT_H_
#define _GETOPT_H_ #define _GETOPT_H_
typedef struct opj_option typedef struct opj_option {
{
const char *name; const char *name;
int has_arg; int has_arg;
int *flag; int *flag;

File diff suppressed because it is too large Load Diff

View File

@ -91,8 +91,7 @@ static void opj_applyLUT8u_8u32s_C1R(
for (y = height; y != 0U; --y) { for (y = height; y != 0U; --y) {
OPJ_UINT32 x; OPJ_UINT32 x;
for(x = 0; x < width; x++) for(x = 0; x < width; x++) {
{
pDst[x] = (OPJ_INT32)pLUT[pSrc[x]]; pDst[x] = (OPJ_INT32)pLUT[pSrc[x]];
} }
pSrc += srcStride; pSrc += srcStride;
@ -117,8 +116,7 @@ static void opj_applyLUT8u_8u32s_C1P3R(
for (y = height; y != 0U; --y) { for (y = height; y != 0U; --y) {
OPJ_UINT32 x; OPJ_UINT32 x;
for(x = 0; x < width; x++) for(x = 0; x < width; x++) {
{
OPJ_UINT8 idx = pSrc[x]; OPJ_UINT8 idx = pSrc[x];
pR[x] = (OPJ_INT32)pLUT_R[idx]; pR[x] = (OPJ_INT32)pLUT_R[idx];
pG[x] = (OPJ_INT32)pLUT_G[idx]; pG[x] = (OPJ_INT32)pLUT_G[idx];
@ -143,10 +141,8 @@ static void bmp24toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t*
index = 0; index = 0;
pSrc = pData + (height - 1U) * stride; pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++) for(y = 0; y < height; y++) {
{ for(x = 0; x < width; x++) {
for(x = 0; x < width; x++)
{
image->comps[0].data[index] = (OPJ_INT32)pSrc[3*x+2]; /* R */ image->comps[0].data[index] = (OPJ_INT32)pSrc[3*x+2]; /* R */
image->comps[1].data[index] = (OPJ_INT32)pSrc[3*x+1]; /* G */ image->comps[1].data[index] = (OPJ_INT32)pSrc[3*x+1]; /* G */
image->comps[2].data[index] = (OPJ_INT32)pSrc[3*x+0]; /* B */ image->comps[2].data[index] = (OPJ_INT32)pSrc[3*x+0]; /* B */
@ -172,7 +168,8 @@ static void bmp_mask_get_shift_and_prec(OPJ_UINT32 mask, OPJ_UINT32* shift, OPJ_
l_prec++; l_prec++;
} }
} }
*shift = l_shift; *prec = l_prec; *shift = l_shift;
*prec = l_prec;
} }
static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask) static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_image_t* image, OPJ_UINT32 redMask, OPJ_UINT32 greenMask, OPJ_UINT32 blueMask, OPJ_UINT32 alphaMask)
@ -210,10 +207,8 @@ static void bmpmask32toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag
index = 0; index = 0;
pSrc = pData + (height - 1U) * stride; pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++) for(y = 0; y < height; y++) {
{ for(x = 0; x < width; x++) {
for(x = 0; x < width; x++)
{
OPJ_UINT32 value = 0U; OPJ_UINT32 value = 0U;
value |= ((OPJ_UINT32)pSrc[4*x+0]) << 0; value |= ((OPJ_UINT32)pSrc[4*x+0]) << 0;
@ -268,10 +263,8 @@ static void bmpmask16toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_imag
index = 0; index = 0;
pSrc = pData + (height - 1U) * stride; pSrc = pData + (height - 1U) * stride;
for(y = 0; y < height; y++) for(y = 0; y < height; y++) {
{ for(x = 0; x < width; x++) {
for(x = 0; x < width; x++)
{
OPJ_UINT32 value = 0U; OPJ_UINT32 value = 0U;
value |= ((OPJ_UINT32)pSrc[2*x+0]) << 0; value |= ((OPJ_UINT32)pSrc[2*x+0]) << 0;
@ -300,13 +293,16 @@ static opj_image_t* bmp8toimage(const OPJ_UINT8* pData, OPJ_UINT32 stride, opj_i
pSrc = pData + (height - 1U) * stride; pSrc = pData + (height - 1U) * stride;
if (image->numcomps == 1U) { if (image->numcomps == 1U) {
opj_applyLUT8u_8u32s_C1R(pSrc, -(OPJ_INT32)stride, image->comps[0].data, (OPJ_INT32)width, pLUT[0], width, height); opj_applyLUT8u_8u32s_C1R(pSrc, -(OPJ_INT32)stride, image->comps[0].data, (OPJ_INT32)width, pLUT[0], width, height);
} } else {
else {
OPJ_INT32* pDst[3]; OPJ_INT32* pDst[3];
OPJ_INT32 pDstStride[3]; OPJ_INT32 pDstStride[3];
pDst[0] = image->comps[0].data; pDst[1] = image->comps[1].data; pDst[2] = image->comps[2].data; pDst[0] = image->comps[0].data;
pDstStride[0] = (OPJ_INT32)width; pDstStride[1] = (OPJ_INT32)width; pDstStride[2] = (OPJ_INT32)width; pDst[1] = image->comps[1].data;
pDst[2] = image->comps[2].data;
pDstStride[0] = (OPJ_INT32)width;
pDstStride[1] = (OPJ_INT32)width;
pDstStride[2] = (OPJ_INT32)width;
opj_applyLUT8u_8u32s_C1P3R(pSrc, -(OPJ_INT32)stride, pDst, pDstStride, pLUT, width, height); opj_applyLUT8u_8u32s_C1P3R(pSrc, -(OPJ_INT32)stride, pDst, pDstStride, pLUT, width, height);
} }
return image; return image;
@ -489,8 +485,7 @@ static OPJ_BOOL bmp_read_raw_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride,
{ {
OPJ_ARG_NOT_USED(width); OPJ_ARG_NOT_USED(width);
if ( fread(pData, sizeof(OPJ_UINT8), stride * height, IN) != (stride * height) ) if ( fread(pData, sizeof(OPJ_UINT8), stride * height, IN) != (stride * height) ) {
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -507,8 +502,7 @@ static OPJ_BOOL bmp_read_rle8_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
pix = pData; pix = pData;
x = y = 0U; x = y = 0U;
while (y < height) while (y < height) {
{
int c = getc(IN); int c = getc(IN);
if (c) { if (c) {
@ -518,29 +512,23 @@ static OPJ_BOOL bmp_read_rle8_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) { for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
*pix = c1; *pix = c1;
} }
} } else {
else {
c = getc(IN); c = getc(IN);
if (c == 0x00) { /* EOL */ if (c == 0x00) { /* EOL */
x = 0; x = 0;
++y; ++y;
pix = pData + y * stride + x; pix = pData + y * stride + x;
} } else if (c == 0x01) { /* EOP */
else if (c == 0x01) { /* EOP */
break; break;
} } else if (c == 0x02) { /* MOVE by dxdy */
else if (c == 0x02) { /* MOVE by dxdy */
c = getc(IN); c = getc(IN);
x += (OPJ_UINT32)c; x += (OPJ_UINT32)c;
c = getc(IN); c = getc(IN);
y += (OPJ_UINT32)c; y += (OPJ_UINT32)c;
pix = pData + y * stride + x; pix = pData + y * stride + x;
} } else { /* 03 .. 255 */
else /* 03 .. 255 */
{
int j; int j;
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
{
OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN); OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN);
*pix = c1; *pix = c1;
} }
@ -562,8 +550,7 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
beyond = pData + stride * height; beyond = pData + stride * height;
pix = pData; pix = pData;
x = y = 0U; x = y = 0U;
while(y < height) while(y < height) {
{
int c = getc(IN); int c = getc(IN);
if(c == EOF) break; if(c == EOF) break;
@ -574,23 +561,23 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) { for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
*pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU)); *pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU));
} }
} } else { /* absolute mode */
else { /* absolute mode */
c = getc(IN); c = getc(IN);
if(c == EOF) break; if(c == EOF) break;
if(c == 0x00) { /* EOL */ if(c == 0x00) { /* EOL */
x = 0; y++; pix = pData + y * stride; x = 0;
} y++;
else if(c == 0x01) { /* EOP */ pix = pData + y * stride;
} else if(c == 0x01) { /* EOP */
break; break;
} } else if(c == 0x02) { /* MOVE by dxdy */
else if(c == 0x02) { /* MOVE by dxdy */ c = getc(IN);
c = getc(IN); x += (OPJ_UINT32)c; x += (OPJ_UINT32)c;
c = getc(IN); y += (OPJ_UINT32)c; c = getc(IN);
y += (OPJ_UINT32)c;
pix = pData + y * stride + x; pix = pData + y * stride + x;
} } else { /* 03 .. 255 : absolute mode */
else { /* 03 .. 255 : absolute mode */
int j; int j;
OPJ_UINT8 c1 = 0U; OPJ_UINT8 c1 = 0U;
@ -623,11 +610,12 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
OPJ_UINT8* pData = NULL; OPJ_UINT8* pData = NULL;
OPJ_UINT32 stride; OPJ_UINT32 stride;
pLUT[0] = lut_R; pLUT[1] = lut_G; pLUT[2] = lut_B; pLUT[0] = lut_R;
pLUT[1] = lut_G;
pLUT[2] = lut_B;
IN = fopen(filename, "rb"); IN = fopen(filename, "rb");
if (!IN) if (!IN) {
{
fprintf(stderr, "Failed to open %s for reading !!\n", filename); fprintf(stderr, "Failed to open %s for reading !!\n", filename);
return NULL; return NULL;
} }
@ -642,8 +630,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
} }
/* Load palette */ /* Load palette */
if (Info_h.biBitCount <= 8U) if (Info_h.biBitCount <= 8U) {
{
memset(&lut_R[0], 0, sizeof(lut_R)); memset(&lut_R[0], 0, sizeof(lut_R));
memset(&lut_G[0], 0, sizeof(lut_G)); memset(&lut_G[0], 0, sizeof(lut_G));
memset(&lut_B[0], 0, sizeof(lut_B)); memset(&lut_B[0], 0, sizeof(lut_B));
@ -715,8 +702,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
/* create the image */ /* create the image */
memset(&cmptparm[0], 0, sizeof(cmptparm)); memset(&cmptparm[0], 0, sizeof(cmptparm));
for(i = 0; i < 4U; i++) for(i = 0; i < 4U; i++) {
{
cmptparm[i].prec = 8; cmptparm[i].prec = 8;
cmptparm[i].bpp = 8; cmptparm[i].bpp = 8;
cmptparm[i].sgnd = 0; cmptparm[i].sgnd = 0;
@ -745,34 +731,26 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
/* Read the data */ /* Read the data */
if (Info_h.biBitCount == 24 && Info_h.biCompression == 0) { /*RGB */ if (Info_h.biBitCount == 24 && Info_h.biCompression == 0) { /*RGB */
bmp24toimage(pData, stride, image); bmp24toimage(pData, stride, image);
} } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) { /* RGB 8bpp Indexed */
else if (Info_h.biBitCount == 8 && Info_h.biCompression == 0) { /* RGB 8bpp Indexed */
bmp8toimage(pData, stride, image, pLUT); bmp8toimage(pData, stride, image, pLUT);
} } else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) { /*RLE8*/
else if (Info_h.biBitCount == 8 && Info_h.biCompression == 1) { /*RLE8*/
bmp8toimage(pData, stride, image, pLUT); bmp8toimage(pData, stride, image, pLUT);
} } else if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /*RLE4*/
else if (Info_h.biBitCount == 4 && Info_h.biCompression == 2) { /*RLE4*/
bmp8toimage(pData, stride, image, pLUT); /* RLE 4 gets decoded as 8 bits data for now */ bmp8toimage(pData, stride, image, pLUT); /* RLE 4 gets decoded as 8 bits data for now */
} } else if (Info_h.biBitCount == 32 && Info_h.biCompression == 0) { /* RGBX */
else if (Info_h.biBitCount == 32 && Info_h.biCompression == 0) { /* RGBX */
bmpmask32toimage(pData, stride, image, 0x00FF0000U, 0x0000FF00U, 0x000000FFU, 0x00000000U); bmpmask32toimage(pData, stride, image, 0x00FF0000U, 0x0000FF00U, 0x000000FFU, 0x00000000U);
} } else if (Info_h.biBitCount == 32 && Info_h.biCompression == 3) { /* bitmask */
else if (Info_h.biBitCount == 32 && Info_h.biCompression == 3) { /* bitmask */
bmpmask32toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask); bmpmask32toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask);
} } else if (Info_h.biBitCount == 16 && Info_h.biCompression == 0) { /* RGBX */
else if (Info_h.biBitCount == 16 && Info_h.biCompression == 0) { /* RGBX */
bmpmask16toimage(pData, stride, image, 0x7C00U, 0x03E0U, 0x001FU, 0x0000U); bmpmask16toimage(pData, stride, image, 0x7C00U, 0x03E0U, 0x001FU, 0x0000U);
} } else if (Info_h.biBitCount == 16 && Info_h.biCompression == 3) { /* bitmask */
else if (Info_h.biBitCount == 16 && Info_h.biCompression == 3) { /* bitmask */
if ((Info_h.biRedMask == 0U) && (Info_h.biGreenMask == 0U) && (Info_h.biBlueMask == 0U)) { if ((Info_h.biRedMask == 0U) && (Info_h.biGreenMask == 0U) && (Info_h.biBlueMask == 0U)) {
Info_h.biRedMask = 0xF800U; Info_h.biRedMask = 0xF800U;
Info_h.biGreenMask = 0x07E0U; Info_h.biGreenMask = 0x07E0U;
Info_h.biBlueMask = 0x001FU; Info_h.biBlueMask = 0x001FU;
} }
bmpmask16toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask); bmpmask16toimage(pData, stride, image, Info_h.biRedMask, Info_h.biGreenMask, Info_h.biBlueMask, Info_h.biAlphaMask);
} } else {
else {
opj_image_destroy(image); opj_image_destroy(image);
image = NULL; image = NULL;
fprintf(stderr, "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n", Info_h.biBitCount); fprintf(stderr, "Other system than 24 bits/pixels or 8 bits (no RLE coding) is not yet implemented [%d]\n", Info_h.biBitCount);
@ -782,7 +760,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
return image; return image;
} }
int imagetobmp(opj_image_t * image, const char *outfile) { int imagetobmp(opj_image_t * image, const char *outfile)
{
int w, h; int w, h;
int i, pad; int i, pad;
FILE *fdest = NULL; FILE *fdest = NULL;
@ -850,20 +829,17 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
if (image->comps[0].prec > 8) { if (image->comps[0].prec > 8) {
adjustR = (int)image->comps[0].prec - 8; adjustR = (int)image->comps[0].prec - 8;
printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
} } else
else
adjustR = 0; adjustR = 0;
if (image->comps[1].prec > 8) { if (image->comps[1].prec > 8) {
adjustG = (int)image->comps[1].prec - 8; adjustG = (int)image->comps[1].prec - 8;
printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec); printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec);
} } else
else
adjustG = 0; adjustG = 0;
if (image->comps[2].prec > 8) { if (image->comps[2].prec > 8) {
adjustB = (int)image->comps[2].prec - 8; adjustB = (int)image->comps[2].prec - 8;
printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec); printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec);
} } else
else
adjustB = 0; adjustB = 0;
for (i = 0; i < w * h; i++) { for (i = 0; i < w * h; i++) {
@ -873,19 +849,22 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r = ((r >> adjustR)+((r >> (adjustR-1))%2)); r = ((r >> adjustR)+((r >> (adjustR-1))%2));
if(r > 255) r = 255; else if(r < 0) r = 0; if(r > 255) r = 255;
else if(r < 0) r = 0;
rc = (OPJ_UINT8)r; rc = (OPJ_UINT8)r;
g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0);
g = ((g >> adjustG)+((g >> (adjustG-1))%2)); g = ((g >> adjustG)+((g >> (adjustG-1))%2));
if(g > 255) g = 255; else if(g < 0) g = 0; if(g > 255) g = 255;
else if(g < 0) g = 0;
gc = (OPJ_UINT8)g; gc = (OPJ_UINT8)g;
b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0);
b = ((b >> adjustB)+((b >> (adjustB-1))%2)); b = ((b >> adjustB)+((b >> (adjustB-1))%2));
if(b > 255) b = 255; else if(b < 0) b = 0; if(b > 255) b = 255;
else if(b < 0) b = 0;
bc = (OPJ_UINT8)b; bc = (OPJ_UINT8)b;
fprintf(fdest, "%c%c%c", bc, gc, rc); fprintf(fdest, "%c%c%c", bc, gc, rc);
@ -962,7 +941,8 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)];
r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
r = ((r >> adjustR)+((r >> (adjustR-1))%2)); r = ((r >> adjustR)+((r >> (adjustR-1))%2));
if(r > 255) r = 255; else if(r < 0) r = 0; if(r > 255) r = 255;
else if(r < 0) r = 0;
fprintf(fdest, "%c", (OPJ_UINT8)r); fprintf(fdest, "%c", (OPJ_UINT8)r);

View File

@ -85,15 +85,13 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
convert_32s_CXPX cvtCxToPx = NULL; convert_32s_CXPX cvtCxToPx = NULL;
OPJ_INT32* planes[4]; OPJ_INT32* planes[4];
if((reader = fopen(read_idf, "rb")) == NULL) if((reader = fopen(read_idf, "rb")) == NULL) {
{
fprintf(stderr,"pngtoimage: can not open %s\n",read_idf); fprintf(stderr,"pngtoimage: can not open %s\n",read_idf);
return NULL; return NULL;
} }
if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE
|| memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) {
{
fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf); fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf);
goto fin; goto fin;
} }
@ -192,8 +190,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
/* Create image */ /* Create image */
memset(cmptparm, 0, sizeof(cmptparm)); memset(cmptparm, 0, sizeof(cmptparm));
for(i = 0; i < nr_comp; ++i) for(i = 0; i < nr_comp; ++i) {
{
cmptparm[i].prec = (OPJ_UINT32)bit_depth; cmptparm[i].prec = (OPJ_UINT32)bit_depth;
/* bits_per_pixel: 8 or 16 */ /* bits_per_pixel: 8 or 16 */
cmptparm[i].bpp = (OPJ_UINT32)bit_depth; cmptparm[i].bpp = (OPJ_UINT32)bit_depth;
@ -217,13 +214,11 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
/* Set alpha channel */ /* Set alpha channel */
image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U); image->comps[nr_comp-1U].alpha = 1U - (nr_comp & 1U);
for(i = 0; i < nr_comp; i++) for(i = 0; i < nr_comp; i++) {
{
planes[i] = image->comps[i].data; planes[i] = image->comps[i].data;
} }
for(i = 0; i < height; ++i) for(i = 0; i < height; ++i) {
{
cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp); cvtXXTo32s(rows[i], row32s, (OPJ_SIZE_T)width * nr_comp);
cvtCxToPx(row32s, planes, width); cvtCxToPx(row32s, planes, width);
planes[0] += width; planes[0] += width;
@ -232,8 +227,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params)
planes[3] += width; planes[3] += width;
} }
fin: fin:
if(rows) if(rows) {
{
for(i = 0; i < height; ++i) for(i = 0; i < height; ++i)
free(rows[i]); free(rows[i]);
free(rows); free(rows);
@ -306,15 +300,12 @@ int imagetopng(opj_image_t * image, const char *write_idf)
for (i = 0; i < nr_comp; ++i) { for (i = 0; i < nr_comp; ++i) {
clip_component(&(image->comps[i]), image->comps[0].prec); clip_component(&(image->comps[i]), image->comps[0].prec);
} }
if(prec > 8 && prec < 16) if(prec > 8 && prec < 16) {
{
for (i = 0; i < nr_comp; ++i) { for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 16); scale_component(&(image->comps[i]), 16);
} }
prec = 16; prec = 16;
} } else if(prec < 8 && nr_comp > 1) { /* GRAY_ALPHA, RGB, RGB_ALPHA */
else if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */
{
for (i = 0; i < nr_comp; ++i) { for (i = 0; i < nr_comp; ++i) {
scale_component(&(image->comps[i]), 8); scale_component(&(image->comps[i]), 8);
} }
@ -330,8 +321,7 @@ int imagetopng(opj_image_t * image, const char *write_idf)
} }
} }
if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) {
{
fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec); fprintf(stderr,"imagetopng: can not create %s\n\twrong bit_depth %d\n", write_idf, prec);
return fails; return fails;
} }
@ -386,18 +376,14 @@ int imagetopng(opj_image_t * image, const char *write_idf)
*/ */
png_set_compression_level(png, Z_BEST_COMPRESSION); png_set_compression_level(png, Z_BEST_COMPRESSION);
if(nr_comp >= 3) /* RGB(A) */ if(nr_comp >= 3) { /* RGB(A) */
{
color_type = PNG_COLOR_TYPE_RGB; color_type = PNG_COLOR_TYPE_RGB;
sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec; sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec;
} } else { /* GRAY(A) */
else /* GRAY(A) */
{
color_type = PNG_COLOR_TYPE_GRAY; color_type = PNG_COLOR_TYPE_GRAY;
sig_bit.gray = (png_byte)prec; sig_bit.gray = (png_byte)prec;
} }
if((nr_comp & 1) == 0) /* ALPHA */ if((nr_comp & 1) == 0) { /* ALPHA */
{
color_type |= PNG_COLOR_MASK_ALPHA; color_type |= PNG_COLOR_MASK_ALPHA;
sig_bit.alpha = (png_byte)prec; sig_bit.alpha = (png_byte)prec;
} }
@ -458,8 +444,7 @@ int imagetopng(opj_image_t * image, const char *write_idf)
break; break;
} }
for(y = 0; y < image->comps[0].h; ++y) for(y = 0; y < image->comps[0].h; ++y) {
{
cvtPxToCx(planes, buffer32s_cpy, width, adjust); cvtPxToCx(planes, buffer32s_cpy, width, adjust);
cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp); cvt32sToPack(buffer32s_cpy, row_buf_cpy, width * (OPJ_SIZE_T)nr_comp);
png_write_row(png, row_buf_cpy); png_write_row(png, row_buf_cpy);

View File

@ -193,8 +193,7 @@ int imagetotif(opj_image_t * image, const char *outfile)
if (numcomps > 4U) { if (numcomps > 4U) {
numcomps = 4U; /* Alpha not supported */ numcomps = 4U; /* Alpha not supported */
} }
} } else if (numcomps > 2U) {
else if (numcomps > 2U) {
tiPhoto = PHOTOMETRIC_RGB; tiPhoto = PHOTOMETRIC_RGB;
if (numcomps > 4U) { if (numcomps > 4U) {
numcomps = 4U; numcomps = 4U;
@ -224,15 +223,13 @@ int imagetotif(opj_image_t * image, const char *outfile)
} }
if((bps > 16) || ((bps != 1) && (bps & 1))) bps = 0; if((bps > 16) || ((bps != 1) && (bps & 1))) bps = 0;
if(bps == 0) if(bps == 0) {
{
fprintf(stderr,"imagetotif: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",bps); fprintf(stderr,"imagetotif: Bits=%d, Only 1, 2, 4, 6, 8, 10, 12, 14 and 16 bits implemented\n",bps);
fprintf(stderr,"\tAborting\n"); fprintf(stderr,"\tAborting\n");
return 1; return 1;
} }
tif = TIFFOpen(outfile, "wb"); tif = TIFFOpen(outfile, "wb");
if (!tif) if (!tif) {
{
fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile);
return 1; return 1;
} }
@ -436,8 +433,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
tif = TIFFOpen(filename, "r"); tif = TIFFOpen(filename, "r");
if(!tif) if(!tif) {
{
fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename); fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename);
return 0; return 0;
} }
@ -500,10 +496,8 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES,
&extrasamples, &sampleinfo); &extrasamples, &sampleinfo);
if(extrasamples >= 1) if(extrasamples >= 1) {
{ switch(sampleinfo[0]) {
switch(sampleinfo[0])
{
case EXTRASAMPLE_UNSPECIFIED: case EXTRASAMPLE_UNSPECIFIED:
/* Workaround for some images without correct info about alpha channel /* Workaround for some images without correct info about alpha channel
*/ */
@ -516,8 +510,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
has_alpha = 1; has_alpha = 1;
break; break;
} }
} } else /* extrasamples == 0 */
else /* extrasamples == 0 */
if(tiSpp == 4 || tiSpp == 2) has_alpha = 1; if(tiSpp == 4 || tiSpp == 2) has_alpha = 1;
} }
@ -534,13 +527,10 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
is_cinema = 0U; is_cinema = 0U;
} }
if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */ if(tiPhoto == PHOTOMETRIC_RGB) { /* RGB(A) */
{
numcomps = 3 + has_alpha; numcomps = 3 + has_alpha;
color_space = OPJ_CLRSPC_SRGB; color_space = OPJ_CLRSPC_SRGB;
} } else if (tiPhoto == PHOTOMETRIC_MINISBLACK) { /* GRAY(A) */
else if (tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */
{
numcomps = 1 + has_alpha; numcomps = 1 + has_alpha;
color_space = OPJ_CLRSPC_GRAY; color_space = OPJ_CLRSPC_GRAY;
} }
@ -551,8 +541,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
tiSpp = 1U; /* consider only one sample per plane */ tiSpp = 1U; /* consider only one sample per plane */
} }
for(j = 0; j < numcomps; j++) for(j = 0; j < numcomps; j++) {
{
cmptparm[j].prec = tiBps; cmptparm[j].prec = tiBps;
cmptparm[j].bpp = tiBps; cmptparm[j].bpp = tiBps;
cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; cmptparm[j].dx = (OPJ_UINT32)subsampling_dx;
@ -562,8 +551,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
} }
image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space);
if(!image) if(!image) {
{
TIFFClose(tif); TIFFClose(tif);
return NULL; return NULL;
} }
@ -575,8 +563,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 :
image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1;
for(j = 0; j < numcomps; j++) for(j = 0; j < numcomps; j++) {
{
planes[j] = image->comps[j].data; planes[j] = image->comps[j].data;
} }
image->comps[numcomps - 1].alpha = (OPJ_UINT16)(1 - (numcomps & 1)); image->comps[numcomps - 1].alpha = (OPJ_UINT16)(1 - (numcomps & 1));
@ -600,13 +587,11 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters)
strip = 0; strip = 0;
currentPlane = 0; currentPlane = 0;
do do {
{
planes[0] = image->comps[currentPlane].data; /* to manage planar data */ planes[0] = image->comps[currentPlane].data; /* to manage planar data */
h= (int)tiHeight; h= (int)tiHeight;
/* Read the Image components */ /* Read the Image components */
for(; (h > 0) && (strip < TIFFNumberOfStrips(tif)); strip++) for(; (h > 0) && (strip < TIFFNumberOfStrips(tif)); strip++) {
{
const OPJ_UINT8 *dat8; const OPJ_UINT8 *dat8;
OPJ_SIZE_T ssize; OPJ_SIZE_T ssize;

View File

@ -46,7 +46,8 @@ Write a structured index to a file
@param index Index filename @param index Index filename
@return Returns 0 if successful, returns 1 otherwise @return Returns 0 if successful, returns 1 otherwise
*/ */
int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb, x, y; int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL; FILE *stream = NULL;
double total_disto = 0; double total_disto = 0;

View File

@ -89,7 +89,8 @@ typedef struct img_folder{
char set_out_format; char set_out_format;
} img_fol_t; } img_fol_t;
static void encode_help_display(void) { static void encode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n" fprintf(stdout,"\nThis is the opj_compress utility from the OpenJPEG project.\n"
"It compresses various image formats with the JPEG 2000 algorithm.\n" "It compresses various image formats with the JPEG 2000 algorithm.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version()); "It has been compiled against openjp2 library v%s.\n\n",opj_version());
@ -353,7 +354,8 @@ static void encode_help_display(void) {
#endif /*FIXME_INDEX*/ #endif /*FIXME_INDEX*/
} }
static OPJ_PROG_ORDER give_progression(const char progression[4]) { static OPJ_PROG_ORDER give_progression(const char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) { if(strncmp(progression, "LRCP", 4) == 0) {
return OPJ_LRCP; return OPJ_LRCP;
} }
@ -373,7 +375,8 @@ static OPJ_PROG_ORDER give_progression(const char progression[4]) {
return OPJ_PROG_UNKNOWN; return OPJ_PROG_UNKNOWN;
} }
static unsigned int get_num_images(char *imgdirpath){ static unsigned int get_num_images(char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
unsigned int num_images = 0; unsigned int num_images = 0;
@ -396,7 +399,8 @@ static unsigned int get_num_images(char *imgdirpath){
return num_images; return num_images;
} }
static int load_images(dircnt_t *dirptr, char *imgdirpath){ static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int i = 0; int i = 0;
@ -422,7 +426,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0; return 0;
} }
static int get_file_format(char *filename) { static int get_file_format(char *filename)
{
unsigned int i; unsigned int i;
static const char *extension[] = { static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc" "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@ -442,12 +447,14 @@ static int get_file_format(char *filename) {
return -1; return -1;
} }
static char * get_file_name(char *name){ static char * get_file_name(char *name)
{
char *fname = strtok(name,"."); char *fname = strtok(name,".");
return fname; return fname;
} }
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]=""; char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -479,7 +486,8 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/* ------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size) { img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size)
{
OPJ_UINT32 i, j; OPJ_UINT32 i, j;
int totlen, c; int totlen, c;
opj_option_t long_option[]= { opj_option_t long_option[]= {
@ -512,8 +520,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile); parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -541,8 +548,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -560,8 +566,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* output format */ case 'O': { /* output format */
{
char outformat[50]; char outformat[50];
char *of = opj_optarg; char *of = opj_optarg;
sprintf(outformat,".%s",of); sprintf(outformat,".%s",of);
@ -583,8 +588,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */ case 'r': { /* rates rates/distorsion */
{
char *s = opj_optarg; char *s = opj_optarg;
parameters->tcp_numlayers = 0; parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@ -603,8 +607,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'F': /* Raw image format parameters */ case 'F': { /* Raw image format parameters */
{
OPJ_BOOL wrong = OPJ_FALSE; OPJ_BOOL wrong = OPJ_FALSE;
char *substr1; char *substr1;
char *substr2; char *substr2;
@ -691,8 +694,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'q': /* add fixed_quality */ case 'q': { /* add fixed_quality */
{
char *s = opj_optarg; char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++; parameters->tcp_numlayers++;
@ -710,8 +712,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* dda */ /* dda */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */ case 'f': { /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL; int *row = NULL, *col = NULL;
OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0; OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0;
@ -757,8 +758,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* tiles */ case 't': { /* tiles */
{
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy); sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE; parameters->tile_size_on = OPJ_TRUE;
} }
@ -766,15 +766,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'n': /* resolution */ case 'n': { /* resolution */
{
sscanf(opj_optarg, "%d", &parameters->numresolution); sscanf(opj_optarg, "%d", &parameters->numresolution);
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'c': /* precinct dimension */ case 'c': { /* precinct dimension */
{
char sep; char sep;
int res_spec = 0; int res_spec = 0;
@ -784,8 +782,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
sep = 0; sep = 0;
ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec], ret = sscanf(s, "[%d,%d]%c", &parameters->prcw_init[res_spec],
&parameters->prch_init[res_spec], &sep); &parameters->prch_init[res_spec], &sep);
if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) {
{
fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep); fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep);
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n"); fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n");
return 1; return 1;
@ -793,16 +790,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->csty |= 0x01; parameters->csty |= 0x01;
res_spec++; res_spec++;
s = strpbrk(s, "]") + 2; s = strpbrk(s, "]") + 2;
} } while (sep == ',');
while (sep == ',');
parameters->res_spec = res_spec; parameters->res_spec = res_spec;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'b': /* code-block dimension */ case 'b': { /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0; int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@ -819,8 +814,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'x': /* creation of index file */ case 'x': { /* creation of index file */
{
if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) { if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) {
return 1; return 1;
} }
@ -834,8 +828,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* progression order */ case 'p': { /* progression order */
{
char progression[4]; char progression[4];
strncpy(progression, opj_optarg, 4); strncpy(progression, opj_optarg, 4);
@ -850,8 +843,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 's': /* subsampling factor */ case 's': { /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx, if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) { &parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@ -862,8 +854,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */ case 'd': { /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0, if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) { &parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument " fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@ -881,8 +872,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'P': /* POC */ case 'P': { /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */ int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@ -909,24 +899,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'S': /* SOP marker */ case 'S': { /* SOP marker */
{
parameters->csty |= 0x02; parameters->csty |= 0x02;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'E': /* EPH marker */ case 'E': { /* EPH marker */
{
parameters->csty |= 0x04; parameters->csty |= 0x04;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */ case 'M': { /* Mode switch pas tous au point !! */
{
int value = 0; int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) { if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) { for (i = 0; i <= 5; i++) {
@ -940,8 +927,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'R': /* ROI */ case 'R': { /* ROI */
{
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno, if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) { &parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n"); fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
@ -952,8 +938,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'T': /* Tile offset */ case 'T': { /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) { if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1; return 1;
@ -963,8 +948,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'C': /* add a comment */ case 'C': { /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) { if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg); strcpy(parameters->cp_comment, opj_optarg);
@ -975,16 +959,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'I': /* reversible or not */ case 'I': { /* reversible or not */
{
parameters->irreversible = 1; parameters->irreversible = 1;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'u': /* Tile part generation*/ case 'u': { /* Tile part generation*/
{
parameters->tp_flag = opj_optarg[0]; parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1; parameters->tp_on = 1;
} }
@ -992,8 +974,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'z': /* Image Directory path */ case 'z': { /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg); strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1; img_fol->set_imgdir=1;
@ -1002,8 +983,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'w': /* Digital Cinema 2K profile compliance*/ case 'w': { /* Digital Cinema 2K profile compliance*/
{
int fps=0; int fps=0;
sscanf(opj_optarg,"%d",&fps); sscanf(opj_optarg,"%d",&fps);
if(fps == 24) { if(fps == 24) {
@ -1026,8 +1006,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'y': /* Digital Cinema 4K profile compliance*/ case 'y': { /* Digital Cinema 4K profile compliance*/
{
parameters->rsiz = OPJ_PROFILE_CINEMA_4K; parameters->rsiz = OPJ_PROFILE_CINEMA_4K;
fprintf(stdout,"CINEMA 4K profile activated\n" fprintf(stdout,"CINEMA 4K profile activated\n"
"Other options specified could be overriden\n"); "Other options specified could be overriden\n");
@ -1036,8 +1015,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'Y': /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/ case 'Y': { /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/
{
int mct_mode=0; int mct_mode=0;
sscanf(opj_optarg,"%d",&mct_mode); sscanf(opj_optarg,"%d",&mct_mode);
if(mct_mode < 0 || mct_mode > 2) { if(mct_mode < 0 || mct_mode > 2) {
@ -1051,8 +1029,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'm': /* mct input file */ case 'm': { /* mct input file */
{
char *lFilename = opj_optarg; char *lFilename = opj_optarg;
char *lMatrix; char *lMatrix;
char *lCurrentPtr ; char *lCurrentPtr ;
@ -1136,8 +1113,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL #ifdef USE_JPWL
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'W': /* JPWL capabilities switched on */ case 'W': { /* JPWL capabilities switched on */
{
char *token = NULL; char *token = NULL;
int hprot, pprot, sens, addr, size, range; int hprot, pprot, sens, addr, size, range;
@ -1455,8 +1431,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* <<UniPG */ /* <<UniPG */
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'J': /* jpip on */ case 'J': { /* jpip on */
{
parameters->jpip_on = OPJ_TRUE; parameters->jpip_on = OPJ_TRUE;
} }
break; break;
@ -1547,26 +1522,30 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/** /**
sample error debug callback expecting no client object sample error debug callback expecting no client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[ERROR] %s", msg); fprintf(stdout, "[ERROR] %s", msg);
} }
/** /**
sample warning debug callback expecting no client object sample warning debug callback expecting no client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[WARNING] %s", msg); fprintf(stdout, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
OPJ_FLOAT64 opj_clock(void) { OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32 #ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */ /* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
@ -1596,7 +1575,8 @@ OPJ_FLOAT64 opj_clock(void) {
* OPJ_COMPRESS MAIN * OPJ_COMPRESS MAIN
*/ */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
opj_cparameters_t parameters; /* compression parameters */ opj_cparameters_t parameters; /* compression parameters */
@ -1796,14 +1776,12 @@ int main(int argc, char **argv) {
/* ---------------------------- */ /* ---------------------------- */
switch(parameters.cod_format) { switch(parameters.cod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */ case J2K_CFMT: { /* JPEG-2000 codestream */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_J2K); l_codec = opj_create_compress(OPJ_CODEC_J2K);
break; break;
} }
case JP2_CFMT: /* JPEG 2000 compressed image data */ case JP2_CFMT: { /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_compress(OPJ_CODEC_JP2); l_codec = opj_create_compress(OPJ_CODEC_JP2);
break; break;
@ -1859,8 +1837,7 @@ int main(int argc, char **argv) {
} }
} }
free(l_data); free(l_data);
} } else {
else {
bSuccess = bSuccess && opj_encode(l_codec, l_stream); bSuccess = bSuccess && opj_encode(l_codec, l_stream);
if (!bSuccess) { if (!bSuccess) {
fprintf(stderr, "failed to encode image: opj_encode\n"); fprintf(stderr, "failed to encode image: opj_encode\n");

View File

@ -97,20 +97,17 @@ typedef struct img_folder{
} img_fol_t; } img_fol_t;
typedef enum opj_prec_mode typedef enum opj_prec_mode {
{
OPJ_PREC_MODE_CLIP, OPJ_PREC_MODE_CLIP,
OPJ_PREC_MODE_SCALE OPJ_PREC_MODE_SCALE
} opj_precision_mode; } opj_precision_mode;
typedef struct opj_prec typedef struct opj_prec {
{
OPJ_UINT32 prec; OPJ_UINT32 prec;
opj_precision_mode mode; opj_precision_mode mode;
} opj_precision; } opj_precision;
typedef struct opj_decompress_params typedef struct opj_decompress_params {
{
/** core library parameters */ /** core library parameters */
opj_dparameters_t core; opj_dparameters_t core;
@ -166,7 +163,8 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
static opj_image_t* convert_gray_to_rgb(opj_image_t* original); static opj_image_t* convert_gray_to_rgb(opj_image_t* original);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static void decode_help_display(void) { static void decode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_decompress utility from the OpenJPEG project.\n" fprintf(stdout,"\nThis is the opj_decompress utility from the OpenJPEG project.\n"
"It decompresses JPEG 2000 codestreams to various image formats.\n" "It decompresses JPEG 2000 codestreams to various image formats.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version()); "It has been compiled against openjp2 library v%s.\n\n",opj_version());
@ -253,8 +251,7 @@ static OPJ_BOOL parse_precision(const char* option, opj_decompress_parameters* p
} }
parameters->nb_precision = 0U; parameters->nb_precision = 0U;
for(;;) for(;;) {
{
int prec; int prec;
char mode; char mode;
char comma; char comma;
@ -346,7 +343,8 @@ static OPJ_BOOL parse_precision(const char* option, opj_decompress_parameters* p
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath){ int get_num_images(char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int num_images = 0; int num_images = 0;
@ -369,7 +367,8 @@ int get_num_images(char *imgdirpath){
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int load_images(dircnt_t *dirptr, char *imgdirpath){ int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int i = 0; int i = 0;
@ -396,7 +395,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int get_file_format(const char *filename) { int get_file_format(const char *filename)
{
unsigned int i; unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@ -422,7 +422,8 @@ const char* path_separator = "/";
#endif #endif
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompress_parameters *parameters){ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompress_parameters *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]=""; char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -486,12 +487,10 @@ static int infile_format(const char *fname)
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT; magic_format = JP2_CFMT;
magic_s = ".jp2"; magic_s = ".jp2";
} } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
magic_format = J2K_CFMT; magic_format = J2K_CFMT;
magic_s = ".j2k or .jpc or .j2c"; magic_s = ".j2k or .jpc or .j2c";
} } else
else
return -1; return -1;
if (magic_format == ext_format) if (magic_format == ext_format)
@ -512,7 +511,8 @@ static int infile_format(const char *fname)
* Parse the command line * Parse the command line
*/ */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol) { int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol)
{
/* parse the command line */ /* parse the command line */
int totlen, c; int totlen, c;
opj_option_t long_option[]= { opj_option_t long_option[]= {
@ -545,8 +545,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
switch (c) { switch (c) {
case 0: /* long opt with flag */ case 0: /* long opt with flag */
break; break;
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = infile_format(infile); parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -577,8 +576,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -611,8 +609,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* output format */ case 'O': { /* output format */
{
char outformat[50]; char outformat[50];
char *of = opj_optarg; char *of = opj_optarg;
sprintf(outformat,".%s",of); sprintf(outformat,".%s",of);
@ -654,8 +651,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* reduce option */ case 'r': { /* reduce option */
{
sscanf(opj_optarg, "%u", &(parameters->core.cp_reduce)); sscanf(opj_optarg, "%u", &(parameters->core.cp_reduce));
} }
break; break;
@ -663,8 +659,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'l': /* layering option */ case 'l': { /* layering option */
{
sscanf(opj_optarg, "%u", &(parameters->core.cp_layer)); sscanf(opj_optarg, "%u", &(parameters->core.cp_layer));
} }
break; break;
@ -677,8 +672,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'y': /* Image Directory path */ case 'y': { /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg); strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1; img_fol->set_imgdir=1;
@ -687,8 +681,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* Input decode ROI */ case 'd': { /* Input decode ROI */
{
size_t size_optarg = (size_t)strlen(opj_optarg) + 1U; size_t size_optarg = (size_t)strlen(opj_optarg) + 1U;
char *ROI_values = (char*) malloc(size_optarg); char *ROI_values = (char*) malloc(size_optarg);
if (ROI_values == NULL) { if (ROI_values == NULL) {
@ -706,8 +699,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* Input tile index */ case 't': { /* Input tile index */
{
sscanf(opj_optarg, "%u", &parameters->tile_index); sscanf(opj_optarg, "%u", &parameters->tile_index);
parameters->nb_tile_to_decode = 1; parameters->nb_tile_to_decode = 1;
} }
@ -715,8 +707,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'x': /* Creation of index file */ case 'x': { /* Creation of index file */
{
if (opj_strcpy_s(parameters->indexfilename, sizeof(parameters->indexfilename), opj_optarg) != 0) { if (opj_strcpy_s(parameters->indexfilename, sizeof(parameters->indexfilename), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n"); fprintf(stderr, "[ERROR] Path is too long\n");
return 1; return 1;
@ -725,10 +716,8 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* Force precision */ case 'p': { /* Force precision */
{ if (!parse_precision(opj_optarg, parameters)) {
if (!parse_precision(opj_optarg, parameters))
{
return 1; return 1;
} }
} }
@ -738,8 +727,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
case 'W': /* activate JPWL correction */ case 'W': { /* activate JPWL correction */
{
char *token = NULL; char *token = NULL;
token = strtok(opj_optarg, ","); token = strtok(opj_optarg, ",");
@ -864,15 +852,17 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi
if (it != 4) { if (it != 4) {
return EXIT_FAILURE; return EXIT_FAILURE;
} } else {
else{ *DA_x0 = (OPJ_UINT32)values[0];
*DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1]; *DA_y0 = (OPJ_UINT32)values[1];
*DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3]; *DA_x1 = (OPJ_UINT32)values[2];
*DA_y1 = (OPJ_UINT32)values[3];
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
} }
OPJ_FLOAT64 opj_clock(void) { OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32 #ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */ /* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
@ -901,21 +891,24 @@ OPJ_FLOAT64 opj_clock(void) {
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[ERROR] %s", msg); fprintf(stdout, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[WARNING] %s", msg); fprintf(stdout, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
@ -1163,8 +1156,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
l_dst += l_new_cmp->w; l_dst += l_new_cmp->w;
} }
} }
} } else {
else {
memcpy(l_new_cmp->data, l_org_cmp->data, l_org_cmp->w * l_org_cmp->h * sizeof(OPJ_INT32)); memcpy(l_new_cmp->data, l_org_cmp->data, l_org_cmp->w * l_org_cmp->h * sizeof(OPJ_INT32));
} }
} }
@ -1262,20 +1254,17 @@ int main(int argc, char **argv)
/* ---------------------- */ /* ---------------------- */
switch(parameters.decod_format) { switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */ case J2K_CFMT: { /* JPEG-2000 codestream */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K); l_codec = opj_create_decompress(OPJ_CODEC_J2K);
break; break;
} }
case JP2_CFMT: /* JPEG 2000 compressed image data */ case JP2_CFMT: { /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JP2); l_codec = opj_create_decompress(OPJ_CODEC_JP2);
break; break;
} }
case JPT_CFMT: /* JPEG 2000, JPIP */ case JPT_CFMT: { /* JPEG 2000, JPIP */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT); l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break; break;
@ -1335,8 +1324,7 @@ int main(int argc, char **argv)
opj_image_destroy(image); opj_image_destroy(image);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} } else {
else {
/* It is just here to illustrate how to use the resolution after set parameters */ /* It is just here to illustrate how to use the resolution after set parameters */
/*if (!opj_set_decoded_resolution_factor(l_codec, 5)) { /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) {
@ -1373,11 +1361,9 @@ int main(int argc, char **argv)
if(image->color_space == OPJ_CLRSPC_SYCC) { if(image->color_space == OPJ_CLRSPC_SYCC) {
color_sycc_to_rgb(image); color_sycc_to_rgb(image);
} } else if((image->color_space == OPJ_CLRSPC_CMYK) && (parameters.cod_format != TIF_DFMT)) {
else if((image->color_space == OPJ_CLRSPC_CMYK) && (parameters.cod_format != TIF_DFMT)){
color_cmyk_to_rgb(image); color_cmyk_to_rgb(image);
} } else if(image->color_space == OPJ_CLRSPC_EYCC) {
else if(image->color_space == OPJ_CLRSPC_EYCC){
color_esycc_to_rgb(image); color_esycc_to_rgb(image);
} }
@ -1389,16 +1375,15 @@ int main(int argc, char **argv)
color_cielab_to_rgb(image); color_cielab_to_rgb(image);
#endif #endif
free(image->icc_profile_buf); free(image->icc_profile_buf);
image->icc_profile_buf = NULL; image->icc_profile_len = 0; image->icc_profile_buf = NULL;
image->icc_profile_len = 0;
} }
/* Force output precision */ /* Force output precision */
/* ---------------------- */ /* ---------------------- */
if (parameters.precision != NULL) if (parameters.precision != NULL) {
{
OPJ_UINT32 compno; OPJ_UINT32 compno;
for (compno = 0; compno < image->numcomps; ++compno) for (compno = 0; compno < image->numcomps; ++compno) {
{
OPJ_UINT32 precno = compno; OPJ_UINT32 precno = compno;
OPJ_UINT32 prec; OPJ_UINT32 prec;
@ -1427,8 +1412,7 @@ int main(int argc, char **argv)
/* Upsample components */ /* Upsample components */
/* ------------------- */ /* ------------------- */
if (parameters.upsample) if (parameters.upsample) {
{
image = upsample_image_components(image); image = upsample_image_components(image);
if (image == NULL) { if (image == NULL) {
fprintf(stderr, "ERROR -> opj_decompress: failed to upsample image components!\n"); fprintf(stderr, "ERROR -> opj_decompress: failed to upsample image components!\n");
@ -1440,8 +1424,7 @@ int main(int argc, char **argv)
/* Force RGB output */ /* Force RGB output */
/* ---------------- */ /* ---------------- */
if (parameters.force_rgb) if (parameters.force_rgb) {
{
switch (image->color_space) { switch (image->color_space) {
case OPJ_CLRSPC_SRGB: case OPJ_CLRSPC_SRGB:
break; break;
@ -1469,8 +1452,7 @@ int main(int argc, char **argv)
if (imagetopnm(image, parameters.outfile, parameters.split_pnm)) { if (imagetopnm(image, parameters.outfile, parameters.split_pnm)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1479,8 +1461,7 @@ int main(int argc, char **argv)
if(imagetopgx(image, parameters.outfile)) { if(imagetopgx(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1489,8 +1470,7 @@ int main(int argc, char **argv)
if(imagetobmp(image, parameters.outfile)) { if(imagetobmp(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1499,8 +1479,7 @@ int main(int argc, char **argv)
if(imagetotif(image, parameters.outfile)) { if(imagetotif(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1509,8 +1488,7 @@ int main(int argc, char **argv)
if(imagetoraw(image, parameters.outfile)) { if(imagetoraw(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating raw file. Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Error generating raw file. Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1519,8 +1497,7 @@ int main(int argc, char **argv)
if(imagetorawl(image, parameters.outfile)) { if(imagetorawl(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating rawl file. Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Error generating rawl file. Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1529,8 +1506,7 @@ int main(int argc, char **argv)
if(imagetotga(image, parameters.outfile)) { if(imagetotga(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating tga file. Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Error generating tga file. Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -1539,8 +1515,7 @@ int main(int argc, char **argv)
if(imagetopng(image, parameters.outfile)) { if(imagetopng(image, parameters.outfile)) {
fprintf(stderr,"[ERROR] Error generating png file. Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Error generating png file. Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;
} } else {
else {
fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"[INFO] Generated Outfile %s\n",parameters.outfile);
} }
break; break;

View File

@ -91,7 +91,8 @@ static int infile_format(const char *fname);
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol); static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static void decode_help_display(void) { static void decode_help_display(void)
{
fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n" fprintf(stdout,"\nThis is the opj_dump utility from the OpenJPEG project.\n"
"It dumps JPEG 2000 codestream info to stdout or a given file.\n" "It dumps JPEG 2000 codestream info to stdout or a given file.\n"
"It has been compiled against openjp2 library v%s.\n\n",opj_version()); "It has been compiled against openjp2 library v%s.\n\n",opj_version());
@ -117,7 +118,8 @@ static void decode_help_display(void) {
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int get_num_images(char *imgdirpath){ static int get_num_images(char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int num_images = 0; int num_images = 0;
@ -140,7 +142,8 @@ static int get_num_images(char *imgdirpath){
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int load_images(dircnt_t *dirptr, char *imgdirpath){ static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int i = 0; int i = 0;
@ -167,7 +170,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int get_file_format(const char *filename) { static int get_file_format(const char *filename)
{
unsigned int i; unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@ -187,7 +191,8 @@ static int get_file_format(const char *filename) {
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]=""; char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -251,12 +256,10 @@ static int infile_format(const char *fname)
if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) { if (memcmp(buf, JP2_RFC3745_MAGIC, 12) == 0 || memcmp(buf, JP2_MAGIC, 4) == 0) {
magic_format = JP2_CFMT; magic_format = JP2_CFMT;
magic_s = ".jp2"; magic_s = ".jp2";
} } else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
else if (memcmp(buf, J2K_CODESTREAM_MAGIC, 4) == 0) {
magic_format = J2K_CFMT; magic_format = J2K_CFMT;
magic_s = ".j2k or .jpc or .j2c"; magic_s = ".j2k or .jpc or .j2c";
} } else
else
return -1; return -1;
if (magic_format == ext_format) if (magic_format == ext_format)
@ -276,7 +279,8 @@ static int infile_format(const char *fname)
* Parse the command line * Parse the command line
*/ */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol)
{
int totlen, c; int totlen, c;
opj_option_t long_option[]= { opj_option_t long_option[]= {
{"ImgDir",REQ_ARG, NULL ,'y'} {"ImgDir",REQ_ARG, NULL ,'y'}
@ -290,8 +294,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = infile_format(infile); parameters->decod_format = infile_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -317,8 +320,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'o': /* output file */ case 'o': { /* output file */
{
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
fprintf(stderr, "[ERROR] Path is too long\n"); fprintf(stderr, "[ERROR] Path is too long\n");
return 1; return 1;
@ -338,8 +340,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'y': /* Image Directory path */ case 'y': { /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg); strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1; img_fol->set_imgdir=1;
@ -348,8 +349,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'v': /* Verbose mode */ case 'v': { /* Verbose mode */
{
parameters->m_verbose = 1; parameters->m_verbose = 1;
} }
break; break;
@ -394,21 +394,24 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
/** /**
sample error debug callback expecting no client object sample error debug callback expecting no client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[ERROR] %s", msg); fprintf(stdout, "[ERROR] %s", msg);
} }
/** /**
sample warning debug callback expecting no client object sample warning debug callback expecting no client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[WARNING] %s", msg); fprintf(stdout, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
@ -488,8 +491,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile); fprintf(stderr, "ERROR -> failed to open %s for writing\n", parameters.outfile);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} } else
else
fout = stdout; fout = stdout;
/* Read the header of each image one by one */ /* Read the header of each image one by one */
@ -517,20 +519,17 @@ int main(int argc, char *argv[])
/* ------------------------ */ /* ------------------------ */
switch(parameters.decod_format) { switch(parameters.decod_format) {
case J2K_CFMT: /* JPEG-2000 codestream */ case J2K_CFMT: { /* JPEG-2000 codestream */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_J2K); l_codec = opj_create_decompress(OPJ_CODEC_J2K);
break; break;
} }
case JP2_CFMT: /* JPEG 2000 compressed image data */ case JP2_CFMT: { /* JPEG 2000 compressed image data */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JP2); l_codec = opj_create_decompress(OPJ_CODEC_JP2);
break; break;
} }
case JPT_CFMT: /* JPEG 2000, JPIP */ case JPT_CFMT: { /* JPEG 2000, JPIP */
{
/* Get a decoder handle */ /* Get a decoder handle */
l_codec = opj_create_decompress(OPJ_CODEC_JPT); l_codec = opj_create_decompress(OPJ_CODEC_JPT);
break; break;

View File

@ -365,8 +365,7 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname); strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0'); p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p && if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
{
strcpy (p++, "\\"); strcpy (p++, "\\");
} }
# ifdef DIRENT_WIN32_INTERFACE # ifdef DIRENT_WIN32_INTERFACE
@ -619,8 +618,7 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname, if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) &dirp->current.data) != 0) {
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no /* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */ * more entries could be retrieved. */
return 0; return 0;
@ -656,7 +654,8 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field. * Copy name of implementation dependent directory entry to the d_name field.
*/ */
static void static void
_setdirname (struct DIR *dirp) { _setdirname (struct DIR *dirp)
{
/* make sure that d_name is long enough */ /* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX); assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);

View File

@ -45,7 +45,8 @@
void dump_volume(FILE *fd, opj_volume_t * vol) { void dump_volume(FILE *fd, opj_volume_t * vol)
{
int compno; int compno;
fprintf(fd, "volume {\n"); fprintf(fd, "volume {\n");
fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1); fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1);
@ -66,7 +67,8 @@ void dump_volume(FILE *fd, opj_volume_t * vol) {
* *
* log2(a) * log2(a)
*/ */
static int int_floorlog2(int a) { static int int_floorlog2(int a)
{
int l; int l;
for (l = 0; a > 1; l++) { for (l = 0; a > 1; l++) {
a >>= 1; a >>= 1;
@ -79,7 +81,8 @@ static int int_floorlog2(int a) {
* *
* a divided by 2^b * a divided by 2^b
*/ */
static int int_ceildivpow2(int a, int b) { static int int_ceildivpow2(int a, int b)
{
return (a + (1 << b) - 1) >> b; return (a + (1 << b) - 1) >> b;
} }
@ -88,7 +91,8 @@ static int int_ceildivpow2(int a, int b) {
* *
* a divided by b * a divided by b
*/ */
static int int_ceildiv(int a, int b) { static int int_ceildiv(int a, int b)
{
return (a + b - 1) / b; return (a + b - 1) / b;
} }
@ -150,7 +154,8 @@ static unsigned int LongSwap (unsigned int i)
} }
/*****************************************/ /*****************************************/
opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) { opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters)
{
FILE *f = NULL; FILE *f = NULL;
int w, h, prec; int w, h, prec;
@ -196,7 +201,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
/*Fetch only the path */ /*Fetch only the path */
strcpy(tmpdirpath,relpath); strcpy(tmpdirpath,relpath);
if ((tmp = strrchr(tmpdirpath,'/')) != NULL) { if ((tmp = strrchr(tmpdirpath,'/')) != NULL) {
tmp++; *tmp='\0'; tmp++;
*tmp='\0';
strcpy(dirpath,tmpdirpath); strcpy(dirpath,tmpdirpath);
} else { } else {
strcpy(dirpath,"./"); strcpy(dirpath,"./");
@ -222,8 +228,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
} }
/*Read all .pgx files of directory */ /*Read all .pgx files of directory */
while ( (direntp = readdir( dirp )) != NULL ) while ( (direntp = readdir( dirp )) != NULL ) {
{
/* Found a directory, but ignore . and .. */ /* Found a directory, but ignore . and .. */
if(strcmp(".",direntp->d_name) == 0 || strcmp("..",direntp->d_name) == 0) if(strcmp(".",direntp->d_name) == 0 || strcmp("..",direntp->d_name) == 0)
continue; continue;
@ -241,7 +246,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
tmpno[i++] = *tmp2; tmpno[i++] = *tmp2;
point = tmp2; point = tmp2;
tmp2 = strpbrk (tmp2+1,"0123456789"); tmp2 = strpbrk (tmp2+1,"0123456789");
}tmpno[i]='\0'; }
tmpno[i]='\0';
/*Comprobamos que no estamos leyendo algo raro como pattern.jp3d*/ /*Comprobamos que no estamos leyendo algo raro como pattern.jp3d*/
if ((point = strpbrk (point,".")) == NULL) { if ((point = strpbrk (point,".")) == NULL) {
@ -270,8 +276,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
return NULL; return NULL;
}*/ }*/
for (s=0;s<sliceno;s++) for (s=0; s<sliceno; s++) {
{
int pos = maxslice == sliceno ? s: pgxslicepos[s]; int pos = maxslice == sliceno ? s: pgxslicepos[s];
f = fopen(pgxfiles[pos], "rb"); f = fopen(pgxfiles[pos], "rb");
if (!f) { if (!f) {
@ -379,7 +384,8 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
} }
int volumetopgx(opj_volume_t * volume, char *outfile) { int volumetopgx(opj_volume_t * volume, char *outfile)
{
int w, wr, wrr, h, hr, hrr, l, lr, lrr; int w, wr, wrr, h, hr, hrr, l, lr, lrr;
int i, j, compno, offset, sliceno; int i, j, compno, offset, sliceno;
FILE *fdest = NULL; FILE *fdest = NULL;
@ -466,7 +472,8 @@ BIN IMAGE FORMAT
<<-- <<-- <<-- <<-- */ <<-- <<-- <<-- <<-- */
opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *parameters) { opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *parameters)
{
int subsampling_dx = parameters->subsampling_dx; int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy; int subsampling_dy = parameters->subsampling_dy;
int subsampling_dz = parameters->subsampling_dz; int subsampling_dz = parameters->subsampling_dz;
@ -678,7 +685,8 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
return volume; return volume;
} }
int volumetobin(opj_volume_t * volume, char *outfile) { int volumetobin(opj_volume_t * volume, char *outfile)
{
int w, wr, wrr, h, hr, hrr, l, lr, lrr, max; int w, wr, wrr, h, hr, hrr, l, lr, lrr, max;
int i,j, compno, nbytes; int i,j, compno, nbytes;
int offset, sliceno; int offset, sliceno;
@ -764,7 +772,8 @@ int volumetobin(opj_volume_t * volume, char *outfile) {
IMG IMAGE FORMAT IMG IMAGE FORMAT
<<-- <<-- <<-- <<-- */ <<-- <<-- <<-- <<-- */
opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) { opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters)
{
int subsampling_dx = parameters->subsampling_dx; int subsampling_dx = parameters->subsampling_dx;
int subsampling_dy = parameters->subsampling_dy; int subsampling_dy = parameters->subsampling_dy;
int subsampling_dz = parameters->subsampling_dz; int subsampling_dz = parameters->subsampling_dz;
@ -795,7 +804,8 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
/*Fetch only the path */ /*Fetch only the path */
strcpy(tmpdirpath,fileimg); strcpy(tmpdirpath,fileimg);
if ((tmp = strrchr(tmpdirpath,'/')) != NULL) { if ((tmp = strrchr(tmpdirpath,'/')) != NULL) {
tmp++; *tmp='\0'; tmp++;
*tmp='\0';
strcpy(dirpath,tmpdirpath); strcpy(dirpath,tmpdirpath);
} else { } else {
strcpy(dirpath,"./"); strcpy(dirpath,"./");

View File

@ -55,7 +55,8 @@ char *optarg; /* argument associated with option */
* getopt -- * getopt --
* Parse argc/argv argument vector. * Parse argc/argv argument vector.
*/ */
int getopt(int nargc, char *const *nargv, const char *ostr) { int getopt(int nargc, char *const *nargv, const char *ostr)
{
# define __progname nargv[0] /* program name */ # define __progname nargv[0] /* program name */

View File

@ -46,7 +46,8 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
void encode_help_display() { void encode_help_display()
{
fprintf(stdout,"List of parameters for the JPEG2000 Part 10 encoder:\n"); fprintf(stdout,"List of parameters for the JPEG2000 Part 10 encoder:\n");
fprintf(stdout,"------------\n"); fprintf(stdout,"------------\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
@ -166,7 +167,8 @@ void encode_help_display() {
} }
OPJ_PROG_ORDER give_progression(char progression[4]) { OPJ_PROG_ORDER give_progression(char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) { if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP; return LRCP;
} }
@ -186,7 +188,8 @@ OPJ_PROG_ORDER give_progression(char progression[4]) {
return PROG_UNKNOWN; return PROG_UNKNOWN;
} }
OPJ_TRANSFORM give_transform(char transform[4]) { OPJ_TRANSFORM give_transform(char transform[4])
{
if(strncmp(transform, "2DWT", 4) == 0) { if(strncmp(transform, "2DWT", 4) == 0) {
return TRF_2D_DWT; return TRF_2D_DWT;
} }
@ -196,7 +199,8 @@ OPJ_TRANSFORM give_transform(char transform[4]) {
return TRF_UNKNOWN; return TRF_UNKNOWN;
} }
OPJ_ENTROPY_CODING give_coding(char coding[3]) { OPJ_ENTROPY_CODING give_coding(char coding[3])
{
if(strncmp(coding, "2EB", 3) == 0) { if(strncmp(coding, "2EB", 3) == 0) {
return ENCOD_2EB; return ENCOD_2EB;
@ -214,7 +218,8 @@ OPJ_ENTROPY_CODING give_coding(char coding[3]) {
return ENCOD_UNKNOWN; return ENCOD_UNKNOWN;
} }
int get_file_format(char *filename) { int get_file_format(char *filename)
{
int i; int i;
static const char *extension[] = {"pgx", "bin", "img", "j3d", "jp3d", "j2k"}; static const char *extension[] = {"pgx", "bin", "img", "j3d", "jp3d", "j2k"};
static const int format[] = { PGX_DFMT, BIN_DFMT, IMG_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT}; static const int format[] = { PGX_DFMT, BIN_DFMT, IMG_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT};
@ -233,7 +238,8 @@ int get_file_format(char *filename) {
/* ------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */
int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) { int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
{
int i, value; int i, value;
/* parse the command line */ /* parse the command line */
@ -243,8 +249,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile); parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -264,8 +269,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'm': /* input IMG file */ case 'm': { /* input IMG file */
{
char *imgfile = opj_optarg; char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile); int imgformat = get_file_format(imgfile);
switch(imgformat) { switch(imgformat) {
@ -282,8 +286,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -303,8 +306,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* define compression rates for each layer */ case 'r': { /* define compression rates for each layer */
{
char *s = opj_optarg; char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++; parameters->tcp_numlayers++;
@ -321,8 +323,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'q': /* define distorsion (PSNR) for each layer */ case 'q': { /* define distorsion (PSNR) for each layer */
{
char *s = opj_optarg; char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++; parameters->tcp_numlayers++;
@ -339,8 +340,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': case 'f': {
{
fprintf(stdout, "/---------------------------------------------------\\\n"); fprintf(stdout, "/---------------------------------------------------\\\n");
fprintf(stdout, "| Fixed layer allocation option not implemented !! |\n"); fprintf(stdout, "| Fixed layer allocation option not implemented !! |\n");
fprintf(stdout, "\\---------------------------------------------------/\n"); fprintf(stdout, "\\---------------------------------------------------/\n");
@ -388,8 +388,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* tiles */ case 't': { /* tiles */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tdx, &parameters->cp_tdy, &parameters->cp_tdz) !=3) { if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tdx, &parameters->cp_tdy, &parameters->cp_tdz) !=3) {
fprintf(stdout, "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n"); fprintf(stdout, "[ERROR] '-t' 'dimensions of tiles' argument error ! [-t tdx,tdy,tdz]\n");
return 1; return 1;
@ -400,8 +399,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'n': /* resolution */ case 'n': { /* resolution */
{
int aux; int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->numresolution[0], &parameters->numresolution[1], &parameters->numresolution[2]); aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->numresolution[0], &parameters->numresolution[1], &parameters->numresolution[2]);
if (aux == 2) if (aux == 2)
@ -418,8 +416,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'c': /* precinct dimension */ case 'c': { /* precinct dimension */
{
char sep; char sep;
int res_spec = 0; int res_spec = 0;
int aux; int aux;
@ -434,16 +431,14 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
parameters->csty |= 0x01; parameters->csty |= 0x01;
res_spec++; res_spec++;
s = strpbrk(s, "]") + 2; s = strpbrk(s, "]") + 2;
} } while (sep == ',');
while (sep == ',');
parameters->res_spec = res_spec; /* number of precinct size specifications */ parameters->res_spec = res_spec; /* number of precinct size specifications */
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'b': /* code-block dimension */ case 'b': { /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0; int cblockw_init = 0, cblockh_init = 0, cblockl_init = 0;
if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) { if (sscanf(opj_optarg, "%d,%d,%d", &cblockw_init, &cblockh_init, &cblockl_init) != 3) {
fprintf(stdout, "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n"); fprintf(stdout, "[ERROR] '-b' 'dimensions of codeblocks' argument error ! [-b cblkx,cblky,cblkz]\n");
@ -461,8 +456,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'x': /* creation of index file */ case 'x': { /* creation of index file */
{
char *index = opj_optarg; char *index = opj_optarg;
strncpy(parameters->index, index, MAX_PATH); strncpy(parameters->index, index, MAX_PATH);
parameters->index_on = 1; parameters->index_on = 1;
@ -471,8 +465,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* progression order */ case 'p': { /* progression order */
{
char progression[4]; char progression[4];
strncpy(progression, opj_optarg, 4); strncpy(progression, opj_optarg, 4);
@ -486,8 +479,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 's': /* subsampling factor */ case 's': { /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 3) { if (sscanf(opj_optarg, "%d,%d,%d", &parameters->subsampling_dx, &parameters->subsampling_dy, &parameters->subsampling_dz) != 3) {
fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n"); fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n");
return 1; return 1;
@ -497,8 +489,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */ case 'd': { /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->volume_offset_x0, &parameters->volume_offset_y0, &parameters->volume_offset_z0) != 3) { if (sscanf(opj_optarg, "%d,%d,%d", &parameters->volume_offset_x0, &parameters->volume_offset_y0, &parameters->volume_offset_z0) != 3) {
fprintf(stdout, "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n"); fprintf(stdout, "[ERROR] -d 'coordonnate of the reference grid' argument error !! [-d x0,y0,z0]\n");
return 1; return 1;
@ -508,8 +499,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'h': /* display an help description */ case 'h': { /* display an help description */
{
encode_help_display(); encode_help_display();
return 1; return 1;
} }
@ -517,8 +507,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'P': /* POC */ case 'P': { /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */ int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@ -550,24 +539,21 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'S': /* SOP marker */ case 'S': { /* SOP marker */
{
parameters->csty |= 0x02; parameters->csty |= 0x02;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'E': /* EPH marker */ case 'E': { /* EPH marker */
{
parameters->csty |= 0x04; parameters->csty |= 0x04;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'M': /* Codification mode switch */ case 'M': { /* Codification mode switch */
{
fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n"); fprintf(stdout, "[INFO] Mode switch option not fully tested !!\n");
value = 0; value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) { if (sscanf(opj_optarg, "%d", &value) == 1) {
@ -582,8 +568,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'D': /* DCO */ case 'D': { /* DCO */
{
if (sscanf(opj_optarg, "%d", &parameters->dcoffset) != 1) { if (sscanf(opj_optarg, "%d", &parameters->dcoffset) != 1) {
fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n",parameters->dcoffset); fprintf(stdout, "[ERROR] DC offset error !! [-D %d]\n",parameters->dcoffset);
return 1; return 1;
@ -593,8 +578,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'R': /* ROI */ case 'R': { /* ROI */
{
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &parameters->roi_compno, &parameters->roi_shift) != 2) { if (sscanf(opj_optarg, "OI:c=%d,U=%d", &parameters->roi_compno, &parameters->roi_shift) != 2) {
fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n"); fprintf(stdout, "[ERROR] ROI error !! [-ROI:c='compno',U='shift']\n");
return 1; return 1;
@ -604,8 +588,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'l': /* Tile offset */ case 'l': { /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tx0, &parameters->cp_ty0, &parameters->cp_tz0) != 3) { if (sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_tx0, &parameters->cp_ty0, &parameters->cp_tz0) != 3) {
fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]"); fprintf(stdout, "[ERROR] -l 'tile offset' argument error !! [-l X0,Y0,Z0]");
return 1; return 1;
@ -630,8 +613,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
------------------------------------------------------ */ ------------------------------------------------------ */
case 'C': /* Coding of transformed data */ case 'C': { /* Coding of transformed data */
{
char coding[3]; char coding[3];
strncpy(coding, opj_optarg, 3); strncpy(coding, opj_optarg, 3);
@ -645,8 +627,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'I': /* reversible or not */ case 'I': { /* reversible or not */
{
parameters->irreversible = 1; parameters->irreversible = 1;
} }
break; break;
@ -754,28 +735,32 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg); fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
bool bSuccess; bool bSuccess;
bool delete_comment = true; bool delete_comment = true;
opj_cparameters_t parameters; /* compression parameters */ opj_cparameters_t parameters; /* compression parameters */

View File

@ -149,7 +149,8 @@ static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
return sum; return sum;
} }
void decode_help_display() { void decode_help_display()
{
fprintf(stdout,"HELP\n----\n\n"); fprintf(stdout,"HELP\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -195,7 +196,8 @@ void decode_help_display() {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int get_file_format(char *filename) { int get_file_format(char *filename)
{
int i; int i;
static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"}; static const char *extension[] = {"pgx", "bin", "j3d", "jp3d", "j2k", "img"};
static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT}; static const int format[] = { PGX_DFMT, BIN_DFMT, J3D_CFMT, J3D_CFMT, J2K_CFMT, IMG_DFMT};
@ -214,7 +216,8 @@ int get_file_format(char *filename) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters) { int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
{
/* parse the command line */ /* parse the command line */
while (1) { while (1) {
@ -222,8 +225,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile); parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -241,8 +243,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
} }
break; break;
case 'm': /* img file */ case 'm': { /* img file */
{
char *imgfile = opj_optarg; char *imgfile = opj_optarg;
int imgformat = get_file_format(imgfile); int imgformat = get_file_format(imgfile);
switch(imgformat) { switch(imgformat) {
@ -260,8 +261,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -281,8 +281,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* Original image for PSNR computing */ case 'O': { /* Original image for PSNR computing */
{
char *original = opj_optarg; char *original = opj_optarg;
parameters->orig_format = get_file_format(original); parameters->orig_format = get_file_format(original);
switch(parameters->orig_format) { switch(parameters->orig_format) {
@ -301,8 +300,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* reduce option */ case 'r': { /* reduce option */
{
/*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/ /*sscanf(opj_optarg, "%d, %d, %d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);*/
int aux; int aux;
aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]); aux = sscanf(opj_optarg, "%d,%d,%d", &parameters->cp_reduce[0], &parameters->cp_reduce[1], &parameters->cp_reduce[2]);
@ -321,32 +319,28 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'l': /* layering option */ case 'l': { /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer); sscanf(opj_optarg, "%d", &parameters->cp_layer);
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'B': /* BIGENDIAN vs. LITTLEENDIAN */ case 'B': { /* BIGENDIAN vs. LITTLEENDIAN */
{
parameters->bigendian = 1; parameters->bigendian = 1;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'L': /* BIGENDIAN vs. LITTLEENDIAN */ case 'L': { /* BIGENDIAN vs. LITTLEENDIAN */
{
parameters->decod_format = LSE_CFMT; parameters->decod_format = LSE_CFMT;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'h': /* display an help description */ case 'h': { /* display an help description */
{
decode_help_display(); decode_help_display();
return 1; return 1;
} }
@ -375,27 +369,31 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
{
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
opj_dparameters_t parameters; /* decompression parameters */ opj_dparameters_t parameters; /* decompression parameters */
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
@ -499,8 +497,12 @@ int main(int argc, char **argv) {
case PGX_DFMT: /* PGX */ case PGX_DFMT: /* PGX */
if (strcmp("NULL",parameters.original) != 0) { if (strcmp("NULL",parameters.original) != 0) {
fprintf(stdout,"Loading original file %s \n",parameters.original); fprintf(stdout,"Loading original file %s \n",parameters.original);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1; cparameters.subsampling_dx = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0; cparameters.subsampling_dy = 1;
cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;
cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
original = pgxtovolume(parameters.original,&cparameters); original = pgxtovolume(parameters.original,&cparameters);
} }
break; break;
@ -508,8 +510,12 @@ int main(int argc, char **argv) {
case BIN_DFMT: /* BMP */ case BIN_DFMT: /* BMP */
if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0) { if (strcmp("NULL",parameters.original) != 0 && strcmp("NULL",parameters.imgfile) != 0) {
fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile); fprintf(stdout,"Loading original file %s %s\n",parameters.original,parameters.imgfile);
cparameters.subsampling_dx = 1; cparameters.subsampling_dy = 1; cparameters.subsampling_dz = 1; cparameters.subsampling_dx = 1;
cparameters.volume_offset_x0 = 0;cparameters.volume_offset_y0 = 0;cparameters.volume_offset_z0 = 0; cparameters.subsampling_dy = 1;
cparameters.subsampling_dz = 1;
cparameters.volume_offset_x0 = 0;
cparameters.volume_offset_y0 = 0;
cparameters.volume_offset_z0 = 0;
original = bintovolume(parameters.original,parameters.imgfile,&cparameters); original = bintovolume(parameters.original,parameters.imgfile,&cparameters);
} }
break; break;

View File

@ -364,8 +364,7 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname); strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0'); p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p && if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
{
strcpy (p++, "\\"); strcpy (p++, "\\");
} }
# ifdef DIRENT_WIN32_INTERFACE # ifdef DIRENT_WIN32_INTERFACE
@ -618,8 +617,7 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname, if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) &dirp->current.data) != 0) {
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no /* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */ * more entries could be retrieved. */
return 0; return 0;
@ -655,7 +653,8 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field. * Copy name of implementation dependent directory entry to the d_name field.
*/ */
static void static void
_setdirname (struct DIR *dirp) { _setdirname (struct DIR *dirp)
{
/* make sure that d_name is long enough */ /* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX); assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);

View File

@ -54,7 +54,8 @@
WSADATA initialisation_win32; WSADATA initialisation_win32;
#endif #endif
int main(int argc, char *argv[]){ int main(int argc, char *argv[])
{
dec_server_record_t *server_record; dec_server_record_t *server_record;
client_t client; client_t client;

View File

@ -106,15 +106,12 @@ int main(int argc,char *argv[])
} }
ext = strrchr( argv[2], '.' ); ext = strrchr( argv[2], '.' );
if( ext ) if( ext ) {
{
/* strcasecmp ? */ /* strcasecmp ? */
if( strcmp(ext, ".jp2" ) == 0 ) if( strcmp(ext, ".jp2" ) == 0 ) {
{
return jpip_to_jp2(argv); return jpip_to_jp2(argv);
} }
if( strcmp(ext, ".j2k" ) == 0 ) if( strcmp(ext, ".j2k" ) == 0 ) {
{
return jpip_to_j2k(argv); return jpip_to_j2k(argv);
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -45,7 +45,8 @@ Write a structured index to a file
@param index Index filename @param index Index filename
@return Returns 0 if successful, returns 1 otherwise @return Returns 0 if successful, returns 1 otherwise
*/ */
int write_index_file(opj_codestream_info_t *cstr_info, char *index) { int write_index_file(opj_codestream_info_t *cstr_info, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb, x, y; int tileno, compno, layno, resno, precno, pack_nb, x, y;
FILE *stream = NULL; FILE *stream = NULL;
double total_disto = 0; double total_disto = 0;

View File

@ -88,7 +88,8 @@ typedef struct img_folder{
float *rates; float *rates;
} img_fol_t; } img_fol_t;
static void encode_help_display(void) { static void encode_help_display(void)
{
fprintf(stdout,"HELP for opj_jpwl_compress\n----\n\n"); fprintf(stdout,"HELP for opj_jpwl_compress\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -327,7 +328,8 @@ static void encode_help_display(void) {
fprintf(stdout,"TotalDisto\n\n"); fprintf(stdout,"TotalDisto\n\n");
} }
static OPJ_PROG_ORDER give_progression(const char progression[4]) { static OPJ_PROG_ORDER give_progression(const char progression[4])
{
if(strncmp(progression, "LRCP", 4) == 0) { if(strncmp(progression, "LRCP", 4) == 0) {
return LRCP; return LRCP;
} }
@ -347,7 +349,8 @@ static OPJ_PROG_ORDER give_progression(const char progression[4]) {
return PROG_UNKNOWN; return PROG_UNKNOWN;
} }
static unsigned int get_num_images(char *imgdirpath){ static unsigned int get_num_images(char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
unsigned int num_images = 0; unsigned int num_images = 0;
@ -369,7 +372,8 @@ static unsigned int get_num_images(char *imgdirpath){
return num_images; return num_images;
} }
static int load_images(dircnt_t *dirptr, char *imgdirpath){ static int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int i = 0; int i = 0;
@ -394,7 +398,8 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0; return 0;
} }
static int get_file_format(char *filename) { static int get_file_format(char *filename)
{
unsigned int i; unsigned int i;
static const char *extension[] = { static const char *extension[] = {
"pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc" "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "tga", "png", "j2k", "jp2", "j2c", "jpc"
@ -414,14 +419,16 @@ static int get_file_format(char *filename) {
return -1; return -1;
} }
static char * get_file_name(char *name){ static char * get_file_name(char *name)
{
char *fname; char *fname;
fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char)); fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char));
fname= strtok(name,"."); fname= strtok(name,".");
return fname; return fname;
} }
static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]=""; char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -446,7 +453,8 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
return 0; return 0;
} }
static int initialise_4K_poc(opj_poc_t *POC, int numres){ static int initialise_4K_poc(opj_poc_t *POC, int numres)
{
POC[0].tile = 1; POC[0].tile = 1;
POC[0].resno0 = 0; POC[0].resno0 = 0;
POC[0].compno0 = 0; POC[0].compno0 = 0;
@ -464,7 +472,8 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres){
return 2; return 2;
} }
static void cinema_parameters(opj_cparameters_t *parameters){ static void cinema_parameters(opj_cparameters_t *parameters)
{
parameters->tile_size_on = OPJ_FALSE; parameters->tile_size_on = OPJ_FALSE;
parameters->cp_tdx=1; parameters->cp_tdx=1;
parameters->cp_tdy=1; parameters->cp_tdy=1;
@ -490,14 +499,16 @@ static void cinema_parameters(opj_cparameters_t *parameters){
/* No ROI */ /* No ROI */
parameters->roi_compno = -1; parameters->roi_compno = -1;
parameters->subsampling_dx = 1; parameters->subsampling_dy = 1; parameters->subsampling_dx = 1;
parameters->subsampling_dy = 1;
/* 9-7 transform */ /* 9-7 transform */
parameters->irreversible = 1; parameters->irreversible = 1;
} }
static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol)
{
int i; int i;
float temp_rate; float temp_rate;
@ -583,7 +594,8 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
/* ------------------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) { img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename)
{
int i, j, totlen, c; int i, j, totlen, c;
opj_option_t long_option[]= { opj_option_t long_option[]= {
{"cinema2K",REQ_ARG, NULL ,'w'}, {"cinema2K",REQ_ARG, NULL ,'w'},
@ -614,8 +626,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile); parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -640,8 +651,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -657,8 +667,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* output format */ case 'O': { /* output format */
{
char outformat[50]; char outformat[50];
char *of = opj_optarg; char *of = opj_optarg;
sprintf(outformat,".%s",of); sprintf(outformat,".%s",of);
@ -680,8 +689,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */ case 'r': { /* rates rates/distorsion */
{
char *s = opj_optarg; char *s = opj_optarg;
parameters->tcp_numlayers = 0; parameters->tcp_numlayers = 0;
while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_rates[parameters->tcp_numlayers]) == 1) {
@ -700,28 +708,24 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'F': /* Raw image format parameters */ case 'F': { /* Raw image format parameters */
{
char signo; char signo;
char *s = opj_optarg; char *s = opj_optarg;
if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) { if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) {
if (signo == 's') { if (signo == 's') {
raw_cp->rawSigned = OPJ_TRUE; raw_cp->rawSigned = OPJ_TRUE;
fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth); fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
} } else if (signo == 'u') {
else if (signo == 'u') {
raw_cp->rawSigned = OPJ_FALSE; raw_cp->rawSigned = OPJ_FALSE;
fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth); fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth);
} } else {
else {
fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n"); fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n");
fprintf(stderr,"Please use the Format option -F:\n"); fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n");
fprintf(stderr,"Aborting\n"); fprintf(stderr,"Aborting\n");
} }
} } else {
else {
fprintf(stderr,"\nError: invalid raw image parameters\n"); fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n"); fprintf(stderr,"Please use the Format option -F:\n");
fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n");
@ -734,8 +738,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'q': /* add fixed_quality */ case 'q': { /* add fixed_quality */
{
char *s = opj_optarg; char *s = opj_optarg;
while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) { while (sscanf(s, "%f", &parameters->tcp_distoratio[parameters->tcp_numlayers]) == 1) {
parameters->tcp_numlayers++; parameters->tcp_numlayers++;
@ -753,8 +756,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* dda */ /* dda */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */ case 'f': { /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL; int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0; int numlayers = 0, numresolution = 0, matrix_width = 0;
@ -800,8 +802,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 't': /* tiles */ case 't': { /* tiles */
{
sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy); sscanf(opj_optarg, "%d,%d", &parameters->cp_tdx, &parameters->cp_tdy);
parameters->tile_size_on = OPJ_TRUE; parameters->tile_size_on = OPJ_TRUE;
} }
@ -809,15 +810,13 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'n': /* resolution */ case 'n': { /* resolution */
{
sscanf(opj_optarg, "%d", &parameters->numresolution); sscanf(opj_optarg, "%d", &parameters->numresolution);
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'c': /* precinct dimension */ case 'c': { /* precinct dimension */
{
char sep; char sep;
int res_spec = 0; int res_spec = 0;
@ -829,16 +828,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
parameters->csty |= 0x01; parameters->csty |= 0x01;
res_spec++; res_spec++;
s = strpbrk(s, "]") + 2; s = strpbrk(s, "]") + 2;
} } while (sep == ',');
while (sep == ',');
parameters->res_spec = res_spec; parameters->res_spec = res_spec;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'b': /* code-block dimension */ case 'b': { /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0; int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@ -855,8 +852,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'x': /* creation of index file */ case 'x': { /* creation of index file */
{
char *index = opj_optarg; char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN); strncpy(indexfilename, index, OPJ_PATH_LEN);
} }
@ -864,8 +860,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* progression order */ case 'p': { /* progression order */
{
char progression[4]; char progression[4];
strncpy(progression, opj_optarg, 4); strncpy(progression, opj_optarg, 4);
@ -880,8 +875,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 's': /* subsampling factor */ case 's': { /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx, if (sscanf(opj_optarg, "%d,%d", &parameters->subsampling_dx,
&parameters->subsampling_dy) != 2) { &parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@ -892,8 +886,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */ case 'd': { /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0, if (sscanf(opj_optarg, "%d,%d", &parameters->image_offset_x0,
&parameters->image_offset_y0) != 2) { &parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument " fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@ -911,8 +904,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'P': /* POC */ case 'P': { /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */ int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@ -939,24 +931,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'S': /* SOP marker */ case 'S': { /* SOP marker */
{
parameters->csty |= 0x02; parameters->csty |= 0x02;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'E': /* EPH marker */ case 'E': { /* EPH marker */
{
parameters->csty |= 0x04; parameters->csty |= 0x04;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'M': /* Mode switch pas tous au point !! */ case 'M': { /* Mode switch pas tous au point !! */
{
int value = 0; int value = 0;
if (sscanf(opj_optarg, "%d", &value) == 1) { if (sscanf(opj_optarg, "%d", &value) == 1) {
for (i = 0; i <= 5; i++) { for (i = 0; i <= 5; i++) {
@ -970,8 +959,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'R': /* ROI */ case 'R': { /* ROI */
{
if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno, if (sscanf(opj_optarg, "c=%d,U=%d", &parameters->roi_compno,
&parameters->roi_shift) != 2) { &parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n"); fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n");
@ -982,8 +970,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'T': /* Tile offset */ case 'T': { /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) { if (sscanf(opj_optarg, "%d,%d", &parameters->cp_tx0, &parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1; return 1;
@ -993,8 +980,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'C': /* add a comment */ case 'C': { /* add a comment */
{
parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(parameters->cp_comment) { if(parameters->cp_comment) {
strcpy(parameters->cp_comment, opj_optarg); strcpy(parameters->cp_comment, opj_optarg);
@ -1005,16 +991,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'I': /* reversible or not */ case 'I': { /* reversible or not */
{
parameters->irreversible = 1; parameters->irreversible = 1;
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'u': /* Tile part generation*/ case 'u': { /* Tile part generation*/
{
parameters->tp_flag = opj_optarg[0]; parameters->tp_flag = opj_optarg[0];
parameters->tp_on = 1; parameters->tp_on = 1;
} }
@ -1022,8 +1006,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'z': /* Image Directory path */ case 'z': { /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg); strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1; img_fol->set_imgdir=1;
@ -1032,8 +1015,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'w': /* Digital Cinema 2K profile compliance*/ case 'w': { /* Digital Cinema 2K profile compliance*/
{
int fps=0; int fps=0;
sscanf(opj_optarg,"%d",&fps); sscanf(opj_optarg,"%d",&fps);
if(fps == 24) { if(fps == 24) {
@ -1052,8 +1034,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'y': /* Digital Cinema 4K profile compliance*/ case 'y': { /* Digital Cinema 4K profile compliance*/
{
parameters->cp_cinema = CINEMA4K_24; parameters->cp_cinema = CINEMA4K_24;
fprintf(stdout,"CINEMA 4K compliant codestream\n"); fprintf(stdout,"CINEMA 4K compliant codestream\n");
parameters->cp_rsiz = CINEMA4K; parameters->cp_rsiz = CINEMA4K;
@ -1066,8 +1047,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
#ifdef USE_JPWL #ifdef USE_JPWL
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'W': /* JPWL capabilities switched on */ case 'W': { /* JPWL capabilities switched on */
{
char *token = NULL; char *token = NULL;
int hprot, pprot, sens, addr, size, range; int hprot, pprot, sens, addr, size, range;
@ -1383,8 +1363,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* <<UniPG */ /* <<UniPG */
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'J': /* jpip on */ case 'J': { /* jpip on */
{
/*parameters->jpip_on = OPJ_TRUE;*/ /*parameters->jpip_on = OPJ_TRUE;*/
} }
break; break;
@ -1472,28 +1451,32 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg); fprintf(stream, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
opj_bool bSuccess; opj_bool bSuccess;
opj_cparameters_t parameters; /* compression parameters */ opj_cparameters_t parameters; /* compression parameters */
img_fol_t img_fol; img_fol_t img_fol;
@ -1670,8 +1653,7 @@ int main(int argc, char **argv) {
/* Can happen if input file is TIFF or PNG /* Can happen if input file is TIFF or PNG
* and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined
*/ */
if( !image) if( !image) {
{
fprintf(stderr, "Unable to load file: got no image\n"); fprintf(stderr, "Unable to load file: got no image\n");
return 1; return 1;
} }

View File

@ -91,7 +91,8 @@ typedef struct img_folder{
} img_fol_t; } img_fol_t;
void decode_help_display(void) { void decode_help_display(void)
{
fprintf(stdout,"HELP for j2k_to_image\n----\n\n"); fprintf(stdout,"HELP for j2k_to_image\n----\n\n");
fprintf(stdout,"- the -h option displays this help information on screen\n\n"); fprintf(stdout,"- the -h option displays this help information on screen\n\n");
@ -150,7 +151,8 @@ void decode_help_display(void) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int get_num_images(char *imgdirpath){ int get_num_images(char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int num_images = 0; int num_images = 0;
@ -171,7 +173,8 @@ int get_num_images(char *imgdirpath){
return num_images; return num_images;
} }
int load_images(dircnt_t *dirptr, char *imgdirpath){ int load_images(dircnt_t *dirptr, char *imgdirpath)
{
DIR *dir; DIR *dir;
struct dirent* content; struct dirent* content;
int i = 0; int i = 0;
@ -196,7 +199,8 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
return 0; return 0;
} }
int get_file_format(char *filename) { int get_file_format(char *filename)
{
unsigned int i; unsigned int i;
static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" };
static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT };
@ -215,7 +219,8 @@ int get_file_format(char *filename) {
return -1; return -1;
} }
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters)
{
char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN];
char *temp_p, temp1[OPJ_PATH_LEN]=""; char *temp_p, temp1[OPJ_PATH_LEN]="";
@ -241,7 +246,8 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename) { int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol, char *indexfilename)
{
/* parse the command line */ /* parse the command line */
int totlen, c; int totlen, c;
opj_option_t long_option[]= { opj_option_t long_option[]= {
@ -264,8 +270,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* input file */ case 'i': { /* input file */
{
char *infile = opj_optarg; char *infile = opj_optarg;
parameters->decod_format = get_file_format(infile); parameters->decod_format = get_file_format(infile);
switch(parameters->decod_format) { switch(parameters->decod_format) {
@ -285,8 +290,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* output file */ case 'o': { /* output file */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
parameters->cod_format = get_file_format(outfile); parameters->cod_format = get_file_format(outfile);
switch(parameters->cod_format) { switch(parameters->cod_format) {
@ -308,8 +312,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'O': /* output format */ case 'O': { /* output format */
{
char outformat[50]; char outformat[50];
char *of = opj_optarg; char *of = opj_optarg;
sprintf(outformat,".%s",of); sprintf(outformat,".%s",of);
@ -348,8 +351,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* reduce option */ case 'r': { /* reduce option */
{
sscanf(opj_optarg, "%d", &parameters->cp_reduce); sscanf(opj_optarg, "%d", &parameters->cp_reduce);
} }
break; break;
@ -357,8 +359,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'l': /* layering option */ case 'l': { /* layering option */
{
sscanf(opj_optarg, "%d", &parameters->cp_layer); sscanf(opj_optarg, "%d", &parameters->cp_layer);
} }
break; break;
@ -371,16 +372,14 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'y': /* Image Directory path */ case 'y': { /* Image Directory path */
{
img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1);
strcpy(img_fol->imgdirpath,opj_optarg); strcpy(img_fol->imgdirpath,opj_optarg);
img_fol->set_imgdir=1; img_fol->set_imgdir=1;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'x': /* Creation of index file */ case 'x': { /* Creation of index file */
{
char *index = opj_optarg; char *index = opj_optarg;
strncpy(indexfilename, index, OPJ_PATH_LEN); strncpy(indexfilename, index, OPJ_PATH_LEN);
} }
@ -389,8 +388,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
case 'W': /* activate JPWL correction */ case 'W': { /* activate JPWL correction */
{
char *token = NULL; char *token = NULL;
token = strtok(opj_optarg, ","); token = strtok(opj_optarg, ",");
@ -496,28 +494,32 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
fprintf(stdout, "[INFO] %s", msg); fprintf(stdout, "[INFO] %s", msg);
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char **argv) { int main(int argc, char **argv)
{
opj_dparameters_t parameters; /* decompression parameters */ opj_dparameters_t parameters; /* decompression parameters */
img_fol_t img_fol; img_fol_t img_fol;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
@ -601,8 +603,7 @@ int main(int argc, char **argv) {
file_length = ftell(fsrc); file_length = ftell(fsrc);
fseek(fsrc, 0, SEEK_SET); fseek(fsrc, 0, SEEK_SET);
src = (unsigned char *) malloc(file_length); src = (unsigned char *) malloc(file_length);
if (fread(src, 1, file_length, fsrc) != (size_t)file_length) if (fread(src, 1, file_length, fsrc) != (size_t)file_length) {
{
free(src); free(src);
fclose(fsrc); fclose(fsrc);
fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n"); fprintf(stderr, "\nERROR: fread return a number of element different from the expected.\n");
@ -614,8 +615,7 @@ int main(int argc, char **argv) {
/* ---------------------- */ /* ---------------------- */
switch(parameters.decod_format) { switch(parameters.decod_format) {
case J2K_CFMT: case J2K_CFMT: {
{
/* JPEG-2000 codestream */ /* JPEG-2000 codestream */
/* get a decoder handle */ /* get a decoder handle */
@ -657,8 +657,7 @@ int main(int argc, char **argv) {
} }
break; break;
case JP2_CFMT: case JP2_CFMT: {
{
/* JPEG 2000 compressed image data */ /* JPEG 2000 compressed image data */
/* get a decoder handle */ /* get a decoder handle */
@ -700,8 +699,7 @@ int main(int argc, char **argv) {
} }
break; break;
case JPT_CFMT: case JPT_CFMT: {
{
/* JPEG 2000, JPIP */ /* JPEG 2000, JPIP */
/* get a decoder handle */ /* get a decoder handle */
@ -752,19 +750,18 @@ int main(int argc, char **argv) {
free(src); free(src);
src = NULL; src = NULL;
if(image->color_space == CLRSPC_SYCC) if(image->color_space == CLRSPC_SYCC) {
{
color_sycc_to_rgb(image); color_sycc_to_rgb(image);
} }
if(image->icc_profile_buf) if(image->icc_profile_buf) {
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(image); color_apply_icc_profile(image);
#endif #endif
free(image->icc_profile_buf); free(image->icc_profile_buf);
image->icc_profile_buf = NULL; image->icc_profile_len = 0; image->icc_profile_buf = NULL;
image->icc_profile_len = 0;
} }
/* create output image */ /* create output image */
@ -773,8 +770,7 @@ int main(int argc, char **argv) {
case PXM_DFMT: /* PNM PGM PPM */ case PXM_DFMT: /* PNM PGM PPM */
if (imagetopnm(image, parameters.outfile)) { if (imagetopnm(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -782,8 +778,7 @@ int main(int argc, char **argv) {
case PGX_DFMT: /* PGX */ case PGX_DFMT: /* PGX */
if(imagetopgx(image, parameters.outfile)) { if(imagetopgx(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -791,8 +786,7 @@ int main(int argc, char **argv) {
case BMP_DFMT: /* BMP */ case BMP_DFMT: /* BMP */
if(imagetobmp(image, parameters.outfile)) { if(imagetobmp(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -800,8 +794,7 @@ int main(int argc, char **argv) {
case TIF_DFMT: /* TIFF */ case TIF_DFMT: /* TIFF */
if(imagetotif(image, parameters.outfile)) { if(imagetotif(image, parameters.outfile)) {
fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -809,8 +802,7 @@ int main(int argc, char **argv) {
case RAW_DFMT: /* RAW */ case RAW_DFMT: /* RAW */
if(imagetoraw(image, parameters.outfile)) { if(imagetoraw(image, parameters.outfile)) {
fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -818,8 +810,7 @@ int main(int argc, char **argv) {
case TGA_DFMT: /* TGA */ case TGA_DFMT: /* TGA */
if(imagetotga(image, parameters.outfile)) { if(imagetotga(image, parameters.outfile)) {
fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
} }
break; break;
@ -827,8 +818,7 @@ int main(int argc, char **argv) {
case PNG_DFMT: /* PNG */ case PNG_DFMT: /* PNG */
if(imagetopng(image, parameters.outfile)) { if(imagetopng(image, parameters.outfile)) {
fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile); fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile);
} } else {
else {
fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile);
} }
break; break;

View File

@ -365,8 +365,7 @@ static DIR *opendir(const char *dirname)
strcpy (dirp->dirname, dirname); strcpy (dirp->dirname, dirname);
p = strchr (dirp->dirname, '\0'); p = strchr (dirp->dirname, '\0');
if (dirp->dirname < p && if (dirp->dirname < p &&
*(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') *(p - 1) != '\\' && *(p - 1) != '/' && *(p - 1) != ':') {
{
strcpy (p++, "\\"); strcpy (p++, "\\");
} }
# ifdef DIRENT_WIN32_INTERFACE # ifdef DIRENT_WIN32_INTERFACE
@ -619,8 +618,7 @@ _initdir (DIR *dirp)
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
if (_dos_findfirst (dirp->dirname, if (_dos_findfirst (dirp->dirname,
_A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN, _A_SUBDIR | _A_RDONLY | _A_ARCH | _A_SYSTEM | _A_HIDDEN,
&dirp->current.data) != 0) &dirp->current.data) != 0) {
{
/* _dos_findfirst and findfirst will set errno to ENOENT when no /* _dos_findfirst and findfirst will set errno to ENOENT when no
* more entries could be retrieved. */ * more entries could be retrieved. */
return 0; return 0;
@ -656,7 +654,8 @@ _getdirname (const struct dirent *dp)
* Copy name of implementation dependent directory entry to the d_name field. * Copy name of implementation dependent directory entry to the d_name field.
*/ */
static void static void
_setdirname (struct DIR *dirp) { _setdirname (struct DIR *dirp)
{
/* make sure that d_name is long enough */ /* make sure that d_name is long enough */
assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX); assert (strlen (_getdirname (&dirp->current)) <= NAME_MAX);

View File

@ -89,10 +89,10 @@ void xml_write_init(BOOL n, BOOL t, BOOL r, BOOL d)
derived = d; derived = d;
} }
int xml_write_struct(FILE* file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr) { int xml_write_struct(FILE* file, FILE *xmlout, opj_mj2_t * movie, unsigned int sampleframe, char* stringDTD, opj_event_mgr_t *event_mgr)
if(stringDTD != NULL)
{ {
if(stringDTD != NULL) {
fprintf(xmlout,"<?xml version=\"1.0\" standalone=\"no\"?>\n"); fprintf(xmlout,"<?xml version=\"1.0\" standalone=\"no\"?>\n");
/* stringDTD is known to start with "SYSTEM " or "PUBLIC " */ /* stringDTD is known to start with "SYSTEM " or "PUBLIC " */
/* typical: SYSTEM mj2_to_metadata.dtd */ /* typical: SYSTEM mj2_to_metadata.dtd */
@ -123,8 +123,7 @@ int xml_write_overall_header(FILE *file, FILE *xmlout, opj_mj2_t * movie, unsign
fprintf(xmlout, " <Brand>%s</Brand>\n", buf); /* 4 character; BR */ fprintf(xmlout, " <Brand>%s</Brand>\n", buf); /* 4 character; BR */
fprintf(xmlout, " <MinorVersion>%u</MinorVersion>\n", movie->minversion); /* 4 char; MinV */ fprintf(xmlout, " <MinorVersion>%u</MinorVersion>\n", movie->minversion); /* 4 char; MinV */
fprintf(xmlout, " <CompatibilityList Count=\"%d\">\n",movie->num_cl); fprintf(xmlout, " <CompatibilityList Count=\"%d\">\n",movie->num_cl);
for (i = movie->num_cl - 1; i > -1; i--) /* read routine stored in reverse order, so let's undo damage */ for (i = movie->num_cl - 1; i > -1; i--) { /* read routine stored in reverse order, so let's undo damage */
{
uint_to_chars(movie->cl[i], buf); uint_to_chars(movie->cl[i], buf);
fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */ fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */
} }
@ -264,8 +263,7 @@ void uint_to_chars(unsigned int value, char* buf)
{ {
/* buf is at least char[5] */ /* buf is at least char[5] */
int i; int i;
for (i = 3; i >= 0; i--) for (i = 3; i >= 0; i--) {
{
buf[i] = (value & 0x000000ff); buf[i] = (value & 0x000000ff);
value = (value >> 8); value = (value >> 8);
} }
@ -319,7 +317,8 @@ void xml_time_out(FILE* xmlout, time_t t)
/* ------------- */ /* ------------- */
void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie) { void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie)
{
/* Compare with xml_write_udta */ /* Compare with xml_write_udta */
#ifdef NOTYET #ifdef NOTYET
/* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak) /* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak)
@ -346,7 +345,8 @@ void xml_write_moov_udta(FILE* xmlout, opj_mj2_t * movie) {
#endif #endif
} }
void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie) { void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie)
{
#ifdef NOTYET #ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of free and/or skip /* NO-OP so far. There can be zero or more instances of free and/or skip
at the top level of the file. This may be a place where the user squirrel's metadata. at the top level of the file. This may be a place where the user squirrel's metadata.
@ -374,7 +374,8 @@ void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie) {
#endif #endif
} }
void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie) { void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie)
{
/* Universal Unique IDs of 16 bytes. */ /* Universal Unique IDs of 16 bytes. */
#ifdef NOTYET #ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of private uuid boxes in a file. /* NO-OP so far. There can be zero or more instances of private uuid boxes in a file.
@ -411,8 +412,7 @@ void xml_write_trak(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
/* sampleframe is from user option -f. 1 = first frame */ /* sampleframe is from user option -f. 1 = first frame */
/* sampleframe of 0 is a user requests: no jp2 header */ /* sampleframe of 0 is a user requests: no jp2 header */
/* Treat out-of-bounds values in the same way */ /* Treat out-of-bounds values in the same way */
if(sampleframe > 0 && sampleframe <= track->num_samples) if(sampleframe > 0 && sampleframe <= track->num_samples) {
{
mj2_sample_t *sample; mj2_sample_t *sample;
unsigned int snum; unsigned int snum;
@ -439,14 +439,12 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <!-- If both found, value read from MediaHeader is used. -->\n"); fprintf(xmlout, " <!-- If both found, value read from MediaHeader is used. -->\n");
} }
fprintf(xmlout, " <TrackID>%u</TrackID>\n", track->track_ID); fprintf(xmlout, " <TrackID>%u</TrackID>\n", track->track_ID);
if(track->track_type==0) /* For visual track */ if(track->track_type==0) { /* For visual track */
{
fprintf(xmlout, " <TrackLayer>%d</TrackLayer>\n", track->layer); fprintf(xmlout, " <TrackLayer>%d</TrackLayer>\n", track->layer);
if(notes) if(notes)
fprintf(xmlout," <!-- front-to-back ordering of video tracks. 0 = normal, -1 is closer, etc. -->\n"); fprintf(xmlout," <!-- front-to-back ordering of video tracks. 0 = normal, -1 is closer, etc. -->\n");
} }
if(track->track_type!=0) /* volume irrelevant for visual track */ if(track->track_type!=0) { /* volume irrelevant for visual track */
{
#ifdef CURRENTSTRUCT #ifdef CURRENTSTRUCT
track->volume = track->volume << 8; track->volume = track->volume << 8;
#endif #endif
@ -466,8 +464,7 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
track->volume = track->volume >> 8; track->volume = track->volume >> 8;
#endif #endif
} }
if(track->track_type==0) if(track->track_type==0) {
{
/* Transformation matrix for video */ /* Transformation matrix for video */
fprintf(xmlout, " <TransformationMatrix>\n"); fprintf(xmlout, " <TransformationMatrix>\n");
if(notes) { if(notes) {
@ -518,7 +515,8 @@ void xml_write_tkhd(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
/* ------------- */ /* ------------- */
void xml_write_udta(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum) { void xml_write_udta(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum)
{
/* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak) /* NO-OP so far. Optional UserData 'udta' (zero or one in moov or each trak)
can contain multiple Copyright 'cprt' with different language codes */ can contain multiple Copyright 'cprt' with different language codes */
/* There may be nested non-standard boxes within udta */ /* There may be nested non-standard boxes within udta */
@ -590,14 +588,16 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <Language>%s</Language>\n", buf); /* 3 chars */ fprintf(xmlout, " <Language>%s</Language>\n", buf); /* 3 chars */
fprintf(xmlout, " </MediaHeader>\n"); fprintf(xmlout, " </MediaHeader>\n");
fprintf(xmlout, " <HandlerReference BoxType=\"hdlr\">\n"); fprintf(xmlout, " <HandlerReference BoxType=\"hdlr\">\n");
switch(track->track_type) switch(track->track_type) {
{
case 0: case 0:
fprintf(xmlout, " <HandlerType Code=\"vide\">video media track</HandlerType>\n"); break; fprintf(xmlout, " <HandlerType Code=\"vide\">video media track</HandlerType>\n");
break;
case 1: case 1:
fprintf(xmlout, " <HandlerType Code=\"soun\">Sound</HandlerType>\n"); break; fprintf(xmlout, " <HandlerType Code=\"soun\">Sound</HandlerType>\n");
break;
case 2: case 2:
fprintf(xmlout, " <HandlerType Code=\"hint\">Hint</HandlerType>\n"); break; fprintf(xmlout, " <HandlerType Code=\"hint\">Hint</HandlerType>\n");
break;
} }
if(notes) { if(notes) {
fprintf(xmlout, " <!-- String value shown is not actually read from file. -->\n"); fprintf(xmlout, " <!-- String value shown is not actually read from file. -->\n");
@ -605,8 +605,7 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
} }
fprintf(xmlout, " </HandlerReference>\n"); fprintf(xmlout, " </HandlerReference>\n");
fprintf(xmlout, " <MediaInfoContainer BoxType=\"minf\">\n"); fprintf(xmlout, " <MediaInfoContainer BoxType=\"minf\">\n");
switch(track->track_type) switch(track->track_type) {
{
case 0: case 0:
fprintf(xmlout, " <VideoMediaHeader BoxType=\"vmhd\">\n"); fprintf(xmlout, " <VideoMediaHeader BoxType=\"vmhd\">\n");
fprintf(xmlout, " <GraphicsMode>0x%02x</GraphicsMode>\n", track->graphicsmode); fprintf(xmlout, " <GraphicsMode>0x%02x</GraphicsMode>\n", track->graphicsmode);
@ -724,8 +723,7 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " <SampleTable BoxType=\"stbl\">\n"); fprintf(xmlout, " <SampleTable BoxType=\"stbl\">\n");
if(notes) if(notes)
fprintf(xmlout, " <!-- What follows are specific instances of generic SampleDescription BoxType=\"stsd\" -->\n"); fprintf(xmlout, " <!-- What follows are specific instances of generic SampleDescription BoxType=\"stsd\" -->\n");
switch(track->track_type) switch(track->track_type) {
{
case 0: case 0:
// There could be multiple instances of this, but "entry_count" is just a local at read-time. // There could be multiple instances of this, but "entry_count" is just a local at read-time.
// And it's used wrong, too, as count of just visual type, when it's really all 3 types. // And it's used wrong, too, as count of just visual type, when it's really all 3 types.
@ -797,16 +795,15 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " </FieldCoding>\n"); fprintf(xmlout, " </FieldCoding>\n");
fprintf(xmlout, " <MJP2_Profile BoxType=\"jp2p\" Count=\"%d\">\n",track->num_br); fprintf(xmlout, " <MJP2_Profile BoxType=\"jp2p\" Count=\"%d\">\n",track->num_br);
for (i = 0; i < track->num_br; i++) /* read routine stored in reverse order, so let's undo damage */ for (i = 0; i < track->num_br; i++) { /* read routine stored in reverse order, so let's undo damage */
{
uint_to_chars(track->br[i], buf); uint_to_chars(track->br[i], buf);
fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */ fprintf(xmlout, " <CompatibleBrand>%s</CompatibleBrand>\n", buf); /*4 characters, each CLi */
} }
fprintf(xmlout, " </MJP2_Profile>\n"); fprintf(xmlout, " </MJP2_Profile>\n");
fprintf(xmlout, " <MJP2_Prefix BoxType=\"jp2x\" Count=\"%d\">\n",track->num_jp2x); fprintf(xmlout, " <MJP2_Prefix BoxType=\"jp2x\" Count=\"%d\">\n",track->num_jp2x);
for (i = 0; i < track->num_jp2x; i++) for (i = 0; i < track->num_jp2x; i++) {
{ // We'll probably need better formatting than this // We'll probably need better formatting than this
fprintf(xmlout, " <Data>0x%02x</Data>\n", track->jp2xdata[i]); /* Each entry is single byte */ fprintf(xmlout, " <Data>0x%02x</Data>\n", track->jp2xdata[i]); /* Each entry is single byte */
} }
fprintf(xmlout, " </MJP2_Prefix>\n"); fprintf(xmlout, " </MJP2_Prefix>\n");
@ -843,9 +840,11 @@ void xml_write_stbl(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout, " </MJP2_OriginalFormat>\n"); fprintf(xmlout, " </MJP2_OriginalFormat>\n");
fprintf(xmlout, " </VisualSampleEntry>\n"); fprintf(xmlout, " </VisualSampleEntry>\n");
break; break;
case 1: case 2: case 1:
case 2:
if(notes) if(notes)
fprintf(xmlout, " <!-- mj2_to_metadata's data structure doesn't record this currently. -->\n"); break; fprintf(xmlout, " <!-- mj2_to_metadata's data structure doesn't record this currently. -->\n");
break;
} }
fprintf(xmlout, " <TimeToSample BoxType=\"stts\">\n"); fprintf(xmlout, " <TimeToSample BoxType=\"stts\">\n");
fprintf(xmlout, " <SampleStatistics>\n"); fprintf(xmlout, " <SampleStatistics>\n");
@ -1031,13 +1030,11 @@ int xml_out_frame(FILE* file, FILE* xmlout, mj2_sample_t *sample, unsigned int s
&& (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1)) && (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1))
|| (img->numcomps == 1)) { || (img->numcomps == 1)) {
fprintf(xmlout, " <!-- file to a YUV movie in the normal manner. -->\n"); fprintf(xmlout, " <!-- file to a YUV movie in the normal manner. -->\n");
} } else if ((img->numcomps == 3) &&
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&& (img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1)) {// If YUV 4:4:4 input --> to bmp (img->comps[2].dx == 1)) {// If YUV 4:4:4 input --> to bmp
fprintf(xmlout, " <!-- YUV 4:4:4 file to a series of .bmp files. -->\n"); fprintf(xmlout, " <!-- YUV 4:4:4 file to a series of .bmp files. -->\n");
} } else {
else {
fprintf(xmlout, " <!-- file whose image component dimension are unknown, to a series of .j2k files. -->\n"); fprintf(xmlout, " <!-- file whose image component dimension are unknown, to a series of .j2k files. -->\n");
} }
} }
@ -1056,8 +1053,7 @@ void int16_to_3packedchars(short int value, char* buf)
/* This is to retrieve the 3-letter ASCII language code */ /* This is to retrieve the 3-letter ASCII language code */
/* Each char is packed into 5 bits, as difference from 0x60 */ /* Each char is packed into 5 bits, as difference from 0x60 */
int i; int i;
for (i = 2; i >= 0; i--) for (i = 2; i >= 0; i--) {
{
buf[i] = (value & 0x001f) + 0x60; buf[i] = (value & 0x001f) + 0x60;
value = (value >>5); value = (value >>5);
} }
@ -1144,7 +1140,8 @@ void xml_out_frame_cod(FILE* xmlout, opj_tcp_t *tcp)
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == j2k_default_tcp) { if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
tccp = &(tcp->tccps[0]); tccp = &(tcp->tccps[0]);
@ -1225,7 +1222,8 @@ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional i
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == j2k_default_tcp) { if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
firstcomp_tccp = &(tcp->tccps[0]); firstcomp_tccp = &(tcp->tccps[0]);
@ -1241,8 +1239,7 @@ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional i
else else
fprintf(xmlout, "%s<!-- and any other component, with tile-part-header style values different from [0], as COC. -->\n", s); fprintf(xmlout, "%s<!-- and any other component, with tile-part-header style values different from [0], as COC. -->\n", s);
} }
for (compno = 1; compno < numcomps; compno++) /* spec says components are zero-based */ for (compno = 1; compno < numcomps; compno++) { /* spec says components are zero-based */
{
tccp = &tcp->tccps[compno]; tccp = &tcp->tccps[compno];
if(same_component_style(firstcomp_tccp, tccp)) if(same_component_style(firstcomp_tccp, tccp))
continue; continue;
@ -1344,7 +1341,8 @@ void xml_out_frame_qcd(FILE* xmlout, opj_tcp_t *tcp)
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == j2k_default_tcp) { if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
/* Compare j2k_read_qcx */ /* Compare j2k_read_qcx */
@ -1477,7 +1475,8 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == j2k_default_tcp) { if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
firstcomp_tccp = &(tcp->tccps[0]); firstcomp_tccp = &(tcp->tccps[0]);
@ -1493,8 +1492,7 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
else else
fprintf(xmlout, "%s<!-- and any other component, with tile-part-header quantization values different from [0], as QCC. -->\n", s); fprintf(xmlout, "%s<!-- and any other component, with tile-part-header quantization values different from [0], as QCC. -->\n", s);
} }
for (compno = 1; compno < numcomps; compno++) /* spec says components are zero-based */ for (compno = 1; compno < numcomps; compno++) { /* spec says components are zero-based */
{
tccp = &(tcp->tccps[compno]); tccp = &(tcp->tccps[compno]);
if(same_component_quantization(firstcomp_tccp, tccp)) if(same_component_quantization(firstcomp_tccp, tccp))
continue; continue;
@ -1661,7 +1659,8 @@ void xml_out_frame_rgn(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == j2k_default_tcp) { if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
for(compno = 0; compno < numcomps; compno++) { for(compno = 0; compno < numcomps; compno++) {
@ -1686,14 +1685,16 @@ void xml_out_frame_rgn(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
/* ------------- */ /* ------------- */
void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) { /* Progression Order Change */ void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) /* Progression Order Change */
{
/* Compare j2k_read_poc() */ /* Compare j2k_read_poc() */
int i; int i;
opj_poc_t *poc; opj_poc_t *poc;
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == j2k_default_tcp) { if(tcp == j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
if(tcp->POC != 1) if(tcp->POC != 1)
@ -1739,7 +1740,8 @@ void xml_out_frame_poc(FILE* xmlout, opj_tcp_t *tcp) { /* Progression Order Chan
/* Suppress PPM and PPT since we're not showing data from the third option, namely within the codestream, and /* Suppress PPM and PPT since we're not showing data from the third option, namely within the codestream, and
that's evidently what frames_to_mj2 uses. And a hex dump isn't so useful anyway */ that's evidently what frames_to_mj2 uses. And a hex dump isn't so useful anyway */
void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) { /* For main header, not tile-part (which uses PPT instead). */ void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) /* For main header, not tile-part (which uses PPT instead). */
{
/* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */ /* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Use of PPM and PPT are mutually exclusive. */ /* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppm() */ /* Compare j2k_read_ppm() */
@ -1770,7 +1772,8 @@ void xml_out_frame_ppm(FILE *xmlout, opj_cp_t *cp) { /* For main header, not til
/* ------------- */ /* ------------- */
void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) { /* For tile-part header, not main (which uses PPM instead). */ void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) /* For tile-part header, not main (which uses PPM instead). */
{
/* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */ /* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Use of PPM and PPT are mutually exclusive. */ /* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppt() */ /* Compare j2k_read_ppt() */
@ -1803,7 +1806,8 @@ void xml_out_frame_ppt(FILE *xmlout, opj_tcp_t *tcp) { /* For tile-part header,
/* ------------- */ /* ------------- */
void xml_out_frame_tlm(FILE* xmlout) { /* opt, main header only. May be multiple. */ void xml_out_frame_tlm(FILE* xmlout) /* opt, main header only. May be multiple. */
{
/* Compare j2k_read_tlm()... which doesn't retain anything! */ /* Compare j2k_read_tlm()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */ /* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
/* Main header indents are 10 spaces */ /* Main header indents are 10 spaces */
@ -1811,7 +1815,8 @@ void xml_out_frame_tlm(FILE* xmlout) { /* opt, main header only. May be multipl
/* ------------- */ /* ------------- */
void xml_out_frame_plm(FILE* xmlout) { /* opt, main header only; can be used in conjunction with tile-part's PLT */ void xml_out_frame_plm(FILE* xmlout) /* opt, main header only; can be used in conjunction with tile-part's PLT */
{
/* NO-OP. PLM NOT SAVED IN DATA STRUCTURE */ /* NO-OP. PLM NOT SAVED IN DATA STRUCTURE */
/* Compare j2k_read_plm()... which doesn't retain anything! */ /* Compare j2k_read_plm()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */ /* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
@ -1820,7 +1825,8 @@ void xml_out_frame_plm(FILE* xmlout) { /* opt, main header only; can be used in
/* ------------- */ /* ------------- */
void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) { /* opt, tile-part headers only; can be used in conjunction with main header's PLM */ void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) /* opt, tile-part headers only; can be used in conjunction with main header's PLM */
{
/* NO-OP. PLT NOT SAVED IN DATA STRUCTURE */ /* NO-OP. PLT NOT SAVED IN DATA STRUCTURE */
/* Compare j2k_read_plt()... which doesn't retain anything! */ /* Compare j2k_read_plt()... which doesn't retain anything! */
/* Tile-part header indents are 12 spaces */ /* Tile-part header indents are 12 spaces */
@ -1828,11 +1834,14 @@ void xml_out_frame_plt(FILE* xmlout, opj_tcp_t *tcp) { /* opt, tile-part headers
/* ------------- */ /* ------------- */
void xml_out_frame_crg(FILE* xmlout) { /* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */ void xml_out_frame_crg(FILE* xmlout)
{
/* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */
/* Compare j2k_read_crg()... which doesn't retain anything! */ /* Compare j2k_read_crg()... which doesn't retain anything! */
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */ /* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */
#ifdef NOTYET #ifdef NOTYET
THIS PSEUDOCODE IMAGINES THESE EXIST: j2k_default_tcp->crg, j2k_default_tcp->crg_i, j2k_default_tcp->crg_xcrg*, j2k_default_tcp->crg_ycrg* THIS PSEUDOCODE IMAGINES THESE EXIST:
j2k_default_tcp->crg, j2k_default_tcp->crg_i, j2k_default_tcp->crg_xcrg*, j2k_default_tcp->crg_ycrg*
(POSSIBLY DON'T NEED crg_i, CAN GET NUMBER OR COMPONENTS FROM ELSEWHERE) (POSSIBLY DON'T NEED crg_i, CAN GET NUMBER OR COMPONENTS FROM ELSEWHERE)
if(j2k_default_tcp->crg != 1 || j2k_default_tcp->crg_i == 0) if(j2k_default_tcp->crg != 1 || j2k_default_tcp->crg_i == 0)
return; /* Not present */ return; /* Not present */
@ -1875,15 +1884,19 @@ void xml_out_frame_crg(FILE* xmlout) { /* NO-OP. CRG NOT SAVED IN DATA STRUCTUR
/* ------------- */ /* ------------- */
/* Regrettably from a metadata point of view, j2k_read_com() skips over any comments in main header or tile-part-header */ /* Regrettably from a metadata point of view, j2k_read_com() skips over any comments in main header or tile-part-header */
void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp) { /* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */ void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp)
{
/* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */
/* Compare j2k_read_com()... which doesn't retain anything! */ /* Compare j2k_read_com()... which doesn't retain anything! */
#ifdef NOTYET #ifdef NOTYET
char spaces[13] = " "; /* 12 spaces if tilepart*/ char spaces[13] = " "; /* 12 spaces if tilepart*/
char* s = spaces; char* s = spaces;
if(tcp == &j2k_default_tcp) { if(tcp == &j2k_default_tcp) {
s++;s++; /* shorten s to 10 spaces if main */ s++;
s++; /* shorten s to 10 spaces if main */
} }
THIS PSEUDOCODE IMAGINES THESE EXIST: tcp->com, tcp->com_len, tcp->com_data array THIS PSEUDOCODE IMAGINES THESE EXIST:
tcp->com, tcp->com_len, tcp->com_data array
if(tcp->com != 1) if(tcp->com != 1)
return; /* Not present */ return; /* Not present */
@ -1893,7 +1906,8 @@ void xml_out_frame_com(FILE* xmlout, opj_tcp_t *tcp) { /* NO-OP. COM NOT SAVED
#endif #endif
} }
void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s) { void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s)
{
/* s is a string of spaces for indent */ /* s is a string of spaces for indent */
int i; int i;
@ -1909,7 +1923,8 @@ void xml_out_dump_hex(FILE* xmlout, char *data, int data_len, char* s) {
/* Define this as an even number: */ /* Define this as an even number: */
#define BYTES_PER_DUMP_LINE 40 #define BYTES_PER_DUMP_LINE 40
/* Current total width for Hex and ASCII is : 11 spaces lead + (3 * BPDL) + 2 spaces + BPDL */ /* Current total width for Hex and ASCII is : 11 spaces lead + (3 * BPDL) + 2 spaces + BPDL */
void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s) { void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s)
{
/* s is a string of spaces for indent */ /* s is a string of spaces for indent */
int i,j; int i,j;
@ -1944,7 +1959,8 @@ void xml_out_dump_hex_and_ascii(FILE* xmlout, char *data, int data_len, char* s)
/* ------------- */ /* ------------- */
void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) /* JP2 Header */
{
/* Compare jp2_read_jp2h(opj_jp2_t * jp2_struct) */ /* Compare jp2_read_jp2h(opj_jp2_t * jp2_struct) */
int i; int i;
@ -1987,8 +2003,7 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
fprintf(xmlout, " <!-- IPR is 1 if frame contains an Intellectual Property box; 0 otherwise. -->\n"); /* 2 bytes */ fprintf(xmlout, " <!-- IPR is 1 if frame contains an Intellectual Property box; 0 otherwise. -->\n"); /* 2 bytes */
fprintf(xmlout, " </ImageHeader>\n"); fprintf(xmlout, " </ImageHeader>\n");
if (jp2_struct->bpc == 255) if (jp2_struct->bpc == 255) {
{
fprintf(xmlout, " <BitsPerComponent BoxType=\"bpcc\">\n"); fprintf(xmlout, " <BitsPerComponent BoxType=\"bpcc\">\n");
if(notes) if(notes)
fprintf(xmlout, " <!-- Pixel depth (range 1 to 38) is low 7 bits of hex value + 1 -->\n"); fprintf(xmlout, " <!-- Pixel depth (range 1 to 38) is low 7 bits of hex value + 1 -->\n");
@ -2029,9 +2044,7 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
fprintf(xmlout, " <!-- 18: sRGB YCC (from JPEG 2000 Part II). -->\n"); fprintf(xmlout, " <!-- 18: sRGB YCC (from JPEG 2000 Part II). -->\n");
fprintf(xmlout, " <!-- (Additional JPX values are defined in Part II). -->\n"); fprintf(xmlout, " <!-- (Additional JPX values are defined in Part II). -->\n");
} }
} } else if(notes)
else
if(notes)
fprintf(xmlout, " <!-- PROFILE is not handled by current OpenJPEG implementation. -->\n"); fprintf(xmlout, " <!-- PROFILE is not handled by current OpenJPEG implementation. -->\n");
/* only 1 byte is read and nothing stored */ /* only 1 byte is read and nothing stored */
fprintf(xmlout, " </ColourSpecification>\n"); fprintf(xmlout, " </ColourSpecification>\n");
@ -2048,15 +2061,15 @@ void xml_out_frame_jp2h(FILE* xmlout, opj_jp2_t *jp2_struct) { /* JP2 Header */
#ifdef NOTYET #ifdef NOTYET
IMAGE these use cp structure, extended... but we could use a new data structure instead IMAGE these use cp structure, extended... but we could use a new data structure instead
void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp) { void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp)
{
/* IntellectualProperty 'jp2i' (no restrictions on location) */ /* IntellectualProperty 'jp2i' (no restrictions on location) */
int i; int i;
IMAGE cp->jp2i, cp->jp2i_count, cp->jp2i_data (array of chars), cp->cp2i_len (array of ints) IMAGE cp->jp2i, cp->jp2i_count, cp->jp2i_data (array of chars), cp->cp2i_len (array of ints)
if(cp->jp2i != 1) if(cp->jp2i != 1)
return; /* Not present */ return; /* Not present */
for(i = 0; i < cp->jp2i_count; i++) for(i = 0; i < cp->jp2i_count; i++) {
{
fprintf(xmlout, " <IntellectualProperty BoxType=\"jp2i\">\n"); fprintf(xmlout, " <IntellectualProperty BoxType=\"jp2i\">\n");
/* I think this can be anything, including binary, so do a dump */ /* I think this can be anything, including binary, so do a dump */
/* Is it better to indent or not indent this content? Indent is better for reading, but /* Is it better to indent or not indent this content? Indent is better for reading, but
@ -2066,7 +2079,8 @@ void xml_out_frame_jp2i(FILE* xmlout, opj_cp_t *cp) {
} }
} }
void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp) { void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp)
{
/* XML 'xml\040' (0x786d6c20). Can appear multiply, before or after jp2c codestreams */ /* XML 'xml\040' (0x786d6c20). Can appear multiply, before or after jp2c codestreams */
IMAGE cp->xml, cp->xml_count, cp->xml_data (array of chars) IMAGE cp->xml, cp->xml_count, cp->xml_data (array of chars)
MAYBE WE DON'T NEED cp->xml_len (array of ints) IF WE ASSUME xml_data IS NULL-TERMINATED. MAYBE WE DON'T NEED cp->xml_len (array of ints) IF WE ASSUME xml_data IS NULL-TERMINATED.
@ -2085,7 +2099,8 @@ void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp) {
} }
} }
void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp) { void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp)
{
/* UUID 'uuid' (top level only) */ /* UUID 'uuid' (top level only) */
/* Part I 1.7.2 says: may appear multiply in JP2 file, anywhere except before File Type box */ /* Part I 1.7.2 says: may appear multiply in JP2 file, anywhere except before File Type box */
/* Part III 5.2.1 says: Private extensions shall be achieved through the 'uuid' type. */ /* Part III 5.2.1 says: Private extensions shall be achieved through the 'uuid' type. */

View File

@ -23,21 +23,24 @@ can be bound by the Open JPEG open-source license and disclaimer, expressed else
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg); fprintf(stream, "[INFO] %s", msg);
} }
@ -107,7 +110,8 @@ void help_display()
/* ------------- */ /* ------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
opj_dinfo_t* dinfo; opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
@ -138,7 +142,9 @@ int main(int argc, char *argv[]) {
case 'i': /* IN file */ case 'i': /* IN file */
infile = optarg; infile = optarg;
s = optarg; s = optarg;
while (*s) { s++; } /* Run to filename end */ while (*s) {
s++; /* Run to filename end */
}
s--; s--;
S3 = *s; S3 = *s;
s--; s--;
@ -156,7 +162,9 @@ int main(int argc, char *argv[]) {
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* OUT file */ case 'o': /* OUT file */
outfile = optarg; outfile = optarg;
while (*outfile) { outfile++; } /* Run to filename end */ while (*outfile) {
outfile++; /* Run to filename end */
}
outfile--; outfile--;
S3 = *outfile; S3 = *outfile;
outfile--; outfile--;
@ -244,8 +252,7 @@ int main(int argc, char *argv[]) {
} }
*/ */
len = strlen(infile); len = strlen(infile);
if(infile[0] == ' ') if(infile[0] == ' ') {
{
infile++; /* There may be a leading blank if user put space after -i */ infile++; /* There may be a leading blank if user put space after -i */
} }
@ -257,8 +264,7 @@ int main(int argc, char *argv[]) {
} }
len = strlen(outfile); len = strlen(outfile);
if(outfile[0] == ' ') if(outfile[0] == ' ') {
{
outfile++; /* There may be a leading blank if user put space after -o */ outfile++; /* There may be a leading blank if user put space after -o */
} }
@ -289,8 +295,7 @@ int main(int argc, char *argv[]) {
movie = (opj_mj2_t*) dinfo->mj2_handle; movie = (opj_mj2_t*) dinfo->mj2_handle;
mj2_setup_decoder(dinfo->mj2_handle, &parameters); mj2_setup_decoder(dinfo->mj2_handle, &parameters);
if (mj2_read_struct(file, movie)) // Creating the movie structure if (mj2_read_struct(file, movie)) { // Creating the movie structure
{
fclose(xmlout); fclose(xmlout);
return 1; return 1;
} }

View File

@ -50,14 +50,16 @@ Size of memory first allocated for MOOV box
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
@ -285,8 +287,7 @@ int main(int argc, char **argv)
if (c == -1) if (c == -1)
break; break;
switch (c) { switch (c) {
case 'i': /* IN fill */ case 'i': { /* IN fill */
{
char *infile = opj_optarg; char *infile = opj_optarg;
s = opj_optarg; s = opj_optarg;
while (*s) { while (*s) {
@ -302,8 +303,7 @@ int main(int argc, char **argv)
if ((S1 == 'y' && S2 == 'u' && S3 == 'v') if ((S1 == 'y' && S2 == 'u' && S3 == 'v')
|| (S1 == 'Y' && S2 == 'U' && S3 == 'V')) { || (S1 == 'Y' && S2 == 'U' && S3 == 'V')) {
mj2_parameters.decod_format = YUV_DFMT; mj2_parameters.decod_format = YUV_DFMT;
} } else {
else {
fprintf(stderr, fprintf(stderr,
"!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n", "!! Unrecognized format for infile : %c%c%c [accept only *.yuv] !!\n\n",
S1, S2, S3); S1, S2, S3);
@ -313,8 +313,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'o': /* OUT fill */ case 'o': { /* OUT fill */
{
char *outfile = opj_optarg; char *outfile = opj_optarg;
while (*outfile) { while (*outfile) {
outfile++; outfile++;
@ -341,8 +340,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'r': /* rates rates/distorsion */ case 'r': { /* rates rates/distorsion */
{
float rate; float rate;
s = opj_optarg; s = opj_optarg;
while (sscanf(s, "%f", &rate) == 1) { while (sscanf(s, "%f", &rate) == 1) {
@ -374,8 +372,7 @@ int main(int argc, char **argv)
break; break;
/* dda */ /* dda */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'f': /* mod fixed_quality (before : -q) */ case 'f': { /* mod fixed_quality (before : -q) */
{
int *row = NULL, *col = NULL; int *row = NULL, *col = NULL;
int numlayers = 0, numresolution = 0, matrix_width = 0; int numlayers = 0, numresolution = 0, matrix_width = 0;
@ -428,8 +425,7 @@ int main(int argc, char **argv)
sscanf(opj_optarg, "%d", &j2k_parameters->numresolution); sscanf(opj_optarg, "%d", &j2k_parameters->numresolution);
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'c': /* precinct dimension */ case 'c': { /* precinct dimension */
{
char sep; char sep;
int res_spec = 0; int res_spec = 0;
@ -441,15 +437,13 @@ int main(int argc, char **argv)
j2k_parameters->csty |= 0x01; j2k_parameters->csty |= 0x01;
res_spec++; res_spec++;
s = strpbrk(s, "]") + 2; s = strpbrk(s, "]") + 2;
} } while (sep == ',');
while (sep == ',');
j2k_parameters->res_spec = res_spec; j2k_parameters->res_spec = res_spec;
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'b': /* code-block dimension */ case 'b': { /* code-block dimension */
{
int cblockw_init = 0, cblockh_init = 0; int cblockw_init = 0, cblockh_init = 0;
sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init);
if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024
@ -464,8 +458,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'p': /* progression order */ case 'p': { /* progression order */
{
char progression[5]; char progression[5];
strncpy(progression, opj_optarg, 5); strncpy(progression, opj_optarg, 5);
@ -478,8 +471,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 's': /* subsampling factor */ case 's': { /* subsampling factor */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx, if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->subsampling_dx,
&j2k_parameters->subsampling_dy) != 2) { &j2k_parameters->subsampling_dy) != 2) {
fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n");
@ -488,8 +480,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'd': /* coordonnate of the reference grid */ case 'd': { /* coordonnate of the reference grid */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0, if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->image_offset_x0,
&j2k_parameters->image_offset_y0) != 2) { &j2k_parameters->image_offset_y0) != 2) {
fprintf(stderr, "-d 'coordonnate of the reference grid' argument " fprintf(stderr, "-d 'coordonnate of the reference grid' argument "
@ -504,8 +495,7 @@ int main(int argc, char **argv)
return 0; return 0;
break; break;
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
case 'P': /* POC */ case 'P': { /* POC */
{
int numpocs = 0; /* number of progression order change (POC) default 0 */ int numpocs = 0; /* number of progression order change (POC) default 0 */
opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */
@ -548,8 +538,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'R': /* ROI */ case 'R': { /* ROI */
{
if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno, if (sscanf(opj_optarg, "OI:c=%d,U=%d", &j2k_parameters->roi_compno,
&j2k_parameters->roi_shift) != 2) { &j2k_parameters->roi_shift) != 2) {
fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n"); fprintf(stderr, "ROI error !! [-ROI:c='compno',U='shift']\n");
@ -558,8 +547,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'T': /* Tile offset */ case 'T': { /* Tile offset */
{
if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) { if (sscanf(opj_optarg, "%d,%d", &j2k_parameters->cp_tx0, &j2k_parameters->cp_ty0) != 2) {
fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]");
return 1; return 1;
@ -567,8 +555,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'C': /* Add a comment */ case 'C': { /* Add a comment */
{
j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); j2k_parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1);
if(j2k_parameters->cp_comment) { if(j2k_parameters->cp_comment) {
strcpy(j2k_parameters->cp_comment, opj_optarg); strcpy(j2k_parameters->cp_comment, opj_optarg);
@ -576,8 +563,7 @@ int main(int argc, char **argv)
} }
break; break;
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'I': /* reversible or not */ case 'I': { /* reversible or not */
{
j2k_parameters->irreversible = 1; j2k_parameters->irreversible = 1;
} }
break; break;
@ -614,8 +600,7 @@ int main(int argc, char **argv)
"Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]); "Usage: %s -i yuv-file -o mj2-file (+ options)\n",argv[0]);
return 1; return 1;
} }
if(prec < 1 || prec > 16) if(prec < 1 || prec > 16) {
{
fprintf(stderr, "Error: Depth %d must be in the range 8 .. 16\n",prec); fprintf(stderr, "Error: Depth %d must be in the range 8 .. 16\n",prec);
return 1; return 1;
} }
@ -723,14 +708,10 @@ int main(int argc, char **argv)
opj_cio_close(cio); opj_cio_close(cio);
free(buf); free(buf);
for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++) for(i = 0; i < movie->num_stk + movie->num_htk + movie->num_vtk; i++) {
{ if(movie->tk[i].track_type != 0) {
if(movie->tk[i].track_type != 0)
{
fprintf(stderr, "Unable to write sound or hint tracks\n"); fprintf(stderr, "Unable to write sound or hint tracks\n");
} } else {
else
{
mj2_tk_t *tk; mj2_tk_t *tk;
int buflen = 0; int buflen = 0;
@ -746,14 +727,12 @@ int main(int argc, char **argv)
buflen = 2 * (tk->w * tk->h * 8); buflen = 2 * (tk->w * tk->h * 8);
buf = (unsigned char *) malloc(buflen*sizeof(unsigned char)); buf = (unsigned char *) malloc(buflen*sizeof(unsigned char));
for(sampleno = 0; sampleno < numframes; sampleno++) for(sampleno = 0; sampleno < numframes; sampleno++) {
{
double init_time = opj_clock(); double init_time = opj_clock();
double elapsed_time; double elapsed_time;
if(yuvtoimage(tk, img, sampleno, j2k_parameters, if(yuvtoimage(tk, img, sampleno, j2k_parameters,
mj2_parameters.infile)) mj2_parameters.infile)) {
{
fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno); fprintf(stderr, "Error with frame number %d in YUV file\n", sampleno);
return 1; return 1;
} }

View File

@ -50,14 +50,16 @@
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
@ -65,7 +67,8 @@ static void warning_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
mj2_dparameters_t mj2_parameters; /* decompression parameters */ mj2_dparameters_t mj2_parameters; /* decompression parameters */
opj_dinfo_t* dinfo; opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
@ -150,8 +153,7 @@ int main(int argc, char *argv[]) {
numframes = track->num_samples; numframes = track->num_samples;
for (snum=0; snum < numframes; snum++) for (snum=0; snum < numframes; snum++) {
{
double init_time = opj_clock(); double init_time = opj_clock();
double elapsed_time; double elapsed_time;
@ -173,20 +175,19 @@ int main(int argc, char *argv[]) {
img = opj_decode(dinfo, cio); /* Decode J2K to image */ img = opj_decode(dinfo, cio); /* Decode J2K to image */
#ifdef WANT_SYCC_TO_RGB #ifdef WANT_SYCC_TO_RGB
if(img->color_space == CLRSPC_SYCC) if(img->color_space == CLRSPC_SYCC) {
{
color_sycc_to_rgb(img); color_sycc_to_rgb(img);
} }
#endif #endif
if(img->icc_profile_buf) if(img->icc_profile_buf) {
{
#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2)
color_apply_icc_profile(img); color_apply_icc_profile(img);
#endif #endif
free(img->icc_profile_buf); free(img->icc_profile_buf);
img->icc_profile_buf = NULL; img->icc_profile_len = 0; img->icc_profile_buf = NULL;
img->icc_profile_len = 0;
} }
if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2) if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2)
@ -195,18 +196,15 @@ int main(int argc, char *argv[]) {
if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */ if (!imagetoyuv(img, argv[2])) /* Convert image to YUV */
return 1; return 1;
} } else if ((img->numcomps == 3) &&
else if ((img->numcomps == 3) &&
(img->comps[0].dx == 1) && (img->comps[1].dx == 1)&& (img->comps[0].dx == 1) && (img->comps[1].dx == 1)&&
(img->comps[2].dx == 1))/* If YUV 4:4:4 input --> to bmp */ (img->comps[2].dx == 1)) { /* If YUV 4:4:4 input --> to bmp */
{
fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n"); fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
sprintf(outfilename,"output_%d.bmp",snum); sprintf(outfilename,"output_%d.bmp",snum);
if (imagetobmp(img, outfilename)) /* Convert image to BMP */ if (imagetobmp(img, outfilename)) /* Convert image to BMP */
return 1; return 1;
} } else {
else {
fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n"); fprintf(stdout,"Image component dimensions are unknown. Unable to output image\n");
fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n"); fprintf(stdout,"The frames will be output in a j2k file (output_1.j2k, ...)\n");

View File

@ -46,21 +46,24 @@
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
void error_callback(const char *msg, void *client_data) { void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
void warning_callback(const char *msg, void *client_data) { void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
void info_callback(const char *msg, void *client_data) { void info_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg); fprintf(stream, "[INFO] %s", msg);
} }
@ -68,7 +71,8 @@ void info_callback(const char *msg, void *client_data) {
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
opj_dinfo_t* dinfo; opj_dinfo_t* dinfo;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
int tnum; int tnum;
@ -126,8 +130,7 @@ int main(int argc, char *argv[]) {
fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples); fprintf(stdout,"Extracting %d frames from file...\n",track->num_samples);
for (snum=0; snum < track->num_samples; snum++) for (snum=0; snum < track->num_samples; snum++) {
{
sample = &track->sample[snum]; sample = &track->sample[snum];
frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/ frame_codestream = (unsigned char*) malloc (sample->sample_size-8); /* Skipping JP2C marker*/
fseek(file,sample->offset+8,SEEK_SET); fseek(file,sample->offset+8,SEEK_SET);

View File

@ -41,7 +41,8 @@
#include "jp2.h" #include "jp2.h"
#include "mj2.h" #include "mj2.h"
static int int_ceildiv(int a, int b) { static int int_ceildiv(int a, int b)
{
return (a + b - 1) / b; return (a + b - 1) / b;
} }
@ -76,9 +77,9 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
fread(src, 1, src_len, reader); fread(src, 1, src_len, reader);
fclose(reader); fclose(reader);
if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) if(memcmp(src, J2K_CODESTREAM_MAGIC, 4) != 0) {
{ free(src);
free(src); return success; return success;
} }
memset(&dparameters, 0, sizeof(opj_dparameters_t)); memset(&dparameters, 0, sizeof(opj_dparameters_t));
@ -92,7 +93,8 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
image = opj_decode(dinfo, cio); image = opj_decode(dinfo, cio);
free(src); cio->buffer = NULL; free(src);
cio->buffer = NULL;
opj_cio_close(cio); opj_cio_close(cio);
if(image == NULL) goto fin; if(image == NULL) goto fin;
@ -102,75 +104,59 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
cp->h = image->comps[0].h; cp->h = image->comps[0].h;
cp->prec = image->comps[0].prec; cp->prec = image->comps[0].prec;
if(image->numcomps > 2 ) if(image->numcomps > 2 ) {
{
if((image->comps[0].dx == 1) if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2) && (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2) && (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1) && (image->comps[0].dy == 1)
&& (image->comps[1].dy == 2) && (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2))/* horizontal and vertical*/ && (image->comps[2].dy == 2)) { /* horizontal and vertical*/
{
/* Y420*/ /* Y420*/
cp->enumcs = ENUMCS_SYCC; cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2; cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 2; cp->CbCr_subsampling_dy = 2;
} } else if((image->comps[0].dx == 1)
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2) && (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2) && (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1) && (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1) && (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1))/* horizontal only*/ && (image->comps[2].dy == 1)) { /* horizontal only*/
{
/* Y422*/ /* Y422*/
cp->enumcs = ENUMCS_SYCC; cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 2; cp->CbCr_subsampling_dx = 2;
cp->CbCr_subsampling_dy = 1; cp->CbCr_subsampling_dy = 1;
} } else if((image->comps[0].dx == 1)
else
if((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1) && (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1) && (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1) && (image->comps[0].dy == 1)
&& (image->comps[1].dy == 1) && (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1)) && (image->comps[2].dy == 1)) {
{
/* Y444 or RGB */ /* Y444 or RGB */
if(image->color_space == CLRSPC_SRGB) if(image->color_space == CLRSPC_SRGB) {
{
cp->enumcs = ENUMCS_SRGB; cp->enumcs = ENUMCS_SRGB;
/* cp->CbCr_subsampling_dx = 0; */ /* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */ /* cp->CbCr_subsampling_dy = 0; */
} } else {
else
{
cp->enumcs = ENUMCS_SYCC; cp->enumcs = ENUMCS_SYCC;
cp->CbCr_subsampling_dx = 1; cp->CbCr_subsampling_dx = 1;
cp->CbCr_subsampling_dy = 1; cp->CbCr_subsampling_dy = 1;
} }
} } else {
else
{
goto fin; goto fin;
} }
} } else {
else
{
cp->enumcs = ENUMCS_GRAY; cp->enumcs = ENUMCS_GRAY;
/* cp->CbCr_subsampling_dx = 0; */ /* cp->CbCr_subsampling_dx = 0; */
/* cp->CbCr_subsampling_dy = 0; */ /* cp->CbCr_subsampling_dy = 0; */
} }
if(image->icc_profile_buf) if(image->icc_profile_buf) {
{
cp->meth = 2; cp->meth = 2;
free(image->icc_profile_buf); image->icc_profile_buf = NULL; free(image->icc_profile_buf);
} image->icc_profile_buf = NULL;
else cp->meth = 1; } else cp->meth = 1;
success = 1; success = 1;
fin: fin:
@ -186,21 +172,24 @@ fin:
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting a FILE* client object sample debug callback expecting a FILE* client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[INFO] %s", msg); fprintf(stream, "[INFO] %s", msg);
} }
@ -221,8 +210,7 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
fread(&buf,1,1, file); fread(&buf,1,1, file);
if (buf==(char)0xff) if (buf==(char)0xff)
fread(&buf,1,1, file); fread(&buf,1,1, file);
} } while (!(buf==(char)0x51));
while (!(buf==(char)0x51));
fread(buf2,2,1,file); /* Lsiz */ fread(buf2,2,1,file); /* Lsiz */
len = ((buf2[0])<<8) + buf2[1]; len = ((buf2[0])<<8) + buf2[1];
@ -257,7 +245,8 @@ static void read_siz_marker(FILE *file, opj_image_t *image)
free(siz_buffer); free(siz_buffer);
} }
static void setparams(opj_mj2_t *movie, opj_image_t *image) { static void setparams(opj_mj2_t *movie, opj_image_t *image)
{
int i, depth_0, depth, sign; int i, depth_0, depth, sign;
movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx); movie->tk[0].w = int_ceildiv(image->x1 - image->x0, image->comps[0].dx);
@ -271,8 +260,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
&& (image->comps[1].dx == 1) && (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1)) && (image->comps[2].dx == 1))
movie->tk[0].CbCr_subsampling_dx = 1; movie->tk[0].CbCr_subsampling_dx = 1;
else else if ((image->comps[0].dx == 1)
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2) && (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2)) && (image->comps[2].dx == 2))
movie->tk[0].CbCr_subsampling_dx = 2; movie->tk[0].CbCr_subsampling_dx = 2;
@ -283,8 +271,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
&& (image->comps[1].dy == 1) && (image->comps[1].dy == 1)
&& (image->comps[2].dy == 1)) && (image->comps[2].dy == 1))
movie->tk[0].CbCr_subsampling_dy = 1; movie->tk[0].CbCr_subsampling_dy = 1;
else else if ((image->comps[0].dy == 1)
if ((image->comps[0].dy == 1)
&& (image->comps[1].dy == 2) && (image->comps[1].dy == 2)
&& (image->comps[2].dy == 2)) && (image->comps[2].dy == 2))
movie->tk[0].CbCr_subsampling_dy = 2; movie->tk[0].CbCr_subsampling_dy = 2;
@ -337,8 +324,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
if (image->numcomps == 1) if (image->numcomps == 1)
movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */ movie->tk[0].jp2_struct.enumcs = 17; /* Grayscale */
else else if ((image->comps[0].dx == 1)
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 1) && (image->comps[1].dx == 1)
&& (image->comps[2].dx == 1) && (image->comps[2].dx == 1)
&& (image->comps[0].dy == 1) && (image->comps[0].dy == 1)
@ -346,8 +332,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
&& (image->comps[2].dy == 1)) && (image->comps[2].dy == 1))
movie->tk[0].jp2_struct.enumcs = 16; /* RGB */ movie->tk[0].jp2_struct.enumcs = 16; /* RGB */
else else if ((image->comps[0].dx == 1)
if ((image->comps[0].dx == 1)
&& (image->comps[1].dx == 2) && (image->comps[1].dx == 2)
&& (image->comps[2].dx == 2) && (image->comps[2].dx == 2)
&& (image->comps[0].dy == 1) && (image->comps[0].dy == 1)
@ -359,7 +344,8 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */ movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
{
opj_cinfo_t* cinfo; opj_cinfo_t* cinfo;
opj_event_mgr_t event_mgr; /* event manager */ opj_event_mgr_t event_mgr; /* event manager */
unsigned int snum; unsigned int snum;
@ -432,8 +418,7 @@ int main(int argc, char *argv[]) {
/* Insert each j2k codestream in a JP2C box */ /* Insert each j2k codestream in a JP2C box */
snum=0; snum=0;
offset = 0; offset = 0;
while(1) while(1) {
{
mj2_sample_t * new_sample; mj2_sample_t * new_sample;
mj2_chunk_t * new_chunk; mj2_chunk_t * new_chunk;
sample = &movie->tk[0].sample[snum]; sample = &movie->tk[0].sample[snum];
@ -443,8 +428,7 @@ int main(int argc, char *argv[]) {
if (snum==0) { /* Could not open a single codestream */ if (snum==0) { /* Could not open a single codestream */
fprintf(stderr, "failed to open %s for reading\n",j2kfilename); fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
return 1; return 1;
} } else { /* Tried to open a inexistant codestream */
else { /* Tried to open a inexistant codestream */
fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum); fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
break; break;
} }

View File

@ -184,13 +184,23 @@ class OPJViewerApp: public wxApp
public: public:
// class constructor // class constructor
OPJViewerApp() { m_showImages = true; m_showButtons = false; } OPJViewerApp()
{
m_showImages = true;
m_showButtons = false;
}
// other methods // other methods
bool OnInit(void); bool OnInit(void);
int OnExit(void); int OnExit(void);
void SetShowImages(bool show) { m_showImages = show; } void SetShowImages(bool show)
bool ShowImages() const { return m_showImages; } {
m_showImages = show;
}
bool ShowImages() const
{
return m_showImages;
}
void ShowCmdLine(const wxCmdLineParser& parser); void ShowCmdLine(const wxCmdLineParser& parser);
// all the threads currently alive - as soon as the thread terminates, it's // all the threads currently alive - as soon as the thread terminates, it's
@ -265,7 +275,8 @@ class OPJCanvas: public wxScrolledWindow
virtual void OnDraw(wxDC& dc); virtual void OnDraw(wxDC& dc);
void OnEvent(wxMouseEvent& event); void OnEvent(wxMouseEvent& event);
void WriteText(const wxString& text) { void WriteText(const wxString& text)
{
#ifndef __WXGTK__ #ifndef __WXGTK__
wxMutexGuiEnter(); wxMutexGuiEnter();
#endif //__WXGTK__ #endif //__WXGTK__
@ -299,11 +310,21 @@ class OPJMarkerData : public wxTreeItemData
public: public:
// class constructor // class constructor
OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname) { m_start = start; m_length = length; } OPJMarkerData(const wxString& desc, const wxString& fname = wxT(""), wxFileOffset start = 0, wxFileOffset length = 0) : m_desc(desc), m_filestring(fname)
{
m_start = start;
m_length = length;
}
void ShowInfo(wxTreeCtrl *tree); void ShowInfo(wxTreeCtrl *tree);
const wxChar *GetDesc1() const { return m_desc.c_str(); } const wxChar *GetDesc1() const
const wxChar *GetDesc2() const { return m_filestring.c_str(); } {
return m_desc.c_str();
}
const wxChar *GetDesc2() const
{
return m_filestring.c_str();
}
wxFileOffset m_start, m_length; wxFileOffset m_start, m_length;
wxString m_desc; wxString m_desc;
@ -316,8 +337,7 @@ class OPJMarkerData : public wxTreeItemData
class OPJMarkerTree : public wxTreeCtrl class OPJMarkerTree : public wxTreeCtrl
{ {
public: public:
enum enum {
{
TreeCtrlIcon_File, TreeCtrlIcon_File,
TreeCtrlIcon_FileSelected, TreeCtrlIcon_FileSelected,
TreeCtrlIcon_Folder, TreeCtrlIcon_Folder,
@ -331,7 +351,12 @@ public:
long style); long style);
virtual ~OPJMarkerTree() {}; virtual ~OPJMarkerTree() {};
OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL); OPJParseThread *CreateParseThread(wxTreeItemId parentid = 0x00, OPJChildFrame *subframe = NULL);
void WriteText(const wxString& text) { wxMutexGuiEnter(); wxLogMessage(text); wxMutexGuiLeave(); } void WriteText(const wxString& text)
{
wxMutexGuiEnter();
wxLogMessage(text);
wxMutexGuiLeave();
}
wxFileName m_fname; wxFileName m_fname;
wxTextCtrl *m_peektextCtrl; wxTextCtrl *m_peektextCtrl;
@ -372,9 +397,15 @@ public:
/*void DoToggleIcon(const wxTreeItemId& item);*/ /*void DoToggleIcon(const wxTreeItemId& item);*/
/*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/ /*void ShowMenu(wxTreeItemId id, const wxPoint& pt);*/
int ImageSize(void) const { return m_imageSize; } int ImageSize(void) const
{
return m_imageSize;
}
void SetLastItem(wxTreeItemId id) { m_lastItem = id; } void SetLastItem(wxTreeItemId id)
{
m_lastItem = id;
}
protected: protected:
/*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/ /*virtual int OnCompareItems(const wxTreeItemId& i1, const wxTreeItemId& i2);*/
@ -541,8 +572,7 @@ enum {
// menu and control ids // menu and control ids
enum enum {
{
TreeTest_Quit = wxID_EXIT, TreeTest_Quit = wxID_EXIT,
TreeTest_About = wxID_ABOUT, TreeTest_About = wxID_ABOUT,
TreeTest_TogButtons = wxID_HIGHEST, TreeTest_TogButtons = wxID_HIGHEST,
@ -666,7 +696,10 @@ private:
class OPJDnDFile: public wxFileDropTarget class OPJDnDFile: public wxFileDropTarget
{ {
public: public:
OPJDnDFile(OPJFrame *pOwner) { m_pOwner = pOwner; } OPJDnDFile(OPJFrame *pOwner)
{
m_pOwner = pOwner;
}
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames); virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);
private: private:

View File

@ -78,7 +78,8 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio);
========================================================== ==========================================================
*/ */
static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) { static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff; bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
@ -88,7 +89,8 @@ static OPJ_BOOL opj_bio_byteout(opj_bio_t *bio) {
return OPJ_TRUE; return OPJ_TRUE;
} }
static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) { static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff; bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->ct = bio->buf == 0xff00 ? 7 : 8;
if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) { if ((OPJ_SIZE_T)bio->bp >= (OPJ_SIZE_T)bio->end) {
@ -98,7 +100,8 @@ static OPJ_BOOL opj_bio_bytein(opj_bio_t *bio) {
return OPJ_TRUE; return OPJ_TRUE;
} }
static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) { static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b)
{
if (bio->ct == 0) { if (bio->ct == 0) {
opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */ opj_bio_byteout(bio); /* MSD: why not check the return value of this function ? */
} }
@ -106,7 +109,8 @@ static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) {
bio->buf |= b << bio->ct; bio->buf |= b << bio->ct;
} }
static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) { static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio)
{
if (bio->ct == 0) { if (bio->ct == 0) {
opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */ opj_bio_bytein(bio); /* MSD: why not check the return value of this function ? */
} }
@ -120,22 +124,26 @@ static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) {
========================================================== ==========================================================
*/ */
opj_bio_t* opj_bio_create(void) { opj_bio_t* opj_bio_create(void)
{
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio; return bio;
} }
void opj_bio_destroy(opj_bio_t *bio) { void opj_bio_destroy(opj_bio_t *bio)
{
if(bio) { if(bio) {
opj_free(bio); opj_free(bio);
} }
} }
ptrdiff_t opj_bio_numbytes(opj_bio_t *bio) { ptrdiff_t opj_bio_numbytes(opj_bio_t *bio)
{
return (bio->bp - bio->start); return (bio->bp - bio->start);
} }
void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
{
bio->start = bp; bio->start = bp;
bio->end = bp + len; bio->end = bp + len;
bio->bp = bp; bio->bp = bp;
@ -143,7 +151,8 @@ void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
bio->ct = 8; bio->ct = 8;
} }
void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len)
{
bio->start = bp; bio->start = bp;
bio->end = bp + len; bio->end = bp + len;
bio->bp = bp; bio->bp = bp;
@ -151,14 +160,16 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
bio->ct = 0; bio->ct = 0;
} }
void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n)
{
OPJ_UINT32 i; OPJ_UINT32 i;
for (i = n - 1; i < n; i--) { for (i = n - 1; i < n; i--) {
opj_bio_putbit(bio, (v >> i) & 1); opj_bio_putbit(bio, (v >> i) & 1);
} }
} }
OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n)
{
OPJ_UINT32 i; OPJ_UINT32 i;
OPJ_UINT32 v; OPJ_UINT32 v;
v = 0; v = 0;
@ -168,7 +179,8 @@ OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) {
return v; return v;
} }
OPJ_BOOL opj_bio_flush(opj_bio_t *bio) { OPJ_BOOL opj_bio_flush(opj_bio_t *bio)
{
if (! opj_bio_byteout(bio)) { if (! opj_bio_byteout(bio)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -180,7 +192,8 @@ OPJ_BOOL opj_bio_flush(opj_bio_t *bio) {
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_BOOL opj_bio_inalign(opj_bio_t *bio) { OPJ_BOOL opj_bio_inalign(opj_bio_t *bio)
{
if ((bio->buf & 0xff) == 0xff) { if ((bio->buf & 0xff) == 0xff) {
if (! opj_bio_bytein(bio)) { if (! opj_bio_bytein(bio)) {
return OPJ_FALSE; return OPJ_FALSE;

View File

@ -219,10 +219,8 @@ OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, op
OPJ_OFF_T org_pos; OPJ_OFF_T org_pos;
unsigned int Scod; unsigned int Scod;
for(i = 0; i < marknum; i++) for(i = 0; i < marknum; i++) {
{ if( markers[i].type == J2K_MS_COD) {
if( markers[i].type == J2K_MS_COD)
{
org_pos = opj_stream_tell(cio); org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager); opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);

View File

@ -169,8 +169,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,OPJ_BOOL l
l_stream->m_status |= OPJ_STREAM_STATUS_INPUT; l_stream->m_status |= OPJ_STREAM_STATUS_INPUT;
l_stream->m_opj_skip = opj_stream_read_skip; l_stream->m_opj_skip = opj_stream_read_skip;
l_stream->m_opj_seek = opj_stream_read_seek; l_stream->m_opj_seek = opj_stream_read_seek;
} } else {
else {
l_stream->m_status |= OPJ_STREAM_STATUS_OUTPUT; l_stream->m_status |= OPJ_STREAM_STATUS_OUTPUT;
l_stream->m_opj_skip = opj_stream_write_skip; l_stream->m_opj_skip = opj_stream_write_skip;
l_stream->m_opj_seek = opj_stream_write_seek; l_stream->m_opj_seek = opj_stream_write_seek;
@ -294,8 +293,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer; p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
} } else {
else {
/* case where we are already at the end of the buffer /* case where we are already at the end of the buffer
so reset the m_current_data to point to the start of the so reset the m_current_data to point to the start of the
stored buffer to get ready to read from disk*/ stored buffer to get ready to read from disk*/
@ -316,8 +314,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
/* end of stream */ /* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1; return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} } else if (p_stream->m_bytes_in_buffer < p_size) {
else if (p_stream->m_bytes_in_buffer < p_size) {
/* not enough data */ /* not enough data */
l_read_nb_bytes += p_stream->m_bytes_in_buffer; l_read_nb_bytes += p_stream->m_bytes_in_buffer;
memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer); memcpy(p_buffer,p_stream->m_current_data,p_stream->m_bytes_in_buffer);
@ -326,8 +323,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer; p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
} } else {
else {
l_read_nb_bytes += p_size; l_read_nb_bytes += p_size;
memcpy(p_buffer,p_stream->m_current_data,p_size); memcpy(p_buffer,p_stream->m_current_data,p_size);
p_stream->m_current_data += p_size; p_stream->m_current_data += p_size;
@ -335,8 +331,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_byte_offset += (OPJ_OFF_T)p_size; p_stream->m_byte_offset += (OPJ_OFF_T)p_size;
return l_read_nb_bytes; return l_read_nb_bytes;
} }
} } else {
else {
/* direct read on the dest buffer */ /* direct read on the dest buffer */
p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer,p_size,p_stream->m_user_data); p_stream->m_bytes_in_buffer = p_stream->m_read_fn(p_buffer,p_size,p_stream->m_user_data);
@ -348,8 +343,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
/* end of stream */ /* end of stream */
return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1; return l_read_nb_bytes ? l_read_nb_bytes : (OPJ_SIZE_T)-1;
} } else if (p_stream->m_bytes_in_buffer < p_size) {
else if (p_stream->m_bytes_in_buffer < p_size) {
/* not enough data */ /* not enough data */
l_read_nb_bytes += p_stream->m_bytes_in_buffer; l_read_nb_bytes += p_stream->m_bytes_in_buffer;
p_stream->m_current_data = p_stream->m_stored_data; p_stream->m_current_data = p_stream->m_stored_data;
@ -357,8 +351,7 @@ OPJ_SIZE_T opj_stream_read_data (opj_stream_private_t * p_stream,OPJ_BYTE * p_bu
p_size -= p_stream->m_bytes_in_buffer; p_size -= p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
p_stream->m_bytes_in_buffer = 0; p_stream->m_bytes_in_buffer = 0;
} } else {
else {
/* we have read the exact size */ /* we have read the exact size */
l_read_nb_bytes += p_stream->m_bytes_in_buffer; l_read_nb_bytes += p_stream->m_bytes_in_buffer;
p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer; p_stream->m_byte_offset += (OPJ_OFF_T)p_stream->m_bytes_in_buffer;
@ -570,8 +563,7 @@ OPJ_BOOL opj_stream_read_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_size
if( !(p_stream->m_seek_fn(p_size,p_stream->m_user_data)) ) { if( !(p_stream->m_seek_fn(p_size,p_stream->m_user_data)) ) {
p_stream->m_status |= OPJ_STREAM_STATUS_END; p_stream->m_status |= OPJ_STREAM_STATUS_END;
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else {
/* reset stream status */ /* reset stream status */
p_stream->m_status &= (~OPJ_STREAM_STATUS_END); p_stream->m_status &= (~OPJ_STREAM_STATUS_END);
p_stream->m_byte_offset = p_size; p_stream->m_byte_offset = p_size;
@ -594,8 +586,7 @@ OPJ_BOOL opj_stream_write_seek (opj_stream_private_t * p_stream, OPJ_OFF_T p_siz
if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) { if (! p_stream->m_seek_fn(p_size,p_stream->m_user_data)) {
p_stream->m_status |= OPJ_STREAM_STATUS_ERROR; p_stream->m_status |= OPJ_STREAM_STATUS_ERROR;
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else {
p_stream->m_byte_offset = p_size; p_stream->m_byte_offset = p_size;
} }

View File

@ -78,8 +78,7 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/** /**
Byte input-output stream. Byte input-output stream.
*/ */
typedef struct opj_stream_private typedef struct opj_stream_private {
{
/** /**
* User data, be it files, ... The actual data depends on the type of the stream. * User data, be it files, ... The actual data depends on the type of the stream.
*/ */

View File

@ -193,7 +193,8 @@ static const OPJ_FLOAT64 opj_dwt_norms_real[4][10] = {
/* <summary> */ /* <summary> */
/* Forward lazy transform (horizontal). */ /* Forward lazy transform (horizontal). */
/* </summary> */ /* </summary> */
static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i; OPJ_INT32 i;
OPJ_INT32 * l_dest = b; OPJ_INT32 * l_dest = b;
OPJ_INT32 * l_src = a+cas; OPJ_INT32 * l_src = a+cas;
@ -215,7 +216,8 @@ static void opj_dwt_deinterleave_h(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
/* <summary> */ /* <summary> */
/* Forward lazy transform (vertical). */ /* Forward lazy transform (vertical). */
/* </summary> */ /* </summary> */
static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas) { static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 x, OPJ_INT32 cas)
{
OPJ_INT32 i = sn; OPJ_INT32 i = sn;
OPJ_INT32 * l_dest = b; OPJ_INT32 * l_dest = b;
OPJ_INT32 * l_src = a+cas; OPJ_INT32 * l_src = a+cas;
@ -240,7 +242,8 @@ static void opj_dwt_deinterleave_v(OPJ_INT32 *a, OPJ_INT32 *b, OPJ_INT32 dn, OPJ
/* <summary> */ /* <summary> */
/* Inverse lazy transform (horizontal). */ /* Inverse lazy transform (horizontal). */
/* </summary> */ /* </summary> */
static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) { static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a)
{
OPJ_INT32 *ai = a; OPJ_INT32 *ai = a;
OPJ_INT32 *bi = h->mem + h->cas; OPJ_INT32 *bi = h->mem + h->cas;
OPJ_INT32 i = h->sn; OPJ_INT32 i = h->sn;
@ -260,7 +263,8 @@ static void opj_dwt_interleave_h(opj_dwt_t* h, OPJ_INT32 *a) {
/* <summary> */ /* <summary> */
/* Inverse lazy transform (vertical). */ /* Inverse lazy transform (vertical). */
/* </summary> */ /* </summary> */
static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) { static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x)
{
OPJ_INT32 *ai = a; OPJ_INT32 *ai = a;
OPJ_INT32 *bi = v->mem + v->cas; OPJ_INT32 *bi = v->mem + v->cas;
OPJ_INT32 i = v->sn; OPJ_INT32 i = v->sn;
@ -283,7 +287,8 @@ static void opj_dwt_interleave_v(opj_dwt_t* v, OPJ_INT32 *a, OPJ_INT32 x) {
/* <summary> */ /* <summary> */
/* Forward 5-3 wavelet transform in 1-D. */ /* Forward 5-3 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i; OPJ_INT32 i;
if (!cas) { if (!cas) {
@ -304,7 +309,8 @@ static void opj_dwt_encode_1(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32
/* <summary> */ /* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */ /* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i; OPJ_INT32 i;
if (!cas) { if (!cas) {
@ -325,14 +331,16 @@ static void opj_dwt_decode_1_(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT3
/* <summary> */ /* <summary> */
/* Inverse 5-3 wavelet transform in 1-D. */ /* Inverse 5-3 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
static void opj_dwt_decode_1(opj_dwt_t *v) { static void opj_dwt_decode_1(opj_dwt_t *v)
{
opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas); opj_dwt_decode_1_(v->mem, v->dn, v->sn, v->cas);
} }
/* <summary> */ /* <summary> */
/* Forward 9-7 wavelet transform in 1-D. */ /* Forward 9-7 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas) { static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_INT32 cas)
{
OPJ_INT32 i; OPJ_INT32 i;
if (!cas) { if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
@ -367,7 +375,8 @@ static void opj_dwt_encode_1_real(OPJ_INT32 *a, OPJ_INT32 dn, OPJ_INT32 sn, OPJ_
} }
} }
static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize) { static void opj_dwt_encode_stepsize(OPJ_INT32 stepsize, OPJ_INT32 numbps, opj_stepsize_t *bandno_stepsize)
{
OPJ_INT32 p, n; OPJ_INT32 p, n;
p = opj_int_floorlog2(stepsize) - 13; p = opj_int_floorlog2(stepsize) - 13;
n = 11 - opj_int_floorlog2(stepsize); n = 11 - opj_int_floorlog2(stepsize);
@ -473,7 +482,8 @@ OPJ_BOOL opj_dwt_encode(opj_tcd_tilecomp_t * tilec)
/* <summary> */ /* <summary> */
/* Inverse 5-3 wavelet transform in 2-D. */ /* Inverse 5-3 wavelet transform in 2-D. */
/* </summary> */ /* </summary> */
OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) { OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres)
{
return opj_dwt_decode_tile(tilec, numres, &opj_dwt_decode_1); return opj_dwt_decode_tile(tilec, numres, &opj_dwt_decode_1);
} }
@ -481,7 +491,8 @@ OPJ_BOOL opj_dwt_decode(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres) {
/* <summary> */ /* <summary> */
/* Get gain of 5-3 wavelet transform. */ /* Get gain of 5-3 wavelet transform. */
/* </summary> */ /* </summary> */
OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) { OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient)
{
if (orient == 0) if (orient == 0)
return 0; return 0;
if (orient == 1 || orient == 2) if (orient == 1 || orient == 2)
@ -492,7 +503,8 @@ OPJ_UINT32 opj_dwt_getgain(OPJ_UINT32 orient) {
/* <summary> */ /* <summary> */
/* Get norm of 5-3 wavelet. */ /* Get norm of 5-3 wavelet. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient) { OPJ_FLOAT64 opj_dwt_getnorm(OPJ_UINT32 level, OPJ_UINT32 orient)
{
return opj_dwt_norms[orient][level]; return opj_dwt_norms[orient][level];
} }
@ -507,7 +519,8 @@ OPJ_BOOL opj_dwt_encode_real(opj_tcd_tilecomp_t * tilec)
/* <summary> */ /* <summary> */
/* Get gain of 9-7 wavelet transform. */ /* Get gain of 9-7 wavelet transform. */
/* </summary> */ /* </summary> */
OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient) { OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient)
{
(void)orient; (void)orient;
return 0; return 0;
} }
@ -515,11 +528,13 @@ OPJ_UINT32 opj_dwt_getgain_real(OPJ_UINT32 orient) {
/* <summary> */ /* <summary> */
/* Get norm of 9-7 wavelet. */ /* Get norm of 9-7 wavelet. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient) { OPJ_FLOAT64 opj_dwt_getnorm_real(OPJ_UINT32 level, OPJ_UINT32 orient)
{
return opj_dwt_norms_real[orient][level]; return opj_dwt_norms_real[orient][level];
} }
void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) { void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec)
{
OPJ_UINT32 numbands, bandno; OPJ_UINT32 numbands, bandno;
numbands = 3 * tccp->numresolutions - 2; numbands = 3 * tccp->numresolutions - 2;
for (bandno = 0; bandno < numbands; bandno++) { for (bandno = 0; bandno < numbands; bandno++) {
@ -543,7 +558,8 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) {
/* <summary> */ /* <summary> */
/* Determine maximum computed resolution level for inverse wavelet transform */ /* Determine maximum computed resolution level for inverse wavelet transform */
/* </summary> */ /* </summary> */
static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i) { static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i)
{
OPJ_UINT32 mr = 0; OPJ_UINT32 mr = 0;
OPJ_UINT32 w; OPJ_UINT32 w;
while( --i ) { while( --i ) {
@ -559,7 +575,8 @@ static OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_U
/* <summary> */ /* <summary> */
/* Inverse wavelet transform in 2-D. */ /* Inverse wavelet transform in 2-D. */
/* </summary> */ /* </summary> */
static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D) { static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1DFN dwt_1D)
{
opj_dwt_t h; opj_dwt_t h;
opj_dwt_t v; opj_dwt_t v;
@ -617,7 +634,8 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
return OPJ_TRUE; return OPJ_TRUE;
} }
static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size){ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restrict a, OPJ_INT32 x, OPJ_INT32 size)
{
OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas); OPJ_FLOAT32* restrict bi = (OPJ_FLOAT32*) (w->wavelet + w->cas);
OPJ_INT32 count = w->sn; OPJ_INT32 count = w->sn;
OPJ_INT32 i, k; OPJ_INT32 i, k;
@ -635,8 +653,7 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
j += x; j += x;
bi[i*8 + 3] = a[j]; bi[i*8 + 3] = a[j];
} }
} } else {
else {
/* Slow code path */ /* Slow code path */
for(i = 0; i < count; ++i) { for(i = 0; i < count; ++i) {
OPJ_INT32 j = i; OPJ_INT32 j = i;
@ -660,7 +677,8 @@ static void opj_v4dwt_interleave_h(opj_v4dwt_t* restrict w, OPJ_FLOAT32* restric
} }
} }
static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read){ static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 x, OPJ_INT32 nb_elts_read)
{
opj_v4_t* restrict bi = v->wavelet + v->cas; opj_v4_t* restrict bi = v->wavelet + v->cas;
OPJ_INT32 i; OPJ_INT32 i;
@ -678,7 +696,8 @@ static void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restri
#ifdef __SSE__ #ifdef __SSE__
static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c){ static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m128 c)
{
__m128* restrict vw = (__m128*) w; __m128* restrict vw = (__m128*) w;
OPJ_INT32 i; OPJ_INT32 i;
/* 4x unrolled loop */ /* 4x unrolled loop */
@ -699,7 +718,8 @@ static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
} }
} }
void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c){ void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32 m, __m128 c)
{
__m128* restrict vl = (__m128*) l; __m128* restrict vl = (__m128*) l;
__m128* restrict vw = (__m128*) w; __m128* restrict vw = (__m128*) w;
OPJ_INT32 i; OPJ_INT32 i;
@ -892,9 +912,12 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
opj_v4dwt_decode(&h); opj_v4dwt_decode(&h);
for(k = (OPJ_INT32)rw; --k >= 0;) { for(k = (OPJ_INT32)rw; --k >= 0;) {
switch(j) { switch(j) {
case 3: aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2]; case 3:
case 2: aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1]; aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
case 1: aj[k ] = h.wavelet[k].f[0]; case 2:
aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
case 1:
aj[k ] = h.wavelet[k].f[0];
} }
} }
} }

View File

@ -40,7 +40,8 @@
#ifdef OPJ_CODE_NOT_USED #ifdef OPJ_CODE_NOT_USED
#ifndef _WIN32 #ifndef _WIN32
static char* static char*
i2a(unsigned i, char *a, unsigned r) { i2a(unsigned i, char *a, unsigned r)
{
if (i/r > 0) a = i2a(i/r,a,r); if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1; return a+1;
@ -55,13 +56,13 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a @return Returns a
*/ */
static char * static char *
_itoa(int i, char *a, int r) { _itoa(int i, char *a, int r)
{
r = ((r < 2) || (r > 36)) ? 10 : r; r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) { if(i < 0) {
*a = '-'; *a = '-';
*i2a(-i, a+1, r) = 0; *i2a(-i, a+1, r) = 0;
} } else *i2a(i, a, r) = 0;
else *i2a(i, a, r) = 0;
return a; return a;
} }
@ -83,7 +84,8 @@ static void opj_default_callback (const char *msg, void *client_data)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...) { OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const char *fmt, ...)
{
#define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ #define OPJ_MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = 00; opj_msg_callback msg_handler = 00;
void * l_data = 00; void * l_data = 00;

View File

@ -47,8 +47,7 @@ used for
<li>Debugging messages <li>Debugging messages
</ul> </ul>
*/ */
typedef struct opj_event_mgr typedef struct opj_event_mgr {
{
/** Data to call the event manager upon */ /** Data to call the event manager upon */
void * m_error_data; void * m_error_data;
/** Data to call the event manager upon */ /** Data to call the event manager upon */

View File

@ -40,15 +40,13 @@ opj_procedure_list_t * opj_procedure_list_create()
{ {
/* memory allocation */ /* memory allocation */
opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t)); opj_procedure_list_t * l_validation = (opj_procedure_list_t *) opj_calloc(1,sizeof(opj_procedure_list_t));
if (! l_validation) if (! l_validation) {
{
return 00; return 00;
} }
/* initialization */ /* initialization */
l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE; l_validation->m_nb_max_procedures = OPJ_VALIDATION_SIZE;
l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure)); l_validation->m_procedures = (opj_procedure*)opj_calloc(OPJ_VALIDATION_SIZE, sizeof(opj_procedure));
if (! l_validation->m_procedures) if (! l_validation->m_procedures) {
{
opj_free(l_validation); opj_free(l_validation);
return 00; return 00;
} }
@ -57,13 +55,11 @@ opj_procedure_list_t * opj_procedure_list_create()
void opj_procedure_list_destroy(opj_procedure_list_t * p_list) void opj_procedure_list_destroy(opj_procedure_list_t * p_list)
{ {
if (! p_list) if (! p_list) {
{
return; return;
} }
/* initialization */ /* initialization */
if (p_list->m_procedures) if (p_list->m_procedures) {
{
opj_free(p_list->m_procedures); opj_free(p_list->m_procedures);
} }
opj_free(p_list); opj_free(p_list);
@ -74,24 +70,20 @@ OPJ_BOOL opj_procedure_list_add_procedure (opj_procedure_list_t * p_validation_l
assert(p_manager != NULL); assert(p_manager != NULL);
if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) if (p_validation_list->m_nb_max_procedures == p_validation_list->m_nb_procedures) {
{
opj_procedure * new_procedures; opj_procedure * new_procedures;
p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE; p_validation_list->m_nb_max_procedures += OPJ_VALIDATION_SIZE;
new_procedures = (opj_procedure*)opj_realloc( new_procedures = (opj_procedure*)opj_realloc(
p_validation_list->m_procedures, p_validation_list->m_procedures,
p_validation_list->m_nb_max_procedures * sizeof(opj_procedure)); p_validation_list->m_nb_max_procedures * sizeof(opj_procedure));
if (! new_procedures) if (! new_procedures) {
{
opj_free(p_validation_list->m_procedures); opj_free(p_validation_list->m_procedures);
p_validation_list->m_nb_max_procedures = 0; p_validation_list->m_nb_max_procedures = 0;
p_validation_list->m_nb_procedures = 0; p_validation_list->m_nb_procedures = 0;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n"); opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add a new validation procedure\n");
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else
{
p_validation_list->m_procedures = new_procedures; p_validation_list->m_procedures = new_procedures;
} }
} }

View File

@ -54,8 +54,7 @@ typedef void (*opj_procedure)(void);
/** /**
* A list of procedures. * A list of procedures.
*/ */
typedef struct opj_procedure_list typedef struct opj_procedure_list {
{
/** /**
* The number of validation procedures. * The number of validation procedures.
*/ */

View File

@ -31,12 +31,14 @@
#include "opj_includes.h" #include "opj_includes.h"
opj_image_t* opj_image_create0(void) { opj_image_t* opj_image_create0(void)
{
opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t)); opj_image_t *image = (opj_image_t*)opj_calloc(1, sizeof(opj_image_t));
return image; return image;
} }
opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
{
OPJ_UINT32 compno; OPJ_UINT32 compno;
opj_image_t *image = NULL; opj_image_t *image = NULL;
@ -77,7 +79,8 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa
return image; return image;
} }
void OPJ_CALLCONV opj_image_destroy(opj_image_t *image) { void OPJ_CALLCONV opj_image_destroy(opj_image_t *image)
{
if(image) { if(image) {
if(image->comps) { if(image->comps) {
OPJ_UINT32 compno; OPJ_UINT32 compno;
@ -198,20 +201,19 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
memcpy( p_image_dest->icc_profile_buf, memcpy( p_image_dest->icc_profile_buf,
p_image_src->icc_profile_buf, p_image_src->icc_profile_buf,
p_image_src->icc_profile_len); p_image_src->icc_profile_len);
} } else
else
p_image_dest->icc_profile_buf = NULL; p_image_dest->icc_profile_buf = NULL;
return; return;
} }
opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
{
OPJ_UINT32 compno; OPJ_UINT32 compno;
opj_image_t *image = 00; opj_image_t *image = 00;
image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t)); image = (opj_image_t*) opj_calloc(1,sizeof(opj_image_t));
if (image) if (image) {
{
image->color_space = clrspc; image->color_space = clrspc;
image->numcomps = numcmpts; image->numcomps = numcmpts;

View File

@ -121,8 +121,7 @@ static OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations,
OPJ_UINT32 lStride = nb_compo-1; OPJ_UINT32 lStride = nb_compo-1;
/*initialize permutations */ /*initialize permutations */
for (i = 0; i < nb_compo; ++i) for (i = 0; i < nb_compo; ++i) {
{
*tmpPermutations++ = i; *tmpPermutations++ = i;
} }
/* now make a pivot with column switch */ /* now make a pivot with column switch */
@ -232,8 +231,7 @@ static void opj_lupSolve (OPJ_FLOAT32 * pResult,
sum = 0.0; sum = 0.0;
lCurrentPtr = p_intermediate_data; lCurrentPtr = p_intermediate_data;
lTmpMatrix = lLineMatrix; lTmpMatrix = lLineMatrix;
for (j = 1; j <= i; ++j) for (j = 1; j <= i; ++j) {
{
/* sum += matrix[i][j-1] * y[j-1]; */ /* sum += matrix[i][j-1] * y[j-1]; */
sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++)); sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++));
} }

View File

@ -1281,8 +1281,7 @@ static j2k_prog_order_t j2k_prog_order_list[] = {
/** /**
* FIXME DOC * FIXME DOC
*/ */
static const OPJ_UINT32 MCT_ELEMENT_SIZE [] = static const OPJ_UINT32 MCT_ELEMENT_SIZE [] = {
{
2, 2,
4, 4,
4, 4,
@ -1291,32 +1290,28 @@ static const OPJ_UINT32 MCT_ELEMENT_SIZE [] =
typedef void (* opj_j2k_mct_function) (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem); typedef void (* opj_j2k_mct_function) (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem);
static const opj_j2k_mct_function j2k_mct_read_functions_to_float [] = static const opj_j2k_mct_function j2k_mct_read_functions_to_float [] = {
{
opj_j2k_read_int16_to_float, opj_j2k_read_int16_to_float,
opj_j2k_read_int32_to_float, opj_j2k_read_int32_to_float,
opj_j2k_read_float32_to_float, opj_j2k_read_float32_to_float,
opj_j2k_read_float64_to_float opj_j2k_read_float64_to_float
}; };
static const opj_j2k_mct_function j2k_mct_read_functions_to_int32 [] = static const opj_j2k_mct_function j2k_mct_read_functions_to_int32 [] = {
{
opj_j2k_read_int16_to_int32, opj_j2k_read_int16_to_int32,
opj_j2k_read_int32_to_int32, opj_j2k_read_int32_to_int32,
opj_j2k_read_float32_to_int32, opj_j2k_read_float32_to_int32,
opj_j2k_read_float64_to_int32 opj_j2k_read_float64_to_int32
}; };
static const opj_j2k_mct_function j2k_mct_write_functions_from_float [] = static const opj_j2k_mct_function j2k_mct_write_functions_from_float [] = {
{
opj_j2k_write_float_to_int16, opj_j2k_write_float_to_int16,
opj_j2k_write_float_to_int32, opj_j2k_write_float_to_int32,
opj_j2k_write_float_to_float, opj_j2k_write_float_to_float,
opj_j2k_write_float_to_float64 opj_j2k_write_float_to_float64
}; };
typedef struct opj_dec_memory_marker_handler typedef struct opj_dec_memory_marker_handler {
{
/** marker value */ /** marker value */
OPJ_UINT32 id; OPJ_UINT32 id;
/** value of the state when the marker can appear */ /** value of the state when the marker can appear */
@ -1329,8 +1324,7 @@ typedef struct opj_dec_memory_marker_handler
} }
opj_dec_memory_marker_handler_t; opj_dec_memory_marker_handler_t;
static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = {
{
{J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot}, {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot},
{J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_cod}, {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_cod},
{J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_coc}, {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_coc},
@ -1558,7 +1552,8 @@ static void opj_j2k_write_float_to_float64 (const void * p_src_data, void * p_d
} }
} }
char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){ char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order)
{
j2k_prog_order_t *po; j2k_prog_order_t *po;
for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ) { for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ) {
if(po->enum_prog == prg_order) { if(po->enum_prog == prg_order) {
@ -1597,8 +1592,7 @@ static OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs,
index = step_r * p_pocs->resno0; index = step_r * p_pocs->resno0;
/* take each resolution for each poc */ /* take each resolution for each poc */
for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) {
{
OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c; OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c;
/* take each comp of each resolution for each poc */ /* take each comp of each resolution for each poc */
@ -1697,8 +1691,7 @@ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, OPJ_UINT32 t
if (cp->m_specific_param.m_enc.m_tp_on == 1) { if (cp->m_specific_param.m_enc.m_tp_on == 1) {
for (i=0; i<4; ++i) { for (i=0; i<4; ++i) {
switch (prog[i]) switch (prog[i]) {
{
/* component wise */ /* component wise */
case 'C': case 'C':
tpnum *= l_current_poc->compE; tpnum *= l_current_poc->compE;
@ -1722,8 +1715,7 @@ static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, OPJ_UINT32 t
break; break;
} }
} }
} } else {
else {
tpnum=1; tpnum=1;
} }
@ -2210,8 +2202,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
p_j2k->m_specific_param.m_decoder.m_start_tile_y = (p_j2k->m_specific_param.m_decoder.m_start_tile_y - l_cp->ty0) / l_cp->tdy; p_j2k->m_specific_param.m_decoder.m_start_tile_y = (p_j2k->m_specific_param.m_decoder.m_start_tile_y - l_cp->ty0) / l_cp->tdy;
p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0), (OPJ_INT32)l_cp->tdx); p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0), (OPJ_INT32)l_cp->tdx);
p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0), (OPJ_INT32)l_cp->tdy); p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0), (OPJ_INT32)l_cp->tdy);
} } else {
else {
p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0; p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0;
p_j2k->m_specific_param.m_decoder.m_start_tile_y = 0; p_j2k->m_specific_param.m_decoder.m_start_tile_y = 0;
p_j2k->m_specific_param.m_decoder.m_end_tile_x = l_cp->tw; p_j2k->m_specific_param.m_decoder.m_end_tile_x = l_cp->tw;
@ -2545,8 +2536,7 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k,
/* If user didn't set a number layer to decode take the max specify in the codestream. */ /* If user didn't set a number layer to decode take the max specify in the codestream. */
if (l_cp->m_specific_param.m_dec.m_layer) { if (l_cp->m_specific_param.m_dec.m_layer) {
l_tcp->num_layers_to_decode = l_cp->m_specific_param.m_dec.m_layer; l_tcp->num_layers_to_decode = l_cp->m_specific_param.m_dec.m_layer;
} } else {
else {
l_tcp->num_layers_to_decode = l_tcp->numlayers; l_tcp->num_layers_to_decode = l_tcp->numlayers;
} }
@ -2945,8 +2935,7 @@ static void opj_j2k_write_qcc_in_memory( opj_j2k_t *p_j2k,
/* in the case only one byte is sufficient the last byte allocated is useless -> still do -6 for available */ /* in the case only one byte is sufficient the last byte allocated is useless -> still do -6 for available */
l_remaining_size -= 6; l_remaining_size -= 6;
} } else {
else {
opj_write_bytes(l_current_data,l_qcc_size-2,2); /* L_QCC */ opj_write_bytes(l_current_data,l_qcc_size-2,2); /* L_QCC */
l_current_data += 2; l_current_data += 2;
@ -2996,8 +2985,7 @@ static OPJ_BOOL opj_j2k_read_qcc( opj_j2k_t *p_j2k,
opj_read_bytes(p_header_data,&l_comp_no,1); opj_read_bytes(p_header_data,&l_comp_no,1);
++p_header_data; ++p_header_data;
--p_header_size; --p_header_size;
} } else {
else {
if (p_header_size < 2) { if (p_header_size < 2) {
opj_event_msg(p_manager, EVT_ERROR, "Error reading QCC marker\n"); opj_event_msg(p_manager, EVT_ERROR, "Error reading QCC marker\n");
return OPJ_FALSE; return OPJ_FALSE;
@ -3076,8 +3064,7 @@ static OPJ_BOOL opj_j2k_write_poc( opj_j2k_t *p_j2k,
if (l_nb_comp <= 256) { if (l_nb_comp <= 256) {
l_poc_room = 1; l_poc_room = 1;
} } else {
else {
l_poc_room = 2; l_poc_room = 2;
} }
l_poc_size = 4 + (5 + 2 * l_poc_room) * l_nb_poc; l_poc_size = 4 + (5 + 2 * l_poc_room) * l_nb_poc;
@ -3133,8 +3120,7 @@ static void opj_j2k_write_poc_in_memory( opj_j2k_t *p_j2k,
if (l_nb_comp <= 256) { if (l_nb_comp <= 256) {
l_poc_room = 1; l_poc_room = 1;
} } else {
else {
l_poc_room = 2; l_poc_room = 2;
} }
@ -3274,8 +3260,7 @@ static OPJ_BOOL opj_j2k_read_poc ( opj_j2k_t *p_j2k,
l_nb_comp = l_image->numcomps; l_nb_comp = l_image->numcomps;
if (l_nb_comp <= 256) { if (l_nb_comp <= 256) {
l_comp_room = 1; l_comp_room = 1;
} } else {
else {
l_comp_room = 2; l_comp_room = 2;
} }
l_chunk_size = 5 + 2 * l_comp_room; l_chunk_size = 5 + 2 * l_comp_room;
@ -3294,8 +3279,7 @@ static OPJ_BOOL opj_j2k_read_poc ( opj_j2k_t *p_j2k,
l_old_poc_nb = l_tcp->POC ? l_tcp->numpocs + 1 : 0; l_old_poc_nb = l_tcp->POC ? l_tcp->numpocs + 1 : 0;
l_current_poc_nb += l_old_poc_nb; l_current_poc_nb += l_old_poc_nb;
if(l_current_poc_nb >= 32) if(l_current_poc_nb >= 32) {
{
opj_event_msg(p_manager, EVT_ERROR, "Too many POCs %d\n", l_current_poc_nb); opj_event_msg(p_manager, EVT_ERROR, "Too many POCs %d\n", l_current_poc_nb);
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -3533,8 +3517,7 @@ static OPJ_BOOL opj_j2k_read_plt ( opj_j2k_t *p_j2k,
l_packet_len |= (l_tmp & 0x7f); l_packet_len |= (l_tmp & 0x7f);
if (l_tmp & 0x80) { if (l_tmp & 0x80) {
l_packet_len <<= 7; l_packet_len <<= 7;
} } else {
else {
/* store packet length and proceed to next packet */ /* store packet length and proceed to next packet */
l_packet_len = 0; l_packet_len = 0;
} }
@ -3664,8 +3647,7 @@ static OPJ_BOOL opj_j2k_merge_ppm ( opj_cp_t *p_cp, opj_event_mgr_t * p_manager
} }
if (l_data_size > 0U) { if (l_data_size > 0U) {
do do {
{
/* read Nppm */ /* read Nppm */
if (l_data_size < 4U) { if (l_data_size < 4U) {
/* clean up to be done on l_cp destruction */ /* clean up to be done on l_cp destruction */
@ -3723,8 +3705,7 @@ static OPJ_BOOL opj_j2k_merge_ppm ( opj_cp_t *p_cp, opj_event_mgr_t * p_manager
} }
if (l_data_size > 0U) { if (l_data_size > 0U) {
do do {
{
/* read Nppm */ /* read Nppm */
if (l_data_size < 4U) { if (l_data_size < 4U) {
/* clean up to be done on l_cp destruction */ /* clean up to be done on l_cp destruction */
@ -4090,14 +4071,10 @@ static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
/* since the time taken by this function can only grow at the time */ /* since the time taken by this function can only grow at the time */
/* PSot should be equal to zero or >=14 or <= 2^32-1 */ /* PSot should be equal to zero or >=14 or <= 2^32-1 */
if ((l_tot_len !=0 ) && (l_tot_len < 14) ) if ((l_tot_len !=0 ) && (l_tot_len < 14) ) {
{ if (l_tot_len == 12 ) { /* MSD: Special case for the PHR data which are read by kakadu*/
if (l_tot_len == 12 ) /* MSD: Special case for the PHR data which are read by kakadu*/
{
opj_event_msg(p_manager, EVT_WARNING, "Empty SOT marker detected: Psot=%d.\n", l_tot_len); opj_event_msg(p_manager, EVT_WARNING, "Empty SOT marker detected: Psot=%d.\n", l_tot_len);
} } else {
else
{
opj_event_msg(p_manager, EVT_ERROR, "Psot value is not correct regards to the JPEG2000 norm: %d.\n", l_tot_len); opj_event_msg(p_manager, EVT_ERROR, "Psot value is not correct regards to the JPEG2000 norm: %d.\n", l_tot_len);
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -4163,8 +4140,7 @@ static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
if (!p_j2k->m_specific_param.m_decoder.m_last_tile_part) { if (!p_j2k->m_specific_param.m_decoder.m_last_tile_part) {
/* Keep the size of data to skip after this marker */ /* Keep the size of data to skip after this marker */
p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - 12; /* SOT_marker_size = 12 */ p_j2k->m_specific_param.m_decoder.m_sot_length = l_tot_len - 12; /* SOT_marker_size = 12 */
} } else {
else {
/* FIXME: need to be computed from the number of bytes remaining in the codestream */ /* FIXME: need to be computed from the number of bytes remaining in the codestream */
p_j2k->m_specific_param.m_decoder.m_sot_length = 0; p_j2k->m_specific_param.m_decoder.m_sot_length = 0;
} }
@ -4178,16 +4154,14 @@ static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
|| (l_tile_x >= p_j2k->m_specific_param.m_decoder.m_end_tile_x) || (l_tile_x >= p_j2k->m_specific_param.m_decoder.m_end_tile_x)
|| (l_tile_y < p_j2k->m_specific_param.m_decoder.m_start_tile_y) || (l_tile_y < p_j2k->m_specific_param.m_decoder.m_start_tile_y)
|| (l_tile_y >= p_j2k->m_specific_param.m_decoder.m_end_tile_y); || (l_tile_y >= p_j2k->m_specific_param.m_decoder.m_end_tile_y);
} } else {
else {
assert( p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec >= 0 ); assert( p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec >= 0 );
p_j2k->m_specific_param.m_decoder.m_skip_data = p_j2k->m_specific_param.m_decoder.m_skip_data =
(p_j2k->m_current_tile_number != (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec); (p_j2k->m_current_tile_number != (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec);
} }
/* Index */ /* Index */
if (p_j2k->cstr_index) if (p_j2k->cstr_index) {
{
assert(p_j2k->cstr_index->tile_index != 00); assert(p_j2k->cstr_index->tile_index != 00);
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tileno = p_j2k->m_current_tile_number; p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tileno = p_j2k->m_current_tile_number;
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_tpsno = l_current_part; p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_tpsno = l_current_part;
@ -4203,8 +4177,7 @@ static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n"); opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read SOT marker. Tile index allocation failed\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc( opj_tp_index_t *new_tp_index = (opj_tp_index_t *) opj_realloc(
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index, l_num_parts* sizeof(opj_tp_index_t)); p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index, l_num_parts* sizeof(opj_tp_index_t));
if (! new_tp_index) { if (! new_tp_index) {
@ -4215,8 +4188,7 @@ static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
} }
p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index; p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index = new_tp_index;
} }
} } else {
else{
/*if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)*/ { /*if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index)*/ {
if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) { if (!p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index) {
@ -4381,8 +4353,7 @@ static OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
// so its result will fit on OPJ_UINT32 unless we find // so its result will fit on OPJ_UINT32 unless we find
// a file with a single tile part of more than 4 GB...*/ // a file with a single tile part of more than 4 GB...*/
p_j2k->m_specific_param.m_decoder.m_sot_length = (OPJ_UINT32)(opj_stream_get_number_byte_left(p_stream) - 2); p_j2k->m_specific_param.m_decoder.m_sot_length = (OPJ_UINT32)(opj_stream_get_number_byte_left(p_stream) - 2);
} } else {
else {
/* Check to avoid pass the limit of OPJ_UINT32 */ /* Check to avoid pass the limit of OPJ_UINT32 */
if (p_j2k->m_specific_param.m_decoder.m_sot_length >= 2 ) if (p_j2k->m_specific_param.m_decoder.m_sot_length >= 2 )
p_j2k->m_specific_param.m_decoder.m_sot_length -= 2; p_j2k->m_specific_param.m_decoder.m_sot_length -= 2;
@ -4407,8 +4378,7 @@ static OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
* TODO: If this was consistent, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...). * TODO: If this was consistent, we could simplify the code to only use realloc(), as realloc(0,...) default to malloc(0,...).
*/ */
*l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param.m_decoder.m_sot_length); *l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param.m_decoder.m_sot_length);
} } else {
else {
OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_current_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length); OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_current_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length);
if (! l_new_current_data) { if (! l_new_current_data) {
opj_free(*l_current_data); opj_free(*l_current_data);
@ -4424,8 +4394,7 @@ static OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to decode tile\n"); opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to decode tile\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
l_sot_length_pb_detected = OPJ_TRUE; l_sot_length_pb_detected = OPJ_TRUE;
} }
@ -4459,16 +4428,13 @@ static OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
*l_current_data + *l_tile_len, *l_current_data + *l_tile_len,
p_j2k->m_specific_param.m_decoder.m_sot_length, p_j2k->m_specific_param.m_decoder.m_sot_length,
p_manager); p_manager);
} } else {
else
{
l_current_read_size = 0; l_current_read_size = 0;
} }
if (l_current_read_size != p_j2k->m_specific_param.m_decoder.m_sot_length) { if (l_current_read_size != p_j2k->m_specific_param.m_decoder.m_sot_length) {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
} } else {
else {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT;
} }
@ -4503,8 +4469,7 @@ static OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k,
if (nb_comps <= 256) { if (nb_comps <= 256) {
l_comp_room = 1; l_comp_room = 1;
} } else {
else {
l_comp_room = 2; l_comp_room = 2;
} }
@ -4595,9 +4560,10 @@ static OPJ_BOOL opj_j2k_read_rgn (opj_j2k_t *p_j2k,
l_nb_comp = l_image->numcomps; l_nb_comp = l_image->numcomps;
if (l_nb_comp <= 256) { if (l_nb_comp <= 256) {
l_comp_room = 1; } l_comp_room = 1;
else { } else {
l_comp_room = 2; } l_comp_room = 2;
}
if (p_header_size != 2 + l_comp_room) { if (p_header_size != 2 + l_comp_room) {
opj_event_msg(p_manager, EVT_ERROR, "Error reading RGN marker\n"); opj_event_msg(p_manager, EVT_ERROR, "Error reading RGN marker\n");
@ -4688,8 +4654,7 @@ static OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k,
if (l_cp->m_specific_param.m_enc.m_tp_on) { if (l_cp->m_specific_param.m_enc.m_tp_on) {
l_tp_stride_func = opj_j2k_get_tp_stride; l_tp_stride_func = opj_j2k_get_tp_stride;
} } else {
else {
l_tp_stride_func = opj_j2k_get_default_stride; l_tp_stride_func = opj_j2k_get_default_stride;
} }
@ -4942,8 +4907,7 @@ static OPJ_BOOL opj_j2k_write_all_coc(
assert(p_manager != 00); assert(p_manager != 00);
assert(p_stream != 00); assert(p_stream != 00);
for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno) for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno) {
{
/* cod is first component of first tile */ /* cod is first component of first tile */
if (! opj_j2k_compare_coc(p_j2k, 0, compno)) { if (! opj_j2k_compare_coc(p_j2k, 0, compno)) {
if (! opj_j2k_write_coc(p_j2k,compno,p_stream, p_manager)) { if (! opj_j2k_write_coc(p_j2k,compno,p_stream, p_manager)) {
@ -4967,8 +4931,7 @@ static OPJ_BOOL opj_j2k_write_all_qcc(
assert(p_manager != 00); assert(p_manager != 00);
assert(p_stream != 00); assert(p_stream != 00);
for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno) for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno) {
{
/* qcd is first component of first tile */ /* qcd is first component of first tile */
if (! opj_j2k_compare_qcc(p_j2k, 0, compno)) { if (! opj_j2k_compare_qcc(p_j2k, 0, compno)) {
if (! opj_j2k_write_qcc(p_j2k,compno,p_stream, p_manager)) { if (! opj_j2k_write_qcc(p_j2k,compno,p_stream, p_manager)) {
@ -5080,12 +5043,10 @@ static OPJ_BOOL opj_j2k_read_unk ( opj_j2k_t *p_j2k,
if (!(p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states)) { if (!(p_j2k->m_specific_param.m_decoder.m_state & l_marker_handler->states)) {
opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n"); opj_event_msg(p_manager, EVT_ERROR, "Marker is not compliant with its position\n");
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else {
if (l_marker_handler->id != J2K_MS_UNK) { if (l_marker_handler->id != J2K_MS_UNK) {
/* Add the marker to the codestream index*/ /* Add the marker to the codestream index*/
if (l_marker_handler->id != J2K_MS_SOT) if (l_marker_handler->id != J2K_MS_SOT) {
{
OPJ_BOOL res = opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_UNK, OPJ_BOOL res = opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_UNK,
(OPJ_UINT32) opj_stream_tell(p_stream) - l_size_unk, (OPJ_UINT32) opj_stream_tell(p_stream) - l_size_unk,
l_size_unk); l_size_unk);
@ -5095,8 +5056,7 @@ static OPJ_BOOL opj_j2k_read_unk ( opj_j2k_t *p_j2k,
} }
} }
break; /* next marker is known and well located */ break; /* next marker is known and well located */
} } else
else
l_size_unk += 2; l_size_unk += 2;
} }
} }
@ -5299,15 +5259,13 @@ static OPJ_BOOL opj_j2k_write_mcc_record( opj_j2k_t *p_j2k,
if (p_mcc_record->m_nb_comps > 255 ) { if (p_mcc_record->m_nb_comps > 255 ) {
l_nb_bytes_for_comp = 2; l_nb_bytes_for_comp = 2;
l_mask = 0x8000; l_mask = 0x8000;
} } else {
else {
l_nb_bytes_for_comp = 1; l_nb_bytes_for_comp = 1;
l_mask = 0; l_mask = 0;
} }
l_mcc_size = p_mcc_record->m_nb_comps * 2 * l_nb_bytes_for_comp + 19; l_mcc_size = p_mcc_record->m_nb_comps * 2 * l_nb_bytes_for_comp + 19;
if (l_mcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) if (l_mcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) {
{
OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mcc_size); OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k->m_specific_param.m_encoder.m_header_tile_data, l_mcc_size);
if (! new_header_tile_data) { if (! new_header_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data); opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
@ -5356,8 +5314,7 @@ static OPJ_BOOL opj_j2k_write_mcc_record( opj_j2k_t *p_j2k,
opj_write_bytes(l_current_data,p_mcc_record->m_nb_comps|l_mask,2); /* Mmcci number of output components involved and size for each component offset = 8 bits */ opj_write_bytes(l_current_data,p_mcc_record->m_nb_comps|l_mask,2); /* Mmcci number of output components involved and size for each component offset = 8 bits */
l_current_data+=2; l_current_data+=2;
for (i=0;i<p_mcc_record->m_nb_comps;++i) for (i=0; i<p_mcc_record->m_nb_comps; ++i) {
{
opj_write_bytes(l_current_data,i,l_nb_bytes_for_comp); /* Wmccij Component offset*/ opj_write_bytes(l_current_data,i,l_nb_bytes_for_comp); /* Wmccij Component offset*/
l_current_data+=l_nb_bytes_for_comp; l_current_data+=l_nb_bytes_for_comp;
} }
@ -5975,7 +5932,8 @@ opj_j2k_t* opj_j2k_create_compress(void)
return l_j2k; return l_j2k;
} }
static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres)
{
POC[0].tile = 1; POC[0].tile = 1;
POC[0].resno0 = 0; POC[0].resno0 = 0;
POC[0].compno0 = 0; POC[0].compno0 = 0;
@ -6594,8 +6552,7 @@ OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
opj_event_msg(p_manager, EVT_ERROR, "Failed to setup j2k mct encoding\n"); opj_event_msg(p_manager, EVT_ERROR, "Failed to setup j2k mct encoding\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
if(tcp->mct==1 && image->numcomps >= 3) { /* RGB->YCC MCT is enabled */ if(tcp->mct==1 && image->numcomps >= 3) { /* RGB->YCC MCT is enabled */
if ((image->comps[0].dx != image->comps[1].dx) || if ((image->comps[0].dx != image->comps[1].dx) ||
(image->comps[0].dx != image->comps[2].dx) || (image->comps[0].dx != image->comps[2].dx) ||
@ -7517,8 +7474,7 @@ void opj_j2k_destroy (opj_j2k_t *p_j2k)
p_j2k->m_specific_param.m_decoder.m_header_data = 00; p_j2k->m_specific_param.m_decoder.m_header_data = 00;
p_j2k->m_specific_param.m_decoder.m_header_data_size = 0; p_j2k->m_specific_param.m_decoder.m_header_data_size = 0;
} }
} } else {
else {
if (p_j2k->m_specific_param.m_encoder.m_encoded_tile_data) { if (p_j2k->m_specific_param.m_encoder.m_encoded_tile_data) {
opj_free(p_j2k->m_specific_param.m_encoder.m_encoded_tile_data); opj_free(p_j2k->m_specific_param.m_encoder.m_encoded_tile_data);
@ -7685,18 +7641,15 @@ static void opj_j2k_cp_destroy (opj_cp_t *p_cp)
OPJ_UINT32 l_nb_tiles; OPJ_UINT32 l_nb_tiles;
opj_tcp_t * l_current_tile = 00; opj_tcp_t * l_current_tile = 00;
if (p_cp == 00) if (p_cp == 00) {
{
return; return;
} }
if (p_cp->tcps != 00) if (p_cp->tcps != 00) {
{
OPJ_UINT32 i; OPJ_UINT32 i;
l_current_tile = p_cp->tcps; l_current_tile = p_cp->tcps;
l_nb_tiles = p_cp->th * p_cp->tw; l_nb_tiles = p_cp->th * p_cp->tw;
for (i = 0U; i < l_nb_tiles; ++i) for (i = 0U; i < l_nb_tiles; ++i) {
{
opj_j2k_tcp_destroy(l_current_tile); opj_j2k_tcp_destroy(l_current_tile);
++l_current_tile; ++l_current_tile;
} }
@ -7719,8 +7672,7 @@ static void opj_j2k_cp_destroy (opj_cp_t *p_cp)
p_cp->ppm_data = NULL; /* ppm_data belongs to the allocated buffer pointed by ppm_buffer */ p_cp->ppm_data = NULL; /* ppm_data belongs to the allocated buffer pointed by ppm_buffer */
opj_free(p_cp->comment); opj_free(p_cp->comment);
p_cp->comment = 00; p_cp->comment = 00;
if (! p_cp->m_is_decoder) if (! p_cp->m_is_decoder) {
{
opj_free(p_cp->m_specific_param.m_enc.m_matrice); opj_free(p_cp->m_specific_param.m_enc.m_matrice);
p_cp->m_specific_param.m_enc.m_matrice = 00; p_cp->m_specific_param.m_enc.m_matrice = 00;
} }
@ -7864,8 +7816,7 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Try to read until the Start Of Data is detected */ /* Try to read until the Start Of Data is detected */
while (l_current_marker != J2K_MS_SOD) { while (l_current_marker != J2K_MS_SOD) {
if(opj_stream_get_number_byte_left(p_stream) == 0) if(opj_stream_get_number_byte_left(p_stream) == 0) {
{
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
break; break;
} }
@ -7958,8 +7909,7 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Keep the position of the last SOT marker read */ /* Keep the position of the last SOT marker read */
if ( l_marker_handler->id == J2K_MS_SOT ) { if ( l_marker_handler->id == J2K_MS_SOT ) {
OPJ_UINT32 sot_pos = (OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4 ; OPJ_UINT32 sot_pos = (OPJ_UINT32) opj_stream_tell(p_stream) - l_marker_size - 4 ;
if (sot_pos > p_j2k->m_specific_param.m_decoder.m_last_sot_read_pos) if (sot_pos > p_j2k->m_specific_param.m_decoder.m_last_sot_read_pos) {
{
p_j2k->m_specific_param.m_decoder.m_last_sot_read_pos = sot_pos; p_j2k->m_specific_param.m_decoder.m_last_sot_read_pos = sot_pos;
} }
} }
@ -7971,8 +7921,7 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
return OPJ_FALSE; return OPJ_FALSE;
} }
l_current_marker = J2K_MS_SOD; /* Normally we reached a SOD */ l_current_marker = J2K_MS_SOD; /* Normally we reached a SOD */
} } else {
else {
/* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer*/ /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer*/
if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) { if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) {
opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n");
@ -8026,8 +7975,7 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
/* Read 2 bytes from buffer as the new marker ID */ /* Read 2 bytes from buffer as the new marker ID */
opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2); opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2);
} }
} } else {
else {
/* Indicate we will try to read a new tile-part header*/ /* Indicate we will try to read a new tile-part header*/
p_j2k->m_specific_param.m_decoder.m_skip_data = 0; p_j2k->m_specific_param.m_decoder.m_skip_data = 0;
p_j2k->m_specific_param.m_decoder.m_can_decode = 0; p_j2k->m_specific_param.m_decoder.m_can_decode = 0;
@ -8162,9 +8110,7 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k,
if (l_current_marker == J2K_MS_EOC) { if (l_current_marker == J2K_MS_EOC) {
p_j2k->m_current_tile_number = 0; p_j2k->m_current_tile_number = 0;
p_j2k->m_specific_param.m_decoder.m_state = 0x0100;/*FIXME J2K_DEC_STATE_EOC;*/ p_j2k->m_specific_param.m_decoder.m_state = 0x0100;/*FIXME J2K_DEC_STATE_EOC;*/
} } else if (l_current_marker != J2K_MS_SOT) {
else if (l_current_marker != J2K_MS_SOT)
{
if(opj_stream_get_number_byte_left(p_stream) == 0) { if(opj_stream_get_number_byte_left(p_stream) == 0) {
p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC;
opj_event_msg(p_manager, EVT_WARNING, "Stream does not end with EOC\n"); opj_event_msg(p_manager, EVT_WARNING, "Stream does not end with EOC\n");
@ -8269,21 +8215,18 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) {
l_width_dest = l_width_src; l_width_dest = l_width_src;
l_offset_x1_src = 0; l_offset_x1_src = 0;
} } else {
else {
l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ; l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ;
l_offset_x1_src = (OPJ_INT32)(l_width_src - l_width_dest); l_offset_x1_src = (OPJ_INT32)(l_width_src - l_width_dest);
} }
} } else {
else {
l_start_x_dest = 0U; l_start_x_dest = 0U;
l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0; l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0;
if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) {
l_width_dest = l_width_src - (OPJ_UINT32)l_offset_x0_src; l_width_dest = l_width_src - (OPJ_UINT32)l_offset_x0_src;
l_offset_x1_src = 0; l_offset_x1_src = 0;
} } else {
else {
l_width_dest = l_img_comp_dest->w ; l_width_dest = l_img_comp_dest->w ;
l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_dest; l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_dest;
} }
@ -8296,21 +8239,18 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) { if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) {
l_height_dest = l_height_src; l_height_dest = l_height_src;
l_offset_y1_src = 0; l_offset_y1_src = 0;
} } else {
else {
l_height_dest = l_y1_dest - (OPJ_UINT32)l_res->y0 ; l_height_dest = l_y1_dest - (OPJ_UINT32)l_res->y0 ;
l_offset_y1_src = (OPJ_INT32)(l_height_src - l_height_dest); l_offset_y1_src = (OPJ_INT32)(l_height_src - l_height_dest);
} }
} } else {
else {
l_start_y_dest = 0U; l_start_y_dest = 0U;
l_offset_y0_src = (OPJ_INT32)l_y0_dest - l_res->y0; l_offset_y0_src = (OPJ_INT32)l_y0_dest - l_res->y0;
if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) { if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) {
l_height_dest = l_height_src - (OPJ_UINT32)l_offset_y0_src; l_height_dest = l_height_src - (OPJ_UINT32)l_offset_y0_src;
l_offset_y1_src = 0; l_offset_y1_src = 0;
} } else {
else {
l_height_dest = l_img_comp_dest->h ; l_height_dest = l_img_comp_dest->h ;
l_offset_y1_src = l_res->y1 - (OPJ_INT32)l_y1_dest; l_offset_y1_src = l_res->y1 - (OPJ_INT32)l_y1_dest;
} }
@ -8352,8 +8292,7 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
}*/ }*/
switch (l_size_comp) { switch (l_size_comp) {
case 1: case 1: {
{
OPJ_CHAR * l_src_ptr = (OPJ_CHAR*) p_data; OPJ_CHAR * l_src_ptr = (OPJ_CHAR*) p_data;
l_src_ptr += l_start_offset_src; /* Move to the first place where we will read*/ l_src_ptr += l_start_offset_src; /* Move to the first place where we will read*/
@ -8366,8 +8305,7 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
l_dest_ptr+= l_line_offset_dest; /* Move to the next place where we will write */ l_dest_ptr+= l_line_offset_dest; /* Move to the next place where we will write */
l_src_ptr += l_line_offset_src ; /* Move to the next place where we will read */ l_src_ptr += l_line_offset_src ; /* Move to the next place where we will read */
} }
} } else {
else {
for ( j = 0 ; j < l_height_dest ; ++j ) { for ( j = 0 ; j < l_height_dest ; ++j ) {
for ( k = 0 ; k < l_width_dest ; ++k) { for ( k = 0 ; k < l_width_dest ; ++k) {
*(l_dest_ptr++) = (OPJ_INT32) ((*(l_src_ptr++))&0xff); *(l_dest_ptr++) = (OPJ_INT32) ((*(l_src_ptr++))&0xff);
@ -8382,8 +8320,7 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
p_data = (OPJ_BYTE*) l_src_ptr; /* Keep the current position for the next component-part */ p_data = (OPJ_BYTE*) l_src_ptr; /* Keep the current position for the next component-part */
} }
break; break;
case 2: case 2: {
{
OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_data; OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_data;
l_src_ptr += l_start_offset_src; l_src_ptr += l_start_offset_src;
@ -8396,8 +8333,7 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
l_dest_ptr+= l_line_offset_dest; l_dest_ptr+= l_line_offset_dest;
l_src_ptr += l_line_offset_src ; l_src_ptr += l_line_offset_src ;
} }
} } else {
else {
for (j=0; j<l_height_dest; ++j) { for (j=0; j<l_height_dest; ++j) {
for (k=0; k<l_width_dest; ++k) { for (k=0; k<l_width_dest; ++k) {
*(l_dest_ptr++) = (*(l_src_ptr++))&0xffff; *(l_dest_ptr++) = (*(l_src_ptr++))&0xffff;
@ -8412,8 +8348,7 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data,
p_data = (OPJ_BYTE*) l_src_ptr; p_data = (OPJ_BYTE*) l_src_ptr;
} }
break; break;
case 4: case 4: {
{
OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_data; OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_data;
l_src_ptr += l_start_offset_src; l_src_ptr += l_start_offset_src;
@ -8482,15 +8417,13 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
"Left position of the decoded area (region_x0=%d) is outside the image area (Xsiz=%d).\n", "Left position of the decoded area (region_x0=%d) is outside the image area (Xsiz=%d).\n",
p_start_x, l_image->x1); p_start_x, l_image->x1);
return OPJ_FALSE; return OPJ_FALSE;
} } else if ((OPJ_UINT32)p_start_x < l_image->x0) {
else if ((OPJ_UINT32)p_start_x < l_image->x0){
opj_event_msg(p_manager, EVT_WARNING, opj_event_msg(p_manager, EVT_WARNING,
"Left position of the decoded area (region_x0=%d) is outside the image area (XOsiz=%d).\n", "Left position of the decoded area (region_x0=%d) is outside the image area (XOsiz=%d).\n",
p_start_x, l_image->x0); p_start_x, l_image->x0);
p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0; p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0;
p_image->x0 = l_image->x0; p_image->x0 = l_image->x0;
} } else {
else {
p_j2k->m_specific_param.m_decoder.m_start_tile_x = ((OPJ_UINT32)p_start_x - l_cp->tx0) / l_cp->tdx; p_j2k->m_specific_param.m_decoder.m_start_tile_x = ((OPJ_UINT32)p_start_x - l_cp->tx0) / l_cp->tdx;
p_image->x0 = (OPJ_UINT32)p_start_x; p_image->x0 = (OPJ_UINT32)p_start_x;
} }
@ -8501,15 +8434,13 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
"Up position of the decoded area (region_y0=%d) is outside the image area (Ysiz=%d).\n", "Up position of the decoded area (region_y0=%d) is outside the image area (Ysiz=%d).\n",
p_start_y, l_image->y1); p_start_y, l_image->y1);
return OPJ_FALSE; return OPJ_FALSE;
} } else if ((OPJ_UINT32)p_start_y < l_image->y0) {
else if ((OPJ_UINT32)p_start_y < l_image->y0){
opj_event_msg(p_manager, EVT_WARNING, opj_event_msg(p_manager, EVT_WARNING,
"Up position of the decoded area (region_y0=%d) is outside the image area (YOsiz=%d).\n", "Up position of the decoded area (region_y0=%d) is outside the image area (YOsiz=%d).\n",
p_start_y, l_image->y0); p_start_y, l_image->y0);
p_j2k->m_specific_param.m_decoder.m_start_tile_y = 0; p_j2k->m_specific_param.m_decoder.m_start_tile_y = 0;
p_image->y0 = l_image->y0; p_image->y0 = l_image->y0;
} } else {
else {
p_j2k->m_specific_param.m_decoder.m_start_tile_y = ((OPJ_UINT32)p_start_y - l_cp->ty0) / l_cp->tdy; p_j2k->m_specific_param.m_decoder.m_start_tile_y = ((OPJ_UINT32)p_start_y - l_cp->ty0) / l_cp->tdy;
p_image->y0 = (OPJ_UINT32)p_start_y; p_image->y0 = (OPJ_UINT32)p_start_y;
} }
@ -8522,15 +8453,13 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
"Right position of the decoded area (region_x1=%d) is outside the image area (XOsiz=%d).\n", "Right position of the decoded area (region_x1=%d) is outside the image area (XOsiz=%d).\n",
p_end_x, l_image->x0); p_end_x, l_image->x0);
return OPJ_FALSE; return OPJ_FALSE;
} } else if ((OPJ_UINT32)p_end_x > l_image->x1) {
else if ((OPJ_UINT32)p_end_x > l_image->x1) {
opj_event_msg(p_manager, EVT_WARNING, opj_event_msg(p_manager, EVT_WARNING,
"Right position of the decoded area (region_x1=%d) is outside the image area (Xsiz=%d).\n", "Right position of the decoded area (region_x1=%d) is outside the image area (Xsiz=%d).\n",
p_end_x, l_image->x1); p_end_x, l_image->x1);
p_j2k->m_specific_param.m_decoder.m_end_tile_x = l_cp->tw; p_j2k->m_specific_param.m_decoder.m_end_tile_x = l_cp->tw;
p_image->x1 = l_image->x1; p_image->x1 = l_image->x1;
} } else {
else {
p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv(p_end_x - (OPJ_INT32)l_cp->tx0, (OPJ_INT32)l_cp->tdx); p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv(p_end_x - (OPJ_INT32)l_cp->tx0, (OPJ_INT32)l_cp->tdx);
p_image->x1 = (OPJ_UINT32)p_end_x; p_image->x1 = (OPJ_UINT32)p_end_x;
} }
@ -8548,8 +8477,7 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
p_end_y, l_image->y1); p_end_y, l_image->y1);
p_j2k->m_specific_param.m_decoder.m_end_tile_y = l_cp->th; p_j2k->m_specific_param.m_decoder.m_end_tile_y = l_cp->th;
p_image->y1 = l_image->y1; p_image->y1 = l_image->y1;
} } else {
else{
p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv(p_end_y - (OPJ_INT32)l_cp->ty0, (OPJ_INT32)l_cp->tdy); p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv(p_end_y - (OPJ_INT32)l_cp->ty0, (OPJ_INT32)l_cp->tdy);
p_image->y1 = (OPJ_UINT32)p_end_y; p_image->y1 = (OPJ_UINT32)p_end_y;
} }
@ -8558,8 +8486,7 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k,
p_j2k->m_specific_param.m_decoder.m_discard_tiles = 1; p_j2k->m_specific_param.m_decoder.m_discard_tiles = 1;
l_img_comp = p_image->comps; l_img_comp = p_image->comps;
for (it_comp=0; it_comp < p_image->numcomps; ++it_comp) for (it_comp=0; it_comp < p_image->numcomps; ++it_comp) {
{
OPJ_INT32 l_h,l_w; OPJ_INT32 l_h,l_w;
l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, (OPJ_INT32)l_img_comp->dx); l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, (OPJ_INT32)l_img_comp->dx);
@ -8694,8 +8621,7 @@ static OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size ( opj_j2k_t *p_j2k,
if (l_tccp->csty & J2K_CCP_CSTY_PRT) { if (l_tccp->csty & J2K_CCP_CSTY_PRT) {
return 5 + l_tccp->numresolutions; return 5 + l_tccp->numresolutions;
} } else {
else {
return 5; return 5;
} }
} }
@ -8906,8 +8832,7 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc( opj_j2k_t *p_j2k,
} }
*p_header_size = *p_header_size - l_tccp->numresolutions; *p_header_size = *p_header_size - l_tccp->numresolutions;
} } else {
else {
/* set default size for the precinct width and height */ /* set default size for the precinct width and height */
for (i = 0; i < l_tccp->numresolutions; ++i) { for (i = 0; i < l_tccp->numresolutions; ++i) {
l_tccp->prcw[i] = 15; l_tccp->prcw[i] = 15;
@ -8993,8 +8918,7 @@ static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size ( opj_j2k_t *p_j2k,
if (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { if (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
return 1 + l_num_bands; return 1 + l_num_bands;
} } else {
else {
return 1 + 2*l_num_bands; return 1 + 2*l_num_bands;
} }
} }
@ -9035,8 +8959,7 @@ static OPJ_BOOL opj_j2k_compare_SQcd_SQcc(opj_j2k_t *p_j2k, OPJ_UINT32 p_tile_no
return OPJ_FALSE; return OPJ_FALSE;
} }
} }
if (l_tccp0->qntsty != J2K_CCP_QNTSTY_NOQNT) if (l_tccp0->qntsty != J2K_CCP_QNTSTY_NOQNT) {
{
for (l_band_no = 0; l_band_no < l_num_bands; ++l_band_no) { for (l_band_no = 0; l_band_no < l_num_bands; ++l_band_no) {
if (l_tccp0->stepsizes[l_band_no].mant != l_tccp1->stepsizes[l_band_no].mant ) { if (l_tccp0->stepsizes[l_band_no].mant != l_tccp1->stepsizes[l_band_no].mant ) {
return OPJ_FALSE; return OPJ_FALSE;
@ -9094,8 +9017,7 @@ static OPJ_BOOL opj_j2k_write_SQcd_SQcc( opj_j2k_t *p_j2k,
opj_write_bytes(p_data, l_expn << 3, 1); /* SPqcx_i */ opj_write_bytes(p_data, l_expn << 3, 1); /* SPqcx_i */
++p_data; ++p_data;
} }
} } else {
else {
l_header_size = 1 + 2*l_num_bands; l_header_size = 1 + 2*l_num_bands;
if (*p_header_size < l_header_size) { if (*p_header_size < l_header_size) {
@ -9165,8 +9087,7 @@ static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k,
l_tccp->numgbits = l_tmp >> 5; l_tccp->numgbits = l_tmp >> 5;
if (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) { if (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) {
l_num_band = 1; l_num_band = 1;
} } else {
else {
l_num_band = (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) ? l_num_band = (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) ?
(*p_header_size) : (*p_header_size) :
(*p_header_size) / 2; (*p_header_size) / 2;
@ -9211,8 +9132,7 @@ static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k,
} }
} }
*p_header_size = *p_header_size - l_num_band; *p_header_size = *p_header_size - l_num_band;
} } else {
else {
for (l_band_no = 0; l_band_no < l_num_band; l_band_no++) { for (l_band_no = 0; l_band_no < l_num_band; l_band_no++) {
opj_read_bytes(l_current_ptr, &l_tmp ,2); /* SPqcx_i */ opj_read_bytes(l_current_ptr, &l_tmp ,2); /* SPqcx_i */
l_current_ptr+=2; l_current_ptr+=2;
@ -9268,8 +9188,7 @@ static void opj_j2k_copy_tile_quantization_parameters( opj_j2k_t *p_j2k )
static void opj_j2k_dump_tile_info( opj_tcp_t * l_default_tile,OPJ_INT32 numcomps,FILE* out_stream) static void opj_j2k_dump_tile_info( opj_tcp_t * l_default_tile,OPJ_INT32 numcomps,FILE* out_stream)
{ {
if (l_default_tile) if (l_default_tile) {
{
OPJ_INT32 compno; OPJ_INT32 compno;
fprintf(out_stream, "\t default tile {\n"); fprintf(out_stream, "\t default tile {\n");
@ -9396,8 +9315,7 @@ static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream)
l_acc_nb_of_tile_part += cstr_index->tile_index[it_tile].nb_tps; l_acc_nb_of_tile_part += cstr_index->tile_index[it_tile].nb_tps;
} }
if (l_acc_nb_of_tile_part) if (l_acc_nb_of_tile_part) {
{
fprintf(out_stream, "\t Tile index: {\n"); fprintf(out_stream, "\t Tile index: {\n");
for (it_tile=0; it_tile < cstr_index->nb_of_tiles ; it_tile++) { for (it_tile=0; it_tile < cstr_index->nb_of_tiles ; it_tile++) {
@ -9452,10 +9370,10 @@ void j2k_dump_image_header(opj_image_t* img_header, OPJ_BOOL dev_dump_flag, FILE
if (dev_dump_flag) { if (dev_dump_flag) {
fprintf(stdout, "[DEV] Dump an image_header struct {\n"); fprintf(stdout, "[DEV] Dump an image_header struct {\n");
tab[0] = '\0'; tab[0] = '\0';
} } else {
else {
fprintf(out_stream, "Image info {\n"); fprintf(out_stream, "Image info {\n");
tab[0] = '\t';tab[1] = '\0'; tab[0] = '\t';
tab[1] = '\0';
} }
fprintf(out_stream, "%s x0=%d, y0=%d\n", tab, img_header->x0, img_header->y0); fprintf(out_stream, "%s x0=%d, y0=%d\n", tab, img_header->x0, img_header->y0);
@ -9482,7 +9400,9 @@ void j2k_dump_image_comp_header(opj_image_comp_t* comp_header, OPJ_BOOL dev_dump
fprintf(stdout, "[DEV] Dump an image_comp_header struct {\n"); fprintf(stdout, "[DEV] Dump an image_comp_header struct {\n");
tab[0] = '\0'; tab[0] = '\0';
} else { } else {
tab[0] = '\t';tab[1] = '\t';tab[2] = '\0'; tab[0] = '\t';
tab[1] = '\t';
tab[2] = '\0';
} }
fprintf(out_stream, "%s dx=%d, dy=%d\n", tab, comp_header->dx, comp_header->dy); fprintf(out_stream, "%s dx=%d, dy=%d\n", tab, comp_header->dx, comp_header->dy);
@ -9521,8 +9441,7 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k)
cstr_info->m_default_tile_info.mct = l_default_tile->mct; cstr_info->m_default_tile_info.mct = l_default_tile->mct;
cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc(cstr_info->nbcomps, sizeof(opj_tccp_info_t)); cstr_info->m_default_tile_info.tccp_info = (opj_tccp_info_t*) opj_calloc(cstr_info->nbcomps, sizeof(opj_tccp_info_t));
if (!cstr_info->m_default_tile_info.tccp_info) if (!cstr_info->m_default_tile_info.tccp_info) {
{
opj_destroy_cstr_info(&cstr_info); opj_destroy_cstr_info(&cstr_info);
return NULL; return NULL;
} }
@ -9539,8 +9458,7 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k)
l_tccp_info->cblkh = l_tccp->cblkh; l_tccp_info->cblkh = l_tccp->cblkh;
l_tccp_info->cblksty = l_tccp->cblksty; l_tccp_info->cblksty = l_tccp->cblksty;
l_tccp_info->qmfbid = l_tccp->qmfbid; l_tccp_info->qmfbid = l_tccp->qmfbid;
if (l_tccp->numresolutions < OPJ_J2K_MAXRLVLS) if (l_tccp->numresolutions < OPJ_J2K_MAXRLVLS) {
{
memcpy(l_tccp_info->prch, l_tccp->prch, l_tccp->numresolutions); memcpy(l_tccp_info->prch, l_tccp->prch, l_tccp->numresolutions);
memcpy(l_tccp_info->prcw, l_tccp->prcw, l_tccp->numresolutions); memcpy(l_tccp_info->prcw, l_tccp->prcw, l_tccp->numresolutions);
} }
@ -9600,8 +9518,7 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k)
if (!p_j2k->cstr_index->tile_index) { if (!p_j2k->cstr_index->tile_index) {
opj_free(l_cstr_index->tile_index); opj_free(l_cstr_index->tile_index);
l_cstr_index->tile_index = NULL; l_cstr_index->tile_index = NULL;
} } else {
else {
OPJ_UINT32 it_tile = 0; OPJ_UINT32 it_tile = 0;
for (it_tile = 0; it_tile < l_cstr_index->nb_of_tiles; it_tile++ ) { for (it_tile = 0; it_tile < l_cstr_index->nb_of_tiles; it_tile++ ) {
@ -9657,8 +9574,7 @@ opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k)
memcpy( l_cstr_index->tile_index[it_tile].tp_index, memcpy( l_cstr_index->tile_index[it_tile].tp_index,
p_j2k->cstr_index->tile_index[it_tile].tp_index, p_j2k->cstr_index->tile_index[it_tile].tp_index,
l_cstr_index->tile_index[it_tile].nb_tps * sizeof(opj_tp_index_t) ); l_cstr_index->tile_index[it_tile].nb_tps * sizeof(opj_tp_index_t) );
} } else {
else{
opj_free(l_cstr_index->tile_index[it_tile].tp_index); opj_free(l_cstr_index->tile_index[it_tile].tp_index);
l_cstr_index->tile_index[it_tile].tp_index = NULL; l_cstr_index->tile_index[it_tile].tp_index = NULL;
} }
@ -9807,8 +9723,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
l_max_data_size = 1000; l_max_data_size = 1000;
/*Allocate and initialize some elements of codestrem index if not already done*/ /*Allocate and initialize some elements of codestrem index if not already done*/
if( !p_j2k->cstr_index->tile_index) if( !p_j2k->cstr_index->tile_index) {
{
if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)) { if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)) {
opj_free(l_current_data); opj_free(l_current_data);
return OPJ_FALSE; return OPJ_FALSE;
@ -9817,8 +9732,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
/* Move into the codestream to the first SOT used to decode the desired tile */ /* Move into the codestream to the first SOT used to decode the desired tile */
l_tile_no_to_dec = (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec; l_tile_no_to_dec = (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec;
if (p_j2k->cstr_index->tile_index) if (p_j2k->cstr_index->tile_index)
if(p_j2k->cstr_index->tile_index->tp_index) if(p_j2k->cstr_index->tile_index->tp_index) {
{
if ( ! p_j2k->cstr_index->tile_index[l_tile_no_to_dec].nb_tps) { if ( ! p_j2k->cstr_index->tile_index[l_tile_no_to_dec].nb_tps) {
/* the index for this tile has not been built, /* the index for this tile has not been built,
* so move to the last SOT read */ * so move to the last SOT read */
@ -9827,8 +9741,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
opj_free(l_current_data); opj_free(l_current_data);
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else{
if ( !(opj_stream_read_seek(p_stream, p_j2k->cstr_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos+2, p_manager)) ) { if ( !(opj_stream_read_seek(p_stream, p_j2k->cstr_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos+2, p_manager)) ) {
opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n");
opj_free(l_current_data); opj_free(l_current_data);
@ -9882,8 +9795,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
} }
opj_event_msg(p_manager, EVT_INFO, "Image data has been updated with tile %d.\n\n", l_current_tile_no+1); opj_event_msg(p_manager, EVT_INFO, "Image data has been updated with tile %d.\n\n", l_current_tile_no+1);
if(l_current_tile_no == l_tile_no_to_dec) if(l_current_tile_no == l_tile_no_to_dec) {
{
/* move into the codestream to the first SOT (FIXME or not move?)*/ /* move into the codestream to the first SOT (FIXME or not move?)*/
if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) ) { if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index->main_head_end + 2, p_manager) ) ) {
opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n");
@ -9891,8 +9803,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
return OPJ_FALSE; return OPJ_FALSE;
} }
break; break;
} } else {
else {
opj_event_msg(p_manager, EVT_WARNING, "Tile read, decoded and updated is not the desired one (%d vs %d).\n", l_current_tile_no+1, l_tile_no_to_dec+1); opj_event_msg(p_manager, EVT_WARNING, "Tile read, decoded and updated is not the desired one (%d vs %d).\n", l_current_tile_no+1, l_tile_no_to_dec+1);
} }
@ -10002,8 +9913,7 @@ OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k,
p_image->y1 = p_j2k->m_private_image->y1; p_image->y1 = p_j2k->m_private_image->y1;
l_img_comp = p_image->comps; l_img_comp = p_image->comps;
for (compno=0; compno < p_image->numcomps; ++compno) for (compno=0; compno < p_image->numcomps; ++compno) {
{
OPJ_INT32 l_comp_x1, l_comp_y1; OPJ_INT32 l_comp_x1, l_comp_y1;
l_img_comp->factor = p_j2k->m_private_image->comps[compno].factor; l_img_comp->factor = p_j2k->m_private_image->comps[compno].factor;
@ -10193,8 +10103,7 @@ OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
return OPJ_FALSE; return OPJ_FALSE;
} }
if (! opj_j2k_exec (p_j2k, p_j2k->m_procedure_list, p_stream, p_manager)) if (! opj_j2k_exec (p_j2k, p_j2k->m_procedure_list, p_stream, p_manager)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -10288,7 +10197,8 @@ static void opj_get_tile_dimensions(opj_image_t * l_image,
OPJ_UINT32* l_offset_y, OPJ_UINT32* l_offset_y,
OPJ_UINT32* l_image_width, OPJ_UINT32* l_image_width,
OPJ_UINT32* l_stride, OPJ_UINT32* l_stride,
OPJ_UINT32* l_tile_offset) { OPJ_UINT32* l_tile_offset)
{
OPJ_UINT32 l_remaining; OPJ_UINT32 l_remaining;
*l_size_comp = l_img_comp->prec >> 3; /* (/8) */ *l_size_comp = l_img_comp->prec >> 3; /* (/8) */
l_remaining = l_img_comp->prec & 7; /* (%8) */ l_remaining = l_img_comp->prec & 7; /* (%8) */
@ -10335,8 +10245,7 @@ static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data)
l_src_ptr = l_img_comp->data + l_tile_offset; l_src_ptr = l_img_comp->data + l_tile_offset;
switch (l_size_comp) { switch (l_size_comp) {
case 1: case 1: {
{
OPJ_CHAR * l_dest_ptr = (OPJ_CHAR*) p_data; OPJ_CHAR * l_dest_ptr = (OPJ_CHAR*) p_data;
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
@ -10347,8 +10256,7 @@ static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data)
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
} }
} } else {
else {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) { for (k=0; k<l_width; ++k) {
*(l_dest_ptr) = (OPJ_CHAR)((*l_src_ptr)&0xff); *(l_dest_ptr) = (OPJ_CHAR)((*l_src_ptr)&0xff);
@ -10362,8 +10270,7 @@ static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data)
p_data = (OPJ_BYTE*) l_dest_ptr; p_data = (OPJ_BYTE*) l_dest_ptr;
} }
break; break;
case 2: case 2: {
{
OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_data; OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_data;
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
@ -10372,8 +10279,7 @@ static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data)
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
} }
} } else {
else {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) { for (k=0; k<l_width; ++k) {
*(l_dest_ptr++) = (OPJ_INT16)((*(l_src_ptr++)) & 0xffff); *(l_dest_ptr++) = (OPJ_INT16)((*(l_src_ptr++)) & 0xffff);
@ -10385,8 +10291,7 @@ static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data)
p_data = (OPJ_BYTE*) l_dest_ptr; p_data = (OPJ_BYTE*) l_dest_ptr;
} }
break; break;
case 4: case 4: {
{
OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_data; OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_data;
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) { for (k=0; k<l_width; ++k) {
@ -10595,8 +10500,7 @@ static OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k,
l_current_nb_bytes_written = 0; l_current_nb_bytes_written = 0;
l_begin_data = p_data; l_begin_data = p_data;
if (! opj_j2k_write_sot(p_j2k,p_data,&l_current_nb_bytes_written,p_stream,p_manager)) if (! opj_j2k_write_sot(p_j2k,p_data,&l_current_nb_bytes_written,p_stream,p_manager)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -10937,8 +10841,7 @@ OPJ_BOOL opj_j2k_write_tile (opj_j2k_t * p_j2k,
if (! opj_j2k_pre_write_tile(p_j2k,p_tile_index,p_stream,p_manager)) { if (! opj_j2k_pre_write_tile(p_j2k,p_tile_index,p_stream,p_manager)) {
opj_event_msg(p_manager, EVT_ERROR, "Error while opj_j2k_pre_write_tile with tile index = %d\n", p_tile_index); opj_event_msg(p_manager, EVT_ERROR, "Error while opj_j2k_pre_write_tile with tile index = %d\n", p_tile_index);
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else {
OPJ_UINT32 j; OPJ_UINT32 j;
/* Allocate data */ /* Allocate data */
for (j=0; j<p_j2k->m_tcd->image->numcomps; ++j) { for (j=0; j<p_j2k->m_tcd->image->numcomps; ++j) {

View File

@ -132,8 +132,7 @@ typedef enum J2K_STATUS {
/** /**
* Type of elements storing in the MCT data * Type of elements storing in the MCT data
*/ */
typedef enum MCT_ELEMENT_TYPE typedef enum MCT_ELEMENT_TYPE {
{
MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/ MCT_TYPE_INT16 = 0, /** MCT data is stored as signed shorts*/
MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/ MCT_TYPE_INT32 = 1, /** MCT data is stored as signed integers*/
MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/ MCT_TYPE_FLOAT = 2, /** MCT data is stored as floats*/
@ -143,8 +142,7 @@ typedef enum MCT_ELEMENT_TYPE
/** /**
* Type of MCT array * Type of MCT array
*/ */
typedef enum MCT_ARRAY_TYPE typedef enum MCT_ARRAY_TYPE {
{
MCT_TYPE_DEPENDENCY = 0, MCT_TYPE_DEPENDENCY = 0,
MCT_TYPE_DECORRELATION = 1, MCT_TYPE_DECORRELATION = 1,
MCT_TYPE_OFFSET = 2 MCT_TYPE_OFFSET = 2
@ -173,8 +171,7 @@ typedef struct opj_stepsize {
/** /**
Tile-component coding parameters Tile-component coding parameters
*/ */
typedef struct opj_tccp typedef struct opj_tccp {
{
/** coding style */ /** coding style */
OPJ_UINT32 csty; OPJ_UINT32 csty;
/** number of resolutions */ /** number of resolutions */
@ -209,8 +206,7 @@ opj_tccp_t;
/** /**
* FIXME DOC * FIXME DOC
*/ */
typedef struct opj_mct_data typedef struct opj_mct_data {
{
J2K_MCT_ELEMENT_TYPE m_element_type; J2K_MCT_ELEMENT_TYPE m_element_type;
J2K_MCT_ARRAY_TYPE m_array_type; J2K_MCT_ARRAY_TYPE m_array_type;
OPJ_UINT32 m_index; OPJ_UINT32 m_index;
@ -222,8 +218,7 @@ opj_mct_data_t;
/** /**
* FIXME DOC * FIXME DOC
*/ */
typedef struct opj_simple_mcc_decorrelation_data typedef struct opj_simple_mcc_decorrelation_data {
{
OPJ_UINT32 m_index; OPJ_UINT32 m_index;
OPJ_UINT32 m_nb_comps; OPJ_UINT32 m_nb_comps;
opj_mct_data_t * m_decorrelation_array; opj_mct_data_t * m_decorrelation_array;
@ -232,8 +227,7 @@ typedef struct opj_simple_mcc_decorrelation_data
} }
opj_simple_mcc_decorrelation_data_t; opj_simple_mcc_decorrelation_data_t;
typedef struct opj_ppx_struct typedef struct opj_ppx_struct {
{
OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */ OPJ_BYTE* m_data; /* m_data == NULL => Zppx not read yet */
OPJ_UINT32 m_data_size; OPJ_UINT32 m_data_size;
} opj_ppx; } opj_ppx;
@ -243,8 +237,7 @@ Tile coding parameters :
this structure is used to store coding/decoding parameters common to all this structure is used to store coding/decoding parameters common to all
tiles (information like COD, COC in main header) tiles (information like COD, COC in main header)
*/ */
typedef struct opj_tcp typedef struct opj_tcp {
{
/** coding style */ /** coding style */
OPJ_UINT32 csty; OPJ_UINT32 csty;
/** progression order */ /** progression order */
@ -316,8 +309,7 @@ typedef struct opj_tcp
typedef struct opj_encoding_param typedef struct opj_encoding_param {
{
/** Maximum rate for each component. If == 0, component size limitation is not considered */ /** Maximum rate for each component. If == 0, component size limitation is not considered */
OPJ_UINT32 m_max_comp_size; OPJ_UINT32 m_max_comp_size;
/** Position of tile part flag in progression order*/ /** Position of tile part flag in progression order*/
@ -337,8 +329,7 @@ typedef struct opj_encoding_param
} }
opj_encoding_param_t; opj_encoding_param_t;
typedef struct opj_decoding_param typedef struct opj_decoding_param {
{
/** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */ /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, image is decoded to the full resolution */
OPJ_UINT32 m_reduce; OPJ_UINT32 m_reduce;
/** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
@ -350,8 +341,7 @@ opj_decoding_param_t;
/** /**
* Coding parameters * Coding parameters
*/ */
typedef struct opj_cp typedef struct opj_cp {
{
/** Size of the image in bits*/ /** Size of the image in bits*/
/*int img_size;*/ /*int img_size;*/
/** Rsiz*/ /** Rsiz*/
@ -399,8 +389,7 @@ typedef struct opj_cp
/** tile coding parameters */ /** tile coding parameters */
opj_tcp_t *tcps; opj_tcp_t *tcps;
union union {
{
opj_decoding_param_t m_dec; opj_decoding_param_t m_dec;
opj_encoding_param_t m_enc; opj_encoding_param_t m_enc;
} }
@ -460,8 +449,7 @@ typedef struct opj_cp
} opj_cp_t; } opj_cp_t;
typedef struct opj_j2k_dec typedef struct opj_j2k_dec {
{
/** locate in which part of the codestream the decoder is (main header, tile header, end) */ /** locate in which part of the codestream the decoder is (main header, tile header, end) */
OPJ_UINT32 m_state; OPJ_UINT32 m_state;
/** /**
@ -506,8 +494,7 @@ typedef struct opj_j2k_dec
} opj_j2k_dec_t; } opj_j2k_dec_t;
typedef struct opj_j2k_enc typedef struct opj_j2k_enc {
{
/** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/ /** Tile part number, regardless of poc, for each new poc, tp is reset to 1*/
OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */ OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
@ -553,14 +540,12 @@ struct opj_tcd;
/** /**
JPEG-2000 codestream reader/writer JPEG-2000 codestream reader/writer
*/ */
typedef struct opj_j2k typedef struct opj_j2k {
{
/* J2K codestream is decoded*/ /* J2K codestream is decoded*/
OPJ_BOOL m_is_decoder; OPJ_BOOL m_is_decoder;
/* FIXME DOC*/ /* FIXME DOC*/
union union {
{
opj_j2k_dec_t m_decoder; opj_j2k_dec_t m_decoder;
opj_j2k_enc_t m_encoder; opj_j2k_enc_t m_encoder;
} }

View File

@ -410,15 +410,13 @@ static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_i
*/ */
static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id ); static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id );
static const opj_jp2_header_handler_t jp2_header [] = static const opj_jp2_header_handler_t jp2_header [] = {
{
{JP2_JP,opj_jp2_read_jp}, {JP2_JP,opj_jp2_read_jp},
{JP2_FTYP,opj_jp2_read_ftyp}, {JP2_FTYP,opj_jp2_read_ftyp},
{JP2_JP2H,opj_jp2_read_jp2h} {JP2_JP2H,opj_jp2_read_jp2h}
}; };
static const opj_jp2_header_handler_t jp2_img_header [] = static const opj_jp2_header_handler_t jp2_img_header [] = {
{
{JP2_IHDR,opj_jp2_read_ihdr}, {JP2_IHDR,opj_jp2_read_ihdr},
{JP2_COLR,opj_jp2_read_colr}, {JP2_COLR,opj_jp2_read_colr},
{JP2_BPCC,opj_jp2_read_bpcc}, {JP2_BPCC,opj_jp2_read_bpcc},
@ -481,8 +479,7 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
opj_read_bytes(l_data_header,&(box->length), 4); opj_read_bytes(l_data_header,&(box->length), 4);
opj_read_bytes(l_data_header+4,&(box->type), 4); opj_read_bytes(l_data_header+4,&(box->type), 4);
if(box->length == 0)/* last box */ if(box->length == 0) { /* last box */
{
const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio); const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio);
if (bleft > (OPJ_OFF_T)(0xFFFFFFFFU - 8U)) { if (bleft > (OPJ_OFF_T)(0xFFFFFFFFU - 8U)) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n"); opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n");
@ -519,7 +516,8 @@ static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box,
} }
#if 0 #if 0
static void jp2_write_url(opj_cio_t *cio, char *Idx_file) { static void jp2_write_url(opj_cio_t *cio, char *Idx_file)
{
OPJ_UINT32 i; OPJ_UINT32 i;
opj_jp2_box_t box; opj_jp2_box_t box;
@ -806,7 +804,8 @@ static OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2,
++l_current_colr_ptr; ++l_current_colr_ptr;
if (jp2->meth == 1) { /* Meth value is restricted to 1 or 2 (Table I.9 of part 1) */ if (jp2->meth == 1) { /* Meth value is restricted to 1 or 2 (Table I.9 of part 1) */
opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4); } /* EnumCS */ opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4);
} /* EnumCS */
else { else {
if (jp2->meth == 2) { /* ICC profile */ if (jp2->meth == 2) { /* ICC profile */
OPJ_UINT32 i; OPJ_UINT32 i;
@ -830,7 +829,8 @@ static void opj_jp2_free_pclr(opj_jp2_color_t *color)
if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap); if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap);
opj_free(color->jp2_pclr); color->jp2_pclr = NULL; opj_free(color->jp2_pclr);
color->jp2_pclr = NULL;
} }
static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *p_manager) static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *p_manager)
@ -863,8 +863,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
/* issue 397 */ /* issue 397 */
/* ISO 15444-1 states that if cdef is present, it shall contain a complete list of channel definitions. */ /* ISO 15444-1 states that if cdef is present, it shall contain a complete list of channel definitions. */
while (nr_channels > 0) while (nr_channels > 0) {
{
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
if ((OPJ_UINT32)info[i].cn == (nr_channels - 1U)) { if ((OPJ_UINT32)info[i].cn == (nr_channels - 1U)) {
break; break;
@ -905,18 +904,15 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
if (pcol >= nr_channels) { if (pcol >= nr_channels) {
opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol); opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol);
is_sane = OPJ_FALSE; is_sane = OPJ_FALSE;
} } else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
else if (pcol_usage[pcol] && cmap[i].mtyp == 1) {
opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol); opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol);
is_sane = OPJ_FALSE; is_sane = OPJ_FALSE;
} } else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) {
else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) {
/* I.5.3.5 PCOL: If the value of the MTYP field for this channel is 0, then /* I.5.3.5 PCOL: If the value of the MTYP field for this channel is 0, then
* the value of this field shall be 0. */ * the value of this field shall be 0. */
opj_event_msg(p_manager, EVT_ERROR, "Direct use at #%d however pcol=%d.\n", i, pcol); opj_event_msg(p_manager, EVT_ERROR, "Direct use at #%d however pcol=%d.\n", i, pcol);
is_sane = OPJ_FALSE; is_sane = OPJ_FALSE;
} } else
else
pcol_usage[pcol] = OPJ_TRUE; pcol_usage[pcol] = OPJ_TRUE;
} }
/* verify that all components are targeted at least once */ /* verify that all components are targeted at least once */
@ -979,7 +975,8 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
return; return;
} }
for(i = 0; i < nr_channels; ++i) { for(i = 0; i < nr_channels; ++i) {
pcol = cmap[i].pcol; cmp = cmap[i].cmp; pcol = cmap[i].pcol;
cmp = cmap[i].cmp;
/* Direct use */ /* Direct use */
if(cmap[i].mtyp == 0) { if(cmap[i].mtyp == 0) {
@ -1008,7 +1005,8 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
for(i = 0; i < nr_channels; ++i) { for(i = 0; i < nr_channels; ++i) {
/* Palette mapping: */ /* Palette mapping: */
cmp = cmap[i].cmp; pcol = cmap[i].pcol; cmp = cmap[i].cmp;
pcol = cmap[i].pcol;
src = old_comps[cmp].data; src = old_comps[cmp].data;
assert( src ); assert( src );
max = new_comps[pcol].w * new_comps[pcol].h; max = new_comps[pcol].w * new_comps[pcol].h;
@ -1021,14 +1019,14 @@ static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color)
for(j = 0; j < max; ++j) { for(j = 0; j < max; ++j) {
dst[j] = src[j]; dst[j] = src[j];
} }
} } else {
else {
assert( i == pcol ); assert( i == pcol );
dst = new_comps[pcol].data; dst = new_comps[pcol].data;
assert( dst ); assert( dst );
for(j = 0; j < max; ++j) { for(j = 0; j < max; ++j) {
/* The index */ /* The index */
if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; if((k = src[j]) < 0) k = 0;
else if(k > top_k) k = top_k;
/* The colour */ /* The colour */
dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol]; dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol];
@ -1098,22 +1096,19 @@ static OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2,
if (!entries) if (!entries)
return OPJ_FALSE; return OPJ_FALSE;
channel_size = (OPJ_BYTE*) opj_malloc(nr_channels); channel_size = (OPJ_BYTE*) opj_malloc(nr_channels);
if (!channel_size) if (!channel_size) {
{
opj_free(entries); opj_free(entries);
return OPJ_FALSE; return OPJ_FALSE;
} }
channel_sign = (OPJ_BYTE*) opj_malloc(nr_channels); channel_sign = (OPJ_BYTE*) opj_malloc(nr_channels);
if (!channel_sign) if (!channel_sign) {
{
opj_free(entries); opj_free(entries);
opj_free(channel_size); opj_free(channel_size);
return OPJ_FALSE; return OPJ_FALSE;
} }
jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t)); jp2_pclr = (opj_jp2_pclr_t*)opj_malloc(sizeof(opj_jp2_pclr_t));
if (!jp2_pclr) if (!jp2_pclr) {
{
opj_free(entries); opj_free(entries);
opj_free(channel_size); opj_free(channel_size);
opj_free(channel_sign); opj_free(channel_sign);
@ -1224,33 +1219,28 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
info = color->jp2_cdef->info; info = color->jp2_cdef->info;
n = color->jp2_cdef->n; n = color->jp2_cdef->n;
for(i = 0; i < n; ++i) for(i = 0; i < n; ++i) {
{
/* WATCH: acn = asoc - 1 ! */ /* WATCH: acn = asoc - 1 ! */
asoc = info[i].asoc; asoc = info[i].asoc;
cn = info[i].cn; cn = info[i].cn;
if( cn >= image->numcomps) if( cn >= image->numcomps) {
{
opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef: cn=%d, numcomps=%d\n", cn, image->numcomps); opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef: cn=%d, numcomps=%d\n", cn, image->numcomps);
continue; continue;
} }
if(asoc == 0 || asoc == 65535) if(asoc == 0 || asoc == 65535) {
{
image->comps[cn].alpha = info[i].typ; image->comps[cn].alpha = info[i].typ;
continue; continue;
} }
acn = (OPJ_UINT16)(asoc - 1); acn = (OPJ_UINT16)(asoc - 1);
if( acn >= image->numcomps ) if( acn >= image->numcomps ) {
{
opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef: acn=%d, numcomps=%d\n", acn, image->numcomps); opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef: acn=%d, numcomps=%d\n", acn, image->numcomps);
continue; continue;
} }
/* Swap only if color channel */ /* Swap only if color channel */
if((cn != acn) && (info[i].typ == 0)) if((cn != acn) && (info[i].typ == 0)) {
{
opj_image_comp_t saved; opj_image_comp_t saved;
OPJ_UINT16 j; OPJ_UINT16 j;
@ -1259,12 +1249,10 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t)); memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t));
/* Swap channels in following channel definitions, don't bother with j <= i that are already processed */ /* Swap channels in following channel definitions, don't bother with j <= i that are already processed */
for (j = (OPJ_UINT16)(i + 1U); j < n ; ++j) for (j = (OPJ_UINT16)(i + 1U); j < n ; ++j) {
{
if (info[j].cn == cn) { if (info[j].cn == cn) {
info[j].cn = acn; info[j].cn = acn;
} } else if (info[j].cn == acn) {
else if (info[j].cn == acn) {
info[j].cn = cn; info[j].cn = cn;
} }
/* asoc is related to color index. Do not update. */ /* asoc is related to color index. Do not update. */
@ -1276,7 +1264,8 @@ static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info);
opj_free(color->jp2_cdef); color->jp2_cdef = NULL; opj_free(color->jp2_cdef);
color->jp2_cdef = NULL;
}/* jp2_apply_cdef() */ }/* jp2_apply_cdef() */
@ -1323,8 +1312,7 @@ static OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
return OPJ_FALSE; return OPJ_FALSE;
jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)); jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t));
if(!jp2->color.jp2_cdef) if(!jp2->color.jp2_cdef) {
{
opj_free(cdef_info); opj_free(cdef_info);
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -1398,8 +1386,7 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
p_colr_header_data += 4; p_colr_header_data += 4;
if(jp2->enumcs == 14)/* CIELab */ if(jp2->enumcs == 14) { /* CIELab */
{
OPJ_UINT32 *cielab; OPJ_UINT32 *cielab;
OPJ_UINT32 rl, ol, ra, oa, rb, ob, il; OPJ_UINT32 rl, ol, ra, oa, rb, ob, il;
@ -1411,8 +1398,7 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
il = 0x00443530; /* D50 */ il = 0x00443530; /* D50 */
cielab[1] = 0x44454600;/* DEF */ cielab[1] = 0x44454600;/* DEF */
if(p_colr_header_size == 35) if(p_colr_header_size == 35) {
{
opj_read_bytes(p_colr_header_data, &rl, 4); opj_read_bytes(p_colr_header_data, &rl, 4);
p_colr_header_data += 4; p_colr_header_data += 4;
opj_read_bytes(p_colr_header_data, &ol, 4); opj_read_bytes(p_colr_header_data, &ol, 4);
@ -1429,44 +1415,41 @@ static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2,
p_colr_header_data += 4; p_colr_header_data += 4;
cielab[1] = 0; cielab[1] = 0;
} } else if(p_colr_header_size != 7) {
else if(p_colr_header_size != 7)
{
opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (CIELab, bad size: %d)\n", p_colr_header_size); opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (CIELab, bad size: %d)\n", p_colr_header_size);
} }
cielab[2] = rl; cielab[4] = ra; cielab[6] = rb; cielab[2] = rl;
cielab[3] = ol; cielab[5] = oa; cielab[7] = ob; cielab[4] = ra;
cielab[6] = rb;
cielab[3] = ol;
cielab[5] = oa;
cielab[7] = ob;
cielab[8] = il; cielab[8] = il;
jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab; jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab;
jp2->color.icc_profile_len = 0; jp2->color.icc_profile_len = 0;
} }
jp2->color.jp2_has_colr = 1; jp2->color.jp2_has_colr = 1;
} } else if (jp2->meth == 2) {
else if (jp2->meth == 2) {
/* ICC profile */ /* ICC profile */
OPJ_INT32 it_icc_value = 0; OPJ_INT32 it_icc_value = 0;
OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3; OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3;
jp2->color.icc_profile_len = (OPJ_UINT32)icc_len; jp2->color.icc_profile_len = (OPJ_UINT32)icc_len;
jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)icc_len); jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)icc_len);
if (!jp2->color.icc_profile_buf) if (!jp2->color.icc_profile_buf) {
{
jp2->color.icc_profile_len = 0; jp2->color.icc_profile_len = 0;
return OPJ_FALSE; return OPJ_FALSE;
} }
for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value) for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value) {
{
opj_read_bytes(p_colr_header_data,&l_value,1); /* icc values */ opj_read_bytes(p_colr_header_data,&l_value,1); /* icc values */
++p_colr_header_data; ++p_colr_header_data;
jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value; jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value;
} }
jp2->color.jp2_has_colr = 1; jp2->color.jp2_has_colr = 1;
} } else if (jp2->meth > 2) {
else if (jp2->meth > 2)
{
/* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values: /* ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values:
conforming JP2 reader shall ignore the entire Colour Specification box.*/ conforming JP2 reader shall ignore the entire Colour Specification box.*/
opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), " opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), "
@ -1559,8 +1542,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
l_writers[0].handler = opj_jp2_write_ihdr; l_writers[0].handler = opj_jp2_write_ihdr;
l_writers[1].handler = opj_jp2_write_bpcc; l_writers[1].handler = opj_jp2_write_bpcc;
l_writers[2].handler = opj_jp2_write_colr; l_writers[2].handler = opj_jp2_write_colr;
} } else {
else {
l_nb_pass = 2; l_nb_pass = 2;
l_writers[0].handler = opj_jp2_write_ihdr; l_writers[0].handler = opj_jp2_write_ihdr;
l_writers[1].handler = opj_jp2_write_colr; l_writers[1].handler = opj_jp2_write_colr;
@ -1674,8 +1656,7 @@ static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2,
} }
l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size); l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size);
if (! l_result) if (! l_result) {
{
opj_event_msg(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n"); opj_event_msg(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n");
} }
@ -1846,8 +1827,7 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
if(image->icc_profile_len) { if(image->icc_profile_len) {
jp2->meth = 2; jp2->meth = 2;
jp2->enumcs = 0; jp2->enumcs = 0;
} } else {
else {
jp2->meth = 1; jp2->meth = 1;
if (image->color_space == 1) if (image->color_space == 1)
jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */ jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */
@ -2005,8 +1985,7 @@ static OPJ_BOOL opj_jp2_setup_end_header_writing (opj_jp2_t *jp2, opj_event_mgr_
} }
/* DEVELOPER CORNER, add your custom procedures */ /* DEVELOPER CORNER, add your custom procedures */
#ifdef USE_JPIP #ifdef USE_JPIP
if( jp2->jpip_on ) if( jp2->jpip_on ) {
{
if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_cidx, p_manager)) { if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jpip_write_cidx, p_manager)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -2118,14 +2097,12 @@ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
jp2->jp2_state |= JP2_STATE_CODESTREAM; jp2->jp2_state |= JP2_STATE_CODESTREAM;
opj_free(l_current_data); opj_free(l_current_data);
return OPJ_TRUE; return OPJ_TRUE;
} } else {
else {
opj_event_msg(p_manager, EVT_ERROR, "bad placed jpeg codestream\n"); opj_event_msg(p_manager, EVT_ERROR, "bad placed jpeg codestream\n");
opj_free(l_current_data); opj_free(l_current_data);
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else if (box.length == 0) {
else if (box.length == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n"); opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
opj_free(l_current_data); opj_free(l_current_data);
return OPJ_FALSE; return OPJ_FALSE;
@ -2186,8 +2163,7 @@ static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
opj_free(l_current_data); opj_free(l_current_data);
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) { if (!(jp2->jp2_state & JP2_STATE_SIGNATURE)) {
opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: first box must be JPEG 2000 signature box\n"); opj_event_msg(p_manager, EVT_ERROR, "Malformed JP2 file format: first box must be JPEG 2000 signature box\n");
opj_free(l_current_data); opj_free(l_current_data);
@ -2308,8 +2284,7 @@ static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id)
static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_id) static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_id)
{ {
OPJ_UINT32 i, l_handler_size = sizeof(jp2_img_header) / sizeof(opj_jp2_header_handler_t); OPJ_UINT32 i, l_handler_size = sizeof(jp2_img_header) / sizeof(opj_jp2_header_handler_t);
for (i=0;i<l_handler_size;++i) for (i=0; i<l_handler_size; ++i) {
{
if (jp2_img_header[i].id == p_id) { if (jp2_img_header[i].id == p_id) {
return &jp2_img_header[i]; return &jp2_img_header[i];
} }
@ -2423,8 +2398,7 @@ static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2,
} }
} }
for (i = 0; i < jp2->numcl; ++i) for (i = 0; i < jp2->numcl; ++i) {
{
opj_read_bytes(p_header_data,&jp2->cl[i],4); /* CLi */ opj_read_bytes(p_header_data,&jp2->cl[i],4); /* CLi */
p_header_data += 4; p_header_data += 4;
} }
@ -2525,8 +2499,7 @@ static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2,
if (! l_current_handler->handler(jp2,p_header_data,l_current_data_size,p_manager)) { if (! l_current_handler->handler(jp2,p_header_data,l_current_data_size,p_manager)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN; jp2->jp2_img_state |= JP2_IMG_STATE_UNKNOWN;
} }
@ -2606,8 +2579,7 @@ static OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box,
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n"); opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else if (box->length == 0) {
else if (box->length == 0) {
opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n"); opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -2918,8 +2890,7 @@ opj_jp2_t* opj_jp2_create(OPJ_BOOL p_is_decoder)
/* create the J2K codec */ /* create the J2K codec */
if (! p_is_decoder) { if (! p_is_decoder) {
jp2->j2k = opj_j2k_create_compress(); jp2->j2k = opj_j2k_create_compress();
} } else {
else {
jp2->j2k = opj_j2k_create_decompress(); jp2->j2k = opj_j2k_create_decompress();
} }

View File

@ -70,8 +70,7 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
typedef enum typedef enum {
{
JP2_STATE_NONE = 0x0, JP2_STATE_NONE = 0x0,
JP2_STATE_SIGNATURE = 0x1, JP2_STATE_SIGNATURE = 0x1,
JP2_STATE_FILE_TYPE = 0x2, JP2_STATE_FILE_TYPE = 0x2,
@ -82,8 +81,7 @@ typedef enum
} }
JP2_STATE; JP2_STATE;
typedef enum typedef enum {
{
JP2_IMG_STATE_NONE = 0x0, JP2_IMG_STATE_NONE = 0x0,
JP2_IMG_STATE_UNKNOWN = 0x7fffffff JP2_IMG_STATE_UNKNOWN = 0x7fffffff
} }
@ -92,16 +90,14 @@ JP2_IMG_STATE;
/** /**
Channel description: channel index, type, association Channel description: channel index, type, association
*/ */
typedef struct opj_jp2_cdef_info typedef struct opj_jp2_cdef_info {
{
OPJ_UINT16 cn, typ, asoc; OPJ_UINT16 cn, typ, asoc;
} opj_jp2_cdef_info_t; } opj_jp2_cdef_info_t;
/** /**
Channel descriptions and number of descriptions Channel descriptions and number of descriptions
*/ */
typedef struct opj_jp2_cdef typedef struct opj_jp2_cdef {
{
opj_jp2_cdef_info_t *info; opj_jp2_cdef_info_t *info;
OPJ_UINT16 n; OPJ_UINT16 n;
} opj_jp2_cdef_t; } opj_jp2_cdef_t;
@ -109,8 +105,7 @@ typedef struct opj_jp2_cdef
/** /**
Component mappings: channel index, mapping type, palette index Component mappings: channel index, mapping type, palette index
*/ */
typedef struct opj_jp2_cmap_comp typedef struct opj_jp2_cmap_comp {
{
OPJ_UINT16 cmp; OPJ_UINT16 cmp;
OPJ_BYTE mtyp, pcol; OPJ_BYTE mtyp, pcol;
} opj_jp2_cmap_comp_t; } opj_jp2_cmap_comp_t;
@ -118,8 +113,7 @@ typedef struct opj_jp2_cmap_comp
/** /**
Palette data: table entries, palette columns Palette data: table entries, palette columns
*/ */
typedef struct opj_jp2_pclr typedef struct opj_jp2_pclr {
{
OPJ_UINT32 *entries; OPJ_UINT32 *entries;
OPJ_BYTE *channel_sign; OPJ_BYTE *channel_sign;
OPJ_BYTE *channel_size; OPJ_BYTE *channel_size;
@ -131,8 +125,7 @@ typedef struct opj_jp2_pclr
/** /**
Collector for ICC profile, palette, component mapping, channel description Collector for ICC profile, palette, component mapping, channel description
*/ */
typedef struct opj_jp2_color typedef struct opj_jp2_color {
{
OPJ_BYTE *icc_profile_buf; OPJ_BYTE *icc_profile_buf;
OPJ_UINT32 icc_profile_len; OPJ_UINT32 icc_profile_len;
@ -153,8 +146,7 @@ typedef struct opj_jp2_comps {
/** /**
JPEG-2000 file format reader/writer JPEG-2000 file format reader/writer
*/ */
typedef struct opj_jp2 typedef struct opj_jp2 {
{
/** handle to the J2K codec */ /** handle to the J2K codec */
opj_j2k_t *j2k; opj_j2k_t *j2k;
/** list of validation procedures */ /** list of validation procedures */
@ -207,8 +199,7 @@ typedef struct opj_jp2_box {
OPJ_INT32 init_pos; OPJ_INT32 init_pos;
} opj_jp2_box_t; } opj_jp2_box_t;
typedef struct opj_jp2_header_handler typedef struct opj_jp2_header_handler {
{
/* marker value */ /* marker value */
OPJ_UINT32 id; OPJ_UINT32 id;
/* action linked to the marker */ /* action linked to the marker */
@ -220,8 +211,7 @@ typedef struct opj_jp2_header_handler
opj_jp2_header_handler_t; opj_jp2_header_handler_t;
typedef struct opj_jp2_img_header_writer_handler typedef struct opj_jp2_img_header_writer_handler {
{
/* action to perform */ /* action to perform */
OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size); OPJ_BYTE* (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
/* result of the action : data */ /* result of the action : data */

View File

@ -201,7 +201,8 @@ void opj_mct_decode(
/* <summary> */ /* <summary> */
/* Get norm of basis function of reversible MCT. */ /* Get norm of basis function of reversible MCT. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) { OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno)
{
return opj_mct_norms[compno]; return opj_mct_norms[compno];
} }
@ -435,7 +436,8 @@ void opj_mct_decode_real(
/* <summary> */ /* <summary> */
/* Get norm of basis function of irreversible MCT. */ /* Get norm of basis function of irreversible MCT. */
/* </summary> */ /* </summary> */
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) { OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno)
{
return opj_mct_norms_real[compno]; return opj_mct_norms_real[compno];
} }

View File

@ -202,7 +202,8 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
========================================================== ==========================================================
*/ */
static void opj_mqc_byteout(opj_mqc_t *mqc) { static void opj_mqc_byteout(opj_mqc_t *mqc)
{
if (*mqc->bp == 0xff) { if (*mqc->bp == 0xff) {
mqc->bp++; mqc->bp++;
*mqc->bp = (OPJ_BYTE)(mqc->c >> 20); *mqc->bp = (OPJ_BYTE)(mqc->c >> 20);
@ -232,7 +233,8 @@ static void opj_mqc_byteout(opj_mqc_t *mqc) {
} }
} }
static void opj_mqc_renorme(opj_mqc_t *mqc) { static void opj_mqc_renorme(opj_mqc_t *mqc)
{
do { do {
mqc->a <<= 1; mqc->a <<= 1;
mqc->c <<= 1; mqc->c <<= 1;
@ -243,7 +245,8 @@ static void opj_mqc_renorme(opj_mqc_t *mqc) {
} while ((mqc->a & 0x8000) == 0); } while ((mqc->a & 0x8000) == 0);
} }
static void opj_mqc_codemps(opj_mqc_t *mqc) { static void opj_mqc_codemps(opj_mqc_t *mqc)
{
mqc->a -= (*mqc->curctx)->qeval; mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) { if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
@ -258,7 +261,8 @@ static void opj_mqc_codemps(opj_mqc_t *mqc) {
} }
} }
static void opj_mqc_codelps(opj_mqc_t *mqc) { static void opj_mqc_codelps(opj_mqc_t *mqc)
{
mqc->a -= (*mqc->curctx)->qeval; mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval; mqc->c += (*mqc->curctx)->qeval;
@ -269,7 +273,8 @@ static void opj_mqc_codelps(opj_mqc_t *mqc) {
opj_mqc_renorme(mqc); opj_mqc_renorme(mqc);
} }
static void opj_mqc_setbits(opj_mqc_t *mqc) { static void opj_mqc_setbits(opj_mqc_t *mqc)
{
OPJ_UINT32 tempc = mqc->c + mqc->a; OPJ_UINT32 tempc = mqc->c + mqc->a;
mqc->c |= 0xffff; mqc->c |= 0xffff;
if (mqc->c >= tempc) { if (mqc->c >= tempc) {
@ -277,7 +282,8 @@ static void opj_mqc_setbits(opj_mqc_t *mqc) {
} }
} }
static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) { static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc)
{
OPJ_INT32 d; OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); d = (OPJ_INT32)(1 - (*mqc->curctx)->mps);
@ -290,7 +296,8 @@ static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) {
return d; return d;
} }
static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) { static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc)
{
OPJ_INT32 d; OPJ_INT32 d;
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval; mqc->a = (*mqc->curctx)->qeval;
@ -306,14 +313,16 @@ static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) {
} }
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc) { static INLINE void opj_mqc_bytein(opj_mqc_t *const mqc)
{
unsigned int i = *((unsigned int *) mqc->bp); unsigned int i = *((unsigned int *) mqc->bp);
mqc->c += i & 0xffff00; mqc->c += i & 0xffff00;
mqc->ct = i & 0x0f; mqc->ct = i & 0x0f;
mqc->bp += (i >> 2) & 0x04; mqc->bp += (i >> 2) & 0x04;
} }
#else #else
static void opj_mqc_bytein(opj_mqc_t *const mqc) { static void opj_mqc_bytein(opj_mqc_t *const mqc)
{
if (mqc->bp != mqc->end) { if (mqc->bp != mqc->end) {
OPJ_UINT32 c; OPJ_UINT32 c;
if (mqc->bp + 1 != mqc->end) { if (mqc->bp + 1 != mqc->end) {
@ -342,7 +351,8 @@ static void opj_mqc_bytein(opj_mqc_t *const mqc) {
} }
#endif #endif
static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) { static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc)
{
do { do {
if (mqc->ct == 0) { if (mqc->ct == 0) {
opj_mqc_bytein(mqc); opj_mqc_bytein(mqc);
@ -359,7 +369,8 @@ static INLINE void opj_mqc_renormd(opj_mqc_t *const mqc) {
========================================================== ==========================================================
*/ */
opj_mqc_t* opj_mqc_create(void) { opj_mqc_t* opj_mqc_create(void)
{
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
if (mqc) { if (mqc) {
@ -369,7 +380,8 @@ opj_mqc_t* opj_mqc_create(void) {
return mqc; return mqc;
} }
void opj_mqc_destroy(opj_mqc_t *mqc) { void opj_mqc_destroy(opj_mqc_t *mqc)
{
if(mqc) { if(mqc) {
#ifdef MQC_PERF_OPT #ifdef MQC_PERF_OPT
if (mqc->buffer) { if (mqc->buffer) {
@ -380,7 +392,8 @@ void opj_mqc_destroy(opj_mqc_t *mqc) {
} }
} }
OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc)
{
const ptrdiff_t diff = mqc->bp - mqc->start; const ptrdiff_t diff = mqc->bp - mqc->start;
#if 0 #if 0
assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */
@ -388,7 +401,8 @@ OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) {
return (OPJ_UINT32)diff; return (OPJ_UINT32)diff;
} }
void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp)
{
/* TODO MSD: need to take a look to the v2 version */ /* TODO MSD: need to take a look to the v2 version */
opj_mqc_setcurctx(mqc, 0); opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000; mqc->a = 0x8000;
@ -401,7 +415,8 @@ void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) {
mqc->start = bp; mqc->start = bp;
} }
void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) { void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d)
{
if ((*mqc->curctx)->mps == d) { if ((*mqc->curctx)->mps == d) {
opj_mqc_codemps(mqc); opj_mqc_codemps(mqc);
} else { } else {
@ -409,7 +424,8 @@ void opj_mqc_encode(opj_mqc_t *mqc, OPJ_UINT32 d) {
} }
} }
void opj_mqc_flush(opj_mqc_t *mqc) { void opj_mqc_flush(opj_mqc_t *mqc)
{
opj_mqc_setbits(mqc); opj_mqc_setbits(mqc);
mqc->c <<= mqc->ct; mqc->c <<= mqc->ct;
opj_mqc_byteout(mqc); opj_mqc_byteout(mqc);
@ -421,7 +437,8 @@ void opj_mqc_flush(opj_mqc_t *mqc) {
} }
} }
void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) { void opj_mqc_bypass_init_enc(opj_mqc_t *mqc)
{
mqc->c = 0; mqc->c = 0;
mqc->ct = 8; mqc->ct = 8;
/*if (*mqc->bp == 0xff) { /*if (*mqc->bp == 0xff) {
@ -429,7 +446,8 @@ void opj_mqc_bypass_init_enc(opj_mqc_t *mqc) {
} */ } */
} }
void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) { void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d)
{
mqc->ct--; mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct); mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) { if (mqc->ct == 0) {
@ -443,7 +461,8 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) {
} }
} }
OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc)
{
OPJ_BYTE bit_padding; OPJ_BYTE bit_padding;
bit_padding = 0; bit_padding = 0;
@ -463,14 +482,16 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) {
return 1; return 1;
} }
void opj_mqc_reset_enc(opj_mqc_t *mqc) { void opj_mqc_reset_enc(opj_mqc_t *mqc)
{
opj_mqc_resetstates(mqc); opj_mqc_resetstates(mqc);
opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46); opj_mqc_setstate(mqc, T1_CTXNO_UNI, 0, 46);
opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3); opj_mqc_setstate(mqc, T1_CTXNO_AGG, 0, 3);
opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4); opj_mqc_setstate(mqc, T1_CTXNO_ZC, 0, 4);
} }
OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc)
{
OPJ_UINT32 correction = 1; OPJ_UINT32 correction = 1;
/* <flush part> */ /* <flush part> */
@ -486,7 +507,8 @@ OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) {
return correction; return correction;
} }
void opj_mqc_restart_init_enc(opj_mqc_t *mqc) { void opj_mqc_restart_init_enc(opj_mqc_t *mqc)
{
/* <Re-init part> */ /* <Re-init part> */
opj_mqc_setcurctx(mqc, 0); opj_mqc_setcurctx(mqc, 0);
mqc->a = 0x8000; mqc->a = 0x8000;
@ -498,7 +520,8 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc) {
} }
} }
void opj_mqc_erterm_enc(opj_mqc_t *mqc) { void opj_mqc_erterm_enc(opj_mqc_t *mqc)
{
OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1);
while (k > 0) { while (k > 0) {
@ -513,7 +536,8 @@ void opj_mqc_erterm_enc(opj_mqc_t *mqc) {
} }
} }
void opj_mqc_segmark_enc(opj_mqc_t *mqc) { void opj_mqc_segmark_enc(opj_mqc_t *mqc)
{
OPJ_UINT32 i; OPJ_UINT32 i;
opj_mqc_setcurctx(mqc, 18); opj_mqc_setcurctx(mqc, 18);
@ -522,7 +546,8 @@ void opj_mqc_segmark_enc(opj_mqc_t *mqc) {
} }
} }
OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) { OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len)
{
opj_mqc_setcurctx(mqc, 0); opj_mqc_setcurctx(mqc, 0);
mqc->start = bp; mqc->start = bp;
mqc->end = bp + len; mqc->end = bp + len;
@ -581,7 +606,8 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) {
return OPJ_TRUE; return OPJ_TRUE;
} }
OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) { OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc)
{
OPJ_INT32 d; OPJ_INT32 d;
mqc->a -= (*mqc->curctx)->qeval; mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
@ -600,14 +626,16 @@ OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) {
return d; return d;
} }
void opj_mqc_resetstates(opj_mqc_t *mqc) { void opj_mqc_resetstates(opj_mqc_t *mqc)
{
OPJ_UINT32 i; OPJ_UINT32 i;
for (i = 0; i < MQC_NUMCTXS; i++) { for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states; mqc->ctxs[i] = mqc_states;
} }
} }
void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) { void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob)
{
mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)];
} }

View File

@ -132,7 +132,8 @@ static OPJ_BOOL opj_seek_from_file (OPJ_OFF_T p_nb_bytes, FILE * p_user_data)
#ifdef _WIN32 #ifdef _WIN32
#ifndef OPJ_STATIC #ifndef OPJ_STATIC
BOOL APIENTRY BOOL APIENTRY
DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
OPJ_ARG_NOT_USED(lpReserved); OPJ_ARG_NOT_USED(lpReserved);
OPJ_ARG_NOT_USED(hModule); OPJ_ARG_NOT_USED(hModule);
@ -154,7 +155,8 @@ DllMain(HINSTANCE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version(void) { const char* OPJ_CALLCONV opj_version(void)
{
return OPJ_PACKAGE_VERSION; return OPJ_PACKAGE_VERSION;
} }
@ -334,7 +336,8 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
return (opj_codec_t*) l_codec; return (opj_codec_t*) l_codec;
} }
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) { void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters)
{
if(parameters) { if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t)); memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */ /* default decoding parameters */
@ -631,7 +634,8 @@ opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT p_format)
return (opj_codec_t*) l_codec; return (opj_codec_t*) l_codec;
} }
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) { void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters)
{
if(parameters) { if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t)); memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */ /* default coding parameters */
@ -843,8 +847,7 @@ void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_codec)
if (l_codec->is_decompressor) { if (l_codec->is_decompressor) {
l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec); l_codec->m_codec_data.m_decompression.opj_destroy(l_codec->m_codec);
} } else {
else {
l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec); l_codec->m_codec_data.m_compression.opj_destroy(l_codec->m_codec);
} }
@ -882,7 +885,8 @@ opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
return NULL; return NULL;
} }
void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info) { void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info)
{
if (cstr_info) { if (cstr_info) {
if ((*cstr_info)->m_default_tile_info.tccp_info) { if ((*cstr_info)->m_default_tile_info.tccp_info) {
@ -935,7 +939,8 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (
return NULL; return NULL;
} }
if(p_is_read_stream) mode = "rb"; else mode = "wb"; if(p_is_read_stream) mode = "rb";
else mode = "wb";
p_file = fopen(fname, mode); p_file = fopen(fname, mode);

View File

@ -855,8 +855,7 @@ typedef struct opj_codestream_info {
/** /**
* Tile-component coding parameters information * Tile-component coding parameters information
*/ */
typedef struct opj_tccp_info typedef struct opj_tccp_info {
{
/** component index */ /** component index */
OPJ_UINT32 compno; OPJ_UINT32 compno;
/** coding style */ /** coding style */

View File

@ -39,7 +39,8 @@
#include <sys/times.h> #include <sys/times.h>
#endif /* _WIN32 */ #endif /* _WIN32 */
OPJ_FLOAT64 opj_clock(void) { OPJ_FLOAT64 opj_clock(void)
{
#ifdef _WIN32 #ifdef _WIN32
/* _WIN32: use QueryPerformance (very accurate) */ /* _WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;

View File

@ -39,16 +39,13 @@
/** /**
* Main codec handler used for compression or decompression. * Main codec handler used for compression or decompression.
*/ */
typedef struct opj_codec_private typedef struct opj_codec_private {
{
/** FIXME DOC */ /** FIXME DOC */
union union {
{
/** /**
* Decompression handler. * Decompression handler.
*/ */
struct opj_decompression struct opj_decompression {
{
/** Main header reading function handler */ /** Main header reading function handler */
OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio, OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
void * p_codec, void * p_codec,
@ -118,8 +115,7 @@ typedef struct opj_codec_private
/** /**
* Compression handler. FIXME DOC * Compression handler. FIXME DOC
*/ */
struct opj_compression struct opj_compression {
{
OPJ_BOOL (* opj_start_compress) ( void *p_codec, OPJ_BOOL (* opj_start_compress) ( void *p_codec,
struct opj_stream_private * cio, struct opj_stream_private * cio,
struct opj_image * p_image, struct opj_image * p_image,

View File

@ -123,7 +123,8 @@
/* MSVC before 2013 and Borland C do not have lrintf */ /* MSVC before 2013 and Borland C do not have lrintf */
#if defined(_MSC_VER) #if defined(_MSC_VER)
#include <intrin.h> #include <intrin.h>
static INLINE long opj_lrintf(float f){ static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64 #ifdef _M_X64
return _mm_cvt_ss2si(_mm_load_ss(&f)); return _mm_cvt_ss2si(_mm_load_ss(&f));
@ -142,7 +143,8 @@ static INLINE long opj_lrintf(float f){
#endif #endif
} }
#elif defined(__BORLANDC__) #elif defined(__BORLANDC__)
static INLINE long opj_lrintf(float f) { static INLINE long opj_lrintf(float f)
{
#ifdef _M_X64 #ifdef _M_X64
return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f));
#else #else
@ -157,7 +159,8 @@ static INLINE long opj_lrintf(float f) {
#endif #endif
} }
#else #else
static INLINE long opj_lrintf(float f) { static INLINE long opj_lrintf(float f)
{
return lrintf(f); return lrintf(f);
} }
#endif #endif

View File

@ -53,7 +53,8 @@ The functions in OPJ_INTMATH.H have for goal to realize operations on integers.
Get the minimum of two integers Get the minimum of two integers
@return Returns a if a < b else b @return Returns a if a < b else b
*/ */
static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b)
{
return a < b ? a : b; return a < b ? a : b;
} }
@ -61,7 +62,8 @@ static INLINE OPJ_INT32 opj_int_min(OPJ_INT32 a, OPJ_INT32 b) {
Get the minimum of two integers Get the minimum of two integers
@return Returns a if a < b else b @return Returns a if a < b else b
*/ */
static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b)
{
return a < b ? a : b; return a < b ? a : b;
} }
@ -69,7 +71,8 @@ static INLINE OPJ_UINT32 opj_uint_min(OPJ_UINT32 a, OPJ_UINT32 b) {
Get the maximum of two integers Get the maximum of two integers
@return Returns a if a > b else b @return Returns a if a > b else b
*/ */
static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b)
{
return (a > b) ? a : b; return (a > b) ? a : b;
} }
@ -77,7 +80,8 @@ static INLINE OPJ_INT32 opj_int_max(OPJ_INT32 a, OPJ_INT32 b) {
Get the maximum of two integers Get the maximum of two integers
@return Returns a if a > b else b @return Returns a if a > b else b
*/ */
static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (a > b) ? a : b; return (a > b) ? a : b;
} }
@ -85,7 +89,8 @@ static INLINE OPJ_UINT32 opj_uint_max(OPJ_UINT32 a, OPJ_UINT32 b) {
Get the saturated sum of two unsigned integers Get the saturated sum of two unsigned integers
@return Returns saturated sum of a+b @return Returns saturated sum of a+b
*/ */
static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_adds(OPJ_UINT32 a, OPJ_UINT32 b)
{
OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b; OPJ_UINT64 sum = (OPJ_UINT64)a + (OPJ_UINT64)b;
return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum; return (OPJ_UINT32)(-(OPJ_INT32)(sum >> 32)) | (OPJ_UINT32)sum;
} }
@ -99,7 +104,8 @@ Clamp an integer inside an interval
<li>Returns min if (a < min) <li>Returns min if (a < min)
</ul> </ul>
*/ */
static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max) { static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
{
if (a < min) if (a < min)
return min; return min;
if (a > max) if (a > max)
@ -109,14 +115,16 @@ static INLINE OPJ_INT32 opj_int_clamp(OPJ_INT32 a, OPJ_INT32 min, OPJ_INT32 max)
/** /**
@return Get absolute value of integer @return Get absolute value of integer
*/ */
static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a) { static INLINE OPJ_INT32 opj_int_abs(OPJ_INT32 a)
{
return a < 0 ? -a : a; return a < 0 ? -a : a;
} }
/** /**
Divide an integer and round upwards Divide an integer and round upwards
@return Returns a divided by b @return Returns a divided by b
*/ */
static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b)
{
assert(b); assert(b);
return (a + b - 1) / b; return (a + b - 1) / b;
} }
@ -125,7 +133,8 @@ static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) {
Divide an integer and round upwards Divide an integer and round upwards
@return Returns a divided by b @return Returns a divided by b
*/ */
static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b)
{
assert(b); assert(b);
return (a + b - 1) / b; return (a + b - 1) / b;
} }
@ -134,7 +143,8 @@ static INLINE OPJ_UINT32 opj_uint_ceildiv(OPJ_UINT32 a, OPJ_UINT32 b) {
Divide an integer by a power of 2 and round upwards Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
} }
@ -142,7 +152,8 @@ static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) {
Divide a 64bits integer by a power of 2 and round upwards Divide a 64bits integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b)
{
return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b); return (OPJ_INT32)((a + ((OPJ_INT64)1 << b) - 1) >> b);
} }
@ -150,7 +161,8 @@ static INLINE OPJ_INT32 opj_int64_ceildivpow2(OPJ_INT64 a, OPJ_INT32 b) {
Divide an integer by a power of 2 and round upwards Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) { static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b)
{
return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b); return (OPJ_UINT32)((a + ((OPJ_UINT64)1U << b) - 1U) >> b);
} }
@ -158,14 +170,16 @@ static INLINE OPJ_UINT32 opj_uint_ceildivpow2(OPJ_UINT32 a, OPJ_UINT32 b) {
Divide an integer by a power of 2 and round downwards Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_floordivpow2(OPJ_INT32 a, OPJ_INT32 b)
{
return a >> b; return a >> b;
} }
/** /**
Get logarithm of an integer and round downwards Get logarithm of an integer and round downwards
@return Returns log2(a) @return Returns log2(a)
*/ */
static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) { static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a)
{
OPJ_INT32 l; OPJ_INT32 l;
for (l = 0; a > 1; l++) { for (l = 0; a > 1; l++) {
a >>= 1; a >>= 1;
@ -176,10 +190,10 @@ static INLINE OPJ_INT32 opj_int_floorlog2(OPJ_INT32 a) {
Get logarithm of an integer and round downwards Get logarithm of an integer and round downwards
@return Returns log2(a) @return Returns log2(a)
*/ */
static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a) { static INLINE OPJ_UINT32 opj_uint_floorlog2(OPJ_UINT32 a)
OPJ_UINT32 l;
for (l = 0; a > 1; ++l)
{ {
OPJ_UINT32 l;
for (l = 0; a > 1; ++l) {
a >>= 1; a >>= 1;
} }
return l; return l;
@ -191,7 +205,8 @@ Multiply two fixed-precision rational numbers.
@param b @param b
@return Returns a * b @return Returns a * b
*/ */
static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86) #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b); OPJ_INT64 temp = __emul(a, b);
#else #else
@ -203,7 +218,8 @@ static INLINE OPJ_INT32 opj_int_fix_mul(OPJ_INT32 a, OPJ_INT32 b) {
return (OPJ_INT32) (temp >> 13); return (OPJ_INT32) (temp >> 13);
} }
static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b) { static INLINE OPJ_INT32 opj_int_fix_mul_t1(OPJ_INT32 a, OPJ_INT32 b)
{
#if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86) #if defined(_MSC_VER) && (_MSC_VER >= 1400) && !defined(__INTEL_COMPILER) && defined(_M_IX86)
OPJ_INT64 temp = __emul(a, b); OPJ_INT64 temp = __emul(a, b);
#else #else

View File

@ -58,8 +58,7 @@ static INLINE void *opj_aligned_alloc_n(size_t alignment, size_t size)
* This function was introduced in POSIX 1003.1d. Although this function is * This function was introduced in POSIX 1003.1d. Although this function is
* superseded by aligned_alloc, it is more portable to older POSIX systems * superseded by aligned_alloc, it is more portable to older POSIX systems
* that do not support ISO C11. */ * that do not support ISO C11. */
if (posix_memalign (&ptr, alignment, size)) if (posix_memalign (&ptr, alignment, size)) {
{
ptr = NULL; ptr = NULL;
} }
/* older linux */ /* older linux */
@ -164,8 +163,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
if (newmem == oldmem) { if (newmem == oldmem) {
r_ptr = ptr; r_ptr = ptr;
} } else {
else {
size_t old_offset; size_t old_offset;
size_t new_offset; size_t new_offset;

View File

@ -107,8 +107,7 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
if( j2klen > pow( 2, 32)) { if( j2klen > pow( 2, 32)) {
size_of_coding = 8; size_of_coding = 8;
version = 1; version = 1;
} } else {
else{
size_of_coding = 4; size_of_coding = 4;
version = 0; version = 0;
} }

View File

@ -230,7 +230,8 @@ static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
========================================================== ==========================================================
*/ */
static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) { static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0; OPJ_UINT32 index = 0;
@ -261,7 +262,8 @@ static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return OPJ_TRUE; return OPJ_TRUE;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -270,7 +272,8 @@ LABEL_SKIP:;
return OPJ_FALSE; return OPJ_FALSE;
} }
static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) { static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0; OPJ_UINT32 index = 0;
@ -300,7 +303,8 @@ static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return OPJ_TRUE; return OPJ_TRUE;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -309,7 +313,8 @@ LABEL_SKIP:;
return OPJ_FALSE; return OPJ_FALSE;
} }
static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) { static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0; OPJ_UINT32 index = 0;
@ -382,7 +387,8 @@ if (!pi->tp_on){
pi->include[index] = 1; pi->include[index] = 1;
return OPJ_TRUE; return OPJ_TRUE;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -392,7 +398,8 @@ LABEL_SKIP:;
return OPJ_FALSE; return OPJ_FALSE;
} }
static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0; OPJ_UINT32 index = 0;
@ -463,7 +470,8 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return OPJ_TRUE; return OPJ_TRUE;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -473,7 +481,8 @@ LABEL_SKIP:;
return OPJ_FALSE; return OPJ_FALSE;
} }
static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
OPJ_UINT32 index = 0; OPJ_UINT32 index = 0;
@ -542,7 +551,8 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return OPJ_TRUE; return OPJ_TRUE;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -1194,15 +1204,13 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_tmp_data = (OPJ_UINT32*)opj_malloc( l_tmp_data = (OPJ_UINT32*)opj_malloc(
l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32)); l_data_stride * p_image->numcomps * sizeof(OPJ_UINT32));
if if
(! l_tmp_data) (! l_tmp_data) {
{
return 00; return 00;
} }
l_tmp_ptr = (OPJ_UINT32**)opj_malloc( l_tmp_ptr = (OPJ_UINT32**)opj_malloc(
p_image->numcomps * sizeof(OPJ_UINT32 *)); p_image->numcomps * sizeof(OPJ_UINT32 *));
if if
(! l_tmp_ptr) (! l_tmp_ptr) {
{
opj_free(l_tmp_data); opj_free(l_tmp_data);
return 00; return 00;
} }
@ -1218,8 +1226,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_encoding_value_ptr = l_tmp_data; l_encoding_value_ptr = l_tmp_data;
/* update pointer array */ /* update pointer array */
for for
(compno = 0; compno < p_image->numcomps; ++compno) (compno = 0; compno < p_image->numcomps; ++compno) {
{
l_tmp_ptr[compno] = l_encoding_value_ptr; l_tmp_ptr[compno] = l_encoding_value_ptr;
l_encoding_value_ptr += l_data_stride; l_encoding_value_ptr += l_data_stride;
} }
@ -1238,8 +1245,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* memory allocation for include */ /* memory allocation for include */
l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16)); l_current_pi->include = (OPJ_INT16*) opj_calloc((l_tcp->numlayers +1) * l_step_l, sizeof(OPJ_INT16));
if if
(!l_current_pi->include) (!l_current_pi->include) {
{
opj_free(l_tmp_data); opj_free(l_tmp_data);
opj_free(l_tmp_ptr); opj_free(l_tmp_ptr);
opj_pi_destroy(l_pi, l_bound); opj_pi_destroy(l_pi, l_bound);
@ -1266,8 +1272,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* allocation for components and number of components has already been calculated by opj_pi_create */ /* allocation for components and number of components has already been calculated by opj_pi_create */
for for
(compno = 0; compno < l_current_pi->numcomps; ++compno) (compno = 0; compno < l_current_pi->numcomps; ++compno) {
{
opj_pi_resolution_t *l_res = l_current_comp->resolutions; opj_pi_resolution_t *l_res = l_current_comp->resolutions;
l_encoding_value_ptr = l_tmp_ptr[compno]; l_encoding_value_ptr = l_tmp_ptr[compno];
@ -1275,8 +1280,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_comp->dy = l_img_comp->dy; l_current_comp->dy = l_img_comp->dy;
/* resolutions have already been initialized */ /* resolutions have already been initialized */
for for
(resno = 0; resno < l_current_comp->numresolutions; resno++) (resno = 0; resno < l_current_comp->numresolutions; resno++) {
{
l_res->pdx = *(l_encoding_value_ptr++); l_res->pdx = *(l_encoding_value_ptr++);
l_res->pdy = *(l_encoding_value_ptr++); l_res->pdy = *(l_encoding_value_ptr++);
l_res->pw = *(l_encoding_value_ptr++); l_res->pw = *(l_encoding_value_ptr++);
@ -1289,8 +1293,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
} }
++l_current_pi; ++l_current_pi;
for (pino = 1 ; pino<l_bound ; ++pino ) for (pino = 1 ; pino<l_bound ; ++pino ) {
{
l_current_comp = l_current_pi->comps; l_current_comp = l_current_pi->comps;
l_img_comp = p_image->comps; l_img_comp = p_image->comps;
l_tccp = l_tcp->tccps; l_tccp = l_tcp->tccps;
@ -1308,8 +1311,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
/* allocation for components and number of components has already been calculated by opj_pi_create */ /* allocation for components and number of components has already been calculated by opj_pi_create */
for for
(compno = 0; compno < l_current_pi->numcomps; ++compno) (compno = 0; compno < l_current_pi->numcomps; ++compno) {
{
opj_pi_resolution_t *l_res = l_current_comp->resolutions; opj_pi_resolution_t *l_res = l_current_comp->resolutions;
l_encoding_value_ptr = l_tmp_ptr[compno]; l_encoding_value_ptr = l_tmp_ptr[compno];
@ -1317,8 +1319,7 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
l_current_comp->dy = l_img_comp->dy; l_current_comp->dy = l_img_comp->dy;
/* resolutions have already been initialized */ /* resolutions have already been initialized */
for for
(resno = 0; resno < l_current_comp->numresolutions; resno++) (resno = 0; resno < l_current_comp->numresolutions; resno++) {
{
l_res->pdx = *(l_encoding_value_ptr++); l_res->pdx = *(l_encoding_value_ptr++);
l_res->pdy = *(l_encoding_value_ptr++); l_res->pdy = *(l_encoding_value_ptr++);
l_res->pw = *(l_encoding_value_ptr++); l_res->pw = *(l_encoding_value_ptr++);
@ -1338,12 +1339,9 @@ opj_pi_iterator_t *opj_pi_create_decode(opj_image_t *p_image,
opj_free(l_tmp_ptr); opj_free(l_tmp_ptr);
l_tmp_ptr = 00; l_tmp_ptr = 00;
if if
(l_tcp->POC) (l_tcp->POC) {
{
opj_pi_update_decode_poc (l_pi,l_tcp,l_max_prec,l_max_res); opj_pi_update_decode_poc (l_pi,l_tcp,l_max_prec,l_max_res);
} } else {
else
{
opj_pi_update_decode_not_poc(l_pi,l_tcp,l_max_prec,l_max_res); opj_pi_update_decode_not_poc(l_pi,l_tcp,l_max_prec,l_max_res);
} }
return l_pi; return l_pi;
@ -1528,8 +1526,7 @@ opj_pi_iterator_t *opj_pi_initialise_encode(const opj_image_t *p_image,
if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) { if (l_tcp->POC && (OPJ_IS_CINEMA(p_cp->rsiz) || p_t2_mode == FINAL_PASS)) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min); opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
} } else {
else {
opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min); opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
} }
@ -1762,15 +1759,18 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=1;resetX=1; incr_top=1;
resetX=1;
} else { } else {
incr_top=0;resetX=0; incr_top=0;
resetX=0;
} }
} else { } else {
pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t;
pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy));
tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1;
incr_top=0;resetX=1; incr_top=0;
resetX=1;
} }
if(resetX==1) { if(resetX==1) {
tcp->tx0_t = tcp->txS; tcp->tx0_t = tcp->txS;
@ -1851,13 +1851,13 @@ void opj_pi_update_encoding_parameters( const opj_image_t *p_image,
if (l_tcp->POC) { if (l_tcp->POC) {
opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min); opj_pi_update_encode_poc_and_final(p_cp,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
} } else {
else {
opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min); opj_pi_update_encode_not_poc(p_cp,p_image->numcomps,p_tile_no,l_tx0,l_tx1,l_ty0,l_ty1,l_max_prec,l_max_res,l_dx_min,l_dy_min);
} }
} }
OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi) { OPJ_BOOL opj_pi_next(opj_pi_iterator_t * pi)
{
switch (pi->poc.prg) { switch (pi->poc.prg) {
case OPJ_LRCP: case OPJ_LRCP:
return opj_pi_next_lrcp(pi); return opj_pi_next_lrcp(pi);

View File

@ -112,8 +112,7 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
if( j2klen > pow( 2, 32)) { if( j2klen > pow( 2, 32)) {
size_of_coding = 8; size_of_coding = 8;
version = 1; version = 1;
} } else {
else{
size_of_coding = 4; size_of_coding = 4;
version = 0; version = 0;
} }

View File

@ -48,24 +48,28 @@
========================================================== ==========================================================
*/ */
opj_raw_t* opj_raw_create(void) { opj_raw_t* opj_raw_create(void)
{
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw; return raw;
} }
void opj_raw_destroy(opj_raw_t *raw) { void opj_raw_destroy(opj_raw_t *raw)
{
if(raw) { if(raw) {
opj_free(raw); opj_free(raw);
} }
} }
OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) { OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw)
{
const ptrdiff_t diff = raw->bp - raw->start; const ptrdiff_t diff = raw->bp - raw->start;
assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */ assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */
return (OPJ_UINT32)diff; return (OPJ_UINT32)diff;
} }
void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) { void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len)
{
raw->start = bp; raw->start = bp;
raw->lenmax = len; raw->lenmax = len;
raw->len = 0; raw->len = 0;
@ -73,7 +77,8 @@ void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) {
raw->ct = 0; raw->ct = 0;
} }
OPJ_UINT32 opj_raw_decode(opj_raw_t *raw) { OPJ_UINT32 opj_raw_decode(opj_raw_t *raw)
{
OPJ_UINT32 d; OPJ_UINT32 d;
if (raw->ct == 0) { if (raw->ct == 0) {
raw->ct = 8; raw->ct = 8;

View File

@ -305,25 +305,30 @@ static OPJ_BOOL opj_t1_allocate_buffers( opj_t1_t *t1,
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static OPJ_BYTE opj_t1_getctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient) { static OPJ_BYTE opj_t1_getctxno_zc(OPJ_UINT32 f, OPJ_UINT32 orient)
{
return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; return lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)];
} }
static OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 f) { static OPJ_BYTE opj_t1_getctxno_sc(OPJ_UINT32 f)
{
return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; return lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
} }
static OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f) { static OPJ_UINT32 opj_t1_getctxno_mag(OPJ_UINT32 f)
{
OPJ_UINT32 tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG; OPJ_UINT32 tmp1 = (f & T1_SIG_OTH) ? T1_CTXNO_MAG + 1 : T1_CTXNO_MAG;
OPJ_UINT32 tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1; OPJ_UINT32 tmp2 = (f & T1_REFINE) ? T1_CTXNO_MAG + 2 : tmp1;
return (tmp2); return (tmp2);
} }
static OPJ_BYTE opj_t1_getspb(OPJ_UINT32 f) { static OPJ_BYTE opj_t1_getspb(OPJ_UINT32 f)
{
return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; return lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
} }
static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) { static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos)
{
if (bitpos > 0) { if (bitpos > 0) {
return lut_nmsedec_sig[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)]; return lut_nmsedec_sig[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
@ -331,7 +336,8 @@ static OPJ_INT16 opj_t1_getnmsedec_sig(OPJ_UINT32 x, OPJ_UINT32 bitpos) {
return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; return lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) { static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos)
{
if (bitpos > 0) { if (bitpos > 0) {
return lut_nmsedec_ref[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)]; return lut_nmsedec_ref[(x >> (bitpos)) & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
@ -339,7 +345,8 @@ static OPJ_INT16 opj_t1_getnmsedec_ref(OPJ_UINT32 x, OPJ_UINT32 bitpos) {
return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; return lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
static void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride) { static void opj_t1_updateflags(opj_flag_t *flagsp, OPJ_UINT32 s, OPJ_UINT32 stride)
{
opj_flag_t *np = flagsp - stride; opj_flag_t *np = flagsp - stride;
opj_flag_t *sp = flagsp + stride; opj_flag_t *sp = flagsp + stride;
@ -1375,8 +1382,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
if(!opj_t1_allocate_buffers( if(!opj_t1_allocate_buffers(
t1, t1,
(OPJ_UINT32)(cblk->x1 - cblk->x0), (OPJ_UINT32)(cblk->x1 - cblk->x0),
(OPJ_UINT32)(cblk->y1 - cblk->y0))) (OPJ_UINT32)(cblk->y1 - cblk->y0))) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -1499,8 +1505,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1,
if(!opj_t1_allocate_buffers( if(!opj_t1_allocate_buffers(
t1, t1,
(OPJ_UINT32)(cblk->x1 - cblk->x0), (OPJ_UINT32)(cblk->x1 - cblk->x0),
(OPJ_UINT32)(cblk->y1 - cblk->y0))) (OPJ_UINT32)(cblk->y1 - cblk->y0))) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }

View File

@ -38,7 +38,8 @@
#include "opj_includes.h" #include "opj_includes.h"
static int t1_init_ctxno_zc(int f, int orient) { static int t1_init_ctxno_zc(int f, int orient)
{
int h, v, d, n, t, hv; int h, v, d, n, t, hv;
n = 0; n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0); h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
@ -110,7 +111,8 @@ static int t1_init_ctxno_zc(int f, int orient) {
return (T1_CTXNO_ZC + n); return (T1_CTXNO_ZC + n);
} }
static int t1_init_ctxno_sc(int f) { static int t1_init_ctxno_sc(int f)
{
int hc, vc, n; int hc, vc, n;
n = 0; n = 0;
@ -151,7 +153,8 @@ static int t1_init_ctxno_sc(int f) {
return (T1_CTXNO_SC + n); return (T1_CTXNO_SC + n);
} }
static int t1_init_spb(int f) { static int t1_init_spb(int f)
{
int hc, vc, n; int hc, vc, n;
hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) == hc = opj_int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
@ -176,7 +179,8 @@ static int t1_init_spb(int f) {
return n; return n;
} }
static void dump_array16(int array[],int size){ static void dump_array16(int array[],int size)
{
int i; int i;
--size; --size;
for (i = 0; i < size; ++i) { for (i = 0; i < size; ++i) {
@ -197,7 +201,8 @@ int main(int argc, char **argv)
int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS];
int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS];
(void)argc; (void)argv; (void)argc;
(void)argv;
printf("/* This file was automatically generated by t1_generate_luts.c */\n\n"); printf("/* This file was automatically generated by t1_generate_luts.c */\n\n");

View File

@ -156,7 +156,8 @@ static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* #define RESTART 0x04 */ /* #define RESTART 0x04 */
static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n) { static void opj_t2_putcommacode(opj_bio_t *bio, OPJ_INT32 n)
{
while (--n >= 0) { while (--n >= 0) {
opj_bio_write(bio, 1, 1); opj_bio_write(bio, 1, 1);
} }
@ -172,7 +173,8 @@ static OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
return n; return n;
} }
static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n)
{
if (n == 1) { if (n == 1) {
opj_bio_write(bio, 0, 1); opj_bio_write(bio, 0, 1);
} else if (n == 2) { } else if (n == 2) {
@ -186,7 +188,8 @@ static void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) {
} }
} }
static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) { static OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio)
{
OPJ_UINT32 n; OPJ_UINT32 n;
if (!opj_bio_read(bio, 1)) if (!opj_bio_read(bio, 1))
return 1; return 1;
@ -279,8 +282,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
++l_current_pi; ++l_current_pi;
} }
} }
} } else { /* t2_mode == FINAL_PASS */
else { /* t2_mode == FINAL_PASS */
opj_pi_create_encode(l_pi, l_cp,p_tile_no,p_pino,p_tp_num,p_tp_pos,p_t2_mode); opj_pi_create_encode(l_pi, l_cp,p_tile_no,p_pino,p_tp_num,p_tp_pos,p_t2_mode);
l_current_pi = &l_pi[p_pino]; l_current_pi = &l_pi[p_pino];
@ -402,8 +404,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
} }
first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL)); first_pass_failed = (OPJ_BOOL*)opj_malloc(l_image->numcomps * sizeof(OPJ_BOOL));
if (!first_pass_failed) if (!first_pass_failed) {
{
opj_pi_destroy(l_pi,l_nb_pocs); opj_pi_destroy(l_pi,l_nb_pocs);
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -427,8 +428,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
l_img_comp = &(l_image->comps[l_current_pi->compno]); l_img_comp = &(l_image->comps[l_current_pi->compno]);
l_img_comp->resno_decoded = opj_uint_max(l_current_pi->resno, l_img_comp->resno_decoded); l_img_comp->resno_decoded = opj_uint_max(l_current_pi->resno, l_img_comp->resno_decoded);
} } else {
else {
l_nb_bytes_read = 0; l_nb_bytes_read = 0;
if (! opj_t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) { if (! opj_t2_skip_packet(p_t2,p_tile,l_tcp,l_current_pi,l_current_data,&l_nb_bytes_read,p_max_len,l_pack_info, p_manager)) {
opj_pi_destroy(l_pi,l_nb_pocs); opj_pi_destroy(l_pi,l_nb_pocs);
@ -511,7 +511,8 @@ opj_t2_t* opj_t2_create(opj_image_t *p_image, opj_cp_t *p_cp)
return l_t2; return l_t2;
} }
void opj_t2_destroy(opj_t2_t *t2) { void opj_t2_destroy(opj_t2_t *t2)
{
if(t2) { if(t2) {
opj_free(t2); opj_free(t2);
} }
@ -918,13 +919,11 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
l_header_data = *l_header_data_start; l_header_data = *l_header_data_start;
l_modified_length_ptr = &(l_cp->ppm_len); l_modified_length_ptr = &(l_cp->ppm_len);
} } else if (p_tcp->ppt == 1) { /* PPT */
else if (p_tcp->ppt == 1) { /* PPT */
l_header_data_start = &(p_tcp->ppt_data); l_header_data_start = &(p_tcp->ppt_data);
l_header_data = *l_header_data_start; l_header_data = *l_header_data_start;
l_modified_length_ptr = &(p_tcp->ppt_len); l_modified_length_ptr = &(p_tcp->ppt_len);
} } else { /* Normal Case */
else { /* Normal Case */
l_header_data_start = &(l_current_data); l_header_data_start = &(l_current_data);
l_header_data = *l_header_data_start; l_header_data = *l_header_data_start;
l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data); l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data);
@ -988,8 +987,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
if (!l_cblk->numsegs) { if (!l_cblk->numsegs) {
l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1)); l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1));
/* else one bit */ /* else one bit */
} } else {
else {
l_included = opj_bio_read(l_bio, 1); l_included = opj_bio_read(l_bio, 1);
} }
@ -1026,8 +1024,7 @@ static OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2,
opj_bio_destroy(l_bio); opj_bio_destroy(l_bio);
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
l_segno = l_cblk->numsegs - 1; l_segno = l_cblk->numsegs - 1;
if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) { if (l_cblk->segs[l_segno].numpasses == l_cblk->segs[l_segno].maxpasses) {
++l_segno; ++l_segno;
@ -1144,8 +1141,7 @@ static OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2,
l_seg = l_cblk->segs; l_seg = l_cblk->segs;
++l_cblk->numsegs; ++l_cblk->numsegs;
l_cblk->data_current_size = 0; l_cblk->data_current_size = 0;
} } else {
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1]; l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) { if (l_seg->numpasses == l_seg->maxpasses) {
@ -1279,8 +1275,7 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
l_seg = l_cblk->segs; l_seg = l_cblk->segs;
++l_cblk->numsegs; ++l_cblk->numsegs;
l_cblk->data_current_size = 0; l_cblk->data_current_size = 0;
} } else {
else {
l_seg = &l_cblk->segs[l_cblk->numsegs - 1]; l_seg = &l_cblk->segs[l_cblk->numsegs - 1];
if (l_seg->numpasses == l_seg->maxpasses) { if (l_seg->numpasses == l_seg->maxpasses) {
@ -1321,8 +1316,7 @@ static OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2,
l_seg->numpasses += l_seg->numnewpasses; l_seg->numpasses += l_seg->numnewpasses;
l_cblk->numnewpasses -= l_seg->numnewpasses; l_cblk->numnewpasses -= l_seg->numnewpasses;
if (l_cblk->numnewpasses > 0) if (l_cblk->numnewpasses > 0) {
{
++l_seg; ++l_seg;
++l_cblk->numsegs; ++l_cblk->numsegs;
} }
@ -1366,8 +1360,7 @@ static OPJ_BOOL opj_t2_init_seg( opj_tcd_cblk_dec_t* cblk,
if (cblksty & J2K_CCP_CBLKSTY_TERMALL) { if (cblksty & J2K_CCP_CBLKSTY_TERMALL) {
seg->maxpasses = 1; seg->maxpasses = 1;
} } else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
else if (cblksty & J2K_CCP_CBLKSTY_LAZY) {
if (first) { if (first) {
seg->maxpasses = 10; seg->maxpasses = 10;
} else { } else {

View File

@ -44,7 +44,8 @@
/* TODO MSD: */ /* TODO MSD: */
#ifdef TODO_MSD #ifdef TODO_MSD
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img) { void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_image_t * img)
{
int tileno, compno, resno, bandno, precno;/*, cblkno;*/ int tileno, compno, resno, bandno, precno;/*, cblkno;*/
fprintf(fd, "image {\n"); fprintf(fd, "image {\n");
@ -206,7 +207,8 @@ opj_tcd_t* opj_tcd_create(OPJ_BOOL p_is_decoder)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd) { void opj_tcd_rateallocate_fixed(opj_tcd_t *tcd)
{
OPJ_UINT32 layno; OPJ_UINT32 layno;
for (layno = 0; layno < tcd->tcp->numlayers; layno++) { for (layno = 0; layno < tcd->tcp->numlayers; layno++) {
@ -300,7 +302,8 @@ void opj_tcd_makelayer( opj_tcd_t *tcd,
} }
} }
void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final) { void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final)
{
OPJ_UINT32 compno, resno, bandno, precno, cblkno; OPJ_UINT32 compno, resno, bandno, precno, cblkno;
OPJ_INT32 value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */ OPJ_INT32 value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolutions][3]; */
OPJ_INT32 matrice[10][10][3]; OPJ_INT32 matrice[10][10][3];
@ -521,8 +524,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
lo = thresh; lo = thresh;
continue; continue;
} } else {
else {
distoachieved = layno == 0 ? distoachieved = layno == 0 ?
tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno];
@ -546,8 +548,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
lo = thresh; lo = thresh;
} }
} else { } else {
if (! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest,p_data_written, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC)) if (! opj_t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest,p_data_written, maxlen, cstr_info,tcd->cur_tp_num,tcd->tp_pos,tcd->cur_pino,THRESH_CALC)) {
{
/* TODO: what to do with l ??? seek / tell ??? */ /* TODO: what to do with l ??? seek / tell ??? */
/* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */ /* opj_event_msg(tcd->cinfo, EVT_INFO, "rate alloc: len=%d, max=%d\n", l, maxlen); */
lo = thresh; lo = thresh;
@ -611,7 +612,8 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd,
/** /**
Destroy a previously created TCD handle Destroy a previously created TCD handle
*/ */
void opj_tcd_destroy(opj_tcd_t *tcd) { void opj_tcd_destroy(opj_tcd_t *tcd)
{
if (tcd) { if (tcd) {
opj_tcd_free_tile(tcd); opj_tcd_free_tile(tcd);
@ -633,8 +635,7 @@ OPJ_BOOL opj_alloc_tile_component_data(opj_tcd_tilecomp_t *l_tilec)
/*fprintf(stderr, "tAllocate data of tilec (int): %d x OPJ_UINT32n",l_data_size);*/ /*fprintf(stderr, "tAllocate data of tilec (int): %d x OPJ_UINT32n",l_data_size);*/
l_tilec->data_size = l_tilec->data_size_needed; l_tilec->data_size = l_tilec->data_size_needed;
l_tilec->ownsData = OPJ_TRUE; l_tilec->ownsData = OPJ_TRUE;
} } else if (l_tilec->data_size_needed > l_tilec->data_size) {
else if (l_tilec->data_size_needed > l_tilec->data_size) {
/* We don't need to keep old data */ /* We don't need to keep old data */
opj_aligned_free(l_tilec->data); opj_aligned_free(l_tilec->data);
l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_tilec->data_size_needed); l_tilec->data = (OPJ_INT32 *) opj_aligned_malloc(l_tilec->data_size_needed);
@ -741,8 +742,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_tilec->numresolutions = l_tccp->numresolutions; l_tilec->numresolutions = l_tccp->numresolutions;
if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) { if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) {
l_tilec->minimum_num_resolutions = 1; l_tilec->minimum_num_resolutions = 1;
} } else {
else {
l_tilec->minimum_num_resolutions = l_tccp->numresolutions - l_cp->m_specific_param.m_dec.m_reduce; l_tilec->minimum_num_resolutions = l_tccp->numresolutions - l_cp->m_specific_param.m_dec.m_reduce;
} }
@ -762,8 +762,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
/*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %d\n",l_data_size);*/ /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %d\n",l_data_size);*/
l_tilec->resolutions_size = l_data_size; l_tilec->resolutions_size = l_data_size;
memset(l_tilec->resolutions,0,l_data_size); memset(l_tilec->resolutions,0,l_data_size);
} } else if (l_data_size > l_tilec->resolutions_size) {
else if (l_data_size > l_tilec->resolutions_size) {
opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolution_t *) opj_realloc(l_tilec->resolutions, l_data_size); opj_tcd_resolution_t* new_resolutions = (opj_tcd_resolution_t *) opj_realloc(l_tilec->resolutions, l_data_size);
if (! new_resolutions) { if (! new_resolutions) {
opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile resolutions\n"); opj_event_msg(manager, EVT_ERROR, "Not enough memory for tile resolutions\n");
@ -783,8 +782,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_step_size = l_tccp->stepsizes; l_step_size = l_tccp->stepsizes;
if (l_tccp->qmfbid == 0) { if (l_tccp->qmfbid == 0) {
l_gain_ptr = &opj_dwt_getgain_real; l_gain_ptr = &opj_dwt_getgain_real;
} } else {
else {
l_gain_ptr = &opj_dwt_getgain; l_gain_ptr = &opj_dwt_getgain;
} }
/*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/ /*fprintf(stderr, "\tlevel_no=%d\n",l_level_no);*/
@ -826,8 +824,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
cbgwidthexpn = l_pdx; cbgwidthexpn = l_pdx;
cbgheightexpn = l_pdy; cbgheightexpn = l_pdy;
l_res->numbands = 1; l_res->numbands = 1;
} } else {
else {
tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_start, 1); tlcbgxstart = opj_int_ceildivpow2(l_tl_prc_x_start, 1);
tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_start, 1); tlcbgystart = opj_int_ceildivpow2(l_tl_prc_y_start, 1);
/*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end, 1);*/ /*brcbgxend = opj_int_ceildivpow2(l_br_prc_x_end, 1);*/
@ -851,8 +848,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no); l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no);
l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no); l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no);
l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no); l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no);
} } else {
else {
l_band->bandno = bandno + 1; l_band->bandno = bandno + 1;
/* x0b = 1 if bandno = 1 or 3 */ /* x0b = 1 if bandno = 1 or 3 */
l_x0b = l_band->bandno&1; l_x0b = l_band->bandno&1;
@ -879,8 +875,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
/*fprintf(stderr, "\t\t\t\tAllocate precincts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */ /*fprintf(stderr, "\t\t\t\tAllocate precincts of a band (opj_tcd_precinct_t): %d\n",l_nb_precinct_size); */
memset(l_band->precincts,0,l_nb_precinct_size); memset(l_band->precincts,0,l_nb_precinct_size);
l_band->precincts_data_size = l_nb_precinct_size; l_band->precincts_data_size = l_nb_precinct_size;
} } else if (l_band->precincts_data_size < l_nb_precinct_size) {
else if (l_band->precincts_data_size < l_nb_precinct_size) {
opj_tcd_precinct_t * new_precincts = (opj_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size); opj_tcd_precinct_t * new_precincts = (opj_tcd_precinct_t *) opj_realloc(l_band->precincts,/*3 * */ l_nb_precinct_size);
if (! new_precincts) { if (! new_precincts) {
@ -940,8 +935,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
memset(l_current_precinct->cblks.blocks,0,l_nb_code_blocks_size); memset(l_current_precinct->cblks.blocks,0,l_nb_code_blocks_size);
l_current_precinct->block_size = l_nb_code_blocks_size; l_current_precinct->block_size = l_nb_code_blocks_size;
} } else if (l_nb_code_blocks_size > l_current_precinct->block_size) {
else if (l_nb_code_blocks_size > l_current_precinct->block_size) {
void *new_blocks = opj_realloc(l_current_precinct->cblks.blocks, l_nb_code_blocks_size); void *new_blocks = opj_realloc(l_current_precinct->cblks.blocks, l_nb_code_blocks_size);
if (! new_blocks) { if (! new_blocks) {
opj_free(l_current_precinct->cblks.blocks); opj_free(l_current_precinct->cblks.blocks);
@ -962,8 +956,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
if (! l_current_precinct->incltree) { if (! l_current_precinct->incltree) {
l_current_precinct->incltree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager); l_current_precinct->incltree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager);
} } else {
else{
l_current_precinct->incltree = opj_tgt_init(l_current_precinct->incltree, l_current_precinct->cw, l_current_precinct->ch, manager); l_current_precinct->incltree = opj_tgt_init(l_current_precinct->incltree, l_current_precinct->cw, l_current_precinct->ch, manager);
} }
@ -974,8 +967,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
if (! l_current_precinct->imsbtree) { if (! l_current_precinct->imsbtree) {
l_current_precinct->imsbtree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager); l_current_precinct->imsbtree = opj_tgt_create(l_current_precinct->cw, l_current_precinct->ch, manager);
} } else {
else {
l_current_precinct->imsbtree = opj_tgt_init(l_current_precinct->imsbtree, l_current_precinct->cw, l_current_precinct->ch, manager); l_current_precinct->imsbtree = opj_tgt_init(l_current_precinct->imsbtree, l_current_precinct->cw, l_current_precinct->ch, manager);
} }
@ -1288,8 +1280,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/*--------------TIER2------------------*/ /*--------------TIER2------------------*/
/* FIXME _ProfStart(PGROUP_T2); */ /* FIXME _ProfStart(PGROUP_T2); */
l_data_read = 0; l_data_read = 0;
if (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index, p_manager)) if (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index, p_manager)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
/* FIXME _ProfStop(PGROUP_T2); */ /* FIXME _ProfStop(PGROUP_T2); */
@ -1298,8 +1289,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/* FIXME _ProfStart(PGROUP_T1); */ /* FIXME _ProfStart(PGROUP_T1); */
if if
(! opj_tcd_t1_decode(p_tcd)) (! opj_tcd_t1_decode(p_tcd)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
/* FIXME _ProfStop(PGROUP_T1); */ /* FIXME _ProfStop(PGROUP_T1); */
@ -1308,8 +1298,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/* FIXME _ProfStart(PGROUP_DWT); */ /* FIXME _ProfStart(PGROUP_DWT); */
if if
(! opj_tcd_dwt_decode(p_tcd)) (! opj_tcd_dwt_decode(p_tcd)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
/* FIXME _ProfStop(PGROUP_DWT); */ /* FIXME _ProfStop(PGROUP_DWT); */
@ -1317,16 +1306,14 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd,
/*----------------MCT-------------------*/ /*----------------MCT-------------------*/
/* FIXME _ProfStart(PGROUP_MCT); */ /* FIXME _ProfStart(PGROUP_MCT); */
if if
(! opj_tcd_mct_decode(p_tcd, p_manager)) (! opj_tcd_mct_decode(p_tcd, p_manager)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
/* FIXME _ProfStop(PGROUP_MCT); */ /* FIXME _ProfStop(PGROUP_MCT); */
/* FIXME _ProfStart(PGROUP_DC_SHIFT); */ /* FIXME _ProfStart(PGROUP_DC_SHIFT); */
if if
(! opj_tcd_dc_level_shift_decode(p_tcd)) (! opj_tcd_dc_level_shift_decode(p_tcd)) {
{
return OPJ_FALSE; return OPJ_FALSE;
} }
/* FIXME _ProfStop(PGROUP_DC_SHIFT); */ /* FIXME _ProfStop(PGROUP_DC_SHIFT); */
@ -1372,10 +1359,8 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
l_size_comp = 4; l_size_comp = 4;
} }
switch (l_size_comp) switch (l_size_comp) {
{ case 1: {
case 1:
{
OPJ_CHAR * l_dest_ptr = (OPJ_CHAR *) p_dest; OPJ_CHAR * l_dest_ptr = (OPJ_CHAR *) p_dest;
const OPJ_INT32 * l_src_ptr = l_tilec->data; const OPJ_INT32 * l_src_ptr = l_tilec->data;
@ -1386,8 +1371,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
} }
} } else {
else {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) { for (k=0; k<l_width; ++k) {
*(l_dest_ptr++) = (OPJ_CHAR) ((*(l_src_ptr++))&0xff); *(l_dest_ptr++) = (OPJ_CHAR) ((*(l_src_ptr++))&0xff);
@ -1399,8 +1383,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
p_dest = (OPJ_BYTE *)l_dest_ptr; p_dest = (OPJ_BYTE *)l_dest_ptr;
} }
break; break;
case 2: case 2: {
{
const OPJ_INT32 * l_src_ptr = l_tilec->data; const OPJ_INT32 * l_src_ptr = l_tilec->data;
OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_dest; OPJ_INT16 * l_dest_ptr = (OPJ_INT16 *) p_dest;
@ -1411,8 +1394,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
} }
} } else {
else {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
for (k=0; k<l_width; ++k) { for (k=0; k<l_width; ++k) {
*(l_dest_ptr++) = (OPJ_INT16) ((*(l_src_ptr++))&0xffff); *(l_dest_ptr++) = (OPJ_INT16) ((*(l_src_ptr++))&0xffff);
@ -1424,8 +1406,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
p_dest = (OPJ_BYTE*) l_dest_ptr; p_dest = (OPJ_BYTE*) l_dest_ptr;
} }
break; break;
case 4: case 4: {
{
OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_dest; OPJ_INT32 * l_dest_ptr = (OPJ_INT32 *) p_dest;
OPJ_INT32 * l_src_ptr = l_tilec->data; OPJ_INT32 * l_src_ptr = l_tilec->data;
@ -1472,8 +1453,7 @@ static void opj_tcd_free_tile(opj_tcd_t *p_tcd)
if (p_tcd->m_is_decoder) { if (p_tcd->m_is_decoder) {
l_tcd_code_block_deallocate = opj_tcd_code_block_dec_deallocate; l_tcd_code_block_deallocate = opj_tcd_code_block_dec_deallocate;
} } else {
else {
l_tcd_code_block_deallocate = opj_tcd_code_block_enc_deallocate; l_tcd_code_block_deallocate = opj_tcd_code_block_enc_deallocate;
} }
@ -1624,8 +1604,7 @@ static OPJ_BOOL opj_tcd_dwt_decode ( opj_tcd_t *p_tcd )
if (! opj_dwt_decode(l_tile_comp, l_img_comp->resno_decoded+1)) { if (! opj_dwt_decode(l_tile_comp, l_img_comp->resno_decoded+1)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
if (! opj_dwt_decode_real(l_tile_comp, l_img_comp->resno_decoded+1)) { if (! opj_dwt_decode_real(l_tile_comp, l_img_comp->resno_decoded+1)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -1658,8 +1637,7 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
(l_tile->comps[2].x1 - l_tile->comps[2].x0) * (l_tile->comps[2].y1 - l_tile->comps[2].y0) < (OPJ_INT32)l_samples) { (l_tile->comps[2].x1 - l_tile->comps[2].x0) * (l_tile->comps[2].y1 - l_tile->comps[2].y0) < (OPJ_INT32)l_samples) {
opj_event_msg(p_manager, EVT_ERROR, "Tiles don't all have the same dimension. Skip the MCT step.\n"); opj_event_msg(p_manager, EVT_ERROR, "Tiles don't all have the same dimension. Skip the MCT step.\n");
return OPJ_FALSE; return OPJ_FALSE;
} } else if (l_tcp->mct == 2) {
else if (l_tcp->mct == 2) {
OPJ_BYTE ** l_data; OPJ_BYTE ** l_data;
if (! l_tcp->m_mct_decoding_matrix) { if (! l_tcp->m_mct_decoding_matrix) {
@ -1691,23 +1669,20 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
} }
opj_free(l_data); opj_free(l_data);
} } else {
else {
if (l_tcp->tccps->qmfbid == 1) { if (l_tcp->tccps->qmfbid == 1) {
opj_mct_decode( l_tile->comps[0].data, opj_mct_decode( l_tile->comps[0].data,
l_tile->comps[1].data, l_tile->comps[1].data,
l_tile->comps[2].data, l_tile->comps[2].data,
l_samples); l_samples);
} } else {
else {
opj_mct_decode_real((OPJ_FLOAT32*)l_tile->comps[0].data, opj_mct_decode_real((OPJ_FLOAT32*)l_tile->comps[0].data,
(OPJ_FLOAT32*)l_tile->comps[1].data, (OPJ_FLOAT32*)l_tile->comps[1].data,
(OPJ_FLOAT32*)l_tile->comps[2].data, (OPJ_FLOAT32*)l_tile->comps[2].data,
l_samples); l_samples);
} }
} }
} } else {
else {
opj_event_msg(p_manager, EVT_ERROR, "Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",l_tile->numcomps); opj_event_msg(p_manager, EVT_ERROR, "Number of components (%d) is inconsistent with a MCT. Skip the MCT step.\n",l_tile->numcomps);
} }
@ -1744,8 +1719,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
l_min = -(1 << (l_img_comp->prec - 1)); l_min = -(1 << (l_img_comp->prec - 1));
l_max = (1 << (l_img_comp->prec - 1)) - 1; l_max = (1 << (l_img_comp->prec - 1)) - 1;
} } else {
else {
l_min = 0; l_min = 0;
l_max = (1 << l_img_comp->prec) - 1; l_max = (1 << l_img_comp->prec) - 1;
} }
@ -1760,8 +1734,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
} }
l_current_ptr += l_stride; l_current_ptr += l_stride;
} }
} } else {
else {
for (j=0; j<l_height; ++j) { for (j=0; j<l_height; ++j) {
for (i = 0; i < l_width; ++i) { for (i = 0; i < l_width; ++i) {
OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr); OPJ_FLOAT32 l_value = *((OPJ_FLOAT32 *) l_current_ptr);
@ -1908,8 +1881,7 @@ static OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd )
*l_current_ptr -= l_tccp->m_dc_level_shift ; *l_current_ptr -= l_tccp->m_dc_level_shift ;
++l_current_ptr; ++l_current_ptr;
} }
} } else {
else {
for (i = 0; i < l_nb_elem; ++i) { for (i = 0; i < l_nb_elem; ++i) {
*l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) << 11 ; *l_current_ptr = (*l_current_ptr - l_tccp->m_dc_level_shift) << 11 ;
++l_current_ptr; ++l_current_ptr;
@ -1961,18 +1933,15 @@ static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
/* nb of components (i.e. size of pData) */ /* nb of components (i.e. size of pData) */
l_tile->numcomps, l_tile->numcomps,
/* tells if the data is signed */ /* tells if the data is signed */
p_tcd->image->comps->sgnd) ) p_tcd->image->comps->sgnd) ) {
{
opj_free(l_data); opj_free(l_data);
return OPJ_FALSE; return OPJ_FALSE;
} }
opj_free(l_data); opj_free(l_data);
} } else if (l_tcp->tccps->qmfbid == 0) {
else if (l_tcp->tccps->qmfbid == 0) {
opj_mct_encode_real(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples); opj_mct_encode_real(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples);
} } else {
else {
opj_mct_encode(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples); opj_mct_encode(l_tile->comps[0].data, l_tile->comps[1].data, l_tile->comps[2].data, samples);
} }
@ -1991,8 +1960,7 @@ static OPJ_BOOL opj_tcd_dwt_encode ( opj_tcd_t *p_tcd )
if (! opj_dwt_encode(l_tile_comp)) { if (! opj_dwt_encode(l_tile_comp)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else if (l_tccp->qmfbid == 0) {
else if (l_tccp->qmfbid == 0) {
if (! opj_dwt_encode_real(l_tile_comp)) { if (! opj_dwt_encode_real(l_tile_comp)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -2022,12 +1990,10 @@ static OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd )
/* irreversible encoding */ /* irreversible encoding */
if (l_tcp->tccps->qmfbid == 0) { if (l_tcp->tccps->qmfbid == 0) {
l_mct_norms = opj_mct_get_mct_norms_real(); l_mct_norms = opj_mct_get_mct_norms_real();
} } else {
else {
l_mct_norms = opj_mct_get_mct_norms(); l_mct_norms = opj_mct_get_mct_norms();
} }
} } else {
else {
l_mct_numcomps = p_tcd->image->numcomps; l_mct_numcomps = p_tcd->image->numcomps;
l_mct_norms = (const OPJ_FLOAT64 *) (l_tcp->mct_norms); l_mct_norms = (const OPJ_FLOAT64 *) (l_tcp->mct_norms);
} }
@ -2067,8 +2033,7 @@ static OPJ_BOOL opj_tcd_t2_encode (opj_tcd_t *p_tcd,
p_tcd->tp_num, p_tcd->tp_num,
p_tcd->tp_pos, p_tcd->tp_pos,
p_tcd->cur_pino, p_tcd->cur_pino,
FINAL_PASS)) FINAL_PASS)) {
{
opj_t2_destroy(l_t2); opj_t2_destroy(l_t2);
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -2098,8 +2063,7 @@ static OPJ_BOOL opj_tcd_rate_allocate_encode( opj_tcd_t *p_tcd,
if (! opj_tcd_rateallocate(p_tcd, p_dest_data,&l_nb_written, p_max_dest_size, p_cstr_info)) { if (! opj_tcd_rateallocate(p_tcd, p_dest_data,&l_nb_written, p_max_dest_size, p_cstr_info)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
} } else {
else {
/* Fixed layer allocation */ /* Fixed layer allocation */
opj_tcd_rateallocate_fixed(p_tcd); opj_tcd_rateallocate_fixed(p_tcd);
} }
@ -2139,8 +2103,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
} }
switch (l_size_comp) { switch (l_size_comp) {
case 1: case 1: {
{
OPJ_CHAR * l_src_ptr = (OPJ_CHAR *) p_src; OPJ_CHAR * l_src_ptr = (OPJ_CHAR *) p_src;
OPJ_INT32 * l_dest_ptr = l_tilec->data; OPJ_INT32 * l_dest_ptr = l_tilec->data;
@ -2148,8 +2111,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
for (j=0; j<l_nb_elem; ++j) { for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++)); *(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++));
} }
} } else {
else {
for (j=0; j<l_nb_elem; ++j) { for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (*(l_src_ptr++))&0xff; *(l_dest_ptr++) = (*(l_src_ptr++))&0xff;
} }
@ -2158,8 +2120,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
p_src = (OPJ_BYTE*) l_src_ptr; p_src = (OPJ_BYTE*) l_src_ptr;
} }
break; break;
case 2: case 2: {
{
OPJ_INT32 * l_dest_ptr = l_tilec->data; OPJ_INT32 * l_dest_ptr = l_tilec->data;
OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_src; OPJ_INT16 * l_src_ptr = (OPJ_INT16 *) p_src;
@ -2167,8 +2128,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
for (j=0; j<l_nb_elem; ++j) { for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++)); *(l_dest_ptr++) = (OPJ_INT32) (*(l_src_ptr++));
} }
} } else {
else {
for (j=0; j<l_nb_elem; ++j) { for (j=0; j<l_nb_elem; ++j) {
*(l_dest_ptr++) = (*(l_src_ptr++))&0xffff; *(l_dest_ptr++) = (*(l_src_ptr++))&0xffff;
} }
@ -2177,8 +2137,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
p_src = (OPJ_BYTE*) l_src_ptr; p_src = (OPJ_BYTE*) l_src_ptr;
} }
break; break;
case 4: case 4: {
{
OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_src; OPJ_INT32 * l_src_ptr = (OPJ_INT32 *) p_src;
OPJ_INT32 * l_dest_ptr = l_tilec->data; OPJ_INT32 * l_dest_ptr = l_tilec->data;

View File

@ -155,8 +155,7 @@ typedef struct opj_tcd_resolution {
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_tilecomp typedef struct opj_tcd_tilecomp {
{
OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of component : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 numresolutions; /* number of resolutions level */ OPJ_UINT32 numresolutions; /* number of resolutions level */
OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/ OPJ_UINT32 minimum_num_resolutions; /* number of resolutions level to decode (at max)*/
@ -186,8 +185,7 @@ typedef struct opj_tcd_tile {
/** /**
FIXME DOC FIXME DOC
*/ */
typedef struct opj_tcd_image typedef struct opj_tcd_image {
{
opj_tcd_tile_t *tiles; /* Tiles information */ opj_tcd_tile_t *tiles; /* Tiles information */
} }
opj_tcd_image_t; opj_tcd_image_t;
@ -196,8 +194,7 @@ opj_tcd_image_t;
/** /**
Tile coder/decoder Tile coder/decoder
*/ */
typedef struct opj_tcd typedef struct opj_tcd {
{
/** Position of the tilepart flag in Progression order*/ /** Position of the tilepart flag in Progression order*/
OPJ_INT32 tp_pos; OPJ_INT32 tp_pos;
/** Tile part number*/ /** Tile part number*/

View File

@ -45,7 +45,8 @@
========================================================== ==========================================================
*/ */
opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager) { opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv, opj_event_mgr_t *manager)
{
OPJ_INT32 nplh[32]; OPJ_INT32 nplh[32];
OPJ_INT32 nplv[32]; OPJ_INT32 nplv[32];
opj_tgt_node_t *node = 00; opj_tgt_node_t *node = 00;
@ -155,15 +156,13 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
l_nplh[0] = (OPJ_INT32)p_num_leafs_h; l_nplh[0] = (OPJ_INT32)p_num_leafs_h;
l_nplv[0] = (OPJ_INT32)p_num_leafs_v; l_nplv[0] = (OPJ_INT32)p_num_leafs_v;
p_tree->numnodes = 0; p_tree->numnodes = 0;
do do {
{
n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]); n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]);
l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2; l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2;
l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2; l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2;
p_tree->numnodes += n; p_tree->numnodes += n;
++l_num_levels; ++l_num_levels;
} } while (n > 1);
while (n > 1);
/* ADD */ /* ADD */
if (p_tree->numnodes == 0) { if (p_tree->numnodes == 0) {
@ -199,12 +198,9 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
} }
++l_parent_node; ++l_parent_node;
} }
if ((j & 1) || j == l_nplv[i] - 1) if ((j & 1) || j == l_nplv[i] - 1) {
{
l_parent_node0 = l_parent_node; l_parent_node0 = l_parent_node;
} } else {
else
{
l_parent_node = l_parent_node0; l_parent_node = l_parent_node0;
l_parent_node0 += l_nplh[i]; l_parent_node0 += l_nplh[i];
} }
@ -230,7 +226,8 @@ void opj_tgt_destroy(opj_tgt_tree_t *p_tree)
opj_free(p_tree); opj_free(p_tree);
} }
void opj_tgt_reset(opj_tgt_tree_t *p_tree) { void opj_tgt_reset(opj_tgt_tree_t *p_tree)
{
OPJ_UINT32 i; OPJ_UINT32 i;
opj_tgt_node_t * l_current_node = 00;; opj_tgt_node_t * l_current_node = 00;;
@ -239,8 +236,7 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
} }
l_current_node = p_tree->nodes; l_current_node = p_tree->nodes;
for (i = 0; i < p_tree->numnodes; ++i) for (i = 0; i < p_tree->numnodes; ++i) {
{
l_current_node->value = 999; l_current_node->value = 999;
l_current_node->low = 0; l_current_node->low = 0;
l_current_node->known = 0; l_current_node->known = 0;
@ -248,7 +244,8 @@ void opj_tgt_reset(opj_tgt_tree_t *p_tree) {
} }
} }
void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value) { void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
{
opj_tgt_node_t *node; opj_tgt_node_t *node;
node = &tree->nodes[leafno]; node = &tree->nodes[leafno];
while (node && node->value > value) { while (node && node->value > value) {
@ -257,7 +254,8 @@ void opj_tgt_setvalue(opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 value)
} }
} }
void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) { void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold)
{
opj_tgt_node_t *stk[31]; opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr; opj_tgt_node_t **stkptr;
opj_tgt_node_t *node; opj_tgt_node_t *node;
@ -297,7 +295,8 @@ void opj_tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ
} }
} }
OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold) { OPJ_UINT32 opj_tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT32 threshold)
{
opj_tgt_node_t *stk[31]; opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr; opj_tgt_node_t **stkptr;
opj_tgt_node_t *node; opj_tgt_node_t *node;

View File

@ -64,8 +64,7 @@ typedef struct opj_tgt_node {
/** /**
Tag tree Tag tree
*/ */
typedef struct opj_tgt_tree typedef struct opj_tgt_tree {
{
OPJ_UINT32 numleafsh; OPJ_UINT32 numleafsh;
OPJ_UINT32 numleafsv; OPJ_UINT32 numleafsv;
OPJ_UINT32 numnodes; OPJ_UINT32 numnodes;

View File

@ -105,8 +105,7 @@ int opj_write_tpixfaix( int coff,
if( j2klen > pow( 2, 32)) { if( j2klen > pow( 2, 32)) {
size_of_coding = 8; size_of_coding = 8;
version = num_max_tile_parts == 1 ? 1:3; version = num_max_tile_parts == 1 ? 1:3;
} } else {
else{
size_of_coding = 4; size_of_coding = 4;
version = num_max_tile_parts == 1 ? 0:2; version = num_max_tile_parts == 1 ? 0:2;
} }
@ -123,10 +122,8 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */ opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++) for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++) {
{ for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++) {
for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++)
{
tp = cstr_info.tile[i].tp[j]; tp = cstr_info.tile[i].tp[j];
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */ opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */
@ -134,8 +131,7 @@ int opj_write_tpixfaix( int coff,
opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */ opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
if (version & 0x02) if (version & 0x02) {
{
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1) if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1); Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1);
else else
@ -150,8 +146,7 @@ int opj_write_tpixfaix( int coff,
/*cio_write(0,4);*/ /*cio_write(0,4);*/
} }
/* PADDING */ /* PADDING */
while (j < num_max_tile_parts) while (j < num_max_tile_parts) {
{
opj_write_bytes(l_data_header,0,size_of_coding);/* start position */ opj_write_bytes(l_data_header,0,size_of_coding);/* start position */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);

View File

@ -77,7 +77,8 @@ static int bio_bytein(opj_bio_t *bio);
========================================================== ==========================================================
*/ */
static int bio_byteout(opj_bio_t *bio) { static int bio_byteout(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff; bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) { if (bio->bp >= bio->end) {
@ -87,7 +88,8 @@ static int bio_byteout(opj_bio_t *bio) {
return 0; return 0;
} }
static int bio_bytein(opj_bio_t *bio) { static int bio_bytein(opj_bio_t *bio)
{
bio->buf = (bio->buf << 8) & 0xffff; bio->buf = (bio->buf << 8) & 0xffff;
bio->ct = bio->buf == 0xff00 ? 7 : 8; bio->ct = bio->buf == 0xff00 ? 7 : 8;
if (bio->bp >= bio->end) { if (bio->bp >= bio->end) {
@ -97,7 +99,8 @@ static int bio_bytein(opj_bio_t *bio) {
return 0; return 0;
} }
static void bio_putbit(opj_bio_t *bio, int b) { static void bio_putbit(opj_bio_t *bio, int b)
{
if (bio->ct == 0) { if (bio->ct == 0) {
bio_byteout(bio); bio_byteout(bio);
} }
@ -106,7 +109,8 @@ static void bio_putbit(opj_bio_t *bio, int b) {
} }
/* MOD antonin */ /* MOD antonin */
static int bio_getbit(opj_bio_t *bio) { static int bio_getbit(opj_bio_t *bio)
{
/* DOM */ /* DOM */
if (bio->ct == 0) { if (bio->ct == 0) {
bio_bytein(bio); bio_bytein(bio);
@ -121,22 +125,26 @@ static int bio_getbit(opj_bio_t *bio) {
========================================================== ==========================================================
*/ */
opj_bio_t* bio_create() { opj_bio_t* bio_create()
{
opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t));
return bio; return bio;
} }
void bio_destroy(opj_bio_t *bio) { void bio_destroy(opj_bio_t *bio)
{
if(bio) { if(bio) {
opj_free(bio); opj_free(bio);
} }
} }
int bio_numbytes(opj_bio_t *bio) { int bio_numbytes(opj_bio_t *bio)
{
return (bio->bp - bio->start); return (bio->bp - bio->start);
} }
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) { void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len)
{
bio->start = bp; bio->start = bp;
bio->end = bp + len; bio->end = bp + len;
bio->bp = bp; bio->bp = bp;
@ -144,7 +152,8 @@ void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) {
bio->ct = 8; bio->ct = 8;
} }
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) { void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len)
{
bio->start = bp; bio->start = bp;
bio->end = bp + len; bio->end = bp + len;
bio->bp = bp; bio->bp = bp;
@ -152,14 +161,16 @@ void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
bio->ct = 0; bio->ct = 0;
} }
void bio_write(opj_bio_t *bio, int v, int n) { void bio_write(opj_bio_t *bio, int v, int n)
{
int i; int i;
for (i = n - 1; i >= 0; i--) { for (i = n - 1; i >= 0; i--) {
bio_putbit(bio, (v >> i) & 1); bio_putbit(bio, (v >> i) & 1);
} }
} }
int bio_read(opj_bio_t *bio, int n) { int bio_read(opj_bio_t *bio, int n)
{
int i, v; int i, v;
v = 0; v = 0;
for (i = n - 1; i >= 0; i--) { for (i = n - 1; i >= 0; i--) {
@ -168,7 +179,8 @@ int bio_read(opj_bio_t *bio, int n) {
return v; return v;
} }
int bio_flush(opj_bio_t *bio) { int bio_flush(opj_bio_t *bio)
{
bio->ct = 0; bio->ct = 0;
if (bio_byteout(bio)) { if (bio_byteout(bio)) {
return 1; return 1;
@ -182,7 +194,8 @@ int bio_flush(opj_bio_t *bio) {
return 0; return 0;
} }
int bio_inalign(opj_bio_t *bio) { int bio_inalign(opj_bio_t *bio)
{
bio->ct = 0; bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) { if ((bio->buf & 0xff) == 0xff) {
if (bio_bytein(bio)) { if (bio_bytein(bio)) {

View File

@ -37,7 +37,8 @@
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length)
{
opj_cp_t *cp = NULL; opj_cp_t *cp = NULL;
opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t));
if(!cio) return NULL; if(!cio) return NULL;
@ -47,8 +48,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
cio->openmode = OPJ_STREAM_READ; cio->openmode = OPJ_STREAM_READ;
cio->buffer = buffer; cio->buffer = buffer;
cio->length = length; cio->length = length;
} } else if(!buffer && !length && cinfo) {
else if(!buffer && !length && cinfo) {
/* allocate a buffer for the encoded image */ /* allocate a buffer for the encoded image */
cio->openmode = OPJ_STREAM_WRITE; cio->openmode = OPJ_STREAM_WRITE;
switch(cinfo->codec_format) { switch(cinfo->codec_format) {
@ -67,8 +67,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
opj_free(cio); opj_free(cio);
return NULL; return NULL;
} }
} } else {
else {
opj_free(cio); opj_free(cio);
return NULL; return NULL;
} }
@ -81,7 +80,8 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer
return cio; return cio;
} }
void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio)
{
if(cio) { if(cio) {
if(cio->openmode == OPJ_STREAM_WRITE) { if(cio->openmode == OPJ_STREAM_WRITE) {
/* destroy the allocated buffer */ /* destroy the allocated buffer */
@ -98,7 +98,8 @@ void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) {
/* /*
* Get position in byte stream. * Get position in byte stream.
*/ */
int OPJ_CALLCONV cio_tell(opj_cio_t *cio) { int OPJ_CALLCONV cio_tell(opj_cio_t *cio)
{
return cio->bp - cio->start; return cio->bp - cio->start;
} }
@ -107,28 +108,32 @@ int OPJ_CALLCONV cio_tell(opj_cio_t *cio) {
* *
* pos : position, in number of bytes, from the beginning of the stream * pos : position, in number of bytes, from the beginning of the stream
*/ */
void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos)
{
cio->bp = cio->start + pos; cio->bp = cio->start + pos;
} }
/* /*
* Number of bytes left before the end of the stream. * Number of bytes left before the end of the stream.
*/ */
int cio_numbytesleft(opj_cio_t *cio) { int cio_numbytesleft(opj_cio_t *cio)
{
return cio->end - cio->bp; return cio->end - cio->bp;
} }
/* /*
* Get pointer to the current position in the stream. * Get pointer to the current position in the stream.
*/ */
unsigned char *cio_getbp(opj_cio_t *cio) { unsigned char *cio_getbp(opj_cio_t *cio)
{
return cio->bp; return cio->bp;
} }
/* /*
* Write a byte. * Write a byte.
*/ */
static bool cio_byteout(opj_cio_t *cio, unsigned char v) { static bool cio_byteout(opj_cio_t *cio, unsigned char v)
{
if (cio->bp >= cio->end) { if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n");
return false; return false;
@ -140,7 +145,8 @@ static bool cio_byteout(opj_cio_t *cio, unsigned char v) {
/* /*
* Read a byte. * Read a byte.
*/ */
static unsigned char cio_bytein(opj_cio_t *cio) { static unsigned char cio_bytein(opj_cio_t *cio)
{
if (cio->bp >= cio->end) { if (cio->bp >= cio->end) {
opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n"); opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n");
return 0; return 0;
@ -154,7 +160,8 @@ static unsigned char cio_bytein(opj_cio_t *cio) {
* v : value to write * v : value to write
* n : number of bytes to write * n : number of bytes to write
*/ */
unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) { unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n)
{
int i; int i;
for (i = n - 1; i >= 0; i--) { for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) )
@ -170,7 +177,8 @@ unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) {
* *
* return : value of the n bytes read * return : value of the n bytes read
*/ */
unsigned int cio_read(opj_cio_t *cio, int n) { unsigned int cio_read(opj_cio_t *cio, int n)
{
int i; int i;
unsigned int v; unsigned int v;
v = 0; v = 0;
@ -185,7 +193,8 @@ unsigned int cio_read(opj_cio_t *cio, int n) {
* *
* n : number of bytes to skip * n : number of bytes to skip
*/ */
void cio_skip(opj_cio_t *cio, int n) { void cio_skip(opj_cio_t *cio, int n)
{
cio->bp += n; cio->bp += n;
} }
@ -195,7 +204,8 @@ void cio_skip(opj_cio_t *cio, int n) {
* v : value to write * v : value to write
* n : number of bytes to write * n : number of bytes to write
*/ */
int cio_write_int(opj_cio_t *cio, int v, int n) { int cio_write_int(opj_cio_t *cio, int v, int n)
{
int i; int i;
for (i = n - 1; i >= 0; i--) { for (i = n - 1; i >= 0; i--) {
if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) ) if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) )
@ -211,7 +221,8 @@ int cio_write_int(opj_cio_t *cio, int v, int n) {
* *
* return : value of the n bytes read * return : value of the n bytes read
*/ */
int cio_read_int(opj_cio_t *cio, int n) { int cio_read_int(opj_cio_t *cio, int n)
{
int i; int i;
int v; int v;
v = 0; v = 0;

View File

@ -224,8 +224,11 @@ static opj_atk_t atk_info_wt[] = {
{3, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-1}, {0,1,2}, {0,1,2}, {1,1,3}, {{-1},{1},{1,0,-1}}}, /* WT 2-6 REV*/ {3, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-1}, {0,1,2}, {0,1,2}, {1,1,3}, {{-1},{1},{1,0,-1}}}, /* WT 2-6 REV*/
{4, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-2}, {0,1,6}, {0,1,32}, {1,1,5}, {{-1},{1},{-3,22,0,-22,3}}}, /* WT 2-10 REV*/ {4, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-2}, {0,1,6}, {0,1,32}, {1,1,5}, {{-1},{1},{-3,22,0,-22,3}}}, /* WT 2-10 REV*/
{5, 1, J3D_ATK_ARB, J3D_ATK_IRR, 1, J3D_ATK_WS, 1, 7, {0}, {0}, {0}, {1,1,2,1,2,1,3},{{-1},{1.58613434206},{-0.460348209828, 0.460348209828},{0.25},{0.374213867768,-0.374213867768},{-1.33613434206},{0.29306717103,0,-0.29306717103}}}, /* WT 6-10 IRR*/ {5, 1, J3D_ATK_ARB, J3D_ATK_IRR, 1, J3D_ATK_WS, 1, 7, {0}, {0}, {0}, {1,1,2,1,2,1,3},{{-1},{1.58613434206},{-0.460348209828, 0.460348209828},{0.25},{0.374213867768,-0.374213867768},{-1.33613434206},{0.29306717103,0,-0.29306717103}}}, /* WT 6-10 IRR*/
{6, 1, J3D_ATK_ARB, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 11, {0}, {0}, {0}, {1,1,2,1,2,1,2,1,2,1,5},{{-1},{0,99715069105},{-1.00573127827, 1.00573127827},{-0.27040357631},{2.20509972343, -2.20509972343},{0.08059995736}, {
{-1.62682532350, 1.62682532350},{0.52040357631},{0.60404664250, -0.60404664250},{-0.82775064841},{-0.06615812964, 0.29402137720, 0, -0.29402137720, 0.06615812964}}}, /* WT 10-18 IRR*/ 6, 1, J3D_ATK_ARB, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 11, {0}, {0}, {0}, {1,1,2,1,2,1,2,1,2,1,5},{{-1},{0,99715069105},{-1.00573127827, 1.00573127827},{-0.27040357631},{2.20509972343, -2.20509972343},{0.08059995736},
{-1.62682532350, 1.62682532350},{0.52040357631},{0.60404664250, -0.60404664250},{-0.82775064841},{-0.06615812964, 0.29402137720, 0, -0.29402137720, 0.06615812964}
}
}, /* WT 10-18 IRR*/
{7, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 2, {0}, {0}, {0}, {1,1}, {-0.5, 0.25}}, /* WT 5-3 IRR*/ {7, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 2, {0}, {0}, {0}, {1,1}, {-0.5, 0.25}}, /* WT 5-3 IRR*/
{8, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {4,4}, {8,8}, {2,2}, {{-9,1},{5,-1}}} /* WT 13-7 REV*/ {8, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {4,4}, {8,8}, {2,2}, {{-9,1},{5,-1}}} /* WT 13-7 REV*/
}; };
@ -238,7 +241,8 @@ static opj_atk_t atk_info_wt[] = {
/* <summary> */ /* <summary> */
/* Forward lazy transform (horizontal). */ /* Forward lazy transform (horizontal). */
/* </summary> */ /* </summary> */
static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) { static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas)
{
int i; int i;
for (i=0; i<sn; i++) b[i]=a[2*i+cas]; for (i=0; i<sn; i++) b[i]=a[2*i+cas];
for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)]; for (i=0; i<dn; i++) b[sn+i]=a[(2*i+1-cas)];
@ -247,7 +251,8 @@ static void dwt_deinterleave_h(int *a, int *b, int dn, int sn, int cas) {
/* <summary> */ /* <summary> */
/* Forward lazy transform (vertical). */ /* Forward lazy transform (vertical). */
/* </summary> */ /* </summary> */
static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) { static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas)
{
int i; int i;
for (i=0; i<sn; i++) b[i*x]=a[2*i+cas]; for (i=0; i<sn; i++) b[i*x]=a[2*i+cas];
for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)]; for (i=0; i<dn; i++) b[(sn+i)*x]=a[(2*i+1-cas)];
@ -256,7 +261,8 @@ static void dwt_deinterleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
/* <summary> */ /* <summary> */
/* Forward lazy transform (axial). */ /* Forward lazy transform (axial). */
/* </summary> */ /* </summary> */
static void dwt_deinterleave_z(int *a, int *b, int dn, int sn, int xy, int cas) { static void dwt_deinterleave_z(int *a, int *b, int dn, int sn, int xy, int cas)
{
int i; int i;
for (i=0; i<sn; i++) b[i*xy]=a[2*i+cas]; for (i=0; i<sn; i++) b[i*xy]=a[2*i+cas];
for (i=0; i<dn; i++) b[(sn+i)*xy]=a[(2*i+1-cas)]; for (i=0; i<dn; i++) b[(sn+i)*xy]=a[(2*i+1-cas)];
@ -265,7 +271,8 @@ static void dwt_deinterleave_z(int *a, int *b, int dn, int sn, int xy, int cas)
/* <summary> */ /* <summary> */
/* Inverse lazy transform (horizontal). */ /* Inverse lazy transform (horizontal). */
/* </summary> */ /* </summary> */
static void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas) { static void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas)
{
int i; int i;
int *ai = NULL; int *ai = NULL;
int *bi = NULL; int *bi = NULL;
@ -288,7 +295,8 @@ static void dwt_interleave_h(int *a, int *b, int dn, int sn, int cas) {
/* <summary> */ /* <summary> */
/* Inverse lazy transform (vertical). */ /* Inverse lazy transform (vertical). */
/* </summary> */ /* </summary> */
static void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas) { static void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas)
{
int i; int i;
int *ai = NULL; int *ai = NULL;
int *bi = NULL; int *bi = NULL;
@ -311,7 +319,8 @@ static void dwt_interleave_v(int *a, int *b, int dn, int sn, int x, int cas) {
/* <summary> */ /* <summary> */
/* Inverse lazy transform (axial). */ /* Inverse lazy transform (axial). */
/* </summary> */ /* </summary> */
static void dwt_interleave_z(int *a, int *b, int dn, int sn, int xy, int cas) { static void dwt_interleave_z(int *a, int *b, int dn, int sn, int xy, int cas)
{
int i; int i;
int *ai = NULL; int *ai = NULL;
int *bi = NULL; int *bi = NULL;
@ -335,7 +344,8 @@ static void dwt_interleave_z(int *a, int *b, int dn, int sn, int xy, int cas) {
/* <summary> */ /* <summary> */
/* Forward 5-3 or 9-7 wavelet transform in 1-D. */ /* Forward 5-3 or 9-7 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
static void dwt_encode_53(int *a, int dn, int sn, int cas) { static void dwt_encode_53(int *a, int dn, int sn, int cas)
{
int i; int i;
if (!cas) { if (!cas) {
@ -373,7 +383,8 @@ static void dwt_encode_53(int *a, int dn, int sn, int cas) {
} }
} }
} }
static void dwt_encode_97(int *a, int dn, int sn, int cas) { static void dwt_encode_97(int *a, int dn, int sn, int cas)
{
int i; int i;
if (!cas) { if (!cas) {
@ -411,7 +422,8 @@ static void dwt_encode_97(int *a, int dn, int sn, int cas) {
/* <summary> */ /* <summary> */
/* Inverse 5-3 or 9-7 wavelet transform in 1-D. */ /* Inverse 5-3 or 9-7 wavelet transform in 1-D. */
/* </summary> */ /* </summary> */
static void dwt_decode_53(int *a, int dn, int sn, int cas) { static void dwt_decode_53(int *a, int dn, int sn, int cas)
{
int i; int i;
if (!cas) { if (!cas) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
@ -427,7 +439,8 @@ static void dwt_decode_53(int *a, int dn, int sn, int cas) {
} }
} }
} }
static void dwt_decode_97(int *a, int dn, int sn, int cas) { static void dwt_decode_97(int *a, int dn, int sn, int cas)
{
int i; int i;
if (!cas) { if (!cas) {
@ -467,7 +480,8 @@ static void dwt_decode_97(int *a, int dn, int sn, int cas) {
/* <summary> */ /* <summary> */
/* Get norm of arbitrary wavelet transform. */ /* Get norm of arbitrary wavelet transform. */
/* </summary> */ /* </summary> */
static int upandconv(double *nXPS, double *LPS, int lenXPS, int lenLPS) { static int upandconv(double *nXPS, double *LPS, int lenXPS, int lenLPS)
{
/* Perform the convolution of the vectors. */ /* Perform the convolution of the vectors. */
int i,j; int i,j;
double *tmp = (double *)opj_malloc(2*lenXPS * sizeof(double)); double *tmp = (double *)opj_malloc(2*lenXPS * sizeof(double));
@ -488,7 +502,8 @@ static int upandconv(double *nXPS, double *LPS, int lenXPS, int lenLPS) {
return 2*lenXPS+lenLPS-1; return 2*lenXPS+lenLPS-1;
} }
static double dwt_calc_wtnorms(int orient, int level[3], int dwtid[3], opj_wtfilt_t *wtfiltX, opj_wtfilt_t *wtfiltY, opj_wtfilt_t *wtfiltZ) { static double dwt_calc_wtnorms(int orient, int level[3], int dwtid[3], opj_wtfilt_t *wtfiltX, opj_wtfilt_t *wtfiltY, opj_wtfilt_t *wtfiltZ)
{
int i, lenLPS, lenHPS; int i, lenLPS, lenHPS;
double Lx = 0, Ly= 0, Hx= 0, Hy= 0, Lz= 0, Hz= 0; double Lx = 0, Ly= 0, Hx= 0, Hy= 0, Lz= 0, Hz= 0;
double *nLPSx, *nHPSx,*nLPSy, *nHPSy,*nLPSz, *nHPSz; double *nLPSx, *nHPSx,*nLPSy, *nHPSy,*nLPSz, *nHPSz;
@ -590,7 +605,8 @@ static double dwt_calc_wtnorms(int orient, int level[3], int dwtid[3], opj_wtfil
free(nLPSz); free(nLPSz);
free(nHPSz); free(nHPSz);
} else { } else {
Lz = 1.0; Hz = 1.0; Lz = 1.0;
Hz = 1.0;
} }
switch (orient) { switch (orient) {
case 0: case 0:
@ -614,27 +630,40 @@ static double dwt_calc_wtnorms(int orient, int level[3], int dwtid[3], opj_wtfil
} }
} }
static void dwt_getwtfilters(opj_wtfilt_t *wtfilt, int dwtid) { static void dwt_getwtfilters(opj_wtfilt_t *wtfilt, int dwtid)
{
if (dwtid == 0) { /*DWT 9-7 */ if (dwtid == 0) { /*DWT 9-7 */
wtfilt->lenLPS = 7; wtfilt->lenHPS = 9; wtfilt->lenLPS = 7;
wtfilt->lenHPS = 9;
wtfilt->LPS = (double *)opj_malloc(wtfilt->lenLPS * sizeof(double)); wtfilt->LPS = (double *)opj_malloc(wtfilt->lenLPS * sizeof(double));
wtfilt->HPS = (double *)opj_malloc(wtfilt->lenHPS * sizeof(double)); wtfilt->HPS = (double *)opj_malloc(wtfilt->lenHPS * sizeof(double));
wtfilt->LPS[0] = -0.091271763114; wtfilt->HPS[0] = 0.026748757411; wtfilt->LPS[0] = -0.091271763114;
wtfilt->LPS[1] = -0.057543526228; wtfilt->HPS[1] = 0.016864118443; wtfilt->HPS[0] = 0.026748757411;
wtfilt->LPS[2] = 0.591271763114; wtfilt->HPS[2] = -0.078223266529; wtfilt->LPS[1] = -0.057543526228;
wtfilt->LPS[3] = 1.115087052457; wtfilt->HPS[3] = -0.266864118443; wtfilt->HPS[1] = 0.016864118443;
wtfilt->LPS[4] = 0.591271763114; wtfilt->HPS[4] = 0.602949018236; wtfilt->LPS[2] = 0.591271763114;
wtfilt->LPS[5] = -0.057543526228; wtfilt->HPS[5] = -0.266864118443; wtfilt->HPS[2] = -0.078223266529;
wtfilt->LPS[6] = -0.091271763114; wtfilt->HPS[6] = -0.078223266529; wtfilt->LPS[3] = 1.115087052457;
wtfilt->HPS[3] = -0.266864118443;
wtfilt->LPS[4] = 0.591271763114;
wtfilt->HPS[4] = 0.602949018236;
wtfilt->LPS[5] = -0.057543526228;
wtfilt->HPS[5] = -0.266864118443;
wtfilt->LPS[6] = -0.091271763114;
wtfilt->HPS[6] = -0.078223266529;
wtfilt->HPS[7] = 0.016864118443; wtfilt->HPS[7] = 0.016864118443;
wtfilt->HPS[8] = 0.026748757411; wtfilt->HPS[8] = 0.026748757411;
} else if (dwtid == 1) { /*DWT 5-3 */ } else if (dwtid == 1) { /*DWT 5-3 */
wtfilt->lenLPS = 3; wtfilt->lenHPS = 5; wtfilt->lenLPS = 3;
wtfilt->lenHPS = 5;
wtfilt->LPS = (double *)opj_malloc(wtfilt->lenLPS * sizeof(double)); wtfilt->LPS = (double *)opj_malloc(wtfilt->lenLPS * sizeof(double));
wtfilt->HPS = (double *)opj_malloc(wtfilt->lenHPS * sizeof(double)); wtfilt->HPS = (double *)opj_malloc(wtfilt->lenHPS * sizeof(double));
wtfilt->LPS[0] = 0.5; wtfilt->HPS[0] = -0.125; wtfilt->LPS[0] = 0.5;
wtfilt->LPS[1] = 1; wtfilt->HPS[1] = -0.25; wtfilt->HPS[0] = -0.125;
wtfilt->LPS[2] = 0.5; wtfilt->HPS[2] = 0.75; wtfilt->LPS[1] = 1;
wtfilt->HPS[1] = -0.25;
wtfilt->LPS[2] = 0.5;
wtfilt->HPS[2] = 0.75;
wtfilt->HPS[3] = -0.25; wtfilt->HPS[3] = -0.25;
wtfilt->HPS[4] = -0.125; wtfilt->HPS[4] = -0.125;
} else { } else {
@ -645,7 +674,8 @@ static void dwt_getwtfilters(opj_wtfilt_t *wtfilt, int dwtid) {
/* <summary> */ /* <summary> */
/* Encoding of quantization stepsize for each subband. */ /* Encoding of quantization stepsize for each subband. */
/* </summary> */ /* </summary> */
static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize) { static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno_stepsize)
{
int p, n; int p, n;
p = int_floorlog2(stepsize) - 13; p = int_floorlog2(stepsize) - 13;
n = 11 - int_floorlog2(stepsize); n = 11 - int_floorlog2(stepsize);
@ -663,7 +693,8 @@ static void dwt_encode_stepsize(int stepsize, int numbps, opj_stepsize_t *bandno
/* <summary> */ /* <summary> */
/* Forward 5-3 wavelet transform in 3-D. */ /* Forward 5-3 wavelet transform in 3-D. */
/* </summary> */ /* </summary> */
void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]) { void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3])
{
int i, j, k; int i, j, k;
int x, y, z; int x, y, z;
int w, h, wh, d; int w, h, wh, d;
@ -794,7 +825,8 @@ void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]) {
/* <summary> */ /* <summary> */
/* Inverse 5-3 wavelet transform in 3-D. */ /* Inverse 5-3 wavelet transform in 3-D. */
/* </summary> */ /* </summary> */
void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]) { void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3])
{
int i, j, k; int i, j, k;
int x, y, z; int x, y, z;
int w, h, wh, d; int w, h, wh, d;
@ -925,7 +957,8 @@ void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]) {
/* <summary> */ /* <summary> */
/* Get gain of wavelet transform. */ /* Get gain of wavelet transform. */
/* </summary> */ /* </summary> */
int dwt_getgain(int orient, int reversible) { int dwt_getgain(int orient, int reversible)
{
if (reversible == 1) { if (reversible == 1) {
if (orient == 0) if (orient == 0)
return 0; return 0;
@ -943,7 +976,8 @@ int dwt_getgain(int orient, int reversible) {
/* <summary> */ /* <summary> */
/* Get norm of wavelet transform. */ /* Get norm of wavelet transform. */
/* </summary> */ /* </summary> */
double dwt_getnorm(int orient, int level[3], int dwtid[3]) { double dwt_getnorm(int orient, int level[3], int dwtid[3])
{
int levelx = level[0]; int levelx = level[0];
int levely = level[1]; int levely = level[1];
int levelz = (level[2] < 0) ? 0 : level[2]; int levelz = (level[2] < 0) ? 0 : level[2];
@ -966,9 +1000,15 @@ double dwt_getnorm(int orient, int level[3], int dwtid[3]) {
dwt_norm[levelx][levely][levelz][orient] = norm; dwt_norm[levelx][levely][levelz][orient] = norm;
flagnorm[levelx][levely][levelz][orient] = 1; flagnorm[levelx][levely][levelz][orient] = 1;
/*Free reserved space*/ /*Free reserved space*/
opj_free(wtfiltx->LPS); opj_free(wtfilty->LPS); opj_free(wtfiltz->LPS); opj_free(wtfiltx->LPS);
opj_free(wtfiltx->HPS); opj_free(wtfilty->HPS); opj_free(wtfiltz->HPS); opj_free(wtfilty->LPS);
opj_free(wtfiltx); opj_free(wtfilty); opj_free(wtfiltz); opj_free(wtfiltz->LPS);
opj_free(wtfiltx->HPS);
opj_free(wtfilty->HPS);
opj_free(wtfiltz->HPS);
opj_free(wtfiltx);
opj_free(wtfilty);
opj_free(wtfiltz);
/*fprintf(stdout,"[INFO] Dwtid: %d %d %d Level: %d %d %d Orient %d Norm: %f \n",dwtid[0],dwtid[1],dwtid[2],level[0],level[1],level[2],orient,norm);*/ /*fprintf(stdout,"[INFO] Dwtid: %d %d %d Level: %d %d %d Orient %d Norm: %f \n",dwtid[0],dwtid[1],dwtid[2],level[0],level[1],level[2],orient,norm);*/
} }
return norm; return norm;
@ -976,7 +1016,8 @@ double dwt_getnorm(int orient, int level[3], int dwtid[3]) {
/* <summary> */ /* <summary> */
/* Calculate explicit stepsizes for DWT. */ /* Calculate explicit stepsizes for DWT. */
/* </summary> */ /* </summary> */
void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec) { void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec)
{
int totnumbands, bandno, diff; int totnumbands, bandno, diff;
assert(tccp->numresolution[0] >= tccp->numresolution[2]); assert(tccp->numresolution[0] >= tccp->numresolution[2]);

View File

@ -37,7 +37,8 @@
#ifndef _WIN32 #ifndef _WIN32
static char* static char*
i2a(unsigned i, char *a, unsigned r) { i2a(unsigned i, char *a, unsigned r)
{
if (i/r > 0) a = i2a(i/r,a,r); if (i/r > 0) a = i2a(i/r,a,r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r];
return a+1; return a+1;
@ -52,13 +53,13 @@ i2a(unsigned i, char *a, unsigned r) {
@return Returns a @return Returns a
*/ */
static char * static char *
_itoa(int i, char *a, int r) { _itoa(int i, char *a, int r)
{
r = ((r < 2) || (r > 36)) ? 10 : r; r = ((r < 2) || (r > 36)) ? 10 : r;
if(i < 0) { if(i < 0) {
*a = '-'; *a = '-';
*i2a(-i, a+1, r) = 0; *i2a(-i, a+1, r) = 0;
} } else *i2a(i, a, r) = 0;
else *i2a(i, a, r) = 0;
return a; return a;
} }
@ -66,7 +67,8 @@ _itoa(int i, char *a, int r) {
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context)
{
if(cinfo) { if(cinfo) {
opj_event_mgr_t *previous = cinfo->event_mgr; opj_event_mgr_t *previous = cinfo->event_mgr;
cinfo->event_mgr = event_mgr; cinfo->event_mgr = event_mgr;
@ -77,7 +79,8 @@ opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_
return NULL; return NULL;
} }
bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...)
{
#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ #define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */
opj_msg_callback msg_handler = NULL; opj_msg_callback msg_handler = NULL;
@ -120,8 +123,7 @@ bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
case '%' : case '%' :
message[j++] = '%'; message[j++] = '%';
break; break;
case 'o' : /* octal numbers */ case 'o' : { /* octal numbers */
{
char tmp[16]; char tmp[16];
_itoa(va_arg(arg, int), tmp, 8); _itoa(va_arg(arg, int), tmp, 8);
strcat(message, tmp); strcat(message, tmp);
@ -130,8 +132,7 @@ bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
break; break;
} }
case 'i' : /* decimal numbers */ case 'i' : /* decimal numbers */
case 'd' : case 'd' : {
{
char tmp[16]; char tmp[16];
_itoa(va_arg(arg, int), tmp, 10); _itoa(va_arg(arg, int), tmp, 10);
strcat(message, tmp); strcat(message, tmp);
@ -139,8 +140,7 @@ bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
++i; ++i;
break; break;
} }
case 'x' : /* hexadecimal numbers */ case 'x' : { /* hexadecimal numbers */
{
char tmp[16]; char tmp[16];
_itoa(va_arg(arg, int), tmp, 16); _itoa(va_arg(arg, int), tmp, 16);
strcat(message, tmp); strcat(message, tmp);
@ -148,16 +148,14 @@ bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) {
++i; ++i;
break; break;
} }
case 's' : /* strings */ case 's' : { /* strings */
{
char *tmp = va_arg(arg, char*); char *tmp = va_arg(arg, char*);
strcat(message, tmp); strcat(message, tmp);
j += strlen(tmp); j += strlen(tmp);
++i; ++i;
break; break;
} }
case 'f' : /* floats */ case 'f' : { /* floats */
{
char tmp[16]; char tmp[16];
double value = va_arg(arg, double); double value = va_arg(arg, double);
sprintf(tmp, "%f", value); sprintf(tmp, "%f", value);

View File

@ -57,7 +57,8 @@ Multiply two fixed-precision rational numbers.
@param b @param b
@return Returns a * b @return Returns a * b
*/ */
static int fix_mul(int a, int b) { static int fix_mul(int a, int b)
{
int64 temp = (int64) a * (int64) b >> 12; int64 temp = (int64) a * (int64) b >> 12;
return (int) ((temp >> 1) + (temp & 1)) ; return (int) ((temp >> 1) + (temp & 1)) ;
} }

View File

@ -51,14 +51,16 @@ The functions in INT.H have for goal to realize operations on integers.
Get the minimum of two integers Get the minimum of two integers
@return Returns a if a < b else b @return Returns a if a < b else b
*/ */
static int int_min(int a, int b) { static int int_min(int a, int b)
{
return a < b ? a : b; return a < b ? a : b;
} }
/** /**
Get the maximum of two integers Get the maximum of two integers
@return Returns a if a > b else b @return Returns a if a > b else b
*/ */
static int int_max(int a, int b) { static int int_max(int a, int b)
{
return (a > b) ? a : b; return (a > b) ? a : b;
} }
/** /**
@ -70,7 +72,8 @@ Clamp an integer inside an interval
<li>Returns min if (a < min) <li>Returns min if (a < min)
</ul> </ul>
*/ */
static int int_clamp(int a, int min, int max) { static int int_clamp(int a, int min, int max)
{
if (a < min) if (a < min)
return min; return min;
if (a > max) if (a > max)
@ -80,39 +83,45 @@ static int int_clamp(int a, int min, int max) {
/** /**
@return Get absolute value of integer @return Get absolute value of integer
*/ */
static int int_abs(int a) { static int int_abs(int a)
{
return a < 0 ? -a : a; return a < 0 ? -a : a;
} }
static double dbl_abs(double a) { static double dbl_abs(double a)
{
return a < 0 ? -a : a; return a < 0 ? -a : a;
} }
/** /**
Divide an integer and round upwards Divide an integer and round upwards
@return Returns a divided by b @return Returns a divided by b
*/ */
static int int_ceildiv(int a, int b) { static int int_ceildiv(int a, int b)
{
return (a + b - 1) / b; return (a + b - 1) / b;
} }
/** /**
Divide an integer by a power of 2 and round upwards Divide an integer by a power of 2 and round upwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static int int_ceildivpow2(int a, int b) { static int int_ceildivpow2(int a, int b)
{
return (a + (1 << b) - 1) >> b; return (a + (1 << b) - 1) >> b;
} }
/** /**
Divide an integer by a power of 2 and round downwards Divide an integer by a power of 2 and round downwards
@return Returns a divided by 2^b @return Returns a divided by 2^b
*/ */
static int int_floordivpow2(int a, int b) { static int int_floordivpow2(int a, int b)
{
return a >> b; return a >> b;
} }
/** /**
Get logarithm of an integer and round downwards Get logarithm of an integer and round downwards
@return Returns log2(a) @return Returns log2(a)
*/ */
static int int_floorlog2(int a) { static int int_floorlog2(int a)
{
int l; int l;
for (l = 0; a > 1; l++) { for (l = 0; a > 1; l++) {
a >>= 1; a >>= 1;

View File

@ -321,7 +321,8 @@ static void j3d_read_nlt(opj_j3d_t *j3d);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static void j3d_dump_volume(FILE *fd, opj_volume_t * vol) { static void j3d_dump_volume(FILE *fd, opj_volume_t * vol)
{
int compno; int compno;
fprintf(fd, "volume {\n"); fprintf(fd, "volume {\n");
fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1); fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1);
@ -337,7 +338,8 @@ static void j3d_dump_volume(FILE *fd, opj_volume_t * vol) {
fprintf(fd, "}\n"); fprintf(fd, "}\n");
} }
static void j3d_dump_cp(FILE *fd, opj_volume_t * vol, opj_cp_t * cp) { static void j3d_dump_cp(FILE *fd, opj_volume_t * vol, opj_cp_t * cp)
{
int tileno, compno, layno, bandno, resno, numbands; int tileno, compno, layno, bandno, resno, numbands;
fprintf(fd, "coding parameters {\n"); fprintf(fd, "coding parameters {\n");
fprintf(fd, " tx0=%d, ty0=%d, tz0=%d\n", cp->tx0, cp->ty0, cp->tz0); fprintf(fd, " tx0=%d, ty0=%d, tz0=%d\n", cp->tx0, cp->ty0, cp->tz0);
@ -415,7 +417,8 @@ static void j3d_dump_cp(FILE *fd, opj_volume_t * vol, opj_cp_t * cp) {
Extended capabilities Extended capabilities
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
static void j3d_write_cap(opj_j3d_t *j3d){ static void j3d_write_cap(opj_j3d_t *j3d)
{
int len,lenp; int len,lenp;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -423,8 +426,7 @@ static void j3d_write_cap(opj_j3d_t *j3d){
lenp = cio_tell(cio); lenp = cio_tell(cio);
cio_skip(cio, 2); cio_skip(cio, 2);
cio_write(cio,J3D_CAP_10, 4); cio_write(cio,J3D_CAP_10, 4);
if( J3D_CAP_10 ) if( J3D_CAP_10 ) {
{
cio_write(cio, 0x0, 2); cio_write(cio, 0x0, 2);
} }
len = cio_tell(cio) - lenp; len = cio_tell(cio) - lenp;
@ -433,7 +435,8 @@ static void j3d_write_cap(opj_j3d_t *j3d){
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_cap(opj_j3d_t *j3d){ static void j3d_read_cap(opj_j3d_t *j3d)
{
int len, Cap; int len, Cap;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
/*cio_read(cio, 2); CAP */ /*cio_read(cio, 2); CAP */
@ -444,7 +447,8 @@ static void j3d_read_cap(opj_j3d_t *j3d){
} }
assert( len == 2 + 4 + 2 ); assert( len == 2 + 4 + 2 );
} }
static void j3d_write_nsi(opj_j3d_t *j3d) { static void j3d_write_nsi(opj_j3d_t *j3d)
{
int i; int i;
int lenp, len; int lenp, len;
int ndim = 3; int ndim = 3;
@ -470,7 +474,8 @@ static void j3d_write_nsi(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_nsi(opj_j3d_t *j3d) { static void j3d_read_nsi(opj_j3d_t *j3d)
{
int ndim; int ndim;
int len, i; int len, i;
@ -519,7 +524,8 @@ static void j3d_read_nsi(opj_j3d_t *j3d) {
j3d->state = J3D_STATE_MH; j3d->state = J3D_STATE_MH;
} }
static void j3d_write_dco(opj_j3d_t *j3d){ static void j3d_write_dco(opj_j3d_t *j3d)
{
int lenp, len, i; int lenp, len, i;
int dcotype; int dcotype;
@ -547,7 +553,8 @@ static void j3d_write_dco(opj_j3d_t *j3d){
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_dco(opj_j3d_t *j3d){ static void j3d_read_dco(opj_j3d_t *j3d)
{
int len, i; int len, i;
int dcotype; int dcotype;
@ -572,7 +579,8 @@ static void j3d_read_dco(opj_j3d_t *j3d){
} }
} }
static void j3d_write_atk(opj_j3d_t *j3d){ static void j3d_write_atk(opj_j3d_t *j3d)
{
int lenp, len, s, k; int lenp, len, s, k;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -603,7 +611,8 @@ static void j3d_write_atk(opj_j3d_t *j3d){
cio_write(cio, len, 2); /* Latk */ cio_write(cio, len, 2); /* Latk */
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_atk(opj_j3d_t *j3d){ static void j3d_read_atk(opj_j3d_t *j3d)
{
int len, i, Satk, k; int len, i, Satk, k;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -634,39 +643,52 @@ static void j3d_read_atk(opj_j3d_t *j3d){
atk->Aatk[i][k] = ((double) cio_read(cio, 1 << atk->coeff_typ) / 8192.0); atk->Aatk[i][k] = ((double) cio_read(cio, 1 << atk->coeff_typ) / 8192.0);
} }
} }
static void j3d_write_cbd(opj_j3d_t *j3d){ static void j3d_write_cbd(opj_j3d_t *j3d)
{
} }
static void j3d_read_cbd(opj_j3d_t *j3d){ static void j3d_read_cbd(opj_j3d_t *j3d)
{
} }
static void j3d_write_mct(opj_j3d_t *j3d){ static void j3d_write_mct(opj_j3d_t *j3d)
{
} }
static void j3d_read_mct(opj_j3d_t *j3d){ static void j3d_read_mct(opj_j3d_t *j3d)
{
} }
static void j3d_write_mcc(opj_j3d_t *j3d){ static void j3d_write_mcc(opj_j3d_t *j3d)
{
} }
static void j3d_read_mcc(opj_j3d_t *j3d){ static void j3d_read_mcc(opj_j3d_t *j3d)
{
} }
static void j3d_write_mco(opj_j3d_t *j3d){ static void j3d_write_mco(opj_j3d_t *j3d)
{
} }
static void j3d_read_mco(opj_j3d_t *j3d){ static void j3d_read_mco(opj_j3d_t *j3d)
{
} }
static void j3d_write_nlt(opj_j3d_t *j3d){ static void j3d_write_nlt(opj_j3d_t *j3d)
{
} }
static void j3d_read_nlt(opj_j3d_t *j3d){ static void j3d_read_nlt(opj_j3d_t *j3d)
{
} }
/* ----------------------------------------------------------------------- /* -----------------------------------------------------------------------
15444-1 codestream syntax 15444-1 codestream syntax
------------------------------------------------------------------------*/ ------------------------------------------------------------------------*/
static void j3d_write_soc(opj_j3d_t *j3d) { static void j3d_write_soc(opj_j3d_t *j3d)
{
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
cio_write(cio, J3D_MS_SOC, 2); cio_write(cio, J3D_MS_SOC, 2);
} }
static void j3d_read_soc(opj_j3d_t *j3d) { static void j3d_read_soc(opj_j3d_t *j3d)
{
j3d->state = J3D_STATE_MHSIZ; j3d->state = J3D_STATE_MHSIZ;
} }
static void j3d_write_siz(opj_j3d_t *j3d) { static void j3d_write_siz(opj_j3d_t *j3d)
{
int i; int i;
int lenp, len; int lenp, len;
int Rsiz; int Rsiz;
@ -701,7 +723,8 @@ static void j3d_write_siz(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_siz(opj_j3d_t *j3d) { static void j3d_read_siz(opj_j3d_t *j3d)
{
int len, i; int len, i;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -776,7 +799,8 @@ static void j3d_read_siz(opj_j3d_t *j3d) {
static void j3d_write_com(opj_j3d_t *j3d) { static void j3d_write_com(opj_j3d_t *j3d)
{
unsigned int i; unsigned int i;
int lenp, len; int lenp, len;
@ -799,7 +823,8 @@ static void j3d_write_com(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_com(opj_j3d_t *j3d) { static void j3d_read_com(opj_j3d_t *j3d)
{
int len; int len;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -811,7 +836,8 @@ static void j3d_read_com(opj_j3d_t *j3d) {
cio_skip(cio, len - 4); /*posible comments*/ cio_skip(cio, len - 4); /*posible comments*/
} }
static void j3d_write_cox(opj_j3d_t *j3d, int compno) { static void j3d_write_cox(opj_j3d_t *j3d, int compno)
{
int i; int i;
int shift = 2; int shift = 2;
@ -846,15 +872,16 @@ static void j3d_write_cox(opj_j3d_t *j3d, int compno) {
for (i = 0; i < tccp->numresolution[0]; i++) { for (i = 0; i < tccp->numresolution[0]; i++) {
if (i < tccp->numresolution[2]) if (i < tccp->numresolution[2])
cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4) + (tccp->prctsiz[2][i] << 8), 2); /* SPcox (N_i) Table A9*/ cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4) + (tccp->prctsiz[2][i] << 8), 2); /* SPcox (N_i) Table A9*/
else else if (j3d->cinfo->codec_format == CODEC_J3D)
if (j3d->cinfo->codec_format == CODEC_J3D)
cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 2); /* SPcox (N_i) Table A9*/ cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 2); /* SPcox (N_i) Table A9*/
else else
cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 1); /* SPcox (N_i) Table A9*/ } cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 1); /* SPcox (N_i) Table A9*/
}
} }
} }
static void j3d_read_cox(opj_j3d_t *j3d, int compno) { static void j3d_read_cox(opj_j3d_t *j3d, int compno)
{
int i; int i;
int shift = 2; int shift = 2;
@ -907,7 +934,8 @@ static void j3d_read_cox(opj_j3d_t *j3d, int compno) {
} }
} }
static void j3d_write_cod(opj_j3d_t *j3d) { static void j3d_write_cod(opj_j3d_t *j3d)
{
opj_cp_t *cp = NULL; opj_cp_t *cp = NULL;
opj_tcp_t *tcp = NULL; opj_tcp_t *tcp = NULL;
int lenp, len; int lenp, len;
@ -936,7 +964,8 @@ static void j3d_write_cod(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_cod(opj_j3d_t *j3d) { static void j3d_read_cod(opj_j3d_t *j3d)
{
int len, i, pos; int len, i, pos;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -961,7 +990,8 @@ static void j3d_read_cod(opj_j3d_t *j3d) {
} }
} }
static void j3d_write_coc(opj_j3d_t *j3d, int compno) { static void j3d_write_coc(opj_j3d_t *j3d, int compno)
{
int lenp, len; int lenp, len;
opj_cp_t *cp = j3d->cp; opj_cp_t *cp = j3d->cp;
@ -983,7 +1013,8 @@ static void j3d_write_coc(opj_j3d_t *j3d, int compno) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_coc(opj_j3d_t *j3d) { static void j3d_read_coc(opj_j3d_t *j3d)
{
int len, compno; int len, compno;
opj_cp_t *cp = j3d->cp; opj_cp_t *cp = j3d->cp;
@ -997,7 +1028,8 @@ static void j3d_read_coc(opj_j3d_t *j3d) {
j3d_read_cox(j3d, compno); j3d_read_cox(j3d, compno);
} }
static void j3d_write_qcx(opj_j3d_t *j3d, int compno) { static void j3d_write_qcx(opj_j3d_t *j3d, int compno)
{
int bandno, numbands; int bandno, numbands;
int expn, mant; int expn, mant;
@ -1028,7 +1060,8 @@ static void j3d_write_qcx(opj_j3d_t *j3d, int compno) {
} }
} }
static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len) { static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len)
{
int tmp; int tmp;
int bandno, numbands; int bandno, numbands;
@ -1071,7 +1104,8 @@ static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len) {
/* ddA */ /* ddA */
} }
static void j3d_write_qcd(opj_j3d_t *j3d) { static void j3d_write_qcd(opj_j3d_t *j3d)
{
int lenp, len; int lenp, len;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1086,7 +1120,8 @@ static void j3d_write_qcd(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_qcd(opj_j3d_t *j3d) { static void j3d_read_qcd(opj_j3d_t *j3d)
{
int len, i, pos; int len, i, pos;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1100,7 +1135,8 @@ static void j3d_read_qcd(opj_j3d_t *j3d) {
} }
} }
static void j3d_write_qcc(opj_j3d_t *j3d, int compno) { static void j3d_write_qcc(opj_j3d_t *j3d, int compno)
{
int lenp, len; int lenp, len;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1116,7 +1152,8 @@ static void j3d_write_qcc(opj_j3d_t *j3d, int compno) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_qcc(opj_j3d_t *j3d) { static void j3d_read_qcc(opj_j3d_t *j3d)
{
int len, compno; int len, compno;
int numcomp = j3d->volume->numcomps; int numcomp = j3d->volume->numcomps;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1126,7 +1163,8 @@ static void j3d_read_qcc(opj_j3d_t *j3d) {
j3d_read_qcx(j3d, compno, len - 2 - (numcomp <= 256 ? 1 : 2)); j3d_read_qcx(j3d, compno, len - 2 - (numcomp <= 256 ? 1 : 2));
} }
static void j3d_write_poc(opj_j3d_t *j3d) { static void j3d_write_poc(opj_j3d_t *j3d)
{
int len, numpchgs, i; int len, numpchgs, i;
int numcomps = j3d->volume->numcomps; int numcomps = j3d->volume->numcomps;
@ -1154,7 +1192,8 @@ static void j3d_write_poc(opj_j3d_t *j3d) {
} }
} }
static void j3d_read_poc(opj_j3d_t *j3d) { static void j3d_read_poc(opj_j3d_t *j3d)
{
int len, numpchgs, i, old_poc; int len, numpchgs, i, old_poc;
int numcomps = j3d->volume->numcomps; int numcomps = j3d->volume->numcomps;
@ -1184,7 +1223,8 @@ static void j3d_read_poc(opj_j3d_t *j3d) {
tcp->numpocs = numpchgs + old_poc - 1; tcp->numpocs = numpchgs + old_poc - 1;
} }
static void j3d_read_crg(opj_j3d_t *j3d) { static void j3d_read_crg(opj_j3d_t *j3d)
{
int len, i, Xcrg_i, Ycrg_i, Zcrg_i; int len, i, Xcrg_i, Ycrg_i, Zcrg_i;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1198,7 +1238,8 @@ static void j3d_read_crg(opj_j3d_t *j3d) {
} }
} }
static void j3d_read_tlm(opj_j3d_t *j3d) { static void j3d_read_tlm(opj_j3d_t *j3d)
{
int len, Ztlm, Stlm, ST, SP, tile_tlm, i; int len, Ztlm, Stlm, ST, SP, tile_tlm, i;
long int Ttlm_i, Ptlm_i; long int Ttlm_i, Ptlm_i;
@ -1216,7 +1257,8 @@ static void j3d_read_tlm(opj_j3d_t *j3d) {
} }
} }
static void j3d_read_plm(opj_j3d_t *j3d) { static void j3d_read_plm(opj_j3d_t *j3d)
{
int len, i, Zplm, Nplm, add, packet_len = 0; int len, i, Zplm, Nplm, add, packet_len = 0;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1241,7 +1283,8 @@ static void j3d_read_plm(opj_j3d_t *j3d) {
} }
} }
static void j3d_read_plt(opj_j3d_t *j3d) { static void j3d_read_plt(opj_j3d_t *j3d)
{
int len, i, Zplt, packet_len = 0, add; int len, i, Zplt, packet_len = 0, add;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1258,7 +1301,8 @@ static void j3d_read_plt(opj_j3d_t *j3d) {
} }
} }
static void j3d_read_ppm(opj_j3d_t *j3d) { static void j3d_read_ppm(opj_j3d_t *j3d)
{
int len, Z_ppm, i, j; int len, Z_ppm, i, j;
int N_ppm; int N_ppm;
@ -1299,7 +1343,8 @@ static void j3d_read_ppm(opj_j3d_t *j3d) {
} }
} }
static void j3d_read_ppt(opj_j3d_t *j3d) { static void j3d_read_ppt(opj_j3d_t *j3d)
{
int len, Z_ppt, i, j = 0; int len, Z_ppt, i, j = 0;
opj_cp_t *cp = j3d->cp; opj_cp_t *cp = j3d->cp;
@ -1327,7 +1372,8 @@ static void j3d_read_ppt(opj_j3d_t *j3d) {
tcp->ppt_store = j; tcp->ppt_store = j;
} }
static void j3d_write_sot(opj_j3d_t *j3d) { static void j3d_write_sot(opj_j3d_t *j3d)
{
int lenp, len; int lenp, len;
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
@ -1346,7 +1392,8 @@ static void j3d_write_sot(opj_j3d_t *j3d) {
cio_seek(cio, lenp + len); cio_seek(cio, lenp + len);
} }
static void j3d_read_sot(opj_j3d_t *j3d) { static void j3d_read_sot(opj_j3d_t *j3d)
{
int len, tileno, totlen, partno, numparts, i; int len, tileno, totlen, partno, numparts, i;
opj_tcp_t *tcp = NULL; opj_tcp_t *tcp = NULL;
char status = 0; char status = 0;
@ -1401,7 +1448,8 @@ static void j3d_read_sot(opj_j3d_t *j3d) {
} }
} }
static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder) { static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder)
{
int l, layno; int l, layno;
int totlen; int totlen;
opj_tcp_t *tcp = NULL; opj_tcp_t *tcp = NULL;
@ -1441,7 +1489,8 @@ static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder) {
cio_seek(cio, j3d->sot_start + totlen); cio_seek(cio, j3d->sot_start + totlen);
} }
static void j3d_read_sod(opj_j3d_t *j3d) { static void j3d_read_sod(opj_j3d_t *j3d)
{
int len, truncate = 0, i; int len, truncate = 0, i;
unsigned char *data = NULL, *data_ptr = NULL; unsigned char *data = NULL, *data_ptr = NULL;
@ -1476,7 +1525,8 @@ static void j3d_read_sod(opj_j3d_t *j3d) {
} }
} }
static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno) { static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno)
{
opj_cp_t *cp = j3d->cp; opj_cp_t *cp = j3d->cp;
opj_tcp_t *tcp = &cp->tcps[tileno]; opj_tcp_t *tcp = &cp->tcps[tileno];
@ -1490,7 +1540,8 @@ static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno) {
cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */ cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */
} }
static void j3d_read_rgn(opj_j3d_t *j3d) { static void j3d_read_rgn(opj_j3d_t *j3d)
{
int len, compno, roisty; int len, compno, roisty;
opj_cp_t *cp = j3d->cp; opj_cp_t *cp = j3d->cp;
@ -1504,13 +1555,15 @@ static void j3d_read_rgn(opj_j3d_t *j3d) {
tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */ tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */
} }
static void j3d_write_eoc(opj_j3d_t *j3d) { static void j3d_write_eoc(opj_j3d_t *j3d)
{
opj_cio_t *cio = j3d->cio; opj_cio_t *cio = j3d->cio;
/* opj_event_msg(j3d->cinfo, "%.8x: EOC\n", cio_tell(cio) + j3d->pos_correction); */ /* opj_event_msg(j3d->cinfo, "%.8x: EOC\n", cio_tell(cio) + j3d->pos_correction); */
cio_write(cio, J3D_MS_EOC, 2); cio_write(cio, J3D_MS_EOC, 2);
} }
static void j3d_read_eoc(opj_j3d_t *j3d) { static void j3d_read_eoc(opj_j3d_t *j3d)
{
int i, tileno; int i, tileno;
#ifndef NO_PACKETS_DECODING #ifndef NO_PACKETS_DECODING
@ -1538,7 +1591,8 @@ static void j3d_read_eoc(opj_j3d_t *j3d) {
j3d->state = J3D_STATE_MT; j3d->state = J3D_STATE_MT;
} }
static void j3d_read_unk(opj_j3d_t *j3d) { static void j3d_read_unk(opj_j3d_t *j3d)
{
opj_event_msg(j3d->cinfo, EVT_WARNING, "Unknown marker\n"); opj_event_msg(j3d->cinfo, EVT_WARNING, "Unknown marker\n");
} }
@ -1549,8 +1603,11 @@ static opj_atk_t atk_info_wt[] = {
{3, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-1}, {0,1,2}, {0,1,2}, {1,1,3}, {{-1.0},{1.0},{1.0,0.0,-1.0}}}, /* WT 2-6 REV*/ {3, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-1}, {0,1,2}, {0,1,2}, {1,1,3}, {{-1.0},{1.0},{1.0,0.0,-1.0}}}, /* WT 2-6 REV*/
{4, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-2}, {0,1,6}, {0,1,32}, {1,1,5}, {{-1},{1},{-3.0,22.0,0.0,-22.0,3.0}}}, /* WT 2-10 REV*/ {4, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-2}, {0,1,6}, {0,1,32}, {1,1,5}, {{-1},{1},{-3.0,22.0,0.0,-22.0,3.0}}}, /* WT 2-10 REV*/
{5, 1, J3D_ATK_ARB, J3D_ATK_IRR, 1, J3D_ATK_WS, 1, 7, {0}, {0}, {0}, {1,1,2,1,2,1,3},{{-1},{1.58613434206},{-0.460348209828, 0.460348209828},{0.25},{0.374213867768,-0.374213867768},{-1.33613434206},{0.29306717103,0,-0.29306717103}}}, /* WT 6-10 IRR*/ {5, 1, J3D_ATK_ARB, J3D_ATK_IRR, 1, J3D_ATK_WS, 1, 7, {0}, {0}, {0}, {1,1,2,1,2,1,3},{{-1},{1.58613434206},{-0.460348209828, 0.460348209828},{0.25},{0.374213867768,-0.374213867768},{-1.33613434206},{0.29306717103,0,-0.29306717103}}}, /* WT 6-10 IRR*/
{6, 1, J3D_ATK_ARB, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 11, {0}, {0}, {0}, {1,1,2,1,2,1,2,1,2,1,5},{{-1},{0,99715069105},{-1.00573127827, 1.00573127827},{-0.27040357631},{2.20509972343, -2.20509972343},{0.08059995736}, {
{-1.62682532350, 1.62682532350},{0.52040357631},{0.60404664250, -0.60404664250},{-0.82775064841},{-0.06615812964, 0.29402137720, 0, -0.29402137720, 0.06615812964}}}, /* WT 10-18 IRR*/ 6, 1, J3D_ATK_ARB, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 11, {0}, {0}, {0}, {1,1,2,1,2,1,2,1,2,1,5},{{-1},{0,99715069105},{-1.00573127827, 1.00573127827},{-0.27040357631},{2.20509972343, -2.20509972343},{0.08059995736},
{-1.62682532350, 1.62682532350},{0.52040357631},{0.60404664250, -0.60404664250},{-0.82775064841},{-0.06615812964, 0.29402137720, 0, -0.29402137720, 0.06615812964}
}
}, /* WT 10-18 IRR*/
{7, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 2, {0}, {0}, {0}, {1,1}, {-0.5, 0.25}}, /* WT 5-3 IRR*/ {7, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 2, {0}, {0}, {0}, {1,1}, {-0.5, 0.25}}, /* WT 5-3 IRR*/
{8, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {4,4}, {8,8}, {2,2}, {{-9,1},{5,-1}}} /* WT 13-7 REV*/ {8, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {4,4}, {8,8}, {2,2}, {{-9,1},{5,-1}}} /* WT 13-7 REV*/
}; };
@ -1606,7 +1663,8 @@ opj_dec_mstabent_t j3d_dec_mstab[] = {
Read the lookup table containing all the marker, status and action Read the lookup table containing all the marker, status and action
@param id Marker value @param id Marker value
*/ */
static opj_dec_mstabent_t *j3d_dec_mstab_lookup(int id) { static opj_dec_mstabent_t *j3d_dec_mstab_lookup(int id)
{
opj_dec_mstabent_t *e; opj_dec_mstabent_t *e;
for (e = j3d_dec_mstab; e->id != 0; e++) { for (e = j3d_dec_mstab; e->id != 0; e++) {
if (e->id == id) { if (e->id == id) {
@ -1620,7 +1678,8 @@ static opj_dec_mstabent_t *j3d_dec_mstab_lookup(int id) {
/* J3D / JPT decoder interface */ /* J3D / JPT decoder interface */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo) { opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo)
{
opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t)); opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t));
if(j3d) { if(j3d) {
j3d->cinfo = cinfo; j3d->cinfo = cinfo;
@ -1633,7 +1692,8 @@ opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo) {
return j3d; return j3d;
} }
void j3d_destroy_decompress(opj_j3d_t *j3d) { void j3d_destroy_decompress(opj_j3d_t *j3d)
{
int i = 0; int i = 0;
if(j3d->tile_len != NULL) { if(j3d->tile_len != NULL) {
@ -1681,7 +1741,8 @@ void j3d_destroy_decompress(opj_j3d_t *j3d) {
opj_free(j3d); opj_free(j3d);
} }
void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters) { void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters)
{
if(j3d && parameters) { if(j3d && parameters) {
/* create and initialize the coding parameters structure */ /* create and initialize the coding parameters structure */
opj_cp_t *cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t)); opj_cp_t *cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t));
@ -1701,7 +1762,8 @@ void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters) {
} }
} }
opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio) { opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio)
{
opj_volume_t *volume = NULL; opj_volume_t *volume = NULL;
opj_common_ptr cinfo = j3d->cinfo; opj_common_ptr cinfo = j3d->cinfo;
@ -1755,7 +1817,8 @@ opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio) {
/* J3D encoder interface */ /* J3D encoder interface */
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo) { opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo)
{
opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t)); opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t));
if(j3d) { if(j3d) {
j3d->cinfo = cinfo; j3d->cinfo = cinfo;
@ -1763,7 +1826,8 @@ opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo) {
return j3d; return j3d;
} }
void j3d_destroy_compress(opj_j3d_t *j3d) { void j3d_destroy_compress(opj_j3d_t *j3d)
{
int tileno; int tileno;
if(!j3d) return; if(!j3d) return;
@ -1800,7 +1864,8 @@ void j3d_destroy_compress(opj_j3d_t *j3d) {
opj_free(j3d); opj_free(j3d);
} }
void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume) { void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume)
{
int i, j, tileno, numpocs_tile; int i, j, tileno, numpocs_tile;
opj_cp_t *cp = NULL; opj_cp_t *cp = NULL;
@ -1987,7 +2052,8 @@ Create an index file
@param index Index filename @param index Index filename
@return Returns 1 if successful, returns 0 otherwise @return Returns 1 if successful, returns 0 otherwise
*/ */
static int j3d_create_index(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_info_t *volume_info, char *index) { static int j3d_create_index(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_info_t *volume_info, char *index)
{
int tileno, compno, layno, resno, precno, pack_nb, x, y, z; int tileno, compno, layno, resno, precno, pack_nb, x, y, z;
FILE *stream = NULL; FILE *stream = NULL;
@ -2224,7 +2290,8 @@ static int j3d_create_index(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_info_t *v
return 1; return 1;
} }
bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index) { bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index)
{
int tileno, compno; int tileno, compno;
opj_volume_info_t *volume_info = NULL; opj_volume_info_t *volume_info = NULL;
opj_cp_t *cp = NULL; opj_cp_t *cp = NULL;

View File

@ -38,7 +38,8 @@
#endif /* _WIN32 */ #endif /* _WIN32 */
#include "opj_includes.h" #include "opj_includes.h"
double opj_clock() { double opj_clock()
{
#ifdef _WIN32 #ifdef _WIN32
/* WIN32: use QueryPerformance (very accurate) */ /* WIN32: use QueryPerformance (very accurate) */
LARGE_INTEGER freq , t ; LARGE_INTEGER freq , t ;
@ -62,7 +63,8 @@ double opj_clock() {
#endif /* _WIN32 */ #endif /* _WIN32 */
} }
void* opj_malloc( size_t size ) { void* opj_malloc( size_t size )
{
void *memblock = malloc(size); void *memblock = malloc(size);
if(memblock) { if(memblock) {
memset(memblock, 0, size); memset(memblock, 0, size);
@ -70,11 +72,13 @@ void* opj_malloc( size_t size ) {
return memblock; return memblock;
} }
void* opj_realloc( void *memblock, size_t size ) { void* opj_realloc( void *memblock, size_t size )
{
return realloc(memblock, size); return realloc(memblock, size);
} }
void opj_free( void *memblock ) { void opj_free( void *memblock )
{
free(memblock); free(memblock);
} }

View File

@ -48,7 +48,8 @@ static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 };
/* <summary> */ /* <summary> */
/* Forward reversible MCT. */ /* Forward reversible MCT. */
/* </summary> */ /* </summary> */
void mct_encode(int *c0, int *c1, int *c2, int n) { void mct_encode(int *c0, int *c1, int *c2, int n)
{
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int r, g, b, y, u, v; int r, g, b, y, u, v;
@ -67,7 +68,8 @@ void mct_encode(int *c0, int *c1, int *c2, int n) {
/* <summary> */ /* <summary> */
/* Inverse reversible MCT. */ /* Inverse reversible MCT. */
/* </summary> */ /* </summary> */
void mct_decode(int *c0, int *c1, int *c2, int n) { void mct_decode(int *c0, int *c1, int *c2, int n)
{
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int y, u, v, r, g, b; int y, u, v, r, g, b;
@ -86,14 +88,16 @@ void mct_decode(int *c0, int *c1, int *c2, int n) {
/* <summary> */ /* <summary> */
/* Get norm of basis function of reversible MCT. */ /* Get norm of basis function of reversible MCT. */
/* </summary> */ /* </summary> */
double mct_getnorm(int compno) { double mct_getnorm(int compno)
{
return mct_norms[compno]; return mct_norms[compno];
} }
/* <summary> */ /* <summary> */
/* Forward irreversible MCT. */ /* Forward irreversible MCT. */
/* </summary> */ /* </summary> */
void mct_encode_real(int *c0, int *c1, int *c2, int n) { void mct_encode_real(int *c0, int *c1, int *c2, int n)
{
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int r, g, b, y, u, v; int r, g, b, y, u, v;
@ -112,7 +116,8 @@ void mct_encode_real(int *c0, int *c1, int *c2, int n) {
/* <summary> */ /* <summary> */
/* Inverse irreversible MCT. */ /* Inverse irreversible MCT. */
/* </summary> */ /* </summary> */
void mct_decode_real(int *c0, int *c1, int *c2, int n) { void mct_decode_real(int *c0, int *c1, int *c2, int n)
{
int i; int i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
int y, u, v, r, g, b; int y, u, v, r, g, b;
@ -131,6 +136,7 @@ void mct_decode_real(int *c0, int *c1, int *c2, int n) {
/* <summary> */ /* <summary> */
/* Get norm of basis function of irreversible MCT. */ /* Get norm of basis function of irreversible MCT. */
/* </summary> */ /* </summary> */
double mct_getnorm_real(int compno) { double mct_getnorm_real(int compno)
{
return mct_norms_real[compno]; return mct_norms_real[compno];
} }

View File

@ -200,7 +200,8 @@ static opj_mqc_state_t mqc_states[47 * 2] = {
========================================================== ==========================================================
*/ */
static void mqc_byteout(opj_mqc_t *mqc) { static void mqc_byteout(opj_mqc_t *mqc)
{
if (*mqc->bp == 0xff) { if (*mqc->bp == 0xff) {
mqc->bp++; mqc->bp++;
*mqc->bp = mqc->c >> 20; *mqc->bp = mqc->c >> 20;
@ -230,7 +231,8 @@ static void mqc_byteout(opj_mqc_t *mqc) {
} }
} }
static void mqc_renorme(opj_mqc_t *mqc) { static void mqc_renorme(opj_mqc_t *mqc)
{
do { do {
mqc->a <<= 1; mqc->a <<= 1;
mqc->c <<= 1; mqc->c <<= 1;
@ -241,7 +243,8 @@ static void mqc_renorme(opj_mqc_t *mqc) {
} while ((mqc->a & 0x8000) == 0); } while ((mqc->a & 0x8000) == 0);
} }
static void mqc_codemps(opj_mqc_t *mqc) { static void mqc_codemps(opj_mqc_t *mqc)
{
mqc->a -= (*mqc->curctx)->qeval; mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->a & 0x8000) == 0) { if ((mqc->a & 0x8000) == 0) {
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
@ -256,7 +259,8 @@ static void mqc_codemps(opj_mqc_t *mqc) {
} }
} }
static void mqc_codelps(opj_mqc_t *mqc) { static void mqc_codelps(opj_mqc_t *mqc)
{
mqc->a -= (*mqc->curctx)->qeval; mqc->a -= (*mqc->curctx)->qeval;
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
mqc->c += (*mqc->curctx)->qeval; mqc->c += (*mqc->curctx)->qeval;
@ -267,7 +271,8 @@ static void mqc_codelps(opj_mqc_t *mqc) {
mqc_renorme(mqc); mqc_renorme(mqc);
} }
static void mqc_setbits(opj_mqc_t *mqc) { static void mqc_setbits(opj_mqc_t *mqc)
{
unsigned int tempc = mqc->c + mqc->a; unsigned int tempc = mqc->c + mqc->a;
mqc->c |= 0xffff; mqc->c |= 0xffff;
if (mqc->c >= tempc) { if (mqc->c >= tempc) {
@ -275,7 +280,8 @@ static void mqc_setbits(opj_mqc_t *mqc) {
} }
} }
static int mqc_mpsexchange(opj_mqc_t *mqc) { static int mqc_mpsexchange(opj_mqc_t *mqc)
{
int d; int d;
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
d = 1 - (*mqc->curctx)->mps; d = 1 - (*mqc->curctx)->mps;
@ -288,7 +294,8 @@ static int mqc_mpsexchange(opj_mqc_t *mqc) {
return d; return d;
} }
static int mqc_lpsexchange(opj_mqc_t *mqc) { static int mqc_lpsexchange(opj_mqc_t *mqc)
{
int d; int d;
if (mqc->a < (*mqc->curctx)->qeval) { if (mqc->a < (*mqc->curctx)->qeval) {
mqc->a = (*mqc->curctx)->qeval; mqc->a = (*mqc->curctx)->qeval;
@ -303,7 +310,8 @@ static int mqc_lpsexchange(opj_mqc_t *mqc) {
return d; return d;
} }
static void mqc_bytein(opj_mqc_t *mqc) { static void mqc_bytein(opj_mqc_t *mqc)
{
if (mqc->bp != mqc->end) { if (mqc->bp != mqc->end) {
unsigned int c; unsigned int c;
if (mqc->bp + 1 != mqc->end) { if (mqc->bp + 1 != mqc->end) {
@ -331,7 +339,8 @@ static void mqc_bytein(opj_mqc_t *mqc) {
} }
} }
static void mqc_renormd(opj_mqc_t *mqc) { static void mqc_renormd(opj_mqc_t *mqc)
{
do { do {
if (mqc->ct == 0) { if (mqc->ct == 0) {
mqc_bytein(mqc); mqc_bytein(mqc);
@ -348,22 +357,26 @@ static void mqc_renormd(opj_mqc_t *mqc) {
========================================================== ==========================================================
*/ */
opj_mqc_t* mqc_create() { opj_mqc_t* mqc_create()
{
opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t));
return mqc; return mqc;
} }
void mqc_destroy(opj_mqc_t *mqc) { void mqc_destroy(opj_mqc_t *mqc)
{
if(mqc) { if(mqc) {
opj_free(mqc); opj_free(mqc);
} }
} }
int mqc_numbytes(opj_mqc_t *mqc) { int mqc_numbytes(opj_mqc_t *mqc)
{
return mqc->bp - mqc->start; return mqc->bp - mqc->start;
} }
void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) { void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp)
{
mqc_setcurctx(mqc, 0); mqc_setcurctx(mqc, 0);
mqc->a = 0x8000; mqc->a = 0x8000;
mqc->c = 0; mqc->c = 0;
@ -375,11 +388,13 @@ void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) {
mqc->start = bp; mqc->start = bp;
} }
void mqc_setcurctx(opj_mqc_t *mqc, int ctxno) { void mqc_setcurctx(opj_mqc_t *mqc, int ctxno)
{
mqc->curctx = &mqc->ctxs[ctxno]; mqc->curctx = &mqc->ctxs[ctxno];
} }
void mqc_encode(opj_mqc_t *mqc, int d) { void mqc_encode(opj_mqc_t *mqc, int d)
{
if ((*mqc->curctx)->mps == d) { if ((*mqc->curctx)->mps == d) {
mqc_codemps(mqc); mqc_codemps(mqc);
} else { } else {
@ -387,7 +402,8 @@ void mqc_encode(opj_mqc_t *mqc, int d) {
} }
} }
void mqc_flush(opj_mqc_t *mqc) { void mqc_flush(opj_mqc_t *mqc)
{
mqc_setbits(mqc); mqc_setbits(mqc);
mqc->c <<= mqc->ct; mqc->c <<= mqc->ct;
mqc_byteout(mqc); mqc_byteout(mqc);
@ -399,7 +415,8 @@ void mqc_flush(opj_mqc_t *mqc) {
} }
} }
void mqc_bypass_init_enc(opj_mqc_t *mqc) { void mqc_bypass_init_enc(opj_mqc_t *mqc)
{
mqc->c = 0; mqc->c = 0;
mqc->ct = 8; mqc->ct = 8;
/*if (*mqc->bp == 0xff) { /*if (*mqc->bp == 0xff) {
@ -407,7 +424,8 @@ void mqc_bypass_init_enc(opj_mqc_t *mqc) {
} */ } */
} }
void mqc_bypass_enc(opj_mqc_t *mqc, int d) { void mqc_bypass_enc(opj_mqc_t *mqc, int d)
{
mqc->ct--; mqc->ct--;
mqc->c = mqc->c + (d << mqc->ct); mqc->c = mqc->c + (d << mqc->ct);
if (mqc->ct == 0) { if (mqc->ct == 0) {
@ -421,7 +439,8 @@ void mqc_bypass_enc(opj_mqc_t *mqc, int d) {
} }
} }
int mqc_bypass_flush_enc(opj_mqc_t *mqc) { int mqc_bypass_flush_enc(opj_mqc_t *mqc)
{
unsigned char bit_padding; unsigned char bit_padding;
bit_padding = 0; bit_padding = 0;
@ -441,21 +460,24 @@ int mqc_bypass_flush_enc(opj_mqc_t *mqc) {
return 1; return 1;
} }
void mqc_reset_enc(opj_mqc_t *mqc) { void mqc_reset_enc(opj_mqc_t *mqc)
{
mqc_resetstates(mqc); mqc_resetstates(mqc);
mqc_setstate(mqc, 18, 0, 46); mqc_setstate(mqc, 18, 0, 46);
mqc_setstate(mqc, 0, 0, 3); mqc_setstate(mqc, 0, 0, 3);
mqc_setstate(mqc, 1, 0, 4); mqc_setstate(mqc, 1, 0, 4);
} }
void mqc_reset_enc_3(opj_mqc_t *mqc) { void mqc_reset_enc_3(opj_mqc_t *mqc)
{
mqc_resetstates(mqc); mqc_resetstates(mqc);
mqc_setstate(mqc, T1_3D_CTXNO_UNI, 0, 46); mqc_setstate(mqc, T1_3D_CTXNO_UNI, 0, 46);
mqc_setstate(mqc, T1_3D_CTXNO_AGG, 0, 3); mqc_setstate(mqc, T1_3D_CTXNO_AGG, 0, 3);
mqc_setstate(mqc, T1_3D_CTXNO_ZC, 0, 4); mqc_setstate(mqc, T1_3D_CTXNO_ZC, 0, 4);
} }
int mqc_restart_enc(opj_mqc_t *mqc) { int mqc_restart_enc(opj_mqc_t *mqc)
{
int correction = 1; int correction = 1;
/* <flush part> */ /* <flush part> */
@ -471,7 +493,8 @@ int mqc_restart_enc(opj_mqc_t *mqc) {
return correction; return correction;
} }
void mqc_restart_init_enc(opj_mqc_t *mqc) { void mqc_restart_init_enc(opj_mqc_t *mqc)
{
/* <Re-init part> */ /* <Re-init part> */
mqc_setcurctx(mqc, 0); mqc_setcurctx(mqc, 0);
mqc->a = 0x8000; mqc->a = 0x8000;
@ -483,7 +506,8 @@ void mqc_restart_init_enc(opj_mqc_t *mqc) {
} }
} }
void mqc_erterm_enc(opj_mqc_t *mqc) { void mqc_erterm_enc(opj_mqc_t *mqc)
{
int k = 11 - mqc->ct + 1; int k = 11 - mqc->ct + 1;
while (k > 0) { while (k > 0) {
@ -498,7 +522,8 @@ void mqc_erterm_enc(opj_mqc_t *mqc) {
} }
} }
void mqc_segmark_enc(opj_mqc_t *mqc) { void mqc_segmark_enc(opj_mqc_t *mqc)
{
int i; int i;
mqc_setcurctx(mqc, 18); mqc_setcurctx(mqc, 18);
@ -507,7 +532,8 @@ void mqc_segmark_enc(opj_mqc_t *mqc) {
} }
} }
void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) { void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len)
{
mqc_setcurctx(mqc, 0); mqc_setcurctx(mqc, 0);
mqc->start = bp; mqc->start = bp;
mqc->end = bp + len; mqc->end = bp + len;
@ -520,7 +546,8 @@ void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) {
mqc->a = 0x8000; mqc->a = 0x8000;
} }
int mqc_decode(opj_mqc_t *mqc) { int mqc_decode(opj_mqc_t *mqc)
{
int d; int d;
mqc->a -= (*mqc->curctx)->qeval; mqc->a -= (*mqc->curctx)->qeval;
if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { if ((mqc->c >> 16) < (*mqc->curctx)->qeval) {
@ -539,14 +566,16 @@ int mqc_decode(opj_mqc_t *mqc) {
return d; return d;
} }
void mqc_resetstates(opj_mqc_t *mqc) { void mqc_resetstates(opj_mqc_t *mqc)
{
int i; int i;
for (i = 0; i < MQC_NUMCTXS; i++) { for (i = 0; i < MQC_NUMCTXS; i++) {
mqc->ctxs[i] = mqc_states; mqc->ctxs[i] = mqc_states;
} }
} }
void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) { void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob)
{
mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)]; mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)];
} }

View File

@ -41,7 +41,8 @@
#ifdef _WIN32 #ifdef _WIN32
#ifndef OPJ_STATIC #ifndef OPJ_STATIC
BOOL APIENTRY BOOL APIENTRY
DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call) { switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH : case DLL_PROCESS_ATTACH :
break; break;
@ -59,10 +60,12 @@ DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
const char* OPJ_CALLCONV opj_version() { const char* OPJ_CALLCONV opj_version()
{
return JP3D_VERSION; return JP3D_VERSION;
} }
opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format)
{
opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t)); opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t));
if(!dinfo) return NULL; if(!dinfo) return NULL;
dinfo->is_decompressor = true; dinfo->is_decompressor = true;
@ -86,7 +89,8 @@ opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
return dinfo; return dinfo;
} }
void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) { void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo)
{
if(dinfo) { if(dinfo) {
/* destroy the codec */ /* destroy the codec */
if(dinfo->codec_format != CODEC_UNKNOWN) { if(dinfo->codec_format != CODEC_UNKNOWN) {
@ -97,7 +101,8 @@ void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) {
} }
} }
void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) { void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters)
{
if(parameters) { if(parameters) {
memset(parameters, 0, sizeof(opj_dparameters_t)); memset(parameters, 0, sizeof(opj_dparameters_t));
/* default decoding parameters */ /* default decoding parameters */
@ -112,7 +117,8 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *paramete
} }
} }
void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) { void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters)
{
if(dinfo && parameters) { if(dinfo && parameters) {
if (dinfo->codec_format != CODEC_UNKNOWN) { if (dinfo->codec_format != CODEC_UNKNOWN) {
j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters); j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters);
@ -120,7 +126,8 @@ void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *param
} }
} }
opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio)
{
if(dinfo && cio) { if(dinfo && cio) {
if (dinfo->codec_format != CODEC_UNKNOWN) { if (dinfo->codec_format != CODEC_UNKNOWN) {
return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio); return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio);
@ -130,7 +137,8 @@ opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
return NULL; return NULL;
} }
opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) { opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format)
{
opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t)); opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t));
if(!cinfo) return NULL; if(!cinfo) return NULL;
cinfo->is_decompressor = false; cinfo->is_decompressor = false;
@ -154,7 +162,8 @@ opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) {
return cinfo; return cinfo;
} }
void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) { void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo)
{
if(cinfo) { if(cinfo) {
/* destroy the codec */ /* destroy the codec */
if (cinfo->codec_format != CODEC_UNKNOWN) { if (cinfo->codec_format != CODEC_UNKNOWN) {
@ -165,7 +174,8 @@ void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) {
} }
} }
void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) { void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters)
{
if(parameters) { if(parameters) {
memset(parameters, 0, sizeof(opj_cparameters_t)); memset(parameters, 0, sizeof(opj_cparameters_t));
/* default coding parameters */ /* default coding parameters */
@ -192,7 +202,8 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
} }
} }
void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) { void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume)
{
if(cinfo && parameters && volume) { if(cinfo && parameters && volume) {
if (cinfo->codec_format != CODEC_UNKNOWN) { if (cinfo->codec_format != CODEC_UNKNOWN) {
j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume); j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume);
@ -200,7 +211,8 @@ void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *param
} }
} }
bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) { bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index)
{
if(cinfo && cio && volume) { if(cinfo && cio && volume) {
if (cinfo->codec_format != CODEC_UNKNOWN) { if (cinfo->codec_format != CODEC_UNKNOWN) {
return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index); return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index);

View File

@ -83,7 +83,8 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi);
========================================================== ==========================================================
*/ */
static bool pi_next_lrcp(opj_pi_iterator_t * pi) { static bool pi_next_lrcp(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
long index = 0; long index = 0;
@ -114,7 +115,8 @@ static bool pi_next_lrcp(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return true; return true;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
@ -124,7 +126,8 @@ LABEL_SKIP:;
return false; return false;
} }
static bool pi_next_rlcp(opj_pi_iterator_t * pi) { static bool pi_next_rlcp(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
long index = 0; long index = 0;
@ -152,7 +155,8 @@ static bool pi_next_rlcp(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return true; return true;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -161,7 +165,8 @@ LABEL_SKIP:;
return false; return false;
} }
static bool pi_next_rpcl(opj_pi_iterator_t * pi) { static bool pi_next_rpcl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
long index = 0; long index = 0;
@ -241,7 +246,8 @@ static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return true; return true;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -252,7 +258,8 @@ static bool pi_next_rpcl(opj_pi_iterator_t * pi) {
return false; return false;
} }
static bool pi_next_pcrl(opj_pi_iterator_t * pi) { static bool pi_next_pcrl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
long index = 0; long index = 0;
@ -335,7 +342,8 @@ for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) {
pi->include[index] = 1; pi->include[index] = 1;
return true; return true;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -346,7 +354,8 @@ LABEL_SKIP:;
return false; return false;
} }
static bool pi_next_cprl(opj_pi_iterator_t * pi) { static bool pi_next_cprl(opj_pi_iterator_t * pi)
{
opj_pi_comp_t *comp = NULL; opj_pi_comp_t *comp = NULL;
opj_pi_resolution_t *res = NULL; opj_pi_resolution_t *res = NULL;
long index = 0; long index = 0;
@ -426,7 +435,8 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) {
pi->include[index] = 1; pi->include[index] = 1;
return true; return true;
} }
LABEL_SKIP:; LABEL_SKIP:
;
} }
} }
} }
@ -443,7 +453,8 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) {
========================================================== ==========================================================
*/ */
opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno) { opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno)
{
int p, q, r; int p, q, r;
int compno, resno, pino; int compno, resno, pino;
opj_pi_iterator_t *pi = NULL; opj_pi_iterator_t *pi = NULL;
@ -570,8 +581,7 @@ opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno) {
pi_destroy(pi, cp, tileno); pi_destroy(pi, cp, tileno);
return NULL; return NULL;
} }
} } else {
else {
pi[pino].include = pi[pino - 1].include; pi[pino].include = pi[pino - 1].include;
} }
@ -597,7 +607,8 @@ opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno) {
return pi; return pi;
} }
void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) { void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno)
{
int compno, pino; int compno, pino;
opj_tcp_t *tcp = &cp->tcps[tileno]; opj_tcp_t *tcp = &cp->tcps[tileno];
if(pi) { if(pi) {
@ -619,7 +630,8 @@ void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) {
} }
} }
bool pi_next(opj_pi_iterator_t * pi) { bool pi_next(opj_pi_iterator_t * pi)
{
switch (pi->poc.prg) { switch (pi->poc.prg) {
case LRCP: case LRCP:
return pi_next_lrcp(pi); return pi_next_lrcp(pi);

View File

@ -46,22 +46,26 @@
========================================================== ==========================================================
*/ */
opj_raw_t* raw_create() { opj_raw_t* raw_create()
{
opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t));
return raw; return raw;
} }
void raw_destroy(opj_raw_t *raw) { void raw_destroy(opj_raw_t *raw)
{
if(raw) { if(raw) {
opj_free(raw); opj_free(raw);
} }
} }
int raw_numbytes(opj_raw_t *raw) { int raw_numbytes(opj_raw_t *raw)
{
return raw->bp - raw->start; return raw->bp - raw->start;
} }
void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) { void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len)
{
raw->start = bp; raw->start = bp;
raw->lenmax = len; raw->lenmax = len;
raw->len = 0; raw->len = 0;
@ -69,7 +73,8 @@ void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) {
raw->ct = 0; raw->ct = 0;
} }
int raw_decode(opj_raw_t *raw) { int raw_decode(opj_raw_t *raw)
{
int d; int d;
if (raw->ct == 0) { if (raw->ct == 0) {
raw->ct = 8; raw->ct = 8;

View File

@ -136,23 +136,28 @@ static void t1_init_luts(opj_t1_t *t1);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int t1_getctxno_zc(opj_t1_t *t1, int f, int orient) { static int t1_getctxno_zc(opj_t1_t *t1, int f, int orient)
{
return t1->lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; return t1->lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)];
} }
static int t1_getctxno_sc(opj_t1_t *t1, int f) { static int t1_getctxno_sc(opj_t1_t *t1, int f)
{
return t1->lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; return t1->lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
} }
static int t1_getctxno_mag(opj_t1_t *t1, int f) { static int t1_getctxno_mag(opj_t1_t *t1, int f)
{
return t1->lut_ctxno_mag[(f & T1_SIG_OTH) | (((f & T1_REFINE) != 0) << 11)]; return t1->lut_ctxno_mag[(f & T1_SIG_OTH) | (((f & T1_REFINE) != 0) << 11)];
} }
static int t1_getspb(opj_t1_t *t1, int f) { static int t1_getspb(opj_t1_t *t1, int f)
{
return t1->lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; return t1->lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4];
} }
static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos) { static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos)
{
if (bitpos > T1_NMSEDEC_FRACBITS) { if (bitpos > T1_NMSEDEC_FRACBITS) {
return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
@ -160,7 +165,8 @@ static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos) {
return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos) { static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos)
{
if (bitpos > T1_NMSEDEC_FRACBITS) { if (bitpos > T1_NMSEDEC_FRACBITS) {
return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
@ -168,7 +174,8 @@ static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos) {
return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
static void t1_updateflags(int *fp, int s) { static void t1_updateflags(int *fp, int s)
{
int *np = fp - (T1_MAXCBLKW + 2); int *np = fp - (T1_MAXCBLKW + 2);
int *sp = fp + (T1_MAXCBLKW + 2); int *sp = fp + (T1_MAXCBLKW + 2);
np[-1] |= T1_SIG_SE; np[-1] |= T1_SIG_SE;
@ -187,7 +194,8 @@ static void t1_updateflags(int *fp, int s) {
} }
} }
static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc) { static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc)
{
int v, flag; int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -219,7 +227,8 @@ static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int
} }
} }
static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, char type, int vsc) { static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, char type, int vsc)
{
int v, flag; int v, flag;
opj_raw_t *raw = t1->raw; /* RAW component */ opj_raw_t *raw = t1->raw; /* RAW component */
@ -248,7 +257,8 @@ static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty)
{
int i, j, k, m, one, vsc; int i, j, k, m, one, vsc;
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
@ -264,7 +274,8 @@ static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
} }
} }
static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty)
{
int i, j, k, m, one, half, oneplushalf, vsc; int i, j, k, m, one, half, oneplushalf, vsc;
one = 1 << bpno; one = 1 << bpno;
half = one >> 1; half = one >> 1;
@ -281,7 +292,8 @@ static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc) { static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc)
{
int v, flag; int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -301,7 +313,8 @@ static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int on
} }
} }
static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int neghalf, char type, int vsc) { static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int neghalf, char type, int vsc)
{
int v, t, flag; int v, t, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -322,7 +335,8 @@ static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty)
{
int i, j, k, m, one, vsc; int i, j, k, m, one, vsc;
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
@ -338,7 +352,8 @@ static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nms
} }
} }
static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty)
{
int i, j, k, m, one, poshalf, neghalf; int i, j, k, m, one, poshalf, neghalf;
int vsc; int vsc;
one = 1 << bpno; one = 1 << bpno;
@ -356,7 +371,8 @@ static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char typ
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc) { static void t1_enc_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc)
{
int v, flag; int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -382,7 +398,8 @@ LABEL_PARTIAL:
*fp &= ~T1_VISIT; *fp &= ~T1_VISIT;
} }
static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc) { static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc)
{
int v, flag; int v, flag;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -405,7 +422,8 @@ LABEL_PARTIAL:
*fp &= ~T1_VISIT; *fp &= ~T1_VISIT;
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty)
{
int i, j, k, m, one, agg, runlen, vsc; int i, j, k, m, one, agg, runlen, vsc;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -456,7 +474,8 @@ static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
} }
} }
static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty)
{
int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc;
int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM;
@ -518,7 +537,8 @@ static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orie
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile)
{
int i, j, k; int i, j, k;
int w, h, l; int w, h, l;
int passno; int passno;
@ -645,7 +665,8 @@ static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
cblk->totalpasses = passno; cblk->totalpasses = passno;
} }
static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty)
{
int i, j, k, w, h, l; int i, j, k, w, h, l;
int bpno, passtype; int bpno, passtype;
int segno, passno; int segno, passno;
@ -714,7 +735,8 @@ static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int
} }
} }
static int t1_init_ctxno_zc(int f, int orient) { static int t1_init_ctxno_zc(int f, int orient)
{
int h, v, d, n, t, hv; int h, v, d, n, t, hv;
n = 0; n = 0;
h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0); h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0);
@ -786,7 +808,8 @@ static int t1_init_ctxno_zc(int f, int orient) {
return (T1_CTXNO_ZC + n); return (T1_CTXNO_ZC + n);
} }
static int t1_init_ctxno_sc(int f) { static int t1_init_ctxno_sc(int f)
{
int hc, vc, n; int hc, vc, n;
n = 0; n = 0;
@ -827,7 +850,8 @@ static int t1_init_ctxno_sc(int f) {
return (T1_CTXNO_SC + n); return (T1_CTXNO_SC + n);
} }
static int t1_init_ctxno_mag(int f) { static int t1_init_ctxno_mag(int f)
{
int n; int n;
if (!(f & T1_REFINE)) if (!(f & T1_REFINE))
n = (f & (T1_SIG_OTH)) ? 1 : 0; n = (f & (T1_SIG_OTH)) ? 1 : 0;
@ -837,7 +861,8 @@ static int t1_init_ctxno_mag(int f) {
return (T1_CTXNO_MAG + n); return (T1_CTXNO_MAG + n);
} }
static int t1_init_spb(int f) { static int t1_init_spb(int f)
{
int hc, vc, n; int hc, vc, n;
hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) ==
@ -862,7 +887,8 @@ static int t1_init_spb(int f) {
return n; return n;
} }
static void t1_init_luts(opj_t1_t *t1) { static void t1_init_luts(opj_t1_t *t1)
{
int i, j; int i, j;
double u, v, t; double u, v, t;
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
@ -910,7 +936,8 @@ static void t1_init_luts(opj_t1_t *t1) {
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_t1_t* t1_create(opj_common_ptr cinfo) { opj_t1_t* t1_create(opj_common_ptr cinfo)
{
opj_t1_t *t1 = (opj_t1_t*)opj_malloc(sizeof(opj_t1_t)); opj_t1_t *t1 = (opj_t1_t*)opj_malloc(sizeof(opj_t1_t));
if(t1) { if(t1) {
t1->cinfo = cinfo; t1->cinfo = cinfo;
@ -923,7 +950,8 @@ opj_t1_t* t1_create(opj_common_ptr cinfo) {
return t1; return t1;
} }
void t1_destroy(opj_t1_t *t1) { void t1_destroy(opj_t1_t *t1)
{
if(t1) { if(t1) {
/* destroy MQC and RAW handles */ /* destroy MQC and RAW handles */
mqc_destroy(t1->mqc); mqc_destroy(t1->mqc);
@ -934,7 +962,8 @@ void t1_destroy(opj_t1_t *t1) {
} }
} }
void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp)
{
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
int x, y, z, i, j, k, orient; int x, y, z, i, j, k, orient;
int n=0; int n=0;
@ -1048,7 +1077,8 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
} /* compno */ } /* compno */
} }
void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp)
{
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
@ -1167,7 +1197,8 @@ void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
/** mod fixed_quality */ /** mod fixed_quality */
double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]) { double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3])
{
double w1, w2, wmsedec; double w1, w2, wmsedec;
if (dwtid[0] == 1 || dwtid[1] == 1 || dwtid[2] == 1) { if (dwtid[0] == 1 || dwtid[1] == 1 || dwtid[2] == 1) {

View File

@ -126,25 +126,30 @@ static void t1_3d_init_luts(opj_t1_3d_t *t1);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int t1_3d_getctxno_zc(unsigned int f, int orient) { static int t1_3d_getctxno_zc(unsigned int f, int orient)
{
return t1_3d_init_ctxno_zc((f & T1_3D_SIG_OTH), orient); return t1_3d_init_ctxno_zc((f & T1_3D_SIG_OTH), orient);
} }
static int t1_3d_getctxno_sc(unsigned int f) { static int t1_3d_getctxno_sc(unsigned int f)
{
return t1_3d_init_ctxno_sc((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)); return t1_3d_init_ctxno_sc((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN));
/*return t1->lut_ctxno_sc[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/ /*return t1->lut_ctxno_sc[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/
} }
static int t1_3d_getctxno_mag(unsigned int f, int fsvr) { static int t1_3d_getctxno_mag(unsigned int f, int fsvr)
{
return t1_3d_init_ctxno_mag((f & T1_3D_SIG_OTH), fsvr); return t1_3d_init_ctxno_mag((f & T1_3D_SIG_OTH), fsvr);
} }
static int t1_3d_getspb(unsigned int f) { static int t1_3d_getspb(unsigned int f)
{
return t1_3d_init_spb((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)); return t1_3d_init_spb((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN));
/*return t1->lut_spb[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/ /*return t1->lut_spb[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/
} }
static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos) { static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos)
{
if (bitpos > T1_NMSEDEC_FRACBITS) { if (bitpos > T1_NMSEDEC_FRACBITS) {
return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
@ -152,7 +157,8 @@ static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos) {
return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos) { static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos)
{
if (bitpos > T1_NMSEDEC_FRACBITS) { if (bitpos > T1_NMSEDEC_FRACBITS) {
return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
@ -160,7 +166,8 @@ static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos) {
return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)];
} }
static void t1_3d_updateflags(unsigned int *fp, int s) { static void t1_3d_updateflags(unsigned int *fp, int s)
{
unsigned int *np = fp - (T1_MAXCBLKW + 2); unsigned int *np = fp - (T1_MAXCBLKW + 2);
unsigned int *sp = fp + (T1_MAXCBLKW + 2); unsigned int *sp = fp + (T1_MAXCBLKW + 2);
@ -212,7 +219,8 @@ static void t1_3d_updateflags(unsigned int *fp, int s) {
} }
} }
static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc) { static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc)
{
int v, flagsvr; int v, flagsvr;
unsigned int flag; unsigned int flag;
@ -246,7 +254,8 @@ static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr,
} }
} }
static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, char type, int vsc) { static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, char type, int vsc)
{
int v, flagsvr; int v, flagsvr;
unsigned int flag; unsigned int flag;
@ -277,7 +286,8 @@ static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr,
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty)
{
int i, j, k, m, one, vsc; int i, j, k, m, one, vsc;
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
@ -293,7 +303,8 @@ static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, in
} }
} }
static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty)
{
int i, j, k, m, one, half, oneplushalf, vsc; int i, j, k, m, one, half, oneplushalf, vsc;
one = 1 << bpno; one = 1 << bpno;
half = one >> 1; half = one >> 1;
@ -310,7 +321,8 @@ static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, in
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int bpno, int one, int *nmsedec, char type, int vsc) { static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int bpno, int one, int *nmsedec, char type, int vsc)
{
int v, flagsvr; int v, flagsvr;
unsigned int flag; unsigned int flag;
@ -332,7 +344,8 @@ static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr,
} }
} }
static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int poshalf, int neghalf, char type, int vsc) { static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int poshalf, int neghalf, char type, int vsc)
{
int v, t, flagsvr; int v, t, flagsvr;
unsigned int flag; unsigned int flag;
@ -355,7 +368,8 @@ static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr,
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty)
{
int i, j, k, m, one, vsc; int i, j, k, m, one, vsc;
*nmsedec = 0; *nmsedec = 0;
one = 1 << (bpno + T1_NMSEDEC_FRACBITS); one = 1 << (bpno + T1_NMSEDEC_FRACBITS);
@ -371,7 +385,8 @@ static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, in
} }
} }
static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, char type, int cblksty)
{
int i, j, k, m, one, poshalf, neghalf; int i, j, k, m, one, poshalf, neghalf;
int vsc; int vsc;
one = 1 << bpno; one = 1 << bpno;
@ -389,7 +404,8 @@ static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, ch
} }
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_3d_enc_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc) { static void t1_3d_enc_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc)
{
int v, flagsvr; int v, flagsvr;
unsigned int flag; unsigned int flag;
@ -417,7 +433,8 @@ LABEL_PARTIAL:
*fsvr &= ~T1_3D_VISIT; *fsvr &= ~T1_3D_VISIT;
} }
static void t1_3d_dec_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, int partial, int vsc) { static void t1_3d_dec_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, int partial, int vsc)
{
int v, flagsvr; int v, flagsvr;
unsigned int flag; unsigned int flag;
@ -442,7 +459,8 @@ LABEL_PARTIAL:
*fsvr &= ~T1_3D_VISIT; *fsvr &= ~T1_3D_VISIT;
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty)
{
int i, j, k, m, one, agg, runlen, vsc; int i, j, k, m, one, agg, runlen, vsc;
opj_mqc_t *mqc = t1->mqc; /* MQC component */ opj_mqc_t *mqc = t1->mqc; /* MQC component */
@ -495,7 +513,8 @@ static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, in
} }
} }
static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int cblksty)
{
int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc;
int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM;
@ -560,7 +579,8 @@ static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, in
} /* VSC and BYPASS by Antonin */ } /* VSC and BYPASS by Antonin */
static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile)
{
int i, j, k; int i, j, k;
int w, h, l; int w, h, l;
int passno; int passno;
@ -685,7 +705,8 @@ static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient
cblk->totalpasses = passno; cblk->totalpasses = passno;
} }
static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty)
{
int i, j, k; int i, j, k;
int w, h, l; int w, h, l;
int bpno, passtype; int bpno, passtype;
@ -757,7 +778,8 @@ static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient
} }
} }
static int t1_3d_init_ctxno_zc(unsigned int f, int orient) { static int t1_3d_init_ctxno_zc(unsigned int f, int orient)
{
unsigned int h, v, c; unsigned int h, v, c;
unsigned int d2xy, d2xz, d2yz, d3; unsigned int d2xy, d2xz, d2yz, d3;
int n; int n;
@ -868,7 +890,8 @@ static int t1_3d_init_ctxno_zc(unsigned int f, int orient) {
return (T1_3D_CTXNO_ZC + n); return (T1_3D_CTXNO_ZC + n);
} }
static int t1_3d_init_ctxno_sc(unsigned int f) { static int t1_3d_init_ctxno_sc(unsigned int f)
{
int hc, vc, cc; int hc, vc, cc;
int n = 0; int n = 0;
@ -918,7 +941,8 @@ static int t1_3d_init_ctxno_sc(unsigned int f) {
return (T1_3D_CTXNO_SC + n); return (T1_3D_CTXNO_SC + n);
} }
static int t1_3d_init_ctxno_mag(unsigned int f, int f2) { static int t1_3d_init_ctxno_mag(unsigned int f, int f2)
{
int n; int n;
if (!(f2 & T1_3D_REFINE)) /*First refinement for this coefficient (no previous refinement)*/ if (!(f2 & T1_3D_REFINE)) /*First refinement for this coefficient (no previous refinement)*/
n = (f & (T1_3D_SIG_PRIM)) ? 1 : 0; n = (f & (T1_3D_SIG_PRIM)) ? 1 : 0;
@ -928,7 +952,8 @@ static int t1_3d_init_ctxno_mag(unsigned int f, int f2) {
return (T1_3D_CTXNO_MAG + n); return (T1_3D_CTXNO_MAG + n);
} }
static int t1_3d_init_spb(unsigned int f) { static int t1_3d_init_spb(unsigned int f)
{
int hc, vc, cc; int hc, vc, cc;
int n = 0; int n = 0;
@ -952,7 +977,8 @@ static int t1_3d_init_spb(unsigned int f) {
return n; return n;
} }
static void t1_3d_init_luts(opj_t1_3d_t *t1) { static void t1_3d_init_luts(opj_t1_3d_t *t1)
{
int i; int i;
double u, v, t; double u, v, t;
/*for (j = 0; j < 4; j++) { /*for (j = 0; j < 4; j++) {
@ -999,7 +1025,8 @@ static void t1_3d_init_luts(opj_t1_3d_t *t1) {
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo) { opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo)
{
opj_t1_3d_t *t1 = (opj_t1_3d_t*)opj_malloc(sizeof(opj_t1_3d_t)); opj_t1_3d_t *t1 = (opj_t1_3d_t*)opj_malloc(sizeof(opj_t1_3d_t));
if(t1) { if(t1) {
t1->cinfo = cinfo; t1->cinfo = cinfo;
@ -1012,7 +1039,8 @@ opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo) {
return t1; return t1;
} }
void t1_3d_destroy(opj_t1_3d_t *t1) { void t1_3d_destroy(opj_t1_3d_t *t1)
{
if(t1) { if(t1) {
/* destroy MQC and RAW handles */ /* destroy MQC and RAW handles */
mqc_destroy(t1->mqc); mqc_destroy(t1->mqc);
@ -1021,7 +1049,8 @@ void t1_3d_destroy(opj_t1_3d_t *t1) {
} }
} }
void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp)
{
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
int x, y, z, i, j, k, orient; int x, y, z, i, j, k, orient;
int level[3]; int level[3];
@ -1116,7 +1145,8 @@ void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
} /* compno */ } /* compno */
} }
void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp)
{
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {

View File

@ -89,14 +89,16 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/* #define RESTART 0x04 */ /* #define RESTART 0x04 */
static void t2_putcommacode(opj_bio_t *bio, int n) { static void t2_putcommacode(opj_bio_t *bio, int n)
{
while (--n >= 0) { while (--n >= 0) {
bio_write(bio, 1, 1); bio_write(bio, 1, 1);
} }
bio_write(bio, 0, 1); bio_write(bio, 0, 1);
} }
static int t2_getcommacode(opj_bio_t *bio) { static int t2_getcommacode(opj_bio_t *bio)
{
int n; int n;
for (n = 0; bio_read(bio, 1); n++) { for (n = 0; bio_read(bio, 1); n++) {
; ;
@ -104,7 +106,8 @@ static int t2_getcommacode(opj_bio_t *bio) {
return n; return n;
} }
static void t2_putnumpasses(opj_bio_t *bio, int n) { static void t2_putnumpasses(opj_bio_t *bio, int n)
{
if (n == 1) { if (n == 1) {
bio_write(bio, 0, 1); bio_write(bio, 0, 1);
} else if (n == 2) { } else if (n == 2) {
@ -118,7 +121,8 @@ static void t2_putnumpasses(opj_bio_t *bio, int n) {
} }
} }
static int t2_getnumpasses(opj_bio_t *bio) { static int t2_getnumpasses(opj_bio_t *bio)
{
int n; int n;
if (!bio_read(bio, 1)) if (!bio_read(bio, 1))
return 1; return 1;
@ -131,7 +135,8 @@ static int t2_getnumpasses(opj_bio_t *bio) {
return (37 + bio_read(bio, 7)); return (37 + bio_read(bio, 7));
} }
static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t * volume_info, int tileno, opj_cp_t *cp) { static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t * volume_info, int tileno, opj_cp_t *cp)
{
int bandno, cblkno; int bandno, cblkno;
unsigned char *sop = 0, *eph = 0; unsigned char *sop = 0, *eph = 0;
unsigned char *c = dest; unsigned char *c = dest;
@ -300,13 +305,13 @@ static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_itera
return (c - dest); return (c - dest);
} }
static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) { static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first)
{
seg->numpasses = 0; seg->numpasses = 0;
seg->len = 0; seg->len = 0;
if (cblksty & J3D_CCP_CBLKSTY_TERMALL) { if (cblksty & J3D_CCP_CBLKSTY_TERMALL) {
seg->maxpasses = 1; seg->maxpasses = 1;
} } else if (cblksty & J3D_CCP_CBLKSTY_LAZY) {
else if (cblksty & J3D_CCP_CBLKSTY_LAZY) {
if (first) { if (first) {
seg->maxpasses = 10; seg->maxpasses = 10;
} else { } else {
@ -317,7 +322,8 @@ static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) {
} }
} }
int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) { int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi)
{
int bandno, cblkno; int bandno, cblkno;
unsigned char *c = src; unsigned char *c = src;
@ -550,7 +556,8 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info) { int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info)
{
unsigned char *c = dest; unsigned char *c = dest;
int e = 0; int e = 0;
opj_pi_iterator_t *pi = NULL; opj_pi_iterator_t *pi = NULL;
@ -611,7 +618,8 @@ int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlay
return (c - dest); return (c - dest);
} }
int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile) { int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile)
{
unsigned char *c = src; unsigned char *c = src;
opj_pi_iterator_t *pi; opj_pi_iterator_t *pi;
int pino, e = 0; int pino, e = 0;
@ -662,7 +670,8 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp) { opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp)
{
/* create the tcd structure */ /* create the tcd structure */
opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t));
if(!t2) return NULL; if(!t2) return NULL;
@ -673,7 +682,8 @@ opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp) {
return t2; return t2;
} }
void t2_destroy(opj_t2_t *t2) { void t2_destroy(opj_t2_t *t2)
{
if(t2) { if(t2) {
opj_free(t2); opj_free(t2);
} }

View File

@ -36,7 +36,8 @@
#include "opj_includes.h" #include "opj_includes.h"
void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t * vol) { void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t * vol)
{
int tileno, compno, resno, bandno, precno, cblkno; int tileno, compno, resno, bandno, precno, cblkno;
fprintf(fd, "volume {\n"); fprintf(fd, "volume {\n");
@ -87,7 +88,8 @@ void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t * vol) {
fprintf(fd, "}\n"); fprintf(fd, "}\n");
} }
static void tilec_dump(FILE *fd, opj_tcd_tilecomp_t *tilec) { static void tilec_dump(FILE *fd, opj_tcd_tilecomp_t *tilec)
{
int i=0,k; int i=0,k;
int datalen; int datalen;
@ -135,7 +137,8 @@ static void tilec_dump(FILE *fd, opj_tcd_tilecomp_t *tilec) {
/** /**
Create a new TCD handle Create a new TCD handle
*/ */
opj_tcd_t* tcd_create(opj_common_ptr cinfo) { opj_tcd_t* tcd_create(opj_common_ptr cinfo)
{
/* create the tcd structure */ /* create the tcd structure */
opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t)); opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t));
if(!tcd) return NULL; if(!tcd) return NULL;
@ -152,7 +155,8 @@ opj_tcd_t* tcd_create(opj_common_ptr cinfo) {
/** /**
Destroy a previously created TCD handle Destroy a previously created TCD handle
*/ */
void tcd_destroy(opj_tcd_t *tcd) { void tcd_destroy(opj_tcd_t *tcd)
{
if(tcd) { if(tcd) {
opj_free(tcd->tcd_volume); opj_free(tcd->tcd_volume);
opj_free(tcd); opj_free(tcd);
@ -160,7 +164,8 @@ void tcd_destroy(opj_tcd_t *tcd) {
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno) { void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno)
{
int compno, resno, bandno, precno, cblkno, i, j;/*, k;*/ int compno, resno, bandno, precno, cblkno, i, j;/*, k;*/
opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */
@ -447,7 +452,8 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int
/*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/
} }
void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno) { void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno)
{
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
int j, p, q, r; int j, p, q, r;
@ -717,7 +723,8 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int c
} }
void tcd_free_encode(opj_tcd_t *tcd) { void tcd_free_encode(opj_tcd_t *tcd)
{
int tileno, compno, resno, bandno, precno; int tileno, compno, resno, bandno, precno;
opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */
@ -773,7 +780,8 @@ void tcd_free_encode(opj_tcd_t *tcd) {
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp) { void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp)
{
int tileno, compno, resno, bandno, precno, cblkno, res_max, int tileno, compno, resno, bandno, precno, cblkno, res_max,
i, j, p, q, r; i, j, p, q, r;
unsigned int x0 = 0, y0 = 0, z0 = 0, unsigned int x0 = 0, y0 = 0, z0 = 0,
@ -1042,7 +1050,8 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp) {
} }
} }
void tcd_free_decode(opj_tcd_t *tcd) { void tcd_free_decode(opj_tcd_t *tcd)
{
int tileno,compno,resno,bandno,precno; int tileno,compno,resno,bandno,precno;
opj_tcd_volume_t *tcd_volume = tcd->tcd_volume; opj_tcd_volume_t *tcd_volume = tcd->tcd_volume;
@ -1079,7 +1088,8 @@ void tcd_free_decode(opj_tcd_t *tcd) {
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) { void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final)
{
int compno, resno, bandno, precno, cblkno; int compno, resno, bandno, precno, cblkno;
int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolution[0]][3]; */ int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolution[0]][3]; */
int matrice[10][10][3]; int matrice[10][10][3];
@ -1168,14 +1178,16 @@ void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) {
} }
} }
void tcd_rateallocate_fixed(opj_tcd_t *tcd) { void tcd_rateallocate_fixed(opj_tcd_t *tcd)
{
int layno; int layno;
for (layno = 0; layno < tcd->tcp->numlayers; layno++) { for (layno = 0; layno < tcd->tcp->numlayers; layno++) {
tcd_makelayer_fixed(tcd, layno, 1); tcd_makelayer_fixed(tcd, layno, 1);
} }
} }
void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) { void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final)
{
int compno, resno, bandno, precno, cblkno, passno; int compno, resno, bandno, precno, cblkno, passno;
opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; opj_tcd_tile_t *tcd_tile = tcd->tcd_tile;
@ -1248,7 +1260,8 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
} }
} }
bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_volume_info_t * volume_info) { bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_volume_info_t * volume_info)
{
int compno, resno, bandno, precno, cblkno, passno, layno; int compno, resno, bandno, precno, cblkno, passno, layno;
double min, max; double min, max;
double cumdisto[100]; /* fixed_quality */ double cumdisto[100]; /* fixed_quality */
@ -1387,7 +1400,8 @@ bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_volume_i
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_volume_info_t * volume_info) { int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_volume_info_t * volume_info)
{
int compno; int compno;
int l, i, npck = 0; int l, i, npck = 0;
double encoding_time; double encoding_time;
@ -1511,8 +1525,7 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
/*-------------------ENTROPY CODING-----------------------------*/ /*-------------------ENTROPY CODING-----------------------------*/
fprintf(stdout,"[INFO] Tcd_encode_tile: Entropy coding\n"); fprintf(stdout,"[INFO] Tcd_encode_tile: Entropy coding\n");
if ((cp->encoding_format == ENCOD_2EB)||(cp->encoding_format == ENCOD_3EB)) if ((cp->encoding_format == ENCOD_2EB)||(cp->encoding_format == ENCOD_3EB)) {
{
if (cp->encoding_format == ENCOD_2EB) { if (cp->encoding_format == ENCOD_2EB) {
opj_t1_t *t1 = NULL; opj_t1_t *t1 = NULL;
t1 = t1_create(tcd->cinfo); t1 = t1_create(tcd->cinfo);
@ -1576,7 +1589,8 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
} }
bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) { bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno)
{
int l, i; int l, i;
int compno, eof = 0; int compno, eof = 0;
double tile_time, t1_time, dwt_time; double tile_time, t1_time, dwt_time;

View File

@ -40,7 +40,8 @@
Tag-tree coder interface Tag-tree coder interface
========================================================== ==========================================================
*/ */
void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree){ void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree)
{
int nodesno; int nodesno;
fprintf(fd, "TGT_TREE {\n"); fprintf(fd, "TGT_TREE {\n");
@ -65,7 +66,8 @@ void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree){
} }
opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) { opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz)
{
int nplh[32]; int nplh[32];
int nplv[32]; int nplv[32];
@ -151,12 +153,14 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) {
return tree; return tree;
} }
void tgt_destroy(opj_tgt_tree_t *tree) { void tgt_destroy(opj_tgt_tree_t *tree)
{
opj_free(tree->nodes); opj_free(tree->nodes);
opj_free(tree); opj_free(tree);
} }
void tgt_reset(opj_tgt_tree_t *tree) { void tgt_reset(opj_tgt_tree_t *tree)
{
int i; int i;
if (NULL == tree) if (NULL == tree)
@ -169,7 +173,8 @@ void tgt_reset(opj_tgt_tree_t *tree) {
} }
} }
void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) { void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value)
{
opj_tgt_node_t *node; opj_tgt_node_t *node;
node = &tree->nodes[leafno]; node = &tree->nodes[leafno];
while (node && node->value > value) { while (node && node->value > value) {
@ -178,7 +183,8 @@ void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) {
} }
} }
void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold)
{
opj_tgt_node_t *stk[31]; opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr; opj_tgt_node_t **stkptr;
opj_tgt_node_t *node; opj_tgt_node_t *node;
@ -218,7 +224,8 @@ void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold)
} }
} }
int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold)
{
opj_tgt_node_t *stk[31]; opj_tgt_node_t *stk[31];
opj_tgt_node_t **stkptr; opj_tgt_node_t **stkptr;
opj_tgt_node_t *node; opj_tgt_node_t *node;

View File

@ -33,7 +33,8 @@
#include "volume.h" #include "volume.h"
#include "openjp3d.h" #include "openjp3d.h"
opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc)
{
int compno; int compno;
opj_volume_t *volume = NULL; opj_volume_t *volume = NULL;
@ -77,7 +78,8 @@ opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t
return volume; return volume;
} }
void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) { void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume)
{
int i; int i;
if(volume) { if(volume) {
if(volume->comps) { if(volume->comps) {

View File

@ -128,8 +128,7 @@ void send_responsedata_on_aux( OPJ_BOOL istcp, auxtrans_param_t auxtrans, const
if( status != 0) if( status != 0)
fprintf( FCGI_stderr,"ERROR: pthread_create() %s",strerror(status)); fprintf( FCGI_stderr,"ERROR: pthread_create() %s",strerror(status));
#endif #endif
} } else
else
fprintf( FCGI_stderr, "Error: error in send_responsedata_on_aux(), udp not implemented\n"); fprintf( FCGI_stderr, "Error: error in send_responsedata_on_aux(), udp not implemented\n");
} }

View File

@ -114,8 +114,7 @@ box_param_t * gene_boxbyOffset( int fd, OPJ_OFF_T offset)
if((data2 = fetch_bytes( fd, offset+8, 8))) { if((data2 = fetch_bytes( fd, offset+8, 8))) {
boxlen = big8(data2); boxlen = big8(data2);
free(data2); free(data2);
} } else {
else{
fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %" PRId64 ")\n", fd, offset); fprintf( FCGI_stderr, "Error: error in gene_boxbyOffset( %d, %" PRId64 ")\n", fd, offset);
free( data); free( data);
return NULL; return NULL;
@ -203,8 +202,7 @@ box_param_t * gene_boxbyType( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length, const
if((data2 = fetch_bytes( fd, pos+8, 8))) { if((data2 = fetch_bytes( fd, pos+8, 8))) {
boxlen = big8(data2); boxlen = big8(data2);
free(data2); free(data2);
} } else {
else{
fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox); fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
return NULL; return NULL;
} }
@ -221,8 +219,7 @@ box_param_t * gene_boxbyType( int fd, OPJ_OFF_T offset, OPJ_SIZE_T length, const
return foundbox; return foundbox;
} }
free( data); free( data);
} } else {
else{
fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox); fprintf( FCGI_stderr, "Error: error in gene_boxbyType( %d, %" PRId64 ", %" PRId64 ", %s)\n", fd, offset, length, TBox);
return NULL; return NULL;
} }
@ -287,8 +284,7 @@ box_param_t * gene_childboxbyType( box_param_t *superbox, OPJ_OFF_T offset, cons
{ {
OPJ_SIZE_T DBOXlen = get_DBoxlen(superbox); OPJ_SIZE_T DBOXlen = get_DBoxlen(superbox);
assert( offset >= 0 ); assert( offset >= 0 );
if( DBOXlen < (OPJ_SIZE_T)offset ) if( DBOXlen < (OPJ_SIZE_T)offset ) {
{
fprintf( FCGI_stderr, "Error: Impossible happen %lu < %ld\n", DBOXlen, offset); fprintf( FCGI_stderr, "Error: Impossible happen %lu < %ld\n", DBOXlen, offset);
return NULL; return NULL;
} }

View File

@ -224,8 +224,7 @@ OPJ_BOOL is_allsent( cachemodel_param_t cachemodel)
} }
} }
return OPJ_TRUE; return OPJ_TRUE;
} } else {
else{
for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++) for( i=0, n=0; i<target->codeidx->SIZ.YTnum; i++)
for( j=0; j<target->codeidx->SIZ.XTnum; j++) for( j=0; j<target->codeidx->SIZ.XTnum; j++)
for( k=0; k<TPnum; k++) for( k=0; k<TPnum; k++)

View File

@ -69,13 +69,11 @@ void handle_JPIPstreamMSG( SOCKET connected_socket, cachelist_param_t *cachelist
update_cachetid( tid, cache); update_cachetid( tid, cache);
if( cid != NULL) if( cid != NULL)
add_cachecid( cid, cache); add_cachecid( cid, cache);
} } else {
else{
cache = gene_cache( target, (int)msgqueue->last->csn, tid, cid); cache = gene_cache( target, (int)msgqueue->last->csn, tid, cid);
insert_cache_into_list( cache, cachelist); insert_cache_into_list( cache, cachelist);
} }
} } else
else
cache = search_cacheBycsn( (int)msgqueue->last->csn, cachelist); cache = search_cacheBycsn( (int)msgqueue->last->csn, cachelist);
if( cache->metadatalist) if( cache->metadatalist)

View File

@ -81,8 +81,7 @@ faixbox_param_t * gene_faixbox( box_param_t *box)
if( faix->version == 3) if( faix->version == 3)
subfaixbox->aux[i] = fetch_DBox4bytebigendian( box, (pos+=4)-4); subfaixbox->aux[i] = fetch_DBox4bytebigendian( box, (pos+=4)-4);
} }
} } else {
else{
subfaixbox4_param_t *subfaixbox; subfaixbox4_param_t *subfaixbox;
size_t i; size_t i;
@ -137,8 +136,7 @@ void delete_faixbox( faixbox_param_t **faix)
if( (*faix)->version == 3) if( (*faix)->version == 3)
free((*faix)->subfaixbox.byte8_params->aux); free((*faix)->subfaixbox.byte8_params->aux);
free((*faix)->subfaixbox.byte8_params); free((*faix)->subfaixbox.byte8_params);
} } else {
else{
free((*faix)->subfaixbox.byte4_params->elem); free((*faix)->subfaixbox.byte4_params->elem);
if( (*faix)->version == 2) if( (*faix)->version == 2)
free((*faix)->subfaixbox.byte4_params->aux); free((*faix)->subfaixbox.byte4_params->aux);

View File

@ -67,8 +67,7 @@ imgreg_param_t map_viewin2imgreg( const int fx, const int fy,
if( rx == -1 || ry == -1) { if( rx == -1 || ry == -1) {
imgreg.ox = 0; imgreg.ox = 0;
imgreg.oy = 0; imgreg.oy = 0;
} } else {
else{
imgreg.ox = rx*imgreg.fx/fx; imgreg.ox = rx*imgreg.fx/fx;
imgreg.oy = ry*imgreg.fy/fy; imgreg.oy = ry*imgreg.fy/fy;
} }
@ -76,8 +75,7 @@ imgreg_param_t map_viewin2imgreg( const int fx, const int fy,
if( rw == -1 || rh == -1) { if( rw == -1 || rh == -1) {
imgreg.sx = imgreg.fx; imgreg.sx = imgreg.fx;
imgreg.sy = imgreg.fy; imgreg.sy = imgreg.fy;
} } else {
else{
px = (int)ceil((double)((rx+rw)*imgreg.fx)/(double)fx); px = (int)ceil((double)((rx+rw)*imgreg.fx)/(double)fx);
py = (int)ceil((double)((ry+rh)*imgreg.fy)/(double)fy); py = (int)ceil((double)((ry+rh)*imgreg.fy)/(double)fy);
@ -111,8 +109,7 @@ void find_level( int maxlev, int *lev, int *fx, int *fy, int *xmin, int *ymin, i
if ((*fx < 1 && xwidth != 0) || (*fy < 1 && ywidth != 0)) { if ((*fx < 1 && xwidth != 0) || (*fy < 1 && ywidth != 0)) {
fprintf( FCGI_stderr, "Frame size must be strictly positive"); fprintf( FCGI_stderr, "Frame size must be strictly positive");
exit(-1); exit(-1);
} } else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) {
else if( *lev < maxlev-1 && ( *fx < xwidth || *fy < ywidth)) {
/* Simulate the ceil function. */ /* Simulate the ceil function. */
*xmin = (int)ceil((double)*xmin/(double)2.0); *xmin = (int)ceil((double)*xmin/(double)2.0);
*ymin = (int)ceil((double)*ymin/(double)2.0); *ymin = (int)ceil((double)*ymin/(double)2.0);

View File

@ -42,7 +42,8 @@ msgtype_t identify_clientmsg( SOCKET connected_socket)
char buf[BUF_LEN]; char buf[BUF_LEN];
static const char *magicid[] = { "JPIP-stream", "PNM request", "XML request", static const char *magicid[] = { "JPIP-stream", "PNM request", "XML request",
"TID request", "CID request", "CID destroy", "SIZ request", "JP2 save", "TID request", "CID request", "CID destroy", "SIZ request", "JP2 save",
"QUIT"}; "QUIT"
};
int i; int i;
receive_size = receive_line( connected_socket, buf); receive_size = receive_line( connected_socket, buf);
@ -102,8 +103,7 @@ Byte_t * receive_JPIPstream( SOCKET connected_socket, char **target, char **tid,
} }
idatalen = atoi( buf); idatalen = atoi( buf);
if( idatalen < 0 ) if( idatalen < 0 ) {
{
fprintf( stderr, "Receive Data: %d Bytes\n", idatalen); fprintf( stderr, "Receive Data: %d Bytes\n", idatalen);
return NULL; return NULL;
} }

View File

@ -641,8 +641,7 @@ OPJ_BOOL set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestr
COD->XPsiz[i] = (Byte2_t)pow( 2, fetch_marker1byte( codmkr, 12+i) & 0x0F); COD->XPsiz[i] = (Byte2_t)pow( 2, fetch_marker1byte( codmkr, 12+i) & 0x0F);
COD->YPsiz[i] = (Byte2_t)pow( 2,(fetch_marker1byte( codmkr, 12+i) & 0xF0) >> 4); COD->YPsiz[i] = (Byte2_t)pow( 2,(fetch_marker1byte( codmkr, 12+i) & 0xF0) >> 4);
} }
} } else {
else{
COD->XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); COD->XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
COD->YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); COD->YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));

View File

@ -135,8 +135,7 @@ CODmarker_param_t get_CODmkrdata_from_j2kstream( Byte_t *CODstream)
COD.XPsiz[i] = (Byte4_t)pow( 2, *( CODstream+12+i) & 0x0F); COD.XPsiz[i] = (Byte4_t)pow( 2, *( CODstream+12+i) & 0x0F);
COD.YPsiz[i] = (Byte4_t)pow( 2, (*( CODstream+12+i) & 0xF0) >> 4); COD.YPsiz[i] = (Byte4_t)pow( 2, (*( CODstream+12+i) & 0xF0) >> 4);
} }
} } else {
else{
COD.XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); COD.XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
COD.YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); COD.YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t));
COD.XPsiz[0] = COD.YPsiz[0] = 1<<15; /*pow(2,15)*/ COD.XPsiz[0] = COD.YPsiz[0] = 1<<15; /*pow(2,15)*/
@ -219,8 +218,7 @@ Byte2_t modify_CODmkrstream( CODmarker_param_t COD, int numOfdecomp, Byte_t *COD
*CODstream++ = (Byte_t)((Byte2_t)(newLcod & 0xff00) >> 8); *CODstream++ = (Byte_t)((Byte2_t)(newLcod & 0xff00) >> 8);
*CODstream++ = (Byte_t)(newLcod & 0x00ff); *CODstream++ = (Byte_t)(newLcod & 0x00ff);
} } else {
else{
newLcod = COD.Lcod; newLcod = COD.Lcod;
CODstream += 2; CODstream += 2;
} }

View File

@ -132,21 +132,24 @@ Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox)
/** /**
sample error callback expecting a FILE* client object sample error callback expecting a FILE* client object
*/ */
static void error_callback(const char *msg, void *client_data) { static void error_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[ERROR] %s", msg); fprintf(stream, "[ERROR] %s", msg);
} }
/** /**
sample warning callback expecting a FILE* client object sample warning callback expecting a FILE* client object
*/ */
static void warning_callback(const char *msg, void *client_data) { static void warning_callback(const char *msg, void *client_data)
{
FILE *stream = (FILE*)client_data; FILE *stream = (FILE*)client_data;
fprintf(stream, "[WARNING] %s", msg); fprintf(stream, "[WARNING] %s", msg);
} }
/** /**
sample debug callback expecting no client object sample debug callback expecting no client object
*/ */
static void info_callback(const char *msg, void *client_data) { static void info_callback(const char *msg, void *client_data)
{
(void)client_data; (void)client_data;
(void)msg; (void)msg;
/* fprintf(stdout, "[INFO] %s", msg); */ /* fprintf(stdout, "[INFO] %s", msg); */
@ -172,8 +175,7 @@ static Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox)
if( (*ihdrbox)->bpc != image->comps[0].prec) if( (*ihdrbox)->bpc != image->comps[0].prec)
fprintf( stderr, "Exception: bits per component not identical, codestream: %d, ihdrbox: %d\n", image->comps[0].prec, (*ihdrbox)->bpc); fprintf( stderr, "Exception: bits per component not identical, codestream: %d, ihdrbox: %d\n", image->comps[0].prec, (*ihdrbox)->bpc);
} } else {
else{
*ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t)); *ihdrbox = (ihdrbox_param_t *)malloc( sizeof(ihdrbox_param_t));
(*ihdrbox)->width = image->comps[0].w; (*ihdrbox)->width = image->comps[0].w;
(*ihdrbox)->height = image->comps[0].h; (*ihdrbox)->height = image->comps[0].h;
@ -188,23 +190,20 @@ static Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox)
if (image->comps[0].prec > 8) { if (image->comps[0].prec > 8) {
adjustR = image->comps[0].prec - 8; adjustR = image->comps[0].prec - 8;
printf("PNM CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); printf("PNM CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec);
} } else
else
adjustR = 0; adjustR = 0;
if( image->numcomps == 3) { if( image->numcomps == 3) {
if (image->comps[1].prec > 8) { if (image->comps[1].prec > 8) {
adjustG = image->comps[1].prec - 8; adjustG = image->comps[1].prec - 8;
printf("PNM CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec); printf("PNM CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec);
} } else
else
adjustG = 0; adjustG = 0;
if (image->comps[2].prec > 8) { if (image->comps[2].prec > 8) {
adjustB = image->comps[2].prec - 8; adjustB = image->comps[2].prec - 8;
printf("PNM CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec); printf("PNM CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec);
} } else
else
adjustB = 0; adjustB = 0;
} }

View File

@ -109,8 +109,7 @@ Byte_t * recons_jp2( msgqueue_param_t *msgqueue, Byte_t *jpipstream, Byte8_t csn
jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen; jp2cDBoxOffset = *jp2len + ptr->phld->OrigBHlen;
jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */ jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */
jp2cDBoxlen = *jp2len - jp2cDBoxOffset; jp2cDBoxlen = *jp2len - jp2cDBoxOffset;
} } else
else
jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */ jp2stream = add_emptyboxstream( ptr->phld, jp2stream, jp2len); /* header only */
} }
jp2stream = add_msgstream( ptr, jpipstream, jp2stream, jp2len); jp2stream = add_msgstream( ptr, jpipstream, jp2stream, jp2len);
@ -151,8 +150,7 @@ OPJ_BOOL isJPPstream( Byte8_t csn, msgqueue_param_t *msgqueue)
if( msg->csn == csn) { if( msg->csn == csn) {
if( msg->class_id <= 2) if( msg->class_id <= 2)
return OPJ_TRUE; return OPJ_TRUE;
else else if( msg->class_id == 4 || msg->class_id == 5)
if( msg->class_id == 4 || msg->class_id == 5)
return OPJ_FALSE; return OPJ_FALSE;
} }
msg = msg->next; msg = msg->next;
@ -274,8 +272,7 @@ Byte_t * recons_codestream_from_JPPstream( msgqueue_param_t *msgqueue, Byte_t *j
if( foundTH) { if( foundTH) {
j2kstream = recons_bitstream( msgqueue, jpipstream, j2kstream, csn, tileID, SIZ, COD, mindeclev, &max_reslev, j2klen); j2kstream = recons_bitstream( msgqueue, jpipstream, j2kstream, csn, tileID, SIZ, COD, mindeclev, &max_reslev, j2klen);
modify_tileheader( j2kstream, SOToffset, (max_reslev<COD.numOfdecomp ? max_reslev : -1), SIZ.Csiz, j2klen); modify_tileheader( j2kstream, SOToffset, (max_reslev<COD.numOfdecomp ? max_reslev : -1), SIZ.Csiz, j2klen);
} } else
else
j2kstream = add_emptytilestream( tileID, j2kstream, j2klen); j2kstream = add_emptytilestream( tileID, j2kstream, j2klen);
} }
@ -459,8 +456,7 @@ Byte_t * recons_PCRLbitstream( msgqueue_param_t *msgqueue, Byte_t *jpipstream, B
if( numOfprcts < min_numOfprcts || min_numOfprcts == 0) if( numOfprcts < min_numOfprcts || min_numOfprcts == 0)
min_numOfprcts = numOfprcts; min_numOfprcts = numOfprcts;
} }
} } else
else
min_numOfprcts = 1; min_numOfprcts = 1;
for( p=0; p<min_numOfprcts; p++) for( p=0; p<min_numOfprcts; p++)
@ -491,8 +487,7 @@ Byte_t * recons_CPRLbitstream( msgqueue_param_t *msgqueue, Byte_t *jpipstream, B
if( numOfprcts < min_numOfprcts || min_numOfprcts == 0) if( numOfprcts < min_numOfprcts || min_numOfprcts == 0)
min_numOfprcts = numOfprcts; min_numOfprcts = numOfprcts;
} }
} } else
else
min_numOfprcts = 1; min_numOfprcts = 1;
for( c=0; c<SIZ.Csiz; c++) for( c=0; c<SIZ.Csiz; c++)
@ -618,8 +613,7 @@ Byte8_t get_last_tileID( msgqueue_param_t *msgqueue, Byte8_t csn, OPJ_BOOL isjpp
if( isjppstream) { if( isjppstream) {
if((msg->class_id == TILE_HEADER_MSG) && msg->csn == csn && last_tileID < msg->in_class_id) if((msg->class_id == TILE_HEADER_MSG) && msg->csn == csn && last_tileID < msg->in_class_id)
last_tileID = msg->in_class_id; last_tileID = msg->in_class_id;
} } else {
else{
if((msg->class_id == TILE_MSG || msg->class_id == EXT_TILE_MSG) && msg->csn == csn && last_tileID < msg->in_class_id) if((msg->class_id == TILE_MSG || msg->class_id == EXT_TILE_MSG) && msg->csn == csn && last_tileID < msg->in_class_id)
last_tileID = msg->in_class_id; last_tileID = msg->in_class_id;
} }
@ -635,8 +629,7 @@ message_param_t * search_message( Byte8_t class_id, Byte8_t in_class_id, Byte8_t
if( in_class_id == (Byte8_t)-1) { if( in_class_id == (Byte8_t)-1) {
if( msg->class_id == class_id && msg->csn == csn) if( msg->class_id == class_id && msg->csn == csn)
return msg; return msg;
} } else {
else{
if( msg->class_id == class_id && msg->in_class_id == in_class_id && msg->csn == csn) if( msg->class_id == class_id && msg->in_class_id == in_class_id && msg->csn == csn)
return msg; return msg;
} }

View File

@ -68,8 +68,7 @@ OPJ_BOOL identify_target( query_param_t query_param, targetlist_param_t *targetl
if( *target) { if( *target) {
fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid); fprintf( FCGI_stdout, "JPIP-tid: %s\r\n", (*target)->tid);
return OPJ_TRUE; return OPJ_TRUE;
} } else {
else{
fprintf( FCGI_stdout, "Reason: target not found\r\n"); fprintf( FCGI_stdout, "Reason: target not found\r\n");
fprintf( FCGI_stdout, "Status: 400\r\n"); fprintf( FCGI_stdout, "Status: 400\r\n");
return OPJ_FALSE; return OPJ_FALSE;
@ -85,8 +84,7 @@ OPJ_BOOL associate_channel( query_param_t query_param,
if( !query_param.cnew) if( !query_param.cnew)
set_channel_variable_param( query_param, *curchannel); set_channel_variable_param( query_param, *curchannel);
} } else {
else{
fprintf( FCGI_stderr, "Error: process canceled\n"); fprintf( FCGI_stderr, "Error: process canceled\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -108,9 +106,7 @@ OPJ_BOOL open_channel( query_param_t query_param,
if( !( cachemodel = search_cachemodel( target, (*cursession)->cachemodellist))) if( !( cachemodel = search_cachemodel( target, (*cursession)->cachemodellist)))
if( !(cachemodel = gene_cachemodel( (*cursession)->cachemodellist, target, query_param.return_type==JPPstream))) if( !(cachemodel = gene_cachemodel( (*cursession)->cachemodellist, target, query_param.return_type==JPPstream)))
return OPJ_FALSE; return OPJ_FALSE;
} } else if( *curchannel)
else
if( *curchannel)
cachemodel = (*curchannel)->cachemodel; cachemodel = (*curchannel)->cachemodel;
*curchannel = gene_channel( query_param, auxtrans, cachemodel, (*cursession)->channellist); *curchannel = gene_channel( query_param, auxtrans, cachemodel, (*cursession)->channellist);
@ -135,8 +131,7 @@ OPJ_BOOL close_channel( query_param_t query_param,
/* all channels associatd with the session will be closed */ /* all channels associatd with the session will be closed */
if( !delete_session( cursession, sessionlist)) if( !delete_session( cursession, sessionlist))
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else{
/* check if all entry belonging to the same session */ /* check if all entry belonging to the same session */
for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)) { for( i=0, cclose=query_param.cclose; i<query_param.numOfcclose; i++, cclose += (strlen(cclose)+1)) {
@ -145,8 +140,7 @@ OPJ_BOOL close_channel( query_param_t query_param,
if( *cursession == NULL) { if( *cursession == NULL) {
if( !search_session_and_channel( cclose, sessionlist, cursession, curchannel)) if( !search_session_and_channel( cclose, sessionlist, cursession, curchannel))
return OPJ_FALSE; return OPJ_FALSE;
} } else /* second or more entry of close cid */
else /* second or more entry of close cid */
if( !(*curchannel=search_channel( cclose, (*cursession)->channellist))) { if( !(*curchannel=search_channel( cclose, (*cursession)->channellist))) {
fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", cclose); fprintf( FCGI_stdout, "Reason: Cclose id %s is from another session\r\n", cclose);
return OPJ_FALSE; return OPJ_FALSE;
@ -201,8 +195,7 @@ OPJ_BOOL gene_JPIPstream( query_param_t query_param,
if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream))) if( !(cachemodel = gene_cachemodel( NULL, target, query_param.return_type==JPPstream)))
return OPJ_FALSE; return OPJ_FALSE;
*msgqueue = gene_msgqueue( OPJ_TRUE, cachemodel); *msgqueue = gene_msgqueue( OPJ_TRUE, cachemodel);
} } else { /* session */
else{ /* session */
cachemodel = curchannel->cachemodel; cachemodel = curchannel->cachemodel;
target = cachemodel->target; target = cachemodel->target;
*msgqueue = gene_msgqueue( OPJ_FALSE, cachemodel); *msgqueue = gene_msgqueue( OPJ_FALSE, cachemodel);
@ -309,8 +302,7 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) { tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) {
/*printf("Tile completely excluded from view-window %d\n", tile_id);*/ /*printf("Tile completely excluded from view-window %d\n", tile_id);*/
/* Tile completely excluded from view-window */ /* Tile completely excluded from view-window */
} } else if( tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) &&
else if( tile_Xrange.minvalue >= (Byte4_t)(imgreg.xosiz + imgreg.ox) &&
tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) && tile_Xrange.maxvalue <= (Byte4_t)(imgreg.xosiz + imgreg.ox + imgreg.sx) &&
tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) && tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) &&
tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) { tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy)) {
@ -320,11 +312,9 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
if( msgqueue->cachemodel->jppstream) { if( msgqueue->cachemodel->jppstream) {
enqueue_tileheader( (int)tile_id, msgqueue); enqueue_tileheader( (int)tile_id, msgqueue);
enqueue_allprecincts( (int)tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue); enqueue_allprecincts( (int)tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
} } else
else
enqueue_tile( tile_id, imgreg.level, msgqueue); enqueue_tile( tile_id, imgreg.level, msgqueue);
} } else {
else{
/* Tile partially overlaps view-window */ /* Tile partially overlaps view-window */
/* low priority */ /* low priority */
/*printf("Tile partially overlaps view-window %d\n", tile_id);*/ /*printf("Tile partially overlaps view-window %d\n", tile_id);*/
@ -337,8 +327,7 @@ void enqueue_imagedata( query_param_t query_param, msgqueue_param_t *msgqueue)
ymin = tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) ? 0 : imgreg.yosiz + imgreg.oy - (int)tile_Yrange.minvalue; ymin = tile_Yrange.minvalue >= (Byte4_t)(imgreg.yosiz + imgreg.oy) ? 0 : imgreg.yosiz + imgreg.oy - (int)tile_Yrange.minvalue;
ymax = tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy) ? (int)(tile_Yrange.maxvalue - tile_Yrange.minvalue - 1) : (int)(imgreg.yosiz + imgreg.oy + imgreg.sy - (int)tile_Yrange.minvalue - 1); ymax = tile_Yrange.maxvalue <= (Byte4_t)(imgreg.yosiz + imgreg.oy + imgreg.sy) ? (int)(tile_Yrange.maxvalue - tile_Yrange.minvalue - 1) : (int)(imgreg.yosiz + imgreg.oy + imgreg.sy - (int)tile_Yrange.minvalue - 1);
enqueue_precincts( xmin, xmax, ymin, ymax, (int)tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue); enqueue_precincts( xmin, xmax, ymin, ymax, (int)tile_id, imgreg.level, query_param.lastcomp, query_param.comps, query_param.layers, msgqueue);
} } else
else
enqueue_tile( tile_id, imgreg.level, msgqueue); enqueue_tile( tile_id, imgreg.level, msgqueue);
} }
} }
@ -389,13 +378,11 @@ void enqueue_precincts( int xmin, int xmax, int ymin, int ymax, int tile_id, int
if( xmaxP < (Byte4_t)xmin || xminP > (Byte4_t)xmax || ymaxP < (Byte4_t)ymin || yminP > (Byte4_t)ymax) { if( xmaxP < (Byte4_t)xmin || xminP > (Byte4_t)xmax || ymaxP < (Byte4_t)ymin || yminP > (Byte4_t)ymax) {
/* Precinct completely excluded from view-window */ /* Precinct completely excluded from view-window */
} } else if( xminP >= (Byte4_t)xmin && xmaxP <= (Byte4_t)xmax && yminP >= (Byte4_t)ymin && ymaxP <= (Byte4_t)ymax) {
else if( xminP >= (Byte4_t)xmin && xmaxP <= (Byte4_t)xmax && yminP >= (Byte4_t)ymin && ymaxP <= (Byte4_t)ymax){
/* Precinct completely contained within view-window /* Precinct completely contained within view-window
high priority */ high priority */
enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue); enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
} } else {
else{
/* Precinct partially overlaps view-window /* Precinct partially overlaps view-window
low priority */ low priority */
enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue); enqueue_precinct( seq_id, tile_id, c, (dec_lev>level)?-1:layers, msgqueue);
@ -443,8 +430,7 @@ OPJ_BOOL enqueue_metabins( query_param_t query_param, metadatalist_param_t *meta
fprintf( FCGI_stdout, "Status: 501\r\n"); fprintf( FCGI_stdout, "Status: 501\r\n");
fprintf( FCGI_stdout, "Reason: metareq with all box-property * not implemented\r\n"); fprintf( FCGI_stdout, "Reason: metareq with all box-property * not implemented\r\n");
return OPJ_FALSE; return OPJ_FALSE;
} } else {
else{
Byte8_t idx = search_metadataidx( query_param.box_type[i], metadatalist); Byte8_t idx = search_metadataidx( query_param.box_type[i], metadatalist);
if( idx != (Byte8_t)-1) if( idx != (Byte8_t)-1)

View File

@ -81,13 +81,11 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
const char j2kfname[] = "tmp.j2k"; const char j2kfname[] = "tmp.j2k";
fp = fopen( j2kfname, "w+b"); fp = fopen( j2kfname, "w+b");
if( !fp ) if( !fp ) {
{
return NULL; return NULL;
} }
j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen);
if( !j2kstream ) if( !j2kstream ) {
{
fclose(fp); fclose(fp);
remove( j2kfname); remove( j2kfname);
return NULL; return NULL;
@ -96,8 +94,7 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte
retlen = fwrite( j2kstream, 1, j2klen, fp); retlen = fwrite( j2kstream, 1, j2klen, fp);
opj_free( j2kstream); opj_free( j2kstream);
fclose(fp); fclose(fp);
if( retlen != j2klen ) if( retlen != j2klen ) {
{
remove( j2kfname); remove( j2kfname);
return NULL; return NULL;
} }

View File

@ -95,7 +95,8 @@ void print_msgqueue( msgqueue_param_t *msgqueue)
{ {
message_param_t *ptr; message_param_t *ptr;
static const char *message_class[] = { "Precinct", "Ext-Prec", "TileHead", "non", static const char *message_class[] = { "Precinct", "Ext-Prec", "TileHead", "non",
"Tile", "Ext-Tile", "Main", "non", "Meta"}; "Tile", "Ext-Tile", "Main", "non", "Meta"
};
if( !msgqueue) if( !msgqueue)
return; return;
@ -427,8 +428,7 @@ void recons_stream_from_msgqueue( msgqueue_param_t *msgqueue, int tmpfd)
bb = 2; bb = 2;
class_id = msg->class_id; class_id = msg->class_id;
} }
} } else {
else{
bb = 3; bb = 3;
class_id = msg->class_id; class_id = msg->class_id;
csn = msg->csn; csn = msg->csn;
@ -671,8 +671,7 @@ void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *d
phld = parse_phld( datastream, msg->length); phld = parse_phld( datastream, msg->length);
msg->phld = phld; msg->phld = phld;
insert_placeholder_into_list( phld, metadata->placeholderlist); insert_placeholder_into_list( phld, metadata->placeholderlist);
} } else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) &&
else if( isalpha(boxtype[0]) && isalpha(boxtype[1]) &&
(isalnum(boxtype[2])||isspace(boxtype[2])) && (isalnum(boxtype[2])||isspace(boxtype[2])) &&
(isalpha(boxtype[3])||isspace(boxtype[3]))) { (isalpha(boxtype[3])||isspace(boxtype[3]))) {
if( !metadata->boxlist) if( !metadata->boxlist)
@ -680,8 +679,7 @@ void parse_metadata( metadata_param_t *metadata, message_param_t *msg, Byte_t *d
box = gene_boxbyOffinStream( datastream, msg->res_offset); box = gene_boxbyOffinStream( datastream, msg->res_offset);
insert_box_into_list( box, metadata->boxlist); insert_box_into_list( box, metadata->boxlist);
} } else
else
metadata->boxcontents = gene_boxcontents( msg->res_offset, msg->length); metadata->boxcontents = gene_boxcontents( msg->res_offset, msg->length);
} }

Some files were not shown because too many files have changed in this diff Show More