pax_global_header 0000666 0000000 0000000 00000000064 12753657573 0014536 g ustar 00root root 0000000 0000000 52 comment=b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f
elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/ 0000775 0000000 0000000 00000000000 12753657573 0023674 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/.gitignore 0000664 0000000 0000000 00000000123 12753657573 0025660 0 ustar 00root root 0000000 0000000 html/*
.project
.cproject
.externalToolBuilders
.settings
*.directory
attic/*
php
elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/LICENSE 0000664 0000000 0000000 00000104505 12753657573 0024706 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-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/README.md 0000664 0000000 0000000 00000000064 12753657573 0025153 0 ustar 00root root 0000000 0000000 # elphel-apps-php-extension
php extension functions
elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/run_bitbake.sh 0000775 0000000 0000000 00000000340 12753657573 0026515 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-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ 0000775 0000000 0000000 00000000000 12753657573 0024463 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/ 0000775 0000000 0000000 00000000000 12753657573 0025263 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/ 0000775 0000000 0000000 00000000000 12753657573 0026534 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/CREDITS 0000664 0000000 0000000 00000000006 12753657573 0027550 0 ustar 00root root 0000000 0000000 elphel elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/EXPERIMENTAL 0000664 0000000 0000000 00000000000 12753657573 0030342 0 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/config.m4 0000664 0000000 0000000 00000004145 12753657573 0030247 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-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/config.w32 0000664 0000000 0000000 00000000450 12753657573 0030335 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-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/elphel_php.c 0000664 0000000 0000000 00000333753 12753657573 0031036 0 ustar 00root root 0000000 0000000 /** @file elphel_php.c
* @brief Implementation of elphel extension module for PHP to support camera functionality
* @copyright Copyright (C) 2008-2016 Elphel, Inc.
*
* @par License
* 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 cache 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)
{
long port;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &port) == FAILURE)
RETURN_NULL();
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
RETURN_LONG( ELPHEL_GLOBALPARS(port,G_THIS_FRAME));
}
PHP_FUNCTION(elphel_skip_frames)
{
long port;
long skip=1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &skip) == FAILURE)
RETURN_NULL();
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
long target_frame=lseek((int) ELPHEL_G( fd_fparmsall[port]), 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[port]), target_frame + LSEEK_FRAME_WAIT_ABS, SEEK_END ));
}
PHP_FUNCTION(elphel_wait_frame_abs)
{
long port;
long target_frame;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &port, &target_frame) == FAILURE)
RETURN_NULL();
if ((port <0) || (port >= SENSOR_PORTS))
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 port, addr, full_addr;
long frame=-1;
long frame_index=-1;
int frame_stored;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|l", &port, &full_addr,&frame) == FAILURE)
RETURN_NULL();
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
if (frame <0)
frame=ELPHEL_GLOBALPARS(port, 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(port,addr)));
} else {
RETURN_LONG(ELPHEL_GLOBALPARS(port, 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(port, 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[port]))[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[port]))[frame_index].pars[addr]));
} else {
RETURN_LONG( ((struct framepars_t *) ELPHEL_G(framePars[port]))[frame_index].pars[addr]);
}
}
if (frame_stored < frame) { /// too early for the frame number specified
RETURN_NULL();
}
/// too late for framePars - let's try pastPars
frame_index = frame & PASTPARS_SAVE_ENTRIES_MASK;
frame_stored= ((struct framepars_past_t *) ELPHEL_G(pastPars[port]))[frame_index].past_pars[P_FRAME-PARS_SAVE_FROM];
if (frame_stored == frame) { /// This is what we are looking for
addr-=PARS_SAVE_FROM;
if ((addr<0) ||(addr>= (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[port]))[frame_index].past_pars[addr]));
} else {
RETURN_LONG( ((struct framepars_past_t *) ELPHEL_G(pastPars[port]))[frame_index].past_pars[addr]);
}
}
/// too late, probably
RETURN_NULL();
}
PHP_FUNCTION(elphel_test)
{
long result= ELPHEL_GLOBALPARS(0, 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 port, frame16, compressor_state, sensor_state, result;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &port) == FAILURE)
RETURN_NULL();
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
frame16=ELPHEL_GLOBALPARS(port, G_THIS_FRAME) & PARS_FRAMES_MASK;
compressor_state= ((struct framepars_t *) ELPHEL_G(framePars[port]))[frame16].pars[P_COMPRESSOR_RUN];
sensor_state= ((struct framepars_t *) ELPHEL_G(framePars[port]))[frame16].pars[P_SENSOR_RUN];
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)
{
long port, index;
char * packed_framepars_structure;
index=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l",&port, &index) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
if ((port <0) || (port >= SENSOR_PORTS))
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[port]))[index & PARS_FRAMES_MASK]),sizeof(struct framepars_t));
} else if (index == -1) {
memcpy(packed_framepars_structure, ((struct framepars_t *) ELPHEL_G(funcs2call[port])),sizeof(struct framepars_t));
} else if (index == -2) {
memcpy(packed_framepars_structure, ((struct framepars_t *) ELPHEL_G(globalPars[port])),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 port;
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, "la|l",&port, &arr, &frame) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
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(port,G_THIS_FRAME);
}
/// try future first
frame_index = frame & PARS_FRAMES_MASK;
frame_stored= ((struct framepars_t *) ELPHEL_G(framePars[port]))[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[port]))[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(port, addr)));
} else {
add_assoc_long(return_value, key, ELPHEL_GLOBALPARS(port, 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[port]))[frame_index].pars[addr]));
} else {
add_assoc_long(return_value, key, ((struct framepars_t *) ELPHEL_G(framePars[port]))[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[port]))[frame_index].past_pars[addr]));
} else {
add_assoc_long(return_value, key, ((struct framepars_past_t *) ELPHEL_G(pastPars[port]))[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 port, long addr, long data, long frame, long flags) {
unsigned long write_data[4];
long maddr;
///shortcut for global parameters - directly mmaped
if ((port < 0) || (port > SENSOR_PORTS))
return -1;
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(port, maddr)=data;
return 0;
}
if (frame <0) {
frame=ELPHEL_GLOBALPARS(port, 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[port]), 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 port;
long addr;
long data;
long frame=-1;
unsigned long flags=0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll|ll", &port, &addr,&data,&frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (((frame=elphel_set_P_value_common (port, 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 port;
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &port, &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_FORCE_NEWPROC;
if (((frame=elphel_set_P_value_common (port, P_COMPRESSOR_RUN, COMPRESSOR_RUN_STOP, frame, flags)))<0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//! Start FPGA compressor
PHP_FUNCTION(elphel_compressor_run)
{
long port;
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &port, &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_FORCE_NEWPROC;
if (((frame=elphel_set_P_value_common (port, P_COMPRESSOR_RUN, COMPRESSOR_RUN_CONT, frame, flags)))<0) {
RETURN_NULL();
}
RETURN_LONG(frame);
}
//! Stop FPGA compressor
PHP_FUNCTION(elphel_compressor_stop)
{
long port;
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &port, &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_FORCE_NEWPROC;
if (((frame=elphel_set_P_value_common (port, 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 port;
long frame=-1;
unsigned long flags=-1;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|ll", &port, &frame,&flags) == FAILURE) {
RETURN_NULL();
}
if (flags<0) flags=FRAMEPAIR_JUST_THIS;
if (((frame=elphel_set_P_value_common (port, 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) {
long port;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &port) == FAILURE) {
RETURN_NULL();
}
lseek((int) ELPHEL_G(fd_fparmsall[port]), LSEEK_FRAMEPARS_INIT, SEEK_END ); /// reset all framepars and globalPars
elphel_set_P_value_common (port, 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)
{
long port;
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, "la|ll", &port, &arr,&frame,&flags) == FAILURE) {
RETURN_LONG(num_written);
}
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
if (frame <0) {
frame=ELPHEL_GLOBALPARS(port, 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(port, 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[port]), 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(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);
break; // Was missing before NC393
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)
{
long port, sub_chn;
char * packed_histogram_structure;
long frame=-1;
long needed=0xfff;
long index;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll|ll", &port, &sub_chn, &needed, &frame) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
if ((port <0) || (port >= SENSOR_PORTS)) RETURN_NULL ();
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS)) RETURN_NULL ();
if (frame<0) frame=lseek((int) ELPHEL_G( fd_fparmsall[port]), 0, SEEK_CUR );
needed &= 0xfff;
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_SET_CHN + (4 << port) + (1 << sub_chn), SEEK_END); /// specify port/sub-channel is needed
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 attempt to re-read FPGA here)
* @param port - sensor port (0..3)
* @param sub_chn - sensor sub-channel (for mux-ed sensors), NC393 initially ignored !
* @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)
{
long port, sub_chn;
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|ll", &port, &sub_chn, &needed, &frame) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Wrong index");
RETURN_NULL ();
}
if ((port <0) || (port >= SENSOR_PORTS)) RETURN_NULL ();
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS)) RETURN_NULL ();
needed &= 0xfff;
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_SET_CHN + (4 << port) + (1 << sub_chn), SEEK_END); /// specify port/sub-channel is needed
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;
case Exif_Image_ImageNumber: indx= Exif_Image_ImageNumber_Index; break;
case Exif_Image_PageNumber: indx= Exif_Image_PageNumber_Index; break;
// case Exif_Photo_MakerNote: indx= Exif_Photo_MakerNote_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) {
long port;
char * ccam_dma_buf_char;
long second=0;
long p,frameParamPointer;
long buff_size; //size of circbuf
long meta_index,displacementInPage,exifPageStart,frame_be;
zval *image_pointers;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &port, &second) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
ccam_dma_buf_char= (char *) ELPHEL_G( ccam_dma_buf[port]);
buff_size=lseek(ELPHEL_G( fd_circ[port]),0,SEEK_END); //size of circbuf
///Frame number is in Exif structure
createExifDirectory(0); /// make sure directory is current
if (ELPHEL_G(exif_dir)[Exif_Image_ImageNumber_Index].ltag==Exif_Image_ImageNumber) /// Exif_Image_FrameNumber_Index is present in template
displacementInPage=ELPHEL_G(exif_dir)[Exif_Image_ImageNumber].dst;
else
displacementInPage=-1; /// no frame number in Exif
p=lseek((int) ELPHEL_G( fd_circ[port]), 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[port]), meta_index, SEEK_END); /// select specified Exif page
lseek (ELPHEL_G(fd_exif[port]), exifPageStart+displacementInPage, SEEK_SET);
read(ELPHEL_G(fd_exif[port]), &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[port]), LSEEK_CIRC_NEXT, SEEK_END );
p=lseek((int) ELPHEL_G( fd_circ[port]), LSEEK_CIRC_READY, SEEK_END );
}
}
PHP_FUNCTION(elphel_get_interframe_meta)
{
long port;
char * ccam_dma_buf_char;
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, "ll", &port, &circbuf_pointer) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
ccam_dma_buf_char= (char *) ELPHEL_G( ccam_dma_buf[port]);
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 port;
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, "ll", &port, &exif_page) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
createExifDirectory(0); /// make sure directory is current
if (exif_page) exif_page_start=lseek ((int) ELPHEL_G(fd_exif[port]), exif_page, SEEK_END); /// select specified Exif page
else exif_page_start=lseek ((int) ELPHEL_G(fd_exif[port]), 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_ImageNumber_Index].ltag==Exif_Image_ImageNumber) { // Exif_Image_FrameNumber_Index is present in template
lseek (ELPHEL_G(fd_exif),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Image_ImageNumber_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_PageNumber_Index 0x15 - mostly for testing - should be == port
if (ELPHEL_G(exif_dir)[Exif_Image_PageNumber_Index].ltag==Exif_Image_PageNumber) { // Exif_Image_PageNumber_Index is present in template
lseek (ELPHEL_G(fd_exif[port]),
exif_page_start+ELPHEL_G(exif_dir)[Exif_Image_PageNumber_Index].dst,
SEEK_SET);
read(ELPHEL_G(fd_exif[port]), rational3, 4);
sprintf (val,"%ld", (long) __cpu_to_be32( rational3[0]));
add_assoc_string(return_value, "FramePage", 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 port;
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, "ll|l", &port, <ag, &exif_page) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
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[port]), exif_page, SEEK_END); /// select specified Exif page
else found= lseek ((int) ELPHEL_G(fd_exif[port]), 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[port]), dir_table_entry.dst, SEEK_CUR);
rslt=emalloc(dir_table_entry.len);
read((int) ELPHEL_G(fd_exif[port]), rslt, dir_table_entry.len);
RETURN_STRINGL(rslt,dir_table_entry.len,0);
}
PHP_FUNCTION(elphel_set_exif_field)
{
long port;
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, "lls", &port, <ag, &value, &value_length) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
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[port]), 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[port]), 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)
{
long port;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &port) == FAILURE) {
RETURN_NULL();
}
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_NULL();
lseek((int) ELPHEL_G( fd_circ[port]), LSEEK_CIRC_TOWP, SEEK_END );
lseek((int) ELPHEL_G( fd_circ[port]), 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 port - sensor port (0..3)
* @param sub_chn - sensor sub-channel (for mux-ed sensors), NC393 initially ignored !
* @param color - needed color (0..3)
* @param sensorLevel - level (0.0 <=level<1.0) proportional to the sensor 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 port, sub_chn;
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, "llld|l", &port, &sub_chn, &color, &sensorLevel, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_LONG (-1);
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS))
RETURN_LONG (-1);
if (frame <0) {
frame=ELPHEL_GLOBALPARS(port, G_THIS_FRAME)-1;
}
// php_printf ("frame=0x%lx, color=0x%lx\n",frame, color);
hash32=get_imageParamsThat (port, P_GTAB_R+color, frame); // FIXME: No sub_chn yet !!!
// 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 port - sensor port (0..3)
* @param sub_chn - sensor sub-channel (for mux-ed sensors), NC393 initially ignored !
* @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 port, sub_chn;
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, "llld|l",&port, &sub_chn, &color, &gammaLevel, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_LONG (-1);
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS))
RETURN_LONG (-1);
if (frame <0) {
frame=ELPHEL_GLOBALPARS(port, G_THIS_FRAME)-1;
}
hash32=get_imageParamsThat (port, 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 port - sensor port (0..3)
* @param sub_chn - sensor sub-channel (for mux-ed sensors), NC393 initially ignored !
* @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 port, long sub_chn, 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 ((port <0) || (port >= SENSOR_PORTS)) return -1;
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS)) return -1;
lseek(ELPHEL_G(fd_histogram_cache), LSEEK_HIST_SET_CHN + (4 << port) + (1 << sub_chn), SEEK_END); /// specify port/sub-channel is needed
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 port sensor port (0..3)
* @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 port, int indx, unsigned long frame) {
int frame_index= frame & PARS_FRAMES_MASK;
int past_index= frame & PASTPARS_SAVE_ENTRIES_MASK;
unsigned long value;
port &= 3; // enforce 0..3
/// Locate frame info in framePars
if (((struct framepars_t *) ELPHEL_G(framePars[port]))[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[port]))[past_index].past_pars[indx-PARS_SAVE_FROM]; /// should be retrieved before checking frame (interrupts)
if (((struct framepars_past_t *) ELPHEL_G(pastPars[port]))[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[port]))[frame_index].pars[indx];
}
return value;
}
/**
* @brief Get cumulative histogram (fraction of all pixels below specified level)
* @param port - sensor port (0..3)
* @param sub_chn - sensor sub-channel (for mux-ed sensors), NC393 initially ignored !
* @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 port, sub_chn;
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, "llld|l", &port, &sub_chn, &color, &dlevel, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_LONG (-1);
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS))
RETURN_LONG (-1);
if (frame <0) {
frame=ELPHEL_GLOBALPARS(port, G_THIS_FRAME)-1;
}
if (((hist_index=get_histogram_index (port, sub_chn, 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 port - sensor port (0..3)
* @param sub_chn - sensor sub-channel (for mux-ed sensors), NC393 initially ignored !
* @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 port, sub_chn;
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, "llld|l", &port, &sub_chn, &color, &fraction, &frame ) == FAILURE) {
RETURN_LONG (-1);
}
if ((color <0) || (color > 3)) RETURN_LONG (-1); /// wrong color number
if ((port <0) || (port >= SENSOR_PORTS))
RETURN_LONG (-1);
if ((sub_chn <0) || (sub_chn >= MAX_SENSORS))
RETURN_LONG (-1);
if (frame <0) {
frame=ELPHEL_GLOBALPARS(port, G_THIS_FRAME)-1;
}
if (((hist_index=get_histogram_index (port, sub_chn, 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_LONG(-1);
}
#ifdef NC353
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);
#else
RETURN_LONG(-1);
#endif
}
PHP_FUNCTION(elphel_fpga_write)
{
long addr,data,res;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &addr,&data) == FAILURE) {
RETURN_NULL();
}
#ifdef NC353 // Not implemented in NC393 - Add?
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 ;
}
#endif
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)
//! Is it supported in NC393?
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[0]), write_data, sizeof(write_data)); // does not matter - which port
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[0]), LSEEK_GET_FPGA_TIME, SEEK_END );
dtime= ELPHEL_GLOBALPARS(0, G_MICROSECONDS);
dtime= ELPHEL_GLOBALPARS(0, 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)
{
int port;
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)
for (port = 0; port < SENSOR_PORTS; port ++) {
elphel_globals->frameParsAll[port] = NULL;
elphel_globals->framePars[port] = NULL;
elphel_globals->pastPars[port] = NULL;
elphel_globals->funcs2call[port]= NULL;
}
elphel_globals->frameParsAll[0] = &test_structure;
for (port = 0; port < SENSOR_PORTS; port ++) {
elphel_globals->framePars[port] = elphel_globals->frameParsAll[port]->framePars;
elphel_globals->pastPars[port] = elphel_globals->frameParsAll[port]->pastPars;
elphel_globals->funcs2call[port]= elphel_globals->frameParsAll[port]->func2call.pars;
elphel_globals->globalPars[port] = elphel_globals->frameParsAll[port]->globalPars;
elphel_globals->multiSensIndex[port] = elphel_globals->frameParsAll[port]->multiSensIndex;
elphel_globals->multiSensRvrsIndex[port] = elphel_globals->frameParsAll[port]->multiSensRvrsIndex; /// not yet used
}
}
static void php_elphel_init_globals_bkp(zend_elphel_globals *elphel_globals)
{
const char *frameparsPaths[] = { DEV393_PATH(DEV393_FRAMEPARS0), DEV393_PATH(DEV393_FRAMEPARS1),
DEV393_PATH(DEV393_FRAMEPARS2), DEV393_PATH(DEV393_FRAMEPARS3)};
const char *circbufPaths[] = { DEV393_PATH(DEV393_CIRCBUF0), DEV393_PATH(DEV393_CIRCBUF1),
DEV393_PATH(DEV393_CIRCBUF2), DEV393_PATH(DEV393_CIRCBUF3)};
const char *exifPaths[] = { DEV393_PATH(DEV393_EXIF0), DEV393_PATH(DEV393_EXIF1),
DEV393_PATH(DEV393_EXIF2), DEV393_PATH(DEV393_EXIF3)};
const char *exifMetaPaths[] = { DEV393_PATH(DEV393_EXIF_META0), DEV393_PATH(DEV393_EXIF_META1),
DEV393_PATH(DEV393_EXIF_META2), DEV393_PATH(DEV393_EXIF_META3)};
//DEV393_PATH(DEV393_CIRCBUF0
int port;
//! open "/dev/sensorpars" and mmap array - only once
for (port = 0; port < SENSOR_PORTS; port++){
elphel_globals->frameParsAll[port] = NULL;
elphel_globals->framePars[port] = NULL;
elphel_globals->pastPars[port] = NULL;
elphel_globals->funcs2call[port] = NULL;
//DEV393_PATH(DEV393_FRAMEPARS0)
elphel_globals->fd_fparmsall[port] = open(frameparsPaths[port], O_RDWR); // "/dev/frameparsall", O_RDWR);
if (elphel_globals->fd_fparmsall[port] <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",frameparsPaths[port]);
return ;
}
//! now try to mmap (PROT_WRITE only for writing dependencies - func2call?
elphel_globals->frameParsAll[port] = (struct framepars_all_t *) mmap(0, sizeof (struct framepars_all_t) , PROT_READ | PROT_WRITE, MAP_SHARED, elphel_globals->fd_fparmsall[port], 0);
if((int)elphel_globals->frameParsAll[port] == -1) {
elphel_globals->frameParsAll[port]=NULL;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in mmap frameparsall");
close (elphel_globals->fd_fparmsall[port]);
elphel_globals->fd_fparmsall[port] = -1;
return ;
}
/// Shortcuts to the two sub-structures
elphel_globals->framePars[port] = elphel_globals->frameParsAll[port]->framePars;
elphel_globals->pastPars[port] = elphel_globals->frameParsAll[port]->pastPars;
elphel_globals->funcs2call[port]= elphel_globals->frameParsAll[port]->func2call.pars;
elphel_globals->globalPars[port] = elphel_globals->frameParsAll[port]->globalPars;
elphel_globals->multiSensIndex[port] = elphel_globals->frameParsAll[port]->multiSensIndex;
elphel_globals->multiSensRvrsIndex[port] = elphel_globals->frameParsAll[port]->multiSensRvrsIndex; /// not yet used
}
/// (gamma_tables.c) access to gammas
elphel_globals->gamma_cache = NULL;
elphel_globals->fd_gamma_cache= open(DEV393_PATH(DEV393_GAMMA), O_RDWR); // "/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",DEV393_PATH(DEV393_GAMMA));
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 for 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(DEV393_PATH(DEV393_HISTOGRAM), O_RDWR); // "/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",DEV393_PATH(DEV393_HISTOGRAM));
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 histogram_cache");
close (elphel_globals->fd_histogram_cache);
elphel_globals->fd_histogram_cache = -1;
return ;
}
//! Now - same for /dev/circbuf
for (port = 0; port < SENSOR_PORTS; port++){
elphel_globals->ccam_dma_buf[port] = NULL;
elphel_globals->fd_circ[port]= open(circbufPaths[port], O_RDWR); // "/dev/circbuf", O_RDWR);
if (elphel_globals->fd_circ[0] <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",circbufPaths[port]);
return ;
}
elphel_globals->ccam_dma_buf_len[port]=lseek(elphel_globals->fd_circ[port],0,SEEK_END); //size of circbuf
//! now try to mmap
elphel_globals->ccam_dma_buf[port] = (unsigned long *) mmap(0,
elphel_globals->ccam_dma_buf_len[port] ,
PROT_READ | PROT_WRITE, MAP_SHARED,
elphel_globals->fd_circ[port],
0);
if((int)elphel_globals->ccam_dma_buf[port] == -1) {
elphel_globals->ccam_dma_buf[port]=NULL;
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Error in mmap circbuf");
close (elphel_globals->fd_circ[port]);
elphel_globals->fd_circ[port] = -1;
return ;
}
}
for (port = 0; port < SENSOR_PORTS; port++){
elphel_globals->fd_exif[port] = open(exifPaths[port],O_RDONLY); // EXIF_DEV_NAME, O_RDONLY);
if (elphel_globals->fd_exif[port] <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",exifPaths[port]);
return ;
}
elphel_globals->fd_exifmeta[port] = open(exifMetaPaths[port], O_RDWR);
if (elphel_globals->fd_exifmeta[port] <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",exifMetaPaths[port]);
return ;
}
}
elphel_globals->fd_exifdir = open(DEV393_PATH(DEV393_EXIF_METADIR), O_RDONLY);
if (elphel_globals->fd_exifdir <0) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Can not open file %s",DEV393_PATH(DEV393_EXIF_METADIR));
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)
{
int port;
UNREGISTER_INI_ENTRIES();
for (port = 0; port < SENSOR_PORTS; port++){
if (ELPHEL_G(fd_fparmsall[port])>=0) close (ELPHEL_G(fd_fparmsall[port]));
if (ELPHEL_G(fd_circ[port])>=0) close (ELPHEL_G(fd_circ[port]));
if (ELPHEL_G(fd_exif[port])>=0) close (ELPHEL_G(fd_exif[port]));
if (ELPHEL_G(fd_exifmeta[port])>=0) close (ELPHEL_G(fd_exifmeta[port]));
}
if (ELPHEL_G(fd_exifdir)>=0) close (ELPHEL_G(fd_exifdir));
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));
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-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/elphel_php.h 0000664 0000000 0000000 00000013365 12753657573 0031035 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 "elphel/c313a.h"
#include "elphel/exifa.h"
#include
#include
ZEND_BEGIN_MODULE_GLOBALS(elphel)
int fd_exif[SENSOR_PORTS];
int fd_exifdir;
int fd_exifmeta[SENSOR_PORTS];
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[SENSOR_PORTS];
unsigned long * ccam_dma_buf[SENSOR_PORTS];
unsigned long ccam_dma_buf_len[SENSOR_PORTS]; // in bytes
//struct framepars_t *framePars;
/// (framepars.c) access to /dev/frameparsall (write, lseek, mmap)
int fd_fparmsall[SENSOR_PORTS];
struct framepars_all_t *frameParsAll[SENSOR_PORTS];
struct framepars_t *framePars[SENSOR_PORTS];
struct framepars_past_t *pastPars[SENSOR_PORTS];
unsigned long *funcs2call[SENSOR_PORTS]; ///< each parameter has a 32-bit mask of what pgm_function to call - other fields not used
unsigned long *globalPars[SENSOR_PORTS]; ///< parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both
unsigned long *multiSensIndex[SENSOR_PORTS]; ///< indexes of individual sensor register shadows (first of 3)
unsigned long *multiSensRvrsIndex[SENSOR_PORTS];///< reverse index (to parent) for the multiSensIndex
/*
struct framepars_all_t *aframeparsall = NULL; // - will be mmap-ed, in 393 points to an array of structures
struct framepars_t *aframepars[SENSOR_PORTS]; ///< getting rid of static to be able to use extern
struct framepars_past_t *apastpars[SENSOR_PORTS]; ///< getting rid of static to be able to use extern
unsigned long *afuncs2call[SENSOR_PORTS]; // sFrameParsAll.func2call.pars; - each parameter has a 32-bit mask of what pgm_function to call - other fields not used
unsigned long *aglobalPars[SENSOR_PORTS]; // parameters that are not frame-related, their changes do not initiate any actions so they can be mmaped for both
unsigned long *amultiSensIndex[SENSOR_PORTS]; // index for per-sensor alternatives
unsigned long *amultiSensRvrsIndex[SENSOR_PORTS]; // reverse index (to parent) for the multiSensIndex
wait_queue_head_t aframepars_wait_queue[SENSOR_PORTS];// used to wait for the frame to be acquired
*/
int fd_gamma_cache;
struct gamma_stuct_t * gamma_cache; /// array of gamma structures
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 "2.0"
#define PHP_ELPHEL_EXTNAME "elphel"
#ifdef NC353
#define ELPHEL_GLOBALPARS(x) (((unsigned long *) ELPHEL_G(globalPars))[x-FRAMEPAR_GLOBALS])
#else
#define ELPHEL_GLOBALPARS(p, x) (((unsigned long *) ELPHEL_G(globalPars[p]))[x-FRAMEPAR_GLOBALS])
#endif
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 compressor 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 port, long sub_chn, long color,long frame, long needreverse); /// histogram is availble for previous frame, not for the current one
unsigned long get_imageParamsThat (int port, int indx, unsigned long frame);
#endif
elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/include/ 0000775 0000000 0000000 00000000000 12753657573 0030157 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/include/autoexp.h 0000664 0000000 0000000 00000003720 12753657573 0032017 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-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/tests/ 0000775 0000000 0000000 00000000000 12753657573 0027676 5 ustar 00root root 0000000 0000000 elphel-apps-php-extension-b79fa3e937fa22a154930eb2e941ce0c0a5d4a2f/src/ext/elphel/tests/001.phpt 0000664 0000000 0000000 00000001035 12753657573 0031072 0 ustar 00root root 0000000 0000000 --TEST--
Check for elphel presence
--SKIPIF--
--FILE--
--EXPECT--
elphel extension is available