pax_global_header 0000666 0000000 0000000 00000000064 13602415555 0014520 g ustar 00root root 0000000 0000000 52 comment=200af4841aa67abc2903733cd59e2ff6445c9655
pngquant-2.12.6/ 0000775 0000000 0000000 00000000000 13602415555 0013445 5 ustar 00root root 0000000 0000000 pngquant-2.12.6/.gitignore 0000664 0000000 0000000 00000000206 13602415555 0015433 0 ustar 00root root 0000000 0000000 *.dylib
*.mode1v3
*.o
*.lo
*.pbxproj
*.pbxuser
build
DerivedData
pngquant
lib/libimagequant.a
*.obj
*.lib
config.mk
test/test
target/
pngquant-2.12.6/.gitmodules 0000664 0000000 0000000 00000000125 13602415555 0015620 0 ustar 00root root 0000000 0000000 [submodule "lib"]
path = lib
url = https://github.com/ImageOptim/libimagequant.git
pngquant-2.12.6/.travis.yml 0000664 0000000 0000000 00000001000 13602415555 0015545 0 ustar 00root root 0000000 0000000 language: c
sudo: required
os:
- linux
- osx
before_install:
- if [[ $TRAVIS_OS_NAME = "osx" ]]; then
brew install lcms2;
elif [[ $TRAVIS_OS_NAME = "linux" ]]; then
echo "deb-src http://archive.ubuntu.com/ubuntu xenial main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list;
sudo apt-get update -q;
sudo apt-get build-dep -y libpng16-16;
sudo apt-get source -b -t xenial libpng16-16;
fi
script:
- ./configure --with-lcms2
- make
- make test
pngquant-2.12.6/CHANGELOG 0000664 0000000 0000000 00000013043 13602415555 0014660 0 ustar 00root root 0000000 0000000 version 2.12
------------
- improved speed on large images
- OpenMP fixes/workarounds
version 2.11
------------
- fixed wildcard support on Windows
- fixed argument parsing on Windows
version 2.10
------------
- supports building with Rust/Cargo
- supports dynamic linking with system-wide libimagequant
version 2.9
-----------
- added support for `-o -`
- windows/JNI build fixes
version 2.8
-----------
- libimagequant is a separate project
- --strip option to disable copying of PNG metadata
version 2.7
-----------
- improved dithering of saturated and semitransparent colors
- fixed order of log output when using openmp
- improved quality sanity check in --skip-if-larger option
- disabled palette post-processing on colors from --map option to preserve them exactly
version 2.6
-----------
- when source image has no color profile information, the output won't have either
version 2.5
-----------
- replaced color search algorithm with vantage point tree, which is much faster and more reliable
- deprecated IE6 workaround
- warn when compiled without color profile support
- Rust API for libimagequant
version 2.4
-----------
- fixed remapping of bright colors when dithering
version 2.3
-----------
- added ./configure script for better support of Intel C compiler and dependencies [thanks to pdknsk]
- tweaked quality metric to better estimate quality of images with large solid backgrounds [thanks to Rolf Timmermans]
- atomic file saves and fixed --skip-if-larger
- avoid applying quality setting to images that use palette already
- preserving standard PNG chunks (requires libpng 1.6)
- deprecated libpng 1.2 support
version 2.2
-----------
- preserving of unknown PNG chunks (enables optimized Android 9-patch images)
- improved color profile support: cHRM & gAMA as alternative to ICC profiles, OpenMP acceleration
- improved support for Intel C Compiler, speedup in 32-bit GCC, and some workarounds for Visual Studio's incomplete C support
version 2.1
-----------
- option to save files only if they're compressed better than the original
- option to generate posterized output (for use with 16-bit textures)
- support for ICC profiles via Little CMS library
version 2.0
-----------
- refactored codebase into pngquant and standalone libimagequant
- reduced memory usage by further 30% (and more for very large images)
- less precise remapping improving speed by 25% in higher speed settings
- --output option for writing converted file under the given path
- light dithering with --floyd=0.5
- fixed regression in dithering of alpha channel
version 1.8
-----------
- min/max quality option (number of colors is automatically adjusted for desired quality level)
- switched option parsing to getopt_long (syntax such as -s1 and --ext=ext is supported)
- significantly improved performance thanks to custom partial sorting
- optional Cocoa (Mac OS X) image reader for color profile support
- reduced memory usage by 20%
- remapping improved for very low number of colors
version 1.7
-----------
- new, accurate RGBA color similarity algorithm
- change of optional SSE3 code to SSE2 that is always enabled on x86-64
- optional OpenMP-based parallelisation of remapping
- changed long options to use double hyphen (-force to --force) [thanks to Jari Aalto]
version 1.6
-----------
- novel dithering algorithm that doesn't add noise unless necessary
- perceptual weighting of colors taking into account edges and noise
- much faster remapping
- improved portability, makefiles and man page
version 1.5
-----------
- palettes postprocessed with Voronoi iteration
- better RGBA color similarity algorithm and Floyd-Steinberg remapping
- SSE optimisations
version 1.4
-----------
- median cut is applied many times in a feedback loop
- speed/quality trade-off option
- faster remap of transparent areas
version 1.3
-----------
- significant changes to the algorithm: use of variance
to find largest dimensioin and to split most varying boxes
- use of premultiplied alpha for color blending
- conversion of output to gamma 2.2
version 1.2
-----------
- color computation done in floating point
- gamma correction applied
- dropped support for very old systems & compilers
version 1.1
-----------
- alpha-sensitive color reduction and dithering
- support -- and - arguments in command line
- number of colors optional (defaults to 256)
- increased maximum number of colors in histogram
version 1.0
-----------
- cleaned up Makefile.unx (better gcc optimizations, "clean" target)
- recompiled binaries with zlib 1.1.4
version 0.95
------------
- fixed Win32 filter bug (binary mode for stdin/stdout)
- fixed cosmetic "choosing colors" verbosity buglet
- fixed palette-size bug when number of colors in image < number requested
- fixed sample-depth bug (png_set_packing() not retroactively smart)
version 0.91
------------
- fixed some verbose/non-verbose oopers
- fixed Win32 (MSVC) portability issues (getpid(), random(), srandom())
- added Makefile.w32 for MSVC (tested with 5.0)
version 0.90
------------
- added support for multiple files on command line
- changed stdin support to write PNG stream to stdout (not "stdin-fs8.png")
version 0.75
------------
- added support for any type of input file [Glenn Randers-Pehrson]
- fixed palette-(re)scaling bug
- added -verbose and -quiet options (default now is -quiet)
- added palette-remapping to minimize size of tRNS chunk
- made Floyd-Steinberg dithering default
- changed output naming scheme to -fs8.png and -or8.png (FS or ordered dither)
version 0.70
------------
- first public release
pngquant-2.12.6/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000006233 13602415555 0016250 0 ustar 00root root 0000000 0000000 # Contributor Covenant Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at kornel@geekhood.net. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
pngquant-2.12.6/CONTRIBUTING.md 0000664 0000000 0000000 00000002721 13602415555 0015700 0 ustar 00root root 0000000 0000000
Thank you for contributing! pngquant and libimagequant are licensed under multiple
licensed, so to make things clear, I'm accepting contributions as licensed under
the BSD 2-clause license:
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.
pngquant-2.12.6/COPYRIGHT 0000664 0000000 0000000 00000105445 13602415555 0014751 0 ustar 00root root 0000000 0000000
pngquant and libimagequant are derived from code by Jef Poskanzer and Greg Roelofs
licensed under pngquant's original licenses (near the end of this file),
and contain extensive changes and additions by Kornel Lesiński
licensed under GPL v3 or later.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pngquant © 2009-2018 by Kornel Lesiński.
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The quantization and dithering code in pngquant is lifted from Jef Poskanzer's
'ppmquant', part of his wonderful PBMPLUS tool suite.
Greg Roelofs hacked it into a (in his words) "slightly cheesy" 'pamquant' back
in 1997 (see http://pobox.com/~newt/greg_rgba.html) and finally he ripped out
the cheesy file-I/O parts and replaced them with nice PNG code in December
2000. The PNG reading and writing code is a merged and slightly simplified
version of readpng, readpng2, and writepng from his book "PNG: The Definitive
Guide."
In 2014 Greg has relicensed the code under the simplified BSD license.
Note that both licenses are basically BSD-like; that is, use the code however
you like, as long as you acknowledge its origins.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pngquant.c:
© 1989, 1991 by Jef Poskanzer.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation. This software is provided "as is" without express or
implied warranty.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pngquant.c and rwpng.c/h:
© 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
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.
pngquant-2.12.6/Cargo.toml 0000664 0000000 0000000 00000003171 13602415555 0015377 0 ustar 00root root 0000000 0000000 [package]
version = "2.12.6"
authors = ["Kornel Lesiński "]
build = "rust/build.rs"
categories = ["multimedia::images"]
description = "Convert 24/32-bit images to 8-bit palette with alpha channel.\nBindings for libimagequant that powers pngquant lossy PNG compressor.\n\nDual-licensed like pngquant. See https://pngquant.org for details."
documentation= "https://github.com/kornelski/pngquant#readme"
homepage = "https://pngquant.org"
include = ["/rwpng*", "/pngquant.c", "/rust/*", "/COPYRIGHT", "/Cargo.toml", "/README.md"]
keywords = ["quantization", "palette", "image", "pngquant", "compression"]
license = "GPL-3.0+"
name = "pngquant"
readme = "README.md"
repository = "https://github.com/kornelski/pngquant.git"
edition = "2018"
[[bin]]
name = "pngquant"
path = "rust/bin.rs"
[build-dependencies]
cc = "1.0.38"
dunce = "1.0.0"
[dependencies]
getopts = "0.2.19"
libc = "0.2.60"
libpng-sys = "1.1.5"
wild = "2.0.2"
[dependencies.cocoa_image]
optional = true
version = "1.0.0"
[dependencies.imagequant-sys]
path = "lib"
version = "2.12.6"
[dependencies.lcms2-sys]
optional = true
version = "3.1.1"
[dependencies.openmp-sys]
optional = true
version = "0.1.6"
[features]
cocoa = ["cocoa_image"]
default = ["sse", "lcms2"]
lcms2 = ["lcms2-sys"]
lcms2-static = ["lcms2", "lcms2-sys/static"]
openmp = ["openmp-sys", "imagequant-sys/openmp"]
openmp-static = ["openmp", "openmp-sys/static", "imagequant-sys/openmp-static"]
png-static = ["libpng-sys/static"]
z-static = ["libpng-sys/static-libz"]
static = ["lcms2-static", "png-static", "openmp-static"]
sse = ["imagequant-sys/sse"]
alloc_system = []
[profile.release]
lto = true
pngquant-2.12.6/INSTALL 0000664 0000000 0000000 00000006265 13602415555 0014507 0 ustar 00root root 0000000 0000000 ## Compiling on Linux, *BSD and macOS using GNU/Make
(For instructions for Windows or Rust, see sections below.)
To get the code:
git clone --recursive https://github.com/kornelski/pngquant.git
You will need libpng installed with development headers.
On Linux install `libpng-dev` package. On macOS `brew install libpng`.
There's an optional `./configure` step (see sections below). Run:
make
It will create `pngquant` executable in the current directory. If you'd like
to install it system-wide:
sudo make install
By default it will be installed in `/usr/local/bin`. To install it in another
directory run `./configure --prefix=dir && make`.
pngquant uses GNU Makefile. To compile on FreeBSD you will need to use `gmake`.
Avoid Linux distros that ship with libpng 1.2. It is old and buggy.
libpng 1.6 or later is required.
### Custom static libpng
Extract libpng source code as a *sub*directory of pngquant source directory.
Build static libpng (`./configure --enable-static && make`), and then
`./configure && make` pngquant.
## Compiling via Rust/Cargo (all platforms, including Windows)
### Prerequisites
Install Rust 1.36 or later: https://www.rust-lang.org/install.html
On Windows also install msys-git and Visual C++ Build Tools
with Windows 8 SDK enabled, and reboot.
### Building
Get the code:
# Unix version
git clone --recursive https://github.com/kornelski/pngquant.git
# Windows version
git clone -b msvc --recursive https://github.com/kornelski/pngquant.git
And then build:
cd pngquant
cargo build --release
This will create executable in `target/release/pngquant`(`.exe`).
You can build with additional features:
cargo build --release --features=sse,lcms2
The features are:
* `sse` — enable use of SSE on x86 CPUs.
* `lcms2` — compile with support for color profiles via Little CMS.
* `lcms2-static` — same, but link statically.
* `cocoa` — compile with support for color profiles via macOS Cocoa.
* `openmp` — use OpenMP to accelerate conversion. Requires GCC 7 or later.
Clang is not supported. Warning: GCC 4 will produce buggy code.
* `openmp-static` — same, but link statically.
## Compilation with OpenMP
cargo build --release --features=openmp # or
cargo build --release --features=openmp-static
On macOS you may need to install gcc (`brew install gcc`) and run `export CC=gcc-9` first,
because clang doesn't support OpenMP (yet).
## Compilation with Cocoa image reader
macOS version can use Cocoa to read images. This adds support for color profiles
and other image formats as input. However, it also disables support for preserving PNG metadata.
cargo build --release --features=cocoa
## Compilation with Little CMS 2
Little CMS library is used by default.
It's linked dynamically if `pkg-config` is working (e.g. install `liblcms2-dev`).
Otherwise uses static build as a fallback.
Set `export LCMS2_STATIC=1` or build `--features=lcms2-static` to force static linking.
## Compilation of `libimagequant.a` only
If you want to use pngquant's conversion algorithm without loading/saving PNG
files, then you can run `make` or `cargo build --release` in the `lib/` directory.
The library doesn't need libpng nor zlib.
pngquant-2.12.6/Makefile 0000664 0000000 0000000 00000004231 13602415555 0015105 0 ustar 00root root 0000000 0000000 -include config.mk
LIQSRCDIR ?= lib
BIN ?= pngquant
BINPREFIX ?= $(DESTDIR)$(PREFIX)/bin
MANPREFIX ?= $(DESTDIR)$(PREFIX)/share/man
OBJS = pngquant.o pngquant_opts.o rwpng.o
STATICLIB = $(LIQSRCDIR)/libimagequant.a
DISTFILES = *.[chm] pngquant.1 Makefile configure README.md INSTALL CHANGELOG COPYRIGHT Cargo.toml
TARNAME = pngquant-$(VERSION)
TARFILE = $(TARNAME)-src.tar.gz
LIBDISTFILES = $(LIQSRCDIR)/*.[ch] $(LIQSRCDIR)/COPYRIGHT $(LIQSRCDIR)/README.md $(LIQSRCDIR)/configure $(LIQSRCDIR)/Makefile $(LIQSRCDIR)/Cargo.toml
TESTBIN = test/test
all: $(BIN)
$(LIQSRCDIR)/config.mk: config.mk
( cd '$(LIQSRCDIR)'; ./configure $(LIQCONFIGUREFLAGS) )
$(STATICLIB): $(LIQSRCDIR)/config.mk $(LIBDISTFILES)
$(MAKE) -C '$(LIQSRCDIR)' static
$(OBJS): $(wildcard *.h) config.mk
$(BIN): $(OBJS) $(STATICLIBDEPS)
$(CC) $(OBJS) $(CFLAGS) $(LDFLAGS) -o $@
$(TESTBIN): test/test.o $(STATICLIBDEPS)
$(CC) test/test.o $(CFLAGS) $(LDFLAGS) -o $@
test: $(BIN) $(TESTBIN)
LD_LIBRARY_PATH='$(LIQSRCDIR)' ./test/test.sh ./test $(BIN) $(TESTBIN)
dist: $(TARFILE)
$(TARFILE): $(DISTFILES)
test -n "$(VERSION)"
make -C $(LIQSRCDIR) cargo
rm -rf $(TARFILE) $(TARNAME)
mkdir -p $(TARNAME)/lib/rust $(TARNAME)/lib/msvc-dist $(TARNAME)/rust
cp $(DISTFILES) $(TARNAME)
cp rust/*.rs $(TARNAME)/rust/
cp $(LIBDISTFILES) $(TARNAME)/lib
cp $(LIQSRCDIR)/rust/*.rs $(TARNAME)/lib/rust/
cp $(LIQSRCDIR)/msvc-dist/*.[ch] $(TARNAME)/lib/msvc-dist/
tar -czf $(TARFILE) --numeric-owner --exclude='._*' $(TARNAME)
rm -rf $(TARNAME)
-shasum $(TARFILE)
install: $(BIN) $(BIN).1
-mkdir -p '$(BINPREFIX)'
-mkdir -p '$(MANPREFIX)/man1'
install -m 0755 -p '$(BIN)' '$(BINPREFIX)/$(BIN)'
install -m 0644 -p '$(BIN).1' '$(MANPREFIX)/man1/'
uninstall:
rm -f '$(BINPREFIX)/$(BIN)'
rm -f '$(MANPREFIX)/man1/$(BIN).1'
clean:
-test -n '$(LIQSRCDIR)' && $(MAKE) -C '$(LIQSRCDIR)' clean
rm -f '$(BIN)' $(OBJS) $(TARFILE)
distclean: clean
-test -n '$(LIQSRCDIR)' && $(MAKE) -C '$(LIQSRCDIR)' distclean
rm -f config.mk pngquant-*-src.tar.gz
config.mk: Makefile
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
./configure
endif
.PHONY: all clean dist distclean dll install uninstall test
.DELETE_ON_ERROR:
pngquant-2.12.6/README.md 0000664 0000000 0000000 00000007654 13602415555 0014740 0 ustar 00root root 0000000 0000000 # pngquant 2 [![build](https://travis-ci.org/kornelski/pngquant.svg?branch=master)](https://travis-ci.org/kornelski/pngquant)
[pngquant](https://pngquant.org) is a PNG compressor that significantly reduces file sizes by converting images to a more efficient 8-bit PNG format *with alpha channel* (often 60-80% smaller than 24/32-bit PNG files). Compressed images are fully standards-compliant and are supported by all web browsers and operating systems.
[This](https://github.com/kornelski/pngquant) is the official `pngquant` repository. The compression engine is also available [as an embeddable library](https://github.com/ImageOptim/libimagequant).
## Usage
- batch conversion of multiple files: `pngquant *.png`
- Unix-style stdin/stdout chaining: `… | pngquant - | …`
To further reduce file size, try [optipng](http://optipng.sourceforge.net), [ImageOptim](https://imageoptim.com), or [zopflipng](https://github.com/google/zopfli).
## Features
* High-quality palette generation
- advanced quantization algorithm with support for gamma correction and premultiplied alpha
- unique dithering algorithm that does not add unnecessary noise to the image
* Configurable quality level
- automatically finds required number of colors and can skip images which can't be converted with the desired quality
* Fast, modern code
- based on a portable [libimagequant library](https://github.com/ImageOptim/libimagequant)
- C99 with no workarounds for legacy systems or compilers ([apart from Visual Studio](https://github.com/kornelski/pngquant/tree/msvc))
- multicore support (via OpenMP) and Intel SSE optimizations
## Options
See `pngquant -h` for full list.
### `--quality min-max`
`min` and `max` are numbers in range 0 (worst) to 100 (perfect), similar to JPEG. pngquant will use the least amount of colors required to meet or exceed the `max` quality. If conversion results in quality below the `min` quality the image won't be saved (if outputting to stdin, 24-bit original will be output) and pngquant will exit with status code 99.
pngquant --quality=65-80 image.png
### `--ext new.png`
Set custom extension (suffix) for output filename. By default `-or8.png` or `-fs8.png` is used. If you use `--ext=.png --force` options pngquant will overwrite input files in place (use with caution).
### `-o out.png` or `--output out.png`
Writes converted file to the given path. When this option is used only single input file is allowed.
### `--skip-if-larger`
Don't write converted files if the conversion isn't worth it.
### `--speed N`
Speed/quality trade-off from 1 (slowest, highest quality, smallest files) to 11 (fastest, less consistent quality, light comperssion). The default is 4. It's recommended to keep the default, unless you need to generate images in real time (e.g. map tiles). Higher speeds are fine with 256 colors, but don't handle lower number of colors well.
### `--nofs`
Disables Floyd-Steinberg dithering.
### `--floyd=0.5`
Controls level of dithering (0 = none, 1 = full). Note that the `=` character is required.
### `--posterize bits`
Reduce precision of the palette by number of bits. Use when the image will be displayed on low-depth screens (e.g. 16-bit displays or compressed textures in ARGB444 format).
### `--strip`
Don't copy optional PNG chunks. Metadata is always removed on Mac (when using Cocoa reader).
See [man page](https://github.com/kornelski/pngquant/blob/master/pngquant.1) (`man pngquant`) for the full list of options.
## License
pngquant is dual-licensed:
* Under **GPL v3** or later with an additional [copyright notice](https://github.com/kornelski/pngquant/blob/master/COPYRIGHT) that must be kept for the older parts of the code.
* Or [a **commercial license**](https://supso.org/projects/pngquant) for use in non-GPL software (e.g. closed-source or App Store distribution). You can [get the license via Super Source](https://supso.org/projects/pngquant). Email kornel@pngquant.org if you have any questions.
pngquant-2.12.6/configure 0000775 0000000 0000000 00000035777 13602415555 0015377 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash
CONFIG="config.mk"
PREFIX="/usr/local"
DEBUG=
LIQSRCDIR=./lib
LIQCONFIGURE=(--quiet)
SSE=auto
OPENMP=
LIBPNG_DIR=.
LCMS2=auto
EXTRA_CFLAGS=
EXTRA_LDFLAGS=
# make gcc default compiler unless CC is already set
CC=${CC:-gcc}
SKIP_CC_CHECK=0
help() {
printf "%4s %s\n" "" "$1"
}
for i in "$@"; do
case $i in
--help|-h)
echo
help "--prefix= installation directory [$PREFIX]"
help "--extra-cflags= append to CFLAGS"
help "--extra-ldflags= append to LDFLAGS"
echo
help "--enable-debug"
help "--enable-sse/--disable-sse enable/disable SSE instructions"
echo
help "--with-libimagequant= external libimagequant (lib/ default)"
help "--with-openmp=static compile with multicore support"
help "--with-lcms2/--without-lcms2 compile with color profile support"
if [[ "$OSTYPE" =~ "darwin" ]]; then
help "--with-cocoa/--without-cocoa use Cocoa framework to read images"
fi
help "--with-libpng= search for libpng in directory"
echo
help "CC= use given compiler command"
help "CFLAGS= pass options to the compiler"
help "LDFLAGS= pass options to the linker"
echo
exit 0
;;
# Can be set before or after configure. Latter overrides former.
CC=*)
CC=${i#*=}
SKIP_CC_CHECK=1
LIQCONFIGURE+=("$i")
;;
CFLAGS=*)
CFLAGS=${i#*=}
LIQCONFIGURE+=("$i")
;;
LDFLAGS=*)
LDFLAGS=${i#*=}
LIQCONFIGURE+=("$i")
;;
--enable-debug)
DEBUG=1
LIQCONFIGURE+=("$i")
;;
--enable-sse)
SSE=1
LIQCONFIGURE+=("$i")
;;
--disable-sse)
SSE=0
LIQCONFIGURE+=("$i")
;;
--with-openmp)
OPENMP=1
LIQCONFIGURE+=("$i")
;;
--with-openmp=static)
OPENMP=static
LIQCONFIGURE+=("$i")
;;
--with-lcms2)
LCMS2=1
;;
--without-lcms2)
LCMS2=0
;;
--with-cocoa)
LCMS2=auto
;;
--without-cocoa)
LCMS2=auto
;;
--with-libpng=*)
LIBPNG_DIR=${i#*=}
;;
--with-libimagequant=*)
LIQSRCDIR=${i#*=}
;;
--with-libimagequant)
LIQSRCDIR=""
;;
--prefix=*)
PREFIX=${i#*=}
LIQCONFIGURE+=("$i")
;;
# can be used multiple times or in quotes to set multiple flags
--extra-cflags=*)
EXTRA_CFLAGS="$EXTRA_CFLAGS ${i#*=}"
LIQCONFIGURE+=("$i")
;;
--extra-ldflags=*)
EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
LIQCONFIGURE+=("$i")
;;
*)
echo "warning: unknown switch ${i%%=*} (see $0 --help for the list)"
;;
esac
done
# If someone runs sudo make install as very first command, and configure later,
# $CONFIG cannot be overwritten, and must be deleted before continuing.
if [[ -f "$CONFIG" && ! -w "$CONFIG" ]]; then
echo "Cannot overwrite file $CONFIG! Please delete it."
exit 1
fi
cflags() {
CFLAGS="$CFLAGS $1"
}
lflags() {
LDFLAGS="$LDFLAGS $1"
}
status() {
printf "%10s: %s\n" "$1" "$2"
}
# Append to CFLAGS if compiler supports flag, with optional prerequisite.
# Fails on errors and warnings.
conditional_cflags() {
if [ -z "$(echo | "$CC" -xc -S -o /dev/null $2 $1 - 2>&1)" ]; then
cflags "$1"
fi
}
# returns first matching file in directory
find_f() {
echo $(find "$1" -not -path '*/.git/*' -not -type d -name "$2" -print -quit 2> /dev/null)
}
# returns first matching file in directory (no symlinks)
find_h() {
echo $(find "$1" -not -path '*/.*/*' -type f -name "$2" -print -quit 2> /dev/null)
}
find_pkgconfig() {
local LIBNAME=$1
PKG_CONFIG=${PKG_CONFIG:-pkg-config}
if $PKG_CONFIG --exists "$LIBNAME" &> /dev/null; then
cflags "$($PKG_CONFIG --cflags "$LIBNAME")"
lflags "$($PKG_CONFIG --libs "$LIBNAME")"
LIBRARY_FOUND_VERSION=$($PKG_CONFIG --modversion "$LIBNAME")
status "$LIBNAME" "shared ($LIBRARY_FOUND_VERSION)"
return 0
fi
if ! type "$PKG_CONFIG" &> /dev/null; then
echo "warning: pkg-config is not installed, can't search for libraries. Please install pkg-config."
fi
return 1
}
find_static() {
local LIBNAME=$1
local HEADERPATTERN=$2
local STATICPATTERN=$3
local HPATH=$(find_h . "$HEADERPATTERN")
if [ -n "$HPATH" ]; then
local APATH=$(find_f . "$STATICPATTERN")
if [ -n "$APATH" ]; then
LIBRARY_FOUND_HEADER=$HPATH
cflags "-I${HPATH%/*}"
lflags "${APATH}"
status "$LIBNAME" "static ($APATH)"
return 0
fi
fi
return 1
}
find_dynamic() {
local LIBNAME=$1
local HEADERPATTERN=$2
local DYNAMICPATTERN=$3
local HEADERDIR=$4
local LIBDIR=$5
local HPATH=$(find_h "$HEADERDIR" "$HEADERPATTERN")
if [ -n "$HPATH" ]; then
local SOPATH=$(find_f "$LIBDIR" "$DYNAMICPATTERN")
if [ -n "$SOPATH" ]; then
LIBRARY_FOUND_HEADER=$HPATH
cflags "-I${HPATH%/*}"
lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
status "$LIBNAME" "shared ... $SOPATH"
return 0
fi
fi
return 1
}
find_library() {
local LIBNAME=$1
local DYNAMICLIBNAME=$2
local HEADERPATTERN=$3
local STATICPATTERN=$4
local DYNAMICPATTERN=$5
# other functions will overwrite it
LIBRARY_FOUND_HEADER=
LIBRARY_FOUND_VERSION=
LIBRARY_FOUND_BUILD=
if [ "imagequant" = "$LIBNAME" -a -n "$LIQSRCDIR" -a -f "$LIQSRCDIR"/"$HEADERPATTERN" ]; then
status "$LIBNAME" "build static"
cflags "-I$LIQSRCDIR"
lflags "$LIQSRCDIR/libimagequant.a"
LIBRARY_FOUND_HEADER="$LIQSRCDIR"/"$HEADERPATTERN"
LIBRARY_FOUND_BUILD="$LIQSRCDIR"
return 0;
fi
# try static in current directory first
if find_static "$LIBNAME" "$HEADERPATTERN" "$STATICPATTERN"; then
return 0;
fi
# try shared
if find_pkgconfig "$LIBNAME"; then
return 0
fi
for i in "${DIRS[@]}"; do
DIR=($i)
if find_dynamic "$LIBNAME" "$HEADERPATTERN" "$DYNAMICPATTERN" "${DIR[0]}" "${DIR[1]}"; then
return 0
fi
done
return 1
}
# returns full png.h version string
pngh_string() {
echo "$(grep -m1 "define PNG_LIBPNG_VER_STRING" "$1" | \
grep -Eo '"[^"]+"' | grep -Eo '[^"]+')"
}
# returns major minor version numbers from png.h
pngh_majmin() {
local MAJ=$(grep -m1 "define PNG_LIBPNG_VER_MAJOR" "$1" | grep -Eo "[0-9]+")
local MIN=$(grep -m1 "define PNG_LIBPNG_VER_MINOR" "$1" | grep -Eo "[0-9]+")
echo "${MAJ}${MIN}"
}
error() {
status "$1" "error ... $2"
echo
exit 1
}
echo
# /tmp, because mingw has problems opening /dev/null and gives false negative
if ! echo "int main(){}" | "$CC" -xc -std=c99 -o pngquant-gcccheck - > /dev/null; then
rm -f pngquant-gcccheck
if [ "$SKIP_CC_CHECK" -eq 1 ]; then
status "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
else
error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
fi
fi
rm -f pngquant-gcccheck
status "Compiler" "$CC"
# init flags
CFLAGS=${CFLAGS:--fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
cflags "-std=c99 -I."
# DEBUG
if [ -z "$DEBUG" ]; then
cflags "-O3 -DNDEBUG"
status "Debug" "no"
else
cflags "-O1 -g -DDEBUG"
status "Debug" "yes"
fi
# SSE
if [ "$SSE" = 'auto' ]; then
SSE=0
if type uname > /dev/null; then
if [[ "$(uname -m)" =~ "amd64" || "$(uname -m)" =~ "x86_64" ||
"$(grep -E -m1 "^flags" /proc/cpuinfo)" =~ "sse" ]]; then
SSE=1
fi
fi
fi
if [ "$SSE" -eq 1 ]; then
status "SSE" "yes"
cflags "-DUSE_SSE=1"
cflags "-msse"
# Silence a later ICC warning due to -msse working slightly different.
conditional_cflags "-wd10121"
# Must be set explicitly for GCC on x86_32. Other compilers imply it.
conditional_cflags "-mfpmath=sse" "-msse"
elif [ "$SSE" -eq 0 ]; then
status "SSE" "no"
cflags "-DUSE_SSE=0"
fi
# OpenMP
if [ -n "$OPENMP" ]; then
if [ "static" = "$OPENMP" ]; then
OPENMPFLAGS="-static-libgcc -Bstatic -fopenmp -Bdynamic"
else
OPENMPFLAGS="-fopenmp"
fi
if [[ "$("$CC" -xc -E $OPENMPFLAGS <(echo "#ifdef _OPENMP
#include
#endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
cflags "$OPENMPFLAGS"
lflags "$OPENMPFLAGS"
status "OpenMP" "yes"
else
error "OpenMP" "not supported by compiler (please install a compiler that supports OpenMP (e.g. gcc) and specify it with the CC= argument)"
fi
else
# silence warnings about omp pragmas
cflags "-Wno-unknown-pragmas"
conditional_cflags "-wd3180" # ICC
status "OpenMP" "no"
fi
# Cocoa
if [[ "$OSTYPE" =~ "darwin" ]]; then
cflags "-mmacosx-version-min=10.7"
lflags "-mmacosx-version-min=10.7"
fi
# pairs of possible *.h and lib*.so locations
DIRS=()
if command -v >/dev/null libpng-config; then
DIRS+=("$(libpng-config --prefix) $(libpng-config --libdir)")
fi
if [ -n $"LIQSRCDIR" ]; then
DIRS+=("$LIQSRCDIR" "$LIQSRCDIR") # local libimagequant
fi
DIRS+=(
"/usr/local/include /usr/local/lib"
"/usr/include /usr/lib64"
"/usr/include /usr/lib"
"/opt/local/include /opt/local/lib" # macports
)
if [[ "$OSTYPE" =~ "darwin" ]]; then
SOLIBSUFFIX=dylib
# Search Developer SDK paths, since Apple seems to have dropped the standard Unixy ones
XCODE_CMD="xcode-select"
XCODE_PATH=$($XCODE_CMD -p)
DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib")
DIRS+=("$XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/include $XCODE_PATH/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/usr/lib")
elif [[ "$OSTYPE" =~ "msys" ]]; then
SOLIBSUFFIX=dll
else
SOLIBSUFFIX=so
fi
# libimagequant
if [ "./lib" = "$LIQSRCDIR" -a -d ".git" -a ! -f "lib/Cargo.toml" ]; then
git submodule init && git submodule update;
fi
if find_library "imagequant" "imagequant" "libimagequant.h" "libimagequant.a" "libimagequant.$SOLIBSUFFIX*"; then
if [ -n "$LIBRARY_FOUND_VERSION" ]; then
VERSION=$LIBRARY_FOUND_VERSION
elif [ -n "$LIBRARY_FOUND_HEADER" ]; then
VERSION=$(grep LIQ_VERSION_STRING "$LIBRARY_FOUND_HEADER" | grep -Eo "2\.[0-9.]+")
else
VERSION=unknown
fi
if [ -n "$LIBRARY_FOUND_BUILD" ]; then
STATICLIBDEPS="$LIBRARY_FOUND_BUILD/libimagequant.h $LIBRARY_FOUND_BUILD/libimagequant.a"
LIQSRCDIR="$LIBRARY_FOUND_BUILD"
fi
else
if [ -n "$LIQSRCDIR" -a ! -f "$LIQSRCDIR"/libimagequant.h ]; then
echo "If you're using git, do clone with --recursive, or download from https://github.com/ImageOptim/libimagequant"
error "imagequant" "libimagequant.h not found in $LIQSRCDIR/"
else
error "imagequant" "not found. Get it from https://github.com/ImageOptim/libimagequant and build it in ./lib/"
fi
fi
# libpng
# try if given flags are enough
HAS_LIBPNG=0
if echo "#include \"png.h\"
int main(){
return !png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
}" | "$CC" -xc -std=c99 -o /dev/null $CFLAGS $LDFLAGS - &> /dev/null; then
status "libpng" "custom flags"
HAS_LIBPNG=1
fi
if [ "$HAS_LIBPNG" -eq 0 ]; then
# try static in the given directory
PNGH=$(find_h "$LIBPNG_DIR" "png.h")
if [ -n "$PNGH" ]; then
PNGH_STRING=$(pngh_string "$PNGH")
PNGH_MAJMIN=$(pngh_majmin "$PNGH")
if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
LIBPNGA=$(find_f "$LIBPNG_DIR" "libpng${PNGH_MAJMIN}.a")
if [ -z "$LIBPNGA" ]; then
LIBPNGA=$(find_f "$LIBPNG_DIR" "libpng.a")
fi
if [ -n "$LIBPNGA" ]; then
cflags "-I${PNGH%/*}"
lflags "${LIBPNGA}"
status "libpng" "static (${PNGH_STRING})"
HAS_LIBPNG=1
fi
fi
fi
fi
# try shared
if [ "$HAS_LIBPNG" -eq 0 ]; then
if find_pkgconfig libpng; then
HAS_LIBPNG=1
else
for i in "${DIRS[@]}"; do
DIR=($i)
PNGH=$(find_h "${DIR[0]}" "png.h")
if [ -n "$PNGH" ]; then
PNGH_STRING=$(pngh_string "$PNGH")
PNGH_MAJMIN=$(pngh_majmin "$PNGH")
if [[ -n "$PNGH_STRING" && -n "$PNGH_MAJMIN" ]]; then
LIBPNGSO=$(find_f "${DIR[1]}" "libpng${PNGH_MAJMIN}.$SOLIBSUFFIX*")
if [ -n "$LIBPNGSO" ]; then
cflags "-I${PNGH%/*}"
lflags "-L${LIBPNGSO%/*} -lpng${PNGH_MAJMIN}"
status "libpng" "shared (${PNGH_STRING})"
HAS_LIBPNG=1
break
fi
fi
fi
done
fi
fi
if [ "$HAS_LIBPNG" -eq 0 ]; then
if [[ "$OSTYPE" =~ "darwin" ]]; then
LIBPNG_CMD='`brew install libpng`'
else
LIBPNG_CMD='`apt-get install libpng16-dev` or `apt-get install libpng-dev` or `yum install libpng-devel`'
fi
error "libpng" "not found (try: $LIBPNG_CMD)"
fi
# zlib
if ! find_library "zlib" "z" "zlib.h" "libz.a" "libz.$SOLIBSUFFIX*"; then
error "zlib" "not found (please install zlib-devel package)"
fi
# lcms2
if [ "$LCMS2" != 0 ]; then
if find_library "lcms2" "lcms2" "lcms2.h" "liblcms2.a" "liblcms2.$SOLIBSUFFIX*"; then
cflags "-DUSE_LCMS=1"
else
if [ "$LCMS2" = 'auto' ]; then
status "lcms2" "no"
else
error "lcms2" "not found (please install libcms2-devel package)"
fi
fi
else
status "lcms2" "no"
fi
echo
# As of GCC 4.5, 387 fp math is significantly slower in C99 mode without this.
# Note: CPUs without SSE2 use 387 for doubles, even when SSE fp math is set.
conditional_cflags "-fexcess-precision=fast"
# Intel C++ Compiler
# ICC does usually only produce fast(er) code when it can optimize to the full
# capabilites of the (Intel) CPU. This is equivalent to -march=native for GCC.
conditional_cflags "-xHOST"
# Disable unsafe fp optimizations and enforce fp precision as set in the source.
conditional_cflags "-fp-model source"
# Silence a gold linker warning about string misalignment.
conditional_cflags "-falign-stack=maintain-16-byte"
lflags "-lm" # Ubuntu requires this library last, issue #38
if [ -n "$EXTRA_CFLAGS" ]; then
cflags "$EXTRA_CFLAGS"
fi
if [ -n "$EXTRA_LDFLAGS" ]; then
lflags "$EXTRA_LDFLAGS"
fi
# Overwrite previous configuration.
echo "
# auto-generated by configure
PREFIX = $PREFIX
VERSION = $VERSION
CC = $CC
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
SOLIBSUFFIX = $SOLIBSUFFIX
STATICLIBDEPS = $STATICLIBDEPS
LIQSRCDIR = $LIQSRCDIR
LIQCONFIGUREFLAGS = $(printf "'%s' " "${LIQCONFIGURE[@]}")
" > "$CONFIG"
pngquant-2.12.6/lib/ 0000775 0000000 0000000 00000000000 13602415555 0014213 5 ustar 00root root 0000000 0000000 pngquant-2.12.6/pngquant.1 0000664 0000000 0000000 00000007132 13602415555 0015367 0 ustar 00root root 0000000 0000000 .Dd 2013-02-25
.Dt pngquant 1
.Sh NAME
.Nm pngquant
.Nd PNG converter and lossy image compressor
.Sh SYNOPSIS
.Nm
.Aq options
.Op ncolors
.Pa file
.Op Ar
.Nm
.Aq options
.Op ncolors
.Fl
.Cm < Ns Pa file
.Cm > Ns Pa file
.Sh DESCRIPTION
.Nm
converts 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette PNGs, optionally using Floyd-Steinberg dithering.
The output filename is the same as the input name except that it ends in
.Ql -fs8.png
or
.Ql -or8.png
(unless the input is stdin, in which case the quantized image will go to stdout).
The default behavior if the output file exists is to skip the conversion; use
.Fl Fl force
to overwrite.
.Sh OPTIONS
.Bl -tag -width -indent
.It Fl o Ar out.png , Fl Fl output Ar out.png
Writes converted file to the given path. When this option is used only single input file is allowed.
.It Fl Fl ext Ar new.png
File extension (suffix) to use for output files instead of the default
.Ql -fs8.png
or
.Ql -or8.png .
.It Fl f , Fl Fl force
Overwrite existing output files.
.Do
.Fl Fl ext
.Ar .png
.Fl Fl force
.Dc
can be used to convert files in place (which is unsafe).
.It Fl Fl nofs , Fl Fl ordered
Disable Floyd-Steinberg dithering.
.It Fl Fl floyd Op Ar =N
Set dithering level using fractional number between
.Cm 0
(none) and
.Cm 1
(full, the default).
.It Fl s Ar N , Fl Fl speed Ar N
.Cm 1
(brute-force) to
.Cm 11
(fastest). The default is
.Cm 3 .
Speed
.Cm 10
has 5% lower quality, but is about 8 times faster than the default. Speed 11 disables dithering and lowers compression level.
.It Fl Q Ar min-max , Fl Fl quality Ar min-max
.Va min
and
.Va max
are numbers in range
.Cm 0
(worst) to
.Cm 100
(perfect), similar to JPEG.
.Nm
will use the least amount of colors required to meet or exceed the
.Va max
quality. If conversion results in quality below the
.Va min
quality the image won't be saved (or if outputting to stdin, 24-bit original will be output) and pngquant will exit with status code
.Er 99 .
.It Fl Fl skip-if-larger
If conversion results in a file larger than the original, the image won't be saved and pngquant will exit with status code
.Er 98 .
Additionally, file size gain must be greater than the amount of quality lost. If quality drops by 50%, it will expect 50% file size reduction to consider it worthwhile.
.It Fl Fl posterize Ar bits
Truncate number of least significant bits of color (per channel). Use this when image will be output on low-depth displays (e.g. 16-bit RGB).
.Nm
will make almost-opaque pixels fully opaque and will reduce amount of semi-transparent colors. When this option is enabled the default filename suffix is
.Ql -ie-fs8.png
/
.Ql -ie-or8.png .
.It Fl Fl strip
Remove optional chunks (metadata) from PNG files.
.It Fl Fl transbug
Workaround for readers that expect fully transparent color to be the last entry in the palette.
.It Fl v , Fl Fl verbose
Enable verbose messages showing progress and information about input/output. Opposite is
.Fl Fl quiet .
Errors are output to
.Pa stderr
regardless of this option.
.It Fl V , Fl Fl version
Display version on
.Pa stdout
and exit.
.It Fl h , Fl Fl help
Display help and exit.
.El
.Sh EXAMPLE
Creating a new image with the number of colors reduced to 64:
.Bd -ragged -offset indent
.Nm
.Cm 64 image.png
.Ed
.Pp
The resulting image will have 64 colors and will be saved as
.Pa image-fs8.png .
.Pp
Overwriting image in-place if it can be reduced without too much quality loss:
.Bd -ragged -offset indent
.Nm
.Cm -f --ext .png --quality 70-95 image.png
.Ed
.Sh AUTHOR
.Nm
is developed by Kornel Lesinski
.Aq Mt kornel@pngquant.org
based on code by Greg Roelofs
.Aq Mt newt@pobox.com .
.Pp
.Lk https://pngquant.org "pngquant homepage" .
pngquant-2.12.6/pngquant.c 0000664 0000000 0000000 00000064112 13602415555 0015452 0 ustar 00root root 0000000 0000000 /* pngquant.c - quantize the colors in an alphamap down to a specified number
**
** © 2009-2019 by Kornel Lesiński.
** © 1989, 1991 by Jef Poskanzer.
** © 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
**
** See COPYRIGHT file for license.
*/
char *PNGQUANT_USAGE = "\
usage: pngquant [options] [ncolors] -- pngfile [pngfile ...]\n\
pngquant [options] [ncolors] - >stdout
#include
#include
#include
#include
#include
#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__)
# include /* O_BINARY */
# include /* setmode() */
#else
# include
#endif
#ifdef _OPENMP
#include
#else
#define omp_get_max_threads() 1
#define omp_get_thread_num() 0
#endif
#include "rwpng.h" /* typedefs, common macros, public prototypes */
#include "libimagequant.h" /* if it fails here, run: git submodule update; ./configure; or add -Ilib to compiler flags */
#include "pngquant_opts.h"
char *PNGQUANT_VERSION = LIQ_VERSION_STRING " (July 2019)";
static pngquant_error prepare_output_image(liq_result *result, liq_image *input_image, rwpng_color_transform tag, png8_image *output_image);
static void set_palette(liq_result *result, png8_image *output_image);
static pngquant_error read_image(liq_attr *options, const char *filename, int using_stdin, png24_image *input_image_p, liq_image **liq_image_p, bool keep_input_pixels, bool strip, bool verbose);
static pngquant_error write_image(png8_image *output_image, png24_image *output_image24, const char *outname, struct pngquant_options *options, liq_attr *liq);
static char *add_filename_extension(const char *filename, const char *newext);
static bool file_exists(const char *outname);
static void verbose_printf(liq_attr *liq, struct pngquant_options *context, const char *fmt, ...)
{
if (context->log_callback) {
va_list va;
va_start(va, fmt);
int required_space = vsnprintf(NULL, 0, fmt, va)+1; // +\0
va_end(va);
#if defined(_MSC_VER)
char *buf = malloc(required_space);
#else
char buf[required_space];
#endif
va_start(va, fmt);
vsnprintf(buf, required_space, fmt, va);
va_end(va);
context->log_callback(liq, buf, context->log_callback_user_info);
#if defined(_MSC_VER)
free(buf);
#endif
}
}
static void log_callback(const liq_attr *attr, const char *msg, void* user_info)
{
fprintf(stderr, "%s\n", msg);
}
#ifdef _OPENMP
#define LOG_BUFFER_SIZE 1300
struct buffered_log {
int buf_used;
char buf[LOG_BUFFER_SIZE];
};
static void log_callback_buferred_flush(const liq_attr *attr, void *context)
{
struct buffered_log *log = context;
if (log->buf_used) {
fwrite(log->buf, 1, log->buf_used, stderr);
fflush(stderr);
log->buf_used = 0;
}
}
static void log_callback_buferred(const liq_attr *attr, const char *msg, void* context)
{
struct buffered_log *log = context;
int len = strlen(msg);
if (len > LOG_BUFFER_SIZE-2) len = LOG_BUFFER_SIZE-2;
if (len > LOG_BUFFER_SIZE - log->buf_used - 2) log_callback_buferred_flush(attr, log);
memcpy(&log->buf[log->buf_used], msg, len);
log->buf_used += len+1;
log->buf[log->buf_used-1] = '\n';
log->buf[log->buf_used] = '\0';
}
#endif
void pngquant_internal_print_config(FILE *fd) {
fputs(""
#ifndef NDEBUG
" WARNING: this is a DEBUG (slow) version.\n" /* NDEBUG disables assert() */
#endif
#if !USE_SSE && (defined(__SSE__) || defined(__amd64__) || defined(__X86_64__) || defined(__i386__))
" SSE acceleration disabled.\n"
#endif
#if _OPENMP
" Compiled with OpenMP (multicore support).\n"
#endif
, fd);
fflush(fd);
}
FILE *pngquant_c_stderr() {
return stderr;
}
FILE *pngquant_c_stdout() {
return stdout;
}
static void print_full_version(FILE *fd)
{
fprintf(fd, "pngquant, %s, by Kornel Lesinski, Greg Roelofs.\n", PNGQUANT_VERSION);
pngquant_internal_print_config(fd);
rwpng_version_info(fd);
fputs("\n", fd);
}
static void print_usage(FILE *fd)
{
fputs(PNGQUANT_USAGE, fd);
}
/**
* N = automatic quality, uses limit unless force is set (N-N or 0-N)
* -N = no better than N (same as 0-N)
* N-M = no worse than N, no better than M
* N- = no worse than N, perfect if possible (same as N-100)
*
* where N,M are numbers between 0 (lousy) and 100 (perfect)
*/
static bool parse_quality(const char *quality, liq_attr *options, bool *min_quality_limit)
{
long limit, target;
const char *str = quality; char *end;
long t1 = strtol(str, &end, 10);
if (str == end) return false;
str = end;
if ('\0' == end[0] && t1 < 0) { // quality="-%d"
target = -t1;
limit = 0;
} else if ('\0' == end[0]) { // quality="%d"
target = t1;
limit = t1*9/10;
} else if ('-' == end[0] && '\0' == end[1]) { // quality="%d-"
target = 100;
limit = t1;
} else { // quality="%d-%d"
long t2 = strtol(str, &end, 10);
if (str == end || t2 > 0) return false;
target = -t2;
limit = t1;
}
*min_quality_limit = (limit > 0);
return LIQ_OK == liq_set_quality(options, limit, target);
}
pngquant_error pngquant_main_internal(struct pngquant_options *options, liq_attr *liq);
static pngquant_error pngquant_file_internal(const char *filename, const char *outname, struct pngquant_options *options, liq_attr *liq);
#ifndef PNGQUANT_NO_MAIN
int main(int argc, char *argv[])
{
struct pngquant_options options = {
.floyd = 1.f, // floyd-steinberg dithering
.strip = false,
};
pngquant_error retval = pngquant_parse_options(argc, argv, &options);
if (retval != SUCCESS) {
return retval;
}
if (options.print_version) {
puts(PNGQUANT_VERSION);
return SUCCESS;
}
if (options.missing_arguments) {
print_full_version(stderr);
print_usage(stderr);
return MISSING_ARGUMENT;
}
if (options.print_help) {
print_full_version(stdout);
print_usage(stdout);
return SUCCESS;
}
liq_attr *liq = liq_attr_create();
if (!liq) {
fputs("SSE-capable CPU is required for this build.\n", stderr);
return WRONG_ARCHITECTURE;
}
if (options.quality && !parse_quality(options.quality, liq, &options.min_quality_limit)) {
fputs("Quality should be in format min-max where min and max are numbers in range 0-100.\n", stderr);
return INVALID_ARGUMENT;
}
if (options.iebug) {
// opacities above 238 will be rounded up to 255, because IE6 truncates <255 to 0.
liq_set_min_opacity(liq, 238);
fputs(" warning: the workaround for IE6 is deprecated\n", stderr);
}
if (options.verbose) {
liq_set_log_callback(liq, log_callback, NULL);
options.log_callback = log_callback;
}
if (options.last_index_transparent) {
liq_set_last_index_transparent(liq, true);
}
if (options.speed >= 10) {
options.fast_compression = true;
if (options.speed == 11) {
options.floyd = 0;
options.speed = 10;
}
}
if (options.speed && LIQ_OK != liq_set_speed(liq, options.speed)) {
fputs("Speed should be between 1 (slow) and 11 (fast).\n", stderr);
return INVALID_ARGUMENT;
}
if (options.colors && LIQ_OK != liq_set_max_colors(liq, options.colors)) {
fputs("Number of colors must be between 2 and 256.\n", stderr);
return INVALID_ARGUMENT;
}
if (options.posterize && LIQ_OK != liq_set_min_posterization(liq, options.posterize)) {
fputs("Posterization should be number of bits in range 0-4.\n", stderr);
return INVALID_ARGUMENT;
}
if (options.extension && options.output_file_path) {
fputs("--ext and --output options can't be used at the same time\n", stderr);
return INVALID_ARGUMENT;
}
// new filename extension depends on options used. Typically basename-fs8.png
if (options.extension == NULL) {
options.extension = options.floyd > 0 ? "-fs8.png" : "-or8.png";
}
if (options.output_file_path && options.num_files != 1) {
fputs(" error: Only one input file is allowed when --output is used. This error also happens when filenames with spaces are not in quotes.\n", stderr);
return INVALID_ARGUMENT;
}
if (options.using_stdout && !options.using_stdin && options.num_files != 1) {
fputs(" error: Only one input file is allowed when using the special output path \"-\" to write to stdout. This error also happens when filenames with spaces are not in quotes.\n", stderr);
return INVALID_ARGUMENT;
}
if (!options.num_files && !options.using_stdin) {
fputs("No input files specified.\n", stderr);
if (options.verbose) {
print_full_version(stderr);
}
print_usage(stderr);
return MISSING_ARGUMENT;
}
retval = pngquant_main_internal(&options, liq);
liq_attr_destroy(liq);
return retval;
}
#endif
// Don't use this. This is not a public API.
pngquant_error pngquant_main_internal(struct pngquant_options *options, liq_attr *liq)
{
if (options->map_file) {
png24_image tmp = {.width=0};
if (SUCCESS != read_image(liq, options->map_file, false, &tmp, &options->fixed_palette_image, true, true, false)) {
fprintf(stderr, " error: unable to load %s", options->map_file);
return INVALID_ARGUMENT;
}
liq_result *tmp_quantize = liq_quantize_image(liq, options->fixed_palette_image);
const liq_palette *pal = liq_get_palette(tmp_quantize);
if (!pal) {
fprintf(stderr, " error: unable to read colors from %s", options->map_file);
return INVALID_ARGUMENT;
}
for(unsigned int i=0; i < pal->count; i++) {
liq_image_add_fixed_color(options->fixed_palette_image, pal->entries[i]);
}
liq_result_destroy(tmp_quantize);
}
#ifdef _OPENMP
// if there's a lot of files, coarse parallelism can be used
if (options->num_files > 2*omp_get_max_threads()) {
omp_set_nested(0);
omp_set_dynamic(1);
} else {
omp_set_nested(1);
}
#endif
unsigned int error_count=0, skipped_count=0, file_count=0;
pngquant_error latest_error=SUCCESS;
#pragma omp parallel for \
schedule(static, 1) reduction(+:skipped_count) reduction(+:error_count) reduction(+:file_count) shared(latest_error)
for(int i=0; i < options->num_files; i++) {
const char *filename = options->using_stdin ? "stdin" : options->files[i];
struct pngquant_options opts = *options;
liq_attr *local_liq = liq_attr_copy(liq);
#ifdef _OPENMP
struct buffered_log buf = {0};
if (opts.log_callback && omp_get_num_threads() > 1 && opts.num_files > 1) {
liq_set_log_callback(local_liq, log_callback_buferred, &buf);
liq_set_log_flush_callback(local_liq, log_callback_buferred_flush, &buf);
opts.log_callback = log_callback_buferred;
opts.log_callback_user_info = &buf;
}
#endif
pngquant_error retval = SUCCESS;
const char *outname = opts.output_file_path;
char *outname_free = NULL;
if (!opts.using_stdout) {
if (!outname) {
outname = outname_free = add_filename_extension(filename, opts.extension);
}
if (!opts.force && file_exists(outname)) {
fprintf(stderr, " error: '%s' exists; not overwriting\n", outname);
retval = NOT_OVERWRITING_ERROR;
}
}
if (SUCCESS == retval) {
retval = pngquant_file_internal(filename, outname, &opts, local_liq);
}
free(outname_free);
liq_attr_destroy(local_liq);
if (retval) {
#pragma omp critical
{
latest_error = retval;
}
if (retval == TOO_LOW_QUALITY || retval == TOO_LARGE_FILE) {
skipped_count++;
} else {
error_count++;
}
}
++file_count;
}
if (error_count) {
verbose_printf(liq, options, "There were errors quantizing %d file%s out of a total of %d file%s.",
error_count, (error_count == 1)? "" : "s", file_count, (file_count == 1)? "" : "s");
}
if (skipped_count) {
verbose_printf(liq, options, "Skipped %d file%s out of a total of %d file%s.",
skipped_count, (skipped_count == 1)? "" : "s", file_count, (file_count == 1)? "" : "s");
}
if (!skipped_count && !error_count) {
verbose_printf(liq, options, "Quantized %d image%s.",
file_count, (file_count == 1)? "" : "s");
}
if (options->fixed_palette_image) liq_image_destroy(options->fixed_palette_image);
return latest_error;
}
/// Don't hack this. Instead use https://github.com/ImageOptim/libimagequant/blob/f54d2f1a3e1cf728e17326f4db0d45811c63f063/example.c
static pngquant_error pngquant_file_internal(const char *filename, const char *outname, struct pngquant_options *options, liq_attr *liq)
{
pngquant_error retval = SUCCESS;
verbose_printf(liq, options, "%s:", filename);
liq_image *input_image = NULL;
png24_image input_image_rwpng = {.width=0};
bool keep_input_pixels = options->skip_if_larger || (options->using_stdout && options->min_quality_limit); // original may need to be output to stdout
if (SUCCESS == retval) {
retval = read_image(liq, filename, options->using_stdin, &input_image_rwpng, &input_image, keep_input_pixels, options->strip, options->verbose);
}
int quality_percent = 90; // quality on 0-100 scale, updated upon successful remap
png8_image output_image = {.width=0};
if (SUCCESS == retval) {
verbose_printf(liq, options, " read %luKB file", (input_image_rwpng.file_size+1023UL)/1024UL);
if (RWPNG_ICCP == input_image_rwpng.input_color) {
verbose_printf(liq, options, " used embedded ICC profile to transform image to sRGB colorspace");
} else if (RWPNG_GAMA_CHRM == input_image_rwpng.input_color) {
verbose_printf(liq, options, " used gAMA and cHRM chunks to transform image to sRGB colorspace");
} else if (RWPNG_ICCP_WARN_GRAY == input_image_rwpng.input_color) {
verbose_printf(liq, options, " warning: ignored ICC profile in GRAY colorspace");
} else if (RWPNG_COCOA == input_image_rwpng.input_color) {
// No comment
} else if (RWPNG_SRGB == input_image_rwpng.input_color) {
verbose_printf(liq, options, " passing sRGB tag from the input");
} else if (input_image_rwpng.gamma != 0.45455) {
verbose_printf(liq, options, " converted image from gamma %2.1f to gamma 2.2",
1.0/input_image_rwpng.gamma);
}
// when using image as source of a fixed palette the palette is extracted using regular quantization
liq_result *remap;
liq_error remap_error = liq_image_quantize(options->fixed_palette_image ? options->fixed_palette_image : input_image, liq, &remap);
if (LIQ_OK == remap_error) {
// fixed gamma ~2.2 for the web. PNG can't store exact 1/2.2
// NB: can't change gamma here, because output_color is allowed to be an sRGB tag
liq_set_output_gamma(remap, 0.45455);
liq_set_dithering_level(remap, options->floyd);
retval = prepare_output_image(remap, input_image, input_image_rwpng.output_color, &output_image);
if (SUCCESS == retval) {
if (LIQ_OK != liq_write_remapped_image_rows(remap, input_image, output_image.row_pointers)) {
retval = OUT_OF_MEMORY_ERROR;
}
set_palette(remap, &output_image);
double palette_error = liq_get_quantization_error(remap);
if (palette_error >= 0) {
quality_percent = liq_get_quantization_quality(remap);
verbose_printf(liq, options, " mapped image to new colors...MSE=%.3f (Q=%d)", palette_error, quality_percent);
}
}
liq_result_destroy(remap);
} else if (LIQ_QUALITY_TOO_LOW == remap_error) {
retval = TOO_LOW_QUALITY;
} else {
retval = INVALID_ARGUMENT; // dunno
}
}
if (SUCCESS == retval) {
if (options->skip_if_larger) {
// this is very rough approximation, but generally avoid losing more quality than is gained in file size.
// Quality is raised to 1.5, because even greater savings are needed to justify big quality loss.
// but >50% savings are considered always worthwile in order to allow low quality conversions to work at all
const double quality = quality_percent/100.0;
const double expected_reduced_size = pow(quality, 1.5);
output_image.maximum_file_size = (input_image_rwpng.file_size-1) * (expected_reduced_size < 0.5 ? 0.5 : expected_reduced_size);
}
output_image.fast_compression = options->fast_compression;
output_image.chunks = input_image_rwpng.chunks; input_image_rwpng.chunks = NULL;
retval = write_image(&output_image, NULL, outname, options, liq);
if (TOO_LARGE_FILE == retval) {
verbose_printf(liq, options, " file exceeded expected size of %luKB", (unsigned long)output_image.maximum_file_size/1024UL);
}
if (SUCCESS == retval && output_image.metadata_size > 0) {
verbose_printf(liq, options, " copied %dKB of additional PNG metadata", (int)(output_image.metadata_size+999)/1000);
}
}
if (options->using_stdout && keep_input_pixels && (TOO_LARGE_FILE == retval || TOO_LOW_QUALITY == retval)) {
// when outputting to stdout it'd be nasty to create 0-byte file
// so if quality is too low, output 24-bit original
pngquant_error write_retval = write_image(NULL, &input_image_rwpng, outname, options, liq);
if (write_retval) {
retval = write_retval;
}
}
if (input_image) liq_image_destroy(input_image);
rwpng_free_image24(&input_image_rwpng);
rwpng_free_image8(&output_image);
return retval;
}
static void set_palette(liq_result *result, png8_image *output_image)
{
const liq_palette *palette = liq_get_palette(result);
output_image->num_palette = palette->count;
for(unsigned int i=0; i < palette->count; i++) {
const liq_color px = palette->entries[i];
output_image->palette[i] = (rwpng_rgba){.r=px.r, .g=px.g, .b=px.b, .a=px.a};
}
}
static bool file_exists(const char *outname)
{
FILE *outfile = fopen(outname, "rb");
if ((outfile ) != NULL) {
fclose(outfile);
return true;
}
return false;
}
/* build the output filename from the input name by inserting "-fs8" or
* "-or8" before the ".png" extension (or by appending that plus ".png" if
* there isn't any extension), then make sure it doesn't exist already */
static char *add_filename_extension(const char *filename, const char *newext)
{
size_t x = strlen(filename);
char* outname = malloc(x+4+strlen(newext)+1);
if (!outname) return NULL;
strcpy(outname, filename);
if (x > 4 && (strncmp(outname+x-4, ".png", 4) == 0 || strncmp(outname+x-4, ".PNG", 4) == 0)) {
strcpy(outname+x-4, newext);
} else {
strcpy(outname+x, newext);
}
return outname;
}
static char *temp_filename(const char *basename) {
size_t x = strlen(basename);
char *outname = malloc(x+1+4);
if (!outname) return NULL;
strcpy(outname, basename);
strcpy(outname+x, ".tmp");
return outname;
}
static void set_binary_mode(FILE *fp)
{
#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__)
setmode(fp == stdout ? 1 : 0, O_BINARY);
#endif
}
static const char *filename_part(const char *path)
{
const char *outfilename = strrchr(path, '/');
if (outfilename) {
return outfilename+1;
} else {
return path;
}
}
static bool replace_file(const char *from, const char *to, const bool force) {
#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__)
if (force) {
// On Windows rename doesn't replace
unlink(to);
}
#endif
return (0 == rename(from, to));
}
static pngquant_error write_image(png8_image *output_image, png24_image *output_image24, const char *outname, struct pngquant_options *options, liq_attr *liq)
{
FILE *outfile;
char *tempname = NULL;
if (options->using_stdout) {
set_binary_mode(stdout);
outfile = stdout;
if (output_image) {
verbose_printf(liq, options, " writing %d-color image to stdout", output_image->num_palette);
} else {
verbose_printf(liq, options, " writing truecolor image to stdout");
}
} else {
tempname = temp_filename(outname);
if (!tempname) return OUT_OF_MEMORY_ERROR;
if ((outfile = fopen(tempname, "wb")) == NULL) {
fprintf(stderr, " error: cannot open '%s' for writing\n", tempname);
free(tempname);
return CANT_WRITE_ERROR;
}
if (output_image) {
verbose_printf(liq, options, " writing %d-color image as %s", output_image->num_palette, filename_part(outname));
} else {
verbose_printf(liq, options, " writing truecolor image as %s", filename_part(outname));
}
}
pngquant_error retval;
#pragma omp critical (libpng)
{
if (output_image) {
retval = rwpng_write_image8(outfile, output_image);
} else {
retval = rwpng_write_image24(outfile, output_image24);
}
}
if (!options->using_stdout) {
fclose(outfile);
if (SUCCESS == retval) {
// Image has been written to a temporary file and then moved over destination.
// This makes replacement atomic and avoids damaging destination file on write error.
if (!replace_file(tempname, outname, options->force)) {
retval = CANT_WRITE_ERROR;
}
}
if (retval) {
unlink(tempname);
}
}
free(tempname);
if (retval && retval != TOO_LARGE_FILE) {
fprintf(stderr, " error: failed writing image to %s (%d)\n", options->using_stdout ? "stdout" : outname, retval);
}
return retval;
}
static pngquant_error read_image(liq_attr *options, const char *filename, int using_stdin, png24_image *input_image_p, liq_image **liq_image_p, bool keep_input_pixels, bool strip, bool verbose)
{
FILE *infile;
if (using_stdin) {
set_binary_mode(stdin);
infile = stdin;
} else if ((infile = fopen(filename, "rb")) == NULL) {
fprintf(stderr, " error: cannot open %s for reading\n", filename);
return READ_ERROR;
}
pngquant_error retval;
#pragma omp critical (libpng)
{
retval = rwpng_read_image24(infile, input_image_p, strip, verbose);
}
if (!using_stdin) {
fclose(infile);
}
if (retval) {
fprintf(stderr, " error: cannot decode image %s\n", using_stdin ? "from stdin" : filename_part(filename));
return retval;
}
*liq_image_p = liq_image_create_rgba_rows(options, (void**)input_image_p->row_pointers, input_image_p->width, input_image_p->height, input_image_p->gamma);
if (!*liq_image_p) {
return OUT_OF_MEMORY_ERROR;
}
if (!keep_input_pixels) {
if (LIQ_OK != liq_image_set_memory_ownership(*liq_image_p, LIQ_OWN_ROWS | LIQ_OWN_PIXELS)) {
return OUT_OF_MEMORY_ERROR;
}
input_image_p->row_pointers = NULL;
input_image_p->rgba_data = NULL;
}
return SUCCESS;
}
static pngquant_error prepare_output_image(liq_result *result, liq_image *input_image, rwpng_color_transform output_color, png8_image *output_image)
{
output_image->width = liq_image_get_width(input_image);
output_image->height = liq_image_get_height(input_image);
output_image->gamma = liq_get_output_gamma(result);
output_image->output_color = output_color;
/*
** Step 3.7 [GRR]: allocate memory for the entire indexed image
*/
output_image->indexed_data = malloc((size_t)output_image->height * (size_t)output_image->width);
output_image->row_pointers = malloc((size_t)output_image->height * sizeof(output_image->row_pointers[0]));
if (!output_image->indexed_data || !output_image->row_pointers) {
return OUT_OF_MEMORY_ERROR;
}
for(size_t row = 0; row < output_image->height; row++) {
output_image->row_pointers[row] = output_image->indexed_data + row * output_image->width;
}
const liq_palette *palette = liq_get_palette(result);
// tRNS, etc.
output_image->num_palette = palette->count;
return SUCCESS;
}
pngquant-2.12.6/pngquant.spec 0000664 0000000 0000000 00000003463 13602415555 0016164 0 ustar 00root root 0000000 0000000 Name: pngquant
Version: 2.12.6
Release: 1%{?dist}
Summary: PNG quantization tool for reducing image file size
# New code is under GPL, forked from old BSD-like
License: GPLv3+ and BSD
URL: https://pngquant.org
Source0: https://github.com/kornelski/pngquant/archive/%{version}.tar.gz
BuildRequires: libpng-devel%{?_isa} >= 1.4.20
BuildRequires: zlib-devel%{?_isa} >= 1.2.3-1
BuildRequires: gcc%{?_isa} >= 4.2-1
Requires: libpng%{?_isa} >= 1.4.20
Requires: zlib%{?isa} >= 1.2.3-1
%description
pngquant converts 24/32-bit RGBA PNG images to high-quality 8-bit palette
with alpha channel preserved. Quantization significantly reduces file sizes.
Such images are fully standards-compliant and supported by all web browsers.
%prep
%setup -q -n pngquant-%{version}
%build
./configure --prefix=%{_prefix}
make %{?_smp_mflags}
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}/%{_bindir}
make install PREFIX=%{_prefix} DESTDIR=%{buildroot}
install -Dpm0755 pngquant %{buildroot}/%{_bindir}/pngquant
install -Dpm0644 pngquant.1 %{buildroot}/%{_mandir}/man1/pngquant.1
%files
%defattr(-,root,root,-)
%doc README.md CHANGELOG COPYRIGHT
%{_bindir}/pngquant
%{_mandir}/man1/pngquant.1*
%changelog
* Fri Sep 12 2014 Michael Dec 1.8.3-1
- Update to latest upstream version and corrected the .spec
* Thu May 03 2012 Craig Barnes - 1.7.2-1
- Update to latest upstream version
* Sun Jan 15 2012 Craig Barnes - 1.7.0-1
- Update to latest upstream version
* Mon Jan 09 2012 Craig Barnes - 1.6.4-1
- Update to latest version
- Remove Makefile patch (merged upstream)
- Use prefix macro when installing (upstream changed the default prefix)
* Wed Dec 28 2011 Craig Barnes - 1.6.2-1
- Initial package
pngquant-2.12.6/pngquant_opts.c 0000664 0000000 0000000 00000013264 13602415555 0016521 0 ustar 00root root 0000000 0000000 /*
** © 2017 by Kornel Lesiński.
**
** See COPYRIGHT file for license.
*/
#include
#include
#include
#include
#include
#include "rwpng.h"
#include "libimagequant.h" /* if you get compile error, add -Ilib to compiler flags */
#include "pngquant_opts.h"
extern char *optarg;
extern int optind, opterr;
static const struct {const char *old; const char *newopt;} obsolete_options[] = {
{"-fs","--floyd=1"},
{"-nofs", "--ordered"},
{"-floyd", "--floyd=1"},
{"-nofloyd", "--ordered"},
{"-ordered", "--ordered"},
{"-force", "--force"},
{"-noforce", "--no-force"},
{"-verbose", "--verbose"},
{"-quiet", "--quiet"},
{"-noverbose", "--quiet"},
{"-noquiet", "--verbose"},
{"-help", "--help"},
{"-version", "--version"},
{"-ext", "--ext"},
{"-speed", "--speed"},
};
static void fix_obsolete_options(const unsigned int argc, char *argv[])
{
for(unsigned int argn=1; argn < argc; argn++) {
if ('-' != argv[argn][0]) continue;
if ('-' == argv[argn][1]) break; // stop on first --option or --
for(unsigned int i=0; i < sizeof(obsolete_options)/sizeof(obsolete_options[0]); i++) {
if (0 == strcmp(obsolete_options[i].old, argv[argn])) {
fprintf(stderr, " warning: option '%s' has been replaced with '%s'.\n", obsolete_options[i].old, obsolete_options[i].newopt);
argv[argn] = (char*)obsolete_options[i].newopt;
}
}
}
}
enum {arg_floyd=1, arg_ordered, arg_ext, arg_no_force, arg_iebug,
arg_transbug, arg_map, arg_posterize, arg_skip_larger, arg_strip};
static const struct option long_options[] = {
{"verbose", no_argument, NULL, 'v'},
{"quiet", no_argument, NULL, 'q'},
{"force", no_argument, NULL, 'f'},
{"no-force", no_argument, NULL, arg_no_force},
{"floyd", optional_argument, NULL, arg_floyd},
{"ordered", no_argument, NULL, arg_ordered},
{"nofs", no_argument, NULL, arg_ordered},
{"iebug", no_argument, NULL, arg_iebug},
{"transbug", no_argument, NULL, arg_transbug},
{"ext", required_argument, NULL, arg_ext},
{"skip-if-larger", no_argument, NULL, arg_skip_larger},
{"output", required_argument, NULL, 'o'},
{"speed", required_argument, NULL, 's'},
{"quality", required_argument, NULL, 'Q'},
{"posterize", required_argument, NULL, arg_posterize},
{"strip", no_argument, NULL, arg_strip},
{"map", required_argument, NULL, arg_map},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0},
};
pngquant_error pngquant_parse_options(int argc, char *argv[], struct pngquant_options *options)
{
fix_obsolete_options(argc, argv);
int opt;
do {
opt = getopt_long(argc, argv, "Vvqfhs:Q:o:", long_options, NULL);
switch (opt) {
case 'v':
options->verbose = true;
break;
case 'q':
options->verbose = false;
break;
case arg_floyd:
options->floyd = optarg ? atof(optarg) : 1.f;
if (options->floyd < 0 || options->floyd > 1.f) {
fputs("--floyd argument must be in 0..1 range\n", stderr);
return INVALID_ARGUMENT;
}
break;
case arg_ordered: options->floyd = 0; break;
case 'f': options->force = true; break;
case arg_no_force: options->force = false; break;
case arg_ext: options->extension = optarg; break;
case 'o':
if (options->output_file_path) {
fputs("--output option can be used only once\n", stderr);
return INVALID_ARGUMENT;
}
if (strcmp(optarg, "-") == 0) {
options->using_stdout = true;
break;
}
options->output_file_path = optarg; break;
case arg_iebug:
options->iebug = true;
break;
case arg_transbug:
options->last_index_transparent = true;
break;
case arg_skip_larger:
options->skip_if_larger = true;
break;
case 's':
options->speed = optarg[0] == '0' ? -1 : atoi(optarg);
break;
case 'Q':
options->quality = optarg;
break;
case arg_posterize:
options->posterize = atoi(optarg);
break;
case arg_strip:
options->strip = true;
break;
case arg_map:
options->map_file = optarg;
break;
case 'h':
options->print_help = true;
break;
case 'V':
options->print_version = true;
break;
case -1: break;
default:
return INVALID_ARGUMENT;
}
} while (opt != -1);
int argn = optind;
if (argn < argc) {
char *colors_end;
unsigned long colors = strtoul(argv[argn], &colors_end, 10);
if (colors_end != argv[argn] && '\0' == colors_end[0]) {
options->colors = colors;
argn++;
}
if (argn == argc || (argn == argc-1 && 0==strcmp(argv[argn],"-"))) {
options->using_stdin = true;
options->using_stdout = !options->output_file_path;
argn = argc-1;
}
options->num_files = argc-argn;
options->files = argv+argn;
} else if (argn <= 1) {
options->missing_arguments = true;
}
return SUCCESS;
}
pngquant-2.12.6/pngquant_opts.h 0000664 0000000 0000000 00000001411 13602415555 0016515 0 ustar 00root root 0000000 0000000 #ifndef PNGQUANT_OPTS_H
#define PNGQUANT_OPTS_H
struct pngquant_options {
liq_image *fixed_palette_image;
liq_log_callback_function *log_callback;
void *log_callback_user_info;
const char *quality;
const char *extension;
const char *output_file_path;
const char *map_file;
char *const *files;
unsigned int num_files;
unsigned int colors;
unsigned int speed;
unsigned int posterize;
float floyd;
bool using_stdin, using_stdout, force, fast_compression,
min_quality_limit, skip_if_larger,
strip, iebug, last_index_transparent,
print_help, print_version, missing_arguments,
verbose;
};
pngquant_error pngquant_parse_options(int argc, char *argv[], struct pngquant_options *options);
#endif
pngquant-2.12.6/rust/ 0000775 0000000 0000000 00000000000 13602415555 0014442 5 ustar 00root root 0000000 0000000 pngquant-2.12.6/rust/bin.rs 0000664 0000000 0000000 00000022736 13602415555 0015572 0 ustar 00root root 0000000 0000000 /*
** © 2019 by Kornel Lesiński.
**
** See COPYRIGHT file for license.
*/
#[cfg(feature = "openmp")]
extern crate openmp_sys;
extern crate imagequant_sys;
extern crate libpng_sys;
#[cfg(feature = "cocoa")]
pub mod rwpng_cocoa;
#[cfg(feature = "lcms2")]
extern crate lcms2_sys;
use imagequant_sys::liq_error::LIQ_OK;
use imagequant_sys::*;
use libc::FILE;
use crate::ffi::PNGQUANT_VERSION;
use crate::ffi::pngquant_internal_print_config;
use std::os::raw::{c_uint, c_char, c_void};
use std::ptr;
use std::io;
use std::ffi::{CString, CStr};
mod ffi;
use crate::ffi::*;
use crate::ffi::pngquant_error::*;
fn unwrap_ptr(opt: Option<&CString>) -> *const c_char {
opt.map(|c| c.as_ptr()).unwrap_or(ptr::null())
}
fn print_full_version(fd: &mut dyn io::Write, c_fd: *mut FILE) {
let _ = writeln!(fd, "pngquant, {} (Rust), by Kornel Lesinski, Greg Roelofs.", unsafe{CStr::from_ptr(PNGQUANT_VERSION)}.to_str().unwrap());
let _ = fd.flush();
unsafe{pngquant_internal_print_config(c_fd);}
let _ = writeln!(fd);
}
fn print_usage(fd: &mut dyn io::Write) {
let _ = writeln!(fd, "{}", unsafe { CStr::from_ptr(PNGQUANT_USAGE) }.to_str().unwrap());
}
/**
* N = automatic quality, uses limit unless force is set (N-N or 0-N)
* -N = no better than N (same as 0-N)
* N-M = no worse than N, no better than M
* N- = no worse than N, perfect if possible (same as N-100)
*
* where N,M are numbers between 0 (lousy) and 100 (perfect)
*/
fn parse_quality(quality: &str) -> Option<(u8, u8)> {
let mut parts = quality.splitn(2, '-');
let left = parts.next().unwrap();
let right = parts.next();
Some(match (left, right) {
// quality="%d-"
(t, Some("")) => {
(t.parse().ok()?, 100)
},
// quality="-%d"
("", Some(t)) => {
(0, t.parse().ok()?)
},
// quality="%d"
(t, None) => {
let target = t.parse().ok()?;
(((target as u16)*9/10) as u8, target)
},
// quality="%d-%d"
(l, Some(t)) => {
(l.parse().ok()?, t.parse().ok()?)
},
})
}
unsafe extern "C" fn log_callback(_a: &liq_attr, msg: *const c_char, _user: *mut c_void) {
eprintln!("{}", CStr::from_ptr(msg).to_str().unwrap());
}
fn main() {
std::process::exit(run() as _);
}
fn run() -> ffi::pngquant_error {
let mut opts = getopts::Options::new();
opts.optflag("v", "verbose", "");
opts.optflag("h", "help", "");
opts.optflag("q", "quiet", "");
opts.optflag("f", "force", "");
opts.optflag("", "no-force", "");
opts.optflag("", "ordered", "");
opts.optflag("", "nofs", "");
opts.optflag("", "iebug", "");
opts.optflag("", "transbug", "");
opts.optflag("", "skip-if-larger", "");
opts.optflag("", "strip", "");
opts.optflag("V", "version", "");
opts.optflagopt("", "floyd", "0.0-1.0", "");
opts.optopt("", "ext", "extension", "");
opts.optopt("o", "output", "file", "");
opts.optopt("s", "speed", "4", "");
opts.optopt("Q", "quality", "0-100", "");
opts.optopt("", "posterize", "0", "");
opts.optopt("", "map", "png", "");
let args: Vec<_> = wild::args().skip(1).collect();
let has_some_explicit_args = !args.is_empty();
let mut m = match opts.parse(args) {
Ok(m) => m,
Err(err) => {
eprintln!("{}", err);
print_usage(&mut io::stderr());
return MISSING_ARGUMENT;
},
};
let posterize = m.opt_str("posterize").and_then(|p| p.parse().ok()).unwrap_or(0);
let floyd = m.opt_str("floyd").and_then(|p| p.parse().ok()).unwrap_or(1.);
let quality = m.opt_str("quality");
let extension = m.opt_str("ext").and_then(|s| CString::new(s).ok());
let map_file = m.opt_str("map").and_then(|s| CString::new(s).ok());
let colors = if let Some(c) = m.free.get(0).and_then(|s| s.parse().ok()) {
m.free.remove(0);
if m.free.len() == 0 {
m.free.push("-".to_owned()); // stdin default
}
c
} else {0};
let using_stdin = m.free.len() == 1 && Some("-") == m.free.get(0).map(|s| s.as_str());
let mut using_stdout = using_stdin;
let output_file_path = m.opt_str("o").and_then(|s| {
if s == "-" {
using_stdout = true;
None
} else {
using_stdout = false;
CString::new(s).ok()
}
});
let files: Vec<_> = m.free.drain(..).filter_map(|s| CString::new(s).ok()).collect();
let file_ptrs: Vec<_> = files.iter().map(|s| s.as_ptr()).collect();
let mut options = pngquant_options {
quality: ptr::null_mut(), // handled in Rust now
extension: unwrap_ptr(extension.as_ref()),
output_file_path: unwrap_ptr(output_file_path.as_ref()),
map_file: unwrap_ptr(map_file.as_ref()),
files: file_ptrs.as_ptr(),
num_files: file_ptrs.len() as c_uint,
using_stdin,
using_stdout,
missing_arguments: !has_some_explicit_args,
colors,
speed: 0, // handled in Rust
posterize,
floyd,
force: m.opt_present("force") && !m.opt_present("no-force"),
skip_if_larger: m.opt_present("skip-if-larger"),
strip: m.opt_present("strip"),
iebug: false,
last_index_transparent: false, // handled in Rust
print_help: m.opt_present("h"),
print_version: m.opt_present("V"),
verbose: m.opt_present("v"),
fixed_palette_image: ptr::null_mut(),
log_callback: None,
log_callback_user_info: ptr::null_mut(),
fast_compression: false,
min_quality_limit: false,
};
if m.opt_present("nofs") || m.opt_present("ordered") {
options.floyd = 0.;
}
if options.print_version {
println!("{}", unsafe { CStr::from_ptr(PNGQUANT_VERSION) }.to_str().unwrap());
return SUCCESS;
}
if options.missing_arguments {
print_full_version(&mut io::stderr(), unsafe { pngquant_c_stderr() });
print_usage(&mut io::stderr());
return MISSING_ARGUMENT;
}
if options.print_help {
print_full_version(&mut io::stdout(), unsafe { pngquant_c_stdout() });
print_usage(&mut io::stdout());
return SUCCESS;
}
let liq = unsafe { liq_attr_create().as_mut().unwrap() };
if options.verbose {
unsafe{liq_set_log_callback(liq, Some(log_callback), ptr::null_mut());}
options.log_callback = Some(log_callback);
}
if m.opt_present("transbug") {
unsafe{liq_set_last_index_transparent(liq, true as _);}
}
if let Some(speed) = m.opt_str("speed") {
let set_ok = speed.parse().ok()
.filter(|&s: &u8| s>=1 && s <=11)
.map_or(false, |mut speed| {
if speed >= 10 {
options.fast_compression = true;
if speed == 11 {
speed = 10;
options.floyd = 0.0;
}
}
LIQ_OK == unsafe{liq_set_speed(liq, speed.into())}
});
if !set_ok {
eprintln!("Speed should be between 1 (slow) and 11 (fast).");
return INVALID_ARGUMENT;
}
}
if let Some(q) = quality.as_ref() {
if let Some((limit, target)) = parse_quality(q) {
options.min_quality_limit = limit > 0;
if LIQ_OK != unsafe { liq_set_quality(liq, limit.into(), target.into()) } {
eprintln!("Quality value(s) must be numbers in range 0-100.");
return INVALID_ARGUMENT;
}
} else {
eprintln!("Quality should be in format min-max where min and max are numbers in range 0-100.");
return INVALID_ARGUMENT;
}
}
if options.colors > 0 && LIQ_OK != unsafe { liq_set_max_colors(liq, options.colors as _) } {
eprintln!("Number of colors must be between 2 and 256.");
return INVALID_ARGUMENT;
}
if options.posterize > 0 && LIQ_OK != unsafe { liq_set_min_posterization(liq, options.posterize as _) } {
eprintln!("Posterization should be number of bits in range 0-4.");
return INVALID_ARGUMENT;
}
if !options.extension.is_null() && !options.output_file_path.is_null() {
eprintln!("--ext and --output options can't be used at the same time\n");
return INVALID_ARGUMENT;
}
// new filename extension depends on options used. Typically basename-fs8.png
if options.extension.is_null() {
options.extension = if options.floyd > 0. { b"-fs8.png\0" } else { b"-or8.png\0" }.as_ptr() as *const _;
}
if !options.output_file_path.is_null() && options.num_files != 1 {
eprintln!(" error: Only one input file is allowed when --output is used. This error also happens when filenames with spaces are not in quotes.");
return INVALID_ARGUMENT;
}
if options.using_stdout && !options.using_stdin && options.num_files != 1 {
eprintln!(" error: Only one input file is allowed when using the special output path \"-\" to write to stdout. This error also happens when filenames with spaces are not in quotes.");
return INVALID_ARGUMENT;
}
if options.num_files == 0 && !options.using_stdin {
eprintln!("No input files specified.");
if options.verbose {
print_full_version(&mut io::stdout(), unsafe { pngquant_c_stdout() });
}
print_usage(&mut io::stderr());
return MISSING_ARGUMENT;
}
let retval = unsafe {pngquant_main_internal(&mut options, liq)};
unsafe {liq_attr_destroy(liq);}
retval
}
pngquant-2.12.6/rust/build.rs 0000664 0000000 0000000 00000002745 13602415555 0016117 0 ustar 00root root 0000000 0000000 use std::env;
use std::path::Path;
fn main() {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
let mut cc = cc::Build::new();
cc.warnings(false);
cc.define("PNGQUANT_NO_MAIN", Some("1"));
if cfg!(feature = "openmp") {
cc.flag(&env::var("DEP_OPENMP_FLAG").unwrap());
}
if cfg!(feature = "cocoa") {
if cfg!(feature = "lcms2") {
println!("cargo:warning=Don't use both lcms2 and cocoa features at the same time, see --no-default-features");
}
cc.define("USE_COCOA", Some("1"));
} else if cfg!(feature = "lcms2") {
if let Ok(p) = env::var("DEP_LCMS2_INCLUDE") {
cc.include(dunce::simplified(Path::new(&p)));
}
cc.define("USE_LCMS", Some("1"));
}
if env::var("PROFILE").map(|p| p != "debug").unwrap_or(true) {
cc.define("NDEBUG", Some("1"));
} else {
cc.define("DEBUG", Some("1"));
}
if target_arch == "x86_64" ||
(target_arch == "x86" && cfg!(feature = "sse")) {
cc.define("USE_SSE", Some("1"));
}
cc.file("rwpng.c");
cc.file("pngquant.c");
if let Ok(p) = env::var("DEP_IMAGEQUANT_INCLUDE") {
cc.include(dunce::simplified(Path::new(&p)));
} else {
cc.include("lib");
}
if let Ok(p) = env::var("DEP_PNG_INCLUDE") {
for p in env::split_paths(&p) {
cc.include(dunce::simplified(&p));
}
}
cc.compile("libpngquant.a");
}
pngquant-2.12.6/rust/ffi.rs 0000664 0000000 0000000 00000003440 13602415555 0015555 0 ustar 00root root 0000000 0000000 #![allow(non_camel_case_types)]
use libc::FILE;
use std::os::raw::*;
use imagequant_sys::*;
extern "C" {
pub static PNGQUANT_VERSION: *const c_char;
pub static PNGQUANT_USAGE: *const c_char;
pub fn pngquant_internal_print_config(fd: *mut libc::FILE);
pub fn pngquant_main_internal(options: &mut pngquant_options, liq: *mut liq_attr) -> pngquant_error;
pub fn pngquant_c_stderr() -> *mut FILE;
pub fn pngquant_c_stdout() -> *mut FILE;
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
#[allow(non_camel_case_types)]
pub enum pngquant_error {
SUCCESS = 0,
MISSING_ARGUMENT = 1,
READ_ERROR = 2,
INVALID_ARGUMENT = 4,
NOT_OVERWRITING_ERROR = 15,
CANT_WRITE_ERROR = 16,
OUT_OF_MEMORY_ERROR = 17,
WRONG_ARCHITECTURE = 18, // Missing SSE
PNG_OUT_OF_MEMORY_ERROR = 24,
LIBPNG_FATAL_ERROR = 25,
WRONG_INPUT_COLOR_TYPE = 26,
LIBPNG_INIT_ERROR = 35,
TOO_LARGE_FILE = 98,
TOO_LOW_QUALITY = 99,
}
#[repr(C)]
pub struct pngquant_options {
pub fixed_palette_image: *mut liq_image,
pub log_callback: liq_log_callback_function,
pub log_callback_user_info: *mut c_void,
pub quality: *const c_char,
pub extension: *const c_char,
pub output_file_path: *const c_char,
pub map_file: *const c_char,
pub files: *const *const c_char,
pub num_files: c_uint,
pub colors: c_uint,
pub speed: c_uint,
pub posterize: c_uint,
pub floyd: f32,
pub using_stdin: bool,
pub using_stdout: bool,
pub force: bool,
pub fast_compression: bool,
pub min_quality_limit: bool,
pub skip_if_larger: bool,
pub strip: bool,
pub iebug: bool,
pub last_index_transparent: bool,
pub print_help: bool,
pub print_version: bool,
pub missing_arguments: bool,
pub verbose: bool,
}
pngquant-2.12.6/rust/rwpng_cocoa.rs 0000664 0000000 0000000 00000002221 13602415555 0017306 0 ustar 00root root 0000000 0000000 use libc::{FILE, fileno, malloc};
use std::fs::File;
use std::io::prelude::*;
use std::os::unix::io::FromRawFd;
use crate::ffi::pngquant_error;
#[no_mangle]
pub extern "C" fn rwpng_read_image32_cocoa(file_handle: *mut FILE, width: &mut u32, height: &mut u32, file_size: &mut usize, out: &mut *mut cocoa_image::RGBA8) -> pngquant_error {
let mut file = unsafe {
File::from_raw_fd(fileno(file_handle))
};
let mut data = Vec::new();
match file.read_to_end(&mut data) {
Ok(_) => {},
Err(_) => return pngquant_error::READ_ERROR,
};
let image = match cocoa_image::decode_image_as_rgba(&data) {
Ok(img) => img,
Err(_) => return pngquant_error::LIBPNG_FATAL_ERROR,
};
*file_size = data.len();
*width = image.width() as u32;
*height = image.height() as u32;
unsafe {
*out = malloc(image.buf.len() * ::std::mem::size_of::()) as *mut _;
if (*out).is_null() {
return pngquant_error::OUT_OF_MEMORY_ERROR;
}
::std::slice::from_raw_parts_mut(*out, image.buf.len()).clone_from_slice(&image.buf);
}
pngquant_error::SUCCESS
}
pngquant-2.12.6/rwpng.c 0000664 0000000 0000000 00000052101 13602415555 0014745 0 ustar 00root root 0000000 0000000 /*
** PNG read/write functions
**
** © 1998-2000 by Greg Roelofs.
** © 2009-2017 by Kornel Lesiński.
**
** See COPYRIGHT file for license.
*/
#include
#include
#include
#include
#include "png.h" /* if this include fails, you need to install libpng (e.g. libpng-devel package) and run ./configure */
#include "rwpng.h"
#if USE_LCMS
#include "lcms2.h"
#endif
#ifndef Z_BEST_COMPRESSION
#define Z_BEST_COMPRESSION 9
#endif
#ifndef Z_BEST_SPEED
#define Z_BEST_SPEED 1
#endif
#ifdef _OPENMP
#include
#else
#define omp_get_max_threads() 1
#endif
#if PNG_LIBPNG_VER < 10400
#error libpng version 1.4 or later is required. 1.6 is recommended. You have an obsolete version of libpng or compiling on an outdated/unsupported operating system. Please upgrade.
#endif
#if PNG_LIBPNG_VER < 10500
typedef png_const_charp png_const_bytep;
#endif
static void rwpng_error_handler(png_structp png_ptr, png_const_charp msg);
pngquant_error rwpng_read_image32_cocoa(FILE *infile, uint32_t *width, uint32_t *height, size_t *file_size, rwpng_rgba **image_data);
void rwpng_version_info(FILE *fp)
{
const char *pngver = png_get_header_ver(NULL);
#if USE_COCOA
fprintf(fp, " Color profiles are supported via Cocoa. Using libpng %s.\n", pngver);
#elif USE_LCMS
fprintf(fp, " Color profiles are supported via Little CMS. Using libpng %s.\n", pngver);
#else
fprintf(fp, " Compiled with no support for color profiles. Using libpng %s.\n", pngver);
#endif
#if PNG_LIBPNG_VER < 10600
if (strcmp(pngver, "1.3.") < 0) {
fputs("\nWARNING: Your version of libpng is outdated and may produce corrupted files.\n"
"Please recompile pngquant with the current version of libpng (1.6 or later).\n", fp);
} else if (strcmp(pngver, "1.6.") < 0) {
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
fputs("\nWARNING: Your version of libpng is old and has buggy support for custom chunks.\n"
"Please recompile pngquant with the current version of libpng (1.6 or later).\n", fp);
#endif
}
#endif
}
struct rwpng_read_data {
FILE *const fp;
png_size_t bytes_read;
};
#if !USE_COCOA
static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
struct rwpng_read_data *read_data = (struct rwpng_read_data *)png_get_io_ptr(png_ptr);
png_size_t read = fread(data, 1, length, read_data->fp);
if (!read) {
png_error(png_ptr, "Read error");
}
read_data->bytes_read += read;
}
#endif
struct rwpng_write_state {
FILE *outfile;
png_size_t maximum_file_size;
png_size_t bytes_written;
pngquant_error retval;
};
static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
struct rwpng_write_state *write_state = (struct rwpng_write_state *)png_get_io_ptr(png_ptr);
if (SUCCESS != write_state->retval) {
return;
}
if (!fwrite(data, length, 1, write_state->outfile)) {
write_state->retval = CANT_WRITE_ERROR;
}
write_state->bytes_written += length;
}
static void user_flush_data(png_structp png_ptr)
{
// libpng never calls this :(
}
static png_bytepp rwpng_create_row_pointers(png_infop info_ptr, png_structp png_ptr, unsigned char *base, size_t height, png_size_t rowbytes)
{
if (!rowbytes) {
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
}
png_bytepp row_pointers = malloc(height * sizeof(row_pointers[0]));
if (!row_pointers) return NULL;
for(size_t row = 0; row < height; row++) {
row_pointers[row] = base + row * rowbytes;
}
return row_pointers;
}
#if !USE_COCOA
static int read_chunk_callback(png_structp png_ptr, png_unknown_chunkp in_chunk)
{
if (0 == memcmp("iCCP", in_chunk->name, 5) ||
0 == memcmp("cHRM", in_chunk->name, 5) ||
0 == memcmp("gAMA", in_chunk->name, 5)) {
return 0; // not handled
}
if (in_chunk->location == 0 ) {
return 1; // ignore chunks with invalid location
}
struct rwpng_chunk **head = (struct rwpng_chunk **)png_get_user_chunk_ptr(png_ptr);
struct rwpng_chunk *chunk = malloc(sizeof(struct rwpng_chunk));
memcpy(chunk->name, in_chunk->name, 5);
chunk->size = in_chunk->size;
chunk->location = in_chunk->location;
chunk->data = in_chunk->size ? malloc(in_chunk->size) : NULL;
if (in_chunk->size) {
memcpy(chunk->data, in_chunk->data, in_chunk->size);
}
chunk->next = *head;
*head = chunk;
return 1; // marks as "handled", libpng won't store it
}
#endif
/*
retval:
0 = success
21 = bad sig
22 = bad IHDR
24 = insufficient memory
25 = libpng error (via longjmp())
26 = wrong PNG color type (no alpha channel)
*/
#if !USE_COCOA
static void rwpng_warning_stderr_handler(png_structp png_ptr, png_const_charp msg) {
fprintf(stderr, " libpng warning: %s\n", msg);
}
static void rwpng_warning_silent_handler(png_structp png_ptr, png_const_charp msg) {
}
static pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr, int strip, int verbose)
{
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
png_size_t rowbytes;
int color_type, bit_depth;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
rwpng_error_handler, verbose ? rwpng_warning_stderr_handler : rwpng_warning_silent_handler);
if (!png_ptr) {
return PNG_OUT_OF_MEMORY_ERROR; /* out of memory */
}
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
return PNG_OUT_OF_MEMORY_ERROR; /* out of memory */
}
/* setjmp() must be called in every function that calls a non-trivial
* libpng function */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return LIBPNG_FATAL_ERROR; /* fatal libpng error (via longjmp()) */
}
#if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && defined(PNG_SET_OPTION_SUPPORTED)
png_set_option(png_ptr, PNG_SKIP_sRGB_CHECK_PROFILE, PNG_OPTION_ON);
#endif
#if PNG_LIBPNG_VER >= 10500 && defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
if (!strip) {
/* copy standard chunks too */
png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_IF_SAFE, (png_const_bytep)"pHYs\0iTXt\0tEXt\0zTXt", 4);
}
#endif
if (!strip) {
png_set_read_user_chunk_fn(png_ptr, &mainprog_ptr->chunks, read_chunk_callback);
}
struct rwpng_read_data read_data = {infile, 0};
png_set_read_fn(png_ptr, &read_data, user_read_data);
png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */
/* alternatively, could make separate calls to png_get_image_width(),
* etc., but want bit_depth and color_type for later [don't care about
* compression_type and filter_type => NULLs] */
png_get_IHDR(png_ptr, info_ptr, &mainprog_ptr->width, &mainprog_ptr->height,
&bit_depth, &color_type, NULL, NULL, NULL);
/* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
* transparency chunks to full alpha channel; strip 16-bit-per-sample
* images to 8 bits per sample; and convert grayscale to RGB[A] */
/* GRR TO DO: preserve all safe-to-copy ancillary PNG chunks */
if (!(color_type & PNG_COLOR_MASK_ALPHA)) {
#ifdef PNG_READ_FILLER_SUPPORTED
png_set_expand(png_ptr);
png_set_filler(png_ptr, 65535L, PNG_FILLER_AFTER);
#else
fprintf(stderr, "pngquant readpng: image is neither RGBA nor GA\n");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
mainprog_ptr->retval = WRONG_INPUT_COLOR_TYPE;
return mainprog_ptr->retval;
#endif
}
if (bit_depth == 16) {
png_set_strip_16(png_ptr);
}
if (!(color_type & PNG_COLOR_MASK_COLOR)) {
png_set_gray_to_rgb(png_ptr);
}
/* get source gamma for gamma correction, or use sRGB default */
double gamma = 0.45455;
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sRGB)) {
mainprog_ptr->input_color = RWPNG_SRGB;
mainprog_ptr->output_color = RWPNG_SRGB;
} else {
png_get_gAMA(png_ptr, info_ptr, &gamma);
if (gamma > 0 && gamma <= 1.0) {
mainprog_ptr->input_color = RWPNG_GAMA_ONLY;
mainprog_ptr->output_color = RWPNG_GAMA_ONLY;
} else {
fprintf(stderr, "pngquant readpng: ignored out-of-range gamma %f\n", gamma);
mainprog_ptr->input_color = RWPNG_NONE;
mainprog_ptr->output_color = RWPNG_NONE;
gamma = 0.45455;
}
}
mainprog_ptr->gamma = gamma;
png_set_interlace_handling(png_ptr);
/* all transformations have been registered; now update info_ptr data,
* get rowbytes and channels, and allocate image memory */
png_read_update_info(png_ptr, info_ptr);
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
// For overflow safety reject images that won't fit in 32-bit
if (rowbytes > INT_MAX/mainprog_ptr->height) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return PNG_OUT_OF_MEMORY_ERROR;
}
if ((mainprog_ptr->rgba_data = malloc(rowbytes * mainprog_ptr->height)) == NULL) {
fprintf(stderr, "pngquant readpng: unable to allocate image data\n");
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return PNG_OUT_OF_MEMORY_ERROR;
}
png_bytepp row_pointers = rwpng_create_row_pointers(info_ptr, png_ptr, mainprog_ptr->rgba_data, mainprog_ptr->height, 0);
/* now we can go ahead and just read the whole image */
png_read_image(png_ptr, row_pointers);
/* and we're done! (png_read_end() can be omitted if no processing of
* post-IDAT text/time/etc. is desired) */
png_read_end(png_ptr, NULL);
#if USE_LCMS
#if PNG_LIBPNG_VER < 10500
png_charp ProfileData;
#else
png_bytep ProfileData;
#endif
png_uint_32 ProfileLen;
cmsHPROFILE hInProfile = NULL;
/* color_type is read from the image before conversion to RGBA */
int COLOR_PNG = color_type & PNG_COLOR_MASK_COLOR;
/* embedded ICC profile */
if (png_get_iCCP(png_ptr, info_ptr, &(png_charp){0}, &(int){0}, &ProfileData, &ProfileLen)) {
hInProfile = cmsOpenProfileFromMem(ProfileData, ProfileLen);
cmsColorSpaceSignature colorspace = cmsGetColorSpace(hInProfile);
/* only RGB (and GRAY) valid for PNGs */
if (colorspace == cmsSigRgbData && COLOR_PNG) {
mainprog_ptr->input_color = RWPNG_ICCP;
mainprog_ptr->output_color = RWPNG_SRGB;
} else {
if (colorspace == cmsSigGrayData && !COLOR_PNG) {
mainprog_ptr->input_color = RWPNG_ICCP_WARN_GRAY;
mainprog_ptr->output_color = RWPNG_SRGB;
}
cmsCloseProfile(hInProfile);
hInProfile = NULL;
}
}
/* build RGB profile from cHRM and gAMA */
if (hInProfile == NULL && COLOR_PNG &&
!png_get_valid(png_ptr, info_ptr, PNG_INFO_sRGB) &&
png_get_valid(png_ptr, info_ptr, PNG_INFO_gAMA) &&
png_get_valid(png_ptr, info_ptr, PNG_INFO_cHRM)) {
cmsCIExyY WhitePoint;
cmsCIExyYTRIPLE Primaries;
png_get_cHRM(png_ptr, info_ptr, &WhitePoint.x, &WhitePoint.y,
&Primaries.Red.x, &Primaries.Red.y,
&Primaries.Green.x, &Primaries.Green.y,
&Primaries.Blue.x, &Primaries.Blue.y);
WhitePoint.Y = Primaries.Red.Y = Primaries.Green.Y = Primaries.Blue.Y = 1.0;
cmsToneCurve *GammaTable[3];
GammaTable[0] = GammaTable[1] = GammaTable[2] = cmsBuildGamma(NULL, 1/gamma);
hInProfile = cmsCreateRGBProfile(&WhitePoint, &Primaries, GammaTable);
cmsFreeToneCurve(GammaTable[0]);
mainprog_ptr->input_color = RWPNG_GAMA_CHRM;
mainprog_ptr->output_color = RWPNG_SRGB;
}
/* transform image to sRGB colorspace */
if (hInProfile != NULL) {
cmsHPROFILE hOutProfile = cmsCreate_sRGBProfile();
cmsHTRANSFORM hTransform = cmsCreateTransform(hInProfile, TYPE_RGBA_8,
hOutProfile, TYPE_RGBA_8,
INTENT_PERCEPTUAL,
omp_get_max_threads() > 1 ? cmsFLAGS_NOCACHE : 0);
#pragma omp parallel for \
if (mainprog_ptr->height*mainprog_ptr->width > 8000) \
schedule(static)
for (unsigned int i = 0; i < mainprog_ptr->height; i++) {
/* It is safe to use the same block for input and output,
when both are of the same TYPE. */
cmsDoTransform(hTransform, row_pointers[i],
row_pointers[i],
mainprog_ptr->width);
}
cmsDeleteTransform(hTransform);
cmsCloseProfile(hOutProfile);
cmsCloseProfile(hInProfile);
mainprog_ptr->gamma = 0.45455;
}
#endif
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
mainprog_ptr->file_size = read_data.bytes_read;
mainprog_ptr->row_pointers = (unsigned char **)row_pointers;
return SUCCESS;
}
#endif
static void rwpng_free_chunks(struct rwpng_chunk *chunk) {
if (!chunk) return;
rwpng_free_chunks(chunk->next);
free(chunk->data);
free(chunk);
}
void rwpng_free_image24(png24_image *image)
{
free(image->row_pointers);
image->row_pointers = NULL;
free(image->rgba_data);
image->rgba_data = NULL;
rwpng_free_chunks(image->chunks);
image->chunks = NULL;
}
void rwpng_free_image8(png8_image *image)
{
free(image->indexed_data);
image->indexed_data = NULL;
free(image->row_pointers);
image->row_pointers = NULL;
rwpng_free_chunks(image->chunks);
image->chunks = NULL;
}
pngquant_error rwpng_read_image24(FILE *infile, png24_image *out, int strip, int verbose)
{
#if USE_COCOA
rwpng_rgba *pixel_data;
pngquant_error res = rwpng_read_image32_cocoa(infile, &out->width, &out->height, &out->file_size, &pixel_data);
if (res != SUCCESS) {
return res;
}
out->gamma = 0.45455;
out->input_color = RWPNG_COCOA;
out->output_color = RWPNG_SRGB;
out->rgba_data = (unsigned char *)pixel_data;
out->row_pointers = malloc(sizeof(out->row_pointers[0])*out->height);
for(int i=0; i < out->height; i++) {
out->row_pointers[i] = (unsigned char *)&pixel_data[out->width*i];
}
return SUCCESS;
#else
return rwpng_read_image24_libpng(infile, out, strip, verbose);
#endif
}
static pngquant_error rwpng_write_image_init(rwpng_png_image *mainprog_ptr, png_structpp png_ptr_p, png_infopp info_ptr_p, int fast_compression)
{
/* could also replace libpng warning-handler (final NULL), but no need: */
*png_ptr_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, rwpng_error_handler, NULL);
if (!(*png_ptr_p)) {
return LIBPNG_INIT_ERROR; /* out of memory */
}
*info_ptr_p = png_create_info_struct(*png_ptr_p);
if (!(*info_ptr_p)) {
png_destroy_write_struct(png_ptr_p, NULL);
return LIBPNG_INIT_ERROR; /* out of memory */
}
/* setjmp() must be called in every function that calls a PNG-writing
* libpng function, unless an alternate error handler was installed--
* but compatible error handlers must either use longjmp() themselves
* (as in this program) or exit immediately, so here we go: */
if (setjmp(mainprog_ptr->jmpbuf)) {
png_destroy_write_struct(png_ptr_p, info_ptr_p);
return LIBPNG_INIT_ERROR; /* libpng error (via longjmp()) */
}
png_set_compression_level(*png_ptr_p, fast_compression ? Z_BEST_SPEED : Z_BEST_COMPRESSION);
png_set_compression_mem_level(*png_ptr_p, fast_compression ? 9 : 5); // judging by optipng results, smaller mem makes libpng compress slightly better
return SUCCESS;
}
static void rwpng_write_end(png_infopp info_ptr_p, png_structpp png_ptr_p, png_bytepp row_pointers)
{
png_write_info(*png_ptr_p, *info_ptr_p);
png_set_packing(*png_ptr_p);
png_write_image(*png_ptr_p, row_pointers);
png_write_end(*png_ptr_p, NULL);
png_destroy_write_struct(png_ptr_p, info_ptr_p);
}
static void rwpng_set_gamma(png_infop info_ptr, png_structp png_ptr, double gamma, rwpng_color_transform color)
{
if (color != RWPNG_GAMA_ONLY && color != RWPNG_NONE) {
png_set_gAMA(png_ptr, info_ptr, gamma);
}
if (color == RWPNG_SRGB) {
png_set_sRGB(png_ptr, info_ptr, 0); // 0 = Perceptual
}
}
pngquant_error rwpng_write_image8(FILE *outfile, png8_image *mainprog_ptr)
{
png_structp png_ptr;
png_infop info_ptr;
if (mainprog_ptr->num_palette > 256) return INVALID_ARGUMENT;
pngquant_error retval = rwpng_write_image_init((rwpng_png_image*)mainprog_ptr, &png_ptr, &info_ptr, mainprog_ptr->fast_compression);
if (retval) return retval;
struct rwpng_write_state write_state;
write_state = (struct rwpng_write_state){
.outfile = outfile,
.maximum_file_size = mainprog_ptr->maximum_file_size,
.retval = SUCCESS,
};
png_set_write_fn(png_ptr, &write_state, user_write_data, user_flush_data);
// Palette images generally don't gain anything from filtering
png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_FILTER_VALUE_NONE);
rwpng_set_gamma(info_ptr, png_ptr, mainprog_ptr->gamma, mainprog_ptr->output_color);
/* set the image parameters appropriately */
int sample_depth;
#if PNG_LIBPNG_VER > 10400 /* old libpng corrupts files with low depth */
if (mainprog_ptr->num_palette <= 2)
sample_depth = 1;
else if (mainprog_ptr->num_palette <= 4)
sample_depth = 2;
else if (mainprog_ptr->num_palette <= 16)
sample_depth = 4;
else
#endif
sample_depth = 8;
struct rwpng_chunk *chunk = mainprog_ptr->chunks;
mainprog_ptr->metadata_size = 0;
int chunk_num=0;
while(chunk) {
png_unknown_chunk pngchunk = {
.size = chunk->size,
.data = chunk->data,
.location = chunk->location,
};
memcpy(pngchunk.name, chunk->name, 5);
png_set_unknown_chunks(png_ptr, info_ptr, &pngchunk, 1);
#if defined(PNG_HAVE_IHDR) && PNG_LIBPNG_VER < 10600
png_set_unknown_chunk_location(png_ptr, info_ptr, chunk_num, pngchunk.location ? pngchunk.location : PNG_HAVE_IHDR);
#endif
mainprog_ptr->metadata_size += chunk->size + 12;
chunk = chunk->next;
chunk_num++;
}
png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
sample_depth, PNG_COLOR_TYPE_PALETTE,
0, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_BASE);
png_color palette[256];
png_byte trans[256];
unsigned int num_trans = 0;
for(unsigned int i = 0; i < mainprog_ptr->num_palette; i++) {
palette[i] = (png_color){
.red = mainprog_ptr->palette[i].r,
.green = mainprog_ptr->palette[i].g,
.blue = mainprog_ptr->palette[i].b,
};
trans[i] = mainprog_ptr->palette[i].a;
if (mainprog_ptr->palette[i].a < 255) {
num_trans = i+1;
}
}
png_set_PLTE(png_ptr, info_ptr, palette, mainprog_ptr->num_palette);
if (num_trans > 0) {
png_set_tRNS(png_ptr, info_ptr, trans, num_trans, NULL);
}
rwpng_write_end(&info_ptr, &png_ptr, mainprog_ptr->row_pointers);
if (SUCCESS == write_state.retval && write_state.maximum_file_size && write_state.bytes_written > write_state.maximum_file_size) {
return TOO_LARGE_FILE;
}
return write_state.retval;
}
pngquant_error rwpng_write_image24(FILE *outfile, const png24_image *mainprog_ptr)
{
png_structp png_ptr;
png_infop info_ptr;
pngquant_error retval = rwpng_write_image_init((rwpng_png_image*)mainprog_ptr, &png_ptr, &info_ptr, 0);
if (retval) return retval;
png_init_io(png_ptr, outfile);
rwpng_set_gamma(info_ptr, png_ptr, mainprog_ptr->gamma, mainprog_ptr->output_color);
png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
8, PNG_COLOR_TYPE_RGB_ALPHA,
0, PNG_COMPRESSION_TYPE_DEFAULT,
PNG_FILTER_TYPE_BASE);
png_bytepp row_pointers = rwpng_create_row_pointers(info_ptr, png_ptr, mainprog_ptr->rgba_data, mainprog_ptr->height, 0);
rwpng_write_end(&info_ptr, &png_ptr, row_pointers);
free(row_pointers);
return SUCCESS;
}
static void rwpng_error_handler(png_structp png_ptr, png_const_charp msg)
{
rwpng_png_image *mainprog_ptr;
/* This function, aside from the extra step of retrieving the "error
* pointer" (below) and the fact that it exists within the application
* rather than within libpng, is essentially identical to libpng's
* default error handler. The second point is critical: since both
* setjmp() and longjmp() are called from the same code, they are
* guaranteed to have compatible notions of how big a jmp_buf is,
* regardless of whether _BSD_SOURCE or anything else has (or has not)
* been defined. */
fprintf(stderr, " error: %s (libpng failed)\n", msg);
fflush(stderr);
mainprog_ptr = png_get_error_ptr(png_ptr);
if (mainprog_ptr == NULL) abort();
longjmp(mainprog_ptr->jmpbuf, 1);
}
pngquant-2.12.6/rwpng.h 0000664 0000000 0000000 00000004723 13602415555 0014761 0 ustar 00root root 0000000 0000000 /*
** PNG read/write functions
**
** © 1998-2000 by Greg Roelofs.
** © 2009-2017 by Kornel Lesiński.
**
** See COPYRIGHT file for license.
*/
#ifndef RWPNG_H
#define RWPNG_H
#include
#include
#include
#include
#ifndef USE_COCOA
#define USE_COCOA 0
#endif
typedef enum {
SUCCESS = 0,
MISSING_ARGUMENT = 1,
READ_ERROR = 2,
INVALID_ARGUMENT = 4,
NOT_OVERWRITING_ERROR = 15,
CANT_WRITE_ERROR = 16,
OUT_OF_MEMORY_ERROR = 17,
WRONG_ARCHITECTURE = 18, // Missing SSE
PNG_OUT_OF_MEMORY_ERROR = 24,
LIBPNG_FATAL_ERROR = 25,
WRONG_INPUT_COLOR_TYPE = 26,
LIBPNG_INIT_ERROR = 35,
TOO_LARGE_FILE = 98,
TOO_LOW_QUALITY = 99,
} pngquant_error;
typedef struct rwpng_rgba {
unsigned char r,g,b,a;
} rwpng_rgba;
struct rwpng_chunk {
struct rwpng_chunk *next;
unsigned char *data;
size_t size;
unsigned char name[5];
unsigned char location;
};
typedef enum {
RWPNG_NONE,
RWPNG_SRGB, // sRGB chunk
RWPNG_ICCP, // used ICC profile
RWPNG_ICCP_WARN_GRAY, // ignore and warn about GRAY ICC profile
RWPNG_GAMA_CHRM, // used gAMA and cHRM
RWPNG_GAMA_ONLY, // used gAMA only (i.e. not sRGB)
RWPNG_COCOA, // Colors handled by Cocoa reader
} rwpng_color_transform;
typedef struct {
jmp_buf jmpbuf;
uint32_t width;
uint32_t height;
size_t file_size;
double gamma;
unsigned char **row_pointers;
unsigned char *rgba_data;
struct rwpng_chunk *chunks;
rwpng_color_transform input_color;
rwpng_color_transform output_color;
} png24_image;
typedef struct {
jmp_buf jmpbuf;
uint32_t width;
uint32_t height;
size_t maximum_file_size;
size_t metadata_size;
double gamma;
unsigned char **row_pointers;
unsigned char *indexed_data;
struct rwpng_chunk *chunks;
unsigned int num_palette;
rwpng_rgba palette[256];
rwpng_color_transform output_color;
char fast_compression;
} png8_image;
typedef union {
jmp_buf jmpbuf;
png24_image png24;
png8_image png8;
} rwpng_png_image;
/* prototypes for public functions in rwpng.c */
void rwpng_version_info(FILE *fp);
pngquant_error rwpng_read_image24(FILE *infile, png24_image *mainprog_ptr, int strip, int verbose);
pngquant_error rwpng_write_image8(FILE *outfile, png8_image *mainprog_ptr);
pngquant_error rwpng_write_image24(FILE *outfile, const png24_image *mainprog_ptr);
void rwpng_free_image24(png24_image *);
void rwpng_free_image8(png8_image *);
#endif
pngquant-2.12.6/snapcraft.yaml 0000664 0000000 0000000 00000001171 13602415555 0016312 0 ustar 00root root 0000000 0000000 name: pngquant
version: 2.12.6
summary: pngquant
description: |
Lossy PNG compressor — pngquant command based
on libimagequant library https://pngquant.org
base: core18
confinement: strict
apps:
pngquant:
command: pngquant
plugs:
- home
parts:
pngquant:
source-type: git
source: https://github.com/kornelski/pngquant.git
source-tag: 2.12.6
plugin: autotools
configflags:
- --with-openmp
build-packages:
- gcc
- make
- libpng-dev
- zlib1g-dev
- liblcms2-dev
stage-packages:
- libgomp1
- libpng16-16
- zlib1g
- liblcms2-2
pngquant-2.12.6/test/ 0000775 0000000 0000000 00000000000 13602415555 0014424 5 ustar 00root root 0000000 0000000 pngquant-2.12.6/test/img/ 0000775 0000000 0000000 00000000000 13602415555 0015200 5 ustar 00root root 0000000 0000000 pngquant-2.12.6/test/img/metadata.png 0000664 0000000 0000000 00000003007 13602415555 0017466 0 ustar 00root root 0000000 0000000 PNG
IHDR r
$ gAMA a
iCCPICC Profile 8U]hU>sg#$Sl4t?
%
V46nI6"dΘ83OEP|1Ŀ (>/
% (>P苦;3ie|{g蹪X-2s=+WQ+]L6Ow[C{_F qbUvz?Zb1@/zcs>~if,ӈUSjF1_Mjbuݠpamhmçϙ>a\+5%QKFkm}ۖ?ޚD\!~6,-7SثŜvķ5Z;[rmS5{yDyH}r9|-ăFAJjI.[/]mK7KRDrYQO-Q||6
(0
MXd(@h2_f<:_δ*d>e\c?~,7?& ك^2Iq2"y