jpegxl-sys-0.11.2+libjxl-0.11.1/.cargo_vcs_info.json 0000644 00000000150 00000000001 0015212 0 ustar {
"git": {
"sha1": "c609dcde9a612bbcdd9cea279c1c588c31720373"
},
"path_in_vcs": "jpegxl-sys"
} jpegxl-sys-0.11.2+libjxl-0.11.1/CHANGELOG.md 0000644 0000000 0000000 00000003110 10461020230 0015612 0 ustar 0000000 0000000 # Changelog
## [Unreleased]
## [0.11.2+libjxl-0.11.1](https://github.com/inflation/jpegxl-rs/compare/jpegxl-sys-v0.11.1+libjxl-0.11.0...jpegxl-sys-v0.11.2+libjxl-0.11.1)
### 🐛 Bug Fixes
- Update extern "C" to extern "C-unwind" in multiple files - ([793c23a](https://github.com/inflation/jpegxl-rs/commit/793c23a04b5f167ec46875cdc85e5b6eb64b260a))
### 📦 Dependencies
- Update `libjxl` to v0.11.1 - ([71f188a](https://github.com/inflation/jpegxl-rs/commit/71f188a331fcbc5c1ec9358ffbcc9e34f6f269c7))
## [0.11.1+libjxl-0.11.0](https://github.com/inflation/jpegxl-rs/compare/jpegxl-sys-v0.11.0+libjxl-0.11.0...jpegxl-sys-v0.11.1+libjxl-0.11.0) - 2024-10-01
### 🐛 Bug Fixes
- Fix doc gen
### 📚 Documentation
- Remove docsrs-specific reference to deleted "threads" feature
## [0.11.0+libjxl-0.11.0](https://github.com/inflation/jpegxl-rs/compare/jpegxl-sys-v0.10.4+libjxl-0.10.3...jpegxl-sys-v0.11.0+libjxl-0.11.0) - 2024-09-27
### ⛰️ Features
- Add gain map utility functions
### 🐛 Bug Fixes
- Change ffi function types to use `c-unwind` ABI
### 🚜 Refactor
- Move `libjxl` functions into modules
- Remove threads feature and update dependencies.
### 📚 Documentation
- Convert `libjxl` doc to rustdoc format with help from @copilot
- Update how docs are generated ([#73](https://github.com/inflation/jpegxl-rs/pull/73))
### 📦 Dependencies
- Bump pkg-config from 0.3.30 to 0.3.31
- Bump pretty_assertions from 1.4.0 to 1.4.1
- Bump image from 0.25.1 to 0.25.2
### ⚙️ Miscellaneous Tasks
- Update release configuration for `jpegxl-rs` and `jpegxl-sys` packages
jpegxl-sys-0.11.2+libjxl-0.11.1/COPYING 0000644 0000000 0000000 00000104514 10461020230 0015046 0 ustar 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
. jpegxl-sys-0.11.2+libjxl-0.11.1/Cargo.toml 0000644 00000003171 00000000001 0013216 0 ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2021"
rust-version = "1.74.0"
name = "jpegxl-sys"
version = "0.11.2+libjxl-0.11.1"
authors = ["Inflation "]
build = "build.rs"
links = "jxl"
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "Rust wrapper for JPEG XL reference implementation"
readme = "README.md"
keywords = [
"jpeg-xl",
"jxl",
]
categories = [
"external-ffi-bindings",
"encoding",
"multimedia::images",
]
license = "GPL-3.0-or-later"
repository = "https://github.com/inflation/jpegxl-rs"
[package.metadata.docs.rs]
features = ["docs"]
[lib]
name = "jpegxl_sys"
path = "src/lib.rs"
[dev-dependencies.image]
version = "0.25.5"
features = ["png"]
default-features = false
[dev-dependencies.pretty_assertions]
version = "1.4.1"
[build-dependencies.jpegxl-src]
version = "0.11.2"
optional = true
[build-dependencies.pkg-config]
version = "0.3.31"
[features]
default = []
docs = []
vendored = ["jpegxl-src"]
[lints.clippy]
module_name_repetitions = "allow"
pedantic = "warn"
[lints.rust.unexpected_cfgs]
level = "warn"
priority = 0
check-cfg = ["cfg(coverage_nightly)"]
[lints.rustdoc]
broken_intra_doc_links = "deny"
jpegxl-sys-0.11.2+libjxl-0.11.1/Cargo.toml.orig 0000644 0000000 0000000 00000002133 10461020230 0016674 0 ustar 0000000 0000000 [package]
authors = ["Inflation "]
categories = ["external-ffi-bindings", "encoding", "multimedia::images"]
description = "Rust wrapper for JPEG XL reference implementation"
edition = "2021"
keywords = ["jpeg-xl", "jxl"]
license = "GPL-3.0-or-later"
links = "jxl"
name = "jpegxl-sys"
readme = "README.md"
repository = "https://github.com/inflation/jpegxl-rs"
version = "0.11.2+libjxl-0.11.1"
rust-version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(coverage_nightly)'] }
[lints.clippy]
pedantic = "warn"
module_name_repetitions = "allow"
[lints.rustdoc]
broken_intra_doc_links = "deny"
[package.metadata.docs.rs]
features = ["docs"]
[build-dependencies]
pkg-config = "0.3.31"
[build-dependencies.jpegxl-src]
version = "0.11.2"
path = "../jpegxl-src"
optional = true
[dev-dependencies]
image = { version = "0.25.5", default-features = false, features = ["png"] }
pretty_assertions = "1.4.1"
[features]
default = []
vendored = ["jpegxl-src"]
docs = []
jpegxl-sys-0.11.2+libjxl-0.11.1/LICENSE 0000644 0000000 0000000 00000001271 10461020230 0015014 0 ustar 0000000 0000000 jpegxl-sys is a wrapper around jpeg-xl decoder's C API
Copyright (C) 2020 Inflation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see . jpegxl-sys-0.11.2+libjxl-0.11.1/README.md 0000644 0000000 0000000 00000001152 10461020230 0015264 0 ustar 0000000 0000000 # jpegxl-sys
`jpegxl-sys` is a wrapper over `libjxl` library. Check out the original library [here](https://github.com/libjxl/libjxl).
## Building
If you wish to specify a custom library path, set the `DEP_JXL_LIB` environment variable.
Building `libjxl` and statically linking can be enabled by using the `vendored` feature.
## Usage
Check out testing units in `src/lib.rs` for some examples.
### Multi-thread
Because `libjxl_threads` uses `std::thread`, if you build and statically link `libjxl`, you need to
dynamically link to `libc++` or `libstdc++`.
Using dynamic library doesn't need this requirement.
jpegxl-sys-0.11.2+libjxl-0.11.1/build.rs 0000644 0000000 0000000 00000003360 10461020230 0015455 0 ustar 0000000 0000000 /*
* This file is part of jpegxl-rs.
*
* jpegxl-rs is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* jpegxl-rs is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with jpegxl-rs. If not, see .
*/
//! Build script for jpegxl-sys.
fn main() {
#[cfg(all(not(feature = "vendored"), not(feature = "docs")))]
{
use std::env;
let version = env!("CARGO_PKG_VERSION")
.split('+')
.nth(1)
.and_then(|s| s.split('-').nth(1))
.unwrap();
if let Ok(path) = env::var("DEP_JXL_LIB") {
println!("cargo:rustc-link-search=native={path}");
println!("cargo:rustc-link-lib=jxl");
println!("cargo:rustc-link-lib=jxl_threads");
} else {
pkg_config::Config::new()
.atleast_version(version)
.probe("libjxl")
.unwrap_or_else(|_| panic!("Cannot find `libjxl` with version >= {version}"));
pkg_config::Config::new()
.atleast_version(version)
.probe("libjxl_threads")
.unwrap_or_else(|_| {
panic!("Cannot find `libjxl_threads` with version >= {version}")
});
}
}
#[cfg(feature = "vendored")]
jpegxl_src::build();
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/color/cms.rs 0000644 0000000 0000000 00000001462 10461020230 0017046 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! ICC profiles and color space conversions.
use super::cms_interface::JxlCmsInterface;
extern "C-unwind" {
pub fn JxlGetDefaultCms() -> *const JxlCmsInterface;
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/color/cms_interface.rs 0000644 0000000 0000000 00000005103 10461020230 0021062 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Interface to allow the injection of different color management systems
//! (CMSes, also called color management modules, or CMMs) in JPEG XL.
//!
//! A CMS is needed by the JPEG XL encoder and decoder to perform colorspace
//! conversions. This defines an interface that can be implemented for different
//! CMSes and then passed to the library.
use std::ffi::c_void;
use crate::common::types::JxlBool;
use super::color_encoding::JxlColorEncoding;
pub type JpegXlCmsSetFieldsFromIccFunc = extern "C-unwind" fn(
user_data: *mut c_void,
icc_data: *const u8,
icc_size: usize,
c: *mut JxlColorEncoding,
cmyk: *mut JxlBool,
) -> JxlBool;
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlColorProfileIcc {
data: *const u8,
size: usize,
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlColorProfile {
pub icc: JxlColorProfileIcc,
pub color_encoding: JxlColorEncoding,
pub num_channels: usize,
}
pub type JpegXlCmsInitFunc = extern "C-unwind" fn(
init_data: *mut c_void,
num_threads: usize,
pixels_per_thread: usize,
input_profile: *const JxlColorProfile,
output_profile: *const JxlColorProfile,
intensity_target: f32,
) -> *mut c_void;
pub type JpegXlCmsGetBufferFunc =
extern "C-unwind" fn(user_data: *mut c_void, thread: usize) -> *mut f32;
pub type JpegXlCmsRunFunc = extern "C-unwind" fn(
user_data: *mut c_void,
thread: usize,
input_buffer: *const f32,
output_buffer: *mut f32,
num_pixels: usize,
) -> JxlBool;
pub type JpegXlCmsDestroyFun = extern "C-unwind" fn(user_data: *mut c_void);
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlCmsInterface {
pub set_fields_data: *mut c_void,
pub set_fields_from_icc: JpegXlCmsSetFieldsFromIccFunc,
pub init_data: *mut c_void,
pub init: JpegXlCmsInitFunc,
pub get_src_buf: JpegXlCmsGetBufferFunc,
pub get_dst_buf: JpegXlCmsGetBufferFunc,
pub run: JpegXlCmsRunFunc,
pub destroy: JpegXlCmsDestroyFun,
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/color/color_encoding.rs 0000644 0000000 0000000 00000013604 10461020230 0021251 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Color Encoding definitions used by JPEG XL.
//! All CIE units are for the standard 1931 2 degree observer.
#[cfg(doc)]
use crate::metadata::codestream_header::JxlBasicInfo;
/// Color space of the image data.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlColorSpace {
/// Tristimulus RGB
Rgb = 0,
/// Luminance based, the primaries in [`JxlColorEncoding`] must be ignored.
/// This value implies that [`JxlBasicInfo::num_color_channels`] is `1`, any
/// other value implies `num_color_channels` is `3`.
Gray,
/// XYB (opsin) color space
Xyb,
/// None of the other table entries describe the color space appropriately
Unknown,
}
/// Built-in white points for color encoding. When decoding, the numerical xy
/// white point value can be read from the [`JxlColorEncoding::white_point`]
/// field regardless of the enum value. When encoding, enum values except
/// [`JxlWhitePoint::Custom`] override the numerical fields. Some enum values
/// match a subset of CICP (Rec. ITU-T H.273 | ISO/IEC 23091-2:2019(E)), however
/// the white point and RGB primaries are separate enums here.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlWhitePoint {
/// CIE Standard Illuminant D65: 0.3127, 0.3290
D65 = 1,
/// White point must be read from the [`JxlColorEncoding::white_point`] field,
/// or as ICC profile. This enum value is not an exact match of the
/// corresponding CICP value.
Custom = 2,
/// CIE Standard Illuminant E (equal-energy): 1/3, 1/3
E = 10,
/// DCI-P3 from SMPTE RP 431-2: 0.314, 0.351
Dci = 11,
}
/// Built-in primaries for color encoding. When decoding, the primaries can be
/// read from the [`JxlColorEncoding::primaries_red_xy`], [`JxlColorEncoding::primaries_green_xy`],
/// and [`JxlColorEncoding::primaries_blue_xy`] fields regardless of the enum value. When encoding,
/// the enum values except [`JxlPrimaries::Custom`] override the numerical fields. Some enum values
/// match a subset of CICP (Rec. ITU-T H.273 | ISO/IEC 23091-2:2019(E)), however the white point
/// and RGB primaries are separate enums here.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlPrimaries {
/// The CIE xy values of the red, green and blue primaries are: 0.639998686,
/// 0.330010138; 0.300003784, 0.600003357; 0.150002046, 0.059997204
SRgb = 1,
/// Primaries must be read from the [`JxlColorEncoding::primaries_red_xy`],
/// [`JxlColorEncoding::primaries_green_xy`] and [`JxlColorEncoding::primaries_blue_xy`] fields,
/// or as ICC profile. This enum value is not an exact match of the corresponding CICP value.
Custom = 2,
/// As specified in Rec. ITU-R BT.2100-1
Rec2100 = 9,
/// As specified in SMPTE RP 431-2
P3 = 11,
}
/// Built-in transfer functions for color encoding. Enum values match a subset
/// of CICP (Rec. ITU-T H.273 | ISO/IEC 23091-2:2019(E)) unless specified
/// otherwise.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlTransferFunction {
/// As specified in ITU-R BT.709-6
BT709 = 1,
/// None of the other table entries describe the transfer function.
Unknown = 2,
/// The gamma exponent is 1
Linear = 8,
/// As specified in IEC 61966-2-1 sRGB
SRGB = 13,
/// As specified in SMPTE ST 2084
PQ = 16,
/// As specified in SMPTE ST 428-1
DCI = 17,
/// As specified in Rec. ITU-R BT.2100-1
HLG = 18,
/// Transfer function follows power law given by the gamma value in [`JxlColorEncoding`].
/// Not a CICP value.
Gamma = 65535,
}
/// Rendering intent for color encoding, as specified in ISO 15076-1:2010
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlRenderingIntent {
/// vendor-specific
Perceptual = 0,
/// media-relative
Relative,
/// vendor-specific
Saturation,
/// ICC-absolute
Absolute,
}
/// Color encoding of the image as structured information.
#[repr(C)]
#[derive(Clone, Debug)]
pub struct JxlColorEncoding {
/// Color space of the image data.
pub color_space: JxlColorSpace,
/// Built-in white point. If this value is [`JxlWhitePoint::Custom`], must
/// use the numerical white point values from [`Self::white_point_xy`].
pub white_point: JxlWhitePoint,
/// Numerical whitepoint values in CIE xy space.
pub white_point_xy: [f64; 2],
/// Built-in RGB primaries. If this value is [`JxlPrimaries::Custom`], must
/// use the numerical primaries values below. This field and the custom values
/// below are unused and must be ignored if the color space is
/// [`JxlColorSpace::Gray`] or [`JxlColorSpace::Xyb`].
pub primaries: JxlPrimaries,
/// Numerical red primary values in CIE xy space.
pub primaries_red_xy: [f64; 2],
/// Numerical green primary values in CIE xy space.
pub primaries_green_xy: [f64; 2],
/// Numerical blue primary values in CIE xy space.
pub primaries_blue_xy: [f64; 2],
/// Transfer function if `have_gamma` is 0.
pub transfer_function: JxlTransferFunction,
/// Gamma value used when [`Self::transfer_function`] is [`JxlTransferFunction::Gamma`].
pub gamma: f64,
/// Rendering intent defined for the color profile.
pub rendering_intent: JxlRenderingIntent,
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/color.rs 0000644 0000000 0000000 00000001400 10461020230 0016254 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! `jxl_color`: ICC profiles and color space conversions.
pub mod cms;
pub mod cms_interface;
pub mod color_encoding;
jpegxl-sys-0.11.2+libjxl-0.11.1/src/common/memory_manager.rs 0000644 0000000 0000000 00000004611 10461020230 0021437 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Abstraction functions used by JPEG XL to allocate memory.
use std::ffi::c_void;
/// Allocating function for a memory region of a given size.
///
/// Allocates a contiguous memory region of size `size` bytes. The returned
/// memory may not be aligned to a specific size or initialized at all.
///
/// # Parameters
/// - `opaque`: custom memory manager handle provided by the caller.
/// - `size`: size in bytes of the requested memory region.
///
/// # Returns
/// - `NULL` if the memory cannot be allocated.
/// - Pointer to the memory otherwise.
pub type JpegxlAllocFunc =
unsafe extern "C-unwind" fn(opaque: *mut c_void, size: usize) -> *mut c_void;
/// Deallocating function pointer type.
///
/// This function **MUST** do nothing if `address` is `NULL`.
///
/// # Parameters
/// - `opaque`: custom memory manager handle provided by the caller.
/// - `address`: memory region pointer returned by [`JpegxlAllocFunc`], or `NULL`.
pub type JpegxlFreeFunc = unsafe extern "C-unwind" fn(opaque: *mut c_void, address: *mut c_void);
/// Memory Manager struct.
/// These functions, when provided by the caller, will be used to handle memory
/// allocations.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlMemoryManager {
/// The opaque pointer that will be passed as the first parameter to all the
/// functions in this struct.
pub opaque: *mut c_void,
/// Memory allocation function. This can be NULL if and only if also the
/// [`Self::free`] member in this class is NULL. All dynamic memory will be allocated
/// and freed with these functions if they are not NULL, otherwise with the
/// standard malloc/free.
pub alloc: Option,
/// Free function matching the [`Self::alloc`] member.
pub free: Option,
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/common/types.rs 0000644 0000000 0000000 00000012476 10461020230 0017611 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Data types for the JPEG XL API, for both encoding and decoding.
use std::ffi::c_char;
#[cfg(doc)]
use crate::metadata::codestream_header::JxlBasicInfo;
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum JxlBool {
True = 1,
False = 0,
}
impl From for JxlBool {
fn from(b: bool) -> Self {
if b {
JxlBool::True
} else {
JxlBool::False
}
}
}
/// Data type for the sample values per channel per pixel.
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum JxlDataType {
/// Use 32-bit single-precision floating point values, with range 0.0-1.0
/// (within gamut, may go outside this range for wide color gamut). Floating
/// point output, either [`JxlDataType::Float`] or [`JxlDataType::Float16`], is recommended
/// for HDR and wide gamut images when color profile conversion is required.
Float = 0,
/// Use type `u8`. May clip wide color gamut data.
Uint8 = 2,
/// Use type `u16`. May clip wide color gamut data.
Uint16 = 3,
/// Use 16-bit IEEE 754 half-precision floating point values.
Float16 = 5,
}
/// Ordering of multi-byte data.
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum JxlEndianness {
/// Use the endianness of the system, either little endian or big endian,
/// without forcing either specific endianness. Do not use if pixel data
/// should be exported to a well defined format.
Native = 0,
/// Force little endian
Little = 1,
/// Force big endian
Big = 2,
}
/// Data type for the sample values per channel per pixel for the output buffer
/// for pixels. This is not necessarily the same as the data type encoded in the
/// codestream. The channels are interleaved per pixel. The pixels are
/// organized row by row, left to right, top to bottom.
/// TODO: support different channel orders if needed (RGB, BGR, ...)
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct JxlPixelFormat {
/// Amount of channels available in a pixel buffer.
/// 1: single-channel data, e.g. grayscale or a single extra channel
/// 2: single-channel + alpha
/// 3: trichromatic, e.g. RGB
/// 4: trichromatic + alpha
/// TODO: this needs finetuning. It is not yet defined how the user
/// chooses output color space. CMYK+alpha needs 5 channels.
pub num_channels: u32,
/// Data type of each channel.
pub data_type: JxlDataType,
/// Whether multi-byte data types are represented in big endian or little
/// endian format. This applies to [`JxlDataType::Uint16`] and [`JxlDataType::Float`].
pub endianness: JxlEndianness,
/// Align scanlines to a multiple of align bytes, or 0 to require no
/// alignment at all (which has the same effect as value 1)
pub align: usize,
}
/// Settings for the interpretation of UINT input and output buffers.
/// (buffers using a FLOAT data type are not affected by this)
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum JxlBitDepthType {
/// This is the default setting, where the encoder expects the input pixels
/// to use the full range of the pixel format data type (e.g. for UINT16, the
/// input range is 0 .. 65535 and the value 65535 is mapped to 1.0 when
/// converting to float), and the decoder uses the full range to output
/// pixels. If the bit depth in the basic info is different from this, the
/// encoder expects the values to be rescaled accordingly (e.g. multiplied by
/// 65535/4095 for a 12-bit image using UINT16 input data type).
FromPixelFormat = 0,
/// If this setting is selected, the encoder expects the input pixels to be
/// in the range defined by the [`JxlBasicInfo::bits_per_sample`] value (e.g.
/// for 12-bit images using UINT16 input data types, the allowed range is
/// 0 .. 4095 and the value 4095 is mapped to 1.0 when converting to float),
/// and the decoder outputs pixels in this range.
FromCodestream = 1,
/// This setting can only be used in the decoder to select a custom range for
/// pixel output.
Custom = 2,
}
/// Data type for describing the interpretation of the input and output buffers
/// in terms of the range of allowed input and output pixel values.
#[repr(C)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct JxlBitDepth {
/// Bit depth setting, see comment on [`JxlBitDepthType`]
pub r#type: JxlBitDepthType,
/// Custom bits per sample
pub bits_per_sample: u32,
/// Custom exponent bits per sample
pub exponent_bits_per_sample: u32,
}
/// Data type holding the 4-character type name of an ISOBMFF box.
#[repr(transparent)]
pub struct JxlBoxType(pub [c_char; 4]);
jpegxl-sys-0.11.2+libjxl-0.11.1/src/common.rs 0000644 0000000 0000000 00000001354 10461020230 0016436 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! `jxl_common`: Common utilities for the JPEG XL library.
pub mod memory_manager;
pub mod types;
jpegxl-sys-0.11.2+libjxl-0.11.1/src/decode.rs 0000644 0000000 0000000 00000231126 10461020230 0016373 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Decoding API for JPEG XL.
use std::{
ffi::c_void,
os::raw::{c_char, c_int},
};
use crate::{
color::{cms_interface::JxlCmsInterface, color_encoding::JxlColorEncoding},
common::memory_manager::JxlMemoryManager,
common::types::{JxlBitDepth, JxlBool, JxlBoxType, JxlPixelFormat},
metadata::codestream_header::{
JxlBasicInfo, JxlBlendInfo, JxlExtraChannelInfo, JxlFrameHeader,
},
threads::parallel_runner::JxlParallelRunner,
};
#[cfg(doc)]
use crate::{
common::types::JxlBitDepthType,
metadata::codestream_header::{JxlOrientation, JxlPreviewHeader},
};
/// The result of [`JxlSignatureCheck`].
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlSignature {
/// Not enough bytes were passed to determine if a valid signature was found.
NotEnoughBytes = 0,
/// No valid JPEG XL header was found.
Invalid = 1,
/// A valid JPEG XL codestream signature was found, that is a JPEG XL image
/// without container.
Codestream = 2,
/// A valid container signature was found, that is a JPEG XL image embedded
/// in a box format container.
Container = 3,
}
/// Opaque structure that holds the JPEG XL decoder.
///
/// Allocated and initialized with [`JxlDecoderCreate`].
/// Cleaned up and deallocated with [`JxlDecoderDestroy`].
#[repr(C)]
pub struct JxlDecoder {
_unused: [u8; 0],
}
/// Return value for [`JxlDecoderProcessInput`].
/// The values from [`JxlDecoderStatus::BasicInfo`] onwards are optional informative
/// events that can be subscribed to, they are never returned if they
/// have not been registered with [`JxlDecoderSubscribeEvents`].
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlDecoderStatus {
/// Function call finished successfully, or decoding is finished and there is
/// nothing more to be done.
///
/// Note that [`JxlDecoderProcessInput`] will return [`JxlDecoderStatus::Success`] if
/// all events that were registered with [`JxlDecoderSubscribeEvents`] were
/// processed, even before the end of the JPEG XL codestream.
///
/// In this case, the return value [`JxlDecoderReleaseInput`] will be the same
/// as it was at the last signaled event. E.g. if [`JxlDecoderStatus::FullImage`] was
/// subscribed to, then all bytes from the end of the JPEG XL codestream
/// (including possible boxes needed for jpeg reconstruction) will be returned
/// as unprocessed.
Success = 0,
/// An error occurred, for example invalid input file or out of memory.
/// TODO: add function to get error information from decoder.
Error = 1,
/// The decoder needs more input bytes to continue. Before the next [`JxlDecoderProcessInput`]
/// call, more input data must be set, by calling [`JxlDecoderReleaseInput`] (if input was set previously)
/// and then calling [`JxlDecoderSetInput`]. [`JxlDecoderReleaseInput`] returns how many bytes
/// are not yet processed, before a next call to [`JxlDecoderProcessInput`]
/// all unprocessed bytes must be provided again (the address need not match,
/// but the contents must), and more bytes must be concatenated after the
/// unprocessed bytes.
/// In most cases, [`JxlDecoderReleaseInput`] will return no unprocessed bytes
/// at this event, the only exceptions are if the previously set input ended
/// within (a) the raw codestream signature, (b) the signature box, (c) a box
/// header, or (d) the first 4 bytes of a `brob`, `ftyp`, or `jxlp` box. In any
/// of these cases the number of unprocessed bytes is less than 20.
NeedMoreInput = 2,
/// The decoder is able to decode a preview image and requests setting a
/// preview output buffer using [`JxlDecoderSetPreviewOutBuffer`]. This occurs
/// if [`JxlDecoderStatus::PreviewImage`] is requested and it is possible to decode a
/// preview image from the codestream and the preview out buffer was not yet
/// set. There is maximum one preview image in a codestream.
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the frame header (including `ToC`) of the preview frame as
/// unprocessed.
NeedPreviewOutBuffer = 3,
/// The decoder requests an output buffer to store the full resolution image,
/// which can be set with [`JxlDecoderSetImageOutBuffer`] or with [`JxlDecoderSetImageOutCallback`].
/// This event re-occurs for new frames if there are multiple animation frames and requires setting an output again.
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the frame header (including `ToC`) as unprocessed.
NeedImageOutBuffer = 5,
/// The JPEG reconstruction buffer is too small for reconstructed JPEG
/// codestream to fit. [`JxlDecoderSetJPEGBuffer`] must be called again to
/// make room for remaining bytes. This event may occur multiple times
/// after [`JxlDecoderStatus::JPEGReconstruction`].
JPEGNeedMoreOutput = 6,
/// The box contents output buffer is too small. [`JxlDecoderSetBoxBuffer`]
/// must be called again to make room for remaining bytes. This event may occur
/// multiple times after [`JxlDecoderStatus::Box`].
BoxNeedMoreOutput = 7,
/// Informative event by [`JxlDecoderProcessInput`]: Basic information such as image dimensions and
/// extra channels. This event occurs max once per image.
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the basic info as unprocessed (including the last byte of basic info
/// if it did not end on a byte boundary).
BasicInfo = 0x40,
/// Informative event by [`JxlDecoderProcessInput`]: Color encoding or ICC profile from the
/// codestream header. This event occurs max once per image and always later
/// than [`JxlDecoderStatus::BasicInfo`] and earlier than any pixel data.
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the image header (which is the start of the first frame) as
/// unprocessed.
ColorEncoding = 0x100,
/// Informative event by [`JxlDecoderProcessInput`]: Preview image, a small frame, decoded. This
/// event can only happen if the image has a preview frame encoded. This event
/// occurs max once for the codestream and always later than [`JxlDecoderStatus::ColorEncoding`]
/// and before [`JxlDecoderStatus::Frame`]. In this case, [`JxlDecoderReleaseInput`] will return all bytes
/// from the end of the preview frame as unprocessed.
PreviewImage = 0x200,
/// Informative event by [`JxlDecoderProcessInput`]: Beginning of a frame. [`JxlDecoderGetFrameHeader`] can be
/// used at this point.
///
/// ## Note:
///
/// a JPEG XL image can have internal frames that are not intended to be
/// displayed (e.g. used for compositing a final frame), but this only returns
/// displayed frames, unless [`JxlDecoderSetCoalescing`] was set to [`JxlBool::False`]:
/// in that case, the individual layers are returned, without blending.
/// Note that even when coalescing is disabled, only frames of type `kRegularFrame` are returned;
/// frames of type `kReferenceOnly` and `kLfFrame` are always for internal purposes only and cannot be accessed.
/// A displayed frame either has an animation duration or is the only or last
/// frame in the image. This event occurs max once per displayed frame, always
/// later than [`JxlDecoderStatus::ColorEncoding`], and always earlier than any pixel
/// data. While JPEG XL supports encoding a single frame as the composition of
/// multiple internal sub-frames also called frames, this event is not
/// indicated for the internal frames. In this case, [`JxlDecoderReleaseInput`] will return all bytes
/// from the end of the frame header (including `ToC`) as unprocessed.
Frame = 0x400,
/// Informative event by [`JxlDecoderProcessInput`]: full frame (or layer, in case coalescing is
/// disabled) is decoded. [`JxlDecoderSetImageOutBuffer`] must be used after
/// getting the basic image information to be able to get the image pixels, if
/// not this return status only indicates we're past this point in the
/// codestream. This event occurs max once per frame.
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the frame (or if [`JxlDecoderStatus::JPEGReconstruction`] is subscribed to,
/// from the end of the last box that is needed for jpeg reconstruction) as
/// unprocessed.
FullImage = 0x1000,
/// Informative event by [`JxlDecoderProcessInput`]: JPEG reconstruction data decoded.
/// [`JxlDecoderSetJPEGBuffer`] may be used to set a JPEG reconstruction buffer
/// after getting the JPEG reconstruction data. If a JPEG reconstruction buffer
/// is set a byte stream identical to the JPEG codestream used to encode the
/// image will be written to the JPEG reconstruction buffer instead of pixels
/// to the image out buffer. This event occurs max once per image and always
/// before [`JxlDecoderStatus::FullImage`].
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the `jbrd` box as unprocessed.
JPEGReconstruction = 0x2000,
/// Informative event by [`JxlDecoderProcessInput`]: The header of a box of the container format
/// (BMFF) is decoded. The following API functions related to boxes can be used
/// after this event:
/// - [`JxlDecoderSetBoxBuffer`] and [`JxlDecoderReleaseBoxBuffer`]: set and release a buffer to get the box
/// data.
/// - [`JxlDecoderGetBoxType`] get the 4-character box typename.
/// - [`JxlDecoderGetBoxSizeRaw`] get the size of the box as it appears in
/// the container file, not decompressed.
/// - [`JxlDecoderSetDecompressBoxes`] to configure whether to get the box
/// data decompressed, or possibly compressed.
///
/// Boxes can be compressed. This is so when their box type is
/// "brob". In that case, they have an underlying decompressed box
/// type and decompressed data. [`JxlDecoderSetDecompressBoxes`] allows
/// configuring which data to get. Decompressing requires
/// Brotli. [`JxlDecoderGetBoxType`] has a flag to get the compressed box
/// type, which can be "brob", or the decompressed box type. If a box
/// is not compressed (its compressed type is not "brob"), then
/// the output decompressed box type and data is independent of what
/// setting is configured.
///
/// The buffer set with [`JxlDecoderSetBoxBuffer`] must be set again for each
/// next box to be obtained, or can be left unset to skip outputting this box.
/// The output buffer contains the full box data when the
/// [`JxlDecoderStatus::BoxComplete`] (if subscribed to) or subsequent [`JxlDecoderStatus::Success`]
/// or subsequent [`JxlDecoderStatus::Box`] event occurs. [`JxlDecoderStatus::Box`] occurs for all boxes,
/// including non-metadata boxes such as the signature box or codestream boxes.
/// To check whether the box is a metadata type for respectively EXIF, XMP or
/// JUMBF, use [`JxlDecoderGetBoxType`] and check for types "Exif", "xml " and
/// "jumb" respectively.
///
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// start of the box header as unprocessed.
Box = 0x4000,
/// Informative event by [`JxlDecoderProcessInput`]: a progressive step in decoding the frame is
/// reached. When calling [`JxlDecoderFlushImage`] at this point, the flushed
/// image will correspond exactly to this point in decoding, and not yet
/// contain partial results (such as partially more fine detail) of a next
/// step. By default, this event will trigger maximum once per frame, when a
/// 8x8th resolution (DC) image is ready (the image data is still returned at
/// full resolution, giving upscaled DC). Use [`JxlDecoderSetProgressiveDetail`] to configure more fine-grainedness.
/// The event is not guaranteed to trigger, not all images have progressive steps
/// or DC encoded.
/// In this case, [`JxlDecoderReleaseInput`] will return all bytes from the
/// end of the section that was needed to produce this progressive event as
/// unprocessed.
FrameProgression = 0x8000,
/// The box being decoded is now complete. This is only emitted if a buffer
/// was set for the box.
BoxComplete = 0x10000,
}
/// Types of progressive detail.
/// Setting a progressive detail with value N implies all progressive details
/// with smaller or equal value. Currently only the following level of
/// progressive detail is implemented:
/// - [`JxlProgressiveDetail::DC`] (which implies [`JxlProgressiveDetail::Frames`])
/// - [`JxlProgressiveDetail::LastPasses`] (which implies [`JxlProgressiveDetail::DC`]
/// and [`JxlProgressiveDetail::Frames`])
/// - [`JxlProgressiveDetail::Passes`] (which implies [`JxlProgressiveDetail::LastPasses`],
/// [`JxlProgressiveDetail::DC`] and [`JxlProgressiveDetail::Frames`])
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlProgressiveDetail {
/// After completed kRegularFrames
Frames = 0,
/// After completed DC (1:8)
DC = 1,
/// After completed AC passes that are the last pass for their resolution target.
LastPasses = 2,
/// After completed AC passes that are not the last pass for their resolution target.
Passes = 3,
/// During DC frame when lower resolutions are completed (1:32, 1:16)
DCProgressive = 4,
/// After completed groups
DCGroups = 5,
/// After completed groups
Groups = 6,
}
/// Defines which color profile to get: the profile from the codestream
/// metadata header, which represents the color profile of the original image,
/// or the color profile from the pixel data produced by the decoder. Both are
/// the same if the [`JxlBasicInfo`] has `uses_original_profile` set.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlColorProfileTarget {
Original = 0,
Data = 1,
}
/// Function type for [`JxlDecoderSetImageOutCallback`].
///
/// The callback may be called simultaneously by different threads when using a
/// threaded parallel runner, on different pixels.
///
/// # Parameters
/// - `opaque`: optional user data, as given to [`JxlDecoderSetImageOutCallback`].
/// - `x`: horizontal position of leftmost pixel of the pixel data.
/// - `y`: vertical position of the pixel data.
/// - `num_pixels`: amount of pixels included in the pixel data, horizontally.
/// This is not the same as xsize of the full image, it may be smaller.
/// - `pixels`: pixel data as a horizontal stripe, in the format passed to
/// [`JxlDecoderSetImageOutCallback`]. The memory is not owned by the user, and
/// is only valid during the time the callback is running.
pub type JxlImageOutCallback = extern "C" fn(
opaque: *mut c_void,
x: usize,
y: usize,
num_pixels: usize,
pixels: *const c_void,
);
/// Initialization callback for [`JxlDecoderSetMultithreadedImageOutCallback`].
///
/// # Parameters
/// - `init_opaque`: optional user data, as given to
/// [`JxlDecoderSetMultithreadedImageOutCallback`].
/// - `num_threads`: maximum number of threads that will call the [`run`](JxlImageOutRunCallback)
/// callback concurrently.
/// - `num_pixels_per_thread`: maximum number of pixels that will be passed in
/// one call to [`run`](JxlImageOutRunCallback).
///
/// # Returns
/// - a pointer to data that will be passed to the [`run`](JxlImageOutRunCallback) callback, or
/// `NULL` if initialization failed.
pub type JxlImageOutInitCallback = extern "C" fn(
init_opaque: *mut c_void,
num_threads: usize,
num_pixels_per_thread: usize,
) -> *mut c_void;
/// Worker callback for [`JxlDecoderSetMultithreadedImageOutCallback`]
///
/// # Parameters
/// - `run_opaque`: user data returned by the [`init`](JxlImageOutInitCallback) callback.
/// - `thread_id`: number in `[0, num_threads)` identifying the thread of the
/// current invocation of the callback.
/// - `x`: horizontal position of the first (leftmost) pixel of the pixel data.
/// - `y`: vertical position of the pixel data.
/// - `num_pixels`: number of pixels in the pixel data. May be less than the
/// full `xsize` of the image, and will be at most equal to the `num_pixels_per_thread`
/// that was passed to [`init`](JxlImageOutInitCallback).
/// - `pixels`: pixel data as a horizontal stripe, in the format passed to
/// [`JxlDecoderSetMultithreadedImageOutCallback`]. The data pointed to
/// remains owned by the caller and is only guaranteed to outlive the current
/// callback invocation.
pub type JxlImageOutRunCallback = extern "C" fn(
run_opaque: *mut c_void,
thread_id: usize,
x: usize,
y: usize,
num_pixels: usize,
pixels: *const c_void,
);
///
/// Destruction callback for [`JxlDecoderSetMultithreadedImageOutCallback`],
/// called after all invocations of the [`run`](JxlImageOutCallback) callback to perform any
/// appropriate clean-up of the `run_opaque` data returned by [`init`](JxlImageOutInitCallback).
///
/// # Parameters
/// - `run_opaque`: user data returned by the [`init`](JxlImageOutInitCallback) callback.
pub type JxlImageOutDestroyCallback = extern "C" fn(run_opaque: *mut c_void);
extern "C-unwind" {
/// Decoder library version.
///
/// # Returns
/// The decoder library version as an integer:
/// `MAJOR_VERSION * 1000000 + MINOR_VERSION * 1000 + PATCH_VERSION`. For example,
/// version 1.2.3 would return 1002003.
pub fn JxlDecoderVersion() -> u32;
/// JPEG XL signature identification.
///
/// Checks if the passed buffer contains a valid JPEG XL signature. The passed `buf` of size
/// `size` doesn't need to be a full image, only the beginning of the file.
///
/// # Returns
/// A flag indicating if a JPEG XL signature was found and what type.
/// - [`JxlSignature::NotEnoughBytes`] if not enough bytes were passed to
/// determine if a valid signature is there.
/// - [`JxlSignature::Invalid`] if no valid signature found for JPEG XL decoding.
/// - [`JxlSignature::Codestream`] if a valid JPEG XL codestream signature was
/// found.
/// - [`JxlSignature::Container`] if a valid JPEG XL container signature was found.
pub fn JxlSignatureCheck(buf: *const u8, len: usize) -> JxlSignature;
/// Creates an instance of [`JxlDecoder`] and initializes it.
///
/// `memory_manager` will be used for all the library dynamic allocations made
/// from this instance. The parameter may be `NULL`, in which case the default
/// allocator will be used. See [`crate::common::memory_manager`] for details.
///
/// # Parameters
/// - `memory_manager`: custom allocator function. It may be `NULL`. The memory
/// manager will be copied internally.
///
/// # Returns
/// - `NULL` if the instance cannot be allocated or initialized.
/// - Pointer to initialized [`JxlDecoder`] otherwise.
pub fn JxlDecoderCreate(memory_manager: *const JxlMemoryManager) -> *mut JxlDecoder;
/// Re-initializes a [`JxlDecoder`] instance, so it can be re-used for decoding
/// another image. All state and settings are reset as if the object was
/// newly created with [`JxlDecoderCreate`], but the memory manager is kept.
///
/// # Parameters
/// - `dec`: instance to be re-initialized.
pub fn JxlDecoderReset(dec: *mut JxlDecoder);
/// Deinitializes and frees [`JxlDecoder`] instance.
///
/// # Parameters
/// - `dec`: instance to be cleaned up and deallocated.
pub fn JxlDecoderDestroy(dec: *mut JxlDecoder);
/// Rewinds decoder to the beginning. The same input must be given again from
/// the beginning of the file and the decoder will emit events from the beginning
/// again. When rewinding (as opposed to [`JxlDecoderReset`]), the decoder can
/// keep state about the image, which it can use to skip to a requested frame
/// more efficiently with [`JxlDecoderSkipFrames`]. Settings such as parallel
/// runner or subscribed events are kept. After rewind, [`JxlDecoderSubscribeEvents`]
/// can be used again, and it is feasible to leave out events that were already
/// handled before, such as [`JxlDecoderStatus::BasicInfo`] and [`JxlDecoderStatus::ColorEncoding`],
/// since they will provide the same information as before.
/// The difference to [`JxlDecoderReset`] is that some state is kept, namely
/// settings set by a call to
/// - [`JxlDecoderSetCoalescing`],
/// - [`JxlDecoderSetDesiredIntensityTarget`],
/// - [`JxlDecoderSetDecompressBoxes`],
/// - [`JxlDecoderSetKeepOrientation`],
/// - [`JxlDecoderSetUnpremultiplyAlpha`],
/// - [`JxlDecoderSetParallelRunner`],
/// - [`JxlDecoderSetRenderSpotcolors`], and
/// - [`JxlDecoderSubscribeEvents`].
///
/// # Parameters
/// - `dec`: decoder object
pub fn JxlDecoderRewind(dec: *mut JxlDecoder);
/// Makes the decoder skip the next `amount` frames. It still needs to process
/// the input, but will not output the frame events. It can be more efficient
/// when skipping frames, and even more so when using this after [`JxlDecoderRewind`].
/// If the decoder is already processing a frame (could have emitted [`JxlDecoderStatus::Frame`]
/// but not yet [`JxlDecoderStatus::FullImage`]), it starts skipping from the next frame.
/// If the amount is larger than the amount of frames remaining in the image, all remaining
/// frames are skipped. Calling this function multiple times adds the amount to skip to the
/// already existing amount.
///
/// A frame here is defined as a frame that without skipping emits events such
/// as [`JxlDecoderStatus::Frame`] and [`JxlDecoderStatus::FullImage`], frames that are internal
/// to the file format but are not rendered as part of an animation, or are not
/// the final still frame of a still image, are not counted.
///
/// # Parameters
/// - `dec`: decoder object
/// - `amount`: the amount of frames to skip
pub fn JxlDecoderSkipFrames(dec: *mut JxlDecoder, amount: usize);
/// Skips processing the current frame. Can be called after frame processing
/// already started, signaled by a [`JxlDecoderStatus::NeedImageOutBuffer`] event,
/// but before the corresponding [`JxlDecoderStatus::FullImage`] event. The next signaled
/// event will be another [`JxlDecoderStatus::Frame`], or [`JxlDecoderStatus::Success`] if there
/// are no more frames. If pixel data is required from the already processed part
/// of the frame, [`JxlDecoderFlushImage`] must be called before this.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if there is a frame to skip, and
/// - [`JxlDecoderStatus::Error`] if the function was not called during frame processing.
pub fn JxlDecoderSkipCurrentFrame(dec: *mut JxlDecoder) -> JxlDecoderStatus;
/// Set the parallel runner for multithreading. May only be set before starting
/// decoding.
///
/// # Parameters
/// - `dec`: decoder object
/// - `parallel_runner`: function pointer to runner for multithreading. It may
/// be `NULL` to use the default, single-threaded, runner. A multithreaded
/// runner should be set to reach fast performance.
/// - `parallel_runner_opaque`: opaque pointer for `parallel_runner`.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the runner was set, [`JxlDecoderStatus::Error`]
/// otherwise (the previous runner remains set).
pub fn JxlDecoderSetParallelRunner(
dec: *mut JxlDecoder,
parallel_runner: JxlParallelRunner,
parallel_runner_opaque: *mut c_void,
) -> JxlDecoderStatus;
/// Returns a hint indicating how many more bytes the decoder is expected to
/// need to make [`JxlDecoderGetBasicInfo`] available after the next
/// [`JxlDecoderProcessInput`] call. This is a suggested large enough value for
/// the amount of bytes to provide in the next [`JxlDecoderSetInput`] call, but
/// it is not guaranteed to be an upper bound nor a lower bound. This number does
/// not include bytes that have already been released from the input. Can be used
/// before the first [`JxlDecoderProcessInput`] call, and is correct the first
/// time in most cases. If not, [`JxlDecoderSizeHintBasicInfo`] can be called
/// again to get an updated hint.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// - the size hint in bytes if the basic info is not yet fully decoded.
/// - 0 when the basic info is already available.
pub fn JxlDecoderSizeHintBasicInfo(dec: *const JxlDecoder) -> usize;
/// Select for which informative events, i.e. [`JxlDecoderStatus::BasicInfo`], etc., the
/// decoder should return with a status. It is not required to subscribe to any
/// events, data can still be requested from the decoder as soon as it is available.
/// By default, the decoder is subscribed to no events (`events_wanted == 0`), and
/// the decoder will then only return when it cannot continue because it needs
/// more input data or more output buffer. This function may only be called
/// before using [`JxlDecoderProcessInput`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `events_wanted`: bitfield of desired events.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if no error, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSubscribeEvents(
dec: *mut JxlDecoder,
events_wanted: c_int,
) -> JxlDecoderStatus;
/// Enables or disables preserving of as-in-bitstream pixeldata
/// orientation. Some images are encoded with an Orientation tag
/// indicating that the decoder must perform a rotation and/or
/// mirroring to the encoded image data.
///
/// - If `skip_reorientation` is [`JxlBool::False`] (the default): the decoder
/// will apply the transformation from the orientation setting, hence
/// rendering the image according to its specified intent. When
/// producing a [`JxlBasicInfo`], the decoder will always set the
/// orientation field to [`JxlOrientation::Identity`] (matching the returned
/// pixel data) and also align xsize and ysize so that they correspond
/// to the width and the height of the returned pixel data.
/// - If `skip_reorientation` is [`JxlBool::True`]: the decoder will skip
/// applying the transformation from the orientation setting, returning
/// the image in the as-in-bitstream pixeldata orientation.
/// This may be faster to decode since the decoder doesn't have to apply the
/// transformation, but can cause wrong display of the image if the
/// orientation tag is not correctly taken into account by the user.
///
/// By default, this option is disabled, and the returned pixel data is
/// re-oriented according to the image's Orientation setting.
///
/// This function must be called at the beginning, before decoding is performed.
///
/// See [`JxlBasicInfo`] for the orientation field, and [`JxlOrientation`] for the
/// possible values.
///
/// # Parameters
/// - `dec`: decoder object
/// - `skip_reorientation`: [`JxlBool::True`] to enable, [`JxlBool::False`] to disable.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if no error, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetKeepOrientation(
dec: *mut JxlDecoder,
keep_orientation: JxlBool,
) -> JxlDecoderStatus;
/// Enables or disables preserving of associated alpha channels. If
/// `unpremul_alpha` is set to [`JxlBool::False`] then for associated alpha channel,
/// the pixel data is returned with premultiplied colors. If it is set to [`JxlBool::True`],
/// the colors will be unpremultiplied based on the alpha channel. This
/// function has no effect if the image does not have an associated alpha
/// channel.
///
/// By default, this option is disabled, and the returned pixel data is "as is".
///
/// This function must be called at the beginning, before decoding is performed.
///
/// # Parameters
/// - `dec`: decoder object
/// - `unpremul_alpha`: [`JxlBool::True`] to enable, [`JxlBool::False`] to disable.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if no error, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetUnpremultiplyAlpha(
dec: *mut JxlDecoder,
unpremul_alpha: JxlBool,
) -> JxlDecoderStatus;
/// Enables or disables rendering spot colors. By default, spot colors
/// are rendered, which is OK for viewing the decoded image. If `render_spotcolors`
/// is [`JxlBool::False`], then spot colors are not rendered, and have to be
/// retrieved separately using [`JxlDecoderSetExtraChannelBuffer`]. This is
/// useful for e.g. printing applications.
///
/// # Parameters
/// - `dec`: decoder object
/// - `render_spotcolors`: [`JxlBool::True`] to enable (default), [`JxlBool::False`] to disable.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if no error, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetRenderSpotcolors(
dec: *mut JxlDecoder,
render_spotcolors: JxlBool,
) -> JxlDecoderStatus;
/// Enables or disables coalescing of zero-duration frames. By default, frames
/// are returned with coalescing enabled, i.e. all frames have the image
/// dimensions, and are blended if needed. When coalescing is disabled, frames
/// can have arbitrary dimensions, a non-zero crop offset, and blending is not
/// performed. For display, coalescing is recommended. For loading a multi-layer
/// still image as separate layers (as opposed to the merged image), coalescing
/// has to be disabled.
///
/// # Parameters
/// - `dec`: decoder object
/// - `coalescing`: [`JxlBool::True`] to enable coalescing (default), [`JxlBool::False`] to
/// disable it.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if no error, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetCoalescing(dec: *mut JxlDecoder, coalescing: JxlBool) -> JxlDecoderStatus;
/// Decodes JPEG XL file using the available bytes. Requires input has been
/// set with [`JxlDecoderSetInput`]. After [`JxlDecoderProcessInput`], input
/// can optionally be released with [`JxlDecoderReleaseInput`] and then set
/// again to next bytes in the stream. [`JxlDecoderReleaseInput`] returns how
/// many bytes are not yet processed, before a next call to [`JxlDecoderProcessInput`]
/// all unprocessed bytes must be provided again (the address need not match, but the contents must),
/// and more bytes may be concatenated after the unprocessed bytes.
///
/// The returned status indicates whether the decoder needs more input bytes, or
/// more output buffer for a certain type of output data. No matter what the
/// returned status is (other than [`JxlDecoderStatus::Error`]), new information,
/// such as [`JxlDecoderGetBasicInfo`], may have become available after this call.
/// When the return value is not [`JxlDecoderStatus::Error`] or [`JxlDecoderStatus::Success`], the
/// decoding requires more [`JxlDecoderProcessInput`] calls to continue.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] when decoding finished and all events handled.
/// If you still have more unprocessed input data anyway, then you can still
/// continue by using [`JxlDecoderSetInput`] and calling [`JxlDecoderProcessInput`] again,
/// similar to handling [`JxlDecoderStatus::NeedMoreInput`]. [`JxlDecoderStatus::Success`] can occur instead of
/// [`JxlDecoderStatus::NeedMoreInput`] when, for example, the input data ended right at
/// the boundary of a box of the container format, all essential codestream
/// boxes were already decoded, but extra metadata boxes are still present in
/// the next data. [`JxlDecoderProcessInput`] cannot return success if all
/// codestream boxes have not been seen yet.
/// - [`JxlDecoderStatus::Error`] when decoding failed, e.g. invalid codestream.
/// - [`JxlDecoderStatus::NeedMoreInput`] when more input data is necessary.
/// - [`JxlDecoderStatus::BasicInfo`] when basic info such as image dimensions is
/// available and this informative event is subscribed to.
/// - [`JxlDecoderStatus::ColorEncoding`] when color profile information is
/// available and this informative event is subscribed to.
/// - [`JxlDecoderStatus::PreviewImage`] when preview pixel information is
/// available and output in the preview buffer.
/// - [`JxlDecoderStatus::FullImage`] when all pixel information at highest detail
/// is available and has been output in the pixel buffer.
pub fn JxlDecoderProcessInput(dec: *mut JxlDecoder) -> JxlDecoderStatus;
/// Sets input data for [`JxlDecoderProcessInput`]. The data is owned by the
/// caller and may be used by the decoder until [`JxlDecoderReleaseInput`] is
/// called or the decoder is destroyed or reset, so it must be kept alive until then.
/// Cannot be called if [`JxlDecoderSetInput`] was already called and [`JxlDecoderReleaseInput`]
/// was not yet called, and cannot be called after [`JxlDecoderCloseInput`] indicating the end
/// of input was called.
///
/// # Parameters
/// - `dec`: decoder object
/// - `data`: pointer to next bytes to read from
/// - `size`: amount of bytes available starting from data
///
/// # Returns
/// - [`JxlDecoderStatus::Error`] if input was already set without releasing or [`JxlDecoderCloseInput`]
/// was already called
/// - [`JxlDecoderStatus::Success`] otherwise
pub fn JxlDecoderSetInput(
dec: *mut JxlDecoder,
data: *const u8,
size: usize,
) -> JxlDecoderStatus;
/// Releases input which was provided with [`JxlDecoderSetInput`]. Between
/// [`JxlDecoderProcessInput`] and [`JxlDecoderReleaseInput`], the user may not
/// alter the data in the buffer. Calling [`JxlDecoderReleaseInput`] is required
/// whenever any input is already set and new input needs to be added with
/// [`JxlDecoderSetInput`], but is not required before [`JxlDecoderDestroy`] or
/// [`JxlDecoderReset`]. Calling [`JxlDecoderReleaseInput`] when no input is set
/// is not an error and returns `0`.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// The amount of bytes the decoder has not yet processed that are still
/// remaining in the data set by [`JxlDecoderSetInput`], or `0` if no input is
/// set or [`JxlDecoderReleaseInput`] was already called. For a next call to
/// [`JxlDecoderProcessInput`], the buffer must start with these unprocessed
/// bytes. From this value it is possible to infer the position of certain JPEG
/// XL codestream elements (e.g. end of headers, frame start/end). See the
/// documentation of individual values of [`JxlDecoderStatus`] for more
/// information.
pub fn JxlDecoderReleaseInput(dec: *mut JxlDecoder) -> usize;
/// Marks the input as finished, indicates that no more [`JxlDecoderSetInput`]
/// will be called. This function allows the decoder to determine correctly if it
/// should return success, need more input or error in certain cases. For
/// backwards compatibility with a previous version of the API, using this
/// function is optional when not using the [`JxlDecoderStatus::Box`] event (the decoder
/// is able to determine the end of the image frames without marking the end),
/// but using this function is required when using [`JxlDecoderStatus::Box`] for getting
/// metadata box contents. This function does not replace [`JxlDecoderReleaseInput`],
/// that function should still be called if its return value is needed.
///
/// [`JxlDecoderCloseInput`] should be called as soon as all known input bytes
/// are set (e.g. at the beginning when not streaming but setting all input
/// at once), before the final [`JxlDecoderProcessInput`] calls.
///
/// # Parameters
/// - `dec`: decoder object
pub fn JxlDecoderCloseInput(dec: *mut JxlDecoder);
/// Outputs the basic image information, such as image dimensions, bit depth and
/// all other [`JxlBasicInfo`] fields, if available.
///
/// # Parameters
/// - `dec`: decoder object
/// - `info`: struct to copy the information into, or `NULL` to only check
/// whether the information is available through the return value.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the value is available
/// - [`JxlDecoderStatus::NeedMoreInput`] if not yet available
/// - [`JxlDecoderStatus::Error`] in case of other error conditions.
pub fn JxlDecoderGetBasicInfo(
dec: *const JxlDecoder,
info: *mut JxlBasicInfo,
) -> JxlDecoderStatus;
/// Outputs information for extra channel at the given index. The index must be
/// smaller than `num_extra_channels` in the associated [`JxlBasicInfo`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `index`: index of the extra channel to query.
/// - `info`: struct to copy the information into, or `NULL` to only check
/// whether the information is available through the return value.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the value is available
/// - [`JxlDecoderStatus::NeedMoreInput`] if not yet available
/// - [`JxlDecoderStatus::Error`] in case of other error conditions.
pub fn JxlDecoderGetExtraChannelInfo(
dec: *const JxlDecoder,
index: usize,
info: *mut JxlExtraChannelInfo,
) -> JxlDecoderStatus;
/// Outputs name for extra channel at the given index in UTF-8. The index must be
/// smaller than `num_extra_channels` in the associated [`JxlBasicInfo`]. The
/// buffer for name must have at least `name_length + 1` bytes allocated, gotten
/// from the associated [`JxlExtraChannelInfo`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `index`: index of the extra channel to query.
/// - `name`: buffer to copy the name into
/// - `size`: size of the name buffer in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the value is available
/// - [`JxlDecoderStatus::NeedMoreInput`] if not yet available
/// - [`JxlDecoderStatus::Error`] in case of other error conditions.
pub fn JxlDecoderGetExtraChannelName(
dec: *const JxlDecoder,
index: usize,
name: *mut c_char,
size: usize,
) -> JxlDecoderStatus;
/// Outputs the color profile as JPEG XL encoded structured data, if available.
/// This is an alternative to an ICC Profile, which can represent a more limited
/// amount of color spaces, but represents them exactly through enum values.
///
/// It is often possible to use [`JxlDecoderGetColorAsICCProfile`] as an
/// alternative anyway. The following scenarios are possible:
/// - The JPEG XL image has an attached ICC Profile, in that case, the encoded
/// structured data is not available and this function will return an error
/// status. [`JxlDecoderGetColorAsICCProfile`] should be called instead.
/// - The JPEG XL image has an encoded structured color profile, and it
/// represents an RGB or grayscale color space. This function will return it.
/// You can still use [`JxlDecoderGetColorAsICCProfile`] as well as an
/// alternative if desired, though depending on which RGB color space is
/// represented, the ICC profile may be a close approximation. It is also not
/// always feasible to deduce from an ICC profile which named color space it
/// exactly represents, if any, as it can represent any arbitrary space.
/// HDR color spaces such as those using PQ and HLG are also potentially
/// problematic, in that: while ICC profiles can encode a transfer function
/// that happens to approximate those of PQ and HLG (HLG for only one given
/// system gamma at a time, and necessitating a 3D LUT if gamma is to be
/// different from `1`), they cannot (before ICCv4.4) semantically signal that
/// this is the color space that they represent. Therefore, they will
/// typically not actually be interpreted as representing an HDR color space.
/// This is especially detrimental to PQ which will then be interpreted as if
/// the maximum signal value represented SDR white instead of 10000 cd/m^2,
/// meaning that the image will be displayed two orders of magnitude (5-7 EV)
/// too dim.
/// - The JPEG XL image has an encoded structured color profile, and it
/// indicates an unknown or xyb color space. In that case, [`JxlDecoderGetColorAsICCProfile`]
/// is not available.
///
/// When rendering an image on a system where ICC-based color management is used,
/// [`JxlDecoderGetColorAsICCProfile`] should generally be used first as it will
/// return a ready-to-use profile (with the aforementioned caveat about HDR).
/// When knowledge about the nominal color space is desired if available, [`JxlDecoderGetColorAsEncodedProfile`]
/// should be used first.
///
/// # Parameters
/// - `dec`: decoder object
/// - `target`: whether to get the original color profile from the metadata
/// or the color profile of the decoded pixels.
/// - `color_encoding`: struct to copy the information into, or `NULL` to only
/// check whether the information is available through the return value.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the data is available and returned
/// - [`JxlDecoderStatus::NeedMoreInput`] if not yet available
/// - [`JxlDecoderStatus::Error`] in case the encoded structured color profile does not exist in the
/// codestream.
pub fn JxlDecoderGetColorAsEncodedProfile(
dec: *const JxlDecoder,
target: JxlColorProfileTarget,
color_encoding: *mut JxlColorEncoding,
) -> JxlDecoderStatus;
/// Outputs the size in bytes of the ICC profile returned by [`JxlDecoderGetColorAsICCProfile`], if available,
/// or indicates there is none available. In most cases, the image will have an ICC profile available, but
/// if it does not, [`JxlDecoderGetColorAsEncodedProfile`] must be used instead.
///
/// See [`JxlDecoderGetColorAsEncodedProfile`] for more information. The ICC
/// profile is either the exact ICC profile attached to the codestream metadata,
/// or a close approximation generated from JPEG XL encoded structured data,
/// depending on what is encoded in the codestream.
///
/// # Parameters
/// - `dec`: decoder object
/// - `target`: whether to get the original color profile from the metadata
/// or the color profile of the decoded pixels.
/// - `size`: variable to output the size into, or `NULL` to only check the
/// return status.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the ICC profile is available
/// - [`JxlDecoderStatus::NeedMoreInput`] if the decoder has not yet received enough
/// input data to determine whether an ICC profile is available or what its
/// size is
/// - [`JxlDecoderStatus::Error`] in case the ICC profile is not available and
/// cannot be generated.
pub fn JxlDecoderGetICCProfileSize(
dec: *const JxlDecoder,
target: JxlColorProfileTarget,
size: *mut usize,
) -> JxlDecoderStatus;
/// Outputs ICC profile if available. The profile is only available if
/// [`JxlDecoderGetICCProfileSize`] returns success. The output buffer must have
/// at least as many bytes as given by [`JxlDecoderGetICCProfileSize`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `target`: whether to get the original color profile from the metadata
/// or the color profile of the decoded pixels.
/// - `icc_profile`: buffer to copy the ICC profile into
/// - `size`: size of the `icc_profile` buffer in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`]: if the profile was successfully returned
/// - [`JxlDecoderStatus::NeedMoreInput`]: if not yet available
/// - [`JxlDecoderStatus::Error`]: if the profile doesn't exist or the output size is not
/// large enough.
pub fn JxlDecoderGetColorAsICCProfile(
dec: *const JxlDecoder,
target: JxlColorProfileTarget,
icc_profile: *mut u8,
size: usize,
) -> JxlDecoderStatus;
/// Sets the desired output color profile of the decoded image by calling
/// [`JxlDecoderSetOutputColorProfile`], passing on `color_encoding` and
/// setting `icc_data` to `NULL`. See [`JxlDecoderSetOutputColorProfile`] for
/// details.
///
/// # Parameters
/// - `dec`: decoder object
/// - `color_encoding`: the default color encoding to set
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the preference was set successfully, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetPreferredColorProfile(
dec: *mut JxlDecoder,
color_encoding: *const JxlColorEncoding,
) -> JxlDecoderStatus;
/// Requests that the decoder perform tone mapping to the peak display luminance
/// passed as `desired_intensity_target`, if appropriate.
///
/// # Note
/// This is provided for convenience and the exact tone mapping that is
/// performed is not meant to be considered authoritative in any way. It may
/// change from version to version.
///
/// # Parameters
/// - `dec`: decoder object
/// - `desired_intensity_target`: the intended target peak luminance
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the preference was set successfully, [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetDesiredIntensityTarget(
dec: *mut JxlDecoder,
desired_intensity_target: f32,
) -> JxlDecoderStatus;
/// Sets the desired output color profile of the decoded image either from a
/// color encoding or an ICC profile. Valid calls of this function have either
/// `color_encoding` or `icc_data` set to `NULL` and `icc_size` must be `0` if and
/// only if `icc_data` is `NULL`.
///
/// Depending on whether a color management system (CMS) has been set the
/// behavior is as follows:
///
/// If a color management system (CMS) has been set with [`JxlDecoderSetCms`],
/// and the CMS supports output to the desired color encoding or ICC profile,
/// then it will provide the output in that color encoding or ICC profile. If the
/// desired color encoding or the ICC is not supported, then an error will be
/// returned.
///
/// If no CMS has been set with [`JxlDecoderSetCms`], there are two cases:
///
/// 1. Calling this function with a color encoding will convert XYB images to
/// the desired color encoding. In this case, if the requested color encoding has
/// a narrower gamut, or the white points differ, then the resulting image can
/// have significant color distortion. Non-XYB images will not be converted to
/// the desired color space.
///
/// 2. Calling this function with an ICC profile will result in an error.
///
/// If called with an ICC profile (after a call to [`JxlDecoderSetCms`]), the
/// ICC profile has to be a valid RGB or grayscale color profile.
///
/// Can only be set after the [`JxlDecoderStatus::ColorEncoding`] event occurred and
/// before any other event occurred, and should be used before getting
/// [`JxlColorProfileTarget::Data`].
///
/// This function must not be called before [`JxlDecoderSetCms`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `color_encoding`: the output color encoding
/// - `icc_data`: bytes of the icc profile
/// - `icc_size`: size of the icc profile in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the color profile was set successfully,
/// [`JxlDecoderStatus::Error`] otherwise.
pub fn JxlDecoderSetOutputColorProfile(
dec: *mut JxlDecoder,
color_encoding: *const JxlColorEncoding,
icc_data: *const u8,
icc_size: usize,
) -> JxlDecoderStatus;
/// Sets the color management system (CMS) that will be used for color
/// conversion (if applicable) during decoding. May only be set before starting
/// decoding and must not be called after [`JxlDecoderSetOutputColorProfile`].
///
/// See [`JxlDecoderSetOutputColorProfile`] for how color conversions are done
/// depending on whether or not a CMS has been set with [`JxlDecoderSetCms`].
///
/// # Parameters
/// - `dec`: decoder object.
/// - `cms`: structure representing a CMS implementation. See [`JxlCmsInterface`] for more details.
pub fn JxlDecoderSetCms(dec: *mut JxlDecoder, cms: JxlCmsInterface) -> JxlDecoderStatus;
/// Returns the minimum size in bytes of the preview image output pixel buffer
/// for the given format. This is the buffer for [`JxlDecoderSetPreviewOutBuffer`].
/// Requires the preview header information is available in the decoder.
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of pixels
/// - `size`: output value, buffer size in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success
/// - [`JxlDecoderStatus::Error`] on error, such as information not available yet.
pub fn JxlDecoderPreviewOutBufferSize(
dec: *const JxlDecoder,
format: *const JxlPixelFormat,
size: *mut usize,
) -> JxlDecoderStatus;
/// Sets the buffer to write the low-resolution preview image
/// to. The size of the buffer must be at least as large as given by [`JxlDecoderPreviewOutBufferSize`].
/// The buffer follows the format described by [`JxlPixelFormat`]. The preview image dimensions are given by the
/// [`JxlPreviewHeader`]. The buffer is owned by the caller.
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of pixels. Object owned by user and its contents are
/// copied internally.
/// - `buffer`: buffer type to output the pixel data to
/// - `size`: size of buffer in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such as
/// size too small.
pub fn JxlDecoderSetPreviewOutBuffer(
dec: *mut JxlDecoder,
format: *const JxlPixelFormat,
buffer: *mut c_void,
size: usize,
) -> JxlDecoderStatus;
/// Outputs the information from the frame, such as duration when `have_animation`.
/// This function can be called when [`JxlDecoderStatus::Frame`] occurred for the current
/// frame, even when `have_animation` in the [`JxlBasicInfo`] is [`JxlBool::False`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `header`: struct to copy the information into, or `NULL` to only check
/// whether the information is available through the return value.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the value is available
/// - [`JxlDecoderStatus::NeedMoreInput`] if not yet available
/// - [`JxlDecoderStatus::Error`] in case of other error conditions.
pub fn JxlDecoderGetFrameHeader(
dec: *const JxlDecoder,
header: *mut JxlFrameHeader,
) -> JxlDecoderStatus;
/// Outputs name for the current frame. The buffer for name must have at least
/// `name_length + 1` bytes allocated, gotten from the associated [`JxlFrameHeader`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `name`: buffer to copy the name into
/// - `size`: size of the name buffer in bytes, including zero termination
/// character, so this must be at least [`JxlFrameHeader::name_length`] + 1.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the value is available
/// - [`JxlDecoderStatus::NeedMoreInput`] if not yet available
/// - [`JxlDecoderStatus::Error`] in case of other error conditions.
pub fn JxlDecoderGetFrameName(
dec: *const JxlDecoder,
name: *mut c_char,
size: usize,
) -> JxlDecoderStatus;
/// Outputs the blend information for the current frame for a specific extra
/// channel. This function can be called once the [`JxlDecoderStatus::Frame`] event occurred
/// for the current frame, even if the `have_animation` field in the [`JxlBasicInfo`] is [`JxlBool::False`].
/// This information is only useful if coalescing is disabled; otherwise the decoder will have performed
/// blending already.
///
/// # Parameters
/// - `dec`: decoder object
/// - `index`: the index of the extra channel
/// - `blend_info`: struct to copy the information into
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success
/// - [`JxlDecoderStatus::Error`] on error
pub fn JxlDecoderGetExtraChannelBlendInfo(
dec: *const JxlDecoder,
index: usize,
blend_info: *mut JxlBlendInfo,
);
/// Returns the minimum size in bytes of the image output pixel buffer for the
/// given format. This is the buffer for [`JxlDecoderSetImageOutBuffer`].
/// Requires that the basic image information is available in the decoder in the
/// case of coalescing enabled (default). In case coalescing is disabled, this
/// can only be called after the [`JxlDecoderStatus::Frame`] event occurs. In that case,
/// it will return the size required to store the possibly cropped frame (which
/// can be larger or smaller than the image dimensions).
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of the pixels.
/// - `size`: output value, buffer size in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such as
/// information not available yet.
pub fn JxlDecoderImageOutBufferSize(
dec: *const JxlDecoder,
format: *const JxlPixelFormat,
size: *mut usize,
) -> JxlDecoderStatus;
/// Sets the buffer to write the full resolution image to. This can be set when
/// the [`JxlDecoderStatus::Frame`] event occurs, must be set when the
/// [`JxlDecoderStatus::NeedImageOutBuffer`] event occurs, and applies only for the
/// current frame. The size of the buffer must be at least as large as given
/// by [`JxlDecoderImageOutBufferSize`]. The buffer follows the format described
/// by [`JxlPixelFormat`]. The buffer is owned by the caller.
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of the pixels. Object owned by user and its contents
/// are copied internally.
/// - `buffer`: buffer type to output the pixel data to
/// - `size`: size of buffer in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such as
/// size too small.
pub fn JxlDecoderSetImageOutBuffer(
dec: *mut JxlDecoder,
format: *const JxlPixelFormat,
buffer: *mut c_void,
size: usize,
) -> JxlDecoderStatus;
/// Sets pixel output callback. This is an alternative to [`JxlDecoderSetImageOutBuffer`].
/// This can be set when the [`JxlDecoderStatus::Frame`] event occurs, must be set when the
/// [`JxlDecoderStatus::NeedImageOutBuffer`] event occurs, and applies only for the current frame.
/// Only one of [`JxlDecoderSetImageOutBuffer`] or [`JxlDecoderSetImageOutCallback`] may be used
/// for the same frame, not both at the same time.
///
/// The callback will be called multiple times, to receive the image
/// data in small chunks. The callback receives a horizontal stripe of pixel
/// data, `1` pixel high, xsize pixels wide, called a scanline. The xsize here is
/// not the same as the full image width, the scanline may be a partial section,
/// and xsize may differ between calls. The user can then process and/or copy the
/// partial scanline to an image buffer. The callback may be called
/// simultaneously by different threads when using a threaded parallel runner, on
/// different pixels.
///
/// If [`JxlDecoderFlushImage`] is not used, then each pixel will be visited
/// exactly once by the different callback calls, during processing with one or
/// more [`JxlDecoderProcessInput`] calls. These pixels are decoded to full
/// detail, they are not part of a lower resolution or lower quality progressive
/// pass, but the final pass.
///
/// If [`JxlDecoderFlushImage`] is used, then in addition each pixel will be
/// visited zero or one times during the blocking [`JxlDecoderFlushImage`] call.
/// Pixels visited as a result of [`JxlDecoderFlushImage`] may represent a lower
/// resolution or lower quality intermediate progressive pass of the image. Any
/// visited pixel will be of a quality at least as good or better than previous
/// visits of this pixel. A pixel may be visited zero times if it cannot be
/// decoded yet or if it was already decoded to full precision (this behavior is
/// not guaranteed).
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of the pixels. Object owned by user; its contents are
/// copied internally.
/// - `callback`: the callback function receiving partial scanlines of pixel
/// data.
/// - `opaque`: optional user data, which will be passed on to the callback,
/// may be `NULL`.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such
/// as [`JxlDecoderSetImageOutBuffer`] already set.
pub fn JxlDecoderSetImageOutCallback(
dec: *mut JxlDecoder,
format: *const JxlPixelFormat,
callback: JxlImageOutCallback,
opaque: *mut c_void,
) -> JxlDecoderStatus;
/// Similar to [`JxlDecoderSetImageOutCallback`] except that the callback is
/// allowed an initialization phase during which it is informed of how many
/// threads will call it concurrently, and those calls are further informed of
/// which thread they are occurring in.
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of the pixels. Object owned by user; its contents are
/// copied internally.
/// - `init_callback`: initialization callback.
/// - `run_callback`: the callback function receiving partial scanlines of
/// pixel data.
/// - `destroy_callback`: clean-up callback invoked after all calls to `run_callback`.
/// May be `NULL` if no clean-up is necessary.
/// - `init_opaque`: optional user data passed to `init_callback`, may be `NULL`
/// (unlike the return value from `init_callback` which may only be `NULL` if
/// initialization failed).
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such
/// as [`JxlDecoderSetImageOutBuffer`] having already been called.
pub fn JxlDecoderSetMultithreadedImageOutCallback(
dec: *mut JxlDecoder,
format: *const JxlPixelFormat,
init_callback: JxlImageOutInitCallback,
run_callback: JxlImageOutRunCallback,
destroy_callback: JxlImageOutDestroyCallback,
init_opaque: *mut c_void,
) -> JxlDecoderStatus;
/// Returns the minimum size in bytes of an extra channel pixel buffer for the
/// given format. This is the buffer for [`JxlDecoderSetExtraChannelBuffer`].
/// Requires the basic image information is available in the decoder.
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of the pixels. The `num_channels` value is ignored and is
/// always treated to be `1`.
/// - `size`: output value, buffer size in bytes
/// - `index`: which extra channel to get, matching the index used in [`JxlDecoderGetExtraChannelInfo`].
/// Must be smaller than `num_extra_channels` in the associated [`JxlBasicInfo`].
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success
/// - [`JxlDecoderStatus::Error`] on error, such as information not available yet or invalid index.
pub fn JxlDecoderExtraChannelBufferSize(
dec: *const JxlDecoder,
format: *const JxlPixelFormat,
size: *mut usize,
index: u32,
) -> JxlDecoderStatus;
/// Sets the buffer to write an extra channel to. This can be set when
/// the [`JxlDecoderStatus::Frame`] or [`JxlDecoderStatus::NeedImageOutBuffer`] event occurs,
/// and applies only for the current frame. The size of the buffer must be at
/// least as large as given by [`JxlDecoderExtraChannelBufferSize`]. The buffer
/// follows the format described by [`JxlPixelFormat`], but where `num_channels`
/// is `1`. The buffer is owned by the caller. The amount of extra channels is
/// given by the `num_extra_channels` field in the associated [`JxlBasicInfo`],
/// and the information of individual extra channels can be queried with [`JxlDecoderGetExtraChannelInfo`].
/// To get multiple extra channels, this function must be called multiple times, once for each wanted index.
/// Not all images have extra channels. The alpha channel is an extra channel and can be gotten
/// as part of the color channels when using an RGBA pixel buffer with [`JxlDecoderSetImageOutBuffer`],
/// but additionally also can be gotten separately as extra channel. The color channels themselves cannot be gotten
/// this way.
///
/// # Parameters
/// - `dec`: decoder object
/// - `format`: format of the pixels. Object owned by user and its contents
/// are copied internally. The `num_channels` value is ignored and is always
/// treated to be `1`.
/// - `buffer`: buffer type to output the pixel data to
/// - `size`: size of buffer in bytes
/// - `index`: which extra channel to get, matching the index used in [`JxlDecoderGetExtraChannelInfo`].
/// Must be smaller than `num_extra_channels` in the associated [`JxlBasicInfo`].
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such as
/// size too small or invalid index.
pub fn JxlDecoderSetExtraChannelBuffer(
dec: *mut JxlDecoder,
format: *const JxlPixelFormat,
buffer: *mut c_void,
size: usize,
index: u32,
) -> JxlDecoderStatus;
/// Sets output buffer for reconstructed JPEG codestream.
///
/// The data is owned by the caller and may be used by the decoder until [`JxlDecoderReleaseJPEGBuffer`]
/// is called or the decoder is destroyed or reset so must be kept alive until then.
///
/// If a JPEG buffer was set before and released with [`JxlDecoderReleaseJPEGBuffer`],
/// bytes that the decoder has already output should not be included,
/// only the remaining bytes output must be set.
///
/// # Parameters
/// - `dec`: decoder object
/// - `data`: pointer to next bytes to write to
/// - `size`: amount of bytes available starting from data
///
/// # Returns
/// - [`JxlDecoderStatus::Error`] if output buffer was already set and [`JxlDecoderReleaseJPEGBuffer`]
/// was not called on it, [`JxlDecoderStatus::Success`] otherwise
pub fn JxlDecoderSetJPEGBuffer(
dec: *mut JxlDecoder,
data: *mut u8,
size: usize,
) -> JxlDecoderStatus;
/// Releases buffer which was provided with [`JxlDecoderSetJPEGBuffer`].
///
/// Calling [`JxlDecoderReleaseJPEGBuffer`] is required whenever
/// a buffer is already set and a new buffer needs to be added with [`JxlDecoderSetJPEGBuffer`],
/// but is not required before [`JxlDecoderDestroy`] or [`JxlDecoderReset`].
///
/// Calling [`JxlDecoderReleaseJPEGBuffer`] when no buffer is set is
/// not an error and returns `0`.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// - The amount of bytes the decoder has not yet written to of the data
/// set by [`JxlDecoderSetJPEGBuffer`], or `0` if no buffer is set or
/// [`JxlDecoderReleaseJPEGBuffer`] was already called.
pub fn JxlDecoderReleaseJPEGBuffer(dec: *mut JxlDecoder) -> usize;
/// Sets output buffer for box output codestream.
///
/// The data is owned by the caller and may be used by the decoder until [`JxlDecoderReleaseBoxBuffer`]
/// is called or the decoder is destroyed or reset so must be kept alive until then.
///
/// If for the current box a box buffer was set before and released with [`JxlDecoderReleaseBoxBuffer`],
/// bytes that the decoder has already output should not be included, only the remaining bytes output must be set.
///
/// The [`JxlDecoderReleaseBoxBuffer`] must be used at the next [`JxlDecoderStatus::Box`] event or final
/// [`JxlDecoderStatus::Success`] event to compute the size of the output box bytes.
///
/// # Parameters
/// - `dec`: decoder object
/// - `data`: pointer to next bytes to write to
/// - `size`: amount of bytes available starting from data
///
/// # Returns
/// - [`JxlDecoderStatus::Error`] if output buffer was already set and [`JxlDecoderReleaseBoxBuffer`]
/// was not called on it, [`JxlDecoderStatus::Success`] otherwise
pub fn JxlDecoderSetBoxBuffer(
dec: *mut JxlDecoder,
data: *mut u8,
size: usize,
) -> JxlDecoderStatus;
/// Releases buffer which was provided with [`JxlDecoderSetBoxBuffer`].
///
/// Calling [`JxlDecoderReleaseBoxBuffer`] is required whenever a buffer is already set and
/// a new buffer needs to be added with [`JxlDecoderSetBoxBuffer`], but is not required before
/// [`JxlDecoderDestroy`] or [`JxlDecoderReset`].
///
/// Calling [`JxlDecoderReleaseBoxBuffer`] when no buffer is set is not an error and returns `0`.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// - The amount of bytes the decoder has not yet written to of the data set by [`JxlDecoderSetBoxBuffer`],
/// or `0` if no buffer is set or [`JxlDecoderReleaseBoxBuffer`] was already called.,
pub fn JxlDecoderReleaseBoxBuffer(dec: *mut JxlDecoder) -> usize;
/// Configures whether to get boxes in raw mode or in decompressed mode. In raw
/// mode, boxes are output as their bytes appear in the container file, which may
/// be decompressed, or compressed if their type is "brob". In decompressed mode,
/// "brob" boxes are decompressed with Brotli before outputting them. The size of
/// the decompressed stream is not known before the decompression has already
/// finished.
///
/// The default mode is raw. This setting can only be changed before decoding, or
/// directly after a [`JxlDecoderStatus::Box`] event, and is remembered until the decoder
/// is reset or destroyed.
///
/// Enabling decompressed mode requires Brotli support from the library.
///
/// # Parameters
/// - `dec`: decoder object
/// - `decompress`: [`JxlBool::True`] to transparently decompress, [`JxlBool::False`]
/// to get boxes in raw mode.
///
/// # Returns
/// - [`JxlDecoderStatus::Error`] if decompressed mode is set and Brotli is not
/// available, [`JxlDecoderStatus::Success`] otherwise.
pub fn JxlDecoderSetDecompressBoxes(
dec: *mut JxlDecoder,
decompress: JxlBool,
) -> JxlDecoderStatus;
/// Outputs the type of the current box, after a [`JxlDecoderStatus::Box`] event occurred,
/// as `4` characters without null termination character. In case of a compressed
/// "brob" box, this will return "brob" if the decompressed argument is
/// [`JxlBool::False`], or the underlying box type if the decompressed argument is
/// [`JxlBool::True`].
///
/// The following box types are currently described in ISO/IEC 18181-2:
/// - "Exif": a box with EXIF metadata. Starts with a 4-byte tiff header offset
/// (big-endian `uint32`) that indicates the start of the actual EXIF data
/// (which starts with a tiff header). Usually the offset will be zero and the
/// EXIF data starts immediately after the offset field. The Exif orientation
/// should be ignored by applications; the JPEG XL codestream orientation
/// takes precedence and libjxl will by default apply the correct orientation
/// automatically (see [`JxlDecoderSetKeepOrientation`]).
/// - "xml ": a box with XML data, in particular XMP metadata.
/// - "jumb": a JUMBF superbox (JPEG Universal Metadata Box Format, ISO/IEC
/// 19566-5).
/// - "JXL ": mandatory signature box, must come first, `12` bytes long
/// including the box header
/// - "ftyp": a second mandatory signature box, must come second, `20` bytes
/// long including the box header
/// - "jxll": a JXL level box. This indicates if the codestream is level `5` or
/// level `10` compatible. If not present, it is level `5`. Level `10` allows
/// more features such as very high image resolution and bit-depths above `16`
/// bits per channel. Added automatically by the encoder when
/// [`crate::encoder::encode::JxlEncoderSetCodestreamLevel`] is used
/// - "jxlc": a box with the image codestream, in case the codestream is not
/// split across multiple boxes. The codestream contains the JPEG XL image
/// itself, including the basic info such as image dimensions, ICC color
/// profile, and all the pixel data of all the image frames.
/// - "jxlp": a codestream box in case it is split across multiple boxes.
/// The contents are the same as in case of a jxlc box, when concatenated.
/// - "brob": a Brotli-compressed box, which otherwise represents an existing
/// type of box such as Exif or "xml ". When [`JxlDecoderSetDecompressBoxes`]
/// is set to [`JxlBool::True`], these boxes will be transparently decompressed by the
/// decoder.
/// - "jxli": frame index box, can list the keyframes in case of a JPEG XL
/// animation allowing the decoder to jump to individual frames more
/// efficiently.
/// - "jbrd": JPEG reconstruction box, contains the information required to
/// byte-for-byte losslessly reconstruct a JPEG-1 image. The JPEG DCT
/// coefficients (pixel content) themselves as well as the ICC profile are
/// encoded in the JXL codestream (jxlc or jxlp) itself. EXIF, XMP and JUMBF
/// metadata is encoded in the corresponding boxes. The jbrd box itself
/// contains information such as the remaining app markers of the JPEG-1 file
/// and everything else required to fit the information together into the
/// exact original JPEG file.
///
/// Other application-specific boxes can exist. Their typename should not begin
/// with "jxl" or "JXL" or conflict with other existing typenames.
///
/// The signature, jxl* and jbrd boxes are processed by the decoder and would
/// typically be ignored by applications. The typical way to use this function is
/// to check if an encountered box contains metadata that the application is
/// interested in (e.g. EXIF or XMP metadata), in order to conditionally set a
/// box buffer.
///
/// # Parameters
/// - `dec`: decoder object
/// - `type`: buffer to copy the type into
/// - `decompressed`: which box type to get: [`JxlBool::False`] to get the raw box type,
/// which can be `"brob"`, [`JxlBool::True`] to get the underlying box type.
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if the value is available
/// - [`JxlDecoderStatus::Error`] if not, for example the JPEG XL file does not use the container format.
pub fn JxlDecoderGetBoxType(
dec: *mut JxlDecoder,
box_type: &mut JxlBoxType,
decompressed: JxlBool,
) -> JxlDecoderStatus;
/// Returns the size of a box as it appears in the container file, after the
/// [`JxlDecoderStatus::Box`] event. This includes all the box headers.
///
/// # Parameters
/// - `dec`: decoder object
/// - `size`: raw size of the box in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Error`] if no box size is available, [`JxlDecoderStatus::Success`] otherwise.
pub fn JxlDecoderGetBoxSizeRaw(dec: *mut JxlDecoder, size: *mut u64) -> JxlDecoderStatus;
/// Returns the size of the contents of a box, after the [`JxlDecoderStatus::Box`] event.
/// This does not include any of the headers of the box. For compressed "brob" boxes,
/// this is the size of the compressed content. Even when [`JxlDecoderSetDecompressBoxes`] is enabled,
/// the return value of function does not change, and the decompressed size is not known before it
/// has already been decompressed and output.
///
/// # Parameters
/// - `dec`: decoder object
/// - `size`: size of the payload of the box in bytes
///
/// # Returns
/// - [`JxlDecoderStatus::Error`] if no box size is available, [`JxlDecoderStatus::Success`]
/// otherwise.
pub fn JxlDecoderGetBoxSizeContents(dec: *mut JxlDecoder, size: *mut u64) -> JxlDecoderStatus;
/// Configures at which progressive steps in frame decoding the [`JxlDecoderStatus::FrameProgression`] event occurs.
/// The default value for the level of detail if this function is never called is [`JxlProgressiveDetail::DC`].
///
/// # Parameters
/// - `dec`: decoder object
/// - `detail`: at which level of detail to trigger [`JxlDecoderStatus::FrameProgression`]
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such as
/// an invalid value for the progressive detail.
pub fn JxlDecoderSetProgressiveDetail(
dec: *mut JxlDecoder,
detail: JxlProgressiveDetail,
) -> JxlDecoderStatus;
/// Returns the intended downsampling ratio for the progressive frame produced
/// by [`JxlDecoderFlushImage`] after the latest [`JxlDecoderStatus::FrameProgression`] event.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// The intended downsampling ratio, can be `1`, `2`, `4` or `8`.
pub fn JxlDecoderGetIntendedDownsamplingRatio(dec: *const JxlDecoder) -> usize;
/// Outputs progressive step towards the decoded image so far when only partial
/// input was received. If the flush was successful, the buffer set with [`JxlDecoderSetImageOutBuffer`]
/// will contain partial image data.
///
/// Can be called when [`JxlDecoderProcessInput`] returns [`JxlDecoderStatus::NeedMoreInput`], after the
/// [`JxlDecoderStatus::Frame`] event already occurred and before the [`JxlDecoderStatus::FullImage`] event
/// occurred for a frame.
///
/// # Parameters
/// - `dec`: decoder object
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] if image data was flushed to the output buffer,
/// - [`JxlDecoderStatus::Error`] when no flush was done, e.g., if not enough image data was available yet
/// even for flush, or no output buffer was set yet. This error is not fatal, it only indicates no flushed
/// image is available right now. Regular decoding can still be performed.
pub fn JxlDecoderFlushImage(dec: *mut JxlDecoder) -> JxlDecoderStatus;
/// Sets the bit depth of the output buffer or callback.
///
/// Can be called after [`JxlDecoderSetImageOutBuffer`] or
/// [`JxlDecoderSetImageOutCallback`]. For float pixel data types, only the default
/// [`JxlBitDepthType::FromPixelFormat`] setting is supported.
///
/// # Parameters
/// - `dec`: decoder object
/// - `bit_depth`: the bit depth setting of the pixel output
///
/// # Returns
/// - [`JxlDecoderStatus::Success`] on success, [`JxlDecoderStatus::Error`] on error, such as
/// incompatible custom bit depth and pixel data type.
pub fn JxlDecoderSetImageOutBitDepth(
dec: *mut JxlDecoder,
bit_depth: *const JxlBitDepth,
) -> JxlDecoderStatus;
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/encoder/encode.rs 0000644 0000000 0000000 00000223571 10461020230 0020031 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Encoding API for JPEG XL.
use std::ffi::{c_char, c_void};
use super::stats::JxlEncoderStats;
use crate::{
color::{cms_interface::JxlCmsInterface, color_encoding::JxlColorEncoding},
common::memory_manager::JxlMemoryManager,
common::types::{JxlBitDepth, JxlBool, JxlBoxType, JxlPixelFormat},
metadata::codestream_header::{
JxlBasicInfo, JxlBlendInfo, JxlExtraChannelInfo, JxlExtraChannelType, JxlFrameHeader,
},
threads::parallel_runner::JxlParallelRunner,
};
#[cfg(doc)]
use crate::{
common::types::{JxlBitDepthType, JxlDataType},
encoder::stats::JxlEncoderStatsCreate,
};
/// Opaque structure that holds the JPEG XL encoder.
///
/// Allocated and initialized with [`JxlEncoderCreate`].
/// Cleaned up and deallocated with [`JxlEncoderDestroy`].
#[repr(C)]
pub struct JxlEncoder {
_unused: [u8; 0],
}
/// Settings and metadata for a single image frame. This includes encoder options
/// for a frame such as compression quality and speed.
///
/// Allocated and initialized with [`JxlEncoderFrameSettingsCreate`].
/// Cleaned up and deallocated when the encoder is destroyed with
/// [`JxlEncoderDestroy`].
#[repr(C)]
pub struct JxlEncoderFrameSettings {
_unused: [u8; 0],
}
/// Return value for multiple encoder functions.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlEncoderStatus {
/// Function call finished successfully, or encoding is finished and there is
/// nothing more to be done
Success = 0,
/// An error occurred, for example out of memory.
Error = 1,
/// The encoder needs more output buffer to continue encoding.
NeedMoreOutput = 2,
}
/// Error conditions:
/// API usage errors have the 0x80 bit set to 1
/// Other errors have the 0x80 bit set to 0
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlEncoderError {
/// No error
OK = 0,
/// Generic encoder error due to unspecified cause
Generic = 1,
/// Out of memory. TODO: not really used
OutOfMemory = 2,
/// JPEG bitstream reconstruction data could not be represented (e.g. too much tail data)
Jbrd = 3,
/// Input is invalid (e.g. corrupt JPEG file or ICC profile)
BadInput = 4,
/// The encoder doesn't (yet) support this. Either no version of libjxl
/// supports this, and the API is used incorrectly, or the libjxl version
/// should have been checked before trying to do this.
NotSupported = 0x80,
/// The encoder API is used in an incorrect way.
/// In this case, a debug build of libjxl should output a specific error
/// message. (if not, please open an issue about it)
ApiUsage = 0x81,
}
/// Id of encoder options for a frame. This includes options such as setting
/// encoding effort/speed or overriding the use of certain coding tools, for this
/// frame. This does not include non-frame related encoder options such as for
/// boxes.
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum JxlEncoderFrameSettingId {
/// Sets encoder effort/speed level without affecting decoding speed. Valid
/// values are, from faster to slower speed: 1:lightning 2:thunder 3:falcon
/// 4:cheetah 5:hare 6:wombat 7:squirrel 8:kitten 9:tortoise 10:glacier.
/// Default: squirrel (7).
Effort = 0,
/// Sets the decoding speed tier for the provided options. Minimum is 0
/// (slowest to decode, best quality/density), and maximum is 4 (fastest to
/// decode, at the cost of some quality/density). Default is 0.
DecodingSpeed = 1,
/// Sets resampling option. If enabled, the image is downsampled before
/// compression, and upsampled to original size in the decoder. Integer option,
/// use -1 for the default behavior (resampling only applied for low quality),
/// 1 for no downsampling (1x1), 2 for 2x2 downsampling, 4 for 4x4
/// downsampling, 8 for 8x8 downsampling.
Resampling = 2,
/// Similar to [`Self::Resampling`], but for extra channels.
/// Integer option, use -1 for the default behavior (depends on encoder
/// implementation), 1 for no downsampling (1x1), 2 for 2x2 downsampling, 4 for
/// 4x4 downsampling, 8 for 8x8 downsampling.
ExtraChannelResampling = 3,
/// Indicates the frame added with [`JxlEncoderAddImageFrame`] is already
/// downsampled by the downsampling factor set with [`Self::Resampling`]. The input frame
/// must then be given in the downsampled resolution, not the full image resolution.
/// The downsampled resolution is given by `ceil(xsize / resampling)`, `ceil(ysize / resampling)`
/// with `xsize` and `ysize` the dimensions given in the basic info, and `resampling`
/// the factor set with [`Self::Resampling`].
/// Use 0 to disable, 1 to enable. Default value is 0.
AlreadyDownsampled = 4,
/// Adds noise to the image emulating photographic film noise, the higher the
/// given number, the grainier the image will be. As an example, a value of 100
/// gives low noise whereas a value of 3200 gives a lot of noise. The default
/// value is 0.
PhotonNoise = 5,
/// Enables adaptive noise generation. This setting is not recommended for
/// use, please use [`Self::PhotonNoise`] instead.
/// Use -1 for the default (encoder chooses), 0 to disable, 1 to enable.
Noise = 6,
/// Enables or disables dots generation. Use -1 for the default (encoder
/// chooses), 0 to disable, 1 to enable.
Dots = 7,
/// Enables or disables patches generation. Use -1 for the default (encoder
/// chooses), 0 to disable, 1 to enable.
Patches = 8,
/// Edge preserving filter level, -1 to 3. Use -1 for the default (encoder
/// chooses), 0 to 3 to set a strength.
Epf = 9,
/// Enables or disables the gaborish filter. Use -1 for the default (encoder
/// chooses), 0 to disable, 1 to enable.
Gaborish = 10,
/// Enables modular encoding. Use -1 for default (encoder
/// chooses), 0 to enforce `VarDCT` mode (e.g. for photographic images), 1 to
/// enforce modular mode (e.g. for lossless images).
Modular = 11,
/// Enables or disables preserving color of invisible pixels. Use -1 for the
/// default (1 if lossless, 0 if lossy), 0 to disable, 1 to enable.
KeepInvisible = 12,
/// Determines the order in which 256x256 regions are stored in the codestream
/// for progressive rendering. Use -1 for the encoder
/// default, 0 for scanline order, 1 for center-first order.
GroupOrder = 13,
/// Determines the horizontal position of center for the center-first group
/// order. Use -1 to automatically use the middle of the image, 0..xsize to
/// specifically set it.
GroupOrderCenterX = 14,
/// Determines the center for the center-first group order. Use -1 to
/// automatically use the middle of the image, 0..ysize to specifically set it.
GroupOrderCenterY = 15,
/// Enables or disables progressive encoding for modular mode. Use -1 for the
/// encoder default, 0 to disable, 1 to enable.
Responsive = 16,
/// Set the progressive mode for the AC coefficients of `VarDCT`, using spectral
/// progression from the DCT coefficients. Use -1 for the encoder default, 0 to
/// disable, 1 to enable.
ProgressiveAc = 17,
/// Set the progressive mode for the AC coefficients of `VarDCT`, using
/// quantization of the least significant bits. Use -1 for the encoder default,
/// 0 to disable, 1 to enable.
QprogressiveAc = 18,
/// Set the progressive mode using lower-resolution DC images for `VarDCT`. Use
/// -1 for the encoder default, 0 to disable, 1 to have an extra 64x64 lower
/// resolution pass, 2 to have a 512x512 and 64x64 lower resolution pass.
ProgressiveDc = 19,
/// Use Global channel palette if the amount of colors is smaller than this
/// percentage of range. Use 0-100 to set an explicit percentage, -1 to use the
/// encoder default. Used for modular encoding.
ChannelColorsGlobalPercent = 20,
/// Use Local (per-group) channel palette if the amount of colors is smaller
/// than this percentage of range. Use 0-100 to set an explicit percentage, -1
/// to use the encoder default. Used for modular encoding.
ChannelColorsGroupPercent = 21,
/// Use color palette if amount of colors is smaller than or equal to this
/// amount, or -1 to use the encoder default. Used for modular encoding.
PaletteColors = 22,
/// Enables or disables delta palette. Use -1 for the default (encoder
/// chooses), 0 to disable, 1 to enable. Used in modular mode.
LossyPalette = 23,
/// Color transform for internal encoding: -1 = default, 0=XYB, 1=none (RGB),
/// 2=YCbCr. The XYB setting performs the forward XYB transform. None and
/// YCbCr both perform no transform, but YCbCr is used to indicate that the
/// encoded data losslessly represents YCbCr values.
ColorTransform = 24,
/// Reversible color transform for modular encoding: -1=default, 0-41=RCT
/// index, e.g. index 0 = none, index 6 = `YCoCg`.
/// If this option is set to a non-default value, the RCT will be globally
/// applied to the whole frame.
/// The default behavior is to try several RCTs locally per modular group,
/// depending on the speed and distance setting.
ModularColorSpace = 25,
/// Group size for modular encoding: -1=default, 0=128, 1=256, 2=512, 3=1024.
ModularGroupSize = 26,
/// Predictor for modular encoding. -1 = default, 0=zero, 1=left, 2=top,
/// 3=avg0, 4=select, 5=gradient, 6=weighted, 7=topright, 8=topleft,
/// 9=leftleft, 10=avg1, 11=avg2, 12=avg3, 13=toptop predictive average 14=mix
/// 5 and 6, 15=mix everything.
ModularPredictor = 27,
/// Fraction of pixels used to learn MA trees as a percentage. -1 = default,
/// 0 = no MA and fast decode, 50 = default value, 100 = all, values above
/// 100 are also permitted. Higher values use more encoder memory.
ModularMaTreeLearningPercent = 28,
/// Number of extra (previous-channel) MA tree properties to use. -1 =
/// default, 0-11 = valid values. Recommended values are in the range 0 to 3,
/// or 0 to amount of channels minus 1 (including all extra channels, and
/// excluding color channels when using `VarDCT` mode). Higher value gives slower
/// encoding and slower decoding.
ModularNbPrevChannels = 29,
/// Enable or disable CFL (chroma-from-luma) for lossless JPEG recompression.
/// -1 = default, 0 = disable CFL, 1 = enable CFL.
JpegReconCfl = 30,
/// Prepare the frame for indexing in the frame index box.
/// 0 = ignore this frame (same as not setting a value),
/// 1 = index this frame within the Frame Index Box.
/// If any frames are indexed, the first frame needs to
/// be indexed, too. If the first frame is not indexed, and
/// a later frame is attempted to be indexed, [`JxlEncoderStatus::Error`] will occur.
/// If non-keyframes, i.e., frames with cropping, blending or patches are
/// attempted to be indexed, [`JxlEncoderStatus::Error`] will occur.
IndexBox = 31,
/// Sets brotli encode effort for use in JPEG recompression and
/// compressed metadata boxes (brob). Can be -1 (default) or 0 (fastest) to 11
/// (slowest). Default is based on the general encode effort in case of JPEG
/// recompression, and 4 for brob boxes.
BrotliEffort = 32,
/// Enables or disables brotli compression of metadata boxes derived from
/// a JPEG frame when using [`JxlEncoderAddJPEGFrame`]. This has no effect on
/// boxes added using [`JxlEncoderAddBox`]. -1 = default, 0 = disable
/// compression, 1 = enable compression.
JpegCompressBoxes = 33,
/// Control what kind of buffering is used, when using chunked image frames.
/// -1 = default (let the encoder decide)
/// 0 = buffers everything, basically the same as non-streamed code path
/// (mainly for testing)
/// 1 = buffers everything for images that are smaller than 2048 x 2048, and
/// uses streaming input and output for larger images
/// 2 = uses streaming input and output for all images that are larger than
/// one group, i.e. 256 x 256 pixels by default
/// 3 = currently same as 2
///
/// When using streaming input and output the encoder minimizes memory usage at
/// the cost of compression density. Also note that images produced with
/// streaming mode might not be progressively decodeable.
Buffering = 34,
/// Keep or discard Exif metadata boxes derived from a JPEG frame when using
/// [`JxlEncoderAddJPEGFrame`]. This has no effect on boxes added using
/// [`JxlEncoderAddBox`]. When [`JxlEncoderStoreJPEGMetadata`] is set to 1,
/// this option cannot be set to 0. Even when Exif metadata is discarded, the
/// orientation will still be applied. 0 = discard Exif metadata, 1 = keep Exif
/// metadata (default).
JpegKeepExif = 35,
/// Keep or discard XMP metadata boxes derived from a JPEG frame when using
/// [`JxlEncoderAddJPEGFrame`]. This has no effect on boxes added using
/// [`JxlEncoderAddBox`]. When [`JxlEncoderStoreJPEGMetadata`] is set to 1,
/// this option cannot be set to 0. 0 = discard XMP metadata, 1 = keep XMP
/// metadata (default).
JpegKeepXmp = 36,
/// Keep or discard JUMBF metadata boxes derived from a JPEG frame when using
/// [`JxlEncoderAddJPEGFrame`]. This has no effect on boxes added using
/// [`JxlEncoderAddBox`]. 0 = discard JUMBF metadata, 1 = keep JUMBF metadata
/// (default).
JpegKeepJumbf = 37,
/// If this mode is disabled, the encoder will not make any image quality
/// decisions that are computed based on the full image, but stored only once
/// (e.g. the X quant multiplier in the frame header). Used mainly for testing
/// equivalence of streaming and non-streaming code.
/// 0 = disabled, 1 = enabled (default)
UseFullImageHeuristics = 38,
/// Disable perceptual optimizations. 0 = optimizations enabled (default), 1 =
/// optimizations disabled.
DisablePerceptualHeuristics = 39,
/// Enum value not to be used as an option. This value is added to force the
/// C compiler to have the enum to take a known size.
FillEnum = 65535,
}
/// The [`JxlEncoderOutputProcessor`] structure provides an interface for the
/// encoder's output processing. Users of the library, who want to do streaming
/// encoding, should implement the required callbacks for buffering, writing,
/// seeking (if supported), and setting a finalized position during the encoding
/// process.
///
/// At a high level, the processor can be in one of two states:
/// - With an active buffer: This indicates that a buffer has been acquired using
/// `get_buffer` and encoded data can be written to it.
/// - Without an active buffer: In this state, no data can be written. A new
/// buffer must be acquired after releasing any previously active buffer.
///
/// The library will not acquire more than one buffer at a given time.
///
/// The state of the processor includes `position` and `finalized position`,
/// which have the following meaning.
///
/// - position: Represents the current position, in bytes, within the output
/// stream where the encoded data will be written next. This position moves
/// forward with each `release_buffer` call as data is written, and can also be
/// adjusted through the optional seek callback, if provided. At this position
/// the next write will occur.
///
/// - finalized position: A position in the output stream that ensures all bytes
/// before this point are finalized and won't be changed by later writes.
///
/// All fields but `seek` are required, `seek` is optional and can be `None`.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlEncoderOutputProcessor {
/// An opaque pointer that the client can use to store custom data.
/// This data will be passed to the associated callback functions.
opaque: *mut c_void,
/// Acquires a buffer at the current position into which the library will write
/// the output data.
///
/// If the `size` argument points to 0 and the returned value is NULL, this
/// will be interpreted as asking the output writing to stop. In such a case,
/// the library will return an error. The client is expected to set the size of
/// the returned buffer based on the suggested `size` when this function is
/// called.
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `size`: Points to a suggested buffer size when called; must be set to
/// the size of the returned buffer once the function returns.
///
/// # Returns
/// A pointer to the acquired buffer or NULL to indicate a stop
/// condition.
get_buffer: extern "C-unwind" fn(opaque: *mut c_void, size: *mut usize) -> *mut c_void,
/// Notifies the user of library that the current buffer's data has been
/// written and can be released. This function should advance the current
/// osition of the buffer by `written_bytes` number of bytes.
///
/// # Parameters
/// - `opaque`: user supplied parameters to the callback
/// - `written_bytes`: the number of bytes written to the buffer.
release_buffer: extern "C-unwind" fn(opaque: *mut c_void, written_bytes: usize),
/// Seeks to a specific position in the output. This function is optional and
/// can be set to `None` if the output doesn't support seeking. Can only be done
/// when there is no buffer. Cannot be used to seek before the finalized
/// position.
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `position`: The position to seek to, in bytes.
seek: Option,
/// Sets a finalized position on the output data, at a specific position.
/// Seeking will never request a position before the finalized position.
///
/// Will only be called if there is no active buffer.
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `finalized_position`: The position, in bytes, where the finalized
/// position should be set.
set_finalized_position: extern "C-unwind" fn(opaque: *mut c_void, finalized_position: u64),
}
/// This struct provides callback functions to pass pixel data in a streaming
/// manner instead of requiring the entire frame data in memory at once.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlChunkedFrameInputSource {
/// A pointer to any user-defined data or state. This can be used to pass
/// information to the callback functions.
opaque: *mut c_void,
/// Get the pixel format that color channel data will be provided in.
/// When called, `pixel_format` points to a suggested pixel format; if
/// color channel data can be given in this pixel format, processing might
/// be more efficient.
///
/// This function will be called exactly once, before any call to
/// [`Self::get_color_channels_data`].
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `pixel_format`: Format for pixels.
get_color_channels_pixel_format:
extern "C-unwind" fn(opaque: *mut c_void, pixel_format: *mut JxlPixelFormat),
/// Callback to retrieve a rectangle of color channel data at a specific
/// location. It is guaranteed that `xpos` and `ypos` are multiples of 8. `xsize`,
/// `ysize` will be multiples of 8, unless the resulting rectangle would be out
/// of image bounds. Moreover, `xsize` and `ysize` will be at most 2048. The
/// returned data will be assumed to be in the format returned by the
/// (preceding) call to [`Self::get_color_channels_pixel_format`], except the `align`
/// parameter of the pixel format will be ignored. Instead, the `i`-th row will
/// be assumed to start at position `return_value + i * *row_offset`, with the
/// value of `*row_offset` decided by the callee.
///
/// Note that multiple calls to `get_color_channel_data_at` may happen before a
/// call to [`Self::release_buffer`].
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `xpos`: Horizontal position for the data.
/// - `ypos`: Vertical position for the data.
/// - `xsize`: Horizontal size of the requested rectangle of data.
/// - `ysize`: Vertical size of the requested rectangle of data.
/// - `row_offset`: Pointer to the byte offset between consecutive rows of
/// the retrieved pixel data.
///
/// # Returns
/// Pointer to the retrieved pixel data.
get_color_channels_data_at: extern "C-unwind" fn(
opaque: *mut c_void,
xpos: usize,
ypos: usize,
xsize: usize,
ysize: usize,
row_offset: *mut usize,
) -> *const c_void,
/// Get the pixel format that extra channel data will be provided in.
/// When called, `pixel_format` points to a suggested pixel format; if
/// extra channel data can be given in this pixel format, processing might
/// be more efficient.
///
/// This function will be called exactly once per index, before any call to
/// [`Self::get_extra_channel_data_at`] with that given index.
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `ec_index`: Zero-indexed index of the extra channel.
/// - `pixel_format`: Format for extra channel data.
get_extra_channel_pixel_format: extern "C-unwind" fn(
opaque: *mut c_void,
ec_index: usize,
pixel_format: *mut JxlPixelFormat,
),
/// Callback to retrieve a rectangle of extra channel `ec_index` data at a
/// specific location. It is guaranteed that `xpos` and `ypos` are multiples of
/// 8. `xsize`, `ysize` will be multiples of 8, unless the resulting rectangle
/// would be out of image bounds. Moreover, `xsize` and `ysize` will be at most
/// 2048. The returned data will be assumed to be in the format returned by the
/// (preceding) call to [`Self::get_extra_channel_pixel_format`] with the
/// corresponding extra channel index `ec_index`, except the `align` parameter
/// of the pixel format will be ignored. Instead, the `i`-th row will be
/// assumed to start at position `return_value + i * *row_offset`, with the
/// value of `*row_offset` decided by the callee.
///
/// Note that multiple calls to `get_extra_channel_data_at` may happen before a
/// call to [`Self::release_buffer`].
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `xpos`: Horizontal position for the data.
/// - `ypos`: Vertical position for the data.
/// - `xsize`: Horizontal size of the requested rectangle of data.
/// - `ysize`: Vertical size of the requested rectangle of data.
/// - `row_offset`: Pointer to the byte offset between consecutive rows of
/// the retrieved pixel data.
///
/// # Returns
/// Pointer to the retrieved pixel data.
get_extra_channel_data_at: extern "C-unwind" fn(
opaque: *mut c_void,
ec_index: usize,
xpos: usize,
ypos: usize,
xsize: usize,
ysize: usize,
row_offset: *mut usize,
) -> *const c_void,
/// Releases the buffer `buf` (obtained through a call to
/// [`Self::get_color_channels_data_at`] or [`Self::get_extra_channel_data_at`]). This function
/// will be called exactly once per call to [`Self::get_color_channels_data_at`] or
/// [`Self::get_extra_channel_data_at`].
///
/// # Parameters
/// - `opaque`: User supplied parameters to the callback.
/// - `buf`: Pointer returned by [`Self::get_color_channels_data_at`] or
/// [`Self::get_extra_channel_data_at`].
release_buffer: extern "C-unwind" fn(opaque: *mut c_void, buf: *const c_void),
}
/// Function type for [`JxlEncoderSetDebugImageCallback`].
///
/// The callback may be called simultaneously by different threads when using a
/// threaded parallel runner, on different debug images.
///
/// # Parameters
/// - `opaque`: Optional user data, as given to [`JxlEncoderSetDebugImageCallback`].
/// - `label`: Label of debug image, can be used in filenames.
/// - `xsize`: Width of debug image.
/// - `ysize`: Height of debug image.
/// - `color`: Color encoding of debug image.
/// - `pixels`: Pixel data of debug image as big-endian 16-bit unsigned samples.
/// The memory is not owned by the user, and is only valid during the time the
/// callback is running.
pub type JxlDebugImageCallback = extern "C-unwind" fn(
opaque: *mut c_void,
label: *const c_char,
xsize: usize,
ysize: usize,
color: *const JxlColorEncoding,
pixels: *const u16,
);
extern "C-unwind" {
/// Encoder library version.
///
/// # Returns
/// The encoder library version as an integer:
/// `MAJOR_VERSION * 1000000 + MINOR_VERSION * 1000 + PATCH_VERSION`.
/// For example, version 1.2.3 would return 1002003.
pub fn JxlEncoderVersion() -> u32;
/// Creates an instance of `JxlEncoder` and initializes it.
///
/// # Parameters
/// - `memory_manager`: Custom allocator function. It may be `NULL`. The memory
/// manager will be copied internally. If `NULL`, the default allocator will be used.
/// See [`crate::common::memory_manager`] for details.
///
/// # Returns
/// - `NULL` if the instance cannot be allocated or initialized.
/// - Pointer to initialized [`JxlEncoder`] otherwise.
pub fn JxlEncoderCreate(memory_manager: *const JxlMemoryManager) -> *mut JxlEncoder;
/// Re-initializes a [`JxlEncoder`] instance, so it can be re-used for encoding
/// another image. All state and settings are reset as if the object was
/// newly created with [`JxlEncoderCreate`], but the memory manager is kept.
///
/// # Parameters
/// - `enc`: Instance to be re-initialized.
pub fn JxlEncoderReset(enc: *mut JxlEncoder);
/// Deinitializes and frees a [`JxlEncoder`] instance.
///
/// # Parameters
/// - `enc`: Instance to be cleaned up and deallocated.
pub fn JxlEncoderDestroy(enc: *mut JxlEncoder);
/// Sets the color management system (CMS) that will be used for color conversion
/// (if applicable) during encoding. May only be set before starting encoding. If
/// left unset, the default CMS implementation will be used.
///
/// # Parameters
/// - `enc`: Encoder object.
/// - `cms`: Structure representing a CMS implementation. See [`JxlCmsInterface`] for more details.
pub fn JxlEncoderSetCms(enc: *mut JxlEncoder, cms: JxlCmsInterface);
/// Set the parallel runner for multithreading. May only be set before starting
/// encoding.
///
/// # Parameters
/// - `enc`: Encoder object.
/// - `parallel_runner`: Function pointer to runner for multithreading. It may
/// be `NULL` to use the default, single-threaded, runner. A multithreaded
/// runner should be set to reach fast performance.
/// - `parallel_runner_opaque`: Opaque pointer for `parallel_runner`.
///
/// # Returns
/// - `JxlEncoderStatus::Success` if the runner was set.
/// - `JxlEncoderStatus::Error` otherwise (the previous runner remains set).
pub fn JxlEncoderSetParallelRunner(
enc: *mut JxlEncoder,
parallel_runner: JxlParallelRunner,
parallel_runner_opaque: *mut c_void,
) -> JxlEncoderStatus;
/// Get the (last) error code in case [`JxlEncoderStatus::Error`] was returned.
///
/// # Parameters
/// - `enc`: Encoder object.
///
/// # Returns
/// The [`JxlEncoderError`] that caused the (last) [`JxlEncoderStatus::Error`] to be returned.
pub fn JxlEncoderGetError(enc: *mut JxlEncoder) -> JxlEncoderError;
/// Encodes a JPEG XL file using the available bytes. `*avail_out` indicates how
/// many output bytes are available, and `*next_out` points to the input bytes.
/// `*avail_out` will be decremented by the amount of bytes that have been
/// processed by the encoder and `*next_out` will be incremented by the same
/// amount, so `*next_out` will now point at the amount of `*avail_out` unprocessed
/// bytes.
///
/// The returned status indicates whether the encoder needs more output bytes.
/// When the return value is not [`JxlEncoderStatus::Error`] or [`JxlEncoderStatus::Success`], the
/// encoding requires more [`JxlEncoderProcessOutput`] calls to continue.
///
/// The caller must guarantee that `*avail_out >= 32` when calling
/// [`JxlEncoderProcessOutput`]; otherwise, [`JxlEncoderStatus::NeedMoreOutput`] will
/// be returned. It is guaranteed that, if `*avail_out >= 32`, at least one byte of
/// output will be written.
///
/// This encodes the frames and/or boxes added so far. If the last frame or last
/// box has been added, [`JxlEncoderCloseInput`], [`JxlEncoderCloseFrames`]
/// and/or [`JxlEncoderCloseBoxes`] must be called before the next
/// [`JxlEncoderProcessOutput`] call, or the codestream won't be encoded
/// correctly.
///
/// # Parameters
/// - `enc`: Encoder object.
/// - `next_out`: Pointer to next bytes to write to.
/// - `avail_out`: Amount of bytes available starting from `*next_out`.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] when encoding finished and all events handled.
/// - [`JxlEncoderStatus::Error`] when encoding failed, e.g. invalid input.
/// - [`JxlEncoderStatus::NeedMoreOutput`] more output buffer is necessary.
pub fn JxlEncoderProcessOutput(
enc: *mut JxlEncoder,
next_out: *mut *mut u8,
avail_out: *mut usize,
) -> JxlEncoderStatus;
/// Sets the frame information for this frame to the encoder. This includes
/// animation information such as frame duration to store in the frame header.
/// The frame header fields represent the frame as passed to the encoder, but not
/// necessarily the exact values as they will be encoded file format: the encoder
/// could change crop and blending options of a frame for more efficient encoding
/// or introduce additional internal frames. Animation duration and time code
/// information is not altered since those are immutable metadata of the frame.
///
/// It is not required to use this function, however if `have_animation` is set
/// to true in the basic info, then this function should be used to set the
/// time duration of this individual frame. By default individual frames have a
/// time duration of 0, making them form a composite still. See [`JxlFrameHeader`]
/// for more information.
///
/// This information is stored in the [`JxlEncoderFrameSettings`] and so is used
/// for any frame encoded with these [`JxlEncoderFrameSettings`]. It is ok to
/// change between [`JxlEncoderAddImageFrame`] calls, each added image frame
/// will have the frame header that was set in the options at the time of calling
/// [`JxlEncoderAddImageFrame`].
///
/// The `is_last` and `name_length` fields of the [`JxlFrameHeader`] are ignored,
/// use [`JxlEncoderCloseFrames`] to indicate last frame, and [`JxlEncoderSetFrameName`]
/// to indicate the name and its length instead.
/// Calling this function will clear any name that was previously set with [`JxlEncoderSetFrameName`].
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `frame_header`: frame header data to set. Object owned by the caller and
/// does not need to be kept in memory, its information is copied internally.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success
/// - [`JxlEncoderStatus::Error`] on error
pub fn JxlEncoderSetFrameHeader(
frame_settings: *mut JxlEncoderFrameSettings,
frame_header: *const JxlFrameHeader,
) -> JxlEncoderStatus;
/// Sets blend info of an extra channel. The blend info of extra channels is set
/// separately from that of the color channels, the color channels are set with
/// [`JxlEncoderSetFrameHeader`].
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `index`: index of the extra channel to use.
/// - `blend_info`: blend info to set for the extra channel.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderSetExtraChannelBlendInfo(
frame_settings: *mut JxlEncoderFrameSettings,
index: usize,
blend_info: *const JxlBlendInfo,
) -> JxlEncoderStatus;
/// Sets the name of the animation frame. This function is optional, frames are
/// not required to have a name. This setting is a part of the frame header, and
/// the same principles as for [`JxlEncoderSetFrameHeader`] apply. The
/// `name_length` field of [`JxlFrameHeader`] is ignored by the encoder, this
/// function determines the name length instead as the length in bytes of the C
/// string.
///
/// The maximum possible name length is 1071 bytes (excluding terminating null
/// character).
///
/// Calling [`JxlEncoderSetFrameHeader`] clears any name that was
/// previously set.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `frame_name`: name of the next frame to be encoded, as a UTF-8 encoded C
/// string (zero terminated). Owned by the caller, and copied internally.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success
/// - [`JxlEncoderStatus::Error`] on error
pub fn JxlEncoderSetFrameName(
frame_settings: *mut JxlEncoderFrameSettings,
frame_name: *const u8,
) -> JxlEncoderStatus;
/// Sets the bit depth of the input buffer.
///
/// For float pixel formats, only the default [`JxlBitDepthType::FromPixelFormat`]
/// setting is allowed, while for unsigned pixel formats,
/// [`JxlBitDepthType::FromCodestream`] setting is also allowed. See the comment
/// on [`JxlEncoderAddImageFrame`] for the effects of the bit depth setting.
///
/// # Parameters
/// - `frame_settings`: Set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `bit_depth`: The bit depth setting of the pixel input.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderSetFrameBitDepth(
frame_settings: *mut JxlEncoderFrameSettings,
bit_depth: *const JxlBitDepth,
) -> JxlEncoderStatus;
/// Sets the buffer to read JPEG encoded bytes from for the next frame to encode.
///
/// If [`JxlEncoderSetBasicInfo`] has not yet been called, calling
/// [`JxlEncoderAddJPEGFrame`] will implicitly call it with the parameters of
/// the added JPEG frame.
///
/// If [`JxlEncoderSetColorEncoding`] or [`JxlEncoderSetICCProfile`] has not
/// yet been called, calling [`JxlEncoderAddJPEGFrame`] will implicitly call it
/// with the parameters of the added JPEG frame.
///
/// If the encoder is set to store JPEG reconstruction metadata using [`JxlEncoderStoreJPEGMetadata`]
/// and a single JPEG frame is added, it will be possible to losslessly reconstruct the JPEG codestream.
///
/// If this is the last frame, [`JxlEncoderCloseInput`] or [`JxlEncoderCloseFrames`] must be called before the next
/// [`JxlEncoderProcessOutput`] call.
///
/// Note, this can only be used to add JPEG frames for lossless compression. To
/// encode with lossy compression, the JPEG must be decoded manually and a pixel
/// buffer added using [`JxlEncoderAddImageFrame`].
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `buffer`: bytes to read JPEG from. Owned by the caller and its contents
/// are copied internally.
/// - `size`: size of buffer in bytes.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success
/// - [`JxlEncoderStatus::Error`] on error
pub fn JxlEncoderAddJPEGFrame(
options: *const JxlEncoderFrameSettings,
buffer: *const u8,
size: usize,
) -> JxlEncoderStatus;
/// Sets the buffer to read pixels from for the next image to encode. Must call
/// [`JxlEncoderSetBasicInfo`] before [`JxlEncoderAddImageFrame`].
///
/// Currently only some data types for pixel formats are supported:
/// - [`JxlDataType::Uint8`], with range 0..255
/// - [`JxlDataType::Uint16`], with range 0..65535
/// - [`JxlDataType::Float16`], with nominal range 0..1
/// - [`JxlDataType::Float`], with nominal range 0..1
///
/// Note: the sample data type in `pixel_format` is allowed to be different from
/// what is described in the [`JxlBasicInfo`]. The type in `pixel_format`,
/// together with an optional [`JxlBitDepth`] parameter set by [`JxlEncoderSetFrameBitDepth`]
/// describes the format of the uncompressed pixel buffer. The `bits_per_sample` and `exponent_bits_per_sample`
/// in the [`JxlBasicInfo`] describes what will actually be encoded in the JPEG XL
/// codestream. For example, to encode a 12-bit image, you would set
/// `bits_per_sample` to 12, while the input frame buffer can be in the following
/// formats:
/// - if pixel format is in [`JxlDataType::Uint16`] with default bit depth setting
/// (i.e. [`JxlBitDepthType::FromPixelFormat`]), input sample values are
/// rescaled to 16-bit, i.e. multiplied by 65535/4095;
/// - if pixel format is in [`JxlDataType::Uint16`] with [`JxlBitDepthType::FromCodestream`] bit depth setting,
/// input sample values are provided unscaled;
/// - if pixel format is in [`JxlDataType::Float`], input sample values are
/// rescaled to 0..1, i.e. multiplied by 1.0/4095.0. While it is allowed, it is
/// obviously not recommended to use a `pixel_format` with lower precision than
/// what is specified in the [`JxlBasicInfo`].
///
/// We support interleaved channels as described by the [`JxlPixelFormat`]:
/// - single-channel data, e.g. grayscale
/// - single-channel + alpha
/// - trichromatic, e.g. RGB
/// - trichromatic + alpha
///
/// Extra channels not handled here need to be set by [`JxlEncoderSetExtraChannelBuffer`].
/// If the image has alpha, and alpha is not passed here, it will implicitly be
/// set to all-opaque (an alpha value of 1.0 everywhere).
///
/// The pixels are assumed to be encoded in the original profile that is set with
/// [`JxlEncoderSetColorEncoding`] or [`JxlEncoderSetICCProfile`]. If none of
/// these functions were used, the pixels are assumed to be nonlinear sRGB for
/// integer data types ([`JxlDataType::Uint8`], [`JxlDataType::Uint16`]), and linear
/// sRGB for floating point data types ([`JxlDataType::Float16`], [`JxlDataType::Float`]).
///
/// Sample values in floating-point pixel formats are allowed to be outside the
/// nominal range, e.g. to represent out-of-sRGB-gamut colors in the
/// `uses_original_profile=false` case. They are however not allowed to be NaN or
/// +-infinity.
///
/// If this is the last frame, [`JxlEncoderCloseInput`] or [`JxlEncoderCloseFrames`] must be called before the next
/// [`JxlEncoderProcessOutput`] call.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `pixel_format`: format for pixels. Object owned by the caller and its
/// contents are copied internally.
/// - `buffer`: buffer type to input the pixel data from. Owned by the caller
/// and its contents are copied internally.
/// - `size`: size of buffer in bytes. This size should match what is implied
/// by the frame dimensions and the pixel format.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success
/// - [`JxlEncoderStatus::Error`] on error
pub fn JxlEncoderAddImageFrame(
options: *const JxlEncoderFrameSettings,
pixel_format: *const JxlPixelFormat,
buffer: *const c_void,
size: usize,
) -> JxlEncoderStatus;
/// Sets the output processor for the encoder. This processor determines how the
/// encoder will handle buffering, writing, seeking (if supported), and
/// setting a finalized position during the encoding process.
///
/// This should not be used when using [`JxlEncoderProcessOutput`].
///
/// # Parameters
/// - `enc`: Encoder object.
/// - `output_processor`: The struct containing the callbacks for managing
/// output.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderSetOutputProcessor(
enc: *mut JxlEncoder,
output_processor: JxlEncoderOutputProcessor,
) -> JxlEncoderStatus;
/// Flushes any buffered input in the encoder, ensuring that all available input
/// data has been processed and written to the output.
///
/// This function can only be used after [`JxlEncoderSetOutputProcessor`].
/// Before making the last call to [`JxlEncoderFlushInput`], users should call
/// [`JxlEncoderCloseInput`] to signal the end of input data.
///
/// This should not be used when using [`JxlEncoderProcessOutput`].
///
/// # Parameters
/// - `enc`: Encoder object.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderFlushInput(enc: *mut JxlEncoder) -> JxlEncoderStatus;
/// Adds a frame to the encoder using a chunked input source.
///
/// This function gives a way to encode a frame by providing pixel data in a
/// chunked or streaming manner, which can be especially useful when dealing with
/// large images that may not fit entirely in memory or when trying to optimize
/// memory usage. The input data is provided through callbacks defined in the
/// [`JxlChunkedFrameInputSource`] struct. Once the frame data has been
/// completely retrieved, this function will flush the input and close it if it
/// is the last frame.
///
/// # Parameters
/// - `frame_settings`: Set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `is_last_frame`: Indicates if this is the last frame.
/// - `chunked_frame_input`: Struct providing callback methods for retrieving
/// pixel data in chunks.
///
/// # Returns
/// Returns a status indicating the success or failure of adding the
/// frame.
pub fn JxlEncoderAddChunkedFrame(
frame_settings: *const JxlEncoderFrameSettings,
is_last_frame: JxlBool,
chunked_frame_input: JxlChunkedFrameInputSource,
) -> JxlEncoderStatus;
/// Sets the buffer to read pixels from for an extra channel at a given index.
/// The index must be smaller than the `num_extra_channels` in the associated
/// [`JxlBasicInfo`]. Must call [`JxlEncoderSetExtraChannelInfo`] before
/// [`JxlEncoderSetExtraChannelBuffer`].
///
/// TODO: mention what data types in pixel formats are supported.
///
/// It is required to call this function for every extra channel, except for the
/// alpha channel if that was already set through [`JxlEncoderAddImageFrame`].
///
/// # Parameters
/// - `frame_settings`: Set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `pixel_format`: Format for pixels. Object owned by the caller and its
/// contents are copied internally. The `num_channels` value is ignored, since the
/// number of channels for an extra channel is always assumed to be one.
/// - `buffer`: Buffer type to input the pixel data from. Owned by the caller
/// and its contents are copied internally.
/// - `size`: Size of buffer in bytes. This size should match what is implied
/// by the frame dimensions and the pixel format.
/// - `index`: Index of the extra channel to use.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderSetExtraChannelBuffer(
frame_settings: *const JxlEncoderFrameSettings,
pixel_format: *const JxlPixelFormat,
buffer: *const c_void,
size: usize,
index: u32,
) -> JxlEncoderStatus;
/// Adds a metadata box to the file format. [`JxlEncoderProcessOutput`] must be
/// used to effectively write the box to the output. [`JxlEncoderUseBoxes`] must
/// be enabled before using this function.
///
/// Boxes allow inserting application-specific data and metadata (Exif, XML/XMP,
/// JUMBF and user defined boxes).
///
/// The box format follows ISO BMFF and shares features and box types with other
/// image and video formats, including the Exif, XML and JUMBF boxes. The box
/// format for JPEG XL is specified in ISO/IEC 18181-2.
///
/// Boxes in general don't contain other boxes inside, except a JUMBF superbox.
/// Boxes follow each other sequentially and are byte-aligned. If the container
/// format is used, the JXL stream consists of concatenated boxes.
/// It is also possible to use a direct codestream without boxes, but in that
/// case metadata cannot be added.
///
/// Each box generally has the following byte structure in the file:
/// - 4 bytes: box size including box header (Big endian. If set to 0, an
/// 8-byte 64-bit size follows instead).
/// - 4 bytes: type, e.g. "JXL " for the signature box, "jxlc" for a codestream
/// box.
/// - N bytes: box contents.
///
/// Only the box contents are provided to the contents argument of this function,
/// the encoder encodes the size header itself. Most boxes are written
/// automatically by the encoder as needed ("JXL ", "ftyp", "jxll", "jxlc",
/// "jxlp", "jxli", "jbrd"), and this function only needs to be called to add
/// optional metadata when encoding from pixels (using [`JxlEncoderAddImageFrame`]).
/// When recompressing JPEG files (using [`JxlEncoderAddJPEGFrame`]),
/// if the input JPEG contains EXIF, XMP or JUMBF
/// metadata, the corresponding boxes are already added automatically.
///
/// Box types are given by 4 characters. The following boxes can be added with
/// this function:
/// - "Exif": a box with EXIF metadata, can be added by libjxl users, or is
/// automatically added when needed for JPEG reconstruction. The contents of
/// this box must be prepended by a 4-byte tiff header offset, which may
/// be 4 zero bytes in case the tiff header follows immediately.
/// The EXIF metadata must be in sync with what is encoded in the JPEG XL
/// codestream, specifically the image orientation. While this is not
/// recommended in practice, in case of conflicting metadata, the JPEG XL
/// codestream takes precedence.
/// - "xml ": a box with XML data, in particular XMP metadata, can be added by
/// libjxl users, or is automatically added when needed for JPEG reconstruction
/// - "jumb": a JUMBF superbox, which can contain boxes with different types of
/// metadata inside. This box type can be added by the encoder transparently,
/// and other libraries to create and handle JUMBF content exist.
/// - Application-specific boxes. Their typename should not begin with "jxl" or
/// "JXL" or conflict with other existing typenames, and they should be
/// registered with MP4RA (mp4ra.org).
///
/// These boxes can be stored uncompressed or Brotli-compressed (using a "brob"
/// box), depending on the `compress_box` parameter.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `box_type`: the box type, e.g. "Exif" for EXIF metadata, "xml " for XMP or
/// IPTC metadata, "jumb" for JUMBF metadata.
/// - `contents`: the full contents of the box, for example EXIF
/// data. ISO BMFF box header must not be included, only the contents. Owned by
/// the caller and its contents are copied internally.
/// - `size`: size of the box contents.
/// - `compress_box`: Whether to compress this box as a "brob" box. Requires
/// Brotli support.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error, such as
/// when using this function without [`JxlEncoderUseContainer`], or adding a box
/// type that would result in an invalid file format.
pub fn JxlEncoderAddBox(
enc: *mut JxlEncoder,
box_type: *const JxlBoxType,
contents: *const u8,
size: usize,
compress_box: JxlBool,
) -> JxlEncoderStatus;
/// Indicates the intention to add metadata boxes. This allows [`JxlEncoderAddBox`] to be used.
/// When using this function, then it is required to use [`JxlEncoderCloseBoxes`] at the end.
///
/// By default the encoder assumes no metadata boxes will be added.
///
/// This setting can only be set at the beginning, before encoding starts.
///
/// # Parameters
/// - `enc`: encoder object.
pub fn JxlEncoderUseBoxes(enc: *mut JxlEncoder) -> JxlEncoderStatus;
/// Declares that no further boxes will be added with [`JxlEncoderAddBox`].
/// This function must be called after the last box is added so the encoder knows
/// the stream will be finished. It is not necessary to use this function if
/// [`JxlEncoderUseBoxes`] is not used. Further frames may still be added.
///
/// Must be called between [`JxlEncoderAddBox`] of the last box
/// and the next call to [`JxlEncoderProcessOutput`], or [`JxlEncoderProcessOutput`]
/// won't output the last box correctly.
///
/// NOTE: if you don't need to close frames and boxes at separate times, you can
/// use [`JxlEncoderCloseInput`] instead to close both at once.
///
/// # Parameters
/// - `enc`: encoder object.
pub fn JxlEncoderCloseBoxes(enc: *mut JxlEncoder);
/// Declares that no frames will be added and [`JxlEncoderAddImageFrame`] and
/// [`JxlEncoderAddJPEGFrame`] won't be called anymore. Further metadata boxes
/// may still be added. This function or [`JxlEncoderCloseInput`] must be called
/// after adding the last frame and the next call to
/// [`JxlEncoderProcessOutput`], or the frame won't be properly marked as last.
///
/// NOTE: if you don't need to close frames and boxes at separate times, you can
/// use [`JxlEncoderCloseInput`] instead to close both at once.
///
/// # Parameters
/// - `enc`: encoder object.
pub fn JxlEncoderCloseFrames(enc: *mut JxlEncoder);
/// Closes any input to the encoder, equivalent to calling [`JxlEncoderCloseFrames`]
/// as well as calling [`JxlEncoderCloseBoxes`] if needed. No further input of any kind
/// may be given to the encoder, but further [`JxlEncoderProcessOutput`] calls should be
/// done to create the final output.
///
/// The requirements of both [`JxlEncoderCloseFrames`] and [`JxlEncoderCloseBoxes`] apply
/// to this function. Either this function or the other two must be called after the final
/// frame and/or box, and the next [`JxlEncoderProcessOutput`] call, or the codestream won't
/// be encoded correctly.
///
/// # Parameters
/// - `enc`: encoder object.
pub fn JxlEncoderCloseInput(enc: *mut JxlEncoder);
/// Sets the original color encoding of the image encoded by this encoder. This
/// is an alternative to [`JxlEncoderSetICCProfile`] and only one of these two
/// must be used. This one sets the color encoding as a [`JxlColorEncoding`],
/// while the other sets it as ICC binary data. Must be called after
/// [`JxlEncoderSetBasicInfo`].
///
/// # Parameters
/// - `enc`: encoder object.
/// - `color`: color encoding. Object owned by the caller and its contents are
/// copied internally.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetColorEncoding(
enc: *mut JxlEncoder,
color: *const JxlColorEncoding,
) -> JxlEncoderStatus;
/// Sets the original color encoding of the image encoded by this encoder as an
/// ICC color profile. This is an alternative to [`JxlEncoderSetColorEncoding`]
/// and only one of these two must be used. This one sets the color encoding as
/// ICC binary data, while the other defines it as a [`JxlColorEncoding`]. Must
/// be called after [`JxlEncoderSetBasicInfo`].
///
/// # Parameters
/// - `enc`: encoder object.
/// - `icc_profile`: bytes of the original ICC profile
/// - `size`: size of the `icc_profile` buffer in bytes
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetICCProfile(
enc: *mut JxlEncoder,
icc_profile: *const u8,
size: usize,
) -> JxlEncoderStatus;
/// Initializes a [`JxlBasicInfo`] struct to default values.
/// For forwards-compatibility, this function has to be called before values
/// are assigned to the struct fields.
/// The default values correspond to an 8-bit RGB image, no alpha or any
/// other extra channels.
///
/// # Parameters
/// - `info`: global image metadata. Object owned by the caller.
pub fn JxlEncoderInitBasicInfo(info: *mut JxlBasicInfo);
/// Initializes a [`JxlFrameHeader`] struct to default values.
/// For forwards-compatibility, this function has to be called before values
/// are assigned to the struct fields.
/// The default values correspond to a frame with no animation duration and the
/// 'replace' blend mode. After using this function, animation duration must
/// be set, and for composite still, blend settings must be set.
///
/// # Parameters
/// - `frame_header`: frame metadata. Object owned by the caller.
pub fn JxlEncoderInitFrameHeader(frame_header: *mut JxlFrameHeader);
/// Initializes a [`JxlBlendInfo`] struct to default values.
/// For forwards-compatibility, this function has to be called before values
/// are assigned to the struct fields.
///
/// # Parameters
/// - `blend_info`: blending info. Object owned by the caller.
pub fn JxlEncoderInitBlendInfo(blend_info: *mut JxlBlendInfo);
/// Sets the global metadata of the image encoded by this encoder.
///
/// If the [`JxlBasicInfo`] contains information of extra channels beyond an
/// alpha channel, then [`JxlEncoderSetExtraChannelInfo`] must be called between
/// [`JxlEncoderSetBasicInfo`] and [`JxlEncoderAddImageFrame`]. In order to
/// indicate extra channels, the value of `info.num_extra_channels` should be set
/// to the number of extra channels, also counting the alpha channel if present.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `info`: global image metadata. Object owned by the caller and its
/// contents are copied internally.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetBasicInfo(
enc: *mut JxlEncoder,
info: *const JxlBasicInfo,
) -> JxlEncoderStatus;
/// Sets the upsampling method the decoder will use in case there are frames
/// with [`JxlEncoderFrameSettingsSetOption`] set. This is useful in combination
/// with the [`JxlEncoderFrameSettingsSetOption`] option, to control
/// the type of upsampling that will be used.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `factor`: upsampling factor to configure (1, 2, 4 or 8; for 1 this
/// function has no effect at all)
/// - `mode`: upsampling mode to use for this upsampling:
/// - `-1`: default (good for photographic images, no signaling overhead)
/// - `0`: nearest neighbor (good for pixel art)
/// - `1`: 'pixel dots' (same as NN for 2x, diamond-shaped 'pixel dots' for 4x/8x)
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful,
/// - [`JxlEncoderStatus::Error`] otherwise
pub fn JxlEncoderSetUpsamplingMode(
enc: *mut JxlEncoder,
factor: i64,
mode: i64,
) -> JxlEncoderStatus;
/// Initializes a [`JxlExtraChannelInfo`] struct to default values.
/// For forwards-compatibility, this function has to be called before values
/// are assigned to the struct fields.
/// The default values correspond to an 8-bit channel of the provided type.
///
/// # Parameters
/// - `channel_type`: type of the extra channel.
/// - `info`: global extra channel metadata. Object owned by the caller and its
/// contents are copied internally.
pub fn JxlEncoderInitExtraChannelInfo(
channel_type: JxlExtraChannelType,
info: *mut JxlExtraChannelInfo,
);
/// Sets information for the extra channel at the given index. The index
/// must be smaller than `num_extra_channels` in the associated [`JxlBasicInfo`].
///
/// # Parameters
/// - `enc`: encoder object.
/// - `index`: index of the extra channel to set.
/// - `info`: global extra channel metadata. Object owned by the caller and its
/// contents are copied internally.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderSetExtraChannelInfo(
enc: *mut JxlEncoder,
index: usize,
info: *const JxlExtraChannelInfo,
) -> JxlEncoderStatus;
/// Sets the name for the extra channel at the given index in UTF-8. The index
/// must be smaller than the `num_extra_channels` in the associated [`JxlBasicInfo`].
///
/// TODO: remove size parameter for consistency with [`JxlEncoderSetFrameName`]
///
/// # Parameters
/// - `enc`: encoder object.
/// - `index`: index of the extra channel to set.
/// - `name`: buffer with the name of the extra channel.
/// - `size`: size of the name buffer in bytes, not counting the terminating
/// character.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] on success.
/// - [`JxlEncoderStatus::Error`] on error.
pub fn JxlEncoderSetExtraChannelName(
enc: *mut JxlEncoder,
index: usize,
name: *const u8,
size: usize,
) -> JxlEncoderStatus;
/// Sets a frame-specific option of integer type to the encoder options.
/// The [`JxlEncoderFrameSettingId`] argument determines which option is set.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `option`: ID of the option to set.
/// - `value`: Integer value to set for this option.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] in case of an error, such as invalid or unknown option id, or
/// invalid integer value for the given option. If an error is returned, the
/// state of the [`JxlEncoderFrameSettings`] object is still valid and is the same as before
/// this function was called.
pub fn JxlEncoderFrameSettingsSetOption(
frame_settings: *mut JxlEncoderFrameSettings,
option: JxlEncoderFrameSettingId,
value: i64,
) -> JxlEncoderStatus;
/// Sets a frame-specific option of float type to the encoder options.
/// The [`JxlEncoderFrameSettingId`] argument determines which option is set.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `option`: ID of the option to set.
/// - `value`: Float value to set for this option.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] in case of an error, such as invalid or unknown option id, or
/// invalid float value for the given option. If an error is returned, the
/// state of the [`JxlEncoderFrameSettings`] object is still valid and is the same as before
/// this function was called.
pub fn JxlEncoderFrameSettingsSetFloatOption(
frame_settings: *mut JxlEncoderFrameSettings,
option: JxlEncoderFrameSettingId,
value: f32,
) -> JxlEncoderStatus;
/// Forces the encoder to use the box-based container format (BMFF) even
/// when not necessary.
///
/// When using [`JxlEncoderUseBoxes`], [`JxlEncoderStoreJPEGMetadata`] or
/// [`JxlEncoderSetCodestreamLevel`] with level 10, the encoder will automatically
/// also use the container format, it is not necessary to use
/// [`JxlEncoderUseContainer`] for those use cases.
///
/// By default this setting is disabled.
///
/// This setting can only be set at the beginning, before encoding starts.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `use_container`: true if the encoder should always output the JPEG XL
/// container format, false to only output it when necessary.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderUseContainer(enc: *mut JxlEncoder, use_container: bool) -> JxlEncoderStatus;
/// Configure the encoder to store JPEG reconstruction metadata in the JPEG XL
/// container.
///
/// If this is set to true and a single JPEG frame is added, it will be
/// possible to losslessly reconstruct the JPEG codestream.
///
/// This setting can only be set at the beginning, before encoding starts.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `store_jpeg_metadata`: true if the encoder should store JPEG metadata.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderStoreJPEGMetadata(
enc: *mut JxlEncoder,
store_jpeg_metadata: bool,
) -> JxlEncoderStatus;
/// Sets the feature level of the JPEG XL codestream. Valid values are 5 and
/// 10, or -1 (to choose automatically). Using the minimum required level, or
/// level 5 in most cases, is recommended for compatibility with all decoders.
///
/// Level 5: for end-user image delivery, this level is the most widely
/// supported level by image decoders and the recommended level to use unless a
/// level 10 feature is absolutely necessary. Supports a maximum resolution
/// 268435456 pixels total with a maximum width or height of 262144 pixels,
/// maximum 16-bit color channel depth, maximum 120 frames per second for
/// animation, maximum ICC color profile size of 4 MiB, it allows all color
/// models and extra channel types except CMYK and the [`JxlExtraChannelType::Black`]
/// extra channel, and a maximum of 4 extra channels in addition to the 3 color
/// channels. It also sets boundaries to certain internally used coding tools.
///
/// Level 10: this level removes or increases the bounds of most of the level
/// 5 limitations, allows CMYK color and up to 32 bits per color channel, but
/// may be less widely supported.
///
/// The default value is -1. This means the encoder will automatically choose
/// between level 5 and level 10 based on what information is inside the [`JxlBasicInfo`]
/// structure. Do note that some level 10 features, particularly those used by animated
/// JPEG XL codestreams, might require level 10, even though the [`JxlBasicInfo`] only
/// suggests level 5. In this case, the level must be explicitly set to 10, otherwise
/// the encoder will return an error. The encoder will restrict internal encoding choices
/// to those compatible with the level setting.
///
/// This setting can only be set at the beginning, before encoding starts.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `level`: the level value to set, must be -1, 5, or 10.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful.
/// - [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetCodestreamLevel(enc: *mut JxlEncoder, level: i32) -> JxlEncoderStatus;
/// Returns the codestream level required to support the currently configured
/// settings and basic info. This function can only be used at the beginning,
/// before encoding starts, but after setting basic info.
///
/// This does not support per-frame settings, only global configuration, such as
/// the image dimensions, that are known at the time of writing the header of
/// the JPEG XL file.
///
/// If this returns 5, nothing needs to be done and the codestream can be
/// compatible with any decoder. If this returns 10, [`JxlEncoderSetCodestreamLevel`]
/// has to be used to set the codestream level to 10, or the encoder can be configured
/// differently to allow using the more compatible level 5.
///
/// # Parameters
/// - `enc`: encoder object.
///
/// # Returns
/// - `-1`: if no level can support the configuration (e.g. image dimensions
/// larger than even level 10 supports),
/// - `5`: if level 5 is supported,
/// - `10`: if setting the codestream level to 10 is required.
pub fn JxlEncoderGetRequiredCodestreamLevel(enc: *mut JxlEncoder) -> i32;
/// Enables lossless encoding.
///
/// This is not an option like the others on itself, but rather while enabled it
/// overrides a set of existing options (such as distance, modular mode and
/// color transform) that enables bit-for-bit lossless encoding.
///
/// When disabled, those options are not overridden, but since those options
/// could still have been manually set to a combination that operates losslessly,
/// using this function with lossless set to [`JxlBool::False`] does not
/// guarantee lossy encoding, though the default set of options is lossy.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `lossless`: whether to override options for lossless mode
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful, [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetFrameLossless(
frame_settings: *mut JxlEncoderFrameSettings,
lossless: bool,
) -> JxlEncoderStatus;
/// Sets the distance level for lossy compression: target max butteraugli
/// distance, lower = higher quality. Range: 0 .. 25.
/// 0.0 = mathematically lossless (however, use [`JxlEncoderSetFrameLossless`]
/// instead to use true lossless, as setting distance to 0 alone is not the only
/// requirement). 1.0 = visually lossless. Recommended range: 0.5 .. 3.0. Default
/// value: 1.0.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `distance`: the distance value to set.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful, [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetFrameDistance(
options: *mut JxlEncoderFrameSettings,
distance: f32,
) -> JxlEncoderStatus;
/// Sets the distance level for lossy compression of extra channels.
/// The distance is as in [`JxlEncoderSetFrameDistance`] (lower = higher
/// quality). If not set, or if set to the special value -1, the distance that
/// was set with [`JxlEncoderSetFrameDistance`] will be used.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `index`: index of the extra channel to set a distance value for.
/// - `distance`: the distance value to set.
///
/// # Returns
/// - [`JxlEncoderStatus::Success`] if the operation was successful, [`JxlEncoderStatus::Error`] otherwise.
pub fn JxlEncoderSetExtraChannelDistance(
frame_settings: *mut JxlEncoderFrameSettings,
index: usize,
distance: f32,
) -> JxlEncoderStatus;
/// Maps JPEG-style quality factor to distance.
///
/// This function takes in input a JPEG-style quality factor `quality` and
/// produces as output a `distance` value suitable to be used with
/// [`JxlEncoderSetFrameDistance`] and [`JxlEncoderSetExtraChannelDistance`].
///
/// The `distance` value influences the level of compression, with lower values
/// indicating higher quality:
/// - 0.0 implies lossless compression (however, note that calling
/// [`JxlEncoderSetFrameLossless`] is required).
/// - 1.0 represents a visually lossy compression, which is also the default
/// setting.
///
/// The `quality` parameter, ranging up to 100, is inversely related to
/// `distance`:
/// - A `quality` of 100.0 maps to a `distance` of 0.0 (lossless).
/// - A `quality` of 90.0 corresponds to a `distance` of 1.0.
///
/// Recommended Range:
/// - `distance`: 0.5 to 3.0.
/// - corresponding `quality`: approximately 96 to 68.
///
/// Allowed Range:
/// - `distance`: 0.0 to 25.0.
/// - corresponding `quality`: 100.0 to 0.0.
///
/// Note: the `quality` parameter has no consistent psychovisual meaning
/// across different codecs and libraries. Using the mapping defined by
/// [`JxlEncoderDistanceFromQuality`] will result in a visual quality roughly
/// equivalent to what would be obtained with `libjpeg-turbo` with the same
/// `quality` parameter, but that is by no means guaranteed; do not assume that
/// the same quality value will result in similar file sizes and image quality
/// across different codecs.
pub fn JxlEncoderDistanceFromQuality(quality: f32) -> f32;
/// Create a new set of encoder options, with all values initially copied from
/// the `source` options, or set to default if `source` is `NULL`.
///
/// The returned pointer is an opaque struct tied to the encoder and it will be
/// deallocated by the encoder when [`JxlEncoderDestroy`] is called. For
/// functions taking both a [`JxlEncoder`] and a [`JxlEncoderFrameSettings`],
/// only [`JxlEncoderFrameSettings`] created with this function for the same
/// encoder instance can be used.
///
/// # Parameters
/// - `enc`: encoder object.
/// - `source`: source options to copy initial values from, or `NULL` to get
/// defaults initialized to defaults.
///
/// # Returns
/// The opaque struct pointer identifying a new set of encoder options.
pub fn JxlEncoderFrameSettingsCreate(
enc: *mut JxlEncoder,
source: *const JxlEncoderFrameSettings,
) -> *mut JxlEncoderFrameSettings;
/// Sets a color encoding to be sRGB.
///
/// # Parameters
/// - `color_encoding`: color encoding instance.
/// - `is_gray`: whether the color encoding should be gray scale or color.
pub fn JxlColorEncodingSetToSRGB(color_encoding: *mut JxlColorEncoding, is_gray: bool);
/// Sets a color encoding to be linear sRGB.
///
/// # Parameters
/// - `color_encoding`: [color encoding instance](JxlColorEncoding).
/// - `is_gray`: whether the color encoding should be gray scale or color.
pub fn JxlColorEncodingSetToLinearSRGB(color_encoding: *mut JxlColorEncoding, is_gray: bool);
/// Enables usage of expert options.
///
/// At the moment, the only expert option is setting an effort value of 11,
/// which gives the best compression for pixel-lossless modes but is very slow.
///
/// # Parameters
/// - `enc`: encoder object.
pub fn JxlEncoderAllowExpertOptions(enc: *mut JxlEncoder);
/// Sets the given debug image callback that will be used by the encoder to
/// output various debug images during encoding.
///
/// This only has any effect if the encoder was compiled with the appropriate
/// debug build flags.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `callback`: used to return the debug image.
/// - `opaque`: user supplied parameter to the image callback.
pub fn JxlEncoderSetDebugImageCallback(
frame_settings: *mut JxlEncoderFrameSettings,
callback: JxlDebugImageCallback,
opaque: *mut c_void,
);
/// Sets the given stats object for gathering various statistics during encoding.
///
/// This only has any effect if the encoder was compiled with the appropriate
/// debug build flags.
///
/// # Parameters
/// - `frame_settings`: set of options and metadata for this frame. Also
/// includes reference to the encoder object.
/// - `stats`: object that can be used to query the gathered stats (created
/// by [`JxlEncoderStatsCreate`])
pub fn JxlEncoderCollectStats(
frame_settings: *mut JxlEncoderFrameSettings,
stats: *mut JxlEncoderStats,
);
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/encoder/stats.rs 0000644 0000000 0000000 00000005627 10461020230 0017732 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! API to collect various statistics from JXL encoder.
#[cfg(doc)]
use crate::encoder::encode::JxlEncoderCollectStats;
/// Opaque structure that holds the encoder statistics.
///
/// Allocated and initialized with [`JxlEncoderStatsCreate`].
/// Cleaned up and deallocated with [`JxlEncoderStatsDestroy`].
#[repr(C)]
pub struct JxlEncoderStats {
_unused: [u8; 0],
}
extern "C-unwind" {
/// Creates an instance of [`JxlEncoderStats`] and initializes it.
///
/// # Returns
/// A pointer to the initialized [`JxlEncoderStats`] instance.
pub fn JxlEncoderStatsCreate() -> *mut JxlEncoderStats;
/// Deinitializes and frees [`JxlEncoderStats`] instance.
///
/// # Parameters
/// - `stats`: Instance to be cleaned up and deallocated. No-op if `stats` is
/// a null pointer.
pub fn JxlEncoderStatsDestroy(stats: *mut JxlEncoderStats);
/// Returns the value of the statistics corresponding to the given key.
///
/// # Parameters
/// - `stats`: Object that was passed to the encoder with a
/// [`JxlEncoderCollectStats`] function.
/// - `key`: The particular statistics to query.
///
/// # Returns
/// The value of the statistics.
pub fn JxlEncoderStatsGet(stats: *const JxlEncoderStats, key: JxlEncoderStatsKey) -> usize;
/** Updates the values of the given stats object with that of an other.
*
* @param stats object whose values will be updated (usually added together)
* @param other stats object whose values will be merged with stats
*/
pub fn JxlEncoderStatsMerge(stats: *mut JxlEncoderStats, other: *const JxlEncoderStats);
}
/// Data type for querying [`JxlEncoderStats`] object
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum JxlEncoderStatsKey {
HeaderBits,
TocBits,
DictionaryBits,
SplinesBits,
NoiseBits,
QuantBits,
ModularTreeBits,
ModularGlobalBits,
DcBits,
ModularDcGroupBits,
ControlFieldsBits,
CoefOrderBits,
AcHistogramBits,
AcBits,
ModularAcGroupBits,
NumSmallBlocks,
NumDct4x8Blocks,
NumAfvBlocks,
NumDct8Blocks,
NumDct8x32Blocks,
NumDct16Blocks,
NumDct16x32Blocks,
NumDct32Blocks,
NumDct32x64Blocks,
NumDct64Blocks,
NumButteraugliIters,
NumStats,
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/encoder.rs 0000644 0000000 0000000 00000001314 10461020230 0016561 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! `jxl_encoder`: JPEG XL encoder.
pub mod encode;
pub mod stats;
jpegxl-sys-0.11.2+libjxl-0.11.1/src/lib.rs 0000644 0000000 0000000 00000034224 10461020230 0015716 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
#![cfg_attr(coverage_nightly, feature(coverage_attribute))]
pub mod decode;
pub mod color;
pub mod common;
pub mod encoder;
pub mod metadata;
pub mod threads;
#[cfg(test)]
mod test {
use crate::{
common::types::*,
decode::*,
encoder::encode::*,
threads::thread_parallel_runner::{
JxlThreadParallelRunner, JxlThreadParallelRunnerCreate,
JxlThreadParallelRunnerDefaultNumWorkerThreads, JxlThreadParallelRunnerDestroy,
},
};
use std::{mem::MaybeUninit, ptr};
use pretty_assertions::assert_eq;
const SAMPLE_PNG: &[u8] = include_bytes!("../../samples/sample.png");
const SAMPLE_JXL: &[u8] = include_bytes!("../../samples/sample.jxl");
macro_rules! jxl_dec_events {
( $( $x: expr ),* ) => {
{
let mut tmp = 0;
$(
tmp |= $x as i32;
)*
tmp
}
};
}
macro_rules! jxl_dec_assert {
($val:expr, $desc:expr) => {
if $val != JxlDecoderStatus::Success as _ {
panic!("Decoder error by: {:#?}, in {}", $val, $desc)
}
};
}
macro_rules! jxl_enc_assert {
($val:expr, $desc:expr) => {
if $val != JxlEncoderStatus::Success as _ {
panic!("Encoder error by: {:#?}, in {}", $val, $desc)
}
};
}
#[test]
#[cfg_attr(coverage_nightly, coverage(off))]
fn test_bindings_version() {
unsafe {
assert_eq!(JxlDecoderVersion(), 11001);
assert_eq!(JxlEncoderVersion(), 11001);
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
unsafe fn decode(decoder: *mut JxlDecoder, sample: &[u8]) {
use JxlDecoderStatus::{
BasicInfo, Error, FullImage, NeedImageOutBuffer, NeedMoreInput, Success,
};
// Stop after getting the basic info and decoding the image
let mut status = JxlDecoderSubscribeEvents(
decoder,
jxl_dec_events!(JxlDecoderStatus::BasicInfo, JxlDecoderStatus::FullImage),
);
jxl_dec_assert!(status, "Subscribe Events");
// Read everything in memory
let signature = JxlSignatureCheck(sample.as_ptr(), 2);
assert_eq!(signature, JxlSignature::Codestream);
let next_in = sample.as_ptr();
let avail_in = sample.len();
let pixel_format = JxlPixelFormat {
num_channels: 3,
data_type: JxlDataType::Uint8,
endianness: JxlEndianness::Native,
align: 0,
};
let mut basic_info;
let mut buffer: Vec = Vec::new();
let mut x_size = 0;
let mut y_size = 0;
status = JxlDecoderSetInput(decoder, next_in, avail_in);
jxl_dec_assert!(status, "Set input");
loop {
status = JxlDecoderProcessInput(decoder);
match status {
Error => panic!("Decoder error!"),
NeedMoreInput => {
panic!("Error, already provided all input")
}
// Get the basic info
BasicInfo => {
basic_info = {
let mut info = MaybeUninit::uninit();
status = JxlDecoderGetBasicInfo(decoder, info.as_mut_ptr());
jxl_dec_assert!(status, "BasicInfo");
info.assume_init()
};
x_size = basic_info.xsize;
y_size = basic_info.ysize;
assert_eq!(basic_info.xsize, 40);
assert_eq!(basic_info.ysize, 50);
}
// Get the output buffer
NeedImageOutBuffer => {
let mut size = 0;
status = JxlDecoderImageOutBufferSize(decoder, &pixel_format, &mut size);
jxl_dec_assert!(status, "BufferSize");
buffer.resize(size, 0f32);
status = JxlDecoderSetImageOutBuffer(
decoder,
&pixel_format,
buffer.as_mut_ptr().cast(),
size,
);
jxl_dec_assert!(status, "SetBuffer");
}
FullImage => continue,
Success => {
assert_eq!(buffer.len(), (x_size * y_size * 3) as usize);
return;
}
_ => panic!("Unknown decoder status: {status:#?}"),
}
}
}
#[test]
#[cfg_attr(coverage_nightly, coverage(off))]
fn test_bindings_decoding() {
unsafe {
let dec = JxlDecoderCreate(ptr::null()); // Default memory manager
assert!(!dec.is_null());
// Simple single thread runner
decode(dec, SAMPLE_JXL);
JxlDecoderDestroy(dec);
}
}
#[test]
#[cfg_attr(coverage_nightly, coverage(off))]
fn test_bindings_thread_pool() {
unsafe {
let runner = JxlThreadParallelRunnerCreate(
std::ptr::null(),
JxlThreadParallelRunnerDefaultNumWorkerThreads(),
);
let dec = JxlDecoderCreate(ptr::null()); // Default memory manager
assert!(!dec.is_null());
// Parallel multi-thread runner
let status = JxlDecoderSetParallelRunner(dec, JxlThreadParallelRunner, runner);
jxl_dec_assert!(status, "Set Parallel Runner");
decode(dec, SAMPLE_JXL);
JxlDecoderDestroy(dec);
JxlThreadParallelRunnerDestroy(runner);
}
}
#[test]
#[cfg_attr(coverage_nightly, coverage(off))]
fn test_bindings_resizable() {
use JxlDecoderStatus::{
BasicInfo, Error, FullImage, NeedImageOutBuffer, NeedMoreInput, Success,
};
use crate::threads::resizable_parallel_runner::{
JxlResizableParallelRunner, JxlResizableParallelRunnerCreate,
JxlResizableParallelRunnerDestroy, JxlResizableParallelRunnerSetThreads,
JxlResizableParallelRunnerSuggestThreads,
};
unsafe {
let runner = JxlResizableParallelRunnerCreate(std::ptr::null());
let dec = JxlDecoderCreate(ptr::null()); // Default memory manager
assert!(!dec.is_null());
// Resizable parallel multi-thread runner
let status = JxlDecoderSetParallelRunner(dec, JxlResizableParallelRunner, runner);
jxl_dec_assert!(status, "Set Parallel Runner");
// Stop after getting the basic info and decoding the image
let mut status = JxlDecoderSubscribeEvents(
dec,
jxl_dec_events!(JxlDecoderStatus::BasicInfo, JxlDecoderStatus::FullImage),
);
jxl_dec_assert!(status, "Subscribe Events");
// Read everything in memory
let signature = JxlSignatureCheck(SAMPLE_JXL.as_ptr(), 2);
assert_eq!(signature, JxlSignature::Codestream);
let next_in = SAMPLE_JXL.as_ptr();
let avail_in = SAMPLE_JXL.len();
let pixel_format = JxlPixelFormat {
num_channels: 3,
data_type: JxlDataType::Uint8,
endianness: JxlEndianness::Native,
align: 0,
};
let mut basic_info;
let mut buffer: Vec = Vec::new();
let mut x_size = 0;
let mut y_size = 0;
status = JxlDecoderSetInput(dec, next_in, avail_in);
jxl_dec_assert!(status, "Set input");
loop {
status = JxlDecoderProcessInput(dec);
match status {
Error => panic!("Decoder error!"),
NeedMoreInput => {
panic!("Error, already provided all input")
}
// Get the basic info
BasicInfo => {
basic_info = {
let mut info = MaybeUninit::uninit();
status = JxlDecoderGetBasicInfo(dec, info.as_mut_ptr());
jxl_dec_assert!(status, "BasicInfo");
info.assume_init()
};
x_size = basic_info.xsize;
y_size = basic_info.ysize;
let num_threads = JxlResizableParallelRunnerSuggestThreads(
u64::from(x_size),
u64::from(y_size),
);
JxlResizableParallelRunnerSetThreads(runner, num_threads as usize);
assert_eq!(basic_info.xsize, 40);
assert_eq!(basic_info.ysize, 50);
}
// Get the output buffer
NeedImageOutBuffer => {
let mut size = 0;
status = JxlDecoderImageOutBufferSize(dec, &pixel_format, &mut size);
jxl_dec_assert!(status, "BufferSize");
buffer.resize(size, 0f32);
status = JxlDecoderSetImageOutBuffer(
dec,
&pixel_format,
buffer.as_mut_ptr().cast(),
size,
);
jxl_dec_assert!(status, "SetBuffer");
}
FullImage => continue,
Success => {
assert_eq!(buffer.len(), (x_size * y_size * 3) as usize);
break;
}
_ => panic!("Unknown decoder status: {status:#?}"),
}
}
JxlDecoderDestroy(dec);
JxlResizableParallelRunnerDestroy(runner);
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
fn encode(pixels: &[u8], x_size: u32, ysize: u32) -> Vec {
unsafe {
let enc = JxlEncoderCreate(std::ptr::null());
let runner = JxlThreadParallelRunnerCreate(
std::ptr::null(),
JxlThreadParallelRunnerDefaultNumWorkerThreads(),
);
let mut status = JxlEncoderSetParallelRunner(enc, JxlThreadParallelRunner, runner);
jxl_enc_assert!(status, "Set Parallel Runner");
let mut basic_info = {
let mut basic_info = MaybeUninit::uninit();
JxlEncoderInitBasicInfo(basic_info.as_mut_ptr());
basic_info.assume_init()
};
basic_info.xsize = x_size;
basic_info.ysize = ysize;
status = JxlEncoderSetBasicInfo(enc, &basic_info);
jxl_enc_assert!(status, "Set Basic Info");
let pixel_format = JxlPixelFormat {
num_channels: 3,
data_type: JxlDataType::Uint8,
endianness: JxlEndianness::Native,
align: 0,
};
let mut color_encoding = MaybeUninit::uninit();
JxlColorEncodingSetToSRGB(color_encoding.as_mut_ptr(), false);
status = JxlEncoderSetColorEncoding(enc, color_encoding.as_ptr());
jxl_enc_assert!(status, "Set Color Encoding");
status = JxlEncoderAddImageFrame(
JxlEncoderFrameSettingsCreate(enc, std::ptr::null()),
&pixel_format,
pixels.as_ptr().cast_mut().cast(),
pixels.len(),
);
jxl_enc_assert!(status, "Add Image Frame");
JxlEncoderCloseInput(enc);
let chunk_size = 1024 * 512; // 512 KB is a good initial value
let mut buffer = vec![0u8; chunk_size];
let mut next_out = buffer.as_mut_ptr();
let mut avail_out = chunk_size;
loop {
status =
JxlEncoderProcessOutput(enc, std::ptr::addr_of_mut!(next_out), &mut avail_out);
if status != JxlEncoderStatus::NeedMoreOutput {
break;
}
let offset = next_out as usize - buffer.as_ptr() as usize;
buffer.resize(buffer.len() * 2, 0);
next_out = buffer.as_mut_ptr().add(offset);
avail_out = buffer.len() - offset;
}
buffer.truncate(next_out as usize - buffer.as_ptr() as usize);
jxl_enc_assert!(status, "Encoding");
JxlEncoderDestroy(enc);
JxlThreadParallelRunnerDestroy(runner);
buffer
}
}
#[test]
#[cfg_attr(coverage_nightly, coverage(off))]
fn test_bindings_encoding() {
let img = image::load_from_memory_with_format(SAMPLE_PNG, image::ImageFormat::Png).unwrap();
let image_buffer = img.into_rgb8();
let output = encode(
image_buffer.as_raw(),
image_buffer.width(),
image_buffer.height(),
);
unsafe {
let runner = JxlThreadParallelRunnerCreate(
std::ptr::null(),
JxlThreadParallelRunnerDefaultNumWorkerThreads(),
);
let dec = JxlDecoderCreate(ptr::null()); // Default memory manager
assert!(!dec.is_null());
let status = JxlDecoderSetParallelRunner(dec, JxlThreadParallelRunner, runner);
jxl_dec_assert!(status, "Set Parallel Runner");
decode(dec, &output);
JxlDecoderDestroy(dec);
JxlThreadParallelRunnerDestroy(runner);
}
}
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/metadata/codestream_header.rs 0000644 0000000 0000000 00000036673 10461020230 0022400 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Definitions of structs and enums for the metadata from the JPEG XL
//! codestream headers (signature, metadata, preview dimensions, ...), excluding
//! color encoding which is in [`crate::color::color_encoding`].
use crate::common::types::JxlBool;
#[cfg(doc)]
use crate::{
color::color_encoding::{JxlColorEncoding, JxlColorSpace},
decode::{
JxlColorProfileTarget, JxlDecoderGetExtraChannelBlendInfo, JxlDecoderGetExtraChannelInfo,
},
encoder::encode::{JxlEncoderCloseFrames, JxlEncoderSetFrameName},
};
/// Image orientation metadata.
///
/// Values 1..8 match the EXIF definitions.
/// The name indicates the operation to perform to transform from the encoded
/// image to the display image.
#[repr(C)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum JxlOrientation {
Identity = 1,
FlipHorizontal = 2,
Rotate180 = 3,
FlipVertical = 4,
Transpose = 5,
Rotate90Cw = 6,
AntiTranspose = 7,
Rotate90Ccw = 8,
}
/// Given type of an extra channel.
#[repr(C)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum JxlExtraChannelType {
Alpha,
Depth,
SpotColor,
SelectionMask,
Black,
Cfa,
Thermal,
Reserved0,
Reserved1,
Reserved2,
Reserved3,
Reserved4,
Reserved5,
Reserved6,
Reserved7,
Unknown,
Optional,
}
/// The codestream preview header
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlPreviewHeader {
/// Preview width in pixels
pub xsize: u32,
/// Preview height in pixels
pub ysize: u32,
}
/// The codestream animation header, optionally present in the beginning of
/// the codestream, and if it is it applies to all animation frames, unlike
/// [`JxlFrameHeader`] which applies to an individual frame.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlAnimationHeader {
/// Numerator of ticks per second of a single animation frame time unit
pub tps_numerator: u32,
/// Denominator of ticks per second of a single animation frame time unit
pub tps_denominator: u32,
/// Amount of animation loops, or 0 to repeat infinitely
pub num_loops: u32,
/// Whether animation time codes are present at animation frames in the
/// codestream
pub have_timecodes: JxlBool,
}
/// Basic image information. This information is available from the file
/// signature and first part of the codestream header.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlBasicInfo {
/// Whether the codestream is embedded in the container format. If true,
/// metadata information and extensions may be available in addition to the
/// codestream.
pub have_container: JxlBool,
/// Width of the image in pixels, before applying orientation.
pub xsize: u32,
/// Height of the image in pixels, before applying orientation.
pub ysize: u32,
/// Original image color channel bit depth.
pub bits_per_sample: u32,
/// Original image color channel floating point exponent bits, or 0 if they
/// are unsigned integer. For example, if the original data is half-precision
/// (binary16) floating point, `bits_per_sample` is 16 and
/// `exponent_bits_per_sample` is 5, and so on for other floating point
/// precisions.
pub exponent_bits_per_sample: u32,
/// Upper bound on the intensity level present in the image in nits. For
/// unsigned integer pixel encodings, this is the brightness of the largest
/// representable value. The image does not necessarily contain a pixel
/// actually this bright. An encoder is allowed to set 255 for SDR images
/// without computing a histogram.
/// Leaving this set to its default of 0 lets libjxl choose a sensible default
/// value based on the color encoding.
pub intensity_target: f32,
/// Lower bound on the intensity level present in the image. This may be
/// loose, i.e. lower than the actual darkest pixel. When tone mapping, a
/// decoder will map `[min_nits, intensity_target]` to the display range.
pub min_nits: f32,
/// See the description of [`Self::linear_below`].
pub relative_to_max_display: JxlBool,
/// The tone mapping will leave unchanged (linear mapping) any pixels whose
/// brightness is strictly below this. The interpretation depends on
/// `relative_to_max_display`. If true, this is a ratio \[0, 1\] of the maximum
/// display brightness \[nits\], otherwise an absolute brightness \[nits\].
pub linear_below: f32,
/// Whether the data in the codestream is encoded in the original color
/// profile that is attached to the codestream metadata header, or is
/// encoded in an internally supported absolute color space (which the decoder
/// can always convert to linear or non-linear sRGB or to XYB). If the original
/// profile is used, the decoder outputs pixel data in the color space matching
/// that profile, but doesn't convert it to any other color space. If the
/// original profile is not used, the decoder only outputs the data as sRGB
/// (linear if outputting to floating point, nonlinear with standard sRGB
/// transfer function if outputting to unsigned integers) but will not convert
/// it to to the original color profile. The decoder also does not convert to
/// the target display color profile. To convert the pixel data produced by
/// the decoder to the original color profile, one of the `JxlDecoderGetColor*`
/// functions needs to be called with
/// [`JxlColorProfileTarget::Data`] to get the color profile of the decoder
/// output, and then an external CMS can be used for conversion. Note that for
/// lossy compression, this should be set to false for most use cases, and if
/// needed, the image should be converted to the original color profile after
/// decoding, as described above.
pub uses_original_profile: JxlBool,
/// Indicates a preview image exists near the beginning of the codestream.
/// The preview itself or its dimensions are not included in the basic info.
pub have_preview: JxlBool,
/// Indicates animation frames exist in the codestream. The animation
/// information is not included in the basic info.
pub have_animation: JxlBool,
/// Image orientation, value 1-8 matching the values used by JEITA CP-3451C
/// (Exif version 2.3).
pub orientation: JxlOrientation,
/// Number of color channels encoded in the image, this is either 1 for
/// grayscale data, or 3 for colored data. This count does not include
/// the alpha channel or other extra channels. To check presence of an alpha
/// channel, such as in the case of RGBA color, check `alpha_bits != 0`.
/// If and only if this is `1`, the [`JxlColorSpace`] in the [`JxlColorEncoding`] is
/// [`JxlColorSpace::Gray`].
pub num_color_channels: u32,
/// Number of additional image channels. This includes the main alpha channel,
/// but can also include additional channels such as depth, additional alpha
/// channels, spot colors, and so on. Information about the extra channels
/// can be queried with [`JxlDecoderGetExtraChannelInfo`]. The main alpha
/// channel, if it exists, also has its information available in the
/// `alpha_bits`, `alpha_exponent_bits` and `alpha_premultiplied` fields in this
/// [`JxlBasicInfo`].
pub num_extra_channels: u32,
/// Bit depth of the encoded alpha channel, or 0 if there is no alpha channel.
/// If present, matches the `alpha_bits` value of the [`JxlExtraChannelInfo`]
/// associated with this alpha channel.
pub alpha_bits: u32,
/// Alpha channel floating point exponent bits, or 0 if they are unsigned. If
/// present, matches the `alpha_bits` value of the [`JxlExtraChannelInfo`] associated
/// with this alpha channel. integer.
pub alpha_exponent_bits: u32,
/// Whether the alpha channel is premultiplied. Only used if there is a main
/// alpha channel. Matches the `alpha_premultiplied` value of the
/// [`JxlExtraChannelInfo`] associated with this alpha channel.
pub alpha_premultiplied: JxlBool,
/// Dimensions of encoded preview image, only used if `have_preview` is
/// [`JxlBool::True`].
pub preview: JxlPreviewHeader,
/// Animation header with global animation properties for all frames, only
/// used if `have_animation` is [`JxlBool::True`].
pub animation: JxlAnimationHeader,
/// Intrinsic width of the image.
/// The intrinsic size can be different from the actual size in pixels
/// (as given by xsize and ysize) and it denotes the recommended dimensions
/// for displaying the image, i.e. applications are advised to resample the
/// decoded image to the intrinsic dimensions.
pub intrinsic_xsize: u32,
/// Intrinsic height of the image.
/// The intrinsic size can be different from the actual size in pixels
/// (as given by xsize and ysize) and it denotes the recommended dimensions
/// for displaying the image, i.e. applications are advised to resample the
/// decoded image to the intrinsic dimensions.
pub intrinsic_ysize: u32,
/// Padding for forwards-compatibility, in case more fields are exposed
/// in a future version of the library.
_padding: [u8; 100],
}
/// Information for a single extra channel.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlExtraChannelInfo {
/// Given type of an extra channel.
pub r#type: JxlExtraChannelType,
/// Total bits per sample for this channel.
pub bits_per_sample: u32,
/// Floating point exponent bits per channel, or 0 if they are unsigned
/// integer.
pub exponent_bits_per_sample: u32,
/// The exponent the channel is downsampled by on each axis.
/// TODO(lode): expand this comment to match the JPEG XL specification,
/// specify how to upscale, how to round the size computation, and to which
/// extra channels this field applies.
pub dim_shift: u32,
/// Length of the extra channel name in bytes, or 0 if no name.
/// Excludes null termination character.
pub name_length: u32,
/// Whether alpha channel uses premultiplied alpha. Only applicable if
/// type is [`JxlExtraChannelType::Alpha`].
pub alpha_premultiplied: JxlBool,
/// Spot color of the current spot channel in linear RGBA. Only applicable if
/// type is [`JxlExtraChannelType::SpotColor`].
pub spot_color: [f32; 4],
/// Only applicable if type is [`JxlExtraChannelType::Cfa`].
/// TODO(lode): add comment about the meaning of this field.
pub cfa_channel: u32,
}
/// Extensions in the codestream header.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlHeaderExtensions {
/// Extension bits.
pub extensions: u64,
}
/// Frame blend modes.
/// When decoding, if coalescing is enabled (default), this can be ignored.
#[repr(C)]
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum JxlBlendMode {
Replace = 0,
Add = 1,
Blend = 2,
MULADD = 3,
MUL = 4,
}
/// The information about blending the color channels or a single extra channel.
/// When decoding, if coalescing is enabled (default), this can be ignored and
/// the blend mode is considered to be [`JxlBlendMode::Replace`].
/// When encoding, these settings apply to the pixel data given to the encoder.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlBlendInfo {
/// Blend mode.
pub blendmode: JxlBlendMode,
/// Reference frame ID to use as the 'bottom' layer (0-3).
pub source: u32,
/// Which extra channel to use as the 'alpha' channel for blend modes
/// [`JxlBlendMode::Blend`] and [`JxlBlendMode::MULADD`].
pub alpha: u32,
/// Clamp values to \[0,1\] for the purpose of blending.
pub clamp: JxlBool,
}
/// The information about layers.
/// When decoding, if coalescing is enabled (default), this can be ignored.
/// When encoding, these settings apply to the pixel data given to the encoder,
/// the encoder could choose an internal representation that differs.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlLayerInfo {
/// Whether cropping is applied for this frame. When decoding, if false,
/// [`Self::crop_x0`] and [`Self::crop_y0`] are set to zero, and [`Self::xsize`] and [`Self::ysize`] to the main
/// image dimensions. When encoding and this is false, those fields are
/// ignored. When decoding, if coalescing is enabled (default), this is always
/// false, regardless of the internal encoding in the JPEG XL codestream.
pub have_crop: JxlBool,
/// Horizontal offset of the frame (can be negative).
pub crop_x0: i32,
/// Vertical offset of the frame (can be negative).
pub crop_y0: i32,
/// Width of the frame (number of columns).
pub xsize: u32,
/// Height of the frame (number of rows).
pub ysize: u32,
/// The blending info for the color channels. Blending info for extra channels
/// has to be retrieved separately using [`JxlDecoderGetExtraChannelBlendInfo`].
pub blend_info: JxlBlendInfo,
/// After blending, save the frame as reference frame with this ID (0-3).
/// Special case: if the frame duration is nonzero, ID 0 means "will not be
/// referenced in the future". This value is not used for the last frame.
/// When encoding, ID 3 is reserved to frames that are generated internally by
/// the encoder, and should not be used by applications.
pub save_as_reference: u32,
}
///The header of one displayed frame or non-coalesced layer.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlFrameHeader {
/// How long to wait after rendering in ticks. The duration in seconds of a
/// tick is given by [`JxlAnimationHeader::tps_numerator`] and [`JxlAnimationHeader::tps_denominator`] in
/// [`JxlAnimationHeader`].
pub duration: u32,
/// SMPTE timecode of the current frame in form 0xHHMMSSFF, or 0. The bits are
/// interpreted from most-significant to least-significant as hour, minute,
/// second, and frame. If timecode is nonzero, it is strictly larger than that
/// of a previous frame with nonzero duration. These values are only available
/// if `have_timecodes` in [`JxlAnimationHeader`] is [`JxlBool::True`].
/// This value is only used if `have_timecodes` in [`JxlAnimationHeader`] is
/// [`JxlBool::True`].
pub timecode: u32,
/// Length of the frame name in bytes, or 0 if no name.
/// Excludes null termination character. This value is set by the decoder.
/// For the encoder, this value is ignored and [`JxlEncoderSetFrameName`] is
/// used instead to set the name and the length.
pub name_length: u32,
/** Indicates this is the last animation frame. This value is set by the
* decoder to indicate no further frames follow. For the encoder, it is not
* required to set this value and it is ignored, [`JxlEncoderCloseFrames`] is
* used to indicate the last frame to the encoder instead.
*/
pub is_last: JxlBool,
/** Information about the layer in case of no coalescing.
*/
pub layer_info: JxlLayerInfo,
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/metadata/compressed_icc.rs 0000644 0000000 0000000 00000005627 10461020230 0021717 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Utility functions to compress and decompress ICC streams.
use crate::common::{memory_manager, types::JxlBool};
extern "C-unwind" {
/// Allocates a buffer using the memory manager, fills it with a compressed
/// representation of an ICC profile, returns the result through `output_buffer`
/// and indicates its size through `output_size`.
///
/// The result must be freed using the memory manager once it is not of any more
/// use.
///
/// # Parameters
///
/// - `memory_manager`: Pointer to a `JxlMemoryManager`.
/// - `icc`: Pointer to a buffer containing the uncompressed ICC profile.
/// - `icc_size`: Size of the buffer containing the ICC profile.
/// - `compressed_icc`: Will be set to a pointer to the buffer containing the result.
/// - `compressed_icc_size`: Will be set to the size of the buffer containing the result.
///
/// # Returns
///
/// Whether compressing the profile was successful.
pub fn JxlICCProfileEncode(
memory_manager: *const memory_manager::JxlMemoryManager,
icc: *const u8,
icc_size: usize,
compressed_icc: *mut *mut u8,
compressed_icc_size: *mut usize,
) -> JxlBool;
/// Allocates a buffer using the memory manager, fills it with the decompressed
/// version of the ICC profile in `compressed_icc`, returns the result through
/// `icc` and indicates its size through `icc_size`.
///
/// The result must be freed using the memory manager once it is no longer needed.
///
/// # Parameters
///
/// - `memory_manager`: Pointer to a `JxlMemoryManager`.
/// - `compressed_icc`: Pointer to a buffer containing the compressed ICC profile.
/// - `compressed_icc_size`: Size of the buffer containing the compressed ICC profile.
/// - `icc`: Will be set to a pointer to the buffer containing the result.
/// - `icc_size`: Will be set to the size of the buffer containing the result.
///
/// # Returns
///
/// Whether decompressing the profile was successful.
pub fn JxlICCProfileDecode(
memory_manager: *const memory_manager::JxlMemoryManager,
compressed_icc: *const u8,
compressed_icc_size: usize,
icc: *mut *mut u8,
icc_size: *mut usize,
) -> JxlBool;
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/metadata/gain_map.rs 0000644 0000000 0000000 00000013375 10461020230 0020507 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Utility functions to manipulate jhgm (gain map) boxes.
use crate::{color::color_encoding::JxlColorEncoding, common::types::JxlBool};
/// Gain map bundle
///
/// This structure is used to serialize gain map data to and from an input
/// buffer. It holds pointers to sections within the buffer, and different parts
/// of the gain map data such as metadata, ICC profile data, and the gain map
/// itself.
///
/// The pointers in this structure do not take ownership of the memory they point
/// to. Instead, they reference specific locations within the provided buffer. It
/// is the caller's responsibility to ensure that the buffer remains valid and is
/// not deallocated as long as these pointers are in use. The structure should be
/// considered as providing a view into the buffer, not as an owner of the data.
#[repr(C)]
#[derive(Debug, Clone)]
pub struct JxlGainMapBundle {
/// Version number of the gain map bundle.
pub jhgm_version: u8,
/// Size of the gain map metadata in bytes.
pub gain_map_metadata_size: u16,
/// Pointer to the gain map metadata, which is a binary
/// blob following ISO 21496-1. This pointer references data within the input
/// buffer.
pub gain_map_metadata: *const u8,
/// Indicates whether a color encoding is present.
pub has_color_encoding: JxlBool,
/// If `has_color_encoding` is true, this field contains the
/// uncompressed color encoding data.
pub color_encoding: JxlColorEncoding,
/// Size of the alternative ICC profile in bytes (compressed
/// size).
pub alt_icc_size: u32,
/// Pointer to the compressed ICC profile. This pointer references
/// data within the input buffer.
pub alt_icc: *const u8,
/// Size of the gain map in bytes.
pub gain_map_size: u32,
/// Pointer to the gain map data, which is a JPEG XL naked
/// codestream. This pointer references data within the input buffer.
pub gain_map: *const u8,
}
extern "C-unwind" {
/// Calculates the total size required to serialize the gain map bundle into a
/// binary buffer. This function accounts for all the necessary space to
/// serialize fields such as gain map metadata, color encoding, compressed ICC
/// profile data, and the gain map itself.
///
/// # Parameters
/// - `map_bundle`: A reference to the [`JxlGainMapBundle`] containing all
/// necessary data to compute the size.
/// - `bundle_size`: A mutable reference to a `usize` where the size in bytes
/// required to serialize the bundle will be stored.
///
/// # Returns
/// - A boolean indicating whether setting the size was successful.
pub fn JxlGainMapGetBundleSize(
map_bundle: *const JxlGainMapBundle,
bundle_size: *mut usize,
) -> JxlBool;
/// Serializes the gain map bundle into a preallocated buffer. The function
/// ensures that all parts of the bundle such as metadata, color encoding,
/// compressed ICC profile, and the gain map are correctly encoded into the
/// buffer. First call [`JxlGainMapGetBundleSize`] to get the size needed for
/// the buffer.
///
/// # Parameters
/// - `map_bundle`: A pointer to the [`JxlGainMapBundle`] to serialize.
/// - `output_buffer`: A pointer to the buffer where the serialized data
/// will be written.
/// - `output_buffer_size`: The size of the output buffer in bytes. Must be
/// large enough to hold the entire serialized data.
/// - `bytes_written`: A mutable reference to a `usize` where the number of bytes
/// written to the output buffer will be stored.
///
/// # Returns
/// - A boolean indicating whether writing the bundle was successful.
pub fn JxlGainMapWriteBundle(
map_bundle: *const JxlGainMapBundle,
output_buffer: *mut u8,
output_buffer_size: usize,
bytes_written: *mut usize,
) -> JxlBool;
/// Deserializes a gain map bundle from a provided buffer and populates a
/// [`JxlGainMapBundle`] structure with the data extracted. This function assumes
/// the buffer contains a valid serialized gain map bundle. After successful
/// execution, the [`JxlGainMapBundle`] structure will reference three different
/// sections within the buffer:
/// - `gain_map_metadata`
/// - `alt_icc`
/// - `gain_map`
///
/// These sections will be accompanied by their respective sizes. Users must
/// ensure that the buffer remains valid as long as these pointers are in use.
///
/// # Parameters
/// - `map_bundle`: Pointer to a preallocated [`JxlGainMapBundle`] where
/// the deserialized data will be stored.
/// - `input_buffer`: Pointer to the buffer containing the serialized gain
/// map bundle data.
/// - `input_buffer_size`: The size of the input buffer in bytes.
/// - `bytes_read`: The number of bytes read from the input buffer.
///
/// # Returns
/// - A boolean indicating whether reading the bundle was successful.
pub fn JxlGainMapReadBundle(
map_bundle: *mut JxlGainMapBundle,
input_buffer: *const u8,
input_buffer_size: usize,
bytes_read: *mut usize,
) -> JxlBool;
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/metadata.rs 0000644 0000000 0000000 00000001377 10461020230 0016733 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! `jxl_metadata`: JPEG XL metadata structures.
pub mod codestream_header;
pub mod compressed_icc;
pub mod gain_map;
jpegxl-sys-0.11.2+libjxl-0.11.1/src/threads/parallel_runner.rs 0000644 0000000 0000000 00000013771 10461020230 0021773 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! API for running data operations in parallel in a multi-threaded environment.
//! This module allows the JPEG XL caller to define their own way of creating and
//! assigning threads.
//!
//! The [`JxlParallelRunner`] function type defines a parallel data processing
//! runner that may be implemented by the caller to allow the library to process
//! in multiple threads. The multi-threaded processing in this library only
//! requires to run the same function over each number of a range, possibly
//! running each call in a different thread. The JPEG XL caller is responsible
//! for implementing this logic using the thread APIs available in their system.
//! For convenience, a C++ implementation based on `std::thread` is provided in
//! [`super::thread_parallel_runner`] (part of the `jpegxl_threads` library).
//!
//! Thread pools usually store small numbers of heterogeneous tasks in a queue.
//! When tasks are identical or differ only by an integer input parameter, it is
//! much faster to store just one function of an integer parameter and call it
//! for each value. Conventional vector-of-tasks can be run in parallel using a
//! lambda function adapter that simply calls `task_funcs[task]`.
//!
//! If no multi-threading is desired, a `NULL` value of [`JxlParallelRunner`]
//! will use an internal implementation without multi-threading.
use std::ffi::{c_int, c_void};
/// Return code used in the `JxlParallel*` functions as return value. A value
/// of [`JXL_PARALLEL_RET_SUCCESS`] means success and any other value means error.
/// The special value [`JXL_PARALLEL_RET_RUNNER_ERROR`] can be used by the runner
/// to indicate any other error.
pub type JxlParallelRetCode = c_int;
/// Code returned by the [`JxlParallelRunInit`] function to indicate success.
pub const JXL_PARALLEL_RET_SUCCESS: JxlParallelRetCode = 0;
/// Code returned by the [`JxlParallelRunInit`] function to indicate a general error.
pub const JXL_PARALLEL_RET_RUNNER_ERROR: JxlParallelRetCode = -1;
/// Parallel run initialization callback. See [`JxlParallelRunner`] for details.
///
/// This function MUST be called by the [`JxlParallelRunner`] only once, on the
/// same thread that called [`JxlParallelRunner`], before any parallel
/// execution. The purpose of this call is to provide the maximum number of
/// threads that the [`JxlParallelRunner`] will use, which can be used by JPEG XL
/// to allocate per-thread storage if needed.
///
/// # Parameters
/// - `jpegxl_opaque`: the `jpegxl_opaque` handle provided to
/// [`JxlParallelRunner`] must be passed here.
/// - `num_threads`: the maximum number of threads. This value must be
/// positive.
///
/// # Returns
/// - `0` if the initialization process was successful.
/// - An error code if there was an error, which should be returned by
/// [`JxlParallelRunner`].
pub type JxlParallelRunInit = unsafe extern "C-unwind" fn(
jpegxl_opaque: *mut c_void,
num_threads: usize,
) -> JxlParallelRetCode;
/// Parallel run data processing callback. See [`JxlParallelRunner`] for
/// details.
///
/// This function MUST be called once for every number in the range `[start_range,
/// end_range)` (including `start_range` but not including `end_range`) passing this
/// number as the `value`. Calls for different values may be executed from
/// different threads in parallel.
///
/// # Parameters
/// - `jpegxl_opaque`: the `jpegxl_opaque` handle provided to
/// [`JxlParallelRunner`] must be passed here.
/// - `value`: the number in the range `[start_range, end_range)` of the call.
/// - `thread_id`: the thread number where this function is being called from.
/// This must be lower than the `num_threads` value passed to
/// [`JxlParallelRunInit`].
pub type JxlParallelRunFunction =
unsafe extern "C-unwind" fn(jpegxl_opaque: *mut c_void, value: u32, thread_id: usize);
/// [`JxlParallelRunner`] function type. A parallel runner implementation can be
/// provided by a JPEG XL caller to allow running computations in multiple
/// threads. This function must call the initialization function [`init`](JxlParallelRunInit) in the
/// same thread that called it and then call the passed [`func`](JxlParallelRunFunction) once for every
/// number in the range `[start_range, end_range)` (including `start_range` but not
/// including `end_range`) possibly from different multiple threads in parallel.
///
/// The [`JxlParallelRunner`] function does not need to be re-entrant. This
/// means that the same [`JxlParallelRunner`] function with the same
/// `runner_opaque` provided parameter will not be called from the library from
/// either [`init`](JxlParallelRunInit) or [`func`](JxlParallelRunFunction) in the same decoder or encoder instance.
/// However, a single decoding or encoding instance may call the provided [`JxlParallelRunner`] multiple
/// times for different parts of the decoding or encoding process.
///
/// # Returns
/// - `0`: if the [`init`](JxlParallelRunInit) call succeeded (returned `0`) and no other error
/// occurred in the runner code.
/// - [`JXL_PARALLEL_RET_RUNNER_ERROR`]: if an error occurred in the runner
/// code, for example, setting up the threads.
/// - The return value of [`init()`](JxlParallelRunInit) if non-zero.
pub type JxlParallelRunner = unsafe extern "C-unwind" fn(
runner_opaque: *mut c_void,
jpegxl_opaque: *mut c_void,
init: JxlParallelRunInit,
func: JxlParallelRunFunction,
start_range: u32,
end_range: u32,
) -> JxlParallelRetCode;
jpegxl-sys-0.11.2+libjxl-0.11.1/src/threads/resizable_parallel_runner.rs 0000644 0000000 0000000 00000005751 10461020230 0024032 0 ustar 0000000 0000000 /*!
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Implementation using `std::thread` of a resizeable [`JxlParallelRunner`].
//! Implementation of [`JxlParallelRunner`] than can be used to enable
//! multithreading when using the JPEG XL library. This uses `std::thread`
//! internally and related synchronization functions. The number of threads
//! created can be changed after creation of the thread pool; the threads
//! (including the main thread) are re-used for every
//! `ResizableParallelRunner::Runner` call. Only one concurrent
//! [`JxlResizableParallelRunner`] call per instance is allowed at a time.
//!
//! This is a scalable, lower-overhead thread pool runner, especially suitable
//! for data-parallel computations in the fork-join model, where clients need to
//! know when all tasks have completed.
//!
//! Compared to the implementation in [`super::thread_parallel_runner`], this
//! implementation is tuned for execution on lower-powered systems, including
//! for example ARM CPUs with big.LITTLE computation models.
use std::ffi::c_void;
#[cfg(doc)]
use super::parallel_runner::JxlParallelRunner;
use super::parallel_runner::{JxlParallelRetCode, JxlParallelRunFunction, JxlParallelRunInit};
use crate::common::memory_manager::JxlMemoryManager;
extern "C-unwind" {
/// Parallel runner internally using `std::thread`. Use as [`JxlParallelRunner`].
pub fn JxlResizableParallelRunner(
runner_opaque: *mut c_void,
jpegxl_opaque: *mut c_void,
init: JxlParallelRunInit,
func: JxlParallelRunFunction,
start_range: u32,
end_range: u32,
) -> JxlParallelRetCode;
/// Creates the runner for [`JxlResizableParallelRunner`]. Use as the opaque
/// runner. The runner will execute tasks on the calling thread until
/// [`JxlResizableParallelRunnerSetThreads`] is called.
pub fn JxlResizableParallelRunnerCreate(memory_manager: *const JxlMemoryManager)
-> *mut c_void;
/// Changes the number of threads for [`JxlResizableParallelRunner`].
pub fn JxlResizableParallelRunnerSetThreads(runner_opaque: *mut c_void, num_threads: usize);
/// Suggests a number of threads to use for an image of given size.
pub fn JxlResizableParallelRunnerSuggestThreads(xsize: u64, ysize: u64) -> u32;
/// Destroys the runner created by [`JxlResizableParallelRunnerCreate`].
pub fn JxlResizableParallelRunnerDestroy(runner_opaque: *mut c_void);
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/threads/thread_parallel_runner.rs 0000644 0000000 0000000 00000005404 10461020230 0023314 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! Implementation using `std::thread` of a [`JxlParallelRunner`].
//! Implementation of [`JxlParallelRunner`] that can be used to enable
//! multithreading when using the JPEG XL library. This uses `std::thread`
//! internally and related synchronization functions. The number of threads
//! created is fixed at construction time and the threads are re-used for every
//! `ThreadParallelRunner::Runner` call. Only one concurrent
//! `JxlThreadParallelRunner` call per instance is allowed at a time.
//!
//! This is a scalable, lower-overhead thread pool runner, especially suitable
//! for data-parallel computations in the fork-join model, where clients need to
//! know when all tasks have completed.
//!
//! This thread pool can efficiently load-balance millions of tasks using an
//! atomic counter, thus avoiding per-task virtual or system calls. With 48
//! hyperthreads and 1M tasks that add to an atomic counter, overall runtime is
//! 10-20x higher when using `std::async`, and ~200x for a queue-based thread
//! pool.
use std::ffi::c_void;
#[cfg(doc)]
use super::parallel_runner::JxlParallelRunner;
use super::parallel_runner::{JxlParallelRetCode, JxlParallelRunFunction, JxlParallelRunInit};
use crate::common::memory_manager::JxlMemoryManager;
extern "C-unwind" {
/// Parallel runner internally using `std::thread`. Use as [`JxlParallelRunner`].
pub fn JxlThreadParallelRunner(
runner_opaque: *mut c_void,
jpegxl_opaque: *mut c_void,
init: JxlParallelRunInit,
func: JxlParallelRunFunction,
start_range: u32,
end_range: u32,
) -> JxlParallelRetCode;
/// Creates the runner for [`JxlThreadParallelRunner`]. Use as the opaque runner.
pub fn JxlThreadParallelRunnerCreate(
memory_manager: *const JxlMemoryManager,
num_worker_threads: usize,
) -> *mut c_void;
/// Destroys the runner created by [`JxlThreadParallelRunnerCreate`].
pub fn JxlThreadParallelRunnerDestroy(runner_opaque: *mut c_void);
/// Returns a default `num_worker_threads` value for [`JxlThreadParallelRunnerCreate`].
pub fn JxlThreadParallelRunnerDefaultNumWorkerThreads() -> usize;
}
jpegxl-sys-0.11.2+libjxl-0.11.1/src/threads.rs 0000644 0000000 0000000 00000001444 10461020230 0016600 0 ustar 0000000 0000000 /*
This file is part of jpegxl-sys.
jpegxl-sys is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
jpegxl-sys is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with jpegxl-sys. If not, see .
*/
//! `libjxl_threads`: Parallel processing support for JPEG XL.
pub mod parallel_runner;
pub mod resizable_parallel_runner;
pub mod thread_parallel_runner;