<commit_before>// Copyright (c) 2009 <NAME> <<EMAIL>>
//
// This file is part of librezin, a free software project.  You can redistribute it and/or modify
// it under the terms of the MIT License.

#include <rezin/png.hpp>

#include <png.h>
#include <sfz/sfz.hpp>

using sfz::Bytes;
using sfz::Exception;
using sfz::WriteTarget;
using sfz::format;

namespace rezin {

namespace {

void png_error(png_struct* png, png_const_charp error_msg) {
    throw Exception(format("png error: {0}", error_msg));
}

void png_write_data(png_struct* png, png_byte* data, png_size_t length) {
    WriteTarget* out = reinterpret_cast<WriteTarget*>(png_get_io_ptr(png));
    write(*out, data, length);
}

void png_flush_data(png_struct* png) {
    static_cast<void>(png);
}

}  // namespace

PngWriter::PngWriter(WriteTarget& out, int32_t width, int32_t height):
        _out(out),
        _width(width),
        _height(height),
        _png(NULL),
        _info(NULL),
        _pixel_index(0) {
    _png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_error, png_error);
    if (!_png) {
        throw Exception("couldn't create png_struct");
    }

    _info = png_create_info_struct(_png);
    if (!_info) {
        png_destroy_write_struct(&_png, NULL);
        throw Exception("couldn't create png_info");
    }

    png_set_write_fn(_png, &_out, png_write_data, png_flush_data);

    png_set_IHDR(_png, _info, width, height, 8, PNG_COLOR_TYPE_RGBA, NULL, NULL, NULL);
    png_set_swap_alpha(_png);
    png_write_info(_png, _info);
}
<commit_msg>Fix compilation on Precise Pangolin.<commit_after>// Copyright (c) 2009 <NAME> <<EMAIL>>
//
// This file is part of librezin, a free software project.  You can redistribute it and/or modify
// it under the terms of the MIT License.

#include <rezin/png.hpp>

#include <png.h>
#include <sfz/sfz.hpp>

using sfz::Bytes;
using sfz::Exception;
using sfz::WriteTarget;
using sfz::format;

namespace rezin {

namespace {

void png_error(png_struct* png, png_const_charp error_msg) {
    throw Exception(format("png error: {0}", error_msg));
}

void png_write_data(png_struct* png, png_byte* data, png_size_t length) {
    WriteTarget* out = reinterpret_cast<WriteTarget*>(png_get_io_ptr(png));
    write(*out, data, length);
}

void png_flush_data(png_struct* png) {
    static_cast<void>(png);
}

}  // namespace

PngWriter::PngWriter(WriteTarget& out, int32_t width, int32_t height):
        _out(out),
        _width(width),
        _height(height),
        _png(NULL),
        _info(NULL),
        _pixel_index(0) {
    _png = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, png_error, png_error);
    if (!_png) {
        throw Exception("couldn't create png_struct");
    }

    _info = png_create_info_struct(_png);
    if (!_info) {
        png_destroy_write_struct(&_png, NULL);
        throw Exception("couldn't create png_info");
    }

    png_set_write_fn(_png, &_out, png_write_data, png_flush_data);

    png_set_IHDR(_png, _info, width, height, 8, PNG_COLOR_TYPE_RGBA, 0, 0, 0);
    png_set_swap_alpha(_png);
    png_write_info(_png, _info);
}

{'fraction_non_alphanumeric': 0.12596649484536082, 'fraction_numerical': 0.008054123711340205, 'mean_word_length': 4.008064516129032, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '761396', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1107, 'n_words': 252}