pax_global_header 0000666 0000000 0000000 00000000064 12753434647 0014531 g ustar 00root root 0000000 0000000 52 comment=1bd97ab88751639cc699387ef508e2b2defcfa8f
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/ 0000775 0000000 0000000 00000000000 12753434647 0023746 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/.gitignore 0000664 0000000 0000000 00000000123 12753434647 0025732 0 ustar 00root root 0000000 0000000 html/*
.project
.cproject
.externalToolBuilders
.settings
*.directory
attic/*
php
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/LICENSE 0000664 0000000 0000000 00000104505 12753434647 0024760 0 ustar 00root root 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.
{one line to give the program's name and a brief idea of what it does.}
Copyright (C) {year} {name of author}
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:
{project} Copyright (C) {year} {fullname}
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
.
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/README.md 0000664 0000000 0000000 00000000064 12753434647 0025225 0 ustar 00root root 0000000 0000000 # elphel-apps-php-extension
php extension functions
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/run_bitbake.sh 0000775 0000000 0000000 00000000340 12753434647 0026567 0 ustar 00root root 0000000 0000000 #!/bin/bash
args="$@"
while (( "$#" )); do
shift
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Launching bitbake $args"
cd $DIR/../../poky
. ./oe-init-build-env
bitbake $args | sed -u 's@| @@'
exit 0
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ 0000775 0000000 0000000 00000000000 12753434647 0024535 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/ 0000775 0000000 0000000 00000000000 12753434647 0025335 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/ 0000775 0000000 0000000 00000000000 12753434647 0026606 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/CREDITS 0000664 0000000 0000000 00000000006 12753434647 0027622 0 ustar 00root root 0000000 0000000 elphel elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/EXPERIMENTAL 0000664 0000000 0000000 00000000000 12753434647 0030414 0 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/config.m4 0000664 0000000 0000000 00000004145 12753434647 0030321 0 ustar 00root root 0000000 0000000 dnl $Id$
dnl config.m4 for extension elphel
dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.
dnl If your extension references something external, use with:
dnl PHP_ARG_WITH(elphel, for elphel support,
dnl Make sure that the comment is aligned:
dnl [ --with-elphel Include elphel support])
dnl Otherwise use enable:
PHP_ARG_ENABLE(elphel, whether to enable elphel support,
Make sure that the comment is aligned:
[ --enable-elphel Enable elphel support])
if test "$PHP_ELPHEL" != "no"; then
dnl Write more examples of tests here...
dnl # --with-elphel -> check with-path
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
dnl SEARCH_FOR="/include/elphel.h" # you most likely want to change this
dnl if test -r $PHP_ELPHEL/$SEARCH_FOR; then # path given as parameter
dnl ELPHEL_DIR=$PHP_ELPHEL
dnl else # search default path list
dnl AC_MSG_CHECKING([for elphel files in default path])
dnl for i in $SEARCH_PATH ; do
dnl if test -r $i/$SEARCH_FOR; then
dnl ELPHEL_DIR=$i
dnl AC_MSG_RESULT(found in $i)
dnl fi
dnl done
dnl fi
dnl
dnl if test -z "$ELPHEL_DIR"; then
dnl AC_MSG_RESULT([not found])
dnl AC_MSG_ERROR([Please reinstall the elphel distribution])
dnl fi
dnl # --with-elphel -> add include path
ELPHEL_DIR=$abs_srcdir/ext/elphel
UAPI_DIR=$PKG_CONFIG_SYSROOT_DIR/usr/include-uapi
PHP_ADD_INCLUDE($ELPHEL_DIR/include)
PHP_ADD_INCLUDE($UAPI_DIR)
dnl # --with-elphel -> check for lib and symbol presence
dnl LIBNAME=elphel # you may want to change this
dnl LIBSYMBOL=elphel # you most likely want to change this
dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
dnl [
dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $ELPHEL_DIR/$PHP_LIBDIR, ELPHEL_SHARED_LIBADD)
dnl AC_DEFINE(HAVE_ELPHELLIB,1,[ ])
dnl ],[
dnl AC_MSG_ERROR([wrong elphel lib version or lib not found])
dnl ],[
dnl -L$ELPHEL_DIR/$PHP_LIBDIR -lm
dnl ])
dnl
dnl PHP_SUBST(ELPHEL_SHARED_LIBADD)
PHP_NEW_EXTENSION(elphel, elphel_php.c, $ext_shared)
fi
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/config.w32 0000664 0000000 0000000 00000000450 12753434647 0030407 0 ustar 00root root 0000000 0000000 // $Id$
// vim:ft=javascript
// If your extension references something external, use ARG_WITH
// ARG_WITH("elphel", "for elphel support", "no");
// Otherwise, use ARG_ENABLE
// ARG_ENABLE("elphel", "enable elphel support", "no");
if (PHP_ELPHEL != "no") {
EXTENSION("elphel", "elphel.c");
}
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/elphel_php.c 0000664 0000000 0000000 00000307477 12753434647 0031114 0 ustar 00root root 0000000 0000000 /**
* \file elphel_php.c
* \brief Implementation of elphel extension module for PHP to support camera functionality
* \date 2008
*/
/*!***************************************************************************
*! FILE NAME : elphel_php.c
*! DESCRIPTION: Implementation of elphel extension module for PHP
*! Copyright (C) 2008 Elphel, Inc.
*! -----------------------------------------------------------------------------**
*! 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 .
*! -----------------------------------------------------------------------------**
*! $Log: elphel_php.c,v $
*! Revision 1.8 2012/04/20 00:25:26 elphel
*! fixed bug in reading Exif data from PHP that was introduced while expanding MakerNote to include temperatures
*!
*! Revision 1.7 2012/04/08 04:11:28 elphel
*! 8.2.2 changes related to temperatures measurement and embedding in the Exif MakerNote
*!
*! Revision 1.6 2010/08/10 21:14:31 elphel
*! 8.0.8.39 - added EEPROM support for multiplexor and sensor boards, so autocampars.php uses application-specific defaults. Exif Orientation tag support, camera Model reflects application and optional mode (i.e. camera number in Eyesis)
*!
*! Revision 1.5 2010/07/20 20:13:34 elphel
*! 8.0.8.33 - added MakerNote info for composite images made with multisensor cameras (with 10359 board)
*!
*! Revision 1.4 2010/05/13 03:39:31 elphel
*! 8.0.8.12 - drivers modified for multi-sensor operation
*!
*! Revision 1.3 2010/03/04 06:41:40 elphel
*! 8.0.7.3 - more data to makerNote
*!
*! Revision 1.2 2009/12/28 06:24:17 elphel
*! 8.0.6.6 - added MakerNote to Exif, it icludes channels gains and gammas/black levels
*!
*! Revision 1.1 2009/04/03 23:18:59 elphel
*! rev 8.0.4.1 - upgraded PHP to 5.2.9 - directories/files added/removed
*!
*! Revision 1.5 2009/02/18 06:25:41 elphel
*! fixed unterminated string of 1 character (GPS mode - 2/3)
*!
*! Revision 1.4 2008/12/08 08:17:50 elphel
*! bug fix in elphel_get_P_value() - it did not handle bit filed for non-global variables ( elphel_get_P_arr() was OK)
*!
*! Revision 1.3 2008/11/30 05:04:46 elphel
*! added Doxygen file data
*!
*! Revision 1.2 2008/11/28 08:17:09 elphel
*! keeping Doxygen a little happier
*!
*! Revision 1.1.1.1 2008/11/27 20:04:02 elphel
*!
*!
*! Revision 1.28 2008/11/22 05:56:40 elphel
*! elphel_set_P_arr(), elphel_set_P_value() now return frame number parameters were written to
*!
*! Revision 1.27 2008/11/20 07:06:04 elphel
*! just touched to overcome dependency (or lack of its support) to make it notice updated c313a.h
*!
*! Revision 1.26 2008/11/15 07:04:27 elphel
*! new parameters to modify analog gains while white balancing
*!
*! Revision 1.25 2008/11/13 05:40:45 elphel
*! 8.0.alpha16 - modified histogram storage, profiling
*!
*! Revision 1.24 2008/11/05 02:01:25 elphel
*! Added bit field manipulation in parameters
*!
*! Revision 1.23 2008/11/04 17:41:43 elphel
*! added elphel_gamma(), elphel_reverse_gamma(), elphel_histogram(), elphel_reverse_histogram() functions
*!
*! Revision 1.22 2008/11/02 07:24:20 elphel
*! added support for some legacy functions
*!
*! Revision 1.21 2008/11/02 00:33:02 elphel
*! Added TODO
*!
*! Revision 1.20 2008/11/01 06:25:46 elphel
*! elphel_get_circbuf_pointers() now returns framenumber too
*!
*! Revision 1.19 2008/10/31 18:26:32 elphel
*! Adding support for constants like SENSOR_REGS32 (defined constant plus 32 to simplify referencing sensor registers from PHP
*!
*! Revision 1.18 2008/10/29 04:18:28 elphel
*! v.8.0.alpha10 made a separate structure for global parameters (not related to particular frames in a frame queue)
*!
*! Revision 1.17 2008/10/28 07:05:49 elphel
*! touched
*!
*! Revision 1.16 2008/10/25 19:51:06 elphel
*! Changed word order in writes to gamma tables driver
*!
*! Revision 1.15 2008/10/23 18:26:14 elphel
*! Fixed percentile calculations in histograms
*!
*! Revision 1.14 2008/10/23 08:11:38 elphel
*! updated for histograms wait queues
*!
*! Revision 1.13 2008/10/19 06:56:05 elphel
*! elphel_wait_frame() now works only for compressed frames, new elphel_skip_frames() and elphel_wait_frame_abs() wait sequencer frames (all sensor frames, even those that are not compressed)
*!
*! Revision 1.12 2008/10/15 22:28:56 elphel
*! snapshot 8.0.alpha2
*!
*! Revision 1.11 2008/10/13 16:56:20 elphel
*! just touched to force recompile
*!
*! Revision 1.10 2008/10/12 06:13:10 elphel
*! snapshot
*!
*! Revision 1.9 2008/10/08 21:26:25 elphel
*! snapsot 7.2.0.pre4 - first images (actually - second)
*!
*! Revision 1.8 2008/10/05 05:13:33 elphel
*! snapshot003
*!
*! Revision 1.7 2008/10/04 16:10:12 elphel
*! snapshot
*!
*! Revision 1.6 2008/09/25 00:58:11 elphel
*! snapshot
*!
*! Revision 1.5 2008/09/19 18:06:38 elphel
*! snapshot
*!
*! Revision 1.4 2008/09/19 04:37:24 elphel
*! snapshot
*!
*! Revision 1.3 2008/09/07 19:48:08 elphel
*! snapshot
*!
*! Revision 1.2 2008/06/04 20:07:08 elphel
*! adding support for multiple frames
*!
*! Revision 1.21 2008/05/02 15:12:09 elphel
*! minor comment edit
*!
*! Revision 1.20 2008/05/01 01:32:04 elphel
*! support for the frame number - combining hardware frame counter used by i2c (3-bit) and software one
*!
*! Revision 1.19 2008/04/25 21:31:35 elphel
*! Added Exif_Photo_ExposureTime to be returned by elphel_get_exif_elphel()
*!
*! Revision 1.18 2008/04/24 18:16:40 elphel
*! New function to retrieve circbuf structure (frame pointers and Exif pointers)
*!
*! Revision 1.17 2008/04/22 22:14:08 elphel
*! Added functions related to Exif data
*!
*! Revision 1.16 2008/04/20 06:49:04 elphel
*! Added histogram related functions
*!
*! Revision 1.15 2008/04/17 22:36:07 elphel
*! Bug fix, new function added - elphel_is_compressor_idle()
*!
*! Revision 1.14 2008/03/20 22:25:09 elphel
*! elphel_trigger - programming synchronization parameters
*!
*! Revision 1.13 2008/03/15 23:04:21 elphel
*! added FPGA registers R/W
*!
*! Revision 1.12 2008/01/27 06:23:17 elphel
*! New function - elphel_wait_frame (wait fro the next frame to be compressed)
*!
*! Revision 1.11 2008/01/12 06:53:23 elphel
*! 7.1.7.2 - added elphel_autoexposure_get() function to elphel php extension
*!
*! Revision 1.10 2008/01/11 07:47:44 elphel
*! added elphel_autoexposure_set() function
*!
*! Revision 1.9 2008/01/10 02:43:37 elphel
*! Added balance of 2 greens in Bayer mosaic
*!
*! Revision 1.8 2008/01/09 10:22:02 elphel
*! Implemented elphel_white_balance() function
*!
*! Revision 1.7 2007/12/14 22:38:53 elphel
*! cleaned up after fixing cache bug
*!
*! Revision 1.6 2007/12/06 19:05:33 elphel
*! 2 new functions - arbitrary compressor command (elphel_compressor_cmd) and elphel_compressor_reset
*!
*! Revision 1.5 2007/12/05 23:41:04 elphel
*! Fixing minor in bugs in the sensor reset code
*!
*! Revision 1.4 2007/12/05 22:01:19 elphel
*! added handling etrax fs mmap cach problem when communicating between PHP extension and the driver
*!
*! Revision 1.3 2007/12/04 06:41:11 elphel
*! Implementation of 2 additional functions: elphel_get_P_arr, elphel_set_P_arr
*!
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include /* mmap */
#include
#include /* (O_RDWR) */
#include
#include
#include "php.h"
#include "php_ini.h" /* for php.ini processing */
#include "elphel_php.h"
ZEND_DECLARE_MODULE_GLOBALS(elphel)
static zend_function_entry elphel_functions[] = {
PHP_FE(elphel_get_frame, NULL)
PHP_FE(elphel_skip_frames, NULL)
PHP_FE(elphel_wait_frame_abs, NULL)
PHP_FE(elphel_framepars_get_raw, NULL)
PHP_FE(elphel_parse_P_name, NULL)
PHP_FE(elphel_is_global_par, NULL)
PHP_FE(elphel_is_frame_par, NULL)
PHP_FE(elphel_get_P_value, NULL)
PHP_FE(elphel_test, NULL)
PHP_FE(elphel_set_P_value, NULL)
PHP_FE(elphel_get_P_arr, NULL)
PHP_FE(elphel_set_P_arr, NULL)
PHP_FE(elphel_gamma_add, NULL)
PHP_FE(elphel_gamma_add_custom, NULL)
PHP_FE(elphel_gamma_get, NULL)
PHP_FE(elphel_gamma_get_index, NULL)
PHP_FE(elphel_gamma_get_raw, NULL)
PHP_FE(elphel_histogram_get_raw, NULL)
PHP_FE(elphel_histogram_get, NULL)
PHP_FE(elphel_get_state, NULL)
PHP_FE(elphel_compressor_reset, NULL)
PHP_FE(elphel_compressor_run, NULL)
PHP_FE(elphel_compressor_stop, NULL)
PHP_FE(elphel_compressor_frame, NULL)
PHP_FE(elphel_reset_sensor, NULL)
PHP_FE(elphel_set_fpga_time, NULL)
PHP_FE(elphel_get_fpga_time, NULL)
PHP_FE(elphel_wait_frame, NULL)
PHP_FE(elphel_fpga_read, NULL)
PHP_FE(elphel_fpga_write, NULL)
PHP_FE(elphel_gamma, NULL)
PHP_FE(elphel_reverse_gamma, NULL)
PHP_FE(elphel_histogram, NULL)
PHP_FE(elphel_reverse_histogram, NULL)
PHP_FE(elphel_get_exif_field, NULL)
PHP_FE(elphel_set_exif_field, NULL)
PHP_FE(elphel_get_interframe_meta, NULL)
PHP_FE(elphel_get_exif_elphel, NULL)
PHP_FE(elphel_update_exif, NULL)
PHP_FE(elphel_get_circbuf_pointers, NULL)
{NULL, NULL, NULL}
};
zend_module_entry elphel_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_ELPHEL_EXTNAME,
elphel_functions,
PHP_MINIT(elphel),
PHP_MSHUTDOWN(elphel),
PHP_RINIT(elphel),
NULL,
PHP_MINFO(elphel),
#if ZEND_MODULE_API_NO >= 20010901
PHP_ELPHEL_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_ELPHEL
ZEND_GET_MODULE(elphel)
#endif
PHP_INI_BEGIN()
//! read ini entries here
PHP_INI_END()
//!call before any access to sensor parameters/functions
static void init_sens() {
}
/**
* @brief See if the name ends with __A,__B,__c,__a,__b.__c
* @param name constant name, possibly ending with a suffix __A,__B,__c,__a,__b or __c
* @return <0 - no suffix, >=0 channel (0..2) | 4 for strict (lower case)
*/
//multiSensIndex
int parseMultiSens(char * name) {
int len= strlen(name);
int nIndex;
int d=0;
int dp=1;
int bfields;
int rslt=-1;
if ((len>3) && (name[len-2]=='_') && (name[len-3]=='_')) {
switch (name[len-1]) {
case 'A':rslt=0; break;
case 'B':rslt=1; break;
case 'C':rslt=2; break;
case 'a':rslt=256; break;
case 'b':rslt=257; break;
case 'c':rslt=258; break;
}
}
if (rslt >=0) name[len-3]='\0';
return rslt;
}
/**
* @brief apply
* @param parNum parameter composite index
* @param multiMod bit 8 - strict, lower bits - channel index
* @return -1 - failure, otherwise - parameter index with allcontrol bits preserved
*/
//multiSensIndex P_MAX_PAR MAX_SENSORS=3
int applyMultiSens(long parNum, long multiMod) {
unsigned long * multiSensIndex = ((unsigned long *) (ELPHEL_G (multiSensIndex)));
long parIndex= parNum &0xffff;
if (parIndex >= P_MAX_PAR) return -1;
if (multiSensIndex[parIndex]==0) {
if (multiMod & 0x100) return -1;
return parNum; /// No individual parameters available, return the original one as 'strict' bit is not set.
}
multiMod &= 0xff;
if (multiMod >= MAX_SENSORS) return -1;
parIndex= (multiSensIndex[parIndex]+multiMod) & 0xffff;
if (parIndex >= P_MAX_PAR) return -1; /// multiSensIndex seems to be corrupted - add error message?
return (parNum & 0xffff0000) | parIndex; /// preserve original modifiers
}
/**
* @brief See if the name ends with number, truncate name to remove number and return number value
* @param name constant name, possibly ending with a number (decimal)
* if constant includes "__" (double "_") and has 4 decimals after __WWBB, those decimals are treated as
* bit field specs (WW 1..31 - width, BB - 0..31 - start bit ), i.e. "__0816" is the 3-rd byte of 4 in the 32-bit parameter
* These bit-filed modifiers are stored in bits 16..20 (bit) and 21..25 (width) of parameter address (number)
* @return number value (to be added to the constant value) or -1 if name does not end with a number
*/
//multiSensIndex
int splitConstantName(char * name) {
int len= strlen(name);
int nIndex;
int d=0;
int dp=1;
int bfields;
int success=0;
if ((len>6) && (name[len-6]=='_') && (name[len-5]=='_')) {
d= FRAMEPAIR_FRAME_BITS(((name[len-3] - '0') + ((name[len-4] - '0') * 10)), ((name[len-1] - '0') + ((name[len-2] - '0') * 10)));
name[len-6]='\0';
len-=6;
success=1;
}
nIndex= len-1;
while ((nIndex>0) && (name[nIndex]>='0') && (name[nIndex] <='9')){
d+=dp*(name[nIndex]-'0');
dp*=10;
nIndex--;
success=1;
}
nIndex++;
if (success) {
name[nIndex]='\0'; /// terminate name with '\0'
return d;
} else return -1;
}
/// Get current frame number
PHP_FUNCTION(elphel_get_frame)
{
RETURN_LONG( ELPHEL_GLOBALPARS(G_THIS_FRAME));
}
PHP_FUNCTION(elphel_skip_frames)
{
long skip=1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &skip) == FAILURE) {
RETURN_NULL();
}
long target_frame=lseek((int) ELPHEL_G( fd_fparmsall), 0, SEEK_CUR )+skip;
if ((target_frame<0) || (target_frame > 0x7ffffdff)) RETURN_NULL(); /// Out of limit for skip frames
RETURN_LONG(lseek((int) ELPHEL_G( fd_fparmsall), target_frame + LSEEK_FRAME_WAIT_ABS, SEEK_END ));
}
PHP_FUNCTION(elphel_wait_frame_abs)
{
long target_frame;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &target_frame) == FAILURE) {
RETURN_NULL();
}
if ((target_frame<0) || (target_frame > 0x7ffffdff)) RETURN_NULL(); /// Out of limit for skip frames
RETURN_LONG(lseek((int) ELPHEL_G( fd_fparmsall), target_frame + LSEEK_FRAME_WAIT_ABS, SEEK_END ));
}
/**
* @brief Parse P_* /G_* parameter name with modifiers
* @param name - constant name (w/o leading "ELPHEL_")
* @return full address/number or NULL if it does not exist
*/
PHP_FUNCTION(elphel_parse_P_name)
{
char full_constant_name[256];
char *name;
int name_len;
long full_addr =-1;
zval const_value;
long constAddNumber;
long multiMod;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_NULL();
}
if (strlen(name)>(sizeof(full_constant_name)-8)) RETURN_NULL();
sprintf (full_constant_name,"ELPHEL_%s",name);
if (zend_get_constant(full_constant_name, strlen(full_constant_name), &const_value TSRMLS_CC)) { /// found the constant as is
full_addr= Z_LVAL(const_value);
} else {
multiMod=parseMultiSens(full_constant_name); /// will truncate full_constant_name if sensor number suffix found
constAddNumber=splitConstantName(full_constant_name);
if ((constAddNumber>=0) && (zend_get_constant(full_constant_name, strlen(full_constant_name), &const_value TSRMLS_CC))) {
full_addr= (Z_LVAL(const_value) & ~FRAMEPAIR_MASK_BYTES)+constAddNumber; /// FRAMEPAIR_MASK_BYTES to prevent bit-field modifier addition to constants that already have them
if ((multiMod>=0) && (full_addr!=-1)) full_addr=applyMultiSens(full_addr,multiMod);
}
}
if (full_addr!=-1) {
RETURN_LONG (full_addr);
zval_dtor(&const_value);
}
RETURN_NULL();
}
/**
* @brief Strips integer constant of optional modifiers and finds if it is a valid global parameter number
* @param full parameter address
* @return true if this address is a valid address of a global parameter
*/
PHP_FUNCTION(elphel_is_global_par)
{
long addr;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &addr) == FAILURE) {
RETURN_NULL();
}
addr &= 0xffff; /// remove any possible flags
if ((addr >= FRAMEPAR_GLOBALS) && (addr < (FRAMEPAR_GLOBALS+P_MAX_GPAR))) RETURN_TRUE;
RETURN_FALSE;
}
/**
* @brief Strips integer constant of optional modifiers and finds if it is a valid frame parameter number
* @param full parameter address
* @return true if this address is a valid address of a frame parameter
*/
PHP_FUNCTION(elphel_is_frame_par)
{
long addr;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &addr) == FAILURE) {
RETURN_NULL();
}
addr &= 0xffff; /// remove any possible flags
if (addr < (sizeof (struct framepars_t) >>2)) RETURN_TRUE;
RETURN_FALSE;
}
//! Read value from the sensor/compressor parameters ("read" parameters, verified by the driver), see asm/elphel/c313a.h
///TODO: Make it read pastPars also?
PHP_FUNCTION(elphel_get_P_value)
{
long addr, full_addr;
long frame=-1;
long frame_index=-1;
int frame_stored;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &full_addr,&frame) == FAILURE) {
RETURN_NULL();
}
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME);
}
addr = full_addr & 0xffff; /// remove any possible flags
/// is it a global parameter?
if (addr >= FRAMEPAR_GLOBALS) { /// these globals can be written just through mmap
if (addr >= (FRAMEPAR_GLOBALS+P_MAX_GPAR)) {
RETURN_NULL();
}
if (full_addr & FRAMEPAIR_MASK_BYTES) {
RETURN_LONG(FRAMEPAIR_FRAME_FIELD(full_addr,ELPHEL_GLOBALPARS(addr)));
} else {
RETURN_LONG(ELPHEL_GLOBALPARS(addr));
}
}
/// processing dynamic frame parameters
if ((addr<0) ||(addr>= (sizeof (struct framepars_t) >>2))) {
RETURN_NULL();
}
if (frame <0) {
// frame=ELPHEL_GLOBALPARS(G_THIS_FRAME) + FRAME_DEAFAULT_AHEAD;
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME); /// read current (most recent) frame - different from _set_
}
///try framePars
frame_index = frame & PARS_FRAMES_MASK;
frame_stored= ((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[P_FRAME];
if (frame_stored == frame) { /// This is what we are looking for
if (full_addr & FRAMEPAIR_MASK_BYTES) {
RETURN_LONG( FRAMEPAIR_FRAME_FIELD(full_addr,((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[addr]));
} else {
RETURN_LONG( ((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[addr]);
}
}
if (frame_stored = (sizeof (struct framepars_past_t) >>2))) {
RETURN_NULL();
}
if (full_addr & FRAMEPAIR_MASK_BYTES) {
RETURN_LONG(FRAMEPAIR_FRAME_FIELD(full_addr,((struct framepars_past_t *) ELPHEL_G(pastPars))[frame_index].past_pars[addr]));
} else {
RETURN_LONG( ((struct framepars_past_t *) ELPHEL_G(pastPars))[frame_index].past_pars[addr]);
}
}
/// too late, probably
RETURN_NULL();
}
PHP_FUNCTION(elphel_test)
{
long result= ELPHEL_GLOBALPARS(G_THIS_FRAME);
RETURN_LONG(result);
}
///NOTE: Just for compatibility with older code
//!Get sensor state, usually 7- sensor is running, compressor is stopped, 8 - compressor is runing
//!program sensor/compressor according to the parameters specified. Argument==0 - restart the sensor, 1 - do it "on the fly"
PHP_FUNCTION(elphel_get_state)
{
long frame8=ELPHEL_GLOBALPARS(G_THIS_FRAME) & PARS_FRAMES_MASK;
long compressor_state= ((struct framepars_t *) ELPHEL_G(framePars))[frame8].pars[P_COMPRESSOR_RUN];
long sensor_state= ((struct framepars_t *) ELPHEL_G(framePars))[frame8].pars[P_SENSOR_RUN];
long result=(compressor_state==COMPRESSOR_RUN_CONT)?0x8:
((compressor_state==COMPRESSOR_RUN_SINGLE)?0xa:
((sensor_state==SENSOR_RUN_CONT)?0x7:0));
RETURN_LONG(result);
}
/**
* @brief return selected (by integer index) framepars structure (struct framepars_t) as a binary string
* @param index - frame index (0..7). -1 - return func2call page instead, -2 - globalPars
* @return NULL - error, otherwise a string with (struct framepars_t)
*
*/
PHP_FUNCTION(elphel_framepars_get_raw)
{
char * packed_framepars_structure;
long index=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &index) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
packed_framepars_structure= (char*) emalloc (sizeof (struct framepars_t));
if (packed_framepars_structure) {
/// use gamma_cache_index to retrieve table from cache
if (index>=0) {
memcpy(packed_framepars_structure, &(((struct framepars_t *) ELPHEL_G(framePars))[index & PARS_FRAMES_MASK]),sizeof(struct framepars_t));
} else if (index == -1) {
memcpy(packed_framepars_structure, ((struct framepars_t *) ELPHEL_G(funcs2call)),sizeof(struct framepars_t));
} else if (index == -2) {
memcpy(packed_framepars_structure, ((struct framepars_t *) ELPHEL_G(globalPars)),sizeof(struct framepars_t));
} else RETURN_NULL ();
RETURN_STRINGL (packed_framepars_structure, sizeof(struct framepars_t), 0);
}
php_error_docref(NULL TSRMLS_CC, E_ERROR, "emalloc error");
RETURN_NULL ();
}
//! This function reads associative array and uses the keys as a template for the result array.
//! If mey is one of the defined P_VALUE names (same as global constant but w/o "ELPHEL_" prefix)
//! then the result array will have element with the same key and the value equal to the value
//! of the camera parameter
/// TODO:Make it per frame (absolute), combine with past frames
/// frame absent - "current frame"
/// frame ==0 - frame zero (static?)
PHP_FUNCTION(elphel_get_P_arr)
{
long frame=-1;
long frame_index=-1;
int future=1;
int frame_stored;
long addr,full_addr,val;
char full_constant_name[256];
zval *arr, **data;
HashTable *arr_hash;
HashPosition pointer;
char *key;
int key_len;
long index;
long constAddNumber; /// number to add to the ELPHEL_* constant value
zval const_value;
long multiMod;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|l", &arr, &frame) == FAILURE) {
RETURN_NULL();
}
// init_sens();
/// first see if this frame is either in the future, past or is frame zero (parameters that are not related to frames)
if (frame < 0) { /// frame number not provided - use latest
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME);
}
/// try future first
frame_index = frame & PARS_FRAMES_MASK;
frame_stored= ((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[P_FRAME];
if (frame_stored frame) { /// Maybe it is in the past frames (only subset of parameters preserved)
frame_index = frame & PASTPARS_SAVE_ENTRIES_MASK;
frame_stored= ((struct framepars_past_t *) ELPHEL_G(pastPars))[frame_index].past_pars[P_FRAME-PARS_SAVE_FROM];
if (frame_stored != frame) { /// Too late, probably - all the records are gone by now
future=-1 ;// not available - only global parameters could be retrieved
} else future=0; /// should be there, but in the past
}
array_init(return_value);
arr_hash = Z_ARRVAL_P(arr);
for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS;
zend_hash_move_forward_ex(arr_hash, &pointer)) {
if (zend_hash_get_current_key_ex(arr_hash, &key, &key_len, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
if (strlen(key)>(sizeof(full_constant_name)-8)) RETURN_NULL();
sprintf (full_constant_name,"ELPHEL_%s",key);
full_addr =-1;
if (zend_get_constant(full_constant_name, strlen(full_constant_name), &const_value TSRMLS_CC)) { /// found the constant as is
full_addr= Z_LVAL(const_value);
} else {
multiMod=parseMultiSens(full_constant_name); /// will truncate full_constant_name if sensor number suffix found
constAddNumber=splitConstantName(full_constant_name);
// php_printf ("constAddNumber=%d, full_constant_name=%s (length=%d)\n",constAddNumber, full_constant_name,strlen(full_constant_name));
if ((constAddNumber>=0) && (zend_get_constant(full_constant_name, strlen(full_constant_name), &const_value TSRMLS_CC))) { /// Try to remove number from the end
full_addr= (Z_LVAL(const_value) & ~FRAMEPAIR_MASK_BYTES)+constAddNumber; /// FRAMEPAIR_MASK_BYTES to prevent bit-field modifier addition to constants that already have them
if ((multiMod>=0) && (full_addr != -1)) full_addr=applyMultiSens(full_addr,multiMod);
}
}
if (full_addr!=-1) {
addr=full_addr & 0xffff;
/// is it a global parameter?
if (addr >= FRAMEPAR_GLOBALS) {
if (addr < (FRAMEPAR_GLOBALS+P_MAX_GPAR)) {
if (full_addr & FRAMEPAIR_MASK_BYTES) {
add_assoc_long(return_value, key, FRAMEPAIR_FRAME_FIELD(full_addr,ELPHEL_GLOBALPARS(addr)));
} else {
add_assoc_long(return_value, key, ELPHEL_GLOBALPARS(addr));
}
}
/// is it in the future/latest?
} else if (future>0) {
if ((addr >=0) && (addr < (sizeof (struct framepars_t) >>2))) {
if (full_addr & FRAMEPAIR_MASK_BYTES) {
add_assoc_long(return_value, key, FRAMEPAIR_FRAME_FIELD(full_addr,((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[addr]));
} else {
add_assoc_long(return_value, key, ((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[addr]);
}
}
/// is it saved in past parameters?
} else if (future==0){
addr-=PARS_SAVE_FROM;
if ((addr >=0) && (addr <(sizeof (struct framepars_past_t) >>2))) {
if (full_addr & FRAMEPAIR_MASK_BYTES) {
add_assoc_long(return_value, key, FRAMEPAIR_FRAME_FIELD(full_addr,((struct framepars_past_t *) ELPHEL_G(pastPars))[frame_index].past_pars[addr]));
} else {
add_assoc_long(return_value, key, ((struct framepars_past_t *) ELPHEL_G(pastPars))[frame_index].past_pars[addr]);
}
}
}
zval_dtor(&const_value);
}
}
}
}
/**
* @brief common part of elphel_set_P_value() and elphel_compressor_*()
* @param addr register address (with possible flags)
* @param data data to write
* @param frame frame to write (<0) - use current + FRAME_DEAFAULT_AHEAD
* @param flags additional flags (0) - none
* @return <0 - -errno ( error), otherwise frame used
*/
long elphel_set_P_value_common(long addr, long data, long frame, long flags) {
unsigned long write_data[4];
long maddr;
///shortcut for global parameters - directly mmaped
maddr=addr & 0xffff;
if (( (addr & 0xff00) != 0xff00 ) && (maddr >= FRAMEPAR_GLOBALS)) { /// these globals can be written just through mmap
if (maddr >= (FRAMEPAR_GLOBALS+P_MAX_GPAR)) {
return -1;
}
ELPHEL_GLOBALPARS(maddr)=data;
return 0;
}
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME) + FRAME_DEAFAULT_AHEAD;
}
flags |= (flags << 16); /// will accept flags both shifted and not shifted
flags &=0xffff0000;
if ((addr<0) ||((maddr >= (sizeof (struct framepars_t) >>2)) && ( (addr & 0xff00) != 0xff00 ) )) {
return -1;
}
write_data[0]=FRAMEPARS_SETFRAME;
write_data[1]=frame;
write_data[2]= addr | flags;
write_data[3]= data;
long rslt=write(ELPHEL_G(fd_fparmsall), write_data, sizeof(write_data));
// if (rslt<0) rslt =-errno;
if (rslt<0) return -errno;
if (rslt == sizeof( write_data )) return frame;
return -1;
}
//! Set acquisition/compression parameters.
/// addr may include flags - addr|=(flags>>16)
/// UPDATE: return frame number to which parameters was set
PHP_FUNCTION(elphel_set_P_value)
{
long addr;
long data;
long frame=-1;
unsigned long flags=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|ll", &addr,&data,&frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (((frame=elphel_set_P_value_common (addr, data, frame, flags))) <0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//! Reset FPGA compressor - set to the same as elphel_compressor_stop()
PHP_FUNCTION(elphel_compressor_reset)
{
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_FORCE_NEWPROC;
if (((frame=elphel_set_P_value_common (P_COMPRESSOR_RUN, COMPRESSOR_RUN_STOP, frame, flags)))<0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//! Start FPGA compressor
PHP_FUNCTION(elphel_compressor_run)
{
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_FORCE_NEWPROC;
if (((frame=elphel_set_P_value_common (P_COMPRESSOR_RUN, COMPRESSOR_RUN_CONT, frame, flags)))<0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//! Stop FPGA compressor
PHP_FUNCTION(elphel_compressor_stop)
{
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_FORCE_NEWPROC;
if (((frame=elphel_set_P_value_common (P_COMPRESSOR_RUN, COMPRESSOR_RUN_STOP, frame, flags)))<0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//! Acquire one frame to the buffer
PHP_FUNCTION(elphel_compressor_frame)
{
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_JUST_THIS;
if (((frame=elphel_set_P_value_common (P_COMPRESSOR_RUN, COMPRESSOR_RUN_SINGLE, frame, flags)))<0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//!reset sensor, and re-initialize it
PHP_FUNCTION(elphel_reset_sensor) {
lseek((int) ELPHEL_G(fd_fparmsall), LSEEK_FRAMEPARS_INIT, SEEK_END ); /// reset all framepars and globalPars
elphel_set_P_value_common (P_SENSOR, 0, 0, -1);
RETURN_NULL();
}
//! This function reads associative array and writes values to the camera registers, using "ELPHEL_* constants"
//! to determine register address from the provided key in each key/value pair
//! All non-numerical values are ignored
//! Returns number of values written
///UPDATE:retuns frame number to which parameters were written
PHP_FUNCTION(elphel_set_P_arr)
{
char full_constant_name[256];
zval *arr, **data;
HashTable *arr_hash;
HashPosition pointer;
char *key;
int key_len;
long index;
zval const_value;
int array_count;
unsigned long * write_data=NULL;
long frame=-1;
long flags=0;
int num_written=0;
int num_mmap_written=0;
int reg_addr, reg_data, constAddNumber;
long multiMod;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ll", &arr,&frame,&flags) == FAILURE) {
RETURN_LONG(num_written);
}
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME) + FRAME_DEAFAULT_AHEAD;
}
flags |= (flags << 16); /// will accept flags both shifted and not shifted
flags &=0xffff0000;
init_sens();
arr_hash = Z_ARRVAL_P(arr);
array_count = zend_hash_num_elements(arr_hash);
///allocate array to be written (8 bytes per value + 8)
write_data=(unsigned long *) emalloc ((array_count+1)<<3);
if (!write_data) RETURN_NULL(); /// emalloc failed
write_data[0]=FRAMEPARS_SETFRAME;
write_data[1]=frame;
for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer);
zend_hash_get_current_data_ex(arr_hash, (void**) &data, &pointer) == SUCCESS;
zend_hash_move_forward_ex(arr_hash, &pointer)) {
if ((zend_hash_get_current_key_ex(arr_hash, &key, &key_len, &index, 0, &pointer) == HASH_KEY_IS_STRING) &&
(Z_TYPE_PP(data) == IS_LONG)) {
reg_data=Z_LVAL_PP(data);
if (strlen(key)>(sizeof(full_constant_name)-8)) RETURN_NULL();
sprintf (full_constant_name,"ELPHEL_%s",key);
reg_addr =-1;
if (zend_get_constant(full_constant_name, strlen(full_constant_name), &const_value TSRMLS_CC)) { /// found the constant as is
reg_addr= Z_LVAL(const_value);
} else {
multiMod=parseMultiSens(full_constant_name); /// will truncate full_constant_name if sensor number suffix found
constAddNumber=splitConstantName(full_constant_name);
if ((constAddNumber>=0) && (zend_get_constant(full_constant_name, strlen(full_constant_name), &const_value TSRMLS_CC))) { /// Try to remove number from the end
reg_addr= (Z_LVAL(const_value) & ~FRAMEPAIR_MASK_BYTES)+constAddNumber; /// FRAMEPAIR_MASK_BYTES to prevent bit-field modifier addition to constants that already have them
if ((multiMod>=0) && (reg_addr != -1)) reg_addr=applyMultiSens(reg_addr,multiMod);
}
}
if (reg_addr>=0) {
/// is it a global parameter?
zval_dtor(&const_value); /// free resources used for constant value
if (((reg_addr & 0xff00) != 0xff00 ) && ((reg_addr & 0xffff) >= FRAMEPAR_GLOBALS)) { /// these globals can be written just through mmap
if ((reg_addr & 0xffff) < (FRAMEPAR_GLOBALS+P_MAX_GPAR)) { /// Fits in the range of the global parameters
if ((reg_addr & FRAMEPAIR_MASK_BYTES) ==0) { /// Full 32-bit writes - use mmap
ELPHEL_GLOBALPARS(reg_addr & 0xffff)=reg_data;
num_mmap_written++;
} else { /// only some bitfield is modified - use (slower) write to have it atomic, no need to do bit field combining here
write_data[(num_written<<1) + 2]= reg_addr | flags;
write_data[(num_written<<1) + 3]= reg_data;
num_written++;
}
}
} else if ((reg_addr>=0) && (((reg_addr & 0xffff) < (sizeof (struct framepars_t) >>2)) || ( (reg_addr & 0xff00) == 0xff00 ) )) {
write_data[(num_written<<1) + 2]= reg_addr | flags;
write_data[(num_written<<1) + 3]= reg_data;
num_written++;
}
}
}
}
if (num_written) {
long rslt=write(ELPHEL_G(fd_fparmsall), write_data, (num_written+1)<<3);
efree(write_data);
if (rslt<0) RETURN_LONG(-errno);
num_written=(rslt>>3) -1 ; ///actually written to driver
}
/// RETURN_LONG(num_mmap_written+num_written);
RETURN_LONG(frame);
}
/**
* @brief Calculate gamma table (as array of 257 unsigned short values)
* @param gamma - gamma value (1.0 - linear)
* @param black - black level, 1.0 corresponds to 256 for 8bit values
* @param gtable - gamma array reference (allocated by the caller)
* @return 0 - OK, <0 - error
*/
int gamma_calc (double gamma, double black, unsigned short * gtable) {
int i;
double x, black256,k;
int ig;
black256=black*256.0;
if (k>=1.0) k= k/256.0 ; /// just in case k is provided as a fraction of 256, not 1.0
if (k>0.99) k=0.99;
k=1.0/(256.0-black256);
if (!gtable) return -1;
///Same 0.13 <= gamma <= 10.0 limits for gamma as used earlier
if (gamma < 0.13) gamma=0.13;
if (gamma >10.0) gamma=10.0;
for (i=0; i<257; i++) {
x=k*(i-black256);
if (x < 0.0 ) x=0.0;
ig= 0.5+65535.0*pow(x,gamma);
if (ig > 0xffff) ig=0xffff;
gtable[i]=ig;
}
return 0;
}
/**
* @brief Calculate new gamma table (specified by gamma value and black level) and put it into gamma cache
* Gamma cache will be used to program gamma tables to FPGA, calculate derivative tables
* Gamma tables should be loaded before used (gamma/black level/scale) specified as frame parameters
* gamma - floating point, <=1.0, will be rounded to 0.01. Larger gammas are reseved for custom tables
* black - floating point, <=1.0 or integer>1 (1..255) - level to subtract from sensor value
* @return hash16 - ((gamma *100) & 0xff) | (((black * 256) 0xff) << 8)
*/
PHP_FUNCTION(elphel_gamma_add)
{
unsigned short data_to_write[260];
double gamma,black;
int igamma, iblack, hash16;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "dd", &gamma, &black ) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong arguments");
RETURN_NULL ();
}
igamma=100*gamma+0.5;
if (igamma < 0) igamma= 0;
if (igamma > 255) igamma=255;
gamma=0.01*igamma;
iblack= (black>=1.0)?black:(256*black+0.5);
if (iblack < 0) iblack= 0;
if (iblack > 254) iblack=254; /// don't use 255 - reserve it for custom tables
black= (1.0/256.0) * iblack;
hash16= igamma | (iblack<<8);
data_to_write[0]= GAMMA_SCLALE_1; /// 1.0
data_to_write[1]= hash16;
///- next 1 byte [4] - mode (1 - not_nice, 2 - need reverse, 4 - hardware)
///- next 1 byte [5] - color ( only if hardware bit in mode is set)
data_to_write[2]=0;
gamma_calc (gamma, black, &data_to_write[3]);
long rslt=write(ELPHEL_G(fd_gamma_cache), data_to_write, sizeof(data_to_write));
if (rslt<0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Write to fd_gamma_cache returned errno=%d",errno);
RETURN_LONG(-errno);
}
RETURN_LONG (hash16);
}
/**
* @brief Load custom gamma table, tag it with hash16 (unsigned short).
* Using lower byte of hash16 larger than 0x64 (100) or high byte of 0xff will prevent hash16 used by gamma/blacklevel pairs
* @param hash16 - hash 16 that will be used to identify the table when setting parameters
* @param zarray - array of 257 elements indexed as 0..256, in the range of 0.. 1.0 to be used for a table
* @return -1.. -998 - errno when writing to driver
* -998 - wrong arguments
* -999 - array length is not 257
* -1000..-1256 - missing element 0..256
* -2000..-2256 - non-numeric element 0..256
* >=0 - hash16
*/
PHP_FUNCTION(elphel_gamma_add_custom)
{
unsigned short data_to_write[260];
long hash16;
int i,d;
zval *arr, **data;
HashTable *arr_hash;
long array_count;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "la", &hash16, &arr ) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong arguments");
RETURN_LONG (-998);
}
arr_hash = Z_ARRVAL_P(arr);
array_count = zend_hash_num_elements(arr_hash);
if (array_count != 257) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong array length (should be 257) - %d",array_count);
RETURN_LONG (-999);
}
hash16 &= 0xffff;
data_to_write[0]= GAMMA_SCLALE_1; /// 1.0
data_to_write[1]= hash16;
///- next 1 byte [4] - mode (1 - not_nice, 2 - need reverse, 4 - hardware)
///- next 1 byte [5] - color - only if hardware bit in mode is set
data_to_write[2]=0;
/// now iterate through indexed array
for (i=0; i<257; i++) {
if (zend_hash_index_find(arr_hash, i, (void**)&data) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Missing array element [%d]",i);
RETURN_LONG(-i-1000);
}
switch (Z_TYPE_PP(data)) {
case IS_DOUBLE:
d=Z_DVAL_PP(data);
break;
case IS_LONG:
d=(1.0/255)* Z_LVAL_PP(data);
default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Non-numeric array element [%d]",i);
RETURN_LONG(-i-2000);
}
if (d<0) d=0.0;
if (d>1.0) d=1.0;
data_to_write[i+3]=d*65535.0;
}
long rslt=write(ELPHEL_G(fd_gamma_cache), data_to_write, sizeof(data_to_write));
if (rslt<0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Write to fd_gamma_cache returned errno=%d",errno);
RETURN_LONG(-errno);
}
RETURN_LONG (hash16);
}
/**
* @brief Read loaded gamma table, optionally scale it and provide "raw" (integer) array
* @param hash16 - unique ID (unsigned short ) of the table provided whan it was created. for regular gamma tables it is
* ((gamma *100) & 0xff) | (((black * 256) 0xff) << 8)
* @param scale - optional scale will be applied to the gamma table. If provided scale is integer, it should be the same format
* as P_GTAB_* lower word - unsigned short, where GAMMA_SCLALE_1 (0x400) is 1.0,
* if it is floating point or integer 1 - it is "true" scale
* @param raw - 0: return array of floating point numbers, in the range 0..1.0, !=0 - array of unsigned short numbers
* @return if OK - array of 257 numbers floating 0..1.0 or intefer 0..0xffff,
* negative integer - error
*
*/
PHP_FUNCTION(elphel_gamma_get)
{
// double scale=1.0;
unsigned short gtable[257];
unsigned short data_to_write[3];
long hash16;
long raw=0;
zval *zscale=NULL;
int iscale=GAMMA_SCLALE_1;
int gamma_cache_index;
int i;
double gk=1.0/65535.0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|zl", &hash16, &zscale,&raw) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong arguments");
RETURN_LONG (-998);
}
if (zscale) {
switch (Z_TYPE_P(zscale)) {
case IS_DOUBLE:
iscale=(GAMMA_SCLALE_1 * Z_DVAL_P(zscale) +0.5);
break;
case IS_LONG:
iscale = Z_LVAL_P(zscale);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong scale type");
}
}
if (iscale < 0) iscale=0;
if (iscale > 0xffff) iscale=0xffff;
/// look for a table in cache
data_to_write[0]= iscale; /// 0..0xffff
data_to_write[1]= hash16;
///- next 1 byte [4] - mode (1 - not_nice, 2 - need reverse, 4 - hardware)
///- next 1 byte [5] - color - only if hardware bit in mode is set
data_to_write[2]=0;
long rslt=write(ELPHEL_G(fd_gamma_cache), data_to_write, sizeof(data_to_write));
if (rslt<0) {
// php_error_docref(NULL TSRMLS_CC, E_ERROR, "Write to fd_gamma_cache returned errno=%d",errno);
RETURN_LONG(-errno); /// i/o error/ table does not exist - "silent" error?
}
gamma_cache_index= lseek(ELPHEL_G(fd_gamma_cache), 0, SEEK_CUR);
if (!gamma_cache_index) {
RETURN_LONG (-997); /// requested table does not exist in the cache - "silent" error?
}
/// use gamma_cache_index to retrieve table from cache
memcpy(gtable, &(((struct gamma_stuct_t *) ELPHEL_G(gamma_cache))[gamma_cache_index].direct[0]),sizeof(gtable));
if (lseek(ELPHEL_G(fd_gamma_cache), LSEEK_GAMMA_ISCURRENT, SEEK_END)<=0) {
RETURN_LONG (-996); /// requested table was overwritten - "silent" error?
}
/// convert gtable to PHP array
array_init(return_value);
if (raw) for (i=0;i<257;i++) add_next_index_long (return_value, gtable[i]);
else for (i=0;i<257;i++) add_next_index_double(return_value, gk*gtable[i]);
/// will return array 'return_value'
}
/**
* @brief Find loaded gamma table, optionally scale it and provide cache index (0 - not in cache)
* @param hash16 - unique ID (unsigned short ) of the table provided whan it was created. for regular gamma tables it is
* ((gamma *100) & 0xff) | (((black * 256) 0xff) << 8)
* @param scale - optional scale will be applied to the gamma table. If provided scale is integer, it should be the same format
* as P_GTAB_* lower word - unsigned short, where GAMMA_SCLALE_1 (0x400) is 1.0,
* if it is floating point or integer 1 - it is "true" scale
* @return <0 - error, 0 - not in cache, >0 - cache index
*
*/
PHP_FUNCTION(elphel_gamma_get_index)
{
unsigned short data_to_write[3];
long hash16;
zval *zscale=NULL;
int iscale=GAMMA_SCLALE_1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|z", &hash16, &zscale) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong arguments");
RETURN_LONG (-998);
}
if (zscale) {
switch (Z_TYPE_P(zscale)) {
case IS_DOUBLE:
iscale=(GAMMA_SCLALE_1 * Z_DVAL_P(zscale) +0.5);
break;
case IS_LONG:
iscale = Z_LVAL_P(zscale);
break;
default:
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong scale type");
}
}
if (iscale < 0) iscale=0;
if (iscale > 0xffff) iscale=0xffff;
/// look for a table in cache
data_to_write[0]= iscale; /// 0..0xffff
data_to_write[1]= hash16;
///- next 1 byte [4] - mode (1 - not_nice, 2 - need reverse, 4 - hardware)
///- next 1 byte [5] - color - only if hardware bit in mode is set
data_to_write[2]=0;
long rslt=write(ELPHEL_G(fd_gamma_cache), data_to_write, sizeof(data_to_write));
if (rslt<0) {
// php_error_docref(NULL TSRMLS_CC, E_ERROR, "Write to fd_gamma_cache returned errno=%d",errno);
RETURN_LONG(-errno); /// i/o error/ table does not exist - "silent" error?
}
RETURN_LONG (lseek(ELPHEL_G(fd_gamma_cache), 0, SEEK_CUR));
}
/**
* @brief return selected (by integer index) cached gamma structure (struct gamma_stuct_t) as a binary string
* @param index - gamma cache index
* @return NULL - error, otherwise a string with (struct gamma_stuct_t)
*
*/
PHP_FUNCTION(elphel_gamma_get_raw)
{
char * packed_gamma_structure;
long index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
if (index >= GAMMA_CACHE_NUMBER) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index (%d >= %d)",index, (int) GAMMA_CACHE_NUMBER);
RETURN_NULL ();
}
packed_gamma_structure= (char*) emalloc (sizeof(struct gamma_stuct_t));
if (packed_gamma_structure) {
/// use gamma_cache_index to retrieve table from cache
memcpy(packed_gamma_structure, &(((struct gamma_stuct_t *) ELPHEL_G(gamma_cache))[index]),sizeof(struct gamma_stuct_t));
if (index==0) { /// just debug
packed_gamma_structure[sizeof(struct gamma_stuct_t)-1]=0xff;
}
RETURN_STRINGL (packed_gamma_structure, sizeof(struct gamma_stuct_t), 0);
}
php_error_docref(NULL TSRMLS_CC, E_ERROR, "emalloc error");
RETURN_NULL ();
}
// memcpy(packed_framepars_structure, &(((struct framepars_t *) ELPHEL_G(framePars))[index]),sizeof(struct framepars_t));
///TODO: elphel_gamma_get_reverse - just testing? or is raw enough? yes, only _raw
///TODO: elphel_gamma_get_fpga - no, not needed, could use binary string if really wanted
/**
* @brief return selected (by integer index) cached histogram structure (struct histogram_stuct_t) as a binary string
* @param index - histogram cache index (or frame number, 3 lsb will be used)
* @return NULL - error, otherwise a string with (struct histogram_stuct_t)
*
*/
PHP_FUNCTION(elphel_histogram_get_raw)
{
char * packed_histogram_structure;
long frame=-1;
long needed=0xfff;
long index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &needed,&frame) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
if (frame<0) frame=lseek((int) ELPHEL_G( fd_fparmsall), 0, SEEK_CUR );
needed &= 0xfff;
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_WAIT_C, SEEK_END); /// wait for all histograms, not just Y (G1)
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_NEEDED + (needed & 0xff0), SEEK_END); /// mask out needed raw (fpga) bits
index=lseek(ELPHEL_G(fd_histogram_cache), frame, SEEK_SET); /// request histograms for frame=frame, wait until available if needed
if (index <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Requested histograms are not available (frame=%d, needed=0x%x)",frame,needed);
RETURN_NULL ();
}
if (index >= HISTOGRAM_CACHE_NUMBER) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: frame=%d, index=%d",frame, index);
RETURN_NULL ();
}
// index &= (HISTOGRAM_CACHE_NUMBER -1);
packed_histogram_structure= (char*) emalloc (sizeof(struct histogram_stuct_t));
if (!packed_histogram_structure) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "emalloc error");
RETURN_NULL ();
}
/// use gamma_cache_index to retrieve table from cache
memcpy(packed_histogram_structure, &(((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[index]),sizeof(struct histogram_stuct_t));
RETURN_STRINGL (packed_histogram_structure, sizeof(struct histogram_stuct_t), 0);
}
/**
* @brief return histograms for selected frame (absolute frame number) as a plain integer array
* some derivative histograms may be calculated if they do not exist yet
* (raw FPGA data should be read from IRQ/tasklet - no attemt to re-read FPGA here)
* @param frame - absolute frame number
* @param needed - bitmask specifying what tables to include in the output array, each group is in the order r(0),g(1),gb(2),b(3)
* - bits 0..3 - raw histograms from the FPGA (only if they are already in the cache)
* - bits 4..7 - cumulative histograms (sum of raw ones) - normally called from applications
* - bits 8..11 - calculate percentiles (reverse cumulative histograms) - normally called from applications
* @return NULL - error, otherwise a string with (struct histogram_stuct_t)
*
*/
PHP_FUNCTION(elphel_histogram_get)
{
struct histogram_stuct_t * frame_histogram_structure;
long frame=-1;
long needed=0xfff;
long index;
int i;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ll", &needed, &frame) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
needed &= 0xfff;
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_WAIT_C, SEEK_END); /// wait for all histograms, not just Y (G1)
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_NEEDED + (needed & 0xff0), SEEK_END); /// mask out needed raw (fpga) bits
index=lseek(ELPHEL_G(fd_histogram_cache), frame, SEEK_SET); /// request histograms for frame=frame, wait until available if needed
if (index <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Requested histograms are not available (frame=%d, needed=0x%x)",frame,needed);
RETURN_NULL ();
}
if (index >= HISTOGRAM_CACHE_NUMBER) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Internal error: frame=%d, index=%d",frame, index);
RETURN_NULL ();
}
frame_histogram_structure= (struct histogram_stuct_t *) emalloc (sizeof(struct histogram_stuct_t));
if (!frame_histogram_structure) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "emalloc error");
RETURN_NULL ();
}
/// use gamma_cache_index to retrieve table from cache
memcpy((void *) frame_histogram_structure, &(((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[index]),sizeof(struct histogram_stuct_t));
/// verify that histogram is still valid
if (frame != ((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[index].frame ) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Frame changed while retrieving histograms (frame requested=%d, current=%d)",
frame, (int)((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[index].frame);
RETURN_NULL ();
efree (frame_histogram_structure);
}
/// verify that selected tables are valid
if ((needed & frame_histogram_structure->valid ) != needed) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Not all the requested tables are available (frame=%d needed=0x%x, valid=0x%x)",
frame, needed, frame_histogram_structure->valid);
RETURN_NULL ();
efree (frame_histogram_structure);
}
/// TODO: make array with subarrays for each individual table/color?
array_init(return_value);
if (needed & 0x001) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->hist_r[i]);
if (needed & 0x002) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->hist_g[i]);
if (needed & 0x004) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->hist_gb[i]);
if (needed & 0x008) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->hist_b[i]);
if (needed & 0x010) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->cumul_hist_r[i]);
if (needed & 0x020) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->cumul_hist_g[i]);
if (needed & 0x040) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->cumul_hist_gb[i]);
if (needed & 0x080) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->cumul_hist_b[i]);
if (needed & 0x100) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->percentile_r[i]);
if (needed & 0x200) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->percentile_g[i]);
if (needed & 0x400) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->percentile_gb[i]);
if (needed & 0x800) for (i=0;i<256;i++) add_next_index_long (return_value, frame_histogram_structure->percentile_b[i]);
efree (frame_histogram_structure);
/// will return array 'return_value'
}
///=================================
long createExifDirectory (int rebuild) { /// build directory of pointers in the Exif data for some of the (variable) fields used in the Elphel cameras
int indx;
long numfields=0;
struct exif_dir_table_t dir_table_entry;
/// Read the size of the Exif data
int exif_this_size=lseek((int) ELPHEL_G(fd_exifdir),1,SEEK_END); // at the beginning of page 1 - position == page length
if ((ELPHEL_G(exif_size) == exif_this_size) && !rebuild) return 0; // no need to rebuild
ELPHEL_G(exif_size) = exif_this_size;
for (indx=0; indx0) {
switch (dir_table_entry.ltag) {
case Exif_Image_ImageDescription: indx= Exif_Image_ImageDescription_Index; break;
case Exif_Image_FrameNumber: indx= Exif_Image_FrameNumber_Index; break;
case Exif_Photo_DateTimeOriginal: indx= Exif_Photo_DateTimeOriginal_Index; break;
case Exif_Photo_SubSecTimeOriginal: indx= Exif_Photo_SubSecTimeOriginal_Index; break;
case Exif_Photo_ExposureTime: indx= Exif_Photo_ExposureTime_Index; break;
case Exif_Photo_MakerNote: indx= Exif_Photo_MakerNote_Index; break;
case Exif_Image_Orientation: indx= Exif_Image_Orientation_Index; break;
case Exif_GPSInfo_GPSLatitudeRef: indx= Exif_GPSInfo_GPSLatitudeRef_Index; break;
case Exif_GPSInfo_GPSLatitude: indx= Exif_GPSInfo_GPSLatitude_Index ; break;
case Exif_GPSInfo_GPSLongitudeRef: indx= Exif_GPSInfo_GPSLongitudeRef_Index ; break;
case Exif_GPSInfo_GPSLongitude: indx= Exif_GPSInfo_GPSLongitude_Index; break;
case Exif_GPSInfo_GPSAltitudeRef: indx= Exif_GPSInfo_GPSAltitudeRef_Index; break;
case Exif_GPSInfo_GPSAltitude: indx= Exif_GPSInfo_GPSAltitude_Index; break;
case Exif_GPSInfo_GPSTimeStamp: indx= Exif_GPSInfo_GPSTimeStamp_Index; break;
case Exif_GPSInfo_GPSDateStamp: indx= Exif_GPSInfo_GPSDateStamp_Index; break;
case Exif_GPSInfo_GPSMeasureMode: indx= Exif_GPSInfo_GPSMeasureMode_Index; break;
case Exif_GPSInfo_CompassDirectionRef: indx= Exif_GPSInfo_CompassDirectionRef_Index; break;
case Exif_GPSInfo_CompassDirection: indx= Exif_GPSInfo_CompassDirection_Index; break;
case Exif_GPSInfo_CompassPitchRef: indx= Exif_GPSInfo_CompassPitchRef_Index; break;
case Exif_GPSInfo_CompassPitch: indx= Exif_GPSInfo_CompassPitch_Index; break;
case Exif_GPSInfo_CompassRollRef: indx= Exif_GPSInfo_CompassRollRef_Index; break;
case Exif_GPSInfo_CompassRoll: indx= Exif_GPSInfo_CompassRoll_Index; break;
default: indx=-1;
}
if (indx>=0) {
memcpy(&(ELPHEL_G(exif_dir)[indx]),&dir_table_entry,sizeof(dir_table_entry));
numfields++;
}
}
return numfields;
}
///TODO: make reverse order, specify how many frames wanted. So first will be most reliable
PHP_FUNCTION(elphel_get_circbuf_pointers) {
char * ccam_dma_buf_char= (char *) ELPHEL_G( ccam_dma_buf);
long second=0;
long p,frameParamPointer;
long buff_size=lseek(ELPHEL_G( fd_circ),0,SEEK_END); //size of circbuf
long meta_index,displacementInPage,exifPageStart,frame_be;
zval *image_pointers;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &second) == FAILURE) {
RETURN_NULL();
}
///Frame number is in Exif structure
createExifDirectory(0); /// make sure directory is current
if (ELPHEL_G(exif_dir)[Exif_Image_FrameNumber_Index].ltag==Exif_Image_FrameNumber) /// Exif_Image_FrameNumber_Index is present in template
displacementInPage=ELPHEL_G(exif_dir)[Exif_Image_FrameNumber_Index].dst;
else
displacementInPage=-1; /// no frame number in Exif
p=lseek((int) ELPHEL_G( fd_circ), second? LSEEK_CIRC_SCND: LSEEK_CIRC_FIRST, SEEK_END );
if (p<0) RETURN_NULL();
array_init(return_value);
while (p>=0) {
frameParamPointer=p-32;
if (frameParamPointer<0) frameParamPointer+=buff_size;
ALLOC_INIT_ZVAL(image_pointers);
array_init(image_pointers);
add_assoc_long(image_pointers, "circbuf_pointer", p);
// add_assoc_long(image_pointers, "exif_pointer", ((struct interframe_params_t *) &ccam_dma_buf_char[frameParamPointer])->meta_index);
meta_index=((struct interframe_params_t *) &ccam_dma_buf_char[frameParamPointer])->meta_index;
add_assoc_long(image_pointers, "exif_pointer", meta_index);
/// Find out frame number...
if (displacementInPage>=0){
exifPageStart=lseek ((int) ELPHEL_G(fd_exif), meta_index, SEEK_END); /// select specified Exif page
lseek (ELPHEL_G(fd_exif), exifPageStart+displacementInPage, SEEK_SET);
read(ELPHEL_G(fd_exif), &frame_be, 4);
///... and add it to the output array
add_assoc_long(image_pointers, "frame", (long) __cpu_to_be32(frame_be));
}
add_next_index_zval(return_value, image_pointers);
/// next frame
p=lseek((int) ELPHEL_G( fd_circ), LSEEK_CIRC_NEXT, SEEK_END );
p=lseek((int) ELPHEL_G( fd_circ), LSEEK_CIRC_READY, SEEK_END );
}
}
PHP_FUNCTION(elphel_get_interframe_meta)
{
char * ccam_dma_buf_char= (char *) ELPHEL_G( ccam_dma_buf);
struct interframe_params_t frame_params;
long circbuf_pointer=-1;
long frameParamPointer,jpeg_len,timestamp_start;
// long circbuf_size=ELPHEL_GLOBALPARS(G_CIRCBUFSIZE);
long circbuf_size=ELPHEL_G(ccam_dma_buf_len);
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &circbuf_pointer) == FAILURE) {
RETURN_NULL();
}
frameParamPointer=circbuf_pointer-32;
if (frameParamPointer < 0) frameParamPointer+=circbuf_size;
memcpy (&frame_params, &ccam_dma_buf_char[frameParamPointer],32);
jpeg_len=frame_params.frame_length;
///Copy timestamp (goes after the image data)
timestamp_start=circbuf_pointer+((jpeg_len+CCAM_MMAP_META+3) & (~0x1f)) + 32 - CCAM_MMAP_META_SEC; //! magic shift - should index first byte of the time stamp
if (timestamp_start >= circbuf_size) timestamp_start-=circbuf_size;
memcpy (&(frame_params.timestamp_sec), &ccam_dma_buf_char[timestamp_start],8);
if (frame_params.signffff !=0xffff) {
RETURN_NULL();
}
array_init(return_value);
/// This data will survive as long as the frame itself in the circular buffer. Some other fields (like exposure) are stored in Exif
add_assoc_long(return_value, "hash32_r", frame_params.hash32_r); /// red color black level (MSB,gamma- bits 16..24, scale - bits 0..15)
add_assoc_long(return_value, "hash32_g", frame_params.hash32_g);
add_assoc_long(return_value, "hash32_gb", frame_params.hash32_gb);
add_assoc_long(return_value, "hash32_b", frame_params.hash32_b);
/// Quality is represented by 2-byte value. Each byte uses Y table if the value is Q<128,// 16-17
/// and C table with (Q-128) if it is Q>=128.
/// If the High byte is zero, it is treated as Q^0x80 (Q|=(Q^0x80)<<8) for compatibility
/// with a standard single-byte Q value
add_assoc_long(return_value, "quality2", frame_params.quality2);
add_assoc_long(return_value, "color", frame_params.color); /// color mode //18
add_assoc_long(return_value, "byrshift", frame_params.byrshift); /// bayer shift in compressor //19
add_assoc_long(return_value, "width", frame_params.width); /// frame width, pixels 20-21 - NOTE: should be 20-21
add_assoc_long(return_value, "height", frame_params.height); /// frame height, pixels 22-23
add_assoc_long(return_value, "meta_index", frame_params.meta_index); /// Exif page number (>0)
add_assoc_long(return_value, "timestamp_sec", frame_params.timestamp_sec); /// number of seconds since 1970 to the start of the frame exposure
add_assoc_long(return_value, "timestamp_usec",frame_params.timestamp_usec); /// number of microseconds to add to seconds
}
#define saferead255(f,d,l) read(f,d,((l)<256)?(l):255)
PHP_FUNCTION(elphel_get_exif_elphel)
{
long makerNote[16];
long rational3[6];
long exif_page_start;
char *key;
long indx;
char val[256];
long exif_page=0;
int hours=0, minutes=0;
double seconds=0.0;
double longitude=0.0, latitude=0.0, altitude=0.0, heading=0.0, roll=0.0, pitch=0.0, exposure=0.0;
val[255]='\0';
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &exif_page) == FAILURE) {
RETURN_NULL();
}
createExifDirectory(0); /// make sure directory is current
if (exif_page) exif_page_start=lseek ((int) ELPHEL_G(fd_exif), exif_page, SEEK_END); /// select specified Exif page
else exif_page_start=lseek ((int) ELPHEL_G(fd_exif), 0, SEEK_SET); /// Select 0 (currently being acquired) Exif page
if (exif_page_start<0) RETURN_NULL(); //exif_page may be out of range
array_init(return_value);
///Image Description
if (ELPHEL_G(exif_dir)[Exif_Image_ImageDescription_Index].ltag==Exif_Image_ImageDescription) { // Exif_Image_ImageDescription is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Image_ImageDescription_Index].dst,
SEEK_SET);
saferead255(ELPHEL_G(fd_exif), val, ELPHEL_G(exif_dir)[Exif_Image_ImageDescription_Index].len);
add_assoc_string(return_value, "ImageDescription", val, 1);
}
///Exif_Image_FrameNumber_Index 0x13
if (ELPHEL_G(exif_dir)[Exif_Image_FrameNumber_Index].ltag==Exif_Image_FrameNumber) { // Exif_Image_FrameNumber_Index is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Image_FrameNumber_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 4);
sprintf (val,"%ld", (long) __cpu_to_be32( rational3[0]));
add_assoc_string(return_value, "FrameNumber", val, 1);
}
///Exif_Image_Orientation_Index 0x15
if (ELPHEL_G(exif_dir)[Exif_Image_Orientation_Index].ltag==Exif_Image_Orientation) { // Exif_Image_Orientation_Index is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Image_Orientation_Index].dst,
SEEK_SET);
rational3[0]=0;
read(ELPHEL_G(fd_exif), rational3, 2);
sprintf (val,"%ld", (long) ( rational3[0]>>8));
add_assoc_string(return_value, "Orientation", val, 1);
}
///DateTimeOriginal (with subseconds)
if (ELPHEL_G(exif_dir)[Exif_Photo_DateTimeOriginal_Index].ltag==Exif_Photo_DateTimeOriginal) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Photo_DateTimeOriginal_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 19);
val[19]='\0';
if (ELPHEL_G(exif_dir)[Exif_Photo_SubSecTimeOriginal_Index].ltag==Exif_Photo_SubSecTimeOriginal) {
val[19]='.';
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Photo_SubSecTimeOriginal_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), &val[20], 7);
val[27]='\0';
}
add_assoc_string(return_value, "DateTimeOriginal", val, 1);
}
///Exif_Photo_ExposureTime
if (ELPHEL_G(exif_dir)[Exif_Photo_ExposureTime_Index].ltag==Exif_Photo_ExposureTime) { // Exif_Photo_ExposureTime is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Photo_ExposureTime_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 8);
exposure=(1.0*__cpu_to_be32( rational3[0]))/__cpu_to_be32( rational3[1]);
sprintf (val,"%f",exposure);
add_assoc_string(return_value, "ExposureTime", val, 1);
}
///Exif_Photo_MakerNote
if (ELPHEL_G(exif_dir)[Exif_Photo_MakerNote_Index].ltag==Exif_Photo_MakerNote) { // Exif_Photo_MakerNote is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Photo_MakerNote_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), makerNote, 64);
sprintf (val,"0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx,0x%08lx",
(long) __cpu_to_be32(makerNote[0]),
(long) __cpu_to_be32(makerNote[1]),
(long) __cpu_to_be32(makerNote[2]),
(long) __cpu_to_be32(makerNote[3]),
(long) __cpu_to_be32(makerNote[4]),
(long) __cpu_to_be32(makerNote[5]),
(long) __cpu_to_be32(makerNote[6]),
(long) __cpu_to_be32(makerNote[7]),
(long) __cpu_to_be32(makerNote[8]),
(long) __cpu_to_be32(makerNote[9]),
(long) __cpu_to_be32(makerNote[10]),
(long) __cpu_to_be32(makerNote[11]),
(long) __cpu_to_be32(makerNote[12]),
(long) __cpu_to_be32(makerNote[13]),
(long) __cpu_to_be32(makerNote[14]),
(long) __cpu_to_be32(makerNote[15]));
add_assoc_string(return_value, "MakerNote", val, 1);
}
/// GPS measure mode
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSMeasureMode_Index].ltag==Exif_GPSInfo_GPSMeasureMode) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSMeasureMode_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 1);
val[1]='\0';
add_assoc_stringl(return_value, "GPSMeasureMode", val, 1, 1);
}
///GPS date/time
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSDateStamp_Index].ltag==Exif_GPSInfo_GPSDateStamp) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSDateStamp_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 10);
val[10]='\0';
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSTimeStamp_Index].ltag==Exif_GPSInfo_GPSTimeStamp) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSTimeStamp_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 24);
hours= __cpu_to_be32( rational3[0]);
minutes= __cpu_to_be32( rational3[2]);
seconds= (1.0*(__cpu_to_be32( rational3[4])+1))/__cpu_to_be32( rational3[5]); /// GPS likes ".999", let's inc by one - anyway will round that out
sprintf (&val[10]," %02d:%02d:%05.2f",hours,minutes,seconds);
}
add_assoc_string(return_value, "GPSDateTime", val, 1);
}
/// knowing format provided from GPS - degrees and minutes only, no seconds:
///GPS Longitude
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLongitude_Index].ltag==Exif_GPSInfo_GPSLongitude) { // Exif_GPSInfo_GPSLongitude is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLongitude_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 24);
longitude=__cpu_to_be32( rational3[0])/(1.0*__cpu_to_be32( rational3[1])) + __cpu_to_be32( rational3[2])/(60.0*__cpu_to_be32( rational3[3]));
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLongitudeRef_Index].ltag==Exif_GPSInfo_GPSLongitudeRef) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLongitudeRef_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 1);
if (val[0]!= 'E') longitude=-longitude;
}
sprintf (val,"%f",longitude);
add_assoc_string(return_value, "GPSLongitude", val, 1);
}
///GPS Latitude
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLatitude_Index].ltag==Exif_GPSInfo_GPSLatitude) { // Exif_GPSInfo_GPSLatitude is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLatitude_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 24);
latitude=__cpu_to_be32( rational3[0])/(1.0*__cpu_to_be32( rational3[1])) + __cpu_to_be32( rational3[2])/(60.0*__cpu_to_be32( rational3[3]));
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLatitudeRef_Index].ltag==Exif_GPSInfo_GPSLatitudeRef) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSLatitudeRef_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 1);
if (val[0] != 'N') latitude=-latitude;
}
sprintf (val,"%f",latitude);
add_assoc_string(return_value, "GPSLatitude", val, 1);
}
///GPS Altitude
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSAltitude_Index].ltag==Exif_GPSInfo_GPSAltitude) { // Exif_GPSInfo_GPSAltitude is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSAltitude_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 8);
altitude=(1.0*__cpu_to_be32( rational3[0]))/__cpu_to_be32( rational3[1]);
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSAltitudeRef_Index].ltag==Exif_GPSInfo_GPSAltitudeRef) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_GPSAltitudeRef_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 1);
if (val[0] != '\0') altitude=-altitude;
}
sprintf (val,"%f",altitude);
add_assoc_string(return_value, "GPSAltitude", val, 1);
}
///Compass Direction (magnetic)
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassDirection_Index].ltag==Exif_GPSInfo_CompassDirection) { // Exif_GPSInfo_CompassDirection is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassDirection_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 8);
heading=(1.0*__cpu_to_be32( rational3[0]))/__cpu_to_be32( rational3[1]);
sprintf (val,"%f",heading);
add_assoc_string(return_value, "CompassDirection", val, 1);
}
///Processing 'hacked' pitch and roll (made of Exif destination latitude/longitude)
///Compass Roll
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassRoll_Index].ltag==Exif_GPSInfo_CompassRoll) { // Exif_GPSInfo_CompassRoll is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassRoll_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 8);
roll=(1.0*__cpu_to_be32( rational3[0]))/__cpu_to_be32( rational3[1]);
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassRollRef_Index].ltag==Exif_GPSInfo_CompassRollRef) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassRollRef_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 1);
if (val[0] != EXIF_COMPASS_ROLL_ASCII[0]) roll=-roll;
}
sprintf (val,"%f",roll);
add_assoc_string(return_value, "CompassRoll", val, 1);
}
///Compass Pitch
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassPitch_Index].ltag==Exif_GPSInfo_CompassPitch) { // Exif_GPSInfo_CompassPitch is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassPitch_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), rational3, 8);
pitch=(1.0*__cpu_to_be32( rational3[0]))/__cpu_to_be32( rational3[1]);
if (ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassPitchRef_Index].ltag==Exif_GPSInfo_CompassPitchRef) {
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_GPSInfo_CompassPitchRef_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif), val, 1);
if (val[0] != EXIF_COMPASS_PITCH_ASCII[0]) pitch=-pitch;
}
sprintf (val,"%f",pitch);
add_assoc_string(return_value, "CompassPitch", val, 1);
}
}
PHP_FUNCTION(elphel_update_exif) {
RETURN_LONG(createExifDirectory(1)); // force rebuild
}
PHP_FUNCTION(elphel_get_exif_field)
{
long exif_page=0;
long ltag;
struct exif_dir_table_t dir_table_entry;
char * rslt;
int found=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", <ag, &exif_page) == FAILURE) {
RETURN_NULL();
}
// find the ltag in the directory (may need to scan all the directory)
lseek ((int) ELPHEL_G(fd_exifdir), 0, SEEK_SET);
while (read((int) ELPHEL_G(fd_exifdir), &dir_table_entry, sizeof(dir_table_entry))>0) {
if (dir_table_entry.ltag==ltag) {
found=1;
break;
}
}
if (!found) RETURN_NULL();
// lseek (fd_exifdir, 0, SEEK_SET);
if (exif_page) found= lseek ((int) ELPHEL_G(fd_exif), exif_page, SEEK_END); /// select specified Exif page
else found= lseek ((int) ELPHEL_G(fd_exif), 0, SEEK_SET); /// Select 0 (currently being acquired) Exif page
if (found<0) RETURN_NULL(); //exif_page may be out of range
lseek ((int) ELPHEL_G(fd_exif), dir_table_entry.dst, SEEK_CUR);
rslt=emalloc(dir_table_entry.len);
read((int) ELPHEL_G(fd_exif), rslt, dir_table_entry.len);
RETURN_STRINGL(rslt,dir_table_entry.len,0);
}
PHP_FUNCTION(elphel_set_exif_field)
{
long ltag;
struct exif_dir_table_t dir_table_entry;
char * value;
int value_length;
int found=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", <ag, &value,&value_length) == FAILURE) {
RETURN_NULL();
}
// find the ltag in the directory (may need to scan all the directory)
lseek ((int) ELPHEL_G(fd_exifdir), 0, SEEK_SET);
while (read((int) ELPHEL_G(fd_exifdir), &dir_table_entry, sizeof(dir_table_entry))>0) {
if (dir_table_entry.ltag==ltag) {
found=1;
break;
}
}
if (!found) RETURN_NULL();
lseek ((int) ELPHEL_G(fd_exifmeta), dir_table_entry.src, SEEK_SET);
if (value_length>dir_table_entry.len) value_length = dir_table_entry.len;
///NOTE:DEBUG
// php_printf ("value=%s, value_length=%d\n",value, value_length);
long rslt=write(ELPHEL_G(fd_exifmeta), value, value_length);
if (rslt<0) rslt =-errno;
RETURN_LONG(rslt);
}
//! wait for the next frame to be compressed (and related parameters updated
PHP_FUNCTION(elphel_wait_frame)
{
lseek((int) ELPHEL_G( fd_circ), LSEEK_CIRC_TOWP, SEEK_END );
lseek((int) ELPHEL_G( fd_circ), LSEEK_CIRC_WAIT, SEEK_END );
RETURN_NULL();
}
/**
* @brief Use current (for the specified frame) gamma table to convert input data (fraction <1.0) into output value (used by histograms)
* @param color - needed color (0..3)
* @param sensorLevel - level (0.0 <=level<1.0) proportional to the senosor output, normalized to 0.0..1.0 scale
* @param frame (optional) absolute frame number for which gamma table is needed. NOTE: Will not wait if it is in the future - just return -1
* if frame is not specified - will use the previous to current frame - same as the one for which histogram is availble (or will be very soon)
* @return -1 if too late (or other errors), otherwise a fraction of the full output level (0.0..1.0)
*/
PHP_FUNCTION(elphel_gamma)
{
long color;
long frame =-1;
double sensorLevel;
int indx,gamma_index;
unsigned long hash32; /// combined black, gamma, scale
unsigned long write_data[2];
int rslt;
unsigned short * gamma_direct;
long lsensorLevel;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ld|l", &color, &sensorLevel, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME)-1;
}
// php_printf ("frame=0x%lx, color=0x%lx\n",frame, color);
hash32=get_imageParamsThat (P_GTAB_R+color, frame);
// php_printf ("hash32=0x%lx\n",hash32);
if (hash32 == 0xffffffff) RETURN_LONG (-1);
/// now request gamma table for that hash32, including reverse
write_data[0]=hash32;
write_data[1]=0; /// GAMMA_MODE_NEED_REVERSE;
rslt=write(ELPHEL_G(fd_gamma_cache), write_data, 6);
// php_printf ("frame=0x%lx, write_data[0]=0x%lx, write_data[1]=0x%lx,rslt=0x%x\n",frame, write_data[0], write_data[1],rslt);
if (rslt<= 0) {
RETURN_LONG (-1);
}
gamma_index=lseek(ELPHEL_G(fd_gamma_cache), 0, SEEK_CUR);
// php_printf ("gamma_index=0x%x\n",gamma_index);
if (gamma_index <= 0) {
RETURN_LONG (-2); /// gamma table may be lost in cache - need reload/recalculation through elphel_gamma_add()
}
gamma_direct= &(((struct gamma_stuct_t *) ELPHEL_G(gamma_cache))[gamma_index].direct[0]);/// [257] "Gamma" table, 16-bit for both non-scaled prototypes
/// and scaled, 0..0xffff range (hardware will use less)
lsensorLevel=0x10000*sensorLevel;
// php_printf ("lsensorLevel=0x%lx\n",lsensorLevel);
if (lsensorLevel <0) RETURN_LONG (-1);
if (lsensorLevel >0xffff) lsensorLevel=0xffff;
// php_printf ("(long) gamma_direct[%lx]=0x%lx\n",lsensorLevel>>8, (long) gamma_direct[lsensorLevel>>8]);
// php_printf ("(long) gamma_direct[%lx]=0x%lx\n",(lsensorLevel>>8)+1, (long) gamma_direct[(lsensorLevel>>8)+1]);
RETURN_DOUBLE ((1.0/(1<<24))* ((((long) gamma_direct[lsensorLevel>>8])<<8) +
(((long) gamma_direct[(lsensorLevel>>8)+1] - ((long) gamma_direct[lsensorLevel>>8]))*(lsensorLevel & 0xff))));
}
/**
* @brief Use current (for the specified frame) gamma table to back-translate gamma converter output data (fraction <1.0) into the input (sensor) data
* @param color - needed color (0..3)
* @param gammaLevel - level (0.0 <=level<1.0) proportional to the senosor output, normalized to 0.0..1.0 scale
* @param frame (optional) absolute frame number for which gamma table is needed. NOTE: Will not wait if it is in the future - just return -1
* if frame is not specified - will use the previous to current frame - same as the one for which histogram is availble (or will be very soon)
* @return -1 if too late (or other errors), otherwise a fraction of the full output level (0.0..1.0)
*/
PHP_FUNCTION(elphel_reverse_gamma)
{
long color;
long frame=-1;
double gammaLevel;
int indx,gamma_index;
unsigned long hash32; /// combined black, gamma, scale
unsigned long write_data[2];
int rslt;
unsigned short * gamma_direct;
unsigned char * gamma_reverse;
long lgammaLevel, sensor_high8,delta, sensor_full;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ld|l", &color, &gammaLevel, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME)-1;
}
hash32=get_imageParamsThat (P_GTAB_R+color, frame);
if (hash32 == 0xffffffff) RETURN_LONG (-1);
/// now request gamma table for that hash32, including reverse
write_data[0]=hash32;
write_data[1]= GAMMA_MODE_NEED_REVERSE;
rslt=write(ELPHEL_G(fd_gamma_cache), write_data, 6);
if (rslt<= 0) {
RETURN_LONG (-1);
}
gamma_index=lseek(ELPHEL_G(fd_gamma_cache), 0, SEEK_CUR);
if (gamma_index <= 0) {
RETURN_LONG (-2); /// gamma table may be lost in cache - need reload/recalculation through elphel_gamma_add()
}
gamma_direct= &(((struct gamma_stuct_t *) ELPHEL_G(gamma_cache))[gamma_index].direct[0]); /// [257] "Gamma" table, 16-bit for both non-scaled prototypes
/// and scaled, 0..0xffff range (hardware will use less)
gamma_reverse=&(((struct gamma_stuct_t *) ELPHEL_G(gamma_cache))[gamma_index].reverse[0]);/// [256] reverse table to speed-up reversing (still need
/// interpolation).Index - most significant 8 bits, data - largest direct
lgammaLevel=0x10000*gammaLevel;
if (lgammaLevel <0) RETURN_LONG (-1);
if (lgammaLevel >0xffff) lgammaLevel=0xffff;
sensor_high8=gamma_reverse[lgammaLevel >> 8]; /// 8 MSBs used as index
if (sensor_high8>0) sensor_high8--; /// seems gamma_reverse[] rounds up, not down
while ((sensor_high8>0) && (gamma_direct[sensor_high8] > lgammaLevel)) sensor_high8--; /// adjust down (is that needed at all?)
sensor_high8++;
while ((sensor_high8<255) && (gamma_direct[sensor_high8] <= lgammaLevel)) sensor_high8++; /// adjust up (is that needed at all?)
sensor_high8--;
delta=gamma_direct[sensor_high8+1] - gamma_direct[sensor_high8];
if (delta) {
sensor_full=((lgammaLevel-gamma_direct[sensor_high8]) << 8)/delta;
} else sensor_full=0;
sensor_full += sensor_high8 << 8;
/// limit just in case?
if (sensor_full < 0) sensor_full=0;
else if (sensor_full > 0xffff) sensor_full=0xffff;
RETURN_DOUBLE ((1.0/(1<<16))* sensor_full);
}
/**
* @brief common function to get index of the histogram cache for the specified color. May wait for the frame to become available
* @param color 0..3 - requested color (0 -R, 1 - G (used as Y ), 2 - GB (second green), 3 - blue
* @param frame absolute frame number (histogrames are available for the previous (to current) frame
* @param needreverse 0 if only cumulative histogram is needed, >0 if the reverse is also needed
* @return <0 if histogram can not be found fo the specified frame (i.e. too late), otherwise it is an index in histogram cache.
*/
int get_histogram_index (long color,long frame, long needreverse) { /// histogram is availble for previous frame, not for the current one
long hist_index;
if ((color<0) || (color>4)) return -1; /// wrong color
if (color == COLOR_Y_NUMBER) lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_WAIT_Y, SEEK_END); /// wait for just Y (G1)
else lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_WAIT_C, SEEK_END); /// wait for all histograms, not just Y (G1)
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_NEEDED + ((1 << color) << (needreverse? 8:4)), SEEK_END); /// specify what color is needed and if reverse is needed
return lseek(ELPHEL_G(fd_histogram_cache), frame, SEEK_SET); /// request histogram for the specified frame
}
/**
* @brief return value of parameter 'index' from frame 'frame' - use pastPars if too late for framePars
* @param indx parameter indx
* @param frame absolute frame number
* @return parameter value (error will be 0xffffffff, but that could be a legitimate value too)
*/
unsigned long get_imageParamsThat (int indx, unsigned long frame) {
int frame_index= frame & PARS_FRAMES_MASK;
int past_index= frame & PASTPARS_SAVE_ENTRIES_MASK;
unsigned long value;
/// Locate frame info in framePars
if (((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[P_FRAME] != frame) {
/// too late, try pastPars
if ((indx < PARS_SAVE_FROM) || (indx >= (PARS_SAVE_FROM+PARS_SAVE_NUM))) return 0xffffffff ; /// not saved
value=((struct framepars_past_t *) ELPHEL_G(pastPars))[past_index].past_pars[indx-PARS_SAVE_FROM]; /// should be retrieved before checking frame (interrupts)
if (((struct framepars_past_t *) ELPHEL_G(pastPars))[frame_index].past_pars[P_FRAME-PARS_SAVE_FROM] != frame) { /// too late even for pastPars? Or a bug?
return 0xffffffff;
}
} else {
value=((struct framepars_t *) ELPHEL_G(framePars))[frame_index].pars[indx];
}
return value;
}
/**
* @brief Get cumulative histogram (fraction of all pixels below specified level)
* @param color - needed color (0..3)
* @param level - level (0.0 <=level<1.0) to compare pixel values to (-1 will return -1, error)
* @param frame (optional) absolute frame number for which histogram is needed. NOTE: If specified in the future - will wait
* if frame is not specified - will use lates histogram (previous to current frame)
* @return -1 if too late (or other errors), otherwise a fraction of pixels (0..1.0) that are below the specified level
*/
PHP_FUNCTION(elphel_histogram)
{
long frame=-1;
long hist_index;
double dlevel;
long llevel,total_pixels;
unsigned long * hist_cumul; /// 256 of cumulated histogram values (in pixels)
long hist,color;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ld|l", &color, &dlevel, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME)-1;
}
if (((hist_index=get_histogram_index (color, frame, 0)))<0) RETURN_LONG (-1);
llevel=0x10000*dlevel;
if (llevel< -0.5) RETURN_LONG(-1) ; /// if input level was ==-1 - error, don't try
if (llevel<0) llevel=0;
else if (llevel>0xffff) llevel=0xffff;
///interpolate
hist_cumul= &(((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[hist_index].cumul_hist[color<<8]);
total_pixels= hist_cumul[255];
hist= (llevel>>8)?hist_cumul[(llevel>>8)-1]:0;
hist +=((hist_cumul[llevel>>8]-hist)*(llevel & 0xff))>>8;
RETURN_DOUBLE(((double) hist)/total_pixels);
}
/**
* @brief Get percentile (reverse cumulative histogram) - level (as a fraction 0..1.0) so that specified fraction of all pixels
* are below it
* @param color - needed color (0..3)
* @param fraction - fraction (0.0 <=fraction<1.0) of all pixels to have value under the output (-1 will return -1, error)
* @param frame (optional) absolute frame number for which histogram is needed. NOTE: If specified in the future - will wait
* if frame is not specified - will use latest histogram (previous to current frame)
* @return -1 if too late (or other errors), otherwise a level (in the 0.0<1.0 range) so that a specified fraction of all pixels are below it
*/
PHP_FUNCTION(elphel_reverse_histogram)
{
long frame=-1;
long hist_index;
double fraction;
long frac_pixels,total_pixels, frac_256, delta;
unsigned long * hist_cumul; /// 256 of cumulated histogram values (in pixels)
unsigned char * hist_percentile; /// 256 of rounded percentiles (1 byte) - used as a starting point for linear interpolation
long perc,perc_frac,color;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ld|l", &color, &fraction, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if (frame <0) {
frame=ELPHEL_GLOBALPARS(G_THIS_FRAME)-1;
}
if (((hist_index=get_histogram_index (color, frame, 1)))<0) RETURN_LONG (-1);
///interpolate
hist_cumul= &(((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[hist_index].cumul_hist[color<<8]);
hist_percentile=&(((struct histogram_stuct_t *) ELPHEL_G(histogram_cache))[hist_index].percentile[color<<8]);
total_pixels= hist_cumul[255];
frac_pixels=total_pixels*fraction;
if (fraction < -0.5) RETURN_LONG(-1) ; /// if input level was ==-1 - error, don't try
if (frac_pixels<0) frac_pixels=0;
else if (frac_pixels>=total_pixels) frac_pixels=total_pixels-1;
frac_256=(1.0/256)*fraction; ///floor()
if (frac_256 > 255) frac_256=255;
perc=hist_percentile[frac_256];
if (perc>0) perc--; /// seems hist_percentile[perc] rounds up, not down
while ((perc>0) && (hist_cumul[perc] > frac_pixels)) perc--; /// adjust down (is that needed at all?)
perc++;
while ((perc<255) && (hist_cumul[perc] <= frac_pixels)) perc++; /// adjust up (is that needed at all?)
perc--;
delta=hist_cumul[perc+1] - hist_cumul[perc];
if (delta) {
perc_frac=((frac_pixels-hist_cumul[perc]) << 8)/delta;
} else perc_frac=0;
perc_frac += perc << 8;
RETURN_DOUBLE((1.0/(1<<16)) * ((double) perc_frac));
}
//! Low-level, direct FPGA read/write
PHP_FUNCTION(elphel_fpga_read)
{
long addr,data,res;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &addr) == FAILURE) {
RETURN_NULL();
}
int fd=open("/dev/fpgaio", O_RDONLY);
if (fd<0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s","/dev/fpgaio");
return ;
}
lseek (fd, addr,SEEK_SET) ; //! 32-bit registers, not bytes
res=read(fd,&data,4);
close (fd);
if (res<4) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not read file %s","/dev/fpgaio");
return ;
}
RETURN_LONG(data);
}
PHP_FUNCTION(elphel_fpga_write)
{
long addr,data,res;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &addr,&data) == FAILURE) {
RETURN_NULL();
}
int fd=open("/dev/fpgaio", O_RDWR);
if (fd<0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s","/dev/fpgaio");
return ;
}
lseek (fd, addr,SEEK_SET) ; //! 32-bit registers, not bytes
res=write(fd,&data,4);
close (fd);
if (res<4) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not write to file %s","/dev/fpgaio");
return ;
}
RETURN_NULL();
}
//! set FPGA clock. Input parameter - (double) seconds (i.e. from 01/01/1970)
//! This clock is used to timestamp each image
//! returns same time rounded to microseconds (as written to FPGA)
PHP_FUNCTION(elphel_set_fpga_time) {
unsigned long write_data[8]= {FRAMEPARS_SETFRAME, 0,
G_SECONDS, 0,
G_MICROSECONDS, 0,
FRAMEPARS_SETFPGATIME, 0};
double dtime;
long ltime_sec,ltime_usec;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "d", &dtime) == FAILURE) {
RETURN_NULL();
}
ltime_sec=dtime;
ltime_usec=(dtime-ltime_sec)*1000000;
write_data[3]=ltime_sec;
write_data[5]=ltime_usec;
long rslt=write(ELPHEL_G(fd_fparmsall), write_data, sizeof(write_data));
if (rslt<0) RETURN_LONG(-errno);
dtime=ltime_usec;
dtime=ltime_sec+0.000001*dtime;
RETURN_DOUBLE(dtime);
}
//! Get current FPGA time as (double) seconds
PHP_FUNCTION(elphel_get_fpga_time) {
double dtime;
long ltime_sec,ltime_usec;
lseek((int) ELPHEL_G( fd_fparmsall), LSEEK_GET_FPGA_TIME, SEEK_END );
dtime= ELPHEL_GLOBALPARS(G_MICROSECONDS);
dtime= ELPHEL_GLOBALPARS(G_SECONDS) + 0.000001*dtime;
RETURN_DOUBLE(dtime);
}
static struct framepars_all_t test_structure;
static void php_elphel_init_globals(zend_elphel_globals *elphel_globals)
{
test_structure.globalPars[G_THIS_FRAME] = 999;
test_structure.framePars[0].pars[P_EXPOS] = 111;
test_structure.framePars[1].pars[P_EXPOS] = 222;
test_structure.framePars[2].pars[P_EXPOS] = 333;
test_structure.framePars[3].pars[P_EXPOS] = 444;
test_structure.framePars[4].pars[P_EXPOS] = 555;
test_structure.framePars[5].pars[P_EXPOS] = 666;
test_structure.framePars[6].pars[P_EXPOS] = 777;
test_structure.framePars[7].pars[P_EXPOS] = 888;
//ELPHEL_GLOBALPARS(G_THIS_FRAME)
elphel_globals->frameParsAll = NULL;
elphel_globals->framePars = NULL;
elphel_globals->pastPars = NULL;
elphel_globals->funcs2call= NULL;
elphel_globals->frameParsAll = &test_structure;
elphel_globals->framePars = elphel_globals->frameParsAll->framePars;
elphel_globals->pastPars = elphel_globals->frameParsAll->pastPars;
elphel_globals->funcs2call= elphel_globals->frameParsAll->func2call.pars;
elphel_globals->globalPars = elphel_globals->frameParsAll->globalPars;
elphel_globals->multiSensIndex = elphel_globals->frameParsAll->multiSensIndex;
elphel_globals->multiSensRvrsIndex = elphel_globals->frameParsAll->multiSensRvrsIndex; /// not yet used
}
static void php_elphel_init_globals_bkp(zend_elphel_globals *elphel_globals)
{
//! open "/dev/sensorpars" and mmap array - only once
elphel_globals->frameParsAll = NULL;
elphel_globals->framePars = NULL;
elphel_globals->pastPars = NULL;
elphel_globals->funcs2call= NULL;
elphel_globals->fd_fparmsall= open("/dev/frameparsall", O_RDWR);
if (elphel_globals->fd_fparmsall <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s","/dev/frameparsall");
return ;
}
//! now try to mmap (PROT_WRITE only for writing dependencies - func2call?
elphel_globals->frameParsAll = (struct framepars_all_t *) mmap(0, sizeof (struct framepars_all_t) , PROT_READ | PROT_WRITE, MAP_SHARED, elphel_globals->fd_fparmsall, 0);
if((int)elphel_globals->frameParsAll == -1) {
elphel_globals->frameParsAll=NULL;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in mmap /dev/frameparsall");
close (elphel_globals->fd_fparmsall);
elphel_globals->fd_fparmsall = -1;
return ;
}
/// Shortcuts to the two sub-structures
elphel_globals->framePars = elphel_globals->frameParsAll->framePars;
elphel_globals->pastPars = elphel_globals->frameParsAll->pastPars;
elphel_globals->funcs2call= elphel_globals->frameParsAll->func2call.pars;
elphel_globals->globalPars = elphel_globals->frameParsAll->globalPars;
elphel_globals->multiSensIndex = elphel_globals->frameParsAll->multiSensIndex;
elphel_globals->multiSensRvrsIndex = elphel_globals->frameParsAll->multiSensRvrsIndex; /// not yet used
/// (gamma_tables.c) access to gammas
elphel_globals->gamma_cache = NULL;
elphel_globals->fd_gamma_cache= open("/dev/gamma_cache", O_RDWR);
if (elphel_globals->fd_gamma_cache <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s","/dev/gamma_cache");
return ;
}
//! now try to mmap
elphel_globals->gamma_cache = (struct gamma_stuct_t *) mmap(0, sizeof (struct gamma_stuct_t) * GAMMA_CACHE_NUMBER , PROT_READ, MAP_SHARED, elphel_globals->fd_gamma_cache, 0);
if((int)elphel_globals->gamma_cache == -1) {
elphel_globals->gamma_cache=NULL;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in mmap /dev/gamma_cache");
close (elphel_globals->fd_gamma_cache);
elphel_globals->fd_gamma_cache = -1;
return ;
}
///debug
/// (histogram.c) access to gammas
elphel_globals->histogram_cache = NULL;
elphel_globals->fd_histogram_cache= open("/dev/histogram_cache", O_RDWR);
if (elphel_globals->fd_histogram_cache <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s","/dev/histogram_cache");
return ;
}
//! now try to mmap
elphel_globals->histogram_cache = (struct histogram_stuct_t *) mmap(0, sizeof (struct histogram_stuct_t) * HISTOGRAM_CACHE_NUMBER , PROT_READ, MAP_SHARED, elphel_globals->fd_histogram_cache, 0);
if((int)elphel_globals->histogram_cache == -1) {
elphel_globals->histogram_cache=NULL;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in mmap /dev/histogram_cache");
close (elphel_globals->fd_histogram_cache);
elphel_globals->fd_histogram_cache = -1;
return ;
}
//! Now - same for /dev/circbuf
elphel_globals->ccam_dma_buf = NULL;
elphel_globals->fd_circ= open("/dev/circbuf", O_RDWR);
if (elphel_globals->fd_circ <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s","/dev/circbuf");
return ;
}
elphel_globals->ccam_dma_buf_len=lseek(elphel_globals->fd_circ,0,SEEK_END); //size of circbuf
//! now try to mmap
elphel_globals->ccam_dma_buf = (unsigned long *) mmap(0, elphel_globals->ccam_dma_buf_len , PROT_READ | PROT_WRITE, MAP_SHARED, elphel_globals->fd_circ, 0);
if((int)elphel_globals->ccam_dma_buf == -1) {
elphel_globals->ccam_dma_buf=NULL;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in mmap /dev/circbuf");
close (elphel_globals->fd_circ);
elphel_globals->fd_circ = -1;
return ;
}
elphel_globals->fd_exif = open(EXIF_DEV_NAME, O_RDONLY);
if (elphel_globals->fd_exif <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",EXIF_DEV_NAME);
return ;
}
elphel_globals->fd_exifdir = open(EXIFDIR_DEV_NAME, O_RDONLY);
if (elphel_globals->fd_exifdir <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",EXIFDIR_DEV_NAME);
return ;
}
elphel_globals->fd_exifmeta = open(EXIFMETA_DEV_NAME, O_RDWR);
if (elphel_globals->fd_exifmeta <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",EXIFMETA_DEV_NAME);
return ;
}
elphel_globals->exif_size=0;
}
PHP_RINIT_FUNCTION(elphel)
{
// session initialization may be here
return SUCCESS;
}
/// use gcc -save-temps to debug those macros for constants
PHP_MINIT_FUNCTION(elphel)
{
ZEND_INIT_MODULE_GLOBALS(elphel, php_elphel_init_globals, NULL);
DEFINE_P_NAMES(pname_arr);
DEFINE_ONCHANGE_NAMES(onchange_arr);
DEFINE_LSEEK_NAMES(lseek_arr);
DEFINE_CONST_NAMES(const_arr);
int i,j;
char full_constant_name[256];
//! here initialize "ELPHEL_*" constants
REGISTER_INI_ENTRIES(); // not used yet
for (i=0;i< (sizeof(pname_arr)/sizeof(pname_arr[0])); i++) {
if (strlen(pname_arr[i].name)>(sizeof(full_constant_name)-8)) return FAILURE;
sprintf (full_constant_name,"ELPHEL_%s",pname_arr[i].name);
zend_register_long_constant(full_constant_name, strlen(full_constant_name)+1, pname_arr[i].value, (CONST_CS | CONST_PERSISTENT), module_number TSRMLS_CC);
}
for (i=0;i< (sizeof(onchange_arr)/sizeof(onchange_arr[0])); i++) {
if (strlen(onchange_arr[i].name)>(sizeof(full_constant_name)-17)) return FAILURE;
sprintf (full_constant_name,"ELPHEL_ONCHANGE_%s",onchange_arr[i].name);
for (j=0; j(sizeof(full_constant_name)-14)) return FAILURE;
sprintf (full_constant_name,"ELPHEL_LSEEK_%s",lseek_arr[i].name);
zend_register_long_constant(full_constant_name, strlen(full_constant_name)+1, lseek_arr[i].value, (CONST_CS | CONST_PERSISTENT), module_number TSRMLS_CC);
}
for (i=0;i< (sizeof(const_arr)/sizeof(const_arr[0])); i++) {
if (strlen(const_arr[i].name)>(sizeof(full_constant_name)-14)) return FAILURE;
sprintf (full_constant_name,"ELPHEL_CONST_%s",const_arr[i].name);
zend_register_long_constant(full_constant_name, strlen(full_constant_name)+1, const_arr[i].value, (CONST_CS | CONST_PERSISTENT), module_number TSRMLS_CC);
}
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(elphel)
{
UNREGISTER_INI_ENTRIES();
if (ELPHEL_G(fd_fparmsall)>=0) close (ELPHEL_G(fd_fparmsall));
if (ELPHEL_G(fd_gamma_cache)>=0) close (ELPHEL_G(fd_gamma_cache));
if (ELPHEL_G(fd_histogram_cache)>=0) close (ELPHEL_G(fd_histogram_cache));
if (ELPHEL_G(fd_circ)>=0) close (ELPHEL_G(fd_circ));
if (ELPHEL_G(fd_exif)>=0) close (ELPHEL_G(fd_exif));
if (ELPHEL_G(fd_exifdir)>=0) close (ELPHEL_G(fd_exifdir));
if (ELPHEL_G(fd_exifmeta)>=0) close (ELPHEL_G(fd_exifmeta));
return SUCCESS;
}
PHP_MINFO_FUNCTION(elphel)
{
php_info_print_table_start();
php_info_print_table_row(2, "Elphel support", "Enabled");
php_info_print_table_row(2, "Elphel API Version", PHP_ELPHEL_VERSION);
php_info_print_table_end();
}
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/elphel_php.h 0000664 0000000 0000000 00000011205 12753434647 0031076 0 ustar 00root root 0000000 0000000 #ifndef PHP_ELPHEL_H
#define PHP_ELPHEL_H 1
#ifdef ZTS
#include "TSRM.h"
#warning Using TSRM.h
#else
#warning Not using TSRM.h
#endif
#include
#include
#include
#include
ZEND_BEGIN_MODULE_GLOBALS(elphel)
int fd_exif;
int fd_exifdir;
int fd_exifmeta;
int exif_size; // to see if verify exif directory has changed
struct exif_dir_table_t exif_dir[ExifKmlNumber] ; //! store locations of the fields needed for KML generations in the Exif block
/// (circbuf.c) access to /dev/circbuf (mmap, lseek)
int fd_circ;
unsigned long * ccam_dma_buf;
unsigned long ccam_dma_buf_len; // in bytes
//struct framepars_t *framePars;
/// (framepars.c) access to /dev/frameparsall (write, lseek, mmap)
int fd_fparmsall;
struct framepars_all_t *frameParsAll;
struct framepars_t *framePars;
struct framepars_past_t *pastPars;
unsigned long *funcs2call; /// each parameter has a 32-bit mask of what pgm_function to call - other fields not used
unsigned long *globalPars; /// parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both
unsigned long *multiSensIndex; /// indexes of individual sensor register shadows (first of 3)
unsigned long *multiSensRvrsIndex; /// reverse index (to parent) for the multiSensIndex
/// (gamma_tables.c) access to gammas
//static struct gamma_stuct_t gammas[GAMMA_CACHE_NUMBER] __attribute__ ((aligned (PAGE_SIZE)));
// struct gamma_stuct_t * gammas_p; /// to use with mmap
int fd_gamma_cache;
struct gamma_stuct_t * gamma_cache; /// array of gamma structures
//static struct histogram_stuct_t histograms[HISTOGRAM_CACHE_NUMBER] __attribute__ ((aligned (PAGE_SIZE)));
int fd_histogram_cache;
struct histogram_stuct_t * histogram_cache; /// array of histogram
ZEND_END_MODULE_GLOBALS(elphel)
//!currently ZTS is not defined
#ifdef ZTS
#define ELPHEL_G(v) TSRMG(elphel_globals_id, zend_elphel_globals *, v)
#else
#define ELPHEL_G(v) (elphel_globals.v)
#endif
#define PHP_ELPHEL_VERSION "1.0"
#define PHP_ELPHEL_EXTNAME "elphel"
#define ELPHEL_GLOBALPARS(x) (((unsigned long *) ELPHEL_G(globalPars))[x-FRAMEPAR_GLOBALS])
PHP_FUNCTION(elphel_get_frame); /// current absolute frame number (includes those that are not compressed)
PHP_FUNCTION(elphel_skip_frames); /// skip some frames (includes those that are not compressed) - will work even if no frames are compressed
PHP_FUNCTION(elphel_wait_frame_abs); /// wait for absolute frame number (includes those that are not compressed)
PHP_FUNCTION(elphel_framepars_get_raw);
PHP_FUNCTION(elphel_parse_P_name);
PHP_FUNCTION(elphel_is_global_par);
PHP_FUNCTION(elphel_is_frame_par);
PHP_FUNCTION(elphel_get_P_value);
PHP_FUNCTION(elphel_set_P_value);
PHP_FUNCTION(elphel_test);
PHP_FUNCTION(elphel_get_P_arr);
PHP_FUNCTION(elphel_set_P_arr);
PHP_FUNCTION(elphel_gamma_add);
PHP_FUNCTION(elphel_gamma_add_custom);
PHP_FUNCTION(elphel_gamma_get);
PHP_FUNCTION(elphel_gamma_get_index);
PHP_FUNCTION(elphel_gamma_get_raw);
PHP_FUNCTION(elphel_histogram_get_raw);
PHP_FUNCTION(elphel_histogram_get);
PHP_FUNCTION(elphel_get_state); /// compatibility with old code
PHP_FUNCTION(elphel_compressor_reset); /// these elphel_compressor_*() functions are for compatibility. Reset will now just stop, not actually reset
PHP_FUNCTION(elphel_compressor_run);
PHP_FUNCTION(elphel_compressor_stop);
PHP_FUNCTION(elphel_compressor_frame);
PHP_FUNCTION(elphel_reset_sensor);
PHP_FUNCTION(elphel_set_fpga_time);
PHP_FUNCTION(elphel_get_fpga_time);
PHP_FUNCTION(elphel_wait_frame); /// wait for compressed frame in a circular frame buffer - will wait forever if comressor is off
PHP_FUNCTION(elphel_fpga_read);
PHP_FUNCTION(elphel_fpga_write);
PHP_FUNCTION(elphel_gamma);
PHP_FUNCTION(elphel_reverse_gamma);
PHP_FUNCTION(elphel_histogram);
PHP_FUNCTION(elphel_reverse_histogram);
PHP_FUNCTION(elphel_get_exif_field);
PHP_FUNCTION(elphel_set_exif_field);
PHP_FUNCTION(elphel_get_interframe_meta);
PHP_FUNCTION(elphel_get_exif_elphel);
PHP_FUNCTION(elphel_get_circbuf_pointers);
PHP_FUNCTION(elphel_update_exif); // force to rebuild directory after Exif format was changed Usually done automatically
PHP_MINIT_FUNCTION(elphel);
PHP_MSHUTDOWN_FUNCTION(elphel);
PHP_RINIT_FUNCTION(elphel);
PHP_MINFO_FUNCTION(elphel);
extern zend_module_entry elphel_module_entry;
#define phpext_elphel_ptr &elphel_module_entry
//static void init_sens();
int splitConstantName(char * name);
int get_histogram_index (long color,long frame, long needreverse); /// histogram is availble for previous frame, not for the current one
unsigned long get_imageParamsThat (int indx, unsigned long frame);
#endif
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/include/ 0000775 0000000 0000000 00000000000 12753434647 0030231 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/include/autoexp.h 0000664 0000000 0000000 00000003720 12753434647 0032071 0 ustar 00root root 0000000 0000000 #ifndef __H_AUTOEXP__
#define __H_AUTOEXP__
#define AUTOEXP_DEV_NAME "/dev/autoexp"
#define TABLES_LEN 8192
#define OFFSET_HIST_C (4096 + 256 * 6 * 2)
#define OFFSET_GAMMA_C (OFFSET_HIST_C + 4)
#define IOC_AUTOEXP_SET 0x01
#define IOC_AUTOEXP_GET 0x02
#define IOC_AUTOEXP_GET_LOG 0x03
#define IOC_AUTOEXP_GAMMA_TABLE 0x10
#ifndef HIST_NOT_CHANGE
#define HIST_NOT_CHANGE 0xFFFF
#endif
//!Moved to c313a.h
#if 0
struct autoexp_t {
unsigned long on;
/*
* in percents: 1 == 1, 100 == 100
*/
unsigned long width;
unsigned long height;
unsigned long left;
unsigned long top;
/*
* start exposure time really not needed...
*/
unsigned long exp_max; /* 100 usec == 1 etc... */
unsigned long overexp_max; /* percentages for overexposured pixels - 1% == 100, 5% == 500, 0.02% == 2 etc... */
/*
* changed chema - balance exposition for set percent of pixels in needed index
*/
unsigned long s_percent;
unsigned long s_index;
/*
* return current state
*/
unsigned long exp;
/*
* "sleep" settings
*/
unsigned long skip_pmin; /* percent of delta for skip changes: 1% == 100 */
unsigned long skip_pmax; /* percent of changes for wait one frame before apply changes: 1% == 100 */
unsigned long skip_t; /* time for skip changes: 100 usec == 1 */
};
#endif
#define LOG_C 200
//#define LOG_C 11
struct autoexp_log_t {
unsigned long tv_sec; /* time of log (fill in driver) */
unsigned long tv_usec;
unsigned long s_index; /* requested in settings index */
unsigned long s_percent; /* requested percent for s_index */
unsigned long n_index; /* searched new index with needed percent - if 0 - index not searched, and use linear scale */
unsigned long n_percent; /* percent in searched index */
unsigned long t_scale; /* scale of exposition - in FFFF.FFFF fixed point format */
unsigned long t_value; /* new time, requested for sensor - w/o real correction, in 0.1ms scale (1ms == 10 etc...) */
}; /* 8 * 4 == 32 bytes in record... */
#endif // __H_AUTOEXP__
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/include/c313a.h 0000664 0000000 0000000 00000332060 12753434647 0031220 0 ustar 00root root 0000000 0000000 /*
* 05.03.2002 changing for revA
* 03.19.2002 Started support for different sensors
*/
#ifndef _ASM_CMOSCAM_H
#define _ASM_CMOSCAM_H
#define SAFE_CHECK 1 // perform more verification on the paremeters
//#define ELPHEL_DEBUG 0 //global debug on/off in multiple files
//#define ELPHEL_DEBUG_STARTUP 000a4c00 ;
//#define ELPHEL_DEBUG_STARTUP 0 ; // removed - add write to fpga init script
//#define ELPHEL_DEBUG 0 //global debug on/off in multiple files
#define ELPHEL_DEBUG 1 //global debug on/off in multiple files
#define ELPHEL_DEBUG_DELAY 100000 //delay after some printk-s
#define ELP_KERR(x) printk("%s:%d:%s: ERROR ",__FILE__,__LINE__,__FUNCTION__);x
#define ELP_FERR(x) fprintf(stderr,"%s:%d:%s: ERROR ",__FILE__,__LINE__,__FUNCTION__);x
#define USELONGLONG 1
#define ETRAXFS_MMAP_CACHE_BUG y
#if ELPHEL_DEBUG
#define EDBG(x) x
#else
#define EDBG(x)
#endif
// _IOC_TYPE, bits 8 to 15 in ioctl cmd
#define CMOSCAM_IOCTYPE 124
/* new i2c devices */
// minors (add more later - maybe different minors for different speed - set speed when opening)
#define X3X3_I2C_CTRL 0 // control/reset i2c
#define X3X3_I2C_8_AINC 1 // 8bit registers, autoincement while read/write
#define X3X3_I2C_16_AINC 2 // 16bit registers, autoincement while read/write
#define X3X3_I2C1_8_AINC 3 // 8bit registers, autoincement while read/write (bus 1)
#define X3X3_I2C1_16_AINC 4 // 16bit registers, autoincement while read/write (bus 1)
#define X3X3_I2C_RAW 5 // 8bit registers, no address byte (just slave, then read/write byte(s)
#define X3X3_I2C1_RAW 6 // 8bit registers, no address byte (just slave, then read/write byte(s)
#define X3X3_I2C_ENABLE 7 // enable(/protect) different I2C devices for different types of I2C accesses
#define X3X3_I2C_ENABLE_RD 0 // bit 0 - enable i2c read
#define X3X3_I2C_ENABLE_WR 1 // bit 1 - enable i2c write
#define X3X3_I2C_ENABLE_RAW 2 // bit 2 - enable i2c raw (no address byte)
#define X3X3_I2C_ENABLE_8 3 // bit 3 - enable i2c 8-bit registers access
#define X3X3_I2C_ENABLE_16 4 // bit 4 - enable i2c 16-bit registers access
#define X3X3_I2C_MAXMINOR 7 //
#define X3X3_I2C_CHANNELS 2 // number of i2c channels
//xi2craw c 134 5
//xi2craw_aux c 134 6
//xi2cenable c 134 7
#define FPGA_DCM_STEP 22 // ps/step
#define FPGA_DCM_RANGE 250 // maximal phase correction (+/-) ?
/* camera sequencer states */
///Obsolete
#define CAMSEQ_OFF 0 // off, not programmed (Video mode off on Zoran sensors)
#define CAMSEQ_READY 1 // sensor programmed may acquire at will (programSensor sets number of frames to skip (if any)
#define CAMSEQ_SKIP 2 // skipping specified number of frames, interrupt service routine counts and will start acquisition
#define CAMSEQ_WAIT_F 3 // set by "start exposure" or interrupt service routine. WAIT_F/WAIT_T/acquire/done differs by hardware register
#define CAMSEQ_WAIT_T 4 // set by "start exposure" or interrupt service routine. Wait/acquire/done differs by hardware register
#define CAMSEQ_ACQUIRE 5 // acquisition in progress (camSeqState is still CAMSEQ_WAIT)
#define CAMSEQ_DONE 6 // acquisition over (camSeqState is still CAMSEQ_WAIT)
#define CAMSEQ_JPEG 7 // waiting for JPEG done interrupt, acquiring/compressing some frames
#define CAMSEQ_RUN 8 // compressor is constantly running (but if camSeqCount>0 - just skipping "bad" frames)
#define CAMSEQ_STOP 9 // compressor is constantly running but will stop after next "compressor ready"
#define CAMSEQ_SINGLE 10 // compressor is constantly running to fill one full buffer
// For KAI11000 sensor board
#define sensorcom_W_size 1024
#define sensorcom_R_size 256
/* MCP definitions */
#define MCP_W_size 1024
#define MCP_R_size 256
#define MCPOtherBits 0xffa7a7ff
#define MCPOffReset 0x00101800
#define MCPReset 0x00001800
#define MCPNoReset 0x00105800
#define MCPToggleA 0x00080000
#define MCPToggleB 0x00001000
#define MCPctlseq 0x00
#define MCPsofttg 0x02
#define MCPeackn 0x03
#define MCPctlgate 0x04
#define MCPwstdly 0x06
#define MCPwrsmsk 0x07
#define MCPwrsup 0x08
#define MCPwrmons 0x09
#define MCPwnom 0x0a
#define MCPwdenom 0x0b
#define MCPwoutw 0x0c
#define MCPwinvctl 0x0d
#define MCPctlsync 0x0e
#define MCPwrdlys 0x10
#define MCPwinv 0x40
#define MCPwshared 0x80
#define MCPwrsynctb 0x100
#define MCPwrseq 0x200
/* supported ioctl _IOC_NR's */
#ifndef I2C_WRITEARG
#define I2C_WRITEARG(bus, slave, reg, value) (((bus) << 24) | ((slave) << 16) | ((reg) << 8) | (value))
#define I2C_READARG(bus, slave, reg) (((bus) << 24) | ((slave) << 16) | ((reg) << 8))
#define I2C_ARGBUS(arg) (((arg) >> 24) & 0x1)
#define I2C_ARGSLAVE(arg) (((arg) >> 16) & 0xff)
#define I2C_ARGREG(arg) (((arg) >> 8) & 0xff)
#define I2C_ARGVALUE(arg) ((arg) & 0xff)
#define I2C_DELAYS 0x0 // read/write bit deleys for I2C
// return delays, if data==0 - don't change, just read
// lower (0) byte - SCL high,
// byte 1 - SCL low
// byte 2 - slave -> master (from slave driving SDA line to master driving SDA)
// byte 3 - master -> slave (from master driving SDA line to slave driving SDA)
#define I2C_WRITEREG 0x1 // write to an i2c register
#define I2C_READREG 0x2 // read from an i2c register
#endif
// new for Micron sensors - 16bit data, always bus 0
#ifndef I2C_16_WRITEARG
#define I2C_16_WRITEREG 0x3 // write 2 bytes to an i2c register
#define I2C_16_READREG 0x4 // read 2 bytes from an i2c register
#define I2C_16_WRITEARG(slave, reg, value) (((slave) << 24) | ((reg) << 16) | (value))
#define I2C_16_READARG(slave, reg) (((slave) << 24) | ((reg) << 16))
#define I2C_16_ARGSLAVE(arg) (((arg) >> 24) & 0xff)
#define I2C_16_ARGREG(arg) (((arg) >> 16) & 0xff)
#define I2C_16_ARGVALUE(arg) ( (arg) & 0xffff)
#define I2C_16_ARGVALUE_H(arg) (((arg) >> 8) & 0xff)
#define I2C_16_ARGVALUE_L(arg) ( (arg) & 0xff)
#endif
// otherParamsRO[16]
#define _CCCMD(x,y) (_IO(CMOSCAM_IOCTYPE, (x << 6) | (y & 0x3f)))
#define CCAM_CTRL(x) ((_IOC_NR(x) >> 6) & 0x03)
#define CCAM_ADDR(x) (_IOC_NR(x) & 0x3f)
//#define CCAM_RWSENSOR 1 /* direct read/write first 32 sensor registers */ // will not use at all
#define CCAM_RPARS 2 /* read parameters 0..0x3f */
#define CCAM_WPARS 3 /* write parameters 0..0x3f */
/* New parameters and update logic
* Separate read and write set of 64 registers
* User may specify:
* 0 - do not update
* 1 - update at once
* 2 - update when appropriate
* and read update status:
* 0 - will not be updated
* 1 - in sync
* 2 - waiting to be updated
* 3 - update in progress (TODO: - support async)
* When updating (validating) parameters and copying them to the read "registers" the I2C registers will be written
* only if they are different from the shadows
*/
/// parameter indexes will be updated to grouprelated ones into the same groups of 32
/// NOTE: P_* and G_* should not end with numbers - numbers will be used in PHP constants to add to the constant value (ELPHEL_AAA3 will be treated as ELPHEL_AAA+3)
#define P_NUMBER 1024 //number of registers (was 64) - NOTE: obsolete?
#define P_SENSOR 1 /* if set to 0 - will (re)detect sensor. If set to None - won't bother
4 - ZR32112MLC - now there is no way to see color/mono
5 - ZR32112PLC
8 - ZR32212MLC
9 - ZR32112PLC
32 - KAC1310-mono
33 - KAC1310-RGB
34 - KAC1310-CMY
36 - KAC5000
48 - MI1300
49 - MT9M001 (1280x1024,same as MI1300)
50 - MT9M001 (1600x1200)
51 - MT9T001 (2048*1536)
52 - MT9P001 (2592*1944)
64 - IBIS5-1300*/
// leave it here - may be used in user applications
#define SENSOR_MASK 0xfc
#define SENSOR_ZR32112 0x04
#define SENSOR_ZR32212 0x08
#define SENSOR_KAC1310 0x20
#define SENSOR_KAC5000 0x24
#define SENSOR_MI1300 0x30
#define SENSOR_MT9X001 0x30 // MT9M001 - 31, MT9D001 - 32, MT9T001 - 33, MT9P001 - 34
#define SENSOR_MT9Y001 0x34 // MT9P001 - 34
#define SENSOR_IBIS51300 0x40
#define SENSOR_KAI11000 0x80
#define SENSOR_NONE 0xfc
// sensor sizes:
//#define SENSORWIDTH_ZR32112 1288
//#define SENSORHEIGHT_ZR32112 1032
#define SENSORWIDTH_ZR32112 1280
#define SENSORHEIGHT_ZR32112 1024
//#define SENSORWIDTH_ZR32212 1288
#define SENSORWIDTH_ZR32212 1280
#define SENSORHEIGHT_ZR32212 968
#define SENSORWIDTH_KAC1310 1280
#define SENSORHEIGHT_KAC1310 1024
//#define SENSORWIDTH_KAC1310 1296
//#define SENSORHEIGHT_KAC1310 1046
#define SENSORWIDTH_MI1300 1280
#define SENSORHEIGHT_MI1300 1024
#define SENSORWIDTH_MT9M001 1280
#define SENSORHEIGHT_MT9M001 1024
#define SENSORWIDTH_MT9D001 1600
#define SENSORHEIGHT_MT9D001 1200
#define SENSORWIDTH_MT9T001 2048
#define SENSORHEIGHT_MT9T001 1536
#define SENSORWIDTH_MT9P001 2592
#define SENSORHEIGHT_MT9P001 1944
#define SENSORWIDTH_KAC5000 2592
#define SENSORHEIGHT_KAC5000 1944
#define SENSORWIDTH_IBIS51300 1280
#define SENSORHEIGHT_IBIS51300 1024
/// Parameters related to multi-sensor (10359A) setup
#define MAX_SENSORS 3 // maximal number of sensor attached (modify some hard-wired constants below if this to be changed)
//! Parameters below are accessed through mmap, because of cache coherency problem it make sense to keep them compact (maybe group by 8 - cache line of 32 bytes)
#define P_SENSOR_RUN 4 // 0 - stop, 1 - single, 2 - run
#define SENSOR_RUN_STOP 0
#define SENSOR_RUN_SINGLE 1
#define SENSOR_RUN_CONT 2
#define P_COMPRESSOR_RUN 5 // 0 - stop, 1 - single, 2 - run
#define COMPRESSOR_RUN_STOP 0
#define COMPRESSOR_RUN_SINGLE 1
#define COMPRESSOR_RUN_CONT 2
#define P_BAYER 6 // filter number at (0,0) 0-R, 1-G(R), 2-G(B), 3 - B. Write enabled at first, move to WindowSize later
#define P_TRIGGERED 7 // when trigger occured - 4 LSBs - pixel in DMA word, higher bits - number of DMA word OBSOLETE
#define P_PERIOD 8 // Frame period in pixel clocks (read only)
#define P_FP1000SLIM 9 // FPS limit, frames per 1000 sec
#define P_FPSFLAGS 10 // FPS limit mode - bit 0 - limit fps (not higher than), bit 1 - maintain fps (not lower than)
#define P_JPEG_WP 11 // Last reported JPEG write pointer in the circular buffer. ** OBSOLETE
//! In new code use G_CIRCBUFWP instead!
#define P_CLK_FPGA 12 // FPGA clock in MHz
#define P_CLK_SENSOR 13 // Sensor clock in MHz
#define P_FPGA_XTRA 14 // Extra cycles needed to compressor (probably constant...)
#define P_TRIG 15 /// External trigger mode
/// bit 0 - "old" external mode (0- internal, 1 - external )
/// bit 1 - enable(1) or disable(0) external trigger to stop clip
/// bit 2 - async (snapshot, ext trigger) mode, 0 - continuous NOTE: Only this bit is used now !
/// bit 3 - no overlap, single frames: program - acquire/compress same frame
#define P_BGFRAME 16 // Background measurement mode - will use 16-bit mode and no FPN correction
#define P_IMGSZMEM 17 // image size in video memory (calculated when channel 0 is programmed)
// image page numbers depend on image size/pixel depth, so changing any of them will invalidate all pages
#define P_PAGE_ACQ 18 // Number of image page buffer to acquire to (0.1?)
#define P_PAGE_READ 19 // Number of image page buffer to read from to (0.1?)
#define P_OVERLAP 20 // number of EXRA lines to be acquired - probably dead,
#define P_VIRT_KEEP 21 // 0 - recalculate P_VIRT_WIDTH, P_VIRT_HEIGHT when window is changed, 1 - keep those parameters
#define P_VIRT_WIDTH 22 // Virtual window width
#define P_VIRT_HEIGHT 23 // Virtual window height
#define P_WOI_LEFT 24 // WOI left corner (before applying decimation)
#define P_WOI_TOP 25 // WOI top corner
#define P_WOI_WIDTH 26 // WOI width
#define P_WOI_HEIGHT 27 // WOI height
#define P_FLIPH 28 // bit 0 horizontal flip
#define P_FLIPV 29 // bit 0 vertical flip
#define P_DCM_HOR 30 /* Horizontal decimation (1/2/4/8) */
#define P_DCM_VERT 31 /* Vertical decimation (1/2/4/8) copied from horizontal for Zoran chips */
#define P_BIN_HOR 32 /* binning 1/2 - KAC1310 only - now for mt9t001 */
#define P_BIN_VERT 33 /* not used yet binning 1/2 - KAC1310 only - now for mt9t001*/
#define P_FPGATEST 34 // FPGA test modes (now - just one)
#define P_FRAMESYNC_DLY 35 /* maybe - temporary - delay of frame sync (vacts) by number of scan lines - for photofinish mode*/
#define P_PF_HEIGHT 36 /*height of each strip in photofinish mode - normally 2 lines */
/*also now includes timestamping mode +0x10000 - for normal frames, 0x20000 - for photo-finish */
#define P_BITS 37 /* pixel depth - bits 10/8/4 */
#define P_SHIFTL 38 /* "digital gain" - shift left by 0/1/2 bits (3 ->-1)*/
#define P_FPNS 39 // FPN correction mode (subtract) 0..3
// 0-none, 1 - fine(25%), 2 - 50%, 3 - coarse(100%)
#define P_FPNM 40 // FPN correction mode (multiply) 0..3
// 0-none, 1 - fine(+/-12.5%), 2 - medium (+/-25%), +3 - coarse(+/-50%)
#define P_TESTSENSOR 41 // sensor test mode(s) 0x10000 - enable, lower bits - test mode
#define P_VIRTTRIG 42 // Sum of pixels in a line greater than this value - trigger acquisition
#define P_PERIOD_MIN 43 // (readonly) minimal frame period (in pixel clocks) limited by user or compressor
#define P_PERIOD_MAX 44 // (readonly) frame period (in pixel clocks) limited by user
#define P_SENSOR_PIXH 45 // (readonly) pixels to be read from the sensor, horizontal (incliding margins, excluding embedded timestamps). In multisesnor applies to the whole frame
#define P_SENSOR_PIXV 46 // (readonly) pixels to be read from the sensor, vertical (incliding margins)
#define P_FATZERO 47 // subtract while adding data from to consequitive frames (async trigger)
#define P_COMPMOD_TILSH 48
#define P_COMPMOD_DCSUB 49
#define P_COMPMOD_QTAB 50 // to be written not directly, but by pgm_quality ?
#define P_FP1000S 51 // Frames per 1000 sec (fps * 1000)
#define P_SENSOR_WIDTH 52
#define P_SENSOR_HEIGHT 53
#define P_COLOR_SATURATION_BLUE 54 // 100*realtive saturation blue - preserve?
#define P_COLOR_SATURATION_RED 55 // 100*realtive saturation red
/// Vignetting control, AX*X^2+BX*X+AY*Y^2+BY*Y+C
#define P_VIGNET_AX 56
#define P_VIGNET_AY 57
#define P_VIGNET_BX 58
#define P_VIGNET_BY 59
#define P_VIGNET_C 60 /// nominal 0x8000
#define P_VIGNET_SHL 61 /// shift left color_coeff*vign_correction. 0..7, default=1 (up to 4x color correction* vignetting correction)
#define P_SCALE_ZERO_IN 62 /// signed 16 bit - subtract from pixel 16-bit data before multiplication
#define P_SCALE_ZERO_OUT 63 /// signed 16 bit - add after correction
/// "digital gains" for color correction, 17-bit unsigned data (default 0x8000).
#define P_DGAINR 64
#define P_DGAING 65
#define P_DGAINGB 66
#define P_DGAINB 67
#define P_RSCALE_ALL 68 /// bits 0..29: Ratio of [P_GAINR]/[P_GAING] or one of special, bit 30 - recalculate(self cleaning), bit 31 - ignore
#define P_GSCALE_ALL 69
#define P_BSCALE_ALL 70
#define CSCALES_WIDTH 28
#define CSCALES_CTL_BIT 28
#define CSCALES_CTL_WIDTH 2
/// commands to be written to P_*SCALE_CTL
#define CSCALES_CTL_NORMAL 0 /// USE P_*SCALE as is
#define CSCALES_CTL_RECALC 1 /// Recalculate P_*SCALE from P_GAIN*, P_GAING, then use it (will change to CSCALES_CTL_NORMAL when applied)
#define CSCALES_CTL_FOLLOW 2 /// Don't apply P_*SCALE to P_GAIN*, but update it from the current P_*SCALE from P_GAIN*/P_GAING
#define CSCALES_CTL_DISABLE 3 /// Disable P_*SCALE - don't apply P_*SCALE to P_GAIN*, don't update P_*SCALE from P_GAIN*, P_GAING
#define P_CORING_PAGE 71 // zero bin + ((rounding add) << 8) 8-bit JPEG quantizer zero bin size, fractional addition to absolute value before truncating
#define P_HISTRQ 72 // per-frame enabling of histogram calculation - bit 0 - Y (G), bit 2 - C (R,G2,B)
#define P_TILES 73 // Number of 16x16 (20x20) tiles in a compressed frame
#define P_SENSOR_PHASE 74 // packed, low 16 bit - signed fine phase, bits [18:17] - 90-degrees shift
#define P_TEMPERATURE_PERIOD 75 // period of temperature measurements, ms (normally - multiple seconds)
#define P_AUTOEXP_ON 76 // unsigned long on;
/// relative histogram (autoexposure) window (changed from % to 1/0x10000)
#define P_HISTWND_RWIDTH 77 // unsigned long width (%)->relative (0x10000 - 1.0);
#define P_HISTWND_RHEIGHT 78 //unsigned long height (%);
#define P_HISTWND_RLEFT 79 // unsigned long left (%);
#define P_HISTWND_RTOP 80 // unsigned long top (%);
/// Are these used anywhere now? ...P_AUTOEXP_SKIP_T
#define P_AUTOEXP_EXP_MAX 81 //unsigned long exp_max; /* 100 usec == 1 etc... */
#define P_AUTOEXP_OVEREXP_MAX 82 // unsigned long overexp_max; /* percentages for overexposured pixels - 1% == 100, 5% == 500, 0.02% == 2 etc... */
#define P_AUTOEXP_S_PERCENT 83 // unsigned long s_percent;(controlling that % of pixels that should have value greater than S_INDEX - below)
#define P_AUTOEXP_S_INDEX 84 // unsigned long s_index; Specified number of pixels (S_PERCENT) should have value above S_INDEX
#define P_AUTOEXP_EXP 85 // unsigned long exp; Current exposure time
#define P_AUTOEXP_SKIP_PMIN 86 // unsigned long skip_pmin; /* percent of delta for skip changes: 1% == 100 */ - no exposure corrections if the desired change is less than that
#define P_AUTOEXP_SKIP_PMAX 87 // unsigned long skip_pmax; /* percent of changes for wait one frame before apply changes: 1% == 100 */ - do not apply chnanges if they are to big - wait for the next frame
#define P_AUTOEXP_SKIP_T 88 // unsigned long skip_t; /* time for skip changes: 100 usec == 1 */ Not quite sure what it is
///same as written to the FPGA for the histogram window
#define P_HISTWND_WIDTH 89 // autoexposure window width (pixels)
#define P_HISTWND_HEIGHT 90 // autoexposure window height (pixels)
#define P_HISTWND_TOP 91 // autoexposure window top (pixels)
#define P_HISTWND_LEFT 92 // autoexposure window left (pixels)
#define P_FOCUS_SHOW 93 // show focus information instead of/combined with the image:
// 0 - regular image, 1 - block focus instead of Y DC (AC=0), 2 - image Y DC combined all frame, 3 combined in WOI
#define P_FOCUS_SHOW1 94 // Additional parameter that modifies visualization mode. Currently just a single bit (how much to add)
#define P_FOCUS_LEFT 96 // focus WOI left margin, inclusive (3 LSB will be zeroed as it should be multiple of 8x8 block width)
#define P_FOCUS_WIDTH 97 // focus WOI width (3 LSB will be zeroed as it should be multiple of 8x8 block width)
#define P_FOCUS_TOP 98 // focus WOI top margin, inclusive (3 LSB will be zeroed as it should be multiple of 8x8 block height)
#define P_FOCUS_HEIGHT 99 // focus WOI height (3 LSB will be zeroed as it should be multiple of 8x8 block height)
#define P_FOCUS_TOTWIDTH 100 // (readonly) - total width of the image frame in pixels
#define P_FOCUS_FILTER 101 // select 8x8 filter used for the focus calculation (same order as quantization coefficients), 0..14
//!timing generator/trigger delay/external trigger control
#define P_TRIG_CONDITION 102 // trigger condition, 0 - internal, else dibits ((use<<1) | level) for each GPIO[11:0] pin
#define P_TRIG_DELAY 103 // trigger delay, 32 bits in pixel clocks
#define P_TRIG_OUT 104 // trigger output to GPIO, dibits ((use << 1) | level_when_active). Bit 24 - test mode, when GPIO[11:10] are controlled by other internal signals
#define P_TRIG_PERIOD 105 // output sync period (32 bits, in pixel clocks). 0- stop. 1..256 - single, >=256 repetitive with specified period.
#define P_TRIG_BITLENGTH 106 // bit length minus 1 (in pixel clock cycles) when transmitting/receiving timestamps. Legal values 2..255
#define P_TRIG_BITLENGTH_DEFAULT 31 // P_TRIG_BITLENGTH default value
#define P_SKIP_FRAMES 107 // number of frames to skip after restarting sensor+compressor - now zero/nonzero?
#define P_I2C_QPERIOD 108 // number of system clock periods in 1/4 of i2c SCL period to the sensor/sensor board
#define P_I2C_BYTES 109 // number of bytes in hardware i2c write (after slave addr) -0/1/2
#define P_IRQ_SMART 110 // "smart" IRQ modes: +1 - wait for VACT in early compressor_done, +2 - wait for dma fifo ready
/// Currently bit 0 will be always 1 (needs fix in FPGA)
#define P_EXTERN_TIMESTAMP 111 // Use external timestamp (received with sync) when availabele, 0 - always use local timestamp
#define P_OVERSIZE 112 // ignore sensor dimensions, use absolute WOI_LEFT, WOI_TOP
#define P_XMIT_TIMESTAMP 113 // 0 - transmit just sync pulse, 1 - pulse+timestamp over the sync line
//#define P_VALID 113 // frame parameters valid (all needed parameters written in time, smth. else)
//#define P_QTABLE 114 // number of quantization table used (0..7)
#define P_CORING_INDEX 114 // MSW - color coring index (if 0 - use LSW), LSW - Y coring index. Currently 1 step is 1/10 of the pre-quantized DCT
// coefficient, maximum of 10. For the same filtering effect it should be higher for higher JPEG quality
#define P_RFOCUS_LEFT 115 // relative (0x10000 - 1.0) focus WOI left margin, inclusive (3 LSB will be zeroed as it should be multiple of 8x8 block width)
#define P_RFOCUS_WIDTH 116 // relative (0x10000 - 1.0)focus WOI width (3 LSB will be zeroed as it should be multiple of 8x8 block width)
#define P_RFOCUS_TOP 117 // relative (0x10000 - 1.0)focus WOI top margin, inclusive (3 LSB will be zeroed as it should be multiple of 8x8 block height)
#define P_RFOCUS_HEIGHT 118 // relative (0x10000 - 1.0)focus WOI height (3 LSB will be zeroed as it should be multiple of 8x8 block height)
#define P_SDRAM_CHN20 125 // data to be written to the SDRAM CH2 REG 0 (last moment)
#define P_SDRAM_CHN21 126 // data to be written to the SDRAM CH2 REG 1
#define P_SDRAM_CHN22 127 // data to be written to the SDRAM CH2 REG 2
/// The following 4 parameters should have consecutive indexes
/// see FRAMEPAIR_MASK_BYTES to modify just part of the word (i.e. scale, not hash16
#define P_GTAB_R 128 // combines (P_PIXEL_LOW<<24) | (P_GAMMA <<16) and 16-bit (6.10) scale for gamma tables, individually for each color.
// 16Msbs are also "hash16" and do not need to be black level/gamma, just uniquely identify the table for applications
#define P_GTAB_G 129 // same for the first green (red line)
#define P_GTAB_GB 130 // same for the second green (blue line)
#define P_GTAB_B 131 // same for the blue
#define P_QUALITY 132 //JPEG IMAGE QUALITY (now uses 2 bytes)
#define P_ACTUAL_WIDTH 133 // RD P_RO_WIDTH 1 pixels/row
#define P_ACTUAL_HEIGHT 134 // RD P_RO_HEIGHT 2 pixels/column
#define P_COLOR 135 /// mono - 0, color mode - 1, +0 - normal, 256 - sensor test, 512 - FPGA test
#define COLORMODE_MONO6 0 // monochrome, (4:2:0),
#define COLORMODE_COLOR 1 // color, 4:2:0, 18x18(old)
#define COLORMODE_JP46 2 // jp4, original (4:2:0)
#define COLORMODE_JP46DC 3 // jp4, dc -improved (4:2:0)
#define COLORMODE_COLOR20 4 // color, 4:2:0, 20x20, middle of the tile (not yet implemented)
#define COLORMODE_JP4 5 // jp4, 4 blocks, (legacy)
#define COLORMODE_JP4DC 6 // jp4, 4 blocks, dc -improved
#define COLORMODE_JP4DIFF 7 // jp4, 4 blocks, differential red := (R-G1), blue:=(B-G1), green=G1, green2 (G2-G1). G1 is defined by Bayer shift, any pixel can be used
#define COLORMODE_JP4HDR 8 // jp4, 4 blocks, differential HDR: red := (R-G1), blue:=(B-G1), green=G1, green2 (high gain)=G2) (G1 and G2 - diagonally opposite)
#define COLORMODE_JP4DIFF2 9 // jp4, 4 blocks, differential, divide differences by 2: red := (R-G1)/2, blue:=(B-G1)/2, green=G1, green2 (G2-G1)/2
#define COLORMODE_JP4HDR2 10 // jp4, 4 blocks, differential HDR: red := (R-G1)/2, blue:=(B-G1)/2, green=G1, green2 (high gain)=G2),
#define COLORMODE_MONO4 14 // monochrome, 4 blocks (but still with 2x2 macroblocks)
/// the following 8 values should go in the same sequence as fields in the histogram page
#define P_FRAME 136 // Frame number (reset with JPEG pointers) -(read only)
#define P_GAINR 137 // R channel gain 8.16 (0x10000 - 1.0). Combines both analog gain and digital scaling
#define P_GAING 138 // G channel gain ("red line")
#define P_GAINGB 139 // G channel gain ("blue line")
#define P_GAINB 140 // B channel gain
#define P_EXPOS 141 //P_RW_EXPOS 1 exposure time - now in microseconds?
#define P_VEXPOS 142 // video exposure (if 0 - use P_RW_EXPOS in ms)
#define P_FOCUS_VALUE 143 // (readonly) - sum of all blocks focus values inside focus WOI
/// 143 - last to copy
#define P_COMPMOD_BYRSH 160 // Bayer shift in compressor
#define P_PORTRAIT 161 // Quantization coefficients optimized for verical scan lines
///TODO: rearrange, combine with other AUTOEXP
/// if [G_HIST_DIM_01] is set to 0xffffffff that will force re-calibration (1 dark frame)
/// The following is a daemons control so the sleeping daemons can be awaken by the drivers when the corresponding bit is set and
/// one of the following events happen (depending on driver and lseek (SEEK_END) offset:
/// frame interrupt (any - compressed or not) - through "/dev/frameparsall"
/// frame compressed interrupt - through "/dev/circbuf"
/// histogram Y (G1) is ready - through "/dev/histogram_cache"
/// histogram C (R,G1,G2,B) are ready - through "/dev/histogram_cache"
#define P_DAEMON_EN 165 /// disable all autoexp features AEXP, WB, HDR- make extra sleep for AUTOEXP_EN to become non-zero (normal frame rules)
#define P_AEXP_FRACPIX 166 /// Fraction of all pixels that should be below P_AEXP_LEVEL (16.16 - 0x10000 - all pixels)
#define P_AEXP_LEVEL 167 /// Target output level: [P_AEXP_FRACPIX]/0x10000 of all pixels should have value below it (also 16.16 - 0x10000 - full output scale)
#define P_HDR_DUR 168 /// 0 - HDR 0ff, >1 - duration of same exposure (currently 1 or 2 - for free running)
#define P_HDR_VEXPOS 169 /// if less than 0x10000 - number of lines of exposure, >=10000 - relative to "normal" exposure
#define P_AE_PERIOD 170 /// Autoexposure period (will be increased if below the latency)
#define P_WB_PERIOD 171 /// White balance period (will be increased if below the latency)
#define P_WB_CTRL 172 /// bitmask - which colors to correct (1 - correct, 0 - ignore)
#define P_WB_WHITELEV 173 /// White balance level of white (16.16 - 0x10000 is full scale, 0xfae1 - 98%, default)
#define P_WB_WHITEFRAC 174 /// White balance fraction (16.16) of all pixels that have level above [P_WB_WHITELEV] for the brightest color
/// locally [P_WB_WHITELEV] will be decreased if needed to satisfy [P_WB_WHITELEV]. default is 1% (0x028f)
#define P_WB_MAXWHITE 175 /// Maximal allowed "white" pixels fraction (16.16) to have level above [P_WB_WHITELEV] for the darkest color
/// if this limit is exceeded there will be no correction (waiting for autoexposure to decrease overall brightness)
#define P_WB_SCALE_R 176 /// additional correction for R from calulated by white balance (16.16)
#define P_WB_SCALE_GB 177 /// additional correction for G2(GB) from calulated by white balance (16.16)
#define P_WB_SCALE_B 178 /// additional correction for B from calulated by white balance (16.16)
#define P_EXP_AHEAD 179 /// How many frames ahead of the current frame write exposure to the sensor
#define P_AE_THRESH 180 /// AE error (logariphmic exposures) is integrated between frame and corrections are scaled when error is below thershold (500)
#define P_WB_THRESH 181 /// same for WB
/// Used by white balancing to control analog gains in addition to gamma tables. Can be limited to narrower range than
#define P_GAIN_MIN 182 /// minimal sensor analog gain 0x10000 ~1.0
#define P_GAIN_MAX 183 /// maximal sensor analog gain 0x10000 ~1.0
#define P_GAIN_CTRL 184 /// minimal correction to be applied to the analog gain (should be set larger that sensor actual gain step to prevent oscillations (0x100 - 1.0, 0x20 - 1/8)
#define GAIN_BIT_STEP 0 /// start bit of gain step control in P_GAIN_CTRL
#define GAIN_BIT_ENABLE 16 /// start bit of enabling analog gain controls in white balancing
/// Requests for autocampars daemon
#define P_AUTOCAMPARS_CTRL 185 /// bits 0..24 - groups to restore, bits 24..27 - page number to save bits 28..30: 1 - restore, 2 - save, 3 - set default 4 save as default 5 - init
/// Parameters for ccamftp.php daemon
/// (server, account, password, directories,script names are sepaarte)
#define P_FTP_PERIOD 190 /// FTP image upload period
#define P_FTP_TIMEOUT 191 /// Maximal time allowed for image uploading
#define P_FTP_UPDATE 192 /// Maximal time between updates (camera wil re-read remote configuration file)
// streamer parameters
#define _P_STROP_OFFSET 193
// multicast/unicast transport
#define P_STROP_MCAST_EN (_P_STROP_OFFSET + 0) // != 0 for multicast, 0 for unicast
#define P_STROP_MCAST_IP (_P_STROP_OFFSET + 1) // 0 for camera IP based multicast, other value - for custom IP
#define P_STROP_MCAST_PORT (_P_STROP_OFFSET + 2) // >= 1024 && <= 65532
#define P_STROP_MCAST_TTL (_P_STROP_OFFSET + 3) // >= 1 && <= 15
// audio - support only one ("default") soundcard, if present
#define P_STROP_AUDIO_EN (_P_STROP_OFFSET + 4) // 0 - disable audio, else - try if soundcard is present
#define P_STROP_AUDIO_RATE (_P_STROP_OFFSET + 5) // >= 11250 && <= 48000
#define P_STROP_AUDIO_CHANNEL (_P_STROP_OFFSET + 6) // 1 - mono, 2 - stereo
#define P_STROP_FRAMES_SKIP (_P_STROP_OFFSET + 7) // 0 - output each frame, 1 - output/skip == 1/1 fomr 2 frames, 2 - output/skip == 1/2 from 3 frames etc
#define P_AUDIO_CAPTURE_VOLUME (_P_STROP_OFFSET + 8) // for streamer and camogm2: 0 == 0%; 65535 == 100% capture volume, by default 90% == 58981
///parameters related to multi-sensor operation
#define _P_MULTISENS_OFFSET 208
#define P_MULTISENS_EN (_P_MULTISENS_OFFSET + 0) // 0 - single sensor, no 10359A, otherwise - bitmask of the sensors enabled (obeys G_SENS_AVAIL that should not be modified at runtime)
#define P_MULTI_PHASE_SDRAM (_P_MULTISENS_OFFSET + 1) // similar to P_SENSOR_PHASE, but for sensor1, connected to 10359
#define P_MULTI_PHASE1 (_P_MULTISENS_OFFSET + 2) // similar to P_SENSOR_PHASE, but for sensor1, connected to 10359
#define P_MULTI_PHASE2 (_P_MULTISENS_OFFSET + 3) // similar to P_SENSOR_PHASE, but for sensor2, connected to 10359
#define P_MULTI_PHASE3 (_P_MULTISENS_OFFSET + 4) // similar to P_SENSOR_PHASE, but for sensor3, connected to 10359
#define P_MULTI_SEQUENCE (_P_MULTISENS_OFFSET + 5) // sensor sequence (bits 0,1 - first, 2,3 - second, 4,5 - third). 0 - disable. Will obey G_SENS_AVAIL & P_MULTISENS_EN
#define P_MULTI_FLIPH (_P_MULTISENS_OFFSET + 6) // additional per-sensor horizontal flip to global P_FLIPH, same bits as in G_SENS_AVAIL
#define P_MULTI_FLIPV (_P_MULTISENS_OFFSET + 7) // additional per-sensor vertical flip to global P_FLIPV, same bits as in G_SENS_AVAIL
#define P_MULTI_MODE (_P_MULTISENS_OFFSET + 8) // Mode 0 - single sensor (first in sequence), 1 - composite (only enabled in triggered mode)
#define P_MULTI_HBLANK (_P_MULTISENS_OFFSET + 9) // Horizontal blanking for buffered frames (2,3) - not needed?
///parameters for adjusting physical sensors WOI inside the composite frame
#define P_MULTI_CWIDTH (_P_MULTISENS_OFFSET + 10) // Composite frame width (stored while in single-sensor mode, copied to P_WOI_WIDTH)
#define P_MULTI_CHEIGHT (_P_MULTISENS_OFFSET + 11) // Composite frame height (stored while in single-sensor mode)
#define P_MULTI_CLEFT (_P_MULTISENS_OFFSET + 12) // Composite frame left margin (stored while in single-sensor mode, copied to P_WOI_LEFT)
#define P_MULTI_CTOP (_P_MULTISENS_OFFSET + 13) // Composite frame top margin (stored while in single-sensor mode)
#define P_MULTI_CFLIPH (_P_MULTISENS_OFFSET + 14) // Horizontal flip for composite image (stored while in single-sensor mode)
#define P_MULTI_CFLIPV (_P_MULTISENS_OFFSET + 15) // Vertical flip for composite image (stored while in single-sensor mode)
#define P_MULTI_VBLANK (_P_MULTISENS_OFFSET + 16) // Vertical blanking for buffered frames (2,3) BEFORE FRAME, not after
/// should go in that sequence *1,*2,*3 (will be indexed)
#define P_MULTI_WOI (_P_MULTISENS_OFFSET + 17) // Width of frame 1 (direct) // Same as next
#define P_MULTI_WIDTH1 ( P_MULTI_WOI+ 0) // Width of frame 1 (direct) // same as P_MULTI_WOI !!!!
#define P_MULTI_WIDTH2 ( P_MULTI_WOI+ 1) // Width of frame 2 (first buffered)
#define P_MULTI_WIDTH3 ( P_MULTI_WOI+ 2) // Width of frame 3 (second buffered)
#define P_MULTI_HEIGHT1 ( P_MULTI_WOI+ 3) // Height of frame 1 (direct)
#define P_MULTI_HEIGHT2 ( P_MULTI_WOI+ 4) // Height of frame 2 (first buffered)
#define P_MULTI_HEIGHT3 ( P_MULTI_WOI+ 5) // Height of frame 3 (second buffered)
#define P_MULTI_LEFT1 ( P_MULTI_WOI+ 6) // Left margin of frame 1 (direct)
#define P_MULTI_LEFT2 ( P_MULTI_WOI+ 7) // Left margin of frame 2 (first buffered)
#define P_MULTI_LEFT3 ( P_MULTI_WOI+ 8) // Left margin of frame 3 (second buffered)
#define P_MULTI_TOP1 ( P_MULTI_WOI+ 9) // Top margin of frame 1 (direct)
#define P_MULTI_TOP2 ( P_MULTI_WOI+ 10) // Top margin of frame 2 (first buffered)
#define P_MULTI_TOP3 ( P_MULTI_WOI+ 11) // Top margin of frame 3 (second buffered)
#define P_MULTI_TOPSENSOR (_P_MULTISENS_OFFSET + 29) // number of sensor channel used in first (direct) frame: 0..2, internal parameter (window->sensorin)
#define P_MULTI_SELECTED (_P_MULTISENS_OFFSET + 30) // number of sensor channel (1..3, not 0..2) used when composite mode is disabled
/// parameters for MakerNote, internal
#define P_MULTI_MODE_FLIPS (_P_MULTISENS_OFFSET + 31) // bit 7 - 0, bit 6 - composite mode, bits 4,5 - flips for frame 3, 2,3 - frame 2, 0,1 - frame 1 (top)
#define P_MULTI_HEIGHT_BLANK1 (_P_MULTISENS_OFFSET + 32) // height of the first sub-frame plus (vertical blank after the first sub-frame) << 16 (output lines, decimated)
#define P_MULTI_HEIGHT_BLANK2 (_P_MULTISENS_OFFSET + 33) // height of the second sub-frame plus (vertical blank after the second sub-frame) << 16 (output lines, decimated)
// up to _P_MULTISENS_OFFSET + 256-208-1=47
#define P_SENSOR_REGS 256 /// shadows of the sensor registers (should be multiple of 32)
#define P_SENSOR_NUMREGS 256 /// number of the sensor registers (should be multiple of 32)
#define P_M10359_REGS (P_SENSOR_REGS + P_SENSOR_NUMREGS) /// shadows of the 10359 registers (should be multiple of 32)
#define P_M10359_NUMREGS 96 /// shadows of the 10359 registers (should be multiple of 32)
#define P_M10359_REGS32BIT 0x40 // 10359 registers above 0x40 are 32-bit ones
#define P_MULTI_NUMREGS 32 /// up to 32 sensor register may have individual values
#define P_MULTI_REGS (P_M10359_REGS + P_M10359_NUMREGS) /// 32-words aligned
#define P_MAX_PAR (P_MULTI_REGS + (MAX_SENSORS * P_MULTI_NUMREGS )) /// maximal # of used parameter+1
#ifdef SAFE_CHECK
#define MULTIREG(x,n) ((((n)>=0) && ((n)0) && ((x) < P_MAX_PAR) && (multiSensIndex[x] > 0))? (multiSensIndex[x]+(n)) : 0)
#else
#define MULTIREG(x,n) ((multiSensIndex[x] > 0)? (multiSensIndex[x]+(n)) : 0) // unsafe
#endif
#define MULTIRVRSREG(x) (multiSensRvrsIndex[x])
//#define P_MAX_PAR 511 /// maximal # of used parameter
//#define P_MAX_GPAR 1023 // maximal # of global parameter
#define P_MAX_GPAR 2047 /// maximal # of global parameter - TODO: change name to NUM_GPAR and make it 2048
#define PARS_SAVE_FROM 128 /// PARS_SAVE_NUM parameters starting from PARS_SAVE_FROM from "this" frame will be saved in circular buffer, PASTPARS_SAVE_ENTRIES entries
#define PARS_SAVE_COPY 16 /// number of parameters copied from future (framepars) to the past (pastpars)
#define PARS_SAVE_NUM 32 /// total size of previous parameter save page
#define PP_PROFILE_START 16 /// index of the first profile timestamp in pastpars
#define P_PROFILE (PARS_SAVE_FROM + PP_PROFILE_START) //index to access profiles as pastpars (i.e. from PHP ELPHEL_PROFILE1,PHP ELPHEL_PROFILE2)
#define FRAMEPAR_GLOBALS 0x01000 /// start of global (not frame-related) parameters
#define GLOBALS_PRESERVE 0x20 /// number of parameters that are not erased during initGlobalPars
/// First 32 parameter values are not erased with initGlobalPars
#define GLOBALPARS(x) globalPars[(x)-FRAMEPAR_GLOBALS] // should work in drivers and applications
#define G_DEBUG (FRAMEPAR_GLOBALS + 2) /// Each bit turns on/off some debug outputs
#define G_TEST_CTL_BITS (FRAMEPAR_GLOBALS + 3) /// turn some features on/off in the drivers for debuggin purposes
#define G_TEST_CTL_BITS_RESET_DMA_COMPRESSOR 0 /// reset compressor and DMA when detecting sensor, bit number in G_TEST_CTL_BITS
#define G_CABLE_TIM (FRAMEPAR_GLOBALS + 7) /// Extra cable delay, signed ps)
#define G_FPGA_TIM0 (FRAMEPAR_GLOBALS + 8) /// FPGA timing parameter 0 - difference between DCLK pad and DCM input, signed (ps)
#define G_FPGA_TIM1 (FRAMEPAR_GLOBALS + 9) /// FPGA timing parameter 1
#define G_SENS_AVAIL (FRAMEPAR_GLOBALS + 10) /// bitmask of the sensor attached to 10359A (0 - no 10359A brd)
#define G_DLY359_OUT (FRAMEPAR_GLOBALS + 11) /// output delay in 10359 board (clock to out) in ps, signed
#define G_DLY359_P1 (FRAMEPAR_GLOBALS + 12) /// delay in 10359 board sensor port 1 (clock to sensor - clock to DCM) in ps, signed
#define G_DLY359_P2 (FRAMEPAR_GLOBALS + 13) /// delay in 10359 board sensor port 2 (clock to sensor - clock to DCM) in ps, signed
#define G_DLY359_P3 (FRAMEPAR_GLOBALS + 14) /// delay in 10359 board sensor port 3 (clock to sensor - clock to DCM) in ps, signed
#define G_DLY359_C1 (FRAMEPAR_GLOBALS + 15) /// cable delay in sensor port 1 in ps, signed
#define G_DLY359_C2 (FRAMEPAR_GLOBALS + 16) /// cable delay in sensor port 2 in ps, signed
#define G_DLY359_C3 (FRAMEPAR_GLOBALS + 17) /// cable delay in sensor port 3 in ps, signed
///gap
#define G_MULTI_CFG (FRAMEPAR_GLOBALS + 23) /// Additional configuration options for 10359 board.
#define G_MULTI_CFG_SYSCLK 0 /// Bit 0 - use 10353 system clock, not the local one (as on 10359 rev 0)
#define G_MULTI_CFG_DLYI2C 1 /// Bit 1 - delay 10359 i2c commands with respect to sensor ones (in multi_pgm_window)
#define G_MULTI_CFG_BEFORE 2 /// Bit 2 - send 10359 i2c commands first (to be sent after frame sync, 0 - sesnor commands first)
#define G_MULTI_REGSM (FRAMEPAR_GLOBALS + 24) /// 8 words of bitmasks of individual sensor registers, used only at init. Later will be initialized (OR-ed?) by driver
/// used up to FRAMEPAR_GLOBALS + 31
///First 32 entries will not be erased when sensor init, Move some here
#define G_FRAME_SIZE (FRAMEPAR_GLOBALS + 33) /// Last compressed frame size in bytes (w/o headers)
#define G_MULTI_NUM (FRAMEPAR_GLOBALS + 34) /// Actual number of parameters that are individual for different channels (limited by P_MULTI_NUMREGS)
#define G_MAXAHEAD (FRAMEPAR_GLOBALS + 35) /// Maximal number of frames ahead of current to be programmed to hardware
#define G_THIS_FRAME (FRAMEPAR_GLOBALS + 36) /// Current frame number (may lag from the hardwaere)
#define G_CIRCBUFSIZE (FRAMEPAR_GLOBALS + 37) /// Size of the circular buffer (in bytes)
//!the following 3 locations should be in the same 32-byte (8 long) cache line
#define G_FREECIRCBUF (FRAMEPAR_GLOBALS + 38) /// Free space in circbuf (uses global read pointer, in bytes)
#define G_CIRCBUFWP (FRAMEPAR_GLOBALS + 39) /// circbuf write pointer (in bytes - similar P_JPEG_WP is in long words)
#define G_CIRCBUFRP (FRAMEPAR_GLOBALS + 40) /// circbuf global read pointer (in bytes )
#define G_SECONDS (FRAMEPAR_GLOBALS + 41) /// seconds (R/W to FPGA timer)
#define G_MICROSECONDS (FRAMEPAR_GLOBALS + 42) /// microseconds (R/W to FPGA timer)
/// Next 5 should go in that sequence
#define G_CALLNASAP (FRAMEPAR_GLOBALS + 43) /// bitmask - what functions can be used not only in the current frame (ASAP) mode
#define G_CALLNEXT (FRAMEPAR_GLOBALS + 43) /// (same as G_CALLNASAP) bitmask of actions to be one or more frames ahead of the programmed one (OR-ed with G_CALLNEXT2..G_CALLNEXT4)
///Leave 4 locations after for (G_CALLNEXT+1)...(G_CALLNEXT+4)
//#define G_CALLNEXT1 (FRAMEPAR_GLOBALS + 44) /// bitmask of actions to be one or more frames ahead of the programmed one (OR-ed with G_CALLNEXT2..G_CALLNEXT4)
//#define G_CALLNEXT2 (FRAMEPAR_GLOBALS + 45) /// bitmask of actions to be two or more frames ahead of the programmed one (OR-ed with G_CALLNEXT3..G_CALLNEXT4)
//#define G_CALLNEXT3 (FRAMEPAR_GLOBALS + 46) // bitmask of actions to be three or more frames ahead of the programmed one (OR-ed with G_CALLNEXT4)
//#define G_CALLNEXT4 (FRAMEPAR_GLOBALS + 47) // bitmask of actions to be four or more frames ahead of the programmed one
#define G_NEXT_AE_FRAME (FRAMEPAR_GLOBALS + 48) // Next frame to be processed by autoexposure - written directly from daemon through mmap
#define G_NEXT_WB_FRAME (FRAMEPAR_GLOBALS + 49) // Next frame to be processed by white balance - written directly from daemon through mmap
#define G_HIST_DIM_01 (FRAMEPAR_GLOBALS + 50) // Percentile measured for colors 0 (lower 16 bits) and 1 (high 16 bits) for VEXPOS=1
#define G_HIST_DIM_23 (FRAMEPAR_GLOBALS + 51) // Percentile measured for colors 2 (lower 16 bits) and 3 (high 16 bits) for VEXPOS=1
/// if [G_HIST_DIM_01] is set to 0xffffffff that will force re-calibration (1 dark frame)
//#define G_EW_HYSTCNTR (FRAMEPAR_GLOBALS + 52) // autoexposure/white balance hysteresis counters , 1 byte each, (sign and count, Y,R,G2,B)
#define G_AE_INTEGERR (FRAMEPAR_GLOBALS + 52) // current integrated error in the AE loop
#define G_WB_INTEGERR (FRAMEPAR_GLOBALS + 53) // current integrated error in WB loop
#define G_TASKLET_CTL (FRAMEPAR_GLOBALS + 54) /// disable individual tasklets (TODO:rename to DEBUG_CTL?)
#define G_GFOCUS_VALUE (FRAMEPAR_GLOBALS + 55) // (readonly) - sum of all blocks focus values inside focus WOI (global)
#define TASKLET_CTL_PGM 0 /// disable programming parameters (should not be)
#define TASKLET_CTL_IGNPAST 1 /// "ignore overdue" control bit
#define TASKLET_CTL_NOSAME 2 /// don't try to process parameters immediately after written. If 0, only non-ASAP will be processed to prevent
#define TASKLET_CTL_ENPROF 3 /// enable profiling (saving timing of the interrupts/tasklets in pastpars)
/// effects of uncertainty of when was it called relative to frame sync
#define TASKLET_HIST_ALL 0 /// calculate each frame
#define TASKLET_HIST_HALF 1 /// calculate each even (0,2,4,6 frme of 8)
#define TASKLET_HIST_QUATER 2 /// calculate twice per 8 (0, 4)
/// NOTE: It is safer to allow all histograms at least once in 8 frames so applications will not be locked up waiting for the missed histogram
/// TODO: detect missing histograms and wakeup queue
#define TASKLET_HIST_ONCE 3 /// calculate once per 8 (0)
#define TASKLET_HIST_RQONLY 4 /// calculate only when specifically requested
#define TASKLET_HIST_NEVER 7 /// never calculate
#define TASKLET_CTL_HISTY_BIT 4 /// shift of histogram calculation for Y in G_TASKLET_CTL (bits 4,5,6)
#define TASKLET_CTL_HISTC_BIT 8 /// shift of histogram calculation for C in G_TASKLET_CTL (bits 8,9,10)
#define G_HIST_LAST_INDEX (FRAMEPAR_GLOBALS + 56) // last used index in histogram cache
#define G_HIST_Y_FRAME (FRAMEPAR_GLOBALS + 57) // last frame for which Y histogram was calcualted
#define G_HIST_C_FRAME (FRAMEPAR_GLOBALS + 58) // last frame for which C histograms were calcualted
#define G_SKIP_DIFF_FRAME (FRAMEPAR_GLOBALS + 59) // number of frames with different size to tolerate before producing POLLHUP in poll(circbuf)
#define G_FTP_NEXT_TIME (FRAMEPAR_GLOBALS + 60) // time of the next FTP upload (seconds from epoch)
#define G_DAEMON_ERR (FRAMEPAR_GLOBALS + 63) // 1 bit per daemon error that needs attention (daemon would put itself to sleep through P_DAEMON_EN)
#define G_DAEMON_RETCODE (FRAMEPAR_GLOBALS + 64) // return codes (32 32-bit words) for daemons, provided with a corresponding bit in G_DAEMON_ERR set
///next will be (FRAMEPAR_GLOBALS + 96)
/// temperature is provided by the daemon, embedded in MakerNote by the driver
#define G_TEMPERATURE01 (FRAMEPAR_GLOBALS + 96) // temperature on the sensors 0 and 1 (0x1000 - sign, rest 8.4 C) no 10359 - only chn0, with 10359 - only 1,2,3 (no 0)
#define G_TEMPERATURE23 (FRAMEPAR_GLOBALS + 97) // temperature on the sensors 2 and 3
#define G_SENSOR_CALIB (FRAMEPAR_GLOBALS + 1024) /// 1024 Array of sensor calibration data, sensor dependent.For Micron it is 256*4 actual gains in 8.16 format
/// Only first 96 for each color are used
///Modifies to the parameter numbers/addresses
#define FRAMEPAIR_FORCE_NEW 0x040000000 // will mark parameter as "modified" even the new==old
#define FRAMEPAIR_FORCE_PROC 0x080000000 // will mark schedule functions for that parameter even if called from setFramePars/setFramePar (normally it is not)
#define FRAMEPAIR_FORCE_NEWPROC 0x0c0000000 // combines both
#define FRAMEPAIR_JUST_THIS 0x10000000 // write only to this frame, don't propagate
// (like "single frame" - compressor, sensor) first write "stop", then - "single" with FRAMEPAIR_JUST_THIS
#define FRAMEPAIR_FRAME_FUNC 0x20000000 // write to func2call instead of the frame parameters
/// compose bit fields to be OR-ed to the parameter number bit 16..25: b - start bit (0..31), w - width 1..32
#define FRAMEPAIR_FRAME_BITS(w,b) ((((w) & 0x1f)<<21) | (((b) & 0x1f)<<16))
/// Shift new data (nd), apply mask and combine with old data (od), taking shift/width information from bits 16..25 of (a)
#define FRAMEPAIR_FRAME_MASK_NEW(a,od,nd) ((((od) ^ ((nd) << (((a)>>16) & 0x1f))) & (((1 << (((a)>>21) & 0x1f))-1) << (((a)>>16) & 0x1f))) ^ (od))
/// read bit field from the data (d), use bit information encoded in bits 16..25 of the parameter address (a)
#define FRAMEPAIR_FRAME_FIELD(a,d) (((d) >> (((a)>>16) & 0x1f)) & ((1 << (((a) >> 21) & 0x1f))-1))
#define FRAMEPAIR_MASK_BYTES (FRAMEPAIR_FRAME_BITS(31,31)) /// 0x03ff0000 - if parameter address & FRAMEPAIR_FRAME_MASK is nonzero, chnage only some bits
///NOTE: byte/word masks not to be OR-ed!
#define FRAMEPAIR_BYTE0 (FRAMEPAIR_FRAME_BITS( 8, 0)) // overwrite only byte0 (LSB) in the paremater
#define FRAMEPAIR_BYTE1 (FRAMEPAIR_FRAME_BITS( 8, 8)) // overwrite only byte1 in the paremater
#define FRAMEPAIR_BYTE2 (FRAMEPAIR_FRAME_BITS( 8, 16)) // overwrite only byte2 in the parematerhttp://192.168.0.229
#define FRAMEPAIR_BYTE3 (FRAMEPAIR_FRAME_BITS( 8, 24)) // overwrite only byte3 (MSB) in the paremater
#define FRAMEPAIR_WORD0 (FRAMEPAIR_FRAME_BITS(16, 0)) // overwrite only word0 (LSW) in the paremater (i.e. gamma scale)
#define FRAMEPAIR_WORD1 (FRAMEPAIR_FRAME_BITS(16, 16)) // overwrite only word1 (MSW) in the paremater (i.e. gamma hash16)
//#define P_DAEMON_EN 165 // disable all autoexp features AEXP, WB, HDR- make extra sleep for AUTOEXP_EN to become non-zero (normal frame rules)
#define DAEMON_BIT_AUTOEXPOSURE 0
#define DAEMON_BIT_STREAMER 1
#define DAEMON_BIT_CCAMFTP 2
#define DAEMON_BIT_CAMOGM 3
#define DAEMON_BIT_AUTOCAMPARS 4
#define DAEMON_BIT_TEMPERATURE 5
// add up to 31
#define P_DAEMON_EN_AUTOEXPOSURE (P_DAEMON_EN | FRAMEPAIR_FRAME_BITS(1, DAEMON_BIT_AUTOEXPOSURE))
#define P_DAEMON_EN_STREAMER (P_DAEMON_EN | FRAMEPAIR_FRAME_BITS(1, DAEMON_BIT_STREAMER))
#define P_DAEMON_EN_CCAMFTP (P_DAEMON_EN | FRAMEPAIR_FRAME_BITS(1, DAEMON_BIT_CCAMFTP))
#define P_DAEMON_EN_CAMOGM (P_DAEMON_EN | FRAMEPAIR_FRAME_BITS(1, DAEMON_BIT_CAMOGM))
#define P_DAEMON_EN_AUTOCAMPARS (P_DAEMON_EN | FRAMEPAIR_FRAME_BITS(1, DAEMON_BIT_AUTOCAMPARS))
#define P_DAEMON_EN_TEMPERATURE (P_DAEMON_EN | FRAMEPAIR_FRAME_BITS(1, DAEMON_BIT_TEMPERATURE))
//#define P_GAIN_CTRL 184 // combines GAIN_STEP and ANA_GAIN_ENABLE
#define P_GAIN_STEP (P_GAIN_CTRL | FRAMEPAIR_FRAME_BITS(16, GAIN_BIT_STEP)) // minimal correction to be applied to the analog gain
// (should be set larger that sensor actual gain step to prevent oscillations (0x100 - 1.0, 0x20 - 1/8)
#define P_ANA_GAIN_ENABLE (P_GAIN_CTRL | FRAMEPAIR_FRAME_BITS(1, GAIN_BIT_ENABLE)) // enable analog gain adjustment in white balance procedure
#define WB_CTRL_BIT_EN 4
#define P_WB_MASK (P_WB_CTRL | FRAMEPAIR_FRAME_BITS(4, 0)) // Colors adjusted in automatic white balance
#define P_WB_EN (P_WB_CTRL | FRAMEPAIR_FRAME_BITS(1, WB_CTRL_BIT_EN)) // Enabling/disabling automatic white balance adjustment
#define P_RSCALE (P_RSCALE_ALL | FRAMEPAIR_FRAME_BITS(CSCALES_WIDTH, 0)) // Red-to-Green ratio, 0x10000 ~ 1.0
#define P_GSCALE (P_GSCALE_ALL | FRAMEPAIR_FRAME_BITS(CSCALES_WIDTH, 0)) // Green2-to-Green ratio, 0x10000 ~ 1.0
#define P_BSCALE (P_BSCALE_ALL | FRAMEPAIR_FRAME_BITS(CSCALES_WIDTH, 0)) // Blue-to-Green ratio, 0x10000 ~ 1.0
#define P_RSCALE_CTL (P_RSCALE_ALL | FRAMEPAIR_FRAME_BITS(CSCALES_CTL_WIDTH, CSCALES_CTL_BIT)) // Red-to-Green ratio control
#define P_GSCALE_CTL (P_GSCALE_ALL | FRAMEPAIR_FRAME_BITS(CSCALES_CTL_WIDTH, CSCALES_CTL_BIT)) // Green2-to-Green ratio control
#define P_BSCALE_CTL (P_BSCALE_ALL | FRAMEPAIR_FRAME_BITS(CSCALES_CTL_WIDTH, CSCALES_CTL_BIT)) // Blue-to-Green ratio control
#define P_SENSOR_SINGLE (P_SENSOR_RUN | FRAMEPAIR_JUST_THIS) // is only good to write SENSOR_RUN_SINGLE there!
#define P_COMPRESSOR_SINGLE (P_COMPRESSOR_RUN | FRAMEPAIR_JUST_THIS) // is only good to write COMPRESSOR_RUN_SINGLE there!
//#define P_HISTRQ 67 // per-frame enabling of histogram calculation - bit 0 - Y (G), bit 2 - C (R,G2,B)
//#define HISTRQ_BITY 0
//#define HISTRQ_BITC 1
#define HISTRQ_BIT_Y 0
#define HISTRQ_BIT_C 1
#define P_HISTRQ_Y (P_HISTRQ | FRAMEPAIR_FRAME_BITS(1, HISTRQ_BIT_Y) | FRAMEPAIR_JUST_THIS) /// request calculation of the Y-histogram for just this frame
#define P_HISTRQ_C (P_HISTRQ | FRAMEPAIR_FRAME_BITS(1, HISTRQ_BIT_C) | FRAMEPAIR_JUST_THIS) /// request calculation of the C-histogram for just this frame
#define P_HISTRQ_YC (P_HISTRQ | FRAMEPAIR_FRAME_BITS(2, HISTRQ_BIT_Y) | FRAMEPAIR_JUST_THIS) /// request calculation of both the Y-histogram and C-histogrames for just this frame
#define G_HISTMODE_Y (G_TASKLET_CTL | FRAMEPAIR_FRAME_BITS(3, TASKLET_CTL_HISTY_BIT)) /// control for histogram calculation Y (see TASKLET_HIST_*)
#define G_HISTMODE_C (G_TASKLET_CTL | FRAMEPAIR_FRAME_BITS(3, TASKLET_CTL_HISTC_BIT)) /// control for histogram calculation Y (see TASKLET_HIST_*)
#define G_PROFILING_EN (G_TASKLET_CTL | FRAMEPAIR_FRAME_BITS(1, TASKLET_CTL_ENPROF)) /// enable profiling (saving timing of the interrupts/tasklets in pastpars)
//#define P_AUTOCAMPARS_CTRL 184 // bits 0..24 - groups to restore, bits 24..27 - page number to save bits 28..30: 1 - restore, 2 - save, 3 - set default 4 save as default 5 - init
#define P_AUTOCAMPARS_GROUPS (P_AUTOCAMPARS_CTRL | FRAMEPAIR_FRAME_BITS(24, 0))
#define P_AUTOCAMPARS_PAGE (P_AUTOCAMPARS_CTRL | FRAMEPAIR_FRAME_BITS(4, 24))
#define P_AUTOCAMPARS_CMD (P_AUTOCAMPARS_CTRL | FRAMEPAIR_FRAME_BITS(3, 28))
///NOTE page 0 is write protected, page 15 (0x0f) is "default" page
#define AUTOCAMPARS_CMD_RESTORE 1 /// restore specified groups of parameters from the specified page
#define AUTOCAMPARS_CMD_SAVE 2 /// save all current parameters to the specified group (page 0 is write-protected)
#define AUTOCAMPARS_CMD_DFLT 3 /// make selected page the default one (used at startup), page 0 OK
#define AUTOCAMPARS_CMD_SAVEDFLT 4 /// save all current parameters to the specified group (page 0 is write-protected) and make it default (used at startup)
#define AUTOCAMPARS_CMD_INIT 5 /// reset sensor/sequencers, restore all parameters from the specified page
/// if defined 1 - will wakeup each frame, regardless of the availability of the histograms
#define HISTOGRAMS_WAKEUP_ALWAYS 0
/// Making use of FPGA queues of i2c and sequencer commands (up to 6 frames ahead)
/// The P_* parameters will now be stored in 8 pages (previous frame, this frame (+0), next(+1),...(+6)
/// Top index (0..7) corresponds to hardware frame counter, parameters are copied after the frame sync/compressor done interrupts.
/// when the 3-bit counter is combined with the software variable to get the full 32-bit frame number
/// Each parameter page includes 927 parameter registers, as well as 97 bitmasks to speed up updates between frames
/// So if no parameters are changed - nothing to be copied from page to page
#define PARS_FRAMES 8 // number of frames handled in buffer
#define PARS_FRAMES_MASK (PARS_FRAMES-1) // currently 7
#define PASTPARS_SAVE_ENTRIES (PARS_FRAMES << 8) // 2048
#define PASTPARS_SAVE_ENTRIES_MASK ((PARS_FRAMES << 8)-1) // 0x7ff
struct framepars_t {
unsigned long pars[927]; // parameter values (indexed by P_* constants)
unsigned long functions; // each bit specifies function to be executed (triggered by some parameters change)
unsigned long modsince[31]; // parameters modified after this frame - each bit corresponds to one element in in par[960] (bit 31 is not used)
unsigned long modsince32; // parameters modified after this frame super index - non-zero elements in in mod[31] (bit 31 is not used)
unsigned long mod[31]; // modified parameters - each bit corresponds to one element in in par[960] (bit 31 is not used)
unsigned long mod32; // super index - non-zero elements in in mod[31] (bit 31 is not used)
unsigned long needproc[31]; /// FIXME: REMOVE parameters "modified and not yet processed" (some do not need any processing)
unsigned long needproc32; /// FIXME: REMOVE parameters "modified and not yet processed" frame super index - non-zero elements in in mod[31] (bit 31 is not used)
};
///TODO: rearrange onchage_* - functions will be executed in this sequence (from 0 to 31)
/// pgm_memcompressor uses pgm_memsensor
/// pgm_compctl,pgm_comprestart use pgm_memcompressor
/// pgm_limitfps uses pgm_memcompressor
/// pgm_memcompressor uses pgm_memsensor
/// pgm_compctl,pgm_comprestart use pgm_memcompressor
/// pgm_limitfps uses pgm_memcompressor
/// pgm_limitfps uses pgm_compmode
/// pgm_trigseq uses pgm_limitfps
/// pgm_sensorin (bayer) uses pgm_window (flip)
/// onchange_i2c should be the first after init sensor (even before onchange_sensorphase)
/// phase (common part conditionally triggers init) -> init -> i2c -> sensorregs -> afterinit
/// reset i2c - only once, when the sensor is reset, it is stopped, by frame numbers go on (and parameters are not erased)
///TODO: onchange_exposure should be after onchange_limitfps
enum onchange_functions_t {
onchange_recalcseq=0, /// recalculate sequences/latencies, according to P_SKIP, P_TRIG
onchange_detectsensor, /// detect sensor type, sets sensor structure (capabilities), function pointers
onchange_sensorphase, /// program sensor clock/phase (needs to know maximal clock frequency)
onchange_i2c, /// program i2c
onchange_sensorregs, /// write sensor registers (only changed from outside the driver as they may have different latencies)?
onchange_initsensor, /// resets sensor, reads sensor registers, schedules "secret" manufacturer's corrections to the registers (stops/re-enables hardware i2c)
onchange_afterinit, /// restore image size, decimation,... after sensor reset or set them according to sensor capabilities if none were specified
onchange_multisens, /// chnages related to multiplexed sensors
onchange_window, /// program sensor WOI and mirroring (flipping)
onchange_window_safe, /// program sensor WOI and mirroring (flipping) - lower latency, no bad frames
// onchange_exposure, /// program exposure
onchange_gains, /// program analog gains
onchange_triggermode, /// program sensor trigger mode
onchange_sensorin, /// program sensor input in FPGA (Bayer, 8/16 bits, ??)
onchange_sensorstop, /// Stop acquisition from the sensor to the FPGA (start has latency of 2)
onchange_sensorrun, /// Start/single acquisition from the sensor to the FPGA (stop has latency of 1)
onchange_gamma, /// program gamma table
onchange_hist, /// program histogram window
onchange_aexp, /// program autoexposure mode
onchange_quality, /// program quantization table(s)
onchange_memsensor, /// program memory channels 0 (sensor->memory) and 1 (memory->FPN)
onchange_memcompressor, /// program memory channel 2 (memory->compressor)
onchange_limitfps, /// check compressor will keep up, limit sensor FPS if needed
onchange_exposure, /// program exposure - NOTE: was just after onchange_window
onchange_compmode, /// program compressor modes (excluding start/stop/single)
onchange_focusmode, /// program focus modes
onchange_trigseq, /// program sequencer (int/ext)
onchange_irq, /// program smart IRQ mode (needs to be on)
onchange_comprestart, /// restart after changing geometry (recognizes ASAP and programs memory channel 2 then)
onchange_compstop, /// stop compressor when changing geometry
onchange_compctl, /// only start/stop/single (after explicitly changed, not when geometry was changed)
onchange_gammaload, /// write gamma tables (should be prepared). Maybe - just last byte, to activate?
onchange_prescal /// change scales for per-color digital gains, apply vignetting correction
// onchange_sensorregs /// write sensor registers (only changed from outside the driver as they may have different latencies)?
/// add others - noe left, all 32 bits used
};
struct framepars_past_t {
unsigned long past_pars[PARS_SAVE_NUM];
};
struct framepars_all_t {
struct framepars_t framePars[PARS_FRAMES];
struct framepars_t func2call; /// func2call.pars[] - each parameter has a 32-bit mask of what pgm_function to call - other fields not used
unsigned long globalPars[P_MAX_GPAR]; /// parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both R/W
struct framepars_past_t pastPars [PASTPARS_SAVE_ENTRIES];
unsigned long multiSensIndex[P_MAX_PAR]; /// indexes of individual sensor register shadows (first of 3) - now for all parameters, not just sensor ones
unsigned long multiSensRvrsIndex[P_MAX_PAR]; /// reverse index (to parent) for the multiSensIndex in lower 16 bits, high 16 bits - sensor number
};
struct frameparspair_t {
unsigned long num; // parameter index ( as defined by P_* constants) ored with "force new" (0x10000) - parameter value will be considered a new one
unsigned long val; // parameter value
};
//framePars errors - change to avoid defined in errno.h?
#define ERR_FRAMEPARS_TOOEARLY 100
#define ERR_FRAMEPARS_TOOLATE 101
#define ERR_FRAMEPARS_BADINDEX 102
#define ERR_PGM_TRYAGAINLATER 103 /// tried to program too early (gamma, ?)
#define FRAMEPARS_SETFRAME 0xff01
#define FRAMEPARS_SETFRAMEREL 0xff02
#define FRAMEPARS_SETLATENCY 0xff03
#define FRAMEPARS_SETFPGATIME 0xff04
#define FRAMEPARS_GETFPGATIME 0xff05
#define FRAME_DEAFAULT_AHEAD 3 // program current frame+3 if not specified
//!for structure mapping:
#define P_AUTOEXP P_AUTOEXP_ON
#define P_AEXPWND P_HISTWND_WIDTH
struct autoexp_t {
unsigned long on;
/*
* in percents: 1 == 1, 100 == 100
*/
unsigned long width;
unsigned long height;
unsigned long left;
unsigned long top;
/*
* start exposure time really not needed...
*/
unsigned long exp_max; /* 100 usec == 1 etc... */
unsigned long overexp_max; /* percentages for overexposured pixels - 1% == 100, 5% == 500, 0.02% == 2 etc... */
/*
* changed chema - balance exposition for set percent of pixels in needed index
*/
unsigned long s_percent;
unsigned long s_index;
/*
* return current state
*/
unsigned long exp;
/*
* "sleep" settings
*/
unsigned long skip_pmin; /* percent of delta for skip changes: 1% == 100 */
unsigned long skip_pmax; /* percent of changes for wait one frame before apply changes: 1% == 100 */
unsigned long skip_t; /* time for skip changes: 100 usec == 1 */
};
struct aexp_window_t {
unsigned long width;
unsigned long height;
unsigned long top;
unsigned long left;
};
struct p_names_t {
int value;
char* name;
};
#define P_NAME_ENTRY(y) { P_##y, #y }
#define G_NAME_ENTRY(y) { G_##y, #y }
#define DEFINE_P_NAMES(x) struct p_names_t x[]= { \
P_NAME_ENTRY(NUMBER), \
P_NAME_ENTRY(SENSOR), \
P_NAME_ENTRY(SENSOR_RUN), \
P_NAME_ENTRY(SENSOR_SINGLE), \
P_NAME_ENTRY(ACTUAL_WIDTH), \
P_NAME_ENTRY(ACTUAL_HEIGHT), \
P_NAME_ENTRY(BAYER), \
P_NAME_ENTRY(PERIOD), \
P_NAME_ENTRY(FP1000SLIM), \
P_NAME_ENTRY(FRAME), \
P_NAME_ENTRY(CLK_FPGA), \
P_NAME_ENTRY(CLK_SENSOR), \
P_NAME_ENTRY(FPGA_XTRA), \
P_NAME_ENTRY(TRIG), \
P_NAME_ENTRY(EXPOS), \
P_NAME_ENTRY(BGFRAME), \
P_NAME_ENTRY(IMGSZMEM), \
P_NAME_ENTRY(PAGE_ACQ), \
P_NAME_ENTRY(PAGE_READ), \
P_NAME_ENTRY(OVERLAP), \
P_NAME_ENTRY(VIRT_KEEP), \
P_NAME_ENTRY(VIRT_WIDTH), \
P_NAME_ENTRY(VIRT_HEIGHT), \
P_NAME_ENTRY(WOI_LEFT), \
P_NAME_ENTRY(WOI_TOP), \
P_NAME_ENTRY(WOI_WIDTH), \
P_NAME_ENTRY(WOI_HEIGHT), \
P_NAME_ENTRY(FLIPH), \
P_NAME_ENTRY(FLIPV), \
P_NAME_ENTRY(FPSFLAGS), \
P_NAME_ENTRY(DCM_HOR), \
P_NAME_ENTRY(DCM_VERT), \
P_NAME_ENTRY(BIN_HOR), \
P_NAME_ENTRY(BIN_VERT), \
P_NAME_ENTRY(FPGATEST), \
P_NAME_ENTRY(TESTSENSOR), \
P_NAME_ENTRY(COLOR), \
P_NAME_ENTRY(FRAMESYNC_DLY), \
P_NAME_ENTRY(PF_HEIGHT), \
P_NAME_ENTRY(BITS), \
P_NAME_ENTRY(SHIFTL), \
P_NAME_ENTRY(FPNS), \
P_NAME_ENTRY(FPNM), \
P_NAME_ENTRY(VEXPOS), \
P_NAME_ENTRY(VIRTTRIG), \
P_NAME_ENTRY(PERIOD_MIN), \
P_NAME_ENTRY(PERIOD_MAX), \
P_NAME_ENTRY(SENSOR_PIXH), \
P_NAME_ENTRY(SENSOR_PIXV), \
P_NAME_ENTRY(GAINR), \
P_NAME_ENTRY(GAING), \
P_NAME_ENTRY(GAINB), \
P_NAME_ENTRY(GAINGB), \
P_NAME_ENTRY(RSCALE_ALL), \
P_NAME_ENTRY(GSCALE_ALL), \
P_NAME_ENTRY(BSCALE_ALL), \
P_NAME_ENTRY(RSCALE), \
P_NAME_ENTRY(GSCALE), \
P_NAME_ENTRY(BSCALE), \
P_NAME_ENTRY(RSCALE_CTL), \
P_NAME_ENTRY(GSCALE_CTL), \
P_NAME_ENTRY(BSCALE_CTL), \
P_NAME_ENTRY(FATZERO), \
P_NAME_ENTRY(QUALITY), \
P_NAME_ENTRY(PORTRAIT), \
P_NAME_ENTRY(FP1000S), \
P_NAME_ENTRY(SENSOR_WIDTH), \
P_NAME_ENTRY(SENSOR_HEIGHT), \
P_NAME_ENTRY(COLOR_SATURATION_BLUE), \
P_NAME_ENTRY(COLOR_SATURATION_RED), \
P_NAME_ENTRY(VIGNET_AX), \
P_NAME_ENTRY(VIGNET_AY), \
P_NAME_ENTRY(VIGNET_BX), \
P_NAME_ENTRY(VIGNET_BY), \
P_NAME_ENTRY(VIGNET_C), \
P_NAME_ENTRY(VIGNET_SHL), \
P_NAME_ENTRY(SCALE_ZERO_IN), \
P_NAME_ENTRY(SCALE_ZERO_OUT), \
P_NAME_ENTRY(DGAINR), \
P_NAME_ENTRY(DGAING), \
P_NAME_ENTRY(DGAINGB), \
P_NAME_ENTRY(DGAINB), \
P_NAME_ENTRY(CORING_PAGE), \
P_NAME_ENTRY(TILES), \
P_NAME_ENTRY(SENSOR_PHASE), \
P_NAME_ENTRY(TEMPERATURE_PERIOD), \
P_NAME_ENTRY(AUTOEXP_ON), \
P_NAME_ENTRY(HISTWND_RWIDTH), \
P_NAME_ENTRY(HISTWND_RHEIGHT), \
P_NAME_ENTRY(HISTWND_RLEFT), \
P_NAME_ENTRY(HISTWND_RTOP), \
P_NAME_ENTRY(AUTOEXP_EXP_MAX), \
P_NAME_ENTRY(AUTOEXP_OVEREXP_MAX), \
P_NAME_ENTRY(AUTOEXP_S_PERCENT), \
P_NAME_ENTRY(AUTOEXP_S_INDEX), \
P_NAME_ENTRY(AUTOEXP_EXP), \
P_NAME_ENTRY(AUTOEXP_SKIP_PMIN), \
P_NAME_ENTRY(AUTOEXP_SKIP_PMAX), \
P_NAME_ENTRY(AUTOEXP_SKIP_T), \
P_NAME_ENTRY(HISTWND_WIDTH), \
P_NAME_ENTRY(HISTWND_HEIGHT), \
P_NAME_ENTRY(HISTWND_TOP), \
P_NAME_ENTRY(HISTWND_LEFT), \
P_NAME_ENTRY(FOCUS_SHOW), \
P_NAME_ENTRY(FOCUS_SHOW1), \
P_NAME_ENTRY(FOCUS_LEFT), \
P_NAME_ENTRY(FOCUS_WIDTH), \
P_NAME_ENTRY(FOCUS_TOP), \
P_NAME_ENTRY(FOCUS_HEIGHT), \
P_NAME_ENTRY(FOCUS_TOTWIDTH), \
P_NAME_ENTRY(FOCUS_FILTER), \
P_NAME_ENTRY(TRIG_CONDITION), \
P_NAME_ENTRY(TRIG_DELAY), \
P_NAME_ENTRY(TRIG_OUT), \
P_NAME_ENTRY(TRIG_PERIOD), \
P_NAME_ENTRY(TRIG_BITLENGTH), \
P_NAME_ENTRY(SKIP_FRAMES), \
P_NAME_ENTRY(I2C_QPERIOD), \
P_NAME_ENTRY(I2C_BYTES), \
P_NAME_ENTRY(IRQ_SMART), \
P_NAME_ENTRY(EXTERN_TIMESTAMP), \
P_NAME_ENTRY(OVERSIZE), \
P_NAME_ENTRY(XMIT_TIMESTAMP), \
P_NAME_ENTRY(GTAB_R), \
P_NAME_ENTRY(GTAB_G), \
P_NAME_ENTRY(GTAB_GB), \
P_NAME_ENTRY(GTAB_B), \
P_NAME_ENTRY(CORING_INDEX), \
P_NAME_ENTRY(RFOCUS_LEFT), \
P_NAME_ENTRY(RFOCUS_WIDTH), \
P_NAME_ENTRY(RFOCUS_TOP), \
P_NAME_ENTRY(RFOCUS_HEIGHT), \
P_NAME_ENTRY(SDRAM_CHN20), \
P_NAME_ENTRY(SDRAM_CHN21), \
P_NAME_ENTRY(SDRAM_CHN22), \
P_NAME_ENTRY(COMPRESSOR_RUN), \
P_NAME_ENTRY(COMPRESSOR_SINGLE), \
P_NAME_ENTRY(COMPMOD_BYRSH), \
P_NAME_ENTRY(COMPMOD_TILSH), \
P_NAME_ENTRY(COMPMOD_DCSUB), \
P_NAME_ENTRY(COMPMOD_QTAB), \
P_NAME_ENTRY(SENSOR_REGS), \
P_NAME_ENTRY(SENSOR_NUMREGS), \
P_NAME_ENTRY(M10359_REGS), \
P_NAME_ENTRY(M10359_NUMREGS), \
P_NAME_ENTRY(DAEMON_EN), \
P_NAME_ENTRY(DAEMON_EN_AUTOEXPOSURE), \
P_NAME_ENTRY(DAEMON_EN_STREAMER), \
P_NAME_ENTRY(DAEMON_EN_CCAMFTP), \
P_NAME_ENTRY(DAEMON_EN_CAMOGM), \
P_NAME_ENTRY(DAEMON_EN_AUTOCAMPARS), \
P_NAME_ENTRY(DAEMON_EN_TEMPERATURE), \
P_NAME_ENTRY(AEXP_FRACPIX), \
P_NAME_ENTRY(AEXP_LEVEL), \
P_NAME_ENTRY(HDR_DUR), \
P_NAME_ENTRY(HDR_VEXPOS), \
P_NAME_ENTRY(EXP_AHEAD), \
P_NAME_ENTRY(AE_THRESH), \
P_NAME_ENTRY(WB_THRESH), \
P_NAME_ENTRY(AE_PERIOD), \
P_NAME_ENTRY(WB_PERIOD), \
P_NAME_ENTRY(WB_CTRL), \
P_NAME_ENTRY(WB_MASK), \
P_NAME_ENTRY(WB_EN), \
P_NAME_ENTRY(WB_WHITELEV), \
P_NAME_ENTRY(WB_WHITEFRAC), \
P_NAME_ENTRY(WB_MAXWHITE), \
P_NAME_ENTRY(WB_SCALE_R), \
P_NAME_ENTRY(WB_SCALE_GB), \
P_NAME_ENTRY(WB_SCALE_B), \
P_NAME_ENTRY(HISTRQ), \
P_NAME_ENTRY(HISTRQ_Y), \
P_NAME_ENTRY(HISTRQ_C), \
P_NAME_ENTRY(HISTRQ_YC), \
P_NAME_ENTRY(PROFILE), \
P_NAME_ENTRY(GAIN_MIN), \
P_NAME_ENTRY(GAIN_MAX), \
P_NAME_ENTRY(GAIN_CTRL), \
P_NAME_ENTRY(GAIN_STEP), \
P_NAME_ENTRY(ANA_GAIN_ENABLE), \
P_NAME_ENTRY(AUTOCAMPARS_CTRL), \
P_NAME_ENTRY(AUTOCAMPARS_GROUPS), \
P_NAME_ENTRY(AUTOCAMPARS_PAGE), \
P_NAME_ENTRY(AUTOCAMPARS_CMD), \
P_NAME_ENTRY(FTP_PERIOD), \
P_NAME_ENTRY(FTP_TIMEOUT), \
P_NAME_ENTRY(FTP_UPDATE), \
P_NAME_ENTRY(STROP_MCAST_EN), \
P_NAME_ENTRY(STROP_MCAST_IP), \
P_NAME_ENTRY(STROP_MCAST_PORT), \
P_NAME_ENTRY(STROP_MCAST_TTL), \
P_NAME_ENTRY(STROP_AUDIO_EN), \
P_NAME_ENTRY(STROP_AUDIO_RATE), \
P_NAME_ENTRY(STROP_AUDIO_CHANNEL), \
P_NAME_ENTRY(STROP_FRAMES_SKIP), \
P_NAME_ENTRY(AUDIO_CAPTURE_VOLUME), \
P_NAME_ENTRY(MULTISENS_EN), \
P_NAME_ENTRY(MULTI_PHASE_SDRAM), \
P_NAME_ENTRY(MULTI_PHASE1), \
P_NAME_ENTRY(MULTI_PHASE2), \
P_NAME_ENTRY(MULTI_PHASE3), \
P_NAME_ENTRY(MULTI_SEQUENCE), \
P_NAME_ENTRY(MULTI_FLIPH), \
P_NAME_ENTRY(MULTI_FLIPV), \
P_NAME_ENTRY(MULTI_MODE), \
P_NAME_ENTRY(MULTI_HBLANK), \
P_NAME_ENTRY(MULTI_VBLANK), \
P_NAME_ENTRY(MULTI_CWIDTH), \
P_NAME_ENTRY(MULTI_CHEIGHT), \
P_NAME_ENTRY(MULTI_CLEFT), \
P_NAME_ENTRY(MULTI_CTOP), \
P_NAME_ENTRY(MULTI_CFLIPH), \
P_NAME_ENTRY(MULTI_CFLIPV), \
P_NAME_ENTRY(MULTI_VBLANK), \
P_NAME_ENTRY(MULTI_WOI), \
P_NAME_ENTRY(MULTI_WIDTH1), \
P_NAME_ENTRY(MULTI_WIDTH2), \
P_NAME_ENTRY(MULTI_WIDTH3), \
P_NAME_ENTRY(MULTI_HEIGHT1), \
P_NAME_ENTRY(MULTI_HEIGHT2), \
P_NAME_ENTRY(MULTI_HEIGHT3), \
P_NAME_ENTRY(MULTI_LEFT1), \
P_NAME_ENTRY(MULTI_LEFT2), \
P_NAME_ENTRY(MULTI_LEFT3), \
P_NAME_ENTRY(MULTI_TOP1), \
P_NAME_ENTRY(MULTI_TOP2), \
P_NAME_ENTRY(MULTI_TOP3), \
P_NAME_ENTRY(MULTI_TOPSENSOR), \
P_NAME_ENTRY(MULTI_SELECTED), \
P_NAME_ENTRY(MULTI_MODE_FLIPS), \
P_NAME_ENTRY(MULTI_HEIGHT_BLANK1), \
P_NAME_ENTRY(MULTI_HEIGHT_BLANK2), \
G_NAME_ENTRY(DEBUG), \
G_NAME_ENTRY(TEST_CTL_BITS), \
G_NAME_ENTRY(CABLE_TIM), \
G_NAME_ENTRY(FPGA_TIM0), \
G_NAME_ENTRY(FPGA_TIM1), \
G_NAME_ENTRY(SENS_AVAIL), \
G_NAME_ENTRY(DLY359_OUT), \
G_NAME_ENTRY(DLY359_P1), \
G_NAME_ENTRY(DLY359_P2), \
G_NAME_ENTRY(DLY359_P3), \
G_NAME_ENTRY(DLY359_C1), \
G_NAME_ENTRY(DLY359_C2), \
G_NAME_ENTRY(DLY359_C3), \
G_NAME_ENTRY(MULTI_CFG), \
G_NAME_ENTRY(MULTI_REGSM), \
G_NAME_ENTRY(FRAME_SIZE), \
G_NAME_ENTRY(MULTI_NUM), \
G_NAME_ENTRY(MAXAHEAD), \
G_NAME_ENTRY(THIS_FRAME), \
G_NAME_ENTRY(CIRCBUFSIZE), \
G_NAME_ENTRY(FREECIRCBUF), \
G_NAME_ENTRY(CIRCBUFWP), \
G_NAME_ENTRY(CIRCBUFRP), \
G_NAME_ENTRY(SECONDS), \
G_NAME_ENTRY(MICROSECONDS), \
G_NAME_ENTRY(CALLNASAP), \
G_NAME_ENTRY(CALLNEXT), \
G_NAME_ENTRY(NEXT_AE_FRAME), \
G_NAME_ENTRY(NEXT_WB_FRAME), \
G_NAME_ENTRY(HIST_DIM_01), \
G_NAME_ENTRY(HIST_DIM_23), \
G_NAME_ENTRY(AE_INTEGERR), \
G_NAME_ENTRY(WB_INTEGERR), \
G_NAME_ENTRY(TASKLET_CTL), \
G_NAME_ENTRY(GFOCUS_VALUE), \
G_NAME_ENTRY(HISTMODE_Y), \
G_NAME_ENTRY(HISTMODE_C), \
G_NAME_ENTRY(HIST_LAST_INDEX), \
G_NAME_ENTRY(HIST_Y_FRAME), \
G_NAME_ENTRY(HIST_C_FRAME), \
G_NAME_ENTRY(SKIP_DIFF_FRAME), \
G_NAME_ENTRY(FTP_NEXT_TIME), \
G_NAME_ENTRY(DAEMON_ERR), \
G_NAME_ENTRY(DAEMON_RETCODE), \
G_NAME_ENTRY(PROFILING_EN), \
G_NAME_ENTRY(TEMPERATURE01), \
G_NAME_ENTRY(TEMPERATURE23), \
G_NAME_ENTRY(SENSOR_CALIB) \
};
#define ONCHANGE_NAME_ENTRY(y) { onchange_##y, #y }
#define DEFINE_ONCHANGE_NAMES(x) struct p_names_t x[]= { \
ONCHANGE_NAME_ENTRY(recalcseq), \
ONCHANGE_NAME_ENTRY(detectsensor), \
ONCHANGE_NAME_ENTRY(sensorphase), \
ONCHANGE_NAME_ENTRY(i2c), \
ONCHANGE_NAME_ENTRY(sensorregs), \
ONCHANGE_NAME_ENTRY(initsensor), \
ONCHANGE_NAME_ENTRY(afterinit), \
ONCHANGE_NAME_ENTRY(window), \
ONCHANGE_NAME_ENTRY(window_safe), \
ONCHANGE_NAME_ENTRY(gains), \
ONCHANGE_NAME_ENTRY(triggermode), \
ONCHANGE_NAME_ENTRY(sensorin), \
ONCHANGE_NAME_ENTRY(sensorstop), \
ONCHANGE_NAME_ENTRY(sensorrun), \
ONCHANGE_NAME_ENTRY(gamma), \
ONCHANGE_NAME_ENTRY(hist), \
ONCHANGE_NAME_ENTRY(aexp), \
ONCHANGE_NAME_ENTRY(quality), \
ONCHANGE_NAME_ENTRY(memsensor), \
ONCHANGE_NAME_ENTRY(memcompressor), \
ONCHANGE_NAME_ENTRY(limitfps), \
ONCHANGE_NAME_ENTRY(exposure), \
ONCHANGE_NAME_ENTRY(compmode), \
ONCHANGE_NAME_ENTRY(focusmode), \
ONCHANGE_NAME_ENTRY(trigseq), \
ONCHANGE_NAME_ENTRY(irq), \
ONCHANGE_NAME_ENTRY(comprestart), \
ONCHANGE_NAME_ENTRY(compstop), \
ONCHANGE_NAME_ENTRY(compctl), \
ONCHANGE_NAME_ENTRY(gammaload), \
ONCHANGE_NAME_ENTRY(prescal), \
ONCHANGE_NAME_ENTRY(multisens) \
};
/* i2c errors */
#ifndef ERR_I2C_SCL_ST0
#define ERR_I2C_SCL_ST0 1
#define ERR_I2C_SDA_ST0 2
#define ERR_I2C_SCL_ST1 4
#define ERR_I2C_SDA_ST1 8
#define ERR_I2C_SCL_NOPULLUP 16
#define ERR_I2C_SDA_NOPULLUP 32
/* i2c_diagnose called by i2c_start (?) could not find any problems. Try again start */
#define ERR_I2C_NOTDETECTED 64
#define ERR_I2C_SHORT 128
#define ERR_I2C_BSY 256
#define ERR_I2C_NACK 512
#endif
/* supported ioctl _IOC_NR's */
#define IO_CCAM_SET_EXT_EXPOSURE 0x06
#define IO_CCAM_MONITOR_SEQ 0x07
//#define IO_CCAM_STOP_DMA 0x08
//#define IO_CCAM_START_DMA 0x09 // just starts DMA - descriptor list should be set eatlier
//#define IO_CCAM_START_RAW 0x0a // Programs DMA descriptor list according to current frame size, FPGA registers and starts DMA
/// MOST ARE OBSOLETE - WILL REMOVE WHEN UPDATING STREAMERS
#define IO_CCAM_JPEG 0x08 /// JPEG-compressor related commands
#define JPEG_CMD_RESET 0x00 /// Resets pointers - both acquisition and readout
//#define JPEG_CMD_ARM 0x01 /// Prepare compressor to read next frame acquired
#define JPEG_CMD_GET 0x02 /// Read current page (will return empty (and length==0) if not ready
#define JPEG_CMD_FORGET 0x03 /// increment read frame pointer
#define JPEG_CMD_CATCHUP 0x04 /// set read pointer to the last acquired (or acquiring if none is acquired yet)
#define JPEG_CMD_ACQUIRE 0x05 /// acquire and compress one frame
#define JPEG_CMD_SAVE_RP 0x06 /// save read pointer
#define JPEG_CMD_RESTORE_RP 0x07 /// restore read pointer
#define JPEG_CMD_N_DONE 0x08 /// return 1 if no more frames to be acquired (frame number)
#define JPEG_CMD_L_DONE 0x09 /// return 1 if no more frames to be acquired (total length)
#define JPEG_CMD_START 0x0a /// start constant compression mode
#define JPEG_CMD_STOP 0x0b /// stop constant compression mode (may want to wait for CAMSEQ_DONE)
#define JPEG_CMD_FRAMES 0x0c /// returns number of frames in buffer, (re)uilds frames chain
#define JPEG_CMD_JUST_STOP 0x0d /// just stop - don't start cycle if was allready off!
#define JPEG_CMD_DUMP 0x0f /// printk all static data/tables
#define JPEG_CMD_RESET0 0x10 /// same as JPEG_CMD_RESET, but non-zero, to be used from lseek (SEEK_END)
//#define PROGRAM_SENSOR_0 0x11 /// programSensor(0) - to be used from lseek (SEEK_END)
//#define PROGRAM_SENSOR_1 0x12 /// programSensor(1) - to be used from lseek (SEEK_END)
/// Compressor state now applies only to particular frame
//#define LSEEK_CAMSEQSTATE 0x13 /// return camSeqState - to be used from lseek (SEEK_END)
#define LSEEK_GAMMA_INIT 1 // SEEK_END LSEEK_GAMMA_INIT to initialize all the gamma data structures
#define LSEEK_GAMMA_ISCURRENT 2 // SEEK_END to check if the selected node(pointed by file pointer) is current - returns 0 if not, otherwise - node index
// parameters for lseek circbuf
#define LSEEK_CIRC_TORP 1
#define LSEEK_CIRC_TOWP 2
#define LSEEK_CIRC_PREV 3
#define LSEEK_CIRC_NEXT 4
#define LSEEK_CIRC_LAST 5
#define LSEEK_CIRC_FIRST 6
#define LSEEK_CIRC_SCND 7
#define LSEEK_CIRC_SETP 8
#define LSEEK_CIRC_VALID 9
#define LSEEK_CIRC_READY 10
#define LSEEK_CIRC_WAIT 11
#define LSEEK_CIRC_FREE 12
#define LSEEK_CIRC_USED 13
#define LSEEK_HUFFMAN_DC0 1
#define LSEEK_HUFFMAN_AC0 2
#define LSEEK_HUFFMAN_DC1 3
#define LSEEK_HUFFMAN_AC1 4
#define LSEEK_HUFFMAN_FPGATAB 5
#define LSEEK_HUFFMAN_DEFAULT 6
#define LSEEK_HUFFMAN_FPGACALC 7
#define LSEEK_HUFFMAN_FPGAPGM 8
//#define LSEEK_RESET_SENSOR 0x14 /// reset sensor and FPGA - next time will reprogram it
//#define LSEEK_INIT_SENSOR 0x15 /// initialise SDRAM and sensor if it is not programmed yet (or reset)
#define LSEEK_GET_FPGA_TIME 0x16 /// get FPGA timer to G_SECONDS, G_MICROSECONDS
#define LSEEK_SET_FPGA_TIME 0x17 /// set FPGA timer to G_SECONDS, G_MICROSECONDS
//#define LSEEK_FLUSH_CACHE 0x18 // workaround for Axis mmap cache coherency problems - flush all cache (8KB)
#define LSEEK_AUTOEXP_SET 0x19 /// set autoexposure parameters
#define LSEEK_AUTOEXP_GET 0x1a /// copy window and exposure parameters to autoexp_state
#define LSEEK_TRIGGER_PGM 0x1b /// program trigger parameters
#define LSEEK_I2C_PGM 0x1c /// program hardware i2c speed/bytes
#define LSEEK_IRQ_SMART_PGM 0x1d /// program "smart" irq modes (+1 - wait VACT, +2 - wait dma fifo)
#define LSEEK_EXTERN_TIMESTAMP_PGM 0x1e /// 1 - use external timestamps if available
#define LSEEK_DMA_INIT 0x1f /// (re-) initialize ETRAX DMA for compressor
#define LSEEK_DMA_STOP 0x20 /// STOP ETRAX DMA
#define LSEEK_DMA_START 0x21 /// STARTETRAX DMA
#define LSEEK_COMPRESSOR_RESET 0x22 /// reset compressor and pointers
#define LSEEK_INTERRUPT_OFF 0x23 /// disable camera interrupts
#define LSEEK_INTERRUPT_ON 0x24 /// enable camera interrupts
#define LSEEK_FRAMEPARS_INIT 0x25 /// reset hardware sequencers, init framepars structure
#define LSEEK_SENSORPROC 0x26 /// process modified parameters in frame 0 (to start sensor detection)
#define LSEEK_FRAME_RESET 0x27 /// reset absolute frame number to avoid integer overflow
///Histograms related commands
#define LSEEK_HIST_WAIT_Y 0x28 /// set histogram waiting for the Y (actually G1) histogram (default after open)
#define LSEEK_HIST_WAIT_C 0x29 /// set histogram waiting for the C (actually R, G2, B) histograms to become available - implies G1 too
#define LSEEK_HIST_REQ_EN 0x2a /// enable histogram request when reading histogram (safer, but may be not desirable in HDR mode) - default after opening
#define LSEEK_HIST_REQ_DIS 0x2b /// disable histogram request when reading histogram - will read latest available relying it is available
#define LSEEK_HIST_NEEDED 0x10000 /// set histogram "needed" mask - 0x10000..0x1ffff
//#define LSEEK_HIST_WAIT_AE 0x2a /// wait for autoexposure enabled
#define LSEEK_DAEMON_FRAME 0x80 /// LSEEK_DAEMON_FRAME+B wait for frame interrupt and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_CIRCBUF 0xa0 /// LSEEK_DAEMON_FRAME+B wait for frame compressed interrupt and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_HIST_Y 0xc0 /// LSEEK_DAEMON_FRAME+B wait for histogram Y ready and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_DAEMON_HIST_C 0xe0 /// LSEEK_DAEMON_FRAME+B wait for all histograms ready and corresponding bit (B) in P_DAEMON_EN is set
#define LSEEK_FRAME_WAIT_REL 0x100 /// LSEEK_WAIT_FRAME_REL+N - skip N frames (0=128.
/// If the High byte is zero, it is treated as Q^0x80 (Q|=(Q^0x80)<<8) for compatibility
/// with a standard single-byte Q value
/// updated in 8.0.8.37 - bit 7 in quality2 means "portrait mode"
unsigned char color; /// color mode //18
unsigned char byrshift; /// bayer shift in compressor //19
unsigned short width; /// frame width, pixels 20-21 - NOTE: should be 20-21
unsigned short height; /// frame height, pixels 22-23
/*24 *//// unsigned char bindec_hor; //! ((bh-1) << 4) | (dh-1) & 0xf (binning/decimation horizontal, 1..16 for each)
/*25 *//// unsigned char bindec_vert; //! ((bv-1) << 4) | (dv-1) & 0xf (binning/decimation vertical , 1..16 for each)
/*24-25*/ unsigned short meta_index; //! index of the linked meta page
/*26-27*/ unsigned short signffff; //! should be 0xffff - it will be a signature that JPEG data was not overwritten,
//! JPEG bitstream can not have two 0xff after each other
union {
/*28-31*/ unsigned long timestamp_sec ; //! number of seconds since 1970 till the start of the frame exposure
/*28-31*/ unsigned long frame_length ; //! JPEG frame length in circular buffer, bytes
};
/*32-35*/ unsigned long timestamp_usec; //! number of microseconds to add
};
struct i2c_timing_t {
unsigned char scl_high; //0x02, //! SCL high:
unsigned char scl_low; //0x02, //! SCL low:
unsigned char slave2master; //0x01, //! slave -> master
unsigned char master2slave; //0x01, //! master -> slave
unsigned char filter_sda; //0x07, //! filter SDA read data by testing multiple times - currently just zero/non zero
unsigned char filter_scl; //0x07};//! filter SCL read data by testing multiple times - currently just zero/non zero
};
/// Gamma data for one component, including direct and reverse tables, hash (i.e. black level+gamma) and links for caching
#define GAMMA_CACHE_NUMBER 256 // number of gamma-tables cached
#define GAMMA_VALID_MASK 1 // table is calculated, matches given hash/scale
#define GAMMA_VALID_REVERSE 2 // reverse table is calculated for the given hash/scale
#define GAMMA_FPGA_MASK 4 // gamma-table encoded for the FPGA is valid
//#define GAMMA_LOCK_MASK 8 // table is locked until programmed to FPGA - now locked is a separate member
// bits passed in int mode
#define GAMMA_MODE_NOT_NICE 1 // if set, no interrupts will be enabled between steps, whole operation is atomic
#define GAMMA_MODE_NEED_REVERSE 2 // reverse gamma table is needed
#define GAMMA_MODE_HARDWARE 4 // the table is needed to program FPGA: fpga-encoded table will be calculated (if not yet),
#define GAMMA_MODE_LOCK 8 // Lock the table for the specified color (used from irq/tasklet - it is needed because all 4 tables in FPGA have to be overwritten at once)
#define GAMMA_SCALE_SHIFT 10 // when scaling - shift right by GAMMA_SCALE_SHIFT (treat scale as 6.10)
#define GAMMA_SCLALE_1 ( 1 << GAMMA_SCALE_SHIFT ) // gamma scale 1.0 - 0x400
struct gamma_stuct_t {
union {
unsigned long hash32; /// fully identifies current table
struct {
unsigned short scale; /// 6.10: 0x400 is 1.0 scale (>=1.0) is applied in the driver, saturating result
union {
unsigned short hash16; /// scale-independent part of the table (tables themselves are calculated outside of the driver)
struct {
unsigned char gamma; /// "gamma" in the range 0.0 ... 2.55
unsigned char black; /// black level to subtract (scaled to full scale) from the input data
};
};
};
};
int valid; /// 0 - table invalid, 1 - table valid +2 for table locked (until sent to FPGA)
// int locked; /// bit frame+ (color<<3) locked for color/frame
int locked; /// NOTE: Changed to just color locked for color
int this_non_scaled; // 0 for non-scaled, others - (for scaled) - pointer to the corresponding non-scaled
union { /// used in head (element 0) and non-scaled chain (not used in scaled)
struct { /// element 0 - heads of the chains
int oldest_non_scaled; //
int newest_non_scaled; //
};
struct { /// non-scaled (gamma data is full 16-bit)
int newer_non_scaled; // table type (non-scaled prototype) used later than this one
int older_non_scaled; // table type (non-scaled prototype) used before this one
};
};
union { /// used in head (element 0) and scaled chain (not used in non-scaled) (or maybe it will be used?)
struct { /// element 0 - heads of the chains
int oldest_all; //
int newest_all; //
};
struct { /// scaled (gamma data is hardware defined 10 bit)
int newer_all; /// newer in a single chain of all scaled tables, regardless of the prototype
int older_all; /// older in a single chain of all scaled tables, regardless of the prototype
/// *_all also includes yet unused nodes (after init)
};
};
union { /// used in non-scaled and scaled, not in the head (element 0)
struct { /// non-scaled
int oldest_scaled; // oldest derivative of this prototype (scaled)
int newest_scaled; // newest derivative of this prototype (scaled)
};
struct { /// scaled (gamma data is hardware defined 10 bit)
int newer_scaled; // table type (non-scaled prototype) used later than this one
int older_scaled; // table type (non-scaled prototype) used before this one
};
struct { /// reuse in the head (element 0) - to make this variable visible through mmap to PHP (for debugging)
int non_scaled_length; // current number of different hash values
int num_locked; // number of nodes locked (until table sent to FPGA)
};
};
union {
struct {
unsigned short direct[257]; // "Gamma" table, 16-bit for both non-scaled prototypes and scaled, 0..0xffff range (hardware will use less)
unsigned short dummy1; // to have it 32-bit aligned
// unsigned short reverse[256]; // reverse table to speed-up reversing (still need interpolation).Index - most significant 8 bits, data - largest direct argument...
unsigned char reverse[256]; /// reverse table to speed-up reversing. No division, but needs interpolation by the application
unsigned long fpga[256]; // data encoded for FPGA "gamma" table (18 bits, "floating point")
};
struct {
// int locked_col_frame[4 * PARS_FRAMES]; //index of the table to load to color/frame (should be locked, until unlocked)
int locked_color[4]; /// NOTE: Changed to just color (locked last written to FPGA - maybe needed again, as the FPGA needs all table to be overwritten - two pages)
// int other [129+128+256 -(4 * PARS_FRAMES)];
// int other [129+64+256 -(4 * PARS_FRAMES)];
int other [129+64+256 -4];
};
};
};
///histograms related structure
#define HISTOGRAM_CACHE_NUMBER 8 // number of frames histograms are kept after acquisition (should be 2^n)
#define COLOR_RED 0
#define COLOR_GREEN1 1
#define COLOR_GREEN2 2
#define COLOR_BLUE 3
#define COLOR_Y_NUMBER COLOR_GREEN1 // green1 (index=1) is used as Y color (i.e. for auto exposure). Histogram for is calculated first (or only)
/*
/// the following 8 values should go in the same sequence as fields in the histogram page
#define P_FRAME 136 // Frame number (reset with JPEG pointers) -(read only)
#define P_GAINR 137 // R channel gain 8.16 (0x10000 - 1.0). Combines both analog gain and digital scaling
#define P_GAING 138 // G channel gain ("red line")
#define P_GAINGB 139 // G channel gain ("blue line")
#define P_GAINB 140 // B channel gain
#define P_EXPOS 141 //P_RW_EXPOS 1 exposure time - now in microseconds?
#define P_VEXPOS 142 // video exposure (if 0 - use P_RW_EXPOS in ms)
#define P_FOCUS_VALUE 143 // (readonly) - sum of all blocks focus values inside focus WOI
*/
#define HISTOGRAM_TABLE_OFFSET 52 /// Histogram tables data starts 44 bytes from the histogram page structure (for PHP raw histogram)
///TODO: Update when histogram_stuct_t is changed
struct histogram_stuct_t {
unsigned long frame; /// frame number correspoding to the current histogram
/// Color gains for the frame of the histogram
union {
unsigned long gains[4];
struct {
unsigned long gain_r;
unsigned long gain_g;
unsigned long gain_gb;
unsigned long gain_b;
};
};
unsigned long expos; /// Exposure time (usec) for the frame of the histogram
unsigned long vexpos; /// number of exposure lines for the frame of the histogram
unsigned long focus; /// sum of all blocks focus values inside focus WOI
unsigned long valid; /// bit mask of valid arrays (0 - hist_r, ... ,4-cumul_hist_r, ..., 11 - percentile_b)
/// Gamma tables hash values for the frame of the histogram
union {
unsigned long gtab[4];
struct {
unsigned long gtab_r;
unsigned long gtab_g;
unsigned long gtab_gb;
unsigned long gtab_b;
};
};
/// Direct histograms, loaded from the FPGA
union {
unsigned long hist[1024] ; /// All 4 histograms
struct {
unsigned long hist_r [256] ; /// Histogram for the red component
unsigned long hist_g [256] ; /// Histogram for the first green component (in the "red" line)
unsigned long hist_gb[256] ; /// Histogram for the second green component (in the "blue" line)
unsigned long hist_b [256] ; /// Histogram for blue component
};
};
/// Direct cumulative histograms, calculated from the loaded from the FPGA
union {
unsigned long cumul_hist[1024] ; /// All 4 cumulative histograms
struct {
unsigned long cumul_hist_r [256] ; /// Cumulative histogram for the red component
unsigned long cumul_hist_g [256] ; /// Cumulative histogram for the first green component (in the "red" line)
unsigned long cumul_hist_gb[256] ; /// Cumulative histogram for the second green component (in the "blue" line)
unsigned long cumul_hist_b [256] ; /// Cumulative histogram for blue component
};
};
/// Calculated reverse cumulative histograms (~percentiles) - for the given 1 byte input X (0 - 1/256 of all pixels, ..., 255 - all pixels)
/// returns threshold value P (0..255), so that number of pixels with value less than x is less or equal to (P/256)*total_number_of_pixels,
/// and number of pixels with value less than (x+1) is greater than (P/256)*total_number_of_pixels,
/// P(0)=0, P(256)=256 /not included in the table/
/// percentiles arrays are calculated without division for each element, interpolation (with division) will be done only for the value of interest
/// on demand, in the user space.
/// NOTE: - argument is _output_ value (after gamma-correction), reverse gamma table is needed to relate percentiles to amount of light (proportional to exposure)
union {
unsigned char percentile[1024] ; /// All 4 percentiles
struct {
unsigned char percentile_r [256] ; /// percentile for the red component
unsigned char percentile_g [256] ; /// percentile for the first green component (in the "red" line)
unsigned char percentile_gb[256] ; /// percentile for the second green component (in the "blue" line)
unsigned char percentile_b [256] ; /// percentile for the blue component
};
};
};
/// Used to provide encoded huffman tables. Those tables (4 of them) will be used in the output JPEG/JP4 files
/// and whill be programmed to the FPGA
struct huffman_encoded_t {
unsigned char bits[16]; /// number of symbols with length k+1
unsigned char huffval[256]; /// The symbols, in order of incr code length
};
/// All other integer constants exported to PHP space (C:"CONSTANT" -> PHP:"ELPHEL_CONST_CONSTANT)
#define CONST_NAME_ENTRY(y) { y, #y }
#define DEFINE_CONST_NAMES(x) struct p_names_t x[]= { \
CONST_NAME_ENTRY(SENSOR_RUN_STOP), \
CONST_NAME_ENTRY(SENSOR_RUN_SINGLE), \
CONST_NAME_ENTRY(SENSOR_RUN_CONT), \
CONST_NAME_ENTRY(COMPRESSOR_RUN_STOP), \
CONST_NAME_ENTRY(COMPRESSOR_RUN_SINGLE), \
CONST_NAME_ENTRY(COMPRESSOR_RUN_CONT), \
CONST_NAME_ENTRY(TASKLET_CTL_PGM), \
CONST_NAME_ENTRY(TASKLET_CTL_IGNPAST), \
CONST_NAME_ENTRY(TASKLET_CTL_NOSAME), \
CONST_NAME_ENTRY(COLORMODE_MONO6), \
CONST_NAME_ENTRY(COLORMODE_COLOR), \
CONST_NAME_ENTRY(COLORMODE_JP46), \
CONST_NAME_ENTRY(COLORMODE_JP46DC), \
CONST_NAME_ENTRY(COLORMODE_COLOR20), \
CONST_NAME_ENTRY(COLORMODE_JP4), \
CONST_NAME_ENTRY(COLORMODE_JP4DC), \
CONST_NAME_ENTRY(COLORMODE_JP4DIFF), \
CONST_NAME_ENTRY(COLORMODE_JP4HDR), \
CONST_NAME_ENTRY(COLORMODE_JP4DIFF2), \
CONST_NAME_ENTRY(COLORMODE_JP4HDR2), \
CONST_NAME_ENTRY(COLORMODE_MONO4), \
CONST_NAME_ENTRY(PARS_FRAMES), \
CONST_NAME_ENTRY(PARS_FRAMES_MASK), \
CONST_NAME_ENTRY(PASTPARS_SAVE_ENTRIES), \
CONST_NAME_ENTRY(PASTPARS_SAVE_ENTRIES_MASK), \
CONST_NAME_ENTRY(FRAMEPAIR_FORCE_NEW), \
CONST_NAME_ENTRY(FRAMEPAIR_FORCE_PROC), \
CONST_NAME_ENTRY(FRAMEPAIR_FORCE_NEWPROC), \
CONST_NAME_ENTRY(FRAMEPAIR_JUST_THIS), \
CONST_NAME_ENTRY(FRAMEPAR_GLOBALS), \
CONST_NAME_ENTRY(FRAMEPAIR_FRAME_FUNC), \
CONST_NAME_ENTRY(FRAMEPAIR_MASK_BYTES), \
CONST_NAME_ENTRY(FRAMEPAIR_BYTE0), \
CONST_NAME_ENTRY(FRAMEPAIR_BYTE1), \
CONST_NAME_ENTRY(FRAMEPAIR_BYTE2), \
CONST_NAME_ENTRY(FRAMEPAIR_BYTE3), \
CONST_NAME_ENTRY(FRAMEPAIR_WORD0), \
CONST_NAME_ENTRY(FRAMEPAIR_WORD1), \
CONST_NAME_ENTRY(ERR_FRAMEPARS_TOOEARLY), \
CONST_NAME_ENTRY(ERR_FRAMEPARS_TOOLATE), \
CONST_NAME_ENTRY(ERR_FRAMEPARS_BADINDEX), \
CONST_NAME_ENTRY(DAEMON_BIT_AUTOEXPOSURE), \
CONST_NAME_ENTRY(DAEMON_BIT_STREAMER), \
CONST_NAME_ENTRY(DAEMON_BIT_CCAMFTP), \
CONST_NAME_ENTRY(DAEMON_BIT_CAMOGM), \
CONST_NAME_ENTRY(DAEMON_BIT_AUTOCAMPARS), \
CONST_NAME_ENTRY(ERR_PGM_TRYAGAINLATER), \
CONST_NAME_ENTRY(FRAMEPARS_SETFRAME), \
CONST_NAME_ENTRY(FRAMEPARS_SETFRAMEREL), \
CONST_NAME_ENTRY(FRAMEPARS_SETLATENCY), \
CONST_NAME_ENTRY(FRAMEPARS_SETFPGATIME), \
CONST_NAME_ENTRY(FRAMEPARS_GETFPGATIME), \
CONST_NAME_ENTRY(GAMMA_CACHE_NUMBER), \
CONST_NAME_ENTRY(GAMMA_VALID_MASK), \
CONST_NAME_ENTRY(GAMMA_VALID_REVERSE), \
CONST_NAME_ENTRY(GAMMA_FPGA_MASK), \
CONST_NAME_ENTRY(GAMMA_MODE_NOT_NICE), \
CONST_NAME_ENTRY(GAMMA_MODE_NEED_REVERSE), \
CONST_NAME_ENTRY(GAMMA_MODE_HARDWARE), \
CONST_NAME_ENTRY(GAMMA_MODE_LOCK), \
CONST_NAME_ENTRY(GAMMA_SCALE_SHIFT), \
CONST_NAME_ENTRY(GAMMA_SCLALE_1), \
CONST_NAME_ENTRY(HISTOGRAM_CACHE_NUMBER), \
CONST_NAME_ENTRY(COLOR_Y_NUMBER), \
CONST_NAME_ENTRY(FRAME_DEAFAULT_AHEAD), \
CONST_NAME_ENTRY(AUTOCAMPARS_CMD_RESTORE), \
CONST_NAME_ENTRY(AUTOCAMPARS_CMD_SAVE), \
CONST_NAME_ENTRY(AUTOCAMPARS_CMD_DFLT), \
CONST_NAME_ENTRY(AUTOCAMPARS_CMD_SAVEDFLT), \
CONST_NAME_ENTRY(AUTOCAMPARS_CMD_INIT), \
CONST_NAME_ENTRY(COLOR_RED), \
CONST_NAME_ENTRY(COLOR_GREEN1), \
CONST_NAME_ENTRY(COLOR_GREEN2), \
CONST_NAME_ENTRY(COLOR_BLUE), \
CONST_NAME_ENTRY(CSCALES_WIDTH), \
CONST_NAME_ENTRY(CSCALES_CTL_BIT), \
CONST_NAME_ENTRY(CSCALES_CTL_WIDTH), \
CONST_NAME_ENTRY(CSCALES_CTL_NORMAL), \
CONST_NAME_ENTRY(CSCALES_CTL_RECALC), \
CONST_NAME_ENTRY(CSCALES_CTL_FOLLOW), \
CONST_NAME_ENTRY(CSCALES_CTL_DISABLE), \
CONST_NAME_ENTRY(HISTOGRAM_TABLE_OFFSET) \
};
/*
///NOTE page 0 is write protected, page 15 (0x0f) is "default" page
#define AUTOCAMPARS_CMD_RESTORE 1 /// restore specified groups of parameters from the specified page
#define AUTOCAMPARS_CMD_SAVE 2 /// save all current parameters to the specified group (page 0 is write-protected)
#define AUTOCAMPARS_CMD_DFLT 3 /// make selected page the default one (used at startup), page 0 OK
#define AUTOCAMPARS_CMD_SAVEDFLT 4 /// save all current parameters to the specified group (page 0 is write-protected) and make it default (used at startup)
#define AUTOCAMPARS_CMD_INIT 5 /// reset sensor/sequencers, restore all parameters from the specified page
*/
#endif /* _ASM_CMOSCAM_H */
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/include/exifa.h 0000664 0000000 0000000 00000020126 12753434647 0031477 0 ustar 00root root 0000000 0000000 /*
exifa.h
*/
#ifndef _ASM_EXIF_H
#define _ASM_EXIF_H
//Major
#define X3X3_EXIF 125
//Minors
#define X3X3_EXIF_EXIF 0 // read encoded Exif data (SEEK_END,
#define X3X3_EXIF_META 1 // write metadata, concurently opened files. All writes atomic
// control/setup devices
#define X3X3_EXIF_TEMPLATE 2 // write Exif template
#define X3X3_EXIF_METADIR 3 // write metadata to Exif header translation (dir_table[MAX_EXIF_FIELDS])
// those 2 files will disable exif_enable and exif_valid, truncate file size to file pointer on release.
#define X3X3_EXIF_TIME 4 // write today/tomorrow date (YYYY:MM:DD) and number of seconds at today/tomorrow
// midnight (00:00:00) in seconds from epoch (long, startting from LSB)
// commands for the overloaded lseek:
//X3X3_EXIF_TIME
#define EXIF_LSEEK_DISABLE 1 // disable Exif (storing of frame meta, generating Exif)
#define EXIF_LSEEK_ENABLE 2 // enable Exif (build buffer if needed)
#define EXIF_LSEEK_INVALIDATE 3 // invalidate (and disable)
#define EXIF_LSEEK_REBUILD 4 // rebuild buffer
#define EXIF_LSEEK_TOMORROW_DATE 5 // file pointer to YYYY:MM:DD (tomorrow) string
#define EXIF_LSEEK_TOMORROW_SEC 6 // file pointer to unsigned long (little endian) tomorrow seconds from epoch
#define EXIF_LSEEK_TODAY_DATE 7 // file pointer to YYYY:MM:DD (today) string
#define EXIF_LSEEK_TODAY_SEC 8 // file pointer to unsigned long (little endian) today seconds from epoch
/*
Exif data in the images is combined from the "static" structure (template), calculated once at startup, and
variable data stored in the buffer for individual frames in the "Exif" form - converted to ASCII strings
or Rational or else. The generated Exif header copies that variable fileds on top of the Exif template.
The compressed data buffer is stored in "meta pages", one per frame
*/
struct exif_dir_table_t {
union {
unsigned long ltag;// tag group and tag combined
struct {
unsigned short tag_group; // tag group: 0 - IFD0, 1 - Exif, 2 - GPS
unsigned short tag; // Exif tag as defined in the standard
};
};
unsigned long len; // Number of bytes to be copied from metadata to Exif
unsigned long src; // offset in meta data page
unsigned long dst; // offset in output Exif page
};
#define MAX_EXIF_FIELDS 256 // number of Exif tags in the header
#define MAX_EXIF_SIZE 4096 // Exif data size
//#define MAX_EXIF_FRAMES 512 // number of frames in the buffer
#define MAX_EXIF_FRAMES 2048 // number of frames in the buffer
//Exif Tags - unsigned long, combining actual Exif tags with tag groups (0 - IFD0, 1 - Exif, 2 - GPS)
#define Exif_Image_ImageDescription 0x0010e
#define Exif_Image_Make 0x0010f
#define Exif_Image_Model 0x00110
#define Exif_Image_Software 0x00131
#define Exif_Image_DateTime 0x00132
#define Exif_Image_Artist 0x0013b
#define Exif_Image_HostComputer 0x0013c
#define Exif_Image_Orientation 0x00112
// hack, reusing field to keep it protected
#define Exif_Image_IPTCNAA 0x083bb
#define Exif_Image_FrameNumber 0x083bb
#define Exif_Image_ExifTag 0x08769
#define Exif_Image_GPSTag 0x08825
//Sub IFD
#define Exif_Photo_ExposureTime 0x1829a
#define Exif_Photo_DateTimeOriginal 0x19003
#define Exif_Photo_MakerNote 0x1927c
#define Exif_Photo_SubSecTime 0x19290
#define Exif_Photo_SubSecTimeOriginal 0x19291
//GPSInfo
#define Exif_GPSInfo_GPSLatitudeRef 0x20001
#define Exif_GPSInfo_GPSLatitude 0x20002
#define Exif_GPSInfo_GPSLongitudeRef 0x20003
#define Exif_GPSInfo_GPSLongitude 0x20004
#define Exif_GPSInfo_GPSAltitudeRef 0x20005
#define Exif_GPSInfo_GPSAltitude 0x20006
#define Exif_GPSInfo_GPSTimeStamp 0x20007
#define Exif_GPSInfo_GPSMeasureMode 0x2000a
#define Exif_GPSInfo_GPSDateStamp 0x2001D
/// used for compass module
#define Exif_GPSInfo_GPSImgDirectionRef 0x20010
#define Exif_GPSInfo_GPSImgDirection 0x20011
#define Exif_GPSInfo_GPSDestLatitudeRef 0x20013
#define Exif_GPSInfo_GPSDestLatitude 0x20014
#define Exif_GPSInfo_GPSDestLongitudeRef 0x20015
#define Exif_GPSInfo_GPSDestLongitude 0x20016
#define Exif_GPSInfo_CompassDirectionRef 0x20010
#define Exif_GPSInfo_CompassDirection 0x20011
#define Exif_GPSInfo_CompassPitchRef 0x20013
#define Exif_GPSInfo_CompassPitch 0x20014
#define Exif_GPSInfo_CompassRollRef 0x20015
#define Exif_GPSInfo_CompassRoll 0x20016
// array(0x9003,2,"2001:06:21 12:00:00","len"=> 20), //date/time original time created, always use 20 bytes (19 ."\0")
// array(0x9291,2,"0 ") //original time sub-second length=10 9 ."\0"
///move back to interframe_params_t?
struct frame_exif_t {
unsigned short meta_index; //! index of the linked meta page
unsigned short signffff; //! should be 0xffff - it will be a signature that JPEG data was not overwritten
unsigned long frame_length; //! frame length
};
struct meta_GPSInfo_t {
unsigned char GPSLatitudeRef; //"N"/"S"
unsigned long GPSLatitude_deg_nom;
unsigned long GPSLatitude_deg_denom;
unsigned long GPSLatitude_min_nom;
unsigned long GPSLatitude_min_denom;
unsigned char GPSLongitudeRef; //"E"/"W"
unsigned long GPSLongitude_deg_nom;
unsigned long GPSLongitude_deg_denom;
unsigned long GPSLongitude_min_nom;
unsigned long GPSLongitude_min_denom;
unsigned char GPSAltitudeRef; //byte, not ascii 0 - above sea level, 1 - below
unsigned long GPSAltitude_nom; //in meters
unsigned long GPSAltitude_denom;
unsigned long GPSTimeStamp_hrs_nom;
unsigned long GPSTimeStamp_hrs_denom;
unsigned long GPSTimeStamp_min_nom;
unsigned long GPSTimeStamp_min_denom;
unsigned long GPSTimeStamp_sec_nom;
unsigned long GPSTimeStamp_sec_denom;
unsigned char GPSDateStamp[11]; //includes '\0'
unsigned char GPSMeasureMode;
};
//hack - use
struct meta_CompassInfo_t {
// unsigned char GPSImgDirectionRef; //"M"/"T" //0x10
unsigned long CompassDirection_nom; //0x11
unsigned long CompassDirection_denom;
unsigned char CompassPitchRef; //"N"/"S"
unsigned long CompassPitch_nom;
unsigned long CompassPitch_denom;
unsigned char CompassRollRef; //"E"/"W"
unsigned long CompassRoll_nom;
unsigned long CompassRoll_denom;
};
#define EXIF_GPS_MIN_DENOM 10000
#define EXIF_GPS_METERS_DENOM 10
#define EXIF_GPS_TIMESEC_DENOM 1000
#define EXIF_GPS_COMPASS_DENOM 10
///hack!
#define EXIF_COMPASS_PITCH_ASCII "NS" // use for pitch +/-
#define EXIF_COMPASS_ROLL_ASCII "EW" // use for roll +/-
/// Exif data (variable, stored with each frame) used for KML (not only)
#define Exif_Image_ImageDescription_Index 0x00
#define Exif_Photo_DateTimeOriginal_Index 0x01
#define Exif_Photo_SubSecTimeOriginal_Index 0x02
#define Exif_Photo_ExposureTime_Index 0x03
#define Exif_GPSInfo_GPSLatitudeRef_Index 0x04
#define Exif_GPSInfo_GPSLatitude_Index 0x05
#define Exif_GPSInfo_GPSLongitudeRef_Index 0x06
#define Exif_GPSInfo_GPSLongitude_Index 0x07
#define Exif_GPSInfo_GPSAltitudeRef_Index 0x08
#define Exif_GPSInfo_GPSAltitude_Index 0x09
#define Exif_GPSInfo_GPSTimeStamp_Index 0x0a
#define Exif_GPSInfo_GPSDateStamp_Index 0x0b
#define Exif_GPSInfo_GPSMeasureMode_Index 0x0c
#define Exif_GPSInfo_CompassDirectionRef_Index 0x0d
#define Exif_GPSInfo_CompassDirection_Index 0x0e
#define Exif_GPSInfo_CompassPitchRef_Index 0x0f
#define Exif_GPSInfo_CompassPitch_Index 0x10
#define Exif_GPSInfo_CompassRollRef_Index 0x11
#define Exif_GPSInfo_CompassRoll_Index 0x12
#define Exif_Image_FrameNumber_Index 0x13
#define Exif_Image_Orientation_Index 0x14
#define Exif_Photo_MakerNote_Index 0x15
/// update ExifKmlNumber to be total number of *_Index entries
#define ExifKmlNumber Exif_Photo_MakerNote_Index+1
#define EXIF_DEV_NAME "/dev/exif_exif"
#define EXIFDIR_DEV_NAME "/dev/exif_metadir"
#define EXIFMETA_DEV_NAME "/dev/exif_meta"
#endif
elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/tests/ 0000775 0000000 0000000 00000000000 12753434647 0027750 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-1bd97ab88751639cc699387ef508e2b2defcfa8f/src/ext/elphel/tests/001.phpt 0000664 0000000 0000000 00000001035 12753434647 0031144 0 ustar 00root root 0000000 0000000 --TEST--
Check for elphel presence
--SKIPIF--
--FILE--
--EXPECT--
elphel extension is available