BitIO.h
Go to the documentation of this file.
/*
* Copyright (C) 2016-2023 Grok Image Compression Inc.
*
* This source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* This source code incorporates work covered by the BSD 2-clause license.
* Please see the LICENSE file in the root directory for details.
*
*/
#pragma once
#include "IBitIO.h"
#include "BufferedStream.h"
namespace grk
{
/*
Bit input/output
*/
class BitIO : public IBitIO
{
public:
BitIO(uint8_t* bp, uint64_t len, bool isCompressor);
BitIO(BufferedStream* stream, bool isCompressor);
/*
Number of bytes written.
@return the number of bytes written
*/
size_t numBytes(void) override;
/*
Write bits
@param v Value of bits
@param n Number of bits to write
*/
bool write(uint32_t v, uint32_t n) override;
bool write(uint32_t v) override;
/*
Read bits
@param n Number of bits to read
*/
void read(uint32_t* bits, uint8_t n) override;
/*
Read bit
*/
uint8_t read(void) override;
/*
Flush bits
@return true if successful, returns false otherwise
*/
bool flush(void) override;
/*
Passes the ending bits (coming from flushing)
*/
void inalign(void) override;
bool putcommacode(uint8_t n);
uint8_t getcommacode(void);
bool putnumpasses(uint32_t n);
void getnumpasses(uint32_t* numpasses);
private:
/* pointer to the start of the buffer */
uint8_t* start;
size_t offset;
size_t buf_len;
/* temporary place where each byte is read or written */
uint8_t buf;
/* coder : number of bits free to write. decoder : number of bits read */
uint8_t ct;
BufferedStream* stream;
bool read0xFF;
/*
Write a bit
@param bio BIO handle
@param b Bit to write (0 or 1)
*/
bool putbit(uint8_t b);
/*
Read a bit
@param bio BIO handle
*/
void getbit(uint32_t* bits, uint8_t pos);
uint8_t getbit(void);
/*
Write a byte
@param bio BIO handle
@return true if successful, returns false otherwise
*/
bool writeByte(void);
/*
Read a byte
@param bio BIO handle
*/
void bytein(void);
};
} // namespace grk
BufferedStream.h
IBitIO.h
grk::BitIO
Definition BitIO.h:33
grk::BitIO::getcommacode
uint8_t getcommacode(void)
Definition BitIO.cpp:174
grk::BitIO::read0xFF
bool read0xFF
Definition BitIO.h:90
grk::BitIO::numBytes
size_t numBytes(void) override
Number of bytes written.
Definition BitIO.cpp:106
grk::BitIO::inalign
void inalign(void) override
Passes the ending bits (coming from flushing)
Definition BitIO.cpp:155
grk::BitIO::flush
bool flush(void) override
Flush bits.
Definition BitIO.cpp:147
grk::BitIO::getbit
uint8_t getbit(void)
Definition BitIO.cpp:96
grk::BitIO::putnumpasses
bool putnumpasses(uint32_t n)
Definition BitIO.cpp:187
grk::BitIO::putbit
bool putbit(uint8_t b)
Definition BitIO.cpp:78
grk::BitIO::ct
uint8_t ct
Definition BitIO.h:86
grk::BitIO::bytein
void bytein(void)
Definition BitIO.cpp:58
grk::BitIO::stream
BufferedStream * stream
Definition BitIO.h:88
grk::BitIO::start
uint8_t * start
Definition BitIO.h:78
grk::BitIO::read
uint8_t read(void) override
Read bit.
Definition BitIO.cpp:127
grk::BitIO::buf
uint8_t buf
Definition BitIO.h:84
grk::BitIO::write
bool write(uint32_t v, uint32_t n) override
Write bits.
Definition BitIO.cpp:111
grk::BitIO::offset
size_t offset
Definition BitIO.h:80
grk::BitIO::writeByte
bool writeByte(void)
Definition BitIO.cpp:37
grk::BitIO::buf_len
size_t buf_len
Definition BitIO.h:81
grk::BitIO::getnumpasses
void getnumpasses(uint32_t *numpasses)
Definition BitIO.cpp:218
grk::BitIO::putcommacode
bool putcommacode(uint8_t n)
Definition BitIO.cpp:162
grk::IBitIO
Bit input/output.
Definition IBitIO.h:26
grk
Copyright (C) 2016-2023 Grok Image Compression Inc.
Definition ICacheable.h:20
grk::grk_read
void grk_read(const uint8_t *buffer, TYPE *value, uint32_t numBytes)
Definition BufferedStream.h:239
grk::BufferedStream
Definition BufferedStream.h:35