diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/gregbook/COPYING | 340 | ||||
-rw-r--r-- | contrib/gregbook/LICENSE | 26 | ||||
-rw-r--r-- | contrib/gregbook/Makefile.mingw32 | 130 | ||||
-rw-r--r-- | contrib/gregbook/Makefile.unx | 94 | ||||
-rw-r--r-- | contrib/gregbook/Makefile.w32 | 9 | ||||
-rw-r--r-- | contrib/gregbook/README | 15 | ||||
-rw-r--r-- | contrib/gregbook/readpng.c | 26 | ||||
-rw-r--r-- | contrib/gregbook/readpng.h | 26 | ||||
-rw-r--r-- | contrib/gregbook/readpng2.c | 103 | ||||
-rw-r--r-- | contrib/gregbook/readpng2.h | 28 | ||||
-rw-r--r-- | contrib/gregbook/readppm.c | 179 | ||||
-rw-r--r-- | contrib/gregbook/rpng-win.c | 43 | ||||
-rw-r--r-- | contrib/gregbook/rpng-x.c | 54 | ||||
-rw-r--r-- | contrib/gregbook/rpng2-win.c | 45 | ||||
-rw-r--r-- | contrib/gregbook/rpng2-x.c | 802 | ||||
-rw-r--r-- | contrib/gregbook/wpng.c | 47 | ||||
-rw-r--r-- | contrib/gregbook/writepng.c | 26 | ||||
-rw-r--r-- | contrib/gregbook/writepng.h | 26 |
18 files changed, 1836 insertions, 183 deletions
diff --git a/contrib/gregbook/COPYING b/contrib/gregbook/COPYING new file mode 100644 index 000000000..d60c31a97 --- /dev/null +++ b/contrib/gregbook/COPYING @@ -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. diff --git a/contrib/gregbook/LICENSE b/contrib/gregbook/LICENSE index 175ebfdf4..a39264e85 100644 --- a/contrib/gregbook/LICENSE +++ b/contrib/gregbook/LICENSE @@ -1,12 +1,19 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -23,4 +30,21 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + --------------------------------------------------------------------------- diff --git a/contrib/gregbook/Makefile.mingw32 b/contrib/gregbook/Makefile.mingw32 new file mode 100644 index 000000000..e70a59aef --- /dev/null +++ b/contrib/gregbook/Makefile.mingw32 @@ -0,0 +1,130 @@ +# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make. +# Greg Roelofs +# Last modified: 2 June 2007 +# +# The programs built by this makefile are described in the book, +# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and +# Associates, 1999). Go buy a copy, eh? Well, OK, it's not +# generally for sale anymore, but it's the thought that counts, +# right? (Hint: http://www.libpng.org/pub/png/book/ ) +# +# Invoke this makefile from a DOS-prompt window via: +# +# make -f Makefile.mingw32 +# +# This makefile assumes libpng and zlib have already been built or downloaded +# and are in subdirectories at the same level as the current subdirectory +# (as indicated by the PNGDIR and ZDIR macros below). It makes no assumptions +# at all about the mingw32 installation tree (W32DIR). Edit as appropriate. +# +# Note that the names of the dynamic and static libpng and zlib libraries +# used below may change in later releases of the libraries. This makefile +# builds both statically and dynamically linked executables by default. +# (You need only one set, but for testing it can be handy to have both.) + + +# macros -------------------------------------------------------------------- + +#PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds +PNGDIR = ../libpng-win32 +PNGINC = -I$(PNGDIR) +PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked +PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng + +#ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds +ZDIR = ../zlib-win32 +ZINC = -I$(ZDIR) +ZLIBd = $(ZDIR)/libzdll.a +ZLIBs = $(ZDIR)/libz.a + +# change this to be the path where mingw32 installs its stuff: +W32DIR = +#W32DIR = /usr/local/cross-tools/i386-mingw32msvc +W32INC = -I$(W32DIR)/include +W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a + +CC = gcc +#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation +LD = $(CC) +RM = rm -f +CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS) +# [note that -Wall is a gcc-specific compilation flag ("most warnings on")] +# [-ansi, -pedantic and -W can also be used] +LDFLAGS = $(MINGW_LDFLAGS) +O = .o +E = .exe + +INCS = $(PNGINC) $(ZINC) $(W32INC) +RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm +RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm +WLIBSd = $(PNGLIBd) $(ZLIBd) +WLIBSs = $(PNGLIBs) $(ZLIBs) + +RPNG = rpng-win +RPNG2 = rpng2-win +WPNG = wpng + +ROBJSd = $(RPNG)$(O) readpng.pic$(O) +ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O) +WOBJSd = $(WPNG)$(O) writepng.pic$(O) + +RPNGs = $(RPNG)-static +RPNG2s = $(RPNG2)-static +WPNGs = $(WPNG)-static + +ROBJSs = $(RPNG)$(O) readpng$(O) +ROBJS2s = $(RPNG2)$(O) readpng2$(O) +WOBJSs = $(WPNG)$(O) writepng$(O) + +STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) +DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) + +EXES = $(STATIC_EXES) $(DYNAMIC_EXES) + + +# implicit make rules ------------------------------------------------------- + +.c$(O): + $(CC) -c $(CFLAGS) $< + +%.pic$(O): %.c + $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $< + + +# dependencies -------------------------------------------------------------- + +all: $(EXES) + +$(RPNGs)$(E): $(ROBJSs) + $(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs) + +$(RPNG)$(E): $(ROBJSd) + $(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd) + +$(RPNG2s)$(E): $(ROBJS2s) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs) + +$(RPNG2)$(E): $(ROBJS2d) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd) + +$(WPNGs)$(E): $(WOBJSs) + $(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs) + +$(WPNG)$(E): $(WOBJSd) + $(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd) + +$(RPNG)$(O): $(RPNG).c readpng.h +$(RPNG2)$(O): $(RPNG2).c readpng2.h +$(WPNG)$(O): $(WPNG).c writepng.h + +readpng$(O) readpng.pic$(O): readpng.c readpng.h +readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h +writepng$(O) writepng.pic$(O): writepng.c writepng.h + + +# maintenance --------------------------------------------------------------- + +clean: + $(RM) $(EXES) + $(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs) + $(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd) diff --git a/contrib/gregbook/Makefile.unx b/contrib/gregbook/Makefile.unx index c0c3fb1c3..7ff65bfb7 100644 --- a/contrib/gregbook/Makefile.unx +++ b/contrib/gregbook/Makefile.unx @@ -1,73 +1,92 @@ # Sample makefile for rpng-x / rpng2-x / wpng using gcc and make. # Greg Roelofs -# Last modified: 7 March 2002 +# Last modified: 2 June 2007 # # The programs built by this makefile are described in the book, # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and -# Associates, 1999). Go buy a copy, eh? Buy some for friends -# and family, too. (Not that this is a blatant plug or anything.) +# Associates, 1999). Go buy a copy, eh? Well, OK, it's not +# generally for sale anymore, but it's the thought that counts, +# right? (Hint: http://www.libpng.org/pub/png/book/ ) # # Invoke this makefile from a shell prompt in the usual way; for example: # # make -f Makefile.unx # # This makefile assumes libpng and zlib have already been built or downloaded -# and are both installed in /usr/local/{include,lib} (as indicated by the -# PNG* and Z* macros below). Edit as appropriate--choose only ONE each of -# the PNGINC, PNGLIB, ZINC and ZLIB lines. +# and are installed in /usr/local/{include,lib} or as otherwise indicated by +# the PNG* and Z* macros below. Edit as appropriate--choose only ONE each of +# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines. # -# This makefile builds statically linked executables (against libpng and zlib, -# that is), but that can be changed by uncommenting the appropriate PNGLIB and -# ZLIB lines. +# This makefile builds both dynamically and statically linked executables +# (against libpng and zlib, that is), but that can be changed by modifying +# the "EXES =" line. (You need only one set, but for testing it can be handy +# to have both.) # macros -------------------------------------------------------------------- -PNGINC = -I/usr/local/include/libpng12 -#PNGLIB = -L/usr/local/lib -lpng12 # dynamically linked against libpng -PNGLIB = /usr/local/lib/libpng12.a # statically linked against libpng +#PNGDIR = /usr/local/lib +#PNGINC = -I/usr/local/include/libpng12 +#PNGLIBd = -L$(PNGDIR) -lpng12 # dynamically linked, installed libpng +#PNGLIBs = $(PNGDIR)/libpng12.a # statically linked, installed libpng # or: -#PNGINC = -I../libpng -#PNGLIB = -L../libpng -lpng -#PNGLIB = ../libpng/libpng.a - +PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds +#PNGDIR = ../libpng +PNGINC = -I$(PNGDIR) +PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng12 # dynamically linked +PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng + +ZDIR = /usr/local/lib +#ZDIR = /usr/lib64 ZINC = -I/usr/local/include -#ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib -ZLIB = /usr/local/lib/libz.a # statically linked against zlib -#ZINC = -I../zlib -#ZLIB = -L../zlib -lz -#ZLIB = ../zlib/libz.a +ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib +ZLIBs = $(ZDIR)/libz.a # statically linked against zlib +# or: +#ZDIR = ../zlib +#ZINC = -I$(ZDIR) +#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing +#ZLIBs = $(ZDIR)/libz.a #XINC = -I/usr/include # old-style, stock X distributions -#XLIB = -L/usr/lib/X11 -lX11 +#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX) #XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) #XLIB = -L/usr/openwin/lib -lX11 -XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.) +XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.) XLIB = -L/usr/X11R6/lib -lX11 +#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64 INCS = $(PNGINC) $(ZINC) $(XINC) -RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm -WLIBS = $(PNGLIB) $(ZLIB) +RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm +RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm +WLIBSd = $(PNGLIBd) $(ZLIBd) -lm +WLIBSs = $(PNGLIBs) $(ZLIBs) CC = gcc LD = gcc RM = rm -f -CFLAGS = -O -Wall $(INCS) +CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP # [note that -Wall is a gcc-specific compilation flag ("most warnings on")] # [-ansi, -pedantic and -W can also be used] LDFLAGS = O = .o E = -RPNG = rpng-x -RPNG2 = rpng2-x -WPNG = wpng +RPNG = rpng-x +RPNG2 = rpng2-x +WPNG = wpng + +RPNGs = $(RPNG)-static +RPNG2s = $(RPNG2)-static +WPNGs = $(WPNG)-static ROBJS = $(RPNG)$(O) readpng$(O) ROBJS2 = $(RPNG2)$(O) readpng2$(O) WOBJS = $(WPNG)$(O) writepng$(O) -EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) +STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) +DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) + +EXES = $(STATIC_EXES) $(DYNAMIC_EXES) # implicit make rules ------------------------------------------------------- @@ -80,14 +99,23 @@ EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) all: $(EXES) +$(RPNGs)$(E): $(ROBJS) + $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs) + $(RPNG)$(E): $(ROBJS) - $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS) + $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd) + +$(RPNG2s)$(E): $(ROBJS2) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs) $(RPNG2)$(E): $(ROBJS2) - $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS) + $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd) + +$(WPNGs)$(E): $(WOBJS) + $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs) $(WPNG)$(E): $(WOBJS) - $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS) + $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd) $(RPNG)$(O): $(RPNG).c readpng.h $(RPNG2)$(O): $(RPNG2).c readpng2.h diff --git a/contrib/gregbook/Makefile.w32 b/contrib/gregbook/Makefile.w32 index 62041cd96..3c0808593 100644 --- a/contrib/gregbook/Makefile.w32 +++ b/contrib/gregbook/Makefile.w32 @@ -1,11 +1,12 @@ # Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE. # Greg Roelofs -# Last modified: 16 February 1999 +# Last modified: 2 June 2007 # # The programs built by this makefile are described in the book, # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and -# Associates, 1999). Go buy a copy, eh? Buy some for friends -# and family, too. (Not that this is a blatant plug or anything.) +# Associates, 1999). Go buy a copy, eh? Well, OK, it's not +# generally for sale anymore, but it's the thought that counts, +# right? (Hint: http://www.libpng.org/pub/png/book/ ) # # Invoke this makefile from a DOS prompt window via: # @@ -53,7 +54,7 @@ CC = cl LD = link RM = del CFLAGS = -nologo -O -W3 $(INCS) $(cvars) -# [note that -Wall is an MSVC-specific compilation flag ("all warnings on")] +# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")] # [see %devstudio%\vc\include\win32.mak for cvars macro definition] O = .obj E = .exe diff --git a/contrib/gregbook/README b/contrib/gregbook/README index c67045cac..5b08bc6f8 100644 --- a/contrib/gregbook/README +++ b/contrib/gregbook/README @@ -22,7 +22,8 @@ below. Files: README this file - LICENSE terms of distribution and reuse (BSD-like) + LICENSE terms of distribution and reuse (BSD-like or GNU GPL) + COPYING GNU General Public License (GPL) Makefile.unx Unix makefile Makefile.w32 Windows (MSVC) makefile @@ -54,15 +55,15 @@ mation and links to the latest version of the source code, and Chapters 13-15 of the book for detailed discussion of the three programs. Greg Roelofs -newt@pobox.com -30 June 2001 +http://pobox.com/~newt/greg_contact.html +2 June 2007 BUILD INSTRUCTIONS - Prerequisites (in order of compilation): - - zlib http://www.gzip.org/zlib/ + - zlib http://zlib.net/ - libpng http://www.libpng.org/pub/png/libpng.html - pngbook http://www.libpng.org/pub/png/book/sources.html @@ -150,9 +151,9 @@ BUILD INSTRUCTIONS To run the programs, they probably first need to be set up as "foreign symbols," with "disk" and "dir" set appropriately: - $ rpng == "$disk:[dir]rpng-x.exe" + $ rpng == "$disk:[dir]rpng-x.exe" $ rpng2 == "$disk:[dir]rpng2-x.exe" - $ wpng == "$disk:[dir]wpng.exe" + $ wpng == "$disk:[dir]wpng.exe" All three will print a basic usage screen when run without any command- line arguments; see the book for more details. Note that the options @@ -176,7 +177,7 @@ RUNNING THE PROGRAMS: (VERY) BRIEF INTRO wpng is a purely command-line image converter from binary PBMPLUS/NetPBM format (.pgm or .ppm) to PNG; for example, - wpng -time < toucan.ppm > toucan.png + wpng -time < toucan-notrans.ppm > toucan-notrans.png would convert the specified PPM file (using redirection) to PNG, auto- matically setting the PNG modification-time chunk. diff --git a/contrib/gregbook/readpng.c b/contrib/gregbook/readpng.c index b8e0904e2..d87f6c7ed 100644 --- a/contrib/gregbook/readpng.c +++ b/contrib/gregbook/readpng.c @@ -4,13 +4,20 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2000 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -27,6 +34,23 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #include <stdio.h> diff --git a/contrib/gregbook/readpng.h b/contrib/gregbook/readpng.h index 1c19aca99..fad9fe3b4 100644 --- a/contrib/gregbook/readpng.h +++ b/contrib/gregbook/readpng.h @@ -4,13 +4,20 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2000 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -27,6 +34,23 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #ifndef TRUE diff --git a/contrib/gregbook/readpng2.c b/contrib/gregbook/readpng2.c index 9e66a0bce..fd95667d1 100644 --- a/contrib/gregbook/readpng2.c +++ b/contrib/gregbook/readpng2.c @@ -4,19 +4,20 @@ --------------------------------------------------------------------------- - Changelog: - - 1.01: initial public release - - 1.02: added code to skip unused chunks (GR-P) - - --------------------------------------------------------------------------- - - Copyright (c) 1998-2002 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -33,6 +34,23 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ @@ -56,7 +74,7 @@ static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg); void readpng2_version_info(void) { #if defined(PNG_ASSEMBLER_CODE_SUPPORTED) && \ - (defined(__i386__) || defined(_M_IX86)) && \ + (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \ defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200) /* * WARNING: This preprocessor approach means that the following code @@ -79,7 +97,12 @@ void readpng2_version_info(void) "with MMX support\n (%s version).", PNG_LIBPNG_VER_STRING, png_libpng_ver, compilerID == 1? "MSVC++" : (compilerID == 2? "GNU C" : "unknown")); - fprintf(stderr, " Processor %s MMX instructions.\n", + fprintf(stderr, " Processor (x86%s) %s MMX instructions.\n", +#if defined(__x86_64__) + "_64" +#else + "", +#endif mmxsupport? "supports" : "does not support"); if (mmxsupport > 0) { int num_optims = 0; @@ -179,40 +202,38 @@ int readpng2_init(mainprog_info *mainprog_ptr) return 2; } - /* prepare the reader to ignore all recognized chunks whose data isn't - * going to be used, i.e., all chunks recognized by libpng except for - * IHDR, PLTE, IDAT, IEND, tRNS, bKGD, gAMA, and sRGB : */ -#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) +#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED + /* prepare the reader to ignore all recognized chunks whose data won't be + * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT, + * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */ { -#ifndef HANDLE_CHUNK_NEVER -/* prior to libpng-1.2.5, this macro was internal, so we define it here. */ -# define HANDLE_CHUNK_NEVER 1 -#endif - /* these byte strings were copied from png.h. - * If a future libpng version recognizes more chunks, add them - * to this list. If a future version of readpng2.c recognizes - * more chunks, delete them from this list. */ - png_byte png_chunk_types_to_ignore[]= - { 99, 72, 82, 77, '\0', /* cHRM */ - 104, 73, 83, 84, '\0', /* hIST */ - 105, 67, 67, 80, '\0', /* iCCP */ - 105, 84, 88, 116, '\0', /* iTXt */ - 111, 70, 70, 115, '\0', /* oFFs */ - 112, 67, 65, 76, '\0', /* pCAL */ - 115, 67, 65, 76, '\0', /* sCAL */ - 112, 72, 89, 115, '\0', /* pHYs */ - 115, 66, 73, 84, '\0', /* sBIT */ - 115, 80, 76, 84, '\0', /* sPLT */ - 116, 69, 88, 116, '\0', /* tEXt */ - 116, 73, 77, 69, '\0', /* tIME */ - 122, 84, 88, 116, '\0'}; /* zTXt */ -#define NUM_PNG_CHUNK_TYPES_TO_IGNORE 13 - - png_set_keep_unknown_chunks(png_ptr, HANDLE_CHUNK_NEVER, - png_chunk_types_to_ignore, NUM_PNG_CHUNK_TYPES_TO_IGNORE); + /* These byte strings were copied from png.h. If a future libpng + * version recognizes more chunks, add them to this list. If a + * future version of readpng2.c recognizes more chunks, delete them + * from this list. */ + static const png_byte chunks_to_ignore[] = { + 99, 72, 82, 77, '\0', /* cHRM */ + 104, 73, 83, 84, '\0', /* hIST */ + 105, 67, 67, 80, '\0', /* iCCP */ + 105, 84, 88, 116, '\0', /* iTXt */ + 111, 70, 70, 115, '\0', /* oFFs */ + 112, 67, 65, 76, '\0', /* pCAL */ + 112, 72, 89, 115, '\0', /* pHYs */ + 115, 66, 73, 84, '\0', /* sBIT */ + 115, 67, 65, 76, '\0', /* sCAL */ + 115, 80, 76, 84, '\0', /* sPLT */ + 115, 84, 69, 82, '\0', /* sTER */ + 116, 69, 88, 116, '\0', /* tEXt */ + 116, 73, 77, 69, '\0', /* tIME */ + 122, 84, 88, 116, '\0' /* zTXt */ + }; + + png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */, + chunks_to_ignore, sizeof(chunks_to_ignore)/5); } -#endif +#endif /* PNG_UNKNOWN_CHUNKS_SUPPORTED */ + /* instead of doing png_init_io() here, now we set up our callback * functions for progressive decoding */ @@ -237,7 +258,7 @@ int readpng2_init(mainprog_info *mainprog_ptr) * png_set_asm_flags (png_ptr, flags); */ -#if (defined(__i386__) || defined(_M_IX86)) && \ +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \ defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER >= 10200) /* * WARNING: This preprocessor approach means that the following code diff --git a/contrib/gregbook/readpng2.h b/contrib/gregbook/readpng2.h index 7caa9d9cf..386e5ee65 100644 --- a/contrib/gregbook/readpng2.h +++ b/contrib/gregbook/readpng2.h @@ -4,13 +4,20 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -27,6 +34,23 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #ifndef TRUE @@ -66,7 +90,7 @@ typedef struct _mainprog_info { int rowbytes; int channels; int need_bgcolor; -#if (defined(__i386__) || defined(_M_IX86)) +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) int nommxfilters; int nommxcombine; int nommxinterlace; diff --git a/contrib/gregbook/readppm.c b/contrib/gregbook/readppm.c new file mode 100644 index 000000000..be9a56d95 --- /dev/null +++ b/contrib/gregbook/readppm.c @@ -0,0 +1,179 @@ +/*--------------------------------------------------------------------------- + + rpng - simple PNG display program readppm.c + + --------------------------------------------------------------------------- + + This is a special-purpose replacement for readpng.c that allows binary + PPM files to be used in place of PNG images. + + --------------------------------------------------------------------------- + + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. + + This software is provided "as is," without warranty of any kind, + express or implied. In no event shall the author or contributors + be held liable for any damages arising in any way from the use of + this software. + + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute + it freely, subject to the following restrictions: + + 1. Redistributions of source code must retain the above copyright + notice, disclaimer, and this list of conditions. + 2. Redistributions in binary form must reproduce the above copyright + notice, disclaimer, and this list of conditions in the documenta- + tion and/or other materials provided with the distribution. + 3. All advertising materials mentioning features or use of this + software must display the following acknowledgment: + + This product includes software developed by Greg Roelofs + and contributors for the book, "PNG: The Definitive Guide," + published by O'Reilly and Associates. + + + LICENSE 2 (GNU GPL v2 or later): + + 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 + + ---------------------------------------------------------------------------*/ + +#include <stdio.h> +#include <stdlib.h> + +#include "readpng.h" /* typedefs, common macros, public prototypes */ + + +ulg width, height; +int bit_depth, color_type, channels; +uch *image_data = NULL; +FILE *saved_infile; + + +void readpng_version_info() +{ + fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n"); +} + + +/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ + +int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) +{ + static uch ppmline[256]; + int maxval; + + + saved_infile = infile; + + fgets(ppmline, 256, infile); + if (ppmline[0] != 'P' || ppmline[1] != '6') { + fprintf(stderr, "ERROR: not a PPM file\n"); + return 1; + } + /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */ + if (ppmline[1] == '6') { + color_type = 2; + channels = 3; + } else if (ppmline[1] == '8') { + color_type = 6; + channels = 4; + } else /* if (ppmline[1] == '5') */ { + color_type = 0; + channels = 1; + } + + do { + fgets(ppmline, 256, infile); + } while (ppmline[0] == '#'); + sscanf(ppmline, "%lu %lu", &width, &height); + + do { + fgets(ppmline, 256, infile); + } while (ppmline[0] == '#'); + sscanf(ppmline, "%d", &maxval); + if (maxval != 255) { + fprintf(stderr, "ERROR: maxval = %d\n", maxval); + return 2; + } + bit_depth = 8; + + *pWidth = width; + *pHeight = height; + + return 0; +} + + + + +/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error; + * scales values to 8-bit if necessary */ + +int readpng_get_bgcolor(uch *red, uch *green, uch *blue) +{ + return 1; +} + + + + +/* display_exponent == LUT_exponent * CRT_exponent */ + +uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) +{ + ulg rowbytes; + + + /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits, + * transparency chunks to full alpha channel; strip 16-bit-per-sample + * images to 8 bits per sample; and convert grayscale to RGB[A] */ + + /* GRR WARNING: grayscale needs to be expanded and channels reset! */ + + *pRowbytes = rowbytes = channels*width; + *pChannels = channels; + + if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { + return NULL; + } + + Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height)); + + + /* now we can go ahead and just read the whole image */ + + fread(image_data, 1L, rowbytes*height, saved_infile); + + + return image_data; +} + + +void readpng_cleanup(int free_image_data) +{ + if (free_image_data && image_data) { + free(image_data); + image_data = NULL; + } +} diff --git a/contrib/gregbook/rpng-win.c b/contrib/gregbook/rpng-win.c index b84a7fc21..b37c00aa7 100644 --- a/contrib/gregbook/rpng-win.c +++ b/contrib/gregbook/rpng-win.c @@ -22,16 +22,24 @@ - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed command-line parsing bug - 1.10: enabled "message window"/console (thanks to David Geldreich) + - 2.00: dual-licensed (added GNU GPL) --------------------------------------------------------------------------- - Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -48,11 +56,28 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #define PROGNAME "rpng-win" #define LONGNAME "Simple PNG Viewer for Windows" -#define VERSION "1.20 of 28 May 2001" +#define VERSION "2.00 of 2 June 2007" #include <stdio.h> #include <stdlib.h> @@ -85,10 +110,9 @@ static void rpng_win_cleanup(void); LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM); -static char titlebar[1024], *window_name = titlebar; +static char titlebar[1024]; static char *progname = PROGNAME; static char *appname = LONGNAME; -static char *icon_name = PROGNAME; /* GRR: not (yet) used */ static char *filename; static FILE *infile; @@ -325,9 +349,14 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) * check for one in the PNG file--if not, the initialized values of 0 * (black) will be used */ - if (have_bg) - sscanf(bgstr+1, "%2x%2x%2x", &bg_red, &bg_green, &bg_blue); - else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { + if (have_bg) { + unsigned r, g, b; /* this approach quiets compiler warnings */ + + sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); + bg_red = (uch)r; + bg_green = (uch)g; + bg_blue = (uch)b; + } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { readpng_cleanup(TRUE); fprintf(stderr, PROGNAME ": libpng error while checking for background color\n"); diff --git a/contrib/gregbook/rpng-x.c b/contrib/gregbook/rpng-x.c index e787ef1d5..947726024 100644 --- a/contrib/gregbook/rpng-x.c +++ b/contrib/gregbook/rpng-x.c @@ -9,7 +9,7 @@ by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking). to do: - - 8-bit support + - 8-bit (colormapped) X support - use %.1023s to simplify truncation of title-bar string? --------------------------------------------------------------------------- @@ -21,18 +21,27 @@ - 1.10: added support for non-default visuals; fixed X pixel-conversion - 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed command-line parsing bug - - 1.12: fixed small X memory leak (thanks to Francois Petitjean) - - 1.13: fixed XFreeGC() crash bug + - 1.12: fixed some small X memory leaks (thanks to François Petitjean) + - 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche) + - 1.14: added support for X resources (thanks to Gerhard Niklasch) + - 2.00: dual-licensed (added GNU GPL) --------------------------------------------------------------------------- - Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -49,11 +58,30 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #define PROGNAME "rpng-x" #define LONGNAME "Simple PNG Viewer for X" -#define VERSION "1.13 of 16 August 2001" +#define VERSION "2.00 of 2 June 2007" +#define RESNAME "rpng" /* our X resource application name */ +#define RESCLASS "Rpng" /* our X resource class name */ #include <stdio.h> #include <stdlib.h> @@ -91,6 +119,8 @@ static int rpng_x_msb(ulg u32val); static char titlebar[1024], *window_name = titlebar; static char *appname = LONGNAME; static char *icon_name = PROGNAME; +static char *res_name = RESNAME; +static char *res_class = RESCLASS; static char *filename; static FILE *infile; @@ -399,11 +429,12 @@ static int rpng_x_create_window(void) XEvent e; XGCValues gcvalues; XSetWindowAttributes attr; - XSizeHints *size_hints; XTextProperty windowName, *pWindowName = &windowName; XTextProperty iconName, *pIconName = &iconName; XVisualInfo visual_info; + XSizeHints *size_hints; XWMHints *wm_hints; + XClassHint *class_hints; screen = DefaultScreen(display); @@ -526,7 +557,7 @@ static int rpng_x_create_window(void) if (!XStringListToTextProperty(&icon_name, 1, pIconName)) pIconName = NULL; - /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */ + /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */ if ((size_hints = XAllocSizeHints()) != NULL) { /* window will not be resizable */ @@ -542,8 +573,13 @@ static int rpng_x_create_window(void) wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; } + if ((class_hints = XAllocClassHint()) != NULL) { + class_hints->res_name = res_name; + class_hints->res_class = res_class; + } + XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, - size_hints, wm_hints, NULL); + size_hints, wm_hints, class_hints); /* various properties and hints no longer needed; free memory */ if (pWindowName) @@ -554,6 +590,8 @@ static int rpng_x_create_window(void) XFree(size_hints); if (wm_hints) XFree(wm_hints); + if (class_hints) + XFree(class_hints); XMapWindow(display, window); diff --git a/contrib/gregbook/rpng2-win.c b/contrib/gregbook/rpng2-win.c index 0c1a9d16e..dfbd6b16b 100644 --- a/contrib/gregbook/rpng2-win.c +++ b/contrib/gregbook/rpng2-win.c @@ -27,16 +27,25 @@ - 1.10: enabled "message window"/console (thanks to David Geldreich) - 1.20: added runtime MMX-enabling/disabling and new -mmx* options - 1.21: made minor tweak to usage screen to fit within 25-line console + - 1.22: added AMD64/EM64T support (__x86_64__) + - 2.00: dual-licensed (added GNU GPL) --------------------------------------------------------------------------- - Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -53,11 +62,28 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #define PROGNAME "rpng2-win" #define LONGNAME "Progressive PNG Viewer for Windows" -#define VERSION "1.21 of 29 June 2001" +#define VERSION "2.00 of 2 June 2007" #include <stdio.h> #include <stdlib.h> @@ -119,10 +145,9 @@ static void rpng2_win_cleanup(void); LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM); -static char titlebar[1024], *window_name = titlebar; +static char titlebar[1024]; static char *progname = PROGNAME; static char *appname = LONGNAME; -static char *icon_name = PROGNAME; /* GRR: not (yet) used */ static char *filename; static FILE *infile; @@ -367,7 +392,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) } } else if (!strncmp(*argv, "-timing", 2)) { timing = TRUE; -#if (defined(__i386__) || defined(_M_IX86)) +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) } else if (!strncmp(*argv, "-nommxfilters", 7)) { rpng2_info.nommxfilters = TRUE; } else if (!strncmp(*argv, "-nommxcombine", 7)) { @@ -432,7 +457,7 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) readpng2_version_info(); fprintf(stderr, "\n" "Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n" -#if (defined(__i386__) || defined(_M_IX86)) +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) " %*s [[-nommxfilters] [-nommxcombine] [-nommxinterlace] | -nommx]\n" #endif " %*s file.png\n\n" @@ -447,17 +472,17 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) "\t\t transparent images; overrides -bgcolor option\n" " -timing\tenables delay for every block read, to simulate modem\n" "\t\t download of image (~36 Kbps)\n" -#if (defined(__i386__) || defined(_M_IX86)) +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) " -nommx*\tdisable optimized MMX routines for decoding row filters,\n" "\t\t combining rows, and expanding interlacing, respectively\n" #endif "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" "Press Q or Esc to quit this usage screen. ", PROGNAME, -#if (defined(__i386__) || defined(_M_IX86)) - strlen(PROGNAME), " ", +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + (int)strlen(PROGNAME), " ", #endif - strlen(PROGNAME), " ", default_display_exponent, num_bgpat); + (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat); fflush(stderr); do ch = _getch(); diff --git a/contrib/gregbook/rpng2-x.c b/contrib/gregbook/rpng2-x.c index 5fc29ea77..6bba64908 100644 --- a/contrib/gregbook/rpng2-x.c +++ b/contrib/gregbook/rpng2-x.c @@ -13,7 +13,8 @@ and "radial waves" patterns, respectively. to do: - - 8-bit support + - fix expose/redraw code: don't draw entire row if only part exposed + - 8-bit (colormapped) X support - finish resizable checkerboard-gradient (sizes 4-128?) - use %.1023s to simplify truncation of title-bar string? @@ -26,18 +27,32 @@ - 1.11: added -usleep option for demos; fixed command-line parsing bug - 1.12: added -pause option for demos and testing - 1.20: added runtime MMX-enabling/disabling and new -mmx* options - - 1.21: fixed small X memory leak (thanks to Francois Petitjean) - - 1.22: fixed XFreeGC() crash bug + - 1.21: fixed some small X memory leaks (thanks to François Petitjean) + - 1.22: fixed XFreeGC() crash bug (thanks to Patrick Welche) + - 1.23: added -bgpat 0 mode (std white/gray checkerboard, 8x8 squares) + - 1.30: added -loop option for -bgpat (ifdef FEATURE_LOOP); fixed bpp = + 24; added support for X resources (thanks to Gerhard Niklasch) + - 1.31: added code to skip unused chunks (thanks to Glenn Randers-Pehrson) + - 1.32: added AMD64/EM64T support (__x86_64__); added basic expose/redraw + handling + - 2.00: dual-licensed (added GNU GPL) --------------------------------------------------------------------------- - Copyright (c) 1998-2001 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -54,14 +69,34 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #define PROGNAME "rpng2-x" #define LONGNAME "Progressive PNG Viewer for X" -#define VERSION "1.22 of 16 August 2001" +#define VERSION "2.00 of 2 June 2007" +#define RESNAME "rpng2" /* our X resource application name */ +#define RESCLASS "Rpng" /* our X resource class name */ #include <stdio.h> #include <stdlib.h> +#include <ctype.h> #include <string.h> #include <setjmp.h> /* for jmpbuf declaration in readpng2.h */ #include <time.h> @@ -88,6 +123,12 @@ #define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */ #define ROUNDF(f) ((int)(f + 0.5)) +#define QUIT(e,k) ((e.type == ButtonPress && e.xbutton.button == Button1) || \ + (e.type == KeyPress && /* v--- or 1 for shifted keys */ \ + ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape))) + +#define NO_24BIT_MASKS /* undef case not fully written--only for redisplay() */ + #define rgb1_max bg_freq #define rgb1_min bg_gray #define rgb2_max bg_bsat @@ -117,18 +158,26 @@ * overhead) */ /* local prototypes */ -static void rpng2_x_init(void); -static int rpng2_x_create_window(void); -static int rpng2_x_load_bg_image(void); -static void rpng2_x_display_row(ulg row); -static void rpng2_x_finish_display(void); -static void rpng2_x_cleanup(void); -static int rpng2_x_msb(ulg u32val); +static void rpng2_x_init (void); +static int rpng2_x_create_window (void); +static int rpng2_x_load_bg_image (void); +static void rpng2_x_display_row (ulg row); +static void rpng2_x_finish_display (void); +static void rpng2_x_redisplay_image (ulg startcol, ulg startrow, + ulg width, ulg height); +#ifdef FEATURE_LOOP +static void rpng2_x_reload_bg_image (void); +static int is_number (char *p); +#endif +static void rpng2_x_cleanup (void); +static int rpng2_x_msb (ulg u32val); static char titlebar[1024], *window_name = titlebar; static char *appname = LONGNAME; static char *icon_name = PROGNAME; +static char *res_name = RESNAME; +static char *res_class = RESCLASS; static char *filename; static FILE *infile; @@ -139,7 +188,7 @@ static int incount; static int pat = 6; /* must be less than num_bgpat */ static int bg_image = 0; -static int bgscale = 16; +static int bgscale, bgscale_default = 16; static ulg bg_rowbytes; static uch *bg_data; @@ -165,7 +214,8 @@ static struct rgb_color { {255, 127, 0}, /* 12: orange */ {192, 96, 0}, /* 13: darker orange */ { 24, 60, 0}, /* 14: dark green-yellow */ - { 85, 125, 200} /* 15: ice blue */ + { 85, 125, 200}, /* 15: ice blue */ + {192, 192, 192} /* 16: Netscape/Mosaic gray */ }; /* not used for now, but should be for error-checking: static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); @@ -193,6 +243,7 @@ static struct background_pattern { int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */ int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/ } bg[] = { + {0, 1,1, 16,16}, /* checkered: white vs. light gray (basic) */ {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */ {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */ {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */ @@ -244,6 +295,10 @@ int main(int argc, char **argv) int error = 0; int timing = FALSE; int have_bg = FALSE; +#ifdef FEATURE_LOOP + int loop = FALSE; + long loop_interval = -1; /* seconds (100,000 max) */ +#endif double LUT_exponent; /* just the lookup table */ double CRT_exponent = 2.2; /* just the monitor */ double default_display_exponent; /* whole display system */ @@ -344,13 +399,12 @@ int main(int argc, char **argv) if (!*++argv) ++error; else { - pat = atoi(*argv) - 1; - if (pat < 0 || pat >= num_bgpat) - ++error; - else { + pat = atoi(*argv); + if (pat >= 0 && pat < num_bgpat) { bg_image = TRUE; have_bg = FALSE; - } + } else + ++error; } } else if (!strncmp(*argv, "-usleep", 2)) { if (!*++argv) @@ -363,7 +417,21 @@ int main(int argc, char **argv) pause_after_pass = TRUE; } else if (!strncmp(*argv, "-timing", 2)) { timing = TRUE; -#if (defined(__i386__) || defined(_M_IX86)) +#ifdef FEATURE_LOOP + } else if (!strncmp(*argv, "-loop", 2)) { + loop = TRUE; + if (!argv[1] || !is_number(argv[1])) + loop_interval = 2; + else { + ++argv; + loop_interval = atol(*argv); + if (loop_interval < 0) + loop_interval = 2; + else if (loop_interval > 100000) /* bit more than one day */ + loop_interval = 100000; + } +#endif +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) } else if (!strncmp(*argv, "-nommxfilters", 7)) { rpng2_info.nommxfilters = TRUE; } else if (!strncmp(*argv, "-nommxcombine", 7)) { @@ -434,10 +502,14 @@ int main(int argc, char **argv) readpng2_version_info(); fprintf(stderr, "\n" "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n" -#if (defined(__i386__) || defined(_M_IX86)) +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) " %*s [[-nommxfilters] [-nommxcombine] [-nommxinterlace] | -nommx]\n" #endif +#ifdef FEATURE_LOOP + " %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n" +#else " %*s [-usleep dur | -timing] [-pause] file.png\n\n" +#endif " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" " exp \ttransfer-function exponent (``gamma'') of the display\n" "\t\t system in floating-point format (e.g., ``%.1f''); equal\n" @@ -446,9 +518,14 @@ int main(int argc, char **argv) " bg \tdesired background color in 7-character hex RGB format\n" "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" "\t\t used with transparent images; overrides -bgpat\n" - " pat \tdesired background pattern number (1-%d); used with\n" + " pat \tdesired background pattern number (0-%d); used with\n" "\t\t transparent images; overrides -bgcolor\n" -#if (defined(__i386__) || defined(_M_IX86)) +#ifdef FEATURE_LOOP + " -loop\tloops through background images after initial display\n" + "\t\t is complete (depends on -bgpat)\n" + " sec \tseconds to display each background image (default = 2)\n" +#endif +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) " -nommx*\tdisable optimized MMX routines for decoding row filters,\n" "\t\t combining rows, and expanding interlacing, respectively\n" #endif @@ -460,10 +537,10 @@ int main(int argc, char **argv) "\nPress Q, Esc or mouse button 1 (within image window, after image\n" "is displayed) to quit.\n" "\n", PROGNAME, -#if (defined(__i386__) || defined(_M_IX86)) - strlen(PROGNAME), " ", +#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) + (int)strlen(PROGNAME), " ", #endif - strlen(PROGNAME), " ", default_display_exponent, num_bgpat); + (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1); exit(1); } @@ -530,13 +607,111 @@ int main(int argc, char **argv) } +#ifdef FEATURE_LOOP + + if (loop && bg_image) { + for (;;) { + int i, use_sleep; + struct timeval now, then; + + /* get current time and add loop_interval to get target time */ + if (gettimeofday(&then, NULL) == 0) { + then.tv_sec += loop_interval; + use_sleep = FALSE; + } else + use_sleep = TRUE; + + /* do quick check for a quit event but don't wait for it */ + /* GRR BUG: should also check for Expose events and redraw... */ + if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e)) + if (QUIT(e,k)) + break; + + /* generate next background image */ + if (++pat >= num_bgpat) + pat = 0; + rpng2_x_reload_bg_image(); + + /* wait for timeout, using whatever means are available */ + if (use_sleep || gettimeofday(&now, NULL) != 0) { + for (i = loop_interval; i > 0; --i) { + sleep(1); + /* GRR BUG: also need to check for Expose (and redraw!) */ + if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, + &e) && QUIT(e,k)) + break; + } + } else { + /* Y2038 BUG! */ + if (now.tv_sec < then.tv_sec || + (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec)) + { + int quit = FALSE; + long seconds_to_go = then.tv_sec - now.tv_sec; + long usleep_usec; + + /* basically chew up most of remaining loop-interval with + * calls to sleep(1) interleaved with checks for quit + * events, but also recalc time-to-go periodically; when + * done, clean up any remaining time with usleep() call + * (could also use SIGALRM, but signals are a pain...) */ + while (seconds_to_go-- > 1) { + int seconds_done = 0; + + for (i = seconds_to_go; i > 0 && !quit; --i) { + sleep(1); + /* GRR BUG: need to check for Expose and redraw */ + if (XCheckMaskEvent(display, KeyPressMask | + ButtonPressMask, &e) && QUIT(e,k)) + quit = TRUE; + if (++seconds_done > 1000) + break; /* time to redo seconds_to_go meas. */ + } + if (quit) + break; + + /* OK, more than 1000 seconds since last check: + * correct the time-to-go measurement for drift */ + if (gettimeofday(&now, NULL) == 0) { + if (now.tv_sec >= then.tv_sec) + break; + seconds_to_go = then.tv_sec - now.tv_sec; + } else + ++seconds_to_go; /* restore what we subtracted */ + } + if (quit) + break; /* breaks outer do-loop, skips redisplay */ + + /* since difference between "now" and "then" is already + * eaten up to within a couple of seconds, don't need to + * worry about overflow--but might have overshot (neg.) */ + if (gettimeofday(&now, NULL) == 0) { + usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) + + then.tv_usec - now.tv_usec; + if (usleep_usec > 0) + usleep((ulg)usleep_usec); + } + } + } + + /* composite image against new background and display (note that + * we do not take into account the time spent doing this...) */ + rpng2_x_redisplay_image (0, 0, rpng2_info.width, rpng2_info.height); + } + + } else /* FALL THROUGH and do the normal thing */ + +#endif /* FEATURE_LOOP */ + /* wait for the user to tell us when to quit */ - do + do { XNextEvent(display, &e); - while (!(e.type == ButtonPress && e.xbutton.button == Button1) && - !(e.type == KeyPress && /* v--- or 1 for shifted keys */ - ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) )); + if (e.type == Expose) { + XExposeEvent *ex = (XExposeEvent *)&e; + rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height); + } + } while (!QUIT(e,k)); /* we're done: clean up all image and X resources and go away */ @@ -594,7 +769,6 @@ static void rpng2_x_init(void) * If we/it segfault instead, seems like a libpng bug... */ /* we're here via libpng callback, so if window fails, clean and bail */ -printf("readpng2_cleanup.\n"); readpng2_cleanup(&rpng2_info); rpng2_x_cleanup(); exit(2); @@ -619,11 +793,12 @@ static int rpng2_x_create_window(void) XEvent e; XGCValues gcvalues; XSetWindowAttributes attr; - XSizeHints *size_hints; XTextProperty windowName, *pWindowName = &windowName; XTextProperty iconName, *pIconName = &iconName; XVisualInfo visual_info; + XSizeHints *size_hints; XWMHints *wm_hints; + XClassHint *class_hints; Trace((stderr, "beginning rpng2_x_create_window()\n")) @@ -746,8 +921,13 @@ static int rpng2_x_create_window(void) wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; } + if ((class_hints = XAllocClassHint()) != NULL) { + class_hints->res_name = res_name; + class_hints->res_class = res_class; + } + XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, - size_hints, wm_hints, NULL); + size_hints, wm_hints, class_hints); /* various properties and hints no longer needed; free memory */ if (pWindowName) @@ -758,6 +938,8 @@ static int rpng2_x_create_window(void) XFree(size_hints); if (wm_hints) XFree(wm_hints); + if (class_hints) + XFree(class_hints); XMapWindow(display, window); @@ -855,7 +1037,7 @@ static int rpng2_x_load_bg_image(void) uch r1, r2, g1, g2, b1, b2; uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; int k, hmax, max; - int xidx, yidx, yidx_max = (bgscale-1); + int xidx, yidx, yidx_max; int even_odd_vert, even_odd_horiz, even_odd; int invert_gradient2 = (bg[pat].type & 0x08); int invert_column; @@ -877,6 +1059,9 @@ static int rpng2_x_load_bg_image(void) return 1; } + bgscale = (pat == 0)? 8 : bgscale_default; + yidx_max = bgscale - 1; + /*--------------------------------------------------------------------------- Vertical gradients (ramps) in NxN squares, alternating direction and colors (N == bgscale). @@ -1068,23 +1253,40 @@ static int rpng2_x_load_bg_image(void) if (depth == 24 || depth == 32) { ulg red, green, blue; + int bpp = ximage->bits_per_pixel; for (row = 0; row < rpng2_info.height; ++row) { src = bg_data + row*bg_rowbytes; dest = ximage->data + row*ximage_rowbytes; - for (i = rpng2_info.width; i > 0; --i) { - red = *src++; - green = *src++; - blue = *src++; - pixel = (red << RShift) | - (green << GShift) | - (blue << BShift); - /* recall that we set ximage->byte_order = MSBFirst above */ - /* GRR BUG: this assumes bpp == 32, but may be 24: */ - *dest++ = (char)((pixel >> 24) & 0xff); - *dest++ = (char)((pixel >> 16) & 0xff); - *dest++ = (char)((pixel >> 8) & 0xff); - *dest++ = (char)( pixel & 0xff); + if (bpp == 32) { /* slightly optimized version */ + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } else { + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + /* GRR BUG? this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } } } @@ -1155,10 +1357,7 @@ static void rpng2_x_display_row(ulg row) PROGNAME, prevpass + 1); do XNextEvent(display, &e); - while (!(e.type == ButtonPress && e.xbutton.button == Button1) - && !(e.type == KeyPress && - ((k = XLookupKeysym(&e.xkey, 0)) == XK_q - || k == XK_Escape) )) ; + while (!QUIT(e,k)); } fprintf(stderr, "%s: pass %d of 7\r", PROGNAME, rpng2_info.pass + 1); fflush(stderr); @@ -1179,6 +1378,7 @@ static void rpng2_x_display_row(ulg row) if (depth == 24 || depth == 32) { ulg red, green, blue; + int bpp = ximage->bits_per_pixel; src = rpng2_info.image_data + row*rpng2_info.rowbytes; if (bg_image) @@ -1193,11 +1393,18 @@ static void rpng2_x_display_row(ulg row) (green << GShift) | (blue << BShift); /* recall that we set ximage->byte_order = MSBFirst above */ - /* GRR BUG: this assumes bpp == 32, but may be 24: */ - *dest++ = (char)((pixel >> 24) & 0xff); - *dest++ = (char)((pixel >> 16) & 0xff); - *dest++ = (char)((pixel >> 8) & 0xff); - *dest++ = (char)( pixel & 0xff); + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG? this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } } } else /* if (rpng2_info.channels == 4) */ { for (i = rpng2_info.width; i > 0; --i) { @@ -1230,11 +1437,18 @@ static void rpng2_x_display_row(ulg row) (green << GShift) | (blue << BShift); /* recall that we set ximage->byte_order = MSBFirst above */ - /* GRR BUG: this assumes bpp == 32, but may be 24: */ - *dest++ = (char)((pixel >> 24) & 0xff); - *dest++ = (char)((pixel >> 16) & 0xff); - *dest++ = (char)((pixel >> 8) & 0xff); - *dest++ = (char)( pixel & 0xff); + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG? this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } } } @@ -1352,6 +1566,472 @@ static void rpng2_x_finish_display(void) +static void rpng2_x_redisplay_image(ulg startcol, ulg startrow, + ulg width, ulg height) +{ + uch bg_red = rpng2_info.bg_red; + uch bg_green = rpng2_info.bg_green; + uch bg_blue = rpng2_info.bg_blue; + uch *src, *src2=NULL; + char *dest; + uch r, g, b, a; + ulg i, row, lastrow = 0; + ulg pixel; + int ximage_rowbytes = ximage->bytes_per_line; + + + Trace((stderr, "beginning display loop (image_channels == %d)\n", + image_channels)) + Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n", + rpng2_info.width, image_rowbytes, ximage_rowbytes)) + Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) + Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? + "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) + +/*--------------------------------------------------------------------------- + Aside from the use of the rpng2_info struct and of src2 (for background + image), this routine is identical to rpng_x_display_image() in the non- + progressive version of the program--for the simple reason that redisplay + of the image against a new background happens after the image is fully + decoded and therefore is, by definition, non-progressive. + ---------------------------------------------------------------------------*/ + + if (depth == 24 || depth == 32) { + ulg red, green, blue; + int bpp = ximage->bits_per_pixel; + + for (lastrow = row = startrow; row < startrow+height; ++row) { + src = rpng2_info.image_data + row*rpng2_info.rowbytes; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + red = *src++; + green = *src++; + blue = *src++; +#ifdef NO_24BIT_MASKS + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#else + red = (RShift < 0)? red << (-RShift) : red >> RShift; + green = (GShift < 0)? green << (-GShift) : green >> GShift; + blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; + pixel = (red & RMask) | (green & GMask) | (blue & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG */ + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift/RMask/etc. here, too) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#endif + } + + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + red = r; + green = g; + blue = b; + } else if (a == 0) { + red = bg_red; + green = bg_green; + blue = bg_blue; + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result into the + * first argument */ + alpha_composite(red, r, a, bg_red); + alpha_composite(green, g, a, bg_green); + alpha_composite(blue, b, a, bg_blue); + } +#ifdef NO_24BIT_MASKS + pixel = (red << RShift) | + (green << GShift) | + (blue << BShift); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift, RMask, etc.) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#else + red = (RShift < 0)? red << (-RShift) : red >> RShift; + green = (GShift < 0)? green << (-GShift) : green >> GShift; + blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; + pixel = (red & RMask) | (green & GMask) | (blue & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + if (bpp == 32) { + *dest++ = (char)((pixel >> 24) & 0xff); + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } else { + /* GRR BUG */ + /* this assumes bpp == 24 & bits are packed low */ + /* (probably need to use RShift/RMask/etc. here, too) */ + *dest++ = (char)((pixel >> 16) & 0xff); + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } +#endif + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, rpng2_info.width, 16); + XFlush(display); + lastrow = row + 1; + } + } + + } else if (depth == 16) { + ush red, green, blue; + + for (lastrow = row = startrow; row < startrow+height; ++row) { + src = rpng2_info.row_pointers[row]; + if (bg_image) + src2 = bg_data + row*bg_rowbytes; + dest = ximage->data + row*ximage_rowbytes; + if (rpng2_info.channels == 3) { + for (i = rpng2_info.width; i > 0; --i) { + red = ((ush)(*src) << 8); + ++src; + green = ((ush)(*src) << 8); + ++src; + blue = ((ush)(*src) << 8); + ++src; + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } else /* if (rpng2_info.channels == 4) */ { + for (i = rpng2_info.width; i > 0; --i) { + r = *src++; + g = *src++; + b = *src++; + a = *src++; + if (bg_image) { + bg_red = *src2++; + bg_green = *src2++; + bg_blue = *src2++; + } + if (a == 255) { + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } else if (a == 0) { + red = ((ush)bg_red << 8); + green = ((ush)bg_green << 8); + blue = ((ush)bg_blue << 8); + } else { + /* this macro (from png.h) composites the foreground + * and background values and puts the result back into + * the first argument (== fg byte here: safe) */ + alpha_composite(r, r, a, bg_red); + alpha_composite(g, g, a, bg_green); + alpha_composite(b, b, a, bg_blue); + red = ((ush)r << 8); + green = ((ush)g << 8); + blue = ((ush)b << 8); + } + pixel = ((red >> RShift) & RMask) | + ((green >> GShift) & GMask) | + ((blue >> BShift) & BMask); + /* recall that we set ximage->byte_order = MSBFirst above */ + *dest++ = (char)((pixel >> 8) & 0xff); + *dest++ = (char)( pixel & 0xff); + } + } + /* display after every 16 lines */ + if (((row+1) & 0xf) == 0) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, rpng2_info.width, 16); + XFlush(display); + lastrow = row + 1; + } + } + + } else /* depth == 8 */ { + + /* GRR: add 8-bit support */ + + } + + Trace((stderr, "calling final XPutImage()\n")) + if (lastrow < startrow+height) { + XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, + (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow); + XFlush(display); + } + +} /* end function rpng2_x_redisplay_image() */ + + + + + +#ifdef FEATURE_LOOP + +static void rpng2_x_reload_bg_image(void) +{ + char *dest; + uch r1, r2, g1, g2, b1, b2; + uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; + int k, hmax, max; + int xidx, yidx, yidx_max; + int even_odd_vert, even_odd_horiz, even_odd; + int invert_gradient2 = (bg[pat].type & 0x08); + int invert_column; + ulg i, row; + + + bgscale = (pat == 0)? 8 : bgscale_default; + yidx_max = bgscale - 1; + +/*--------------------------------------------------------------------------- + Vertical gradients (ramps) in NxN squares, alternating direction and + colors (N == bgscale). + ---------------------------------------------------------------------------*/ + + if ((bg[pat].type & 0x07) == 0) { + uch r1_min = rgb[bg[pat].rgb1_min].r; + uch g1_min = rgb[bg[pat].rgb1_min].g; + uch b1_min = rgb[bg[pat].rgb1_min].b; + uch r2_min = rgb[bg[pat].rgb2_min].r; + uch g2_min = rgb[bg[pat].rgb2_min].g; + uch b2_min = rgb[bg[pat].rgb2_min].b; + int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; + int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min; + int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; + int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min; + int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; + int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = (int)(row % bgscale); + even_odd_vert = (int)((row / bgscale) & 1); + + r1 = r1_min + (r1_diff * yidx) / yidx_max; + g1 = g1_min + (g1_diff * yidx) / yidx_max; + b1 = b1_min + (b1_diff * yidx) / yidx_max; + r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; + g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max; + b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; + + r2 = r2_min + (r2_diff * yidx) / yidx_max; + g2 = g2_min + (g2_diff * yidx) / yidx_max; + b2 = b2_min + (b2_diff * yidx) / yidx_max; + r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; + g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max; + b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; + + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + even_odd_horiz = (int)((i / bgscale) & 1); + even_odd = even_odd_vert ^ even_odd_horiz; + invert_column = + (even_odd_horiz && (bg[pat].type & 0x10)); + if (even_odd == 0) { /* gradient #1 */ + if (invert_column) { + *dest++ = r1_inv; + *dest++ = g1_inv; + *dest++ = b1_inv; + } else { + *dest++ = r1; + *dest++ = g1; + *dest++ = b1; + } + } else { /* gradient #2 */ + if ((invert_column && invert_gradient2) || + (!invert_column && !invert_gradient2)) + { + *dest++ = r2; /* not inverted or */ + *dest++ = g2; /* doubly inverted */ + *dest++ = b2; + } else { + *dest++ = r2_inv; + *dest++ = g2_inv; /* singly inverted */ + *dest++ = b2_inv; + } + } + } + } + +/*--------------------------------------------------------------------------- + Soft gradient-diamonds with scale = bgscale. Code contributed by Adam + M. Costello. + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 1) { + + hmax = (bgscale-1)/2; /* half the max weight of a color */ + max = 2*hmax; /* the max weight of a color */ + + r1 = rgb[bg[pat].rgb1_max].r; + g1 = rgb[bg[pat].rgb1_max].g; + b1 = rgb[bg[pat].rgb1_max].b; + r2 = rgb[bg[pat].rgb2_max].r; + g2 = rgb[bg[pat].rgb2_max].g; + b2 = rgb[bg[pat].rgb2_max].b; + + for (row = 0; row < rpng2_info.height; ++row) { + yidx = (int)(row % bgscale); + if (yidx > hmax) + yidx = bgscale-1 - yidx; + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + xidx = (int)(i % bgscale); + if (xidx > hmax) + xidx = bgscale-1 - xidx; + k = xidx + yidx; + *dest++ = (k*r1 + (max-k)*r2) / max; + *dest++ = (k*g1 + (max-k)*g2) / max; + *dest++ = (k*b1 + (max-k)*b2) / max; + } + } + +/*--------------------------------------------------------------------------- + Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- + soids will equal bgscale?]. This one is slow but very cool. Code con- + tributed by Pieter S. van der Meulen (originally in Smalltalk). + ---------------------------------------------------------------------------*/ + + } else if ((bg[pat].type & 0x07) == 2) { + uch ch; + int ii, x, y, hw, hh, grayspot; + double freq, rotate, saturate, gray, intensity; + double angle=0.0, aoffset=0.0, maxDist, dist; + double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; + + hh = (int)(rpng2_info.height / 2); + hw = (int)(rpng2_info.width / 2); + + /* variables for radial waves: + * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] + * freq: number of color beams originating from the center + * grayspot: size of the graying center area (anti-alias) + * rotate: rotation of the beams as a function of radius + * saturate: saturation of beams' shape azimuthally + */ + angle = CLIP(angle, 0.0, 360.0); + grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); + freq = MAX((double)bg[pat].bg_freq, 0.0); + saturate = (double)bg[pat].bg_bsat * 0.1; + rotate = (double)bg[pat].bg_brot * 0.1; + gray = 0.0; + intensity = 0.0; + maxDist = (double)((hw*hw) + (hh*hh)); + + for (row = 0; row < rpng2_info.height; ++row) { + y = (int)(row - hh); + dest = (char *)bg_data + row*bg_rowbytes; + for (i = 0; i < rpng2_info.width; ++i) { + x = (int)(i - hw); + angle = (x == 0)? PI_2 : atan((double)y / (double)x); + gray = (double)MAX(ABS(y), ABS(x)) / grayspot; + gray = MIN(1.0, gray); + dist = (double)((x*x) + (y*y)) / maxDist; + intensity = cos((angle+(rotate*dist*PI)) * freq) * + gray * saturate; + intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; + hue = (angle + PI) * INV_PI_360 + aoffset; + s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); + s = MIN(MAX(s,0.0), 1.0); + v = MIN(MAX(intensity,0.0), 1.0); + + if (s == 0.0) { + ch = (uch)(v * 255.0); + *dest++ = ch; + *dest++ = ch; + *dest++ = ch; + } else { + if ((hue < 0.0) || (hue >= 360.0)) + hue -= (((int)(hue / 360.0)) * 360.0); + hue /= 60.0; + ii = (int)hue; + f = hue - (double)ii; + p = (1.0 - s) * v; + q = (1.0 - (s * f)) * v; + t = (1.0 - (s * (1.0 - f))) * v; + if (ii == 0) { red = v; green = t; blue = p; } + else if (ii == 1) { red = q; green = v; blue = p; } + else if (ii == 2) { red = p; green = v; blue = t; } + else if (ii == 3) { red = p; green = q; blue = v; } + else if (ii == 4) { red = t; green = p; blue = v; } + else if (ii == 5) { red = v; green = p; blue = q; } + *dest++ = (uch)(red * 255.0); + *dest++ = (uch)(green * 255.0); + *dest++ = (uch)(blue * 255.0); + } + } + } + } + +} /* end function rpng2_x_reload_bg_image() */ + + + + + +static int is_number(char *p) +{ + while (*p) { + if (!isdigit(*p)) + return FALSE; + ++p; + } + return TRUE; +} + +#endif /* FEATURE_LOOP */ + + + + + static void rpng2_x_cleanup(void) { if (bg_image && bg_data) { diff --git a/contrib/gregbook/wpng.c b/contrib/gregbook/wpng.c index d6e85148b..a06e3529e 100644 --- a/contrib/gregbook/wpng.c +++ b/contrib/gregbook/wpng.c @@ -5,8 +5,10 @@ This program converts certain NetPBM binary files (grayscale and RGB, maxval = 255) to PNG. Non-interlaced PNGs are written progressively; interlaced PNGs are read and written in one memory-intensive blast. + Thanks to Jean-loup Gailly for providing the necessary trick to read - interactive text from the keyboard while stdin is redirected. + interactive text from the keyboard while stdin is redirected. Thanks + to Cosmin Truta for Cygwin fixes. NOTE: includes provisional support for PNM type "8" (portable alphamap) images, presumed to be a 32-bit interleaved RGBA format; no pro- @@ -24,16 +26,32 @@ - 1.02: modified to allow abbreviated options - 1.03: removed extraneous character from usage screen; fixed bug in command-line parsing + - 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix + (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff) + - 2.00: dual-licensed (added GNU GPL) + + [REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line + dose not work! In order to do something useful I needed to redirect + both input and output, with cygwin and with bcc32 as well. Under + Linux, the same wpng appears to work fine. I don't know what is + the problem."] --------------------------------------------------------------------------- - Copyright (c) 1998-2000 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -50,16 +68,35 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #define PROGNAME "wpng" -#define VERSION "1.03 of 19 March 2000" +#define VERSION "2.00 of 2 June 2007" #define APPNAME "Simple PGM/PPM/PAM to PNG Converter" #if defined(__MSDOS__) || defined(__OS2__) # define DOS_OS2_W32 -#elif defined(_WIN32) || defined(__WIN32__) -# define DOS_OS2_W32 +#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) +# ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */ +# define DOS_OS2_W32 +# endif #endif #include <stdio.h> diff --git a/contrib/gregbook/writepng.c b/contrib/gregbook/writepng.c index 6802b12fb..e6d81ea40 100644 --- a/contrib/gregbook/writepng.c +++ b/contrib/gregbook/writepng.c @@ -4,13 +4,20 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2000 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -27,6 +34,23 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ diff --git a/contrib/gregbook/writepng.h b/contrib/gregbook/writepng.h index 93c3da820..78b966b58 100644 --- a/contrib/gregbook/writepng.h +++ b/contrib/gregbook/writepng.h @@ -4,13 +4,20 @@ --------------------------------------------------------------------------- - Copyright (c) 1998-2000 Greg Roelofs. All rights reserved. + Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. This software is provided "as is," without warranty of any kind, express or implied. In no event shall the author or contributors be held liable for any damages arising in any way from the use of this software. + The contents of this file are DUAL-LICENSED. You may modify and/or + redistribute this software according to the terms of one of the + following two licenses (at your option): + + + LICENSE 1 ("BSD-like with advertising clause"): + Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: @@ -27,6 +34,23 @@ and contributors for the book, "PNG: The Definitive Guide," published by O'Reilly and Associates. + + LICENSE 2 (GNU GPL v2 or later): + + 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 + ---------------------------------------------------------------------------*/ #ifndef TRUE |