eqemu
changeset 10:819c7ebb1bec
added libimago to avoid the external dependency
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Jul 2014 05:07:40 +0300 |
parents | fca1f126d23b |
children | 2b559dc24c7b |
files | Makefile README libs/libimago/COPYING libs/libimago/COPYING.LESSER libs/libimago/Makefile.in libs/libimago/README libs/libimago/build/vcconfig.bat libs/libimago/configure libs/libimago/imago-vs2012.sln libs/libimago/imago-vs2012.vcxproj libs/libimago/imago-vs2012.vcxproj.filters libs/libimago/imago.sln libs/libimago/imago.vcproj libs/libimago/install.bat libs/libimago/src/conv.c libs/libimago/src/file_jpeg.c libs/libimago/src/file_png.c libs/libimago/src/file_ppm.c libs/libimago/src/file_rgbe.c libs/libimago/src/ftype_module.c libs/libimago/src/ftype_module.h libs/libimago/src/imago2.c libs/libimago/src/imago2.h libs/libimago/src/imago_gl.c libs/libimago/test/Makefile libs/libimago/test/test.c |
diffstat | 26 files changed, 4070 insertions(+), 5 deletions(-) [+] |
line diff
1.1 --- a/Makefile Fri Jul 18 04:47:27 2014 +0300 1.2 +++ b/Makefile Fri Jul 18 05:07:40 2014 +0300 1.3 @@ -1,13 +1,16 @@ 1.4 src = $(wildcard src/*.cc) 1.5 obj = $(src:.cc=.o) 1.6 dep = $(obj:.o=.d) 1.7 -bin = eqdummy 1.8 +bin = eqemu 1.9 1.10 -CFLAGS = -pedantic -Wall -g 1.11 +libimago_path = libs/libimago 1.12 +libimago = $(libimago_path)/libimago.a 1.13 + 1.14 +CFLAGS = -pedantic -Wall -g -I$(libimago_path)/src 1.15 CXXFLAGS = $(CFLAGS) 1.16 -LDFLAGS = -lGL -lGLU -lGLEW -lX11 -lm -lpthread -limago 1.17 +LDFLAGS = -lGL -lGLU -lGLEW -lX11 -lm -lpthread -L$(libimago_path) -limago -lpng -ljpeg -lz 1.18 1.19 -$(bin): $(obj) 1.20 +$(bin): $(obj) $(libimago) 1.21 $(CXX) -o $@ $(obj) $(LDFLAGS) 1.22 1.23 -include $(dep) 1.24 @@ -15,6 +18,15 @@ 1.25 %.d: %.cc 1.26 @$(CPP) $< $(CXXFLAGS) -MM -MT $(@:.d=.o) >$@ 1.27 1.28 +.PHONY: $(libimago) 1.29 +$(libimago): 1.30 + cd $(libimago_path) && ./configure --disable-debug --enable-opt 1.31 + $(MAKE) -C $(libimago_path) 1.32 + 1.33 .PHONY: clean 1.34 clean: 1.35 rm -f $(obj) $(bin) 1.36 + 1.37 +.PHONY: clean-libs 1.38 +clean-libs: 1.39 + $(MAKE) -C $(libimago_path) clean
2.1 --- a/README Fri Jul 18 04:47:27 2014 +0300 2.2 +++ b/README Fri Jul 18 05:07:40 2014 +0300 2.3 @@ -1,4 +1,5 @@ 2.4 1. Create 2 pseudoterminals: socat -d -d PTY PTY 2.5 -2. start ./equeue_dummy /dev/pts/one 2.6 +2. start ./eqemu /dev/pts/one 2.7 3. set the php script to use /dev/pts/theother (make sure apache has permission 2.8 to rw it). 2.9 + Try minicom -D /dev/pts/theother with disabled flow control to test it.
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/libs/libimago/COPYING Fri Jul 18 05:07:40 2014 +0300 3.3 @@ -0,0 +1,674 @@ 3.4 + GNU GENERAL PUBLIC LICENSE 3.5 + Version 3, 29 June 2007 3.6 + 3.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 3.8 + Everyone is permitted to copy and distribute verbatim copies 3.9 + of this license document, but changing it is not allowed. 3.10 + 3.11 + Preamble 3.12 + 3.13 + The GNU General Public License is a free, copyleft license for 3.14 +software and other kinds of works. 3.15 + 3.16 + The licenses for most software and other practical works are designed 3.17 +to take away your freedom to share and change the works. By contrast, 3.18 +the GNU General Public License is intended to guarantee your freedom to 3.19 +share and change all versions of a program--to make sure it remains free 3.20 +software for all its users. We, the Free Software Foundation, use the 3.21 +GNU General Public License for most of our software; it applies also to 3.22 +any other work released this way by its authors. You can apply it to 3.23 +your programs, too. 3.24 + 3.25 + When we speak of free software, we are referring to freedom, not 3.26 +price. Our General Public Licenses are designed to make sure that you 3.27 +have the freedom to distribute copies of free software (and charge for 3.28 +them if you wish), that you receive source code or can get it if you 3.29 +want it, that you can change the software or use pieces of it in new 3.30 +free programs, and that you know you can do these things. 3.31 + 3.32 + To protect your rights, we need to prevent others from denying you 3.33 +these rights or asking you to surrender the rights. Therefore, you have 3.34 +certain responsibilities if you distribute copies of the software, or if 3.35 +you modify it: responsibilities to respect the freedom of others. 3.36 + 3.37 + For example, if you distribute copies of such a program, whether 3.38 +gratis or for a fee, you must pass on to the recipients the same 3.39 +freedoms that you received. You must make sure that they, too, receive 3.40 +or can get the source code. And you must show them these terms so they 3.41 +know their rights. 3.42 + 3.43 + Developers that use the GNU GPL protect your rights with two steps: 3.44 +(1) assert copyright on the software, and (2) offer you this License 3.45 +giving you legal permission to copy, distribute and/or modify it. 3.46 + 3.47 + For the developers' and authors' protection, the GPL clearly explains 3.48 +that there is no warranty for this free software. For both users' and 3.49 +authors' sake, the GPL requires that modified versions be marked as 3.50 +changed, so that their problems will not be attributed erroneously to 3.51 +authors of previous versions. 3.52 + 3.53 + Some devices are designed to deny users access to install or run 3.54 +modified versions of the software inside them, although the manufacturer 3.55 +can do so. This is fundamentally incompatible with the aim of 3.56 +protecting users' freedom to change the software. The systematic 3.57 +pattern of such abuse occurs in the area of products for individuals to 3.58 +use, which is precisely where it is most unacceptable. Therefore, we 3.59 +have designed this version of the GPL to prohibit the practice for those 3.60 +products. If such problems arise substantially in other domains, we 3.61 +stand ready to extend this provision to those domains in future versions 3.62 +of the GPL, as needed to protect the freedom of users. 3.63 + 3.64 + Finally, every program is threatened constantly by software patents. 3.65 +States should not allow patents to restrict development and use of 3.66 +software on general-purpose computers, but in those that do, we wish to 3.67 +avoid the special danger that patents applied to a free program could 3.68 +make it effectively proprietary. To prevent this, the GPL assures that 3.69 +patents cannot be used to render the program non-free. 3.70 + 3.71 + The precise terms and conditions for copying, distribution and 3.72 +modification follow. 3.73 + 3.74 + TERMS AND CONDITIONS 3.75 + 3.76 + 0. Definitions. 3.77 + 3.78 + "This License" refers to version 3 of the GNU General Public License. 3.79 + 3.80 + "Copyright" also means copyright-like laws that apply to other kinds of 3.81 +works, such as semiconductor masks. 3.82 + 3.83 + "The Program" refers to any copyrightable work licensed under this 3.84 +License. Each licensee is addressed as "you". "Licensees" and 3.85 +"recipients" may be individuals or organizations. 3.86 + 3.87 + To "modify" a work means to copy from or adapt all or part of the work 3.88 +in a fashion requiring copyright permission, other than the making of an 3.89 +exact copy. The resulting work is called a "modified version" of the 3.90 +earlier work or a work "based on" the earlier work. 3.91 + 3.92 + A "covered work" means either the unmodified Program or a work based 3.93 +on the Program. 3.94 + 3.95 + To "propagate" a work means to do anything with it that, without 3.96 +permission, would make you directly or secondarily liable for 3.97 +infringement under applicable copyright law, except executing it on a 3.98 +computer or modifying a private copy. Propagation includes copying, 3.99 +distribution (with or without modification), making available to the 3.100 +public, and in some countries other activities as well. 3.101 + 3.102 + To "convey" a work means any kind of propagation that enables other 3.103 +parties to make or receive copies. Mere interaction with a user through 3.104 +a computer network, with no transfer of a copy, is not conveying. 3.105 + 3.106 + An interactive user interface displays "Appropriate Legal Notices" 3.107 +to the extent that it includes a convenient and prominently visible 3.108 +feature that (1) displays an appropriate copyright notice, and (2) 3.109 +tells the user that there is no warranty for the work (except to the 3.110 +extent that warranties are provided), that licensees may convey the 3.111 +work under this License, and how to view a copy of this License. If 3.112 +the interface presents a list of user commands or options, such as a 3.113 +menu, a prominent item in the list meets this criterion. 3.114 + 3.115 + 1. Source Code. 3.116 + 3.117 + The "source code" for a work means the preferred form of the work 3.118 +for making modifications to it. "Object code" means any non-source 3.119 +form of a work. 3.120 + 3.121 + A "Standard Interface" means an interface that either is an official 3.122 +standard defined by a recognized standards body, or, in the case of 3.123 +interfaces specified for a particular programming language, one that 3.124 +is widely used among developers working in that language. 3.125 + 3.126 + The "System Libraries" of an executable work include anything, other 3.127 +than the work as a whole, that (a) is included in the normal form of 3.128 +packaging a Major Component, but which is not part of that Major 3.129 +Component, and (b) serves only to enable use of the work with that 3.130 +Major Component, or to implement a Standard Interface for which an 3.131 +implementation is available to the public in source code form. A 3.132 +"Major Component", in this context, means a major essential component 3.133 +(kernel, window system, and so on) of the specific operating system 3.134 +(if any) on which the executable work runs, or a compiler used to 3.135 +produce the work, or an object code interpreter used to run it. 3.136 + 3.137 + The "Corresponding Source" for a work in object code form means all 3.138 +the source code needed to generate, install, and (for an executable 3.139 +work) run the object code and to modify the work, including scripts to 3.140 +control those activities. However, it does not include the work's 3.141 +System Libraries, or general-purpose tools or generally available free 3.142 +programs which are used unmodified in performing those activities but 3.143 +which are not part of the work. For example, Corresponding Source 3.144 +includes interface definition files associated with source files for 3.145 +the work, and the source code for shared libraries and dynamically 3.146 +linked subprograms that the work is specifically designed to require, 3.147 +such as by intimate data communication or control flow between those 3.148 +subprograms and other parts of the work. 3.149 + 3.150 + The Corresponding Source need not include anything that users 3.151 +can regenerate automatically from other parts of the Corresponding 3.152 +Source. 3.153 + 3.154 + The Corresponding Source for a work in source code form is that 3.155 +same work. 3.156 + 3.157 + 2. Basic Permissions. 3.158 + 3.159 + All rights granted under this License are granted for the term of 3.160 +copyright on the Program, and are irrevocable provided the stated 3.161 +conditions are met. This License explicitly affirms your unlimited 3.162 +permission to run the unmodified Program. The output from running a 3.163 +covered work is covered by this License only if the output, given its 3.164 +content, constitutes a covered work. This License acknowledges your 3.165 +rights of fair use or other equivalent, as provided by copyright law. 3.166 + 3.167 + You may make, run and propagate covered works that you do not 3.168 +convey, without conditions so long as your license otherwise remains 3.169 +in force. You may convey covered works to others for the sole purpose 3.170 +of having them make modifications exclusively for you, or provide you 3.171 +with facilities for running those works, provided that you comply with 3.172 +the terms of this License in conveying all material for which you do 3.173 +not control copyright. Those thus making or running the covered works 3.174 +for you must do so exclusively on your behalf, under your direction 3.175 +and control, on terms that prohibit them from making any copies of 3.176 +your copyrighted material outside their relationship with you. 3.177 + 3.178 + Conveying under any other circumstances is permitted solely under 3.179 +the conditions stated below. Sublicensing is not allowed; section 10 3.180 +makes it unnecessary. 3.181 + 3.182 + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 3.183 + 3.184 + No covered work shall be deemed part of an effective technological 3.185 +measure under any applicable law fulfilling obligations under article 3.186 +11 of the WIPO copyright treaty adopted on 20 December 1996, or 3.187 +similar laws prohibiting or restricting circumvention of such 3.188 +measures. 3.189 + 3.190 + When you convey a covered work, you waive any legal power to forbid 3.191 +circumvention of technological measures to the extent such circumvention 3.192 +is effected by exercising rights under this License with respect to 3.193 +the covered work, and you disclaim any intention to limit operation or 3.194 +modification of the work as a means of enforcing, against the work's 3.195 +users, your or third parties' legal rights to forbid circumvention of 3.196 +technological measures. 3.197 + 3.198 + 4. Conveying Verbatim Copies. 3.199 + 3.200 + You may convey verbatim copies of the Program's source code as you 3.201 +receive it, in any medium, provided that you conspicuously and 3.202 +appropriately publish on each copy an appropriate copyright notice; 3.203 +keep intact all notices stating that this License and any 3.204 +non-permissive terms added in accord with section 7 apply to the code; 3.205 +keep intact all notices of the absence of any warranty; and give all 3.206 +recipients a copy of this License along with the Program. 3.207 + 3.208 + You may charge any price or no price for each copy that you convey, 3.209 +and you may offer support or warranty protection for a fee. 3.210 + 3.211 + 5. Conveying Modified Source Versions. 3.212 + 3.213 + You may convey a work based on the Program, or the modifications to 3.214 +produce it from the Program, in the form of source code under the 3.215 +terms of section 4, provided that you also meet all of these conditions: 3.216 + 3.217 + a) The work must carry prominent notices stating that you modified 3.218 + it, and giving a relevant date. 3.219 + 3.220 + b) The work must carry prominent notices stating that it is 3.221 + released under this License and any conditions added under section 3.222 + 7. This requirement modifies the requirement in section 4 to 3.223 + "keep intact all notices". 3.224 + 3.225 + c) You must license the entire work, as a whole, under this 3.226 + License to anyone who comes into possession of a copy. This 3.227 + License will therefore apply, along with any applicable section 7 3.228 + additional terms, to the whole of the work, and all its parts, 3.229 + regardless of how they are packaged. This License gives no 3.230 + permission to license the work in any other way, but it does not 3.231 + invalidate such permission if you have separately received it. 3.232 + 3.233 + d) If the work has interactive user interfaces, each must display 3.234 + Appropriate Legal Notices; however, if the Program has interactive 3.235 + interfaces that do not display Appropriate Legal Notices, your 3.236 + work need not make them do so. 3.237 + 3.238 + A compilation of a covered work with other separate and independent 3.239 +works, which are not by their nature extensions of the covered work, 3.240 +and which are not combined with it such as to form a larger program, 3.241 +in or on a volume of a storage or distribution medium, is called an 3.242 +"aggregate" if the compilation and its resulting copyright are not 3.243 +used to limit the access or legal rights of the compilation's users 3.244 +beyond what the individual works permit. Inclusion of a covered work 3.245 +in an aggregate does not cause this License to apply to the other 3.246 +parts of the aggregate. 3.247 + 3.248 + 6. Conveying Non-Source Forms. 3.249 + 3.250 + You may convey a covered work in object code form under the terms 3.251 +of sections 4 and 5, provided that you also convey the 3.252 +machine-readable Corresponding Source under the terms of this License, 3.253 +in one of these ways: 3.254 + 3.255 + a) Convey the object code in, or embodied in, a physical product 3.256 + (including a physical distribution medium), accompanied by the 3.257 + Corresponding Source fixed on a durable physical medium 3.258 + customarily used for software interchange. 3.259 + 3.260 + b) Convey the object code in, or embodied in, a physical product 3.261 + (including a physical distribution medium), accompanied by a 3.262 + written offer, valid for at least three years and valid for as 3.263 + long as you offer spare parts or customer support for that product 3.264 + model, to give anyone who possesses the object code either (1) a 3.265 + copy of the Corresponding Source for all the software in the 3.266 + product that is covered by this License, on a durable physical 3.267 + medium customarily used for software interchange, for a price no 3.268 + more than your reasonable cost of physically performing this 3.269 + conveying of source, or (2) access to copy the 3.270 + Corresponding Source from a network server at no charge. 3.271 + 3.272 + c) Convey individual copies of the object code with a copy of the 3.273 + written offer to provide the Corresponding Source. This 3.274 + alternative is allowed only occasionally and noncommercially, and 3.275 + only if you received the object code with such an offer, in accord 3.276 + with subsection 6b. 3.277 + 3.278 + d) Convey the object code by offering access from a designated 3.279 + place (gratis or for a charge), and offer equivalent access to the 3.280 + Corresponding Source in the same way through the same place at no 3.281 + further charge. You need not require recipients to copy the 3.282 + Corresponding Source along with the object code. If the place to 3.283 + copy the object code is a network server, the Corresponding Source 3.284 + may be on a different server (operated by you or a third party) 3.285 + that supports equivalent copying facilities, provided you maintain 3.286 + clear directions next to the object code saying where to find the 3.287 + Corresponding Source. Regardless of what server hosts the 3.288 + Corresponding Source, you remain obligated to ensure that it is 3.289 + available for as long as needed to satisfy these requirements. 3.290 + 3.291 + e) Convey the object code using peer-to-peer transmission, provided 3.292 + you inform other peers where the object code and Corresponding 3.293 + Source of the work are being offered to the general public at no 3.294 + charge under subsection 6d. 3.295 + 3.296 + A separable portion of the object code, whose source code is excluded 3.297 +from the Corresponding Source as a System Library, need not be 3.298 +included in conveying the object code work. 3.299 + 3.300 + A "User Product" is either (1) a "consumer product", which means any 3.301 +tangible personal property which is normally used for personal, family, 3.302 +or household purposes, or (2) anything designed or sold for incorporation 3.303 +into a dwelling. In determining whether a product is a consumer product, 3.304 +doubtful cases shall be resolved in favor of coverage. For a particular 3.305 +product received by a particular user, "normally used" refers to a 3.306 +typical or common use of that class of product, regardless of the status 3.307 +of the particular user or of the way in which the particular user 3.308 +actually uses, or expects or is expected to use, the product. A product 3.309 +is a consumer product regardless of whether the product has substantial 3.310 +commercial, industrial or non-consumer uses, unless such uses represent 3.311 +the only significant mode of use of the product. 3.312 + 3.313 + "Installation Information" for a User Product means any methods, 3.314 +procedures, authorization keys, or other information required to install 3.315 +and execute modified versions of a covered work in that User Product from 3.316 +a modified version of its Corresponding Source. The information must 3.317 +suffice to ensure that the continued functioning of the modified object 3.318 +code is in no case prevented or interfered with solely because 3.319 +modification has been made. 3.320 + 3.321 + If you convey an object code work under this section in, or with, or 3.322 +specifically for use in, a User Product, and the conveying occurs as 3.323 +part of a transaction in which the right of possession and use of the 3.324 +User Product is transferred to the recipient in perpetuity or for a 3.325 +fixed term (regardless of how the transaction is characterized), the 3.326 +Corresponding Source conveyed under this section must be accompanied 3.327 +by the Installation Information. But this requirement does not apply 3.328 +if neither you nor any third party retains the ability to install 3.329 +modified object code on the User Product (for example, the work has 3.330 +been installed in ROM). 3.331 + 3.332 + The requirement to provide Installation Information does not include a 3.333 +requirement to continue to provide support service, warranty, or updates 3.334 +for a work that has been modified or installed by the recipient, or for 3.335 +the User Product in which it has been modified or installed. Access to a 3.336 +network may be denied when the modification itself materially and 3.337 +adversely affects the operation of the network or violates the rules and 3.338 +protocols for communication across the network. 3.339 + 3.340 + Corresponding Source conveyed, and Installation Information provided, 3.341 +in accord with this section must be in a format that is publicly 3.342 +documented (and with an implementation available to the public in 3.343 +source code form), and must require no special password or key for 3.344 +unpacking, reading or copying. 3.345 + 3.346 + 7. Additional Terms. 3.347 + 3.348 + "Additional permissions" are terms that supplement the terms of this 3.349 +License by making exceptions from one or more of its conditions. 3.350 +Additional permissions that are applicable to the entire Program shall 3.351 +be treated as though they were included in this License, to the extent 3.352 +that they are valid under applicable law. If additional permissions 3.353 +apply only to part of the Program, that part may be used separately 3.354 +under those permissions, but the entire Program remains governed by 3.355 +this License without regard to the additional permissions. 3.356 + 3.357 + When you convey a copy of a covered work, you may at your option 3.358 +remove any additional permissions from that copy, or from any part of 3.359 +it. (Additional permissions may be written to require their own 3.360 +removal in certain cases when you modify the work.) You may place 3.361 +additional permissions on material, added by you to a covered work, 3.362 +for which you have or can give appropriate copyright permission. 3.363 + 3.364 + Notwithstanding any other provision of this License, for material you 3.365 +add to a covered work, you may (if authorized by the copyright holders of 3.366 +that material) supplement the terms of this License with terms: 3.367 + 3.368 + a) Disclaiming warranty or limiting liability differently from the 3.369 + terms of sections 15 and 16 of this License; or 3.370 + 3.371 + b) Requiring preservation of specified reasonable legal notices or 3.372 + author attributions in that material or in the Appropriate Legal 3.373 + Notices displayed by works containing it; or 3.374 + 3.375 + c) Prohibiting misrepresentation of the origin of that material, or 3.376 + requiring that modified versions of such material be marked in 3.377 + reasonable ways as different from the original version; or 3.378 + 3.379 + d) Limiting the use for publicity purposes of names of licensors or 3.380 + authors of the material; or 3.381 + 3.382 + e) Declining to grant rights under trademark law for use of some 3.383 + trade names, trademarks, or service marks; or 3.384 + 3.385 + f) Requiring indemnification of licensors and authors of that 3.386 + material by anyone who conveys the material (or modified versions of 3.387 + it) with contractual assumptions of liability to the recipient, for 3.388 + any liability that these contractual assumptions directly impose on 3.389 + those licensors and authors. 3.390 + 3.391 + All other non-permissive additional terms are considered "further 3.392 +restrictions" within the meaning of section 10. If the Program as you 3.393 +received it, or any part of it, contains a notice stating that it is 3.394 +governed by this License along with a term that is a further 3.395 +restriction, you may remove that term. If a license document contains 3.396 +a further restriction but permits relicensing or conveying under this 3.397 +License, you may add to a covered work material governed by the terms 3.398 +of that license document, provided that the further restriction does 3.399 +not survive such relicensing or conveying. 3.400 + 3.401 + If you add terms to a covered work in accord with this section, you 3.402 +must place, in the relevant source files, a statement of the 3.403 +additional terms that apply to those files, or a notice indicating 3.404 +where to find the applicable terms. 3.405 + 3.406 + Additional terms, permissive or non-permissive, may be stated in the 3.407 +form of a separately written license, or stated as exceptions; 3.408 +the above requirements apply either way. 3.409 + 3.410 + 8. Termination. 3.411 + 3.412 + You may not propagate or modify a covered work except as expressly 3.413 +provided under this License. Any attempt otherwise to propagate or 3.414 +modify it is void, and will automatically terminate your rights under 3.415 +this License (including any patent licenses granted under the third 3.416 +paragraph of section 11). 3.417 + 3.418 + However, if you cease all violation of this License, then your 3.419 +license from a particular copyright holder is reinstated (a) 3.420 +provisionally, unless and until the copyright holder explicitly and 3.421 +finally terminates your license, and (b) permanently, if the copyright 3.422 +holder fails to notify you of the violation by some reasonable means 3.423 +prior to 60 days after the cessation. 3.424 + 3.425 + Moreover, your license from a particular copyright holder is 3.426 +reinstated permanently if the copyright holder notifies you of the 3.427 +violation by some reasonable means, this is the first time you have 3.428 +received notice of violation of this License (for any work) from that 3.429 +copyright holder, and you cure the violation prior to 30 days after 3.430 +your receipt of the notice. 3.431 + 3.432 + Termination of your rights under this section does not terminate the 3.433 +licenses of parties who have received copies or rights from you under 3.434 +this License. If your rights have been terminated and not permanently 3.435 +reinstated, you do not qualify to receive new licenses for the same 3.436 +material under section 10. 3.437 + 3.438 + 9. Acceptance Not Required for Having Copies. 3.439 + 3.440 + You are not required to accept this License in order to receive or 3.441 +run a copy of the Program. Ancillary propagation of a covered work 3.442 +occurring solely as a consequence of using peer-to-peer transmission 3.443 +to receive a copy likewise does not require acceptance. However, 3.444 +nothing other than this License grants you permission to propagate or 3.445 +modify any covered work. These actions infringe copyright if you do 3.446 +not accept this License. Therefore, by modifying or propagating a 3.447 +covered work, you indicate your acceptance of this License to do so. 3.448 + 3.449 + 10. Automatic Licensing of Downstream Recipients. 3.450 + 3.451 + Each time you convey a covered work, the recipient automatically 3.452 +receives a license from the original licensors, to run, modify and 3.453 +propagate that work, subject to this License. You are not responsible 3.454 +for enforcing compliance by third parties with this License. 3.455 + 3.456 + An "entity transaction" is a transaction transferring control of an 3.457 +organization, or substantially all assets of one, or subdividing an 3.458 +organization, or merging organizations. If propagation of a covered 3.459 +work results from an entity transaction, each party to that 3.460 +transaction who receives a copy of the work also receives whatever 3.461 +licenses to the work the party's predecessor in interest had or could 3.462 +give under the previous paragraph, plus a right to possession of the 3.463 +Corresponding Source of the work from the predecessor in interest, if 3.464 +the predecessor has it or can get it with reasonable efforts. 3.465 + 3.466 + You may not impose any further restrictions on the exercise of the 3.467 +rights granted or affirmed under this License. For example, you may 3.468 +not impose a license fee, royalty, or other charge for exercise of 3.469 +rights granted under this License, and you may not initiate litigation 3.470 +(including a cross-claim or counterclaim in a lawsuit) alleging that 3.471 +any patent claim is infringed by making, using, selling, offering for 3.472 +sale, or importing the Program or any portion of it. 3.473 + 3.474 + 11. Patents. 3.475 + 3.476 + A "contributor" is a copyright holder who authorizes use under this 3.477 +License of the Program or a work on which the Program is based. The 3.478 +work thus licensed is called the contributor's "contributor version". 3.479 + 3.480 + A contributor's "essential patent claims" are all patent claims 3.481 +owned or controlled by the contributor, whether already acquired or 3.482 +hereafter acquired, that would be infringed by some manner, permitted 3.483 +by this License, of making, using, or selling its contributor version, 3.484 +but do not include claims that would be infringed only as a 3.485 +consequence of further modification of the contributor version. For 3.486 +purposes of this definition, "control" includes the right to grant 3.487 +patent sublicenses in a manner consistent with the requirements of 3.488 +this License. 3.489 + 3.490 + Each contributor grants you a non-exclusive, worldwide, royalty-free 3.491 +patent license under the contributor's essential patent claims, to 3.492 +make, use, sell, offer for sale, import and otherwise run, modify and 3.493 +propagate the contents of its contributor version. 3.494 + 3.495 + In the following three paragraphs, a "patent license" is any express 3.496 +agreement or commitment, however denominated, not to enforce a patent 3.497 +(such as an express permission to practice a patent or covenant not to 3.498 +sue for patent infringement). To "grant" such a patent license to a 3.499 +party means to make such an agreement or commitment not to enforce a 3.500 +patent against the party. 3.501 + 3.502 + If you convey a covered work, knowingly relying on a patent license, 3.503 +and the Corresponding Source of the work is not available for anyone 3.504 +to copy, free of charge and under the terms of this License, through a 3.505 +publicly available network server or other readily accessible means, 3.506 +then you must either (1) cause the Corresponding Source to be so 3.507 +available, or (2) arrange to deprive yourself of the benefit of the 3.508 +patent license for this particular work, or (3) arrange, in a manner 3.509 +consistent with the requirements of this License, to extend the patent 3.510 +license to downstream recipients. "Knowingly relying" means you have 3.511 +actual knowledge that, but for the patent license, your conveying the 3.512 +covered work in a country, or your recipient's use of the covered work 3.513 +in a country, would infringe one or more identifiable patents in that 3.514 +country that you have reason to believe are valid. 3.515 + 3.516 + If, pursuant to or in connection with a single transaction or 3.517 +arrangement, you convey, or propagate by procuring conveyance of, a 3.518 +covered work, and grant a patent license to some of the parties 3.519 +receiving the covered work authorizing them to use, propagate, modify 3.520 +or convey a specific copy of the covered work, then the patent license 3.521 +you grant is automatically extended to all recipients of the covered 3.522 +work and works based on it. 3.523 + 3.524 + A patent license is "discriminatory" if it does not include within 3.525 +the scope of its coverage, prohibits the exercise of, or is 3.526 +conditioned on the non-exercise of one or more of the rights that are 3.527 +specifically granted under this License. You may not convey a covered 3.528 +work if you are a party to an arrangement with a third party that is 3.529 +in the business of distributing software, under which you make payment 3.530 +to the third party based on the extent of your activity of conveying 3.531 +the work, and under which the third party grants, to any of the 3.532 +parties who would receive the covered work from you, a discriminatory 3.533 +patent license (a) in connection with copies of the covered work 3.534 +conveyed by you (or copies made from those copies), or (b) primarily 3.535 +for and in connection with specific products or compilations that 3.536 +contain the covered work, unless you entered into that arrangement, 3.537 +or that patent license was granted, prior to 28 March 2007. 3.538 + 3.539 + Nothing in this License shall be construed as excluding or limiting 3.540 +any implied license or other defenses to infringement that may 3.541 +otherwise be available to you under applicable patent law. 3.542 + 3.543 + 12. No Surrender of Others' Freedom. 3.544 + 3.545 + If conditions are imposed on you (whether by court order, agreement or 3.546 +otherwise) that contradict the conditions of this License, they do not 3.547 +excuse you from the conditions of this License. If you cannot convey a 3.548 +covered work so as to satisfy simultaneously your obligations under this 3.549 +License and any other pertinent obligations, then as a consequence you may 3.550 +not convey it at all. For example, if you agree to terms that obligate you 3.551 +to collect a royalty for further conveying from those to whom you convey 3.552 +the Program, the only way you could satisfy both those terms and this 3.553 +License would be to refrain entirely from conveying the Program. 3.554 + 3.555 + 13. Use with the GNU Affero General Public License. 3.556 + 3.557 + Notwithstanding any other provision of this License, you have 3.558 +permission to link or combine any covered work with a work licensed 3.559 +under version 3 of the GNU Affero General Public License into a single 3.560 +combined work, and to convey the resulting work. The terms of this 3.561 +License will continue to apply to the part which is the covered work, 3.562 +but the special requirements of the GNU Affero General Public License, 3.563 +section 13, concerning interaction through a network will apply to the 3.564 +combination as such. 3.565 + 3.566 + 14. Revised Versions of this License. 3.567 + 3.568 + The Free Software Foundation may publish revised and/or new versions of 3.569 +the GNU General Public License from time to time. Such new versions will 3.570 +be similar in spirit to the present version, but may differ in detail to 3.571 +address new problems or concerns. 3.572 + 3.573 + Each version is given a distinguishing version number. If the 3.574 +Program specifies that a certain numbered version of the GNU General 3.575 +Public License "or any later version" applies to it, you have the 3.576 +option of following the terms and conditions either of that numbered 3.577 +version or of any later version published by the Free Software 3.578 +Foundation. If the Program does not specify a version number of the 3.579 +GNU General Public License, you may choose any version ever published 3.580 +by the Free Software Foundation. 3.581 + 3.582 + If the Program specifies that a proxy can decide which future 3.583 +versions of the GNU General Public License can be used, that proxy's 3.584 +public statement of acceptance of a version permanently authorizes you 3.585 +to choose that version for the Program. 3.586 + 3.587 + Later license versions may give you additional or different 3.588 +permissions. However, no additional obligations are imposed on any 3.589 +author or copyright holder as a result of your choosing to follow a 3.590 +later version. 3.591 + 3.592 + 15. Disclaimer of Warranty. 3.593 + 3.594 + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 3.595 +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 3.596 +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 3.597 +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 3.598 +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 3.599 +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 3.600 +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 3.601 +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 3.602 + 3.603 + 16. Limitation of Liability. 3.604 + 3.605 + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 3.606 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 3.607 +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 3.608 +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 3.609 +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 3.610 +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 3.611 +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 3.612 +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 3.613 +SUCH DAMAGES. 3.614 + 3.615 + 17. Interpretation of Sections 15 and 16. 3.616 + 3.617 + If the disclaimer of warranty and limitation of liability provided 3.618 +above cannot be given local legal effect according to their terms, 3.619 +reviewing courts shall apply local law that most closely approximates 3.620 +an absolute waiver of all civil liability in connection with the 3.621 +Program, unless a warranty or assumption of liability accompanies a 3.622 +copy of the Program in return for a fee. 3.623 + 3.624 + END OF TERMS AND CONDITIONS 3.625 + 3.626 + How to Apply These Terms to Your New Programs 3.627 + 3.628 + If you develop a new program, and you want it to be of the greatest 3.629 +possible use to the public, the best way to achieve this is to make it 3.630 +free software which everyone can redistribute and change under these terms. 3.631 + 3.632 + To do so, attach the following notices to the program. It is safest 3.633 +to attach them to the start of each source file to most effectively 3.634 +state the exclusion of warranty; and each file should have at least 3.635 +the "copyright" line and a pointer to where the full notice is found. 3.636 + 3.637 + <one line to give the program's name and a brief idea of what it does.> 3.638 + Copyright (C) <year> <name of author> 3.639 + 3.640 + This program is free software: you can redistribute it and/or modify 3.641 + it under the terms of the GNU General Public License as published by 3.642 + the Free Software Foundation, either version 3 of the License, or 3.643 + (at your option) any later version. 3.644 + 3.645 + This program is distributed in the hope that it will be useful, 3.646 + but WITHOUT ANY WARRANTY; without even the implied warranty of 3.647 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.648 + GNU General Public License for more details. 3.649 + 3.650 + You should have received a copy of the GNU General Public License 3.651 + along with this program. If not, see <http://www.gnu.org/licenses/>. 3.652 + 3.653 +Also add information on how to contact you by electronic and paper mail. 3.654 + 3.655 + If the program does terminal interaction, make it output a short 3.656 +notice like this when it starts in an interactive mode: 3.657 + 3.658 + <program> Copyright (C) <year> <name of author> 3.659 + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 3.660 + This is free software, and you are welcome to redistribute it 3.661 + under certain conditions; type `show c' for details. 3.662 + 3.663 +The hypothetical commands `show w' and `show c' should show the appropriate 3.664 +parts of the General Public License. Of course, your program's commands 3.665 +might be different; for a GUI interface, you would use an "about box". 3.666 + 3.667 + You should also get your employer (if you work as a programmer) or school, 3.668 +if any, to sign a "copyright disclaimer" for the program, if necessary. 3.669 +For more information on this, and how to apply and follow the GNU GPL, see 3.670 +<http://www.gnu.org/licenses/>. 3.671 + 3.672 + The GNU General Public License does not permit incorporating your program 3.673 +into proprietary programs. If your program is a subroutine library, you 3.674 +may consider it more useful to permit linking proprietary applications with 3.675 +the library. If this is what you want to do, use the GNU Lesser General 3.676 +Public License instead of this License. But first, please read 3.677 +<http://www.gnu.org/philosophy/why-not-lgpl.html>.
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/libs/libimago/COPYING.LESSER Fri Jul 18 05:07:40 2014 +0300 4.3 @@ -0,0 +1,165 @@ 4.4 + GNU LESSER GENERAL PUBLIC LICENSE 4.5 + Version 3, 29 June 2007 4.6 + 4.7 + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> 4.8 + Everyone is permitted to copy and distribute verbatim copies 4.9 + of this license document, but changing it is not allowed. 4.10 + 4.11 + 4.12 + This version of the GNU Lesser General Public License incorporates 4.13 +the terms and conditions of version 3 of the GNU General Public 4.14 +License, supplemented by the additional permissions listed below. 4.15 + 4.16 + 0. Additional Definitions. 4.17 + 4.18 + As used herein, "this License" refers to version 3 of the GNU Lesser 4.19 +General Public License, and the "GNU GPL" refers to version 3 of the GNU 4.20 +General Public License. 4.21 + 4.22 + "The Library" refers to a covered work governed by this License, 4.23 +other than an Application or a Combined Work as defined below. 4.24 + 4.25 + An "Application" is any work that makes use of an interface provided 4.26 +by the Library, but which is not otherwise based on the Library. 4.27 +Defining a subclass of a class defined by the Library is deemed a mode 4.28 +of using an interface provided by the Library. 4.29 + 4.30 + A "Combined Work" is a work produced by combining or linking an 4.31 +Application with the Library. The particular version of the Library 4.32 +with which the Combined Work was made is also called the "Linked 4.33 +Version". 4.34 + 4.35 + The "Minimal Corresponding Source" for a Combined Work means the 4.36 +Corresponding Source for the Combined Work, excluding any source code 4.37 +for portions of the Combined Work that, considered in isolation, are 4.38 +based on the Application, and not on the Linked Version. 4.39 + 4.40 + The "Corresponding Application Code" for a Combined Work means the 4.41 +object code and/or source code for the Application, including any data 4.42 +and utility programs needed for reproducing the Combined Work from the 4.43 +Application, but excluding the System Libraries of the Combined Work. 4.44 + 4.45 + 1. Exception to Section 3 of the GNU GPL. 4.46 + 4.47 + You may convey a covered work under sections 3 and 4 of this License 4.48 +without being bound by section 3 of the GNU GPL. 4.49 + 4.50 + 2. Conveying Modified Versions. 4.51 + 4.52 + If you modify a copy of the Library, and, in your modifications, a 4.53 +facility refers to a function or data to be supplied by an Application 4.54 +that uses the facility (other than as an argument passed when the 4.55 +facility is invoked), then you may convey a copy of the modified 4.56 +version: 4.57 + 4.58 + a) under this License, provided that you make a good faith effort to 4.59 + ensure that, in the event an Application does not supply the 4.60 + function or data, the facility still operates, and performs 4.61 + whatever part of its purpose remains meaningful, or 4.62 + 4.63 + b) under the GNU GPL, with none of the additional permissions of 4.64 + this License applicable to that copy. 4.65 + 4.66 + 3. Object Code Incorporating Material from Library Header Files. 4.67 + 4.68 + The object code form of an Application may incorporate material from 4.69 +a header file that is part of the Library. You may convey such object 4.70 +code under terms of your choice, provided that, if the incorporated 4.71 +material is not limited to numerical parameters, data structure 4.72 +layouts and accessors, or small macros, inline functions and templates 4.73 +(ten or fewer lines in length), you do both of the following: 4.74 + 4.75 + a) Give prominent notice with each copy of the object code that the 4.76 + Library is used in it and that the Library and its use are 4.77 + covered by this License. 4.78 + 4.79 + b) Accompany the object code with a copy of the GNU GPL and this license 4.80 + document. 4.81 + 4.82 + 4. Combined Works. 4.83 + 4.84 + You may convey a Combined Work under terms of your choice that, 4.85 +taken together, effectively do not restrict modification of the 4.86 +portions of the Library contained in the Combined Work and reverse 4.87 +engineering for debugging such modifications, if you also do each of 4.88 +the following: 4.89 + 4.90 + a) Give prominent notice with each copy of the Combined Work that 4.91 + the Library is used in it and that the Library and its use are 4.92 + covered by this License. 4.93 + 4.94 + b) Accompany the Combined Work with a copy of the GNU GPL and this license 4.95 + document. 4.96 + 4.97 + c) For a Combined Work that displays copyright notices during 4.98 + execution, include the copyright notice for the Library among 4.99 + these notices, as well as a reference directing the user to the 4.100 + copies of the GNU GPL and this license document. 4.101 + 4.102 + d) Do one of the following: 4.103 + 4.104 + 0) Convey the Minimal Corresponding Source under the terms of this 4.105 + License, and the Corresponding Application Code in a form 4.106 + suitable for, and under terms that permit, the user to 4.107 + recombine or relink the Application with a modified version of 4.108 + the Linked Version to produce a modified Combined Work, in the 4.109 + manner specified by section 6 of the GNU GPL for conveying 4.110 + Corresponding Source. 4.111 + 4.112 + 1) Use a suitable shared library mechanism for linking with the 4.113 + Library. A suitable mechanism is one that (a) uses at run time 4.114 + a copy of the Library already present on the user's computer 4.115 + system, and (b) will operate properly with a modified version 4.116 + of the Library that is interface-compatible with the Linked 4.117 + Version. 4.118 + 4.119 + e) Provide Installation Information, but only if you would otherwise 4.120 + be required to provide such information under section 6 of the 4.121 + GNU GPL, and only to the extent that such information is 4.122 + necessary to install and execute a modified version of the 4.123 + Combined Work produced by recombining or relinking the 4.124 + Application with a modified version of the Linked Version. (If 4.125 + you use option 4d0, the Installation Information must accompany 4.126 + the Minimal Corresponding Source and Corresponding Application 4.127 + Code. If you use option 4d1, you must provide the Installation 4.128 + Information in the manner specified by section 6 of the GNU GPL 4.129 + for conveying Corresponding Source.) 4.130 + 4.131 + 5. Combined Libraries. 4.132 + 4.133 + You may place library facilities that are a work based on the 4.134 +Library side by side in a single library together with other library 4.135 +facilities that are not Applications and are not covered by this 4.136 +License, and convey such a combined library under terms of your 4.137 +choice, if you do both of the following: 4.138 + 4.139 + a) Accompany the combined library with a copy of the same work based 4.140 + on the Library, uncombined with any other library facilities, 4.141 + conveyed under the terms of this License. 4.142 + 4.143 + b) Give prominent notice with the combined library that part of it 4.144 + is a work based on the Library, and explaining where to find the 4.145 + accompanying uncombined form of the same work. 4.146 + 4.147 + 6. Revised Versions of the GNU Lesser General Public License. 4.148 + 4.149 + The Free Software Foundation may publish revised and/or new versions 4.150 +of the GNU Lesser General Public License from time to time. Such new 4.151 +versions will be similar in spirit to the present version, but may 4.152 +differ in detail to address new problems or concerns. 4.153 + 4.154 + Each version is given a distinguishing version number. If the 4.155 +Library as you received it specifies that a certain numbered version 4.156 +of the GNU Lesser General Public License "or any later version" 4.157 +applies to it, you have the option of following the terms and 4.158 +conditions either of that published version or of any later version 4.159 +published by the Free Software Foundation. If the Library as you 4.160 +received it does not specify a version number of the GNU Lesser 4.161 +General Public License, you may choose any version of the GNU Lesser 4.162 +General Public License ever published by the Free Software Foundation. 4.163 + 4.164 + If the Library as you received it specifies that a proxy can decide 4.165 +whether future versions of the GNU Lesser General Public License shall 4.166 +apply, that proxy's public statement of acceptance of any version is 4.167 +permanent authorization for you to choose that version for the 4.168 +Library.
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/libs/libimago/Makefile.in Fri Jul 18 05:07:40 2014 +0300 5.3 @@ -0,0 +1,76 @@ 5.4 +dbg = -g 5.5 +opt = 5.6 + 5.7 +csrc = $(wildcard src/*.c) 5.8 +obj = $(csrc:.c=.o) 5.9 +lib_a = libimago.a 5.10 + 5.11 +somajor = 2 5.12 +sominor = 0 5.13 + 5.14 +incdir = -I$(PREFIX)/include 5.15 +libdir = -L$(PREFIX)/lib 5.16 + 5.17 +ifeq ($(shell uname -s), Darwin) 5.18 + lib_so = libimago.dylib 5.19 + shared = -dynamiclib 5.20 + # add macports and fink dirs to the include and lib paths 5.21 + incdir += -I/opt/local/include -I/sw/local/include -I/usr/X11R6/include 5.22 + libdir += -L/opt/local/lib -L/sw/local/lib -L/usr/X11R6/lib 5.23 +else 5.24 + soname = libimago.so.$(somajor) 5.25 + lib_so = $(soname).$(sominor) 5.26 + solink = libimago.so 5.27 + shared = -shared -Wl,-soname,$(soname) 5.28 +endif 5.29 + 5.30 +ifeq ($(shell uname -s), IRIX) 5.31 + # add nekoware and SGI freeware dirs to the include and lib paths 5.32 + incdir += -I/usr/nekoware/include -I/usr/freeware/include 5.33 + libdir += -L/usr/nekoware/lib -L/usr/freeware/lib 5.34 +endif 5.35 + 5.36 +CC = gcc 5.37 +AR = ar 5.38 +CFLAGS = -pedantic -Wall $(opt) $(dbg) -fPIC -Isrc $(incdir) 5.39 +LDFLAGS = $(libdir) -lpng -lz -ljpeg -ldl 5.40 + 5.41 +.PHONY: all 5.42 +all: $(lib_a) $(lib_so) 5.43 + 5.44 +$(lib_a): $(obj) 5.45 + $(AR) rcs $@ $^ 5.46 + 5.47 +$(lib_so): $(obj) 5.48 + $(CC) $(CFLAGS) $(shared) -o $@ $^ $(LDFLAGS) 5.49 + 5.50 +.PHONY: clean 5.51 +clean: 5.52 + rm -f $(obj) 5.53 + 5.54 +.PHONY: distclean 5.55 +distclean: 5.56 + rm -f $(obj) $(lib_so) $(lib_a) Makefile src/modules.c 5.57 + 5.58 +.PHONY: install 5.59 +install: $(lib_so) $(lib_a) 5.60 + mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib 5.61 + cp src/imago2.h $(DESTDIR)$(PREFIX)/include/imago2.h 5.62 + cp $(lib_so) $(DESTDIR)$(PREFIX)/lib/$(lib_so) 5.63 + cp $(lib_a) $(DESTDIR)$(PREFIX)/lib/$(lib_a) 5.64 + [ -n "$(solink)" ] \ 5.65 + && cd $(DESTDIR)$(PREFIX)/lib \ 5.66 + && rm -f $(solink) $(soname) \ 5.67 + && ln -s $(lib_so) $(soname) \ 5.68 + && ln -s $(soname) $(solink) \ 5.69 + || true 5.70 + 5.71 +.PHONY: uninstall 5.72 +uninstall: 5.73 + rm -f $(DESTDIR)$(PREFIX)/include/imago2.h 5.74 + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_so) 5.75 + rm -f $(DESTDIR)$(PREFIX)/lib/$(lib_a) 5.76 + [ -n "$(solink)" ] \ 5.77 + && rm -f $(DESTDIR)$(PREFIX)/lib/$(solink) \ 5.78 + && rm -f $(DESTDIR)$(PREFIX)/lib/$(soname) \ 5.79 + || true
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/libs/libimago/README Fri Jul 18 05:07:40 2014 +0300 6.3 @@ -0,0 +1,8 @@ 6.4 +imago version 2.0 6.5 +----------------- 6.6 + 6.7 +Author: John Tsiombikas <nuclear@member.fsf.org> 6.8 + 6.9 +This library is released as free software under the term of the GNU Lesser 6.10 +General Public License (LGPL) version 3 or any later version published by 6.11 +the Free Software Foundation. See COPYING and COPYING.LESSER for details.
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/libs/libimago/build/vcconfig.bat Fri Jul 18 05:07:40 2014 +0300 7.3 @@ -0,0 +1,14 @@ 7.4 +@set outfile=src/modules.c 7.5 + 7.6 +@echo /* this file is generated by vcconfig.bat, do not edit */ >%outfile% 7.7 +@echo int img_register_png(); >>%outfile% 7.8 +@echo int img_register_jpeg(); >>%outfile% 7.9 +@echo int img_register_ppm(); >>%outfile% 7.10 +@echo int img_register_rgbe(); >>%outfile% 7.11 +@echo void img_modules_init(void) >>%outfile% 7.12 +@echo { >>%outfile% 7.13 +@echo img_register_png(); >>%outfile% 7.14 +@echo img_register_jpeg(); >>%outfile% 7.15 +@echo img_register_ppm(); >>%outfile% 7.16 +@echo img_register_rgbe(); >>%outfile% 7.17 +@echo } >>%outfile%
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/libs/libimago/configure Fri Jul 18 05:07:40 2014 +0300 8.3 @@ -0,0 +1,27 @@ 8.4 +#!/bin/sh 8.5 + 8.6 +gen_module_init() 8.7 +{ 8.8 + # collect all src/file_whatever.c files 8.9 + modules=`ls src/file_*.c 2>/dev/null | sort | sed 's/src\/file_//' | sed 's/\.c//'` 8.10 + 8.11 + echo "/* this file is generated by $0, do not edit */" 8.12 + for m in $modules; do 8.13 + echo "int img_register_$m();" 8.14 + done 8.15 + 8.16 + echo 8.17 + echo 'void img_modules_init(void)' 8.18 + echo '{' 8.19 + 8.20 + for m in $modules; do 8.21 + echo " img_register_$m();" 8.22 + done 8.23 + 8.24 + echo '}' 8.25 +} 8.26 + 8.27 +gen_module_init >src/modules.c 8.28 + 8.29 +echo 'PREFIX = /usr/local' >Makefile 8.30 +cat Makefile.in >>Makefile
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/libs/libimago/imago-vs2012.sln Fri Jul 18 05:07:40 2014 +0300 9.3 @@ -0,0 +1,26 @@ 9.4 + 9.5 +Microsoft Visual Studio Solution File, Format Version 12.00 9.6 +# Visual Studio 2012 9.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imago", "imago-vs2012.vcxproj", "{1FFDD3FB-E37E-4258-8955-5583AF3A0C29}" 9.8 +EndProject 9.9 +Global 9.10 + GlobalSection(SolutionConfigurationPlatforms) = preSolution 9.11 + Debug|Win32 = Debug|Win32 9.12 + Debug|x64 = Debug|x64 9.13 + Release|Win32 = Release|Win32 9.14 + Release|x64 = Release|x64 9.15 + EndGlobalSection 9.16 + GlobalSection(ProjectConfigurationPlatforms) = postSolution 9.17 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Debug|Win32.ActiveCfg = Debug|Win32 9.18 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Debug|Win32.Build.0 = Debug|Win32 9.19 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Debug|x64.ActiveCfg = Debug|x64 9.20 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Debug|x64.Build.0 = Debug|x64 9.21 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Release|Win32.ActiveCfg = Release|Win32 9.22 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Release|Win32.Build.0 = Release|Win32 9.23 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Release|x64.ActiveCfg = Release|x64 9.24 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Release|x64.Build.0 = Release|x64 9.25 + EndGlobalSection 9.26 + GlobalSection(SolutionProperties) = preSolution 9.27 + HideSolutionNode = FALSE 9.28 + EndGlobalSection 9.29 +EndGlobal
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/libs/libimago/imago-vs2012.vcxproj Fri Jul 18 05:07:40 2014 +0300 10.3 @@ -0,0 +1,173 @@ 10.4 +<?xml version="1.0" encoding="utf-8"?> 10.5 +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 10.6 + <ItemGroup Label="ProjectConfigurations"> 10.7 + <ProjectConfiguration Include="Debug|Win32"> 10.8 + <Configuration>Debug</Configuration> 10.9 + <Platform>Win32</Platform> 10.10 + </ProjectConfiguration> 10.11 + <ProjectConfiguration Include="Debug|x64"> 10.12 + <Configuration>Debug</Configuration> 10.13 + <Platform>x64</Platform> 10.14 + </ProjectConfiguration> 10.15 + <ProjectConfiguration Include="Release|Win32"> 10.16 + <Configuration>Release</Configuration> 10.17 + <Platform>Win32</Platform> 10.18 + </ProjectConfiguration> 10.19 + <ProjectConfiguration Include="Release|x64"> 10.20 + <Configuration>Release</Configuration> 10.21 + <Platform>x64</Platform> 10.22 + </ProjectConfiguration> 10.23 + </ItemGroup> 10.24 + <PropertyGroup Label="Globals"> 10.25 + <ProjectName>libimago2</ProjectName> 10.26 + <ProjectGuid>{1FFDD3FB-E37E-4258-8955-5583AF3A0C29}</ProjectGuid> 10.27 + <RootNamespace>imago</RootNamespace> 10.28 + <Keyword>Win32Proj</Keyword> 10.29 + </PropertyGroup> 10.30 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 10.31 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 10.32 + <ConfigurationType>StaticLibrary</ConfigurationType> 10.33 + <PlatformToolset>v110</PlatformToolset> 10.34 + <CharacterSet>Unicode</CharacterSet> 10.35 + <WholeProgramOptimization>true</WholeProgramOptimization> 10.36 + </PropertyGroup> 10.37 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> 10.38 + <ConfigurationType>StaticLibrary</ConfigurationType> 10.39 + <PlatformToolset>v100</PlatformToolset> 10.40 + <CharacterSet>Unicode</CharacterSet> 10.41 + <WholeProgramOptimization>true</WholeProgramOptimization> 10.42 + </PropertyGroup> 10.43 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 10.44 + <ConfigurationType>StaticLibrary</ConfigurationType> 10.45 + <PlatformToolset>v110</PlatformToolset> 10.46 + <CharacterSet>Unicode</CharacterSet> 10.47 + </PropertyGroup> 10.48 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> 10.49 + <ConfigurationType>StaticLibrary</ConfigurationType> 10.50 + <PlatformToolset>v100</PlatformToolset> 10.51 + <CharacterSet>Unicode</CharacterSet> 10.52 + </PropertyGroup> 10.53 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 10.54 + <ImportGroup Label="ExtensionSettings"> 10.55 + </ImportGroup> 10.56 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> 10.57 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 10.58 + </ImportGroup> 10.59 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> 10.60 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 10.61 + </ImportGroup> 10.62 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> 10.63 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 10.64 + </ImportGroup> 10.65 + <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> 10.66 + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 10.67 + </ImportGroup> 10.68 + <PropertyGroup Label="UserMacros" /> 10.69 + <PropertyGroup> 10.70 + <_ProjectFileVersion>11.0.60610.1</_ProjectFileVersion> 10.71 + </PropertyGroup> 10.72 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 10.73 + <OutDir>$(SolutionDir)$(Configuration)\</OutDir> 10.74 + <IntDir>$(Configuration)\</IntDir> 10.75 + </PropertyGroup> 10.76 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 10.77 + <TargetName>$(ProjectName)-x64</TargetName> 10.78 + </PropertyGroup> 10.79 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 10.80 + <OutDir>$(SolutionDir)$(Configuration)\</OutDir> 10.81 + <IntDir>$(Configuration)\</IntDir> 10.82 + </PropertyGroup> 10.83 + <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 10.84 + <TargetName>$(ProjectName)-x64</TargetName> 10.85 + </PropertyGroup> 10.86 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 10.87 + <PreBuildEvent> 10.88 + <Command>$(SolutionDir)\build\vcconfig.bat</Command> 10.89 + </PreBuildEvent> 10.90 + <ClCompile> 10.91 + <Optimization>Disabled</Optimization> 10.92 + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> 10.93 + <MinimalRebuild>true</MinimalRebuild> 10.94 + <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> 10.95 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 10.96 + <PrecompiledHeader /> 10.97 + <WarningLevel>Level3</WarningLevel> 10.98 + <DebugInformationFormat>EditAndContinue</DebugInformationFormat> 10.99 + <DisableSpecificWarnings>4244;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings> 10.100 + </ClCompile> 10.101 + </ItemDefinitionGroup> 10.102 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> 10.103 + <PreBuildEvent> 10.104 + <Command>$(SolutionDir)\build\vcconfig.bat</Command> 10.105 + </PreBuildEvent> 10.106 + <ClCompile> 10.107 + <Optimization>Disabled</Optimization> 10.108 + <PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> 10.109 + <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> 10.110 + <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> 10.111 + <PrecompiledHeader> 10.112 + </PrecompiledHeader> 10.113 + <WarningLevel>Level3</WarningLevel> 10.114 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 10.115 + <DisableSpecificWarnings>4244;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings> 10.116 + </ClCompile> 10.117 + <PostBuildEvent> 10.118 + <Command>mkdir $(SolutionDir)\usr\include 10.119 +mkdir $(SolutionDir)\usr\lib 10.120 +copy /Y $(SolutionDir)\src\imago2.h $(SolutionDir)\usr\include\ 10.121 +copy /Y $(TargetPath) $(SolutionDir)\usr\lib\</Command> 10.122 + </PostBuildEvent> 10.123 + </ItemDefinitionGroup> 10.124 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 10.125 + <ClCompile> 10.126 + <Optimization>MaxSpeed</Optimization> 10.127 + <IntrinsicFunctions>true</IntrinsicFunctions> 10.128 + <WholeProgramOptimization>false</WholeProgramOptimization> 10.129 + <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> 10.130 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 10.131 + <FunctionLevelLinking>true</FunctionLevelLinking> 10.132 + <PrecompiledHeader /> 10.133 + <WarningLevel>Level3</WarningLevel> 10.134 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 10.135 + <DisableSpecificWarnings>4244;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings> 10.136 + </ClCompile> 10.137 + </ItemDefinitionGroup> 10.138 + <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 10.139 + <ClCompile> 10.140 + <Optimization>MaxSpeed</Optimization> 10.141 + <IntrinsicFunctions>true</IntrinsicFunctions> 10.142 + <WholeProgramOptimization>false</WholeProgramOptimization> 10.143 + <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> 10.144 + <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> 10.145 + <FunctionLevelLinking>true</FunctionLevelLinking> 10.146 + <PrecompiledHeader> 10.147 + </PrecompiledHeader> 10.148 + <WarningLevel>Level3</WarningLevel> 10.149 + <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> 10.150 + <DisableSpecificWarnings>4244;4996;%(DisableSpecificWarnings)</DisableSpecificWarnings> 10.151 + </ClCompile> 10.152 + <PostBuildEvent> 10.153 + <Command>mkdir $(SolutionDir)\usr\include 10.154 +mkdir $(SolutionDir)\usr\lib 10.155 +copy /Y $(SolutionDir)\src\imago2.h $(SolutionDir)\usr\include\ 10.156 +copy /Y $(TargetPath) $(SolutionDir)\usr\lib\</Command> 10.157 + </PostBuildEvent> 10.158 + </ItemDefinitionGroup> 10.159 + <ItemGroup> 10.160 + <ClCompile Include="src\conv.c" /> 10.161 + <ClCompile Include="src\file_jpeg.c" /> 10.162 + <ClCompile Include="src\file_png.c" /> 10.163 + <ClCompile Include="src\file_ppm.c" /> 10.164 + <ClCompile Include="src\file_rgbe.c" /> 10.165 + <ClCompile Include="src\ftype_module.c" /> 10.166 + <ClCompile Include="src\imago2.c" /> 10.167 + <ClCompile Include="src\imago_gl.c" /> 10.168 + </ItemGroup> 10.169 + <ItemGroup> 10.170 + <ClInclude Include="src\ftype_module.h" /> 10.171 + <ClInclude Include="src\imago2.h" /> 10.172 + </ItemGroup> 10.173 + <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 10.174 + <ImportGroup Label="ExtensionTargets"> 10.175 + </ImportGroup> 10.176 +</Project> 10.177 \ No newline at end of file
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/libs/libimago/imago-vs2012.vcxproj.filters Fri Jul 18 05:07:40 2014 +0300 11.3 @@ -0,0 +1,51 @@ 11.4 +<?xml version="1.0" encoding="utf-8"?> 11.5 +<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 11.6 + <ItemGroup> 11.7 + <Filter Include="Source Files"> 11.8 + <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> 11.9 + <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions> 11.10 + </Filter> 11.11 + <Filter Include="Header Files"> 11.12 + <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier> 11.13 + <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions> 11.14 + </Filter> 11.15 + <Filter Include="Resource Files"> 11.16 + <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> 11.17 + <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions> 11.18 + </Filter> 11.19 + </ItemGroup> 11.20 + <ItemGroup> 11.21 + <ClCompile Include="src\conv.c"> 11.22 + <Filter>Source Files</Filter> 11.23 + </ClCompile> 11.24 + <ClCompile Include="src\file_jpeg.c"> 11.25 + <Filter>Source Files</Filter> 11.26 + </ClCompile> 11.27 + <ClCompile Include="src\file_png.c"> 11.28 + <Filter>Source Files</Filter> 11.29 + </ClCompile> 11.30 + <ClCompile Include="src\file_ppm.c"> 11.31 + <Filter>Source Files</Filter> 11.32 + </ClCompile> 11.33 + <ClCompile Include="src\file_rgbe.c"> 11.34 + <Filter>Source Files</Filter> 11.35 + </ClCompile> 11.36 + <ClCompile Include="src\ftype_module.c"> 11.37 + <Filter>Source Files</Filter> 11.38 + </ClCompile> 11.39 + <ClCompile Include="src\imago2.c"> 11.40 + <Filter>Source Files</Filter> 11.41 + </ClCompile> 11.42 + <ClCompile Include="src\imago_gl.c"> 11.43 + <Filter>Source Files</Filter> 11.44 + </ClCompile> 11.45 + </ItemGroup> 11.46 + <ItemGroup> 11.47 + <ClInclude Include="src\ftype_module.h"> 11.48 + <Filter>Header Files</Filter> 11.49 + </ClInclude> 11.50 + <ClInclude Include="src\imago2.h"> 11.51 + <Filter>Header Files</Filter> 11.52 + </ClInclude> 11.53 + </ItemGroup> 11.54 +</Project> 11.55 \ No newline at end of file
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/libs/libimago/imago.sln Fri Jul 18 05:07:40 2014 +0300 12.3 @@ -0,0 +1,20 @@ 12.4 + 12.5 +Microsoft Visual Studio Solution File, Format Version 10.00 12.6 +# Visual Studio 2008 12.7 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imago", "imago.vcproj", "{1FFDD3FB-E37E-4258-8955-5583AF3A0C29}" 12.8 +EndProject 12.9 +Global 12.10 + GlobalSection(SolutionConfigurationPlatforms) = preSolution 12.11 + Debug|Win32 = Debug|Win32 12.12 + Release|Win32 = Release|Win32 12.13 + EndGlobalSection 12.14 + GlobalSection(ProjectConfigurationPlatforms) = postSolution 12.15 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Debug|Win32.ActiveCfg = Debug|Win32 12.16 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Debug|Win32.Build.0 = Debug|Win32 12.17 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Release|Win32.ActiveCfg = Release|Win32 12.18 + {1FFDD3FB-E37E-4258-8955-5583AF3A0C29}.Release|Win32.Build.0 = Release|Win32 12.19 + EndGlobalSection 12.20 + GlobalSection(SolutionProperties) = preSolution 12.21 + HideSolutionNode = FALSE 12.22 + EndGlobalSection 12.23 +EndGlobal
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/libs/libimago/imago.vcproj Fri Jul 18 05:07:40 2014 +0300 13.3 @@ -0,0 +1,211 @@ 13.4 +<?xml version="1.0" encoding="windows-1253"?> 13.5 +<VisualStudioProject 13.6 + ProjectType="Visual C++" 13.7 + Version="9.00" 13.8 + Name="libimago2" 13.9 + ProjectGUID="{1FFDD3FB-E37E-4258-8955-5583AF3A0C29}" 13.10 + RootNamespace="imago" 13.11 + Keyword="Win32Proj" 13.12 + TargetFrameworkVersion="196613" 13.13 + > 13.14 + <Platforms> 13.15 + <Platform 13.16 + Name="Win32" 13.17 + /> 13.18 + </Platforms> 13.19 + <ToolFiles> 13.20 + </ToolFiles> 13.21 + <Configurations> 13.22 + <Configuration 13.23 + Name="Debug|Win32" 13.24 + OutputDirectory="$(SolutionDir)$(ConfigurationName)" 13.25 + IntermediateDirectory="$(ConfigurationName)" 13.26 + ConfigurationType="4" 13.27 + CharacterSet="1" 13.28 + > 13.29 + <Tool 13.30 + Name="VCPreBuildEventTool" 13.31 + CommandLine="$(SolutionDir)\build\vcconfig.bat" 13.32 + /> 13.33 + <Tool 13.34 + Name="VCCustomBuildTool" 13.35 + /> 13.36 + <Tool 13.37 + Name="VCXMLDataGeneratorTool" 13.38 + /> 13.39 + <Tool 13.40 + Name="VCWebServiceProxyGeneratorTool" 13.41 + /> 13.42 + <Tool 13.43 + Name="VCMIDLTool" 13.44 + /> 13.45 + <Tool 13.46 + Name="VCCLCompilerTool" 13.47 + Optimization="0" 13.48 + PreprocessorDefinitions="WIN32;_DEBUG;_LIB" 13.49 + MinimalRebuild="true" 13.50 + BasicRuntimeChecks="3" 13.51 + RuntimeLibrary="3" 13.52 + UsePrecompiledHeader="0" 13.53 + WarningLevel="3" 13.54 + DebugInformationFormat="4" 13.55 + DisableSpecificWarnings="4244;4996" 13.56 + /> 13.57 + <Tool 13.58 + Name="VCManagedResourceCompilerTool" 13.59 + /> 13.60 + <Tool 13.61 + Name="VCResourceCompilerTool" 13.62 + /> 13.63 + <Tool 13.64 + Name="VCPreLinkEventTool" 13.65 + /> 13.66 + <Tool 13.67 + Name="VCLibrarianTool" 13.68 + /> 13.69 + <Tool 13.70 + Name="VCALinkTool" 13.71 + /> 13.72 + <Tool 13.73 + Name="VCXDCMakeTool" 13.74 + /> 13.75 + <Tool 13.76 + Name="VCBscMakeTool" 13.77 + /> 13.78 + <Tool 13.79 + Name="VCFxCopTool" 13.80 + /> 13.81 + <Tool 13.82 + Name="VCPostBuildEventTool" 13.83 + /> 13.84 + </Configuration> 13.85 + <Configuration 13.86 + Name="Release|Win32" 13.87 + OutputDirectory="$(SolutionDir)$(ConfigurationName)" 13.88 + IntermediateDirectory="$(ConfigurationName)" 13.89 + ConfigurationType="4" 13.90 + CharacterSet="1" 13.91 + WholeProgramOptimization="1" 13.92 + > 13.93 + <Tool 13.94 + Name="VCPreBuildEventTool" 13.95 + CommandLine="$(SolutionDir)\build\vcconfig.bat" 13.96 + /> 13.97 + <Tool 13.98 + Name="VCCustomBuildTool" 13.99 + /> 13.100 + <Tool 13.101 + Name="VCXMLDataGeneratorTool" 13.102 + /> 13.103 + <Tool 13.104 + Name="VCWebServiceProxyGeneratorTool" 13.105 + /> 13.106 + <Tool 13.107 + Name="VCMIDLTool" 13.108 + /> 13.109 + <Tool 13.110 + Name="VCCLCompilerTool" 13.111 + Optimization="2" 13.112 + EnableIntrinsicFunctions="true" 13.113 + WholeProgramOptimization="false" 13.114 + PreprocessorDefinitions="WIN32;NDEBUG;_LIB" 13.115 + RuntimeLibrary="2" 13.116 + EnableFunctionLevelLinking="true" 13.117 + UsePrecompiledHeader="0" 13.118 + WarningLevel="3" 13.119 + DebugInformationFormat="3" 13.120 + DisableSpecificWarnings="4244;4996" 13.121 + /> 13.122 + <Tool 13.123 + Name="VCManagedResourceCompilerTool" 13.124 + /> 13.125 + <Tool 13.126 + Name="VCResourceCompilerTool" 13.127 + /> 13.128 + <Tool 13.129 + Name="VCPreLinkEventTool" 13.130 + /> 13.131 + <Tool 13.132 + Name="VCLibrarianTool" 13.133 + /> 13.134 + <Tool 13.135 + Name="VCALinkTool" 13.136 + /> 13.137 + <Tool 13.138 + Name="VCXDCMakeTool" 13.139 + /> 13.140 + <Tool 13.141 + Name="VCBscMakeTool" 13.142 + /> 13.143 + <Tool 13.144 + Name="VCFxCopTool" 13.145 + /> 13.146 + <Tool 13.147 + Name="VCPostBuildEventTool" 13.148 + CommandLine="mkdir usr\include
mkdir usr\lib
copy /Y src\imago2.h usr\include\imago2.h
copy /Y $(TargetPath) usr\lib\
" 13.149 + /> 13.150 + </Configuration> 13.151 + </Configurations> 13.152 + <References> 13.153 + </References> 13.154 + <Files> 13.155 + <Filter 13.156 + Name="Source Files" 13.157 + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" 13.158 + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" 13.159 + > 13.160 + <File 13.161 + RelativePath=".\src\conv.c" 13.162 + > 13.163 + </File> 13.164 + <File 13.165 + RelativePath=".\src\file_jpeg.c" 13.166 + > 13.167 + </File> 13.168 + <File 13.169 + RelativePath=".\src\file_png.c" 13.170 + > 13.171 + </File> 13.172 + <File 13.173 + RelativePath=".\src\file_ppm.c" 13.174 + > 13.175 + </File> 13.176 + <File 13.177 + RelativePath=".\src\file_rgbe.c" 13.178 + > 13.179 + </File> 13.180 + <File 13.181 + RelativePath=".\src\ftype_module.c" 13.182 + > 13.183 + </File> 13.184 + <File 13.185 + RelativePath=".\src\imago2.c" 13.186 + > 13.187 + </File> 13.188 + <File 13.189 + RelativePath=".\src\imago_gl.c" 13.190 + > 13.191 + </File> 13.192 + <File 13.193 + RelativePath=".\src\modules.c" 13.194 + > 13.195 + </File> 13.196 + </Filter> 13.197 + <Filter 13.198 + Name="Header Files" 13.199 + Filter="h;hpp;hxx;hm;inl;inc;xsd" 13.200 + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" 13.201 + > 13.202 + <File 13.203 + RelativePath=".\src\ftype_module.h" 13.204 + > 13.205 + </File> 13.206 + <File 13.207 + RelativePath=".\src\imago2.h" 13.208 + > 13.209 + </File> 13.210 + </Filter> 13.211 + </Files> 13.212 + <Globals> 13.213 + </Globals> 13.214 +</VisualStudioProject>
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/libs/libimago/install.bat Fri Jul 18 05:07:40 2014 +0300 14.3 @@ -0,0 +1,5 @@ 14.4 +mkdir c:\usr\include\ 14.5 +copy /Y usr\include\* c:\usr\include\ 14.6 +mkdir c:\usr\lib 14.7 +copy /Y usr\lib\* c:\usr\lib\ 14.8 +pause
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/libs/libimago/src/conv.c Fri Jul 18 05:07:40 2014 +0300 15.3 @@ -0,0 +1,260 @@ 15.4 +/* 15.5 +libimago - a multi-format image file input/output library. 15.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 15.7 + 15.8 +This program is free software: you can redistribute it and/or modify 15.9 +it under the terms of the GNU Lesser General Public License as published 15.10 +by the Free Software Foundation, either version 3 of the License, or 15.11 +(at your option) any later version. 15.12 + 15.13 +This program is distributed in the hope that it will be useful, 15.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 15.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15.16 +GNU Lesser General Public License for more details. 15.17 + 15.18 +You should have received a copy of the GNU Lesser General Public License 15.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 15.20 +*/ 15.21 +#include <string.h> 15.22 +#include "imago2.h" 15.23 + 15.24 +/* pixel-format conversions are sub-optimal at the moment to avoid 15.25 + * writing a lot of code. optimize at some point ? 15.26 + */ 15.27 + 15.28 +#define CLAMP(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x))) 15.29 + 15.30 +struct pixel { 15.31 + float r, g, b, a; 15.32 +}; 15.33 + 15.34 +static void unpack_grey8(struct pixel *unp, void *pptr, int count); 15.35 +static void unpack_rgb24(struct pixel *unp, void *pptr, int count); 15.36 +static void unpack_rgba32(struct pixel *unp, void *pptr, int count); 15.37 +static void unpack_greyf(struct pixel *unp, void *pptr, int count); 15.38 +static void unpack_rgbf(struct pixel *unp, void *pptr, int count); 15.39 +static void unpack_rgbaf(struct pixel *unp, void *pptr, int count); 15.40 + 15.41 +static void pack_grey8(void *pptr, struct pixel *unp, int count); 15.42 +static void pack_rgb24(void *pptr, struct pixel *unp, int count); 15.43 +static void pack_rgba32(void *pptr, struct pixel *unp, int count); 15.44 +static void pack_greyf(void *pptr, struct pixel *unp, int count); 15.45 +static void pack_rgbf(void *pptr, struct pixel *unp, int count); 15.46 +static void pack_rgbaf(void *pptr, struct pixel *unp, int count); 15.47 + 15.48 +/* XXX keep in sync with enum img_fmt at imago2.h */ 15.49 +static void (*unpack[])(struct pixel*, void*, int) = { 15.50 + unpack_grey8, 15.51 + unpack_rgb24, 15.52 + unpack_rgba32, 15.53 + unpack_greyf, 15.54 + unpack_rgbf, 15.55 + unpack_rgbaf 15.56 +}; 15.57 + 15.58 +/* XXX keep in sync with enum img_fmt at imago2.h */ 15.59 +static void (*pack[])(void*, struct pixel*, int) = { 15.60 + pack_grey8, 15.61 + pack_rgb24, 15.62 + pack_rgba32, 15.63 + pack_greyf, 15.64 + pack_rgbf, 15.65 + pack_rgbaf 15.66 +}; 15.67 + 15.68 + 15.69 +int img_convert(struct img_pixmap *img, enum img_fmt tofmt) 15.70 +{ 15.71 + struct pixel pbuf[8]; 15.72 + int bufsz = (img->width & 7) == 0 ? 8 : ((img->width & 3) == 0 ? 4 : 1); 15.73 + int i, num_pix = img->width * img->height; 15.74 + int num_iter = num_pix / bufsz; 15.75 + char *sptr, *dptr; 15.76 + struct img_pixmap nimg; 15.77 + 15.78 + if(img->fmt == tofmt) { 15.79 + return 0; /* nothing to do */ 15.80 + } 15.81 + 15.82 + img_init(&nimg); 15.83 + if(img_set_pixels(&nimg, img->width, img->height, tofmt, 0) == -1) { 15.84 + img_destroy(&nimg); 15.85 + return -1; 15.86 + } 15.87 + 15.88 + sptr = img->pixels; 15.89 + dptr = nimg.pixels; 15.90 + 15.91 + for(i=0; i<num_iter; i++) { 15.92 + unpack[img->fmt](pbuf, sptr, bufsz); 15.93 + pack[tofmt](dptr, pbuf, bufsz); 15.94 + 15.95 + sptr += bufsz * img->pixelsz; 15.96 + dptr += bufsz * nimg.pixelsz; 15.97 + } 15.98 + 15.99 + img_copy(img, &nimg); 15.100 + img_destroy(&nimg); 15.101 + return 0; 15.102 +} 15.103 + 15.104 +/* the following functions *could* benefit from SIMD */ 15.105 + 15.106 +static void unpack_grey8(struct pixel *unp, void *pptr, int count) 15.107 +{ 15.108 + int i; 15.109 + unsigned char *pix = pptr; 15.110 + 15.111 + for(i=0; i<count; i++) { 15.112 + unp->r = unp->g = unp->b = (float)*pix++ / 255.0; 15.113 + unp->a = 1.0; 15.114 + unp++; 15.115 + } 15.116 +} 15.117 + 15.118 +static void unpack_rgb24(struct pixel *unp, void *pptr, int count) 15.119 +{ 15.120 + int i; 15.121 + unsigned char *pix = pptr; 15.122 + 15.123 + for(i=0; i<count; i++) { 15.124 + unp->r = (float)*pix++ / 255.0; 15.125 + unp->g = (float)*pix++ / 255.0; 15.126 + unp->b = (float)*pix++ / 255.0; 15.127 + unp->a = 1.0; 15.128 + unp++; 15.129 + } 15.130 +} 15.131 + 15.132 +static void unpack_rgba32(struct pixel *unp, void *pptr, int count) 15.133 +{ 15.134 + int i; 15.135 + unsigned char *pix = pptr; 15.136 + 15.137 + for(i=0; i<count; i++) { 15.138 + unp->r = (float)*pix++ / 255.0; 15.139 + unp->g = (float)*pix++ / 255.0; 15.140 + unp->b = (float)*pix++ / 255.0; 15.141 + unp->a = (float)*pix++ / 255.0; 15.142 + unp++; 15.143 + } 15.144 +} 15.145 + 15.146 +static void unpack_greyf(struct pixel *unp, void *pptr, int count) 15.147 +{ 15.148 + int i; 15.149 + float *pix = pptr; 15.150 + 15.151 + for(i=0; i<count; i++) { 15.152 + unp->r = unp->g = unp->b = *pix++; 15.153 + unp->a = 1.0; 15.154 + unp++; 15.155 + } 15.156 +} 15.157 + 15.158 +static void unpack_rgbf(struct pixel *unp, void *pptr, int count) 15.159 +{ 15.160 + int i; 15.161 + float *pix = pptr; 15.162 + 15.163 + for(i=0; i<count; i++) { 15.164 + unp->r = *pix++; 15.165 + unp->g = *pix++; 15.166 + unp->b = *pix++; 15.167 + unp->a = 1.0; 15.168 + unp++; 15.169 + } 15.170 +} 15.171 + 15.172 +static void unpack_rgbaf(struct pixel *unp, void *pptr, int count) 15.173 +{ 15.174 + int i; 15.175 + float *pix = pptr; 15.176 + 15.177 + for(i=0; i<count; i++) { 15.178 + unp->r = *pix++; 15.179 + unp->g = *pix++; 15.180 + unp->b = *pix++; 15.181 + unp->a = *pix++; 15.182 + unp++; 15.183 + } 15.184 +} 15.185 + 15.186 + 15.187 +static void pack_grey8(void *pptr, struct pixel *unp, int count) 15.188 +{ 15.189 + int i; 15.190 + unsigned char *pix = pptr; 15.191 + 15.192 + for(i=0; i<count; i++) { 15.193 + int lum = (int)(255.0 * (unp->r + unp->g + unp->b) / 3.0); 15.194 + *pix++ = CLAMP(lum, 0, 255); 15.195 + unp++; 15.196 + } 15.197 +} 15.198 + 15.199 +static void pack_rgb24(void *pptr, struct pixel *unp, int count) 15.200 +{ 15.201 + int i; 15.202 + unsigned char *pix = pptr; 15.203 + 15.204 + for(i=0; i<count; i++) { 15.205 + int r = (int)(unp->r * 255.0); 15.206 + int g = (int)(unp->g * 255.0); 15.207 + int b = (int)(unp->b * 255.0); 15.208 + 15.209 + *pix++ = CLAMP(r, 0, 255); 15.210 + *pix++ = CLAMP(g, 0, 255); 15.211 + *pix++ = CLAMP(b, 0, 255); 15.212 + unp++; 15.213 + } 15.214 +} 15.215 + 15.216 +static void pack_rgba32(void *pptr, struct pixel *unp, int count) 15.217 +{ 15.218 + int i; 15.219 + unsigned char *pix = pptr; 15.220 + 15.221 + for(i=0; i<count; i++) { 15.222 + int r = (int)(unp->r * 255.0); 15.223 + int g = (int)(unp->g * 255.0); 15.224 + int b = (int)(unp->b * 255.0); 15.225 + int a = (int)(unp->a * 255.0); 15.226 + 15.227 + *pix++ = CLAMP(r, 0, 255); 15.228 + *pix++ = CLAMP(g, 0, 255); 15.229 + *pix++ = CLAMP(b, 0, 255); 15.230 + *pix++ = CLAMP(a, 0, 255); 15.231 + unp++; 15.232 + } 15.233 +} 15.234 + 15.235 +static void pack_greyf(void *pptr, struct pixel *unp, int count) 15.236 +{ 15.237 + int i; 15.238 + float *pix = pptr; 15.239 + 15.240 + for(i=0; i<count; i++) { 15.241 + *pix++ = (unp->r + unp->g + unp->b) / 3.0; 15.242 + unp++; 15.243 + } 15.244 +} 15.245 + 15.246 +static void pack_rgbf(void *pptr, struct pixel *unp, int count) 15.247 +{ 15.248 + int i; 15.249 + float *pix = pptr; 15.250 + 15.251 + for(i=0; i<count; i++) { 15.252 + *pix++ = unp->r; 15.253 + *pix++ = unp->g; 15.254 + *pix++ = unp->b; 15.255 + unp++; 15.256 + } 15.257 +} 15.258 + 15.259 +static void pack_rgbaf(void *pptr, struct pixel *unp, int count) 15.260 +{ 15.261 + memcpy(pptr, unp, count * sizeof *unp); 15.262 +} 15.263 +
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/libs/libimago/src/file_jpeg.c Fri Jul 18 05:07:40 2014 +0300 16.3 @@ -0,0 +1,294 @@ 16.4 +/* 16.5 +libimago - a multi-format image file input/output library. 16.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 16.7 + 16.8 +This program is free software: you can redistribute it and/or modify 16.9 +it under the terms of the GNU Lesser General Public License as published 16.10 +by the Free Software Foundation, either version 3 of the License, or 16.11 +(at your option) any later version. 16.12 + 16.13 +This program is distributed in the hope that it will be useful, 16.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 16.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16.16 +GNU Lesser General Public License for more details. 16.17 + 16.18 +You should have received a copy of the GNU Lesser General Public License 16.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 16.20 +*/ 16.21 + 16.22 +/* -- JPEG module -- */ 16.23 + 16.24 +#include <stdio.h> 16.25 +#include <stdlib.h> 16.26 +#include <string.h> 16.27 + 16.28 +#ifdef WIN32 16.29 +#include <windows.h> 16.30 +#define HAVE_BOOLEAN 16.31 +#endif 16.32 + 16.33 +#include <jpeglib.h> 16.34 +#include "imago2.h" 16.35 +#include "ftype_module.h" 16.36 + 16.37 +#define INPUT_BUF_SIZE 512 16.38 +#define OUTPUT_BUF_SIZE 512 16.39 + 16.40 +/* data source manager: adapted from jdatasrc.c */ 16.41 +struct src_mgr { 16.42 + struct jpeg_source_mgr pub; 16.43 + 16.44 + struct img_io *io; 16.45 + unsigned char buffer[INPUT_BUF_SIZE]; 16.46 + int start_of_file; 16.47 +}; 16.48 + 16.49 +/* data destination manager: adapted from jdatadst.c */ 16.50 +struct dst_mgr { 16.51 + struct jpeg_destination_mgr pub; 16.52 + 16.53 + struct img_io *io; 16.54 + unsigned char buffer[OUTPUT_BUF_SIZE]; 16.55 +}; 16.56 + 16.57 +static int check(struct img_io *io); 16.58 +static int read(struct img_pixmap *img, struct img_io *io); 16.59 +static int write(struct img_pixmap *img, struct img_io *io); 16.60 + 16.61 +/* read source functions */ 16.62 +static void init_source(j_decompress_ptr jd); 16.63 +static boolean fill_input_buffer(j_decompress_ptr jd); 16.64 +static void skip_input_data(j_decompress_ptr jd, long num_bytes); 16.65 +static void term_source(j_decompress_ptr jd); 16.66 + 16.67 +/* write destination functions */ 16.68 +static void init_destination(j_compress_ptr jc); 16.69 +static boolean empty_output_buffer(j_compress_ptr jc); 16.70 +static void term_destination(j_compress_ptr jc); 16.71 + 16.72 +int img_register_jpeg(void) 16.73 +{ 16.74 + static struct ftype_module mod = {".jpg", check, read, write}; 16.75 + return img_register_module(&mod); 16.76 +} 16.77 + 16.78 + 16.79 +static int check(struct img_io *io) 16.80 +{ 16.81 + unsigned char sig[10]; 16.82 + 16.83 + long pos = io->seek(0, SEEK_CUR, io->uptr); 16.84 + 16.85 + if(io->read(sig, 10, io->uptr) < 10) { 16.86 + io->seek(pos, SEEK_SET, io->uptr); 16.87 + return -1; 16.88 + } 16.89 + 16.90 + if(memcmp(sig, "\xff\xd8\xff\xe0", 4) != 0 && memcmp(sig, "\xff\xd8\xff\xe1", 4) != 0 16.91 + && memcmp(sig + 6, "JFIF", 4) != 0) { 16.92 + io->seek(pos, SEEK_SET, io->uptr); 16.93 + return -1; 16.94 + } 16.95 + io->seek(pos, SEEK_SET, io->uptr); 16.96 + return 0; 16.97 +} 16.98 + 16.99 +static int read(struct img_pixmap *img, struct img_io *io) 16.100 +{ 16.101 + int i, nlines = 0; 16.102 + struct jpeg_decompress_struct cinfo; 16.103 + struct jpeg_error_mgr jerr; 16.104 + struct src_mgr src; 16.105 + unsigned char **scanlines; 16.106 + 16.107 + io->seek(0, SEEK_CUR, io->uptr); 16.108 + 16.109 + cinfo.err = jpeg_std_error(&jerr); /* XXX change... */ 16.110 + jpeg_create_decompress(&cinfo); 16.111 + 16.112 + src.pub.init_source = init_source; 16.113 + src.pub.fill_input_buffer = fill_input_buffer; 16.114 + src.pub.skip_input_data = skip_input_data; 16.115 + src.pub.resync_to_restart = jpeg_resync_to_restart; 16.116 + src.pub.term_source = term_source; 16.117 + src.pub.next_input_byte = 0; 16.118 + src.pub.bytes_in_buffer = 0; 16.119 + src.io = io; 16.120 + cinfo.src = (struct jpeg_source_mgr*)&src; 16.121 + 16.122 + jpeg_read_header(&cinfo, 1); 16.123 + cinfo.out_color_space = JCS_RGB; 16.124 + 16.125 + if(img_set_pixels(img, cinfo.image_width, cinfo.image_height, IMG_FMT_RGB24, 0) == -1) { 16.126 + jpeg_destroy_decompress(&cinfo); 16.127 + return -1; 16.128 + } 16.129 + 16.130 + if(!(scanlines = malloc(img->height * sizeof *scanlines))) { 16.131 + jpeg_destroy_decompress(&cinfo); 16.132 + return -1; 16.133 + } 16.134 + scanlines[0] = img->pixels; 16.135 + for(i=1; i<img->height; i++) { 16.136 + scanlines[i] = scanlines[i - 1] + img->width * img->pixelsz; 16.137 + } 16.138 + 16.139 + jpeg_start_decompress(&cinfo); 16.140 + while(nlines < img->height) { 16.141 + int res = jpeg_read_scanlines(&cinfo, scanlines + nlines, img->height - nlines); 16.142 + nlines += res; 16.143 + } 16.144 + jpeg_finish_decompress(&cinfo); 16.145 + jpeg_destroy_decompress(&cinfo); 16.146 + 16.147 + free(scanlines); 16.148 + return 0; 16.149 +} 16.150 + 16.151 +static int write(struct img_pixmap *img, struct img_io *io) 16.152 +{ 16.153 + int i, nlines = 0; 16.154 + struct jpeg_compress_struct cinfo; 16.155 + struct jpeg_error_mgr jerr; 16.156 + struct dst_mgr dest; 16.157 + struct img_pixmap tmpimg; 16.158 + unsigned char **scanlines; 16.159 + 16.160 + img_init(&tmpimg); 16.161 + 16.162 + if(img->fmt != IMG_FMT_RGB24) { 16.163 + if(img_copy(&tmpimg, img) == -1) { 16.164 + return -1; 16.165 + } 16.166 + if(img_convert(&tmpimg, IMG_FMT_RGB24) == -1) { 16.167 + img_destroy(&tmpimg); 16.168 + return -1; 16.169 + } 16.170 + img = &tmpimg; 16.171 + } 16.172 + 16.173 + if(!(scanlines = malloc(img->height * sizeof *scanlines))) { 16.174 + img_destroy(&tmpimg); 16.175 + return -1; 16.176 + } 16.177 + scanlines[0] = img->pixels; 16.178 + for(i=1; i<img->height; i++) { 16.179 + scanlines[i] = scanlines[i - 1] + img->width * img->pixelsz; 16.180 + } 16.181 + 16.182 + cinfo.err = jpeg_std_error(&jerr); /* XXX */ 16.183 + jpeg_create_compress(&cinfo); 16.184 + 16.185 + dest.pub.init_destination = init_destination; 16.186 + dest.pub.empty_output_buffer = empty_output_buffer; 16.187 + dest.pub.term_destination = term_destination; 16.188 + dest.io = io; 16.189 + cinfo.dest = (struct jpeg_destination_mgr*)&dest; 16.190 + 16.191 + cinfo.image_width = img->width; 16.192 + cinfo.image_height = img->height; 16.193 + cinfo.input_components = 3; 16.194 + cinfo.in_color_space = JCS_RGB; 16.195 + 16.196 + jpeg_set_defaults(&cinfo); 16.197 + 16.198 + jpeg_start_compress(&cinfo, 1); 16.199 + while(nlines < img->height) { 16.200 + int res = jpeg_write_scanlines(&cinfo, scanlines + nlines, img->height - nlines); 16.201 + nlines += res; 16.202 + } 16.203 + jpeg_finish_compress(&cinfo); 16.204 + jpeg_destroy_compress(&cinfo); 16.205 + 16.206 + free(scanlines); 16.207 + img_destroy(&tmpimg); 16.208 + return 0; 16.209 +} 16.210 + 16.211 +/* -- read source functions -- 16.212 + * the following functions are adapted from jdatasrc.c in jpeglib 16.213 + */ 16.214 +static void init_source(j_decompress_ptr jd) 16.215 +{ 16.216 + struct src_mgr *src = (struct src_mgr*)jd->src; 16.217 + src->start_of_file = 1; 16.218 +} 16.219 + 16.220 +static boolean fill_input_buffer(j_decompress_ptr jd) 16.221 +{ 16.222 + struct src_mgr *src = (struct src_mgr*)jd->src; 16.223 + size_t nbytes; 16.224 + 16.225 + nbytes = src->io->read(src->buffer, INPUT_BUF_SIZE, src->io->uptr); 16.226 + 16.227 + if(nbytes <= 0) { 16.228 + if(src->start_of_file) { 16.229 + return 0; 16.230 + } 16.231 + /* insert a fake EOI marker */ 16.232 + src->buffer[0] = 0xff; 16.233 + src->buffer[1] = JPEG_EOI; 16.234 + nbytes = 2; 16.235 + } 16.236 + 16.237 + src->pub.next_input_byte = src->buffer; 16.238 + src->pub.bytes_in_buffer = nbytes; 16.239 + src->start_of_file = 0; 16.240 + return 1; 16.241 +} 16.242 + 16.243 +static void skip_input_data(j_decompress_ptr jd, long num_bytes) 16.244 +{ 16.245 + struct src_mgr *src = (struct src_mgr*)jd->src; 16.246 + 16.247 + if(num_bytes > 0) { 16.248 + while(num_bytes > (long)src->pub.bytes_in_buffer) { 16.249 + num_bytes -= (long)src->pub.bytes_in_buffer; 16.250 + fill_input_buffer(jd); 16.251 + } 16.252 + src->pub.next_input_byte += (size_t)num_bytes; 16.253 + src->pub.bytes_in_buffer -= (size_t)num_bytes; 16.254 + } 16.255 +} 16.256 + 16.257 +static void term_source(j_decompress_ptr jd) 16.258 +{ 16.259 + /* nothing to see here, move along */ 16.260 +} 16.261 + 16.262 + 16.263 +/* -- write destination functions -- 16.264 + * the following functions are adapted from jdatadst.c in jpeglib 16.265 + */ 16.266 +static void init_destination(j_compress_ptr jc) 16.267 +{ 16.268 + struct dst_mgr *dest = (struct dst_mgr*)jc->dest; 16.269 + 16.270 + dest->pub.next_output_byte = dest->buffer; 16.271 + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; 16.272 +} 16.273 + 16.274 +static boolean empty_output_buffer(j_compress_ptr jc) 16.275 +{ 16.276 + struct dst_mgr *dest = (struct dst_mgr*)jc->dest; 16.277 + 16.278 + if(dest->io->write(dest->buffer, OUTPUT_BUF_SIZE, dest->io->uptr) != OUTPUT_BUF_SIZE) { 16.279 + return 0; 16.280 + } 16.281 + 16.282 + dest->pub.next_output_byte = dest->buffer; 16.283 + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; 16.284 + return 1; 16.285 +} 16.286 + 16.287 +static void term_destination(j_compress_ptr jc) 16.288 +{ 16.289 + struct dst_mgr *dest = (struct dst_mgr*)jc->dest; 16.290 + size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; 16.291 + 16.292 + /* write any remaining data in the buffer */ 16.293 + if(datacount > 0) { 16.294 + dest->io->write(dest->buffer, datacount, dest->io->uptr); 16.295 + } 16.296 + /* XXX flush? ... */ 16.297 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/libs/libimago/src/file_png.c Fri Jul 18 05:07:40 2014 +0300 17.3 @@ -0,0 +1,261 @@ 17.4 +/* 17.5 +libimago - a multi-format image file input/output library. 17.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 17.7 + 17.8 +This program is free software: you can redistribute it and/or modify 17.9 +it under the terms of the GNU Lesser General Public License as published 17.10 +by the Free Software Foundation, either version 3 of the License, or 17.11 +(at your option) any later version. 17.12 + 17.13 +This program is distributed in the hope that it will be useful, 17.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 17.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17.16 +GNU Lesser General Public License for more details. 17.17 + 17.18 +You should have received a copy of the GNU Lesser General Public License 17.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 17.20 +*/ 17.21 + 17.22 +/* -- PNG module -- */ 17.23 + 17.24 +#include <stdlib.h> 17.25 +#include <png.h> 17.26 +#include "imago2.h" 17.27 +#include "ftype_module.h" 17.28 + 17.29 +static int check_file(struct img_io *io); 17.30 +static int read_file(struct img_pixmap *img, struct img_io *io); 17.31 +static int write_file(struct img_pixmap *img, struct img_io *io); 17.32 + 17.33 +static void read_func(png_struct *png, unsigned char *data, size_t len); 17.34 +static void write_func(png_struct *png, unsigned char *data, size_t len); 17.35 +static void flush_func(png_struct *png); 17.36 + 17.37 +static int png_type_to_fmt(int color_type, int channel_bits); 17.38 +static int fmt_to_png_type(enum img_fmt fmt); 17.39 + 17.40 + 17.41 +int img_register_png(void) 17.42 +{ 17.43 + static struct ftype_module mod = {".png", check_file, read_file, write_file}; 17.44 + return img_register_module(&mod); 17.45 +} 17.46 + 17.47 +static int check_file(struct img_io *io) 17.48 +{ 17.49 + unsigned char sig[8]; 17.50 + int res; 17.51 + long pos = io->seek(0, SEEK_CUR, io->uptr); 17.52 + 17.53 + if(io->read(sig, 8, io->uptr) < 8) { 17.54 + io->seek(pos, SEEK_SET, io->uptr); 17.55 + return -1; 17.56 + } 17.57 + 17.58 + res = png_sig_cmp(sig, 0, 8) == 0 ? 0 : -1; 17.59 + io->seek(pos, SEEK_SET, io->uptr); 17.60 + return res; 17.61 +} 17.62 + 17.63 +static int read_file(struct img_pixmap *img, struct img_io *io) 17.64 +{ 17.65 + png_struct *png; 17.66 + png_info *info; 17.67 + int channel_bits, color_type, ilace_type, compression, filtering, fmt; 17.68 + png_uint_32 xsz, ysz; 17.69 + 17.70 + if(!(png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) { 17.71 + return -1; 17.72 + } 17.73 + 17.74 + if(!(info = png_create_info_struct(png))) { 17.75 + png_destroy_read_struct(&png, 0, 0); 17.76 + return -1; 17.77 + } 17.78 + 17.79 + if(setjmp(png_jmpbuf(png))) { 17.80 + png_destroy_read_struct(&png, &info, 0); 17.81 + return -1; 17.82 + } 17.83 + 17.84 + png_set_read_fn(png, io, read_func); 17.85 + png_set_sig_bytes(png, 0); 17.86 + png_read_png(png, info, 0, 0); 17.87 + 17.88 + png_get_IHDR(png, info, &xsz, &ysz, &channel_bits, &color_type, &ilace_type, 17.89 + &compression, &filtering); 17.90 + if((fmt = png_type_to_fmt(color_type, channel_bits)) == -1) { 17.91 + png_destroy_read_struct(&png, &info, 0); 17.92 + return -1; 17.93 + } 17.94 + 17.95 + if(img_set_pixels(img, xsz, ysz, fmt, 0) == -1) { 17.96 + png_destroy_read_struct(&png, &info, 0); 17.97 + return -1; 17.98 + } 17.99 + 17.100 + 17.101 + if(channel_bits == 8) { 17.102 + unsigned int i; 17.103 + unsigned char **lineptr = (unsigned char**)png_get_rows(png, info); 17.104 + unsigned char *dest = img->pixels; 17.105 + 17.106 + for(i=0; i<ysz; i++) { 17.107 + memcpy(dest, lineptr[i], xsz * img->pixelsz); 17.108 + dest += xsz * img->pixelsz; 17.109 + } 17.110 + } else { 17.111 + unsigned int i, j, num_elem; 17.112 + unsigned char **lineptr = (unsigned char**)png_get_rows(png, info); 17.113 + float *dest = img->pixels; 17.114 + 17.115 + num_elem = img->pixelsz / sizeof(float); 17.116 + for(i=0; i<ysz; i++) { 17.117 + for(j=0; j<xsz * num_elem; j++) { 17.118 + unsigned short val = (lineptr[i][j * 2] << 8) | lineptr[i][j * 2 + 1]; 17.119 + *dest++ = (float)val / 65535.0; 17.120 + } 17.121 + } 17.122 + } 17.123 + 17.124 + 17.125 + png_destroy_read_struct(&png, &info, 0); 17.126 + return 0; 17.127 +} 17.128 + 17.129 + 17.130 +static int write_file(struct img_pixmap *img, struct img_io *io) 17.131 +{ 17.132 + png_struct *png; 17.133 + png_info *info; 17.134 + png_text txt; 17.135 + struct img_pixmap tmpimg; 17.136 + unsigned char **rows; 17.137 + unsigned char *pixptr; 17.138 + int i, coltype; 17.139 + 17.140 + img_init(&tmpimg); 17.141 + 17.142 + if(!(png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0))) { 17.143 + return -1; 17.144 + } 17.145 + if(!(info = png_create_info_struct(png))) { 17.146 + png_destroy_write_struct(&png, 0); 17.147 + return -1; 17.148 + } 17.149 + 17.150 + /* if the input image is floating-point, we need to convert it to integer */ 17.151 + if(img_is_float(img)) { 17.152 + if(img_copy(&tmpimg, img) == -1) { 17.153 + return -1; 17.154 + } 17.155 + if(img_to_integer(&tmpimg) == -1) { 17.156 + img_destroy(&tmpimg); 17.157 + return -1; 17.158 + } 17.159 + img = &tmpimg; 17.160 + } 17.161 + 17.162 + txt.compression = PNG_TEXT_COMPRESSION_NONE; 17.163 + txt.key = "Software"; 17.164 + txt.text = "libimago2"; 17.165 + txt.text_length = 0; 17.166 + 17.167 + if(setjmp(png_jmpbuf(png))) { 17.168 + png_destroy_write_struct(&png, &info); 17.169 + img_destroy(&tmpimg); 17.170 + return -1; 17.171 + } 17.172 + png_set_write_fn(png, io, write_func, flush_func); 17.173 + 17.174 + coltype = fmt_to_png_type(img->fmt); 17.175 + png_set_IHDR(png, info, img->width, img->height, 8, coltype, PNG_INTERLACE_NONE, 17.176 + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); 17.177 + png_set_text(png, info, &txt, 1); 17.178 + 17.179 + if(!(rows = malloc(img->height * sizeof *rows))) { 17.180 + png_destroy_write_struct(&png, &info); 17.181 + img_destroy(&tmpimg); 17.182 + return -1; 17.183 + } 17.184 + 17.185 + pixptr = img->pixels; 17.186 + for(i=0; i<img->height; i++) { 17.187 + rows[i] = pixptr; 17.188 + pixptr += img->width * img->pixelsz; 17.189 + } 17.190 + png_set_rows(png, info, rows); 17.191 + 17.192 + png_write_png(png, info, 0, 0); 17.193 + png_write_end(png, info); 17.194 + png_destroy_write_struct(&png, &info); 17.195 + 17.196 + free(rows); 17.197 + 17.198 + img_destroy(&tmpimg); 17.199 + return 0; 17.200 +} 17.201 + 17.202 +static void read_func(png_struct *png, unsigned char *data, size_t len) 17.203 +{ 17.204 + struct img_io *io = (struct img_io*)png_get_io_ptr(png); 17.205 + 17.206 + if(io->read(data, len, io->uptr) == -1) { 17.207 + longjmp(png_jmpbuf(png), 1); 17.208 + } 17.209 +} 17.210 + 17.211 +static void write_func(png_struct *png, unsigned char *data, size_t len) 17.212 +{ 17.213 + struct img_io *io = (struct img_io*)png_get_io_ptr(png); 17.214 + 17.215 + if(io->write(data, len, io->uptr) == -1) { 17.216 + longjmp(png_jmpbuf(png), 1); 17.217 + } 17.218 +} 17.219 + 17.220 +static void flush_func(png_struct *png) 17.221 +{ 17.222 + /* XXX does it matter that we can't flush? */ 17.223 +} 17.224 + 17.225 +static int png_type_to_fmt(int color_type, int channel_bits) 17.226 +{ 17.227 + /* only 8 and 16 bits per channel ar supported at the moment */ 17.228 + if(channel_bits != 8 && channel_bits != 16) { 17.229 + return -1; 17.230 + } 17.231 + 17.232 + switch(color_type) { 17.233 + case PNG_COLOR_TYPE_RGB: 17.234 + return channel_bits == 16 ? IMG_FMT_RGBF : IMG_FMT_RGB24; 17.235 + 17.236 + case PNG_COLOR_TYPE_RGB_ALPHA: 17.237 + return channel_bits == 16 ? IMG_FMT_RGBAF : IMG_FMT_RGBA32; 17.238 + 17.239 + case PNG_COLOR_TYPE_GRAY: 17.240 + return channel_bits == 16 ? IMG_FMT_GREYF : IMG_FMT_GREY8; 17.241 + 17.242 + default: 17.243 + break; 17.244 + } 17.245 + return -1; 17.246 +} 17.247 + 17.248 +static int fmt_to_png_type(enum img_fmt fmt) 17.249 +{ 17.250 + switch(fmt) { 17.251 + case IMG_FMT_GREY8: 17.252 + return PNG_COLOR_TYPE_GRAY; 17.253 + 17.254 + case IMG_FMT_RGB24: 17.255 + return PNG_COLOR_TYPE_RGB; 17.256 + 17.257 + case IMG_FMT_RGBA32: 17.258 + return PNG_COLOR_TYPE_RGBA; 17.259 + 17.260 + default: 17.261 + break; 17.262 + } 17.263 + return -1; 17.264 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/libs/libimago/src/file_ppm.c Fri Jul 18 05:07:40 2014 +0300 18.3 @@ -0,0 +1,153 @@ 18.4 +/* 18.5 +libimago - a multi-format image file input/output library. 18.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 18.7 + 18.8 +This program is free software: you can redistribute it and/or modify 18.9 +it under the terms of the GNU Lesser General Public License as published 18.10 +by the Free Software Foundation, either version 3 of the License, or 18.11 +(at your option) any later version. 18.12 + 18.13 +This program is distributed in the hope that it will be useful, 18.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 18.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18.16 +GNU Lesser General Public License for more details. 18.17 + 18.18 +You should have received a copy of the GNU Lesser General Public License 18.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 18.20 +*/ 18.21 + 18.22 +/* -- Portable Pixmap (PPM) module -- */ 18.23 + 18.24 +#include <string.h> 18.25 +#include "imago2.h" 18.26 +#include "ftype_module.h" 18.27 + 18.28 +static int check(struct img_io *io); 18.29 +static int read(struct img_pixmap *img, struct img_io *io); 18.30 +static int write(struct img_pixmap *img, struct img_io *io); 18.31 + 18.32 +int img_register_ppm(void) 18.33 +{ 18.34 + static struct ftype_module mod = {".ppm", check, read, write}; 18.35 + return img_register_module(&mod); 18.36 +} 18.37 + 18.38 + 18.39 +static int check(struct img_io *io) 18.40 +{ 18.41 + char id[2]; 18.42 + int res = -1; 18.43 + long pos = io->seek(0, SEEK_CUR, io->uptr); 18.44 + 18.45 + if(io->read(id, 2, io->uptr) < 2) { 18.46 + io->seek(pos, SEEK_SET, io->uptr); 18.47 + return -1; 18.48 + } 18.49 + 18.50 + if(id[0] == 'P' && (id[1] == '6' || id[1] == '3')) { 18.51 + res = 0; 18.52 + } 18.53 + io->seek(pos, SEEK_SET, io->uptr); 18.54 + return res; 18.55 +} 18.56 + 18.57 +static int iofgetc(struct img_io *io) 18.58 +{ 18.59 + char c; 18.60 + return io->read(&c, 1, io->uptr) < 1 ? -1 : c; 18.61 +} 18.62 + 18.63 +static char *iofgets(char *buf, int size, struct img_io *io) 18.64 +{ 18.65 + int c; 18.66 + char *ptr = buf; 18.67 + 18.68 + while(--size > 0 && (c = iofgetc(io)) != -1) { 18.69 + *ptr++ = c; 18.70 + if(c == '\n') break; 18.71 + } 18.72 + *ptr = 0; 18.73 + 18.74 + return ptr == buf ? 0 : buf; 18.75 +} 18.76 + 18.77 +/* TODO: implement P3 reading */ 18.78 +static int read(struct img_pixmap *img, struct img_io *io) 18.79 +{ 18.80 + char buf[256]; 18.81 + int xsz, ysz, maxval, got_hdrlines = 1; 18.82 + 18.83 + if(!iofgets(buf, sizeof buf, io)) { 18.84 + return -1; 18.85 + } 18.86 + if(!(buf[0] == 'P' && (buf[1] == '6' || buf[1] == '3'))) { 18.87 + return -1; 18.88 + } 18.89 + 18.90 + while(got_hdrlines < 3 && iofgets(buf, sizeof buf, io)) { 18.91 + if(buf[0] == '#') continue; 18.92 + 18.93 + switch(got_hdrlines) { 18.94 + case 1: 18.95 + if(sscanf(buf, "%d %d\n", &xsz, &ysz) < 2) { 18.96 + return -1; 18.97 + } 18.98 + break; 18.99 + 18.100 + case 2: 18.101 + if(sscanf(buf, "%d\n", &maxval) < 1) { 18.102 + return -1; 18.103 + } 18.104 + default: 18.105 + break; 18.106 + } 18.107 + got_hdrlines++; 18.108 + } 18.109 + 18.110 + if(xsz < 1 || ysz < 1 || maxval != 255) { 18.111 + return -1; 18.112 + } 18.113 + 18.114 + if(img_set_pixels(img, xsz, ysz, IMG_FMT_RGB24, 0) == -1) { 18.115 + return -1; 18.116 + } 18.117 + 18.118 + if(io->read(img->pixels, xsz * ysz * 3, io->uptr) < (unsigned int)(xsz * ysz * 3)) { 18.119 + return -1; 18.120 + } 18.121 + return 0; 18.122 +} 18.123 + 18.124 +static int write(struct img_pixmap *img, struct img_io *io) 18.125 +{ 18.126 + int sz; 18.127 + char buf[256]; 18.128 + struct img_pixmap tmpimg; 18.129 + 18.130 + img_init(&tmpimg); 18.131 + 18.132 + if(img->fmt != IMG_FMT_RGB24) { 18.133 + if(img_copy(&tmpimg, img) == -1) { 18.134 + return -1; 18.135 + } 18.136 + if(img_convert(&tmpimg, IMG_FMT_RGB24) == -1) { 18.137 + return -1; 18.138 + } 18.139 + img = &tmpimg; 18.140 + } 18.141 + 18.142 + sprintf(buf, "P6\n#written by libimago2\n%d %d\n255\n", img->width, img->height); 18.143 + if(io->write(buf, strlen(buf), io->uptr) < strlen(buf)) { 18.144 + img_destroy(&tmpimg); 18.145 + return -1; 18.146 + } 18.147 + 18.148 + sz = img->width * img->height * 3; 18.149 + if(io->write(img->pixels, sz, io->uptr) < (unsigned int)sz) { 18.150 + img_destroy(&tmpimg); 18.151 + return -1; 18.152 + } 18.153 + 18.154 + img_destroy(&tmpimg); 18.155 + return 0; 18.156 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/libs/libimago/src/file_rgbe.c Fri Jul 18 05:07:40 2014 +0300 19.3 @@ -0,0 +1,501 @@ 19.4 +/* This file contains code to read and write four byte rgbe file format 19.5 + * developed by Greg Ward. It handles the conversions between rgbe and 19.6 + * pixels consisting of floats. The data is assumed to be an array of floats. 19.7 + * By default there are three floats per pixel in the order red, green, blue. 19.8 + * (RGBE_DATA_??? values control this.) 19.9 + * 19.10 + * written by Bruce Walter (bjw@graphics.cornell.edu) 5/26/95 19.11 + * based on code written by Greg Ward 19.12 + * minor modifications by John Tsiombikas (nuclear@member.fsf.org) apr.9 2007 19.13 + */ 19.14 + 19.15 +#include <stdio.h> 19.16 +#include <stdlib.h> 19.17 +#include <string.h> 19.18 +#include <math.h> 19.19 +#include <ctype.h> 19.20 +#include <errno.h> 19.21 +#include "imago2.h" 19.22 +#include "ftype_module.h" 19.23 + 19.24 + 19.25 +typedef struct { 19.26 + int valid; /* indicate which fields are valid */ 19.27 + char programtype[16]; /* listed at beginning of file to identify it 19.28 + * after "#?". defaults to "RGBE" */ 19.29 + float gamma; /* image has already been gamma corrected with 19.30 + * given gamma. defaults to 1.0 (no correction) */ 19.31 + float exposure; /* a value of 1.0 in an image corresponds to 19.32 + * <exposure> watts/steradian/m^2. 19.33 + * defaults to 1.0 */ 19.34 +} rgbe_header_info; 19.35 + 19.36 + 19.37 +static int check(struct img_io *io); 19.38 +static int read(struct img_pixmap *img, struct img_io *io); 19.39 +static int write(struct img_pixmap *img, struct img_io *io); 19.40 + 19.41 +static int rgbe_read_header(struct img_io *io, int *width, int *height, rgbe_header_info * info); 19.42 +static int rgbe_read_pixels_rle(struct img_io *io, float *data, int scanline_width, int num_scanlines); 19.43 + 19.44 + 19.45 +int img_register_rgbe(void) 19.46 +{ 19.47 + static struct ftype_module mod = {".rgbe", check, read, write}; 19.48 + return img_register_module(&mod); 19.49 +} 19.50 + 19.51 + 19.52 +static int check(struct img_io *io) 19.53 +{ 19.54 + int xsz, ysz, res; 19.55 + long pos = io->seek(0, SEEK_CUR, io->uptr); 19.56 + 19.57 + rgbe_header_info hdr; 19.58 + res = rgbe_read_header(io, &xsz, &ysz, &hdr); 19.59 + 19.60 + io->seek(pos, SEEK_SET, io->uptr); 19.61 + return res; 19.62 +} 19.63 + 19.64 +static int read(struct img_pixmap *img, struct img_io *io) 19.65 +{ 19.66 + int xsz, ysz; 19.67 + rgbe_header_info hdr; 19.68 + 19.69 + if(rgbe_read_header(io, &xsz, &ysz, &hdr) == -1) { 19.70 + return -1; 19.71 + } 19.72 + 19.73 + if(img_set_pixels(img, xsz, ysz, IMG_FMT_RGBF, 0) == -1) { 19.74 + return -1; 19.75 + } 19.76 + if(rgbe_read_pixels_rle(io, img->pixels, xsz, ysz) == -1) { 19.77 + return -1; 19.78 + } 19.79 + return 0; 19.80 +} 19.81 + 19.82 +static int write(struct img_pixmap *img, struct img_io *io) 19.83 +{ 19.84 + return -1; /* TODO */ 19.85 +} 19.86 + 19.87 + 19.88 +static int iofgetc(struct img_io *io) 19.89 +{ 19.90 + char c; 19.91 + return io->read(&c, 1, io->uptr) < 1 ? -1 : c; 19.92 +} 19.93 + 19.94 +static char *iofgets(char *buf, int size, struct img_io *io) 19.95 +{ 19.96 + int c; 19.97 + char *ptr = buf; 19.98 + 19.99 + while(--size > 0 && (c = iofgetc(io)) != -1) { 19.100 + *ptr++ = c; 19.101 + if(c == '\n') break; 19.102 + } 19.103 + *ptr = 0; 19.104 + 19.105 + return ptr == buf ? 0 : buf; 19.106 +} 19.107 + 19.108 + 19.109 +/* flags indicating which fields in an rgbe_header_info are valid */ 19.110 +#define RGBE_VALID_PROGRAMTYPE 0x01 19.111 +#define RGBE_VALID_GAMMA 0x02 19.112 +#define RGBE_VALID_EXPOSURE 0x04 19.113 + 19.114 +/* return codes for rgbe routines */ 19.115 +#define RGBE_RETURN_SUCCESS 0 19.116 +#define RGBE_RETURN_FAILURE -1 19.117 + 19.118 + 19.119 +#if defined(__cplusplus) || defined(GNUC) || __STDC_VERSION >= 199901L 19.120 +#define INLINE inline 19.121 +#else 19.122 +#define INLINE 19.123 +#endif 19.124 + 19.125 +/* offsets to red, green, and blue components in a data (float) pixel */ 19.126 +#define RGBE_DATA_RED 0 19.127 +#define RGBE_DATA_GREEN 1 19.128 +#define RGBE_DATA_BLUE 2 19.129 + 19.130 +/* number of floats per pixel */ 19.131 +#define RGBE_DATA_SIZE 3 19.132 + 19.133 +enum rgbe_error_codes { 19.134 + rgbe_read_error, 19.135 + rgbe_write_error, 19.136 + rgbe_format_error, 19.137 + rgbe_memory_error 19.138 +}; 19.139 + 19.140 + 19.141 +/* default error routine. change this to change error handling */ 19.142 +static int rgbe_error(int rgbe_error_code, char *msg) 19.143 +{ 19.144 + switch (rgbe_error_code) { 19.145 + case rgbe_read_error: 19.146 + fprintf(stderr, "RGBE read error: %s\n", strerror(errno)); 19.147 + break; 19.148 + 19.149 + case rgbe_write_error: 19.150 + fprintf(stderr, "RGBE write error: %s\n", strerror(errno)); 19.151 + break; 19.152 + 19.153 + case rgbe_format_error: 19.154 + fprintf(stderr, "RGBE bad file format: %s\n", msg); 19.155 + break; 19.156 + 19.157 + default: 19.158 + case rgbe_memory_error: 19.159 + fprintf(stderr, "RGBE error: %s\n", msg); 19.160 + } 19.161 + return RGBE_RETURN_FAILURE; 19.162 +} 19.163 + 19.164 +/* standard conversion from float pixels to rgbe pixels */ 19.165 +/*static INLINE void float2rgbe(unsigned char rgbe[4], float red, float green, float blue) 19.166 +{ 19.167 + float v; 19.168 + int e; 19.169 + 19.170 + v = red; 19.171 + if(green > v) 19.172 + v = green; 19.173 + if(blue > v) 19.174 + v = blue; 19.175 + if(v < 1e-32) { 19.176 + rgbe[0] = rgbe[1] = rgbe[2] = rgbe[3] = 0; 19.177 + } else { 19.178 + v = frexp(v, &e) * 256.0 / v; 19.179 + rgbe[0] = (unsigned char)(red * v); 19.180 + rgbe[1] = (unsigned char)(green * v); 19.181 + rgbe[2] = (unsigned char)(blue * v); 19.182 + rgbe[3] = (unsigned char)(e + 128); 19.183 + } 19.184 +}*/ 19.185 + 19.186 +/* standard conversion from rgbe to float pixels */ 19.187 +/* note: Ward uses ldexp(col+0.5,exp-(128+8)). However we wanted pixels */ 19.188 +/* in the range [0,1] to map back into the range [0,1]. */ 19.189 +static INLINE void rgbe2float(float *red, float *green, float *blue, unsigned char rgbe[4]) 19.190 +{ 19.191 + float f; 19.192 + 19.193 + if(rgbe[3]) { /*nonzero pixel */ 19.194 + f = ldexp(1.0, rgbe[3] - (int)(128 + 8)); 19.195 + *red = rgbe[0] * f; 19.196 + *green = rgbe[1] * f; 19.197 + *blue = rgbe[2] * f; 19.198 + } else 19.199 + *red = *green = *blue = 0.0; 19.200 +} 19.201 + 19.202 +#if 0 19.203 +/* default minimal header. modify if you want more information in header */ 19.204 +static int rgbe_write_header(FILE * fp, int width, int height, rgbe_header_info * info) 19.205 +{ 19.206 + char *programtype = "RGBE"; 19.207 + 19.208 + if(info && (info->valid & RGBE_VALID_PROGRAMTYPE)) 19.209 + programtype = info->programtype; 19.210 + if(fprintf(fp, "#?%s\n", programtype) < 0) 19.211 + return rgbe_error(rgbe_write_error, NULL); 19.212 + /* The #? is to identify file type, the programtype is optional. */ 19.213 + if(info && (info->valid & RGBE_VALID_GAMMA)) { 19.214 + if(fprintf(fp, "GAMMA=%g\n", info->gamma) < 0) 19.215 + return rgbe_error(rgbe_write_error, NULL); 19.216 + } 19.217 + if(info && (info->valid & RGBE_VALID_EXPOSURE)) { 19.218 + if(fprintf(fp, "EXPOSURE=%g\n", info->exposure) < 0) 19.219 + return rgbe_error(rgbe_write_error, NULL); 19.220 + } 19.221 + if(fprintf(fp, "FORMAT=32-bit_rle_rgbe\n\n") < 0) 19.222 + return rgbe_error(rgbe_write_error, NULL); 19.223 + if(fprintf(fp, "-Y %d +X %d\n", height, width) < 0) 19.224 + return rgbe_error(rgbe_write_error, NULL); 19.225 + return RGBE_RETURN_SUCCESS; 19.226 +} 19.227 +#endif 19.228 + 19.229 +/* minimal header reading. modify if you want to parse more information */ 19.230 +static int rgbe_read_header(struct img_io *io, int *width, int *height, rgbe_header_info * info) 19.231 +{ 19.232 + char buf[128]; 19.233 + float tempf; 19.234 + int i; 19.235 + 19.236 + if(info) { 19.237 + info->valid = 0; 19.238 + info->programtype[0] = 0; 19.239 + info->gamma = info->exposure = 1.0; 19.240 + } 19.241 + if(iofgets(buf, sizeof(buf) / sizeof(buf[0]), io) == NULL) 19.242 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_read_error, NULL);*/ 19.243 + if((buf[0] != '#') || (buf[1] != '?')) { 19.244 + /* if you want to require the magic token then uncomment the next line */ 19.245 + /*return rgbe_error(rgbe_format_error,"bad initial token"); */ 19.246 + } else if(info) { 19.247 + info->valid |= RGBE_VALID_PROGRAMTYPE; 19.248 + for(i = 0; i < sizeof(info->programtype) - 1; i++) { 19.249 + if((buf[i + 2] == 0) || isspace(buf[i + 2])) 19.250 + break; 19.251 + info->programtype[i] = buf[i + 2]; 19.252 + } 19.253 + info->programtype[i] = 0; 19.254 + if(iofgets(buf, sizeof(buf) / sizeof(buf[0]), io) == 0) 19.255 + return rgbe_error(rgbe_read_error, NULL); 19.256 + } 19.257 + for(;;) { 19.258 + if((buf[0] == 0) || (buf[0] == '\n')) 19.259 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_format_error, "no FORMAT specifier found");*/ 19.260 + else if(strcmp(buf, "FORMAT=32-bit_rle_rgbe\n") == 0) 19.261 + break; /* format found so break out of loop */ 19.262 + else if(info && (sscanf(buf, "GAMMA=%g", &tempf) == 1)) { 19.263 + info->gamma = tempf; 19.264 + info->valid |= RGBE_VALID_GAMMA; 19.265 + } else if(info && (sscanf(buf, "EXPOSURE=%g", &tempf) == 1)) { 19.266 + info->exposure = tempf; 19.267 + info->valid |= RGBE_VALID_EXPOSURE; 19.268 + } 19.269 + if(iofgets(buf, sizeof(buf) / sizeof(buf[0]), io) == 0) 19.270 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_read_error, NULL);*/ 19.271 + } 19.272 + if(iofgets(buf, sizeof(buf) / sizeof(buf[0]), io) == 0) 19.273 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_read_error, NULL);*/ 19.274 + if(strcmp(buf, "\n") != 0) 19.275 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_format_error, "missing blank line after FORMAT specifier");*/ 19.276 + if(iofgets(buf, sizeof(buf) / sizeof(buf[0]), io) == 0) 19.277 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_read_error, NULL);*/ 19.278 + if(sscanf(buf, "-Y %d +X %d", height, width) < 2) 19.279 + return RGBE_RETURN_FAILURE;/*rgbe_error(rgbe_format_error, "missing image size specifier");*/ 19.280 + return RGBE_RETURN_SUCCESS; 19.281 +} 19.282 + 19.283 +#if 0 19.284 +/* simple write routine that does not use run length encoding */ 19.285 + 19.286 +/* These routines can be made faster by allocating a larger buffer and 19.287 + fread-ing and fwrite-ing the data in larger chunks */ 19.288 +static int rgbe_write_pixels(FILE * fp, float *data, int numpixels) 19.289 +{ 19.290 + unsigned char rgbe[4]; 19.291 + 19.292 + while(numpixels-- > 0) { 19.293 + float2rgbe(rgbe, data[RGBE_DATA_RED], data[RGBE_DATA_GREEN], data[RGBE_DATA_BLUE]); 19.294 + data += RGBE_DATA_SIZE; 19.295 + if(fwrite(rgbe, sizeof(rgbe), 1, fp) < 1) 19.296 + return rgbe_error(rgbe_write_error, NULL); 19.297 + } 19.298 + return RGBE_RETURN_SUCCESS; 19.299 +} 19.300 +#endif 19.301 + 19.302 +/* simple read routine. will not correctly handle run length encoding */ 19.303 +static int rgbe_read_pixels(struct img_io *io, float *data, int numpixels) 19.304 +{ 19.305 + unsigned char rgbe[4]; 19.306 + 19.307 + while(numpixels-- > 0) { 19.308 + if(io->read(rgbe, sizeof(rgbe), io->uptr) < 1) 19.309 + return rgbe_error(rgbe_read_error, NULL); 19.310 + rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe); 19.311 + data += RGBE_DATA_SIZE; 19.312 + } 19.313 + return RGBE_RETURN_SUCCESS; 19.314 +} 19.315 + 19.316 +#if 0 19.317 +/* The code below is only needed for the run-length encoded files. */ 19.318 + 19.319 +/* Run length encoding adds considerable complexity but does */ 19.320 + 19.321 +/* save some space. For each scanline, each channel (r,g,b,e) is */ 19.322 + 19.323 +/* encoded separately for better compression. */ 19.324 + 19.325 +static int rgbe_write_bytes_rle(struct img_io *io, unsigned char *data, int numbytes) 19.326 +{ 19.327 +#define MINRUNLENGTH 4 19.328 + int cur, beg_run, run_count, old_run_count, nonrun_count; 19.329 + unsigned char buf[2]; 19.330 + 19.331 + cur = 0; 19.332 + while(cur < numbytes) { 19.333 + beg_run = cur; 19.334 + /* find next run of length at least 4 if one exists */ 19.335 + run_count = old_run_count = 0; 19.336 + while((run_count < MINRUNLENGTH) && (beg_run < numbytes)) { 19.337 + beg_run += run_count; 19.338 + old_run_count = run_count; 19.339 + run_count = 1; 19.340 + while((beg_run + run_count < numbytes) && (run_count < 127) 19.341 + && (data[beg_run] == data[beg_run + run_count])) 19.342 + run_count++; 19.343 + } 19.344 + /* if data before next big run is a short run then write it as such */ 19.345 + if((old_run_count > 1) && (old_run_count == beg_run - cur)) { 19.346 + buf[0] = 128 + old_run_count; /*write short run */ 19.347 + buf[1] = data[cur]; 19.348 + if(fwrite(buf, sizeof(buf[0]) * 2, 1, fp) < 1) 19.349 + return rgbe_error(rgbe_write_error, NULL); 19.350 + cur = beg_run; 19.351 + } 19.352 + /* write out bytes until we reach the start of the next run */ 19.353 + while(cur < beg_run) { 19.354 + nonrun_count = beg_run - cur; 19.355 + if(nonrun_count > 128) 19.356 + nonrun_count = 128; 19.357 + buf[0] = nonrun_count; 19.358 + if(fwrite(buf, sizeof(buf[0]), 1, fp) < 1) 19.359 + return rgbe_error(rgbe_write_error, NULL); 19.360 + if(fwrite(&data[cur], sizeof(data[0]) * nonrun_count, 1, fp) < 1) 19.361 + return rgbe_error(rgbe_write_error, NULL); 19.362 + cur += nonrun_count; 19.363 + } 19.364 + /* write out next run if one was found */ 19.365 + if(run_count >= MINRUNLENGTH) { 19.366 + buf[0] = 128 + run_count; 19.367 + buf[1] = data[beg_run]; 19.368 + if(fwrite(buf, sizeof(buf[0]) * 2, 1, fp) < 1) 19.369 + return rgbe_error(rgbe_write_error, NULL); 19.370 + cur += run_count; 19.371 + } 19.372 + } 19.373 + return RGBE_RETURN_SUCCESS; 19.374 +#undef MINRUNLENGTH 19.375 +} 19.376 + 19.377 +static int rgbe_write_pixels_rle(struct img_io *io, float *data, int scanline_width, int num_scanlines) 19.378 +{ 19.379 + unsigned char rgbe[4]; 19.380 + unsigned char *buffer; 19.381 + int i, err; 19.382 + 19.383 + if((scanline_width < 8) || (scanline_width > 0x7fff)) 19.384 + /* run length encoding is not allowed so write flat */ 19.385 + return rgbe_write_pixels(io, data, scanline_width * num_scanlines); 19.386 + buffer = (unsigned char *)malloc(sizeof(unsigned char) * 4 * scanline_width); 19.387 + if(buffer == NULL) 19.388 + /* no buffer space so write flat */ 19.389 + return rgbe_write_pixels(fp, data, scanline_width * num_scanlines); 19.390 + while(num_scanlines-- > 0) { 19.391 + rgbe[0] = 2; 19.392 + rgbe[1] = 2; 19.393 + rgbe[2] = scanline_width >> 8; 19.394 + rgbe[3] = scanline_width & 0xFF; 19.395 + if(fwrite(rgbe, sizeof(rgbe), 1, fp) < 1) { 19.396 + free(buffer); 19.397 + return rgbe_error(rgbe_write_error, NULL); 19.398 + } 19.399 + for(i = 0; i < scanline_width; i++) { 19.400 + float2rgbe(rgbe, data[RGBE_DATA_RED], data[RGBE_DATA_GREEN], data[RGBE_DATA_BLUE]); 19.401 + buffer[i] = rgbe[0]; 19.402 + buffer[i + scanline_width] = rgbe[1]; 19.403 + buffer[i + 2 * scanline_width] = rgbe[2]; 19.404 + buffer[i + 3 * scanline_width] = rgbe[3]; 19.405 + data += RGBE_DATA_SIZE; 19.406 + } 19.407 + /* write out each of the four channels separately run length encoded */ 19.408 + /* first red, then green, then blue, then exponent */ 19.409 + for(i = 0; i < 4; i++) { 19.410 + if((err = rgbe_write_bytes_rle(fp, &buffer[i * scanline_width], 19.411 + scanline_width)) != RGBE_RETURN_SUCCESS) { 19.412 + free(buffer); 19.413 + return err; 19.414 + } 19.415 + } 19.416 + } 19.417 + free(buffer); 19.418 + return RGBE_RETURN_SUCCESS; 19.419 +} 19.420 +#endif 19.421 + 19.422 +static int rgbe_read_pixels_rle(struct img_io *io, float *data, int scanline_width, int num_scanlines) 19.423 +{ 19.424 + unsigned char rgbe[4], *scanline_buffer, *ptr, *ptr_end; 19.425 + int i, count; 19.426 + unsigned char buf[2]; 19.427 + 19.428 + if((scanline_width < 8) || (scanline_width > 0x7fff)) 19.429 + /* run length encoding is not allowed so read flat */ 19.430 + return rgbe_read_pixels(io, data, scanline_width * num_scanlines); 19.431 + scanline_buffer = NULL; 19.432 + /* read in each successive scanline */ 19.433 + while(num_scanlines > 0) { 19.434 + if(io->read(rgbe, sizeof(rgbe), io->uptr) < 1) { 19.435 + free(scanline_buffer); 19.436 + return rgbe_error(rgbe_read_error, NULL); 19.437 + } 19.438 + if((rgbe[0] != 2) || (rgbe[1] != 2) || (rgbe[2] & 0x80)) { 19.439 + /* this file is not run length encoded */ 19.440 + rgbe2float(&data[0], &data[1], &data[2], rgbe); 19.441 + data += RGBE_DATA_SIZE; 19.442 + free(scanline_buffer); 19.443 + return rgbe_read_pixels(io, data, scanline_width * num_scanlines - 1); 19.444 + } 19.445 + if((((int)rgbe[2]) << 8 | rgbe[3]) != scanline_width) { 19.446 + free(scanline_buffer); 19.447 + return rgbe_error(rgbe_format_error, "wrong scanline width"); 19.448 + } 19.449 + if(scanline_buffer == NULL) 19.450 + scanline_buffer = (unsigned char *) 19.451 + malloc(sizeof(unsigned char) * 4 * scanline_width); 19.452 + if(scanline_buffer == NULL) 19.453 + return rgbe_error(rgbe_memory_error, "unable to allocate buffer space"); 19.454 + 19.455 + ptr = &scanline_buffer[0]; 19.456 + /* read each of the four channels for the scanline into the buffer */ 19.457 + for(i = 0; i < 4; i++) { 19.458 + ptr_end = &scanline_buffer[(i + 1) * scanline_width]; 19.459 + while(ptr < ptr_end) { 19.460 + if(io->read(buf, sizeof(buf[0]) * 2, io->uptr) < 1) { 19.461 + free(scanline_buffer); 19.462 + return rgbe_error(rgbe_read_error, NULL); 19.463 + } 19.464 + if(buf[0] > 128) { 19.465 + /* a run of the same value */ 19.466 + count = buf[0] - 128; 19.467 + if((count == 0) || (count > ptr_end - ptr)) { 19.468 + free(scanline_buffer); 19.469 + return rgbe_error(rgbe_format_error, "bad scanline data"); 19.470 + } 19.471 + while(count-- > 0) 19.472 + *ptr++ = buf[1]; 19.473 + } else { 19.474 + /* a non-run */ 19.475 + count = buf[0]; 19.476 + if((count == 0) || (count > ptr_end - ptr)) { 19.477 + free(scanline_buffer); 19.478 + return rgbe_error(rgbe_format_error, "bad scanline data"); 19.479 + } 19.480 + *ptr++ = buf[1]; 19.481 + if(--count > 0) { 19.482 + if(io->read(ptr, sizeof(*ptr) * count, io->uptr) < 1) { 19.483 + free(scanline_buffer); 19.484 + return rgbe_error(rgbe_read_error, NULL); 19.485 + } 19.486 + ptr += count; 19.487 + } 19.488 + } 19.489 + } 19.490 + } 19.491 + /* now convert data from buffer into floats */ 19.492 + for(i = 0; i < scanline_width; i++) { 19.493 + rgbe[0] = scanline_buffer[i]; 19.494 + rgbe[1] = scanline_buffer[i + scanline_width]; 19.495 + rgbe[2] = scanline_buffer[i + 2 * scanline_width]; 19.496 + rgbe[3] = scanline_buffer[i + 3 * scanline_width]; 19.497 + rgbe2float(&data[RGBE_DATA_RED], &data[RGBE_DATA_GREEN], &data[RGBE_DATA_BLUE], rgbe); 19.498 + data += RGBE_DATA_SIZE; 19.499 + } 19.500 + num_scanlines--; 19.501 + } 19.502 + free(scanline_buffer); 19.503 + return RGBE_RETURN_SUCCESS; 19.504 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/libs/libimago/src/ftype_module.c Fri Jul 18 05:07:40 2014 +0300 20.3 @@ -0,0 +1,118 @@ 20.4 +/* 20.5 +libimago - a multi-format image file input/output library. 20.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 20.7 + 20.8 +This program is free software: you can redistribute it and/or modify 20.9 +it under the terms of the GNU Lesser General Public License as published 20.10 +by the Free Software Foundation, either version 3 of the License, or 20.11 +(at your option) any later version. 20.12 + 20.13 +This program is distributed in the hope that it will be useful, 20.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 20.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20.16 +GNU Lesser General Public License for more details. 20.17 + 20.18 +You should have received a copy of the GNU Lesser General Public License 20.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 20.20 +*/ 20.21 + 20.22 +#include <stdlib.h> 20.23 +#include <string.h> 20.24 +#include "ftype_module.h" 20.25 + 20.26 +static struct list_node { 20.27 + struct ftype_module *module; 20.28 + struct list_node *next; 20.29 +} *modules; 20.30 + 20.31 +/* defined in modules.c which is generated by configure */ 20.32 +void img_modules_init(); 20.33 + 20.34 +static int done_init; 20.35 + 20.36 +int img_register_module(struct ftype_module *mod) 20.37 +{ 20.38 + struct list_node *node; 20.39 + 20.40 + if(!(node = malloc(sizeof *node))) { 20.41 + return -1; 20.42 + } 20.43 + 20.44 + node->module = mod; 20.45 + node->next = modules; 20.46 + modules = node; 20.47 + return 0; 20.48 +} 20.49 + 20.50 +struct ftype_module *img_find_format_module(struct img_io *io) 20.51 +{ 20.52 + struct list_node *node; 20.53 + 20.54 + if(!done_init) { 20.55 + img_modules_init(); 20.56 + done_init = 1; 20.57 + } 20.58 + 20.59 + node = modules; 20.60 + while(node) { 20.61 + if(node->module->check(io) != -1) { 20.62 + return node->module; 20.63 + } 20.64 + node = node->next; 20.65 + } 20.66 + return 0; 20.67 +} 20.68 + 20.69 +struct ftype_module *img_guess_format(const char *fname) 20.70 +{ 20.71 + struct list_node *node; 20.72 + char *suffix; 20.73 + int suffix_len; 20.74 + 20.75 + if(!done_init) { 20.76 + img_modules_init(); 20.77 + done_init = 1; 20.78 + } 20.79 + 20.80 + if(!(suffix = strrchr(fname, '.'))) { 20.81 + return 0; /* no suffix, can't guess ... */ 20.82 + } 20.83 + suffix_len = (int)strlen(suffix); 20.84 + 20.85 + node = modules; 20.86 + while(node) { 20.87 + char *suflist = node->module->suffix; 20.88 + char *start, *end; 20.89 + 20.90 + while(*suflist) { 20.91 + if(!(start = strstr(suflist, suffix))) { 20.92 + break; 20.93 + } 20.94 + end = start + suffix_len; 20.95 + 20.96 + if(*end == ':' || *end == 0) { 20.97 + return node->module; /* found it */ 20.98 + } 20.99 + suflist = end; 20.100 + } 20.101 + 20.102 + node = node->next; 20.103 + } 20.104 + return 0; 20.105 +} 20.106 + 20.107 +struct ftype_module *img_get_module(int idx) 20.108 +{ 20.109 + struct list_node *node; 20.110 + 20.111 + if(!done_init) { 20.112 + img_modules_init(); 20.113 + done_init = 1; 20.114 + } 20.115 + 20.116 + node = modules; 20.117 + while(node && idx--) { 20.118 + node = node->next; 20.119 + } 20.120 + return node->module; 20.121 +}
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/libs/libimago/src/ftype_module.h Fri Jul 18 05:07:40 2014 +0300 21.3 @@ -0,0 +1,39 @@ 21.4 +/* 21.5 +libimago - a multi-format image file input/output library. 21.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 21.7 + 21.8 +This program is free software: you can redistribute it and/or modify 21.9 +it under the terms of the GNU Lesser General Public License as published 21.10 +by the Free Software Foundation, either version 3 of the License, or 21.11 +(at your option) any later version. 21.12 + 21.13 +This program is distributed in the hope that it will be useful, 21.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 21.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21.16 +GNU Lesser General Public License for more details. 21.17 + 21.18 +You should have received a copy of the GNU Lesser General Public License 21.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 21.20 +*/ 21.21 + 21.22 +#ifndef FTYPE_MODULE_H_ 21.23 +#define FTYPE_MODULE_H_ 21.24 + 21.25 +#include "imago2.h" 21.26 + 21.27 +struct ftype_module { 21.28 + char *suffix; /* used for format autodetection during saving only */ 21.29 + 21.30 + int (*check)(struct img_io *io); 21.31 + int (*read)(struct img_pixmap *img, struct img_io *io); 21.32 + int (*write)(struct img_pixmap *img, struct img_io *io); 21.33 +}; 21.34 + 21.35 +int img_register_module(struct ftype_module *mod); 21.36 + 21.37 +struct ftype_module *img_find_format_module(struct img_io *io); 21.38 +struct ftype_module *img_guess_format(const char *fname); 21.39 +struct ftype_module *img_get_module(int idx); 21.40 + 21.41 + 21.42 +#endif /* FTYPE_MODULE_H_ */
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/libs/libimago/src/imago2.c Fri Jul 18 05:07:40 2014 +0300 22.3 @@ -0,0 +1,449 @@ 22.4 +/* 22.5 +libimago - a multi-format image file input/output library. 22.6 +Copyright (C) 2010 John Tsiombikas <nuclear@member.fsf.org> 22.7 + 22.8 +This program is free software: you can redistribute it and/or modify 22.9 +it under the terms of the GNU Lesser General Public License as published 22.10 +by the Free Software Foundation, either version 3 of the License, or 22.11 +(at your option) any later version. 22.12 + 22.13 +This program is distributed in the hope that it will be useful, 22.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 22.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22.16 +GNU Lesser General Public License for more details. 22.17 + 22.18 +You should have received a copy of the GNU Lesser General Public License 22.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 22.20 +*/ 22.21 + 22.22 +#include <stdio.h> 22.23 +#include <stdlib.h> 22.24 +#include <string.h> 22.25 +#include "imago2.h" 22.26 +#include "ftype_module.h" 22.27 + 22.28 +static int pixel_size(enum img_fmt fmt); 22.29 +static size_t def_read(void *buf, size_t bytes, void *uptr); 22.30 +static size_t def_write(void *buf, size_t bytes, void *uptr); 22.31 +static long def_seek(long offset, int whence, void *uptr); 22.32 + 22.33 + 22.34 +void img_init(struct img_pixmap *img) 22.35 +{ 22.36 + img->pixels = 0; 22.37 + img->width = img->height = 0; 22.38 + img->fmt = IMG_FMT_RGBA32; 22.39 + img->pixelsz = pixel_size(img->fmt); 22.40 + img->name = 0; 22.41 +} 22.42 + 22.43 + 22.44 +void img_destroy(struct img_pixmap *img) 22.45 +{ 22.46 + free(img->pixels); 22.47 + img->pixels = 0; /* just in case... */ 22.48 + img->width = img->height = 0xbadbeef; 22.49 + free(img->name); 22.50 +} 22.51 + 22.52 +struct img_pixmap *img_create(void) 22.53 +{ 22.54 + struct img_pixmap *p; 22.55 + 22.56 + if(!(p = malloc(sizeof *p))) { 22.57 + return 0; 22.58 + } 22.59 + img_init(p); 22.60 + return p; 22.61 +} 22.62 + 22.63 +void img_free(struct img_pixmap *img) 22.64 +{ 22.65 + img_destroy(img); 22.66 + free(img); 22.67 +} 22.68 + 22.69 +int img_set_name(struct img_pixmap *img, const char *name) 22.70 +{ 22.71 + char *tmp; 22.72 + 22.73 + if(!(tmp = malloc(strlen(name) + 1))) { 22.74 + return -1; 22.75 + } 22.76 + strcpy(tmp, name); 22.77 + img->name = tmp; 22.78 + return 0; 22.79 +} 22.80 + 22.81 +int img_set_format(struct img_pixmap *img, enum img_fmt fmt) 22.82 +{ 22.83 + if(img->pixels) { 22.84 + return img_convert(img, fmt); 22.85 + } 22.86 + img->fmt = fmt; 22.87 + return 0; 22.88 +} 22.89 + 22.90 +int img_copy(struct img_pixmap *dest, struct img_pixmap *src) 22.91 +{ 22.92 + return img_set_pixels(dest, src->width, src->height, src->fmt, src->pixels); 22.93 +} 22.94 + 22.95 +int img_set_pixels(struct img_pixmap *img, int w, int h, enum img_fmt fmt, void *pix) 22.96 +{ 22.97 + void *newpix; 22.98 + int pixsz = pixel_size(fmt); 22.99 + 22.100 + if(!(newpix = malloc(w * h * pixsz))) { 22.101 + return -1; 22.102 + } 22.103 + 22.104 + if(pix) { 22.105 + memcpy(newpix, pix, w * h * pixsz); 22.106 + } else { 22.107 + memset(newpix, 0, w * h * pixsz); 22.108 + } 22.109 + 22.110 + free(img->pixels); 22.111 + img->pixels = newpix; 22.112 + img->width = w; 22.113 + img->height = h; 22.114 + img->pixelsz = pixsz; 22.115 + img->fmt = fmt; 22.116 + return 0; 22.117 +} 22.118 + 22.119 +void *img_load_pixels(const char *fname, int *xsz, int *ysz, enum img_fmt fmt) 22.120 +{ 22.121 + struct img_pixmap img; 22.122 + 22.123 + img_init(&img); 22.124 + 22.125 + if(img_load(&img, fname) == -1) { 22.126 + return 0; 22.127 + } 22.128 + if(img.fmt != fmt) { 22.129 + if(img_convert(&img, fmt) == -1) { 22.130 + img_destroy(&img); 22.131 + return 0; 22.132 + } 22.133 + } 22.134 + 22.135 + *xsz = img.width; 22.136 + *ysz = img.height; 22.137 + return img.pixels; 22.138 +} 22.139 + 22.140 +int img_save_pixels(const char *fname, void *pix, int xsz, int ysz, enum img_fmt fmt) 22.141 +{ 22.142 + struct img_pixmap img; 22.143 + 22.144 + img_init(&img); 22.145 + img.fmt = fmt; 22.146 + img.name = (char*)fname; 22.147 + img.width = xsz; 22.148 + img.height = ysz; 22.149 + img.pixels = pix; 22.150 + 22.151 + return img_save(&img, fname); 22.152 +} 22.153 + 22.154 +void img_free_pixels(void *pix) 22.155 +{ 22.156 + free(pix); 22.157 +} 22.158 + 22.159 +int img_load(struct img_pixmap *img, const char *fname) 22.160 +{ 22.161 + int res; 22.162 + FILE *fp; 22.163 + 22.164 + if(!(fp = fopen(fname, "rb"))) { 22.165 + return -1; 22.166 + } 22.167 + res = img_read_file(img, fp); 22.168 + fclose(fp); 22.169 + return res; 22.170 +} 22.171 + 22.172 +/* TODO implement filetype selection */ 22.173 +int img_save(struct img_pixmap *img, const char *fname) 22.174 +{ 22.175 + int res; 22.176 + FILE *fp; 22.177 + 22.178 + img_set_name(img, fname); 22.179 + 22.180 + if(!(fp = fopen(fname, "wb"))) { 22.181 + return -1; 22.182 + } 22.183 + res = img_write_file(img, fp); 22.184 + fclose(fp); 22.185 + return res; 22.186 +} 22.187 + 22.188 +int img_read_file(struct img_pixmap *img, FILE *fp) 22.189 +{ 22.190 + struct img_io io = {0, def_read, def_write, def_seek}; 22.191 + 22.192 + io.uptr = fp; 22.193 + return img_read(img, &io); 22.194 +} 22.195 + 22.196 +int img_write_file(struct img_pixmap *img, FILE *fp) 22.197 +{ 22.198 + struct img_io io = {0, def_read, def_write, def_seek}; 22.199 + 22.200 + io.uptr = fp; 22.201 + return img_write(img, &io); 22.202 +} 22.203 + 22.204 +int img_read(struct img_pixmap *img, struct img_io *io) 22.205 +{ 22.206 + struct ftype_module *mod; 22.207 + 22.208 + if((mod = img_find_format_module(io))) { 22.209 + return mod->read(img, io); 22.210 + } 22.211 + return -1; 22.212 +} 22.213 + 22.214 +int img_write(struct img_pixmap *img, struct img_io *io) 22.215 +{ 22.216 + struct ftype_module *mod; 22.217 + 22.218 + if(!img->name || !(mod = img_guess_format(img->name))) { 22.219 + /* TODO throw some sort of warning? */ 22.220 + /* TODO implement some sort of module priority or let the user specify? */ 22.221 + if(!(mod = img_get_module(0))) { 22.222 + return -1; 22.223 + } 22.224 + } 22.225 + 22.226 + return mod->write(img, io); 22.227 +} 22.228 + 22.229 +int img_to_float(struct img_pixmap *img) 22.230 +{ 22.231 + enum img_fmt targ_fmt; 22.232 + 22.233 + switch(img->fmt) { 22.234 + case IMG_FMT_GREY8: 22.235 + targ_fmt = IMG_FMT_GREYF; 22.236 + break; 22.237 + 22.238 + case IMG_FMT_RGB24: 22.239 + targ_fmt = IMG_FMT_RGBF; 22.240 + break; 22.241 + 22.242 + case IMG_FMT_RGBA32: 22.243 + targ_fmt = IMG_FMT_RGBAF; 22.244 + break; 22.245 + 22.246 + default: 22.247 + return 0; /* already float */ 22.248 + } 22.249 + 22.250 + return img_convert(img, targ_fmt); 22.251 +} 22.252 + 22.253 +int img_to_integer(struct img_pixmap *img) 22.254 +{ 22.255 + enum img_fmt targ_fmt; 22.256 + 22.257 + switch(img->fmt) { 22.258 + case IMG_FMT_GREYF: 22.259 + targ_fmt = IMG_FMT_GREY8; 22.260 + break; 22.261 + 22.262 + case IMG_FMT_RGBF: 22.263 + targ_fmt = IMG_FMT_RGB24; 22.264 + break; 22.265 + 22.266 + case IMG_FMT_RGBAF: 22.267 + targ_fmt = IMG_FMT_RGBA32; 22.268 + break; 22.269 + 22.270 + default: 22.271 + return 0; /* already integer */ 22.272 + } 22.273 + 22.274 + return img_convert(img, targ_fmt); 22.275 +} 22.276 + 22.277 +int img_is_float(struct img_pixmap *img) 22.278 +{ 22.279 + return img->fmt >= IMG_FMT_GREYF && img->fmt <= IMG_FMT_RGBAF; 22.280 +} 22.281 + 22.282 +int img_has_alpha(struct img_pixmap *img) 22.283 +{ 22.284 + if(img->fmt == IMG_FMT_RGBA32 || img->fmt == IMG_FMT_RGBAF) { 22.285 + return 1; 22.286 + } 22.287 + return 0; 22.288 +} 22.289 + 22.290 + 22.291 +void img_setpixel(struct img_pixmap *img, int x, int y, void *pixel) 22.292 +{ 22.293 + char *dest = (char*)img->pixels + (y * img->width + x) * img->pixelsz; 22.294 + memcpy(dest, pixel, img->pixelsz); 22.295 +} 22.296 + 22.297 +void img_getpixel(struct img_pixmap *img, int x, int y, void *pixel) 22.298 +{ 22.299 + char *dest = (char*)img->pixels + (y * img->width + x) * img->pixelsz; 22.300 + memcpy(pixel, dest, img->pixelsz); 22.301 +} 22.302 + 22.303 +void img_setpixel1i(struct img_pixmap *img, int x, int y, int pix) 22.304 +{ 22.305 + img_setpixel4i(img, x, y, pix, pix, pix, pix); 22.306 +} 22.307 + 22.308 +void img_setpixel1f(struct img_pixmap *img, int x, int y, float pix) 22.309 +{ 22.310 + img_setpixel4f(img, x, y, pix, pix, pix, pix); 22.311 +} 22.312 + 22.313 +void img_setpixel4i(struct img_pixmap *img, int x, int y, int r, int g, int b, int a) 22.314 +{ 22.315 + if(img_is_float(img)) { 22.316 + img_setpixel4f(img, x, y, r / 255.0, g / 255.0, b / 255.0, a / 255.0); 22.317 + } else { 22.318 + unsigned char pixel[4]; 22.319 + pixel[0] = r; 22.320 + pixel[1] = g; 22.321 + pixel[2] = b; 22.322 + pixel[3] = a; 22.323 + 22.324 + img_setpixel(img, x, y, pixel); 22.325 + } 22.326 +} 22.327 + 22.328 +void img_setpixel4f(struct img_pixmap *img, int x, int y, float r, float g, float b, float a) 22.329 +{ 22.330 + if(img_is_float(img)) { 22.331 + float pixel[4]; 22.332 + pixel[0] = r; 22.333 + pixel[1] = g; 22.334 + pixel[2] = b; 22.335 + pixel[3] = a; 22.336 + 22.337 + img_setpixel(img, x, y, pixel); 22.338 + } else { 22.339 + img_setpixel4i(img, x, y, (int)(r * 255.0), (int)(g * 255.0), (int)(b * 255.0), (int)(a * 255.0)); 22.340 + } 22.341 +} 22.342 + 22.343 +void img_getpixel1i(struct img_pixmap *img, int x, int y, int *pix) 22.344 +{ 22.345 + int junk[3]; 22.346 + img_getpixel4i(img, x, y, pix, junk, junk + 1, junk + 2); 22.347 +} 22.348 + 22.349 +void img_getpixel1f(struct img_pixmap *img, int x, int y, float *pix) 22.350 +{ 22.351 + float junk[3]; 22.352 + img_getpixel4f(img, x, y, pix, junk, junk + 1, junk + 2); 22.353 +} 22.354 + 22.355 +void img_getpixel4i(struct img_pixmap *img, int x, int y, int *r, int *g, int *b, int *a) 22.356 +{ 22.357 + if(img_is_float(img)) { 22.358 + float pixel[4] = {0, 0, 0, 0}; 22.359 + img_getpixel(img, x, y, pixel); 22.360 + *r = pixel[0] * 255.0; 22.361 + *g = pixel[1] * 255.0; 22.362 + *b = pixel[2] * 255.0; 22.363 + *a = pixel[3] * 255.0; 22.364 + } else { 22.365 + unsigned char pixel[4]; 22.366 + img_getpixel(img, x, y, pixel); 22.367 + *r = pixel[0]; 22.368 + *g = pixel[1]; 22.369 + *b = pixel[2]; 22.370 + *a = pixel[3]; 22.371 + } 22.372 +} 22.373 + 22.374 +void img_getpixel4f(struct img_pixmap *img, int x, int y, float *r, float *g, float *b, float *a) 22.375 +{ 22.376 + if(img_is_float(img)) { 22.377 + float pixel[4] = {0, 0, 0, 0}; 22.378 + img_getpixel(img, x, y, pixel); 22.379 + *r = pixel[0]; 22.380 + *g = pixel[1]; 22.381 + *b = pixel[2]; 22.382 + *a = pixel[3]; 22.383 + } else { 22.384 + unsigned char pixel[4]; 22.385 + img_getpixel(img, x, y, pixel); 22.386 + *r = pixel[0] / 255.0; 22.387 + *g = pixel[1] / 255.0; 22.388 + *b = pixel[2] / 255.0; 22.389 + *a = pixel[3] / 255.0; 22.390 + } 22.391 +} 22.392 + 22.393 +void img_io_set_user_data(struct img_io *io, void *uptr) 22.394 +{ 22.395 + io->uptr = uptr; 22.396 +} 22.397 + 22.398 +void img_io_set_read_func(struct img_io *io, size_t (*read)(void*, size_t, void*)) 22.399 +{ 22.400 + io->read = read; 22.401 +} 22.402 + 22.403 +void img_io_set_write_func(struct img_io *io, size_t (*write)(void*, size_t, void*)) 22.404 +{ 22.405 + io->write = write; 22.406 +} 22.407 + 22.408 +void img_io_set_seek_func(struct img_io *io, long (*seek)(long, int, void*)) 22.409 +{ 22.410 + io->seek = seek; 22.411 +} 22.412 + 22.413 + 22.414 +static int pixel_size(enum img_fmt fmt) 22.415 +{ 22.416 + switch(fmt) { 22.417 + case IMG_FMT_GREY8: 22.418 + return 1; 22.419 + case IMG_FMT_RGB24: 22.420 + return 3; 22.421 + case IMG_FMT_RGBA32: 22.422 + return 4; 22.423 + case IMG_FMT_GREYF: 22.424 + return sizeof(float); 22.425 + case IMG_FMT_RGBF: 22.426 + return 3 * sizeof(float); 22.427 + case IMG_FMT_RGBAF: 22.428 + return 4 * sizeof(float); 22.429 + default: 22.430 + break; 22.431 + } 22.432 + return 0; 22.433 +} 22.434 + 22.435 +static size_t def_read(void *buf, size_t bytes, void *uptr) 22.436 +{ 22.437 + return uptr ? fread(buf, 1, bytes, uptr) : 0; 22.438 +} 22.439 + 22.440 +static size_t def_write(void *buf, size_t bytes, void *uptr) 22.441 +{ 22.442 + return uptr ? fwrite(buf, 1, bytes, uptr) : 0; 22.443 +} 22.444 + 22.445 +static long def_seek(long offset, int whence, void *uptr) 22.446 +{ 22.447 + if(!uptr || fseek(uptr, offset, whence) == -1) { 22.448 + return -1; 22.449 + } 22.450 + return ftell(uptr); 22.451 +} 22.452 +
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/libs/libimago/src/imago2.h Fri Jul 18 05:07:40 2014 +0300 23.3 @@ -0,0 +1,222 @@ 23.4 +/* 23.5 +libimago - a multi-format image file input/output library. 23.6 +Copyright (C) 2010-2012 John Tsiombikas <nuclear@member.fsf.org> 23.7 + 23.8 +This program is free software: you can redistribute it and/or modify 23.9 +it under the terms of the GNU Lesser General Public License as published 23.10 +by the Free Software Foundation, either version 3 of the License, or 23.11 +(at your option) any later version. 23.12 + 23.13 +This program is distributed in the hope that it will be useful, 23.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 23.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23.16 +GNU Lesser General Public License for more details. 23.17 + 23.18 +You should have received a copy of the GNU Lesser General Public License 23.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 23.20 +*/ 23.21 + 23.22 +#ifndef IMAGO2_H_ 23.23 +#define IMAGO2_H_ 23.24 + 23.25 +#include <stdio.h> 23.26 + 23.27 +#ifdef __cplusplus 23.28 +#define IMG_OPTARG(arg, val) arg = val 23.29 +#else 23.30 +#define IMG_OPTARG(arg, val) arg 23.31 +#endif 23.32 + 23.33 +/* XXX if you change this make sure to also change pack/unpack arrays in conv.c */ 23.34 +enum img_fmt { 23.35 + IMG_FMT_GREY8, 23.36 + IMG_FMT_RGB24, 23.37 + IMG_FMT_RGBA32, 23.38 + IMG_FMT_GREYF, 23.39 + IMG_FMT_RGBF, 23.40 + IMG_FMT_RGBAF, 23.41 + 23.42 + NUM_IMG_FMT 23.43 +}; 23.44 + 23.45 +struct img_pixmap { 23.46 + void *pixels; 23.47 + int width, height; 23.48 + enum img_fmt fmt; 23.49 + int pixelsz; 23.50 + char *name; 23.51 +}; 23.52 + 23.53 +struct img_io { 23.54 + void *uptr; /* user-data */ 23.55 + 23.56 + size_t (*read)(void *buf, size_t bytes, void *uptr); 23.57 + size_t (*write)(void *buf, size_t bytes, void *uptr); 23.58 + long (*seek)(long offs, int whence, void *uptr); 23.59 +}; 23.60 + 23.61 +#ifdef __cplusplus 23.62 +extern "C" { 23.63 +#endif 23.64 + 23.65 +/* initialize the img_pixmap structure */ 23.66 +void img_init(struct img_pixmap *img); 23.67 +/* destroys the img_pixmap structure, freeing the pixel buffer (if available) 23.68 + * and any other memory held by the pixmap. 23.69 + */ 23.70 +void img_destroy(struct img_pixmap *img); 23.71 + 23.72 +/* convenience function that allocates an img_pixmap struct and then initializes it. 23.73 + * returns null if the malloc fails. 23.74 + */ 23.75 +struct img_pixmap *img_create(void); 23.76 +/* frees a pixmap previously allocated with img_create (free followed by img_destroy) */ 23.77 +void img_free(struct img_pixmap *img); 23.78 + 23.79 +int img_set_name(struct img_pixmap *img, const char *name); 23.80 + 23.81 +/* set the image pixel format */ 23.82 +int img_set_format(struct img_pixmap *img, enum img_fmt fmt); 23.83 + 23.84 +/* copies one pixmap to another. 23.85 + * equivalent to: img_set_pixels(dest, src->width, src->height, src->fmt, src->pixels) 23.86 + */ 23.87 +int img_copy(struct img_pixmap *dest, struct img_pixmap *src); 23.88 + 23.89 +/* allocates a pixel buffer of the specified dimensions and format, and copies the 23.90 + * pixels given through the pix pointer into it. 23.91 + * the pix pointer can be null, in which case there's no copy, just allocation. 23.92 + * 23.93 + * C++: fmt and pix have default parameters IMG_FMT_RGBA32 and null respectively. 23.94 + */ 23.95 +int img_set_pixels(struct img_pixmap *img, int w, int h, IMG_OPTARG(enum img_fmt fmt, IMG_FMT_RGBA32), IMG_OPTARG(void *pix, 0)); 23.96 + 23.97 +/* Simplified image loading 23.98 + * Loads the specified file, and returns a pointer to an array of pixels of the 23.99 + * requested pixel format. The width and height of the image are returned through 23.100 + * the xsz and ysz pointers. 23.101 + * If the image cannot be loaded, the function returns null. 23.102 + * 23.103 + * C++: the format argument is optional and defaults to IMG_FMT_RGBA32 23.104 + */ 23.105 +void *img_load_pixels(const char *fname, int *xsz, int *ysz, IMG_OPTARG(enum img_fmt fmt, IMG_FMT_RGBA32)); 23.106 + 23.107 +/* Simplified image saving 23.108 + * Reads an array of pixels supplied through the pix pointer, of dimensions xsz 23.109 + * and ysz, and pixel-format fmt, and saves it to a file. 23.110 + * The output filetype is guessed by the filename suffix. 23.111 + * 23.112 + * C++: the format argument is optional and defaults to IMG_FMT_RGBA32 23.113 + */ 23.114 +int img_save_pixels(const char *fname, void *pix, int xsz, int ysz, IMG_OPTARG(enum img_fmt fmt, IMG_FMT_RGBA32)); 23.115 + 23.116 +/* Frees the memory allocated by img_load_pixels */ 23.117 +void img_free_pixels(void *pix); 23.118 + 23.119 +/* Loads an image file into the supplied pixmap */ 23.120 +int img_load(struct img_pixmap *img, const char *fname); 23.121 +/* Saves the supplied pixmap to a file. The output filetype is guessed by the filename suffix */ 23.122 +int img_save(struct img_pixmap *img, const char *fname); 23.123 + 23.124 +/* Reads an image from an open FILE* into the supplied pixmap */ 23.125 +int img_read_file(struct img_pixmap *img, FILE *fp); 23.126 +/* Writes the supplied pixmap to an open FILE* */ 23.127 +int img_write_file(struct img_pixmap *img, FILE *fp); 23.128 + 23.129 +/* Reads an image using user-defined file-i/o functions (see img_io_set_*) */ 23.130 +int img_read(struct img_pixmap *img, struct img_io *io); 23.131 +/* Writes an image using user-defined file-i/o functions (see img_io_set_*) */ 23.132 +int img_write(struct img_pixmap *img, struct img_io *io); 23.133 + 23.134 +/* Converts an image to the specified pixel format */ 23.135 +int img_convert(struct img_pixmap *img, enum img_fmt tofmt); 23.136 + 23.137 +/* Converts an image from an integer pixel format to the corresponding floating point one */ 23.138 +int img_to_float(struct img_pixmap *img); 23.139 +/* Converts an image from a floating point pixel format to the corresponding integer one */ 23.140 +int img_to_integer(struct img_pixmap *img); 23.141 + 23.142 +/* Returns non-zero (true) if the supplied image is in a floating point pixel format */ 23.143 +int img_is_float(struct img_pixmap *img); 23.144 +/* Returns non-zero (true) if the supplied image has an alpha channel */ 23.145 +int img_has_alpha(struct img_pixmap *img); 23.146 + 23.147 + 23.148 +/* don't use these for anything performance-critical */ 23.149 +void img_setpixel(struct img_pixmap *img, int x, int y, void *pixel); 23.150 +void img_getpixel(struct img_pixmap *img, int x, int y, void *pixel); 23.151 + 23.152 +void img_setpixel1i(struct img_pixmap *img, int x, int y, int pix); 23.153 +void img_setpixel1f(struct img_pixmap *img, int x, int y, float pix); 23.154 +void img_setpixel4i(struct img_pixmap *img, int x, int y, int r, int g, int b, int a); 23.155 +void img_setpixel4f(struct img_pixmap *img, int x, int y, float r, float g, float b, float a); 23.156 + 23.157 +void img_getpixel1i(struct img_pixmap *img, int x, int y, int *pix); 23.158 +void img_getpixel1f(struct img_pixmap *img, int x, int y, float *pix); 23.159 +void img_getpixel4i(struct img_pixmap *img, int x, int y, int *r, int *g, int *b, int *a); 23.160 +void img_getpixel4f(struct img_pixmap *img, int x, int y, float *r, float *g, float *b, float *a); 23.161 + 23.162 + 23.163 +/* OpenGL helper functions */ 23.164 + 23.165 +/* Returns the equivalent OpenGL "format" as expected by the 7th argument of glTexImage2D */ 23.166 +unsigned int img_fmt_glfmt(enum img_fmt fmt); 23.167 +/* Returns the equivalent OpenGL "type" as expected by the 8th argument of glTexImage2D */ 23.168 +unsigned int img_fmt_gltype(enum img_fmt fmt); 23.169 +/* Returns the equivalent OpenGL "internal format" as expected by the 3rd argument of glTexImage2D */ 23.170 +unsigned int img_fmt_glintfmt(enum img_fmt fmt); 23.171 + 23.172 +/* Same as above, based on the pixel format of the supplied image */ 23.173 +unsigned int img_glfmt(struct img_pixmap *img); 23.174 +unsigned int img_gltype(struct img_pixmap *img); 23.175 +unsigned int img_glintfmt(struct img_pixmap *img); 23.176 + 23.177 +/* Creates an OpenGL texture from the image, and returns the texture id, or 0 for failure */ 23.178 +unsigned int img_gltexture(struct img_pixmap *img); 23.179 + 23.180 +/* Load an image and create an OpenGL texture out of it */ 23.181 +unsigned int img_gltexture_load(const char *fname); 23.182 +unsigned int img_gltexture_read_file(FILE *fp); 23.183 +unsigned int img_gltexture_read(struct img_io *io); 23.184 + 23.185 +/* These functions can be used to fill an img_io struct before it's passed to 23.186 + * one of the user-defined i/o image reading/writing functions (img_read/img_write). 23.187 + * 23.188 + * User-defined i/o functions: 23.189 + * 23.190 + * - size_t read_func(void *buffer, size_t bytes, void *user_ptr) 23.191 + * Must try to fill the buffer with the specified number of bytes, and return 23.192 + * the number of bytes actually read. 23.193 + * 23.194 + * - size_t write_func(void *buffer, size_t bytes, void *user_ptr) 23.195 + * Must write the specified number of bytes from the supplied buffer and return 23.196 + * the number of bytes actually written. 23.197 + * 23.198 + * - long seek_func(long offset, int whence, void *user_ptr) 23.199 + * Must seek offset bytes from: the beginning of the file if whence is SEEK_SET, 23.200 + * the current position if whence is SEEK_CUR, or the end of the file if whence is 23.201 + * SEEK_END, and return the resulting file offset from the beginning of the file. 23.202 + * (i.e. seek_func(0, SEEK_CUR, user_ptr); must be equivalent to an ftell). 23.203 + * 23.204 + * All three functions get the user-data pointer set through img_io_set_user_data 23.205 + * as their last argument. 23.206 + * 23.207 + * Note: obviously you don't need to set a write function if you're only going 23.208 + * to call img_read, or the read and seek function if you're only going to call 23.209 + * img_write. 23.210 + * 23.211 + * Note: if the user-supplied write function is buffered, make sure to flush 23.212 + * (or close the file) after img_write returns. 23.213 + */ 23.214 +void img_io_set_user_data(struct img_io *io, void *uptr); 23.215 +void img_io_set_read_func(struct img_io *io, size_t (*read)(void*, size_t, void*)); 23.216 +void img_io_set_write_func(struct img_io *io, size_t (*write)(void*, size_t, void*)); 23.217 +void img_io_set_seek_func(struct img_io *io, long (*seek)(long, int, void*)); 23.218 + 23.219 + 23.220 +#ifdef __cplusplus 23.221 +} 23.222 +#endif 23.223 + 23.224 + 23.225 +#endif /* IMAGO_H_ */
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/libs/libimago/src/imago_gl.c Fri Jul 18 05:07:40 2014 +0300 24.3 @@ -0,0 +1,223 @@ 24.4 +#include "imago2.h" 24.5 + 24.6 + 24.7 +/* to avoid dependency to OpenGL, I'll define all the relevant GL macros manually */ 24.8 +#define GL_UNSIGNED_BYTE 0x1401 24.9 +#define GL_FLOAT 0x1406 24.10 + 24.11 +#define GL_LUMINANCE 0x1909 24.12 +#define GL_RGB 0x1907 24.13 +#define GL_RGBA 0x1908 24.14 + 24.15 +#define GL_RGBA32F 0x8814 24.16 +#define GL_RGB32F 0x8815 24.17 +#define GL_LUMINANCE32F 0x8818 24.18 + 24.19 +#define GL_TEXTURE_2D 0x0de1 24.20 +#define GL_TEXTURE_WRAP_S 0x2802 24.21 +#define GL_TEXTURE_WRAP_T 0x2803 24.22 +#define GL_TEXTURE_MAG_FILTER 0x2800 24.23 +#define GL_TEXTURE_MIN_FILTER 0x2801 24.24 +#define GL_LINEAR 0x2601 24.25 +#define GL_REPEAT 0x2901 24.26 + 24.27 + 24.28 +typedef unsigned int GLenum; 24.29 +typedef unsigned int GLuint; 24.30 +typedef int GLint; 24.31 +typedef int GLsizei; 24.32 +typedef void GLvoid; 24.33 + 24.34 +/* for the same reason I'll load GL functions dynamically */ 24.35 +typedef void (*gl_gen_textures_func)(GLsizei, GLuint*); 24.36 +typedef void (*gl_bind_texture_func)(GLenum, GLuint); 24.37 +typedef void (*gl_tex_parameteri_func)(GLenum, GLenum, GLint); 24.38 +typedef void (*gl_tex_image2d_func)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid*); 24.39 + 24.40 +static gl_gen_textures_func gl_gen_textures; 24.41 +static gl_bind_texture_func gl_bind_texture; 24.42 +static gl_tex_parameteri_func gl_tex_parameteri; 24.43 +static gl_tex_image2d_func gl_tex_image2d; 24.44 + 24.45 +static int load_glfunc(void); 24.46 + 24.47 +unsigned int img_fmt_glfmt(enum img_fmt fmt) 24.48 +{ 24.49 + switch(fmt) { 24.50 + case IMG_FMT_GREY8: 24.51 + case IMG_FMT_GREYF: 24.52 + return GL_LUMINANCE; 24.53 + 24.54 + case IMG_FMT_RGB24: 24.55 + case IMG_FMT_RGBF: 24.56 + return GL_RGB; 24.57 + 24.58 + case IMG_FMT_RGBA32: 24.59 + case IMG_FMT_RGBAF: 24.60 + return GL_RGBA; 24.61 + 24.62 + default: 24.63 + break; 24.64 + } 24.65 + return 0; 24.66 +} 24.67 + 24.68 +unsigned int img_fmt_gltype(enum img_fmt fmt) 24.69 +{ 24.70 + switch(fmt) { 24.71 + case IMG_FMT_GREY8: 24.72 + case IMG_FMT_RGB24: 24.73 + case IMG_FMT_RGBA32: 24.74 + return GL_UNSIGNED_BYTE; 24.75 + 24.76 + case IMG_FMT_GREYF: 24.77 + case IMG_FMT_RGBF: 24.78 + case IMG_FMT_RGBAF: 24.79 + return GL_FLOAT; 24.80 + 24.81 + default: 24.82 + break; 24.83 + } 24.84 + return 0; 24.85 +} 24.86 + 24.87 +unsigned int img_fmt_glintfmt(enum img_fmt fmt) 24.88 +{ 24.89 + switch(fmt) { 24.90 + case IMG_FMT_GREY8: 24.91 + return GL_LUMINANCE; 24.92 + case IMG_FMT_RGB24: 24.93 + return GL_RGB; 24.94 + case IMG_FMT_RGBA32: 24.95 + return GL_RGBA; 24.96 + case IMG_FMT_GREYF: 24.97 + return GL_LUMINANCE32F; 24.98 + case IMG_FMT_RGBF: 24.99 + return GL_RGB32F; 24.100 + case IMG_FMT_RGBAF: 24.101 + return GL_RGBA32F; 24.102 + default: 24.103 + break; 24.104 + } 24.105 + return 0; 24.106 +} 24.107 + 24.108 +unsigned int img_glfmt(struct img_pixmap *img) 24.109 +{ 24.110 + return img_fmt_glfmt(img->fmt); 24.111 +} 24.112 + 24.113 +unsigned int img_gltype(struct img_pixmap *img) 24.114 +{ 24.115 + return img_fmt_gltype(img->fmt); 24.116 +} 24.117 + 24.118 +unsigned int img_glintfmt(struct img_pixmap *img) 24.119 +{ 24.120 + return img_fmt_glintfmt(img->fmt); 24.121 +} 24.122 + 24.123 +unsigned int img_gltexture(struct img_pixmap *img) 24.124 +{ 24.125 + unsigned int tex; 24.126 + unsigned int intfmt, fmt, type; 24.127 + 24.128 + if(!gl_gen_textures) { 24.129 + if(load_glfunc() == -1) { 24.130 + fprintf(stderr, "imago: failed to initialize the OpenGL helpers\n"); 24.131 + return 0; 24.132 + } 24.133 + } 24.134 + 24.135 + intfmt = img_glintfmt(img); 24.136 + fmt = img_glfmt(img); 24.137 + type = img_gltype(img); 24.138 + 24.139 + gl_gen_textures(1, &tex); 24.140 + gl_bind_texture(GL_TEXTURE_2D, tex); 24.141 + gl_tex_parameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 24.142 + gl_tex_parameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 24.143 + gl_tex_parameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 24.144 + gl_tex_parameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 24.145 + gl_tex_image2d(GL_TEXTURE_2D, 0, intfmt, img->width, img->height, 0, fmt, type, img->pixels); 24.146 + return tex; 24.147 +} 24.148 + 24.149 +unsigned int img_gltexture_load(const char *fname) 24.150 +{ 24.151 + struct img_pixmap img; 24.152 + unsigned int tex; 24.153 + 24.154 + img_init(&img); 24.155 + if(img_load(&img, fname) == -1) { 24.156 + img_destroy(&img); 24.157 + return 0; 24.158 + } 24.159 + 24.160 + tex = img_gltexture(&img); 24.161 + img_destroy(&img); 24.162 + return tex; 24.163 +} 24.164 + 24.165 +unsigned int img_gltexture_read_file(FILE *fp) 24.166 +{ 24.167 + struct img_pixmap img; 24.168 + unsigned int tex; 24.169 + 24.170 + img_init(&img); 24.171 + if(img_read_file(&img, fp) == -1) { 24.172 + img_destroy(&img); 24.173 + return 0; 24.174 + } 24.175 + 24.176 + tex = img_gltexture(&img); 24.177 + img_destroy(&img); 24.178 + return tex; 24.179 +} 24.180 + 24.181 +unsigned int img_gltexture_read(struct img_io *io) 24.182 +{ 24.183 + struct img_pixmap img; 24.184 + unsigned int tex; 24.185 + 24.186 + img_init(&img); 24.187 + if(img_read(&img, io) == -1) { 24.188 + img_destroy(&img); 24.189 + return 0; 24.190 + } 24.191 + 24.192 + tex = img_gltexture(&img); 24.193 + img_destroy(&img); 24.194 + return tex; 24.195 +} 24.196 + 24.197 +#if defined(__unix__) || defined(__APPLE__) 24.198 +#ifndef __USE_GNU 24.199 +#define __USE_GNU 24.200 +#endif 24.201 + 24.202 +#include <dlfcn.h> 24.203 +#endif 24.204 +#ifdef WIN32 24.205 +#include <windows.h> 24.206 +#endif 24.207 + 24.208 +static int load_glfunc(void) 24.209 +{ 24.210 +#if defined(__unix__) || defined(__APPLE__) 24.211 + gl_gen_textures = (gl_gen_textures_func)dlsym(RTLD_DEFAULT, "glGenTextures"); 24.212 + gl_bind_texture = (gl_bind_texture_func)dlsym(RTLD_DEFAULT, "glBindTexture"); 24.213 + gl_tex_parameteri = (gl_tex_parameteri_func)dlsym(RTLD_DEFAULT, "glTexParameteri"); 24.214 + gl_tex_image2d = (gl_tex_image2d_func)dlsym(RTLD_DEFAULT, "glTexImage2D"); 24.215 +#endif 24.216 + 24.217 +#ifdef WIN32 24.218 + HMODULE handle = GetModuleHandle(0); 24.219 + gl_gen_textures = (gl_gen_textures_func)GetProcAddress(handle, "glGenTextures"); 24.220 + gl_bind_texture = (gl_bind_texture_func)GetProcAddress(handle, "glBindTexture"); 24.221 + gl_tex_parameteri = (gl_tex_parameteri_func)GetProcAddress(handle, "glTexParameteri"); 24.222 + gl_tex_image2d = (gl_tex_image2d_func)GetProcAddress(handle, "glTexImage2D"); 24.223 +#endif 24.224 + 24.225 + return (gl_gen_textures && gl_bind_texture && gl_tex_parameteri && gl_tex_image2d) ? 0 : -1; 24.226 +}
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/libs/libimago/test/Makefile Fri Jul 18 05:07:40 2014 +0300 25.3 @@ -0,0 +1,19 @@ 25.4 +obj = test.o 25.5 +bin = test 25.6 + 25.7 +CC = gcc 25.8 +CFLAGS = -pedantic -Wall -g -I../src 25.9 +LDFLAGS = $(lib) 25.10 + 25.11 +ifeq ($(shell uname -s), Darwin) 25.12 + lib = ../libimago.dylib 25.13 +else 25.14 + lib = ../libimago.so.2.0 25.15 +endif 25.16 + 25.17 +$(bin): $(obj) $(lib) 25.18 + $(CC) -o $@ $(obj) $(LDFLAGS) 25.19 + 25.20 +.PHONY: clean 25.21 +clean: 25.22 + rm -f $(obj) $(bin)
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/libs/libimago/test/test.c Fri Jul 18 05:07:40 2014 +0300 26.3 @@ -0,0 +1,63 @@ 26.4 +#include <stdio.h> 26.5 +#include <imago2.h> 26.6 + 26.7 +int main(int argc, char **argv) 26.8 +{ 26.9 + const char *infile = "foo.jpg"; 26.10 + const char *outfile = "bar.jpg"; 26.11 + int i, j, xsz = 512, ysz = 512; 26.12 + struct img_pixmap img; 26.13 + 26.14 + for(i=1; i<argc; i++) { 26.15 + if(argv[i][0] == '-' && argv[i][2] == 0) { 26.16 + switch(argv[i][1]) { 26.17 + case 'i': 26.18 + infile = argv[++i]; 26.19 + break; 26.20 + 26.21 + case 'o': 26.22 + outfile = argv[++i]; 26.23 + break; 26.24 + 26.25 + default: 26.26 + fprintf(stderr, "invalid option: %s\n", argv[i]); 26.27 + return 1; 26.28 + } 26.29 + } else { 26.30 + fprintf(stderr, "invalid argument: %s\n", argv[i]); 26.31 + return 1; 26.32 + } 26.33 + } 26.34 + 26.35 + img_init(&img); 26.36 + 26.37 + if(img_load(&img, infile) == -1) { 26.38 + unsigned char *pix; 26.39 + 26.40 + fprintf(stderr, "failed to load image: %s, generating instead\n", infile); 26.41 + 26.42 + if(img_set_pixels(&img, xsz, ysz, IMG_FMT_RGB24, 0) == -1) { 26.43 + perror("wtf"); 26.44 + return 1; 26.45 + } 26.46 + 26.47 + pix = img.pixels; 26.48 + for(i=0; i<ysz; i++) { 26.49 + for(j=0; j<xsz; j++) { 26.50 + int bw = ((i >> 5) & 1) == ((j >> 5) & 1); 26.51 + 26.52 + *pix++ = bw ? 255 : 0; 26.53 + *pix++ = 127; 26.54 + *pix++ = bw ? 0 : 255; 26.55 + } 26.56 + } 26.57 + } 26.58 + 26.59 + if(img_save(&img, outfile) == -1) { 26.60 + fprintf(stderr, "failed to save file %s\n", outfile); 26.61 + return 1; 26.62 + } 26.63 + 26.64 + img_destroy(&img); 26.65 + return 0; 26.66 +}