[trunk] update global functions of bio.c with opj_prefix and new opj type

This commit is contained in:
Mickael Savinaud 2012-10-03 09:04:44 +00:00
parent 82afd3a891
commit df870e5241
4 changed files with 55 additions and 53 deletions

View File

@ -125,11 +125,11 @@ void opj_bio_destroy(opj_bio_t *bio) {
} }
} }
ptrdiff_t 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 bio_init_enc(opj_bio_t *bio, unsigned char *bp, int 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;
@ -137,7 +137,7 @@ 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 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;
@ -145,15 +145,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 opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) {
int i; OPJ_INT32 i;
for (i = n - 1; i >= 0; i--) { for (i = n - 1; i >= 0; i--) {
opj_bio_putbit(bio, (v >> i) & 1); opj_bio_putbit(bio, (v >> i) & 1);
} }
} }
int bio_read(opj_bio_t *bio, int n) { OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) {
int i, v; OPJ_INT32 i;
OPJ_UINT32 v;
v = 0; v = 0;
for (i = n - 1; i >= 0; i--) { for (i = n - 1; i >= 0; i--) {
v += opj_bio_getbit(bio) << i; v += opj_bio_getbit(bio) << i;
@ -161,27 +162,27 @@ int bio_read(opj_bio_t *bio, int n) {
return v; return v;
} }
int bio_flush(opj_bio_t *bio) { opj_bool opj_bio_flush(opj_bio_t *bio) {
bio->ct = 0; bio->ct = 0;
if (! opj_bio_byteout(bio)) { if (! opj_bio_byteout(bio)) {
return 1; return OPJ_FALSE;
} }
if (bio->ct == 7) { if (bio->ct == 7) {
bio->ct = 0; bio->ct = 0;
if (! opj_bio_byteout(bio)) { if (! opj_bio_byteout(bio)) {
return 1; return OPJ_FALSE;
} }
} }
return 0; return OPJ_TRUE;
} }
int bio_inalign(opj_bio_t *bio) { opj_bool opj_bio_inalign(opj_bio_t *bio) {
bio->ct = 0; bio->ct = 0;
if ((bio->buf & 0xff) == 0xff) { if ((bio->buf & 0xff) == 0xff) {
if (! opj_bio_bytein(bio)) { if (! opj_bio_bytein(bio)) {
return 1; return OPJ_FALSE;
} }
bio->ct = 0; bio->ct = 0;
} }
return 0; return OPJ_TRUE;
} }

View File

@ -78,47 +78,47 @@ Number of bytes written.
@param bio BIO handle @param bio BIO handle
@return Returns the number of bytes written @return Returns the number of bytes written
*/ */
ptrdiff_t bio_numbytes(opj_bio_t *bio); ptrdiff_t opj_bio_numbytes(opj_bio_t *bio);
/** /**
Init encoder Init encoder
@param bio BIO handle @param bio BIO handle
@param bp Output buffer @param bp Output buffer
@param len Output buffer length @param len Output buffer length
*/ */
void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len); void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
/** /**
Init decoder Init decoder
@param bio BIO handle @param bio BIO handle
@param bp Input buffer @param bp Input buffer
@param len Input buffer length @param len Input buffer length
*/ */
void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len); void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len);
/** /**
Write bits Write bits
@param bio BIO handle @param bio BIO handle
@param v Value of bits @param v Value of bits
@param n Number of bits to write @param n Number of bits to write
*/ */
void bio_write(opj_bio_t *bio, int v, int n); void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n);
/** /**
Read bits Read bits
@param bio BIO handle @param bio BIO handle
@param n Number of bits to read @param n Number of bits to read
@return Returns the corresponding read number @return Returns the corresponding read number
*/ */
int bio_read(opj_bio_t *bio, int n); OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n);
/** /**
Flush bits Flush bits
@param bio BIO handle @param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise @return Returns OPJ_TRUE if successful, returns OPJ_FALSE otherwise
*/ */
int bio_flush(opj_bio_t *bio); opj_bool opj_bio_flush(opj_bio_t *bio);
/** /**
Passes the ending bits (coming from flushing) Passes the ending bits (coming from flushing)
@param bio BIO handle @param bio BIO handle
@return Returns 1 if successful, returns 0 otherwise @return Returns OPJ_TRUE if successful, returns OPJ_FALSE otherwise
*/ */
int bio_inalign(opj_bio_t *bio); opj_bool opj_bio_inalign(opj_bio_t *bio);
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
/*@}*/ /*@}*/

View File

@ -146,15 +146,15 @@ static opj_bool opj_t2_init_seg( opj_tcd_cblk_dec_v2_t* cblk,
/* TODO MSD->LHE */ /* TODO MSD->LHE */
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); opj_bio_write(bio, 1, 1);
} }
bio_write(bio, 0, 1); opj_bio_write(bio, 0, 1);
} }
OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio) OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
{ {
OPJ_UINT32 n = 0; OPJ_UINT32 n = 0;
while (bio_read(bio, 1)) { while (opj_bio_read(bio, 1)) {
++n; ++n;
} }
return n; return n;
@ -162,29 +162,29 @@ OPJ_UINT32 opj_t2_getcommacode(opj_bio_t *bio)
void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) { void opj_t2_putnumpasses(opj_bio_t *bio, OPJ_UINT32 n) {
if (n == 1) { if (n == 1) {
bio_write(bio, 0, 1); opj_bio_write(bio, 0, 1);
} else if (n == 2) { } else if (n == 2) {
bio_write(bio, 2, 2); opj_bio_write(bio, 2, 2);
} else if (n <= 5) { } else if (n <= 5) {
bio_write(bio, 0xc | (n - 3), 4); opj_bio_write(bio, 0xc | (n - 3), 4);
} else if (n <= 36) { } else if (n <= 36) {
bio_write(bio, 0x1e0 | (n - 6), 9); opj_bio_write(bio, 0x1e0 | (n - 6), 9);
} else if (n <= 164) { } else if (n <= 164) {
bio_write(bio, 0xff80 | (n - 37), 16); opj_bio_write(bio, 0xff80 | (n - 37), 16);
} }
} }
OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) { OPJ_UINT32 opj_t2_getnumpasses(opj_bio_t *bio) {
OPJ_UINT32 n; OPJ_UINT32 n;
if (!bio_read(bio, 1)) if (!opj_bio_read(bio, 1))
return 1; return 1;
if (!bio_read(bio, 1)) if (!opj_bio_read(bio, 1))
return 2; return 2;
if ((n = bio_read(bio, 2)) != 3) if ((n = opj_bio_read(bio, 2)) != 3)
return (3 + n); return (3 + n);
if ((n = bio_read(bio, 5)) != 31) if ((n = opj_bio_read(bio, 5)) != 31)
return (6 + n); return (6 + n);
return (37 + bio_read(bio, 7)); return (37 + opj_bio_read(bio, 7));
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
@ -562,8 +562,8 @@ opj_bool opj_t2_encode_packet( OPJ_UINT32 tileno,
} }
bio = opj_bio_create(); bio = opj_bio_create();
bio_init_enc(bio, c, length); opj_bio_init_enc(bio, c, length);
bio_write(bio, 1, 1); /* Empty header bit */ opj_bio_write(bio, 1, 1); /* Empty header bit */
/* Writing Packet header */ /* Writing Packet header */
band = res->bands; band = res->bands;
@ -595,7 +595,7 @@ opj_bool opj_t2_encode_packet( OPJ_UINT32 tileno,
if (!cblk->numpasses) { if (!cblk->numpasses) {
tgt_encode(bio, prc->incltree, cblkno, layno + 1); tgt_encode(bio, prc->incltree, cblkno, layno + 1);
} else { } else {
bio_write(bio, layer->numpasses != 0, 1); opj_bio_write(bio, layer->numpasses != 0, 1);
} }
/* if cblk not included, go to the next cblk */ /* if cblk not included, go to the next cblk */
@ -640,7 +640,7 @@ opj_bool opj_t2_encode_packet( OPJ_UINT32 tileno,
len += pass->len; len += pass->len;
if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) {
bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump)); opj_bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump));
len = 0; len = 0;
nump = 0; nump = 0;
} }
@ -653,12 +653,12 @@ opj_bool opj_t2_encode_packet( OPJ_UINT32 tileno,
++band; ++band;
} }
if (bio_flush(bio)) { if (!opj_bio_flush(bio)) {
opj_bio_destroy(bio); opj_bio_destroy(bio);
return OPJ_FALSE; /* modified to eliminate longjmp !! */ return OPJ_FALSE; /* modified to eliminate longjmp !! */
} }
l_nb_bytes = bio_numbytes(bio); l_nb_bytes = opj_bio_numbytes(bio);
c += l_nb_bytes; c += l_nb_bytes;
length -= l_nb_bytes; length -= l_nb_bytes;
@ -862,12 +862,13 @@ opj_bool opj_t2_read_packet_header( opj_t2_v2_t* p_t2,
l_modified_length_ptr = &(l_remaining_length); l_modified_length_ptr = &(l_remaining_length);
} }
bio_init_dec(l_bio, l_header_data,*l_modified_length_ptr); opj_bio_init_dec(l_bio, l_header_data,*l_modified_length_ptr);
l_present = bio_read(l_bio, 1); l_present = opj_bio_read(l_bio, 1);
if (!l_present) { if (!l_present) {
bio_inalign(l_bio); /* TODO MSD: no test to control the output of this function*/
l_header_data += bio_numbytes(l_bio); opj_bio_inalign(l_bio);
l_header_data += opj_bio_numbytes(l_bio);
opj_bio_destroy(l_bio); opj_bio_destroy(l_bio);
/* EPH markers */ /* EPH markers */
@ -917,7 +918,7 @@ opj_bool opj_t2_read_packet_header( opj_t2_v2_t* p_t2,
/* else one bit */ /* else one bit */
} }
else { else {
l_included = bio_read(l_bio, 1); l_included = opj_bio_read(l_bio, 1);
} }
/* if cblk not included */ /* if cblk not included */
@ -967,7 +968,7 @@ opj_bool opj_t2_read_packet_header( opj_t2_v2_t* p_t2,
do { do {
l_cblk->segs[l_segno].numnewpasses = int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].numnewpasses = int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n);
l_cblk->segs[l_segno].newlen = bio_read(l_bio, l_cblk->numlenbits + uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + uint_floorlog2(l_cblk->segs[l_segno].numnewpasses));
n -= l_cblk->segs[l_segno].numnewpasses; n -= l_cblk->segs[l_segno].numnewpasses;
if (n > 0) { if (n > 0) {
@ -986,12 +987,12 @@ opj_bool opj_t2_read_packet_header( opj_t2_v2_t* p_t2,
++l_band; ++l_band;
} }
if (bio_inalign(l_bio)) { if (!opj_bio_inalign(l_bio)) {
opj_bio_destroy(l_bio); opj_bio_destroy(l_bio);
return OPJ_FALSE; return OPJ_FALSE;
} }
l_header_data += bio_numbytes(l_bio); l_header_data += opj_bio_numbytes(l_bio);
opj_bio_destroy(l_bio); opj_bio_destroy(l_bio);
/* EPH markers */ /* EPH markers */

View File

@ -308,12 +308,12 @@ void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, OPJ_INT
while (low < threshold) { while (low < threshold) {
if (low >= node->value) { if (low >= node->value) {
if (!node->known) { if (!node->known) {
bio_write(bio, 1, 1); opj_bio_write(bio, 1, 1);
node->known = 1; node->known = 1;
} }
break; break;
} }
bio_write(bio, 0, 1); opj_bio_write(bio, 0, 1);
++low; ++low;
} }
@ -345,7 +345,7 @@ OPJ_UINT32 tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, OPJ_UINT32 leafno, O
low = node->low; low = node->low;
} }
while (low < threshold && low < node->value) { while (low < threshold && low < node->value) {
if (bio_read(bio, 1)) { if (opj_bio_read(bio, 1)) {
node->value = low; node->value = low;
} else { } else {
++low; ++low;