internal: fix style as determined by clang (#27)

This commit is contained in:
Felix Salcher 2025-07-06 15:14:40 +02:00 committed by GitHub
parent 5f9c68e3f8
commit a71c0529d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 8 deletions

View file

@ -1,8 +1,6 @@
#include "Png.hpp"
#include <cstddef>
#include <vector>
#include <memory>
#include <fstream>
#include <filesystem>
#include <cstdint>
#include <cstdlib>
@ -39,13 +37,13 @@ std::expected<cairo_surface_t*, std::string> PNG::createSurfaceFromPNG(co
return loadPNG(png, info);
}
struct ReadState {
struct SReadState {
const std::span<uint8_t>& data;
size_t offset;
};
void custom_read_function(png_structp png, png_bytep data, png_size_t length) {
ReadState* state = static_cast<ReadState*>(png_get_io_ptr(png));
static void customReadFunction(png_structp png, png_bytep data, png_size_t length) {
SReadState* state = static_cast<SReadState*>(png_get_io_ptr(png));
if (state->offset + length > state->data.size()) {
png_error(png, "read error");
return;
@ -66,9 +64,9 @@ std::expected<cairo_surface_t*, std::string> PNG::createSurfaceFromPNG(const std
if (setjmp(png_jmpbuf(png)))
return std::unexpected("loading png: couldn't setjmp");
ReadState readState = {data, 0};
SReadState readState = {.data = data, .offset = 0};
png_set_read_fn(png, &readState, custom_read_function);
png_set_read_fn(png, &readState, customReadFunction);
png_set_sig_bytes(png, 0);
return loadPNG(png, info);

View file

@ -55,7 +55,7 @@ static bool tryLoadImageFromBuffer(const std::span<uint8_t>& data) {
return cairo_surface_write_to_png(image.cairoSurface()->cairo(), (TEST_DIR + "/" + name + ".png").c_str()) == CAIRO_STATUS_SUCCESS;
}
std::vector<uint8_t> getImageBuffer(const std::string& path) {
static std::vector<uint8_t> getImageBuffer(const std::string& path) {
std::vector<uint8_t> buffer;
std::ifstream file("./resource/images/hyprland.png", std::ios::binary | std::ios::ate);