Update pngquant (2.8.0)
parent
f4f6cc7285
commit
4c0341602d
|
@ -1,7 +1,37 @@
|
|||
version 2.8
|
||||
-----------
|
||||
- libimagequant is a separate project
|
||||
|
||||
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
|
||||
-----------
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
# 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/
|
|
@ -1,5 +1,8 @@
|
|||
To build pngquant from source on Mac OS X and most Linux distributions,
|
||||
simply run:
|
||||
To get the code:
|
||||
|
||||
$ git clone --recursive https://github.com/pornel/pngquant.git
|
||||
|
||||
To build pngquant from source on macOS and most Linux distributions, run:
|
||||
|
||||
$ make
|
||||
|
||||
|
|
|
@ -1,3 +1,634 @@
|
|||
|
||||
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.
|
||||
|
||||
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
pngquant © 2009-2016 by Kornel Lesiński.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
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.
|
||||
|
||||
|
@ -30,7 +661,6 @@ pngquant.c:
|
|||
pngquant.c and rwpng.c/h:
|
||||
|
||||
© 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
|
||||
© 2009-2014 by Kornel Lesiński.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
-include config.mk
|
||||
|
||||
BIN ?= pngquant
|
||||
BINPREFIX = $(PREFIX)/bin
|
||||
BINPREFIX ?= $(DESTDIR)$(PREFIX)/bin
|
||||
MANPREFIX ?= $(DESTDIR)$(PREFIX)/share/man
|
||||
|
||||
OBJS = pngquant.o rwpng.o
|
||||
COCOA_OBJS = rwpng_cocoa.o
|
||||
|
@ -11,29 +12,50 @@ OBJS += $(COCOA_OBJS)
|
|||
endif
|
||||
|
||||
STATICLIB = lib/libimagequant.a
|
||||
SHAREDLIB = lib/libimagequant.so
|
||||
|
||||
DISTFILES = *.[chm] pngquant.1 Makefile configure README.md INSTALL CHANGELOG COPYRIGHT
|
||||
TARNAME = pngquant-$(VERSION)
|
||||
TARFILE = $(TARNAME)-src.tar.bz2
|
||||
TARFILE = $(TARNAME)-src.tar.gz
|
||||
|
||||
LIBDISTFILES = lib/*.[ch] lib/COPYRIGHT lib/MANUAL.md lib/configure lib/Makefile
|
||||
LIBDISTFILES = lib/*.[ch] lib/COPYRIGHT lib/README.md lib/configure lib/Makefile
|
||||
|
||||
DLL=libimagequant.dll
|
||||
DLLIMP=libimagequant_dll.a
|
||||
DLLDEF=libimagequant_dll.def
|
||||
TESTBIN = test/test
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(STATICLIB):: config.mk
|
||||
staticlib: lib/libimagequant.h
|
||||
$(MAKE) -C lib static
|
||||
|
||||
$(STATICLIB): config.mk staticlib
|
||||
|
||||
sharedlib: lib/libimagequant.h
|
||||
$(MAKE) -C lib shared
|
||||
|
||||
$(SHAREDLIB): config.mk sharedlib
|
||||
|
||||
$(OBJS): $(wildcard *.h) config.mk
|
||||
|
||||
rwpng_cocoa.o: rwpng_cocoa.m
|
||||
$(CC) -Wno-enum-conversion -c $(CFLAGS) -o $@ $< || clang -Wno-enum-conversion -c -O3 -o $@ $<
|
||||
$(CC) -Wno-enum-conversion -c $(CFLAGS) -o $@ $< &> /dev/null || clang -Wno-enum-conversion -c -O3 $(CFLAGS) -o $@ $<
|
||||
|
||||
$(BIN): $(STATICLIB) $(OBJS)
|
||||
$(CC) $(OBJS) $(LDFLAGS) -o $@
|
||||
$(BIN): $(OBJS) $(STATICLIB)
|
||||
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
$(TESTBIN): test/test.o $(STATICLIB)
|
||||
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $@
|
||||
|
||||
test: $(BIN) $(TESTBIN)
|
||||
./test/test.sh ./test $(BIN) $(TESTBIN)
|
||||
|
||||
bin.shared: $(OBJS) $(SHAREDLIB)
|
||||
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(BIN)
|
||||
|
||||
testbin.shared: test/test.o $(SHAREDLIB)
|
||||
$(CC) $^ $(CFLAGS) $(LDFLAGS) -o $(TESTBIN)
|
||||
|
||||
test.shared: bin.shared testbin.shared
|
||||
./test/test.sh ./test $(BIN) $(TESTBIN)
|
||||
|
||||
dist: $(TARFILE)
|
||||
|
||||
|
@ -42,26 +64,35 @@ $(TARFILE): $(DISTFILES)
|
|||
mkdir -p $(TARNAME)/lib
|
||||
cp $(DISTFILES) $(TARNAME)
|
||||
cp $(LIBDISTFILES) $(TARNAME)/lib
|
||||
tar -cjf $(TARFILE) --numeric-owner --exclude='._*' $(TARNAME)
|
||||
tar -czf $(TARFILE) --numeric-owner --exclude='._*' $(TARNAME)
|
||||
rm -rf $(TARNAME)
|
||||
-shasum $(TARFILE)
|
||||
|
||||
install: $(BIN)
|
||||
install -m 0755 -p $(BIN) $(BINPREFIX)/$(BIN)
|
||||
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 '$(BINPREFIX)/$(BIN)'
|
||||
rm -f '$(MANPREFIX)/man1/$(BIN).1'
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) $(OBJS) $(COCOA_OBJS) $(STATICLIB) $(TARFILE)
|
||||
$(MAKE) -C lib clean
|
||||
rm -f '$(BIN)' $(OBJS) $(COCOA_OBJS) $(STATICLIB) $(TARFILE)
|
||||
|
||||
distclean: clean
|
||||
rm -f config.mk
|
||||
$(MAKE) -C lib distclean
|
||||
rm -f config.mk pngquant-*-src.tar.gz
|
||||
|
||||
config.mk: lib/libimagequant.h
|
||||
ifeq ($(filter %clean %distclean, $(MAKECMDGOALS)), )
|
||||
config.mk:
|
||||
./configure
|
||||
endif
|
||||
|
||||
.PHONY: all clean dist distclean dll install uninstall
|
||||
lib/libimagequant.h:
|
||||
git submodule init && git submodule update
|
||||
|
||||
.PHONY: all clean dist distclean dll install uninstall test staticlib
|
||||
.DELETE_ON_ERROR:
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
# pngquant 2
|
||||
|
||||
This is the official `pngquant` and `libimagequant`.
|
||||
[pngquant](https://pngquant.org) converts 24/32-bit RGBA PNGs to 8-bit palette with *alpha channel preserved*.
|
||||
Such images are fully standards-compliant and are supported by all web browsers.
|
||||
|
||||
[pngquant](http://pngquant.org) converts 24/32-bit RGBA PNGs to 8-bit palette with *alpha channel preserved*.
|
||||
Such images are compatible with all modern browsers, and a special compatibility setting exists which helps transparency degrade well in Internet Explorer 6.
|
||||
Quantized files are often 60-80% smaller than their 24/32-bit versions.
|
||||
|
||||
Quantized files are often 40-70% smaller than their 24/32-bit version.
|
||||
|
||||
This utility works on Linux, Mac OS X and Windows.
|
||||
This utility works on Linux, Mac OS X and Windows. [This](https://github.com/pornel/pngquant) is the official `pngquant` repository.
|
||||
|
||||
## 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) or [ImageOptim](http://imageoptim.pornel.net).
|
||||
To further reduce file size, try [optipng](http://optipng.sourceforge.net), [ImageOptim](https://imageoptim.com), or [zopflipng](https://github.com/google/zopfli).
|
||||
|
||||
## Improvements since 1.0
|
||||
|
||||
|
@ -24,24 +22,15 @@ Generated files are both smaller and look much better.
|
|||
|
||||
- more accurate remapping of semitransparent colors
|
||||
- special dithering algorithm that does not add noise in well-quantized areas of the image
|
||||
- uses variance instead of popularity for box selection (improvement suggested in the original median cut paper)
|
||||
- feedback loop that repeats median cut for poorly quantized colors
|
||||
- additional colormap improvement using Voronoi iteration
|
||||
- supports much larger number of colors in input images without degradation of quality
|
||||
- gamma correction (output is always generated with gamma 2.2 for web compatibility)
|
||||
|
||||
* More flexible commandline usage
|
||||
|
||||
- number of colors defaults to 256
|
||||
- long options and standard switches like `--` and `-` are allowed
|
||||
- gamma correction and optional color profile support (output is always in gamma 2.2 for web compatibility)
|
||||
|
||||
* Refactored and modernised code
|
||||
|
||||
- C99 with no workarounds for old systems
|
||||
- floating-point math used throughout
|
||||
- Intel SSE optimisations
|
||||
- quantization [moved to standalone libimagequant](https://github.com/ImageOptim/libimagequant)
|
||||
- C99 with no workarounds for legacy systems or compilers ([apart from Visual Studio](https://github.com/pornel/pngquant/tree/msvc))
|
||||
- Intel SSE optimisations and floating-point math used throughout
|
||||
- multicore support via OpenMP
|
||||
- quantization moved to standalone libimagequant
|
||||
|
||||
## Options
|
||||
|
||||
|
@ -57,6 +46,10 @@ See `pngquant -h` for full list.
|
|||
|
||||
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.
|
||||
|
@ -71,11 +64,11 @@ Disables Floyd-Steinberg dithering.
|
|||
|
||||
### `--floyd=0.5`
|
||||
|
||||
Controls level of dithering (0 = none, 1 = full).
|
||||
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).
|
||||
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).
|
||||
|
||||
### `--version`
|
||||
|
||||
|
@ -91,3 +84,10 @@ Stops processing of arguments. This allows use of file names that start with `-`
|
|||
|
||||
pngquant $OPTIONS -- "$FILE"
|
||||
|
||||
## License
|
||||
|
||||
pngquant is dual-licensed:
|
||||
|
||||
* GPL v3 or later, and additional copyright notice must be kept for older parts of the code. See [COPYRIGHT](https://github.com/pornel/pngquant/blob/master/COPYRIGHT) for details.
|
||||
|
||||
* For use in non-GPL software (e.g. closed-source or App Store distribution) please ask kornel@pngquant.org for a commercial license.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
URL: https://github.com/pornel/pngquant/archive/2.3.0.tar.gz
|
||||
Version: 2.3.0
|
||||
License: BSD
|
||||
URL: https://github.com/pornel/pngquant/archive/2.8.0.tar.gz
|
||||
Version: 2.8.0
|
||||
License: GPLv3
|
||||
License File: LICENSE
|
||||
|
||||
Description:
|
||||
|
|
|
@ -2,11 +2,14 @@
|
|||
|
||||
CONFIG="config.mk"
|
||||
PREFIX="/usr/local"
|
||||
VERSION=$(grep "define PNGQUANT_VERSION" pngquant.c | grep -Eo "[12]\.[0-9.]+")
|
||||
|
||||
test -f lib/libimagequant.h || { git submodule init && git submodule update; }
|
||||
VERSION=$(grep LIQ_VERSION_STRING lib/libimagequant.h | grep -Eo "2\.[0-9.]+")
|
||||
|
||||
DEBUG=
|
||||
SSE=auto
|
||||
OPENMP=
|
||||
LIBPNG_DIR=.
|
||||
if [[ "$OSTYPE" =~ "darwin" ]]; then
|
||||
COCOA_READER=auto
|
||||
LCMS2=0
|
||||
|
@ -28,18 +31,19 @@ for i in "$@"; do
|
|||
case $i in
|
||||
--help)
|
||||
echo
|
||||
help "--prefix= installation directory [$PREFIX]"
|
||||
help "--extra-cflags= append to CFLAGS"
|
||||
help "--extra-ldflags= append to LDFLAGS"
|
||||
help "--prefix=<dir> installation directory [$PREFIX]"
|
||||
help "--extra-cflags=<flags> append to CFLAGS"
|
||||
help "--extra-ldflags=<flags> append to LDFLAGS"
|
||||
echo
|
||||
help "--enable-debug"
|
||||
help "--enable-sse/--disable-sse enable/disable SSE instructions"
|
||||
echo
|
||||
help "--with-openmp compile with multicore support"
|
||||
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=<dir> search for libpng in directory"
|
||||
echo
|
||||
help "CC=<compiler> use given compiler command"
|
||||
help "CFLAGS=<flags> pass options to the compiler"
|
||||
|
@ -69,6 +73,9 @@ fi
|
|||
--with-openmp)
|
||||
OPENMP=1
|
||||
;;
|
||||
--with-openmp=static)
|
||||
OPENMP=static
|
||||
;;
|
||||
--with-lcms2)
|
||||
LCMS2=1
|
||||
COCOA_READER=0
|
||||
|
@ -83,6 +90,9 @@ fi
|
|||
--without-cocoa)
|
||||
COCOA_READER=0
|
||||
;;
|
||||
--with-libpng=*)
|
||||
LIBPNG_DIR=${i#*=}
|
||||
;;
|
||||
--prefix=*)
|
||||
PREFIX=${i#*=}
|
||||
;;
|
||||
|
@ -94,8 +104,7 @@ fi
|
|||
EXTRA_LDFLAGS="$EXTRA_LDFLAGS ${i#*=}"
|
||||
;;
|
||||
*)
|
||||
echo "error: unknown switch ${i%%=*} (see $0 --help for the list)"
|
||||
exit 1
|
||||
echo "warning: unknown switch ${i%%=*} (see $0 --help for the list)"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
@ -122,23 +131,23 @@ status() {
|
|||
# Append to CFLAGS if compiler supports flag, with optional prerequisite.
|
||||
# Fails on errors and warnings.
|
||||
conditional_cflags() {
|
||||
if [ -z "$("$CC" -xc -S -o /dev/null $2 $1 <(echo) 2>&1)" ]; then
|
||||
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 -type d -name "$2" -print -quit 2> /dev/null)
|
||||
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" -type f -name "$2" -print -quit 2> /dev/null)
|
||||
echo $(find "$1" -not -path '*/.*/*' -type f -name "$2" -print -quit 2> /dev/null)
|
||||
}
|
||||
|
||||
find_pkgconfig() {
|
||||
LIBNAME=$1
|
||||
local LIBNAME=$1
|
||||
if pkg-config --exists "$LIBNAME" &> /dev/null; then
|
||||
cflags "$(pkg-config --cflags "$LIBNAME")"
|
||||
lflags "$(pkg-config --libs "$LIBNAME")"
|
||||
|
@ -149,13 +158,13 @@ find_pkgconfig() {
|
|||
}
|
||||
|
||||
find_static() {
|
||||
LIBNAME=$1
|
||||
HEADERPATTERN=$2
|
||||
STATICPATTERN=$3
|
||||
local LIBNAME=$1
|
||||
local HEADERPATTERN=$2
|
||||
local STATICPATTERN=$3
|
||||
|
||||
HPATH=$(find_h . "$HEADERPATTERN")
|
||||
local HPATH=$(find_h . "$HEADERPATTERN")
|
||||
if [ -n "$HPATH" ]; then
|
||||
APATH=$(find_f . "$STATICPATTERN")
|
||||
local APATH=$(find_f . "$STATICPATTERN")
|
||||
if [ -n "$APATH" ]; then
|
||||
cflags "-I${HPATH%/*}"
|
||||
lflags "${APATH}"
|
||||
|
@ -166,12 +175,32 @@ find_static() {
|
|||
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
|
||||
cflags "-I${HPATH%/*}"
|
||||
lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
|
||||
status "$LIBNAME" "shared ... $SOPATH"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
find_library() {
|
||||
LIBNAME=$1
|
||||
DYNAMICLIBNAME=$2
|
||||
HEADERPATTERN=$3
|
||||
STATICPATTERN=$4
|
||||
DYNAMICPATTERN=$5
|
||||
local LIBNAME=$1
|
||||
local DYNAMICLIBNAME=$2
|
||||
local HEADERPATTERN=$3
|
||||
local STATICPATTERN=$4
|
||||
local DYNAMICPATTERN=$5
|
||||
|
||||
# try static in current directory first
|
||||
if find_static "$LIBNAME" "$HEADERPATTERN" "$STATICPATTERN"; then
|
||||
|
@ -185,16 +214,9 @@ find_library() {
|
|||
|
||||
for i in "${DIRS[@]}"; do
|
||||
DIR=($i)
|
||||
HPATH=$(find_h "${DIR[0]}" "$HEADERPATTERN")
|
||||
if [ -n "$HPATH" ]; then
|
||||
SOPATH=$(find_f "${DIR[1]}" "$DYNAMICPATTERN")
|
||||
if [ -n "$SOPATH" ]; then
|
||||
cflags "-I${HPATH%/*}"
|
||||
lflags "-L${SOPATH%/*} -l$DYNAMICLIBNAME"
|
||||
status "$LIBNAME" "shared ... $SOPATH"
|
||||
if find_dynamic "$LIBNAME" "$HEADERPATTERN" "$DYNAMICPATTERN" "${DIR[0]}" "${DIR[1]}"; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
@ -221,23 +243,22 @@ error() {
|
|||
echo
|
||||
|
||||
# basic check
|
||||
if ! "$CC" -xc -std=c99 <(echo "int main(){}") -o /dev/null &> /dev/null; then
|
||||
error "Compiler" "$CC is no C compiler"
|
||||
if ! echo "int main(){}" | "$CC" -xc -std=c99 -o /dev/null - > /dev/null; then
|
||||
error "Compiler" "$CC failed to compile anything (make sure it's installed and supports C99)"
|
||||
fi
|
||||
|
||||
status "Compiler" "$CC"
|
||||
|
||||
# init flags
|
||||
CFLAGS=${CFLAGS:--O3 -fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
|
||||
CFLAGS=${CFLAGS:--fno-math-errno -funroll-loops -fomit-frame-pointer -Wall}
|
||||
cflags "-std=c99 -I."
|
||||
lflags "-lm lib/libimagequant.a"
|
||||
|
||||
# DEBUG
|
||||
if [ -z "$DEBUG" ]; then
|
||||
cflags "-DNDEBUG"
|
||||
cflags "-O3 -DNDEBUG"
|
||||
status "Debug" "no"
|
||||
else
|
||||
cflags "-g"
|
||||
cflags "-O1 -g"
|
||||
status "Debug" "yes"
|
||||
fi
|
||||
|
||||
|
@ -264,12 +285,16 @@ fi
|
|||
|
||||
# OpenMP
|
||||
if [ -n "$OPENMP" ]; then
|
||||
if [[ "$("$CC" -xc -E -fopenmp <(echo -e \
|
||||
"#ifdef _OPENMP
|
||||
if [ "static" = "$OPENMP" ]; then
|
||||
OPENMPFLAGS="-static-libgcc -Bstatic -fopenmp -Bdynamic"
|
||||
else
|
||||
OPENMPFLAGS="-fopenmp"
|
||||
fi
|
||||
if [[ "$("$CC" -xc -E $OPENMPFLAGS <(echo "#ifdef _OPENMP
|
||||
#include <omp.h>
|
||||
#endif") 2>&1)" =~ "omp_get_thread_num" ]]; then
|
||||
cflags "-fopenmp"
|
||||
lflags "-fopenmp"
|
||||
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)"
|
||||
|
@ -286,7 +311,7 @@ if [[ "$OSTYPE" =~ "darwin" ]]; then
|
|||
cflags "-mmacosx-version-min=10.6"
|
||||
lflags "-mmacosx-version-min=10.6"
|
||||
|
||||
if [ "$COCOA_READER" != 0 ]; then
|
||||
if [ "$COCOA_READER" != 0 ] && "$CC" 2>/dev/null 1>/dev/null -xc -E <(echo "#import <Cocoa/Cocoa.h>"); then
|
||||
COCOA_READER=1
|
||||
cflags "-DUSE_COCOA=1"
|
||||
lflags "-framework Cocoa"
|
||||
|
@ -296,37 +321,63 @@ if [[ "$OSTYPE" =~ "darwin" ]]; then
|
|||
fi
|
||||
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
|
||||
|
||||
DIRS+=("/usr/local/include /usr/local/lib"
|
||||
"/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")
|
||||
else
|
||||
SOLIBSUFFIX=so
|
||||
fi
|
||||
|
||||
# pairs of possible *.h and lib*.so locations
|
||||
DIRS=("/usr/local/include /usr/local/lib"
|
||||
"/usr/include /usr/lib")
|
||||
|
||||
# libpng
|
||||
SUCCESS=0
|
||||
# try static in current directory first
|
||||
PNGH=$(find_h . "png.h")
|
||||
# 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${PNGH_MAJMIN}.a")
|
||||
LIBPNGA=$(find_f "$LIBPNG_DIR" "libpng${PNGH_MAJMIN}.a")
|
||||
if [ -n "$LIBPNGA" ]; then
|
||||
cflags "-I${PNGH%/*}"
|
||||
lflags "${LIBPNGA}"
|
||||
status "libpng" "static (${PNGH_STRING})"
|
||||
SUCCESS=1
|
||||
HAS_LIBPNG=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
# try shared
|
||||
if [ "$SUCCESS" -eq 0 ]; then
|
||||
if [ "$HAS_LIBPNG" -eq 0 ]; then
|
||||
if find_pkgconfig libpng; then
|
||||
SUCCESS=1
|
||||
HAS_LIBPNG=1
|
||||
else
|
||||
for i in "${DIRS[@]}"; do
|
||||
DIR=($i)
|
||||
|
@ -340,7 +391,7 @@ if [ "$SUCCESS" -eq 0 ]; then
|
|||
cflags "-I${PNGH%/*}"
|
||||
lflags "-L${LIBPNGSO%/*} -lpng${PNGH_MAJMIN}"
|
||||
status "libpng" "shared (${PNGH_STRING})"
|
||||
SUCCESS=1
|
||||
HAS_LIBPNG=1
|
||||
break
|
||||
fi
|
||||
fi
|
||||
|
@ -348,13 +399,13 @@ if [ "$SUCCESS" -eq 0 ]; then
|
|||
done
|
||||
fi
|
||||
fi
|
||||
if [ "$SUCCESS" -eq 0 ]; then
|
||||
if [ "$HAS_LIBPNG" -eq 0 ]; then
|
||||
if [[ "$OSTYPE" =~ "darwin" ]]; then
|
||||
LIBPNGCOMMAND='`brew install libpng`'
|
||||
LIBPNG_CMD='`brew install libpng`'
|
||||
else
|
||||
LIBPNGCOMMAND='`apt-get install libpng-dev` or `yum install libpng-devel`'
|
||||
LIBPNG_CMD='`apt-get install libpng16-dev` or `apt-get install libpng-dev` or `yum install libpng-devel`'
|
||||
fi
|
||||
error "libpng" "not found (try: $LIBPNGCOMMAND)"
|
||||
error "libpng" "not found (try: $LIBPNG_CMD)"
|
||||
fi
|
||||
|
||||
# zlib
|
||||
|
@ -414,6 +465,7 @@ CC = $CC
|
|||
CFLAGS = $CFLAGS
|
||||
LDFLAGS = $LDFLAGS
|
||||
COCOA_READER = $COCOA_READER
|
||||
SOLIBSUFFIX = $SOLIBSUFFIX
|
||||
" > "$CONFIG"
|
||||
|
||||
# Configure static library the same way
|
||||
|
|
|
@ -77,13 +77,11 @@ quality. If conversion results in quality below the
|
|||
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
|
||||
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.
|
||||
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).
|
||||
.It Fl Fl iebug
|
||||
Workaround for Internet Explorer 6, which only displays fully opaque pixels.
|
||||
.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
|
||||
|
@ -126,4 +124,4 @@ is developed by Kornel Lesinski
|
|||
based on code by Greg Roelofs
|
||||
.Aq Mt newt@pobox.com .
|
||||
.Pp
|
||||
.Lk http://pngquant.org "pngquant homepage" .
|
||||
.Lk https://pngquant.org "pngquant homepage" .
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
** - - - -
|
||||
**
|
||||
** © 1997-2002 by Greg Roelofs; based on an idea by Stefan Schneider.
|
||||
** © 2009-2014 by Kornel Lesiński.
|
||||
** © 2009-2015 by Kornel Lesiński.
|
||||
**
|
||||
** All rights reserved.
|
||||
**
|
||||
|
@ -39,26 +39,28 @@
|
|||
**
|
||||
*/
|
||||
|
||||
#define PNGQUANT_VERSION "2.3.0 (July 2014)"
|
||||
#define PNGQUANT_VERSION LIQ_VERSION_STRING " (November 2016)"
|
||||
|
||||
#define PNGQUANT_USAGE "\
|
||||
usage: pngquant [options] [ncolors] [pngfile [pngfile ...]]\n\n\
|
||||
usage: pngquant [options] [ncolors] -- pngfile [pngfile ...]\n\
|
||||
pngquant [options] [ncolors] - >stdout <stdin\n\n\
|
||||
options:\n\
|
||||
--force overwrite existing output files (synonym: -f)\n\
|
||||
--nofs disable Floyd-Steinberg dithering\n\
|
||||
--ext new.png set custom suffix/extension for output filename\n\
|
||||
--output file output path, only if one input file is specified (synonym: -o)\n\
|
||||
--skip-if-larger only save converted files if they're smaller than original\n\
|
||||
--output file destination file path to use instead of --ext (synonym: -o)\n\
|
||||
--ext new.png set custom suffix/extension for output filenames\n\
|
||||
--quality min-max don't save below min, use fewer colors below max (0-100)\n\
|
||||
--speed N speed/quality trade-off. 1=slow, 3=default, 11=fast & rough\n\
|
||||
--quality min-max don't save below min, use less colors below max (0-100)\n\
|
||||
--nofs disable Floyd-Steinberg dithering\n\
|
||||
--posterize N output lower-precision color (e.g. for ARGB4444 output)\n\
|
||||
--verbose print status messages (synonym: -v)\n\
|
||||
\n\
|
||||
Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette\n\
|
||||
PNGs using Floyd-Steinberg diffusion dithering (unless disabled).\n\
|
||||
Quantizes one or more 32-bit RGBA PNGs to 8-bit (or smaller) RGBA-palette.\n\
|
||||
The output filename is the same as the input name except that\n\
|
||||
it ends in \"-fs8.png\", \"-or8.png\" or your custom extension (unless the\n\
|
||||
input is stdin, in which case the quantized image will go to stdout).\n\
|
||||
The default behavior if the output file exists is to skip the conversion;\n\
|
||||
use --force to overwrite.\n"
|
||||
use --force to overwrite. See man page for full list of options.\n"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -67,6 +69,8 @@ use --force to overwrite.\n"
|
|||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
|
||||
extern char *optarg;
|
||||
extern int optind, opterr;
|
||||
|
@ -92,12 +96,12 @@ struct pngquant_options {
|
|||
liq_log_callback_function *log_callback;
|
||||
void *log_callback_user_info;
|
||||
float floyd;
|
||||
bool using_stdin, force, fast_compression, ie_mode,
|
||||
bool using_stdin, using_stdout, force, fast_compression, ie_mode,
|
||||
min_quality_limit, skip_if_larger,
|
||||
verbose;
|
||||
};
|
||||
|
||||
static pngquant_error prepare_output_image(liq_result *result, liq_image *input_image, png8_image *output_image);
|
||||
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 verbose);
|
||||
static pngquant_error write_image(png8_image *output_image, png24_image *output_image24, const char *outname, struct pngquant_options *options);
|
||||
|
@ -159,12 +163,12 @@ static void log_callback_buferred(const liq_attr *attr, const char *msg, void* c
|
|||
|
||||
static void print_full_version(FILE *fd)
|
||||
{
|
||||
fprintf(fd, "pngquant, %s, by Greg Roelofs, Kornel Lesinski.\n"
|
||||
fprintf(fd, "pngquant, %s, by Kornel Lesinski, Greg Roelofs.\n"
|
||||
#ifndef NDEBUG
|
||||
" DEBUG (slow) version.\n" /* NDEBUG disables assert() */
|
||||
" WARNING: this is a DEBUG (slow) version.\n" /* NDEBUG disables assert() */
|
||||
#endif
|
||||
#if USE_SSE
|
||||
" Compiled with SSE instructions.\n"
|
||||
#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"
|
||||
|
@ -308,7 +312,7 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
|
||||
case arg_floyd:
|
||||
options.floyd = optarg ? atof(optarg) : 1.0;
|
||||
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;
|
||||
|
@ -330,7 +334,7 @@ int main(int argc, char *argv[])
|
|||
case arg_iebug:
|
||||
// opacities above 238 will be rounded up to 255, because IE6 truncates <255 to 0.
|
||||
liq_set_min_opacity(options.liq, 238);
|
||||
options.ie_mode = true;
|
||||
fputs(" warning: the workaround for IE6 is deprecated\n", stderr);
|
||||
break;
|
||||
|
||||
case arg_transbug:
|
||||
|
@ -375,10 +379,20 @@ int main(int argc, char *argv[])
|
|||
case arg_map:
|
||||
{
|
||||
png24_image tmp = {};
|
||||
if (SUCCESS != read_image(options.liq, optarg, false, &tmp, &options.fixed_palette_image, false, false)) {
|
||||
fprintf(stderr, " error: Unable to load %s", optarg);
|
||||
if (SUCCESS != read_image(options.liq, optarg, false, &tmp, &options.fixed_palette_image, true, false)) {
|
||||
fprintf(stderr, " error: unable to load %s", optarg);
|
||||
return INVALID_ARGUMENT;
|
||||
}
|
||||
liq_result *tmp_quantize = liq_quantize_image(options.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", optarg);
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -402,11 +416,11 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (argn >= argc) {
|
||||
if (argn > 1) {
|
||||
fputs("No input files specified. See -h for help.\n", stderr);
|
||||
fputs("No input files specified.\n", stderr);
|
||||
} else {
|
||||
print_full_version(stderr);
|
||||
print_usage(stderr);
|
||||
}
|
||||
print_usage(stderr);
|
||||
return MISSING_ARGUMENT;
|
||||
}
|
||||
|
||||
|
@ -440,14 +454,10 @@ int main(int argc, char *argv[])
|
|||
|
||||
if (argn == argc || (argn == argc-1 && 0==strcmp(argv[argn],"-"))) {
|
||||
options.using_stdin = true;
|
||||
options.using_stdout = !output_file_path;
|
||||
argn = argc-1;
|
||||
}
|
||||
|
||||
if (options.using_stdin && output_file_path) {
|
||||
fputs("--output can't be mixed with stdin\n", stderr);
|
||||
return INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
const int num_files = argc-argn;
|
||||
|
||||
if (output_file_path && num_files != 1) {
|
||||
|
@ -478,8 +488,8 @@ int main(int argc, char *argv[])
|
|||
if (opts.log_callback && omp_get_num_threads() > 1 && num_files > 1) {
|
||||
liq_set_log_callback(opts.liq, log_callback_buferred, &buf);
|
||||
liq_set_log_flush_callback(opts.liq, log_callback_buferred_flush, &buf);
|
||||
options.log_callback = log_callback_buferred;
|
||||
options.log_callback_user_info = &buf;
|
||||
opts.log_callback = log_callback_buferred;
|
||||
opts.log_callback_user_info = &buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -488,17 +498,17 @@ int main(int argc, char *argv[])
|
|||
|
||||
const char *outname = output_file_path;
|
||||
char *outname_free = NULL;
|
||||
if (!options.using_stdin) {
|
||||
if (!opts.using_stdout) {
|
||||
if (!outname) {
|
||||
outname = outname_free = add_filename_extension(filename, newext);
|
||||
}
|
||||
if (!options.force && file_exists(outname)) {
|
||||
fprintf(stderr, " error: %s exists; not overwriting\n", outname);
|
||||
if (!opts.force && file_exists(outname)) {
|
||||
fprintf(stderr, " error: '%s' exists; not overwriting\n", outname);
|
||||
retval = NOT_OVERWRITING_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
if (SUCCESS == retval) {
|
||||
retval = pngquant_file(filename, outname, &opts);
|
||||
}
|
||||
|
||||
|
@ -547,40 +557,44 @@ pngquant_error pngquant_file(const char *filename, const char *outname, struct p
|
|||
|
||||
liq_image *input_image = NULL;
|
||||
png24_image input_image_rwpng = {};
|
||||
bool keep_input_pixels = options->skip_if_larger || (options->using_stdin && options->min_quality_limit); // original may need to be output to stdout
|
||||
if (!retval) {
|
||||
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(options->liq, filename, options->using_stdin, &input_image_rwpng, &input_image, keep_input_pixels, options->verbose);
|
||||
}
|
||||
|
||||
int quality_percent = 90; // quality on 0-100 scale, updated upon successful remap
|
||||
png8_image output_image = {};
|
||||
if (!retval) {
|
||||
if (SUCCESS == retval) {
|
||||
verbose_printf(options, " read %luKB file", (input_image_rwpng.file_size+1023UL)/1024UL);
|
||||
|
||||
#if USE_LCMS
|
||||
if (input_image_rwpng.lcms_status == ICCP) {
|
||||
if (RWPNG_ICCP == input_image_rwpng.input_color) {
|
||||
verbose_printf(options, " used embedded ICC profile to transform image to sRGB colorspace");
|
||||
} else if (input_image_rwpng.lcms_status == GAMA_CHRM) {
|
||||
} else if (RWPNG_GAMA_CHRM == input_image_rwpng.input_color) {
|
||||
verbose_printf(options, " used gAMA and cHRM chunks to transform image to sRGB colorspace");
|
||||
} else if (input_image_rwpng.lcms_status == ICCP_WARN_GRAY) {
|
||||
} else if (RWPNG_ICCP_WARN_GRAY == input_image_rwpng.input_color) {
|
||||
verbose_printf(options, " warning: ignored ICC profile in GRAY colorspace");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (input_image_rwpng.gamma != 0.45455) {
|
||||
verbose_printf(options, " corrected image from gamma %2.1f to sRGB gamma",
|
||||
} else if (RWPNG_COCOA == input_image_rwpng.input_color) {
|
||||
// No comment
|
||||
} else if (RWPNG_SRGB == input_image_rwpng.input_color) {
|
||||
verbose_printf(options, " passing sRGB tag from the input");
|
||||
} else if (input_image_rwpng.gamma != 0.45455) {
|
||||
verbose_printf(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_quantize_image(options->liq, options->fixed_palette_image ? options->fixed_palette_image : input_image);
|
||||
liq_result *remap;
|
||||
liq_error remap_error = liq_image_quantize(options->fixed_palette_image ? options->fixed_palette_image : input_image, options->liq, &remap);
|
||||
|
||||
if (remap) {
|
||||
liq_set_output_gamma(remap, 0.45455); // fixed gamma ~2.2 for the web. PNG can't store exact 1/2.2
|
||||
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, &output_image);
|
||||
if (!retval) {
|
||||
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;
|
||||
}
|
||||
|
@ -594,18 +608,22 @@ pngquant_error pngquant_file(const char *filename, const char *outname, struct p
|
|||
}
|
||||
}
|
||||
liq_result_destroy(remap);
|
||||
} else {
|
||||
} else if (LIQ_QUALITY_TOO_LOW == remap_error) {
|
||||
retval = TOO_LOW_QUALITY;
|
||||
} else {
|
||||
retval = INVALID_ARGUMENT; // dunno
|
||||
}
|
||||
}
|
||||
|
||||
if (!retval) {
|
||||
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 squared, because even greater savings are needed to justify big quality loss.
|
||||
double quality = quality_percent/100.0;
|
||||
output_image.maximum_file_size = input_image_rwpng.file_size * quality*quality;
|
||||
// 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;
|
||||
|
@ -617,18 +635,16 @@ pngquant_error pngquant_file(const char *filename, const char *outname, struct p
|
|||
}
|
||||
}
|
||||
|
||||
if (TOO_LARGE_FILE == retval || (TOO_LOW_QUALITY == retval && options->using_stdin)) {
|
||||
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
|
||||
if (keep_input_pixels) {
|
||||
pngquant_error write_retval = write_image(NULL, &input_image_rwpng, outname, options);
|
||||
if (write_retval) {
|
||||
retval = write_retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
liq_image_destroy(input_image);
|
||||
if (input_image) liq_image_destroy(input_image);
|
||||
rwpng_free_image24(&input_image_rwpng);
|
||||
rwpng_free_image8(&output_image);
|
||||
|
||||
|
@ -639,16 +655,10 @@ static void set_palette(liq_result *result, png8_image *output_image)
|
|||
{
|
||||
const liq_palette *palette = liq_get_palette(result);
|
||||
|
||||
// tRNS, etc.
|
||||
output_image->num_palette = palette->count;
|
||||
output_image->num_trans = 0;
|
||||
for(unsigned int i=0; i < palette->count; i++) {
|
||||
liq_color px = palette->entries[i];
|
||||
if (px.a < 255) {
|
||||
output_image->num_trans = i+1;
|
||||
}
|
||||
output_image->palette[i] = (png_color){.red=px.r, .green=px.g, .blue=px.b};
|
||||
output_image->trans[i] = px.a;
|
||||
output_image->palette[i] = (rwpng_rgba){.r=px.r, .g=px.g, .b=px.b, .a=px.a};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -674,10 +684,23 @@ static char *add_filename_extension(const char *filename, const char *newext)
|
|||
if (!outname) return NULL;
|
||||
|
||||
strncpy(outname, filename, x);
|
||||
if (strncmp(outname+x-4, ".png", 4) == 0 || strncmp(outname+x-4, ".PNG", 4) == 0)
|
||||
if (strncmp(outname+x-4, ".png", 4) == 0 || strncmp(outname+x-4, ".PNG", 4) == 0) {
|
||||
strcpy(outname+x-4, newext);
|
||||
else
|
||||
} 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;
|
||||
}
|
||||
|
@ -689,10 +712,32 @@ static void set_binary_mode(FILE *fp)
|
|||
#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__)
|
||||
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)
|
||||
{
|
||||
FILE *outfile;
|
||||
if (options->using_stdin) {
|
||||
char *tempname = NULL;
|
||||
|
||||
if (options->using_stdout) {
|
||||
set_binary_mode(stdout);
|
||||
outfile = stdout;
|
||||
|
||||
|
@ -702,23 +747,19 @@ static pngquant_error write_image(png8_image *output_image, png24_image *output_
|
|||
verbose_printf(options, " writing truecolor image to stdout");
|
||||
}
|
||||
} else {
|
||||
tempname = temp_filename(outname);
|
||||
if (!tempname) return OUT_OF_MEMORY_ERROR;
|
||||
|
||||
if ((outfile = fopen(outname, "wb")) == NULL) {
|
||||
fprintf(stderr, " error: cannot open %s for writing\n", outname);
|
||||
if ((outfile = fopen(tempname, "wb")) == NULL) {
|
||||
fprintf(stderr, " error: cannot open '%s' for writing\n", tempname);
|
||||
free(tempname);
|
||||
return CANT_WRITE_ERROR;
|
||||
}
|
||||
|
||||
const char *outfilename = strrchr(outname, '/');
|
||||
if (outfilename) {
|
||||
outfilename++;
|
||||
} else {
|
||||
outfilename = outname;
|
||||
}
|
||||
|
||||
if (output_image) {
|
||||
verbose_printf(options, " writing %d-color image as %s", output_image->num_palette, outfilename);
|
||||
verbose_printf(options, " writing %d-color image as %s", output_image->num_palette, filename_part(outname));
|
||||
} else {
|
||||
verbose_printf(options, " writing truecolor image as %s", outfilename);
|
||||
verbose_printf(options, " writing truecolor image as %s", filename_part(outname));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -732,12 +773,25 @@ static pngquant_error write_image(png8_image *output_image, png24_image *output_
|
|||
}
|
||||
}
|
||||
|
||||
if (retval && retval != TOO_LARGE_FILE) {
|
||||
fprintf(stderr, " error: failed writing image to %s\n", outname);
|
||||
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 (!options->using_stdin) {
|
||||
fclose(outfile);
|
||||
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;
|
||||
|
@ -766,7 +820,7 @@ static pngquant_error read_image(liq_attr *options, const char *filename, int us
|
|||
}
|
||||
|
||||
if (retval) {
|
||||
fprintf(stderr, " error: rwpng_read_image() error %d\n", retval);
|
||||
fprintf(stderr, " error: cannot decode image %s\n", using_stdin ? "from stdin" : filename_part(filename));
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -787,11 +841,12 @@ static pngquant_error read_image(liq_attr *options, const char *filename, int us
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
static pngquant_error prepare_output_image(liq_result *result, liq_image *input_image, png8_image *output_image)
|
||||
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
|
||||
|
@ -804,19 +859,13 @@ static pngquant_error prepare_output_image(liq_result *result, liq_image *input_
|
|||
return OUT_OF_MEMORY_ERROR;
|
||||
}
|
||||
|
||||
for(unsigned int row = 0; row < output_image->height; ++row) {
|
||||
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;
|
||||
output_image->num_trans = 0;
|
||||
for(unsigned int i=0; i < palette->count; i++) {
|
||||
if (palette->entries[i].a < 255) {
|
||||
output_image->num_trans = i+1;
|
||||
}
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
Name: pngquant
|
||||
Version: 1.8.3
|
||||
Version: 2.8.0
|
||||
Release: 1%{?dist}
|
||||
Summary: PNG quantization tool for reducing image file size
|
||||
License: BSD
|
||||
URL: http://pngquant.org
|
||||
Source0: https://github.com/pornel/improved-pngquant/tarball/%{version}
|
||||
# New code is under GPL, forked from old BSD-like
|
||||
License: GPLv3+ and BSD
|
||||
URL: https://pngquant.org
|
||||
Source0: https://github.com/pornel/pngquant/archive/%{version}.tar.gz
|
||||
BuildRequires: libpng-devel%{?_isa} >= 1.2.46-1
|
||||
BuildRequires: zlib-devel%{?_isa} >= 1.2.3-1
|
||||
BuildRequires: gcc%{?_isa} >= 4.2-1
|
||||
|
@ -12,24 +13,23 @@ Requires: libpng%{?_isa} >= 1.2.46-1
|
|||
Requires: zlib%{?isa} >= 1.2.3-1
|
||||
|
||||
%description
|
||||
pngquant converts 24/32-bit RGBA PNG images to 8-bit palette with
|
||||
alpha channel preserved. Such images are compatible with all modern web
|
||||
browsers and a compatibility setting is available to help transparency
|
||||
degrade well in Internet Explorer 6. Quantized files are often 40-70
|
||||
percent smaller than their 24/32-bit version. pngquant uses the
|
||||
median cut algorithm.
|
||||
|
||||
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 pornel-improved-pngquant-6f6e12c
|
||||
%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
|
||||
|
||||
|
||||
|
@ -42,6 +42,9 @@ install -Dpm0644 pngquant.1 %{buildroot}/%{_mandir}/man1/pngquant.1
|
|||
|
||||
%changelog
|
||||
|
||||
* Fri Sep 12 2014 Michael Dec <grepwood@sucs.org> 1.8.3-1
|
||||
- Update to latest upstream version and corrected the .spec
|
||||
|
||||
* Thu May 03 2012 Craig Barnes <cr@igbarn.es> - 1.7.2-1
|
||||
- Update to latest upstream version
|
||||
|
||||
|
@ -55,4 +58,3 @@ install -Dpm0644 pngquant.1 %{buildroot}/%{_mandir}/man1/pngquant.1
|
|||
|
||||
* Wed Dec 28 2011 Craig Barnes <cr@igbarn.es> - 1.6.2-1
|
||||
- Initial package
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
---------------------------------------------------------------------------
|
||||
|
||||
© 1998-2000 by Greg Roelofs.
|
||||
© 2009-2014 by Kornel Lesiński.
|
||||
© 2009-2015 by Kornel Lesiński.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
@ -35,8 +35,9 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "png.h"
|
||||
#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"
|
||||
|
@ -55,9 +56,11 @@
|
|||
#define omp_get_max_threads() 1
|
||||
#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);
|
||||
static void rwpng_warning_stderr_handler(png_structp png_ptr, png_const_charp msg);
|
||||
static void rwpng_warning_silent_handler(png_structp png_ptr, png_const_charp msg);
|
||||
int rwpng_read_image24_cocoa(FILE *infile, png24_image *mainprog_ptr);
|
||||
|
||||
|
||||
|
@ -66,19 +69,22 @@ void rwpng_version_info(FILE *fp)
|
|||
const char *pngver = png_get_header_ver(NULL);
|
||||
|
||||
#if USE_COCOA
|
||||
fputs(" Compiled with Apple Cocoa image reader.\n", fp);
|
||||
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 USE_LCMS
|
||||
fputs(" Compiled with Little CMS color profile support.\n", fp);
|
||||
#endif
|
||||
|
||||
fprintf(fp, " Compiled with libpng %s; using libpng %s.\n",
|
||||
PNG_LIBPNG_VER_STRING, pngver);
|
||||
|
||||
#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 newer version of libpng (1.5 or later).\n", fp);
|
||||
"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
|
||||
}
|
||||
|
@ -89,6 +95,7 @@ struct rwpng_read_data {
|
|||
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);
|
||||
|
@ -99,25 +106,28 @@ static void user_read_data(png_structp png_ptr, png_bytep data, png_size_t lengt
|
|||
}
|
||||
read_data->bytes_read += read;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct rwpng_write_data {
|
||||
unsigned char *buffer;
|
||||
struct rwpng_write_state {
|
||||
FILE *outfile;
|
||||
png_size_t maximum_file_size;
|
||||
png_size_t bytes_written;
|
||||
png_size_t bytes_left;
|
||||
pngquant_error retval;
|
||||
};
|
||||
|
||||
static void user_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
{
|
||||
struct rwpng_write_data *write_data = (struct rwpng_write_data *)png_get_io_ptr(png_ptr);
|
||||
struct rwpng_write_state *write_state = (struct rwpng_write_state *)png_get_io_ptr(png_ptr);
|
||||
|
||||
if (length <= write_data->bytes_left) {
|
||||
memcpy(write_data->buffer + write_data->bytes_written, data, length);
|
||||
write_data->bytes_left -= length;
|
||||
write_data->bytes_written += length;
|
||||
} else {
|
||||
write_data->bytes_written = 0;
|
||||
write_data->bytes_left = 0;
|
||||
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)
|
||||
|
@ -126,7 +136,7 @@ static void user_flush_data(png_structp png_ptr)
|
|||
}
|
||||
|
||||
|
||||
static png_bytepp rwpng_create_row_pointers(png_infop info_ptr, png_structp png_ptr, unsigned char *base, unsigned int height, unsigned int rowbytes)
|
||||
static png_bytepp rwpng_create_row_pointers(png_infop info_ptr, png_structp png_ptr, unsigned char *base, unsigned int height, png_size_t rowbytes)
|
||||
{
|
||||
if (!rowbytes) {
|
||||
rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||
|
@ -134,12 +144,13 @@ static png_bytepp rwpng_create_row_pointers(png_infop info_ptr, png_structp png_
|
|||
|
||||
png_bytepp row_pointers = malloc(height * sizeof(row_pointers[0]));
|
||||
if (!row_pointers) return NULL;
|
||||
for(unsigned int row = 0; row < height; ++row) {
|
||||
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) ||
|
||||
|
@ -164,6 +175,7 @@ static int read_chunk_callback(png_structp png_ptr, png_unknown_chunkp in_chunk)
|
|||
|
||||
return 1; // marks as "handled", libpng won't store it
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
retval:
|
||||
|
@ -175,7 +187,15 @@ static int read_chunk_callback(png_structp png_ptr, png_unknown_chunkp in_chunk)
|
|||
26 = wrong PNG color type (no alpha channel)
|
||||
*/
|
||||
|
||||
pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr, int verbose)
|
||||
#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 verbose)
|
||||
{
|
||||
png_structp png_ptr = NULL;
|
||||
png_infop info_ptr = NULL;
|
||||
|
@ -202,6 +222,14 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
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)
|
||||
/* 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
|
||||
png_set_read_user_chunk_fn(png_ptr, &mainprog_ptr->chunks, read_chunk_callback);
|
||||
|
||||
struct rwpng_read_data read_data = {infile, 0};
|
||||
|
@ -209,7 +237,6 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
|
||||
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] */
|
||||
|
@ -217,7 +244,6 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
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] */
|
||||
|
@ -231,7 +257,7 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
#else
|
||||
fprintf(stderr, "pngquant readpng: image is neither RGBA nor GA\n");
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
mainprog_ptr->retval = 26;
|
||||
mainprog_ptr->retval = WRONG_INPUT_COLOR_TYPE;
|
||||
return mainprog_ptr->retval;
|
||||
#endif
|
||||
}
|
||||
|
@ -244,12 +270,22 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
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)) {
|
||||
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;
|
||||
|
||||
|
@ -262,6 +298,12 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_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);
|
||||
|
@ -292,8 +334,6 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
/* color_type is read from the image before conversion to RGBA */
|
||||
int COLOR_PNG = color_type & PNG_COLOR_MASK_COLOR;
|
||||
|
||||
mainprog_ptr->lcms_status = NONE;
|
||||
|
||||
/* embedded ICC profile */
|
||||
if (png_get_iCCP(png_ptr, info_ptr, &(png_charp){0}, &(int){0}, &ProfileData, &ProfileLen)) {
|
||||
|
||||
|
@ -302,10 +342,12 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
|
||||
/* only RGB (and GRAY) valid for PNGs */
|
||||
if (colorspace == cmsSigRgbData && COLOR_PNG) {
|
||||
mainprog_ptr->lcms_status = ICCP;
|
||||
mainprog_ptr->input_color = RWPNG_ICCP;
|
||||
mainprog_ptr->output_color = RWPNG_SRGB;
|
||||
} else {
|
||||
if (colorspace == cmsSigGrayData && !COLOR_PNG) {
|
||||
mainprog_ptr->lcms_status = ICCP_WARN_GRAY;
|
||||
mainprog_ptr->input_color = RWPNG_ICCP_WARN_GRAY;
|
||||
mainprog_ptr->output_color = RWPNG_SRGB;
|
||||
}
|
||||
cmsCloseProfile(hInProfile);
|
||||
hInProfile = NULL;
|
||||
|
@ -335,7 +377,8 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
|
||||
cmsFreeToneCurve(GammaTable[0]);
|
||||
|
||||
mainprog_ptr->lcms_status = GAMA_CHRM;
|
||||
mainprog_ptr->input_color = RWPNG_GAMA_CHRM;
|
||||
mainprog_ptr->output_color = RWPNG_SRGB;
|
||||
}
|
||||
|
||||
/* transform image to sRGB colorspace */
|
||||
|
@ -373,6 +416,7 @@ pngquant_error rwpng_read_image24_libpng(FILE *infile, png24_image *mainprog_ptr
|
|||
|
||||
return SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void rwpng_free_chunks(struct rwpng_chunk *chunk) {
|
||||
if (!chunk) return;
|
||||
|
@ -448,7 +492,7 @@ static pngquant_error rwpng_write_image_init(rwpng_png_image *mainprog_ptr, png_
|
|||
}
|
||||
|
||||
|
||||
void rwpng_write_end(png_infopp info_ptr_p, png_structpp png_ptr_p, png_bytepp row_pointers)
|
||||
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);
|
||||
|
||||
|
@ -461,37 +505,38 @@ void rwpng_write_end(png_infopp info_ptr_p, png_structpp png_ptr_p, png_bytepp r
|
|||
png_destroy_write_struct(png_ptr_p, info_ptr_p);
|
||||
}
|
||||
|
||||
void rwpng_set_gamma(png_infop info_ptr, png_structp png_ptr, double gamma)
|
||||
static void rwpng_set_gamma(png_infop info_ptr, png_structp png_ptr, double gamma, rwpng_color_transform color)
|
||||
{
|
||||
/* remap sets gamma to 0.45455 */
|
||||
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)
|
||||
pngquant_error rwpng_write_image8(FILE *outfile, const 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_data write_data;
|
||||
if (mainprog_ptr->maximum_file_size) {
|
||||
write_data = (struct rwpng_write_data){
|
||||
.buffer = malloc(mainprog_ptr->maximum_file_size),
|
||||
.bytes_left = mainprog_ptr->maximum_file_size,
|
||||
struct rwpng_write_state write_state;
|
||||
write_state = (struct rwpng_write_state){
|
||||
.outfile = outfile,
|
||||
.maximum_file_size = mainprog_ptr->maximum_file_size,
|
||||
.retval = SUCCESS,
|
||||
};
|
||||
if (!write_data.buffer) return PNG_OUT_OF_MEMORY_ERROR;
|
||||
png_set_write_fn(png_ptr, &write_data, user_write_data, user_flush_data);
|
||||
} else {
|
||||
png_init_io(png_ptr, outfile);
|
||||
}
|
||||
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);
|
||||
rwpng_set_gamma(info_ptr, png_ptr, mainprog_ptr->gamma, mainprog_ptr->output_color);
|
||||
|
||||
/* set the image parameters appropriately */
|
||||
int sample_depth;
|
||||
|
@ -517,7 +562,7 @@ pngquant_error rwpng_write_image8(FILE *outfile, png8_image *mainprog_ptr)
|
|||
memcpy(pngchunk.name, chunk->name, 5);
|
||||
png_set_unknown_chunks(png_ptr, info_ptr, &pngchunk, 1);
|
||||
|
||||
#if PNG_LIBPNG_VER < 10600
|
||||
#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
|
||||
|
||||
|
@ -530,29 +575,37 @@ pngquant_error rwpng_write_image8(FILE *outfile, png8_image *mainprog_ptr)
|
|||
0, PNG_COMPRESSION_TYPE_DEFAULT,
|
||||
PNG_FILTER_TYPE_BASE);
|
||||
|
||||
png_set_PLTE(png_ptr, info_ptr, &mainprog_ptr->palette[0], mainprog_ptr->num_palette);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (mainprog_ptr->num_trans > 0) {
|
||||
png_set_tRNS(png_ptr, info_ptr, mainprog_ptr->trans, mainprog_ptr->num_trans, NULL);
|
||||
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 (mainprog_ptr->maximum_file_size) {
|
||||
if (!write_data.bytes_written) {
|
||||
retval = TOO_LARGE_FILE;
|
||||
} else {
|
||||
if (!fwrite(write_data.buffer, 1, write_data.bytes_written, outfile)) {
|
||||
retval = CANT_WRITE_ERROR;
|
||||
}
|
||||
if (SUCCESS == write_state.retval && write_state.maximum_file_size && write_state.bytes_written > write_state.maximum_file_size) {
|
||||
return TOO_LARGE_FILE;
|
||||
}
|
||||
|
||||
free(write_data.buffer);
|
||||
}
|
||||
return retval;
|
||||
return write_state.retval;
|
||||
}
|
||||
|
||||
pngquant_error rwpng_write_image24(FILE *outfile, png24_image *mainprog_ptr)
|
||||
pngquant_error rwpng_write_image24(FILE *outfile, const png24_image *mainprog_ptr)
|
||||
{
|
||||
png_structp png_ptr;
|
||||
png_infop info_ptr;
|
||||
|
@ -562,7 +615,7 @@ pngquant_error rwpng_write_image24(FILE *outfile, png24_image *mainprog_ptr)
|
|||
|
||||
png_init_io(png_ptr, outfile);
|
||||
|
||||
rwpng_set_gamma(info_ptr, png_ptr, mainprog_ptr->gamma);
|
||||
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,
|
||||
|
@ -579,14 +632,6 @@ pngquant_error rwpng_write_image24(FILE *outfile, png24_image *mainprog_ptr)
|
|||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static void rwpng_warning_stderr_handler(png_structp png_ptr, png_const_charp msg) {
|
||||
fprintf(stderr, " %s\n", msg);
|
||||
}
|
||||
|
||||
static void rwpng_warning_silent_handler(png_structp png_ptr, png_const_charp msg) {
|
||||
}
|
||||
|
||||
static void rwpng_error_handler(png_structp png_ptr, png_const_charp msg)
|
||||
{
|
||||
rwpng_png_image *mainprog_ptr;
|
||||
|
@ -600,7 +645,7 @@ static void rwpng_error_handler(png_structp png_ptr, png_const_charp msg)
|
|||
* regardless of whether _BSD_SOURCE or anything else has (or has not)
|
||||
* been defined. */
|
||||
|
||||
fprintf(stderr, " error: %s\n", msg);
|
||||
fprintf(stderr, " error: %s (libpng failed)\n", msg);
|
||||
fflush(stderr);
|
||||
|
||||
mainprog_ptr = png_get_error_ptr(png_ptr);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
---------------------------------------------------------------------------
|
||||
|
||||
© 1998-2000 by Greg Roelofs.
|
||||
© 2009-2014 by Kornel Lesiński.
|
||||
© 2009-2015 by Kornel Lesiński.
|
||||
|
||||
All rights reserved.
|
||||
|
||||
|
@ -35,7 +35,9 @@
|
|||
#ifndef RWPNG_H
|
||||
#define RWPNG_H
|
||||
|
||||
#include "png.h" /* if this include fails, you need to install libpng (e.g. libpng-devel package) */
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
#ifndef USE_COCOA
|
||||
|
@ -53,55 +55,59 @@ typedef enum {
|
|||
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;
|
||||
png_byte *data;
|
||||
png_size_t size;
|
||||
png_byte name[5];
|
||||
png_byte location;
|
||||
unsigned char *data;
|
||||
size_t size;
|
||||
unsigned char name[5];
|
||||
unsigned char location;
|
||||
};
|
||||
|
||||
#if USE_LCMS
|
||||
typedef enum {
|
||||
NONE = 0,
|
||||
ICCP = 1, // used ICC profile
|
||||
ICCP_WARN_GRAY = 2, // ignore and warn about GRAY ICC profile
|
||||
GAMA_CHRM = 3, // used gAMA and cHARM
|
||||
} lcms_transform;
|
||||
#endif
|
||||
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;
|
||||
png_uint_32 width;
|
||||
png_uint_32 height;
|
||||
png_size_t file_size;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
size_t file_size;
|
||||
double gamma;
|
||||
unsigned char **row_pointers;
|
||||
unsigned char *rgba_data;
|
||||
struct rwpng_chunk *chunks;
|
||||
#if USE_LCMS
|
||||
lcms_transform lcms_status;
|
||||
#endif
|
||||
rwpng_color_transform input_color;
|
||||
rwpng_color_transform output_color;
|
||||
} png24_image;
|
||||
|
||||
typedef struct {
|
||||
jmp_buf jmpbuf;
|
||||
png_uint_32 width;
|
||||
png_uint_32 height;
|
||||
png_size_t maximum_file_size;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
size_t maximum_file_size;
|
||||
double gamma;
|
||||
unsigned char **row_pointers;
|
||||
unsigned char *indexed_data;
|
||||
unsigned int num_palette;
|
||||
unsigned int num_trans;
|
||||
png_color palette[256];
|
||||
unsigned char trans[256];
|
||||
struct rwpng_chunk *chunks;
|
||||
unsigned int num_palette;
|
||||
rwpng_rgba palette[256];
|
||||
rwpng_color_transform output_color;
|
||||
char fast_compression;
|
||||
} png8_image;
|
||||
|
||||
|
@ -116,8 +122,8 @@ typedef union {
|
|||
void rwpng_version_info(FILE *fp);
|
||||
|
||||
pngquant_error rwpng_read_image24(FILE *infile, png24_image *mainprog_ptr, int verbose);
|
||||
pngquant_error rwpng_write_image8(FILE *outfile, png8_image *mainprog_ptr);
|
||||
pngquant_error rwpng_write_image24(FILE *outfile, png24_image *mainprog_ptr);
|
||||
pngquant_error rwpng_write_image8(FILE *outfile, const 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 *);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ int rwpng_read_image24_cocoa(FILE *fp, png24_image *out)
|
|||
width, height,
|
||||
8, width*4,
|
||||
colorspace,
|
||||
kCGImageAlphaPremultipliedLast);
|
||||
(CGBitmapInfo)kCGImageAlphaPremultipliedLast);
|
||||
|
||||
CGColorSpaceRelease(colorspace);
|
||||
|
||||
|
@ -60,6 +60,8 @@ int rwpng_read_image24_cocoa(FILE *fp, png24_image *out)
|
|||
}
|
||||
|
||||
out->gamma = 0.45455;
|
||||
out->input_color = RWPNG_COCOA;
|
||||
out->output_color = RWPNG_SRGB;
|
||||
out->width = width;
|
||||
out->height = height;
|
||||
out->rgba_data = (unsigned char *)pixel_data;
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,172 @@
|
|||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include "../lib/libimagequant.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char magic[] = "magic";
|
||||
|
||||
static void test_log_callback_function(const liq_attr *at, const char *message, void* user_info) {
|
||||
assert(user_info == magic);
|
||||
assert(message);
|
||||
assert(strlen(message));
|
||||
}
|
||||
|
||||
static int test_abort_callback(float progress_percent, void* user_info) {
|
||||
assert(user_info == magic);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int progress_called = 0;
|
||||
static int test_continue_callback(float progress_percent, void* user_info) {
|
||||
assert(user_info == magic);
|
||||
progress_called++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void test_abort() {
|
||||
liq_attr *attr = liq_attr_create();
|
||||
|
||||
unsigned char dummy[4] = {0};
|
||||
liq_image *img = liq_image_create_rgba(attr, dummy, 1, 1, 0);
|
||||
|
||||
liq_attr_set_progress_callback(attr, test_abort_callback, magic);
|
||||
|
||||
liq_result *res = liq_quantize_image(attr, img);
|
||||
assert(!res);
|
||||
|
||||
liq_attr_destroy(attr);
|
||||
}
|
||||
|
||||
static void test_zero_histogram() {
|
||||
liq_attr *attr = liq_attr_create();
|
||||
liq_histogram *hist = liq_histogram_create(attr);
|
||||
assert(hist);
|
||||
|
||||
liq_result *res;
|
||||
liq_error err = liq_histogram_quantize(hist, attr, &res);
|
||||
assert(!res);
|
||||
assert(err);
|
||||
|
||||
liq_attr_destroy(attr);
|
||||
liq_histogram_destroy(hist);
|
||||
}
|
||||
|
||||
static void test_histogram() {
|
||||
liq_attr *attr = liq_attr_create();
|
||||
liq_histogram *hist = liq_histogram_create(attr);
|
||||
assert(hist);
|
||||
|
||||
const unsigned char dummy1[4] = {255,0,255,255};
|
||||
liq_image *const img1 = liq_image_create_rgba(attr, dummy1, 1, 1, 0);
|
||||
assert(img1);
|
||||
|
||||
const liq_error err1 = liq_histogram_add_image(hist, attr, img1);
|
||||
assert(LIQ_OK == err1);
|
||||
|
||||
const unsigned char dummy2[4] = {0,0,0,0};
|
||||
liq_image *const img2 = liq_image_create_rgba(attr, dummy2, 1, 1, 0);
|
||||
assert(img2);
|
||||
liq_image_add_fixed_color(img2, (liq_color){255,255,255,255});
|
||||
|
||||
|
||||
const liq_error err2 = liq_histogram_add_image(hist, attr, img2);
|
||||
assert(LIQ_OK == err2);
|
||||
|
||||
liq_image_destroy(img1);
|
||||
liq_image_destroy(img2);
|
||||
|
||||
liq_result *res;
|
||||
liq_error err = liq_histogram_quantize(hist, attr, &res);
|
||||
assert(LIQ_OK == err);
|
||||
assert(res);
|
||||
|
||||
liq_attr_destroy(attr);
|
||||
|
||||
liq_histogram_destroy(hist);
|
||||
|
||||
const liq_palette *pal = liq_get_palette(res);
|
||||
assert(pal);
|
||||
assert(pal->count == 3);
|
||||
|
||||
liq_result_destroy(res);
|
||||
}
|
||||
|
||||
static void test_fixed_colors() {
|
||||
liq_attr *attr = liq_attr_create();
|
||||
|
||||
liq_attr_set_progress_callback(attr, test_continue_callback, magic);
|
||||
liq_set_log_callback(attr, test_log_callback_function, magic);
|
||||
|
||||
unsigned char dummy[4] = {0};
|
||||
liq_image *img = liq_image_create_rgba(attr, dummy, 1, 1, 0);
|
||||
assert(img);
|
||||
|
||||
liq_image_add_fixed_color(img, (liq_color){0,0,0,0});
|
||||
|
||||
liq_result *res = liq_quantize_image(attr, img);
|
||||
assert(res);
|
||||
assert(progress_called);
|
||||
|
||||
const liq_palette *pal = liq_get_palette(res);
|
||||
assert(pal);
|
||||
assert(pal->count == 1);
|
||||
|
||||
liq_result_destroy(res);
|
||||
liq_image_destroy(img);
|
||||
liq_attr_destroy(attr);
|
||||
}
|
||||
|
||||
static void test_fixed_colors_order() {
|
||||
liq_attr *attr = liq_attr_create();
|
||||
|
||||
unsigned char dummy[4] = {0};
|
||||
liq_image *img = liq_image_create_rgba(attr, dummy, 1, 1, 0);
|
||||
assert(img);
|
||||
|
||||
liq_color colors[17] = {
|
||||
{0,0,0,0}, {1,1,1,1}, {2,2,2,2}, {3,3,3,3}, {4,4,4,4}, {5,4,4,4},
|
||||
{6,4,4,4}, {6,7,4,4}, {6,7,8,4}, {6,7,8,9}, {10,7,8,9}, {10,11,8,9},
|
||||
{10,11,12,9}, {10,11,12,13}, {14,11,12,13}, {14,15,12,13}, {14,15,16,13},
|
||||
};
|
||||
|
||||
for(int i=0; i < 17; i++) {
|
||||
liq_image_add_fixed_color(img, colors[i]);
|
||||
}
|
||||
|
||||
liq_result *res = liq_quantize_image(attr, img);
|
||||
assert(res);
|
||||
|
||||
const liq_palette *pal = liq_get_palette(res);
|
||||
assert(pal);
|
||||
assert(pal->count == 17);
|
||||
|
||||
for(int i=0; i < 17; i++) {
|
||||
assert(pal->entries[i].r == colors[i].r);
|
||||
assert(pal->entries[i].g == colors[i].g);
|
||||
assert(pal->entries[i].b == colors[i].b);
|
||||
assert(pal->entries[i].a == colors[i].a);
|
||||
}
|
||||
|
||||
liq_set_dithering_level(res, 1.0);
|
||||
|
||||
char buf[1];
|
||||
assert(LIQ_OK == liq_write_remapped_image(res, img, buf, 1));
|
||||
|
||||
liq_result_set_progress_callback(res, test_abort_callback, magic);
|
||||
assert(LIQ_ABORTED == liq_write_remapped_image(res, img, buf, 1));
|
||||
|
||||
liq_result_destroy(res);
|
||||
liq_image_destroy(img);
|
||||
liq_attr_destroy(attr);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test_fixed_colors();
|
||||
test_fixed_colors_order();
|
||||
test_abort();
|
||||
test_histogram();
|
||||
test_zero_histogram();
|
||||
assert(printf("OK\n"));
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
set -o pipefail
|
||||
|
||||
TESTDIR=$1
|
||||
IMGSRC=$TESTDIR/img
|
||||
TMPDIR=$(mktemp -d -t pngquantXXXXXX)
|
||||
BIN=$2
|
||||
TESTBIN=$3
|
||||
PATH=.:$PATH # Required, since BIN may be just 'pngquant'
|
||||
|
||||
$BIN --version 2>&1 | fgrep 2.
|
||||
$BIN --help | fgrep -q "usage:"
|
||||
|
||||
$BIN 2>/dev/null && { echo "should fail without args"; exit 1; } || true
|
||||
|
||||
function test_overwrite() {
|
||||
cp "$IMGSRC/test.png" "$TMPDIR/overwritetest.png"
|
||||
rm -rf "$TMPDIR/overwritetest-fs8.png" "$TMPDIR/overwritetest-or8.png"
|
||||
|
||||
$BIN "$TMPDIR/overwritetest.png"
|
||||
test -f "$TMPDIR/overwritetest-fs8.png"
|
||||
|
||||
$BIN --floyd=0.5 --force "$TMPDIR/overwritetest.png"
|
||||
test -f "$TMPDIR/overwritetest-fs8.png"
|
||||
test '!' -e "$TMPDIR/overwritetest-or8.png"
|
||||
|
||||
$BIN --nofs "$TMPDIR/overwritetest.png"
|
||||
test -f "$TMPDIR/overwritetest-or8.png"
|
||||
|
||||
rm "$TMPDIR/overwritetest-or8.png"
|
||||
$BIN 2>&1 -nofs "$TMPDIR/overwritetest.png" | fgrep -q warning:
|
||||
test -f "$TMPDIR/overwritetest-or8.png"
|
||||
|
||||
$BIN 2>/dev/null --ordered "$TMPDIR/overwritetest.png" && { echo "should refuse to overwrite"; exit 1; } || true
|
||||
|
||||
{ $BIN 2>&1 --ordered "$TMPDIR/overwritetest.png" && { echo "should refuse to overwrite"; exit 1; } || true; } | fgrep -q 'not overwriting'
|
||||
|
||||
$BIN "$TMPDIR/overwritetest.png" -o "$TMPDIR/overwritedest.png"
|
||||
test -f "$TMPDIR/overwritedest.png"
|
||||
|
||||
$BIN 2>/dev/null "$TMPDIR/overwritetest.png" -o "$TMPDIR/overwritedest.png" && { echo "should refuse to overwrite"; exit 1; } || true
|
||||
}
|
||||
|
||||
function test_skip() {
|
||||
cp "$IMGSRC/test.png" "$TMPDIR/skiptest.png"
|
||||
rm -rf "$TMPDIR/shouldskip.png"
|
||||
|
||||
$BIN 2>/dev/null "$TMPDIR/skiptest.png" -Q 100-100 -o "$TMPDIR/shouldskip.png" && { echo "should skip due to quality"; exit 1; } || RET=$?
|
||||
test "$RET" -eq 99 || { echo "should return 99, not $RET"; exit 1; }
|
||||
test '!' -e "$TMPDIR/shouldskip.png"
|
||||
|
||||
$BIN "$TMPDIR/skiptest.png" -Q 0-50 -o "$TMPDIR/q50output.png"
|
||||
test -f "$TMPDIR/q50output.png"
|
||||
|
||||
$BIN "$TMPDIR/q50output.png" --skip-if-larger -Q 0-49 -o "$TMPDIR/q49output.png" && { echo "should skip due to filesize"; exit 1; } || RET=$?
|
||||
test "$RET" -eq 98 || { echo "should return 98, not $RET"; exit 1; }
|
||||
test '!' -e "$TMPDIR/q49output.png"
|
||||
}
|
||||
|
||||
function test_metadata() {
|
||||
cp "$IMGSRC/metadata.png" "$TMPDIR/metadatatest.png"
|
||||
$BIN 2>/dev/null "$TMPDIR/metadatatest.png"
|
||||
|
||||
# This test will fail if compiled with old libpng
|
||||
fgrep -q '<rdf:RDF xmlns:rdf' "$TMPDIR/metadatatest-fs8.png" || { echo "embedded RDF not found. This is expected if configured with Cocoa reader"; exit 1; }
|
||||
|
||||
# This test will fail if compiled without liblcms or cocoa
|
||||
fgrep -q 'sRGB' "$TMPDIR/metadatatest-fs8.png" || { echo "sRGB chunk not found. This test requires lcms2"; exit 1; }
|
||||
}
|
||||
|
||||
test_overwrite &
|
||||
test_skip &
|
||||
test_metadata &
|
||||
|
||||
for job in `jobs -p`
|
||||
do
|
||||
wait $job
|
||||
done
|
||||
|
||||
$TESTBIN
|
Loading…
Reference in New Issue