Giter Site home page Giter Site logo

kornelski / mediancut-posterizer Goto Github PK

View Code? Open in Web Editor NEW
234.0 15.0 32.0 75 KB

Lossy PNG compressor for RGBA PNGs. Has two modes: lossy averaging filter (blurizer) that denoises the image and optimal posterization using Median Cut quantization to reduce number of unique colors in the image with minimal visual distortion

Home Page: https://pngmini.com

Makefile 1.25% C 94.99% Objective-C 3.75%
png-compression lossy png minification image-optimization

mediancut-posterizer's Introduction

Lossy compressors for true-color PNGs

Median Cut PNG Posterizer

Reduces number of distinct color/alpha intensities in the image. Unlike typical posterization, which distributes levels evenly, this one tries to pick levels intelligently using variance-based Median Cut and Voronoi iteration.

The goal of this tool is to make RGB/RGBA PNG images more compressible, assuming that lower number of unique byte values increses chance of finding repetition and improves efficiency of Huffman coding.

Blurizer

With -b argument it reduces PNG file sizes by selectively blurring the image. It makes image more compressible by making it more predictable for PNG's diagonal average prediction filter.

Usage

posterize [ -v ] [ -b ] [ -d ] [ -Q <quality> ] [ levels ] -- [ input.png ] [ output.png ]
  • -b — Use blurring instead of posterization (recommended). Without this argument posterization is used.
  • -Q num — Picks minimum number of levels needed to achieve given quality. num is quality 0-100 (100 is best, similar to JPEG). Number of levels is optional if quality is specified.
  • levels — Number of levels to use (2-255). Lower number gives worse quality, but smaller file.
  • -d — Enables simple ordered dithering in posterization mode.
  • -v — Verbose output. Prints mean square error (MSE) caused by posterization.

If input/output files are not specified then stdin/stdout is used respectively.

Posterized images can be further compressed using PNGOUT or similar. Try ImageOptim.

GUI?

Integrated in ImageAlpha.app.

Licenses

Posterizer

© 2011-2014 Kornel Lesiński.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

rwpng.c

© 1997-2002 by Greg Roelofs. © 2009-2014 by Kornel Lesiński.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

mediancut-posterizer's People

Contributors

agprimatic avatar ikem-krueger avatar kornelski avatar panzi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mediancut-posterizer's Issues

License question

I don't want to offend - if you're a big fan of the GPL I apologize - but as the developer of several OSS imaging libraries, I've found the Apache license (or even MIT/BSD) to encourage contributions much more effectively. Update 2016: I now use AGPLv3, and offer commercial licenses. Slightly fewer contributions but more effective overall at making projects sustainable

I originally released GPL/LGPL myself, but got 0 contributions. Under MIT/Apache I've seen hundreds....

What you've built here is fantastic; I'd love to integrate my libraries with it. But under the GPL, I'm unable to.

Update version to match ImageAlpha

The version of posterizer provided in ImageAlpha is different from posterize as it exists in this repo. This becomes evident when running the following:

$ posterize -v 64 test.png test.png
MSE=20.288 (Q=43, 64 levels)
$ wc -c test.png
210715 test.png
$ /Applications/ImageAlpha.app/Contents/MacOS/posterizer -v 64 test.png test.png 
MSE=17.192 (Q=50, 64 levels)
$ wc -c test.png
137719 test.png

AddressSanitizer report LeakSanitizer: SEGV when use the posterize

Version

Posterize (2.1) 2015

Environment

Ubuntu 18.04,64 bit

Command

Compile test program:

$ make clean all

Compile test program with address sanitizer:

  • Update Makefile:
CFLAGS ?= -Wall -Wno-unknown-pragmas -I. -I/usr/local/include/libpng16/ -I/usr/local/include/ -I/usr/include/ -I/usr/X11/include/ $(CFLAGSOPT) -fsanitize=address
LDFLAGS ?= -L/usr/local/lib/ -L/usr/lib/ -L/usr/X11/lib/ -fsanitize=address
  • Compile program:
$ make clean all

Result

The result of running without ASAN:

$ ./posterize -Q 95 SEGV.png

error: gamma value does not match sRGB
libpng warning: Invalid image width in IHDR
libpng warning: Image width exceeds user limit in IHDR
  error: Invalid IHDR data
Segmentation fault (core dumped)

Information obtained by using ASAN:

$ ./posterize_asan -Q 95 SEGV.png

  error: gamma value does not match sRGB
AddressSanitizer:DEADLYSIGNAL
=================================================================
==18674==ERROR: AddressSanitizer: SEGV on unknown address 0x02007eb79a0c (pc 0x55de6e864ae6 bp 0x0ffff5c0cf9a sp 0x7fffae067ca0 T0)
==18674==The signal is caused by a READ memory access.
    #0 0x55de6e864ae6 in rwpng_write_image24 (/docker/mp/posterize+0xcae6)
    #1 0x55de6e85c11f in main (/docker/mp/posterize+0x411f)
    #2 0x7f7a1ae090b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #3 0x55de6e85c6ed in _start (/docker/mp/posterize+0x46ed)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/docker/mp/posterize+0xcae6) in rwpng_write_image24
==18674==ABORTING

Description

When we execute the command, asan reports the error LeakSanitizer: SEGV.

Poc

Poc file is this.

New windows builds?

Hi.

Can you please provide a new windows build with the new -b option? I tried for over an hour to build it unsuccessfuly.

Also, would be nice if you provided matching libpng & zlib libraries & a windows build script.

Thank you, -J

"posterize -b" produces larger files size at worse qualities

I've tried a number of different options and no matter what I try, I can't get the command line of posterize -b to produce the same quality and file size as ImageAlpha.app.

Basically I'm taking ~300KB png and in ImageAlpha using Blurizer and about 64 quality is what I want and it gives me ~150KB png that looks great, but this process is manual.

Using the CLI I take the same png and provide these options "posterize -b 64" and the image looks really bad, broken, artifacts and the file size is ~300KB. I use "posterize -b -Q80" and the image looks good but the file size is 450KB+.

I tried lowest quality settings just to see and with 2 levels i get ~260KB image with total distortion of the image. At -Q10 I get a slightly artifacted image still relatively ok looking but ~400KB

Any help?

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.