[trunk] udpate local functions of bio.c with opj_prefix and new opj types

update opj_bio structure
This commit is contained in:
Mickael Savinaud 2012-09-27 14:36:30 +00:00
parent ccf0f05e98
commit e7cd945000
2 changed files with 26 additions and 26 deletions

View File

@ -42,25 +42,25 @@ Write a bit
@param bio BIO handle @param bio BIO handle
@param b Bit to write (0 or 1) @param b Bit to write (0 or 1)
*/ */
static void bio_putbit(opj_bio_t *bio, unsigned int b); static void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b);
/** /**
Read a bit Read a bit
@param bio BIO handle @param bio BIO handle
@return Returns the read bit @return Returns the read bit
*/ */
static int bio_getbit(opj_bio_t *bio); static OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio);
/** /**
Write a byte Write a byte
@param bio BIO handle @param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise @return Returns OPJ_TRUE if successful, returns OPJ_FALSE otherwise
*/ */
static int bio_byteout(opj_bio_t *bio); static opj_bool opj_bio_byteout(opj_bio_t *bio);
/** /**
Read a byte Read a byte
@param bio BIO handle @param bio BIO handle
@return Returns 0 if successful, returns 1 otherwise @return Returns OPJ_TRUE if successful, returns OPJ_FALSE otherwise
*/ */
static int bio_bytein(opj_bio_t *bio); static opj_bool opj_bio_bytein(opj_bio_t *bio);
/*@}*/ /*@}*/
@ -72,37 +72,37 @@ static int bio_bytein(opj_bio_t *bio);
========================================================== ==========================================================
*/ */
static int bio_byteout(opj_bio_t *bio) { 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 (bio->bp >= bio->end) { if (bio->bp >= bio->end) {
return 1; return OPJ_FALSE;
} }
*bio->bp++ = (unsigned char)(bio->buf >> 8); *bio->bp++ = (unsigned char)(bio->buf >> 8); /* TODO MSD: check this conversion */
return 0; return OPJ_TRUE;
} }
static int bio_bytein(opj_bio_t *bio) { 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 (bio->bp >= bio->end) { if (bio->bp >= bio->end) {
return 1; return OPJ_FALSE;
} }
bio->buf |= *bio->bp++; bio->buf |= *bio->bp++;
return 0; return OPJ_TRUE;
} }
static void bio_putbit(opj_bio_t *bio, unsigned int b) { void opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b) {
if (bio->ct == 0) { if (bio->ct == 0) {
bio_byteout(bio); opj_bio_byteout(bio); // TODO_MSD: check this line
} }
bio->ct--; bio->ct--;
bio->buf |= b << bio->ct; bio->buf |= b << bio->ct;
} }
static int bio_getbit(opj_bio_t *bio) { OPJ_UINT32 opj_bio_getbit(opj_bio_t *bio) {
if (bio->ct == 0) { if (bio->ct == 0) {
bio_bytein(bio); opj_bio_bytein(bio); // TODO_MSD: check this line
} }
bio->ct--; bio->ct--;
return (bio->buf >> bio->ct) & 1; return (bio->buf >> bio->ct) & 1;
@ -148,7 +148,7 @@ void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) {
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); opj_bio_putbit(bio, (v >> i) & 1);
} }
} }
@ -156,19 +156,19 @@ 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--) {
v += bio_getbit(bio) << i; v += opj_bio_getbit(bio) << i;
} }
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 (! opj_bio_byteout(bio)) {
return 1; return 1;
} }
if (bio->ct == 7) { if (bio->ct == 7) {
bio->ct = 0; bio->ct = 0;
if (bio_byteout(bio)) { if (! opj_bio_byteout(bio)) {
return 1; return 1;
} }
} }
@ -178,7 +178,7 @@ int bio_flush(opj_bio_t *bio) {
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 (! opj_bio_bytein(bio)) {
return 1; return 1;
} }
bio->ct = 0; bio->ct = 0;

View File

@ -49,13 +49,13 @@ 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; OPJ_BYTE *start;
/** pointer to the end of the buffer */ /** pointer to the end of the buffer */
unsigned char *end; OPJ_BYTE *end;
/** pointer to the present position in the buffer */ /** pointer to the present position in the buffer */
unsigned char *bp; OPJ_BYTE *bp;
/** temporary place where each byte is read or written */ /** temporary place where each byte is read or written */
unsigned int buf; OPJ_UINT32 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;