{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> */
/* This table contains the norms of the basis function of the reversible MCT. */
/* </summary> */
static const double mct_norms[3] = { 1.732, .8292, .8292 };
static const OPJ_FLOAT64 opj_mct_norms[3] = { 1.732, .8292, .8292 };
/* <summary> */
/* This table contains the norms of the basis function of the irreversible MCT. */
/* </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> */
/* Foward reversible MCT. */
/* </summary> */
void mct_encode(
int* restrict c0,
int* restrict c1,
int* restrict c2,
int n)
void opj_mct_encode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
int i;
OPJ_UINT32 i;
for(i = 0; i < n; ++i) {
int r = c0[i];
int g = c1[i];
int b = c2[i];
int y = (r + (g * 2) + b) >> 2;
int u = b - g;
int v = r - g;
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = (r + (g * 2) + b) >> 2;
OPJ_INT32 u = b - g;
OPJ_INT32 v = r - g;
c0[i] = y;
c1[i] = u;
c2[i] = v;
@ -81,20 +81,20 @@ void mct_encode(
/* <summary> */
/* Inverse reversible MCT. */
/* </summary> */
void mct_decode(
int* restrict c0,
int* restrict c1,
int* restrict c2,
int n)
void opj_mct_decode(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
int i;
OPJ_UINT32 i;
for (i = 0; i < n; ++i) {
int y = c0[i];
int u = c1[i];
int v = c2[i];
int g = y - ((u + v) >> 2);
int r = v + g;
int b = u + g;
OPJ_INT32 y = c0[i];
OPJ_INT32 u = c1[i];
OPJ_INT32 v = c2[i];
OPJ_INT32 g = y - ((u + v) >> 2);
OPJ_INT32 r = v + g;
OPJ_INT32 b = u + g;
c0[i] = r;
c1[i] = g;
c2[i] = b;
@ -104,27 +104,27 @@ void mct_decode(
/* <summary> */
/* Get norm of basis function of reversible MCT. */
/* </summary> */
double mct_getnorm(int compno) {
return mct_norms[compno];
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno) {
return opj_mct_norms[compno];
}
/* <summary> */
/* Foward irreversible MCT. */
/* </summary> */
void mct_encode_real(
int* restrict c0,
int* restrict c1,
int* restrict c2,
int n)
void opj_mct_encode_real(
OPJ_INT32* restrict c0,
OPJ_INT32* restrict c1,
OPJ_INT32* restrict c2,
OPJ_UINT32 n)
{
int i;
OPJ_UINT32 i;
for(i = 0; i < n; ++i) {
int r = c0[i];
int g = c1[i];
int b = c2[i];
int 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);
int v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
OPJ_INT32 r = c0[i];
OPJ_INT32 g = c1[i];
OPJ_INT32 b = c2[i];
OPJ_INT32 y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934);
OPJ_INT32 u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096);
OPJ_INT32 v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666);
c0[i] = y;
c1[i] = u;
c2[i] = v;
@ -134,13 +134,13 @@ void mct_encode_real(
/* <summary> */
/* Inverse irreversible MCT. */
/* </summary> */
void mct_decode_real(
float* restrict c0,
float* restrict c1,
float* restrict c2,
int n)
void opj_mct_decode_real(
OPJ_FLOAT32* restrict c0,
OPJ_FLOAT32* restrict c1,
OPJ_FLOAT32* restrict c2,
OPJ_UINT32 n)
{
int i;
OPJ_UINT32 i;
#ifdef __SSE__
__m128 vrv, vgu, vgv, vbu;
vrv = _mm_set1_ps(1.402f);
@ -180,12 +180,12 @@ void mct_decode_real(
n &= 7;
#endif
for(i = 0; i < n; ++i) {
float y = c0[i];
float u = c1[i];
float v = c2[i];
float r = y + (v * 1.402f);
float g = y - (u * 0.34413f) - (v * (0.71414f));
float b = y + (u * 1.772f);
OPJ_FLOAT32 y = c0[i];
OPJ_FLOAT32 u = c1[i];
OPJ_FLOAT32 v = c2[i];
OPJ_FLOAT32 r = y + (v * 1.402f);
OPJ_FLOAT32 g = y - (u * 0.34413f) - (v * (0.71414f));
OPJ_FLOAT32 b = y + (u * 1.772f);
c0[i] = r;
c1[i] = g;
c2[i] = b;
@ -195,21 +195,16 @@ void mct_decode_real(
/* <summary> */
/* Get norm of basis function of irreversible MCT. */
/* </summary> */
double mct_getnorm_real(int compno) {
return mct_norms_real[compno];
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno) {
return opj_mct_norms_real[compno];
}
opj_bool mct_encode_custom(
/* MCT data */
opj_bool opj_mct_encode_custom(
OPJ_BYTE * pCodingdata,
/* size of components */
OPJ_UINT32 n,
/* components */
OPJ_BYTE ** pData,
/* nb of components (i.e. size of pData) */
OPJ_UINT32 pNbComp,
/* tells if the data is signed */
OPJ_UINT32 isSigned)
{
OPJ_FLOAT32 * lMct = (OPJ_FLOAT32 *) pCodingdata;
@ -256,16 +251,11 @@ opj_bool mct_encode_custom(
return OPJ_TRUE;
}
opj_bool mct_decode_custom(
/* MCT data */
opj_bool opj_mct_decode_custom(
OPJ_BYTE * pDecodingData,
/* size of components */
OPJ_UINT32 n,
/* components */
OPJ_BYTE ** pData,
/* nb of components (i.e. size of pData) */
OPJ_UINT32 pNbComp,
/* tells if the data is signed */
OPJ_UINT32 isSigned)
{
OPJ_FLOAT32 * lMct;
@ -278,29 +268,19 @@ opj_bool mct_decode_custom(
OPJ_FLOAT32 ** lData = (OPJ_FLOAT32 **) pData;
lCurrentData = (OPJ_FLOAT32 *) opj_malloc (2 * pNbComp * sizeof(OPJ_FLOAT32));
if
(! lCurrentData)
{
if (! lCurrentData) {
return OPJ_FALSE;
}
lCurrentResult = lCurrentData + pNbComp;
for
(i = 0; i < n; ++i)
{
for (i = 0; i < n; ++i) {
lMct = (OPJ_FLOAT32 *) pDecodingData;
for
(j=0;j<pNbComp;++j)
{
for (j=0;j<pNbComp;++j) {
lCurrentData[j] = (OPJ_FLOAT32) (*(lData[j]));
}
for
(j=0;j<pNbComp;++j)
{
for (j=0;j<pNbComp;++j) {
lCurrentResult[j] = 0;
for
(k=0;k<pNbComp;++k)
{
for (k=0;k<pNbComp;++k) {
lCurrentResult[j] += *(lMct++) * lCurrentData[k];
}
*(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 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
@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 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
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm(int compno);
OPJ_FLOAT64 opj_mct_getnorm(OPJ_UINT32 compno);
/**
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 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
@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 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
@param compno Number of the component (0->Y, 1->U, 2->V)
@return
*/
double mct_getnorm_real(int compno);
OPJ_FLOAT64 opj_mct_getnorm_real(OPJ_UINT32 compno);
opj_bool mct_encode_custom(
/* MCT data */
/**
FIXME DOC
@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,
/* size of components */
OPJ_UINT32 n,
/* components */
OPJ_BYTE ** p_data,
/* nb of components (i.e. size of p_data) */
OPJ_UINT32 p_nb_comp,
/* tells if the data is signed */
OPJ_UINT32 is_signed);
opj_bool mct_decode_custom(
/* MCT data */
/**
FIXME DOC
@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,
/* size of components */
OPJ_UINT32 n,
/* components */
OPJ_BYTE ** pData,
/* nb of components (i.e. size of pData) */
OPJ_UINT32 pNbComp,
/* tells if the data is signed */
OPJ_UINT32 isSigned);
void opj_calculate_norms(OPJ_FLOAT64 * pNorms,OPJ_UINT32 p_nb_comps,OPJ_FLOAT32 * pMatrix);
const OPJ_FLOAT64 * get_mct_norms ();
const OPJ_FLOAT64 * get_mct_norms_real ();
/**
FIXME DOC
@param pNorms MCT data
@param p_nb_comps size of components
@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;
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);
} 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);
}
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;
}
if (! mct_decode_custom(/* MCT data */
if (! opj_mct_decode_custom(/* MCT data */
(OPJ_BYTE*) l_tcp->m_mct_decoding_matrix,
/* size of components */
l_samples,
@ -1604,13 +1604,13 @@ opj_bool opj_tcd_mct_decode ( opj_tcd_v2_t *p_tcd )
}
else {
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[2].data,
l_samples);
}
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[2].data,
l_samples);
@ -1865,7 +1865,7 @@ opj_bool opj_tcd_mct_encode ( opj_tcd_v2_t *p_tcd )
++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,
/* size of components */
samples,
@ -1883,10 +1883,10 @@ opj_bool opj_tcd_mct_encode ( opj_tcd_v2_t *p_tcd )
opj_free(l_data);
}
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 {
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;
@ -1932,10 +1932,10 @@ opj_bool opj_tcd_t1_encode ( opj_tcd_v2_t *p_tcd )
if (l_tcp->mct == 1) {
/* irreversible encoding */
if (l_tcp->tccps->qmfbid == 0) {
l_mct_norms = get_mct_norms_real();
l_mct_norms = opj_mct_get_mct_norms_real();
}
else {
l_mct_norms = get_mct_norms();
l_mct_norms = opj_mct_get_mct_norms();
}
}
else {