mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-25 04:14:13 +08:00
(WEBP): fixed alpha decoder.
This commit is contained in:
parent
b9480255af
commit
1797f5151f
@ -64,11 +64,9 @@ namespace GameRes.Formats.Google
|
|||||||
{
|
{
|
||||||
if (0x46464952 != stream.Signature) // 'RIFF'
|
if (0x46464952 != stream.Signature) // 'RIFF'
|
||||||
return null;
|
return null;
|
||||||
|
if (!stream.ReadHeader (12).AsciiEqual (8, "WEBP"))
|
||||||
|
return null;
|
||||||
var header = new byte[0x10];
|
var header = new byte[0x10];
|
||||||
if (8 != stream.Read (header, 0, 8))
|
|
||||||
return null;
|
|
||||||
if (!Binary.AsciiEqual (header, 4, "WEBP"))
|
|
||||||
return null;
|
|
||||||
bool found_vp8x = false;
|
bool found_vp8x = false;
|
||||||
var info = new WebPMetaData();
|
var info = new WebPMetaData();
|
||||||
int chunk_size;
|
int chunk_size;
|
||||||
|
@ -1614,7 +1614,7 @@ namespace GameRes.Formats.Google
|
|||||||
{
|
{
|
||||||
ulong val_; // pre-fetched bits
|
ulong val_; // pre-fetched bits
|
||||||
byte[] buf_; // input byte buffer
|
byte[] buf_; // input byte buffer
|
||||||
uint len_; // buffer length
|
uint end_pos_; // buffer length
|
||||||
uint pos_; // byte position in buf_
|
uint pos_; // byte position in buf_
|
||||||
int bit_pos_; // current bit-reading position in val_
|
int bit_pos_; // current bit-reading position in val_
|
||||||
bool eos_; // true if a bit was read past the end of buffer
|
bool eos_; // true if a bit was read past the end of buffer
|
||||||
@ -1632,11 +1632,11 @@ namespace GameRes.Formats.Google
|
|||||||
/// Returns true if there was an attempt at reading bit past the end of
|
/// Returns true if there was an attempt at reading bit past the end of
|
||||||
/// the buffer. Doesn't set br->eos_ flag.
|
/// the buffer. Doesn't set br->eos_ flag.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool IsEndOfStream { get { return eos_ || ((pos_ == len_) && (bit_pos_ > LBITS)); } }
|
private bool IsEndOfStream { get { return eos_ || ((pos_ == end_pos_) && (bit_pos_ > LBITS)); } }
|
||||||
|
|
||||||
public void Init (byte[] input, int start, uint length)
|
public void Init (byte[] input, int start, uint length)
|
||||||
{
|
{
|
||||||
len_ = length;
|
end_pos_ = (uint)start + length;
|
||||||
val_ = 0;
|
val_ = 0;
|
||||||
bit_pos_ = 0;
|
bit_pos_ = 0;
|
||||||
eos_ = false;
|
eos_ = false;
|
||||||
@ -1665,7 +1665,7 @@ namespace GameRes.Formats.Google
|
|||||||
{
|
{
|
||||||
other.val_ = val_;
|
other.val_ = val_;
|
||||||
other.buf_ = buf_;
|
other.buf_ = buf_;
|
||||||
other.len_ = len_;
|
other.end_pos_ = end_pos_;
|
||||||
other.pos_ = pos_;
|
other.pos_ = pos_;
|
||||||
other.bit_pos_ = bit_pos_;
|
other.bit_pos_ = bit_pos_;
|
||||||
other.eos_ = eos_;
|
other.eos_ = eos_;
|
||||||
@ -1677,9 +1677,9 @@ namespace GameRes.Formats.Google
|
|||||||
public void SetBuffer (byte[] buffer, uint length)
|
public void SetBuffer (byte[] buffer, uint length)
|
||||||
{
|
{
|
||||||
buf_ = buffer;
|
buf_ = buffer;
|
||||||
len_ = length;
|
end_pos_ = length;
|
||||||
// pos_ > len_ should be considered a param error.
|
// pos_ > end_pos_ should be considered a param error.
|
||||||
eos_ = (pos_ > len_) || IsEndOfStream;
|
eos_ = (pos_ > end_pos_) || IsEndOfStream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -1742,7 +1742,7 @@ namespace GameRes.Formats.Google
|
|||||||
|
|
||||||
void DoFillBitWindow ()
|
void DoFillBitWindow ()
|
||||||
{
|
{
|
||||||
if (pos_ + sizeof(ulong) < len_)
|
if (pos_ + sizeof(ulong) < end_pos_)
|
||||||
{
|
{
|
||||||
val_ >>= WBITS;
|
val_ >>= WBITS;
|
||||||
bit_pos_ -= WBITS;
|
bit_pos_ -= WBITS;
|
||||||
@ -1755,7 +1755,7 @@ namespace GameRes.Formats.Google
|
|||||||
|
|
||||||
void ShiftBytes ()
|
void ShiftBytes ()
|
||||||
{
|
{
|
||||||
while (bit_pos_ >= 8 && pos_ < len_)
|
while (bit_pos_ >= 8 && pos_ < end_pos_)
|
||||||
{
|
{
|
||||||
val_ >>= 8;
|
val_ >>= 8;
|
||||||
val_ |= ((ulong)buf_[pos_]) << (LBITS - 8);
|
val_ |= ((ulong)buf_[pos_]) << (LBITS - 8);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user