{trunk]update mct functions with opj_ prefix and new opj type

add some comments
This commit is contained in:
Mickael Savinaud 2012-10-03 09:47:50 +00:00
parent df870e5241
commit 6a84a1788b
4 changed files with 119 additions and 120 deletions

View File

@ -38,40 +38,40 @@
/* <summary> */ /* <summary> */
/* This table contains the norms of the basis function of the reversible MCT. */ /* This table contains the norms of the basis function of the reversible MCT. */
/* </summary> */ /* </summary> */
static const double mct_norms[3] = { 1.732, .8292, .8292 }; static const OPJ_FLOAT64 opj_mct_norms[3] = { 1.732, .8292, .8292 };
/* <summary> */ /* <summary> */
/* This table contains the norms of the basis function of the irreversible MCT. */ /* This table contains the norms of the basis function of the irreversible MCT. */
/* </summary> */ /* </summary> */
static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 }; static const OPJ_FLOAT64 opj_mct_norms_real[3] = { 1.732, 1.805, 1.573 };
const OPJ_FLOAT64 * get_mct_norms () const OPJ_FLOAT64 * opj_mct_get_mct_norms ()
{ {
return mct_norms; return opj_mct_norms;
} }
const OPJ_FLOAT64 * get_mct_norms_real () const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ()
{ {
return mct_norms_real; return opj_mct_norms_real;
} }
/* <summary> */ /* <summary> */
/* Foward reversible MCT. */ /* Foward reversible MCT. */
/* </summary> */ /* </summary> */
void mct_encode( void opj_mct_encode(
int* restrict c0, OPJ_INT32* restrict c0,
int* restrict c1, OPJ_INT32* restrict c1,
int* restrict c2, OPJ_INT32* restrict c2,
int n) OPJ_UINT32 n)
{ {
int i; OPJ_UINT32 i;
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
int r = c0[i]; OPJ_INT32 r = c0[i];
int g = c1[i]; OPJ_INT32 g = c1[i];
int b = c2[i]; OPJ_INT32 b = c2[i];
int y = (r + (g * 2) + b) >> 2; OPJ_INT32 y = (r + (g * 2) + b) >> 2;
int u = b - g; OPJ_INT32 u = b - g;
int v = r - g; OPJ_INT32 v = r - g;
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
@ -81,20 +81,20 @@ void mct_encode(
/* <summary> */ /* <summary> */
/* Inverse reversible MCT. */ /* Inverse reversible MCT. */
/* </summary> */ /* </summary> */
void mct_decode( void opj_mct_decode(
int* restrict c0, OPJ_INT32* restrict c0,
int* restrict c1, OPJ_INT32* restrict c1,
int* restrict c2, OPJ_INT32* restrict c2,
int n) OPJ_UINT32 n)
{ {
int i; OPJ_UINT32 i;
for (i = 0; i < n; ++i) { for (i = 0; i < n; ++i) {
int y = c0[i]; OPJ_INT32 y = c0[i];
int u = c1[i]; OPJ_INT32 u = c1[i];
int v = c2[i]; OPJ_INT32 v = c2[i];
int g = y - ((u + v) >> 2); OPJ_INT32 g = y - ((u + v) >> 2);
int r = v + g; OPJ_INT32 r = v + g;
int b = u + g; OPJ_INT32 b = u + g;
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
@ -104,27 +104,27 @@ void mct_decode(
/* <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) { OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
return mct_norms[compno]; return opj_mct_norms[compno];
} }
/* <summary> */ /* <summary> */
/* Foward irreversible MCT. */ /* Foward irreversible MCT. */
/* </summary> */ /* </summary> */
void mct_encode_real( void opj_mct_encode_real(
int* restrict c0, OPJ_INT32* restrict c0,
int* restrict c1, OPJ_INT32* restrict c1,
int* restrict c2, OPJ_INT32* restrict c2,
int n) OPJ_UINT32 n)
{ {
int i; OPJ_UINT32 i;
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
int r = c0[i]; OPJ_INT32 r = c0[i];
int g = c1[i]; OPJ_INT32 g = c1[i];
int b = c2[i]; OPJ_INT32 b = c2[i];
int y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934); OPJ_INT32 y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
int u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096); OPJ_INT32 u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
int v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666); OPJ_INT32 v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
c0[i] = y; c0[i] = y;
c1[i] = u; c1[i] = u;
c2[i] = v; c2[i] = v;
@ -134,13 +134,13 @@ void mct_encode_real(
/* <summary> */ /* <summary> */
/* Inverse irreversible MCT. */ /* Inverse irreversible MCT. */
/* </summary> */ /* </summary> */
void mct_decode_real( void opj_mct_decode_real(
float* restrict c0, OPJ_FLOAT32* restrict c0,
float* restrict c1, OPJ_FLOAT32* restrict c1,
float* restrict c2, OPJ_FLOAT32* restrict c2,
int n) OPJ_UINT32 n)
{ {
int i; OPJ_UINT32 i;
#ifdef __SSE__ #ifdef __SSE__
__m128 vrv, vgu, vgv, vbu; __m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f); vrv = _mm_set1_ps(1.402f);
@ -180,12 +180,12 @@ void mct_decode_real(
n &= 7; n &= 7;
#endif #endif
for(i = 0; i < n; ++i) { for(i = 0; i < n; ++i) {
float y = c0[i]; OPJ_FLOAT32 y = c0[i];
float u = c1[i]; OPJ_FLOAT32 u = c1[i];
float v = c2[i]; OPJ_FLOAT32 v = c2[i];
float r = y + (v * 1.402f); OPJ_FLOAT32 r = y + (v * 1.402f);
float g = y - (u * 0.34413f) - (v * (0.71414f)); OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f));
float b = y + (u * 1.772f); OPJ_FLOAT32 b = y + (u * 1.772f);
c0[i] = r; c0[i] = r;
c1[i] = g; c1[i] = g;
c2[i] = b; c2[i] = b;
@ -195,21 +195,16 @@ void mct_decode_real(
/* <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) { OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) {
return mct_norms_real[compno]; return opj_mct_norms_real[compno];
} }
opj_bool mct_encode_custom( opj_bool opj_mct_encode_custom(
/* MCT data */
OPJ_BYTE * pCodingdata, OPJ_BYTE * pCodingdata,
/* size of components */
OPJ_UINT32 n, OPJ_UINT32 n,
/* components */
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
/* nb of components (i.e. size of pData) */
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
/* tells if the data is signed */
OPJ_UINT32 isSigned) OPJ_UINT32 isSigned)
{ {
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata; OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
@ -256,16 +251,11 @@ opj_bool mct_encode_custom(
return OPJ_TRUE; return OPJ_TRUE;
} }
opj_bool mct_decode_custom( opj_bool opj_mct_decode_custom(
/* MCT data */
OPJ_BYTE * pDecodingData, OPJ_BYTE * pDecodingData,
/* size of components */
OPJ_UINT32 n, OPJ_UINT32 n,
/* components */
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
/* nb of components (i.e. size of pData) */
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
/* tells if the data is signed */
OPJ_UINT32 isSigned) OPJ_UINT32 isSigned)
{ {
OPJ_FLOAT32 * lMct; OPJ_FLOAT32 * lMct;
@ -278,29 +268,19 @@ opj_bool mct_decode_custom(
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData; OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32)); lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
if if (! lCurrentData) {
(! lCurrentData)
{
return OPJ_FALSE; return OPJ_FALSE;
} }
lCurrentResult = lCurrentData + pNbComp; lCurrentResult = lCurrentData + pNbComp;
for for (i = 0; i < n; ++i) {
(i = 0; i < n; ++i)
{
lMct = (OPJ_FLOAT32 *) pDecodingData; lMct = (OPJ_FLOAT32 *) pDecodingData;
for for (j=0;j<pNbComp;++j) {
(j=0;j<pNbComp;++j)
{
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j])); lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
} }
for for (j=0;j<pNbComp;++j) {
(j=0;j<pNbComp;++j)
{
lCurrentResult[j] = 0; lCurrentResult[j] = 0;
for for (k=0;k<pNbComp;++k) {
(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]);

View File

@ -52,7 +52,7 @@ Apply a reversible multi-component transform to an image
@param c2 Samples blue component @param c2 Samples blue component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void mct_encode(int *c0, int *c1, int *c2, int n); void opj_mct_encode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Apply a reversible multi-component inverse transform to an image Apply a reversible multi-component inverse transform to an image
@param c0 Samples for luminance component @param c0 Samples for luminance component
@ -60,13 +60,13 @@ Apply a reversible multi-component inverse transform to an image
@param c2 Samples for blue chrominance component @param c2 Samples for blue chrominance component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void mct_decode(int *c0, int *c1, int *c2, int n); void opj_mct_decode(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Get norm of the basis function used for the reversible multi-component transform Get norm of the basis function used for the reversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V) @param compno Number of the component (0->Y, 1->U, 2->V)
@return @return
*/ */
double mct_getnorm(int compno); OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno);
/** /**
Apply an irreversible multi-component transform to an image Apply an irreversible multi-component transform to an image
@ -75,7 +75,7 @@ Apply an irreversible multi-component transform to an image
@param c2 Samples blue component @param c2 Samples blue component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void mct_encode_real(int *c0, int *c1, int *c2, int n); void opj_mct_encode_real(OPJ_INT32 *c0, OPJ_INT32 *c1, OPJ_INT32 *c2, OPJ_UINT32 n);
/** /**
Apply an irreversible multi-component inverse transform to an image Apply an irreversible multi-component inverse transform to an image
@param c0 Samples for luminance component @param c0 Samples for luminance component
@ -83,43 +83,62 @@ Apply an irreversible multi-component inverse transform to an image
@param c2 Samples for blue chrominance component @param c2 Samples for blue chrominance component
@param n Number of samples for each component @param n Number of samples for each component
*/ */
void mct_decode_real(float* c0, float* c1, float* c2, int n); void opj_mct_decode_real(OPJ_FLOAT32* c0, OPJ_FLOAT32* c1, OPJ_FLOAT32* c2, OPJ_UINT32 n);
/** /**
Get norm of the basis function used for the irreversible multi-component transform Get norm of the basis function used for the irreversible multi-component transform
@param compno Number of the component (0->Y, 1->U, 2->V) @param compno Number of the component (0->Y, 1->U, 2->V)
@return @return
*/ */
double mct_getnorm_real(int compno); OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno);
/**
opj_bool mct_encode_custom( FIXME DOC
/* MCT data */ @param p_coding_data MCT data
@param n size of components
@param p_data components
@param p_nb_comp nb of components (i.e. size of p_data)
@param is_signed tells if the data is signed
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/
opj_bool opj_mct_encode_custom(
OPJ_BYTE * p_coding_data, OPJ_BYTE * p_coding_data,
/* size of components */
OPJ_UINT32 n, OPJ_UINT32 n,
/* components */
OPJ_BYTE ** p_data, OPJ_BYTE ** p_data,
/* nb of components (i.e. size of p_data) */
OPJ_UINT32 p_nb_comp, OPJ_UINT32 p_nb_comp,
/* tells if the data is signed */
OPJ_UINT32 is_signed); OPJ_UINT32 is_signed);
/**
opj_bool mct_decode_custom( FIXME DOC
/* MCT data */ @param pDecodingData MCT data
@param n size of components
@param pDataa components
@param pNbComp nb of components (i.e. size of p_data)
@param isSigneda tells if the data is signed
@return OPJ_FALSE if function encounter a problem, OPJ_TRUE otherwise
*/
opj_bool opj_mct_decode_custom(
OPJ_BYTE * pDecodingData, OPJ_BYTE * pDecodingData,
/* size of components */
OPJ_UINT32 n, OPJ_UINT32 n,
/* components */
OPJ_BYTE ** pData, OPJ_BYTE ** pData,
/* nb of components (i.e. size of pData) */
OPJ_UINT32 pNbComp, OPJ_UINT32 pNbComp,
/* tells if the data is signed */
OPJ_UINT32 isSigned); OPJ_UINT32 isSigned);
/**
void opj_calculate_norms(OPJ_FLOAT64 * pNorms,OPJ_UINT32 p_nb_comps,OPJ_FLOAT32 * pMatrix); FIXME DOC
@param pNorms MCT data
const OPJ_FLOAT64 * get_mct_norms (); @param p_nb_comps size of components
const OPJ_FLOAT64 * get_mct_norms_real (); @param pMatrix components
@return
*/
void opj_calculate_norms( OPJ_FLOAT64 * pNorms,
OPJ_UINT32 p_nb_comps,
OPJ_FLOAT32 * pMatrix);
/**
FIXME DOC
*/
const OPJ_FLOAT64 * opj_mct_get_mct_norms ();
/**
FIXME DOC
*/
const OPJ_FLOAT64 * opj_mct_get_mct_norms_real ();
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -747,10 +747,10 @@ static double t1_getwmsedec(
{ {
double w1, w2, wmsedec; double w1, w2, wmsedec;
if (qmfbid == 1) { if (qmfbid == 1) {
w1 = (mct && numcomps==3) ? mct_getnorm(compno) : 1.0; w1 = (mct && numcomps==3) ? opj_mct_getnorm(compno) : 1.0;
w2 = dwt_getnorm(level, orient); w2 = dwt_getnorm(level, orient);
} else { /* if (qmfbid == 0) */ } else { /* if (qmfbid == 0) */
w1 = (mct && numcomps==3) ? mct_getnorm_real(compno) : 1.0; w1 = (mct && numcomps==3) ? opj_mct_getnorm_real(compno) : 1.0;
w2 = dwt_getnorm_real(level, orient); w2 = dwt_getnorm_real(level, orient);
} }
wmsedec = w1 * w2 * stepsize * (1 << bpno); wmsedec = w1 * w2 * stepsize * (1 << bpno);

View File

@ -1586,7 +1586,7 @@ opj_bool opj_tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
++l_tile_comp; ++l_tile_comp;
} }
if (! mct_decode_custom(/* MCT data */ if (! opj_mct_decode_custom(/* MCT data */
(OPJ_BYTE*) l_tcp->m_mct_decoding_matrix, (OPJ_BYTE*) l_tcp->m_mct_decoding_matrix,
/* size of components */ /* size of components */
l_samples, l_samples,
@ -1604,13 +1604,13 @@ opj_bool opj_tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
} }
else { else {
if (l_tcp->tccps->qmfbid == 1) { if (l_tcp->tccps->qmfbid == 1) {
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 {
mct_decode_real( (float*)l_tile->comps[0].data, opj_mct_decode_real( (float*)l_tile->comps[0].data,
(float*)l_tile->comps[1].data, (float*)l_tile->comps[1].data,
(float*)l_tile->comps[2].data, (float*)l_tile->comps[2].data,
l_samples); l_samples);
@ -1865,7 +1865,7 @@ opj_bool opj_tcd_mct_encode ( opj_tcd_v2_t *p_tcd )
++l_tile_comp; ++l_tile_comp;
} }
if (! mct_encode_custom(/* MCT data */ if (! opj_mct_encode_custom(/* MCT data */
(OPJ_BYTE*) p_tcd->tcp->m_mct_coding_matrix, (OPJ_BYTE*) p_tcd->tcp->m_mct_coding_matrix,
/* size of components */ /* size of components */
samples, samples,
@ -1883,10 +1883,10 @@ opj_bool opj_tcd_mct_encode ( opj_tcd_v2_t *p_tcd )
opj_free(l_data); opj_free(l_data);
} }
else if (l_tcp->tccps->qmfbid == 0) { else if (l_tcp->tccps->qmfbid == 0) {
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 {
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);
} }
return OPJ_TRUE; return OPJ_TRUE;
@ -1932,10 +1932,10 @@ opj_bool opj_tcd_t1_encode ( opj_tcd_v2_t *p_tcd )
if (l_tcp->mct == 1) { if (l_tcp->mct == 1) {
/* irreversible encoding */ /* irreversible encoding */
if (l_tcp->tccps->qmfbid == 0) { if (l_tcp->tccps->qmfbid == 0) {
l_mct_norms = get_mct_norms_real(); l_mct_norms = opj_mct_get_mct_norms_real();
} }
else { else {
l_mct_norms = get_mct_norms(); l_mct_norms = opj_mct_get_mct_norms();
} }
} }
else { else {