aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING340
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE50
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32130
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi104
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx132
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32113
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README186
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com132
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c311
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h88
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c511
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h116
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c179
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c728
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c904
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c1253
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c2107
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.pngbin0 -> 12901 bytes
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c853
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c400
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h133
21 files changed, 8770 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING
new file mode 100644
index 0000000..c2d382b
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING
@@ -0,0 +1,340 @@
1 GNU GENERAL PUBLIC LICENSE
2 Version 2, June 1991
3
4 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
6 Everyone is permitted to copy and distribute verbatim copies
7 of this license document, but changing it is not allowed.
8
9 Preamble
10
11 The licenses for most software are designed to take away your
12freedom to share and change it. By contrast, the GNU General Public
13License is intended to guarantee your freedom to share and change free
14software--to make sure the software is free for all its users. This
15General Public License applies to most of the Free Software
16Foundation's software and to any other program whose authors commit to
17using it. (Some other Free Software Foundation software is covered by
18the GNU Library General Public License instead.) You can apply it to
19your programs, too.
20
21 When we speak of free software, we are referring to freedom, not
22price. Our General Public Licenses are designed to make sure that you
23have the freedom to distribute copies of free software (and charge for
24this service if you wish), that you receive source code or can get it
25if you want it, that you can change the software or use pieces of it
26in new free programs; and that you know you can do these things.
27
28 To protect your rights, we need to make restrictions that forbid
29anyone to deny you these rights or to ask you to surrender the rights.
30These restrictions translate to certain responsibilities for you if you
31distribute copies of the software, or if you modify it.
32
33 For example, if you distribute copies of such a program, whether
34gratis or for a fee, you must give the recipients all the rights that
35you have. You must make sure that they, too, receive or can get the
36source code. And you must show them these terms so they know their
37rights.
38
39 We protect your rights with two steps: (1) copyright the software, and
40(2) offer you this license which gives you legal permission to copy,
41distribute and/or modify the software.
42
43 Also, for each author's protection and ours, we want to make certain
44that everyone understands that there is no warranty for this free
45software. If the software is modified by someone else and passed on, we
46want its recipients to know that what they have is not the original, so
47that any problems introduced by others will not reflect on the original
48authors' reputations.
49
50 Finally, any free program is threatened constantly by software
51patents. We wish to avoid the danger that redistributors of a free
52program will individually obtain patent licenses, in effect making the
53program proprietary. To prevent this, we have made it clear that any
54patent must be licensed for everyone's free use or not licensed at all.
55
56 The precise terms and conditions for copying, distribution and
57modification follow.
58
59 GNU GENERAL PUBLIC LICENSE
60 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
62 0. This License applies to any program or other work which contains
63a notice placed by the copyright holder saying it may be distributed
64under the terms of this General Public License. The "Program", below,
65refers to any such program or work, and a "work based on the Program"
66means either the Program or any derivative work under copyright law:
67that is to say, a work containing the Program or a portion of it,
68either verbatim or with modifications and/or translated into another
69language. (Hereinafter, translation is included without limitation in
70the term "modification".) Each licensee is addressed as "you".
71
72Activities other than copying, distribution and modification are not
73covered by this License; they are outside its scope. The act of
74running the Program is not restricted, and the output from the Program
75is covered only if its contents constitute a work based on the
76Program (independent of having been made by running the Program).
77Whether that is true depends on what the Program does.
78
79 1. You may copy and distribute verbatim copies of the Program's
80source code as you receive it, in any medium, provided that you
81conspicuously and appropriately publish on each copy an appropriate
82copyright notice and disclaimer of warranty; keep intact all the
83notices that refer to this License and to the absence of any warranty;
84and give any other recipients of the Program a copy of this License
85along with the Program.
86
87You may charge a fee for the physical act of transferring a copy, and
88you may at your option offer warranty protection in exchange for a fee.
89
90 2. You may modify your copy or copies of the Program or any portion
91of it, thus forming a work based on the Program, and copy and
92distribute such modifications or work under the terms of Section 1
93above, provided that you also meet all of these conditions:
94
95 a) You must cause the modified files to carry prominent notices
96 stating that you changed the files and the date of any change.
97
98 b) You must cause any work that you distribute or publish, that in
99 whole or in part contains or is derived from the Program or any
100 part thereof, to be licensed as a whole at no charge to all third
101 parties under the terms of this License.
102
103 c) If the modified program normally reads commands interactively
104 when run, you must cause it, when started running for such
105 interactive use in the most ordinary way, to print or display an
106 announcement including an appropriate copyright notice and a
107 notice that there is no warranty (or else, saying that you provide
108 a warranty) and that users may redistribute the program under
109 these conditions, and telling the user how to view a copy of this
110 License. (Exception: if the Program itself is interactive but
111 does not normally print such an announcement, your work based on
112 the Program is not required to print an announcement.)
113
114These requirements apply to the modified work as a whole. If
115identifiable sections of that work are not derived from the Program,
116and can be reasonably considered independent and separate works in
117themselves, then this License, and its terms, do not apply to those
118sections when you distribute them as separate works. But when you
119distribute the same sections as part of a whole which is a work based
120on the Program, the distribution of the whole must be on the terms of
121this License, whose permissions for other licensees extend to the
122entire whole, and thus to each and every part regardless of who wrote it.
123
124Thus, it is not the intent of this section to claim rights or contest
125your rights to work written entirely by you; rather, the intent is to
126exercise the right to control the distribution of derivative or
127collective works based on the Program.
128
129In addition, mere aggregation of another work not based on the Program
130with the Program (or with a work based on the Program) on a volume of
131a storage or distribution medium does not bring the other work under
132the scope of this License.
133
134 3. You may copy and distribute the Program (or a work based on it,
135under Section 2) in object code or executable form under the terms of
136Sections 1 and 2 above provided that you also do one of the following:
137
138 a) Accompany it with the complete corresponding machine-readable
139 source code, which must be distributed under the terms of Sections
140 1 and 2 above on a medium customarily used for software interchange; or,
141
142 b) Accompany it with a written offer, valid for at least three
143 years, to give any third party, for a charge no more than your
144 cost of physically performing source distribution, a complete
145 machine-readable copy of the corresponding source code, to be
146 distributed under the terms of Sections 1 and 2 above on a medium
147 customarily used for software interchange; or,
148
149 c) Accompany it with the information you received as to the offer
150 to distribute corresponding source code. (This alternative is
151 allowed only for noncommercial distribution and only if you
152 received the program in object code or executable form with such
153 an offer, in accord with Subsection b above.)
154
155The source code for a work means the preferred form of the work for
156making modifications to it. For an executable work, complete source
157code means all the source code for all modules it contains, plus any
158associated interface definition files, plus the scripts used to
159control compilation and installation of the executable. However, as a
160special exception, the source code distributed need not include
161anything that is normally distributed (in either source or binary
162form) with the major components (compiler, kernel, and so on) of the
163operating system on which the executable runs, unless that component
164itself accompanies the executable.
165
166If distribution of executable or object code is made by offering
167access to copy from a designated place, then offering equivalent
168access to copy the source code from the same place counts as
169distribution of the source code, even though third parties are not
170compelled to copy the source along with the object code.
171
172 4. You may not copy, modify, sublicense, or distribute the Program
173except as expressly provided under this License. Any attempt
174otherwise to copy, modify, sublicense or distribute the Program is
175void, and will automatically terminate your rights under this License.
176However, parties who have received copies, or rights, from you under
177this License will not have their licenses terminated so long as such
178parties remain in full compliance.
179
180 5. You are not required to accept this License, since you have not
181signed it. However, nothing else grants you permission to modify or
182distribute the Program or its derivative works. These actions are
183prohibited by law if you do not accept this License. Therefore, by
184modifying or distributing the Program (or any work based on the
185Program), you indicate your acceptance of this License to do so, and
186all its terms and conditions for copying, distributing or modifying
187the Program or works based on it.
188
189 6. Each time you redistribute the Program (or any work based on the
190Program), the recipient automatically receives a license from the
191original licensor to copy, distribute or modify the Program subject to
192these terms and conditions. You may not impose any further
193restrictions on the recipients' exercise of the rights granted herein.
194You are not responsible for enforcing compliance by third parties to
195this License.
196
197 7. If, as a consequence of a court judgment or allegation of patent
198infringement or for any other reason (not limited to patent issues),
199conditions are imposed on you (whether by court order, agreement or
200otherwise) that contradict the conditions of this License, they do not
201excuse you from the conditions of this License. If you cannot
202distribute so as to satisfy simultaneously your obligations under this
203License and any other pertinent obligations, then as a consequence you
204may not distribute the Program at all. For example, if a patent
205license would not permit royalty-free redistribution of the Program by
206all those who receive copies directly or indirectly through you, then
207the only way you could satisfy both it and this License would be to
208refrain entirely from distribution of the Program.
209
210If any portion of this section is held invalid or unenforceable under
211any particular circumstance, the balance of the section is intended to
212apply and the section as a whole is intended to apply in other
213circumstances.
214
215It is not the purpose of this section to induce you to infringe any
216patents or other property right claims or to contest validity of any
217such claims; this section has the sole purpose of protecting the
218integrity of the free software distribution system, which is
219implemented by public license practices. Many people have made
220generous contributions to the wide range of software distributed
221through that system in reliance on consistent application of that
222system; it is up to the author/donor to decide if he or she is willing
223to distribute software through any other system and a licensee cannot
224impose that choice.
225
226This section is intended to make thoroughly clear what is believed to
227be a consequence of the rest of this License.
228
229 8. If the distribution and/or use of the Program is restricted in
230certain countries either by patents or by copyrighted interfaces, the
231original copyright holder who places the Program under this License
232may add an explicit geographical distribution limitation excluding
233those countries, so that distribution is permitted only in or among
234countries not thus excluded. In such case, this License incorporates
235the limitation as if written in the body of this License.
236
237 9. The Free Software Foundation may publish revised and/or new versions
238of the General Public License from time to time. Such new versions will
239be similar in spirit to the present version, but may differ in detail to
240address new problems or concerns.
241
242Each version is given a distinguishing version number. If the Program
243specifies a version number of this License which applies to it and "any
244later version", you have the option of following the terms and conditions
245either of that version or of any later version published by the Free
246Software Foundation. If the Program does not specify a version number of
247this License, you may choose any version ever published by the Free Software
248Foundation.
249
250 10. If you wish to incorporate parts of the Program into other free
251programs whose distribution conditions are different, write to the author
252to ask for permission. For software which is copyrighted by the Free
253Software Foundation, write to the Free Software Foundation; we sometimes
254make exceptions for this. Our decision will be guided by the two goals
255of preserving the free status of all derivatives of our free software and
256of promoting the sharing and reuse of software generally.
257
258 NO WARRANTY
259
260 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268REPAIR OR CORRECTION.
269
270 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278POSSIBILITY OF SUCH DAMAGES.
279
280 END OF TERMS AND CONDITIONS
281
282 How to Apply These Terms to Your New Programs
283
284 If you develop a new program, and you want it to be of the greatest
285possible use to the public, the best way to achieve this is to make it
286free software which everyone can redistribute and change under these terms.
287
288 To do so, attach the following notices to the program. It is safest
289to attach them to the start of each source file to most effectively
290convey the exclusion of warranty; and each file should have at least
291the "copyright" line and a pointer to where the full notice is found.
292
293 <one line to give the program's name and a brief idea of what it does.>
294 Copyright (C) <year> <name of author>
295
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
300
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
305
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
309
310
311Also add information on how to contact you by electronic and paper mail.
312
313If the program is interactive, make it output a short notice like this
314when it starts in an interactive mode:
315
316 Gnomovision version 69, Copyright (C) year name of author
317 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 This is free software, and you are welcome to redistribute it
319 under certain conditions; type `show c' for details.
320
321The hypothetical commands `show w' and `show c' should show the appropriate
322parts of the General Public License. Of course, the commands you use may
323be called something other than `show w' and `show c'; they could even be
324mouse-clicks or menu items--whatever suits your program.
325
326You should also get your employer (if you work as a programmer) or your
327school, if any, to sign a "copyright disclaimer" for the program, if
328necessary. Here is a sample; alter the names:
329
330 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 `Gnomovision' (which makes passes at compilers) written by James Hacker.
332
333 <signature of Ty Coon>, 1 April 1989
334 Ty Coon, President of Vice
335
336This General Public License does not permit incorporating your program into
337proprietary programs. If your program is a subroutine library, you may
338consider it more useful to permit linking proprietary applications with the
339library. If this is what you want to do, use the GNU Library General
340Public License instead of this License.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE
new file mode 100644
index 0000000..40a0c8e
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE
@@ -0,0 +1,50 @@
1 ---------------------------------------------------------------------------
2
3 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
4
5 This software is provided "as is," without warranty of any kind,
6 express or implied. In no event shall the author or contributors
7 be held liable for any damages arising in any way from the use of
8 this software.
9
10 The contents of this file are DUAL-LICENSED. You may modify and/or
11 redistribute this software according to the terms of one of the
12 following two licenses (at your option):
13
14
15 LICENSE 1 ("BSD-like with advertising clause"):
16
17 Permission is granted to anyone to use this software for any purpose,
18 including commercial applications, and to alter it and redistribute
19 it freely, subject to the following restrictions:
20
21 1. Redistributions of source code must retain the above copyright
22 notice, disclaimer, and this list of conditions.
23 2. Redistributions in binary form must reproduce the above copyright
24 notice, disclaimer, and this list of conditions in the documenta-
25 tion and/or other materials provided with the distribution.
26 3. All advertising materials mentioning features or use of this
27 software must display the following acknowledgment:
28
29 This product includes software developed by Greg Roelofs
30 and contributors for the book, "PNG: The Definitive Guide,"
31 published by O'Reilly and Associates.
32
33
34 LICENSE 2 (GNU GPL v2 or later):
35
36 This program is free software; you can redistribute it and/or modify
37 it under the terms of the GNU General Public License as published by
38 the Free Software Foundation; either version 2 of the License, or
39 (at your option) any later version.
40
41 This program is distributed in the hope that it will be useful,
42 but WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 GNU General Public License for more details.
45
46 You should have received a copy of the GNU General Public License
47 along with this program; if not, write to the Free Software Foundation,
48 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
49
50 ---------------------------------------------------------------------------
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32
new file mode 100644
index 0000000..a736556
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32
@@ -0,0 +1,130 @@
1# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make.
2# Greg Roelofs
3# Last modified: 2 June 2007
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
8# generally for sale anymore, but it's the thought that counts,
9# right? (Hint: http://www.libpng.org/pub/png/book/ )
10#
11# Invoke this makefile from a DOS-prompt window via:
12#
13# make -f Makefile.mingw32
14#
15# This makefile assumes libpng and zlib have already been built or downloaded
16# and are in subdirectories at the same level as the current subdirectory
17# (as indicated by the PNGDIR and ZDIR macros below). It makes no assumptions
18# at all about the mingw32 installation tree (W32DIR). Edit as appropriate.
19#
20# Note that the names of the dynamic and static libpng and zlib libraries
21# used below may change in later releases of the libraries. This makefile
22# builds both statically and dynamically linked executables by default.
23# (You need only one set, but for testing it can be handy to have both.)
24
25
26# macros --------------------------------------------------------------------
27
28#PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds
29PNGDIR = ../libpng-win32
30PNGINC = -I$(PNGDIR)
31PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked
32PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
33
34#ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds
35ZDIR = ../zlib-win32
36ZINC = -I$(ZDIR)
37ZLIBd = $(ZDIR)/libzdll.a
38ZLIBs = $(ZDIR)/libz.a
39
40# change this to be the path where mingw32 installs its stuff:
41W32DIR =
42#W32DIR = /usr/local/cross-tools/i386-mingw32msvc
43W32INC = -I$(W32DIR)/include
44W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a
45
46CC = gcc
47#CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation
48LD = $(CC)
49RM = rm -f
50CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS)
51# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
52# [-ansi, -pedantic and -W can also be used]
53LDFLAGS = $(MINGW_LDFLAGS)
54O = .o
55E = .exe
56
57INCS = $(PNGINC) $(ZINC) $(W32INC)
58RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm
59RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm
60WLIBSd = $(PNGLIBd) $(ZLIBd)
61WLIBSs = $(PNGLIBs) $(ZLIBs)
62
63RPNG = rpng-win
64RPNG2 = rpng2-win
65WPNG = wpng
66
67ROBJSd = $(RPNG)$(O) readpng.pic$(O)
68ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O)
69WOBJSd = $(WPNG)$(O) writepng.pic$(O)
70
71RPNGs = $(RPNG)-static
72RPNG2s = $(RPNG2)-static
73WPNGs = $(WPNG)-static
74
75ROBJSs = $(RPNG)$(O) readpng$(O)
76ROBJS2s = $(RPNG2)$(O) readpng2$(O)
77WOBJSs = $(WPNG)$(O) writepng$(O)
78
79STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
80DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
81
82EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
83
84
85# implicit make rules -------------------------------------------------------
86
87.c$(O):
88 $(CC) -c $(CFLAGS) $<
89
90%.pic$(O): %.c
91 $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<
92
93
94# dependencies --------------------------------------------------------------
95
96all: $(EXES)
97
98$(RPNGs)$(E): $(ROBJSs)
99 $(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs)
100
101$(RPNG)$(E): $(ROBJSd)
102 $(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd)
103
104$(RPNG2s)$(E): $(ROBJS2s)
105 $(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs)
106
107$(RPNG2)$(E): $(ROBJS2d)
108 $(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd)
109
110$(WPNGs)$(E): $(WOBJSs)
111 $(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs)
112
113$(WPNG)$(E): $(WOBJSd)
114 $(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd)
115
116$(RPNG)$(O): $(RPNG).c readpng.h
117$(RPNG2)$(O): $(RPNG2).c readpng2.h
118$(WPNG)$(O): $(WPNG).c writepng.h
119
120readpng$(O) readpng.pic$(O): readpng.c readpng.h
121readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h
122writepng$(O) writepng.pic$(O): writepng.c writepng.h
123
124
125# maintenance ---------------------------------------------------------------
126
127clean:
128 $(RM) $(EXES)
129 $(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs)
130 $(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi
new file mode 100644
index 0000000..8773a00
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi
@@ -0,0 +1,104 @@
1# Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make.
2# Greg Roelofs
3# Last modified: 7 March 2002
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Buy some for friends
8# and family, too. (Not that this is a blatant plug or anything.)
9#
10# Invoke this makefile from a shell prompt in the usual way; for example:
11#
12# make -f Makefile.sgi
13#
14# This makefile assumes libpng and zlib have already been built or downloaded
15# and are both installed in /usr/local/{include,lib} (as indicated by the
16# PNG* and Z* macros below). Edit as appropriate--choose only ONE each of
17# the PNGINC, PNGLIB, ZINC and ZLIB lines.
18#
19# This makefile builds dynamically linked executables (against libpng and zlib,
20# that is), but that can be changed by uncommenting the appropriate PNGLIB and
21# ZLIB lines.
22
23
24# macros --------------------------------------------------------------------
25
26PNGINC = -I/usr/local/include/libpng15
27PNGLIB = -L/usr/local/lib -lpng15 # dynamically linked against libpng
28#PNGLIB = /usr/local/lib/libpng15.a # statically linked against libpng
29# or:
30#PNGINC = -I../..
31#PNGLIB = -L../.. -lpng
32#PNGLIB = ../../libpng.a
33
34ZINC = -I/usr/local/include
35ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib
36#ZLIB = /usr/local/lib/libz.a # statically linked against zlib
37#ZINC = -I../zlib
38#ZLIB = -L../zlib -lz
39#ZLIB = ../../../zlib/libz.a
40
41XINC = -I/usr/include/X11 # old-style, stock X distributions
42XLIB = -L/usr/lib/X11 -lX11
43#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
44#XLIB = -L/usr/openwin/lib -lX11
45#XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.)
46#XLIB = -L/usr/X11R6/lib -lX11
47
48INCS = $(PNGINC) $(ZINC) $(XINC)
49RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm
50WLIBS = $(PNGLIB) $(ZLIB)
51
52CC = cc
53LD = cc
54RM = rm -f
55# ABI must be the same as that used to build libpng.
56ABI=
57CFLAGS = $(ABI) -O -fullwarn $(INCS)
58LDFLAGS = $(ABI)
59O = .o
60E =
61
62RPNG = rpng-x
63RPNG2 = rpng2-x
64WPNG = wpng
65
66ROBJS = $(RPNG)$(O) readpng$(O)
67ROBJS2 = $(RPNG2)$(O) readpng2$(O)
68WOBJS = $(WPNG)$(O) writepng$(O)
69
70EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
71
72
73# implicit make rules -------------------------------------------------------
74
75.c$(O):
76 $(CC) -c $(CFLAGS) $<
77
78
79# dependencies --------------------------------------------------------------
80
81all: $(EXES)
82
83$(RPNG)$(E): $(ROBJS)
84 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)
85
86$(RPNG2)$(E): $(ROBJS2)
87 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)
88
89$(WPNG)$(E): $(WOBJS)
90 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)
91
92$(RPNG)$(O): $(RPNG).c readpng.h
93$(RPNG2)$(O): $(RPNG2).c readpng2.h
94$(WPNG)$(O): $(WPNG).c writepng.h
95
96readpng$(O): readpng.c readpng.h
97readpng2$(O): readpng2.c readpng2.h
98writepng$(O): writepng.c writepng.h
99
100
101# maintenance ---------------------------------------------------------------
102
103clean:
104 $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx
new file mode 100644
index 0000000..3bffc2f
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx
@@ -0,0 +1,132 @@
1# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.
2# Greg Roelofs
3# Last modified: 2 June 2007
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
8# generally for sale anymore, but it's the thought that counts,
9# right? (Hint: http://www.libpng.org/pub/png/book/ )
10#
11# Invoke this makefile from a shell prompt in the usual way; for example:
12#
13# make -f Makefile.unx
14#
15# This makefile assumes libpng and zlib have already been built or downloaded
16# and are installed in /usr/local/{include,lib} or as otherwise indicated by
17# the PNG* and Z* macros below. Edit as appropriate--choose only ONE each of
18# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines.
19#
20# This makefile builds both dynamically and statically linked executables
21# (against libpng and zlib, that is), but that can be changed by modifying
22# the "EXES =" line. (You need only one set, but for testing it can be handy
23# to have both.)
24
25
26# macros --------------------------------------------------------------------
27
28#PNGDIR = /usr/local/lib
29#PNGINC = -I/usr/local/include/libpng15
30#PNGLIBd = -L$(PNGDIR) -lpng15 # dynamically linked, installed libpng
31#PNGLIBs = $(PNGDIR)/libpng15.a # statically linked, installed libpng
32# or:
33PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds
34#PNGDIR = ../libpng
35PNGINC = -I$(PNGDIR)
36PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng15 # dynamically linked
37PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng
38
39ZDIR = /usr/local/lib
40#ZDIR = /usr/lib64
41ZINC = -I/usr/local/include
42ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib
43ZLIBs = $(ZDIR)/libz.a # statically linked against zlib
44# or:
45#ZDIR = ../zlib
46#ZINC = -I$(ZDIR)
47#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing
48#ZLIBs = $(ZDIR)/libz.a
49
50#XINC = -I/usr/include # old-style, stock X distributions
51#XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX)
52#XINC = -I/usr/openwin/include # Sun workstations (OpenWindows)
53#XLIB = -L/usr/openwin/lib -lX11
54XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.)
55XLIB = -L/usr/X11R6/lib -lX11
56#XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64
57
58INCS = $(PNGINC) $(ZINC) $(XINC)
59RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm
60RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm
61WLIBSd = $(PNGLIBd) $(ZLIBd) -lm
62WLIBSs = $(PNGLIBs) $(ZLIBs)
63
64CC = gcc
65LD = gcc
66RM = rm -f
67CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP
68# [note that -Wall is a gcc-specific compilation flag ("most warnings on")]
69# [-ansi, -pedantic and -W can also be used]
70LDFLAGS =
71O = .o
72E =
73
74RPNG = rpng-x
75RPNG2 = rpng2-x
76WPNG = wpng
77
78RPNGs = $(RPNG)-static
79RPNG2s = $(RPNG2)-static
80WPNGs = $(WPNG)-static
81
82ROBJS = $(RPNG)$(O) readpng$(O)
83ROBJS2 = $(RPNG2)$(O) readpng2$(O)
84WOBJS = $(WPNG)$(O) writepng$(O)
85
86STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)
87DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
88
89EXES = $(STATIC_EXES) $(DYNAMIC_EXES)
90
91
92# implicit make rules -------------------------------------------------------
93
94.c$(O):
95 $(CC) -c $(CFLAGS) $<
96
97
98# dependencies --------------------------------------------------------------
99
100all: $(EXES)
101
102$(RPNGs)$(E): $(ROBJS)
103 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs)
104
105$(RPNG)$(E): $(ROBJS)
106 $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd)
107
108$(RPNG2s)$(E): $(ROBJS2)
109 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs)
110
111$(RPNG2)$(E): $(ROBJS2)
112 $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd)
113
114$(WPNGs)$(E): $(WOBJS)
115 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs)
116
117$(WPNG)$(E): $(WOBJS)
118 $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd)
119
120$(RPNG)$(O): $(RPNG).c readpng.h
121$(RPNG2)$(O): $(RPNG2).c readpng2.h
122$(WPNG)$(O): $(WPNG).c writepng.h
123
124readpng$(O): readpng.c readpng.h
125readpng2$(O): readpng2.c readpng2.h
126writepng$(O): writepng.c writepng.h
127
128
129# maintenance ---------------------------------------------------------------
130
131clean:
132 $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32 b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32
new file mode 100644
index 0000000..eced083
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32
@@ -0,0 +1,113 @@
1# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.
2# Greg Roelofs
3# Last modified: 2 June 2007
4#
5# The programs built by this makefile are described in the book,
6# "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and
7# Associates, 1999). Go buy a copy, eh? Well, OK, it's not
8# generally for sale anymore, but it's the thought that counts,
9# right? (Hint: http://www.libpng.org/pub/png/book/ )
10#
11# Invoke this makefile from a DOS prompt window via:
12#
13# %devstudio%\vc\bin\vcvars32.bat
14# nmake -nologo -f Makefile.w32
15#
16# where %devstudio% is the installation directory for MSVC / DevStudio. If
17# you get "environment out of space" errors, create a desktop shortcut with
18# "c:\windows\command.com /e:4096" as the program command line and set the
19# working directory to this directory. Then double-click to open the new
20# DOS-prompt window with a bigger environment and retry the commands above.
21#
22# This makefile assumes libpng and zlib have already been built or downloaded
23# and are in subdirectories at the same level as the current subdirectory
24# (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate.
25#
26# Note that the names of the dynamic and static libpng and zlib libraries
27# used below may change in later releases of the libraries. This makefile
28# builds statically linked executables, but that can be changed by uncom-
29# menting the appropriate PNGLIB and ZLIB lines.
30
31!include <ntwin32.mak>
32
33
34# macros --------------------------------------------------------------------
35
36PNGPATH = ../libpng
37PNGINC = -I$(PNGPATH)
38#PNGLIB = $(PNGPATH)/pngdll.lib
39PNGLIB = $(PNGPATH)/libpng.lib
40
41ZPATH = ../zlib
42ZINC = -I$(ZPATH)
43#ZLIB = $(ZPATH)/zlibdll.lib
44ZLIB = $(ZPATH)/zlibstat.lib
45
46WINLIBS = -defaultlib:user32.lib gdi32.lib
47# ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.]
48
49INCS = $(PNGINC) $(ZINC)
50RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS)
51WLIBS = $(PNGLIB) $(ZLIB)
52
53CC = cl
54LD = link
55RM = del
56CFLAGS = -nologo -O -W3 $(INCS) $(cvars)
57# [note that -W3 is an MSVC-specific compilation flag ("all warnings on")]
58# [see %devstudio%\vc\include\win32.mak for cvars macro definition]
59O = .obj
60E = .exe
61
62RLDFLAGS = -nologo -subsystem:windows
63WLDFLAGS = -nologo
64
65RPNG = rpng-win
66RPNG2 = rpng2-win
67WPNG = wpng
68
69ROBJS = $(RPNG)$(O) readpng$(O)
70ROBJS2 = $(RPNG2)$(O) readpng2$(O)
71WOBJS = $(WPNG)$(O) writepng$(O)
72
73EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)
74
75
76# implicit make rules -------------------------------------------------------
77
78.c$(O):
79 $(CC) -c $(CFLAGS) $<
80
81
82# dependencies --------------------------------------------------------------
83
84all: $(EXES)
85
86$(RPNG)$(E): $(ROBJS)
87 $(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS)
88
89$(RPNG2)$(E): $(ROBJS2)
90 $(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS)
91
92$(WPNG)$(E): $(WOBJS)
93 $(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS)
94
95$(RPNG)$(O): $(RPNG).c readpng.h
96$(RPNG2)$(O): $(RPNG2).c readpng2.h
97$(WPNG)$(O): $(WPNG).c writepng.h
98
99readpng$(O): readpng.c readpng.h
100readpng2$(O): readpng2.c readpng2.h
101writepng$(O): writepng.c writepng.h
102
103
104# maintenance ---------------------------------------------------------------
105
106clean:
107# ideally we could just do this:
108# $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)
109# ...but the Windows "DEL" command is none too bright, so:
110 $(RM) r*$(E)
111 $(RM) w*$(E)
112 $(RM) r*$(O)
113 $(RM) w*$(O)
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README
new file mode 100644
index 0000000..791fec8
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README
@@ -0,0 +1,186 @@
1 ===========================
2 PNG: The Definitive Guide
3 ===========================
4
5 Source Code
6
7Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free,
8cross-platform demo programs that show how to use the libpng reference
9library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is
10a very simple example that that shows how a standard file-viewer might use
11libpng, while the second is designed to process streaming data and shows
12how a web browser might be written. wpng is a simple command-line program
13that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets
14of PBMPLUS/NetPBM) and converts them to PNG.
15
16The source code for all three demo programs currently compiles under
17Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser,
18zinser@decus.de, for making the necessary changes for OpenVMS and for
19providing an appropriate build script.) Build instructions can be found
20below.
21
22Files:
23
24 README this file
25 LICENSE terms of distribution and reuse (BSD-like or GNU GPL)
26 COPYING GNU General Public License (GPL)
27
28 Makefile.unx Unix makefile
29 Makefile.w32 Windows (MSVC) makefile
30 makevms.com OpenVMS build script
31
32 rpng-win.c Windows front end for the basic viewer
33 rpng-x.c X Window System (Unix, OpenVMS) front end
34 readpng.c generic back end for the basic viewer
35 readpng.h header file for the basic viewer
36
37 rpng2-win.c Windows front end for the progressive viewer
38 rpng2-x.c X front end for the progressive viewer
39 readpng2.c generic back end for the progressive viewer
40 readpng2.h header file for the progressive viewer
41
42 wpng.c generic (text) front end for the converter
43 writepng.c generic back end for the converter
44 writepng.h header file for the converter
45
46 toucan.png transparent PNG for testing (by Stefan Schneider)
47
48Note that, although the programs are designed to be functional, their
49primary purpose is to illustrate how to use libpng to add PNG support to
50other programs. As such, their user interfaces are crude and definitely
51are not intended for everyday use.
52
53Please see http://www.libpng.org/pub/png/pngbook.html for further infor-
54mation and links to the latest version of the source code, and Chapters
5513-15 of the book for detailed discussion of the three programs.
56
57Greg Roelofs
58http://pobox.com/~newt/greg_contact.html
5916 March 2008
60
61
62BUILD INSTRUCTIONS
63
64 - Prerequisites (in order of compilation):
65
66 - zlib http://zlib.net/
67 - libpng http://www.libpng.org/pub/png/libpng.html
68 - pngbook http://www.libpng.org/pub/png/book/sources.html
69
70 The pngbook demo programs are explicitly designed to demonstrate proper
71 coding techniques for using the libpng reference library. As a result,
72 you need to download and build both zlib (on which libpng depends) and
73 libpng. A common build setup is to place the zlib, libpng and pngbook
74 subdirectory trees ("folders") in the same parent directory. Then the
75 libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]),
76 and similarly for the pngbook build.
77
78 Note that all three packages are designed to be built from a command
79 line by default; those who wish to use a graphical or other integrated
80 development environments are on their own.
81
82
83 - Unix:
84
85 Unpack the latest pngbook sources (which should correspond to this
86 README file) into a directory and change into that directory.
87
88 Copy Makefile.unx to Makefile and edit the PNG* and Z* variables
89 appropriately (possibly also the X* variables if necessary).
90
91 make
92
93 There is no "install" target, so copy the three executables somewhere
94 in your path or run them from the current directory. All three will
95 print a basic usage screen when run without any command-line arguments;
96 see the book for more details.
97
98
99 - Windows:
100
101 Unpack the latest pngbook sources (which should correspond to this
102 README file) into a folder, open a "DOS shell" or "command prompt"
103 or equivalent command-line window, and cd into the folder where you
104 unpacked the source code.
105
106 For MSVC, set up the necessary environment variables by invoking
107
108 %devstudio%\vc\bin\vcvars32.bat
109
110 where where %devstudio% is the installation directory for MSVC /
111 DevStudio. If you get "environment out of space" errors under 95/98,
112 create a desktop shortcut with "c:\windows\command.com /e:4096" as
113 the program command line and set the working directory to the pngbook
114 directory. Then double-click to open the new DOS-prompt window with
115 a bigger environment and retry the commands above.
116
117 Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables
118 appropriately (possibly also the "INC" and "LIB" variables if needed).
119 Note that the names of the dynamic and static libpng and zlib libraries
120 used in the makefile may change in later releases of the libraries.
121 Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work.
122 This makefile therefore builds statically linked executables, but if
123 the DLL problems ever get fixed, uncommenting the appropriate PNGLIB
124 and ZLIB lines will build dynamically linked executables instead.
125
126 Do the build by typing
127
128 nmake
129
130 The result should be three executables: rpng-win.exe, rpng2-win.exe,
131 and wpng.exe. Copy them somewhere in your PATH or run them from the
132 current folder. Like the Unix versions, the two windowed programs
133 (rpng and rpng2) now display a usage screen in a console window when
134 invoked without command-line arguments; this is new behavior as of
135 the June 2001 release. Note that the programs use the Unix-style "-"
136 character to specify options, instead of the more common DOS/Windows
137 "/" character. (For example: "rpng2-win -bgpat 4 foo.png", not
138 "rpng2-win /bgpat 4 foo.png")
139
140
141 - OpenVMS:
142
143 Unpack the pngbook sources into a subdirectory and change into that
144 subdirectory.
145
146 Edit makevms.com appropriately, specifically the zpath and pngpath
147 variables.
148
149 @makevms
150
151 To run the programs, they probably first need to be set up as "foreign
152 symbols," with "disk" and "dir" set appropriately:
153
154 $ rpng == "$disk:[dir]rpng-x.exe"
155 $ rpng2 == "$disk:[dir]rpng2-x.exe"
156 $ wpng == "$disk:[dir]wpng.exe"
157
158 All three will print a basic usage screen when run without any command-
159 line arguments; see the book for more details. Note that the options
160 style is Unix-like, i.e., preceded by "-" rather than "/".
161
162
163RUNNING THE PROGRAMS: (VERY) BRIEF INTRO
164
165 rpng is a simple PNG viewer that can display transparent PNGs with a
166 specified background color; for example,
167
168 rpng -bgcolor \#ff0000 toucan.png
169
170 would display the image with a red background. rpng2 is a progressive
171 viewer that simulates a web browser in some respects; it can display
172 images against either a background color or a dynamically generated
173 background image. For example:
174
175 rpng2 -bgpat 16 toucan.png
176
177 wpng is a purely command-line image converter from binary PBMPLUS/NetPBM
178 format (.pgm or .ppm) to PNG; for example,
179
180 wpng -time < toucan-notrans.ppm > toucan-notrans.png
181
182 would convert the specified PPM file (using redirection) to PNG, auto-
183 matically setting the PNG modification-time chunk.
184
185 All options can be abbreviated to the shortest unique value; for example,
186 "-bgc" for -bgcolor (versus "-bgp" for -bgpat), or "-g" for -gamma.
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com
new file mode 100644
index 0000000..29a5727
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com
@@ -0,0 +1,132 @@
1$!------------------------------------------------------------------------------
2$! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS
3$!
4$! Script created by Martin Zinser for libpng; modified by Greg Roelofs
5$! for standalone pngbook source distribution.
6$!
7$!
8$! Set locations where zlib and libpng sources live.
9$!
10$ zpath = ""
11$ pngpath = ""
12$!
13$ if f$search("[---.zlib]zlib.h").nes."" then zpath = "[---.zlib]"
14$ if f$search("[--]png.h").nes."" then pngpath = "[--]"
15$!
16$ if f$search("[-.zlib]zlib.h").nes."" then zpath = "[-.zlib]"
17$ if f$search("[-.libpng]png.h").nes."" then pngpath = "[-.libpng]"
18$!
19$ if zpath .eqs. ""
20$ then
21$ write sys$output "zlib include not found. Exiting..."
22$ exit 2
23$ endif
24$!
25$ if pngpath .eqs. ""
26$ then
27$ write sys$output "libpng include not found. Exiting..."
28$ exit 2
29$ endif
30$!
31$! Look for the compiler used.
32$!
33$ ccopt="/include=(''zpath',''pngpath')"
34$ if f$getsyi("HW_MODEL").ge.1024
35$ then
36$ ccopt = "/prefix=all"+ccopt
37$ comp = "__decc__=1"
38$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
39$ else
40$ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs.""
41$ then
42$ if f$trnlnm("SYS").eqs."" then define sys sys$library:
43$ if f$search("SYS$SYSTEM:VAXC.EXE").eqs.""
44$ then
45$ comp = "__gcc__=1"
46$ CC :== GCC
47$ else
48$ comp = "__vaxc__=1"
49$ endif
50$ else
51$ if f$trnlnm("SYS").eqs."" then define sys decc$library_include:
52$ ccopt = "/decc/prefix=all"+ccopt
53$ comp = "__decc__=1"
54$ endif
55$ endif
56$ open/write lopt lib.opt
57$ write lopt "''pngpath'libpng.olb/lib"
58$ write lopt "''zpath'libz.olb/lib"
59$ close lopt
60$ open/write xopt x11.opt
61$ write xopt "sys$library:decw$xlibshr.exe/share"
62$ close xopt
63$!
64$! Build 'em.
65$!
66$ write sys$output "Compiling PNG book programs ..."
67$ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" -
68 readpng.c readpng.h
69$ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" -
70 readpng2.c readpng2.h
71$ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" -
72 writepng.c writepng.h
73$ write sys$output "Building rpng-x..."
74$ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" -
75 rpng-x.c readpng.h
76$ call make rpng-x.exe -
77 "LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" -
78 rpng-x.obj readpng.obj
79$ write sys$output "Building rpng2-x..."
80$ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" -
81 rpng2-x.c readpng2.h
82$ call make rpng2-x.exe -
83 "LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" -
84 rpng2-x.obj readpng2.obj
85$ write sys$output "Building wpng..."
86$ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" -
87 wpng.c writepng.h
88$ call make wpng.exe -
89 "LINK wpng,writepng,lib.opt/opt" -
90 wpng.obj writepng.obj
91$ exit
92$!
93$!
94$MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES
95$ V = 'F$Verify(0)
96$! P1 = What we are trying to make
97$! P2 = Command to make it
98$! P3 - P8 What it depends on
99$
100$ If F$Search(P1) .Eqs. "" Then Goto Makeit
101$ Time = F$CvTime(F$File(P1,"RDT"))
102$arg=3
103$Loop:
104$ Argument = P'arg
105$ If Argument .Eqs. "" Then Goto Exit
106$ El=0
107$Loop2:
108$ File = F$Element(El," ",Argument)
109$ If File .Eqs. " " Then Goto Endl
110$ AFile = ""
111$Loop3:
112$ OFile = AFile
113$ AFile = F$Search(File)
114$ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl
115$ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit
116$ Goto Loop3
117$NextEL:
118$ El = El + 1
119$ Goto Loop2
120$EndL:
121$ arg=arg+1
122$ If arg .Le. 8 Then Goto Loop
123$ Goto Exit
124$
125$Makeit:
126$ VV=F$VERIFY(0)
127$ write sys$output P2
128$ 'P2
129$ VV='F$Verify(VV)
130$Exit:
131$ If V Then Set Verify
132$ENDSUBROUTINE
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c
new file mode 100644
index 0000000..27a2f11
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c
@@ -0,0 +1,311 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program readpng.c
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#include <stdio.h>
57#include <stdlib.h>
58
59#include "png.h" /* libpng header; includes zlib.h */
60#include "readpng.h" /* typedefs, common macros, public prototypes */
61
62/* future versions of libpng will provide this macro: */
63#ifndef png_jmpbuf
64# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
65#endif
66
67
68static png_structp png_ptr = NULL;
69static png_infop info_ptr = NULL;
70
71png_uint_32 width, height;
72int bit_depth, color_type;
73uch *image_data = NULL;
74
75
76void readpng_version_info(void)
77{
78 fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
79 PNG_LIBPNG_VER_STRING, png_libpng_ver);
80 fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
81 ZLIB_VERSION, zlib_version);
82}
83
84
85/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
86
87int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
88{
89 uch sig[8];
90
91
92 /* first do a quick check that the file really is a PNG image; could
93 * have used slightly more general png_sig_cmp() function instead */
94
95 fread(sig, 1, 8, infile);
96 if (png_sig_cmp(sig, 0, 8))
97 return 1; /* bad signature */
98
99
100 /* could pass pointers to user-defined error handlers instead of NULLs: */
101
102 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
103 if (!png_ptr)
104 return 4; /* out of memory */
105
106 info_ptr = png_create_info_struct(png_ptr);
107 if (!info_ptr) {
108 png_destroy_read_struct(&png_ptr, NULL, NULL);
109 return 4; /* out of memory */
110 }
111
112
113 /* we could create a second info struct here (end_info), but it's only
114 * useful if we want to keep pre- and post-IDAT chunk info separated
115 * (mainly for PNG-aware image editors and converters) */
116
117
118 /* setjmp() must be called in every function that calls a PNG-reading
119 * libpng function */
120
121 if (setjmp(png_jmpbuf(png_ptr))) {
122 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
123 return 2;
124 }
125
126
127 png_init_io(png_ptr, infile);
128 png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */
129
130 png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */
131
132
133 /* alternatively, could make separate calls to png_get_image_width(),
134 * etc., but want bit_depth and color_type for later [don't care about
135 * compression_type and filter_type => NULLs] */
136
137 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
138 NULL, NULL, NULL);
139 *pWidth = width;
140 *pHeight = height;
141
142
143 /* OK, that's all we need for now; return happy */
144
145 return 0;
146}
147
148
149
150
151/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
152 * scales values to 8-bit if necessary */
153
154int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
155{
156 png_color_16p pBackground;
157
158
159 /* setjmp() must be called in every function that calls a PNG-reading
160 * libpng function */
161
162 if (setjmp(png_jmpbuf(png_ptr))) {
163 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
164 return 2;
165 }
166
167
168 if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
169 return 1;
170
171 /* it is not obvious from the libpng documentation, but this function
172 * takes a pointer to a pointer, and it always returns valid red, green
173 * and blue values, regardless of color_type: */
174
175 png_get_bKGD(png_ptr, info_ptr, &pBackground);
176
177
178 /* however, it always returns the raw bKGD data, regardless of any
179 * bit-depth transformations, so check depth and adjust if necessary */
180
181 if (bit_depth == 16) {
182 *red = pBackground->red >> 8;
183 *green = pBackground->green >> 8;
184 *blue = pBackground->blue >> 8;
185 } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
186 if (bit_depth == 1)
187 *red = *green = *blue = pBackground->gray? 255 : 0;
188 else if (bit_depth == 2)
189 *red = *green = *blue = (255/3) * pBackground->gray;
190 else /* bit_depth == 4 */
191 *red = *green = *blue = (255/15) * pBackground->gray;
192 } else {
193 *red = (uch)pBackground->red;
194 *green = (uch)pBackground->green;
195 *blue = (uch)pBackground->blue;
196 }
197
198 return 0;
199}
200
201
202
203
204/* display_exponent == LUT_exponent * CRT_exponent */
205
206uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
207{
208 double gamma;
209 png_uint_32 i, rowbytes;
210 png_bytepp row_pointers = NULL;
211
212
213 /* setjmp() must be called in every function that calls a PNG-reading
214 * libpng function */
215
216 if (setjmp(png_jmpbuf(png_ptr))) {
217 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
218 return NULL;
219 }
220
221
222 /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
223 * transparency chunks to full alpha channel; strip 16-bit-per-sample
224 * images to 8 bits per sample; and convert grayscale to RGB[A] */
225
226 if (color_type == PNG_COLOR_TYPE_PALETTE)
227 png_set_expand(png_ptr);
228 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
229 png_set_expand(png_ptr);
230 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
231 png_set_expand(png_ptr);
232#ifdef PNG_READ_16_TO_8_SUPPORTED
233 if (bit_depth == 16)
234# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
235 png_set_scale_16(png_ptr);
236# else
237 png_set_strip_16(png_ptr);
238# endif
239#endif
240 if (color_type == PNG_COLOR_TYPE_GRAY ||
241 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
242 png_set_gray_to_rgb(png_ptr);
243
244
245 /* unlike the example in the libpng documentation, we have *no* idea where
246 * this file may have come from--so if it doesn't have a file gamma, don't
247 * do any correction ("do no harm") */
248
249 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
250 png_set_gamma(png_ptr, display_exponent, gamma);
251
252
253 /* all transformations have been registered; now update info_ptr data,
254 * get rowbytes and channels, and allocate image memory */
255
256 png_read_update_info(png_ptr, info_ptr);
257
258 *pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);
259 *pChannels = (int)png_get_channels(png_ptr, info_ptr);
260
261 if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
262 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
263 return NULL;
264 }
265 if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {
266 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
267 free(image_data);
268 image_data = NULL;
269 return NULL;
270 }
271
272 Trace((stderr, "readpng_get_image: channels = %d, rowbytes = %ld, height = %ld\n",
273 *pChannels, rowbytes, height));
274
275
276 /* set the individual row_pointers to point at the correct offsets */
277
278 for (i = 0; i < height; ++i)
279 row_pointers[i] = image_data + i*rowbytes;
280
281
282 /* now we can go ahead and just read the whole image */
283
284 png_read_image(png_ptr, row_pointers);
285
286
287 /* and we're done! (png_read_end() can be omitted if no processing of
288 * post-IDAT text/time/etc. is desired) */
289
290 free(row_pointers);
291 row_pointers = NULL;
292
293 png_read_end(png_ptr, NULL);
294
295 return image_data;
296}
297
298
299void readpng_cleanup(int free_image_data)
300{
301 if (free_image_data && image_data) {
302 free(image_data);
303 image_data = NULL;
304 }
305
306 if (png_ptr && info_ptr) {
307 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
308 png_ptr = NULL;
309 info_ptr = NULL;
310 }
311}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h
new file mode 100644
index 0000000..ec6b483
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h
@@ -0,0 +1,88 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program readpng.h
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#ifndef TRUE
57# define TRUE 1
58# define FALSE 0
59#endif
60
61#ifndef MAX
62# define MAX(a,b) ((a) > (b)? (a) : (b))
63# define MIN(a,b) ((a) < (b)? (a) : (b))
64#endif
65
66#ifdef DEBUG
67# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
68#else
69# define Trace(x) ;
70#endif
71
72typedef unsigned char uch;
73typedef unsigned short ush;
74typedef unsigned long ulg;
75
76
77/* prototypes for public functions in readpng.c */
78
79void readpng_version_info(void);
80
81int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight);
82
83int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue);
84
85uch *readpng_get_image(double display_exponent, int *pChannels,
86 ulg *pRowbytes);
87
88void readpng_cleanup(int free_image_data);
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c
new file mode 100644
index 0000000..3bbd2ec
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c
@@ -0,0 +1,511 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program readpng2.c
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56
57#include <stdlib.h> /* for exit() prototype */
58#include <setjmp.h>
59
60#include <zlib.h>
61#include "png.h" /* libpng header from the local directory */
62#include "readpng2.h" /* typedefs, common macros, public prototypes */
63
64
65/* local prototypes */
66
67static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);
68static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
69 png_uint_32 row_num, int pass);
70static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);
71static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);
72
73
74
75
76void readpng2_version_info(void)
77{
78 fprintf(stderr, " Compiled with libpng %s; using libpng %s\n",
79 PNG_LIBPNG_VER_STRING, png_libpng_ver);
80
81 fprintf(stderr, " and with zlib %s; using zlib %s.\n",
82 ZLIB_VERSION, zlib_version);
83}
84
85
86
87
88int readpng2_check_sig(uch *sig, int num)
89{
90 return !png_sig_cmp(sig, 0, num);
91}
92
93
94
95
96/* returns 0 for success, 2 for libpng problem, 4 for out of memory */
97
98int readpng2_init(mainprog_info *mainprog_ptr)
99{
100 png_structp png_ptr; /* note: temporary variables! */
101 png_infop info_ptr;
102
103
104 /* could also replace libpng warning-handler (final NULL), but no need: */
105
106 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
107 readpng2_error_handler, NULL);
108 if (!png_ptr)
109 return 4; /* out of memory */
110
111 info_ptr = png_create_info_struct(png_ptr);
112 if (!info_ptr) {
113 png_destroy_read_struct(&png_ptr, NULL, NULL);
114 return 4; /* out of memory */
115 }
116
117
118 /* we could create a second info struct here (end_info), but it's only
119 * useful if we want to keep pre- and post-IDAT chunk info separated
120 * (mainly for PNG-aware image editors and converters) */
121
122
123 /* setjmp() must be called in every function that calls a PNG-reading
124 * libpng function, unless an alternate error handler was installed--
125 * but compatible error handlers must either use longjmp() themselves
126 * (as in this program) or exit immediately, so here we are: */
127
128 if (setjmp(mainprog_ptr->jmpbuf)) {
129 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
130 return 2;
131 }
132
133
134#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
135 /* prepare the reader to ignore all recognized chunks whose data won't be
136 * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,
137 * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */
138 {
139 /* These byte strings were copied from png.h. If a future libpng
140 * version recognizes more chunks, add them to this list. If a
141 * future version of readpng2.c recognizes more chunks, delete them
142 * from this list. */
143 static /* const */ png_byte chunks_to_ignore[] = {
144 99, 72, 82, 77, '\0', /* cHRM */
145 104, 73, 83, 84, '\0', /* hIST */
146 105, 67, 67, 80, '\0', /* iCCP */
147 105, 84, 88, 116, '\0', /* iTXt */
148 111, 70, 70, 115, '\0', /* oFFs */
149 112, 67, 65, 76, '\0', /* pCAL */
150 112, 72, 89, 115, '\0', /* pHYs */
151 115, 66, 73, 84, '\0', /* sBIT */
152 115, 67, 65, 76, '\0', /* sCAL */
153 115, 80, 76, 84, '\0', /* sPLT */
154 115, 84, 69, 82, '\0', /* sTER */
155 116, 69, 88, 116, '\0', /* tEXt */
156 116, 73, 77, 69, '\0', /* tIME */
157 122, 84, 88, 116, '\0' /* zTXt */
158 };
159
160 png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */,
161 chunks_to_ignore, sizeof(chunks_to_ignore)/5);
162 }
163#endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */
164
165
166 /* instead of doing png_init_io() here, now we set up our callback
167 * functions for progressive decoding */
168
169 png_set_progressive_read_fn(png_ptr, mainprog_ptr,
170 readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);
171
172
173 /* make sure we save our pointers for use in readpng2_decode_data() */
174
175 mainprog_ptr->png_ptr = png_ptr;
176 mainprog_ptr->info_ptr = info_ptr;
177
178
179 /* and that's all there is to initialization */
180
181 return 0;
182}
183
184
185
186
187/* returns 0 for success, 2 for libpng (longjmp) problem */
188
189int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)
190{
191 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
192 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
193
194
195 /* setjmp() must be called in every function that calls a PNG-reading
196 * libpng function */
197
198 if (setjmp(mainprog_ptr->jmpbuf)) {
199 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
200 mainprog_ptr->png_ptr = NULL;
201 mainprog_ptr->info_ptr = NULL;
202 return 2;
203 }
204
205
206 /* hand off the next chunk of input data to libpng for decoding */
207
208 png_process_data(png_ptr, info_ptr, rawbuf, length);
209
210 return 0;
211}
212
213
214
215
216static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)
217{
218 mainprog_info *mainprog_ptr;
219 int color_type, bit_depth;
220 png_uint_32 width, height;
221#ifdef PNG_FLOATING_POINT_SUPPORTED
222 double gamma;
223#else
224 png_fixed_point gamma;
225#endif
226
227
228 /* setjmp() doesn't make sense here, because we'd either have to exit(),
229 * longjmp() ourselves, or return control to libpng, which doesn't want
230 * to see us again. By not doing anything here, libpng will instead jump
231 * to readpng2_decode_data(), which can return an error value to the main
232 * program. */
233
234
235 /* retrieve the pointer to our special-purpose struct, using the png_ptr
236 * that libpng passed back to us (i.e., not a global this time--there's
237 * no real difference for a single image, but for a multithreaded browser
238 * decoding several PNG images at the same time, one needs to avoid mixing
239 * up different images' structs) */
240
241 mainprog_ptr = png_get_progressive_ptr(png_ptr);
242
243 if (mainprog_ptr == NULL) { /* we be hosed */
244 fprintf(stderr,
245 "readpng2 error: main struct not recoverable in info_callback.\n");
246 fflush(stderr);
247 return;
248 /*
249 * Alternatively, we could call our error-handler just like libpng
250 * does, which would effectively terminate the program. Since this
251 * can only happen if png_ptr gets redirected somewhere odd or the
252 * main PNG struct gets wiped, we're probably toast anyway. (If
253 * png_ptr itself is NULL, we would not have been called.)
254 */
255 }
256
257
258 /* this is just like in the non-progressive case */
259
260 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
261 NULL, NULL, NULL);
262 mainprog_ptr->width = (ulg)width;
263 mainprog_ptr->height = (ulg)height;
264
265
266 /* since we know we've read all of the PNG file's "header" (i.e., up
267 * to IDAT), we can check for a background color here */
268
269 if (mainprog_ptr->need_bgcolor &&
270 png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))
271 {
272 png_color_16p pBackground;
273
274 /* it is not obvious from the libpng documentation, but this function
275 * takes a pointer to a pointer, and it always returns valid red,
276 * green and blue values, regardless of color_type: */
277 png_get_bKGD(png_ptr, info_ptr, &pBackground);
278
279 /* however, it always returns the raw bKGD data, regardless of any
280 * bit-depth transformations, so check depth and adjust if necessary */
281 if (bit_depth == 16) {
282 mainprog_ptr->bg_red = pBackground->red >> 8;
283 mainprog_ptr->bg_green = pBackground->green >> 8;
284 mainprog_ptr->bg_blue = pBackground->blue >> 8;
285 } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {
286 if (bit_depth == 1)
287 mainprog_ptr->bg_red = mainprog_ptr->bg_green =
288 mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;
289 else if (bit_depth == 2)
290 mainprog_ptr->bg_red = mainprog_ptr->bg_green =
291 mainprog_ptr->bg_blue = (255/3) * pBackground->gray;
292 else /* bit_depth == 4 */
293 mainprog_ptr->bg_red = mainprog_ptr->bg_green =
294 mainprog_ptr->bg_blue = (255/15) * pBackground->gray;
295 } else {
296 mainprog_ptr->bg_red = (uch)pBackground->red;
297 mainprog_ptr->bg_green = (uch)pBackground->green;
298 mainprog_ptr->bg_blue = (uch)pBackground->blue;
299 }
300 }
301
302
303 /* as before, let libpng expand palette images to RGB, low-bit-depth
304 * grayscale images to 8 bits, transparency chunks to full alpha channel;
305 * strip 16-bit-per-sample images to 8 bits per sample; and convert
306 * grayscale to RGB[A] */
307
308 if (color_type == PNG_COLOR_TYPE_PALETTE)
309 png_set_expand(png_ptr);
310 if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
311 png_set_expand(png_ptr);
312 if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
313 png_set_expand(png_ptr);
314#ifdef PNG_READ_16_TO_8_SUPPORTED
315 if (bit_depth == 16)
316# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED
317 png_set_scale_16(png_ptr);
318# else
319 png_set_strip_16(png_ptr);
320# endif
321#endif
322 if (color_type == PNG_COLOR_TYPE_GRAY ||
323 color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
324 png_set_gray_to_rgb(png_ptr);
325
326
327 /* Unlike the basic viewer, which was designed to operate on local files,
328 * this program is intended to simulate a web browser--even though we
329 * actually read from a local file, too. But because we are pretending
330 * that most of the images originate on the Internet, we follow the recom-
331 * mendation of the sRGB proposal and treat unlabelled images (no gAMA
332 * chunk) as existing in the sRGB color space. That is, we assume that
333 * such images have a file gamma of 0.45455, which corresponds to a PC-like
334 * display system. This change in assumptions will have no effect on a
335 * PC-like system, but on a Mac, SGI, NeXT or other system with a non-
336 * identity lookup table, it will darken unlabelled images, which effec-
337 * tively favors images from PC-like systems over those originating on
338 * the local platform. Note that mainprog_ptr->display_exponent is the
339 * "gamma" value for the entire display system, i.e., the product of
340 * LUT_exponent and CRT_exponent. */
341
342#ifdef PNG_FLOATING_POINT_SUPPORTED
343 if (png_get_gAMA(png_ptr, info_ptr, &gamma))
344 png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);
345 else
346 png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);
347#else
348 if (png_get_gAMA_fixed(png_ptr, info_ptr, &gamma))
349 png_set_gamma_fixed(png_ptr,
350 (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), gamma);
351 else
352 png_set_gamma_fixed(png_ptr,
353 (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), 45455);
354#endif
355
356 /* we'll let libpng expand interlaced images, too */
357
358 mainprog_ptr->passes = png_set_interlace_handling(png_ptr);
359
360
361 /* all transformations have been registered; now update info_ptr data and
362 * then get rowbytes and channels */
363
364 png_read_update_info(png_ptr, info_ptr);
365
366 mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr);
367 mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);
368
369
370 /* Call the main program to allocate memory for the image buffer and
371 * initialize windows and whatnot. (The old-style function-pointer
372 * invocation is used for compatibility with a few supposedly ANSI
373 * compilers that nevertheless barf on "fn_ptr()"-style syntax.) */
374
375 (*mainprog_ptr->mainprog_init)();
376
377
378 /* and that takes care of initialization */
379
380 return;
381}
382
383
384
385
386
387static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,
388 png_uint_32 row_num, int pass)
389{
390 mainprog_info *mainprog_ptr;
391
392
393 /* first check whether the row differs from the previous pass; if not,
394 * nothing to combine or display */
395
396 if (!new_row)
397 return;
398
399
400 /* retrieve the pointer to our special-purpose struct so we can access
401 * the old rows and image-display callback function */
402
403 mainprog_ptr = png_get_progressive_ptr(png_ptr);
404
405
406 /* save the pass number for optional use by the front end */
407
408 mainprog_ptr->pass = pass;
409
410
411 /* have libpng either combine the new row data with the existing row data
412 * from previous passes (if interlaced) or else just copy the new row
413 * into the main program's image buffer */
414
415 png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],
416 new_row);
417
418
419 /* finally, call the display routine in the main program with the number
420 * of the row we just updated */
421
422 (*mainprog_ptr->mainprog_display_row)(row_num);
423
424
425 /* and we're ready for more */
426
427 return;
428}
429
430
431
432
433
434static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)
435{
436 mainprog_info *mainprog_ptr;
437
438
439 /* retrieve the pointer to our special-purpose struct */
440
441 mainprog_ptr = png_get_progressive_ptr(png_ptr);
442
443
444 /* let the main program know that it should flush any buffered image
445 * data to the display now and set a "done" flag or whatever, but note
446 * that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do
447 * NOT call readpng2_cleanup() either here or in the finish_display()
448 * routine; wait until control returns to the main program via
449 * readpng2_decode_data() */
450
451 (*mainprog_ptr->mainprog_finish_display)();
452
453
454 /* all done */
455
456 return;
457}
458
459
460
461
462
463void readpng2_cleanup(mainprog_info *mainprog_ptr)
464{
465 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
466 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
467
468 if (png_ptr && info_ptr)
469 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
470
471 mainprog_ptr->png_ptr = NULL;
472 mainprog_ptr->info_ptr = NULL;
473}
474
475
476
477
478
479static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)
480{
481 mainprog_info *mainprog_ptr;
482
483 /* This function, aside from the extra step of retrieving the "error
484 * pointer" (below) and the fact that it exists within the application
485 * rather than within libpng, is essentially identical to libpng's
486 * default error handler. The second point is critical: since both
487 * setjmp() and longjmp() are called from the same code, they are
488 * guaranteed to have compatible notions of how big a jmp_buf is,
489 * regardless of whether _BSD_SOURCE or anything else has (or has not)
490 * been defined. */
491
492 fprintf(stderr, "readpng2 libpng error: %s\n", msg);
493 fflush(stderr);
494
495 mainprog_ptr = png_get_error_ptr(png_ptr);
496 if (mainprog_ptr == NULL) { /* we are completely hosed now */
497 fprintf(stderr,
498 "readpng2 severe error: jmpbuf not recoverable; terminating.\n");
499 fflush(stderr);
500 exit(99);
501 }
502
503 /* Now we have our data structure we can use the information in it
504 * to return control to our own higher level code (all the points
505 * where 'setjmp' is called in this file.) This will work with other
506 * error handling mechanisms as well - libpng always calls png_error
507 * when it can proceed no further, thus, so long as the error handler
508 * is intercepted, application code can do its own error recovery.
509 */
510 longjmp(mainprog_ptr->jmpbuf, 1);
511}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h
new file mode 100644
index 0000000..7a59263
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h
@@ -0,0 +1,116 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program readpng2.h
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#ifndef TRUE
57# define TRUE 1
58# define FALSE 0
59#endif
60
61#ifndef MAX
62# define MAX(a,b) ((a) > (b)? (a) : (b))
63# define MIN(a,b) ((a) < (b)? (a) : (b))
64#endif
65
66#ifdef DEBUG
67# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
68#else
69# define Trace(x) ;
70#endif
71
72enum rpng2_states {
73 kPreInit = 0,
74 kWindowInit,
75 kDone
76};
77
78typedef unsigned char uch;
79typedef unsigned short ush;
80typedef unsigned long ulg;
81
82typedef struct _mainprog_info {
83 double display_exponent;
84 ulg width;
85 ulg height;
86 void *png_ptr;
87 void *info_ptr;
88 void (*mainprog_init)(void);
89 void (*mainprog_display_row)(ulg row_num);
90 void (*mainprog_finish_display)(void);
91 uch *image_data;
92 uch **row_pointers;
93 jmp_buf jmpbuf;
94 int passes; /* not used */
95 int pass;
96 int rowbytes;
97 int channels;
98 int need_bgcolor;
99 int state;
100 uch bg_red;
101 uch bg_green;
102 uch bg_blue;
103} mainprog_info;
104
105
106/* prototypes for public functions in readpng2.c */
107
108void readpng2_version_info(void);
109
110int readpng2_check_sig(uch *sig, int num);
111
112int readpng2_init(mainprog_info *mainprog_ptr);
113
114int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length);
115
116void readpng2_cleanup(mainprog_info *mainprog_ptr);
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
new file mode 100644
index 0000000..1ba2092
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
@@ -0,0 +1,179 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program readppm.c
4
5 ---------------------------------------------------------------------------
6
7 This is a special-purpose replacement for readpng.c that allows binary
8 PPM files to be used in place of PNG images.
9
10 ---------------------------------------------------------------------------
11
12 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
13
14 This software is provided "as is," without warranty of any kind,
15 express or implied. In no event shall the author or contributors
16 be held liable for any damages arising in any way from the use of
17 this software.
18
19 The contents of this file are DUAL-LICENSED. You may modify and/or
20 redistribute this software according to the terms of one of the
21 following two licenses (at your option):
22
23
24 LICENSE 1 ("BSD-like with advertising clause"):
25
26 Permission is granted to anyone to use this software for any purpose,
27 including commercial applications, and to alter it and redistribute
28 it freely, subject to the following restrictions:
29
30 1. Redistributions of source code must retain the above copyright
31 notice, disclaimer, and this list of conditions.
32 2. Redistributions in binary form must reproduce the above copyright
33 notice, disclaimer, and this list of conditions in the documenta-
34 tion and/or other materials provided with the distribution.
35 3. All advertising materials mentioning features or use of this
36 software must display the following acknowledgment:
37
38 This product includes software developed by Greg Roelofs
39 and contributors for the book, "PNG: The Definitive Guide,"
40 published by O'Reilly and Associates.
41
42
43 LICENSE 2 (GNU GPL v2 or later):
44
45 This program is free software; you can redistribute it and/or modify
46 it under the terms of the GNU General Public License as published by
47 the Free Software Foundation; either version 2 of the License, or
48 (at your option) any later version.
49
50 This program is distributed in the hope that it will be useful,
51 but WITHOUT ANY WARRANTY; without even the implied warranty of
52 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 GNU General Public License for more details.
54
55 You should have received a copy of the GNU General Public License
56 along with this program; if not, write to the Free Software Foundation,
57 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
58
59 ---------------------------------------------------------------------------*/
60
61#include <stdio.h>
62#include <stdlib.h>
63
64#include "readpng.h" /* typedefs, common macros, public prototypes */
65
66
67ulg width, height;
68int bit_depth, color_type, channels;
69uch *image_data = NULL;
70FILE *saved_infile;
71
72
73void readpng_version_info()
74{
75 fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n");
76}
77
78
79/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
80
81int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
82{
83 static uch ppmline[256];
84 int maxval;
85
86
87 saved_infile = infile;
88
89 fgets(ppmline, 256, infile);
90 if (ppmline[0] != 'P' || ppmline[1] != '6') {
91 fprintf(stderr, "ERROR: not a PPM file\n");
92 return 1;
93 }
94 /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */
95 if (ppmline[1] == '6') {
96 color_type = 2;
97 channels = 3;
98 } else if (ppmline[1] == '8') {
99 color_type = 6;
100 channels = 4;
101 } else /* if (ppmline[1] == '5') */ {
102 color_type = 0;
103 channels = 1;
104 }
105
106 do {
107 fgets(ppmline, 256, infile);
108 } while (ppmline[0] == '#');
109 sscanf(ppmline, "%lu %lu", &width, &height);
110
111 do {
112 fgets(ppmline, 256, infile);
113 } while (ppmline[0] == '#');
114 sscanf(ppmline, "%d", &maxval);
115 if (maxval != 255) {
116 fprintf(stderr, "ERROR: maxval = %d\n", maxval);
117 return 2;
118 }
119 bit_depth = 8;
120
121 *pWidth = width;
122 *pHeight = height;
123
124 return 0;
125}
126
127
128
129
130/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
131 * scales values to 8-bit if necessary */
132
133int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
134{
135 return 1;
136}
137
138
139
140
141/* display_exponent == LUT_exponent * CRT_exponent */
142
143uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
144{
145 ulg rowbytes;
146
147
148 /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
149 * transparency chunks to full alpha channel; strip 16-bit-per-sample
150 * images to 8 bits per sample; and convert grayscale to RGB[A] */
151
152 /* GRR WARNING: grayscale needs to be expanded and channels reset! */
153
154 *pRowbytes = rowbytes = channels*width;
155 *pChannels = channels;
156
157 if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
158 return NULL;
159 }
160
161 Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
162
163
164 /* now we can go ahead and just read the whole image */
165
166 fread(image_data, 1L, rowbytes*height, saved_infile);
167
168
169 return image_data;
170}
171
172
173void readpng_cleanup(int free_image_data)
174{
175 if (free_image_data && image_data) {
176 free(image_data);
177 image_data = NULL;
178 }
179}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c
new file mode 100644
index 0000000..1c22282
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-win.c
@@ -0,0 +1,728 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program rpng-win.c
4
5 This program decodes and displays PNG images, with gamma correction and
6 optionally with a user-specified background color (in case the image has
7 transparency). It is very nearly the most basic PNG viewer possible.
8 This version is for 32-bit Windows; it may compile under 16-bit Windows
9 with a little tweaking (or maybe not).
10
11 to do:
12 - handle quoted command-line args (especially filenames with spaces)
13 - have minimum window width: oh well
14 - use %.1023s to simplify truncation of title-bar string?
15
16 ---------------------------------------------------------------------------
17
18 Changelog:
19 - 1.00: initial public release
20 - 1.01: modified to allow abbreviated options; fixed long/ulong mis-
21 match; switched to png_jmpbuf() macro
22 - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed
23 command-line parsing bug
24 - 1.10: enabled "message window"/console (thanks to David Geldreich)
25 - 2.00: dual-licensed (added GNU GPL)
26 - 2.01: fixed improper display of usage screen on PNG error(s)
27
28 ---------------------------------------------------------------------------
29
30 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
31
32 This software is provided "as is," without warranty of any kind,
33 express or implied. In no event shall the author or contributors
34 be held liable for any damages arising in any way from the use of
35 this software.
36
37 The contents of this file are DUAL-LICENSED. You may modify and/or
38 redistribute this software according to the terms of one of the
39 following two licenses (at your option):
40
41
42 LICENSE 1 ("BSD-like with advertising clause"):
43
44 Permission is granted to anyone to use this software for any purpose,
45 including commercial applications, and to alter it and redistribute
46 it freely, subject to the following restrictions:
47
48 1. Redistributions of source code must retain the above copyright
49 notice, disclaimer, and this list of conditions.
50 2. Redistributions in binary form must reproduce the above copyright
51 notice, disclaimer, and this list of conditions in the documenta-
52 tion and/or other materials provided with the distribution.
53 3. All advertising materials mentioning features or use of this
54 software must display the following acknowledgment:
55
56 This product includes software developed by Greg Roelofs
57 and contributors for the book, "PNG: The Definitive Guide,"
58 published by O'Reilly and Associates.
59
60
61 LICENSE 2 (GNU GPL v2 or later):
62
63 This program is free software; you can redistribute it and/or modify
64 it under the terms of the GNU General Public License as published by
65 the Free Software Foundation; either version 2 of the License, or
66 (at your option) any later version.
67
68 This program is distributed in the hope that it will be useful,
69 but WITHOUT ANY WARRANTY; without even the implied warranty of
70 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
71 GNU General Public License for more details.
72
73 You should have received a copy of the GNU General Public License
74 along with this program; if not, write to the Free Software Foundation,
75 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
76
77 ---------------------------------------------------------------------------*/
78
79#define PROGNAME "rpng-win"
80#define LONGNAME "Simple PNG Viewer for Windows"
81#define VERSION "2.01 of 16 March 2008"
82
83#include <stdio.h>
84#include <stdlib.h>
85#include <string.h>
86#include <time.h>
87#include <windows.h>
88#ifdef __CYGWIN__
89/* getch replacement. Turns out, we don't really need this,
90 * but leave it here if we ever enable any of the uses of
91 * _getch in the main code
92 */
93#include <unistd.h>
94#include <termio.h>
95#include <sys/ioctl.h>
96int repl_getch( void )
97{
98 char ch;
99 int fd = fileno(stdin);
100 struct termio old_tty, new_tty;
101
102 ioctl(fd, TCGETA, &old_tty);
103 new_tty = old_tty;
104 new_tty.c_lflag &= ~(ICANON | ECHO | ISIG);
105 ioctl(fd, TCSETA, &new_tty);
106 fread(&ch, 1, sizeof(ch), stdin);
107 ioctl(fd, TCSETA, &old_tty);
108
109 return ch;
110}
111#define _getch repl_getch
112#else
113#include <conio.h> /* only for _getch() */
114#endif
115
116/* #define DEBUG : this enables the Trace() macros */
117
118#include "readpng.h" /* typedefs, common macros, readpng prototypes */
119
120
121/* could just include png.h, but this macro is the only thing we need
122 * (name and typedefs changed to local versions); note that side effects
123 * only happen with alpha (which could easily be avoided with
124 * "ush acopy = (alpha);") */
125
126#define alpha_composite(composite, fg, alpha, bg) { \
127 ush temp = ((ush)(fg)*(ush)(alpha) + \
128 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
129 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
130}
131
132
133/* local prototypes */
134static int rpng_win_create_window(HINSTANCE hInst, int showmode);
135static int rpng_win_display_image(void);
136static void rpng_win_cleanup(void);
137LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM);
138
139
140static char titlebar[1024];
141static char *progname = PROGNAME;
142static char *appname = LONGNAME;
143static char *filename;
144static FILE *infile;
145
146static char *bgstr;
147static uch bg_red=0, bg_green=0, bg_blue=0;
148
149static double display_exponent;
150
151static ulg image_width, image_height, image_rowbytes;
152static int image_channels;
153static uch *image_data;
154
155/* Windows-specific variables */
156static ulg wimage_rowbytes;
157static uch *dib;
158static uch *wimage_data;
159static BITMAPINFOHEADER *bmih;
160
161static HWND global_hwnd;
162
163
164
165
166int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
167{
168 char *args[1024]; /* arbitrary limit, but should suffice */
169 char *p, *q, **argv = args;
170 int argc = 0;
171 int rc, alen, flen;
172 int error = 0;
173 int have_bg = FALSE;
174 double LUT_exponent; /* just the lookup table */
175 double CRT_exponent = 2.2; /* just the monitor */
176 double default_display_exponent; /* whole display system */
177 MSG msg;
178
179
180 filename = (char *)NULL;
181
182#ifndef __CYGWIN__
183 /* First reenable console output, which normally goes to the bit bucket
184 * for windowed apps. Closing the console window will terminate the
185 * app. Thanks to David.Geldreich@realviz.com for supplying the magical
186 * incantation. */
187
188 AllocConsole();
189 freopen("CONOUT$", "a", stderr);
190 freopen("CONOUT$", "a", stdout);
191#endif
192
193
194 /* Next set the default value for our display-system exponent, i.e.,
195 * the product of the CRT exponent and the exponent corresponding to
196 * the frame-buffer's lookup table (LUT), if any. This is not an
197 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
198 * ones), but it should cover 99% of the current possibilities. And
199 * yes, these ifdefs are completely wasted in a Windows program... */
200
201#if defined(NeXT)
202 LUT_exponent = 1.0 / 2.2;
203 /*
204 if (some_next_function_that_returns_gamma(&next_gamma))
205 LUT_exponent = 1.0 / next_gamma;
206 */
207#elif defined(sgi)
208 LUT_exponent = 1.0 / 1.7;
209 /* there doesn't seem to be any documented function to get the
210 * "gamma" value, so we do it the hard way */
211 infile = fopen("/etc/config/system.glGammaVal", "r");
212 if (infile) {
213 double sgi_gamma;
214
215 fgets(tmpline, 80, infile);
216 fclose(infile);
217 sgi_gamma = atof(tmpline);
218 if (sgi_gamma > 0.0)
219 LUT_exponent = 1.0 / sgi_gamma;
220 }
221#elif defined(Macintosh)
222 LUT_exponent = 1.8 / 2.61;
223 /*
224 if (some_mac_function_that_returns_gamma(&mac_gamma))
225 LUT_exponent = mac_gamma / 2.61;
226 */
227#else
228 LUT_exponent = 1.0; /* assume no LUT: most PCs */
229#endif
230
231 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
232 default_display_exponent = LUT_exponent * CRT_exponent;
233
234
235 /* If the user has set the SCREEN_GAMMA environment variable as suggested
236 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
237 * use the default value we just calculated. Either way, the user may
238 * override this via a command-line option. */
239
240 if ((p = getenv("SCREEN_GAMMA")) != NULL)
241 display_exponent = atof(p);
242 else
243 display_exponent = default_display_exponent;
244
245
246 /* Windows really hates command lines, so we have to set up our own argv.
247 * Note that we do NOT bother with quoted arguments here, so don't use
248 * filenames with spaces in 'em! */
249
250 argv[argc++] = PROGNAME;
251 p = cmd;
252 for (;;) {
253 if (*p == ' ')
254 while (*++p == ' ')
255 ;
256 /* now p points at the first non-space after some spaces */
257 if (*p == '\0')
258 break; /* nothing after the spaces: done */
259 argv[argc++] = q = p;
260 while (*q && *q != ' ')
261 ++q;
262 /* now q points at a space or the end of the string */
263 if (*q == '\0')
264 break; /* last argv already terminated; quit */
265 *q = '\0'; /* change space to terminator */
266 p = q + 1;
267 }
268 argv[argc] = NULL; /* terminate the argv array itself */
269
270
271 /* Now parse the command line for options and the PNG filename. */
272
273 while (*++argv && !error) {
274 if (!strncmp(*argv, "-gamma", 2)) {
275 if (!*++argv)
276 ++error;
277 else {
278 display_exponent = atof(*argv);
279 if (display_exponent <= 0.0)
280 ++error;
281 }
282 } else if (!strncmp(*argv, "-bgcolor", 2)) {
283 if (!*++argv)
284 ++error;
285 else {
286 bgstr = *argv;
287 if (strlen(bgstr) != 7 || bgstr[0] != '#')
288 ++error;
289 else
290 have_bg = TRUE;
291 }
292 } else {
293 if (**argv != '-') {
294 filename = *argv;
295 if (argv[1]) /* shouldn't be any more args after filename */
296 ++error;
297 } else
298 ++error; /* not expecting any other options */
299 }
300 }
301
302 if (!filename)
303 ++error;
304
305
306 /* print usage screen if any errors up to this point */
307
308 if (error) {
309#ifndef __CYGWIN__
310 int ch;
311#endif
312
313 fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
314 readpng_version_info();
315 fprintf(stderr, "\n"
316 "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n"
317 " exp \ttransfer-function exponent (``gamma'') of the display\n"
318 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
319 "\t\t to the product of the lookup-table exponent (varies)\n"
320 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
321 " bg \tdesired background color in 7-character hex RGB format\n"
322 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
323 "\t\t used with transparent images\n"
324 "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
325#ifndef __CYGWIN__
326 "Press Q or Esc to quit this usage screen.\n"
327#endif
328 "\n", PROGNAME, default_display_exponent);
329#ifndef __CYGWIN__
330 do
331 ch = _getch();
332 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
333#endif
334 exit(1);
335 }
336
337
338 if (!(infile = fopen(filename, "rb"))) {
339 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
340 ++error;
341 } else {
342 if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
343 switch (rc) {
344 case 1:
345 fprintf(stderr, PROGNAME
346 ": [%s] is not a PNG file: incorrect signature\n",
347 filename);
348 break;
349 case 2:
350 fprintf(stderr, PROGNAME
351 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
352 break;
353 case 4:
354 fprintf(stderr, PROGNAME ": insufficient memory\n");
355 break;
356 default:
357 fprintf(stderr, PROGNAME
358 ": unknown readpng_init() error\n");
359 break;
360 }
361 ++error;
362 }
363 if (error)
364 fclose(infile);
365 }
366
367
368 if (error) {
369#ifndef __CYGWIN__
370 int ch;
371#endif
372
373 fprintf(stderr, PROGNAME ": aborting.\n");
374#ifndef __CYGWIN__
375 do
376 ch = _getch();
377 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
378#endif
379 exit(2);
380 } else {
381 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
382#ifndef __CYGWIN__
383 fprintf(stderr,
384 "\n [console window: closing this window will terminate %s]\n\n",
385 PROGNAME);
386#endif
387 }
388
389
390 /* set the title-bar string, but make sure buffer doesn't overflow */
391
392 alen = strlen(appname);
393 flen = strlen(filename);
394 if (alen + flen + 3 > 1023)
395 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
396 else
397 sprintf(titlebar, "%s: %s", appname, filename);
398
399
400 /* if the user didn't specify a background color on the command line,
401 * check for one in the PNG file--if not, the initialized values of 0
402 * (black) will be used */
403
404 if (have_bg) {
405 unsigned r, g, b; /* this approach quiets compiler warnings */
406
407 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
408 bg_red = (uch)r;
409 bg_green = (uch)g;
410 bg_blue = (uch)b;
411 } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
412 readpng_cleanup(TRUE);
413 fprintf(stderr, PROGNAME
414 ": libpng error while checking for background color\n");
415 exit(2);
416 }
417
418
419 /* do the basic Windows initialization stuff, make the window and fill it
420 * with the background color */
421
422 if (rpng_win_create_window(hInst, showmode))
423 exit(2);
424
425
426 /* decode the image, all at once */
427
428 Trace((stderr, "calling readpng_get_image()\n"))
429 image_data = readpng_get_image(display_exponent, &image_channels,
430 &image_rowbytes);
431 Trace((stderr, "done with readpng_get_image()\n"))
432
433
434 /* done with PNG file, so clean up to minimize memory usage (but do NOT
435 * nuke image_data!) */
436
437 readpng_cleanup(FALSE);
438 fclose(infile);
439
440 if (!image_data) {
441 fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
442 exit(3);
443 }
444
445
446 /* display image (composite with background if requested) */
447
448 Trace((stderr, "calling rpng_win_display_image()\n"))
449 if (rpng_win_display_image()) {
450 free(image_data);
451 exit(4);
452 }
453 Trace((stderr, "done with rpng_win_display_image()\n"))
454
455
456 /* wait for the user to tell us when to quit */
457
458 printf(
459#ifndef __CYGWIN__
460 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"
461#else
462 "Done. Press mouse button 1 (within image window) to quit.\n"
463#endif
464 );
465 fflush(stdout);
466
467 while (GetMessage(&msg, NULL, 0, 0)) {
468 TranslateMessage(&msg);
469 DispatchMessage(&msg);
470 }
471
472
473 /* OK, we're done: clean up all image and Windows resources and go away */
474
475 rpng_win_cleanup();
476
477 return msg.wParam;
478}
479
480
481
482
483
484static int rpng_win_create_window(HINSTANCE hInst, int showmode)
485{
486 uch *dest;
487 int extra_width, extra_height;
488 ulg i, j;
489 WNDCLASSEX wndclass;
490
491
492/*---------------------------------------------------------------------------
493 Allocate memory for the display-specific version of the image (round up
494 to multiple of 4 for Windows DIB).
495 ---------------------------------------------------------------------------*/
496
497 wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2;
498
499 if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
500 wimage_rowbytes*image_height)))
501 {
502 return 4; /* fail */
503 }
504
505/*---------------------------------------------------------------------------
506 Initialize the DIB. Negative height means to use top-down BMP ordering
507 (must be uncompressed, but that's what we want). Bit count of 1, 4 or 8
508 implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values
509 directly => wimage_data begins immediately after BMP header.
510 ---------------------------------------------------------------------------*/
511
512 memset(dib, 0, sizeof(BITMAPINFOHEADER));
513 bmih = (BITMAPINFOHEADER *)dib;
514 bmih->biSize = sizeof(BITMAPINFOHEADER);
515 bmih->biWidth = image_width;
516 bmih->biHeight = -((long)image_height);
517 bmih->biPlanes = 1;
518 bmih->biBitCount = 24;
519 bmih->biCompression = 0;
520 wimage_data = dib + sizeof(BITMAPINFOHEADER);
521
522/*---------------------------------------------------------------------------
523 Fill in background color (black by default); data are in BGR order.
524 ---------------------------------------------------------------------------*/
525
526 for (j = 0; j < image_height; ++j) {
527 dest = wimage_data + j*wimage_rowbytes;
528 for (i = image_width; i > 0; --i) {
529 *dest++ = bg_blue;
530 *dest++ = bg_green;
531 *dest++ = bg_red;
532 }
533 }
534
535/*---------------------------------------------------------------------------
536 Set the window parameters.
537 ---------------------------------------------------------------------------*/
538
539 memset(&wndclass, 0, sizeof(wndclass));
540
541 wndclass.cbSize = sizeof(wndclass);
542 wndclass.style = CS_HREDRAW | CS_VREDRAW;
543 wndclass.lpfnWndProc = rpng_win_wndproc;
544 wndclass.hInstance = hInst;
545 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
546 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
547 wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
548 wndclass.lpszMenuName = NULL;
549 wndclass.lpszClassName = progname;
550 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
551
552 RegisterClassEx(&wndclass);
553
554/*---------------------------------------------------------------------------
555 Finally, create the window.
556 ---------------------------------------------------------------------------*/
557
558 extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
559 GetSystemMetrics(SM_CXDLGFRAME));
560 extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
561 GetSystemMetrics(SM_CYDLGFRAME)) +
562 GetSystemMetrics(SM_CYCAPTION);
563
564 global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
565 CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width,
566 image_height+extra_height, NULL, NULL, hInst, NULL);
567
568 ShowWindow(global_hwnd, showmode);
569 UpdateWindow(global_hwnd);
570
571 return 0;
572
573} /* end function rpng_win_create_window() */
574
575
576
577
578
579static int rpng_win_display_image()
580{
581 uch *src, *dest;
582 uch r, g, b, a;
583 ulg i, row, lastrow;
584 RECT rect;
585
586
587 Trace((stderr, "beginning display loop (image_channels == %d)\n",
588 image_channels))
589 Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n",
590 image_width, image_rowbytes, wimage_rowbytes))
591
592
593/*---------------------------------------------------------------------------
594 Blast image data to buffer. This whole routine takes place before the
595 message loop begins, so there's no real point in any pseudo-progressive
596 display...
597 ---------------------------------------------------------------------------*/
598
599 for (lastrow = row = 0; row < image_height; ++row) {
600 src = image_data + row*image_rowbytes;
601 dest = wimage_data + row*wimage_rowbytes;
602 if (image_channels == 3) {
603 for (i = image_width; i > 0; --i) {
604 r = *src++;
605 g = *src++;
606 b = *src++;
607 *dest++ = b;
608 *dest++ = g; /* note reverse order */
609 *dest++ = r;
610 }
611 } else /* if (image_channels == 4) */ {
612 for (i = image_width; i > 0; --i) {
613 r = *src++;
614 g = *src++;
615 b = *src++;
616 a = *src++;
617 if (a == 255) {
618 *dest++ = b;
619 *dest++ = g;
620 *dest++ = r;
621 } else if (a == 0) {
622 *dest++ = bg_blue;
623 *dest++ = bg_green;
624 *dest++ = bg_red;
625 } else {
626 /* this macro (copied from png.h) composites the
627 * foreground and background values and puts the
628 * result into the first argument; there are no
629 * side effects with the first argument */
630 alpha_composite(*dest++, b, a, bg_blue);
631 alpha_composite(*dest++, g, a, bg_green);
632 alpha_composite(*dest++, r, a, bg_red);
633 }
634 }
635 }
636 /* display after every 16 lines */
637 if (((row+1) & 0xf) == 0) {
638 rect.left = 0L;
639 rect.top = (LONG)lastrow;
640 rect.right = (LONG)image_width; /* possibly off by one? */
641 rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */
642 InvalidateRect(global_hwnd, &rect, FALSE);
643 UpdateWindow(global_hwnd); /* similar to XFlush() */
644 lastrow = row + 1;
645 }
646 }
647
648 Trace((stderr, "calling final image-flush routine\n"))
649 if (lastrow < image_height) {
650 rect.left = 0L;
651 rect.top = (LONG)lastrow;
652 rect.right = (LONG)image_width; /* possibly off by one? */
653 rect.bottom = (LONG)image_height; /* possibly off by one? */
654 InvalidateRect(global_hwnd, &rect, FALSE);
655 UpdateWindow(global_hwnd); /* similar to XFlush() */
656 }
657
658/*
659 last param determines whether or not background is wiped before paint
660 InvalidateRect(global_hwnd, NULL, TRUE);
661 UpdateWindow(global_hwnd);
662 */
663
664 return 0;
665}
666
667
668
669
670
671static void rpng_win_cleanup()
672{
673 if (image_data) {
674 free(image_data);
675 image_data = NULL;
676 }
677
678 if (dib) {
679 free(dib);
680 dib = NULL;
681 }
682}
683
684
685
686
687
688LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)
689{
690 HDC hdc;
691 PAINTSTRUCT ps;
692 int rc;
693
694 switch (iMsg) {
695 case WM_CREATE:
696 /* one-time processing here, if any */
697 return 0;
698
699 case WM_PAINT:
700 hdc = BeginPaint(hwnd, &ps);
701 /* dest */
702 rc = StretchDIBits(hdc, 0, 0, image_width, image_height,
703 /* source */
704 0, 0, image_width, image_height,
705 wimage_data, (BITMAPINFO *)bmih,
706 /* iUsage: no clue */
707 0, SRCCOPY);
708 EndPaint(hwnd, &ps);
709 return 0;
710
711 /* wait for the user to tell us when to quit */
712 case WM_CHAR:
713 switch (wP) { /* only need one, so ignore repeat count */
714 case 'q':
715 case 'Q':
716 case 0x1B: /* Esc key */
717 PostQuitMessage(0);
718 }
719 return 0;
720
721 case WM_LBUTTONDOWN: /* another way of quitting */
722 case WM_DESTROY:
723 PostQuitMessage(0);
724 return 0;
725 }
726
727 return DefWindowProc(hwnd, iMsg, wP, lP);
728}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c
new file mode 100644
index 0000000..fc8be88
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng-x.c
@@ -0,0 +1,904 @@
1/*---------------------------------------------------------------------------
2
3 rpng - simple PNG display program rpng-x.c
4
5 This program decodes and displays PNG images, with gamma correction and
6 optionally with a user-specified background color (in case the image has
7 transparency). It is very nearly the most basic PNG viewer possible.
8 This version is for the X Window System (tested by author under Unix and
9 by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking).
10
11 to do:
12 - 8-bit (colormapped) X support
13 - use %.1023s to simplify truncation of title-bar string?
14
15 ---------------------------------------------------------------------------
16
17 Changelog:
18 - 1.01: initial public release
19 - 1.02: modified to allow abbreviated options; fixed long/ulong mis-
20 match; switched to png_jmpbuf() macro
21 - 1.10: added support for non-default visuals; fixed X pixel-conversion
22 - 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed
23 command-line parsing bug
24 - 1.12: fixed some small X memory leaks (thanks to François Petitjean)
25 - 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche)
26 - 1.14: added support for X resources (thanks to Gerhard Niklasch)
27 - 2.00: dual-licensed (added GNU GPL)
28 - 2.01: fixed improper display of usage screen on PNG error(s)
29
30 ---------------------------------------------------------------------------
31
32 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
33
34 This software is provided "as is," without warranty of any kind,
35 express or implied. In no event shall the author or contributors
36 be held liable for any damages arising in any way from the use of
37 this software.
38
39 The contents of this file are DUAL-LICENSED. You may modify and/or
40 redistribute this software according to the terms of one of the
41 following two licenses (at your option):
42
43
44 LICENSE 1 ("BSD-like with advertising clause"):
45
46 Permission is granted to anyone to use this software for any purpose,
47 including commercial applications, and to alter it and redistribute
48 it freely, subject to the following restrictions:
49
50 1. Redistributions of source code must retain the above copyright
51 notice, disclaimer, and this list of conditions.
52 2. Redistributions in binary form must reproduce the above copyright
53 notice, disclaimer, and this list of conditions in the documenta-
54 tion and/or other materials provided with the distribution.
55 3. All advertising materials mentioning features or use of this
56 software must display the following acknowledgment:
57
58 This product includes software developed by Greg Roelofs
59 and contributors for the book, "PNG: The Definitive Guide,"
60 published by O'Reilly and Associates.
61
62
63 LICENSE 2 (GNU GPL v2 or later):
64
65 This program is free software; you can redistribute it and/or modify
66 it under the terms of the GNU General Public License as published by
67 the Free Software Foundation; either version 2 of the License, or
68 (at your option) any later version.
69
70 This program is distributed in the hope that it will be useful,
71 but WITHOUT ANY WARRANTY; without even the implied warranty of
72 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73 GNU General Public License for more details.
74
75 You should have received a copy of the GNU General Public License
76 along with this program; if not, write to the Free Software Foundation,
77 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
78
79 ---------------------------------------------------------------------------*/
80
81#define PROGNAME "rpng-x"
82#define LONGNAME "Simple PNG Viewer for X"
83#define VERSION "2.01 of 16 March 2008"
84#define RESNAME "rpng" /* our X resource application name */
85#define RESCLASS "Rpng" /* our X resource class name */
86
87#include <stdio.h>
88#include <stdlib.h>
89#include <string.h>
90#include <time.h>
91#include <X11/Xlib.h>
92#include <X11/Xutil.h>
93#include <X11/Xos.h>
94#include <X11/keysym.h>
95
96/* #define DEBUG : this enables the Trace() macros */
97
98#include "readpng.h" /* typedefs, common macros, readpng prototypes */
99
100
101/* could just include png.h, but this macro is the only thing we need
102 * (name and typedefs changed to local versions); note that side effects
103 * only happen with alpha (which could easily be avoided with
104 * "ush acopy = (alpha);") */
105
106#define alpha_composite(composite, fg, alpha, bg) { \
107 ush temp = ((ush)(fg)*(ush)(alpha) + \
108 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
109 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
110}
111
112
113/* local prototypes */
114static int rpng_x_create_window(void);
115static int rpng_x_display_image(void);
116static void rpng_x_cleanup(void);
117static int rpng_x_msb(ulg u32val);
118
119
120static char titlebar[1024], *window_name = titlebar;
121static char *appname = LONGNAME;
122static char *icon_name = PROGNAME;
123static char *res_name = RESNAME;
124static char *res_class = RESCLASS;
125static char *filename;
126static FILE *infile;
127
128static char *bgstr;
129static uch bg_red=0, bg_green=0, bg_blue=0;
130
131static double display_exponent;
132
133static ulg image_width, image_height, image_rowbytes;
134static int image_channels;
135static uch *image_data;
136
137/* X-specific variables */
138static char *displayname;
139static XImage *ximage;
140static Display *display;
141static int depth;
142static Visual *visual;
143static XVisualInfo *visual_list;
144static int RShift, GShift, BShift;
145static ulg RMask, GMask, BMask;
146static Window window;
147static GC gc;
148static Colormap colormap;
149
150static int have_nondefault_visual = FALSE;
151static int have_colormap = FALSE;
152static int have_window = FALSE;
153static int have_gc = FALSE;
154/*
155ulg numcolors=0, pixels[256];
156ush reds[256], greens[256], blues[256];
157 */
158
159
160
161
162int main(int argc, char **argv)
163{
164#ifdef sgi
165 char tmpline[80];
166#endif
167 char *p;
168 int rc, alen, flen;
169 int error = 0;
170 int have_bg = FALSE;
171 double LUT_exponent; /* just the lookup table */
172 double CRT_exponent = 2.2; /* just the monitor */
173 double default_display_exponent; /* whole display system */
174 XEvent e;
175 KeySym k;
176
177
178 displayname = (char *)NULL;
179 filename = (char *)NULL;
180
181
182 /* First set the default value for our display-system exponent, i.e.,
183 * the product of the CRT exponent and the exponent corresponding to
184 * the frame-buffer's lookup table (LUT), if any. This is not an
185 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
186 * ones), but it should cover 99% of the current possibilities. */
187
188#if defined(NeXT)
189 LUT_exponent = 1.0 / 2.2;
190 /*
191 if (some_next_function_that_returns_gamma(&next_gamma))
192 LUT_exponent = 1.0 / next_gamma;
193 */
194#elif defined(sgi)
195 LUT_exponent = 1.0 / 1.7;
196 /* there doesn't seem to be any documented function to get the
197 * "gamma" value, so we do it the hard way */
198 infile = fopen("/etc/config/system.glGammaVal", "r");
199 if (infile) {
200 double sgi_gamma;
201
202 fgets(tmpline, 80, infile);
203 fclose(infile);
204 sgi_gamma = atof(tmpline);
205 if (sgi_gamma > 0.0)
206 LUT_exponent = 1.0 / sgi_gamma;
207 }
208#elif defined(Macintosh)
209 LUT_exponent = 1.8 / 2.61;
210 /*
211 if (some_mac_function_that_returns_gamma(&mac_gamma))
212 LUT_exponent = mac_gamma / 2.61;
213 */
214#else
215 LUT_exponent = 1.0; /* assume no LUT: most PCs */
216#endif
217
218 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
219 default_display_exponent = LUT_exponent * CRT_exponent;
220
221
222 /* If the user has set the SCREEN_GAMMA environment variable as suggested
223 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
224 * use the default value we just calculated. Either way, the user may
225 * override this via a command-line option. */
226
227 if ((p = getenv("SCREEN_GAMMA")) != NULL)
228 display_exponent = atof(p);
229 else
230 display_exponent = default_display_exponent;
231
232
233 /* Now parse the command line for options and the PNG filename. */
234
235 while (*++argv && !error) {
236 if (!strncmp(*argv, "-display", 2)) {
237 if (!*++argv)
238 ++error;
239 else
240 displayname = *argv;
241 } else if (!strncmp(*argv, "-gamma", 2)) {
242 if (!*++argv)
243 ++error;
244 else {
245 display_exponent = atof(*argv);
246 if (display_exponent <= 0.0)
247 ++error;
248 }
249 } else if (!strncmp(*argv, "-bgcolor", 2)) {
250 if (!*++argv)
251 ++error;
252 else {
253 bgstr = *argv;
254 if (strlen(bgstr) != 7 || bgstr[0] != '#')
255 ++error;
256 else
257 have_bg = TRUE;
258 }
259 } else {
260 if (**argv != '-') {
261 filename = *argv;
262 if (argv[1]) /* shouldn't be any more args after filename */
263 ++error;
264 } else
265 ++error; /* not expecting any other options */
266 }
267 }
268
269 if (!filename)
270 ++error;
271
272
273 /* print usage screen if any errors up to this point */
274
275 if (error) {
276 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
277 readpng_version_info();
278 fprintf(stderr, "\n"
279 "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\n"
280 " xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
281 " exp \ttransfer-function exponent (``gamma'') of the display\n"
282 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
283 "\t\t to the product of the lookup-table exponent (varies)\n"
284 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
285 " bg \tdesired background color in 7-character hex RGB format\n"
286 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
287 "\t\t used with transparent images\n"
288 "\nPress Q, Esc or mouse button 1 (within image window, after image\n"
289 "is displayed) to quit.\n"
290 "\n", PROGNAME, default_display_exponent);
291 exit(1);
292 }
293
294
295 if (!(infile = fopen(filename, "rb"))) {
296 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
297 ++error;
298 } else {
299 if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {
300 switch (rc) {
301 case 1:
302 fprintf(stderr, PROGNAME
303 ": [%s] is not a PNG file: incorrect signature\n",
304 filename);
305 break;
306 case 2:
307 fprintf(stderr, PROGNAME
308 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
309 break;
310 case 4:
311 fprintf(stderr, PROGNAME ": insufficient memory\n");
312 break;
313 default:
314 fprintf(stderr, PROGNAME
315 ": unknown readpng_init() error\n");
316 break;
317 }
318 ++error;
319 } else {
320 display = XOpenDisplay(displayname);
321 if (!display) {
322 readpng_cleanup(TRUE);
323 fprintf(stderr, PROGNAME ": can't open X display [%s]\n",
324 displayname? displayname : "default");
325 ++error;
326 }
327 }
328 if (error)
329 fclose(infile);
330 }
331
332
333 if (error) {
334 fprintf(stderr, PROGNAME ": aborting.\n");
335 exit(2);
336 }
337
338
339 /* set the title-bar string, but make sure buffer doesn't overflow */
340
341 alen = strlen(appname);
342 flen = strlen(filename);
343 if (alen + flen + 3 > 1023)
344 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
345 else
346 sprintf(titlebar, "%s: %s", appname, filename);
347
348
349 /* if the user didn't specify a background color on the command line,
350 * check for one in the PNG file--if not, the initialized values of 0
351 * (black) will be used */
352
353 if (have_bg) {
354 unsigned r, g, b; /* this approach quiets compiler warnings */
355
356 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
357 bg_red = (uch)r;
358 bg_green = (uch)g;
359 bg_blue = (uch)b;
360 } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {
361 readpng_cleanup(TRUE);
362 fprintf(stderr, PROGNAME
363 ": libpng error while checking for background color\n");
364 exit(2);
365 }
366
367
368 /* do the basic X initialization stuff, make the window and fill it
369 * with the background color */
370
371 if (rpng_x_create_window())
372 exit(2);
373
374
375 /* decode the image, all at once */
376
377 Trace((stderr, "calling readpng_get_image()\n"))
378 image_data = readpng_get_image(display_exponent, &image_channels,
379 &image_rowbytes);
380 Trace((stderr, "done with readpng_get_image()\n"))
381
382
383 /* done with PNG file, so clean up to minimize memory usage (but do NOT
384 * nuke image_data!) */
385
386 readpng_cleanup(FALSE);
387 fclose(infile);
388
389 if (!image_data) {
390 fprintf(stderr, PROGNAME ": unable to decode PNG image\n");
391 exit(3);
392 }
393
394
395 /* display image (composite with background if requested) */
396
397 Trace((stderr, "calling rpng_x_display_image()\n"))
398 if (rpng_x_display_image()) {
399 free(image_data);
400 exit(4);
401 }
402 Trace((stderr, "done with rpng_x_display_image()\n"))
403
404
405 /* wait for the user to tell us when to quit */
406
407 printf(
408 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
409 fflush(stdout);
410
411 do
412 XNextEvent(display, &e);
413 while (!(e.type == ButtonPress && e.xbutton.button == Button1) &&
414 !(e.type == KeyPress && /* v--- or 1 for shifted keys */
415 ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) ));
416
417
418 /* OK, we're done: clean up all image and X resources and go away */
419
420 rpng_x_cleanup();
421
422 return 0;
423}
424
425
426
427
428
429static int rpng_x_create_window(void)
430{
431 uch *xdata;
432 int need_colormap = FALSE;
433 int screen, pad;
434 ulg bg_pixel = 0L;
435 ulg attrmask;
436 Window root;
437 XEvent e;
438 XGCValues gcvalues;
439 XSetWindowAttributes attr;
440 XTextProperty windowName, *pWindowName = &windowName;
441 XTextProperty iconName, *pIconName = &iconName;
442 XVisualInfo visual_info;
443 XSizeHints *size_hints;
444 XWMHints *wm_hints;
445 XClassHint *class_hints;
446
447
448 screen = DefaultScreen(display);
449 depth = DisplayPlanes(display, screen);
450 root = RootWindow(display, screen);
451
452#ifdef DEBUG
453 XSynchronize(display, True);
454#endif
455
456#if 0
457/* GRR: add 8-bit support */
458 if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) {
459 fprintf(stderr,
460 "screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n",
461 depth);
462 return 2;
463 }
464
465 XMatchVisualInfo(display, screen, depth,
466 (depth == 8)? PseudoColor : TrueColor, &visual_info);
467 visual = visual_info.visual;
468#else
469 if (depth != 16 && depth != 24 && depth != 32) {
470 int visuals_matched = 0;
471
472 Trace((stderr, "default depth is %d: checking other visuals\n",
473 depth))
474
475 /* 24-bit first */
476 visual_info.screen = screen;
477 visual_info.depth = 24;
478 visual_list = XGetVisualInfo(display,
479 VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);
480 if (visuals_matched == 0) {
481/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */
482 fprintf(stderr, "default screen depth %d not supported, and no"
483 " 24-bit visuals found\n", depth);
484 return 2;
485 }
486 Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n",
487 visuals_matched))
488 visual = visual_list[0].visual;
489 depth = visual_list[0].depth;
490/*
491 colormap_size = visual_list[0].colormap_size;
492 visual_class = visual->class;
493 visualID = XVisualIDFromVisual(visual);
494 */
495 have_nondefault_visual = TRUE;
496 need_colormap = TRUE;
497 } else {
498 XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);
499 visual = visual_info.visual;
500 }
501#endif
502
503 RMask = visual->red_mask;
504 GMask = visual->green_mask;
505 BMask = visual->blue_mask;
506
507/* GRR: add/check 8-bit support */
508 if (depth == 8 || need_colormap) {
509 colormap = XCreateColormap(display, root, visual, AllocNone);
510 if (!colormap) {
511 fprintf(stderr, "XCreateColormap() failed\n");
512 return 2;
513 }
514 have_colormap = TRUE;
515 }
516 if (depth == 15 || depth == 16) {
517 RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */
518 GShift = 15 - rpng_x_msb(GMask);
519 BShift = 15 - rpng_x_msb(BMask);
520 } else if (depth > 16) {
521#define NO_24BIT_MASKS
522#ifdef NO_24BIT_MASKS
523 RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */
524 GShift = rpng_x_msb(GMask) - 7;
525 BShift = rpng_x_msb(BMask) - 7;
526#else
527 RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */
528 GShift = 7 - rpng_x_msb(GMask);
529 BShift = 7 - rpng_x_msb(BMask);
530#endif
531 }
532 if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
533 fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n");
534 return 2;
535 }
536
537/*---------------------------------------------------------------------------
538 Finally, create the window.
539 ---------------------------------------------------------------------------*/
540
541 attr.backing_store = Always;
542 attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
543 attrmask = CWBackingStore | CWEventMask;
544 if (have_nondefault_visual) {
545 attr.colormap = colormap;
546 attr.background_pixel = 0;
547 attr.border_pixel = 1;
548 attrmask |= CWColormap | CWBackPixel | CWBorderPixel;
549 }
550
551 window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0,
552 depth, InputOutput, visual, attrmask, &attr);
553
554 if (window == None) {
555 fprintf(stderr, "XCreateWindow() failed\n");
556 return 2;
557 } else
558 have_window = TRUE;
559
560 if (depth == 8)
561 XSetWindowColormap(display, window, colormap);
562
563 if (!XStringListToTextProperty(&window_name, 1, pWindowName))
564 pWindowName = NULL;
565 if (!XStringListToTextProperty(&icon_name, 1, pIconName))
566 pIconName = NULL;
567
568 /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */
569
570 if ((size_hints = XAllocSizeHints()) != NULL) {
571 /* window will not be resizable */
572 size_hints->flags = PMinSize | PMaxSize;
573 size_hints->min_width = size_hints->max_width = (int)image_width;
574 size_hints->min_height = size_hints->max_height = (int)image_height;
575 }
576
577 if ((wm_hints = XAllocWMHints()) != NULL) {
578 wm_hints->initial_state = NormalState;
579 wm_hints->input = True;
580 /* wm_hints->icon_pixmap = icon_pixmap; */
581 wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ;
582 }
583
584 if ((class_hints = XAllocClassHint()) != NULL) {
585 class_hints->res_name = res_name;
586 class_hints->res_class = res_class;
587 }
588
589 XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
590 size_hints, wm_hints, class_hints);
591
592 /* various properties and hints no longer needed; free memory */
593 if (pWindowName)
594 XFree(pWindowName->value);
595 if (pIconName)
596 XFree(pIconName->value);
597 if (size_hints)
598 XFree(size_hints);
599 if (wm_hints)
600 XFree(wm_hints);
601 if (class_hints)
602 XFree(class_hints);
603
604 XMapWindow(display, window);
605
606 gc = XCreateGC(display, window, 0, &gcvalues);
607 have_gc = TRUE;
608
609/*---------------------------------------------------------------------------
610 Fill window with the specified background color.
611 ---------------------------------------------------------------------------*/
612
613 if (depth == 24 || depth == 32) {
614 bg_pixel = ((ulg)bg_red << RShift) |
615 ((ulg)bg_green << GShift) |
616 ((ulg)bg_blue << BShift);
617 } else if (depth == 16) {
618 bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) |
619 ((((ulg)bg_green << 8) >> GShift) & GMask) |
620 ((((ulg)bg_blue << 8) >> BShift) & BMask);
621 } else /* depth == 8 */ {
622
623 /* GRR: add 8-bit support */
624
625 }
626
627 XSetForeground(display, gc, bg_pixel);
628 XFillRectangle(display, window, gc, 0, 0, image_width, image_height);
629
630/*---------------------------------------------------------------------------
631 Wait for first Expose event to do any drawing, then flush.
632 ---------------------------------------------------------------------------*/
633
634 do
635 XNextEvent(display, &e);
636 while (e.type != Expose || e.xexpose.count);
637
638 XFlush(display);
639
640/*---------------------------------------------------------------------------
641 Allocate memory for the X- and display-specific version of the image.
642 ---------------------------------------------------------------------------*/
643
644 if (depth == 24 || depth == 32) {
645 xdata = (uch *)malloc(4*image_width*image_height);
646 pad = 32;
647 } else if (depth == 16) {
648 xdata = (uch *)malloc(2*image_width*image_height);
649 pad = 16;
650 } else /* depth == 8 */ {
651 xdata = (uch *)malloc(image_width*image_height);
652 pad = 8;
653 }
654
655 if (!xdata) {
656 fprintf(stderr, PROGNAME ": unable to allocate image memory\n");
657 return 4;
658 }
659
660 ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
661 (char *)xdata, image_width, image_height, pad, 0);
662
663 if (!ximage) {
664 fprintf(stderr, PROGNAME ": XCreateImage() failed\n");
665 free(xdata);
666 return 3;
667 }
668
669 /* to avoid testing the byte order every pixel (or doubling the size of
670 * the drawing routine with a giant if-test), we arbitrarily set the byte
671 * order to MSBFirst and let Xlib worry about inverting things on little-
672 * endian machines (like Linux/x86, old VAXen, etc.)--this is not the most
673 * efficient approach (the giant if-test would be better), but in the
674 * interest of clarity, we take the easy way out... */
675
676 ximage->byte_order = MSBFirst;
677
678 return 0;
679
680} /* end function rpng_x_create_window() */
681
682
683
684
685
686static int rpng_x_display_image(void)
687{
688 uch *src;
689 char *dest;
690 uch r, g, b, a;
691 ulg i, row, lastrow = 0;
692 ulg pixel;
693 int ximage_rowbytes = ximage->bytes_per_line;
694/* int bpp = ximage->bits_per_pixel; */
695
696
697 Trace((stderr, "beginning display loop (image_channels == %d)\n",
698 image_channels))
699 Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n",
700 image_width, image_rowbytes, ximage_rowbytes))
701 Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel))
702 Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst?
703 "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown")))
704
705 if (depth == 24 || depth == 32) {
706 ulg red, green, blue;
707
708 for (lastrow = row = 0; row < image_height; ++row) {
709 src = image_data + row*image_rowbytes;
710 dest = ximage->data + row*ximage_rowbytes;
711 if (image_channels == 3) {
712 for (i = image_width; i > 0; --i) {
713 red = *src++;
714 green = *src++;
715 blue = *src++;
716#ifdef NO_24BIT_MASKS
717 pixel = (red << RShift) |
718 (green << GShift) |
719 (blue << BShift);
720 /* recall that we set ximage->byte_order = MSBFirst above */
721 /* GRR BUG: this assumes bpp == 32, but may be 24: */
722 *dest++ = (char)((pixel >> 24) & 0xff);
723 *dest++ = (char)((pixel >> 16) & 0xff);
724 *dest++ = (char)((pixel >> 8) & 0xff);
725 *dest++ = (char)( pixel & 0xff);
726#else
727 red = (RShift < 0)? red << (-RShift) : red >> RShift;
728 green = (GShift < 0)? green << (-GShift) : green >> GShift;
729 blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
730 pixel = (red & RMask) | (green & GMask) | (blue & BMask);
731 /* recall that we set ximage->byte_order = MSBFirst above */
732 *dest++ = (char)((pixel >> 24) & 0xff);
733 *dest++ = (char)((pixel >> 16) & 0xff);
734 *dest++ = (char)((pixel >> 8) & 0xff);
735 *dest++ = (char)( pixel & 0xff);
736#endif
737 }
738 } else /* if (image_channels == 4) */ {
739 for (i = image_width; i > 0; --i) {
740 r = *src++;
741 g = *src++;
742 b = *src++;
743 a = *src++;
744 if (a == 255) {
745 red = r;
746 green = g;
747 blue = b;
748 } else if (a == 0) {
749 red = bg_red;
750 green = bg_green;
751 blue = bg_blue;
752 } else {
753 /* this macro (from png.h) composites the foreground
754 * and background values and puts the result into the
755 * first argument */
756 alpha_composite(red, r, a, bg_red);
757 alpha_composite(green, g, a, bg_green);
758 alpha_composite(blue, b, a, bg_blue);
759 }
760 pixel = (red << RShift) |
761 (green << GShift) |
762 (blue << BShift);
763 /* recall that we set ximage->byte_order = MSBFirst above */
764 *dest++ = (char)((pixel >> 24) & 0xff);
765 *dest++ = (char)((pixel >> 16) & 0xff);
766 *dest++ = (char)((pixel >> 8) & 0xff);
767 *dest++ = (char)( pixel & 0xff);
768 }
769 }
770 /* display after every 16 lines */
771 if (((row+1) & 0xf) == 0) {
772 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
773 (int)lastrow, image_width, 16);
774 XFlush(display);
775 lastrow = row + 1;
776 }
777 }
778
779 } else if (depth == 16) {
780 ush red, green, blue;
781
782 for (lastrow = row = 0; row < image_height; ++row) {
783 src = image_data + row*image_rowbytes;
784 dest = ximage->data + row*ximage_rowbytes;
785 if (image_channels == 3) {
786 for (i = image_width; i > 0; --i) {
787 red = ((ush)(*src) << 8);
788 ++src;
789 green = ((ush)(*src) << 8);
790 ++src;
791 blue = ((ush)(*src) << 8);
792 ++src;
793 pixel = ((red >> RShift) & RMask) |
794 ((green >> GShift) & GMask) |
795 ((blue >> BShift) & BMask);
796 /* recall that we set ximage->byte_order = MSBFirst above */
797 *dest++ = (char)((pixel >> 8) & 0xff);
798 *dest++ = (char)( pixel & 0xff);
799 }
800 } else /* if (image_channels == 4) */ {
801 for (i = image_width; i > 0; --i) {
802 r = *src++;
803 g = *src++;
804 b = *src++;
805 a = *src++;
806 if (a == 255) {
807 red = ((ush)r << 8);
808 green = ((ush)g << 8);
809 blue = ((ush)b << 8);
810 } else if (a == 0) {
811 red = ((ush)bg_red << 8);
812 green = ((ush)bg_green << 8);
813 blue = ((ush)bg_blue << 8);
814 } else {
815 /* this macro (from png.h) composites the foreground
816 * and background values and puts the result back into
817 * the first argument (== fg byte here: safe) */
818 alpha_composite(r, r, a, bg_red);
819 alpha_composite(g, g, a, bg_green);
820 alpha_composite(b, b, a, bg_blue);
821 red = ((ush)r << 8);
822 green = ((ush)g << 8);
823 blue = ((ush)b << 8);
824 }
825 pixel = ((red >> RShift) & RMask) |
826 ((green >> GShift) & GMask) |
827 ((blue >> BShift) & BMask);
828 /* recall that we set ximage->byte_order = MSBFirst above */
829 *dest++ = (char)((pixel >> 8) & 0xff);
830 *dest++ = (char)( pixel & 0xff);
831 }
832 }
833 /* display after every 16 lines */
834 if (((row+1) & 0xf) == 0) {
835 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
836 (int)lastrow, image_width, 16);
837 XFlush(display);
838 lastrow = row + 1;
839 }
840 }
841
842 } else /* depth == 8 */ {
843
844 /* GRR: add 8-bit support */
845
846 }
847
848 Trace((stderr, "calling final XPutImage()\n"))
849 if (lastrow < image_height) {
850 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
851 (int)lastrow, image_width, image_height-lastrow);
852 XFlush(display);
853 }
854
855 return 0;
856}
857
858
859
860
861static void rpng_x_cleanup(void)
862{
863 if (image_data) {
864 free(image_data);
865 image_data = NULL;
866 }
867
868 if (ximage) {
869 if (ximage->data) {
870 free(ximage->data); /* we allocated it, so we free it */
871 ximage->data = (char *)NULL; /* instead of XDestroyImage() */
872 }
873 XDestroyImage(ximage);
874 ximage = NULL;
875 }
876
877 if (have_gc)
878 XFreeGC(display, gc);
879
880 if (have_window)
881 XDestroyWindow(display, window);
882
883 if (have_colormap)
884 XFreeColormap(display, colormap);
885
886 if (have_nondefault_visual)
887 XFree(visual_list);
888}
889
890
891
892
893
894static int rpng_x_msb(ulg u32val)
895{
896 int i;
897
898 for (i = 31; i >= 0; --i) {
899 if (u32val & 0x80000000L)
900 break;
901 u32val <<= 1;
902 }
903 return i;
904}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c
new file mode 100644
index 0000000..2303b58
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-win.c
@@ -0,0 +1,1253 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program rpng2-win.c
4
5 This program decodes and displays PNG files progressively, as if it were
6 a web browser (though the front end is only set up to read from files).
7 It supports gamma correction, user-specified background colors, and user-
8 specified background patterns (for transparent images). This version is
9 for 32-bit Windows; it may compile under 16-bit Windows with a little
10 tweaking (or maybe not). Thanks to Adam Costello and Pieter S. van der
11 Meulen for the "diamond" and "radial waves" patterns, respectively.
12
13 to do (someday, maybe):
14 - handle quoted command-line args (especially filenames with spaces)
15 - finish resizable checkerboard-gradient (sizes 4-128?)
16 - use %.1023s to simplify truncation of title-bar string?
17 - have minimum window width: oh well
18
19 ---------------------------------------------------------------------------
20
21 Changelog:
22 - 1.01: initial public release
23 - 1.02: fixed cut-and-paste error in usage screen (oops...)
24 - 1.03: modified to allow abbreviated options
25 - 1.04: removed bogus extra argument from usage fprintf() [Glenn R-P?];
26 fixed command-line parsing bug
27 - 1.10: enabled "message window"/console (thanks to David Geldreich)
28 - 1.20: added runtime MMX-enabling/disabling and new -mmx* options
29 - 1.21: made minor tweak to usage screen to fit within 25-line console
30 - 1.22: added AMD64/EM64T support (__x86_64__)
31 - 2.00: dual-licensed (added GNU GPL)
32 - 2.01: fixed 64-bit typo in readpng2.c
33 - 2.02: fixed improper display of usage screen on PNG error(s); fixed
34 unexpected-EOF and file-read-error cases
35 - 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options
36
37 ---------------------------------------------------------------------------
38
39 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
40
41 This software is provided "as is," without warranty of any kind,
42 express or implied. In no event shall the author or contributors
43 be held liable for any damages arising in any way from the use of
44 this software.
45
46 The contents of this file are DUAL-LICENSED. You may modify and/or
47 redistribute this software according to the terms of one of the
48 following two licenses (at your option):
49
50
51 LICENSE 1 ("BSD-like with advertising clause"):
52
53 Permission is granted to anyone to use this software for any purpose,
54 including commercial applications, and to alter it and redistribute
55 it freely, subject to the following restrictions:
56
57 1. Redistributions of source code must retain the above copyright
58 notice, disclaimer, and this list of conditions.
59 2. Redistributions in binary form must reproduce the above copyright
60 notice, disclaimer, and this list of conditions in the documenta-
61 tion and/or other materials provided with the distribution.
62 3. All advertising materials mentioning features or use of this
63 software must display the following acknowledgment:
64
65 This product includes software developed by Greg Roelofs
66 and contributors for the book, "PNG: The Definitive Guide,"
67 published by O'Reilly and Associates.
68
69
70 LICENSE 2 (GNU GPL v2 or later):
71
72 This program is free software; you can redistribute it and/or modify
73 it under the terms of the GNU General Public License as published by
74 the Free Software Foundation; either version 2 of the License, or
75 (at your option) any later version.
76
77 This program is distributed in the hope that it will be useful,
78 but WITHOUT ANY WARRANTY; without even the implied warranty of
79 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80 GNU General Public License for more details.
81
82 You should have received a copy of the GNU General Public License
83 along with this program; if not, write to the Free Software Foundation,
84 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
85
86 ---------------------------------------------------------------------------*/
87
88#define PROGNAME "rpng2-win"
89#define LONGNAME "Progressive PNG Viewer for Windows"
90#define VERSION "2.02 of 16 March 2008"
91
92#include <stdio.h>
93#include <stdlib.h>
94#include <string.h>
95#include <setjmp.h> /* for jmpbuf declaration in readpng2.h */
96#include <time.h>
97#include <math.h> /* only for PvdM background code */
98#include <windows.h>
99#ifdef __CYGWIN__
100/* getch replacement. Turns out, we don't really need this,
101 * but leave it here if we ever enable any of the uses of
102 * _getch in the main code
103 */
104#include <unistd.h>
105#include <termio.h>
106#include <sys/ioctl.h>
107int repl_getch( void )
108{
109 char ch;
110 int fd = fileno(stdin);
111 struct termio old_tty, new_tty;
112
113 ioctl(fd, TCGETA, &old_tty);
114 new_tty = old_tty;
115 new_tty.c_lflag &= ~(ICANON | ECHO | ISIG);
116 ioctl(fd, TCSETA, &new_tty);
117 fread(&ch, 1, sizeof(ch), stdin);
118 ioctl(fd, TCSETA, &old_tty);
119
120 return ch;
121}
122#define _getch repl_getch
123#else
124#include <conio.h> /* only for _getch() */
125#endif
126
127/* all for PvdM background code: */
128#ifndef PI
129# define PI 3.141592653589793238
130#endif
131#define PI_2 (PI*0.5)
132#define INV_PI_360 (360.0 / PI)
133#define MAX(a,b) (a>b?a:b)
134#define MIN(a,b) (a<b?a:b)
135#define CLIP(a,min,max) MAX(min,MIN((a),max))
136#define ABS(a) ((a)<0?-(a):(a))
137#define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */
138#define ROUNDF(f) ((int)(f + 0.5))
139
140#define rgb1_max bg_freq
141#define rgb1_min bg_gray
142#define rgb2_max bg_bsat
143#define rgb2_min bg_brot
144
145/* #define DEBUG */ /* this enables the Trace() macros */
146
147#include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */
148
149
150/* could just include png.h, but this macro is the only thing we need
151 * (name and typedefs changed to local versions); note that side effects
152 * only happen with alpha (which could easily be avoided with
153 * "ush acopy = (alpha);") */
154
155#define alpha_composite(composite, fg, alpha, bg) { \
156 ush temp = ((ush)(fg)*(ush)(alpha) + \
157 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
158 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
159}
160
161
162#define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this
163 * block size corresponds roughly to a download
164 * speed 10% faster than theoretical 33.6K maximum
165 * (assuming 8 data bits, 1 stop bit and no other
166 * overhead) */
167
168/* local prototypes */
169static void rpng2_win_init(void);
170static int rpng2_win_create_window(void);
171static int rpng2_win_load_bg_image(void);
172static void rpng2_win_display_row(ulg row);
173static void rpng2_win_finish_display(void);
174static void rpng2_win_cleanup(void);
175LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM);
176
177
178static char titlebar[1024];
179static char *progname = PROGNAME;
180static char *appname = LONGNAME;
181static char *filename;
182static FILE *infile;
183
184static mainprog_info rpng2_info;
185
186static uch inbuf[INBUFSIZE];
187static int incount;
188
189static int pat = 6; /* must be less than num_bgpat */
190static int bg_image = 0;
191static int bgscale = 16;
192static ulg bg_rowbytes;
193static uch *bg_data;
194
195static struct rgb_color {
196 uch r, g, b;
197} rgb[] = {
198 { 0, 0, 0}, /* 0: black */
199 {255, 255, 255}, /* 1: white */
200 {173, 132, 57}, /* 2: tan */
201 { 64, 132, 0}, /* 3: medium green */
202 {189, 117, 1}, /* 4: gold */
203 {253, 249, 1}, /* 5: yellow */
204 { 0, 0, 255}, /* 6: blue */
205 { 0, 0, 120}, /* 7: medium blue */
206 {255, 0, 255}, /* 8: magenta */
207 { 64, 0, 64}, /* 9: dark magenta */
208 {255, 0, 0}, /* 10: red */
209 { 64, 0, 0}, /* 11: dark red */
210 {255, 127, 0}, /* 12: orange */
211 {192, 96, 0}, /* 13: darker orange */
212 { 24, 60, 0}, /* 14: dark green-yellow */
213 { 85, 125, 200} /* 15: ice blue */
214};
215/* not used for now, but should be for error-checking:
216static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color);
217 */
218
219/*
220 This whole struct is a fairly cheesy way to keep the number of
221 command-line options to a minimum. The radial-waves background
222 type is a particularly poor fit to the integer elements of the
223 struct...but a few macros and a little fixed-point math will do
224 wonders for ya.
225
226 type bits:
227 F E D C B A 9 8 7 6 5 4 3 2 1 0
228 | | | | |
229 | | +-+-+-- 0 = sharp-edged checkerboard
230 | | 1 = soft diamonds
231 | | 2 = radial waves
232 | | 3-7 = undefined
233 | +-- gradient #2 inverted?
234 +-- alternating columns inverted?
235 */
236static struct background_pattern {
237 ush type;
238 int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */
239 int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/
240} bg[] = {
241 {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */
242 {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */
243 {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */
244 {0+8, 4,5, 0,6}, /* checkered: gold/yellow vs. black/blue */
245 {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */
246 {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */
247 {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */
248 {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */
249 {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */
250 {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */
251 {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */
252 {1, 3,0, 0,0}, /* diamonds: medium green vs. black */
253 {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */
254 {2, 18, 100, 10, 2}, /* radial: soft, curved radial color-beams */
255 {2, 16, 256, 100, 250}, /* radial: very tight spiral */
256 {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */
257};
258static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern);
259
260
261/* Windows-specific global variables (could go in struct, but messy...) */
262static ulg wimage_rowbytes;
263static uch *dib;
264static uch *wimage_data;
265static BITMAPINFOHEADER *bmih;
266
267static HWND global_hwnd;
268static HINSTANCE global_hInst;
269static int global_showmode;
270
271
272
273
274int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)
275{
276 char *args[1024]; /* arbitrary limit, but should suffice */
277 char **argv = args;
278 char *p, *q, *bgstr = NULL;
279 int argc = 0;
280 int rc, alen, flen;
281 int error = 0;
282 int timing = FALSE;
283 int have_bg = FALSE;
284 double LUT_exponent; /* just the lookup table */
285 double CRT_exponent = 2.2; /* just the monitor */
286 double default_display_exponent; /* whole display system */
287 MSG msg;
288
289
290 /* First initialize a few things, just to be sure--memset takes care of
291 * default background color (black), booleans (FALSE), pointers (NULL),
292 * etc. */
293
294 global_hInst = hInst;
295 global_showmode = showmode;
296 filename = (char *)NULL;
297 memset(&rpng2_info, 0, sizeof(mainprog_info));
298
299#ifndef __CYGWIN__
300 /* Next reenable console output, which normally goes to the bit bucket
301 * for windowed apps. Closing the console window will terminate the
302 * app. Thanks to David.Geldreich@realviz.com for supplying the magical
303 * incantation. */
304
305 AllocConsole();
306 freopen("CONOUT$", "a", stderr);
307 freopen("CONOUT$", "a", stdout);
308#endif
309
310 /* Set the default value for our display-system exponent, i.e., the
311 * product of the CRT exponent and the exponent corresponding to
312 * the frame-buffer's lookup table (LUT), if any. This is not an
313 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
314 * ones), but it should cover 99% of the current possibilities. And
315 * yes, these ifdefs are completely wasted in a Windows program... */
316
317#if defined(NeXT)
318 /* third-party utilities can modify the default LUT exponent */
319 LUT_exponent = 1.0 / 2.2;
320 /*
321 if (some_next_function_that_returns_gamma(&next_gamma))
322 LUT_exponent = 1.0 / next_gamma;
323 */
324#elif defined(sgi)
325 LUT_exponent = 1.0 / 1.7;
326 /* there doesn't seem to be any documented function to
327 * get the "gamma" value, so we do it the hard way */
328 infile = fopen("/etc/config/system.glGammaVal", "r");
329 if (infile) {
330 double sgi_gamma;
331
332 fgets(tmpline, 80, infile);
333 fclose(infile);
334 sgi_gamma = atof(tmpline);
335 if (sgi_gamma > 0.0)
336 LUT_exponent = 1.0 / sgi_gamma;
337 }
338#elif defined(Macintosh)
339 LUT_exponent = 1.8 / 2.61;
340 /*
341 if (some_mac_function_that_returns_gamma(&mac_gamma))
342 LUT_exponent = mac_gamma / 2.61;
343 */
344#else
345 LUT_exponent = 1.0; /* assume no LUT: most PCs */
346#endif
347
348 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
349 default_display_exponent = LUT_exponent * CRT_exponent;
350
351
352 /* If the user has set the SCREEN_GAMMA environment variable as suggested
353 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
354 * use the default value we just calculated. Either way, the user may
355 * override this via a command-line option. */
356
357 if ((p = getenv("SCREEN_GAMMA")) != NULL)
358 rpng2_info.display_exponent = atof(p);
359 else
360 rpng2_info.display_exponent = default_display_exponent;
361
362
363 /* Windows really hates command lines, so we have to set up our own argv.
364 * Note that we do NOT bother with quoted arguments here, so don't use
365 * filenames with spaces in 'em! */
366
367 argv[argc++] = PROGNAME;
368 p = cmd;
369 for (;;) {
370 if (*p == ' ')
371 while (*++p == ' ')
372 ;
373 /* now p points at the first non-space after some spaces */
374 if (*p == '\0')
375 break; /* nothing after the spaces: done */
376 argv[argc++] = q = p;
377 while (*q && *q != ' ')
378 ++q;
379 /* now q points at a space or the end of the string */
380 if (*q == '\0')
381 break; /* last argv already terminated; quit */
382 *q = '\0'; /* change space to terminator */
383 p = q + 1;
384 }
385 argv[argc] = NULL; /* terminate the argv array itself */
386
387
388 /* Now parse the command line for options and the PNG filename. */
389
390 while (*++argv && !error) {
391 if (!strncmp(*argv, "-gamma", 2)) {
392 if (!*++argv)
393 ++error;
394 else {
395 rpng2_info.display_exponent = atof(*argv);
396 if (rpng2_info.display_exponent <= 0.0)
397 ++error;
398 }
399 } else if (!strncmp(*argv, "-bgcolor", 4)) {
400 if (!*++argv)
401 ++error;
402 else {
403 bgstr = *argv;
404 if (strlen(bgstr) != 7 || bgstr[0] != '#')
405 ++error;
406 else {
407 have_bg = TRUE;
408 bg_image = FALSE;
409 }
410 }
411 } else if (!strncmp(*argv, "-bgpat", 4)) {
412 if (!*++argv)
413 ++error;
414 else {
415 pat = atoi(*argv) - 1;
416 if (pat < 0 || pat >= num_bgpat)
417 ++error;
418 else {
419 bg_image = TRUE;
420 have_bg = FALSE;
421 }
422 }
423 } else if (!strncmp(*argv, "-timing", 2)) {
424 timing = TRUE;
425 } else {
426 if (**argv != '-') {
427 filename = *argv;
428 if (argv[1]) /* shouldn't be any more args after filename */
429 ++error;
430 } else
431 ++error; /* not expecting any other options */
432 }
433 }
434
435 if (!filename)
436 ++error;
437
438
439 /* print usage screen if any errors up to this point */
440
441 if (error) {
442#ifndef __CYGWIN__
443 int ch;
444#endif
445
446 fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
447 readpng2_version_info();
448 fprintf(stderr, "\n"
449 "Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n"
450 " %*s file.png\n\n"
451 " exp \ttransfer-function exponent (``gamma'') of the display\n"
452 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
453 "\t\t to the product of the lookup-table exponent (varies)\n"
454 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
455 " bg \tdesired background color in 7-character hex RGB format\n"
456 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
457 "\t\t used with transparent images; overrides -bgpat option\n"
458 " pat \tdesired background pattern number (1-%d); used with\n"
459 "\t\t transparent images; overrides -bgcolor option\n"
460 " -timing\tenables delay for every block read, to simulate modem\n"
461 "\t\t download of image (~36 Kbps)\n"
462 "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n"
463#ifndef __CYGWIN__
464 "Press Q or Esc to quit this usage screen. ",
465#else
466 ,
467#endif
468 PROGNAME,
469#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \
470 !(defined(__CYGWIN__) || defined(__MINGW32__))
471 (int)strlen(PROGNAME), " ",
472#endif
473 (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat);
474 fflush(stderr);
475#ifndef __CYGWIN__
476 do
477 ch = _getch();
478 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
479#endif
480 exit(1);
481 }
482
483
484 if (!(infile = fopen(filename, "rb"))) {
485 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
486 ++error;
487 } else {
488 incount = fread(inbuf, 1, INBUFSIZE, infile);
489 if (incount < 8 || !readpng2_check_sig(inbuf, 8)) {
490 fprintf(stderr, PROGNAME
491 ": [%s] is not a PNG file: incorrect signature\n",
492 filename);
493 ++error;
494 } else if ((rc = readpng2_init(&rpng2_info)) != 0) {
495 switch (rc) {
496 case 2:
497 fprintf(stderr, PROGNAME
498 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
499 break;
500 case 4:
501 fprintf(stderr, PROGNAME ": insufficient memory\n");
502 break;
503 default:
504 fprintf(stderr, PROGNAME
505 ": unknown readpng2_init() error\n");
506 break;
507 }
508 ++error;
509 }
510 if (error)
511 fclose(infile);
512 }
513
514
515 if (error) {
516#ifndef __CYGWIN__
517 int ch;
518#endif
519
520 fprintf(stderr, PROGNAME ": aborting.\n");
521#ifndef __CYGWIN__
522 do
523 ch = _getch();
524 while (ch != 'q' && ch != 'Q' && ch != 0x1B);
525#endif
526 exit(2);
527 } else {
528 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname);
529#ifndef __CYGWIN__
530 fprintf(stderr,
531 "\n [console window: closing this window will terminate %s]\n\n",
532 PROGNAME);
533#endif
534 fflush(stderr);
535 }
536
537
538 /* set the title-bar string, but make sure buffer doesn't overflow */
539
540 alen = strlen(appname);
541 flen = strlen(filename);
542 if (alen + flen + 3 > 1023)
543 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
544 else
545 sprintf(titlebar, "%s: %s", appname, filename);
546
547
548 /* set some final rpng2_info variables before entering main data loop */
549
550 if (have_bg) {
551 unsigned r, g, b; /* this approach quiets compiler warnings */
552
553 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
554 rpng2_info.bg_red = (uch)r;
555 rpng2_info.bg_green = (uch)g;
556 rpng2_info.bg_blue = (uch)b;
557 } else
558 rpng2_info.need_bgcolor = TRUE;
559
560 rpng2_info.state = kPreInit;
561 rpng2_info.mainprog_init = rpng2_win_init;
562 rpng2_info.mainprog_display_row = rpng2_win_display_row;
563 rpng2_info.mainprog_finish_display = rpng2_win_finish_display;
564
565
566 /* OK, this is the fun part: call readpng2_decode_data() at the start of
567 * the loop to deal with our first buffer of data (read in above to verify
568 * that the file is a PNG image), then loop through the file and continue
569 * calling the same routine to handle each chunk of data. It in turn
570 * passes the data to libpng, which will invoke one or more of our call-
571 * backs as decoded data become available. We optionally call Sleep() for
572 * one second per iteration to simulate downloading the image via an analog
573 * modem. */
574
575 for (;;) {
576 Trace((stderr, "about to call readpng2_decode_data()\n"))
577 if (readpng2_decode_data(&rpng2_info, inbuf, incount))
578 ++error;
579 Trace((stderr, "done with readpng2_decode_data()\n"))
580
581 if (error || incount != INBUFSIZE || rpng2_info.state == kDone) {
582 if (rpng2_info.state == kDone) {
583 Trace((stderr, "done decoding PNG image\n"))
584 } else if (ferror(infile)) {
585 fprintf(stderr, PROGNAME
586 ": error while reading PNG image file\n");
587 exit(3);
588 } else if (feof(infile)) {
589 fprintf(stderr, PROGNAME ": end of file reached "
590 "(unexpectedly) while reading PNG image file\n");
591 exit(3);
592 } else /* if (error) */ {
593 /* will print error message below */
594 }
595 break;
596 }
597
598 if (timing)
599 Sleep(1000L);
600
601 incount = fread(inbuf, 1, INBUFSIZE, infile);
602 }
603
604
605 /* clean up PNG stuff and report any decoding errors */
606
607 fclose(infile);
608 Trace((stderr, "about to call readpng2_cleanup()\n"))
609 readpng2_cleanup(&rpng2_info);
610
611 if (error) {
612 fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n");
613 exit(3);
614 }
615
616
617 /* wait for the user to tell us when to quit */
618
619 while (GetMessage(&msg, NULL, 0, 0)) {
620 TranslateMessage(&msg);
621 DispatchMessage(&msg);
622 }
623
624
625 /* we're done: clean up all image and Windows resources and go away */
626
627 Trace((stderr, "about to call rpng2_win_cleanup()\n"))
628 rpng2_win_cleanup();
629
630 return msg.wParam;
631}
632
633
634
635
636
637/* this function is called by readpng2_info_callback() in readpng2.c, which
638 * in turn is called by libpng after all of the pre-IDAT chunks have been
639 * read and processed--i.e., we now have enough info to finish initializing */
640
641static void rpng2_win_init()
642{
643 ulg i;
644 ulg rowbytes = rpng2_info.rowbytes;
645
646 Trace((stderr, "beginning rpng2_win_init()\n"))
647 Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes))
648 Trace((stderr, " width = %ld\n", rpng2_info.width))
649 Trace((stderr, " height = %ld\n", rpng2_info.height))
650
651 rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
652 if (!rpng2_info.image_data) {
653 readpng2_cleanup(&rpng2_info);
654 return;
655 }
656
657 rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));
658 if (!rpng2_info.row_pointers) {
659 free(rpng2_info.image_data);
660 rpng2_info.image_data = NULL;
661 readpng2_cleanup(&rpng2_info);
662 return;
663 }
664
665 for (i = 0; i < rpng2_info.height; ++i)
666 rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;
667
668/*---------------------------------------------------------------------------
669 Do the basic Windows initialization stuff, make the window, and fill it
670 with the user-specified, file-specified or default background color.
671 ---------------------------------------------------------------------------*/
672
673 if (rpng2_win_create_window()) {
674 readpng2_cleanup(&rpng2_info);
675 return;
676 }
677
678 rpng2_info.state = kWindowInit;
679}
680
681
682
683
684
685static int rpng2_win_create_window()
686{
687 uch bg_red = rpng2_info.bg_red;
688 uch bg_green = rpng2_info.bg_green;
689 uch bg_blue = rpng2_info.bg_blue;
690 uch *dest;
691 int extra_width, extra_height;
692 ulg i, j;
693 WNDCLASSEX wndclass;
694 RECT rect;
695
696
697/*---------------------------------------------------------------------------
698 Allocate memory for the display-specific version of the image (round up
699 to multiple of 4 for Windows DIB).
700 ---------------------------------------------------------------------------*/
701
702 wimage_rowbytes = ((3*rpng2_info.width + 3L) >> 2) << 2;
703
704 if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +
705 wimage_rowbytes*rpng2_info.height)))
706 {
707 return 4; /* fail */
708 }
709
710/*---------------------------------------------------------------------------
711 Initialize the DIB. Negative height means to use top-down BMP ordering
712 (must be uncompressed, but that's what we want). Bit count of 1, 4 or 8
713 implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values
714 directly => wimage_data begins immediately after BMP header.
715 ---------------------------------------------------------------------------*/
716
717 memset(dib, 0, sizeof(BITMAPINFOHEADER));
718 bmih = (BITMAPINFOHEADER *)dib;
719 bmih->biSize = sizeof(BITMAPINFOHEADER);
720 bmih->biWidth = rpng2_info.width;
721 bmih->biHeight = -((long)rpng2_info.height);
722 bmih->biPlanes = 1;
723 bmih->biBitCount = 24;
724 bmih->biCompression = 0;
725 wimage_data = dib + sizeof(BITMAPINFOHEADER);
726
727/*---------------------------------------------------------------------------
728 Fill window with the specified background color (default is black), but
729 defer loading faked "background image" until window is displayed (may be
730 slow to compute). Data are in BGR order.
731 ---------------------------------------------------------------------------*/
732
733 if (bg_image) { /* just fill with black for now */
734 memset(wimage_data, 0, wimage_rowbytes*rpng2_info.height);
735 } else {
736 for (j = 0; j < rpng2_info.height; ++j) {
737 dest = wimage_data + j*wimage_rowbytes;
738 for (i = rpng2_info.width; i > 0; --i) {
739 *dest++ = bg_blue;
740 *dest++ = bg_green;
741 *dest++ = bg_red;
742 }
743 }
744 }
745
746/*---------------------------------------------------------------------------
747 Set the window parameters.
748 ---------------------------------------------------------------------------*/
749
750 memset(&wndclass, 0, sizeof(wndclass));
751
752 wndclass.cbSize = sizeof(wndclass);
753 wndclass.style = CS_HREDRAW | CS_VREDRAW;
754 wndclass.lpfnWndProc = rpng2_win_wndproc;
755 wndclass.hInstance = global_hInst;
756 wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
757 wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
758 wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
759 wndclass.lpszMenuName = NULL;
760 wndclass.lpszClassName = progname;
761 wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
762
763 RegisterClassEx(&wndclass);
764
765/*---------------------------------------------------------------------------
766 Finally, create the window.
767 ---------------------------------------------------------------------------*/
768
769 extra_width = 2*(GetSystemMetrics(SM_CXBORDER) +
770 GetSystemMetrics(SM_CXDLGFRAME));
771 extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +
772 GetSystemMetrics(SM_CYDLGFRAME)) +
773 GetSystemMetrics(SM_CYCAPTION);
774
775 global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,
776 CW_USEDEFAULT, CW_USEDEFAULT, rpng2_info.width+extra_width,
777 rpng2_info.height+extra_height, NULL, NULL, global_hInst, NULL);
778
779 ShowWindow(global_hwnd, global_showmode);
780 UpdateWindow(global_hwnd);
781
782/*---------------------------------------------------------------------------
783 Now compute the background image and display it. If it fails (memory
784 allocation), revert to a plain background color.
785 ---------------------------------------------------------------------------*/
786
787 if (bg_image) {
788 static const char *msg = "Computing background image...";
789 int x, y, len = strlen(msg);
790 HDC hdc = GetDC(global_hwnd);
791 TEXTMETRIC tm;
792
793 GetTextMetrics(hdc, &tm);
794 x = (rpng2_info.width - len*tm.tmAveCharWidth)/2;
795 y = (rpng2_info.height - tm.tmHeight)/2;
796 SetBkMode(hdc, TRANSPARENT);
797 SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
798 /* this can still begin out of bounds even if x is positive (???): */
799 TextOut(hdc, ((x < 0)? 0 : x), ((y < 0)? 0 : y), msg, len);
800 ReleaseDC(global_hwnd, hdc);
801
802 rpng2_win_load_bg_image(); /* resets bg_image if fails */
803 }
804
805 if (!bg_image) {
806 for (j = 0; j < rpng2_info.height; ++j) {
807 dest = wimage_data + j*wimage_rowbytes;
808 for (i = rpng2_info.width; i > 0; --i) {
809 *dest++ = bg_blue;
810 *dest++ = bg_green;
811 *dest++ = bg_red;
812 }
813 }
814 }
815
816 rect.left = 0L;
817 rect.top = 0L;
818 rect.right = (LONG)rpng2_info.width; /* possibly off by one? */
819 rect.bottom = (LONG)rpng2_info.height; /* possibly off by one? */
820 InvalidateRect(global_hwnd, &rect, FALSE);
821 UpdateWindow(global_hwnd); /* similar to XFlush() */
822
823 return 0;
824
825} /* end function rpng2_win_create_window() */
826
827
828
829
830
831static int rpng2_win_load_bg_image()
832{
833 uch *src, *dest;
834 uch r1, r2, g1, g2, b1, b2;
835 uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
836 int k, hmax, max;
837 int xidx, yidx, yidx_max = (bgscale-1);
838 int even_odd_vert, even_odd_horiz, even_odd;
839 int invert_gradient2 = (bg[pat].type & 0x08);
840 int invert_column;
841 ulg i, row;
842
843/*---------------------------------------------------------------------------
844 Allocate buffer for fake background image to be used with transparent
845 images; if this fails, revert to plain background color.
846 ---------------------------------------------------------------------------*/
847
848 bg_rowbytes = 3 * rpng2_info.width;
849 bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);
850 if (!bg_data) {
851 fprintf(stderr, PROGNAME
852 ": unable to allocate memory for background image\n");
853 bg_image = 0;
854 return 1;
855 }
856
857/*---------------------------------------------------------------------------
858 Vertical gradients (ramps) in NxN squares, alternating direction and
859 colors (N == bgscale).
860 ---------------------------------------------------------------------------*/
861
862 if ((bg[pat].type & 0x07) == 0) {
863 uch r1_min = rgb[bg[pat].rgb1_min].r;
864 uch g1_min = rgb[bg[pat].rgb1_min].g;
865 uch b1_min = rgb[bg[pat].rgb1_min].b;
866 uch r2_min = rgb[bg[pat].rgb2_min].r;
867 uch g2_min = rgb[bg[pat].rgb2_min].g;
868 uch b2_min = rgb[bg[pat].rgb2_min].b;
869 int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
870 int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
871 int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
872 int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
873 int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
874 int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
875
876 for (row = 0; row < rpng2_info.height; ++row) {
877 yidx = row % bgscale;
878 even_odd_vert = (row / bgscale) & 1;
879
880 r1 = r1_min + (r1_diff * yidx) / yidx_max;
881 g1 = g1_min + (g1_diff * yidx) / yidx_max;
882 b1 = b1_min + (b1_diff * yidx) / yidx_max;
883 r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
884 g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
885 b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
886
887 r2 = r2_min + (r2_diff * yidx) / yidx_max;
888 g2 = g2_min + (g2_diff * yidx) / yidx_max;
889 b2 = b2_min + (b2_diff * yidx) / yidx_max;
890 r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
891 g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
892 b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
893
894 dest = bg_data + row*bg_rowbytes;
895 for (i = 0; i < rpng2_info.width; ++i) {
896 even_odd_horiz = (i / bgscale) & 1;
897 even_odd = even_odd_vert ^ even_odd_horiz;
898 invert_column =
899 (even_odd_horiz && (bg[pat].type & 0x10));
900 if (even_odd == 0) { /* gradient #1 */
901 if (invert_column) {
902 *dest++ = r1_inv;
903 *dest++ = g1_inv;
904 *dest++ = b1_inv;
905 } else {
906 *dest++ = r1;
907 *dest++ = g1;
908 *dest++ = b1;
909 }
910 } else { /* gradient #2 */
911 if ((invert_column && invert_gradient2) ||
912 (!invert_column && !invert_gradient2))
913 {
914 *dest++ = r2; /* not inverted or */
915 *dest++ = g2; /* doubly inverted */
916 *dest++ = b2;
917 } else {
918 *dest++ = r2_inv;
919 *dest++ = g2_inv; /* singly inverted */
920 *dest++ = b2_inv;
921 }
922 }
923 }
924 }
925
926/*---------------------------------------------------------------------------
927 Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
928 M. Costello.
929 ---------------------------------------------------------------------------*/
930
931 } else if ((bg[pat].type & 0x07) == 1) {
932
933 hmax = (bgscale-1)/2; /* half the max weight of a color */
934 max = 2*hmax; /* the max weight of a color */
935
936 r1 = rgb[bg[pat].rgb1_max].r;
937 g1 = rgb[bg[pat].rgb1_max].g;
938 b1 = rgb[bg[pat].rgb1_max].b;
939 r2 = rgb[bg[pat].rgb2_max].r;
940 g2 = rgb[bg[pat].rgb2_max].g;
941 b2 = rgb[bg[pat].rgb2_max].b;
942
943 for (row = 0; row < rpng2_info.height; ++row) {
944 yidx = row % bgscale;
945 if (yidx > hmax)
946 yidx = bgscale-1 - yidx;
947 dest = bg_data + row*bg_rowbytes;
948 for (i = 0; i < rpng2_info.width; ++i) {
949 xidx = i % bgscale;
950 if (xidx > hmax)
951 xidx = bgscale-1 - xidx;
952 k = xidx + yidx;
953 *dest++ = (k*r1 + (max-k)*r2) / max;
954 *dest++ = (k*g1 + (max-k)*g2) / max;
955 *dest++ = (k*b1 + (max-k)*b2) / max;
956 }
957 }
958
959/*---------------------------------------------------------------------------
960 Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
961 soids will equal bgscale?]. This one is slow but very cool. Code con-
962 tributed by Pieter S. van der Meulen (originally in Smalltalk).
963 ---------------------------------------------------------------------------*/
964
965 } else if ((bg[pat].type & 0x07) == 2) {
966 uch ch;
967 int ii, x, y, hw, hh, grayspot;
968 double freq, rotate, saturate, gray, intensity;
969 double angle=0.0, aoffset=0.0, maxDist, dist;
970 double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
971
972 fprintf(stderr, "%s: computing radial background...",
973 PROGNAME);
974 fflush(stderr);
975
976 hh = rpng2_info.height / 2;
977 hw = rpng2_info.width / 2;
978
979 /* variables for radial waves:
980 * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
981 * freq: number of color beams originating from the center
982 * grayspot: size of the graying center area (anti-alias)
983 * rotate: rotation of the beams as a function of radius
984 * saturate: saturation of beams' shape azimuthally
985 */
986 angle = CLIP(angle, 0.0, 360.0);
987 grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
988 freq = MAX((double)bg[pat].bg_freq, 0.0);
989 saturate = (double)bg[pat].bg_bsat * 0.1;
990 rotate = (double)bg[pat].bg_brot * 0.1;
991 gray = 0.0;
992 intensity = 0.0;
993 maxDist = (double)((hw*hw) + (hh*hh));
994
995 for (row = 0; row < rpng2_info.height; ++row) {
996 y = row - hh;
997 dest = bg_data + row*bg_rowbytes;
998 for (i = 0; i < rpng2_info.width; ++i) {
999 x = i - hw;
1000 angle = (x == 0)? PI_2 : atan((double)y / (double)x);
1001 gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
1002 gray = MIN(1.0, gray);
1003 dist = (double)((x*x) + (y*y)) / maxDist;
1004 intensity = cos((angle+(rotate*dist*PI)) * freq) *
1005 gray * saturate;
1006 intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
1007 hue = (angle + PI) * INV_PI_360 + aoffset;
1008 s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
1009 s = MIN(MAX(s,0.0), 1.0);
1010 v = MIN(MAX(intensity,0.0), 1.0);
1011
1012 if (s == 0.0) {
1013 ch = (uch)(v * 255.0);
1014 *dest++ = ch;
1015 *dest++ = ch;
1016 *dest++ = ch;
1017 } else {
1018 if ((hue < 0.0) || (hue >= 360.0))
1019 hue -= (((int)(hue / 360.0)) * 360.0);
1020 hue /= 60.0;
1021 ii = (int)hue;
1022 f = hue - (double)ii;
1023 p = (1.0 - s) * v;
1024 q = (1.0 - (s * f)) * v;
1025 t = (1.0 - (s * (1.0 - f))) * v;
1026 if (ii == 0) { red = v; green = t; blue = p; }
1027 else if (ii == 1) { red = q; green = v; blue = p; }
1028 else if (ii == 2) { red = p; green = v; blue = t; }
1029 else if (ii == 3) { red = p; green = q; blue = v; }
1030 else if (ii == 4) { red = t; green = p; blue = v; }
1031 else if (ii == 5) { red = v; green = p; blue = q; }
1032 *dest++ = (uch)(red * 255.0);
1033 *dest++ = (uch)(green * 255.0);
1034 *dest++ = (uch)(blue * 255.0);
1035 }
1036 }
1037 }
1038 fprintf(stderr, "done.\n");
1039 fflush(stderr);
1040 }
1041
1042/*---------------------------------------------------------------------------
1043 Blast background image to display buffer before beginning PNG decode;
1044 calling function will handle invalidation and UpdateWindow() call.
1045 ---------------------------------------------------------------------------*/
1046
1047 for (row = 0; row < rpng2_info.height; ++row) {
1048 src = bg_data + row*bg_rowbytes;
1049 dest = wimage_data + row*wimage_rowbytes;
1050 for (i = rpng2_info.width; i > 0; --i) {
1051 r1 = *src++;
1052 g1 = *src++;
1053 b1 = *src++;
1054 *dest++ = b1;
1055 *dest++ = g1; /* note reverse order */
1056 *dest++ = r1;
1057 }
1058 }
1059
1060 return 0;
1061
1062} /* end function rpng2_win_load_bg_image() */
1063
1064
1065
1066
1067
1068static void rpng2_win_display_row(ulg row)
1069{
1070 uch bg_red = rpng2_info.bg_red;
1071 uch bg_green = rpng2_info.bg_green;
1072 uch bg_blue = rpng2_info.bg_blue;
1073 uch *src, *src2=NULL, *dest;
1074 uch r, g, b, a;
1075 ulg i;
1076 static int rows=0;
1077 static ulg firstrow;
1078
1079/*---------------------------------------------------------------------------
1080 rows and firstrow simply track how many rows (and which ones) have not
1081 yet been displayed; alternatively, we could call InvalidateRect() for
1082 every row and not bother with the records-keeping.
1083 ---------------------------------------------------------------------------*/
1084
1085 Trace((stderr, "beginning rpng2_win_display_row()\n"))
1086
1087 if (rows == 0)
1088 firstrow = row; /* first row not yet displayed */
1089
1090 ++rows; /* count of rows received but not yet displayed */
1091
1092/*---------------------------------------------------------------------------
1093 Aside from the use of the rpng2_info struct and the lack of an outer
1094 loop (over rows), this routine is identical to rpng_win_display_image()
1095 in the non-progressive version of the program.
1096 ---------------------------------------------------------------------------*/
1097
1098 src = rpng2_info.image_data + row*rpng2_info.rowbytes;
1099 if (bg_image)
1100 src2 = bg_data + row*bg_rowbytes;
1101 dest = wimage_data + row*wimage_rowbytes;
1102
1103 if (rpng2_info.channels == 3) {
1104 for (i = rpng2_info.width; i > 0; --i) {
1105 r = *src++;
1106 g = *src++;
1107 b = *src++;
1108 *dest++ = b;
1109 *dest++ = g; /* note reverse order */
1110 *dest++ = r;
1111 }
1112 } else /* if (rpng2_info.channels == 4) */ {
1113 for (i = rpng2_info.width; i > 0; --i) {
1114 r = *src++;
1115 g = *src++;
1116 b = *src++;
1117 a = *src++;
1118 if (bg_image) {
1119 bg_red = *src2++;
1120 bg_green = *src2++;
1121 bg_blue = *src2++;
1122 }
1123 if (a == 255) {
1124 *dest++ = b;
1125 *dest++ = g;
1126 *dest++ = r;
1127 } else if (a == 0) {
1128 *dest++ = bg_blue;
1129 *dest++ = bg_green;
1130 *dest++ = bg_red;
1131 } else {
1132 /* this macro (copied from png.h) composites the
1133 * foreground and background values and puts the
1134 * result into the first argument; there are no
1135 * side effects with the first argument */
1136 alpha_composite(*dest++, b, a, bg_blue);
1137 alpha_composite(*dest++, g, a, bg_green);
1138 alpha_composite(*dest++, r, a, bg_red);
1139 }
1140 }
1141 }
1142
1143/*---------------------------------------------------------------------------
1144 Display after every 16 rows or when on last row. (Region may include
1145 previously displayed lines due to interlacing--i.e., not contiguous.)
1146 ---------------------------------------------------------------------------*/
1147
1148 if ((rows & 0xf) == 0 || row == rpng2_info.height-1) {
1149 RECT rect;
1150
1151 rect.left = 0L;
1152 rect.top = (LONG)firstrow;
1153 rect.right = (LONG)rpng2_info.width; /* possibly off by one? */
1154 rect.bottom = (LONG)row + 1L; /* possibly off by one? */
1155 InvalidateRect(global_hwnd, &rect, FALSE);
1156 UpdateWindow(global_hwnd); /* similar to XFlush() */
1157 rows = 0;
1158 }
1159
1160} /* end function rpng2_win_display_row() */
1161
1162
1163
1164
1165
1166static void rpng2_win_finish_display()
1167{
1168 Trace((stderr, "beginning rpng2_win_finish_display()\n"))
1169
1170 /* last row has already been displayed by rpng2_win_display_row(), so
1171 * we have nothing to do here except set a flag and let the user know
1172 * that the image is done */
1173
1174 rpng2_info.state = kDone;
1175 printf(
1176#ifndef __CYGWIN__
1177 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"
1178#else
1179 "Done. Press mouse button 1 (within image window) to quit.\n"
1180#endif
1181 );
1182 fflush(stdout);
1183}
1184
1185
1186
1187
1188
1189static void rpng2_win_cleanup()
1190{
1191 if (bg_image && bg_data) {
1192 free(bg_data);
1193 bg_data = NULL;
1194 }
1195
1196 if (rpng2_info.image_data) {
1197 free(rpng2_info.image_data);
1198 rpng2_info.image_data = NULL;
1199 }
1200
1201 if (rpng2_info.row_pointers) {
1202 free(rpng2_info.row_pointers);
1203 rpng2_info.row_pointers = NULL;
1204 }
1205
1206 if (dib) {
1207 free(dib);
1208 dib = NULL;
1209 }
1210}
1211
1212
1213
1214
1215
1216LRESULT CALLBACK rpng2_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)
1217{
1218 HDC hdc;
1219 PAINTSTRUCT ps;
1220 int rc;
1221
1222 switch (iMsg) {
1223 case WM_CREATE:
1224 /* one-time processing here, if any */
1225 return 0;
1226
1227 case WM_PAINT:
1228 hdc = BeginPaint(hwnd, &ps);
1229 rc = StretchDIBits(hdc, 0, 0, rpng2_info.width, rpng2_info.height,
1230 0, 0, rpng2_info.width, rpng2_info.height,
1231 wimage_data, (BITMAPINFO *)bmih,
1232 0, SRCCOPY);
1233 EndPaint(hwnd, &ps);
1234 return 0;
1235
1236 /* wait for the user to tell us when to quit */
1237 case WM_CHAR:
1238 switch (wP) { /* only need one, so ignore repeat count */
1239 case 'q':
1240 case 'Q':
1241 case 0x1B: /* Esc key */
1242 PostQuitMessage(0);
1243 }
1244 return 0;
1245
1246 case WM_LBUTTONDOWN: /* another way of quitting */
1247 case WM_DESTROY:
1248 PostQuitMessage(0);
1249 return 0;
1250 }
1251
1252 return DefWindowProc(hwnd, iMsg, wP, lP);
1253}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c
new file mode 100644
index 0000000..6c687db
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/rpng2-x.c
@@ -0,0 +1,2107 @@
1/*---------------------------------------------------------------------------
2
3 rpng2 - progressive-model PNG display program rpng2-x.c
4
5 This program decodes and displays PNG files progressively, as if it were
6 a web browser (though the front end is only set up to read from files).
7 It supports gamma correction, user-specified background colors, and user-
8 specified background patterns (for transparent images). This version is
9 for the X Window System (tested by the author under Unix and by Martin
10 Zinser under OpenVMS; may work under OS/2 with a little tweaking).
11
12 Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond"
13 and "radial waves" patterns, respectively.
14
15 to do (someday, maybe):
16 - fix expose/redraw code: don't draw entire row if only part exposed
17 - 8-bit (colormapped) X support
18 - finish resizable checkerboard-gradient (sizes 4-128?)
19 - use %.1023s to simplify truncation of title-bar string?
20
21 ---------------------------------------------------------------------------
22
23 Changelog:
24 - 1.01: initial public release
25 - 1.02: modified to allow abbreviated options; fixed char/uchar mismatch
26 - 1.10: added support for non-default visuals; fixed X pixel-conversion
27 - 1.11: added -usleep option for demos; fixed command-line parsing bug
28 - 1.12: added -pause option for demos and testing
29 - 1.20: added runtime MMX-enabling/disabling and new -mmx* options
30 - 1.21: fixed some small X memory leaks (thanks to François Petitjean)
31 - 1.22: fixed XFreeGC() crash bug (thanks to Patrick Welche)
32 - 1.23: added -bgpat 0 mode (std white/gray checkerboard, 8x8 squares)
33 - 1.30: added -loop option for -bgpat (ifdef FEATURE_LOOP); fixed bpp =
34 24; added support for X resources (thanks to Gerhard Niklasch)
35 - 1.31: added code to skip unused chunks (thanks to Glenn Randers-Pehrson)
36 - 1.32: added AMD64/EM64T support (__x86_64__); added basic expose/redraw
37 handling
38 - 2.00: dual-licensed (added GNU GPL)
39 - 2.01: fixed 64-bit typo in readpng2.c; fixed -pause usage description
40 - 2.02: fixed improper display of usage screen on PNG error(s); fixed
41 unexpected-EOF and file-read-error cases; fixed Trace() cut-and-
42 paste bugs
43 - 2.03: deleted runtime MMX-enabling/disabling and obsolete -mmx* options
44
45 ---------------------------------------------------------------------------
46
47 Copyright (c) 1998-2008 Greg Roelofs. All rights reserved.
48
49 This software is provided "as is," without warranty of any kind,
50 express or implied. In no event shall the author or contributors
51 be held liable for any damages arising in any way from the use of
52 this software.
53
54 The contents of this file are DUAL-LICENSED. You may modify and/or
55 redistribute this software according to the terms of one of the
56 following two licenses (at your option):
57
58
59 LICENSE 1 ("BSD-like with advertising clause"):
60
61 Permission is granted to anyone to use this software for any purpose,
62 including commercial applications, and to alter it and redistribute
63 it freely, subject to the following restrictions:
64
65 1. Redistributions of source code must retain the above copyright
66 notice, disclaimer, and this list of conditions.
67 2. Redistributions in binary form must reproduce the above copyright
68 notice, disclaimer, and this list of conditions in the documenta-
69 tion and/or other materials provided with the distribution.
70 3. All advertising materials mentioning features or use of this
71 software must display the following acknowledgment:
72
73 This product includes software developed by Greg Roelofs
74 and contributors for the book, "PNG: The Definitive Guide,"
75 published by O'Reilly and Associates.
76
77
78 LICENSE 2 (GNU GPL v2 or later):
79
80 This program is free software; you can redistribute it and/or modify
81 it under the terms of the GNU General Public License as published by
82 the Free Software Foundation; either version 2 of the License, or
83 (at your option) any later version.
84
85 This program is distributed in the hope that it will be useful,
86 but WITHOUT ANY WARRANTY; without even the implied warranty of
87 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88 GNU General Public License for more details.
89
90 You should have received a copy of the GNU General Public License
91 along with this program; if not, write to the Free Software Foundation,
92 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
93
94 ---------------------------------------------------------------------------*/
95
96#define PROGNAME "rpng2-x"
97#define LONGNAME "Progressive PNG Viewer for X"
98#define VERSION "2.03 of 25 February 2010"
99#define RESNAME "rpng2" /* our X resource application name */
100#define RESCLASS "Rpng" /* our X resource class name */
101
102#include <stdio.h>
103#include <stdlib.h>
104#include <ctype.h>
105#include <string.h>
106#include <setjmp.h> /* for jmpbuf declaration in readpng2.h */
107#include <time.h>
108#include <math.h> /* only for PvdM background code */
109#include <X11/Xlib.h>
110#include <X11/Xutil.h>
111#include <X11/Xos.h>
112#include <X11/keysym.h> /* defines XK_* macros */
113
114#ifdef VMS
115# include <unistd.h>
116#endif
117
118/* all for PvdM background code: */
119#ifndef PI
120# define PI 3.141592653589793238
121#endif
122#define PI_2 (PI*0.5)
123#define INV_PI_360 (360.0 / PI)
124#define MAX(a,b) (a>b?a:b)
125#define MIN(a,b) (a<b?a:b)
126#define CLIP(a,min,max) MAX(min,MIN((a),max))
127#define ABS(a) ((a)<0?-(a):(a))
128#define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */
129#define ROUNDF(f) ((int)(f + 0.5))
130
131#define QUIT(e,k) ((e.type == ButtonPress && e.xbutton.button == Button1) || \
132 (e.type == KeyPress && /* v--- or 1 for shifted keys */ \
133 ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape)))
134
135#define NO_24BIT_MASKS /* undef case not fully written--only for redisplay() */
136
137#define rgb1_max bg_freq
138#define rgb1_min bg_gray
139#define rgb2_max bg_bsat
140#define rgb2_min bg_brot
141
142/* #define DEBUG */ /* this enables the Trace() macros */
143
144#include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */
145
146
147/* could just include png.h, but this macro is the only thing we need
148 * (name and typedefs changed to local versions); note that side effects
149 * only happen with alpha (which could easily be avoided with
150 * "ush acopy = (alpha);") */
151
152#define alpha_composite(composite, fg, alpha, bg) { \
153 ush temp = ((ush)(fg)*(ush)(alpha) + \
154 (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \
155 (composite) = (uch)((temp + (temp >> 8)) >> 8); \
156}
157
158
159#define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this
160 * block size corresponds roughly to a download
161 * speed 10% faster than theoretical 33.6K maximum
162 * (assuming 8 data bits, 1 stop bit and no other
163 * overhead) */
164
165/* local prototypes */
166static void rpng2_x_init (void);
167static int rpng2_x_create_window (void);
168static int rpng2_x_load_bg_image (void);
169static void rpng2_x_display_row (ulg row);
170static void rpng2_x_finish_display (void);
171static void rpng2_x_redisplay_image (ulg startcol, ulg startrow,
172 ulg width, ulg height);
173#ifdef FEATURE_LOOP
174static void rpng2_x_reload_bg_image (void);
175static int is_number (char *p);
176#endif
177static void rpng2_x_cleanup (void);
178static int rpng2_x_msb (ulg u32val);
179
180
181static char titlebar[1024], *window_name = titlebar;
182static char *appname = LONGNAME;
183static char *icon_name = PROGNAME;
184static char *res_name = RESNAME;
185static char *res_class = RESCLASS;
186static char *filename;
187static FILE *infile;
188
189static mainprog_info rpng2_info;
190
191static uch inbuf[INBUFSIZE];
192static int incount;
193
194static int pat = 6; /* must be less than num_bgpat */
195static int bg_image = 0;
196static int bgscale, bgscale_default = 16;
197static ulg bg_rowbytes;
198static uch *bg_data;
199
200int pause_after_pass = FALSE;
201int demo_timing = FALSE;
202ulg usleep_duration = 0L;
203
204static struct rgb_color {
205 uch r, g, b;
206} rgb[] = {
207 { 0, 0, 0}, /* 0: black */
208 {255, 255, 255}, /* 1: white */
209 {173, 132, 57}, /* 2: tan */
210 { 64, 132, 0}, /* 3: medium green */
211 {189, 117, 1}, /* 4: gold */
212 {253, 249, 1}, /* 5: yellow */
213 { 0, 0, 255}, /* 6: blue */
214 { 0, 0, 120}, /* 7: medium blue */
215 {255, 0, 255}, /* 8: magenta */
216 { 64, 0, 64}, /* 9: dark magenta */
217 {255, 0, 0}, /* 10: red */
218 { 64, 0, 0}, /* 11: dark red */
219 {255, 127, 0}, /* 12: orange */
220 {192, 96, 0}, /* 13: darker orange */
221 { 24, 60, 0}, /* 14: dark green-yellow */
222 { 85, 125, 200}, /* 15: ice blue */
223 {192, 192, 192} /* 16: Netscape/Mosaic gray */
224};
225/* not used for now, but should be for error-checking:
226static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color);
227 */
228
229/*
230 This whole struct is a fairly cheesy way to keep the number of
231 command-line options to a minimum. The radial-waves background
232 type is a particularly poor fit to the integer elements of the
233 struct...but a few macros and a little fixed-point math will do
234 wonders for ya.
235
236 type bits:
237 F E D C B A 9 8 7 6 5 4 3 2 1 0
238 | | | | |
239 | | +-+-+-- 0 = sharp-edged checkerboard
240 | | 1 = soft diamonds
241 | | 2 = radial waves
242 | | 3-7 = undefined
243 | +-- gradient #2 inverted?
244 +-- alternating columns inverted?
245 */
246static struct background_pattern {
247 ush type;
248 int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */
249 int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/
250} bg[] = {
251 {0, 1,1, 16,16}, /* checkered: white vs. light gray (basic) */
252 {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */
253 {0+24, 2,0, 1,0}, /* checkered: tan/black vs. white/black */
254 {0+8, 4,5, 0,2}, /* checkered: gold/yellow vs. black/tan */
255 {0+8, 4,5, 0,6}, /* checkered: gold/yellow vs. black/blue */
256 {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */
257 {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */
258 {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */
259 {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */
260 {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */
261 {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */
262 {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */
263 {1, 3,0, 0,0}, /* diamonds: medium green vs. black */
264 {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */
265 {2, 18, 100, 10, 2}, /* radial: soft, curved radial color-beams */
266 {2, 16, 256, 100, 250}, /* radial: very tight spiral */
267 {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */
268};
269static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern);
270
271
272/* X-specific variables */
273static char *displayname;
274static XImage *ximage;
275static Display *display;
276static int depth;
277static Visual *visual;
278static XVisualInfo *visual_list;
279static int RShift, GShift, BShift;
280static ulg RMask, GMask, BMask;
281static Window window;
282static GC gc;
283static Colormap colormap;
284
285static int have_nondefault_visual = FALSE;
286static int have_colormap = FALSE;
287static int have_window = FALSE;
288static int have_gc = FALSE;
289
290
291
292
293int main(int argc, char **argv)
294{
295#ifdef sgi
296 char tmpline[80];
297#endif
298 char *p, *bgstr = NULL;
299 int rc, alen, flen;
300 int error = 0;
301 int timing = FALSE;
302 int have_bg = FALSE;
303#ifdef FEATURE_LOOP
304 int loop = FALSE;
305 long loop_interval = -1; /* seconds (100,000 max) */
306#endif
307 double LUT_exponent; /* just the lookup table */
308 double CRT_exponent = 2.2; /* just the monitor */
309 double default_display_exponent; /* whole display system */
310 XEvent e;
311 KeySym k;
312
313
314 /* First initialize a few things, just to be sure--memset takes care of
315 * default background color (black), booleans (FALSE), pointers (NULL),
316 * etc. */
317
318 displayname = (char *)NULL;
319 filename = (char *)NULL;
320 memset(&rpng2_info, 0, sizeof(mainprog_info));
321
322
323 /* Set the default value for our display-system exponent, i.e., the
324 * product of the CRT exponent and the exponent corresponding to
325 * the frame-buffer's lookup table (LUT), if any. This is not an
326 * exhaustive list of LUT values (e.g., OpenStep has a lot of weird
327 * ones), but it should cover 99% of the current possibilities. */
328
329#if defined(NeXT)
330 /* third-party utilities can modify the default LUT exponent */
331 LUT_exponent = 1.0 / 2.2;
332 /*
333 if (some_next_function_that_returns_gamma(&next_gamma))
334 LUT_exponent = 1.0 / next_gamma;
335 */
336#elif defined(sgi)
337 LUT_exponent = 1.0 / 1.7;
338 /* there doesn't seem to be any documented function to
339 * get the "gamma" value, so we do it the hard way */
340 infile = fopen("/etc/config/system.glGammaVal", "r");
341 if (infile) {
342 double sgi_gamma;
343
344 fgets(tmpline, 80, infile);
345 fclose(infile);
346 sgi_gamma = atof(tmpline);
347 if (sgi_gamma > 0.0)
348 LUT_exponent = 1.0 / sgi_gamma;
349 }
350#elif defined(Macintosh)
351 LUT_exponent = 1.8 / 2.61;
352 /*
353 if (some_mac_function_that_returns_gamma(&mac_gamma))
354 LUT_exponent = mac_gamma / 2.61;
355 */
356#else
357 LUT_exponent = 1.0; /* assume no LUT: most PCs */
358#endif
359
360 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
361 default_display_exponent = LUT_exponent * CRT_exponent;
362
363
364 /* If the user has set the SCREEN_GAMMA environment variable as suggested
365 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
366 * use the default value we just calculated. Either way, the user may
367 * override this via a command-line option. */
368
369 if ((p = getenv("SCREEN_GAMMA")) != NULL)
370 rpng2_info.display_exponent = atof(p);
371 else
372 rpng2_info.display_exponent = default_display_exponent;
373
374
375 /* Now parse the command line for options and the PNG filename. */
376
377 while (*++argv && !error) {
378 if (!strncmp(*argv, "-display", 2)) {
379 if (!*++argv)
380 ++error;
381 else
382 displayname = *argv;
383 } else if (!strncmp(*argv, "-gamma", 2)) {
384 if (!*++argv)
385 ++error;
386 else {
387 rpng2_info.display_exponent = atof(*argv);
388 if (rpng2_info.display_exponent <= 0.0)
389 ++error;
390 }
391 } else if (!strncmp(*argv, "-bgcolor", 4)) {
392 if (!*++argv)
393 ++error;
394 else {
395 bgstr = *argv;
396 if (strlen(bgstr) != 7 || bgstr[0] != '#')
397 ++error;
398 else {
399 have_bg = TRUE;
400 bg_image = FALSE;
401 }
402 }
403 } else if (!strncmp(*argv, "-bgpat", 4)) {
404 if (!*++argv)
405 ++error;
406 else {
407 pat = atoi(*argv);
408 if (pat >= 0 && pat < num_bgpat) {
409 bg_image = TRUE;
410 have_bg = FALSE;
411 } else
412 ++error;
413 }
414 } else if (!strncmp(*argv, "-usleep", 2)) {
415 if (!*++argv)
416 ++error;
417 else {
418 usleep_duration = (ulg)atol(*argv);
419 demo_timing = TRUE;
420 }
421 } else if (!strncmp(*argv, "-pause", 2)) {
422 pause_after_pass = TRUE;
423 } else if (!strncmp(*argv, "-timing", 2)) {
424 timing = TRUE;
425#ifdef FEATURE_LOOP
426 } else if (!strncmp(*argv, "-loop", 2)) {
427 loop = TRUE;
428 if (!argv[1] || !is_number(argv[1]))
429 loop_interval = 2;
430 else {
431 ++argv;
432 loop_interval = atol(*argv);
433 if (loop_interval < 0)
434 loop_interval = 2;
435 else if (loop_interval > 100000) /* bit more than one day */
436 loop_interval = 100000;
437 }
438#endif
439 } else {
440 if (**argv != '-') {
441 filename = *argv;
442 if (argv[1]) /* shouldn't be any more args after filename */
443 ++error;
444 } else
445 ++error; /* not expecting any other options */
446 }
447 }
448
449 if (!filename)
450 ++error;
451
452
453 /* print usage screen if any errors up to this point */
454
455 if (error) {
456 fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname);
457 readpng2_version_info();
458 fprintf(stderr, "\n"
459 "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n"
460#ifdef FEATURE_LOOP
461 " %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n"
462#else
463 " %*s [-usleep dur | -timing] [-pause] file.png\n\n"
464#endif
465 " xdpy\tname of the target X display (e.g., ``hostname:0'')\n"
466 " exp \ttransfer-function exponent (``gamma'') of the display\n"
467 "\t\t system in floating-point format (e.g., ``%.1f''); equal\n"
468 "\t\t to the product of the lookup-table exponent (varies)\n"
469 "\t\t and the CRT exponent (usually 2.2); must be positive\n"
470 " bg \tdesired background color in 7-character hex RGB format\n"
471 "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n"
472 "\t\t used with transparent images; overrides -bgpat\n"
473 " pat \tdesired background pattern number (0-%d); used with\n"
474 "\t\t transparent images; overrides -bgcolor\n"
475#ifdef FEATURE_LOOP
476 " -loop\tloops through background images after initial display\n"
477 "\t\t is complete (depends on -bgpat)\n"
478 " sec \tseconds to display each background image (default = 2)\n"
479#endif
480 " dur \tduration in microseconds to wait after displaying each\n"
481 "\t\t row (for demo purposes)\n"
482 " -timing\tenables delay for every block read, to simulate modem\n"
483 "\t\t download of image (~36 Kbps)\n"
484 " -pause\tpauses after displaying each pass until mouse clicked\n"
485 "\nPress Q, Esc or mouse button 1 (within image window, after image\n"
486 "is displayed) to quit.\n"
487 "\n", PROGNAME,
488 (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1);
489 exit(1);
490 }
491
492
493 if (!(infile = fopen(filename, "rb"))) {
494 fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename);
495 ++error;
496 } else {
497 incount = fread(inbuf, 1, INBUFSIZE, infile);
498 if (incount < 8 || !readpng2_check_sig(inbuf, 8)) {
499 fprintf(stderr, PROGNAME
500 ": [%s] is not a PNG file: incorrect signature\n",
501 filename);
502 ++error;
503 } else if ((rc = readpng2_init(&rpng2_info)) != 0) {
504 switch (rc) {
505 case 2:
506 fprintf(stderr, PROGNAME
507 ": [%s] has bad IHDR (libpng longjmp)\n", filename);
508 break;
509 case 4:
510 fprintf(stderr, PROGNAME ": insufficient memory\n");
511 break;
512 default:
513 fprintf(stderr, PROGNAME
514 ": unknown readpng2_init() error\n");
515 break;
516 }
517 ++error;
518 } else {
519 Trace((stderr, "about to call XOpenDisplay()\n"))
520 display = XOpenDisplay(displayname);
521 if (!display) {
522 readpng2_cleanup(&rpng2_info);
523 fprintf(stderr, PROGNAME ": can't open X display [%s]\n",
524 displayname? displayname : "default");
525 ++error;
526 }
527 }
528 if (error)
529 fclose(infile);
530 }
531
532
533 if (error) {
534 fprintf(stderr, PROGNAME ": aborting.\n");
535 exit(2);
536 }
537
538
539 /* set the title-bar string, but make sure buffer doesn't overflow */
540
541 alen = strlen(appname);
542 flen = strlen(filename);
543 if (alen + flen + 3 > 1023)
544 sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023));
545 else
546 sprintf(titlebar, "%s: %s", appname, filename);
547
548
549 /* set some final rpng2_info variables before entering main data loop */
550
551 if (have_bg) {
552 unsigned r, g, b; /* this approach quiets compiler warnings */
553
554 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
555 rpng2_info.bg_red = (uch)r;
556 rpng2_info.bg_green = (uch)g;
557 rpng2_info.bg_blue = (uch)b;
558 } else
559 rpng2_info.need_bgcolor = TRUE;
560
561 rpng2_info.state = kPreInit;
562 rpng2_info.mainprog_init = rpng2_x_init;
563 rpng2_info.mainprog_display_row = rpng2_x_display_row;
564 rpng2_info.mainprog_finish_display = rpng2_x_finish_display;
565
566
567 /* OK, this is the fun part: call readpng2_decode_data() at the start of
568 * the loop to deal with our first buffer of data (read in above to verify
569 * that the file is a PNG image), then loop through the file and continue
570 * calling the same routine to handle each chunk of data. It in turn
571 * passes the data to libpng, which will invoke one or more of our call-
572 * backs as decoded data become available. We optionally call sleep() for
573 * one second per iteration to simulate downloading the image via an analog
574 * modem. */
575
576 for (;;) {
577 Trace((stderr, "about to call readpng2_decode_data()\n"))
578 if (readpng2_decode_data(&rpng2_info, inbuf, incount))
579 ++error;
580 Trace((stderr, "done with readpng2_decode_data()\n"))
581
582 if (error || incount != INBUFSIZE || rpng2_info.state == kDone) {
583 if (rpng2_info.state == kDone) {
584 Trace((stderr, "done decoding PNG image\n"))
585 } else if (ferror(infile)) {
586 fprintf(stderr, PROGNAME
587 ": error while reading PNG image file\n");
588 exit(3);
589 } else if (feof(infile)) {
590 fprintf(stderr, PROGNAME ": end of file reached "
591 "(unexpectedly) while reading PNG image file\n");
592 exit(3);
593 } else /* if (error) */ {
594 /* will print error message below */
595 }
596 break;
597 }
598
599 if (timing)
600 sleep(1);
601
602 incount = fread(inbuf, 1, INBUFSIZE, infile);
603 }
604
605
606 /* clean up PNG stuff and report any decoding errors */
607
608 fclose(infile);
609 Trace((stderr, "about to call readpng2_cleanup()\n"))
610 readpng2_cleanup(&rpng2_info);
611
612 if (error) {
613 fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n");
614 exit(3);
615 }
616
617
618#ifdef FEATURE_LOOP
619
620 if (loop && bg_image) {
621 Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n"))
622 for (;;) {
623 int i, use_sleep;
624 struct timeval now, then;
625
626 /* get current time and add loop_interval to get target time */
627 if (gettimeofday(&then, NULL) == 0) {
628 then.tv_sec += loop_interval;
629 use_sleep = FALSE;
630 } else
631 use_sleep = TRUE;
632
633 /* do quick check for a quit event but don't wait for it */
634 /* GRR BUG: should also check for Expose events and redraw... */
635 if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e))
636 if (QUIT(e,k))
637 break;
638
639 /* generate next background image */
640 if (++pat >= num_bgpat)
641 pat = 0;
642 rpng2_x_reload_bg_image();
643
644 /* wait for timeout, using whatever means are available */
645 if (use_sleep || gettimeofday(&now, NULL) != 0) {
646 for (i = loop_interval; i > 0; --i) {
647 sleep(1);
648 /* GRR BUG: also need to check for Expose (and redraw!) */
649 if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask,
650 &e) && QUIT(e,k))
651 break;
652 }
653 } else {
654 /* Y2038 BUG! */
655 if (now.tv_sec < then.tv_sec ||
656 (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec))
657 {
658 int quit = FALSE;
659 long seconds_to_go = then.tv_sec - now.tv_sec;
660 long usleep_usec;
661
662 /* basically chew up most of remaining loop-interval with
663 * calls to sleep(1) interleaved with checks for quit
664 * events, but also recalc time-to-go periodically; when
665 * done, clean up any remaining time with usleep() call
666 * (could also use SIGALRM, but signals are a pain...) */
667 while (seconds_to_go-- > 1) {
668 int seconds_done = 0;
669
670 for (i = seconds_to_go; i > 0 && !quit; --i) {
671 sleep(1);
672 /* GRR BUG: need to check for Expose and redraw */
673 if (XCheckMaskEvent(display, KeyPressMask |
674 ButtonPressMask, &e) && QUIT(e,k))
675 quit = TRUE;
676 if (++seconds_done > 1000)
677 break; /* time to redo seconds_to_go meas. */
678 }
679 if (quit)
680 break;
681
682 /* OK, more than 1000 seconds since last check:
683 * correct the time-to-go measurement for drift */
684 if (gettimeofday(&now, NULL) == 0) {
685 if (now.tv_sec >= then.tv_sec)
686 break;
687 seconds_to_go = then.tv_sec - now.tv_sec;
688 } else
689 ++seconds_to_go; /* restore what we subtracted */
690 }
691 if (quit)
692 break; /* breaks outer do-loop, skips redisplay */
693
694 /* since difference between "now" and "then" is already
695 * eaten up to within a couple of seconds, don't need to
696 * worry about overflow--but might have overshot (neg.) */
697 if (gettimeofday(&now, NULL) == 0) {
698 usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) +
699 then.tv_usec - now.tv_usec;
700 if (usleep_usec > 0)
701 usleep((ulg)usleep_usec);
702 }
703 }
704 }
705
706 /* composite image against new background and display (note that
707 * we do not take into account the time spent doing this...) */
708 rpng2_x_redisplay_image (0, 0, rpng2_info.width, rpng2_info.height);
709 }
710
711 } else /* FALL THROUGH and do the normal thing */
712
713#endif /* FEATURE_LOOP */
714
715 /* wait for the user to tell us when to quit */
716
717 if (rpng2_info.state >= kWindowInit) {
718 Trace((stderr, "entering final wait-for-quit-event loop\n"))
719 do {
720 XNextEvent(display, &e);
721 if (e.type == Expose) {
722 XExposeEvent *ex = (XExposeEvent *)&e;
723 rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height);
724 }
725 } while (!QUIT(e,k));
726 } else {
727 fprintf(stderr, PROGNAME ": init callback never called: probable "
728 "libpng error while decoding PNG metadata\n");
729 exit(4);
730 }
731
732
733 /* we're done: clean up all image and X resources and go away */
734
735 Trace((stderr, "about to call rpng2_x_cleanup()\n"))
736 rpng2_x_cleanup();
737
738 return 0;
739}
740
741
742
743
744
745/* this function is called by readpng2_info_callback() in readpng2.c, which
746 * in turn is called by libpng after all of the pre-IDAT chunks have been
747 * read and processed--i.e., we now have enough info to finish initializing */
748
749static void rpng2_x_init(void)
750{
751 ulg i;
752 ulg rowbytes = rpng2_info.rowbytes;
753
754 Trace((stderr, "beginning rpng2_x_init()\n"))
755 Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes))
756 Trace((stderr, " width = %ld\n", rpng2_info.width))
757 Trace((stderr, " height = %ld\n", rpng2_info.height))
758
759 rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);
760 if (!rpng2_info.image_data) {
761 readpng2_cleanup(&rpng2_info);
762 return;
763 }
764
765 rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));
766 if (!rpng2_info.row_pointers) {
767 free(rpng2_info.image_data);
768 rpng2_info.image_data = NULL;
769 readpng2_cleanup(&rpng2_info);
770 return;
771 }
772
773 for (i = 0; i < rpng2_info.height; ++i)
774 rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;
775
776
777 /* do the basic X initialization stuff, make the window, and fill it with
778 * the user-specified, file-specified or default background color or
779 * pattern */
780
781 if (rpng2_x_create_window()) {
782
783 /* GRR TEMPORARY HACK: this is fundamentally no different from cases
784 * above; libpng should call our error handler to longjmp() back to us
785 * when png_ptr goes away. If we/it segfault instead, seems like a
786 * libpng bug... */
787
788 /* we're here via libpng callback, so if window fails, clean and bail */
789 readpng2_cleanup(&rpng2_info);
790 rpng2_x_cleanup();
791 exit(2);
792 }
793
794 rpng2_info.state = kWindowInit;
795}
796
797
798
799
800
801static int rpng2_x_create_window(void)
802{
803 ulg bg_red = rpng2_info.bg_red;
804 ulg bg_green = rpng2_info.bg_green;
805 ulg bg_blue = rpng2_info.bg_blue;
806 ulg bg_pixel = 0L;
807 ulg attrmask;
808 int need_colormap = FALSE;
809 int screen, pad;
810 uch *xdata;
811 Window root;
812 XEvent e;
813 XGCValues gcvalues;
814 XSetWindowAttributes attr;
815 XTextProperty windowName, *pWindowName = &windowName;
816 XTextProperty iconName, *pIconName = &iconName;
817 XVisualInfo visual_info;
818 XSizeHints *size_hints;
819 XWMHints *wm_hints;
820 XClassHint *class_hints;
821
822
823 Trace((stderr, "beginning rpng2_x_create_window()\n"))
824
825 screen = DefaultScreen(display);
826 depth = DisplayPlanes(display, screen);
827 root = RootWindow(display, screen);
828
829#ifdef DEBUG
830 XSynchronize(display, True);
831#endif
832
833 if (depth != 16 && depth != 24 && depth != 32) {
834 int visuals_matched = 0;
835
836 Trace((stderr, "default depth is %d: checking other visuals\n",
837 depth))
838
839 /* 24-bit first */
840 visual_info.screen = screen;
841 visual_info.depth = 24;
842 visual_list = XGetVisualInfo(display,
843 VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);
844 if (visuals_matched == 0) {
845/* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */
846 fprintf(stderr, "default screen depth %d not supported, and no"
847 " 24-bit visuals found\n", depth);
848 return 2;
849 }
850 Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n",
851 visuals_matched))
852 visual = visual_list[0].visual;
853 depth = visual_list[0].depth;
854/*
855 colormap_size = visual_list[0].colormap_size;
856 visual_class = visual->class;
857 visualID = XVisualIDFromVisual(visual);
858 */
859 have_nondefault_visual = TRUE;
860 need_colormap = TRUE;
861 } else {
862 XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);
863 visual = visual_info.visual;
864 }
865
866 RMask = visual->red_mask;
867 GMask = visual->green_mask;
868 BMask = visual->blue_mask;
869
870/* GRR: add/check 8-bit support */
871 if (depth == 8 || need_colormap) {
872 colormap = XCreateColormap(display, root, visual, AllocNone);
873 if (!colormap) {
874 fprintf(stderr, "XCreateColormap() failed\n");
875 return 2;
876 }
877 have_colormap = TRUE;
878 if (depth == 8)
879 bg_image = FALSE; /* gradient just wastes palette entries */
880 }
881 if (depth == 15 || depth == 16) {
882 RShift = 15 - rpng2_x_msb(RMask); /* these are right-shifts */
883 GShift = 15 - rpng2_x_msb(GMask);
884 BShift = 15 - rpng2_x_msb(BMask);
885 } else if (depth > 16) {
886 RShift = rpng2_x_msb(RMask) - 7; /* these are left-shifts */
887 GShift = rpng2_x_msb(GMask) - 7;
888 BShift = rpng2_x_msb(BMask) - 7;
889 }
890 if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {
891 fprintf(stderr, "rpng2 internal logic error: negative X shift(s)!\n");
892 return 2;
893 }
894
895/*---------------------------------------------------------------------------
896 Finally, create the window.
897 ---------------------------------------------------------------------------*/
898
899 attr.backing_store = Always;
900 attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;
901 attrmask = CWBackingStore | CWEventMask;
902 if (have_nondefault_visual) {
903 attr.colormap = colormap;
904 attr.background_pixel = 0;
905 attr.border_pixel = 1;
906 attrmask |= CWColormap | CWBackPixel | CWBorderPixel;
907 }
908
909 window = XCreateWindow(display, root, 0, 0, rpng2_info.width,
910 rpng2_info.height, 0, depth, InputOutput, visual, attrmask, &attr);
911
912 if (window == None) {
913 fprintf(stderr, "XCreateWindow() failed\n");
914 return 2;
915 } else
916 have_window = TRUE;
917
918 if (depth == 8)
919 XSetWindowColormap(display, window, colormap);
920
921 if (!XStringListToTextProperty(&window_name, 1, pWindowName))
922 pWindowName = NULL;
923 if (!XStringListToTextProperty(&icon_name, 1, pIconName))
924 pIconName = NULL;
925
926 /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */
927
928 if ((size_hints = XAllocSizeHints()) != NULL) {
929 /* window will not be resizable */
930 size_hints->flags = PMinSize | PMaxSize;
931 size_hints->min_width = size_hints->max_width = (int)rpng2_info.width;
932 size_hints->min_height = size_hints->max_height =
933 (int)rpng2_info.height;
934 }
935
936 if ((wm_hints = XAllocWMHints()) != NULL) {
937 wm_hints->initial_state = NormalState;
938 wm_hints->input = True;
939 /* wm_hints->icon_pixmap = icon_pixmap; */
940 wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ;
941 }
942
943 if ((class_hints = XAllocClassHint()) != NULL) {
944 class_hints->res_name = res_name;
945 class_hints->res_class = res_class;
946 }
947
948 XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,
949 size_hints, wm_hints, class_hints);
950
951 /* various properties and hints no longer needed; free memory */
952 if (pWindowName)
953 XFree(pWindowName->value);
954 if (pIconName)
955 XFree(pIconName->value);
956 if (size_hints)
957 XFree(size_hints);
958 if (wm_hints)
959 XFree(wm_hints);
960 if (class_hints)
961 XFree(class_hints);
962
963 XMapWindow(display, window);
964
965 gc = XCreateGC(display, window, 0, &gcvalues);
966 have_gc = TRUE;
967
968/*---------------------------------------------------------------------------
969 Allocate memory for the X- and display-specific version of the image.
970 ---------------------------------------------------------------------------*/
971
972 if (depth == 24 || depth == 32) {
973 xdata = (uch *)malloc(4*rpng2_info.width*rpng2_info.height);
974 pad = 32;
975 } else if (depth == 16) {
976 xdata = (uch *)malloc(2*rpng2_info.width*rpng2_info.height);
977 pad = 16;
978 } else /* depth == 8 */ {
979 xdata = (uch *)malloc(rpng2_info.width*rpng2_info.height);
980 pad = 8;
981 }
982
983 if (!xdata) {
984 fprintf(stderr, PROGNAME ": unable to allocate image memory\n");
985 return 4;
986 }
987
988 ximage = XCreateImage(display, visual, depth, ZPixmap, 0,
989 (char *)xdata, rpng2_info.width, rpng2_info.height, pad, 0);
990
991 if (!ximage) {
992 fprintf(stderr, PROGNAME ": XCreateImage() failed\n");
993 free(xdata);
994 return 3;
995 }
996
997 /* to avoid testing the byte order every pixel (or doubling the size of
998 * the drawing routine with a giant if-test), we arbitrarily set the byte
999 * order to MSBFirst and let Xlib worry about inverting things on little-
1000 * endian machines (e.g., Linux/x86, old VAXen, etc.)--this is not the
1001 * most efficient approach (the giant if-test would be better), but in
1002 * the interest of clarity, we'll take the easy way out... */
1003
1004 ximage->byte_order = MSBFirst;
1005
1006/*---------------------------------------------------------------------------
1007 Fill window with the specified background color (default is black) or
1008 faked "background image" (but latter is disabled if 8-bit; gradients
1009 just waste palette entries).
1010 ---------------------------------------------------------------------------*/
1011
1012 if (bg_image)
1013 rpng2_x_load_bg_image(); /* resets bg_image if fails */
1014
1015 if (!bg_image) {
1016 if (depth == 24 || depth == 32) {
1017 bg_pixel = (bg_red << RShift) |
1018 (bg_green << GShift) |
1019 (bg_blue << BShift);
1020 } else if (depth == 16) {
1021 bg_pixel = (((bg_red << 8) >> RShift) & RMask) |
1022 (((bg_green << 8) >> GShift) & GMask) |
1023 (((bg_blue << 8) >> BShift) & BMask);
1024 } else /* depth == 8 */ {
1025
1026 /* GRR: add 8-bit support */
1027
1028 }
1029 XSetForeground(display, gc, bg_pixel);
1030 XFillRectangle(display, window, gc, 0, 0, rpng2_info.width,
1031 rpng2_info.height);
1032 }
1033
1034/*---------------------------------------------------------------------------
1035 Wait for first Expose event to do any drawing, then flush and return.
1036 ---------------------------------------------------------------------------*/
1037
1038 do
1039 XNextEvent(display, &e);
1040 while (e.type != Expose || e.xexpose.count);
1041
1042 XFlush(display);
1043
1044 return 0;
1045
1046} /* end function rpng2_x_create_window() */
1047
1048
1049
1050
1051
1052static int rpng2_x_load_bg_image(void)
1053{
1054 uch *src;
1055 char *dest;
1056 uch r1, r2, g1, g2, b1, b2;
1057 uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
1058 int k, hmax, max;
1059 int xidx, yidx, yidx_max;
1060 int even_odd_vert, even_odd_horiz, even_odd;
1061 int invert_gradient2 = (bg[pat].type & 0x08);
1062 int invert_column;
1063 int ximage_rowbytes = ximage->bytes_per_line;
1064 ulg i, row;
1065 ulg pixel;
1066
1067/*---------------------------------------------------------------------------
1068 Allocate buffer for fake background image to be used with transparent
1069 images; if this fails, revert to plain background color.
1070 ---------------------------------------------------------------------------*/
1071
1072 bg_rowbytes = 3 * rpng2_info.width;
1073 bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);
1074 if (!bg_data) {
1075 fprintf(stderr, PROGNAME
1076 ": unable to allocate memory for background image\n");
1077 bg_image = 0;
1078 return 1;
1079 }
1080
1081 bgscale = (pat == 0)? 8 : bgscale_default;
1082 yidx_max = bgscale - 1;
1083
1084/*---------------------------------------------------------------------------
1085 Vertical gradients (ramps) in NxN squares, alternating direction and
1086 colors (N == bgscale).
1087 ---------------------------------------------------------------------------*/
1088
1089 if ((bg[pat].type & 0x07) == 0) {
1090 uch r1_min = rgb[bg[pat].rgb1_min].r;
1091 uch g1_min = rgb[bg[pat].rgb1_min].g;
1092 uch b1_min = rgb[bg[pat].rgb1_min].b;
1093 uch r2_min = rgb[bg[pat].rgb2_min].r;
1094 uch g2_min = rgb[bg[pat].rgb2_min].g;
1095 uch b2_min = rgb[bg[pat].rgb2_min].b;
1096 int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
1097 int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
1098 int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
1099 int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
1100 int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
1101 int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
1102
1103 for (row = 0; row < rpng2_info.height; ++row) {
1104 yidx = (int)(row % bgscale);
1105 even_odd_vert = (int)((row / bgscale) & 1);
1106
1107 r1 = r1_min + (r1_diff * yidx) / yidx_max;
1108 g1 = g1_min + (g1_diff * yidx) / yidx_max;
1109 b1 = b1_min + (b1_diff * yidx) / yidx_max;
1110 r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
1111 g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
1112 b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
1113
1114 r2 = r2_min + (r2_diff * yidx) / yidx_max;
1115 g2 = g2_min + (g2_diff * yidx) / yidx_max;
1116 b2 = b2_min + (b2_diff * yidx) / yidx_max;
1117 r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
1118 g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
1119 b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
1120
1121 dest = (char *)bg_data + row*bg_rowbytes;
1122 for (i = 0; i < rpng2_info.width; ++i) {
1123 even_odd_horiz = (int)((i / bgscale) & 1);
1124 even_odd = even_odd_vert ^ even_odd_horiz;
1125 invert_column =
1126 (even_odd_horiz && (bg[pat].type & 0x10));
1127 if (even_odd == 0) { /* gradient #1 */
1128 if (invert_column) {
1129 *dest++ = r1_inv;
1130 *dest++ = g1_inv;
1131 *dest++ = b1_inv;
1132 } else {
1133 *dest++ = r1;
1134 *dest++ = g1;
1135 *dest++ = b1;
1136 }
1137 } else { /* gradient #2 */
1138 if ((invert_column && invert_gradient2) ||
1139 (!invert_column && !invert_gradient2))
1140 {
1141 *dest++ = r2; /* not inverted or */
1142 *dest++ = g2; /* doubly inverted */
1143 *dest++ = b2;
1144 } else {
1145 *dest++ = r2_inv;
1146 *dest++ = g2_inv; /* singly inverted */
1147 *dest++ = b2_inv;
1148 }
1149 }
1150 }
1151 }
1152
1153/*---------------------------------------------------------------------------
1154 Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
1155 M. Costello.
1156 ---------------------------------------------------------------------------*/
1157
1158 } else if ((bg[pat].type & 0x07) == 1) {
1159
1160 hmax = (bgscale-1)/2; /* half the max weight of a color */
1161 max = 2*hmax; /* the max weight of a color */
1162
1163 r1 = rgb[bg[pat].rgb1_max].r;
1164 g1 = rgb[bg[pat].rgb1_max].g;
1165 b1 = rgb[bg[pat].rgb1_max].b;
1166 r2 = rgb[bg[pat].rgb2_max].r;
1167 g2 = rgb[bg[pat].rgb2_max].g;
1168 b2 = rgb[bg[pat].rgb2_max].b;
1169
1170 for (row = 0; row < rpng2_info.height; ++row) {
1171 yidx = (int)(row % bgscale);
1172 if (yidx > hmax)
1173 yidx = bgscale-1 - yidx;
1174 dest = (char *)bg_data + row*bg_rowbytes;
1175 for (i = 0; i < rpng2_info.width; ++i) {
1176 xidx = (int)(i % bgscale);
1177 if (xidx > hmax)
1178 xidx = bgscale-1 - xidx;
1179 k = xidx + yidx;
1180 *dest++ = (k*r1 + (max-k)*r2) / max;
1181 *dest++ = (k*g1 + (max-k)*g2) / max;
1182 *dest++ = (k*b1 + (max-k)*b2) / max;
1183 }
1184 }
1185
1186/*---------------------------------------------------------------------------
1187 Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
1188 soids will equal bgscale?]. This one is slow but very cool. Code con-
1189 tributed by Pieter S. van der Meulen (originally in Smalltalk).
1190 ---------------------------------------------------------------------------*/
1191
1192 } else if ((bg[pat].type & 0x07) == 2) {
1193 uch ch;
1194 int ii, x, y, hw, hh, grayspot;
1195 double freq, rotate, saturate, gray, intensity;
1196 double angle=0.0, aoffset=0.0, maxDist, dist;
1197 double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
1198
1199 fprintf(stderr, "%s: computing radial background...",
1200 PROGNAME);
1201 fflush(stderr);
1202
1203 hh = (int)(rpng2_info.height / 2);
1204 hw = (int)(rpng2_info.width / 2);
1205
1206 /* variables for radial waves:
1207 * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
1208 * freq: number of color beams originating from the center
1209 * grayspot: size of the graying center area (anti-alias)
1210 * rotate: rotation of the beams as a function of radius
1211 * saturate: saturation of beams' shape azimuthally
1212 */
1213 angle = CLIP(angle, 0.0, 360.0);
1214 grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
1215 freq = MAX((double)bg[pat].bg_freq, 0.0);
1216 saturate = (double)bg[pat].bg_bsat * 0.1;
1217 rotate = (double)bg[pat].bg_brot * 0.1;
1218 gray = 0.0;
1219 intensity = 0.0;
1220 maxDist = (double)((hw*hw) + (hh*hh));
1221
1222 for (row = 0; row < rpng2_info.height; ++row) {
1223 y = (int)(row - hh);
1224 dest = (char *)bg_data + row*bg_rowbytes;
1225 for (i = 0; i < rpng2_info.width; ++i) {
1226 x = (int)(i - hw);
1227 angle = (x == 0)? PI_2 : atan((double)y / (double)x);
1228 gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
1229 gray = MIN(1.0, gray);
1230 dist = (double)((x*x) + (y*y)) / maxDist;
1231 intensity = cos((angle+(rotate*dist*PI)) * freq) *
1232 gray * saturate;
1233 intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
1234 hue = (angle + PI) * INV_PI_360 + aoffset;
1235 s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
1236 s = MIN(MAX(s,0.0), 1.0);
1237 v = MIN(MAX(intensity,0.0), 1.0);
1238
1239 if (s == 0.0) {
1240 ch = (uch)(v * 255.0);
1241 *dest++ = ch;
1242 *dest++ = ch;
1243 *dest++ = ch;
1244 } else {
1245 if ((hue < 0.0) || (hue >= 360.0))
1246 hue -= (((int)(hue / 360.0)) * 360.0);
1247 hue /= 60.0;
1248 ii = (int)hue;
1249 f = hue - (double)ii;
1250 p = (1.0 - s) * v;
1251 q = (1.0 - (s * f)) * v;
1252 t = (1.0 - (s * (1.0 - f))) * v;
1253 if (ii == 0) { red = v; green = t; blue = p; }
1254 else if (ii == 1) { red = q; green = v; blue = p; }
1255 else if (ii == 2) { red = p; green = v; blue = t; }
1256 else if (ii == 3) { red = p; green = q; blue = v; }
1257 else if (ii == 4) { red = t; green = p; blue = v; }
1258 else if (ii == 5) { red = v; green = p; blue = q; }
1259 *dest++ = (uch)(red * 255.0);
1260 *dest++ = (uch)(green * 255.0);
1261 *dest++ = (uch)(blue * 255.0);
1262 }
1263 }
1264 }
1265 fprintf(stderr, "done.\n");
1266 fflush(stderr);
1267 }
1268
1269/*---------------------------------------------------------------------------
1270 Blast background image to display buffer before beginning PNG decode.
1271 ---------------------------------------------------------------------------*/
1272
1273 if (depth == 24 || depth == 32) {
1274 ulg red, green, blue;
1275 int bpp = ximage->bits_per_pixel;
1276
1277 for (row = 0; row < rpng2_info.height; ++row) {
1278 src = bg_data + row*bg_rowbytes;
1279 dest = ximage->data + row*ximage_rowbytes;
1280 if (bpp == 32) { /* slightly optimized version */
1281 for (i = rpng2_info.width; i > 0; --i) {
1282 red = *src++;
1283 green = *src++;
1284 blue = *src++;
1285 pixel = (red << RShift) |
1286 (green << GShift) |
1287 (blue << BShift);
1288 /* recall that we set ximage->byte_order = MSBFirst above */
1289 *dest++ = (char)((pixel >> 24) & 0xff);
1290 *dest++ = (char)((pixel >> 16) & 0xff);
1291 *dest++ = (char)((pixel >> 8) & 0xff);
1292 *dest++ = (char)( pixel & 0xff);
1293 }
1294 } else {
1295 for (i = rpng2_info.width; i > 0; --i) {
1296 red = *src++;
1297 green = *src++;
1298 blue = *src++;
1299 pixel = (red << RShift) |
1300 (green << GShift) |
1301 (blue << BShift);
1302 /* recall that we set ximage->byte_order = MSBFirst above */
1303 /* GRR BUG? this assumes bpp == 24 & bits are packed low */
1304 /* (probably need to use RShift, RMask, etc.) */
1305 *dest++ = (char)((pixel >> 16) & 0xff);
1306 *dest++ = (char)((pixel >> 8) & 0xff);
1307 *dest++ = (char)( pixel & 0xff);
1308 }
1309 }
1310 }
1311
1312 } else if (depth == 16) {
1313 ush red, green, blue;
1314
1315 for (row = 0; row < rpng2_info.height; ++row) {
1316 src = bg_data + row*bg_rowbytes;
1317 dest = ximage->data + row*ximage_rowbytes;
1318 for (i = rpng2_info.width; i > 0; --i) {
1319 red = ((ush)(*src) << 8); ++src;
1320 green = ((ush)(*src) << 8); ++src;
1321 blue = ((ush)(*src) << 8); ++src;
1322 pixel = ((red >> RShift) & RMask) |
1323 ((green >> GShift) & GMask) |
1324 ((blue >> BShift) & BMask);
1325 /* recall that we set ximage->byte_order = MSBFirst above */
1326 *dest++ = (char)((pixel >> 8) & 0xff);
1327 *dest++ = (char)( pixel & 0xff);
1328 }
1329 }
1330
1331 } else /* depth == 8 */ {
1332
1333 /* GRR: add 8-bit support */
1334
1335 }
1336
1337 XPutImage(display, window, gc, ximage, 0, 0, 0, 0, rpng2_info.width,
1338 rpng2_info.height);
1339
1340 return 0;
1341
1342} /* end function rpng2_x_load_bg_image() */
1343
1344
1345
1346
1347
1348static void rpng2_x_display_row(ulg row)
1349{
1350 uch bg_red = rpng2_info.bg_red;
1351 uch bg_green = rpng2_info.bg_green;
1352 uch bg_blue = rpng2_info.bg_blue;
1353 uch *src, *src2=NULL;
1354 char *dest;
1355 uch r, g, b, a;
1356 int ximage_rowbytes = ximage->bytes_per_line;
1357 ulg i, pixel;
1358 static int rows=0, prevpass=(-1);
1359 static ulg firstrow;
1360
1361/*---------------------------------------------------------------------------
1362 rows and firstrow simply track how many rows (and which ones) have not
1363 yet been displayed; alternatively, we could call XPutImage() for every
1364 row and not bother with the records-keeping.
1365 ---------------------------------------------------------------------------*/
1366
1367 Trace((stderr, "beginning rpng2_x_display_row()\n"))
1368
1369 if (rpng2_info.pass != prevpass) {
1370 if (pause_after_pass && rpng2_info.pass > 0) {
1371 XEvent e;
1372 KeySym k;
1373
1374 fprintf(stderr,
1375 "%s: end of pass %d of 7; click in image window to continue\n",
1376 PROGNAME, prevpass + 1);
1377 do
1378 XNextEvent(display, &e);
1379 while (!QUIT(e,k));
1380 }
1381 fprintf(stderr, "%s: pass %d of 7\r", PROGNAME, rpng2_info.pass + 1);
1382 fflush(stderr);
1383 prevpass = rpng2_info.pass;
1384 }
1385
1386 if (rows == 0)
1387 firstrow = row; /* first row that is not yet displayed */
1388
1389 ++rows; /* count of rows received but not yet displayed */
1390
1391/*---------------------------------------------------------------------------
1392 Aside from the use of the rpng2_info struct, the lack of an outer loop
1393 (over rows) and moving the XPutImage() call outside the "if (depth)"
1394 tests, this routine is identical to rpng_x_display_image() in the non-
1395 progressive version of the program.
1396 ---------------------------------------------------------------------------*/
1397
1398 if (depth == 24 || depth == 32) {
1399 ulg red, green, blue;
1400 int bpp = ximage->bits_per_pixel;
1401
1402 src = rpng2_info.image_data + row*rpng2_info.rowbytes;
1403 if (bg_image)
1404 src2 = bg_data + row*bg_rowbytes;
1405 dest = ximage->data + row*ximage_rowbytes;
1406 if (rpng2_info.channels == 3) {
1407 for (i = rpng2_info.width; i > 0; --i) {
1408 red = *src++;
1409 green = *src++;
1410 blue = *src++;
1411 pixel = (red << RShift) |
1412 (green << GShift) |
1413 (blue << BShift);
1414 /* recall that we set ximage->byte_order = MSBFirst above */
1415 if (bpp == 32) {
1416 *dest++ = (char)((pixel >> 24) & 0xff);
1417 *dest++ = (char)((pixel >> 16) & 0xff);
1418 *dest++ = (char)((pixel >> 8) & 0xff);
1419 *dest++ = (char)( pixel & 0xff);
1420 } else {
1421 /* GRR BUG? this assumes bpp == 24 & bits are packed low */
1422 /* (probably need to use RShift, RMask, etc.) */
1423 *dest++ = (char)((pixel >> 16) & 0xff);
1424 *dest++ = (char)((pixel >> 8) & 0xff);
1425 *dest++ = (char)( pixel & 0xff);
1426 }
1427 }
1428 } else /* if (rpng2_info.channels == 4) */ {
1429 for (i = rpng2_info.width; i > 0; --i) {
1430 r = *src++;
1431 g = *src++;
1432 b = *src++;
1433 a = *src++;
1434 if (bg_image) {
1435 bg_red = *src2++;
1436 bg_green = *src2++;
1437 bg_blue = *src2++;
1438 }
1439 if (a == 255) {
1440 red = r;
1441 green = g;
1442 blue = b;
1443 } else if (a == 0) {
1444 red = bg_red;
1445 green = bg_green;
1446 blue = bg_blue;
1447 } else {
1448 /* this macro (from png.h) composites the foreground
1449 * and background values and puts the result into the
1450 * first argument */
1451 alpha_composite(red, r, a, bg_red);
1452 alpha_composite(green, g, a, bg_green);
1453 alpha_composite(blue, b, a, bg_blue);
1454 }
1455 pixel = (red << RShift) |
1456 (green << GShift) |
1457 (blue << BShift);
1458 /* recall that we set ximage->byte_order = MSBFirst above */
1459 if (bpp == 32) {
1460 *dest++ = (char)((pixel >> 24) & 0xff);
1461 *dest++ = (char)((pixel >> 16) & 0xff);
1462 *dest++ = (char)((pixel >> 8) & 0xff);
1463 *dest++ = (char)( pixel & 0xff);
1464 } else {
1465 /* GRR BUG? this assumes bpp == 24 & bits are packed low */
1466 /* (probably need to use RShift, RMask, etc.) */
1467 *dest++ = (char)((pixel >> 16) & 0xff);
1468 *dest++ = (char)((pixel >> 8) & 0xff);
1469 *dest++ = (char)( pixel & 0xff);
1470 }
1471 }
1472 }
1473
1474 } else if (depth == 16) {
1475 ush red, green, blue;
1476
1477 src = rpng2_info.row_pointers[row];
1478 if (bg_image)
1479 src2 = bg_data + row*bg_rowbytes;
1480 dest = ximage->data + row*ximage_rowbytes;
1481 if (rpng2_info.channels == 3) {
1482 for (i = rpng2_info.width; i > 0; --i) {
1483 red = ((ush)(*src) << 8);
1484 ++src;
1485 green = ((ush)(*src) << 8);
1486 ++src;
1487 blue = ((ush)(*src) << 8);
1488 ++src;
1489 pixel = ((red >> RShift) & RMask) |
1490 ((green >> GShift) & GMask) |
1491 ((blue >> BShift) & BMask);
1492 /* recall that we set ximage->byte_order = MSBFirst above */
1493 *dest++ = (char)((pixel >> 8) & 0xff);
1494 *dest++ = (char)( pixel & 0xff);
1495 }
1496 } else /* if (rpng2_info.channels == 4) */ {
1497 for (i = rpng2_info.width; i > 0; --i) {
1498 r = *src++;
1499 g = *src++;
1500 b = *src++;
1501 a = *src++;
1502 if (bg_image) {
1503 bg_red = *src2++;
1504 bg_green = *src2++;
1505 bg_blue = *src2++;
1506 }
1507 if (a == 255) {
1508 red = ((ush)r << 8);
1509 green = ((ush)g << 8);
1510 blue = ((ush)b << 8);
1511 } else if (a == 0) {
1512 red = ((ush)bg_red << 8);
1513 green = ((ush)bg_green << 8);
1514 blue = ((ush)bg_blue << 8);
1515 } else {
1516 /* this macro (from png.h) composites the foreground
1517 * and background values and puts the result back into
1518 * the first argument (== fg byte here: safe) */
1519 alpha_composite(r, r, a, bg_red);
1520 alpha_composite(g, g, a, bg_green);
1521 alpha_composite(b, b, a, bg_blue);
1522 red = ((ush)r << 8);
1523 green = ((ush)g << 8);
1524 blue = ((ush)b << 8);
1525 }
1526 pixel = ((red >> RShift) & RMask) |
1527 ((green >> GShift) & GMask) |
1528 ((blue >> BShift) & BMask);
1529 /* recall that we set ximage->byte_order = MSBFirst above */
1530 *dest++ = (char)((pixel >> 8) & 0xff);
1531 *dest++ = (char)( pixel & 0xff);
1532 }
1533 }
1534
1535 } else /* depth == 8 */ {
1536
1537 /* GRR: add 8-bit support */
1538
1539 }
1540
1541
1542/*---------------------------------------------------------------------------
1543 Display after every 16 rows or when on one of last two rows. (Region
1544 may include previously displayed lines due to interlacing--i.e., not
1545 contiguous. Also, second-to-last row is final one in interlaced images
1546 with odd number of rows.) For demos, flush (and delay) after every 16th
1547 row so "sparse" passes don't go twice as fast.
1548 ---------------------------------------------------------------------------*/
1549
1550 if (demo_timing && (row - firstrow >= 16 || row >= rpng2_info.height-2)) {
1551 XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0,
1552 (int)firstrow, rpng2_info.width, row - firstrow + 1);
1553 XFlush(display);
1554 rows = 0;
1555 usleep(usleep_duration);
1556 } else
1557 if (!demo_timing && ((rows & 0xf) == 0 || row >= rpng2_info.height-2)) {
1558 XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0,
1559 (int)firstrow, rpng2_info.width, row - firstrow + 1);
1560 XFlush(display);
1561 rows = 0;
1562 }
1563
1564}
1565
1566
1567
1568
1569
1570static void rpng2_x_finish_display(void)
1571{
1572 Trace((stderr, "beginning rpng2_x_finish_display()\n"))
1573
1574 /* last row has already been displayed by rpng2_x_display_row(), so we
1575 * have nothing to do here except set a flag and let the user know that
1576 * the image is done */
1577
1578 rpng2_info.state = kDone;
1579 printf(
1580 "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n");
1581 fflush(stdout);
1582}
1583
1584
1585
1586
1587
1588static void rpng2_x_redisplay_image(ulg startcol, ulg startrow,
1589 ulg width, ulg height)
1590{
1591 uch bg_red = rpng2_info.bg_red;
1592 uch bg_green = rpng2_info.bg_green;
1593 uch bg_blue = rpng2_info.bg_blue;
1594 uch *src, *src2=NULL;
1595 char *dest;
1596 uch r, g, b, a;
1597 ulg i, row, lastrow = 0;
1598 ulg pixel;
1599 int ximage_rowbytes = ximage->bytes_per_line;
1600
1601
1602 Trace((stderr, "beginning display loop (image_channels == %d)\n",
1603 rpng2_info.channels))
1604 Trace((stderr, " (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\n",
1605 rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes))
1606 Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel))
1607 Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst?
1608 "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown")))
1609
1610/*---------------------------------------------------------------------------
1611 Aside from the use of the rpng2_info struct and of src2 (for background
1612 image), this routine is identical to rpng_x_display_image() in the non-
1613 progressive version of the program--for the simple reason that redisplay
1614 of the image against a new background happens after the image is fully
1615 decoded and therefore is, by definition, non-progressive.
1616 ---------------------------------------------------------------------------*/
1617
1618 if (depth == 24 || depth == 32) {
1619 ulg red, green, blue;
1620 int bpp = ximage->bits_per_pixel;
1621
1622 for (lastrow = row = startrow; row < startrow+height; ++row) {
1623 src = rpng2_info.image_data + row*rpng2_info.rowbytes;
1624 if (bg_image)
1625 src2 = bg_data + row*bg_rowbytes;
1626 dest = ximage->data + row*ximage_rowbytes;
1627 if (rpng2_info.channels == 3) {
1628 for (i = rpng2_info.width; i > 0; --i) {
1629 red = *src++;
1630 green = *src++;
1631 blue = *src++;
1632#ifdef NO_24BIT_MASKS
1633 pixel = (red << RShift) |
1634 (green << GShift) |
1635 (blue << BShift);
1636 /* recall that we set ximage->byte_order = MSBFirst above */
1637 if (bpp == 32) {
1638 *dest++ = (char)((pixel >> 24) & 0xff);
1639 *dest++ = (char)((pixel >> 16) & 0xff);
1640 *dest++ = (char)((pixel >> 8) & 0xff);
1641 *dest++ = (char)( pixel & 0xff);
1642 } else {
1643 /* this assumes bpp == 24 & bits are packed low */
1644 /* (probably need to use RShift, RMask, etc.) */
1645 *dest++ = (char)((pixel >> 16) & 0xff);
1646 *dest++ = (char)((pixel >> 8) & 0xff);
1647 *dest++ = (char)( pixel & 0xff);
1648 }
1649#else
1650 red = (RShift < 0)? red << (-RShift) : red >> RShift;
1651 green = (GShift < 0)? green << (-GShift) : green >> GShift;
1652 blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
1653 pixel = (red & RMask) | (green & GMask) | (blue & BMask);
1654 /* recall that we set ximage->byte_order = MSBFirst above */
1655 if (bpp == 32) {
1656 *dest++ = (char)((pixel >> 24) & 0xff);
1657 *dest++ = (char)((pixel >> 16) & 0xff);
1658 *dest++ = (char)((pixel >> 8) & 0xff);
1659 *dest++ = (char)( pixel & 0xff);
1660 } else {
1661 /* GRR BUG */
1662 /* this assumes bpp == 24 & bits are packed low */
1663 /* (probably need to use RShift/RMask/etc. here, too) */
1664 *dest++ = (char)((pixel >> 16) & 0xff);
1665 *dest++ = (char)((pixel >> 8) & 0xff);
1666 *dest++ = (char)( pixel & 0xff);
1667 }
1668#endif
1669 }
1670
1671 } else /* if (rpng2_info.channels == 4) */ {
1672 for (i = rpng2_info.width; i > 0; --i) {
1673 r = *src++;
1674 g = *src++;
1675 b = *src++;
1676 a = *src++;
1677 if (bg_image) {
1678 bg_red = *src2++;
1679 bg_green = *src2++;
1680 bg_blue = *src2++;
1681 }
1682 if (a == 255) {
1683 red = r;
1684 green = g;
1685 blue = b;
1686 } else if (a == 0) {
1687 red = bg_red;
1688 green = bg_green;
1689 blue = bg_blue;
1690 } else {
1691 /* this macro (from png.h) composites the foreground
1692 * and background values and puts the result into the
1693 * first argument */
1694 alpha_composite(red, r, a, bg_red);
1695 alpha_composite(green, g, a, bg_green);
1696 alpha_composite(blue, b, a, bg_blue);
1697 }
1698#ifdef NO_24BIT_MASKS
1699 pixel = (red << RShift) |
1700 (green << GShift) |
1701 (blue << BShift);
1702 /* recall that we set ximage->byte_order = MSBFirst above */
1703 if (bpp == 32) {
1704 *dest++ = (char)((pixel >> 24) & 0xff);
1705 *dest++ = (char)((pixel >> 16) & 0xff);
1706 *dest++ = (char)((pixel >> 8) & 0xff);
1707 *dest++ = (char)( pixel & 0xff);
1708 } else {
1709 /* this assumes bpp == 24 & bits are packed low */
1710 /* (probably need to use RShift, RMask, etc.) */
1711 *dest++ = (char)((pixel >> 16) & 0xff);
1712 *dest++ = (char)((pixel >> 8) & 0xff);
1713 *dest++ = (char)( pixel & 0xff);
1714 }
1715#else
1716 red = (RShift < 0)? red << (-RShift) : red >> RShift;
1717 green = (GShift < 0)? green << (-GShift) : green >> GShift;
1718 blue = (BShift < 0)? blue << (-BShift) : blue >> BShift;
1719 pixel = (red & RMask) | (green & GMask) | (blue & BMask);
1720 /* recall that we set ximage->byte_order = MSBFirst above */
1721 if (bpp == 32) {
1722 *dest++ = (char)((pixel >> 24) & 0xff);
1723 *dest++ = (char)((pixel >> 16) & 0xff);
1724 *dest++ = (char)((pixel >> 8) & 0xff);
1725 *dest++ = (char)( pixel & 0xff);
1726 } else {
1727 /* GRR BUG */
1728 /* this assumes bpp == 24 & bits are packed low */
1729 /* (probably need to use RShift/RMask/etc. here, too) */
1730 *dest++ = (char)((pixel >> 16) & 0xff);
1731 *dest++ = (char)((pixel >> 8) & 0xff);
1732 *dest++ = (char)( pixel & 0xff);
1733 }
1734#endif
1735 }
1736 }
1737 /* display after every 16 lines */
1738 if (((row+1) & 0xf) == 0) {
1739 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
1740 (int)lastrow, rpng2_info.width, 16);
1741 XFlush(display);
1742 lastrow = row + 1;
1743 }
1744 }
1745
1746 } else if (depth == 16) {
1747 ush red, green, blue;
1748
1749 for (lastrow = row = startrow; row < startrow+height; ++row) {
1750 src = rpng2_info.row_pointers[row];
1751 if (bg_image)
1752 src2 = bg_data + row*bg_rowbytes;
1753 dest = ximage->data + row*ximage_rowbytes;
1754 if (rpng2_info.channels == 3) {
1755 for (i = rpng2_info.width; i > 0; --i) {
1756 red = ((ush)(*src) << 8);
1757 ++src;
1758 green = ((ush)(*src) << 8);
1759 ++src;
1760 blue = ((ush)(*src) << 8);
1761 ++src;
1762 pixel = ((red >> RShift) & RMask) |
1763 ((green >> GShift) & GMask) |
1764 ((blue >> BShift) & BMask);
1765 /* recall that we set ximage->byte_order = MSBFirst above */
1766 *dest++ = (char)((pixel >> 8) & 0xff);
1767 *dest++ = (char)( pixel & 0xff);
1768 }
1769 } else /* if (rpng2_info.channels == 4) */ {
1770 for (i = rpng2_info.width; i > 0; --i) {
1771 r = *src++;
1772 g = *src++;
1773 b = *src++;
1774 a = *src++;
1775 if (bg_image) {
1776 bg_red = *src2++;
1777 bg_green = *src2++;
1778 bg_blue = *src2++;
1779 }
1780 if (a == 255) {
1781 red = ((ush)r << 8);
1782 green = ((ush)g << 8);
1783 blue = ((ush)b << 8);
1784 } else if (a == 0) {
1785 red = ((ush)bg_red << 8);
1786 green = ((ush)bg_green << 8);
1787 blue = ((ush)bg_blue << 8);
1788 } else {
1789 /* this macro (from png.h) composites the foreground
1790 * and background values and puts the result back into
1791 * the first argument (== fg byte here: safe) */
1792 alpha_composite(r, r, a, bg_red);
1793 alpha_composite(g, g, a, bg_green);
1794 alpha_composite(b, b, a, bg_blue);
1795 red = ((ush)r << 8);
1796 green = ((ush)g << 8);
1797 blue = ((ush)b << 8);
1798 }
1799 pixel = ((red >> RShift) & RMask) |
1800 ((green >> GShift) & GMask) |
1801 ((blue >> BShift) & BMask);
1802 /* recall that we set ximage->byte_order = MSBFirst above */
1803 *dest++ = (char)((pixel >> 8) & 0xff);
1804 *dest++ = (char)( pixel & 0xff);
1805 }
1806 }
1807 /* display after every 16 lines */
1808 if (((row+1) & 0xf) == 0) {
1809 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
1810 (int)lastrow, rpng2_info.width, 16);
1811 XFlush(display);
1812 lastrow = row + 1;
1813 }
1814 }
1815
1816 } else /* depth == 8 */ {
1817
1818 /* GRR: add 8-bit support */
1819
1820 }
1821
1822 Trace((stderr, "calling final XPutImage()\n"))
1823 if (lastrow < startrow+height) {
1824 XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,
1825 (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow);
1826 XFlush(display);
1827 }
1828
1829} /* end function rpng2_x_redisplay_image() */
1830
1831
1832
1833
1834
1835#ifdef FEATURE_LOOP
1836
1837static void rpng2_x_reload_bg_image(void)
1838{
1839 char *dest;
1840 uch r1, r2, g1, g2, b1, b2;
1841 uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;
1842 int k, hmax, max;
1843 int xidx, yidx, yidx_max;
1844 int even_odd_vert, even_odd_horiz, even_odd;
1845 int invert_gradient2 = (bg[pat].type & 0x08);
1846 int invert_column;
1847 ulg i, row;
1848
1849
1850 bgscale = (pat == 0)? 8 : bgscale_default;
1851 yidx_max = bgscale - 1;
1852
1853/*---------------------------------------------------------------------------
1854 Vertical gradients (ramps) in NxN squares, alternating direction and
1855 colors (N == bgscale).
1856 ---------------------------------------------------------------------------*/
1857
1858 if ((bg[pat].type & 0x07) == 0) {
1859 uch r1_min = rgb[bg[pat].rgb1_min].r;
1860 uch g1_min = rgb[bg[pat].rgb1_min].g;
1861 uch b1_min = rgb[bg[pat].rgb1_min].b;
1862 uch r2_min = rgb[bg[pat].rgb2_min].r;
1863 uch g2_min = rgb[bg[pat].rgb2_min].g;
1864 uch b2_min = rgb[bg[pat].rgb2_min].b;
1865 int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;
1866 int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;
1867 int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;
1868 int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;
1869 int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;
1870 int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;
1871
1872 for (row = 0; row < rpng2_info.height; ++row) {
1873 yidx = (int)(row % bgscale);
1874 even_odd_vert = (int)((row / bgscale) & 1);
1875
1876 r1 = r1_min + (r1_diff * yidx) / yidx_max;
1877 g1 = g1_min + (g1_diff * yidx) / yidx_max;
1878 b1 = b1_min + (b1_diff * yidx) / yidx_max;
1879 r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;
1880 g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;
1881 b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;
1882
1883 r2 = r2_min + (r2_diff * yidx) / yidx_max;
1884 g2 = g2_min + (g2_diff * yidx) / yidx_max;
1885 b2 = b2_min + (b2_diff * yidx) / yidx_max;
1886 r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;
1887 g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;
1888 b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;
1889
1890 dest = (char *)bg_data + row*bg_rowbytes;
1891 for (i = 0; i < rpng2_info.width; ++i) {
1892 even_odd_horiz = (int)((i / bgscale) & 1);
1893 even_odd = even_odd_vert ^ even_odd_horiz;
1894 invert_column =
1895 (even_odd_horiz && (bg[pat].type & 0x10));
1896 if (even_odd == 0) { /* gradient #1 */
1897 if (invert_column) {
1898 *dest++ = r1_inv;
1899 *dest++ = g1_inv;
1900 *dest++ = b1_inv;
1901 } else {
1902 *dest++ = r1;
1903 *dest++ = g1;
1904 *dest++ = b1;
1905 }
1906 } else { /* gradient #2 */
1907 if ((invert_column && invert_gradient2) ||
1908 (!invert_column && !invert_gradient2))
1909 {
1910 *dest++ = r2; /* not inverted or */
1911 *dest++ = g2; /* doubly inverted */
1912 *dest++ = b2;
1913 } else {
1914 *dest++ = r2_inv;
1915 *dest++ = g2_inv; /* singly inverted */
1916 *dest++ = b2_inv;
1917 }
1918 }
1919 }
1920 }
1921
1922/*---------------------------------------------------------------------------
1923 Soft gradient-diamonds with scale = bgscale. Code contributed by Adam
1924 M. Costello.
1925 ---------------------------------------------------------------------------*/
1926
1927 } else if ((bg[pat].type & 0x07) == 1) {
1928
1929 hmax = (bgscale-1)/2; /* half the max weight of a color */
1930 max = 2*hmax; /* the max weight of a color */
1931
1932 r1 = rgb[bg[pat].rgb1_max].r;
1933 g1 = rgb[bg[pat].rgb1_max].g;
1934 b1 = rgb[bg[pat].rgb1_max].b;
1935 r2 = rgb[bg[pat].rgb2_max].r;
1936 g2 = rgb[bg[pat].rgb2_max].g;
1937 b2 = rgb[bg[pat].rgb2_max].b;
1938
1939 for (row = 0; row < rpng2_info.height; ++row) {
1940 yidx = (int)(row % bgscale);
1941 if (yidx > hmax)
1942 yidx = bgscale-1 - yidx;
1943 dest = (char *)bg_data + row*bg_rowbytes;
1944 for (i = 0; i < rpng2_info.width; ++i) {
1945 xidx = (int)(i % bgscale);
1946 if (xidx > hmax)
1947 xidx = bgscale-1 - xidx;
1948 k = xidx + yidx;
1949 *dest++ = (k*r1 + (max-k)*r2) / max;
1950 *dest++ = (k*g1 + (max-k)*g2) / max;
1951 *dest++ = (k*b1 + (max-k)*b2) / max;
1952 }
1953 }
1954
1955/*---------------------------------------------------------------------------
1956 Radial "starburst" with azimuthal sinusoids; [eventually number of sinu-
1957 soids will equal bgscale?]. This one is slow but very cool. Code con-
1958 tributed by Pieter S. van der Meulen (originally in Smalltalk).
1959 ---------------------------------------------------------------------------*/
1960
1961 } else if ((bg[pat].type & 0x07) == 2) {
1962 uch ch;
1963 int ii, x, y, hw, hh, grayspot;
1964 double freq, rotate, saturate, gray, intensity;
1965 double angle=0.0, aoffset=0.0, maxDist, dist;
1966 double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;
1967
1968 hh = (int)(rpng2_info.height / 2);
1969 hw = (int)(rpng2_info.width / 2);
1970
1971 /* variables for radial waves:
1972 * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED]
1973 * freq: number of color beams originating from the center
1974 * grayspot: size of the graying center area (anti-alias)
1975 * rotate: rotation of the beams as a function of radius
1976 * saturate: saturation of beams' shape azimuthally
1977 */
1978 angle = CLIP(angle, 0.0, 360.0);
1979 grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));
1980 freq = MAX((double)bg[pat].bg_freq, 0.0);
1981 saturate = (double)bg[pat].bg_bsat * 0.1;
1982 rotate = (double)bg[pat].bg_brot * 0.1;
1983 gray = 0.0;
1984 intensity = 0.0;
1985 maxDist = (double)((hw*hw) + (hh*hh));
1986
1987 for (row = 0; row < rpng2_info.height; ++row) {
1988 y = (int)(row - hh);
1989 dest = (char *)bg_data + row*bg_rowbytes;
1990 for (i = 0; i < rpng2_info.width; ++i) {
1991 x = (int)(i - hw);
1992 angle = (x == 0)? PI_2 : atan((double)y / (double)x);
1993 gray = (double)MAX(ABS(y), ABS(x)) / grayspot;
1994 gray = MIN(1.0, gray);
1995 dist = (double)((x*x) + (y*y)) / maxDist;
1996 intensity = cos((angle+(rotate*dist*PI)) * freq) *
1997 gray * saturate;
1998 intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;
1999 hue = (angle + PI) * INV_PI_360 + aoffset;
2000 s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));
2001 s = MIN(MAX(s,0.0), 1.0);
2002 v = MIN(MAX(intensity,0.0), 1.0);
2003
2004 if (s == 0.0) {
2005 ch = (uch)(v * 255.0);
2006 *dest++ = ch;
2007 *dest++ = ch;
2008 *dest++ = ch;
2009 } else {
2010 if ((hue < 0.0) || (hue >= 360.0))
2011 hue -= (((int)(hue / 360.0)) * 360.0);
2012 hue /= 60.0;
2013 ii = (int)hue;
2014 f = hue - (double)ii;
2015 p = (1.0 - s) * v;
2016 q = (1.0 - (s * f)) * v;
2017 t = (1.0 - (s * (1.0 - f))) * v;
2018 if (ii == 0) { red = v; green = t; blue = p; }
2019 else if (ii == 1) { red = q; green = v; blue = p; }
2020 else if (ii == 2) { red = p; green = v; blue = t; }
2021 else if (ii == 3) { red = p; green = q; blue = v; }
2022 else if (ii == 4) { red = t; green = p; blue = v; }
2023 else if (ii == 5) { red = v; green = p; blue = q; }
2024 *dest++ = (uch)(red * 255.0);
2025 *dest++ = (uch)(green * 255.0);
2026 *dest++ = (uch)(blue * 255.0);
2027 }
2028 }
2029 }
2030 }
2031
2032} /* end function rpng2_x_reload_bg_image() */
2033
2034
2035
2036
2037
2038static int is_number(char *p)
2039{
2040 while (*p) {
2041 if (!isdigit(*p))
2042 return FALSE;
2043 ++p;
2044 }
2045 return TRUE;
2046}
2047
2048#endif /* FEATURE_LOOP */
2049
2050
2051
2052
2053
2054static void rpng2_x_cleanup(void)
2055{
2056 if (bg_image && bg_data) {
2057 free(bg_data);
2058 bg_data = NULL;
2059 }
2060
2061 if (rpng2_info.image_data) {
2062 free(rpng2_info.image_data);
2063 rpng2_info.image_data = NULL;
2064 }
2065
2066 if (rpng2_info.row_pointers) {
2067 free(rpng2_info.row_pointers);
2068 rpng2_info.row_pointers = NULL;
2069 }
2070
2071 if (ximage) {
2072 if (ximage->data) {
2073 free(ximage->data); /* we allocated it, so we free it */
2074 ximage->data = (char *)NULL; /* instead of XDestroyImage() */
2075 }
2076 XDestroyImage(ximage);
2077 ximage = NULL;
2078 }
2079
2080 if (have_gc)
2081 XFreeGC(display, gc);
2082
2083 if (have_window)
2084 XDestroyWindow(display, window);
2085
2086 if (have_colormap)
2087 XFreeColormap(display, colormap);
2088
2089 if (have_nondefault_visual)
2090 XFree(visual_list);
2091}
2092
2093
2094
2095
2096
2097static int rpng2_x_msb(ulg u32val)
2098{
2099 int i;
2100
2101 for (i = 31; i >= 0; --i) {
2102 if (u32val & 0x80000000L)
2103 break;
2104 u32val <<= 1;
2105 }
2106 return i;
2107}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.png b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.png
new file mode 100644
index 0000000..03960d4
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/toucan.png
Binary files differ
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c
new file mode 100644
index 0000000..30372a3
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c
@@ -0,0 +1,853 @@
1/*---------------------------------------------------------------------------
2
3 wpng - simple PNG-writing program wpng.c
4
5 This program converts certain NetPBM binary files (grayscale and RGB,
6 maxval = 255) to PNG. Non-interlaced PNGs are written progressively;
7 interlaced PNGs are read and written in one memory-intensive blast.
8
9 Thanks to Jean-loup Gailly for providing the necessary trick to read
10 interactive text from the keyboard while stdin is redirected. Thanks
11 to Cosmin Truta for Cygwin fixes.
12
13 NOTE: includes provisional support for PNM type "8" (portable alphamap)
14 images, presumed to be a 32-bit interleaved RGBA format; no pro-
15 vision for possible interleaved grayscale+alpha (16-bit) format.
16 THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT!
17
18 to do:
19 - delete output file if quit before calling any writepng routines
20 - process backspace with -text option under DOS/Win? (currently get ^H)
21
22 ---------------------------------------------------------------------------
23
24 Changelog:
25 - 1.01: initial public release
26 - 1.02: modified to allow abbreviated options
27 - 1.03: removed extraneous character from usage screen; fixed bug in
28 command-line parsing
29 - 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix
30 (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff)
31 - 2.00: dual-licensed (added GNU GPL)
32
33 [REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line
34 dose not work! In order to do something useful I needed to redirect
35 both input and output, with cygwin and with bcc32 as well. Under
36 Linux, the same wpng appears to work fine. I don't know what is
37 the problem."]
38
39 ---------------------------------------------------------------------------
40
41 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
42
43 This software is provided "as is," without warranty of any kind,
44 express or implied. In no event shall the author or contributors
45 be held liable for any damages arising in any way from the use of
46 this software.
47
48 The contents of this file are DUAL-LICENSED. You may modify and/or
49 redistribute this software according to the terms of one of the
50 following two licenses (at your option):
51
52
53 LICENSE 1 ("BSD-like with advertising clause"):
54
55 Permission is granted to anyone to use this software for any purpose,
56 including commercial applications, and to alter it and redistribute
57 it freely, subject to the following restrictions:
58
59 1. Redistributions of source code must retain the above copyright
60 notice, disclaimer, and this list of conditions.
61 2. Redistributions in binary form must reproduce the above copyright
62 notice, disclaimer, and this list of conditions in the documenta-
63 tion and/or other materials provided with the distribution.
64 3. All advertising materials mentioning features or use of this
65 software must display the following acknowledgment:
66
67 This product includes software developed by Greg Roelofs
68 and contributors for the book, "PNG: The Definitive Guide,"
69 published by O'Reilly and Associates.
70
71
72 LICENSE 2 (GNU GPL v2 or later):
73
74 This program is free software; you can redistribute it and/or modify
75 it under the terms of the GNU General Public License as published by
76 the Free Software Foundation; either version 2 of the License, or
77 (at your option) any later version.
78
79 This program is distributed in the hope that it will be useful,
80 but WITHOUT ANY WARRANTY; without even the implied warranty of
81 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82 GNU General Public License for more details.
83
84 You should have received a copy of the GNU General Public License
85 along with this program; if not, write to the Free Software Foundation,
86 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
87
88 ---------------------------------------------------------------------------*/
89
90#define PROGNAME "wpng"
91#define VERSION "2.00 of 2 June 2007"
92#define APPNAME "Simple PGM/PPM/PAM to PNG Converter"
93
94#if defined(__MSDOS__) || defined(__OS2__)
95# define DOS_OS2_W32
96#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
97# ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */
98# define DOS_OS2_W32
99# endif
100#endif
101
102#include <stdio.h>
103#include <stdlib.h>
104#include <string.h>
105#include <setjmp.h> /* for jmpbuf declaration in writepng.h */
106#include <time.h>
107
108#ifdef DOS_OS2_W32
109# include <io.h> /* for isatty(), setmode() prototypes */
110# include <fcntl.h> /* O_BINARY for fdopen() without text translation */
111# ifdef __EMX__
112# ifndef getch
113# define getch() _read_kbd(0, 1, 0) /* need getche() */
114# endif
115# else /* !__EMX__ */
116# ifdef __GO32__
117# include <pc.h>
118# define getch() getkey() /* GRR: need getche() */
119# else
120# include <conio.h> /* for getche() console input */
121# endif
122# endif /* ?__EMX__ */
123# define FGETS(buf,len,stream) dos_kbd_gets(buf,len)
124#else
125# include <unistd.h> /* for isatty() prototype */
126# define FGETS fgets
127#endif
128
129/* #define DEBUG : this enables the Trace() macros */
130
131/* #define FORBID_LATIN1_CTRL : this requires the user to re-enter any
132 text that includes control characters discouraged by the PNG spec; text
133 that includes an escape character (27) must be re-entered regardless */
134
135#include "writepng.h" /* typedefs, common macros, writepng prototypes */
136
137
138
139/* local prototypes */
140
141static int wpng_isvalid_latin1(uch *p, int len);
142static void wpng_cleanup(void);
143
144#ifdef DOS_OS2_W32
145 static char *dos_kbd_gets(char *buf, int len);
146#endif
147
148
149
150static mainprog_info wpng_info; /* lone global */
151
152
153
154int main(int argc, char **argv)
155{
156#ifndef DOS_OS2_W32
157 FILE *keybd;
158#endif
159#ifdef sgi
160 FILE *tmpfile; /* or we could just use keybd, since no overlap */
161 char tmpline[80];
162#endif
163 char *inname = NULL, outname[256];
164 char *p, pnmchar, pnmline[256];
165 char *bgstr, *textbuf = NULL;
166 ulg rowbytes;
167 int rc, len = 0;
168 int error = 0;
169 int text = FALSE;
170 int maxval;
171 double LUT_exponent; /* just the lookup table */
172 double CRT_exponent = 2.2; /* just the monitor */
173 double default_display_exponent; /* whole display system */
174 double default_gamma = 0.0;
175
176
177 wpng_info.infile = NULL;
178 wpng_info.outfile = NULL;
179 wpng_info.image_data = NULL;
180 wpng_info.row_pointers = NULL;
181 wpng_info.filter = FALSE;
182 wpng_info.interlaced = FALSE;
183 wpng_info.have_bg = FALSE;
184 wpng_info.have_time = FALSE;
185 wpng_info.have_text = 0;
186 wpng_info.gamma = 0.0;
187
188
189 /* First get the default value for our display-system exponent, i.e.,
190 * the product of the CRT exponent and the exponent corresponding to
191 * the frame-buffer's lookup table (LUT), if any. If the PNM image
192 * looks correct on the user's display system, its file gamma is the
193 * inverse of this value. (Note that this is not an exhaustive list
194 * of LUT values--e.g., OpenStep has a lot of weird ones--but it should
195 * cover 99% of the current possibilities. This section must ensure
196 * that default_display_exponent is positive.) */
197
198#if defined(NeXT)
199 /* third-party utilities can modify the default LUT exponent */
200 LUT_exponent = 1.0 / 2.2;
201 /*
202 if (some_next_function_that_returns_gamma(&next_gamma))
203 LUT_exponent = 1.0 / next_gamma;
204 */
205#elif defined(sgi)
206 LUT_exponent = 1.0 / 1.7;
207 /* there doesn't seem to be any documented function to
208 * get the "gamma" value, so we do it the hard way */
209 tmpfile = fopen("/etc/config/system.glGammaVal", "r");
210 if (tmpfile) {
211 double sgi_gamma;
212
213 fgets(tmpline, 80, tmpfile);
214 fclose(tmpfile);
215 sgi_gamma = atof(tmpline);
216 if (sgi_gamma > 0.0)
217 LUT_exponent = 1.0 / sgi_gamma;
218 }
219#elif defined(Macintosh)
220 LUT_exponent = 1.8 / 2.61;
221 /*
222 if (some_mac_function_that_returns_gamma(&mac_gamma))
223 LUT_exponent = mac_gamma / 2.61;
224 */
225#else
226 LUT_exponent = 1.0; /* assume no LUT: most PCs */
227#endif
228
229 /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */
230 default_display_exponent = LUT_exponent * CRT_exponent;
231
232
233 /* If the user has set the SCREEN_GAMMA environment variable as suggested
234 * (somewhat imprecisely) in the libpng documentation, use that; otherwise
235 * use the default value we just calculated. Either way, the user may
236 * override this via a command-line option. */
237
238 if ((p = getenv("SCREEN_GAMMA")) != NULL) {
239 double exponent = atof(p);
240
241 if (exponent > 0.0)
242 default_gamma = 1.0 / exponent;
243 }
244
245 if (default_gamma == 0.0)
246 default_gamma = 1.0 / default_display_exponent;
247
248
249 /* Now parse the command line for options and the PNM filename. */
250
251 while (*++argv && !error) {
252 if (!strncmp(*argv, "-i", 2)) {
253 wpng_info.interlaced = TRUE;
254 } else if (!strncmp(*argv, "-time", 3)) {
255 wpng_info.modtime = time(NULL);
256 wpng_info.have_time = TRUE;
257 } else if (!strncmp(*argv, "-text", 3)) {
258 text = TRUE;
259 } else if (!strncmp(*argv, "-gamma", 2)) {
260 if (!*++argv)
261 ++error;
262 else {
263 wpng_info.gamma = atof(*argv);
264 if (wpng_info.gamma <= 0.0)
265 ++error;
266 else if (wpng_info.gamma > 1.01)
267 fprintf(stderr, PROGNAME
268 " warning: file gammas are usually less than 1.0\n");
269 }
270 } else if (!strncmp(*argv, "-bgcolor", 4)) {
271 if (!*++argv)
272 ++error;
273 else {
274 bgstr = *argv;
275 if (strlen(bgstr) != 7 || bgstr[0] != '#')
276 ++error;
277 else {
278 unsigned r, g, b; /* this way quiets compiler warnings */
279
280 sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b);
281 wpng_info.bg_red = (uch)r;
282 wpng_info.bg_green = (uch)g;
283 wpng_info.bg_blue = (uch)b;
284 wpng_info.have_bg = TRUE;
285 }
286 }
287 } else {
288 if (**argv != '-') {
289 inname = *argv;
290 if (argv[1]) /* shouldn't be any more args after filename */
291 ++error;
292 } else
293 ++error; /* not expecting any other options */
294 }
295 }
296
297
298 /* open the input and output files, or register an error and abort */
299
300 if (!inname) {
301 if (isatty(0)) {
302 fprintf(stderr, PROGNAME
303 ": must give input filename or provide image data via stdin\n");
304 ++error;
305 } else {
306#ifdef DOS_OS2_W32
307 /* some buggy C libraries require BOTH setmode() and fdopen(bin) */
308 setmode(fileno(stdin), O_BINARY);
309 setmode(fileno(stdout), O_BINARY);
310#endif
311 if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) {
312 fprintf(stderr, PROGNAME
313 ": unable to reopen stdin in binary mode\n");
314 ++error;
315 } else
316 if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) {
317 fprintf(stderr, PROGNAME
318 ": unable to reopen stdout in binary mode\n");
319 fclose(wpng_info.infile);
320 ++error;
321 } else
322 wpng_info.filter = TRUE;
323 }
324 } else if ((len = strlen(inname)) > 250) {
325 fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n",
326 len);
327 ++error;
328 } else if (!(wpng_info.infile = fopen(inname, "rb"))) {
329 fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname);
330 ++error;
331 }
332
333 if (!error) {
334 fgets(pnmline, 256, wpng_info.infile);
335 if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' &&
336 pnmchar != '6' && pnmchar != '8'))
337 {
338 fprintf(stderr, PROGNAME
339 ": input file [%s] is not a binary PGM, PPM or PAM file\n",
340 inname);
341 ++error;
342 } else {
343 wpng_info.pnmtype = (int)(pnmchar - '0');
344 if (wpng_info.pnmtype != 8)
345 wpng_info.have_bg = FALSE; /* no need for bg if opaque */
346 do {
347 fgets(pnmline, 256, wpng_info.infile); /* lose any comments */
348 } while (pnmline[0] == '#');
349 sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height);
350 do {
351 fgets(pnmline, 256, wpng_info.infile); /* more comment lines */
352 } while (pnmline[0] == '#');
353 sscanf(pnmline, "%d", &maxval);
354 if (wpng_info.width <= 0L || wpng_info.height <= 0L ||
355 maxval != 255)
356 {
357 fprintf(stderr, PROGNAME
358 ": only positive width/height, maxval == 255 allowed \n");
359 ++error;
360 }
361 wpng_info.sample_depth = 8; /* <==> maxval 255 */
362
363 if (!wpng_info.filter) {
364 /* make outname from inname */
365 if ((p = strrchr(inname, '.')) == NULL ||
366 (p - inname) != (len - 4))
367 {
368 strcpy(outname, inname);
369 strcpy(outname+len, ".png");
370 } else {
371 len -= 4;
372 strncpy(outname, inname, len);
373 strcpy(outname+len, ".png");
374 }
375 /* check if outname already exists; if not, open */
376 if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) {
377 fprintf(stderr, PROGNAME ": output file exists [%s]\n",
378 outname);
379 fclose(wpng_info.outfile);
380 ++error;
381 } else if (!(wpng_info.outfile = fopen(outname, "wb"))) {
382 fprintf(stderr, PROGNAME ": can't open output file [%s]\n",
383 outname);
384 ++error;
385 }
386 }
387 }
388 if (error) {
389 fclose(wpng_info.infile);
390 wpng_info.infile = NULL;
391 if (wpng_info.filter) {
392 fclose(wpng_info.outfile);
393 wpng_info.outfile = NULL;
394 }
395 }
396 }
397
398
399 /* if we had any errors, print usage and die horrible death...arrr! */
400
401 if (error) {
402 fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME);
403 writepng_version_info();
404 fprintf(stderr, "\n"
405"Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n"
406"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n"
407 " exp \ttransfer-function exponent (``gamma'') of the image in\n"
408 "\t\t floating-point format (e.g., ``%.5f''); if image looks\n"
409 "\t\t correct on given display system, image gamma is equal to\n"
410 "\t\t inverse of display-system exponent, i.e., 1 / (LUT * CRT)\n"
411 "\t\t (where LUT = lookup-table exponent and CRT = CRT exponent;\n"
412 "\t\t first varies, second is usually 2.2, all are positive)\n"
413 " bg \tdesired background color for alpha-channel images, in\n"
414 "\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n"
415 "\t\t same as HTML colors)\n"
416 " -text\tprompt interactively for text info (tEXt chunks)\n"
417 " -time\tinclude a tIME chunk (last modification time)\n"
418 " -interlace\twrite interlaced PNG image\n"
419 "\n"
420"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\n"
421"unofficial and unsupported!) PAM (`P8') file. Currently it is required\n"
422"to have maxval == 255 (i.e., no scaling). If pnmfile is specified, it\n"
423"is converted to the corresponding PNG file with the same base name but a\n"
424"``.png'' extension; files read from stdin are converted and sent to stdout.\n"
425"The conversion is progressive (low memory usage) unless interlacing is\n"
426"requested; in that case the whole image will be buffered in memory and\n"
427"written in one call.\n"
428 "\n", PROGNAME, PROGNAME, default_gamma);
429 exit(1);
430 }
431
432
433 /* prepare the text buffers for libpng's use; note that even though
434 * PNG's png_text struct includes a length field, we don't have to fill
435 * it out */
436
437 if (text &&
438#ifndef DOS_OS2_W32
439 (keybd = fdopen(fileno(stderr), "r")) != NULL &&
440#endif
441 (textbuf = (char *)malloc((5 + 9)*75)) != NULL)
442 {
443 int i, valid, result;
444
445 fprintf(stderr,
446 "Enter text info (no more than 72 characters per line);\n");
447 fprintf(stderr, "to skip a field, hit the <Enter> key.\n");
448 /* note: just <Enter> leaves len == 1 */
449
450 do {
451 valid = TRUE;
452 p = textbuf + TEXT_TITLE_OFFSET;
453 fprintf(stderr, " Title: ");
454 fflush(stderr);
455 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
456 if (p[len-1] == '\n')
457 p[--len] = '\0';
458 wpng_info.title = p;
459 wpng_info.have_text |= TEXT_TITLE;
460 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
461 fprintf(stderr, " " PROGNAME " warning: character code"
462 " %u is %sdiscouraged by the PNG\n specification "
463 "[first occurrence was at character position #%d]\n",
464 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
465 result+1);
466 fflush(stderr);
467#ifdef FORBID_LATIN1_CTRL
468 wpng_info.have_text &= ~TEXT_TITLE;
469 valid = FALSE;
470#else
471 if (p[result] == 27) { /* escape character */
472 wpng_info.have_text &= ~TEXT_TITLE;
473 valid = FALSE;
474 }
475#endif
476 }
477 }
478 } while (!valid);
479
480 do {
481 valid = TRUE;
482 p = textbuf + TEXT_AUTHOR_OFFSET;
483 fprintf(stderr, " Author: ");
484 fflush(stderr);
485 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
486 if (p[len-1] == '\n')
487 p[--len] = '\0';
488 wpng_info.author = p;
489 wpng_info.have_text |= TEXT_AUTHOR;
490 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
491 fprintf(stderr, " " PROGNAME " warning: character code"
492 " %u is %sdiscouraged by the PNG\n specification "
493 "[first occurrence was at character position #%d]\n",
494 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
495 result+1);
496 fflush(stderr);
497#ifdef FORBID_LATIN1_CTRL
498 wpng_info.have_text &= ~TEXT_AUTHOR;
499 valid = FALSE;
500#else
501 if (p[result] == 27) { /* escape character */
502 wpng_info.have_text &= ~TEXT_AUTHOR;
503 valid = FALSE;
504 }
505#endif
506 }
507 }
508 } while (!valid);
509
510 do {
511 valid = TRUE;
512 p = textbuf + TEXT_DESC_OFFSET;
513 fprintf(stderr, " Description (up to 9 lines):\n");
514 for (i = 1; i < 10; ++i) {
515 fprintf(stderr, " [%d] ", i);
516 fflush(stderr);
517 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1)
518 p += len; /* now points at NULL; char before is newline */
519 else
520 break;
521 }
522 if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) {
523 if (p[-1] == '\n') {
524 p[-1] = '\0';
525 --len;
526 }
527 wpng_info.desc = textbuf + TEXT_DESC_OFFSET;
528 wpng_info.have_text |= TEXT_DESC;
529 p = textbuf + TEXT_DESC_OFFSET;
530 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
531 fprintf(stderr, " " PROGNAME " warning: character code"
532 " %u is %sdiscouraged by the PNG\n specification "
533 "[first occurrence was at character position #%d]\n",
534 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
535 result+1);
536 fflush(stderr);
537#ifdef FORBID_LATIN1_CTRL
538 wpng_info.have_text &= ~TEXT_DESC;
539 valid = FALSE;
540#else
541 if (p[result] == 27) { /* escape character */
542 wpng_info.have_text &= ~TEXT_DESC;
543 valid = FALSE;
544 }
545#endif
546 }
547 }
548 } while (!valid);
549
550 do {
551 valid = TRUE;
552 p = textbuf + TEXT_COPY_OFFSET;
553 fprintf(stderr, " Copyright: ");
554 fflush(stderr);
555 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
556 if (p[len-1] == '\n')
557 p[--len] = '\0';
558 wpng_info.copyright = p;
559 wpng_info.have_text |= TEXT_COPY;
560 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
561 fprintf(stderr, " " PROGNAME " warning: character code"
562 " %u is %sdiscouraged by the PNG\n specification "
563 "[first occurrence was at character position #%d]\n",
564 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
565 result+1);
566 fflush(stderr);
567#ifdef FORBID_LATIN1_CTRL
568 wpng_info.have_text &= ~TEXT_COPY;
569 valid = FALSE;
570#else
571 if (p[result] == 27) { /* escape character */
572 wpng_info.have_text &= ~TEXT_COPY;
573 valid = FALSE;
574 }
575#endif
576 }
577 }
578 } while (!valid);
579
580 do {
581 valid = TRUE;
582 p = textbuf + TEXT_EMAIL_OFFSET;
583 fprintf(stderr, " E-mail: ");
584 fflush(stderr);
585 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
586 if (p[len-1] == '\n')
587 p[--len] = '\0';
588 wpng_info.email = p;
589 wpng_info.have_text |= TEXT_EMAIL;
590 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
591 fprintf(stderr, " " PROGNAME " warning: character code"
592 " %u is %sdiscouraged by the PNG\n specification "
593 "[first occurrence was at character position #%d]\n",
594 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
595 result+1);
596 fflush(stderr);
597#ifdef FORBID_LATIN1_CTRL
598 wpng_info.have_text &= ~TEXT_EMAIL;
599 valid = FALSE;
600#else
601 if (p[result] == 27) { /* escape character */
602 wpng_info.have_text &= ~TEXT_EMAIL;
603 valid = FALSE;
604 }
605#endif
606 }
607 }
608 } while (!valid);
609
610 do {
611 valid = TRUE;
612 p = textbuf + TEXT_URL_OFFSET;
613 fprintf(stderr, " URL: ");
614 fflush(stderr);
615 if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {
616 if (p[len-1] == '\n')
617 p[--len] = '\0';
618 wpng_info.url = p;
619 wpng_info.have_text |= TEXT_URL;
620 if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {
621 fprintf(stderr, " " PROGNAME " warning: character code"
622 " %u is %sdiscouraged by the PNG\n specification "
623 "[first occurrence was at character position #%d]\n",
624 (unsigned)p[result], (p[result] == 27)? "strongly " : "",
625 result+1);
626 fflush(stderr);
627#ifdef FORBID_LATIN1_CTRL
628 wpng_info.have_text &= ~TEXT_URL;
629 valid = FALSE;
630#else
631 if (p[result] == 27) { /* escape character */
632 wpng_info.have_text &= ~TEXT_URL;
633 valid = FALSE;
634 }
635#endif
636 }
637 }
638 } while (!valid);
639
640#ifndef DOS_OS2_W32
641 fclose(keybd);
642#endif
643
644 } else if (text) {
645 fprintf(stderr, PROGNAME ": unable to allocate memory for text\n");
646 text = FALSE;
647 wpng_info.have_text = 0;
648 }
649
650
651 /* allocate libpng stuff, initialize transformations, write pre-IDAT data */
652
653 if ((rc = writepng_init(&wpng_info)) != 0) {
654 switch (rc) {
655 case 2:
656 fprintf(stderr, PROGNAME
657 ": libpng initialization problem (longjmp)\n");
658 break;
659 case 4:
660 fprintf(stderr, PROGNAME ": insufficient memory\n");
661 break;
662 case 11:
663 fprintf(stderr, PROGNAME
664 ": internal logic error (unexpected PNM type)\n");
665 break;
666 default:
667 fprintf(stderr, PROGNAME
668 ": unknown writepng_init() error\n");
669 break;
670 }
671 exit(rc);
672 }
673
674
675 /* free textbuf, since it's a completely local variable and all text info
676 * has just been written to the PNG file */
677
678 if (text && textbuf) {
679 free(textbuf);
680 textbuf = NULL;
681 }
682
683
684 /* calculate rowbytes on basis of image type; note that this becomes much
685 * more complicated if we choose to support PBM type, ASCII PNM types, or
686 * 16-bit-per-sample binary data [currently not an official NetPBM type] */
687
688 if (wpng_info.pnmtype == 5)
689 rowbytes = wpng_info.width;
690 else if (wpng_info.pnmtype == 6)
691 rowbytes = wpng_info.width * 3;
692 else /* if (wpng_info.pnmtype == 8) */
693 rowbytes = wpng_info.width * 4;
694
695
696 /* read and write the image, either in its entirety (if writing interlaced
697 * PNG) or row by row (if non-interlaced) */
698
699 fprintf(stderr, "Encoding image data...\n");
700 fflush(stderr);
701
702 if (wpng_info.interlaced) {
703 long i;
704 ulg bytes;
705 ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */
706
707 wpng_info.image_data = (uch *)malloc(image_bytes);
708 wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));
709 if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) {
710 fprintf(stderr, PROGNAME ": insufficient memory for image data\n");
711 writepng_cleanup(&wpng_info);
712 wpng_cleanup();
713 exit(5);
714 }
715 for (i = 0; i < wpng_info.height; ++i)
716 wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes;
717 bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile);
718 if (bytes != image_bytes) {
719 fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n",
720 image_bytes, bytes);
721 fprintf(stderr, " (continuing anyway)\n");
722 }
723 if (writepng_encode_image(&wpng_info) != 0) {
724 fprintf(stderr, PROGNAME
725 ": libpng problem (longjmp) while writing image data\n");
726 writepng_cleanup(&wpng_info);
727 wpng_cleanup();
728 exit(2);
729 }
730
731 } else /* not interlaced: write progressively (row by row) */ {
732 long j;
733 ulg bytes;
734
735 wpng_info.image_data = (uch *)malloc(rowbytes);
736 if (wpng_info.image_data == NULL) {
737 fprintf(stderr, PROGNAME ": insufficient memory for row data\n");
738 writepng_cleanup(&wpng_info);
739 wpng_cleanup();
740 exit(5);
741 }
742 error = 0;
743 for (j = wpng_info.height; j > 0L; --j) {
744 bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile);
745 if (bytes != rowbytes) {
746 fprintf(stderr, PROGNAME
747 ": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes,
748 bytes, wpng_info.height-j);
749 ++error;
750 break;
751 }
752 if (writepng_encode_row(&wpng_info) != 0) {
753 fprintf(stderr, PROGNAME
754 ": libpng problem (longjmp) while writing row %ld\n",
755 wpng_info.height-j);
756 ++error;
757 break;
758 }
759 }
760 if (error) {
761 writepng_cleanup(&wpng_info);
762 wpng_cleanup();
763 exit(2);
764 }
765 if (writepng_encode_finish(&wpng_info) != 0) {
766 fprintf(stderr, PROGNAME ": error on final libpng call\n");
767 writepng_cleanup(&wpng_info);
768 wpng_cleanup();
769 exit(2);
770 }
771 }
772
773
774 /* OK, we're done (successfully): clean up all resources and quit */
775
776 fprintf(stderr, "Done.\n");
777 fflush(stderr);
778
779 writepng_cleanup(&wpng_info);
780 wpng_cleanup();
781
782 return 0;
783}
784
785
786
787
788
789static int wpng_isvalid_latin1(uch *p, int len)
790{
791 int i, result = -1;
792
793 for (i = 0; i < len; ++i) {
794 if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160)
795 continue; /* character is completely OK */
796 if (result < 0 || (p[result] != 27 && p[i] == 27))
797 result = i; /* mark location of first questionable one */
798 } /* or of first escape character (bad) */
799
800 return result;
801}
802
803
804
805
806
807static void wpng_cleanup(void)
808{
809 if (wpng_info.outfile) {
810 fclose(wpng_info.outfile);
811 wpng_info.outfile = NULL;
812 }
813
814 if (wpng_info.infile) {
815 fclose(wpng_info.infile);
816 wpng_info.infile = NULL;
817 }
818
819 if (wpng_info.image_data) {
820 free(wpng_info.image_data);
821 wpng_info.image_data = NULL;
822 }
823
824 if (wpng_info.row_pointers) {
825 free(wpng_info.row_pointers);
826 wpng_info.row_pointers = NULL;
827 }
828}
829
830
831
832
833#ifdef DOS_OS2_W32
834
835static char *dos_kbd_gets(char *buf, int len)
836{
837 int ch, count=0;
838
839 do {
840 buf[count++] = ch = getche();
841 } while (ch != '\r' && count < len-1);
842
843 buf[count--] = '\0'; /* terminate string */
844 if (buf[count] == '\r') /* Enter key makes CR, so change to newline */
845 buf[count] = '\n';
846
847 fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */
848 fflush(stderr);
849
850 return buf;
851}
852
853#endif /* DOS_OS2_W32 */
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c
new file mode 100644
index 0000000..8373c16
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c
@@ -0,0 +1,400 @@
1/*---------------------------------------------------------------------------
2
3 wpng - simple PNG-writing program writepng.c
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56
57#include <stdlib.h> /* for exit() prototype */
58
59#include "png.h" /* libpng header; includes zlib.h and setjmp.h */
60#include "writepng.h" /* typedefs, common macros, public prototypes */
61
62
63/* local prototype */
64
65static void writepng_error_handler(png_structp png_ptr, png_const_charp msg);
66
67
68
69void writepng_version_info(void)
70{
71 fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n",
72 PNG_LIBPNG_VER_STRING, png_libpng_ver);
73 fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n",
74 ZLIB_VERSION, zlib_version);
75}
76
77
78
79
80/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for
81 * unexpected pnmtype; note that outfile might be stdout */
82
83int writepng_init(mainprog_info *mainprog_ptr)
84{
85 png_structp png_ptr; /* note: temporary variables! */
86 png_infop info_ptr;
87 int color_type, interlace_type;
88
89
90 /* could also replace libpng warning-handler (final NULL), but no need: */
91
92 png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr,
93 writepng_error_handler, NULL);
94 if (!png_ptr)
95 return 4; /* out of memory */
96
97 info_ptr = png_create_info_struct(png_ptr);
98 if (!info_ptr) {
99 png_destroy_write_struct(&png_ptr, NULL);
100 return 4; /* out of memory */
101 }
102
103
104 /* setjmp() must be called in every function that calls a PNG-writing
105 * libpng function, unless an alternate error handler was installed--
106 * but compatible error handlers must either use longjmp() themselves
107 * (as in this program) or some other method to return control to
108 * application code, so here we go: */
109
110 if (setjmp(mainprog_ptr->jmpbuf)) {
111 png_destroy_write_struct(&png_ptr, &info_ptr);
112 return 2;
113 }
114
115
116 /* make sure outfile is (re)opened in BINARY mode */
117
118 png_init_io(png_ptr, mainprog_ptr->outfile);
119
120
121 /* set the compression levels--in general, always want to leave filtering
122 * turned on (except for palette images) and allow all of the filters,
123 * which is the default; want 32K zlib window, unless entire image buffer
124 * is 16K or smaller (unknown here)--also the default; usually want max
125 * compression (NOT the default); and remaining compression flags should
126 * be left alone */
127
128 png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);
129/*
130 >> this is default for no filtering; Z_FILTERED is default otherwise:
131 png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
132 >> these are all defaults:
133 png_set_compression_mem_level(png_ptr, 8);
134 png_set_compression_window_bits(png_ptr, 15);
135 png_set_compression_method(png_ptr, 8);
136 */
137
138
139 /* set the image parameters appropriately */
140
141 if (mainprog_ptr->pnmtype == 5)
142 color_type = PNG_COLOR_TYPE_GRAY;
143 else if (mainprog_ptr->pnmtype == 6)
144 color_type = PNG_COLOR_TYPE_RGB;
145 else if (mainprog_ptr->pnmtype == 8)
146 color_type = PNG_COLOR_TYPE_RGB_ALPHA;
147 else {
148 png_destroy_write_struct(&png_ptr, &info_ptr);
149 return 11;
150 }
151
152 interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :
153 PNG_INTERLACE_NONE;
154
155 png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,
156 mainprog_ptr->sample_depth, color_type, interlace_type,
157 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
158
159 if (mainprog_ptr->gamma > 0.0)
160 png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);
161
162 if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */
163 png_color_16 background;
164
165 background.red = mainprog_ptr->bg_red;
166 background.green = mainprog_ptr->bg_green;
167 background.blue = mainprog_ptr->bg_blue;
168 png_set_bKGD(png_ptr, info_ptr, &background);
169 }
170
171 if (mainprog_ptr->have_time) {
172 png_time modtime;
173
174 png_convert_from_time_t(&modtime, mainprog_ptr->modtime);
175 png_set_tIME(png_ptr, info_ptr, &modtime);
176 }
177
178 if (mainprog_ptr->have_text) {
179 png_text text[6];
180 int num_text = 0;
181
182 if (mainprog_ptr->have_text & TEXT_TITLE) {
183 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
184 text[num_text].key = "Title";
185 text[num_text].text = mainprog_ptr->title;
186 ++num_text;
187 }
188 if (mainprog_ptr->have_text & TEXT_AUTHOR) {
189 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
190 text[num_text].key = "Author";
191 text[num_text].text = mainprog_ptr->author;
192 ++num_text;
193 }
194 if (mainprog_ptr->have_text & TEXT_DESC) {
195 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
196 text[num_text].key = "Description";
197 text[num_text].text = mainprog_ptr->desc;
198 ++num_text;
199 }
200 if (mainprog_ptr->have_text & TEXT_COPY) {
201 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
202 text[num_text].key = "Copyright";
203 text[num_text].text = mainprog_ptr->copyright;
204 ++num_text;
205 }
206 if (mainprog_ptr->have_text & TEXT_EMAIL) {
207 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
208 text[num_text].key = "E-mail";
209 text[num_text].text = mainprog_ptr->email;
210 ++num_text;
211 }
212 if (mainprog_ptr->have_text & TEXT_URL) {
213 text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;
214 text[num_text].key = "URL";
215 text[num_text].text = mainprog_ptr->url;
216 ++num_text;
217 }
218 png_set_text(png_ptr, info_ptr, text, num_text);
219 }
220
221
222 /* write all chunks up to (but not including) first IDAT */
223
224 png_write_info(png_ptr, info_ptr);
225
226
227 /* if we wanted to write any more text info *after* the image data, we
228 * would set up text struct(s) here and call png_set_text() again, with
229 * just the new data; png_set_tIME() could also go here, but it would
230 * have no effect since we already called it above (only one tIME chunk
231 * allowed) */
232
233
234 /* set up the transformations: for now, just pack low-bit-depth pixels
235 * into bytes (one, two or four pixels per byte) */
236
237 png_set_packing(png_ptr);
238/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */
239
240
241 /* make sure we save our pointers for use in writepng_encode_image() */
242
243 mainprog_ptr->png_ptr = png_ptr;
244 mainprog_ptr->info_ptr = info_ptr;
245
246
247 /* OK, that's all we need to do for now; return happy */
248
249 return 0;
250}
251
252
253
254
255
256/* returns 0 for success, 2 for libpng (longjmp) problem */
257
258int writepng_encode_image(mainprog_info *mainprog_ptr)
259{
260 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
261 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
262
263
264 /* as always, setjmp() must be called in every function that calls a
265 * PNG-writing libpng function */
266
267 if (setjmp(mainprog_ptr->jmpbuf)) {
268 png_destroy_write_struct(&png_ptr, &info_ptr);
269 mainprog_ptr->png_ptr = NULL;
270 mainprog_ptr->info_ptr = NULL;
271 return 2;
272 }
273
274
275 /* and now we just write the whole image; libpng takes care of interlacing
276 * for us */
277
278 png_write_image(png_ptr, mainprog_ptr->row_pointers);
279
280
281 /* since that's it, we also close out the end of the PNG file now--if we
282 * had any text or time info to write after the IDATs, second argument
283 * would be info_ptr, but we optimize slightly by sending NULL pointer: */
284
285 png_write_end(png_ptr, NULL);
286
287 return 0;
288}
289
290
291
292
293
294/* returns 0 if succeeds, 2 if libpng problem */
295
296int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */
297{
298 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
299 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
300
301
302 /* as always, setjmp() must be called in every function that calls a
303 * PNG-writing libpng function */
304
305 if (setjmp(mainprog_ptr->jmpbuf)) {
306 png_destroy_write_struct(&png_ptr, &info_ptr);
307 mainprog_ptr->png_ptr = NULL;
308 mainprog_ptr->info_ptr = NULL;
309 return 2;
310 }
311
312
313 /* image_data points at our one row of image data */
314
315 png_write_row(png_ptr, mainprog_ptr->image_data);
316
317 return 0;
318}
319
320
321
322
323
324/* returns 0 if succeeds, 2 if libpng problem */
325
326int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */
327{
328 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
329 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
330
331
332 /* as always, setjmp() must be called in every function that calls a
333 * PNG-writing libpng function */
334
335 if (setjmp(mainprog_ptr->jmpbuf)) {
336 png_destroy_write_struct(&png_ptr, &info_ptr);
337 mainprog_ptr->png_ptr = NULL;
338 mainprog_ptr->info_ptr = NULL;
339 return 2;
340 }
341
342
343 /* close out PNG file; if we had any text or time info to write after
344 * the IDATs, second argument would be info_ptr: */
345
346 png_write_end(png_ptr, NULL);
347
348 return 0;
349}
350
351
352
353
354
355void writepng_cleanup(mainprog_info *mainprog_ptr)
356{
357 png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;
358 png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;
359
360 if (png_ptr && info_ptr)
361 png_destroy_write_struct(&png_ptr, &info_ptr);
362}
363
364
365
366
367
368static void writepng_error_handler(png_structp png_ptr, png_const_charp msg)
369{
370 mainprog_info *mainprog_ptr;
371
372 /* This function, aside from the extra step of retrieving the "error
373 * pointer" (below) and the fact that it exists within the application
374 * rather than within libpng, is essentially identical to libpng's
375 * default error handler. The second point is critical: since both
376 * setjmp() and longjmp() are called from the same code, they are
377 * guaranteed to have compatible notions of how big a jmp_buf is,
378 * regardless of whether _BSD_SOURCE or anything else has (or has not)
379 * been defined. */
380
381 fprintf(stderr, "writepng libpng error: %s\n", msg);
382 fflush(stderr);
383
384 mainprog_ptr = png_get_error_ptr(png_ptr);
385 if (mainprog_ptr == NULL) { /* we are completely hosed now */
386 fprintf(stderr,
387 "writepng severe error: jmpbuf not recoverable; terminating.\n");
388 fflush(stderr);
389 exit(99);
390 }
391
392 /* Now we have our data structure we can use the information in it
393 * to return control to our own higher level code (all the points
394 * where 'setjmp' is called in this file.) This will work with other
395 * error handling mechanisms as well - libpng always calls png_error
396 * when it can proceed no further, thus, so long as the error handler
397 * is intercepted, application code can do its own error recovery.
398 */
399 longjmp(mainprog_ptr->jmpbuf, 1);
400}
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h
new file mode 100644
index 0000000..904e4fb
--- /dev/null
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h
@@ -0,0 +1,133 @@
1/*---------------------------------------------------------------------------
2
3 wpng - simple PNG-writing program writepng.h
4
5 ---------------------------------------------------------------------------
6
7 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
8
9 This software is provided "as is," without warranty of any kind,
10 express or implied. In no event shall the author or contributors
11 be held liable for any damages arising in any way from the use of
12 this software.
13
14 The contents of this file are DUAL-LICENSED. You may modify and/or
15 redistribute this software according to the terms of one of the
16 following two licenses (at your option):
17
18
19 LICENSE 1 ("BSD-like with advertising clause"):
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute
23 it freely, subject to the following restrictions:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, disclaimer, and this list of conditions.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, disclaimer, and this list of conditions in the documenta-
29 tion and/or other materials provided with the distribution.
30 3. All advertising materials mentioning features or use of this
31 software must display the following acknowledgment:
32
33 This product includes software developed by Greg Roelofs
34 and contributors for the book, "PNG: The Definitive Guide,"
35 published by O'Reilly and Associates.
36
37
38 LICENSE 2 (GNU GPL v2 or later):
39
40 This program is free software; you can redistribute it and/or modify
41 it under the terms of the GNU General Public License as published by
42 the Free Software Foundation; either version 2 of the License, or
43 (at your option) any later version.
44
45 This program is distributed in the hope that it will be useful,
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 GNU General Public License for more details.
49
50 You should have received a copy of the GNU General Public License
51 along with this program; if not, write to the Free Software Foundation,
52 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
53
54 ---------------------------------------------------------------------------*/
55
56#ifndef TRUE
57# define TRUE 1
58# define FALSE 0
59#endif
60
61#ifndef MAX
62# define MAX(a,b) ((a) > (b)? (a) : (b))
63# define MIN(a,b) ((a) < (b)? (a) : (b))
64#endif
65
66#ifdef DEBUG
67# define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);}
68#else
69# define Trace(x) ;
70#endif
71
72#define TEXT_TITLE 0x01
73#define TEXT_AUTHOR 0x02
74#define TEXT_DESC 0x04
75#define TEXT_COPY 0x08
76#define TEXT_EMAIL 0x10
77#define TEXT_URL 0x20
78
79#define TEXT_TITLE_OFFSET 0
80#define TEXT_AUTHOR_OFFSET 72
81#define TEXT_COPY_OFFSET (2*72)
82#define TEXT_EMAIL_OFFSET (3*72)
83#define TEXT_URL_OFFSET (4*72)
84#define TEXT_DESC_OFFSET (5*72)
85
86typedef unsigned char uch;
87typedef unsigned short ush;
88typedef unsigned long ulg;
89
90typedef struct _mainprog_info {
91 double gamma;
92 long width;
93 long height;
94 time_t modtime;
95 FILE *infile;
96 FILE *outfile;
97 void *png_ptr;
98 void *info_ptr;
99 uch *image_data;
100 uch **row_pointers;
101 char *title;
102 char *author;
103 char *desc;
104 char *copyright;
105 char *email;
106 char *url;
107 int filter; /* command-line-filter flag, not PNG row filter! */
108 int pnmtype;
109 int sample_depth;
110 int interlaced;
111 int have_bg;
112 int have_time;
113 int have_text;
114 jmp_buf jmpbuf;
115 uch bg_red;
116 uch bg_green;
117 uch bg_blue;
118} mainprog_info;
119
120
121/* prototypes for public functions in writepng.c */
122
123void writepng_version_info(void);
124
125int writepng_init(mainprog_info *mainprog_ptr);
126
127int writepng_encode_image(mainprog_info *mainprog_ptr);
128
129int writepng_encode_row(mainprog_info *mainprog_ptr);
130
131int writepng_encode_finish(mainprog_info *mainprog_ptr);
132
133void writepng_cleanup(mainprog_info *mainprog_ptr);