Single header lib for JPEG encoding. Public domain. C99. stb style.

Related tags

Compression TinyJPEG
Overview

tiny_jpeg.h

A header-only public domain implementation of Baseline JPEG compression.

Features:

  • stb-style header only library.
  • Does not do dynamic allocations
  • Simple API:
    • 2 API calls.
    • 3-value compression quality: 3 (best quality), 2 (Very good), 1 (Noticeable artifacts, best compression)
  • Public domain
Comments
  • option : stride in bytes

    option : stride in bytes

    In stb_write_image, function have a 4° parameter: stride_in_bytes

    int stbi_write_png(char const *filename, int w, int h, int comp, const void *data, int stride_in_bytes);

    so writing

    unsigned char* buffer = (unsigned char_)malloc (width * height * 3); glReadPixels (0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, buffer); unsigned char_ last_row = buffer + (width * 3 * (height - 1)); stbi_write_png (name, width, height, 3, last_row, -3 * width)

    There is no need to flip the image OpenGL.

    could it have on tje_encode_to_file_at_quality a fourth identical parameter?

    opened by AssociationSirius 3
  • Corrupt JPEG data.

    Corrupt JPEG data.

    With use of function tje_encode_to_file_at_quality:

    glReadPixels( (rw-rh)/2, 0, rh, rh, GL_RGB, GL_UNSIGNED_BYTE, pixels);
    tje_encode_to_file_at_quality(filename.c_str(), 3,rh, rh, 3, pixels);
    

    The Gimp say me: Corrupt JPEG data: 26 extraneous bytes before marker 0xdb

    spacecrafter-00355

    bug 
    opened by AssociationSirius 3
  • Special request

    Special request

    I'm sorry to ask for that again but with the time that has passed, I'm unable to manipulate your source code to save an image from the OpenGL buffer to avoid symmetry of the image.

    You gave me an indication but I forgot!

    The problem is that in OpenGL I get this image while I should get the image by vertical mirror.

    spacecrafter-17 03 05-08 00 13

    Thanks again for everything. Sorry to ask the same question twice!

    opened by AssociationSirius 2
  • making the library multithread safe

    making the library multithread safe

    Dear Sergio,

    Thanks for the library, I appreciate the small one header library. I really like it. Because I use the library in a multithreaded program on FreeBSD I made some necessary changes. The library can now compile correctly on FreeBSD. The global buffer is removed and added to the state so no race conditions occur. Will you consider importing these changes into master? I more changes are necessary, I would like to help.

    Thanks in advance, Bernard van Gastel

    opened by bvgastel 2
  • Don't byteswap 16-bit words if already big-endian

    Don't byteswap 16-bit words if already big-endian

    Previously, this assumed that native endianness was always little-endian, which is true for x86 and most other architectures, but untrue for some (mostly older) unusual architectures.

    opened by smcv 1
  • crash with memcpy

    crash with memcpy

    with bug comment fixed:

    Function tjei_encode_main crash at execution


    When compile, GCC say:

    In function ‘void* memcpy(void_, const void_, size_t)’, inlined from ‘int tjei_encode_main(TJEState_, const unsigned char_, int, int, int)’ at tiny_jpeg.h:948:59: /usr/include/x86_64-linux-gnu/bits/string3.h:53:71: warning: call to void* builtin___memcpy_chk(void, const void, long unsigned int, long unsigned int) will always overflow destination buffer return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));

    opened by AssociationSirius 0
  • g++ : warning: missing initializer for member

    g++ : warning: missing initializer for member

    with build commit /f6d01b81294e10b5ccf7700918eef60eeb16e8f1

    g++ say: (with params -Wall -Wextra)

    tiny_jpeg.h: In function ‘int tje_encode_to_file_at_quality(const char_, int, int, int, int, const unsigned char_)’:

    tiny_jpeg.h:1130:26: warning: missing initializer for member ‘TJEState_s::ehuffcode’ tiny_jpeg.h:1130:26: warning: missing initializer for member ‘TJEState_s::ht_bits’ tiny_jpeg.h:1130:26: warning: missing initializer for member ‘TJEState_s::ht_vals’ tiny_jpeg.h:1130:26: warning: missing initializer for member ‘TJEState_s::qt_luma’ tiny_jpeg.h:1130:26: warning: missing initializer for member ‘TJEState_s::qt_chroma’ tiny_jpeg.h:1130:26: warning: missing initializer for member ‘TJEState_s::fd’

    bug 
    opened by AssociationSirius 0
  • Added ENABLE_FOPEN define, if not defined, defaults on. But allows you to exclude FILE funcs

    Added ENABLE_FOPEN define, if not defined, defaults on. But allows you to exclude FILE funcs

    I was using this for a UWP app/library in unity, and UWP/win10 sdk doesn't allow fopen usage (or maybe the unsafe version, I can't remember, I was in a rush, either way, I had to remove these :)

    So I needed to make a change to cleanly exclude that support.

    This is that change!

    opened by SoylentGraham 0
  • Remove warning on Visual Studio

    Remove warning on Visual Studio

    Tested on Visual Studio 2015, should work on 2012, 2013, 2017 and maybe even more.

    Visual Studio refuse to compile due to the use of fopen(). This pragma disable the warning and let the compilation proceed.

    I took the code from LodePNG https://github.com/lvandeve/lodepng/blob/master/lodepng.cpp#L37-L40 That's not a very important PR but may be useful to somes !

    Thanks.

    opened by mhammerc 0
Owner
Sergio Gonzalez
Sergio Gonzalez
miniz: Single C source file zlib-replacement library, originally from code.google.com/p/miniz

Miniz Miniz is a lossless, high performance data compression library in a single source file that implements the zlib (RFC 1950) and Deflate (RFC 1951

Rich Geldreich 1.6k Oct 3, 2022
Gzip header-only C++ library

Gzip C++ lib for gzip compression and decompression. Extracted from mapnik-vector-tile for light-weight modularity. Usage // Include the specific gzip

Mapbox 237 Sep 29, 2022
A C++ header-only ZLib wrapper

A C++ ZLib wrapper This C++ header-only library enables the use of C++ standard iostreams to access ZLib-compressed streams. For input access (decompr

Matei David 226 Sep 8, 2022
Single header lib for JPEG encoding. Public domain. C99. stb style.

tiny_jpeg.h A header-only public domain implementation of Baseline JPEG compression. Features: stb-style header only library. Does not do dynamic allo

Sergio Gonzalez 201 Sep 18, 2022
stb single-file public domain libraries for C/C++

stb single-file public domain (or MIT licensed) libraries for C/C++ Noteworthy: image loader: stb_image.h image writer: stb_image_write.h image resize

Sean Barrett 20k Oct 1, 2022
stb single-file public domain libraries for C/C++

stb single-file public domain (or MIT licensed) libraries for C/C++ Noteworthy: image loader: stb_image.h image writer: stb_image_write.h image resize

Sean Barrett 20k Oct 1, 2022
linalg.h is a single header, public domain, short vector math library for C++

linalg.h linalg.h is a single header, public domain, short vector math library for C++. It is inspired by the syntax of popular shading and compute la

Sterling Orsten 746 Oct 1, 2022
A single file, public domain C implementation of aSchroeder reverb.

Introduction This is a reverb implementation based on Freeverb, a public domain reverb written by Jezar at Dreampoint in 2000. The library is written

Philip Bennefall 54 Oct 4, 2022
Single file public domain networking library

zed_net zed_net is a single file, public domain library that provides a simple wrapper around BSD sockets (Winsock 2.2 on Windows), intended primary f

Ian T. Jacobsen 50 Jul 18, 2022
Several single-file, cross-platform, public domain libraries for C/C++ that I use for learning / testing

HTC Several single-file, cross-platform, public domain libraries for C/C++ that I use for learning / testing (Not meant for production code). This is

Chris 19 Jul 12, 2022
A collection of public domain/unlicense single-file cryptography

simple-crypto A collection of single-file public domain/unlicense cryptographic functions in different programming languages. Feel free to copy-paste

null 4 Sep 24, 2022
⛳ Simple, extensible, header-only C++17 argument parser released into the public domain.

⛳ flags Simple, extensible, header-only C++17 argument parser released into the public domain. why requirements api get get (with default value) posit

sailormoon 204 Aug 11, 2022
Public domain, header-only file to simplify the C programmer's life in their interaction with strings

SCL_String Public domain, header-only file to simplify the C programmer's life in their interaction with strings NOTE: This library is still under con

null 5 Aug 22, 2022
An 'embedded-friendly' (aka Arduino) JPEG image encoding library

Starting in the late 80's I wrote my own imaging codecs for the existing standards (CCITT G3/G4 was the first). I soon added GIF, JPEG and not long after that, the PNG specification was ratified. All of this code was "clean room" - written just from the specification. I used my imaging library in many projects and products over the years and recently decided that some of my codecs could get a new lease on life as open source, embedded-friendly libraries for microcontrollers.

Larry Bank 37 Sep 18, 2022
Analysing and implementation of lossless data compression techniques like Huffman encoding and LZW was conducted along with JPEG lossy compression technique based on discrete cosine transform (DCT) for Image compression.

PROJECT FILE COMPRESSION ALGORITHMS - Huffman compression LZW compression DCT Aim of the project - Implement above mentioned compression algorithms an

null 1 Dec 14, 2021
Telepati 2 Nov 29, 2021
Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

rpmalloc - General Purpose Memory Allocator This library provides a public domain cross platform lock free thread caching 16-byte aligned memory alloc

Mattias Jansson 1.6k Sep 23, 2022
Jittey - A public domain text editor written in C and Win32

Jittey (Jacob's Terrific Text Editor) is a single-file basic text editor written in pure C and Win32, there is no real reason to use it, but it

Jakub Šebek 25 Aug 8, 2022
The MHS Filesystem- A very simple linked-list based file system designed for recoverability and low data redundancy. Public domain filesystem (Version 1)

MHS Filesystem The MHS filesystem. Features: can be modified to work with any size of disk or sector, even non powers of two! Allocation bitmap stored

DMHSW 8 Sep 17, 2022
Rpmalloc - Public domain cross platform lock free thread caching 16-byte aligned memory allocator implemented in C

rpmalloc - General Purpose Memory Allocator This library provides a public domain cross platform lock free thread caching 16-byte aligned memory alloc

Mattias Jansson 1.6k Oct 2, 2022