#include "cio.h"
#include <setjmp.h>
+#include <memory.h>
static unsigned char *cio_start; /* pointer to the start of the stream */
static unsigned char *cio_end; /* pointer to the end of the stream */
*/
int cio_numbytes()
{
- return cio_bp - cio_start;
+ return cio_bp - cio_start;
}
/*
*/
int cio_tell()
{
- return cio_bp - cio_start;
+ return cio_bp - cio_start;
}
/*
*/
void cio_seek(int pos)
{
- cio_bp = cio_start + pos;
+ cio_bp = cio_start + pos;
}
/*
*/
int cio_numbytesleft()
{
- return cio_end - cio_bp;
+ return cio_end - cio_bp;
}
/*
*/
unsigned char *cio_getbp()
{
- return cio_bp;
+ return cio_bp;
}
/*
*/
void cio_init(unsigned char *bp, int len)
{
- cio_start = bp;
- cio_end = bp + len;
- cio_bp = bp;
+ cio_start = bp;
+ cio_end = bp + len;
+ cio_bp = bp;
}
/*
*/
void cio_byteout(unsigned char v)
{
- if (cio_bp >= cio_end)
- longjmp(j2k_error, 1);
- *cio_bp++ = v;
+ if (cio_bp >= cio_end)
+ longjmp(j2k_error, 1);
+ *cio_bp++ = v;
}
*/
unsigned char cio_bytein()
{
- if (cio_bp >= cio_end)
- longjmp(j2k_error, 1);
- return *cio_bp++;
+ if (cio_bp >= cio_end)
+ longjmp(j2k_error, 1);
+ return *cio_bp++;
}
/*
*/
void cio_write(unsigned int v, int n)
{
- int i;
- for (i = n - 1; i >= 0; i--) {
- cio_byteout((unsigned char) ((v >> (i << 3)) & 0xff));
- }
+ int i;
+ for (i = n - 1; i >= 0; i--) {
+ cio_byteout((unsigned char) ((v >> (i << 3)) & 0xff));
+ }
}
/*
*/
unsigned int cio_read(int n)
{
- int i;
- unsigned int v;
- v = 0;
- for (i = n - 1; i >= 0; i--) {
- v += cio_bytein() << (i << 3);
- }
- return v;
+ int i;
+ unsigned int v;
+ v = 0;
+ for (i = n - 1; i >= 0; i--) {
+ v += cio_bytein() << (i << 3);
+ }
+ return v;
}
/*
*/
void cio_skip(int n)
{
- cio_bp += n;
+ cio_bp += n;
}
+
+/*
+ * Read n bytes, copy to buffer
+ *
+ * n : number of bytes to transfer
+ */
+void cio_read_to_buf(unsigned char* src_buf, int n)/* Glenn adds */
+{
+ if (cio_bp + n > cio_end)
+ longjmp(j2k_error, 1);
+ memcpy(cio_bp, src_buf, n);
+ cio_bp += n;
+}
+
+/*
+ * Write n bytes, copy from buffer
+ *
+ * n : number of bytes to transfer
+ */
+void cio_write_from_buf(unsigned char* dest_buf, int n)/* Glenn adds */
+{
+ if (cio_bp + n > cio_end)
+ longjmp(j2k_error, 1);
+ memcpy(dest_buf, cio_bp, n);
+ cio_bp += n;
+}
\ No newline at end of file