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

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
Issues
  • 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
  • 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
  • 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 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
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
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 4 May 5, 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 24 Aug 7, 2022
Small and dirty header-only library that supports user input with some more advanced features than in the standard lib.

dirty-term Small and dirty header-only library that supports user input with some more advanced features than in the standard lib. This small, lightwe

null 3 Apr 24, 2022
JS/WASM build of libjxl (JPEG-XL)

libjxl-js JS/WASM build of libjxl (JPEG-XL) Try It Out! Try it in your browser here Building This project uses git submodules to pull in libjxl. If de

Chris Hafey 9 Mar 27, 2022
Second life for famous JPEGView - fast and tiny viewer/editor for JPEG, BMP, PNG, WEBP, TGA, GIF and TIFF images with a minimalist GUI and base image processing.

JPEGView-Image-Viewer-and-Editor Updated Dec 07 2021. Version 1.1.1.0 has been released. Download link1, link2 added. Second life for famous JPEGView

Ann Hatt 25 Aug 5, 2022
MozJPEG improves JPEG compression efficiency achieving higher visual quality and smaller file sizes at the same time

Mozilla JPEG Encoder Project MozJPEG improves JPEG compression efficiency achieving higher visual quality and smaller file sizes at the same time. It

Mozilla 4.9k Aug 9, 2022
A single file, single function, header to make notifications on the PS4 easier

Notifi Synopsis Adds a single function notifi(). It functions like printf however the first arg is the image to use (NULL and any invalid input should

Al Azif 7 Mar 24, 2022
Just another "Won't Fix" Windows Privilege Escalation from User to Domain Admin.

RemotePotato0 Just another "Won't Fix" Windows Privilege Escalation from User to Domain Admin. RemotePotato0 is an exploit that allows you to escalate

null 1.1k Aug 3, 2022
A static C++ library for the generation of discrete functions on a box-shaped domain

A static C++ library for the generation of discrete functions on a box-shaped domain. This is especially suited for the discretization of signed distance fields.

Interactive Computer Graphics 220 Jul 28, 2022
Project #1: Run-length Encoding (Computer Architecture, Fall 2021)

4190.308 Computer Architecture (Fall 2021) Project #1: Run-length Encoding Due: 11:59PM, September 26 (Sunday) Introduction In this project, you need

SNU Systems Software & Architecture Laboratory 4 Apr 18, 2022
Lingo - Text encoding for modern C++

Lingo Lingo is an encoding aware string library for C++11 and up. It aims to be a drop in replacement for the standard library strings by defining new

Rick de Water 28 Nov 21, 2021
A C++ concepts and range based character encoding and code point enumeration library

Travis CI (Linux:gcc) Text_view A C++ Concepts based character encoding and code point enumeration library. This project is the reference implementati

Tom Honermann 121 Aug 5, 2022
Read file to console, automatically recognize file encoding, include ansi, utf16le, utf16be, utf8. Currently output ansi as gbk for chinese text search.

rgpre A tool for rg --pre. Read file to console, automatically recognize file encoding, include ansi, utf16le, utf16be, utf8. Currently output ansi as

null 3 Mar 18, 2022
Stack-based texture generation tool written in C99!

Stack-based texture generation tool written in C99! Brought to you by @zaklaus and contributors Introduction zpl.texed is a cross-platform stack-based

zpl | pushing the boundaries of simplicity. 17 May 1, 2022
ASMotor is a portable and generic assembler engine and development system written in ANSI C99

ASMotor is a portable and generic assembler engine and development system written in ANSI C99 and licensed under the GNU Public License v3. The package consists of the assembler, the librarian and the linker. It can be used as either a cross or native development system.

null 40 Jul 28, 2022
QtVerbalExpressions - This Qt lib is based off of the C++ VerbalExpressions library. [MIT]

QtVerbalExpressions Qt Regular Expressions made easy This Qt lib is based off of the C++ VerbalExpressions library by whackashoe. Testing if we have a

null 54 Jul 2, 2022
个人专用 ONEPLUS 5 内核,做了一些基础的反调试修改(从 maps 隐藏特定 lib,最完整最正常的 tracerPid 修改措施)

Linux kernel release 4.x <http://kernel.org/> These are the release notes for Linux version 4. Read them carefully, as they tell you what this is al

REV1SI0N 37 Jul 21, 2022
Android Dumper Lib From The Memory

LibDumper This Project Is Using For Make You Easy Dump Lib From The Memory Changelog 3.5 : fixing corrupt file after fixing elf format result dump [st

BryanGIG 31 Jan 27, 2022