diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook')
20 files changed, 8770 insertions, 8770 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 index c2d382b..a3e9774 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/COPYING | |||
@@ -1,340 +1,340 @@ | |||
1 | GNU GENERAL PUBLIC LICENSE | 1 | GNU GENERAL PUBLIC LICENSE |
2 | Version 2, June 1991 | 2 | Version 2, June 1991 |
3 | 3 | ||
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. |
5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 5 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
6 | Everyone is permitted to copy and distribute verbatim copies | 6 | Everyone is permitted to copy and distribute verbatim copies |
7 | of this license document, but changing it is not allowed. | 7 | of this license document, but changing it is not allowed. |
8 | 8 | ||
9 | Preamble | 9 | Preamble |
10 | 10 | ||
11 | The licenses for most software are designed to take away your | 11 | The licenses for most software are designed to take away your |
12 | freedom to share and change it. By contrast, the GNU General Public | 12 | freedom to share and change it. By contrast, the GNU General Public |
13 | License is intended to guarantee your freedom to share and change free | 13 | License is intended to guarantee your freedom to share and change free |
14 | software--to make sure the software is free for all its users. This | 14 | software--to make sure the software is free for all its users. This |
15 | General Public License applies to most of the Free Software | 15 | General Public License applies to most of the Free Software |
16 | Foundation's software and to any other program whose authors commit to | 16 | Foundation's software and to any other program whose authors commit to |
17 | using it. (Some other Free Software Foundation software is covered by | 17 | using it. (Some other Free Software Foundation software is covered by |
18 | the GNU Library General Public License instead.) You can apply it to | 18 | the GNU Library General Public License instead.) You can apply it to |
19 | your programs, too. | 19 | your programs, too. |
20 | 20 | ||
21 | When we speak of free software, we are referring to freedom, not | 21 | When we speak of free software, we are referring to freedom, not |
22 | price. Our General Public Licenses are designed to make sure that you | 22 | price. Our General Public Licenses are designed to make sure that you |
23 | have the freedom to distribute copies of free software (and charge for | 23 | have the freedom to distribute copies of free software (and charge for |
24 | this service if you wish), that you receive source code or can get it | 24 | this service if you wish), that you receive source code or can get it |
25 | if you want it, that you can change the software or use pieces of it | 25 | if you want it, that you can change the software or use pieces of it |
26 | in new free programs; and that you know you can do these things. | 26 | in new free programs; and that you know you can do these things. |
27 | 27 | ||
28 | To protect your rights, we need to make restrictions that forbid | 28 | To protect your rights, we need to make restrictions that forbid |
29 | anyone to deny you these rights or to ask you to surrender the rights. | 29 | anyone to deny you these rights or to ask you to surrender the rights. |
30 | These restrictions translate to certain responsibilities for you if you | 30 | These restrictions translate to certain responsibilities for you if you |
31 | distribute copies of the software, or if you modify it. | 31 | distribute copies of the software, or if you modify it. |
32 | 32 | ||
33 | For example, if you distribute copies of such a program, whether | 33 | For example, if you distribute copies of such a program, whether |
34 | gratis or for a fee, you must give the recipients all the rights that | 34 | gratis or for a fee, you must give the recipients all the rights that |
35 | you have. You must make sure that they, too, receive or can get the | 35 | you have. You must make sure that they, too, receive or can get the |
36 | source code. And you must show them these terms so they know their | 36 | source code. And you must show them these terms so they know their |
37 | rights. | 37 | rights. |
38 | 38 | ||
39 | We protect your rights with two steps: (1) copyright the software, and | 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, | 40 | (2) offer you this license which gives you legal permission to copy, |
41 | distribute and/or modify the software. | 41 | distribute and/or modify the software. |
42 | 42 | ||
43 | Also, for each author's protection and ours, we want to make certain | 43 | Also, for each author's protection and ours, we want to make certain |
44 | that everyone understands that there is no warranty for this free | 44 | that everyone understands that there is no warranty for this free |
45 | software. If the software is modified by someone else and passed on, we | 45 | software. If the software is modified by someone else and passed on, we |
46 | want its recipients to know that what they have is not the original, so | 46 | want its recipients to know that what they have is not the original, so |
47 | that any problems introduced by others will not reflect on the original | 47 | that any problems introduced by others will not reflect on the original |
48 | authors' reputations. | 48 | authors' reputations. |
49 | 49 | ||
50 | Finally, any free program is threatened constantly by software | 50 | Finally, any free program is threatened constantly by software |
51 | patents. We wish to avoid the danger that redistributors of a free | 51 | patents. We wish to avoid the danger that redistributors of a free |
52 | program will individually obtain patent licenses, in effect making the | 52 | program will individually obtain patent licenses, in effect making the |
53 | program proprietary. To prevent this, we have made it clear that any | 53 | program proprietary. To prevent this, we have made it clear that any |
54 | patent must be licensed for everyone's free use or not licensed at all. | 54 | patent must be licensed for everyone's free use or not licensed at all. |
55 | 55 | ||
56 | The precise terms and conditions for copying, distribution and | 56 | The precise terms and conditions for copying, distribution and |
57 | modification follow. | 57 | modification follow. |
58 | 58 | ||
59 | GNU GENERAL PUBLIC LICENSE | 59 | GNU GENERAL PUBLIC LICENSE |
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
61 | 61 | ||
62 | 0. This License applies to any program or other work which contains | 62 | 0. This License applies to any program or other work which contains |
63 | a notice placed by the copyright holder saying it may be distributed | 63 | a notice placed by the copyright holder saying it may be distributed |
64 | under the terms of this General Public License. The "Program", below, | 64 | under the terms of this General Public License. The "Program", below, |
65 | refers to any such program or work, and a "work based on the Program" | 65 | refers to any such program or work, and a "work based on the Program" |
66 | means either the Program or any derivative work under copyright law: | 66 | means either the Program or any derivative work under copyright law: |
67 | that is to say, a work containing the Program or a portion of it, | 67 | that is to say, a work containing the Program or a portion of it, |
68 | either verbatim or with modifications and/or translated into another | 68 | either verbatim or with modifications and/or translated into another |
69 | language. (Hereinafter, translation is included without limitation in | 69 | language. (Hereinafter, translation is included without limitation in |
70 | the term "modification".) Each licensee is addressed as "you". | 70 | the term "modification".) Each licensee is addressed as "you". |
71 | 71 | ||
72 | Activities other than copying, distribution and modification are not | 72 | Activities other than copying, distribution and modification are not |
73 | covered by this License; they are outside its scope. The act of | 73 | covered by this License; they are outside its scope. The act of |
74 | running the Program is not restricted, and the output from the Program | 74 | running the Program is not restricted, and the output from the Program |
75 | is covered only if its contents constitute a work based on the | 75 | is covered only if its contents constitute a work based on the |
76 | Program (independent of having been made by running the Program). | 76 | Program (independent of having been made by running the Program). |
77 | Whether that is true depends on what the Program does. | 77 | Whether that is true depends on what the Program does. |
78 | 78 | ||
79 | 1. You may copy and distribute verbatim copies of the Program's | 79 | 1. You may copy and distribute verbatim copies of the Program's |
80 | source code as you receive it, in any medium, provided that you | 80 | source code as you receive it, in any medium, provided that you |
81 | conspicuously and appropriately publish on each copy an appropriate | 81 | conspicuously and appropriately publish on each copy an appropriate |
82 | copyright notice and disclaimer of warranty; keep intact all the | 82 | copyright notice and disclaimer of warranty; keep intact all the |
83 | notices that refer to this License and to the absence of any warranty; | 83 | notices that refer to this License and to the absence of any warranty; |
84 | and give any other recipients of the Program a copy of this License | 84 | and give any other recipients of the Program a copy of this License |
85 | along with the Program. | 85 | along with the Program. |
86 | 86 | ||
87 | You may charge a fee for the physical act of transferring a copy, and | 87 | You may charge a fee for the physical act of transferring a copy, and |
88 | you may at your option offer warranty protection in exchange for a fee. | 88 | you may at your option offer warranty protection in exchange for a fee. |
89 | 89 | ||
90 | 2. You may modify your copy or copies of the Program or any portion | 90 | 2. You may modify your copy or copies of the Program or any portion |
91 | of it, thus forming a work based on the Program, and copy and | 91 | of it, thus forming a work based on the Program, and copy and |
92 | distribute such modifications or work under the terms of Section 1 | 92 | distribute such modifications or work under the terms of Section 1 |
93 | above, provided that you also meet all of these conditions: | 93 | above, provided that you also meet all of these conditions: |
94 | 94 | ||
95 | a) You must cause the modified files to carry prominent notices | 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. | 96 | stating that you changed the files and the date of any change. |
97 | 97 | ||
98 | b) You must cause any work that you distribute or publish, that in | 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 | 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 | 100 | part thereof, to be licensed as a whole at no charge to all third |
101 | parties under the terms of this License. | 101 | parties under the terms of this License. |
102 | 102 | ||
103 | c) If the modified program normally reads commands interactively | 103 | c) If the modified program normally reads commands interactively |
104 | when run, you must cause it, when started running for such | 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 | 105 | interactive use in the most ordinary way, to print or display an |
106 | announcement including an appropriate copyright notice and a | 106 | announcement including an appropriate copyright notice and a |
107 | notice that there is no warranty (or else, saying that you provide | 107 | notice that there is no warranty (or else, saying that you provide |
108 | a warranty) and that users may redistribute the program under | 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 | 109 | these conditions, and telling the user how to view a copy of this |
110 | License. (Exception: if the Program itself is interactive but | 110 | License. (Exception: if the Program itself is interactive but |
111 | does not normally print such an announcement, your work based on | 111 | does not normally print such an announcement, your work based on |
112 | the Program is not required to print an announcement.) | 112 | the Program is not required to print an announcement.) |
113 | 113 | ||
114 | These requirements apply to the modified work as a whole. If | 114 | These requirements apply to the modified work as a whole. If |
115 | identifiable sections of that work are not derived from the Program, | 115 | identifiable sections of that work are not derived from the Program, |
116 | and can be reasonably considered independent and separate works in | 116 | and can be reasonably considered independent and separate works in |
117 | themselves, then this License, and its terms, do not apply to those | 117 | themselves, then this License, and its terms, do not apply to those |
118 | sections when you distribute them as separate works. But when you | 118 | sections when you distribute them as separate works. But when you |
119 | distribute the same sections as part of a whole which is a work based | 119 | distribute the same sections as part of a whole which is a work based |
120 | on the Program, the distribution of the whole must be on the terms of | 120 | on the Program, the distribution of the whole must be on the terms of |
121 | this License, whose permissions for other licensees extend to the | 121 | this License, whose permissions for other licensees extend to the |
122 | entire whole, and thus to each and every part regardless of who wrote it. | 122 | entire whole, and thus to each and every part regardless of who wrote it. |
123 | 123 | ||
124 | Thus, it is not the intent of this section to claim rights or contest | 124 | Thus, it is not the intent of this section to claim rights or contest |
125 | your rights to work written entirely by you; rather, the intent is to | 125 | your rights to work written entirely by you; rather, the intent is to |
126 | exercise the right to control the distribution of derivative or | 126 | exercise the right to control the distribution of derivative or |
127 | collective works based on the Program. | 127 | collective works based on the Program. |
128 | 128 | ||
129 | In addition, mere aggregation of another work not based on the Program | 129 | In addition, mere aggregation of another work not based on the Program |
130 | with the Program (or with a work based on the Program) on a volume of | 130 | with the Program (or with a work based on the Program) on a volume of |
131 | a storage or distribution medium does not bring the other work under | 131 | a storage or distribution medium does not bring the other work under |
132 | the scope of this License. | 132 | the scope of this License. |
133 | 133 | ||
134 | 3. You may copy and distribute the Program (or a work based on it, | 134 | 3. You may copy and distribute the Program (or a work based on it, |
135 | under Section 2) in object code or executable form under the terms of | 135 | under Section 2) in object code or executable form under the terms of |
136 | Sections 1 and 2 above provided that you also do one of the following: | 136 | Sections 1 and 2 above provided that you also do one of the following: |
137 | 137 | ||
138 | a) Accompany it with the complete corresponding machine-readable | 138 | a) Accompany it with the complete corresponding machine-readable |
139 | source code, which must be distributed under the terms of Sections | 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, | 140 | 1 and 2 above on a medium customarily used for software interchange; or, |
141 | 141 | ||
142 | b) Accompany it with a written offer, valid for at least three | 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 | 143 | years, to give any third party, for a charge no more than your |
144 | cost of physically performing source distribution, a complete | 144 | cost of physically performing source distribution, a complete |
145 | machine-readable copy of the corresponding source code, to be | 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 | 146 | distributed under the terms of Sections 1 and 2 above on a medium |
147 | customarily used for software interchange; or, | 147 | customarily used for software interchange; or, |
148 | 148 | ||
149 | c) Accompany it with the information you received as to the offer | 149 | c) Accompany it with the information you received as to the offer |
150 | to distribute corresponding source code. (This alternative is | 150 | to distribute corresponding source code. (This alternative is |
151 | allowed only for noncommercial distribution and only if you | 151 | allowed only for noncommercial distribution and only if you |
152 | received the program in object code or executable form with such | 152 | received the program in object code or executable form with such |
153 | an offer, in accord with Subsection b above.) | 153 | an offer, in accord with Subsection b above.) |
154 | 154 | ||
155 | The source code for a work means the preferred form of the work for | 155 | The source code for a work means the preferred form of the work for |
156 | making modifications to it. For an executable work, complete source | 156 | making modifications to it. For an executable work, complete source |
157 | code means all the source code for all modules it contains, plus any | 157 | code means all the source code for all modules it contains, plus any |
158 | associated interface definition files, plus the scripts used to | 158 | associated interface definition files, plus the scripts used to |
159 | control compilation and installation of the executable. However, as a | 159 | control compilation and installation of the executable. However, as a |
160 | special exception, the source code distributed need not include | 160 | special exception, the source code distributed need not include |
161 | anything that is normally distributed (in either source or binary | 161 | anything that is normally distributed (in either source or binary |
162 | form) with the major components (compiler, kernel, and so on) of the | 162 | form) with the major components (compiler, kernel, and so on) of the |
163 | operating system on which the executable runs, unless that component | 163 | operating system on which the executable runs, unless that component |
164 | itself accompanies the executable. | 164 | itself accompanies the executable. |
165 | 165 | ||
166 | If distribution of executable or object code is made by offering | 166 | If distribution of executable or object code is made by offering |
167 | access to copy from a designated place, then offering equivalent | 167 | access to copy from a designated place, then offering equivalent |
168 | access to copy the source code from the same place counts as | 168 | access to copy the source code from the same place counts as |
169 | distribution of the source code, even though third parties are not | 169 | distribution of the source code, even though third parties are not |
170 | compelled to copy the source along with the object code. | 170 | compelled to copy the source along with the object code. |
171 | 171 | ||
172 | 4. You may not copy, modify, sublicense, or distribute the Program | 172 | 4. You may not copy, modify, sublicense, or distribute the Program |
173 | except as expressly provided under this License. Any attempt | 173 | except as expressly provided under this License. Any attempt |
174 | otherwise to copy, modify, sublicense or distribute the Program is | 174 | otherwise to copy, modify, sublicense or distribute the Program is |
175 | void, and will automatically terminate your rights under this License. | 175 | void, and will automatically terminate your rights under this License. |
176 | However, parties who have received copies, or rights, from you under | 176 | However, parties who have received copies, or rights, from you under |
177 | this License will not have their licenses terminated so long as such | 177 | this License will not have their licenses terminated so long as such |
178 | parties remain in full compliance. | 178 | parties remain in full compliance. |
179 | 179 | ||
180 | 5. You are not required to accept this License, since you have not | 180 | 5. You are not required to accept this License, since you have not |
181 | signed it. However, nothing else grants you permission to modify or | 181 | signed it. However, nothing else grants you permission to modify or |
182 | distribute the Program or its derivative works. These actions are | 182 | distribute the Program or its derivative works. These actions are |
183 | prohibited by law if you do not accept this License. Therefore, by | 183 | prohibited by law if you do not accept this License. Therefore, by |
184 | modifying or distributing the Program (or any work based on the | 184 | modifying or distributing the Program (or any work based on the |
185 | Program), you indicate your acceptance of this License to do so, and | 185 | Program), you indicate your acceptance of this License to do so, and |
186 | all its terms and conditions for copying, distributing or modifying | 186 | all its terms and conditions for copying, distributing or modifying |
187 | the Program or works based on it. | 187 | the Program or works based on it. |
188 | 188 | ||
189 | 6. Each time you redistribute the Program (or any work based on the | 189 | 6. Each time you redistribute the Program (or any work based on the |
190 | Program), the recipient automatically receives a license from the | 190 | Program), the recipient automatically receives a license from the |
191 | original licensor to copy, distribute or modify the Program subject to | 191 | original licensor to copy, distribute or modify the Program subject to |
192 | these terms and conditions. You may not impose any further | 192 | these terms and conditions. You may not impose any further |
193 | restrictions on the recipients' exercise of the rights granted herein. | 193 | restrictions on the recipients' exercise of the rights granted herein. |
194 | You are not responsible for enforcing compliance by third parties to | 194 | You are not responsible for enforcing compliance by third parties to |
195 | this License. | 195 | this License. |
196 | 196 | ||
197 | 7. If, as a consequence of a court judgment or allegation of patent | 197 | 7. If, as a consequence of a court judgment or allegation of patent |
198 | infringement or for any other reason (not limited to patent issues), | 198 | infringement or for any other reason (not limited to patent issues), |
199 | conditions are imposed on you (whether by court order, agreement or | 199 | conditions are imposed on you (whether by court order, agreement or |
200 | otherwise) that contradict the conditions of this License, they do not | 200 | otherwise) that contradict the conditions of this License, they do not |
201 | excuse you from the conditions of this License. If you cannot | 201 | excuse you from the conditions of this License. If you cannot |
202 | distribute so as to satisfy simultaneously your obligations under this | 202 | distribute so as to satisfy simultaneously your obligations under this |
203 | License and any other pertinent obligations, then as a consequence you | 203 | License and any other pertinent obligations, then as a consequence you |
204 | may not distribute the Program at all. For example, if a patent | 204 | may not distribute the Program at all. For example, if a patent |
205 | license would not permit royalty-free redistribution of the Program by | 205 | license would not permit royalty-free redistribution of the Program by |
206 | all those who receive copies directly or indirectly through you, then | 206 | all those who receive copies directly or indirectly through you, then |
207 | the only way you could satisfy both it and this License would be to | 207 | the only way you could satisfy both it and this License would be to |
208 | refrain entirely from distribution of the Program. | 208 | refrain entirely from distribution of the Program. |
209 | 209 | ||
210 | If any portion of this section is held invalid or unenforceable under | 210 | If any portion of this section is held invalid or unenforceable under |
211 | any particular circumstance, the balance of the section is intended to | 211 | any particular circumstance, the balance of the section is intended to |
212 | apply and the section as a whole is intended to apply in other | 212 | apply and the section as a whole is intended to apply in other |
213 | circumstances. | 213 | circumstances. |
214 | 214 | ||
215 | It is not the purpose of this section to induce you to infringe any | 215 | It is not the purpose of this section to induce you to infringe any |
216 | patents or other property right claims or to contest validity of any | 216 | patents or other property right claims or to contest validity of any |
217 | such claims; this section has the sole purpose of protecting the | 217 | such claims; this section has the sole purpose of protecting the |
218 | integrity of the free software distribution system, which is | 218 | integrity of the free software distribution system, which is |
219 | implemented by public license practices. Many people have made | 219 | implemented by public license practices. Many people have made |
220 | generous contributions to the wide range of software distributed | 220 | generous contributions to the wide range of software distributed |
221 | through that system in reliance on consistent application of that | 221 | through that system in reliance on consistent application of that |
222 | system; it is up to the author/donor to decide if he or she is willing | 222 | system; it is up to the author/donor to decide if he or she is willing |
223 | to distribute software through any other system and a licensee cannot | 223 | to distribute software through any other system and a licensee cannot |
224 | impose that choice. | 224 | impose that choice. |
225 | 225 | ||
226 | This section is intended to make thoroughly clear what is believed to | 226 | This section is intended to make thoroughly clear what is believed to |
227 | be a consequence of the rest of this License. | 227 | be a consequence of the rest of this License. |
228 | 228 | ||
229 | 8. If the distribution and/or use of the Program is restricted in | 229 | 8. If the distribution and/or use of the Program is restricted in |
230 | certain countries either by patents or by copyrighted interfaces, the | 230 | certain countries either by patents or by copyrighted interfaces, the |
231 | original copyright holder who places the Program under this License | 231 | original copyright holder who places the Program under this License |
232 | may add an explicit geographical distribution limitation excluding | 232 | may add an explicit geographical distribution limitation excluding |
233 | those countries, so that distribution is permitted only in or among | 233 | those countries, so that distribution is permitted only in or among |
234 | countries not thus excluded. In such case, this License incorporates | 234 | countries not thus excluded. In such case, this License incorporates |
235 | the limitation as if written in the body of this License. | 235 | the limitation as if written in the body of this License. |
236 | 236 | ||
237 | 9. The Free Software Foundation may publish revised and/or new versions | 237 | 9. The Free Software Foundation may publish revised and/or new versions |
238 | of the General Public License from time to time. Such new versions will | 238 | of the General Public License from time to time. Such new versions will |
239 | be similar in spirit to the present version, but may differ in detail to | 239 | be similar in spirit to the present version, but may differ in detail to |
240 | address new problems or concerns. | 240 | address new problems or concerns. |
241 | 241 | ||
242 | Each version is given a distinguishing version number. If the Program | 242 | Each version is given a distinguishing version number. If the Program |
243 | specifies a version number of this License which applies to it and "any | 243 | specifies a version number of this License which applies to it and "any |
244 | later version", you have the option of following the terms and conditions | 244 | later version", you have the option of following the terms and conditions |
245 | either of that version or of any later version published by the Free | 245 | either of that version or of any later version published by the Free |
246 | Software Foundation. If the Program does not specify a version number of | 246 | Software Foundation. If the Program does not specify a version number of |
247 | this License, you may choose any version ever published by the Free Software | 247 | this License, you may choose any version ever published by the Free Software |
248 | Foundation. | 248 | Foundation. |
249 | 249 | ||
250 | 10. If you wish to incorporate parts of the Program into other free | 250 | 10. If you wish to incorporate parts of the Program into other free |
251 | programs whose distribution conditions are different, write to the author | 251 | programs whose distribution conditions are different, write to the author |
252 | to ask for permission. For software which is copyrighted by the Free | 252 | to ask for permission. For software which is copyrighted by the Free |
253 | Software Foundation, write to the Free Software Foundation; we sometimes | 253 | Software Foundation, write to the Free Software Foundation; we sometimes |
254 | make exceptions for this. Our decision will be guided by the two goals | 254 | make exceptions for this. Our decision will be guided by the two goals |
255 | of preserving the free status of all derivatives of our free software and | 255 | of preserving the free status of all derivatives of our free software and |
256 | of promoting the sharing and reuse of software generally. | 256 | of promoting the sharing and reuse of software generally. |
257 | 257 | ||
258 | NO WARRANTY | 258 | NO WARRANTY |
259 | 259 | ||
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED |
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS |
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE |
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, |
268 | REPAIR OR CORRECTION. | 268 | REPAIR OR CORRECTION. |
269 | 269 | ||
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED |
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY |
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
278 | POSSIBILITY OF SUCH DAMAGES. | 278 | POSSIBILITY OF SUCH DAMAGES. |
279 | 279 | ||
280 | END OF TERMS AND CONDITIONS | 280 | END OF TERMS AND CONDITIONS |
281 | 281 | ||
282 | How to Apply These Terms to Your New Programs | 282 | How to Apply These Terms to Your New Programs |
283 | 283 | ||
284 | If you develop a new program, and you want it to be of the greatest | 284 | If you develop a new program, and you want it to be of the greatest |
285 | possible use to the public, the best way to achieve this is to make it | 285 | possible use to the public, the best way to achieve this is to make it |
286 | free software which everyone can redistribute and change under these terms. | 286 | free software which everyone can redistribute and change under these terms. |
287 | 287 | ||
288 | To do so, attach the following notices to the program. It is safest | 288 | To do so, attach the following notices to the program. It is safest |
289 | to attach them to the start of each source file to most effectively | 289 | to attach them to the start of each source file to most effectively |
290 | convey the exclusion of warranty; and each file should have at least | 290 | convey the exclusion of warranty; and each file should have at least |
291 | the "copyright" line and a pointer to where the full notice is found. | 291 | the "copyright" line and a pointer to where the full notice is found. |
292 | 292 | ||
293 | <one line to give the program's name and a brief idea of what it does.> | 293 | <one line to give the program's name and a brief idea of what it does.> |
294 | Copyright (C) <year> <name of author> | 294 | Copyright (C) <year> <name of author> |
295 | 295 | ||
296 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 298 | the Free Software Foundation; either version 2 of the License, or |
299 | (at your option) any later version. | 299 | (at your option) any later version. |
300 | 300 | ||
301 | This program is distributed in the hope that it will be useful, | 301 | This program is distributed in the hope that it will be useful, |
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
304 | GNU General Public License for more details. | 304 | GNU General Public License for more details. |
305 | 305 | ||
306 | You should have received a copy of the GNU General Public License | 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 | 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 | 308 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
309 | 309 | ||
310 | 310 | ||
311 | Also add information on how to contact you by electronic and paper mail. | 311 | Also add information on how to contact you by electronic and paper mail. |
312 | 312 | ||
313 | If the program is interactive, make it output a short notice like this | 313 | If the program is interactive, make it output a short notice like this |
314 | when it starts in an interactive mode: | 314 | when it starts in an interactive mode: |
315 | 315 | ||
316 | Gnomovision version 69, Copyright (C) year name of author | 316 | Gnomovision version 69, Copyright (C) year name of author |
317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
318 | This is free software, and you are welcome to redistribute it | 318 | This is free software, and you are welcome to redistribute it |
319 | under certain conditions; type `show c' for details. | 319 | under certain conditions; type `show c' for details. |
320 | 320 | ||
321 | The hypothetical commands `show w' and `show c' should show the appropriate | 321 | The hypothetical commands `show w' and `show c' should show the appropriate |
322 | parts of the General Public License. Of course, the commands you use may | 322 | parts of the General Public License. Of course, the commands you use may |
323 | be called something other than `show w' and `show c'; they could even be | 323 | be called something other than `show w' and `show c'; they could even be |
324 | mouse-clicks or menu items--whatever suits your program. | 324 | mouse-clicks or menu items--whatever suits your program. |
325 | 325 | ||
326 | You should also get your employer (if you work as a programmer) or your | 326 | You should also get your employer (if you work as a programmer) or your |
327 | school, if any, to sign a "copyright disclaimer" for the program, if | 327 | school, if any, to sign a "copyright disclaimer" for the program, if |
328 | necessary. Here is a sample; alter the names: | 328 | necessary. Here is a sample; alter the names: |
329 | 329 | ||
330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program |
331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. | 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. |
332 | 332 | ||
333 | <signature of Ty Coon>, 1 April 1989 | 333 | <signature of Ty Coon>, 1 April 1989 |
334 | Ty Coon, President of Vice | 334 | Ty Coon, President of Vice |
335 | 335 | ||
336 | This General Public License does not permit incorporating your program into | 336 | This General Public License does not permit incorporating your program into |
337 | proprietary programs. If your program is a subroutine library, you may | 337 | proprietary programs. If your program is a subroutine library, you may |
338 | consider it more useful to permit linking proprietary applications with the | 338 | consider it more useful to permit linking proprietary applications with the |
339 | library. If this is what you want to do, use the GNU Library General | 339 | library. If this is what you want to do, use the GNU Library General |
340 | Public License instead of this License. | 340 | Public 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 index 40a0c8e..d956717 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/LICENSE | |||
@@ -1,50 +1,50 @@ | |||
1 | --------------------------------------------------------------------------- | 1 | --------------------------------------------------------------------------- |
2 | 2 | ||
3 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. | 3 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. |
4 | 4 | ||
5 | This software is provided "as is," without warranty of any kind, | 5 | This software is provided "as is," without warranty of any kind, |
6 | express or implied. In no event shall the author or contributors | 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 | 7 | be held liable for any damages arising in any way from the use of |
8 | this software. | 8 | this software. |
9 | 9 | ||
10 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 11 | redistribute this software according to the terms of one of the |
12 | following two licenses (at your option): | 12 | following two licenses (at your option): |
13 | 13 | ||
14 | 14 | ||
15 | LICENSE 1 ("BSD-like with advertising clause"): | 15 | LICENSE 1 ("BSD-like with advertising clause"): |
16 | 16 | ||
17 | Permission is granted to anyone to use this software for any purpose, | 17 | Permission is granted to anyone to use this software for any purpose, |
18 | including commercial applications, and to alter it and redistribute | 18 | including commercial applications, and to alter it and redistribute |
19 | it freely, subject to the following restrictions: | 19 | it freely, subject to the following restrictions: |
20 | 20 | ||
21 | 1. Redistributions of source code must retain the above copyright | 21 | 1. Redistributions of source code must retain the above copyright |
22 | notice, disclaimer, and this list of conditions. | 22 | notice, disclaimer, and this list of conditions. |
23 | 2. Redistributions in binary form must reproduce the above copyright | 23 | 2. Redistributions in binary form must reproduce the above copyright |
24 | notice, disclaimer, and this list of conditions in the documenta- | 24 | notice, disclaimer, and this list of conditions in the documenta- |
25 | tion and/or other materials provided with the distribution. | 25 | tion and/or other materials provided with the distribution. |
26 | 3. All advertising materials mentioning features or use of this | 26 | 3. All advertising materials mentioning features or use of this |
27 | software must display the following acknowledgment: | 27 | software must display the following acknowledgment: |
28 | 28 | ||
29 | This product includes software developed by Greg Roelofs | 29 | This product includes software developed by Greg Roelofs |
30 | and contributors for the book, "PNG: The Definitive Guide," | 30 | and contributors for the book, "PNG: The Definitive Guide," |
31 | published by O'Reilly and Associates. | 31 | published by O'Reilly and Associates. |
32 | 32 | ||
33 | 33 | ||
34 | LICENSE 2 (GNU GPL v2 or later): | 34 | LICENSE 2 (GNU GPL v2 or later): |
35 | 35 | ||
36 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 38 | the Free Software Foundation; either version 2 of the License, or |
39 | (at your option) any later version. | 39 | (at your option) any later version. |
40 | 40 | ||
41 | This program is distributed in the hope that it will be useful, | 41 | This program is distributed in the hope that it will be useful, |
42 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 42 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 43 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
44 | GNU General Public License for more details. | 44 | GNU General Public License for more details. |
45 | 45 | ||
46 | You should have received a copy of the GNU General Public License | 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, | 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 | 48 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
49 | 49 | ||
50 | --------------------------------------------------------------------------- | 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 index a736556..e70a59a 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32 +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.mingw32 | |||
@@ -1,130 +1,130 @@ | |||
1 | # Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make. | 1 | # Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make. |
2 | # Greg Roelofs | 2 | # Greg Roelofs |
3 | # Last modified: 2 June 2007 | 3 | # Last modified: 2 June 2007 |
4 | # | 4 | # |
5 | # The programs built by this makefile are described in the book, | 5 | # The programs built by this makefile are described in the book, |
6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and | 6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and |
7 | # Associates, 1999). Go buy a copy, eh? Well, OK, it's not | 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, | 8 | # generally for sale anymore, but it's the thought that counts, |
9 | # right? (Hint: http://www.libpng.org/pub/png/book/ ) | 9 | # right? (Hint: http://www.libpng.org/pub/png/book/ ) |
10 | # | 10 | # |
11 | # Invoke this makefile from a DOS-prompt window via: | 11 | # Invoke this makefile from a DOS-prompt window via: |
12 | # | 12 | # |
13 | # make -f Makefile.mingw32 | 13 | # make -f Makefile.mingw32 |
14 | # | 14 | # |
15 | # This makefile assumes libpng and zlib have already been built or downloaded | 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 | 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 | 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. | 18 | # at all about the mingw32 installation tree (W32DIR). Edit as appropriate. |
19 | # | 19 | # |
20 | # Note that the names of the dynamic and static libpng and zlib libraries | 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 | 21 | # used below may change in later releases of the libraries. This makefile |
22 | # builds both statically and dynamically linked executables by default. | 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.) | 23 | # (You need only one set, but for testing it can be handy to have both.) |
24 | 24 | ||
25 | 25 | ||
26 | # macros -------------------------------------------------------------------- | 26 | # macros -------------------------------------------------------------------- |
27 | 27 | ||
28 | #PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds | 28 | #PNGDIR = ../..# for libpng-x.y.z/contrib/gregbook builds |
29 | PNGDIR = ../libpng-win32 | 29 | PNGDIR = ../libpng-win32 |
30 | PNGINC = -I$(PNGDIR) | 30 | PNGINC = -I$(PNGDIR) |
31 | PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked | 31 | PNGLIBd = $(PNGDIR)/libpng.dll.a # dynamically linked |
32 | PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng | 32 | PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng |
33 | 33 | ||
34 | #ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds | 34 | #ZDIR = ../../../zlib-win32# for libpng-x.y.z/contrib/gregbook builds |
35 | ZDIR = ../zlib-win32 | 35 | ZDIR = ../zlib-win32 |
36 | ZINC = -I$(ZDIR) | 36 | ZINC = -I$(ZDIR) |
37 | ZLIBd = $(ZDIR)/libzdll.a | 37 | ZLIBd = $(ZDIR)/libzdll.a |
38 | ZLIBs = $(ZDIR)/libz.a | 38 | ZLIBs = $(ZDIR)/libz.a |
39 | 39 | ||
40 | # change this to be the path where mingw32 installs its stuff: | 40 | # change this to be the path where mingw32 installs its stuff: |
41 | W32DIR = | 41 | W32DIR = |
42 | #W32DIR = /usr/local/cross-tools/i386-mingw32msvc | 42 | #W32DIR = /usr/local/cross-tools/i386-mingw32msvc |
43 | W32INC = -I$(W32DIR)/include | 43 | W32INC = -I$(W32DIR)/include |
44 | W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a | 44 | W32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a |
45 | 45 | ||
46 | CC = gcc | 46 | CC = gcc |
47 | #CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation | 47 | #CC = i386-mingw32msvc-gcc # e.g., Linux -> Win32 cross-compilation |
48 | LD = $(CC) | 48 | LD = $(CC) |
49 | RM = rm -f | 49 | RM = rm -f |
50 | CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS) | 50 | CFLAGS = -O -Wall $(INCS) $(MINGW_CCFLAGS) |
51 | # [note that -Wall is a gcc-specific compilation flag ("most warnings on")] | 51 | # [note that -Wall is a gcc-specific compilation flag ("most warnings on")] |
52 | # [-ansi, -pedantic and -W can also be used] | 52 | # [-ansi, -pedantic and -W can also be used] |
53 | LDFLAGS = $(MINGW_LDFLAGS) | 53 | LDFLAGS = $(MINGW_LDFLAGS) |
54 | O = .o | 54 | O = .o |
55 | E = .exe | 55 | E = .exe |
56 | 56 | ||
57 | INCS = $(PNGINC) $(ZINC) $(W32INC) | 57 | INCS = $(PNGINC) $(ZINC) $(W32INC) |
58 | RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm | 58 | RLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm |
59 | RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm | 59 | RLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm |
60 | WLIBSd = $(PNGLIBd) $(ZLIBd) | 60 | WLIBSd = $(PNGLIBd) $(ZLIBd) |
61 | WLIBSs = $(PNGLIBs) $(ZLIBs) | 61 | WLIBSs = $(PNGLIBs) $(ZLIBs) |
62 | 62 | ||
63 | RPNG = rpng-win | 63 | RPNG = rpng-win |
64 | RPNG2 = rpng2-win | 64 | RPNG2 = rpng2-win |
65 | WPNG = wpng | 65 | WPNG = wpng |
66 | 66 | ||
67 | ROBJSd = $(RPNG)$(O) readpng.pic$(O) | 67 | ROBJSd = $(RPNG)$(O) readpng.pic$(O) |
68 | ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O) | 68 | ROBJS2d = $(RPNG2)$(O) readpng2.pic$(O) |
69 | WOBJSd = $(WPNG)$(O) writepng.pic$(O) | 69 | WOBJSd = $(WPNG)$(O) writepng.pic$(O) |
70 | 70 | ||
71 | RPNGs = $(RPNG)-static | 71 | RPNGs = $(RPNG)-static |
72 | RPNG2s = $(RPNG2)-static | 72 | RPNG2s = $(RPNG2)-static |
73 | WPNGs = $(WPNG)-static | 73 | WPNGs = $(WPNG)-static |
74 | 74 | ||
75 | ROBJSs = $(RPNG)$(O) readpng$(O) | 75 | ROBJSs = $(RPNG)$(O) readpng$(O) |
76 | ROBJS2s = $(RPNG2)$(O) readpng2$(O) | 76 | ROBJS2s = $(RPNG2)$(O) readpng2$(O) |
77 | WOBJSs = $(WPNG)$(O) writepng$(O) | 77 | WOBJSs = $(WPNG)$(O) writepng$(O) |
78 | 78 | ||
79 | STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) | 79 | STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) |
80 | DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) | 80 | DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) |
81 | 81 | ||
82 | EXES = $(STATIC_EXES) $(DYNAMIC_EXES) | 82 | EXES = $(STATIC_EXES) $(DYNAMIC_EXES) |
83 | 83 | ||
84 | 84 | ||
85 | # implicit make rules ------------------------------------------------------- | 85 | # implicit make rules ------------------------------------------------------- |
86 | 86 | ||
87 | .c$(O): | 87 | .c$(O): |
88 | $(CC) -c $(CFLAGS) $< | 88 | $(CC) -c $(CFLAGS) $< |
89 | 89 | ||
90 | %.pic$(O): %.c | 90 | %.pic$(O): %.c |
91 | $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $< | 91 | $(CC) -c $(CFLAGS) -DPNG_BUILD_DLL -o $@ $< |
92 | 92 | ||
93 | 93 | ||
94 | # dependencies -------------------------------------------------------------- | 94 | # dependencies -------------------------------------------------------------- |
95 | 95 | ||
96 | all: $(EXES) | 96 | all: $(EXES) |
97 | 97 | ||
98 | $(RPNGs)$(E): $(ROBJSs) | 98 | $(RPNGs)$(E): $(ROBJSs) |
99 | $(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs) | 99 | $(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs) |
100 | 100 | ||
101 | $(RPNG)$(E): $(ROBJSd) | 101 | $(RPNG)$(E): $(ROBJSd) |
102 | $(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd) | 102 | $(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd) |
103 | 103 | ||
104 | $(RPNG2s)$(E): $(ROBJS2s) | 104 | $(RPNG2s)$(E): $(ROBJS2s) |
105 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs) | 105 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs) |
106 | 106 | ||
107 | $(RPNG2)$(E): $(ROBJS2d) | 107 | $(RPNG2)$(E): $(ROBJS2d) |
108 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd) | 108 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd) |
109 | 109 | ||
110 | $(WPNGs)$(E): $(WOBJSs) | 110 | $(WPNGs)$(E): $(WOBJSs) |
111 | $(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs) | 111 | $(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs) |
112 | 112 | ||
113 | $(WPNG)$(E): $(WOBJSd) | 113 | $(WPNG)$(E): $(WOBJSd) |
114 | $(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd) | 114 | $(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd) |
115 | 115 | ||
116 | $(RPNG)$(O): $(RPNG).c readpng.h | 116 | $(RPNG)$(O): $(RPNG).c readpng.h |
117 | $(RPNG2)$(O): $(RPNG2).c readpng2.h | 117 | $(RPNG2)$(O): $(RPNG2).c readpng2.h |
118 | $(WPNG)$(O): $(WPNG).c writepng.h | 118 | $(WPNG)$(O): $(WPNG).c writepng.h |
119 | 119 | ||
120 | readpng$(O) readpng.pic$(O): readpng.c readpng.h | 120 | readpng$(O) readpng.pic$(O): readpng.c readpng.h |
121 | readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h | 121 | readpng2$(O) readpng2.pic$(O): readpng2.c readpng2.h |
122 | writepng$(O) writepng.pic$(O): writepng.c writepng.h | 122 | writepng$(O) writepng.pic$(O): writepng.c writepng.h |
123 | 123 | ||
124 | 124 | ||
125 | # maintenance --------------------------------------------------------------- | 125 | # maintenance --------------------------------------------------------------- |
126 | 126 | ||
127 | clean: | 127 | clean: |
128 | $(RM) $(EXES) | 128 | $(RM) $(EXES) |
129 | $(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs) | 129 | $(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs) |
130 | $(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd) | 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 index 8773a00..91623ac 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.sgi | |||
@@ -1,104 +1,104 @@ | |||
1 | # Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make. | 1 | # Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make. |
2 | # Greg Roelofs | 2 | # Greg Roelofs |
3 | # Last modified: 7 March 2002 | 3 | # Last modified: 7 March 2002 |
4 | # | 4 | # |
5 | # The programs built by this makefile are described in the book, | 5 | # The programs built by this makefile are described in the book, |
6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and | 6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and |
7 | # Associates, 1999). Go buy a copy, eh? Buy some for friends | 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.) | 8 | # and family, too. (Not that this is a blatant plug or anything.) |
9 | # | 9 | # |
10 | # Invoke this makefile from a shell prompt in the usual way; for example: | 10 | # Invoke this makefile from a shell prompt in the usual way; for example: |
11 | # | 11 | # |
12 | # make -f Makefile.sgi | 12 | # make -f Makefile.sgi |
13 | # | 13 | # |
14 | # This makefile assumes libpng and zlib have already been built or downloaded | 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 | 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 | 16 | # PNG* and Z* macros below). Edit as appropriate--choose only ONE each of |
17 | # the PNGINC, PNGLIB, ZINC and ZLIB lines. | 17 | # the PNGINC, PNGLIB, ZINC and ZLIB lines. |
18 | # | 18 | # |
19 | # This makefile builds dynamically linked executables (against libpng and zlib, | 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 | 20 | # that is), but that can be changed by uncommenting the appropriate PNGLIB and |
21 | # ZLIB lines. | 21 | # ZLIB lines. |
22 | 22 | ||
23 | 23 | ||
24 | # macros -------------------------------------------------------------------- | 24 | # macros -------------------------------------------------------------------- |
25 | 25 | ||
26 | PNGINC = -I/usr/local/include/libpng15 | 26 | PNGINC = -I/usr/local/include/libpng15 |
27 | PNGLIB = -L/usr/local/lib -lpng15 # dynamically linked against libpng | 27 | PNGLIB = -L/usr/local/lib -lpng15 # dynamically linked against libpng |
28 | #PNGLIB = /usr/local/lib/libpng15.a # statically linked against libpng | 28 | #PNGLIB = /usr/local/lib/libpng15.a # statically linked against libpng |
29 | # or: | 29 | # or: |
30 | #PNGINC = -I../.. | 30 | #PNGINC = -I../.. |
31 | #PNGLIB = -L../.. -lpng | 31 | #PNGLIB = -L../.. -lpng |
32 | #PNGLIB = ../../libpng.a | 32 | #PNGLIB = ../../libpng.a |
33 | 33 | ||
34 | ZINC = -I/usr/local/include | 34 | ZINC = -I/usr/local/include |
35 | ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib | 35 | ZLIB = -L/usr/local/lib -lz # dynamically linked against zlib |
36 | #ZLIB = /usr/local/lib/libz.a # statically linked against zlib | 36 | #ZLIB = /usr/local/lib/libz.a # statically linked against zlib |
37 | #ZINC = -I../zlib | 37 | #ZINC = -I../zlib |
38 | #ZLIB = -L../zlib -lz | 38 | #ZLIB = -L../zlib -lz |
39 | #ZLIB = ../../../zlib/libz.a | 39 | #ZLIB = ../../../zlib/libz.a |
40 | 40 | ||
41 | XINC = -I/usr/include/X11 # old-style, stock X distributions | 41 | XINC = -I/usr/include/X11 # old-style, stock X distributions |
42 | XLIB = -L/usr/lib/X11 -lX11 | 42 | XLIB = -L/usr/lib/X11 -lX11 |
43 | #XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) | 43 | #XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) |
44 | #XLIB = -L/usr/openwin/lib -lX11 | 44 | #XLIB = -L/usr/openwin/lib -lX11 |
45 | #XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.) | 45 | #XINC = -I/usr/X11R6/include # new X distributions (XFree86, etc.) |
46 | #XLIB = -L/usr/X11R6/lib -lX11 | 46 | #XLIB = -L/usr/X11R6/lib -lX11 |
47 | 47 | ||
48 | INCS = $(PNGINC) $(ZINC) $(XINC) | 48 | INCS = $(PNGINC) $(ZINC) $(XINC) |
49 | RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm | 49 | RLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm |
50 | WLIBS = $(PNGLIB) $(ZLIB) | 50 | WLIBS = $(PNGLIB) $(ZLIB) |
51 | 51 | ||
52 | CC = cc | 52 | CC = cc |
53 | LD = cc | 53 | LD = cc |
54 | RM = rm -f | 54 | RM = rm -f |
55 | # ABI must be the same as that used to build libpng. | 55 | # ABI must be the same as that used to build libpng. |
56 | ABI= | 56 | ABI= |
57 | CFLAGS = $(ABI) -O -fullwarn $(INCS) | 57 | CFLAGS = $(ABI) -O -fullwarn $(INCS) |
58 | LDFLAGS = $(ABI) | 58 | LDFLAGS = $(ABI) |
59 | O = .o | 59 | O = .o |
60 | E = | 60 | E = |
61 | 61 | ||
62 | RPNG = rpng-x | 62 | RPNG = rpng-x |
63 | RPNG2 = rpng2-x | 63 | RPNG2 = rpng2-x |
64 | WPNG = wpng | 64 | WPNG = wpng |
65 | 65 | ||
66 | ROBJS = $(RPNG)$(O) readpng$(O) | 66 | ROBJS = $(RPNG)$(O) readpng$(O) |
67 | ROBJS2 = $(RPNG2)$(O) readpng2$(O) | 67 | ROBJS2 = $(RPNG2)$(O) readpng2$(O) |
68 | WOBJS = $(WPNG)$(O) writepng$(O) | 68 | WOBJS = $(WPNG)$(O) writepng$(O) |
69 | 69 | ||
70 | EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) | 70 | EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) |
71 | 71 | ||
72 | 72 | ||
73 | # implicit make rules ------------------------------------------------------- | 73 | # implicit make rules ------------------------------------------------------- |
74 | 74 | ||
75 | .c$(O): | 75 | .c$(O): |
76 | $(CC) -c $(CFLAGS) $< | 76 | $(CC) -c $(CFLAGS) $< |
77 | 77 | ||
78 | 78 | ||
79 | # dependencies -------------------------------------------------------------- | 79 | # dependencies -------------------------------------------------------------- |
80 | 80 | ||
81 | all: $(EXES) | 81 | all: $(EXES) |
82 | 82 | ||
83 | $(RPNG)$(E): $(ROBJS) | 83 | $(RPNG)$(E): $(ROBJS) |
84 | $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS) | 84 | $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS) |
85 | 85 | ||
86 | $(RPNG2)$(E): $(ROBJS2) | 86 | $(RPNG2)$(E): $(ROBJS2) |
87 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS) | 87 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS) |
88 | 88 | ||
89 | $(WPNG)$(E): $(WOBJS) | 89 | $(WPNG)$(E): $(WOBJS) |
90 | $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS) | 90 | $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS) |
91 | 91 | ||
92 | $(RPNG)$(O): $(RPNG).c readpng.h | 92 | $(RPNG)$(O): $(RPNG).c readpng.h |
93 | $(RPNG2)$(O): $(RPNG2).c readpng2.h | 93 | $(RPNG2)$(O): $(RPNG2).c readpng2.h |
94 | $(WPNG)$(O): $(WPNG).c writepng.h | 94 | $(WPNG)$(O): $(WPNG).c writepng.h |
95 | 95 | ||
96 | readpng$(O): readpng.c readpng.h | 96 | readpng$(O): readpng.c readpng.h |
97 | readpng2$(O): readpng2.c readpng2.h | 97 | readpng2$(O): readpng2.c readpng2.h |
98 | writepng$(O): writepng.c writepng.h | 98 | writepng$(O): writepng.c writepng.h |
99 | 99 | ||
100 | 100 | ||
101 | # maintenance --------------------------------------------------------------- | 101 | # maintenance --------------------------------------------------------------- |
102 | 102 | ||
103 | clean: | 103 | clean: |
104 | $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) | 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 index 3bffc2f..b52d8b6 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.unx | |||
@@ -1,132 +1,132 @@ | |||
1 | # Sample makefile for rpng-x / rpng2-x / wpng using gcc and make. | 1 | # Sample makefile for rpng-x / rpng2-x / wpng using gcc and make. |
2 | # Greg Roelofs | 2 | # Greg Roelofs |
3 | # Last modified: 2 June 2007 | 3 | # Last modified: 2 June 2007 |
4 | # | 4 | # |
5 | # The programs built by this makefile are described in the book, | 5 | # The programs built by this makefile are described in the book, |
6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and | 6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and |
7 | # Associates, 1999). Go buy a copy, eh? Well, OK, it's not | 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, | 8 | # generally for sale anymore, but it's the thought that counts, |
9 | # right? (Hint: http://www.libpng.org/pub/png/book/ ) | 9 | # right? (Hint: http://www.libpng.org/pub/png/book/ ) |
10 | # | 10 | # |
11 | # Invoke this makefile from a shell prompt in the usual way; for example: | 11 | # Invoke this makefile from a shell prompt in the usual way; for example: |
12 | # | 12 | # |
13 | # make -f Makefile.unx | 13 | # make -f Makefile.unx |
14 | # | 14 | # |
15 | # This makefile assumes libpng and zlib have already been built or downloaded | 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 | 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 | 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. | 18 | # the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines. |
19 | # | 19 | # |
20 | # This makefile builds both dynamically and statically linked executables | 20 | # This makefile builds both dynamically and statically linked executables |
21 | # (against libpng and zlib, that is), but that can be changed by modifying | 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 | 22 | # the "EXES =" line. (You need only one set, but for testing it can be handy |
23 | # to have both.) | 23 | # to have both.) |
24 | 24 | ||
25 | 25 | ||
26 | # macros -------------------------------------------------------------------- | 26 | # macros -------------------------------------------------------------------- |
27 | 27 | ||
28 | #PNGDIR = /usr/local/lib | 28 | #PNGDIR = /usr/local/lib |
29 | #PNGINC = -I/usr/local/include/libpng15 | 29 | #PNGINC = -I/usr/local/include/libpng15 |
30 | #PNGLIBd = -L$(PNGDIR) -lpng15 # dynamically linked, installed libpng | 30 | #PNGLIBd = -L$(PNGDIR) -lpng15 # dynamically linked, installed libpng |
31 | #PNGLIBs = $(PNGDIR)/libpng15.a # statically linked, installed libpng | 31 | #PNGLIBs = $(PNGDIR)/libpng15.a # statically linked, installed libpng |
32 | # or: | 32 | # or: |
33 | PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds | 33 | PNGDIR = ../..# this one is for libpng-x.y.z/contrib/gregbook builds |
34 | #PNGDIR = ../libpng | 34 | #PNGDIR = ../libpng |
35 | PNGINC = -I$(PNGDIR) | 35 | PNGINC = -I$(PNGDIR) |
36 | PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng15 # dynamically linked | 36 | PNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng15 # dynamically linked |
37 | PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng | 37 | PNGLIBs = $(PNGDIR)/libpng.a # statically linked, local libpng |
38 | 38 | ||
39 | ZDIR = /usr/local/lib | 39 | ZDIR = /usr/local/lib |
40 | #ZDIR = /usr/lib64 | 40 | #ZDIR = /usr/lib64 |
41 | ZINC = -I/usr/local/include | 41 | ZINC = -I/usr/local/include |
42 | ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib | 42 | ZLIBd = -L$(ZDIR) -lz # dynamically linked against zlib |
43 | ZLIBs = $(ZDIR)/libz.a # statically linked against zlib | 43 | ZLIBs = $(ZDIR)/libz.a # statically linked against zlib |
44 | # or: | 44 | # or: |
45 | #ZDIR = ../zlib | 45 | #ZDIR = ../zlib |
46 | #ZINC = -I$(ZDIR) | 46 | #ZINC = -I$(ZDIR) |
47 | #ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing | 47 | #ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz # -rpath allows in-place testing |
48 | #ZLIBs = $(ZDIR)/libz.a | 48 | #ZLIBs = $(ZDIR)/libz.a |
49 | 49 | ||
50 | #XINC = -I/usr/include # old-style, stock X distributions | 50 | #XINC = -I/usr/include # old-style, stock X distributions |
51 | #XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX) | 51 | #XLIB = -L/usr/lib/X11 -lX11 # (including SGI IRIX) |
52 | #XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) | 52 | #XINC = -I/usr/openwin/include # Sun workstations (OpenWindows) |
53 | #XLIB = -L/usr/openwin/lib -lX11 | 53 | #XLIB = -L/usr/openwin/lib -lX11 |
54 | XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.) | 54 | XINC = -I/usr/X11R6/include # new X distributions (X.org, etc.) |
55 | XLIB = -L/usr/X11R6/lib -lX11 | 55 | XLIB = -L/usr/X11R6/lib -lX11 |
56 | #XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64 | 56 | #XLIB = -L/usr/X11R6/lib64 -lX11 # e.g., Red Hat on AMD64 |
57 | 57 | ||
58 | INCS = $(PNGINC) $(ZINC) $(XINC) | 58 | INCS = $(PNGINC) $(ZINC) $(XINC) |
59 | RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm | 59 | RLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm |
60 | RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm | 60 | RLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm |
61 | WLIBSd = $(PNGLIBd) $(ZLIBd) -lm | 61 | WLIBSd = $(PNGLIBd) $(ZLIBd) -lm |
62 | WLIBSs = $(PNGLIBs) $(ZLIBs) | 62 | WLIBSs = $(PNGLIBs) $(ZLIBs) |
63 | 63 | ||
64 | CC = gcc | 64 | CC = gcc |
65 | LD = gcc | 65 | LD = gcc |
66 | RM = rm -f | 66 | RM = rm -f |
67 | CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP | 67 | CFLAGS = -O -Wall $(INCS) -DFEATURE_LOOP |
68 | # [note that -Wall is a gcc-specific compilation flag ("most warnings on")] | 68 | # [note that -Wall is a gcc-specific compilation flag ("most warnings on")] |
69 | # [-ansi, -pedantic and -W can also be used] | 69 | # [-ansi, -pedantic and -W can also be used] |
70 | LDFLAGS = | 70 | LDFLAGS = |
71 | O = .o | 71 | O = .o |
72 | E = | 72 | E = |
73 | 73 | ||
74 | RPNG = rpng-x | 74 | RPNG = rpng-x |
75 | RPNG2 = rpng2-x | 75 | RPNG2 = rpng2-x |
76 | WPNG = wpng | 76 | WPNG = wpng |
77 | 77 | ||
78 | RPNGs = $(RPNG)-static | 78 | RPNGs = $(RPNG)-static |
79 | RPNG2s = $(RPNG2)-static | 79 | RPNG2s = $(RPNG2)-static |
80 | WPNGs = $(WPNG)-static | 80 | WPNGs = $(WPNG)-static |
81 | 81 | ||
82 | ROBJS = $(RPNG)$(O) readpng$(O) | 82 | ROBJS = $(RPNG)$(O) readpng$(O) |
83 | ROBJS2 = $(RPNG2)$(O) readpng2$(O) | 83 | ROBJS2 = $(RPNG2)$(O) readpng2$(O) |
84 | WOBJS = $(WPNG)$(O) writepng$(O) | 84 | WOBJS = $(WPNG)$(O) writepng$(O) |
85 | 85 | ||
86 | STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) | 86 | STATIC_EXES = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E) |
87 | DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) | 87 | DYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) |
88 | 88 | ||
89 | EXES = $(STATIC_EXES) $(DYNAMIC_EXES) | 89 | EXES = $(STATIC_EXES) $(DYNAMIC_EXES) |
90 | 90 | ||
91 | 91 | ||
92 | # implicit make rules ------------------------------------------------------- | 92 | # implicit make rules ------------------------------------------------------- |
93 | 93 | ||
94 | .c$(O): | 94 | .c$(O): |
95 | $(CC) -c $(CFLAGS) $< | 95 | $(CC) -c $(CFLAGS) $< |
96 | 96 | ||
97 | 97 | ||
98 | # dependencies -------------------------------------------------------------- | 98 | # dependencies -------------------------------------------------------------- |
99 | 99 | ||
100 | all: $(EXES) | 100 | all: $(EXES) |
101 | 101 | ||
102 | $(RPNGs)$(E): $(ROBJS) | 102 | $(RPNGs)$(E): $(ROBJS) |
103 | $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs) | 103 | $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs) |
104 | 104 | ||
105 | $(RPNG)$(E): $(ROBJS) | 105 | $(RPNG)$(E): $(ROBJS) |
106 | $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd) | 106 | $(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd) |
107 | 107 | ||
108 | $(RPNG2s)$(E): $(ROBJS2) | 108 | $(RPNG2s)$(E): $(ROBJS2) |
109 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs) | 109 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs) |
110 | 110 | ||
111 | $(RPNG2)$(E): $(ROBJS2) | 111 | $(RPNG2)$(E): $(ROBJS2) |
112 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd) | 112 | $(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd) |
113 | 113 | ||
114 | $(WPNGs)$(E): $(WOBJS) | 114 | $(WPNGs)$(E): $(WOBJS) |
115 | $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs) | 115 | $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs) |
116 | 116 | ||
117 | $(WPNG)$(E): $(WOBJS) | 117 | $(WPNG)$(E): $(WOBJS) |
118 | $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd) | 118 | $(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd) |
119 | 119 | ||
120 | $(RPNG)$(O): $(RPNG).c readpng.h | 120 | $(RPNG)$(O): $(RPNG).c readpng.h |
121 | $(RPNG2)$(O): $(RPNG2).c readpng2.h | 121 | $(RPNG2)$(O): $(RPNG2).c readpng2.h |
122 | $(WPNG)$(O): $(WPNG).c writepng.h | 122 | $(WPNG)$(O): $(WPNG).c writepng.h |
123 | 123 | ||
124 | readpng$(O): readpng.c readpng.h | 124 | readpng$(O): readpng.c readpng.h |
125 | readpng2$(O): readpng2.c readpng2.h | 125 | readpng2$(O): readpng2.c readpng2.h |
126 | writepng$(O): writepng.c writepng.h | 126 | writepng$(O): writepng.c writepng.h |
127 | 127 | ||
128 | 128 | ||
129 | # maintenance --------------------------------------------------------------- | 129 | # maintenance --------------------------------------------------------------- |
130 | 130 | ||
131 | clean: | 131 | clean: |
132 | $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) | 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 index eced083..41cfb23 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32 +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/Makefile.w32 | |||
@@ -1,113 +1,113 @@ | |||
1 | # Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE. | 1 | # Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE. |
2 | # Greg Roelofs | 2 | # Greg Roelofs |
3 | # Last modified: 2 June 2007 | 3 | # Last modified: 2 June 2007 |
4 | # | 4 | # |
5 | # The programs built by this makefile are described in the book, | 5 | # The programs built by this makefile are described in the book, |
6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and | 6 | # "PNG: The Definitive Guide," by Greg Roelofs (O'Reilly and |
7 | # Associates, 1999). Go buy a copy, eh? Well, OK, it's not | 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, | 8 | # generally for sale anymore, but it's the thought that counts, |
9 | # right? (Hint: http://www.libpng.org/pub/png/book/ ) | 9 | # right? (Hint: http://www.libpng.org/pub/png/book/ ) |
10 | # | 10 | # |
11 | # Invoke this makefile from a DOS prompt window via: | 11 | # Invoke this makefile from a DOS prompt window via: |
12 | # | 12 | # |
13 | # %devstudio%\vc\bin\vcvars32.bat | 13 | # %devstudio%\vc\bin\vcvars32.bat |
14 | # nmake -nologo -f Makefile.w32 | 14 | # nmake -nologo -f Makefile.w32 |
15 | # | 15 | # |
16 | # where %devstudio% is the installation directory for MSVC / DevStudio. If | 16 | # where %devstudio% is the installation directory for MSVC / DevStudio. If |
17 | # you get "environment out of space" errors, create a desktop shortcut with | 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 | 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 | 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. | 20 | # DOS-prompt window with a bigger environment and retry the commands above. |
21 | # | 21 | # |
22 | # This makefile assumes libpng and zlib have already been built or downloaded | 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 | 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. | 24 | # (as indicated by the PNGPATH and ZPATH macros below). Edit as appropriate. |
25 | # | 25 | # |
26 | # Note that the names of the dynamic and static libpng and zlib libraries | 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 | 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- | 28 | # builds statically linked executables, but that can be changed by uncom- |
29 | # menting the appropriate PNGLIB and ZLIB lines. | 29 | # menting the appropriate PNGLIB and ZLIB lines. |
30 | 30 | ||
31 | !include <ntwin32.mak> | 31 | !include <ntwin32.mak> |
32 | 32 | ||
33 | 33 | ||
34 | # macros -------------------------------------------------------------------- | 34 | # macros -------------------------------------------------------------------- |
35 | 35 | ||
36 | PNGPATH = ../libpng | 36 | PNGPATH = ../libpng |
37 | PNGINC = -I$(PNGPATH) | 37 | PNGINC = -I$(PNGPATH) |
38 | #PNGLIB = $(PNGPATH)/pngdll.lib | 38 | #PNGLIB = $(PNGPATH)/pngdll.lib |
39 | PNGLIB = $(PNGPATH)/libpng.lib | 39 | PNGLIB = $(PNGPATH)/libpng.lib |
40 | 40 | ||
41 | ZPATH = ../zlib | 41 | ZPATH = ../zlib |
42 | ZINC = -I$(ZPATH) | 42 | ZINC = -I$(ZPATH) |
43 | #ZLIB = $(ZPATH)/zlibdll.lib | 43 | #ZLIB = $(ZPATH)/zlibdll.lib |
44 | ZLIB = $(ZPATH)/zlibstat.lib | 44 | ZLIB = $(ZPATH)/zlibstat.lib |
45 | 45 | ||
46 | WINLIBS = -defaultlib:user32.lib gdi32.lib | 46 | WINLIBS = -defaultlib:user32.lib gdi32.lib |
47 | # ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.] | 47 | # ["real" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.] |
48 | 48 | ||
49 | INCS = $(PNGINC) $(ZINC) | 49 | INCS = $(PNGINC) $(ZINC) |
50 | RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS) | 50 | RLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS) |
51 | WLIBS = $(PNGLIB) $(ZLIB) | 51 | WLIBS = $(PNGLIB) $(ZLIB) |
52 | 52 | ||
53 | CC = cl | 53 | CC = cl |
54 | LD = link | 54 | LD = link |
55 | RM = del | 55 | RM = del |
56 | CFLAGS = -nologo -O -W3 $(INCS) $(cvars) | 56 | CFLAGS = -nologo -O -W3 $(INCS) $(cvars) |
57 | # [note that -W3 is an MSVC-specific compilation flag ("all warnings on")] | 57 | # [note that -W3 is an MSVC-specific compilation flag ("all warnings on")] |
58 | # [see %devstudio%\vc\include\win32.mak for cvars macro definition] | 58 | # [see %devstudio%\vc\include\win32.mak for cvars macro definition] |
59 | O = .obj | 59 | O = .obj |
60 | E = .exe | 60 | E = .exe |
61 | 61 | ||
62 | RLDFLAGS = -nologo -subsystem:windows | 62 | RLDFLAGS = -nologo -subsystem:windows |
63 | WLDFLAGS = -nologo | 63 | WLDFLAGS = -nologo |
64 | 64 | ||
65 | RPNG = rpng-win | 65 | RPNG = rpng-win |
66 | RPNG2 = rpng2-win | 66 | RPNG2 = rpng2-win |
67 | WPNG = wpng | 67 | WPNG = wpng |
68 | 68 | ||
69 | ROBJS = $(RPNG)$(O) readpng$(O) | 69 | ROBJS = $(RPNG)$(O) readpng$(O) |
70 | ROBJS2 = $(RPNG2)$(O) readpng2$(O) | 70 | ROBJS2 = $(RPNG2)$(O) readpng2$(O) |
71 | WOBJS = $(WPNG)$(O) writepng$(O) | 71 | WOBJS = $(WPNG)$(O) writepng$(O) |
72 | 72 | ||
73 | EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) | 73 | EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E) |
74 | 74 | ||
75 | 75 | ||
76 | # implicit make rules ------------------------------------------------------- | 76 | # implicit make rules ------------------------------------------------------- |
77 | 77 | ||
78 | .c$(O): | 78 | .c$(O): |
79 | $(CC) -c $(CFLAGS) $< | 79 | $(CC) -c $(CFLAGS) $< |
80 | 80 | ||
81 | 81 | ||
82 | # dependencies -------------------------------------------------------------- | 82 | # dependencies -------------------------------------------------------------- |
83 | 83 | ||
84 | all: $(EXES) | 84 | all: $(EXES) |
85 | 85 | ||
86 | $(RPNG)$(E): $(ROBJS) | 86 | $(RPNG)$(E): $(ROBJS) |
87 | $(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS) | 87 | $(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS) |
88 | 88 | ||
89 | $(RPNG2)$(E): $(ROBJS2) | 89 | $(RPNG2)$(E): $(ROBJS2) |
90 | $(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS) | 90 | $(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS) |
91 | 91 | ||
92 | $(WPNG)$(E): $(WOBJS) | 92 | $(WPNG)$(E): $(WOBJS) |
93 | $(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS) | 93 | $(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS) |
94 | 94 | ||
95 | $(RPNG)$(O): $(RPNG).c readpng.h | 95 | $(RPNG)$(O): $(RPNG).c readpng.h |
96 | $(RPNG2)$(O): $(RPNG2).c readpng2.h | 96 | $(RPNG2)$(O): $(RPNG2).c readpng2.h |
97 | $(WPNG)$(O): $(WPNG).c writepng.h | 97 | $(WPNG)$(O): $(WPNG).c writepng.h |
98 | 98 | ||
99 | readpng$(O): readpng.c readpng.h | 99 | readpng$(O): readpng.c readpng.h |
100 | readpng2$(O): readpng2.c readpng2.h | 100 | readpng2$(O): readpng2.c readpng2.h |
101 | writepng$(O): writepng.c writepng.h | 101 | writepng$(O): writepng.c writepng.h |
102 | 102 | ||
103 | 103 | ||
104 | # maintenance --------------------------------------------------------------- | 104 | # maintenance --------------------------------------------------------------- |
105 | 105 | ||
106 | clean: | 106 | clean: |
107 | # ideally we could just do this: | 107 | # ideally we could just do this: |
108 | # $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) | 108 | # $(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS) |
109 | # ...but the Windows "DEL" command is none too bright, so: | 109 | # ...but the Windows "DEL" command is none too bright, so: |
110 | $(RM) r*$(E) | 110 | $(RM) r*$(E) |
111 | $(RM) w*$(E) | 111 | $(RM) w*$(E) |
112 | $(RM) r*$(O) | 112 | $(RM) r*$(O) |
113 | $(RM) w*$(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 index 791fec8..7b1f6a3 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/README | |||
@@ -1,186 +1,186 @@ | |||
1 | =========================== | 1 | =========================== |
2 | PNG: The Definitive Guide | 2 | PNG: The Definitive Guide |
3 | =========================== | 3 | =========================== |
4 | 4 | ||
5 | Source Code | 5 | Source Code |
6 | 6 | ||
7 | Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free, | 7 | Chapters 13, 14 and 15 of "PNG: The Definitive Guide" discuss three free, |
8 | cross-platform demo programs that show how to use the libpng reference | 8 | cross-platform demo programs that show how to use the libpng reference |
9 | library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is | 9 | library: rpng, rpng2 and wpng. rpng and rpng2 are viewers; the first is |
10 | a very simple example that that shows how a standard file-viewer might use | 10 | a very simple example that that shows how a standard file-viewer might use |
11 | libpng, while the second is designed to process streaming data and shows | 11 | libpng, while the second is designed to process streaming data and shows |
12 | how a web browser might be written. wpng is a simple command-line program | 12 | how a web browser might be written. wpng is a simple command-line program |
13 | that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets | 13 | that reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets |
14 | of PBMPLUS/NetPBM) and converts them to PNG. | 14 | of PBMPLUS/NetPBM) and converts them to PNG. |
15 | 15 | ||
16 | The source code for all three demo programs currently compiles under | 16 | The source code for all three demo programs currently compiles under |
17 | Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser, | 17 | Unix, OpenVMS, and 32-bit Windows. (Special thanks to Martin Zinser, |
18 | zinser@decus.de, for making the necessary changes for OpenVMS and for | 18 | zinser@decus.de, for making the necessary changes for OpenVMS and for |
19 | providing an appropriate build script.) Build instructions can be found | 19 | providing an appropriate build script.) Build instructions can be found |
20 | below. | 20 | below. |
21 | 21 | ||
22 | Files: | 22 | Files: |
23 | 23 | ||
24 | README this file | 24 | README this file |
25 | LICENSE terms of distribution and reuse (BSD-like or GNU GPL) | 25 | LICENSE terms of distribution and reuse (BSD-like or GNU GPL) |
26 | COPYING GNU General Public License (GPL) | 26 | COPYING GNU General Public License (GPL) |
27 | 27 | ||
28 | Makefile.unx Unix makefile | 28 | Makefile.unx Unix makefile |
29 | Makefile.w32 Windows (MSVC) makefile | 29 | Makefile.w32 Windows (MSVC) makefile |
30 | makevms.com OpenVMS build script | 30 | makevms.com OpenVMS build script |
31 | 31 | ||
32 | rpng-win.c Windows front end for the basic viewer | 32 | rpng-win.c Windows front end for the basic viewer |
33 | rpng-x.c X Window System (Unix, OpenVMS) front end | 33 | rpng-x.c X Window System (Unix, OpenVMS) front end |
34 | readpng.c generic back end for the basic viewer | 34 | readpng.c generic back end for the basic viewer |
35 | readpng.h header file for the basic viewer | 35 | readpng.h header file for the basic viewer |
36 | 36 | ||
37 | rpng2-win.c Windows front end for the progressive viewer | 37 | rpng2-win.c Windows front end for the progressive viewer |
38 | rpng2-x.c X 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 | 39 | readpng2.c generic back end for the progressive viewer |
40 | readpng2.h header file for the progressive viewer | 40 | readpng2.h header file for the progressive viewer |
41 | 41 | ||
42 | wpng.c generic (text) front end for the converter | 42 | wpng.c generic (text) front end for the converter |
43 | writepng.c generic back end for the converter | 43 | writepng.c generic back end for the converter |
44 | writepng.h header file for the converter | 44 | writepng.h header file for the converter |
45 | 45 | ||
46 | toucan.png transparent PNG for testing (by Stefan Schneider) | 46 | toucan.png transparent PNG for testing (by Stefan Schneider) |
47 | 47 | ||
48 | Note that, although the programs are designed to be functional, their | 48 | Note that, although the programs are designed to be functional, their |
49 | primary purpose is to illustrate how to use libpng to add PNG support to | 49 | primary purpose is to illustrate how to use libpng to add PNG support to |
50 | other programs. As such, their user interfaces are crude and definitely | 50 | other programs. As such, their user interfaces are crude and definitely |
51 | are not intended for everyday use. | 51 | are not intended for everyday use. |
52 | 52 | ||
53 | Please see http://www.libpng.org/pub/png/pngbook.html for further infor- | 53 | Please see http://www.libpng.org/pub/png/pngbook.html for further infor- |
54 | mation and links to the latest version of the source code, and Chapters | 54 | mation and links to the latest version of the source code, and Chapters |
55 | 13-15 of the book for detailed discussion of the three programs. | 55 | 13-15 of the book for detailed discussion of the three programs. |
56 | 56 | ||
57 | Greg Roelofs | 57 | Greg Roelofs |
58 | http://pobox.com/~newt/greg_contact.html | 58 | http://pobox.com/~newt/greg_contact.html |
59 | 16 March 2008 | 59 | 16 March 2008 |
60 | 60 | ||
61 | 61 | ||
62 | BUILD INSTRUCTIONS | 62 | BUILD INSTRUCTIONS |
63 | 63 | ||
64 | - Prerequisites (in order of compilation): | 64 | - Prerequisites (in order of compilation): |
65 | 65 | ||
66 | - zlib http://zlib.net/ | 66 | - zlib http://zlib.net/ |
67 | - libpng http://www.libpng.org/pub/png/libpng.html | 67 | - libpng http://www.libpng.org/pub/png/libpng.html |
68 | - pngbook http://www.libpng.org/pub/png/book/sources.html | 68 | - pngbook http://www.libpng.org/pub/png/book/sources.html |
69 | 69 | ||
70 | The pngbook demo programs are explicitly designed to demonstrate proper | 70 | The pngbook demo programs are explicitly designed to demonstrate proper |
71 | coding techniques for using the libpng reference library. As a result, | 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 | 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 | 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 | 74 | subdirectory trees ("folders") in the same parent directory. Then the |
75 | libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]), | 75 | libpng build can refer to files in ../zlib (or ..\zlib or [-.zlib]), |
76 | and similarly for the pngbook build. | 76 | and similarly for the pngbook build. |
77 | 77 | ||
78 | Note that all three packages are designed to be built from a command | 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 | 79 | line by default; those who wish to use a graphical or other integrated |
80 | development environments are on their own. | 80 | development environments are on their own. |
81 | 81 | ||
82 | 82 | ||
83 | - Unix: | 83 | - Unix: |
84 | 84 | ||
85 | Unpack the latest pngbook sources (which should correspond to this | 85 | Unpack the latest pngbook sources (which should correspond to this |
86 | README file) into a directory and change into that directory. | 86 | README file) into a directory and change into that directory. |
87 | 87 | ||
88 | Copy Makefile.unx to Makefile and edit the PNG* and Z* variables | 88 | Copy Makefile.unx to Makefile and edit the PNG* and Z* variables |
89 | appropriately (possibly also the X* variables if necessary). | 89 | appropriately (possibly also the X* variables if necessary). |
90 | 90 | ||
91 | make | 91 | make |
92 | 92 | ||
93 | There is no "install" target, so copy the three executables somewhere | 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 | 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; | 95 | print a basic usage screen when run without any command-line arguments; |
96 | see the book for more details. | 96 | see the book for more details. |
97 | 97 | ||
98 | 98 | ||
99 | - Windows: | 99 | - Windows: |
100 | 100 | ||
101 | Unpack the latest pngbook sources (which should correspond to this | 101 | Unpack the latest pngbook sources (which should correspond to this |
102 | README file) into a folder, open a "DOS shell" or "command prompt" | 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 | 103 | or equivalent command-line window, and cd into the folder where you |
104 | unpacked the source code. | 104 | unpacked the source code. |
105 | 105 | ||
106 | For MSVC, set up the necessary environment variables by invoking | 106 | For MSVC, set up the necessary environment variables by invoking |
107 | 107 | ||
108 | %devstudio%\vc\bin\vcvars32.bat | 108 | %devstudio%\vc\bin\vcvars32.bat |
109 | 109 | ||
110 | where where %devstudio% is the installation directory for MSVC / | 110 | where where %devstudio% is the installation directory for MSVC / |
111 | DevStudio. If you get "environment out of space" errors under 95/98, | 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 | 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 | 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 | 114 | directory. Then double-click to open the new DOS-prompt window with |
115 | a bigger environment and retry the commands above. | 115 | a bigger environment and retry the commands above. |
116 | 116 | ||
117 | Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables | 117 | Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables |
118 | appropriately (possibly also the "INC" and "LIB" variables if needed). | 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 | 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. | 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. | 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 | 122 | This makefile therefore builds statically linked executables, but if |
123 | the DLL problems ever get fixed, uncommenting the appropriate PNGLIB | 123 | the DLL problems ever get fixed, uncommenting the appropriate PNGLIB |
124 | and ZLIB lines will build dynamically linked executables instead. | 124 | and ZLIB lines will build dynamically linked executables instead. |
125 | 125 | ||
126 | Do the build by typing | 126 | Do the build by typing |
127 | 127 | ||
128 | nmake | 128 | nmake |
129 | 129 | ||
130 | The result should be three executables: rpng-win.exe, rpng2-win.exe, | 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 | 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 | 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 | 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 | 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 "-" | 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 | 136 | character to specify options, instead of the more common DOS/Windows |
137 | "/" character. (For example: "rpng2-win -bgpat 4 foo.png", not | 137 | "/" character. (For example: "rpng2-win -bgpat 4 foo.png", not |
138 | "rpng2-win /bgpat 4 foo.png") | 138 | "rpng2-win /bgpat 4 foo.png") |
139 | 139 | ||
140 | 140 | ||
141 | - OpenVMS: | 141 | - OpenVMS: |
142 | 142 | ||
143 | Unpack the pngbook sources into a subdirectory and change into that | 143 | Unpack the pngbook sources into a subdirectory and change into that |
144 | subdirectory. | 144 | subdirectory. |
145 | 145 | ||
146 | Edit makevms.com appropriately, specifically the zpath and pngpath | 146 | Edit makevms.com appropriately, specifically the zpath and pngpath |
147 | variables. | 147 | variables. |
148 | 148 | ||
149 | @makevms | 149 | @makevms |
150 | 150 | ||
151 | To run the programs, they probably first need to be set up as "foreign | 151 | To run the programs, they probably first need to be set up as "foreign |
152 | symbols," with "disk" and "dir" set appropriately: | 152 | symbols," with "disk" and "dir" set appropriately: |
153 | 153 | ||
154 | $ rpng == "$disk:[dir]rpng-x.exe" | 154 | $ rpng == "$disk:[dir]rpng-x.exe" |
155 | $ rpng2 == "$disk:[dir]rpng2-x.exe" | 155 | $ rpng2 == "$disk:[dir]rpng2-x.exe" |
156 | $ wpng == "$disk:[dir]wpng.exe" | 156 | $ wpng == "$disk:[dir]wpng.exe" |
157 | 157 | ||
158 | All three will print a basic usage screen when run without any command- | 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 | 159 | line arguments; see the book for more details. Note that the options |
160 | style is Unix-like, i.e., preceded by "-" rather than "/". | 160 | style is Unix-like, i.e., preceded by "-" rather than "/". |
161 | 161 | ||
162 | 162 | ||
163 | RUNNING THE PROGRAMS: (VERY) BRIEF INTRO | 163 | RUNNING THE PROGRAMS: (VERY) BRIEF INTRO |
164 | 164 | ||
165 | rpng is a simple PNG viewer that can display transparent PNGs with a | 165 | rpng is a simple PNG viewer that can display transparent PNGs with a |
166 | specified background color; for example, | 166 | specified background color; for example, |
167 | 167 | ||
168 | rpng -bgcolor \#ff0000 toucan.png | 168 | rpng -bgcolor \#ff0000 toucan.png |
169 | 169 | ||
170 | would display the image with a red background. rpng2 is a progressive | 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 | 171 | viewer that simulates a web browser in some respects; it can display |
172 | images against either a background color or a dynamically generated | 172 | images against either a background color or a dynamically generated |
173 | background image. For example: | 173 | background image. For example: |
174 | 174 | ||
175 | rpng2 -bgpat 16 toucan.png | 175 | rpng2 -bgpat 16 toucan.png |
176 | 176 | ||
177 | wpng is a purely command-line image converter from binary PBMPLUS/NetPBM | 177 | wpng is a purely command-line image converter from binary PBMPLUS/NetPBM |
178 | format (.pgm or .ppm) to PNG; for example, | 178 | format (.pgm or .ppm) to PNG; for example, |
179 | 179 | ||
180 | wpng -time < toucan-notrans.ppm > toucan-notrans.png | 180 | wpng -time < toucan-notrans.ppm > toucan-notrans.png |
181 | 181 | ||
182 | would convert the specified PPM file (using redirection) to PNG, auto- | 182 | would convert the specified PPM file (using redirection) to PNG, auto- |
183 | matically setting the PNG modification-time chunk. | 183 | matically setting the PNG modification-time chunk. |
184 | 184 | ||
185 | All options can be abbreviated to the shortest unique value; for example, | 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. | 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 index 29a5727..f32bcab 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/makevms.com | |||
@@ -1,132 +1,132 @@ | |||
1 | $!------------------------------------------------------------------------------ | 1 | $!------------------------------------------------------------------------------ |
2 | $! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS | 2 | $! make "PNG: The Definitive Guide" demo programs (for X) under OpenVMS |
3 | $! | 3 | $! |
4 | $! Script created by Martin Zinser for libpng; modified by Greg Roelofs | 4 | $! Script created by Martin Zinser for libpng; modified by Greg Roelofs |
5 | $! for standalone pngbook source distribution. | 5 | $! for standalone pngbook source distribution. |
6 | $! | 6 | $! |
7 | $! | 7 | $! |
8 | $! Set locations where zlib and libpng sources live. | 8 | $! Set locations where zlib and libpng sources live. |
9 | $! | 9 | $! |
10 | $ zpath = "" | 10 | $ zpath = "" |
11 | $ pngpath = "" | 11 | $ pngpath = "" |
12 | $! | 12 | $! |
13 | $ if f$search("[---.zlib]zlib.h").nes."" then zpath = "[---.zlib]" | 13 | $ if f$search("[---.zlib]zlib.h").nes."" then zpath = "[---.zlib]" |
14 | $ if f$search("[--]png.h").nes."" then pngpath = "[--]" | 14 | $ if f$search("[--]png.h").nes."" then pngpath = "[--]" |
15 | $! | 15 | $! |
16 | $ if f$search("[-.zlib]zlib.h").nes."" then zpath = "[-.zlib]" | 16 | $ if f$search("[-.zlib]zlib.h").nes."" then zpath = "[-.zlib]" |
17 | $ if f$search("[-.libpng]png.h").nes."" then pngpath = "[-.libpng]" | 17 | $ if f$search("[-.libpng]png.h").nes."" then pngpath = "[-.libpng]" |
18 | $! | 18 | $! |
19 | $ if zpath .eqs. "" | 19 | $ if zpath .eqs. "" |
20 | $ then | 20 | $ then |
21 | $ write sys$output "zlib include not found. Exiting..." | 21 | $ write sys$output "zlib include not found. Exiting..." |
22 | $ exit 2 | 22 | $ exit 2 |
23 | $ endif | 23 | $ endif |
24 | $! | 24 | $! |
25 | $ if pngpath .eqs. "" | 25 | $ if pngpath .eqs. "" |
26 | $ then | 26 | $ then |
27 | $ write sys$output "libpng include not found. Exiting..." | 27 | $ write sys$output "libpng include not found. Exiting..." |
28 | $ exit 2 | 28 | $ exit 2 |
29 | $ endif | 29 | $ endif |
30 | $! | 30 | $! |
31 | $! Look for the compiler used. | 31 | $! Look for the compiler used. |
32 | $! | 32 | $! |
33 | $ ccopt="/include=(''zpath',''pngpath')" | 33 | $ ccopt="/include=(''zpath',''pngpath')" |
34 | $ if f$getsyi("HW_MODEL").ge.1024 | 34 | $ if f$getsyi("HW_MODEL").ge.1024 |
35 | $ then | 35 | $ then |
36 | $ ccopt = "/prefix=all"+ccopt | 36 | $ ccopt = "/prefix=all"+ccopt |
37 | $ comp = "__decc__=1" | 37 | $ comp = "__decc__=1" |
38 | $ if f$trnlnm("SYS").eqs."" then define sys sys$library: | 38 | $ if f$trnlnm("SYS").eqs."" then define sys sys$library: |
39 | $ else | 39 | $ else |
40 | $ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" | 40 | $ if f$search("SYS$SYSTEM:DECC$COMPILER.EXE").eqs."" |
41 | $ then | 41 | $ then |
42 | $ if f$trnlnm("SYS").eqs."" then define sys sys$library: | 42 | $ if f$trnlnm("SYS").eqs."" then define sys sys$library: |
43 | $ if f$search("SYS$SYSTEM:VAXC.EXE").eqs."" | 43 | $ if f$search("SYS$SYSTEM:VAXC.EXE").eqs."" |
44 | $ then | 44 | $ then |
45 | $ comp = "__gcc__=1" | 45 | $ comp = "__gcc__=1" |
46 | $ CC :== GCC | 46 | $ CC :== GCC |
47 | $ else | 47 | $ else |
48 | $ comp = "__vaxc__=1" | 48 | $ comp = "__vaxc__=1" |
49 | $ endif | 49 | $ endif |
50 | $ else | 50 | $ else |
51 | $ if f$trnlnm("SYS").eqs."" then define sys decc$library_include: | 51 | $ if f$trnlnm("SYS").eqs."" then define sys decc$library_include: |
52 | $ ccopt = "/decc/prefix=all"+ccopt | 52 | $ ccopt = "/decc/prefix=all"+ccopt |
53 | $ comp = "__decc__=1" | 53 | $ comp = "__decc__=1" |
54 | $ endif | 54 | $ endif |
55 | $ endif | 55 | $ endif |
56 | $ open/write lopt lib.opt | 56 | $ open/write lopt lib.opt |
57 | $ write lopt "''pngpath'libpng.olb/lib" | 57 | $ write lopt "''pngpath'libpng.olb/lib" |
58 | $ write lopt "''zpath'libz.olb/lib" | 58 | $ write lopt "''zpath'libz.olb/lib" |
59 | $ close lopt | 59 | $ close lopt |
60 | $ open/write xopt x11.opt | 60 | $ open/write xopt x11.opt |
61 | $ write xopt "sys$library:decw$xlibshr.exe/share" | 61 | $ write xopt "sys$library:decw$xlibshr.exe/share" |
62 | $ close xopt | 62 | $ close xopt |
63 | $! | 63 | $! |
64 | $! Build 'em. | 64 | $! Build 'em. |
65 | $! | 65 | $! |
66 | $ write sys$output "Compiling PNG book programs ..." | 66 | $ write sys$output "Compiling PNG book programs ..." |
67 | $ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" - | 67 | $ CALL MAKE readpng.OBJ "cc ''CCOPT' readpng" - |
68 | readpng.c readpng.h | 68 | readpng.c readpng.h |
69 | $ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" - | 69 | $ CALL MAKE readpng2.OBJ "cc ''CCOPT' readpng2" - |
70 | readpng2.c readpng2.h | 70 | readpng2.c readpng2.h |
71 | $ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" - | 71 | $ CALL MAKE writepng.OBJ "cc ''CCOPT' writepng" - |
72 | writepng.c writepng.h | 72 | writepng.c writepng.h |
73 | $ write sys$output "Building rpng-x..." | 73 | $ write sys$output "Building rpng-x..." |
74 | $ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" - | 74 | $ CALL MAKE rpng-x.OBJ "cc ''CCOPT' rpng-x" - |
75 | rpng-x.c readpng.h | 75 | rpng-x.c readpng.h |
76 | $ call make rpng-x.exe - | 76 | $ call make rpng-x.exe - |
77 | "LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" - | 77 | "LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt" - |
78 | rpng-x.obj readpng.obj | 78 | rpng-x.obj readpng.obj |
79 | $ write sys$output "Building rpng2-x..." | 79 | $ write sys$output "Building rpng2-x..." |
80 | $ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" - | 80 | $ CALL MAKE rpng2-x.OBJ "cc ''CCOPT' rpng2-x" - |
81 | rpng2-x.c readpng2.h | 81 | rpng2-x.c readpng2.h |
82 | $ call make rpng2-x.exe - | 82 | $ call make rpng2-x.exe - |
83 | "LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" - | 83 | "LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt" - |
84 | rpng2-x.obj readpng2.obj | 84 | rpng2-x.obj readpng2.obj |
85 | $ write sys$output "Building wpng..." | 85 | $ write sys$output "Building wpng..." |
86 | $ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" - | 86 | $ CALL MAKE wpng.OBJ "cc ''CCOPT' wpng" - |
87 | wpng.c writepng.h | 87 | wpng.c writepng.h |
88 | $ call make wpng.exe - | 88 | $ call make wpng.exe - |
89 | "LINK wpng,writepng,lib.opt/opt" - | 89 | "LINK wpng,writepng,lib.opt/opt" - |
90 | wpng.obj writepng.obj | 90 | wpng.obj writepng.obj |
91 | $ exit | 91 | $ exit |
92 | $! | 92 | $! |
93 | $! | 93 | $! |
94 | $MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES | 94 | $MAKE: SUBROUTINE !SUBROUTINE TO CHECK DEPENDENCIES |
95 | $ V = 'F$Verify(0) | 95 | $ V = 'F$Verify(0) |
96 | $! P1 = What we are trying to make | 96 | $! P1 = What we are trying to make |
97 | $! P2 = Command to make it | 97 | $! P2 = Command to make it |
98 | $! P3 - P8 What it depends on | 98 | $! P3 - P8 What it depends on |
99 | $ | 99 | $ |
100 | $ If F$Search(P1) .Eqs. "" Then Goto Makeit | 100 | $ If F$Search(P1) .Eqs. "" Then Goto Makeit |
101 | $ Time = F$CvTime(F$File(P1,"RDT")) | 101 | $ Time = F$CvTime(F$File(P1,"RDT")) |
102 | $arg=3 | 102 | $arg=3 |
103 | $Loop: | 103 | $Loop: |
104 | $ Argument = P'arg | 104 | $ Argument = P'arg |
105 | $ If Argument .Eqs. "" Then Goto Exit | 105 | $ If Argument .Eqs. "" Then Goto Exit |
106 | $ El=0 | 106 | $ El=0 |
107 | $Loop2: | 107 | $Loop2: |
108 | $ File = F$Element(El," ",Argument) | 108 | $ File = F$Element(El," ",Argument) |
109 | $ If File .Eqs. " " Then Goto Endl | 109 | $ If File .Eqs. " " Then Goto Endl |
110 | $ AFile = "" | 110 | $ AFile = "" |
111 | $Loop3: | 111 | $Loop3: |
112 | $ OFile = AFile | 112 | $ OFile = AFile |
113 | $ AFile = F$Search(File) | 113 | $ AFile = F$Search(File) |
114 | $ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl | 114 | $ If AFile .Eqs. "" .Or. AFile .Eqs. OFile Then Goto NextEl |
115 | $ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit | 115 | $ If F$CvTime(F$File(AFile,"RDT")) .Ges. Time Then Goto Makeit |
116 | $ Goto Loop3 | 116 | $ Goto Loop3 |
117 | $NextEL: | 117 | $NextEL: |
118 | $ El = El + 1 | 118 | $ El = El + 1 |
119 | $ Goto Loop2 | 119 | $ Goto Loop2 |
120 | $EndL: | 120 | $EndL: |
121 | $ arg=arg+1 | 121 | $ arg=arg+1 |
122 | $ If arg .Le. 8 Then Goto Loop | 122 | $ If arg .Le. 8 Then Goto Loop |
123 | $ Goto Exit | 123 | $ Goto Exit |
124 | $ | 124 | $ |
125 | $Makeit: | 125 | $Makeit: |
126 | $ VV=F$VERIFY(0) | 126 | $ VV=F$VERIFY(0) |
127 | $ write sys$output P2 | 127 | $ write sys$output P2 |
128 | $ 'P2 | 128 | $ 'P2 |
129 | $ VV='F$Verify(VV) | 129 | $ VV='F$Verify(VV) |
130 | $Exit: | 130 | $Exit: |
131 | $ If V Then Set Verify | 131 | $ If V Then Set Verify |
132 | $ENDSUBROUTINE | 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 index 27a2f11..df42c30 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.c | |||
@@ -1,311 +1,311 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng - simple PNG display program readpng.c | 3 | rpng - simple PNG display program readpng.c |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
8 | 8 | ||
9 | This software is provided "as is," without warranty of any kind, | 9 | This software is provided "as is," without warranty of any kind, |
10 | express or implied. In no event shall the author or contributors | 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 | 11 | be held liable for any damages arising in any way from the use of |
12 | this software. | 12 | this software. |
13 | 13 | ||
14 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 15 | redistribute this software according to the terms of one of the |
16 | following two licenses (at your option): | 16 | following two licenses (at your option): |
17 | 17 | ||
18 | 18 | ||
19 | LICENSE 1 ("BSD-like with advertising clause"): | 19 | LICENSE 1 ("BSD-like with advertising clause"): |
20 | 20 | ||
21 | Permission is granted to anyone to use this software for any purpose, | 21 | Permission is granted to anyone to use this software for any purpose, |
22 | including commercial applications, and to alter it and redistribute | 22 | including commercial applications, and to alter it and redistribute |
23 | it freely, subject to the following restrictions: | 23 | it freely, subject to the following restrictions: |
24 | 24 | ||
25 | 1. Redistributions of source code must retain the above copyright | 25 | 1. Redistributions of source code must retain the above copyright |
26 | notice, disclaimer, and this list of conditions. | 26 | notice, disclaimer, and this list of conditions. |
27 | 2. Redistributions in binary form must reproduce the above copyright | 27 | 2. Redistributions in binary form must reproduce the above copyright |
28 | notice, disclaimer, and this list of conditions in the documenta- | 28 | notice, disclaimer, and this list of conditions in the documenta- |
29 | tion and/or other materials provided with the distribution. | 29 | tion and/or other materials provided with the distribution. |
30 | 3. All advertising materials mentioning features or use of this | 30 | 3. All advertising materials mentioning features or use of this |
31 | software must display the following acknowledgment: | 31 | software must display the following acknowledgment: |
32 | 32 | ||
33 | This product includes software developed by Greg Roelofs | 33 | This product includes software developed by Greg Roelofs |
34 | and contributors for the book, "PNG: The Definitive Guide," | 34 | and contributors for the book, "PNG: The Definitive Guide," |
35 | published by O'Reilly and Associates. | 35 | published by O'Reilly and Associates. |
36 | 36 | ||
37 | 37 | ||
38 | LICENSE 2 (GNU GPL v2 or later): | 38 | LICENSE 2 (GNU GPL v2 or later): |
39 | 39 | ||
40 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 42 | the Free Software Foundation; either version 2 of the License, or |
43 | (at your option) any later version. | 43 | (at your option) any later version. |
44 | 44 | ||
45 | This program is distributed in the hope that it will be useful, | 45 | This program is distributed in the hope that it will be useful, |
46 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | GNU General Public License for more details. | 48 | GNU General Public License for more details. |
49 | 49 | ||
50 | You should have received a copy of the GNU General Public License | 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, | 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 | 52 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
53 | 53 | ||
54 | ---------------------------------------------------------------------------*/ | 54 | ---------------------------------------------------------------------------*/ |
55 | 55 | ||
56 | #include <stdio.h> | 56 | #include <stdio.h> |
57 | #include <stdlib.h> | 57 | #include <stdlib.h> |
58 | 58 | ||
59 | #include "png.h" /* libpng header; includes zlib.h */ | 59 | #include "png.h" /* libpng header; includes zlib.h */ |
60 | #include "readpng.h" /* typedefs, common macros, public prototypes */ | 60 | #include "readpng.h" /* typedefs, common macros, public prototypes */ |
61 | 61 | ||
62 | /* future versions of libpng will provide this macro: */ | 62 | /* future versions of libpng will provide this macro: */ |
63 | #ifndef png_jmpbuf | 63 | #ifndef png_jmpbuf |
64 | # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) | 64 | # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) |
65 | #endif | 65 | #endif |
66 | 66 | ||
67 | 67 | ||
68 | static png_structp png_ptr = NULL; | 68 | static png_structp png_ptr = NULL; |
69 | static png_infop info_ptr = NULL; | 69 | static png_infop info_ptr = NULL; |
70 | 70 | ||
71 | png_uint_32 width, height; | 71 | png_uint_32 width, height; |
72 | int bit_depth, color_type; | 72 | int bit_depth, color_type; |
73 | uch *image_data = NULL; | 73 | uch *image_data = NULL; |
74 | 74 | ||
75 | 75 | ||
76 | void readpng_version_info(void) | 76 | void readpng_version_info(void) |
77 | { | 77 | { |
78 | fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", | 78 | fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", |
79 | PNG_LIBPNG_VER_STRING, png_libpng_ver); | 79 | PNG_LIBPNG_VER_STRING, png_libpng_ver); |
80 | fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", | 80 | fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", |
81 | ZLIB_VERSION, zlib_version); | 81 | ZLIB_VERSION, zlib_version); |
82 | } | 82 | } |
83 | 83 | ||
84 | 84 | ||
85 | /* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ | 85 | /* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ |
86 | 86 | ||
87 | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) | 87 | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) |
88 | { | 88 | { |
89 | uch sig[8]; | 89 | uch sig[8]; |
90 | 90 | ||
91 | 91 | ||
92 | /* first do a quick check that the file really is a PNG image; could | 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 */ | 93 | * have used slightly more general png_sig_cmp() function instead */ |
94 | 94 | ||
95 | fread(sig, 1, 8, infile); | 95 | fread(sig, 1, 8, infile); |
96 | if (png_sig_cmp(sig, 0, 8)) | 96 | if (png_sig_cmp(sig, 0, 8)) |
97 | return 1; /* bad signature */ | 97 | return 1; /* bad signature */ |
98 | 98 | ||
99 | 99 | ||
100 | /* could pass pointers to user-defined error handlers instead of NULLs: */ | 100 | /* could pass pointers to user-defined error handlers instead of NULLs: */ |
101 | 101 | ||
102 | png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); | 102 | png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); |
103 | if (!png_ptr) | 103 | if (!png_ptr) |
104 | return 4; /* out of memory */ | 104 | return 4; /* out of memory */ |
105 | 105 | ||
106 | info_ptr = png_create_info_struct(png_ptr); | 106 | info_ptr = png_create_info_struct(png_ptr); |
107 | if (!info_ptr) { | 107 | if (!info_ptr) { |
108 | png_destroy_read_struct(&png_ptr, NULL, NULL); | 108 | png_destroy_read_struct(&png_ptr, NULL, NULL); |
109 | return 4; /* out of memory */ | 109 | return 4; /* out of memory */ |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | /* we could create a second info struct here (end_info), but it's only | 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 | 114 | * useful if we want to keep pre- and post-IDAT chunk info separated |
115 | * (mainly for PNG-aware image editors and converters) */ | 115 | * (mainly for PNG-aware image editors and converters) */ |
116 | 116 | ||
117 | 117 | ||
118 | /* setjmp() must be called in every function that calls a PNG-reading | 118 | /* setjmp() must be called in every function that calls a PNG-reading |
119 | * libpng function */ | 119 | * libpng function */ |
120 | 120 | ||
121 | if (setjmp(png_jmpbuf(png_ptr))) { | 121 | if (setjmp(png_jmpbuf(png_ptr))) { |
122 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 122 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
123 | return 2; | 123 | return 2; |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | png_init_io(png_ptr, infile); | 127 | png_init_io(png_ptr, infile); |
128 | png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */ | 128 | png_set_sig_bytes(png_ptr, 8); /* we already read the 8 signature bytes */ |
129 | 129 | ||
130 | png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */ | 130 | png_read_info(png_ptr, info_ptr); /* read all PNG info up to image data */ |
131 | 131 | ||
132 | 132 | ||
133 | /* alternatively, could make separate calls to png_get_image_width(), | 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 | 134 | * etc., but want bit_depth and color_type for later [don't care about |
135 | * compression_type and filter_type => NULLs] */ | 135 | * compression_type and filter_type => NULLs] */ |
136 | 136 | ||
137 | png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, | 137 | png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, |
138 | NULL, NULL, NULL); | 138 | NULL, NULL, NULL); |
139 | *pWidth = width; | 139 | *pWidth = width; |
140 | *pHeight = height; | 140 | *pHeight = height; |
141 | 141 | ||
142 | 142 | ||
143 | /* OK, that's all we need for now; return happy */ | 143 | /* OK, that's all we need for now; return happy */ |
144 | 144 | ||
145 | return 0; | 145 | return 0; |
146 | } | 146 | } |
147 | 147 | ||
148 | 148 | ||
149 | 149 | ||
150 | 150 | ||
151 | /* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error; | 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 */ | 152 | * scales values to 8-bit if necessary */ |
153 | 153 | ||
154 | int readpng_get_bgcolor(uch *red, uch *green, uch *blue) | 154 | int readpng_get_bgcolor(uch *red, uch *green, uch *blue) |
155 | { | 155 | { |
156 | png_color_16p pBackground; | 156 | png_color_16p pBackground; |
157 | 157 | ||
158 | 158 | ||
159 | /* setjmp() must be called in every function that calls a PNG-reading | 159 | /* setjmp() must be called in every function that calls a PNG-reading |
160 | * libpng function */ | 160 | * libpng function */ |
161 | 161 | ||
162 | if (setjmp(png_jmpbuf(png_ptr))) { | 162 | if (setjmp(png_jmpbuf(png_ptr))) { |
163 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 163 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
164 | return 2; | 164 | return 2; |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) | 168 | if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) |
169 | return 1; | 169 | return 1; |
170 | 170 | ||
171 | /* it is not obvious from the libpng documentation, but this function | 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 | 172 | * takes a pointer to a pointer, and it always returns valid red, green |
173 | * and blue values, regardless of color_type: */ | 173 | * and blue values, regardless of color_type: */ |
174 | 174 | ||
175 | png_get_bKGD(png_ptr, info_ptr, &pBackground); | 175 | png_get_bKGD(png_ptr, info_ptr, &pBackground); |
176 | 176 | ||
177 | 177 | ||
178 | /* however, it always returns the raw bKGD data, regardless of any | 178 | /* however, it always returns the raw bKGD data, regardless of any |
179 | * bit-depth transformations, so check depth and adjust if necessary */ | 179 | * bit-depth transformations, so check depth and adjust if necessary */ |
180 | 180 | ||
181 | if (bit_depth == 16) { | 181 | if (bit_depth == 16) { |
182 | *red = pBackground->red >> 8; | 182 | *red = pBackground->red >> 8; |
183 | *green = pBackground->green >> 8; | 183 | *green = pBackground->green >> 8; |
184 | *blue = pBackground->blue >> 8; | 184 | *blue = pBackground->blue >> 8; |
185 | } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { | 185 | } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { |
186 | if (bit_depth == 1) | 186 | if (bit_depth == 1) |
187 | *red = *green = *blue = pBackground->gray? 255 : 0; | 187 | *red = *green = *blue = pBackground->gray? 255 : 0; |
188 | else if (bit_depth == 2) | 188 | else if (bit_depth == 2) |
189 | *red = *green = *blue = (255/3) * pBackground->gray; | 189 | *red = *green = *blue = (255/3) * pBackground->gray; |
190 | else /* bit_depth == 4 */ | 190 | else /* bit_depth == 4 */ |
191 | *red = *green = *blue = (255/15) * pBackground->gray; | 191 | *red = *green = *blue = (255/15) * pBackground->gray; |
192 | } else { | 192 | } else { |
193 | *red = (uch)pBackground->red; | 193 | *red = (uch)pBackground->red; |
194 | *green = (uch)pBackground->green; | 194 | *green = (uch)pBackground->green; |
195 | *blue = (uch)pBackground->blue; | 195 | *blue = (uch)pBackground->blue; |
196 | } | 196 | } |
197 | 197 | ||
198 | return 0; | 198 | return 0; |
199 | } | 199 | } |
200 | 200 | ||
201 | 201 | ||
202 | 202 | ||
203 | 203 | ||
204 | /* display_exponent == LUT_exponent * CRT_exponent */ | 204 | /* display_exponent == LUT_exponent * CRT_exponent */ |
205 | 205 | ||
206 | uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) | 206 | uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) |
207 | { | 207 | { |
208 | double gamma; | 208 | double gamma; |
209 | png_uint_32 i, rowbytes; | 209 | png_uint_32 i, rowbytes; |
210 | png_bytepp row_pointers = NULL; | 210 | png_bytepp row_pointers = NULL; |
211 | 211 | ||
212 | 212 | ||
213 | /* setjmp() must be called in every function that calls a PNG-reading | 213 | /* setjmp() must be called in every function that calls a PNG-reading |
214 | * libpng function */ | 214 | * libpng function */ |
215 | 215 | ||
216 | if (setjmp(png_jmpbuf(png_ptr))) { | 216 | if (setjmp(png_jmpbuf(png_ptr))) { |
217 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 217 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
218 | return NULL; | 218 | return NULL; |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits, | 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 | 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] */ | 224 | * images to 8 bits per sample; and convert grayscale to RGB[A] */ |
225 | 225 | ||
226 | if (color_type == PNG_COLOR_TYPE_PALETTE) | 226 | if (color_type == PNG_COLOR_TYPE_PALETTE) |
227 | png_set_expand(png_ptr); | 227 | png_set_expand(png_ptr); |
228 | if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) | 228 | if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) |
229 | png_set_expand(png_ptr); | 229 | png_set_expand(png_ptr); |
230 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) | 230 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) |
231 | png_set_expand(png_ptr); | 231 | png_set_expand(png_ptr); |
232 | #ifdef PNG_READ_16_TO_8_SUPPORTED | 232 | #ifdef PNG_READ_16_TO_8_SUPPORTED |
233 | if (bit_depth == 16) | 233 | if (bit_depth == 16) |
234 | # ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED | 234 | # ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED |
235 | png_set_scale_16(png_ptr); | 235 | png_set_scale_16(png_ptr); |
236 | # else | 236 | # else |
237 | png_set_strip_16(png_ptr); | 237 | png_set_strip_16(png_ptr); |
238 | # endif | 238 | # endif |
239 | #endif | 239 | #endif |
240 | if (color_type == PNG_COLOR_TYPE_GRAY || | 240 | if (color_type == PNG_COLOR_TYPE_GRAY || |
241 | color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 241 | color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
242 | png_set_gray_to_rgb(png_ptr); | 242 | png_set_gray_to_rgb(png_ptr); |
243 | 243 | ||
244 | 244 | ||
245 | /* unlike the example in the libpng documentation, we have *no* idea where | 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 | 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") */ | 247 | * do any correction ("do no harm") */ |
248 | 248 | ||
249 | if (png_get_gAMA(png_ptr, info_ptr, &gamma)) | 249 | if (png_get_gAMA(png_ptr, info_ptr, &gamma)) |
250 | png_set_gamma(png_ptr, display_exponent, gamma); | 250 | png_set_gamma(png_ptr, display_exponent, gamma); |
251 | 251 | ||
252 | 252 | ||
253 | /* all transformations have been registered; now update info_ptr data, | 253 | /* all transformations have been registered; now update info_ptr data, |
254 | * get rowbytes and channels, and allocate image memory */ | 254 | * get rowbytes and channels, and allocate image memory */ |
255 | 255 | ||
256 | png_read_update_info(png_ptr, info_ptr); | 256 | png_read_update_info(png_ptr, info_ptr); |
257 | 257 | ||
258 | *pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr); | 258 | *pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr); |
259 | *pChannels = (int)png_get_channels(png_ptr, info_ptr); | 259 | *pChannels = (int)png_get_channels(png_ptr, info_ptr); |
260 | 260 | ||
261 | if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { | 261 | if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { |
262 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 262 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
263 | return NULL; | 263 | return NULL; |
264 | } | 264 | } |
265 | if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) { | 265 | if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) { |
266 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 266 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
267 | free(image_data); | 267 | free(image_data); |
268 | image_data = NULL; | 268 | image_data = NULL; |
269 | return NULL; | 269 | return NULL; |
270 | } | 270 | } |
271 | 271 | ||
272 | Trace((stderr, "readpng_get_image: channels = %d, rowbytes = %ld, height = %ld\n", | 272 | Trace((stderr, "readpng_get_image: channels = %d, rowbytes = %ld, height = %ld\n", |
273 | *pChannels, rowbytes, height)); | 273 | *pChannels, rowbytes, height)); |
274 | 274 | ||
275 | 275 | ||
276 | /* set the individual row_pointers to point at the correct offsets */ | 276 | /* set the individual row_pointers to point at the correct offsets */ |
277 | 277 | ||
278 | for (i = 0; i < height; ++i) | 278 | for (i = 0; i < height; ++i) |
279 | row_pointers[i] = image_data + i*rowbytes; | 279 | row_pointers[i] = image_data + i*rowbytes; |
280 | 280 | ||
281 | 281 | ||
282 | /* now we can go ahead and just read the whole image */ | 282 | /* now we can go ahead and just read the whole image */ |
283 | 283 | ||
284 | png_read_image(png_ptr, row_pointers); | 284 | png_read_image(png_ptr, row_pointers); |
285 | 285 | ||
286 | 286 | ||
287 | /* and we're done! (png_read_end() can be omitted if no processing of | 287 | /* and we're done! (png_read_end() can be omitted if no processing of |
288 | * post-IDAT text/time/etc. is desired) */ | 288 | * post-IDAT text/time/etc. is desired) */ |
289 | 289 | ||
290 | free(row_pointers); | 290 | free(row_pointers); |
291 | row_pointers = NULL; | 291 | row_pointers = NULL; |
292 | 292 | ||
293 | png_read_end(png_ptr, NULL); | 293 | png_read_end(png_ptr, NULL); |
294 | 294 | ||
295 | return image_data; | 295 | return image_data; |
296 | } | 296 | } |
297 | 297 | ||
298 | 298 | ||
299 | void readpng_cleanup(int free_image_data) | 299 | void readpng_cleanup(int free_image_data) |
300 | { | 300 | { |
301 | if (free_image_data && image_data) { | 301 | if (free_image_data && image_data) { |
302 | free(image_data); | 302 | free(image_data); |
303 | image_data = NULL; | 303 | image_data = NULL; |
304 | } | 304 | } |
305 | 305 | ||
306 | if (png_ptr && info_ptr) { | 306 | if (png_ptr && info_ptr) { |
307 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 307 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
308 | png_ptr = NULL; | 308 | png_ptr = NULL; |
309 | info_ptr = NULL; | 309 | info_ptr = NULL; |
310 | } | 310 | } |
311 | } | 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 index ec6b483..fad9fe3 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng.h | |||
@@ -1,88 +1,88 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng - simple PNG display program readpng.h | 3 | rpng - simple PNG display program readpng.h |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
8 | 8 | ||
9 | This software is provided "as is," without warranty of any kind, | 9 | This software is provided "as is," without warranty of any kind, |
10 | express or implied. In no event shall the author or contributors | 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 | 11 | be held liable for any damages arising in any way from the use of |
12 | this software. | 12 | this software. |
13 | 13 | ||
14 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 15 | redistribute this software according to the terms of one of the |
16 | following two licenses (at your option): | 16 | following two licenses (at your option): |
17 | 17 | ||
18 | 18 | ||
19 | LICENSE 1 ("BSD-like with advertising clause"): | 19 | LICENSE 1 ("BSD-like with advertising clause"): |
20 | 20 | ||
21 | Permission is granted to anyone to use this software for any purpose, | 21 | Permission is granted to anyone to use this software for any purpose, |
22 | including commercial applications, and to alter it and redistribute | 22 | including commercial applications, and to alter it and redistribute |
23 | it freely, subject to the following restrictions: | 23 | it freely, subject to the following restrictions: |
24 | 24 | ||
25 | 1. Redistributions of source code must retain the above copyright | 25 | 1. Redistributions of source code must retain the above copyright |
26 | notice, disclaimer, and this list of conditions. | 26 | notice, disclaimer, and this list of conditions. |
27 | 2. Redistributions in binary form must reproduce the above copyright | 27 | 2. Redistributions in binary form must reproduce the above copyright |
28 | notice, disclaimer, and this list of conditions in the documenta- | 28 | notice, disclaimer, and this list of conditions in the documenta- |
29 | tion and/or other materials provided with the distribution. | 29 | tion and/or other materials provided with the distribution. |
30 | 3. All advertising materials mentioning features or use of this | 30 | 3. All advertising materials mentioning features or use of this |
31 | software must display the following acknowledgment: | 31 | software must display the following acknowledgment: |
32 | 32 | ||
33 | This product includes software developed by Greg Roelofs | 33 | This product includes software developed by Greg Roelofs |
34 | and contributors for the book, "PNG: The Definitive Guide," | 34 | and contributors for the book, "PNG: The Definitive Guide," |
35 | published by O'Reilly and Associates. | 35 | published by O'Reilly and Associates. |
36 | 36 | ||
37 | 37 | ||
38 | LICENSE 2 (GNU GPL v2 or later): | 38 | LICENSE 2 (GNU GPL v2 or later): |
39 | 39 | ||
40 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 42 | the Free Software Foundation; either version 2 of the License, or |
43 | (at your option) any later version. | 43 | (at your option) any later version. |
44 | 44 | ||
45 | This program is distributed in the hope that it will be useful, | 45 | This program is distributed in the hope that it will be useful, |
46 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | GNU General Public License for more details. | 48 | GNU General Public License for more details. |
49 | 49 | ||
50 | You should have received a copy of the GNU General Public License | 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, | 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 | 52 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
53 | 53 | ||
54 | ---------------------------------------------------------------------------*/ | 54 | ---------------------------------------------------------------------------*/ |
55 | 55 | ||
56 | #ifndef TRUE | 56 | #ifndef TRUE |
57 | # define TRUE 1 | 57 | # define TRUE 1 |
58 | # define FALSE 0 | 58 | # define FALSE 0 |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifndef MAX | 61 | #ifndef MAX |
62 | # define MAX(a,b) ((a) > (b)? (a) : (b)) | 62 | # define MAX(a,b) ((a) > (b)? (a) : (b)) |
63 | # define MIN(a,b) ((a) < (b)? (a) : (b)) | 63 | # define MIN(a,b) ((a) < (b)? (a) : (b)) |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #ifdef DEBUG | 66 | #ifdef DEBUG |
67 | # define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} | 67 | # define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} |
68 | #else | 68 | #else |
69 | # define Trace(x) ; | 69 | # define Trace(x) ; |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | typedef unsigned char uch; | 72 | typedef unsigned char uch; |
73 | typedef unsigned short ush; | 73 | typedef unsigned short ush; |
74 | typedef unsigned long ulg; | 74 | typedef unsigned long ulg; |
75 | 75 | ||
76 | 76 | ||
77 | /* prototypes for public functions in readpng.c */ | 77 | /* prototypes for public functions in readpng.c */ |
78 | 78 | ||
79 | void readpng_version_info(void); | 79 | void readpng_version_info(void); |
80 | 80 | ||
81 | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight); | 81 | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight); |
82 | 82 | ||
83 | int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue); | 83 | int readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue); |
84 | 84 | ||
85 | uch *readpng_get_image(double display_exponent, int *pChannels, | 85 | uch *readpng_get_image(double display_exponent, int *pChannels, |
86 | ulg *pRowbytes); | 86 | ulg *pRowbytes); |
87 | 87 | ||
88 | void readpng_cleanup(int free_image_data); | 88 | void 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 index 3bbd2ec..b9746b7 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.c | |||
@@ -1,511 +1,511 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng2 - progressive-model PNG display program readpng2.c | 3 | rpng2 - progressive-model PNG display program readpng2.c |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
8 | 8 | ||
9 | This software is provided "as is," without warranty of any kind, | 9 | This software is provided "as is," without warranty of any kind, |
10 | express or implied. In no event shall the author or contributors | 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 | 11 | be held liable for any damages arising in any way from the use of |
12 | this software. | 12 | this software. |
13 | 13 | ||
14 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 15 | redistribute this software according to the terms of one of the |
16 | following two licenses (at your option): | 16 | following two licenses (at your option): |
17 | 17 | ||
18 | 18 | ||
19 | LICENSE 1 ("BSD-like with advertising clause"): | 19 | LICENSE 1 ("BSD-like with advertising clause"): |
20 | 20 | ||
21 | Permission is granted to anyone to use this software for any purpose, | 21 | Permission is granted to anyone to use this software for any purpose, |
22 | including commercial applications, and to alter it and redistribute | 22 | including commercial applications, and to alter it and redistribute |
23 | it freely, subject to the following restrictions: | 23 | it freely, subject to the following restrictions: |
24 | 24 | ||
25 | 1. Redistributions of source code must retain the above copyright | 25 | 1. Redistributions of source code must retain the above copyright |
26 | notice, disclaimer, and this list of conditions. | 26 | notice, disclaimer, and this list of conditions. |
27 | 2. Redistributions in binary form must reproduce the above copyright | 27 | 2. Redistributions in binary form must reproduce the above copyright |
28 | notice, disclaimer, and this list of conditions in the documenta- | 28 | notice, disclaimer, and this list of conditions in the documenta- |
29 | tion and/or other materials provided with the distribution. | 29 | tion and/or other materials provided with the distribution. |
30 | 3. All advertising materials mentioning features or use of this | 30 | 3. All advertising materials mentioning features or use of this |
31 | software must display the following acknowledgment: | 31 | software must display the following acknowledgment: |
32 | 32 | ||
33 | This product includes software developed by Greg Roelofs | 33 | This product includes software developed by Greg Roelofs |
34 | and contributors for the book, "PNG: The Definitive Guide," | 34 | and contributors for the book, "PNG: The Definitive Guide," |
35 | published by O'Reilly and Associates. | 35 | published by O'Reilly and Associates. |
36 | 36 | ||
37 | 37 | ||
38 | LICENSE 2 (GNU GPL v2 or later): | 38 | LICENSE 2 (GNU GPL v2 or later): |
39 | 39 | ||
40 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 42 | the Free Software Foundation; either version 2 of the License, or |
43 | (at your option) any later version. | 43 | (at your option) any later version. |
44 | 44 | ||
45 | This program is distributed in the hope that it will be useful, | 45 | This program is distributed in the hope that it will be useful, |
46 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | GNU General Public License for more details. | 48 | GNU General Public License for more details. |
49 | 49 | ||
50 | You should have received a copy of the GNU General Public License | 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, | 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 | 52 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
53 | 53 | ||
54 | ---------------------------------------------------------------------------*/ | 54 | ---------------------------------------------------------------------------*/ |
55 | 55 | ||
56 | 56 | ||
57 | #include <stdlib.h> /* for exit() prototype */ | 57 | #include <stdlib.h> /* for exit() prototype */ |
58 | #include <setjmp.h> | 58 | #include <setjmp.h> |
59 | 59 | ||
60 | #include <zlib.h> | 60 | #include <zlib.h> |
61 | #include "png.h" /* libpng header from the local directory */ | 61 | #include "png.h" /* libpng header from the local directory */ |
62 | #include "readpng2.h" /* typedefs, common macros, public prototypes */ | 62 | #include "readpng2.h" /* typedefs, common macros, public prototypes */ |
63 | 63 | ||
64 | 64 | ||
65 | /* local prototypes */ | 65 | /* local prototypes */ |
66 | 66 | ||
67 | static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr); | 67 | static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr); |
68 | static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row, | 68 | static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row, |
69 | png_uint_32 row_num, int pass); | 69 | png_uint_32 row_num, int pass); |
70 | static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr); | 70 | static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr); |
71 | static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg); | 71 | static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg); |
72 | 72 | ||
73 | 73 | ||
74 | 74 | ||
75 | 75 | ||
76 | void readpng2_version_info(void) | 76 | void readpng2_version_info(void) |
77 | { | 77 | { |
78 | fprintf(stderr, " Compiled with libpng %s; using libpng %s\n", | 78 | fprintf(stderr, " Compiled with libpng %s; using libpng %s\n", |
79 | PNG_LIBPNG_VER_STRING, png_libpng_ver); | 79 | PNG_LIBPNG_VER_STRING, png_libpng_ver); |
80 | 80 | ||
81 | fprintf(stderr, " and with zlib %s; using zlib %s.\n", | 81 | fprintf(stderr, " and with zlib %s; using zlib %s.\n", |
82 | ZLIB_VERSION, zlib_version); | 82 | ZLIB_VERSION, zlib_version); |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
86 | 86 | ||
87 | 87 | ||
88 | int readpng2_check_sig(uch *sig, int num) | 88 | int readpng2_check_sig(uch *sig, int num) |
89 | { | 89 | { |
90 | return !png_sig_cmp(sig, 0, num); | 90 | return !png_sig_cmp(sig, 0, num); |
91 | } | 91 | } |
92 | 92 | ||
93 | 93 | ||
94 | 94 | ||
95 | 95 | ||
96 | /* returns 0 for success, 2 for libpng problem, 4 for out of memory */ | 96 | /* returns 0 for success, 2 for libpng problem, 4 for out of memory */ |
97 | 97 | ||
98 | int readpng2_init(mainprog_info *mainprog_ptr) | 98 | int readpng2_init(mainprog_info *mainprog_ptr) |
99 | { | 99 | { |
100 | png_structp png_ptr; /* note: temporary variables! */ | 100 | png_structp png_ptr; /* note: temporary variables! */ |
101 | png_infop info_ptr; | 101 | png_infop info_ptr; |
102 | 102 | ||
103 | 103 | ||
104 | /* could also replace libpng warning-handler (final NULL), but no need: */ | 104 | /* could also replace libpng warning-handler (final NULL), but no need: */ |
105 | 105 | ||
106 | png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, | 106 | png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, |
107 | readpng2_error_handler, NULL); | 107 | readpng2_error_handler, NULL); |
108 | if (!png_ptr) | 108 | if (!png_ptr) |
109 | return 4; /* out of memory */ | 109 | return 4; /* out of memory */ |
110 | 110 | ||
111 | info_ptr = png_create_info_struct(png_ptr); | 111 | info_ptr = png_create_info_struct(png_ptr); |
112 | if (!info_ptr) { | 112 | if (!info_ptr) { |
113 | png_destroy_read_struct(&png_ptr, NULL, NULL); | 113 | png_destroy_read_struct(&png_ptr, NULL, NULL); |
114 | return 4; /* out of memory */ | 114 | return 4; /* out of memory */ |
115 | } | 115 | } |
116 | 116 | ||
117 | 117 | ||
118 | /* we could create a second info struct here (end_info), but it's only | 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 | 119 | * useful if we want to keep pre- and post-IDAT chunk info separated |
120 | * (mainly for PNG-aware image editors and converters) */ | 120 | * (mainly for PNG-aware image editors and converters) */ |
121 | 121 | ||
122 | 122 | ||
123 | /* setjmp() must be called in every function that calls a PNG-reading | 123 | /* setjmp() must be called in every function that calls a PNG-reading |
124 | * libpng function, unless an alternate error handler was installed-- | 124 | * libpng function, unless an alternate error handler was installed-- |
125 | * but compatible error handlers must either use longjmp() themselves | 125 | * but compatible error handlers must either use longjmp() themselves |
126 | * (as in this program) or exit immediately, so here we are: */ | 126 | * (as in this program) or exit immediately, so here we are: */ |
127 | 127 | ||
128 | if (setjmp(mainprog_ptr->jmpbuf)) { | 128 | if (setjmp(mainprog_ptr->jmpbuf)) { |
129 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 129 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
130 | return 2; | 130 | return 2; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED | 134 | #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED |
135 | /* prepare the reader to ignore all recognized chunks whose data won't be | 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, | 136 | * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT, |
137 | * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */ | 137 | * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */ |
138 | { | 138 | { |
139 | /* These byte strings were copied from png.h. If a future libpng | 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 | 140 | * version recognizes more chunks, add them to this list. If a |
141 | * future version of readpng2.c recognizes more chunks, delete them | 141 | * future version of readpng2.c recognizes more chunks, delete them |
142 | * from this list. */ | 142 | * from this list. */ |
143 | static /* const */ png_byte chunks_to_ignore[] = { | 143 | static /* const */ png_byte chunks_to_ignore[] = { |
144 | 99, 72, 82, 77, '\0', /* cHRM */ | 144 | 99, 72, 82, 77, '\0', /* cHRM */ |
145 | 104, 73, 83, 84, '\0', /* hIST */ | 145 | 104, 73, 83, 84, '\0', /* hIST */ |
146 | 105, 67, 67, 80, '\0', /* iCCP */ | 146 | 105, 67, 67, 80, '\0', /* iCCP */ |
147 | 105, 84, 88, 116, '\0', /* iTXt */ | 147 | 105, 84, 88, 116, '\0', /* iTXt */ |
148 | 111, 70, 70, 115, '\0', /* oFFs */ | 148 | 111, 70, 70, 115, '\0', /* oFFs */ |
149 | 112, 67, 65, 76, '\0', /* pCAL */ | 149 | 112, 67, 65, 76, '\0', /* pCAL */ |
150 | 112, 72, 89, 115, '\0', /* pHYs */ | 150 | 112, 72, 89, 115, '\0', /* pHYs */ |
151 | 115, 66, 73, 84, '\0', /* sBIT */ | 151 | 115, 66, 73, 84, '\0', /* sBIT */ |
152 | 115, 67, 65, 76, '\0', /* sCAL */ | 152 | 115, 67, 65, 76, '\0', /* sCAL */ |
153 | 115, 80, 76, 84, '\0', /* sPLT */ | 153 | 115, 80, 76, 84, '\0', /* sPLT */ |
154 | 115, 84, 69, 82, '\0', /* sTER */ | 154 | 115, 84, 69, 82, '\0', /* sTER */ |
155 | 116, 69, 88, 116, '\0', /* tEXt */ | 155 | 116, 69, 88, 116, '\0', /* tEXt */ |
156 | 116, 73, 77, 69, '\0', /* tIME */ | 156 | 116, 73, 77, 69, '\0', /* tIME */ |
157 | 122, 84, 88, 116, '\0' /* zTXt */ | 157 | 122, 84, 88, 116, '\0' /* zTXt */ |
158 | }; | 158 | }; |
159 | 159 | ||
160 | png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */, | 160 | png_set_keep_unknown_chunks(png_ptr, 1 /* PNG_HANDLE_CHUNK_NEVER */, |
161 | chunks_to_ignore, sizeof(chunks_to_ignore)/5); | 161 | chunks_to_ignore, sizeof(chunks_to_ignore)/5); |
162 | } | 162 | } |
163 | #endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */ | 163 | #endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */ |
164 | 164 | ||
165 | 165 | ||
166 | /* instead of doing png_init_io() here, now we set up our callback | 166 | /* instead of doing png_init_io() here, now we set up our callback |
167 | * functions for progressive decoding */ | 167 | * functions for progressive decoding */ |
168 | 168 | ||
169 | png_set_progressive_read_fn(png_ptr, mainprog_ptr, | 169 | png_set_progressive_read_fn(png_ptr, mainprog_ptr, |
170 | readpng2_info_callback, readpng2_row_callback, readpng2_end_callback); | 170 | readpng2_info_callback, readpng2_row_callback, readpng2_end_callback); |
171 | 171 | ||
172 | 172 | ||
173 | /* make sure we save our pointers for use in readpng2_decode_data() */ | 173 | /* make sure we save our pointers for use in readpng2_decode_data() */ |
174 | 174 | ||
175 | mainprog_ptr->png_ptr = png_ptr; | 175 | mainprog_ptr->png_ptr = png_ptr; |
176 | mainprog_ptr->info_ptr = info_ptr; | 176 | mainprog_ptr->info_ptr = info_ptr; |
177 | 177 | ||
178 | 178 | ||
179 | /* and that's all there is to initialization */ | 179 | /* and that's all there is to initialization */ |
180 | 180 | ||
181 | return 0; | 181 | return 0; |
182 | } | 182 | } |
183 | 183 | ||
184 | 184 | ||
185 | 185 | ||
186 | 186 | ||
187 | /* returns 0 for success, 2 for libpng (longjmp) problem */ | 187 | /* returns 0 for success, 2 for libpng (longjmp) problem */ |
188 | 188 | ||
189 | int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length) | 189 | int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length) |
190 | { | 190 | { |
191 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; | 191 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; |
192 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; | 192 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; |
193 | 193 | ||
194 | 194 | ||
195 | /* setjmp() must be called in every function that calls a PNG-reading | 195 | /* setjmp() must be called in every function that calls a PNG-reading |
196 | * libpng function */ | 196 | * libpng function */ |
197 | 197 | ||
198 | if (setjmp(mainprog_ptr->jmpbuf)) { | 198 | if (setjmp(mainprog_ptr->jmpbuf)) { |
199 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 199 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
200 | mainprog_ptr->png_ptr = NULL; | 200 | mainprog_ptr->png_ptr = NULL; |
201 | mainprog_ptr->info_ptr = NULL; | 201 | mainprog_ptr->info_ptr = NULL; |
202 | return 2; | 202 | return 2; |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
206 | /* hand off the next chunk of input data to libpng for decoding */ | 206 | /* hand off the next chunk of input data to libpng for decoding */ |
207 | 207 | ||
208 | png_process_data(png_ptr, info_ptr, rawbuf, length); | 208 | png_process_data(png_ptr, info_ptr, rawbuf, length); |
209 | 209 | ||
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | 214 | ||
215 | 215 | ||
216 | static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr) | 216 | static void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr) |
217 | { | 217 | { |
218 | mainprog_info *mainprog_ptr; | 218 | mainprog_info *mainprog_ptr; |
219 | int color_type, bit_depth; | 219 | int color_type, bit_depth; |
220 | png_uint_32 width, height; | 220 | png_uint_32 width, height; |
221 | #ifdef PNG_FLOATING_POINT_SUPPORTED | 221 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
222 | double gamma; | 222 | double gamma; |
223 | #else | 223 | #else |
224 | png_fixed_point gamma; | 224 | png_fixed_point gamma; |
225 | #endif | 225 | #endif |
226 | 226 | ||
227 | 227 | ||
228 | /* setjmp() doesn't make sense here, because we'd either have to exit(), | 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 | 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 | 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 | 231 | * to readpng2_decode_data(), which can return an error value to the main |
232 | * program. */ | 232 | * program. */ |
233 | 233 | ||
234 | 234 | ||
235 | /* retrieve the pointer to our special-purpose struct, using the png_ptr | 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 | 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 | 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 | 238 | * decoding several PNG images at the same time, one needs to avoid mixing |
239 | * up different images' structs) */ | 239 | * up different images' structs) */ |
240 | 240 | ||
241 | mainprog_ptr = png_get_progressive_ptr(png_ptr); | 241 | mainprog_ptr = png_get_progressive_ptr(png_ptr); |
242 | 242 | ||
243 | if (mainprog_ptr == NULL) { /* we be hosed */ | 243 | if (mainprog_ptr == NULL) { /* we be hosed */ |
244 | fprintf(stderr, | 244 | fprintf(stderr, |
245 | "readpng2 error: main struct not recoverable in info_callback.\n"); | 245 | "readpng2 error: main struct not recoverable in info_callback.\n"); |
246 | fflush(stderr); | 246 | fflush(stderr); |
247 | return; | 247 | return; |
248 | /* | 248 | /* |
249 | * Alternatively, we could call our error-handler just like libpng | 249 | * Alternatively, we could call our error-handler just like libpng |
250 | * does, which would effectively terminate the program. Since this | 250 | * does, which would effectively terminate the program. Since this |
251 | * can only happen if png_ptr gets redirected somewhere odd or the | 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 | 252 | * main PNG struct gets wiped, we're probably toast anyway. (If |
253 | * png_ptr itself is NULL, we would not have been called.) | 253 | * png_ptr itself is NULL, we would not have been called.) |
254 | */ | 254 | */ |
255 | } | 255 | } |
256 | 256 | ||
257 | 257 | ||
258 | /* this is just like in the non-progressive case */ | 258 | /* this is just like in the non-progressive case */ |
259 | 259 | ||
260 | png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, | 260 | png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, |
261 | NULL, NULL, NULL); | 261 | NULL, NULL, NULL); |
262 | mainprog_ptr->width = (ulg)width; | 262 | mainprog_ptr->width = (ulg)width; |
263 | mainprog_ptr->height = (ulg)height; | 263 | mainprog_ptr->height = (ulg)height; |
264 | 264 | ||
265 | 265 | ||
266 | /* since we know we've read all of the PNG file's "header" (i.e., up | 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 */ | 267 | * to IDAT), we can check for a background color here */ |
268 | 268 | ||
269 | if (mainprog_ptr->need_bgcolor && | 269 | if (mainprog_ptr->need_bgcolor && |
270 | png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) | 270 | png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD)) |
271 | { | 271 | { |
272 | png_color_16p pBackground; | 272 | png_color_16p pBackground; |
273 | 273 | ||
274 | /* it is not obvious from the libpng documentation, but this function | 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, | 275 | * takes a pointer to a pointer, and it always returns valid red, |
276 | * green and blue values, regardless of color_type: */ | 276 | * green and blue values, regardless of color_type: */ |
277 | png_get_bKGD(png_ptr, info_ptr, &pBackground); | 277 | png_get_bKGD(png_ptr, info_ptr, &pBackground); |
278 | 278 | ||
279 | /* however, it always returns the raw bKGD data, regardless of any | 279 | /* however, it always returns the raw bKGD data, regardless of any |
280 | * bit-depth transformations, so check depth and adjust if necessary */ | 280 | * bit-depth transformations, so check depth and adjust if necessary */ |
281 | if (bit_depth == 16) { | 281 | if (bit_depth == 16) { |
282 | mainprog_ptr->bg_red = pBackground->red >> 8; | 282 | mainprog_ptr->bg_red = pBackground->red >> 8; |
283 | mainprog_ptr->bg_green = pBackground->green >> 8; | 283 | mainprog_ptr->bg_green = pBackground->green >> 8; |
284 | mainprog_ptr->bg_blue = pBackground->blue >> 8; | 284 | mainprog_ptr->bg_blue = pBackground->blue >> 8; |
285 | } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { | 285 | } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) { |
286 | if (bit_depth == 1) | 286 | if (bit_depth == 1) |
287 | mainprog_ptr->bg_red = mainprog_ptr->bg_green = | 287 | mainprog_ptr->bg_red = mainprog_ptr->bg_green = |
288 | mainprog_ptr->bg_blue = pBackground->gray? 255 : 0; | 288 | mainprog_ptr->bg_blue = pBackground->gray? 255 : 0; |
289 | else if (bit_depth == 2) | 289 | else if (bit_depth == 2) |
290 | mainprog_ptr->bg_red = mainprog_ptr->bg_green = | 290 | mainprog_ptr->bg_red = mainprog_ptr->bg_green = |
291 | mainprog_ptr->bg_blue = (255/3) * pBackground->gray; | 291 | mainprog_ptr->bg_blue = (255/3) * pBackground->gray; |
292 | else /* bit_depth == 4 */ | 292 | else /* bit_depth == 4 */ |
293 | mainprog_ptr->bg_red = mainprog_ptr->bg_green = | 293 | mainprog_ptr->bg_red = mainprog_ptr->bg_green = |
294 | mainprog_ptr->bg_blue = (255/15) * pBackground->gray; | 294 | mainprog_ptr->bg_blue = (255/15) * pBackground->gray; |
295 | } else { | 295 | } else { |
296 | mainprog_ptr->bg_red = (uch)pBackground->red; | 296 | mainprog_ptr->bg_red = (uch)pBackground->red; |
297 | mainprog_ptr->bg_green = (uch)pBackground->green; | 297 | mainprog_ptr->bg_green = (uch)pBackground->green; |
298 | mainprog_ptr->bg_blue = (uch)pBackground->blue; | 298 | mainprog_ptr->bg_blue = (uch)pBackground->blue; |
299 | } | 299 | } |
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | /* as before, let libpng expand palette images to RGB, low-bit-depth | 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; | 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 | 305 | * strip 16-bit-per-sample images to 8 bits per sample; and convert |
306 | * grayscale to RGB[A] */ | 306 | * grayscale to RGB[A] */ |
307 | 307 | ||
308 | if (color_type == PNG_COLOR_TYPE_PALETTE) | 308 | if (color_type == PNG_COLOR_TYPE_PALETTE) |
309 | png_set_expand(png_ptr); | 309 | png_set_expand(png_ptr); |
310 | if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) | 310 | if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) |
311 | png_set_expand(png_ptr); | 311 | png_set_expand(png_ptr); |
312 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) | 312 | if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) |
313 | png_set_expand(png_ptr); | 313 | png_set_expand(png_ptr); |
314 | #ifdef PNG_READ_16_TO_8_SUPPORTED | 314 | #ifdef PNG_READ_16_TO_8_SUPPORTED |
315 | if (bit_depth == 16) | 315 | if (bit_depth == 16) |
316 | # ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED | 316 | # ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED |
317 | png_set_scale_16(png_ptr); | 317 | png_set_scale_16(png_ptr); |
318 | # else | 318 | # else |
319 | png_set_strip_16(png_ptr); | 319 | png_set_strip_16(png_ptr); |
320 | # endif | 320 | # endif |
321 | #endif | 321 | #endif |
322 | if (color_type == PNG_COLOR_TYPE_GRAY || | 322 | if (color_type == PNG_COLOR_TYPE_GRAY || |
323 | color_type == PNG_COLOR_TYPE_GRAY_ALPHA) | 323 | color_type == PNG_COLOR_TYPE_GRAY_ALPHA) |
324 | png_set_gray_to_rgb(png_ptr); | 324 | png_set_gray_to_rgb(png_ptr); |
325 | 325 | ||
326 | 326 | ||
327 | /* Unlike the basic viewer, which was designed to operate on local files, | 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 | 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 | 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- | 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 | 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 | 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 | 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 | 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- | 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- | 336 | * identity lookup table, it will darken unlabelled images, which effec- |
337 | * tively favors images from PC-like systems over those originating on | 337 | * tively favors images from PC-like systems over those originating on |
338 | * the local platform. Note that mainprog_ptr->display_exponent is the | 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 | 339 | * "gamma" value for the entire display system, i.e., the product of |
340 | * LUT_exponent and CRT_exponent. */ | 340 | * LUT_exponent and CRT_exponent. */ |
341 | 341 | ||
342 | #ifdef PNG_FLOATING_POINT_SUPPORTED | 342 | #ifdef PNG_FLOATING_POINT_SUPPORTED |
343 | if (png_get_gAMA(png_ptr, info_ptr, &gamma)) | 343 | if (png_get_gAMA(png_ptr, info_ptr, &gamma)) |
344 | png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma); | 344 | png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma); |
345 | else | 345 | else |
346 | png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455); | 346 | png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455); |
347 | #else | 347 | #else |
348 | if (png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) | 348 | if (png_get_gAMA_fixed(png_ptr, info_ptr, &gamma)) |
349 | png_set_gamma_fixed(png_ptr, | 349 | png_set_gamma_fixed(png_ptr, |
350 | (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), gamma); | 350 | (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), gamma); |
351 | else | 351 | else |
352 | png_set_gamma_fixed(png_ptr, | 352 | png_set_gamma_fixed(png_ptr, |
353 | (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), 45455); | 353 | (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), 45455); |
354 | #endif | 354 | #endif |
355 | 355 | ||
356 | /* we'll let libpng expand interlaced images, too */ | 356 | /* we'll let libpng expand interlaced images, too */ |
357 | 357 | ||
358 | mainprog_ptr->passes = png_set_interlace_handling(png_ptr); | 358 | mainprog_ptr->passes = png_set_interlace_handling(png_ptr); |
359 | 359 | ||
360 | 360 | ||
361 | /* all transformations have been registered; now update info_ptr data and | 361 | /* all transformations have been registered; now update info_ptr data and |
362 | * then get rowbytes and channels */ | 362 | * then get rowbytes and channels */ |
363 | 363 | ||
364 | png_read_update_info(png_ptr, info_ptr); | 364 | png_read_update_info(png_ptr, info_ptr); |
365 | 365 | ||
366 | mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr); | 366 | mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr); |
367 | mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr); | 367 | mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr); |
368 | 368 | ||
369 | 369 | ||
370 | /* Call the main program to allocate memory for the image buffer and | 370 | /* Call the main program to allocate memory for the image buffer and |
371 | * initialize windows and whatnot. (The old-style function-pointer | 371 | * initialize windows and whatnot. (The old-style function-pointer |
372 | * invocation is used for compatibility with a few supposedly ANSI | 372 | * invocation is used for compatibility with a few supposedly ANSI |
373 | * compilers that nevertheless barf on "fn_ptr()"-style syntax.) */ | 373 | * compilers that nevertheless barf on "fn_ptr()"-style syntax.) */ |
374 | 374 | ||
375 | (*mainprog_ptr->mainprog_init)(); | 375 | (*mainprog_ptr->mainprog_init)(); |
376 | 376 | ||
377 | 377 | ||
378 | /* and that takes care of initialization */ | 378 | /* and that takes care of initialization */ |
379 | 379 | ||
380 | return; | 380 | return; |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | 384 | ||
385 | 385 | ||
386 | 386 | ||
387 | static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row, | 387 | static void readpng2_row_callback(png_structp png_ptr, png_bytep new_row, |
388 | png_uint_32 row_num, int pass) | 388 | png_uint_32 row_num, int pass) |
389 | { | 389 | { |
390 | mainprog_info *mainprog_ptr; | 390 | mainprog_info *mainprog_ptr; |
391 | 391 | ||
392 | 392 | ||
393 | /* first check whether the row differs from the previous pass; if not, | 393 | /* first check whether the row differs from the previous pass; if not, |
394 | * nothing to combine or display */ | 394 | * nothing to combine or display */ |
395 | 395 | ||
396 | if (!new_row) | 396 | if (!new_row) |
397 | return; | 397 | return; |
398 | 398 | ||
399 | 399 | ||
400 | /* retrieve the pointer to our special-purpose struct so we can access | 400 | /* retrieve the pointer to our special-purpose struct so we can access |
401 | * the old rows and image-display callback function */ | 401 | * the old rows and image-display callback function */ |
402 | 402 | ||
403 | mainprog_ptr = png_get_progressive_ptr(png_ptr); | 403 | mainprog_ptr = png_get_progressive_ptr(png_ptr); |
404 | 404 | ||
405 | 405 | ||
406 | /* save the pass number for optional use by the front end */ | 406 | /* save the pass number for optional use by the front end */ |
407 | 407 | ||
408 | mainprog_ptr->pass = pass; | 408 | mainprog_ptr->pass = pass; |
409 | 409 | ||
410 | 410 | ||
411 | /* have libpng either combine the new row data with the existing row data | 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 | 412 | * from previous passes (if interlaced) or else just copy the new row |
413 | * into the main program's image buffer */ | 413 | * into the main program's image buffer */ |
414 | 414 | ||
415 | png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num], | 415 | png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num], |
416 | new_row); | 416 | new_row); |
417 | 417 | ||
418 | 418 | ||
419 | /* finally, call the display routine in the main program with the number | 419 | /* finally, call the display routine in the main program with the number |
420 | * of the row we just updated */ | 420 | * of the row we just updated */ |
421 | 421 | ||
422 | (*mainprog_ptr->mainprog_display_row)(row_num); | 422 | (*mainprog_ptr->mainprog_display_row)(row_num); |
423 | 423 | ||
424 | 424 | ||
425 | /* and we're ready for more */ | 425 | /* and we're ready for more */ |
426 | 426 | ||
427 | return; | 427 | return; |
428 | } | 428 | } |
429 | 429 | ||
430 | 430 | ||
431 | 431 | ||
432 | 432 | ||
433 | 433 | ||
434 | static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr) | 434 | static void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr) |
435 | { | 435 | { |
436 | mainprog_info *mainprog_ptr; | 436 | mainprog_info *mainprog_ptr; |
437 | 437 | ||
438 | 438 | ||
439 | /* retrieve the pointer to our special-purpose struct */ | 439 | /* retrieve the pointer to our special-purpose struct */ |
440 | 440 | ||
441 | mainprog_ptr = png_get_progressive_ptr(png_ptr); | 441 | mainprog_ptr = png_get_progressive_ptr(png_ptr); |
442 | 442 | ||
443 | 443 | ||
444 | /* let the main program know that it should flush any buffered image | 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 | 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 | 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() | 447 | * NOT call readpng2_cleanup() either here or in the finish_display() |
448 | * routine; wait until control returns to the main program via | 448 | * routine; wait until control returns to the main program via |
449 | * readpng2_decode_data() */ | 449 | * readpng2_decode_data() */ |
450 | 450 | ||
451 | (*mainprog_ptr->mainprog_finish_display)(); | 451 | (*mainprog_ptr->mainprog_finish_display)(); |
452 | 452 | ||
453 | 453 | ||
454 | /* all done */ | 454 | /* all done */ |
455 | 455 | ||
456 | return; | 456 | return; |
457 | } | 457 | } |
458 | 458 | ||
459 | 459 | ||
460 | 460 | ||
461 | 461 | ||
462 | 462 | ||
463 | void readpng2_cleanup(mainprog_info *mainprog_ptr) | 463 | void readpng2_cleanup(mainprog_info *mainprog_ptr) |
464 | { | 464 | { |
465 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; | 465 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; |
466 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; | 466 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; |
467 | 467 | ||
468 | if (png_ptr && info_ptr) | 468 | if (png_ptr && info_ptr) |
469 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); | 469 | png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
470 | 470 | ||
471 | mainprog_ptr->png_ptr = NULL; | 471 | mainprog_ptr->png_ptr = NULL; |
472 | mainprog_ptr->info_ptr = NULL; | 472 | mainprog_ptr->info_ptr = NULL; |
473 | } | 473 | } |
474 | 474 | ||
475 | 475 | ||
476 | 476 | ||
477 | 477 | ||
478 | 478 | ||
479 | static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg) | 479 | static void readpng2_error_handler(png_structp png_ptr, png_const_charp msg) |
480 | { | 480 | { |
481 | mainprog_info *mainprog_ptr; | 481 | mainprog_info *mainprog_ptr; |
482 | 482 | ||
483 | /* This function, aside from the extra step of retrieving the "error | 483 | /* This function, aside from the extra step of retrieving the "error |
484 | * pointer" (below) and the fact that it exists within the application | 484 | * pointer" (below) and the fact that it exists within the application |
485 | * rather than within libpng, is essentially identical to libpng's | 485 | * rather than within libpng, is essentially identical to libpng's |
486 | * default error handler. The second point is critical: since both | 486 | * default error handler. The second point is critical: since both |
487 | * setjmp() and longjmp() are called from the same code, they are | 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, | 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) | 489 | * regardless of whether _BSD_SOURCE or anything else has (or has not) |
490 | * been defined. */ | 490 | * been defined. */ |
491 | 491 | ||
492 | fprintf(stderr, "readpng2 libpng error: %s\n", msg); | 492 | fprintf(stderr, "readpng2 libpng error: %s\n", msg); |
493 | fflush(stderr); | 493 | fflush(stderr); |
494 | 494 | ||
495 | mainprog_ptr = png_get_error_ptr(png_ptr); | 495 | mainprog_ptr = png_get_error_ptr(png_ptr); |
496 | if (mainprog_ptr == NULL) { /* we are completely hosed now */ | 496 | if (mainprog_ptr == NULL) { /* we are completely hosed now */ |
497 | fprintf(stderr, | 497 | fprintf(stderr, |
498 | "readpng2 severe error: jmpbuf not recoverable; terminating.\n"); | 498 | "readpng2 severe error: jmpbuf not recoverable; terminating.\n"); |
499 | fflush(stderr); | 499 | fflush(stderr); |
500 | exit(99); | 500 | exit(99); |
501 | } | 501 | } |
502 | 502 | ||
503 | /* Now we have our data structure we can use the information in it | 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 | 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 | 505 | * where 'setjmp' is called in this file.) This will work with other |
506 | * error handling mechanisms as well - libpng always calls png_error | 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 | 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. | 508 | * is intercepted, application code can do its own error recovery. |
509 | */ | 509 | */ |
510 | longjmp(mainprog_ptr->jmpbuf, 1); | 510 | longjmp(mainprog_ptr->jmpbuf, 1); |
511 | } | 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 index 7a59263..6b3660d 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readpng2.h | |||
@@ -1,116 +1,116 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng2 - progressive-model PNG display program readpng2.h | 3 | rpng2 - progressive-model PNG display program readpng2.h |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. | 7 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. |
8 | 8 | ||
9 | This software is provided "as is," without warranty of any kind, | 9 | This software is provided "as is," without warranty of any kind, |
10 | express or implied. In no event shall the author or contributors | 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 | 11 | be held liable for any damages arising in any way from the use of |
12 | this software. | 12 | this software. |
13 | 13 | ||
14 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 15 | redistribute this software according to the terms of one of the |
16 | following two licenses (at your option): | 16 | following two licenses (at your option): |
17 | 17 | ||
18 | 18 | ||
19 | LICENSE 1 ("BSD-like with advertising clause"): | 19 | LICENSE 1 ("BSD-like with advertising clause"): |
20 | 20 | ||
21 | Permission is granted to anyone to use this software for any purpose, | 21 | Permission is granted to anyone to use this software for any purpose, |
22 | including commercial applications, and to alter it and redistribute | 22 | including commercial applications, and to alter it and redistribute |
23 | it freely, subject to the following restrictions: | 23 | it freely, subject to the following restrictions: |
24 | 24 | ||
25 | 1. Redistributions of source code must retain the above copyright | 25 | 1. Redistributions of source code must retain the above copyright |
26 | notice, disclaimer, and this list of conditions. | 26 | notice, disclaimer, and this list of conditions. |
27 | 2. Redistributions in binary form must reproduce the above copyright | 27 | 2. Redistributions in binary form must reproduce the above copyright |
28 | notice, disclaimer, and this list of conditions in the documenta- | 28 | notice, disclaimer, and this list of conditions in the documenta- |
29 | tion and/or other materials provided with the distribution. | 29 | tion and/or other materials provided with the distribution. |
30 | 3. All advertising materials mentioning features or use of this | 30 | 3. All advertising materials mentioning features or use of this |
31 | software must display the following acknowledgment: | 31 | software must display the following acknowledgment: |
32 | 32 | ||
33 | This product includes software developed by Greg Roelofs | 33 | This product includes software developed by Greg Roelofs |
34 | and contributors for the book, "PNG: The Definitive Guide," | 34 | and contributors for the book, "PNG: The Definitive Guide," |
35 | published by O'Reilly and Associates. | 35 | published by O'Reilly and Associates. |
36 | 36 | ||
37 | 37 | ||
38 | LICENSE 2 (GNU GPL v2 or later): | 38 | LICENSE 2 (GNU GPL v2 or later): |
39 | 39 | ||
40 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 42 | the Free Software Foundation; either version 2 of the License, or |
43 | (at your option) any later version. | 43 | (at your option) any later version. |
44 | 44 | ||
45 | This program is distributed in the hope that it will be useful, | 45 | This program is distributed in the hope that it will be useful, |
46 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | GNU General Public License for more details. | 48 | GNU General Public License for more details. |
49 | 49 | ||
50 | You should have received a copy of the GNU General Public License | 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, | 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 | 52 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
53 | 53 | ||
54 | ---------------------------------------------------------------------------*/ | 54 | ---------------------------------------------------------------------------*/ |
55 | 55 | ||
56 | #ifndef TRUE | 56 | #ifndef TRUE |
57 | # define TRUE 1 | 57 | # define TRUE 1 |
58 | # define FALSE 0 | 58 | # define FALSE 0 |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifndef MAX | 61 | #ifndef MAX |
62 | # define MAX(a,b) ((a) > (b)? (a) : (b)) | 62 | # define MAX(a,b) ((a) > (b)? (a) : (b)) |
63 | # define MIN(a,b) ((a) < (b)? (a) : (b)) | 63 | # define MIN(a,b) ((a) < (b)? (a) : (b)) |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #ifdef DEBUG | 66 | #ifdef DEBUG |
67 | # define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} | 67 | # define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} |
68 | #else | 68 | #else |
69 | # define Trace(x) ; | 69 | # define Trace(x) ; |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | enum rpng2_states { | 72 | enum rpng2_states { |
73 | kPreInit = 0, | 73 | kPreInit = 0, |
74 | kWindowInit, | 74 | kWindowInit, |
75 | kDone | 75 | kDone |
76 | }; | 76 | }; |
77 | 77 | ||
78 | typedef unsigned char uch; | 78 | typedef unsigned char uch; |
79 | typedef unsigned short ush; | 79 | typedef unsigned short ush; |
80 | typedef unsigned long ulg; | 80 | typedef unsigned long ulg; |
81 | 81 | ||
82 | typedef struct _mainprog_info { | 82 | typedef struct _mainprog_info { |
83 | double display_exponent; | 83 | double display_exponent; |
84 | ulg width; | 84 | ulg width; |
85 | ulg height; | 85 | ulg height; |
86 | void *png_ptr; | 86 | void *png_ptr; |
87 | void *info_ptr; | 87 | void *info_ptr; |
88 | void (*mainprog_init)(void); | 88 | void (*mainprog_init)(void); |
89 | void (*mainprog_display_row)(ulg row_num); | 89 | void (*mainprog_display_row)(ulg row_num); |
90 | void (*mainprog_finish_display)(void); | 90 | void (*mainprog_finish_display)(void); |
91 | uch *image_data; | 91 | uch *image_data; |
92 | uch **row_pointers; | 92 | uch **row_pointers; |
93 | jmp_buf jmpbuf; | 93 | jmp_buf jmpbuf; |
94 | int passes; /* not used */ | 94 | int passes; /* not used */ |
95 | int pass; | 95 | int pass; |
96 | int rowbytes; | 96 | int rowbytes; |
97 | int channels; | 97 | int channels; |
98 | int need_bgcolor; | 98 | int need_bgcolor; |
99 | int state; | 99 | int state; |
100 | uch bg_red; | 100 | uch bg_red; |
101 | uch bg_green; | 101 | uch bg_green; |
102 | uch bg_blue; | 102 | uch bg_blue; |
103 | } mainprog_info; | 103 | } mainprog_info; |
104 | 104 | ||
105 | 105 | ||
106 | /* prototypes for public functions in readpng2.c */ | 106 | /* prototypes for public functions in readpng2.c */ |
107 | 107 | ||
108 | void readpng2_version_info(void); | 108 | void readpng2_version_info(void); |
109 | 109 | ||
110 | int readpng2_check_sig(uch *sig, int num); | 110 | int readpng2_check_sig(uch *sig, int num); |
111 | 111 | ||
112 | int readpng2_init(mainprog_info *mainprog_ptr); | 112 | int readpng2_init(mainprog_info *mainprog_ptr); |
113 | 113 | ||
114 | int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length); | 114 | int readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length); |
115 | 115 | ||
116 | void readpng2_cleanup(mainprog_info *mainprog_ptr); | 116 | void 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 index 1ba2092..be9a56d 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c | |||
@@ -1,179 +1,179 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng - simple PNG display program readppm.c | 3 | rpng - simple PNG display program readppm.c |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | This is a special-purpose replacement for readpng.c that allows binary | 7 | This is a special-purpose replacement for readpng.c that allows binary |
8 | PPM files to be used in place of PNG images. | 8 | PPM files to be used in place of PNG images. |
9 | 9 | ||
10 | --------------------------------------------------------------------------- | 10 | --------------------------------------------------------------------------- |
11 | 11 | ||
12 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 12 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
13 | 13 | ||
14 | This software is provided "as is," without warranty of any kind, | 14 | This software is provided "as is," without warranty of any kind, |
15 | express or implied. In no event shall the author or contributors | 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 | 16 | be held liable for any damages arising in any way from the use of |
17 | this software. | 17 | this software. |
18 | 18 | ||
19 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 20 | redistribute this software according to the terms of one of the |
21 | following two licenses (at your option): | 21 | following two licenses (at your option): |
22 | 22 | ||
23 | 23 | ||
24 | LICENSE 1 ("BSD-like with advertising clause"): | 24 | LICENSE 1 ("BSD-like with advertising clause"): |
25 | 25 | ||
26 | Permission is granted to anyone to use this software for any purpose, | 26 | Permission is granted to anyone to use this software for any purpose, |
27 | including commercial applications, and to alter it and redistribute | 27 | including commercial applications, and to alter it and redistribute |
28 | it freely, subject to the following restrictions: | 28 | it freely, subject to the following restrictions: |
29 | 29 | ||
30 | 1. Redistributions of source code must retain the above copyright | 30 | 1. Redistributions of source code must retain the above copyright |
31 | notice, disclaimer, and this list of conditions. | 31 | notice, disclaimer, and this list of conditions. |
32 | 2. Redistributions in binary form must reproduce the above copyright | 32 | 2. Redistributions in binary form must reproduce the above copyright |
33 | notice, disclaimer, and this list of conditions in the documenta- | 33 | notice, disclaimer, and this list of conditions in the documenta- |
34 | tion and/or other materials provided with the distribution. | 34 | tion and/or other materials provided with the distribution. |
35 | 3. All advertising materials mentioning features or use of this | 35 | 3. All advertising materials mentioning features or use of this |
36 | software must display the following acknowledgment: | 36 | software must display the following acknowledgment: |
37 | 37 | ||
38 | This product includes software developed by Greg Roelofs | 38 | This product includes software developed by Greg Roelofs |
39 | and contributors for the book, "PNG: The Definitive Guide," | 39 | and contributors for the book, "PNG: The Definitive Guide," |
40 | published by O'Reilly and Associates. | 40 | published by O'Reilly and Associates. |
41 | 41 | ||
42 | 42 | ||
43 | LICENSE 2 (GNU GPL v2 or later): | 43 | LICENSE 2 (GNU GPL v2 or later): |
44 | 44 | ||
45 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 47 | the Free Software Foundation; either version 2 of the License, or |
48 | (at your option) any later version. | 48 | (at your option) any later version. |
49 | 49 | ||
50 | This program is distributed in the hope that it will be useful, | 50 | This program is distributed in the hope that it will be useful, |
51 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 51 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
52 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 52 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
53 | GNU General Public License for more details. | 53 | GNU General Public License for more details. |
54 | 54 | ||
55 | You should have received a copy of the GNU General Public License | 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, | 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 | 57 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
58 | 58 | ||
59 | ---------------------------------------------------------------------------*/ | 59 | ---------------------------------------------------------------------------*/ |
60 | 60 | ||
61 | #include <stdio.h> | 61 | #include <stdio.h> |
62 | #include <stdlib.h> | 62 | #include <stdlib.h> |
63 | 63 | ||
64 | #include "readpng.h" /* typedefs, common macros, public prototypes */ | 64 | #include "readpng.h" /* typedefs, common macros, public prototypes */ |
65 | 65 | ||
66 | 66 | ||
67 | ulg width, height; | 67 | ulg width, height; |
68 | int bit_depth, color_type, channels; | 68 | int bit_depth, color_type, channels; |
69 | uch *image_data = NULL; | 69 | uch *image_data = NULL; |
70 | FILE *saved_infile; | 70 | FILE *saved_infile; |
71 | 71 | ||
72 | 72 | ||
73 | void readpng_version_info() | 73 | void readpng_version_info() |
74 | { | 74 | { |
75 | fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n"); | 75 | fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n"); |
76 | } | 76 | } |
77 | 77 | ||
78 | 78 | ||
79 | /* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ | 79 | /* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ |
80 | 80 | ||
81 | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) | 81 | int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) |
82 | { | 82 | { |
83 | static uch ppmline[256]; | 83 | static uch ppmline[256]; |
84 | int maxval; | 84 | int maxval; |
85 | 85 | ||
86 | 86 | ||
87 | saved_infile = infile; | 87 | saved_infile = infile; |
88 | 88 | ||
89 | fgets(ppmline, 256, infile); | 89 | fgets(ppmline, 256, infile); |
90 | if (ppmline[0] != 'P' || ppmline[1] != '6') { | 90 | if (ppmline[0] != 'P' || ppmline[1] != '6') { |
91 | fprintf(stderr, "ERROR: not a PPM file\n"); | 91 | fprintf(stderr, "ERROR: not a PPM file\n"); |
92 | return 1; | 92 | return 1; |
93 | } | 93 | } |
94 | /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */ | 94 | /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */ |
95 | if (ppmline[1] == '6') { | 95 | if (ppmline[1] == '6') { |
96 | color_type = 2; | 96 | color_type = 2; |
97 | channels = 3; | 97 | channels = 3; |
98 | } else if (ppmline[1] == '8') { | 98 | } else if (ppmline[1] == '8') { |
99 | color_type = 6; | 99 | color_type = 6; |
100 | channels = 4; | 100 | channels = 4; |
101 | } else /* if (ppmline[1] == '5') */ { | 101 | } else /* if (ppmline[1] == '5') */ { |
102 | color_type = 0; | 102 | color_type = 0; |
103 | channels = 1; | 103 | channels = 1; |
104 | } | 104 | } |
105 | 105 | ||
106 | do { | 106 | do { |
107 | fgets(ppmline, 256, infile); | 107 | fgets(ppmline, 256, infile); |
108 | } while (ppmline[0] == '#'); | 108 | } while (ppmline[0] == '#'); |
109 | sscanf(ppmline, "%lu %lu", &width, &height); | 109 | sscanf(ppmline, "%lu %lu", &width, &height); |
110 | 110 | ||
111 | do { | 111 | do { |
112 | fgets(ppmline, 256, infile); | 112 | fgets(ppmline, 256, infile); |
113 | } while (ppmline[0] == '#'); | 113 | } while (ppmline[0] == '#'); |
114 | sscanf(ppmline, "%d", &maxval); | 114 | sscanf(ppmline, "%d", &maxval); |
115 | if (maxval != 255) { | 115 | if (maxval != 255) { |
116 | fprintf(stderr, "ERROR: maxval = %d\n", maxval); | 116 | fprintf(stderr, "ERROR: maxval = %d\n", maxval); |
117 | return 2; | 117 | return 2; |
118 | } | 118 | } |
119 | bit_depth = 8; | 119 | bit_depth = 8; |
120 | 120 | ||
121 | *pWidth = width; | 121 | *pWidth = width; |
122 | *pHeight = height; | 122 | *pHeight = height; |
123 | 123 | ||
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | 128 | ||
129 | 129 | ||
130 | /* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error; | 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 */ | 131 | * scales values to 8-bit if necessary */ |
132 | 132 | ||
133 | int readpng_get_bgcolor(uch *red, uch *green, uch *blue) | 133 | int readpng_get_bgcolor(uch *red, uch *green, uch *blue) |
134 | { | 134 | { |
135 | return 1; | 135 | return 1; |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | 139 | ||
140 | 140 | ||
141 | /* display_exponent == LUT_exponent * CRT_exponent */ | 141 | /* display_exponent == LUT_exponent * CRT_exponent */ |
142 | 142 | ||
143 | uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) | 143 | uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) |
144 | { | 144 | { |
145 | ulg rowbytes; | 145 | ulg rowbytes; |
146 | 146 | ||
147 | 147 | ||
148 | /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits, | 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 | 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] */ | 150 | * images to 8 bits per sample; and convert grayscale to RGB[A] */ |
151 | 151 | ||
152 | /* GRR WARNING: grayscale needs to be expanded and channels reset! */ | 152 | /* GRR WARNING: grayscale needs to be expanded and channels reset! */ |
153 | 153 | ||
154 | *pRowbytes = rowbytes = channels*width; | 154 | *pRowbytes = rowbytes = channels*width; |
155 | *pChannels = channels; | 155 | *pChannels = channels; |
156 | 156 | ||
157 | if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { | 157 | if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { |
158 | return NULL; | 158 | return NULL; |
159 | } | 159 | } |
160 | 160 | ||
161 | Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height)); | 161 | Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height)); |
162 | 162 | ||
163 | 163 | ||
164 | /* now we can go ahead and just read the whole image */ | 164 | /* now we can go ahead and just read the whole image */ |
165 | 165 | ||
166 | fread(image_data, 1L, rowbytes*height, saved_infile); | 166 | fread(image_data, 1L, rowbytes*height, saved_infile); |
167 | 167 | ||
168 | 168 | ||
169 | return image_data; | 169 | return image_data; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | void readpng_cleanup(int free_image_data) | 173 | void readpng_cleanup(int free_image_data) |
174 | { | 174 | { |
175 | if (free_image_data && image_data) { | 175 | if (free_image_data && image_data) { |
176 | free(image_data); | 176 | free(image_data); |
177 | image_data = NULL; | 177 | image_data = NULL; |
178 | } | 178 | } |
179 | } | 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 index 1c22282..f53ddc8 100644 --- 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 | |||
@@ -1,728 +1,728 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng - simple PNG display program rpng-win.c | 3 | rpng - simple PNG display program rpng-win.c |
4 | 4 | ||
5 | This program decodes and displays PNG images, with gamma correction and | 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 | 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. | 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 | 8 | This version is for 32-bit Windows; it may compile under 16-bit Windows |
9 | with a little tweaking (or maybe not). | 9 | with a little tweaking (or maybe not). |
10 | 10 | ||
11 | to do: | 11 | to do: |
12 | - handle quoted command-line args (especially filenames with spaces) | 12 | - handle quoted command-line args (especially filenames with spaces) |
13 | - have minimum window width: oh well | 13 | - have minimum window width: oh well |
14 | - use %.1023s to simplify truncation of title-bar string? | 14 | - use %.1023s to simplify truncation of title-bar string? |
15 | 15 | ||
16 | --------------------------------------------------------------------------- | 16 | --------------------------------------------------------------------------- |
17 | 17 | ||
18 | Changelog: | 18 | Changelog: |
19 | - 1.00: initial public release | 19 | - 1.00: initial public release |
20 | - 1.01: modified to allow abbreviated options; fixed long/ulong mis- | 20 | - 1.01: modified to allow abbreviated options; fixed long/ulong mis- |
21 | match; switched to png_jmpbuf() macro | 21 | match; switched to png_jmpbuf() macro |
22 | - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed | 22 | - 1.02: added extra set of parentheses to png_jmpbuf() macro; fixed |
23 | command-line parsing bug | 23 | command-line parsing bug |
24 | - 1.10: enabled "message window"/console (thanks to David Geldreich) | 24 | - 1.10: enabled "message window"/console (thanks to David Geldreich) |
25 | - 2.00: dual-licensed (added GNU GPL) | 25 | - 2.00: dual-licensed (added GNU GPL) |
26 | - 2.01: fixed improper display of usage screen on PNG error(s) | 26 | - 2.01: fixed improper display of usage screen on PNG error(s) |
27 | 27 | ||
28 | --------------------------------------------------------------------------- | 28 | --------------------------------------------------------------------------- |
29 | 29 | ||
30 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. | 30 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. |
31 | 31 | ||
32 | This software is provided "as is," without warranty of any kind, | 32 | This software is provided "as is," without warranty of any kind, |
33 | express or implied. In no event shall the author or contributors | 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 | 34 | be held liable for any damages arising in any way from the use of |
35 | this software. | 35 | this software. |
36 | 36 | ||
37 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 38 | redistribute this software according to the terms of one of the |
39 | following two licenses (at your option): | 39 | following two licenses (at your option): |
40 | 40 | ||
41 | 41 | ||
42 | LICENSE 1 ("BSD-like with advertising clause"): | 42 | LICENSE 1 ("BSD-like with advertising clause"): |
43 | 43 | ||
44 | Permission is granted to anyone to use this software for any purpose, | 44 | Permission is granted to anyone to use this software for any purpose, |
45 | including commercial applications, and to alter it and redistribute | 45 | including commercial applications, and to alter it and redistribute |
46 | it freely, subject to the following restrictions: | 46 | it freely, subject to the following restrictions: |
47 | 47 | ||
48 | 1. Redistributions of source code must retain the above copyright | 48 | 1. Redistributions of source code must retain the above copyright |
49 | notice, disclaimer, and this list of conditions. | 49 | notice, disclaimer, and this list of conditions. |
50 | 2. Redistributions in binary form must reproduce the above copyright | 50 | 2. Redistributions in binary form must reproduce the above copyright |
51 | notice, disclaimer, and this list of conditions in the documenta- | 51 | notice, disclaimer, and this list of conditions in the documenta- |
52 | tion and/or other materials provided with the distribution. | 52 | tion and/or other materials provided with the distribution. |
53 | 3. All advertising materials mentioning features or use of this | 53 | 3. All advertising materials mentioning features or use of this |
54 | software must display the following acknowledgment: | 54 | software must display the following acknowledgment: |
55 | 55 | ||
56 | This product includes software developed by Greg Roelofs | 56 | This product includes software developed by Greg Roelofs |
57 | and contributors for the book, "PNG: The Definitive Guide," | 57 | and contributors for the book, "PNG: The Definitive Guide," |
58 | published by O'Reilly and Associates. | 58 | published by O'Reilly and Associates. |
59 | 59 | ||
60 | 60 | ||
61 | LICENSE 2 (GNU GPL v2 or later): | 61 | LICENSE 2 (GNU GPL v2 or later): |
62 | 62 | ||
63 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 65 | the Free Software Foundation; either version 2 of the License, or |
66 | (at your option) any later version. | 66 | (at your option) any later version. |
67 | 67 | ||
68 | This program is distributed in the hope that it will be useful, | 68 | This program is distributed in the hope that it will be useful, |
69 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 69 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
70 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 70 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
71 | GNU General Public License for more details. | 71 | GNU General Public License for more details. |
72 | 72 | ||
73 | You should have received a copy of the GNU General Public License | 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, | 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 | 75 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
76 | 76 | ||
77 | ---------------------------------------------------------------------------*/ | 77 | ---------------------------------------------------------------------------*/ |
78 | 78 | ||
79 | #define PROGNAME "rpng-win" | 79 | #define PROGNAME "rpng-win" |
80 | #define LONGNAME "Simple PNG Viewer for Windows" | 80 | #define LONGNAME "Simple PNG Viewer for Windows" |
81 | #define VERSION "2.01 of 16 March 2008" | 81 | #define VERSION "2.01 of 16 March 2008" |
82 | 82 | ||
83 | #include <stdio.h> | 83 | #include <stdio.h> |
84 | #include <stdlib.h> | 84 | #include <stdlib.h> |
85 | #include <string.h> | 85 | #include <string.h> |
86 | #include <time.h> | 86 | #include <time.h> |
87 | #include <windows.h> | 87 | #include <windows.h> |
88 | #ifdef __CYGWIN__ | 88 | #ifdef __CYGWIN__ |
89 | /* getch replacement. Turns out, we don't really need this, | 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 | 90 | * but leave it here if we ever enable any of the uses of |
91 | * _getch in the main code | 91 | * _getch in the main code |
92 | */ | 92 | */ |
93 | #include <unistd.h> | 93 | #include <unistd.h> |
94 | #include <termio.h> | 94 | #include <termio.h> |
95 | #include <sys/ioctl.h> | 95 | #include <sys/ioctl.h> |
96 | int repl_getch( void ) | 96 | int repl_getch( void ) |
97 | { | 97 | { |
98 | char ch; | 98 | char ch; |
99 | int fd = fileno(stdin); | 99 | int fd = fileno(stdin); |
100 | struct termio old_tty, new_tty; | 100 | struct termio old_tty, new_tty; |
101 | 101 | ||
102 | ioctl(fd, TCGETA, &old_tty); | 102 | ioctl(fd, TCGETA, &old_tty); |
103 | new_tty = old_tty; | 103 | new_tty = old_tty; |
104 | new_tty.c_lflag &= ~(ICANON | ECHO | ISIG); | 104 | new_tty.c_lflag &= ~(ICANON | ECHO | ISIG); |
105 | ioctl(fd, TCSETA, &new_tty); | 105 | ioctl(fd, TCSETA, &new_tty); |
106 | fread(&ch, 1, sizeof(ch), stdin); | 106 | fread(&ch, 1, sizeof(ch), stdin); |
107 | ioctl(fd, TCSETA, &old_tty); | 107 | ioctl(fd, TCSETA, &old_tty); |
108 | 108 | ||
109 | return ch; | 109 | return ch; |
110 | } | 110 | } |
111 | #define _getch repl_getch | 111 | #define _getch repl_getch |
112 | #else | 112 | #else |
113 | #include <conio.h> /* only for _getch() */ | 113 | #include <conio.h> /* only for _getch() */ |
114 | #endif | 114 | #endif |
115 | 115 | ||
116 | /* #define DEBUG : this enables the Trace() macros */ | 116 | /* #define DEBUG : this enables the Trace() macros */ |
117 | 117 | ||
118 | #include "readpng.h" /* typedefs, common macros, readpng prototypes */ | 118 | #include "readpng.h" /* typedefs, common macros, readpng prototypes */ |
119 | 119 | ||
120 | 120 | ||
121 | /* could just include png.h, but this macro is the only thing we need | 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 | 122 | * (name and typedefs changed to local versions); note that side effects |
123 | * only happen with alpha (which could easily be avoided with | 123 | * only happen with alpha (which could easily be avoided with |
124 | * "ush acopy = (alpha);") */ | 124 | * "ush acopy = (alpha);") */ |
125 | 125 | ||
126 | #define alpha_composite(composite, fg, alpha, bg) { \ | 126 | #define alpha_composite(composite, fg, alpha, bg) { \ |
127 | ush temp = ((ush)(fg)*(ush)(alpha) + \ | 127 | ush temp = ((ush)(fg)*(ush)(alpha) + \ |
128 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ | 128 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ |
129 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ | 129 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ |
130 | } | 130 | } |
131 | 131 | ||
132 | 132 | ||
133 | /* local prototypes */ | 133 | /* local prototypes */ |
134 | static int rpng_win_create_window(HINSTANCE hInst, int showmode); | 134 | static int rpng_win_create_window(HINSTANCE hInst, int showmode); |
135 | static int rpng_win_display_image(void); | 135 | static int rpng_win_display_image(void); |
136 | static void rpng_win_cleanup(void); | 136 | static void rpng_win_cleanup(void); |
137 | LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM); | 137 | LRESULT CALLBACK rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM); |
138 | 138 | ||
139 | 139 | ||
140 | static char titlebar[1024]; | 140 | static char titlebar[1024]; |
141 | static char *progname = PROGNAME; | 141 | static char *progname = PROGNAME; |
142 | static char *appname = LONGNAME; | 142 | static char *appname = LONGNAME; |
143 | static char *filename; | 143 | static char *filename; |
144 | static FILE *infile; | 144 | static FILE *infile; |
145 | 145 | ||
146 | static char *bgstr; | 146 | static char *bgstr; |
147 | static uch bg_red=0, bg_green=0, bg_blue=0; | 147 | static uch bg_red=0, bg_green=0, bg_blue=0; |
148 | 148 | ||
149 | static double display_exponent; | 149 | static double display_exponent; |
150 | 150 | ||
151 | static ulg image_width, image_height, image_rowbytes; | 151 | static ulg image_width, image_height, image_rowbytes; |
152 | static int image_channels; | 152 | static int image_channels; |
153 | static uch *image_data; | 153 | static uch *image_data; |
154 | 154 | ||
155 | /* Windows-specific variables */ | 155 | /* Windows-specific variables */ |
156 | static ulg wimage_rowbytes; | 156 | static ulg wimage_rowbytes; |
157 | static uch *dib; | 157 | static uch *dib; |
158 | static uch *wimage_data; | 158 | static uch *wimage_data; |
159 | static BITMAPINFOHEADER *bmih; | 159 | static BITMAPINFOHEADER *bmih; |
160 | 160 | ||
161 | static HWND global_hwnd; | 161 | static HWND global_hwnd; |
162 | 162 | ||
163 | 163 | ||
164 | 164 | ||
165 | 165 | ||
166 | int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) | 166 | int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) |
167 | { | 167 | { |
168 | char *args[1024]; /* arbitrary limit, but should suffice */ | 168 | char *args[1024]; /* arbitrary limit, but should suffice */ |
169 | char *p, *q, **argv = args; | 169 | char *p, *q, **argv = args; |
170 | int argc = 0; | 170 | int argc = 0; |
171 | int rc, alen, flen; | 171 | int rc, alen, flen; |
172 | int error = 0; | 172 | int error = 0; |
173 | int have_bg = FALSE; | 173 | int have_bg = FALSE; |
174 | double LUT_exponent; /* just the lookup table */ | 174 | double LUT_exponent; /* just the lookup table */ |
175 | double CRT_exponent = 2.2; /* just the monitor */ | 175 | double CRT_exponent = 2.2; /* just the monitor */ |
176 | double default_display_exponent; /* whole display system */ | 176 | double default_display_exponent; /* whole display system */ |
177 | MSG msg; | 177 | MSG msg; |
178 | 178 | ||
179 | 179 | ||
180 | filename = (char *)NULL; | 180 | filename = (char *)NULL; |
181 | 181 | ||
182 | #ifndef __CYGWIN__ | 182 | #ifndef __CYGWIN__ |
183 | /* First reenable console output, which normally goes to the bit bucket | 183 | /* First reenable console output, which normally goes to the bit bucket |
184 | * for windowed apps. Closing the console window will terminate the | 184 | * for windowed apps. Closing the console window will terminate the |
185 | * app. Thanks to David.Geldreich@realviz.com for supplying the magical | 185 | * app. Thanks to David.Geldreich@realviz.com for supplying the magical |
186 | * incantation. */ | 186 | * incantation. */ |
187 | 187 | ||
188 | AllocConsole(); | 188 | AllocConsole(); |
189 | freopen("CONOUT$", "a", stderr); | 189 | freopen("CONOUT$", "a", stderr); |
190 | freopen("CONOUT$", "a", stdout); | 190 | freopen("CONOUT$", "a", stdout); |
191 | #endif | 191 | #endif |
192 | 192 | ||
193 | 193 | ||
194 | /* Next set the default value for our display-system exponent, i.e., | 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 | 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 | 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 | 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 | 198 | * ones), but it should cover 99% of the current possibilities. And |
199 | * yes, these ifdefs are completely wasted in a Windows program... */ | 199 | * yes, these ifdefs are completely wasted in a Windows program... */ |
200 | 200 | ||
201 | #if defined(NeXT) | 201 | #if defined(NeXT) |
202 | LUT_exponent = 1.0 / 2.2; | 202 | LUT_exponent = 1.0 / 2.2; |
203 | /* | 203 | /* |
204 | if (some_next_function_that_returns_gamma(&next_gamma)) | 204 | if (some_next_function_that_returns_gamma(&next_gamma)) |
205 | LUT_exponent = 1.0 / next_gamma; | 205 | LUT_exponent = 1.0 / next_gamma; |
206 | */ | 206 | */ |
207 | #elif defined(sgi) | 207 | #elif defined(sgi) |
208 | LUT_exponent = 1.0 / 1.7; | 208 | LUT_exponent = 1.0 / 1.7; |
209 | /* there doesn't seem to be any documented function to get the | 209 | /* there doesn't seem to be any documented function to get the |
210 | * "gamma" value, so we do it the hard way */ | 210 | * "gamma" value, so we do it the hard way */ |
211 | infile = fopen("/etc/config/system.glGammaVal", "r"); | 211 | infile = fopen("/etc/config/system.glGammaVal", "r"); |
212 | if (infile) { | 212 | if (infile) { |
213 | double sgi_gamma; | 213 | double sgi_gamma; |
214 | 214 | ||
215 | fgets(tmpline, 80, infile); | 215 | fgets(tmpline, 80, infile); |
216 | fclose(infile); | 216 | fclose(infile); |
217 | sgi_gamma = atof(tmpline); | 217 | sgi_gamma = atof(tmpline); |
218 | if (sgi_gamma > 0.0) | 218 | if (sgi_gamma > 0.0) |
219 | LUT_exponent = 1.0 / sgi_gamma; | 219 | LUT_exponent = 1.0 / sgi_gamma; |
220 | } | 220 | } |
221 | #elif defined(Macintosh) | 221 | #elif defined(Macintosh) |
222 | LUT_exponent = 1.8 / 2.61; | 222 | LUT_exponent = 1.8 / 2.61; |
223 | /* | 223 | /* |
224 | if (some_mac_function_that_returns_gamma(&mac_gamma)) | 224 | if (some_mac_function_that_returns_gamma(&mac_gamma)) |
225 | LUT_exponent = mac_gamma / 2.61; | 225 | LUT_exponent = mac_gamma / 2.61; |
226 | */ | 226 | */ |
227 | #else | 227 | #else |
228 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ | 228 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ |
229 | #endif | 229 | #endif |
230 | 230 | ||
231 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ | 231 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ |
232 | default_display_exponent = LUT_exponent * CRT_exponent; | 232 | default_display_exponent = LUT_exponent * CRT_exponent; |
233 | 233 | ||
234 | 234 | ||
235 | /* If the user has set the SCREEN_GAMMA environment variable as suggested | 235 | /* If the user has set the SCREEN_GAMMA environment variable as suggested |
236 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise | 236 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise |
237 | * use the default value we just calculated. Either way, the user may | 237 | * use the default value we just calculated. Either way, the user may |
238 | * override this via a command-line option. */ | 238 | * override this via a command-line option. */ |
239 | 239 | ||
240 | if ((p = getenv("SCREEN_GAMMA")) != NULL) | 240 | if ((p = getenv("SCREEN_GAMMA")) != NULL) |
241 | display_exponent = atof(p); | 241 | display_exponent = atof(p); |
242 | else | 242 | else |
243 | display_exponent = default_display_exponent; | 243 | display_exponent = default_display_exponent; |
244 | 244 | ||
245 | 245 | ||
246 | /* Windows really hates command lines, so we have to set up our own argv. | 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 | 247 | * Note that we do NOT bother with quoted arguments here, so don't use |
248 | * filenames with spaces in 'em! */ | 248 | * filenames with spaces in 'em! */ |
249 | 249 | ||
250 | argv[argc++] = PROGNAME; | 250 | argv[argc++] = PROGNAME; |
251 | p = cmd; | 251 | p = cmd; |
252 | for (;;) { | 252 | for (;;) { |
253 | if (*p == ' ') | 253 | if (*p == ' ') |
254 | while (*++p == ' ') | 254 | while (*++p == ' ') |
255 | ; | 255 | ; |
256 | /* now p points at the first non-space after some spaces */ | 256 | /* now p points at the first non-space after some spaces */ |
257 | if (*p == '\0') | 257 | if (*p == '\0') |
258 | break; /* nothing after the spaces: done */ | 258 | break; /* nothing after the spaces: done */ |
259 | argv[argc++] = q = p; | 259 | argv[argc++] = q = p; |
260 | while (*q && *q != ' ') | 260 | while (*q && *q != ' ') |
261 | ++q; | 261 | ++q; |
262 | /* now q points at a space or the end of the string */ | 262 | /* now q points at a space or the end of the string */ |
263 | if (*q == '\0') | 263 | if (*q == '\0') |
264 | break; /* last argv already terminated; quit */ | 264 | break; /* last argv already terminated; quit */ |
265 | *q = '\0'; /* change space to terminator */ | 265 | *q = '\0'; /* change space to terminator */ |
266 | p = q + 1; | 266 | p = q + 1; |
267 | } | 267 | } |
268 | argv[argc] = NULL; /* terminate the argv array itself */ | 268 | argv[argc] = NULL; /* terminate the argv array itself */ |
269 | 269 | ||
270 | 270 | ||
271 | /* Now parse the command line for options and the PNG filename. */ | 271 | /* Now parse the command line for options and the PNG filename. */ |
272 | 272 | ||
273 | while (*++argv && !error) { | 273 | while (*++argv && !error) { |
274 | if (!strncmp(*argv, "-gamma", 2)) { | 274 | if (!strncmp(*argv, "-gamma", 2)) { |
275 | if (!*++argv) | 275 | if (!*++argv) |
276 | ++error; | 276 | ++error; |
277 | else { | 277 | else { |
278 | display_exponent = atof(*argv); | 278 | display_exponent = atof(*argv); |
279 | if (display_exponent <= 0.0) | 279 | if (display_exponent <= 0.0) |
280 | ++error; | 280 | ++error; |
281 | } | 281 | } |
282 | } else if (!strncmp(*argv, "-bgcolor", 2)) { | 282 | } else if (!strncmp(*argv, "-bgcolor", 2)) { |
283 | if (!*++argv) | 283 | if (!*++argv) |
284 | ++error; | 284 | ++error; |
285 | else { | 285 | else { |
286 | bgstr = *argv; | 286 | bgstr = *argv; |
287 | if (strlen(bgstr) != 7 || bgstr[0] != '#') | 287 | if (strlen(bgstr) != 7 || bgstr[0] != '#') |
288 | ++error; | 288 | ++error; |
289 | else | 289 | else |
290 | have_bg = TRUE; | 290 | have_bg = TRUE; |
291 | } | 291 | } |
292 | } else { | 292 | } else { |
293 | if (**argv != '-') { | 293 | if (**argv != '-') { |
294 | filename = *argv; | 294 | filename = *argv; |
295 | if (argv[1]) /* shouldn't be any more args after filename */ | 295 | if (argv[1]) /* shouldn't be any more args after filename */ |
296 | ++error; | 296 | ++error; |
297 | } else | 297 | } else |
298 | ++error; /* not expecting any other options */ | 298 | ++error; /* not expecting any other options */ |
299 | } | 299 | } |
300 | } | 300 | } |
301 | 301 | ||
302 | if (!filename) | 302 | if (!filename) |
303 | ++error; | 303 | ++error; |
304 | 304 | ||
305 | 305 | ||
306 | /* print usage screen if any errors up to this point */ | 306 | /* print usage screen if any errors up to this point */ |
307 | 307 | ||
308 | if (error) { | 308 | if (error) { |
309 | #ifndef __CYGWIN__ | 309 | #ifndef __CYGWIN__ |
310 | int ch; | 310 | int ch; |
311 | #endif | 311 | #endif |
312 | 312 | ||
313 | fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); | 313 | fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); |
314 | readpng_version_info(); | 314 | readpng_version_info(); |
315 | fprintf(stderr, "\n" | 315 | fprintf(stderr, "\n" |
316 | "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n" | 316 | "Usage: %s [-gamma exp] [-bgcolor bg] file.png\n" |
317 | " exp \ttransfer-function exponent (``gamma'') of the display\n" | 317 | " exp \ttransfer-function exponent (``gamma'') of the display\n" |
318 | "\t\t system in floating-point format (e.g., ``%.1f''); equal\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" | 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" | 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" | 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" | 322 | "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" |
323 | "\t\t used with transparent images\n" | 323 | "\t\t used with transparent images\n" |
324 | "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" | 324 | "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" |
325 | #ifndef __CYGWIN__ | 325 | #ifndef __CYGWIN__ |
326 | "Press Q or Esc to quit this usage screen.\n" | 326 | "Press Q or Esc to quit this usage screen.\n" |
327 | #endif | 327 | #endif |
328 | "\n", PROGNAME, default_display_exponent); | 328 | "\n", PROGNAME, default_display_exponent); |
329 | #ifndef __CYGWIN__ | 329 | #ifndef __CYGWIN__ |
330 | do | 330 | do |
331 | ch = _getch(); | 331 | ch = _getch(); |
332 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); | 332 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); |
333 | #endif | 333 | #endif |
334 | exit(1); | 334 | exit(1); |
335 | } | 335 | } |
336 | 336 | ||
337 | 337 | ||
338 | if (!(infile = fopen(filename, "rb"))) { | 338 | if (!(infile = fopen(filename, "rb"))) { |
339 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); | 339 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); |
340 | ++error; | 340 | ++error; |
341 | } else { | 341 | } else { |
342 | if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { | 342 | if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { |
343 | switch (rc) { | 343 | switch (rc) { |
344 | case 1: | 344 | case 1: |
345 | fprintf(stderr, PROGNAME | 345 | fprintf(stderr, PROGNAME |
346 | ": [%s] is not a PNG file: incorrect signature\n", | 346 | ": [%s] is not a PNG file: incorrect signature\n", |
347 | filename); | 347 | filename); |
348 | break; | 348 | break; |
349 | case 2: | 349 | case 2: |
350 | fprintf(stderr, PROGNAME | 350 | fprintf(stderr, PROGNAME |
351 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); | 351 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); |
352 | break; | 352 | break; |
353 | case 4: | 353 | case 4: |
354 | fprintf(stderr, PROGNAME ": insufficient memory\n"); | 354 | fprintf(stderr, PROGNAME ": insufficient memory\n"); |
355 | break; | 355 | break; |
356 | default: | 356 | default: |
357 | fprintf(stderr, PROGNAME | 357 | fprintf(stderr, PROGNAME |
358 | ": unknown readpng_init() error\n"); | 358 | ": unknown readpng_init() error\n"); |
359 | break; | 359 | break; |
360 | } | 360 | } |
361 | ++error; | 361 | ++error; |
362 | } | 362 | } |
363 | if (error) | 363 | if (error) |
364 | fclose(infile); | 364 | fclose(infile); |
365 | } | 365 | } |
366 | 366 | ||
367 | 367 | ||
368 | if (error) { | 368 | if (error) { |
369 | #ifndef __CYGWIN__ | 369 | #ifndef __CYGWIN__ |
370 | int ch; | 370 | int ch; |
371 | #endif | 371 | #endif |
372 | 372 | ||
373 | fprintf(stderr, PROGNAME ": aborting.\n"); | 373 | fprintf(stderr, PROGNAME ": aborting.\n"); |
374 | #ifndef __CYGWIN__ | 374 | #ifndef __CYGWIN__ |
375 | do | 375 | do |
376 | ch = _getch(); | 376 | ch = _getch(); |
377 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); | 377 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); |
378 | #endif | 378 | #endif |
379 | exit(2); | 379 | exit(2); |
380 | } else { | 380 | } else { |
381 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); | 381 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); |
382 | #ifndef __CYGWIN__ | 382 | #ifndef __CYGWIN__ |
383 | fprintf(stderr, | 383 | fprintf(stderr, |
384 | "\n [console window: closing this window will terminate %s]\n\n", | 384 | "\n [console window: closing this window will terminate %s]\n\n", |
385 | PROGNAME); | 385 | PROGNAME); |
386 | #endif | 386 | #endif |
387 | } | 387 | } |
388 | 388 | ||
389 | 389 | ||
390 | /* set the title-bar string, but make sure buffer doesn't overflow */ | 390 | /* set the title-bar string, but make sure buffer doesn't overflow */ |
391 | 391 | ||
392 | alen = strlen(appname); | 392 | alen = strlen(appname); |
393 | flen = strlen(filename); | 393 | flen = strlen(filename); |
394 | if (alen + flen + 3 > 1023) | 394 | if (alen + flen + 3 > 1023) |
395 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); | 395 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); |
396 | else | 396 | else |
397 | sprintf(titlebar, "%s: %s", appname, filename); | 397 | sprintf(titlebar, "%s: %s", appname, filename); |
398 | 398 | ||
399 | 399 | ||
400 | /* if the user didn't specify a background color on the command line, | 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 | 401 | * check for one in the PNG file--if not, the initialized values of 0 |
402 | * (black) will be used */ | 402 | * (black) will be used */ |
403 | 403 | ||
404 | if (have_bg) { | 404 | if (have_bg) { |
405 | unsigned r, g, b; /* this approach quiets compiler warnings */ | 405 | unsigned r, g, b; /* this approach quiets compiler warnings */ |
406 | 406 | ||
407 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); | 407 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); |
408 | bg_red = (uch)r; | 408 | bg_red = (uch)r; |
409 | bg_green = (uch)g; | 409 | bg_green = (uch)g; |
410 | bg_blue = (uch)b; | 410 | bg_blue = (uch)b; |
411 | } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { | 411 | } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { |
412 | readpng_cleanup(TRUE); | 412 | readpng_cleanup(TRUE); |
413 | fprintf(stderr, PROGNAME | 413 | fprintf(stderr, PROGNAME |
414 | ": libpng error while checking for background color\n"); | 414 | ": libpng error while checking for background color\n"); |
415 | exit(2); | 415 | exit(2); |
416 | } | 416 | } |
417 | 417 | ||
418 | 418 | ||
419 | /* do the basic Windows initialization stuff, make the window and fill it | 419 | /* do the basic Windows initialization stuff, make the window and fill it |
420 | * with the background color */ | 420 | * with the background color */ |
421 | 421 | ||
422 | if (rpng_win_create_window(hInst, showmode)) | 422 | if (rpng_win_create_window(hInst, showmode)) |
423 | exit(2); | 423 | exit(2); |
424 | 424 | ||
425 | 425 | ||
426 | /* decode the image, all at once */ | 426 | /* decode the image, all at once */ |
427 | 427 | ||
428 | Trace((stderr, "calling readpng_get_image()\n")) | 428 | Trace((stderr, "calling readpng_get_image()\n")) |
429 | image_data = readpng_get_image(display_exponent, &image_channels, | 429 | image_data = readpng_get_image(display_exponent, &image_channels, |
430 | &image_rowbytes); | 430 | &image_rowbytes); |
431 | Trace((stderr, "done with readpng_get_image()\n")) | 431 | Trace((stderr, "done with readpng_get_image()\n")) |
432 | 432 | ||
433 | 433 | ||
434 | /* done with PNG file, so clean up to minimize memory usage (but do NOT | 434 | /* done with PNG file, so clean up to minimize memory usage (but do NOT |
435 | * nuke image_data!) */ | 435 | * nuke image_data!) */ |
436 | 436 | ||
437 | readpng_cleanup(FALSE); | 437 | readpng_cleanup(FALSE); |
438 | fclose(infile); | 438 | fclose(infile); |
439 | 439 | ||
440 | if (!image_data) { | 440 | if (!image_data) { |
441 | fprintf(stderr, PROGNAME ": unable to decode PNG image\n"); | 441 | fprintf(stderr, PROGNAME ": unable to decode PNG image\n"); |
442 | exit(3); | 442 | exit(3); |
443 | } | 443 | } |
444 | 444 | ||
445 | 445 | ||
446 | /* display image (composite with background if requested) */ | 446 | /* display image (composite with background if requested) */ |
447 | 447 | ||
448 | Trace((stderr, "calling rpng_win_display_image()\n")) | 448 | Trace((stderr, "calling rpng_win_display_image()\n")) |
449 | if (rpng_win_display_image()) { | 449 | if (rpng_win_display_image()) { |
450 | free(image_data); | 450 | free(image_data); |
451 | exit(4); | 451 | exit(4); |
452 | } | 452 | } |
453 | Trace((stderr, "done with rpng_win_display_image()\n")) | 453 | Trace((stderr, "done with rpng_win_display_image()\n")) |
454 | 454 | ||
455 | 455 | ||
456 | /* wait for the user to tell us when to quit */ | 456 | /* wait for the user to tell us when to quit */ |
457 | 457 | ||
458 | printf( | 458 | printf( |
459 | #ifndef __CYGWIN__ | 459 | #ifndef __CYGWIN__ |
460 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n" | 460 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n" |
461 | #else | 461 | #else |
462 | "Done. Press mouse button 1 (within image window) to quit.\n" | 462 | "Done. Press mouse button 1 (within image window) to quit.\n" |
463 | #endif | 463 | #endif |
464 | ); | 464 | ); |
465 | fflush(stdout); | 465 | fflush(stdout); |
466 | 466 | ||
467 | while (GetMessage(&msg, NULL, 0, 0)) { | 467 | while (GetMessage(&msg, NULL, 0, 0)) { |
468 | TranslateMessage(&msg); | 468 | TranslateMessage(&msg); |
469 | DispatchMessage(&msg); | 469 | DispatchMessage(&msg); |
470 | } | 470 | } |
471 | 471 | ||
472 | 472 | ||
473 | /* OK, we're done: clean up all image and Windows resources and go away */ | 473 | /* OK, we're done: clean up all image and Windows resources and go away */ |
474 | 474 | ||
475 | rpng_win_cleanup(); | 475 | rpng_win_cleanup(); |
476 | 476 | ||
477 | return msg.wParam; | 477 | return msg.wParam; |
478 | } | 478 | } |
479 | 479 | ||
480 | 480 | ||
481 | 481 | ||
482 | 482 | ||
483 | 483 | ||
484 | static int rpng_win_create_window(HINSTANCE hInst, int showmode) | 484 | static int rpng_win_create_window(HINSTANCE hInst, int showmode) |
485 | { | 485 | { |
486 | uch *dest; | 486 | uch *dest; |
487 | int extra_width, extra_height; | 487 | int extra_width, extra_height; |
488 | ulg i, j; | 488 | ulg i, j; |
489 | WNDCLASSEX wndclass; | 489 | WNDCLASSEX wndclass; |
490 | 490 | ||
491 | 491 | ||
492 | /*--------------------------------------------------------------------------- | 492 | /*--------------------------------------------------------------------------- |
493 | Allocate memory for the display-specific version of the image (round up | 493 | Allocate memory for the display-specific version of the image (round up |
494 | to multiple of 4 for Windows DIB). | 494 | to multiple of 4 for Windows DIB). |
495 | ---------------------------------------------------------------------------*/ | 495 | ---------------------------------------------------------------------------*/ |
496 | 496 | ||
497 | wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2; | 497 | wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2; |
498 | 498 | ||
499 | if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) + | 499 | if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) + |
500 | wimage_rowbytes*image_height))) | 500 | wimage_rowbytes*image_height))) |
501 | { | 501 | { |
502 | return 4; /* fail */ | 502 | return 4; /* fail */ |
503 | } | 503 | } |
504 | 504 | ||
505 | /*--------------------------------------------------------------------------- | 505 | /*--------------------------------------------------------------------------- |
506 | Initialize the DIB. Negative height means to use top-down BMP ordering | 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 | 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 | 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. | 509 | directly => wimage_data begins immediately after BMP header. |
510 | ---------------------------------------------------------------------------*/ | 510 | ---------------------------------------------------------------------------*/ |
511 | 511 | ||
512 | memset(dib, 0, sizeof(BITMAPINFOHEADER)); | 512 | memset(dib, 0, sizeof(BITMAPINFOHEADER)); |
513 | bmih = (BITMAPINFOHEADER *)dib; | 513 | bmih = (BITMAPINFOHEADER *)dib; |
514 | bmih->biSize = sizeof(BITMAPINFOHEADER); | 514 | bmih->biSize = sizeof(BITMAPINFOHEADER); |
515 | bmih->biWidth = image_width; | 515 | bmih->biWidth = image_width; |
516 | bmih->biHeight = -((long)image_height); | 516 | bmih->biHeight = -((long)image_height); |
517 | bmih->biPlanes = 1; | 517 | bmih->biPlanes = 1; |
518 | bmih->biBitCount = 24; | 518 | bmih->biBitCount = 24; |
519 | bmih->biCompression = 0; | 519 | bmih->biCompression = 0; |
520 | wimage_data = dib + sizeof(BITMAPINFOHEADER); | 520 | wimage_data = dib + sizeof(BITMAPINFOHEADER); |
521 | 521 | ||
522 | /*--------------------------------------------------------------------------- | 522 | /*--------------------------------------------------------------------------- |
523 | Fill in background color (black by default); data are in BGR order. | 523 | Fill in background color (black by default); data are in BGR order. |
524 | ---------------------------------------------------------------------------*/ | 524 | ---------------------------------------------------------------------------*/ |
525 | 525 | ||
526 | for (j = 0; j < image_height; ++j) { | 526 | for (j = 0; j < image_height; ++j) { |
527 | dest = wimage_data + j*wimage_rowbytes; | 527 | dest = wimage_data + j*wimage_rowbytes; |
528 | for (i = image_width; i > 0; --i) { | 528 | for (i = image_width; i > 0; --i) { |
529 | *dest++ = bg_blue; | 529 | *dest++ = bg_blue; |
530 | *dest++ = bg_green; | 530 | *dest++ = bg_green; |
531 | *dest++ = bg_red; | 531 | *dest++ = bg_red; |
532 | } | 532 | } |
533 | } | 533 | } |
534 | 534 | ||
535 | /*--------------------------------------------------------------------------- | 535 | /*--------------------------------------------------------------------------- |
536 | Set the window parameters. | 536 | Set the window parameters. |
537 | ---------------------------------------------------------------------------*/ | 537 | ---------------------------------------------------------------------------*/ |
538 | 538 | ||
539 | memset(&wndclass, 0, sizeof(wndclass)); | 539 | memset(&wndclass, 0, sizeof(wndclass)); |
540 | 540 | ||
541 | wndclass.cbSize = sizeof(wndclass); | 541 | wndclass.cbSize = sizeof(wndclass); |
542 | wndclass.style = CS_HREDRAW | CS_VREDRAW; | 542 | wndclass.style = CS_HREDRAW | CS_VREDRAW; |
543 | wndclass.lpfnWndProc = rpng_win_wndproc; | 543 | wndclass.lpfnWndProc = rpng_win_wndproc; |
544 | wndclass.hInstance = hInst; | 544 | wndclass.hInstance = hInst; |
545 | wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); | 545 | wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); |
546 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); | 546 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
547 | wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); | 547 | wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); |
548 | wndclass.lpszMenuName = NULL; | 548 | wndclass.lpszMenuName = NULL; |
549 | wndclass.lpszClassName = progname; | 549 | wndclass.lpszClassName = progname; |
550 | wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | 550 | wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); |
551 | 551 | ||
552 | RegisterClassEx(&wndclass); | 552 | RegisterClassEx(&wndclass); |
553 | 553 | ||
554 | /*--------------------------------------------------------------------------- | 554 | /*--------------------------------------------------------------------------- |
555 | Finally, create the window. | 555 | Finally, create the window. |
556 | ---------------------------------------------------------------------------*/ | 556 | ---------------------------------------------------------------------------*/ |
557 | 557 | ||
558 | extra_width = 2*(GetSystemMetrics(SM_CXBORDER) + | 558 | extra_width = 2*(GetSystemMetrics(SM_CXBORDER) + |
559 | GetSystemMetrics(SM_CXDLGFRAME)); | 559 | GetSystemMetrics(SM_CXDLGFRAME)); |
560 | extra_height = 2*(GetSystemMetrics(SM_CYBORDER) + | 560 | extra_height = 2*(GetSystemMetrics(SM_CYBORDER) + |
561 | GetSystemMetrics(SM_CYDLGFRAME)) + | 561 | GetSystemMetrics(SM_CYDLGFRAME)) + |
562 | GetSystemMetrics(SM_CYCAPTION); | 562 | GetSystemMetrics(SM_CYCAPTION); |
563 | 563 | ||
564 | global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW, | 564 | global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW, |
565 | CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width, | 565 | CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width, |
566 | image_height+extra_height, NULL, NULL, hInst, NULL); | 566 | image_height+extra_height, NULL, NULL, hInst, NULL); |
567 | 567 | ||
568 | ShowWindow(global_hwnd, showmode); | 568 | ShowWindow(global_hwnd, showmode); |
569 | UpdateWindow(global_hwnd); | 569 | UpdateWindow(global_hwnd); |
570 | 570 | ||
571 | return 0; | 571 | return 0; |
572 | 572 | ||
573 | } /* end function rpng_win_create_window() */ | 573 | } /* end function rpng_win_create_window() */ |
574 | 574 | ||
575 | 575 | ||
576 | 576 | ||
577 | 577 | ||
578 | 578 | ||
579 | static int rpng_win_display_image() | 579 | static int rpng_win_display_image() |
580 | { | 580 | { |
581 | uch *src, *dest; | 581 | uch *src, *dest; |
582 | uch r, g, b, a; | 582 | uch r, g, b, a; |
583 | ulg i, row, lastrow; | 583 | ulg i, row, lastrow; |
584 | RECT rect; | 584 | RECT rect; |
585 | 585 | ||
586 | 586 | ||
587 | Trace((stderr, "beginning display loop (image_channels == %d)\n", | 587 | Trace((stderr, "beginning display loop (image_channels == %d)\n", |
588 | image_channels)) | 588 | image_channels)) |
589 | Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n", | 589 | Trace((stderr, "(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\n", |
590 | image_width, image_rowbytes, wimage_rowbytes)) | 590 | image_width, image_rowbytes, wimage_rowbytes)) |
591 | 591 | ||
592 | 592 | ||
593 | /*--------------------------------------------------------------------------- | 593 | /*--------------------------------------------------------------------------- |
594 | Blast image data to buffer. This whole routine takes place before the | 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 | 595 | message loop begins, so there's no real point in any pseudo-progressive |
596 | display... | 596 | display... |
597 | ---------------------------------------------------------------------------*/ | 597 | ---------------------------------------------------------------------------*/ |
598 | 598 | ||
599 | for (lastrow = row = 0; row < image_height; ++row) { | 599 | for (lastrow = row = 0; row < image_height; ++row) { |
600 | src = image_data + row*image_rowbytes; | 600 | src = image_data + row*image_rowbytes; |
601 | dest = wimage_data + row*wimage_rowbytes; | 601 | dest = wimage_data + row*wimage_rowbytes; |
602 | if (image_channels == 3) { | 602 | if (image_channels == 3) { |
603 | for (i = image_width; i > 0; --i) { | 603 | for (i = image_width; i > 0; --i) { |
604 | r = *src++; | 604 | r = *src++; |
605 | g = *src++; | 605 | g = *src++; |
606 | b = *src++; | 606 | b = *src++; |
607 | *dest++ = b; | 607 | *dest++ = b; |
608 | *dest++ = g; /* note reverse order */ | 608 | *dest++ = g; /* note reverse order */ |
609 | *dest++ = r; | 609 | *dest++ = r; |
610 | } | 610 | } |
611 | } else /* if (image_channels == 4) */ { | 611 | } else /* if (image_channels == 4) */ { |
612 | for (i = image_width; i > 0; --i) { | 612 | for (i = image_width; i > 0; --i) { |
613 | r = *src++; | 613 | r = *src++; |
614 | g = *src++; | 614 | g = *src++; |
615 | b = *src++; | 615 | b = *src++; |
616 | a = *src++; | 616 | a = *src++; |
617 | if (a == 255) { | 617 | if (a == 255) { |
618 | *dest++ = b; | 618 | *dest++ = b; |
619 | *dest++ = g; | 619 | *dest++ = g; |
620 | *dest++ = r; | 620 | *dest++ = r; |
621 | } else if (a == 0) { | 621 | } else if (a == 0) { |
622 | *dest++ = bg_blue; | 622 | *dest++ = bg_blue; |
623 | *dest++ = bg_green; | 623 | *dest++ = bg_green; |
624 | *dest++ = bg_red; | 624 | *dest++ = bg_red; |
625 | } else { | 625 | } else { |
626 | /* this macro (copied from png.h) composites the | 626 | /* this macro (copied from png.h) composites the |
627 | * foreground and background values and puts the | 627 | * foreground and background values and puts the |
628 | * result into the first argument; there are no | 628 | * result into the first argument; there are no |
629 | * side effects with the first argument */ | 629 | * side effects with the first argument */ |
630 | alpha_composite(*dest++, b, a, bg_blue); | 630 | alpha_composite(*dest++, b, a, bg_blue); |
631 | alpha_composite(*dest++, g, a, bg_green); | 631 | alpha_composite(*dest++, g, a, bg_green); |
632 | alpha_composite(*dest++, r, a, bg_red); | 632 | alpha_composite(*dest++, r, a, bg_red); |
633 | } | 633 | } |
634 | } | 634 | } |
635 | } | 635 | } |
636 | /* display after every 16 lines */ | 636 | /* display after every 16 lines */ |
637 | if (((row+1) & 0xf) == 0) { | 637 | if (((row+1) & 0xf) == 0) { |
638 | rect.left = 0L; | 638 | rect.left = 0L; |
639 | rect.top = (LONG)lastrow; | 639 | rect.top = (LONG)lastrow; |
640 | rect.right = (LONG)image_width; /* possibly off by one? */ | 640 | rect.right = (LONG)image_width; /* possibly off by one? */ |
641 | rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */ | 641 | rect.bottom = (LONG)lastrow + 16L; /* possibly off by one? */ |
642 | InvalidateRect(global_hwnd, &rect, FALSE); | 642 | InvalidateRect(global_hwnd, &rect, FALSE); |
643 | UpdateWindow(global_hwnd); /* similar to XFlush() */ | 643 | UpdateWindow(global_hwnd); /* similar to XFlush() */ |
644 | lastrow = row + 1; | 644 | lastrow = row + 1; |
645 | } | 645 | } |
646 | } | 646 | } |
647 | 647 | ||
648 | Trace((stderr, "calling final image-flush routine\n")) | 648 | Trace((stderr, "calling final image-flush routine\n")) |
649 | if (lastrow < image_height) { | 649 | if (lastrow < image_height) { |
650 | rect.left = 0L; | 650 | rect.left = 0L; |
651 | rect.top = (LONG)lastrow; | 651 | rect.top = (LONG)lastrow; |
652 | rect.right = (LONG)image_width; /* possibly off by one? */ | 652 | rect.right = (LONG)image_width; /* possibly off by one? */ |
653 | rect.bottom = (LONG)image_height; /* possibly off by one? */ | 653 | rect.bottom = (LONG)image_height; /* possibly off by one? */ |
654 | InvalidateRect(global_hwnd, &rect, FALSE); | 654 | InvalidateRect(global_hwnd, &rect, FALSE); |
655 | UpdateWindow(global_hwnd); /* similar to XFlush() */ | 655 | UpdateWindow(global_hwnd); /* similar to XFlush() */ |
656 | } | 656 | } |
657 | 657 | ||
658 | /* | 658 | /* |
659 | last param determines whether or not background is wiped before paint | 659 | last param determines whether or not background is wiped before paint |
660 | InvalidateRect(global_hwnd, NULL, TRUE); | 660 | InvalidateRect(global_hwnd, NULL, TRUE); |
661 | UpdateWindow(global_hwnd); | 661 | UpdateWindow(global_hwnd); |
662 | */ | 662 | */ |
663 | 663 | ||
664 | return 0; | 664 | return 0; |
665 | } | 665 | } |
666 | 666 | ||
667 | 667 | ||
668 | 668 | ||
669 | 669 | ||
670 | 670 | ||
671 | static void rpng_win_cleanup() | 671 | static void rpng_win_cleanup() |
672 | { | 672 | { |
673 | if (image_data) { | 673 | if (image_data) { |
674 | free(image_data); | 674 | free(image_data); |
675 | image_data = NULL; | 675 | image_data = NULL; |
676 | } | 676 | } |
677 | 677 | ||
678 | if (dib) { | 678 | if (dib) { |
679 | free(dib); | 679 | free(dib); |
680 | dib = NULL; | 680 | dib = NULL; |
681 | } | 681 | } |
682 | } | 682 | } |
683 | 683 | ||
684 | 684 | ||
685 | 685 | ||
686 | 686 | ||
687 | 687 | ||
688 | LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP) | 688 | LRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP) |
689 | { | 689 | { |
690 | HDC hdc; | 690 | HDC hdc; |
691 | PAINTSTRUCT ps; | 691 | PAINTSTRUCT ps; |
692 | int rc; | 692 | int rc; |
693 | 693 | ||
694 | switch (iMsg) { | 694 | switch (iMsg) { |
695 | case WM_CREATE: | 695 | case WM_CREATE: |
696 | /* one-time processing here, if any */ | 696 | /* one-time processing here, if any */ |
697 | return 0; | 697 | return 0; |
698 | 698 | ||
699 | case WM_PAINT: | 699 | case WM_PAINT: |
700 | hdc = BeginPaint(hwnd, &ps); | 700 | hdc = BeginPaint(hwnd, &ps); |
701 | /* dest */ | 701 | /* dest */ |
702 | rc = StretchDIBits(hdc, 0, 0, image_width, image_height, | 702 | rc = StretchDIBits(hdc, 0, 0, image_width, image_height, |
703 | /* source */ | 703 | /* source */ |
704 | 0, 0, image_width, image_height, | 704 | 0, 0, image_width, image_height, |
705 | wimage_data, (BITMAPINFO *)bmih, | 705 | wimage_data, (BITMAPINFO *)bmih, |
706 | /* iUsage: no clue */ | 706 | /* iUsage: no clue */ |
707 | 0, SRCCOPY); | 707 | 0, SRCCOPY); |
708 | EndPaint(hwnd, &ps); | 708 | EndPaint(hwnd, &ps); |
709 | return 0; | 709 | return 0; |
710 | 710 | ||
711 | /* wait for the user to tell us when to quit */ | 711 | /* wait for the user to tell us when to quit */ |
712 | case WM_CHAR: | 712 | case WM_CHAR: |
713 | switch (wP) { /* only need one, so ignore repeat count */ | 713 | switch (wP) { /* only need one, so ignore repeat count */ |
714 | case 'q': | 714 | case 'q': |
715 | case 'Q': | 715 | case 'Q': |
716 | case 0x1B: /* Esc key */ | 716 | case 0x1B: /* Esc key */ |
717 | PostQuitMessage(0); | 717 | PostQuitMessage(0); |
718 | } | 718 | } |
719 | return 0; | 719 | return 0; |
720 | 720 | ||
721 | case WM_LBUTTONDOWN: /* another way of quitting */ | 721 | case WM_LBUTTONDOWN: /* another way of quitting */ |
722 | case WM_DESTROY: | 722 | case WM_DESTROY: |
723 | PostQuitMessage(0); | 723 | PostQuitMessage(0); |
724 | return 0; | 724 | return 0; |
725 | } | 725 | } |
726 | 726 | ||
727 | return DefWindowProc(hwnd, iMsg, wP, lP); | 727 | return DefWindowProc(hwnd, iMsg, wP, lP); |
728 | } | 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 index fc8be88..6d10e1b 100644 --- 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 | |||
@@ -1,904 +1,904 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng - simple PNG display program rpng-x.c | 3 | rpng - simple PNG display program rpng-x.c |
4 | 4 | ||
5 | This program decodes and displays PNG images, with gamma correction and | 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 | 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. | 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 | 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). | 9 | by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking). |
10 | 10 | ||
11 | to do: | 11 | to do: |
12 | - 8-bit (colormapped) X support | 12 | - 8-bit (colormapped) X support |
13 | - use %.1023s to simplify truncation of title-bar string? | 13 | - use %.1023s to simplify truncation of title-bar string? |
14 | 14 | ||
15 | --------------------------------------------------------------------------- | 15 | --------------------------------------------------------------------------- |
16 | 16 | ||
17 | Changelog: | 17 | Changelog: |
18 | - 1.01: initial public release | 18 | - 1.01: initial public release |
19 | - 1.02: modified to allow abbreviated options; fixed long/ulong mis- | 19 | - 1.02: modified to allow abbreviated options; fixed long/ulong mis- |
20 | match; switched to png_jmpbuf() macro | 20 | match; switched to png_jmpbuf() macro |
21 | - 1.10: added support for non-default visuals; fixed X pixel-conversion | 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 | 22 | - 1.11: added extra set of parentheses to png_jmpbuf() macro; fixed |
23 | command-line parsing bug | 23 | command-line parsing bug |
24 | - 1.12: fixed some small X memory leaks (thanks to François Petitjean) | 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) | 25 | - 1.13: fixed XFreeGC() crash bug (thanks to Patrick Welche) |
26 | - 1.14: added support for X resources (thanks to Gerhard Niklasch) | 26 | - 1.14: added support for X resources (thanks to Gerhard Niklasch) |
27 | - 2.00: dual-licensed (added GNU GPL) | 27 | - 2.00: dual-licensed (added GNU GPL) |
28 | - 2.01: fixed improper display of usage screen on PNG error(s) | 28 | - 2.01: fixed improper display of usage screen on PNG error(s) |
29 | 29 | ||
30 | --------------------------------------------------------------------------- | 30 | --------------------------------------------------------------------------- |
31 | 31 | ||
32 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. | 32 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. |
33 | 33 | ||
34 | This software is provided "as is," without warranty of any kind, | 34 | This software is provided "as is," without warranty of any kind, |
35 | express or implied. In no event shall the author or contributors | 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 | 36 | be held liable for any damages arising in any way from the use of |
37 | this software. | 37 | this software. |
38 | 38 | ||
39 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 40 | redistribute this software according to the terms of one of the |
41 | following two licenses (at your option): | 41 | following two licenses (at your option): |
42 | 42 | ||
43 | 43 | ||
44 | LICENSE 1 ("BSD-like with advertising clause"): | 44 | LICENSE 1 ("BSD-like with advertising clause"): |
45 | 45 | ||
46 | Permission is granted to anyone to use this software for any purpose, | 46 | Permission is granted to anyone to use this software for any purpose, |
47 | including commercial applications, and to alter it and redistribute | 47 | including commercial applications, and to alter it and redistribute |
48 | it freely, subject to the following restrictions: | 48 | it freely, subject to the following restrictions: |
49 | 49 | ||
50 | 1. Redistributions of source code must retain the above copyright | 50 | 1. Redistributions of source code must retain the above copyright |
51 | notice, disclaimer, and this list of conditions. | 51 | notice, disclaimer, and this list of conditions. |
52 | 2. Redistributions in binary form must reproduce the above copyright | 52 | 2. Redistributions in binary form must reproduce the above copyright |
53 | notice, disclaimer, and this list of conditions in the documenta- | 53 | notice, disclaimer, and this list of conditions in the documenta- |
54 | tion and/or other materials provided with the distribution. | 54 | tion and/or other materials provided with the distribution. |
55 | 3. All advertising materials mentioning features or use of this | 55 | 3. All advertising materials mentioning features or use of this |
56 | software must display the following acknowledgment: | 56 | software must display the following acknowledgment: |
57 | 57 | ||
58 | This product includes software developed by Greg Roelofs | 58 | This product includes software developed by Greg Roelofs |
59 | and contributors for the book, "PNG: The Definitive Guide," | 59 | and contributors for the book, "PNG: The Definitive Guide," |
60 | published by O'Reilly and Associates. | 60 | published by O'Reilly and Associates. |
61 | 61 | ||
62 | 62 | ||
63 | LICENSE 2 (GNU GPL v2 or later): | 63 | LICENSE 2 (GNU GPL v2 or later): |
64 | 64 | ||
65 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 67 | the Free Software Foundation; either version 2 of the License, or |
68 | (at your option) any later version. | 68 | (at your option) any later version. |
69 | 69 | ||
70 | This program is distributed in the hope that it will be useful, | 70 | This program is distributed in the hope that it will be useful, |
71 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 71 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
72 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 72 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
73 | GNU General Public License for more details. | 73 | GNU General Public License for more details. |
74 | 74 | ||
75 | You should have received a copy of the GNU General Public License | 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, | 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 | 77 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
78 | 78 | ||
79 | ---------------------------------------------------------------------------*/ | 79 | ---------------------------------------------------------------------------*/ |
80 | 80 | ||
81 | #define PROGNAME "rpng-x" | 81 | #define PROGNAME "rpng-x" |
82 | #define LONGNAME "Simple PNG Viewer for X" | 82 | #define LONGNAME "Simple PNG Viewer for X" |
83 | #define VERSION "2.01 of 16 March 2008" | 83 | #define VERSION "2.01 of 16 March 2008" |
84 | #define RESNAME "rpng" /* our X resource application name */ | 84 | #define RESNAME "rpng" /* our X resource application name */ |
85 | #define RESCLASS "Rpng" /* our X resource class name */ | 85 | #define RESCLASS "Rpng" /* our X resource class name */ |
86 | 86 | ||
87 | #include <stdio.h> | 87 | #include <stdio.h> |
88 | #include <stdlib.h> | 88 | #include <stdlib.h> |
89 | #include <string.h> | 89 | #include <string.h> |
90 | #include <time.h> | 90 | #include <time.h> |
91 | #include <X11/Xlib.h> | 91 | #include <X11/Xlib.h> |
92 | #include <X11/Xutil.h> | 92 | #include <X11/Xutil.h> |
93 | #include <X11/Xos.h> | 93 | #include <X11/Xos.h> |
94 | #include <X11/keysym.h> | 94 | #include <X11/keysym.h> |
95 | 95 | ||
96 | /* #define DEBUG : this enables the Trace() macros */ | 96 | /* #define DEBUG : this enables the Trace() macros */ |
97 | 97 | ||
98 | #include "readpng.h" /* typedefs, common macros, readpng prototypes */ | 98 | #include "readpng.h" /* typedefs, common macros, readpng prototypes */ |
99 | 99 | ||
100 | 100 | ||
101 | /* could just include png.h, but this macro is the only thing we need | 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 | 102 | * (name and typedefs changed to local versions); note that side effects |
103 | * only happen with alpha (which could easily be avoided with | 103 | * only happen with alpha (which could easily be avoided with |
104 | * "ush acopy = (alpha);") */ | 104 | * "ush acopy = (alpha);") */ |
105 | 105 | ||
106 | #define alpha_composite(composite, fg, alpha, bg) { \ | 106 | #define alpha_composite(composite, fg, alpha, bg) { \ |
107 | ush temp = ((ush)(fg)*(ush)(alpha) + \ | 107 | ush temp = ((ush)(fg)*(ush)(alpha) + \ |
108 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ | 108 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ |
109 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ | 109 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | /* local prototypes */ | 113 | /* local prototypes */ |
114 | static int rpng_x_create_window(void); | 114 | static int rpng_x_create_window(void); |
115 | static int rpng_x_display_image(void); | 115 | static int rpng_x_display_image(void); |
116 | static void rpng_x_cleanup(void); | 116 | static void rpng_x_cleanup(void); |
117 | static int rpng_x_msb(ulg u32val); | 117 | static int rpng_x_msb(ulg u32val); |
118 | 118 | ||
119 | 119 | ||
120 | static char titlebar[1024], *window_name = titlebar; | 120 | static char titlebar[1024], *window_name = titlebar; |
121 | static char *appname = LONGNAME; | 121 | static char *appname = LONGNAME; |
122 | static char *icon_name = PROGNAME; | 122 | static char *icon_name = PROGNAME; |
123 | static char *res_name = RESNAME; | 123 | static char *res_name = RESNAME; |
124 | static char *res_class = RESCLASS; | 124 | static char *res_class = RESCLASS; |
125 | static char *filename; | 125 | static char *filename; |
126 | static FILE *infile; | 126 | static FILE *infile; |
127 | 127 | ||
128 | static char *bgstr; | 128 | static char *bgstr; |
129 | static uch bg_red=0, bg_green=0, bg_blue=0; | 129 | static uch bg_red=0, bg_green=0, bg_blue=0; |
130 | 130 | ||
131 | static double display_exponent; | 131 | static double display_exponent; |
132 | 132 | ||
133 | static ulg image_width, image_height, image_rowbytes; | 133 | static ulg image_width, image_height, image_rowbytes; |
134 | static int image_channels; | 134 | static int image_channels; |
135 | static uch *image_data; | 135 | static uch *image_data; |
136 | 136 | ||
137 | /* X-specific variables */ | 137 | /* X-specific variables */ |
138 | static char *displayname; | 138 | static char *displayname; |
139 | static XImage *ximage; | 139 | static XImage *ximage; |
140 | static Display *display; | 140 | static Display *display; |
141 | static int depth; | 141 | static int depth; |
142 | static Visual *visual; | 142 | static Visual *visual; |
143 | static XVisualInfo *visual_list; | 143 | static XVisualInfo *visual_list; |
144 | static int RShift, GShift, BShift; | 144 | static int RShift, GShift, BShift; |
145 | static ulg RMask, GMask, BMask; | 145 | static ulg RMask, GMask, BMask; |
146 | static Window window; | 146 | static Window window; |
147 | static GC gc; | 147 | static GC gc; |
148 | static Colormap colormap; | 148 | static Colormap colormap; |
149 | 149 | ||
150 | static int have_nondefault_visual = FALSE; | 150 | static int have_nondefault_visual = FALSE; |
151 | static int have_colormap = FALSE; | 151 | static int have_colormap = FALSE; |
152 | static int have_window = FALSE; | 152 | static int have_window = FALSE; |
153 | static int have_gc = FALSE; | 153 | static int have_gc = FALSE; |
154 | /* | 154 | /* |
155 | ulg numcolors=0, pixels[256]; | 155 | ulg numcolors=0, pixels[256]; |
156 | ush reds[256], greens[256], blues[256]; | 156 | ush reds[256], greens[256], blues[256]; |
157 | */ | 157 | */ |
158 | 158 | ||
159 | 159 | ||
160 | 160 | ||
161 | 161 | ||
162 | int main(int argc, char **argv) | 162 | int main(int argc, char **argv) |
163 | { | 163 | { |
164 | #ifdef sgi | 164 | #ifdef sgi |
165 | char tmpline[80]; | 165 | char tmpline[80]; |
166 | #endif | 166 | #endif |
167 | char *p; | 167 | char *p; |
168 | int rc, alen, flen; | 168 | int rc, alen, flen; |
169 | int error = 0; | 169 | int error = 0; |
170 | int have_bg = FALSE; | 170 | int have_bg = FALSE; |
171 | double LUT_exponent; /* just the lookup table */ | 171 | double LUT_exponent; /* just the lookup table */ |
172 | double CRT_exponent = 2.2; /* just the monitor */ | 172 | double CRT_exponent = 2.2; /* just the monitor */ |
173 | double default_display_exponent; /* whole display system */ | 173 | double default_display_exponent; /* whole display system */ |
174 | XEvent e; | 174 | XEvent e; |
175 | KeySym k; | 175 | KeySym k; |
176 | 176 | ||
177 | 177 | ||
178 | displayname = (char *)NULL; | 178 | displayname = (char *)NULL; |
179 | filename = (char *)NULL; | 179 | filename = (char *)NULL; |
180 | 180 | ||
181 | 181 | ||
182 | /* First set the default value for our display-system exponent, i.e., | 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 | 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 | 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 | 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. */ | 186 | * ones), but it should cover 99% of the current possibilities. */ |
187 | 187 | ||
188 | #if defined(NeXT) | 188 | #if defined(NeXT) |
189 | LUT_exponent = 1.0 / 2.2; | 189 | LUT_exponent = 1.0 / 2.2; |
190 | /* | 190 | /* |
191 | if (some_next_function_that_returns_gamma(&next_gamma)) | 191 | if (some_next_function_that_returns_gamma(&next_gamma)) |
192 | LUT_exponent = 1.0 / next_gamma; | 192 | LUT_exponent = 1.0 / next_gamma; |
193 | */ | 193 | */ |
194 | #elif defined(sgi) | 194 | #elif defined(sgi) |
195 | LUT_exponent = 1.0 / 1.7; | 195 | LUT_exponent = 1.0 / 1.7; |
196 | /* there doesn't seem to be any documented function to get the | 196 | /* there doesn't seem to be any documented function to get the |
197 | * "gamma" value, so we do it the hard way */ | 197 | * "gamma" value, so we do it the hard way */ |
198 | infile = fopen("/etc/config/system.glGammaVal", "r"); | 198 | infile = fopen("/etc/config/system.glGammaVal", "r"); |
199 | if (infile) { | 199 | if (infile) { |
200 | double sgi_gamma; | 200 | double sgi_gamma; |
201 | 201 | ||
202 | fgets(tmpline, 80, infile); | 202 | fgets(tmpline, 80, infile); |
203 | fclose(infile); | 203 | fclose(infile); |
204 | sgi_gamma = atof(tmpline); | 204 | sgi_gamma = atof(tmpline); |
205 | if (sgi_gamma > 0.0) | 205 | if (sgi_gamma > 0.0) |
206 | LUT_exponent = 1.0 / sgi_gamma; | 206 | LUT_exponent = 1.0 / sgi_gamma; |
207 | } | 207 | } |
208 | #elif defined(Macintosh) | 208 | #elif defined(Macintosh) |
209 | LUT_exponent = 1.8 / 2.61; | 209 | LUT_exponent = 1.8 / 2.61; |
210 | /* | 210 | /* |
211 | if (some_mac_function_that_returns_gamma(&mac_gamma)) | 211 | if (some_mac_function_that_returns_gamma(&mac_gamma)) |
212 | LUT_exponent = mac_gamma / 2.61; | 212 | LUT_exponent = mac_gamma / 2.61; |
213 | */ | 213 | */ |
214 | #else | 214 | #else |
215 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ | 215 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ |
216 | #endif | 216 | #endif |
217 | 217 | ||
218 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ | 218 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ |
219 | default_display_exponent = LUT_exponent * CRT_exponent; | 219 | default_display_exponent = LUT_exponent * CRT_exponent; |
220 | 220 | ||
221 | 221 | ||
222 | /* If the user has set the SCREEN_GAMMA environment variable as suggested | 222 | /* If the user has set the SCREEN_GAMMA environment variable as suggested |
223 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise | 223 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise |
224 | * use the default value we just calculated. Either way, the user may | 224 | * use the default value we just calculated. Either way, the user may |
225 | * override this via a command-line option. */ | 225 | * override this via a command-line option. */ |
226 | 226 | ||
227 | if ((p = getenv("SCREEN_GAMMA")) != NULL) | 227 | if ((p = getenv("SCREEN_GAMMA")) != NULL) |
228 | display_exponent = atof(p); | 228 | display_exponent = atof(p); |
229 | else | 229 | else |
230 | display_exponent = default_display_exponent; | 230 | display_exponent = default_display_exponent; |
231 | 231 | ||
232 | 232 | ||
233 | /* Now parse the command line for options and the PNG filename. */ | 233 | /* Now parse the command line for options and the PNG filename. */ |
234 | 234 | ||
235 | while (*++argv && !error) { | 235 | while (*++argv && !error) { |
236 | if (!strncmp(*argv, "-display", 2)) { | 236 | if (!strncmp(*argv, "-display", 2)) { |
237 | if (!*++argv) | 237 | if (!*++argv) |
238 | ++error; | 238 | ++error; |
239 | else | 239 | else |
240 | displayname = *argv; | 240 | displayname = *argv; |
241 | } else if (!strncmp(*argv, "-gamma", 2)) { | 241 | } else if (!strncmp(*argv, "-gamma", 2)) { |
242 | if (!*++argv) | 242 | if (!*++argv) |
243 | ++error; | 243 | ++error; |
244 | else { | 244 | else { |
245 | display_exponent = atof(*argv); | 245 | display_exponent = atof(*argv); |
246 | if (display_exponent <= 0.0) | 246 | if (display_exponent <= 0.0) |
247 | ++error; | 247 | ++error; |
248 | } | 248 | } |
249 | } else if (!strncmp(*argv, "-bgcolor", 2)) { | 249 | } else if (!strncmp(*argv, "-bgcolor", 2)) { |
250 | if (!*++argv) | 250 | if (!*++argv) |
251 | ++error; | 251 | ++error; |
252 | else { | 252 | else { |
253 | bgstr = *argv; | 253 | bgstr = *argv; |
254 | if (strlen(bgstr) != 7 || bgstr[0] != '#') | 254 | if (strlen(bgstr) != 7 || bgstr[0] != '#') |
255 | ++error; | 255 | ++error; |
256 | else | 256 | else |
257 | have_bg = TRUE; | 257 | have_bg = TRUE; |
258 | } | 258 | } |
259 | } else { | 259 | } else { |
260 | if (**argv != '-') { | 260 | if (**argv != '-') { |
261 | filename = *argv; | 261 | filename = *argv; |
262 | if (argv[1]) /* shouldn't be any more args after filename */ | 262 | if (argv[1]) /* shouldn't be any more args after filename */ |
263 | ++error; | 263 | ++error; |
264 | } else | 264 | } else |
265 | ++error; /* not expecting any other options */ | 265 | ++error; /* not expecting any other options */ |
266 | } | 266 | } |
267 | } | 267 | } |
268 | 268 | ||
269 | if (!filename) | 269 | if (!filename) |
270 | ++error; | 270 | ++error; |
271 | 271 | ||
272 | 272 | ||
273 | /* print usage screen if any errors up to this point */ | 273 | /* print usage screen if any errors up to this point */ |
274 | 274 | ||
275 | if (error) { | 275 | if (error) { |
276 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); | 276 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); |
277 | readpng_version_info(); | 277 | readpng_version_info(); |
278 | fprintf(stderr, "\n" | 278 | fprintf(stderr, "\n" |
279 | "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\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" | 280 | " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" |
281 | " exp \ttransfer-function exponent (``gamma'') of the display\n" | 281 | " exp \ttransfer-function exponent (``gamma'') of the display\n" |
282 | "\t\t system in floating-point format (e.g., ``%.1f''); equal\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" | 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" | 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" | 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" | 286 | "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" |
287 | "\t\t used with transparent images\n" | 287 | "\t\t used with transparent images\n" |
288 | "\nPress Q, Esc or mouse button 1 (within image window, after image\n" | 288 | "\nPress Q, Esc or mouse button 1 (within image window, after image\n" |
289 | "is displayed) to quit.\n" | 289 | "is displayed) to quit.\n" |
290 | "\n", PROGNAME, default_display_exponent); | 290 | "\n", PROGNAME, default_display_exponent); |
291 | exit(1); | 291 | exit(1); |
292 | } | 292 | } |
293 | 293 | ||
294 | 294 | ||
295 | if (!(infile = fopen(filename, "rb"))) { | 295 | if (!(infile = fopen(filename, "rb"))) { |
296 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); | 296 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); |
297 | ++error; | 297 | ++error; |
298 | } else { | 298 | } else { |
299 | if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { | 299 | if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) { |
300 | switch (rc) { | 300 | switch (rc) { |
301 | case 1: | 301 | case 1: |
302 | fprintf(stderr, PROGNAME | 302 | fprintf(stderr, PROGNAME |
303 | ": [%s] is not a PNG file: incorrect signature\n", | 303 | ": [%s] is not a PNG file: incorrect signature\n", |
304 | filename); | 304 | filename); |
305 | break; | 305 | break; |
306 | case 2: | 306 | case 2: |
307 | fprintf(stderr, PROGNAME | 307 | fprintf(stderr, PROGNAME |
308 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); | 308 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); |
309 | break; | 309 | break; |
310 | case 4: | 310 | case 4: |
311 | fprintf(stderr, PROGNAME ": insufficient memory\n"); | 311 | fprintf(stderr, PROGNAME ": insufficient memory\n"); |
312 | break; | 312 | break; |
313 | default: | 313 | default: |
314 | fprintf(stderr, PROGNAME | 314 | fprintf(stderr, PROGNAME |
315 | ": unknown readpng_init() error\n"); | 315 | ": unknown readpng_init() error\n"); |
316 | break; | 316 | break; |
317 | } | 317 | } |
318 | ++error; | 318 | ++error; |
319 | } else { | 319 | } else { |
320 | display = XOpenDisplay(displayname); | 320 | display = XOpenDisplay(displayname); |
321 | if (!display) { | 321 | if (!display) { |
322 | readpng_cleanup(TRUE); | 322 | readpng_cleanup(TRUE); |
323 | fprintf(stderr, PROGNAME ": can't open X display [%s]\n", | 323 | fprintf(stderr, PROGNAME ": can't open X display [%s]\n", |
324 | displayname? displayname : "default"); | 324 | displayname? displayname : "default"); |
325 | ++error; | 325 | ++error; |
326 | } | 326 | } |
327 | } | 327 | } |
328 | if (error) | 328 | if (error) |
329 | fclose(infile); | 329 | fclose(infile); |
330 | } | 330 | } |
331 | 331 | ||
332 | 332 | ||
333 | if (error) { | 333 | if (error) { |
334 | fprintf(stderr, PROGNAME ": aborting.\n"); | 334 | fprintf(stderr, PROGNAME ": aborting.\n"); |
335 | exit(2); | 335 | exit(2); |
336 | } | 336 | } |
337 | 337 | ||
338 | 338 | ||
339 | /* set the title-bar string, but make sure buffer doesn't overflow */ | 339 | /* set the title-bar string, but make sure buffer doesn't overflow */ |
340 | 340 | ||
341 | alen = strlen(appname); | 341 | alen = strlen(appname); |
342 | flen = strlen(filename); | 342 | flen = strlen(filename); |
343 | if (alen + flen + 3 > 1023) | 343 | if (alen + flen + 3 > 1023) |
344 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); | 344 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); |
345 | else | 345 | else |
346 | sprintf(titlebar, "%s: %s", appname, filename); | 346 | sprintf(titlebar, "%s: %s", appname, filename); |
347 | 347 | ||
348 | 348 | ||
349 | /* if the user didn't specify a background color on the command line, | 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 | 350 | * check for one in the PNG file--if not, the initialized values of 0 |
351 | * (black) will be used */ | 351 | * (black) will be used */ |
352 | 352 | ||
353 | if (have_bg) { | 353 | if (have_bg) { |
354 | unsigned r, g, b; /* this approach quiets compiler warnings */ | 354 | unsigned r, g, b; /* this approach quiets compiler warnings */ |
355 | 355 | ||
356 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); | 356 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); |
357 | bg_red = (uch)r; | 357 | bg_red = (uch)r; |
358 | bg_green = (uch)g; | 358 | bg_green = (uch)g; |
359 | bg_blue = (uch)b; | 359 | bg_blue = (uch)b; |
360 | } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { | 360 | } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) { |
361 | readpng_cleanup(TRUE); | 361 | readpng_cleanup(TRUE); |
362 | fprintf(stderr, PROGNAME | 362 | fprintf(stderr, PROGNAME |
363 | ": libpng error while checking for background color\n"); | 363 | ": libpng error while checking for background color\n"); |
364 | exit(2); | 364 | exit(2); |
365 | } | 365 | } |
366 | 366 | ||
367 | 367 | ||
368 | /* do the basic X initialization stuff, make the window and fill it | 368 | /* do the basic X initialization stuff, make the window and fill it |
369 | * with the background color */ | 369 | * with the background color */ |
370 | 370 | ||
371 | if (rpng_x_create_window()) | 371 | if (rpng_x_create_window()) |
372 | exit(2); | 372 | exit(2); |
373 | 373 | ||
374 | 374 | ||
375 | /* decode the image, all at once */ | 375 | /* decode the image, all at once */ |
376 | 376 | ||
377 | Trace((stderr, "calling readpng_get_image()\n")) | 377 | Trace((stderr, "calling readpng_get_image()\n")) |
378 | image_data = readpng_get_image(display_exponent, &image_channels, | 378 | image_data = readpng_get_image(display_exponent, &image_channels, |
379 | &image_rowbytes); | 379 | &image_rowbytes); |
380 | Trace((stderr, "done with readpng_get_image()\n")) | 380 | Trace((stderr, "done with readpng_get_image()\n")) |
381 | 381 | ||
382 | 382 | ||
383 | /* done with PNG file, so clean up to minimize memory usage (but do NOT | 383 | /* done with PNG file, so clean up to minimize memory usage (but do NOT |
384 | * nuke image_data!) */ | 384 | * nuke image_data!) */ |
385 | 385 | ||
386 | readpng_cleanup(FALSE); | 386 | readpng_cleanup(FALSE); |
387 | fclose(infile); | 387 | fclose(infile); |
388 | 388 | ||
389 | if (!image_data) { | 389 | if (!image_data) { |
390 | fprintf(stderr, PROGNAME ": unable to decode PNG image\n"); | 390 | fprintf(stderr, PROGNAME ": unable to decode PNG image\n"); |
391 | exit(3); | 391 | exit(3); |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | /* display image (composite with background if requested) */ | 395 | /* display image (composite with background if requested) */ |
396 | 396 | ||
397 | Trace((stderr, "calling rpng_x_display_image()\n")) | 397 | Trace((stderr, "calling rpng_x_display_image()\n")) |
398 | if (rpng_x_display_image()) { | 398 | if (rpng_x_display_image()) { |
399 | free(image_data); | 399 | free(image_data); |
400 | exit(4); | 400 | exit(4); |
401 | } | 401 | } |
402 | Trace((stderr, "done with rpng_x_display_image()\n")) | 402 | Trace((stderr, "done with rpng_x_display_image()\n")) |
403 | 403 | ||
404 | 404 | ||
405 | /* wait for the user to tell us when to quit */ | 405 | /* wait for the user to tell us when to quit */ |
406 | 406 | ||
407 | printf( | 407 | printf( |
408 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); | 408 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); |
409 | fflush(stdout); | 409 | fflush(stdout); |
410 | 410 | ||
411 | do | 411 | do |
412 | XNextEvent(display, &e); | 412 | XNextEvent(display, &e); |
413 | while (!(e.type == ButtonPress && e.xbutton.button == Button1) && | 413 | while (!(e.type == ButtonPress && e.xbutton.button == Button1) && |
414 | !(e.type == KeyPress && /* v--- or 1 for shifted keys */ | 414 | !(e.type == KeyPress && /* v--- or 1 for shifted keys */ |
415 | ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) )); | 415 | ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) )); |
416 | 416 | ||
417 | 417 | ||
418 | /* OK, we're done: clean up all image and X resources and go away */ | 418 | /* OK, we're done: clean up all image and X resources and go away */ |
419 | 419 | ||
420 | rpng_x_cleanup(); | 420 | rpng_x_cleanup(); |
421 | 421 | ||
422 | return 0; | 422 | return 0; |
423 | } | 423 | } |
424 | 424 | ||
425 | 425 | ||
426 | 426 | ||
427 | 427 | ||
428 | 428 | ||
429 | static int rpng_x_create_window(void) | 429 | static int rpng_x_create_window(void) |
430 | { | 430 | { |
431 | uch *xdata; | 431 | uch *xdata; |
432 | int need_colormap = FALSE; | 432 | int need_colormap = FALSE; |
433 | int screen, pad; | 433 | int screen, pad; |
434 | ulg bg_pixel = 0L; | 434 | ulg bg_pixel = 0L; |
435 | ulg attrmask; | 435 | ulg attrmask; |
436 | Window root; | 436 | Window root; |
437 | XEvent e; | 437 | XEvent e; |
438 | XGCValues gcvalues; | 438 | XGCValues gcvalues; |
439 | XSetWindowAttributes attr; | 439 | XSetWindowAttributes attr; |
440 | XTextProperty windowName, *pWindowName = &windowName; | 440 | XTextProperty windowName, *pWindowName = &windowName; |
441 | XTextProperty iconName, *pIconName = &iconName; | 441 | XTextProperty iconName, *pIconName = &iconName; |
442 | XVisualInfo visual_info; | 442 | XVisualInfo visual_info; |
443 | XSizeHints *size_hints; | 443 | XSizeHints *size_hints; |
444 | XWMHints *wm_hints; | 444 | XWMHints *wm_hints; |
445 | XClassHint *class_hints; | 445 | XClassHint *class_hints; |
446 | 446 | ||
447 | 447 | ||
448 | screen = DefaultScreen(display); | 448 | screen = DefaultScreen(display); |
449 | depth = DisplayPlanes(display, screen); | 449 | depth = DisplayPlanes(display, screen); |
450 | root = RootWindow(display, screen); | 450 | root = RootWindow(display, screen); |
451 | 451 | ||
452 | #ifdef DEBUG | 452 | #ifdef DEBUG |
453 | XSynchronize(display, True); | 453 | XSynchronize(display, True); |
454 | #endif | 454 | #endif |
455 | 455 | ||
456 | #if 0 | 456 | #if 0 |
457 | /* GRR: add 8-bit support */ | 457 | /* GRR: add 8-bit support */ |
458 | if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) { | 458 | if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) { |
459 | fprintf(stderr, | 459 | fprintf(stderr, |
460 | "screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n", | 460 | "screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\n", |
461 | depth); | 461 | depth); |
462 | return 2; | 462 | return 2; |
463 | } | 463 | } |
464 | 464 | ||
465 | XMatchVisualInfo(display, screen, depth, | 465 | XMatchVisualInfo(display, screen, depth, |
466 | (depth == 8)? PseudoColor : TrueColor, &visual_info); | 466 | (depth == 8)? PseudoColor : TrueColor, &visual_info); |
467 | visual = visual_info.visual; | 467 | visual = visual_info.visual; |
468 | #else | 468 | #else |
469 | if (depth != 16 && depth != 24 && depth != 32) { | 469 | if (depth != 16 && depth != 24 && depth != 32) { |
470 | int visuals_matched = 0; | 470 | int visuals_matched = 0; |
471 | 471 | ||
472 | Trace((stderr, "default depth is %d: checking other visuals\n", | 472 | Trace((stderr, "default depth is %d: checking other visuals\n", |
473 | depth)) | 473 | depth)) |
474 | 474 | ||
475 | /* 24-bit first */ | 475 | /* 24-bit first */ |
476 | visual_info.screen = screen; | 476 | visual_info.screen = screen; |
477 | visual_info.depth = 24; | 477 | visual_info.depth = 24; |
478 | visual_list = XGetVisualInfo(display, | 478 | visual_list = XGetVisualInfo(display, |
479 | VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched); | 479 | VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched); |
480 | if (visuals_matched == 0) { | 480 | if (visuals_matched == 0) { |
481 | /* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */ | 481 | /* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */ |
482 | fprintf(stderr, "default screen depth %d not supported, and no" | 482 | fprintf(stderr, "default screen depth %d not supported, and no" |
483 | " 24-bit visuals found\n", depth); | 483 | " 24-bit visuals found\n", depth); |
484 | return 2; | 484 | return 2; |
485 | } | 485 | } |
486 | Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n", | 486 | Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n", |
487 | visuals_matched)) | 487 | visuals_matched)) |
488 | visual = visual_list[0].visual; | 488 | visual = visual_list[0].visual; |
489 | depth = visual_list[0].depth; | 489 | depth = visual_list[0].depth; |
490 | /* | 490 | /* |
491 | colormap_size = visual_list[0].colormap_size; | 491 | colormap_size = visual_list[0].colormap_size; |
492 | visual_class = visual->class; | 492 | visual_class = visual->class; |
493 | visualID = XVisualIDFromVisual(visual); | 493 | visualID = XVisualIDFromVisual(visual); |
494 | */ | 494 | */ |
495 | have_nondefault_visual = TRUE; | 495 | have_nondefault_visual = TRUE; |
496 | need_colormap = TRUE; | 496 | need_colormap = TRUE; |
497 | } else { | 497 | } else { |
498 | XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info); | 498 | XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info); |
499 | visual = visual_info.visual; | 499 | visual = visual_info.visual; |
500 | } | 500 | } |
501 | #endif | 501 | #endif |
502 | 502 | ||
503 | RMask = visual->red_mask; | 503 | RMask = visual->red_mask; |
504 | GMask = visual->green_mask; | 504 | GMask = visual->green_mask; |
505 | BMask = visual->blue_mask; | 505 | BMask = visual->blue_mask; |
506 | 506 | ||
507 | /* GRR: add/check 8-bit support */ | 507 | /* GRR: add/check 8-bit support */ |
508 | if (depth == 8 || need_colormap) { | 508 | if (depth == 8 || need_colormap) { |
509 | colormap = XCreateColormap(display, root, visual, AllocNone); | 509 | colormap = XCreateColormap(display, root, visual, AllocNone); |
510 | if (!colormap) { | 510 | if (!colormap) { |
511 | fprintf(stderr, "XCreateColormap() failed\n"); | 511 | fprintf(stderr, "XCreateColormap() failed\n"); |
512 | return 2; | 512 | return 2; |
513 | } | 513 | } |
514 | have_colormap = TRUE; | 514 | have_colormap = TRUE; |
515 | } | 515 | } |
516 | if (depth == 15 || depth == 16) { | 516 | if (depth == 15 || depth == 16) { |
517 | RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */ | 517 | RShift = 15 - rpng_x_msb(RMask); /* these are right-shifts */ |
518 | GShift = 15 - rpng_x_msb(GMask); | 518 | GShift = 15 - rpng_x_msb(GMask); |
519 | BShift = 15 - rpng_x_msb(BMask); | 519 | BShift = 15 - rpng_x_msb(BMask); |
520 | } else if (depth > 16) { | 520 | } else if (depth > 16) { |
521 | #define NO_24BIT_MASKS | 521 | #define NO_24BIT_MASKS |
522 | #ifdef NO_24BIT_MASKS | 522 | #ifdef NO_24BIT_MASKS |
523 | RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */ | 523 | RShift = rpng_x_msb(RMask) - 7; /* these are left-shifts */ |
524 | GShift = rpng_x_msb(GMask) - 7; | 524 | GShift = rpng_x_msb(GMask) - 7; |
525 | BShift = rpng_x_msb(BMask) - 7; | 525 | BShift = rpng_x_msb(BMask) - 7; |
526 | #else | 526 | #else |
527 | RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */ | 527 | RShift = 7 - rpng_x_msb(RMask); /* these are right-shifts, too */ |
528 | GShift = 7 - rpng_x_msb(GMask); | 528 | GShift = 7 - rpng_x_msb(GMask); |
529 | BShift = 7 - rpng_x_msb(BMask); | 529 | BShift = 7 - rpng_x_msb(BMask); |
530 | #endif | 530 | #endif |
531 | } | 531 | } |
532 | if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) { | 532 | if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) { |
533 | fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n"); | 533 | fprintf(stderr, "rpng internal logic error: negative X shift(s)!\n"); |
534 | return 2; | 534 | return 2; |
535 | } | 535 | } |
536 | 536 | ||
537 | /*--------------------------------------------------------------------------- | 537 | /*--------------------------------------------------------------------------- |
538 | Finally, create the window. | 538 | Finally, create the window. |
539 | ---------------------------------------------------------------------------*/ | 539 | ---------------------------------------------------------------------------*/ |
540 | 540 | ||
541 | attr.backing_store = Always; | 541 | attr.backing_store = Always; |
542 | attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; | 542 | attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; |
543 | attrmask = CWBackingStore | CWEventMask; | 543 | attrmask = CWBackingStore | CWEventMask; |
544 | if (have_nondefault_visual) { | 544 | if (have_nondefault_visual) { |
545 | attr.colormap = colormap; | 545 | attr.colormap = colormap; |
546 | attr.background_pixel = 0; | 546 | attr.background_pixel = 0; |
547 | attr.border_pixel = 1; | 547 | attr.border_pixel = 1; |
548 | attrmask |= CWColormap | CWBackPixel | CWBorderPixel; | 548 | attrmask |= CWColormap | CWBackPixel | CWBorderPixel; |
549 | } | 549 | } |
550 | 550 | ||
551 | window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0, | 551 | window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0, |
552 | depth, InputOutput, visual, attrmask, &attr); | 552 | depth, InputOutput, visual, attrmask, &attr); |
553 | 553 | ||
554 | if (window == None) { | 554 | if (window == None) { |
555 | fprintf(stderr, "XCreateWindow() failed\n"); | 555 | fprintf(stderr, "XCreateWindow() failed\n"); |
556 | return 2; | 556 | return 2; |
557 | } else | 557 | } else |
558 | have_window = TRUE; | 558 | have_window = TRUE; |
559 | 559 | ||
560 | if (depth == 8) | 560 | if (depth == 8) |
561 | XSetWindowColormap(display, window, colormap); | 561 | XSetWindowColormap(display, window, colormap); |
562 | 562 | ||
563 | if (!XStringListToTextProperty(&window_name, 1, pWindowName)) | 563 | if (!XStringListToTextProperty(&window_name, 1, pWindowName)) |
564 | pWindowName = NULL; | 564 | pWindowName = NULL; |
565 | if (!XStringListToTextProperty(&icon_name, 1, pIconName)) | 565 | if (!XStringListToTextProperty(&icon_name, 1, pIconName)) |
566 | pIconName = NULL; | 566 | pIconName = NULL; |
567 | 567 | ||
568 | /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */ | 568 | /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */ |
569 | 569 | ||
570 | if ((size_hints = XAllocSizeHints()) != NULL) { | 570 | if ((size_hints = XAllocSizeHints()) != NULL) { |
571 | /* window will not be resizable */ | 571 | /* window will not be resizable */ |
572 | size_hints->flags = PMinSize | PMaxSize; | 572 | size_hints->flags = PMinSize | PMaxSize; |
573 | size_hints->min_width = size_hints->max_width = (int)image_width; | 573 | size_hints->min_width = size_hints->max_width = (int)image_width; |
574 | size_hints->min_height = size_hints->max_height = (int)image_height; | 574 | size_hints->min_height = size_hints->max_height = (int)image_height; |
575 | } | 575 | } |
576 | 576 | ||
577 | if ((wm_hints = XAllocWMHints()) != NULL) { | 577 | if ((wm_hints = XAllocWMHints()) != NULL) { |
578 | wm_hints->initial_state = NormalState; | 578 | wm_hints->initial_state = NormalState; |
579 | wm_hints->input = True; | 579 | wm_hints->input = True; |
580 | /* wm_hints->icon_pixmap = icon_pixmap; */ | 580 | /* wm_hints->icon_pixmap = icon_pixmap; */ |
581 | wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; | 581 | wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; |
582 | } | 582 | } |
583 | 583 | ||
584 | if ((class_hints = XAllocClassHint()) != NULL) { | 584 | if ((class_hints = XAllocClassHint()) != NULL) { |
585 | class_hints->res_name = res_name; | 585 | class_hints->res_name = res_name; |
586 | class_hints->res_class = res_class; | 586 | class_hints->res_class = res_class; |
587 | } | 587 | } |
588 | 588 | ||
589 | XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, | 589 | XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, |
590 | size_hints, wm_hints, class_hints); | 590 | size_hints, wm_hints, class_hints); |
591 | 591 | ||
592 | /* various properties and hints no longer needed; free memory */ | 592 | /* various properties and hints no longer needed; free memory */ |
593 | if (pWindowName) | 593 | if (pWindowName) |
594 | XFree(pWindowName->value); | 594 | XFree(pWindowName->value); |
595 | if (pIconName) | 595 | if (pIconName) |
596 | XFree(pIconName->value); | 596 | XFree(pIconName->value); |
597 | if (size_hints) | 597 | if (size_hints) |
598 | XFree(size_hints); | 598 | XFree(size_hints); |
599 | if (wm_hints) | 599 | if (wm_hints) |
600 | XFree(wm_hints); | 600 | XFree(wm_hints); |
601 | if (class_hints) | 601 | if (class_hints) |
602 | XFree(class_hints); | 602 | XFree(class_hints); |
603 | 603 | ||
604 | XMapWindow(display, window); | 604 | XMapWindow(display, window); |
605 | 605 | ||
606 | gc = XCreateGC(display, window, 0, &gcvalues); | 606 | gc = XCreateGC(display, window, 0, &gcvalues); |
607 | have_gc = TRUE; | 607 | have_gc = TRUE; |
608 | 608 | ||
609 | /*--------------------------------------------------------------------------- | 609 | /*--------------------------------------------------------------------------- |
610 | Fill window with the specified background color. | 610 | Fill window with the specified background color. |
611 | ---------------------------------------------------------------------------*/ | 611 | ---------------------------------------------------------------------------*/ |
612 | 612 | ||
613 | if (depth == 24 || depth == 32) { | 613 | if (depth == 24 || depth == 32) { |
614 | bg_pixel = ((ulg)bg_red << RShift) | | 614 | bg_pixel = ((ulg)bg_red << RShift) | |
615 | ((ulg)bg_green << GShift) | | 615 | ((ulg)bg_green << GShift) | |
616 | ((ulg)bg_blue << BShift); | 616 | ((ulg)bg_blue << BShift); |
617 | } else if (depth == 16) { | 617 | } else if (depth == 16) { |
618 | bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) | | 618 | bg_pixel = ((((ulg)bg_red << 8) >> RShift) & RMask) | |
619 | ((((ulg)bg_green << 8) >> GShift) & GMask) | | 619 | ((((ulg)bg_green << 8) >> GShift) & GMask) | |
620 | ((((ulg)bg_blue << 8) >> BShift) & BMask); | 620 | ((((ulg)bg_blue << 8) >> BShift) & BMask); |
621 | } else /* depth == 8 */ { | 621 | } else /* depth == 8 */ { |
622 | 622 | ||
623 | /* GRR: add 8-bit support */ | 623 | /* GRR: add 8-bit support */ |
624 | 624 | ||
625 | } | 625 | } |
626 | 626 | ||
627 | XSetForeground(display, gc, bg_pixel); | 627 | XSetForeground(display, gc, bg_pixel); |
628 | XFillRectangle(display, window, gc, 0, 0, image_width, image_height); | 628 | XFillRectangle(display, window, gc, 0, 0, image_width, image_height); |
629 | 629 | ||
630 | /*--------------------------------------------------------------------------- | 630 | /*--------------------------------------------------------------------------- |
631 | Wait for first Expose event to do any drawing, then flush. | 631 | Wait for first Expose event to do any drawing, then flush. |
632 | ---------------------------------------------------------------------------*/ | 632 | ---------------------------------------------------------------------------*/ |
633 | 633 | ||
634 | do | 634 | do |
635 | XNextEvent(display, &e); | 635 | XNextEvent(display, &e); |
636 | while (e.type != Expose || e.xexpose.count); | 636 | while (e.type != Expose || e.xexpose.count); |
637 | 637 | ||
638 | XFlush(display); | 638 | XFlush(display); |
639 | 639 | ||
640 | /*--------------------------------------------------------------------------- | 640 | /*--------------------------------------------------------------------------- |
641 | Allocate memory for the X- and display-specific version of the image. | 641 | Allocate memory for the X- and display-specific version of the image. |
642 | ---------------------------------------------------------------------------*/ | 642 | ---------------------------------------------------------------------------*/ |
643 | 643 | ||
644 | if (depth == 24 || depth == 32) { | 644 | if (depth == 24 || depth == 32) { |
645 | xdata = (uch *)malloc(4*image_width*image_height); | 645 | xdata = (uch *)malloc(4*image_width*image_height); |
646 | pad = 32; | 646 | pad = 32; |
647 | } else if (depth == 16) { | 647 | } else if (depth == 16) { |
648 | xdata = (uch *)malloc(2*image_width*image_height); | 648 | xdata = (uch *)malloc(2*image_width*image_height); |
649 | pad = 16; | 649 | pad = 16; |
650 | } else /* depth == 8 */ { | 650 | } else /* depth == 8 */ { |
651 | xdata = (uch *)malloc(image_width*image_height); | 651 | xdata = (uch *)malloc(image_width*image_height); |
652 | pad = 8; | 652 | pad = 8; |
653 | } | 653 | } |
654 | 654 | ||
655 | if (!xdata) { | 655 | if (!xdata) { |
656 | fprintf(stderr, PROGNAME ": unable to allocate image memory\n"); | 656 | fprintf(stderr, PROGNAME ": unable to allocate image memory\n"); |
657 | return 4; | 657 | return 4; |
658 | } | 658 | } |
659 | 659 | ||
660 | ximage = XCreateImage(display, visual, depth, ZPixmap, 0, | 660 | ximage = XCreateImage(display, visual, depth, ZPixmap, 0, |
661 | (char *)xdata, image_width, image_height, pad, 0); | 661 | (char *)xdata, image_width, image_height, pad, 0); |
662 | 662 | ||
663 | if (!ximage) { | 663 | if (!ximage) { |
664 | fprintf(stderr, PROGNAME ": XCreateImage() failed\n"); | 664 | fprintf(stderr, PROGNAME ": XCreateImage() failed\n"); |
665 | free(xdata); | 665 | free(xdata); |
666 | return 3; | 666 | return 3; |
667 | } | 667 | } |
668 | 668 | ||
669 | /* to avoid testing the byte order every pixel (or doubling the size of | 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 | 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- | 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 | 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 | 673 | * efficient approach (the giant if-test would be better), but in the |
674 | * interest of clarity, we take the easy way out... */ | 674 | * interest of clarity, we take the easy way out... */ |
675 | 675 | ||
676 | ximage->byte_order = MSBFirst; | 676 | ximage->byte_order = MSBFirst; |
677 | 677 | ||
678 | return 0; | 678 | return 0; |
679 | 679 | ||
680 | } /* end function rpng_x_create_window() */ | 680 | } /* end function rpng_x_create_window() */ |
681 | 681 | ||
682 | 682 | ||
683 | 683 | ||
684 | 684 | ||
685 | 685 | ||
686 | static int rpng_x_display_image(void) | 686 | static int rpng_x_display_image(void) |
687 | { | 687 | { |
688 | uch *src; | 688 | uch *src; |
689 | char *dest; | 689 | char *dest; |
690 | uch r, g, b, a; | 690 | uch r, g, b, a; |
691 | ulg i, row, lastrow = 0; | 691 | ulg i, row, lastrow = 0; |
692 | ulg pixel; | 692 | ulg pixel; |
693 | int ximage_rowbytes = ximage->bytes_per_line; | 693 | int ximage_rowbytes = ximage->bytes_per_line; |
694 | /* int bpp = ximage->bits_per_pixel; */ | 694 | /* int bpp = ximage->bits_per_pixel; */ |
695 | 695 | ||
696 | 696 | ||
697 | Trace((stderr, "beginning display loop (image_channels == %d)\n", | 697 | Trace((stderr, "beginning display loop (image_channels == %d)\n", |
698 | image_channels)) | 698 | image_channels)) |
699 | Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n", | 699 | Trace((stderr, " (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\n", |
700 | image_width, image_rowbytes, ximage_rowbytes)) | 700 | image_width, image_rowbytes, ximage_rowbytes)) |
701 | Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) | 701 | Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) |
702 | Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? | 702 | Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? |
703 | "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) | 703 | "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) |
704 | 704 | ||
705 | if (depth == 24 || depth == 32) { | 705 | if (depth == 24 || depth == 32) { |
706 | ulg red, green, blue; | 706 | ulg red, green, blue; |
707 | 707 | ||
708 | for (lastrow = row = 0; row < image_height; ++row) { | 708 | for (lastrow = row = 0; row < image_height; ++row) { |
709 | src = image_data + row*image_rowbytes; | 709 | src = image_data + row*image_rowbytes; |
710 | dest = ximage->data + row*ximage_rowbytes; | 710 | dest = ximage->data + row*ximage_rowbytes; |
711 | if (image_channels == 3) { | 711 | if (image_channels == 3) { |
712 | for (i = image_width; i > 0; --i) { | 712 | for (i = image_width; i > 0; --i) { |
713 | red = *src++; | 713 | red = *src++; |
714 | green = *src++; | 714 | green = *src++; |
715 | blue = *src++; | 715 | blue = *src++; |
716 | #ifdef NO_24BIT_MASKS | 716 | #ifdef NO_24BIT_MASKS |
717 | pixel = (red << RShift) | | 717 | pixel = (red << RShift) | |
718 | (green << GShift) | | 718 | (green << GShift) | |
719 | (blue << BShift); | 719 | (blue << BShift); |
720 | /* recall that we set ximage->byte_order = MSBFirst above */ | 720 | /* recall that we set ximage->byte_order = MSBFirst above */ |
721 | /* GRR BUG: this assumes bpp == 32, but may be 24: */ | 721 | /* GRR BUG: this assumes bpp == 32, but may be 24: */ |
722 | *dest++ = (char)((pixel >> 24) & 0xff); | 722 | *dest++ = (char)((pixel >> 24) & 0xff); |
723 | *dest++ = (char)((pixel >> 16) & 0xff); | 723 | *dest++ = (char)((pixel >> 16) & 0xff); |
724 | *dest++ = (char)((pixel >> 8) & 0xff); | 724 | *dest++ = (char)((pixel >> 8) & 0xff); |
725 | *dest++ = (char)( pixel & 0xff); | 725 | *dest++ = (char)( pixel & 0xff); |
726 | #else | 726 | #else |
727 | red = (RShift < 0)? red << (-RShift) : red >> RShift; | 727 | red = (RShift < 0)? red << (-RShift) : red >> RShift; |
728 | green = (GShift < 0)? green << (-GShift) : green >> GShift; | 728 | green = (GShift < 0)? green << (-GShift) : green >> GShift; |
729 | blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; | 729 | blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; |
730 | pixel = (red & RMask) | (green & GMask) | (blue & BMask); | 730 | pixel = (red & RMask) | (green & GMask) | (blue & BMask); |
731 | /* recall that we set ximage->byte_order = MSBFirst above */ | 731 | /* recall that we set ximage->byte_order = MSBFirst above */ |
732 | *dest++ = (char)((pixel >> 24) & 0xff); | 732 | *dest++ = (char)((pixel >> 24) & 0xff); |
733 | *dest++ = (char)((pixel >> 16) & 0xff); | 733 | *dest++ = (char)((pixel >> 16) & 0xff); |
734 | *dest++ = (char)((pixel >> 8) & 0xff); | 734 | *dest++ = (char)((pixel >> 8) & 0xff); |
735 | *dest++ = (char)( pixel & 0xff); | 735 | *dest++ = (char)( pixel & 0xff); |
736 | #endif | 736 | #endif |
737 | } | 737 | } |
738 | } else /* if (image_channels == 4) */ { | 738 | } else /* if (image_channels == 4) */ { |
739 | for (i = image_width; i > 0; --i) { | 739 | for (i = image_width; i > 0; --i) { |
740 | r = *src++; | 740 | r = *src++; |
741 | g = *src++; | 741 | g = *src++; |
742 | b = *src++; | 742 | b = *src++; |
743 | a = *src++; | 743 | a = *src++; |
744 | if (a == 255) { | 744 | if (a == 255) { |
745 | red = r; | 745 | red = r; |
746 | green = g; | 746 | green = g; |
747 | blue = b; | 747 | blue = b; |
748 | } else if (a == 0) { | 748 | } else if (a == 0) { |
749 | red = bg_red; | 749 | red = bg_red; |
750 | green = bg_green; | 750 | green = bg_green; |
751 | blue = bg_blue; | 751 | blue = bg_blue; |
752 | } else { | 752 | } else { |
753 | /* this macro (from png.h) composites the foreground | 753 | /* this macro (from png.h) composites the foreground |
754 | * and background values and puts the result into the | 754 | * and background values and puts the result into the |
755 | * first argument */ | 755 | * first argument */ |
756 | alpha_composite(red, r, a, bg_red); | 756 | alpha_composite(red, r, a, bg_red); |
757 | alpha_composite(green, g, a, bg_green); | 757 | alpha_composite(green, g, a, bg_green); |
758 | alpha_composite(blue, b, a, bg_blue); | 758 | alpha_composite(blue, b, a, bg_blue); |
759 | } | 759 | } |
760 | pixel = (red << RShift) | | 760 | pixel = (red << RShift) | |
761 | (green << GShift) | | 761 | (green << GShift) | |
762 | (blue << BShift); | 762 | (blue << BShift); |
763 | /* recall that we set ximage->byte_order = MSBFirst above */ | 763 | /* recall that we set ximage->byte_order = MSBFirst above */ |
764 | *dest++ = (char)((pixel >> 24) & 0xff); | 764 | *dest++ = (char)((pixel >> 24) & 0xff); |
765 | *dest++ = (char)((pixel >> 16) & 0xff); | 765 | *dest++ = (char)((pixel >> 16) & 0xff); |
766 | *dest++ = (char)((pixel >> 8) & 0xff); | 766 | *dest++ = (char)((pixel >> 8) & 0xff); |
767 | *dest++ = (char)( pixel & 0xff); | 767 | *dest++ = (char)( pixel & 0xff); |
768 | } | 768 | } |
769 | } | 769 | } |
770 | /* display after every 16 lines */ | 770 | /* display after every 16 lines */ |
771 | if (((row+1) & 0xf) == 0) { | 771 | if (((row+1) & 0xf) == 0) { |
772 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, | 772 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, |
773 | (int)lastrow, image_width, 16); | 773 | (int)lastrow, image_width, 16); |
774 | XFlush(display); | 774 | XFlush(display); |
775 | lastrow = row + 1; | 775 | lastrow = row + 1; |
776 | } | 776 | } |
777 | } | 777 | } |
778 | 778 | ||
779 | } else if (depth == 16) { | 779 | } else if (depth == 16) { |
780 | ush red, green, blue; | 780 | ush red, green, blue; |
781 | 781 | ||
782 | for (lastrow = row = 0; row < image_height; ++row) { | 782 | for (lastrow = row = 0; row < image_height; ++row) { |
783 | src = image_data + row*image_rowbytes; | 783 | src = image_data + row*image_rowbytes; |
784 | dest = ximage->data + row*ximage_rowbytes; | 784 | dest = ximage->data + row*ximage_rowbytes; |
785 | if (image_channels == 3) { | 785 | if (image_channels == 3) { |
786 | for (i = image_width; i > 0; --i) { | 786 | for (i = image_width; i > 0; --i) { |
787 | red = ((ush)(*src) << 8); | 787 | red = ((ush)(*src) << 8); |
788 | ++src; | 788 | ++src; |
789 | green = ((ush)(*src) << 8); | 789 | green = ((ush)(*src) << 8); |
790 | ++src; | 790 | ++src; |
791 | blue = ((ush)(*src) << 8); | 791 | blue = ((ush)(*src) << 8); |
792 | ++src; | 792 | ++src; |
793 | pixel = ((red >> RShift) & RMask) | | 793 | pixel = ((red >> RShift) & RMask) | |
794 | ((green >> GShift) & GMask) | | 794 | ((green >> GShift) & GMask) | |
795 | ((blue >> BShift) & BMask); | 795 | ((blue >> BShift) & BMask); |
796 | /* recall that we set ximage->byte_order = MSBFirst above */ | 796 | /* recall that we set ximage->byte_order = MSBFirst above */ |
797 | *dest++ = (char)((pixel >> 8) & 0xff); | 797 | *dest++ = (char)((pixel >> 8) & 0xff); |
798 | *dest++ = (char)( pixel & 0xff); | 798 | *dest++ = (char)( pixel & 0xff); |
799 | } | 799 | } |
800 | } else /* if (image_channels == 4) */ { | 800 | } else /* if (image_channels == 4) */ { |
801 | for (i = image_width; i > 0; --i) { | 801 | for (i = image_width; i > 0; --i) { |
802 | r = *src++; | 802 | r = *src++; |
803 | g = *src++; | 803 | g = *src++; |
804 | b = *src++; | 804 | b = *src++; |
805 | a = *src++; | 805 | a = *src++; |
806 | if (a == 255) { | 806 | if (a == 255) { |
807 | red = ((ush)r << 8); | 807 | red = ((ush)r << 8); |
808 | green = ((ush)g << 8); | 808 | green = ((ush)g << 8); |
809 | blue = ((ush)b << 8); | 809 | blue = ((ush)b << 8); |
810 | } else if (a == 0) { | 810 | } else if (a == 0) { |
811 | red = ((ush)bg_red << 8); | 811 | red = ((ush)bg_red << 8); |
812 | green = ((ush)bg_green << 8); | 812 | green = ((ush)bg_green << 8); |
813 | blue = ((ush)bg_blue << 8); | 813 | blue = ((ush)bg_blue << 8); |
814 | } else { | 814 | } else { |
815 | /* this macro (from png.h) composites the foreground | 815 | /* this macro (from png.h) composites the foreground |
816 | * and background values and puts the result back into | 816 | * and background values and puts the result back into |
817 | * the first argument (== fg byte here: safe) */ | 817 | * the first argument (== fg byte here: safe) */ |
818 | alpha_composite(r, r, a, bg_red); | 818 | alpha_composite(r, r, a, bg_red); |
819 | alpha_composite(g, g, a, bg_green); | 819 | alpha_composite(g, g, a, bg_green); |
820 | alpha_composite(b, b, a, bg_blue); | 820 | alpha_composite(b, b, a, bg_blue); |
821 | red = ((ush)r << 8); | 821 | red = ((ush)r << 8); |
822 | green = ((ush)g << 8); | 822 | green = ((ush)g << 8); |
823 | blue = ((ush)b << 8); | 823 | blue = ((ush)b << 8); |
824 | } | 824 | } |
825 | pixel = ((red >> RShift) & RMask) | | 825 | pixel = ((red >> RShift) & RMask) | |
826 | ((green >> GShift) & GMask) | | 826 | ((green >> GShift) & GMask) | |
827 | ((blue >> BShift) & BMask); | 827 | ((blue >> BShift) & BMask); |
828 | /* recall that we set ximage->byte_order = MSBFirst above */ | 828 | /* recall that we set ximage->byte_order = MSBFirst above */ |
829 | *dest++ = (char)((pixel >> 8) & 0xff); | 829 | *dest++ = (char)((pixel >> 8) & 0xff); |
830 | *dest++ = (char)( pixel & 0xff); | 830 | *dest++ = (char)( pixel & 0xff); |
831 | } | 831 | } |
832 | } | 832 | } |
833 | /* display after every 16 lines */ | 833 | /* display after every 16 lines */ |
834 | if (((row+1) & 0xf) == 0) { | 834 | if (((row+1) & 0xf) == 0) { |
835 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, | 835 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, |
836 | (int)lastrow, image_width, 16); | 836 | (int)lastrow, image_width, 16); |
837 | XFlush(display); | 837 | XFlush(display); |
838 | lastrow = row + 1; | 838 | lastrow = row + 1; |
839 | } | 839 | } |
840 | } | 840 | } |
841 | 841 | ||
842 | } else /* depth == 8 */ { | 842 | } else /* depth == 8 */ { |
843 | 843 | ||
844 | /* GRR: add 8-bit support */ | 844 | /* GRR: add 8-bit support */ |
845 | 845 | ||
846 | } | 846 | } |
847 | 847 | ||
848 | Trace((stderr, "calling final XPutImage()\n")) | 848 | Trace((stderr, "calling final XPutImage()\n")) |
849 | if (lastrow < image_height) { | 849 | if (lastrow < image_height) { |
850 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, | 850 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, |
851 | (int)lastrow, image_width, image_height-lastrow); | 851 | (int)lastrow, image_width, image_height-lastrow); |
852 | XFlush(display); | 852 | XFlush(display); |
853 | } | 853 | } |
854 | 854 | ||
855 | return 0; | 855 | return 0; |
856 | } | 856 | } |
857 | 857 | ||
858 | 858 | ||
859 | 859 | ||
860 | 860 | ||
861 | static void rpng_x_cleanup(void) | 861 | static void rpng_x_cleanup(void) |
862 | { | 862 | { |
863 | if (image_data) { | 863 | if (image_data) { |
864 | free(image_data); | 864 | free(image_data); |
865 | image_data = NULL; | 865 | image_data = NULL; |
866 | } | 866 | } |
867 | 867 | ||
868 | if (ximage) { | 868 | if (ximage) { |
869 | if (ximage->data) { | 869 | if (ximage->data) { |
870 | free(ximage->data); /* we allocated it, so we free it */ | 870 | free(ximage->data); /* we allocated it, so we free it */ |
871 | ximage->data = (char *)NULL; /* instead of XDestroyImage() */ | 871 | ximage->data = (char *)NULL; /* instead of XDestroyImage() */ |
872 | } | 872 | } |
873 | XDestroyImage(ximage); | 873 | XDestroyImage(ximage); |
874 | ximage = NULL; | 874 | ximage = NULL; |
875 | } | 875 | } |
876 | 876 | ||
877 | if (have_gc) | 877 | if (have_gc) |
878 | XFreeGC(display, gc); | 878 | XFreeGC(display, gc); |
879 | 879 | ||
880 | if (have_window) | 880 | if (have_window) |
881 | XDestroyWindow(display, window); | 881 | XDestroyWindow(display, window); |
882 | 882 | ||
883 | if (have_colormap) | 883 | if (have_colormap) |
884 | XFreeColormap(display, colormap); | 884 | XFreeColormap(display, colormap); |
885 | 885 | ||
886 | if (have_nondefault_visual) | 886 | if (have_nondefault_visual) |
887 | XFree(visual_list); | 887 | XFree(visual_list); |
888 | } | 888 | } |
889 | 889 | ||
890 | 890 | ||
891 | 891 | ||
892 | 892 | ||
893 | 893 | ||
894 | static int rpng_x_msb(ulg u32val) | 894 | static int rpng_x_msb(ulg u32val) |
895 | { | 895 | { |
896 | int i; | 896 | int i; |
897 | 897 | ||
898 | for (i = 31; i >= 0; --i) { | 898 | for (i = 31; i >= 0; --i) { |
899 | if (u32val & 0x80000000L) | 899 | if (u32val & 0x80000000L) |
900 | break; | 900 | break; |
901 | u32val <<= 1; | 901 | u32val <<= 1; |
902 | } | 902 | } |
903 | return i; | 903 | return i; |
904 | } | 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 index 2303b58..223e737 100644 --- 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 | |||
@@ -1,1253 +1,1253 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng2 - progressive-model PNG display program rpng2-win.c | 3 | rpng2 - progressive-model PNG display program rpng2-win.c |
4 | 4 | ||
5 | This program decodes and displays PNG files progressively, as if it were | 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). | 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- | 7 | It supports gamma correction, user-specified background colors, and user- |
8 | specified background patterns (for transparent images). This version is | 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 | 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 | 10 | tweaking (or maybe not). Thanks to Adam Costello and Pieter S. van der |
11 | Meulen for the "diamond" and "radial waves" patterns, respectively. | 11 | Meulen for the "diamond" and "radial waves" patterns, respectively. |
12 | 12 | ||
13 | to do (someday, maybe): | 13 | to do (someday, maybe): |
14 | - handle quoted command-line args (especially filenames with spaces) | 14 | - handle quoted command-line args (especially filenames with spaces) |
15 | - finish resizable checkerboard-gradient (sizes 4-128?) | 15 | - finish resizable checkerboard-gradient (sizes 4-128?) |
16 | - use %.1023s to simplify truncation of title-bar string? | 16 | - use %.1023s to simplify truncation of title-bar string? |
17 | - have minimum window width: oh well | 17 | - have minimum window width: oh well |
18 | 18 | ||
19 | --------------------------------------------------------------------------- | 19 | --------------------------------------------------------------------------- |
20 | 20 | ||
21 | Changelog: | 21 | Changelog: |
22 | - 1.01: initial public release | 22 | - 1.01: initial public release |
23 | - 1.02: fixed cut-and-paste error in usage screen (oops...) | 23 | - 1.02: fixed cut-and-paste error in usage screen (oops...) |
24 | - 1.03: modified to allow abbreviated options | 24 | - 1.03: modified to allow abbreviated options |
25 | - 1.04: removed bogus extra argument from usage fprintf() [Glenn R-P?]; | 25 | - 1.04: removed bogus extra argument from usage fprintf() [Glenn R-P?]; |
26 | fixed command-line parsing bug | 26 | fixed command-line parsing bug |
27 | - 1.10: enabled "message window"/console (thanks to David Geldreich) | 27 | - 1.10: enabled "message window"/console (thanks to David Geldreich) |
28 | - 1.20: added runtime MMX-enabling/disabling and new -mmx* options | 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 | 29 | - 1.21: made minor tweak to usage screen to fit within 25-line console |
30 | - 1.22: added AMD64/EM64T support (__x86_64__) | 30 | - 1.22: added AMD64/EM64T support (__x86_64__) |
31 | - 2.00: dual-licensed (added GNU GPL) | 31 | - 2.00: dual-licensed (added GNU GPL) |
32 | - 2.01: fixed 64-bit typo in readpng2.c | 32 | - 2.01: fixed 64-bit typo in readpng2.c |
33 | - 2.02: fixed improper display of usage screen on PNG error(s); fixed | 33 | - 2.02: fixed improper display of usage screen on PNG error(s); fixed |
34 | unexpected-EOF and file-read-error cases | 34 | unexpected-EOF and file-read-error cases |
35 | - 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options | 35 | - 2.03: removed runtime MMX-enabling/disabling and obsolete -mmx* options |
36 | 36 | ||
37 | --------------------------------------------------------------------------- | 37 | --------------------------------------------------------------------------- |
38 | 38 | ||
39 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. | 39 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. |
40 | 40 | ||
41 | This software is provided "as is," without warranty of any kind, | 41 | This software is provided "as is," without warranty of any kind, |
42 | express or implied. In no event shall the author or contributors | 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 | 43 | be held liable for any damages arising in any way from the use of |
44 | this software. | 44 | this software. |
45 | 45 | ||
46 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 47 | redistribute this software according to the terms of one of the |
48 | following two licenses (at your option): | 48 | following two licenses (at your option): |
49 | 49 | ||
50 | 50 | ||
51 | LICENSE 1 ("BSD-like with advertising clause"): | 51 | LICENSE 1 ("BSD-like with advertising clause"): |
52 | 52 | ||
53 | Permission is granted to anyone to use this software for any purpose, | 53 | Permission is granted to anyone to use this software for any purpose, |
54 | including commercial applications, and to alter it and redistribute | 54 | including commercial applications, and to alter it and redistribute |
55 | it freely, subject to the following restrictions: | 55 | it freely, subject to the following restrictions: |
56 | 56 | ||
57 | 1. Redistributions of source code must retain the above copyright | 57 | 1. Redistributions of source code must retain the above copyright |
58 | notice, disclaimer, and this list of conditions. | 58 | notice, disclaimer, and this list of conditions. |
59 | 2. Redistributions in binary form must reproduce the above copyright | 59 | 2. Redistributions in binary form must reproduce the above copyright |
60 | notice, disclaimer, and this list of conditions in the documenta- | 60 | notice, disclaimer, and this list of conditions in the documenta- |
61 | tion and/or other materials provided with the distribution. | 61 | tion and/or other materials provided with the distribution. |
62 | 3. All advertising materials mentioning features or use of this | 62 | 3. All advertising materials mentioning features or use of this |
63 | software must display the following acknowledgment: | 63 | software must display the following acknowledgment: |
64 | 64 | ||
65 | This product includes software developed by Greg Roelofs | 65 | This product includes software developed by Greg Roelofs |
66 | and contributors for the book, "PNG: The Definitive Guide," | 66 | and contributors for the book, "PNG: The Definitive Guide," |
67 | published by O'Reilly and Associates. | 67 | published by O'Reilly and Associates. |
68 | 68 | ||
69 | 69 | ||
70 | LICENSE 2 (GNU GPL v2 or later): | 70 | LICENSE 2 (GNU GPL v2 or later): |
71 | 71 | ||
72 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 74 | the Free Software Foundation; either version 2 of the License, or |
75 | (at your option) any later version. | 75 | (at your option) any later version. |
76 | 76 | ||
77 | This program is distributed in the hope that it will be useful, | 77 | This program is distributed in the hope that it will be useful, |
78 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 78 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
79 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 79 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
80 | GNU General Public License for more details. | 80 | GNU General Public License for more details. |
81 | 81 | ||
82 | You should have received a copy of the GNU General Public License | 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, | 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 | 84 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
85 | 85 | ||
86 | ---------------------------------------------------------------------------*/ | 86 | ---------------------------------------------------------------------------*/ |
87 | 87 | ||
88 | #define PROGNAME "rpng2-win" | 88 | #define PROGNAME "rpng2-win" |
89 | #define LONGNAME "Progressive PNG Viewer for Windows" | 89 | #define LONGNAME "Progressive PNG Viewer for Windows" |
90 | #define VERSION "2.02 of 16 March 2008" | 90 | #define VERSION "2.02 of 16 March 2008" |
91 | 91 | ||
92 | #include <stdio.h> | 92 | #include <stdio.h> |
93 | #include <stdlib.h> | 93 | #include <stdlib.h> |
94 | #include <string.h> | 94 | #include <string.h> |
95 | #include <setjmp.h> /* for jmpbuf declaration in readpng2.h */ | 95 | #include <setjmp.h> /* for jmpbuf declaration in readpng2.h */ |
96 | #include <time.h> | 96 | #include <time.h> |
97 | #include <math.h> /* only for PvdM background code */ | 97 | #include <math.h> /* only for PvdM background code */ |
98 | #include <windows.h> | 98 | #include <windows.h> |
99 | #ifdef __CYGWIN__ | 99 | #ifdef __CYGWIN__ |
100 | /* getch replacement. Turns out, we don't really need this, | 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 | 101 | * but leave it here if we ever enable any of the uses of |
102 | * _getch in the main code | 102 | * _getch in the main code |
103 | */ | 103 | */ |
104 | #include <unistd.h> | 104 | #include <unistd.h> |
105 | #include <termio.h> | 105 | #include <termio.h> |
106 | #include <sys/ioctl.h> | 106 | #include <sys/ioctl.h> |
107 | int repl_getch( void ) | 107 | int repl_getch( void ) |
108 | { | 108 | { |
109 | char ch; | 109 | char ch; |
110 | int fd = fileno(stdin); | 110 | int fd = fileno(stdin); |
111 | struct termio old_tty, new_tty; | 111 | struct termio old_tty, new_tty; |
112 | 112 | ||
113 | ioctl(fd, TCGETA, &old_tty); | 113 | ioctl(fd, TCGETA, &old_tty); |
114 | new_tty = old_tty; | 114 | new_tty = old_tty; |
115 | new_tty.c_lflag &= ~(ICANON | ECHO | ISIG); | 115 | new_tty.c_lflag &= ~(ICANON | ECHO | ISIG); |
116 | ioctl(fd, TCSETA, &new_tty); | 116 | ioctl(fd, TCSETA, &new_tty); |
117 | fread(&ch, 1, sizeof(ch), stdin); | 117 | fread(&ch, 1, sizeof(ch), stdin); |
118 | ioctl(fd, TCSETA, &old_tty); | 118 | ioctl(fd, TCSETA, &old_tty); |
119 | 119 | ||
120 | return ch; | 120 | return ch; |
121 | } | 121 | } |
122 | #define _getch repl_getch | 122 | #define _getch repl_getch |
123 | #else | 123 | #else |
124 | #include <conio.h> /* only for _getch() */ | 124 | #include <conio.h> /* only for _getch() */ |
125 | #endif | 125 | #endif |
126 | 126 | ||
127 | /* all for PvdM background code: */ | 127 | /* all for PvdM background code: */ |
128 | #ifndef PI | 128 | #ifndef PI |
129 | # define PI 3.141592653589793238 | 129 | # define PI 3.141592653589793238 |
130 | #endif | 130 | #endif |
131 | #define PI_2 (PI*0.5) | 131 | #define PI_2 (PI*0.5) |
132 | #define INV_PI_360 (360.0 / PI) | 132 | #define INV_PI_360 (360.0 / PI) |
133 | #define MAX(a,b) (a>b?a:b) | 133 | #define MAX(a,b) (a>b?a:b) |
134 | #define MIN(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)) | 135 | #define CLIP(a,min,max) MAX(min,MIN((a),max)) |
136 | #define ABS(a) ((a)<0?-(a):(a)) | 136 | #define ABS(a) ((a)<0?-(a):(a)) |
137 | #define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */ | 137 | #define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */ |
138 | #define ROUNDF(f) ((int)(f + 0.5)) | 138 | #define ROUNDF(f) ((int)(f + 0.5)) |
139 | 139 | ||
140 | #define rgb1_max bg_freq | 140 | #define rgb1_max bg_freq |
141 | #define rgb1_min bg_gray | 141 | #define rgb1_min bg_gray |
142 | #define rgb2_max bg_bsat | 142 | #define rgb2_max bg_bsat |
143 | #define rgb2_min bg_brot | 143 | #define rgb2_min bg_brot |
144 | 144 | ||
145 | /* #define DEBUG */ /* this enables the Trace() macros */ | 145 | /* #define DEBUG */ /* this enables the Trace() macros */ |
146 | 146 | ||
147 | #include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */ | 147 | #include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */ |
148 | 148 | ||
149 | 149 | ||
150 | /* could just include png.h, but this macro is the only thing we need | 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 | 151 | * (name and typedefs changed to local versions); note that side effects |
152 | * only happen with alpha (which could easily be avoided with | 152 | * only happen with alpha (which could easily be avoided with |
153 | * "ush acopy = (alpha);") */ | 153 | * "ush acopy = (alpha);") */ |
154 | 154 | ||
155 | #define alpha_composite(composite, fg, alpha, bg) { \ | 155 | #define alpha_composite(composite, fg, alpha, bg) { \ |
156 | ush temp = ((ush)(fg)*(ush)(alpha) + \ | 156 | ush temp = ((ush)(fg)*(ush)(alpha) + \ |
157 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ | 157 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ |
158 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ | 158 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ |
159 | } | 159 | } |
160 | 160 | ||
161 | 161 | ||
162 | #define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this | 162 | #define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this |
163 | * block size corresponds roughly to a download | 163 | * block size corresponds roughly to a download |
164 | * speed 10% faster than theoretical 33.6K maximum | 164 | * speed 10% faster than theoretical 33.6K maximum |
165 | * (assuming 8 data bits, 1 stop bit and no other | 165 | * (assuming 8 data bits, 1 stop bit and no other |
166 | * overhead) */ | 166 | * overhead) */ |
167 | 167 | ||
168 | /* local prototypes */ | 168 | /* local prototypes */ |
169 | static void rpng2_win_init(void); | 169 | static void rpng2_win_init(void); |
170 | static int rpng2_win_create_window(void); | 170 | static int rpng2_win_create_window(void); |
171 | static int rpng2_win_load_bg_image(void); | 171 | static int rpng2_win_load_bg_image(void); |
172 | static void rpng2_win_display_row(ulg row); | 172 | static void rpng2_win_display_row(ulg row); |
173 | static void rpng2_win_finish_display(void); | 173 | static void rpng2_win_finish_display(void); |
174 | static void rpng2_win_cleanup(void); | 174 | static void rpng2_win_cleanup(void); |
175 | LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM); | 175 | LRESULT CALLBACK rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM); |
176 | 176 | ||
177 | 177 | ||
178 | static char titlebar[1024]; | 178 | static char titlebar[1024]; |
179 | static char *progname = PROGNAME; | 179 | static char *progname = PROGNAME; |
180 | static char *appname = LONGNAME; | 180 | static char *appname = LONGNAME; |
181 | static char *filename; | 181 | static char *filename; |
182 | static FILE *infile; | 182 | static FILE *infile; |
183 | 183 | ||
184 | static mainprog_info rpng2_info; | 184 | static mainprog_info rpng2_info; |
185 | 185 | ||
186 | static uch inbuf[INBUFSIZE]; | 186 | static uch inbuf[INBUFSIZE]; |
187 | static int incount; | 187 | static int incount; |
188 | 188 | ||
189 | static int pat = 6; /* must be less than num_bgpat */ | 189 | static int pat = 6; /* must be less than num_bgpat */ |
190 | static int bg_image = 0; | 190 | static int bg_image = 0; |
191 | static int bgscale = 16; | 191 | static int bgscale = 16; |
192 | static ulg bg_rowbytes; | 192 | static ulg bg_rowbytes; |
193 | static uch *bg_data; | 193 | static uch *bg_data; |
194 | 194 | ||
195 | static struct rgb_color { | 195 | static struct rgb_color { |
196 | uch r, g, b; | 196 | uch r, g, b; |
197 | } rgb[] = { | 197 | } rgb[] = { |
198 | { 0, 0, 0}, /* 0: black */ | 198 | { 0, 0, 0}, /* 0: black */ |
199 | {255, 255, 255}, /* 1: white */ | 199 | {255, 255, 255}, /* 1: white */ |
200 | {173, 132, 57}, /* 2: tan */ | 200 | {173, 132, 57}, /* 2: tan */ |
201 | { 64, 132, 0}, /* 3: medium green */ | 201 | { 64, 132, 0}, /* 3: medium green */ |
202 | {189, 117, 1}, /* 4: gold */ | 202 | {189, 117, 1}, /* 4: gold */ |
203 | {253, 249, 1}, /* 5: yellow */ | 203 | {253, 249, 1}, /* 5: yellow */ |
204 | { 0, 0, 255}, /* 6: blue */ | 204 | { 0, 0, 255}, /* 6: blue */ |
205 | { 0, 0, 120}, /* 7: medium blue */ | 205 | { 0, 0, 120}, /* 7: medium blue */ |
206 | {255, 0, 255}, /* 8: magenta */ | 206 | {255, 0, 255}, /* 8: magenta */ |
207 | { 64, 0, 64}, /* 9: dark magenta */ | 207 | { 64, 0, 64}, /* 9: dark magenta */ |
208 | {255, 0, 0}, /* 10: red */ | 208 | {255, 0, 0}, /* 10: red */ |
209 | { 64, 0, 0}, /* 11: dark red */ | 209 | { 64, 0, 0}, /* 11: dark red */ |
210 | {255, 127, 0}, /* 12: orange */ | 210 | {255, 127, 0}, /* 12: orange */ |
211 | {192, 96, 0}, /* 13: darker orange */ | 211 | {192, 96, 0}, /* 13: darker orange */ |
212 | { 24, 60, 0}, /* 14: dark green-yellow */ | 212 | { 24, 60, 0}, /* 14: dark green-yellow */ |
213 | { 85, 125, 200} /* 15: ice blue */ | 213 | { 85, 125, 200} /* 15: ice blue */ |
214 | }; | 214 | }; |
215 | /* not used for now, but should be for error-checking: | 215 | /* not used for now, but should be for error-checking: |
216 | static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); | 216 | static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); |
217 | */ | 217 | */ |
218 | 218 | ||
219 | /* | 219 | /* |
220 | This whole struct is a fairly cheesy way to keep the number of | 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 | 221 | command-line options to a minimum. The radial-waves background |
222 | type is a particularly poor fit to the integer elements of the | 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 | 223 | struct...but a few macros and a little fixed-point math will do |
224 | wonders for ya. | 224 | wonders for ya. |
225 | 225 | ||
226 | type bits: | 226 | type bits: |
227 | F E D C B A 9 8 7 6 5 4 3 2 1 0 | 227 | F E D C B A 9 8 7 6 5 4 3 2 1 0 |
228 | | | | | | | 228 | | | | | | |
229 | | | +-+-+-- 0 = sharp-edged checkerboard | 229 | | | +-+-+-- 0 = sharp-edged checkerboard |
230 | | | 1 = soft diamonds | 230 | | | 1 = soft diamonds |
231 | | | 2 = radial waves | 231 | | | 2 = radial waves |
232 | | | 3-7 = undefined | 232 | | | 3-7 = undefined |
233 | | +-- gradient #2 inverted? | 233 | | +-- gradient #2 inverted? |
234 | +-- alternating columns inverted? | 234 | +-- alternating columns inverted? |
235 | */ | 235 | */ |
236 | static struct background_pattern { | 236 | static struct background_pattern { |
237 | ush type; | 237 | ush type; |
238 | int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */ | 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)*/ | 239 | int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/ |
240 | } bg[] = { | 240 | } bg[] = { |
241 | {0+8, 2,0, 1,15}, /* checkered: tan/black vs. white/ice blue */ | 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 */ | 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 */ | 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 */ | 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 */ | 245 | {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */ |
246 | {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */ | 246 | {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */ |
247 | {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */ | 247 | {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */ |
248 | {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */ | 248 | {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */ |
249 | {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */ | 249 | {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */ |
250 | {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */ | 250 | {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */ |
251 | {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */ | 251 | {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */ |
252 | {1, 3,0, 0,0}, /* diamonds: medium green vs. black */ | 252 | {1, 3,0, 0,0}, /* diamonds: medium green vs. black */ |
253 | {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */ | 253 | {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */ |
254 | {2, 18, 100, 10, 2}, /* radial: soft, curved 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 */ | 255 | {2, 16, 256, 100, 250}, /* radial: very tight spiral */ |
256 | {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */ | 256 | {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */ |
257 | }; | 257 | }; |
258 | static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern); | 258 | static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern); |
259 | 259 | ||
260 | 260 | ||
261 | /* Windows-specific global variables (could go in struct, but messy...) */ | 261 | /* Windows-specific global variables (could go in struct, but messy...) */ |
262 | static ulg wimage_rowbytes; | 262 | static ulg wimage_rowbytes; |
263 | static uch *dib; | 263 | static uch *dib; |
264 | static uch *wimage_data; | 264 | static uch *wimage_data; |
265 | static BITMAPINFOHEADER *bmih; | 265 | static BITMAPINFOHEADER *bmih; |
266 | 266 | ||
267 | static HWND global_hwnd; | 267 | static HWND global_hwnd; |
268 | static HINSTANCE global_hInst; | 268 | static HINSTANCE global_hInst; |
269 | static int global_showmode; | 269 | static int global_showmode; |
270 | 270 | ||
271 | 271 | ||
272 | 272 | ||
273 | 273 | ||
274 | int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) | 274 | int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode) |
275 | { | 275 | { |
276 | char *args[1024]; /* arbitrary limit, but should suffice */ | 276 | char *args[1024]; /* arbitrary limit, but should suffice */ |
277 | char **argv = args; | 277 | char **argv = args; |
278 | char *p, *q, *bgstr = NULL; | 278 | char *p, *q, *bgstr = NULL; |
279 | int argc = 0; | 279 | int argc = 0; |
280 | int rc, alen, flen; | 280 | int rc, alen, flen; |
281 | int error = 0; | 281 | int error = 0; |
282 | int timing = FALSE; | 282 | int timing = FALSE; |
283 | int have_bg = FALSE; | 283 | int have_bg = FALSE; |
284 | double LUT_exponent; /* just the lookup table */ | 284 | double LUT_exponent; /* just the lookup table */ |
285 | double CRT_exponent = 2.2; /* just the monitor */ | 285 | double CRT_exponent = 2.2; /* just the monitor */ |
286 | double default_display_exponent; /* whole display system */ | 286 | double default_display_exponent; /* whole display system */ |
287 | MSG msg; | 287 | MSG msg; |
288 | 288 | ||
289 | 289 | ||
290 | /* First initialize a few things, just to be sure--memset takes care of | 290 | /* First initialize a few things, just to be sure--memset takes care of |
291 | * default background color (black), booleans (FALSE), pointers (NULL), | 291 | * default background color (black), booleans (FALSE), pointers (NULL), |
292 | * etc. */ | 292 | * etc. */ |
293 | 293 | ||
294 | global_hInst = hInst; | 294 | global_hInst = hInst; |
295 | global_showmode = showmode; | 295 | global_showmode = showmode; |
296 | filename = (char *)NULL; | 296 | filename = (char *)NULL; |
297 | memset(&rpng2_info, 0, sizeof(mainprog_info)); | 297 | memset(&rpng2_info, 0, sizeof(mainprog_info)); |
298 | 298 | ||
299 | #ifndef __CYGWIN__ | 299 | #ifndef __CYGWIN__ |
300 | /* Next reenable console output, which normally goes to the bit bucket | 300 | /* Next reenable console output, which normally goes to the bit bucket |
301 | * for windowed apps. Closing the console window will terminate the | 301 | * for windowed apps. Closing the console window will terminate the |
302 | * app. Thanks to David.Geldreich@realviz.com for supplying the magical | 302 | * app. Thanks to David.Geldreich@realviz.com for supplying the magical |
303 | * incantation. */ | 303 | * incantation. */ |
304 | 304 | ||
305 | AllocConsole(); | 305 | AllocConsole(); |
306 | freopen("CONOUT$", "a", stderr); | 306 | freopen("CONOUT$", "a", stderr); |
307 | freopen("CONOUT$", "a", stdout); | 307 | freopen("CONOUT$", "a", stdout); |
308 | #endif | 308 | #endif |
309 | 309 | ||
310 | /* Set the default value for our display-system exponent, i.e., the | 310 | /* Set the default value for our display-system exponent, i.e., the |
311 | * product of the CRT exponent and the exponent corresponding to | 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 | 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 | 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 | 314 | * ones), but it should cover 99% of the current possibilities. And |
315 | * yes, these ifdefs are completely wasted in a Windows program... */ | 315 | * yes, these ifdefs are completely wasted in a Windows program... */ |
316 | 316 | ||
317 | #if defined(NeXT) | 317 | #if defined(NeXT) |
318 | /* third-party utilities can modify the default LUT exponent */ | 318 | /* third-party utilities can modify the default LUT exponent */ |
319 | LUT_exponent = 1.0 / 2.2; | 319 | LUT_exponent = 1.0 / 2.2; |
320 | /* | 320 | /* |
321 | if (some_next_function_that_returns_gamma(&next_gamma)) | 321 | if (some_next_function_that_returns_gamma(&next_gamma)) |
322 | LUT_exponent = 1.0 / next_gamma; | 322 | LUT_exponent = 1.0 / next_gamma; |
323 | */ | 323 | */ |
324 | #elif defined(sgi) | 324 | #elif defined(sgi) |
325 | LUT_exponent = 1.0 / 1.7; | 325 | LUT_exponent = 1.0 / 1.7; |
326 | /* there doesn't seem to be any documented function to | 326 | /* there doesn't seem to be any documented function to |
327 | * get the "gamma" value, so we do it the hard way */ | 327 | * get the "gamma" value, so we do it the hard way */ |
328 | infile = fopen("/etc/config/system.glGammaVal", "r"); | 328 | infile = fopen("/etc/config/system.glGammaVal", "r"); |
329 | if (infile) { | 329 | if (infile) { |
330 | double sgi_gamma; | 330 | double sgi_gamma; |
331 | 331 | ||
332 | fgets(tmpline, 80, infile); | 332 | fgets(tmpline, 80, infile); |
333 | fclose(infile); | 333 | fclose(infile); |
334 | sgi_gamma = atof(tmpline); | 334 | sgi_gamma = atof(tmpline); |
335 | if (sgi_gamma > 0.0) | 335 | if (sgi_gamma > 0.0) |
336 | LUT_exponent = 1.0 / sgi_gamma; | 336 | LUT_exponent = 1.0 / sgi_gamma; |
337 | } | 337 | } |
338 | #elif defined(Macintosh) | 338 | #elif defined(Macintosh) |
339 | LUT_exponent = 1.8 / 2.61; | 339 | LUT_exponent = 1.8 / 2.61; |
340 | /* | 340 | /* |
341 | if (some_mac_function_that_returns_gamma(&mac_gamma)) | 341 | if (some_mac_function_that_returns_gamma(&mac_gamma)) |
342 | LUT_exponent = mac_gamma / 2.61; | 342 | LUT_exponent = mac_gamma / 2.61; |
343 | */ | 343 | */ |
344 | #else | 344 | #else |
345 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ | 345 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ |
346 | #endif | 346 | #endif |
347 | 347 | ||
348 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ | 348 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ |
349 | default_display_exponent = LUT_exponent * CRT_exponent; | 349 | default_display_exponent = LUT_exponent * CRT_exponent; |
350 | 350 | ||
351 | 351 | ||
352 | /* If the user has set the SCREEN_GAMMA environment variable as suggested | 352 | /* If the user has set the SCREEN_GAMMA environment variable as suggested |
353 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise | 353 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise |
354 | * use the default value we just calculated. Either way, the user may | 354 | * use the default value we just calculated. Either way, the user may |
355 | * override this via a command-line option. */ | 355 | * override this via a command-line option. */ |
356 | 356 | ||
357 | if ((p = getenv("SCREEN_GAMMA")) != NULL) | 357 | if ((p = getenv("SCREEN_GAMMA")) != NULL) |
358 | rpng2_info.display_exponent = atof(p); | 358 | rpng2_info.display_exponent = atof(p); |
359 | else | 359 | else |
360 | rpng2_info.display_exponent = default_display_exponent; | 360 | rpng2_info.display_exponent = default_display_exponent; |
361 | 361 | ||
362 | 362 | ||
363 | /* Windows really hates command lines, so we have to set up our own argv. | 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 | 364 | * Note that we do NOT bother with quoted arguments here, so don't use |
365 | * filenames with spaces in 'em! */ | 365 | * filenames with spaces in 'em! */ |
366 | 366 | ||
367 | argv[argc++] = PROGNAME; | 367 | argv[argc++] = PROGNAME; |
368 | p = cmd; | 368 | p = cmd; |
369 | for (;;) { | 369 | for (;;) { |
370 | if (*p == ' ') | 370 | if (*p == ' ') |
371 | while (*++p == ' ') | 371 | while (*++p == ' ') |
372 | ; | 372 | ; |
373 | /* now p points at the first non-space after some spaces */ | 373 | /* now p points at the first non-space after some spaces */ |
374 | if (*p == '\0') | 374 | if (*p == '\0') |
375 | break; /* nothing after the spaces: done */ | 375 | break; /* nothing after the spaces: done */ |
376 | argv[argc++] = q = p; | 376 | argv[argc++] = q = p; |
377 | while (*q && *q != ' ') | 377 | while (*q && *q != ' ') |
378 | ++q; | 378 | ++q; |
379 | /* now q points at a space or the end of the string */ | 379 | /* now q points at a space or the end of the string */ |
380 | if (*q == '\0') | 380 | if (*q == '\0') |
381 | break; /* last argv already terminated; quit */ | 381 | break; /* last argv already terminated; quit */ |
382 | *q = '\0'; /* change space to terminator */ | 382 | *q = '\0'; /* change space to terminator */ |
383 | p = q + 1; | 383 | p = q + 1; |
384 | } | 384 | } |
385 | argv[argc] = NULL; /* terminate the argv array itself */ | 385 | argv[argc] = NULL; /* terminate the argv array itself */ |
386 | 386 | ||
387 | 387 | ||
388 | /* Now parse the command line for options and the PNG filename. */ | 388 | /* Now parse the command line for options and the PNG filename. */ |
389 | 389 | ||
390 | while (*++argv && !error) { | 390 | while (*++argv && !error) { |
391 | if (!strncmp(*argv, "-gamma", 2)) { | 391 | if (!strncmp(*argv, "-gamma", 2)) { |
392 | if (!*++argv) | 392 | if (!*++argv) |
393 | ++error; | 393 | ++error; |
394 | else { | 394 | else { |
395 | rpng2_info.display_exponent = atof(*argv); | 395 | rpng2_info.display_exponent = atof(*argv); |
396 | if (rpng2_info.display_exponent <= 0.0) | 396 | if (rpng2_info.display_exponent <= 0.0) |
397 | ++error; | 397 | ++error; |
398 | } | 398 | } |
399 | } else if (!strncmp(*argv, "-bgcolor", 4)) { | 399 | } else if (!strncmp(*argv, "-bgcolor", 4)) { |
400 | if (!*++argv) | 400 | if (!*++argv) |
401 | ++error; | 401 | ++error; |
402 | else { | 402 | else { |
403 | bgstr = *argv; | 403 | bgstr = *argv; |
404 | if (strlen(bgstr) != 7 || bgstr[0] != '#') | 404 | if (strlen(bgstr) != 7 || bgstr[0] != '#') |
405 | ++error; | 405 | ++error; |
406 | else { | 406 | else { |
407 | have_bg = TRUE; | 407 | have_bg = TRUE; |
408 | bg_image = FALSE; | 408 | bg_image = FALSE; |
409 | } | 409 | } |
410 | } | 410 | } |
411 | } else if (!strncmp(*argv, "-bgpat", 4)) { | 411 | } else if (!strncmp(*argv, "-bgpat", 4)) { |
412 | if (!*++argv) | 412 | if (!*++argv) |
413 | ++error; | 413 | ++error; |
414 | else { | 414 | else { |
415 | pat = atoi(*argv) - 1; | 415 | pat = atoi(*argv) - 1; |
416 | if (pat < 0 || pat >= num_bgpat) | 416 | if (pat < 0 || pat >= num_bgpat) |
417 | ++error; | 417 | ++error; |
418 | else { | 418 | else { |
419 | bg_image = TRUE; | 419 | bg_image = TRUE; |
420 | have_bg = FALSE; | 420 | have_bg = FALSE; |
421 | } | 421 | } |
422 | } | 422 | } |
423 | } else if (!strncmp(*argv, "-timing", 2)) { | 423 | } else if (!strncmp(*argv, "-timing", 2)) { |
424 | timing = TRUE; | 424 | timing = TRUE; |
425 | } else { | 425 | } else { |
426 | if (**argv != '-') { | 426 | if (**argv != '-') { |
427 | filename = *argv; | 427 | filename = *argv; |
428 | if (argv[1]) /* shouldn't be any more args after filename */ | 428 | if (argv[1]) /* shouldn't be any more args after filename */ |
429 | ++error; | 429 | ++error; |
430 | } else | 430 | } else |
431 | ++error; /* not expecting any other options */ | 431 | ++error; /* not expecting any other options */ |
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
435 | if (!filename) | 435 | if (!filename) |
436 | ++error; | 436 | ++error; |
437 | 437 | ||
438 | 438 | ||
439 | /* print usage screen if any errors up to this point */ | 439 | /* print usage screen if any errors up to this point */ |
440 | 440 | ||
441 | if (error) { | 441 | if (error) { |
442 | #ifndef __CYGWIN__ | 442 | #ifndef __CYGWIN__ |
443 | int ch; | 443 | int ch; |
444 | #endif | 444 | #endif |
445 | 445 | ||
446 | fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); | 446 | fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); |
447 | readpng2_version_info(); | 447 | readpng2_version_info(); |
448 | fprintf(stderr, "\n" | 448 | fprintf(stderr, "\n" |
449 | "Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n" | 449 | "Usage: %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\n" |
450 | " %*s file.png\n\n" | 450 | " %*s file.png\n\n" |
451 | " exp \ttransfer-function exponent (``gamma'') of the display\n" | 451 | " exp \ttransfer-function exponent (``gamma'') of the display\n" |
452 | "\t\t system in floating-point format (e.g., ``%.1f''); equal\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" | 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" | 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" | 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" | 456 | "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" |
457 | "\t\t used with transparent images; overrides -bgpat option\n" | 457 | "\t\t used with transparent images; overrides -bgpat option\n" |
458 | " pat \tdesired background pattern number (1-%d); used with\n" | 458 | " pat \tdesired background pattern number (1-%d); used with\n" |
459 | "\t\t transparent images; overrides -bgcolor option\n" | 459 | "\t\t transparent images; overrides -bgcolor option\n" |
460 | " -timing\tenables delay for every block read, to simulate modem\n" | 460 | " -timing\tenables delay for every block read, to simulate modem\n" |
461 | "\t\t download of image (~36 Kbps)\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" | 462 | "\nPress Q, Esc or mouse button 1 after image is displayed to quit.\n" |
463 | #ifndef __CYGWIN__ | 463 | #ifndef __CYGWIN__ |
464 | "Press Q or Esc to quit this usage screen. ", | 464 | "Press Q or Esc to quit this usage screen. ", |
465 | #else | 465 | #else |
466 | , | 466 | , |
467 | #endif | 467 | #endif |
468 | PROGNAME, | 468 | PROGNAME, |
469 | #if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \ | 469 | #if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \ |
470 | !(defined(__CYGWIN__) || defined(__MINGW32__)) | 470 | !(defined(__CYGWIN__) || defined(__MINGW32__)) |
471 | (int)strlen(PROGNAME), " ", | 471 | (int)strlen(PROGNAME), " ", |
472 | #endif | 472 | #endif |
473 | (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat); | 473 | (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat); |
474 | fflush(stderr); | 474 | fflush(stderr); |
475 | #ifndef __CYGWIN__ | 475 | #ifndef __CYGWIN__ |
476 | do | 476 | do |
477 | ch = _getch(); | 477 | ch = _getch(); |
478 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); | 478 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); |
479 | #endif | 479 | #endif |
480 | exit(1); | 480 | exit(1); |
481 | } | 481 | } |
482 | 482 | ||
483 | 483 | ||
484 | if (!(infile = fopen(filename, "rb"))) { | 484 | if (!(infile = fopen(filename, "rb"))) { |
485 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); | 485 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); |
486 | ++error; | 486 | ++error; |
487 | } else { | 487 | } else { |
488 | incount = fread(inbuf, 1, INBUFSIZE, infile); | 488 | incount = fread(inbuf, 1, INBUFSIZE, infile); |
489 | if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { | 489 | if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { |
490 | fprintf(stderr, PROGNAME | 490 | fprintf(stderr, PROGNAME |
491 | ": [%s] is not a PNG file: incorrect signature\n", | 491 | ": [%s] is not a PNG file: incorrect signature\n", |
492 | filename); | 492 | filename); |
493 | ++error; | 493 | ++error; |
494 | } else if ((rc = readpng2_init(&rpng2_info)) != 0) { | 494 | } else if ((rc = readpng2_init(&rpng2_info)) != 0) { |
495 | switch (rc) { | 495 | switch (rc) { |
496 | case 2: | 496 | case 2: |
497 | fprintf(stderr, PROGNAME | 497 | fprintf(stderr, PROGNAME |
498 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); | 498 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); |
499 | break; | 499 | break; |
500 | case 4: | 500 | case 4: |
501 | fprintf(stderr, PROGNAME ": insufficient memory\n"); | 501 | fprintf(stderr, PROGNAME ": insufficient memory\n"); |
502 | break; | 502 | break; |
503 | default: | 503 | default: |
504 | fprintf(stderr, PROGNAME | 504 | fprintf(stderr, PROGNAME |
505 | ": unknown readpng2_init() error\n"); | 505 | ": unknown readpng2_init() error\n"); |
506 | break; | 506 | break; |
507 | } | 507 | } |
508 | ++error; | 508 | ++error; |
509 | } | 509 | } |
510 | if (error) | 510 | if (error) |
511 | fclose(infile); | 511 | fclose(infile); |
512 | } | 512 | } |
513 | 513 | ||
514 | 514 | ||
515 | if (error) { | 515 | if (error) { |
516 | #ifndef __CYGWIN__ | 516 | #ifndef __CYGWIN__ |
517 | int ch; | 517 | int ch; |
518 | #endif | 518 | #endif |
519 | 519 | ||
520 | fprintf(stderr, PROGNAME ": aborting.\n"); | 520 | fprintf(stderr, PROGNAME ": aborting.\n"); |
521 | #ifndef __CYGWIN__ | 521 | #ifndef __CYGWIN__ |
522 | do | 522 | do |
523 | ch = _getch(); | 523 | ch = _getch(); |
524 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); | 524 | while (ch != 'q' && ch != 'Q' && ch != 0x1B); |
525 | #endif | 525 | #endif |
526 | exit(2); | 526 | exit(2); |
527 | } else { | 527 | } else { |
528 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); | 528 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, appname); |
529 | #ifndef __CYGWIN__ | 529 | #ifndef __CYGWIN__ |
530 | fprintf(stderr, | 530 | fprintf(stderr, |
531 | "\n [console window: closing this window will terminate %s]\n\n", | 531 | "\n [console window: closing this window will terminate %s]\n\n", |
532 | PROGNAME); | 532 | PROGNAME); |
533 | #endif | 533 | #endif |
534 | fflush(stderr); | 534 | fflush(stderr); |
535 | } | 535 | } |
536 | 536 | ||
537 | 537 | ||
538 | /* set the title-bar string, but make sure buffer doesn't overflow */ | 538 | /* set the title-bar string, but make sure buffer doesn't overflow */ |
539 | 539 | ||
540 | alen = strlen(appname); | 540 | alen = strlen(appname); |
541 | flen = strlen(filename); | 541 | flen = strlen(filename); |
542 | if (alen + flen + 3 > 1023) | 542 | if (alen + flen + 3 > 1023) |
543 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); | 543 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); |
544 | else | 544 | else |
545 | sprintf(titlebar, "%s: %s", appname, filename); | 545 | sprintf(titlebar, "%s: %s", appname, filename); |
546 | 546 | ||
547 | 547 | ||
548 | /* set some final rpng2_info variables before entering main data loop */ | 548 | /* set some final rpng2_info variables before entering main data loop */ |
549 | 549 | ||
550 | if (have_bg) { | 550 | if (have_bg) { |
551 | unsigned r, g, b; /* this approach quiets compiler warnings */ | 551 | unsigned r, g, b; /* this approach quiets compiler warnings */ |
552 | 552 | ||
553 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); | 553 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); |
554 | rpng2_info.bg_red = (uch)r; | 554 | rpng2_info.bg_red = (uch)r; |
555 | rpng2_info.bg_green = (uch)g; | 555 | rpng2_info.bg_green = (uch)g; |
556 | rpng2_info.bg_blue = (uch)b; | 556 | rpng2_info.bg_blue = (uch)b; |
557 | } else | 557 | } else |
558 | rpng2_info.need_bgcolor = TRUE; | 558 | rpng2_info.need_bgcolor = TRUE; |
559 | 559 | ||
560 | rpng2_info.state = kPreInit; | 560 | rpng2_info.state = kPreInit; |
561 | rpng2_info.mainprog_init = rpng2_win_init; | 561 | rpng2_info.mainprog_init = rpng2_win_init; |
562 | rpng2_info.mainprog_display_row = rpng2_win_display_row; | 562 | rpng2_info.mainprog_display_row = rpng2_win_display_row; |
563 | rpng2_info.mainprog_finish_display = rpng2_win_finish_display; | 563 | rpng2_info.mainprog_finish_display = rpng2_win_finish_display; |
564 | 564 | ||
565 | 565 | ||
566 | /* OK, this is the fun part: call readpng2_decode_data() at the start of | 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 | 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 | 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 | 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- | 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 | 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 | 572 | * one second per iteration to simulate downloading the image via an analog |
573 | * modem. */ | 573 | * modem. */ |
574 | 574 | ||
575 | for (;;) { | 575 | for (;;) { |
576 | Trace((stderr, "about to call readpng2_decode_data()\n")) | 576 | Trace((stderr, "about to call readpng2_decode_data()\n")) |
577 | if (readpng2_decode_data(&rpng2_info, inbuf, incount)) | 577 | if (readpng2_decode_data(&rpng2_info, inbuf, incount)) |
578 | ++error; | 578 | ++error; |
579 | Trace((stderr, "done with readpng2_decode_data()\n")) | 579 | Trace((stderr, "done with readpng2_decode_data()\n")) |
580 | 580 | ||
581 | if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { | 581 | if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { |
582 | if (rpng2_info.state == kDone) { | 582 | if (rpng2_info.state == kDone) { |
583 | Trace((stderr, "done decoding PNG image\n")) | 583 | Trace((stderr, "done decoding PNG image\n")) |
584 | } else if (ferror(infile)) { | 584 | } else if (ferror(infile)) { |
585 | fprintf(stderr, PROGNAME | 585 | fprintf(stderr, PROGNAME |
586 | ": error while reading PNG image file\n"); | 586 | ": error while reading PNG image file\n"); |
587 | exit(3); | 587 | exit(3); |
588 | } else if (feof(infile)) { | 588 | } else if (feof(infile)) { |
589 | fprintf(stderr, PROGNAME ": end of file reached " | 589 | fprintf(stderr, PROGNAME ": end of file reached " |
590 | "(unexpectedly) while reading PNG image file\n"); | 590 | "(unexpectedly) while reading PNG image file\n"); |
591 | exit(3); | 591 | exit(3); |
592 | } else /* if (error) */ { | 592 | } else /* if (error) */ { |
593 | /* will print error message below */ | 593 | /* will print error message below */ |
594 | } | 594 | } |
595 | break; | 595 | break; |
596 | } | 596 | } |
597 | 597 | ||
598 | if (timing) | 598 | if (timing) |
599 | Sleep(1000L); | 599 | Sleep(1000L); |
600 | 600 | ||
601 | incount = fread(inbuf, 1, INBUFSIZE, infile); | 601 | incount = fread(inbuf, 1, INBUFSIZE, infile); |
602 | } | 602 | } |
603 | 603 | ||
604 | 604 | ||
605 | /* clean up PNG stuff and report any decoding errors */ | 605 | /* clean up PNG stuff and report any decoding errors */ |
606 | 606 | ||
607 | fclose(infile); | 607 | fclose(infile); |
608 | Trace((stderr, "about to call readpng2_cleanup()\n")) | 608 | Trace((stderr, "about to call readpng2_cleanup()\n")) |
609 | readpng2_cleanup(&rpng2_info); | 609 | readpng2_cleanup(&rpng2_info); |
610 | 610 | ||
611 | if (error) { | 611 | if (error) { |
612 | fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n"); | 612 | fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n"); |
613 | exit(3); | 613 | exit(3); |
614 | } | 614 | } |
615 | 615 | ||
616 | 616 | ||
617 | /* wait for the user to tell us when to quit */ | 617 | /* wait for the user to tell us when to quit */ |
618 | 618 | ||
619 | while (GetMessage(&msg, NULL, 0, 0)) { | 619 | while (GetMessage(&msg, NULL, 0, 0)) { |
620 | TranslateMessage(&msg); | 620 | TranslateMessage(&msg); |
621 | DispatchMessage(&msg); | 621 | DispatchMessage(&msg); |
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | /* we're done: clean up all image and Windows resources and go away */ | 625 | /* we're done: clean up all image and Windows resources and go away */ |
626 | 626 | ||
627 | Trace((stderr, "about to call rpng2_win_cleanup()\n")) | 627 | Trace((stderr, "about to call rpng2_win_cleanup()\n")) |
628 | rpng2_win_cleanup(); | 628 | rpng2_win_cleanup(); |
629 | 629 | ||
630 | return msg.wParam; | 630 | return msg.wParam; |
631 | } | 631 | } |
632 | 632 | ||
633 | 633 | ||
634 | 634 | ||
635 | 635 | ||
636 | 636 | ||
637 | /* this function is called by readpng2_info_callback() in readpng2.c, which | 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 | 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 */ | 639 | * read and processed--i.e., we now have enough info to finish initializing */ |
640 | 640 | ||
641 | static void rpng2_win_init() | 641 | static void rpng2_win_init() |
642 | { | 642 | { |
643 | ulg i; | 643 | ulg i; |
644 | ulg rowbytes = rpng2_info.rowbytes; | 644 | ulg rowbytes = rpng2_info.rowbytes; |
645 | 645 | ||
646 | Trace((stderr, "beginning rpng2_win_init()\n")) | 646 | Trace((stderr, "beginning rpng2_win_init()\n")) |
647 | Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) | 647 | Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) |
648 | Trace((stderr, " width = %ld\n", rpng2_info.width)) | 648 | Trace((stderr, " width = %ld\n", rpng2_info.width)) |
649 | Trace((stderr, " height = %ld\n", rpng2_info.height)) | 649 | Trace((stderr, " height = %ld\n", rpng2_info.height)) |
650 | 650 | ||
651 | rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); | 651 | rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); |
652 | if (!rpng2_info.image_data) { | 652 | if (!rpng2_info.image_data) { |
653 | readpng2_cleanup(&rpng2_info); | 653 | readpng2_cleanup(&rpng2_info); |
654 | return; | 654 | return; |
655 | } | 655 | } |
656 | 656 | ||
657 | rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *)); | 657 | rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *)); |
658 | if (!rpng2_info.row_pointers) { | 658 | if (!rpng2_info.row_pointers) { |
659 | free(rpng2_info.image_data); | 659 | free(rpng2_info.image_data); |
660 | rpng2_info.image_data = NULL; | 660 | rpng2_info.image_data = NULL; |
661 | readpng2_cleanup(&rpng2_info); | 661 | readpng2_cleanup(&rpng2_info); |
662 | return; | 662 | return; |
663 | } | 663 | } |
664 | 664 | ||
665 | for (i = 0; i < rpng2_info.height; ++i) | 665 | for (i = 0; i < rpng2_info.height; ++i) |
666 | rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes; | 666 | rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes; |
667 | 667 | ||
668 | /*--------------------------------------------------------------------------- | 668 | /*--------------------------------------------------------------------------- |
669 | Do the basic Windows initialization stuff, make the window, and fill it | 669 | Do the basic Windows initialization stuff, make the window, and fill it |
670 | with the user-specified, file-specified or default background color. | 670 | with the user-specified, file-specified or default background color. |
671 | ---------------------------------------------------------------------------*/ | 671 | ---------------------------------------------------------------------------*/ |
672 | 672 | ||
673 | if (rpng2_win_create_window()) { | 673 | if (rpng2_win_create_window()) { |
674 | readpng2_cleanup(&rpng2_info); | 674 | readpng2_cleanup(&rpng2_info); |
675 | return; | 675 | return; |
676 | } | 676 | } |
677 | 677 | ||
678 | rpng2_info.state = kWindowInit; | 678 | rpng2_info.state = kWindowInit; |
679 | } | 679 | } |
680 | 680 | ||
681 | 681 | ||
682 | 682 | ||
683 | 683 | ||
684 | 684 | ||
685 | static int rpng2_win_create_window() | 685 | static int rpng2_win_create_window() |
686 | { | 686 | { |
687 | uch bg_red = rpng2_info.bg_red; | 687 | uch bg_red = rpng2_info.bg_red; |
688 | uch bg_green = rpng2_info.bg_green; | 688 | uch bg_green = rpng2_info.bg_green; |
689 | uch bg_blue = rpng2_info.bg_blue; | 689 | uch bg_blue = rpng2_info.bg_blue; |
690 | uch *dest; | 690 | uch *dest; |
691 | int extra_width, extra_height; | 691 | int extra_width, extra_height; |
692 | ulg i, j; | 692 | ulg i, j; |
693 | WNDCLASSEX wndclass; | 693 | WNDCLASSEX wndclass; |
694 | RECT rect; | 694 | RECT rect; |
695 | 695 | ||
696 | 696 | ||
697 | /*--------------------------------------------------------------------------- | 697 | /*--------------------------------------------------------------------------- |
698 | Allocate memory for the display-specific version of the image (round up | 698 | Allocate memory for the display-specific version of the image (round up |
699 | to multiple of 4 for Windows DIB). | 699 | to multiple of 4 for Windows DIB). |
700 | ---------------------------------------------------------------------------*/ | 700 | ---------------------------------------------------------------------------*/ |
701 | 701 | ||
702 | wimage_rowbytes = ((3*rpng2_info.width + 3L) >> 2) << 2; | 702 | wimage_rowbytes = ((3*rpng2_info.width + 3L) >> 2) << 2; |
703 | 703 | ||
704 | if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) + | 704 | if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) + |
705 | wimage_rowbytes*rpng2_info.height))) | 705 | wimage_rowbytes*rpng2_info.height))) |
706 | { | 706 | { |
707 | return 4; /* fail */ | 707 | return 4; /* fail */ |
708 | } | 708 | } |
709 | 709 | ||
710 | /*--------------------------------------------------------------------------- | 710 | /*--------------------------------------------------------------------------- |
711 | Initialize the DIB. Negative height means to use top-down BMP ordering | 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 | 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 | 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. | 714 | directly => wimage_data begins immediately after BMP header. |
715 | ---------------------------------------------------------------------------*/ | 715 | ---------------------------------------------------------------------------*/ |
716 | 716 | ||
717 | memset(dib, 0, sizeof(BITMAPINFOHEADER)); | 717 | memset(dib, 0, sizeof(BITMAPINFOHEADER)); |
718 | bmih = (BITMAPINFOHEADER *)dib; | 718 | bmih = (BITMAPINFOHEADER *)dib; |
719 | bmih->biSize = sizeof(BITMAPINFOHEADER); | 719 | bmih->biSize = sizeof(BITMAPINFOHEADER); |
720 | bmih->biWidth = rpng2_info.width; | 720 | bmih->biWidth = rpng2_info.width; |
721 | bmih->biHeight = -((long)rpng2_info.height); | 721 | bmih->biHeight = -((long)rpng2_info.height); |
722 | bmih->biPlanes = 1; | 722 | bmih->biPlanes = 1; |
723 | bmih->biBitCount = 24; | 723 | bmih->biBitCount = 24; |
724 | bmih->biCompression = 0; | 724 | bmih->biCompression = 0; |
725 | wimage_data = dib + sizeof(BITMAPINFOHEADER); | 725 | wimage_data = dib + sizeof(BITMAPINFOHEADER); |
726 | 726 | ||
727 | /*--------------------------------------------------------------------------- | 727 | /*--------------------------------------------------------------------------- |
728 | Fill window with the specified background color (default is black), but | 728 | Fill window with the specified background color (default is black), but |
729 | defer loading faked "background image" until window is displayed (may be | 729 | defer loading faked "background image" until window is displayed (may be |
730 | slow to compute). Data are in BGR order. | 730 | slow to compute). Data are in BGR order. |
731 | ---------------------------------------------------------------------------*/ | 731 | ---------------------------------------------------------------------------*/ |
732 | 732 | ||
733 | if (bg_image) { /* just fill with black for now */ | 733 | if (bg_image) { /* just fill with black for now */ |
734 | memset(wimage_data, 0, wimage_rowbytes*rpng2_info.height); | 734 | memset(wimage_data, 0, wimage_rowbytes*rpng2_info.height); |
735 | } else { | 735 | } else { |
736 | for (j = 0; j < rpng2_info.height; ++j) { | 736 | for (j = 0; j < rpng2_info.height; ++j) { |
737 | dest = wimage_data + j*wimage_rowbytes; | 737 | dest = wimage_data + j*wimage_rowbytes; |
738 | for (i = rpng2_info.width; i > 0; --i) { | 738 | for (i = rpng2_info.width; i > 0; --i) { |
739 | *dest++ = bg_blue; | 739 | *dest++ = bg_blue; |
740 | *dest++ = bg_green; | 740 | *dest++ = bg_green; |
741 | *dest++ = bg_red; | 741 | *dest++ = bg_red; |
742 | } | 742 | } |
743 | } | 743 | } |
744 | } | 744 | } |
745 | 745 | ||
746 | /*--------------------------------------------------------------------------- | 746 | /*--------------------------------------------------------------------------- |
747 | Set the window parameters. | 747 | Set the window parameters. |
748 | ---------------------------------------------------------------------------*/ | 748 | ---------------------------------------------------------------------------*/ |
749 | 749 | ||
750 | memset(&wndclass, 0, sizeof(wndclass)); | 750 | memset(&wndclass, 0, sizeof(wndclass)); |
751 | 751 | ||
752 | wndclass.cbSize = sizeof(wndclass); | 752 | wndclass.cbSize = sizeof(wndclass); |
753 | wndclass.style = CS_HREDRAW | CS_VREDRAW; | 753 | wndclass.style = CS_HREDRAW | CS_VREDRAW; |
754 | wndclass.lpfnWndProc = rpng2_win_wndproc; | 754 | wndclass.lpfnWndProc = rpng2_win_wndproc; |
755 | wndclass.hInstance = global_hInst; | 755 | wndclass.hInstance = global_hInst; |
756 | wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); | 756 | wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); |
757 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); | 757 | wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); |
758 | wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); | 758 | wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); |
759 | wndclass.lpszMenuName = NULL; | 759 | wndclass.lpszMenuName = NULL; |
760 | wndclass.lpszClassName = progname; | 760 | wndclass.lpszClassName = progname; |
761 | wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | 761 | wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION); |
762 | 762 | ||
763 | RegisterClassEx(&wndclass); | 763 | RegisterClassEx(&wndclass); |
764 | 764 | ||
765 | /*--------------------------------------------------------------------------- | 765 | /*--------------------------------------------------------------------------- |
766 | Finally, create the window. | 766 | Finally, create the window. |
767 | ---------------------------------------------------------------------------*/ | 767 | ---------------------------------------------------------------------------*/ |
768 | 768 | ||
769 | extra_width = 2*(GetSystemMetrics(SM_CXBORDER) + | 769 | extra_width = 2*(GetSystemMetrics(SM_CXBORDER) + |
770 | GetSystemMetrics(SM_CXDLGFRAME)); | 770 | GetSystemMetrics(SM_CXDLGFRAME)); |
771 | extra_height = 2*(GetSystemMetrics(SM_CYBORDER) + | 771 | extra_height = 2*(GetSystemMetrics(SM_CYBORDER) + |
772 | GetSystemMetrics(SM_CYDLGFRAME)) + | 772 | GetSystemMetrics(SM_CYDLGFRAME)) + |
773 | GetSystemMetrics(SM_CYCAPTION); | 773 | GetSystemMetrics(SM_CYCAPTION); |
774 | 774 | ||
775 | global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW, | 775 | global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW, |
776 | CW_USEDEFAULT, CW_USEDEFAULT, rpng2_info.width+extra_width, | 776 | CW_USEDEFAULT, CW_USEDEFAULT, rpng2_info.width+extra_width, |
777 | rpng2_info.height+extra_height, NULL, NULL, global_hInst, NULL); | 777 | rpng2_info.height+extra_height, NULL, NULL, global_hInst, NULL); |
778 | 778 | ||
779 | ShowWindow(global_hwnd, global_showmode); | 779 | ShowWindow(global_hwnd, global_showmode); |
780 | UpdateWindow(global_hwnd); | 780 | UpdateWindow(global_hwnd); |
781 | 781 | ||
782 | /*--------------------------------------------------------------------------- | 782 | /*--------------------------------------------------------------------------- |
783 | Now compute the background image and display it. If it fails (memory | 783 | Now compute the background image and display it. If it fails (memory |
784 | allocation), revert to a plain background color. | 784 | allocation), revert to a plain background color. |
785 | ---------------------------------------------------------------------------*/ | 785 | ---------------------------------------------------------------------------*/ |
786 | 786 | ||
787 | if (bg_image) { | 787 | if (bg_image) { |
788 | static const char *msg = "Computing background image..."; | 788 | static const char *msg = "Computing background image..."; |
789 | int x, y, len = strlen(msg); | 789 | int x, y, len = strlen(msg); |
790 | HDC hdc = GetDC(global_hwnd); | 790 | HDC hdc = GetDC(global_hwnd); |
791 | TEXTMETRIC tm; | 791 | TEXTMETRIC tm; |
792 | 792 | ||
793 | GetTextMetrics(hdc, &tm); | 793 | GetTextMetrics(hdc, &tm); |
794 | x = (rpng2_info.width - len*tm.tmAveCharWidth)/2; | 794 | x = (rpng2_info.width - len*tm.tmAveCharWidth)/2; |
795 | y = (rpng2_info.height - tm.tmHeight)/2; | 795 | y = (rpng2_info.height - tm.tmHeight)/2; |
796 | SetBkMode(hdc, TRANSPARENT); | 796 | SetBkMode(hdc, TRANSPARENT); |
797 | SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); | 797 | SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT)); |
798 | /* this can still begin out of bounds even if x is positive (???): */ | 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); | 799 | TextOut(hdc, ((x < 0)? 0 : x), ((y < 0)? 0 : y), msg, len); |
800 | ReleaseDC(global_hwnd, hdc); | 800 | ReleaseDC(global_hwnd, hdc); |
801 | 801 | ||
802 | rpng2_win_load_bg_image(); /* resets bg_image if fails */ | 802 | rpng2_win_load_bg_image(); /* resets bg_image if fails */ |
803 | } | 803 | } |
804 | 804 | ||
805 | if (!bg_image) { | 805 | if (!bg_image) { |
806 | for (j = 0; j < rpng2_info.height; ++j) { | 806 | for (j = 0; j < rpng2_info.height; ++j) { |
807 | dest = wimage_data + j*wimage_rowbytes; | 807 | dest = wimage_data + j*wimage_rowbytes; |
808 | for (i = rpng2_info.width; i > 0; --i) { | 808 | for (i = rpng2_info.width; i > 0; --i) { |
809 | *dest++ = bg_blue; | 809 | *dest++ = bg_blue; |
810 | *dest++ = bg_green; | 810 | *dest++ = bg_green; |
811 | *dest++ = bg_red; | 811 | *dest++ = bg_red; |
812 | } | 812 | } |
813 | } | 813 | } |
814 | } | 814 | } |
815 | 815 | ||
816 | rect.left = 0L; | 816 | rect.left = 0L; |
817 | rect.top = 0L; | 817 | rect.top = 0L; |
818 | rect.right = (LONG)rpng2_info.width; /* possibly off by one? */ | 818 | rect.right = (LONG)rpng2_info.width; /* possibly off by one? */ |
819 | rect.bottom = (LONG)rpng2_info.height; /* possibly off by one? */ | 819 | rect.bottom = (LONG)rpng2_info.height; /* possibly off by one? */ |
820 | InvalidateRect(global_hwnd, &rect, FALSE); | 820 | InvalidateRect(global_hwnd, &rect, FALSE); |
821 | UpdateWindow(global_hwnd); /* similar to XFlush() */ | 821 | UpdateWindow(global_hwnd); /* similar to XFlush() */ |
822 | 822 | ||
823 | return 0; | 823 | return 0; |
824 | 824 | ||
825 | } /* end function rpng2_win_create_window() */ | 825 | } /* end function rpng2_win_create_window() */ |
826 | 826 | ||
827 | 827 | ||
828 | 828 | ||
829 | 829 | ||
830 | 830 | ||
831 | static int rpng2_win_load_bg_image() | 831 | static int rpng2_win_load_bg_image() |
832 | { | 832 | { |
833 | uch *src, *dest; | 833 | uch *src, *dest; |
834 | uch r1, r2, g1, g2, b1, b2; | 834 | uch r1, r2, g1, g2, b1, b2; |
835 | uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; | 835 | uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; |
836 | int k, hmax, max; | 836 | int k, hmax, max; |
837 | int xidx, yidx, yidx_max = (bgscale-1); | 837 | int xidx, yidx, yidx_max = (bgscale-1); |
838 | int even_odd_vert, even_odd_horiz, even_odd; | 838 | int even_odd_vert, even_odd_horiz, even_odd; |
839 | int invert_gradient2 = (bg[pat].type & 0x08); | 839 | int invert_gradient2 = (bg[pat].type & 0x08); |
840 | int invert_column; | 840 | int invert_column; |
841 | ulg i, row; | 841 | ulg i, row; |
842 | 842 | ||
843 | /*--------------------------------------------------------------------------- | 843 | /*--------------------------------------------------------------------------- |
844 | Allocate buffer for fake background image to be used with transparent | 844 | Allocate buffer for fake background image to be used with transparent |
845 | images; if this fails, revert to plain background color. | 845 | images; if this fails, revert to plain background color. |
846 | ---------------------------------------------------------------------------*/ | 846 | ---------------------------------------------------------------------------*/ |
847 | 847 | ||
848 | bg_rowbytes = 3 * rpng2_info.width; | 848 | bg_rowbytes = 3 * rpng2_info.width; |
849 | bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height); | 849 | bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height); |
850 | if (!bg_data) { | 850 | if (!bg_data) { |
851 | fprintf(stderr, PROGNAME | 851 | fprintf(stderr, PROGNAME |
852 | ": unable to allocate memory for background image\n"); | 852 | ": unable to allocate memory for background image\n"); |
853 | bg_image = 0; | 853 | bg_image = 0; |
854 | return 1; | 854 | return 1; |
855 | } | 855 | } |
856 | 856 | ||
857 | /*--------------------------------------------------------------------------- | 857 | /*--------------------------------------------------------------------------- |
858 | Vertical gradients (ramps) in NxN squares, alternating direction and | 858 | Vertical gradients (ramps) in NxN squares, alternating direction and |
859 | colors (N == bgscale). | 859 | colors (N == bgscale). |
860 | ---------------------------------------------------------------------------*/ | 860 | ---------------------------------------------------------------------------*/ |
861 | 861 | ||
862 | if ((bg[pat].type & 0x07) == 0) { | 862 | if ((bg[pat].type & 0x07) == 0) { |
863 | uch r1_min = rgb[bg[pat].rgb1_min].r; | 863 | uch r1_min = rgb[bg[pat].rgb1_min].r; |
864 | uch g1_min = rgb[bg[pat].rgb1_min].g; | 864 | uch g1_min = rgb[bg[pat].rgb1_min].g; |
865 | uch b1_min = rgb[bg[pat].rgb1_min].b; | 865 | uch b1_min = rgb[bg[pat].rgb1_min].b; |
866 | uch r2_min = rgb[bg[pat].rgb2_min].r; | 866 | uch r2_min = rgb[bg[pat].rgb2_min].r; |
867 | uch g2_min = rgb[bg[pat].rgb2_min].g; | 867 | uch g2_min = rgb[bg[pat].rgb2_min].g; |
868 | uch b2_min = rgb[bg[pat].rgb2_min].b; | 868 | uch b2_min = rgb[bg[pat].rgb2_min].b; |
869 | int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; | 869 | int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; |
870 | int g1_diff = rgb[bg[pat].rgb1_max].g - g1_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; | 871 | int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; |
872 | int r2_diff = rgb[bg[pat].rgb2_max].r - r2_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; | 873 | int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; |
874 | int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; | 874 | int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; |
875 | 875 | ||
876 | for (row = 0; row < rpng2_info.height; ++row) { | 876 | for (row = 0; row < rpng2_info.height; ++row) { |
877 | yidx = row % bgscale; | 877 | yidx = row % bgscale; |
878 | even_odd_vert = (row / bgscale) & 1; | 878 | even_odd_vert = (row / bgscale) & 1; |
879 | 879 | ||
880 | r1 = r1_min + (r1_diff * yidx) / yidx_max; | 880 | r1 = r1_min + (r1_diff * yidx) / yidx_max; |
881 | g1 = g1_min + (g1_diff * yidx) / yidx_max; | 881 | g1 = g1_min + (g1_diff * yidx) / yidx_max; |
882 | b1 = b1_min + (b1_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; | 883 | r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; |
884 | g1_inv = g1_min + (g1_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; | 885 | b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; |
886 | 886 | ||
887 | r2 = r2_min + (r2_diff * yidx) / yidx_max; | 887 | r2 = r2_min + (r2_diff * yidx) / yidx_max; |
888 | g2 = g2_min + (g2_diff * yidx) / yidx_max; | 888 | g2 = g2_min + (g2_diff * yidx) / yidx_max; |
889 | b2 = b2_min + (b2_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; | 890 | r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; |
891 | g2_inv = g2_min + (g2_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; | 892 | b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; |
893 | 893 | ||
894 | dest = bg_data + row*bg_rowbytes; | 894 | dest = bg_data + row*bg_rowbytes; |
895 | for (i = 0; i < rpng2_info.width; ++i) { | 895 | for (i = 0; i < rpng2_info.width; ++i) { |
896 | even_odd_horiz = (i / bgscale) & 1; | 896 | even_odd_horiz = (i / bgscale) & 1; |
897 | even_odd = even_odd_vert ^ even_odd_horiz; | 897 | even_odd = even_odd_vert ^ even_odd_horiz; |
898 | invert_column = | 898 | invert_column = |
899 | (even_odd_horiz && (bg[pat].type & 0x10)); | 899 | (even_odd_horiz && (bg[pat].type & 0x10)); |
900 | if (even_odd == 0) { /* gradient #1 */ | 900 | if (even_odd == 0) { /* gradient #1 */ |
901 | if (invert_column) { | 901 | if (invert_column) { |
902 | *dest++ = r1_inv; | 902 | *dest++ = r1_inv; |
903 | *dest++ = g1_inv; | 903 | *dest++ = g1_inv; |
904 | *dest++ = b1_inv; | 904 | *dest++ = b1_inv; |
905 | } else { | 905 | } else { |
906 | *dest++ = r1; | 906 | *dest++ = r1; |
907 | *dest++ = g1; | 907 | *dest++ = g1; |
908 | *dest++ = b1; | 908 | *dest++ = b1; |
909 | } | 909 | } |
910 | } else { /* gradient #2 */ | 910 | } else { /* gradient #2 */ |
911 | if ((invert_column && invert_gradient2) || | 911 | if ((invert_column && invert_gradient2) || |
912 | (!invert_column && !invert_gradient2)) | 912 | (!invert_column && !invert_gradient2)) |
913 | { | 913 | { |
914 | *dest++ = r2; /* not inverted or */ | 914 | *dest++ = r2; /* not inverted or */ |
915 | *dest++ = g2; /* doubly inverted */ | 915 | *dest++ = g2; /* doubly inverted */ |
916 | *dest++ = b2; | 916 | *dest++ = b2; |
917 | } else { | 917 | } else { |
918 | *dest++ = r2_inv; | 918 | *dest++ = r2_inv; |
919 | *dest++ = g2_inv; /* singly inverted */ | 919 | *dest++ = g2_inv; /* singly inverted */ |
920 | *dest++ = b2_inv; | 920 | *dest++ = b2_inv; |
921 | } | 921 | } |
922 | } | 922 | } |
923 | } | 923 | } |
924 | } | 924 | } |
925 | 925 | ||
926 | /*--------------------------------------------------------------------------- | 926 | /*--------------------------------------------------------------------------- |
927 | Soft gradient-diamonds with scale = bgscale. Code contributed by Adam | 927 | Soft gradient-diamonds with scale = bgscale. Code contributed by Adam |
928 | M. Costello. | 928 | M. Costello. |
929 | ---------------------------------------------------------------------------*/ | 929 | ---------------------------------------------------------------------------*/ |
930 | 930 | ||
931 | } else if ((bg[pat].type & 0x07) == 1) { | 931 | } else if ((bg[pat].type & 0x07) == 1) { |
932 | 932 | ||
933 | hmax = (bgscale-1)/2; /* half the max weight of a color */ | 933 | hmax = (bgscale-1)/2; /* half the max weight of a color */ |
934 | max = 2*hmax; /* the max weight of a color */ | 934 | max = 2*hmax; /* the max weight of a color */ |
935 | 935 | ||
936 | r1 = rgb[bg[pat].rgb1_max].r; | 936 | r1 = rgb[bg[pat].rgb1_max].r; |
937 | g1 = rgb[bg[pat].rgb1_max].g; | 937 | g1 = rgb[bg[pat].rgb1_max].g; |
938 | b1 = rgb[bg[pat].rgb1_max].b; | 938 | b1 = rgb[bg[pat].rgb1_max].b; |
939 | r2 = rgb[bg[pat].rgb2_max].r; | 939 | r2 = rgb[bg[pat].rgb2_max].r; |
940 | g2 = rgb[bg[pat].rgb2_max].g; | 940 | g2 = rgb[bg[pat].rgb2_max].g; |
941 | b2 = rgb[bg[pat].rgb2_max].b; | 941 | b2 = rgb[bg[pat].rgb2_max].b; |
942 | 942 | ||
943 | for (row = 0; row < rpng2_info.height; ++row) { | 943 | for (row = 0; row < rpng2_info.height; ++row) { |
944 | yidx = row % bgscale; | 944 | yidx = row % bgscale; |
945 | if (yidx > hmax) | 945 | if (yidx > hmax) |
946 | yidx = bgscale-1 - yidx; | 946 | yidx = bgscale-1 - yidx; |
947 | dest = bg_data + row*bg_rowbytes; | 947 | dest = bg_data + row*bg_rowbytes; |
948 | for (i = 0; i < rpng2_info.width; ++i) { | 948 | for (i = 0; i < rpng2_info.width; ++i) { |
949 | xidx = i % bgscale; | 949 | xidx = i % bgscale; |
950 | if (xidx > hmax) | 950 | if (xidx > hmax) |
951 | xidx = bgscale-1 - xidx; | 951 | xidx = bgscale-1 - xidx; |
952 | k = xidx + yidx; | 952 | k = xidx + yidx; |
953 | *dest++ = (k*r1 + (max-k)*r2) / max; | 953 | *dest++ = (k*r1 + (max-k)*r2) / max; |
954 | *dest++ = (k*g1 + (max-k)*g2) / max; | 954 | *dest++ = (k*g1 + (max-k)*g2) / max; |
955 | *dest++ = (k*b1 + (max-k)*b2) / max; | 955 | *dest++ = (k*b1 + (max-k)*b2) / max; |
956 | } | 956 | } |
957 | } | 957 | } |
958 | 958 | ||
959 | /*--------------------------------------------------------------------------- | 959 | /*--------------------------------------------------------------------------- |
960 | Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- | 960 | Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- |
961 | soids will equal bgscale?]. This one is slow but very cool. Code con- | 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). | 962 | tributed by Pieter S. van der Meulen (originally in Smalltalk). |
963 | ---------------------------------------------------------------------------*/ | 963 | ---------------------------------------------------------------------------*/ |
964 | 964 | ||
965 | } else if ((bg[pat].type & 0x07) == 2) { | 965 | } else if ((bg[pat].type & 0x07) == 2) { |
966 | uch ch; | 966 | uch ch; |
967 | int ii, x, y, hw, hh, grayspot; | 967 | int ii, x, y, hw, hh, grayspot; |
968 | double freq, rotate, saturate, gray, intensity; | 968 | double freq, rotate, saturate, gray, intensity; |
969 | double angle=0.0, aoffset=0.0, maxDist, dist; | 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; | 970 | double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; |
971 | 971 | ||
972 | fprintf(stderr, "%s: computing radial background...", | 972 | fprintf(stderr, "%s: computing radial background...", |
973 | PROGNAME); | 973 | PROGNAME); |
974 | fflush(stderr); | 974 | fflush(stderr); |
975 | 975 | ||
976 | hh = rpng2_info.height / 2; | 976 | hh = rpng2_info.height / 2; |
977 | hw = rpng2_info.width / 2; | 977 | hw = rpng2_info.width / 2; |
978 | 978 | ||
979 | /* variables for radial waves: | 979 | /* variables for radial waves: |
980 | * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] | 980 | * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] |
981 | * freq: number of color beams originating from the center | 981 | * freq: number of color beams originating from the center |
982 | * grayspot: size of the graying center area (anti-alias) | 982 | * grayspot: size of the graying center area (anti-alias) |
983 | * rotate: rotation of the beams as a function of radius | 983 | * rotate: rotation of the beams as a function of radius |
984 | * saturate: saturation of beams' shape azimuthally | 984 | * saturate: saturation of beams' shape azimuthally |
985 | */ | 985 | */ |
986 | angle = CLIP(angle, 0.0, 360.0); | 986 | angle = CLIP(angle, 0.0, 360.0); |
987 | grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); | 987 | grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); |
988 | freq = MAX((double)bg[pat].bg_freq, 0.0); | 988 | freq = MAX((double)bg[pat].bg_freq, 0.0); |
989 | saturate = (double)bg[pat].bg_bsat * 0.1; | 989 | saturate = (double)bg[pat].bg_bsat * 0.1; |
990 | rotate = (double)bg[pat].bg_brot * 0.1; | 990 | rotate = (double)bg[pat].bg_brot * 0.1; |
991 | gray = 0.0; | 991 | gray = 0.0; |
992 | intensity = 0.0; | 992 | intensity = 0.0; |
993 | maxDist = (double)((hw*hw) + (hh*hh)); | 993 | maxDist = (double)((hw*hw) + (hh*hh)); |
994 | 994 | ||
995 | for (row = 0; row < rpng2_info.height; ++row) { | 995 | for (row = 0; row < rpng2_info.height; ++row) { |
996 | y = row - hh; | 996 | y = row - hh; |
997 | dest = bg_data + row*bg_rowbytes; | 997 | dest = bg_data + row*bg_rowbytes; |
998 | for (i = 0; i < rpng2_info.width; ++i) { | 998 | for (i = 0; i < rpng2_info.width; ++i) { |
999 | x = i - hw; | 999 | x = i - hw; |
1000 | angle = (x == 0)? PI_2 : atan((double)y / (double)x); | 1000 | angle = (x == 0)? PI_2 : atan((double)y / (double)x); |
1001 | gray = (double)MAX(ABS(y), ABS(x)) / grayspot; | 1001 | gray = (double)MAX(ABS(y), ABS(x)) / grayspot; |
1002 | gray = MIN(1.0, gray); | 1002 | gray = MIN(1.0, gray); |
1003 | dist = (double)((x*x) + (y*y)) / maxDist; | 1003 | dist = (double)((x*x) + (y*y)) / maxDist; |
1004 | intensity = cos((angle+(rotate*dist*PI)) * freq) * | 1004 | intensity = cos((angle+(rotate*dist*PI)) * freq) * |
1005 | gray * saturate; | 1005 | gray * saturate; |
1006 | intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; | 1006 | intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; |
1007 | hue = (angle + PI) * INV_PI_360 + aoffset; | 1007 | hue = (angle + PI) * INV_PI_360 + aoffset; |
1008 | s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); | 1008 | s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); |
1009 | s = MIN(MAX(s,0.0), 1.0); | 1009 | s = MIN(MAX(s,0.0), 1.0); |
1010 | v = MIN(MAX(intensity,0.0), 1.0); | 1010 | v = MIN(MAX(intensity,0.0), 1.0); |
1011 | 1011 | ||
1012 | if (s == 0.0) { | 1012 | if (s == 0.0) { |
1013 | ch = (uch)(v * 255.0); | 1013 | ch = (uch)(v * 255.0); |
1014 | *dest++ = ch; | 1014 | *dest++ = ch; |
1015 | *dest++ = ch; | 1015 | *dest++ = ch; |
1016 | *dest++ = ch; | 1016 | *dest++ = ch; |
1017 | } else { | 1017 | } else { |
1018 | if ((hue < 0.0) || (hue >= 360.0)) | 1018 | if ((hue < 0.0) || (hue >= 360.0)) |
1019 | hue -= (((int)(hue / 360.0)) * 360.0); | 1019 | hue -= (((int)(hue / 360.0)) * 360.0); |
1020 | hue /= 60.0; | 1020 | hue /= 60.0; |
1021 | ii = (int)hue; | 1021 | ii = (int)hue; |
1022 | f = hue - (double)ii; | 1022 | f = hue - (double)ii; |
1023 | p = (1.0 - s) * v; | 1023 | p = (1.0 - s) * v; |
1024 | q = (1.0 - (s * f)) * v; | 1024 | q = (1.0 - (s * f)) * v; |
1025 | t = (1.0 - (s * (1.0 - f))) * v; | 1025 | t = (1.0 - (s * (1.0 - f))) * v; |
1026 | if (ii == 0) { red = v; green = t; blue = p; } | 1026 | if (ii == 0) { red = v; green = t; blue = p; } |
1027 | else if (ii == 1) { red = q; green = v; blue = p; } | 1027 | else if (ii == 1) { red = q; green = v; blue = p; } |
1028 | else if (ii == 2) { red = p; green = v; blue = t; } | 1028 | else if (ii == 2) { red = p; green = v; blue = t; } |
1029 | else if (ii == 3) { red = p; green = q; blue = v; } | 1029 | else if (ii == 3) { red = p; green = q; blue = v; } |
1030 | else if (ii == 4) { red = t; green = p; blue = v; } | 1030 | else if (ii == 4) { red = t; green = p; blue = v; } |
1031 | else if (ii == 5) { red = v; green = p; blue = q; } | 1031 | else if (ii == 5) { red = v; green = p; blue = q; } |
1032 | *dest++ = (uch)(red * 255.0); | 1032 | *dest++ = (uch)(red * 255.0); |
1033 | *dest++ = (uch)(green * 255.0); | 1033 | *dest++ = (uch)(green * 255.0); |
1034 | *dest++ = (uch)(blue * 255.0); | 1034 | *dest++ = (uch)(blue * 255.0); |
1035 | } | 1035 | } |
1036 | } | 1036 | } |
1037 | } | 1037 | } |
1038 | fprintf(stderr, "done.\n"); | 1038 | fprintf(stderr, "done.\n"); |
1039 | fflush(stderr); | 1039 | fflush(stderr); |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | /*--------------------------------------------------------------------------- | 1042 | /*--------------------------------------------------------------------------- |
1043 | Blast background image to display buffer before beginning PNG decode; | 1043 | Blast background image to display buffer before beginning PNG decode; |
1044 | calling function will handle invalidation and UpdateWindow() call. | 1044 | calling function will handle invalidation and UpdateWindow() call. |
1045 | ---------------------------------------------------------------------------*/ | 1045 | ---------------------------------------------------------------------------*/ |
1046 | 1046 | ||
1047 | for (row = 0; row < rpng2_info.height; ++row) { | 1047 | for (row = 0; row < rpng2_info.height; ++row) { |
1048 | src = bg_data + row*bg_rowbytes; | 1048 | src = bg_data + row*bg_rowbytes; |
1049 | dest = wimage_data + row*wimage_rowbytes; | 1049 | dest = wimage_data + row*wimage_rowbytes; |
1050 | for (i = rpng2_info.width; i > 0; --i) { | 1050 | for (i = rpng2_info.width; i > 0; --i) { |
1051 | r1 = *src++; | 1051 | r1 = *src++; |
1052 | g1 = *src++; | 1052 | g1 = *src++; |
1053 | b1 = *src++; | 1053 | b1 = *src++; |
1054 | *dest++ = b1; | 1054 | *dest++ = b1; |
1055 | *dest++ = g1; /* note reverse order */ | 1055 | *dest++ = g1; /* note reverse order */ |
1056 | *dest++ = r1; | 1056 | *dest++ = r1; |
1057 | } | 1057 | } |
1058 | } | 1058 | } |
1059 | 1059 | ||
1060 | return 0; | 1060 | return 0; |
1061 | 1061 | ||
1062 | } /* end function rpng2_win_load_bg_image() */ | 1062 | } /* end function rpng2_win_load_bg_image() */ |
1063 | 1063 | ||
1064 | 1064 | ||
1065 | 1065 | ||
1066 | 1066 | ||
1067 | 1067 | ||
1068 | static void rpng2_win_display_row(ulg row) | 1068 | static void rpng2_win_display_row(ulg row) |
1069 | { | 1069 | { |
1070 | uch bg_red = rpng2_info.bg_red; | 1070 | uch bg_red = rpng2_info.bg_red; |
1071 | uch bg_green = rpng2_info.bg_green; | 1071 | uch bg_green = rpng2_info.bg_green; |
1072 | uch bg_blue = rpng2_info.bg_blue; | 1072 | uch bg_blue = rpng2_info.bg_blue; |
1073 | uch *src, *src2=NULL, *dest; | 1073 | uch *src, *src2=NULL, *dest; |
1074 | uch r, g, b, a; | 1074 | uch r, g, b, a; |
1075 | ulg i; | 1075 | ulg i; |
1076 | static int rows=0; | 1076 | static int rows=0; |
1077 | static ulg firstrow; | 1077 | static ulg firstrow; |
1078 | 1078 | ||
1079 | /*--------------------------------------------------------------------------- | 1079 | /*--------------------------------------------------------------------------- |
1080 | rows and firstrow simply track how many rows (and which ones) have not | 1080 | rows and firstrow simply track how many rows (and which ones) have not |
1081 | yet been displayed; alternatively, we could call InvalidateRect() for | 1081 | yet been displayed; alternatively, we could call InvalidateRect() for |
1082 | every row and not bother with the records-keeping. | 1082 | every row and not bother with the records-keeping. |
1083 | ---------------------------------------------------------------------------*/ | 1083 | ---------------------------------------------------------------------------*/ |
1084 | 1084 | ||
1085 | Trace((stderr, "beginning rpng2_win_display_row()\n")) | 1085 | Trace((stderr, "beginning rpng2_win_display_row()\n")) |
1086 | 1086 | ||
1087 | if (rows == 0) | 1087 | if (rows == 0) |
1088 | firstrow = row; /* first row not yet displayed */ | 1088 | firstrow = row; /* first row not yet displayed */ |
1089 | 1089 | ||
1090 | ++rows; /* count of rows received but not yet displayed */ | 1090 | ++rows; /* count of rows received but not yet displayed */ |
1091 | 1091 | ||
1092 | /*--------------------------------------------------------------------------- | 1092 | /*--------------------------------------------------------------------------- |
1093 | Aside from the use of the rpng2_info struct and the lack of an outer | 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() | 1094 | loop (over rows), this routine is identical to rpng_win_display_image() |
1095 | in the non-progressive version of the program. | 1095 | in the non-progressive version of the program. |
1096 | ---------------------------------------------------------------------------*/ | 1096 | ---------------------------------------------------------------------------*/ |
1097 | 1097 | ||
1098 | src = rpng2_info.image_data + row*rpng2_info.rowbytes; | 1098 | src = rpng2_info.image_data + row*rpng2_info.rowbytes; |
1099 | if (bg_image) | 1099 | if (bg_image) |
1100 | src2 = bg_data + row*bg_rowbytes; | 1100 | src2 = bg_data + row*bg_rowbytes; |
1101 | dest = wimage_data + row*wimage_rowbytes; | 1101 | dest = wimage_data + row*wimage_rowbytes; |
1102 | 1102 | ||
1103 | if (rpng2_info.channels == 3) { | 1103 | if (rpng2_info.channels == 3) { |
1104 | for (i = rpng2_info.width; i > 0; --i) { | 1104 | for (i = rpng2_info.width; i > 0; --i) { |
1105 | r = *src++; | 1105 | r = *src++; |
1106 | g = *src++; | 1106 | g = *src++; |
1107 | b = *src++; | 1107 | b = *src++; |
1108 | *dest++ = b; | 1108 | *dest++ = b; |
1109 | *dest++ = g; /* note reverse order */ | 1109 | *dest++ = g; /* note reverse order */ |
1110 | *dest++ = r; | 1110 | *dest++ = r; |
1111 | } | 1111 | } |
1112 | } else /* if (rpng2_info.channels == 4) */ { | 1112 | } else /* if (rpng2_info.channels == 4) */ { |
1113 | for (i = rpng2_info.width; i > 0; --i) { | 1113 | for (i = rpng2_info.width; i > 0; --i) { |
1114 | r = *src++; | 1114 | r = *src++; |
1115 | g = *src++; | 1115 | g = *src++; |
1116 | b = *src++; | 1116 | b = *src++; |
1117 | a = *src++; | 1117 | a = *src++; |
1118 | if (bg_image) { | 1118 | if (bg_image) { |
1119 | bg_red = *src2++; | 1119 | bg_red = *src2++; |
1120 | bg_green = *src2++; | 1120 | bg_green = *src2++; |
1121 | bg_blue = *src2++; | 1121 | bg_blue = *src2++; |
1122 | } | 1122 | } |
1123 | if (a == 255) { | 1123 | if (a == 255) { |
1124 | *dest++ = b; | 1124 | *dest++ = b; |
1125 | *dest++ = g; | 1125 | *dest++ = g; |
1126 | *dest++ = r; | 1126 | *dest++ = r; |
1127 | } else if (a == 0) { | 1127 | } else if (a == 0) { |
1128 | *dest++ = bg_blue; | 1128 | *dest++ = bg_blue; |
1129 | *dest++ = bg_green; | 1129 | *dest++ = bg_green; |
1130 | *dest++ = bg_red; | 1130 | *dest++ = bg_red; |
1131 | } else { | 1131 | } else { |
1132 | /* this macro (copied from png.h) composites the | 1132 | /* this macro (copied from png.h) composites the |
1133 | * foreground and background values and puts the | 1133 | * foreground and background values and puts the |
1134 | * result into the first argument; there are no | 1134 | * result into the first argument; there are no |
1135 | * side effects with the first argument */ | 1135 | * side effects with the first argument */ |
1136 | alpha_composite(*dest++, b, a, bg_blue); | 1136 | alpha_composite(*dest++, b, a, bg_blue); |
1137 | alpha_composite(*dest++, g, a, bg_green); | 1137 | alpha_composite(*dest++, g, a, bg_green); |
1138 | alpha_composite(*dest++, r, a, bg_red); | 1138 | alpha_composite(*dest++, r, a, bg_red); |
1139 | } | 1139 | } |
1140 | } | 1140 | } |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | /*--------------------------------------------------------------------------- | 1143 | /*--------------------------------------------------------------------------- |
1144 | Display after every 16 rows or when on last row. (Region may include | 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.) | 1145 | previously displayed lines due to interlacing--i.e., not contiguous.) |
1146 | ---------------------------------------------------------------------------*/ | 1146 | ---------------------------------------------------------------------------*/ |
1147 | 1147 | ||
1148 | if ((rows & 0xf) == 0 || row == rpng2_info.height-1) { | 1148 | if ((rows & 0xf) == 0 || row == rpng2_info.height-1) { |
1149 | RECT rect; | 1149 | RECT rect; |
1150 | 1150 | ||
1151 | rect.left = 0L; | 1151 | rect.left = 0L; |
1152 | rect.top = (LONG)firstrow; | 1152 | rect.top = (LONG)firstrow; |
1153 | rect.right = (LONG)rpng2_info.width; /* possibly off by one? */ | 1153 | rect.right = (LONG)rpng2_info.width; /* possibly off by one? */ |
1154 | rect.bottom = (LONG)row + 1L; /* possibly off by one? */ | 1154 | rect.bottom = (LONG)row + 1L; /* possibly off by one? */ |
1155 | InvalidateRect(global_hwnd, &rect, FALSE); | 1155 | InvalidateRect(global_hwnd, &rect, FALSE); |
1156 | UpdateWindow(global_hwnd); /* similar to XFlush() */ | 1156 | UpdateWindow(global_hwnd); /* similar to XFlush() */ |
1157 | rows = 0; | 1157 | rows = 0; |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | } /* end function rpng2_win_display_row() */ | 1160 | } /* end function rpng2_win_display_row() */ |
1161 | 1161 | ||
1162 | 1162 | ||
1163 | 1163 | ||
1164 | 1164 | ||
1165 | 1165 | ||
1166 | static void rpng2_win_finish_display() | 1166 | static void rpng2_win_finish_display() |
1167 | { | 1167 | { |
1168 | Trace((stderr, "beginning rpng2_win_finish_display()\n")) | 1168 | Trace((stderr, "beginning rpng2_win_finish_display()\n")) |
1169 | 1169 | ||
1170 | /* last row has already been displayed by rpng2_win_display_row(), so | 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 | 1171 | * we have nothing to do here except set a flag and let the user know |
1172 | * that the image is done */ | 1172 | * that the image is done */ |
1173 | 1173 | ||
1174 | rpng2_info.state = kDone; | 1174 | rpng2_info.state = kDone; |
1175 | printf( | 1175 | printf( |
1176 | #ifndef __CYGWIN__ | 1176 | #ifndef __CYGWIN__ |
1177 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n" | 1177 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n" |
1178 | #else | 1178 | #else |
1179 | "Done. Press mouse button 1 (within image window) to quit.\n" | 1179 | "Done. Press mouse button 1 (within image window) to quit.\n" |
1180 | #endif | 1180 | #endif |
1181 | ); | 1181 | ); |
1182 | fflush(stdout); | 1182 | fflush(stdout); |
1183 | } | 1183 | } |
1184 | 1184 | ||
1185 | 1185 | ||
1186 | 1186 | ||
1187 | 1187 | ||
1188 | 1188 | ||
1189 | static void rpng2_win_cleanup() | 1189 | static void rpng2_win_cleanup() |
1190 | { | 1190 | { |
1191 | if (bg_image && bg_data) { | 1191 | if (bg_image && bg_data) { |
1192 | free(bg_data); | 1192 | free(bg_data); |
1193 | bg_data = NULL; | 1193 | bg_data = NULL; |
1194 | } | 1194 | } |
1195 | 1195 | ||
1196 | if (rpng2_info.image_data) { | 1196 | if (rpng2_info.image_data) { |
1197 | free(rpng2_info.image_data); | 1197 | free(rpng2_info.image_data); |
1198 | rpng2_info.image_data = NULL; | 1198 | rpng2_info.image_data = NULL; |
1199 | } | 1199 | } |
1200 | 1200 | ||
1201 | if (rpng2_info.row_pointers) { | 1201 | if (rpng2_info.row_pointers) { |
1202 | free(rpng2_info.row_pointers); | 1202 | free(rpng2_info.row_pointers); |
1203 | rpng2_info.row_pointers = NULL; | 1203 | rpng2_info.row_pointers = NULL; |
1204 | } | 1204 | } |
1205 | 1205 | ||
1206 | if (dib) { | 1206 | if (dib) { |
1207 | free(dib); | 1207 | free(dib); |
1208 | dib = NULL; | 1208 | dib = NULL; |
1209 | } | 1209 | } |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | 1212 | ||
1213 | 1213 | ||
1214 | 1214 | ||
1215 | 1215 | ||
1216 | LRESULT CALLBACK rpng2_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP) | 1216 | LRESULT CALLBACK rpng2_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP) |
1217 | { | 1217 | { |
1218 | HDC hdc; | 1218 | HDC hdc; |
1219 | PAINTSTRUCT ps; | 1219 | PAINTSTRUCT ps; |
1220 | int rc; | 1220 | int rc; |
1221 | 1221 | ||
1222 | switch (iMsg) { | 1222 | switch (iMsg) { |
1223 | case WM_CREATE: | 1223 | case WM_CREATE: |
1224 | /* one-time processing here, if any */ | 1224 | /* one-time processing here, if any */ |
1225 | return 0; | 1225 | return 0; |
1226 | 1226 | ||
1227 | case WM_PAINT: | 1227 | case WM_PAINT: |
1228 | hdc = BeginPaint(hwnd, &ps); | 1228 | hdc = BeginPaint(hwnd, &ps); |
1229 | rc = StretchDIBits(hdc, 0, 0, rpng2_info.width, rpng2_info.height, | 1229 | rc = StretchDIBits(hdc, 0, 0, rpng2_info.width, rpng2_info.height, |
1230 | 0, 0, rpng2_info.width, rpng2_info.height, | 1230 | 0, 0, rpng2_info.width, rpng2_info.height, |
1231 | wimage_data, (BITMAPINFO *)bmih, | 1231 | wimage_data, (BITMAPINFO *)bmih, |
1232 | 0, SRCCOPY); | 1232 | 0, SRCCOPY); |
1233 | EndPaint(hwnd, &ps); | 1233 | EndPaint(hwnd, &ps); |
1234 | return 0; | 1234 | return 0; |
1235 | 1235 | ||
1236 | /* wait for the user to tell us when to quit */ | 1236 | /* wait for the user to tell us when to quit */ |
1237 | case WM_CHAR: | 1237 | case WM_CHAR: |
1238 | switch (wP) { /* only need one, so ignore repeat count */ | 1238 | switch (wP) { /* only need one, so ignore repeat count */ |
1239 | case 'q': | 1239 | case 'q': |
1240 | case 'Q': | 1240 | case 'Q': |
1241 | case 0x1B: /* Esc key */ | 1241 | case 0x1B: /* Esc key */ |
1242 | PostQuitMessage(0); | 1242 | PostQuitMessage(0); |
1243 | } | 1243 | } |
1244 | return 0; | 1244 | return 0; |
1245 | 1245 | ||
1246 | case WM_LBUTTONDOWN: /* another way of quitting */ | 1246 | case WM_LBUTTONDOWN: /* another way of quitting */ |
1247 | case WM_DESTROY: | 1247 | case WM_DESTROY: |
1248 | PostQuitMessage(0); | 1248 | PostQuitMessage(0); |
1249 | return 0; | 1249 | return 0; |
1250 | } | 1250 | } |
1251 | 1251 | ||
1252 | return DefWindowProc(hwnd, iMsg, wP, lP); | 1252 | return DefWindowProc(hwnd, iMsg, wP, lP); |
1253 | } | 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 index 6c687db..7f24b63 100644 --- 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 | |||
@@ -1,2107 +1,2107 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | rpng2 - progressive-model PNG display program rpng2-x.c | 3 | rpng2 - progressive-model PNG display program rpng2-x.c |
4 | 4 | ||
5 | This program decodes and displays PNG files progressively, as if it were | 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). | 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- | 7 | It supports gamma correction, user-specified background colors, and user- |
8 | specified background patterns (for transparent images). This version is | 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 | 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). | 10 | Zinser under OpenVMS; may work under OS/2 with a little tweaking). |
11 | 11 | ||
12 | Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond" | 12 | Thanks to Adam Costello and Pieter S. van der Meulen for the "diamond" |
13 | and "radial waves" patterns, respectively. | 13 | and "radial waves" patterns, respectively. |
14 | 14 | ||
15 | to do (someday, maybe): | 15 | to do (someday, maybe): |
16 | - fix expose/redraw code: don't draw entire row if only part exposed | 16 | - fix expose/redraw code: don't draw entire row if only part exposed |
17 | - 8-bit (colormapped) X support | 17 | - 8-bit (colormapped) X support |
18 | - finish resizable checkerboard-gradient (sizes 4-128?) | 18 | - finish resizable checkerboard-gradient (sizes 4-128?) |
19 | - use %.1023s to simplify truncation of title-bar string? | 19 | - use %.1023s to simplify truncation of title-bar string? |
20 | 20 | ||
21 | --------------------------------------------------------------------------- | 21 | --------------------------------------------------------------------------- |
22 | 22 | ||
23 | Changelog: | 23 | Changelog: |
24 | - 1.01: initial public release | 24 | - 1.01: initial public release |
25 | - 1.02: modified to allow abbreviated options; fixed char/uchar mismatch | 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 | 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 | 27 | - 1.11: added -usleep option for demos; fixed command-line parsing bug |
28 | - 1.12: added -pause option for demos and testing | 28 | - 1.12: added -pause option for demos and testing |
29 | - 1.20: added runtime MMX-enabling/disabling and new -mmx* options | 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) | 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) | 31 | - 1.22: fixed XFreeGC() crash bug (thanks to Patrick Welche) |
32 | - 1.23: added -bgpat 0 mode (std white/gray checkerboard, 8x8 squares) | 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 = | 33 | - 1.30: added -loop option for -bgpat (ifdef FEATURE_LOOP); fixed bpp = |
34 | 24; added support for X resources (thanks to Gerhard Niklasch) | 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) | 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 | 36 | - 1.32: added AMD64/EM64T support (__x86_64__); added basic expose/redraw |
37 | handling | 37 | handling |
38 | - 2.00: dual-licensed (added GNU GPL) | 38 | - 2.00: dual-licensed (added GNU GPL) |
39 | - 2.01: fixed 64-bit typo in readpng2.c; fixed -pause usage description | 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 | 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- | 41 | unexpected-EOF and file-read-error cases; fixed Trace() cut-and- |
42 | paste bugs | 42 | paste bugs |
43 | - 2.03: deleted runtime MMX-enabling/disabling and obsolete -mmx* options | 43 | - 2.03: deleted runtime MMX-enabling/disabling and obsolete -mmx* options |
44 | 44 | ||
45 | --------------------------------------------------------------------------- | 45 | --------------------------------------------------------------------------- |
46 | 46 | ||
47 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. | 47 | Copyright (c) 1998-2008 Greg Roelofs. All rights reserved. |
48 | 48 | ||
49 | This software is provided "as is," without warranty of any kind, | 49 | This software is provided "as is," without warranty of any kind, |
50 | express or implied. In no event shall the author or contributors | 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 | 51 | be held liable for any damages arising in any way from the use of |
52 | this software. | 52 | this software. |
53 | 53 | ||
54 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 55 | redistribute this software according to the terms of one of the |
56 | following two licenses (at your option): | 56 | following two licenses (at your option): |
57 | 57 | ||
58 | 58 | ||
59 | LICENSE 1 ("BSD-like with advertising clause"): | 59 | LICENSE 1 ("BSD-like with advertising clause"): |
60 | 60 | ||
61 | Permission is granted to anyone to use this software for any purpose, | 61 | Permission is granted to anyone to use this software for any purpose, |
62 | including commercial applications, and to alter it and redistribute | 62 | including commercial applications, and to alter it and redistribute |
63 | it freely, subject to the following restrictions: | 63 | it freely, subject to the following restrictions: |
64 | 64 | ||
65 | 1. Redistributions of source code must retain the above copyright | 65 | 1. Redistributions of source code must retain the above copyright |
66 | notice, disclaimer, and this list of conditions. | 66 | notice, disclaimer, and this list of conditions. |
67 | 2. Redistributions in binary form must reproduce the above copyright | 67 | 2. Redistributions in binary form must reproduce the above copyright |
68 | notice, disclaimer, and this list of conditions in the documenta- | 68 | notice, disclaimer, and this list of conditions in the documenta- |
69 | tion and/or other materials provided with the distribution. | 69 | tion and/or other materials provided with the distribution. |
70 | 3. All advertising materials mentioning features or use of this | 70 | 3. All advertising materials mentioning features or use of this |
71 | software must display the following acknowledgment: | 71 | software must display the following acknowledgment: |
72 | 72 | ||
73 | This product includes software developed by Greg Roelofs | 73 | This product includes software developed by Greg Roelofs |
74 | and contributors for the book, "PNG: The Definitive Guide," | 74 | and contributors for the book, "PNG: The Definitive Guide," |
75 | published by O'Reilly and Associates. | 75 | published by O'Reilly and Associates. |
76 | 76 | ||
77 | 77 | ||
78 | LICENSE 2 (GNU GPL v2 or later): | 78 | LICENSE 2 (GNU GPL v2 or later): |
79 | 79 | ||
80 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 82 | the Free Software Foundation; either version 2 of the License, or |
83 | (at your option) any later version. | 83 | (at your option) any later version. |
84 | 84 | ||
85 | This program is distributed in the hope that it will be useful, | 85 | This program is distributed in the hope that it will be useful, |
86 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 86 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
87 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 87 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
88 | GNU General Public License for more details. | 88 | GNU General Public License for more details. |
89 | 89 | ||
90 | You should have received a copy of the GNU General Public License | 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, | 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 | 92 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
93 | 93 | ||
94 | ---------------------------------------------------------------------------*/ | 94 | ---------------------------------------------------------------------------*/ |
95 | 95 | ||
96 | #define PROGNAME "rpng2-x" | 96 | #define PROGNAME "rpng2-x" |
97 | #define LONGNAME "Progressive PNG Viewer for X" | 97 | #define LONGNAME "Progressive PNG Viewer for X" |
98 | #define VERSION "2.03 of 25 February 2010" | 98 | #define VERSION "2.03 of 25 February 2010" |
99 | #define RESNAME "rpng2" /* our X resource application name */ | 99 | #define RESNAME "rpng2" /* our X resource application name */ |
100 | #define RESCLASS "Rpng" /* our X resource class name */ | 100 | #define RESCLASS "Rpng" /* our X resource class name */ |
101 | 101 | ||
102 | #include <stdio.h> | 102 | #include <stdio.h> |
103 | #include <stdlib.h> | 103 | #include <stdlib.h> |
104 | #include <ctype.h> | 104 | #include <ctype.h> |
105 | #include <string.h> | 105 | #include <string.h> |
106 | #include <setjmp.h> /* for jmpbuf declaration in readpng2.h */ | 106 | #include <setjmp.h> /* for jmpbuf declaration in readpng2.h */ |
107 | #include <time.h> | 107 | #include <time.h> |
108 | #include <math.h> /* only for PvdM background code */ | 108 | #include <math.h> /* only for PvdM background code */ |
109 | #include <X11/Xlib.h> | 109 | #include <X11/Xlib.h> |
110 | #include <X11/Xutil.h> | 110 | #include <X11/Xutil.h> |
111 | #include <X11/Xos.h> | 111 | #include <X11/Xos.h> |
112 | #include <X11/keysym.h> /* defines XK_* macros */ | 112 | #include <X11/keysym.h> /* defines XK_* macros */ |
113 | 113 | ||
114 | #ifdef VMS | 114 | #ifdef VMS |
115 | # include <unistd.h> | 115 | # include <unistd.h> |
116 | #endif | 116 | #endif |
117 | 117 | ||
118 | /* all for PvdM background code: */ | 118 | /* all for PvdM background code: */ |
119 | #ifndef PI | 119 | #ifndef PI |
120 | # define PI 3.141592653589793238 | 120 | # define PI 3.141592653589793238 |
121 | #endif | 121 | #endif |
122 | #define PI_2 (PI*0.5) | 122 | #define PI_2 (PI*0.5) |
123 | #define INV_PI_360 (360.0 / PI) | 123 | #define INV_PI_360 (360.0 / PI) |
124 | #define MAX(a,b) (a>b?a:b) | 124 | #define MAX(a,b) (a>b?a:b) |
125 | #define MIN(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)) | 126 | #define CLIP(a,min,max) MAX(min,MIN((a),max)) |
127 | #define ABS(a) ((a)<0?-(a):(a)) | 127 | #define ABS(a) ((a)<0?-(a):(a)) |
128 | #define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */ | 128 | #define CLIP8P(c) MAX(0,(MIN((c),255))) /* 8-bit pos. integer (uch) */ |
129 | #define ROUNDF(f) ((int)(f + 0.5)) | 129 | #define ROUNDF(f) ((int)(f + 0.5)) |
130 | 130 | ||
131 | #define QUIT(e,k) ((e.type == ButtonPress && e.xbutton.button == Button1) || \ | 131 | #define QUIT(e,k) ((e.type == ButtonPress && e.xbutton.button == Button1) || \ |
132 | (e.type == KeyPress && /* v--- or 1 for shifted keys */ \ | 132 | (e.type == KeyPress && /* v--- or 1 for shifted keys */ \ |
133 | ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape))) | 133 | ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape))) |
134 | 134 | ||
135 | #define NO_24BIT_MASKS /* undef case not fully written--only for redisplay() */ | 135 | #define NO_24BIT_MASKS /* undef case not fully written--only for redisplay() */ |
136 | 136 | ||
137 | #define rgb1_max bg_freq | 137 | #define rgb1_max bg_freq |
138 | #define rgb1_min bg_gray | 138 | #define rgb1_min bg_gray |
139 | #define rgb2_max bg_bsat | 139 | #define rgb2_max bg_bsat |
140 | #define rgb2_min bg_brot | 140 | #define rgb2_min bg_brot |
141 | 141 | ||
142 | /* #define DEBUG */ /* this enables the Trace() macros */ | 142 | /* #define DEBUG */ /* this enables the Trace() macros */ |
143 | 143 | ||
144 | #include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */ | 144 | #include "readpng2.h" /* typedefs, common macros, readpng2 prototypes */ |
145 | 145 | ||
146 | 146 | ||
147 | /* could just include png.h, but this macro is the only thing we need | 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 | 148 | * (name and typedefs changed to local versions); note that side effects |
149 | * only happen with alpha (which could easily be avoided with | 149 | * only happen with alpha (which could easily be avoided with |
150 | * "ush acopy = (alpha);") */ | 150 | * "ush acopy = (alpha);") */ |
151 | 151 | ||
152 | #define alpha_composite(composite, fg, alpha, bg) { \ | 152 | #define alpha_composite(composite, fg, alpha, bg) { \ |
153 | ush temp = ((ush)(fg)*(ush)(alpha) + \ | 153 | ush temp = ((ush)(fg)*(ush)(alpha) + \ |
154 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ | 154 | (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128); \ |
155 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ | 155 | (composite) = (uch)((temp + (temp >> 8)) >> 8); \ |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | #define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this | 159 | #define INBUFSIZE 4096 /* with pseudo-timing on (1 sec delay/block), this |
160 | * block size corresponds roughly to a download | 160 | * block size corresponds roughly to a download |
161 | * speed 10% faster than theoretical 33.6K maximum | 161 | * speed 10% faster than theoretical 33.6K maximum |
162 | * (assuming 8 data bits, 1 stop bit and no other | 162 | * (assuming 8 data bits, 1 stop bit and no other |
163 | * overhead) */ | 163 | * overhead) */ |
164 | 164 | ||
165 | /* local prototypes */ | 165 | /* local prototypes */ |
166 | static void rpng2_x_init (void); | 166 | static void rpng2_x_init (void); |
167 | static int rpng2_x_create_window (void); | 167 | static int rpng2_x_create_window (void); |
168 | static int rpng2_x_load_bg_image (void); | 168 | static int rpng2_x_load_bg_image (void); |
169 | static void rpng2_x_display_row (ulg row); | 169 | static void rpng2_x_display_row (ulg row); |
170 | static void rpng2_x_finish_display (void); | 170 | static void rpng2_x_finish_display (void); |
171 | static void rpng2_x_redisplay_image (ulg startcol, ulg startrow, | 171 | static void rpng2_x_redisplay_image (ulg startcol, ulg startrow, |
172 | ulg width, ulg height); | 172 | ulg width, ulg height); |
173 | #ifdef FEATURE_LOOP | 173 | #ifdef FEATURE_LOOP |
174 | static void rpng2_x_reload_bg_image (void); | 174 | static void rpng2_x_reload_bg_image (void); |
175 | static int is_number (char *p); | 175 | static int is_number (char *p); |
176 | #endif | 176 | #endif |
177 | static void rpng2_x_cleanup (void); | 177 | static void rpng2_x_cleanup (void); |
178 | static int rpng2_x_msb (ulg u32val); | 178 | static int rpng2_x_msb (ulg u32val); |
179 | 179 | ||
180 | 180 | ||
181 | static char titlebar[1024], *window_name = titlebar; | 181 | static char titlebar[1024], *window_name = titlebar; |
182 | static char *appname = LONGNAME; | 182 | static char *appname = LONGNAME; |
183 | static char *icon_name = PROGNAME; | 183 | static char *icon_name = PROGNAME; |
184 | static char *res_name = RESNAME; | 184 | static char *res_name = RESNAME; |
185 | static char *res_class = RESCLASS; | 185 | static char *res_class = RESCLASS; |
186 | static char *filename; | 186 | static char *filename; |
187 | static FILE *infile; | 187 | static FILE *infile; |
188 | 188 | ||
189 | static mainprog_info rpng2_info; | 189 | static mainprog_info rpng2_info; |
190 | 190 | ||
191 | static uch inbuf[INBUFSIZE]; | 191 | static uch inbuf[INBUFSIZE]; |
192 | static int incount; | 192 | static int incount; |
193 | 193 | ||
194 | static int pat = 6; /* must be less than num_bgpat */ | 194 | static int pat = 6; /* must be less than num_bgpat */ |
195 | static int bg_image = 0; | 195 | static int bg_image = 0; |
196 | static int bgscale, bgscale_default = 16; | 196 | static int bgscale, bgscale_default = 16; |
197 | static ulg bg_rowbytes; | 197 | static ulg bg_rowbytes; |
198 | static uch *bg_data; | 198 | static uch *bg_data; |
199 | 199 | ||
200 | int pause_after_pass = FALSE; | 200 | int pause_after_pass = FALSE; |
201 | int demo_timing = FALSE; | 201 | int demo_timing = FALSE; |
202 | ulg usleep_duration = 0L; | 202 | ulg usleep_duration = 0L; |
203 | 203 | ||
204 | static struct rgb_color { | 204 | static struct rgb_color { |
205 | uch r, g, b; | 205 | uch r, g, b; |
206 | } rgb[] = { | 206 | } rgb[] = { |
207 | { 0, 0, 0}, /* 0: black */ | 207 | { 0, 0, 0}, /* 0: black */ |
208 | {255, 255, 255}, /* 1: white */ | 208 | {255, 255, 255}, /* 1: white */ |
209 | {173, 132, 57}, /* 2: tan */ | 209 | {173, 132, 57}, /* 2: tan */ |
210 | { 64, 132, 0}, /* 3: medium green */ | 210 | { 64, 132, 0}, /* 3: medium green */ |
211 | {189, 117, 1}, /* 4: gold */ | 211 | {189, 117, 1}, /* 4: gold */ |
212 | {253, 249, 1}, /* 5: yellow */ | 212 | {253, 249, 1}, /* 5: yellow */ |
213 | { 0, 0, 255}, /* 6: blue */ | 213 | { 0, 0, 255}, /* 6: blue */ |
214 | { 0, 0, 120}, /* 7: medium blue */ | 214 | { 0, 0, 120}, /* 7: medium blue */ |
215 | {255, 0, 255}, /* 8: magenta */ | 215 | {255, 0, 255}, /* 8: magenta */ |
216 | { 64, 0, 64}, /* 9: dark magenta */ | 216 | { 64, 0, 64}, /* 9: dark magenta */ |
217 | {255, 0, 0}, /* 10: red */ | 217 | {255, 0, 0}, /* 10: red */ |
218 | { 64, 0, 0}, /* 11: dark red */ | 218 | { 64, 0, 0}, /* 11: dark red */ |
219 | {255, 127, 0}, /* 12: orange */ | 219 | {255, 127, 0}, /* 12: orange */ |
220 | {192, 96, 0}, /* 13: darker orange */ | 220 | {192, 96, 0}, /* 13: darker orange */ |
221 | { 24, 60, 0}, /* 14: dark green-yellow */ | 221 | { 24, 60, 0}, /* 14: dark green-yellow */ |
222 | { 85, 125, 200}, /* 15: ice blue */ | 222 | { 85, 125, 200}, /* 15: ice blue */ |
223 | {192, 192, 192} /* 16: Netscape/Mosaic gray */ | 223 | {192, 192, 192} /* 16: Netscape/Mosaic gray */ |
224 | }; | 224 | }; |
225 | /* not used for now, but should be for error-checking: | 225 | /* not used for now, but should be for error-checking: |
226 | static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); | 226 | static int num_rgb = sizeof(rgb) / sizeof(struct rgb_color); |
227 | */ | 227 | */ |
228 | 228 | ||
229 | /* | 229 | /* |
230 | This whole struct is a fairly cheesy way to keep the number of | 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 | 231 | command-line options to a minimum. The radial-waves background |
232 | type is a particularly poor fit to the integer elements of the | 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 | 233 | struct...but a few macros and a little fixed-point math will do |
234 | wonders for ya. | 234 | wonders for ya. |
235 | 235 | ||
236 | type bits: | 236 | type bits: |
237 | F E D C B A 9 8 7 6 5 4 3 2 1 0 | 237 | F E D C B A 9 8 7 6 5 4 3 2 1 0 |
238 | | | | | | | 238 | | | | | | |
239 | | | +-+-+-- 0 = sharp-edged checkerboard | 239 | | | +-+-+-- 0 = sharp-edged checkerboard |
240 | | | 1 = soft diamonds | 240 | | | 1 = soft diamonds |
241 | | | 2 = radial waves | 241 | | | 2 = radial waves |
242 | | | 3-7 = undefined | 242 | | | 3-7 = undefined |
243 | | +-- gradient #2 inverted? | 243 | | +-- gradient #2 inverted? |
244 | +-- alternating columns inverted? | 244 | +-- alternating columns inverted? |
245 | */ | 245 | */ |
246 | static struct background_pattern { | 246 | static struct background_pattern { |
247 | ush type; | 247 | ush type; |
248 | int rgb1_max, rgb1_min; /* or bg_freq, bg_gray */ | 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)*/ | 249 | int rgb2_max, rgb2_min; /* or bg_bsat, bg_brot (both scaled by 10)*/ |
250 | } bg[] = { | 250 | } bg[] = { |
251 | {0, 1,1, 16,16}, /* checkered: white vs. light gray (basic) */ | 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 */ | 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 */ | 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 */ | 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 */ | 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 */ | 256 | {0, 7,0, 8,9}, /* checkered: deep blue/black vs. magenta */ |
257 | {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */ | 257 | {0+8, 13,0, 5,14}, /* checkered: orange/black vs. yellow */ |
258 | {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */ | 258 | {0+8, 12,0, 10,11}, /* checkered: orange/black vs. red */ |
259 | {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */ | 259 | {1, 7,0, 8,0}, /* diamonds: deep blue/black vs. magenta */ |
260 | {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */ | 260 | {1, 12,0, 11,0}, /* diamonds: orange vs. dark red */ |
261 | {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */ | 261 | {1, 10,0, 7,0}, /* diamonds: red vs. medium blue */ |
262 | {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */ | 262 | {1, 4,0, 5,0}, /* diamonds: gold vs. yellow */ |
263 | {1, 3,0, 0,0}, /* diamonds: medium green vs. black */ | 263 | {1, 3,0, 0,0}, /* diamonds: medium green vs. black */ |
264 | {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */ | 264 | {2, 16, 100, 20, 0}, /* radial: ~hard radial color-beams */ |
265 | {2, 18, 100, 10, 2}, /* radial: soft, curved 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 */ | 266 | {2, 16, 256, 100, 250}, /* radial: very tight spiral */ |
267 | {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */ | 267 | {2, 10000, 256, 11, 0} /* radial: dipole-moire' (almost fractal) */ |
268 | }; | 268 | }; |
269 | static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern); | 269 | static int num_bgpat = sizeof(bg) / sizeof(struct background_pattern); |
270 | 270 | ||
271 | 271 | ||
272 | /* X-specific variables */ | 272 | /* X-specific variables */ |
273 | static char *displayname; | 273 | static char *displayname; |
274 | static XImage *ximage; | 274 | static XImage *ximage; |
275 | static Display *display; | 275 | static Display *display; |
276 | static int depth; | 276 | static int depth; |
277 | static Visual *visual; | 277 | static Visual *visual; |
278 | static XVisualInfo *visual_list; | 278 | static XVisualInfo *visual_list; |
279 | static int RShift, GShift, BShift; | 279 | static int RShift, GShift, BShift; |
280 | static ulg RMask, GMask, BMask; | 280 | static ulg RMask, GMask, BMask; |
281 | static Window window; | 281 | static Window window; |
282 | static GC gc; | 282 | static GC gc; |
283 | static Colormap colormap; | 283 | static Colormap colormap; |
284 | 284 | ||
285 | static int have_nondefault_visual = FALSE; | 285 | static int have_nondefault_visual = FALSE; |
286 | static int have_colormap = FALSE; | 286 | static int have_colormap = FALSE; |
287 | static int have_window = FALSE; | 287 | static int have_window = FALSE; |
288 | static int have_gc = FALSE; | 288 | static int have_gc = FALSE; |
289 | 289 | ||
290 | 290 | ||
291 | 291 | ||
292 | 292 | ||
293 | int main(int argc, char **argv) | 293 | int main(int argc, char **argv) |
294 | { | 294 | { |
295 | #ifdef sgi | 295 | #ifdef sgi |
296 | char tmpline[80]; | 296 | char tmpline[80]; |
297 | #endif | 297 | #endif |
298 | char *p, *bgstr = NULL; | 298 | char *p, *bgstr = NULL; |
299 | int rc, alen, flen; | 299 | int rc, alen, flen; |
300 | int error = 0; | 300 | int error = 0; |
301 | int timing = FALSE; | 301 | int timing = FALSE; |
302 | int have_bg = FALSE; | 302 | int have_bg = FALSE; |
303 | #ifdef FEATURE_LOOP | 303 | #ifdef FEATURE_LOOP |
304 | int loop = FALSE; | 304 | int loop = FALSE; |
305 | long loop_interval = -1; /* seconds (100,000 max) */ | 305 | long loop_interval = -1; /* seconds (100,000 max) */ |
306 | #endif | 306 | #endif |
307 | double LUT_exponent; /* just the lookup table */ | 307 | double LUT_exponent; /* just the lookup table */ |
308 | double CRT_exponent = 2.2; /* just the monitor */ | 308 | double CRT_exponent = 2.2; /* just the monitor */ |
309 | double default_display_exponent; /* whole display system */ | 309 | double default_display_exponent; /* whole display system */ |
310 | XEvent e; | 310 | XEvent e; |
311 | KeySym k; | 311 | KeySym k; |
312 | 312 | ||
313 | 313 | ||
314 | /* First initialize a few things, just to be sure--memset takes care of | 314 | /* First initialize a few things, just to be sure--memset takes care of |
315 | * default background color (black), booleans (FALSE), pointers (NULL), | 315 | * default background color (black), booleans (FALSE), pointers (NULL), |
316 | * etc. */ | 316 | * etc. */ |
317 | 317 | ||
318 | displayname = (char *)NULL; | 318 | displayname = (char *)NULL; |
319 | filename = (char *)NULL; | 319 | filename = (char *)NULL; |
320 | memset(&rpng2_info, 0, sizeof(mainprog_info)); | 320 | memset(&rpng2_info, 0, sizeof(mainprog_info)); |
321 | 321 | ||
322 | 322 | ||
323 | /* Set the default value for our display-system exponent, i.e., the | 323 | /* Set the default value for our display-system exponent, i.e., the |
324 | * product of the CRT exponent and the exponent corresponding to | 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 | 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 | 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. */ | 327 | * ones), but it should cover 99% of the current possibilities. */ |
328 | 328 | ||
329 | #if defined(NeXT) | 329 | #if defined(NeXT) |
330 | /* third-party utilities can modify the default LUT exponent */ | 330 | /* third-party utilities can modify the default LUT exponent */ |
331 | LUT_exponent = 1.0 / 2.2; | 331 | LUT_exponent = 1.0 / 2.2; |
332 | /* | 332 | /* |
333 | if (some_next_function_that_returns_gamma(&next_gamma)) | 333 | if (some_next_function_that_returns_gamma(&next_gamma)) |
334 | LUT_exponent = 1.0 / next_gamma; | 334 | LUT_exponent = 1.0 / next_gamma; |
335 | */ | 335 | */ |
336 | #elif defined(sgi) | 336 | #elif defined(sgi) |
337 | LUT_exponent = 1.0 / 1.7; | 337 | LUT_exponent = 1.0 / 1.7; |
338 | /* there doesn't seem to be any documented function to | 338 | /* there doesn't seem to be any documented function to |
339 | * get the "gamma" value, so we do it the hard way */ | 339 | * get the "gamma" value, so we do it the hard way */ |
340 | infile = fopen("/etc/config/system.glGammaVal", "r"); | 340 | infile = fopen("/etc/config/system.glGammaVal", "r"); |
341 | if (infile) { | 341 | if (infile) { |
342 | double sgi_gamma; | 342 | double sgi_gamma; |
343 | 343 | ||
344 | fgets(tmpline, 80, infile); | 344 | fgets(tmpline, 80, infile); |
345 | fclose(infile); | 345 | fclose(infile); |
346 | sgi_gamma = atof(tmpline); | 346 | sgi_gamma = atof(tmpline); |
347 | if (sgi_gamma > 0.0) | 347 | if (sgi_gamma > 0.0) |
348 | LUT_exponent = 1.0 / sgi_gamma; | 348 | LUT_exponent = 1.0 / sgi_gamma; |
349 | } | 349 | } |
350 | #elif defined(Macintosh) | 350 | #elif defined(Macintosh) |
351 | LUT_exponent = 1.8 / 2.61; | 351 | LUT_exponent = 1.8 / 2.61; |
352 | /* | 352 | /* |
353 | if (some_mac_function_that_returns_gamma(&mac_gamma)) | 353 | if (some_mac_function_that_returns_gamma(&mac_gamma)) |
354 | LUT_exponent = mac_gamma / 2.61; | 354 | LUT_exponent = mac_gamma / 2.61; |
355 | */ | 355 | */ |
356 | #else | 356 | #else |
357 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ | 357 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ |
358 | #endif | 358 | #endif |
359 | 359 | ||
360 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ | 360 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ |
361 | default_display_exponent = LUT_exponent * CRT_exponent; | 361 | default_display_exponent = LUT_exponent * CRT_exponent; |
362 | 362 | ||
363 | 363 | ||
364 | /* If the user has set the SCREEN_GAMMA environment variable as suggested | 364 | /* If the user has set the SCREEN_GAMMA environment variable as suggested |
365 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise | 365 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise |
366 | * use the default value we just calculated. Either way, the user may | 366 | * use the default value we just calculated. Either way, the user may |
367 | * override this via a command-line option. */ | 367 | * override this via a command-line option. */ |
368 | 368 | ||
369 | if ((p = getenv("SCREEN_GAMMA")) != NULL) | 369 | if ((p = getenv("SCREEN_GAMMA")) != NULL) |
370 | rpng2_info.display_exponent = atof(p); | 370 | rpng2_info.display_exponent = atof(p); |
371 | else | 371 | else |
372 | rpng2_info.display_exponent = default_display_exponent; | 372 | rpng2_info.display_exponent = default_display_exponent; |
373 | 373 | ||
374 | 374 | ||
375 | /* Now parse the command line for options and the PNG filename. */ | 375 | /* Now parse the command line for options and the PNG filename. */ |
376 | 376 | ||
377 | while (*++argv && !error) { | 377 | while (*++argv && !error) { |
378 | if (!strncmp(*argv, "-display", 2)) { | 378 | if (!strncmp(*argv, "-display", 2)) { |
379 | if (!*++argv) | 379 | if (!*++argv) |
380 | ++error; | 380 | ++error; |
381 | else | 381 | else |
382 | displayname = *argv; | 382 | displayname = *argv; |
383 | } else if (!strncmp(*argv, "-gamma", 2)) { | 383 | } else if (!strncmp(*argv, "-gamma", 2)) { |
384 | if (!*++argv) | 384 | if (!*++argv) |
385 | ++error; | 385 | ++error; |
386 | else { | 386 | else { |
387 | rpng2_info.display_exponent = atof(*argv); | 387 | rpng2_info.display_exponent = atof(*argv); |
388 | if (rpng2_info.display_exponent <= 0.0) | 388 | if (rpng2_info.display_exponent <= 0.0) |
389 | ++error; | 389 | ++error; |
390 | } | 390 | } |
391 | } else if (!strncmp(*argv, "-bgcolor", 4)) { | 391 | } else if (!strncmp(*argv, "-bgcolor", 4)) { |
392 | if (!*++argv) | 392 | if (!*++argv) |
393 | ++error; | 393 | ++error; |
394 | else { | 394 | else { |
395 | bgstr = *argv; | 395 | bgstr = *argv; |
396 | if (strlen(bgstr) != 7 || bgstr[0] != '#') | 396 | if (strlen(bgstr) != 7 || bgstr[0] != '#') |
397 | ++error; | 397 | ++error; |
398 | else { | 398 | else { |
399 | have_bg = TRUE; | 399 | have_bg = TRUE; |
400 | bg_image = FALSE; | 400 | bg_image = FALSE; |
401 | } | 401 | } |
402 | } | 402 | } |
403 | } else if (!strncmp(*argv, "-bgpat", 4)) { | 403 | } else if (!strncmp(*argv, "-bgpat", 4)) { |
404 | if (!*++argv) | 404 | if (!*++argv) |
405 | ++error; | 405 | ++error; |
406 | else { | 406 | else { |
407 | pat = atoi(*argv); | 407 | pat = atoi(*argv); |
408 | if (pat >= 0 && pat < num_bgpat) { | 408 | if (pat >= 0 && pat < num_bgpat) { |
409 | bg_image = TRUE; | 409 | bg_image = TRUE; |
410 | have_bg = FALSE; | 410 | have_bg = FALSE; |
411 | } else | 411 | } else |
412 | ++error; | 412 | ++error; |
413 | } | 413 | } |
414 | } else if (!strncmp(*argv, "-usleep", 2)) { | 414 | } else if (!strncmp(*argv, "-usleep", 2)) { |
415 | if (!*++argv) | 415 | if (!*++argv) |
416 | ++error; | 416 | ++error; |
417 | else { | 417 | else { |
418 | usleep_duration = (ulg)atol(*argv); | 418 | usleep_duration = (ulg)atol(*argv); |
419 | demo_timing = TRUE; | 419 | demo_timing = TRUE; |
420 | } | 420 | } |
421 | } else if (!strncmp(*argv, "-pause", 2)) { | 421 | } else if (!strncmp(*argv, "-pause", 2)) { |
422 | pause_after_pass = TRUE; | 422 | pause_after_pass = TRUE; |
423 | } else if (!strncmp(*argv, "-timing", 2)) { | 423 | } else if (!strncmp(*argv, "-timing", 2)) { |
424 | timing = TRUE; | 424 | timing = TRUE; |
425 | #ifdef FEATURE_LOOP | 425 | #ifdef FEATURE_LOOP |
426 | } else if (!strncmp(*argv, "-loop", 2)) { | 426 | } else if (!strncmp(*argv, "-loop", 2)) { |
427 | loop = TRUE; | 427 | loop = TRUE; |
428 | if (!argv[1] || !is_number(argv[1])) | 428 | if (!argv[1] || !is_number(argv[1])) |
429 | loop_interval = 2; | 429 | loop_interval = 2; |
430 | else { | 430 | else { |
431 | ++argv; | 431 | ++argv; |
432 | loop_interval = atol(*argv); | 432 | loop_interval = atol(*argv); |
433 | if (loop_interval < 0) | 433 | if (loop_interval < 0) |
434 | loop_interval = 2; | 434 | loop_interval = 2; |
435 | else if (loop_interval > 100000) /* bit more than one day */ | 435 | else if (loop_interval > 100000) /* bit more than one day */ |
436 | loop_interval = 100000; | 436 | loop_interval = 100000; |
437 | } | 437 | } |
438 | #endif | 438 | #endif |
439 | } else { | 439 | } else { |
440 | if (**argv != '-') { | 440 | if (**argv != '-') { |
441 | filename = *argv; | 441 | filename = *argv; |
442 | if (argv[1]) /* shouldn't be any more args after filename */ | 442 | if (argv[1]) /* shouldn't be any more args after filename */ |
443 | ++error; | 443 | ++error; |
444 | } else | 444 | } else |
445 | ++error; /* not expecting any other options */ | 445 | ++error; /* not expecting any other options */ |
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | if (!filename) | 449 | if (!filename) |
450 | ++error; | 450 | ++error; |
451 | 451 | ||
452 | 452 | ||
453 | /* print usage screen if any errors up to this point */ | 453 | /* print usage screen if any errors up to this point */ |
454 | 454 | ||
455 | if (error) { | 455 | if (error) { |
456 | fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); | 456 | fprintf(stderr, "\n%s %s: %s\n\n", PROGNAME, VERSION, appname); |
457 | readpng2_version_info(); | 457 | readpng2_version_info(); |
458 | fprintf(stderr, "\n" | 458 | fprintf(stderr, "\n" |
459 | "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n" | 459 | "Usage: %s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\n" |
460 | #ifdef FEATURE_LOOP | 460 | #ifdef FEATURE_LOOP |
461 | " %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n" | 461 | " %*s [-usleep dur | -timing] [-pause] [-loop [sec]] file.png\n\n" |
462 | #else | 462 | #else |
463 | " %*s [-usleep dur | -timing] [-pause] file.png\n\n" | 463 | " %*s [-usleep dur | -timing] [-pause] file.png\n\n" |
464 | #endif | 464 | #endif |
465 | " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" | 465 | " xdpy\tname of the target X display (e.g., ``hostname:0'')\n" |
466 | " exp \ttransfer-function exponent (``gamma'') of the display\n" | 466 | " exp \ttransfer-function exponent (``gamma'') of the display\n" |
467 | "\t\t system in floating-point format (e.g., ``%.1f''); equal\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" | 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" | 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" | 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" | 471 | "\t\t (e.g., ``#ff7700'' for orange: same as HTML colors);\n" |
472 | "\t\t used with transparent images; overrides -bgpat\n" | 472 | "\t\t used with transparent images; overrides -bgpat\n" |
473 | " pat \tdesired background pattern number (0-%d); used with\n" | 473 | " pat \tdesired background pattern number (0-%d); used with\n" |
474 | "\t\t transparent images; overrides -bgcolor\n" | 474 | "\t\t transparent images; overrides -bgcolor\n" |
475 | #ifdef FEATURE_LOOP | 475 | #ifdef FEATURE_LOOP |
476 | " -loop\tloops through background images after initial display\n" | 476 | " -loop\tloops through background images after initial display\n" |
477 | "\t\t is complete (depends on -bgpat)\n" | 477 | "\t\t is complete (depends on -bgpat)\n" |
478 | " sec \tseconds to display each background image (default = 2)\n" | 478 | " sec \tseconds to display each background image (default = 2)\n" |
479 | #endif | 479 | #endif |
480 | " dur \tduration in microseconds to wait after displaying each\n" | 480 | " dur \tduration in microseconds to wait after displaying each\n" |
481 | "\t\t row (for demo purposes)\n" | 481 | "\t\t row (for demo purposes)\n" |
482 | " -timing\tenables delay for every block read, to simulate modem\n" | 482 | " -timing\tenables delay for every block read, to simulate modem\n" |
483 | "\t\t download of image (~36 Kbps)\n" | 483 | "\t\t download of image (~36 Kbps)\n" |
484 | " -pause\tpauses after displaying each pass until mouse clicked\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" | 485 | "\nPress Q, Esc or mouse button 1 (within image window, after image\n" |
486 | "is displayed) to quit.\n" | 486 | "is displayed) to quit.\n" |
487 | "\n", PROGNAME, | 487 | "\n", PROGNAME, |
488 | (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1); | 488 | (int)strlen(PROGNAME), " ", default_display_exponent, num_bgpat-1); |
489 | exit(1); | 489 | exit(1); |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | if (!(infile = fopen(filename, "rb"))) { | 493 | if (!(infile = fopen(filename, "rb"))) { |
494 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); | 494 | fprintf(stderr, PROGNAME ": can't open PNG file [%s]\n", filename); |
495 | ++error; | 495 | ++error; |
496 | } else { | 496 | } else { |
497 | incount = fread(inbuf, 1, INBUFSIZE, infile); | 497 | incount = fread(inbuf, 1, INBUFSIZE, infile); |
498 | if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { | 498 | if (incount < 8 || !readpng2_check_sig(inbuf, 8)) { |
499 | fprintf(stderr, PROGNAME | 499 | fprintf(stderr, PROGNAME |
500 | ": [%s] is not a PNG file: incorrect signature\n", | 500 | ": [%s] is not a PNG file: incorrect signature\n", |
501 | filename); | 501 | filename); |
502 | ++error; | 502 | ++error; |
503 | } else if ((rc = readpng2_init(&rpng2_info)) != 0) { | 503 | } else if ((rc = readpng2_init(&rpng2_info)) != 0) { |
504 | switch (rc) { | 504 | switch (rc) { |
505 | case 2: | 505 | case 2: |
506 | fprintf(stderr, PROGNAME | 506 | fprintf(stderr, PROGNAME |
507 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); | 507 | ": [%s] has bad IHDR (libpng longjmp)\n", filename); |
508 | break; | 508 | break; |
509 | case 4: | 509 | case 4: |
510 | fprintf(stderr, PROGNAME ": insufficient memory\n"); | 510 | fprintf(stderr, PROGNAME ": insufficient memory\n"); |
511 | break; | 511 | break; |
512 | default: | 512 | default: |
513 | fprintf(stderr, PROGNAME | 513 | fprintf(stderr, PROGNAME |
514 | ": unknown readpng2_init() error\n"); | 514 | ": unknown readpng2_init() error\n"); |
515 | break; | 515 | break; |
516 | } | 516 | } |
517 | ++error; | 517 | ++error; |
518 | } else { | 518 | } else { |
519 | Trace((stderr, "about to call XOpenDisplay()\n")) | 519 | Trace((stderr, "about to call XOpenDisplay()\n")) |
520 | display = XOpenDisplay(displayname); | 520 | display = XOpenDisplay(displayname); |
521 | if (!display) { | 521 | if (!display) { |
522 | readpng2_cleanup(&rpng2_info); | 522 | readpng2_cleanup(&rpng2_info); |
523 | fprintf(stderr, PROGNAME ": can't open X display [%s]\n", | 523 | fprintf(stderr, PROGNAME ": can't open X display [%s]\n", |
524 | displayname? displayname : "default"); | 524 | displayname? displayname : "default"); |
525 | ++error; | 525 | ++error; |
526 | } | 526 | } |
527 | } | 527 | } |
528 | if (error) | 528 | if (error) |
529 | fclose(infile); | 529 | fclose(infile); |
530 | } | 530 | } |
531 | 531 | ||
532 | 532 | ||
533 | if (error) { | 533 | if (error) { |
534 | fprintf(stderr, PROGNAME ": aborting.\n"); | 534 | fprintf(stderr, PROGNAME ": aborting.\n"); |
535 | exit(2); | 535 | exit(2); |
536 | } | 536 | } |
537 | 537 | ||
538 | 538 | ||
539 | /* set the title-bar string, but make sure buffer doesn't overflow */ | 539 | /* set the title-bar string, but make sure buffer doesn't overflow */ |
540 | 540 | ||
541 | alen = strlen(appname); | 541 | alen = strlen(appname); |
542 | flen = strlen(filename); | 542 | flen = strlen(filename); |
543 | if (alen + flen + 3 > 1023) | 543 | if (alen + flen + 3 > 1023) |
544 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); | 544 | sprintf(titlebar, "%s: ...%s", appname, filename+(alen+flen+6-1023)); |
545 | else | 545 | else |
546 | sprintf(titlebar, "%s: %s", appname, filename); | 546 | sprintf(titlebar, "%s: %s", appname, filename); |
547 | 547 | ||
548 | 548 | ||
549 | /* set some final rpng2_info variables before entering main data loop */ | 549 | /* set some final rpng2_info variables before entering main data loop */ |
550 | 550 | ||
551 | if (have_bg) { | 551 | if (have_bg) { |
552 | unsigned r, g, b; /* this approach quiets compiler warnings */ | 552 | unsigned r, g, b; /* this approach quiets compiler warnings */ |
553 | 553 | ||
554 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); | 554 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); |
555 | rpng2_info.bg_red = (uch)r; | 555 | rpng2_info.bg_red = (uch)r; |
556 | rpng2_info.bg_green = (uch)g; | 556 | rpng2_info.bg_green = (uch)g; |
557 | rpng2_info.bg_blue = (uch)b; | 557 | rpng2_info.bg_blue = (uch)b; |
558 | } else | 558 | } else |
559 | rpng2_info.need_bgcolor = TRUE; | 559 | rpng2_info.need_bgcolor = TRUE; |
560 | 560 | ||
561 | rpng2_info.state = kPreInit; | 561 | rpng2_info.state = kPreInit; |
562 | rpng2_info.mainprog_init = rpng2_x_init; | 562 | rpng2_info.mainprog_init = rpng2_x_init; |
563 | rpng2_info.mainprog_display_row = rpng2_x_display_row; | 563 | rpng2_info.mainprog_display_row = rpng2_x_display_row; |
564 | rpng2_info.mainprog_finish_display = rpng2_x_finish_display; | 564 | rpng2_info.mainprog_finish_display = rpng2_x_finish_display; |
565 | 565 | ||
566 | 566 | ||
567 | /* OK, this is the fun part: call readpng2_decode_data() at the start of | 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 | 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 | 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 | 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- | 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 | 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 | 573 | * one second per iteration to simulate downloading the image via an analog |
574 | * modem. */ | 574 | * modem. */ |
575 | 575 | ||
576 | for (;;) { | 576 | for (;;) { |
577 | Trace((stderr, "about to call readpng2_decode_data()\n")) | 577 | Trace((stderr, "about to call readpng2_decode_data()\n")) |
578 | if (readpng2_decode_data(&rpng2_info, inbuf, incount)) | 578 | if (readpng2_decode_data(&rpng2_info, inbuf, incount)) |
579 | ++error; | 579 | ++error; |
580 | Trace((stderr, "done with readpng2_decode_data()\n")) | 580 | Trace((stderr, "done with readpng2_decode_data()\n")) |
581 | 581 | ||
582 | if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { | 582 | if (error || incount != INBUFSIZE || rpng2_info.state == kDone) { |
583 | if (rpng2_info.state == kDone) { | 583 | if (rpng2_info.state == kDone) { |
584 | Trace((stderr, "done decoding PNG image\n")) | 584 | Trace((stderr, "done decoding PNG image\n")) |
585 | } else if (ferror(infile)) { | 585 | } else if (ferror(infile)) { |
586 | fprintf(stderr, PROGNAME | 586 | fprintf(stderr, PROGNAME |
587 | ": error while reading PNG image file\n"); | 587 | ": error while reading PNG image file\n"); |
588 | exit(3); | 588 | exit(3); |
589 | } else if (feof(infile)) { | 589 | } else if (feof(infile)) { |
590 | fprintf(stderr, PROGNAME ": end of file reached " | 590 | fprintf(stderr, PROGNAME ": end of file reached " |
591 | "(unexpectedly) while reading PNG image file\n"); | 591 | "(unexpectedly) while reading PNG image file\n"); |
592 | exit(3); | 592 | exit(3); |
593 | } else /* if (error) */ { | 593 | } else /* if (error) */ { |
594 | /* will print error message below */ | 594 | /* will print error message below */ |
595 | } | 595 | } |
596 | break; | 596 | break; |
597 | } | 597 | } |
598 | 598 | ||
599 | if (timing) | 599 | if (timing) |
600 | sleep(1); | 600 | sleep(1); |
601 | 601 | ||
602 | incount = fread(inbuf, 1, INBUFSIZE, infile); | 602 | incount = fread(inbuf, 1, INBUFSIZE, infile); |
603 | } | 603 | } |
604 | 604 | ||
605 | 605 | ||
606 | /* clean up PNG stuff and report any decoding errors */ | 606 | /* clean up PNG stuff and report any decoding errors */ |
607 | 607 | ||
608 | fclose(infile); | 608 | fclose(infile); |
609 | Trace((stderr, "about to call readpng2_cleanup()\n")) | 609 | Trace((stderr, "about to call readpng2_cleanup()\n")) |
610 | readpng2_cleanup(&rpng2_info); | 610 | readpng2_cleanup(&rpng2_info); |
611 | 611 | ||
612 | if (error) { | 612 | if (error) { |
613 | fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n"); | 613 | fprintf(stderr, PROGNAME ": libpng error while decoding PNG image\n"); |
614 | exit(3); | 614 | exit(3); |
615 | } | 615 | } |
616 | 616 | ||
617 | 617 | ||
618 | #ifdef FEATURE_LOOP | 618 | #ifdef FEATURE_LOOP |
619 | 619 | ||
620 | if (loop && bg_image) { | 620 | if (loop && bg_image) { |
621 | Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n")) | 621 | Trace((stderr, "entering -loop loop (FEATURE_LOOP)\n")) |
622 | for (;;) { | 622 | for (;;) { |
623 | int i, use_sleep; | 623 | int i, use_sleep; |
624 | struct timeval now, then; | 624 | struct timeval now, then; |
625 | 625 | ||
626 | /* get current time and add loop_interval to get target time */ | 626 | /* get current time and add loop_interval to get target time */ |
627 | if (gettimeofday(&then, NULL) == 0) { | 627 | if (gettimeofday(&then, NULL) == 0) { |
628 | then.tv_sec += loop_interval; | 628 | then.tv_sec += loop_interval; |
629 | use_sleep = FALSE; | 629 | use_sleep = FALSE; |
630 | } else | 630 | } else |
631 | use_sleep = TRUE; | 631 | use_sleep = TRUE; |
632 | 632 | ||
633 | /* do quick check for a quit event but don't wait for it */ | 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... */ | 634 | /* GRR BUG: should also check for Expose events and redraw... */ |
635 | if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e)) | 635 | if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e)) |
636 | if (QUIT(e,k)) | 636 | if (QUIT(e,k)) |
637 | break; | 637 | break; |
638 | 638 | ||
639 | /* generate next background image */ | 639 | /* generate next background image */ |
640 | if (++pat >= num_bgpat) | 640 | if (++pat >= num_bgpat) |
641 | pat = 0; | 641 | pat = 0; |
642 | rpng2_x_reload_bg_image(); | 642 | rpng2_x_reload_bg_image(); |
643 | 643 | ||
644 | /* wait for timeout, using whatever means are available */ | 644 | /* wait for timeout, using whatever means are available */ |
645 | if (use_sleep || gettimeofday(&now, NULL) != 0) { | 645 | if (use_sleep || gettimeofday(&now, NULL) != 0) { |
646 | for (i = loop_interval; i > 0; --i) { | 646 | for (i = loop_interval; i > 0; --i) { |
647 | sleep(1); | 647 | sleep(1); |
648 | /* GRR BUG: also need to check for Expose (and redraw!) */ | 648 | /* GRR BUG: also need to check for Expose (and redraw!) */ |
649 | if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, | 649 | if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, |
650 | &e) && QUIT(e,k)) | 650 | &e) && QUIT(e,k)) |
651 | break; | 651 | break; |
652 | } | 652 | } |
653 | } else { | 653 | } else { |
654 | /* Y2038 BUG! */ | 654 | /* Y2038 BUG! */ |
655 | if (now.tv_sec < then.tv_sec || | 655 | if (now.tv_sec < then.tv_sec || |
656 | (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec)) | 656 | (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec)) |
657 | { | 657 | { |
658 | int quit = FALSE; | 658 | int quit = FALSE; |
659 | long seconds_to_go = then.tv_sec - now.tv_sec; | 659 | long seconds_to_go = then.tv_sec - now.tv_sec; |
660 | long usleep_usec; | 660 | long usleep_usec; |
661 | 661 | ||
662 | /* basically chew up most of remaining loop-interval with | 662 | /* basically chew up most of remaining loop-interval with |
663 | * calls to sleep(1) interleaved with checks for quit | 663 | * calls to sleep(1) interleaved with checks for quit |
664 | * events, but also recalc time-to-go periodically; when | 664 | * events, but also recalc time-to-go periodically; when |
665 | * done, clean up any remaining time with usleep() call | 665 | * done, clean up any remaining time with usleep() call |
666 | * (could also use SIGALRM, but signals are a pain...) */ | 666 | * (could also use SIGALRM, but signals are a pain...) */ |
667 | while (seconds_to_go-- > 1) { | 667 | while (seconds_to_go-- > 1) { |
668 | int seconds_done = 0; | 668 | int seconds_done = 0; |
669 | 669 | ||
670 | for (i = seconds_to_go; i > 0 && !quit; --i) { | 670 | for (i = seconds_to_go; i > 0 && !quit; --i) { |
671 | sleep(1); | 671 | sleep(1); |
672 | /* GRR BUG: need to check for Expose and redraw */ | 672 | /* GRR BUG: need to check for Expose and redraw */ |
673 | if (XCheckMaskEvent(display, KeyPressMask | | 673 | if (XCheckMaskEvent(display, KeyPressMask | |
674 | ButtonPressMask, &e) && QUIT(e,k)) | 674 | ButtonPressMask, &e) && QUIT(e,k)) |
675 | quit = TRUE; | 675 | quit = TRUE; |
676 | if (++seconds_done > 1000) | 676 | if (++seconds_done > 1000) |
677 | break; /* time to redo seconds_to_go meas. */ | 677 | break; /* time to redo seconds_to_go meas. */ |
678 | } | 678 | } |
679 | if (quit) | 679 | if (quit) |
680 | break; | 680 | break; |
681 | 681 | ||
682 | /* OK, more than 1000 seconds since last check: | 682 | /* OK, more than 1000 seconds since last check: |
683 | * correct the time-to-go measurement for drift */ | 683 | * correct the time-to-go measurement for drift */ |
684 | if (gettimeofday(&now, NULL) == 0) { | 684 | if (gettimeofday(&now, NULL) == 0) { |
685 | if (now.tv_sec >= then.tv_sec) | 685 | if (now.tv_sec >= then.tv_sec) |
686 | break; | 686 | break; |
687 | seconds_to_go = then.tv_sec - now.tv_sec; | 687 | seconds_to_go = then.tv_sec - now.tv_sec; |
688 | } else | 688 | } else |
689 | ++seconds_to_go; /* restore what we subtracted */ | 689 | ++seconds_to_go; /* restore what we subtracted */ |
690 | } | 690 | } |
691 | if (quit) | 691 | if (quit) |
692 | break; /* breaks outer do-loop, skips redisplay */ | 692 | break; /* breaks outer do-loop, skips redisplay */ |
693 | 693 | ||
694 | /* since difference between "now" and "then" is already | 694 | /* since difference between "now" and "then" is already |
695 | * eaten up to within a couple of seconds, don't need to | 695 | * eaten up to within a couple of seconds, don't need to |
696 | * worry about overflow--but might have overshot (neg.) */ | 696 | * worry about overflow--but might have overshot (neg.) */ |
697 | if (gettimeofday(&now, NULL) == 0) { | 697 | if (gettimeofday(&now, NULL) == 0) { |
698 | usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) + | 698 | usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) + |
699 | then.tv_usec - now.tv_usec; | 699 | then.tv_usec - now.tv_usec; |
700 | if (usleep_usec > 0) | 700 | if (usleep_usec > 0) |
701 | usleep((ulg)usleep_usec); | 701 | usleep((ulg)usleep_usec); |
702 | } | 702 | } |
703 | } | 703 | } |
704 | } | 704 | } |
705 | 705 | ||
706 | /* composite image against new background and display (note that | 706 | /* composite image against new background and display (note that |
707 | * we do not take into account the time spent doing this...) */ | 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); | 708 | rpng2_x_redisplay_image (0, 0, rpng2_info.width, rpng2_info.height); |
709 | } | 709 | } |
710 | 710 | ||
711 | } else /* FALL THROUGH and do the normal thing */ | 711 | } else /* FALL THROUGH and do the normal thing */ |
712 | 712 | ||
713 | #endif /* FEATURE_LOOP */ | 713 | #endif /* FEATURE_LOOP */ |
714 | 714 | ||
715 | /* wait for the user to tell us when to quit */ | 715 | /* wait for the user to tell us when to quit */ |
716 | 716 | ||
717 | if (rpng2_info.state >= kWindowInit) { | 717 | if (rpng2_info.state >= kWindowInit) { |
718 | Trace((stderr, "entering final wait-for-quit-event loop\n")) | 718 | Trace((stderr, "entering final wait-for-quit-event loop\n")) |
719 | do { | 719 | do { |
720 | XNextEvent(display, &e); | 720 | XNextEvent(display, &e); |
721 | if (e.type == Expose) { | 721 | if (e.type == Expose) { |
722 | XExposeEvent *ex = (XExposeEvent *)&e; | 722 | XExposeEvent *ex = (XExposeEvent *)&e; |
723 | rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height); | 723 | rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height); |
724 | } | 724 | } |
725 | } while (!QUIT(e,k)); | 725 | } while (!QUIT(e,k)); |
726 | } else { | 726 | } else { |
727 | fprintf(stderr, PROGNAME ": init callback never called: probable " | 727 | fprintf(stderr, PROGNAME ": init callback never called: probable " |
728 | "libpng error while decoding PNG metadata\n"); | 728 | "libpng error while decoding PNG metadata\n"); |
729 | exit(4); | 729 | exit(4); |
730 | } | 730 | } |
731 | 731 | ||
732 | 732 | ||
733 | /* we're done: clean up all image and X resources and go away */ | 733 | /* we're done: clean up all image and X resources and go away */ |
734 | 734 | ||
735 | Trace((stderr, "about to call rpng2_x_cleanup()\n")) | 735 | Trace((stderr, "about to call rpng2_x_cleanup()\n")) |
736 | rpng2_x_cleanup(); | 736 | rpng2_x_cleanup(); |
737 | 737 | ||
738 | return 0; | 738 | return 0; |
739 | } | 739 | } |
740 | 740 | ||
741 | 741 | ||
742 | 742 | ||
743 | 743 | ||
744 | 744 | ||
745 | /* this function is called by readpng2_info_callback() in readpng2.c, which | 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 | 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 */ | 747 | * read and processed--i.e., we now have enough info to finish initializing */ |
748 | 748 | ||
749 | static void rpng2_x_init(void) | 749 | static void rpng2_x_init(void) |
750 | { | 750 | { |
751 | ulg i; | 751 | ulg i; |
752 | ulg rowbytes = rpng2_info.rowbytes; | 752 | ulg rowbytes = rpng2_info.rowbytes; |
753 | 753 | ||
754 | Trace((stderr, "beginning rpng2_x_init()\n")) | 754 | Trace((stderr, "beginning rpng2_x_init()\n")) |
755 | Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) | 755 | Trace((stderr, " rowbytes = %d\n", rpng2_info.rowbytes)) |
756 | Trace((stderr, " width = %ld\n", rpng2_info.width)) | 756 | Trace((stderr, " width = %ld\n", rpng2_info.width)) |
757 | Trace((stderr, " height = %ld\n", rpng2_info.height)) | 757 | Trace((stderr, " height = %ld\n", rpng2_info.height)) |
758 | 758 | ||
759 | rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); | 759 | rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height); |
760 | if (!rpng2_info.image_data) { | 760 | if (!rpng2_info.image_data) { |
761 | readpng2_cleanup(&rpng2_info); | 761 | readpng2_cleanup(&rpng2_info); |
762 | return; | 762 | return; |
763 | } | 763 | } |
764 | 764 | ||
765 | rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *)); | 765 | rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *)); |
766 | if (!rpng2_info.row_pointers) { | 766 | if (!rpng2_info.row_pointers) { |
767 | free(rpng2_info.image_data); | 767 | free(rpng2_info.image_data); |
768 | rpng2_info.image_data = NULL; | 768 | rpng2_info.image_data = NULL; |
769 | readpng2_cleanup(&rpng2_info); | 769 | readpng2_cleanup(&rpng2_info); |
770 | return; | 770 | return; |
771 | } | 771 | } |
772 | 772 | ||
773 | for (i = 0; i < rpng2_info.height; ++i) | 773 | for (i = 0; i < rpng2_info.height; ++i) |
774 | rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes; | 774 | rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes; |
775 | 775 | ||
776 | 776 | ||
777 | /* do the basic X initialization stuff, make the window, and fill it with | 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 | 778 | * the user-specified, file-specified or default background color or |
779 | * pattern */ | 779 | * pattern */ |
780 | 780 | ||
781 | if (rpng2_x_create_window()) { | 781 | if (rpng2_x_create_window()) { |
782 | 782 | ||
783 | /* GRR TEMPORARY HACK: this is fundamentally no different from cases | 783 | /* GRR TEMPORARY HACK: this is fundamentally no different from cases |
784 | * above; libpng should call our error handler to longjmp() back to us | 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 | 785 | * when png_ptr goes away. If we/it segfault instead, seems like a |
786 | * libpng bug... */ | 786 | * libpng bug... */ |
787 | 787 | ||
788 | /* we're here via libpng callback, so if window fails, clean and bail */ | 788 | /* we're here via libpng callback, so if window fails, clean and bail */ |
789 | readpng2_cleanup(&rpng2_info); | 789 | readpng2_cleanup(&rpng2_info); |
790 | rpng2_x_cleanup(); | 790 | rpng2_x_cleanup(); |
791 | exit(2); | 791 | exit(2); |
792 | } | 792 | } |
793 | 793 | ||
794 | rpng2_info.state = kWindowInit; | 794 | rpng2_info.state = kWindowInit; |
795 | } | 795 | } |
796 | 796 | ||
797 | 797 | ||
798 | 798 | ||
799 | 799 | ||
800 | 800 | ||
801 | static int rpng2_x_create_window(void) | 801 | static int rpng2_x_create_window(void) |
802 | { | 802 | { |
803 | ulg bg_red = rpng2_info.bg_red; | 803 | ulg bg_red = rpng2_info.bg_red; |
804 | ulg bg_green = rpng2_info.bg_green; | 804 | ulg bg_green = rpng2_info.bg_green; |
805 | ulg bg_blue = rpng2_info.bg_blue; | 805 | ulg bg_blue = rpng2_info.bg_blue; |
806 | ulg bg_pixel = 0L; | 806 | ulg bg_pixel = 0L; |
807 | ulg attrmask; | 807 | ulg attrmask; |
808 | int need_colormap = FALSE; | 808 | int need_colormap = FALSE; |
809 | int screen, pad; | 809 | int screen, pad; |
810 | uch *xdata; | 810 | uch *xdata; |
811 | Window root; | 811 | Window root; |
812 | XEvent e; | 812 | XEvent e; |
813 | XGCValues gcvalues; | 813 | XGCValues gcvalues; |
814 | XSetWindowAttributes attr; | 814 | XSetWindowAttributes attr; |
815 | XTextProperty windowName, *pWindowName = &windowName; | 815 | XTextProperty windowName, *pWindowName = &windowName; |
816 | XTextProperty iconName, *pIconName = &iconName; | 816 | XTextProperty iconName, *pIconName = &iconName; |
817 | XVisualInfo visual_info; | 817 | XVisualInfo visual_info; |
818 | XSizeHints *size_hints; | 818 | XSizeHints *size_hints; |
819 | XWMHints *wm_hints; | 819 | XWMHints *wm_hints; |
820 | XClassHint *class_hints; | 820 | XClassHint *class_hints; |
821 | 821 | ||
822 | 822 | ||
823 | Trace((stderr, "beginning rpng2_x_create_window()\n")) | 823 | Trace((stderr, "beginning rpng2_x_create_window()\n")) |
824 | 824 | ||
825 | screen = DefaultScreen(display); | 825 | screen = DefaultScreen(display); |
826 | depth = DisplayPlanes(display, screen); | 826 | depth = DisplayPlanes(display, screen); |
827 | root = RootWindow(display, screen); | 827 | root = RootWindow(display, screen); |
828 | 828 | ||
829 | #ifdef DEBUG | 829 | #ifdef DEBUG |
830 | XSynchronize(display, True); | 830 | XSynchronize(display, True); |
831 | #endif | 831 | #endif |
832 | 832 | ||
833 | if (depth != 16 && depth != 24 && depth != 32) { | 833 | if (depth != 16 && depth != 24 && depth != 32) { |
834 | int visuals_matched = 0; | 834 | int visuals_matched = 0; |
835 | 835 | ||
836 | Trace((stderr, "default depth is %d: checking other visuals\n", | 836 | Trace((stderr, "default depth is %d: checking other visuals\n", |
837 | depth)) | 837 | depth)) |
838 | 838 | ||
839 | /* 24-bit first */ | 839 | /* 24-bit first */ |
840 | visual_info.screen = screen; | 840 | visual_info.screen = screen; |
841 | visual_info.depth = 24; | 841 | visual_info.depth = 24; |
842 | visual_list = XGetVisualInfo(display, | 842 | visual_list = XGetVisualInfo(display, |
843 | VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched); | 843 | VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched); |
844 | if (visuals_matched == 0) { | 844 | if (visuals_matched == 0) { |
845 | /* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */ | 845 | /* GRR: add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */ |
846 | fprintf(stderr, "default screen depth %d not supported, and no" | 846 | fprintf(stderr, "default screen depth %d not supported, and no" |
847 | " 24-bit visuals found\n", depth); | 847 | " 24-bit visuals found\n", depth); |
848 | return 2; | 848 | return 2; |
849 | } | 849 | } |
850 | Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n", | 850 | Trace((stderr, "XGetVisualInfo() returned %d 24-bit visuals\n", |
851 | visuals_matched)) | 851 | visuals_matched)) |
852 | visual = visual_list[0].visual; | 852 | visual = visual_list[0].visual; |
853 | depth = visual_list[0].depth; | 853 | depth = visual_list[0].depth; |
854 | /* | 854 | /* |
855 | colormap_size = visual_list[0].colormap_size; | 855 | colormap_size = visual_list[0].colormap_size; |
856 | visual_class = visual->class; | 856 | visual_class = visual->class; |
857 | visualID = XVisualIDFromVisual(visual); | 857 | visualID = XVisualIDFromVisual(visual); |
858 | */ | 858 | */ |
859 | have_nondefault_visual = TRUE; | 859 | have_nondefault_visual = TRUE; |
860 | need_colormap = TRUE; | 860 | need_colormap = TRUE; |
861 | } else { | 861 | } else { |
862 | XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info); | 862 | XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info); |
863 | visual = visual_info.visual; | 863 | visual = visual_info.visual; |
864 | } | 864 | } |
865 | 865 | ||
866 | RMask = visual->red_mask; | 866 | RMask = visual->red_mask; |
867 | GMask = visual->green_mask; | 867 | GMask = visual->green_mask; |
868 | BMask = visual->blue_mask; | 868 | BMask = visual->blue_mask; |
869 | 869 | ||
870 | /* GRR: add/check 8-bit support */ | 870 | /* GRR: add/check 8-bit support */ |
871 | if (depth == 8 || need_colormap) { | 871 | if (depth == 8 || need_colormap) { |
872 | colormap = XCreateColormap(display, root, visual, AllocNone); | 872 | colormap = XCreateColormap(display, root, visual, AllocNone); |
873 | if (!colormap) { | 873 | if (!colormap) { |
874 | fprintf(stderr, "XCreateColormap() failed\n"); | 874 | fprintf(stderr, "XCreateColormap() failed\n"); |
875 | return 2; | 875 | return 2; |
876 | } | 876 | } |
877 | have_colormap = TRUE; | 877 | have_colormap = TRUE; |
878 | if (depth == 8) | 878 | if (depth == 8) |
879 | bg_image = FALSE; /* gradient just wastes palette entries */ | 879 | bg_image = FALSE; /* gradient just wastes palette entries */ |
880 | } | 880 | } |
881 | if (depth == 15 || depth == 16) { | 881 | if (depth == 15 || depth == 16) { |
882 | RShift = 15 - rpng2_x_msb(RMask); /* these are right-shifts */ | 882 | RShift = 15 - rpng2_x_msb(RMask); /* these are right-shifts */ |
883 | GShift = 15 - rpng2_x_msb(GMask); | 883 | GShift = 15 - rpng2_x_msb(GMask); |
884 | BShift = 15 - rpng2_x_msb(BMask); | 884 | BShift = 15 - rpng2_x_msb(BMask); |
885 | } else if (depth > 16) { | 885 | } else if (depth > 16) { |
886 | RShift = rpng2_x_msb(RMask) - 7; /* these are left-shifts */ | 886 | RShift = rpng2_x_msb(RMask) - 7; /* these are left-shifts */ |
887 | GShift = rpng2_x_msb(GMask) - 7; | 887 | GShift = rpng2_x_msb(GMask) - 7; |
888 | BShift = rpng2_x_msb(BMask) - 7; | 888 | BShift = rpng2_x_msb(BMask) - 7; |
889 | } | 889 | } |
890 | if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) { | 890 | if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) { |
891 | fprintf(stderr, "rpng2 internal logic error: negative X shift(s)!\n"); | 891 | fprintf(stderr, "rpng2 internal logic error: negative X shift(s)!\n"); |
892 | return 2; | 892 | return 2; |
893 | } | 893 | } |
894 | 894 | ||
895 | /*--------------------------------------------------------------------------- | 895 | /*--------------------------------------------------------------------------- |
896 | Finally, create the window. | 896 | Finally, create the window. |
897 | ---------------------------------------------------------------------------*/ | 897 | ---------------------------------------------------------------------------*/ |
898 | 898 | ||
899 | attr.backing_store = Always; | 899 | attr.backing_store = Always; |
900 | attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; | 900 | attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask; |
901 | attrmask = CWBackingStore | CWEventMask; | 901 | attrmask = CWBackingStore | CWEventMask; |
902 | if (have_nondefault_visual) { | 902 | if (have_nondefault_visual) { |
903 | attr.colormap = colormap; | 903 | attr.colormap = colormap; |
904 | attr.background_pixel = 0; | 904 | attr.background_pixel = 0; |
905 | attr.border_pixel = 1; | 905 | attr.border_pixel = 1; |
906 | attrmask |= CWColormap | CWBackPixel | CWBorderPixel; | 906 | attrmask |= CWColormap | CWBackPixel | CWBorderPixel; |
907 | } | 907 | } |
908 | 908 | ||
909 | window = XCreateWindow(display, root, 0, 0, rpng2_info.width, | 909 | window = XCreateWindow(display, root, 0, 0, rpng2_info.width, |
910 | rpng2_info.height, 0, depth, InputOutput, visual, attrmask, &attr); | 910 | rpng2_info.height, 0, depth, InputOutput, visual, attrmask, &attr); |
911 | 911 | ||
912 | if (window == None) { | 912 | if (window == None) { |
913 | fprintf(stderr, "XCreateWindow() failed\n"); | 913 | fprintf(stderr, "XCreateWindow() failed\n"); |
914 | return 2; | 914 | return 2; |
915 | } else | 915 | } else |
916 | have_window = TRUE; | 916 | have_window = TRUE; |
917 | 917 | ||
918 | if (depth == 8) | 918 | if (depth == 8) |
919 | XSetWindowColormap(display, window, colormap); | 919 | XSetWindowColormap(display, window, colormap); |
920 | 920 | ||
921 | if (!XStringListToTextProperty(&window_name, 1, pWindowName)) | 921 | if (!XStringListToTextProperty(&window_name, 1, pWindowName)) |
922 | pWindowName = NULL; | 922 | pWindowName = NULL; |
923 | if (!XStringListToTextProperty(&icon_name, 1, pIconName)) | 923 | if (!XStringListToTextProperty(&icon_name, 1, pIconName)) |
924 | pIconName = NULL; | 924 | pIconName = NULL; |
925 | 925 | ||
926 | /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */ | 926 | /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */ |
927 | 927 | ||
928 | if ((size_hints = XAllocSizeHints()) != NULL) { | 928 | if ((size_hints = XAllocSizeHints()) != NULL) { |
929 | /* window will not be resizable */ | 929 | /* window will not be resizable */ |
930 | size_hints->flags = PMinSize | PMaxSize; | 930 | size_hints->flags = PMinSize | PMaxSize; |
931 | size_hints->min_width = size_hints->max_width = (int)rpng2_info.width; | 931 | size_hints->min_width = size_hints->max_width = (int)rpng2_info.width; |
932 | size_hints->min_height = size_hints->max_height = | 932 | size_hints->min_height = size_hints->max_height = |
933 | (int)rpng2_info.height; | 933 | (int)rpng2_info.height; |
934 | } | 934 | } |
935 | 935 | ||
936 | if ((wm_hints = XAllocWMHints()) != NULL) { | 936 | if ((wm_hints = XAllocWMHints()) != NULL) { |
937 | wm_hints->initial_state = NormalState; | 937 | wm_hints->initial_state = NormalState; |
938 | wm_hints->input = True; | 938 | wm_hints->input = True; |
939 | /* wm_hints->icon_pixmap = icon_pixmap; */ | 939 | /* wm_hints->icon_pixmap = icon_pixmap; */ |
940 | wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; | 940 | wm_hints->flags = StateHint | InputHint /* | IconPixmapHint */ ; |
941 | } | 941 | } |
942 | 942 | ||
943 | if ((class_hints = XAllocClassHint()) != NULL) { | 943 | if ((class_hints = XAllocClassHint()) != NULL) { |
944 | class_hints->res_name = res_name; | 944 | class_hints->res_name = res_name; |
945 | class_hints->res_class = res_class; | 945 | class_hints->res_class = res_class; |
946 | } | 946 | } |
947 | 947 | ||
948 | XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, | 948 | XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0, |
949 | size_hints, wm_hints, class_hints); | 949 | size_hints, wm_hints, class_hints); |
950 | 950 | ||
951 | /* various properties and hints no longer needed; free memory */ | 951 | /* various properties and hints no longer needed; free memory */ |
952 | if (pWindowName) | 952 | if (pWindowName) |
953 | XFree(pWindowName->value); | 953 | XFree(pWindowName->value); |
954 | if (pIconName) | 954 | if (pIconName) |
955 | XFree(pIconName->value); | 955 | XFree(pIconName->value); |
956 | if (size_hints) | 956 | if (size_hints) |
957 | XFree(size_hints); | 957 | XFree(size_hints); |
958 | if (wm_hints) | 958 | if (wm_hints) |
959 | XFree(wm_hints); | 959 | XFree(wm_hints); |
960 | if (class_hints) | 960 | if (class_hints) |
961 | XFree(class_hints); | 961 | XFree(class_hints); |
962 | 962 | ||
963 | XMapWindow(display, window); | 963 | XMapWindow(display, window); |
964 | 964 | ||
965 | gc = XCreateGC(display, window, 0, &gcvalues); | 965 | gc = XCreateGC(display, window, 0, &gcvalues); |
966 | have_gc = TRUE; | 966 | have_gc = TRUE; |
967 | 967 | ||
968 | /*--------------------------------------------------------------------------- | 968 | /*--------------------------------------------------------------------------- |
969 | Allocate memory for the X- and display-specific version of the image. | 969 | Allocate memory for the X- and display-specific version of the image. |
970 | ---------------------------------------------------------------------------*/ | 970 | ---------------------------------------------------------------------------*/ |
971 | 971 | ||
972 | if (depth == 24 || depth == 32) { | 972 | if (depth == 24 || depth == 32) { |
973 | xdata = (uch *)malloc(4*rpng2_info.width*rpng2_info.height); | 973 | xdata = (uch *)malloc(4*rpng2_info.width*rpng2_info.height); |
974 | pad = 32; | 974 | pad = 32; |
975 | } else if (depth == 16) { | 975 | } else if (depth == 16) { |
976 | xdata = (uch *)malloc(2*rpng2_info.width*rpng2_info.height); | 976 | xdata = (uch *)malloc(2*rpng2_info.width*rpng2_info.height); |
977 | pad = 16; | 977 | pad = 16; |
978 | } else /* depth == 8 */ { | 978 | } else /* depth == 8 */ { |
979 | xdata = (uch *)malloc(rpng2_info.width*rpng2_info.height); | 979 | xdata = (uch *)malloc(rpng2_info.width*rpng2_info.height); |
980 | pad = 8; | 980 | pad = 8; |
981 | } | 981 | } |
982 | 982 | ||
983 | if (!xdata) { | 983 | if (!xdata) { |
984 | fprintf(stderr, PROGNAME ": unable to allocate image memory\n"); | 984 | fprintf(stderr, PROGNAME ": unable to allocate image memory\n"); |
985 | return 4; | 985 | return 4; |
986 | } | 986 | } |
987 | 987 | ||
988 | ximage = XCreateImage(display, visual, depth, ZPixmap, 0, | 988 | ximage = XCreateImage(display, visual, depth, ZPixmap, 0, |
989 | (char *)xdata, rpng2_info.width, rpng2_info.height, pad, 0); | 989 | (char *)xdata, rpng2_info.width, rpng2_info.height, pad, 0); |
990 | 990 | ||
991 | if (!ximage) { | 991 | if (!ximage) { |
992 | fprintf(stderr, PROGNAME ": XCreateImage() failed\n"); | 992 | fprintf(stderr, PROGNAME ": XCreateImage() failed\n"); |
993 | free(xdata); | 993 | free(xdata); |
994 | return 3; | 994 | return 3; |
995 | } | 995 | } |
996 | 996 | ||
997 | /* to avoid testing the byte order every pixel (or doubling the size of | 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 | 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- | 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 | 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 | 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... */ | 1002 | * the interest of clarity, we'll take the easy way out... */ |
1003 | 1003 | ||
1004 | ximage->byte_order = MSBFirst; | 1004 | ximage->byte_order = MSBFirst; |
1005 | 1005 | ||
1006 | /*--------------------------------------------------------------------------- | 1006 | /*--------------------------------------------------------------------------- |
1007 | Fill window with the specified background color (default is black) or | 1007 | Fill window with the specified background color (default is black) or |
1008 | faked "background image" (but latter is disabled if 8-bit; gradients | 1008 | faked "background image" (but latter is disabled if 8-bit; gradients |
1009 | just waste palette entries). | 1009 | just waste palette entries). |
1010 | ---------------------------------------------------------------------------*/ | 1010 | ---------------------------------------------------------------------------*/ |
1011 | 1011 | ||
1012 | if (bg_image) | 1012 | if (bg_image) |
1013 | rpng2_x_load_bg_image(); /* resets bg_image if fails */ | 1013 | rpng2_x_load_bg_image(); /* resets bg_image if fails */ |
1014 | 1014 | ||
1015 | if (!bg_image) { | 1015 | if (!bg_image) { |
1016 | if (depth == 24 || depth == 32) { | 1016 | if (depth == 24 || depth == 32) { |
1017 | bg_pixel = (bg_red << RShift) | | 1017 | bg_pixel = (bg_red << RShift) | |
1018 | (bg_green << GShift) | | 1018 | (bg_green << GShift) | |
1019 | (bg_blue << BShift); | 1019 | (bg_blue << BShift); |
1020 | } else if (depth == 16) { | 1020 | } else if (depth == 16) { |
1021 | bg_pixel = (((bg_red << 8) >> RShift) & RMask) | | 1021 | bg_pixel = (((bg_red << 8) >> RShift) & RMask) | |
1022 | (((bg_green << 8) >> GShift) & GMask) | | 1022 | (((bg_green << 8) >> GShift) & GMask) | |
1023 | (((bg_blue << 8) >> BShift) & BMask); | 1023 | (((bg_blue << 8) >> BShift) & BMask); |
1024 | } else /* depth == 8 */ { | 1024 | } else /* depth == 8 */ { |
1025 | 1025 | ||
1026 | /* GRR: add 8-bit support */ | 1026 | /* GRR: add 8-bit support */ |
1027 | 1027 | ||
1028 | } | 1028 | } |
1029 | XSetForeground(display, gc, bg_pixel); | 1029 | XSetForeground(display, gc, bg_pixel); |
1030 | XFillRectangle(display, window, gc, 0, 0, rpng2_info.width, | 1030 | XFillRectangle(display, window, gc, 0, 0, rpng2_info.width, |
1031 | rpng2_info.height); | 1031 | rpng2_info.height); |
1032 | } | 1032 | } |
1033 | 1033 | ||
1034 | /*--------------------------------------------------------------------------- | 1034 | /*--------------------------------------------------------------------------- |
1035 | Wait for first Expose event to do any drawing, then flush and return. | 1035 | Wait for first Expose event to do any drawing, then flush and return. |
1036 | ---------------------------------------------------------------------------*/ | 1036 | ---------------------------------------------------------------------------*/ |
1037 | 1037 | ||
1038 | do | 1038 | do |
1039 | XNextEvent(display, &e); | 1039 | XNextEvent(display, &e); |
1040 | while (e.type != Expose || e.xexpose.count); | 1040 | while (e.type != Expose || e.xexpose.count); |
1041 | 1041 | ||
1042 | XFlush(display); | 1042 | XFlush(display); |
1043 | 1043 | ||
1044 | return 0; | 1044 | return 0; |
1045 | 1045 | ||
1046 | } /* end function rpng2_x_create_window() */ | 1046 | } /* end function rpng2_x_create_window() */ |
1047 | 1047 | ||
1048 | 1048 | ||
1049 | 1049 | ||
1050 | 1050 | ||
1051 | 1051 | ||
1052 | static int rpng2_x_load_bg_image(void) | 1052 | static int rpng2_x_load_bg_image(void) |
1053 | { | 1053 | { |
1054 | uch *src; | 1054 | uch *src; |
1055 | char *dest; | 1055 | char *dest; |
1056 | uch r1, r2, g1, g2, b1, b2; | 1056 | uch r1, r2, g1, g2, b1, b2; |
1057 | uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; | 1057 | uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; |
1058 | int k, hmax, max; | 1058 | int k, hmax, max; |
1059 | int xidx, yidx, yidx_max; | 1059 | int xidx, yidx, yidx_max; |
1060 | int even_odd_vert, even_odd_horiz, even_odd; | 1060 | int even_odd_vert, even_odd_horiz, even_odd; |
1061 | int invert_gradient2 = (bg[pat].type & 0x08); | 1061 | int invert_gradient2 = (bg[pat].type & 0x08); |
1062 | int invert_column; | 1062 | int invert_column; |
1063 | int ximage_rowbytes = ximage->bytes_per_line; | 1063 | int ximage_rowbytes = ximage->bytes_per_line; |
1064 | ulg i, row; | 1064 | ulg i, row; |
1065 | ulg pixel; | 1065 | ulg pixel; |
1066 | 1066 | ||
1067 | /*--------------------------------------------------------------------------- | 1067 | /*--------------------------------------------------------------------------- |
1068 | Allocate buffer for fake background image to be used with transparent | 1068 | Allocate buffer for fake background image to be used with transparent |
1069 | images; if this fails, revert to plain background color. | 1069 | images; if this fails, revert to plain background color. |
1070 | ---------------------------------------------------------------------------*/ | 1070 | ---------------------------------------------------------------------------*/ |
1071 | 1071 | ||
1072 | bg_rowbytes = 3 * rpng2_info.width; | 1072 | bg_rowbytes = 3 * rpng2_info.width; |
1073 | bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height); | 1073 | bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height); |
1074 | if (!bg_data) { | 1074 | if (!bg_data) { |
1075 | fprintf(stderr, PROGNAME | 1075 | fprintf(stderr, PROGNAME |
1076 | ": unable to allocate memory for background image\n"); | 1076 | ": unable to allocate memory for background image\n"); |
1077 | bg_image = 0; | 1077 | bg_image = 0; |
1078 | return 1; | 1078 | return 1; |
1079 | } | 1079 | } |
1080 | 1080 | ||
1081 | bgscale = (pat == 0)? 8 : bgscale_default; | 1081 | bgscale = (pat == 0)? 8 : bgscale_default; |
1082 | yidx_max = bgscale - 1; | 1082 | yidx_max = bgscale - 1; |
1083 | 1083 | ||
1084 | /*--------------------------------------------------------------------------- | 1084 | /*--------------------------------------------------------------------------- |
1085 | Vertical gradients (ramps) in NxN squares, alternating direction and | 1085 | Vertical gradients (ramps) in NxN squares, alternating direction and |
1086 | colors (N == bgscale). | 1086 | colors (N == bgscale). |
1087 | ---------------------------------------------------------------------------*/ | 1087 | ---------------------------------------------------------------------------*/ |
1088 | 1088 | ||
1089 | if ((bg[pat].type & 0x07) == 0) { | 1089 | if ((bg[pat].type & 0x07) == 0) { |
1090 | uch r1_min = rgb[bg[pat].rgb1_min].r; | 1090 | uch r1_min = rgb[bg[pat].rgb1_min].r; |
1091 | uch g1_min = rgb[bg[pat].rgb1_min].g; | 1091 | uch g1_min = rgb[bg[pat].rgb1_min].g; |
1092 | uch b1_min = rgb[bg[pat].rgb1_min].b; | 1092 | uch b1_min = rgb[bg[pat].rgb1_min].b; |
1093 | uch r2_min = rgb[bg[pat].rgb2_min].r; | 1093 | uch r2_min = rgb[bg[pat].rgb2_min].r; |
1094 | uch g2_min = rgb[bg[pat].rgb2_min].g; | 1094 | uch g2_min = rgb[bg[pat].rgb2_min].g; |
1095 | uch b2_min = rgb[bg[pat].rgb2_min].b; | 1095 | uch b2_min = rgb[bg[pat].rgb2_min].b; |
1096 | int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; | 1096 | int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; |
1097 | int g1_diff = rgb[bg[pat].rgb1_max].g - g1_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; | 1098 | int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; |
1099 | int r2_diff = rgb[bg[pat].rgb2_max].r - r2_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; | 1100 | int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; |
1101 | int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; | 1101 | int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; |
1102 | 1102 | ||
1103 | for (row = 0; row < rpng2_info.height; ++row) { | 1103 | for (row = 0; row < rpng2_info.height; ++row) { |
1104 | yidx = (int)(row % bgscale); | 1104 | yidx = (int)(row % bgscale); |
1105 | even_odd_vert = (int)((row / bgscale) & 1); | 1105 | even_odd_vert = (int)((row / bgscale) & 1); |
1106 | 1106 | ||
1107 | r1 = r1_min + (r1_diff * yidx) / yidx_max; | 1107 | r1 = r1_min + (r1_diff * yidx) / yidx_max; |
1108 | g1 = g1_min + (g1_diff * yidx) / yidx_max; | 1108 | g1 = g1_min + (g1_diff * yidx) / yidx_max; |
1109 | b1 = b1_min + (b1_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; | 1110 | r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; |
1111 | g1_inv = g1_min + (g1_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; | 1112 | b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; |
1113 | 1113 | ||
1114 | r2 = r2_min + (r2_diff * yidx) / yidx_max; | 1114 | r2 = r2_min + (r2_diff * yidx) / yidx_max; |
1115 | g2 = g2_min + (g2_diff * yidx) / yidx_max; | 1115 | g2 = g2_min + (g2_diff * yidx) / yidx_max; |
1116 | b2 = b2_min + (b2_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; | 1117 | r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; |
1118 | g2_inv = g2_min + (g2_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; | 1119 | b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; |
1120 | 1120 | ||
1121 | dest = (char *)bg_data + row*bg_rowbytes; | 1121 | dest = (char *)bg_data + row*bg_rowbytes; |
1122 | for (i = 0; i < rpng2_info.width; ++i) { | 1122 | for (i = 0; i < rpng2_info.width; ++i) { |
1123 | even_odd_horiz = (int)((i / bgscale) & 1); | 1123 | even_odd_horiz = (int)((i / bgscale) & 1); |
1124 | even_odd = even_odd_vert ^ even_odd_horiz; | 1124 | even_odd = even_odd_vert ^ even_odd_horiz; |
1125 | invert_column = | 1125 | invert_column = |
1126 | (even_odd_horiz && (bg[pat].type & 0x10)); | 1126 | (even_odd_horiz && (bg[pat].type & 0x10)); |
1127 | if (even_odd == 0) { /* gradient #1 */ | 1127 | if (even_odd == 0) { /* gradient #1 */ |
1128 | if (invert_column) { | 1128 | if (invert_column) { |
1129 | *dest++ = r1_inv; | 1129 | *dest++ = r1_inv; |
1130 | *dest++ = g1_inv; | 1130 | *dest++ = g1_inv; |
1131 | *dest++ = b1_inv; | 1131 | *dest++ = b1_inv; |
1132 | } else { | 1132 | } else { |
1133 | *dest++ = r1; | 1133 | *dest++ = r1; |
1134 | *dest++ = g1; | 1134 | *dest++ = g1; |
1135 | *dest++ = b1; | 1135 | *dest++ = b1; |
1136 | } | 1136 | } |
1137 | } else { /* gradient #2 */ | 1137 | } else { /* gradient #2 */ |
1138 | if ((invert_column && invert_gradient2) || | 1138 | if ((invert_column && invert_gradient2) || |
1139 | (!invert_column && !invert_gradient2)) | 1139 | (!invert_column && !invert_gradient2)) |
1140 | { | 1140 | { |
1141 | *dest++ = r2; /* not inverted or */ | 1141 | *dest++ = r2; /* not inverted or */ |
1142 | *dest++ = g2; /* doubly inverted */ | 1142 | *dest++ = g2; /* doubly inverted */ |
1143 | *dest++ = b2; | 1143 | *dest++ = b2; |
1144 | } else { | 1144 | } else { |
1145 | *dest++ = r2_inv; | 1145 | *dest++ = r2_inv; |
1146 | *dest++ = g2_inv; /* singly inverted */ | 1146 | *dest++ = g2_inv; /* singly inverted */ |
1147 | *dest++ = b2_inv; | 1147 | *dest++ = b2_inv; |
1148 | } | 1148 | } |
1149 | } | 1149 | } |
1150 | } | 1150 | } |
1151 | } | 1151 | } |
1152 | 1152 | ||
1153 | /*--------------------------------------------------------------------------- | 1153 | /*--------------------------------------------------------------------------- |
1154 | Soft gradient-diamonds with scale = bgscale. Code contributed by Adam | 1154 | Soft gradient-diamonds with scale = bgscale. Code contributed by Adam |
1155 | M. Costello. | 1155 | M. Costello. |
1156 | ---------------------------------------------------------------------------*/ | 1156 | ---------------------------------------------------------------------------*/ |
1157 | 1157 | ||
1158 | } else if ((bg[pat].type & 0x07) == 1) { | 1158 | } else if ((bg[pat].type & 0x07) == 1) { |
1159 | 1159 | ||
1160 | hmax = (bgscale-1)/2; /* half the max weight of a color */ | 1160 | hmax = (bgscale-1)/2; /* half the max weight of a color */ |
1161 | max = 2*hmax; /* the max weight of a color */ | 1161 | max = 2*hmax; /* the max weight of a color */ |
1162 | 1162 | ||
1163 | r1 = rgb[bg[pat].rgb1_max].r; | 1163 | r1 = rgb[bg[pat].rgb1_max].r; |
1164 | g1 = rgb[bg[pat].rgb1_max].g; | 1164 | g1 = rgb[bg[pat].rgb1_max].g; |
1165 | b1 = rgb[bg[pat].rgb1_max].b; | 1165 | b1 = rgb[bg[pat].rgb1_max].b; |
1166 | r2 = rgb[bg[pat].rgb2_max].r; | 1166 | r2 = rgb[bg[pat].rgb2_max].r; |
1167 | g2 = rgb[bg[pat].rgb2_max].g; | 1167 | g2 = rgb[bg[pat].rgb2_max].g; |
1168 | b2 = rgb[bg[pat].rgb2_max].b; | 1168 | b2 = rgb[bg[pat].rgb2_max].b; |
1169 | 1169 | ||
1170 | for (row = 0; row < rpng2_info.height; ++row) { | 1170 | for (row = 0; row < rpng2_info.height; ++row) { |
1171 | yidx = (int)(row % bgscale); | 1171 | yidx = (int)(row % bgscale); |
1172 | if (yidx > hmax) | 1172 | if (yidx > hmax) |
1173 | yidx = bgscale-1 - yidx; | 1173 | yidx = bgscale-1 - yidx; |
1174 | dest = (char *)bg_data + row*bg_rowbytes; | 1174 | dest = (char *)bg_data + row*bg_rowbytes; |
1175 | for (i = 0; i < rpng2_info.width; ++i) { | 1175 | for (i = 0; i < rpng2_info.width; ++i) { |
1176 | xidx = (int)(i % bgscale); | 1176 | xidx = (int)(i % bgscale); |
1177 | if (xidx > hmax) | 1177 | if (xidx > hmax) |
1178 | xidx = bgscale-1 - xidx; | 1178 | xidx = bgscale-1 - xidx; |
1179 | k = xidx + yidx; | 1179 | k = xidx + yidx; |
1180 | *dest++ = (k*r1 + (max-k)*r2) / max; | 1180 | *dest++ = (k*r1 + (max-k)*r2) / max; |
1181 | *dest++ = (k*g1 + (max-k)*g2) / max; | 1181 | *dest++ = (k*g1 + (max-k)*g2) / max; |
1182 | *dest++ = (k*b1 + (max-k)*b2) / max; | 1182 | *dest++ = (k*b1 + (max-k)*b2) / max; |
1183 | } | 1183 | } |
1184 | } | 1184 | } |
1185 | 1185 | ||
1186 | /*--------------------------------------------------------------------------- | 1186 | /*--------------------------------------------------------------------------- |
1187 | Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- | 1187 | Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- |
1188 | soids will equal bgscale?]. This one is slow but very cool. Code con- | 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). | 1189 | tributed by Pieter S. van der Meulen (originally in Smalltalk). |
1190 | ---------------------------------------------------------------------------*/ | 1190 | ---------------------------------------------------------------------------*/ |
1191 | 1191 | ||
1192 | } else if ((bg[pat].type & 0x07) == 2) { | 1192 | } else if ((bg[pat].type & 0x07) == 2) { |
1193 | uch ch; | 1193 | uch ch; |
1194 | int ii, x, y, hw, hh, grayspot; | 1194 | int ii, x, y, hw, hh, grayspot; |
1195 | double freq, rotate, saturate, gray, intensity; | 1195 | double freq, rotate, saturate, gray, intensity; |
1196 | double angle=0.0, aoffset=0.0, maxDist, dist; | 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; | 1197 | double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; |
1198 | 1198 | ||
1199 | fprintf(stderr, "%s: computing radial background...", | 1199 | fprintf(stderr, "%s: computing radial background...", |
1200 | PROGNAME); | 1200 | PROGNAME); |
1201 | fflush(stderr); | 1201 | fflush(stderr); |
1202 | 1202 | ||
1203 | hh = (int)(rpng2_info.height / 2); | 1203 | hh = (int)(rpng2_info.height / 2); |
1204 | hw = (int)(rpng2_info.width / 2); | 1204 | hw = (int)(rpng2_info.width / 2); |
1205 | 1205 | ||
1206 | /* variables for radial waves: | 1206 | /* variables for radial waves: |
1207 | * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] | 1207 | * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] |
1208 | * freq: number of color beams originating from the center | 1208 | * freq: number of color beams originating from the center |
1209 | * grayspot: size of the graying center area (anti-alias) | 1209 | * grayspot: size of the graying center area (anti-alias) |
1210 | * rotate: rotation of the beams as a function of radius | 1210 | * rotate: rotation of the beams as a function of radius |
1211 | * saturate: saturation of beams' shape azimuthally | 1211 | * saturate: saturation of beams' shape azimuthally |
1212 | */ | 1212 | */ |
1213 | angle = CLIP(angle, 0.0, 360.0); | 1213 | angle = CLIP(angle, 0.0, 360.0); |
1214 | grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); | 1214 | grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); |
1215 | freq = MAX((double)bg[pat].bg_freq, 0.0); | 1215 | freq = MAX((double)bg[pat].bg_freq, 0.0); |
1216 | saturate = (double)bg[pat].bg_bsat * 0.1; | 1216 | saturate = (double)bg[pat].bg_bsat * 0.1; |
1217 | rotate = (double)bg[pat].bg_brot * 0.1; | 1217 | rotate = (double)bg[pat].bg_brot * 0.1; |
1218 | gray = 0.0; | 1218 | gray = 0.0; |
1219 | intensity = 0.0; | 1219 | intensity = 0.0; |
1220 | maxDist = (double)((hw*hw) + (hh*hh)); | 1220 | maxDist = (double)((hw*hw) + (hh*hh)); |
1221 | 1221 | ||
1222 | for (row = 0; row < rpng2_info.height; ++row) { | 1222 | for (row = 0; row < rpng2_info.height; ++row) { |
1223 | y = (int)(row - hh); | 1223 | y = (int)(row - hh); |
1224 | dest = (char *)bg_data + row*bg_rowbytes; | 1224 | dest = (char *)bg_data + row*bg_rowbytes; |
1225 | for (i = 0; i < rpng2_info.width; ++i) { | 1225 | for (i = 0; i < rpng2_info.width; ++i) { |
1226 | x = (int)(i - hw); | 1226 | x = (int)(i - hw); |
1227 | angle = (x == 0)? PI_2 : atan((double)y / (double)x); | 1227 | angle = (x == 0)? PI_2 : atan((double)y / (double)x); |
1228 | gray = (double)MAX(ABS(y), ABS(x)) / grayspot; | 1228 | gray = (double)MAX(ABS(y), ABS(x)) / grayspot; |
1229 | gray = MIN(1.0, gray); | 1229 | gray = MIN(1.0, gray); |
1230 | dist = (double)((x*x) + (y*y)) / maxDist; | 1230 | dist = (double)((x*x) + (y*y)) / maxDist; |
1231 | intensity = cos((angle+(rotate*dist*PI)) * freq) * | 1231 | intensity = cos((angle+(rotate*dist*PI)) * freq) * |
1232 | gray * saturate; | 1232 | gray * saturate; |
1233 | intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; | 1233 | intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; |
1234 | hue = (angle + PI) * INV_PI_360 + aoffset; | 1234 | hue = (angle + PI) * INV_PI_360 + aoffset; |
1235 | s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); | 1235 | s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); |
1236 | s = MIN(MAX(s,0.0), 1.0); | 1236 | s = MIN(MAX(s,0.0), 1.0); |
1237 | v = MIN(MAX(intensity,0.0), 1.0); | 1237 | v = MIN(MAX(intensity,0.0), 1.0); |
1238 | 1238 | ||
1239 | if (s == 0.0) { | 1239 | if (s == 0.0) { |
1240 | ch = (uch)(v * 255.0); | 1240 | ch = (uch)(v * 255.0); |
1241 | *dest++ = ch; | 1241 | *dest++ = ch; |
1242 | *dest++ = ch; | 1242 | *dest++ = ch; |
1243 | *dest++ = ch; | 1243 | *dest++ = ch; |
1244 | } else { | 1244 | } else { |
1245 | if ((hue < 0.0) || (hue >= 360.0)) | 1245 | if ((hue < 0.0) || (hue >= 360.0)) |
1246 | hue -= (((int)(hue / 360.0)) * 360.0); | 1246 | hue -= (((int)(hue / 360.0)) * 360.0); |
1247 | hue /= 60.0; | 1247 | hue /= 60.0; |
1248 | ii = (int)hue; | 1248 | ii = (int)hue; |
1249 | f = hue - (double)ii; | 1249 | f = hue - (double)ii; |
1250 | p = (1.0 - s) * v; | 1250 | p = (1.0 - s) * v; |
1251 | q = (1.0 - (s * f)) * v; | 1251 | q = (1.0 - (s * f)) * v; |
1252 | t = (1.0 - (s * (1.0 - f))) * v; | 1252 | t = (1.0 - (s * (1.0 - f))) * v; |
1253 | if (ii == 0) { red = v; green = t; blue = p; } | 1253 | if (ii == 0) { red = v; green = t; blue = p; } |
1254 | else if (ii == 1) { red = q; green = v; blue = p; } | 1254 | else if (ii == 1) { red = q; green = v; blue = p; } |
1255 | else if (ii == 2) { red = p; green = v; blue = t; } | 1255 | else if (ii == 2) { red = p; green = v; blue = t; } |
1256 | else if (ii == 3) { red = p; green = q; blue = v; } | 1256 | else if (ii == 3) { red = p; green = q; blue = v; } |
1257 | else if (ii == 4) { red = t; green = p; blue = v; } | 1257 | else if (ii == 4) { red = t; green = p; blue = v; } |
1258 | else if (ii == 5) { red = v; green = p; blue = q; } | 1258 | else if (ii == 5) { red = v; green = p; blue = q; } |
1259 | *dest++ = (uch)(red * 255.0); | 1259 | *dest++ = (uch)(red * 255.0); |
1260 | *dest++ = (uch)(green * 255.0); | 1260 | *dest++ = (uch)(green * 255.0); |
1261 | *dest++ = (uch)(blue * 255.0); | 1261 | *dest++ = (uch)(blue * 255.0); |
1262 | } | 1262 | } |
1263 | } | 1263 | } |
1264 | } | 1264 | } |
1265 | fprintf(stderr, "done.\n"); | 1265 | fprintf(stderr, "done.\n"); |
1266 | fflush(stderr); | 1266 | fflush(stderr); |
1267 | } | 1267 | } |
1268 | 1268 | ||
1269 | /*--------------------------------------------------------------------------- | 1269 | /*--------------------------------------------------------------------------- |
1270 | Blast background image to display buffer before beginning PNG decode. | 1270 | Blast background image to display buffer before beginning PNG decode. |
1271 | ---------------------------------------------------------------------------*/ | 1271 | ---------------------------------------------------------------------------*/ |
1272 | 1272 | ||
1273 | if (depth == 24 || depth == 32) { | 1273 | if (depth == 24 || depth == 32) { |
1274 | ulg red, green, blue; | 1274 | ulg red, green, blue; |
1275 | int bpp = ximage->bits_per_pixel; | 1275 | int bpp = ximage->bits_per_pixel; |
1276 | 1276 | ||
1277 | for (row = 0; row < rpng2_info.height; ++row) { | 1277 | for (row = 0; row < rpng2_info.height; ++row) { |
1278 | src = bg_data + row*bg_rowbytes; | 1278 | src = bg_data + row*bg_rowbytes; |
1279 | dest = ximage->data + row*ximage_rowbytes; | 1279 | dest = ximage->data + row*ximage_rowbytes; |
1280 | if (bpp == 32) { /* slightly optimized version */ | 1280 | if (bpp == 32) { /* slightly optimized version */ |
1281 | for (i = rpng2_info.width; i > 0; --i) { | 1281 | for (i = rpng2_info.width; i > 0; --i) { |
1282 | red = *src++; | 1282 | red = *src++; |
1283 | green = *src++; | 1283 | green = *src++; |
1284 | blue = *src++; | 1284 | blue = *src++; |
1285 | pixel = (red << RShift) | | 1285 | pixel = (red << RShift) | |
1286 | (green << GShift) | | 1286 | (green << GShift) | |
1287 | (blue << BShift); | 1287 | (blue << BShift); |
1288 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1288 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1289 | *dest++ = (char)((pixel >> 24) & 0xff); | 1289 | *dest++ = (char)((pixel >> 24) & 0xff); |
1290 | *dest++ = (char)((pixel >> 16) & 0xff); | 1290 | *dest++ = (char)((pixel >> 16) & 0xff); |
1291 | *dest++ = (char)((pixel >> 8) & 0xff); | 1291 | *dest++ = (char)((pixel >> 8) & 0xff); |
1292 | *dest++ = (char)( pixel & 0xff); | 1292 | *dest++ = (char)( pixel & 0xff); |
1293 | } | 1293 | } |
1294 | } else { | 1294 | } else { |
1295 | for (i = rpng2_info.width; i > 0; --i) { | 1295 | for (i = rpng2_info.width; i > 0; --i) { |
1296 | red = *src++; | 1296 | red = *src++; |
1297 | green = *src++; | 1297 | green = *src++; |
1298 | blue = *src++; | 1298 | blue = *src++; |
1299 | pixel = (red << RShift) | | 1299 | pixel = (red << RShift) | |
1300 | (green << GShift) | | 1300 | (green << GShift) | |
1301 | (blue << BShift); | 1301 | (blue << BShift); |
1302 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1302 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1303 | /* GRR BUG? this assumes bpp == 24 & bits are packed low */ | 1303 | /* GRR BUG? this assumes bpp == 24 & bits are packed low */ |
1304 | /* (probably need to use RShift, RMask, etc.) */ | 1304 | /* (probably need to use RShift, RMask, etc.) */ |
1305 | *dest++ = (char)((pixel >> 16) & 0xff); | 1305 | *dest++ = (char)((pixel >> 16) & 0xff); |
1306 | *dest++ = (char)((pixel >> 8) & 0xff); | 1306 | *dest++ = (char)((pixel >> 8) & 0xff); |
1307 | *dest++ = (char)( pixel & 0xff); | 1307 | *dest++ = (char)( pixel & 0xff); |
1308 | } | 1308 | } |
1309 | } | 1309 | } |
1310 | } | 1310 | } |
1311 | 1311 | ||
1312 | } else if (depth == 16) { | 1312 | } else if (depth == 16) { |
1313 | ush red, green, blue; | 1313 | ush red, green, blue; |
1314 | 1314 | ||
1315 | for (row = 0; row < rpng2_info.height; ++row) { | 1315 | for (row = 0; row < rpng2_info.height; ++row) { |
1316 | src = bg_data + row*bg_rowbytes; | 1316 | src = bg_data + row*bg_rowbytes; |
1317 | dest = ximage->data + row*ximage_rowbytes; | 1317 | dest = ximage->data + row*ximage_rowbytes; |
1318 | for (i = rpng2_info.width; i > 0; --i) { | 1318 | for (i = rpng2_info.width; i > 0; --i) { |
1319 | red = ((ush)(*src) << 8); ++src; | 1319 | red = ((ush)(*src) << 8); ++src; |
1320 | green = ((ush)(*src) << 8); ++src; | 1320 | green = ((ush)(*src) << 8); ++src; |
1321 | blue = ((ush)(*src) << 8); ++src; | 1321 | blue = ((ush)(*src) << 8); ++src; |
1322 | pixel = ((red >> RShift) & RMask) | | 1322 | pixel = ((red >> RShift) & RMask) | |
1323 | ((green >> GShift) & GMask) | | 1323 | ((green >> GShift) & GMask) | |
1324 | ((blue >> BShift) & BMask); | 1324 | ((blue >> BShift) & BMask); |
1325 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1325 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1326 | *dest++ = (char)((pixel >> 8) & 0xff); | 1326 | *dest++ = (char)((pixel >> 8) & 0xff); |
1327 | *dest++ = (char)( pixel & 0xff); | 1327 | *dest++ = (char)( pixel & 0xff); |
1328 | } | 1328 | } |
1329 | } | 1329 | } |
1330 | 1330 | ||
1331 | } else /* depth == 8 */ { | 1331 | } else /* depth == 8 */ { |
1332 | 1332 | ||
1333 | /* GRR: add 8-bit support */ | 1333 | /* GRR: add 8-bit support */ |
1334 | 1334 | ||
1335 | } | 1335 | } |
1336 | 1336 | ||
1337 | XPutImage(display, window, gc, ximage, 0, 0, 0, 0, rpng2_info.width, | 1337 | XPutImage(display, window, gc, ximage, 0, 0, 0, 0, rpng2_info.width, |
1338 | rpng2_info.height); | 1338 | rpng2_info.height); |
1339 | 1339 | ||
1340 | return 0; | 1340 | return 0; |
1341 | 1341 | ||
1342 | } /* end function rpng2_x_load_bg_image() */ | 1342 | } /* end function rpng2_x_load_bg_image() */ |
1343 | 1343 | ||
1344 | 1344 | ||
1345 | 1345 | ||
1346 | 1346 | ||
1347 | 1347 | ||
1348 | static void rpng2_x_display_row(ulg row) | 1348 | static void rpng2_x_display_row(ulg row) |
1349 | { | 1349 | { |
1350 | uch bg_red = rpng2_info.bg_red; | 1350 | uch bg_red = rpng2_info.bg_red; |
1351 | uch bg_green = rpng2_info.bg_green; | 1351 | uch bg_green = rpng2_info.bg_green; |
1352 | uch bg_blue = rpng2_info.bg_blue; | 1352 | uch bg_blue = rpng2_info.bg_blue; |
1353 | uch *src, *src2=NULL; | 1353 | uch *src, *src2=NULL; |
1354 | char *dest; | 1354 | char *dest; |
1355 | uch r, g, b, a; | 1355 | uch r, g, b, a; |
1356 | int ximage_rowbytes = ximage->bytes_per_line; | 1356 | int ximage_rowbytes = ximage->bytes_per_line; |
1357 | ulg i, pixel; | 1357 | ulg i, pixel; |
1358 | static int rows=0, prevpass=(-1); | 1358 | static int rows=0, prevpass=(-1); |
1359 | static ulg firstrow; | 1359 | static ulg firstrow; |
1360 | 1360 | ||
1361 | /*--------------------------------------------------------------------------- | 1361 | /*--------------------------------------------------------------------------- |
1362 | rows and firstrow simply track how many rows (and which ones) have not | 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 | 1363 | yet been displayed; alternatively, we could call XPutImage() for every |
1364 | row and not bother with the records-keeping. | 1364 | row and not bother with the records-keeping. |
1365 | ---------------------------------------------------------------------------*/ | 1365 | ---------------------------------------------------------------------------*/ |
1366 | 1366 | ||
1367 | Trace((stderr, "beginning rpng2_x_display_row()\n")) | 1367 | Trace((stderr, "beginning rpng2_x_display_row()\n")) |
1368 | 1368 | ||
1369 | if (rpng2_info.pass != prevpass) { | 1369 | if (rpng2_info.pass != prevpass) { |
1370 | if (pause_after_pass && rpng2_info.pass > 0) { | 1370 | if (pause_after_pass && rpng2_info.pass > 0) { |
1371 | XEvent e; | 1371 | XEvent e; |
1372 | KeySym k; | 1372 | KeySym k; |
1373 | 1373 | ||
1374 | fprintf(stderr, | 1374 | fprintf(stderr, |
1375 | "%s: end of pass %d of 7; click in image window to continue\n", | 1375 | "%s: end of pass %d of 7; click in image window to continue\n", |
1376 | PROGNAME, prevpass + 1); | 1376 | PROGNAME, prevpass + 1); |
1377 | do | 1377 | do |
1378 | XNextEvent(display, &e); | 1378 | XNextEvent(display, &e); |
1379 | while (!QUIT(e,k)); | 1379 | while (!QUIT(e,k)); |
1380 | } | 1380 | } |
1381 | fprintf(stderr, "%s: pass %d of 7\r", PROGNAME, rpng2_info.pass + 1); | 1381 | fprintf(stderr, "%s: pass %d of 7\r", PROGNAME, rpng2_info.pass + 1); |
1382 | fflush(stderr); | 1382 | fflush(stderr); |
1383 | prevpass = rpng2_info.pass; | 1383 | prevpass = rpng2_info.pass; |
1384 | } | 1384 | } |
1385 | 1385 | ||
1386 | if (rows == 0) | 1386 | if (rows == 0) |
1387 | firstrow = row; /* first row that is not yet displayed */ | 1387 | firstrow = row; /* first row that is not yet displayed */ |
1388 | 1388 | ||
1389 | ++rows; /* count of rows received but not yet displayed */ | 1389 | ++rows; /* count of rows received but not yet displayed */ |
1390 | 1390 | ||
1391 | /*--------------------------------------------------------------------------- | 1391 | /*--------------------------------------------------------------------------- |
1392 | Aside from the use of the rpng2_info struct, the lack of an outer loop | 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)" | 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- | 1394 | tests, this routine is identical to rpng_x_display_image() in the non- |
1395 | progressive version of the program. | 1395 | progressive version of the program. |
1396 | ---------------------------------------------------------------------------*/ | 1396 | ---------------------------------------------------------------------------*/ |
1397 | 1397 | ||
1398 | if (depth == 24 || depth == 32) { | 1398 | if (depth == 24 || depth == 32) { |
1399 | ulg red, green, blue; | 1399 | ulg red, green, blue; |
1400 | int bpp = ximage->bits_per_pixel; | 1400 | int bpp = ximage->bits_per_pixel; |
1401 | 1401 | ||
1402 | src = rpng2_info.image_data + row*rpng2_info.rowbytes; | 1402 | src = rpng2_info.image_data + row*rpng2_info.rowbytes; |
1403 | if (bg_image) | 1403 | if (bg_image) |
1404 | src2 = bg_data + row*bg_rowbytes; | 1404 | src2 = bg_data + row*bg_rowbytes; |
1405 | dest = ximage->data + row*ximage_rowbytes; | 1405 | dest = ximage->data + row*ximage_rowbytes; |
1406 | if (rpng2_info.channels == 3) { | 1406 | if (rpng2_info.channels == 3) { |
1407 | for (i = rpng2_info.width; i > 0; --i) { | 1407 | for (i = rpng2_info.width; i > 0; --i) { |
1408 | red = *src++; | 1408 | red = *src++; |
1409 | green = *src++; | 1409 | green = *src++; |
1410 | blue = *src++; | 1410 | blue = *src++; |
1411 | pixel = (red << RShift) | | 1411 | pixel = (red << RShift) | |
1412 | (green << GShift) | | 1412 | (green << GShift) | |
1413 | (blue << BShift); | 1413 | (blue << BShift); |
1414 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1414 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1415 | if (bpp == 32) { | 1415 | if (bpp == 32) { |
1416 | *dest++ = (char)((pixel >> 24) & 0xff); | 1416 | *dest++ = (char)((pixel >> 24) & 0xff); |
1417 | *dest++ = (char)((pixel >> 16) & 0xff); | 1417 | *dest++ = (char)((pixel >> 16) & 0xff); |
1418 | *dest++ = (char)((pixel >> 8) & 0xff); | 1418 | *dest++ = (char)((pixel >> 8) & 0xff); |
1419 | *dest++ = (char)( pixel & 0xff); | 1419 | *dest++ = (char)( pixel & 0xff); |
1420 | } else { | 1420 | } else { |
1421 | /* GRR BUG? this assumes bpp == 24 & bits are packed low */ | 1421 | /* GRR BUG? this assumes bpp == 24 & bits are packed low */ |
1422 | /* (probably need to use RShift, RMask, etc.) */ | 1422 | /* (probably need to use RShift, RMask, etc.) */ |
1423 | *dest++ = (char)((pixel >> 16) & 0xff); | 1423 | *dest++ = (char)((pixel >> 16) & 0xff); |
1424 | *dest++ = (char)((pixel >> 8) & 0xff); | 1424 | *dest++ = (char)((pixel >> 8) & 0xff); |
1425 | *dest++ = (char)( pixel & 0xff); | 1425 | *dest++ = (char)( pixel & 0xff); |
1426 | } | 1426 | } |
1427 | } | 1427 | } |
1428 | } else /* if (rpng2_info.channels == 4) */ { | 1428 | } else /* if (rpng2_info.channels == 4) */ { |
1429 | for (i = rpng2_info.width; i > 0; --i) { | 1429 | for (i = rpng2_info.width; i > 0; --i) { |
1430 | r = *src++; | 1430 | r = *src++; |
1431 | g = *src++; | 1431 | g = *src++; |
1432 | b = *src++; | 1432 | b = *src++; |
1433 | a = *src++; | 1433 | a = *src++; |
1434 | if (bg_image) { | 1434 | if (bg_image) { |
1435 | bg_red = *src2++; | 1435 | bg_red = *src2++; |
1436 | bg_green = *src2++; | 1436 | bg_green = *src2++; |
1437 | bg_blue = *src2++; | 1437 | bg_blue = *src2++; |
1438 | } | 1438 | } |
1439 | if (a == 255) { | 1439 | if (a == 255) { |
1440 | red = r; | 1440 | red = r; |
1441 | green = g; | 1441 | green = g; |
1442 | blue = b; | 1442 | blue = b; |
1443 | } else if (a == 0) { | 1443 | } else if (a == 0) { |
1444 | red = bg_red; | 1444 | red = bg_red; |
1445 | green = bg_green; | 1445 | green = bg_green; |
1446 | blue = bg_blue; | 1446 | blue = bg_blue; |
1447 | } else { | 1447 | } else { |
1448 | /* this macro (from png.h) composites the foreground | 1448 | /* this macro (from png.h) composites the foreground |
1449 | * and background values and puts the result into the | 1449 | * and background values and puts the result into the |
1450 | * first argument */ | 1450 | * first argument */ |
1451 | alpha_composite(red, r, a, bg_red); | 1451 | alpha_composite(red, r, a, bg_red); |
1452 | alpha_composite(green, g, a, bg_green); | 1452 | alpha_composite(green, g, a, bg_green); |
1453 | alpha_composite(blue, b, a, bg_blue); | 1453 | alpha_composite(blue, b, a, bg_blue); |
1454 | } | 1454 | } |
1455 | pixel = (red << RShift) | | 1455 | pixel = (red << RShift) | |
1456 | (green << GShift) | | 1456 | (green << GShift) | |
1457 | (blue << BShift); | 1457 | (blue << BShift); |
1458 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1458 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1459 | if (bpp == 32) { | 1459 | if (bpp == 32) { |
1460 | *dest++ = (char)((pixel >> 24) & 0xff); | 1460 | *dest++ = (char)((pixel >> 24) & 0xff); |
1461 | *dest++ = (char)((pixel >> 16) & 0xff); | 1461 | *dest++ = (char)((pixel >> 16) & 0xff); |
1462 | *dest++ = (char)((pixel >> 8) & 0xff); | 1462 | *dest++ = (char)((pixel >> 8) & 0xff); |
1463 | *dest++ = (char)( pixel & 0xff); | 1463 | *dest++ = (char)( pixel & 0xff); |
1464 | } else { | 1464 | } else { |
1465 | /* GRR BUG? this assumes bpp == 24 & bits are packed low */ | 1465 | /* GRR BUG? this assumes bpp == 24 & bits are packed low */ |
1466 | /* (probably need to use RShift, RMask, etc.) */ | 1466 | /* (probably need to use RShift, RMask, etc.) */ |
1467 | *dest++ = (char)((pixel >> 16) & 0xff); | 1467 | *dest++ = (char)((pixel >> 16) & 0xff); |
1468 | *dest++ = (char)((pixel >> 8) & 0xff); | 1468 | *dest++ = (char)((pixel >> 8) & 0xff); |
1469 | *dest++ = (char)( pixel & 0xff); | 1469 | *dest++ = (char)( pixel & 0xff); |
1470 | } | 1470 | } |
1471 | } | 1471 | } |
1472 | } | 1472 | } |
1473 | 1473 | ||
1474 | } else if (depth == 16) { | 1474 | } else if (depth == 16) { |
1475 | ush red, green, blue; | 1475 | ush red, green, blue; |
1476 | 1476 | ||
1477 | src = rpng2_info.row_pointers[row]; | 1477 | src = rpng2_info.row_pointers[row]; |
1478 | if (bg_image) | 1478 | if (bg_image) |
1479 | src2 = bg_data + row*bg_rowbytes; | 1479 | src2 = bg_data + row*bg_rowbytes; |
1480 | dest = ximage->data + row*ximage_rowbytes; | 1480 | dest = ximage->data + row*ximage_rowbytes; |
1481 | if (rpng2_info.channels == 3) { | 1481 | if (rpng2_info.channels == 3) { |
1482 | for (i = rpng2_info.width; i > 0; --i) { | 1482 | for (i = rpng2_info.width; i > 0; --i) { |
1483 | red = ((ush)(*src) << 8); | 1483 | red = ((ush)(*src) << 8); |
1484 | ++src; | 1484 | ++src; |
1485 | green = ((ush)(*src) << 8); | 1485 | green = ((ush)(*src) << 8); |
1486 | ++src; | 1486 | ++src; |
1487 | blue = ((ush)(*src) << 8); | 1487 | blue = ((ush)(*src) << 8); |
1488 | ++src; | 1488 | ++src; |
1489 | pixel = ((red >> RShift) & RMask) | | 1489 | pixel = ((red >> RShift) & RMask) | |
1490 | ((green >> GShift) & GMask) | | 1490 | ((green >> GShift) & GMask) | |
1491 | ((blue >> BShift) & BMask); | 1491 | ((blue >> BShift) & BMask); |
1492 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1492 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1493 | *dest++ = (char)((pixel >> 8) & 0xff); | 1493 | *dest++ = (char)((pixel >> 8) & 0xff); |
1494 | *dest++ = (char)( pixel & 0xff); | 1494 | *dest++ = (char)( pixel & 0xff); |
1495 | } | 1495 | } |
1496 | } else /* if (rpng2_info.channels == 4) */ { | 1496 | } else /* if (rpng2_info.channels == 4) */ { |
1497 | for (i = rpng2_info.width; i > 0; --i) { | 1497 | for (i = rpng2_info.width; i > 0; --i) { |
1498 | r = *src++; | 1498 | r = *src++; |
1499 | g = *src++; | 1499 | g = *src++; |
1500 | b = *src++; | 1500 | b = *src++; |
1501 | a = *src++; | 1501 | a = *src++; |
1502 | if (bg_image) { | 1502 | if (bg_image) { |
1503 | bg_red = *src2++; | 1503 | bg_red = *src2++; |
1504 | bg_green = *src2++; | 1504 | bg_green = *src2++; |
1505 | bg_blue = *src2++; | 1505 | bg_blue = *src2++; |
1506 | } | 1506 | } |
1507 | if (a == 255) { | 1507 | if (a == 255) { |
1508 | red = ((ush)r << 8); | 1508 | red = ((ush)r << 8); |
1509 | green = ((ush)g << 8); | 1509 | green = ((ush)g << 8); |
1510 | blue = ((ush)b << 8); | 1510 | blue = ((ush)b << 8); |
1511 | } else if (a == 0) { | 1511 | } else if (a == 0) { |
1512 | red = ((ush)bg_red << 8); | 1512 | red = ((ush)bg_red << 8); |
1513 | green = ((ush)bg_green << 8); | 1513 | green = ((ush)bg_green << 8); |
1514 | blue = ((ush)bg_blue << 8); | 1514 | blue = ((ush)bg_blue << 8); |
1515 | } else { | 1515 | } else { |
1516 | /* this macro (from png.h) composites the foreground | 1516 | /* this macro (from png.h) composites the foreground |
1517 | * and background values and puts the result back into | 1517 | * and background values and puts the result back into |
1518 | * the first argument (== fg byte here: safe) */ | 1518 | * the first argument (== fg byte here: safe) */ |
1519 | alpha_composite(r, r, a, bg_red); | 1519 | alpha_composite(r, r, a, bg_red); |
1520 | alpha_composite(g, g, a, bg_green); | 1520 | alpha_composite(g, g, a, bg_green); |
1521 | alpha_composite(b, b, a, bg_blue); | 1521 | alpha_composite(b, b, a, bg_blue); |
1522 | red = ((ush)r << 8); | 1522 | red = ((ush)r << 8); |
1523 | green = ((ush)g << 8); | 1523 | green = ((ush)g << 8); |
1524 | blue = ((ush)b << 8); | 1524 | blue = ((ush)b << 8); |
1525 | } | 1525 | } |
1526 | pixel = ((red >> RShift) & RMask) | | 1526 | pixel = ((red >> RShift) & RMask) | |
1527 | ((green >> GShift) & GMask) | | 1527 | ((green >> GShift) & GMask) | |
1528 | ((blue >> BShift) & BMask); | 1528 | ((blue >> BShift) & BMask); |
1529 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1529 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1530 | *dest++ = (char)((pixel >> 8) & 0xff); | 1530 | *dest++ = (char)((pixel >> 8) & 0xff); |
1531 | *dest++ = (char)( pixel & 0xff); | 1531 | *dest++ = (char)( pixel & 0xff); |
1532 | } | 1532 | } |
1533 | } | 1533 | } |
1534 | 1534 | ||
1535 | } else /* depth == 8 */ { | 1535 | } else /* depth == 8 */ { |
1536 | 1536 | ||
1537 | /* GRR: add 8-bit support */ | 1537 | /* GRR: add 8-bit support */ |
1538 | 1538 | ||
1539 | } | 1539 | } |
1540 | 1540 | ||
1541 | 1541 | ||
1542 | /*--------------------------------------------------------------------------- | 1542 | /*--------------------------------------------------------------------------- |
1543 | Display after every 16 rows or when on one of last two rows. (Region | 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 | 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 | 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 | 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. | 1547 | row so "sparse" passes don't go twice as fast. |
1548 | ---------------------------------------------------------------------------*/ | 1548 | ---------------------------------------------------------------------------*/ |
1549 | 1549 | ||
1550 | if (demo_timing && (row - firstrow >= 16 || row >= rpng2_info.height-2)) { | 1550 | if (demo_timing && (row - firstrow >= 16 || row >= rpng2_info.height-2)) { |
1551 | XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0, | 1551 | XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0, |
1552 | (int)firstrow, rpng2_info.width, row - firstrow + 1); | 1552 | (int)firstrow, rpng2_info.width, row - firstrow + 1); |
1553 | XFlush(display); | 1553 | XFlush(display); |
1554 | rows = 0; | 1554 | rows = 0; |
1555 | usleep(usleep_duration); | 1555 | usleep(usleep_duration); |
1556 | } else | 1556 | } else |
1557 | if (!demo_timing && ((rows & 0xf) == 0 || row >= rpng2_info.height-2)) { | 1557 | if (!demo_timing && ((rows & 0xf) == 0 || row >= rpng2_info.height-2)) { |
1558 | XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0, | 1558 | XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0, |
1559 | (int)firstrow, rpng2_info.width, row - firstrow + 1); | 1559 | (int)firstrow, rpng2_info.width, row - firstrow + 1); |
1560 | XFlush(display); | 1560 | XFlush(display); |
1561 | rows = 0; | 1561 | rows = 0; |
1562 | } | 1562 | } |
1563 | 1563 | ||
1564 | } | 1564 | } |
1565 | 1565 | ||
1566 | 1566 | ||
1567 | 1567 | ||
1568 | 1568 | ||
1569 | 1569 | ||
1570 | static void rpng2_x_finish_display(void) | 1570 | static void rpng2_x_finish_display(void) |
1571 | { | 1571 | { |
1572 | Trace((stderr, "beginning rpng2_x_finish_display()\n")) | 1572 | Trace((stderr, "beginning rpng2_x_finish_display()\n")) |
1573 | 1573 | ||
1574 | /* last row has already been displayed by rpng2_x_display_row(), so we | 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 | 1575 | * have nothing to do here except set a flag and let the user know that |
1576 | * the image is done */ | 1576 | * the image is done */ |
1577 | 1577 | ||
1578 | rpng2_info.state = kDone; | 1578 | rpng2_info.state = kDone; |
1579 | printf( | 1579 | printf( |
1580 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); | 1580 | "Done. Press Q, Esc or mouse button 1 (within image window) to quit.\n"); |
1581 | fflush(stdout); | 1581 | fflush(stdout); |
1582 | } | 1582 | } |
1583 | 1583 | ||
1584 | 1584 | ||
1585 | 1585 | ||
1586 | 1586 | ||
1587 | 1587 | ||
1588 | static void rpng2_x_redisplay_image(ulg startcol, ulg startrow, | 1588 | static void rpng2_x_redisplay_image(ulg startcol, ulg startrow, |
1589 | ulg width, ulg height) | 1589 | ulg width, ulg height) |
1590 | { | 1590 | { |
1591 | uch bg_red = rpng2_info.bg_red; | 1591 | uch bg_red = rpng2_info.bg_red; |
1592 | uch bg_green = rpng2_info.bg_green; | 1592 | uch bg_green = rpng2_info.bg_green; |
1593 | uch bg_blue = rpng2_info.bg_blue; | 1593 | uch bg_blue = rpng2_info.bg_blue; |
1594 | uch *src, *src2=NULL; | 1594 | uch *src, *src2=NULL; |
1595 | char *dest; | 1595 | char *dest; |
1596 | uch r, g, b, a; | 1596 | uch r, g, b, a; |
1597 | ulg i, row, lastrow = 0; | 1597 | ulg i, row, lastrow = 0; |
1598 | ulg pixel; | 1598 | ulg pixel; |
1599 | int ximage_rowbytes = ximage->bytes_per_line; | 1599 | int ximage_rowbytes = ximage->bytes_per_line; |
1600 | 1600 | ||
1601 | 1601 | ||
1602 | Trace((stderr, "beginning display loop (image_channels == %d)\n", | 1602 | Trace((stderr, "beginning display loop (image_channels == %d)\n", |
1603 | rpng2_info.channels)) | 1603 | rpng2_info.channels)) |
1604 | Trace((stderr, " (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\n", | 1604 | Trace((stderr, " (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\n", |
1605 | rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes)) | 1605 | rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes)) |
1606 | Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) | 1606 | Trace((stderr, " (bpp = %d)\n", ximage->bits_per_pixel)) |
1607 | Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? | 1607 | Trace((stderr, " (byte_order = %s)\n", ximage->byte_order == MSBFirst? |
1608 | "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) | 1608 | "MSBFirst" : (ximage->byte_order == LSBFirst? "LSBFirst" : "unknown"))) |
1609 | 1609 | ||
1610 | /*--------------------------------------------------------------------------- | 1610 | /*--------------------------------------------------------------------------- |
1611 | Aside from the use of the rpng2_info struct and of src2 (for background | 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- | 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 | 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 | 1614 | of the image against a new background happens after the image is fully |
1615 | decoded and therefore is, by definition, non-progressive. | 1615 | decoded and therefore is, by definition, non-progressive. |
1616 | ---------------------------------------------------------------------------*/ | 1616 | ---------------------------------------------------------------------------*/ |
1617 | 1617 | ||
1618 | if (depth == 24 || depth == 32) { | 1618 | if (depth == 24 || depth == 32) { |
1619 | ulg red, green, blue; | 1619 | ulg red, green, blue; |
1620 | int bpp = ximage->bits_per_pixel; | 1620 | int bpp = ximage->bits_per_pixel; |
1621 | 1621 | ||
1622 | for (lastrow = row = startrow; row < startrow+height; ++row) { | 1622 | for (lastrow = row = startrow; row < startrow+height; ++row) { |
1623 | src = rpng2_info.image_data + row*rpng2_info.rowbytes; | 1623 | src = rpng2_info.image_data + row*rpng2_info.rowbytes; |
1624 | if (bg_image) | 1624 | if (bg_image) |
1625 | src2 = bg_data + row*bg_rowbytes; | 1625 | src2 = bg_data + row*bg_rowbytes; |
1626 | dest = ximage->data + row*ximage_rowbytes; | 1626 | dest = ximage->data + row*ximage_rowbytes; |
1627 | if (rpng2_info.channels == 3) { | 1627 | if (rpng2_info.channels == 3) { |
1628 | for (i = rpng2_info.width; i > 0; --i) { | 1628 | for (i = rpng2_info.width; i > 0; --i) { |
1629 | red = *src++; | 1629 | red = *src++; |
1630 | green = *src++; | 1630 | green = *src++; |
1631 | blue = *src++; | 1631 | blue = *src++; |
1632 | #ifdef NO_24BIT_MASKS | 1632 | #ifdef NO_24BIT_MASKS |
1633 | pixel = (red << RShift) | | 1633 | pixel = (red << RShift) | |
1634 | (green << GShift) | | 1634 | (green << GShift) | |
1635 | (blue << BShift); | 1635 | (blue << BShift); |
1636 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1636 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1637 | if (bpp == 32) { | 1637 | if (bpp == 32) { |
1638 | *dest++ = (char)((pixel >> 24) & 0xff); | 1638 | *dest++ = (char)((pixel >> 24) & 0xff); |
1639 | *dest++ = (char)((pixel >> 16) & 0xff); | 1639 | *dest++ = (char)((pixel >> 16) & 0xff); |
1640 | *dest++ = (char)((pixel >> 8) & 0xff); | 1640 | *dest++ = (char)((pixel >> 8) & 0xff); |
1641 | *dest++ = (char)( pixel & 0xff); | 1641 | *dest++ = (char)( pixel & 0xff); |
1642 | } else { | 1642 | } else { |
1643 | /* this assumes bpp == 24 & bits are packed low */ | 1643 | /* this assumes bpp == 24 & bits are packed low */ |
1644 | /* (probably need to use RShift, RMask, etc.) */ | 1644 | /* (probably need to use RShift, RMask, etc.) */ |
1645 | *dest++ = (char)((pixel >> 16) & 0xff); | 1645 | *dest++ = (char)((pixel >> 16) & 0xff); |
1646 | *dest++ = (char)((pixel >> 8) & 0xff); | 1646 | *dest++ = (char)((pixel >> 8) & 0xff); |
1647 | *dest++ = (char)( pixel & 0xff); | 1647 | *dest++ = (char)( pixel & 0xff); |
1648 | } | 1648 | } |
1649 | #else | 1649 | #else |
1650 | red = (RShift < 0)? red << (-RShift) : red >> RShift; | 1650 | red = (RShift < 0)? red << (-RShift) : red >> RShift; |
1651 | green = (GShift < 0)? green << (-GShift) : green >> GShift; | 1651 | green = (GShift < 0)? green << (-GShift) : green >> GShift; |
1652 | blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; | 1652 | blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; |
1653 | pixel = (red & RMask) | (green & GMask) | (blue & BMask); | 1653 | pixel = (red & RMask) | (green & GMask) | (blue & BMask); |
1654 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1654 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1655 | if (bpp == 32) { | 1655 | if (bpp == 32) { |
1656 | *dest++ = (char)((pixel >> 24) & 0xff); | 1656 | *dest++ = (char)((pixel >> 24) & 0xff); |
1657 | *dest++ = (char)((pixel >> 16) & 0xff); | 1657 | *dest++ = (char)((pixel >> 16) & 0xff); |
1658 | *dest++ = (char)((pixel >> 8) & 0xff); | 1658 | *dest++ = (char)((pixel >> 8) & 0xff); |
1659 | *dest++ = (char)( pixel & 0xff); | 1659 | *dest++ = (char)( pixel & 0xff); |
1660 | } else { | 1660 | } else { |
1661 | /* GRR BUG */ | 1661 | /* GRR BUG */ |
1662 | /* this assumes bpp == 24 & bits are packed low */ | 1662 | /* this assumes bpp == 24 & bits are packed low */ |
1663 | /* (probably need to use RShift/RMask/etc. here, too) */ | 1663 | /* (probably need to use RShift/RMask/etc. here, too) */ |
1664 | *dest++ = (char)((pixel >> 16) & 0xff); | 1664 | *dest++ = (char)((pixel >> 16) & 0xff); |
1665 | *dest++ = (char)((pixel >> 8) & 0xff); | 1665 | *dest++ = (char)((pixel >> 8) & 0xff); |
1666 | *dest++ = (char)( pixel & 0xff); | 1666 | *dest++ = (char)( pixel & 0xff); |
1667 | } | 1667 | } |
1668 | #endif | 1668 | #endif |
1669 | } | 1669 | } |
1670 | 1670 | ||
1671 | } else /* if (rpng2_info.channels == 4) */ { | 1671 | } else /* if (rpng2_info.channels == 4) */ { |
1672 | for (i = rpng2_info.width; i > 0; --i) { | 1672 | for (i = rpng2_info.width; i > 0; --i) { |
1673 | r = *src++; | 1673 | r = *src++; |
1674 | g = *src++; | 1674 | g = *src++; |
1675 | b = *src++; | 1675 | b = *src++; |
1676 | a = *src++; | 1676 | a = *src++; |
1677 | if (bg_image) { | 1677 | if (bg_image) { |
1678 | bg_red = *src2++; | 1678 | bg_red = *src2++; |
1679 | bg_green = *src2++; | 1679 | bg_green = *src2++; |
1680 | bg_blue = *src2++; | 1680 | bg_blue = *src2++; |
1681 | } | 1681 | } |
1682 | if (a == 255) { | 1682 | if (a == 255) { |
1683 | red = r; | 1683 | red = r; |
1684 | green = g; | 1684 | green = g; |
1685 | blue = b; | 1685 | blue = b; |
1686 | } else if (a == 0) { | 1686 | } else if (a == 0) { |
1687 | red = bg_red; | 1687 | red = bg_red; |
1688 | green = bg_green; | 1688 | green = bg_green; |
1689 | blue = bg_blue; | 1689 | blue = bg_blue; |
1690 | } else { | 1690 | } else { |
1691 | /* this macro (from png.h) composites the foreground | 1691 | /* this macro (from png.h) composites the foreground |
1692 | * and background values and puts the result into the | 1692 | * and background values and puts the result into the |
1693 | * first argument */ | 1693 | * first argument */ |
1694 | alpha_composite(red, r, a, bg_red); | 1694 | alpha_composite(red, r, a, bg_red); |
1695 | alpha_composite(green, g, a, bg_green); | 1695 | alpha_composite(green, g, a, bg_green); |
1696 | alpha_composite(blue, b, a, bg_blue); | 1696 | alpha_composite(blue, b, a, bg_blue); |
1697 | } | 1697 | } |
1698 | #ifdef NO_24BIT_MASKS | 1698 | #ifdef NO_24BIT_MASKS |
1699 | pixel = (red << RShift) | | 1699 | pixel = (red << RShift) | |
1700 | (green << GShift) | | 1700 | (green << GShift) | |
1701 | (blue << BShift); | 1701 | (blue << BShift); |
1702 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1702 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1703 | if (bpp == 32) { | 1703 | if (bpp == 32) { |
1704 | *dest++ = (char)((pixel >> 24) & 0xff); | 1704 | *dest++ = (char)((pixel >> 24) & 0xff); |
1705 | *dest++ = (char)((pixel >> 16) & 0xff); | 1705 | *dest++ = (char)((pixel >> 16) & 0xff); |
1706 | *dest++ = (char)((pixel >> 8) & 0xff); | 1706 | *dest++ = (char)((pixel >> 8) & 0xff); |
1707 | *dest++ = (char)( pixel & 0xff); | 1707 | *dest++ = (char)( pixel & 0xff); |
1708 | } else { | 1708 | } else { |
1709 | /* this assumes bpp == 24 & bits are packed low */ | 1709 | /* this assumes bpp == 24 & bits are packed low */ |
1710 | /* (probably need to use RShift, RMask, etc.) */ | 1710 | /* (probably need to use RShift, RMask, etc.) */ |
1711 | *dest++ = (char)((pixel >> 16) & 0xff); | 1711 | *dest++ = (char)((pixel >> 16) & 0xff); |
1712 | *dest++ = (char)((pixel >> 8) & 0xff); | 1712 | *dest++ = (char)((pixel >> 8) & 0xff); |
1713 | *dest++ = (char)( pixel & 0xff); | 1713 | *dest++ = (char)( pixel & 0xff); |
1714 | } | 1714 | } |
1715 | #else | 1715 | #else |
1716 | red = (RShift < 0)? red << (-RShift) : red >> RShift; | 1716 | red = (RShift < 0)? red << (-RShift) : red >> RShift; |
1717 | green = (GShift < 0)? green << (-GShift) : green >> GShift; | 1717 | green = (GShift < 0)? green << (-GShift) : green >> GShift; |
1718 | blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; | 1718 | blue = (BShift < 0)? blue << (-BShift) : blue >> BShift; |
1719 | pixel = (red & RMask) | (green & GMask) | (blue & BMask); | 1719 | pixel = (red & RMask) | (green & GMask) | (blue & BMask); |
1720 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1720 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1721 | if (bpp == 32) { | 1721 | if (bpp == 32) { |
1722 | *dest++ = (char)((pixel >> 24) & 0xff); | 1722 | *dest++ = (char)((pixel >> 24) & 0xff); |
1723 | *dest++ = (char)((pixel >> 16) & 0xff); | 1723 | *dest++ = (char)((pixel >> 16) & 0xff); |
1724 | *dest++ = (char)((pixel >> 8) & 0xff); | 1724 | *dest++ = (char)((pixel >> 8) & 0xff); |
1725 | *dest++ = (char)( pixel & 0xff); | 1725 | *dest++ = (char)( pixel & 0xff); |
1726 | } else { | 1726 | } else { |
1727 | /* GRR BUG */ | 1727 | /* GRR BUG */ |
1728 | /* this assumes bpp == 24 & bits are packed low */ | 1728 | /* this assumes bpp == 24 & bits are packed low */ |
1729 | /* (probably need to use RShift/RMask/etc. here, too) */ | 1729 | /* (probably need to use RShift/RMask/etc. here, too) */ |
1730 | *dest++ = (char)((pixel >> 16) & 0xff); | 1730 | *dest++ = (char)((pixel >> 16) & 0xff); |
1731 | *dest++ = (char)((pixel >> 8) & 0xff); | 1731 | *dest++ = (char)((pixel >> 8) & 0xff); |
1732 | *dest++ = (char)( pixel & 0xff); | 1732 | *dest++ = (char)( pixel & 0xff); |
1733 | } | 1733 | } |
1734 | #endif | 1734 | #endif |
1735 | } | 1735 | } |
1736 | } | 1736 | } |
1737 | /* display after every 16 lines */ | 1737 | /* display after every 16 lines */ |
1738 | if (((row+1) & 0xf) == 0) { | 1738 | if (((row+1) & 0xf) == 0) { |
1739 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, | 1739 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, |
1740 | (int)lastrow, rpng2_info.width, 16); | 1740 | (int)lastrow, rpng2_info.width, 16); |
1741 | XFlush(display); | 1741 | XFlush(display); |
1742 | lastrow = row + 1; | 1742 | lastrow = row + 1; |
1743 | } | 1743 | } |
1744 | } | 1744 | } |
1745 | 1745 | ||
1746 | } else if (depth == 16) { | 1746 | } else if (depth == 16) { |
1747 | ush red, green, blue; | 1747 | ush red, green, blue; |
1748 | 1748 | ||
1749 | for (lastrow = row = startrow; row < startrow+height; ++row) { | 1749 | for (lastrow = row = startrow; row < startrow+height; ++row) { |
1750 | src = rpng2_info.row_pointers[row]; | 1750 | src = rpng2_info.row_pointers[row]; |
1751 | if (bg_image) | 1751 | if (bg_image) |
1752 | src2 = bg_data + row*bg_rowbytes; | 1752 | src2 = bg_data + row*bg_rowbytes; |
1753 | dest = ximage->data + row*ximage_rowbytes; | 1753 | dest = ximage->data + row*ximage_rowbytes; |
1754 | if (rpng2_info.channels == 3) { | 1754 | if (rpng2_info.channels == 3) { |
1755 | for (i = rpng2_info.width; i > 0; --i) { | 1755 | for (i = rpng2_info.width; i > 0; --i) { |
1756 | red = ((ush)(*src) << 8); | 1756 | red = ((ush)(*src) << 8); |
1757 | ++src; | 1757 | ++src; |
1758 | green = ((ush)(*src) << 8); | 1758 | green = ((ush)(*src) << 8); |
1759 | ++src; | 1759 | ++src; |
1760 | blue = ((ush)(*src) << 8); | 1760 | blue = ((ush)(*src) << 8); |
1761 | ++src; | 1761 | ++src; |
1762 | pixel = ((red >> RShift) & RMask) | | 1762 | pixel = ((red >> RShift) & RMask) | |
1763 | ((green >> GShift) & GMask) | | 1763 | ((green >> GShift) & GMask) | |
1764 | ((blue >> BShift) & BMask); | 1764 | ((blue >> BShift) & BMask); |
1765 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1765 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1766 | *dest++ = (char)((pixel >> 8) & 0xff); | 1766 | *dest++ = (char)((pixel >> 8) & 0xff); |
1767 | *dest++ = (char)( pixel & 0xff); | 1767 | *dest++ = (char)( pixel & 0xff); |
1768 | } | 1768 | } |
1769 | } else /* if (rpng2_info.channels == 4) */ { | 1769 | } else /* if (rpng2_info.channels == 4) */ { |
1770 | for (i = rpng2_info.width; i > 0; --i) { | 1770 | for (i = rpng2_info.width; i > 0; --i) { |
1771 | r = *src++; | 1771 | r = *src++; |
1772 | g = *src++; | 1772 | g = *src++; |
1773 | b = *src++; | 1773 | b = *src++; |
1774 | a = *src++; | 1774 | a = *src++; |
1775 | if (bg_image) { | 1775 | if (bg_image) { |
1776 | bg_red = *src2++; | 1776 | bg_red = *src2++; |
1777 | bg_green = *src2++; | 1777 | bg_green = *src2++; |
1778 | bg_blue = *src2++; | 1778 | bg_blue = *src2++; |
1779 | } | 1779 | } |
1780 | if (a == 255) { | 1780 | if (a == 255) { |
1781 | red = ((ush)r << 8); | 1781 | red = ((ush)r << 8); |
1782 | green = ((ush)g << 8); | 1782 | green = ((ush)g << 8); |
1783 | blue = ((ush)b << 8); | 1783 | blue = ((ush)b << 8); |
1784 | } else if (a == 0) { | 1784 | } else if (a == 0) { |
1785 | red = ((ush)bg_red << 8); | 1785 | red = ((ush)bg_red << 8); |
1786 | green = ((ush)bg_green << 8); | 1786 | green = ((ush)bg_green << 8); |
1787 | blue = ((ush)bg_blue << 8); | 1787 | blue = ((ush)bg_blue << 8); |
1788 | } else { | 1788 | } else { |
1789 | /* this macro (from png.h) composites the foreground | 1789 | /* this macro (from png.h) composites the foreground |
1790 | * and background values and puts the result back into | 1790 | * and background values and puts the result back into |
1791 | * the first argument (== fg byte here: safe) */ | 1791 | * the first argument (== fg byte here: safe) */ |
1792 | alpha_composite(r, r, a, bg_red); | 1792 | alpha_composite(r, r, a, bg_red); |
1793 | alpha_composite(g, g, a, bg_green); | 1793 | alpha_composite(g, g, a, bg_green); |
1794 | alpha_composite(b, b, a, bg_blue); | 1794 | alpha_composite(b, b, a, bg_blue); |
1795 | red = ((ush)r << 8); | 1795 | red = ((ush)r << 8); |
1796 | green = ((ush)g << 8); | 1796 | green = ((ush)g << 8); |
1797 | blue = ((ush)b << 8); | 1797 | blue = ((ush)b << 8); |
1798 | } | 1798 | } |
1799 | pixel = ((red >> RShift) & RMask) | | 1799 | pixel = ((red >> RShift) & RMask) | |
1800 | ((green >> GShift) & GMask) | | 1800 | ((green >> GShift) & GMask) | |
1801 | ((blue >> BShift) & BMask); | 1801 | ((blue >> BShift) & BMask); |
1802 | /* recall that we set ximage->byte_order = MSBFirst above */ | 1802 | /* recall that we set ximage->byte_order = MSBFirst above */ |
1803 | *dest++ = (char)((pixel >> 8) & 0xff); | 1803 | *dest++ = (char)((pixel >> 8) & 0xff); |
1804 | *dest++ = (char)( pixel & 0xff); | 1804 | *dest++ = (char)( pixel & 0xff); |
1805 | } | 1805 | } |
1806 | } | 1806 | } |
1807 | /* display after every 16 lines */ | 1807 | /* display after every 16 lines */ |
1808 | if (((row+1) & 0xf) == 0) { | 1808 | if (((row+1) & 0xf) == 0) { |
1809 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, | 1809 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, |
1810 | (int)lastrow, rpng2_info.width, 16); | 1810 | (int)lastrow, rpng2_info.width, 16); |
1811 | XFlush(display); | 1811 | XFlush(display); |
1812 | lastrow = row + 1; | 1812 | lastrow = row + 1; |
1813 | } | 1813 | } |
1814 | } | 1814 | } |
1815 | 1815 | ||
1816 | } else /* depth == 8 */ { | 1816 | } else /* depth == 8 */ { |
1817 | 1817 | ||
1818 | /* GRR: add 8-bit support */ | 1818 | /* GRR: add 8-bit support */ |
1819 | 1819 | ||
1820 | } | 1820 | } |
1821 | 1821 | ||
1822 | Trace((stderr, "calling final XPutImage()\n")) | 1822 | Trace((stderr, "calling final XPutImage()\n")) |
1823 | if (lastrow < startrow+height) { | 1823 | if (lastrow < startrow+height) { |
1824 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, | 1824 | XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0, |
1825 | (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow); | 1825 | (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow); |
1826 | XFlush(display); | 1826 | XFlush(display); |
1827 | } | 1827 | } |
1828 | 1828 | ||
1829 | } /* end function rpng2_x_redisplay_image() */ | 1829 | } /* end function rpng2_x_redisplay_image() */ |
1830 | 1830 | ||
1831 | 1831 | ||
1832 | 1832 | ||
1833 | 1833 | ||
1834 | 1834 | ||
1835 | #ifdef FEATURE_LOOP | 1835 | #ifdef FEATURE_LOOP |
1836 | 1836 | ||
1837 | static void rpng2_x_reload_bg_image(void) | 1837 | static void rpng2_x_reload_bg_image(void) |
1838 | { | 1838 | { |
1839 | char *dest; | 1839 | char *dest; |
1840 | uch r1, r2, g1, g2, b1, b2; | 1840 | uch r1, r2, g1, g2, b1, b2; |
1841 | uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; | 1841 | uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv; |
1842 | int k, hmax, max; | 1842 | int k, hmax, max; |
1843 | int xidx, yidx, yidx_max; | 1843 | int xidx, yidx, yidx_max; |
1844 | int even_odd_vert, even_odd_horiz, even_odd; | 1844 | int even_odd_vert, even_odd_horiz, even_odd; |
1845 | int invert_gradient2 = (bg[pat].type & 0x08); | 1845 | int invert_gradient2 = (bg[pat].type & 0x08); |
1846 | int invert_column; | 1846 | int invert_column; |
1847 | ulg i, row; | 1847 | ulg i, row; |
1848 | 1848 | ||
1849 | 1849 | ||
1850 | bgscale = (pat == 0)? 8 : bgscale_default; | 1850 | bgscale = (pat == 0)? 8 : bgscale_default; |
1851 | yidx_max = bgscale - 1; | 1851 | yidx_max = bgscale - 1; |
1852 | 1852 | ||
1853 | /*--------------------------------------------------------------------------- | 1853 | /*--------------------------------------------------------------------------- |
1854 | Vertical gradients (ramps) in NxN squares, alternating direction and | 1854 | Vertical gradients (ramps) in NxN squares, alternating direction and |
1855 | colors (N == bgscale). | 1855 | colors (N == bgscale). |
1856 | ---------------------------------------------------------------------------*/ | 1856 | ---------------------------------------------------------------------------*/ |
1857 | 1857 | ||
1858 | if ((bg[pat].type & 0x07) == 0) { | 1858 | if ((bg[pat].type & 0x07) == 0) { |
1859 | uch r1_min = rgb[bg[pat].rgb1_min].r; | 1859 | uch r1_min = rgb[bg[pat].rgb1_min].r; |
1860 | uch g1_min = rgb[bg[pat].rgb1_min].g; | 1860 | uch g1_min = rgb[bg[pat].rgb1_min].g; |
1861 | uch b1_min = rgb[bg[pat].rgb1_min].b; | 1861 | uch b1_min = rgb[bg[pat].rgb1_min].b; |
1862 | uch r2_min = rgb[bg[pat].rgb2_min].r; | 1862 | uch r2_min = rgb[bg[pat].rgb2_min].r; |
1863 | uch g2_min = rgb[bg[pat].rgb2_min].g; | 1863 | uch g2_min = rgb[bg[pat].rgb2_min].g; |
1864 | uch b2_min = rgb[bg[pat].rgb2_min].b; | 1864 | uch b2_min = rgb[bg[pat].rgb2_min].b; |
1865 | int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; | 1865 | int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min; |
1866 | int g1_diff = rgb[bg[pat].rgb1_max].g - g1_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; | 1867 | int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min; |
1868 | int r2_diff = rgb[bg[pat].rgb2_max].r - r2_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; | 1869 | int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min; |
1870 | int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; | 1870 | int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min; |
1871 | 1871 | ||
1872 | for (row = 0; row < rpng2_info.height; ++row) { | 1872 | for (row = 0; row < rpng2_info.height; ++row) { |
1873 | yidx = (int)(row % bgscale); | 1873 | yidx = (int)(row % bgscale); |
1874 | even_odd_vert = (int)((row / bgscale) & 1); | 1874 | even_odd_vert = (int)((row / bgscale) & 1); |
1875 | 1875 | ||
1876 | r1 = r1_min + (r1_diff * yidx) / yidx_max; | 1876 | r1 = r1_min + (r1_diff * yidx) / yidx_max; |
1877 | g1 = g1_min + (g1_diff * yidx) / yidx_max; | 1877 | g1 = g1_min + (g1_diff * yidx) / yidx_max; |
1878 | b1 = b1_min + (b1_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; | 1879 | r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max; |
1880 | g1_inv = g1_min + (g1_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; | 1881 | b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max; |
1882 | 1882 | ||
1883 | r2 = r2_min + (r2_diff * yidx) / yidx_max; | 1883 | r2 = r2_min + (r2_diff * yidx) / yidx_max; |
1884 | g2 = g2_min + (g2_diff * yidx) / yidx_max; | 1884 | g2 = g2_min + (g2_diff * yidx) / yidx_max; |
1885 | b2 = b2_min + (b2_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; | 1886 | r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max; |
1887 | g2_inv = g2_min + (g2_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; | 1888 | b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max; |
1889 | 1889 | ||
1890 | dest = (char *)bg_data + row*bg_rowbytes; | 1890 | dest = (char *)bg_data + row*bg_rowbytes; |
1891 | for (i = 0; i < rpng2_info.width; ++i) { | 1891 | for (i = 0; i < rpng2_info.width; ++i) { |
1892 | even_odd_horiz = (int)((i / bgscale) & 1); | 1892 | even_odd_horiz = (int)((i / bgscale) & 1); |
1893 | even_odd = even_odd_vert ^ even_odd_horiz; | 1893 | even_odd = even_odd_vert ^ even_odd_horiz; |
1894 | invert_column = | 1894 | invert_column = |
1895 | (even_odd_horiz && (bg[pat].type & 0x10)); | 1895 | (even_odd_horiz && (bg[pat].type & 0x10)); |
1896 | if (even_odd == 0) { /* gradient #1 */ | 1896 | if (even_odd == 0) { /* gradient #1 */ |
1897 | if (invert_column) { | 1897 | if (invert_column) { |
1898 | *dest++ = r1_inv; | 1898 | *dest++ = r1_inv; |
1899 | *dest++ = g1_inv; | 1899 | *dest++ = g1_inv; |
1900 | *dest++ = b1_inv; | 1900 | *dest++ = b1_inv; |
1901 | } else { | 1901 | } else { |
1902 | *dest++ = r1; | 1902 | *dest++ = r1; |
1903 | *dest++ = g1; | 1903 | *dest++ = g1; |
1904 | *dest++ = b1; | 1904 | *dest++ = b1; |
1905 | } | 1905 | } |
1906 | } else { /* gradient #2 */ | 1906 | } else { /* gradient #2 */ |
1907 | if ((invert_column && invert_gradient2) || | 1907 | if ((invert_column && invert_gradient2) || |
1908 | (!invert_column && !invert_gradient2)) | 1908 | (!invert_column && !invert_gradient2)) |
1909 | { | 1909 | { |
1910 | *dest++ = r2; /* not inverted or */ | 1910 | *dest++ = r2; /* not inverted or */ |
1911 | *dest++ = g2; /* doubly inverted */ | 1911 | *dest++ = g2; /* doubly inverted */ |
1912 | *dest++ = b2; | 1912 | *dest++ = b2; |
1913 | } else { | 1913 | } else { |
1914 | *dest++ = r2_inv; | 1914 | *dest++ = r2_inv; |
1915 | *dest++ = g2_inv; /* singly inverted */ | 1915 | *dest++ = g2_inv; /* singly inverted */ |
1916 | *dest++ = b2_inv; | 1916 | *dest++ = b2_inv; |
1917 | } | 1917 | } |
1918 | } | 1918 | } |
1919 | } | 1919 | } |
1920 | } | 1920 | } |
1921 | 1921 | ||
1922 | /*--------------------------------------------------------------------------- | 1922 | /*--------------------------------------------------------------------------- |
1923 | Soft gradient-diamonds with scale = bgscale. Code contributed by Adam | 1923 | Soft gradient-diamonds with scale = bgscale. Code contributed by Adam |
1924 | M. Costello. | 1924 | M. Costello. |
1925 | ---------------------------------------------------------------------------*/ | 1925 | ---------------------------------------------------------------------------*/ |
1926 | 1926 | ||
1927 | } else if ((bg[pat].type & 0x07) == 1) { | 1927 | } else if ((bg[pat].type & 0x07) == 1) { |
1928 | 1928 | ||
1929 | hmax = (bgscale-1)/2; /* half the max weight of a color */ | 1929 | hmax = (bgscale-1)/2; /* half the max weight of a color */ |
1930 | max = 2*hmax; /* the max weight of a color */ | 1930 | max = 2*hmax; /* the max weight of a color */ |
1931 | 1931 | ||
1932 | r1 = rgb[bg[pat].rgb1_max].r; | 1932 | r1 = rgb[bg[pat].rgb1_max].r; |
1933 | g1 = rgb[bg[pat].rgb1_max].g; | 1933 | g1 = rgb[bg[pat].rgb1_max].g; |
1934 | b1 = rgb[bg[pat].rgb1_max].b; | 1934 | b1 = rgb[bg[pat].rgb1_max].b; |
1935 | r2 = rgb[bg[pat].rgb2_max].r; | 1935 | r2 = rgb[bg[pat].rgb2_max].r; |
1936 | g2 = rgb[bg[pat].rgb2_max].g; | 1936 | g2 = rgb[bg[pat].rgb2_max].g; |
1937 | b2 = rgb[bg[pat].rgb2_max].b; | 1937 | b2 = rgb[bg[pat].rgb2_max].b; |
1938 | 1938 | ||
1939 | for (row = 0; row < rpng2_info.height; ++row) { | 1939 | for (row = 0; row < rpng2_info.height; ++row) { |
1940 | yidx = (int)(row % bgscale); | 1940 | yidx = (int)(row % bgscale); |
1941 | if (yidx > hmax) | 1941 | if (yidx > hmax) |
1942 | yidx = bgscale-1 - yidx; | 1942 | yidx = bgscale-1 - yidx; |
1943 | dest = (char *)bg_data + row*bg_rowbytes; | 1943 | dest = (char *)bg_data + row*bg_rowbytes; |
1944 | for (i = 0; i < rpng2_info.width; ++i) { | 1944 | for (i = 0; i < rpng2_info.width; ++i) { |
1945 | xidx = (int)(i % bgscale); | 1945 | xidx = (int)(i % bgscale); |
1946 | if (xidx > hmax) | 1946 | if (xidx > hmax) |
1947 | xidx = bgscale-1 - xidx; | 1947 | xidx = bgscale-1 - xidx; |
1948 | k = xidx + yidx; | 1948 | k = xidx + yidx; |
1949 | *dest++ = (k*r1 + (max-k)*r2) / max; | 1949 | *dest++ = (k*r1 + (max-k)*r2) / max; |
1950 | *dest++ = (k*g1 + (max-k)*g2) / max; | 1950 | *dest++ = (k*g1 + (max-k)*g2) / max; |
1951 | *dest++ = (k*b1 + (max-k)*b2) / max; | 1951 | *dest++ = (k*b1 + (max-k)*b2) / max; |
1952 | } | 1952 | } |
1953 | } | 1953 | } |
1954 | 1954 | ||
1955 | /*--------------------------------------------------------------------------- | 1955 | /*--------------------------------------------------------------------------- |
1956 | Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- | 1956 | Radial "starburst" with azimuthal sinusoids; [eventually number of sinu- |
1957 | soids will equal bgscale?]. This one is slow but very cool. Code con- | 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). | 1958 | tributed by Pieter S. van der Meulen (originally in Smalltalk). |
1959 | ---------------------------------------------------------------------------*/ | 1959 | ---------------------------------------------------------------------------*/ |
1960 | 1960 | ||
1961 | } else if ((bg[pat].type & 0x07) == 2) { | 1961 | } else if ((bg[pat].type & 0x07) == 2) { |
1962 | uch ch; | 1962 | uch ch; |
1963 | int ii, x, y, hw, hh, grayspot; | 1963 | int ii, x, y, hw, hh, grayspot; |
1964 | double freq, rotate, saturate, gray, intensity; | 1964 | double freq, rotate, saturate, gray, intensity; |
1965 | double angle=0.0, aoffset=0.0, maxDist, dist; | 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; | 1966 | double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t; |
1967 | 1967 | ||
1968 | hh = (int)(rpng2_info.height / 2); | 1968 | hh = (int)(rpng2_info.height / 2); |
1969 | hw = (int)(rpng2_info.width / 2); | 1969 | hw = (int)(rpng2_info.width / 2); |
1970 | 1970 | ||
1971 | /* variables for radial waves: | 1971 | /* variables for radial waves: |
1972 | * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] | 1972 | * aoffset: number of degrees to rotate hue [CURRENTLY NOT USED] |
1973 | * freq: number of color beams originating from the center | 1973 | * freq: number of color beams originating from the center |
1974 | * grayspot: size of the graying center area (anti-alias) | 1974 | * grayspot: size of the graying center area (anti-alias) |
1975 | * rotate: rotation of the beams as a function of radius | 1975 | * rotate: rotation of the beams as a function of radius |
1976 | * saturate: saturation of beams' shape azimuthally | 1976 | * saturate: saturation of beams' shape azimuthally |
1977 | */ | 1977 | */ |
1978 | angle = CLIP(angle, 0.0, 360.0); | 1978 | angle = CLIP(angle, 0.0, 360.0); |
1979 | grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); | 1979 | grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw)); |
1980 | freq = MAX((double)bg[pat].bg_freq, 0.0); | 1980 | freq = MAX((double)bg[pat].bg_freq, 0.0); |
1981 | saturate = (double)bg[pat].bg_bsat * 0.1; | 1981 | saturate = (double)bg[pat].bg_bsat * 0.1; |
1982 | rotate = (double)bg[pat].bg_brot * 0.1; | 1982 | rotate = (double)bg[pat].bg_brot * 0.1; |
1983 | gray = 0.0; | 1983 | gray = 0.0; |
1984 | intensity = 0.0; | 1984 | intensity = 0.0; |
1985 | maxDist = (double)((hw*hw) + (hh*hh)); | 1985 | maxDist = (double)((hw*hw) + (hh*hh)); |
1986 | 1986 | ||
1987 | for (row = 0; row < rpng2_info.height; ++row) { | 1987 | for (row = 0; row < rpng2_info.height; ++row) { |
1988 | y = (int)(row - hh); | 1988 | y = (int)(row - hh); |
1989 | dest = (char *)bg_data + row*bg_rowbytes; | 1989 | dest = (char *)bg_data + row*bg_rowbytes; |
1990 | for (i = 0; i < rpng2_info.width; ++i) { | 1990 | for (i = 0; i < rpng2_info.width; ++i) { |
1991 | x = (int)(i - hw); | 1991 | x = (int)(i - hw); |
1992 | angle = (x == 0)? PI_2 : atan((double)y / (double)x); | 1992 | angle = (x == 0)? PI_2 : atan((double)y / (double)x); |
1993 | gray = (double)MAX(ABS(y), ABS(x)) / grayspot; | 1993 | gray = (double)MAX(ABS(y), ABS(x)) / grayspot; |
1994 | gray = MIN(1.0, gray); | 1994 | gray = MIN(1.0, gray); |
1995 | dist = (double)((x*x) + (y*y)) / maxDist; | 1995 | dist = (double)((x*x) + (y*y)) / maxDist; |
1996 | intensity = cos((angle+(rotate*dist*PI)) * freq) * | 1996 | intensity = cos((angle+(rotate*dist*PI)) * freq) * |
1997 | gray * saturate; | 1997 | gray * saturate; |
1998 | intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; | 1998 | intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5; |
1999 | hue = (angle + PI) * INV_PI_360 + aoffset; | 1999 | hue = (angle + PI) * INV_PI_360 + aoffset; |
2000 | s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); | 2000 | s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh)); |
2001 | s = MIN(MAX(s,0.0), 1.0); | 2001 | s = MIN(MAX(s,0.0), 1.0); |
2002 | v = MIN(MAX(intensity,0.0), 1.0); | 2002 | v = MIN(MAX(intensity,0.0), 1.0); |
2003 | 2003 | ||
2004 | if (s == 0.0) { | 2004 | if (s == 0.0) { |
2005 | ch = (uch)(v * 255.0); | 2005 | ch = (uch)(v * 255.0); |
2006 | *dest++ = ch; | 2006 | *dest++ = ch; |
2007 | *dest++ = ch; | 2007 | *dest++ = ch; |
2008 | *dest++ = ch; | 2008 | *dest++ = ch; |
2009 | } else { | 2009 | } else { |
2010 | if ((hue < 0.0) || (hue >= 360.0)) | 2010 | if ((hue < 0.0) || (hue >= 360.0)) |
2011 | hue -= (((int)(hue / 360.0)) * 360.0); | 2011 | hue -= (((int)(hue / 360.0)) * 360.0); |
2012 | hue /= 60.0; | 2012 | hue /= 60.0; |
2013 | ii = (int)hue; | 2013 | ii = (int)hue; |
2014 | f = hue - (double)ii; | 2014 | f = hue - (double)ii; |
2015 | p = (1.0 - s) * v; | 2015 | p = (1.0 - s) * v; |
2016 | q = (1.0 - (s * f)) * v; | 2016 | q = (1.0 - (s * f)) * v; |
2017 | t = (1.0 - (s * (1.0 - f))) * v; | 2017 | t = (1.0 - (s * (1.0 - f))) * v; |
2018 | if (ii == 0) { red = v; green = t; blue = p; } | 2018 | if (ii == 0) { red = v; green = t; blue = p; } |
2019 | else if (ii == 1) { red = q; green = v; blue = p; } | 2019 | else if (ii == 1) { red = q; green = v; blue = p; } |
2020 | else if (ii == 2) { red = p; green = v; blue = t; } | 2020 | else if (ii == 2) { red = p; green = v; blue = t; } |
2021 | else if (ii == 3) { red = p; green = q; blue = v; } | 2021 | else if (ii == 3) { red = p; green = q; blue = v; } |
2022 | else if (ii == 4) { red = t; green = p; blue = v; } | 2022 | else if (ii == 4) { red = t; green = p; blue = v; } |
2023 | else if (ii == 5) { red = v; green = p; blue = q; } | 2023 | else if (ii == 5) { red = v; green = p; blue = q; } |
2024 | *dest++ = (uch)(red * 255.0); | 2024 | *dest++ = (uch)(red * 255.0); |
2025 | *dest++ = (uch)(green * 255.0); | 2025 | *dest++ = (uch)(green * 255.0); |
2026 | *dest++ = (uch)(blue * 255.0); | 2026 | *dest++ = (uch)(blue * 255.0); |
2027 | } | 2027 | } |
2028 | } | 2028 | } |
2029 | } | 2029 | } |
2030 | } | 2030 | } |
2031 | 2031 | ||
2032 | } /* end function rpng2_x_reload_bg_image() */ | 2032 | } /* end function rpng2_x_reload_bg_image() */ |
2033 | 2033 | ||
2034 | 2034 | ||
2035 | 2035 | ||
2036 | 2036 | ||
2037 | 2037 | ||
2038 | static int is_number(char *p) | 2038 | static int is_number(char *p) |
2039 | { | 2039 | { |
2040 | while (*p) { | 2040 | while (*p) { |
2041 | if (!isdigit(*p)) | 2041 | if (!isdigit(*p)) |
2042 | return FALSE; | 2042 | return FALSE; |
2043 | ++p; | 2043 | ++p; |
2044 | } | 2044 | } |
2045 | return TRUE; | 2045 | return TRUE; |
2046 | } | 2046 | } |
2047 | 2047 | ||
2048 | #endif /* FEATURE_LOOP */ | 2048 | #endif /* FEATURE_LOOP */ |
2049 | 2049 | ||
2050 | 2050 | ||
2051 | 2051 | ||
2052 | 2052 | ||
2053 | 2053 | ||
2054 | static void rpng2_x_cleanup(void) | 2054 | static void rpng2_x_cleanup(void) |
2055 | { | 2055 | { |
2056 | if (bg_image && bg_data) { | 2056 | if (bg_image && bg_data) { |
2057 | free(bg_data); | 2057 | free(bg_data); |
2058 | bg_data = NULL; | 2058 | bg_data = NULL; |
2059 | } | 2059 | } |
2060 | 2060 | ||
2061 | if (rpng2_info.image_data) { | 2061 | if (rpng2_info.image_data) { |
2062 | free(rpng2_info.image_data); | 2062 | free(rpng2_info.image_data); |
2063 | rpng2_info.image_data = NULL; | 2063 | rpng2_info.image_data = NULL; |
2064 | } | 2064 | } |
2065 | 2065 | ||
2066 | if (rpng2_info.row_pointers) { | 2066 | if (rpng2_info.row_pointers) { |
2067 | free(rpng2_info.row_pointers); | 2067 | free(rpng2_info.row_pointers); |
2068 | rpng2_info.row_pointers = NULL; | 2068 | rpng2_info.row_pointers = NULL; |
2069 | } | 2069 | } |
2070 | 2070 | ||
2071 | if (ximage) { | 2071 | if (ximage) { |
2072 | if (ximage->data) { | 2072 | if (ximage->data) { |
2073 | free(ximage->data); /* we allocated it, so we free it */ | 2073 | free(ximage->data); /* we allocated it, so we free it */ |
2074 | ximage->data = (char *)NULL; /* instead of XDestroyImage() */ | 2074 | ximage->data = (char *)NULL; /* instead of XDestroyImage() */ |
2075 | } | 2075 | } |
2076 | XDestroyImage(ximage); | 2076 | XDestroyImage(ximage); |
2077 | ximage = NULL; | 2077 | ximage = NULL; |
2078 | } | 2078 | } |
2079 | 2079 | ||
2080 | if (have_gc) | 2080 | if (have_gc) |
2081 | XFreeGC(display, gc); | 2081 | XFreeGC(display, gc); |
2082 | 2082 | ||
2083 | if (have_window) | 2083 | if (have_window) |
2084 | XDestroyWindow(display, window); | 2084 | XDestroyWindow(display, window); |
2085 | 2085 | ||
2086 | if (have_colormap) | 2086 | if (have_colormap) |
2087 | XFreeColormap(display, colormap); | 2087 | XFreeColormap(display, colormap); |
2088 | 2088 | ||
2089 | if (have_nondefault_visual) | 2089 | if (have_nondefault_visual) |
2090 | XFree(visual_list); | 2090 | XFree(visual_list); |
2091 | } | 2091 | } |
2092 | 2092 | ||
2093 | 2093 | ||
2094 | 2094 | ||
2095 | 2095 | ||
2096 | 2096 | ||
2097 | static int rpng2_x_msb(ulg u32val) | 2097 | static int rpng2_x_msb(ulg u32val) |
2098 | { | 2098 | { |
2099 | int i; | 2099 | int i; |
2100 | 2100 | ||
2101 | for (i = 31; i >= 0; --i) { | 2101 | for (i = 31; i >= 0; --i) { |
2102 | if (u32val & 0x80000000L) | 2102 | if (u32val & 0x80000000L) |
2103 | break; | 2103 | break; |
2104 | u32val <<= 1; | 2104 | u32val <<= 1; |
2105 | } | 2105 | } |
2106 | return i; | 2106 | return i; |
2107 | } | 2107 | } |
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 index 30372a3..a06e352 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/wpng.c | |||
@@ -1,853 +1,853 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | wpng - simple PNG-writing program wpng.c | 3 | wpng - simple PNG-writing program wpng.c |
4 | 4 | ||
5 | This program converts certain NetPBM binary files (grayscale and RGB, | 5 | This program converts certain NetPBM binary files (grayscale and RGB, |
6 | maxval = 255) to PNG. Non-interlaced PNGs are written progressively; | 6 | maxval = 255) to PNG. Non-interlaced PNGs are written progressively; |
7 | interlaced PNGs are read and written in one memory-intensive blast. | 7 | interlaced PNGs are read and written in one memory-intensive blast. |
8 | 8 | ||
9 | Thanks to Jean-loup Gailly for providing the necessary trick to read | 9 | Thanks to Jean-loup Gailly for providing the necessary trick to read |
10 | interactive text from the keyboard while stdin is redirected. Thanks | 10 | interactive text from the keyboard while stdin is redirected. Thanks |
11 | to Cosmin Truta for Cygwin fixes. | 11 | to Cosmin Truta for Cygwin fixes. |
12 | 12 | ||
13 | NOTE: includes provisional support for PNM type "8" (portable alphamap) | 13 | NOTE: includes provisional support for PNM type "8" (portable alphamap) |
14 | images, presumed to be a 32-bit interleaved RGBA format; no pro- | 14 | images, presumed to be a 32-bit interleaved RGBA format; no pro- |
15 | vision for possible interleaved grayscale+alpha (16-bit) format. | 15 | vision for possible interleaved grayscale+alpha (16-bit) format. |
16 | THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT! | 16 | THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT! |
17 | 17 | ||
18 | to do: | 18 | to do: |
19 | - delete output file if quit before calling any writepng routines | 19 | - delete output file if quit before calling any writepng routines |
20 | - process backspace with -text option under DOS/Win? (currently get ^H) | 20 | - process backspace with -text option under DOS/Win? (currently get ^H) |
21 | 21 | ||
22 | --------------------------------------------------------------------------- | 22 | --------------------------------------------------------------------------- |
23 | 23 | ||
24 | Changelog: | 24 | Changelog: |
25 | - 1.01: initial public release | 25 | - 1.01: initial public release |
26 | - 1.02: modified to allow abbreviated options | 26 | - 1.02: modified to allow abbreviated options |
27 | - 1.03: removed extraneous character from usage screen; fixed bug in | 27 | - 1.03: removed extraneous character from usage screen; fixed bug in |
28 | command-line parsing | 28 | command-line parsing |
29 | - 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix | 29 | - 1.04: fixed DOS/OS2/Win32 detection, including partial Cygwin fix |
30 | (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff) | 30 | (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff) |
31 | - 2.00: dual-licensed (added GNU GPL) | 31 | - 2.00: dual-licensed (added GNU GPL) |
32 | 32 | ||
33 | [REPORTED BUG (win32 only): "contrib/gregbook/wpng.c - cmd line | 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 | 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 | 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 | 36 | Linux, the same wpng appears to work fine. I don't know what is |
37 | the problem."] | 37 | the problem."] |
38 | 38 | ||
39 | --------------------------------------------------------------------------- | 39 | --------------------------------------------------------------------------- |
40 | 40 | ||
41 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 41 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
42 | 42 | ||
43 | This software is provided "as is," without warranty of any kind, | 43 | This software is provided "as is," without warranty of any kind, |
44 | express or implied. In no event shall the author or contributors | 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 | 45 | be held liable for any damages arising in any way from the use of |
46 | this software. | 46 | this software. |
47 | 47 | ||
48 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 49 | redistribute this software according to the terms of one of the |
50 | following two licenses (at your option): | 50 | following two licenses (at your option): |
51 | 51 | ||
52 | 52 | ||
53 | LICENSE 1 ("BSD-like with advertising clause"): | 53 | LICENSE 1 ("BSD-like with advertising clause"): |
54 | 54 | ||
55 | Permission is granted to anyone to use this software for any purpose, | 55 | Permission is granted to anyone to use this software for any purpose, |
56 | including commercial applications, and to alter it and redistribute | 56 | including commercial applications, and to alter it and redistribute |
57 | it freely, subject to the following restrictions: | 57 | it freely, subject to the following restrictions: |
58 | 58 | ||
59 | 1. Redistributions of source code must retain the above copyright | 59 | 1. Redistributions of source code must retain the above copyright |
60 | notice, disclaimer, and this list of conditions. | 60 | notice, disclaimer, and this list of conditions. |
61 | 2. Redistributions in binary form must reproduce the above copyright | 61 | 2. Redistributions in binary form must reproduce the above copyright |
62 | notice, disclaimer, and this list of conditions in the documenta- | 62 | notice, disclaimer, and this list of conditions in the documenta- |
63 | tion and/or other materials provided with the distribution. | 63 | tion and/or other materials provided with the distribution. |
64 | 3. All advertising materials mentioning features or use of this | 64 | 3. All advertising materials mentioning features or use of this |
65 | software must display the following acknowledgment: | 65 | software must display the following acknowledgment: |
66 | 66 | ||
67 | This product includes software developed by Greg Roelofs | 67 | This product includes software developed by Greg Roelofs |
68 | and contributors for the book, "PNG: The Definitive Guide," | 68 | and contributors for the book, "PNG: The Definitive Guide," |
69 | published by O'Reilly and Associates. | 69 | published by O'Reilly and Associates. |
70 | 70 | ||
71 | 71 | ||
72 | LICENSE 2 (GNU GPL v2 or later): | 72 | LICENSE 2 (GNU GPL v2 or later): |
73 | 73 | ||
74 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 76 | the Free Software Foundation; either version 2 of the License, or |
77 | (at your option) any later version. | 77 | (at your option) any later version. |
78 | 78 | ||
79 | This program is distributed in the hope that it will be useful, | 79 | This program is distributed in the hope that it will be useful, |
80 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 80 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
81 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 81 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
82 | GNU General Public License for more details. | 82 | GNU General Public License for more details. |
83 | 83 | ||
84 | You should have received a copy of the GNU General Public License | 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, | 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 | 86 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
87 | 87 | ||
88 | ---------------------------------------------------------------------------*/ | 88 | ---------------------------------------------------------------------------*/ |
89 | 89 | ||
90 | #define PROGNAME "wpng" | 90 | #define PROGNAME "wpng" |
91 | #define VERSION "2.00 of 2 June 2007" | 91 | #define VERSION "2.00 of 2 June 2007" |
92 | #define APPNAME "Simple PGM/PPM/PAM to PNG Converter" | 92 | #define APPNAME "Simple PGM/PPM/PAM to PNG Converter" |
93 | 93 | ||
94 | #if defined(__MSDOS__) || defined(__OS2__) | 94 | #if defined(__MSDOS__) || defined(__OS2__) |
95 | # define DOS_OS2_W32 | 95 | # define DOS_OS2_W32 |
96 | #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) | 96 | #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) |
97 | # ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */ | 97 | # ifndef __GNUC__ /* treat Win32 native ports of gcc as Unix environments */ |
98 | # define DOS_OS2_W32 | 98 | # define DOS_OS2_W32 |
99 | # endif | 99 | # endif |
100 | #endif | 100 | #endif |
101 | 101 | ||
102 | #include <stdio.h> | 102 | #include <stdio.h> |
103 | #include <stdlib.h> | 103 | #include <stdlib.h> |
104 | #include <string.h> | 104 | #include <string.h> |
105 | #include <setjmp.h> /* for jmpbuf declaration in writepng.h */ | 105 | #include <setjmp.h> /* for jmpbuf declaration in writepng.h */ |
106 | #include <time.h> | 106 | #include <time.h> |
107 | 107 | ||
108 | #ifdef DOS_OS2_W32 | 108 | #ifdef DOS_OS2_W32 |
109 | # include <io.h> /* for isatty(), setmode() prototypes */ | 109 | # include <io.h> /* for isatty(), setmode() prototypes */ |
110 | # include <fcntl.h> /* O_BINARY for fdopen() without text translation */ | 110 | # include <fcntl.h> /* O_BINARY for fdopen() without text translation */ |
111 | # ifdef __EMX__ | 111 | # ifdef __EMX__ |
112 | # ifndef getch | 112 | # ifndef getch |
113 | # define getch() _read_kbd(0, 1, 0) /* need getche() */ | 113 | # define getch() _read_kbd(0, 1, 0) /* need getche() */ |
114 | # endif | 114 | # endif |
115 | # else /* !__EMX__ */ | 115 | # else /* !__EMX__ */ |
116 | # ifdef __GO32__ | 116 | # ifdef __GO32__ |
117 | # include <pc.h> | 117 | # include <pc.h> |
118 | # define getch() getkey() /* GRR: need getche() */ | 118 | # define getch() getkey() /* GRR: need getche() */ |
119 | # else | 119 | # else |
120 | # include <conio.h> /* for getche() console input */ | 120 | # include <conio.h> /* for getche() console input */ |
121 | # endif | 121 | # endif |
122 | # endif /* ?__EMX__ */ | 122 | # endif /* ?__EMX__ */ |
123 | # define FGETS(buf,len,stream) dos_kbd_gets(buf,len) | 123 | # define FGETS(buf,len,stream) dos_kbd_gets(buf,len) |
124 | #else | 124 | #else |
125 | # include <unistd.h> /* for isatty() prototype */ | 125 | # include <unistd.h> /* for isatty() prototype */ |
126 | # define FGETS fgets | 126 | # define FGETS fgets |
127 | #endif | 127 | #endif |
128 | 128 | ||
129 | /* #define DEBUG : this enables the Trace() macros */ | 129 | /* #define DEBUG : this enables the Trace() macros */ |
130 | 130 | ||
131 | /* #define FORBID_LATIN1_CTRL : this requires the user to re-enter any | 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 | 132 | text that includes control characters discouraged by the PNG spec; text |
133 | that includes an escape character (27) must be re-entered regardless */ | 133 | that includes an escape character (27) must be re-entered regardless */ |
134 | 134 | ||
135 | #include "writepng.h" /* typedefs, common macros, writepng prototypes */ | 135 | #include "writepng.h" /* typedefs, common macros, writepng prototypes */ |
136 | 136 | ||
137 | 137 | ||
138 | 138 | ||
139 | /* local prototypes */ | 139 | /* local prototypes */ |
140 | 140 | ||
141 | static int wpng_isvalid_latin1(uch *p, int len); | 141 | static int wpng_isvalid_latin1(uch *p, int len); |
142 | static void wpng_cleanup(void); | 142 | static void wpng_cleanup(void); |
143 | 143 | ||
144 | #ifdef DOS_OS2_W32 | 144 | #ifdef DOS_OS2_W32 |
145 | static char *dos_kbd_gets(char *buf, int len); | 145 | static char *dos_kbd_gets(char *buf, int len); |
146 | #endif | 146 | #endif |
147 | 147 | ||
148 | 148 | ||
149 | 149 | ||
150 | static mainprog_info wpng_info; /* lone global */ | 150 | static mainprog_info wpng_info; /* lone global */ |
151 | 151 | ||
152 | 152 | ||
153 | 153 | ||
154 | int main(int argc, char **argv) | 154 | int main(int argc, char **argv) |
155 | { | 155 | { |
156 | #ifndef DOS_OS2_W32 | 156 | #ifndef DOS_OS2_W32 |
157 | FILE *keybd; | 157 | FILE *keybd; |
158 | #endif | 158 | #endif |
159 | #ifdef sgi | 159 | #ifdef sgi |
160 | FILE *tmpfile; /* or we could just use keybd, since no overlap */ | 160 | FILE *tmpfile; /* or we could just use keybd, since no overlap */ |
161 | char tmpline[80]; | 161 | char tmpline[80]; |
162 | #endif | 162 | #endif |
163 | char *inname = NULL, outname[256]; | 163 | char *inname = NULL, outname[256]; |
164 | char *p, pnmchar, pnmline[256]; | 164 | char *p, pnmchar, pnmline[256]; |
165 | char *bgstr, *textbuf = NULL; | 165 | char *bgstr, *textbuf = NULL; |
166 | ulg rowbytes; | 166 | ulg rowbytes; |
167 | int rc, len = 0; | 167 | int rc, len = 0; |
168 | int error = 0; | 168 | int error = 0; |
169 | int text = FALSE; | 169 | int text = FALSE; |
170 | int maxval; | 170 | int maxval; |
171 | double LUT_exponent; /* just the lookup table */ | 171 | double LUT_exponent; /* just the lookup table */ |
172 | double CRT_exponent = 2.2; /* just the monitor */ | 172 | double CRT_exponent = 2.2; /* just the monitor */ |
173 | double default_display_exponent; /* whole display system */ | 173 | double default_display_exponent; /* whole display system */ |
174 | double default_gamma = 0.0; | 174 | double default_gamma = 0.0; |
175 | 175 | ||
176 | 176 | ||
177 | wpng_info.infile = NULL; | 177 | wpng_info.infile = NULL; |
178 | wpng_info.outfile = NULL; | 178 | wpng_info.outfile = NULL; |
179 | wpng_info.image_data = NULL; | 179 | wpng_info.image_data = NULL; |
180 | wpng_info.row_pointers = NULL; | 180 | wpng_info.row_pointers = NULL; |
181 | wpng_info.filter = FALSE; | 181 | wpng_info.filter = FALSE; |
182 | wpng_info.interlaced = FALSE; | 182 | wpng_info.interlaced = FALSE; |
183 | wpng_info.have_bg = FALSE; | 183 | wpng_info.have_bg = FALSE; |
184 | wpng_info.have_time = FALSE; | 184 | wpng_info.have_time = FALSE; |
185 | wpng_info.have_text = 0; | 185 | wpng_info.have_text = 0; |
186 | wpng_info.gamma = 0.0; | 186 | wpng_info.gamma = 0.0; |
187 | 187 | ||
188 | 188 | ||
189 | /* First get the default value for our display-system exponent, i.e., | 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 | 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 | 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 | 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 | 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 | 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 | 195 | * cover 99% of the current possibilities. This section must ensure |
196 | * that default_display_exponent is positive.) */ | 196 | * that default_display_exponent is positive.) */ |
197 | 197 | ||
198 | #if defined(NeXT) | 198 | #if defined(NeXT) |
199 | /* third-party utilities can modify the default LUT exponent */ | 199 | /* third-party utilities can modify the default LUT exponent */ |
200 | LUT_exponent = 1.0 / 2.2; | 200 | LUT_exponent = 1.0 / 2.2; |
201 | /* | 201 | /* |
202 | if (some_next_function_that_returns_gamma(&next_gamma)) | 202 | if (some_next_function_that_returns_gamma(&next_gamma)) |
203 | LUT_exponent = 1.0 / next_gamma; | 203 | LUT_exponent = 1.0 / next_gamma; |
204 | */ | 204 | */ |
205 | #elif defined(sgi) | 205 | #elif defined(sgi) |
206 | LUT_exponent = 1.0 / 1.7; | 206 | LUT_exponent = 1.0 / 1.7; |
207 | /* there doesn't seem to be any documented function to | 207 | /* there doesn't seem to be any documented function to |
208 | * get the "gamma" value, so we do it the hard way */ | 208 | * get the "gamma" value, so we do it the hard way */ |
209 | tmpfile = fopen("/etc/config/system.glGammaVal", "r"); | 209 | tmpfile = fopen("/etc/config/system.glGammaVal", "r"); |
210 | if (tmpfile) { | 210 | if (tmpfile) { |
211 | double sgi_gamma; | 211 | double sgi_gamma; |
212 | 212 | ||
213 | fgets(tmpline, 80, tmpfile); | 213 | fgets(tmpline, 80, tmpfile); |
214 | fclose(tmpfile); | 214 | fclose(tmpfile); |
215 | sgi_gamma = atof(tmpline); | 215 | sgi_gamma = atof(tmpline); |
216 | if (sgi_gamma > 0.0) | 216 | if (sgi_gamma > 0.0) |
217 | LUT_exponent = 1.0 / sgi_gamma; | 217 | LUT_exponent = 1.0 / sgi_gamma; |
218 | } | 218 | } |
219 | #elif defined(Macintosh) | 219 | #elif defined(Macintosh) |
220 | LUT_exponent = 1.8 / 2.61; | 220 | LUT_exponent = 1.8 / 2.61; |
221 | /* | 221 | /* |
222 | if (some_mac_function_that_returns_gamma(&mac_gamma)) | 222 | if (some_mac_function_that_returns_gamma(&mac_gamma)) |
223 | LUT_exponent = mac_gamma / 2.61; | 223 | LUT_exponent = mac_gamma / 2.61; |
224 | */ | 224 | */ |
225 | #else | 225 | #else |
226 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ | 226 | LUT_exponent = 1.0; /* assume no LUT: most PCs */ |
227 | #endif | 227 | #endif |
228 | 228 | ||
229 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ | 229 | /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */ |
230 | default_display_exponent = LUT_exponent * CRT_exponent; | 230 | default_display_exponent = LUT_exponent * CRT_exponent; |
231 | 231 | ||
232 | 232 | ||
233 | /* If the user has set the SCREEN_GAMMA environment variable as suggested | 233 | /* If the user has set the SCREEN_GAMMA environment variable as suggested |
234 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise | 234 | * (somewhat imprecisely) in the libpng documentation, use that; otherwise |
235 | * use the default value we just calculated. Either way, the user may | 235 | * use the default value we just calculated. Either way, the user may |
236 | * override this via a command-line option. */ | 236 | * override this via a command-line option. */ |
237 | 237 | ||
238 | if ((p = getenv("SCREEN_GAMMA")) != NULL) { | 238 | if ((p = getenv("SCREEN_GAMMA")) != NULL) { |
239 | double exponent = atof(p); | 239 | double exponent = atof(p); |
240 | 240 | ||
241 | if (exponent > 0.0) | 241 | if (exponent > 0.0) |
242 | default_gamma = 1.0 / exponent; | 242 | default_gamma = 1.0 / exponent; |
243 | } | 243 | } |
244 | 244 | ||
245 | if (default_gamma == 0.0) | 245 | if (default_gamma == 0.0) |
246 | default_gamma = 1.0 / default_display_exponent; | 246 | default_gamma = 1.0 / default_display_exponent; |
247 | 247 | ||
248 | 248 | ||
249 | /* Now parse the command line for options and the PNM filename. */ | 249 | /* Now parse the command line for options and the PNM filename. */ |
250 | 250 | ||
251 | while (*++argv && !error) { | 251 | while (*++argv && !error) { |
252 | if (!strncmp(*argv, "-i", 2)) { | 252 | if (!strncmp(*argv, "-i", 2)) { |
253 | wpng_info.interlaced = TRUE; | 253 | wpng_info.interlaced = TRUE; |
254 | } else if (!strncmp(*argv, "-time", 3)) { | 254 | } else if (!strncmp(*argv, "-time", 3)) { |
255 | wpng_info.modtime = time(NULL); | 255 | wpng_info.modtime = time(NULL); |
256 | wpng_info.have_time = TRUE; | 256 | wpng_info.have_time = TRUE; |
257 | } else if (!strncmp(*argv, "-text", 3)) { | 257 | } else if (!strncmp(*argv, "-text", 3)) { |
258 | text = TRUE; | 258 | text = TRUE; |
259 | } else if (!strncmp(*argv, "-gamma", 2)) { | 259 | } else if (!strncmp(*argv, "-gamma", 2)) { |
260 | if (!*++argv) | 260 | if (!*++argv) |
261 | ++error; | 261 | ++error; |
262 | else { | 262 | else { |
263 | wpng_info.gamma = atof(*argv); | 263 | wpng_info.gamma = atof(*argv); |
264 | if (wpng_info.gamma <= 0.0) | 264 | if (wpng_info.gamma <= 0.0) |
265 | ++error; | 265 | ++error; |
266 | else if (wpng_info.gamma > 1.01) | 266 | else if (wpng_info.gamma > 1.01) |
267 | fprintf(stderr, PROGNAME | 267 | fprintf(stderr, PROGNAME |
268 | " warning: file gammas are usually less than 1.0\n"); | 268 | " warning: file gammas are usually less than 1.0\n"); |
269 | } | 269 | } |
270 | } else if (!strncmp(*argv, "-bgcolor", 4)) { | 270 | } else if (!strncmp(*argv, "-bgcolor", 4)) { |
271 | if (!*++argv) | 271 | if (!*++argv) |
272 | ++error; | 272 | ++error; |
273 | else { | 273 | else { |
274 | bgstr = *argv; | 274 | bgstr = *argv; |
275 | if (strlen(bgstr) != 7 || bgstr[0] != '#') | 275 | if (strlen(bgstr) != 7 || bgstr[0] != '#') |
276 | ++error; | 276 | ++error; |
277 | else { | 277 | else { |
278 | unsigned r, g, b; /* this way quiets compiler warnings */ | 278 | unsigned r, g, b; /* this way quiets compiler warnings */ |
279 | 279 | ||
280 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); | 280 | sscanf(bgstr+1, "%2x%2x%2x", &r, &g, &b); |
281 | wpng_info.bg_red = (uch)r; | 281 | wpng_info.bg_red = (uch)r; |
282 | wpng_info.bg_green = (uch)g; | 282 | wpng_info.bg_green = (uch)g; |
283 | wpng_info.bg_blue = (uch)b; | 283 | wpng_info.bg_blue = (uch)b; |
284 | wpng_info.have_bg = TRUE; | 284 | wpng_info.have_bg = TRUE; |
285 | } | 285 | } |
286 | } | 286 | } |
287 | } else { | 287 | } else { |
288 | if (**argv != '-') { | 288 | if (**argv != '-') { |
289 | inname = *argv; | 289 | inname = *argv; |
290 | if (argv[1]) /* shouldn't be any more args after filename */ | 290 | if (argv[1]) /* shouldn't be any more args after filename */ |
291 | ++error; | 291 | ++error; |
292 | } else | 292 | } else |
293 | ++error; /* not expecting any other options */ | 293 | ++error; /* not expecting any other options */ |
294 | } | 294 | } |
295 | } | 295 | } |
296 | 296 | ||
297 | 297 | ||
298 | /* open the input and output files, or register an error and abort */ | 298 | /* open the input and output files, or register an error and abort */ |
299 | 299 | ||
300 | if (!inname) { | 300 | if (!inname) { |
301 | if (isatty(0)) { | 301 | if (isatty(0)) { |
302 | fprintf(stderr, PROGNAME | 302 | fprintf(stderr, PROGNAME |
303 | ": must give input filename or provide image data via stdin\n"); | 303 | ": must give input filename or provide image data via stdin\n"); |
304 | ++error; | 304 | ++error; |
305 | } else { | 305 | } else { |
306 | #ifdef DOS_OS2_W32 | 306 | #ifdef DOS_OS2_W32 |
307 | /* some buggy C libraries require BOTH setmode() and fdopen(bin) */ | 307 | /* some buggy C libraries require BOTH setmode() and fdopen(bin) */ |
308 | setmode(fileno(stdin), O_BINARY); | 308 | setmode(fileno(stdin), O_BINARY); |
309 | setmode(fileno(stdout), O_BINARY); | 309 | setmode(fileno(stdout), O_BINARY); |
310 | #endif | 310 | #endif |
311 | if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) { | 311 | if ((wpng_info.infile = fdopen(fileno(stdin), "rb")) == NULL) { |
312 | fprintf(stderr, PROGNAME | 312 | fprintf(stderr, PROGNAME |
313 | ": unable to reopen stdin in binary mode\n"); | 313 | ": unable to reopen stdin in binary mode\n"); |
314 | ++error; | 314 | ++error; |
315 | } else | 315 | } else |
316 | if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) { | 316 | if ((wpng_info.outfile = fdopen(fileno(stdout), "wb")) == NULL) { |
317 | fprintf(stderr, PROGNAME | 317 | fprintf(stderr, PROGNAME |
318 | ": unable to reopen stdout in binary mode\n"); | 318 | ": unable to reopen stdout in binary mode\n"); |
319 | fclose(wpng_info.infile); | 319 | fclose(wpng_info.infile); |
320 | ++error; | 320 | ++error; |
321 | } else | 321 | } else |
322 | wpng_info.filter = TRUE; | 322 | wpng_info.filter = TRUE; |
323 | } | 323 | } |
324 | } else if ((len = strlen(inname)) > 250) { | 324 | } else if ((len = strlen(inname)) > 250) { |
325 | fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n", | 325 | fprintf(stderr, PROGNAME ": input filename is too long [%d chars]\n", |
326 | len); | 326 | len); |
327 | ++error; | 327 | ++error; |
328 | } else if (!(wpng_info.infile = fopen(inname, "rb"))) { | 328 | } else if (!(wpng_info.infile = fopen(inname, "rb"))) { |
329 | fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname); | 329 | fprintf(stderr, PROGNAME ": can't open input file [%s]\n", inname); |
330 | ++error; | 330 | ++error; |
331 | } | 331 | } |
332 | 332 | ||
333 | if (!error) { | 333 | if (!error) { |
334 | fgets(pnmline, 256, wpng_info.infile); | 334 | fgets(pnmline, 256, wpng_info.infile); |
335 | if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' && | 335 | if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' && |
336 | pnmchar != '6' && pnmchar != '8')) | 336 | pnmchar != '6' && pnmchar != '8')) |
337 | { | 337 | { |
338 | fprintf(stderr, PROGNAME | 338 | fprintf(stderr, PROGNAME |
339 | ": input file [%s] is not a binary PGM, PPM or PAM file\n", | 339 | ": input file [%s] is not a binary PGM, PPM or PAM file\n", |
340 | inname); | 340 | inname); |
341 | ++error; | 341 | ++error; |
342 | } else { | 342 | } else { |
343 | wpng_info.pnmtype = (int)(pnmchar - '0'); | 343 | wpng_info.pnmtype = (int)(pnmchar - '0'); |
344 | if (wpng_info.pnmtype != 8) | 344 | if (wpng_info.pnmtype != 8) |
345 | wpng_info.have_bg = FALSE; /* no need for bg if opaque */ | 345 | wpng_info.have_bg = FALSE; /* no need for bg if opaque */ |
346 | do { | 346 | do { |
347 | fgets(pnmline, 256, wpng_info.infile); /* lose any comments */ | 347 | fgets(pnmline, 256, wpng_info.infile); /* lose any comments */ |
348 | } while (pnmline[0] == '#'); | 348 | } while (pnmline[0] == '#'); |
349 | sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height); | 349 | sscanf(pnmline, "%ld %ld", &wpng_info.width, &wpng_info.height); |
350 | do { | 350 | do { |
351 | fgets(pnmline, 256, wpng_info.infile); /* more comment lines */ | 351 | fgets(pnmline, 256, wpng_info.infile); /* more comment lines */ |
352 | } while (pnmline[0] == '#'); | 352 | } while (pnmline[0] == '#'); |
353 | sscanf(pnmline, "%d", &maxval); | 353 | sscanf(pnmline, "%d", &maxval); |
354 | if (wpng_info.width <= 0L || wpng_info.height <= 0L || | 354 | if (wpng_info.width <= 0L || wpng_info.height <= 0L || |
355 | maxval != 255) | 355 | maxval != 255) |
356 | { | 356 | { |
357 | fprintf(stderr, PROGNAME | 357 | fprintf(stderr, PROGNAME |
358 | ": only positive width/height, maxval == 255 allowed \n"); | 358 | ": only positive width/height, maxval == 255 allowed \n"); |
359 | ++error; | 359 | ++error; |
360 | } | 360 | } |
361 | wpng_info.sample_depth = 8; /* <==> maxval 255 */ | 361 | wpng_info.sample_depth = 8; /* <==> maxval 255 */ |
362 | 362 | ||
363 | if (!wpng_info.filter) { | 363 | if (!wpng_info.filter) { |
364 | /* make outname from inname */ | 364 | /* make outname from inname */ |
365 | if ((p = strrchr(inname, '.')) == NULL || | 365 | if ((p = strrchr(inname, '.')) == NULL || |
366 | (p - inname) != (len - 4)) | 366 | (p - inname) != (len - 4)) |
367 | { | 367 | { |
368 | strcpy(outname, inname); | 368 | strcpy(outname, inname); |
369 | strcpy(outname+len, ".png"); | 369 | strcpy(outname+len, ".png"); |
370 | } else { | 370 | } else { |
371 | len -= 4; | 371 | len -= 4; |
372 | strncpy(outname, inname, len); | 372 | strncpy(outname, inname, len); |
373 | strcpy(outname+len, ".png"); | 373 | strcpy(outname+len, ".png"); |
374 | } | 374 | } |
375 | /* check if outname already exists; if not, open */ | 375 | /* check if outname already exists; if not, open */ |
376 | if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) { | 376 | if ((wpng_info.outfile = fopen(outname, "rb")) != NULL) { |
377 | fprintf(stderr, PROGNAME ": output file exists [%s]\n", | 377 | fprintf(stderr, PROGNAME ": output file exists [%s]\n", |
378 | outname); | 378 | outname); |
379 | fclose(wpng_info.outfile); | 379 | fclose(wpng_info.outfile); |
380 | ++error; | 380 | ++error; |
381 | } else if (!(wpng_info.outfile = fopen(outname, "wb"))) { | 381 | } else if (!(wpng_info.outfile = fopen(outname, "wb"))) { |
382 | fprintf(stderr, PROGNAME ": can't open output file [%s]\n", | 382 | fprintf(stderr, PROGNAME ": can't open output file [%s]\n", |
383 | outname); | 383 | outname); |
384 | ++error; | 384 | ++error; |
385 | } | 385 | } |
386 | } | 386 | } |
387 | } | 387 | } |
388 | if (error) { | 388 | if (error) { |
389 | fclose(wpng_info.infile); | 389 | fclose(wpng_info.infile); |
390 | wpng_info.infile = NULL; | 390 | wpng_info.infile = NULL; |
391 | if (wpng_info.filter) { | 391 | if (wpng_info.filter) { |
392 | fclose(wpng_info.outfile); | 392 | fclose(wpng_info.outfile); |
393 | wpng_info.outfile = NULL; | 393 | wpng_info.outfile = NULL; |
394 | } | 394 | } |
395 | } | 395 | } |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
399 | /* if we had any errors, print usage and die horrible death...arrr! */ | 399 | /* if we had any errors, print usage and die horrible death...arrr! */ |
400 | 400 | ||
401 | if (error) { | 401 | if (error) { |
402 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME); | 402 | fprintf(stderr, "\n%s %s: %s\n", PROGNAME, VERSION, APPNAME); |
403 | writepng_version_info(); | 403 | writepng_version_info(); |
404 | fprintf(stderr, "\n" | 404 | fprintf(stderr, "\n" |
405 | "Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n" | 405 | "Usage: %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\n" |
406 | "or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n" | 406 | "or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\n" |
407 | " exp \ttransfer-function exponent (``gamma'') of the image in\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" | 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" | 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" | 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" | 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" | 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" | 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" | 414 | "\t\t 7-character hex RGB format (e.g., ``#ff7700'' for orange:\n" |
415 | "\t\t same as HTML colors)\n" | 415 | "\t\t same as HTML colors)\n" |
416 | " -text\tprompt interactively for text info (tEXt chunks)\n" | 416 | " -text\tprompt interactively for text info (tEXt chunks)\n" |
417 | " -time\tinclude a tIME chunk (last modification time)\n" | 417 | " -time\tinclude a tIME chunk (last modification time)\n" |
418 | " -interlace\twrite interlaced PNG image\n" | 418 | " -interlace\twrite interlaced PNG image\n" |
419 | "\n" | 419 | "\n" |
420 | "pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\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" | 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" | 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" | 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" | 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" | 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" | 426 | "requested; in that case the whole image will be buffered in memory and\n" |
427 | "written in one call.\n" | 427 | "written in one call.\n" |
428 | "\n", PROGNAME, PROGNAME, default_gamma); | 428 | "\n", PROGNAME, PROGNAME, default_gamma); |
429 | exit(1); | 429 | exit(1); |
430 | } | 430 | } |
431 | 431 | ||
432 | 432 | ||
433 | /* prepare the text buffers for libpng's use; note that even though | 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 | 434 | * PNG's png_text struct includes a length field, we don't have to fill |
435 | * it out */ | 435 | * it out */ |
436 | 436 | ||
437 | if (text && | 437 | if (text && |
438 | #ifndef DOS_OS2_W32 | 438 | #ifndef DOS_OS2_W32 |
439 | (keybd = fdopen(fileno(stderr), "r")) != NULL && | 439 | (keybd = fdopen(fileno(stderr), "r")) != NULL && |
440 | #endif | 440 | #endif |
441 | (textbuf = (char *)malloc((5 + 9)*75)) != NULL) | 441 | (textbuf = (char *)malloc((5 + 9)*75)) != NULL) |
442 | { | 442 | { |
443 | int i, valid, result; | 443 | int i, valid, result; |
444 | 444 | ||
445 | fprintf(stderr, | 445 | fprintf(stderr, |
446 | "Enter text info (no more than 72 characters per line);\n"); | 446 | "Enter text info (no more than 72 characters per line);\n"); |
447 | fprintf(stderr, "to skip a field, hit the <Enter> key.\n"); | 447 | fprintf(stderr, "to skip a field, hit the <Enter> key.\n"); |
448 | /* note: just <Enter> leaves len == 1 */ | 448 | /* note: just <Enter> leaves len == 1 */ |
449 | 449 | ||
450 | do { | 450 | do { |
451 | valid = TRUE; | 451 | valid = TRUE; |
452 | p = textbuf + TEXT_TITLE_OFFSET; | 452 | p = textbuf + TEXT_TITLE_OFFSET; |
453 | fprintf(stderr, " Title: "); | 453 | fprintf(stderr, " Title: "); |
454 | fflush(stderr); | 454 | fflush(stderr); |
455 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { | 455 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { |
456 | if (p[len-1] == '\n') | 456 | if (p[len-1] == '\n') |
457 | p[--len] = '\0'; | 457 | p[--len] = '\0'; |
458 | wpng_info.title = p; | 458 | wpng_info.title = p; |
459 | wpng_info.have_text |= TEXT_TITLE; | 459 | wpng_info.have_text |= TEXT_TITLE; |
460 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { | 460 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { |
461 | fprintf(stderr, " " PROGNAME " warning: character code" | 461 | fprintf(stderr, " " PROGNAME " warning: character code" |
462 | " %u is %sdiscouraged by the PNG\n specification " | 462 | " %u is %sdiscouraged by the PNG\n specification " |
463 | "[first occurrence was at character position #%d]\n", | 463 | "[first occurrence was at character position #%d]\n", |
464 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", | 464 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", |
465 | result+1); | 465 | result+1); |
466 | fflush(stderr); | 466 | fflush(stderr); |
467 | #ifdef FORBID_LATIN1_CTRL | 467 | #ifdef FORBID_LATIN1_CTRL |
468 | wpng_info.have_text &= ~TEXT_TITLE; | 468 | wpng_info.have_text &= ~TEXT_TITLE; |
469 | valid = FALSE; | 469 | valid = FALSE; |
470 | #else | 470 | #else |
471 | if (p[result] == 27) { /* escape character */ | 471 | if (p[result] == 27) { /* escape character */ |
472 | wpng_info.have_text &= ~TEXT_TITLE; | 472 | wpng_info.have_text &= ~TEXT_TITLE; |
473 | valid = FALSE; | 473 | valid = FALSE; |
474 | } | 474 | } |
475 | #endif | 475 | #endif |
476 | } | 476 | } |
477 | } | 477 | } |
478 | } while (!valid); | 478 | } while (!valid); |
479 | 479 | ||
480 | do { | 480 | do { |
481 | valid = TRUE; | 481 | valid = TRUE; |
482 | p = textbuf + TEXT_AUTHOR_OFFSET; | 482 | p = textbuf + TEXT_AUTHOR_OFFSET; |
483 | fprintf(stderr, " Author: "); | 483 | fprintf(stderr, " Author: "); |
484 | fflush(stderr); | 484 | fflush(stderr); |
485 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { | 485 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { |
486 | if (p[len-1] == '\n') | 486 | if (p[len-1] == '\n') |
487 | p[--len] = '\0'; | 487 | p[--len] = '\0'; |
488 | wpng_info.author = p; | 488 | wpng_info.author = p; |
489 | wpng_info.have_text |= TEXT_AUTHOR; | 489 | wpng_info.have_text |= TEXT_AUTHOR; |
490 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { | 490 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { |
491 | fprintf(stderr, " " PROGNAME " warning: character code" | 491 | fprintf(stderr, " " PROGNAME " warning: character code" |
492 | " %u is %sdiscouraged by the PNG\n specification " | 492 | " %u is %sdiscouraged by the PNG\n specification " |
493 | "[first occurrence was at character position #%d]\n", | 493 | "[first occurrence was at character position #%d]\n", |
494 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", | 494 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", |
495 | result+1); | 495 | result+1); |
496 | fflush(stderr); | 496 | fflush(stderr); |
497 | #ifdef FORBID_LATIN1_CTRL | 497 | #ifdef FORBID_LATIN1_CTRL |
498 | wpng_info.have_text &= ~TEXT_AUTHOR; | 498 | wpng_info.have_text &= ~TEXT_AUTHOR; |
499 | valid = FALSE; | 499 | valid = FALSE; |
500 | #else | 500 | #else |
501 | if (p[result] == 27) { /* escape character */ | 501 | if (p[result] == 27) { /* escape character */ |
502 | wpng_info.have_text &= ~TEXT_AUTHOR; | 502 | wpng_info.have_text &= ~TEXT_AUTHOR; |
503 | valid = FALSE; | 503 | valid = FALSE; |
504 | } | 504 | } |
505 | #endif | 505 | #endif |
506 | } | 506 | } |
507 | } | 507 | } |
508 | } while (!valid); | 508 | } while (!valid); |
509 | 509 | ||
510 | do { | 510 | do { |
511 | valid = TRUE; | 511 | valid = TRUE; |
512 | p = textbuf + TEXT_DESC_OFFSET; | 512 | p = textbuf + TEXT_DESC_OFFSET; |
513 | fprintf(stderr, " Description (up to 9 lines):\n"); | 513 | fprintf(stderr, " Description (up to 9 lines):\n"); |
514 | for (i = 1; i < 10; ++i) { | 514 | for (i = 1; i < 10; ++i) { |
515 | fprintf(stderr, " [%d] ", i); | 515 | fprintf(stderr, " [%d] ", i); |
516 | fflush(stderr); | 516 | fflush(stderr); |
517 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) | 517 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) |
518 | p += len; /* now points at NULL; char before is newline */ | 518 | p += len; /* now points at NULL; char before is newline */ |
519 | else | 519 | else |
520 | break; | 520 | break; |
521 | } | 521 | } |
522 | if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) { | 522 | if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) { |
523 | if (p[-1] == '\n') { | 523 | if (p[-1] == '\n') { |
524 | p[-1] = '\0'; | 524 | p[-1] = '\0'; |
525 | --len; | 525 | --len; |
526 | } | 526 | } |
527 | wpng_info.desc = textbuf + TEXT_DESC_OFFSET; | 527 | wpng_info.desc = textbuf + TEXT_DESC_OFFSET; |
528 | wpng_info.have_text |= TEXT_DESC; | 528 | wpng_info.have_text |= TEXT_DESC; |
529 | p = textbuf + TEXT_DESC_OFFSET; | 529 | p = textbuf + TEXT_DESC_OFFSET; |
530 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { | 530 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { |
531 | fprintf(stderr, " " PROGNAME " warning: character code" | 531 | fprintf(stderr, " " PROGNAME " warning: character code" |
532 | " %u is %sdiscouraged by the PNG\n specification " | 532 | " %u is %sdiscouraged by the PNG\n specification " |
533 | "[first occurrence was at character position #%d]\n", | 533 | "[first occurrence was at character position #%d]\n", |
534 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", | 534 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", |
535 | result+1); | 535 | result+1); |
536 | fflush(stderr); | 536 | fflush(stderr); |
537 | #ifdef FORBID_LATIN1_CTRL | 537 | #ifdef FORBID_LATIN1_CTRL |
538 | wpng_info.have_text &= ~TEXT_DESC; | 538 | wpng_info.have_text &= ~TEXT_DESC; |
539 | valid = FALSE; | 539 | valid = FALSE; |
540 | #else | 540 | #else |
541 | if (p[result] == 27) { /* escape character */ | 541 | if (p[result] == 27) { /* escape character */ |
542 | wpng_info.have_text &= ~TEXT_DESC; | 542 | wpng_info.have_text &= ~TEXT_DESC; |
543 | valid = FALSE; | 543 | valid = FALSE; |
544 | } | 544 | } |
545 | #endif | 545 | #endif |
546 | } | 546 | } |
547 | } | 547 | } |
548 | } while (!valid); | 548 | } while (!valid); |
549 | 549 | ||
550 | do { | 550 | do { |
551 | valid = TRUE; | 551 | valid = TRUE; |
552 | p = textbuf + TEXT_COPY_OFFSET; | 552 | p = textbuf + TEXT_COPY_OFFSET; |
553 | fprintf(stderr, " Copyright: "); | 553 | fprintf(stderr, " Copyright: "); |
554 | fflush(stderr); | 554 | fflush(stderr); |
555 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { | 555 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { |
556 | if (p[len-1] == '\n') | 556 | if (p[len-1] == '\n') |
557 | p[--len] = '\0'; | 557 | p[--len] = '\0'; |
558 | wpng_info.copyright = p; | 558 | wpng_info.copyright = p; |
559 | wpng_info.have_text |= TEXT_COPY; | 559 | wpng_info.have_text |= TEXT_COPY; |
560 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { | 560 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { |
561 | fprintf(stderr, " " PROGNAME " warning: character code" | 561 | fprintf(stderr, " " PROGNAME " warning: character code" |
562 | " %u is %sdiscouraged by the PNG\n specification " | 562 | " %u is %sdiscouraged by the PNG\n specification " |
563 | "[first occurrence was at character position #%d]\n", | 563 | "[first occurrence was at character position #%d]\n", |
564 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", | 564 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", |
565 | result+1); | 565 | result+1); |
566 | fflush(stderr); | 566 | fflush(stderr); |
567 | #ifdef FORBID_LATIN1_CTRL | 567 | #ifdef FORBID_LATIN1_CTRL |
568 | wpng_info.have_text &= ~TEXT_COPY; | 568 | wpng_info.have_text &= ~TEXT_COPY; |
569 | valid = FALSE; | 569 | valid = FALSE; |
570 | #else | 570 | #else |
571 | if (p[result] == 27) { /* escape character */ | 571 | if (p[result] == 27) { /* escape character */ |
572 | wpng_info.have_text &= ~TEXT_COPY; | 572 | wpng_info.have_text &= ~TEXT_COPY; |
573 | valid = FALSE; | 573 | valid = FALSE; |
574 | } | 574 | } |
575 | #endif | 575 | #endif |
576 | } | 576 | } |
577 | } | 577 | } |
578 | } while (!valid); | 578 | } while (!valid); |
579 | 579 | ||
580 | do { | 580 | do { |
581 | valid = TRUE; | 581 | valid = TRUE; |
582 | p = textbuf + TEXT_EMAIL_OFFSET; | 582 | p = textbuf + TEXT_EMAIL_OFFSET; |
583 | fprintf(stderr, " E-mail: "); | 583 | fprintf(stderr, " E-mail: "); |
584 | fflush(stderr); | 584 | fflush(stderr); |
585 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { | 585 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { |
586 | if (p[len-1] == '\n') | 586 | if (p[len-1] == '\n') |
587 | p[--len] = '\0'; | 587 | p[--len] = '\0'; |
588 | wpng_info.email = p; | 588 | wpng_info.email = p; |
589 | wpng_info.have_text |= TEXT_EMAIL; | 589 | wpng_info.have_text |= TEXT_EMAIL; |
590 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { | 590 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { |
591 | fprintf(stderr, " " PROGNAME " warning: character code" | 591 | fprintf(stderr, " " PROGNAME " warning: character code" |
592 | " %u is %sdiscouraged by the PNG\n specification " | 592 | " %u is %sdiscouraged by the PNG\n specification " |
593 | "[first occurrence was at character position #%d]\n", | 593 | "[first occurrence was at character position #%d]\n", |
594 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", | 594 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", |
595 | result+1); | 595 | result+1); |
596 | fflush(stderr); | 596 | fflush(stderr); |
597 | #ifdef FORBID_LATIN1_CTRL | 597 | #ifdef FORBID_LATIN1_CTRL |
598 | wpng_info.have_text &= ~TEXT_EMAIL; | 598 | wpng_info.have_text &= ~TEXT_EMAIL; |
599 | valid = FALSE; | 599 | valid = FALSE; |
600 | #else | 600 | #else |
601 | if (p[result] == 27) { /* escape character */ | 601 | if (p[result] == 27) { /* escape character */ |
602 | wpng_info.have_text &= ~TEXT_EMAIL; | 602 | wpng_info.have_text &= ~TEXT_EMAIL; |
603 | valid = FALSE; | 603 | valid = FALSE; |
604 | } | 604 | } |
605 | #endif | 605 | #endif |
606 | } | 606 | } |
607 | } | 607 | } |
608 | } while (!valid); | 608 | } while (!valid); |
609 | 609 | ||
610 | do { | 610 | do { |
611 | valid = TRUE; | 611 | valid = TRUE; |
612 | p = textbuf + TEXT_URL_OFFSET; | 612 | p = textbuf + TEXT_URL_OFFSET; |
613 | fprintf(stderr, " URL: "); | 613 | fprintf(stderr, " URL: "); |
614 | fflush(stderr); | 614 | fflush(stderr); |
615 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { | 615 | if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) { |
616 | if (p[len-1] == '\n') | 616 | if (p[len-1] == '\n') |
617 | p[--len] = '\0'; | 617 | p[--len] = '\0'; |
618 | wpng_info.url = p; | 618 | wpng_info.url = p; |
619 | wpng_info.have_text |= TEXT_URL; | 619 | wpng_info.have_text |= TEXT_URL; |
620 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { | 620 | if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) { |
621 | fprintf(stderr, " " PROGNAME " warning: character code" | 621 | fprintf(stderr, " " PROGNAME " warning: character code" |
622 | " %u is %sdiscouraged by the PNG\n specification " | 622 | " %u is %sdiscouraged by the PNG\n specification " |
623 | "[first occurrence was at character position #%d]\n", | 623 | "[first occurrence was at character position #%d]\n", |
624 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", | 624 | (unsigned)p[result], (p[result] == 27)? "strongly " : "", |
625 | result+1); | 625 | result+1); |
626 | fflush(stderr); | 626 | fflush(stderr); |
627 | #ifdef FORBID_LATIN1_CTRL | 627 | #ifdef FORBID_LATIN1_CTRL |
628 | wpng_info.have_text &= ~TEXT_URL; | 628 | wpng_info.have_text &= ~TEXT_URL; |
629 | valid = FALSE; | 629 | valid = FALSE; |
630 | #else | 630 | #else |
631 | if (p[result] == 27) { /* escape character */ | 631 | if (p[result] == 27) { /* escape character */ |
632 | wpng_info.have_text &= ~TEXT_URL; | 632 | wpng_info.have_text &= ~TEXT_URL; |
633 | valid = FALSE; | 633 | valid = FALSE; |
634 | } | 634 | } |
635 | #endif | 635 | #endif |
636 | } | 636 | } |
637 | } | 637 | } |
638 | } while (!valid); | 638 | } while (!valid); |
639 | 639 | ||
640 | #ifndef DOS_OS2_W32 | 640 | #ifndef DOS_OS2_W32 |
641 | fclose(keybd); | 641 | fclose(keybd); |
642 | #endif | 642 | #endif |
643 | 643 | ||
644 | } else if (text) { | 644 | } else if (text) { |
645 | fprintf(stderr, PROGNAME ": unable to allocate memory for text\n"); | 645 | fprintf(stderr, PROGNAME ": unable to allocate memory for text\n"); |
646 | text = FALSE; | 646 | text = FALSE; |
647 | wpng_info.have_text = 0; | 647 | wpng_info.have_text = 0; |
648 | } | 648 | } |
649 | 649 | ||
650 | 650 | ||
651 | /* allocate libpng stuff, initialize transformations, write pre-IDAT data */ | 651 | /* allocate libpng stuff, initialize transformations, write pre-IDAT data */ |
652 | 652 | ||
653 | if ((rc = writepng_init(&wpng_info)) != 0) { | 653 | if ((rc = writepng_init(&wpng_info)) != 0) { |
654 | switch (rc) { | 654 | switch (rc) { |
655 | case 2: | 655 | case 2: |
656 | fprintf(stderr, PROGNAME | 656 | fprintf(stderr, PROGNAME |
657 | ": libpng initialization problem (longjmp)\n"); | 657 | ": libpng initialization problem (longjmp)\n"); |
658 | break; | 658 | break; |
659 | case 4: | 659 | case 4: |
660 | fprintf(stderr, PROGNAME ": insufficient memory\n"); | 660 | fprintf(stderr, PROGNAME ": insufficient memory\n"); |
661 | break; | 661 | break; |
662 | case 11: | 662 | case 11: |
663 | fprintf(stderr, PROGNAME | 663 | fprintf(stderr, PROGNAME |
664 | ": internal logic error (unexpected PNM type)\n"); | 664 | ": internal logic error (unexpected PNM type)\n"); |
665 | break; | 665 | break; |
666 | default: | 666 | default: |
667 | fprintf(stderr, PROGNAME | 667 | fprintf(stderr, PROGNAME |
668 | ": unknown writepng_init() error\n"); | 668 | ": unknown writepng_init() error\n"); |
669 | break; | 669 | break; |
670 | } | 670 | } |
671 | exit(rc); | 671 | exit(rc); |
672 | } | 672 | } |
673 | 673 | ||
674 | 674 | ||
675 | /* free textbuf, since it's a completely local variable and all text info | 675 | /* free textbuf, since it's a completely local variable and all text info |
676 | * has just been written to the PNG file */ | 676 | * has just been written to the PNG file */ |
677 | 677 | ||
678 | if (text && textbuf) { | 678 | if (text && textbuf) { |
679 | free(textbuf); | 679 | free(textbuf); |
680 | textbuf = NULL; | 680 | textbuf = NULL; |
681 | } | 681 | } |
682 | 682 | ||
683 | 683 | ||
684 | /* calculate rowbytes on basis of image type; note that this becomes much | 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 | 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] */ | 686 | * 16-bit-per-sample binary data [currently not an official NetPBM type] */ |
687 | 687 | ||
688 | if (wpng_info.pnmtype == 5) | 688 | if (wpng_info.pnmtype == 5) |
689 | rowbytes = wpng_info.width; | 689 | rowbytes = wpng_info.width; |
690 | else if (wpng_info.pnmtype == 6) | 690 | else if (wpng_info.pnmtype == 6) |
691 | rowbytes = wpng_info.width * 3; | 691 | rowbytes = wpng_info.width * 3; |
692 | else /* if (wpng_info.pnmtype == 8) */ | 692 | else /* if (wpng_info.pnmtype == 8) */ |
693 | rowbytes = wpng_info.width * 4; | 693 | rowbytes = wpng_info.width * 4; |
694 | 694 | ||
695 | 695 | ||
696 | /* read and write the image, either in its entirety (if writing interlaced | 696 | /* read and write the image, either in its entirety (if writing interlaced |
697 | * PNG) or row by row (if non-interlaced) */ | 697 | * PNG) or row by row (if non-interlaced) */ |
698 | 698 | ||
699 | fprintf(stderr, "Encoding image data...\n"); | 699 | fprintf(stderr, "Encoding image data...\n"); |
700 | fflush(stderr); | 700 | fflush(stderr); |
701 | 701 | ||
702 | if (wpng_info.interlaced) { | 702 | if (wpng_info.interlaced) { |
703 | long i; | 703 | long i; |
704 | ulg bytes; | 704 | ulg bytes; |
705 | ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */ | 705 | ulg image_bytes = rowbytes * wpng_info.height; /* overflow? */ |
706 | 706 | ||
707 | wpng_info.image_data = (uch *)malloc(image_bytes); | 707 | wpng_info.image_data = (uch *)malloc(image_bytes); |
708 | wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *)); | 708 | wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *)); |
709 | if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) { | 709 | if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) { |
710 | fprintf(stderr, PROGNAME ": insufficient memory for image data\n"); | 710 | fprintf(stderr, PROGNAME ": insufficient memory for image data\n"); |
711 | writepng_cleanup(&wpng_info); | 711 | writepng_cleanup(&wpng_info); |
712 | wpng_cleanup(); | 712 | wpng_cleanup(); |
713 | exit(5); | 713 | exit(5); |
714 | } | 714 | } |
715 | for (i = 0; i < wpng_info.height; ++i) | 715 | for (i = 0; i < wpng_info.height; ++i) |
716 | wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes; | 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); | 717 | bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile); |
718 | if (bytes != image_bytes) { | 718 | if (bytes != image_bytes) { |
719 | fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n", | 719 | fprintf(stderr, PROGNAME ": expected %lu bytes, got %lu bytes\n", |
720 | image_bytes, bytes); | 720 | image_bytes, bytes); |
721 | fprintf(stderr, " (continuing anyway)\n"); | 721 | fprintf(stderr, " (continuing anyway)\n"); |
722 | } | 722 | } |
723 | if (writepng_encode_image(&wpng_info) != 0) { | 723 | if (writepng_encode_image(&wpng_info) != 0) { |
724 | fprintf(stderr, PROGNAME | 724 | fprintf(stderr, PROGNAME |
725 | ": libpng problem (longjmp) while writing image data\n"); | 725 | ": libpng problem (longjmp) while writing image data\n"); |
726 | writepng_cleanup(&wpng_info); | 726 | writepng_cleanup(&wpng_info); |
727 | wpng_cleanup(); | 727 | wpng_cleanup(); |
728 | exit(2); | 728 | exit(2); |
729 | } | 729 | } |
730 | 730 | ||
731 | } else /* not interlaced: write progressively (row by row) */ { | 731 | } else /* not interlaced: write progressively (row by row) */ { |
732 | long j; | 732 | long j; |
733 | ulg bytes; | 733 | ulg bytes; |
734 | 734 | ||
735 | wpng_info.image_data = (uch *)malloc(rowbytes); | 735 | wpng_info.image_data = (uch *)malloc(rowbytes); |
736 | if (wpng_info.image_data == NULL) { | 736 | if (wpng_info.image_data == NULL) { |
737 | fprintf(stderr, PROGNAME ": insufficient memory for row data\n"); | 737 | fprintf(stderr, PROGNAME ": insufficient memory for row data\n"); |
738 | writepng_cleanup(&wpng_info); | 738 | writepng_cleanup(&wpng_info); |
739 | wpng_cleanup(); | 739 | wpng_cleanup(); |
740 | exit(5); | 740 | exit(5); |
741 | } | 741 | } |
742 | error = 0; | 742 | error = 0; |
743 | for (j = wpng_info.height; j > 0L; --j) { | 743 | for (j = wpng_info.height; j > 0L; --j) { |
744 | bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile); | 744 | bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile); |
745 | if (bytes != rowbytes) { | 745 | if (bytes != rowbytes) { |
746 | fprintf(stderr, PROGNAME | 746 | fprintf(stderr, PROGNAME |
747 | ": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes, | 747 | ": expected %lu bytes, got %lu bytes (row %ld)\n", rowbytes, |
748 | bytes, wpng_info.height-j); | 748 | bytes, wpng_info.height-j); |
749 | ++error; | 749 | ++error; |
750 | break; | 750 | break; |
751 | } | 751 | } |
752 | if (writepng_encode_row(&wpng_info) != 0) { | 752 | if (writepng_encode_row(&wpng_info) != 0) { |
753 | fprintf(stderr, PROGNAME | 753 | fprintf(stderr, PROGNAME |
754 | ": libpng problem (longjmp) while writing row %ld\n", | 754 | ": libpng problem (longjmp) while writing row %ld\n", |
755 | wpng_info.height-j); | 755 | wpng_info.height-j); |
756 | ++error; | 756 | ++error; |
757 | break; | 757 | break; |
758 | } | 758 | } |
759 | } | 759 | } |
760 | if (error) { | 760 | if (error) { |
761 | writepng_cleanup(&wpng_info); | 761 | writepng_cleanup(&wpng_info); |
762 | wpng_cleanup(); | 762 | wpng_cleanup(); |
763 | exit(2); | 763 | exit(2); |
764 | } | 764 | } |
765 | if (writepng_encode_finish(&wpng_info) != 0) { | 765 | if (writepng_encode_finish(&wpng_info) != 0) { |
766 | fprintf(stderr, PROGNAME ": error on final libpng call\n"); | 766 | fprintf(stderr, PROGNAME ": error on final libpng call\n"); |
767 | writepng_cleanup(&wpng_info); | 767 | writepng_cleanup(&wpng_info); |
768 | wpng_cleanup(); | 768 | wpng_cleanup(); |
769 | exit(2); | 769 | exit(2); |
770 | } | 770 | } |
771 | } | 771 | } |
772 | 772 | ||
773 | 773 | ||
774 | /* OK, we're done (successfully): clean up all resources and quit */ | 774 | /* OK, we're done (successfully): clean up all resources and quit */ |
775 | 775 | ||
776 | fprintf(stderr, "Done.\n"); | 776 | fprintf(stderr, "Done.\n"); |
777 | fflush(stderr); | 777 | fflush(stderr); |
778 | 778 | ||
779 | writepng_cleanup(&wpng_info); | 779 | writepng_cleanup(&wpng_info); |
780 | wpng_cleanup(); | 780 | wpng_cleanup(); |
781 | 781 | ||
782 | return 0; | 782 | return 0; |
783 | } | 783 | } |
784 | 784 | ||
785 | 785 | ||
786 | 786 | ||
787 | 787 | ||
788 | 788 | ||
789 | static int wpng_isvalid_latin1(uch *p, int len) | 789 | static int wpng_isvalid_latin1(uch *p, int len) |
790 | { | 790 | { |
791 | int i, result = -1; | 791 | int i, result = -1; |
792 | 792 | ||
793 | for (i = 0; i < len; ++i) { | 793 | for (i = 0; i < len; ++i) { |
794 | if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160) | 794 | if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160) |
795 | continue; /* character is completely OK */ | 795 | continue; /* character is completely OK */ |
796 | if (result < 0 || (p[result] != 27 && p[i] == 27)) | 796 | if (result < 0 || (p[result] != 27 && p[i] == 27)) |
797 | result = i; /* mark location of first questionable one */ | 797 | result = i; /* mark location of first questionable one */ |
798 | } /* or of first escape character (bad) */ | 798 | } /* or of first escape character (bad) */ |
799 | 799 | ||
800 | return result; | 800 | return result; |
801 | } | 801 | } |
802 | 802 | ||
803 | 803 | ||
804 | 804 | ||
805 | 805 | ||
806 | 806 | ||
807 | static void wpng_cleanup(void) | 807 | static void wpng_cleanup(void) |
808 | { | 808 | { |
809 | if (wpng_info.outfile) { | 809 | if (wpng_info.outfile) { |
810 | fclose(wpng_info.outfile); | 810 | fclose(wpng_info.outfile); |
811 | wpng_info.outfile = NULL; | 811 | wpng_info.outfile = NULL; |
812 | } | 812 | } |
813 | 813 | ||
814 | if (wpng_info.infile) { | 814 | if (wpng_info.infile) { |
815 | fclose(wpng_info.infile); | 815 | fclose(wpng_info.infile); |
816 | wpng_info.infile = NULL; | 816 | wpng_info.infile = NULL; |
817 | } | 817 | } |
818 | 818 | ||
819 | if (wpng_info.image_data) { | 819 | if (wpng_info.image_data) { |
820 | free(wpng_info.image_data); | 820 | free(wpng_info.image_data); |
821 | wpng_info.image_data = NULL; | 821 | wpng_info.image_data = NULL; |
822 | } | 822 | } |
823 | 823 | ||
824 | if (wpng_info.row_pointers) { | 824 | if (wpng_info.row_pointers) { |
825 | free(wpng_info.row_pointers); | 825 | free(wpng_info.row_pointers); |
826 | wpng_info.row_pointers = NULL; | 826 | wpng_info.row_pointers = NULL; |
827 | } | 827 | } |
828 | } | 828 | } |
829 | 829 | ||
830 | 830 | ||
831 | 831 | ||
832 | 832 | ||
833 | #ifdef DOS_OS2_W32 | 833 | #ifdef DOS_OS2_W32 |
834 | 834 | ||
835 | static char *dos_kbd_gets(char *buf, int len) | 835 | static char *dos_kbd_gets(char *buf, int len) |
836 | { | 836 | { |
837 | int ch, count=0; | 837 | int ch, count=0; |
838 | 838 | ||
839 | do { | 839 | do { |
840 | buf[count++] = ch = getche(); | 840 | buf[count++] = ch = getche(); |
841 | } while (ch != '\r' && count < len-1); | 841 | } while (ch != '\r' && count < len-1); |
842 | 842 | ||
843 | buf[count--] = '\0'; /* terminate string */ | 843 | buf[count--] = '\0'; /* terminate string */ |
844 | if (buf[count] == '\r') /* Enter key makes CR, so change to newline */ | 844 | if (buf[count] == '\r') /* Enter key makes CR, so change to newline */ |
845 | buf[count] = '\n'; | 845 | buf[count] = '\n'; |
846 | 846 | ||
847 | fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */ | 847 | fprintf(stderr, "\n"); /* Enter key does *not* cause a newline */ |
848 | fflush(stderr); | 848 | fflush(stderr); |
849 | 849 | ||
850 | return buf; | 850 | return buf; |
851 | } | 851 | } |
852 | 852 | ||
853 | #endif /* DOS_OS2_W32 */ | 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 index 8373c16..f07f4a8 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.c | |||
@@ -1,400 +1,400 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | wpng - simple PNG-writing program writepng.c | 3 | wpng - simple PNG-writing program writepng.c |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
8 | 8 | ||
9 | This software is provided "as is," without warranty of any kind, | 9 | This software is provided "as is," without warranty of any kind, |
10 | express or implied. In no event shall the author or contributors | 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 | 11 | be held liable for any damages arising in any way from the use of |
12 | this software. | 12 | this software. |
13 | 13 | ||
14 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 15 | redistribute this software according to the terms of one of the |
16 | following two licenses (at your option): | 16 | following two licenses (at your option): |
17 | 17 | ||
18 | 18 | ||
19 | LICENSE 1 ("BSD-like with advertising clause"): | 19 | LICENSE 1 ("BSD-like with advertising clause"): |
20 | 20 | ||
21 | Permission is granted to anyone to use this software for any purpose, | 21 | Permission is granted to anyone to use this software for any purpose, |
22 | including commercial applications, and to alter it and redistribute | 22 | including commercial applications, and to alter it and redistribute |
23 | it freely, subject to the following restrictions: | 23 | it freely, subject to the following restrictions: |
24 | 24 | ||
25 | 1. Redistributions of source code must retain the above copyright | 25 | 1. Redistributions of source code must retain the above copyright |
26 | notice, disclaimer, and this list of conditions. | 26 | notice, disclaimer, and this list of conditions. |
27 | 2. Redistributions in binary form must reproduce the above copyright | 27 | 2. Redistributions in binary form must reproduce the above copyright |
28 | notice, disclaimer, and this list of conditions in the documenta- | 28 | notice, disclaimer, and this list of conditions in the documenta- |
29 | tion and/or other materials provided with the distribution. | 29 | tion and/or other materials provided with the distribution. |
30 | 3. All advertising materials mentioning features or use of this | 30 | 3. All advertising materials mentioning features or use of this |
31 | software must display the following acknowledgment: | 31 | software must display the following acknowledgment: |
32 | 32 | ||
33 | This product includes software developed by Greg Roelofs | 33 | This product includes software developed by Greg Roelofs |
34 | and contributors for the book, "PNG: The Definitive Guide," | 34 | and contributors for the book, "PNG: The Definitive Guide," |
35 | published by O'Reilly and Associates. | 35 | published by O'Reilly and Associates. |
36 | 36 | ||
37 | 37 | ||
38 | LICENSE 2 (GNU GPL v2 or later): | 38 | LICENSE 2 (GNU GPL v2 or later): |
39 | 39 | ||
40 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 42 | the Free Software Foundation; either version 2 of the License, or |
43 | (at your option) any later version. | 43 | (at your option) any later version. |
44 | 44 | ||
45 | This program is distributed in the hope that it will be useful, | 45 | This program is distributed in the hope that it will be useful, |
46 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | GNU General Public License for more details. | 48 | GNU General Public License for more details. |
49 | 49 | ||
50 | You should have received a copy of the GNU General Public License | 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, | 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 | 52 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
53 | 53 | ||
54 | ---------------------------------------------------------------------------*/ | 54 | ---------------------------------------------------------------------------*/ |
55 | 55 | ||
56 | 56 | ||
57 | #include <stdlib.h> /* for exit() prototype */ | 57 | #include <stdlib.h> /* for exit() prototype */ |
58 | 58 | ||
59 | #include "png.h" /* libpng header; includes zlib.h and setjmp.h */ | 59 | #include "png.h" /* libpng header; includes zlib.h and setjmp.h */ |
60 | #include "writepng.h" /* typedefs, common macros, public prototypes */ | 60 | #include "writepng.h" /* typedefs, common macros, public prototypes */ |
61 | 61 | ||
62 | 62 | ||
63 | /* local prototype */ | 63 | /* local prototype */ |
64 | 64 | ||
65 | static void writepng_error_handler(png_structp png_ptr, png_const_charp msg); | 65 | static void writepng_error_handler(png_structp png_ptr, png_const_charp msg); |
66 | 66 | ||
67 | 67 | ||
68 | 68 | ||
69 | void writepng_version_info(void) | 69 | void writepng_version_info(void) |
70 | { | 70 | { |
71 | fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", | 71 | fprintf(stderr, " Compiled with libpng %s; using libpng %s.\n", |
72 | PNG_LIBPNG_VER_STRING, png_libpng_ver); | 72 | PNG_LIBPNG_VER_STRING, png_libpng_ver); |
73 | fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", | 73 | fprintf(stderr, " Compiled with zlib %s; using zlib %s.\n", |
74 | ZLIB_VERSION, zlib_version); | 74 | ZLIB_VERSION, zlib_version); |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
78 | 78 | ||
79 | 79 | ||
80 | /* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for | 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 */ | 81 | * unexpected pnmtype; note that outfile might be stdout */ |
82 | 82 | ||
83 | int writepng_init(mainprog_info *mainprog_ptr) | 83 | int writepng_init(mainprog_info *mainprog_ptr) |
84 | { | 84 | { |
85 | png_structp png_ptr; /* note: temporary variables! */ | 85 | png_structp png_ptr; /* note: temporary variables! */ |
86 | png_infop info_ptr; | 86 | png_infop info_ptr; |
87 | int color_type, interlace_type; | 87 | int color_type, interlace_type; |
88 | 88 | ||
89 | 89 | ||
90 | /* could also replace libpng warning-handler (final NULL), but no need: */ | 90 | /* could also replace libpng warning-handler (final NULL), but no need: */ |
91 | 91 | ||
92 | png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, | 92 | png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, mainprog_ptr, |
93 | writepng_error_handler, NULL); | 93 | writepng_error_handler, NULL); |
94 | if (!png_ptr) | 94 | if (!png_ptr) |
95 | return 4; /* out of memory */ | 95 | return 4; /* out of memory */ |
96 | 96 | ||
97 | info_ptr = png_create_info_struct(png_ptr); | 97 | info_ptr = png_create_info_struct(png_ptr); |
98 | if (!info_ptr) { | 98 | if (!info_ptr) { |
99 | png_destroy_write_struct(&png_ptr, NULL); | 99 | png_destroy_write_struct(&png_ptr, NULL); |
100 | return 4; /* out of memory */ | 100 | return 4; /* out of memory */ |
101 | } | 101 | } |
102 | 102 | ||
103 | 103 | ||
104 | /* setjmp() must be called in every function that calls a PNG-writing | 104 | /* setjmp() must be called in every function that calls a PNG-writing |
105 | * libpng function, unless an alternate error handler was installed-- | 105 | * libpng function, unless an alternate error handler was installed-- |
106 | * but compatible error handlers must either use longjmp() themselves | 106 | * but compatible error handlers must either use longjmp() themselves |
107 | * (as in this program) or some other method to return control to | 107 | * (as in this program) or some other method to return control to |
108 | * application code, so here we go: */ | 108 | * application code, so here we go: */ |
109 | 109 | ||
110 | if (setjmp(mainprog_ptr->jmpbuf)) { | 110 | if (setjmp(mainprog_ptr->jmpbuf)) { |
111 | png_destroy_write_struct(&png_ptr, &info_ptr); | 111 | png_destroy_write_struct(&png_ptr, &info_ptr); |
112 | return 2; | 112 | return 2; |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | /* make sure outfile is (re)opened in BINARY mode */ | 116 | /* make sure outfile is (re)opened in BINARY mode */ |
117 | 117 | ||
118 | png_init_io(png_ptr, mainprog_ptr->outfile); | 118 | png_init_io(png_ptr, mainprog_ptr->outfile); |
119 | 119 | ||
120 | 120 | ||
121 | /* set the compression levels--in general, always want to leave filtering | 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, | 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 | 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 | 124 | * is 16K or smaller (unknown here)--also the default; usually want max |
125 | * compression (NOT the default); and remaining compression flags should | 125 | * compression (NOT the default); and remaining compression flags should |
126 | * be left alone */ | 126 | * be left alone */ |
127 | 127 | ||
128 | png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); | 128 | png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); |
129 | /* | 129 | /* |
130 | >> this is default for no filtering; Z_FILTERED is default otherwise: | 130 | >> this is default for no filtering; Z_FILTERED is default otherwise: |
131 | png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY); | 131 | png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY); |
132 | >> these are all defaults: | 132 | >> these are all defaults: |
133 | png_set_compression_mem_level(png_ptr, 8); | 133 | png_set_compression_mem_level(png_ptr, 8); |
134 | png_set_compression_window_bits(png_ptr, 15); | 134 | png_set_compression_window_bits(png_ptr, 15); |
135 | png_set_compression_method(png_ptr, 8); | 135 | png_set_compression_method(png_ptr, 8); |
136 | */ | 136 | */ |
137 | 137 | ||
138 | 138 | ||
139 | /* set the image parameters appropriately */ | 139 | /* set the image parameters appropriately */ |
140 | 140 | ||
141 | if (mainprog_ptr->pnmtype == 5) | 141 | if (mainprog_ptr->pnmtype == 5) |
142 | color_type = PNG_COLOR_TYPE_GRAY; | 142 | color_type = PNG_COLOR_TYPE_GRAY; |
143 | else if (mainprog_ptr->pnmtype == 6) | 143 | else if (mainprog_ptr->pnmtype == 6) |
144 | color_type = PNG_COLOR_TYPE_RGB; | 144 | color_type = PNG_COLOR_TYPE_RGB; |
145 | else if (mainprog_ptr->pnmtype == 8) | 145 | else if (mainprog_ptr->pnmtype == 8) |
146 | color_type = PNG_COLOR_TYPE_RGB_ALPHA; | 146 | color_type = PNG_COLOR_TYPE_RGB_ALPHA; |
147 | else { | 147 | else { |
148 | png_destroy_write_struct(&png_ptr, &info_ptr); | 148 | png_destroy_write_struct(&png_ptr, &info_ptr); |
149 | return 11; | 149 | return 11; |
150 | } | 150 | } |
151 | 151 | ||
152 | interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 : | 152 | interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 : |
153 | PNG_INTERLACE_NONE; | 153 | PNG_INTERLACE_NONE; |
154 | 154 | ||
155 | png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height, | 155 | png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height, |
156 | mainprog_ptr->sample_depth, color_type, interlace_type, | 156 | mainprog_ptr->sample_depth, color_type, interlace_type, |
157 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); | 157 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
158 | 158 | ||
159 | if (mainprog_ptr->gamma > 0.0) | 159 | if (mainprog_ptr->gamma > 0.0) |
160 | png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma); | 160 | png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma); |
161 | 161 | ||
162 | if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */ | 162 | if (mainprog_ptr->have_bg) { /* we know it's RGBA, not gray+alpha */ |
163 | png_color_16 background; | 163 | png_color_16 background; |
164 | 164 | ||
165 | background.red = mainprog_ptr->bg_red; | 165 | background.red = mainprog_ptr->bg_red; |
166 | background.green = mainprog_ptr->bg_green; | 166 | background.green = mainprog_ptr->bg_green; |
167 | background.blue = mainprog_ptr->bg_blue; | 167 | background.blue = mainprog_ptr->bg_blue; |
168 | png_set_bKGD(png_ptr, info_ptr, &background); | 168 | png_set_bKGD(png_ptr, info_ptr, &background); |
169 | } | 169 | } |
170 | 170 | ||
171 | if (mainprog_ptr->have_time) { | 171 | if (mainprog_ptr->have_time) { |
172 | png_time modtime; | 172 | png_time modtime; |
173 | 173 | ||
174 | png_convert_from_time_t(&modtime, mainprog_ptr->modtime); | 174 | png_convert_from_time_t(&modtime, mainprog_ptr->modtime); |
175 | png_set_tIME(png_ptr, info_ptr, &modtime); | 175 | png_set_tIME(png_ptr, info_ptr, &modtime); |
176 | } | 176 | } |
177 | 177 | ||
178 | if (mainprog_ptr->have_text) { | 178 | if (mainprog_ptr->have_text) { |
179 | png_text text[6]; | 179 | png_text text[6]; |
180 | int num_text = 0; | 180 | int num_text = 0; |
181 | 181 | ||
182 | if (mainprog_ptr->have_text & TEXT_TITLE) { | 182 | if (mainprog_ptr->have_text & TEXT_TITLE) { |
183 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; | 183 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; |
184 | text[num_text].key = "Title"; | 184 | text[num_text].key = "Title"; |
185 | text[num_text].text = mainprog_ptr->title; | 185 | text[num_text].text = mainprog_ptr->title; |
186 | ++num_text; | 186 | ++num_text; |
187 | } | 187 | } |
188 | if (mainprog_ptr->have_text & TEXT_AUTHOR) { | 188 | if (mainprog_ptr->have_text & TEXT_AUTHOR) { |
189 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; | 189 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; |
190 | text[num_text].key = "Author"; | 190 | text[num_text].key = "Author"; |
191 | text[num_text].text = mainprog_ptr->author; | 191 | text[num_text].text = mainprog_ptr->author; |
192 | ++num_text; | 192 | ++num_text; |
193 | } | 193 | } |
194 | if (mainprog_ptr->have_text & TEXT_DESC) { | 194 | if (mainprog_ptr->have_text & TEXT_DESC) { |
195 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; | 195 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; |
196 | text[num_text].key = "Description"; | 196 | text[num_text].key = "Description"; |
197 | text[num_text].text = mainprog_ptr->desc; | 197 | text[num_text].text = mainprog_ptr->desc; |
198 | ++num_text; | 198 | ++num_text; |
199 | } | 199 | } |
200 | if (mainprog_ptr->have_text & TEXT_COPY) { | 200 | if (mainprog_ptr->have_text & TEXT_COPY) { |
201 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; | 201 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; |
202 | text[num_text].key = "Copyright"; | 202 | text[num_text].key = "Copyright"; |
203 | text[num_text].text = mainprog_ptr->copyright; | 203 | text[num_text].text = mainprog_ptr->copyright; |
204 | ++num_text; | 204 | ++num_text; |
205 | } | 205 | } |
206 | if (mainprog_ptr->have_text & TEXT_EMAIL) { | 206 | if (mainprog_ptr->have_text & TEXT_EMAIL) { |
207 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; | 207 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; |
208 | text[num_text].key = "E-mail"; | 208 | text[num_text].key = "E-mail"; |
209 | text[num_text].text = mainprog_ptr->email; | 209 | text[num_text].text = mainprog_ptr->email; |
210 | ++num_text; | 210 | ++num_text; |
211 | } | 211 | } |
212 | if (mainprog_ptr->have_text & TEXT_URL) { | 212 | if (mainprog_ptr->have_text & TEXT_URL) { |
213 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; | 213 | text[num_text].compression = PNG_TEXT_COMPRESSION_NONE; |
214 | text[num_text].key = "URL"; | 214 | text[num_text].key = "URL"; |
215 | text[num_text].text = mainprog_ptr->url; | 215 | text[num_text].text = mainprog_ptr->url; |
216 | ++num_text; | 216 | ++num_text; |
217 | } | 217 | } |
218 | png_set_text(png_ptr, info_ptr, text, num_text); | 218 | png_set_text(png_ptr, info_ptr, text, num_text); |
219 | } | 219 | } |
220 | 220 | ||
221 | 221 | ||
222 | /* write all chunks up to (but not including) first IDAT */ | 222 | /* write all chunks up to (but not including) first IDAT */ |
223 | 223 | ||
224 | png_write_info(png_ptr, info_ptr); | 224 | png_write_info(png_ptr, info_ptr); |
225 | 225 | ||
226 | 226 | ||
227 | /* if we wanted to write any more text info *after* the image data, we | 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 | 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 | 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 | 230 | * have no effect since we already called it above (only one tIME chunk |
231 | * allowed) */ | 231 | * allowed) */ |
232 | 232 | ||
233 | 233 | ||
234 | /* set up the transformations: for now, just pack low-bit-depth pixels | 234 | /* set up the transformations: for now, just pack low-bit-depth pixels |
235 | * into bytes (one, two or four pixels per byte) */ | 235 | * into bytes (one, two or four pixels per byte) */ |
236 | 236 | ||
237 | png_set_packing(png_ptr); | 237 | png_set_packing(png_ptr); |
238 | /* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */ | 238 | /* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */ |
239 | 239 | ||
240 | 240 | ||
241 | /* make sure we save our pointers for use in writepng_encode_image() */ | 241 | /* make sure we save our pointers for use in writepng_encode_image() */ |
242 | 242 | ||
243 | mainprog_ptr->png_ptr = png_ptr; | 243 | mainprog_ptr->png_ptr = png_ptr; |
244 | mainprog_ptr->info_ptr = info_ptr; | 244 | mainprog_ptr->info_ptr = info_ptr; |
245 | 245 | ||
246 | 246 | ||
247 | /* OK, that's all we need to do for now; return happy */ | 247 | /* OK, that's all we need to do for now; return happy */ |
248 | 248 | ||
249 | return 0; | 249 | return 0; |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | 253 | ||
254 | 254 | ||
255 | 255 | ||
256 | /* returns 0 for success, 2 for libpng (longjmp) problem */ | 256 | /* returns 0 for success, 2 for libpng (longjmp) problem */ |
257 | 257 | ||
258 | int writepng_encode_image(mainprog_info *mainprog_ptr) | 258 | int writepng_encode_image(mainprog_info *mainprog_ptr) |
259 | { | 259 | { |
260 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; | 260 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; |
261 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; | 261 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; |
262 | 262 | ||
263 | 263 | ||
264 | /* as always, setjmp() must be called in every function that calls a | 264 | /* as always, setjmp() must be called in every function that calls a |
265 | * PNG-writing libpng function */ | 265 | * PNG-writing libpng function */ |
266 | 266 | ||
267 | if (setjmp(mainprog_ptr->jmpbuf)) { | 267 | if (setjmp(mainprog_ptr->jmpbuf)) { |
268 | png_destroy_write_struct(&png_ptr, &info_ptr); | 268 | png_destroy_write_struct(&png_ptr, &info_ptr); |
269 | mainprog_ptr->png_ptr = NULL; | 269 | mainprog_ptr->png_ptr = NULL; |
270 | mainprog_ptr->info_ptr = NULL; | 270 | mainprog_ptr->info_ptr = NULL; |
271 | return 2; | 271 | return 2; |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | /* and now we just write the whole image; libpng takes care of interlacing | 275 | /* and now we just write the whole image; libpng takes care of interlacing |
276 | * for us */ | 276 | * for us */ |
277 | 277 | ||
278 | png_write_image(png_ptr, mainprog_ptr->row_pointers); | 278 | png_write_image(png_ptr, mainprog_ptr->row_pointers); |
279 | 279 | ||
280 | 280 | ||
281 | /* since that's it, we also close out the end of the PNG file now--if we | 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 | 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: */ | 283 | * would be info_ptr, but we optimize slightly by sending NULL pointer: */ |
284 | 284 | ||
285 | png_write_end(png_ptr, NULL); | 285 | png_write_end(png_ptr, NULL); |
286 | 286 | ||
287 | return 0; | 287 | return 0; |
288 | } | 288 | } |
289 | 289 | ||
290 | 290 | ||
291 | 291 | ||
292 | 292 | ||
293 | 293 | ||
294 | /* returns 0 if succeeds, 2 if libpng problem */ | 294 | /* returns 0 if succeeds, 2 if libpng problem */ |
295 | 295 | ||
296 | int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */ | 296 | int writepng_encode_row(mainprog_info *mainprog_ptr) /* NON-interlaced only! */ |
297 | { | 297 | { |
298 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; | 298 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; |
299 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; | 299 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; |
300 | 300 | ||
301 | 301 | ||
302 | /* as always, setjmp() must be called in every function that calls a | 302 | /* as always, setjmp() must be called in every function that calls a |
303 | * PNG-writing libpng function */ | 303 | * PNG-writing libpng function */ |
304 | 304 | ||
305 | if (setjmp(mainprog_ptr->jmpbuf)) { | 305 | if (setjmp(mainprog_ptr->jmpbuf)) { |
306 | png_destroy_write_struct(&png_ptr, &info_ptr); | 306 | png_destroy_write_struct(&png_ptr, &info_ptr); |
307 | mainprog_ptr->png_ptr = NULL; | 307 | mainprog_ptr->png_ptr = NULL; |
308 | mainprog_ptr->info_ptr = NULL; | 308 | mainprog_ptr->info_ptr = NULL; |
309 | return 2; | 309 | return 2; |
310 | } | 310 | } |
311 | 311 | ||
312 | 312 | ||
313 | /* image_data points at our one row of image data */ | 313 | /* image_data points at our one row of image data */ |
314 | 314 | ||
315 | png_write_row(png_ptr, mainprog_ptr->image_data); | 315 | png_write_row(png_ptr, mainprog_ptr->image_data); |
316 | 316 | ||
317 | return 0; | 317 | return 0; |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | 321 | ||
322 | 322 | ||
323 | 323 | ||
324 | /* returns 0 if succeeds, 2 if libpng problem */ | 324 | /* returns 0 if succeeds, 2 if libpng problem */ |
325 | 325 | ||
326 | int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */ | 326 | int writepng_encode_finish(mainprog_info *mainprog_ptr) /* NON-interlaced! */ |
327 | { | 327 | { |
328 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; | 328 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; |
329 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; | 329 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; |
330 | 330 | ||
331 | 331 | ||
332 | /* as always, setjmp() must be called in every function that calls a | 332 | /* as always, setjmp() must be called in every function that calls a |
333 | * PNG-writing libpng function */ | 333 | * PNG-writing libpng function */ |
334 | 334 | ||
335 | if (setjmp(mainprog_ptr->jmpbuf)) { | 335 | if (setjmp(mainprog_ptr->jmpbuf)) { |
336 | png_destroy_write_struct(&png_ptr, &info_ptr); | 336 | png_destroy_write_struct(&png_ptr, &info_ptr); |
337 | mainprog_ptr->png_ptr = NULL; | 337 | mainprog_ptr->png_ptr = NULL; |
338 | mainprog_ptr->info_ptr = NULL; | 338 | mainprog_ptr->info_ptr = NULL; |
339 | return 2; | 339 | return 2; |
340 | } | 340 | } |
341 | 341 | ||
342 | 342 | ||
343 | /* close out PNG file; if we had any text or time info to write after | 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: */ | 344 | * the IDATs, second argument would be info_ptr: */ |
345 | 345 | ||
346 | png_write_end(png_ptr, NULL); | 346 | png_write_end(png_ptr, NULL); |
347 | 347 | ||
348 | return 0; | 348 | return 0; |
349 | } | 349 | } |
350 | 350 | ||
351 | 351 | ||
352 | 352 | ||
353 | 353 | ||
354 | 354 | ||
355 | void writepng_cleanup(mainprog_info *mainprog_ptr) | 355 | void writepng_cleanup(mainprog_info *mainprog_ptr) |
356 | { | 356 | { |
357 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; | 357 | png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr; |
358 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; | 358 | png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr; |
359 | 359 | ||
360 | if (png_ptr && info_ptr) | 360 | if (png_ptr && info_ptr) |
361 | png_destroy_write_struct(&png_ptr, &info_ptr); | 361 | png_destroy_write_struct(&png_ptr, &info_ptr); |
362 | } | 362 | } |
363 | 363 | ||
364 | 364 | ||
365 | 365 | ||
366 | 366 | ||
367 | 367 | ||
368 | static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) | 368 | static void writepng_error_handler(png_structp png_ptr, png_const_charp msg) |
369 | { | 369 | { |
370 | mainprog_info *mainprog_ptr; | 370 | mainprog_info *mainprog_ptr; |
371 | 371 | ||
372 | /* This function, aside from the extra step of retrieving the "error | 372 | /* This function, aside from the extra step of retrieving the "error |
373 | * pointer" (below) and the fact that it exists within the application | 373 | * pointer" (below) and the fact that it exists within the application |
374 | * rather than within libpng, is essentially identical to libpng's | 374 | * rather than within libpng, is essentially identical to libpng's |
375 | * default error handler. The second point is critical: since both | 375 | * default error handler. The second point is critical: since both |
376 | * setjmp() and longjmp() are called from the same code, they are | 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, | 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) | 378 | * regardless of whether _BSD_SOURCE or anything else has (or has not) |
379 | * been defined. */ | 379 | * been defined. */ |
380 | 380 | ||
381 | fprintf(stderr, "writepng libpng error: %s\n", msg); | 381 | fprintf(stderr, "writepng libpng error: %s\n", msg); |
382 | fflush(stderr); | 382 | fflush(stderr); |
383 | 383 | ||
384 | mainprog_ptr = png_get_error_ptr(png_ptr); | 384 | mainprog_ptr = png_get_error_ptr(png_ptr); |
385 | if (mainprog_ptr == NULL) { /* we are completely hosed now */ | 385 | if (mainprog_ptr == NULL) { /* we are completely hosed now */ |
386 | fprintf(stderr, | 386 | fprintf(stderr, |
387 | "writepng severe error: jmpbuf not recoverable; terminating.\n"); | 387 | "writepng severe error: jmpbuf not recoverable; terminating.\n"); |
388 | fflush(stderr); | 388 | fflush(stderr); |
389 | exit(99); | 389 | exit(99); |
390 | } | 390 | } |
391 | 391 | ||
392 | /* Now we have our data structure we can use the information in it | 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 | 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 | 394 | * where 'setjmp' is called in this file.) This will work with other |
395 | * error handling mechanisms as well - libpng always calls png_error | 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 | 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. | 397 | * is intercepted, application code can do its own error recovery. |
398 | */ | 398 | */ |
399 | longjmp(mainprog_ptr->jmpbuf, 1); | 399 | longjmp(mainprog_ptr->jmpbuf, 1); |
400 | } | 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 index 904e4fb..78b966b 100644 --- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h +++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/writepng.h | |||
@@ -1,133 +1,133 @@ | |||
1 | /*--------------------------------------------------------------------------- | 1 | /*--------------------------------------------------------------------------- |
2 | 2 | ||
3 | wpng - simple PNG-writing program writepng.h | 3 | wpng - simple PNG-writing program writepng.h |
4 | 4 | ||
5 | --------------------------------------------------------------------------- | 5 | --------------------------------------------------------------------------- |
6 | 6 | ||
7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. | 7 | Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. |
8 | 8 | ||
9 | This software is provided "as is," without warranty of any kind, | 9 | This software is provided "as is," without warranty of any kind, |
10 | express or implied. In no event shall the author or contributors | 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 | 11 | be held liable for any damages arising in any way from the use of |
12 | this software. | 12 | this software. |
13 | 13 | ||
14 | The contents of this file are DUAL-LICENSED. You may modify and/or | 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 | 15 | redistribute this software according to the terms of one of the |
16 | following two licenses (at your option): | 16 | following two licenses (at your option): |
17 | 17 | ||
18 | 18 | ||
19 | LICENSE 1 ("BSD-like with advertising clause"): | 19 | LICENSE 1 ("BSD-like with advertising clause"): |
20 | 20 | ||
21 | Permission is granted to anyone to use this software for any purpose, | 21 | Permission is granted to anyone to use this software for any purpose, |
22 | including commercial applications, and to alter it and redistribute | 22 | including commercial applications, and to alter it and redistribute |
23 | it freely, subject to the following restrictions: | 23 | it freely, subject to the following restrictions: |
24 | 24 | ||
25 | 1. Redistributions of source code must retain the above copyright | 25 | 1. Redistributions of source code must retain the above copyright |
26 | notice, disclaimer, and this list of conditions. | 26 | notice, disclaimer, and this list of conditions. |
27 | 2. Redistributions in binary form must reproduce the above copyright | 27 | 2. Redistributions in binary form must reproduce the above copyright |
28 | notice, disclaimer, and this list of conditions in the documenta- | 28 | notice, disclaimer, and this list of conditions in the documenta- |
29 | tion and/or other materials provided with the distribution. | 29 | tion and/or other materials provided with the distribution. |
30 | 3. All advertising materials mentioning features or use of this | 30 | 3. All advertising materials mentioning features or use of this |
31 | software must display the following acknowledgment: | 31 | software must display the following acknowledgment: |
32 | 32 | ||
33 | This product includes software developed by Greg Roelofs | 33 | This product includes software developed by Greg Roelofs |
34 | and contributors for the book, "PNG: The Definitive Guide," | 34 | and contributors for the book, "PNG: The Definitive Guide," |
35 | published by O'Reilly and Associates. | 35 | published by O'Reilly and Associates. |
36 | 36 | ||
37 | 37 | ||
38 | LICENSE 2 (GNU GPL v2 or later): | 38 | LICENSE 2 (GNU GPL v2 or later): |
39 | 39 | ||
40 | This program is free software; you can redistribute it and/or modify | 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 | 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 | 42 | the Free Software Foundation; either version 2 of the License, or |
43 | (at your option) any later version. | 43 | (at your option) any later version. |
44 | 44 | ||
45 | This program is distributed in the hope that it will be useful, | 45 | This program is distributed in the hope that it will be useful, |
46 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 46 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 47 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
48 | GNU General Public License for more details. | 48 | GNU General Public License for more details. |
49 | 49 | ||
50 | You should have received a copy of the GNU General Public License | 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, | 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 | 52 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
53 | 53 | ||
54 | ---------------------------------------------------------------------------*/ | 54 | ---------------------------------------------------------------------------*/ |
55 | 55 | ||
56 | #ifndef TRUE | 56 | #ifndef TRUE |
57 | # define TRUE 1 | 57 | # define TRUE 1 |
58 | # define FALSE 0 | 58 | # define FALSE 0 |
59 | #endif | 59 | #endif |
60 | 60 | ||
61 | #ifndef MAX | 61 | #ifndef MAX |
62 | # define MAX(a,b) ((a) > (b)? (a) : (b)) | 62 | # define MAX(a,b) ((a) > (b)? (a) : (b)) |
63 | # define MIN(a,b) ((a) < (b)? (a) : (b)) | 63 | # define MIN(a,b) ((a) < (b)? (a) : (b)) |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #ifdef DEBUG | 66 | #ifdef DEBUG |
67 | # define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} | 67 | # define Trace(x) {fprintf x ; fflush(stderr); fflush(stdout);} |
68 | #else | 68 | #else |
69 | # define Trace(x) ; | 69 | # define Trace(x) ; |
70 | #endif | 70 | #endif |
71 | 71 | ||
72 | #define TEXT_TITLE 0x01 | 72 | #define TEXT_TITLE 0x01 |
73 | #define TEXT_AUTHOR 0x02 | 73 | #define TEXT_AUTHOR 0x02 |
74 | #define TEXT_DESC 0x04 | 74 | #define TEXT_DESC 0x04 |
75 | #define TEXT_COPY 0x08 | 75 | #define TEXT_COPY 0x08 |
76 | #define TEXT_EMAIL 0x10 | 76 | #define TEXT_EMAIL 0x10 |
77 | #define TEXT_URL 0x20 | 77 | #define TEXT_URL 0x20 |
78 | 78 | ||
79 | #define TEXT_TITLE_OFFSET 0 | 79 | #define TEXT_TITLE_OFFSET 0 |
80 | #define TEXT_AUTHOR_OFFSET 72 | 80 | #define TEXT_AUTHOR_OFFSET 72 |
81 | #define TEXT_COPY_OFFSET (2*72) | 81 | #define TEXT_COPY_OFFSET (2*72) |
82 | #define TEXT_EMAIL_OFFSET (3*72) | 82 | #define TEXT_EMAIL_OFFSET (3*72) |
83 | #define TEXT_URL_OFFSET (4*72) | 83 | #define TEXT_URL_OFFSET (4*72) |
84 | #define TEXT_DESC_OFFSET (5*72) | 84 | #define TEXT_DESC_OFFSET (5*72) |
85 | 85 | ||
86 | typedef unsigned char uch; | 86 | typedef unsigned char uch; |
87 | typedef unsigned short ush; | 87 | typedef unsigned short ush; |
88 | typedef unsigned long ulg; | 88 | typedef unsigned long ulg; |
89 | 89 | ||
90 | typedef struct _mainprog_info { | 90 | typedef struct _mainprog_info { |
91 | double gamma; | 91 | double gamma; |
92 | long width; | 92 | long width; |
93 | long height; | 93 | long height; |
94 | time_t modtime; | 94 | time_t modtime; |
95 | FILE *infile; | 95 | FILE *infile; |
96 | FILE *outfile; | 96 | FILE *outfile; |
97 | void *png_ptr; | 97 | void *png_ptr; |
98 | void *info_ptr; | 98 | void *info_ptr; |
99 | uch *image_data; | 99 | uch *image_data; |
100 | uch **row_pointers; | 100 | uch **row_pointers; |
101 | char *title; | 101 | char *title; |
102 | char *author; | 102 | char *author; |
103 | char *desc; | 103 | char *desc; |
104 | char *copyright; | 104 | char *copyright; |
105 | char *email; | 105 | char *email; |
106 | char *url; | 106 | char *url; |
107 | int filter; /* command-line-filter flag, not PNG row filter! */ | 107 | int filter; /* command-line-filter flag, not PNG row filter! */ |
108 | int pnmtype; | 108 | int pnmtype; |
109 | int sample_depth; | 109 | int sample_depth; |
110 | int interlaced; | 110 | int interlaced; |
111 | int have_bg; | 111 | int have_bg; |
112 | int have_time; | 112 | int have_time; |
113 | int have_text; | 113 | int have_text; |
114 | jmp_buf jmpbuf; | 114 | jmp_buf jmpbuf; |
115 | uch bg_red; | 115 | uch bg_red; |
116 | uch bg_green; | 116 | uch bg_green; |
117 | uch bg_blue; | 117 | uch bg_blue; |
118 | } mainprog_info; | 118 | } mainprog_info; |
119 | 119 | ||
120 | 120 | ||
121 | /* prototypes for public functions in writepng.c */ | 121 | /* prototypes for public functions in writepng.c */ |
122 | 122 | ||
123 | void writepng_version_info(void); | 123 | void writepng_version_info(void); |
124 | 124 | ||
125 | int writepng_init(mainprog_info *mainprog_ptr); | 125 | int writepng_init(mainprog_info *mainprog_ptr); |
126 | 126 | ||
127 | int writepng_encode_image(mainprog_info *mainprog_ptr); | 127 | int writepng_encode_image(mainprog_info *mainprog_ptr); |
128 | 128 | ||
129 | int writepng_encode_row(mainprog_info *mainprog_ptr); | 129 | int writepng_encode_row(mainprog_info *mainprog_ptr); |
130 | 130 | ||
131 | int writepng_encode_finish(mainprog_info *mainprog_ptr); | 131 | int writepng_encode_finish(mainprog_info *mainprog_ptr); |
132 | 132 | ||
133 | void writepng_cleanup(mainprog_info *mainprog_ptr); | 133 | void writepng_cleanup(mainprog_info *mainprog_ptr); |