Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial check-in

  • Loading branch information...
commit b94f24ae1e7c2a66975153c8288da39ca66f55ef 0 parents
@fsphil authored
162 CHANGELOG
@@ -0,0 +1,162 @@
+
+fswebcam-20091224
+
+ - Fix memset() error in src_v4l1.c introduced in yesterdays release.
+ (Thomas Spahni)
+
+fswebcam-20091223
+
+ - Stop configure warning about datarootdir being ignored.
+ - Updated the videodev.h and videodev2.h header files.
+ - Corrected a number of memory leaks and a potential buffer overflow.
+ (Thomas Spahni)
+ - Escape minus signs in the man page. (Luca Niccoli)
+ - Removed debian/ subdirectory. (Luca Niccoli)
+ - Removed spec and ebuild files.
+ - Free mmap()'s on error.
+ - Stop skipping frames on error.
+
+fswebcam-20070108
+
+ - Fixed R<>B channel swap when using [M]JPEG or PNG.
+
+fswebcam-20061210
+
+ - Added syslog support via log command.
+ - Added pidfile command for saving the process ID (PID) to file.
+ - The output command has been replaced by the log command.
+ - Added framedump command for dumping the raw captured data to file.
+ - Added exec command for running external programs after capture.
+ - Removed unnecessary malloc.h includes, replaced with the more portable
+ stdlib.h where not already included. (Alexander Logvinov)
+ - Fixed small bug in and simplified the configure script.
+ - Fixed a bug where fswebcam wouldn't close a device if its file descriptor
+ was equal to zero. Affected RAW and V4L2 sources. (Dmitry Saychenko)
+ - The localtime command has been replaced by the new gmt command.
+ The local timezone is now used as the default.
+ - Added offset command to offset capture times in loop mode.
+ - Added file-based configuration support.
+ - Updated argument parser.
+ - Renamed RGB24 and RGB32 to BGR24 and BGR32, and added the real
+ RGB24 and RGB32 formats.
+ - Added signal handler for gracefully exiting loop mode, reloading
+ file-based configuration or for immediately capturing an image.
+ - Don't force an interlaced mode when using V4L2 source.
+ - Fixed RAW source to fail when no more data can be read from source.
+ - Added RAW source to the man page.
+
+fswebcam-20060604
+
+ - Even more configure fixes.
+ - Added NV12MB palette type (for raw source only).
+ - Added raw source support.
+ - V4L1/V4L2 header files included with source.
+ - More V4L2 configure fixes. (Gary E. Miller)
+
+fswebcam-20060424
+
+ - Improved V4L2 detection in configure script.
+ - Warn if there have been unsaved changes made to the image.
+ - Fixed a number of small message formatting errors.
+ - Fixed man page formatting.
+ - Be more verbose when adjusting to a new resolution. (Alexandre Bourget)
+ - Added MJPEG palette type.
+
+fswebcam-20060415
+
+ - Many other small fixes and changes.
+ - Insert DHT segment if missing from MJPEG frames. (Scott J. Bertin)
+ - Properly sets up resolution for V4L1 sources.
+ - New autoconf based configuration system.
+ - Added read support to V4L1 and V4L2 sources (if mmap is unavailable),
+ and an option to force read.
+ - Loop and background modes, allowing the program to run as a daemon.
+ - New job queue allows multiple images to be output from a single run,
+ each with different attributes.
+ - Filenames are now processed by strftime().
+ - Inputs can now be specified by name.
+ - Tweaked the deinterlacer a bit more.
+ - Timeout when devices take too long delivering a frame.
+ - Added support for YUYV and UYVY colour formats.
+ - Added support for the "Bayer Encoding" colour format. (V4L2 only)
+ - New source system added, allowing for more source types. Including:
+
+ v4l2 - Captures images using the V4L2 API.
+ v4l1 - The old V4L1 capture code has been moved here.
+ file - Reads a JPEG or PNG image from disk.
+ test - Draws colour bars.
+
+ - Release mmap before device is closed.
+ - Changed some char's to int8_t's for platforms where char may be unsigned.
+
+fswebcam-20050529
+
+ - Added option to skip a number of frames at the start of capture. This
+ helps when some of the early frames are corrupted like with the QuickCam.
+ - Added a test to make sure the selected font is useable.
+ - Added compile time option for increasing the number of frames that can be
+ captured and averaged.
+ - Fixed colour problem when using a JPEG capture device.
+ - Tweaked the deinterlacer a bit to reduce blurring in static areas.
+ - Removed some test code from the deinterlacer that found it's way into the
+ last release. D'oh!
+
+fswebcam-20050519
+
+ - When capturing from a QX5 microscope, the lights are turned on.
+ This will be removed when a separate light control app exists.
+ - Added support for MJPEG devices.
+ - Removed vflip and hflip options as this is done now with the flip effect.
+ - New effects system added, including:
+
+ flip - Flips the image horizontally or vertically.
+ crop - Crops a part of the image.
+ scale - Scales the image to a new size.
+ rotate - Rotates the image in right angles 90, 180 and 270 degrees.
+ deinterlace - A simple deinterlacer for video capture cards.
+ invert - Inverts the colours of the image, creating a negative.
+
+ - Capture width and height options combined into single resolution option.
+ - Releases capture device as soon as capturing is finished.
+ - Capture device is opened read/write instead of read only.
+ - Some small cosmetic fixes.
+
+fswebcam-20050308
+
+ - Added options to flip the image horizontally and vertically.
+ - Added missing copy of the GPL license.
+
+fswebcam-20050211
+
+ - Default frame count is now 1.
+ - Now using the faster integer-based YUV420P conversion code from camE:
+ http://linuxbrit.co.uk/camE/
+ - Added support for two more colour formats: RGB565 RGB555
+ - Added depth information into the palette table.
+ - Verbose mode now shows information about the size and number of buffers.
+
+fswebcam-20050210
+
+ - Added support for multiple colour formats: RGB32 RGB24 YUV420P GREY
+
+fswebcam-20041219
+
+ - Added an option to delay while a capture device settles down after a
+ channel or input change.
+
+fswebcam-20041031
+
+ - Tuner code was broken in yesterdays release. This fixes that as
+ well as adding awareness for low and high frequency ranges (KHz and MHz).
+
+fswebcam-20041030
+
+ - Much better now at preparing the capture device.
+ - Added many more options to control the banner.
+ - Added support for underlay and overlay images.
+ - A much needed cleanup.
+
+fswebcam-20040731
+
+ - Initial release.
+
340 LICENSE
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 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.
+
+ 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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.
41 Makefile.in
@@ -0,0 +1,41 @@
+# Makefile for fswebcam
+# [22/02/2006]
+
+SHELL = /bin/sh
+
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+bindir = @bindir@
+mandir = @mandir@
+datarootdir = @datarootdir@
+
+CC = @CC@
+CFLAGS = @CFLAGS@ @DEFS@
+LDFLAGS = @LDFLAGS@
+
+OBJS = fswebcam.o log.o effects.o parse.o src.o @SRC_OBJS@
+# src_test.o src_file.o src_v4l1.o src_v4l2.o
+
+all: fswebcam fswebcam.1.gz
+
+install: all
+ mkdir -p ${DESTDIR}${bindir}
+ mkdir -p ${DESTDIR}${mandir}/man1
+ install -m 755 fswebcam ${DESTDIR}${bindir}
+ install -m 644 fswebcam.1.gz ${DESTDIR}${mandir}/man1
+
+fswebcam: $(OBJS)
+ $(CC) $(LDFLAGS) $(OBJS) -o fswebcam
+
+.c.o:
+ ${CC} ${CFLAGS} -c $< -o $@
+
+fswebcam.1.gz: fswebcam.1
+ gzip -c --best fswebcam.1 > fswebcam.1.gz
+
+clean:
+ rm -f core* *.o fswebcam fswebcam.1.gz
+
+distclean: clean
+ rm -rf config.h *.cache config.log config.status Makefile *.jp*g *.png
+
22 README
@@ -0,0 +1,22 @@
+
+fswebcam - Small and simple webcam software for *nix.
+
+Created by Philip Heron <phil@firestorm.cx>
+http://www.firestorm.cx/fswebcam/
+
+This is the program used to generate images for a webcam. It captures a number
+of frames from any V4L or V4L2 compatible device, averages them to reduce noise
+and draws the details on it using the GD Graphics Library which also handles
+compressing the image to PNG or JPEG.
+
+INSTALLING
+
+Run the following commands in the source folder to build and install fswebcam:
+
+./configure --prefix=/usr
+make
+make install
+
+It's only requirements are that the GD library be installed with JPEG, PNG
+and FreeType support.
+
31 config.h.in
@@ -0,0 +1,31 @@
+/* config.h.in. Generated from configure.ac by autoheader. */
+
+/* Define to 1 if you have a working `mmap' system call. */
+#undef HAVE_MMAP
+
+/* bktr source support. */
+#undef HAVE_BKTR
+
+/* V4L1 source support. */
+#undef HAVE_V4L1
+
+/* V4L2 source support. */
+#undef HAVE_V4L2
+
+/* Define to the address where bug reports for this package should be sent. */
+#undef PACKAGE_BUGREPORT
+
+/* Define to the full name of this package. */
+#undef PACKAGE_NAME
+
+/* Define to the full name and version of this package. */
+#undef PACKAGE_STRING
+
+/* Define to the one symbol short name of this package. */
+#undef PACKAGE_TARNAME
+
+/* Define to the version of this package. */
+#undef PACKAGE_VERSION
+
+/* Allow capture of 2^32 frames */
+#undef USE_32BIT_BUFFER
5,413 configure
5,413 additions, 0 deletions not shown
86 configure.ac
@@ -0,0 +1,86 @@
+
+AC_INIT(fswebcam, 20091224, phil@firestorm.cx)
+AC_PROG_CC
+
+AC_ARG_ENABLE(32bit-buffer,
+ [ --enable-32bit-buffer allow capturing of 2^32 frames],
+ [BUFFER_BITS="32"
+ AC_DEFINE([USE_32BIT_BUFFER], [1], [Allow capture of 2^32 frames])],
+ [BUFFER_BITS="16"])
+
+SRC_OBJS="src_test.o src_raw.o src_file.o"
+
+dnl --- Test if V4L1 should be disabled. ---
+AC_ARG_ENABLE(v4l1,
+ [ --disable-v4l1 disable V4L1 support],
+ [HAVE_V4L1="no"],
+ [AC_DEFINE([HAVE_V4L1], [1], [V4L1 source support.])
+ SRC_OBJS="$SRC_OBJS src_v4l1.o"
+ HAVE_V4L1="yes"]
+)
+
+dnl --- Test if V4L2 should be disabled. ---
+
+AC_ARG_ENABLE(v4l2,
+ [ --disable-v4l2 disable V4L2 support],
+ [HAVE_V4L2="no"],
+ [AC_DEFINE([HAVE_V4L2], [1], [V4L2 source support.])
+ SRC_OBJS="$SRC_OBJS src_v4l2.o"
+ HAVE_V4L2="yes"]
+)
+
+AC_SUBST(SRC_OBJS)
+
+AC_FUNC_MMAP
+
+AC_CHECK_LIB(gd, gdImageCreateTrueColor, HAVE_GD="yes",,)
+if test "$HAVE_GD" != "yes"; then
+ AC_MSG_ERROR([GD graphics library not found])
+else
+ LDFLAGS="-lgd $LDFLAGS"
+fi
+
+AC_CHECK_LIB(gd, gdImageStringFT, HAVE_FT2="yes",,)
+if test "$HAVE_FT2" != "yes"; then
+ AC_MSG_ERROR([GD does not have FreeType2 font support!])
+fi
+
+AC_CHECK_LIB(gd, gdImageJpeg, HAVE_JPEG="yes",,)
+if test "$HAVE_JPEG" != "yes"; then
+ AC_MSG_ERROR([GD does not have JPEG support!])
+fi
+
+AC_CHECK_LIB(gd, gdImagePngEx, HAVE_PNG="yes",,)
+if test "$HAVE_PNG" != "yes"; then
+ AC_MSG_ERROR([GD does not have PNG support!])
+fi
+
+# The V4Lx headers are now included along with the source.
+
+#AC_CHECK_HEADER(linux/videodev.h, HAVE_V4L1="yes",,)
+#if test "$HAVE_V4L1" == "yes"; then
+# AC_DEFINE([HAVE_V4L1], [1], [V4L1 source support.])
+#fi
+
+#AC_CHECK_HEADERS([linux/videodev2.h], HAVE_V4L2="yes",,[
+##include <sys/types.h>
+##include <sys/time.h>
+##include <linux/videodev.h>
+#])
+#if test "$HAVE_V4L2" == "yes"; then
+# AC_DEFINE([HAVE_V4L2], [1], [V4L2 source support.])
+#fi
+
+AC_MSG_RESULT([
+ Buffer type ........... $BUFFER_BITS bit
+ PNG support ........... $HAVE_PNG
+ JPEG support .......... $HAVE_JPEG
+ Freetype 2.x support .. $HAVE_FT2
+ V4L1 support .......... $HAVE_V4L1
+ V4L2 support .......... $HAVE_V4L2
+])
+
+AC_CONFIG_FILES(Makefile)
+AC_CONFIG_HEADER(config.h)
+AC_OUTPUT
+
337 effects.c
@@ -0,0 +1,337 @@
+/* fswebcam - FireStorm.cx's webcam generator */
+/*===========================================================*/
+/* Copyright (C)2005-2006 Philip Heron <phil@firestorm.cx> */
+/* */
+/* This program is distributed under the terms of the GNU */
+/* General Public License, version 2. You may use, modify, */
+/* and redistribute it under the terms of this license. A */
+/* copy should be included with this source. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <gd.h>
+#include "parse.h"
+#include "log.h"
+
+/* These helper macros should maybe be moved elsewhere. */
+
+#define RGB(r, g, b) ((r << 16) + (g << 8) + b)
+
+#define R(c) ((c & 0xFF0000) >> 16)
+#define G(c) ((c & 0xFF00) >> 8)
+#define B(c) (c & 0xFF)
+
+#define GREY(c) ((R(c) + G(c) + B(c)) / 3)
+#define MIX(a, b, c) (a + (((b - a) * c) / 0xFF))
+
+#define RGBMIX(c1, c2, d) \
+ (RGB(MIX(R(c1), R(c2), d), MIX(G(c1), G(c2), d), MIX(B(c1), G(c2), d)))
+
+gdImage *fx_flip(gdImage *src, char *options)
+{
+ int i;
+ char d[32];
+
+ i = 0;
+ while(!argncpy(d, 32, options, ", \t", i++, 0))
+ {
+ if(*d == 'v')
+ {
+ int y, h;
+ gdImage *line;
+
+ MSG("Flipping image vertically.");
+
+ line = gdImageCreateTrueColor(gdImageSX(src), 1);
+ h = gdImageSY(src) / 2;
+
+ for(y = 0; y < h; y++)
+ {
+ /* Copy bottom line into buffer. */
+ gdImageCopy(line, src,
+ 0, 0,
+ 0, gdImageSY(src) - y - 1,
+ gdImageSX(src), 1);
+
+ /* Copy the top line onto the bottom. */
+ gdImageCopy(src, src,
+ 0, gdImageSY(src) - y - 1,
+ 0, y,
+ gdImageSX(src), 1);
+
+ /* Copy the buffer into the top. */
+ gdImageCopy(src, line,
+ 0, y,
+ 0, 0,
+ gdImageSX(src), 1);
+ }
+
+ gdImageDestroy(line);
+ }
+ else if(*d == 'h')
+ {
+ int x, w;
+ gdImage *line;
+
+ MSG("Flipping image horizontally.");
+
+ line = gdImageCreateTrueColor(1, gdImageSY(src));
+ w = gdImageSX(src) / 2;
+
+ for(x = 0; x < w; x++)
+ {
+ /* Copy right line into buffer. */
+ gdImageCopy(line, src,
+ 0, 0,
+ gdImageSX(src) - x - 1, 0,
+ 1, gdImageSY(src));
+
+ /* Copy the left line onto the right. */
+ gdImageCopy(src, src,
+ gdImageSX(src) - x - 1, 0,
+ x, 0,
+ 1, gdImageSY(src));
+
+ /* Copy the buffer into the left. */
+ gdImageCopy(src, line,
+ x, 0,
+ 0, 0,
+ 1, gdImageSY(src));
+ }
+
+ gdImageDestroy(line);
+ }
+ else WARN("Unknown flip direction: %s", d);
+ }
+
+ return(src);
+}
+
+gdImage *fx_crop(gdImage *src, char *options)
+{
+ char arg[32];
+ int w, h, x, y;
+ gdImage *im;
+
+ if(argncpy(arg, 32, options, ", \t", 0, 0))
+ {
+ WARN("Invalid area to crop: %s", arg);
+ return(src);
+ }
+
+ w = argtol(arg, "x ", 0, 0, 10);
+ h = argtol(arg, "x ", 1, 0, 10);
+
+ if(w < 0 || h < 0)
+ {
+ WARN("Invalid area to crop: %s", arg);
+ return(src);
+ }
+
+ /* Make sure crop area resolution is smaller than the source image. */
+ if(w > gdImageSX(src) ||
+ h > gdImageSY(src))
+ {
+ WARN("Crop area is larger than the image!");
+ return(src);
+ }
+
+ /* Get the offset. */
+ x = -1;
+ y = -1;
+
+ if(!argncpy(arg, 32, options, ", \t", 1, 0))
+ {
+ x = argtol(arg, "x ", 0, 0, 10);
+ y = argtol(arg, "x ", 1, 0, 10);
+ }
+
+ if(x < 0 || y < 0)
+ {
+ /* By default crop the center of the image. */
+ x = (gdImageSX(src) - w) / 2;
+ y = (gdImageSY(src) - h) / 2;
+ }
+
+ MSG("Cropping image from %ix%i [offset: %ix%i] -> %ix%i.",
+ gdImageSX(src), gdImageSY(src), x, y, w, h);
+
+ im = gdImageCreateTrueColor(w, h);
+ if(!im)
+ {
+ WARN("Out of memory.");
+ return(src);
+ }
+
+ gdImageCopy(im, src, 0, 0, x, y, w, h);
+
+ gdImageDestroy(src);
+
+ return(im);
+}
+
+gdImage *fx_scale(gdImage *src, char *options)
+{
+ int w, h;
+ gdImage *im;
+
+ w = argtol(options, "x ", 0, 0, 10);
+ h = argtol(options, "x ", 1, 0, 10);
+
+ if(w < 0 || h < 0)
+ {
+ WARN("Invalid resolution: %s", options);
+ return(src);
+ }
+
+ MSG("Scaling image from %ix%i -> %ix%i.",
+ gdImageSX(src), gdImageSY(src), w, h);
+
+ im = gdImageCreateTrueColor(w, h);
+ if(!im)
+ {
+ WARN("Out of memory.");
+ return(src);
+ }
+
+ gdImageCopyResampled(im, src, 0, 0, 0, 0,
+ w, h, gdImageSX(src), gdImageSY(src));
+
+ gdImageDestroy(src);
+
+ return(im);
+}
+
+gdImage *fx_rotate(gdImage *src, char *options)
+{
+ int x, y;
+ gdImage *im;
+ int angle = atoi(options);
+
+ /* Restrict angle to 0-360 range. */
+ if((angle %= 360) < 0) angle += 360;
+
+ /* Round to nearest right angle. */
+ x = (angle + 45) % 360;
+ angle = x - (x % 90);
+
+ /* Not rotating 0 degrees. */
+ if(angle == 0)
+ {
+ MSG("Not rotating 0 degrees.");
+ return(src);
+ }
+
+ /* 180 can be done with two flips. */
+ if(angle == 180)
+ {
+ fx_flip(src, "h,v");
+ return(src);
+ }
+
+ MSG("Rotating image %i degrees. %ix%i -> %ix%i.", angle,
+ gdImageSX(src), gdImageSY(src),
+ gdImageSY(src), gdImageSX(src));
+
+ /* Create rotated image. */
+ im = gdImageCreateTrueColor(gdImageSY(src), gdImageSX(src));
+ if(!im)
+ {
+ WARN("Out of memory.");
+ return(src);
+ }
+
+ for(y = 0; y < gdImageSY(src); y++)
+ for(x = 0; x < gdImageSX(src); x++)
+ {
+ int c = gdImageGetPixel(src, x, y);
+
+ if(angle == 90)
+ {
+ gdImageSetPixel(im, gdImageSX(im) - y - 1, x, c);
+ }
+ else
+ {
+ gdImageSetPixel(im, y, gdImageSY(im) - x - 1, c);
+ }
+ }
+
+ gdImageDestroy(src);
+
+ return(im);
+}
+
+/*
+ * This is a very simple and experimental deinterlacer,
+ * there is a lot of room for improvement here.
+ *
+ * (For example: Making it work)
+ *
+*/
+gdImage *fx_deinterlace(gdImage *src, char *options)
+{
+ int x, y;
+
+ MSG("Deinterlacing image.");
+
+ for(y = 1; y < gdImageSY(src) - 1; y += 2)
+ {
+ for(x = 0; x < gdImageSX(src); x++)
+ {
+ int c, cu, cd, d;
+
+ c = gdImageGetPixel(src, x, y);
+ cu = gdImageGetPixel(src, x, y - 1);
+ cd = gdImageGetPixel(src, x, y + 1);
+
+ /* Calculate the difference of the pixel (x,y) from
+ * the average of it's neighbours above and below. */
+ d = 0xFF - abs(GREY(cu) - GREY(cd));
+ d = (abs(GREY(cu) - (0xFF - GREY(c)) - GREY(cd)) * d) / 0xFF;
+
+ c = RGBMIX(c, RGBMIX(cu, cd, 128), d);
+
+ gdImageSetPixel(src, x, y, c);
+ }
+ }
+
+ return(src);
+}
+
+gdImage *fx_invert(gdImage *src, char *options)
+{
+ int x, y;
+
+ MSG("Inverting image.");
+
+ for(y = 0; y < gdImageSY(src); y++)
+ for(x = 0; x < gdImageSX(src); x++)
+ {
+ /* Overwrite the pixel with a negative of its value. */
+ gdImageSetPixel(src, x, y,
+ 0xFFFFFF - gdImageGetPixel(src, x, y));
+ }
+
+ return(src);
+}
+
+gdImage *fx_greyscale(gdImage *src, char *options)
+{
+ int x, y;
+
+ MSG("Greyscaling image.");
+
+ for(y = 0; y < gdImageSY(src); y++)
+ for(x = 0; x < gdImageSX(src); x++)
+ {
+ uint8_t c = GREY(gdImageGetPixel(src, x, y));
+ gdImageSetPixel(src, x, y, RGB(c, c, c));
+ }
+
+ return(src);
+}
+
23 effects.h
@@ -0,0 +1,23 @@
+/* fswebcam - FireStorm.cx's webcam generator */
+/*===========================================================*/
+/* Copyright (C)2005 Philip Heron <phil@firestorm.cx> */
+/* */
+/* This program is distributed under the terms of the GNU */
+/* General Public License, version 2. You may use, modify, */
+/* and redistribute it under the terms of this license. A */
+/* copy should be included with this source. */
+
+#ifndef INC_EFFECTS_H
+#define INC_EFFECTS_H
+
+extern gdImage *fx_flip(gdImage *src, char *options);
+extern gdImage *fx_crop(gdImage *src, char *options);
+extern gdImage *fx_scale(gdImage *src, char *options);
+extern gdImage *fx_rotate(gdImage *src, char *options);
+extern gdImage *fx_deinterlace(gdImage *src, char *options);
+extern gdImage *fx_invert(gdImage *src, char *options);
+extern gdImage *fx_blur(gdImage *src, char *options);
+extern gdImage *fx_greyscale(gdImage *src, char *options);
+
+#endif
+
51 example.conf
@@ -0,0 +1,51 @@
+# Example configuration for fswebcam
+# [2006-09-05: phil@firestorm.cx]
+
+# Be very quiet...
+quiet
+
+# Or be very loud?
+#verbose
+
+# The image source - In this case we are capturing frames from a TV channel
+device "v4l2:/dev/video0"
+input 0
+frequency 670.90
+palette YUV420P
+resolution 768x576
+
+skip 2 # Skip the first two frames.
+frames 1 # And capture one.
+
+# Move the banner to the top and make the background 100% transparent.
+top-banner
+font "/home/user/.fonts/luxisr.ttf"
+title "Webcam 1"
+info "The Office"
+banner-colour #FF000000
+line-colour #FF000000
+
+# Save it to a shared folder.
+save "/home/user/public_html/02-large.jpeg"
+
+# Save another copy for the archive. The archive contains a folder for each
+# day of images. First we create the folder if it doesn't already exist.
+exec "mkdir /home/user/archive/%Y%m%d 2> /dev/null"
+
+# Then save the image into it.
+save "/home/user/archive/%Y%m%d/01-%Y%m%d-%H%M%S.jpeg"
+
+# Scale the image down to half it's size.
+scale 384x288
+
+# Move the banner to the bottom and give it some colour.
+bottom-banner
+banner-colour \#40263A93
+line-colour \#00FF0000
+
+# Load an overlay image. This is placed above everything, including the banner.
+overlay "/home/user/outline.png"
+
+# Save this to the shared folder.
+save "/home/user/public_html/02.jpeg"
+
425 fswebcam.1
@@ -0,0 +1,425 @@
+.TH FSWEBCAM "1" "24 December 2009" "fswebcam 20091224" "User Commands"
+.SH NAME
+fswebcam \- Small and simple webcam for *nix.
+.SH SYNOPSIS
+.B fswebcam
+[\fI<options>\fR] \fI<filename>\fR [[\fI<options>\fR] \fI<filename>\fR ... ]
+.SH DESCRIPTION
+.PP
+fswebcam is a small and simple webcam app for *nix. It can capture images from a number of different sources and perform simple manipulation on the captured image. The image can be saved as one or more PNG or JPEG files.
+.PP
+The PNG or JPEG image can be sent to stdio using the filename "\-". The output filename is formatted by \fBstrftime\fR.
+
+.SH CONFIGURATION
+
+.SS
+Configuration File
+
+.TP
+Config files use the long version of options without the "\-\-" prefix. Comments start with a # symbol at the beginning of the line.
+
+.SS
+General Options
+
+.TP
+\fB\-?\fR, \fB\-\-help\fR
+Show a usage summary.
+
+.TP
+\fB\-c\fR, \fB\-\-config\fR
+Load options from a file. You can load more than one config file, and can mix them with command\-line arguments.
+
+Note: This option can not be used from within a configuration file.
+
+.TP
+\fB\-q\fR, \fB\-\-quiet\fR
+Hides all messages except errors.
+
+.TP
+\fB\-v\fR, \fB\-\-verbose\fR
+Print extra information during the capture process.
+
+.TP
+\fB\-\-version\fR
+Print the version number and exit.
+
+.TP
+\fB\-l\fR, \fB\-\-loop\fR \fI<frequency>\fR
+Continually capture images. The time between images is specified in seconds.
+.IP
+Default behaviour is to capture a single image and exit.
+.IP
+\fINote\fR: The time to capture the next image is calculated relative to the epoch, so an image will not be captured immediately when the program is first started.
+
+.TP
+\fB\-\-offset\fR \fI<seconds>\fR
+Sets the offset to use when calculating when the next image is due in loop mode. Value can be positive or negative.
+
+.TP
+\fB\-b\fR, \fB\-\-background\fR
+Run in the background. In this mode \fIstdout\fR and console logging are unavailable.
+
+.TP
+\fB\-\-pid\fR \fI<filename>\fR
+Saves the PID of the background process to the specified file. Ignored when not using background mode.
+
+.TP
+\fB\-\-log\fR \fI[file/syslog:]<filename>\fR
+Redirect log messages to a file or syslog. For example
+.IP
+\-\-log output.log
+.br
+\-\-log file:output.log
+.br
+\-\-log syslog
+
+.TP
+\fB\-\-gmt\fR
+Use GMT instead of the local timezone when formatting text with \fBstrftime\fR.
+
+.SS
+Capture Options
+
+.TP
+\fB\-d\fR, \fB\-\-device\fR \fI[<prefix>:]<device name>\fR
+Set the source or device to use. The source module is selected automatically unless specified in the prefix.
+.IP
+Default is \fI/dev/video0\fR.
+.IP
+Available source modules, in order of preference:
+.IP
+V4L2 \- Capture images from a V4L2 compatible video device.
+.br
+V4L1 \- Capture images from a V4L1 compatible video device.
+.br
+FILE \- Capture an image from a JPEG or PNG image file.
+.br
+RAW \- Reads images straight from a device or file.
+.br
+TEST \- Draws colour bars.
+
+.TP
+\fB\-i\fR, \fB\-\-input\fR \fI<input number or name>\fR
+Set the input to use. You may select an input by either it's number or name.
+.IP
+Default is "0".
+
+.TP
+\fB\-\-list\-inputs\fR
+List available inputs for the selected source or device.
+.IP
+fswebcam \-d v4l2:/dev/video1 \-\-list\-inputs
+
+.TP
+\fB\-t\fR, \fB\-\-tuner\fR \fI<tuner number>\fR
+Set the tuner to use.
+
+.TP
+\fB\-f\fR, \fB\-\-frequency\fR \fI<frequency>\fR
+Set the frequency of the selected input or tuner. The value may be read as KHz or MHz depending on the input or tuner.
+
+.TP
+\fB\-p\fR, \fB\-\-palette\fR \fI<name>\fR
+Try to use the specified image format when capturing the image.
+.IP
+Default is to select one automatically.
+.IP
+Supported formats:
+.IP
+PNG
+.br
+JPEG
+.br
+MJPEG
+.br
+RGB32
+.br
+RGB24
+.br
+BGR32
+.br
+BGR24
+.br
+YUYV
+.br
+UYVY
+.br
+YUV420P
+.br
+BAYER
+.br
+RGB565
+.br
+RGB555
+.br
+GREY
+
+.TP
+\fB\-r\fR, \fB\-\-resolution\fR \fI<dimensions>\fR
+Set the image resolution of the source or device. The actual resolution used may differ if the source or device cannot capture at the specified resolution.
+.IP
+Default is "384x288".
+
+.TP
+\fB\-\-list\-framesizes\fR
+Lists the supported resolutions for the selected source.
+
+.TP
+\fB\-\-list\-framerates\fR
+Lists the supported frame rates for the selected source and resolution.
+
+.TP
+\fB\-F\fR, \fB\-\-frames\fR \fI<number>\fR
+Set the number of frames to capture. More frames mean less noise in the final image, however capture times will be longer and moving objects may appear blurred.
+.IP
+Default is "1".
+
+.TP
+\fB\-S\fR, \fB\-\-skip\fR \fI<number>\fR
+Set the number of frames to skip. These frames will be captured but won't be use. Use this option if your camera sends some bad or corrupt frames when it first starts capturing.
+.IP
+Default is "0".
+
+.TP
+\fB\-D\fR, \fB\-\-delay\fR \fI<delay>\fR
+Inserts a delay after the source or device has been opened and initialised, and before the capture begins. Some devices need this delay to let the image settle after a setting has changed. The delay time is specified in seconds.
+
+.TP
+\fB\-R\fR, \fB\-\-read\fR
+Use read() to capture images. This can be slower but more stable with some devices.
+.IP
+Default is to use mmap(), falling back on read() if mmap() is unavailable.
+
+.TP
+\fB\-s\fR, \fB\-\-set\fR \fI<name=value>\fI
+Set a control. These are used by the source modules to control image or device parameters. Numeric values can be expressed as a percentage of there maximum range or a literal value, for example:
+.IP
+\-\-set brightness=50%
+\-\-set framerate=5
+.IP
+Non\-numeric controls are also supported:
+.IP
+\-\-set lights=on
+.IP
+V4L2 features a type of control called a 'button'. These controls do not take any value, but trigger an action. For example:
+.IP
+\-\-set "Restore Factory Settings"
+.IP
+Control names and values are not case sensitive.
+.IP
+\fINote\fR: Available controls will vary depending in the source module and devices used. For more information see the \fB\-\-list\-controls\fR option.
+
+.TP
+\fB\-\-list\-controls\fR
+List available controls and their current values for the selected source module and device. For example:
+.IP
+fswebcam \-d v4l2:/dev/video2 \-\-list\-controls
+
+.SS
+Output Options
+
+.TP
+These options are performed in the order they appear on the command line, only effecting images output later on the command line. For example:
+.IP
+fswebcam \-r 640x480 output1.jpeg \-\-scale 320x240 output2.jpeg
+.IP
+Will create two images, "output1.jpeg" containing a full resolution copy of the captured image and "output2.jpeg" containing the same captured image but scaled to half the size.
+
+.TP
+\fB\-\-no\-banner\fR
+Disable the banner.
+
+.TP
+\fB\-\-top\-banner\fR
+Position the banner at the top of the image.
+
+.TP
+\fB\-\-bottom\-banner\fR
+Position the banner at the bottom of the image.
+.IP
+This is the default.
+
+.TP
+\fB\-\-banner\-colour\fR \fI<#AARRGGBB>\fR
+Set the colour of the banner. Uses the web\-style hexadecimal format (#RRGGBB) to describe the colour, and can support an alpha channel (#AARRGGBB). Examples:
+.IP
+"#FF0000" is pure red.
+.br
+"#80000000" is semi\-transparent black.
+.br
+"#FF000000" is invisible (alpha channel is at maximum).
+.br
+Default is "#40263A93".
+
+.TP
+\fB\-\-line\-colour\fR \fI<#AARRGGBB>\fR
+Set the colour of the divider line. See \fB\-\-banner\-colour\fR for more information.
+.IP
+Default is "#00FF0000".
+
+.TP
+\fB\-\-text\-colour\fR \fI<#AARRGGBB>\fR
+Set the colour of the text. See \fB\-\-banner\-colour\fR for more information.
+.IP
+Default is "#00FFFFFF".
+
+.TP
+\fB\-\-font\fR \fI<[file or font name]:[font size]>\fR
+Set the font used in the banner. If no path is specified the path in the GDFONTPATH environment variable is searched for the font.
+.IP
+If no font size is specified the default of "10" will be used.
+.IP
+Default is "luxisr:10".
+
+.TP
+\fB\-\-no\-shadow\fR
+Disable the text shadow.
+
+.TP
+\fB\-\-shadow\fR
+Enable the text shadow.
+.IP
+This is the default behaviour.
+
+.TP
+\fB\-\-title\fR \fI<text>\fR
+Set the main text, located in the top left of the banner.
+
+.TP
+\fB\-\-no\-title\fR
+Clear the main text.
+
+.TP
+\fB\-\-subtitle\fR \fI<text>\fR
+Set the sub\-title text, located in the bottom left of the banner.
+
+.TP
+\fB\-\-no\-subtitle\fR
+Clear the sub\-title text.
+
+.TP
+\fB\-\-timestamp\fR \fI<text>\fR
+Set the timestamp text, located in the top right of the banner. This string is formatted by \fBstrftime\fP.
+.IP
+Default is "%Y\-%m\-%d %H:%M (%Z)".
+
+.TP
+\fB\-\-no\-timestamp\fR
+Clear the timestamp text.
+
+.TP
+\fB\-\-info\fR \fI<text>\fR
+Set the info text, located in the bottom right of the banner.
+
+.TP
+\fB\-\-no\-info\fR
+Clear the info text.
+
+.TP
+\fB\-\-underlay\fR \fI<filename>\fR
+Load a PNG image and overlay it on the image, below the banner. The image is aligned to the top left.
+.IP
+\fINote\fR: The underlay is only applied when saving an image and is not modified by any of the image options or effects.
+
+.TP
+\fB\-\-no\-underlay\fR
+Clear the underlay image.
+
+.TP
+\fB\-\-overlay\fR \fI<filename>\fR
+Load a PNG image and overlay on the image, above the banner. The image is aligned to the top left.
+.IP
+\fINote\fR: The overlay is only applied when saving an image and is not modified by any of the image options or effects.
+
+.TP
+\fB\-\-no\-overlay\fR
+Remove the overlay image.
+
+.TP
+\fB\-\-jpeg\fR \fI<factor>\fR
+Set JPEG as the output image format. The compression factor is a value between 0 and 95, or \-1 for automatic.
+.IP
+This is the default format, with a factor of "\-1".
+
+.TP
+\fB\-\-png\fR \fI<factor>\fR
+Set PNG as the output image format. The compression factor can be a value between 0 and 9, or \-1 for automatic.
+
+.TP
+\fB\-\-save\fR \fI<filename>\fR
+Saves the image to the specified filename.
+
+Note: This isn't necessary on the command\-line where a filename alone is enough to save an image.
+
+.TP
+\fB\-\-revert\fR
+Revert to the original captured image and resolution. This undoes all previous effects on the image.
+
+Note: This only reverts the image itself, and not options such as font, colours and overlay.
+
+.TP
+\fB\-\-flip\fR \fI<direction[,direction]>\fI
+Flips the image. Direction can be (h)orizontal or (v)ertical. Example:
+.IP
+\-\-flip h Flips the image horizontally.
+.br
+\-\-flip h,v Flips the image both horizontally and vertically.
+
+.TP
+\fB\-\-crop\fR \fI<dimensions[,offset]>\fR
+Crop the image. With no offset the cropped area will be the center of the image. Example:
+.IP
+\-\-crop 320x240 Crops the center 320x240 area of the image.
+.br
+\-\-crop 10x10,0x0 Crops the 10x10 area at the top left corner of the image.
+
+.TP
+\fB\-\-scale\fR <dimensions>
+Scale the image.
+.IP
+Example: "\-\-scale 640x480" scales the image up or down to 640x480.
+.IP
+\fINote:\fR The aspect ratio of the image is not maintained.
+
+.TP
+\fB\-\-rotate\fR \fI<angle>\fR
+Rotate the image in right angles (90, 180 and 270 degrees).
+.IP
+\fINote:\fR Rotating the image 90 or 270 degrees will swap the dimensions.
+
+.TP
+\fB\-\-deinterlace\fR
+Apply a simple deinterlacer to the image.
+
+.TP
+\fB\-\-invert\fR
+Invert all the colours in the image, creating a negative.
+
+.TP
+\fB\-\-exec\fR <command>
+Executes the specified command and waits for it to complete before continuing. The command line is formatted by \fBstrftime\fR.
+
+.SH SIGNALS
+
+.TP
+\fBSIGHUP\fR
+This causes fswebcam to reload it's configuration.
+
+.TP
+\fBSIGUSR1\fR
+Causes fswebcam to capture an image immediately without waiting on the timer in loop mode.
+
+.SH KNOWN BUGS
+The spacing between letters may be incorrect. This is an issue with the GD library.
+
+.SH REPORTING BUGS
+Please report bugs to <phil@firestorm.cx>.
+
+.SH SEE ALSO
+\fB
+ncftpput(1), strftime(3)
+\fP
+
+.SH AUTHOR
+Written by Philip Heron <phil@firestorm.cx>.
+
2,162 fswebcam.c
@@ -0,0 +1,2162 @@
+/* fswebcam - Small and simple webcam for *nix */
+/*===========================================================*/
+/* Copyright (C)2005-2009 Philip Heron <phil@firestorm.cx> */
+/* */
+/* This program is distributed under the terms of the GNU */
+/* General Public License, version 2. You may use, modify, */
+/* and redistribute it under the terms of this license. A */
+/* copy should be included with this source. */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdio.h>
+#include <getopt.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
+#include <gd.h>
+#include <errno.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "log.h"
+#include "src.h"
+#include "effects.h"
+#include "parse.h"
+
+#define CLIP(val, min, max) (val > max) ? max : ((val < min) ? min : val)
+
+#define ALIGN_LEFT (0)
+#define ALIGN_CENTER (1)
+#define ALIGN_RIGHT (2)
+
+#define NO_BANNER (0)
+#define TOP_BANNER (1)
+#define BOTTOM_BANNER (2)
+
+#define FORMAT_JPEG (0)
+#define FORMAT_PNG (1)
+
+#define OPTBASE (128)
+#define OPT_VERSION (OPTBASE + 0)
+#define OPT_PID (OPTBASE + 1)
+#define OPT_OFFSET (OPTBASE + 2)
+#define OPT_LIST_INPUTS (OPTBASE + 3)
+#define OPT_LIST_TUNERS (OPTBASE + 4)
+#define OPT_LIST_FORMATS (OPTBASE + 5)
+#define OPT_LIST_CONTROLS (OPTBASE + 6)
+#define OPT_LIST_FRAMESIZES (OPTBASE + 7)
+#define OPT_LIST_FRAMERATES (OPTBASE + 8)
+#define OPT_BRIGHTNESS (OPTBASE + 9)
+#define OPT_HUE (OPTBASE + 10)
+#define OPT_COLOUR (OPTBASE + 11)
+#define OPT_CONTRAST (OPTBASE + 12)
+#define OPT_WHITENESS (OPTBASE + 13)
+#define OPT_REVERT (OPTBASE + 14)
+#define OPT_FLIP (OPTBASE + 15)
+#define OPT_CROP (OPTBASE + 16)
+#define OPT_SCALE (OPTBASE + 17)
+#define OPT_ROTATE (OPTBASE + 18)
+#define OPT_DEINTERLACE (OPTBASE + 19)
+#define OPT_INVERT (OPTBASE + 20)
+#define OPT_GREYSCALE (OPTBASE + 21)
+#define OPT_NO_BANNER (OPTBASE + 22)
+#define OPT_TOP_BANNER (OPTBASE + 23)
+#define OPT_BOTTOM_BANNER (OPTBASE + 24)
+#define OPT_BG_COLOUR (OPTBASE + 25)
+#define OPT_BL_COLOUR (OPTBASE + 26)
+#define OPT_FG_COLOUR (OPTBASE + 27)
+#define OPT_FONT (OPTBASE + 28)
+#define OPT_NO_SHADOW (OPTBASE + 29)
+#define OPT_SHADOW (OPTBASE + 30)
+#define OPT_TITLE (OPTBASE + 31)
+#define OPT_NO_TITLE (OPTBASE + 32)
+#define OPT_SUBTITLE (OPTBASE + 33)
+#define OPT_NO_SUBTITLE (OPTBASE + 34)
+#define OPT_TIMESTAMP (OPTBASE + 35)
+#define OPT_NO_TIMESTAMP (OPTBASE + 36)
+#define OPT_GMT (OPTBASE + 37)
+#define OPT_INFO (OPTBASE + 38)
+#define OPT_NO_INFO (OPTBASE + 39)
+#define OPT_UNDERLAY (OPTBASE + 40)
+#define OPT_NO_UNDERLAY (OPTBASE + 41)
+#define OPT_OVERLAY (OPTBASE + 42)
+#define OPT_NO_OVERLAY (OPTBASE + 43)
+#define OPT_JPEG (OPTBASE + 44)
+#define OPT_PNG (OPTBASE + 45)
+#define OPT_SAVE (OPTBASE + 46)
+#define OPT_EXEC (OPTBASE + 47)
+#define OPT_DUMPFRAME (OPTBASE + 48)
+
+typedef struct {
+
+ /* List of options. */
+ char *opts;
+ const struct option *long_opts;
+
+ /* When reading from the command line. */
+ int opt_index;
+
+ /* When reading from a configuration file. */
+ char *filename;
+ FILE *f;
+ size_t line;
+
+} fswc_getopt_t;
+
+typedef struct {
+ uint16_t id;
+ char *options;
+} fswebcam_job_t;
+
+typedef struct {
+
+ /* General options. */
+ unsigned long loop;
+ signed long offset;
+ unsigned char background;
+ char *pidfile;
+ char *logfile;
+ char gmt;
+
+ /* Capture start time. */
+ time_t start;
+
+ /* Device options. */
+ char *device;
+ char *input;
+ unsigned char tuner;
+ unsigned long frequency;
+ unsigned long delay;
+ char use_read;
+ uint8_t list;
+
+ /* Image capture options. */
+ unsigned int width;
+ unsigned int height;
+ unsigned int frames;
+ unsigned int skipframes;
+ int palette;
+ src_option_t **option;
+ char *dumpframe;
+
+ /* Job queue. */
+ uint8_t jobs;
+ fswebcam_job_t **job;
+
+ /* Banner options. */
+ char banner;
+ uint32_t bg_colour;
+ uint32_t bl_colour;
+ uint32_t fg_colour;
+ char *title;
+ char *subtitle;
+ char *timestamp;
+ char *info;
+ char *font;
+ int fontsize;
+ char shadow;
+
+ /* Overlay options. */
+ char *underlay;
+ char *overlay;
+
+ /* Output options. */
+ char *filename;
+ char format;
+ char compression;
+
+} fswebcam_config_t;
+
+#ifdef USE_32BIT_BUFFER
+
+typedef uint32_t avgbmp_t;
+#define MAX_FRAMES (UINT32_MAX >> 8)
+
+#else
+
+typedef uint16_t avgbmp_t;
+#define MAX_FRAMES (UINT16_MAX >> 8)
+
+#endif
+
+volatile char received_sigusr1 = 0;
+volatile char received_sighup = 0;
+volatile char received_sigterm = 0;
+
+void fswc_signal_usr1_handler(int signum)
+{
+ /* Catches SIGUSR1 */
+ INFO("Caught signal SIGUSR1.");
+ received_sigusr1 = 1;
+}
+
+void fswc_signal_hup_handler(int signum)
+{
+ /* Catches SIGHUP */
+ INFO("Caught signal SIGHUP.");
+ received_sighup = 1;
+}
+
+void fswc_signal_term_handler(int signum)
+{
+ char *signame;
+
+ /* Catches SIGTERM and SIGINT */
+ switch(signum)
+ {
+ case SIGTERM: signame = "SIGTERM"; break;
+ case SIGINT: signame = "SIGINT"; break;
+ default: signame = "Unknown"; break;
+ }
+
+ INFO("Caught signal %s", signame);
+ received_sigterm = 1;
+}
+
+int fswc_setup_signals()
+{
+ signal(SIGUSR1, fswc_signal_usr1_handler);
+ signal(SIGHUP, fswc_signal_hup_handler);
+ signal(SIGTERM, fswc_signal_term_handler);
+ signal(SIGINT, fswc_signal_term_handler);
+
+ return(0);
+}
+
+char *fswc_strftime(char *dst, size_t max, char *src,
+ time_t timestamp, int gmt)
+{
+ struct tm tm_timestamp;
+
+ /* Set the time structure. */
+ if(gmt) gmtime_r(&timestamp, &tm_timestamp);
+ else localtime_r(&timestamp, &tm_timestamp);
+
+ *dst = '\0';
+ strftime(dst, max, src, &tm_timestamp);
+
+ return(dst);
+}
+
+char *fswc_strduptime(char *src, time_t timestamp, int gmt)
+{
+ struct tm tm_timestamp;
+ char *dst;
+ size_t l;
+
+ if(!src) return(NULL);
+
+ /* Set the time structure. */
+ if(gmt) gmtime_r(&timestamp, &tm_timestamp);
+ else localtime_r(&timestamp, &tm_timestamp);
+
+ dst = NULL;
+ l = strlen(src) * 2;
+
+ while(1)
+ {
+ size_t r;
+ char *t = realloc(dst, l);
+
+ if(!t)
+ {
+ free(dst);
+ return(NULL);
+ }
+
+ dst = t;
+
+ *dst = 1;
+ r = strftime(dst, l, src, &tm_timestamp);
+
+ if(r > 0 && r < l) return(dst);
+ if(r == 0 && *dst == '\0') return(dst);
+
+ l *= 2;
+ }
+
+ return(NULL);
+}
+
+void fswc_DrawText(gdImagePtr im, char *font, double size,
+ int x, int y, char align,
+ uint32_t colour, char shadow, char *text)
+{
+ char *err;
+ int brect[8];
+
+ if(!text) return;
+
+ if(shadow)
+ {
+ uint32_t scolour = colour & 0xFF000000;
+
+ fswc_DrawText(im, font, size, x + 1, y + 1,
+ align, scolour, 0, text);
+ }
+
+ /* Correct alpha value for GD. */
+ colour = (((colour & 0xFF000000) / 2) & 0xFF000000) +
+ (colour & 0xFFFFFF);
+
+ /* Pre-render the text. We use the results during alignment. */
+ err = gdImageStringFT(NULL, &brect[0], colour, font, size, 0.0, 0, 0, text);
+ if(err)
+ {
+ WARN("%s", err);
+ return;
+ }
+
+ /* Adjust the coordinates according to the alignment. */
+ switch(align)
+ {
+ case ALIGN_CENTER: x -= brect[4] / 2; break;
+ case ALIGN_RIGHT: x -= brect[4]; break;
+ }
+
+ /* Render the text onto the image. */
+ gdImageStringFT(im, NULL, colour, font, size, 0.0, x, y, text);
+}
+
+int fswc_add_image_png(src_t *src, avgbmp_t *abitmap)
+{
+ uint32_t x, y;
+ gdImage *im;
+
+ im = gdImageCreateFromPngPtr(src->length, src->img);
+ if(!im) return(-1);
+
+ for(y = 0; y < src->height; y++)
+ for(x = 0; x < src->width; x++)
+ {
+ int c = gdImageGetPixel(im, x, y);
+
+ *(abitmap++) += (c & 0xFF0000) >> 16;
+ *(abitmap++) += (c & 0x00FF00) >> 8;
+ *(abitmap++) += (c & 0x0000FF);
+ }
+
+ gdImageDestroy(im);
+
+ return(0);
+}
+
+int fswc_verify_jpeg_dht(uint8_t *src, uint32_t lsrc,
+ uint8_t **dst, uint32_t *ldst)
+{
+ /* This function is based on a patch provided by Scott J. Bertin. */
+
+ static unsigned char dht[] =
+ {
+ 0xff, 0xc4, 0x01, 0xa2, 0x00, 0x00, 0x01, 0x05, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x10, 0x00, 0x02, 0x01, 0x03, 0x03, 0x02,
+ 0x04, 0x03, 0x05, 0x05, 0x04, 0x04, 0x00, 0x00, 0x01, 0x7d,
+ 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31,
+ 0x41, 0x06, 0x13, 0x51, 0x61, 0x07, 0x22, 0x71, 0x14, 0x32,
+ 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52,
+ 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
+ 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
+ 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
+ 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
+ 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83,
+ 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94,
+ 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
+ 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8,
+ 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
+ 0xf9, 0xfa, 0x01, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
+ 0x0b, 0x11, 0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
+ 0x07, 0x05, 0x04, 0x04, 0x00, 0x01, 0x02, 0x77, 0x00, 0x01,
+ 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41,
+ 0x51, 0x07, 0x61, 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14,
+ 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
+ 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25,
+ 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a,
+ 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46,
+ 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
+ 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a,
+ 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x82, 0x83,
+ 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94,
+ 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
+ 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
+ 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,
+ 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
+ 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa
+ };
+ uint8_t *p, *i = NULL;
+
+ /* By default we simply return the source image. */
+ *dst = src;
+ *ldst = lsrc;
+
+ /* Scan for an existing DHT segment or the first SOS segment. */
+ for(p = src + 2; p - src < lsrc - 3 && i == NULL; )
+ {
+ if(*(p++) != 0xFF) continue;
+
+ if(*p == 0xD9) break; /* JPEG_EOI */
+ if(*p == 0xC4) return(0); /* JPEG_DHT */
+ if(*p == 0xDA && !i) i = p - 1; /* JPEG_SOS */
+
+ /* Move to next segment. */
+ p += (p[1] << 8) + p[2];
+ }
+
+ /* If no SOS was found, insert the DHT directly after the SOI. */
+ if(i == NULL) i = src + 2;
+
+ DEBUG("Inserting DHT segment into JPEG frame.");
+
+ *ldst = lsrc + sizeof(dht);
+ *dst = malloc(*ldst);
+ if(!*dst)
+ {
+ ERROR("Out of memory.");
+ return(-1);
+ }
+
+ /* Copy the JPEG data, inserting the DHT segment. */
+ memcpy((p = *dst), src, i - src);
+ memcpy((p += i - src), dht, sizeof(dht));
+ memcpy((p += sizeof(dht)), i, lsrc - (i - src));
+
+ return(1);
+}
+
+int fswc_add_image_jpeg(src_t *src, avgbmp_t *abitmap)
+{
+ uint32_t x, y, hlength;
+ uint8_t *himg = NULL;
+ gdImage *im;
+ int i;
+
+ /* MJPEG data may lack the DHT segment required for decoding... */
+ i = fswc_verify_jpeg_dht(src->img, src->length, &himg, &hlength);
+
+ im = gdImageCreateFromJpegPtr(hlength, himg);
+ if(i == 1) free(himg);
+
+ if(!im) return(-1);
+
+ for(y = 0; y < src->height; y++)
+ for(x = 0; x < src->width; x++)
+ {
+ int c = gdImageGetPixel(im, x, y);
+
+ *(abitmap++) += (c & 0xFF0000) >> 16;
+ *(abitmap++) += (c & 0x00FF00) >> 8;
+ *(abitmap++) += (c & 0x0000FF);
+ }
+
+ gdImageDestroy(im);
+
+ return(0);
+}
+
+int fswc_add_image_rgb32(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *img = (uint8_t *) src->img;
+ uint32_t i = src->width * src->height;
+
+ if(src->length << 2 < i) return(-1);
+
+ while(i-- > 0)
+ {
+ *(abitmap++) += *(img++);
+ *(abitmap++) += *(img++);
+ *(abitmap++) += *(img++);
+ img++;
+ }
+
+ return(0);
+}
+
+int fswc_add_image_bgr32(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *img = (uint8_t *) src->img;
+ uint32_t p, i = src->width * src->height;
+
+ if(src->length << 2 < i) return(-1);
+
+ for(p = 0; p < i; p += 4)
+ {
+ abitmap[0] += img[2];
+ abitmap[1] += img[1];
+ abitmap[2] += img[0];
+ abitmap += 3;
+ img += 4;
+ }
+
+ return(0);
+}
+
+int fswc_add_image_rgb24(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *img = (uint8_t *) src->img;
+ uint32_t i = src->width * src->height * 3;
+
+ if(src->length < i) return(-1);
+ while(i-- > 0) *(abitmap++) += *(img++);
+
+ return(0);
+}
+
+int fswc_add_image_bgr24(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *img = (uint8_t *) src->img;
+ uint32_t p, i = src->width * src->height * 3;
+
+ if(src->length < i) return(-1);
+
+ for(p = 0; p < src->length; p += 3)
+ {
+ abitmap[0] += img[2];
+ abitmap[1] += img[1];
+ abitmap[2] += img[0];
+ abitmap += 3;
+ img += 3;
+ }
+
+ return(0);
+}
+
+int fswc_add_image_rgb565(src_t *src, avgbmp_t *abitmap)
+{
+ uint16_t *img = (uint16_t *) src->img;
+ uint32_t i = src->width * src->height;
+
+ if(src->length >> 1 < i) return(-1);
+
+ while(i-- > 0)
+ {
+ uint8_t r, g, b;
+
+ r = (*img & 0xF800) >> 8;
+ g = (*img & 0x7E0) >> 3;
+ b = (*img & 0x1F) << 3;
+
+ *(abitmap++) += r + (r >> 5);
+ *(abitmap++) += g + (g >> 6);
+ *(abitmap++) += b + (b >> 5);
+
+ img++;
+ }
+
+ return(0);
+}
+
+int fswc_add_image_rgb555(src_t *src, avgbmp_t *abitmap)
+{
+ uint16_t *img = (uint16_t *) src->img;
+ uint32_t i = src->width * src->height;
+
+ if(src->length >> 1 < i) return(-1);
+
+ while(i-- > 0)
+ {
+ uint8_t r, g, b;
+
+ r = (*img & 0x7C00) >> 7;
+ g = (*img & 0x3E0) >> 2;
+ b = (*img & 0x1F) << 3;
+
+ *(abitmap++) += r + (r >> 5);
+ *(abitmap++) += g + (g >> 5);
+ *(abitmap++) += b + (b >> 5);
+
+ img++;
+ }
+
+ return(0);
+}
+
+int fswc_add_image_bayer(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *img = src->img;
+ uint32_t x = 0, y = 0;
+ uint32_t w = src->width, h = src->height;
+ uint32_t i = w * h;
+
+ if(src->length < i) return(-1);
+
+ /* SBGGR8 bayer pattern:
+ *
+ * BGBGBGBGBG
+ * GRGRGRGRGR
+ * BGBGBGBGBG
+ * GRGRGRGRGR
+ *
+ */
+
+ while(i-- > 0)
+ {
+ uint8_t *p[8];
+ uint8_t hn, vn, di;
+ uint8_t r, g, b;
+
+ /* Setup pointers to this pixel's neighbours. */
+ p[0] = img - w - 1;
+ p[1] = img - w;
+ p[2] = img - w + 1;
+ p[3] = img - 1;
+ p[4] = img + 1;
+ p[5] = img + w - 1;
+ p[6] = img + w;
+ p[7] = img + w + 1;
+
+ /* Juggle pointers if they are out of bounds. */
+ if(!y) { p[0]=p[5]; p[1]=p[6]; p[2]=p[7]; }
+ else if(y == h - 1) { p[5]=p[0]; p[6]=p[1]; p[7]=p[2]; }
+ if(!x) { p[0]=p[2]; p[3]=p[4]; p[5]=p[7]; }
+ else if(x == w - 1) { p[2]=p[0]; p[4]=p[3]; p[7]=p[5]; }
+
+ /* Average matching neighbours. */
+ hn = (*p[3] + *p[4]) / 2;
+ vn = (*p[1] + *p[6]) / 2;
+ di = (*p[0] + *p[2] + *p[5] + *p[7]) / 4;
+
+ /* Calculate RGB */
+ if((x + y) & 0x01)
+ {
+ g = *img;
+ if(y & 0x01) { r = hn; b = vn; }
+ else { r = vn; b = hn; }
+ }
+ else if(y & 0x01) { r = *img; g = (vn + hn) / 2; b = di; }
+ else { b = *img; g = (vn + hn) / 2; r = di; }
+
+ *(abitmap++) += r;
+ *(abitmap++) += g;
+ *(abitmap++) += b;
+
+ /* Move to the next pixel (or line) */
+ if(++x == w) { x = 0; y++; }
+ img++;
+ }
+
+ return(0);
+}
+
+/* The following YUV functions are based on code by Vincent Hourdin.
+ * http://vinvin.dyndns.org/projects/
+ *
+ * Faster integer maths from camE by Tom Gilbert.
+ * http://linuxbrit.co.uk/camE/
+*/
+
+int fswc_add_image_yuyv(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *ptr;
+ uint32_t x, y, z;
+
+ if(src->length < (src->width * src->height * 2)) return(-1);
+
+ /* YUYV and UYVY are very similar and so *
+ * are both handled by this one function. */
+
+ ptr = (uint8_t *) src->img;
+ z = 0;
+
+ for(y = 0; y < src->height; y++)
+ {
+ for(x = 0; x < src->width; x++)
+ {
+ int r, g, b;
+ int y, u, v;
+
+ if(src->palette == SRC_PAL_UYVY)
+ {
+ if(!z) y = ptr[1] << 8;
+ else y = ptr[3] << 8;
+
+ u = ptr[0] - 128;
+ v = ptr[2] - 128;
+ }
+ else /* SRC_PAL_YUYV */
+ {
+ if(!z) y = ptr[0] << 8;
+ else y = ptr[2] << 8;
+
+ u = ptr[1] - 128;
+ v = ptr[3] - 128;
+ }
+
+ r = (y + (359 * v)) >> 8;
+ g = (y - (88 * u) - (183 * v)) >> 8;
+ b = (y + (454 * u)) >> 8;
+
+ *(abitmap++) += CLIP(r, 0x00, 0xFF);
+ *(abitmap++) += CLIP(g, 0x00, 0xFF);
+ *(abitmap++) += CLIP(b, 0x00, 0xFF);
+
+ if(z++)
+ {
+ z = 0;
+ ptr += 4;
+ }
+ }
+ }
+
+ return(0);
+}
+
+int fswc_add_image_yuv420p(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *yptr, *uptr, *vptr;
+ uint32_t x, y, p, o;
+
+ if(src->length < (src->width * src->height * 3) / 2) return(-1);
+
+ /* Setup pointers to Y, U and V buffers. */
+ yptr = (uint8_t *) src->img;
+ uptr = yptr + (src->width * src->height);
+ vptr = uptr + (src->width * src->height / 4);
+ o = 0;
+ p = 0;
+
+ for(y = 0; y < src->height; y++)
+ {
+ for(x = 0; x < src->width; x++)
+ {
+ int r, g, b;
+ int y, u, v;
+
+ y = *(yptr++) << 8;
+ u = uptr[p] - 128;
+ v = vptr[p] - 128;
+
+ r = (y + (359 * v)) >> 8;
+ g = (y - (88 * u) - (183 * v)) >> 8;
+ b = (y + (454 * u)) >> 8;
+
+ *(abitmap++) += CLIP(r, 0x00, 0xFF);
+ *(abitmap++) += CLIP(g, 0x00, 0xFF);
+ *(abitmap++) += CLIP(b, 0x00, 0xFF);
+
+ if(x & 1) p++;
+ }
+
+ if(!(y & 1)) p -= src->width / 2;
+ }
+
+ return(0);
+}
+
+int fswc_add_image_nv12mb(src_t *src, avgbmp_t *abitmap)
+{
+ uint32_t x, y;
+ uint32_t bw;
+
+ if(src->length != (src->width * src->height * 3) / 2) return(-1);
+
+ bw = src->width >> 4;
+
+ for(y = 0; y < src->height; y++)
+ {
+ for(x = 0; x < src->width; x++)
+ {
+ uint32_t bx, by;
+ int cy, cu, cv;
+ int cr, cg, cb;
+ uint8_t *py, *puv;
+
+ bx = x >> 4;
+ by = y >> 4;
+
+ py = src->img;
+ py += ((by * bw) + bx) * 0x100;
+ py += ((y - (by << 4)) * 0x10) + (x - (bx << 4));
+
+ by /= 2;
+
+ puv = src->img + (src->width * src->height);
+ puv += ((by * bw) + bx) * 0x100;
+ puv += (((y / 2) - (by << 4)) * 0x10) + ((x - (bx << 4)) &~ 1);
+
+ cy = *py << 8;
+ cu = puv[0] - 128;
+ cv = puv[1] - 128;
+
+ cr = (cy + (359 * cv)) >> 8;
+ cg = (cy - (88 * cu) - (183 * cv)) >> 8;
+ cb = (cy + (454 * cu)) >> 8;
+
+ *(abitmap++) += CLIP(cr, 0x00, 0xFF);
+ *(abitmap++) += CLIP(cg, 0x00, 0xFF);
+ *(abitmap++) += CLIP(cb, 0x00, 0xFF);
+ }
+ }
+
+ return(0);
+}
+
+int fswc_add_image_grey(src_t *src, avgbmp_t *abitmap)
+{
+ uint8_t *bitmap = (uint8_t *) src->img;
+ uint32_t i = src->width * src->height;
+
+ if(src->length < i) return(-1);
+
+ while(i-- > 0)
+ {
+ *(abitmap++) += *bitmap;
+ *(abitmap++) += *bitmap;
+ *(abitmap++) += *(bitmap++);
+ }
+
+ return(0);
+}
+
+int fswc_draw_overlay(fswebcam_config_t *config, char *filename, gdImage *image){
+ FILE *f;
+ gdImage *overlay;
+
+ if(!filename) return(-1);
+
+ f = fopen(filename, "rb");
+ if(!f)
+ {
+ ERROR("Unable to open '%s'", filename);
+ ERROR("fopen: %s", strerror(errno));
+ return(-1);
+ }
+
+ overlay = gdImageCreateFromPng(f);
+ fclose(f);
+
+ if(!overlay)
+ {
+ ERROR("Unable to read '%s'. Not a PNG image?", filename);
+ return(-1);
+ }
+
+ gdImageCopy(image, overlay, 0, 0, 0, 0, overlay->sx, overlay->sy);
+ gdImageDestroy(overlay);
+
+ return(0);
+}
+
+int fswc_draw_banner(fswebcam_config_t *config, gdImage *image)
+{
+ char timestamp[200];
+ int w, h;
+ int height;
+ int spacing;
+ int top;
+ int y;
+
+ w = gdImageSX(image);
+ h = gdImageSY(image);
+
+ /* Create the timestamp text. */
+ fswc_strftime(timestamp, 200, config->timestamp,
+ config->start, config->gmt);
+
+ /* Calculate the position and height of the banner. */
+ spacing = 4;
+ height = config->fontsize + (spacing * 2);
+
+ if(config->subtitle || config->info)
+ height += config->fontsize * 0.8 + spacing;
+
+ top = 0;
+ if(config->banner == BOTTOM_BANNER) top = h - height;
+
+ /* Draw the banner line. */
+ if(config->banner == TOP_BANNER)
+ {
+ gdImageFilledRectangle(image,
+ 0, height + 1,
+ w, height + 2,
+ config->bl_colour);
+ }
+ else
+ {
+ gdImageFilledRectangle(image,
+ 0, top - 2,
+ w, top - 1,
+ config->bl_colour);
+ }
+
+ /* Draw the background box. */
+ gdImageFilledRectangle(image,
+ 0, top,
+ w, top + height,
+ config->bg_colour);
+
+ y = top + spacing + config->fontsize;
+
+ /* Draw the title. */
+ fswc_DrawText(image, config->font, config->fontsize,
+ spacing, y, ALIGN_LEFT,
+ config->fg_colour, config->shadow, config->title);
+
+ /* Draw the timestamp. */
+ fswc_DrawText(image, config->font, config->fontsize * 0.8,
+ w - spacing, y, ALIGN_RIGHT,
+ config->fg_colour, config->shadow, timestamp);
+
+ y += spacing + config->fontsize * 0.8;
+
+ /* Draw the sub-title. */
+ fswc_DrawText(image, config->font, config->fontsize * 0.8,
+ spacing, y, ALIGN_LEFT,
+ config->fg_colour, config->shadow, config->subtitle);
+
+ /* Draw the info text. */
+ fswc_DrawText(image, config->font, config->fontsize * 0.7,
+ w - spacing, y, ALIGN_RIGHT,
+ config->fg_colour, config->shadow, config->info);
+
+ return(0);
+}
+
+gdImage* fswc_gdImageDuplicate(gdImage* src)
+{
+ gdImage *dst;
+
+ dst = gdImageCreateTrueColor(gdImageSX(src), gdImageSY(src));
+ if(!dst) return(NULL);
+
+ gdImageCopy(dst, src, 0, 0, 0, 0, gdImageSX(src), gdImageSY(src));
+
+ return(dst);
+}
+
+int fswc_output(fswebcam_config_t *config, char *name, gdImage *image)
+{
+ char filename[FILENAME_MAX];
+ gdImage *im;
+ FILE *f;
+
+ if(!name) return(-1);
+ if(!strncmp(name, "-", 2) && config->background)
+ {
+ ERROR("stdout is unavalaible in background mode.");
+ return(-1);
+ }
+
+ fswc_strftime(filename, FILENAME_MAX, name,
+ config->start, config->gmt);
+
+ /* Create a temporary image buffer. */
+ im = fswc_gdImageDuplicate(image);
+ if(!im)
+ {
+ ERROR("Out of memory.");
+ return(-1);
+ }
+
+ /* Draw the underlay. */
+ fswc_draw_overlay(config, config->underlay, im);
+
+ /* Draw the banner. */
+ if(config->banner != NO_BANNER) fswc_draw_banner(config, im);
+
+ /* Draw the overlay. */
+ fswc_draw_overlay(config, config->overlay, im);
+
+ /* Write to a file if a filename was given, otherwise stdout. */
+ if(strncmp(name, "-", 2)) f = fopen(filename, "wb");
+ else f = stdout;
+
+ if(!f)
+ {
+ ERROR("Error opening file for output: %s", filename);
+ ERROR("fopen: %s", strerror(errno));
+ gdImageDestroy(im);
+ return(-1);
+ }
+
+ /* Write the compressed image. */
+ switch(config->format)
+ {
+ case FORMAT_JPEG:
+ MSG("Writing JPEG image to '%s'.", filename);
+ gdImageJpeg(im, f, config->compression);
+ break;
+ case FORMAT_PNG:
+ MSG("Writing PNG image to '%s'.", filename);
+ gdImagePngEx(im, f, config->compression);
+ break;
+ }
+
+ if(f != stdout) fclose(f);
+
+ gdImageDestroy(im);
+
+ return(0);
+}
+
+int fswc_exec(fswebcam_config_t *config, char *cmd)
+{
+ char *cmdline;
+ FILE *p;
+
+ cmdline = fswc_strduptime(cmd, config->start, config->gmt);
+ if(!cmdline) return(-1);
+
+ MSG("Executing '%s'...", cmdline);
+
+ p = popen(cmdline, "r");
+ free(cmdline);
+
+ if(p)
+ {
+ while(!feof(p))
+ {
+ char *n;
+ char line[1024];
+
+ if(!fgets(line, 1024, p)) break;
+
+ while((n = strchr(line, '\n'))) *n = '\0';
+ MSG("%s", line);
+ }
+
+ pclose(p);
+ }
+ else
+ {
+ ERROR("popen: %s", strerror(errno));
+ return(-1);
+ }
+
+ return(0);
+}
+
+int fswc_grab(fswebcam_config_t *config)
+{
+ uint32_t frame;
+ uint32_t x, y;
+ avgbmp_t *abitmap, *pbitmap;
+ gdImage *image, *original;
+ uint8_t modified;
+ src_t src;
+
+ /* Record the start time. */
+ config->start = time(NULL);
+
+ /* Set source options... */
+ memset(&src, 0, sizeof(src));
+ src.input = config->input;
+ src.tuner = config->tuner;
+ src.frequency = config->frequency;
+ src.delay = config->delay;
+ src.timeout = 10; /* seconds */
+ src.use_read = config->use_read;
+ src.list = config->list;
+ src.palette = config->palette;
+ src.width = config->width;
+ src.height = config->height;
+ src.option = config->option;
+
+ HEAD("--- Opening %s...", config->device);
+
+ if(src_open(&src, config->device) == -1) return(-1);
+
+ /* The source may have adjusted the width and height we passed
+ * to it. Update the main config to match. */
+ config->width = src.width;
+ config->height = src.height;
+
+ /* Allocate memory for the average bitmap buffer. */
+ abitmap = calloc(config->width * config->height * 3, sizeof(avgbmp_t));
+ if(!abitmap)
+ {
+ ERROR("Out of memory.");
+ return(-1);
+ }
+
+ if(config->frames == 1) HEAD("--- Capturing frame...");
+ else HEAD("--- Capturing %i frames...", config->frames);
+
+ if(config->skipframes == 1) MSG("Skipping frame...");
+ else if(config->skipframes > 1) MSG("Skipping %i frames...", config->skipframes);
+
+ /* Grab (and do nothing with) the skipped frames. */
+ for(frame = 0; frame < config->skipframes; frame++)
+ if(src_grab(&src) == -1) break;
+
+ /* If frames where skipped, inform when normal capture begins. */
+ if(config->skipframes) MSG("Capturing %i frames...", config->frames);
+
+ /* Grab the requested number of frames. */
+ for(frame = 0; frame < config->frames; frame++)
+ {
+ if(src_grab(&src) == -1) break;
+
+ if(!frame && config->dumpframe)
+ {
+ /* Dump the raw data from the first frame to file. */
+ FILE *f;
+
+ MSG("Dumping raw frame to '%s'...", config->dumpframe);
+
+ f = fopen(config->dumpframe, "wb");
+ if(!f) ERROR("fopen: %s", strerror(errno));
+ else
+ {