made bio more efficient, and added simulate out mode, where bio doesn't actually write bytes out to output buffer.
This commit is contained in:
parent
c311463900
commit
269c40c544
|
@ -48,7 +48,7 @@ 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 opj_bio_putbit(opj_bio_t *bio, OPJ_UINT32 b);
|
static void opj_bio_putbit(opj_bio_t *bio, OPJ_BYTE b);
|
||||||
/**
|
/**
|
||||||
Read a bit
|
Read a bit
|
||||||
@param bio BIO handle
|
@param bio BIO handle
|
||||||
|
@ -79,26 +79,27 @@ 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->ct = bio->buf == 0xff ? 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) {
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
*bio->bp++ = (OPJ_BYTE)(bio->buf >> 8);
|
if (!bio->simOut)
|
||||||
|
*bio->bp = bio->buf;
|
||||||
|
bio->bp++;
|
||||||
|
bio->buf = 0;
|
||||||
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->ct = bio->buf == 0xff ? 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) {
|
||||||
return OPJ_FALSE;
|
return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
bio->buf |= *bio->bp++;
|
bio->buf = *bio->bp++;
|
||||||
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_BYTE 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 ? */
|
||||||
}
|
}
|
||||||
|
@ -141,6 +142,7 @@ void opj_bio_init_enc(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) {
|
||||||
bio->bp = bp;
|
bio->bp = bp;
|
||||||
bio->buf = 0;
|
bio->buf = 0;
|
||||||
bio->ct = 8;
|
bio->ct = 8;
|
||||||
|
bio->simOut = OPJ_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
@ -61,9 +61,11 @@ typedef struct opj_bio {
|
||||||
/** pointer to the present position in the buffer */
|
/** pointer to the present position in the buffer */
|
||||||
OPJ_BYTE *bp;
|
OPJ_BYTE *bp;
|
||||||
/** temporary place where each byte is read or written */
|
/** temporary place where each byte is read or written */
|
||||||
OPJ_UINT32 buf;
|
OPJ_UINT8 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 */
|
||||||
OPJ_UINT32 ct;
|
OPJ_UINT32 ct;
|
||||||
|
|
||||||
|
OPJ_BOOL simOut;
|
||||||
} opj_bio_t;
|
} opj_bio_t;
|
||||||
|
|
||||||
/** @name Exported functions */
|
/** @name Exported functions */
|
||||||
|
|
Loading…
Reference in New Issue