Libspng

libspng

제품 정보

즐겨찾기

공개 채팅

지원 계획

현재 사용할 수 있는 OSS 플랜이 없습니다.

저장소의 제공자 또는 기여자인 경우 OSS 플랜 추가를 시작할 수 있습니다.

OSS 플랜 추가
여기에서 자세히 알아보세요

이 오픈소스에 대한 플랜을 찾고 있다면 저희에게 문의해 주세요.

전문 공급자와 연락하실 수 있도록 도와드리겠습니다.

제품 세부 정보

Simple, modern libpng alternative

Gitter Financial Contributors on Open Collective Fuzzing Status Coverity tag

libspng

libspng (simple png) is a C library for reading and writing Portable Network Graphics (PNG) format files with a focus on security and ease of use.

libspng is an alternative to libpng, the projects are separate and the APIs are not compatible.

Motivation

The goal is to provide a fast PNG library with a simpler API than libpng, it outperforms the reference implementation in common use cases.

Performance

Features

Feature spng libpng stb_image lodepng
Decode from stream
Gamma correction
No known security bugs[1]
Progressive image read
Parses all standard chunks
Doesn't require zlib[2]
Encoding
Animated PNG Planned [3]

[1] The project is fuzz tested on OSS-Fuzz and vulnerabilities are fixed before they become public.

[2] Building with miniz is supported.

[3] With a 3rd party patch

Getting spng

Download the latest release and include spng.c/spng.h in your project, you can also build with CMake or Meson, refer to the documentation for details.

Usage

#include <spng.h>

/* Create a decoder context */
spng_ctx *ctx = spng_ctx_new(0);

/* Set an input buffer */
spng_set_png_buffer(ctx, buf, buf_size);

/* Determine output image size */
spng_decoded_image_size(ctx, SPNG_FMT_RGBA8, &out_size);

/* Decode to 8-bit RGBA */
spng_decode_image(ctx, out, out_size, SPNG_FMT_RGBA8, 0);

/* Free context memory */
spng_ctx_free(ctx);

/* Creating an encoder context requires a flag */
spng_ctx *enc = spng_ctx_new(SPNG_CTX_ENCODER);

/* Encode to internal buffer managed by the library */
spng_set_option(enc, SPNG_ENCODE_TO_BUFFER, 1);

/* Specify image dimensions, PNG format */
struct spng_ihdr ihdr =
{
    .width = width,
    .height = height,
    .bit_depth = 8,
    .color_type = SPNG_COLOR_TYPE_TRUECOLOR_ALPHA
};

/* Image will be encoded according to ihdr.color_type, .bit_depth */
spng_set_ihdr(enc, &ihdr);

/* SPNG_FMT_PNG is a special value that matches the format in ihdr,
   SPNG_ENCODE_FINALIZE will finalize the PNG with the end-of-file marker */
spng_encode_image(enc, image, image_size, SPNG_FMT_PNG, SPNG_ENCODE_FINALIZE);

/* PNG is written to an internal buffer by default */
void *png = spng_get_png_buffer(enc, &png_size, &error);

/* User owns the buffer after a successful call */
free(png);

/* Free context memory */
spng_ctx_free(enc);

See example.c.

License

Code is licensed under the BSD 2-clause "Simplified" License.

The project contains optimizations and test images from libpng, these are licensed under the PNG Reference Library License version 2.

Security & Testing

Code is written according to the rules of the CERT C Coding Standard. All integer arithmetic is checked for overflow and all error conditions are handled gracefully.

The library is continuously fuzzed by OSS-Fuzz, code is also scanned with Clang Static Analyzer, Coverity Scan and PVS-Studio.

The test suite consists of over 1000 test cases, 175 test images are decoded with all possible output format and flag combinations and compared against libpng for correctness.

Versioning

Releases follow the semantic versioning scheme with additional guarantees:

  • Releases from 0.4.0 to 0.8.x are stable
  • If 1.0.0 will introduce breaking changes then 0.8.x will be maintained as a separate stable branch

Currently 1.0.0 is planned to be compatible.

Documentation

Online documentation is available at libspng.org/docs.

Known Issues

  • Decoding to SPNG_FMT_G8, SPNG_FMT_GA8 and SPNG_FMT_GA16 output formats is not supported for all PNG color type and bit depth combinations, see documentation for details.
  • Gamma correction is not implemented for SPNG_FMT_PNG, SPNG_FMT_G8, SPNG_FMT_GA8 and SPNG_FMT_GA16 output formats.

Supporting spng

You can sponsor development through OpenCollective, funds will be used for maintenance and further development according to the roadmap.

OpenCollective backers

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

문의하기

  • 비즈니스 개발자를 위한 최신 정보를 원하십니까? 소스 코드 프로젝트에 대한 PieceX 커뮤니티의 요구사항을 알아보세요. PieceX의 최신 무료 커뮤니티 코드를 빠르게 알려드립니다.
PieceX Logo