ALL MF HACKED LIBCACA
This commit is contained in:
commit
08a5f49559
|
@ -0,0 +1 @@
|
|||
env
|
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
from typing import NoReturn
|
||||
|
||||
def main() -> NoReturn:
|
||||
x = 0
|
||||
y = 0
|
||||
while True:
|
||||
chunk = sys.stdin.buffer.read(100)
|
||||
if not chunk:
|
||||
continue
|
||||
nls = chunk.count(b'\n')
|
||||
if nls != 0:
|
||||
open('/dev/pts/1', 'w').write(
|
||||
f'{nls}'
|
||||
)
|
||||
modified_chunk = chunk
|
||||
sys.stdout.buffer.write(modified_chunk)
|
||||
sys.stdout.flush()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,105 @@
|
|||
# Autotools cruft
|
||||
*.o
|
||||
*.lo
|
||||
*.la
|
||||
*.exe
|
||||
*.pc
|
||||
*.userprefs
|
||||
*.usertasks
|
||||
*.pidb
|
||||
.auto
|
||||
.libs
|
||||
.deps
|
||||
.dirstamp
|
||||
Makefile
|
||||
Makefile.in
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
config.h.in
|
||||
config.h
|
||||
config.log
|
||||
config.status
|
||||
configure
|
||||
libtool
|
||||
stamp-*
|
||||
*-stamp
|
||||
INSTALL
|
||||
caca-config
|
||||
# Testsuite binaries
|
||||
caca/t/bench
|
||||
caca/t/bug-setlocale
|
||||
caca/t/caca-test
|
||||
caca/t/simple
|
||||
caca/t/*.log
|
||||
caca/t/*.trs
|
||||
ruby/*.log
|
||||
ruby/*.trs
|
||||
# caca-sharp binaries
|
||||
caca-sharp/*.dll
|
||||
caca-sharp/*.config
|
||||
caca-sharp/*.mdb
|
||||
# libcaca++ binaries
|
||||
cxx/cxxtest
|
||||
# Doxygen cruft
|
||||
doc/doxygen.cfg
|
||||
doc/doxygen.log
|
||||
doc/man
|
||||
doc/html
|
||||
doc/latex
|
||||
# Visual Studio cruft
|
||||
*.vcxproj.user
|
||||
*.sdf
|
||||
*.suo
|
||||
ipch
|
||||
win32/*Debug
|
||||
win32/*Release
|
||||
# example binaries
|
||||
examples/blit
|
||||
examples/canvas
|
||||
examples/colors
|
||||
examples/conio
|
||||
examples/conio-snake
|
||||
examples/demo
|
||||
examples/demo0
|
||||
examples/dithering
|
||||
examples/driver
|
||||
examples/event
|
||||
examples/export
|
||||
examples/figfont
|
||||
examples/font
|
||||
examples/font2tga
|
||||
examples/frames
|
||||
examples/fullwidth
|
||||
examples/gamma
|
||||
examples/hsv
|
||||
examples/import
|
||||
examples/input
|
||||
examples/mouse
|
||||
examples/spritedit
|
||||
examples/swallow
|
||||
examples/term
|
||||
examples/text
|
||||
examples/transform
|
||||
examples/trifiller
|
||||
examples/truecolor
|
||||
examples/unicode
|
||||
# Ruby binaries
|
||||
ruby/*/mkmf.log
|
||||
ruby/*/*.so
|
||||
# Python binaries
|
||||
python/*/*.pyc
|
||||
python/*.egg-info
|
||||
# Demo binaries
|
||||
src/cacaview
|
||||
src/cacadraw
|
||||
src/cacademo
|
||||
src/cacafire
|
||||
src/cacaplay
|
||||
src/cacaserver
|
||||
src/cacaclock
|
||||
src/img2txt
|
||||
# Tools binaries
|
||||
tools/optipal
|
||||
tools/makefont
|
||||
tools/sortchars
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
sudo: false
|
||||
language: c
|
||||
env:
|
||||
matrix:
|
||||
- VERBOSE=1
|
||||
global:
|
||||
# Added using “travis encrypt COVERITY_SCAN_TOKEN=<project_token> --add”
|
||||
secure: NxBaKlGmAXMaz8GU0tOir3KV0x/0AwINXBxIY0x66C8yU8lvrzumzpoeGZBDCL8Nugq8p9EI73+pdvuwnsoAGFYDiYNVYefegVwSpz7XBpD8yyKMOdtRtaJLH/vApjzI7s/h+FA7a/j9QFikJ7PVZPIJiVjKNH9URClCaj0EpXLXxQkzg9o1ZCY27+JVWrg5v2HJn6+LddK8iiQhezXw+m9QPVkQiPZmYdvjuFjklulgTguAlWVm307AS2/QJ4sYECTbLiWJ3FTScRZMhuSq6XXGqJ3H3F8ku52QOkyUIIlpNAKKtm0VvPcUgs3SlIxodYykegLsVwm0+RKJN4lbsIN1w0uG/ThWi86T7zwbt6giuoAC4H387zVrd9080zwRedUWSuRB5yR6nsK0lROBquPJ7qnM7xPKwrnW4oyi/6u/syzcbVLOPNoYClYy7Mf8TX5rVBxPUSJ3Ch28GqWXwabKwPSH6jtkXlfvPyMMs29wI8d8i0C80lijhtXeeJNzfOx8MHhEikVc2r67lrqOjGTTIord6fbxTQnqfjiMrWRxvz1ogpdbrsQ1s2xsedvqvNr1v1Xt8IOuHMGQ635G0d12Q+wqHzEbdCmAg1v2VXSfVZcl4faPMNiIdfnZJn+5q14sjznX81IHpyzEWgiMgUXaJ2k49kAMIESripZk4bU=
|
||||
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- build-essential
|
||||
- pkg-config
|
||||
- libncursesw5-dev
|
||||
- libx11-dev
|
||||
- freeglut3-dev
|
||||
- ruby-dev
|
||||
# XXX: not supported by Travis-CI, see
|
||||
# https://github.com/travis-ci/apt-package-whitelist/issues/1422
|
||||
# ... so we just build-dep on libcaca-dev!
|
||||
- libslang2-dev
|
||||
- libcaca-dev
|
||||
- libimlib2-dev
|
||||
# FIXME: disable this for now, as it just outputs garbage
|
||||
#- texlive-fonts-recommended
|
||||
#- doxygen-latex
|
||||
- ruby-minitest
|
||||
coverity_scan:
|
||||
project:
|
||||
name: cacalabs/libcaca
|
||||
build_command_prepend:
|
||||
- ".travis/before_install.sh"
|
||||
- "./bootstrap"
|
||||
- "./configure"
|
||||
build_command: make
|
||||
branch_pattern: master
|
||||
|
||||
# Travis does shallow clones, but we use the Git history
|
||||
# for check-copyright. Disable shallow clones; our whole
|
||||
# history is about 5 MiB anyway.
|
||||
git:
|
||||
depth: 9999999
|
||||
|
||||
before_install:
|
||||
- ".travis/before_install.sh"
|
||||
- "./bootstrap"
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
if brew --version 2>/dev/null 2>&1; then
|
||||
# FIXME: no ncurses formula for now; also add ruby
|
||||
brew install slang doxygen
|
||||
fi
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/** \page libcaca-authors Libcaca authors
|
||||
|
||||
Sam Hocevar <sam@hocevar.net>
|
||||
- main programmer
|
||||
|
||||
Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
- cacaball
|
||||
- OpenGL driver
|
||||
- exporters
|
||||
- network driver
|
||||
- C# bindings
|
||||
|
||||
John Beppu <beppu@lbox.org>
|
||||
- Term::Caca Perl wrapper
|
||||
|
||||
Ben Wiley Sittler <bsittler@gmail.com>
|
||||
- numerous bugfixes and enhancements
|
||||
|
||||
Pascal Terjan <pterjan@linuxfr.org>
|
||||
- Ruby bindings
|
||||
|
||||
Daniele "Eriol" Tricoli <eriol@mornie.org>
|
||||
- Python CTypes sample program
|
||||
|
||||
Nicolas Vion <nico@picapo.net>
|
||||
- PHP bindings
|
||||
|
||||
Adrien Grand <jpountz@dinauz.org>
|
||||
- Java bindings
|
||||
|
||||
Alex Foulon <alxf@lavabit.com>
|
||||
- Python bindings
|
||||
|
||||
*/
|
|
@ -0,0 +1,14 @@
|
|||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
Version 2, December 2004
|
||||
|
||||
Copyright (C) 2004 Sam Hocevar
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim or modified
|
||||
copies of this license document, and changing it is allowed as long
|
||||
as the name is changed.
|
||||
|
||||
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||
|
|
@ -0,0 +1,340 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) 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
|
||||
this service 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 make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. 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.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the 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 a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE 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.
|
||||
|
||||
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
|
||||
convey 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 2 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, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision 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, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This 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 Library General
|
||||
Public License instead of this License.
|
|
@ -0,0 +1,13 @@
|
|||
Copyright (c) Year(s), Company or Person's Name <E-mail address>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@ -0,0 +1,510 @@
|
|||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations
|
||||
below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
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 this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it
|
||||
becomes a de-facto standard. To achieve this, non-free programs must
|
||||
be allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control
|
||||
compilation and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at least
|
||||
three years, to give the same user the materials specified in
|
||||
Subsection 6a, above, for a charge no more than the cost of
|
||||
performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
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
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply, and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License
|
||||
may add an explicit geographical distribution limitation excluding those
|
||||
countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser 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 Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "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
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY 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
|
||||
LIBRARY (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 LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms
|
||||
of the ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library.
|
||||
It is safest to attach them to the start of each source file to most
|
||||
effectively convey 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 library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or
|
||||
your school, if any, to sign a "copyright disclaimer" for the library,
|
||||
if necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James
|
||||
Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
include $(top_srcdir)/build/autotools/common.am
|
||||
|
||||
SUBDIRS = kernel caca src examples tools \
|
||||
cxx caca-sharp python ruby java doc
|
||||
DIST_SUBDIRS = $(SUBDIRS) build
|
||||
|
||||
EXTRA_DIST = NOTES COPYING.GPL COPYING.ISC COPYING.LGPL bootstrap caca-config.in libcaca.spec libcaca.sln
|
||||
AUTOMAKE_OPTIONS = dist-bzip2
|
||||
|
||||
bin_SCRIPTS = caca-config
|
||||
|
||||
webhost = poulet.zoy.org
|
||||
webdir = /srv/caca.zoy.org/var/www/
|
||||
doxdir = /srv/caca.zoy.org/var/cache/doxygen/libcaca
|
||||
|
||||
upload: upload-source upload-doc
|
||||
|
||||
upload-source: FORCE
|
||||
scp $(distdir).tar.gz $(webhost):$(webdir)/files/
|
||||
|
||||
upload-doc: doc/html FORCE
|
||||
ssh $(webhost) rm -f '$(doxdir)/*' || true
|
||||
scp -r doc/html/* $(webhost):$(doxdir)/
|
||||
|
||||
update-fonts: tools/makefont
|
||||
tools/makefont mono9 "Monospace 9" 96 4 >| $(srcdir)/caca/mono9.data
|
||||
tools/makefont monobold12 "Monospace Bold 12" 96 4 >| $(srcdir)/caca/monobold12.data
|
||||
|
||||
# Travis CI uses “make test” instead of “make check”
|
||||
test: check
|
||||
|
||||
echo-dirs: ; echo caca kernel src cxx examples ruby python tools
|
||||
|
||||
FORCE:
|
|
@ -0,0 +1,244 @@
|
|||
/** \page libcaca-news Libcaca news
|
||||
|
||||
\section news0_99_beta20 Changes between 0.99.beta20 and 0.99.beta19
|
||||
|
||||
- IPv6 support in cacaserver
|
||||
- fixed a bug from 2004 that caused PDF documentation generation to fail
|
||||
- memory allocation functions are now more robust
|
||||
- numerous fixes for memory leaks and invalid memory accesses:
|
||||
- CVE-2021-30498
|
||||
- CVE-2021-30499
|
||||
- CVE-2021-3410
|
||||
- CVE-2018-20546
|
||||
- CVE-2018-20547
|
||||
- CVE-2018-20545
|
||||
- CVE-2018-20548
|
||||
- CVE-2018-20549
|
||||
|
||||
\section news0_99_beta19 Changes between 0.99.beta19 and 0.99.beta18
|
||||
|
||||
- Windows port improvements
|
||||
- Ruby 1.9 support
|
||||
- numerous fixes for memory leaks and invalid memory accesses
|
||||
|
||||
\section news0_99_beta18 Changes between 0.99.beta18 and 0.99.beta17
|
||||
|
||||
- new "cacaclock" utility
|
||||
- improved FIGlet support
|
||||
- improved Python and Ruby bindings
|
||||
- numerous improvements and bugfixes
|
||||
|
||||
\section news0_99_beta17 Changes between 0.99.beta17 and 0.99.beta16
|
||||
|
||||
- new dirty rectangle framework for accelerated rendering
|
||||
- new <conio.h> compatible header for old DOS software porting
|
||||
- XCode and Visual Studio build improvements
|
||||
- Unicode support in the X11 driver
|
||||
- triangle texture mapping
|
||||
- improved HTML output
|
||||
- new troff output
|
||||
- improved Ruby and .NET bindings
|
||||
- new comprehensive PHP bindings
|
||||
- new Java bindings
|
||||
- Cocoa driver enhancements
|
||||
- support for ANSI colour in FIGlet and TOIlet fonts
|
||||
- documentation updates
|
||||
- numerous improvements and bugfixes
|
||||
|
||||
\section news0_99_beta16 Changes between 0.99.beta16 and 0.99.beta15
|
||||
|
||||
- many build fixes, especially for nonstandard platforms
|
||||
|
||||
\section news0_99_beta15 Changes between 0.99.beta15 and 0.99.beta14
|
||||
|
||||
- libcucul was merged back into libcaca for more clarity
|
||||
|
||||
\section news0_99_beta14 Changes between 0.99.beta14 and 0.99.beta13
|
||||
|
||||
- internal FIGlet font support
|
||||
- use C99 types in public headers
|
||||
- runtime support for output drivers
|
||||
- BBcode export support
|
||||
|
||||
\section news0_99_beta13 Changes between 0.99.beta13 and 0.99.beta12
|
||||
|
||||
- device-dependent cursor support
|
||||
- event API rewrite
|
||||
- minor API improvements and extensions
|
||||
- img2txt improvements
|
||||
- Ruby bindings
|
||||
- Massive C# bindings improvements
|
||||
- Python sample code
|
||||
- Visual Studio build solution
|
||||
|
||||
\section news0_99_beta12 Changes between 0.99.beta12 and 0.99.beta11
|
||||
|
||||
- support for 90-degree canvas rotation
|
||||
- better behaviour when trying to output Unicode on an ASCII terminal
|
||||
- the built-in font now supports the Geometric Shapes, Halfwidth and Fullwidth
|
||||
Forms and Miscellaneous Symbols Unicode blocks
|
||||
- new rotozoom effect in cacademo
|
||||
- Cocoa output driver for Mac OS X
|
||||
- preliminary .NET bindings
|
||||
- many bugfixes and documentation changes
|
||||
|
||||
\section news0_99_beta11 Changes between 0.99.beta11 and 0.99.beta10
|
||||
|
||||
- fixed compilation of the C++ bindings
|
||||
- fixed bugs in cucul_import_memory(), cucul_set_canvas_size()
|
||||
- implemented caca_set_display_title() for ncurses and S-Lang
|
||||
- minor bugfixes
|
||||
|
||||
\section news0_99_beta10 Changes between 0.99.beta10 and 0.99.beta9
|
||||
|
||||
- new debug mode
|
||||
- blitting canvases now makes use of the canvas' handle coordinates
|
||||
- import functions can read streamed data
|
||||
- attribute to colorspace transformations
|
||||
- added katakana and hiragana glyphs to the built-in font
|
||||
- many bugfixes and documentation changes
|
||||
|
||||
\section news0_99_beta9 Changes between 0.99.beta9 and 0.99.beta8
|
||||
|
||||
- support for blink, bold, italics and underline attributes
|
||||
- allow to import and export zero-sized canvases
|
||||
- fixed Imlib2 support in cacaview
|
||||
- fixed buffer overlows in the file importer
|
||||
- big documentation updates
|
||||
|
||||
\section news0_99_beta8 Changes between 0.99.beta8 and 0.99.beta7
|
||||
|
||||
- allow to build the X11 and GL drivers as separate plugins
|
||||
- support for fullwidth Unicode characters
|
||||
- improved cucul_flip() and cucul_rotate()
|
||||
- minor bugfixes and documentation updates
|
||||
|
||||
\section news0_99_beta7 Changes between 0.99.beta7 and 0.99.beta6
|
||||
|
||||
- transparency support in the UTF-8 importer and exporter
|
||||
- optimised triangle fill routine
|
||||
- updated C++ bindings
|
||||
|
||||
\section news0_99_beta6 Changes between 0.99.beta6 and 0.99.beta5
|
||||
|
||||
- ANSI importer now handles transparency and UTF-8
|
||||
- Unicode support was broken for about 10% of the set
|
||||
- various memory leaks were fixed
|
||||
|
||||
\section news0_99_beta5 Changes between 0.99.beta5 and 0.99.beta4
|
||||
|
||||
- implemented cucul_getchar() and cucul_get_color()
|
||||
- handle transparency in the IRC export
|
||||
- new cropping and expanding filters
|
||||
- full Unicode support in the OpenGL driver
|
||||
- portability fixes for 64-bit architectures, Win32 and MS-DOS
|
||||
- all demos except cacafire were merged into cacademo
|
||||
|
||||
\section news0_99_beta4 Changes between 0.99.beta4 and 0.99.beta3
|
||||
|
||||
- added a compatibility layer for pre-1.x libcaca applications
|
||||
- fixed manpage generation
|
||||
- minor bugfixes and documentation updates
|
||||
|
||||
\section news0_99_beta3 Changes between 0.99.beta3 and 0.99.beta2
|
||||
|
||||
- libcaca functions use errno for error reporting
|
||||
- updated C++ bindings
|
||||
- minor improvements, bugfixes and documentation updates
|
||||
|
||||
\section news0_99_beta2 Changes between 0.99.beta2 and 0.99.beta1
|
||||
|
||||
- ANSI importer
|
||||
- functions use errno for error reporting
|
||||
- updated C++ bindings
|
||||
- .NET bindings
|
||||
- cacadraw, an ANSI viewer that will evolve into an editor
|
||||
- Unicode input and output support for SLang and ncurses
|
||||
- built-in fonts work on Win32
|
||||
|
||||
\section news0_99_beta1 Changes between 0.9 and 0.99.beta1
|
||||
|
||||
- license switched to WTFPL
|
||||
- libcaca was split into libcucul, a standalone text manipulation backend,
|
||||
and libcaca, the display and user input frontend
|
||||
- Unicode support
|
||||
- TrueColor (more than 16 colours) support
|
||||
- Floyd-Steinberg dithering
|
||||
- gamma correction
|
||||
- export functions for HTML, IRC, ANSI, SVG, PostScript, TGA...
|
||||
- builtin fonts for device-independent bitmap output
|
||||
- various text transformation routines (rotation, horizontal flip...)
|
||||
- OpenGL renderer
|
||||
- kernel mode to build libcaca programs into a bootable x86 kernel
|
||||
- cacaserver, a telnet server that can be hooked to libcaca applications
|
||||
- img2irc, an image to IRC conversion utility
|
||||
|
||||
\section news0_9 Changes between 0.8 and 0.9
|
||||
|
||||
- fix for a buffer overflow in the line rendering
|
||||
- fixed resizing in the ncurses and slang drivers
|
||||
- aspect ratio and finer zoom support in cacaview
|
||||
- minor compilation fixes
|
||||
|
||||
\section news0_8 Changes between 0.7 and 0.8
|
||||
|
||||
- window resizing support
|
||||
- native Win32 port
|
||||
- autorepeat emulation in the ncurses and slang drivers
|
||||
- support for more keycodes in the ncurses and slang drivers
|
||||
- cacaplas, a plasma animation example
|
||||
- cacamoir, a moire circles animation example
|
||||
- MSVC project file
|
||||
|
||||
\section news0_7 Changes between 0.6 and 0.7
|
||||
|
||||
- many bugfixes in the event handling
|
||||
- cacaball, a metaball animation example
|
||||
|
||||
\section news0_6 Changes between 0.5 and 0.6
|
||||
|
||||
- 30% speed increase in the bitmap rendering routine
|
||||
- mouse support and various speed optimisations in the X11 driver
|
||||
- X11 is now the preferred driver
|
||||
- improved documentation
|
||||
- minor bugfixes
|
||||
|
||||
\section news0_5 Changes between 0.4 and 0.5
|
||||
|
||||
- palette optimisation for the S-Lang driver to work around the colour pair
|
||||
shortage bug
|
||||
- minor compilation fix
|
||||
|
||||
\section news0_4 Changes between 0.3 and 0.4
|
||||
|
||||
- preliminary X11 graphics driver
|
||||
- support for simultaneously compiled-in drivers
|
||||
- honour the CACA_DRIVER, CACA_GEOMETRY and CACA_FONT environment variables
|
||||
- more documentation
|
||||
|
||||
\section news0_3 Changes between 0.2 and 0.3
|
||||
|
||||
- antialiasing support
|
||||
- dithering, antialiasing and background mode can now be selected at
|
||||
runtime or in the environment using the CACA_BACKGROUND, CACA_DITHERING
|
||||
and CACA_ANTIALIASING variables
|
||||
- alpha channel support in cacaview
|
||||
- BMP loading support in cacaview even if Imlib2 is not present
|
||||
- cacafire, a libcaca port of aafire
|
||||
|
||||
\section news0_2 Changes between 0.1 and 0.2
|
||||
|
||||
- rendering now uses 256 colour pairs instead of 16
|
||||
- mouse support for ncurses
|
||||
- ncurses is now the preferred backend
|
||||
- arbitrary color depth and bitmasks in the bitmap renderer
|
||||
- cacaview, an image viewer based on libcaca
|
||||
|
||||
\section news_0_1 New in 0.1
|
||||
|
||||
- initial release
|
||||
- slang, ncurses and conio drivers
|
||||
- basic line, box, ellipse and triangle primitives
|
||||
- colour bitmap blitting
|
||||
|
||||
*/
|
|
@ -0,0 +1,125 @@
|
|||
|
||||
o Colour does not work with all backends and all terminals. I tested
|
||||
many terminal emulators and tried to summarise which combinations
|
||||
worked properly and which ones did not.
|
||||
|
||||
From termcap(5):
|
||||
|
||||
set_a_background setab AB Set background
|
||||
color to #1, using
|
||||
ANSI escape
|
||||
set_a_foreground setaf AF Set foreground
|
||||
color to #1, using
|
||||
ANSI escape
|
||||
From the xterm terminfo:
|
||||
|
||||
setab=\E[4%p1%dm, setaf=\E[3%p1%dm
|
||||
|
||||
From the xterm-16color terminfo:
|
||||
(http://www.sct.gu.edu.au/~anthony/info/X/Xterm_xf86.terminfo)
|
||||
|
||||
setab=\E[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm,
|
||||
setaf=\E[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm,
|
||||
|
||||
These values can be simply retrieved with a tigetstr() call.
|
||||
|
||||
o I tested the following terminals:
|
||||
|
||||
name $TERM $COLORTERM
|
||||
------------------------------------------
|
||||
Linux console linux
|
||||
pterm xterm
|
||||
aterm xterm rxvt-xpm
|
||||
wterm xterm wterm-xpm
|
||||
Eterm xterm Eterm
|
||||
xterm xterm
|
||||
gnome-terminal xterm
|
||||
konsole xterm
|
||||
mlterm mlterm
|
||||
uxterm xterm
|
||||
|
||||
o In most terminals, \e[3xm and \[4xm respectively set the foreground
|
||||
and background colours. x is a colour between 0 and 7 or the value
|
||||
9 for default colour (may be transparent).
|
||||
|
||||
\e[0m sets everything to normal, \e[1m sets bold, \e[5m sets blink
|
||||
and \e[7m sets inverse video.
|
||||
|
||||
In ncurses, only 64 colour pairs are created, and A_BOLD (\e[1m) and
|
||||
A_BLINK (\e[5m) are used for foreground/background colour highlighting,
|
||||
hence creating 256 possible colour pairs.
|
||||
|
||||
Different tests of blue on yellow:
|
||||
|
||||
for invert in '' '\e[7m'; do
|
||||
for blink in '' '\e[5m'; do
|
||||
for bold in '' '\e[1m'; do
|
||||
echo -ne "$bold$blink$invert"'\e[33m\e[44m'hop'\e[0m '
|
||||
echo "($bold$blink$invert)"
|
||||
done
|
||||
done
|
||||
done
|
||||
|
||||
Successfully works on:
|
||||
+ Linux console
|
||||
+ pterm
|
||||
+ Eterm
|
||||
+ aterm, wterm, rxvt
|
||||
|
||||
Almost works on:
|
||||
+ xterm (bright bg only works when fg is bright and then inverted,
|
||||
but then fg is not bright)
|
||||
|
||||
Fails on:
|
||||
+ mlterm (no bright colours, neither fg nor bg)
|
||||
+ gnome-terminal (no bright bg)
|
||||
+ konsole (no bright bg, $blink really blinks)
|
||||
|
||||
o In an XTerm-compatible terminal, \e[9xm sets bright foreground
|
||||
and \e[10xm bright background colours. Documentation on this can be
|
||||
found at http://ftp.xfree86.org/pub/XFree86/4.2.1/doc/ctlseqs.TXT .
|
||||
Unfortunately all terminals don't support these escape sequences. Here
|
||||
is a testcase:
|
||||
|
||||
for fgpre in 3 9; do for fg in 0 4 2 6 1 5 3 7; do
|
||||
for bgpre in 4 10; do
|
||||
echo -ne '\e['$fgpre$fg'm'
|
||||
for bg in 0 4 2 6 1 5 3 7; do echo -ne '\e['$bgpre$bg'm# '; done
|
||||
echo -ne '\e[0m '
|
||||
done
|
||||
echo ''
|
||||
done; echo ''; done
|
||||
|
||||
Successfully tested on:
|
||||
+ gnome-terminal
|
||||
+ konsole
|
||||
+ xterm
|
||||
+ pterm
|
||||
|
||||
Failed (\e[9x and \e[10x don't do anything) on:
|
||||
+ Eterm
|
||||
+ aterm, wterm, rxvt
|
||||
+ mlterm
|
||||
+ Linux console
|
||||
|
||||
o How to draw bright colours on any terminal?
|
||||
|
||||
'\e[93;104m' -> bright yellow on bright blue
|
||||
doesn't work on mlterm, gnome-terminal, konsole
|
||||
|
||||
'\e[5;1;33;44m' -> bright yellow on bright blue
|
||||
doesn't work on mlterm, aterm/wterm/rxvt, Eterm, console
|
||||
|
||||
'\e[5;1;33;44;93;104m' -> bright yellow on bright blue
|
||||
works on gnome-terminal, xterm, pterm, aterm/wterm/rxvt, console
|
||||
doesn't work on konsole
|
||||
|
||||
o MS-DOS: all bright colours, bright backgrounds, and bright combinations
|
||||
work using <conio.h>. No need to kludge anything.
|
||||
|
||||
o Win32: we use GetConsoleScreenBufferInfo etc. There is an interesting
|
||||
tutorial here: http://www.adrianxw.dk/SoftwareSite/index.html
|
||||
|
||||
o Set terminal window title:
|
||||
http://mail.gnome.org/archives/mc-devel/2003-January/msg00101.html
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
Building libcaca
|
||||
|
||||
o If you are using a Git or SVN checkout, you need to run the
|
||||
bootstrap script in order to generate configure. This is not
|
||||
necessary for official tarballs.
|
||||
|
||||
o Run configure then make. Useful configure flags are:
|
||||
|
||||
--enable-ncurses: support for the ncurses library
|
||||
--enable-slang: support for the SLang library
|
||||
--enable-conio: support for MS-DOS conio.h
|
||||
--enable-x11: support for native X11 rendering
|
||||
--enable-gl: support for OpenGL rendering
|
||||
--enable-win32: support for the Windows console
|
||||
--enable-network: support for the network server
|
||||
|
||||
--disable-imlib2: remove Imlib2 support in cacaview
|
||||
|
||||
--disable-doc: do not build documentation
|
||||
|
||||
o Cross-compilation examples:
|
||||
|
||||
./configure --disable-imlib2 --host=i386-pc-msdosdjgpp
|
||||
|
||||
./configure --disable-imlib2 --host=i586-mingw32msvc
|
||||
|
||||
|
||||
Using libcaca
|
||||
|
||||
o Look into the src/ and test/ directories for source code examples.
|
||||
|
||||
o Compiling a libcaca program is fairly simple:
|
||||
|
||||
gcc -c foobar.c -o foobar.o `pkg-config --cflags caca`
|
||||
gcc foobar.o -o foobar `pkg-config --libs caca`
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/** \page libcaca-thanks Libcaca thanks
|
||||
|
||||
\section thanks1 Bugfixes and improvements
|
||||
|
||||
- Gildas Bazin <gbazin@netcourrier.com> - win32 driver improvements
|
||||
- Jari Komppa <jari.komppa at gmail> - win32 speed improvements
|
||||
- Bastian Märkisch <bmaerkisch@web.de> - bugfixes and win32 driver improvements
|
||||
- Denis Fondras <ledeuns at github> - IPv6 support in cacaserver
|
||||
|
||||
\section thanks2 Reused code
|
||||
|
||||
- Jan Hubicka <hubicka@freesoft.cz> - aafire
|
||||
- Michele Bini <mibin@tin.it> - original SDL plasma
|
||||
- Free Software Foundation, Inc. - multiboot.S
|
||||
- Simon Huggins <webmaster#simonhuggins.com> - conio-snake
|
||||
|
||||
\section thanks3 Porters and packagers
|
||||
|
||||
- Derk-Jan Hartman <thedj@users.sourceforge.net> - Gentoo ebuild file
|
||||
- Ladislav Hagara <hgr@vabo.cz> - Source Mage spell
|
||||
- Philip Balinov - Slackware package
|
||||
- Richard Zidlicky <rz@linux-m68k.org> - rpm specfile
|
||||
- Thomas Klausner <wiz@NetBSD.org> - NetBSD port maintainer
|
||||
- Vincent Tantardini <vinc@FreeBSD-fr.org> - FreeBSD port maintainer
|
||||
|
||||
*/
|
|
@ -0,0 +1,503 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 45;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
E60690EB10DCD81300F80E76 /* pic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = pic.c; sourceTree = "<group>"; };
|
||||
E60690EC10DCD81300F80E76 /* int.asm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm.asm; path = int.asm; sourceTree = "<group>"; };
|
||||
E60690ED10DCD81300F80E76 /* stage2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = stage2.h; sourceTree = "<group>"; };
|
||||
E60690EE10DCD81300F80E76 /* interruptions.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = interruptions.c; sourceTree = "<group>"; };
|
||||
E60690EF10DCD81300F80E76 /* stage2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = stage2.c; sourceTree = "<group>"; };
|
||||
E60690F010DCD81300F80E76 /* bootsect.asm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm.asm; path = bootsect.asm; sourceTree = "<group>"; };
|
||||
E60690F110DCD81300F80E76 /* gdt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = gdt.c; sourceTree = "<group>"; };
|
||||
E60690F210DCD81300F80E76 /* idt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = idt.c; sourceTree = "<group>"; };
|
||||
E60690F410DCD81300F80E76 /* floppy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = floppy.h; sourceTree = "<group>"; };
|
||||
E60690F510DCD81300F80E76 /* floppy.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = floppy.c; sourceTree = "<group>"; };
|
||||
E60690FA10DCD85300F80E76 /* keyboard.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = keyboard.c; sourceTree = "<group>"; };
|
||||
E606910010DCDA3100F80E76 /* processor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = processor.h; sourceTree = "<group>"; };
|
||||
E606910110DCDA3100F80E76 /* processor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = processor.c; sourceTree = "<group>"; };
|
||||
E606911F10DCDF2B00F80E76 /* klibc.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = klibc.h; sourceTree = "<group>"; };
|
||||
E60691C710DCF2EA00F80E76 /* memory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = memory.h; sourceTree = "<group>"; };
|
||||
E60691C810DCF2EA00F80E76 /* memory.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = memory.c; sourceTree = "<group>"; };
|
||||
E60691E910DD0D6D00F80E76 /* timer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = timer.h; sourceTree = "<group>"; };
|
||||
E60691EA10DD0D6D00F80E76 /* timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = timer.c; sourceTree = "<group>"; };
|
||||
E64A326110DA344400325A66 /* build-kernel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = "build-kernel"; path = "../build-kernel"; sourceTree = SOURCE_ROOT; };
|
||||
E64A326610DA344400325A66 /* kernel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = kernel.c; sourceTree = "<group>"; };
|
||||
E64A326710DA344400325A66 /* kernel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = kernel.h; sourceTree = "<group>"; };
|
||||
E64A326810DA344400325A66 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Makefile.am; sourceTree = "<group>"; };
|
||||
E64A326910DA344400325A66 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
|
||||
E64A331D10DA447500325A66 /* config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = config.h; path = ../config.h; sourceTree = SOURCE_ROOT; };
|
||||
E64A33E410DA861600325A66 /* klibc.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = klibc.c; sourceTree = "<group>"; };
|
||||
E68A871110CD1F040047EB17 /* mouse.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = mouse.c; path = ../examples/mouse.c; sourceTree = SOURCE_ROOT; };
|
||||
E68B916D13237280006B282B /* cacaclock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacaclock.c; path = ../src/cacaclock.c; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681710B560BB008B6DEC /* caca++.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "caca++.cpp"; path = "../cxx/caca++.cpp"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681810B560BB008B6DEC /* caca++.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca++.h"; path = "../cxx/caca++.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681910B560BB008B6DEC /* cxxtest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cxxtest.cpp; path = ../cxx/cxxtest.cpp; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681B10B561CE008B6DEC /* caca-canvas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "caca-canvas.c"; path = "../ruby/caca-canvas.c"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681C10B561CE008B6DEC /* caca-canvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca-canvas.h"; path = "../ruby/caca-canvas.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681D10B561CE008B6DEC /* caca-display.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "caca-display.c"; path = "../ruby/caca-display.c"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681E10B561CE008B6DEC /* caca-display.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca-display.h"; path = "../ruby/caca-display.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7681F10B561CE008B6DEC /* caca-dither.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "caca-dither.c"; path = "../ruby/caca-dither.c"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682010B561CE008B6DEC /* caca-dither.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca-dither.h"; path = "../ruby/caca-dither.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682110B561CE008B6DEC /* caca-event.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "caca-event.c"; path = "../ruby/caca-event.c"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682210B561CE008B6DEC /* caca-event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca-event.h"; path = "../ruby/caca-event.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682310B561CE008B6DEC /* caca-font.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "caca-font.c"; path = "../ruby/caca-font.c"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682410B561CE008B6DEC /* caca-font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "caca-font.h"; path = "../ruby/caca-font.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682510B561CE008B6DEC /* caca.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = caca.c; path = ../ruby/caca.c; sourceTree = SOURCE_ROOT; };
|
||||
E6A7682610B561CE008B6DEC /* common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = common.h; path = ../ruby/common.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65F610AECC7800B6F924 /* attr.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = attr.c; path = ../caca/attr.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65F710AECC7800B6F924 /* box.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = box.c; path = ../caca/box.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65F810AECC7800B6F924 /* caca_conio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = caca_conio.c; path = ../caca/caca_conio.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65F910AECC7800B6F924 /* caca_conio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = caca_conio.h; path = ../caca/caca_conio.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65FA10AECC7800B6F924 /* caca_internals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = caca_internals.h; path = ../caca/caca_internals.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65FB10AECC7800B6F924 /* caca_stubs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = caca_stubs.h; path = ../caca/caca_stubs.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65FC10AECC7800B6F924 /* caca_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = caca_types.h; path = ../caca/caca_types.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65FE10AECC7800B6F924 /* caca.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = caca.c; path = ../caca/caca.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB65FF10AECC7800B6F924 /* caca.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = caca.h; path = ../caca/caca.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660210AECC7800B6F924 /* caca0.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = caca0.c; path = ../caca/caca0.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660310AECC7800B6F924 /* caca0.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = caca0.h; path = ../caca/caca0.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660410AECC7800B6F924 /* canvas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = canvas.c; path = ../caca/canvas.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660510AECC7800B6F924 /* charset.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = charset.c; path = ../caca/charset.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660710AECC7800B6F924 /* codec.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = codec.h; sourceTree = "<group>"; };
|
||||
E6DB660810AECC7800B6F924 /* export.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = export.c; sourceTree = "<group>"; };
|
||||
E6DB660910AECC7800B6F924 /* import.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = import.c; sourceTree = "<group>"; };
|
||||
E6DB660A10AECC7800B6F924 /* text.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = text.c; sourceTree = "<group>"; };
|
||||
E6DB660B10AECC7800B6F924 /* conic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = conic.c; path = ../caca/conic.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660C10AECC7800B6F924 /* dirty.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = dirty.c; path = ../caca/dirty.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660D10AECC7800B6F924 /* dither.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = dither.c; path = ../caca/dither.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB660F10AECC7800B6F924 /* cocoa.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = cocoa.m; sourceTree = "<group>"; };
|
||||
E6DB661010AECC7800B6F924 /* conio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = conio.c; sourceTree = "<group>"; };
|
||||
E6DB661110AECC7800B6F924 /* gl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = gl.c; sourceTree = "<group>"; };
|
||||
E6DB661210AECC7800B6F924 /* ncurses.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ncurses.c; sourceTree = "<group>"; };
|
||||
E6DB661310AECC7800B6F924 /* null.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = null.c; sourceTree = "<group>"; };
|
||||
E6DB661410AECC7800B6F924 /* raw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = raw.c; sourceTree = "<group>"; };
|
||||
E6DB661510AECC7800B6F924 /* slang.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = slang.c; sourceTree = "<group>"; };
|
||||
E6DB661610AECC7800B6F924 /* vga.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = vga.c; sourceTree = "<group>"; };
|
||||
E6DB661710AECC7800B6F924 /* win32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = win32.c; sourceTree = "<group>"; };
|
||||
E6DB661810AECC7800B6F924 /* x11.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = x11.c; sourceTree = "<group>"; };
|
||||
E6DB661910AECC7800B6F924 /* event.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = event.c; path = ../caca/event.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB661A10AECC7800B6F924 /* figfont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = figfont.c; path = ../caca/figfont.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB661B10AECC7800B6F924 /* file.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = file.c; path = ../caca/file.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB661C10AECC7800B6F924 /* font.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = font.c; path = ../caca/font.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB661D10AECC7800B6F924 /* frame.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = frame.c; path = ../caca/frame.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB661E10AECC7800B6F924 /* graphics.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = graphics.c; path = ../caca/graphics.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662010AECC7800B6F924 /* line.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = line.c; path = ../caca/line.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662110AECC7800B6F924 /* string.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = string.c; path = ../caca/string.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662210AECC7800B6F924 /* time.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = time.c; path = ../caca/time.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662310AECC7800B6F924 /* transform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = transform.c; path = ../caca/transform.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662410AECC7800B6F924 /* triangle.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = triangle.c; path = ../caca/triangle.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662C10AECCD700B6F924 /* aafire.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = aafire.c; path = ../src/aafire.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662D10AECCD700B6F924 /* cacademo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacademo.c; path = ../src/cacademo.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662E10AECCD700B6F924 /* cacadraw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacadraw.c; path = ../src/cacadraw.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB662F10AECCD700B6F924 /* cacaplay.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacaplay.c; path = ../src/cacaplay.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663010AECCD700B6F924 /* cacaserver.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacaserver.c; path = ../src/cacaserver.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663110AECCD700B6F924 /* cacaview.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cacaview.c; path = ../src/cacaview.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663210AECCD700B6F924 /* common-image.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = "common-image.c"; path = "../src/common-image.c"; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663310AECCD700B6F924 /* common-image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "common-image.h"; path = "../src/common-image.h"; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663410AECCD700B6F924 /* img2txt.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = img2txt.c; path = ../src/img2txt.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663710AECCD700B6F924 /* texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = texture.h; path = ../src/texture.h; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663910AECD1F00B6F924 /* trifiller.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = trifiller.c; path = ../examples/trifiller.c; sourceTree = SOURCE_ROOT; wrapsLines = 0; };
|
||||
E6DB663B10AECDF500B6F924 /* blit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = blit.c; path = ../examples/blit.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663C10AECDF500B6F924 /* canvas.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = canvas.c; path = ../examples/canvas.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663D10AECDF500B6F924 /* colors.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = colors.c; path = ../examples/colors.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663E10AECDF500B6F924 /* conio-snake.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "conio-snake.cpp"; path = "../examples/conio-snake.cpp"; sourceTree = SOURCE_ROOT; };
|
||||
E6DB663F10AECDF500B6F924 /* conio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = conio.c; path = ../examples/conio.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664010AECDF500B6F924 /* demo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = demo.c; path = ../examples/demo.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664110AECDF500B6F924 /* demo0.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = demo0.c; path = ../examples/demo0.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664210AECDF500B6F924 /* dithering.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = dithering.c; path = ../examples/dithering.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664310AECDF500B6F924 /* driver.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = driver.c; path = ../examples/driver.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664410AECDF500B6F924 /* event.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = event.c; path = ../examples/event.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664510AECDF500B6F924 /* export.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = export.c; path = ../examples/export.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664610AECDF500B6F924 /* figfont.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = figfont.c; path = ../examples/figfont.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664710AECDF500B6F924 /* font.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = font.c; path = ../examples/font.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664810AECDF500B6F924 /* font2tga.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = font2tga.c; path = ../examples/font2tga.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664910AECDF500B6F924 /* frames.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = frames.c; path = ../examples/frames.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664A10AECDF500B6F924 /* fullwidth.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = fullwidth.c; path = ../examples/fullwidth.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664B10AECDF500B6F924 /* gamma.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = gamma.c; path = ../examples/gamma.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664C10AECDF500B6F924 /* hsv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = hsv.c; path = ../examples/hsv.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664D10AECDF500B6F924 /* import.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = import.c; path = ../examples/import.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664E10AECDF500B6F924 /* input.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = input.c; path = ../examples/input.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB664F10AECDF500B6F924 /* spritedit.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = spritedit.c; path = ../examples/spritedit.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB665010AECDF500B6F924 /* swallow.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = swallow.c; path = ../examples/swallow.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB665110AECDF500B6F924 /* text.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = text.c; path = ../examples/text.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB665210AECDF500B6F924 /* transform.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = transform.c; path = ../examples/transform.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB665310AECDF500B6F924 /* truecolor.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = truecolor.c; path = ../examples/truecolor.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB665410AECDF500B6F924 /* unicode.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = unicode.c; path = ../examples/unicode.c; sourceTree = SOURCE_ROOT; };
|
||||
E6DB665510AECE3600B6F924 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Makefile.am; path = ../examples/Makefile.am; sourceTree = SOURCE_ROOT; };
|
||||
E6DB66FA10B176D100B6F924 /* configure.ac */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = configure.ac; path = ../configure.ac; sourceTree = SOURCE_ROOT; };
|
||||
E6DB66FF10B17BEA00B6F924 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Makefile.am; path = ../src/Makefile.am; sourceTree = SOURCE_ROOT; };
|
||||
E6DB670010B17BFC00B6F924 /* Makefile.am */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = Makefile.am; path = ../caca/Makefile.am; sourceTree = SOURCE_ROOT; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
08FB7794FE84155DC02AAC07 /* XCode */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E64A331D10DA447500325A66 /* config.h */,
|
||||
E64A326110DA344400325A66 /* build-kernel */,
|
||||
E64A326210DA344400325A66 /* kernel */,
|
||||
E6A7681A10B561B9008B6DEC /* ruby */,
|
||||
E6A7681510B560AE008B6DEC /* cxx */,
|
||||
E6DB66FA10B176D100B6F924 /* configure.ac */,
|
||||
E6DB663A10AECDC500B6F924 /* examples */,
|
||||
E6DB662B10AECCBF00B6F924 /* src */,
|
||||
E6DB65F510AECC5800B6F924 /* caca */,
|
||||
);
|
||||
name = XCode;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E60690EA10DCD81300F80E76 /* boot */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E60690ED10DCD81300F80E76 /* stage2.h */,
|
||||
E60690F010DCD81300F80E76 /* bootsect.asm */,
|
||||
E60690EC10DCD81300F80E76 /* int.asm */,
|
||||
E60690EB10DCD81300F80E76 /* pic.c */,
|
||||
E60690EE10DCD81300F80E76 /* interruptions.c */,
|
||||
E60690EF10DCD81300F80E76 /* stage2.c */,
|
||||
E60690F110DCD81300F80E76 /* gdt.c */,
|
||||
E60690F210DCD81300F80E76 /* idt.c */,
|
||||
);
|
||||
path = boot;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E60690F310DCD81300F80E76 /* drivers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E606910010DCDA3100F80E76 /* processor.h */,
|
||||
E60690F410DCD81300F80E76 /* floppy.h */,
|
||||
E60691C710DCF2EA00F80E76 /* memory.h */,
|
||||
E60691E910DD0D6D00F80E76 /* timer.h */,
|
||||
E60690FA10DCD85300F80E76 /* keyboard.c */,
|
||||
E60690F510DCD81300F80E76 /* floppy.c */,
|
||||
E606910110DCDA3100F80E76 /* processor.c */,
|
||||
E60691C810DCF2EA00F80E76 /* memory.c */,
|
||||
E60691EA10DD0D6D00F80E76 /* timer.c */,
|
||||
);
|
||||
path = drivers;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E64A326210DA344400325A66 /* kernel */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E606911F10DCDF2B00F80E76 /* klibc.h */,
|
||||
E64A326710DA344400325A66 /* kernel.h */,
|
||||
E64A33E410DA861600325A66 /* klibc.c */,
|
||||
E64A326610DA344400325A66 /* kernel.c */,
|
||||
E60690EA10DCD81300F80E76 /* boot */,
|
||||
E60690F310DCD81300F80E76 /* drivers */,
|
||||
E64A326810DA344400325A66 /* Makefile.am */,
|
||||
E64A326910DA344400325A66 /* Makefile */,
|
||||
);
|
||||
name = kernel;
|
||||
path = ../kernel;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
E6A7681510B560AE008B6DEC /* cxx */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E6A7681810B560BB008B6DEC /* caca++.h */,
|
||||
E6A7681710B560BB008B6DEC /* caca++.cpp */,
|
||||
E6A7681910B560BB008B6DEC /* cxxtest.cpp */,
|
||||
);
|
||||
name = cxx;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E6A7681A10B561B9008B6DEC /* ruby */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E6A7681B10B561CE008B6DEC /* caca-canvas.c */,
|
||||
E6A7681C10B561CE008B6DEC /* caca-canvas.h */,
|
||||
E6A7681D10B561CE008B6DEC /* caca-display.c */,
|
||||
E6A7681E10B561CE008B6DEC /* caca-display.h */,
|
||||
E6A7681F10B561CE008B6DEC /* caca-dither.c */,
|
||||
E6A7682010B561CE008B6DEC /* caca-dither.h */,
|
||||
E6A7682110B561CE008B6DEC /* caca-event.c */,
|
||||
E6A7682210B561CE008B6DEC /* caca-event.h */,
|
||||
E6A7682310B561CE008B6DEC /* caca-font.c */,
|
||||
E6A7682410B561CE008B6DEC /* caca-font.h */,
|
||||
E6A7682510B561CE008B6DEC /* caca.c */,
|
||||
E6A7682610B561CE008B6DEC /* common.h */,
|
||||
);
|
||||
name = ruby;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E6DB65F510AECC5800B6F924 /* caca */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E6DB670010B17BFC00B6F924 /* Makefile.am */,
|
||||
E6DB65FF10AECC7800B6F924 /* caca.h */,
|
||||
E6DB65F610AECC7800B6F924 /* attr.c */,
|
||||
E6DB65F710AECC7800B6F924 /* box.c */,
|
||||
E6DB65F810AECC7800B6F924 /* caca_conio.c */,
|
||||
E6DB65F910AECC7800B6F924 /* caca_conio.h */,
|
||||
E6DB65FA10AECC7800B6F924 /* caca_internals.h */,
|
||||
E6DB65FB10AECC7800B6F924 /* caca_stubs.h */,
|
||||
E6DB65FC10AECC7800B6F924 /* caca_types.h */,
|
||||
E6DB65FE10AECC7800B6F924 /* caca.c */,
|
||||
E6DB660210AECC7800B6F924 /* caca0.c */,
|
||||
E6DB660310AECC7800B6F924 /* caca0.h */,
|
||||
E6DB660410AECC7800B6F924 /* canvas.c */,
|
||||
E6DB660510AECC7800B6F924 /* charset.c */,
|
||||
E6DB660610AECC7800B6F924 /* codec */,
|
||||
E6DB660B10AECC7800B6F924 /* conic.c */,
|
||||
E6DB660C10AECC7800B6F924 /* dirty.c */,
|
||||
E6DB660D10AECC7800B6F924 /* dither.c */,
|
||||
E6DB660E10AECC7800B6F924 /* driver */,
|
||||
E6DB661910AECC7800B6F924 /* event.c */,
|
||||
E6DB661A10AECC7800B6F924 /* figfont.c */,
|
||||
E6DB661B10AECC7800B6F924 /* file.c */,
|
||||
E6DB661C10AECC7800B6F924 /* font.c */,
|
||||
E6DB661D10AECC7800B6F924 /* frame.c */,
|
||||
E6DB661E10AECC7800B6F924 /* graphics.c */,
|
||||
E6DB662010AECC7800B6F924 /* line.c */,
|
||||
E6DB662110AECC7800B6F924 /* string.c */,
|
||||
E6DB662210AECC7800B6F924 /* time.c */,
|
||||
E6DB662310AECC7800B6F924 /* transform.c */,
|
||||
E6DB662410AECC7800B6F924 /* triangle.c */,
|
||||
);
|
||||
name = caca;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E6DB660610AECC7800B6F924 /* codec */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E6DB660710AECC7800B6F924 /* codec.h */,
|
||||
E6DB660810AECC7800B6F924 /* export.c */,
|
||||
E6DB660910AECC7800B6F924 /* import.c */,
|
||||
E6DB660A10AECC7800B6F924 /* text.c */,
|
||||
);
|
||||
name = codec;
|
||||
path = ../caca/codec;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
E6DB660E10AECC7800B6F924 /* driver */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E6DB660F10AECC7800B6F924 /* cocoa.m */,
|
||||
E6DB661010AECC7800B6F924 /* conio.c */,
|
||||
E6DB661110AECC7800B6F924 /* gl.c */,
|
||||
E6DB661210AECC7800B6F924 /* ncurses.c */,
|
||||
E6DB661310AECC7800B6F924 /* null.c */,
|
||||
E6DB661410AECC7800B6F924 /* raw.c */,
|
||||
E6DB661510AECC7800B6F924 /* slang.c */,
|
||||
E6DB661610AECC7800B6F924 /* vga.c */,
|
||||
E6DB661710AECC7800B6F924 /* win32.c */,
|
||||
E6DB661810AECC7800B6F924 /* x11.c */,
|
||||
);
|
||||
name = driver;
|
||||
path = ../caca/driver;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
E6DB662B10AECCBF00B6F924 /* src */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E68B916D13237280006B282B /* cacaclock.c */,
|
||||
E6DB66FF10B17BEA00B6F924 /* Makefile.am */,
|
||||
E6DB662C10AECCD700B6F924 /* aafire.c */,
|
||||
E6DB662D10AECCD700B6F924 /* cacademo.c */,
|
||||
E6DB662E10AECCD700B6F924 /* cacadraw.c */,
|
||||
E6DB662F10AECCD700B6F924 /* cacaplay.c */,
|
||||
E6DB663010AECCD700B6F924 /* cacaserver.c */,
|
||||
E6DB663110AECCD700B6F924 /* cacaview.c */,
|
||||
E6DB663210AECCD700B6F924 /* common-image.c */,
|
||||
E6DB663310AECCD700B6F924 /* common-image.h */,
|
||||
E6DB663410AECCD700B6F924 /* img2txt.c */,
|
||||
E6DB663710AECCD700B6F924 /* texture.h */,
|
||||
);
|
||||
name = src;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E6DB663A10AECDC500B6F924 /* examples */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E6DB665510AECE3600B6F924 /* Makefile.am */,
|
||||
E6DB663B10AECDF500B6F924 /* blit.c */,
|
||||
E6DB663C10AECDF500B6F924 /* canvas.c */,
|
||||
E6DB663D10AECDF500B6F924 /* colors.c */,
|
||||
E6DB663E10AECDF500B6F924 /* conio-snake.cpp */,
|
||||
E6DB663F10AECDF500B6F924 /* conio.c */,
|
||||
E6DB664010AECDF500B6F924 /* demo.c */,
|
||||
E6DB664110AECDF500B6F924 /* demo0.c */,
|
||||
E6DB664210AECDF500B6F924 /* dithering.c */,
|
||||
E6DB664310AECDF500B6F924 /* driver.c */,
|
||||
E6DB664410AECDF500B6F924 /* event.c */,
|
||||
E6DB664510AECDF500B6F924 /* export.c */,
|
||||
E6DB664610AECDF500B6F924 /* figfont.c */,
|
||||
E6DB664710AECDF500B6F924 /* font.c */,
|
||||
E6DB664810AECDF500B6F924 /* font2tga.c */,
|
||||
E6DB664910AECDF500B6F924 /* frames.c */,
|
||||
E6DB664A10AECDF500B6F924 /* fullwidth.c */,
|
||||
E6DB664B10AECDF500B6F924 /* gamma.c */,
|
||||
E6DB664C10AECDF500B6F924 /* hsv.c */,
|
||||
E6DB664D10AECDF500B6F924 /* import.c */,
|
||||
E6DB664E10AECDF500B6F924 /* input.c */,
|
||||
E6DB664F10AECDF500B6F924 /* spritedit.c */,
|
||||
E6DB665010AECDF500B6F924 /* swallow.c */,
|
||||
E6DB665110AECDF500B6F924 /* text.c */,
|
||||
E6DB665210AECDF500B6F924 /* transform.c */,
|
||||
E6DB665310AECDF500B6F924 /* truecolor.c */,
|
||||
E6DB665410AECDF500B6F924 /* unicode.c */,
|
||||
E6DB663910AECD1F00B6F924 /* trifiller.c */,
|
||||
E68A871110CD1F040047EB17 /* mouse.c */,
|
||||
);
|
||||
name = examples;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXLegacyTarget section */
|
||||
D28A88AD04BDD90700651E21 /* libcacaXCode */ = {
|
||||
isa = PBXLegacyTarget;
|
||||
buildArgumentsString = "$(ACTION)";
|
||||
buildConfigurationList = 1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "libcacaXCode" */;
|
||||
buildPhases = (
|
||||
);
|
||||
buildToolPath = /usr/bin/make;
|
||||
dependencies = (
|
||||
);
|
||||
name = libcacaXCode;
|
||||
passBuildSettingsInEnvironment = 1;
|
||||
productName = XCode;
|
||||
};
|
||||
E6DB66B110B03F1700B6F924 /* libcaca */ = {
|
||||
isa = PBXLegacyTarget;
|
||||
buildArgumentsString = "$(ACTION)";
|
||||
buildConfigurationList = E6DB66B810B03F1800B6F924 /* Build configuration list for PBXLegacyTarget "libcaca" */;
|
||||
buildPhases = (
|
||||
);
|
||||
buildToolPath = /usr/bin/make;
|
||||
buildWorkingDirectory = "/Users/jylam/code/libcaca-trunk";
|
||||
dependencies = (
|
||||
);
|
||||
name = libcaca;
|
||||
passBuildSettingsInEnvironment = 1;
|
||||
productName = libcaca;
|
||||
};
|
||||
/* End PBXLegacyTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
08FB7793FE84155DC02AAC07 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = 1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "libcacaXCode" */;
|
||||
compatibilityVersion = "Xcode 3.1";
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 08FB7794FE84155DC02AAC07 /* XCode */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
D28A88AD04BDD90700651E21 /* libcacaXCode */,
|
||||
E6DB66B110B03F1700B6F924 /* libcaca */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
1DEB919008733D9F0010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUGGING_SYMBOLS = YES;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
OTHER_CFLAGS = "";
|
||||
OTHER_LDFLAGS = "";
|
||||
PRODUCT_NAME = libcacaXCode;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
1DEB919108733D9F0010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = YES;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = NO;
|
||||
OTHER_CFLAGS = "";
|
||||
OTHER_LDFLAGS = "";
|
||||
PRODUCT_NAME = libcacaXCode;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
1DEB919408733D9F0010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
PREBINDING = NO;
|
||||
SDKROOT = macosx10.6;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
1DEB919508733D9F0010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
PREBINDING = NO;
|
||||
SDKROOT = macosx10.6;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
E6DB66B210B03F1800B6F924 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
PRODUCT_NAME = libcaca;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
E6DB66B310B03F1800B6F924 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = NO;
|
||||
PRODUCT_NAME = libcaca;
|
||||
ZERO_LINK = NO;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
1DEB918F08733D9F0010E9CD /* Build configuration list for PBXLegacyTarget "libcacaXCode" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
1DEB919008733D9F0010E9CD /* Debug */,
|
||||
1DEB919108733D9F0010E9CD /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
1DEB919308733D9F0010E9CD /* Build configuration list for PBXProject "libcacaXCode" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
1DEB919408733D9F0010E9CD /* Debug */,
|
||||
1DEB919508733D9F0010E9CD /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
E6DB66B810B03F1800B6F924 /* Build configuration list for PBXLegacyTarget "libcaca" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
E6DB66B210B03F1800B6F924 /* Debug */,
|
||||
E6DB66B310B03F1800B6F924 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
|
||||
}
|
|
@ -0,0 +1,139 @@
|
|||
#! /bin/sh
|
||||
|
||||
# bootstrap — generic bootstrap/autogen.sh script for autotools projects
|
||||
#
|
||||
# Copyright © 2002—2015 Sam Hocevar <sam@hocevar.net>
|
||||
#
|
||||
# This program is free software. It comes without any warranty, to
|
||||
# the extent permitted by applicable law. You can redistribute it
|
||||
# and/or modify it under the terms of the Do What the Fuck You Want
|
||||
# to Public License, Version 2, as published by the WTFPL Task Force.
|
||||
# See http://www.wtfpl.net/ for more details.
|
||||
#
|
||||
# The latest version of this script can be found at the following place:
|
||||
# http://caca.zoy.org/wiki/build
|
||||
|
||||
# Die if an error occurs
|
||||
set -e
|
||||
|
||||
# Guess whether we are using configure.ac or configure.in
|
||||
if test -f configure.ac; then
|
||||
conffile="configure.ac"
|
||||
elif test -f configure.in; then
|
||||
conffile="configure.in"
|
||||
else
|
||||
echo "$0: could not find configure.ac or configure.in"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for needed features
|
||||
auxdir="`sed -ne 's/^[ \t]*A._CONFIG_AUX_DIR *([[ ]*\([^] )]*\).*/\1/p' $conffile`"
|
||||
pkgconfig="`grep '^[ \t]*PKG_PROG_PKG_CONFIG' $conffile >/dev/null 2>&1 && echo yes || echo no`"
|
||||
libtool="`grep '^[ \t]*LT_INIT' $conffile >/dev/null 2>&1 && echo yes || echo no`"
|
||||
header="`grep '^[ \t]*A._CONFIG_HEADERS' $conffile >/dev/null 2>&1 && echo yes || echo no`"
|
||||
makefile="`[ -f Makefile.am ] && echo yes || echo no`"
|
||||
aclocalflags="`sed -ne 's/^[ \t]*ACLOCAL_AMFLAGS[ \t]*=//p' Makefile.am 2>/dev/null || :`"
|
||||
|
||||
# Check for automake
|
||||
amvers="no"
|
||||
for v in "" "-1.15" "-1.14" "-1.13" "-1.12" "-1.11"; do
|
||||
if automake${v} --version > /dev/null 2>&1; then
|
||||
amvers=${v}
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if test "$amvers" = "no"; then
|
||||
echo "$0: automake not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for autoconf
|
||||
acvers="no"
|
||||
for v in "" "259" "253"; do
|
||||
if autoconf${v} --version >/dev/null 2>&1; then
|
||||
acvers="${v}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if test "$acvers" = "no"; then
|
||||
echo "$0: autoconf not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check for libtool
|
||||
if test "$libtool" = "yes"; then
|
||||
libtoolize="no"
|
||||
if glibtoolize --version >/dev/null 2>&1; then
|
||||
libtoolize="glibtoolize"
|
||||
else
|
||||
for v in "16" "15" "" "14"; do
|
||||
if libtoolize${v} --version >/dev/null 2>&1; then
|
||||
libtoolize="libtoolize${v}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if test "$libtoolize" = "no"; then
|
||||
echo "$0: libtool not found"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check for pkg-config
|
||||
if test "$pkgconfig" = "yes"; then
|
||||
if ! pkg-config --version >/dev/null 2>&1; then
|
||||
echo "$0: pkg-config not found"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Remove old cruft
|
||||
for x in aclocal.m4 configure config.guess config.log config.sub config.cache config.h.in config.h compile libtool.m4 ltoptions.m4 ltsugar.m4 ltversion.m4 ltmain.sh libtool ltconfig missing mkinstalldirs depcomp install-sh; do rm -f $x autotools/$x; if test -n "$auxdir"; then rm -f "$auxdir/$x"; fi; done
|
||||
rm -Rf autom4te.cache
|
||||
if test -n "$auxdir"; then
|
||||
if test ! -d "$auxdir"; then
|
||||
mkdir "$auxdir"
|
||||
fi
|
||||
aclocalflags="-I $auxdir -I . ${aclocalflags}"
|
||||
fi
|
||||
|
||||
# Honour M4PATH because sometimes M4 doesn't
|
||||
save_IFS=$IFS
|
||||
IFS=:
|
||||
tmp="$M4PATH"
|
||||
for x in $tmp; do
|
||||
if test -n "$x"; then
|
||||
aclocalflags="-I $x ${aclocalflags}"
|
||||
fi
|
||||
done
|
||||
IFS=$save_IFS
|
||||
|
||||
# Explain what we are doing from now
|
||||
set -x
|
||||
|
||||
# Bootstrap package
|
||||
if test "$libtool" = "yes"; then
|
||||
${libtoolize} --copy --force
|
||||
if test -n "$auxdir" -a ! "$auxdir" = "." -a -f "ltmain.sh"; then
|
||||
echo "$0: working around a minor libtool issue"
|
||||
mv ltmain.sh "$auxdir/"
|
||||
fi
|
||||
fi
|
||||
|
||||
aclocal${amvers} ${aclocalflags}
|
||||
autoconf${acvers}
|
||||
if test "$header" = "yes"; then
|
||||
autoheader${acvers}
|
||||
fi
|
||||
if test "$makefile" = "yes"; then
|
||||
#add --include-deps if you want to bootstrap with any other compiler than gcc
|
||||
#automake${amvers} --add-missing --copy --include-deps
|
||||
automake${amvers} --foreign --add-missing --copy
|
||||
fi
|
||||
|
||||
# Remove cruft that we no longer want
|
||||
rm -Rf autom4te.cache
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
|
||||
include $(top_srcdir)/build/autotools/common.am
|
||||
|
||||
EXTRA_DIST = autotools/common.am \
|
||||
win32/config.h \
|
||||
build-dos build-kernel build-win32 build-win64
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/caca -I$(top_builddir)/caca
|
||||
|
||||
echo-topdir: ; echo $(top_srcdir)
|
||||
echo-sources: ; echo $(SOURCES) $(EXTRA_CHECKS)
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#! /bin/sh
|
||||
|
||||
## DOS cross-compilation for libcaca -- Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Clean up our working directory
|
||||
SRCDIR="`pwd`"
|
||||
DIRNAME="libcaca-dos-`sed -ne 's/^AM_INIT_AUTOMAKE(.*, \(.*\)).*/\1/p' configure.ac`"
|
||||
INSTALLDIR="`pwd`/${DIRNAME}"
|
||||
BUILDDIR="${INSTALLDIR}/build"
|
||||
rm -Rf "${INSTALLDIR}"
|
||||
rm -f "${INSTALLDIR}.zip"
|
||||
mkdir "${INSTALLDIR}"
|
||||
mkdir "${BUILDDIR}"
|
||||
|
||||
cd "${BUILDDIR}"
|
||||
# Build for DOS
|
||||
"${SRCDIR}/configure" --host=i386-pc-msdosdjgpp --prefix=/ --bindir=/ --libdir=/ --disable-imlib2 --disable-doc --disable-ruby --disable-csharp --disable-cxx
|
||||
make pkglibdir=/lib pkgdatadir=/data
|
||||
# Install into our private directory
|
||||
make install DESTDIR="${INSTALLDIR}" pkglibdir=/lib pkgdatadir=/
|
||||
cd "${SRCDIR}"
|
||||
rm -Rf "${BUILDDIR}"
|
||||
|
||||
i386-pc-msdosdjgpp-strip "${INSTALLDIR}/"*.exe
|
||||
|
||||
mkdir "${INSTALLDIR}/doc"
|
||||
for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do
|
||||
sed -e 's/$/^M/' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt"
|
||||
done
|
||||
|
||||
rm -Rf "${INSTALLDIR}/share"
|
||||
rm -Rf "${INSTALLDIR}/man"
|
||||
rm -Rf "${INSTALLDIR}/include"
|
||||
rm -Rf "${INSTALLDIR}/pkg-config"
|
||||
rm -f "${INSTALLDIR}/caca-config"
|
||||
rm -f "${INSTALLDIR}/"*.a
|
||||
rm -f "${INSTALLDIR}/"*.la
|
||||
|
||||
# Pack the directory
|
||||
zip "${DIRNAME}.zip" `find "${DIRNAME}"`
|
||||
rm -Rf "${INSTALLDIR}"
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#! /bin/sh
|
||||
|
||||
## Kernel-mode libcaca compilation script -- Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
MYCFLAGS="-fno-builtin -O0 -I. -I.. -I../caca/ -Wall -D__KERNEL__ -fno-stack-protector -m32"
|
||||
|
||||
./configure --enable-kernel --disable-doc --host i386
|
||||
|
||||
# Compile cacademo, leave it as an object
|
||||
cd caca && make && cd ..
|
||||
cd examples && make dithering.o && cd ..
|
||||
|
||||
cd kernel
|
||||
|
||||
# Bootsector
|
||||
nasm -f bin -o bootsect.bin boot/bootsect.asm
|
||||
# Interruption handlers
|
||||
nasm -f elf -o int.o boot/int.asm
|
||||
|
||||
##### Boot (x86)
|
||||
# Stage2, loads GDT, PIC, IDT, interrupts, then calls kmain()
|
||||
gcc $MYCFLAGS boot/stage2.c -c
|
||||
# GDT installation, called by stage2
|
||||
gcc $MYCFLAGS boot/gdt.c -c
|
||||
# PIC installation, called by stage2
|
||||
gcc $MYCFLAGS boot/pic.c -c
|
||||
# IDT installation, called by stage2
|
||||
gcc $MYCFLAGS boot/idt.c -c
|
||||
# Interruptions installation, called by stage2
|
||||
gcc $MYCFLAGS boot/interruptions.c -c
|
||||
|
||||
##### Drivers
|
||||
# Floppy driver
|
||||
gcc $MYCFLAGS drivers/floppy.c -c
|
||||
# Processor driver
|
||||
gcc $MYCFLAGS drivers/processor.c -c
|
||||
# Keyboard handler
|
||||
gcc $MYCFLAGS drivers/keyboard.c -c
|
||||
# Memory driver
|
||||
gcc $MYCFLAGS drivers/memory.c -c
|
||||
# Programmable Interval Timer driver
|
||||
gcc $MYCFLAGS drivers/timer.c -c
|
||||
|
||||
# Minimalistic libc
|
||||
gcc $MYCFLAGS klibc.c -c
|
||||
|
||||
# Kernel by itself, contains cmain() which calls main()
|
||||
gcc $MYCFLAGS kernel.c -c
|
||||
|
||||
# Link everything but bootsector, kernel.o MUST be at the very end
|
||||
ld --oformat binary -Ttext 1000 stage2.o gdt.o pic.o int.o idt.o interruptions.o keyboard.o memory.o timer.o floppy.o processor.o klibc.o kernel.o ../caca/.libs/libcaca.a -Map kernel.map -o kern.bin
|
||||
|
||||
ls -ail kern.bin
|
||||
cd ..
|
||||
|
||||
# Copy bootsector at the very beginning of the floppy (first sector/512 bytes of the image), then kernel right after
|
||||
cat kernel/bootsect.bin kernel/kern.bin /dev/zero | dd of=cacademo.img bs=512 count=2500
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#! /bin/sh
|
||||
|
||||
## Win32 cross-compilation for libcaca -- Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Clean up our working directory
|
||||
SRCDIR="`pwd`"
|
||||
DIRNAME="libcaca-win32-`sed -ne 's/^AC_INIT(.*, \(.*\)).*/\1/p' configure.ac`"
|
||||
INSTALLDIR="`pwd`/${DIRNAME}"
|
||||
BUILDDIR="${INSTALLDIR}/build"
|
||||
rm -Rf "${INSTALLDIR}"
|
||||
rm -f "${INSTALLDIR}.zip"
|
||||
mkdir "${INSTALLDIR}"
|
||||
mkdir "${BUILDDIR}"
|
||||
|
||||
make distclean || true
|
||||
|
||||
cd "${BUILDDIR}"
|
||||
# Build for win32
|
||||
"${SRCDIR}/configure" --host=i686-w64-mingw32 --build=none --prefix=/ --bindir=/bin --libdir=/lib --disable-imlib2 --disable-java --disable-doc "$@"
|
||||
make -j4 pkglibdir=/lib pkgdatadir=/data bindir=/bin
|
||||
# Install into our private directory
|
||||
make -j4 install DESTDIR="${INSTALLDIR}" pkglibdir=/lib/ pkgdatadir=/ bindir=/bin/
|
||||
cd "${SRCDIR}"
|
||||
rm -Rf "${BUILDDIR}"
|
||||
|
||||
mv "${INSTALLDIR}/bin/"* "${INSTALLDIR}/"
|
||||
rmdir "${INSTALLDIR}/bin"
|
||||
mv "${INSTALLDIR}/lib/"* "${INSTALLDIR}/"
|
||||
for f in caca caca++; do
|
||||
mv "${INSTALLDIR}/lib${f}.a" "${INSTALLDIR}/lib/${f}.lib"
|
||||
done
|
||||
rm -f "${INSTALLDIR}/caca-config.exe" # Just in case. *sigh*.
|
||||
i686-w64-mingw32-strip "${INSTALLDIR}/"*.exe || true
|
||||
i686-w64-mingw32-strip "${INSTALLDIR}/"*.dll || true
|
||||
|
||||
mkdir "${INSTALLDIR}/doc"
|
||||
for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do
|
||||
sed -e 's/$/
/' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt"
|
||||
done
|
||||
rm -Rf "${INSTALLDIR}/share"
|
||||
rm -Rf "${INSTALLDIR}/man"
|
||||
rm -Rf "${INSTALLDIR}/pkgconfig"
|
||||
rm -f "${INSTALLDIR}/caca-config"
|
||||
rm -f "${INSTALLDIR}/"*.a
|
||||
rm -f "${INSTALLDIR}/"*.la
|
||||
|
||||
# Pack the directory
|
||||
zip "${DIRNAME}.zip" `find "${DIRNAME}"`
|
||||
rm -Rf "${INSTALLDIR}"
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#! /bin/sh
|
||||
|
||||
## Win32 cross-compilation for libcaca -- Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
set -x
|
||||
set -e
|
||||
|
||||
# Clean up our working directory
|
||||
SRCDIR="`pwd`"
|
||||
DIRNAME="libcaca-win64-`sed -ne 's/^AC_INIT(.*, \(.*\)).*/\1/p' configure.ac`"
|
||||
INSTALLDIR="`pwd`/${DIRNAME}"
|
||||
BUILDDIR="${INSTALLDIR}/build"
|
||||
rm -Rf "${INSTALLDIR}"
|
||||
rm -f "${INSTALLDIR}.zip"
|
||||
mkdir "${INSTALLDIR}"
|
||||
mkdir "${BUILDDIR}"
|
||||
|
||||
make distclean || true
|
||||
|
||||
cd "${BUILDDIR}"
|
||||
# Build for win64
|
||||
"${SRCDIR}/configure" --host=x86_64-w64-mingw32 --build=none --prefix=/ --bindir=/bin --libdir=/lib --disable-imlib2 --disable-java --disable-doc "$@"
|
||||
make -j4 pkglibdir=/lib pkgdatadir=/data bindir=/bin
|
||||
# Install into our private directory
|
||||
make -j4 install DESTDIR="${INSTALLDIR}" pkglibdir=/lib/ pkgdatadir=/ bindir=/bin/
|
||||
cd "${SRCDIR}"
|
||||
rm -Rf "${BUILDDIR}"
|
||||
|
||||
mv "${INSTALLDIR}/bin/"* "${INSTALLDIR}/"
|
||||
rmdir "${INSTALLDIR}/bin"
|
||||
mv "${INSTALLDIR}/lib/"* "${INSTALLDIR}/"
|
||||
for f in caca caca++; do
|
||||
mv "${INSTALLDIR}/lib${f}.a" "${INSTALLDIR}/lib/${f}.lib"
|
||||
done
|
||||
rm -f "${INSTALLDIR}/caca-config.exe" # Just in case. *sigh*.
|
||||
x86_64-w64-mingw32-strip "${INSTALLDIR}/"*.exe || true
|
||||
x86_64-w64-mingw32-strip "${INSTALLDIR}/"*.dll || true
|
||||
|
||||
mkdir "${INSTALLDIR}/doc"
|
||||
for f in COPYING COPYING.LGPL COPYING.GPL README AUTHORS NEWS NOTES THANKS; do
|
||||
sed -e 's/$/
/' < "${SRCDIR}/${f}" > "${INSTALLDIR}/doc/${f}.txt"
|
||||
done
|
||||
rm -Rf "${INSTALLDIR}/share"
|
||||
rm -Rf "${INSTALLDIR}/man"
|
||||
rm -Rf "${INSTALLDIR}/pkgconfig"
|
||||
rm -f "${INSTALLDIR}/caca-config"
|
||||
rm -f "${INSTALLDIR}/"*.a
|
||||
rm -f "${INSTALLDIR}/"*.la
|
||||
|
||||
# Pack the directory
|
||||
zip "${DIRNAME}.zip" `find "${DIRNAME}"`
|
||||
rm -Rf "${INSTALLDIR}"
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
#! /bin/sh
|
||||
|
||||
## config script for libcaca -- Sam Hocevar <sam@hocevar.net>
|
||||
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
|
||||
lib_dir=@libdir@
|
||||
include_dir=@includedir@
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage: caca-config [OPTIONS] [LIBRARIES]
|
||||
Options:
|
||||
[--prefix[=DIR]]
|
||||
[--exec-prefix[=DIR]]
|
||||
[--version]
|
||||
[--libs]
|
||||
[--ldflags]
|
||||
[--cflags]
|
||||
EOF
|
||||
exit $1
|
||||
}
|
||||
|
||||
libs=""
|
||||
|
||||
if test $# -eq 0
|
||||
then
|
||||
usage 1 1>&2
|
||||
fi
|
||||
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "$1" in
|
||||
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
|
||||
*) optarg= ;;
|
||||
esac
|
||||
|
||||
case $1 in
|
||||
--prefix=*)
|
||||
prefix=$optarg
|
||||
local_prefix=yes
|
||||
;;
|
||||
--prefix)
|
||||
echo_prefix=yes
|
||||
;;
|
||||
--exec-prefix=*)
|
||||
exec_prefix=$optarg
|
||||
exec_prefix_set=yes
|
||||
local_prefix=yes
|
||||
;;
|
||||
--exec-prefix)
|
||||
echo_exec_prefix=yes
|
||||
;;
|
||||
--version)
|
||||
echo @VERSION@
|
||||
exit 0
|
||||
;;
|
||||
--cflags)
|
||||
echo_cflags=yes
|
||||
;;
|
||||
--ldflags)
|
||||
echo_ldflags=yes
|
||||
;;
|
||||
--libs | --plugin-libs)
|
||||
echo_libs=yes
|
||||
;;
|
||||
caca)
|
||||
libs="$libs -lcaca"
|
||||
;;
|
||||
*)
|
||||
usage 1 1>&2
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if test "$libs" = ""
|
||||
then
|
||||
libs="-lcaca"
|
||||
fi
|
||||
|
||||
if test "$local_prefix" = "yes"
|
||||
then
|
||||
if test "$exec_prefix_set" != "yes"
|
||||
then
|
||||
exec_prefix=$prefix
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "$echo_prefix" = "yes"
|
||||
then
|
||||
echo $prefix
|
||||
fi
|
||||
|
||||
if test "$echo_exec_prefix" = "yes"
|
||||
then
|
||||
echo $exec_prefix
|
||||
fi
|
||||
|
||||
if test "$echo_cflags" = "yes"
|
||||
then
|
||||
cflags="-I$include_dir/"
|
||||
echo $cflags
|
||||
fi
|
||||
|
||||
if test "$echo_ldflags" = "yes"
|
||||
then
|
||||
ldflags="-L$lib_dir"
|
||||
echo $ldflags
|
||||
fi
|
||||
|
||||
if test "$echo_libs" = "yes"
|
||||
then
|
||||
echo -L@libdir@ $libs
|
||||
fi
|
||||
|
|
@ -0,0 +1,583 @@
|
|||
<?php
|
||||
/*
|
||||
* php-caca Php binding for Libcaca
|
||||
* caca.php object layer for caca-php
|
||||
* Copyright (c) 2008 Vion Nicolas <nico@picapo.net>
|
||||
*
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
class Libcaca
|
||||
{
|
||||
static function Rand($min, $max)
|
||||
{
|
||||
return caca_rand($min, $max);
|
||||
}
|
||||
|
||||
static function getVersion()
|
||||
{
|
||||
return caca_get_version();
|
||||
}
|
||||
}
|
||||
|
||||
class AnsiColor
|
||||
{
|
||||
const BLACK = CACA_BLACK;
|
||||
const BLUE = CACA_BLUE;
|
||||
const GREEN = CACA_GREEN;
|
||||
const CYAN = CACA_CYAN;
|
||||
const RED = CACA_RED;
|
||||
const MAGENTA = CACA_MAGENTA;
|
||||
const BROWN = CACA_BROWN;
|
||||
const LIGHTGRAY = CACA_LIGHTGRAY;
|
||||
const DARKGRAY = CACA_DARKGRAY;
|
||||
const LIGHTBLUE = CACA_LIGHTBLUE;
|
||||
const LIGHTGREEN = CACA_LIGHTGREEN;
|
||||
const LIGHTCYAN = CACA_LIGHTCYAN;
|
||||
const LIGHTRED = CACA_LIGHTRED;
|
||||
const LIGHTMAGENTA = CACA_LIGHTMAGENTA;
|
||||
const YELLOW = CACA_YELLOW;
|
||||
const WHITE = CACA_WHITE;
|
||||
/* NOTE: We can't call this one DEFAULT because that's a reserved
|
||||
* token in PHP. */
|
||||
const DEFAULTCOLOR = CACA_DEFAULT;
|
||||
const TRANSPARENT = CACA_TRANSPARENT;
|
||||
}
|
||||
|
||||
class Canvas {
|
||||
private $cv;
|
||||
|
||||
function importFile($path, $codec) {
|
||||
return caca_import_file($this->cv, $path, $codec);
|
||||
}
|
||||
|
||||
function importString($str, $codec) {
|
||||
return caca_import_string($this->cv, $str, $codec);
|
||||
}
|
||||
|
||||
function exportString($codec) {
|
||||
return caca_export_string($this->cv, $codec);
|
||||
}
|
||||
|
||||
function freeFrame($id) {
|
||||
return caca_free_frame($this->cv, $id);
|
||||
}
|
||||
|
||||
function frameCount() {
|
||||
return caca_get_frame_count($this->cv);
|
||||
}
|
||||
|
||||
function createFrame($id) {
|
||||
return caca_create_frame($this->cv, $id);
|
||||
}
|
||||
|
||||
function setFrameName($name) {
|
||||
return caca_set_frame_name($this->cv, $name);
|
||||
}
|
||||
|
||||
function setFrame($id) {
|
||||
return caca_set_frame($this->cv, $id);
|
||||
}
|
||||
|
||||
function putFigchar($char) {
|
||||
return caca_put_figchar($this->cv, $char);
|
||||
}
|
||||
|
||||
function setFigfont($path) {
|
||||
return caca_canvas_set_figfont($this->cv, $path);
|
||||
}
|
||||
|
||||
function putAttr($attr) {
|
||||
return caca_put_attr($this->cv, $attr);
|
||||
}
|
||||
|
||||
function stretchRight() {
|
||||
return caca_stretch_right($this->cv);
|
||||
}
|
||||
|
||||
function stretchLeft() {
|
||||
return caca_stretch_left($this->cv);
|
||||
}
|
||||
|
||||
function setBoundaries($width, $height) {
|
||||
return caca_set_canvas_boundaries($this->cv, $width, $height);
|
||||
}
|
||||
|
||||
function setHandle($x, $y) {
|
||||
return caca_set_canvas_handle($this->cv, $x, $y);
|
||||
}
|
||||
|
||||
function getHandleX() {
|
||||
return caca_get_canvas_handle_x($this->cv);
|
||||
}
|
||||
|
||||
function getHandleY() {
|
||||
return caca_get_canvas_handle_y($this->cv);
|
||||
}
|
||||
|
||||
function whereX() {
|
||||
return caca_wherex($this->cv);
|
||||
}
|
||||
|
||||
function whereY() {
|
||||
return caca_wherey($this->cv);
|
||||
}
|
||||
|
||||
function getChars() {
|
||||
return caca_get_canvas_chars($this->cv);
|
||||
}
|
||||
|
||||
function getAttrs() {
|
||||
return caca_get_canvas_attrs($this->cv);
|
||||
}
|
||||
|
||||
function setSize($width, $height) {
|
||||
return caca_set_canvas_size($this->cv, $width, $height);
|
||||
}
|
||||
|
||||
function getWidth() {
|
||||
return caca_get_canvas_width($this->cv);
|
||||
}
|
||||
|
||||
function getHeight() {
|
||||
return caca_get_canvas_height($this->cv);
|
||||
}
|
||||
|
||||
function getAttr($x, $y) {
|
||||
return caca_get_attr($this->cv, $x, $y);
|
||||
}
|
||||
|
||||
function setAttr($attr) {
|
||||
return caca_set_attr($this->cv, $x, $y, $attr);
|
||||
}
|
||||
|
||||
function setColorANSI($foreground, $background) {
|
||||
return caca_set_color_ansi($this->cv, $foreground, $background);
|
||||
}
|
||||
|
||||
function setColorARGB($foreground, $background) {
|
||||
return caca_set_color_argb($this->cv, $foreground, $background);
|
||||
}
|
||||
|
||||
function putChar($x, $y, $c) {
|
||||
return caca_put_char($this->cv, $x, $y, $c);
|
||||
}
|
||||
|
||||
function getChar($x, $y) {
|
||||
return caca_get_char($this->cv, $x, $y);
|
||||
}
|
||||
|
||||
function putStr($x, $y, $str) {
|
||||
return caca_put_str($this->cv, $x, $y, $str);
|
||||
}
|
||||
|
||||
function Clear() {
|
||||
return caca_clear_canvas($this->cv);
|
||||
}
|
||||
|
||||
function Blit($x, $y, $canvas, $mask = NULL) {
|
||||
if($mask)
|
||||
return caca_blit($this->cv, $x, $y, $canvas->get_resource(), $mask->get_resource());
|
||||
return caca_blit($this->cv, $x, $y, $canvas->get_resource());
|
||||
}
|
||||
|
||||
function Invert() {
|
||||
return caca_invert($this->cv);
|
||||
}
|
||||
|
||||
function Flip() {
|
||||
return caca_flip($this->cv);
|
||||
}
|
||||
|
||||
function Flop() {
|
||||
return caca_flop($this->cv);
|
||||
}
|
||||
|
||||
function Rotate180() {
|
||||
return caca_rotate_180($this->cv);
|
||||
}
|
||||
|
||||
function RotateLeft() {
|
||||
return caca_rotate_left($this->cv);
|
||||
}
|
||||
|
||||
function RotateRight() {
|
||||
return caca_rotate_right($this->cv);
|
||||
}
|
||||
|
||||
function drawLine($x1, $y1, $x2, $y2, $char) {
|
||||
return caca_draw_line($this->cv, $x1, $y1, $x2, $y2, $char);
|
||||
}
|
||||
|
||||
function drawPolyline($points, $char) {
|
||||
return caca_draw_polyline($this->cv, $points, $char);
|
||||
}
|
||||
|
||||
function drawThinLine($x1, $y1, $x2, $y2) {
|
||||
return caca_draw_thin_line($this->cv, $x1, $y1, $x2, $y2);
|
||||
}
|
||||
|
||||
function drawThinPolyline($points) {
|
||||
return caca_draw_thin_polyline($this->cv, $points);
|
||||
}
|
||||
|
||||
function drawCircle($x, $y, $radius, $char) {
|
||||
return caca_draw_circle($this->cv, $x, $y, $radius, $char);
|
||||
}
|
||||
|
||||
function drawEllipse($x1, $y1, $x2, $y2, $char) {
|
||||
return caca_draw_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
|
||||
}
|
||||
|
||||
function drawThinEllipse($x1, $y1, $x2, $y2) {
|
||||
return caca_draw_thin_ellipse($this->cv, $x1, $y1, $x2, $y2);
|
||||
}
|
||||
|
||||
function fillEllipse($x1, $y1, $x2, $y2, $char) {
|
||||
return caca_fill_ellipse($this->cv, $x1, $y1, $x2, $y2, $char);
|
||||
}
|
||||
|
||||
function drawBox($x1, $y1, $x2, $y2, $char) {
|
||||
return caca_draw_box($this->cv, $x1, $y1, $x2, $y2, $char);
|
||||
}
|
||||
|
||||
function drawThinBox($x1, $y1, $x2, $y2) {
|
||||
return caca_draw_thin_box($this->cv, $x1, $y1, $x2, $y2);
|
||||
}
|
||||
|
||||
function drawCP437Box($x1, $y1, $x2, $y2) {
|
||||
return caca_draw_cp437_box($this->cv, $x1, $y1, $x2, $y2);
|
||||
}
|
||||
|
||||
function fillBox($x1, $y1, $x2, $y2, $char) {
|
||||
return caca_fill_box($this->cv, $x1, $y1, $x2, $y2, $char);
|
||||
}
|
||||
|
||||
function drawTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) {
|
||||
return caca_draw_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char);
|
||||
}
|
||||
|
||||
function drawThinTriangle($x1, $y1, $x2, $y2, $x3, $y3) {
|
||||
return caca_draw_thin_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3);
|
||||
}
|
||||
|
||||
function fillTriangle($x1, $y1, $x2, $y2, $x3, $y3, $char) {
|
||||
return caca_fill_triangle($this->cv, $x1, $y1, $x2, $y2, $x3, $y3, $char);
|
||||
}
|
||||
|
||||
function __construct($width = 0, $height = 0) {
|
||||
$this->cv = caca_create_canvas($width, $height);
|
||||
}
|
||||
|
||||
function get_resource() {
|
||||
return $this->cv;
|
||||
}
|
||||
}
|
||||
|
||||
class EventType
|
||||
{
|
||||
const NONE = CACA_EVENT_NONE;
|
||||
|
||||
const KEY_PRESS = CACA_EVENT_KEY_PRESS;
|
||||
const KEY_RELEASE = CACA_EVENT_KEY_RELEASE;
|
||||
const MOUSE_PRESS = CACA_EVENT_MOUSE_PRESS;
|
||||
const MOUSE_RELEASE = CACA_EVENT_MOUSE_RELEASE;
|
||||
const MOUSE_MOTION = CACA_EVENT_MOUSE_MOTION;
|
||||
const RESIZE = CACA_EVENT_RESIZE;
|
||||
const QUIT = CACA_EVENT_QUIT;
|
||||
|
||||
const ANY = CACA_EVENT_ANY;
|
||||
}
|
||||
|
||||
class EventKey
|
||||
{
|
||||
const UNKNOWN = CACA_KEY_UNKNOWN;
|
||||
|
||||
const CTRL_A = CACA_KEY_CTRL_A;
|
||||
const CTRL_B = CACA_KEY_CTRL_B;
|
||||
const CTRL_C = CACA_KEY_CTRL_C;
|
||||
const CTRL_D = CACA_KEY_CTRL_D;
|
||||
const CTRL_E = CACA_KEY_CTRL_E;
|
||||
const CTRL_F = CACA_KEY_CTRL_F;
|
||||
const CTRL_G = CACA_KEY_CTRL_G;
|
||||
const BACKSPACE = CACA_KEY_BACKSPACE;
|
||||
const TAB = CACA_KEY_TAB;
|
||||
const CTRL_J = CACA_KEY_CTRL_J;
|
||||
const CTRL_K = CACA_KEY_CTRL_K;
|
||||
const CTRL_L = CACA_KEY_CTRL_L;
|
||||
/* NOTE: We can't call this one RETURN because that's a
|
||||
* reserved token in PHP */
|
||||
const RETURN_KEY = CACA_KEY_RETURN;
|
||||
const CTRL_N = CACA_KEY_CTRL_N;
|
||||
const CTRL_O = CACA_KEY_CTRL_O;
|
||||
const CTRL_P = CACA_KEY_CTRL_P;
|
||||
const CTRL_Q = CACA_KEY_CTRL_Q;
|
||||
const CTRL_R = CACA_KEY_CTRL_R;
|
||||
const PAUSE = CACA_KEY_PAUSE;
|
||||
const CTRL_T = CACA_KEY_CTRL_T;
|
||||
const CTRL_U = CACA_KEY_CTRL_U;
|
||||
const CTRL_V = CACA_KEY_CTRL_V;
|
||||
const CTRL_W = CACA_KEY_CTRL_W;
|
||||
const CTRL_X = CACA_KEY_CTRL_X;
|
||||
const CTRL_Y = CACA_KEY_CTRL_Y;
|
||||
const CTRL_Z = CACA_KEY_CTRL_Z;
|
||||
const ESCAPE = CACA_KEY_ESCAPE;
|
||||
const DELETE = CACA_KEY_DELETE;
|
||||
|
||||
const UP = CACA_KEY_UP;
|
||||
const DOWN = CACA_KEY_DOWN;
|
||||
const LEFT = CACA_KEY_LEFT;
|
||||
const RIGHT = CACA_KEY_RIGHT;
|
||||
|
||||
const INSERT = CACA_KEY_INSERT;
|
||||
const HOME = CACA_KEY_HOME;
|
||||
const END = CACA_KEY_END;
|
||||
const PAGEUP = CACA_KEY_PAGEUP;
|
||||
const PAGEDOWN = CACA_KEY_PAGEDOWN;
|
||||
|
||||
const F1 = CACA_KEY_F1;
|
||||
const F2 = CACA_KEY_F2;
|
||||
const F3 = CACA_KEY_F3;
|
||||
const F4 = CACA_KEY_F4;
|
||||
const F5 = CACA_KEY_F5;
|
||||
const F6 = CACA_KEY_F6;
|
||||
const F7 = CACA_KEY_F7;
|
||||
const F8 = CACA_KEY_F8;
|
||||
const F9 = CACA_KEY_F9;
|
||||
const F10 = CACA_KEY_F10;
|
||||
const F11 = CACA_KEY_F11;
|
||||
const F12 = CACA_KEY_F12;
|
||||
const F13 = CACA_KEY_F13;
|
||||
const F14 = CACA_KEY_F14;
|
||||
const F15 = CACA_KEY_F15;
|
||||
}
|
||||
|
||||
class Event {
|
||||
private $ev;
|
||||
|
||||
function getType() {
|
||||
return caca_get_event_type($this->ev);
|
||||
}
|
||||
|
||||
function getKeyCh() {
|
||||
return caca_get_event_key_ch($this->ev);
|
||||
}
|
||||
|
||||
function getMouseX() {
|
||||
return caca_get_event_mouse_x($this->ev);
|
||||
}
|
||||
|
||||
function getResizeWidth() {
|
||||
return caca_get_event_resize_width($this->ev);
|
||||
}
|
||||
|
||||
function getResizeHeight() {
|
||||
return caca_get_event_resize_height($this->ev);
|
||||
}
|
||||
|
||||
function __construct($_ev) {
|
||||
$this->ev = $_ev;
|
||||
}
|
||||
|
||||
function get_resource() {
|
||||
return $this->ev;
|
||||
}
|
||||
}
|
||||
|
||||
class Display {
|
||||
private $dp;
|
||||
|
||||
function setCursor($visible) {
|
||||
return caca_set_cursor($this->dp, $visible);
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
return caca_refresh_display($this->dp);
|
||||
}
|
||||
|
||||
function getDriver() {
|
||||
return caca_get_display_driver($this->dp);
|
||||
}
|
||||
|
||||
function setDriver($name) {
|
||||
return caca_set_display_driver($this->dp, $name);
|
||||
}
|
||||
|
||||
function setDisplayTime($time) {
|
||||
return caca_set_display_time($this->dp, $time);
|
||||
}
|
||||
|
||||
function getDisplayTime() {
|
||||
return caca_get_display_time($this->dp);
|
||||
}
|
||||
|
||||
function getWidth() {
|
||||
return caca_get_display_width($this->dp);
|
||||
}
|
||||
|
||||
function getHeight() {
|
||||
return caca_get_display_height($this->dp);
|
||||
}
|
||||
|
||||
function setTitle($title) {
|
||||
return caca_set_display_title($this->dp, $title);
|
||||
}
|
||||
|
||||
function gotoXY($x, $y) {
|
||||
return caca_gotoxy($this->dp, $x, $y);
|
||||
}
|
||||
|
||||
function getMouseX() {
|
||||
return caca_get_mouse_x($this->dp);
|
||||
}
|
||||
|
||||
function getMouseY() {
|
||||
return caca_get_mouse_y($this->dp);
|
||||
}
|
||||
|
||||
function setMouse($state) {
|
||||
return caca_set_mouse($this->dp, $state);
|
||||
}
|
||||
|
||||
function getEvent($t, $timeout = 0) {
|
||||
$ev = caca_get_event($this->dp, $t, $timeout);
|
||||
if(! $ev) {
|
||||
return NULL;
|
||||
}
|
||||
return new Event($ev);
|
||||
}
|
||||
|
||||
function __construct($canvas, $driver = NULL) {
|
||||
if($driver)
|
||||
$this->dp = caca_create_display_with_driver($canvas->get_resource(), $driver);
|
||||
else
|
||||
$this->dp = caca_create_display($canvas->get_resource());
|
||||
}
|
||||
|
||||
function get_resource() {
|
||||
return $this->dp;
|
||||
}
|
||||
}
|
||||
|
||||
class Dither {
|
||||
private $dt;
|
||||
private $img;
|
||||
|
||||
function setPalette($colors) {
|
||||
return caca_set_dither_palette($this->dt, $colors);
|
||||
}
|
||||
|
||||
function setBrightness($value) {
|
||||
return caca_set_dither_brightness($this->dt, $value);
|
||||
}
|
||||
|
||||
function getBrightness() {
|
||||
return caca_get_dither_brightness($this->dt);
|
||||
}
|
||||
|
||||
function setGamme($value) {
|
||||
return caca_set_dither_gamma($this->dt, $value);
|
||||
}
|
||||
|
||||
function getGamma() {
|
||||
return caca_get_dither_gamma($this->dt);
|
||||
}
|
||||
|
||||
function setContrast($value) {
|
||||
return caca_set_dither_contrast($this->dt, $value);
|
||||
}
|
||||
|
||||
function getContrast() {
|
||||
return caca_get_dither_contrast($this->dt);
|
||||
}
|
||||
|
||||
function setAntialias($value) {
|
||||
return caca_set_dither_antialias($this->dt, $value);
|
||||
}
|
||||
|
||||
function getAntialiasList() {
|
||||
return caca_get_dither_antialias_list($this->dt);
|
||||
}
|
||||
|
||||
function getAntialias() {
|
||||
return caca_get_dither_antialias($this->dt);
|
||||
}
|
||||
|
||||
function setColor($color) {
|
||||
return caca_set_dither_color($this->dt, $color);
|
||||
}
|
||||
|
||||
function getColorList() {
|
||||
return caca_get_dither_color_list($this->dt);
|
||||
}
|
||||
|
||||
function getColor() {
|
||||
return caca_get_dither_color($this->dt);
|
||||
}
|
||||
|
||||
function setCharset($value) {
|
||||
return caca_set_dither_charset($this->dt, $value);
|
||||
}
|
||||
|
||||
function getCharsetList() {
|
||||
return caca_get_dither_charset_list($this->dt);
|
||||
}
|
||||
|
||||
function getCharset() {
|
||||
return caca_get_dither_charset($this->dt);
|
||||
}
|
||||
|
||||
function setAlgorithm($name) {
|
||||
return caca_set_dither_algorithm($this->dt, $name);
|
||||
}
|
||||
|
||||
function getAlgorithmList() {
|
||||
return caca_get_dither_algorithm_list($this->dt);
|
||||
}
|
||||
|
||||
function getAlgorithm() {
|
||||
return caca_get_dither_algorithm($this->dt);
|
||||
}
|
||||
|
||||
function bitmap($canvas, $x, $y, $width, $height, $load_palette = true) {
|
||||
return caca_dither_bitmap($canvas->get_resource(), $x, $y, $width, $height, $this->dt, $this->img, $load_palette);
|
||||
}
|
||||
|
||||
function __construct($image) {
|
||||
$this->dt = caca_create_dither($image);
|
||||
$this->img = $image;
|
||||
}
|
||||
}
|
||||
|
||||
class Font {
|
||||
private $f;
|
||||
|
||||
function getWidth() {
|
||||
return caca_get_font_width($this->f);
|
||||
}
|
||||
|
||||
function getHeight() {
|
||||
return caca_get_font_height($this->f);
|
||||
}
|
||||
|
||||
function getBlocks() {
|
||||
return caca_get_font_blocks($this->f);
|
||||
}
|
||||
|
||||
function Render($cv, $image) {
|
||||
return caca_render_canvas($cv->get_resource(), $this->f, $image);
|
||||
}
|
||||
|
||||
static function getList() {
|
||||
return caca_get_font_list();
|
||||
}
|
||||
|
||||
function __construct($name) {
|
||||
$this->f = caca_load_builtin_font($name);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
PHP_ARG_ENABLE(caca, whether to enable Libcaca support,
|
||||
[ --enable-caca Enable Libcaca support])
|
||||
|
||||
if test "$PHP_CACA" = "yes"; then
|
||||
AC_CHECK_LIB(caca, caca_get_version, [
|
||||
PHP_ADD_LIBRARY(caca,, CACA_SHARED_LIBADD)
|
||||
], [
|
||||
AC_MSG_ERROR(libcaca development files required !)
|
||||
])
|
||||
|
||||
AC_CHECK_LIB(gd, gdImageSetPixel, [
|
||||
dnl PHP_ADD_LIBRARY(gd,, CACA_SHARED_LIBADD)
|
||||
AC_DEFINE(HAVE_GD, 1, [Wheter you have development files of gd])
|
||||
])
|
||||
|
||||
PHP_NEW_EXTENSION(caca, php_caca.c, $ext_shared,,)
|
||||
PHP_SUBST(CACA_SHARED_LIBADD)
|
||||
fi
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* cacainfo.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
|
||||
//--- Just for fun ---//
|
||||
|
||||
function just_for_fun() {
|
||||
|
||||
$moo = <<<EOT
|
||||
(__)
|
||||
(oo)
|
||||
/------\/
|
||||
/ | ||
|
||||
* /\---/\
|
||||
~~ ~~
|
||||
EOT;
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
|
||||
caca_import_string($cv, $moo, "text");
|
||||
|
||||
for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
|
||||
for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
|
||||
caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT);
|
||||
$a = caca_get_attr($cv, -1, -1);
|
||||
caca_put_attr($cv, $i, $j, $a);
|
||||
caca_put_attr($cv, $i + 1, $j, $a);
|
||||
}
|
||||
}
|
||||
caca_set_canvas_size($cv, 18, 6);
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
|
||||
caca_put_str($cv, 14, 0, "Moo!");
|
||||
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
|
||||
caca_put_char($cv, 14, 1, hexdec("2765")); //U+2765
|
||||
caca_put_char($cv, 16, 1, hexdec("2764")); //U+2764
|
||||
echo caca_export_string($cv, "utf8");
|
||||
}
|
||||
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
just_for_fun();
|
||||
|
||||
//--- Show caca's information ---//
|
||||
|
||||
echo "libcaca version: ".caca_get_version()."\n\n";
|
||||
echo "Available drivers:\n";
|
||||
$list = caca_get_display_driver_list();
|
||||
foreach($list as $type => $name)
|
||||
echo "* $name ($type)\n";
|
||||
echo "\n";
|
||||
|
||||
echo "Available import formats:\n";
|
||||
$list = caca_get_import_list();
|
||||
foreach($list as $format => $name)
|
||||
echo "* $name ($format)\n";
|
||||
echo "\n";
|
||||
|
||||
echo "Available export formats:\n";
|
||||
$list = caca_get_export_list();
|
||||
foreach($list as $format => $name)
|
||||
echo "* $name ($format)\n";
|
||||
echo "\n";
|
||||
|
||||
echo "Available caca fonts:\n";
|
||||
$list = caca_get_font_list();
|
||||
foreach($list as $name)
|
||||
echo "* $name\n";
|
||||
echo "\n";
|
||||
|
||||
?>
|
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* cacapig.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This file is a Php port of "cxx/cxxtest.cpp"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
include dirname($argv[0]) . '/../caca.php';
|
||||
|
||||
$pig_str = <<<EOT
|
||||
|
||||
_._ _..._ .-', _.._(`))
|
||||
'-. ` ' /-._.-' ',/
|
||||
) \ '.
|
||||
/ _ _ | \
|
||||
| a a / PHP |
|
||||
\ .-. ;
|
||||
'-('' ).-' ,' ;
|
||||
'-; | .'
|
||||
\ \ /
|
||||
| 7 .__ _.-\ \
|
||||
| | | ``/ /` /
|
||||
jgs /,_| | /,_/ /
|
||||
/,_/ '`-'
|
||||
EOT;
|
||||
|
||||
$canvas = new Canvas();
|
||||
if (!$canvas) {
|
||||
die("Error while creating main canvas\n");
|
||||
}
|
||||
|
||||
$pig = new Canvas();
|
||||
if (!$pig) {
|
||||
die("Error while creating canvas pig\n");
|
||||
}
|
||||
|
||||
$display = new Display($canvas);
|
||||
if (!$display) {
|
||||
die("Error while attaching canvas to display\n");
|
||||
}
|
||||
|
||||
|
||||
$pig->setColorANSI(AnsiColor::LIGHTMAGENTA, AnsiColor::TRANSPARENT);
|
||||
$pig->importString($pig_str, "text");
|
||||
$display->setDisplayTime(20000);
|
||||
|
||||
$x = $y = 0;
|
||||
$ix = $iy = 1;
|
||||
|
||||
while (! $display->getEvent(EventType::KEY_PRESS)) {
|
||||
// In case of resize ...
|
||||
if ($x + $pig->getWidth() - 1 >= $canvas->getWidth() || $x < 0 )
|
||||
$x = 0;
|
||||
if ($y + $pig->getHeight() - 1 >= $canvas->getHeight() || $y < 0 )
|
||||
$y = 0;
|
||||
|
||||
$canvas->Clear();
|
||||
|
||||
// Draw
|
||||
$canvas->Blit($x, $y, $pig, NULL);
|
||||
$canvas->setColorANSI(AnsiColor::LIGHTBLUE, AnsiColor::BLACK);
|
||||
$canvas->putStr($canvas->getWidth() / 2 - 10, $canvas->getHeight() / 2, "Powered by libcaca ".Libcaca::getVersion());
|
||||
$display->refresh();
|
||||
|
||||
|
||||
// Move cursor
|
||||
$x += $ix;
|
||||
$y += $iy;
|
||||
if ($x + $pig->getWidth() >= $canvas->getWidth() || $x < 0 )
|
||||
$ix = -$ix;
|
||||
if ($y + $pig->getHeight() >= $canvas->getHeight() || $y < 0 )
|
||||
$iy = -$iy;
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,62 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* colors display all possible libcaca colour pairs
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/colors.c"
|
||||
* Copyright (c) 2003-2004 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(80, 24);
|
||||
if(!$cv)
|
||||
{
|
||||
die("Failed to create canvas\n");
|
||||
}
|
||||
|
||||
$dp = caca_create_display($cv);
|
||||
if(!$dp)
|
||||
{
|
||||
die("Failed to create display\n");
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_clear_canvas($cv);
|
||||
for($i = 0; $i < 16; $i++)
|
||||
{
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_put_str($cv, 3, $i + ($i >= 8 ? 3 : 2), "ANSI " . $i);
|
||||
for($j = 0; $j < 16; $j++)
|
||||
{
|
||||
caca_set_color_ansi($cv, $i, $j);
|
||||
caca_put_str($cv, ($j >= 8 ? 13 : 12) + $j * 4, $i + ($i >= 8 ? 3 : 2),
|
||||
"Aaホ");
|
||||
}
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_put_str($cv, 3, 20, "This is bold This is blink This is italics This is underline");
|
||||
caca_set_attr($cv, CACA_BOLD);
|
||||
caca_put_str($cv, 3 + 8, 20, "bold");
|
||||
caca_set_attr($cv, CACA_BLINK);
|
||||
caca_put_str($cv, 3 + 24, 20, "blink");
|
||||
caca_set_attr($cv, CACA_ITALICS);
|
||||
caca_put_str($cv, 3 + 41, 20, "italics");
|
||||
caca_set_attr($cv, CACA_UNDERLINE);
|
||||
caca_put_str($cv, 3 + 60, 20, "underline");
|
||||
|
||||
caca_refresh_display($dp);
|
||||
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
|
||||
|
||||
?>
|
|
@ -0,0 +1,370 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* demo.php demo for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This file is a Php port of the official libcaca's sample program "demo.c"
|
||||
* which is:
|
||||
* Copyright (c) 2003 Sam Hocevar <sam@hocevar.net>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
function main() {
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if (!$cv) {
|
||||
die("Error while creating canvas\n");
|
||||
}
|
||||
|
||||
$dp = caca_create_display($cv);
|
||||
if (!$dp) {
|
||||
die("Error while attaching canvas to display\n");
|
||||
}
|
||||
|
||||
caca_set_display_time($dp, 40000);
|
||||
|
||||
/* Disable X cursor */
|
||||
caca_set_mouse($dp, 0);
|
||||
|
||||
/* Main menu */
|
||||
$bounds = $outline = $dithering = 0;
|
||||
|
||||
display_menu($cv, $dp, $bounds, $outline);
|
||||
|
||||
/* Go ! */
|
||||
$need_refresh = false;
|
||||
$quit = 0;
|
||||
while(!$quit) {
|
||||
while ($ev = caca_get_event($dp, CACA_EVENT_ANY, 1000)) {
|
||||
if (caca_get_event_type($ev) & CACA_EVENT_KEY_PRESS) {
|
||||
switch (caca_get_event_key_ch($ev)) {
|
||||
case ord('q'):
|
||||
case ord('Q'):
|
||||
case CACA_KEY_ESCAPE:
|
||||
$demo = false;
|
||||
$quit = 1;
|
||||
break;
|
||||
case ord('o'):
|
||||
case ord('O'):
|
||||
$outline = ($outline + 1) % 3;
|
||||
display_menu($cv, $dp, $bounds, $outline);
|
||||
break;
|
||||
case ord('b'):
|
||||
case ord('B'):
|
||||
$bounds = ($bounds + 1) % 2;
|
||||
display_menu($cv, $dp, $bounds, $outline);
|
||||
break;
|
||||
case ord('d'):
|
||||
case ord('D'):
|
||||
$dithering = ($dithering + 1) % 5;
|
||||
caca_set_feature($cv, $dithering);
|
||||
display_menu($cv, $dp, $bounds, $outline);
|
||||
break;
|
||||
case ord('f'):
|
||||
case ord('F'):
|
||||
demo_go($dp, "demo_all", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('1'):
|
||||
demo_go($dp, "demo_dots", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('2'):
|
||||
demo_go($dp, "demo_lines", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('3'):
|
||||
demo_go($dp, "demo_boxes", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('4'):
|
||||
demo_go($dp, "demo_triangles", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('5'):
|
||||
demo_go($dp, "demo_ellipses", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('s'):
|
||||
case ord('S'):
|
||||
demo_go($dp, "demo_sprites", $cv, $bounds, $outline);
|
||||
break;
|
||||
case ord('r'):
|
||||
case ord('R'):
|
||||
demo_go($dp, "demo_render", $cv, $bounds, $outline);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(caca_get_event_type($ev) & CACA_EVENT_MOUSE_MOTION) {
|
||||
$x = caca_get_event_mouse_x($ev);
|
||||
$y = caca_get_event_mouse_y($ev);
|
||||
display_menu($cv, $dp, $bounds, $outline, false);
|
||||
caca_set_color_ansi($cv, CACA_RED, CACA_BLACK);
|
||||
caca_put_str($cv, $x, $y, ".");
|
||||
caca_put_str($cv, $x, $y + 1, "|\\");
|
||||
$need_refresh = true;
|
||||
}
|
||||
else if(caca_get_event_type($ev) & CACA_EVENT_RESIZE) {
|
||||
display_menu($cv, $dp, $bounds, $outline);
|
||||
}
|
||||
}
|
||||
|
||||
if ($need_refresh) {
|
||||
caca_refresh_display($dp);
|
||||
$need_refresh = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function display_menu($cv, $dp, $bounds, $outline, $refresh = true) {
|
||||
$xo = caca_get_canvas_width($cv) - 2;
|
||||
$yo = caca_get_canvas_height($cv) - 2;
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_clear_canvas($cv);
|
||||
caca_draw_thin_box($cv, 1, 1, $xo, $yo);
|
||||
|
||||
caca_put_str($cv, ($xo - strlen("libcaca demo")) / 2, 3, "libcaca demo");
|
||||
caca_put_str($cv, ($xo - strlen("==============")) / 2, 4, "==============");
|
||||
|
||||
caca_put_str($cv, 4, 6, "demos:");
|
||||
caca_put_str($cv, 4, 7, "'f': full");
|
||||
caca_put_str($cv, 4, 8, "'1': dots");
|
||||
caca_put_str($cv, 4, 9, "'2': lines");
|
||||
caca_put_str($cv, 4, 10, "'3': boxes");
|
||||
caca_put_str($cv, 4, 11, "'4': triangles");
|
||||
caca_put_str($cv, 4, 12, "'5': ellipses");
|
||||
// caca_put_str($cv, 4, 13, "'c': colour");
|
||||
// caca_put_str($cv, 4, 14, "'r': render");
|
||||
|
||||
// caca_put_str($cv, 4, 15, "'s': sprites");
|
||||
|
||||
caca_put_str($cv, 4, 16, "settings:");
|
||||
caca_put_str($cv, 4, 17, "'o': outline: ".(($outline == 0) ? "none" : (($outline == 1) ? "solid" : "thin")));
|
||||
caca_put_str($cv, 4, 18, "'b': drawing boundaries: ".(($bounds == 0) ? "screen" : "infinite"));
|
||||
caca_put_str($cv, 4, $yo - 2, "'q': quit");
|
||||
|
||||
if ($refresh)
|
||||
caca_refresh_display($dp);
|
||||
}
|
||||
|
||||
function demo_go($dp, $demo, $cv, $bounds, $outline) {
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_clear_canvas($cv);
|
||||
|
||||
while (!caca_get_event($dp, CACA_EVENT_KEY_PRESS)) {
|
||||
if (function_exists($demo))
|
||||
$demo($cv, $bounds, $outline);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_draw_thin_box($cv, 1, 1, caca_get_canvas_width($cv) - 2, caca_get_canvas_height($cv) - 2);
|
||||
$rate = sprintf("%01.2f", 1000000 / caca_get_display_time($dp));
|
||||
caca_put_str($cv, 4, 1, "[$rate fps]----");
|
||||
caca_refresh_display($dp);
|
||||
}
|
||||
|
||||
display_menu($cv, $dp, $bounds, $outline);
|
||||
caca_refresh_display($dp);
|
||||
}
|
||||
|
||||
|
||||
function demo_all($cv, $bounds, $outline) {
|
||||
global $i;
|
||||
|
||||
$i++;
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_clear_canvas($cv);
|
||||
|
||||
/* Draw the sun */
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_BLACK);
|
||||
$xo = caca_get_canvas_width($cv) / 4;
|
||||
$yo = caca_get_canvas_height($cv) / 4 + 5 * sin(0.03 * $i);
|
||||
|
||||
for ($j = 0; $j < 16; $j++) {
|
||||
$xa = $xo - (30 + sin(0.03 * $i) * 8) * sin(0.03 * $i + M_PI * $j / 8);
|
||||
$ya = $yo + (15 + sin(0.03 * $i) * 4) * cos(0.03 * $i + M_PI * $j / 8);
|
||||
caca_draw_thin_line($cv, $xo, $yo, $xa, $ya);
|
||||
}
|
||||
|
||||
$j = 15 + sin(0.03 * $i) * 8;
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
|
||||
caca_fill_ellipse($cv, $xo, $yo, $j, $j / 2, ord('#'));
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_BLACK);
|
||||
caca_draw_ellipse($cv, $xo, $yo, $j, $j / 2, ord('#'));
|
||||
|
||||
/* Draw the pyramid */
|
||||
$xo = caca_get_canvas_width($cv) * 5 / 8;
|
||||
$yo = 2;
|
||||
|
||||
$xa = caca_get_canvas_width($cv) / 8 + sin(0.03 * $i) * 5;
|
||||
$ya = caca_get_canvas_height($cv) / 2 + cos(0.03 * $i) * 5;
|
||||
|
||||
$xb = caca_get_canvas_width($cv) - 10 - cos(0.02 * $i) * 10;
|
||||
$yb = caca_get_canvas_height($cv) * 3 / 4 - 5 + sin(0.02 * $i) * 5;
|
||||
|
||||
$xc = caca_get_canvas_width($cv) / 4 - sin(0.02 * $i) * 5;
|
||||
$yc = caca_get_canvas_height($cv) * 3 / 4 + cos(0.02 * $i) * 5;
|
||||
|
||||
caca_set_color_ansi($cv, CACA_GREEN, CACA_BLACK);
|
||||
caca_fill_triangle($cv, $xo, $yo, $xb, $yb, $xa, $ya, ord('%'));
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_BLACK);
|
||||
caca_draw_thin_triangle($cv, $xo, $yo, $xb, $yb, $xa, $ya);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_RED, CACA_BLACK);
|
||||
caca_fill_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc, ord('#'));
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_BLACK);
|
||||
caca_draw_thin_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_BLUE, CACA_BLACK);
|
||||
caca_fill_triangle($cv, $xo, $yo, $xb, $yb, $xc, $yc, ord('%'));
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_BLACK);
|
||||
caca_draw_thin_triangle($cv, $xo, $yo, $xb, $yb, $xc, $yc);
|
||||
|
||||
/* Draw a background triangle */
|
||||
$xa = 2;
|
||||
$ya = 2;
|
||||
|
||||
$xb = caca_get_canvas_width($cv) - 3;
|
||||
$yb = caca_get_canvas_height($cv) / 2;
|
||||
|
||||
$xc = caca_get_canvas_width($cv) / 3;
|
||||
$yc = caca_get_canvas_height($cv) - 3;
|
||||
|
||||
caca_set_color_ansi($cv, CACA_CYAN, CACA_BLACK);
|
||||
caca_draw_thin_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc);
|
||||
|
||||
$xo = caca_get_canvas_width($cv) / 2 + cos(0.027 * $i) * caca_get_canvas_width($cv) / 3;
|
||||
$yo = caca_get_canvas_height($cv) / 2 - sin(0.027 * $i) * caca_get_canvas_height($cv) / 2;
|
||||
|
||||
caca_draw_thin_line($cv, $xa, $ya, $xo, $yo);
|
||||
caca_draw_thin_line($cv, $xb, $yb, $xo, $yo);
|
||||
caca_draw_thin_line($cv, $xc, $yc, $xo, $yo);
|
||||
|
||||
/* Draw a trail behind the foreground sprite */
|
||||
for($j = $i - 60; $j < $i; $j++) {
|
||||
$delta = caca_rand(-5, 6);
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), caca_rand(0, 16));
|
||||
caca_put_char($cv,
|
||||
caca_get_canvas_width($cv) / 2 + cos(0.02 * $j) * ($delta + caca_get_canvas_width($cv) / 4),
|
||||
caca_get_canvas_height($cv) / 2 + sin(0.02 * $j) * ($delta + caca_get_canvas_height($cv) / 3),
|
||||
ord('#'));
|
||||
}
|
||||
}
|
||||
|
||||
function demo_dots($cv, $bounds, $outline) {
|
||||
$xmax = caca_get_canvas_width($cv);
|
||||
$ymax = caca_get_canvas_height($cv);
|
||||
|
||||
$chars = array('+', '-', '*', '#', 'X', '@', '%', '$', 'M', 'W');
|
||||
|
||||
for ($i = 1000; $i--;) {
|
||||
/* Putpixel */
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), caca_rand(0, 16));
|
||||
caca_put_char($cv, caca_rand(0, $xmax), caca_rand(0, $ymax), ord($chars[caca_rand(0, 9)]));
|
||||
}
|
||||
}
|
||||
|
||||
function demo_lines($cv, $bounds, $outline) {
|
||||
$w = caca_get_canvas_width($cv);
|
||||
$h = caca_get_canvas_height($cv);
|
||||
|
||||
if ($bounds) {
|
||||
$xa = caca_rand(- $w, 2 * $w); $ya = caca_rand(- $h, 2 * $h);
|
||||
$xb = caca_rand(- $w, 2 * $w); $yb = caca_rand(- $h, 2 * $h);
|
||||
}
|
||||
else {
|
||||
$xa = caca_rand(0, $w); $ya = caca_rand(0, $h);
|
||||
$xb = caca_rand(0, $w); $yb = caca_rand(0, $h);
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), CACA_BLACK);
|
||||
if ($outline > 1)
|
||||
caca_draw_thin_line($cv, $xa, $ya, $xb, $yb);
|
||||
else
|
||||
caca_draw_line($cv, $xa, $ya, $xb, $yb, ord('#'));
|
||||
}
|
||||
|
||||
function demo_boxes($cv, $bounds, $outline) {
|
||||
$w = caca_get_canvas_width($cv);
|
||||
$h = caca_get_canvas_height($cv);
|
||||
|
||||
if ($bounds) {
|
||||
$xa = caca_rand(- $w, 2 * $w); $ya = caca_rand(- $h, 2 * $h);
|
||||
$xb = caca_rand(- $w, 2 * $w); $yb = caca_rand(- $h, 2 * $h);
|
||||
}
|
||||
else {
|
||||
$xa = caca_rand(0, $w); $ya = caca_rand(0, $h);
|
||||
$xb = caca_rand(0, $w); $yb = caca_rand(0, $h);
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), caca_rand(0, 16));
|
||||
caca_fill_box($cv, $xa, $ya, $xb, $yb, ord('#'));
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), CACA_BLACK);
|
||||
if($outline == 2)
|
||||
caca_draw_thin_box($cv, $xa, $ya, $xb, $yb);
|
||||
else if($outline == 1)
|
||||
caca_draw_box($cv, $xa, $ya, $xb, $yb, ord('#'));
|
||||
}
|
||||
|
||||
function demo_ellipses($cv, $bounds, $outline) {
|
||||
$w = caca_get_canvas_width($cv);
|
||||
$h = caca_get_canvas_height($cv);
|
||||
|
||||
if ($bounds) {
|
||||
$x = caca_rand(- $w, 2 * $w); $y = caca_rand(- $h, 2 * $h);
|
||||
$a = caca_rand(0, $w); $b = caca_rand(0, $h);
|
||||
}
|
||||
else {
|
||||
do {
|
||||
$x = caca_rand(0, $w); $y = caca_rand(0, $h);
|
||||
$a = caca_rand(0, $w); $b = caca_rand(0, $h);
|
||||
} while ($x - $a < 0 || $x + $a >= $w || $y - $b < 0 || $y + $b >= $h);
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), caca_rand(0, 16));
|
||||
caca_fill_ellipse($cv, $x, $y, $a, $b, ord('#'));
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), CACA_BLACK);
|
||||
if ($outline == 2)
|
||||
caca_draw_thin_ellipse($cv, $x, $y, $a, $b);
|
||||
else if ($outline == 1)
|
||||
caca_draw_ellipse($cv, $x, $y, $a, $b, ord('#'));
|
||||
}
|
||||
|
||||
function demo_triangles($cv, $bounds, $outline) {
|
||||
$w = caca_get_canvas_width($cv);
|
||||
$h = caca_get_canvas_height($cv);
|
||||
|
||||
if ($bounds) {
|
||||
$xa = caca_rand(- $w, 2 * $w); $ya = caca_rand(- $h, 2 * $h);
|
||||
$xb = caca_rand(- $w, 2 * $w); $yb = caca_rand(- $h, 2 * $h);
|
||||
$xc = caca_rand(- $w, 2 * $w); $yc = caca_rand(- $h, 2 * $h);
|
||||
}
|
||||
else {
|
||||
$xa = caca_rand(0, $w); $ya = caca_rand(0, $h);
|
||||
$xb = caca_rand(0, $w); $yb = caca_rand(0, $h);
|
||||
$xc = caca_rand(0, $w); $yc = caca_rand(0, $h);
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), caca_rand(0, 16));
|
||||
caca_fill_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc, ord('#'));
|
||||
|
||||
caca_set_color_ansi($cv, caca_rand(0, 16), CACA_BLACK);
|
||||
if ($outline == 2)
|
||||
caca_draw_thin_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc);
|
||||
else if ($outline == 1)
|
||||
caca_draw_triangle($cv, $xa, $ya, $xb, $yb, $xc, $yc, ord('#'));
|
||||
}
|
||||
|
||||
function demo_render($cv, $bounds, $outline) {
|
||||
}
|
||||
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
main();
|
||||
|
||||
?>
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* dithering.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$img = imagecreatefrompng(dirname(__FILE__)."/logo-caca.png");
|
||||
if (!$img) {
|
||||
die("Can not open image.\n");
|
||||
}
|
||||
|
||||
$dither = caca_create_dither($img);
|
||||
if (!$dither) {
|
||||
die("Can not create dither. Maybe you compiled caca-php without gd support.\n");
|
||||
}
|
||||
|
||||
$canvas = caca_create_canvas(0, 0);
|
||||
$display = caca_create_display($canvas);
|
||||
if (!$display) {
|
||||
die("Can not create display.\n");
|
||||
}
|
||||
|
||||
caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
|
||||
caca_refresh_display($display);
|
||||
|
||||
caca_get_event($display, CACA_EVENT_KEY_PRESS, -1);
|
||||
|
||||
?>
|
|
@ -0,0 +1,134 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* export libcaca export test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/export.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
define('WIDTH', 80);
|
||||
define('HEIGHT', 32);
|
||||
|
||||
$pixels = imagecreatetruecolor(256, 256);
|
||||
|
||||
$exports = caca_get_export_list();
|
||||
|
||||
if($argc < 2 || $argc > 3)
|
||||
{
|
||||
$msg = ($argv[0] . ": wrong argument count\n" .
|
||||
"usage: " . $argv[0] . " [file] <format>\n" .
|
||||
"where <format> is one of:\n");
|
||||
foreach($exports as $format => $name)
|
||||
$msg .= " \"" . $name . "\" (" . $format . ")\n";
|
||||
die($msg);
|
||||
}
|
||||
|
||||
if($argc == 2)
|
||||
{
|
||||
$file = NULL;
|
||||
$format = $argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = $argv[1];
|
||||
$format = $argv[2];
|
||||
}
|
||||
|
||||
if(! array_key_exists($format, $exports))
|
||||
{
|
||||
$msg = ($argv[0] . ": unknown format `" . $format . "'\n" .
|
||||
"please use one of:\n");
|
||||
foreach($exports as $format => $name)
|
||||
$msg .= " \"" . $name . "\" (" . $format . ")\n";
|
||||
die($msg);
|
||||
}
|
||||
|
||||
if($file)
|
||||
{
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(caca_import_file($cv, $file, "") < 0)
|
||||
{
|
||||
die($argv[0] . ": `" . $file . "' has unknown format\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$cv = caca_create_canvas(WIDTH, HEIGHT);
|
||||
|
||||
for($y = 0; $y < 256; $y++)
|
||||
{
|
||||
for($x = 0; $x < 256; $x++)
|
||||
{
|
||||
$r = $x;
|
||||
$g = (255 - $y + $x) / 2;
|
||||
$b = $y * (255 - $x) / 256;
|
||||
imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
|
||||
}
|
||||
}
|
||||
|
||||
$dither = caca_create_dither($pixels);
|
||||
if(($format == "ansi") || ($format == "utf8"))
|
||||
caca_set_dither_charset($dither, "shades");
|
||||
caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv),
|
||||
caca_get_canvas_height($cv), $dither, $pixels);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
|
||||
caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
|
||||
caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2,
|
||||
WIDTH / 4, HEIGHT / 4, ord(' '));
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
|
||||
" lightgray on black ");
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
|
||||
" default on transparent ");
|
||||
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
|
||||
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
|
||||
" black on white ");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
|
||||
caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
|
||||
caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
|
||||
caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
|
||||
caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
|
||||
|
||||
caca_set_attr($cv, CACA_BOLD);
|
||||
caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
|
||||
caca_set_attr($cv, CACA_BLINK);
|
||||
caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
|
||||
caca_set_attr($cv, CACA_ITALICS);
|
||||
caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
|
||||
caca_set_attr($cv, CACA_UNDERLINE);
|
||||
caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
|
||||
caca_set_attr($cv, 0);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
|
||||
caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
|
||||
|
||||
for($x = 0; $x < 16; $x++)
|
||||
{
|
||||
caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4));
|
||||
caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
|
||||
}
|
||||
}
|
||||
|
||||
echo caca_export_string($cv, $format);
|
||||
|
||||
?>
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* figfont.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
function unistr_to_ords($str, $encoding = 'UTF-8'){
|
||||
$str = mb_convert_encoding($str, "UCS-4BE", $encoding);
|
||||
$result = array();
|
||||
|
||||
for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){
|
||||
$c = mb_substr($str, $i, 1, "UCS-4BE");
|
||||
$val = unpack("N", $c);
|
||||
$result[] = $val[1];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
if ($argc < 3) {
|
||||
die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
|
||||
if (!caca_canvas_set_figfont($cv, $argv[1])) {
|
||||
die("Could not open font\n");
|
||||
}
|
||||
|
||||
$chars = unistr_to_ords($argv[2]);
|
||||
$color = 0;
|
||||
foreach ($chars as $c) {
|
||||
caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
|
||||
caca_put_figchar($cv, $c);
|
||||
}
|
||||
|
||||
echo caca_export_string($cv, "utf8");
|
||||
|
||||
?>
|
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* fullwidth libcaca fullwidth Unicode characters test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/fullwidth.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
define('CACA', "쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊");
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
$dp = caca_create_display($cv);
|
||||
if(! $dp)
|
||||
{
|
||||
die("Can't create display\n");
|
||||
}
|
||||
|
||||
$caca = caca_create_canvas(6, 10);
|
||||
$line = caca_create_canvas(2, 1);
|
||||
|
||||
/* Line of x's */
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($caca, 0, $i, CACA);
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_RED);
|
||||
caca_put_char($caca, $i - 2, $i, ord('x'));
|
||||
}
|
||||
|
||||
caca_blit($cv, 1, 1, $caca);
|
||||
|
||||
/* Line of ホ's */
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($caca, 0, $i, CACA);
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_GREEN);
|
||||
caca_put_str($caca, $i - 2, $i, "ホ");
|
||||
}
|
||||
|
||||
caca_blit($cv, 15, 1, $caca);
|
||||
|
||||
/* Line of canvas */
|
||||
caca_set_color_ansi($line, CACA_WHITE, CACA_MAGENTA);
|
||||
caca_put_str($line, 0, 0, "ほ");
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($caca, 0, $i, CACA);
|
||||
caca_blit($caca, $i - 2, $i, $line);
|
||||
}
|
||||
|
||||
caca_blit($cv, 29, 1, $caca);
|
||||
|
||||
caca_refresh_display($dp);
|
||||
|
||||
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
|
||||
|
||||
?>
|
|
@ -0,0 +1,396 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* img2txt image to text converter
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "src/img2txt.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* 2007 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
class MygetoptException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
$myoptind = 0;
|
||||
|
||||
function mygetopt($shortopts, $longopts)
|
||||
{
|
||||
global $argc, $argv, $myoptind;
|
||||
if($myoptind < 0)
|
||||
{
|
||||
$myoptind = 0;
|
||||
}
|
||||
if(($myoptind + 1) >= $argc)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
$myoptind ++;
|
||||
$nextarg = $argv[$myoptind];
|
||||
$ret = NULL;
|
||||
if((substr($nextarg, 0, 1) != '-')
|
||||
||
|
||||
($nextarg == '-'))
|
||||
{
|
||||
$myoptind = $argc - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$skipopt = $myoptind;
|
||||
$skipopts = 1;
|
||||
if($nextarg == '--')
|
||||
{
|
||||
$myoptind = $argc - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt = NULL;
|
||||
$arg = NULL;
|
||||
foreach($longopts as $longopt)
|
||||
{
|
||||
$optional = false;
|
||||
$hasarg = false;
|
||||
if(($longopt != '::') && substr($longopt, -2) == '::')
|
||||
{
|
||||
$optional = true;
|
||||
$hasarg = true;
|
||||
$longopt = substr($longopt, 0, -2);
|
||||
}
|
||||
else if(($longopt != ':') && substr($longopt, -1) == ':')
|
||||
{
|
||||
$optional = false;
|
||||
$hasarg = true;
|
||||
$longopt = substr($longopt, 0, -1);
|
||||
}
|
||||
if($nextarg == ('--' . $longopt))
|
||||
{
|
||||
$opt = '--' . $longopt;
|
||||
if($hasarg && ! $optional)
|
||||
{
|
||||
if(($myoptind + 1) < $argc)
|
||||
{
|
||||
$myoptind ++;
|
||||
$skipopts ++;
|
||||
$arg = $argv[$myoptind];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MygetoptException("option \"$opt\" requires an argument");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(substr($nextarg, 0, strlen('--' . $longopt . '='))
|
||||
==
|
||||
('--' . $longopt . '='))
|
||||
{
|
||||
$opt = '--' . $longopt;
|
||||
$arg = substr($nextarg, strlen($opt . '='));
|
||||
if(! $hasarg)
|
||||
{
|
||||
throw new MygetoptException("option \"$opt\" does not allow an argument");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($opt === NULL)
|
||||
{
|
||||
for($i = 0; $i < strlen($shortopts); $i ++)
|
||||
{
|
||||
$optional = false;
|
||||
$hasarg = false;
|
||||
$shortopt = substr($shortopts, $i, 1);
|
||||
if(substr($shortopts, $i + 1, 2) == '::')
|
||||
{
|
||||
$optional = true;
|
||||
$hasarg = true;
|
||||
$i += 2;
|
||||
}
|
||||
else if(substr($shortopts, $i + 1, 1) == ':')
|
||||
{
|
||||
$hasarg = true;
|
||||
}
|
||||
if($nextarg
|
||||
==
|
||||
('-' . $shortopt))
|
||||
{
|
||||
$opt = '-' . $shortopt;
|
||||
if($hasarg && ! $optional)
|
||||
{
|
||||
if(($myoptind + 1) < $argc)
|
||||
{
|
||||
$myoptind ++;
|
||||
$skipopts ++;
|
||||
$arg = $argv[$myoptind];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MygetoptException("option \"$opt\" requires an argument");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(substr($nextarg, 0, strlen('-' . $shortopt))
|
||||
==
|
||||
('-' . $shortopt))
|
||||
{
|
||||
$opt = '-' . $shortopt;
|
||||
if($hasarg)
|
||||
{
|
||||
$arg = substr($nextarg, strlen($opt));
|
||||
}
|
||||
else
|
||||
{
|
||||
$argv[$myoptind] = '-' . substr($nextarg, strlen($opt));
|
||||
$myoptind --;
|
||||
$skipopts = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($opt === NULL)
|
||||
{
|
||||
if(substr($nextarg, 0, strlen('--')) == '--')
|
||||
{
|
||||
$longopt = substr($nextarg, strlen('--'));
|
||||
if(strpos($longopt, '=') !== false)
|
||||
{
|
||||
$longopt = substr($longopt, 0, strpos($longopt, '='));
|
||||
}
|
||||
throw new MygetoptException("option \"--$longopt\" is not recognized");
|
||||
}
|
||||
$shortopt = substr($nextarg, strlen('-'), 1);
|
||||
throw new MygetoptException("option \"-$shortopt\" is not recognized");
|
||||
}
|
||||
$ret = array($opt, $arg);
|
||||
}
|
||||
if ($skipopts > 0)
|
||||
{
|
||||
for($i = 0; $i < $argc; $i ++)
|
||||
{
|
||||
if(($i < $skipopt) || ($i >= ($skipopt + $skipopts)))
|
||||
{
|
||||
$new_argv[] = $argv[$i];
|
||||
}
|
||||
}
|
||||
if($myoptind >= $skipopt)
|
||||
{
|
||||
$myoptind -= $skipopts;
|
||||
}
|
||||
$argv = $new_argv;
|
||||
$argc = count($argv);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function usage($argc, $argv)
|
||||
{
|
||||
fprintf(STDERR, "Usage: %s [OPTIONS]... <IMAGE>\n", $argv[0]);
|
||||
fprintf(STDERR, "Convert IMAGE to any text based available format.\n");
|
||||
fprintf(STDERR, "Example : %s -W 80 -f ansi ./caca.png\n\n", $argv[0]);
|
||||
fprintf(STDERR, "Options:\n");
|
||||
fprintf(STDERR, " -h, --help\t\t\tThis help\n");
|
||||
fprintf(STDERR, " -v, --version\t\t\tVersion of the program\n");
|
||||
fprintf(STDERR, " -W, --width=WIDTH\t\tWidth of resulting image\n");
|
||||
fprintf(STDERR, " -H, --height=HEIGHT\t\tHeight of resulting image\n");
|
||||
fprintf(STDERR, " -x, --font-width=WIDTH\t\tWidth of output font\n");
|
||||
fprintf(STDERR, " -y, --font-height=HEIGHT\t\tHeight of output font\n");
|
||||
fprintf(STDERR, " -b, --brightness=BRIGHTNESS\tBrightness of resulting image\n");
|
||||
fprintf(STDERR, " -c, --contrast=CONTRAST\tContrast of resulting image\n");
|
||||
fprintf(STDERR, " -g, --gamma=GAMMA\t\tGamma of resulting image\n");
|
||||
fprintf(STDERR, " -d, --dither=DITHER\t\tDithering algorithm to use :\n");
|
||||
$list = caca_get_dither_algorithm_list(caca_create_dither(imagecreate(1, 1)));
|
||||
foreach($list as $type => $name)
|
||||
{
|
||||
fprintf(STDERR, "\t\t\t%s: %s\n", $type, $name);
|
||||
}
|
||||
|
||||
fprintf(STDERR, " -f, --format=FORMAT\t\tFormat of the resulting image :\n");
|
||||
$list = caca_get_export_list();
|
||||
foreach($list as $type => $name)
|
||||
{
|
||||
fprintf(STDERR, "\t\t\t%s: %s\n", $type, $name);
|
||||
}
|
||||
}
|
||||
|
||||
function version()
|
||||
{
|
||||
printf(
|
||||
"img2txt Copyright 2006-2007 Sam Hocevar and Jean-Yves Lamoureux\n" .
|
||||
" Copyright 2008 Benjamin C. Wiley Sittler\n" .
|
||||
"Internet: <sam@hocevar.net> <jylam@lnxscene.org>\n" .
|
||||
" <bsittler@gmail.com> Version: %s\n" .
|
||||
"\n" .
|
||||
"img2txt, along with its documentation, may be freely copied and distributed.\n" .
|
||||
"\n" .
|
||||
"The latest version of img2txt is available from the web site,\n" .
|
||||
" http://caca.zoy.org/wiki/libcaca in the libcaca package.\n" .
|
||||
"\n",
|
||||
caca_get_version());
|
||||
}
|
||||
function main()
|
||||
{
|
||||
global $argc, $argv;
|
||||
$cols = 0;
|
||||
$lines = 0;
|
||||
$font_width = 6;
|
||||
$font_height = 10;
|
||||
$format = NULL;
|
||||
$dither = NULL;
|
||||
$gamma = $brightness = $contrast = -1.0;
|
||||
|
||||
$long_options = array(
|
||||
"width:" => 'W',
|
||||
"height:" => 'H',
|
||||
"font-width:" => 'x',
|
||||
"font-height:" => 'y',
|
||||
"format:" => 'f',
|
||||
"dither:" => 'd',
|
||||
"gamma:" => 'g',
|
||||
"brightness:" => 'b',
|
||||
"contrast:" => 'c',
|
||||
"help" => 'h',
|
||||
"version" => 'v'
|
||||
);
|
||||
|
||||
try {
|
||||
while($opt_and_arg = mygetopt("W:H:f:d:g:b:c:hvx:y:", array_keys($long_options)))
|
||||
{
|
||||
$opt = $opt_and_arg[0];
|
||||
$arg = $opt_and_arg[1];
|
||||
if((substr($opt, 0, 2) == '--')
|
||||
&&
|
||||
array_key_exists(substr($opt, strlen('--')) . (($arg !== NULL) ? ':' : ''), $long_options))
|
||||
{
|
||||
$opt = '-' . $long_options[substr($opt, strlen('--')) . (($arg !== NULL) ? ':' : '')];
|
||||
}
|
||||
switch($opt)
|
||||
{
|
||||
case '-W': /* --width */
|
||||
$cols = intval($arg);
|
||||
break;
|
||||
case '-H': /* --height */
|
||||
$lines = intval($arg);
|
||||
break;
|
||||
case '-x': /* --width */
|
||||
$font_width = intval($arg);
|
||||
break;
|
||||
case '-y': /* --height */
|
||||
$font_height = intval($arg);
|
||||
break;
|
||||
case '-f': /* --format */
|
||||
$format = $arg;
|
||||
break;
|
||||
case '-d': /* --dither */
|
||||
$dither = $arg;
|
||||
break;
|
||||
case '-g': /* --gamma */
|
||||
$gamma = floatval($arg);
|
||||
break;
|
||||
case '-b': /* --brightness */
|
||||
$brightness = floatval($arg);
|
||||
break;
|
||||
case '-c': /* --contrast */
|
||||
$contrast = floatval($arg);
|
||||
break;
|
||||
case '-h': /* --help */
|
||||
usage($argc, $argv);
|
||||
return 0;
|
||||
case '-v': /* --version */
|
||||
version();
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MygetoptException $e)
|
||||
{
|
||||
fprintf(STDERR, "%s", $argv[0] . ": " . $e->getMessage() . "\n");
|
||||
usage($argc, $argv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if($argc != 2)
|
||||
{
|
||||
fprintf(STDERR, "%s: wrong argument count\n", $argv[0]);
|
||||
usage($argc, $argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(!$cv)
|
||||
{
|
||||
fprintf(STDERR, "%s: unable to initialise libcaca\n", $argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$i_str = file_get_contents($argv[$argc-1]);
|
||||
$i = $i_str ? imagecreatefromstring($i_str) : NULL;
|
||||
if(!$i)
|
||||
{
|
||||
fprintf(STDERR, "%s: unable to load %s\n", $argv[0], $argv[$argc-1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Assume a 6×10 font */
|
||||
if(!$cols && !$lines)
|
||||
{
|
||||
$cols = 60;
|
||||
$lines = $cols * imagesy($i) * $font_width / imagesx($i) / $font_height;
|
||||
}
|
||||
else if($cols && !$lines)
|
||||
{
|
||||
$lines = $cols * imagesy($i) * $font_width / imagesx($i) / $font_height;
|
||||
}
|
||||
else if(!$cols && $lines)
|
||||
{
|
||||
$cols = $lines * imagesx($i) * $font_height / imagesy($i) / $font_width;
|
||||
}
|
||||
|
||||
|
||||
caca_set_canvas_size($cv, $cols, $lines);
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_clear_canvas($cv);
|
||||
$i_dither = caca_create_dither($i);
|
||||
if(! caca_set_dither_algorithm($i_dither, $dither?$dither:"fstein"))
|
||||
{
|
||||
fprintf(STDERR, "%s: Can't dither image with algorithm '%s'\n", $argv[0], $dither?$dither:"fstein");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if($brightness!=-1) caca_set_dither_brightness ($i_dither, $brightness);
|
||||
if($contrast!=-1) caca_set_dither_contrast ($i_dither, $contrast);
|
||||
if($gamma!=-1) caca_set_dither_gamma ($i_dither, $gamma);
|
||||
|
||||
caca_dither_bitmap($cv, 0, 0, $cols, $lines, $i_dither, $i);
|
||||
|
||||
$export = caca_export_string($cv, $format?$format:"ansi");
|
||||
if(!$export)
|
||||
{
|
||||
fprintf(STDERR, "%s: Can't export to format '%s'\n", $argv[0], $format?$format:"ansi");
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $export;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
exit(main());
|
||||
?>
|
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* import libcaca importers test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/import.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$imports = caca_get_import_list();
|
||||
|
||||
if($argc < 2 || $argc > 3)
|
||||
{
|
||||
$msg = ($argv[0] . ": wrong argument count\n" .
|
||||
"usage: " . $argv[0] . " file [<format>]\n" .
|
||||
"where <format> is one of:\n");
|
||||
foreach($imports as $format => $name)
|
||||
$msg .= " \"" . $name . "\" (" . $format . ")\n";
|
||||
die($msg);
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't create canvas\n");
|
||||
}
|
||||
|
||||
if(caca_import_file($cv, $argv[1], $argc >= 3 ? $argv[2] : "") < 0)
|
||||
{
|
||||
die($argv[0] . ": could not open `" . $argv[1] . "'.\n");
|
||||
}
|
||||
|
||||
$dp = caca_create_display($cv);
|
||||
if(! $dp)
|
||||
{
|
||||
die("Can't create display\n");
|
||||
}
|
||||
|
||||
caca_refresh_display($dp);
|
||||
|
||||
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
|
||||
|
||||
?>
|
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,57 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* polyline.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
function transform($tbl, $tx, $ty, $sx, $sy) {
|
||||
$result = array();
|
||||
foreach($tbl as $pt)
|
||||
$result[] = array($pt[0] * $sx + $tx, $pt[1] * $sy + $ty);
|
||||
return $result;
|
||||
}
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$canvas = caca_create_canvas(0, 0);
|
||||
$display = caca_create_display($canvas);
|
||||
if (!$display) {
|
||||
die("Error while attaching canvas to display\n");
|
||||
}
|
||||
|
||||
$tbl = array(
|
||||
array(5, 2),
|
||||
array(15, 2),
|
||||
array(20, 4),
|
||||
array(25, 2),
|
||||
array(34, 2),
|
||||
array(37, 4),
|
||||
array(36, 9),
|
||||
array(20, 16),
|
||||
array(3, 9),
|
||||
array(2, 4),
|
||||
array(5, 2)
|
||||
);
|
||||
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
caca_set_color_ansi($canvas, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
|
||||
$scale = caca_rand(4, 10) / 10;
|
||||
$translate = array(caca_rand(-5, 55), caca_rand(-2, 25));
|
||||
$pts = transform($tbl, $translate[0], $translate[1], $scale, $scale);
|
||||
caca_draw_thin_polyline($canvas, $pts);
|
||||
}
|
||||
|
||||
caca_put_str($canvas, 1, 1, "Caca forever...");
|
||||
caca_refresh_display($display);
|
||||
caca_get_event($display, CACA_EVENT_KEY_PRESS, 5000000);
|
||||
|
||||
?>
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/php5
|
||||
<?
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$pig_str = <<<EOT
|
||||
|
||||
_._ _..._ .-', _.._(`))
|
||||
'-. ` ' /-._.-' ',/
|
||||
) \ '.
|
||||
/ _ _ | \
|
||||
| a a / PHP |
|
||||
\ .-. ;
|
||||
'-('' ).-' ,' ;
|
||||
'-; | .'
|
||||
\ \ /
|
||||
| 7 .__ _.-\ \
|
||||
| | | ``/ /` /
|
||||
jgs /,_| | /,_/ /
|
||||
/,_/ '`-'
|
||||
EOT;
|
||||
|
||||
$canvas = caca_create_canvas(0, 0);
|
||||
caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE);
|
||||
caca_import_string($canvas, $pig_str, "text");
|
||||
caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY);
|
||||
caca_put_str($canvas, 0, 0, "Я люблю Либкаку");
|
||||
echo caca_export_string($canvas, "utf8");
|
||||
|
||||
$font = caca_load_builtin_font("Monospace Bold 12");
|
||||
|
||||
$width = caca_get_canvas_width($canvas) * caca_get_font_width($font);
|
||||
$height = caca_get_canvas_height($canvas) * caca_get_font_height($font);
|
||||
|
||||
$img = imagecreatetruecolor($width, $height);
|
||||
|
||||
caca_render_canvas($canvas, $font, $img);
|
||||
|
||||
imagepng($img, "out.png");
|
||||
echo "Please, open new created png file: out.png\n";
|
||||
|
||||
?>
|
|
@ -0,0 +1,146 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* Test PHP bindings test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "caca-sharp/test.cs"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
include dirname($argv[0]) . '/../caca.php';
|
||||
|
||||
class DemoCanvas extends Canvas
|
||||
{
|
||||
private $image;
|
||||
|
||||
private $startTime;
|
||||
private $d;
|
||||
private $scroll;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->startTime = gettimeofday(true);
|
||||
|
||||
$message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN";
|
||||
|
||||
$this->scroll = new Canvas(strlen($message), 1);
|
||||
$this->scroll->setColorAnsi(AnsiColor::WHITE, AnsiColor::TRANSPARENT);
|
||||
$this->scroll->putStr(0, 0, $message);
|
||||
|
||||
$fontList = Font::getList();
|
||||
$f = new Font($fontList[1]);
|
||||
$w = $f->getWidth() * strlen($message);
|
||||
$h = $f->getHeight();
|
||||
$this->image = imagecreatetruecolor($w, $h);
|
||||
imagealphablending($this->image, false);
|
||||
imagesavealpha($this->image, true);
|
||||
$this->d = new Dither($this->image);
|
||||
$f->Render($this->scroll, $this->image);
|
||||
}
|
||||
|
||||
function Draw()
|
||||
{
|
||||
$barCount = 6;
|
||||
$t = (gettimeofday(true) - $this->startTime) * 1000;
|
||||
|
||||
$this->Clear();
|
||||
|
||||
$this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
|
||||
for($i = 0; $i < $barCount; $i++)
|
||||
{
|
||||
$v = ((sin(($t / 500.0)
|
||||
+ (1.0 * $i / $barCount)) + 1) / 2) * $this->getHeight();
|
||||
$p1_x = 0; $p1_y = intval($v);
|
||||
$p2_x = $this->getWidth() - 1; $p2_y = intval($v);
|
||||
|
||||
$this->setColorAnsi(($i + 9), AnsiColor::BLACK);
|
||||
/* drawLine is already clipped, we don't care about overflows */
|
||||
$this->drawLine($p1_x + 0, $p1_y - 2, $p2_x + 0, $p2_y - 2, ord('-'));
|
||||
$this->drawLine($p1_x + 0, $p1_y - 1, $p2_x + 0, $p2_y - 1, ord('*'));
|
||||
$this->drawLine($p1_x, $p1_y, $p2_x, $p2_y, ord('#'));
|
||||
$this->drawLine($p1_x + 0, $p1_y + 1, $p2_x + 0, $p2_y + 1, ord('*'));
|
||||
$this->drawLine($p1_x + 0, $p1_y + 2, $p2_x + 0, $p2_y + 2, ord('-'));
|
||||
}
|
||||
|
||||
$w = $this->getWidth();
|
||||
$h = $this->getHeight();
|
||||
$x = intval(($t / 10) % (12 * $w));
|
||||
$y = intval($h * (2.0 + sin($t / 200.0)) / 4);
|
||||
$this->d->bitmap($this, - $x, $h / 2 - $y, $w * 12, $y * 2);
|
||||
$this->d->bitmap($this, 12 * $w - $x, $h / 2 - $y, $w * 12, $y * 2);
|
||||
|
||||
$this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLUE);
|
||||
$this->putStr($this->getWidth() - 30, $this->getHeight() - 2, " -=[ Powered by libcaca ]=- ");
|
||||
$this->setColorAnsi(AnsiColor::WHITE, AnsiColor::BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
class DemoDisplay extends Display
|
||||
{
|
||||
private $cv;
|
||||
|
||||
function __construct(DemoCanvas $_cv)
|
||||
{
|
||||
parent::__construct($_cv);
|
||||
$this->setTitle("libcaca PHP Bindings test suite");
|
||||
$this->setDisplayTime(20000); // Refresh every 20 ms
|
||||
$this->cv = $_cv;
|
||||
}
|
||||
|
||||
function EventLoop()
|
||||
{
|
||||
while(! ($ev = $this->getEvent(EventType::KEY_RELEASE, 10)))
|
||||
{
|
||||
$this->cv->Draw();
|
||||
|
||||
$this->Refresh();
|
||||
}
|
||||
|
||||
if($ev->getKeyCh() > 0x20 && $ev->getKeyCh() < 0x7f)
|
||||
printf("Key pressed: %c\n", $ev->getKeyCh());
|
||||
else
|
||||
printf("Key pressed: 0x%x\n", $ev->getKeyCh());
|
||||
}
|
||||
}
|
||||
|
||||
class Test
|
||||
{
|
||||
static function Main()
|
||||
{
|
||||
printf("libcaca %s PHP test\n", Libcaca::getVersion());
|
||||
printf("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>\n");
|
||||
printf("(c) 2007 Sam Hocevar <sam@hocevar.net>\n");
|
||||
printf("(c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>\n");
|
||||
|
||||
/* Instanciate a caca canvas */
|
||||
$cv = new DemoCanvas();
|
||||
|
||||
/* We have a proper canvas, let's display it using Caca */
|
||||
$dp = new DemoDisplay($cv);
|
||||
|
||||
/* Random number. This is a static method,
|
||||
not to be used with previous instance */
|
||||
printf("A random number: %d\n", Libcaca::Rand(0, 1337));
|
||||
|
||||
$dp->EventLoop();
|
||||
}
|
||||
}
|
||||
|
||||
Test::Main();
|
||||
|
||||
?>
|
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* demo.php demo for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This file is a Php port of the official libcaca's sample program "demo.c"
|
||||
* which is:
|
||||
* Copyright (c) 2003 Sam Hocevar <sam@hocevar.net>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$string = <<<EOT
|
||||
|_|
|
||||
_,----._ | |
|
||||
(/ @ @ \) __
|
||||
| OO | |_
|
||||
\ `--' / |__
|
||||
`----'
|
||||
|_|
|
||||
Hello world! |
|
||||
EOT;
|
||||
|
||||
$pig = caca_create_canvas(0, 0);
|
||||
caca_import_string($pig, $string, "text");
|
||||
|
||||
$cv = caca_create_canvas(caca_get_canvas_width($pig) * 2, caca_get_canvas_height($pig) * 2);
|
||||
|
||||
if (!$cv or !$pig) {
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
|
||||
caca_blit($cv, 0, 0, $pig);
|
||||
caca_flip($pig);
|
||||
caca_blit($cv, caca_get_canvas_width($pig), 0, $pig);
|
||||
caca_flip($pig);
|
||||
caca_flop($pig);
|
||||
caca_blit($cv, 0, caca_get_canvas_height($pig), $pig);
|
||||
caca_flop($pig);
|
||||
caca_rotate_180($pig);
|
||||
caca_blit($cv, caca_get_canvas_width($pig), caca_get_canvas_height($pig), $pig);
|
||||
|
||||
for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
|
||||
for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
|
||||
caca_set_color_ansi($cv, CACA_LIGHTBLUE + ($i + $j) % 6, CACA_DEFAULT);
|
||||
$a = caca_get_attr($cv, -1, -1);
|
||||
caca_put_attr($cv, $i, $j, $a);
|
||||
caca_put_attr($cv, $i + 1, $j, $a);
|
||||
}
|
||||
}
|
||||
|
||||
echo caca_export_string($cv, "utf8");
|
||||
caca_rotate_left($cv);
|
||||
echo caca_export_string($cv, "utf8");
|
||||
|
||||
?>
|
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* transform transformation test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/transform.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$pig = (
|
||||
",--. ,--.\n" .
|
||||
"\\ /-~-\\ /\n" .
|
||||
" )' o O `(\n" .
|
||||
"( ,---. )\n" .
|
||||
" `(_o_o_)'\n" .
|
||||
" )`-'(\n");
|
||||
|
||||
$duck = (
|
||||
" ,~~.\n" .
|
||||
" __ , ( O )>\n" .
|
||||
"___( o)> )`~~' (\n" .
|
||||
"\\ <_. ) ( .__) )\n" .
|
||||
" `---' `-.____,'\n");
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
$dp = caca_create_display($cv);
|
||||
if(! $dp)
|
||||
{
|
||||
die("Can't create display\n");
|
||||
}
|
||||
|
||||
$image = caca_create_canvas(70, 6);
|
||||
$tmp = caca_create_canvas(70, 6);
|
||||
$sprite = caca_create_canvas(0, 0);
|
||||
|
||||
caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
|
||||
caca_import_string($sprite, $pig, "text");
|
||||
caca_blit($image, 55, 0, $sprite);
|
||||
|
||||
caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK);
|
||||
caca_import_string($sprite, $duck, "text");
|
||||
caca_blit($image, 30, 1, $sprite);
|
||||
|
||||
caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK);
|
||||
caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
|
||||
caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK);
|
||||
caca_put_char($image, 38, 1, ord('|'));
|
||||
|
||||
caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK);
|
||||
caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
|
||||
|
||||
caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED);
|
||||
caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
|
||||
caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
|
||||
caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED);
|
||||
caca_put_str($image, 4, 3, "▓▒░");
|
||||
caca_put_str($image, 4, 4, "▓▒░");
|
||||
caca_put_str($image, 24, 3, "░▒▓");
|
||||
caca_put_str($image, 24, 4, "░▒▓");
|
||||
|
||||
/* Blit the transformed canvas onto the main canvas */
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 0, 0, "normal");
|
||||
caca_blit($cv, 10, 0, $image);
|
||||
|
||||
caca_put_str($cv, 0, 6, "flip");
|
||||
caca_blit($tmp, 0, 0, $image);
|
||||
caca_flip($tmp);
|
||||
caca_blit($cv, 10, 6, $tmp);
|
||||
|
||||
caca_put_str($cv, 0, 12, "flop");
|
||||
caca_blit($tmp, 0, 0, $image);
|
||||
caca_flop($tmp);
|
||||
caca_blit($cv, 10, 12, $tmp);
|
||||
|
||||
caca_put_str($cv, 0, 18, "rotate");
|
||||
caca_blit($tmp, 0, 0, $image);
|
||||
caca_rotate_180($tmp);
|
||||
caca_blit($cv, 10, 18, $tmp);
|
||||
|
||||
caca_refresh_display($dp);
|
||||
|
||||
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
|
||||
?>
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* truecolor truecolor canvas features
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/truecolor.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(32, 16);
|
||||
if(!$cv) {
|
||||
die("Failed to create canvas\n");
|
||||
}
|
||||
|
||||
$dp = caca_create_display($cv);
|
||||
if(!$dp) {
|
||||
die("Failed to create display\n");
|
||||
}
|
||||
|
||||
for($y = 0; $y < 16; $y++)
|
||||
for($x = 0; $x < 16; $x++)
|
||||
{
|
||||
$bgcolor = 0xff00 | ($y << 4) | $x;
|
||||
$fgcolor = 0xf000 | ((15 - $y) << 4) | ((15 - $x) << 8);
|
||||
|
||||
caca_set_color_argb($cv, $fgcolor, $bgcolor);
|
||||
caca_put_str($cv, $x * 2, $y, "CA");
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
|
||||
caca_put_str($cv, 2, 1, " truecolor libcaca ");
|
||||
|
||||
caca_refresh_display($dp);
|
||||
|
||||
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
|
||||
|
||||
?>
|
|
@ -0,0 +1,91 @@
|
|||
#!/usr/bin/php5
|
||||
<?php
|
||||
/*
|
||||
* unicode libcaca Unicode rendering test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/unicode.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
if (php_sapi_name() != "cli") {
|
||||
die("You have to run this program with php-cli!\n");
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
$dp = caca_create_display($cv);
|
||||
if(! $dp)
|
||||
{
|
||||
die("Can't create display\n");
|
||||
}
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 1, 1, "Basic Unicode support");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
|
||||
caca_put_str($cv, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
|
||||
caca_put_str($cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
|
||||
|
||||
caca_put_str($cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 1, 7, "Gradient glyphs");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 31, 8, " 0%");
|
||||
caca_put_str($cv, 31, 9, " 25%");
|
||||
caca_put_str($cv, 31, 10, " 50%");
|
||||
caca_put_str($cv, 31, 11, " 75%");
|
||||
caca_put_str($cv, 31, 12, "100%");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_LIGHTGREEN);
|
||||
caca_put_str($cv, 1, 8, " ");
|
||||
caca_put_str($cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
|
||||
caca_put_str($cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
|
||||
caca_put_str($cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
|
||||
caca_put_str($cv, 1, 12, "█████████████████████████████");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_LIGHTRED);
|
||||
caca_put_str($cv, 36, 8, "█████████████████████████████");
|
||||
caca_put_str($cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
|
||||
caca_put_str($cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
|
||||
caca_put_str($cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
|
||||
caca_put_str($cv, 36, 12, " ");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 1, 14, "Double width characters");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 15, "| ドラゴン ボーレ |");
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 16, "| ()()()() ()()() |");
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 17, "| ドラゴン");
|
||||
caca_put_str($cv, 12, 17, "ボーレ |");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
|
||||
|
||||
caca_put_str($cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
|
||||
caca_put_str($cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
|
||||
caca_put_str($cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟ ─ │ ┌ ┐ └ ┘ ├ ┤");
|
||||
caca_put_str($cv, 1, 23, "more drawing: ┬ ┴ ┼ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬");
|
||||
caca_put_str($cv, 1, 24, "misc Unicode: ● ☭ ☮ ☯ ♔ ♛ ♙ ♞ ⚒ ⚓ ⚠");
|
||||
|
||||
caca_refresh_display($dp);
|
||||
|
||||
caca_get_event($dp, CACA_EVENT_KEY_PRESS, -1);
|
||||
|
||||
?>
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* cacainfo.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>sample program for libcaca php binding</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
//--- Just for fun ---//
|
||||
|
||||
function just_for_fun() {
|
||||
|
||||
$moo = <<<EOT
|
||||
(__)
|
||||
(oo)
|
||||
/------\/
|
||||
/ | ||
|
||||
* /\---/\
|
||||
~~ ~~
|
||||
EOT;
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
|
||||
caca_import_string($cv, $moo, "text");
|
||||
|
||||
for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
|
||||
for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
|
||||
caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE : CACA_WHITE), CACA_DEFAULT);
|
||||
$a = caca_get_attr($cv, -1, -1);
|
||||
caca_put_attr($cv, $i, $j, $a);
|
||||
caca_put_attr($cv, $i + 1, $j, $a);
|
||||
}
|
||||
}
|
||||
caca_set_canvas_size($cv, 18, 6);
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
|
||||
caca_put_str($cv, 14, 0, "Moo!");
|
||||
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
|
||||
caca_put_char($cv, 14, 1, hexdec("2765")); //U+2765
|
||||
caca_put_char($cv, 16, 1, hexdec("2764")); //U+2764
|
||||
echo caca_export_string($cv, "html3");
|
||||
}
|
||||
|
||||
|
||||
just_for_fun();
|
||||
|
||||
?>
|
||||
<?php
|
||||
|
||||
//--- Show caca's information ---//
|
||||
|
||||
?>
|
||||
<p>libcaca version: <?php echo htmlspecialchars(caca_get_version()); ?></p>
|
||||
|
||||
<p>Available drivers:</p>
|
||||
<ul>
|
||||
<?php
|
||||
$list = caca_get_display_driver_list();
|
||||
foreach($list as $type => $name)
|
||||
echo '<li>' . htmlspecialchars("$name ($type)") . '</li>';
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<p>Available import formats:</p>
|
||||
<ul>
|
||||
<?php
|
||||
$list = caca_get_import_list();
|
||||
foreach($list as $format => $name)
|
||||
echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<p>Available export formats:</p>
|
||||
<ul>
|
||||
<?php
|
||||
$list = caca_get_export_list();
|
||||
foreach($list as $format => $name)
|
||||
echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<p>Available caca fonts:</p>
|
||||
<ul>
|
||||
<?php
|
||||
$list = caca_get_font_list();
|
||||
foreach($list as $name)
|
||||
echo '<li>' . htmlspecialchars("$name") . '</li>';
|
||||
?>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* colors display all possible libcaca colour pairs
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/colors.c"
|
||||
* Copyright (c) 2003-2004 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>display all possible libcaca colour pairs</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
$cv = caca_create_canvas(80, 24);
|
||||
if(!$cv)
|
||||
{
|
||||
die("Failed to create canvas\n");
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_clear_canvas($cv);
|
||||
for($i = 0; $i < 16; $i++)
|
||||
{
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_put_str($cv, 3, $i + ($i >= 8 ? 3 : 2), "ANSI " . $i);
|
||||
for($j = 0; $j < 16; $j++)
|
||||
{
|
||||
caca_set_color_ansi($cv, $i, $j);
|
||||
caca_put_str($cv, ($j >= 8 ? 13 : 12) + $j * 4, $i + ($i >= 8 ? 3 : 2),
|
||||
"Aaホ");
|
||||
}
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_put_str($cv, 3, 20, "This is bold This is blink This is italics This is underline");
|
||||
caca_set_attr($cv, CACA_BOLD);
|
||||
caca_put_str($cv, 3 + 8, 20, "bold");
|
||||
caca_set_attr($cv, CACA_BLINK);
|
||||
caca_put_str($cv, 3 + 24, 20, "blink");
|
||||
caca_set_attr($cv, CACA_ITALICS);
|
||||
caca_put_str($cv, 3 + 41, 20, "italics");
|
||||
caca_set_attr($cv, CACA_UNDERLINE);
|
||||
caca_put_str($cv, 3 + 60, 20, "underline");
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Caca power!</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
/*
|
||||
* dithering.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
$src = "logo-caca.png";
|
||||
$img = imagecreatefrompng(dirname(__FILE__)."/".$src);
|
||||
if (!$img) {
|
||||
die("Can not open image.\n");
|
||||
}
|
||||
|
||||
$dither = caca_create_dither($img);
|
||||
if (!$dither) {
|
||||
die("Can not create dither. Maybe you compiled caca-php without gd support.\n");
|
||||
}
|
||||
|
||||
$canvas = caca_create_canvas(100, 40);
|
||||
|
||||
caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
|
||||
|
||||
echo caca_export_string($canvas, "html3");
|
||||
echo "<img src=\"./$src\" alt=\"\" />";
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
/*
|
||||
* export libcaca export test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/export.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
define('WIDTH', 80);
|
||||
define('HEIGHT', 32);
|
||||
|
||||
$pixels = imagecreatetruecolor(256, 256);
|
||||
|
||||
$exports = caca_get_export_list();
|
||||
|
||||
$file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;
|
||||
$filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;
|
||||
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL;
|
||||
|
||||
if((! $format) || (! array_key_exists($format, $exports)))
|
||||
{
|
||||
header("Content-type: text/html; charset=UTF-8");
|
||||
|
||||
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>libcaca export test program</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<script type="text/javascript">
|
||||
/*<![CDATA[*/
|
||||
update_preview = function (select)
|
||||
{
|
||||
var iframe_map = {
|
||||
'html': true,
|
||||
'html3': true,
|
||||
'bbfr': true
|
||||
};
|
||||
if (self.opera
|
||||
||
|
||||
(('' + navigator.userAgent).match(/.*(WebKit|Gecko).*/)))
|
||||
{
|
||||
iframe_map['svg'] = true;
|
||||
}
|
||||
var e;
|
||||
try
|
||||
{
|
||||
var format = select.options[select.selectedIndex].value;
|
||||
var newLocation = 'about:blank';
|
||||
if (iframe_map[format])
|
||||
{
|
||||
newLocation = self.location.pathname + '?format=' + encodeURIComponent(format);
|
||||
}
|
||||
self.frames[0].location.replace(newLocation, true);
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
alert('e' + e);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
/*]]>*/
|
||||
</script>
|
||||
</head>
|
||||
<body onload="update_preview(document.forms.exportform.elements.format);">
|
||||
|
||||
<form id="exportform" name="exportform" action="#" enctype="multipart/form-data" method="post">
|
||||
<label for="file">File:</label>
|
||||
<input id="file" name="file" type="file" /> <em>(optional)</em>
|
||||
<br />
|
||||
<input type="submit" value="Export" />
|
||||
<label for="format">as</label>
|
||||
<select name="format" id="format" onchange="update_preview(this);">
|
||||
<?php
|
||||
foreach($exports as $format => $name)
|
||||
{
|
||||
?><option value="<?= htmlspecialchars($format) ?>"<?=
|
||||
($format == 'html') ? ' selected="selected"' : '' ?>><?=
|
||||
htmlspecialchars($name . " (" . $format . ")") ?></option><?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
<?php
|
||||
$export_php = isset($_SERVER['SCRIPT_NAME'])
|
||||
?
|
||||
$_SERVER['SCRIPT_NAME']
|
||||
:
|
||||
'export.php';
|
||||
?><iframe frameborder="0" name="preview" id="preview" width="820" height="620" style="margin: 0; padding: 0; border: none; width: 100%"></iframe>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if($file)
|
||||
{
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(caca_import_file($cv, $file, "") < 0)
|
||||
{
|
||||
die("`" . htmlspecialchars($filename) . "' has unknown format\n");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$cv = caca_create_canvas(WIDTH, HEIGHT);
|
||||
|
||||
for($y = 0; $y < 256; $y++)
|
||||
{
|
||||
for($x = 0; $x < 256; $x++)
|
||||
{
|
||||
$r = $x;
|
||||
$g = (255 - $y + $x) / 2;
|
||||
$b = $y * (255 - $x) / 256;
|
||||
imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
|
||||
}
|
||||
}
|
||||
|
||||
$dither = caca_create_dither($pixels);
|
||||
if(($format == "ansi") || ($format == "utf8"))
|
||||
caca_set_dither_charset($dither, "shades");
|
||||
caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv),
|
||||
caca_get_canvas_height($cv), $dither, $pixels);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
|
||||
caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
|
||||
caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2,
|
||||
WIDTH / 4, HEIGHT / 4, ord(' '));
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
|
||||
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
|
||||
" lightgray on black ");
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
|
||||
" default on transparent ");
|
||||
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
|
||||
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
|
||||
" black on white ");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
|
||||
caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
|
||||
caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
|
||||
caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
|
||||
caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
|
||||
|
||||
caca_set_attr($cv, CACA_BOLD);
|
||||
caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
|
||||
caca_set_attr($cv, CACA_BLINK);
|
||||
caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
|
||||
caca_set_attr($cv, CACA_ITALICS);
|
||||
caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
|
||||
caca_set_attr($cv, CACA_UNDERLINE);
|
||||
caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
|
||||
caca_set_attr($cv, 0);
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
|
||||
caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
|
||||
|
||||
for($x = 0; $x < 16; $x++)
|
||||
{
|
||||
caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4));
|
||||
caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
|
||||
}
|
||||
}
|
||||
|
||||
$content_type_map = array(
|
||||
'ansi' => 'text/plain; charset=CP437',
|
||||
'utf8' => 'text/plain; charset=UTF-8',
|
||||
'utf8cr' => 'text/plain; charset=UTF-8',
|
||||
'html' => 'text/html; charset=UTF-8',
|
||||
'html3' => 'text/html; charset=UTF-8',
|
||||
'bbfr' => 'text/plain; charset=UTF-8',
|
||||
'irc' => 'text/plain; charset=UTF-8',
|
||||
'ps' => 'application/postscript',
|
||||
'svg' => 'image/svg+xml',
|
||||
'tga' => 'image/x-targa'
|
||||
);
|
||||
|
||||
$download_extension_map = array(
|
||||
'caca' => 'caca',
|
||||
'ansi' => 'txt',
|
||||
'utf8' => 'txt',
|
||||
'utf8cr' => 'txt',
|
||||
'irc' => 'txt',
|
||||
'tga' => 'tga'
|
||||
);
|
||||
|
||||
$inline_extension_map = array(
|
||||
'bbfr' => 'txt',
|
||||
'ps' => 'ps',
|
||||
'svg' => 'svg'
|
||||
);
|
||||
|
||||
if (! array_key_exists($format, $content_type_map))
|
||||
$content_type = 'application/octet-stream';
|
||||
else
|
||||
$content_type = $content_type_map[$format];
|
||||
|
||||
header('Content-Type: ' . $content_type);
|
||||
if (array_key_exists($format, $download_extension_map))
|
||||
header('Content-Disposition: attachment; filename=export.' . $download_extension_map[$format]);
|
||||
else if (array_key_exists($format, $inline_extension_map))
|
||||
header('Content-Disposition: inline; filename=export.' . $inline_extension_map[$format]);
|
||||
|
||||
echo caca_export_string($cv, $format);
|
||||
|
||||
?>
|
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>Caca power!</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<form method="get" action="#"><input name="str" value="<?= htmlspecialchars(isset($_GET["str"]) ? $_GET["str"] : "Libcaca") ?>" /><input type="submit" value="OK" /></form>
|
||||
<?php
|
||||
/*
|
||||
* figlet.php sample program for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
function unistr_to_ords($str, $encoding = 'UTF-8'){
|
||||
$str = mb_convert_encoding($str, "UCS-4BE", $encoding);
|
||||
$result = array();
|
||||
|
||||
for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){
|
||||
$c = mb_substr($str, $i, 1, "UCS-4BE");
|
||||
$val = unpack("N", $c);
|
||||
$result[] = $val[1];
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function show_figlet($str, $font) {
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
|
||||
if (!caca_canvas_set_figfont($cv, $font)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$chars = unistr_to_ords($str);
|
||||
$color = 0;
|
||||
foreach ($chars as $c) {
|
||||
caca_set_color_ansi($cv, 1 + (($color += 1) % 13), CACA_WHITE);
|
||||
caca_put_figchar($cv, $c);
|
||||
}
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
}
|
||||
|
||||
$path = "/usr/share/figlet/";
|
||||
if (!is_dir($path)) {
|
||||
die("can not open directory $path.\n");
|
||||
}
|
||||
|
||||
$dir = opendir($path);
|
||||
while (($it = readdir($dir)) != false) {
|
||||
if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) {
|
||||
echo "<b>font : $it</b>\n";
|
||||
show_figlet(isset($_GET["str"]) ? $_GET["str"] : "Libcaca", $path.$it);
|
||||
}
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* fullwidth libcaca fullwidth Unicode characters test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/fullwidth.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>sample program for libcaca php binding</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
define('CACA', "쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊쫊");
|
||||
|
||||
$cv = caca_create_canvas(36, 12);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
|
||||
$caca = caca_create_canvas(6, 10);
|
||||
$line = caca_create_canvas(2, 1);
|
||||
|
||||
/* Line of x's */
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($caca, 0, $i, CACA);
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_RED);
|
||||
caca_put_char($caca, $i - 2, $i, ord('x'));
|
||||
}
|
||||
|
||||
caca_blit($cv, 1, 1, $caca);
|
||||
|
||||
/* Line of ホ's */
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($caca, 0, $i, CACA);
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_GREEN);
|
||||
caca_put_str($caca, $i - 2, $i, "ホ");
|
||||
}
|
||||
|
||||
caca_blit($cv, 15, 1, $caca);
|
||||
|
||||
/* Line of canvas */
|
||||
caca_set_color_ansi($line, CACA_WHITE, CACA_MAGENTA);
|
||||
caca_put_str($line, 0, 0, "ほ");
|
||||
for($i = 0; $i < 10; $i++)
|
||||
{
|
||||
caca_set_color_ansi($caca, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($caca, 0, $i, CACA);
|
||||
caca_blit($caca, $i - 2, $i, $line);
|
||||
}
|
||||
|
||||
caca_blit($cv, 29, 1, $caca);
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,530 @@
|
|||
<?php
|
||||
/*
|
||||
* img2txt image to text converter
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "src/img2txt.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* 2007 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
$img2txt_php = isset($_SERVER['SCRIPT_NAME'])
|
||||
?
|
||||
$_SERVER['SCRIPT_NAME']
|
||||
:
|
||||
'img2txt.php';
|
||||
|
||||
$argv = array(basename($img2txt_php));
|
||||
$file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;
|
||||
$filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;
|
||||
$args = NULL;
|
||||
if(isset($_REQUEST['args']))
|
||||
{
|
||||
$args = trim($_REQUEST['args']);
|
||||
if(strlen($args))
|
||||
{
|
||||
foreach(explode(' ', $args) as $arg)
|
||||
{
|
||||
$argv[] = $arg;
|
||||
}
|
||||
}
|
||||
}
|
||||
$argc = count($argv);
|
||||
$stderr = '';
|
||||
$stdout = '';
|
||||
|
||||
class MygetoptException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
$myoptind = 0;
|
||||
|
||||
function mygetopt($shortopts, $longopts)
|
||||
{
|
||||
global $argc, $argv, $myoptind;
|
||||
if($myoptind < 0)
|
||||
{
|
||||
$myoptind = 0;
|
||||
}
|
||||
if(($myoptind + 1) >= $argc)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
$myoptind ++;
|
||||
$nextarg = $argv[$myoptind];
|
||||
$ret = NULL;
|
||||
if((substr($nextarg, 0, 1) != '-')
|
||||
||
|
||||
($nextarg == '-'))
|
||||
{
|
||||
$myoptind = $argc - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$skipopt = $myoptind;
|
||||
$skipopts = 1;
|
||||
if($nextarg == '--')
|
||||
{
|
||||
$myoptind = $argc - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$opt = NULL;
|
||||
$arg = NULL;
|
||||
foreach($longopts as $longopt)
|
||||
{
|
||||
$optional = false;
|
||||
$hasarg = false;
|
||||
if(($longopt != '::') && substr($longopt, -2) == '::')
|
||||
{
|
||||
$optional = true;
|
||||
$hasarg = true;
|
||||
$longopt = substr($longopt, 0, -2);
|
||||
}
|
||||
else if(($longopt != ':') && substr($longopt, -1) == ':')
|
||||
{
|
||||
$optional = false;
|
||||
$hasarg = true;
|
||||
$longopt = substr($longopt, 0, -1);
|
||||
}
|
||||
if($nextarg == ('--' . $longopt))
|
||||
{
|
||||
$opt = '--' . $longopt;
|
||||
if($hasarg && ! $optional)
|
||||
{
|
||||
if(($myoptind + 1) < $argc)
|
||||
{
|
||||
$myoptind ++;
|
||||
$skipopts ++;
|
||||
$arg = $argv[$myoptind];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MygetoptException("option \"$opt\" requires an argument");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(substr($nextarg, 0, strlen('--' . $longopt . '='))
|
||||
==
|
||||
('--' . $longopt . '='))
|
||||
{
|
||||
$opt = '--' . $longopt;
|
||||
$arg = substr($nextarg, strlen($opt . '='));
|
||||
if(! $hasarg)
|
||||
{
|
||||
throw new MygetoptException("option \"$opt\" does not allow an argument");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($opt === NULL)
|
||||
{
|
||||
for($i = 0; $i < strlen($shortopts); $i ++)
|
||||
{
|
||||
$optional = false;
|
||||
$hasarg = false;
|
||||
$shortopt = substr($shortopts, $i, 1);
|
||||
if(substr($shortopts, $i + 1, 2) == '::')
|
||||
{
|
||||
$optional = true;
|
||||
$hasarg = true;
|
||||
$i += 2;
|
||||
}
|
||||
else if(substr($shortopts, $i + 1, 1) == ':')
|
||||
{
|
||||
$hasarg = true;
|
||||
}
|
||||
if($nextarg
|
||||
==
|
||||
('-' . $shortopt))
|
||||
{
|
||||
$opt = '-' . $shortopt;
|
||||
if($hasarg && ! $optional)
|
||||
{
|
||||
if(($myoptind + 1) < $argc)
|
||||
{
|
||||
$myoptind ++;
|
||||
$skipopts ++;
|
||||
$arg = $argv[$myoptind];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MygetoptException("option \"$opt\" requires an argument");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if(substr($nextarg, 0, strlen('-' . $shortopt))
|
||||
==
|
||||
('-' . $shortopt))
|
||||
{
|
||||
$opt = '-' . $shortopt;
|
||||
if($hasarg)
|
||||
{
|
||||
$arg = substr($nextarg, strlen($opt));
|
||||
}
|
||||
else
|
||||
{
|
||||
$argv[$myoptind] = '-' . substr($nextarg, strlen($opt));
|
||||
$myoptind --;
|
||||
$skipopts = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($opt === NULL)
|
||||
{
|
||||
if(substr($nextarg, 0, strlen('--')) == '--')
|
||||
{
|
||||
$longopt = substr($nextarg, strlen('--'));
|
||||
if(strpos($longopt, '=') !== false)
|
||||
{
|
||||
$longopt = substr($longopt, 0, strpos($longopt, '='));
|
||||
}
|
||||
throw new MygetoptException("option \"--$longopt\" is not recognized");
|
||||
}
|
||||
$shortopt = substr($nextarg, strlen('-'), 1);
|
||||
throw new MygetoptException("option \"-$shortopt\" is not recognized");
|
||||
}
|
||||
$ret = array($opt, $arg);
|
||||
}
|
||||
if ($skipopts > 0)
|
||||
{
|
||||
for($i = 0; $i < $argc; $i ++)
|
||||
{
|
||||
if(($i < $skipopt) || ($i >= ($skipopt + $skipopts)))
|
||||
{
|
||||
$new_argv[] = $argv[$i];
|
||||
}
|
||||
}
|
||||
if($myoptind >= $skipopt)
|
||||
{
|
||||
$myoptind -= $skipopts;
|
||||
}
|
||||
$argv = $new_argv;
|
||||
$argc = count($argv);
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function usage($argc, $argv)
|
||||
{
|
||||
global $stdout;
|
||||
$stdout .= sprintf("Usage: %s [OPTIONS]... <IMAGE>\n", $argv[0]);
|
||||
$stdout .= sprintf("Convert IMAGE to any text based available format.\n");
|
||||
$stdout .= sprintf("Example : -W 80 -f html logo-caca.png\n\n", $argv[0]);
|
||||
$stdout .= sprintf("Options:\n");
|
||||
$stdout .= sprintf(" -h, --help\t\t\tThis help\n");
|
||||
$stdout .= sprintf(" -v, --version\t\t\tVersion of the program\n");
|
||||
$stdout .= sprintf(" -W, --width=WIDTH\t\tWidth of resulting image\n");
|
||||
$stdout .= sprintf(" -H, --height=HEIGHT\t\tHeight of resulting image\n");
|
||||
$stdout .= sprintf(" -x, --font-width=WIDTH\t\tWidth of output font\n");
|
||||
$stdout .= sprintf(" -y, --font-height=HEIGHT\t\tHeight of output font\n");
|
||||
$stdout .= sprintf(" -b, --brightness=BRIGHTNESS\tBrightness of resulting image\n");
|
||||
$stdout .= sprintf(" -c, --contrast=CONTRAST\tContrast of resulting image\n");
|
||||
$stdout .= sprintf(" -g, --gamma=GAMMA\t\tGamma of resulting image\n");
|
||||
$stdout .= sprintf(" -d, --dither=DITHER\t\tDithering algorithm to use :\n");
|
||||
$list = caca_get_dither_algorithm_list(caca_create_dither(imagecreate(1, 1)));
|
||||
foreach($list as $type => $name)
|
||||
{
|
||||
$stdout .= sprintf("\t\t\t%s: %s\n", $type, $name);
|
||||
}
|
||||
|
||||
$stdout .= sprintf(" -f, --format=FORMAT\t\tFormat of the resulting image :\n");
|
||||
$list = caca_get_export_list();
|
||||
foreach($list as $type => $name)
|
||||
{
|
||||
$stdout .= sprintf("\t\t\t%s: %s\n", $type, $name);
|
||||
}
|
||||
}
|
||||
|
||||
function version()
|
||||
{
|
||||
global $stdout;
|
||||
$stdout .= sprintf(
|
||||
"img2txt Copyright 2006-2007 Sam Hocevar and Jean-Yves Lamoureux\n" .
|
||||
" Copyright 2008 Benjamin C. Wiley Sittler\n" .
|
||||
"Internet: <sam@hocevar.net> <jylam@lnxscene.org>\n" .
|
||||
" <bsittler@gmail.com> Version: %s\n" .
|
||||
"\n" .
|
||||
"img2txt, along with its documentation, may be freely copied and distributed.\n" .
|
||||
"\n" .
|
||||
"The latest version of img2txt is available from the web site,\n" .
|
||||
" http://caca.zoy.org/wiki/libcaca in the libcaca package.\n" .
|
||||
"\n",
|
||||
caca_get_version());
|
||||
}
|
||||
function main()
|
||||
{
|
||||
global $file, $filename;
|
||||
global $argc, $argv;
|
||||
global $stderr;
|
||||
$cols = 0;
|
||||
$lines = 0;
|
||||
$font_width = 6;
|
||||
$font_height = 10;
|
||||
$format = NULL;
|
||||
$dither = NULL;
|
||||
$gamma = $brightness = $contrast = -1.0;
|
||||
|
||||
$long_options = array(
|
||||
"width:" => 'W',
|
||||
"height:" => 'H',
|
||||
"font-width:" => 'x',
|
||||
"font-height:" => 'y',
|
||||
"format:" => 'f',
|
||||
"dither:" => 'd',
|
||||
"gamma:" => 'g',
|
||||
"brightness:" => 'b',
|
||||
"contrast:" => 'c',
|
||||
"help" => 'h',
|
||||
"version" => 'v'
|
||||
);
|
||||
|
||||
try {
|
||||
while($opt_and_arg = mygetopt("W:H:f:d:g:b:c:hvx:y:", array_keys($long_options)))
|
||||
{
|
||||
$opt = $opt_and_arg[0];
|
||||
$arg = $opt_and_arg[1];
|
||||
if((substr($opt, 0, 2) == '--')
|
||||
&&
|
||||
array_key_exists(substr($opt, strlen('--')) . (($arg !== NULL) ? ':' : ''), $long_options))
|
||||
{
|
||||
$opt = '-' . $long_options[substr($opt, strlen('--')) . (($arg !== NULL) ? ':' : '')];
|
||||
}
|
||||
switch($opt)
|
||||
{
|
||||
case '-W': /* --width */
|
||||
$cols = intval($arg);
|
||||
break;
|
||||
case '-H': /* --height */
|
||||
$lines = intval($arg);
|
||||
break;
|
||||
case '-x': /* --width */
|
||||
$font_width = intval($arg);
|
||||
break;
|
||||
case '-y': /* --height */
|
||||
$font_height = intval($arg);
|
||||
break;
|
||||
case '-f': /* --format */
|
||||
$format = $arg;
|
||||
break;
|
||||
case '-d': /* --dither */
|
||||
$dither = $arg;
|
||||
break;
|
||||
case '-g': /* --gamma */
|
||||
$gamma = floatval($arg);
|
||||
break;
|
||||
case '-b': /* --brightness */
|
||||
$brightness = floatval($arg);
|
||||
break;
|
||||
case '-c': /* --contrast */
|
||||
$contrast = floatval($arg);
|
||||
break;
|
||||
case '-h': /* --help */
|
||||
usage($argc, $argv);
|
||||
return 0;
|
||||
case '-v': /* --version */
|
||||
version();
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MygetoptException $e)
|
||||
{
|
||||
$stderr .= $argv[0] . ": " . $e->getMessage() . "\n";
|
||||
usage($argc, $argv);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if((! $file) && ($argc == 2) && ($argv[1] == 'logo-caca.png'))
|
||||
{
|
||||
$file = 'logo-caca.png';
|
||||
$argc = 1;
|
||||
}
|
||||
else if($filename && $file && ($argc == 2)
|
||||
&&
|
||||
(strtolower(basename($argv[1])) == strtolower(basename($filename))))
|
||||
{
|
||||
$argc = 1;
|
||||
}
|
||||
|
||||
if($argc == 2)
|
||||
{
|
||||
$stderr .= sprintf("%s: image not found\n", $argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if($argc > 2)
|
||||
{
|
||||
$stderr .= sprintf("%s: too many arguments\n", $argv[0]);
|
||||
usage($argc, $argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(! $file)
|
||||
{
|
||||
$stderr .= sprintf("%s: no image was provided\n", $argv[0]);
|
||||
usage($argc, $argv);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(!$cv)
|
||||
{
|
||||
$stderr .= sprintf("%s: unable to initialise libcaca\n", $argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
$i_str = $file ? file_get_contents($file) : NULL;
|
||||
$i = $i_str ? imagecreatefromstring($i_str) : NULL;
|
||||
if(!$i)
|
||||
{
|
||||
$stderr .= sprintf("%s: unable to load %s\n", $argv[0], $filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Assume a 6×10 font */
|
||||
if(!$cols && !$lines)
|
||||
{
|
||||
$cols = 60;
|
||||
$lines = $cols * imagesy($i) * $font_width / imagesx($i) / $font_height;
|
||||
}
|
||||
else if($cols && !$lines)
|
||||
{
|
||||
$lines = $cols * imagesy($i) * $font_width / imagesx($i) / $font_height;
|
||||
}
|
||||
else if(!$cols && $lines)
|
||||
{
|
||||
$cols = $lines * imagesx($i) * $font_height / imagesy($i) / $font_width;
|
||||
}
|
||||
|
||||
|
||||
caca_set_canvas_size($cv, $cols, $lines);
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_clear_canvas($cv);
|
||||
$i_dither = caca_create_dither($i);
|
||||
if(! caca_set_dither_algorithm($i_dither, $dither?$dither:"fstein"))
|
||||
{
|
||||
$stderr .= sprintf("%s: Can't dither image with algorithm '%s'\n", $argv[0], $dither?$dither:"fstein");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if($brightness!=-1) caca_set_dither_brightness ($i_dither, $brightness);
|
||||
if($contrast!=-1) caca_set_dither_contrast ($i_dither, $contrast);
|
||||
if($gamma!=-1) caca_set_dither_gamma ($i_dither, $gamma);
|
||||
|
||||
caca_dither_bitmap($cv, 0, 0, $cols, $lines, $i_dither, $i);
|
||||
|
||||
$format = $format ? $format : 'html';
|
||||
|
||||
$export = caca_export_string($cv, $format);
|
||||
if(!$export)
|
||||
{
|
||||
$stderr .= sprintf("%s: Can't export to format '%s'\n", $argv[0], $format);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$content_type_map = array(
|
||||
'ansi' => 'text/plain; charset=CP437',
|
||||
'utf8' => 'text/plain; charset=UTF-8',
|
||||
'utf8cr' => 'text/plain; charset=UTF-8',
|
||||
'html' => 'text/html; charset=UTF-8',
|
||||
'html3' => 'text/html; charset=UTF-8',
|
||||
'bbfr' => 'text/plain; charset=UTF-8',
|
||||
'irc' => 'text/plain; charset=UTF-8',
|
||||
'ps' => 'application/postscript',
|
||||
'svg' => 'image/svg+xml',
|
||||
'tga' => 'image/x-targa'
|
||||
);
|
||||
|
||||
$download_extension_map = array(
|
||||
'caca' => 'caca',
|
||||
'ansi' => 'txt',
|
||||
'utf8' => 'txt',
|
||||
'utf8cr' => 'txt',
|
||||
'irc' => 'txt',
|
||||
'tga' => 'tga'
|
||||
);
|
||||
|
||||
$inline_extension_map = array(
|
||||
'bbfr' => 'txt',
|
||||
'ps' => 'ps',
|
||||
'svg' => 'svg'
|
||||
);
|
||||
|
||||
if (! array_key_exists($format, $content_type_map))
|
||||
$content_type = 'application/octet-stream';
|
||||
else
|
||||
$content_type = $content_type_map[$format];
|
||||
|
||||
header('Content-Type: ' . $content_type);
|
||||
if (array_key_exists($format, $download_extension_map))
|
||||
header('Content-Disposition: attachment; filename=export.' . $download_extension_map[$format]);
|
||||
else if (array_key_exists($format, $inline_extension_map))
|
||||
header('Content-Disposition: inline; filename=export.' . $inline_extension_map[$format]);
|
||||
|
||||
echo $export;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
$ret = 1;
|
||||
if(isset($_REQUEST['args']) || $file)
|
||||
{
|
||||
$ret = main();
|
||||
}
|
||||
if($ret || strlen($stdout) || strlen($stderr))
|
||||
{
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>image to text converter</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<form id="img2txtform" name="img2txtform" action="#" enctype="multipart/form-data" method="post">
|
||||
<label for="file">Image:</label>
|
||||
<input id="file" name="file" type="file" />
|
||||
<br />
|
||||
<label for="args">Options:</label>
|
||||
<input id="args" name="args" type="text" value="<?= isset($_REQUEST['args']) ? htmlspecialchars($_REQUEST['args']) : '' ?>" size="80" />
|
||||
<br />
|
||||
<input type="submit" /> <input type="reset" />
|
||||
</form>
|
||||
<?php
|
||||
;
|
||||
if(strlen($stderr))
|
||||
{
|
||||
?><pre xml:space="preserve"><strong><?= htmlspecialchars($stderr) ?></strong></pre><?php
|
||||
;
|
||||
}
|
||||
if(strlen($stdout))
|
||||
{
|
||||
?><pre xml:space="preserve"><?= preg_replace('!([&]lt;)([.a-zA-Z0-9]+[@])([-.a-zA-Z0-9]+)([&]gt;)!', '$1<a href="mailto:$2$3">$2...</a>$4', preg_replace('!(\s|^)(https?://[-.:_/0-9a-zA-Z%?=&;#]+)(\s|$)!', '$1<a href="$2">$2</a>$3', htmlspecialchars($stdout))) ?></pre><?php
|
||||
;
|
||||
}
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
;
|
||||
}
|
||||
?>
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* import libcaca importers test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/import.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
$imports = caca_get_import_list();
|
||||
|
||||
$file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;
|
||||
$filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;
|
||||
$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL;
|
||||
|
||||
?>
|
||||
<head>
|
||||
<title><?= ($filename == NULL) ? '' : htmlspecialchars($filename . ' | ') ?>libcaca importers test program</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body>
|
||||
<?php
|
||||
|
||||
if ($file == NULL)
|
||||
{
|
||||
?>
|
||||
<form id="importform" name="importform" action="#" enctype="multipart/form-data" method="post">
|
||||
<label for="file">File:</label>
|
||||
<input id="file" name="file" type="file" />
|
||||
<br />
|
||||
<input type="submit" value="Import" />
|
||||
<label for="format">as</label>
|
||||
<select name="format" id="format" onchange="update_preview(this);">
|
||||
<?php
|
||||
foreach($imports as $import_format => $name)
|
||||
{
|
||||
?><option value="<?= htmlspecialchars($import_format) ?>"<?=
|
||||
($format == $import_format) ? ' selected="selected"' : '' ?>><?=
|
||||
htmlspecialchars($name . " (" . $import_format . ")") ?></option><?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</form>
|
||||
<?php
|
||||
;
|
||||
}
|
||||
|
||||
if($file)
|
||||
{
|
||||
$cv = caca_create_canvas(0, 0);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't create canvas\n");
|
||||
}
|
||||
|
||||
if(caca_import_file($cv, $file, ($format == NULL) ? "" : $format) < 0)
|
||||
{
|
||||
die("could not import `" . htmlspecialchars($filename) . "'.\n");
|
||||
}
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
}
|
||||
else
|
||||
{
|
||||
?>See the <a href="export.php">libcaca export test program</a> for an <a
|
||||
href="export.php?format=caca">example file</a>.<?php
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
function pig() {
|
||||
$pig_str = <<<EOT
|
||||
|
||||
_._ _..._ .-', _.._(`))
|
||||
'-. ` ' /-._.-' ',/
|
||||
) \ '.
|
||||
/ _ _ | \
|
||||
| a a / PHP |
|
||||
\ .-. ;
|
||||
'-('' ).-' ,' ;
|
||||
'-; | .'
|
||||
\ \ /
|
||||
| 7 .__ _.-\ \
|
||||
| | | ``/ /` /
|
||||
jgs /,_| | /,_/ /
|
||||
/,_/ '`-'
|
||||
EOT;
|
||||
|
||||
$canvas = caca_create_canvas(0, 0);
|
||||
caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE);
|
||||
caca_import_string($canvas, $pig_str, "text");
|
||||
caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY);
|
||||
caca_put_str($canvas, 0, 0, "Я люблю Либкаку");
|
||||
return $canvas;
|
||||
}
|
||||
|
||||
|
||||
if (isset($_GET["png"])) {
|
||||
$canvas = pig();
|
||||
$font = caca_load_builtin_font("Monospace Bold 12");
|
||||
$width = caca_get_canvas_width($canvas) * caca_get_font_width($font);
|
||||
$height = caca_get_canvas_height($canvas) * caca_get_font_height($font);
|
||||
$img = imagecreatetruecolor($width, $height);
|
||||
caca_render_canvas($canvas, $font, $img);
|
||||
header("Content-type: image/png");
|
||||
imagepng($img);
|
||||
}
|
||||
else {
|
||||
|
||||
$render_php = isset($_SERVER['SCRIPT_NAME'])
|
||||
?
|
||||
$_SERVER['SCRIPT_NAME']
|
||||
:
|
||||
'render.php';
|
||||
|
||||
header("Content-type: text/html; charset=UTF-8");
|
||||
|
||||
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Я люблю Либкаку</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
|
||||
<h1>Text mode:</h1>
|
||||
<?echo caca_export_string(pig(), "html3");?>
|
||||
|
||||
<h1>Generated image:</h1>
|
||||
<a href="<?= htmlspecialchars($render_php) ?>?png=1"><img alt="[PNG]"
|
||||
src="<?= htmlspecialchars($render_php) ?>?png=1" border="0" /></a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* demo.php demo for libcaca php binding
|
||||
* Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
|
||||
*
|
||||
* This file is a Php port of the official libcaca's sample program "demo.c"
|
||||
* which is:
|
||||
* Copyright (c) 2003 Sam Hocevar <sam@hocevar.net>
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>demo for libcaca php binding</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
$string = <<<EOT
|
||||
|_|
|
||||
_,----._ | |
|
||||
(/ @ @ \) __
|
||||
| OO | |_
|
||||
\ `--' / |__
|
||||
`----'
|
||||
|_|
|
||||
Hello world! |
|
||||
EOT;
|
||||
|
||||
$pig = caca_create_canvas(0, 0);
|
||||
caca_import_string($pig, $string, "text");
|
||||
|
||||
$cv = caca_create_canvas(caca_get_canvas_width($pig) * 2, caca_get_canvas_height($pig) * 2);
|
||||
|
||||
if (!$cv or !$pig) {
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
|
||||
caca_blit($cv, 0, 0, $pig);
|
||||
caca_flip($pig);
|
||||
caca_blit($cv, caca_get_canvas_width($pig), 0, $pig);
|
||||
caca_flip($pig);
|
||||
caca_flop($pig);
|
||||
caca_blit($cv, 0, caca_get_canvas_height($pig), $pig);
|
||||
caca_flop($pig);
|
||||
caca_rotate_180($pig);
|
||||
caca_blit($cv, caca_get_canvas_width($pig), caca_get_canvas_height($pig), $pig);
|
||||
|
||||
for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
|
||||
for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
|
||||
caca_set_color_ansi($cv, CACA_LIGHTBLUE + ($i + $j) % 6, CACA_DEFAULT);
|
||||
$a = caca_get_attr($cv, -1, -1);
|
||||
caca_put_attr($cv, $i, $j, $a);
|
||||
caca_put_attr($cv, $i + 1, $j, $a);
|
||||
}
|
||||
}
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
caca_rotate_left($cv);
|
||||
echo caca_export_string($cv, "html3");
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* transform transformation test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/transform.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>transformation test program</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
$pig = (
|
||||
",--. ,--.\n" .
|
||||
"\\ /-~-\\ /\n" .
|
||||
" )' o O `(\n" .
|
||||
"( ,---. )\n" .
|
||||
" `(_o_o_)'\n" .
|
||||
" )`-'(\n");
|
||||
|
||||
$duck = (
|
||||
" ,~~.\n" .
|
||||
" __ , ( O )>\n" .
|
||||
"___( o)> )`~~' (\n" .
|
||||
"\\ <_. ) ( .__) )\n" .
|
||||
" `---' `-.____,'\n");
|
||||
|
||||
$cv = caca_create_canvas(80, 25);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
|
||||
$image = caca_create_canvas(70, 6);
|
||||
$tmp = caca_create_canvas(70, 6);
|
||||
$sprite = caca_create_canvas(0, 0);
|
||||
|
||||
caca_set_color_ansi($sprite, CACA_LIGHTMAGENTA, CACA_BLACK);
|
||||
caca_import_string($sprite, $pig, "text");
|
||||
caca_blit($image, 55, 0, $sprite);
|
||||
|
||||
caca_set_color_ansi($sprite, CACA_LIGHTGREEN, CACA_BLACK);
|
||||
caca_import_string($sprite, $duck, "text");
|
||||
caca_blit($image, 30, 1, $sprite);
|
||||
|
||||
caca_set_color_ansi($image, CACA_LIGHTCYAN, CACA_BLACK);
|
||||
caca_put_str($image, 1, 1, "hahaha mais vieux porc immonde !! [⽼ ⾗]");
|
||||
caca_set_color_ansi($image, CACA_LIGHTRED, CACA_BLACK);
|
||||
caca_put_char($image, 38, 1, ord('|'));
|
||||
|
||||
caca_set_color_ansi($image, CACA_YELLOW, CACA_BLACK);
|
||||
caca_put_str($image, 4, 2, "\\o\\ \\o| _o/ \\o_ |o/ /o/");
|
||||
|
||||
caca_set_color_ansi($image, CACA_WHITE, CACA_LIGHTRED);
|
||||
caca_put_str($image, 7, 3, "▙▘▌▙▘▞▖▞▖▌ ▞▖▌ ▌▌");
|
||||
caca_put_str($image, 7, 4, "▛▖▌▛▖▚▘▚▘▚▖▚▘▚▖▖▖");
|
||||
caca_set_color_ansi($image, CACA_BLACK, CACA_LIGHTRED);
|
||||
caca_put_str($image, 4, 3, "▓▒░");
|
||||
caca_put_str($image, 4, 4, "▓▒░");
|
||||
caca_put_str($image, 24, 3, "░▒▓");
|
||||
caca_put_str($image, 24, 4, "░▒▓");
|
||||
|
||||
/* Blit the transformed canvas onto the main canvas */
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 0, 0, "normal");
|
||||
caca_blit($cv, 10, 0, $image);
|
||||
|
||||
caca_put_str($cv, 0, 6, "flip");
|
||||
caca_blit($tmp, 0, 0, $image);
|
||||
caca_flip($tmp);
|
||||
caca_blit($cv, 10, 6, $tmp);
|
||||
|
||||
caca_put_str($cv, 0, 12, "flop");
|
||||
caca_blit($tmp, 0, 0, $image);
|
||||
caca_flop($tmp);
|
||||
caca_blit($cv, 10, 12, $tmp);
|
||||
|
||||
caca_put_str($cv, 0, 18, "rotate");
|
||||
caca_blit($tmp, 0, 0, $image);
|
||||
caca_rotate_180($tmp);
|
||||
caca_blit($cv, 10, 18, $tmp);
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* truecolor truecolor canvas features
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/truecolor.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>truecolor canvas features</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
$cv = caca_create_canvas(32, 16);
|
||||
if(!$cv) {
|
||||
die("Failed to create canvas\n");
|
||||
}
|
||||
|
||||
for($y = 0; $y < 16; $y++)
|
||||
for($x = 0; $x < 16; $x++)
|
||||
{
|
||||
$bgcolor = 0xff00 | ($y << 4) | $x;
|
||||
$fgcolor = 0xf000 | ((15 - $y) << 4) | ((15 - $x) << 8);
|
||||
|
||||
caca_set_color_argb($cv, $fgcolor, $bgcolor);
|
||||
caca_put_str($cv, $x * 2, $y, "CA");
|
||||
}
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
|
||||
caca_put_str($cv, 2, 1, " truecolor libcaca ");
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<?php
|
||||
/*
|
||||
* unicode libcaca Unicode rendering test program
|
||||
* Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
|
||||
*
|
||||
* This file is a Php port of "examples/unicode.c"
|
||||
* which is:
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
?>
|
||||
<head>
|
||||
<title>libcaca Unicode rendering test program</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
</head>
|
||||
<body text="silver" bgcolor="black">
|
||||
<?php
|
||||
|
||||
$cv = caca_create_canvas(80, 25);
|
||||
if(! $cv)
|
||||
{
|
||||
die("Can't created canvas\n");
|
||||
}
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 1, 1, "Basic Unicode support");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 2, "This is ASCII: | abc DEF 123 !@# |");
|
||||
caca_put_str($cv, 1, 3, "This is Unicode: | äßç δεφ ☺♥♀ ╞╬╗ |");
|
||||
caca_put_str($cv, 1, 4, "And this is, too: | ἀβϛ ΔЗҒ ᚴᛒᛯ ♩♔✈ |");
|
||||
|
||||
caca_put_str($cv, 1, 5, "If the three lines do not have the same length, there is a bug somewhere.");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 1, 7, "Gradient glyphs");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 31, 8, " 0%");
|
||||
caca_put_str($cv, 31, 9, " 25%");
|
||||
caca_put_str($cv, 31, 10, " 50%");
|
||||
caca_put_str($cv, 31, 11, " 75%");
|
||||
caca_put_str($cv, 31, 12, "100%");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_LIGHTGREEN);
|
||||
caca_put_str($cv, 1, 8, " ");
|
||||
caca_put_str($cv, 1, 9, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
|
||||
caca_put_str($cv, 1, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
|
||||
caca_put_str($cv, 1, 11, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
|
||||
caca_put_str($cv, 1, 12, "█████████████████████████████");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_LIGHTRED);
|
||||
caca_put_str($cv, 36, 8, "█████████████████████████████");
|
||||
caca_put_str($cv, 36, 9, "▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓");
|
||||
caca_put_str($cv, 36, 10, "▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒");
|
||||
caca_put_str($cv, 36, 11, "░░░░░░░░░░░░░░░░░░░░░░░░░░░░░");
|
||||
caca_put_str($cv, 36, 12, " ");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLUE);
|
||||
caca_put_str($cv, 1, 14, "Double width characters");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 15, "| ドラゴン ボーレ |");
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 16, "| ()()()() ()()() |");
|
||||
caca_set_color_ansi($cv, CACA_YELLOW, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 17, "| ドラゴン");
|
||||
caca_put_str($cv, 12, 17, "ボーレ |");
|
||||
|
||||
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
caca_put_str($cv, 1, 18, "If the three lines do not have the same length, there is a bug somewhere.");
|
||||
|
||||
caca_put_str($cv, 1, 20, "CP437 glyphs: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼");
|
||||
caca_put_str($cv, 1, 21, "more CP437: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■");
|
||||
caca_put_str($cv, 1, 22, "drawing blocks: ███ ▓▓▓ ▒▒▒ ░░░ ▀ ▄ ▌ ▐ █ ▖ ▗ ▘ ▝ ▚ ▞ ▙ ▛ ▜ ▟ ─ │ ┌ ┐ └ ┘ ├ ┤");
|
||||
caca_put_str($cv, 1, 23, "more drawing: ┬ ┴ ┼ ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬");
|
||||
caca_put_str($cv, 1, 24, "misc Unicode: ● ☭ ☮ ☯ ♔ ♛ ♙ ♞ ⚒ ⚓ ⚠");
|
||||
|
||||
echo caca_export_string($cv, "html3");
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,33 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0">
|
||||
<package version="1.0" packagerversion="1.4.8">
|
||||
<name>caca</name>
|
||||
<summary>PHP binding for libcaca</summary>
|
||||
<description>This extension allows PHP scripts to use libcaca.
|
||||
</description>
|
||||
<maintainers>
|
||||
<maintainer>
|
||||
<user>zMoo</user>
|
||||
<name>Nicolas Vion</name>
|
||||
<email>nico@yojik.eu</email>
|
||||
<role>lead</role>
|
||||
</maintainer>
|
||||
</maintainers>
|
||||
<release>
|
||||
<version>0.0</version>
|
||||
<date>2008-10-15</date>
|
||||
<license>WTFPL</license>
|
||||
<state>alpha</state>
|
||||
<notes>See included ChangeLog for details...
|
||||
</notes>
|
||||
<deps>
|
||||
<dep type="php" rel="ge" version="5.0.0"/>
|
||||
</deps>
|
||||
<filelist>
|
||||
<file role="data" name="examples/example1.php"/>
|
||||
<file role="src" name="config.m4"/>
|
||||
<file role="src" name="php_caca.c"/>
|
||||
<file role="src" name="php_caca.h"/>
|
||||
</filelist>
|
||||
</release>
|
||||
</package>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,174 @@
|
|||
/*
|
||||
* php-caca Php binding for Libcaca
|
||||
* Copyright (c) 2008 Vion Nicolas <nico@picapo.net>
|
||||
*
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
#ifndef PHP_CACA_H
|
||||
#define PHP_CACA_H
|
||||
|
||||
#include <caca.h>
|
||||
|
||||
#define PHP_CACA_VERSION "0.0"
|
||||
#define PHP_CACA_EXTNAME "caca"
|
||||
|
||||
#define PHP_CACA_CANVAS_RES_NAME "caca_canvas"
|
||||
#define PHP_CACA_DITHER_RES_NAME "caca_dither"
|
||||
#define PHP_CACA_FONT_RES_NAME "caca_font"
|
||||
#define PHP_CACA_FILE_RES_NAME "caca_file"
|
||||
#define PHP_CACA_DISPLAY_RES_NAME "caca_display"
|
||||
#define PHP_CACA_EVENT_RES_NAME "caca_event"
|
||||
|
||||
int le_caca_canvas;
|
||||
int le_caca_dither;
|
||||
int le_caca_font;
|
||||
int le_caca_file;
|
||||
int le_caca_display;
|
||||
int le_caca_event;
|
||||
|
||||
PHP_MINIT_FUNCTION(caca);
|
||||
PHP_MINFO_FUNCTION(caca);
|
||||
|
||||
PHP_FUNCTION(caca_create_canvas);
|
||||
PHP_FUNCTION(caca_set_canvas_size);
|
||||
PHP_FUNCTION(caca_get_canvas_width);
|
||||
PHP_FUNCTION(caca_get_canvas_height);
|
||||
PHP_FUNCTION(caca_get_canvas_chars);
|
||||
PHP_FUNCTION(caca_get_canvas_attrs);
|
||||
PHP_FUNCTION(caca_rand);
|
||||
PHP_FUNCTION(caca_get_version);
|
||||
PHP_FUNCTION(caca_gotoxy);
|
||||
PHP_FUNCTION(caca_wherex);
|
||||
PHP_FUNCTION(caca_wherey);
|
||||
PHP_FUNCTION(caca_put_char);
|
||||
PHP_FUNCTION(caca_get_char);
|
||||
PHP_FUNCTION(caca_put_str);
|
||||
PHP_FUNCTION(caca_clear_canvas);
|
||||
PHP_FUNCTION(caca_set_canvas_handle);
|
||||
PHP_FUNCTION(caca_get_canvas_handle_x);
|
||||
PHP_FUNCTION(caca_get_canvas_handle_y);
|
||||
PHP_FUNCTION(caca_blit);
|
||||
PHP_FUNCTION(caca_set_canvas_boundaries);
|
||||
PHP_FUNCTION(caca_invert);
|
||||
PHP_FUNCTION(caca_flip);
|
||||
PHP_FUNCTION(caca_flop);
|
||||
PHP_FUNCTION(caca_rotate_180);
|
||||
PHP_FUNCTION(caca_rotate_left);
|
||||
PHP_FUNCTION(caca_rotate_right);
|
||||
PHP_FUNCTION(caca_stretch_left);
|
||||
PHP_FUNCTION(caca_stretch_right);
|
||||
PHP_FUNCTION(caca_get_attr);
|
||||
PHP_FUNCTION(caca_set_attr);
|
||||
PHP_FUNCTION(caca_put_attr);
|
||||
PHP_FUNCTION(caca_set_color_ansi);
|
||||
PHP_FUNCTION(caca_set_color_argb);
|
||||
PHP_FUNCTION(caca_attr_to_ansi);
|
||||
PHP_FUNCTION(caca_attr_to_ansi_fg);
|
||||
PHP_FUNCTION(caca_attr_to_ansi_bg);
|
||||
PHP_FUNCTION(caca_attr_to_rgb12_fg);
|
||||
PHP_FUNCTION(caca_attr_to_rgb12_bg);
|
||||
PHP_FUNCTION(caca_attr_to_argb64);
|
||||
PHP_FUNCTION(caca_utf8_to_utf32);
|
||||
PHP_FUNCTION(caca_utf32_to_utf8);
|
||||
PHP_FUNCTION(caca_utf32_to_cp437);
|
||||
PHP_FUNCTION(caca_cp437_to_utf32);
|
||||
PHP_FUNCTION(caca_utf32_to_ascii);
|
||||
PHP_FUNCTION(caca_utf32_is_fullwidth);
|
||||
PHP_FUNCTION(caca_draw_line);
|
||||
PHP_FUNCTION(caca_draw_polyline);
|
||||
PHP_FUNCTION(caca_draw_thin_line);
|
||||
PHP_FUNCTION(caca_draw_thin_polyline);
|
||||
PHP_FUNCTION(caca_draw_circle);
|
||||
PHP_FUNCTION(caca_draw_ellipse);
|
||||
PHP_FUNCTION(caca_draw_thin_ellipse);
|
||||
PHP_FUNCTION(caca_fill_ellipse);
|
||||
PHP_FUNCTION(caca_draw_box);
|
||||
PHP_FUNCTION(caca_draw_thin_box);
|
||||
PHP_FUNCTION(caca_draw_cp437_box);
|
||||
PHP_FUNCTION(caca_fill_box);
|
||||
PHP_FUNCTION(caca_draw_triangle);
|
||||
PHP_FUNCTION(caca_draw_thin_triangle);
|
||||
PHP_FUNCTION(caca_fill_triangle);
|
||||
PHP_FUNCTION(caca_get_frame_count);
|
||||
PHP_FUNCTION(caca_set_frame);
|
||||
PHP_FUNCTION(caca_set_frame_name);
|
||||
PHP_FUNCTION(caca_create_frame);
|
||||
PHP_FUNCTION(caca_free_frame);
|
||||
PHP_FUNCTION(caca_create_dither);
|
||||
PHP_FUNCTION(caca_set_dither_palette);
|
||||
PHP_FUNCTION(caca_set_dither_brightness);
|
||||
PHP_FUNCTION(caca_get_dither_brightness);
|
||||
PHP_FUNCTION(caca_set_dither_gamma);
|
||||
PHP_FUNCTION(caca_get_dither_gamma);
|
||||
PHP_FUNCTION(caca_set_dither_contrast);
|
||||
PHP_FUNCTION(caca_get_dither_contrast);
|
||||
PHP_FUNCTION(caca_set_dither_antialias);
|
||||
PHP_FUNCTION(caca_get_dither_antialias_list);
|
||||
PHP_FUNCTION(caca_get_dither_antialias);
|
||||
PHP_FUNCTION(caca_set_dither_color);
|
||||
PHP_FUNCTION(caca_get_dither_color_list);
|
||||
PHP_FUNCTION(caca_get_dither_color);
|
||||
PHP_FUNCTION(caca_set_dither_charset);
|
||||
PHP_FUNCTION(caca_get_dither_charset_list);
|
||||
PHP_FUNCTION(caca_get_dither_charset);
|
||||
PHP_FUNCTION(caca_set_dither_algorithm);
|
||||
PHP_FUNCTION(caca_get_dither_algorithm_list);
|
||||
PHP_FUNCTION(caca_get_dither_algorithm);
|
||||
PHP_FUNCTION(caca_dither_bitmap);
|
||||
PHP_FUNCTION(caca_load_font);
|
||||
PHP_FUNCTION(caca_load_builtin_font);
|
||||
PHP_FUNCTION(caca_get_font_list);
|
||||
PHP_FUNCTION(caca_get_font_width);
|
||||
PHP_FUNCTION(caca_get_font_height);
|
||||
PHP_FUNCTION(caca_get_font_blocks);
|
||||
PHP_FUNCTION(caca_render_canvas);
|
||||
PHP_FUNCTION(caca_canvas_set_figfont);
|
||||
PHP_FUNCTION(caca_put_figchar);
|
||||
PHP_FUNCTION(caca_flush_figlet);
|
||||
PHP_FUNCTION(caca_file_open);
|
||||
PHP_FUNCTION(caca_file_close);
|
||||
PHP_FUNCTION(caca_file_tell);
|
||||
PHP_FUNCTION(caca_file_read);
|
||||
PHP_FUNCTION(caca_file_write);
|
||||
PHP_FUNCTION(caca_file_gets);
|
||||
PHP_FUNCTION(caca_file_eof);
|
||||
PHP_FUNCTION(caca_import_string);
|
||||
PHP_FUNCTION(caca_import_file);
|
||||
PHP_FUNCTION(caca_get_import_list);
|
||||
PHP_FUNCTION(caca_export_string);
|
||||
PHP_FUNCTION(caca_get_export_list);
|
||||
PHP_FUNCTION(caca_create_display);
|
||||
PHP_FUNCTION(caca_create_display_with_driver);
|
||||
PHP_FUNCTION(caca_get_display_driver_list);
|
||||
PHP_FUNCTION(caca_get_display_driver);
|
||||
PHP_FUNCTION(caca_set_display_driver);
|
||||
PHP_FUNCTION(caca_get_canvas);
|
||||
PHP_FUNCTION(caca_refresh_display);
|
||||
PHP_FUNCTION(caca_set_display_time);
|
||||
PHP_FUNCTION(caca_get_display_time);
|
||||
PHP_FUNCTION(caca_get_display_width);
|
||||
PHP_FUNCTION(caca_get_display_height);
|
||||
PHP_FUNCTION(caca_set_display_title);
|
||||
PHP_FUNCTION(caca_set_mouse);
|
||||
PHP_FUNCTION(caca_set_cursor);
|
||||
PHP_FUNCTION(caca_get_event);
|
||||
PHP_FUNCTION(caca_get_mouse_x);
|
||||
PHP_FUNCTION(caca_get_mouse_y);
|
||||
PHP_FUNCTION(caca_get_event_type);
|
||||
PHP_FUNCTION(caca_get_event_key_ch);
|
||||
PHP_FUNCTION(caca_get_event_mouse_button);
|
||||
PHP_FUNCTION(caca_get_event_mouse_x);
|
||||
PHP_FUNCTION(caca_get_event_mouse_y);
|
||||
PHP_FUNCTION(caca_get_event_resize_width);
|
||||
PHP_FUNCTION(caca_get_event_resize_height);
|
||||
|
||||
extern zend_module_entry caca_module_entry;
|
||||
#define phpext_caca_ptr &caca_module_entry
|
||||
|
||||
#endif
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* AssemblyInfo .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: AssemblyTitle("Caca")]
|
||||
[assembly: AssemblyDescription("libcaca .NET bindings")]
|
||||
[assembly: AssemblyCopyright("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org")]
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
public class Attr
|
||||
{
|
||||
private uint _attr;
|
||||
|
||||
public Attr(uint attr)
|
||||
{
|
||||
_attr = attr;
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern byte caca_attr_to_ansi(uint a);
|
||||
public byte toAnsi()
|
||||
{
|
||||
return caca_attr_to_ansi(_attr);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern byte caca_attr_to_ansi_fg(uint a);
|
||||
public byte toAnsiFg()
|
||||
{
|
||||
return caca_attr_to_ansi_fg(_attr);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern byte caca_attr_to_ansi_bg(uint a);
|
||||
public byte toAnsiBg()
|
||||
{
|
||||
return caca_attr_to_ansi_bg(_attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
/* Static libcaca stuff that does not fit in any object */
|
||||
public static class Libcaca
|
||||
{
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_rand(int min, int max);
|
||||
public static int Rand(int min, int max)
|
||||
{
|
||||
return caca_rand(min, max);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_get_version();
|
||||
public static string getVersion()
|
||||
{
|
||||
return Marshal.PtrToStringAnsi(caca_get_version());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,682 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007-2009 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
public enum AnsiColor
|
||||
{
|
||||
BLACK = 0x00,
|
||||
BLUE = 0x01,
|
||||
GREEN = 0x02,
|
||||
CYAN = 0x03,
|
||||
RED = 0x04,
|
||||
MAGENTA = 0x05,
|
||||
BROWN = 0x06,
|
||||
LIGHTGRAY = 0x07,
|
||||
DARKGRAY = 0x08,
|
||||
LIGHTBLUE = 0x09,
|
||||
LIGHTGREEN = 0x0a,
|
||||
LIGHTCYAN = 0x0b,
|
||||
LIGHTRED = 0x0c,
|
||||
LIGHTMAGENTA = 0x0d,
|
||||
YELLOW = 0x0e,
|
||||
WHITE = 0x0f,
|
||||
DEFAULT = 0x10,
|
||||
TRANSPARENT = 0x20,
|
||||
}
|
||||
|
||||
public enum AnsiStyle
|
||||
{
|
||||
BOLD = 0x01,
|
||||
ITALICS = 0x02,
|
||||
UNDERLINE = 0x04,
|
||||
BLINK = 0x08,
|
||||
}
|
||||
|
||||
public class Canvas : IDisposable
|
||||
{
|
||||
public readonly IntPtr _c_cv;
|
||||
|
||||
/* libcaca basic functions */
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_create_canvas(int w, int h);
|
||||
public Canvas()
|
||||
{
|
||||
_c_cv = caca_create_canvas(0, 0);
|
||||
}
|
||||
|
||||
public Canvas(Size s)
|
||||
{
|
||||
_c_cv = caca_create_canvas(s.Width, s.Height);
|
||||
}
|
||||
|
||||
public Canvas(int w, int h)
|
||||
{
|
||||
_c_cv = caca_create_canvas(h, w);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_free_canvas(IntPtr cv);
|
||||
public void Dispose()
|
||||
{
|
||||
/* FIXME: don't destroy ourselves if we're attached */
|
||||
caca_free_canvas(_c_cv);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_canvas_size(IntPtr cv,
|
||||
int w, int h);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_canvas_width(IntPtr cv);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_canvas_height(IntPtr cv);
|
||||
public Size Size
|
||||
{
|
||||
get { return new Size(caca_get_canvas_width(_c_cv),
|
||||
caca_get_canvas_height(_c_cv)); }
|
||||
set { caca_set_canvas_size(_c_cv, value.Width, value.Height); }
|
||||
}
|
||||
|
||||
public Rectangle Rectangle
|
||||
{
|
||||
get { return new Rectangle(0, 0, caca_get_canvas_width(_c_cv),
|
||||
caca_get_canvas_height(_c_cv)); }
|
||||
set { caca_set_canvas_size(_c_cv, value.Width, value.Height); }
|
||||
}
|
||||
|
||||
/* canvas drawing */
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_gotoxy(IntPtr cv, int x, int y);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_wherex(IntPtr cv);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_wherey(IntPtr cv);
|
||||
public Point Cursor
|
||||
{
|
||||
get { return new Point(caca_wherex(_c_cv), caca_wherey(_c_cv)); }
|
||||
set { caca_gotoxy(_c_cv, value.X, value.Y); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_put_char(IntPtr cv,
|
||||
int x, int y, uint c);
|
||||
public int putChar(Point p, uint c)
|
||||
{
|
||||
return caca_put_char(_c_cv, p.X, p.Y, c);
|
||||
}
|
||||
|
||||
public int putChar(int x, int y, uint c)
|
||||
{
|
||||
return caca_put_char(_c_cv, x, y, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern uint caca_get_char(IntPtr cv, int x, int y);
|
||||
public uint getChar(Point p)
|
||||
{
|
||||
return caca_get_char(_c_cv, p.X, p.Y);
|
||||
}
|
||||
|
||||
public uint getChar(int x, int y)
|
||||
{
|
||||
return caca_get_char(_c_cv, x, y);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_put_str(IntPtr cv,
|
||||
int x, int y, string c);
|
||||
public int putStr(Point p, string c)
|
||||
{
|
||||
return caca_put_str(_c_cv, p.X, p.Y, c);
|
||||
}
|
||||
|
||||
public int putStr(int x, int y, string c)
|
||||
{
|
||||
return caca_put_str(_c_cv, x, y, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_attr(IntPtr cv, int x, int y);
|
||||
public int getAttr(Point p)
|
||||
{
|
||||
return caca_get_attr(_c_cv, p.X, p.Y);
|
||||
}
|
||||
|
||||
public int getAttr(int x, int y)
|
||||
{
|
||||
return caca_get_attr(_c_cv, x, y);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_attr(IntPtr cv, uint a);
|
||||
public int setAttr(uint a)
|
||||
{
|
||||
return caca_set_attr(_c_cv, a);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_put_attr(IntPtr cv,
|
||||
int x, int y, uint a);
|
||||
public int putAttr(Point p, uint a)
|
||||
{
|
||||
return caca_put_attr(_c_cv, p.X, p.Y, a);
|
||||
}
|
||||
|
||||
public int putAttr(int x, int y, uint a)
|
||||
{
|
||||
return caca_put_attr(_c_cv, x, y, a);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_color_ansi(IntPtr cv,
|
||||
byte fg, byte bg);
|
||||
public int setColorAnsi(AnsiColor fg, AnsiColor bg)
|
||||
{
|
||||
return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
|
||||
}
|
||||
|
||||
public int setColorAnsi(uint fg, AnsiColor bg)
|
||||
{
|
||||
return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
|
||||
}
|
||||
|
||||
public int setColorAnsi(AnsiColor fg, uint bg)
|
||||
{
|
||||
return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
|
||||
}
|
||||
|
||||
public int setColorAnsi(uint fg, uint bg)
|
||||
{
|
||||
return caca_set_color_ansi(_c_cv, (byte)fg, (byte)bg);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_color_argb(IntPtr cv,
|
||||
uint fg, uint bg);
|
||||
public int setColorArgb(ushort fg, ushort bg)
|
||||
{
|
||||
return caca_set_color_argb(_c_cv, fg, bg);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_clear_canvas(IntPtr cv);
|
||||
public int Clear()
|
||||
{
|
||||
return caca_clear_canvas(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_canvas_handle(IntPtr cv,
|
||||
int x, int y);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_canvas_handle_x(IntPtr cv);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_canvas_handle_y(IntPtr cv);
|
||||
public Point Handle
|
||||
{
|
||||
get { return new Point(caca_get_canvas_handle_x(_c_cv),
|
||||
caca_get_canvas_handle_y(_c_cv)); }
|
||||
set { caca_set_canvas_handle(_c_cv, value.X, value.Y); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_blit(IntPtr cv, int x, int y,
|
||||
IntPtr cv1, IntPtr cv2);
|
||||
public int Blit(Point p, Canvas canvas)
|
||||
{
|
||||
return caca_blit(_c_cv, p.X, p.Y, canvas._c_cv, IntPtr.Zero);
|
||||
}
|
||||
|
||||
public int Blit(Point p, Canvas cv, Canvas mask)
|
||||
{
|
||||
return caca_blit(_c_cv, p.X, p.Y, cv._c_cv, mask._c_cv);
|
||||
}
|
||||
|
||||
public int Blit(int x, int y, Canvas canvas)
|
||||
{
|
||||
return caca_blit(_c_cv, x, y, canvas._c_cv, IntPtr.Zero);
|
||||
}
|
||||
|
||||
public int Blit(int x, int y, Canvas cv, Canvas mask)
|
||||
{
|
||||
return caca_blit(_c_cv, x, y, cv._c_cv, mask._c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_canvas_boundaries(IntPtr cv,
|
||||
int x, int y,
|
||||
int h, int w);
|
||||
public int setBoundaries(Rectangle r)
|
||||
{
|
||||
return caca_set_canvas_boundaries(_c_cv, r.X, r.Y,
|
||||
r.Width, r.Height);
|
||||
}
|
||||
|
||||
public int setBoundaries(int x, int y, int w, int h)
|
||||
{
|
||||
return caca_set_canvas_boundaries(_c_cv, x, y, w, h);
|
||||
}
|
||||
|
||||
/* canvas transformation */
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_invert(IntPtr cv);
|
||||
public int Invert()
|
||||
{
|
||||
return caca_invert(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_flip(IntPtr cv);
|
||||
public int Flip()
|
||||
{
|
||||
return caca_flip(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_flop(IntPtr cv);
|
||||
public int Flop()
|
||||
{
|
||||
return caca_flop(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_rotate_180(IntPtr cv);
|
||||
public int Rotate180()
|
||||
{
|
||||
return caca_rotate_180(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_rotate_left(IntPtr cv);
|
||||
public int RotateLeft()
|
||||
{
|
||||
return caca_rotate_left(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_rotate_right(IntPtr cv);
|
||||
public int RotateRight()
|
||||
{
|
||||
return caca_rotate_right(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_stretch_left(IntPtr cv);
|
||||
public int StretchLeft()
|
||||
{
|
||||
return caca_stretch_left(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_stretch_right(IntPtr cv);
|
||||
public int StretchRight()
|
||||
{
|
||||
return caca_stretch_right(_c_cv);
|
||||
}
|
||||
|
||||
/* primitives drawing */
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_line(IntPtr cv, int x1, int y1,
|
||||
int x2, int y2, uint c);
|
||||
public int drawLine(Point p1, Point p2, uint c)
|
||||
{
|
||||
return caca_draw_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y, c);
|
||||
}
|
||||
|
||||
public int drawLine(int x1, int y1, int x2, int y2, uint c)
|
||||
{
|
||||
return caca_draw_line(_c_cv, x1, y1, x2, y2, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_polyline(IntPtr cv, int[] x,
|
||||
int[] y, int n, uint c);
|
||||
public int drawPolyline(Point[] lp, uint c)
|
||||
{
|
||||
int[] lx = new int[lp.Length];
|
||||
int[] ly = new int[lp.Length];
|
||||
for(int i = 0; i < lp.Length; i++)
|
||||
{
|
||||
lx[i] = lp[i].X;
|
||||
ly[i] = lp[i].Y;
|
||||
}
|
||||
return caca_draw_polyline(_c_cv, lx, ly, lp.Length - 1, c);
|
||||
}
|
||||
|
||||
public int drawPolyline(int[] lx, int[] ly, uint c)
|
||||
{
|
||||
if(lx.Length != ly.Length)
|
||||
return -1;
|
||||
|
||||
return caca_draw_polyline(_c_cv, lx, ly, lx.Length - 1, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_thin_line(IntPtr cv, int x1,
|
||||
int y1, int x2, int y2);
|
||||
public int drawThinLine(Point p1, Point p2)
|
||||
{
|
||||
return caca_draw_thin_line(_c_cv, p1.X, p1.Y, p2.X, p2.Y);
|
||||
}
|
||||
|
||||
public int drawThinLine(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
return caca_draw_thin_line(_c_cv, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_thin_polyline(IntPtr cv, int[] x,
|
||||
int[] y, int n);
|
||||
public int drawThinPolyline(Point[] lp)
|
||||
{
|
||||
int[] lx = new int[lp.Length];
|
||||
int[] ly = new int[lp.Length];
|
||||
for(int i = 0; i < lp.Length; i++)
|
||||
{
|
||||
lx[i] = lp[i].X;
|
||||
ly[i] = lp[i].Y;
|
||||
}
|
||||
return caca_draw_thin_polyline(_c_cv, lx, ly, lp.Length - 1);
|
||||
}
|
||||
|
||||
public int drawThinPolyline(int[] lx, int[] ly)
|
||||
{
|
||||
if(lx.Length != ly.Length)
|
||||
return -1;
|
||||
|
||||
return caca_draw_thin_polyline(_c_cv, lx, ly, lx.Length - 1);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_circle(IntPtr cv, int x, int y,
|
||||
int r, uint c);
|
||||
public int drawCircle(Point p, int r, uint c)
|
||||
{
|
||||
return caca_draw_circle(_c_cv, p.X, p.Y, r, c);
|
||||
}
|
||||
|
||||
public int drawCircle(int x, int y, int r, uint c)
|
||||
{
|
||||
return caca_draw_circle(_c_cv, x, y, r, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_ellipse(IntPtr cv, int x, int y,
|
||||
int a, int b, uint c);
|
||||
public int drawEllipse(Point p, int a, int b, uint c)
|
||||
{
|
||||
return caca_draw_ellipse(_c_cv, p.X, p.Y, a, b, c);
|
||||
}
|
||||
|
||||
public int drawEllipse(int x, int y, int a, int b, uint c)
|
||||
{
|
||||
return caca_draw_ellipse(_c_cv, x, y, a, b, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_thin_ellipse(IntPtr cv,
|
||||
int x, int y,
|
||||
int a, int b);
|
||||
public int drawThinEllipse(Point p, int a, int b)
|
||||
{
|
||||
return caca_draw_thin_ellipse(_c_cv, p.X, p.Y, a, b);
|
||||
}
|
||||
|
||||
public int drawThinEllipse(int x, int y, int a, int b)
|
||||
{
|
||||
return caca_draw_thin_ellipse(_c_cv, x, y, a, b);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_fill_ellipse(IntPtr cv, int x, int y,
|
||||
int a, int b, uint c);
|
||||
public int fillEllipse(Point p, int a, int b, uint c)
|
||||
{
|
||||
return caca_fill_ellipse(_c_cv, p.X, p.Y, a, b, c);
|
||||
}
|
||||
|
||||
public int fillEllipse(int x, int y, int a, int b, uint c)
|
||||
{
|
||||
return caca_fill_ellipse(_c_cv, x, y, a, b, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_box(IntPtr cv, int x, int y,
|
||||
int w, int h, uint c);
|
||||
public int drawBox(Rectangle r, uint c)
|
||||
{
|
||||
return caca_draw_box(_c_cv, r.X, r.Y, r.Width, r.Height, c);
|
||||
}
|
||||
|
||||
public int drawBox(int x, int y, int w, int h, uint c)
|
||||
{
|
||||
return caca_draw_box(_c_cv, x, y, w, h, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_thin_box(IntPtr cv, int x, int y,
|
||||
int w, int h);
|
||||
public int drawThinBox(Rectangle r)
|
||||
{
|
||||
return caca_draw_thin_box(_c_cv, r.X, r.Y, r.Width, r.Height);
|
||||
}
|
||||
|
||||
public int drawThinBox(int x, int y, int w, int h)
|
||||
{
|
||||
return caca_draw_thin_box(_c_cv, x, y, w, h);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_cp437_box(IntPtr cv, int x, int y,
|
||||
int w, int h);
|
||||
public int drawCp437Box(Rectangle r)
|
||||
{
|
||||
return caca_draw_cp437_box(_c_cv, r.X, r.Y, r.Width, r.Height);
|
||||
}
|
||||
|
||||
public int drawCp437Box(int x, int y, int w, int h)
|
||||
{
|
||||
return caca_draw_cp437_box(_c_cv, x, y, w, h);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_fill_box(IntPtr cv, int x, int y,
|
||||
int w, int h, uint c);
|
||||
public int fillBox(Rectangle r, uint c)
|
||||
{
|
||||
return caca_fill_box(_c_cv, r.X, r.Y, r.Width, r.Height, c);
|
||||
}
|
||||
|
||||
public int fillBox(int x, int y, int w, int h, uint c)
|
||||
{
|
||||
return caca_fill_box(_c_cv, x, y, w, h, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_triangle(IntPtr cv, int x1,
|
||||
int y1, int x2, int y2,
|
||||
int x3, int y3, uint c);
|
||||
public int drawTriangle(Point p1, Point p2, Point p3, uint c)
|
||||
{
|
||||
return caca_draw_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
|
||||
p3.X, p3.Y, c);
|
||||
}
|
||||
|
||||
public int drawTriangle(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, uint c)
|
||||
{
|
||||
return caca_draw_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_draw_thin_triangle(IntPtr cv,
|
||||
int x1, int y1,
|
||||
int x2, int y2,
|
||||
int x3, int y3);
|
||||
public int drawThinTriangle(Point p1, Point p2, Point p3)
|
||||
{
|
||||
return caca_draw_thin_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
|
||||
p3.X, p3.Y);
|
||||
}
|
||||
|
||||
public int drawThinTriangle(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3)
|
||||
{
|
||||
return caca_draw_thin_triangle(_c_cv, x1, y1, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_fill_triangle(IntPtr cv, int x1,
|
||||
int y1, int x2, int y2,
|
||||
int x3, int y3, uint c);
|
||||
public int fillTriangle(Point p1, Point p2, Point p3, uint c)
|
||||
{
|
||||
return caca_fill_triangle(_c_cv, p1.X, p1.Y, p2.X, p2.Y,
|
||||
p3.X, p3.Y, c);
|
||||
}
|
||||
|
||||
public int fillTriangle(int x1, int y1, int x2, int y2,
|
||||
int x3, int y3, uint c)
|
||||
{
|
||||
return caca_fill_triangle(_c_cv, x1, y1, x2, y2, x3, y3, c);
|
||||
}
|
||||
|
||||
/* frame handling */
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_frame_count(IntPtr cv);
|
||||
public int getFrameCount()
|
||||
{
|
||||
return caca_get_frame_count(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_frame(IntPtr cv, int f);
|
||||
public int setFrame(int f)
|
||||
{
|
||||
return caca_set_frame(_c_cv, f);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern string caca_get_frame_name(IntPtr cv);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_frame_name(IntPtr cv, string n);
|
||||
public string FrameName
|
||||
{
|
||||
get { return caca_get_frame_name(_c_cv); }
|
||||
set { caca_set_frame_name(_c_cv, value); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_create_frame(IntPtr cv, int f);
|
||||
public int createFrame(int f)
|
||||
{
|
||||
return caca_create_frame(_c_cv, f);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_free_frame(IntPtr cv, int f);
|
||||
public int freeFrame(int f)
|
||||
{
|
||||
return caca_free_frame(_c_cv, f);
|
||||
}
|
||||
|
||||
/* bitmap dithering */
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_dither_bitmap(IntPtr c, int x, int y,
|
||||
int w, int h,
|
||||
IntPtr d, IntPtr data);
|
||||
public int ditherBitmap(Rectangle r, Dither d, object data)
|
||||
{
|
||||
GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
int ret = caca_dither_bitmap(_c_cv, r.X, r.Y, r.Width, r.Height,
|
||||
d._dither, gch.AddrOfPinnedObject());
|
||||
gch.Free();
|
||||
return ret;
|
||||
}
|
||||
|
||||
public int ditherBitmap(int x, int y, int w, int h,
|
||||
Dither d, object data)
|
||||
{
|
||||
GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
int ret = caca_dither_bitmap(_c_cv, x, y, w, h, d._dither,
|
||||
gch.AddrOfPinnedObject());
|
||||
gch.Free();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,139 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
public class Display : IDisposable
|
||||
{
|
||||
private Canvas _cv;
|
||||
public Canvas Canvas { get { return _cv; } }
|
||||
|
||||
private IntPtr _c_cv;
|
||||
private IntPtr _c_dp;
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_create_display(IntPtr cv);
|
||||
public Display(Canvas cv)
|
||||
{
|
||||
_cv = cv;
|
||||
_c_cv = _cv._c_cv;
|
||||
_c_dp = caca_create_display(_c_cv);
|
||||
}
|
||||
|
||||
public Display()
|
||||
{
|
||||
/* XXX: we do not call caca_create_display() with a NULL
|
||||
* argument because it's then impossible to create a Canvas
|
||||
* and I don't want to add a weird constructor */
|
||||
_cv = new Canvas();
|
||||
_c_cv = _cv._c_cv;
|
||||
_c_dp = caca_create_display(_c_cv);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_free_display(IntPtr dp);
|
||||
public void Dispose()
|
||||
{
|
||||
caca_free_display(_c_dp);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_refresh_display(IntPtr dp);
|
||||
public void Refresh()
|
||||
{
|
||||
caca_refresh_display(_c_dp);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_display_time(IntPtr dp, int d);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_display_time(IntPtr dp);
|
||||
public int DisplayTime
|
||||
{
|
||||
get { return caca_get_display_time(_c_dp); }
|
||||
set { caca_set_display_time(_c_dp, value); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event(IntPtr dp, uint t,
|
||||
IntPtr cevent,
|
||||
int timeout);
|
||||
public Event getEvent(EventType t, int timeout)
|
||||
{
|
||||
Event e = new Event();
|
||||
caca_get_event(_c_dp, (uint)t, e.cevent, timeout);
|
||||
return e;
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_display_width(IntPtr dp);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_display_height(IntPtr dp);
|
||||
public Size Size
|
||||
{
|
||||
get { return new Size(caca_get_display_width(_c_dp),
|
||||
caca_get_display_height(_c_dp)); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_display_title(IntPtr dp, string t);
|
||||
public string Title
|
||||
{
|
||||
set { caca_set_display_title(_c_dp, value); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_mouse(IntPtr k, bool status);
|
||||
public bool Mouse
|
||||
{
|
||||
set { caca_set_mouse(_c_dp, value); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_mouse_x(IntPtr k);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_mouse_y(IntPtr k);
|
||||
public Point MousePos
|
||||
{
|
||||
get { return new Point(caca_get_mouse_x(_c_dp),
|
||||
caca_get_mouse_y(_c_dp)); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_cursor(IntPtr k, bool status);
|
||||
public bool Cursor
|
||||
{
|
||||
set { caca_set_cursor(_c_dp, value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
public class Dither : IDisposable
|
||||
{
|
||||
public readonly IntPtr _dither;
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_create_dither(int bpp, int w,
|
||||
int h, int pitch,
|
||||
uint rmask,
|
||||
uint gmask,
|
||||
uint bmask,
|
||||
uint amask);
|
||||
public Dither(int bpp, Size s, int pitch,
|
||||
uint rmask, uint gmask, uint bmask, uint amask)
|
||||
{
|
||||
_dither = caca_create_dither(bpp, s.Width, s.Height, pitch,
|
||||
rmask, gmask, bmask, amask);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_free_dither(IntPtr d);
|
||||
public void Dispose()
|
||||
{
|
||||
caca_free_dither(_dither);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/* TODO: fix this shit */
|
||||
|
||||
#if false
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_palette(IntPtr d,
|
||||
uint[] r, uint[] g,
|
||||
uint[] b, uint[] a);
|
||||
#endif
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_brightness(IntPtr d, float b);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_gamma(IntPtr d, float g);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_contrast(IntPtr d, float c);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_invert(IntPtr d, int i);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_antialias(IntPtr d, string s);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern string[] caca_get_dither_antialias_list(IntPtr d);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_color(IntPtr d, string s);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern string[] caca_get_dither_color_list(IntPtr d);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_charset(IntPtr d, string s);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern string[] caca_get_dither_charset_list(IntPtr d);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_set_dither_mode(IntPtr d, string s);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern string[] caca_get_dither_mode_list(IntPtr d);
|
||||
|
||||
|
||||
public int setBrightness(float b)
|
||||
{
|
||||
return caca_set_dither_brightness(_dither, b);
|
||||
}
|
||||
|
||||
public int setGamma(float g)
|
||||
{
|
||||
return caca_set_dither_gamma(_dither, g);
|
||||
}
|
||||
|
||||
public int setContrast(float c)
|
||||
{
|
||||
return caca_set_dither_contrast(_dither, c);
|
||||
}
|
||||
|
||||
public int setInvert(int i)
|
||||
{
|
||||
return caca_set_dither_invert(_dither, i);
|
||||
}
|
||||
|
||||
public int setAntialias(string s)
|
||||
{
|
||||
return caca_set_dither_antialias(_dither, s);
|
||||
}
|
||||
|
||||
public int setColor(string s)
|
||||
{
|
||||
return caca_set_dither_color(_dither, s);
|
||||
}
|
||||
|
||||
public int setCharset(string s)
|
||||
{
|
||||
return caca_set_dither_charset(_dither, s);
|
||||
}
|
||||
|
||||
public int setMode(string s)
|
||||
{
|
||||
return caca_set_dither_mode(_dither, s);
|
||||
}
|
||||
|
||||
/* <FIXME> */
|
||||
public string[] getAntialiasList()
|
||||
{
|
||||
return caca_get_dither_antialias_list(_dither);
|
||||
}
|
||||
|
||||
public string[] getColorList()
|
||||
{
|
||||
return caca_get_dither_color_list(_dither);
|
||||
}
|
||||
|
||||
public string[] getCharsetList()
|
||||
{
|
||||
return caca_get_dither_charset_list(_dither);
|
||||
}
|
||||
|
||||
public string[] getModeList()
|
||||
{
|
||||
return caca_get_dither_mode_list(_dither);
|
||||
}
|
||||
|
||||
/* </FIXME> */
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
public enum EventType
|
||||
{
|
||||
NONE = 0x0000,
|
||||
|
||||
KEY_PRESS = 0x0001,
|
||||
KEY_RELEASE = 0x0002,
|
||||
MOUSE_PRESS = 0x0004,
|
||||
MOUSE_RELEASE = 0x0008,
|
||||
MOUSE_MOTION = 0x0010,
|
||||
RESIZE = 0x0020,
|
||||
QUIT = 0x0040,
|
||||
|
||||
ANY = 0xffff,
|
||||
}
|
||||
|
||||
public enum EventKey
|
||||
{
|
||||
UNKNOWN = 0x00,
|
||||
|
||||
CTRL_A = 0x01,
|
||||
CTRL_B = 0x02,
|
||||
CTRL_C = 0x03,
|
||||
CTRL_D = 0x04,
|
||||
CTRL_E = 0x05,
|
||||
CTRL_F = 0x06,
|
||||
CTRL_G = 0x07,
|
||||
BACKSPACE = 0x08,
|
||||
TAB = 0x09,
|
||||
CTRL_J = 0x0a,
|
||||
CTRL_K = 0x0b,
|
||||
CTRL_L = 0x0c,
|
||||
RETURN = 0x0d,
|
||||
CTRL_N = 0x0e,
|
||||
CTRL_O = 0x0f,
|
||||
CTRL_P = 0x10,
|
||||
CTRL_Q = 0x11,
|
||||
CTRL_R = 0x12,
|
||||
PAUSE = 0x13,
|
||||
CTRL_T = 0x14,
|
||||
CTRL_U = 0x15,
|
||||
CTRL_V = 0x16,
|
||||
CTRL_W = 0x17,
|
||||
CTRL_X = 0x18,
|
||||
CTRL_Y = 0x19,
|
||||
CTRL_Z = 0x1a,
|
||||
ESCAPE = 0x1b,
|
||||
DELETE = 0x7f,
|
||||
|
||||
UP = 0x111,
|
||||
DOWN = 0x112,
|
||||
LEFT = 0x113,
|
||||
RIGHT = 0x114,
|
||||
|
||||
INSERT = 0x115,
|
||||
HOME = 0x116,
|
||||
END = 0x117,
|
||||
PAGEUP = 0x118,
|
||||
PAGEDOWN = 0x119,
|
||||
|
||||
F1 = 0x11a,
|
||||
F2 = 0x11b,
|
||||
F3 = 0x11c,
|
||||
F4 = 0x11d,
|
||||
F5 = 0x11e,
|
||||
F6 = 0x11f,
|
||||
F7 = 0x120,
|
||||
F8 = 0x121,
|
||||
F9 = 0x122,
|
||||
F10 = 0x123,
|
||||
F11 = 0x124,
|
||||
F12 = 0x125,
|
||||
F13 = 0x126,
|
||||
F14 = 0x127,
|
||||
F15 = 0x128,
|
||||
}
|
||||
|
||||
public class Event : IDisposable
|
||||
{
|
||||
public IntPtr cevent;
|
||||
private IntPtr _utf8;
|
||||
|
||||
public Event()
|
||||
{
|
||||
cevent = Marshal.AllocHGlobal(32);
|
||||
_utf8 = Marshal.AllocHGlobal(8);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Marshal.FreeHGlobal(cevent);
|
||||
Marshal.FreeHGlobal(_utf8);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_type(IntPtr ev);
|
||||
public EventType Type
|
||||
{
|
||||
get { return (EventType)caca_get_event_type(cevent); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_key_ch(IntPtr ev);
|
||||
public int KeyCh
|
||||
{
|
||||
get { return caca_get_event_key_ch(cevent); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern uint caca_get_event_key_utf32(IntPtr ev);
|
||||
public uint KeyUtf32
|
||||
{
|
||||
get { return caca_get_event_key_utf32(cevent); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_key_utf8(IntPtr ev,
|
||||
IntPtr _utf8);
|
||||
public string KeyUtf8
|
||||
{
|
||||
get
|
||||
{
|
||||
caca_get_event_key_utf8(cevent, _utf8);
|
||||
return Marshal.PtrToStringAnsi(_utf8);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_mouse_button(IntPtr ev);
|
||||
public int MouseButton
|
||||
{
|
||||
get { return caca_get_event_mouse_button(cevent); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_mouse_x(IntPtr ev);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_mouse_y(IntPtr ev);
|
||||
public Point MousePos
|
||||
{
|
||||
get { return new Point(caca_get_event_mouse_x(cevent),
|
||||
caca_get_event_mouse_y(cevent)); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_resize_width(IntPtr ev);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_event_resize_height(IntPtr ev);
|
||||
public Size ResizeSize
|
||||
{
|
||||
get { return new Size(caca_get_event_resize_width(cevent),
|
||||
caca_get_event_resize_height(cevent)); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* libcaca .NET bindings for libcaca
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Caca
|
||||
{
|
||||
public class Font : IDisposable
|
||||
{
|
||||
private IntPtr _font;
|
||||
private GCHandle _gch;
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_load_font(IntPtr data, uint len);
|
||||
public Font(string s)
|
||||
{
|
||||
IntPtr name = Marshal.StringToHGlobalAnsi(s);
|
||||
_font = caca_load_font(name, 0);
|
||||
Marshal.FreeHGlobal(name);
|
||||
}
|
||||
|
||||
public Font(byte[] buf)
|
||||
{
|
||||
GCHandle _gch = GCHandle.Alloc(buf, GCHandleType.Pinned);
|
||||
_font = caca_load_font(_gch.AddrOfPinnedObject(),
|
||||
(uint)buf.Length);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_free_font(IntPtr d);
|
||||
public void Dispose()
|
||||
{
|
||||
caca_free_font(_font);
|
||||
_gch.Free();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_get_font_list();
|
||||
public static string[] getList()
|
||||
{
|
||||
IntPtr l = caca_get_font_list();
|
||||
|
||||
int size;
|
||||
for(size = 0; true; size++)
|
||||
if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero)
|
||||
break;
|
||||
|
||||
string[] ret = new string[size];
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
IntPtr s = Marshal.ReadIntPtr(l, IntPtr.Size * i);
|
||||
ret[i] = Marshal.PtrToStringAnsi(s);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_font_width(IntPtr font);
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_get_font_height(IntPtr font);
|
||||
public Size Size
|
||||
{
|
||||
get { return new Size(caca_get_font_width(_font),
|
||||
caca_get_font_height(_font)); }
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern IntPtr caca_get_font_blocks(IntPtr font);
|
||||
public int[,] getBlocks()
|
||||
{
|
||||
IntPtr l = caca_get_font_blocks(_font);
|
||||
|
||||
int size;
|
||||
for(size = 1; true; size += 2)
|
||||
if(Marshal.ReadIntPtr(l, IntPtr.Size * size) == IntPtr.Zero)
|
||||
break;
|
||||
|
||||
int[,] ret = new int[size,2];
|
||||
for(int i = 0; i < size; i++)
|
||||
{
|
||||
ret[i,0] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2);
|
||||
ret[i,1] = (int)Marshal.ReadIntPtr(l, IntPtr.Size * i * 2 + 1);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
[DllImport("libcaca.dll", CallingConvention=CallingConvention.Cdecl),
|
||||
SuppressUnmanagedCodeSecurity]
|
||||
private static extern int caca_render_canvas(IntPtr cv, IntPtr f,
|
||||
IntPtr buf, int w, int h,
|
||||
int pitch);
|
||||
public int Render(Canvas cv, uint[,] buf, int pitch)
|
||||
{
|
||||
GCHandle gch = GCHandle.Alloc(buf, GCHandleType.Pinned);
|
||||
int ret = caca_render_canvas(cv._c_cv, _font,
|
||||
gch.AddrOfPinnedObject(),
|
||||
buf.GetLength(0), buf.GetLength(1),
|
||||
pitch);
|
||||
gch.Free();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
|
||||
include $(top_srcdir)/build/autotools/common.am
|
||||
|
||||
# We need to install the .config file ourselves because of a gacutil
|
||||
# bug (https://bugzilla.novell.com/show_bug.cgi?id=363341)
|
||||
monodir = $(libdir)/mono/caca-sharp-0.0
|
||||
if USE_CSHARP
|
||||
noinst_DATA = caca-sharp.dll caca-sharp.dll.config test.exe
|
||||
endif
|
||||
|
||||
caca_sources = \
|
||||
$(srcdir)/AssemblyInfo.cs \
|
||||
$(srcdir)/Caca.cs \
|
||||
$(srcdir)/Attr.cs \
|
||||
$(srcdir)/Canvas.cs \
|
||||
$(srcdir)/Display.cs \
|
||||
$(srcdir)/Dither.cs \
|
||||
$(srcdir)/Event.cs \
|
||||
$(srcdir)/Font.cs
|
||||
|
||||
test_sources = \
|
||||
$(srcdir)/test.cs
|
||||
|
||||
EXTRA_DIST = $(caca_sources) $(test_sources) \
|
||||
caca-sharp.snk caca-sharp.pc.in caca-sharp.dll.config.in \
|
||||
caca-sharp.csproj test-csharp.csproj
|
||||
|
||||
caca-sharp.dll: $(caca_sources)
|
||||
$(CSC) -debug -unsafe $(caca_sources) -out:$@ -target:library \
|
||||
-keyfile:$(srcdir)/caca-sharp.snk -r:System.Drawing.dll
|
||||
|
||||
test.exe: $(test_sources) caca-sharp.dll
|
||||
$(CSC) -debug $(test_sources) -out:$@ -lib:./ \
|
||||
-r:System.Drawing.dll -r:./caca-sharp.dll
|
||||
|
||||
if USE_CSHARP
|
||||
install-data-local:
|
||||
MONO_SHARED_DIR=$$HOME $(GACUTIL) -i caca-sharp.dll \
|
||||
-package caca-sharp-0.0 -f -root $(DESTDIR)$(libdir)
|
||||
$(mkinstalldirs) $(DESTDIR)$(monodir)
|
||||
sed -e 's@target="[^"]*/@target="@' < caca-sharp.dll.config > $(DESTDIR)$(monodir)/caca-sharp.dll.config
|
||||
|
||||
uninstall-local:
|
||||
MONO_SHARED_DIR=$$HOME $(GACUTIL) -u caca-sharp.dll, Version=0.0 \
|
||||
-package caca-sharp-0.0 || true
|
||||
rm -f $(DESTDIR)$(monodir)/caca-sharp.dll.config
|
||||
rmdir $(DESTDIR)$(monodir) 2>/dev/null || true
|
||||
endif
|
||||
|
||||
clean-local:
|
||||
rm -f *.exe *.dll *.mdb
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{046BD004-7B02-4521-BF01-9D9042F19AD5}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>caca_sharp</RootNamespace>
|
||||
<AssemblyName>caca-sharp</AssemblyName>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<OutputPath>$(SolutionDir)\win32\$(Configuration)\$(Platform)\</OutputPath>
|
||||
<BaseOutputPath>$(SolutionDir)\win32\$(Configuration)\$(Platform)\obj-$(AssemblyName)\</BaseOutputPath>
|
||||
<IntermediateOutputPath>$(SolutionDir)\win32\$(Configuration)\$(Platform)\obj-$(AssemblyName)\</IntermediateOutputPath>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Caca.cs" />
|
||||
<Compile Include="Canvas.cs" />
|
||||
<Compile Include="Attr.cs" />
|
||||
<Compile Include="Font.cs" />
|
||||
<Compile Include="Dither.cs" />
|
||||
<Compile Include="Display.cs" />
|
||||
<Compile Include="Event.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>rd /Q /S $(ProjectDir)\obj</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
<configuration>
|
||||
<dllmap dll="libcaca.dll" target="libcaca@LT_SUFFIX@" />
|
||||
</configuration>
|
|
@ -0,0 +1,6 @@
|
|||
Name: caca-sharp
|
||||
Description: caca-sharp
|
||||
Version: @PACKAGE_VERSION@
|
||||
|
||||
Requires:
|
||||
Libs: -r:@expanded_libdir@/@PACKAGE@/caca-sharp.dll
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,123 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6EB34142-45E0-4BF3-8F75-81F4F604EAAA}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>test_csharp</RootNamespace>
|
||||
<AssemblyName>test-csharp</AssemblyName>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<OutputPath>$(SolutionDir)\win32\$(Configuration)\$(Platform)\</OutputPath>
|
||||
<BaseOutputPath>$(SolutionDir)\win32\$(Configuration)\$(Platform)\obj-$(AssemblyName)\</BaseOutputPath>
|
||||
<IntermediateOutputPath>$(SolutionDir)\win32\$(Configuration)\$(Platform)\obj-$(AssemblyName)\</IntermediateOutputPath>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>rd /Q /S $(ProjectDir)\obj</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="test.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="caca-sharp.csproj">
|
||||
<Project>{046BD004-7B02-4521-BF01-9D9042F19AD5}</Project>
|
||||
<Name>caca-sharp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Drawing" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Test .NET bindings test program
|
||||
* Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* 2007 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Caca;
|
||||
|
||||
class DemoCanvas : Canvas
|
||||
{
|
||||
private uint[,] image;
|
||||
|
||||
private DateTime startTime;
|
||||
private Dither d;
|
||||
private Canvas scroll;
|
||||
|
||||
public DemoCanvas()
|
||||
{
|
||||
startTime = DateTime.Now;
|
||||
|
||||
string message = " --- POWERED BY LIBCACA --- OLDSCHOOL TEXT EFFECTS ARE 100% PURE WIN";
|
||||
|
||||
scroll = new Canvas(new Size(message.Length, 1));
|
||||
scroll.setColorAnsi(AnsiColor.WHITE, AnsiColor.TRANSPARENT);
|
||||
scroll.putStr(new Point(0, 0), message);
|
||||
|
||||
Caca.Font f = new Caca.Font(Caca.Font.getList()[1]);
|
||||
int w = f.Size.Width * message.Length;
|
||||
int h = f.Size.Height;
|
||||
image = new uint[w, h];
|
||||
d = new Dither(32, new Size(w, h), w * 4,
|
||||
0xff00, 0xff0000, 0xff000000, 0xff);
|
||||
f.Render(scroll, image, image.GetLength(0) * 4);
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
int barCount = 6;
|
||||
double t = (DateTime.Now - startTime).TotalMilliseconds;
|
||||
|
||||
Clear();
|
||||
|
||||
setColorAnsi(AnsiColor.WHITE, AnsiColor.BLACK);
|
||||
for(int i = 0; i < barCount; i++)
|
||||
{
|
||||
double v = ((Math.Sin((t / 500.0)
|
||||
+ (i / ((double)barCount))) + 1) / 2) * Size.Height;
|
||||
Point p1 = new Point(0, (int)v);
|
||||
Point p2 = new Point(Size.Width - 1, (int)v);
|
||||
|
||||
setColorAnsi((uint)(i + 9), AnsiColor.BLACK);
|
||||
/* drawLine is already clipped, we don't care about overflows */
|
||||
drawLine(p1 + new Size(0, -2), p2 + new Size(0, -2), '-');
|
||||
drawLine(p1 + new Size(0, -1), p2 + new Size(0, -1), '*');
|
||||
drawLine(p1, p2, '#');
|
||||
drawLine(p1 + new Size(0, 1), p2 + new Size(0, 1), '*');
|
||||
drawLine(p1 + new Size(0, 2), p2 + new Size(0, 2), '-');
|
||||
}
|
||||
|
||||
int w = Size.Width;
|
||||
int h = Size.Height;
|
||||
int x = (int)(t / 10) % (12 * w);
|
||||
int y = (int)(h * (2.0 + Math.Sin(t / 200.0)) / 4);
|
||||
ditherBitmap(new Rectangle(- x, h / 2 - y, w * 12, y * 2), d, image);
|
||||
ditherBitmap(new Rectangle(12 * w - x, h / 2 - y, w * 12, y * 2), d, image);
|
||||
|
||||
setColorAnsi(AnsiColor.WHITE, AnsiColor.BLUE);
|
||||
putStr(new Point(-30, -2) + Size, " -=[ Powered by libcaca ]=- ");
|
||||
setColorAnsi(AnsiColor.WHITE, AnsiColor.BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
class DemoDisplay : Display
|
||||
{
|
||||
private DemoCanvas cv;
|
||||
|
||||
public DemoDisplay(DemoCanvas _cv) : base(_cv)
|
||||
{
|
||||
Title = "libcaca .NET Bindings test suite";
|
||||
DisplayTime = 20000; // Refresh every 20 ms
|
||||
cv = _cv;
|
||||
}
|
||||
|
||||
public void EventLoop()
|
||||
{
|
||||
Event ev;
|
||||
|
||||
while((ev = getEvent(EventType.KEY_RELEASE, 10)).Type == 0)
|
||||
{
|
||||
cv.Draw();
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
if(ev.KeyCh > 0x20 && ev.KeyCh < 0x7f)
|
||||
Console.WriteLine("Key pressed: {0}", ev.KeyUtf8);
|
||||
else
|
||||
Console.WriteLine("Key pressed: 0x{0:x}", ev.KeyCh);
|
||||
}
|
||||
}
|
||||
|
||||
class Test
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
Console.WriteLine("libcaca {0} .NET test", Libcaca.getVersion());
|
||||
Console.WriteLine("(c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>");
|
||||
|
||||
/* Instanciate a caca canvas */
|
||||
DemoCanvas cv = new DemoCanvas();
|
||||
|
||||
/* We have a proper canvas, let's display it using Caca */
|
||||
DemoDisplay dp = new DemoDisplay(cv);
|
||||
|
||||
/* Random number. This is a static method,
|
||||
not to be used with previous instance */
|
||||
Console.WriteLine("A random number: {0}", Libcaca.Rand(0, 1337));
|
||||
|
||||
dp.EventLoop();
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
|
@ -0,0 +1,107 @@
|
|||
|
||||
include $(top_srcdir)/build/autotools/common.am
|
||||
|
||||
SUBDIRS = . t
|
||||
|
||||
EXTRA_DIST = caca.pc.in \
|
||||
mono9.data monobold12.data \
|
||||
libcaca.vcxproj libcaca.def
|
||||
DISTCLEANFILES = caca.pc
|
||||
|
||||
AM_CPPFLAGS += -DPLUGINDIR=\"$(plugindir)\"
|
||||
|
||||
pkgconfig_DATA = caca.pc
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
|
||||
include_HEADERS = caca.h caca_types.h caca_conio.h caca0.h
|
||||
|
||||
lib_LTLIBRARIES = libcaca.la
|
||||
|
||||
libcaca_la_SOURCES = \
|
||||
caca.c \
|
||||
caca.h \
|
||||
caca_types.h \
|
||||
caca_internals.h \
|
||||
caca_debug.h \
|
||||
caca_prof.h \
|
||||
caca_stubs.h \
|
||||
caca_conio.c \
|
||||
caca_conio.h \
|
||||
caca0.c \
|
||||
caca0.h \
|
||||
canvas.c \
|
||||
dirty.c \
|
||||
string.c \
|
||||
transform.c \
|
||||
charset.c \
|
||||
attr.c \
|
||||
line.c \
|
||||
box.c \
|
||||
conic.c \
|
||||
triangle.c \
|
||||
frame.c \
|
||||
dither.c \
|
||||
font.c \
|
||||
file.c \
|
||||
figfont.c \
|
||||
graphics.c \
|
||||
event.c \
|
||||
time.c \
|
||||
prof.c \
|
||||
getopt.c \
|
||||
$(codec_source) \
|
||||
$(driver_source) \
|
||||
$(NULL)
|
||||
libcaca_la_DEPENDENCIES = \
|
||||
mono9.data \
|
||||
monobold12.data \
|
||||
$(NULL)
|
||||
libcaca_la_CPPFLAGS = $(AM_CPPFLAGS) @CACA_CFLAGS@ -D__LIBCACA__
|
||||
libcaca_la_LDFLAGS = -no-undefined -version-number @LT_VERSION@
|
||||
libcaca_la_LIBADD = @CACA_LIBS@ $(ZLIB_LIBS) $(GETOPT_LIBS)
|
||||
|
||||
codec_source = \
|
||||
codec/import.c \
|
||||
codec/export.c \
|
||||
codec/codec.h \
|
||||
codec/text.c \
|
||||
$(NULL)
|
||||
|
||||
driver_source = \
|
||||
driver/conio.c \
|
||||
driver/ncurses.c \
|
||||
driver/null.c \
|
||||
driver/raw.c \
|
||||
driver/slang.c \
|
||||
driver/vga.c \
|
||||
driver/win32.c \
|
||||
$(NULL)
|
||||
|
||||
uninstall-local:
|
||||
. ./libcaca.la || exit 1; \
|
||||
rmdir $(DESTDIR)$(libdir) 2>/dev/null || true
|
||||
rmdir $(DESTDIR)$(pkgconfigdir) 2>/dev/null || true
|
||||
|
||||
if USE_PLUGINS
|
||||
plugin_LTLIBRARIES = libx11_plugin.la libgl_plugin.la
|
||||
plugindir = $(libdir)/caca
|
||||
|
||||
libx11_plugin_la_SOURCES = driver/x11.c
|
||||
libx11_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(X11_CFLAGS)
|
||||
libx11_plugin_la_LDFLAGS = -no-undefined -module -no-version
|
||||
libx11_plugin_la_LIBADD = libcaca.la $(X11_LIBS)
|
||||
|
||||
libgl_plugin_la_SOURCES = driver/gl.c
|
||||
libgl_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(GL_CFLAGS) #$(FTGL_CFLAGS)
|
||||
libgl_plugin_la_LDFLAGS = -no-undefined -module -no-version
|
||||
libgl_plugin_la_LIBADD = libcaca.la $(GL_LIBS) #$(FTGL_LIBS)
|
||||
else
|
||||
driver_source += driver/x11.c driver/gl.c
|
||||
endif
|
||||
|
||||
if USE_COCOA
|
||||
driver_source += driver/cocoa.m
|
||||
else
|
||||
EXTRA_CHECKS = driver/cocoa.m
|
||||
endif
|
||||
|
|
@ -0,0 +1,527 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2018 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains functions for attribute management and colourspace
|
||||
* conversions.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
|
||||
static uint8_t nearest_ansi(uint16_t);
|
||||
|
||||
/* RGB colours for the ANSI palette. There is no real standard, so we
|
||||
* use the same values as gnome-terminal. The 7th colour (brown) is a bit
|
||||
* special: 0xfa50 instead of 0xfaa0. */
|
||||
static const uint16_t ansitab16[16] =
|
||||
{
|
||||
0xf000, 0xf00a, 0xf0a0, 0xf0aa, 0xfa00, 0xfa0a, 0xfa50, 0xfaaa,
|
||||
0xf555, 0xf55f, 0xf5f5, 0xf5ff, 0xff55, 0xff5f, 0xfff5, 0xffff,
|
||||
};
|
||||
|
||||
/* Same table, except on 14 bits (3-4-4-3) */
|
||||
static const uint16_t ansitab14[16] =
|
||||
{
|
||||
0x3800, 0x3805, 0x3850, 0x3855, 0x3d00, 0x3d05, 0x3d28, 0x3d55,
|
||||
0x3aaa, 0x3aaf, 0x3afa, 0x3aff, 0x3faa, 0x3faf, 0x3ffa, 0x3fff,
|
||||
};
|
||||
|
||||
/** \brief Get the text attribute at the given coordinates.
|
||||
*
|
||||
* Get the internal \e libcaca attribute value of the character at the
|
||||
* given coordinates. The attribute value has 32 significant bits,
|
||||
* organised as follows from MSB to LSB:
|
||||
* - 3 bits for the background alpha
|
||||
* - 4 bits for the background red component
|
||||
* - 4 bits for the background green component
|
||||
* - 3 bits for the background blue component
|
||||
* - 3 bits for the foreground alpha
|
||||
* - 4 bits for the foreground red component
|
||||
* - 4 bits for the foreground green component
|
||||
* - 3 bits for the foreground blue component
|
||||
* - 4 bits for the bold, italics, underline and blink flags
|
||||
*
|
||||
* If the coordinates are outside the canvas boundaries, the current
|
||||
* attribute is returned.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param x X coordinate.
|
||||
* \param y Y coordinate.
|
||||
* \return The requested attribute.
|
||||
*/
|
||||
uint32_t caca_get_attr(caca_canvas_t const *cv, int x, int y)
|
||||
{
|
||||
if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height)
|
||||
return cv->curattr;
|
||||
|
||||
return cv->attrs[x + y * cv->width];
|
||||
}
|
||||
|
||||
/** \brief Set the default character attribute.
|
||||
*
|
||||
* Set the default character attribute for drawing. Attributes define
|
||||
* foreground and background colour, transparency, bold, italics and
|
||||
* underline styles, as well as blink. String functions such as
|
||||
* caca_printf() and graphical primitive functions such as caca_draw_line()
|
||||
* will use this attribute.
|
||||
*
|
||||
* The value of \e attr is either:
|
||||
* - a 32-bit integer as returned by caca_get_attr(), in which case it
|
||||
* also contains colour information,
|
||||
* - a combination (bitwise OR) of style values (\e CACA_UNDERLINE,
|
||||
* \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS), in which case
|
||||
* setting the attribute does not modify the current colour information.
|
||||
*
|
||||
* To retrieve the current attribute value, use caca_get_attr(-1,-1).
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param attr The requested attribute value.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_set_attr(caca_canvas_t *cv, uint32_t attr)
|
||||
{
|
||||
if(attr < 0x00000010)
|
||||
attr = (cv->curattr & 0xfffffff0) | attr;
|
||||
|
||||
cv->curattr = attr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Unset flags in the default character attribute.
|
||||
*
|
||||
* Unset flags in the default character attribute for drawing. Attributes
|
||||
* define foreground and background colour, transparency, bold, italics and
|
||||
* underline styles, as well as blink. String functions such as
|
||||
* caca_printf() and graphical primitive functions such as caca_draw_line()
|
||||
* will use this attribute.
|
||||
*
|
||||
* The value of \e attr is a combination (bitwise OR) of style values
|
||||
* (\e CACA_UNDERLINE, \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS).
|
||||
* Unsetting these attributes does not modify the current colour information.
|
||||
*
|
||||
* To retrieve the current attribute value, use caca_get_attr(-1,-1).
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param attr The requested attribute values to unset.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_unset_attr(caca_canvas_t *cv, uint32_t attr)
|
||||
{
|
||||
cv->curattr &= ~(attr & 0x0000000f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Toggle flags in the default character attribute.
|
||||
*
|
||||
* Toggle flags in the default character attribute for drawing. Attributes
|
||||
* define foreground and background colour, transparency, bold, italics and
|
||||
* underline styles, as well as blink. String functions such as
|
||||
* caca_printf() and graphical primitive functions such as caca_draw_line()
|
||||
* will use this attribute.
|
||||
*
|
||||
* The value of \e attr is a combination (bitwise OR) of style values
|
||||
* (\e CACA_UNDERLINE, \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS).
|
||||
* Toggling these attributes does not modify the current colour information.
|
||||
*
|
||||
* To retrieve the current attribute value, use caca_get_attr(-1,-1).
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param attr The requested attribute values to toggle.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_toggle_attr(caca_canvas_t *cv, uint32_t attr)
|
||||
{
|
||||
cv->curattr ^= attr & 0x0000000f;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Set the character attribute at the given coordinates.
|
||||
*
|
||||
* Set the character attribute, without changing the character's value. If
|
||||
* the character at the given coordinates is a fullwidth character, both
|
||||
* cells' attributes are replaced.
|
||||
*
|
||||
* The value of \e attr is either:
|
||||
* - a 32-bit integer as returned by caca_get_attr(), in which case it
|
||||
* also contains colour information,
|
||||
* - a combination (bitwise OR) of style values (\e CACA_UNDERLINE,
|
||||
* \e CACA_BLINK, \e CACA_BOLD and \e CACA_ITALICS), in which case
|
||||
* setting the attribute does not modify the current colour information.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param x X coordinate.
|
||||
* \param y Y coordinate.
|
||||
* \param attr The requested attribute value.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_put_attr(caca_canvas_t *cv, int x, int y, uint32_t attr)
|
||||
{
|
||||
uint32_t *curattr, *curchar;
|
||||
int xmin, xmax;
|
||||
|
||||
if(x < 0 || x >= (int)cv->width || y < 0 || y >= (int)cv->height)
|
||||
return 0;
|
||||
|
||||
xmin = xmax = x;
|
||||
|
||||
curchar = cv->chars + x + y * cv->width;
|
||||
curattr = cv->attrs + x + y * cv->width;
|
||||
|
||||
if(attr < 0x00000010)
|
||||
curattr[0] = (curattr[0] & 0xfffffff0) | attr;
|
||||
else
|
||||
curattr[0] = attr;
|
||||
|
||||
if(x && curchar[0] == CACA_MAGIC_FULLWIDTH)
|
||||
{
|
||||
curattr[-1] = curattr[0];
|
||||
xmin--;
|
||||
}
|
||||
else if(x + 1 < (int)cv->width && curchar[1] == CACA_MAGIC_FULLWIDTH)
|
||||
{
|
||||
curattr[1] = curattr[0];
|
||||
xmax++;
|
||||
}
|
||||
|
||||
if(!cv->dirty_disabled)
|
||||
caca_add_dirty_rect(cv, xmin, y, xmax - xmin + 1, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Set the default colour pair for text (ANSI version).
|
||||
*
|
||||
* Set the default ANSI colour pair for text drawing. String functions such
|
||||
* as caca_printf() and graphical primitive functions such as caca_draw_line()
|
||||
* will use these attributes.
|
||||
*
|
||||
* Color values are those defined in caca.h, such as CACA_RED
|
||||
* or CACA_TRANSPARENT.
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c EINVAL At least one of the colour values is invalid.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param fg The requested ANSI foreground colour.
|
||||
* \param bg The requested ANSI background colour.
|
||||
* \return 0 in case of success, -1 if an error occurred.
|
||||
*/
|
||||
int caca_set_color_ansi(caca_canvas_t *cv, uint8_t fg, uint8_t bg)
|
||||
{
|
||||
uint32_t attr;
|
||||
|
||||
if(fg > 0x20 || bg > 0x20)
|
||||
{
|
||||
seterrno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
attr = ((uint32_t)(bg | 0x40) << 18) | ((uint32_t)(fg | 0x40) << 4);
|
||||
cv->curattr = (cv->curattr & 0x0000000f) | attr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Set the default colour pair for text (truecolor version).
|
||||
*
|
||||
* Set the default ARGB colour pair for text drawing. String functions such
|
||||
* as caca_printf() and graphical primitive functions such as caca_draw_line()
|
||||
* will use these attributes.
|
||||
*
|
||||
* Colors are 16-bit ARGB values, each component being coded on 4 bits. For
|
||||
* instance, 0xf088 is solid dark cyan (A=15 R=0 G=8 B=8), and 0x8fff is
|
||||
* white with 50% alpha (A=8 R=15 G=15 B=15).
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A handle to the libcaca canvas.
|
||||
* \param fg The requested ARGB foreground colour.
|
||||
* \param bg The requested ARGB background colour.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_set_color_argb(caca_canvas_t *cv, uint16_t fg, uint16_t bg)
|
||||
{
|
||||
uint32_t attr;
|
||||
|
||||
if(fg < 0x100)
|
||||
fg += 0x100;
|
||||
|
||||
if(bg < 0x100)
|
||||
bg += 0x100;
|
||||
|
||||
fg = ((fg >> 1) & 0x7ff) | ((fg >> 13) << 11);
|
||||
bg = ((bg >> 1) & 0x7ff) | ((bg >> 13) << 11);
|
||||
|
||||
attr = ((uint32_t)bg << 18) | ((uint32_t)fg << 4);
|
||||
cv->curattr = (cv->curattr & 0x0000000f) | attr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Get DOS ANSI information from attribute.
|
||||
*
|
||||
* Get the ANSI colour pair for a given attribute. The returned value is
|
||||
* an 8-bit value whose higher 4 bits are the background colour and lower
|
||||
* 4 bits are the foreground colour.
|
||||
*
|
||||
* If the attribute has ARGB colours, the nearest colour is used. Special
|
||||
* attributes such as \e CACA_DEFAULT and \e CACA_TRANSPARENT are not
|
||||
* handled and are both replaced with \e CACA_LIGHTGRAY for the foreground
|
||||
* colour and \e CACA_BLACK for the background colour.
|
||||
*
|
||||
* This function never fails. If the attribute value is outside the expected
|
||||
* 32-bit range, higher order bits are simply ignored.
|
||||
*
|
||||
* \param attr The requested attribute value.
|
||||
* \return The corresponding DOS ANSI value.
|
||||
*/
|
||||
uint8_t caca_attr_to_ansi(uint32_t attr)
|
||||
{
|
||||
uint8_t fg = nearest_ansi((attr >> 4) & 0x3fff);
|
||||
uint8_t bg = nearest_ansi(attr >> 18);
|
||||
|
||||
return (fg < 0x10 ? fg : CACA_LIGHTGRAY)
|
||||
| ((bg < 0x10 ? bg : CACA_BLACK) << 4);
|
||||
}
|
||||
|
||||
/** \brief Get ANSI foreground information from attribute.
|
||||
*
|
||||
* Get the ANSI foreground colour value for a given attribute. The returned
|
||||
* value is either one of the \e CACA_RED, \e CACA_BLACK etc. predefined
|
||||
* colours, or the special value \e CACA_DEFAULT meaning the media's
|
||||
* default foreground value, or the special value \e CACA_TRANSPARENT.
|
||||
*
|
||||
* If the attribute has ARGB colours, the nearest colour is returned.
|
||||
*
|
||||
* This function never fails. If the attribute value is outside the expected
|
||||
* 32-bit range, higher order bits are simply ignored.
|
||||
*
|
||||
* \param attr The requested attribute value.
|
||||
* \return The corresponding ANSI foreground value.
|
||||
*/
|
||||
uint8_t caca_attr_to_ansi_fg(uint32_t attr)
|
||||
{
|
||||
return nearest_ansi((attr >> 4) & 0x3fff);
|
||||
}
|
||||
|
||||
/** \brief Get ANSI background information from attribute.
|
||||
*
|
||||
* Get the ANSI background colour value for a given attribute. The returned
|
||||
* value is either one of the \e CACA_RED, \e CACA_BLACK etc. predefined
|
||||
* colours, or the special value \e CACA_DEFAULT meaning the media's
|
||||
* default background value, or the special value \e CACA_TRANSPARENT.
|
||||
*
|
||||
* If the attribute has ARGB colours, the nearest colour is returned.
|
||||
*
|
||||
* This function never fails. If the attribute value is outside the expected
|
||||
* 32-bit range, higher order bits are simply ignored.
|
||||
*
|
||||
* \param attr The requested attribute value.
|
||||
* \return The corresponding ANSI background value.
|
||||
*/
|
||||
uint8_t caca_attr_to_ansi_bg(uint32_t attr)
|
||||
{
|
||||
return nearest_ansi(attr >> 18);
|
||||
}
|
||||
|
||||
/** \brief Get 12-bit RGB foreground information from attribute.
|
||||
*
|
||||
* Get the 12-bit foreground colour value for a given attribute. The returned
|
||||
* value is a native-endian encoded integer with each red, green and blue
|
||||
* values encoded on 8 bits in the following order:
|
||||
* - 8-11 most significant bits: red
|
||||
* - 4-7 most significant bits: green
|
||||
* - least significant bits: blue
|
||||
*
|
||||
* This function never fails. If the attribute value is outside the expected
|
||||
* 32-bit range, higher order bits are simply ignored.
|
||||
*
|
||||
* \param attr The requested attribute value.
|
||||
* \return The corresponding 12-bit RGB foreground value.
|
||||
*/
|
||||
uint16_t caca_attr_to_rgb12_fg(uint32_t attr)
|
||||
{
|
||||
uint16_t fg = (attr >> 4) & 0x3fff;
|
||||
|
||||
if(fg < (0x10 | 0x40))
|
||||
return ansitab16[fg ^ 0x40] & 0x0fff;
|
||||
|
||||
if(fg == (CACA_DEFAULT | 0x40))
|
||||
return ansitab16[CACA_LIGHTGRAY] & 0x0fff;
|
||||
|
||||
if(fg == (CACA_TRANSPARENT | 0x40))
|
||||
return ansitab16[CACA_LIGHTGRAY] & 0x0fff;
|
||||
|
||||
return (fg << 1) & 0x0fff;
|
||||
}
|
||||
|
||||
/** \brief Get 12-bit RGB background information from attribute.
|
||||
*
|
||||
* Get the 12-bit background colour value for a given attribute. The returned
|
||||
* value is a native-endian encoded integer with each red, green and blue
|
||||
* values encoded on 8 bits in the following order:
|
||||
* - 8-11 most significant bits: red
|
||||
* - 4-7 most significant bits: green
|
||||
* - least significant bits: blue
|
||||
*
|
||||
* This function never fails. If the attribute value is outside the expected
|
||||
* 32-bit range, higher order bits are simply ignored.
|
||||
*
|
||||
* \param attr The requested attribute value.
|
||||
* \return The corresponding 12-bit RGB background value.
|
||||
*/
|
||||
uint16_t caca_attr_to_rgb12_bg(uint32_t attr)
|
||||
{
|
||||
uint16_t bg = attr >> 18;
|
||||
|
||||
if(bg < (0x10 | 0x40))
|
||||
return ansitab16[bg ^ 0x40] & 0x0fff;
|
||||
|
||||
if(bg == (CACA_DEFAULT | 0x40))
|
||||
return ansitab16[CACA_BLACK] & 0x0fff;
|
||||
|
||||
if(bg == (CACA_TRANSPARENT | 0x40))
|
||||
return ansitab16[CACA_BLACK] & 0x0fff;
|
||||
|
||||
return (bg << 1) & 0x0fff;
|
||||
}
|
||||
|
||||
/** \brief Get 64-bit ARGB information from attribute.
|
||||
*
|
||||
* Get the 64-bit colour and alpha values for a given attribute. The values
|
||||
* are written as 8-bit integers in the \e argb array in the following order:
|
||||
* - \e argb[0]: background alpha value
|
||||
* - \e argb[1]: background red value
|
||||
* - \e argb[2]: background green value
|
||||
* - \e argb[3]: background blue value
|
||||
* - \e argb[4]: foreground alpha value
|
||||
* - \e argb[5]: foreground red value
|
||||
* - \e argb[6]: foreground green value
|
||||
* - \e argb[7]: foreground blue value
|
||||
*
|
||||
* This function never fails. If the attribute value is outside the expected
|
||||
* 32-bit range, higher order bits are simply ignored.
|
||||
*
|
||||
* \param attr The requested attribute value.
|
||||
* \param argb An array of 8-bit integers.
|
||||
*/
|
||||
void caca_attr_to_argb64(uint32_t attr, uint8_t argb[8])
|
||||
{
|
||||
uint16_t fg = (attr >> 4) & 0x3fff;
|
||||
uint16_t bg = attr >> 18;
|
||||
|
||||
if(bg < (0x10 | 0x40))
|
||||
bg = ansitab16[bg ^ 0x40];
|
||||
else if(bg == (CACA_DEFAULT | 0x40))
|
||||
bg = ansitab16[CACA_BLACK];
|
||||
else if(bg == (CACA_TRANSPARENT | 0x40))
|
||||
bg = 0x0fff;
|
||||
else
|
||||
bg = ((bg << 2) & 0xf000) | ((bg << 1) & 0x0fff);
|
||||
|
||||
argb[0] = bg >> 12;
|
||||
argb[1] = (bg >> 8) & 0xf;
|
||||
argb[2] = (bg >> 4) & 0xf;
|
||||
argb[3] = bg & 0xf;
|
||||
|
||||
if(fg < (0x10 | 0x40))
|
||||
fg = ansitab16[fg ^ 0x40];
|
||||
else if(fg == (CACA_DEFAULT | 0x40))
|
||||
fg = ansitab16[CACA_LIGHTGRAY];
|
||||
else if(fg == (CACA_TRANSPARENT | 0x40))
|
||||
fg = 0x0fff;
|
||||
else
|
||||
fg = ((fg << 2) & 0xf000) | ((fg << 1) & 0x0fff);
|
||||
|
||||
argb[4] = fg >> 12;
|
||||
argb[5] = (fg >> 8) & 0xf;
|
||||
argb[6] = (fg >> 4) & 0xf;
|
||||
argb[7] = fg & 0xf;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: the following functions are local
|
||||
*/
|
||||
|
||||
static uint8_t nearest_ansi(uint16_t argb14)
|
||||
{
|
||||
unsigned int i, best, dist;
|
||||
|
||||
if(argb14 < (0x10 | 0x40))
|
||||
return argb14 ^ 0x40;
|
||||
|
||||
if(argb14 == (CACA_DEFAULT | 0x40) || argb14 == (CACA_TRANSPARENT | 0x40))
|
||||
return argb14 ^ 0x40;
|
||||
|
||||
if(argb14 < 0x0fff) /* too transparent */
|
||||
return CACA_TRANSPARENT;
|
||||
|
||||
best = CACA_DEFAULT;
|
||||
dist = 0x3fff;
|
||||
for(i = 0; i < 16; i++)
|
||||
{
|
||||
unsigned int d = 0;
|
||||
int a, b;
|
||||
|
||||
a = (ansitab14[i] >> 7) & 0xf;
|
||||
b = (argb14 >> 7) & 0xf;
|
||||
d += (a - b) * (a - b);
|
||||
|
||||
a = (ansitab14[i] >> 3) & 0xf;
|
||||
b = (argb14 >> 3) & 0xf;
|
||||
d += (a - b) * (a - b);
|
||||
|
||||
a = (ansitab14[i] << 1) & 0xf;
|
||||
b = (argb14 << 1) & 0xf;
|
||||
d += (a - b) * (a - b);
|
||||
|
||||
if(d < dist)
|
||||
{
|
||||
dist = d;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
}
|
||||
|
||||
#define RGB12TO24(i) \
|
||||
(((uint32_t)((i & 0xf00) >> 8) * 0x110000) \
|
||||
| ((uint32_t)((i & 0x0f0) >> 4) * 0x001100) \
|
||||
| ((uint32_t)(i & 0x00f) * 0x000011))
|
||||
|
||||
uint32_t _caca_attr_to_rgb24fg(uint32_t attr)
|
||||
{
|
||||
return RGB12TO24(caca_attr_to_rgb12_fg(attr));
|
||||
}
|
||||
|
||||
uint32_t _caca_attr_to_rgb24bg(uint32_t attr)
|
||||
{
|
||||
return RGB12TO24(caca_attr_to_rgb12_bg(attr));
|
||||
}
|
||||
|
|
@ -0,0 +1,216 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2018 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains box drawing functions, both filled and outline.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
|
||||
static int draw_box(caca_canvas_t *cv, int x, int y, int w, int h,
|
||||
uint32_t const *chars);
|
||||
|
||||
/** \brief Draw a box on the canvas using the given character.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv The handle to the libcaca canvas.
|
||||
* \param x X coordinate of the upper-left corner of the box.
|
||||
* \param y Y coordinate of the upper-left corner of the box.
|
||||
* \param w Width of the box.
|
||||
* \param h Height of the box.
|
||||
* \param ch UTF-32 character to be used to draw the box.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_draw_box(caca_canvas_t *cv, int x, int y, int w, int h, uint32_t ch)
|
||||
{
|
||||
int x2 = x + w - 1;
|
||||
int y2 = y + h - 1;
|
||||
|
||||
caca_draw_line(cv, x, y, x, y2, ch);
|
||||
caca_draw_line(cv, x, y2, x2, y2, ch);
|
||||
caca_draw_line(cv, x2, y2, x2, y, ch);
|
||||
caca_draw_line(cv, x2, y, x, y, ch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Draw a thin box on the canvas.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv The handle to the libcaca canvas.
|
||||
* \param x X coordinate of the upper-left corner of the box.
|
||||
* \param y Y coordinate of the upper-left corner of the box.
|
||||
* \param w Width of the box.
|
||||
* \param h Height of the box.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_draw_thin_box(caca_canvas_t *cv, int x, int y, int w, int h)
|
||||
{
|
||||
static uint32_t const ascii_chars[] =
|
||||
{
|
||||
'-', '|', ',', '`', '.', '\''
|
||||
};
|
||||
|
||||
return draw_box(cv, x, y, w, h, ascii_chars);
|
||||
}
|
||||
|
||||
/** \brief Draw a box on the canvas using CP437 characters.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv The handle to the libcaca canvas.
|
||||
* \param x X coordinate of the upper-left corner of the box.
|
||||
* \param y Y coordinate of the upper-left corner of the box.
|
||||
* \param w Width of the box.
|
||||
* \param h Height of the box.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_draw_cp437_box(caca_canvas_t *cv, int x, int y, int w, int h)
|
||||
{
|
||||
static uint32_t const cp437_chars[] =
|
||||
{
|
||||
/* ─ │ ┌ └ ┐ ┘ */
|
||||
0x2500, 0x2502, 0x250c, 0x2514, 0x2510, 0x2518
|
||||
};
|
||||
|
||||
return draw_box(cv, x, y, w, h, cp437_chars);
|
||||
}
|
||||
|
||||
/** \brief Fill a box on the canvas using the given character.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv The handle to the libcaca canvas.
|
||||
* \param x X coordinate of the upper-left corner of the box.
|
||||
* \param y Y coordinate of the upper-left corner of the box.
|
||||
* \param w Width of the box.
|
||||
* \param h Height of the box.
|
||||
* \param ch UTF-32 character to be used to draw the box.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_fill_box(caca_canvas_t *cv, int x, int y, int w, int h,
|
||||
uint32_t ch)
|
||||
{
|
||||
int i, j, xmax, ymax;
|
||||
|
||||
int x2 = x + w - 1;
|
||||
int y2 = y + h - 1;
|
||||
|
||||
if(x > x2)
|
||||
{
|
||||
int tmp = x;
|
||||
x = x2; x2 = tmp;
|
||||
}
|
||||
|
||||
if(y > y2)
|
||||
{
|
||||
int tmp = y;
|
||||
y = y2; y2 = tmp;
|
||||
}
|
||||
|
||||
xmax = cv->width - 1;
|
||||
ymax = cv->height - 1;
|
||||
|
||||
if(x2 < 0 || y2 < 0 || x > xmax || y > ymax)
|
||||
return 0;
|
||||
|
||||
if(x < 0) x = 0;
|
||||
if(y < 0) y = 0;
|
||||
if(x2 > xmax) x2 = xmax;
|
||||
if(y2 > ymax) y2 = ymax;
|
||||
|
||||
#if 0
|
||||
/* FIXME: this fails with fullwidth character blits. Also, the dirty
|
||||
* rectangle handling may miss fullwidth cells. */
|
||||
/* Optimise dirty rectangle handling, part 1 */
|
||||
cv->dirty_disabled++;
|
||||
#endif
|
||||
|
||||
for(j = y; j <= y2; j++)
|
||||
for(i = x; i <= x2; i++)
|
||||
caca_put_char(cv, i, j, ch);
|
||||
|
||||
#if 0
|
||||
/* Optimise dirty rectangle handling, part 2 */
|
||||
cv->dirty_disabled--;
|
||||
if(!cv->dirty_disabled)
|
||||
caca_add_dirty_rect(cv, x, y, x2 - x + 1, y2 - y + 1);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: The following functions are local.
|
||||
*/
|
||||
|
||||
static int draw_box(caca_canvas_t *cv, int x, int y, int w, int h,
|
||||
uint32_t const *chars)
|
||||
{
|
||||
int i, j, xmax, ymax;
|
||||
|
||||
int x2 = x + w - 1;
|
||||
int y2 = y + h - 1;
|
||||
|
||||
if(x > x2)
|
||||
{
|
||||
int tmp = x;
|
||||
x = x2; x2 = tmp;
|
||||
}
|
||||
|
||||
if(y > y2)
|
||||
{
|
||||
int tmp = y;
|
||||
y = y2; y2 = tmp;
|
||||
}
|
||||
|
||||
xmax = cv->width - 1;
|
||||
ymax = cv->height - 1;
|
||||
|
||||
if(x2 < 0 || y2 < 0 || x > xmax || y > ymax)
|
||||
return 0;
|
||||
|
||||
/* Draw edges */
|
||||
if(y >= 0)
|
||||
for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++)
|
||||
caca_put_char(cv, i, y, chars[0]);
|
||||
|
||||
if(y2 <= ymax)
|
||||
for(i = x < 0 ? 1 : x + 1; i < x2 && i < xmax; i++)
|
||||
caca_put_char(cv, i, y2, chars[0]);
|
||||
|
||||
if(x >= 0)
|
||||
for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++)
|
||||
caca_put_char(cv, x, j, chars[1]);
|
||||
|
||||
if(x2 <= xmax)
|
||||
for(j = y < 0 ? 1 : y + 1; j < y2 && j < ymax; j++)
|
||||
caca_put_char(cv, x2, j, chars[1]);
|
||||
|
||||
/* Draw corners */
|
||||
caca_put_char(cv, x, y, chars[2]);
|
||||
caca_put_char(cv, x, y2, chars[3]);
|
||||
caca_put_char(cv, x2, y, chars[4]);
|
||||
caca_put_char(cv, x2, y2, chars[5]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,486 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2006—2021 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains the main functions used by \e libcaca applications to
|
||||
* initialise the library, get the screen properties, set the framerate and
|
||||
* so on.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <stdio.h>
|
||||
# if defined(USE_PLUGINS)
|
||||
# if defined(HAVE_DLFCN_H)
|
||||
# include <dlfcn.h>
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h" // my change
|
||||
|
||||
#if defined(USE_PLUGINS)
|
||||
# define gl_install(p) caca_plugin_install(p, "gl")
|
||||
# define x11_install(p) caca_plugin_install(p, "x11")
|
||||
#endif
|
||||
|
||||
static int caca_can_resize(caca_display_t *);
|
||||
static int caca_install_driver(caca_display_t *, char const *);
|
||||
static int caca_uninstall_driver(caca_display_t *);
|
||||
static int caca_select_driver(caca_display_t *, char const *);
|
||||
#if defined(USE_PLUGINS)
|
||||
static int caca_plugin_install(caca_display_t *, char const *);
|
||||
#endif
|
||||
|
||||
/** \brief Attach a caca graphical context to a caca canvas.
|
||||
*
|
||||
* Create a graphical context using device-dependent features (ncurses for
|
||||
* terminals, an X11 window, a DOS command window...) that attaches to a
|
||||
* libcaca canvas. Everything that gets drawn in the libcaca canvas can
|
||||
* then be displayed by the libcaca driver.
|
||||
*
|
||||
* If no caca canvas is provided, a new one is created. Its handle can be
|
||||
* retrieved using caca_get_canvas() and it is automatically destroyed when
|
||||
* caca_free_display() is called.
|
||||
*
|
||||
* Note that in order to achieve maximum Unicode compatibility, the driver
|
||||
* initialisation code may temporarily change the program’s global LC_CTYPE
|
||||
* locale using setlocale(). It is advised not to call LC_CTYPE-dependent
|
||||
* functions from other threads during the call to caca_create_display().
|
||||
* The locale settings are restored when the function returns.
|
||||
*
|
||||
* See also caca_create_display_with_driver().
|
||||
*
|
||||
* If an error occurs, NULL is returned and \b errno is set accordingly:
|
||||
* - \c ENOMEM Not enough memory.
|
||||
* - \c ENODEV Graphical device could not be initialised.
|
||||
*
|
||||
* \param cv The caca canvas or NULL to create a canvas automatically.
|
||||
* \return The caca graphical context or NULL if an error occurred.
|
||||
*/
|
||||
caca_display_t * caca_create_display(caca_canvas_t *cv)
|
||||
{
|
||||
return caca_create_display_with_driver(cv, NULL);
|
||||
}
|
||||
|
||||
/** \brief Attach a specific caca graphical context to a caca canvas.
|
||||
*
|
||||
* Create a graphical context using device-dependent features (ncurses for
|
||||
* terminals, an X11 window, a DOS command window...) that attaches to a
|
||||
* libcaca canvas. Everything that gets drawn in the libcaca canvas can
|
||||
* then be displayed by the libcaca driver.
|
||||
*
|
||||
* If no caca canvas is provided, a new one is created. Its handle can be
|
||||
* retrieved using caca_get_canvas() and it is automatically destroyed when
|
||||
* caca_free_display() is called.
|
||||
*
|
||||
* If no driver name is provided, \e libcaca will try to autodetect the best
|
||||
* output driver it can.
|
||||
*
|
||||
* See also caca_create_display().
|
||||
*
|
||||
* If an error occurs, NULL is returned and \b errno is set accordingly:
|
||||
* - \c ENOMEM Not enough memory.
|
||||
* - \c ENODEV Graphical device could not be initialised.
|
||||
*
|
||||
* \param cv The caca canvas or NULL to create a canvas automatically.
|
||||
* \param driver A string describing the desired output driver or NULL to
|
||||
* choose the best driver automatically.
|
||||
* \return The caca graphical context or NULL if an error occurred.
|
||||
*/
|
||||
caca_display_t * caca_create_display_with_driver(caca_canvas_t *cv,
|
||||
char const *driver)
|
||||
{
|
||||
caca_display_t *dp = malloc(sizeof(caca_display_t));
|
||||
|
||||
if(!dp)
|
||||
{
|
||||
seterrno(ENOMEM);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if((dp->autorelease = (cv == NULL)))
|
||||
{
|
||||
cv = caca_create_canvas(0, 0);
|
||||
}
|
||||
|
||||
dp->cv = cv;
|
||||
|
||||
if(caca_manage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp))
|
||||
{
|
||||
if(dp->autorelease)
|
||||
caca_free_canvas(dp->cv);
|
||||
free(dp);
|
||||
seterrno(EBUSY);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(caca_install_driver(dp, driver))
|
||||
{
|
||||
caca_unmanage_canvas(cv, (int (*)(void *))caca_can_resize, (void *)dp);
|
||||
if(dp->autorelease)
|
||||
caca_free_canvas(dp->cv);
|
||||
free(dp);
|
||||
seterrno(ENODEV);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dp;
|
||||
}
|
||||
|
||||
/** \brief Get available display drivers
|
||||
*
|
||||
* Return a list of available display drivers. The list is a NULL-terminated
|
||||
* array of strings, interleaving a string containing the internal value for
|
||||
* the display driver, and a string containing the natural language
|
||||
* description for that driver.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \return An array of strings.
|
||||
*/
|
||||
char const * const * caca_get_display_driver_list(void)
|
||||
{
|
||||
static char const * const list[] =
|
||||
{
|
||||
#if defined(USE_COCOA)
|
||||
"cocoa", "Mac OS X Cocoa",
|
||||
#endif
|
||||
#if defined(USE_WIN32)
|
||||
"win32", "Windows console",
|
||||
#endif
|
||||
#if defined(USE_CONIO)
|
||||
"conio", "MS-DOS conio",
|
||||
#endif
|
||||
#if defined(USE_X11)
|
||||
"x11", "X11 graphical window",
|
||||
#endif
|
||||
#if defined(USE_GL)
|
||||
"gl", "OpenGL window",
|
||||
#endif
|
||||
#if defined(USE_SLANG)
|
||||
"slang", "S-Lang console library",
|
||||
#endif
|
||||
#if defined(USE_NCURSES)
|
||||
"ncurses", "ncurses console library",
|
||||
#endif
|
||||
#if defined(USE_VGA)
|
||||
"vga", "direct VGA memory",
|
||||
#endif
|
||||
#if !defined(__KERNEL__)
|
||||
"raw", "raw libcaca output",
|
||||
"null", "null driver",
|
||||
#endif
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/** \brief Return a caca graphical context's current output driver.
|
||||
*
|
||||
* Return the given display's current output driver.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param dp The caca display.
|
||||
* \return A static string.
|
||||
*/
|
||||
char const * caca_get_display_driver(caca_display_t *dp)
|
||||
{
|
||||
return dp->drv.driver;
|
||||
}
|
||||
|
||||
/** \brief Set the output driver.
|
||||
*
|
||||
* Dynamically change the given display's output driver.
|
||||
*
|
||||
* FIXME: decide what to do in case of failure
|
||||
*
|
||||
* \param dp The caca display.
|
||||
* \param driver A string describing the desired output driver or NULL to
|
||||
* choose the best driver automatically.
|
||||
* \return 0 in case of success, -1 if an error occurred.
|
||||
*/
|
||||
int caca_set_display_driver(caca_display_t *dp, char const *driver)
|
||||
{
|
||||
caca_uninstall_driver(dp);
|
||||
if(caca_install_driver(dp, driver))
|
||||
{
|
||||
seterrno(ENODEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Detach a caca graphical context from a caca backend context.
|
||||
*
|
||||
* Detach a graphical context from its caca backend and destroy it. The
|
||||
* libcaca canvas continues to exist and other graphical contexts can be
|
||||
* attached to it afterwards.
|
||||
*
|
||||
* If the caca canvas was automatically created by caca_create_display(),
|
||||
* it is automatically destroyed and any handle to it becomes invalid.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param dp The libcaca graphical context.
|
||||
* \return This function always returns 0.
|
||||
*/
|
||||
int caca_free_display(caca_display_t *dp)
|
||||
{
|
||||
caca_uninstall_driver(dp);
|
||||
caca_unmanage_canvas(dp->cv, (int (*)(void *))caca_can_resize, (void *)dp);
|
||||
if(dp->autorelease)
|
||||
caca_free_canvas(dp->cv);
|
||||
free(dp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Get the canvas attached to a caca graphical context.
|
||||
*
|
||||
* Return a handle on the \e caca_canvas_t object that was either attached
|
||||
* or created by caca_create_display().
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param dp The libcaca graphical context.
|
||||
* \return The libcaca canvas.
|
||||
*/
|
||||
caca_canvas_t * caca_get_canvas(caca_display_t *dp)
|
||||
{
|
||||
return dp->cv;
|
||||
}
|
||||
|
||||
/** \brief Return the \e libcaca version.
|
||||
*
|
||||
* Return a read-only string with the \e libcaca version information.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \return The \e libcaca version information.
|
||||
*/
|
||||
char const * caca_get_version(void)
|
||||
{
|
||||
return PACKAGE_VERSION;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: The following functions are private.
|
||||
*/
|
||||
|
||||
extern void *_caca_alloc2d(size_t width, size_t height, size_t elem_size)
|
||||
{
|
||||
if (width == 0 || height == 0 || elem_size == 0 || SIZE_MAX / width / height < elem_size)
|
||||
return NULL;
|
||||
return malloc(width * height * elem_size);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: The following functions are local.
|
||||
*/
|
||||
|
||||
static int caca_can_resize(caca_display_t *dp)
|
||||
{
|
||||
return dp->resize.allow;
|
||||
}
|
||||
|
||||
static int caca_install_driver(caca_display_t *dp, char const *driver)
|
||||
{
|
||||
#if defined(USE_PLUGINS)
|
||||
dp->plugin = NULL;
|
||||
#endif
|
||||
|
||||
if(caca_select_driver(dp, driver))
|
||||
{
|
||||
#if defined(USE_PLUGINS)
|
||||
if(dp->plugin)
|
||||
dlclose(dp->plugin);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(dp->drv.init_graphics(dp))
|
||||
{
|
||||
#if defined(USE_PLUGINS)
|
||||
if(dp->plugin)
|
||||
dlclose(dp->plugin);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Graphics stuff */
|
||||
dp->delay = 0;
|
||||
dp->rendertime = 0;
|
||||
|
||||
/* Events stuff */
|
||||
#if defined(USE_SLANG) || defined(USE_NCURSES)
|
||||
dp->events.key_timer.last_sec = 0;
|
||||
dp->events.key_timer.last_usec = 0;
|
||||
dp->events.last_key_ticks = 0;
|
||||
dp->events.autorepeat_ticks = 0;
|
||||
dp->events.last_key_event.type = CACA_EVENT_NONE;
|
||||
#endif
|
||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
|
||||
dp->events.queue = 0;
|
||||
#endif
|
||||
|
||||
dp->timer.last_sec = 0;
|
||||
dp->timer.last_usec = 0;
|
||||
#if defined PROF
|
||||
_caca_init_stat(&dp->display_stat, "dp[%p] disp_sys time", dp);
|
||||
_caca_init_stat(&dp->wait_stat, "dp[%p] disp_wait time", dp);
|
||||
_caca_init_stat(&dp->ev_sys_stat, "dp[%p] ev_sys time", dp);
|
||||
_caca_init_stat(&dp->ev_wait_stat, "dp[%p] ev_wait time", dp);
|
||||
#endif
|
||||
dp->lastticks = 0;
|
||||
|
||||
/* Mouse position */
|
||||
dp->mouse.x = caca_get_canvas_width(dp->cv) / 2;
|
||||
dp->mouse.y = caca_get_canvas_height(dp->cv) / 2;
|
||||
|
||||
/* Resize events */
|
||||
dp->resize.resized = 0;
|
||||
dp->resize.allow = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int caca_uninstall_driver(caca_display_t *dp)
|
||||
{
|
||||
dp->drv.end_graphics(dp);
|
||||
#if defined(USE_PLUGINS)
|
||||
if(dp->plugin)
|
||||
dlclose(dp->plugin);
|
||||
#endif
|
||||
#if defined PROF
|
||||
_caca_fini_stat(&dp->display_stat);
|
||||
_caca_fini_stat(&dp->wait_stat);
|
||||
_caca_fini_stat(&dp->ev_wait_stat);
|
||||
_caca_fini_stat(&dp->ev_sys_stat);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int caca_select_driver(caca_display_t *dp, char const *driver)
|
||||
{
|
||||
char const *var = driver;
|
||||
#if defined(HAVE_GETENV)
|
||||
if(!var)
|
||||
var = getenv("CACA_DRIVER");
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_STRCASECMP)
|
||||
/* If the environment variable was set, use it */
|
||||
if(var && *var)
|
||||
{
|
||||
#if defined(USE_COCOA)
|
||||
if(!strcasecmp(var, "cocoa")) return cocoa_install(dp);
|
||||
#endif
|
||||
#if defined(USE_WIN32)
|
||||
if(!strcasecmp(var, "win32")) return win32_install(dp);
|
||||
#endif
|
||||
#if defined(USE_CONIO)
|
||||
if(!strcasecmp(var, "conio")) return conio_install(dp);
|
||||
#endif
|
||||
#if defined(USE_X11)
|
||||
if(!strcasecmp(var, "x11")) return x11_install(dp);
|
||||
#endif
|
||||
#if defined(USE_GL)
|
||||
if(!strcasecmp(var, "gl")) return gl_install(dp);
|
||||
#endif
|
||||
#if !defined(__KERNEL__)
|
||||
if(!strcasecmp(var, "raw")) return raw_install(dp);
|
||||
#endif
|
||||
#if defined(USE_SLANG)
|
||||
if(!strcasecmp(var, "slang")) return slang_install(dp);
|
||||
#endif
|
||||
#if defined(USE_NCURSES)
|
||||
if(!strcasecmp(var, "ncurses")) return ncurses_install(dp);
|
||||
#endif
|
||||
#if defined(USE_VGA)
|
||||
if(!strcasecmp(var, "vga")) return vga_install(dp);
|
||||
#endif
|
||||
#if !defined(__KERNEL__)
|
||||
if(!strcasecmp(var, "null")) return null_install(dp);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(USE_COCOA)
|
||||
if(cocoa_install(dp) == 0) return 0;
|
||||
#endif
|
||||
#if defined(USE_WIN32)
|
||||
if(win32_install(dp) == 0) return 0;
|
||||
#endif
|
||||
#if defined(USE_CONIO)
|
||||
if(conio_install(dp) == 0) return 0;
|
||||
#endif
|
||||
#if defined(USE_VGA)
|
||||
if(vga_install(dp) == 0) return 0;
|
||||
#endif
|
||||
#if defined(USE_X11)
|
||||
if(x11_install(dp) == 0) return 0;
|
||||
#endif
|
||||
#if defined(USE_GL)
|
||||
if(gl_install(dp) == 0) return 0;
|
||||
#endif
|
||||
/* ncurses has a higher priority than slang because it has better colour
|
||||
* support across terminal types, despite being slightly slower. */
|
||||
#if defined(USE_NCURSES)
|
||||
if(ncurses_install(dp) == 0) return 0;
|
||||
#endif
|
||||
#if defined(USE_SLANG)
|
||||
if(slang_install(dp) == 0) return 0;
|
||||
#endif
|
||||
/* Of course we don't try "raw" or "null" if the user did not
|
||||
* specifically ask for them. */
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined(USE_PLUGINS)
|
||||
static int caca_plugin_install(caca_display_t *dp, char const *driver)
|
||||
{
|
||||
char buf[512];
|
||||
int (*sym) (caca_display_t *);
|
||||
|
||||
sprintf(buf, "%s/lib%s_plugin.so", PLUGINDIR, driver);
|
||||
dp->plugin = dlopen(buf, RTLD_NOW);
|
||||
if(!dp->plugin)
|
||||
{
|
||||
sprintf(buf, "lib%s_plugin.so", driver);
|
||||
dp->plugin = dlopen(buf, RTLD_NOW);
|
||||
if(!dp->plugin)
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(buf, "%s_install", driver);
|
||||
sym = dlsym(dp->plugin, buf);
|
||||
if(!sym)
|
||||
{
|
||||
dlclose(dp->plugin);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sym(dp);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,723 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2018 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/** \file caca.h
|
||||
* \author Sam Hocevar <sam@hocevar.net>
|
||||
* \brief The \e libcaca public header.
|
||||
*
|
||||
* This header contains the public types and functions that applications
|
||||
* using \e libcaca may use.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_H__
|
||||
#define __CACA_H__
|
||||
|
||||
#include <caca_types.h>
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#undef __extern
|
||||
#if defined _DOXYGEN_SKIP_ME
|
||||
#elif defined _WIN32 && defined __LIBCACA__ && defined DLL_EXPORT
|
||||
# define __extern extern __declspec(dllexport)
|
||||
#elif defined _WIN32 && !defined __LIBCACA__ && !defined CACA_STATIC
|
||||
# define __extern extern __declspec(dllimport)
|
||||
#elif defined CACA_ENABLE_VISIBILITY
|
||||
# define __extern extern __attribute__((visibility("default")))
|
||||
#else
|
||||
# define __extern extern
|
||||
#endif
|
||||
|
||||
/** libcaca API version */
|
||||
#define CACA_API_VERSION_1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/** \e libcaca canvas */
|
||||
typedef struct caca_canvas caca_canvas_t;
|
||||
/** dither structure */
|
||||
typedef struct caca_dither caca_dither_t;
|
||||
/** character font structure */
|
||||
typedef struct caca_charfont caca_charfont_t;
|
||||
/** bitmap font structure */
|
||||
typedef struct caca_font caca_font_t;
|
||||
/** file handle structure */
|
||||
typedef struct caca_file caca_file_t;
|
||||
/** \e libcaca display context */
|
||||
typedef struct caca_display caca_display_t;
|
||||
/** \e libcaca event structure */
|
||||
typedef struct caca_event caca_event_t;
|
||||
|
||||
/** \defgroup caca_attr libcaca attribute definitions
|
||||
*
|
||||
* Colours and styles that can be used with caca_set_attr().
|
||||
*
|
||||
* @{ */
|
||||
/** \e libcaca colour keyword */
|
||||
enum caca_color
|
||||
{
|
||||
CACA_BLACK = 0x00, /**< The colour index for black. */
|
||||
CACA_BLUE = 0x01, /**< The colour index for blue. */
|
||||
CACA_GREEN = 0x02, /**< The colour index for green. */
|
||||
CACA_CYAN = 0x03, /**< The colour index for cyan. */
|
||||
CACA_RED = 0x04, /**< The colour index for red. */
|
||||
CACA_MAGENTA = 0x05, /**< The colour index for magenta. */
|
||||
CACA_BROWN = 0x06, /**< The colour index for brown. */
|
||||
CACA_LIGHTGRAY = 0x07, /**< The colour index for light gray. */
|
||||
CACA_DARKGRAY = 0x08, /**< The colour index for dark gray. */
|
||||
CACA_LIGHTBLUE = 0x09, /**< The colour index for blue. */
|
||||
CACA_LIGHTGREEN = 0x0a, /**< The colour index for light green. */
|
||||
CACA_LIGHTCYAN = 0x0b, /**< The colour index for light cyan. */
|
||||
CACA_LIGHTRED = 0x0c, /**< The colour index for light red. */
|
||||
CACA_LIGHTMAGENTA = 0x0d, /**< The colour index for light magenta. */
|
||||
CACA_YELLOW = 0x0e, /**< The colour index for yellow. */
|
||||
CACA_WHITE = 0x0f, /**< The colour index for white. */
|
||||
CACA_DEFAULT = 0x10, /**< The output driver's default colour. */
|
||||
CACA_TRANSPARENT = 0x20, /**< The transparent colour. */
|
||||
};
|
||||
|
||||
/** \e libcaca style keyword */
|
||||
enum caca_style
|
||||
{
|
||||
CACA_BOLD = 0x01, /**< The style mask for bold. */
|
||||
CACA_ITALICS = 0x02, /**< The style mask for italics. */
|
||||
CACA_UNDERLINE = 0x04, /**< The style mask for underline. */
|
||||
CACA_BLINK = 0x08, /**< The style mask for blink. */
|
||||
};
|
||||
/* @} */
|
||||
|
||||
/** \brief User event type enumeration.
|
||||
*
|
||||
* This enum serves two purposes:
|
||||
* - Build listening masks for caca_get_event().
|
||||
* - Define the type of a \e caca_event_t.
|
||||
*/
|
||||
enum caca_event_type
|
||||
{
|
||||
CACA_EVENT_NONE = 0x0000, /**< No event. */
|
||||
|
||||
CACA_EVENT_KEY_PRESS = 0x0001, /**< A key was pressed. */
|
||||
CACA_EVENT_KEY_RELEASE = 0x0002, /**< A key was released. */
|
||||
CACA_EVENT_MOUSE_PRESS = 0x0004, /**< A mouse button was pressed. */
|
||||
CACA_EVENT_MOUSE_RELEASE = 0x0008, /**< A mouse button was released. */
|
||||
CACA_EVENT_MOUSE_MOTION = 0x0010, /**< The mouse was moved. */
|
||||
CACA_EVENT_RESIZE = 0x0020, /**< The window was resized. */
|
||||
CACA_EVENT_QUIT = 0x0040, /**< The user requested to quit. */
|
||||
|
||||
CACA_EVENT_ANY = 0xffff /**< Bitmask for any event. */
|
||||
};
|
||||
|
||||
/** \brief Handling of user events.
|
||||
*
|
||||
* This structure is filled by caca_get_event() when an event is received.
|
||||
* It is an opaque structure that should only be accessed through
|
||||
* caca_event_get_type() and similar functions. The struct members may no
|
||||
* longer be directly accessible in future versions.
|
||||
*/
|
||||
struct caca_event
|
||||
{
|
||||
enum caca_event_type type; /**< The event type. */
|
||||
union
|
||||
{
|
||||
struct { int x, y, button; } mouse;
|
||||
struct { int w, h; } resize;
|
||||
struct { int ch; uint32_t utf32; char utf8[8]; } key;
|
||||
} data; /**< The event information data */
|
||||
#if !defined(_DOXYGEN_SKIP_ME)
|
||||
uint8_t padding[16];
|
||||
#endif
|
||||
};
|
||||
|
||||
/** \brief Option parsing.
|
||||
*
|
||||
* This structure contains commandline parsing information for systems
|
||||
* where getopt_long() is unavailable.
|
||||
*/
|
||||
struct caca_option
|
||||
{
|
||||
char const *name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/** \brief Special key values.
|
||||
*
|
||||
* Special key values returned by caca_get_event() for which there is no
|
||||
* printable ASCII equivalent.
|
||||
*/
|
||||
enum caca_key
|
||||
{
|
||||
CACA_KEY_UNKNOWN = 0x00, /**< Unknown key. */
|
||||
|
||||
/* The following keys have ASCII equivalents */
|
||||
CACA_KEY_CTRL_A = 0x01, /**< The Ctrl-A key. */
|
||||
CACA_KEY_CTRL_B = 0x02, /**< The Ctrl-B key. */
|
||||
CACA_KEY_CTRL_C = 0x03, /**< The Ctrl-C key. */
|
||||
CACA_KEY_CTRL_D = 0x04, /**< The Ctrl-D key. */
|
||||
CACA_KEY_CTRL_E = 0x05, /**< The Ctrl-E key. */
|
||||
CACA_KEY_CTRL_F = 0x06, /**< The Ctrl-F key. */
|
||||
CACA_KEY_CTRL_G = 0x07, /**< The Ctrl-G key. */
|
||||
CACA_KEY_BACKSPACE = 0x08, /**< The backspace key. */
|
||||
CACA_KEY_TAB = 0x09, /**< The tabulation key. */
|
||||
CACA_KEY_CTRL_J = 0x0a, /**< The Ctrl-J key. */
|
||||
CACA_KEY_CTRL_K = 0x0b, /**< The Ctrl-K key. */
|
||||
CACA_KEY_CTRL_L = 0x0c, /**< The Ctrl-L key. */
|
||||
CACA_KEY_RETURN = 0x0d, /**< The return key. */
|
||||
CACA_KEY_CTRL_N = 0x0e, /**< The Ctrl-N key. */
|
||||
CACA_KEY_CTRL_O = 0x0f, /**< The Ctrl-O key. */
|
||||
CACA_KEY_CTRL_P = 0x10, /**< The Ctrl-P key. */
|
||||
CACA_KEY_CTRL_Q = 0x11, /**< The Ctrl-Q key. */
|
||||
CACA_KEY_CTRL_R = 0x12, /**< The Ctrl-R key. */
|
||||
CACA_KEY_PAUSE = 0x13, /**< The pause key. */
|
||||
CACA_KEY_CTRL_T = 0x14, /**< The Ctrl-T key. */
|
||||
CACA_KEY_CTRL_U = 0x15, /**< The Ctrl-U key. */
|
||||
CACA_KEY_CTRL_V = 0x16, /**< The Ctrl-V key. */
|
||||
CACA_KEY_CTRL_W = 0x17, /**< The Ctrl-W key. */
|
||||
CACA_KEY_CTRL_X = 0x18, /**< The Ctrl-X key. */
|
||||
CACA_KEY_CTRL_Y = 0x19, /**< The Ctrl-Y key. */
|
||||
CACA_KEY_CTRL_Z = 0x1a, /**< The Ctrl-Z key. */
|
||||
CACA_KEY_ESCAPE = 0x1b, /**< The escape key. */
|
||||
CACA_KEY_DELETE = 0x7f, /**< The delete key. */
|
||||
|
||||
/* The following keys do not have ASCII equivalents but have been
|
||||
* chosen to match the SDL equivalents */
|
||||
CACA_KEY_UP = 0x111, /**< The up arrow key. */
|
||||
CACA_KEY_DOWN = 0x112, /**< The down arrow key. */
|
||||
CACA_KEY_LEFT = 0x113, /**< The left arrow key. */
|
||||
CACA_KEY_RIGHT = 0x114, /**< The right arrow key. */
|
||||
|
||||
CACA_KEY_INSERT = 0x115, /**< The insert key. */
|
||||
CACA_KEY_HOME = 0x116, /**< The home key. */
|
||||
CACA_KEY_END = 0x117, /**< The end key. */
|
||||
CACA_KEY_PAGEUP = 0x118, /**< The page up key. */
|
||||
CACA_KEY_PAGEDOWN = 0x119, /**< The page down key. */
|
||||
|
||||
CACA_KEY_F1 = 0x11a, /**< The F1 key. */
|
||||
CACA_KEY_F2 = 0x11b, /**< The F2 key. */
|
||||
CACA_KEY_F3 = 0x11c, /**< The F3 key. */
|
||||
CACA_KEY_F4 = 0x11d, /**< The F4 key. */
|
||||
CACA_KEY_F5 = 0x11e, /**< The F5 key. */
|
||||
CACA_KEY_F6 = 0x11f, /**< The F6 key. */
|
||||
CACA_KEY_F7 = 0x120, /**< The F7 key. */
|
||||
CACA_KEY_F8 = 0x121, /**< The F8 key. */
|
||||
CACA_KEY_F9 = 0x122, /**< The F9 key. */
|
||||
CACA_KEY_F10 = 0x123, /**< The F10 key. */
|
||||
CACA_KEY_F11 = 0x124, /**< The F11 key. */
|
||||
CACA_KEY_F12 = 0x125, /**< The F12 key. */
|
||||
CACA_KEY_F13 = 0x126, /**< The F13 key. */
|
||||
CACA_KEY_F14 = 0x127, /**< The F14 key. */
|
||||
CACA_KEY_F15 = 0x128 /**< The F15 key. */
|
||||
};
|
||||
|
||||
/** \defgroup libcaca libcaca basic functions
|
||||
*
|
||||
* These functions provide the basic \e libcaca routines for library
|
||||
* initialisation, system information retrieval and configuration.
|
||||
*
|
||||
* @{ */
|
||||
__extern caca_canvas_t * caca_create_canvas(int, int);
|
||||
__extern int caca_manage_canvas(caca_canvas_t *, int (*)(void *), void *);
|
||||
__extern int caca_unmanage_canvas(caca_canvas_t *, int (*)(void *), void *);
|
||||
__extern int caca_set_canvas_size(caca_canvas_t *, int, int);
|
||||
__extern int caca_get_canvas_width(caca_canvas_t const *);
|
||||
__extern int caca_get_canvas_height(caca_canvas_t const *);
|
||||
__extern uint32_t const * caca_get_canvas_chars(caca_canvas_t const *);
|
||||
__extern uint32_t const * caca_get_canvas_attrs(caca_canvas_t const *);
|
||||
__extern int caca_free_canvas(caca_canvas_t *);
|
||||
__extern int caca_rand(int, int);
|
||||
__extern char const * caca_get_version(void);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_canvas libcaca canvas drawing
|
||||
*
|
||||
* These functions provide low-level character printing routines and
|
||||
* higher level graphics functions.
|
||||
*
|
||||
* @{ */
|
||||
#define CACA_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */
|
||||
__extern int caca_gotoxy(caca_canvas_t *, int, int);
|
||||
__extern int caca_wherex(caca_canvas_t const *);
|
||||
__extern int caca_wherey(caca_canvas_t const *);
|
||||
__extern int caca_put_char(caca_canvas_t *, int, int, uint32_t);
|
||||
__extern uint32_t caca_get_char(caca_canvas_t const *, int, int);
|
||||
__extern int caca_put_str(caca_canvas_t *, int, int, char const *);
|
||||
__extern int caca_printf(caca_canvas_t *, int, int, char const *, ...);
|
||||
__extern int caca_vprintf(caca_canvas_t *, int, int, char const *, va_list);
|
||||
__extern int caca_clear_canvas(caca_canvas_t *);
|
||||
__extern int caca_set_canvas_handle(caca_canvas_t *, int, int);
|
||||
__extern int caca_get_canvas_handle_x(caca_canvas_t const *);
|
||||
__extern int caca_get_canvas_handle_y(caca_canvas_t const *);
|
||||
__extern int caca_blit(caca_canvas_t *, int, int, caca_canvas_t const *,
|
||||
caca_canvas_t const *);
|
||||
__extern int caca_set_canvas_boundaries(caca_canvas_t *, int, int, int, int);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_dirty libcaca dirty rectangle manipulation
|
||||
*
|
||||
* These functions manipulate dirty rectangles for optimised blitting.
|
||||
* @{ */
|
||||
__extern int caca_disable_dirty_rect(caca_canvas_t *);
|
||||
__extern int caca_enable_dirty_rect(caca_canvas_t *);
|
||||
__extern int caca_get_dirty_rect_count(caca_canvas_t *);
|
||||
__extern int caca_get_dirty_rect(caca_canvas_t *, int, int *, int *,
|
||||
int *, int *);
|
||||
__extern int caca_add_dirty_rect(caca_canvas_t *, int, int, int, int);
|
||||
__extern int caca_remove_dirty_rect(caca_canvas_t *, int, int, int, int);
|
||||
__extern int caca_clear_dirty_rect_list(caca_canvas_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_transform libcaca canvas transformation
|
||||
*
|
||||
* These functions perform horizontal and vertical canvas flipping.
|
||||
*
|
||||
* @{ */
|
||||
__extern int caca_invert(caca_canvas_t *);
|
||||
__extern int caca_flip(caca_canvas_t *);
|
||||
__extern int caca_flop(caca_canvas_t *);
|
||||
__extern int caca_rotate_180(caca_canvas_t *);
|
||||
__extern int caca_rotate_left(caca_canvas_t *);
|
||||
__extern int caca_rotate_right(caca_canvas_t *);
|
||||
__extern int caca_stretch_left(caca_canvas_t *);
|
||||
__extern int caca_stretch_right(caca_canvas_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_attributes libcaca attribute conversions
|
||||
*
|
||||
* These functions perform conversions between attribute values.
|
||||
*
|
||||
* @{ */
|
||||
__extern uint32_t caca_get_attr(caca_canvas_t const *, int, int);
|
||||
__extern int caca_set_attr(caca_canvas_t *, uint32_t);
|
||||
__extern int caca_unset_attr(caca_canvas_t *, uint32_t);
|
||||
__extern int caca_toggle_attr(caca_canvas_t *, uint32_t);
|
||||
__extern int caca_put_attr(caca_canvas_t *, int, int, uint32_t);
|
||||
__extern int caca_set_color_ansi(caca_canvas_t *, uint8_t, uint8_t);
|
||||
__extern int caca_set_color_argb(caca_canvas_t *, uint16_t, uint16_t);
|
||||
__extern uint8_t caca_attr_to_ansi(uint32_t);
|
||||
__extern uint8_t caca_attr_to_ansi_fg(uint32_t);
|
||||
__extern uint8_t caca_attr_to_ansi_bg(uint32_t);
|
||||
__extern uint16_t caca_attr_to_rgb12_fg(uint32_t);
|
||||
__extern uint16_t caca_attr_to_rgb12_bg(uint32_t);
|
||||
__extern void caca_attr_to_argb64(uint32_t, uint8_t[8]);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_charset libcaca character set conversions
|
||||
*
|
||||
* These functions perform conversions between usual character sets.
|
||||
*
|
||||
* @{ */
|
||||
__extern uint32_t caca_utf8_to_utf32(char const *, size_t *);
|
||||
__extern size_t caca_utf32_to_utf8(char *, uint32_t);
|
||||
__extern uint8_t caca_utf32_to_cp437(uint32_t);
|
||||
__extern uint32_t caca_cp437_to_utf32(uint8_t);
|
||||
__extern char caca_utf32_to_ascii(uint32_t);
|
||||
__extern int caca_utf32_is_fullwidth(uint32_t);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_primitives libcaca primitives drawing
|
||||
*
|
||||
* These functions provide routines for primitive drawing, such as lines,
|
||||
* boxes, triangles and ellipses.
|
||||
*
|
||||
* @{ */
|
||||
__extern int caca_draw_line(caca_canvas_t *, int, int, int, int, uint32_t);
|
||||
__extern int caca_draw_polyline(caca_canvas_t *, int const x[],
|
||||
int const y[], int, uint32_t);
|
||||
__extern int caca_draw_thin_line(caca_canvas_t *, int, int, int, int);
|
||||
__extern int caca_draw_thin_polyline(caca_canvas_t *, int const x[],
|
||||
int const y[], int);
|
||||
|
||||
__extern int caca_draw_circle(caca_canvas_t *, int, int, int, uint32_t);
|
||||
__extern int caca_draw_ellipse(caca_canvas_t *, int, int, int, int, uint32_t);
|
||||
__extern int caca_draw_thin_ellipse(caca_canvas_t *, int, int, int, int);
|
||||
__extern int caca_fill_ellipse(caca_canvas_t *, int, int, int, int, uint32_t);
|
||||
|
||||
__extern int caca_draw_box(caca_canvas_t *, int, int, int, int, uint32_t);
|
||||
__extern int caca_draw_thin_box(caca_canvas_t *, int, int, int, int);
|
||||
__extern int caca_draw_cp437_box(caca_canvas_t *, int, int, int, int);
|
||||
__extern int caca_fill_box(caca_canvas_t *, int, int, int, int, uint32_t);
|
||||
|
||||
__extern int caca_draw_triangle(caca_canvas_t *, int, int, int, int, int,
|
||||
int, uint32_t);
|
||||
__extern int caca_draw_thin_triangle(caca_canvas_t *, int, int, int, int,
|
||||
int, int);
|
||||
__extern int caca_fill_triangle(caca_canvas_t *, int, int, int, int, int,
|
||||
int, uint32_t);
|
||||
__extern int caca_fill_triangle_textured(caca_canvas_t *cv,
|
||||
int coords[6],
|
||||
caca_canvas_t *tex,
|
||||
float uv[6]);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_frame libcaca canvas frame handling
|
||||
*
|
||||
* These functions provide high level routines for canvas frame insertion,
|
||||
* removal, copying etc.
|
||||
*
|
||||
* @{ */
|
||||
__extern int caca_get_frame_count(caca_canvas_t const *);
|
||||
__extern int caca_set_frame(caca_canvas_t *, int);
|
||||
__extern char const *caca_get_frame_name(caca_canvas_t const *);
|
||||
__extern int caca_set_frame_name(caca_canvas_t *, char const *);
|
||||
__extern int caca_create_frame(caca_canvas_t *, int);
|
||||
__extern int caca_free_frame(caca_canvas_t *, int);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_dither libcaca bitmap dithering
|
||||
*
|
||||
* These functions provide high level routines for dither allocation and
|
||||
* rendering.
|
||||
*
|
||||
* @{ */
|
||||
__extern void *_caca_alloc2d(size_t width, size_t height, size_t elem_size);
|
||||
__extern caca_dither_t *caca_create_dither(int, int, int, int,
|
||||
uint32_t, uint32_t,
|
||||
uint32_t, uint32_t);
|
||||
__extern int caca_set_dither_palette(caca_dither_t *,
|
||||
uint32_t r[], uint32_t g[],
|
||||
uint32_t b[], uint32_t a[]);
|
||||
__extern int caca_set_dither_brightness(caca_dither_t *, float);
|
||||
__extern float caca_get_dither_brightness(caca_dither_t const *);
|
||||
__extern int caca_set_dither_gamma(caca_dither_t *, float);
|
||||
__extern float caca_get_dither_gamma(caca_dither_t const *);
|
||||
__extern int caca_set_dither_contrast(caca_dither_t *, float);
|
||||
__extern float caca_get_dither_contrast(caca_dither_t const *);
|
||||
__extern int caca_set_dither_antialias(caca_dither_t *, char const *);
|
||||
__extern char const * const * caca_get_dither_antialias_list(caca_dither_t
|
||||
const *);
|
||||
__extern char const * caca_get_dither_antialias(caca_dither_t const *);
|
||||
__extern int caca_set_dither_color(caca_dither_t *, char const *);
|
||||
__extern char const * const * caca_get_dither_color_list(caca_dither_t
|
||||
const *);
|
||||
__extern char const * caca_get_dither_color(caca_dither_t const *);
|
||||
__extern int caca_set_dither_charset(caca_dither_t *, char const *);
|
||||
__extern char const * const * caca_get_dither_charset_list(caca_dither_t
|
||||
const *);
|
||||
__extern char const * caca_get_dither_charset(caca_dither_t const *);
|
||||
__extern int caca_set_dither_algorithm(caca_dither_t *, char const *);
|
||||
__extern char const * const * caca_get_dither_algorithm_list(caca_dither_t
|
||||
const *);
|
||||
__extern char const * caca_get_dither_algorithm(caca_dither_t const *);
|
||||
__extern int caca_dither_bitmap(caca_canvas_t *, int, int, int, int,
|
||||
caca_dither_t const *, void const *);
|
||||
__extern int caca_free_dither(caca_dither_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_charfont libcaca character font handling
|
||||
*
|
||||
* These functions provide character font handling routines.
|
||||
*
|
||||
* @{ */
|
||||
__extern caca_charfont_t *caca_load_charfont(void const *, size_t);
|
||||
__extern int caca_free_charfont(caca_charfont_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_font libcaca bitmap font handling
|
||||
*
|
||||
* These functions provide bitmap font handling routines and high quality
|
||||
* canvas to bitmap rendering.
|
||||
*
|
||||
* @{ */
|
||||
__extern caca_font_t *caca_load_font(void const *, size_t);
|
||||
__extern char const * const * caca_get_font_list(void);
|
||||
__extern int caca_get_font_width(caca_font_t const *);
|
||||
__extern int caca_get_font_height(caca_font_t const *);
|
||||
__extern uint32_t const *caca_get_font_blocks(caca_font_t const *);
|
||||
__extern int caca_render_canvas(caca_canvas_t const *, caca_font_t const *,
|
||||
void *, int, int, int);
|
||||
__extern int caca_free_font(caca_font_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_figfont libcaca FIGfont handling
|
||||
*
|
||||
* These functions provide FIGlet and TOIlet font handling routines.
|
||||
*
|
||||
* @{ */
|
||||
__extern int caca_canvas_set_figfont(caca_canvas_t *, char const *);
|
||||
__extern int caca_set_figfont_smush(caca_canvas_t *, char const *);
|
||||
__extern int caca_set_figfont_width(caca_canvas_t *, int);
|
||||
__extern int caca_put_figchar(caca_canvas_t *, uint32_t);
|
||||
__extern int caca_flush_figlet(caca_canvas_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_file libcaca file IO
|
||||
*
|
||||
* These functions allow to read and write files in a platform-independent
|
||||
* way.
|
||||
* @{ */
|
||||
__extern caca_file_t *caca_file_open(char const *, const char *);
|
||||
__extern int caca_file_close(caca_file_t *);
|
||||
__extern uint64_t caca_file_tell(caca_file_t *);
|
||||
__extern size_t caca_file_read(caca_file_t *, void *, size_t);
|
||||
__extern size_t caca_file_write(caca_file_t *, const void *, size_t);
|
||||
__extern char * caca_file_gets(caca_file_t *, char *, int);
|
||||
__extern int caca_file_eof(caca_file_t *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_importexport libcaca importers/exporters from/to various
|
||||
* formats
|
||||
*
|
||||
* These functions import various file formats into a new canvas, or export
|
||||
* the current canvas to various text formats.
|
||||
*
|
||||
* @{ */
|
||||
__extern ssize_t caca_import_canvas_from_memory(caca_canvas_t *, void const *,
|
||||
size_t, char const *);
|
||||
__extern ssize_t caca_import_canvas_from_file(caca_canvas_t *, char const *,
|
||||
char const *);
|
||||
__extern ssize_t caca_import_area_from_memory(caca_canvas_t *, int, int,
|
||||
void const *, size_t,
|
||||
char const *);
|
||||
__extern ssize_t caca_import_area_from_file(caca_canvas_t *, int, int,
|
||||
char const *, char const *);
|
||||
__extern char const * const * caca_get_import_list(void);
|
||||
__extern void *caca_export_canvas_to_memory(caca_canvas_t const *,
|
||||
char const *, size_t *);
|
||||
__extern void *caca_export_area_to_memory(caca_canvas_t const *, int, int,
|
||||
int, int, char const *, size_t *);
|
||||
__extern char const * const * caca_get_export_list(void);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_display libcaca display functions
|
||||
*
|
||||
* These functions provide the basic \e libcaca routines for display
|
||||
* initialisation, system information retrieval and configuration.
|
||||
*
|
||||
* @{ */
|
||||
__extern caca_display_t * caca_create_display(caca_canvas_t *);
|
||||
__extern caca_display_t * caca_create_display_with_driver(caca_canvas_t *,
|
||||
char const *);
|
||||
__extern char const * const * caca_get_display_driver_list(void);
|
||||
__extern char const * caca_get_display_driver(caca_display_t *);
|
||||
__extern int caca_set_display_driver(caca_display_t *, char const *);
|
||||
__extern int caca_free_display(caca_display_t *);
|
||||
__extern caca_canvas_t * caca_get_canvas(caca_display_t *);
|
||||
__extern int caca_refresh_display(caca_display_t *);
|
||||
__extern int caca_set_display_time(caca_display_t *, int);
|
||||
__extern int caca_get_display_time(caca_display_t const *);
|
||||
__extern int caca_get_display_width(caca_display_t const *);
|
||||
__extern int caca_get_display_height(caca_display_t const *);
|
||||
__extern int caca_set_display_title(caca_display_t *, char const *);
|
||||
__extern int caca_set_mouse(caca_display_t *, int);
|
||||
__extern int caca_set_cursor(caca_display_t *, int);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_event libcaca event handling
|
||||
*
|
||||
* These functions handle user events such as keyboard input and mouse
|
||||
* clicks.
|
||||
*
|
||||
* @{ */
|
||||
__extern int caca_get_event(caca_display_t *, int, caca_event_t *, int);
|
||||
__extern int caca_get_mouse_x(caca_display_t const *);
|
||||
__extern int caca_get_mouse_y(caca_display_t const *);
|
||||
__extern enum caca_event_type caca_get_event_type(caca_event_t const *);
|
||||
__extern int caca_get_event_key_ch(caca_event_t const *);
|
||||
__extern uint32_t caca_get_event_key_utf32(caca_event_t const *);
|
||||
__extern int caca_get_event_key_utf8(caca_event_t const *, char *);
|
||||
__extern int caca_get_event_mouse_button(caca_event_t const *);
|
||||
__extern int caca_get_event_mouse_x(caca_event_t const *);
|
||||
__extern int caca_get_event_mouse_y(caca_event_t const *);
|
||||
__extern int caca_get_event_resize_width(caca_event_t const *);
|
||||
__extern int caca_get_event_resize_height(caca_event_t const *);
|
||||
/* @} */
|
||||
|
||||
/** \defgroup caca_process libcaca process management
|
||||
*
|
||||
* These functions help with various process handling tasks such as
|
||||
* option parsing, DLL injection.
|
||||
*
|
||||
* @{ */
|
||||
__extern int caca_optind;
|
||||
__extern char *caca_optarg;
|
||||
__extern int caca_getopt(int, char * const[], char const *,
|
||||
struct caca_option const *, int *);
|
||||
/* @} */
|
||||
|
||||
/** \brief DOS colours
|
||||
*
|
||||
* This enum lists the colour values for the DOS conio.h compatibility
|
||||
* layer.
|
||||
*/
|
||||
enum CACA_CONIO_COLORS
|
||||
{
|
||||
CACA_CONIO_BLINK = 128,
|
||||
CACA_CONIO_BLACK = 0,
|
||||
CACA_CONIO_BLUE = 1,
|
||||
CACA_CONIO_GREEN = 2,
|
||||
CACA_CONIO_CYAN = 3,
|
||||
CACA_CONIO_RED = 4,
|
||||
CACA_CONIO_MAGENTA = 5,
|
||||
CACA_CONIO_BROWN = 6,
|
||||
CACA_CONIO_LIGHTGRAY = 7,
|
||||
CACA_CONIO_DARKGRAY = 8,
|
||||
CACA_CONIO_LIGHTBLUE = 9,
|
||||
CACA_CONIO_LIGHTGREEN = 10,
|
||||
CACA_CONIO_LIGHTCYAN = 11,
|
||||
CACA_CONIO_LIGHTRED = 12,
|
||||
CACA_CONIO_LIGHTMAGENTA = 13,
|
||||
CACA_CONIO_YELLOW = 14,
|
||||
CACA_CONIO_WHITE = 15,
|
||||
};
|
||||
|
||||
/** \brief DOS cursor modes
|
||||
*
|
||||
* This enum lists the cursor mode values for the DOS conio.h compatibility
|
||||
* layer.
|
||||
*/
|
||||
enum CACA_CONIO_CURSOR
|
||||
{
|
||||
CACA_CONIO__NOCURSOR = 0,
|
||||
CACA_CONIO__SOLIDCURSOR = 1,
|
||||
CACA_CONIO__NORMALCURSOR = 2,
|
||||
};
|
||||
|
||||
/** \brief DOS video modes
|
||||
*
|
||||
* This enum lists the video mode values for the DOS conio.h compatibility
|
||||
* layer.
|
||||
*/
|
||||
enum CACA_CONIO_MODE
|
||||
{
|
||||
CACA_CONIO_LASTMODE = -1,
|
||||
CACA_CONIO_BW40 = 0,
|
||||
CACA_CONIO_C40 = 1,
|
||||
CACA_CONIO_BW80 = 2,
|
||||
CACA_CONIO_C80 = 3,
|
||||
CACA_CONIO_MONO = 7,
|
||||
CACA_CONIO_C4350 = 64,
|
||||
};
|
||||
|
||||
/** \brief DOS text area information
|
||||
*
|
||||
* This structure stores text area information for the DOS conio.h
|
||||
* compatibility layer.
|
||||
*/
|
||||
struct caca_conio_text_info
|
||||
{
|
||||
unsigned char winleft; /**< left window coordinate */
|
||||
unsigned char wintop; /**< top window coordinate */
|
||||
unsigned char winright; /**< right window coordinate */
|
||||
unsigned char winbottom; /**< bottom window coordinate */
|
||||
unsigned char attribute; /**< text attribute */
|
||||
unsigned char normattr; /**< normal attribute */
|
||||
unsigned char currmode; /**< current video mode:
|
||||
BW40, BW80, C40, C80, or C4350 */
|
||||
unsigned char screenheight; /**< text screen's height */
|
||||
unsigned char screenwidth; /**< text screen's width */
|
||||
unsigned char curx; /**< x-coordinate in current window */
|
||||
unsigned char cury; /**< y-coordinate in current window */
|
||||
};
|
||||
|
||||
/** \brief DOS direct video control */
|
||||
__extern int caca_conio_directvideo;
|
||||
|
||||
/** \brief DOS scrolling control */
|
||||
__extern int caca_conio__wscroll;
|
||||
|
||||
/** \defgroup conio libcaca DOS conio.h compatibility layer
|
||||
*
|
||||
* These functions implement DOS-like functions for high-level text
|
||||
* operations.
|
||||
*
|
||||
* @{ */
|
||||
__extern char * caca_conio_cgets(char *str);
|
||||
__extern void caca_conio_clreol(void);
|
||||
__extern void caca_conio_clrscr(void);
|
||||
__extern int caca_conio_cprintf(const char *format, ...);
|
||||
__extern int caca_conio_cputs(const char *str);
|
||||
__extern int caca_conio_cscanf(char *format, ...);
|
||||
__extern void caca_conio_delay(unsigned int);
|
||||
__extern void caca_conio_delline(void);
|
||||
__extern int caca_conio_getch(void);
|
||||
__extern int caca_conio_getche(void);
|
||||
__extern char * caca_conio_getpass(const char *prompt);
|
||||
__extern int caca_conio_gettext(int left, int top, int right, int bottom,
|
||||
void *destin);
|
||||
__extern void caca_conio_gettextinfo(struct caca_conio_text_info *r);
|
||||
__extern void caca_conio_gotoxy(int x, int y);
|
||||
__extern void caca_conio_highvideo(void);
|
||||
__extern void caca_conio_insline(void);
|
||||
__extern int caca_conio_kbhit(void);
|
||||
__extern void caca_conio_lowvideo(void);
|
||||
__extern int caca_conio_movetext(int left, int top, int right, int bottom,
|
||||
int destleft, int desttop);
|
||||
__extern void caca_conio_normvideo(void);
|
||||
__extern void caca_conio_nosound(void);
|
||||
__extern int caca_conio_printf(const char *format, ...);
|
||||
__extern int caca_conio_putch(int ch);
|
||||
__extern int caca_conio_puttext(int left, int top, int right, int bottom,
|
||||
void *destin);
|
||||
__extern void caca_conio__setcursortype(int cur_t);
|
||||
__extern void caca_conio_sleep(unsigned int);
|
||||
__extern void caca_conio_sound(unsigned int);
|
||||
__extern void caca_conio_textattr(int newattr);
|
||||
__extern void caca_conio_textbackground(int newcolor);
|
||||
__extern void caca_conio_textcolor(int newcolor);
|
||||
__extern void caca_conio_textmode(int newmode);
|
||||
__extern int caca_conio_ungetch(int ch);
|
||||
__extern int caca_conio_wherex(void);
|
||||
__extern int caca_conio_wherey(void);
|
||||
__extern void caca_conio_window(int left, int top, int right, int bottom);
|
||||
/* @} */
|
||||
|
||||
#if !defined(_DOXYGEN_SKIP_ME)
|
||||
/* Legacy stuff from beta versions, will probably disappear in 1.0 */
|
||||
|
||||
# if defined __GNUC__ && __GNUC__ >= 3
|
||||
# define CACA_DEPRECATED __attribute__ ((__deprecated__))
|
||||
# else
|
||||
# define CACA_DEPRECATED
|
||||
# endif
|
||||
|
||||
# if defined __GNUC__ && __GNUC__ > 3 && !defined __APPLE__
|
||||
# define CACA_ALIAS(x) __attribute__ ((weak, alias(#x)))
|
||||
# else
|
||||
# define CACA_ALIAS(x)
|
||||
# endif
|
||||
|
||||
# if defined __GNUC__ && __GNUC__ > 3
|
||||
# define CACA_WEAK __attribute__ ((weak))
|
||||
# else
|
||||
# define CACA_WEAK
|
||||
# endif
|
||||
|
||||
|
||||
/* Aliases from old libcaca functions */
|
||||
#if !defined _WIN32 || !defined __GNUC__
|
||||
__extern ssize_t caca_import_memory(caca_canvas_t *, void const *, size_t,
|
||||
char const *) CACA_DEPRECATED;
|
||||
__extern ssize_t caca_import_file(caca_canvas_t *, char const *,
|
||||
char const *) CACA_DEPRECATED;
|
||||
__extern void *caca_export_memory(caca_canvas_t const *, char const *,
|
||||
size_t *) CACA_DEPRECATED;
|
||||
#endif
|
||||
|
||||
# if !defined __LIBCACA__
|
||||
# define caca_get_cursor_x caca_wherex
|
||||
# define caca_get_cursor_y caca_wherey
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef __extern
|
||||
|
||||
#endif /* __CACA_H__ */
|
|
@ -0,0 +1,13 @@
|
|||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: caca
|
||||
Description: Colour ASCII-Art library
|
||||
Version: @VERSION@
|
||||
Requires:
|
||||
Conflicts:
|
||||
Libs: -L${libdir} -lcaca
|
||||
Libs.private: @ZLIB_LIBS@
|
||||
Cflags: -I${includedir}
|
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2002-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains glue code for applications using the pre-1.0
|
||||
* libcaca API.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "caca0.h"
|
||||
|
||||
/* These variables are needed to emulate old non-thread safe behaviour */
|
||||
caca_canvas_t *__caca0_cv = NULL;
|
||||
caca_display_t *__caca0_dp = NULL;
|
||||
unsigned char __caca0_fg = CACA_LIGHTGRAY;
|
||||
unsigned char __caca0_bg = CACA_BLACK;
|
||||
char __caca0_utf8[2] = " ";
|
||||
|
||||
/* These functions are needed, too */
|
||||
int __caca0_init(void);
|
||||
void __caca0_end(void);
|
||||
unsigned int __caca0_get_event(unsigned int, int);
|
||||
unsigned int __caca0_sqrt(unsigned int);
|
||||
int __caca0_get_feature(int);
|
||||
void __caca0_set_feature(int);
|
||||
char const *__caca0_get_feature_name(int);
|
||||
caca_canvas_t *__caca0_load_sprite(char const *);
|
||||
caca_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
|
||||
unsigned int, unsigned int, unsigned long int, unsigned long int,
|
||||
unsigned long int, unsigned long int);
|
||||
void __caca0_free_bitmap(caca_dither_t *);
|
||||
extern char const *__caca0_get_color_name(unsigned char);
|
||||
|
||||
/* Emulation functions */
|
||||
int __caca0_init(void)
|
||||
{
|
||||
__caca0_cv = caca_create_canvas(0, 0);
|
||||
if(!__caca0_cv)
|
||||
return -1;
|
||||
__caca0_dp = caca_create_display(__caca0_cv);
|
||||
if(!__caca0_dp)
|
||||
{
|
||||
caca_free_canvas(__caca0_cv);
|
||||
__caca0_cv = NULL;
|
||||
return -1;
|
||||
}
|
||||
__caca0_fg = CACA_LIGHTGRAY;
|
||||
__caca0_bg = CACA_BLACK;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void __caca0_end(void)
|
||||
{
|
||||
caca_free_display(__caca0_dp);
|
||||
__caca0_dp = NULL;
|
||||
caca_free_canvas(__caca0_cv);
|
||||
__caca0_cv = NULL;
|
||||
}
|
||||
|
||||
unsigned int __caca0_get_event(unsigned int m, int t)
|
||||
{
|
||||
caca_event_t ev;
|
||||
int ret;
|
||||
|
||||
ret = caca_get_event(__caca0_dp, (m >> 24) & 0x7f, &ev, t);
|
||||
if(!ret)
|
||||
return 0x00000000;
|
||||
|
||||
switch(caca_get_event_type(&ev))
|
||||
{
|
||||
case CACA_EVENT_KEY_PRESS:
|
||||
return 0x01000000 | caca_get_event_key_ch(&ev);
|
||||
case CACA_EVENT_KEY_RELEASE:
|
||||
return 0x02000000 | caca_get_event_key_ch(&ev);
|
||||
case CACA_EVENT_MOUSE_PRESS:
|
||||
return 0x04000000 | caca_get_event_mouse_button(&ev);
|
||||
case CACA_EVENT_MOUSE_RELEASE:
|
||||
return 0x08000000 | caca_get_event_mouse_button(&ev);
|
||||
case CACA_EVENT_MOUSE_MOTION:
|
||||
return 0x10000000 | ((caca_get_event_mouse_x(&ev) & 0xfff) << 12)
|
||||
| (caca_get_event_mouse_y(&ev) & 0xfff);
|
||||
case CACA_EVENT_RESIZE:
|
||||
return 0x20000000;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0x00000000;
|
||||
}
|
||||
|
||||
unsigned int __caca0_sqrt(unsigned int a)
|
||||
{
|
||||
if(a == 0)
|
||||
return 0;
|
||||
|
||||
if(a < 1000000000)
|
||||
{
|
||||
unsigned int x = a < 10 ? 1
|
||||
: a < 1000 ? 10
|
||||
: a < 100000 ? 100
|
||||
: a < 10000000 ? 1000
|
||||
: 10000;
|
||||
|
||||
/* Newton's method. Three iterations would be more than enough. */
|
||||
x = (x * x + a) / x / 2;
|
||||
x = (x * x + a) / x / 2;
|
||||
x = (x * x + a) / x / 2;
|
||||
x = (x * x + a) / x / 2;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
return 2 * __caca0_sqrt(a / 4);
|
||||
}
|
||||
|
||||
static char const *features[] =
|
||||
{
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
|
||||
NULL, "16", "full16", NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
|
||||
NULL, "none", "prefilter", NULL, NULL, NULL, NULL, NULL,
|
||||
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
|
||||
|
||||
NULL, "none", "ordered2", "ordered4", "ordered8", "random"
|
||||
};
|
||||
|
||||
static caca_dither_t **bitmaps = NULL;
|
||||
static unsigned int nbitmaps = 0;
|
||||
|
||||
static int background = 0x12;
|
||||
static int antialiasing = 0x22;
|
||||
static int dithering = 0x33;
|
||||
|
||||
int __caca0_get_feature(int feature)
|
||||
{
|
||||
if(feature == 0x10)
|
||||
return background;
|
||||
if(feature == 0x20)
|
||||
return antialiasing;
|
||||
if(feature == 0x30)
|
||||
return dithering;
|
||||
return 0xffff; /* CACA_FEATURE_UNKNOWN */
|
||||
}
|
||||
|
||||
void __caca0_set_feature(int feature)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
switch(feature)
|
||||
{
|
||||
case 0x10: feature = 0x12; /* CACA_BACKGROUND_SOLID */
|
||||
case 0x11: case 0x12:
|
||||
background = feature;
|
||||
for(i = 0; i < nbitmaps; i++)
|
||||
caca_set_dither_color(bitmaps[i], features[feature]);
|
||||
break;
|
||||
|
||||
case 0x20: feature = 0x22; /* CACA_ANTIALIASING_PREFILTER */
|
||||
case 0x21: case 0x22:
|
||||
antialiasing = feature;
|
||||
for(i = 0; i < nbitmaps; i++)
|
||||
caca_set_dither_antialias(bitmaps[i], features[feature]);
|
||||
break;
|
||||
|
||||
case 0x30: feature = 0x33; /* CACA_DITHERING_ORDERED4 */
|
||||
case 0x31: case 0x32: case 0x33: case 0x34: case 0x35:
|
||||
dithering = feature;
|
||||
for(i = 0; i < nbitmaps; i++)
|
||||
caca_set_dither_algorithm(bitmaps[i], features[feature]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char const *__caca0_get_feature_name(int feature)
|
||||
{
|
||||
switch(feature)
|
||||
{
|
||||
case 0x11: return "black background";
|
||||
case 0x12: return "solid background";
|
||||
|
||||
case 0x21: return "no antialiasing";
|
||||
case 0x22: return "prefilter antialiasing";
|
||||
|
||||
case 0x31: return "no dithering";
|
||||
case 0x32: return "2x2 ordered dithering";
|
||||
case 0x33: return "4x4 ordered dithering";
|
||||
case 0x34: return "8x8 ordered dithering";
|
||||
case 0x35: return "random dithering";
|
||||
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
caca_canvas_t *__caca0_load_sprite(char const *file)
|
||||
{
|
||||
caca_canvas_t *cv;
|
||||
|
||||
cv = caca_create_canvas(0, 0);;
|
||||
if(caca_import_canvas_from_file(cv, file, "") < 0)
|
||||
{
|
||||
caca_free_canvas(cv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cv;
|
||||
}
|
||||
|
||||
caca_dither_t *__caca0_create_bitmap(unsigned int bpp, unsigned int w,
|
||||
unsigned int h, unsigned int pitch,
|
||||
unsigned long int r, unsigned long int g,
|
||||
unsigned long int b, unsigned long int a)
|
||||
{
|
||||
caca_dither_t *d;
|
||||
|
||||
d = caca_create_dither(bpp, w, h, pitch, r, g, b, a);
|
||||
if(!d)
|
||||
return NULL;
|
||||
|
||||
caca_set_dither_color(d, features[background]);
|
||||
caca_set_dither_antialias(d, features[antialiasing]);
|
||||
caca_set_dither_algorithm(d, features[dithering]);
|
||||
|
||||
/* Store bitmap in our list */
|
||||
nbitmaps++;
|
||||
bitmaps = realloc(bitmaps, nbitmaps * (sizeof(caca_dither_t *)));
|
||||
bitmaps[nbitmaps - 1] = d;
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void __caca0_free_bitmap(caca_dither_t *d)
|
||||
{
|
||||
unsigned int i, found = 0;
|
||||
|
||||
caca_free_dither(d);
|
||||
|
||||
/* Remove bitmap from our list */
|
||||
for(i = 0; i + 1 < nbitmaps; i++)
|
||||
{
|
||||
if(bitmaps[i] == d)
|
||||
found = 1;
|
||||
if(found)
|
||||
bitmaps[i] = bitmaps[i + 1];
|
||||
}
|
||||
|
||||
nbitmaps--;
|
||||
}
|
||||
|
||||
char const *__caca0_get_color_name(unsigned char color)
|
||||
{
|
||||
static char const *color_names[] =
|
||||
{
|
||||
"black",
|
||||
"blue",
|
||||
"green",
|
||||
"cyan",
|
||||
"red",
|
||||
"magenta",
|
||||
"brown",
|
||||
"light gray",
|
||||
"dark gray",
|
||||
"light blue",
|
||||
"light green",
|
||||
"light cyan",
|
||||
"light red",
|
||||
"light magenta",
|
||||
"yellow",
|
||||
"white",
|
||||
};
|
||||
|
||||
if(color > 15)
|
||||
return "unknown";
|
||||
|
||||
return color_names[(unsigned int)color];
|
||||
}
|
||||
|
|
@ -0,0 +1,210 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2018 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header contains glue code for applications using the pre-1.0
|
||||
* libcaca API.
|
||||
*/
|
||||
|
||||
#ifndef __CACA0_H__
|
||||
#define __CACA0_H__
|
||||
|
||||
#include <caca.h>
|
||||
|
||||
#undef __extern
|
||||
#if defined _DOXYGEN_SKIP_ME
|
||||
#elif defined _WIN32 && defined __LIBCACA__ && defined DLL_EXPORT
|
||||
# define __extern extern __declspec(dllexport)
|
||||
#elif defined _WIN32 && !defined __LIBCACA__
|
||||
# define __extern extern __declspec(dllimport)
|
||||
#elif defined CACA_ENABLE_VISIBILITY
|
||||
# define __extern extern __attribute__((visibility("default")))
|
||||
#else
|
||||
# define __extern extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Function emulation */
|
||||
__extern int __caca0_init(void);
|
||||
__extern void __caca0_end(void);
|
||||
__extern unsigned int __caca0_get_event(unsigned int, int);
|
||||
__extern unsigned int __caca0_sqrt(unsigned int);
|
||||
__extern int __caca0_get_feature(int);
|
||||
__extern void __caca0_set_feature(int);
|
||||
__extern char const *__caca0_get_feature_name(int);
|
||||
__extern caca_canvas_t *__caca0_load_sprite(char const *);
|
||||
__extern caca_dither_t *__caca0_create_bitmap(unsigned int, unsigned int,
|
||||
unsigned int, unsigned int, unsigned long int, unsigned long int,
|
||||
unsigned long int, unsigned long int);
|
||||
__extern void __caca0_free_bitmap(caca_dither_t *);
|
||||
__extern char const *__caca0_get_color_name(unsigned char);
|
||||
|
||||
/* These variables are needed to emulate old non-thread safe behaviour */
|
||||
__extern caca_canvas_t *__caca0_cv;
|
||||
__extern caca_display_t *__caca0_dp;
|
||||
__extern unsigned char __caca0_fg;
|
||||
__extern unsigned char __caca0_bg;
|
||||
|
||||
/* This enum still exists in libcaca 1.x, thus cannot be redefined */
|
||||
#define CACA_COLOR_BLACK CACA_BLACK
|
||||
#define CACA_COLOR_BLUE CACA_BLUE
|
||||
#define CACA_COLOR_GREEN CACA_GREEN
|
||||
#define CACA_COLOR_CYAN CACA_CYAN
|
||||
#define CACA_COLOR_RED CACA_RED
|
||||
#define CACA_COLOR_MAGENTA CACA_MAGENTA
|
||||
#define CACA_COLOR_BROWN CACA_BROWN
|
||||
#define CACA_COLOR_LIGHTGRAY CACA_LIGHTGRAY
|
||||
#define CACA_COLOR_DARKGRAY CACA_DARKGRAY
|
||||
#define CACA_COLOR_LIGHTBLUE CACA_LIGHTBLUE
|
||||
#define CACA_COLOR_LIGHTGREEN CACA_LIGHTGREEN
|
||||
#define CACA_COLOR_LIGHTCYAN CACA_LIGHTCYAN
|
||||
#define CACA_COLOR_LIGHTRED CACA_LIGHTRED
|
||||
#define CACA_COLOR_LIGHTMAGENTA CACA_LIGHTMAGENTA
|
||||
#define CACA_COLOR_YELLOW CACA_YELLOW
|
||||
#define CACA_COLOR_WHITE CACA_WHITE
|
||||
|
||||
/* These enums and macros changed names or values */
|
||||
enum caca_feature
|
||||
{
|
||||
CACA_BACKGROUND = 0x10,
|
||||
CACA_BACKGROUND_BLACK = 0x11,
|
||||
CACA_BACKGROUND_SOLID = 0x12,
|
||||
#define CACA_BACKGROUND_MIN 0x11
|
||||
#define CACA_BACKGROUND_MAX 0x12
|
||||
CACA_ANTIALIASING = 0x20,
|
||||
CACA_ANTIALIASING_NONE = 0x21,
|
||||
CACA_ANTIALIASING_PREFILTER = 0x22,
|
||||
#define CACA_ANTIALIASING_MIN 0x21
|
||||
#define CACA_ANTIALIASING_MAX 0x22
|
||||
CACA_DITHERING = 0x30,
|
||||
CACA_DITHERING_NONE = 0x31,
|
||||
CACA_DITHERING_ORDERED2 = 0x32,
|
||||
CACA_DITHERING_ORDERED4 = 0x33,
|
||||
CACA_DITHERING_ORDERED8 = 0x34,
|
||||
CACA_DITHERING_RANDOM = 0x35,
|
||||
#define CACA_DITHERING_MIN 0x31
|
||||
#define CACA_DITHERING_MAX 0x35
|
||||
CACA_FEATURE_UNKNOWN = 0xffff
|
||||
};
|
||||
|
||||
#if ! defined __LIBCACA__
|
||||
|
||||
/* This enum still exists in libcaca 1.x, thus cannot be redefined */
|
||||
#define CACA_EVENT_NONE 0x00000000
|
||||
#define CACA_EVENT_KEY_PRESS 0x01000000
|
||||
#define CACA_EVENT_KEY_RELEASE 0x02000000
|
||||
#define CACA_EVENT_MOUSE_PRESS 0x04000000
|
||||
#define CACA_EVENT_MOUSE_RELEASE 0x08000000
|
||||
#define CACA_EVENT_MOUSE_MOTION 0x10000000
|
||||
#define CACA_EVENT_RESIZE 0x20000000
|
||||
#define CACA_EVENT_ANY 0xff000000
|
||||
|
||||
/* Backwards compatibility macros for even older shit */
|
||||
#define caca_dithering caca_feature
|
||||
#define caca_set_dithering caca_set_feature
|
||||
#define caca_get_dithering_name caca_get_feature_name
|
||||
#define CACA_DITHER_NONE CACA_DITHERING_NONE
|
||||
#define CACA_DITHER_ORDERED CACA_DITHERING_ORDERED8
|
||||
#define CACA_DITHER_RANDOM CACA_DITHERING_RANDOM
|
||||
|
||||
/* Macros to redefine all the shit */
|
||||
#define caca_init __caca0_init
|
||||
#define caca_set_delay(x) caca_set_display_time(__caca0_dp, x)
|
||||
#define caca_get_feature __caca0_get_feature
|
||||
#define caca_set_feature __caca0_set_feature
|
||||
#define caca_get_feature_name __caca0_get_feature_name
|
||||
#define caca_get_rendertime() caca_get_display_time(__caca0_dp)
|
||||
#define caca_get_width() caca_get_canvas_width(__caca0_cv)
|
||||
#define caca_get_height() caca_get_canvas_height(__caca0_cv)
|
||||
#define caca_set_window_title(s) caca_set_display_title(__caca0_dp, s)
|
||||
#define caca_get_window_width() caca_get_display_width(__caca0_dp)
|
||||
#define caca_get_window_height() caca_get_display_height(__caca0_dp)
|
||||
#define caca_refresh() caca_refresh_display(__caca0_dp)
|
||||
#define caca_end __caca0_end
|
||||
|
||||
#define caca_get_event(x) __caca0_get_event(x, 0)
|
||||
#define caca_wait_event(x) __caca0_get_event(x, -1)
|
||||
#define caca_get_mouse_x() caca_get_mouse_x(__caca0_dp)
|
||||
#define caca_get_mouse_y() caca_get_mouse_y(__caca0_dp)
|
||||
|
||||
#define caca_set_color(x, y) \
|
||||
(__caca0_fg = (x), __caca0_bg = (y), caca_set_color_ansi(__caca0_cv, x, y))
|
||||
#define caca_get_fg_color() __caca0_fg
|
||||
#define caca_get_bg_color() __caca0_bg
|
||||
#define caca_get_color_name __caca0_get_color_name
|
||||
#define caca_putchar(x, y, c) caca_put_char(__caca0_cv, x, y, c)
|
||||
#define caca_putstr(x, y, s) caca_put_str(__caca0_cv, x, y, s)
|
||||
#define caca_printf(x, y, f, z...) caca_printf(__caca0_cv, x, y, f, ##z)
|
||||
#define caca_clear() caca_clear_canvas(__caca0_cv)
|
||||
|
||||
#define caca_draw_line(x, y, z, t, c) \
|
||||
caca_draw_line(__caca0_cv, x, y, z, t, c)
|
||||
#define caca_draw_polyline(x, y, z, c) \
|
||||
caca_draw_polyline(__caca0_cv, x, y, z, c)
|
||||
#define caca_draw_thin_line(x, y, z, t) \
|
||||
caca_draw_thin_line(__caca0_cv, x, y, z, t)
|
||||
#define caca_draw_thin_polyline(x, y, z) \
|
||||
caca_draw_thin_polyline(__caca0_cv, x, y, z)
|
||||
#define caca_draw_circle(x, y, z, c) \
|
||||
caca_draw_circle(__caca0_cv, x, y, z, c)
|
||||
#define caca_draw_ellipse(x, y, z, t, c) \
|
||||
caca_draw_ellipse(__caca0_cv, x, y, z, t, c)
|
||||
#define caca_draw_thin_ellipse(x, y, z, t) \
|
||||
caca_draw_thin_ellipse(__caca0_cv, x, y, z, t)
|
||||
#define caca_fill_ellipse(x, y, z, t, c) \
|
||||
caca_fill_ellipse(__caca0_cv, x, y, z, t, c)
|
||||
#define caca_draw_box(x, y, z, t, c) \
|
||||
caca_draw_box(__caca0_cv, x, y, z, t, c)
|
||||
#define caca_draw_thin_box(x, y, z, t) \
|
||||
caca_draw_thin_box(__caca0_cv, x, y, z, t)
|
||||
#define caca_fill_box(x, y, z, t, c) \
|
||||
caca_fill_box(__caca0_cv, x, y, z, t, c)
|
||||
#define caca_draw_triangle(x, y, z, t, u, v, c) \
|
||||
caca_draw_triangle(__caca0_cv, x, y, z, t, u, v, c)
|
||||
#define caca_draw_thin_triangle(x, y, z, t, u, v) \
|
||||
caca_draw_thin_triangle(__caca0_cv, x, y, z, t, u, v)
|
||||
#define caca_fill_triangle(x, y, z, t, u, v, c) \
|
||||
caca_fill_triangle(__caca0_cv, x, y, z, t, u, v, c)
|
||||
|
||||
#define caca_rand(a, b) caca_rand(a, (b)+1)
|
||||
#define caca_sqrt __caca0_sqrt
|
||||
|
||||
#define caca_sprite caca_canvas
|
||||
#define caca_load_sprite __caca0_load_sprite
|
||||
#define caca_get_sprite_frames(c) 1
|
||||
#define caca_get_sprite_width(c, f) caca_get_canvas_width(c)
|
||||
#define caca_get_sprite_height(c, f) caca_get_canvas_height(c)
|
||||
#define caca_get_sprite_dx(c, f) 0
|
||||
#define caca_get_sprite_dx(c, f) 0
|
||||
#define caca_draw_sprite(x, y, c, f) caca_blit(__caca0_cv, x, y, c, NULL)
|
||||
#define caca_free_sprite caca_free_canvas
|
||||
|
||||
#define caca_bitmap caca_dither
|
||||
#define caca_create_bitmap __caca0_create_bitmap
|
||||
#define caca_set_bitmap_palette caca_set_dither_palette
|
||||
#define caca_draw_bitmap(x, y, z, t, b, p) \
|
||||
caca_dither_bitmap(__caca0_cv, x, y, z, t, b, p)
|
||||
#define caca_free_bitmap __caca0_free_bitmap
|
||||
|
||||
#endif /* ! defined __LIBCACA__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef __extern
|
||||
|
||||
#endif /* __CACA0_H__ */
|
|
@ -0,0 +1,570 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2002-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains a full conio.h reimplementation. More information
|
||||
* on conio.h can be found on http://poli.cs.vsb.cz/c/help/conio.htm
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
#include "caca_conio.h"
|
||||
|
||||
static caca_canvas_t *cv;
|
||||
static caca_display_t *dp;
|
||||
|
||||
static caca_timer_t refresh_timer = {0, 0};
|
||||
static uint64_t refresh_ticks;
|
||||
|
||||
static int unget_ch = -1;
|
||||
static int kbhit_ch = -1;
|
||||
static char pass_buffer[8 + 1];
|
||||
|
||||
static void conio_init(void);
|
||||
static void conio_refresh(void);
|
||||
static void conio_fini(void);
|
||||
|
||||
int caca_conio_directvideo = 0;
|
||||
int caca_conio__wscroll = 1;
|
||||
|
||||
/** \brief DOS conio.h cgets() equivalent */
|
||||
char * caca_conio_cgets(char *str)
|
||||
{
|
||||
int len = ((uint8_t *)str)[0];
|
||||
int pos = 0;
|
||||
|
||||
conio_init();
|
||||
|
||||
while (pos < len)
|
||||
{
|
||||
int ch = caca_conio_getch();
|
||||
if (ch == '\n' || ch == '\r')
|
||||
break;
|
||||
str[2 + pos] = (char)(uint8_t)ch;
|
||||
/* FIXME: handle scrolling */
|
||||
caca_put_char(cv, caca_wherex(cv), caca_wherey(cv), ch);
|
||||
caca_gotoxy(cv, caca_wherex(cv) + 1, caca_wherey(cv));
|
||||
pos++;
|
||||
}
|
||||
|
||||
str[2 + pos] = '\0';
|
||||
str[1] = (char)(uint8_t)pos;
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return str + 2;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h clreol() equivalent */
|
||||
void caca_conio_clreol(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* FIXME: must work within the currently active text window */
|
||||
caca_fill_box(cv, caca_wherex(cv), caca_wherey(cv),
|
||||
caca_get_canvas_width(cv), caca_wherey(cv), ' ');
|
||||
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h clrscr() equivalent */
|
||||
void caca_conio_clrscr(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* FIXME: must work within the currently active text window */
|
||||
caca_clear_canvas(cv);
|
||||
caca_gotoxy(cv, 0, 0);
|
||||
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h cprintf() equivalent */
|
||||
int caca_conio_cprintf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
conio_init();
|
||||
|
||||
/* FIXME: handle scrolling */
|
||||
va_start(args, format);
|
||||
ret = caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args);
|
||||
va_end(args);
|
||||
|
||||
caca_gotoxy(cv, caca_wherex(cv) + ret, caca_wherey(cv));
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h cputs() equivalent */
|
||||
int caca_conio_cputs(const char *str)
|
||||
{
|
||||
int ch;
|
||||
|
||||
conio_init();
|
||||
|
||||
while ((ch = (uint8_t)*str++))
|
||||
{
|
||||
/* FIXME: handle windows, scrolling, '\n' and '\r' */
|
||||
caca_put_char(cv, caca_wherex(cv), caca_wherey(cv), ch);
|
||||
caca_gotoxy(cv, caca_wherex(cv) + 1, caca_wherey(cv));
|
||||
}
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/** \brief DOS stdio.h cscanf() equivalent */
|
||||
int caca_conio_cscanf(char *format, ...)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief DOS dos.h delay() equivalent */
|
||||
void caca_conio_delay(unsigned int milliseconds)
|
||||
{
|
||||
int64_t usec = (int64_t)milliseconds * 1000;
|
||||
caca_timer_t timer = {0, 0};
|
||||
|
||||
conio_init();
|
||||
|
||||
_caca_getticks(&timer);
|
||||
|
||||
/* Refresh screen as long as we have enough time */
|
||||
while(usec > 5000)
|
||||
{
|
||||
conio_refresh();
|
||||
_caca_sleep(5000);
|
||||
usec -= _caca_getticks(&timer);
|
||||
}
|
||||
|
||||
if(usec > 0)
|
||||
_caca_sleep(usec);
|
||||
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h delline() equivalent */
|
||||
void caca_conio_delline(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h getch() equivalent */
|
||||
int caca_conio_getch(void)
|
||||
{
|
||||
caca_event_t ev;
|
||||
int ret;
|
||||
|
||||
conio_init();
|
||||
|
||||
if(unget_ch >= 0)
|
||||
{
|
||||
int tmp = unget_ch;
|
||||
unget_ch = -1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
if(kbhit_ch >= 0)
|
||||
{
|
||||
int tmp = kbhit_ch;
|
||||
kbhit_ch = -1;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
while(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 1000) == 0)
|
||||
conio_refresh();
|
||||
|
||||
ret = caca_get_event_key_ch(&ev);
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h getche() equivalent */
|
||||
int caca_conio_getche(void)
|
||||
{
|
||||
/* conio_init() is called here. */
|
||||
int tmp = caca_conio_getch();
|
||||
/* conio_refresh() is called here. */
|
||||
caca_conio_printf("%c", tmp);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h getpass() equivalent */
|
||||
char * caca_conio_getpass(const char *prompt)
|
||||
{
|
||||
int pos = 0;
|
||||
|
||||
conio_init();
|
||||
|
||||
while (pos < 8)
|
||||
{
|
||||
int ch = caca_conio_getch();
|
||||
if (ch == '\n' || ch == '\r')
|
||||
break;
|
||||
pass_buffer[pos] = (char)(uint8_t)ch;
|
||||
pos++;
|
||||
}
|
||||
|
||||
pass_buffer[pos] = '\0';
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return pass_buffer;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h gettext() equivalent */
|
||||
int caca_conio_gettext(int left, int top, int right, int bottom, void *destin)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h gettextinfo() equivalent */
|
||||
void caca_conio_gettextinfo(struct caca_conio_text_info *r)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h gotoxy() equivalent */
|
||||
void caca_conio_gotoxy(int x, int y)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
caca_gotoxy(cv, x - 1, y - 1);
|
||||
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h highvideo() equivalent */
|
||||
void caca_conio_highvideo(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h insline() equivalent */
|
||||
void caca_conio_insline(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h kbhit() equivalent */
|
||||
int caca_conio_kbhit(void)
|
||||
{
|
||||
static caca_timer_t timer = {0, 0};
|
||||
static int last_failed = 0;
|
||||
caca_event_t ev;
|
||||
|
||||
conio_init();
|
||||
|
||||
/* If last call failed and this call is made less than 100µs
|
||||
* afterwards, we assume the caller is in a busy loop and we
|
||||
* delay it slightly to avoid resource leakage. */
|
||||
if(last_failed && _caca_getticks(&timer) < 100)
|
||||
{
|
||||
_caca_sleep(1000);
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
last_failed = 0;
|
||||
|
||||
if(kbhit_ch >= 0)
|
||||
return 1;
|
||||
|
||||
if(caca_get_event(dp, CACA_EVENT_KEY_PRESS, &ev, 0))
|
||||
{
|
||||
kbhit_ch = caca_get_event_key_ch(&ev);
|
||||
return 1;
|
||||
}
|
||||
|
||||
last_failed = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h lowvideo() equivalent */
|
||||
void caca_conio_lowvideo(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h movetext() equivalent */
|
||||
int caca_conio_movetext(int left, int top, int right, int bottom,
|
||||
int destleft, int desttop)
|
||||
{
|
||||
caca_canvas_t *tmp;
|
||||
|
||||
conio_init();
|
||||
|
||||
if (left < 1 || top < 1 || left > right || top > bottom
|
||||
|| destleft < 1 || desttop < 1 || destleft > right
|
||||
|| desttop > bottom || right > caca_get_canvas_width(cv)
|
||||
|| bottom > caca_get_canvas_width(cv))
|
||||
return 0;
|
||||
|
||||
tmp = caca_create_canvas(right - left + 1, bottom - top + 1);
|
||||
caca_blit(tmp, 1 - left, 1 - top, cv, NULL);
|
||||
caca_blit(cv, destleft - 1, desttop - 1, tmp, NULL);
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h normvideo() equivalent */
|
||||
void caca_conio_normvideo(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS dos.h nosound() equivalent */
|
||||
void caca_conio_nosound(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS stdio.h printf() equivalent */
|
||||
int caca_conio_printf(const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
int ret;
|
||||
|
||||
conio_init();
|
||||
|
||||
va_start(args, format);
|
||||
ret = caca_vprintf(cv, caca_wherex(cv), caca_wherey(cv), format, args);
|
||||
va_end(args);
|
||||
|
||||
caca_gotoxy(cv, caca_wherex(cv) + ret, caca_wherey(cv));
|
||||
|
||||
conio_refresh();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h putch() equivalent */
|
||||
int caca_conio_putch(int ch)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* FIXME: handle scrolling, windows */
|
||||
caca_put_char(cv, caca_wherex(cv), caca_wherey(cv), ch);
|
||||
caca_gotoxy(cv, caca_wherex(cv) + 1, caca_wherey(cv));
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h puttext() equivalent */
|
||||
int caca_conio_puttext(int left, int top, int right, int bottom, void *destin)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h _setcursortype() equivalent */
|
||||
void caca_conio__setcursortype(int cur_t)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
switch(cur_t)
|
||||
{
|
||||
case CACA_CONIO__NOCURSOR:
|
||||
caca_set_cursor(dp, 0);
|
||||
break;
|
||||
case CACA_CONIO__SOLIDCURSOR:
|
||||
case CACA_CONIO__NORMALCURSOR:
|
||||
caca_set_cursor(dp, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
/** \brief DOS dos.h sleep() equivalent */
|
||||
void caca_conio_sleep(unsigned int seconds)
|
||||
{
|
||||
int64_t usec = (int64_t)seconds * 1000000;
|
||||
caca_timer_t timer = {0, 0};
|
||||
|
||||
conio_init();
|
||||
|
||||
_caca_getticks(&timer);
|
||||
|
||||
/* Refresh screen as long as we have enough time */
|
||||
while(usec > 5000)
|
||||
{
|
||||
conio_refresh();
|
||||
_caca_sleep(5000);
|
||||
usec -= _caca_getticks(&timer);
|
||||
}
|
||||
|
||||
if(usec > 0)
|
||||
_caca_sleep(usec);
|
||||
|
||||
conio_refresh();
|
||||
}
|
||||
|
||||
/** \brief DOS dos.h sound() equivalent */
|
||||
void caca_conio_sound(unsigned int frequency)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h textattr() equivalent */
|
||||
void caca_conio_textattr(int newattr)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h textbackground() equivalent */
|
||||
void caca_conio_textbackground(int newcolor)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
caca_set_color_ansi(cv, caca_attr_to_ansi_fg(caca_get_attr(cv, -1, -1)),
|
||||
newcolor);
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h textcolor() equivalent */
|
||||
void caca_conio_textcolor(int newcolor)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
caca_set_color_ansi(cv, newcolor,
|
||||
caca_attr_to_ansi_bg(caca_get_attr(cv, -1, -1)));
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h textmode() equivalent */
|
||||
void caca_conio_textmode(int newmode)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h ungetch() equivalent */
|
||||
int caca_conio_ungetch(int ch)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
if(unget_ch >= 0)
|
||||
return EOF;
|
||||
|
||||
unget_ch = ch;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h wherex() equivalent */
|
||||
int caca_conio_wherex(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
return caca_wherex(cv) + 1;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h wherey() equivalent */
|
||||
int caca_conio_wherey(void)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
return caca_wherey(cv) + 1;
|
||||
}
|
||||
|
||||
/** \brief DOS conio.h window() equivalent */
|
||||
void caca_conio_window(int left, int top, int right, int bottom)
|
||||
{
|
||||
conio_init();
|
||||
|
||||
/* TODO: implement this function */
|
||||
}
|
||||
|
||||
/* XXX: the following functions are local. */
|
||||
|
||||
static void conio_init(void)
|
||||
{
|
||||
if(!cv)
|
||||
cv = caca_create_canvas(80, 25);
|
||||
if(!dp)
|
||||
{
|
||||
dp = caca_create_display(cv);
|
||||
caca_refresh_display(dp);
|
||||
caca_set_cursor(dp, 1);
|
||||
_caca_getticks(&refresh_timer);
|
||||
refresh_ticks = 0;
|
||||
#if defined HAVE_ATEXIT
|
||||
atexit(conio_fini);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void conio_refresh(void)
|
||||
{
|
||||
refresh_ticks += _caca_getticks(&refresh_timer);
|
||||
if(refresh_ticks > 10000)
|
||||
{
|
||||
caca_refresh_display(dp);
|
||||
_caca_getticks(&refresh_timer);
|
||||
refresh_ticks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void conio_fini(void)
|
||||
{
|
||||
caca_free_display(dp);
|
||||
dp = NULL;
|
||||
caca_free_canvas(cv);
|
||||
cv = NULL;
|
||||
}
|
||||
|
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2002-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header contains a conio.h reimplementation.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_CONIO_H__
|
||||
#define __CACA_CONIO_H__
|
||||
|
||||
/* Since we're going to redefine standard functions, include these
|
||||
* headers first to avoid errors upon later inclusion. */
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include <caca.h>
|
||||
|
||||
#if !defined _DOXYGEN_SKIP_ME && !defined __LIBCACA__
|
||||
# undef BLINK
|
||||
# define BLINK CACA_CONIO_BLINK
|
||||
# undef BLACK
|
||||
# define BLACK CACA_CONIO_BLACK
|
||||
# undef BLUE
|
||||
# define BLUE CACA_CONIO_BLUE
|
||||
# undef GREEN
|
||||
# define GREEN CACA_CONIO_GREEN
|
||||
# undef CYAN
|
||||
# define CYAN CACA_CONIO_CYAN
|
||||
# undef RED
|
||||
# define RED CACA_CONIO_RED
|
||||
# undef MAGENTA
|
||||
# define MAGENTA CACA_CONIO_MAGENTA
|
||||
# undef BROWN
|
||||
# define BROWN CACA_CONIO_BROWN
|
||||
# undef LIGHTGRAY
|
||||
# define LIGHTGRAY CACA_CONIO_LIGHTGRAY
|
||||
# undef DARKGRAY
|
||||
# define DARKGRAY CACA_CONIO_DARKGRAY
|
||||
# undef LIGHTBLUE
|
||||
# define LIGHTBLUE CACA_CONIO_LIGHTBLUE
|
||||
# undef LIGHTGREEN
|
||||
# define LIGHTGREEN CACA_CONIO_LIGHTGREEN
|
||||
# undef LIGHTCYAN
|
||||
# define LIGHTCYAN CACA_CONIO_LIGHTCYAN
|
||||
# undef LIGHTRED
|
||||
# define LIGHTRED CACA_CONIO_LIGHTRED
|
||||
# undef LIGHTMAGENTA
|
||||
# define LIGHTMAGENTA CACA_CONIO_LIGHTMAGENTA
|
||||
# undef YELLOW
|
||||
# define YELLOW CACA_CONIO_YELLOW
|
||||
# undef WHITE
|
||||
# define WHITE CACA_CONIO_WHITE
|
||||
#endif
|
||||
|
||||
#if !defined _DOXYGEN_SKIP_ME && !defined __LIBCACA__
|
||||
# undef _NOCURSOR
|
||||
# define _NOCURSOR CACA_CONIO__NOCURSOR
|
||||
# undef _SOLIDCURSOR
|
||||
# define _SOLIDCURSOR CACA_CONIO__SOLIDCURSOR
|
||||
# undef _NORMALCURSOR
|
||||
# define _NORMALCURSOR CACA_CONIO__NORMALCURSOR
|
||||
#endif
|
||||
|
||||
#if !defined _DOXYGEN_SKIP_ME && !defined __LIBCACA__
|
||||
# undef LASTMODE
|
||||
# define LASTMODE CACA_CONIO_LASTMODE
|
||||
# undef BW40
|
||||
# define BW40 CACA_CONIO_BW40
|
||||
# undef C40
|
||||
# define C40 CACA_CONIO_C40
|
||||
# undef BW80
|
||||
# define BW80 CACA_CONIO_BW80
|
||||
# undef C80
|
||||
# define C80 CACA_CONIO_C80
|
||||
# undef MONO
|
||||
# define MONO CACA_CONIO_MONO
|
||||
# undef C4350
|
||||
# define C4350 CACA_CONIO_C4350
|
||||
#endif
|
||||
|
||||
#if !defined _DOXYGEN_SKIP_ME && !defined __LIBCACA__
|
||||
# undef directvideo
|
||||
# define directvideo caca_conio_directvideo
|
||||
# undef text_info
|
||||
# define text_info caca_conio_text_info
|
||||
# undef _wscroll
|
||||
# define _wscroll caca_conio__wscroll
|
||||
#endif
|
||||
|
||||
#if !defined _DOXYGEN_SKIP_ME && !defined __LIBCACA__
|
||||
# undef cgets
|
||||
# define cgets caca_conio_cgets
|
||||
# undef clreol
|
||||
# define clreol caca_conio_clreol
|
||||
# undef clrscr
|
||||
# define clrscr caca_conio_clrscr
|
||||
# undef cprintf
|
||||
# define cprintf caca_conio_cprintf
|
||||
# undef cputs
|
||||
# define cputs caca_conio_cputs
|
||||
# undef cscanf
|
||||
# define cscanf caca_conio_cscanf
|
||||
# undef delay
|
||||
# define delay caca_conio_delay
|
||||
# undef delline
|
||||
# define delline caca_conio_delline
|
||||
# undef getch
|
||||
# define getch caca_conio_getch
|
||||
# undef getche
|
||||
# define getche caca_conio_getche
|
||||
# undef getpass
|
||||
# define getpass caca_conio_getpass
|
||||
# undef gettext
|
||||
# define gettext caca_conio_gettext
|
||||
# undef gettextinfo
|
||||
# define gettextinfo caca_conio_gettextinfo
|
||||
# undef gotoxy
|
||||
# define gotoxy caca_conio_gotoxy
|
||||
# undef highvideo
|
||||
# define highvideo caca_conio_highvideo
|
||||
# undef insline
|
||||
# define insline caca_conio_insline
|
||||
# undef kbhit
|
||||
# define kbhit caca_conio_kbhit
|
||||
# undef lowvideo
|
||||
# define lowvideo caca_conio_lowvideo
|
||||
# undef movetext
|
||||
# define movetext caca_conio_movetext
|
||||
# undef normvideo
|
||||
# define normvideo caca_conio_normvideo
|
||||
# undef nosound
|
||||
# define nosound caca_conio_nosound
|
||||
# undef printf
|
||||
# define printf caca_conio_printf
|
||||
# undef putch
|
||||
# define putch caca_conio_putch
|
||||
# undef puttext
|
||||
# define puttext caca_conio_puttext
|
||||
# undef _setcursortype
|
||||
# define _setcursortype caca_conio__setcursortype
|
||||
# undef sleep
|
||||
# define sleep caca_conio_sleep
|
||||
# undef sound
|
||||
# define sound caca_conio_sound
|
||||
# undef textattr
|
||||
# define textattr caca_conio_textattr
|
||||
# undef textbackground
|
||||
# define textbackground caca_conio_textbackground
|
||||
# undef textcolor
|
||||
# define textcolor caca_conio_textcolor
|
||||
# undef textmode
|
||||
# define textmode caca_conio_textmode
|
||||
# undef ungetch
|
||||
# define ungetch caca_conio_ungetch
|
||||
# undef wherex
|
||||
# define wherex caca_conio_wherex
|
||||
# undef wherey
|
||||
# define wherey caca_conio_wherey
|
||||
# undef window
|
||||
# define window caca_conio_window
|
||||
#endif
|
||||
|
||||
#endif /* __CACA_CONIO_H__ */
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2006-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains debugging functions.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_DEBUG_H__
|
||||
#define __CACA_DEBUG_H__
|
||||
|
||||
/* debug messages */
|
||||
#if defined DEBUG && !defined __KERNEL__
|
||||
# include <stdio.h>
|
||||
# include <stdarg.h>
|
||||
static inline void debug(const char *format, ...)
|
||||
{
|
||||
int saved_errno = geterrno();
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
fprintf(stderr, "** libcaca debug ** ");
|
||||
vfprintf(stderr, format, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
seterrno(saved_errno);
|
||||
}
|
||||
#else
|
||||
# define debug(format, ...) do {} while(0)
|
||||
#endif
|
||||
|
||||
#endif /* __CACA_DEBUG_H__ */
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2021 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_INTERNALS_H__
|
||||
#define __CACA_INTERNALS_H__
|
||||
|
||||
#include "caca_stubs.h"
|
||||
#include "caca_debug.h"
|
||||
#include "caca_prof.h"
|
||||
|
||||
typedef struct caca_timer caca_timer_t;
|
||||
typedef struct caca_privevent caca_privevent_t;
|
||||
|
||||
#if !defined(_DOXYGEN_SKIP_ME)
|
||||
# define STAT_VALUES 32
|
||||
# define EVENTBUF_LEN 10
|
||||
# define MAX_DIRTY_COUNT 8
|
||||
#endif
|
||||
|
||||
#undef __extern
|
||||
#if defined CACA_ENABLE_VISIBILITY
|
||||
# define __extern extern __attribute__((visibility("default")))
|
||||
#else
|
||||
# define __extern extern
|
||||
#endif
|
||||
|
||||
struct caca_frame
|
||||
{
|
||||
/* Frame size */
|
||||
int width, height;
|
||||
|
||||
/* Cell information */
|
||||
uint32_t *chars;
|
||||
uint32_t *attrs;
|
||||
|
||||
/* Painting context */
|
||||
int x, y;
|
||||
int handlex, handley;
|
||||
uint32_t curattr;
|
||||
|
||||
/* Frame name */
|
||||
char *name;
|
||||
};
|
||||
|
||||
struct caca_canvas
|
||||
{
|
||||
/* XXX: look at caca_set_canvas_boundaries() before adding anything
|
||||
* to this structure. The function is quite hacky. */
|
||||
|
||||
/* Frame information */
|
||||
int frame, framecount;
|
||||
struct caca_frame *frames;
|
||||
|
||||
/* Canvas management */
|
||||
int refcount;
|
||||
int autoinc;
|
||||
int (*resize_callback)(void *);
|
||||
void *resize_data;
|
||||
|
||||
/* Dirty rectangles */
|
||||
int ndirty, dirty_disabled;
|
||||
struct
|
||||
{
|
||||
int xmin, ymin, xmax, ymax;
|
||||
}
|
||||
dirty[MAX_DIRTY_COUNT + 1];
|
||||
|
||||
/* Shortcut to the active frame information */
|
||||
int width, height;
|
||||
uint32_t *chars;
|
||||
uint32_t *attrs;
|
||||
uint32_t curattr;
|
||||
|
||||
/* FIGfont management */
|
||||
caca_charfont_t *ff;
|
||||
};
|
||||
|
||||
/* Graphics driver */
|
||||
enum caca_driver
|
||||
{
|
||||
CACA_DRIVER_NULL = 0,
|
||||
CACA_DRIVER_RAW = 1,
|
||||
#if defined(USE_COCOA)
|
||||
CACA_DRIVER_COCOA = 2,
|
||||
#endif
|
||||
#if defined(USE_CONIO)
|
||||
CACA_DRIVER_CONIO = 3,
|
||||
#endif
|
||||
#if defined(USE_GL)
|
||||
CACA_DRIVER_GL = 4,
|
||||
#endif
|
||||
#if defined(USE_NCURSES)
|
||||
CACA_DRIVER_NCURSES = 5,
|
||||
#endif
|
||||
#if defined(USE_SLANG)
|
||||
CACA_DRIVER_SLANG = 6,
|
||||
#endif
|
||||
#if defined(USE_VGA)
|
||||
CACA_DRIVER_VGA = 7,
|
||||
#endif
|
||||
#if defined(USE_WIN32)
|
||||
CACA_DRIVER_WIN32 = 8,
|
||||
#endif
|
||||
#if defined(USE_X11)
|
||||
CACA_DRIVER_X11 = 9,
|
||||
#endif
|
||||
};
|
||||
|
||||
/* Available external drivers */
|
||||
#if defined(USE_COCOA)
|
||||
int cocoa_install(caca_display_t *);
|
||||
#endif
|
||||
#if defined(USE_CONIO)
|
||||
int conio_install(caca_display_t *);
|
||||
#endif
|
||||
#if defined(USE_GL)
|
||||
__extern int gl_install(caca_display_t *);
|
||||
#endif
|
||||
#if defined(USE_NCURSES)
|
||||
int ncurses_install(caca_display_t *);
|
||||
#endif
|
||||
int null_install(caca_display_t *);
|
||||
int raw_install(caca_display_t *);
|
||||
#if defined(USE_SLANG)
|
||||
int slang_install(caca_display_t *);
|
||||
#endif
|
||||
#if defined(USE_VGA)
|
||||
int vga_install(caca_display_t *);
|
||||
#endif
|
||||
#if defined(USE_WIN32)
|
||||
int win32_install(caca_display_t *);
|
||||
#endif
|
||||
#if defined(USE_X11)
|
||||
__extern int x11_install(caca_display_t *);
|
||||
#endif
|
||||
|
||||
/* Timer structure */
|
||||
struct caca_timer
|
||||
{
|
||||
int last_sec, last_usec;
|
||||
};
|
||||
|
||||
/* Statistic structure for profiling */
|
||||
struct caca_stat
|
||||
{
|
||||
int itable[STAT_VALUES];
|
||||
int64_t imean;
|
||||
char *name;
|
||||
};
|
||||
|
||||
/* Private event structure */
|
||||
struct caca_privevent
|
||||
{
|
||||
enum caca_event_type type;
|
||||
|
||||
union
|
||||
{
|
||||
struct { int x, y, button; } mouse;
|
||||
struct { int w, h; } resize;
|
||||
struct { int ch; uint32_t utf32; char utf8[8]; } key;
|
||||
} data;
|
||||
};
|
||||
|
||||
/* Internal caca display context */
|
||||
struct caca_display
|
||||
{
|
||||
/* A link to our caca canvas */
|
||||
caca_canvas_t *cv;
|
||||
int autorelease;
|
||||
|
||||
#if defined(USE_PLUGINS)
|
||||
void *plugin;
|
||||
#endif
|
||||
|
||||
/* Device-specific functions */
|
||||
struct drv
|
||||
{
|
||||
char const * driver;
|
||||
enum caca_driver id;
|
||||
struct driver_private *p;
|
||||
|
||||
int (* init_graphics) (caca_display_t *);
|
||||
int (* end_graphics) (caca_display_t *);
|
||||
int (* set_display_title) (caca_display_t *, char const *);
|
||||
int (* get_display_width) (caca_display_t const *);
|
||||
int (* get_display_height) (caca_display_t const *);
|
||||
void (* display) (caca_display_t *);
|
||||
void (* handle_resize) (caca_display_t *);
|
||||
int (* get_event) (caca_display_t *, caca_privevent_t *);
|
||||
void (* set_mouse) (caca_display_t *, int);
|
||||
void (* set_cursor) (caca_display_t *, int);
|
||||
} drv;
|
||||
|
||||
/* Mouse position */
|
||||
struct mouse
|
||||
{
|
||||
int x, y;
|
||||
} mouse;
|
||||
|
||||
/* Window resize handling */
|
||||
struct resize
|
||||
{
|
||||
int resized; /* A resize event was requested */
|
||||
int allow; /* The display driver allows resizing */
|
||||
int w, h; /* Requested width and height */
|
||||
} resize;
|
||||
|
||||
/* Framerate handling */
|
||||
int delay, rendertime;
|
||||
caca_timer_t timer;
|
||||
#if defined PROF
|
||||
struct caca_stat display_stat, wait_stat;
|
||||
struct caca_stat ev_sys_stat, ev_wait_stat;
|
||||
#endif
|
||||
int lastticks;
|
||||
|
||||
struct events
|
||||
{
|
||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
|
||||
caca_privevent_t buf[EVENTBUF_LEN];
|
||||
int queue;
|
||||
#endif
|
||||
#if defined(USE_SLANG) || defined(USE_NCURSES)
|
||||
caca_timer_t key_timer;
|
||||
int last_key_ticks;
|
||||
int autorepeat_ticks;
|
||||
caca_privevent_t last_key_event;
|
||||
#endif
|
||||
#if defined(USE_WIN32)
|
||||
uint8_t not_empty_struct;
|
||||
#endif
|
||||
} events;
|
||||
};
|
||||
|
||||
/* Dirty rectangle functions */
|
||||
extern void _caca_clip_dirty_rect_list(caca_canvas_t *);
|
||||
|
||||
/* Colour functions */
|
||||
extern uint32_t _caca_attr_to_rgb24fg(uint32_t);
|
||||
extern uint32_t _caca_attr_to_rgb24bg(uint32_t);
|
||||
|
||||
/* Frames functions */
|
||||
extern void _caca_save_frame_info(caca_canvas_t *);
|
||||
extern void _caca_load_frame_info(caca_canvas_t *);
|
||||
|
||||
/* Internal timer functions */
|
||||
extern void _caca_sleep(int);
|
||||
extern int _caca_getticks(caca_timer_t *);
|
||||
|
||||
/* Internal event functions */
|
||||
extern void _caca_handle_resize(caca_display_t *);
|
||||
#if defined(USE_SLANG) || defined(USE_NCURSES) || defined(USE_CONIO) || defined(USE_GL)
|
||||
/* Expose this with ‘__extern’ because the GL driver uses it */
|
||||
__extern void _caca_push_event(caca_display_t *, caca_privevent_t *);
|
||||
extern int _caca_pop_event(caca_display_t *, caca_privevent_t *);
|
||||
#endif
|
||||
|
||||
/* Internal window functions */
|
||||
extern void _caca_set_term_title(char const *);
|
||||
|
||||
/* Internal memory function */
|
||||
extern void *_caca_alloc2d(size_t width, size_t height, size_t elem_size);
|
||||
|
||||
/* Profiling functions */
|
||||
#if defined PROF
|
||||
extern void _caca_dump_stats(void);
|
||||
extern void _caca_init_stat(struct caca_stat *, char const *, ...);
|
||||
extern void _caca_fini_stat(struct caca_stat *);
|
||||
#endif
|
||||
|
||||
#undef __extern
|
||||
|
||||
#endif /* __CACA_INTERNALS_H__ */
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2009-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains profiling functions.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_PROF_H__
|
||||
#define __CACA_PROF_H__
|
||||
|
||||
#if defined PROF && !defined __KERNEL__
|
||||
# define PROFILING_VARS
|
||||
|
||||
# define STAT_IADD(_s, _n) \
|
||||
do \
|
||||
{ \
|
||||
struct caca_stat *s = _s; \
|
||||
int i, n = _n; \
|
||||
for (i = STAT_VALUES - 1; i > 0; i--) \
|
||||
s->itable[i] = s->itable[i - 1]; \
|
||||
s->itable[0] = n; \
|
||||
s->imean = (s->imean * 63 + (int64_t)n * 64 + 32) / 64; \
|
||||
} \
|
||||
while(0)
|
||||
|
||||
# define START_PROF(obj, fn)
|
||||
# define STOP_PROF(obj, fn)
|
||||
|
||||
#else
|
||||
# define PROFILING_VARS
|
||||
# define STAT_IADD(_s, _n) do { } while(0)
|
||||
# define START_PROF(obj, fn) do { } while(0)
|
||||
# define STOP_PROF(obj, fn) do { } while(0)
|
||||
#endif
|
||||
|
||||
#endif /* __CACA_PROF_H__ */
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2006-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains replacements for commonly found object types and
|
||||
* function prototypes that are sometimes missing.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_STUBS_H__
|
||||
#define __CACA_STUBS_H__
|
||||
|
||||
/* errno handling */
|
||||
#if defined HAVE_ERRNO_H && !defined __KERNEL__
|
||||
# include <errno.h>
|
||||
static inline void seterrno(int e) { errno = e; }
|
||||
static inline int geterrno(void) { return errno; }
|
||||
#else
|
||||
# define seterrno(x) do { (void)(x); } while(0)
|
||||
# define geterrno(x) 0
|
||||
#endif
|
||||
|
||||
/* hton16() and hton32() */
|
||||
#if defined HAVE_HTONS && !defined __KERNEL__
|
||||
# if defined HAVE_ARPA_INET_H
|
||||
# include <arpa/inet.h>
|
||||
# elif defined HAVE_NETINET_IN_H
|
||||
# include <netinet/in.h>
|
||||
# endif
|
||||
# define hton16 htons
|
||||
# define hton32 htonl
|
||||
#else
|
||||
# if defined __KERNEL__
|
||||
/* Nothing to do */
|
||||
# elif defined HAVE_ENDIAN_H
|
||||
# include <endian.h>
|
||||
# endif
|
||||
static inline uint16_t hton16(uint16_t x)
|
||||
{
|
||||
/* This is compile-time optimised with at least -O1 or -Os */
|
||||
#if defined HAVE_ENDIAN_H
|
||||
if(__BYTE_ORDER == __BIG_ENDIAN)
|
||||
#else
|
||||
uint32_t const dummy = 0x12345678;
|
||||
if(*(uint8_t const *)&dummy == 0x12)
|
||||
#endif
|
||||
return x;
|
||||
else
|
||||
return (x >> 8) | (x << 8);
|
||||
}
|
||||
|
||||
static inline uint32_t hton32(uint32_t x)
|
||||
{
|
||||
/* This is compile-time optimised with at least -O1 or -Os */
|
||||
#if defined HAVE_ENDIAN_H
|
||||
if(__BYTE_ORDER == __BIG_ENDIAN)
|
||||
#else
|
||||
uint32_t const dummy = 0x12345678;
|
||||
if(*(uint8_t const *)&dummy == 0x12)
|
||||
#endif
|
||||
return x;
|
||||
else
|
||||
return (x >> 24) | ((x >> 8) & 0x0000ff00)
|
||||
| ((x << 8) & 0x00ff0000) | (x << 24);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __CACA_STUBS_H__ */
|
||||
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2008-2012 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains definitions for required C99 integer types.
|
||||
*/
|
||||
|
||||
#ifndef __CACA_TYPES_H__
|
||||
#define __CACA_TYPES_H__
|
||||
|
||||
#if !defined _MSC_VER
|
||||
/* FIXME: detect platforms with <inttypes.h> and no <stdint.h> */
|
||||
# include <stdint.h>
|
||||
# include <unistd.h>
|
||||
|
||||
#elif defined _MSC_STDINT_H_ /* msinttypes */ \
|
||||
|| defined NM_DEFINED_FIXED_WIDTH_TYPEDEFS /* Morpheme */
|
||||
/* Someone already defined things for us: do nothing */
|
||||
|
||||
#else
|
||||
# if _MSC_VER >= 1600
|
||||
/* Visual Studio 2010 and later */
|
||||
# include <stdint.h>
|
||||
# else
|
||||
# include <intsafe.h>
|
||||
# if _MSC_VER >= 1300
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
# else
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef signed long long int int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long int uint64_t;
|
||||
# endif
|
||||
# endif
|
||||
# if defined _WIN64
|
||||
/* Win64, (u)intptr_t and size_t are present */
|
||||
typedef int ssize_t;
|
||||
# else
|
||||
/* Win32, only (u)intptr_t is present */
|
||||
typedef int ssize_t;
|
||||
typedef unsigned int size_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* fallback: nothing is known, we assume the platform is 32-bit and
|
||||
* sizeof(long) == sizeof(void *). We don't typedef directly because we
|
||||
* have no idea what other typedefs have already been made. */
|
||||
typedef signed char _caca_int8_t;
|
||||
typedef signed short _caca_int16_t;
|
||||
typedef signed long int _caca_int32_t;
|
||||
typedef signed long long int _caca_int64_t;
|
||||
# undef int8_t
|
||||
# define int8_t _caca_int8_t
|
||||
# undef int16_t
|
||||
# define int16_t _caca_int16_t
|
||||
# undef int32_t
|
||||
# define int32_t _caca_int32_t
|
||||
# undef int64_t
|
||||
# define int64_t _caca_int64_t
|
||||
typedef unsigned char _caca_uint8_t;
|
||||
typedef unsigned short _caca_uint16_t;
|
||||
typedef unsigned long int _caca_uint32_t;
|
||||
typedef unsigned long long int _caca_uint64_t;
|
||||
# undef uint8_t
|
||||
# define uint8_t _caca_uint8_t
|
||||
# undef uint16_t
|
||||
# define uint16_t _caca_uint16_t
|
||||
# undef uint32_t
|
||||
# define uint32_t _caca_uint32_t
|
||||
# undef uint64_t
|
||||
# define uint64_t _caca_uint64_t
|
||||
typedef long int _caca_intptr_t;
|
||||
typedef unsigned long int _caca_uintptr_t;
|
||||
# undef intptr_t
|
||||
# define intptr_t _caca_intptr_t
|
||||
# undef uintptr_t
|
||||
# define uintptr_t _caca_uintptr_t
|
||||
typedef int _caca_ssize_t;
|
||||
typedef unsigned int _caca_size_t;
|
||||
# undef ssize_t
|
||||
# define ssize_t _caca_ssize_t
|
||||
# undef size_t
|
||||
# define size_t _caca_size_t
|
||||
#endif
|
||||
|
||||
#endif /* __CACA_TYPES_H__ */
|
||||
|
|
@ -0,0 +1,535 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2021 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains the main functions used by \e libcaca applications
|
||||
* to initialise a drawing context.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <time.h>
|
||||
# include <sys/types.h>
|
||||
# if defined(HAVE_UNISTD_H)
|
||||
# include <unistd.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
|
||||
static int caca_resize(caca_canvas_t *, int, int);
|
||||
|
||||
/** \brief Initialise a \e libcaca canvas.
|
||||
*
|
||||
* Initialise internal \e libcaca structures and the backend that will
|
||||
* be used for subsequent graphical operations. It must be the first
|
||||
* \e libcaca function to be called in a function. caca_free_canvas()
|
||||
* should be called at the end of the program to free all allocated resources.
|
||||
*
|
||||
* Both the cursor and the canvas' handle are initialised at the top-left
|
||||
* corner.
|
||||
*
|
||||
* If an error occurs, NULL is returned and \b errno is set accordingly:
|
||||
* - \c EINVAL Specified width or height is invalid.
|
||||
* - \c EOVERFLOW Specified width and height overflowed.
|
||||
* - \c ENOMEM Not enough memory for the requested canvas size.
|
||||
*
|
||||
* \param width The desired canvas width
|
||||
* \param height The desired canvas height
|
||||
* \return A libcaca canvas handle upon success, NULL if an error occurred.
|
||||
*/
|
||||
caca_canvas_t * caca_create_canvas(int width, int height)
|
||||
{
|
||||
caca_canvas_t *cv;
|
||||
|
||||
if(width < 0 || height < 0)
|
||||
{
|
||||
seterrno(EINVAL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cv = malloc(sizeof(caca_canvas_t));
|
||||
|
||||
if(!cv)
|
||||
goto nomem;
|
||||
|
||||
cv->refcount = 0;
|
||||
cv->autoinc = 0;
|
||||
cv->resize_callback = NULL;
|
||||
cv->resize_data = NULL;
|
||||
|
||||
cv->frame = 0;
|
||||
cv->framecount = 1;
|
||||
cv->frames = malloc(sizeof(struct caca_frame));
|
||||
if(!cv->frames)
|
||||
{
|
||||
free(cv);
|
||||
goto nomem;
|
||||
}
|
||||
|
||||
cv->frames[0].width = cv->frames[0].height = 0;
|
||||
cv->frames[0].chars = NULL;
|
||||
cv->frames[0].attrs = NULL;
|
||||
cv->frames[0].x = cv->frames[0].y = 0;
|
||||
cv->frames[0].handlex = cv->frames[0].handley = 0;
|
||||
cv->frames[0].curattr = 0;
|
||||
cv->frames[0].name = strdup("frame#00000000");
|
||||
|
||||
_caca_load_frame_info(cv);
|
||||
caca_set_color_ansi(cv, CACA_DEFAULT, CACA_TRANSPARENT);
|
||||
|
||||
cv->ndirty = 0;
|
||||
cv->dirty_disabled = 0;
|
||||
cv->ff = NULL;
|
||||
|
||||
if(caca_resize(cv, width, height) < 0)
|
||||
{
|
||||
int saved_errno = geterrno();
|
||||
free(cv->frames[0].name);
|
||||
free(cv->frames);
|
||||
free(cv);
|
||||
seterrno(saved_errno);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return cv;
|
||||
|
||||
nomem:
|
||||
seterrno(ENOMEM);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** \brief Manage a canvas.
|
||||
*
|
||||
* Lock a canvas to prevent it from being resized. If non-NULL,
|
||||
* the \e callback function pointer will be called upon each
|
||||
* \e caca_set_canvas_size call and if the returned value is zero, the
|
||||
* canvas resize request will be denied.
|
||||
*
|
||||
* This function is only useful for display drivers such as the \e libcaca
|
||||
* library.
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c EBUSY The canvas is already being managed.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \param callback An optional callback function pointer.
|
||||
* \param p The argument to be passed to \e callback.
|
||||
* \return 0 in case of success, -1 if an error occurred.
|
||||
*/
|
||||
int caca_manage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
|
||||
{
|
||||
if(cv->refcount)
|
||||
{
|
||||
seterrno(EBUSY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cv->resize_callback = callback;
|
||||
cv->resize_data = p;
|
||||
cv->refcount = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief unmanage a canvas.
|
||||
*
|
||||
* unlock a canvas previously locked by caca_manage_canvas(). for safety
|
||||
* reasons, the callback and callback data arguments must be the same as for
|
||||
* the caca_manage_canvas() call.
|
||||
*
|
||||
* this function is only useful for display drivers such as the \e libcaca
|
||||
* library.
|
||||
*
|
||||
* if an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c einval the canvas is not managed, or the callback arguments do
|
||||
* not match.
|
||||
*
|
||||
* \param cv a libcaca canvas.
|
||||
* \param callback the \e callback argument previously passed to
|
||||
* caca_manage_canvas().
|
||||
* \param p the \e p argument previously passed to caca_manage_canvas().
|
||||
* \return 0 in case of success, -1 if an error occurred.
|
||||
*/
|
||||
int caca_unmanage_canvas(caca_canvas_t *cv, int (*callback)(void *), void *p)
|
||||
{
|
||||
if(!cv->refcount
|
||||
|| cv->resize_callback != callback || cv->resize_data != p)
|
||||
{
|
||||
seterrno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
cv->refcount = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Resize a canvas.
|
||||
*
|
||||
* Set the canvas' width and height, in character cells.
|
||||
*
|
||||
* The contents of the canvas are preserved to the extent of the new
|
||||
* canvas size. Newly allocated character cells at the right and/or at
|
||||
* the bottom of the canvas are filled with spaces.
|
||||
*
|
||||
* If as a result of the resize the cursor coordinates fall outside the
|
||||
* new canvas boundaries, they are readjusted. For instance, if the
|
||||
* current X cursor coordinate is 11 and the requested width is 10, the
|
||||
* new X cursor coordinate will be 10.
|
||||
*
|
||||
* It is an error to try to resize the canvas if an output driver has
|
||||
* been attached to the canvas using caca_create_display(). You need to
|
||||
* remove the output driver using caca_free_display() before you can change
|
||||
* the canvas size again. However, the caca output driver can cause a
|
||||
* canvas resize through user interaction. See the caca_event() documentation
|
||||
* for more about this.
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c EINVAL Specified width or height is invalid.
|
||||
* - \c EOVERFLOW Specified width and height overflowed.
|
||||
* - \c EBUSY The canvas is in use by a display driver and cannot be resized.
|
||||
* - \c ENOMEM Not enough memory for the requested canvas size. If this
|
||||
* happens, the canvas handle becomes invalid and should not be used.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \param width The desired canvas width.
|
||||
* \param height The desired canvas height.
|
||||
* \return 0 in case of success, -1 if an error occurred.
|
||||
*/
|
||||
int caca_set_canvas_size(caca_canvas_t *cv, int width, int height)
|
||||
{
|
||||
if(width < 0 || height < 0)
|
||||
{
|
||||
seterrno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(cv->refcount && cv->resize_callback
|
||||
&& !cv->resize_callback(cv->resize_data))
|
||||
{
|
||||
seterrno(EBUSY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return caca_resize(cv, width, height);
|
||||
}
|
||||
|
||||
/** \brief Get the canvas width.
|
||||
*
|
||||
* Return the current canvas' width, in character cells.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \return The canvas width.
|
||||
*/
|
||||
int caca_get_canvas_width(caca_canvas_t const *cv)
|
||||
{
|
||||
return cv->width;
|
||||
}
|
||||
|
||||
/** \brief Get the canvas height.
|
||||
*
|
||||
* Returns the current canvas' height, in character cells.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \return The canvas height.
|
||||
*/
|
||||
int caca_get_canvas_height(caca_canvas_t const *cv)
|
||||
{
|
||||
return cv->height;
|
||||
}
|
||||
|
||||
/** \brief Get the canvas character array.
|
||||
*
|
||||
* Return the current canvas' internal character array. The array elements
|
||||
* consist in native endian 32-bit Unicode values as returned by
|
||||
* caca_get_char().
|
||||
*
|
||||
* This function is probably only useful for \e libcaca 's internal display
|
||||
* drivers.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \return The canvas character array.
|
||||
*/
|
||||
uint32_t const * caca_get_canvas_chars(caca_canvas_t const *cv)
|
||||
{
|
||||
return (uint32_t const *)cv->chars;
|
||||
}
|
||||
|
||||
/** \brief Get the canvas attribute array.
|
||||
*
|
||||
* Returns the current canvas' internal attribute array. The array elements
|
||||
* consist in native endian 32-bit attribute values as returned by
|
||||
* caca_get_attr().
|
||||
*
|
||||
* This function is probably only useful for \e libcaca 's internal display
|
||||
* drivers.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \return The canvas attribute array.
|
||||
*/
|
||||
uint32_t const * caca_get_canvas_attrs(caca_canvas_t const *cv)
|
||||
{
|
||||
return (uint32_t const *)cv->attrs;
|
||||
}
|
||||
|
||||
/** \brief Free a \e libcaca canvas.
|
||||
*
|
||||
* Free all resources allocated by caca_create_canvas(). The canvas
|
||||
* pointer becomes invalid and must no longer be used unless a new call
|
||||
* to caca_create_canvas() is made.
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c EBUSY The canvas is in use by a display driver and cannot be freed.
|
||||
*
|
||||
* \param cv A libcaca canvas.
|
||||
* \return 0 in case of success, -1 if an error occurred.
|
||||
*/
|
||||
int caca_free_canvas(caca_canvas_t *cv)
|
||||
{
|
||||
int f;
|
||||
|
||||
if(cv->refcount)
|
||||
{
|
||||
seterrno(EBUSY);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
free(cv->frames[f].chars);
|
||||
free(cv->frames[f].attrs);
|
||||
free(cv->frames[f].name);
|
||||
}
|
||||
|
||||
caca_canvas_set_figfont(cv, NULL);
|
||||
|
||||
free(cv->frames);
|
||||
free(cv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** \brief Generate a random integer within a range.
|
||||
*
|
||||
* Generate a random integer within the given range.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param min The lower bound of the integer range.
|
||||
* \param max The upper bound of the integer range.
|
||||
* \return A random integer comprised between \p min and \p max - 1
|
||||
* (inclusive).
|
||||
*/
|
||||
static caca_timer_t timer = {0, 0};
|
||||
|
||||
int caca_rand(int min, int max)
|
||||
{
|
||||
static int need_init = 1;
|
||||
|
||||
if(need_init)
|
||||
{
|
||||
srand(getpid() + _caca_getticks(&timer));
|
||||
need_init = 0;
|
||||
}
|
||||
|
||||
return min + (int)((1.0 * (max - min)) * rand() / (RAND_MAX + 1.0));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* XXX: The following functions are local.
|
||||
*/
|
||||
|
||||
int caca_resize(caca_canvas_t *cv, int width, int height)
|
||||
{
|
||||
int x, y, f, old_width, old_height, old_size;
|
||||
|
||||
/* Check for overflow */
|
||||
int new_size = width * height;
|
||||
if (new_size < 0 || (width > 0 && new_size / width != height))
|
||||
{
|
||||
seterrno(EOVERFLOW);
|
||||
return -1;
|
||||
}
|
||||
|
||||
old_width = cv->width;
|
||||
old_height = cv->height;
|
||||
old_size = old_width * old_height;
|
||||
|
||||
_caca_save_frame_info(cv);
|
||||
|
||||
/* Preload new width and height values into the canvas to optimise
|
||||
* dirty rectangle handling */
|
||||
cv->width = width;
|
||||
cv->height = height;
|
||||
|
||||
/* If width or height is smaller (or both), we have the opportunity to
|
||||
* reduce or even remove dirty rectangles */
|
||||
if(width < old_width || height < old_height)
|
||||
_caca_clip_dirty_rect_list(cv);
|
||||
|
||||
/* Step 1: if new area is bigger, resize the memory area now. */
|
||||
if(new_size > old_size)
|
||||
{
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
cv->frames[f].chars = realloc(cv->frames[f].chars,
|
||||
new_size * sizeof(uint32_t));
|
||||
cv->frames[f].attrs = realloc(cv->frames[f].attrs,
|
||||
new_size * sizeof(uint32_t));
|
||||
if(new_size && (!cv->frames[f].chars || !cv->frames[f].attrs))
|
||||
{
|
||||
seterrno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 2: move line data if necessary. */
|
||||
if(width == old_width)
|
||||
{
|
||||
/* Width did not change, which means we do not need to move data. */
|
||||
;
|
||||
}
|
||||
else if(width > old_width)
|
||||
{
|
||||
/* New width is bigger than old width, which means we need to
|
||||
* copy lines starting from the bottom of the screen otherwise
|
||||
* we will overwrite information. */
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
uint32_t *chars = cv->frames[f].chars;
|
||||
uint32_t *attrs = cv->frames[f].attrs;
|
||||
|
||||
for(y = height < old_height ? height : old_height; y--; )
|
||||
{
|
||||
uint32_t attr = cv->frames[f].curattr;
|
||||
|
||||
for(x = old_width; x--; )
|
||||
{
|
||||
chars[y * width + x] = chars[y * old_width + x];
|
||||
attrs[y * width + x] = attrs[y * old_width + x];
|
||||
}
|
||||
|
||||
/* Zero the end of the line */
|
||||
for(x = width - old_width; x--; )
|
||||
{
|
||||
chars[y * width + old_width + x] = (uint32_t)' ';
|
||||
attrs[y * width + old_width + x] = attr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!cv->dirty_disabled)
|
||||
caca_add_dirty_rect(cv, old_width, 0,
|
||||
width - old_width, old_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* New width is smaller. Copy as many lines as possible. Ignore
|
||||
* the first line, it is already in place. */
|
||||
int lines = height < old_height ? height : old_height;
|
||||
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
uint32_t *chars = cv->frames[f].chars;
|
||||
uint32_t *attrs = cv->frames[f].attrs;
|
||||
|
||||
for(y = 1; y < lines; y++)
|
||||
{
|
||||
for(x = 0; x < width; x++)
|
||||
{
|
||||
chars[y * width + x] = chars[y * old_width + x];
|
||||
attrs[y * width + x] = attrs[y * old_width + x];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Step 3: fill the bottom of the new screen if necessary. */
|
||||
if(height > old_height)
|
||||
{
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
uint32_t *chars = cv->frames[f].chars;
|
||||
uint32_t *attrs = cv->frames[f].attrs;
|
||||
uint32_t attr = cv->frames[f].curattr;
|
||||
|
||||
/* Zero the bottom of the screen */
|
||||
for(x = (height - old_height) * width; x--; )
|
||||
{
|
||||
chars[old_height * width + x] = (uint32_t)' ';
|
||||
attrs[old_height * width + x] = attr;
|
||||
}
|
||||
}
|
||||
|
||||
if(!cv->dirty_disabled)
|
||||
caca_add_dirty_rect(cv, 0, old_height,
|
||||
old_width, height - old_height);
|
||||
}
|
||||
|
||||
/* If both width and height are larger, there is a new dirty rectangle
|
||||
* that needs to be created in the lower right corner. */
|
||||
if(!cv->dirty_disabled &&
|
||||
width > old_width && height > old_height)
|
||||
caca_add_dirty_rect(cv, old_width, old_height,
|
||||
width - old_width, height - old_height);
|
||||
|
||||
/* Step 4: if new area is smaller, resize memory area now. */
|
||||
if(new_size < old_size)
|
||||
{
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
cv->frames[f].chars = realloc(cv->frames[f].chars,
|
||||
new_size * sizeof(uint32_t));
|
||||
cv->frames[f].attrs = realloc(cv->frames[f].attrs,
|
||||
new_size * sizeof(uint32_t));
|
||||
if(new_size && (!cv->frames[f].chars || !cv->frames[f].attrs))
|
||||
{
|
||||
seterrno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Set new size */
|
||||
for(f = 0; f < cv->framecount; f++)
|
||||
{
|
||||
if(cv->frames[f].x > (int)width)
|
||||
cv->frames[f].x = width;
|
||||
if(cv->frames[f].y > (int)height)
|
||||
cv->frames[f].y = height;
|
||||
|
||||
cv->frames[f].width = width;
|
||||
cv->frames[f].height = height;
|
||||
}
|
||||
|
||||
/* Reset the current frame shortcuts */
|
||||
_caca_load_frame_info(cv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,420 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2018 Sam Hocevar <sam@hocevar.net>
|
||||
* 2007 Ben Wiley Sittler <bsittler@gmail.com>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains functions for converting characters between
|
||||
* various character sets.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
|
||||
/*
|
||||
* UTF-8 handling
|
||||
*/
|
||||
|
||||
static uint8_t const trailing[256] =
|
||||
{
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
|
||||
};
|
||||
|
||||
static uint32_t const offsets[6] =
|
||||
{
|
||||
0x00000000UL, 0x00003080UL, 0x000E2080UL,
|
||||
0x03C82080UL, 0xFA082080UL, 0x82082080UL
|
||||
};
|
||||
|
||||
/*
|
||||
* CP437 handling
|
||||
*/
|
||||
|
||||
static uint32_t const cp437_lookup1[] =
|
||||
{
|
||||
/* 0x01 - 0x0f: ☺ ☻ ♥ ♦ ♣ ♠ • ◘ ○ ◙ ♂ ♀ ♪ ♫ ☼ */
|
||||
0x263a, 0x263b, 0x2665, 0x2666, 0x2663, 0x2660, 0x2022,
|
||||
0x25d8, 0x25cb, 0x25d9, 0x2642, 0x2640, 0x266a, 0x266b, 0x263c,
|
||||
/* 0x10 - 0x1f: ► ◄ ↕ ‼ ¶ § ▬ ↨ ↑ ↓ → ← ∟ ↔ ▲ ▼ */
|
||||
0x25ba, 0x25c4, 0x2195, 0x203c, 0xb6, 0xa7, 0x25ac, 0x21a8,
|
||||
0x2191, 0x2193, 0x2192, 0x2190, 0x221f, 0x2194, 0x25b2, 0x25bc
|
||||
};
|
||||
|
||||
static uint32_t const cp437_lookup2[] =
|
||||
{
|
||||
/* 0x7f: ⌂ */
|
||||
0x2302,
|
||||
/* 0x80 - 0x8f: Ç ü é â ä à å ç ê ë è ï î ì Ä Å */
|
||||
0xc7, 0xfc, 0xe9, 0xe2, 0xe4, 0xe0, 0xe5, 0xe7,
|
||||
0xea, 0xeb, 0xe8, 0xef, 0xee, 0xec, 0xc4, 0xc5,
|
||||
/* 0x90 - 0x9f: É æ Æ ô ö ò û ù ÿ Ö Ü ¢ £ ¥ ₧ ƒ */
|
||||
0xc9, 0xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,
|
||||
0xff, 0xd6, 0xdc, 0xa2, 0xa3, 0xa5, 0x20a7, 0x192,
|
||||
/* 0xa0 - 0xaf: á í ó ú ñ Ñ ª º ¿ ⌐ ¬ ½ ¼ ¡ « » */
|
||||
0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,
|
||||
0xbf, 0x2310, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,
|
||||
/* 0xb0 - 0xbf: ░ ▒ ▓ │ ┤ ╡ ╢ ╖ ╕ ╣ ║ ╗ ╝ ╜ ╛ ┐ */
|
||||
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
|
||||
0x2555, 0x2563, 0x2551, 0x2557, 0x255d, 0x255c, 0x255b, 0x2510,
|
||||
/* 0xc0 - 0xcf: └ ┴ ┬ ├ ─ ┼ ╞ ╟ ╚ ╔ ╩ ╦ ╠ ═ ╬ ╧ */
|
||||
0x2514, 0x2534, 0x252c, 0x251c, 0x2500, 0x253c, 0x255e, 0x255f,
|
||||
0x255a, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256c, 0x2567,
|
||||
/* 0xd0 - 0xdf: ╨ ╤ ╥ ╙ ╘ ╒ ╓ ╫ ╪ ┘ ┌ █ ▄ ▌ ▐ ▀ */
|
||||
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256b,
|
||||
0x256a, 0x2518, 0x250c, 0x2588, 0x2584, 0x258c, 0x2590, 0x2580,
|
||||
/* 0xe0 - 0xef: α ß Γ π Σ σ µ τ Φ Θ Ω δ ∞ φ ε ∩ */
|
||||
0x3b1, 0xdf, 0x393, 0x3c0, 0x3a3, 0x3c3, 0xb5, 0x3c4,
|
||||
0x3a6, 0x398, 0x3a9, 0x3b4, 0x221e, 0x3c6, 0x3b5, 0x2229,
|
||||
/* 0xf0 - 0xff: ≡ ± ≥ ≤ ⌠ ⌡ ÷ ≈ ° ∙ · √ ⁿ ² ■ <nbsp> */
|
||||
0x2261, 0xb1, 0x2265, 0x2264, 0x2320, 0x2321, 0xf7, 0x2248,
|
||||
0xb0, 0x2219, 0xb7, 0x221a, 0x207f, 0xb2, 0x25a0, 0xa0
|
||||
};
|
||||
|
||||
/** \brief Convert a UTF-8 character to UTF-32.
|
||||
*
|
||||
* Convert a UTF-8 character read from a string and return its value in
|
||||
* the UTF-32 character set. If the second argument is not null, the total
|
||||
* number of read bytes is written in it.
|
||||
*
|
||||
* If a null byte was reached before the expected end of the UTF-8 sequence,
|
||||
* this function returns zero and the number of read bytes is set to zero.
|
||||
*
|
||||
* This function never fails, but its behaviour with illegal UTF-8 sequences
|
||||
* is undefined.
|
||||
*
|
||||
* \param s A string containing the UTF-8 character.
|
||||
* \param bytes A pointer to a size_t to store the number of bytes in the
|
||||
* character, or NULL.
|
||||
* \return The corresponding UTF-32 character, or zero if the character
|
||||
* is incomplete.
|
||||
*/
|
||||
uint32_t caca_utf8_to_utf32(char const *s, size_t *bytes)
|
||||
{
|
||||
int todo = trailing[(int)(unsigned char)*s];
|
||||
int i = 0;
|
||||
uint32_t ret = 0;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if(!*s)
|
||||
{
|
||||
if(bytes)
|
||||
*bytes = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret += ((uint32_t)(unsigned char)*s++) << (6 * (todo - i));
|
||||
|
||||
if(todo == i++)
|
||||
{
|
||||
if(bytes)
|
||||
*bytes = i;
|
||||
return ret - offsets[todo];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** \brief Convert a UTF-32 character to UTF-8.
|
||||
*
|
||||
* Convert a UTF-32 character read from a string and write its value in
|
||||
* the UTF-8 character set into the given buffer.
|
||||
*
|
||||
* This function never fails, but its behaviour with illegal UTF-32 characters
|
||||
* is undefined.
|
||||
*
|
||||
* \param buf A pointer to a character buffer where the UTF-8 sequence will
|
||||
* be written.
|
||||
* \param ch The UTF-32 character.
|
||||
* \return The number of bytes written.
|
||||
*/
|
||||
size_t caca_utf32_to_utf8(char *buf, uint32_t ch)
|
||||
{
|
||||
static const uint8_t mark[7] =
|
||||
{
|
||||
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
|
||||
};
|
||||
|
||||
char *parser = buf;
|
||||
size_t bytes;
|
||||
|
||||
if(ch < 0x80)
|
||||
{
|
||||
*parser++ = ch;
|
||||
return 1;
|
||||
}
|
||||
|
||||
bytes = (ch < 0x800) ? 2 : (ch < 0x10000) ? 3 : 4;
|
||||
parser += bytes;
|
||||
|
||||
switch(bytes)
|
||||
{
|
||||
case 4: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
|
||||
case 3: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
|
||||
case 2: *--parser = (ch | 0x80) & 0xbf; ch >>= 6;
|
||||
}
|
||||
*--parser = ch | mark[bytes];
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/** \brief Convert a UTF-32 character to CP437.
|
||||
*
|
||||
* Convert a UTF-32 character read from a string and return its value in
|
||||
* the CP437 character set, or "?" if the character has no equivalent.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param ch The UTF-32 character.
|
||||
* \return The corresponding CP437 character, or "?" if not representable.
|
||||
*/
|
||||
uint8_t caca_utf32_to_cp437(uint32_t ch)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if(ch < 0x00000020)
|
||||
return '?';
|
||||
|
||||
if(ch < 0x00000080)
|
||||
return ch;
|
||||
|
||||
for(i = 0; i < sizeof(cp437_lookup1) / sizeof(*cp437_lookup1); i++)
|
||||
if(cp437_lookup1[i] == ch)
|
||||
return 0x01 + i;
|
||||
|
||||
for(i = 0; i < sizeof(cp437_lookup2) / sizeof(*cp437_lookup2); i++)
|
||||
if(cp437_lookup2[i] == ch)
|
||||
return 0x7f + i;
|
||||
|
||||
return '?';
|
||||
}
|
||||
|
||||
/** \brief Convert a CP437 character to UTF-32.
|
||||
*
|
||||
* Convert a CP437 character read from a string and return its value in
|
||||
* the UTF-32 character set, or zero if the character is a CP437 control
|
||||
* character.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param ch The CP437 character.
|
||||
* \return The corresponding UTF-32 character, or zero if not representable.
|
||||
*/
|
||||
uint32_t caca_cp437_to_utf32(uint8_t ch)
|
||||
{
|
||||
if(ch > 0x7f)
|
||||
return cp437_lookup2[ch - 0x7f];
|
||||
|
||||
if(ch >= 0x20)
|
||||
return (uint32_t)ch;
|
||||
|
||||
if(ch > 0)
|
||||
return cp437_lookup1[ch - 0x01];
|
||||
|
||||
return 0x00000000;
|
||||
}
|
||||
|
||||
/** \brief Convert a UTF-32 character to ASCII.
|
||||
*
|
||||
* Convert a UTF-32 character into an ASCII character. When no equivalent
|
||||
* exists, a graphically close equivalent is sought.
|
||||
*
|
||||
* This function never fails, but its behaviour with illegal UTF-32 characters
|
||||
* is undefined.
|
||||
*
|
||||
* \param ch The UTF-32 character.
|
||||
* \return The corresponding ASCII character, or a graphically close
|
||||
* equivalent if found, or "?" if not representable.
|
||||
*/
|
||||
char caca_utf32_to_ascii(uint32_t ch)
|
||||
{
|
||||
/* Standard ASCII */
|
||||
if(ch < 0x80)
|
||||
return ch;
|
||||
|
||||
/* Fullwidth Forms */
|
||||
if(ch > 0x0000ff00 && ch < 0x0000ff5f)
|
||||
return ' ' + (ch - 0x0000ff00);
|
||||
|
||||
switch (ch)
|
||||
{
|
||||
case 0x000000a0: /* (nbsp) */
|
||||
case 0x00003000: /* (ideographic space) */
|
||||
return ' ';
|
||||
case 0x000000a3: /* £ */
|
||||
return 'f';
|
||||
case 0x000000b0: /* ° */
|
||||
return '\'';
|
||||
case 0x000000b1: /* ± */
|
||||
return '#';
|
||||
case 0x000000b7: /* · */
|
||||
case 0x00002219: /* ∙ */
|
||||
case 0x000030fb: /* ・ */
|
||||
return '.';
|
||||
case 0x000003c0: /* π */
|
||||
return '*';
|
||||
case 0x00002018: /* ‘ */
|
||||
case 0x00002019: /* ’ */
|
||||
return '\'';
|
||||
case 0x0000201c: /* “ */
|
||||
case 0x0000201d: /* ” */
|
||||
return '"';
|
||||
case 0x00002190: /* ← */
|
||||
return '<';
|
||||
case 0x00002191: /* ↑ */
|
||||
return '^';
|
||||
case 0x00002192: /* → */
|
||||
return '>';
|
||||
case 0x00002193: /* ↓ */
|
||||
return 'v';
|
||||
case 0x00002260: /* ≠ */
|
||||
return '!';
|
||||
case 0x00002261: /* ≡ */
|
||||
return '=';
|
||||
case 0x00002264: /* ≤ */
|
||||
return '<';
|
||||
case 0x00002265: /* ≥ */
|
||||
return '>';
|
||||
case 0x000023ba: /* ⎺ */
|
||||
case 0x000023bb: /* ⎻ */
|
||||
case 0x000023bc: /* ⎼ */
|
||||
case 0x000023bd: /* ⎽ */
|
||||
case 0x00002500: /* ─ */
|
||||
case 0x00002550: /* ═ */
|
||||
return '-';
|
||||
case 0x00002502: /* │ */
|
||||
case 0x00002551: /* ║ */
|
||||
return '|';
|
||||
case 0x0000250c: /* ┌ */
|
||||
case 0x00002552: /* ╒ */
|
||||
case 0x00002553: /* ╓ */
|
||||
case 0x00002554: /* ╔ */
|
||||
case 0x00002514: /* └ */
|
||||
case 0x00002558: /* ╘ */
|
||||
case 0x00002559: /* ╙ */
|
||||
case 0x0000255a: /* ╚ */
|
||||
case 0x0000251c: /* ├ */
|
||||
case 0x0000255e: /* ╞ */
|
||||
case 0x0000255f: /* ╟ */
|
||||
case 0x00002560: /* ╠ */
|
||||
case 0x0000252c: /* ┬ */
|
||||
case 0x00002564: /* ╤ */
|
||||
case 0x00002565: /* ╥ */
|
||||
case 0x00002566: /* ╦ */
|
||||
case 0x00002534: /* ┴ */
|
||||
case 0x00002567: /* ╧ */
|
||||
case 0x00002568: /* ╨ */
|
||||
case 0x00002569: /* ╩ */
|
||||
case 0x0000253c: /* ┼ */
|
||||
case 0x0000256a: /* ╪ */
|
||||
case 0x0000256b: /* ╫ */
|
||||
case 0x0000256c: /* ╬ */
|
||||
return '+';
|
||||
case 0x00002510: /* ┐ */
|
||||
case 0x00002555: /* ╕ */
|
||||
case 0x00002556: /* ╖ */
|
||||
case 0x00002557: /* ╗ */
|
||||
case 0x00002518: /* ┘ */
|
||||
case 0x0000255b: /* ╛ */
|
||||
case 0x0000255c: /* ╜ */
|
||||
case 0x0000255d: /* ╝ */
|
||||
case 0x00002524: /* ┤ */
|
||||
case 0x00002561: /* ╡ */
|
||||
case 0x00002562: /* ╢ */
|
||||
case 0x00002563: /* ╣ */
|
||||
return '+';
|
||||
case 0x00002591: /* ░ */
|
||||
case 0x00002592: /* ▒ */
|
||||
case 0x00002593: /* ▓ */
|
||||
case 0x00002588: /* █ */
|
||||
case 0x0000258c: /* ▌ */
|
||||
case 0x00002590: /* ▐ */
|
||||
case 0x000025a0: /* ■ */
|
||||
case 0x000025ac: /* ▬ */
|
||||
case 0x000025ae: /* ▮ */
|
||||
return '#';
|
||||
case 0x00002580: /* ▀ */
|
||||
return '"';
|
||||
case 0x00002584: /* ▄ */
|
||||
return ',';
|
||||
case 0x000025c6: /* ◆ */
|
||||
case 0x00002666: /* ♦ */
|
||||
return '+';
|
||||
case 0x00002022: /* • */
|
||||
case 0x000025cb: /* ○ */
|
||||
case 0x000025cf: /* ● */
|
||||
case 0x00002603: /* ☃ */
|
||||
case 0x0000263c: /* ☼ */
|
||||
return 'o';
|
||||
case 0x0000301c: /* 〜 */
|
||||
return '~';
|
||||
}
|
||||
|
||||
return '?';
|
||||
}
|
||||
|
||||
/** \brief Tell whether a UTF-32 character is fullwidth.
|
||||
*
|
||||
* Check whether the given UTF-32 character should be printed at twice
|
||||
* the normal width (fullwidth characters). If the character is unknown
|
||||
* or if its status cannot be decided, it is treated as a standard-width
|
||||
* character.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \param ch The UTF-32 character.
|
||||
* \return 1 if the character is fullwidth, 0 otherwise.
|
||||
*/
|
||||
int caca_utf32_is_fullwidth(uint32_t ch)
|
||||
{
|
||||
if(ch < 0x2e80) /* Standard stuff */
|
||||
return 0;
|
||||
if(ch < 0xa700) /* Japanese, Korean, CJK, Yi... */
|
||||
return 1;
|
||||
if(ch < 0xac00) /* Modified Tone Letters, Syloti Nagri */
|
||||
return 0;
|
||||
if(ch < 0xd800) /* Hangul Syllables */
|
||||
return 1;
|
||||
if(ch < 0xf900) /* Misc crap */
|
||||
return 0;
|
||||
if(ch < 0xfb00) /* More CJK */
|
||||
return 1;
|
||||
if(ch < 0xfe20) /* Misc crap */
|
||||
return 0;
|
||||
if(ch < 0xfe70) /* More CJK */
|
||||
return 1;
|
||||
if(ch < 0xff00) /* Misc crap */
|
||||
return 0;
|
||||
if(ch < 0xff61) /* Fullwidth forms */
|
||||
return 1;
|
||||
if(ch < 0xffe0) /* Halfwidth forms */
|
||||
return 0;
|
||||
if(ch < 0xffe8) /* More fullwidth forms */
|
||||
return 1;
|
||||
if(ch < 0x20000) /* Misc crap */
|
||||
return 0;
|
||||
if(ch < 0xe0000) /* More CJK */
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright (c) 2002-2014 Sam Hocevar <sam@hocevar.net>
|
||||
* 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
ssize_t _import_text(caca_canvas_t *, void const *, size_t);
|
||||
ssize_t _import_ansi(caca_canvas_t *, void const *, size_t, int);
|
||||
ssize_t _import_bin(caca_canvas_t *, void const *, size_t);
|
||||
|
||||
void *_export_ansi(caca_canvas_t const *, size_t *);
|
||||
void *_export_utf8(caca_canvas_t const *, size_t *, int);
|
||||
void *_export_irc(caca_canvas_t const *, size_t *);
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,441 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2021 Sam Hocevar <sam@hocevar.net>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains various import functions.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined __KERNEL__
|
||||
# include <stdlib.h>
|
||||
# include <string.h>
|
||||
# include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
#include "codec.h"
|
||||
|
||||
static inline uint32_t sscanu32(void const *s)
|
||||
{
|
||||
uint32_t x;
|
||||
memcpy(&x, s, 4);
|
||||
return hton32(x);
|
||||
}
|
||||
|
||||
static inline uint16_t sscanu16(void const *s)
|
||||
{
|
||||
uint16_t x;
|
||||
memcpy(&x, s, 2);
|
||||
return hton16(x);
|
||||
}
|
||||
|
||||
static ssize_t import_caca(caca_canvas_t *, void const *, size_t);
|
||||
|
||||
/** \brief Import a memory buffer into a canvas
|
||||
*
|
||||
* Import a memory buffer into the given libcaca canvas's current
|
||||
* frame. The current frame is resized accordingly and its contents are
|
||||
* replaced with the imported data.
|
||||
*
|
||||
* Valid values for \c format are:
|
||||
* - \c "": attempt to autodetect the file format.
|
||||
* - \c "caca": import native libcaca files.
|
||||
* - \c "text": import ASCII text files.
|
||||
* - \c "ansi": import ANSI files.
|
||||
* - \c "utf8": import UTF-8 files with ANSI colour codes.
|
||||
* - \c "bin": import BIN files.
|
||||
*
|
||||
* The number of bytes read is returned. If the file format is valid, but
|
||||
* not enough data was available, 0 is returned.
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c ENOMEM Not enough memory to allocate canvas.
|
||||
* - \c EOVERFLOW Importing data caused a value overflow.
|
||||
* - \c EINVAL Invalid format requested.
|
||||
*
|
||||
* \param cv A libcaca canvas in which to import the file.
|
||||
* \param data A memory area containing the data to be loaded into the canvas.
|
||||
* \param len The size in bytes of the memory area.
|
||||
* \param format A string describing the input format.
|
||||
* \return The number of bytes read, or 0 if there was not enough data,
|
||||
* or -1 if an error occurred.
|
||||
*/
|
||||
ssize_t caca_import_canvas_from_memory(caca_canvas_t *cv, void const *data,
|
||||
size_t len, char const *format)
|
||||
{
|
||||
if(!strcasecmp("caca", format))
|
||||
return import_caca(cv, data, len);
|
||||
if(!strcasecmp("utf8", format))
|
||||
return _import_ansi(cv, data, len, 1);
|
||||
if(!strcasecmp("text", format))
|
||||
return _import_text(cv, data, len);
|
||||
if(!strcasecmp("ansi", format))
|
||||
return _import_ansi(cv, data, len, 0);
|
||||
if(!strcasecmp("bin", format))
|
||||
return _import_bin(cv, data, len);
|
||||
|
||||
/* Autodetection */
|
||||
if(!strcasecmp("", format))
|
||||
{
|
||||
unsigned char const *str = data;
|
||||
unsigned int i, j, k;
|
||||
|
||||
/* If 4 first bytes are 0xcaca + 'CV' */
|
||||
if(len >= 4 && str[0] == 0xca &&
|
||||
str[1] == 0xca && str[2] == 'C' && str[3] == 'V')
|
||||
return import_caca(cv, data, len);
|
||||
|
||||
/* If we find ESC[ argv, we guess it's an ANSI file */
|
||||
for(i = 0; i + 1 < len; i++)
|
||||
if((str[i] == '\033') && (str[i + 1] == '['))
|
||||
return _import_ansi(cv, data, len, 0);
|
||||
|
||||
/* If we find a lot of spaces at even locations,
|
||||
* we guess it's a BIN file. */
|
||||
for (i = j = k = 0; i < len; i += 2)
|
||||
{
|
||||
j += (str[i] == ' ');
|
||||
k += (str[i + 1] == ' ');
|
||||
}
|
||||
|
||||
if (j > 10 && j > len / 40 && k < 10)
|
||||
return _import_bin(cv, data, len);
|
||||
|
||||
/* Otherwise, import it as text */
|
||||
return _import_text(cv, data, len);
|
||||
}
|
||||
|
||||
seterrno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/** \brief Import a file into a canvas
|
||||
*
|
||||
* Import a file into the given libcaca canvas's current frame. The
|
||||
* current frame is resized accordingly and its contents are replaced
|
||||
* with the imported data.
|
||||
*
|
||||
* Valid values for \c format are:
|
||||
* - \c "": attempt to autodetect the file format.
|
||||
* - \c "caca": import native libcaca files.
|
||||
* - \c "text": import ASCII text files.
|
||||
* - \c "ansi": import ANSI files.
|
||||
* - \c "utf8": import UTF-8 files with ANSI colour codes.
|
||||
* - \c "bin": import BIN files.
|
||||
*
|
||||
* The number of bytes read is returned. If the file format is valid, but
|
||||
* not enough data was available, 0 is returned.
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c ENOSYS File access is not implemented on this system.
|
||||
* - \c ENOMEM Not enough memory to allocate canvas.
|
||||
* - \c EINVAL Invalid format requested.
|
||||
* caca_import_file() may also fail and set \b errno for any of the
|
||||
* errors specified for the routine fopen().
|
||||
*
|
||||
* \param cv A libcaca canvas in which to import the file.
|
||||
* \param filename The name of the file to load.
|
||||
* \param format A string describing the input format.
|
||||
* \return The number of bytes read, or 0 if there was not enough data,
|
||||
* or -1 if an error occurred.
|
||||
*/
|
||||
ssize_t caca_import_canvas_from_file(caca_canvas_t *cv, char const *filename,
|
||||
char const *format)
|
||||
{
|
||||
#if defined __KERNEL__
|
||||
seterrno(ENOSYS);
|
||||
return -1;
|
||||
#else
|
||||
caca_file_t *f;
|
||||
char *data = NULL;
|
||||
ssize_t ret, size = 0;
|
||||
|
||||
f = caca_file_open(filename, "rb");
|
||||
if(!f)
|
||||
return -1; /* fopen already set errno */
|
||||
|
||||
while(!caca_file_eof(f))
|
||||
{
|
||||
data = realloc(data, size + 1024);
|
||||
if(!data)
|
||||
{
|
||||
caca_file_close(f);
|
||||
seterrno(ENOMEM);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = (ssize_t)caca_file_read(f, data + size, 1024);
|
||||
if(ret >= 0)
|
||||
size += ret;
|
||||
}
|
||||
caca_file_close(f);
|
||||
|
||||
ret = caca_import_canvas_from_memory(cv, data, size, format);
|
||||
free(data);
|
||||
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
/** \brief Import a memory buffer into a canvas area
|
||||
*
|
||||
* Import a memory buffer into the given libcaca canvas's current
|
||||
* frame, at the specified position. For more information, see
|
||||
* caca_import_canvas_from_memory().
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c EINVAL Unsupported format requested or invalid coordinates.
|
||||
* - \c ENOMEM Not enough memory to allocate canvas.
|
||||
*
|
||||
* \param cv A libcaca canvas in which to import the file.
|
||||
* \param x The leftmost coordinate of the area to import to.
|
||||
* \param y The topmost coordinate of the area to import to.
|
||||
* \param data A memory area containing the data to be loaded into the canvas.
|
||||
* \param len The size in bytes of the memory area.
|
||||
* \param format A string describing the input format.
|
||||
* \return The number of bytes read, or 0 if there was not enough data,
|
||||
* or -1 if an error occurred.
|
||||
*/
|
||||
ssize_t caca_import_area_from_memory(caca_canvas_t *cv, int x, int y,
|
||||
void const *data, size_t len,
|
||||
char const *format)
|
||||
{
|
||||
caca_canvas_t *tmp;
|
||||
ssize_t ret;
|
||||
|
||||
tmp = caca_create_canvas(0, 0);
|
||||
ret = caca_import_canvas_from_memory(tmp, data, len, format);
|
||||
|
||||
if(ret > 0)
|
||||
caca_blit(cv, x, y, tmp, NULL);
|
||||
|
||||
caca_free_canvas(tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** \brief Import a file into a canvas area
|
||||
*
|
||||
* Import a file into the given libcaca canvas's current frame, at the
|
||||
* specified position. For more information, see
|
||||
* caca_import_canvas_from_file().
|
||||
*
|
||||
* If an error occurs, -1 is returned and \b errno is set accordingly:
|
||||
* - \c ENOSYS File access is not implemented on this system.
|
||||
* - \c ENOMEM Not enough memory to allocate canvas.
|
||||
* - \c EINVAL Unsupported format requested or invalid coordinates.
|
||||
* caca_import_file() may also fail and set \b errno for any of the
|
||||
* errors specified for the routine fopen().
|
||||
*
|
||||
* \param cv A libcaca canvas in which to import the file.
|
||||
* \param x The leftmost coordinate of the area to import to.
|
||||
* \param y The topmost coordinate of the area to import to.
|
||||
* \param filename The name of the file to load.
|
||||
* \param format A string describing the input format.
|
||||
* \return The number of bytes read, or 0 if there was not enough data,
|
||||
* or -1 if an error occurred.
|
||||
*/
|
||||
ssize_t caca_import_area_from_file(caca_canvas_t *cv, int x, int y,
|
||||
char const *filename, char const *format)
|
||||
{
|
||||
caca_canvas_t *tmp;
|
||||
ssize_t ret;
|
||||
|
||||
tmp = caca_create_canvas(0, 0);
|
||||
ret = caca_import_canvas_from_file(tmp, filename, format);
|
||||
|
||||
if(ret > 0)
|
||||
caca_blit(cv, x, y, tmp, NULL);
|
||||
|
||||
caca_free_canvas(tmp);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** \brief Get available import formats
|
||||
*
|
||||
* Return a list of available import formats. The list is a NULL-terminated
|
||||
* array of strings, interleaving a string containing the internal value for
|
||||
* the import format, to be used with caca_import_canvas(), and a string
|
||||
* containing the natural language description for that import format.
|
||||
*
|
||||
* This function never fails.
|
||||
*
|
||||
* \return An array of strings.
|
||||
*/
|
||||
char const * const * caca_get_import_list(void)
|
||||
{
|
||||
static char const * const list[] =
|
||||
{
|
||||
"", "autodetect",
|
||||
"caca", "native libcaca format",
|
||||
"text", "plain text",
|
||||
"ansi", "ANSI coloured text",
|
||||
"utf8", "UTF-8 files with ANSI colour codes",
|
||||
"bin", "BIN binary ANSI art",
|
||||
NULL, NULL
|
||||
};
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: the following functions are local.
|
||||
*/
|
||||
|
||||
static ssize_t import_caca(caca_canvas_t *cv, void const *data, size_t size)
|
||||
{
|
||||
uint8_t const *buf = (uint8_t const *)data;
|
||||
size_t control_size, data_size, expected_size;
|
||||
unsigned int frames, f, n, offset;
|
||||
uint16_t version, flags;
|
||||
int32_t xmin = 0, ymin = 0, xmax = 0, ymax = 0;
|
||||
|
||||
if(size < 20)
|
||||
return 0;
|
||||
|
||||
if(buf[0] != 0xca || buf[1] != 0xca || buf[2] != 'C' || buf[3] != 'V')
|
||||
{
|
||||
debug("caca import error: expected \\xca\\xcaCV header");
|
||||
goto invalid_caca;
|
||||
}
|
||||
|
||||
control_size = sscanu32(buf + 4);
|
||||
data_size = sscanu32(buf + 8);
|
||||
version = sscanu16(buf + 12);
|
||||
frames = sscanu32(buf + 14);
|
||||
flags = sscanu16(buf + 18);
|
||||
|
||||
if(size < 4 + control_size + data_size)
|
||||
return 0;
|
||||
|
||||
if(control_size < 16 + frames * 32)
|
||||
{
|
||||
debug("caca import error: control size %u < expected %u",
|
||||
(unsigned int)control_size, 16 + frames * 32);
|
||||
goto invalid_caca;
|
||||
}
|
||||
|
||||
for(expected_size = 0, f = 0; f < frames; f++)
|
||||
{
|
||||
unsigned int width, height, duration;
|
||||
uint32_t attr;
|
||||
int x, y, handlex, handley;
|
||||
|
||||
width = sscanu32(buf + 4 + 16 + f * 32);
|
||||
height = sscanu32(buf + 4 + 16 + f * 32 + 4);
|
||||
duration = sscanu32(buf + 4 + 16 + f * 32 + 8);
|
||||
attr = sscanu32(buf + 4 + 16 + f * 32 + 12);
|
||||
x = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 16);
|
||||
y = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 20);
|
||||
handlex = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 24);
|
||||
handley = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 28);
|
||||
expected_size += width * height * 8;
|
||||
if(-handlex < xmin)
|
||||
xmin = -handlex;
|
||||
if(-handley < ymin)
|
||||
ymin = -handley;
|
||||
if((((int32_t) width) - handlex) > xmax)
|
||||
xmax = ((int32_t) width) - handlex;
|
||||
if((((int32_t) height) - handley) > ymax)
|
||||
ymax = ((int32_t) height) - handley;
|
||||
}
|
||||
|
||||
if(expected_size != data_size)
|
||||
{
|
||||
debug("caca import error: data size %u < expected %u",
|
||||
(unsigned int)data_size, (unsigned int)expected_size);
|
||||
goto invalid_caca;
|
||||
}
|
||||
|
||||
caca_set_canvas_size(cv, 0, 0);
|
||||
caca_set_canvas_size(cv, xmax - xmin, ymax - ymin);
|
||||
|
||||
for (f = caca_get_frame_count(cv); f--; )
|
||||
{
|
||||
caca_free_frame(cv, f);
|
||||
}
|
||||
|
||||
for (offset = 0, f = 0; f < frames; f ++)
|
||||
{
|
||||
unsigned int width, height;
|
||||
|
||||
width = sscanu32(buf + 4 + 16 + f * 32);
|
||||
height = sscanu32(buf + 4 + 16 + f * 32 + 4);
|
||||
caca_create_frame(cv, f);
|
||||
caca_set_frame(cv, f);
|
||||
|
||||
cv->curattr = sscanu32(buf + 4 + 16 + f * 32 + 12);
|
||||
cv->frames[f].x = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 16);
|
||||
cv->frames[f].y = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 20);
|
||||
cv->frames[f].handlex = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 24);
|
||||
cv->frames[f].handley = (int32_t)sscanu32(buf + 4 + 16 + f * 32 + 28);
|
||||
|
||||
/* FIXME: check for return value */
|
||||
|
||||
for(n = width * height; n--; )
|
||||
{
|
||||
int x = (n % width) - cv->frames[f].handlex - xmin;
|
||||
int y = (n / width) - cv->frames[f].handley - ymin;
|
||||
|
||||
caca_put_char(cv, x, y, sscanu32(buf + 4 + control_size
|
||||
+ offset + 8 * n));
|
||||
caca_put_attr(cv, x, y, sscanu32(buf + 4 + control_size
|
||||
+ offset + 8 * n + 4));
|
||||
}
|
||||
offset += width * height * 8;
|
||||
|
||||
cv->frames[f].x -= cv->frames[f].handlex;
|
||||
cv->frames[f].y -= cv->frames[f].handley;
|
||||
cv->frames[f].handlex = -xmin;
|
||||
cv->frames[f].handley = -ymin;
|
||||
}
|
||||
|
||||
caca_set_frame(cv, 0);
|
||||
|
||||
return (ssize_t)(4 + control_size + data_size);
|
||||
|
||||
invalid_caca:
|
||||
seterrno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t _import_bin(caca_canvas_t *cv, void const *data, size_t len)
|
||||
{
|
||||
uint8_t const *buf = (uint8_t const *)data;
|
||||
size_t i;
|
||||
int x = 0, y = 0;
|
||||
|
||||
caca_set_canvas_size(cv, 0, 0);
|
||||
caca_set_canvas_size(cv, 160, len / 160);
|
||||
|
||||
/* Only read an even number of bytes */
|
||||
len &= ~(size_t)1;
|
||||
|
||||
for (i = 0; i < len; i += 2)
|
||||
{
|
||||
caca_set_color_ansi(cv, buf[i + 1] & 0xf, buf[i + 1] >> 4);
|
||||
caca_put_char(cv, x, y, caca_cp437_to_utf32(buf[i]));
|
||||
|
||||
++x;
|
||||
if (x >= 160)
|
||||
{
|
||||
++y;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
|
@ -0,0 +1,903 @@
|
|||
/*
|
||||
* libcaca Colour ASCII-Art library
|
||||
* Copyright © 2002—2021 Sam Hocevar <sam@hocevar.net>
|
||||
* 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This library is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What the Fuck You Want
|
||||
* to Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://www.wtfpl.net/ for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file contains text import and export functions
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if !defined(__KERNEL__)
|
||||
# include <stdlib.h>
|
||||
# include <stdio.h>
|
||||
# include <string.h>
|
||||
#endif
|
||||
|
||||
#include "caca.h"
|
||||
#include "caca_internals.h"
|
||||
#include "codec.h"
|
||||
|
||||
struct import
|
||||
{
|
||||
uint32_t clearattr;
|
||||
|
||||
/* ANSI Graphic Rendition Combination Mode */
|
||||
uint8_t fg, bg; /* ANSI-context fg/bg */
|
||||
uint8_t dfg, dbg; /* Default fg/bg */
|
||||
uint8_t bold, blink, italics, negative, concealed, underline;
|
||||
uint8_t faint, strike, proportional; /* unsupported */
|
||||
};
|
||||
|
||||
static void ansi_parse_grcm(caca_canvas_t *, struct import *,
|
||||
unsigned int, unsigned int const *);
|
||||
|
||||
ssize_t _import_text(caca_canvas_t *cv, void const *data, size_t size)
|
||||
{
|
||||
char const *text = (char const *)data;
|
||||
unsigned int width = 0, height = 0, x = 0, y = 0, i;
|
||||
|
||||
caca_set_canvas_size(cv, 0, 0);
|
||||
|
||||
for(i = 0; i < size; i++)
|
||||
{
|
||||
unsigned char ch = *text++;
|
||||
|
||||
if(ch == '\r')
|
||||
continue;
|
||||
|
||||
if(ch == '\n')
|
||||
{
|
||||
x = 0;
|
||||
y++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(x >= width || y >= height)
|
||||
{
|
||||
if(x >= width)
|
||||
width = x + 1;
|
||||
|
||||
if(y >= height)
|
||||
height = y + 1;
|
||||
|
||||
if (caca_set_canvas_size(cv, width, height) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
caca_put_char(cv, x, y, ch);
|
||||
x++;
|
||||
}
|
||||
|
||||
if (y > height)
|
||||
{
|
||||
if (caca_set_canvas_size(cv, width, height = y) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (ssize_t)size;
|
||||
}
|
||||
|
||||
ssize_t _import_ansi(caca_canvas_t *cv, void const *data, size_t size, int utf8)
|
||||
{
|
||||
struct import im;
|
||||
unsigned char const *buffer = (unsigned char const*)data;
|
||||
unsigned int i, j, skip, growx = 0, growy = 0, dummy = 0;
|
||||
unsigned int width, height;
|
||||
uint32_t savedattr;
|
||||
int x = 0, y = 0, save_x = 0, save_y = 0;
|
||||
|
||||
if(utf8)
|
||||
{
|
||||
width = cv->width;
|
||||
height = cv->height;
|
||||
growx = !width;
|
||||
growy = !height;
|
||||
x = cv->frames[cv->frame].x;
|
||||
y = cv->frames[cv->frame].y;
|
||||
}
|
||||
else
|
||||
{
|
||||
caca_set_canvas_size(cv, width = 80, height = 0);
|
||||
growx = 0;
|
||||
growy = 1;
|
||||
}
|
||||
|
||||
if(utf8)
|
||||
{
|
||||
im.dfg = CACA_DEFAULT;
|
||||
im.dbg = CACA_TRANSPARENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
im.dfg = CACA_LIGHTGRAY;
|
||||
im.dbg = CACA_BLACK;
|
||||
}
|
||||
|
||||
caca_set_color_ansi(cv, im.dfg, im.dbg);
|
||||
im.clearattr = caca_get_attr(cv, -1, -1);
|
||||
|
||||
ansi_parse_grcm(cv, &im, 1, &dummy);
|
||||
|
||||
for(i = 0; i < size; i += skip)
|
||||
{
|
||||
uint32_t ch = 0;
|
||||
int wch = 0;
|
||||
|
||||
skip = 1;
|
||||
|
||||
if(!utf8 && buffer[i] == '\x1a' && i + 7 < size
|
||||
&& !memcmp(buffer + i + 1, "SAUCE00", 7))
|
||||
break; /* End before SAUCE data */
|
||||
|
||||
else if(buffer[i] == '\r')
|
||||
{
|
||||
x = 0;
|
||||
}
|
||||
|
||||
else if(buffer[i] == '\n')
|
||||
{
|
||||
x = 0;
|
||||
y++;
|
||||
}
|
||||
|
||||
else if(buffer[i] == '\t')
|
||||
{
|
||||
x = (x + 8) & ~7;
|
||||
}
|
||||
|
||||
else if(buffer[i] == '\x08')
|
||||
{
|
||||
if(x > 0)
|
||||
x--;
|
||||
}
|
||||
|
||||
/* If there are not enough characters to parse the escape sequence,
|
||||
* wait until the next try. We require 3. */
|
||||
else if(buffer[i] == '\033' && i + 2 >= size)
|
||||
break;
|
||||
|
||||
/* XXX: What the fuck is this shit? */
|
||||
else if(buffer[i] == '\033' && buffer[i + 1] == '('
|
||||
&& buffer[i + 2] == 'B')
|
||||
{
|
||||
skip += 2;
|
||||
}
|
||||
|
||||
/* Interpret escape commands, as per Standard ECMA-48 "Control
|
||||
* Functions for Coded Character Sets", 5.4. Control sequences. */
|
||||
else if(buffer[i] == '\033' && buffer[i + 1] == '[')
|
||||
{
|
||||
unsigned int argc = 0, argv[101];
|
||||
unsigned int param, inter, final;
|
||||
|
||||
/* Compute offsets to parameter bytes, intermediate bytes and
|
||||
* to the final byte. Only the final byte is mandatory, there
|
||||
* can be zero of the others.
|
||||
* 0 param=2 inter final final+1
|
||||
* +-----+------------------+---------------------+-----------------+
|
||||
* | CSI | parameter bytes | intermediate bytes | final byte |
|
||||
* | | 0x30 - 0x3f | 0x20 - 0x2f | 0x40 - 0x7e |
|
||||
* | ^[[ | 0123456789:;<=>? | SPC !"#$%&'()*+,-./ | azAZ@[\]^_`{|}~ |
|
||||
* +-----+------------------+---------------------+-----------------+
|
||||
*/
|
||||
param = 2;
|
||||
|
||||
for(inter = param; i + inter < size; inter++)
|
||||
if(buffer[i + inter] < 0x30 || buffer[i + inter] > 0x3f)
|
||||
break;
|
||||
|
||||
for(final = inter; i + final < size; final++)
|
||||
if(buffer[i + final] < 0x20 || buffer[i + final] > 0x2f)
|
||||
break;
|
||||
|
||||
if(i + final >= size
|
||||
|| buffer[i + final] < 0x40 || buffer[i + final] > 0x7e)
|
||||
break; /* Invalid Final Byte */
|
||||
|
||||
skip += final;
|
||||
|
||||
/* Sanity checks */
|
||||
if(param < inter && buffer[i + param] >= 0x3c)
|
||||
{
|
||||
/* Private sequence, only parse what we know */
|
||||
debug("ansi import: private sequence \"^[[%.*s\"",
|
||||
final - param + 1, buffer + i + param);
|
||||
continue; /* Private sequence, skip it entirely */
|
||||
}
|
||||
|
||||
if(final - param > 100)
|
||||
continue; /* Suspiciously long sequence, skip it */
|
||||
|
||||
/* Parse parameter bytes as per ECMA-48 5.4.2: Parameter string
|
||||
* format */
|
||||
if(param < inter)
|
||||
{
|
||||
argv[0] = 0;
|
||||
for(j = param; j < inter; j++)
|
||||
{
|
||||
if(buffer[i + j] == ';')
|
||||
argv[++argc] = 0;
|
||||
else if(buffer[i + j] >= '0' && buffer[i + j] <= '9')
|
||||
argv[argc] = 10 * argv[argc] + (buffer[i + j] - '0');
|
||||
}
|
||||
argc++;
|
||||
}
|
||||
|
||||
/* Interpret final byte. The code representations are given in
|
||||
* ECMA-48 5.4: Control sequences, and the code definitions are
|
||||
* given in ECMA-48 8.3: Definition of control functions. */
|
||||
switch(buffer[i + final])
|
||||
{
|
||||
case 'H': /* CUP (0x48) - Cursor Position */
|
||||
x = (argc > 1 && argv[1] > 0) ? argv[1] - 1 : 0;
|
||||
y = (argc > 0 && argv[0] > 0) ? argv[0] - 1 : 0;
|
||||
break;
|
||||
case 'A': /* CUU (0x41) - Cursor Up */
|
||||
y -= argc ? argv[0] : 1;
|
||||
if(y < 0)
|
||||
y = 0;
|
||||
break;
|
||||
case 'B': /* CUD (0x42) - Cursor Down */
|
||||
y += argc ? argv[0] : 1;
|
||||
break;
|
||||
case 'C': /* CUF (0x43) - Cursor Right */
|
||||
x += argc ? argv[0] : 1;
|
||||
break;
|
||||
case 'D': /* CUB (0x44) - Cursor Left */
|
||||
x -= argc ? argv[0] : 1;
|
||||
if(x < 0)
|
||||
x = 0;
|
||||
break;
|
||||
case 'G': /* CHA (0x47) - Cursor Character Absolute */
|
||||
x = (argc && argv[0] > 0) ? argv[0] - 1 : 0;
|
||||
break;
|
||||
case 'J': /* ED (0x4a) - Erase In Page */
|
||||
savedattr = caca_get_attr(cv, -1, -1);
|
||||
caca_set_attr(cv, im.clearattr);
|
||||
if(!argc || argv[0] == 0)
|
||||
{
|
||||
caca_draw_line(cv, x, y, width, y, ' ');
|
||||
caca_fill_box(cv, 0, y + 1, width - 1, height - 1, ' ');
|
||||
}
|
||||
else if(argv[0] == 1)
|
||||
{
|
||||
caca_fill_box(cv, 0, 0, width - 1, y - 1, ' ');
|
||||
caca_draw_line(cv, 0, y, x, y, ' ');
|
||||
}
|
||||
else if(argv[0] == 2)
|
||||
//x = y = 0;
|
||||
caca_fill_box(cv, 0, 0, width - 1, height - 1, ' ');
|
||||
caca_set_attr(cv, savedattr);
|
||||
break;
|
||||
case 'K': /* EL (0x4b) - Erase In Line */
|
||||
if(!argc || argv[0] == 0)
|
||||
caca_draw_line(cv, x, y, width, y, ' ');
|
||||
else if(argv[0] == 1)
|
||||
caca_draw_line(cv, 0, y, x, y, ' ');
|
||||
else if(argv[0] == 2)
|
||||
if((unsigned int)x < width)
|
||||
caca_draw_line(cv, x, y, width - 1, y, ' ');
|
||||
//x = width;
|
||||
break;
|
||||
case 'P': /* DCH (0x50) - Delete Character */
|
||||
if(!argc || argv[0] == 0)
|
||||
argv[0] = 1; /* echo -ne 'foobar\r\e[0P\n' */
|
||||
for(j = 0; (unsigned int)(j + argv[0]) < width; j++)
|
||||
{
|
||||
caca_put_char(cv, j, y,
|
||||
caca_get_char(cv, j + argv[0], y));
|
||||
caca_put_attr(cv, j, y,
|
||||
caca_get_attr(cv, j + argv[0], y));
|
||||
}
|
||||
#if 0
|
||||
savedattr = caca_get_attr(cv, -1, -1);
|
||||
caca_set_attr(cv, im.clearattr);
|
||||
for( ; (unsigned int)j < width; j++)
|
||||
caca_put_char(cv, j, y, ' ');
|
||||
caca_set_attr(cv, savedattr);
|
||||
#endif
|
||||
break;
|
||||
case 'X': /* ECH (0x58) - Erase Character */
|
||||
if(argc && argv[0])
|
||||
{
|
||||
savedattr = caca_get_attr(cv, -1, -1);
|
||||
caca_set_attr(cv, im.clearattr);
|
||||
caca_draw_line(cv, x, y, x + argv[0] - 1, y, ' ');
|
||||
caca_set_attr(cv, savedattr);
|
||||
}
|
||||
break;
|
||||
case 'd': /* VPA (0x64) - Line Position Absolute */
|
||||
y = (argc && argv[0] > 0) ? argv[0] - 1 : 0;
|
||||
break;
|
||||
case 'f': /* HVP (0x66) - Character And Line Position */
|
||||
x = (argc > 1 && argv[1] > 0) ? argv[1] - 1 : 0;
|
||||
y = (argc > 0 && argv[0] > 0) ? argv[0] - 1 : 0;
|
||||
break;
|
||||
case 'h': /* SM (0x68) - FIXME */
|
||||
debug("ansi import: set mode %i", argc ? (int)argv[0] : -1);
|
||||
break;
|
||||
case 'l': /* RM (0x6c) - FIXME */
|
||||
debug("ansi import: reset mode %i", argc ? (int)argv[0] : -1);
|
||||
break;
|
||||
case 'm': /* SGR (0x6d) - Select Graphic Rendition */
|
||||
if(argc)
|
||||
ansi_parse_grcm(cv, &im, argc, argv);
|
||||
else
|
||||
ansi_parse_grcm(cv, &im, 1, &dummy);
|
||||
break;
|
||||
case 's': /* Private (save cursor position) */
|
||||
save_x = x;
|
||||
save_y = y;
|
||||
break;
|
||||
case 'u': /* Private (reload cursor position) */
|
||||
x = save_x;
|
||||
y = save_y;
|
||||
break;
|
||||
default:
|
||||
debug("ansi import: unknown command \"^[[%.*s\"",
|
||||
final - param + 1, buffer + i + param);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse OSC stuff. */
|
||||
else if(buffer[i] == '\033' && buffer[i + 1] == ']')
|
||||
{
|
||||
char *string;
|
||||
unsigned int command = 0;
|
||||
unsigned int mode = 2, semicolon, final;
|
||||
|
||||
for(semicolon = mode; i + semicolon < size; semicolon++)
|
||||
{
|
||||
if(buffer[i + semicolon] < '0' || buffer[i + semicolon] > '9')
|
||||
break;
|
||||
command = 10 * command + (buffer[i + semicolon] - '0');
|
||||
}
|
||||
|
||||
if(i + semicolon >= size || buffer[i + semicolon] != ';')
|
||||
break; /* Invalid Mode */
|
||||
|
||||
for(final = semicolon + 1; i + final < size; final++)
|
||||
if(buffer[i + final] < 0x20)
|
||||
break;
|
||||
|
||||
if(i + final >= size || buffer[i + final] != '\a')
|
||||
break; /* Not enough data or no bell found */
|
||||
/* FIXME: XTerm also reacts to <ESC><backslash> and <ST> */
|
||||
/* FIXME: differenciate between not enough data (try again)
|
||||
* and invalid data (print shit) */
|
||||
|
||||
skip += final;
|
||||
|
||||
string = malloc(final - (semicolon + 1) + 1);
|
||||
memcpy(string, buffer + (semicolon + 1), final - (semicolon + 1));
|
||||
string[final - (semicolon + 1)] = '\0';
|
||||
debug("ansi import: got OSC command %i string '%s'", command,
|
||||
string);
|
||||
free(string);
|
||||
}
|
||||
|
||||
/* Form feed means a new frame */
|
||||
else if (i + 1 < size && buffer[i] == '\f' && buffer[i + 1] == '\n')
|
||||
{
|
||||
int f = caca_get_frame_count(cv);
|
||||
caca_create_frame(cv, f);
|
||||
caca_set_frame(cv, f);
|
||||
x = y = 0;
|
||||
skip++;
|
||||
}
|
||||
|
||||
/* Get the character we’re going to paste */
|
||||
else if(utf8)
|
||||
{
|
||||
size_t bytes;
|
||||
|
||||
if(i + 6 < size)
|
||||
ch = caca_utf8_to_utf32((char const *)(buffer + i), &bytes);
|
||||
else
|
||||
{
|
||||
/* Add a trailing zero to what we're going to read */
|
||||
char tmp[7];
|
||||
memcpy(tmp, buffer + i, size - i);
|
||||
tmp[size - i] = '\0';
|
||||
ch = caca_utf8_to_utf32(tmp, &bytes);
|
||||
}
|
||||
|
||||
if(!bytes)
|
||||
{
|
||||
/* If the Unicode is invalid, assume it was latin1. */
|
||||
ch = buffer[i];
|
||||
bytes = 1;
|
||||
}
|
||||
wch = caca_utf32_is_fullwidth(ch) ? 2 : 1;
|
||||
skip += (int)(bytes - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ch = caca_cp437_to_utf32(buffer[i]);
|
||||
wch = 1;
|
||||
}
|
||||
|
||||
/* Wrap long lines or grow horizontally */
|
||||
while((unsigned int)x + wch > width)
|
||||
{
|
||||
if(growx)
|
||||
{
|
||||
savedattr = caca_get_attr(cv, -1, -1);
|
||||
caca_set_attr(cv, im.clearattr);
|
||||
if (caca_set_canvas_size(cv, width = x + wch, height) < 0)
|
||||
return -1;
|
||||
caca_set_attr(cv, savedattr);
|
||||
}
|
||||
else
|
||||
{
|
||||
x -= width;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Scroll or grow vertically */
|
||||
if((unsigned int)y >= height)
|
||||
{
|
||||
savedattr = caca_get_attr(cv, -1, -1);
|
||||
caca_set_attr(cv, im.clearattr);
|
||||
if(growy)
|
||||
{
|
||||
if (caca_set_canvas_size(cv, width, height = y + 1) < 0)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int lines = (y - height) + 1;
|
||||
|
||||
for(j = 0; j + lines < height; j++)
|
||||
{
|
||||
memcpy(cv->attrs + j * cv->width,
|
||||
cv->attrs + (j + lines) * cv->width, cv->width * 4);
|
||||
memcpy(cv->chars + j * cv->width,
|
||||
cv->chars + (j + lines) * cv->width, cv->width * 4);
|
||||
}
|
||||
caca_fill_box(cv, 0, height - lines,
|
||||
cv->width - 1, height - 1, ' ');
|
||||
y -= lines;
|
||||
}
|
||||
caca_set_attr(cv, savedattr);
|
||||
}
|
||||
|
||||
/* Now paste our character, if any */
|
||||
if(wch)
|
||||
{
|
||||
caca_put_char(cv, x, y, ch);
|
||||
x += wch;
|
||||
}
|
||||
}
|
||||
|
||||
if(growy && (unsigned int)y > height)
|
||||
{
|
||||
savedattr = caca_get_attr(cv, -1, -1);
|
||||
caca_set_attr(cv, im.clearattr);
|
||||
if (caca_set_canvas_size(cv, width, height = y))
|
||||
return -1;
|
||||
caca_set_attr(cv, savedattr);
|
||||
}
|
||||
|
||||
cv->frames[cv->frame].x = x;
|
||||
cv->frames[cv->frame].y = y;
|
||||
|
||||
// if(utf8)
|
||||
// caca_set_attr(cv, savedattr);
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
/* Generate UTF-8 representation of current canvas. */
|
||||
void *_export_utf8(caca_canvas_t const *cv, size_t *bytes, int cr)
|
||||
{
|
||||
static uint8_t const palette[] =
|
||||
{
|
||||
0, 4, 2, 6, 1, 5, 3, 7,
|
||||
8, 12, 10, 14, 9, 13, 11, 15
|
||||
};
|
||||
|
||||
char *data, *cur;
|
||||
int x, y;
|
||||
|
||||
/* 23 bytes assumed for max length per pixel ('\e[5;1;3x;4y;9x;10ym' plus
|
||||
* 4 max bytes for a UTF-8 character).
|
||||
* Add height*9 to that (zeroes color at the end and jump to next line) */
|
||||
*bytes = (cv->height * 9) + (cv->width * cv->height * 23);
|
||||
cur = data = malloc(*bytes);
|
||||
|
||||
for(y = 0; y < cv->height; y++)
|
||||
{
|
||||
uint32_t *lineattr = cv->attrs + y * cv->width;
|
||||
uint32_t *linechar = cv->chars + y * cv->width;
|
||||
|
||||
uint8_t prevfg = 0x10;
|
||||
uint8_t prevbg = 0x10;
|
||||
|
||||
for(x = 0; x < cv->width; x++)
|
||||
{
|
||||
uint32_t attr = lineattr[x];
|
||||
uint32_t ch = linechar[x];
|
||||
uint8_t ansifg, ansibg, fg, bg;
|
||||
|
||||
if(ch == CACA_MAGIC_FULLWIDTH)
|
||||
continue;
|
||||
|
||||
ansifg = caca_attr_to_ansi_fg(attr);
|
||||
ansibg = caca_attr_to_ansi_bg(attr);
|
||||
|
||||
fg = ansifg < 0x10 ? palette[ansifg] : 0x10;
|
||||
bg = ansibg < 0x10 ? palette[ansibg] : 0x10;
|
||||
|
||||
/* TODO: the [0 could be omitted in some cases */
|
||||
if(fg != prevfg || bg != prevbg)
|
||||
{
|
||||
cur += sprintf(cur, "\033[0");
|
||||
|
||||
if(fg < 8)
|
||||
cur += sprintf(cur, ";3%d", fg);
|
||||
else if(fg < 16)
|
||||
cur += sprintf(cur, ";1;3%d;9%d", fg - 8, fg - 8);
|
||||
|
||||
if(bg < 8)
|
||||
cur += sprintf(cur, ";4%d", bg);
|
||||
else if(bg < 16)
|
||||
cur += sprintf(cur, ";5;4%d;10%d", bg - 8, bg - 8);
|
||||
|
||||
cur += sprintf(cur, "m");
|
||||
}
|
||||
|
||||
cur += caca_utf32_to_utf8(cur, ch);
|
||||
|
||||
prevfg = fg;
|
||||
prevbg = bg;
|
||||
}
|
||||
|
||||
if(prevfg != 0x10 || prevbg != 0x10)
|
||||
cur += sprintf(cur, "\033[0m");
|
||||
|
||||
cur += sprintf(cur, cr ? "\r\n" : "\n");
|
||||
}
|
||||
|
||||
/* Crop to really used size */
|
||||
debug("utf8 export: alloc %lu bytes, realloc %lu",
|
||||
(unsigned long int)*bytes, (unsigned long int)(cur - data));
|
||||
*bytes = (uintptr_t)(cur - data);
|
||||
data = realloc(data, *bytes);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* Generate ANSI representation of current canvas. */
|
||||
void *_export_ansi(caca_canvas_t const *cv, size_t *bytes)
|
||||
{
|
||||
static uint8_t const palette[] =
|
||||
{
|
||||
0, 4, 2, 6, 1, 5, 3, 7,
|
||||
8, 12, 10, 14, 9, 13, 11, 15
|
||||
};
|
||||
|
||||
char *data, *cur;
|
||||
int x, y;
|
||||
|
||||
uint8_t prevfg = -1;
|
||||
uint8_t prevbg = -1;
|
||||
|
||||
/* 16 bytes assumed for max length per pixel ('\e[5;1;3x;4ym' plus
|
||||
* 1 byte for a CP437 character).
|
||||
* Add height*9 to that (zeroes color at the end and jump to next line) */
|
||||
*bytes = (cv->height * 9) + (cv->width * cv->height * 16);
|
||||
cur = data = malloc(*bytes);
|
||||
|
||||
for(y = 0; y < cv->height; y++)
|
||||
{
|
||||
uint32_t *lineattr = cv->attrs + y * cv->width;
|
||||
uint32_t *linechar = cv->chars + y * cv->width;
|
||||
|
||||
for(x = 0; x < cv->width; x++)
|
||||
{
|
||||
uint8_t ansifg = caca_attr_to_ansi_fg(lineattr[x]);
|
||||
uint8_t ansibg = caca_attr_to_ansi_bg(lineattr[x]);
|
||||
uint8_t fg = ansifg < 0x10 ? palette[ansifg] : CACA_LIGHTGRAY;
|
||||
uint8_t bg = ansibg < 0x10 ? palette[ansibg] : CACA_BLACK;
|
||||
uint32_t ch = linechar[x];
|
||||
|
||||
if(ch == CACA_MAGIC_FULLWIDTH)
|
||||
ch = '?';
|
||||
|
||||
if(fg != prevfg || bg != prevbg)
|
||||
{
|
||||
cur += sprintf(cur, "\033[0;");
|
||||
|
||||
if(fg < 8)
|
||||
if(bg < 8)
|
||||
cur += sprintf(cur, "3%d;4%dm", fg, bg);
|
||||
else
|
||||
cur += sprintf(cur, "5;3%d;4%dm", fg, bg - 8);
|
||||
else
|
||||
if(bg < 8)
|
||||
cur += sprintf(cur, "1;3%d;4%dm", fg - 8, bg);
|
||||
else
|
||||
cur += sprintf(cur, "5;1;3%d;4%dm", fg - 8, bg - 8);
|
||||
}
|
||||
|
||||
*cur++ = caca_utf32_to_cp437(ch);
|
||||
|
||||
prevfg = fg;
|
||||
prevbg = bg;
|
||||
}
|
||||
|
||||
if(cv->width == 80)
|
||||
{
|
||||
cur += sprintf(cur, "\033[s\n\033[u");
|
||||
}
|
||||
else
|
||||
{
|
||||
cur += sprintf(cur, "\033[0m\r\n");
|
||||
prevfg = -1;
|
||||
prevbg = -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Crop to really used size */
|
||||
debug("ansi export: alloc %lu bytes, realloc %lu",
|
||||
(unsigned long int)*bytes, (unsigned long int)(cur - data));
|
||||
*bytes = (uintptr_t)(cur - data);
|
||||
data = realloc(data, *bytes);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* Export a text file with IRC colours */
|
||||
void *_export_irc(caca_canvas_t const *cv, size_t *bytes)
|
||||
{
|
||||
static uint8_t const palette[] =
|
||||
{
|
||||
1, 2, 3, 10, 5, 6, 7, 15, /* Dark */
|
||||
14, 12, 9, 11, 4, 13, 8, 0, /* Light */
|
||||
};
|
||||
|
||||
char *data, *cur;
|
||||
int x, y;
|
||||
|
||||
/* 14 bytes assumed for max length per pixel. Worst case scenario:
|
||||
* ^Cxx,yy 6 bytes
|
||||
* ^B^B 2 bytes
|
||||
* ch 6 bytes
|
||||
* 3 bytes for max length per line. Worst case scenario:
|
||||
* <spc> 1 byte (for empty lines)
|
||||
* \r\n 2 bytes
|
||||
* In real life, the average bytes per pixel value will be around 5.
|
||||
*/
|
||||
|
||||
*bytes = 2 + cv->height * (3 + cv->width * 14);
|
||||
cur = data = malloc(*bytes);
|
||||
|
||||
for(y = 0; y < cv->height; y++)
|
||||
{
|
||||
uint32_t *lineattr = cv->attrs + y * cv->width;
|
||||
uint32_t *linechar = cv->chars + y * cv->width;
|
||||
|
||||
uint8_t prevfg = 0x10;
|
||||
uint8_t prevbg = 0x10;
|
||||
|
||||
for(x = 0; x < cv->width; x++)
|
||||
{
|
||||
uint32_t attr = lineattr[x];
|
||||
uint32_t ch = linechar[x];
|
||||
uint8_t ansifg, ansibg, fg, bg;
|
||||
|
||||
if(ch == CACA_MAGIC_FULLWIDTH)
|
||||
continue;
|
||||
|
||||
ansifg = caca_attr_to_ansi_fg(attr);
|
||||
ansibg = caca_attr_to_ansi_bg(attr);
|
||||
|
||||
fg = ansifg < 0x10 ? palette[ansifg] : 0x10;
|
||||
bg = ansibg < 0x10 ? palette[ansibg] : 0x10;
|
||||
|
||||
/* TODO: optimise series of same fg / same bg
|
||||
* don't change fg value if ch == ' '
|
||||
* make sure the \x03,%d trick works everywhere */
|
||||
if(bg != prevbg || fg != prevfg)
|
||||
{
|
||||
int need_escape = 0;
|
||||
|
||||
if(bg == 0x10)
|
||||
{
|
||||
if(fg == 0x10)
|
||||
cur += sprintf(cur, "\x0f");
|
||||
else
|
||||
{
|
||||
if(prevbg == 0x10)
|
||||
cur += sprintf(cur, "\x03%d", fg);
|
||||
else
|
||||
cur += sprintf(cur, "\x0f\x03%d", fg);
|
||||
|
||||
if(ch == (uint32_t)',')
|
||||
need_escape = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(fg == 0x10)
|
||||
cur += sprintf(cur, "\x0f\x03,%d", bg);
|
||||
else
|
||||
cur += sprintf(cur, "\x03%d,%d", fg, bg);
|
||||
}
|
||||
|
||||
if(ch >= (uint32_t)'0' && ch <= (uint32_t)'9')
|
||||
need_escape = 1;
|
||||
|
||||
if(need_escape)
|
||||
cur += sprintf(cur, "\x02\x02");
|
||||
}
|
||||
|
||||
cur += caca_utf32_to_utf8(cur, ch);
|
||||
prevfg = fg;
|
||||
prevbg = bg;
|
||||
}
|
||||
|
||||
/* TODO: do the same the day we optimise whole lines above */
|
||||
if(!cv->width)
|
||||
*cur++ = ' ';
|
||||
|
||||
*cur++ = '\r';
|
||||
*cur++ = '\n';
|
||||
}
|
||||
|
||||
/* Crop to really used size */
|
||||
debug("IRC export: alloc %lu bytes, realloc %lu",
|
||||
(unsigned long int)*bytes, (unsigned long int)(cur - data));
|
||||
*bytes = (uintptr_t)(cur - data);
|
||||
data = realloc(data, *bytes);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/* XXX : ANSI loader helper */
|
||||
|
||||
static void ansi_parse_grcm(caca_canvas_t *cv, struct import *im,
|
||||
unsigned int argc, unsigned int const *argv)
|
||||
{
|
||||
static uint8_t const ansi2caca[] =
|
||||
{
|
||||
CACA_BLACK, CACA_RED, CACA_GREEN, CACA_BROWN,
|
||||
CACA_BLUE, CACA_MAGENTA, CACA_CYAN, CACA_LIGHTGRAY
|
||||
};
|
||||
|
||||
unsigned int j;
|
||||
uint8_t efg, ebg; /* Effective (libcaca) fg/bg */
|
||||
|
||||
for(j = 0; j < argc; j++)
|
||||
{
|
||||
/* Defined in ECMA-48 8.3.117: SGR - SELECT GRAPHIC RENDITION */
|
||||
if(argv[j] >= 30 && argv[j] <= 37)
|
||||
im->fg = ansi2caca[argv[j] - 30];
|
||||
else if(argv[j] >= 40 && argv[j] <= 47)
|
||||
im->bg = ansi2caca[argv[j] - 40];
|
||||
else if(argv[j] >= 90 && argv[j] <= 97)
|
||||
im->fg = ansi2caca[argv[j] - 90] + 8;
|
||||
else if(argv[j] >= 100 && argv[j] <= 107)
|
||||
im->bg = ansi2caca[argv[j] - 100] + 8;
|
||||
else switch(argv[j])
|
||||
{
|
||||
case 0: /* default rendition */
|
||||
im->fg = im->dfg;
|
||||
im->bg = im->dbg;
|
||||
im->bold = im->blink = im->italics = im->negative
|
||||
= im->concealed = im->underline = im->faint = im->strike
|
||||
= im->proportional = 0;
|
||||
break;
|
||||
case 1: /* bold or increased intensity */
|
||||
im->bold = 1;
|
||||
break;
|
||||
case 2: /* faint, decreased intensity or second colour */
|
||||
im->faint = 1;
|
||||
break;
|
||||
case 3: /* italicized */
|
||||
im->italics = 1;
|
||||
break;
|
||||
case 4: /* singly underlined */
|
||||
im->underline = 1;
|
||||
break;
|
||||
case 5: /* slowly blinking (less then 150 per minute) */
|
||||
case 6: /* rapidly blinking (150 per minute or more) */
|
||||
im->blink = 1;
|
||||
break;
|
||||
case 7: /* negative image */
|
||||
im->negative = 1;
|
||||
break;
|
||||
case 8: /* concealed characters */
|
||||
im->concealed = 1;
|
||||
break;
|
||||
case 9: /* crossed-out (characters still legible but marked as to be
|
||||
* deleted */
|
||||
im->strike = 1;
|
||||
break;
|
||||
case 21: /* doubly underlined */
|
||||
im->underline = 1;
|
||||
break;
|
||||
case 22: /* normal colour or normal intensity (neither bold nor
|
||||
* faint) */
|
||||
im->bold = im->faint = 0;
|
||||
break;
|
||||
case 23: /* not italicized, not fraktur */
|
||||
im->italics = 0;
|
||||
break;
|
||||
case 24: /* not underlined (neither singly nor doubly) */
|
||||
im->underline = 0;
|
||||
break;
|
||||
case 25: /* steady (not blinking) */
|
||||
im->blink = 0;
|
||||
break;
|
||||
case 26: /* (reserved for proportional spacing as specified in CCITT
|
||||
* Recommendation T.61) */
|
||||
im->proportional = 1;
|
||||
break;
|
||||
case 27: /* positive image */
|
||||
im->negative = 0;
|
||||
break;
|
||||
case 28: /* revealed characters */
|
||||
im->concealed = 0;
|
||||
break;
|
||||
case 29: /* not crossed out */
|
||||
im->strike = 0;
|
||||
break;
|
||||
case 38: /* (reserved for future standardization, intended for setting
|
||||
* character foreground colour as specified in ISO 8613-6
|
||||
* [CCITT Recommendation T.416]) */
|
||||
break;
|
||||
case 39: /* default display colour (implementation-defined) */
|
||||
im->fg = im->dfg;
|
||||
break;
|
||||
case 48: /* (reserved for future standardization, intended for setting
|
||||
* character background colour as specified in ISO 8613-6
|
||||
* [CCITT Recommendation T.416]) */
|
||||
break;
|
||||
case 49: /* default background colour (implementation-defined) */
|
||||
im->bg = im->dbg;
|
||||
break;
|
||||
case 50: /* (reserved for cancelling the effect of the rendering
|
||||
* aspect established by parameter value 26) */
|
||||
im->proportional = 0;
|
||||
break;
|
||||
default:
|
||||
debug("ansi import: unknown sgr %i", argv[j]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(im->concealed)
|
||||
{
|
||||
efg = ebg = CACA_TRANSPARENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
efg = im->negative ? im->bg : im->fg;
|
||||
ebg = im->negative ? im->fg : im->bg;
|
||||
|
||||
if(im->bold)
|
||||
{
|
||||
if(efg < 8)
|
||||
efg += 8;
|
||||
else if(efg == CACA_DEFAULT)
|
||||
efg = CACA_WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
caca_set_color_ansi(cv, efg, ebg);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue