mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-18 08:59:51 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c9d5ddab57 | |||
| 1eb44e3ea6 | |||
| 6c96d9f43d |
@@ -115,8 +115,6 @@ add_library(
|
|||||||
stb.h
|
stb.h
|
||||||
steady_clock.cpp
|
steady_clock.cpp
|
||||||
steady_clock.h
|
steady_clock.h
|
||||||
stream.cpp
|
|
||||||
stream.h
|
|
||||||
string_util.cpp
|
string_util.cpp
|
||||||
string_util.h
|
string_util.h
|
||||||
swap.h
|
swap.h
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
#include "common/common_types.h"
|
|
||||||
#include "common/stream.h"
|
|
||||||
|
|
||||||
namespace Common {
|
|
||||||
|
|
||||||
Stream::Stream() = default;
|
|
||||||
Stream::~Stream() = default;
|
|
||||||
|
|
||||||
void Stream::Seek(s32 offset, SeekOrigin origin) {
|
|
||||||
if (origin == SeekOrigin::SetOrigin) {
|
|
||||||
if (offset < 0) {
|
|
||||||
position = 0;
|
|
||||||
} else if (position >= buffer.size()) {
|
|
||||||
position = buffer.size();
|
|
||||||
} else {
|
|
||||||
position = offset;
|
|
||||||
}
|
|
||||||
} else if (origin == SeekOrigin::FromCurrentPos) {
|
|
||||||
Seek(static_cast<s32>(position) + offset, SeekOrigin::SetOrigin);
|
|
||||||
} else if (origin == SeekOrigin::FromEnd) {
|
|
||||||
Seek(static_cast<s32>(buffer.size()) - offset, SeekOrigin::SetOrigin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 Stream::ReadByte() {
|
|
||||||
if (position < buffer.size()) {
|
|
||||||
return buffer[position++];
|
|
||||||
} else {
|
|
||||||
throw std::out_of_range("Attempting to read a byte not within the buffer range");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Stream::WriteByte(u8 byte) {
|
|
||||||
if (position == buffer.size()) {
|
|
||||||
buffer.push_back(byte);
|
|
||||||
position++;
|
|
||||||
} else {
|
|
||||||
buffer.insert(buffer.begin() + position, byte);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Common
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "common/common_types.h"
|
|
||||||
|
|
||||||
namespace Common {
|
|
||||||
|
|
||||||
enum class SeekOrigin {
|
|
||||||
SetOrigin,
|
|
||||||
FromCurrentPos,
|
|
||||||
FromEnd,
|
|
||||||
};
|
|
||||||
|
|
||||||
class Stream {
|
|
||||||
public:
|
|
||||||
/// Stream creates a bitstream and provides common functionality on the stream.
|
|
||||||
explicit Stream();
|
|
||||||
~Stream();
|
|
||||||
|
|
||||||
Stream(const Stream&) = delete;
|
|
||||||
Stream& operator=(const Stream&) = delete;
|
|
||||||
|
|
||||||
Stream(Stream&&) = default;
|
|
||||||
Stream& operator=(Stream&&) = default;
|
|
||||||
|
|
||||||
/// Reposition bitstream "cursor" to the specified offset from origin
|
|
||||||
void Seek(s32 offset, SeekOrigin origin);
|
|
||||||
|
|
||||||
/// Reads next byte in the stream buffer and increments position
|
|
||||||
u8 ReadByte();
|
|
||||||
|
|
||||||
/// Writes byte at current position
|
|
||||||
void WriteByte(u8 byte);
|
|
||||||
|
|
||||||
[[nodiscard]] std::size_t GetPosition() const {
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] std::vector<u8>& GetBuffer() {
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<u8>& GetBuffer() const {
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<u8> buffer;
|
|
||||||
std::size_t position{0};
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Common
|
|
||||||
@@ -892,20 +892,28 @@ void VpxRangeEncoder::Write(bool bit, s32 probability) {
|
|||||||
count += shift;
|
count += shift;
|
||||||
|
|
||||||
if (count >= 0) {
|
if (count >= 0) {
|
||||||
const s32 offset = shift - count;
|
auto const write_byte = [&](u8 byte) {
|
||||||
|
if (stream_pos == stream_data.size()) {
|
||||||
if (((low_value << (offset - 1)) >> 31) != 0) {
|
stream_data.push_back(byte);
|
||||||
const s32 current_pos = static_cast<s32>(base_stream.GetPosition());
|
++stream_pos;
|
||||||
base_stream.Seek(-1, Common::SeekOrigin::FromCurrentPos);
|
} else {
|
||||||
while (PeekByte() == 0xff) {
|
stream_data.insert(stream_data.begin() + stream_pos, byte);
|
||||||
base_stream.WriteByte(0);
|
|
||||||
|
|
||||||
base_stream.Seek(-2, Common::SeekOrigin::FromCurrentPos);
|
|
||||||
}
|
}
|
||||||
base_stream.WriteByte(static_cast<u8>((PeekByte() + 1)));
|
};
|
||||||
base_stream.Seek(current_pos, Common::SeekOrigin::SetOrigin);
|
|
||||||
|
const s32 offset = shift - count;
|
||||||
|
if (((low_value << (offset - 1)) >> 31) != 0) {
|
||||||
|
auto const current_pos = stream_pos;
|
||||||
|
--stream_pos;
|
||||||
|
while (stream_data[stream_pos] == 0xff) {
|
||||||
|
write_byte(0);
|
||||||
|
stream_pos -= 2;
|
||||||
|
}
|
||||||
|
write_byte(stream_data[stream_pos] + 1);
|
||||||
|
stream_pos = current_pos;
|
||||||
}
|
}
|
||||||
base_stream.WriteByte(static_cast<u8>((low_value >> (24 - offset))));
|
write_byte(u8((low_value >> (24 - offset))));
|
||||||
|
++stream_pos;
|
||||||
|
|
||||||
low_value <<= offset;
|
low_value <<= offset;
|
||||||
shift = count;
|
shift = count;
|
||||||
@@ -923,13 +931,6 @@ void VpxRangeEncoder::End() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 VpxRangeEncoder::PeekByte() {
|
|
||||||
const u8 value = base_stream.ReadByte();
|
|
||||||
base_stream.Seek(-1, Common::SeekOrigin::FromCurrentPos);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
VpxBitStreamWriter::VpxBitStreamWriter() = default;
|
VpxBitStreamWriter::VpxBitStreamWriter() = default;
|
||||||
|
|
||||||
VpxBitStreamWriter::~VpxBitStreamWriter() = default;
|
VpxBitStreamWriter::~VpxBitStreamWriter() = default;
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/scratch_buffer.h"
|
#include "common/scratch_buffer.h"
|
||||||
#include "common/stream.h"
|
|
||||||
#include "video_core/host1x/codecs/decoder.h"
|
#include "video_core/host1x/codecs/decoder.h"
|
||||||
#include "video_core/host1x/codec_types.h"
|
#include "video_core/host1x/codec_types.h"
|
||||||
#include "video_core/host1x/nvdec_common.h"
|
#include "video_core/host1x/nvdec_common.h"
|
||||||
@@ -52,16 +51,19 @@ public:
|
|||||||
void End();
|
void End();
|
||||||
|
|
||||||
[[nodiscard]] std::vector<u8>& GetBuffer() {
|
[[nodiscard]] std::vector<u8>& GetBuffer() {
|
||||||
return base_stream.GetBuffer();
|
return stream_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<u8>& GetBuffer() const {
|
[[nodiscard]] const std::vector<u8>& GetBuffer() const {
|
||||||
return base_stream.GetBuffer();
|
return stream_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u8 PeekByte();
|
u8 PeekByte();
|
||||||
Common::Stream base_stream{};
|
|
||||||
|
std::vector<u8> stream_data{};
|
||||||
|
size_t stream_pos;
|
||||||
|
|
||||||
u32 low_value{};
|
u32 low_value{};
|
||||||
u32 range{0xff};
|
u32 range{0xff};
|
||||||
s32 count{-24};
|
s32 count{-24};
|
||||||
|
|||||||
Reference in New Issue
Block a user