mirror of
https://github.com/PrimeDecomp/prime.git
synced 2025-07-13 17:05:52 +00:00
Share min_containing_bytes between CInputStream and COutputStream
Former-commit-id: 1c956d06f2c2e5399aed40705c019d28c6e9bbb9
This commit is contained in:
parent
637de45b40
commit
8d0b032e01
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
|
|
||||||
|
#include "Kyoto/Streams/StreamSupport.hpp"
|
||||||
#include "Kyoto/Alloc/CMemory.hpp"
|
#include "Kyoto/Alloc/CMemory.hpp"
|
||||||
|
|
||||||
CInputStream::CInputStream(int len)
|
CInputStream::CInputStream(int len)
|
||||||
@ -97,8 +98,6 @@ uint CInputStream::ReadBytes(void* dest, unsigned long len) {
|
|||||||
return curReadLen;
|
return curReadLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint BitsToBytes(uint bits) { return (bits / 8) + ((bits % 8) ? 1 : 0); }
|
|
||||||
|
|
||||||
uint CInputStream::ReadBits(uint bitCount) {
|
uint CInputStream::ReadBits(uint bitCount) {
|
||||||
if (x20_bitOffset >= bitCount) {
|
if (x20_bitOffset >= bitCount) {
|
||||||
uint mask = 0xffffffff;
|
uint mask = 0xffffffff;
|
||||||
@ -125,7 +124,7 @@ uint CInputStream::ReadBits(uint bitCount) {
|
|||||||
ret = (mask & (x1c_bitWord >> bwShift)) << shiftAmt;
|
ret = (mask & (x1c_bitWord >> bwShift)) << shiftAmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint len = BitsToBytes(shiftAmt);
|
uint len = min_containing_bytes(shiftAmt);
|
||||||
x20_bitOffset = 0;
|
x20_bitOffset = 0;
|
||||||
Get(&x1c_bitWord, len);
|
Get(&x1c_bitWord, len);
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "Kyoto/Streams/COutputStream.hpp"
|
#include "Kyoto/Streams/COutputStream.hpp"
|
||||||
|
|
||||||
|
#include "Kyoto/Streams/StreamSupport.hpp"
|
||||||
|
|
||||||
#include "Kyoto/Alloc/CMemory.hpp"
|
#include "Kyoto/Alloc/CMemory.hpp"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -57,14 +59,9 @@ void COutputStream::DoFlush() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u32 min_containing_bytes(u32 v) {
|
|
||||||
v = 32 - v;
|
|
||||||
return (v / 8) + ((v % 8) != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void COutputStream::FlushShiftRegister() {
|
void COutputStream::FlushShiftRegister() {
|
||||||
if (mShiftRegisterOffset < 32) {
|
if (mShiftRegisterOffset < 32) {
|
||||||
DoPut((void*)&mShiftRegister, min_containing_bytes(mShiftRegisterOffset));
|
DoPut((void*)&mShiftRegister, min_containing_bytes(32 - mShiftRegisterOffset));
|
||||||
mShiftRegister = 0;
|
mShiftRegister = 0;
|
||||||
mShiftRegisterOffset = 32;
|
mShiftRegisterOffset = 32;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user