mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-16 16:00:30 +02:00
Replace zlib, zstd, libchdr, libzip and libpng with libretro-common
Deflate, zlib and gzip streams go through rinflate and rdeflate, zstd through rzstd, CHD images through rchd, zip archives through rzip_archive and PNG through rpng. The bundled libraries, their build glue and the system-library options are gone; adler32 and uncompress keep zlib's ABI for the prebuilt FFmpeg archives that still call them. libretro-common is one CMake library that the core, the headless tool and the unit tests all link. The reads take shorter paths on the way. CHD decodes straight from the loader's reads and a range of blocks at a time, and a file read at any alignment decodes into place; CSO keeps one inflate stream instead of one per block; a plain ISO serves a file read with one read of its exact bytes; a stored zip member is read in place and a deflated one through restart points rather than a copy of the whole image in memory; zip members decode into the caller's buffer; sequential reads through the frontend's VFS skip the seek, which also keeps its buffering. libretro/test reads one image as ISO, CSO, CHD and zip through the block devices, boots each, and checks the codecs against Python-made vectors; a CI job runs it.
This commit is contained in:
1 parent
6b22f99818
commit
d56b453891
252 files changed
+1751
-91370
No files matched your search
@@ -16,8 +16,9 @@
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <algorithm>
|
||||
#include <png.h>
|
||||
#include <zlib.h>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/Data/Format/PNGLoad.h"
|
||||
#include "Common/Data/Encoding/Base64.h"
|
||||
#include "Common/StringUtils.h"
|
||||
#include "Core/Debugger/WebSocket/GPUBufferSubscriber.h"
|
||||
@@ -61,22 +62,13 @@ static bool StreamBufferToDataURI(DebuggerRequest &req, const GPUDebugBuffer &bu
|
||||
h = totalPixels / w;
|
||||
}
|
||||
|
||||
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
|
||||
if (!png_ptr) {
|
||||
req.Fail("Internal error setting up PNG encoder (png_ptr)");
|
||||
std::vector<uint8_t> png;
|
||||
const bool encoded = pngEncode(&png, buffer, w, h, includeAlpha ? PNGFormat::RGBA8888 : PNGFormat::RGB888);
|
||||
delete [] flipbuffer;
|
||||
if (!encoded) {
|
||||
req.Fail("Internal error encoding PNG");
|
||||
return false;
|
||||
}
|
||||
png_infop info_ptr = png_create_info_struct(png_ptr);
|
||||
if (!info_ptr) {
|
||||
png_destroy_write_struct(&png_ptr, nullptr);
|
||||
req.Fail("Internal error setting up PNG encoder (info_ptr)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Speed. Wireless N should give 35 KB/ms. For most devices, zlib/filters will cost more.
|
||||
png_set_compression_strategy(png_ptr, Z_RLE);
|
||||
png_set_compression_level(png_ptr, 1);
|
||||
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_FILTER_NONE);
|
||||
|
||||
auto &json = req.Respond();
|
||||
json.writeInt("width", w);
|
||||
@@ -88,68 +80,12 @@ static bool StreamBufferToDataURI(DebuggerRequest &req, const GPUDebugBuffer &bu
|
||||
// Start a value...
|
||||
json.writeRaw("uri", "");
|
||||
req.Flush();
|
||||
// Now we'll write it directly to the stream.
|
||||
// Now we'll write it directly to the stream, in pieces that are a multiple of 3 bytes
|
||||
// so the base64 has no padding until the end.
|
||||
req.ws->AddFragment(false, "\"data:image/png;base64,");
|
||||
|
||||
struct Context {
|
||||
DebuggerRequest *req;
|
||||
uint8_t buf[3];
|
||||
size_t bufSize;
|
||||
};
|
||||
Context ctx = { &req, {}, 0 };
|
||||
|
||||
auto write = [](png_structp png_ptr, png_bytep data, png_size_t length) {
|
||||
auto ctx = (Context *)png_get_io_ptr(png_ptr);
|
||||
auto &req = *ctx->req;
|
||||
|
||||
// If we buffered some bytes, fill to 3 bytes for a clean base64 encode.
|
||||
// This way we don't have padding.
|
||||
while (length > 0 && ctx->bufSize > 0 && ctx->bufSize != 3) {
|
||||
ctx->buf[ctx->bufSize++] = data[0];
|
||||
data++;
|
||||
length--;
|
||||
}
|
||||
|
||||
if (ctx->bufSize == 3) {
|
||||
req.ws->AddFragment(false, Base64Encode(ctx->buf, ctx->bufSize));
|
||||
ctx->bufSize = 0;
|
||||
}
|
||||
_assert_(ctx->bufSize == 0 || length == 0);
|
||||
|
||||
// Save bytes that would result in padding for next time.
|
||||
size_t toBuffer = length % 3;
|
||||
for (size_t i = 0; i < toBuffer; ++i) {
|
||||
ctx->buf[i] = data[length - toBuffer + i];
|
||||
ctx->bufSize++;
|
||||
}
|
||||
|
||||
if (length > toBuffer) {
|
||||
req.ws->AddFragment(false, Base64Encode(data, length - toBuffer));
|
||||
}
|
||||
};
|
||||
auto flush = [](png_structp png_ptr) {
|
||||
// Nothing, just here to prevent stdio flush.
|
||||
};
|
||||
|
||||
png_bytep *row_pointers = new png_bytep[h];
|
||||
u32 stride = includeAlpha ? w * 4 : w * 3;
|
||||
for (u32 i = 0; i < h; ++i) {
|
||||
row_pointers[i] = (u8 *)buffer + stride * i;
|
||||
}
|
||||
|
||||
png_set_write_fn(png_ptr, &ctx, write, flush);
|
||||
int colorType = includeAlpha ? PNG_COLOR_TYPE_RGBA : PNG_COLOR_TYPE_RGB;
|
||||
png_set_IHDR(png_ptr, info_ptr, w, h, 8, colorType, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
png_set_rows(png_ptr, info_ptr, row_pointers);
|
||||
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, nullptr);
|
||||
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
delete [] row_pointers;
|
||||
delete [] flipbuffer;
|
||||
|
||||
if (ctx.bufSize > 0) {
|
||||
req.ws->AddFragment(false, Base64Encode(ctx.buf, ctx.bufSize));
|
||||
ctx.bufSize = 0;
|
||||
const size_t piece = 3 * 16384;
|
||||
for (size_t pos = 0; pos < png.size(); pos += piece) {
|
||||
req.ws->AddFragment(false, Base64Encode(png.data() + pos, std::min(piece, png.size() - pos)));
|
||||
}
|
||||
|
||||
// End the string.
|
||||
|
||||
Reference in new issue
Block a user