Coder Social home page Coder Social logo

brackeen / ok-file-formats Goto Github PK

View Code? Open in Web Editor NEW
105.0 7.0 14.0 1.71 MB

Decoders for PNG, JPEG, WAV, and a few other file formats

License: MIT License

Objective-C 1.30% C 91.39% CMake 6.35% Batchfile 0.16% Shell 0.55% VBScript 0.25%
c png jpg fnt mo csv wav caf

ok-file-formats's Introduction

ok-file-formats

C functions for reading a few different file formats. No external dependencies. Written in C99.

Library Description
ok_png Reads PNG files. Supports Apple's proprietary CgBI chunk. Tested against the PngSuite.
ok_jpg Reads JPEG files. Baseline and progressive formats. Interprets EXIF orientation tags. No CMYK support.
ok_wav Reads WAV and CAF files. PCM, u-law, a-law, and ADPCM formats.
ok_fnt Reads AngelCode BMFont files. Binary format from AngelCode Bitmap Font Generator v1.10 or newer.
ok_csv Reads Comma-Separated Values files.
ok_mo Reads gettext MO files.

The source files do not depend on one another. If all you need is to read a PNG file, just use ok_png.h and ok_png.c.

The CMakeLists.txt file can be used but is not required.

The ok_png, ok_jpg, and ok_wav functions include:

  • Option to use a custom allocator (ok_png_read_with_allocator, etc.)
  • Fuzz tests.

The ok_png and ok_jpg functions include these decode options:

  • Get the image dimensions without decoding image data.
  • Premultiply alpha.
  • Flip the image vertically.

Example: Decode PNG

#include <stdio.h>
#include "ok_png.h"

int main() {
    FILE *file = fopen("my_image.png", "rb");
    ok_png image = ok_png_read(file, OK_PNG_COLOR_FORMAT_RGBA | OK_PNG_PREMULTIPLIED_ALPHA | OK_PNG_FLIP_Y);
    fclose(file);
    if (image.data) {
        printf("Got image! Size: %li x %li\n", (long)image.width, (long)image.height);
        free(image.data);
    }
    return 0;
}

Recent breaking changes in ok_png, ok_jpg, and ok_wav:

  • The read functions now return the ok_png, ok_jpg, and ok_wav structs on the stack instead of the heap. (These structs are small, around 24-32 bytes).
  • Replaced ok_png_read_to_buffer with ok_png_read_with_allocator.
  • Replaced ok_png_read_from_callbacks with ok_png_read_from_input.
  • Replaced error_message with error_code.
  • Removed ok_png_free. Free png.data directly instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.