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,43 +417,31 @@ 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",
__FILE__,__LINE__,out_space, __FILE__,__LINE__,out_space,
(out_space>>24) & 0xff,(out_space>>16) & 0xff, (out_space>>24) & 0xff,(out_space>>16) & 0xff,
(out_space>>8) & 0xff, out_space & 0xff); (out_space>>8) & 0xff, out_space & 0xff);
#endif #endif
@ -397,13 +449,13 @@ __FILE__,__LINE__,out_space,
} }
#ifdef DEBUG_PROFILE #ifdef DEBUG_PROFILE
fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)" fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tchannels(%d) prec(%d) w(%d) h(%d)"
"\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec, "\n\tprofile: in(%p) out(%p)\n",__FILE__,__LINE__,image->numcomps,prec,
max_w,max_h, (void*)in_prof,(void*)out_prof); max_w,max_h, (void*)in_prof,(void*)out_prof);
fprintf(stderr,"\trender_intent (%u)\n\t" fprintf(stderr,"\trender_intent (%u)\n\t"
"color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t" "color_space: in(%#x)(%c%c%c%c) out:(%#x)(%c%c%c%c)\n\t"
" type: in(%u) out:(%u)\n", " type: in(%u) out:(%u)\n",
intent, intent,
in_space, in_space,
(in_space>>24) & 0xff,(in_space>>16) & 0xff, (in_space>>24) & 0xff,(in_space>>16) & 0xff,
@ -424,16 +476,15 @@ fprintf(stderr,"\trender_intent (%u)\n\t"
out_prof, out_type, intent, 0); out_prof, out_type, intent, 0);
#ifdef OPJ_HAVE_LIBLCMS2 #ifdef OPJ_HAVE_LIBLCMS2
/* Possible for: LCMS_VERSION >= 2000 :*/ /* Possible for: LCMS_VERSION >= 2000 :*/
cmsCloseProfile(in_prof); cmsCloseProfile(in_prof);
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__);
#endif #endif
image->color_space = oldspace; image->color_space = oldspace;
#ifdef OPJ_HAVE_LIBLCMS1 #ifdef OPJ_HAVE_LIBLCMS1
@ -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

@ -47,14 +47,15 @@ int opj_opterr = 1, /* if error message should be printed */
opj_optind = 1, /* index into parent argv vector */ opj_optind = 1, /* index into parent argv vector */
opj_optopt, /* character checked for validity */ opj_optopt, /* character checked for validity */
opj_optreset; /* reset getopt */ opj_optreset; /* reset getopt */
char *opj_optarg; /* argument associated with option */ char *opj_optarg; /* argument associated with option */
#define BADCH (int)'?' #define BADCH (int)'?'
#define BADARG (int)':' #define BADARG (int)':'
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;
@ -134,14 +137,12 @@ again:
return -1; return -1;
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;
} }
} }
@ -158,25 +159,24 @@ again:
o=longopts; o=longopts;
len=sizeof(longopts[0]); len=sizeof(longopts[0]);
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) {
for (i=0;i<totlen;i=i+len,o++) { for (i=0; i<totlen; i=i+len,o++) {
if (!strcmp(o->name,arg)) { /* match */ if (!strcmp(o->name,arg)) { /* match */
if (o->has_arg == 0) { if (o->has_arg == 0) {
if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))){ if ((argv[opj_optind+1])&&(!(argv[opj_optind+1][0]=='-'))) {
fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]); fprintf(stderr,"%s: option does not require an argument. Ignoring %s\n",arg,argv[opj_optind+1]);
++opj_optind; ++opj_optind;
} }
}else{ } else {
opj_optarg=argv[opj_optind+1]; opj_optarg=argv[opj_optind+1];
if(opj_optarg){ if(opj_optarg) {
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */ if (opj_optarg[0] == '-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) { if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg); fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH); return (BADCH);
@ -202,10 +202,11 @@ again:
fprintf(stderr,"Invalid option %s\n",arg); fprintf(stderr,"Invalid option %s\n",arg);
++opj_optind; ++opj_optind;
return (BADCH); return (BADCH);
}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*/
@ -219,8 +220,8 @@ again:
goto found; goto found;
} }
opj_optarg=argv[opj_optind+1]; opj_optarg=argv[opj_optind+1];
if(opj_optarg){ if(opj_optarg) {
if (opj_optarg[0] == '-'){ /* Has read next input parameter: No arg for current parameter */ if (opj_optarg[0] == '-') { /* Has read next input parameter: No arg for current parameter */
if (opj_opterr) { if (opj_opterr) {
fprintf(stderr,"%s: option requires an argument\n",arg); fprintf(stderr,"%s: option requires an argument\n",arg);
return (BADCH); return (BADCH);
@ -234,7 +235,7 @@ again:
} }
} }
++opj_optind; ++opj_optind;
}else {/*Argument not expected*/ } else {/*Argument not expected*/
++lastofs; ++lastofs;
return opj_optopt; return opj_optopt;
} }

View File

@ -3,13 +3,12 @@
#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;
int val; int val;
}opj_option_t; } opj_option_t;
#define NO_ARG 0 #define NO_ARG 0
#define REQ_ARG 1 #define REQ_ARG 1

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);
@ -949,7 +928,7 @@ 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;
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
@ -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,11 +46,12 @@ 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;
/* UniPG>> */ /* UniPG>> */
int tilepartno; int tilepartno;
char disto_on, numpix_on; char disto_on, numpix_on;
@ -58,7 +59,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0; return 0;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
if (!cstr_info) if (!cstr_info)
return 1; return 1;
@ -93,9 +94,9 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
} }
fprintf(stream, "\n"); fprintf(stream, "\n");
/* UniPG>> */ /* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start); fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */ /* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end); fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size); fprintf(stream, "%d\n", cstr_info->codestream_size);
@ -379,7 +380,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */ fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */ fprintf(stream, "%.8e\n", total_disto); /* SE totale */
} }
/* UniPG>> */ /* UniPG>> */
/* print the markers' list */ /* print the markers' list */
if (cstr_info->marknum) { if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n"); fprintf(stream, "\nMARKER LIST\n");
@ -388,7 +389,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
for (x = 0; x < cstr_info->marknum; x++) for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len); fprintf(stream, "%X\t%9" PRId64 " %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
} }
/* <<UniPG */ /* <<UniPG */
fclose(stream); fclose(stream);
fprintf(stderr,"Generated index file %s\n", index); fprintf(stderr,"Generated index file %s\n", index);

View File

@ -71,14 +71,14 @@
#include "format_defs.h" #include "format_defs.h"
#include "opj_string.h" #include "opj_string.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
@ -87,9 +87,10 @@ typedef struct img_folder{
char set_imgdir; char set_imgdir;
/** Enable Cod Format for output*/ /** Enable Cod Format for output*/
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());
@ -108,9 +109,9 @@ static void encode_help_display(void) {
fprintf(stdout," * No sub-sampling in x or y direction\n"); fprintf(stdout," * No sub-sampling in x or y direction\n");
fprintf(stdout," * No mode switch activated\n"); fprintf(stdout," * No mode switch activated\n");
fprintf(stdout," * Progression order: LRCP\n"); fprintf(stdout," * Progression order: LRCP\n");
#ifdef FIXME_INDEX #ifdef FIXME_INDEX
fprintf(stdout," * No index file\n"); fprintf(stdout," * No index file\n");
#endif /* FIXME_INDEX */ #endif /* FIXME_INDEX */
fprintf(stdout," * No ROI upshifted\n"); fprintf(stdout," * No ROI upshifted\n");
fprintf(stdout," * No offset of the origin of the image\n"); fprintf(stdout," * No offset of the origin of the image\n");
fprintf(stdout," * No offset of the origin of the tiles\n"); fprintf(stdout," * No offset of the origin of the tiles\n");
@ -218,10 +219,10 @@ static void encode_help_display(void) {
fprintf(stdout," Divide packets of every tile into tile-parts.\n"); fprintf(stdout," Divide packets of every tile into tile-parts.\n");
fprintf(stdout," Division is made by grouping Resolutions (R), Layers (L)\n"); fprintf(stdout," Division is made by grouping Resolutions (R), Layers (L)\n");
fprintf(stdout," or Components (C).\n"); fprintf(stdout," or Components (C).\n");
#ifdef FIXME_INDEX #ifdef FIXME_INDEX
fprintf(stdout,"-x <index file>\n"); fprintf(stdout,"-x <index file>\n");
fprintf(stdout," Create an index file.\n"); fprintf(stdout," Create an index file.\n");
#endif /*FIXME_INDEX*/ #endif /*FIXME_INDEX*/
fprintf(stdout,"-ROI c=<component index>,U=<upshifting value>\n"); fprintf(stdout,"-ROI c=<component index>,U=<upshifting value>\n");
fprintf(stdout," Quantization indices upshifted for a component. \n"); fprintf(stdout," Quantization indices upshifted for a component. \n");
fprintf(stdout," Warning: This option does not implement the usual ROI (Region of Interest).\n"); fprintf(stdout," Warning: This option does not implement the usual ROI (Region of Interest).\n");
@ -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;
@ -381,13 +384,13 @@ static unsigned int get_num_images(char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
num_images=0; num_images=0;
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
@ -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;
@ -404,14 +408,14 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
@ -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]="";
@ -463,11 +470,11 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,get_file_name(image_filename)); strcpy(temp_ofname,get_file_name(image_filename));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1; return 1;
@ -479,10 +486,11 @@ 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[]= {
{"cinema2K",REQ_ARG, NULL ,'w'}, {"cinema2K",REQ_ARG, NULL ,'w'},
{"cinema4K",NO_ARG, NULL ,'y'}, {"cinema4K",NO_ARG, NULL ,'y'},
{"ImgDir",REQ_ARG, NULL ,'z'}, {"ImgDir",REQ_ARG, NULL ,'z'},
@ -498,22 +506,21 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* parse the command line */ /* parse the command line */
const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:" const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:"
#ifdef USE_JPWL #ifdef USE_JPWL
"W:" "W:"
#endif /* USE_JPWL */ #endif /* USE_JPWL */
"h"; "h";
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format=0; img_fol->set_out_format=0;
raw_cp->rawWidth = 0; raw_cp->rawWidth = 0;
do{ do {
c = opj_getopt_long(argc, argv, optlist,long_option,totlen); c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
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,19 +983,18 @@ 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) {
parameters->rsiz = OPJ_PROFILE_CINEMA_2K; parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_comp_size = OPJ_CINEMA_24_COMP; parameters->max_comp_size = OPJ_CINEMA_24_COMP;
parameters->max_cs_size = OPJ_CINEMA_24_CS; parameters->max_cs_size = OPJ_CINEMA_24_CS;
}else if(fps == 48 ){ } else if(fps == 48 ) {
parameters->rsiz = OPJ_PROFILE_CINEMA_2K; parameters->rsiz = OPJ_PROFILE_CINEMA_2K;
parameters->max_comp_size = OPJ_CINEMA_48_COMP; parameters->max_comp_size = OPJ_CINEMA_48_COMP;
parameters->max_cs_size = OPJ_CINEMA_48_CS; parameters->max_cs_size = OPJ_CINEMA_48_CS;
}else { } else {
fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); fprintf(stderr,"Incorrect value!! must be 24 or 48\n");
return 1; return 1;
} }
@ -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,11 +1015,10 @@ 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) {
fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n"); fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n");
return 1; return 1;
} }
@ -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 ;
@ -1107,14 +1084,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
return 1; return 1;
} }
lCurrentDoublePtr = lSpace; lCurrentDoublePtr = lSpace;
for (i2=0;i2<lMctComp;++i2) { for (i2=0; i2<lMctComp; ++i2) {
lStrLen = strlen(lCurrentPtr) + 1; lStrLen = strlen(lCurrentPtr) + 1;
*lCurrentDoublePtr++ = (float) atof(lCurrentPtr); *lCurrentDoublePtr++ = (float) atof(lCurrentPtr);
lCurrentPtr += lStrLen; lCurrentPtr += lStrLen;
} }
l_int_ptr = (int*) lCurrentDoublePtr; l_int_ptr = (int*) lCurrentDoublePtr;
for (i2=0;i2<lNbComp;++i2) { for (i2=0; i2<lNbComp; ++i2) {
lStrLen = strlen(lCurrentPtr) + 1; lStrLen = strlen(lCurrentPtr) + 1;
*l_int_ptr++ = atoi(lCurrentPtr); *l_int_ptr++ = atoi(lCurrentPtr);
lCurrentPtr += lStrLen; lCurrentPtr += lStrLen;
@ -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;
@ -1467,24 +1442,24 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
fprintf(stderr, "[WARNING] An invalid option has been ignored\n"); fprintf(stderr, "[WARNING] An invalid option has been ignored\n");
break; break;
} }
}while(c != -1); } while(c != -1);
if(img_fol->set_imgdir == 1){ if(img_fol->set_imgdir == 1) {
if(!(parameters->infile[0] == 0)){ if(!(parameters->infile[0] == 0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together !!\n"); fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together !!\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n"); fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n");
return 1; return 1;
} }
if(!((parameters->outfile[0] == 0))){ if(!((parameters->outfile[0] == 0))) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n"); fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n"); fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n");
return 1; return 1;
} }
}else{ } else {
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] Required parameters are missing\n" fprintf(stderr, "[ERROR] Required parameters are missing\n"
"Example: %s -i image.pgm -o image.j2k\n",argv[0]); "Example: %s -i image.pgm -o image.j2k\n",argv[0]);
@ -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 */
@ -1639,35 +1619,35 @@ int main(int argc, char **argv) {
} }
/* Read directory if necessary */ /* Read directory if necessary */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ if(dirptr) {
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images*sizeof(char*)); dirptr->filename = (char**) malloc(num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
return 0; return 0;
} }
for(i=0;i<num_images;i++){ for(i=0; i<num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
return 0; return 0;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
return 0; return 0;
} }
}else{ } else {
num_images=1; num_images=1;
} }
/*Encoding image one by one*/ /*Encoding image one by one*/
for(imageno=0;imageno<num_images;imageno++) { for(imageno=0; imageno<num_images; imageno++) {
image = NULL; image = NULL;
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file((int)imageno, dirptr,&img_fol, &parameters)) { if (get_next_file((int)imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
@ -1770,7 +1750,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;
@ -1780,12 +1760,12 @@ int main(int argc, char **argv) {
if (parameters.tcp_mct == (char) 255) { /* mct mode has not been set in commandline */ if (parameters.tcp_mct == (char) 255) { /* mct mode has not been set in commandline */
parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0; parameters.tcp_mct = (image->numcomps >= 3) ? 1 : 0;
} else { /* mct mode has been set in commandline */ } else { /* mct mode has been set in commandline */
if ((parameters.tcp_mct == 1) && (image->numcomps < 3)){ if ((parameters.tcp_mct == 1) && (image->numcomps < 3)) {
fprintf(stderr, "RGB->YCC conversion cannot be used:\n"); fprintf(stderr, "RGB->YCC conversion cannot be used:\n");
fprintf(stderr, "Input image has less than 3 components\n"); fprintf(stderr, "Input image has less than 3 components\n");
return 1; return 1;
} }
if ((parameters.tcp_mct == 2) && (!parameters.mct_data)){ if ((parameters.tcp_mct == 2) && (!parameters.mct_data)) {
fprintf(stderr, "Custom MCT has been set but no array-based MCT\n"); fprintf(stderr, "Custom MCT has been set but no array-based MCT\n");
fprintf(stderr, "has been provided. Aborting.\n"); fprintf(stderr, "has been provided. Aborting.\n");
return 1; return 1;
@ -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;
@ -1835,7 +1813,7 @@ int main(int argc, char **argv) {
/* open a byte stream for writing and allocate memory for all tiles */ /* open a byte stream for writing and allocate memory for all tiles */
l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE); l_stream = opj_stream_create_default_file_stream(parameters.outfile,OPJ_FALSE);
if (! l_stream){ if (! l_stream) {
return 1; return 1;
} }
@ -1849,7 +1827,7 @@ int main(int argc, char **argv) {
OPJ_UINT32 l_data_size = 512*512*3; OPJ_UINT32 l_data_size = 512*512*3;
l_data = (OPJ_BYTE*) calloc( 1,l_data_size); l_data = (OPJ_BYTE*) calloc( 1,l_data_size);
assert( l_data ); assert( l_data );
for (i=0;i<l_nb_tiles;++i) { for (i=0; i<l_nb_tiles; ++i) {
if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) { if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) {
fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i); fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i);
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -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

@ -77,15 +77,15 @@
#include "format_defs.h" #include "format_defs.h"
#include "opj_string.h" #include "opj_string.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
@ -95,22 +95,19 @@ typedef struct img_folder{
/** Enable Cod Format for output*/ /** Enable Cod Format for output*/
char set_out_format; char set_out_format;
}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;
@ -150,7 +147,7 @@ typedef struct opj_decompress_params
int upsample; int upsample;
/* split output components to different files */ /* split output components to different files */
int split_pnm; int split_pnm;
}opj_decompress_parameters; } opj_decompress_parameters;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* Declarations */ /* Declarations */
@ -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());
@ -226,7 +224,7 @@ static void decode_help_display(void) {
" -split-pnm\n" " -split-pnm\n"
" Split output components to different files when writing to PNM\n" " Split output components to different files when writing to PNM\n"
"\n"); "\n");
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
fprintf(stdout," -W <options>\n" fprintf(stdout," -W <options>\n"
" Activates the JPWL correction capability, if the codestream complies.\n" " Activates the JPWL correction capability, if the codestream complies.\n"
@ -235,7 +233,7 @@ static void decode_help_display(void) {
" numcomps is the number of expected components in the codestream\n" " numcomps is the number of expected components in the codestream\n"
" (search of first EPB rely upon this, default is %d)\n", JPWL_EXPECTED_COMPONENTS); " (search of first EPB rely upon this, default is %d)\n", JPWL_EXPECTED_COMPONENTS);
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
@ -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;
@ -354,12 +352,12 @@ int get_num_images(char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
@ -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;
@ -377,14 +376,14 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
@ -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]="";
@ -438,11 +439,11 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompre
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,strtok(image_filename,".")); strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1; return 1;
@ -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,10 +511,11 @@ 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[]= {
{"ImgDir", REQ_ARG, NULL,'y'}, {"ImgDir", REQ_ARG, NULL,'y'},
{"OutFor", REQ_ARG, NULL,'O'}, {"OutFor", REQ_ARG, NULL,'O'},
{"force-rgb", NO_ARG, NULL, 1}, {"force-rgb", NO_ARG, NULL, 1},
@ -525,11 +525,11 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
const char optlist[] = "i:o:r:l:x:d:t:p:" const char optlist[] = "i:o:r:l:x:d:t:p:"
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
"W:" "W:"
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
"h" ; "h" ;
long_option[2].flag = &(parameters->force_rgb); long_option[2].flag = &(parameters->force_rgb);
@ -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, ",");
@ -804,7 +792,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
} }
break; break;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
@ -812,25 +800,25 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break; break;
} }
}while(c != -1); } while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1) {
if(!(parameters->infile[0]==0)){ if(!(parameters->infile[0]==0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n" fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1; return 1;
} }
if(!((parameters->outfile[0] == 0))){ if(!((parameters->outfile[0] == 0))) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together.\n"); fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together.\n");
return 1; return 1;
} }
}else{ } else {
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] Required parameters are missing\n" fprintf(stderr, "[ERROR] Required parameters are missing\n"
"Example: %s -i image.j2k -o image.pgm\n",argv[0]); "Example: %s -i image.j2k -o image.pgm\n",argv[0]);
@ -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));
} }
} }
@ -1205,33 +1197,33 @@ int main(int argc, char **argv)
} }
/* Initialize reading of directory */ /* Initialize reading of directory */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
int it_image; int it_image;
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ if(dirptr) {
dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
destroy_parameters(&parameters); destroy_parameters(&parameters);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
for(it_image=0;it_image<num_images;it_image++){ for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
destroy_parameters(&parameters); destroy_parameters(&parameters);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
destroy_parameters(&parameters); destroy_parameters(&parameters);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}else{ } else {
num_images=1; num_images=1;
} }
@ -1240,7 +1232,7 @@ int main(int argc, char **argv)
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) { if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
destroy_parameters(&parameters); destroy_parameters(&parameters);
@ -1252,7 +1244,7 @@ int main(int argc, char **argv)
/* ---------------------------------------- */ /* ---------------------------------------- */
l_stream = opj_stream_create_default_file_stream(parameters.infile,1); l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){ if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile); fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile);
destroy_parameters(&parameters); destroy_parameters(&parameters);
return EXIT_FAILURE; return EXIT_FAILURE;
@ -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;
@ -1295,7 +1284,7 @@ int main(int argc, char **argv)
t = opj_clock(); t = opj_clock();
/* Setup the decoder decoding parameters using user parameters */ /* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &(parameters.core)) ){ if ( !opj_setup_decoder(l_codec, &(parameters.core)) ) {
fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n"); fprintf(stderr, "ERROR -> opj_decompress: failed to setup the decoder\n");
destroy_parameters(&parameters); destroy_parameters(&parameters);
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -1305,7 +1294,7 @@ int main(int argc, char **argv)
/* Read the main header of the codestream and if necessary the JP2 boxes*/ /* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)){ if(! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n");
destroy_parameters(&parameters); destroy_parameters(&parameters);
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -1317,7 +1306,7 @@ int main(int argc, char **argv)
if (!parameters.nb_tile_to_decode) { if (!parameters.nb_tile_to_decode) {
/* Optional if you want decode the entire image */ /* Optional if you want decode the entire image */
if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0, if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0,
(OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){ (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)) {
fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n");
destroy_parameters(&parameters); destroy_parameters(&parameters);
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
@ -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)) {
@ -1371,13 +1359,11 @@ int main(int argc, char **argv)
else if (image->numcomps <= 2) else if (image->numcomps <= 2)
image->color_space = OPJ_CLRSPC_GRAY; image->color_space = OPJ_CLRSPC_GRAY;
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,85 +1452,77 @@ 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;
case PGX_DFMT: /* PGX */ case PGX_DFMT: /* PGX */
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;
case BMP_DFMT: /* BMP */ case BMP_DFMT: /* BMP */
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;
#ifdef OPJ_HAVE_LIBTIFF #ifdef OPJ_HAVE_LIBTIFF
case TIF_DFMT: /* TIFF */ case TIF_DFMT: /* TIFF */
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;
#endif /* OPJ_HAVE_LIBTIFF */ #endif /* OPJ_HAVE_LIBTIFF */
case RAW_DFMT: /* RAW */ case RAW_DFMT: /* RAW */
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;
case RAWL_DFMT: /* RAWL */ case RAWL_DFMT: /* RAWL */
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;
case TGA_DFMT: /* TGA */ case TGA_DFMT: /* TGA */
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;
#ifdef OPJ_HAVE_LIBPNG #ifdef OPJ_HAVE_LIBPNG
case PNG_DFMT: /* PNG */ case PNG_DFMT: /* PNG */
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;
#endif /* OPJ_HAVE_LIBPNG */ #endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG /* Can happen if output 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
*/ */
default: default:
fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"[ERROR] Outfile %s not generated\n",parameters.outfile);
failed = 1; failed = 1;

View File

@ -59,15 +59,15 @@
#include "format_defs.h" #include "format_defs.h"
#include "opj_string.h" #include "opj_string.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
@ -78,7 +78,7 @@ typedef struct img_folder{
char set_out_format; char set_out_format;
int flag; int flag;
}img_fol_t; } img_fol_t;
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* Declarations */ /* Declarations */
@ -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;
@ -125,12 +127,12 @@ static int get_num_images(char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
@ -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;
@ -148,14 +151,14 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
@ -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]="";
@ -203,11 +208,11 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,strtok(image_filename,".")); strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) { if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
return 1; return 1;
@ -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,9 +279,10 @@ 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'}
}; };
const char optlist[] = "i:o:f:hv"; const char optlist[] = "i:o:f:hv";
@ -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;
@ -359,25 +359,25 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
fprintf(stderr, "[WARNING] An invalid option has been ignored.\n"); fprintf(stderr, "[WARNING] An invalid option has been ignored.\n");
break; break;
} }
}while(c != -1); } while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1) {
if(!(parameters->infile[0]==0)){ if(!(parameters->infile[0]==0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n"); fprintf(stderr, "[ERROR] options -ImgDir and -i cannot be used together.\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n"); fprintf(stderr, "[ERROR] When -ImgDir is used, -OutFor <FORMAT> must be used.\n");
fprintf(stderr, "Only one format allowed.\n" fprintf(stderr, "Only one format allowed.\n"
"Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n"); "Valid format are PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA.\n");
return 1; return 1;
} }
if(!(parameters->outfile[0] == 0)){ if(!(parameters->outfile[0] == 0)) {
fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n"); fprintf(stderr, "[ERROR] options -ImgDir and -o cannot be used together\n");
return 1; return 1;
} }
}else{ } else {
if(parameters->infile[0] == 0) { if(parameters->infile[0] == 0) {
fprintf(stderr, "[ERROR] Required parameter is missing\n"); fprintf(stderr, "[ERROR] Required parameter is missing\n");
fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]); fprintf(stderr, "Example: %s -i image.j2k\n",argv[0]);
@ -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);
} }
@ -452,52 +455,51 @@ int main(int argc, char *argv[])
} }
/* Initialize reading of directory */ /* Initialize reading of directory */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
int it_image; int it_image;
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ if(dirptr) {
dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
for(it_image=0;it_image<num_images;it_image++){ for(it_image=0; it_image<num_images; it_image++) {
dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN; dirptr->filename[it_image] = dirptr->filename_buf + it_image*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
}else{ } else {
num_images=1; num_images=1;
} }
/* Try to open for writing the output file if necessary */ /* Try to open for writing the output file if necessary */
if (parameters.outfile[0] != 0){ if (parameters.outfile[0] != 0) {
fout = fopen(parameters.outfile,"w"); fout = fopen(parameters.outfile,"w");
if (!fout){ if (!fout) {
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 */
for(imageno = 0; imageno < num_images ; imageno++){ for(imageno = 0; imageno < num_images ; imageno++) {
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) { if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
@ -508,7 +510,7 @@ int main(int argc, char *argv[])
/* ---------------------------------------- */ /* ---------------------------------------- */
l_stream = opj_stream_create_default_file_stream(parameters.infile,1); l_stream = opj_stream_create_default_file_stream(parameters.infile,1);
if (!l_stream){ if (!l_stream) {
fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile); fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -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;
@ -547,7 +546,7 @@ int main(int argc, char *argv[])
opj_set_error_handler(l_codec, error_callback,00); opj_set_error_handler(l_codec, error_callback,00);
/* Setup the decoder decoding parameters using user parameters */ /* Setup the decoder decoding parameters using user parameters */
if ( !opj_setup_decoder(l_codec, &parameters) ){ if ( !opj_setup_decoder(l_codec, &parameters) ) {
fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n");
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);
@ -556,7 +555,7 @@ int main(int argc, char *argv[])
} }
/* Read the main header of the codestream and if necessary the JP2 boxes*/ /* Read the main header of the codestream and if necessary the JP2 boxes*/
if(! opj_read_header(l_stream, l_codec, &image)){ if(! opj_read_header(l_stream, l_codec, &image)) {
fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n");
opj_stream_destroy(l_stream); opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec); opj_destroy_codec(l_codec);

View File

@ -106,14 +106,14 @@
*/ */
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) #if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */ # if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */ /* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */ # elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */ /* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */ # elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H # define HAVE_DIRENT_H
# define VOID_CLOSEDIR # define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */ # elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */ /* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */ # elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H # define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */ # elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#elif defined(MSDOS) || defined(WIN32) #elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */ /* figure out type of underlaying directory interface to be used */
# if defined(WIN32) # if defined(WIN32)
# define DIRENT_WIN32_INTERFACE # define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS) # elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface" # error "missing native dirent interface"
# endif # endif
/*** WIN32 specifics ***/ /*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h> # include <windows.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif # endif
/*** MS-DOS specifics ***/ /*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h> # include <dos.h>
/* Borland defines file length macros in dir.h */ /* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t # define _find_t find_t
# endif # endif
/* Turbo C defines ffblk structure in dir.h */ /* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__) # elif defined(__TURBOC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif # endif
# define DIRENT_USE_FFBLK # define DIRENT_USE_FFBLK
/* MSVC */ /* MSVC */
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12) # define DIRENT_MAXNAMLEN (12)
# endif # endif
/* Watcom */ /* Watcom */
# elif defined(__WATCOMC__) # elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__) # if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif # endif
# endif # endif
/*** generic MS-DOS and MS-Windows stuff ***/ /*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) # if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN # define NAME_MAX DIRENT_MAXNAMLEN
# endif # endif
@ -239,7 +239,7 @@
# endif # endif
/* /*
* Substitute for real dirent structure. Note that `d_name' field is a * Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation * true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name' * dependent data. We could save some memory if we had declared `d_name'
@ -248,7 +248,7 @@
* something other than four. Besides, directory entries are typically so * something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place. * small that it takes virtually no time to copy them from place to place.
*/ */
typedef struct dirent { typedef struct dirent {
char d_name[NAME_MAX + 1]; char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/ /*** Operating system specific part ***/
@ -261,11 +261,11 @@
struct _find_t data; struct _find_t data;
# endif # endif
# endif # endif
} dirent; } dirent;
/* DIR substitute structure containing directory name. The name is /* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */ * essential for the operation of ``rewinndir'' function. */
typedef struct DIR { typedef struct DIR {
char *dirname; /* directory being scanned */ char *dirname; /* directory being scanned */
dirent current; /* current entry */ dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */ int dirent_filled; /* is current un-processed? */
@ -275,7 +275,7 @@
HANDLE search_handle; HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# endif # endif
} DIR; } DIR;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
@ -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;
@ -186,7 +191,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
memset(&cmptparm, 0, sizeof(opj_volume_cmptparm_t)); memset(&cmptparm, 0, sizeof(opj_volume_cmptparm_t));
/* Separación del caso de un único slice frente al de muchos */ /* Separación del caso de un único slice frente al de muchos */
if ((tmp = strrchr(relpath,'-')) == NULL){ if ((tmp = strrchr(relpath,'-')) == NULL) {
/*fprintf(stdout,"[INFO] A volume of only one slice....\n");*/ /*fprintf(stdout,"[INFO] A volume of only one slice....\n");*/
sliceno = 1; sliceno = 1;
maxslice = 1; maxslice = 1;
@ -195,8 +200,9 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
} else { } else {
/*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,"./");
@ -209,26 +215,25 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
tmp = relpath; tmp = relpath;
if ((tmp2 = strrchr(tmp,'-')) != NULL) if ((tmp2 = strrchr(tmp,'-')) != NULL)
*tmp2='\0'; *tmp2='\0';
else{ else {
fprintf(stdout, "[ERROR] tmp2 ha dado null. no ha encontrado el * %s %s",tmp,relpath); fprintf(stdout, "[ERROR] tmp2 ha dado null. no ha encontrado el * %s %s",tmp,relpath);
return NULL; return NULL;
} }
strcpy(pattern,tmp); strcpy(pattern,tmp);
dirp = opendir( dirpath ); dirp = opendir( dirpath );
if (dirp == NULL){ if (dirp == NULL) {
fprintf(stdout, "[ERROR] Infile must be a .pgx file or a directory that contain pgx files"); fprintf(stdout, "[ERROR] Infile must be a .pgx file or a directory that contain pgx files");
return NULL; return NULL;
} }
/*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;
if( ((pgx = strstr(direntp->d_name,pattern)) != NULL) && ((tmp2 = strstr(direntp->d_name,".pgx")) != NULL) ){ if( ((pgx = strstr(direntp->d_name,pattern)) != NULL) && ((tmp2 = strstr(direntp->d_name,".pgx")) != NULL) ) {
strcpy(tmp,dirpath); strcpy(tmp,dirpath);
tmp = strcat(tmp,direntp->d_name); tmp = strcat(tmp,direntp->d_name);
@ -241,10 +246,11 @@ 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) {
break; break;
} }
/*Slicepos --> index de slice; Sliceno --> no de slices hasta el momento*/ /*Slicepos --> index de slice; Sliceno --> no de slices hasta el momento*/
@ -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) {
@ -300,7 +305,7 @@ opj_volume_t* pgxtovolume(char *relpath, opj_cparameters_t *parameters) {
return NULL; return NULL;
} }
if (s==0){ if (s==0) {
/* initialize volume component */ /* initialize volume component */
cmptparm.x0 = parameters->volume_offset_x0; cmptparm.x0 = parameters->volume_offset_x0;
@ -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;
@ -474,7 +481,7 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
int i, compno, w, h, l, numcomps = 1; int i, compno, w, h, l, numcomps = 1;
int prec, max = 0; int prec, max = 0;
/* char temp[32];*/ /* char temp[32];*/
char line[100]; char line[100];
int bigendian; int bigendian;
@ -498,11 +505,11 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
while (!feof(fimg)) { while (!feof(fimg)) {
fgets(line,100,fimg); fgets(line,100,fimg);
/*fprintf(stdout,"%s %d \n",line,feof(fimg));*/ /*fprintf(stdout,"%s %d \n",line,feof(fimg));*/
if (strncmp(line,"Bpp",3) == 0){ if (strncmp(line,"Bpp",3) == 0) {
sscanf(line,"%*s%*[ \t]%d",&prec); sscanf(line,"%*s%*[ \t]%d",&prec);
} else if (strncmp(line,"Color",5) == 0){ } else if (strncmp(line,"Color",5) == 0) {
sscanf(line, "%*s%*[ \t]%d",&color_space); sscanf(line, "%*s%*[ \t]%d",&color_space);
} else if (strncmp(line,"Dim",3) == 0){ } else if (strncmp(line,"Dim",3) == 0) {
sscanf(line, "%*s%*[ \t]%d%*[ \t]%d%*[ \t]%d",&w,&h,&l); sscanf(line, "%*s%*[ \t]%d%*[ \t]%d%*[ \t]%d",&w,&h,&l);
} }
} }
@ -510,9 +517,9 @@ opj_volume_t* bintovolume(char *filename, char *fileimg, opj_cparameters_t *para
/*fscanf(fimg, "Color Map%[ \t]%d%[ \n\t]Dimensions%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&color_space,temp,temp,&w,temp,&h,temp,&l,temp);*/ /*fscanf(fimg, "Color Map%[ \t]%d%[ \n\t]Dimensions%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&color_space,temp,temp,&w,temp,&h,temp,&l,temp);*/
/*fscanf(fimg, "Resolution(mm)%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&subsampling_dx,temp,&subsampling_dy,temp,&subsampling_dz,temp);*/ /*fscanf(fimg, "Resolution(mm)%[ \t]%d%[ \t]%d%[ \t]%d%[ \n\t]",temp,&subsampling_dx,temp,&subsampling_dy,temp,&subsampling_dz,temp);*/
#ifdef VERBOSE #ifdef VERBOSE
fprintf(stdout, "[INFO] %d \t %d %d %d \t %3.2f %2.2f %2.2f \t %d \n",color_space,w,h,l,subsampling_dx,subsampling_dy,subsampling_dz,prec); fprintf(stdout, "[INFO] %d \t %d %d %d \t %3.2f %2.2f %2.2f \t %d \n",color_space,w,h,l,subsampling_dx,subsampling_dy,subsampling_dz,prec);
#endif #endif
fclose(fimg); fclose(fimg);
/* initialize volume components */ /* initialize volume components */
@ -678,13 +685,14 @@ 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;
FILE *fdest = NULL; FILE *fdest = NULL;
FILE *fimgdest = NULL; FILE *fimgdest = NULL;
/* char *imgtemp;*/ /* char *imgtemp;*/
char name[256]; char name[256];
for (compno = 0; compno < 1; compno++) { /*Only one component*/ for (compno = 0; compno < 1; compno++) { /*Only one component*/
@ -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;
@ -794,8 +803,9 @@ 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,"./");
@ -805,33 +815,33 @@ opj_volume_t* imgtovolume(char *fileimg, opj_cparameters_t *parameters) {
while (!feof(fimg)) { while (!feof(fimg)) {
fgets(line,100,fimg); fgets(line,100,fimg);
/*fprintf(stdout,"%s %d \n",line,feof(fimg));*/ /*fprintf(stdout,"%s %d \n",line,feof(fimg));*/
if (strncmp(line,"Image",5) == 0){ if (strncmp(line,"Image",5) == 0) {
sscanf(line,"%*s%*[ \t]%s",datatype); sscanf(line,"%*s%*[ \t]%s",datatype);
} else if (strncmp(line,"File",4) == 0){ } else if (strncmp(line,"File",4) == 0) {
sscanf(line,"%*s %*s%*[ \t]%s",filename); sscanf(line,"%*s %*s%*[ \t]%s",filename);
strcat(dirpath, filename); strcat(dirpath, filename);
strcpy(filename,dirpath); strcpy(filename,dirpath);
} else if (strncmp(line,"Min",3) == 0){ } else if (strncmp(line,"Min",3) == 0) {
sscanf(line,"%*s %*s%*[ \t]%d%*[ \t]%d",&min,&max); sscanf(line,"%*s %*s%*[ \t]%d%*[ \t]%d",&min,&max);
prec = int_floorlog2(max - min + 1); prec = int_floorlog2(max - min + 1);
} else if (strncmp(line,"Bpp",3) == 0){ } else if (strncmp(line,"Bpp",3) == 0) {
sscanf(line,"%*s%*[ \t]%d",&prec); sscanf(line,"%*s%*[ \t]%d",&prec);
} else if (strncmp(line,"Color",5) == 0){ } else if (strncmp(line,"Color",5) == 0) {
sscanf(line, "%*s %*s%*[ \t]%d",&color_space); sscanf(line, "%*s %*s%*[ \t]%d",&color_space);
} else if (strncmp(line,"Dim",3) == 0){ } else if (strncmp(line,"Dim",3) == 0) {
sscanf(line, "%*s%*[ \t]%d%*[ \t]%d%*[ \t]%d",&w,&h,&l); sscanf(line, "%*s%*[ \t]%d%*[ \t]%d%*[ \t]%d",&w,&h,&l);
} else if (strncmp(line,"Res",3) == 0){ } else if (strncmp(line,"Res",3) == 0) {
sscanf(line,"%*s%*[ \t]%f%*[ \t]%f%*[ \t]%f",&dx,&dy,&dz); sscanf(line,"%*s%*[ \t]%f%*[ \t]%f%*[ \t]%f",&dx,&dy,&dz);
} }
} }
#ifdef VERBOSE #ifdef VERBOSE
fprintf(stdout, "[INFO] %s %d \t %d %d %d \t %f %f %f \t %d %d %d \n",filename,color_space,w,h,l,dx,dy,dz,max,min,prec); fprintf(stdout, "[INFO] %s %d \t %d %d %d \t %f %f %f \t %d %d %d \n",filename,color_space,w,h,l,dx,dy,dz,max,min,prec);
#endif #endif
fclose(fimg); fclose(fimg);
/* error control */ /* error control */
if ( !prec || !w || !h || !l ){ if ( !prec || !w || !h || !l ) {
fprintf(stderr,"[ERROR] Unable to read IMG file correctly. Found some null values."); fprintf(stderr,"[ERROR] Unable to read IMG file correctly. Found some null values.");
return NULL; return NULL;
} }

View File

@ -55,9 +55,10 @@ 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 */
static char *place = EMSG; /* option letter processing */ static char *place = EMSG; /* option letter processing */
char *oli; /* option letter list index */ char *oli; /* option letter list index */

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)
@ -409,7 +407,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters)
else if (aux == 1) { else if (aux == 1) {
parameters->numresolution[1] = parameters->numresolution[0]; parameters->numresolution[1] = parameters->numresolution[0];
parameters->numresolution[2] = 1; parameters->numresolution[2] = 1;
}else if (aux == 0){ } else if (aux == 0) {
parameters->numresolution[0] = 1; parameters->numresolution[0] = 1;
parameters->numresolution[1] = 1; parameters->numresolution[1] = 1;
parameters->numresolution[2] = 1; parameters->numresolution[2] = 1;
@ -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

@ -105,7 +105,7 @@ static double calc_SSIM(opj_volume_t *original, opj_volume_t *decoded)
/*MSSIM*/ /*MSSIM*/
/* sizeM = size / (original->z1 - original->z0);*/ /* sizeM = size / (original->z1 - original->z0);*/
sizeM = size; sizeM = size;
for(sum = 0, i = 0; i < sizeM; ++i) { for(sum = 0, i = 0; i < sizeM; ++i) {
@ -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]);
@ -311,7 +309,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters)
else if (aux == 1) { else if (aux == 1) {
parameters->cp_reduce[1] = parameters->cp_reduce[0]; parameters->cp_reduce[1] = parameters->cp_reduce[0];
parameters->cp_reduce[2] = 0; parameters->cp_reduce[2] = 0;
}else if (aux == 0){ } else if (aux == 0) {
parameters->cp_reduce[0] = 0; parameters->cp_reduce[0] = 0;
parameters->cp_reduce[1] = 0; parameters->cp_reduce[1] = 0;
parameters->cp_reduce[2] = 0; parameters->cp_reduce[2] = 0;
@ -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 */
@ -497,19 +495,27 @@ int main(int argc, char **argv) {
} }
switch (parameters.orig_format) { switch (parameters.orig_format) {
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;
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;
@ -521,7 +527,7 @@ int main(int argc, char **argv) {
(volume->comps[0].l >> volume->comps[0].factor[2]), (volume->comps[0].l >> volume->comps[0].factor[2]),
volume->comps[0].prec); volume->comps[0].prec);
if(original){ if(original) {
psnr = calc_PSNR(original,volume); psnr = calc_PSNR(original,volume);
ssim = calc_SSIM(original,volume); ssim = calc_SSIM(original,volume);
if (psnr < 0.0) if (psnr < 0.0)

View File

@ -105,14 +105,14 @@
*/ */
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) #if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */ # if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */ /* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */ # elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */ /* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */ # elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H # define HAVE_DIRENT_H
# define VOID_CLOSEDIR # define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */ # elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */ /* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */ # elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H # define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */ # elif defined(__apollo) /* Apollo */
@ -171,7 +171,7 @@
#elif defined(MSDOS) || defined(WIN32) #elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */ /* figure out type of underlaying directory interface to be used */
# if defined(WIN32) # if defined(WIN32)
# define DIRENT_WIN32_INTERFACE # define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS) # elif defined(MSDOS)
@ -180,7 +180,7 @@
# error "missing native dirent interface" # error "missing native dirent interface"
# endif # endif
/*** WIN32 specifics ***/ /*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h> # include <windows.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -188,11 +188,11 @@
# endif # endif
/*** MS-DOS specifics ***/ /*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h> # include <dos.h>
/* Borland defines file length macros in dir.h */ /* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -202,7 +202,7 @@
# define _find_t find_t # define _find_t find_t
# endif # endif
/* Turbo C defines ffblk structure in dir.h */ /* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__) # elif defined(__TURBOC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -210,13 +210,13 @@
# endif # endif
# define DIRENT_USE_FFBLK # define DIRENT_USE_FFBLK
/* MSVC */ /* MSVC */
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12) # define DIRENT_MAXNAMLEN (12)
# endif # endif
/* Watcom */ /* Watcom */
# elif defined(__WATCOMC__) # elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__) # if defined(__OS2__) || defined(__NT__)
@ -229,7 +229,7 @@
# endif # endif
# endif # endif
/*** generic MS-DOS and MS-Windows stuff ***/ /*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) # if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN # define NAME_MAX DIRENT_MAXNAMLEN
# endif # endif
@ -238,7 +238,7 @@
# endif # endif
/* /*
* Substitute for real dirent structure. Note that `d_name' field is a * Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation * true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name' * dependent data. We could save some memory if we had declared `d_name'
@ -247,7 +247,7 @@
* something other than four. Besides, directory entries are typically so * something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place. * small that it takes virtually no time to copy them from place to place.
*/ */
typedef struct dirent { typedef struct dirent {
char d_name[NAME_MAX + 1]; char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/ /*** Operating system specific part ***/
@ -260,11 +260,11 @@
struct _find_t data; struct _find_t data;
# endif # endif
# endif # endif
} dirent; } dirent;
/* DIR substitute structure containing directory name. The name is /* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */ * essential for the operation of ``rewinndir'' function. */
typedef struct DIR { typedef struct DIR {
char *dirname; /* directory being scanned */ char *dirname; /* directory being scanned */
dirent current; /* current entry */ dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */ int dirent_filled; /* is current un-processed? */
@ -274,7 +274,7 @@
HANDLE search_handle; HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# endif # endif
} DIR; } DIR;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
@ -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;
@ -82,9 +83,9 @@ int main(int argc, char *argv[]){
terminate_dec_server( &server_record); terminate_dec_server( &server_record);
#ifdef _WIN32 #ifdef _WIN32
if( WSACleanup() != 0){ if( WSACleanup() != 0) {
printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError()); printf("\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{ } else {
printf("\nWSACleanup OK\n"); printf("\nWSACleanup OK\n");
} }
#endif #endif

View File

@ -78,7 +78,7 @@ int main(int argc, char *argv[])
char *xmldata, type[]="xml "; char *xmldata, type[]="xml ";
long fsize, boxsize; long fsize, boxsize;
if( argc<3){ if( argc<3) {
fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] ); fprintf( stderr, "USAGE: %s modifing.jp2 adding.xml\n", argv[0] );
return -1; return -1;
} }
@ -109,19 +109,19 @@ FILE * open_jp2file( const char filename[])
FILE *fp; FILE *fp;
char *data; char *data;
if( !(fp = fopen( filename, "a+b"))){ if( !(fp = fopen( filename, "a+b"))) {
fprintf( stderr, "Original JP2 %s not found\n", filename); fprintf( stderr, "Original JP2 %s not found\n", filename);
return NULL; return NULL;
} }
/* Check resource is a JP family file. */ /* Check resource is a JP family file. */
if( fseek( fp, 0, SEEK_SET)==-1){ if( fseek( fp, 0, SEEK_SET)==-1) {
fclose(fp); fclose(fp);
fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename); fprintf( stderr, "Original JP2 %s broken (fseek error)\n", filename);
return NULL; return NULL;
} }
data = (char *)malloc( 12); /* size of header */ data = (char *)malloc( 12); /* size of header */
if( fread( data, 12, 1, fp) != 1){ if( fread( data, 12, 1, fp) != 1) {
free( data); free( data);
fclose(fp); fclose(fp);
fprintf( stderr, "Original JP2 %s broken (read error)\n", filename); fprintf( stderr, "Original JP2 %s broken (read error)\n", filename);
@ -129,7 +129,7 @@ FILE * open_jp2file( const char filename[])
} }
if( *data || *(data + 1) || *(data + 2) || if( *data || *(data + 1) || *(data + 2) ||
*(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)){ *(data + 3) != 12 || strncmp (data + 4, "jP \r\n\x87\n", 8)) {
free( data); free( data);
fclose(fp); fclose(fp);
fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename); fprintf( stderr, "No JPEG 2000 Signature box in target %s\n", filename);
@ -145,25 +145,25 @@ char * read_xmlfile( const char filename[], long *fsize)
char *data; char *data;
/* fprintf( stderr, "open %s\n", filename);*/ /* fprintf( stderr, "open %s\n", filename);*/
if(!(fp = fopen( filename, "r"))){ if(!(fp = fopen( filename, "r"))) {
fprintf( stderr, "XML file %s not found\n", filename); fprintf( stderr, "XML file %s not found\n", filename);
return NULL; return NULL;
} }
if( fseek( fp, 0, SEEK_END) == -1){ if( fseek( fp, 0, SEEK_END) == -1) {
fprintf( stderr, "XML file %s broken (seek error)\n", filename); fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp); fclose( fp);
return NULL; return NULL;
} }
if( (*fsize = ftell( fp)) == -1){ if( (*fsize = ftell( fp)) == -1) {
fprintf( stderr, "XML file %s broken (seek error)\n", filename); fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp); fclose( fp);
return NULL; return NULL;
} }
assert( *fsize >= 0 ); assert( *fsize >= 0 );
if( fseek( fp, 0, SEEK_SET) == -1){ if( fseek( fp, 0, SEEK_SET) == -1) {
fprintf( stderr, "XML file %s broken (seek error)\n", filename); fprintf( stderr, "XML file %s broken (seek error)\n", filename);
fclose( fp); fclose( fp);
return NULL; return NULL;
@ -171,7 +171,7 @@ char * read_xmlfile( const char filename[], long *fsize)
data = (char *)malloc( (size_t)*fsize); data = (char *)malloc( (size_t)*fsize);
if( fread( data, (size_t)*fsize, 1, fp) != 1){ if( fread( data, (size_t)*fsize, 1, fp) != 1) {
fprintf( stderr, "XML file %s broken (read error)\n", filename); fprintf( stderr, "XML file %s broken (read error)\n", filename);
free( data); free( data);
fclose(fp); fclose(fp);

View File

@ -55,12 +55,12 @@ main(int argc, char *argv[])
index_t *jp2idx; index_t *jp2idx;
if( argc < 2 ) return 1; if( argc < 2 ) return 1;
if( (fd = open( argv[1], O_RDONLY)) == -1){ if( (fd = open( argv[1], O_RDONLY)) == -1) {
fprintf( stderr, "Error: Target %s not found\n", argv[1]); fprintf( stderr, "Error: Target %s not found\n", argv[1]);
return -1; return -1;
} }
if( !(jp2idx = get_index_from_JP2file( fd))){ if( !(jp2idx = get_index_from_JP2file( fd))) {
fprintf( stderr, "JP2 file broken\n"); fprintf( stderr, "JP2 file broken\n");
return -1; return -1;
} }

View File

@ -98,7 +98,7 @@ static int jpip_to_j2k(char *argv[])
int main(int argc,char *argv[]) int main(int argc,char *argv[])
{ {
char *ext; char *ext;
if( argc < 3){ if( argc < 3) {
fprintf( stderr, "Too few arguments:\n"); fprintf( stderr, "Too few arguments:\n");
fprintf( stderr, " - input jpt or jpp file\n"); fprintf( stderr, " - input jpt or jpp file\n");
fprintf( stderr, " - output j2k file\n"); fprintf( stderr, " - output j2k file\n");
@ -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);
} }
} }

View File

@ -104,7 +104,7 @@ int main(void)
if( parse_status) if( parse_status)
send_responsedata( server_record, qr); send_responsedata( server_record, qr);
else{ else {
fprintf( FCGI_stderr, "Error: JPIP request failed\n"); fprintf( FCGI_stderr, "Error: JPIP request failed\n");
fprintf( FCGI_stdout, "\r\n"); fprintf( FCGI_stdout, "\r\n");
} }
@ -117,9 +117,9 @@ int main(void)
terminate_JPIPserver( &server_record); terminate_JPIPserver( &server_record);
#ifdef _WIN32 #ifdef _WIN32
if( WSACleanup() != 0){ if( WSACleanup() != 0) {
fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError()); fprintf( stderr, "\nError in WSACleanup : %d %d",erreur,WSAGetLastError());
}else{ } else {
fprintf( stderr, "\nWSACleanup OK\n"); fprintf( stderr, "\nWSACleanup OK\n");
} }
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -45,11 +45,12 @@ 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;
/* UniPG>> */ /* UniPG>> */
int tilepartno; int tilepartno;
char disto_on, numpix_on; char disto_on, numpix_on;
@ -57,7 +58,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
if (!strcmp(index, JPWL_PRIVATEINDEX_NAME)) if (!strcmp(index, JPWL_PRIVATEINDEX_NAME))
return 0; return 0;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
if (!cstr_info) if (!cstr_info)
return 1; return 1;
@ -92,9 +93,9 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
} }
fprintf(stream, "\n"); fprintf(stream, "\n");
/* UniPG>> */ /* UniPG>> */
fprintf(stream, "%d\n", cstr_info->main_head_start); fprintf(stream, "%d\n", cstr_info->main_head_start);
/* <<UniPG */ /* <<UniPG */
fprintf(stream, "%d\n", cstr_info->main_head_end); fprintf(stream, "%d\n", cstr_info->main_head_end);
fprintf(stream, "%d\n", cstr_info->codestream_size); fprintf(stream, "%d\n", cstr_info->codestream_size);
@ -378,7 +379,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */ fprintf(stream, "%8e\n", cstr_info->D_max); /* SE max */
fprintf(stream, "%.8e\n", total_disto); /* SE totale */ fprintf(stream, "%.8e\n", total_disto); /* SE totale */
} }
/* UniPG>> */ /* UniPG>> */
/* print the markers' list */ /* print the markers' list */
if (cstr_info->marknum) { if (cstr_info->marknum) {
fprintf(stream, "\nMARKER LIST\n"); fprintf(stream, "\nMARKER LIST\n");
@ -387,7 +388,7 @@ int write_index_file(opj_codestream_info_t *cstr_info, char *index) {
for (x = 0; x < cstr_info->marknum; x++) for (x = 0; x < cstr_info->marknum; x++)
fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len); fprintf(stream, "%X\t%9d %9d\n", cstr_info->marker[x].type, cstr_info->marker[x].pos, cstr_info->marker[x].len);
} }
/* <<UniPG */ /* <<UniPG */
fclose(stream); fclose(stream);
fprintf(stderr,"Generated index file %s\n", index); fprintf(stderr,"Generated index file %s\n", index);

View File

@ -68,14 +68,14 @@
#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ #define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/
#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ #define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
@ -86,19 +86,20 @@ typedef struct img_folder{
char set_out_format; char set_out_format;
/** User specified rate stored in case of cinema option*/ /** User specified rate stored in case of cinema option*/
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");
/* UniPG>> */ /* UniPG>> */
fprintf(stdout,"List of parameters for the JPEG 2000 " fprintf(stdout,"List of parameters for the JPEG 2000 "
#ifdef USE_JPWL #ifdef USE_JPWL
"+ JPWL " "+ JPWL "
#endif /* USE_JPWL */ #endif /* USE_JPWL */
"encoder:\n"); "encoder:\n");
/* <<UniPG */ /* <<UniPG */
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"REMARKS:\n"); fprintf(stdout,"REMARKS:\n");
fprintf(stdout,"---------\n"); fprintf(stdout,"---------\n");
@ -124,11 +125,11 @@ static void encode_help_display(void) {
fprintf(stdout," * No offset of the origin of the image\n"); fprintf(stdout," * No offset of the origin of the image\n");
fprintf(stdout," * No offset of the origin of the tiles\n"); fprintf(stdout," * No offset of the origin of the tiles\n");
fprintf(stdout," * Reversible DWT 5-3\n"); fprintf(stdout," * Reversible DWT 5-3\n");
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
fprintf(stdout," * No JPWL protection\n"); fprintf(stdout," * No JPWL protection\n");
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"Parameters:\n"); fprintf(stdout,"Parameters:\n");
fprintf(stdout,"------------\n"); fprintf(stdout,"------------\n");
@ -220,7 +221,7 @@ static void encode_help_display(void) {
fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n"); fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n");
fprintf(stdout," NOTICE: currently supports only RPCL order\n"); fprintf(stdout," NOTICE: currently supports only RPCL order\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n"); fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n");
fprintf(stdout," The parameters can be written and repeated in any order:\n"); fprintf(stdout," The parameters can be written and repeated in any order:\n");
@ -286,7 +287,7 @@ static void encode_help_display(void) {
fprintf(stdout," - when you use UEP, always pair the 'p' option with 'h'\n"); fprintf(stdout," - when you use UEP, always pair the 'p' option with 'h'\n");
fprintf(stdout," \n"); fprintf(stdout," \n");
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
fprintf(stdout,"IMPORTANT:\n"); fprintf(stdout,"IMPORTANT:\n");
fprintf(stdout,"-----------\n"); fprintf(stdout,"-----------\n");
fprintf(stdout,"\n"); fprintf(stdout,"\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;
@ -355,13 +358,13 @@ static unsigned int get_num_images(char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
num_images=0; num_images=0;
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
@ -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;
@ -377,14 +381,14 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
@ -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]="";
@ -435,18 +442,19 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,get_file_name(image_filename)); strcpy(temp_ofname,get_file_name(image_filename));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
strncpy(parameters->outfile, outfilename, sizeof(outfilename)); strncpy(parameters->outfile, outfilename, sizeof(outfilename));
} }
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,24 +499,26 @@ 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;
switch (parameters->cp_cinema){ switch (parameters->cp_cinema) {
case CINEMA2K_24: case CINEMA2K_24:
case CINEMA2K_48: case CINEMA2K_48:
if(parameters->numresolution > 6){ if(parameters->numresolution > 6) {
parameters->numresolution = 6; parameters->numresolution = 6;
} }
if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){ if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))) {
fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
"(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
image->comps[0].w,image->comps[0].h); image->comps[0].w,image->comps[0].h);
@ -516,12 +527,12 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
break; break;
case CINEMA4K_24: case CINEMA4K_24:
if(parameters->numresolution < 1){ if(parameters->numresolution < 1) {
parameters->numresolution = 1; parameters->numresolution = 1;
}else if(parameters->numresolution > 7){ } else if(parameters->numresolution > 7) {
parameters->numresolution = 7; parameters->numresolution = 7;
} }
if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){ if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))) {
fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
"(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
image->comps[0].w,image->comps[0].h); image->comps[0].w,image->comps[0].h);
@ -533,21 +544,21 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
break; break;
} }
switch (parameters->cp_cinema){ switch (parameters->cp_cinema) {
case CINEMA2K_24: case CINEMA2K_24:
case CINEMA4K_24: case CINEMA4K_24:
for(i=0 ; i<parameters->tcp_numlayers ; i++){ for(i=0 ; i<parameters->tcp_numlayers ; i++) {
temp_rate = 0 ; temp_rate = 0 ;
if (img_fol->rates[i]== 0){ if (img_fol->rates[i]== 0) {
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{ } else {
temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_24_CS ){ if (temp_rate > CINEMA_24_CS ) {
parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{ } else {
parameters->tcp_rates[i]= img_fol->rates[i]; parameters->tcp_rates[i]= img_fol->rates[i];
} }
} }
@ -556,18 +567,18 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *imag
break; break;
case CINEMA2K_48: case CINEMA2K_48:
for(i=0 ; i<parameters->tcp_numlayers ; i++){ for(i=0 ; i<parameters->tcp_numlayers ; i++) {
temp_rate = 0 ; temp_rate = 0 ;
if (img_fol->rates[i]== 0){ if (img_fol->rates[i]== 0) {
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{ } else {
temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
if (temp_rate > CINEMA_48_CS ){ if (temp_rate > CINEMA_48_CS ) {
parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/
(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
}else{ } else {
parameters->tcp_rates[i]= img_fol->rates[i]; parameters->tcp_rates[i]= img_fol->rates[i];
} }
} }
@ -583,9 +594,10 @@ 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'},
{"cinema4K",NO_ARG, NULL ,'y'}, {"cinema4K",NO_ARG, NULL ,'y'},
{"ImgDir",REQ_ARG, NULL ,'z'}, {"ImgDir",REQ_ARG, NULL ,'z'},
@ -609,13 +621,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
img_fol->set_out_format=0; img_fol->set_out_format=0;
raw_cp->rawWidth = 0; raw_cp->rawWidth = 0;
do{ do {
c = opj_getopt_long(argc, argv, optlist,long_option,totlen); c = opj_getopt_long(argc, argv, optlist,long_option,totlen);
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,15 +1015,14 @@ 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) {
parameters->cp_cinema = CINEMA2K_24; parameters->cp_cinema = CINEMA2K_24;
}else if(fps == 48 ){ } else if(fps == 48 ) {
parameters->cp_cinema = CINEMA2K_48; parameters->cp_cinema = CINEMA2K_48;
}else { } else {
fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); fprintf(stderr,"Incorrect value!! must be 24 or 48\n");
return 1; return 1;
} }
@ -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;
@ -1062,12 +1043,11 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
/* UniPG>> */ /* UniPG>> */
#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;
@ -1380,11 +1360,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
} }
break; break;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
/* ------------------------------------------------------ */ /* ------------------------------------------------------ */
case 'J': /* jpip on */ case 'J': { /* jpip on */
{
/*parameters->jpip_on = OPJ_TRUE;*/ /*parameters->jpip_on = OPJ_TRUE;*/
} }
break; break;
@ -1395,31 +1374,31 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
fprintf(stderr, "ERROR -> Command line not valid\n"); fprintf(stderr, "ERROR -> Command line not valid\n");
return 1; return 1;
} }
}while(c != -1); } while(c != -1);
/* check for possible errors */ /* check for possible errors */
if (parameters->cp_cinema){ if (parameters->cp_cinema) {
if(parameters->tcp_numlayers > 1){ if(parameters->tcp_numlayers > 1) {
parameters->cp_rsiz = STD_RSIZ; parameters->cp_rsiz = STD_RSIZ;
fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n"); fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n");
} }
} }
if(img_fol->set_imgdir == 1){ if(img_fol->set_imgdir == 1) {
if(!(parameters->infile[0] == 0)){ if(!(parameters->infile[0] == 0)) {
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n"); fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n");
return 1; return 1;
} }
if(!((parameters->outfile[0] == 0))){ if(!((parameters->outfile[0] == 0))) {
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n"); fprintf(stderr, "Specify OutputFormat using -OutFor<FORMAT> !!\n");
return 1; return 1;
} }
}else{ } else {
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]); fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]); fprintf(stderr, " Try: %s -h\n",argv[0]);
@ -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;
@ -1527,9 +1510,9 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
if (parameters.cp_cinema){ if (parameters.cp_cinema) {
img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float)); img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float));
for(i=0; i< parameters.tcp_numlayers; i++){ for(i=0; i< parameters.tcp_numlayers; i++) {
img_fol.rates[i] = parameters.tcp_rates[i]; img_fol.rates[i] = parameters.tcp_rates[i];
} }
cinema_parameters(&parameters); cinema_parameters(&parameters);
@ -1540,7 +1523,7 @@ int main(int argc, char **argv) {
const char comment[] = "Created by OpenJPEG version "; const char comment[] = "Created by OpenJPEG version ";
const size_t clen = strlen(comment); const size_t clen = strlen(comment);
const char *version = opj_version(); const char *version = opj_version();
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
parameters.cp_comment = (char*)malloc(clen+strlen(version)+11); parameters.cp_comment = (char*)malloc(clen+strlen(version)+11);
sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version); sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version);
@ -1548,39 +1531,39 @@ int main(int argc, char **argv) {
parameters.cp_comment = (char*)malloc(clen+strlen(version)+1); parameters.cp_comment = (char*)malloc(clen+strlen(version)+1);
sprintf(parameters.cp_comment,"%s%s", comment, version); sprintf(parameters.cp_comment,"%s%s", comment, version);
#endif #endif
/* <<UniPG */ /* <<UniPG */
} }
/* Read directory if necessary */ /* Read directory if necessary */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ if(dirptr) {
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images*sizeof(char*)); dirptr->filename = (char**) malloc(num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
return 0; return 0;
} }
for(i=0;i<num_images;i++){ for(i=0; i<num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
return 0; return 0;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
return 0; return 0;
} }
}else{ } else {
num_images=1; num_images=1;
} }
/*Encoding image one by one*/ /*Encoding image one by one*/
for(imageno=0;imageno<num_images;imageno++) { for(imageno=0; imageno<num_images; imageno++) {
image = NULL; image = NULL;
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) { if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
@ -1667,18 +1650,17 @@ int main(int argc, char **argv) {
break; break;
#endif /* OPJ_HAVE_LIBPNG */ #endif /* OPJ_HAVE_LIBPNG */
} }
/* 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;
} }
/* Decide if MCT should be used */ /* Decide if MCT should be used */
parameters.tcp_mct = image->numcomps == 3 ? 1 : 0; parameters.tcp_mct = image->numcomps == 3 ? 1 : 0;
if(parameters.cp_cinema){ if(parameters.cp_cinema) {
cinema_setup_encoder(&parameters,image,&img_fol); cinema_setup_encoder(&parameters,image,&img_fol);
} }

View File

@ -71,15 +71,15 @@
#include "format_defs.h" #include "format_defs.h"
typedef struct dircnt{ typedef struct dircnt {
/** Buffer for holding images read from Directory*/ /** Buffer for holding images read from Directory*/
char *filename_buf; char *filename_buf;
/** Pointer to the buffer*/ /** Pointer to the buffer*/
char **filename; char **filename;
}dircnt_t; } dircnt_t;
typedef struct img_folder{ typedef struct img_folder {
/** The directory path of the folder containing input images*/ /** The directory path of the folder containing input images*/
char *imgdirpath; char *imgdirpath;
/** Output format*/ /** Output format*/
@ -89,19 +89,20 @@ typedef struct img_folder{
/** Enable Cod Format for output*/ /** Enable Cod Format for output*/
char set_out_format; char set_out_format;
}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");
/* UniPG>> */ /* UniPG>> */
fprintf(stdout,"List of parameters for the JPEG 2000 " fprintf(stdout,"List of parameters for the JPEG 2000 "
#ifdef USE_JPWL #ifdef USE_JPWL
"+ JPWL " "+ JPWL "
#endif /* USE_JPWL */ #endif /* USE_JPWL */
"decoder:\n"); "decoder:\n");
/* <<UniPG */ /* <<UniPG */
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
fprintf(stdout," -ImgDir \n"); fprintf(stdout," -ImgDir \n");
@ -135,7 +136,7 @@ void decode_help_display(void) {
fprintf(stdout," -x \n"); fprintf(stdout," -x \n");
fprintf(stdout," Create an index file *.Idx (-x index_name.Idx) \n"); fprintf(stdout," Create an index file *.Idx (-x index_name.Idx) \n");
fprintf(stdout,"\n"); fprintf(stdout,"\n");
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
fprintf(stdout," -W <options>\n"); fprintf(stdout," -W <options>\n");
fprintf(stdout," Activates the JPWL correction capability, if the codestream complies.\n"); fprintf(stdout," Activates the JPWL correction capability, if the codestream complies.\n");
@ -144,13 +145,14 @@ void decode_help_display(void) {
fprintf(stdout," numcomps is the number of expected components in the codestream\n"); fprintf(stdout," numcomps is the number of expected components in the codestream\n");
fprintf(stdout," (search of first EPB rely upon this, default is %d)\n", JPWL_EXPECTED_COMPONENTS); fprintf(stdout," (search of first EPB rely upon this, default is %d)\n", JPWL_EXPECTED_COMPONENTS);
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
fprintf(stdout,"\n"); fprintf(stdout,"\n");
} }
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
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;
@ -158,12 +160,12 @@ int get_num_images(char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 0; return 0;
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
num_images++; num_images++;
@ -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;
@ -179,14 +182,14 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
/*Reading the input images from given input directory*/ /*Reading the input images from given input directory*/
dir= opendir(imgdirpath); dir= opendir(imgdirpath);
if(!dir){ if(!dir) {
fprintf(stderr,"Could not open Folder %s\n",imgdirpath); fprintf(stderr,"Could not open Folder %s\n",imgdirpath);
return 1; return 1;
}else { } else {
fprintf(stderr,"Folder opened successfully\n"); fprintf(stderr,"Folder opened successfully\n");
} }
while((content=readdir(dir))!=NULL){ while((content=readdir(dir))!=NULL) {
if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 )
continue; continue;
@ -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]="";
@ -229,11 +234,11 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparamet
/*Set output file*/ /*Set output file*/
strcpy(temp_ofname,strtok(image_filename,".")); strcpy(temp_ofname,strtok(image_filename,"."));
while((temp_p = strtok(NULL,".")) != NULL){ while((temp_p = strtok(NULL,".")) != NULL) {
strcat(temp_ofname,temp1); strcat(temp_ofname,temp1);
sprintf(temp1,".%s",temp_p); sprintf(temp1,".%s",temp_p);
} }
if(img_fol->set_out_format==1){ if(img_fol->set_out_format==1) {
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
strncpy(parameters->outfile, outfilename, sizeof(outfilename)); strncpy(parameters->outfile, outfilename, sizeof(outfilename));
} }
@ -241,21 +246,22 @@ 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[]= {
{"ImgDir",REQ_ARG, NULL ,'y'}, {"ImgDir",REQ_ARG, NULL ,'y'},
{"OutFor",REQ_ARG, NULL ,'O'}, {"OutFor",REQ_ARG, NULL ,'O'},
}; };
const char optlist[] = "i:o:r:l:x:" const char optlist[] = "i:o:r:l:x:"
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
"W:" "W:"
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
"h" ; "h" ;
totlen=sizeof(long_option); totlen=sizeof(long_option);
img_fol->set_out_format = 0; img_fol->set_out_format = 0;
@ -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, ",");
@ -455,7 +453,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
} }
break; break;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
/* ----------------------------------------------------- */ /* ----------------------------------------------------- */
@ -463,24 +461,24 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i
fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg); fprintf(stderr,"WARNING -> this option is not valid \"-%c %s\"\n",c, opj_optarg);
break; break;
} }
}while(c != -1); } while(c != -1);
/* check for possible errors */ /* check for possible errors */
if(img_fol->set_imgdir==1){ if(img_fol->set_imgdir==1) {
if(!(parameters->infile[0]==0)){ if(!(parameters->infile[0]==0)) {
fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n");
return 1; return 1;
} }
if(img_fol->set_out_format == 0){ if(img_fol->set_out_format == 0) {
fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n"); fprintf(stderr, "Error: When -ImgDir is used, -OutFor <FORMAT> must be used !!\n");
fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n"); fprintf(stderr, "Only one format allowed! Valid format PGM, PPM, PNM, PGX, BMP, TIF, RAW and TGA!!\n");
return 1; return 1;
} }
if(!((parameters->outfile[0] == 0))){ if(!((parameters->outfile[0] == 0))) {
fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n");
return 1; return 1;
} }
}else{ } else {
if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) {
fprintf(stderr, "Example: %s -i image.j2k -o image.pgm\n",argv[0]); fprintf(stderr, "Example: %s -i image.j2k -o image.pgm\n",argv[0]);
fprintf(stderr, " Try: %s -h\n",argv[0]); fprintf(stderr, " Try: %s -h\n",argv[0]);
@ -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 */
@ -552,29 +554,29 @@ int main(int argc, char **argv) {
} }
/* Initialize reading of directory */ /* Initialize reading of directory */
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
num_images=get_num_images(img_fol.imgdirpath); num_images=get_num_images(img_fol.imgdirpath);
dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); dirptr=(dircnt_t*)malloc(sizeof(dircnt_t));
if(dirptr){ if(dirptr) {
dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images*sizeof(char*)); dirptr->filename = (char**) malloc(num_images*sizeof(char*));
if(!dirptr->filename_buf){ if(!dirptr->filename_buf) {
return 1; return 1;
} }
for(i=0;i<num_images;i++){ for(i=0; i<num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; dirptr->filename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN;
} }
} }
if(load_images(dirptr,img_fol.imgdirpath)==1){ if(load_images(dirptr,img_fol.imgdirpath)==1) {
return 1; return 1;
} }
if (num_images==0){ if (num_images==0) {
fprintf(stdout,"Folder is empty\n"); fprintf(stdout,"Folder is empty\n");
return 1; return 1;
} }
}else{ } else {
num_images=1; num_images=1;
} }
@ -583,7 +585,7 @@ int main(int argc, char **argv) {
image = NULL; image = NULL;
fprintf(stderr,"\n"); fprintf(stderr,"\n");
if(img_fol.set_imgdir==1){ if(img_fol.set_imgdir==1) {
if (get_next_file(imageno, dirptr,&img_fol, &parameters)) { if (get_next_file(imageno, dirptr,&img_fol, &parameters)) {
fprintf(stderr,"skipping file...\n"); fprintf(stderr,"skipping file...\n");
continue; continue;
@ -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,69 +770,62 @@ 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;
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;
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;
#ifdef OPJ_HAVE_LIBTIFF #ifdef OPJ_HAVE_LIBTIFF
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;
#endif /* OPJ_HAVE_LIBTIFF */ #endif /* OPJ_HAVE_LIBTIFF */
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;
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;
#ifdef OPJ_HAVE_LIBPNG #ifdef OPJ_HAVE_LIBPNG
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;
#endif /* OPJ_HAVE_LIBPNG */ #endif /* OPJ_HAVE_LIBPNG */
/* Can happen if output file is TIFF or PNG /* Can happen if output 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
*/ */
default: default:
fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); fprintf(stderr,"Outfile %s not generated\n",parameters.outfile);
} }

View File

@ -106,14 +106,14 @@
*/ */
#if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H) #if !defined(HAVE_DIRENT_H) && !defined(HAVE_DIRECT_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_NDIR_H) && !defined(HAVE_DIR_H)
# if defined(_MSC_VER) /* Microsoft C/C++ */ # if defined(_MSC_VER) /* Microsoft C/C++ */
/* no dirent.h */ /* no dirent.h */
# elif defined(__MINGW32__) /* MinGW */ # elif defined(__MINGW32__) /* MinGW */
/* no dirent.h */ /* no dirent.h */
# elif defined(__BORLANDC__) /* Borland C/C++ */ # elif defined(__BORLANDC__) /* Borland C/C++ */
# define HAVE_DIRENT_H # define HAVE_DIRENT_H
# define VOID_CLOSEDIR # define VOID_CLOSEDIR
# elif defined(__TURBOC__) /* Borland Turbo C */ # elif defined(__TURBOC__) /* Borland Turbo C */
/* no dirent.h */ /* no dirent.h */
# elif defined(__WATCOMC__) /* Watcom C/C++ */ # elif defined(__WATCOMC__) /* Watcom C/C++ */
# define HAVE_DIRECT_H # define HAVE_DIRECT_H
# elif defined(__apollo) /* Apollo */ # elif defined(__apollo) /* Apollo */
@ -172,7 +172,7 @@
#elif defined(MSDOS) || defined(WIN32) #elif defined(MSDOS) || defined(WIN32)
/* figure out type of underlaying directory interface to be used */ /* figure out type of underlaying directory interface to be used */
# if defined(WIN32) # if defined(WIN32)
# define DIRENT_WIN32_INTERFACE # define DIRENT_WIN32_INTERFACE
# elif defined(MSDOS) # elif defined(MSDOS)
@ -181,7 +181,7 @@
# error "missing native dirent interface" # error "missing native dirent interface"
# endif # endif
/*** WIN32 specifics ***/ /*** WIN32 specifics ***/
# if defined(DIRENT_WIN32_INTERFACE) # if defined(DIRENT_WIN32_INTERFACE)
# include <windows.h> # include <windows.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -189,11 +189,11 @@
# endif # endif
/*** MS-DOS specifics ***/ /*** MS-DOS specifics ***/
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# include <dos.h> # include <dos.h>
/* Borland defines file length macros in dir.h */ /* Borland defines file length macros in dir.h */
# if defined(__BORLANDC__) # if defined(__BORLANDC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -203,7 +203,7 @@
# define _find_t find_t # define _find_t find_t
# endif # endif
/* Turbo C defines ffblk structure in dir.h */ /* Turbo C defines ffblk structure in dir.h */
# elif defined(__TURBOC__) # elif defined(__TURBOC__)
# include <dir.h> # include <dir.h>
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
@ -211,13 +211,13 @@
# endif # endif
# define DIRENT_USE_FFBLK # define DIRENT_USE_FFBLK
/* MSVC */ /* MSVC */
# elif defined(_MSC_VER) # elif defined(_MSC_VER)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# define DIRENT_MAXNAMLEN (12) # define DIRENT_MAXNAMLEN (12)
# endif # endif
/* Watcom */ /* Watcom */
# elif defined(__WATCOMC__) # elif defined(__WATCOMC__)
# if !defined(DIRENT_MAXNAMLEN) # if !defined(DIRENT_MAXNAMLEN)
# if defined(__OS2__) || defined(__NT__) # if defined(__OS2__) || defined(__NT__)
@ -230,7 +230,7 @@
# endif # endif
# endif # endif
/*** generic MS-DOS and MS-Windows stuff ***/ /*** generic MS-DOS and MS-Windows stuff ***/
# if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN) # if !defined(NAME_MAX) && defined(DIRENT_MAXNAMLEN)
# define NAME_MAX DIRENT_MAXNAMLEN # define NAME_MAX DIRENT_MAXNAMLEN
# endif # endif
@ -239,7 +239,7 @@
# endif # endif
/* /*
* Substitute for real dirent structure. Note that `d_name' field is a * Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation * true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name' * dependent data. We could save some memory if we had declared `d_name'
@ -248,7 +248,7 @@
* something other than four. Besides, directory entries are typically so * something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place. * small that it takes virtually no time to copy them from place to place.
*/ */
typedef struct dirent { typedef struct dirent {
char d_name[NAME_MAX + 1]; char d_name[NAME_MAX + 1];
/*** Operating system specific part ***/ /*** Operating system specific part ***/
@ -261,11 +261,11 @@
struct _find_t data; struct _find_t data;
# endif # endif
# endif # endif
} dirent; } dirent;
/* DIR substitute structure containing directory name. The name is /* DIR substitute structure containing directory name. The name is
* essential for the operation of ``rewinndir'' function. */ * essential for the operation of ``rewinndir'' function. */
typedef struct DIR { typedef struct DIR {
char *dirname; /* directory being scanned */ char *dirname; /* directory being scanned */
dirent current; /* current entry */ dirent current; /* current entry */
int dirent_filled; /* is current un-processed? */ int dirent_filled; /* is current un-processed? */
@ -275,7 +275,7 @@
HANDLE search_handle; HANDLE search_handle;
# elif defined(DIRENT_MSDOS_INTERFACE) # elif defined(DIRENT_MSDOS_INTERFACE)
# endif # endif
} DIR; } DIR;
# ifdef __cplusplus # ifdef __cplusplus
extern "C" { extern "C" {
@ -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,8 +374,9 @@ 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.
This function supports the top level of the file, but uuid may be elsewhere [not yet supported]. This function supports the top level of the file, but uuid may be elsewhere [not yet supported].
@ -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);
@ -615,7 +614,7 @@ void xml_write_mdia(FILE* file, FILE* xmlout, mj2_tk_t *track, unsigned int tnum
fprintf(xmlout," <!-- 0x00 = copy (over existing image); -->\n"); fprintf(xmlout," <!-- 0x00 = copy (over existing image); -->\n");
fprintf(xmlout," <!-- 0x24 = transparent; 'blue-screen' this image using opcolor; -->\n"); fprintf(xmlout," <!-- 0x24 = transparent; 'blue-screen' this image using opcolor; -->\n");
fprintf(xmlout," <!-- 0x100 = alpha; alpha-blend this image -->\n"); fprintf(xmlout," <!-- 0x100 = alpha; alpha-blend this image -->\n");
/* fprintf(xmlout," <!-- 0x101 = whitealpha; alpha-blend this image, which has been blended with white; -->\n"); This was evidently dropped upon amendment */ /* fprintf(xmlout," <!-- 0x101 = whitealpha; alpha-blend this image, which has been blended with white; -->\n"); This was evidently dropped upon amendment */
fprintf(xmlout," <!-- 0x102 = pre-multiplied black alpha; image has been already been alpha-blended with black. -->\n"); fprintf(xmlout," <!-- 0x102 = pre-multiplied black alpha; image has been already been alpha-blended with black. -->\n");
fprintf(xmlout," <!-- 0x110 = component alpha; blend alpha channel(s) and color channels individually. -->\n"); fprintf(xmlout," <!-- 0x110 = component alpha; blend alpha channel(s) and color channels individually. -->\n");
} }
@ -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);
} }
@ -1135,16 +1131,17 @@ void xml_out_frame_siz(FILE* xmlout, opj_image_t *img, opj_cp_t *cp)
void xml_out_frame_cod(FILE* xmlout, opj_tcp_t *tcp) void xml_out_frame_cod(FILE* xmlout, opj_tcp_t *tcp)
{ {
/* Could be called with tcp = &j2k_default_tcp; /* Could be called with tcp = &j2k_default_tcp;
/* Or, for tile-part header, with &j2k_cp->tcps[j2k_curtileno] /* Or, for tile-part header, with &j2k_cp->tcps[j2k_curtileno]
/* Alignment for main:" < < < < To help maintain xml pretty-printing */ /* Alignment for main:" < < < < To help maintain xml pretty-printing */
/* Alignment for tile:" < < < To help maintain xml pretty-printing */ /* Alignment for tile:" < < < To help maintain xml pretty-printing */
opj_tccp_t *tccp; opj_tccp_t *tccp;
int i; int 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 */
} }
tccp = &(tcp->tccps[0]); tccp = &(tcp->tccps[0]);
@ -1219,13 +1216,14 @@ void xml_out_frame_cod(FILE* xmlout, opj_tcp_t *tcp)
void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional in main & tile-part headers */ void xml_out_frame_coc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) /* Optional in main & tile-part headers */
{ {
/* Uses global j2k_default_tcp */ /* Uses global j2k_default_tcp */
opj_tccp_t *tccp, *firstcomp_tccp; opj_tccp_t *tccp, *firstcomp_tccp;
int i, compno; int i, compno;
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,13 +1239,12 @@ 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;
/* Alignments: " < < < < < To help maintain xml pretty-printing */ /* Alignments: " < < < < < To help maintain xml pretty-printing */
fprintf(xmlout, "%s<CodingStyleComponent Marker=\"COC\">\n", s); /* Optional in main header, at most 1 per component */ fprintf(xmlout, "%s<CodingStyleComponent Marker=\"COC\">\n", s); /* Optional in main header, at most 1 per component */
if(notes) if(notes)
fprintf(xmlout, "%s <!-- See Ccoc below for zero-based component number. -->\n", s); fprintf(xmlout, "%s <!-- See Ccoc below for zero-based component number. -->\n", s);
@ -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 */
@ -1462,14 +1460,14 @@ void xml_out_frame_qcd(FILE* xmlout, opj_tcp_t *tcp)
fprintf(xmlout, "%s </SPqcd>\n", s); fprintf(xmlout, "%s </SPqcd>\n", s);
fprintf(xmlout, "%s</QuantizationDefault>\n", s); fprintf(xmlout, "%s</QuantizationDefault>\n", s);
/* Alignments: " < < < < < To help maintain xml pretty-printing */ /* Alignments: " < < < < < To help maintain xml pretty-printing */
} }
/* ------------- */ /* ------------- */
void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps) void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
{ {
/* Uses global j2k_default_tcp */ /* Uses global j2k_default_tcp */
/* This code will compile only if declaration of j2k_default_tcp is changed from static (to implicit extern) in j2k.c */ /* This code will compile only if declaration of j2k_default_tcp is changed from static (to implicit extern) in j2k.c */
opj_tccp_t *tccp, *firstcomp_tccp; opj_tccp_t *tccp, *firstcomp_tccp;
int bandno, numbands; int bandno, numbands;
@ -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;
@ -1608,7 +1606,7 @@ void xml_out_frame_qcc(FILE* xmlout, opj_tcp_t *tcp, int numcomps)
fprintf(xmlout, "%s </SPqcc>\n", s); fprintf(xmlout, "%s </SPqcc>\n", s);
fprintf(xmlout, "%s</QuantizationComponent>\n", s); fprintf(xmlout, "%s</QuantizationComponent>\n", s);
} }
/* Alignments: " < < < < < To help maintain xml pretty-printing */ /* Alignments: " < < < < < To help maintain xml pretty-printing */
} }
/* ------------- */ /* ------------- */
@ -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,15 +1740,16 @@ 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 */ {
/* Use of PPM and PPT are mutually exclusive. */ /* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Compare j2k_read_ppm() */ /* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppm() */
int j; int j;
if(cp->ppm != 1) if(cp->ppm != 1)
return; /* Not present */ return; /* Not present */
/* Main header uses indent of 10 spaces */ /* Main header uses indent of 10 spaces */
fprintf(xmlout, " <PackedPacketHeadersMainHeader Marker=\"PPM\">\n"); /* Optional in main header, but if not, must be in PPT or codestream */ fprintf(xmlout, " <PackedPacketHeadersMainHeader Marker=\"PPM\">\n"); /* Optional in main header, but if not, must be in PPT or codestream */
/* 2 bytes Lppm not saved */ /* 2 bytes Lppm not saved */
if(notes) { if(notes) {
@ -1770,10 +1772,11 @@ 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 */ {
/* Use of PPM and PPT are mutually exclusive. */ /* Either the PPM or PPT is required if the packet headers are not distributed in the bit stream */
/* Compare j2k_read_ppt() */ /* Use of PPM and PPT are mutually exclusive. */
/* Compare j2k_read_ppt() */
int j; int j;
if(tcp->ppt != 1) if(tcp->ppt != 1)
@ -1803,41 +1806,47 @@ 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! */ {
/* Plan: Since this is only called from main header, not tilepart, use global j2k_default_tcp rather than parameter */ /* Compare j2k_read_tlm()... which doesn't retain anything! */
/* Main header indents are 10 spaces */ /* 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 */
} }
/* ------------- */ /* ------------- */
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 */
/* Main header indents are 10 spaces */ /* Main header indents are 10 spaces */
} }
/* ------------- */ /* ------------- */
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 */
} }
/* ------------- */ /* ------------- */
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)
/* 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 */ /* NO-OP. CRG NOT SAVED IN DATA STRUCTURE */ /* opt, main header only; */
/* 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 */
#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 */
/* Main header indents are 10 spaces */ /* Main header indents are 10 spaces */
fprintf(xmlout, " <ComponentRegistration Marker=\"RG\" Count=\"%d\">\n", j2k_default_tcp->crg_i); fprintf(xmlout, " <ComponentRegistration Marker=\"RG\" Count=\"%d\">\n", j2k_default_tcp->crg_i);
if(notes) { if(notes) {
fprintf(xmlout, " <!-- Fine tuning of registration of components with respect to each other, -->\n"); fprintf(xmlout, " <!-- Fine tuning of registration of components with respect to each other, -->\n");
@ -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)
/* Compare j2k_read_com()... which doesn't retain anything! */ {
/* NO-OP. COM NOT SAVED IN DATA STRUCTURE */ /* opt in main or tile-part headers; */
/* 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,13 +1959,14 @@ 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;
fprintf(xmlout, " <JP2Header BoxType=\"jp2h\">\n"); fprintf(xmlout, " <JP2Header BoxType=\"jp2h\">\n");
/* Compare jp2_read_ihdr(jp2_struct)) */ /* Compare jp2_read_ihdr(jp2_struct)) */
fprintf(xmlout, " <ImageHeader BoxType=\"ihdr\">\n"); fprintf(xmlout, " <ImageHeader BoxType=\"ihdr\">\n");
fprintf(xmlout, " <HEIGHT>%d</HEIGHT>\n", jp2_struct->h); /* 4 bytes */ fprintf(xmlout, " <HEIGHT>%d</HEIGHT>\n", jp2_struct->h); /* 4 bytes */
fprintf(xmlout, " <WIDTH>%d</WIDTH>\n", jp2_struct->w); /* 4 bytes */ fprintf(xmlout, " <WIDTH>%d</WIDTH>\n", jp2_struct->w); /* 4 bytes */
@ -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.
@ -2082,10 +2096,11 @@ void xml_out_frame_xml(FILE* xmlout, opj_cp_t *cp) {
worse for cut/paste. Being lazy, didn't indent here. */ worse for cut/paste. Being lazy, didn't indent here. */
fprintf(xmlout,cp->xml_data[i]); /* May be multiple lines */ /* Could check if this is well-formed */ fprintf(xmlout,cp->xml_data[i]); /* May be multiple lines */ /* Could check if this is well-formed */
fprintf(xmlout, " </TextFormXML>\n"); fprintf(xmlout, " </TextFormXML>\n");
} }
} }
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. */
@ -2113,9 +2128,9 @@ void xml_out_frame_uuid(FILE* xmlout, opj_cp_t *cp) {
fprintf(xmlout, " </Data>\n"); fprintf(xmlout, " </Data>\n");
fprintf(xmlout, " </UniversalUniqueID>\n"); fprintf(xmlout, " </UniversalUniqueID>\n");
} }
} }
void xml_out_frame_uinf(FILE* xmlout, opj_cp_t *cp) { void xml_out_frame_uinf(FILE* xmlout, opj_cp_t *cp) {
/* UUIDInfo 'uinf', includes UUIDList 'ulst' and URL 'url\40' */ /* UUIDInfo 'uinf', includes UUIDList 'ulst' and URL 'url\40' */
/* Part I 1.7.3 says: may appear multiply in JP2 file, anywhere at the top level except before File Type box */ /* Part I 1.7.3 says: may appear multiply in JP2 file, anywhere at the top level except before File Type box */
/* So there may be multiple ulst's, and each can have multiple UUIDs listed (with a single URL) */ /* So there may be multiple ulst's, and each can have multiple UUIDs listed (with a single URL) */
@ -2144,10 +2159,10 @@ void xml_out_frame_uinf(FILE* xmlout, opj_cp_t *cp) {
fprintf(xmlout, " </DataEntryURL>\n"); fprintf(xmlout, " </DataEntryURL>\n");
fprintf(xmlout, " </UUIDInfo>\n"); fprintf(xmlout, " </UUIDInfo>\n");
} }
} }
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_unknown_type(FILE* xmlout, opj_cp_t *cp) { void xml_out_frame_unknown_type(FILE* xmlout, opj_cp_t *cp) {
/* Part III 5.2.1 says "Type fields not defined here are reserved. Private extensions /* Part III 5.2.1 says "Type fields not defined here are reserved. Private extensions
shall be acieved through the 'uuid' type." [This implies an unknown shall be acieved through the 'uuid' type." [This implies an unknown
type would be an error, but then...] "Boxes not explicitly defined in this standard, type would be an error, but then...] "Boxes not explicitly defined in this standard,
@ -2176,6 +2191,6 @@ void xml_out_frame_unknown_type(FILE* xmlout, opj_cp_t *cp) {
xml_out_dump_hex_and_ascii(xmlout, cp->unknown_type_data[i], cp->unknown_type_len[i]); xml_out_dump_hex_and_ascii(xmlout, cp->unknown_type_data[i], cp->unknown_type_len[i]);
fprintf(xmlout, " </UnknownType>\n"); fprintf(xmlout, " </UnknownType>\n");
} }
} }
#endif #endif

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,13 +110,14 @@ 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 */
FILE *file, *xmlout; FILE *file, *xmlout;
/* char xmloutname[50]; */ /* char xmloutname[50]; */
opj_mj2_t *movie; opj_mj2_t *movie;
char* infile = 0; char* infile = 0;
@ -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--;
@ -236,16 +244,15 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
/* was: /* was:
if (argc != 3) { if (argc != 3) {
printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n"); printf("Bad syntax: Usage: MJ2_to_metadata inputfile.mj2 outputfile.xml\n");
printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n"); printf("Example: MJ2_to_metadata foreman.mj2 foreman.xml\n");
return 1; return 1;
} }
*/ */
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);
} }
@ -257,10 +259,10 @@ int main(int argc, char **argv)
mj2_parameters.enumcs = ENUMCS_SYCC; /* FIXME: ENUMCS_YUV420 */ mj2_parameters.enumcs = ENUMCS_SYCC; /* FIXME: ENUMCS_YUV420 */
mj2_parameters.meth = 1; /* enumerated color space */ mj2_parameters.meth = 1; /* enumerated color space */
/* /*
configure the event callbacks (not required) configure the event callbacks (not required)
setting of each callback is optionnal setting of each callback is optionnal
*/ */
memset(&event_mgr, 0, sizeof(opj_event_mgr_t)); memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = error_callback; event_mgr.error_handler = error_callback;
event_mgr.warning_handler = warning_callback; event_mgr.warning_handler = warning_callback;
@ -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;
} }
@ -702,8 +687,8 @@ int main(int argc, char **argv)
return 1; return 1;
} }
/* Writing JP, FTYP and MDAT boxes */ /* Writing JP, FTYP and MDAT boxes */
/* Assuming that the JP and FTYP boxes won't be longer than 300 bytes:*/ /* Assuming that the JP and FTYP boxes won't be longer than 300 bytes:*/
buf = (unsigned char*) buf = (unsigned char*)
malloc (300 * sizeof(unsigned char)); malloc (300 * sizeof(unsigned char));
@ -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,19 +727,17 @@ 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;
} }
/* setup the encoder parameters using the current image and user parameters */ /* setup the encoder parameters using the current image and user parameters */
opj_setup_encoder(cinfo, j2k_parameters, img); opj_setup_encoder(cinfo, j2k_parameters, img);
cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, buflen); cio = opj_cio_open((opj_common_ptr)movie->cinfo, buf, buflen);
@ -766,7 +745,7 @@ int main(int argc, char **argv)
cio_skip(cio, 4); cio_skip(cio, 4);
cio_write(cio, JP2_JP2C, 4); /* JP2C*/ cio_write(cio, JP2_JP2C, 4); /* JP2C*/
/* encode the image */ /* encode the image */
bSuccess = opj_encode(cinfo, cio, img, NULL); bSuccess = opj_encode(cinfo, cio, img, NULL);
if (!bSuccess) { if (!bSuccess) {
@ -801,14 +780,14 @@ int main(int argc, char **argv)
buf = (unsigned char*) malloc(4*sizeof(unsigned char)); buf = (unsigned char*) malloc(4*sizeof(unsigned char));
/* Init a cio to write box length variable in a little endian way */ /* Init a cio to write box length variable in a little endian way */
cio = opj_cio_open(NULL, buf, 4); cio = opj_cio_open(NULL, buf, 4);
cio_write(cio, offset - mdat_initpos, 4); cio_write(cio, offset - mdat_initpos, 4);
fwrite(buf, 4, 1, mj2file); fwrite(buf, 4, 1, mj2file);
fseek(mj2file,0,SEEK_END); fseek(mj2file,0,SEEK_END);
free(buf); free(buf);
/* Writing MOOV box */ /* Writing MOOV box */
buf = (unsigned char*) buf = (unsigned char*)
malloc ((TEMP_BUF+numframes*20) * sizeof(unsigned char)); malloc ((TEMP_BUF+numframes*20) * sizeof(unsigned char));
cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+numframes*20)); cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+numframes*20));
@ -822,7 +801,7 @@ int main(int argc, char **argv)
/* Ending program */ /* Ending program */
fclose(mj2file); fclose(mj2file);
/* free remaining compression structures */ /* free remaining compression structures */
mj2_destroy_compress(movie); mj2_destroy_compress(movie);
free(cinfo); free(cinfo);

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

@ -181,16 +181,26 @@ class OPJChildFrame;
class OPJViewerApp: public wxApp class OPJViewerApp: public wxApp
{ {
// public methods and variables // public methods and variables
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
@ -245,7 +255,7 @@ class OPJViewerApp: public wxApp
wxConfig *OPJconfig; wxConfig *OPJconfig;
// private methods and variables // private methods and variables
private: private:
bool m_showImages, m_showButtons; bool m_showImages, m_showButtons;
}; };
@ -258,14 +268,15 @@ DECLARE_APP(OPJViewerApp)
class OPJCanvas: public wxScrolledWindow class OPJCanvas: public wxScrolledWindow
{ {
// public methods and variables // public methods and variables
public: public:
// class constructor // class constructor
OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size); OPJCanvas(wxFileName fname, wxWindow *parent, const wxPoint& pos, const wxSize& size);
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__
@ -296,19 +307,29 @@ class OPJCanvas: public wxScrolledWindow
class OPJMarkerData : public wxTreeItemData class OPJMarkerData : public wxTreeItemData
{ {
// public methods and variables // public methods and variables
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;
// private methods and variables // private methods and variables
private: private:
wxString m_filestring; wxString m_filestring;
}; };
@ -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,
@ -329,9 +349,14 @@ public:
OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id, OPJMarkerTree(wxWindow *parent, OPJChildFrame *subframe, wxFileName fname, wxString name, const wxWindowID id,
const wxPoint& pos, const wxSize& size, const wxPoint& pos, const wxSize& size,
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);*/
@ -416,7 +447,7 @@ WX_DECLARE_HASH_MAP(int, OPJChildFrame*, wxIntegerHash, wxIntegerEqual, OPJChild
// Define a new frame // Define a new frame
class OPJFrame: public wxMDIParentFrame class OPJFrame: public wxMDIParentFrame
{ {
public: public:
OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); OPJFrame(wxWindow *parent, const wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
@ -465,7 +496,7 @@ class OPJFrame: public wxMDIParentFrame
wxNotebook *m_bookCtrlbottom; wxNotebook *m_bookCtrlbottom;
wxTextCtrl *m_textCtrlbrowse; wxTextCtrl *m_textCtrlbrowse;
private: private:
void TogStyle(int id, long flag); void TogStyle(int id, long flag);
void DoSort(bool reverse = false); void DoSort(bool reverse = false);
@ -479,12 +510,12 @@ protected:
wxSashLayoutWindow* m_topWindow; wxSashLayoutWindow* m_topWindow;
wxSashLayoutWindow* m_leftWindow2; wxSashLayoutWindow* m_leftWindow2;
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
class OPJChildFrame: public wxMDIChildFrame class OPJChildFrame: public wxMDIChildFrame
{ {
public: public:
OPJCanvas *m_canvas; OPJCanvas *m_canvas;
OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style); OPJChildFrame(OPJFrame *parent, wxFileName fname, int winnumber, const wxString& title, const wxPoint& pos, const wxSize& size, const long style);
~OPJChildFrame(void); ~OPJChildFrame(void);
@ -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:
@ -678,7 +711,7 @@ private:
// Property sheet dialog: encoder // Property sheet dialog: encoder
class OPJEncoderDialog: public wxPropertySheetDialog class OPJEncoderDialog: public wxPropertySheetDialog
{ {
DECLARE_CLASS(OPJEncoderDialog) DECLARE_CLASS(OPJEncoderDialog)
public: public:
OPJEncoderDialog(wxWindow* parent, int dialogType); OPJEncoderDialog(wxWindow* parent, int dialogType);
~OPJEncoderDialog(); ~OPJEncoderDialog();
@ -688,7 +721,7 @@ public:
wxPanel* CreateMainSettingsPage(wxWindow* parent); wxPanel* CreateMainSettingsPage(wxWindow* parent);
wxPanel* CreatePart1_1SettingsPage(wxWindow* parent); wxPanel* CreatePart1_1SettingsPage(wxWindow* parent);
wxPanel* CreatePart1_2SettingsPage(wxWindow* parent); wxPanel* CreatePart1_2SettingsPage(wxWindow* parent);
/* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/ /* wxPanel* CreatePart3SettingsPage(wxWindow* parent);*/
void OnEnableComm(wxCommandEvent& event); void OnEnableComm(wxCommandEvent& event);
void OnEnableIdx(wxCommandEvent& event); void OnEnableIdx(wxCommandEvent& event);
void OnEnablePoc(wxCommandEvent& event); void OnEnablePoc(wxCommandEvent& event);
@ -763,13 +796,13 @@ protected:
OPJENCO_STILE OPJENCO_STILE
}; };
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// Property sheet dialog: decoder // Property sheet dialog: decoder
class OPJDecoderDialog: public wxPropertySheetDialog class OPJDecoderDialog: public wxPropertySheetDialog
{ {
DECLARE_CLASS(OPJDecoderDialog) DECLARE_CLASS(OPJDecoderDialog)
public: public:
OPJDecoderDialog(wxWindow* parent, int dialogType); OPJDecoderDialog(wxWindow* parent, int dialogType);
~OPJDecoderDialog(); ~OPJDecoderDialog();
@ -808,7 +841,7 @@ protected:
OPJDECO_FRAMENUM OPJDECO_FRAMENUM
}; };
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
#endif //__OPJ_VIEWER_H__ #endif //__OPJ_VIEWER_H__

View File

@ -1,54 +1,54 @@
wxString htmlaboutpage = wxT( wxString htmlaboutpage = wxT(
"<html>" "<html>"
"<body bgcolor=#FFFFFF>" "<body bgcolor=#FFFFFF>"
"<table cellspacing=7 cellpadding=1 border=0 width=100%>" "<table cellspacing=7 cellpadding=1 border=0 width=100%>"
"<tr>" "<tr>"
"<td rowspan=3 valign=top align=center width=70>" "<td rowspan=3 valign=top align=center width=70>"
"<img src=\"memory:opj_logo.xpm\"><br><br>" "<img src=\"memory:opj_logo.xpm\"><br><br>"
"</td>" "</td>"
"<td align=center>" "<td align=center>"
"<font size=+0 color=#000000><b>" "<font size=+0 color=#000000><b>"
OPJ_APPLICATION " " OPJ_APPLICATION_VERSION OPJ_APPLICATION " " OPJ_APPLICATION_VERSION
"</b></font><br>" "</b></font><br>"
"<font size=-1 color=#000000><b>A JPEG 2000 image viewer</b></font><br>" "<font size=-1 color=#000000><b>A JPEG 2000 image viewer</b></font><br>"
"<font size=-2 color=#000000><b>" OPJ_APPLICATION_PLATFORM " version</b></font>" "<font size=-2 color=#000000><b>" OPJ_APPLICATION_PLATFORM " version</b></font>"
"</td>" "</td>"
"</tr>" "</tr>"
"<tr height=3 valign=center>" "<tr height=3 valign=center>"
"<td valign=center bgcolor=#cc3300></td>" "<td valign=center bgcolor=#cc3300></td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td align=justify>" "<td align=justify>"
"<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>" "<center><font size=+0 color=#000000><a href=\"http://www.openjpeg.org/\">OpenJPEG</a></font></center>"
"<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. " "<p><font size=-1 color=#000000>The OpenJPEG library is an open-source JPEG 2000 codec written in C language. "
"In addition to the basic codec, various other features are under development.</font></p><br>" "In addition to the basic codec, various other features are under development.</font></p><br>"
"<font size=-2 color=red>* Build: ") "<font size=-2 color=red>* Build: ")
#include "build.h" #include "build.h"
wxT(", " __DATE__ ", " __TIME__ "</font><br>") wxT(", " __DATE__ ", " __TIME__ "</font><br>")
wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>") wxT("<font size=-2 color=red>* " wxVERSION_STRING "</font><br>")
wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (") wxT("<font size=-2 color=red>* OpenJPEG " OPENJPEG_VERSION " (")
#ifdef USE_JPWL #ifdef USE_JPWL
wxT("<font size=-2 color=green>JPWL</font> ") wxT("<font size=-2 color=green>JPWL</font> ")
#endif // USE_JPWL #endif // USE_JPWL
#ifdef USE_JPSEC #ifdef USE_JPSEC
wxT("<font size=-2 color=green>JPSEC</font> ") wxT("<font size=-2 color=green>JPSEC</font> ")
#endif // USE_JPSEC #endif // USE_JPSEC
wxT(")</font><br>") wxT(")</font><br>")
#ifdef USE_MXF #ifdef USE_MXF
wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "." MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD ")</font><br>") wxT("<font size=-2 color=red>* MXFLib " MXFLIB_VERSION_MAJOR "." MXFLIB_VERSION_MINOR "." MXFLIB_VERSION_TWEAK " (" MXFLIB_VERSION_BUILD ")</font><br>")
#endif // USE_MXF #endif // USE_MXF
wxT("</td>" wxT("</td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>" "<td colspan=2 bgcolor=#CC3300 height=3 valign=center></td>"
"</tr>" "</tr>"
"<tr>" "<tr>"
"<td colspan=2>" "<td colspan=2>"
"<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>" "<font size=-2 color=#444444>OpenJPEG is &copy; 2002-2008 <a href=\"http://www.tele.ucl.ac.be/\">TELE</a> - <a href=\"http://www.uclouvain.be/\">Universite' Catholique de Louvain</a></font><br>"
"<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>" "<font size=-2 color=#444444>OPJViewer is &copy; 2007-2008 <a href=\"http://dsplab.diei.unipg.it/\">DSPLab</a> - <a href=\"http://www.unipg.it/\">Universita' degli studi di Perugia</a></font>"
"</td>" "</td>"
"</tr>" "</tr>"
"</table>" "</table>"
"</body>" "</body>"
"</html>" "</html>"
); );

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

@ -61,7 +61,7 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t
lenp = -1; lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
for (i=0;i<2;i++){ for (i=0; i<2; i++) {
if(i) if(i)
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
@ -158,8 +158,8 @@ void opj_write_manf(int second,
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */ opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
if (second){ /* Write only during the second pass */ if (second) { /* Write only during the second pass */
for( i=0; i<v; i++){ for( i=0; i<v; i++) {
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */ opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */ opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
@ -191,7 +191,7 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr
opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */ opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */
opj_stream_write_data(cio,l_data_header,8,p_manager); opj_stream_write_data(cio,l_data_header,8,p_manager);
for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */ for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++) { /* Marker restricted to 1 apparition, skip SOC marker */
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2); opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2); opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
@ -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

@ -60,7 +60,7 @@ void opj_write_bytes_LE (OPJ_BYTE * p_buffer, OPJ_UINT32 p_value, OPJ_UINT32 p_n
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
for (i=0;i<p_nb_bytes;++i) { for (i=0; i<p_nb_bytes; ++i) {
*(p_buffer++) = *(l_data_ptr--); *(p_buffer++) = *(l_data_ptr--);
} }
} }
@ -83,7 +83,7 @@ void opj_read_bytes_LE(const OPJ_BYTE * p_buffer, OPJ_UINT32 * p_value, OPJ_UINT
assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32)); assert(p_nb_bytes > 0 && p_nb_bytes <= sizeof(OPJ_UINT32));
*p_value = 0; *p_value = 0;
for (i=0;i<p_nb_bytes;++i) { for (i=0; i<p_nb_bytes; ++i) {
*(l_data_ptr--) = *(p_buffer++); *(l_data_ptr--) = *(p_buffer++);
} }
} }
@ -98,7 +98,7 @@ void opj_write_double_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT64 p_value)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT64) - 1; const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT64) - 1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT64);++i) { for (i=0; i<sizeof(OPJ_FLOAT64); ++i) {
*(p_buffer++) = *(l_data_ptr--); *(p_buffer++) = *(l_data_ptr--);
} }
} }
@ -113,7 +113,7 @@ void opj_read_double_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT64 * p_value)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64)-1; OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT64)-1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT64);++i) { for (i=0; i<sizeof(OPJ_FLOAT64); ++i) {
*(l_data_ptr--) = *(p_buffer++); *(l_data_ptr--) = *(p_buffer++);
} }
} }
@ -128,7 +128,7 @@ void opj_write_float_LE(OPJ_BYTE * p_buffer, OPJ_FLOAT32 p_value)
{ {
const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT32) - 1; const OPJ_BYTE * l_data_ptr = ((const OPJ_BYTE *) &p_value) + sizeof(OPJ_FLOAT32) - 1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT32);++i) { for (i=0; i<sizeof(OPJ_FLOAT32); ++i) {
*(p_buffer++) = *(l_data_ptr--); *(p_buffer++) = *(l_data_ptr--);
} }
} }
@ -143,7 +143,7 @@ void opj_read_float_LE(const OPJ_BYTE * p_buffer, OPJ_FLOAT32 * p_value)
{ {
OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32)-1; OPJ_BYTE * l_data_ptr = ((OPJ_BYTE *) p_value) + sizeof(OPJ_FLOAT32)-1;
OPJ_UINT32 i; OPJ_UINT32 i;
for (i=0;i<sizeof(OPJ_FLOAT32);++i) { for (i=0; i<sizeof(OPJ_FLOAT32); ++i) {
*(l_data_ptr--) = *(p_buffer++); *(l_data_ptr--) = *(p_buffer++);
} }
} }
@ -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

@ -54,19 +54,19 @@ The functions in CIO.C have for goal to realize a byte input / output process.
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
#if defined(OPJ_BIG_ENDIAN) #if defined(OPJ_BIG_ENDIAN)
#define opj_write_bytes opj_write_bytes_BE #define opj_write_bytes opj_write_bytes_BE
#define opj_read_bytes opj_read_bytes_BE #define opj_read_bytes opj_read_bytes_BE
#define opj_write_double opj_write_double_BE #define opj_write_double opj_write_double_BE
#define opj_read_double opj_read_double_BE #define opj_read_double opj_read_double_BE
#define opj_write_float opj_write_float_BE #define opj_write_float opj_write_float_BE
#define opj_read_float opj_read_float_BE #define opj_read_float opj_read_float_BE
#else #else
#define opj_write_bytes opj_write_bytes_LE #define opj_write_bytes opj_write_bytes_LE
#define opj_read_bytes opj_read_bytes_LE #define opj_read_bytes opj_read_bytes_LE
#define opj_write_double opj_write_double_LE #define opj_write_double opj_write_double_LE
#define opj_read_double opj_read_double_LE #define opj_read_double opj_read_double_LE
#define opj_write_float opj_write_float_LE #define opj_write_float opj_write_float_LE
#define opj_read_float opj_read_float_LE #define opj_read_float opj_read_float_LE
#endif #endif
@ -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;
@ -574,7 +591,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
return OPJ_TRUE; return OPJ_TRUE;
} }
h.mem = (OPJ_INT32*)opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32)); h.mem = (OPJ_INT32*)opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32));
if (! h.mem){ if (! h.mem) {
/* FIXME event manager error callback */ /* FIXME event manager error callback */
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -604,7 +621,7 @@ static OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres
v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn); v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn);
v.cas = tr->y0 % 2; v.cas = tr->y0 % 2;
for(j = 0; j < rw; ++j){ for(j = 0; j < rw; ++j) {
OPJ_UINT32 k; OPJ_UINT32 k;
opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w); opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w);
(dwt_1D)(&v); (dwt_1D)(&v);
@ -617,15 +634,16 @@ 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;
for(k = 0; k < 2; ++k){ for(k = 0; k < 2; ++k) {
if ( count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0 ) { if ( count + 3 * x < size && ((size_t) a & 0x0f) == 0 && ((size_t) bi & 0x0f) == 0 && (x & 0x0f) == 0 ) {
/* Fast code path */ /* Fast code path */
for(i = 0; i < count; ++i){ for(i = 0; i < count; ++i) {
OPJ_INT32 j = i; OPJ_INT32 j = i;
bi[i*8 ] = a[j]; bi[i*8 ] = a[j];
j += x; j += x;
@ -635,10 +653,9 @@ 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;
bi[i*8 ] = a[j]; bi[i*8 ] = a[j];
j += x; j += x;
@ -660,29 +677,31 @@ 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;
for(i = 0; i < v->sn; ++i){ for(i = 0; i < v->sn; ++i) {
memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32)); memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32));
} }
a += v->sn * x; a += v->sn * x;
bi = v->wavelet + 1 - v->cas; bi = v->wavelet + 1 - v->cas;
for(i = 0; i < v->dn; ++i){ for(i = 0; i < v->dn; ++i) {
memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32)); memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32));
} }
} }
#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 */
for(i = 0; i < count >> 2; ++i){ for(i = 0; i < count >> 2; ++i) {
*vw = _mm_mul_ps(*vw, c); *vw = _mm_mul_ps(*vw, c);
vw += 2; vw += 2;
*vw = _mm_mul_ps(*vw, c); *vw = _mm_mul_ps(*vw, c);
@ -693,19 +712,20 @@ static void opj_v4dwt_decode_step1_sse(opj_v4_t* w, OPJ_INT32 count, const __m12
vw += 2; vw += 2;
} }
count &= 3; count &= 3;
for(i = 0; i < count; ++i){ for(i = 0; i < count; ++i) {
*vw = _mm_mul_ps(*vw, c); *vw = _mm_mul_ps(*vw, c);
vw += 2; vw += 2;
} }
} }
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;
__m128 tmp1, tmp2, tmp3; __m128 tmp1, tmp2, tmp3;
tmp1 = vl[0]; tmp1 = vl[0];
for(i = 0; i < m; ++i){ for(i = 0; i < m; ++i) {
tmp2 = vw[-1]; tmp2 = vw[-1];
tmp3 = vw[ 0]; tmp3 = vw[ 0];
vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c)); vw[-1] = _mm_add_ps(tmp2, _mm_mul_ps(_mm_add_ps(tmp1, tmp3), c));
@ -713,12 +733,12 @@ void opj_v4dwt_decode_step2_sse(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_INT32
vw += 2; vw += 2;
} }
vl = vw - 2; vl = vw - 2;
if(m >= k){ if(m >= k) {
return; return;
} }
c = _mm_add_ps(c, c); c = _mm_add_ps(c, c);
c = _mm_mul_ps(c, vl[0]); c = _mm_mul_ps(c, vl[0]);
for(; m < k; ++m){ for(; m < k; ++m) {
__m128 tmp = vw[-1]; __m128 tmp = vw[-1];
vw[-1] = _mm_add_ps(tmp, c); vw[-1] = _mm_add_ps(tmp, c);
vw += 2; vw += 2;
@ -731,7 +751,7 @@ static void opj_v4dwt_decode_step1(opj_v4_t* w, OPJ_INT32 count, const OPJ_FLOAT
{ {
OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w; OPJ_FLOAT32* restrict fw = (OPJ_FLOAT32*) w;
OPJ_INT32 i; OPJ_INT32 i;
for(i = 0; i < count; ++i){ for(i = 0; i < count; ++i) {
OPJ_FLOAT32 tmp1 = fw[i*8 ]; OPJ_FLOAT32 tmp1 = fw[i*8 ];
OPJ_FLOAT32 tmp2 = fw[i*8 + 1]; OPJ_FLOAT32 tmp2 = fw[i*8 + 1];
OPJ_FLOAT32 tmp3 = fw[i*8 + 2]; OPJ_FLOAT32 tmp3 = fw[i*8 + 2];
@ -748,7 +768,7 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
OPJ_FLOAT32* fl = (OPJ_FLOAT32*) l; OPJ_FLOAT32* fl = (OPJ_FLOAT32*) l;
OPJ_FLOAT32* fw = (OPJ_FLOAT32*) w; OPJ_FLOAT32* fw = (OPJ_FLOAT32*) w;
OPJ_INT32 i; OPJ_INT32 i;
for(i = 0; i < m; ++i){ for(i = 0; i < m; ++i) {
OPJ_FLOAT32 tmp1_1 = fl[0]; OPJ_FLOAT32 tmp1_1 = fl[0];
OPJ_FLOAT32 tmp1_2 = fl[1]; OPJ_FLOAT32 tmp1_2 = fl[1];
OPJ_FLOAT32 tmp1_3 = fl[2]; OPJ_FLOAT32 tmp1_3 = fl[2];
@ -768,7 +788,7 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
fl = fw; fl = fw;
fw += 8; fw += 8;
} }
if(m < k){ if(m < k) {
OPJ_FLOAT32 c1; OPJ_FLOAT32 c1;
OPJ_FLOAT32 c2; OPJ_FLOAT32 c2;
OPJ_FLOAT32 c3; OPJ_FLOAT32 c3;
@ -778,7 +798,7 @@ static void opj_v4dwt_decode_step2(opj_v4_t* l, opj_v4_t* w, OPJ_INT32 k, OPJ_IN
c2 = fl[1] * c; c2 = fl[1] * c;
c3 = fl[2] * c; c3 = fl[2] * c;
c4 = fl[3] * c; c4 = fl[3] * c;
for(; m < k; ++m){ for(; m < k; ++m) {
OPJ_FLOAT32 tmp1 = fw[-4]; OPJ_FLOAT32 tmp1 = fw[-4];
OPJ_FLOAT32 tmp2 = fw[-3]; OPJ_FLOAT32 tmp2 = fw[-3];
OPJ_FLOAT32 tmp3 = fw[-2]; OPJ_FLOAT32 tmp3 = fw[-2];
@ -801,12 +821,12 @@ static void opj_v4dwt_decode(opj_v4dwt_t* restrict dwt)
{ {
OPJ_INT32 a, b; OPJ_INT32 a, b;
if(dwt->cas == 0) { if(dwt->cas == 0) {
if(!((dwt->dn > 0) || (dwt->sn > 1))){ if(!((dwt->dn > 0) || (dwt->sn > 1))) {
return; return;
} }
a = 0; a = 0;
b = 1; b = 1;
}else{ } else {
if(!((dwt->sn > 0) || (dwt->dn > 1))) { if(!((dwt->sn > 0) || (dwt->dn > 1))) {
return; return;
} }
@ -874,7 +894,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize); opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize);
opj_v4dwt_decode(&h); opj_v4dwt_decode(&h);
for(k = (OPJ_INT32)rw; --k >= 0;){ for(k = (OPJ_INT32)rw; --k >= 0;) {
aj[k ] = h.wavelet[k].f[0]; aj[k ] = h.wavelet[k].f[0];
aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1]; aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1];
aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2]; aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2];
@ -890,11 +910,14 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
j = rh & 0x03; j = rh & 0x03;
opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize); opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize);
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];
} }
} }
} }
@ -903,19 +926,19 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
v.cas = res->y0 % 2; v.cas = res->y0 % 2;
aj = (OPJ_FLOAT32*) tilec->data; aj = (OPJ_FLOAT32*) tilec->data;
for(j = (OPJ_INT32)rw; j > 3; j -= 4){ for(j = (OPJ_INT32)rw; j > 3; j -= 4) {
OPJ_UINT32 k; OPJ_UINT32 k;
opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, 4); opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, 4);
opj_v4dwt_decode(&v); opj_v4dwt_decode(&v);
for(k = 0; k < rh; ++k){ for(k = 0; k < rh; ++k) {
memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32)); memcpy(&aj[k*w], &v.wavelet[k], 4 * sizeof(OPJ_FLOAT32));
} }
aj += 4; aj += 4;
} }
if (rw & 0x03){ if (rw & 0x03) {
OPJ_UINT32 k; OPJ_UINT32 k;
j = rw & 0x03; j = rw & 0x03;
@ -923,7 +946,7 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr
opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, j); opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, j);
opj_v4dwt_decode(&v); opj_v4dwt_decode(&v);
for(k = 0; k < rh; ++k){ for(k = 0; k < rh; ++k) {
memcpy(&aj[k*w], &v.wavelet[k], (size_t)j * sizeof(OPJ_FLOAT32)); memcpy(&aj[k*w], &v.wavelet[k], (size_t)j * sizeof(OPJ_FLOAT32));
} }
} }

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;
@ -158,7 +161,7 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
p_image_dest->x1 = p_image_src->x1; p_image_dest->x1 = p_image_src->x1;
p_image_dest->y1 = p_image_src->y1; p_image_dest->y1 = p_image_src->y1;
if (p_image_dest->comps){ if (p_image_dest->comps) {
for(compno = 0; compno < p_image_dest->numcomps; compno++) { for(compno = 0; compno < p_image_dest->numcomps; compno++) {
opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]); opj_image_comp_t *image_comp = &(p_image_dest->comps[compno]);
if(image_comp->data) { if(image_comp->data) {
@ -172,13 +175,13 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
p_image_dest->numcomps = p_image_src->numcomps; p_image_dest->numcomps = p_image_src->numcomps;
p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t)); p_image_dest->comps = (opj_image_comp_t*) opj_malloc(p_image_dest->numcomps * sizeof(opj_image_comp_t));
if (!p_image_dest->comps){ if (!p_image_dest->comps) {
p_image_dest->comps = NULL; p_image_dest->comps = NULL;
p_image_dest->numcomps = 0; p_image_dest->numcomps = 0;
return; return;
} }
for (compno=0; compno < p_image_dest->numcomps; compno++){ for (compno=0; compno < p_image_dest->numcomps; compno++) {
memcpy( &(p_image_dest->comps[compno]), memcpy( &(p_image_dest->comps[compno]),
&(p_image_src->comps[compno]), &(p_image_src->comps[compno]),
sizeof(opj_image_comp_t)); sizeof(opj_image_comp_t));
@ -190,7 +193,7 @@ void opj_copy_image_header(const opj_image_t* p_image_src, opj_image_t* p_image_
if (p_image_dest->icc_profile_len) { if (p_image_dest->icc_profile_len) {
p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len); p_image_dest->icc_profile_buf = (OPJ_BYTE*)opj_malloc(p_image_dest->icc_profile_len);
if (!p_image_dest->icc_profile_buf){ if (!p_image_dest->icc_profile_buf) {
p_image_dest->icc_profile_buf = NULL; p_image_dest->icc_profile_buf = NULL;
p_image_dest->icc_profile_len = 0; p_image_dest->icc_profile_len = 0;
return; return;
@ -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++));
} }

File diff suppressed because it is too large Load Diff

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
@ -158,7 +156,7 @@ T2 encoding mode
typedef enum T2_MODE { typedef enum T2_MODE {
THRESH_CALC = 0, /** Function called in Rate allocation process*/ THRESH_CALC = 0, /** Function called in Rate allocation process*/
FINAL_PASS = 1 /** Function called in Tier 2 process*/ FINAL_PASS = 1 /** Function called in Tier 2 process*/
}J2K_T2_MODE; } J2K_T2_MODE;
/** /**
* Quantization stepsize * Quantization stepsize
@ -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,15 +389,14 @@ 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;
} }
m_specific_param; m_specific_param;
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
/** enables writing of EPC in MH, thus activating JPWL */ /** enables writing of EPC in MH, thus activating JPWL */
OPJ_BOOL epc_on; OPJ_BOOL epc_on;
@ -456,12 +445,11 @@ typedef struct opj_cp
OPJ_UINT32 ppm : 1; OPJ_UINT32 ppm : 1;
/** tells if the parameter is a coding or decoding one */ /** tells if the parameter is a coding or decoding one */
OPJ_UINT32 m_is_decoder : 1; OPJ_UINT32 m_is_decoder : 1;
/* <<UniPG */ /* <<UniPG */
} 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;
@ -578,7 +576,7 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2,
++ p_image_header_data; ++ p_image_header_data;
/* Should be equal to 7 cf. chapter about image header box of the norm */ /* Should be equal to 7 cf. chapter about image header box of the norm */
if (jp2->C != 7){ if (jp2->C != 7) {
opj_event_msg(p_manager, EVT_INFO, "JP2 IHDR box: compression type indicate that the file is not a conforming JP2 file (%d) \n", jp2->C); opj_event_msg(p_manager, EVT_INFO, "JP2 IHDR box: compression type indicate that the file is not a conforming JP2 file (%d) \n", jp2->C);
} }
@ -690,7 +688,7 @@ static OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2,
assert(p_manager != 00); assert(p_manager != 00);
if (jp2->bpc != 255 ){ if (jp2->bpc != 255 ) {
opj_event_msg(p_manager, EVT_WARNING, "A BPCC header box is available although BPC given by the IHDR box (%d) indicate components bit depth is constant\n",jp2->bpc); opj_event_msg(p_manager, EVT_WARNING, "A BPCC header box is available although BPC given by the IHDR box (%d) indicate components bit depth is constant\n",jp2->bpc);
} }
@ -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,10 +975,11 @@ 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) {
assert( pcol == 0 ); assert( pcol == 0 );
new_comps[i] = old_comps[cmp]; new_comps[i] = old_comps[cmp];
} else { } else {
@ -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() */
@ -1308,7 +1297,7 @@ static OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2,
opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */ opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */
p_cdef_header_data+= 2; p_cdef_header_data+= 2;
if ( (OPJ_UINT16)l_value == 0){ /* szukw000: FIXME */ if ( (OPJ_UINT16)l_value == 0) { /* szukw000: FIXME */
opj_event_msg(p_manager, EVT_ERROR, "Number of channel description is equal to zero in CDEF box.\n"); opj_event_msg(p_manager, EVT_ERROR, "Number of channel description is equal to zero in CDEF box.\n");
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -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), "
@ -1489,7 +1472,7 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
return OPJ_FALSE; return OPJ_FALSE;
} }
if (!jp2->ignore_pclr_cmap_cdef){ if (!jp2->ignore_pclr_cmap_cdef) {
if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) { if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -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;
@ -1576,7 +1558,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
opj_write_bytes(l_jp2h_data+4,JP2_JP2H,4); opj_write_bytes(l_jp2h_data+4,JP2_JP2H,4);
l_current_writer = l_writers; l_current_writer = l_writers;
for (i=0;i<l_nb_pass;++i) { for (i=0; i<l_nb_pass; ++i) {
l_current_writer->m_data = l_current_writer->handler(jp2,&(l_current_writer->m_size)); l_current_writer->m_data = l_current_writer->handler(jp2,&(l_current_writer->m_size));
if (l_current_writer->m_data == 00) { if (l_current_writer->m_data == 00) {
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to hold JP2 Header data\n"); opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to hold JP2 Header data\n");
@ -1590,7 +1572,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
if (! l_result) { if (! l_result) {
l_current_writer = l_writers; l_current_writer = l_writers;
for (i=0;i<l_nb_pass;++i) { for (i=0; i<l_nb_pass; ++i) {
if (l_current_writer->m_data != 00) { if (l_current_writer->m_data != 00) {
opj_free(l_current_writer->m_data ); opj_free(l_current_writer->m_data );
} }
@ -1611,7 +1593,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
if (l_result) { if (l_result) {
l_current_writer = l_writers; l_current_writer = l_writers;
for (i=0;i<l_nb_pass;++i) { for (i=0; i<l_nb_pass; ++i) {
if (opj_stream_write_data(stream,l_current_writer->m_data,l_current_writer->m_size,p_manager) != l_current_writer->m_size) { if (opj_stream_write_data(stream,l_current_writer->m_data,l_current_writer->m_size,p_manager) != l_current_writer->m_size) {
opj_event_msg(p_manager, EVT_ERROR, "Stream error while writing JP2 Header box\n"); opj_event_msg(p_manager, EVT_ERROR, "Stream error while writing JP2 Header box\n");
l_result = OPJ_FALSE; l_result = OPJ_FALSE;
@ -1624,7 +1606,7 @@ static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
l_current_writer = l_writers; l_current_writer = l_writers;
/* cleanup */ /* cleanup */
for (i=0;i<l_nb_pass;++i) { for (i=0; i<l_nb_pass; ++i) {
if (l_current_writer->m_data != 00) { if (l_current_writer->m_data != 00) {
opj_free(l_current_writer->m_data ); opj_free(l_current_writer->m_data );
} }
@ -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");
} }
@ -1803,7 +1784,7 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2,
jp2->minversion = 0; /* MinV */ jp2->minversion = 0; /* MinV */
jp2->numcl = 1; jp2->numcl = 1;
jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32)); jp2->cl = (OPJ_UINT32*) opj_malloc(jp2->numcl * sizeof(OPJ_UINT32));
if (!jp2->cl){ if (!jp2->cl) {
jp2->cl = NULL; jp2->cl = NULL;
opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n"); opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n");
return OPJ_FALSE; return OPJ_FALSE;
@ -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);
@ -2242,7 +2218,7 @@ static OPJ_BOOL opj_jp2_exec ( opj_jp2_t * jp2,
l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list); l_nb_proc = opj_procedure_list_get_nb_procedures(p_procedure_list);
l_procedure = (OPJ_BOOL (**) (opj_jp2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list); l_procedure = (OPJ_BOOL (**) (opj_jp2_t * jp2, opj_stream_private_t *, opj_event_mgr_t *)) opj_procedure_list_get_first_procedure(p_procedure_list);
for (i=0;i<l_nb_proc;++i) { for (i=0; i<l_nb_proc; ++i) {
l_result = l_result && (*l_procedure) (jp2,stream,p_manager); l_result = l_result && (*l_procedure) (jp2,stream,p_manager);
++l_procedure; ++l_procedure;
} }
@ -2290,7 +2266,7 @@ static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id)
{ {
OPJ_UINT32 i, l_handler_size = sizeof(jp2_header) / sizeof(opj_jp2_header_handler_t); OPJ_UINT32 i, l_handler_size = sizeof(jp2_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_header[i].id == p_id) { if (jp2_header[i].id == p_id) {
return &jp2_header[i]; return &jp2_header[i];
} }
@ -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;
} }
@ -2861,7 +2833,7 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_event_msg(p_manager, EVT_WARNING, "JP2 box which are after the codestream will not be read by this function.\n"); opj_event_msg(p_manager, EVT_WARNING, "JP2 box which are after the codestream will not be read by this function.\n");
if (! opj_j2k_get_tile(p_jp2->j2k, p_stream, p_image, p_manager, tile_index) ){ if (! opj_j2k_get_tile(p_jp2->j2k, p_stream, p_image, p_manager, tile_index) ) {
opj_event_msg(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\n"); opj_event_msg(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\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 */
@ -427,9 +417,9 @@ OPJ_BOOL opj_jp2_set_decode_area( opj_jp2_t *p_jp2,
OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
opj_event_mgr_t * p_manager ); opj_event_mgr_t * p_manager );
/** /**
* *
*/ */
OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2, OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2,
opj_stream_private_t *p_stream, opj_stream_private_t *p_stream,
opj_image_t* p_image, opj_image_t* p_image,

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];
} }
@ -467,19 +469,19 @@ OPJ_BOOL opj_mct_encode_custom(
lCurrentMatrix = lCurrentData + pNbComp; lCurrentMatrix = lCurrentData + pNbComp;
for (i =0;i<lNbMatCoeff;++i) { for (i =0; i<lNbMatCoeff; ++i) {
lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator); lCurrentMatrix[i] = (OPJ_INT32) (*(lMct++) * (OPJ_FLOAT32)lMultiplicator);
} }
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
lMctPtr = lCurrentMatrix; lMctPtr = lCurrentMatrix;
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (*(lData[j])); lCurrentData[j] = (*(lData[j]));
} }
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
*(lData[j]) = 0; *(lData[j]) = 0;
for (k=0;k<pNbComp;++k) { for (k=0; k<pNbComp; ++k) {
*(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]); *(lData[j]) += opj_int_fix_mul(*lMctPtr, lCurrentData[k]);
++lMctPtr; ++lMctPtr;
} }
@ -519,12 +521,12 @@ OPJ_BOOL opj_mct_decode_custom(
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
lMct = (OPJ_FLOAT32 *) pDecodingData; lMct = (OPJ_FLOAT32 *) pDecodingData;
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j])); lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
} }
for (j=0;j<pNbComp;++j) { for (j=0; j<pNbComp; ++j) {
lCurrentResult[j] = 0; lCurrentResult[j] = 0;
for (k=0;k<pNbComp;++k) { for (k=0; k<pNbComp; ++k) {
lCurrentResult[j] += *(lMct++) * lCurrentData[k]; lCurrentResult[j] += *(lMct++) * lCurrentData[k];
} }
*(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]); *(lData[j]++) = (OPJ_FLOAT32) (lCurrentResult[j]);
@ -543,11 +545,11 @@ void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms; OPJ_FLOAT64 * lNorms = (OPJ_FLOAT64 *) pNorms;
OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix; OPJ_FLOAT32 * lMatrix = (OPJ_FLOAT32 *) pMatrix;
for (i=0;i<pNbComps;++i) { for (i=0; i<pNbComps; ++i) {
lNorms[i] = 0; lNorms[i] = 0;
lIndex = i; lIndex = i;
for (j=0;j<pNbComps;++j) { for (j=0; j<pNbComps; ++j) {
lCurrentValue = lMatrix[lIndex]; lCurrentValue = lMatrix[lIndex];
lIndex += pNbComps; lIndex += pNbComps;
lNorms[i] += lCurrentValue * lCurrentValue; lNorms[i] += lCurrentValue * lCurrentValue;

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

@ -46,7 +46,7 @@ OPJ_BOOL OPJ_CALLCONV opj_set_info_handler( opj_codec_t * p_codec,
void * p_user_data) void * p_user_data)
{ {
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
if(! l_codec){ if(! l_codec) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -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;
} }
@ -166,7 +168,7 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT p_format)
opj_codec_private_t *l_codec = 00; opj_codec_private_t *l_codec = 00;
l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t)); l_codec = (opj_codec_private_t*) opj_calloc(1, sizeof(opj_codec_private_t));
if (!l_codec){ if (!l_codec) {
return 00; return 00;
} }
@ -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 */
@ -344,13 +347,13 @@ void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *paramete
parameters->decod_format = -1; parameters->decod_format = -1;
parameters->cod_format = -1; parameters->cod_format = -1;
parameters->flags = 0; parameters->flags = 0;
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
parameters->jpwl_correct = OPJ_FALSE; parameters->jpwl_correct = OPJ_FALSE;
parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS; parameters->jpwl_exp_comps = JPWL_EXPECTED_COMPONENTS;
parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES; parameters->jpwl_max_tiles = JPWL_MAXIMUM_TILES;
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
} }
} }
@ -523,7 +526,7 @@ OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec,
{ {
opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec; opj_codec_private_t * l_codec = (opj_codec_private_t *) p_codec;
if ( !l_codec ){ if ( !l_codec ) {
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -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 */
@ -655,7 +659,7 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
parameters->cp_fixed_alloc = 0; parameters->cp_fixed_alloc = 0;
parameters->cp_fixed_quality = 0; parameters->cp_fixed_quality = 0;
parameters->jpip_on = OPJ_FALSE; parameters->jpip_on = OPJ_FALSE;
/* UniPG>> */ /* UniPG>> */
#ifdef USE_JPWL #ifdef USE_JPWL
parameters->jpwl_epc_on = OPJ_FALSE; parameters->jpwl_epc_on = OPJ_FALSE;
parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */ parameters->jpwl_hprot_MH = -1; /* -1 means unassigned */
@ -686,7 +690,7 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
} }
}; };
#endif /* USE_JPWL */ #endif /* USE_JPWL */
/* <<UniPG */ /* <<UniPG */
} }
} }
@ -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,14 +885,15 @@ 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) {
opj_free((*cstr_info)->m_default_tile_info.tccp_info); opj_free((*cstr_info)->m_default_tile_info.tccp_info);
} }
if ((*cstr_info)->tile_info){ if ((*cstr_info)->tile_info) {
/* FIXME not used for the moment*/ /* FIXME not used for the moment*/
} }
@ -911,7 +915,7 @@ opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index) void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index)
{ {
if (*p_cstr_index){ if (*p_cstr_index) {
j2k_destroy_cstr_index(*p_cstr_index); j2k_destroy_cstr_index(*p_cstr_index);
(*p_cstr_index) = NULL; (*p_cstr_index) = NULL;
} }
@ -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

@ -1,44 +1,44 @@
/* /*
* The copyright in this software is being made available under the 2-clauses * The copyright in this software is being made available under the 2-clauses
* BSD License, included below. This software may be subject to other third * BSD License, included below. This software may be subject to other third
* party and contributor rights, including patent rights, and no such rights * party and contributor rights, including patent rights, and no such rights
* are granted under this license. * are granted under this license.
* *
* Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
* Copyright (c) 2002-2014, Professor Benoit Macq * Copyright (c) 2002-2014, Professor Benoit Macq
* Copyright (c) 2001-2003, David Janssens * Copyright (c) 2001-2003, David Janssens
* Copyright (c) 2002-2003, Yannick Verschueren * Copyright (c) 2002-2003, Yannick Verschueren
* Copyright (c) 2003-2007, Francois-Olivier Devaux * Copyright (c) 2003-2007, Francois-Olivier Devaux
* Copyright (c) 2003-2014, Antonin Descampe * Copyright (c) 2003-2014, Antonin Descampe
* Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2005, Herve Drolon, FreeImage Team
* Copyright (c) 2006-2007, Parvatha Elangovan * Copyright (c) 2006-2007, Parvatha Elangovan
* Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
* Copyright (c) 2010-2011, Kaori Hagihara * Copyright (c) 2010-2011, Kaori Hagihara
* Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France
* Copyright (c) 2012, CS Systemes d'Information, France * Copyright (c) 2012, CS Systemes d'Information, France
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef OPENJPEG_H #ifndef OPENJPEG_H
#define OPENJPEG_H #define OPENJPEG_H
@ -54,26 +54,26 @@ The inline keyword is supported by C99 but not by C90.
Most compilers implement their own version of this keyword ... Most compilers implement their own version of this keyword ...
*/ */
#ifndef INLINE #ifndef INLINE
#if defined(_MSC_VER) #if defined(_MSC_VER)
#define INLINE __forceinline #define INLINE __forceinline
#elif defined(__GNUC__) #elif defined(__GNUC__)
#define INLINE __inline__ #define INLINE __inline__
#elif defined(__MWERKS__) #elif defined(__MWERKS__)
#define INLINE inline #define INLINE inline
#else #else
/* add other compilers here ... */ /* add other compilers here ... */
#define INLINE #define INLINE
#endif /* defined(<Compiler>) */ #endif /* defined(<Compiler>) */
#endif /* INLINE */ #endif /* INLINE */
/* deprecated attribute */ /* deprecated attribute */
#ifdef __GNUC__ #ifdef __GNUC__
#define OPJ_DEPRECATED(func) func __attribute__ ((deprecated)) #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define OPJ_DEPRECATED(func) __declspec(deprecated) func #define OPJ_DEPRECATED(func) __declspec(deprecated) func
#else #else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler") #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define OPJ_DEPRECATED(func) func #define OPJ_DEPRECATED(func) func
#endif #endif
#if defined(OPJ_STATIC) || !defined(_WIN32) #if defined(OPJ_STATIC) || !defined(_WIN32)
@ -259,7 +259,7 @@ typedef enum CINEMA_MODE {
OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/ OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/ OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/ OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
}OPJ_CINEMA_MODE; } OPJ_CINEMA_MODE;
/** /**
* Progression order * Progression order
@ -430,7 +430,7 @@ typedef struct opj_cparameters {
int cod_format; int cod_format;
/*@}*/ /*@}*/
/* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */ /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
/**@name JPWL encoding parameters */ /**@name JPWL encoding parameters */
/*@{*/ /*@{*/
/** enables writing of EPC in MH, thus activating JPWL */ /** enables writing of EPC in MH, thus activating JPWL */
@ -460,7 +460,7 @@ typedef struct opj_cparameters {
/** sensitivity methods for TPHs (-1=no,0-7) */ /** sensitivity methods for TPHs (-1=no,0-7) */
int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS]; int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
/*@}*/ /*@}*/
/* <<UniPG */ /* <<UniPG */
/** /**
* DEPRECATED: use RSIZ, OPJ_PROFILE_* and MAX_COMP_SIZE instead * DEPRECATED: use RSIZ, OPJ_PROFILE_* and MAX_COMP_SIZE instead
@ -551,7 +551,7 @@ typedef struct opj_dparameters {
/*@}*/ /*@}*/
/* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */ /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
/**@name JPWL decoding parameters */ /**@name JPWL decoding parameters */
/*@{*/ /*@{*/
/** activates the JPWL correction capabilities */ /** activates the JPWL correction capabilities */
@ -561,7 +561,7 @@ typedef struct opj_dparameters {
/** maximum number of tiles */ /** maximum number of tiles */
int jpwl_max_tiles; int jpwl_max_tiles;
/*@}*/ /*@}*/
/* <<UniPG */ /* <<UniPG */
unsigned int flags; unsigned int flags;
@ -831,14 +831,14 @@ typedef struct opj_codestream_info {
int numlayers; int numlayers;
/** number of decomposition for each component */ /** number of decomposition for each component */
int *numdecompos; int *numdecompos;
/* UniPG>> */ /* UniPG>> */
/** number of markers */ /** number of markers */
int marknum; int marknum;
/** list of markers */ /** list of markers */
opj_marker_info_t *marker; opj_marker_info_t *marker;
/** actual size of markers array */ /** actual size of markers array */
int maxmarknum; int maxmarknum;
/* <<UniPG */ /* <<UniPG */
/** main header position */ /** main header position */
int main_head_start; int main_head_start;
/** main header position */ /** main header position */
@ -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 */
@ -996,21 +995,21 @@ typedef struct opj_codestream_index {
/** codestream's size */ /** codestream's size */
OPJ_UINT64 codestream_size; OPJ_UINT64 codestream_size;
/* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */ /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
/** number of markers */ /** number of markers */
OPJ_UINT32 marknum; OPJ_UINT32 marknum;
/** list of markers */ /** list of markers */
opj_marker_info_t *marker; opj_marker_info_t *marker;
/** actual size of markers array */ /** actual size of markers array */
OPJ_UINT32 maxmarknum; OPJ_UINT32 maxmarknum;
/* <<UniPG */ /* <<UniPG */
/** */ /** */
OPJ_UINT32 nb_of_tiles; OPJ_UINT32 nb_of_tiles;
/** */ /** */
opj_tile_index_t *tile_index; /* FIXME not used for the moment */ opj_tile_index_t *tile_index; /* FIXME not used for the moment */
}opj_codestream_index_t; } opj_codestream_index_t;
/* -----------------------------------------------------------> */ /* -----------------------------------------------------------> */
/* /*

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

@ -70,11 +70,11 @@
#if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \ #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \
!(defined(_MSC_VER) && _MSC_VER < 1400) && \ !(defined(_MSC_VER) && _MSC_VER < 1400) && \
!(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800) !(defined(__MINGW32__) && __MSVCRT_VERSION__ < 0x800)
/* /*
Windows '95 and Borland C do not support _lseeki64 Windows '95 and Borland C do not support _lseeki64
Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release. Visual Studio does not support _fseeki64 and _ftelli64 until the 2005 release.
Without these interfaces, files over 2GB in size are not supported for Windows. Without these interfaces, files over 2GB in size are not supported for Windows.
*/ */
# define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence) # define OPJ_FSEEK(stream,offset,whence) _fseeki64(stream,/* __int64 */ offset,whence)
# define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff) # define OPJ_FSTAT(fildes,stat_buff) _fstati64(fildes,/* struct _stati64 */ stat_buff)
# define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream) # define OPJ_FTELL(stream) /* __int64 */ _ftelli64(stream)
@ -104,18 +104,18 @@
/* Ignore GCC attributes if this is not GCC */ /* Ignore GCC attributes if this is not GCC */
#ifndef __GNUC__ #ifndef __GNUC__
#define __attribute__(x) /* __attribute__(x) */ #define __attribute__(x) /* __attribute__(x) */
#endif #endif
/* Are restricted pointers available? (C99) */ /* Are restricted pointers available? (C99) */
#if (__STDC_VERSION__ != 199901L) #if (__STDC_VERSION__ != 199901L)
/* Not a C99 compiler */ /* Not a C99 compiler */
#ifdef __GNUC__ #ifdef __GNUC__
#define restrict __restrict__ #define restrict __restrict__
#else #else
#define restrict /* restrict */ #define restrict /* restrict */
#endif #endif
#endif #endif
@ -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,13 +159,14 @@ 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
#if defined(_MSC_VER) && (_MSC_VER < 1400) #if defined(_MSC_VER) && (_MSC_VER < 1400)
#define vsnprintf _vsnprintf #define vsnprintf _vsnprintf
#endif #endif
/* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */ /* MSVC x86 is really bad at doing int64 = int32 * int32 on its own. Use intrinsic. */

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; OPJ_UINT32 l;
for (l = 0; a > 1; ++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,14 +58,13 @@ 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 */
#elif defined(OPJ_HAVE_MEMALIGN) #elif defined(OPJ_HAVE_MEMALIGN)
ptr = memalign( alignment, size ); ptr = memalign( alignment, size );
/* _MSC_VER */ /* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC) #elif defined(OPJ_HAVE__ALIGNED_MALLOC)
ptr = _aligned_malloc(size, alignment); ptr = _aligned_malloc(size, alignment);
#else #else
@ -117,7 +116,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
return NULL; return NULL;
} }
/* no portable aligned realloc */ /* no portable aligned realloc */
#if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN) #if defined(OPJ_HAVE_POSIX_MEMALIGN) || defined(OPJ_HAVE_MEMALIGN)
/* glibc doc states one can mix aligned malloc with realloc */ /* glibc doc states one can mix aligned malloc with realloc */
r_ptr = realloc( ptr, new_size ); /* fast path */ r_ptr = realloc( ptr, new_size ); /* fast path */
@ -135,7 +134,7 @@ static INLINE void *opj_aligned_realloc_n(void *ptr, size_t alignment, size_t ne
free( r_ptr ); free( r_ptr );
r_ptr = a_ptr; r_ptr = a_ptr;
} }
/* _MSC_VER */ /* _MSC_VER */
#elif defined(OPJ_HAVE__ALIGNED_MALLOC) #elif defined(OPJ_HAVE__ALIGNED_MALLOC)
r_ptr = _aligned_realloc( ptr, new_size, alignment ); r_ptr = _aligned_realloc( ptr, new_size, alignment );
#else #else
@ -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

@ -58,7 +58,7 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
for( i=0;i<2;i++){ for( i=0; i<2; i++) {
if (i) if (i)
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
@ -69,7 +69,7 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager ); opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager );
for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++){ for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++) {
box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager); box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].type = JPIP_FAIX; box[compno].type = JPIP_FAIX;
} }
@ -104,11 +104,10 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
(void)EPHused; /* unused ? */ (void)EPHused; /* unused ? */
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;
} }
@ -129,19 +128,19 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
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( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++){ for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++) {
tile_Idx = &cstr_info.tile[ tileno]; tile_Idx = &cstr_info.tile[ tileno];
num_packet = 0; num_packet = 0;
numOfres = cstr_info.numdecompos[compno] + 1; numOfres = cstr_info.numdecompos[compno] + 1;
for( resno=0; resno<numOfres ; resno++){ for( resno=0; resno<numOfres ; resno++) {
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno]; numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
for( precno=0; precno<numOfprec; precno++){ for( precno=0; precno<numOfprec; precno++) {
numOflayers = cstr_info.numlayers; numOflayers = cstr_info.numlayers;
for( layno=0; layno<numOflayers; layno++){ for( layno=0; layno<numOflayers; layno++) {
switch ( cstr_info.prog){ switch ( cstr_info.prog) {
case OPJ_LRCP: case OPJ_LRCP:
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
break; break;
@ -172,7 +171,7 @@ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
} }
/* PADDING */ /* PADDING */
while( num_packet < nmax){ while( num_packet < nmax) {
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);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,0,size_of_coding);/* length */

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;
@ -252,7 +253,7 @@ static OPJ_BOOL opj_pi_next_lrcp(opj_pi_iterator_t * pi) {
continue; continue;
} }
res = &comp->resolutions[pi->resno]; res = &comp->resolutions[pi->resno];
if (!pi->tp_on){ if (!pi->tp_on) {
pi->poc.precno1 = res->pw * res->ph; pi->poc.precno1 = res->pw * res->ph;
} }
for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
@ -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;
@ -291,7 +294,7 @@ static OPJ_BOOL opj_pi_next_rlcp(opj_pi_iterator_t * pi) {
continue; continue;
} }
res = &comp->resolutions[pi->resno]; res = &comp->resolutions[pi->resno];
if(!pi->tp_on){ if(!pi->tp_on) {
pi->poc.precno1 = res->pw * res->ph; pi->poc.precno1 = res->pw * res->ph;
} }
for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) { for (pi->precno = pi->poc.precno0; pi->precno < pi->poc.precno1; pi->precno++) {
@ -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;
@ -333,7 +338,7 @@ static OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) {
} }
} }
} }
if (!pi->tp_on){ if (!pi->tp_on) {
pi->poc.ty0 = pi->ty0; pi->poc.ty0 = pi->ty0;
pi->poc.tx0 = pi->tx0; pi->poc.tx0 = pi->tx0;
pi->poc.ty1 = pi->ty1; pi->poc.ty1 = pi->ty1;
@ -360,10 +365,10 @@ if (!pi->tp_on){
try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
rpx = res->pdx + levelno; rpx = res->pdx + levelno;
rpy = res->pdy + levelno; rpy = res->pdy + levelno;
if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))) {
continue; continue;
} }
if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))) {
continue; continue;
} }
@ -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;
@ -417,7 +424,7 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
} }
} }
} }
if (!pi->tp_on){ if (!pi->tp_on) {
pi->poc.ty0 = pi->ty0; pi->poc.ty0 = pi->ty0;
pi->poc.tx0 = pi->tx0; pi->poc.tx0 = pi->tx0;
pi->poc.ty1 = pi->ty1; pi->poc.ty1 = pi->ty1;
@ -441,10 +448,10 @@ static OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) {
try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
rpx = res->pdx + levelno; rpx = res->pdx + levelno;
rpy = res->pdy + levelno; rpy = res->pdy + levelno;
if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))) {
continue; continue;
} }
if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))) {
continue; continue;
} }
@ -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;
@ -498,7 +507,7 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx); pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx);
pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy); pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy);
} }
if (!pi->tp_on){ if (!pi->tp_on) {
pi->poc.ty0 = pi->ty0; pi->poc.ty0 = pi->ty0;
pi->poc.tx0 = pi->tx0; pi->poc.tx0 = pi->tx0;
pi->poc.ty1 = pi->ty1; pi->poc.ty1 = pi->ty1;
@ -520,10 +529,10 @@ static OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) {
try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno));
rpx = res->pdx + levelno; rpx = res->pdx + levelno;
rpy = res->pdy + levelno; rpy = res->pdy + levelno;
if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))) {
continue; continue;
} }
if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))) {
continue; continue;
} }
@ -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:
;
} }
} }
} }
@ -906,7 +916,7 @@ static void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp,
l_current_poc->dy = p_dy_min; l_current_poc->dy = p_dy_min;
++ l_current_poc; ++ l_current_poc;
for (pino = 1;pino < l_poc_bound ; ++pino) { for (pino = 1; pino < l_poc_bound ; ++pino) {
l_current_poc->compS = l_current_poc->compno0; l_current_poc->compS = l_current_poc->compno0;
l_current_poc->compE= l_current_poc->compno1; l_current_poc->compE= l_current_poc->compno1;
l_current_poc->resS = l_current_poc->resno0; l_current_poc->resS = l_current_poc->resno0;
@ -1008,7 +1018,7 @@ static void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi,
l_current_pi = p_pi; l_current_pi = p_pi;
l_current_poc = p_tcp->pocs; l_current_poc = p_tcp->pocs;
for (pino = 0;pino<l_bound;++pino) { for (pino = 0; pino<l_bound; ++pino) {
l_current_pi->poc.prg = l_current_poc->prg; /* Progression Order #0 */ l_current_pi->poc.prg = l_current_poc->prg; /* Progression Order #0 */
l_current_pi->first = 1; l_current_pi->first = 1;
@ -1045,7 +1055,7 @@ static void opj_pi_update_decode_not_poc (opj_pi_iterator_t * p_pi,
l_bound = p_tcp->numpocs+1; l_bound = p_tcp->numpocs+1;
l_current_pi = p_pi; l_current_pi = p_pi;
for (pino = 0;pino<l_bound;++pino) { for (pino = 0; pino<l_bound; ++pino) {
l_current_pi->poc.prg = p_tcp->prg; l_current_pi->poc.prg = p_tcp->prg;
l_current_pi->first = 1; l_current_pi->first = 1;
l_current_pi->poc.resno0 = 0; l_current_pi->poc.resno0 = 0;
@ -1072,69 +1082,69 @@ static OPJ_BOOL opj_pi_check_next_level( OPJ_INT32 pos,
opj_tcp_t *tcps =&cp->tcps[tileno]; opj_tcp_t *tcps =&cp->tcps[tileno];
opj_poc_t *tcp = &tcps->pocs[pino]; opj_poc_t *tcp = &tcps->pocs[pino];
if(pos>=0){ if(pos>=0) {
for(i=pos;pos>=0;i--){ for(i=pos; pos>=0; i--) {
switch(prog[i]){ switch(prog[i]) {
case 'R': case 'R':
if(tcp->res_t==tcp->resE){ if(tcp->res_t==tcp->resE) {
if(opj_pi_check_next_level(pos-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(pos-1,cp,tileno,pino,prog)) {
return OPJ_TRUE; return OPJ_TRUE;
}else{ } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
}else{ } else {
return OPJ_TRUE; return OPJ_TRUE;
} }
break; break;
case 'C': case 'C':
if(tcp->comp_t==tcp->compE){ if(tcp->comp_t==tcp->compE) {
if(opj_pi_check_next_level(pos-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(pos-1,cp,tileno,pino,prog)) {
return OPJ_TRUE; return OPJ_TRUE;
}else{ } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
}else{ } else {
return OPJ_TRUE; return OPJ_TRUE;
} }
break; break;
case 'L': case 'L':
if(tcp->lay_t==tcp->layE){ if(tcp->lay_t==tcp->layE) {
if(opj_pi_check_next_level(pos-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(pos-1,cp,tileno,pino,prog)) {
return OPJ_TRUE; return OPJ_TRUE;
}else{ } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
}else{ } else {
return OPJ_TRUE; return OPJ_TRUE;
} }
break; break;
case 'P': case 'P':
switch(tcp->prg){ switch(tcp->prg) {
case OPJ_LRCP: /* fall through */ case OPJ_LRCP: /* fall through */
case OPJ_RLCP: case OPJ_RLCP:
if(tcp->prc_t == tcp->prcE){ if(tcp->prc_t == tcp->prcE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
return OPJ_TRUE; return OPJ_TRUE;
}else{ } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
}else{ } else {
return OPJ_TRUE; return OPJ_TRUE;
} }
break; break;
default: default:
if(tcp->tx0_t == tcp->txE){ if(tcp->tx0_t == tcp->txE) {
/*TY*/ /*TY*/
if(tcp->ty0_t == tcp->tyE){ if(tcp->ty0_t == tcp->tyE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
return OPJ_TRUE; return OPJ_TRUE;
}else{ } else {
return OPJ_FALSE; return OPJ_FALSE;
} }
}else{ } else {
return OPJ_TRUE; return OPJ_TRUE;
}/*TY*/ }/*TY*/
}else{ } else {
return OPJ_TRUE; return OPJ_TRUE;
} }
break; break;
@ -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);
} }
@ -1555,7 +1552,7 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].first = 1; pi[pino].first = 1;
pi[pino].poc.prg = tcp->prg; pi[pino].poc.prg = tcp->prg;
if(!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) && (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz)))){ if(!(cp->m_specific_param.m_enc.m_tp_on && ((!OPJ_IS_CINEMA(cp->rsiz) && (t2_mode == FINAL_PASS)) || OPJ_IS_CINEMA(cp->rsiz)))) {
pi[pino].poc.resno0 = tcp->resS; pi[pino].poc.resno0 = tcp->resS;
pi[pino].poc.resno1 = tcp->resE; pi[pino].poc.resno1 = tcp->resE;
pi[pino].poc.compno0 = tcp->compS; pi[pino].poc.compno0 = tcp->compS;
@ -1568,9 +1565,9 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS; pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS;
pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE; pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE;
pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE; pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE;
}else { } else {
for(i=tppos+1;i<4;i++){ for(i=tppos+1; i<4; i++) {
switch(prog[i]){ switch(prog[i]) {
case 'R': case 'R':
pi[pino].poc.resno0 = tcp->resS; pi[pino].poc.resno0 = tcp->resS;
pi[pino].poc.resno1 = tcp->resE; pi[pino].poc.resno1 = tcp->resE;
@ -1584,7 +1581,7 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.layno1 = tcp->layE; pi[pino].poc.layno1 = tcp->layE;
break; break;
case 'P': case 'P':
switch(tcp->prg){ switch(tcp->prg) {
case OPJ_LRCP: case OPJ_LRCP:
case OPJ_RLCP: case OPJ_RLCP:
pi[pino].poc.precno0 = tcp->prcS; pi[pino].poc.precno0 = tcp->prcS;
@ -1601,9 +1598,9 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
} }
if(tpnum==0){ if(tpnum==0) {
for(i=tppos;i>=0;i--){ for(i=tppos; i>=0; i--) {
switch(prog[i]){ switch(prog[i]) {
case 'C': case 'C':
tcp->comp_t = tcp->compS; tcp->comp_t = tcp->compS;
pi[pino].poc.compno0 = tcp->comp_t; pi[pino].poc.compno0 = tcp->comp_t;
@ -1623,7 +1620,7 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
tcp->lay_t+=1; tcp->lay_t+=1;
break; break;
case 'P': case 'P':
switch(tcp->prg){ switch(tcp->prg) {
case OPJ_LRCP: case OPJ_LRCP:
case OPJ_RLCP: case OPJ_RLCP:
tcp->prc_t = tcp->prcS; tcp->prc_t = tcp->prcS;
@ -1646,9 +1643,9 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
} }
incr_top=1; incr_top=1;
}else{ } else {
for(i=tppos;i>=0;i--){ for(i=tppos; i>=0; i--) {
switch(prog[i]){ switch(prog[i]) {
case 'C': case 'C':
pi[pino].poc.compno0 = tcp->comp_t-1; pi[pino].poc.compno0 = tcp->comp_t-1;
pi[pino].poc.compno1 = tcp->comp_t; pi[pino].poc.compno1 = tcp->comp_t;
@ -1662,7 +1659,7 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
pi[pino].poc.layno1 = tcp->lay_t; pi[pino].poc.layno1 = tcp->lay_t;
break; break;
case 'P': case 'P':
switch(tcp->prg){ switch(tcp->prg) {
case OPJ_LRCP: case OPJ_LRCP:
case OPJ_RLCP: case OPJ_RLCP:
pi[pino].poc.precno0 = tcp->prc_t-1; pi[pino].poc.precno0 = tcp->prc_t-1;
@ -1677,20 +1674,20 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
break; break;
} }
if(incr_top==1){ if(incr_top==1) {
switch(prog[i]){ switch(prog[i]) {
case 'R': case 'R':
if(tcp->res_t==tcp->resE){ if(tcp->res_t==tcp->resE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
tcp->res_t = tcp->resS; tcp->res_t = tcp->resS;
pi[pino].poc.resno0 = tcp->res_t; pi[pino].poc.resno0 = tcp->res_t;
pi[pino].poc.resno1 = tcp->res_t+1; pi[pino].poc.resno1 = tcp->res_t+1;
tcp->res_t+=1; tcp->res_t+=1;
incr_top=1; incr_top=1;
}else{ } else {
incr_top=0; incr_top=0;
} }
}else{ } else {
pi[pino].poc.resno0 = tcp->res_t; pi[pino].poc.resno0 = tcp->res_t;
pi[pino].poc.resno1 = tcp->res_t+1; pi[pino].poc.resno1 = tcp->res_t+1;
tcp->res_t+=1; tcp->res_t+=1;
@ -1698,17 +1695,17 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
break; break;
case 'C': case 'C':
if(tcp->comp_t ==tcp->compE){ if(tcp->comp_t ==tcp->compE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
tcp->comp_t = tcp->compS; tcp->comp_t = tcp->compS;
pi[pino].poc.compno0 = tcp->comp_t; pi[pino].poc.compno0 = tcp->comp_t;
pi[pino].poc.compno1 = tcp->comp_t+1; pi[pino].poc.compno1 = tcp->comp_t+1;
tcp->comp_t+=1; tcp->comp_t+=1;
incr_top=1; incr_top=1;
}else{ } else {
incr_top=0; incr_top=0;
} }
}else{ } else {
pi[pino].poc.compno0 = tcp->comp_t; pi[pino].poc.compno0 = tcp->comp_t;
pi[pino].poc.compno1 = tcp->comp_t+1; pi[pino].poc.compno1 = tcp->comp_t+1;
tcp->comp_t+=1; tcp->comp_t+=1;
@ -1716,17 +1713,17 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
break; break;
case 'L': case 'L':
if(tcp->lay_t == tcp->layE){ if(tcp->lay_t == tcp->layE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
tcp->lay_t = tcp->layS; tcp->lay_t = tcp->layS;
pi[pino].poc.layno0 = tcp->lay_t; pi[pino].poc.layno0 = tcp->lay_t;
pi[pino].poc.layno1 = tcp->lay_t+1; pi[pino].poc.layno1 = tcp->lay_t+1;
tcp->lay_t+=1; tcp->lay_t+=1;
incr_top=1; incr_top=1;
}else{ } else {
incr_top=0; incr_top=0;
} }
}else{ } else {
pi[pino].poc.layno0 = tcp->lay_t; pi[pino].poc.layno0 = tcp->lay_t;
pi[pino].poc.layno1 = tcp->lay_t+1; pi[pino].poc.layno1 = tcp->lay_t+1;
tcp->lay_t+=1; tcp->lay_t+=1;
@ -1734,20 +1731,20 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
break; break;
case 'P': case 'P':
switch(tcp->prg){ switch(tcp->prg) {
case OPJ_LRCP: case OPJ_LRCP:
case OPJ_RLCP: case OPJ_RLCP:
if(tcp->prc_t == tcp->prcE){ if(tcp->prc_t == tcp->prcE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
tcp->prc_t = tcp->prcS; tcp->prc_t = tcp->prcS;
pi[pino].poc.precno0 = tcp->prc_t; pi[pino].poc.precno0 = tcp->prc_t;
pi[pino].poc.precno1 = tcp->prc_t+1; pi[pino].poc.precno1 = tcp->prc_t+1;
tcp->prc_t+=1; tcp->prc_t+=1;
incr_top=1; incr_top=1;
}else{ } else {
incr_top=0; incr_top=0;
} }
}else{ } else {
pi[pino].poc.precno0 = tcp->prc_t; pi[pino].poc.precno0 = tcp->prc_t;
pi[pino].poc.precno1 = tcp->prc_t+1; pi[pino].poc.precno1 = tcp->prc_t+1;
tcp->prc_t+=1; tcp->prc_t+=1;
@ -1755,30 +1752,33 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi,
} }
break; break;
default: default:
if(tcp->tx0_t >= tcp->txE){ if(tcp->tx0_t >= tcp->txE) {
if(tcp->ty0_t >= tcp->tyE){ if(tcp->ty0_t >= tcp->tyE) {
if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)) {
tcp->ty0_t = tcp->tyS; tcp->ty0_t = tcp->tyS;
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;
}else{ resetX=1;
incr_top=0;resetX=0; } else {
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;
pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx)); pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx));
tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
} }
}else{ } else {
pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t;
pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx)); pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx));
tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1;
@ -1804,10 +1804,10 @@ void opj_pi_destroy(opj_pi_iterator_t *p_pi,
opj_free(p_pi->include); opj_free(p_pi->include);
p_pi->include = 00; p_pi->include = 00;
} }
for (pino = 0; pino < p_nb_elements; ++pino){ for (pino = 0; pino < p_nb_elements; ++pino) {
if(l_current_pi->comps) { if(l_current_pi->comps) {
opj_pi_comp_t *l_current_component = l_current_pi->comps; opj_pi_comp_t *l_current_component = l_current_pi->comps;
for (compno = 0; compno < l_current_pi->numcomps; compno++){ for (compno = 0; compno < l_current_pi->numcomps; compno++) {
if(l_current_component->resolutions) { if(l_current_component->resolutions) {
opj_free(l_current_component->resolutions); opj_free(l_current_component->resolutions);
l_current_component->resolutions = 00; l_current_component->resolutions = 00;
@ -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

@ -62,7 +62,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
lenp = -1; lenp = -1;
box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t));
for (i=0;i<2;i++){ for (i=0; i<2; i++) {
if (i) if (i)
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
@ -74,7 +74,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused,
opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager); opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager);
for (compno=0; compno<cstr_info.numcomps; compno++){ for (compno=0; compno<cstr_info.numcomps; compno++) {
box[compno].length = (OPJ_UINT32)opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager); box[compno].length = (OPJ_UINT32)opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
box[compno].type = JPIP_FAIX; box[compno].type = JPIP_FAIX;
} }
@ -109,11 +109,10 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
packet.end_pos = packet.end_ph_pos = packet.start_pos = -1; packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */ (void)EPHused; /* unused ? */
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;
} }
@ -133,19 +132,19 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
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( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++){ for( tileno=0; tileno<(OPJ_UINT32)(cstr_info.tw*cstr_info.th); tileno++) {
tile_Idx = &cstr_info.tile[ tileno]; tile_Idx = &cstr_info.tile[ tileno];
num_packet=0; num_packet=0;
numOfres = cstr_info.numdecompos[compno] + 1; numOfres = cstr_info.numdecompos[compno] + 1;
for( resno=0; resno<numOfres ; resno++){ for( resno=0; resno<numOfres ; resno++) {
numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno]; numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
for( precno=0; precno<numOfprec; precno++){ for( precno=0; precno<numOfprec; precno++) {
numOflayers = cstr_info.numlayers; numOflayers = cstr_info.numlayers;
for( layno=0; layno<numOflayers; layno++){ for( layno=0; layno<numOflayers; layno++) {
switch ( cstr_info.prog){ switch ( cstr_info.prog) {
case OPJ_LRCP: case OPJ_LRCP:
packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
break; break;
@ -175,7 +174,7 @@ int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, O
} }
} }
while( num_packet < nmax){ /* PADDING */ while( num_packet < nmax) { /* PADDING */
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);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,0,size_of_coding);/* length */

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;
@ -1171,10 +1178,10 @@ static OPJ_BOOL opj_t1_allocate_buffers(
/* encoder uses tile buffer, so no need to allocate */ /* encoder uses tile buffer, so no need to allocate */
if (!t1->encoder) { if (!t1->encoder) {
if(datasize > t1->datasize){ if(datasize > t1->datasize) {
opj_aligned_free(t1->data); opj_aligned_free(t1->data);
t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32)); t1->data = (OPJ_INT32*) opj_aligned_malloc(datasize * sizeof(OPJ_INT32));
if(!t1->data){ if(!t1->data) {
/* FIXME event manager error callback */ /* FIXME event manager error callback */
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -1185,10 +1192,10 @@ static OPJ_BOOL opj_t1_allocate_buffers(
t1->flags_stride=w+2; t1->flags_stride=w+2;
flagssize=t1->flags_stride * (h+2); flagssize=t1->flags_stride * (h+2);
if(flagssize > t1->flagssize){ if(flagssize > t1->flagssize) {
opj_aligned_free(t1->flags); opj_aligned_free(t1->flags);
t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t)); t1->flags = (opj_flag_t*) opj_aligned_malloc(flagssize * sizeof(opj_flag_t));
if(!t1->flags){ if(!t1->flags) {
/* FIXME event manager error callback */ /* FIXME event manager error callback */
return OPJ_FALSE; return OPJ_FALSE;
} }
@ -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;
} }
@ -1394,7 +1400,7 @@ static OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1,
/* BYPASS mode */ /* BYPASS mode */
type = ((bpno_plus_one <= ((OPJ_INT32) (cblk->numbps)) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; type = ((bpno_plus_one <= ((OPJ_INT32) (cblk->numbps)) - 4) && (passtype < 2) && (cblksty & J2K_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ;
/* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */ /* FIXME: slviewer gets here with a null pointer. Why? Partially downloaded and/or corrupt textures? */
if(seg->data == 00){ if(seg->data == 00) {
continue; continue;
} }
if (type == T1_TYPE_RAW) { if (type == T1_TYPE_RAW) {
@ -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;
} }
@ -1688,7 +1693,7 @@ static void opj_t1_encode_cblk(opj_t1_t *t1,
if (pass->rate > opj_mqc_numbytes(mqc)) if (pass->rate > opj_mqc_numbytes(mqc))
pass->rate = opj_mqc_numbytes(mqc); pass->rate = opj_mqc_numbytes(mqc);
/*Preventing generation of FF as last data byte of a pass*/ /*Preventing generation of FF as last data byte of a pass*/
if((pass->rate>1) && (cblk->data[pass->rate - 1] == 0xFF)){ if((pass->rate>1) && (cblk->data[pass->rate - 1] == 0xFF)) {
pass->rate--; pass->rate--;
} }
pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate);

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;
@ -234,7 +237,7 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2,
* p_data_written = 0; * p_data_written = 0;
if (p_t2_mode == THRESH_CALC ){ /* Calculating threshold */ if (p_t2_mode == THRESH_CALC ) { /* Calculating threshold */
l_current_pi = l_pi; l_current_pi = l_pi;
for (compno = 0; compno < l_max_comp; ++compno) { for (compno = 0; compno < l_max_comp; ++compno) {
@ -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);
@ -454,7 +454,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2,
tp_start_packno = 0; tp_start_packno = 0;
if (!p_cstr_info->packno) { if (!p_cstr_info->packno) {
info_PK->start_pos = info_TL->end_header + 1; info_PK->start_pos = info_TL->end_header + 1;
} else if (info_TL->packet[p_cstr_info->packno-1].end_pos >= (OPJ_INT32)p_cstr_info->tile[p_tile_no].tp[curtp].tp_end_pos){ /* New tile part */ } else if (info_TL->packet[p_cstr_info->packno-1].end_pos >= (OPJ_INT32)p_cstr_info->tile[p_tile_no].tp[curtp].tp_end_pos) { /* New tile part */
info_TL->tp[curtp].tp_numpacks = p_cstr_info->packno - tp_start_packno; /* Number of packets in previous tile-part */ info_TL->tp[curtp].tp_numpacks = p_cstr_info->packno - tp_start_packno; /* Number of packets in previous tile-part */
tp_start_packno = p_cstr_info->packno; tp_start_packno = p_cstr_info->packno;
curtp++; curtp++;
@ -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];
@ -516,13 +519,12 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
opj_tcd_makelayer(tcd, layno, thresh, 0); opj_tcd_makelayer(tcd, layno, thresh, 0);
if (cp->m_specific_param.m_enc.m_fixed_quality) { /* fixed_quality */ if (cp->m_specific_param.m_enc.m_fixed_quality) { /* fixed_quality */
if(OPJ_IS_CINEMA(cp->rsiz)){ if(OPJ_IS_CINEMA(cp->rsiz)) {
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)) {
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];
@ -530,11 +532,11 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd,
hi=thresh; hi=thresh;
stable_thresh = thresh; stable_thresh = thresh;
continue; continue;
}else{ } else {
lo=thresh; lo=thresh;
} }
} }
}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);
} }
@ -1141,7 +1133,7 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size ( opj_tcd_t *p_tcd )
l_tile_comp = p_tcd->tcd_image->tiles->comps; l_tile_comp = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image->comps; l_img_comp = p_tcd->image->comps;
for (i=0;i<p_tcd->image->numcomps;++i) { for (i=0; i<p_tcd->image->numcomps; ++i) {
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) */
@ -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); */
@ -1356,7 +1343,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd,
l_tilec = p_tcd->tcd_image->tiles->comps; l_tilec = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image->comps; l_img_comp = p_tcd->image->comps;
for (i=0;i<p_tcd->image->numcomps;++i) { for (i=0; i<p_tcd->image->numcomps; ++i) {
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) */
l_res = l_tilec->resolutions + l_img_comp->resno_decoded; l_res = l_tilec->resolutions + l_img_comp->resno_decoded;
@ -1372,24 +1359,21 @@ 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;
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
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++)); *(l_dest_ptr++) = (OPJ_CHAR) (*(l_src_ptr++));
} }
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);
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
@ -1399,22 +1383,20 @@ 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;
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
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++)); *(l_dest_ptr++) = (OPJ_INT16) (*(l_src_ptr++));
} }
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);
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
@ -1424,13 +1406,12 @@ 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;
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++) = (*(l_src_ptr++)); *(l_dest_ptr++) = (*(l_src_ptr++));
} }
l_src_ptr += l_stride; l_src_ptr += l_stride;
@ -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;
} }
@ -1651,15 +1630,14 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
l_samples = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0)); l_samples = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0));
if (l_tile->numcomps >= 3 ){ if (l_tile->numcomps >= 3 ) {
/* testcase 1336.pdf.asan.47.376 */ /* testcase 1336.pdf.asan.47.376 */
if ((l_tile->comps[0].x1 - l_tile->comps[0].x0) * (l_tile->comps[0].y1 - l_tile->comps[0].y0) < (OPJ_INT32)l_samples || if ((l_tile->comps[0].x1 - l_tile->comps[0].x0) * (l_tile->comps[0].y1 - l_tile->comps[0].y0) < (OPJ_INT32)l_samples ||
(l_tile->comps[1].x1 - l_tile->comps[1].x0) * (l_tile->comps[1].y1 - l_tile->comps[1].y0) < (OPJ_INT32)l_samples || (l_tile->comps[1].x1 - l_tile->comps[1].x0) * (l_tile->comps[1].y1 - l_tile->comps[1].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) { (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) {
@ -1671,7 +1649,7 @@ static OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd, opj_event_mgr_t *p_manage
return OPJ_FALSE; return OPJ_FALSE;
} }
for (i=0;i<l_tile->numcomps;++i) { for (i=0; i<l_tile->numcomps; ++i) {
l_data[i] = (OPJ_BYTE*) l_tile_comp->data; l_data[i] = (OPJ_BYTE*) l_tile_comp->data;
++l_tile_comp; ++l_tile_comp;
} }
@ -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;
} }
@ -1753,16 +1727,15 @@ static OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd )
l_current_ptr = l_tile_comp->data; l_current_ptr = l_tile_comp->data;
if (l_tccp->qmfbid == 1) { if (l_tccp->qmfbid == 1) {
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) {
*l_current_ptr = opj_int_clamp(*l_current_ptr + l_tccp->m_dc_level_shift, l_min, l_max); *l_current_ptr = opj_int_clamp(*l_current_ptr + l_tccp->m_dc_level_shift, l_min, l_max);
++l_current_ptr; ++l_current_ptr;
} }
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);
*l_current_ptr = opj_int_clamp((OPJ_INT32)opj_lrintf(l_value) + l_tccp->m_dc_level_shift, l_min, l_max); ; *l_current_ptr = opj_int_clamp((OPJ_INT32)opj_lrintf(l_value) + l_tccp->m_dc_level_shift, l_min, l_max); ;
@ -1864,7 +1837,7 @@ OPJ_UINT32 opj_tcd_get_encoded_tile_size ( opj_tcd_t *p_tcd )
l_tilec = p_tcd->tcd_image->tiles->comps; l_tilec = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image->comps; l_img_comp = p_tcd->image->comps;
for (i=0;i<p_tcd->image->numcomps;++i) { for (i=0; i<p_tcd->image->numcomps; ++i) {
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) */
@ -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;
@ -1947,7 +1919,7 @@ static OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd )
return OPJ_FALSE; return OPJ_FALSE;
} }
for (i=0;i<l_tile->numcomps;++i) { for (i=0; i<l_tile->numcomps; ++i) {
l_data[i] = (OPJ_BYTE*) l_tile_comp->data; l_data[i] = (OPJ_BYTE*) l_tile_comp->data;
++l_tile_comp; ++l_tile_comp;
} }
@ -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);
} }
@ -2125,7 +2089,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd,
l_tilec = p_tcd->tcd_image->tiles->comps; l_tilec = p_tcd->tcd_image->tiles->comps;
l_img_comp = p_tcd->image->comps; l_img_comp = p_tcd->image->comps;
for (i=0;i<p_tcd->image->numcomps;++i) { for (i=0; i<p_tcd->image->numcomps; ++i) {
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) */
l_nb_elem = (OPJ_UINT32)((l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0)); l_nb_elem = (OPJ_UINT32)((l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0));
@ -2139,18 +2103,16 @@ 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;
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
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,18 +2120,16 @@ 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;
if (l_img_comp->sgnd) { if (l_img_comp->sgnd) {
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,12 +2137,11 @@ 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;
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++));
} }

View File

@ -120,7 +120,7 @@ FIXME DOC
typedef struct opj_tcd_precinct { typedef struct opj_tcd_precinct {
OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_INT32 x0, y0, x1, y1; /* dimension of the precinct : left upper corner (x0, y0) right low corner (x1,y1) */
OPJ_UINT32 cw, ch; /* number of precinct in width and height */ OPJ_UINT32 cw, ch; /* number of precinct in width and height */
union{ /* code-blocks information */ union { /* code-blocks information */
opj_tcd_cblk_enc_t* enc; opj_tcd_cblk_enc_t* enc;
opj_tcd_cblk_dec_t* dec; opj_tcd_cblk_dec_t* dec;
void* blocks; void* blocks;
@ -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;
@ -143,7 +144,7 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O
OPJ_UINT32 n; OPJ_UINT32 n;
OPJ_UINT32 l_node_size; OPJ_UINT32 l_node_size;
if (! p_tree){ if (! p_tree) {
return 00; return 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

@ -50,7 +50,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
lenp = 0; lenp = 0;
box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t));
for ( i = 0; i < 2 ; i++ ){ for ( i = 0; i < 2 ; i++ ) {
if (i) if (i)
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
@ -61,7 +61,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat
opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager); opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager);
for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){ for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++) {
box[tileno].length = (OPJ_UINT32)opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager); box[tileno].length = (OPJ_UINT32)opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
box[tileno].type = JPIP_MHIX; box[tileno].type = JPIP_MHIX;
} }
@ -112,7 +112,7 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o
marker = cstr_info.tile[tileno].marker; marker = cstr_info.tile[tileno].marker;
for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */ for( i=0; i<cstr_info.tile[tileno].marknum; i++) { /* Marker restricted to 1 apparition */
opj_write_bytes( l_data_header, marker[i].type, 2); opj_write_bytes( l_data_header, marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2); opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);

View File

@ -102,11 +102,10 @@ int opj_write_tpixfaix( int coff,
num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info); num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info);
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,8 +109,9 @@ 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

@ -49,15 +49,15 @@ The functions in BIO.C have for goal to realize an individual bit input - output
Individual bit input-output stream (BIO) Individual bit input-output stream (BIO)
*/ */
typedef struct opj_bio { typedef struct opj_bio {
/** pointer to the start of the buffer */ /** pointer to the start of the buffer */
unsigned char *start; unsigned char *start;
/** pointer to the end of the buffer */ /** pointer to the end of the buffer */
unsigned char *end; unsigned char *end;
/** pointer to the present position in the buffer */ /** pointer to the present position in the buffer */
unsigned char *bp; unsigned char *bp;
/** temporary place where each byte is read or written */ /** temporary place where each byte is read or written */
unsigned int buf; unsigned int buf;
/** coder : number of bits free to write. decoder : number of bits read */ /** coder : number of bits free to write. decoder : number of bits read */
int ct; int ct;
} opj_bio_t; } opj_bio_t;

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,18 +344,19 @@ 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) {
if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */ if ((dn > 0) || (sn > 1)) { /* NEW : CASE ONE ELEMENT */
/*for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1;*/ /*for (i = 0; i < dn; i++) D(i) -= (S_(i) + S_(i + 1)) >> 1;*/
/*for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2;*/ /*for (i = 0; i < sn; i++) S(i) += (D_(i - 1) + D_(i) + 2) >> 2;*/
for (i = 0; i < dn; i++){ for (i = 0; i < dn; i++) {
D(i) -= (S_(i) + S_(i + 1)) >> 1; D(i) -= (S_(i) + S_(i + 1)) >> 1;
/*ops += 2;*/ /*ops += 2;*/
} }
for (i = 0; i < sn; i++){ for (i = 0; i < sn; i++) {
S(i) += (D_(i - 1) + D_(i) + 2) >> 2; S(i) += (D_(i - 1) + D_(i) + 2) >> 2;
/*ops += 3;*/ /*ops += 3;*/
} }
@ -358,22 +368,23 @@ static void dwt_encode_53(int *a, int dn, int sn, int cas) {
for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1; for (i = 0; i < dn; i++) S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2; for (i = 0; i < sn; i++) D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
}*/ }*/
if (!sn && dn == 1){ if (!sn && dn == 1) {
S(0) *= 2; S(0) *= 2;
/*ops++;*/ /*ops++;*/
} else { } else {
for (i = 0; i < dn; i++){ for (i = 0; i < dn; i++) {
S(i) -= (DD_(i) + DD_(i - 1)) >> 1; S(i) -= (DD_(i) + DD_(i - 1)) >> 1;
/* ops += 2;*/ /* ops += 2;*/
} }
for (i = 0; i < sn; i++){ for (i = 0; i < sn; i++) {
D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2; D(i) += (SS_(i) + SS_(i + 1) + 2) >> 2;
/* ops += 3;*/ /* ops += 3;*/
} }
} }
} }
} }
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;
@ -528,7 +543,7 @@ static double dwt_calc_wtnorms(int orient, int level[3], int dwtid[3], opj_wtfil
free(nHPSx); free(nHPSx);
/*Y axis*/ /*Y axis*/
if (dwtid[0] != dwtid[1] || level[0] != level[1]){ if (dwtid[0] != dwtid[1] || level[0] != level[1]) {
lenLPS = wtfiltY->lenLPS; lenLPS = wtfiltY->lenLPS;
lenHPS = wtfiltY->lenHPS; lenHPS = wtfiltY->lenHPS;
for (i = 0; i < levely; i++) { for (i = 0; i < levely; i++) {
@ -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;
@ -763,7 +794,7 @@ void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]) {
opj_free(bj); opj_free(bj);
} }
if (z < levelz){ if (z < levelz) {
/*Axial fprintf(stdout,"Axial DWT Transform %d %d %d\n",z,rd,rd1);*/ /*Axial fprintf(stdout,"Axial DWT Transform %d %d %d\n",z,rd,rd1);*/
sn = rd1; sn = rd1;
dn = rd - rd1; dn = rd - rd1;
@ -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;
@ -816,7 +848,7 @@ void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]) {
level = int_max(levelx,int_max(levely,levelz)); level = int_max(levelx,int_max(levely,levelz));
diff = tilec->numresolution[0] - tilec->numresolution[2]; diff = tilec->numresolution[0] - tilec->numresolution[2];
/* General lifting framework -- DCCS-LIWT */ /* General lifting framework -- DCCS-LIWT */
for (x = level - 1, y = level - 1, z = level - 1; (x >= stops[0]) && (y >= stops[1]); x--, y--, z--) { for (x = level - 1, y = level - 1, z = level - 1; (x >= stops[0]) && (y >= stops[1]); x--, y--, z--) {
int rw; /* width of the resolution level computed */ int rw; /* width of the resolution level computed */
int rh; /* heigth of the resolution level computed */ int rh; /* heigth of the resolution level computed */
@ -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;
@ -536,7 +542,7 @@ static void j3d_write_dco(opj_j3d_t *j3d){
for (i = 0; i < volume->numcomps; i++) for (i = 0; i < volume->numcomps; i++)
cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */ cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */
} else if (dcotype == 1) { } else if (dcotype == 1) {
for (i = 0; i < volume->numcomps; i++){ for (i = 0; i < volume->numcomps; i++) {
cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */ cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */
opj_event_msg(j3d->cinfo, EVT_INFO, "dcotype %d DCO %d \n",dcotype,volume->comps[i].dcoffset); opj_event_msg(j3d->cinfo, EVT_INFO, "dcotype %d DCO %d \n",dcotype,volume->comps[i].dcoffset);
} }
@ -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;
@ -587,10 +595,10 @@ static void j3d_write_atk(opj_j3d_t *j3d){
if (atk->wt_typ == J3D_ATK_IRR) if (atk->wt_typ == J3D_ATK_IRR)
cio_write(cio,(unsigned int) (atk->Katk * 8192.0), 1 << atk->coeff_typ); cio_write(cio,(unsigned int) (atk->Katk * 8192.0), 1 << atk->coeff_typ);
cio_write(cio, atk->Natk, 1); cio_write(cio, atk->Natk, 1);
for (s = 0; s < atk->Natk; s++){ for (s = 0; s < atk->Natk; s++) {
if (atk->filt_cat == J3D_ATK_ARB) if (atk->filt_cat == J3D_ATK_ARB)
cio_write(cio, atk->Oatk[s], 1); cio_write(cio, atk->Oatk[s], 1);
if (atk->wt_typ == J3D_ATK_REV){ if (atk->wt_typ == J3D_ATK_REV) {
cio_write(cio, atk->Eatk[s], 1); cio_write(cio, atk->Eatk[s], 1);
cio_write(cio, atk->Batk[s], 1); cio_write(cio, atk->Batk[s], 1);
} }
@ -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;
@ -625,7 +634,7 @@ static void j3d_read_atk(opj_j3d_t *j3d){
for (i = 0; i < atk->Natk; i++) { for (i = 0; i < atk->Natk; i++) {
if (atk->filt_cat == J3D_ATK_ARB) if (atk->filt_cat == J3D_ATK_ARB)
atk->Oatk[i] = cio_read(cio, 1); atk->Oatk[i] = cio_read(cio, 1);
if (atk->wt_typ == J3D_ATK_REV){ if (atk->wt_typ == J3D_ATK_REV) {
atk->Eatk[i] = cio_read(cio, 1); atk->Eatk[i] = cio_read(cio, 1);
atk->Batk[i] = cio_read(cio, 1); atk->Batk[i] = cio_read(cio, 1);
} }
@ -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;
@ -734,7 +757,7 @@ static void j3d_read_siz(opj_j3d_t *j3d) {
} }
} }
if (j3d->cinfo->codec_format == CODEC_J2K){ if (j3d->cinfo->codec_format == CODEC_J2K) {
volume->z1 = 1; volume->z1 = 1;
volume->z0 = 0; volume->z0 = 0;
volume->numslices = 1; volume->numslices = 1;
@ -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;
@ -867,7 +894,7 @@ static void j3d_read_cox(opj_j3d_t *j3d, int compno) {
if (j3d->cinfo->codec_format == CODEC_J3D) { if (j3d->cinfo->codec_format == CODEC_J3D) {
tccp->numresolution[1] = cio_read(cio, 1) + 1; /* SPcox (E) No of decomposition levels in y-axis*/ tccp->numresolution[1] = cio_read(cio, 1) + 1; /* SPcox (E) No of decomposition levels in y-axis*/
tccp->numresolution[2] = cio_read(cio, 1) + 1; /* SPcox (F) No of decomposition levels in z-axis*/ tccp->numresolution[2] = cio_read(cio, 1) + 1; /* SPcox (F) No of decomposition levels in z-axis*/
}else if (j3d->cinfo->codec_format == CODEC_J2K) { } else if (j3d->cinfo->codec_format == CODEC_J2K) {
tccp->numresolution[1] = tccp->numresolution[0]; tccp->numresolution[1] = tccp->numresolution[0];
tccp->numresolution[2] = 1; tccp->numresolution[2] = 1;
} }
@ -892,7 +919,7 @@ static void j3d_read_cox(opj_j3d_t *j3d, int compno) {
if (j3d->cinfo->codec_format == CODEC_J3D) { if (j3d->cinfo->codec_format == CODEC_J3D) {
tccp->dwtid[1] = cio_read(cio, 1); /* SPcox (L) */ tccp->dwtid[1] = cio_read(cio, 1); /* SPcox (L) */
tccp->dwtid[2] = cio_read(cio, 1); /* SPcox (M) */ tccp->dwtid[2] = cio_read(cio, 1); /* SPcox (M) */
}else{ } else {
tccp->dwtid[1] = tccp->dwtid[0]; /* SPcox (L) */ tccp->dwtid[1] = tccp->dwtid[0]; /* SPcox (L) */
tccp->dwtid[2] = tccp->dwtid[0]; /* SPcox (M) */ tccp->dwtid[2] = tccp->dwtid[0]; /* SPcox (M) */
} }
@ -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

@ -153,31 +153,31 @@ typedef enum J3D_STATUS {
Arbitrary transformation kernel Arbitrary transformation kernel
*/ */
typedef struct opj_atk { typedef struct opj_atk {
/** index of wavelet kernel */ /** index of wavelet kernel */
int index; int index;
/** Numerical type of scaling factor and lifting step parameters */ /** Numerical type of scaling factor and lifting step parameters */
int coeff_typ; int coeff_typ;
/** Wavelet filter category */ /** Wavelet filter category */
int filt_cat; int filt_cat;
/** Wavelet transformation type (REV/IRR) */ /** Wavelet transformation type (REV/IRR) */
int wt_typ; int wt_typ;
/** Initial odd/even subsequence */ /** Initial odd/even subsequence */
int minit; int minit;
/** Boundary extension method (constant CON / whole-sample symmetric WS) */ /** Boundary extension method (constant CON / whole-sample symmetric WS) */
int exten; int exten;
/** Scaling factor. Only for wt_typ=IRR */ /** Scaling factor. Only for wt_typ=IRR */
double Katk; double Katk;
/** Number of lifting steps */ /** Number of lifting steps */
int Natk; int Natk;
/** Offset for lifting step s. Only for filt_cat=ARB */ /** Offset for lifting step s. Only for filt_cat=ARB */
int Oatk[256]; int Oatk[256];
/** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */ /** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */
int Eatk[256]; int Eatk[256];
/** Additive residue for lifting step s. Only for wt_typ=REV */ /** Additive residue for lifting step s. Only for wt_typ=REV */
int Batk[256]; int Batk[256];
/** Number of lifting coefficients signaled for lifting step s */ /** Number of lifting coefficients signaled for lifting step s */
int LCatk[256]; int LCatk[256];
/** Lifting coefficient k for lifting step s */ /** Lifting coefficient k for lifting step s */
double Aatk[256][256]; double Aatk[256][256];
} opj_atk_t; } opj_atk_t;
@ -186,9 +186,9 @@ typedef struct opj_atk {
Quantization stepsize Quantization stepsize
*/ */
typedef struct opj_stepsize { typedef struct opj_stepsize {
/** exponent */ /** exponent */
int expn; int expn;
/** mantissa */ /** mantissa */
int mant; int mant;
} opj_stepsize_t; } opj_stepsize_t;
@ -229,7 +229,7 @@ Tile coding parameters : coding/decoding parameters common to all tiles
(information like COD, COC in main header) (information like COD, COC in main header)
*/ */
typedef struct opj_tcp { typedef struct opj_tcp {
/** 1 : first part-tile of a tile */ /** 1 : first part-tile of a tile */
int first; int first;
/** coding style */ /** coding style */
int csty; int csty;
@ -251,7 +251,7 @@ typedef struct opj_tcp {
float distoratio[100]; float distoratio[100];
/** tile-component coding parameters */ /** tile-component coding parameters */
opj_tccp_t *tccps; opj_tccp_t *tccps;
/** packet header store there for futur use in t2_decode_packet */ /** packet header store there for futur use in t2_decode_packet */
unsigned char *ppt_data; unsigned char *ppt_data;
/** pointer remaining on the first byte of the first header if ppt is used */ /** pointer remaining on the first byte of the first header if ppt is used */
unsigned char *ppt_data_first; unsigned char *ppt_data_first;
@ -266,7 +266,7 @@ typedef struct opj_tcp {
Coding parameters Coding parameters
*/ */
typedef struct opj_cp { typedef struct opj_cp {
/** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
OPJ_TRANSFORM transform_format; OPJ_TRANSFORM transform_format;
/** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ /** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/
OPJ_ENTROPY_CODING encoding_format; OPJ_ENTROPY_CODING encoding_format;

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

@ -129,17 +129,17 @@ braindamage below.
/** Progression order */ /** Progression order */
typedef enum PROG_ORDER { typedef enum PROG_ORDER {
/**< place-holder */ /**< place-holder */
PROG_UNKNOWN = -1, PROG_UNKNOWN = -1,
/**< layer-resolution-component-precinct order */ /**< layer-resolution-component-precinct order */
LRCP = 0, LRCP = 0,
/**< resolution-layer-component-precinct order */ /**< resolution-layer-component-precinct order */
RLCP = 1, RLCP = 1,
/**< resolution-precinct-component-layer order */ /**< resolution-precinct-component-layer order */
RPCL = 2, RPCL = 2,
/**< precinct-component-resolution-layer order */ /**< precinct-component-resolution-layer order */
PCRL = 3, PCRL = 3,
/**< component-precinct-resolution-layer order */ /**< component-precinct-resolution-layer order */
CPRL = 4 CPRL = 4
} OPJ_PROG_ORDER; } OPJ_PROG_ORDER;
@ -147,13 +147,13 @@ typedef enum PROG_ORDER {
Supported volume color spaces Supported volume color spaces
*/ */
typedef enum COLOR_SPACE { typedef enum COLOR_SPACE {
/**< place-holder */ /**< place-holder */
CLRSPC_UNKNOWN = -1, CLRSPC_UNKNOWN = -1,
/**< sRGB */ /**< sRGB */
CLRSPC_SRGB = 1, CLRSPC_SRGB = 1,
/**< grayscale */ /**< grayscale */
CLRSPC_GRAY = 2, CLRSPC_GRAY = 2,
/**< YUV */ /**< YUV */
CLRSPC_SYCC = 3 CLRSPC_SYCC = 3
} OPJ_COLOR_SPACE; } OPJ_COLOR_SPACE;
@ -163,9 +163,9 @@ Supported codec
typedef enum CODEC_FORMAT { typedef enum CODEC_FORMAT {
/**< place-holder */ /**< place-holder */
CODEC_UNKNOWN = -1, CODEC_UNKNOWN = -1,
/**< JPEG-2000 codestream : read/write */ /**< JPEG-2000 codestream : read/write */
CODEC_J2K = 0, CODEC_J2K = 0,
/**< JPEG-2000 Part 10 file format : read/write */ /**< JPEG-2000 Part 10 file format : read/write */
CODEC_J3D = 1 CODEC_J3D = 1
} OPJ_CODEC_FORMAT; } OPJ_CODEC_FORMAT;
@ -173,15 +173,15 @@ typedef enum CODEC_FORMAT {
Supported entropy coding algorithms Supported entropy coding algorithms
*/ */
typedef enum ENTROPY_CODING { typedef enum ENTROPY_CODING {
/**< place-holder */ /**< place-holder */
ENCOD_UNKNOWN = -1, ENCOD_UNKNOWN = -1,
/**< 2D EBCOT encoding */ /**< 2D EBCOT encoding */
ENCOD_2EB = 0, ENCOD_2EB = 0,
/**< 3D EBCOT encoding */ /**< 3D EBCOT encoding */
ENCOD_3EB = 1, ENCOD_3EB = 1,
/**< Golomb-Rice coding with 2D context */ /**< Golomb-Rice coding with 2D context */
ENCOD_2GR = 2, ENCOD_2GR = 2,
/**< Golomb-Rice coding with 3D context */ /**< Golomb-Rice coding with 3D context */
ENCOD_3GR = 3 ENCOD_3GR = 3
} OPJ_ENTROPY_CODING; } OPJ_ENTROPY_CODING;
@ -189,13 +189,13 @@ typedef enum ENTROPY_CODING {
Supported transforms Supported transforms
*/ */
typedef enum TRANSFORM { typedef enum TRANSFORM {
/**< place-holder */ /**< place-holder */
TRF_UNKNOWN = -1, TRF_UNKNOWN = -1,
/**< 2D DWT, no transform in axial dim */ /**< 2D DWT, no transform in axial dim */
TRF_2D_DWT = 0, TRF_2D_DWT = 0,
/**< 3D DWT */ /**< 3D DWT */
TRF_3D_DWT = 1, TRF_3D_DWT = 1,
/**< 3D prediction*/ /**< 3D prediction*/
TRF_3D_RLS = 2, TRF_3D_RLS = 2,
TRF_3D_LSE = 3 TRF_3D_LSE = 3
} OPJ_TRANSFORM; } OPJ_TRANSFORM;
@ -253,73 +253,73 @@ typedef struct opj_poc {
Compression parameters Compression parameters
*/ */
typedef struct opj_cparameters { typedef struct opj_cparameters {
/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */ /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
bool tile_size_on; bool tile_size_on;
/** XTOsiz */ /** XTOsiz */
int cp_tx0; int cp_tx0;
/** YTOsiz */ /** YTOsiz */
int cp_ty0; int cp_ty0;
/** ZTOsiz */ /** ZTOsiz */
int cp_tz0; int cp_tz0;
/** XTsiz */ /** XTsiz */
int cp_tdx; int cp_tdx;
/** YTsiz */ /** YTsiz */
int cp_tdy; int cp_tdy;
/** ZTsiz */ /** ZTsiz */
int cp_tdz; int cp_tdz;
/** allocation by rate/distortion */ /** allocation by rate/distortion */
int cp_disto_alloc; int cp_disto_alloc;
/** allocation by fixed layer */ /** allocation by fixed layer */
int cp_fixed_alloc; int cp_fixed_alloc;
/** add fixed_quality */ /** add fixed_quality */
int cp_fixed_quality; int cp_fixed_quality;
/** fixed layer */ /** fixed layer */
int *cp_matrice; int *cp_matrice;
/** number of layers */ /** number of layers */
int tcp_numlayers; int tcp_numlayers;
/** rates for successive layers */ /** rates for successive layers */
float tcp_rates[100]; float tcp_rates[100];
/** psnr's for successive layers */ /** psnr's for successive layers */
float tcp_distoratio[100]; float tcp_distoratio[100];
/** comment for coding */ /** comment for coding */
char *cp_comment; char *cp_comment;
/** csty : coding style */ /** csty : coding style */
int csty; int csty;
/** DC offset (DCO) */ /** DC offset (DCO) */
int dcoffset; int dcoffset;
/** progression order (default LRCP) */ /** progression order (default LRCP) */
OPJ_PROG_ORDER prog_order; OPJ_PROG_ORDER prog_order;
/** progression order changes */ /** progression order changes */
opj_poc_t POC[J3D_MAXRLVLS-1]; opj_poc_t POC[J3D_MAXRLVLS-1];
/** number of progression order changes (POC), default to 0 */ /** number of progression order changes (POC), default to 0 */
int numpocs; int numpocs;
/** number of resolutions */ /** number of resolutions */
int numresolution[3]; int numresolution[3];
/** initial code block width, height and depth, default to 64 */ /** initial code block width, height and depth, default to 64 */
int cblock_init[3]; int cblock_init[3];
/** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */ /** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */
int mode; int mode;
/** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */ /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
int irreversible; int irreversible;
/** WT from ATK, default to 0 (false), no of atk used */ /** WT from ATK, default to 0 (false), no of atk used */
int atk_wt[3]; int atk_wt[3];
/** region of interest: affected component in [0..3], -1 means no ROI */ /** region of interest: affected component in [0..3], -1 means no ROI */
int roi_compno; int roi_compno;
/** region of interest: upshift value */ /** region of interest: upshift value */
int roi_shift; int roi_shift;
/* number of precinct size specifications */ /* number of precinct size specifications */
int res_spec; int res_spec;
/** initial precinct width */ /** initial precinct width */
int prct_init[3][J3D_MAXRLVLS]; int prct_init[3][J3D_MAXRLVLS];
/** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ /** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */
OPJ_TRANSFORM transform_format; OPJ_TRANSFORM transform_format;
/** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */ /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */
OPJ_ENTROPY_CODING encoding_format; OPJ_ENTROPY_CODING encoding_format;
/**@name command line encoder parameters (not used inside the library) */ /**@name command line encoder parameters (not used inside the library) */
@ -347,27 +347,27 @@ typedef struct opj_cparameters {
Decompression parameters Decompression parameters
*/ */
typedef struct opj_dparameters { typedef struct opj_dparameters {
/** Set the number of highest resolution levels to be discarded. if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */ /** Set the number of highest resolution levels to be discarded. if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */
int cp_reduce[3]; int cp_reduce[3];
/** Set the maximum number of quality layers to decode. if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ /** Set the maximum number of quality layers to decode. if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */
int cp_layer; int cp_layer;
int bigendian; int bigendian;
/**@name command line encoder parameters (not used inside the library) */ /**@name command line encoder parameters (not used inside the library) */
/*@{*/ /*@{*/
/** input file name */ /** input file name */
char infile[MAX_PATH]; char infile[MAX_PATH];
/** output file name */ /** output file name */
char outfile[MAX_PATH]; char outfile[MAX_PATH];
/** IMG file name for BIN volumes*/ /** IMG file name for BIN volumes*/
char imgfile[MAX_PATH]; char imgfile[MAX_PATH];
/** Original file name for PSNR measures*/ /** Original file name for PSNR measures*/
char original[MAX_PATH]; char original[MAX_PATH];
/** input file format 0: J2K, 1: JP3D */ /** input file format 0: J2K, 1: JP3D */
int decod_format; int decod_format;
/** input file format 0: BIN, 1: PGM */ /** input file format 0: BIN, 1: PGM */
int cod_format; int cod_format;
/** original file format 0: BIN, 1: PGM */ /** original file format 0: BIN, 1: PGM */
int orig_format; int orig_format;
/*@}*/ /*@}*/
} opj_dparameters_t; } opj_dparameters_t;
@ -432,19 +432,19 @@ typedef struct opj_dinfo {
Byte input-output stream (CIO) Byte input-output stream (CIO)
*/ */
typedef struct opj_cio { typedef struct opj_cio {
/** codec context */ /** codec context */
opj_common_ptr cinfo; opj_common_ptr cinfo;
/** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */ /** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */
int openmode; int openmode;
/** pointer to the start of the buffer */ /** pointer to the start of the buffer */
unsigned char *buffer; unsigned char *buffer;
/** buffer size in bytes */ /** buffer size in bytes */
int length; int length;
/** pointer to the start of the stream */ /** pointer to the start of the stream */
unsigned char *start; unsigned char *start;
/** pointer to the end of the stream */ /** pointer to the end of the stream */
unsigned char *end; unsigned char *end;
/** pointer to the current position */ /** pointer to the current position */
unsigned char *bp; unsigned char *bp;
} opj_cio_t; } opj_cio_t;
@ -458,13 +458,13 @@ typedef struct opj_cio {
Defines a single volume component Defines a single volume component
*/ */
typedef struct opj_volume_comp { typedef struct opj_volume_comp {
/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */ /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
int dx; int dx;
/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */ /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
int dy; int dy;
/** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */ /** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */
int dz; int dz;
/** data width */ /** data width */
int w; int w;
/** data height */ /** data height */
int h; int h;
@ -498,25 +498,25 @@ typedef struct opj_volume_comp {
Defines volume data and characteristics Defines volume data and characteristics
*/ */
typedef struct opj_volume { typedef struct opj_volume {
/** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */ /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */
int x0; int x0;
/** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */ /** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
int y0; int y0;
/** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */ /** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */
int z0; int z0;
/** Xsiz: width of the reference grid */ /** Xsiz: width of the reference grid */
int x1; int x1;
/** Ysiz: height of the reference grid */ /** Ysiz: height of the reference grid */
int y1; int y1;
/** Zsiz: length of the reference grid */ /** Zsiz: length of the reference grid */
int z1; int z1;
/** number of components in the volume */ /** number of components in the volume */
int numcomps; int numcomps;
/** number of slices in the volume */ /** number of slices in the volume */
int numslices; int numslices;
/** color space: sRGB, Greyscale or YUV */ /** color space: sRGB, Greyscale or YUV */
OPJ_COLOR_SPACE color_space; OPJ_COLOR_SPACE color_space;
/** volume components */ /** volume components */
opj_volume_comp_t *comps; opj_volume_comp_t *comps;
} opj_volume_t; } opj_volume_t;

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;
@ -281,7 +288,7 @@ static bool pi_next_pcrl(opj_pi_iterator_t * pi) {
} }
} }
for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) {
for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) {
for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) {
for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) {
@ -335,18 +342,20 @@ 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:
;
}
} }
} }
} }
} }
} }
}
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

@ -52,13 +52,13 @@ by some function in T2.C.
Packet iterator : resolution level information Packet iterator : resolution level information
*/ */
typedef struct opj_pi_resolution { typedef struct opj_pi_resolution {
/** Size of precints in horizontal axis */ /** Size of precints in horizontal axis */
int pdx; int pdx;
/** Size of precints in vertical axis */ /** Size of precints in vertical axis */
int pdy; int pdy;
/** Size of precints in axial axis */ /** Size of precints in axial axis */
int pdz; int pdz;
/** Number of precints in each axis */ /** Number of precints in each axis */
int prctno[3]; int prctno[3];
} opj_pi_resolution_t; } opj_pi_resolution_t;
@ -66,15 +66,15 @@ typedef struct opj_pi_resolution {
Packet iterator : component information Packet iterator : component information
*/ */
typedef struct opj_pi_comp { typedef struct opj_pi_comp {
/** Size in horizontal axis */ /** Size in horizontal axis */
int dx; int dx;
/** Size in vertical axis */ /** Size in vertical axis */
int dy; int dy;
/** Size in axial axis */ /** Size in axial axis */
int dz; int dz;
/** Number of resolution levels */ /** Number of resolution levels */
int numresolution[3]; int numresolution[3];
/** Packet iterator : resolution level information */ /** Packet iterator : resolution level information */
opj_pi_resolution_t *resolutions; opj_pi_resolution_t *resolutions;
} opj_pi_comp_t; } opj_pi_comp_t;
@ -82,30 +82,30 @@ typedef struct opj_pi_comp {
Packet iterator Packet iterator
*/ */
typedef struct opj_pi_iterator { typedef struct opj_pi_iterator {
/** precise if the packet has been already used (useful for progression order change) */ /** precise if the packet has been already used (useful for progression order change) */
short int *include; short int *include;
/** layer step used to localize the packet in the include vector */ /** layer step used to localize the packet in the include vector */
int step_l; int step_l;
/** resolution step used to localize the packet in the include vector */ /** resolution step used to localize the packet in the include vector */
int step_r; int step_r;
/** component step used to localize the packet in the include vector */ /** component step used to localize the packet in the include vector */
int step_c; int step_c;
/** precinct step used to localize the packet in the include vector */ /** precinct step used to localize the packet in the include vector */
int step_p; int step_p;
/** component that identify the packet */ /** component that identify the packet */
int compno; int compno;
/** resolution that identify the packet */ /** resolution that identify the packet */
int resno; int resno;
/** precinct that identify the packet */ /** precinct that identify the packet */
int precno; int precno;
/** layer that identify the packet */ /** layer that identify the packet */
int layno; int layno;
/** 0 if the first packet */ /** 0 if the first packet */
int first; int first;
/** progression order change information */ /** progression order change information */
opj_poc_t poc; opj_poc_t poc;
/** Packet iterator : component information */ /** Packet iterator : component information */
opj_pi_comp_t *comps; opj_pi_comp_t *comps;
int numcomps; int numcomps;
int tx0, ty0, tz0; int tx0, ty0, tz0;

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

@ -48,19 +48,19 @@ with the corresponding mode switch.
RAW encoding operations RAW encoding operations
*/ */
typedef struct opj_raw { typedef struct opj_raw {
/** Temporary buffer where bits are coded or decoded */ /** Temporary buffer where bits are coded or decoded */
unsigned char c; unsigned char c;
/** Number of bits already read or free to write */ /** Number of bits already read or free to write */
unsigned int ct; unsigned int ct;
/** Maximum length to decode */ /** Maximum length to decode */
unsigned int lenmax; unsigned int lenmax;
/** Length decoded */ /** Length decoded */
unsigned int len; unsigned int len;
/** Pointer to the current position in the buffer */ /** Pointer to the current position in the buffer */
unsigned char *bp; unsigned char *bp;
/** Pointer to the start of the buffer */ /** Pointer to the start of the buffer */
unsigned char *start; unsigned char *start;
/** Pointer to the end of the buffer */ /** Pointer to the end of the buffer */
unsigned char *end; unsigned char *end;
} opj_raw_t; } opj_raw_t;

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,13 +962,14 @@ 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;
int level[3]; int level[3];
FILE *fid = NULL; FILE *fid = NULL;
/* char filename[10];*/ /* char filename[10];*/
tile->distotile = 0; /* fixed_quality */ tile->distotile = 0; /* fixed_quality */
for (compno = 0; compno < tile->numcomps; compno++) { for (compno = 0; compno < tile->numcomps; compno++) {
@ -1012,7 +1041,7 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
for (i = 0; i < cblk->x1 - cblk->x0; i++) { for (i = 0; i < cblk->x1 - cblk->x0; i++) {
t1->data[k][j][i] = t1->data[k][j][i] =
tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS; tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS;
/*fprintf(fid," %d",t1->data[k][j][i]);*/ /*fprintf(fid," %d",t1->data[k][j][i]);*/
} }
} }
} }
@ -1041,14 +1070,15 @@ void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) {
} /* cblkno */ } /* cblkno */
} /* precno */ } /* precno */
/*fprintf(fid,"\n");*/ /*fprintf(fid,"\n");*/
} /* bandno */ } /* bandno */
/*fclose(fid);*/ /*fclose(fid);*/
} /* resno */ } /* resno */
} /* 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,11 +368,12 @@ 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);
for (m = 0; m < l; m++){ for (m = 0; m < l; m++) {
for (k = 0; k < h; k += 4) { for (k = 0; k < h; k += 4) {
for (i = 0; i < w; i++) { for (i = 0; i < w; i++) {
for (j = k; j < k + 4 && j < h; j++) { for (j = k; j < k + 4 && j < h; j++) {
@ -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;
@ -636,7 +644,7 @@ int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj
} }
/* progression in resolution */ /* progression in resolution */
for (i = 0; i < 3; i++){ for (i = 0; i < 3; i++) {
volume->comps[pi[pino].compno].resno_decoded[i] = (e > 0) ? int_max(pi[pino].resno, volume->comps[pi[pino].compno].resno_decoded[i]) : volume->comps[pi[pino].compno].resno_decoded[i]; volume->comps[pi[pino].compno].resno_decoded[i] = (e > 0) ? int_max(pi[pino].resno, volume->comps[pi[pino].compno].resno_decoded[i]) : volume->comps[pi[pino].compno].resno_decoded[i];
} }
n++; n++;
@ -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

@ -48,11 +48,11 @@
Tier-2 coding Tier-2 coding
*/ */
typedef struct opj_t2 { typedef struct opj_t2 {
/** Codec context */ /** Codec context */
opj_common_ptr cinfo; opj_common_ptr cinfo;
/** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */ /** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */
opj_volume_t *volume; opj_volume_t *volume;
/** Pointer to the volume coding parameters */ /** Pointer to the volume coding parameters */
opj_cp_t *cp; opj_cp_t *cp;
} opj_t2_t; } opj_t2_t;

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;
@ -100,10 +102,10 @@ static void tilec_dump(FILE *fd, opj_tcd_tilecomp_t *tilec) {
datalen = (tilec->z1 - tilec->z0) * (tilec->y1 - tilec->y0) * (tilec->x1 - tilec->x0); datalen = (tilec->z1 - tilec->z0) * (tilec->y1 - tilec->y0) * (tilec->x1 - tilec->x0);
a = tilec->data; a = tilec->data;
for (k = 0; k < datalen; k++) { for (k = 0; k < datalen; k++) {
if (!(k % tilec->x1)){ if (!(k % tilec->x1)) {
fprintf(fd, "\n"); fprintf(fd, "\n");
} }
if (!(k % (tilec->y1 * tilec->x1))){ if (!(k % (tilec->y1 * tilec->x1))) {
fprintf(fd, "Slice %d\n",i++); fprintf(fd, "Slice %d\n",i++);
} }
fprintf(fd," %d",a[k]); fprintf(fd," %d",a[k]);
@ -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 */
@ -214,7 +219,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int
if (tcp->rates[j]) { if (tcp->rates[j]) {
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
tcp->rates[j] = tcp->rates[j - 1] + 20; tcp->rates[j] = tcp->rates[j - 1] + 20;
} else if (!j && tcp->rates[j] < 30){ } else if (!j && tcp->rates[j] < 30) {
tcp->rates[j] = 30; tcp->rates[j] = 30;
} }
} }
@ -242,7 +247,7 @@ void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int
tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int));
res_max = 0; res_max = 0;
for (i = 0;i < 3; i++){ for (i = 0; i < 3; i++) {
tilec->numresolution[i] = tccp->numresolution[i]; tilec->numresolution[i] = tccp->numresolution[i];
/*Greater of 3 resolutions contains all information*/ /*Greater of 3 resolutions contains all information*/
res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max;
@ -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;
@ -494,7 +500,7 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int c
if (tcp->rates[j]) { if (tcp->rates[j]) {
if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) {
tcp->rates[j] = tcp->rates[j - 1] + 20; tcp->rates[j] = tcp->rates[j - 1] + 20;
} else if (!j && tcp->rates[j] < 30){ } else if (!j && tcp->rates[j] < 30) {
tcp->rates[j] = 30; tcp->rates[j] = 30;
} }
} }
@ -521,7 +527,7 @@ void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int c
tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int));
res_max = 0; res_max = 0;
for (i = 0;i < 3; i++){ for (i = 0; i < 3; i++) {
tilec->numresolution[i] = tccp->numresolution[i]; tilec->numresolution[i] = tccp->numresolution[i];
/*Greater of 3 resolutions contains all information*/ /*Greater of 3 resolutions contains all information*/
res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max;
@ -717,11 +723,12 @@ 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 */
/* opj_tcd_slice_t *slice = NULL; */ /* pointer to tcd->slice */ /* opj_tcd_slice_t *slice = NULL; */ /* pointer to tcd->slice */
opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */
opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */
opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ opj_tcd_band_t *band = NULL; /* pointer to tcd->band */
@ -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,
@ -825,7 +833,7 @@ void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp) {
tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int));
res_max = 0; res_max = 0;
for (i = 0;i < 3; i++){ for (i = 0; i < 3; i++) {
tilec->numresolution[i] = tccp->numresolution[i]; tilec->numresolution[i] = tccp->numresolution[i];
/*Greater of 3 resolutions contains all information*/ /*Greater of 3 resolutions contains all information*/
res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max;
@ -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;
@ -1215,7 +1227,7 @@ void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) {
n = passno + 1; n = passno + 1;
continue; continue;
} }
if (dd / dr >= thresh){ if (dd / dr >= thresh) {
n = passno + 1; n = passno + 1;
} }
} }
@ -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;
@ -1458,7 +1472,7 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
adjust = 0; adjust = 0;
} else { } else {
adjust = volume->comps[compno].sgnd ? 0 : 1 << (volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/ adjust = volume->comps[compno].sgnd ? 0 : 1 << (volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/
if (volume->comps[compno].dcoffset != 0){ if (volume->comps[compno].dcoffset != 0) {
adjust += volume->comps[compno].dcoffset; adjust += volume->comps[compno].dcoffset;
fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",volume->comps[compno].dcoffset,adjust); fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",volume->comps[compno].dcoffset,adjust);
} }
@ -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);
@ -1567,7 +1580,7 @@ int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, op
opj_free(tcd->tilec->data); opj_free(tcd->tilec->data);
} }
if (l == -999){ if (l == -999) {
fprintf(stdout,"[ERROR] Unable to perform T2 tier. Return -999.\n"); fprintf(stdout,"[ERROR] Unable to perform T2 tier. Return -999.\n");
return 0; return 0;
} }
@ -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;
@ -1612,7 +1626,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
t1 = t1_create(tcd->cinfo); t1 = t1_create(tcd->cinfo);
t1_decode_cblks(t1, tile, tcd->tcp); t1_decode_cblks(t1, tile, tcd->tcp);
t1_destroy(t1); t1_destroy(t1);
}else if (tcd->cp->encoding_format == ENCOD_3EB) { } else if (tcd->cp->encoding_format == ENCOD_3EB) {
opj_t1_3d_t *t1 = NULL; /* T1 component */ opj_t1_3d_t *t1 = NULL; /* T1 component */
t1 = t1_3d_create(tcd->cinfo); t1 = t1_3d_create(tcd->cinfo);
t1_3d_decode_cblks(t1, tile, tcd->tcp); t1_3d_decode_cblks(t1, tile, tcd->tcp);
@ -1620,9 +1634,9 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
} }
t1_time = opj_clock() - t1_time; t1_time = opj_clock() - t1_time;
#ifdef VERBOSE #ifdef VERBOSE
opj_event_msg(tcd->cinfo, EVT_INFO, "- tier-1 took %f s\n", t1_time); opj_event_msg(tcd->cinfo, EVT_INFO, "- tier-1 took %f s\n", t1_time);
#endif #endif
} else if ((tcd->cp->encoding_format == ENCOD_2GR)||(tcd->cp->encoding_format == ENCOD_3GR)) { } else if ((tcd->cp->encoding_format == ENCOD_2GR)||(tcd->cp->encoding_format == ENCOD_3GR)) {
opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: Entropy decoding -- Does nothing :-D\n"); opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: Entropy decoding -- Does nothing :-D\n");
/* /*
@ -1662,9 +1676,9 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
} }
} }
dwt_time = opj_clock() - dwt_time; dwt_time = opj_clock() - dwt_time;
#ifdef VERBOSE #ifdef VERBOSE
opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time); opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time);
#endif #endif
/*----------------MCT-------------------*/ /*----------------MCT-------------------*/
@ -1701,7 +1715,7 @@ bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) {
adjust = 0; adjust = 0;
} else { } else {
adjust = tcd->volume->comps[compno].sgnd ? 0 : 1 << (tcd->volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/ adjust = tcd->volume->comps[compno].sgnd ? 0 : 1 << (tcd->volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/
if (tcd->volume->comps[compno].dcoffset != 0){ if (tcd->volume->comps[compno].dcoffset != 0) {
adjust += tcd->volume->comps[compno].dcoffset; adjust += tcd->volume->comps[compno].dcoffset;
fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",tcd->volume->comps[compno].dcoffset,adjust); fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",tcd->volume->comps[compno].dcoffset,adjust);
} }

View File

@ -50,17 +50,17 @@ each other. The functions in TCD.C are used by some function in JP3D.C.
Tile coder/decoder: segment instance Tile coder/decoder: segment instance
*/ */
typedef struct opj_tcd_seg { typedef struct opj_tcd_seg {
/** Number of passes in the segment */ /** Number of passes in the segment */
int numpasses; int numpasses;
/** Length of information */ /** Length of information */
int len; int len;
/** Data */ /** Data */
unsigned char *data; unsigned char *data;
/** Number of passes posible for the segment */ /** Number of passes posible for the segment */
int maxpasses; int maxpasses;
/** Number of passes added to the segment */ /** Number of passes added to the segment */
int numnewpasses; int numnewpasses;
/** New length after inclusion of segments */ /** New length after inclusion of segments */
int newlen; int newlen;
} opj_tcd_seg_t; } opj_tcd_seg_t;
@ -68,12 +68,12 @@ typedef struct opj_tcd_seg {
Tile coder/decoder: pass instance Tile coder/decoder: pass instance
*/ */
typedef struct opj_tcd_pass { typedef struct opj_tcd_pass {
/** Rate obtained in the pass*/ /** Rate obtained in the pass*/
int rate; int rate;
/** Distorsion obtained in the pass*/ /** Distorsion obtained in the pass*/
double distortiondec; double distortiondec;
int term; int term;
/** Length of information */ /** Length of information */
int len; int len;
} opj_tcd_pass_t; } opj_tcd_pass_t;
@ -81,11 +81,11 @@ typedef struct opj_tcd_pass {
Tile coder/decoder: layer instance Tile coder/decoder: layer instance
*/ */
typedef struct opj_tcd_layer { typedef struct opj_tcd_layer {
/** Number of passes in the layer */ /** Number of passes in the layer */
int numpasses; int numpasses;
/** Length of information */ /** Length of information */
int len; int len;
/** Distortion within layer */ /** Distortion within layer */
double disto; /* add for index (Cfr. Marcela) */ double disto; /* add for index (Cfr. Marcela) */
unsigned char *data; /* data */ unsigned char *data; /* data */
} opj_tcd_layer_t; } opj_tcd_layer_t;
@ -94,31 +94,31 @@ typedef struct opj_tcd_layer {
Tile coder/decoder: codeblock instance Tile coder/decoder: codeblock instance
*/ */
typedef struct opj_tcd_cblk { typedef struct opj_tcd_cblk {
/** Dimension of the code-blocks : left upper corner (x0, y0, z0) */ /** Dimension of the code-blocks : left upper corner (x0, y0, z0) */
int x0, y0, z0; int x0, y0, z0;
/** Dimension of the code-blocks : right low corner (x1,y1,z1) */ /** Dimension of the code-blocks : right low corner (x1,y1,z1) */
int x1, y1, z1; int x1, y1, z1;
/** Number of bits per simbol in codeblock */ /** Number of bits per simbol in codeblock */
int numbps; int numbps;
int numlenbits; int numlenbits;
int len; /* length */ int len; /* length */
/** Number of pass already done for the code-blocks */ /** Number of pass already done for the code-blocks */
int numpasses; int numpasses;
/** number of pass added to the code-blocks */ /** number of pass added to the code-blocks */
int numnewpasses; int numnewpasses;
/** Number of segments */ /** Number of segments */
int numsegs; int numsegs;
/** Segments informations */ /** Segments informations */
opj_tcd_seg_t segs[100]; opj_tcd_seg_t segs[100];
/** Number of passes in the layer */ /** Number of passes in the layer */
int numpassesinlayers; int numpassesinlayers;
/** Layer information */ /** Layer information */
opj_tcd_layer_t layers[100]; opj_tcd_layer_t layers[100];
/** Total number of passes */ /** Total number of passes */
int totalpasses; int totalpasses;
/** Information about the passes */ /** Information about the passes */
opj_tcd_pass_t passes[100]; opj_tcd_pass_t passes[100];
/* Data */ /* Data */
unsigned char data[524288]; unsigned char data[524288];
/*unsigned char *data;*/ /*unsigned char *data;*/
} opj_tcd_cblk_t; } opj_tcd_cblk_t;
@ -127,17 +127,17 @@ typedef struct opj_tcd_cblk {
Tile coder/decoder: precint instance Tile coder/decoder: precint instance
*/ */
typedef struct opj_tcd_precinct { typedef struct opj_tcd_precinct {
/** Dimension of the precint : left upper corner (x0, y0, z0) */ /** Dimension of the precint : left upper corner (x0, y0, z0) */
int x0, y0, z0; int x0, y0, z0;
/** Dimension of the precint : right low corner (x1,y1,z1) */ /** Dimension of the precint : right low corner (x1,y1,z1) */
int x1, y1, z1; int x1, y1, z1;
/** Number of codeblocks in precinct in width and heigth and length*/ /** Number of codeblocks in precinct in width and heigth and length*/
int cblkno[3]; int cblkno[3];
/** Information about the codeblocks */ /** Information about the codeblocks */
opj_tcd_cblk_t *cblks; opj_tcd_cblk_t *cblks;
/** Inclusion tree */ /** Inclusion tree */
opj_tgt_tree_t *incltree; opj_tgt_tree_t *incltree;
/** Missing MSBs tree */ /** Missing MSBs tree */
opj_tgt_tree_t *imsbtree; opj_tgt_tree_t *imsbtree;
} opj_tcd_precinct_t; } opj_tcd_precinct_t;
@ -145,17 +145,17 @@ typedef struct opj_tcd_precinct {
Tile coder/decoder: subband instance Tile coder/decoder: subband instance
*/ */
typedef struct opj_tcd_band { typedef struct opj_tcd_band {
/** Dimension of the subband : left upper corner (x0, y0, z0) */ /** Dimension of the subband : left upper corner (x0, y0, z0) */
int x0, y0, z0; int x0, y0, z0;
/** Dimension of the subband : right low corner (x1,y1,z1) */ /** Dimension of the subband : right low corner (x1,y1,z1) */
int x1, y1, z1; int x1, y1, z1;
/** Information about the precints */ /** Information about the precints */
opj_tcd_precinct_t *precincts; /* precinct information */ opj_tcd_precinct_t *precincts; /* precinct information */
/** Number of bits per symbol in band */ /** Number of bits per symbol in band */
int numbps; int numbps;
/** Quantization stepsize associated */ /** Quantization stepsize associated */
float stepsize; float stepsize;
/** Band orientation (O->LLL,...,7->HHH) */ /** Band orientation (O->LLL,...,7->HHH) */
int bandno; int bandno;
} opj_tcd_band_t; } opj_tcd_band_t;
@ -163,15 +163,15 @@ typedef struct opj_tcd_band {
Tile coder/decoder: resolution instance Tile coder/decoder: resolution instance
*/ */
typedef struct opj_tcd_resolution { typedef struct opj_tcd_resolution {
/** Dimension of the resolution level : left upper corner (x0, y0, z0) */ /** Dimension of the resolution level : left upper corner (x0, y0, z0) */
int x0, y0, z0; int x0, y0, z0;
/** Dimension of the resolution level : right low corner (x1,y1,z1) */ /** Dimension of the resolution level : right low corner (x1,y1,z1) */
int x1, y1, z1; int x1, y1, z1;
/** Number of precints in each dimension for the resolution level */ /** Number of precints in each dimension for the resolution level */
int prctno[3]; int prctno[3];
/** Number of subbands for the resolution level */ /** Number of subbands for the resolution level */
int numbands; int numbands;
/** Subband information */ /** Subband information */
opj_tcd_band_t *bands; opj_tcd_band_t *bands;
} opj_tcd_resolution_t; } opj_tcd_resolution_t;
@ -179,19 +179,19 @@ typedef struct opj_tcd_resolution {
Tile coder/decoder: component instance Tile coder/decoder: component instance
*/ */
typedef struct opj_tcd_tilecomp { typedef struct opj_tcd_tilecomp {
/** Dimension of the component : left upper corner (x0, y0, z0) */ /** Dimension of the component : left upper corner (x0, y0, z0) */
int x0, y0, z0; int x0, y0, z0;
/** Dimension of the component : right low corner (x1,y1,z1) */ /** Dimension of the component : right low corner (x1,y1,z1) */
int x1, y1, z1; int x1, y1, z1;
/** Number of resolutions level if DWT transform*/ /** Number of resolutions level if DWT transform*/
int numresolution[3]; int numresolution[3];
/** Resolution information */ /** Resolution information */
opj_tcd_resolution_t *resolutions; opj_tcd_resolution_t *resolutions;
/** Data of the component */ /** Data of the component */
int *data; int *data;
/** Fixed_quality related */ /** Fixed_quality related */
int nbpix; int nbpix;
/** Number of bits per voxel in component */ /** Number of bits per voxel in component */
int bpp; int bpp;
} opj_tcd_tilecomp_t; } opj_tcd_tilecomp_t;
@ -199,19 +199,19 @@ typedef struct opj_tcd_tilecomp {
Tile coder/decoder: tile instance Tile coder/decoder: tile instance
*/ */
typedef struct opj_tcd_tile { typedef struct opj_tcd_tile {
/** Dimension of the tile : left upper corner (x0, y0, z0) */ /** Dimension of the tile : left upper corner (x0, y0, z0) */
int x0, y0, z0; int x0, y0, z0;
/** Dimension of the tile : right low corner (x1,y1,z1) */ /** Dimension of the tile : right low corner (x1,y1,z1) */
int x1, y1, z1; int x1, y1, z1;
/** Number of components in tile */ /** Number of components in tile */
int numcomps; int numcomps;
/** Components information */ /** Components information */
opj_tcd_tilecomp_t *comps; opj_tcd_tilecomp_t *comps;
/** Fixed_quality related : no of bytes of data*/ /** Fixed_quality related : no of bytes of data*/
int nbpix; int nbpix;
/** Fixed_quality related : distortion achieved in tile */ /** Fixed_quality related : distortion achieved in tile */
double distotile; double distotile;
/** Fixed_quality related : distortion achieved in each layer */ /** Fixed_quality related : distortion achieved in each layer */
double distolayer[100]; double distolayer[100];
} opj_tcd_tile_t; } opj_tcd_tile_t;
@ -219,9 +219,9 @@ typedef struct opj_tcd_tile {
Tile coder/decoder: volume instance Tile coder/decoder: volume instance
*/ */
typedef struct opj_tcd_volume { typedef struct opj_tcd_volume {
/** Number of tiles in width and heigth and length */ /** Number of tiles in width and heigth and length */
int tw, th, tl; int tw, th, tl;
/** Tiles information */ /** Tiles information */
opj_tcd_tile_t *tiles; opj_tcd_tile_t *tiles;
} opj_tcd_volume_t; } opj_tcd_volume_t;
@ -229,19 +229,19 @@ typedef struct opj_tcd_volume {
Tile coder/decoder Tile coder/decoder
*/ */
typedef struct opj_tcd { typedef struct opj_tcd {
/** Codec context */ /** Codec context */
opj_common_ptr cinfo; opj_common_ptr cinfo;
/** Volume information */ /** Volume information */
opj_volume_t *volume; opj_volume_t *volume;
/** Coding parameters */ /** Coding parameters */
opj_cp_t *cp; opj_cp_t *cp;
/** Coding/decoding parameters common to all tiles */ /** Coding/decoding parameters common to all tiles */
opj_tcp_t *tcp; opj_tcp_t *tcp;
/** Info on each volume tile */ /** Info on each volume tile */
opj_tcd_volume_t *tcd_volume; opj_tcd_volume_t *tcd_volume;
/** Pointer to the current encoded/decoded tile */ /** Pointer to the current encoded/decoded tile */
opj_tcd_tile_t *tcd_tile; opj_tcd_tile_t *tcd_tile;
/** Current encoded/decoded tile */ /** Current encoded/decoded tile */
int tcd_tileno; int tcd_tileno;
/**@name working variables */ /**@name working variables */

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

@ -50,13 +50,13 @@ are used by some function in T2.C.
Tag node Tag node
*/ */
typedef struct opj_tgt_node { typedef struct opj_tgt_node {
/** Node parent reference */ /** Node parent reference */
struct opj_tgt_node *parent; struct opj_tgt_node *parent;
/** */ /** */
int value; int value;
/** */ /** */
int low; int low;
/** */ /** */
int known; int known;
} opj_tgt_node_t; } opj_tgt_node_t;
@ -64,15 +64,15 @@ typedef struct opj_tgt_node {
Tag tree Tag tree
*/ */
typedef struct opj_tgt_tree { typedef struct opj_tgt_tree {
/** Number of leaves from horizontal axis */ /** Number of leaves from horizontal axis */
int numleafsh; int numleafsh;
/** Number of leaves from vertical axis */ /** Number of leaves from vertical axis */
int numleafsv; int numleafsv;
/** Number of leaves from axial axis */ /** Number of leaves from axial axis */
int numleafsz; int numleafsz;
/** Number of nodes */ /** Number of nodes */
int numnodes; int numnodes;
/** Reference to each node instance */ /** Reference to each node instance */
opj_tgt_node_t *nodes; opj_tgt_node_t *nodes;
} opj_tgt_tree_t; } opj_tgt_tree_t;

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

@ -79,7 +79,7 @@ void close_aux_transport( auxtrans_param_t auxtrans)
/*!< auxiliary response parameters */ /*!< auxiliary response parameters */
typedef struct aux_response_param{ typedef struct aux_response_param {
char *cid; /*!< channel ID */ char *cid; /*!< channel ID */
unsigned char *data; /*!< sending data */ unsigned char *data; /*!< sending data */
OPJ_SIZE_T datalen; /*!< length of data */ OPJ_SIZE_T datalen; /*!< length of data */
@ -111,8 +111,8 @@ void send_responsedata_on_aux( OPJ_BOOL istcp, auxtrans_param_t auxtrans, const
int status; int status;
#endif #endif
if( istcp){ if( istcp) {
if( auxtrans.tcplistensock == -1){ if( auxtrans.tcplistensock == -1) {
fprintf( FCGI_stderr, "Error: error in send_responsedata_on_aux(), tcp listening socket no open\n"); fprintf( FCGI_stderr, "Error: error in send_responsedata_on_aux(), tcp listening socket no open\n");
return; return;
} }
@ -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");
} }
@ -190,10 +189,10 @@ void * aux_streaming( void *arg)
maxLenOfBody = auxresponse->maxlenPerFrame - headlen; maxLenOfBody = auxresponse->maxlenPerFrame - headlen;
remlen = auxresponse->datalen; remlen = auxresponse->datalen;
while((connected_socket = accept_socket( auxresponse->listensock)) != -1){ while((connected_socket = accept_socket( auxresponse->listensock)) != -1) {
if( identify_cid( connected_socket, auxresponse->cid, FCGI_stderr)){ if( identify_cid( connected_socket, auxresponse->cid, FCGI_stderr)) {
ptr = auxresponse->data; ptr = auxresponse->data;
while( 0 < remlen){ while( 0 < remlen) {
memset( chunk, 0, auxresponse->maxlenPerFrame); memset( chunk, 0, auxresponse->maxlenPerFrame);
chunklen = remlen<maxLenOfBody?remlen:maxLenOfBody; chunklen = remlen<maxLenOfBody?remlen:maxLenOfBody;
@ -204,9 +203,9 @@ void * aux_streaming( void *arg)
memcpy( chunk+headlen, ptr, chunklen-headlen); memcpy( chunk+headlen, ptr, chunklen-headlen);
do{ do {
send_stream( connected_socket, chunk, chunklen); send_stream( connected_socket, chunk, chunklen);
}while( !recv_ack( connected_socket, chunk)); } while( !recv_ack( connected_socket, chunk));
remlen -= maxLenOfBody; remlen -= maxLenOfBody;
ptr += maxLenOfBody; ptr += maxLenOfBody;
@ -235,7 +234,7 @@ OPJ_BOOL identify_cid( SOCKET connected_socket, char refcid[], FILE *fp)
char *cid; char *cid;
OPJ_BOOL succeed; OPJ_BOOL succeed;
if(!(cid = receive_string( connected_socket))){ if(!(cid = receive_string( connected_socket))) {
fprintf( fp, "Error: error in identify_cid(), while receiving cid from client\n"); fprintf( fp, "Error: error in identify_cid(), while receiving cid from client\n");
return OPJ_FALSE; return OPJ_FALSE;
} }

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