diff --git a/Assets.xcassets/AppIcon.appiconset/Contents.json b/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..1397e64 --- /dev/null +++ b/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_16.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_32-1.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_32.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_64.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_128.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_256-1.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_256.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_512.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_512-1.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "spiritied_array_app_icon_1024.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_1024.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_1024.png new file mode 100644 index 0000000..d559a79 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_1024.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_128.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_128.png new file mode 100644 index 0000000..c820279 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_128.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_16.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_16.png new file mode 100644 index 0000000..cee7202 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_16.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_256-1.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_256-1.png new file mode 100644 index 0000000..fd6e537 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_256-1.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_256.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_256.png new file mode 100644 index 0000000..fd6e537 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_256.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_32-1.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_32-1.png new file mode 100644 index 0000000..b684a43 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_32-1.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_32.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_32.png new file mode 100644 index 0000000..b684a43 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_32.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_512-1.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_512-1.png new file mode 100644 index 0000000..372811a Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_512-1.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_512.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_512.png new file mode 100644 index 0000000..372811a Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_512.png differ diff --git a/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_64.png b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_64.png new file mode 100644 index 0000000..2822253 Binary files /dev/null and b/Assets.xcassets/AppIcon.appiconset/spiritied_array_app_icon_64.png differ diff --git a/Assets.xcassets/Contents.json b/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..20d40b6 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..08e56c0 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +_Spirited Array_ is a Mac application for de-pixelating and then whimsically re-pixelating animated GIF's. Inspired by the nightly Electrical Water Pageant on the Seven Seas Lagoon at Walt Disney World, Spirited Array was written to simulate light board animations of unspecified dimension, without expensive hardware. + +# Operation + +To operate, open the Application on your Mac and choose _Open_ from the _File_ pull-down menu. Then, navigate to and select an animated GIF, static GIF, (static) PNG or (static) TIFF file. + +An attempt will be made to recognize any pixelation your file exhibits, and remove it. Finally, your animation will be re-pixelated according to the configured tiling strategy, and animated in a loop. Details about your animation will be provided in a status bar at the lower left-hand corner of the animation window. + +| ![](docs/animation_window.png) | +|:--:| +| _screenshot of animation processed from prguitarman's "Pop Tart Cat" GIF (popularized as "Nyan Cat" in a video by saraj00n.)_ | + +You may choose different tiling strategies with the _Tiling_ pull-down menu. + +To change the dimensions of the virtual array, simply resize the animation window. + +Use the linked sliders that appear after processing to change the tile size and restart the de-pixelation and re-pixelation sequence. + +By default, the vertical and horizontal sliders will be locked together. You can toggle locking on and off by clicking on the padlock icon in the lower right-hand corner of the animation window. + +To export re-pixelated video to a file, use the appropriate Export corresponding to the desired output format under the _File_ Menu. + +# Building from Source + +_Spirited Array_ is licensed under GPL v3.0 and available to clone [on github](https://github.com/dhorlick/spirited_array). + +The project should build directly in XCode 9. + +_Spirited Array_ makes use of MIT-licensed [libungif-4.1.4](https://sourceforge.net/projects/giflib/files/libungif-4.x/4.1.1/), a decompression-only version of the venerable giflib. To keep things simple, an actual binary is included. But feel free to compile libungif (or giflib) yourself, and replace `libungif.a`. + diff --git a/appkit/AppKitAwareSpiritedArrayFactory.h b/appkit/AppKitAwareSpiritedArrayFactory.h new file mode 100755 index 0000000..0ea891a --- /dev/null +++ b/appkit/AppKitAwareSpiritedArrayFactory.h @@ -0,0 +1,13 @@ +// +// AppKitAwareSpirtedArrayFactory.h +// spiritedarray +// +// Created by Dave Horlick on 8/27/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SpiritedArrayFactory.h" + +@interface AppKitAwareSpiritedArrayFactory : SpiritedArrayFactory + +@end diff --git a/appkit/AppKitAwareSpiritedArrayFactory.m b/appkit/AppKitAwareSpiritedArrayFactory.m new file mode 100755 index 0000000..242e4af --- /dev/null +++ b/appkit/AppKitAwareSpiritedArrayFactory.m @@ -0,0 +1,58 @@ +// +// AppKitAwareSpirtedArrayFactory.m +// spiritedarray +// +// Created by Dave Horlick on 8/27/13. +// Copyleft 2013 River Porpoise Software +// + +#import "AppKitAwareSpiritedArrayFactory.h" +#import "CoreGraphicsImageDataBackedSpiritedArray.h" + +@implementation AppKitAwareSpiritedArrayFactory + ++(SpiritedArray *) build:(NSString *)imageFileName +{ + NSLog(@"imageFileName = %@", imageFileName); + NSString* extension = [SpiritedArrayFactory fileExtension: imageFileName]; + NSLog(@"extension = %@", extension); + // CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + if ([extension caseInsensitiveCompare: @"png"]==0) + { + /** ? + UIImage *image = [UIImage imageNamed:@"image.png"]; + CGImageRef imageRef = [image CGImage]; + */ + + NSImage* nsImage = [[NSImage alloc] initWithContentsOfFile:imageFileName]; + if (nsImage == nil) + { + @throw [NSException exceptionWithName:@"Can't open image file" reason:[NSString stringWithFormat:@"Attempt to open %@ returned nil.", imageFileName] userInfo: nil]; + } + + // CGContextRef context = CGBitmapContextCreate(NULL, 14, 14, 8, 0, colorSpace, kCGImageAlphaPremultipliedLast); + // [nsImage CGImageForProposedRect:nil context:context hints:nil]; + + NSData *imageData = [nsImage TIFFRepresentation]; + + return [[CoreGraphicsImageDataBackedSpiritedArray alloc] initWithImageData:(UInt8*)[imageData bytes] Width: [nsImage size].width Height:[nsImage size].height]; + + // CFDataRef cfImageData = CFBridgingRetain(imageData); + // CGImageSourceRef source = CGImageSourceCreateWithData(cfImageData, NULL); + // CGImageRef maskRef = CGImageSourceCreateImageAtIndex(source, 0, NULL); + + // CGContextRelease(context); + // CFRelease(cfImageData); + // CFRelease(source); + + // TODO release imageData, somehow? + } + else + { + return [[AppKitAwareSpiritedArrayFactory superclass] build:imageFileName]; + } +} + + +@end diff --git a/appkit/SAAppDelegate.h b/appkit/SAAppDelegate.h new file mode 100755 index 0000000..ffcacb6 --- /dev/null +++ b/appkit/SAAppDelegate.h @@ -0,0 +1,60 @@ +// +// SAAppDelegate.h +// spiritedarray +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import +#import + +#import "SAMacView.h" +#import "SpiritedArray.h" +#import "SAVideoExportSettings.h" +#import "SAVideoExportSettingsController.h" + +@interface SAAppDelegate : NSObject +{ + BOOL inaugural; +} +@property IBOutlet SAViewHelper* viewHelper; // TODO make this readonly? +@property (getter=desiredTileWidth, setter=setDesiredTileWidth:) IBOutlet NSNumber* desiredTileWidth; +@property (getter=desiredTileHeight, setter=setDesiredTileHeight:) IBOutlet NSNumber* desiredTileHeight; + +@property (assign) IBOutlet NSWindow *window; +@property (weak) IBOutlet SAMacView *view; +@property (weak) IBOutlet NSView *exportSettingsView; +@property (weak) IBOutlet NSMenuItem *exportAsGif; +@property (weak) IBOutlet NSMenuItem *exportAsH264EncodedMp4Video; +@property (weak) IBOutlet NSMenuItem *exportAsH264EncodedQuickTimeMovie; +@property (weak) IBOutlet NSMenuItem* solidColors; +@property (weak) IBOutlet NSMenuItem* lightEmittingDiodes; +@property (weak) IBOutlet NSMenuItem* meta; +@property (weak) IBOutlet NSMenuItem* fatBits; +@property (weak) IBOutlet NSMenuItem* graphPaper; +@property (weak) IBOutlet NSMenuItem* crossStitch; +@property (weak) IBOutlet NSMenu* linePrinter; +@property (weak) IBOutlet NSMenu* tiling; +@property (weak) IBOutlet SAVideoExportSettingsController* videoExportSettingsController; +@property (weak) IBOutlet NSButton *lockIcon; +@property (weak) IBOutlet NSSlider *tileWidthSlider; +@property (weak) IBOutlet NSSlider *tileHeightSlider; + ++(void) uncheckAllBut:(NSMenuItem*)selection In:(NSMenu*)menu; ++(void) uncheckAllButName:(NSString*)name In:(NSMenu*)menu; + +-(IBAction) doOpenFile:(id)sender; +-(IBAction) doExportAsGif:(id)sender; + +-(IBAction)doSolidColors:(id)sender; +-(IBAction)doLightEmittingDiodes:(id)sender; +-(IBAction)doFatBits:(id)sender; +-(IBAction)doGraphPaper:(id)sender; + +-(IBAction)doExportAsH264EncodedMp4Video:(id)sender; +-(IBAction)doExportAsH264EncodedQuickTimeMovie:(id)sender; + +- (IBAction)toggleResizeTileWidthAndHeightTogether:(id)sender; + +@end diff --git a/appkit/SAAppDelegate.m b/appkit/SAAppDelegate.m new file mode 100755 index 0000000..132caac --- /dev/null +++ b/appkit/SAAppDelegate.m @@ -0,0 +1,379 @@ +// +// SAAppDelegate.m +// spiritedarray +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SAAppDelegate.h" +#import "SpiritedArray.h" +#import "SALayer.h" +#import "GifEncoder.h" + +#import "SATileDrawingStrategy.h" +#import "SALightEmittingDiodeTileDrawingStrategy.h" +#import "SAFatBitsTileDrawingStrategy.h" +#import "SAGraphPaperTileDrawingStrategy.h" +#import "SAH264AvEncoder.h" +#import "SAMacroblockedBounded.h" +@implementation SAAppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification +{ + inaugural = YES; +} + +-(IBAction) doOpenFile:(id)sender +{ + NSOpenPanel* openDlg = [NSOpenPanel openPanel]; + [openDlg setCanChooseFiles:YES]; + [openDlg setAllowsMultipleSelection:NO]; + [openDlg setAllowedFileTypes:[NSImage imageTypes]]; + + [openDlg beginSheetModalForWindow: _window completionHandler: ^(NSInteger returnCode) + { + if (returnCode == NSOKButton) + { + NSURL* toOpen = [openDlg URL]; + NSString* fileName = [toOpen path]; + + NSLog(@"got file %@", fileName); + + [self->_view setPostsBoundsChangedNotifications: YES]; + + NSString* fileExtension = [fileName pathExtension]; + + if ([fileExtension isCaseInsensitiveLike:@"gif"] || [fileExtension isCaseInsensitiveLike:@"png"]) + { + SATileDrawingStrategy* oldTileDrawingStrategy = nil; + if (self.viewHelper!=nil) + oldTileDrawingStrategy = [self.viewHelper tileDrawingStrategy]; + + self.viewHelper = [[SAViewHelper alloc] initWith:self->_view Path: fileName]; + if (self->inaugural) + { + [self doGraphPaper:nil]; + self->inaugural = NO; + } + else + [self.viewHelper setTileDrawingStrategy:oldTileDrawingStrategy]; + + SALayer* layer = [[SALayer alloc] initWithViewHelper:self.viewHelper]; + self->_view.layer = layer; + + layer.bounds = [self->_view bounds]; + layer.timeValue = 0; + layer.position = NSMakePoint(CGRectGetMidX([self->_view bounds]), CGRectGetMidY([self->_view bounds])); + layer.delegate = self.viewHelper; + + CAMediaTimingFunction *timingfn = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; + + CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"timeValue"]; + anim.fromValue = 0; + NSLog(@"Mark! [self.viewHelper frames]=%u", [self.viewHelper frames]); + anim.toValue = [NSNumber numberWithDouble:(double)[self.viewHelper frames]-0.01]; + anim.timingFunction = timingfn; + + uint average = [[self.viewHelper content] averageDelayInCentisBetweenFrames]; + NSLog(@"average delay between frames in centis = %u", average); + + anim.duration = average * (double)[self.viewHelper frames] / 100.0; + NSLog(@"anim.duration = %f", anim.duration); + anim.repeatCount = INFINITY; + anim.fillMode = kCAFillModeForwards; + anim.removedOnCompletion = NO; + + // TODO figure out how to get this from repeating integer timeValues + + [CATransaction begin]; + [layer addAnimation:anim forKey:@"timeValue"]; + [self->_view setWantsLayer:YES]; + [CATransaction commit]; + + [self->_exportAsGif setEnabled:YES]; + [self->_exportAsH264EncodedMp4Video setEnabled:YES]; + [self->_exportAsH264EncodedQuickTimeMovie setEnabled:YES]; + + [self->_lightEmittingDiodes setEnabled:YES]; + [self->_fatBits setEnabled:YES]; + [self->_solidColors setEnabled:YES]; + [self->_meta setEnabled: YES]; + [self->_graphPaper setEnabled:YES]; + + [self.tileWidthSlider setHidden:NO]; + [self.tileHeightSlider setHidden:NO]; + [self.lockIcon setHidden:NO]; + + NSString* title = [[toOpen pathComponents] lastObject]; + + if (title!=nil) + [[self.view window] setTitle:title]; // TODO concatenate with MIDI if loaded? + } + /* else if ([fileExtension isCaseInsensitiveLike:@"mid"] + || [fileExtension isCaseInsensitiveLike:@"midi"]) + { + CFURLRef midiFileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8*)[fileName UTF8String], [fileName length]+1, false); // Why is +1 necessary here? + + MusicPlayer musicPlayer; + NewMusicPlayer(&musicPlayer); + + OSStatus result = noErr; + + MusicSequence musicSequence; + + result = NewMusicSequence(&musicSequence); + + if (result!=noErr) + { + [NSException raise:@"play" format:@"Can't create MusicSequence. Error code %d", (int)result]; + } + + CFErrorRef thisErr; + if (!CFURLResourceIsReachable(midiFileURL, &thisErr)) + { + CFStringRef pErrDesc = CFErrorCopyDescription( thisErr ); + + if( pErrDesc != NULL ) + { + [NSException raise:@"Can't resolve URL" format:@">> %@", pErrDesc]; + } + } + + result = MusicSequenceFileLoad(musicSequence, midiFileURL, 0, 0); + + if (result!=noErr) + { + [NSException raise:@"play" format:@"Can't load MusicSequence. Error code %d", (int)result]; + } + + MusicPlayerSetSequence(musicPlayer, musicSequence); + MusicPlayerPreroll(musicPlayer); + MusicPlayerStart(musicPlayer); + } */ + else + { + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:@"OK"]; + [alert setMessageText:@"Unrecognized File type"]; + [alert setInformativeText:@"Sorry, but you can only open GIF and PNG files."]; + [alert setAlertStyle:NSWarningAlertStyle]; + + [alert beginSheetModalForWindow:self->_window modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil]; + } + } + } + ]; +} + +- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode + contextInfo:(void *)contextInfo +{ +} + +-(IBAction) doExportAsGif:(id)sender +{ + NSSavePanel* saveDialog = [NSSavePanel savePanel]; + [saveDialog setAllowedFileTypes: [[NSArray alloc] initWithObjects:@"gif", nil]]; + [saveDialog beginSheetModalForWindow: _window completionHandler: ^(NSInteger returnCode) + { + if (returnCode == NSOKButton) + { + NSURL* fileUrl = [saveDialog URL]; + NSString* fileName = [fileUrl path]; + + NSLog(@"got file %@", fileName); + + GifEncoder* encoder = [GifEncoder new]; + [encoder encode:[self.viewHelper freeze] FilePath:fileName]; // TODO find a way to do this without memorization + } + }]; +} + + +-(IBAction) doSolidColors:(id)sender +{ + if (self.viewHelper != nil) + { + [self.viewHelper setTileDrawingStrategy: [SATileDrawingStrategy new]]; + [SAAppDelegate uncheckAllBut:_solidColors In:_tiling]; + } +} + +-(IBAction) doLightEmittingDiodes:(id)sender +{ + if (self.viewHelper != nil) + { + [self.viewHelper setTileDrawingStrategy: [SALightEmittingDiodeTileDrawingStrategy new]]; + [SAAppDelegate uncheckAllBut:_lightEmittingDiodes In:_tiling]; + } +} + +-(IBAction) doFatBits:(id)sender +{ + if (self.viewHelper != nil) + { + [self.viewHelper setTileDrawingStrategy: [SAFatBitsTileDrawingStrategy new]]; + [SAAppDelegate uncheckAllBut:_fatBits In:_tiling]; + } +} + +- (IBAction)doGraphPaper:(id)sender +{ + if (self.viewHelper!=nil) + { + [self.viewHelper setTileDrawingStrategy: [SAGraphPaperTileDrawingStrategy new]]; + [SAAppDelegate uncheckAllBut:_graphPaper In:_tiling]; + } +} + +-(void) setMenu:(NSMenu*)menu ItemsEnabled:(BOOL) enabled +{ + NSArray* menuItems = [menu itemArray]; + + for (uint i=0U; i<[menuItems count]; i++) + { + NSMenuItem* menuItem = [menuItems objectAtIndex:i]; + [menuItem setEnabled:enabled]; + } +} + ++(void) uncheckAllBut:(NSMenuItem*)selection In:(NSMenu*)menu +{ + NSArray* menuItems = [menu itemArray]; + + for (uint i=0U; i<[menuItems count]; i++) + { + NSMenuItem* menuItem = [menuItems objectAtIndex:i]; + if (menuItem==selection) + [menuItem setState:NSOnState]; + else + [menuItem setState:NSOffState]; + + if ([menuItem hasSubmenu]) + { + [SAAppDelegate uncheckAllBut:selection In:[menuItem submenu]]; + } + } +} + ++(void) uncheckAllButName:(NSString*)name In:(NSMenu*)menu +{ + NSArray* menuItems = [menu itemArray]; + + for (uint i=0U; i<[menuItems count]; i++) + { + NSMenuItem* menuItem = [menuItems objectAtIndex:i]; + if ([[menuItem title] isEqual: name]) + [menuItem setState:NSOnState]; + else + [menuItem setState:NSOffState]; + + if ([menuItem hasSubmenu]) + { + [SAAppDelegate uncheckAllButName:name In:[menuItem submenu]]; + } + } +} + +-(void)setupVideoExportSettingsView +{ + SAMacroblockedBounded* macroblocked = [[SAMacroblockedBounded alloc] initWithBounded:self.view AndMacroblockOfWidth:8U AndHeight:8U]; + + self.videoExportSettingsController.initialWidthInPixels = macroblocked.bounds.size.width; + self.videoExportSettingsController.initialHeightInPixels = macroblocked.bounds.size.height; + self.videoExportSettingsController.videoExportSettings.widthInPixels = [NSNumber numberWithFloat: macroblocked.bounds.size.width]; + self.videoExportSettingsController.videoExportSettings.heightInPixels = [NSNumber numberWithFloat: macroblocked.bounds.size.height]; + + [self.videoExportSettingsController.dimensionsRadioButtonMatrix selectCellWithTag:0]; +} + +-(IBAction)doExportAsH264EncodedMp4Video:(id)sender +{ + NSSavePanel* panel = [NSSavePanel savePanel]; + [panel setAllowedFileTypes: [[NSArray alloc] initWithObjects:@"mp4", nil]]; + + [panel setAccessoryView: self.exportSettingsView]; + [self setupVideoExportSettingsView]; + + [panel beginSheetModalForWindow: _window completionHandler: ^(NSInteger returnCode) + { + if (returnCode == NSOKButton) + { + float tileFootprintCorrectionFactor = [self leastUpheavalTileFootprintCorrectionFactor]; + + SAH264AvEncoder* encoder = [SAH264AvEncoder new]; + [encoder encode:[self.viewHelper spiritedArraySourceFilePath] TileDrawingStrategy:[self.viewHelper tileDrawingStrategy] WidthInPixels:[self.videoExportSettingsController.videoExportSettings.widthInPixels unsignedIntValue] HeightInPixels:[self.videoExportSettingsController.videoExportSettings.heightInPixels unsignedIntValue] TileWidthInPixels:tileFootprintCorrectionFactor*self.viewHelper.desiredTileWidth TileHeightInPixels:tileFootprintCorrectionFactor*self.viewHelper.desiredTileHeight Url:[panel URL] QuicktimeContainer:NO]; + } + } + ]; +} + +-(IBAction)doExportAsH264EncodedQuickTimeMovie:(id)sender +{ + NSSavePanel *panel = [NSSavePanel savePanel]; + [panel setAllowedFileTypes: [[NSArray alloc] initWithObjects:@"mov", nil]]; + [panel setAccessoryView: self.exportSettingsView]; + + [self setupVideoExportSettingsView]; + [panel setAccessoryView: self.exportSettingsView]; + + [panel beginSheetModalForWindow: _window completionHandler: ^(NSInteger returnCode) + { + if (returnCode == NSOKButton) + { + float tileFootprintCorrectionFactor = [self leastUpheavalTileFootprintCorrectionFactor]; + + SAH264AvEncoder* encoder = [SAH264AvEncoder new]; + [encoder encode:[self.viewHelper spiritedArraySourceFilePath] TileDrawingStrategy:[self.viewHelper tileDrawingStrategy] WidthInPixels:[self.videoExportSettingsController.videoExportSettings.widthInPixels unsignedIntValue] HeightInPixels:[self.videoExportSettingsController.videoExportSettings.heightInPixels unsignedIntValue] TileWidthInPixels:tileFootprintCorrectionFactor*self.viewHelper.desiredTileWidth TileHeightInPixels:tileFootprintCorrectionFactor*self.viewHelper.desiredTileHeight Url:[panel URL] QuicktimeContainer:YES]; + } + } + ]; +} + +-(float) leastUpheavalTileFootprintCorrectionFactor +{ + float a = [self.videoExportSettingsController.videoExportSettings.widthInPixels floatValue] / (float)self.videoExportSettingsController.initialWidthInPixels; + float b = [self.videoExportSettingsController.videoExportSettings.heightInPixels floatValue] / (float)self.videoExportSettingsController.initialHeightInPixels; + + float c; + + if (a>1 && b>1) + { + if (a>b) + c = b; + else + c = a; + } + else if (a<1 && b<1) + { + if (a>b) + c = a; + else + c = b; + } + else + { + c = 1.0f; + } + + NSLog(@"tileFootprintCorrectionFactor=%f", c); + + return c; +} + +- (IBAction)toggleResizeTileWidthAndHeightTogether:(id)sender +{ + if (!self.viewHelper.resizeTileWidthAndHeightTogether) + { + [self.lockIcon setTitle:@"🔒"]; + self.viewHelper.resizeTileWidthAndHeightTogether = true; + } + else + { + [self.lockIcon setTitle:@"🔓"]; + self.viewHelper.resizeTileWidthAndHeightTogether = false; + } +} + +@end diff --git a/appkit/SAMacView.h b/appkit/SAMacView.h new file mode 100755 index 0000000..a157665 --- /dev/null +++ b/appkit/SAMacView.h @@ -0,0 +1,14 @@ +// +// SAView.h +// spiritedarray +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import +#import "SAViewHelper.h" + +@interface SAMacView : NSView + +@end diff --git a/appkit/SAMacView.m b/appkit/SAMacView.m new file mode 100755 index 0000000..fe64341 --- /dev/null +++ b/appkit/SAMacView.m @@ -0,0 +1,38 @@ +// +// SAView.m +// spiritedarray +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SAMacView.h" +#import "SALayer.h" + +@implementation SAMacView + +/* -(void)drawRect:(NSRect)dirtyRect +{ + CGContextRef context = [[NSGraphicsContext currentContext] graphicsPort]; + [viewHelper drawRect: dirtyRect Context: context Frame: frame]; + + frame++; + + if (frame>=[viewHelper frames]) + frame = 0; +} */ + +-(void) setFrameSize: (NSSize)newSize +{ + [super setFrameSize:newSize]; + // NSLog(@"intercepted setFrameSize. new width = %f, new height = %f", newSize.width, newSize.height); + self.layer.bounds = [self bounds]; + self.layer.position = NSMakePoint(CGRectGetMidX([self bounds]), CGRectGetMidY([self bounds])); + SALayer* saLayer = (SALayer*) self.layer; + + // TODO bounds has changed by more than one tile footprint… + [[saLayer viewHelper] clearCachedSpiritedArray]; + [[saLayer viewHelper] regenerateStatusText]; +} + +@end diff --git a/appkit/SAVideoExportSettingsController.h b/appkit/SAVideoExportSettingsController.h new file mode 100755 index 0000000..97db77f --- /dev/null +++ b/appkit/SAVideoExportSettingsController.h @@ -0,0 +1,28 @@ +// +// SAVideoExportSettingsController.h +// spiritedarray +// +// Created by Dave Horlick on 10/3/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SAVideoExportSettings.h" + +@interface SAVideoExportSettingsController : NSObject < NSTextFieldDelegate > + +@property (weak) IBOutlet NSTextField* widthInPixelsTextField; +@property (weak) IBOutlet NSTextField* heightInPixelsTextField; +@property (weak) IBOutlet NSMatrix* dimensionsRadioButtonMatrix; +@property (weak) IBOutlet SAVideoExportSettings* videoExportSettings; + +@property uint initialWidthInPixels; +@property uint initialHeightInPixels; + +- (IBAction)doExportDimensionsMoreOrLessWindowSize:(id)sender; +- (IBAction)doExportDimensionsFullHighDef:(id)sender; +- (IBAction)doExportDimensionsNonFullHighDef:(id)sender; +- (IBAction)doExportDimensionsMediumStandardDef:(id)sender; +- (IBAction)doExportDimensionsSomewhatLargeWidescreen:(id)sender; + +@end diff --git a/appkit/SAVideoExportSettingsController.m b/appkit/SAVideoExportSettingsController.m new file mode 100755 index 0000000..8dc08c9 --- /dev/null +++ b/appkit/SAVideoExportSettingsController.m @@ -0,0 +1,54 @@ +// +// SAVideoExportSettingsController.m +// spiritedarray +// +// Created by Dave Horlick on 10/3/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAVideoExportSettingsController.h" + +@implementation SAVideoExportSettingsController + +- (IBAction)doExportDimensionsMoreOrLessWindowSize:(id)sender +{ + self.videoExportSettings.widthInPixels = [NSNumber numberWithUnsignedInt:self.initialWidthInPixels]; + self.videoExportSettings.heightInPixels = [NSNumber numberWithUnsignedInt:self.initialHeightInPixels]; +} + +- (IBAction)doExportDimensionsFullHighDef:(id)sender +{ + self.videoExportSettings.widthInPixels = [NSNumber numberWithUnsignedInt:1920U]; + self.videoExportSettings.heightInPixels = [NSNumber numberWithUnsignedInt:1080U]; +} + +- (IBAction)doExportDimensionsNonFullHighDef:(id)sender +{ + self.videoExportSettings.widthInPixels = [NSNumber numberWithUnsignedInt:1280U]; + self.videoExportSettings.heightInPixels = [NSNumber numberWithUnsignedInt:720U]; +} + +- (IBAction)doExportDimensionsMediumStandardDef:(id)sender +{ + self.videoExportSettings.widthInPixels = [NSNumber numberWithUnsignedInt:640U]; + self.videoExportSettings.heightInPixels = [NSNumber numberWithUnsignedInt:480U]; +} + +- (IBAction)doExportDimensionsSomewhatLargeWidescreen:(id)sender +{ + self.videoExportSettings.widthInPixels = [NSNumber numberWithUnsignedInt:853U]; + self.videoExportSettings.heightInPixels = [NSNumber numberWithUnsignedInt:480U]; +} + +- (void)awakeFromNib +{ + self.widthInPixelsTextField.delegate = self; + self.heightInPixelsTextField.delegate = self; +} + +- (BOOL)control:(NSControl *)control isValidObject:(id)object +{ + return [object isKindOfClass:[NSNumber class]]; +} + +@end diff --git a/coregraphics/CoreGraphicsImageDataBackedSpiritedArray.h b/coregraphics/CoreGraphicsImageDataBackedSpiritedArray.h new file mode 100755 index 0000000..ea5c928 --- /dev/null +++ b/coregraphics/CoreGraphicsImageDataBackedSpiritedArray.h @@ -0,0 +1,22 @@ +// +// CoreGraphicsBackedSpiritedArray.h +// spiritedarray +// +// Created by Dave Horlick on 8/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SpiritedArray.h" + +/** + * For handling TIFF's + */ +@interface CoreGraphicsImageDataBackedSpiritedArray : SpiritedArray +{ + const UInt8 *pixelData; +} + +-(id) initWithImage:(CGImageRef)cgImage; +-(id) initWithImageData:(unsigned char*) designatedPixelData Width:(uint)designatedWidth Height:(uint)designatedHeight; + +@end diff --git a/coregraphics/CoreGraphicsImageDataBackedSpiritedArray.m b/coregraphics/CoreGraphicsImageDataBackedSpiritedArray.m new file mode 100755 index 0000000..9c44c2a --- /dev/null +++ b/coregraphics/CoreGraphicsImageDataBackedSpiritedArray.m @@ -0,0 +1,77 @@ +// +// CoreGraphicsBackedSpiritedArray.m +// spiritedarray +// +// Created by Dave Horlick on 8/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "CoreGraphicsImageDataBackedSpiritedArray.h" +#import "SpiritedArray.h" + +@implementation CoreGraphicsImageDataBackedSpiritedArray + +-(id) initWithImage:(CGImageRef)designatedCgImageRef +{ + if (self = [super init]) + { + // TODO make sure input image is of type ARGB + + CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(designatedCgImageRef)); + pixelData = CFDataGetBytePtr(dataRef); + frames = 1U; + width = (uint)CGImageGetWidth(designatedCgImageRef); + height = (uint)CGImageGetHeight(designatedCgImageRef); + } + + return self; +} + +-(id) initWithImageData:(unsigned char*) designatedPixelData Width:(uint)designatedWidth Height:(uint)designatedHeight +{ + if (self = [super init]) + { + // TODO make sure input image is of type ARGB + + pixelData = designatedPixelData; + frames = 1U; + width = designatedWidth; + height = designatedHeight; + } + + return self; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + if (frame!=0) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Frame index must be zero, it's %u", frame] + userInfo:nil]; + } + + uint i = 3*(x + (y*width)); + UInt8 green = pixelData[i++]; + UInt8 blue = pixelData[i++]; + UInt8 red = pixelData[i++]; + SAColorType pixel = {red, green, blue}; + + return pixel; +} + +- (uint) delayInCentisAfterFrame: (uint)frame +{ + return 10L; + // TODO rework the animation not to flip at all if there's only one frame +} + +- (void) dealloc +{ + // if (pixelData) + // free((void*)pixelData); + + // TODO uncomment-out above? +} + +@end diff --git a/coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.h b/coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.h new file mode 100755 index 0000000..9b0ba16 --- /dev/null +++ b/coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.h @@ -0,0 +1,19 @@ +// +// CoreGraphicsRGBADataBackedSpirtedArray.h +// spiritedarray +// +// Created by Dave Horlick on 9/15/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SpiritedArray.h" + +@interface CoreGraphicsRGBADataBackedSpiritedArray : SpiritedArray +{ + const UInt8 *pixelData; +} + +-(id) initWithImage:(CGImageRef)cgImage; +-(id) initWithImageData:(unsigned char*) designatedPixelData Width:(uint)designatedWidth Height:(uint)designatedHeight; + +@end diff --git a/coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.m b/coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.m new file mode 100755 index 0000000..c3b9664 --- /dev/null +++ b/coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.m @@ -0,0 +1,72 @@ +// +// CoreGraphicsRGBADataBackedSpirtedArray.m +// spiritedarray +// +// Created by Dave Horlick on 9/15/13. +// Copyleft 2013 River Porpoise Software +// + +#import "CoreGraphicsRGBADataBackedSpiritedArray.h" + +@implementation CoreGraphicsRGBADataBackedSpiritedArray +-(id) initWithImage:(CGImageRef)designatedCgImageRef +{ + if (self = [super init]) + { + CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(designatedCgImageRef)); + pixelData = CFDataGetBytePtr(dataRef); + frames = 1U; + width = (uint)CGImageGetWidth(designatedCgImageRef); + height = (uint)CGImageGetHeight(designatedCgImageRef); + } + + return self; +} + +-(id) initWithImageData:(unsigned char*) designatedPixelData Width:(uint)designatedWidth Height:(uint)designatedHeight +{ + if (self = [super init]) + { + pixelData = designatedPixelData; + frames = 1U; + width = designatedWidth; + height = designatedHeight; + } + + return self; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + if (frame!=0) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Frame index must be zero, it's %u", frame] + userInfo:nil]; + } + + uint i = 4*(x + (y*width)); + UInt8 red = pixelData[i++]; + UInt8 green = pixelData[i++]; + UInt8 blue = pixelData[i++]; + // i++; // (alpha) + SAColorType pixel = {red, green, blue}; + + return pixel; +} + +- (uint) delayInCentisAfterFrame: (uint)frame +{ + return 10L; + // TODO rework the animation not to flip at all if there's only one frame +} + +- (void) dealloc +{ + // if (pixelData) + // free((void*)pixelData); + + // TODO uncomment-out above? +} + +@end diff --git a/coregraphics/ImageMetapixelPalette.h b/coregraphics/ImageMetapixelPalette.h new file mode 100755 index 0000000..012ad7e --- /dev/null +++ b/coregraphics/ImageMetapixelPalette.h @@ -0,0 +1,29 @@ +// +// ImageMetapixelPalette.h +// spiritedarray +// +// Created by Dave Horlick on 4/11/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SATileDrawingStrategy.h" + +/** + Used for managing a palette of tiles rendered for different colors based on + the supplied Tile Drawing strategy. Outputs CGImageRef's. + + The content of these tiles is not animated. + */ +@interface ImageMetapixelPalette : NSObject +{ + SATileDrawingStrategy* strategy; + NSMutableDictionary* palette; +} + +-(id)initWith: (SATileDrawingStrategy*) designatedTileDrawingStrategy; +-(CGImageRef) metapixelForColor: (SAColorType) color; +-(SATileDrawingStrategy*) strategy; +-(NSUInteger)cachedMetapixelCount; + +@end diff --git a/coregraphics/ImageMetapixelPalette.m b/coregraphics/ImageMetapixelPalette.m new file mode 100755 index 0000000..73ad050 --- /dev/null +++ b/coregraphics/ImageMetapixelPalette.m @@ -0,0 +1,66 @@ +// +// ImageMetapixelPalette.m +// spiritedarray +// +// Created by Dave Horlick on 4/11/13. +// Copyleft 2013 River Porpoise Software +// + +#import "ImageMetapixelPalette.h" +#import "SAMetapixelPalette.h" + +@implementation ImageMetapixelPalette + +-(id)initWith: (SATileDrawingStrategy*) designatedTileDrawingStrategy +{ + self = [super init]; + if (self) + { + strategy = designatedTileDrawingStrategy; + palette = [NSMutableDictionary new]; + } + + return self; +} + +-(CGImageRef) metapixelForColor: (SAColorType) color +{ + uint colorIndex = [SAMetapixelPalette indexFor: color]; + NSNumber* key = [NSNumber numberWithUnsignedInt: colorIndex]; + NSValue* intermediateResult = [palette objectForKey:key]; + + if (intermediateResult == nil) + { + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + size_t bitsPerComponent = 8; + size_t bytesPerPixel = 4; + size_t bytesPerRow = ([strategy metapixelWidthInPixels] * bitsPerComponent * bytesPerPixel + 7) / 8; // TODO why isn't this just 4 * width? To leave some kind of margin? + CGContextRef context = CGBitmapContextCreate(NULL, [strategy metapixelWidthInPixels], [strategy metapixelHeightInPixels], bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); + + [strategy drawX:0U Y:0U Color:color Context:context Height:1U]; // TODO wrong + CGImageRef imageRef = CGBitmapContextCreateImage(context); + + CGColorSpaceRelease(colorSpace); + CGContextRelease(context); + + intermediateResult = [NSValue valueWithBytes:&imageRef objCType:@encode(CGImageRef)]; + [palette setObject:intermediateResult forKey:key]; + } + + CGImageRef retrievedCGImageRef; + [intermediateResult getValue:&retrievedCGImageRef]; + return retrievedCGImageRef; +} + +-(SATileDrawingStrategy*) strategy +{ + return strategy; +} + +-(NSUInteger) cachedMetapixelCount +{ + return [palette count]; +} + +@end diff --git a/coregraphics/SACoreGraphicsConverter.h b/coregraphics/SACoreGraphicsConverter.h new file mode 100755 index 0000000..41f1e17 --- /dev/null +++ b/coregraphics/SACoreGraphicsConverter.h @@ -0,0 +1,24 @@ +// +// SACoreGraphicsConverter.h +// spiritedarray +// +// Created by Dave Horlick on 3/5/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "MemorizedSpiritedArray.h" +#import "SpiritedArray.h" + +@interface SACoreGraphicsConverter : NSObject + +/** + * You need to call CGImageRelease on returned images when done with them. + */ ++(CGImageRef) convertToCoreGraphicsImage: (SpiritedArray*)spiritedArray Frame: (uint) frame; + +// +(void) transcribe: (CGImageRef)cgImage ToSpiritedArray:(SpiritedArray*)spiritedArray; + +// +(MemorizedSpiritedArray*) convertToMemorizedSpiritedArray:(CGImageRef)cgImage; + +@end diff --git a/coregraphics/SACoreGraphicsConverter.m b/coregraphics/SACoreGraphicsConverter.m new file mode 100755 index 0000000..876b456 --- /dev/null +++ b/coregraphics/SACoreGraphicsConverter.m @@ -0,0 +1,61 @@ +// +// SACoreGraphicsConverter.m +// spiritedarray +// +// Created by Dave Horlick on 3/5/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SACoreGraphicsConverter.h" +#import "SAMetapixelPalette.h" +#import "CoreGraphicsImageDataBackedSpiritedArray.h" +#import + +@implementation SACoreGraphicsConverter + ++(CGImageRef) convertToCoreGraphicsImage: (SpiritedArray*)spiritedArray Frame: (uint) frame +{ + uint arrLength = [spiritedArray width] * [spiritedArray height] * 3; + UInt8 pixelData[arrLength]; + + // fill the raw pixel buffer with arbitrary gray color for test + + uint i=0; + + for (int y=0; y<[spiritedArray height]; y++) + { + for (int x=0; x<[spiritedArray width]; x++) + { + SAColorType color = [spiritedArray pixelColorAtFrame:frame X:x Y:y]; + // pixelData[i++] = [SAMetapixelPalette indexFor:color]; + pixelData[i++] = color.Red; + pixelData[i++] = color.Green; + pixelData[i++] = color.Blue; + } + } + + CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB(); + + CFDataRef rgbData = CFDataCreate(NULL, pixelData, arrLength); + + CGDataProviderRef provider = CGDataProviderCreateWithCFData(rgbData); + + CGImageRef rgbImageRef = CGImageCreate([spiritedArray width], [spiritedArray height], 8, 24, [spiritedArray width] * 3, colorspace, kCGBitmapByteOrderDefault, provider, NULL, false, kCGRenderingIntentDefault); + + CFRelease(rgbData); + + CGDataProviderRelease(provider); + + CGColorSpaceRelease(colorspace); + + return rgbImageRef; +} + +/* ++(CoreGraphicsImageDataBackedSpiritedArray*) convertToMemorizedSpiritedArray:(CGImageRef)cgImage +{ + return [[CoreGraphicsImageDataBackedSpiritedArray alloc] initWithImage: cgImage]; +} +*/ + +@end diff --git a/coregraphics/SAFrameWheelViewHelper.h b/coregraphics/SAFrameWheelViewHelper.h new file mode 100755 index 0000000..75b100b --- /dev/null +++ b/coregraphics/SAFrameWheelViewHelper.h @@ -0,0 +1,31 @@ +// +// SAFrameWheelViewHelper.h +// spiritedarray +// +// Created by Dave Horlick on 4/15/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SpiritedArray.h" + +@interface SAFrameWheelViewHelper : NSObject +{ + SpiritedArray* spiritedArray; + uint gapBetweenFramesInPixels; +} + +-(uint) ringOuterWidthInPixels; +-(uint) ringInnerWidthInPixels; +-(uint) ringThickness; +-(double) startAngleInRadiansFor:(uint)frame; +-(double) endAngleInRadiansFor:(uint)frame; + +/** + * @return a zero-ordered frame index, or -1 if no frame was clicked in. + */ +-(uint) frameAtX:(uint)x Y:(uint) y; + +-(void)drawRect:(NSRect)dirtyRect Context:(CGContextRef)context; + +@end diff --git a/coregraphics/SAFrameWheelViewHelper.m b/coregraphics/SAFrameWheelViewHelper.m new file mode 100755 index 0000000..dd972ce --- /dev/null +++ b/coregraphics/SAFrameWheelViewHelper.m @@ -0,0 +1,54 @@ +// +// SAFrameWheelViewHelper.m +// spiritedarray +// +// Created by Dave Horlick on 4/15/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAFrameWheelViewHelper.h" + +@implementation SAFrameWheelViewHelper + +-(uint) ringOuterWidthInPixels +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Not yet implemented." userInfo: nil]; + return 0U; +} + +-(uint) ringInnerWidthInPixels +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Not yet implemented." userInfo: nil]; + return 0U; +} + +-(uint) ringThickness +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Not yet implemented." userInfo: nil]; + return 0U; +} + +-(double) startAngleInRadiansFor:(uint)frame +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Not yet implemented." userInfo: nil]; + return 0.0; +} + +-(double) endAngleInRadiansFor:(uint)frame +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Not yet implemented." userInfo: nil]; + return 0.0; +} + +-(uint) frameAtX:(uint)x Y:(uint) y +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Not yet implemented." userInfo: nil]; + return 0U; +} + +-(void)drawRect:(NSRect)dirtyRect Context:(CGContextRef)context +{ + // TODO … +} + +@end diff --git a/coregraphics/SAH264AvEncoder.h b/coregraphics/SAH264AvEncoder.h new file mode 100755 index 0000000..1f89f02 --- /dev/null +++ b/coregraphics/SAH264AvEncoder.h @@ -0,0 +1,18 @@ +// +// SAH264AvEncoder.h +// spiritedarray +// +// Created by Dave Horlick on 9/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SAViewHelper.h" + +@interface SAH264AvEncoder : NSObject +{ +} + +-(void) encode:(NSString*)spiritedArraySourceFilePath TileDrawingStrategy:tileDrawingStrategy WidthInPixels:(uint)widthInPixels HeightInPixels:(uint)heightInPixels TileWidthInPixels:(uint)tileWidthInPixels TileHeightInPixels:(uint)tileHeightInPixels Url:(NSURL*)url QuicktimeContainer:(BOOL)quicktimeContainer; + +@end diff --git a/coregraphics/SAH264AvEncoder.m b/coregraphics/SAH264AvEncoder.m new file mode 100755 index 0000000..ae0f248 --- /dev/null +++ b/coregraphics/SAH264AvEncoder.m @@ -0,0 +1,138 @@ +// +// SAH264AvEncoder.m +// spiritedarray +// +// Created by Dave Horlick on 9/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAH264AvEncoder.h" +#import +#import "SATileDrawingStrategy.h" +#import "SAMacroblockedBounded.h" +#import "SAConcreteBounded.h" + +@implementation SAH264AvEncoder + +-(void) encode:(NSString*)spiritedArraySourceFilePath TileDrawingStrategy:tileDrawingStrategy WidthInPixels:(uint)widthInPixels HeightInPixels:(uint)heightInPixels TileWidthInPixels:(uint)tileWidthInPixels TileHeightInPixels:(uint)tileHeightInPixels Url:(NSURL*)url QuicktimeContainer:(BOOL)quicktimeContainer +{ + // borrowed liberally from http://stackoverflow.com/questions/3741323/how-do-i-export-uiimage-array-as-a-movie/3742212#3742212 and http://www.codegod.com/AVAssetWriterInputPixelBufferAdaptor-use-to-append-QID1296437.aspx : + + NSRect rect; + rect.origin.x = 0; + rect.origin.y = 0; + rect.size.width = widthInPixels; + rect.size.height = heightInPixels; + + SAConcreteBounded* concreteBounded = [[SAConcreteBounded alloc] initWith: rect]; + + SAMacroblockedBounded* replacementBounded = [[SAMacroblockedBounded alloc] initWithBounded:concreteBounded AndMacroblockOfWidth:8U AndHeight:8U]; + NSLog(@"replacementBounded = %@", replacementBounded); + + SAViewHelper* h264ViewHelper = [[SAViewHelper alloc] initWith:replacementBounded Path:spiritedArraySourceFilePath]; + [h264ViewHelper setTileDrawingStrategy:tileDrawingStrategy]; + h264ViewHelper.desiredTileWidth = tileWidthInPixels; + h264ViewHelper.desiredTileHeight = tileHeightInPixels; + + NSLog(@"newBounded = %@", [h264ViewHelper bounded]); + NSLog(@" (width=%f, height=%f)", [h264ViewHelper bounds].size.width, [h264ViewHelper bounds].size.height); + + // 1) Wire the writer: + + CGSize frameSize = {[h264ViewHelper bounds].size.width, [h264ViewHelper bounds].size.height}; + + NSError *error = nil; + + NSString* outputFileType = nil; + if (quicktimeContainer) + outputFileType = AVFileTypeQuickTimeMovie; + else + outputFileType = AVFileTypeMPEG4; + + AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL: url fileType:outputFileType error:&error]; + NSParameterAssert(videoWriter); + if (!quicktimeContainer) + videoWriter.shouldOptimizeForNetworkUse = YES; + + NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: + AVVideoCodecH264, AVVideoCodecKey, + [NSNumber numberWithInt:frameSize.width], AVVideoWidthKey, + [NSNumber numberWithInt:frameSize.height], AVVideoHeightKey, + nil]; + AVAssetWriterInput* writerInput = [AVAssetWriterInput + assetWriterInputWithMediaType:AVMediaTypeVideo + outputSettings:videoSettings]; + + NSParameterAssert(writerInput); + NSParameterAssert([videoWriter canAddInput:writerInput]); + [videoWriter addInput:writerInput]; + + NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithBool:YES], kCVPixelBufferCGBitmapContextCompatibilityKey, + [NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, nil]; + + AVAssetWriterInputPixelBufferAdaptor* adaptor = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput sourcePixelBufferAttributes:options]; + + [videoWriter startWriting]; + [videoWriter startSessionAtSourceTime:kCMTimeZero]; + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + + size_t bitsPerComponent = 8; + size_t bytesPerPixel = 4; + size_t bytesPerRow = frameSize.width * bytesPerPixel; + + __block int time = 0; + __block uint frame = 0U; + + dispatch_queue_t assetWriterQueue = dispatch_queue_create("AssetWriterQueue", DISPATCH_QUEUE_SERIAL); // thanks, http://stackoverflow.com/questions/14121511/avassetwriter-sometimes-fails-with-status-avassetwriterstatusfailed-seems-rando + + [writerInput requestMediaDataWhenReadyOnQueue:assetWriterQueue usingBlock:^(void) + { + NSLog(@" again, width=%f, height=%f", [h264ViewHelper bounds].size.width, [h264ViewHelper bounds].size.height); + + while ([writerInput isReadyForMoreMediaData]) + { + // NSLog(@"encoding frame #%d", frame); + CVPixelBufferRef pxbuffer = NULL; + CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault, frameSize.width, + frameSize.height, kCVPixelFormatType_32ARGB, (__bridge CFDictionaryRef) options, + &pxbuffer); // Note that kCVPixelFormatType_32RGBA, which we use elsewhere, is not supported + NSParameterAssert(status == kCVReturnSuccess && pxbuffer != NULL); + + CVPixelBufferLockBaseAddress(pxbuffer, 0); + void *pxdata = CVPixelBufferGetBaseAddress(pxbuffer); + NSParameterAssert(pxdata != NULL); + + CGContextRef context = CGBitmapContextCreate(pxdata, frameSize.width, frameSize.height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaNoneSkipFirst); + + [h264ViewHelper drawRect:CGRectMake(0, 0, frameSize.width, frameSize.height) Context:context Frame: frame]; + NSParameterAssert(context); + CVPixelBufferUnlockBaseAddress(pxbuffer, 0); + + CVPixelBufferRef buffer = (CVPixelBufferRef)pxbuffer; + + if(![adaptor appendPixelBuffer:buffer withPresentationTime:CMTimeMake(time, 100)]) + { + @throw [NSException exceptionWithName:@"Can't appendPixelBuffer" reason:nil userInfo: nil]; + } + + time += [[h264ViewHelper content] delayInCentisAfterFrame:frame]; + frame++; + + if (frame >= [[h264ViewHelper content] frames]) + { + NSLog(@"our work is done here."); + [writerInput markAsFinished]; + [videoWriter endSessionAtSourceTime:CMTimeMake(time,100)]; + [videoWriter finishWriting]; + } + + // CGColorSpaceRelease(colorSpace); // see http://stackoverflow.com/questions/5269815/does-the-result-of-cgimagegetcolorspaceimage-have-to-be-released + CGContextRelease(context); + } + } + ]; +} + +@end diff --git a/coregraphics/SALayer.h b/coregraphics/SALayer.h new file mode 100755 index 0000000..7942d30 --- /dev/null +++ b/coregraphics/SALayer.h @@ -0,0 +1,22 @@ +// +// SALayer.h +// spiritedarray +// +// Created by Dave Horlick on 3/13/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SAViewHelper.h" + +@interface SALayer : CALayer +{ + SAViewHelper* viewHelper; +} +// @property (nonatomic) uint frameIndex; // TODO add "assign"? +@property (nonatomic) int timeValue; + +-(id)initWithViewHelper: (SAViewHelper*) designatedViewHelper; +-(SAViewHelper*) viewHelper; + +@end diff --git a/coregraphics/SALayer.m b/coregraphics/SALayer.m new file mode 100755 index 0000000..146b383 --- /dev/null +++ b/coregraphics/SALayer.m @@ -0,0 +1,73 @@ +// +// SALayer.m +// spiritedarray +// +// Created by Dave Horlick on 3/13/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SALayer.h" + +@implementation SALayer + +- (id)init +{ + [NSException raise:@"Unsupported Operation Exception" + format:@"Call initWith:designatedBounded, instead at %d", (int)__LINE__]; + + return self; +} + +-(id)initWithViewHelper: (SAViewHelper*) designatedViewHelper +{ + self = [super init]; + if (self) + { + viewHelper = designatedViewHelper; + // self.frameIndex = 0; + self.timeValue = 0; + [self setNeedsDisplay]; + } + + return self; +} + +- (id)initWithLayer:(id)layer +{ + if (self = [super initWithLayer:layer]) + { + if ([layer isKindOfClass:[SALayer class]]) + { + SALayer* other = (SALayer*) layer; + self.timeValue = other.timeValue; + viewHelper = [other viewHelper]; + } + } + + return self; +} + ++ (BOOL)needsDisplayForKey:(NSString *)key +{ + if ([key isEqualToString:@"timeValue"]) + { + return YES; + } + + return [super needsDisplayForKey:key]; +} + + +-(void)drawInContext:(CGContextRef)context +{ + [viewHelper drawRect:[self bounds] Context:context Frame:self.timeValue]; +} + +-(SAViewHelper*) viewHelper +{ + return viewHelper; +} + +@dynamic timeValue; + +@end diff --git a/coregraphics/SAMacroblockedBounded.h b/coregraphics/SAMacroblockedBounded.h new file mode 100755 index 0000000..83ba5f1 --- /dev/null +++ b/coregraphics/SAMacroblockedBounded.h @@ -0,0 +1,23 @@ +// +// SAH264Bounded.h +// spiritedarray +// +// Created by Dave Horlick on 9/22/13. +// Copyleft 2013 River Porpoise Software +// + +#import + +@interface SAMacroblockedBounded : NSObject +{ + uint macroblockWidth; + uint macroblockHeight; +} + +@property id bounded; + +-(id)initWithBounded:(NSObject*) designatedBounded AndMacroblockOfWidth:(uint)designatedMacroblockWidth AndHeight:(uint)designatedMacroblockHeight; +-(NSRect)bounds; ++(NSRect)makeRectWithWidth:(int) width Height:(int) height; + +@end diff --git a/coregraphics/SAMacroblockedBounded.m b/coregraphics/SAMacroblockedBounded.m new file mode 100755 index 0000000..3094cd8 --- /dev/null +++ b/coregraphics/SAMacroblockedBounded.m @@ -0,0 +1,66 @@ +// +// SAH264Bounded.m +// spiritedarray +// +// Created by Dave Horlick on 9/22/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAMacroblockedBounded.h" + +@implementation SAMacroblockedBounded + +-(id)initWithBounded:(NSObject*) designatedBounded AndMacroblockOfWidth:(uint)designatedMacroblockWidth AndHeight:(uint)designatedMacroblockHeight +{ + self = [super init]; + if (self) + { + if(![designatedBounded respondsToSelector:@selector(bounds)]) + { + [NSException raise:@"MyDelegate Exception" + format:@"Parameter lacks a bounds selector at %d", (int)__LINE__]; + } + + if (designatedMacroblockWidth==0U) + { + [NSException raise:@"IllegalArgument" format:@"Macroblock width cannot be zero."]; + } + if (designatedMacroblockHeight==0U) + { + [NSException raise:@"IllegalArgument" format:@"Macroblock height cannot be zero."]; + } + + _bounded = designatedBounded; + macroblockWidth = designatedMacroblockWidth; + macroblockHeight = designatedMacroblockHeight; + } + + return self; +} + +-(NSRect)bounds +{ + NSRect bounds = (NSRect)[_bounded bounds]; + return [SAMacroblockedBounded makeRectWithWidth:macroblockWidth * (int)ceil((double)bounds.size.width / (double)macroblockWidth) + Height:macroblockHeight * (int)ceil((double)bounds.size.height / (double)macroblockHeight)]; +} + ++(NSRect)makeRectWithWidth:(int) width Height:(int) height +{ + NSRect myRect; + + myRect.origin.x = 0; + myRect.origin.y = 0; + myRect.size.width = width; + myRect.size.height = height; + + return myRect; +} + +-(NSString *)description +{ + NSRect bounds = [self bounds]; + return [NSString stringWithFormat:@"", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height, macroblockWidth, macroblockHeight]; +} + +@end diff --git a/coregraphics/SAViewHelper.h b/coregraphics/SAViewHelper.h new file mode 100755 index 0000000..0fd7af1 --- /dev/null +++ b/coregraphics/SAViewHelper.h @@ -0,0 +1,55 @@ +// +// SAViewHelper.h +// spiritedarray +// +// Created by Dave Horlick on 3/10/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import +#import "SpiritedArray.h" +#import "MemorizedSpiritedArray.h" +#import "SAMetapixelPalette.h" +#import "SATileDrawingStrategy.h" +#import "ImageMetapixelPalette.h" + +@interface SAViewHelper : NSObject +{ + NSString* spiritedArraySourceFilePath; // TODO change this to an NSArray* of string? + SpiritedArray* content; + SpiritedArray* tileContent; + SAMetapixelPalette* scaledMetapixelPalette; + SATileDrawingStrategy* tileDrawingStrategy; + ImageMetapixelPalette* imageMetapixelPalette; + uint desiredTileWidth; + uint desiredTileHeight; +} + +@property id bounded; +@property uint desiredTileWidth; +@property uint desiredTileHeight; +@property BOOL resizeTileWidthAndHeightTogether; +@property NSString* statusText; + +-(id)initWith:(NSObject*)designatedBounded Path:(NSString*) designatedSpiritedArraySourceFilePath; + +-(NSString*) spiritedArraySourceFilePath; +-(void) setSpiritedArraySourceFilePath: (NSString*)setSpiritedArraySourceFilePath; + +-(void) clearCachedSpiritedArray; +-(void)drawRect:(NSRect)dirtyRect Context:(CGContextRef)context Frame: (uint)frame; +-(MemorizedSpiritedArray*) freeze; + +-(SpiritedArray*) content; +-(SpiritedArray*) tileContent; +-(void) setTileDrawingStrategy: (SATileDrawingStrategy*) designatedTileDrawingStrategy; +-(SATileDrawingStrategy*) tileDrawingStrategy; + +-(uint) frames; +-(NSRect) bounds; +-(uint) desiredTileWidth; +-(uint) desiredTileHeight; +-(void) regenerateStatusText; + +@end diff --git a/coregraphics/SAViewHelper.m b/coregraphics/SAViewHelper.m new file mode 100755 index 0000000..56084de --- /dev/null +++ b/coregraphics/SAViewHelper.m @@ -0,0 +1,408 @@ +// +// SAViewHelper.m +// spiritedarray +// +// Created by Dave Horlick on 3/10/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAViewHelper.h" +#import "SpiritedArray.h" +#import "OptimizedSpiritedArray.h" +#import "UnUpSampler.h" +#import "SAMetapixelPalette.h" +#import "SACoreGraphicsConverter.h" +#import "SAFatBitsTileDrawingStrategy.h" +#import "SALightEmittingDiodeTileDrawingStrategy.h" +#import "AppKitAwareSpiritedArrayFactory.h" +#import "CoreGraphicsRGBADataBackedSpiritedArray.h" +#import + +@implementation SAViewHelper + +-(id)init +{ + [NSException raise:@"Unsupported Operation Exception" + format:@"Call initWith:designatedBounded, instead at %d", (int)__LINE__]; + + return self; +} + +-(id)initWith:(NSObject*)designatedBounded Path:(NSString*) designatedSpiritedArraySourceFilePath +{ + self = [super init]; + if (self) + { + if(![designatedBounded respondsToSelector:@selector(bounds)]) + { + [NSException raise:@"MyDelegate Exception" + format:@"Parameter lacks a bounds selector at %d", (int)__LINE__]; + } + + _bounded = designatedBounded; + self.resizeTileWidthAndHeightTogether = YES; + + [self setSpiritedArraySourceFilePath: designatedSpiritedArraySourceFilePath]; + self.desiredTileWidth = 20U; + self.desiredTileHeight = 20U; + [self obtainSpiritedArray]; + [self regenerateStatusText]; + } + + return self; +} + +-(void)drawRect:(NSRect)dirtyRect Context:(CGContextRef)context Frame: (uint)frame +{ + // TODO do something with dirtyRect? + + SpiritedArray* spiritedArray = [self obtainSpiritedArray]; + + if (spiritedArray == nil || [spiritedArray frames]==0) + { + NSLog(@"NOT drawing GIF"); + } + else + { + // NSLog(@"drawing GIF %u x %u frame #%u…", [spiritedArray width], [spiritedArray height], frame); + + if (tileDrawingStrategy!=nil) + { + SAColorType backgroundColor = [tileDrawingStrategy backgroundColor]; + CGContextSetRGBFillColor(context, + backgroundColor.Red/255.0f, + backgroundColor.Green/255.0f, + backgroundColor.Blue/255.0f, + 1.0f); + CGContextFillRect(context, [self bounds]); + } + else + { + if (scaledMetapixelPalette == nil + || [[scaledMetapixelPalette content] width]!=self.desiredTileWidth + || [[scaledMetapixelPalette content] height]!=self.desiredTileHeight) + { + // Resize the tile content + + NSLog(@"Resizing tile content cache…"); + scaledMetapixelPalette = [[SAMetapixelPalette alloc] initWith:[tileContent fitCopyToWidth:self.desiredTileWidth Height:desiredTileHeight]]; + } + } + + if ([self bounds].size.width==0) + [NSException raise:@"IllegalArgument" format:@"Bounds width is zero."]; + if ([self bounds].size.height==0) + [NSException raise:@"IllegalArgument" format:@"Bounds height is zero."]; + + float shiftX = ceilf(([self bounds].size.width - [spiritedArray width]*self.desiredTileWidth) / 2.0); + float shiftY = ceilf(([self bounds].size.height - [spiritedArray height]*self.desiredTileHeight) / 2.0); + // NSLog(@"shiftX=%f, shiftY=%f", shiftX, shiftY); + CGContextTranslateCTM(context, shiftX, shiftY); + + for (int y=0; y<[spiritedArray height]; y++) + { + for (int x=0; x<[spiritedArray width]; x++) + { + SAColorType pixelColor = [spiritedArray pixelColorAtFrame:frame X:x Y:y]; + + // if (tileContent==nil) // TODO or, if the Tile content won't fit + if (tileDrawingStrategy!=nil) + { + // TODO refrain from caching CGImages for non-GIF images with enormous color palettes? + // [tileDrawingStrategy drawX:x Y:y Color:pixelColor Context:context Height:[spiritedArray height]]; + + if (imageMetapixelPalette==nil + || [tileDrawingStrategy metapixelWidthInPixels]!=self.desiredTileWidth + || [tileDrawingStrategy metapixelHeightInPixels]!=self.desiredTileHeight) + { + [tileDrawingStrategy setMetapixelWidthInPixels:self.desiredTileWidth]; + [tileDrawingStrategy setMetapixelHeightInPixels:self.desiredTileHeight]; + imageMetapixelPalette = [[ImageMetapixelPalette alloc] initWith:tileDrawingStrategy]; + } + + CGImageRef cgImageRef = [imageMetapixelPalette metapixelForColor:pixelColor]; + CGContextDrawImage(context, CGRectMake(x*self.desiredTileWidth, ([spiritedArray height]-y)*self.desiredTileHeight, self.desiredTileWidth, self.desiredTileHeight), cgImageRef); + } + else + { + MemorizedSpiritedArray* memoized = [scaledMetapixelPalette metapixelForColor: pixelColor]; + + CGImageRef imageRef = [SACoreGraphicsConverter convertToCoreGraphicsImage: memoized Frame:frame]; // TODO manage these in a separate container + + CGRect rect = CGRectMake(x*desiredTileWidth, + ([spiritedArray height]-y)*self.desiredTileHeight, + [memoized width], + [memoized height]); + + CGContextDrawImage(context, rect, imageRef); + CGImageRelease(imageRef); + } + } + } + + CGContextTranslateCTM(context, -shiftX, -shiftY); + } +} + +-(NSString*) spiritedArraySourceFilePath +{ + return spiritedArraySourceFilePath; +} + +-(void) setSpiritedArraySourceFilePath: (NSString*) designatedSpiritedArraySourceFilePath +{ + spiritedArraySourceFilePath = designatedSpiritedArraySourceFilePath; +} + +-(SpiritedArray*)obtainSpiritedArray +{ + if (content==nil) + { + if (spiritedArraySourceFilePath!=nil) + { + NSLog(@"generating spirited array…"); + SpiritedArray* spiritedArrayFromFile = [AppKitAwareSpiritedArrayFactory build:spiritedArraySourceFilePath]; // TODO Obtain the factory from a factory factory (sigh) + OptimizedSpiritedArray* optimizedSpiritedArray = [[OptimizedSpiritedArray alloc] initWith:spiritedArrayFromFile]; + // TODO stop doing this… wasteful + UnUpSampler* unUpSampler = [[UnUpSampler alloc] initWith: optimizedSpiritedArray TargetWidth:[self bounds].size.width TargetHeight:[self bounds].size.height TileWidth:desiredTileWidth TileHeight:desiredTileHeight]; + // TODO parameterize the tile bounds + // TODO make sure view starts at the origin + content = unUpSampler; + + tileContent = unUpSampler; // TODO get this from a separate input, instead + [self regenerateStatusText]; + // [optimizedSpiritedArray close]; // TODO really safe? + } + else + { + return nil; + } + } + + return content; +} + +-(uint)desiredTileWidth +{ + return desiredTileWidth; +} + +-(void) setDesiredTileWidth:(uint)designatedDesiredTileWidth +{ + if (designatedDesiredTileWidth!=desiredTileWidth) + { + desiredTileWidth = designatedDesiredTileWidth; + tileContent = nil; + content = nil; + } + + if (self.resizeTileWidthAndHeightTogether && designatedDesiredTileWidth!=desiredTileHeight) + { + self.desiredTileHeight = designatedDesiredTileWidth; + tileContent = nil; + content = nil; + } +} + +-(uint)desiredTileHeight +{ + return desiredTileHeight; +} + +-(void) setDesiredTileHeight:(uint)designatedDesiredTileHeight +{ + if (designatedDesiredTileHeight!=desiredTileHeight) + { + desiredTileHeight = designatedDesiredTileHeight; + tileContent = nil; + content = nil; + } + + if (self.resizeTileWidthAndHeightTogether && designatedDesiredTileHeight!=desiredTileWidth) + { + self.desiredTileWidth = designatedDesiredTileHeight; + tileContent = nil; + content = nil; + } +} + +-(void) clearCachedSpiritedArray +{ + if (content!=nil) + { + content = nil; + } +} + +-(NSRect) bounds +{ + if (_bounded==nil) + { + [NSException raise:@"SAViewHelper Unitialized" + format:@"_bounded property has not been configured at %d", (int)__LINE__]; + } + + return [_bounded bounds]; +} + +-(MemorizedSpiritedArray*) freeze +{ + NSRect bounds = [self bounds]; + MemorizedSpiritedArray* result = [[MemorizedSpiritedArray alloc] initWith:[content frames] Width:bounds.size.width Height:bounds.size.height]; + // TODO tighten-up framing here. + // TODO also, not super-efficient to store entire thing in memory. Maybe do this (or optionally do this) via a SpiritedArrayIterator? + + if (tileDrawingStrategy!=nil) + [result fillWithColor: [tileDrawingStrategy backgroundColor]]; + else + [result fillWithColor: [SpiritedArray black]]; + + SpiritedArray* spiritedArray = [self obtainSpiritedArray]; + + for (uint f=0; f<[content frames]; f++) + { + // TODO center + + // TODO introduce SATileBlittingStrategies? Or would that perform badly for command line users providing their own tiles? + + for (int y=0; y<[spiritedArray height]; y++) + { + for (int x=0; x<[spiritedArray width]; x++) + { + SAColorType pixelColor = [spiritedArray pixelColorAtFrame:f X:x Y:y]; + + if (tileDrawingStrategy!=nil) + // if (tileContent==nil) // TODO or, if the Tile content won't fit + { + if (imageMetapixelPalette==nil + || [tileDrawingStrategy metapixelWidthInPixels]!=desiredTileWidth + || [tileDrawingStrategy metapixelHeightInPixels]!=desiredTileHeight) + { + [tileDrawingStrategy setMetapixelWidthInPixels:desiredTileWidth]; + [tileDrawingStrategy setMetapixelHeightInPixels:desiredTileHeight]; + imageMetapixelPalette = [[ImageMetapixelPalette alloc] initWith:tileDrawingStrategy]; + } + + CGImageRef cgImageRef = [imageMetapixelPalette metapixelForColor:pixelColor]; + + // transcribe cgImageRef to memorized spirited array + CoreGraphicsRGBADataBackedSpiritedArray* metapixel = [[CoreGraphicsRGBADataBackedSpiritedArray alloc] initWithImage:cgImageRef]; + + uint yy0 = y*desiredTileHeight; + uint xx0 = x*desiredTileWidth; + + for (int yy=yy0; yy1) // TODO try to ensure this isn't forcing unnecessary memorization + { + float rateInFpsTimes10000 = 100.0f/(float)[content averageDelayInCentisBetweenFrames]; + uint integerRateInFps = (uint)round(rateInFpsTimes10000); + uint firstFourFractionalDigitsOfRateInFps = integerRateInFps % 10000U; + + bool uniformFrameRate = YES; + for (uint i=1; uniformFrameRate && i<[content frames]; i++) + { + if ([content delayInCentisAfterFrame:i]!=[content delayInCentisAfterFrame:i-1]) + uniformFrameRate = NO; + } + + stagedText = [stagedText stringByAppendingString: [NSString stringWithFormat:@", rate%@%u.%u f/s", uniformFrameRate?@"=":@"≈", integerRateInFps, firstFourFractionalDigitsOfRateInFps]]; + + if ([content isKindOfClass:[UnUpSampler class]]) + { + NSString* samplingTypeString = nil; + + UnUpSampler* unUpSampler = (UnUpSampler*) content; + switch ([unUpSampler samplingType]) + { + case UNDETERMINED: + samplingTypeString = @"?"; + break; + case UN_UP: + samplingTypeString = @"un-up"; + break; + case DUMBED_DOWN: + samplingTypeString = @"down"; + break; + case NONE: + samplingTypeString = @"none"; + break; + default: + @throw [NSException exceptionWithName:@"Unsupported option" reason:[NSString stringWithFormat:@"Unsupported sampling type: %i", [unUpSampler samplingType]] userInfo: nil]; + } + + stagedText = [stagedText stringByAppendingString:[NSString stringWithFormat:@", sampling=%@", samplingTypeString]]; + } + } + + self.statusText = stagedText; +} + +@end diff --git a/coregraphics/StreamedH264Decoder.h b/coregraphics/StreamedH264Decoder.h new file mode 100755 index 0000000..2b62fa4 --- /dev/null +++ b/coregraphics/StreamedH264Decoder.h @@ -0,0 +1,18 @@ +// +// StreamedH264Decoder.h +// spiritedarray +// +// Created by Dave Horlick on 2/5/14. +// Copyleft 2014 River Porpoise Software. All rights reserved. +// + +#import "SpiritedArray.h" +#import +#import "MemorizedSpiritedArray.h" + +@interface StreamedH264Decoder : SpiritedArray +{ + BOOL ready; + MemorizedSpiritedArray* memorized; +} +@end diff --git a/coregraphics/StreamedH264Decoder.m b/coregraphics/StreamedH264Decoder.m new file mode 100755 index 0000000..453d6f2 --- /dev/null +++ b/coregraphics/StreamedH264Decoder.m @@ -0,0 +1,201 @@ +// +// StreamedH264Decoder.m +// spiritedarray +// +// Created by Dave Horlick on 2/5/14. +// Copyleft 2014 River Porpoise Software. All rights reserved. +// + +#import "StreamedH264Decoder.h" +#import + +@implementation StreamedH264Decoder + +-(id) initWithFileNameToRead: (NSString*)fileName +{ + if (self = [super init]) + { + ready = NO; + NSURL* url = [NSURL fileURLWithPath: fileName]; + // NSError *error = nil; + + NSString* outputFileType = nil; + BOOL quicktimeContainer = YES; // TODO look at file extension or whatever + if (quicktimeContainer) + outputFileType = AVFileTypeQuickTimeMovie; + else + outputFileType = AVFileTypeMPEG4; + + AVAsset* asset = [AVAsset assetWithURL:url]; + + /* + AVAssetReader* videoReader = [[AVAssetReader alloc] initWithAsset:asset error:&error]; + + if (videoReader == nil) + { + // TODO throw something + } + */ + + memorized = nil; + + NSLog(@"Async Time"); + + [asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: + ^{ + // dispatch_async(dispatch_get_main_queue(), + dispatch_sync(dispatch_get_main_queue(), + ^{ + AVAssetTrack * videoTrack = nil; + NSArray * tracks = [asset tracksWithMediaType:AVMediaTypeVideo]; + if ([tracks count] == 1) + { + videoTrack = [tracks objectAtIndex:0]; + + NSError * error = nil; + + // _movieReader is a member variable + AVAssetReader* videoReader = [[AVAssetReader alloc] initWithAsset:asset error:&error]; + if (error) + { + NSLog(error.localizedDescription); + // TODO throw something + } + + NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; + NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; + NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; + + [videoReader addOutput:[AVAssetReaderTrackOutput + assetReaderTrackOutputWithTrack:videoTrack + outputSettings:videoSettings]]; + [videoReader startReading]; + + if (videoReader.status == AVAssetReaderStatusReading) + { + AVAssetReaderTrackOutput * output = [videoReader.outputs objectAtIndex:0]; + + CMSampleBufferRef sampleBuffer = [output copyNextSampleBuffer]; + if (sampleBuffer) + { + // frames = (uint) (sampleBuffer->duration).value; + + // TODO throw exception if [asset duration].value > MAX_UINT + // frames = (uint)[asset duration].value; + // TODO this isn't quite right; we want the *frames* count, not the duration + self->frames = 1U; + + CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); + + // Lock the image buffer + CVPixelBufferLockBaseAddress(imageBuffer,0); + + // Get information of the image + uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); + size_t ulWidth = CVPixelBufferGetWidth(imageBuffer); + // TODO throw exception if ulWidth > MAX_UINT + self->width = (uint) ulWidth; + size_t ulHeight = CVPixelBufferGetHeight(imageBuffer); + // TODO throw exception if ulHeight > MAX_UINT + self->height = (uint) ulHeight; + + if (self->memorized==nil) + { + self->memorized = [[MemorizedSpiritedArray alloc] initWith:1U Width:self->width Height:self->height]; + } + + // Here's where you can process the buffer! + // (your code goes here) + + uint i = 0U; + uint blackPixels = 0U; + + for (uint y=0U; yheight; y++) + { + for (uint x=0U; xwidth; x++) + { + SAColorType color; + uint ii = i * 3; + color.Red = baseAddress[ii]; + color.Green = baseAddress[ii+1]; + color.Blue = baseAddress[ii+2]; + [self->memorized writePixelColorAtFrame: 0U X:x Y:y Color:color]; + i++; + + if (color.Red<20 && color.Green<20 && color.Blue<20) + blackPixels++; + } + } + + NSLog(@"blackPixels = %u", blackPixels); + + // Unlock the image buffer + CVPixelBufferUnlockBaseAddress(imageBuffer,0); + CFRelease(sampleBuffer); + } + } + + NSLog([NSString stringWithFormat:@"OK, ready now."]); + NSLog(@"frames = %u", self->frames); + self->ready = YES; + [self _fireAndClearLoadListeners]; + } + }); + }]; + + // thanks, http://www.7twenty7.com/blog/2010/11/video-processing-with-av-foundation + } + + NSLog(@"Returning self…"); + + return self; +} + +- (void) _fireAndClearLoadListeners +{ + NSLog(@"Hello! ]["); +} + +- (uint) frames +{ + NSLog(@"Returning super frames %u", [super frames]); + return [super frames]; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + NSLog(@"SHD frames = %u", frames); + return [memorized pixelColorAtFrame:frame X:x Y:y]; +} + +- (void) writePixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y Color:(SAColorType)color +{ + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +- (uint) delayInCentisAfterFrame: (uint)frame +{ + return 10; +} + +- (BOOL) streamed +{ + return YES; +} + +-(void) close +{ + if (memorized!=nil) + { + [memorized close]; + } +} + +- (BOOL) ready +{ + return ready; +} + +@end diff --git a/coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.h b/coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.h new file mode 100755 index 0000000..2524e98 --- /dev/null +++ b/coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.h @@ -0,0 +1,13 @@ +// +// SAColorLinePrinterTileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 9/4/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SALinePrinterTileDrawingStrategy.h" + +@interface SAColorLinePrinterTileDrawingStrategy : SALinePrinterTileDrawingStrategy + +@end diff --git a/coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.m b/coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.m new file mode 100755 index 0000000..9898795 --- /dev/null +++ b/coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.m @@ -0,0 +1,26 @@ +// +// SAColorLinePrinterTileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 9/4/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAColorLinePrinterTileDrawingStrategy.h" + +@implementation SAColorLinePrinterTileDrawingStrategy +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + CGContextSelectFont(context, [fontFamily cStringUsingEncoding:NSASCIIStringEncoding], 26.0, kCGEncodingMacRoman); // TODO revisit + + unsigned char whiteness = (color.Red + color.Green + color.Blue) / 3; + unsigned char blackness = (255U-whiteness); + + CGContextSetRGBFillColor (context, color.Red/255.0f, + color.Green/255.0f, + color.Blue/255.0f, + 1.0f); + + CGContextShowTextAtPoint(context, 0, 0, [[palette objectAtIndex:(uint)blackness] cStringUsingEncoding:NSASCIIStringEncoding], 1); +} +@end diff --git a/coregraphics/tiling/SACrossStitchTileDrawingStrategy.h b/coregraphics/tiling/SACrossStitchTileDrawingStrategy.h new file mode 100755 index 0000000..dacd6d9 --- /dev/null +++ b/coregraphics/tiling/SACrossStitchTileDrawingStrategy.h @@ -0,0 +1,13 @@ +// +// SACrossStitchTileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 12/20/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SATileDrawingStrategy.h" + +@interface SACrossStitchTileDrawingStrategy : SATileDrawingStrategy + +@end diff --git a/coregraphics/tiling/SACrossStitchTileDrawingStrategy.m b/coregraphics/tiling/SACrossStitchTileDrawingStrategy.m new file mode 100755 index 0000000..7441bcf --- /dev/null +++ b/coregraphics/tiling/SACrossStitchTileDrawingStrategy.m @@ -0,0 +1,83 @@ +// +// SACrossStitchTileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 12/20/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SACrossStitchTileDrawingStrategy.h" + +@implementation SACrossStitchTileDrawingStrategy + +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + CGRect rect = CGRectMake(0, 0.3*metapixelHeightInPixels, metapixelWidthInPixels, 0.4*metapixelHeightInPixels); + float shortestSide; + if (rect.size.width < rect.size.height) + shortestSide = rect.size.width; + else + shortestSide = rect.size.height; + + CGPathRef roundedRectPath = [self newPathForRoundedRect:rect radius:shortestSide/2.1]; + + [SATileDrawingStrategy setFillColorTo:color OnContext:context]; + + float translateX = x*metapixelWidthInPixels; + float translateY = (height-y-1)*metapixelHeightInPixels; + // float rotateAngleInRadians = 3.1415926 / 4.0; + + CGContextTranslateCTM(context, translateX, translateY); + // CGContextRotateCTM(context, rotateAngleInRadians); + + [SATileDrawingStrategy setFillColorTo:color OnContext:context]; + + CGContextAddPath(context, roundedRectPath); + CGContextFillPath(context); + + // CGContextRotateCTM(context, -rotateAngleInRadians); + CGContextTranslateCTM(context, -translateX, -translateY); + + CGPathRelease(roundedRectPath); + +} + +/** + * Thanks, http://www.cocoanetics.com/2010/02/drawing-rounded-rectangles/ + * + * Note that if radius is larger than either of the input rectangle dimensions, the resulting shape will + * not be renderable. + */ +- (CGPathRef) newPathForRoundedRect:(CGRect)rect radius:(CGFloat)radius +{ + CGMutablePathRef retPath = CGPathCreateMutable(); + + CGRect innerRect = CGRectInset(rect, radius, radius); + + CGFloat inside_right = innerRect.origin.x + innerRect.size.width; + CGFloat outside_right = rect.origin.x + rect.size.width; + CGFloat inside_bottom = innerRect.origin.y + innerRect.size.height; + CGFloat outside_bottom = rect.origin.y + rect.size.height; + + CGFloat inside_top = innerRect.origin.y; + CGFloat outside_top = rect.origin.y; + CGFloat outside_left = rect.origin.x; + + CGPathMoveToPoint(retPath, NULL, innerRect.origin.x, outside_top); + + CGPathAddLineToPoint(retPath, NULL, inside_right, outside_top); + CGPathAddArcToPoint(retPath, NULL, outside_right, outside_top, outside_right, inside_top, radius); + CGPathAddLineToPoint(retPath, NULL, outside_right, inside_bottom); + CGPathAddArcToPoint(retPath, NULL, outside_right, outside_bottom, inside_right, outside_bottom, radius); + + CGPathAddLineToPoint(retPath, NULL, innerRect.origin.x, outside_bottom); + CGPathAddArcToPoint(retPath, NULL, outside_left, outside_bottom, outside_left, inside_bottom, radius); + CGPathAddLineToPoint(retPath, NULL, outside_left, inside_top); + CGPathAddArcToPoint(retPath, NULL, outside_left, outside_top, innerRect.origin.x, outside_top, radius); + + CGPathCloseSubpath(retPath); + + return retPath; +} + +@end diff --git a/coregraphics/tiling/SAFatBitsTileDrawingStrategy.h b/coregraphics/tiling/SAFatBitsTileDrawingStrategy.h new file mode 100755 index 0000000..881cb4e --- /dev/null +++ b/coregraphics/tiling/SAFatBitsTileDrawingStrategy.h @@ -0,0 +1,17 @@ +// +// SAFatBitsTileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 3/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SATileDrawingStrategy.h" + +@interface SAFatBitsTileDrawingStrategy : SATileDrawingStrategy +{ + uint metapixelWidthInPixelsMinusAnyTrim; + uint metapixelHeightInPixelsMinusAnyTrim; +} +@end diff --git a/coregraphics/tiling/SAFatBitsTileDrawingStrategy.m b/coregraphics/tiling/SAFatBitsTileDrawingStrategy.m new file mode 100755 index 0000000..ccb7f5d --- /dev/null +++ b/coregraphics/tiling/SAFatBitsTileDrawingStrategy.m @@ -0,0 +1,64 @@ +// +// SAFatBitsTileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 3/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAFatBitsTileDrawingStrategy.h" +#import "SpiritedArray.h" + +@implementation SAFatBitsTileDrawingStrategy + +static const SAColorType bluish = {237, 242, 255}; + +-(void) setMetapixelWidthInPixels:(uint)designatedMetapixelWidthInPixels +{ + [super setMetapixelWidthInPixels: designatedMetapixelWidthInPixels]; + + if (designatedMetapixelWidthInPixels>1) + metapixelWidthInPixelsMinusAnyTrim = designatedMetapixelWidthInPixels - 1; + else + metapixelWidthInPixelsMinusAnyTrim = 1; +} + +-(void) setMetapixelHeightInPixels:(uint)designatedMetapixelHeightInPixels +{ + [super setMetapixelHeightInPixels:designatedMetapixelHeightInPixels]; + + if (designatedMetapixelHeightInPixels>1) + metapixelHeightInPixelsMinusAnyTrim = designatedMetapixelHeightInPixels - 1; + else + metapixelHeightInPixelsMinusAnyTrim = 1; +} + +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + [SATileDrawingStrategy setFillColorTo:bluish OnContext:context]; + CGRect backgroundRect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixels, + metapixelHeightInPixels); + CGContextFillRect(context, backgroundRect); + + + if (color.Red > 127U || color.Blue > 127U || color.Green > 127) + CGContextSetRGBFillColor(context, 0.93f, 0.95f, 1.0f, 1.0f); + else + CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f); + + CGRect rect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixelsMinusAnyTrim, + metapixelHeightInPixelsMinusAnyTrim); + + CGContextFillRect(context, rect); +} + +-(SAColorType) backgroundColor +{ + return bluish; +} + +@end diff --git a/coregraphics/tiling/SAGraphPaperTileDrawingStrategy.h b/coregraphics/tiling/SAGraphPaperTileDrawingStrategy.h new file mode 100755 index 0000000..4a8203a --- /dev/null +++ b/coregraphics/tiling/SAGraphPaperTileDrawingStrategy.h @@ -0,0 +1,16 @@ +// +// SAGraphPaperTileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 9/15/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SATileDrawingStrategy.h" + +@interface SAGraphPaperTileDrawingStrategy : SATileDrawingStrategy +{ + uint metapixelWidthInPixelsMinusAnyTrim; + uint metapixelHeightInPixelsMinusAnyTrim; +} +@end diff --git a/coregraphics/tiling/SAGraphPaperTileDrawingStrategy.m b/coregraphics/tiling/SAGraphPaperTileDrawingStrategy.m new file mode 100755 index 0000000..5e547fd --- /dev/null +++ b/coregraphics/tiling/SAGraphPaperTileDrawingStrategy.m @@ -0,0 +1,60 @@ +// +// SAGraphPaperTileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 9/15/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAGraphPaperTileDrawingStrategy.h" +#import "SpiritedArray.h" + +@implementation SAGraphPaperTileDrawingStrategy + +static const SAColorType graphPaperBlue = {100, 100, 255}; + +-(void) setMetapixelWidthInPixels:(uint)designatedMetapixelWidthInPixels +{ + [super setMetapixelWidthInPixels: designatedMetapixelWidthInPixels]; + + if (designatedMetapixelWidthInPixels>1) + metapixelWidthInPixelsMinusAnyTrim = designatedMetapixelWidthInPixels - 1; + else + metapixelWidthInPixelsMinusAnyTrim = 1; +} + +-(void) setMetapixelHeightInPixels:(uint)designatedMetapixelHeightInPixels +{ + [super setMetapixelHeightInPixels:designatedMetapixelHeightInPixels]; + + if (designatedMetapixelHeightInPixels>1) + metapixelHeightInPixelsMinusAnyTrim = designatedMetapixelHeightInPixels - 1; + else + metapixelHeightInPixelsMinusAnyTrim = 1; +} + +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + [SATileDrawingStrategy setFillColorTo:graphPaperBlue OnContext:context]; + CGRect backgroundRect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixels, + metapixelHeightInPixels); + CGContextFillRect(context, backgroundRect); + + [SATileDrawingStrategy setFillColorTo:color OnContext:context]; + + CGRect rect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixelsMinusAnyTrim, + metapixelHeightInPixelsMinusAnyTrim); + + CGContextFillRect(context, rect); +} + +-(SAColorType) backgroundColor +{ + return [SpiritedArray white]; +} + +@end diff --git a/coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.h b/coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.h new file mode 100755 index 0000000..a70bdbc --- /dev/null +++ b/coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.h @@ -0,0 +1,18 @@ +// +// SALightEmittingDiodeTileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 3/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SATileDrawingStrategy.h" + +@interface SALightEmittingDiodeTileDrawingStrategy : SATileDrawingStrategy +{ + uint metapixelWidthInPixelsMinusAnyTrim; + uint metapixelHeightInPixelsMinusAnyTrim; + float centerGradientIntensityDelta; // 0 < x << 1 + float edgeGradientIntensityDelta; // 0 < x << 1 +} +@end diff --git a/coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.m b/coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.m new file mode 100755 index 0000000..f28ed4d --- /dev/null +++ b/coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.m @@ -0,0 +1,117 @@ +// +// SALightEmittingDiodeTileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 3/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SALightEmittingDiodeTileDrawingStrategy.h" + +@implementation SALightEmittingDiodeTileDrawingStrategy + +-(id) init +{ + if (self = [super init]) + { + centerGradientIntensityDelta = 0.10f; + edgeGradientIntensityDelta = -0.22f; + } + + return self; +} + +-(void) setMetapixelWidthInPixels:(uint)designatedMetapixelWidthInPixels +{ + [super setMetapixelWidthInPixels: designatedMetapixelWidthInPixels]; + + if (designatedMetapixelWidthInPixels>2) + metapixelWidthInPixelsMinusAnyTrim = designatedMetapixelWidthInPixels - 2; + else + metapixelWidthInPixelsMinusAnyTrim = designatedMetapixelWidthInPixels; +} + +-(void) setMetapixelHeightInPixels:(uint)designatedMetapixelHeightInPixels +{ + [super setMetapixelHeightInPixels:designatedMetapixelHeightInPixels]; + + if (designatedMetapixelHeightInPixels>2) + metapixelHeightInPixelsMinusAnyTrim = designatedMetapixelHeightInPixels - 2; + else + metapixelHeightInPixelsMinusAnyTrim = designatedMetapixelHeightInPixels; +} + +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + CGRect metapixelRect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixels, + metapixelHeightInPixels); + + CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f); + + CGContextFillRect(context, metapixelRect); + + CGRect diodeRect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixelsMinusAnyTrim, + metapixelHeightInPixelsMinusAnyTrim); + + float red = color.Red/255.0f; + float green = color.Green/255.0f; + float blue = color.Blue/255.0f; + + float bottomRed = [SALightEmittingDiodeTileDrawingStrategy tweakFloatColor: red By: edgeGradientIntensityDelta]; + float bottomGreen = [SALightEmittingDiodeTileDrawingStrategy tweakFloatColor:green By: edgeGradientIntensityDelta]; + float bottomBlue = [SALightEmittingDiodeTileDrawingStrategy tweakFloatColor: blue By: edgeGradientIntensityDelta]; + + float topRed = [SALightEmittingDiodeTileDrawingStrategy tweakFloatColor: red By: centerGradientIntensityDelta]; + float topGreen = [SALightEmittingDiodeTileDrawingStrategy tweakFloatColor:green By: centerGradientIntensityDelta]; + float topBlue = [SALightEmittingDiodeTileDrawingStrategy tweakFloatColor: blue By: centerGradientIntensityDelta]; + + CGFloat colors [] = { + topRed, topGreen, topBlue, 1.0, + bottomRed, bottomGreen, bottomBlue, 1.0 + }; + + CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB(); + CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2); + CGColorSpaceRelease(baseSpace); + baseSpace = NULL; + + CGContextSaveGState(context); + CGContextAddEllipseInRect(context, diodeRect); + CGContextClip(context); + + CGPoint center = CGPointMake(CGRectGetMidX(diodeRect), CGRectGetMidY(diodeRect)); + + float radius = (float)metapixelHeightInPixelsMinusAnyTrim/2.0f; + // TODO should we consider metapixelWidthInPixelsMinusAnyTrim here, too? + CGContextDrawRadialGradient(context, gradient, CGPointMake(diodeRect.origin.x + diodeRect.size.width*0.35f, diodeRect.origin.y+ diodeRect.size.height*0.35f), 0, center, radius, 0); + CGGradientRelease(gradient); + gradient = NULL; + + CGContextRestoreGState(context); + + CGContextAddEllipseInRect(context, diodeRect); + CGContextDrawPath(context, kCGPathStroke); +} + ++(float) tweakFloatColor:(float)color By:(float)amount +{ + float sum = color + amount; + + if (sum<0.0f) + return 0.0f; + if (sum>1.0f) + return 1.0f; + + return sum; +} + +-(SAColorType) backgroundColor +{ + return [SpiritedArray black]; +} + +@end diff --git a/coregraphics/tiling/SALinePrinterTileDrawingStrategy.h b/coregraphics/tiling/SALinePrinterTileDrawingStrategy.h new file mode 100755 index 0000000..f20ef67 --- /dev/null +++ b/coregraphics/tiling/SALinePrinterTileDrawingStrategy.h @@ -0,0 +1,20 @@ +// +// SALinePrinterTileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 8/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SATileDrawingStrategy.h" + +@interface SALinePrinterTileDrawingStrategy : SATileDrawingStrategy +{ + NSString* fontFamily; + NSMutableArray* palette; +} + +-(id) initWithFontFamily:(NSString*)designatedFontFamily; +-(NSString*) fontFamily; + +@end diff --git a/coregraphics/tiling/SALinePrinterTileDrawingStrategy.m b/coregraphics/tiling/SALinePrinterTileDrawingStrategy.m new file mode 100755 index 0000000..c183c67 --- /dev/null +++ b/coregraphics/tiling/SALinePrinterTileDrawingStrategy.m @@ -0,0 +1,139 @@ +// +// SALinePrinterTileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 8/18/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SALinePrinterTileDrawingStrategy.h" + +@implementation SALinePrinterTileDrawingStrategy + +-(id) initWithFontFamily:(NSString*)designatedFontFamily +{ + if (designatedFontFamily==nil) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"No font family provided."] userInfo:nil]; + } + + if (self = [super init]) + { + fontFamily = designatedFontFamily; + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray(); + char letter[] = " "; + letter[1] = 0; // terminator + + NSMutableDictionary* charIndexArrayKeyedOnCount = [NSMutableDictionary new]; + NSMutableArray* counts = [NSMutableArray new]; + + for (uint i=32U; i<127U; i++) + { + letter[0] = i; + CGContextRef context = CGBitmapContextCreate(NULL, 14, 14, 8, 14, colorSpace, kCGImageAlphaNone); + CGContextSelectFont(context, [fontFamily cStringUsingEncoding:NSASCIIStringEncoding], 14.0, kCGEncodingMacRoman); // TODO revisit + + CGContextSetGrayFillColor(context, 1.0f, 1.0f); // black + CGContextSetGrayStrokeColor(context, 1.0f, 1.0f); // black + CGContextShowTextAtPoint(context, 0, 0, letter, 1); + + unsigned char* data = CGBitmapContextGetData(context); + double darkPixelCount = 0.0; + + // NSLog(@"%s --------", letter); + + if (data != NULL) + { + for (uint i=0U; i<14*14; i++) + { + if (data[i]!=0U) + { + // NSLog(@"data[%u] = %u", i, data[i]); + darkPixelCount += ((double)data[i]/255.0); + } + } + } + else + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Insufficient memory to obtain bitmap data."] userInfo:nil]; + + } + + // When finished, release the context + CGContextRelease(context); + // Free image data memory for the context + + CGContextRelease(context); + NSNumber* darkPixelCountAsObject = [NSNumber numberWithDouble:darkPixelCount]; + NSMutableArray* charIndexArray = [charIndexArrayKeyedOnCount objectForKey:darkPixelCountAsObject]; + if (charIndexArray==nil) + { + charIndexArray = [NSMutableArray new]; + [charIndexArrayKeyedOnCount setObject:charIndexArray forKey:darkPixelCountAsObject]; + [counts addObject:darkPixelCountAsObject]; + } + + [charIndexArray addObject:[NSString stringWithCString:letter encoding:NSASCIIStringEncoding]]; + } + + NSArray *sortedCounts = [counts sortedArrayUsingSelector: @selector(compare:)]; + + /* for (int i=(int)[sortedCounts count]-1U; i>=0; i--) + { + NSNumber* darkPixelCountAsObject = [sortedCounts objectAtIndex:i]; + NSMutableArray* charIndexArray = [charIndexArrayKeyedOnCount objectForKey:darkPixelCountAsObject]; + NSLog(@"%@ ... %@", darkPixelCountAsObject, charIndexArray); + } */ + + palette = [NSMutableArray new]; + + NSString* string = nil; + + for (uint i=0U; i<[sortedCounts count]; i++) + { + NSNumber* darkPixelCountAsObject = [sortedCounts objectAtIndex:i]; + NSMutableArray* charIndexArray = [charIndexArrayKeyedOnCount objectForKey:darkPixelCountAsObject]; + + string = [charIndexArray objectAtIndex:0U]; // TODO pick character with biggest footprint? + + while ([palette count] <= [darkPixelCountAsObject unsignedCharValue]) + { + [palette addObject:string]; + } + } + + while ([palette count]<256U) + { + [palette addObject:string]; + } + + // NSLog(@"--> %@", palette); + + CGColorSpaceRelease(colorSpace); + } + + return self; +} + +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + CGContextSelectFont(context, [fontFamily cStringUsingEncoding:NSASCIIStringEncoding], 26.0, kCGEncodingMacRoman); // TODO revisit + + unsigned char whiteness = (color.Red + color.Green + color.Blue) / 3; + unsigned char blackness = (255U-whiteness); + + // TODO scale brightness + + CGContextSetRGBFillColor(context, 0.0f, 0.0f, 0.0f, 1.0f); + + CGContextShowTextAtPoint(context, 0, 0, [[palette objectAtIndex:(uint)blackness] cStringUsingEncoding:NSASCIIStringEncoding], 1); +} + +-(NSString*) fontFamily +{ + return fontFamily; +} + +@end diff --git a/coregraphics/tiling/SATileDrawingStrategy.h b/coregraphics/tiling/SATileDrawingStrategy.h new file mode 100755 index 0000000..3ffc174 --- /dev/null +++ b/coregraphics/tiling/SATileDrawingStrategy.h @@ -0,0 +1,32 @@ +// +// SATileDrawingStrategy.h +// spiritedarray +// +// Created by Dave Horlick on 3/17/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SpiritedArray.h" + +@interface SATileDrawingStrategy : NSObject +{ + uint metapixelWidthInPixels; + uint metapixelHeightInPixels; +} + +-(uint) metapixelWidthInPixels; +-(uint) metapixelHeightInPixels; + +-(void) setMetapixelWidthInPixels: (uint)designatedMetapixelWidthInPixels; +-(void) setMetapixelHeightInPixels: (uint)designatedMetapixelHeightInPixels; + +/** + * x and y are in the coordinate from of the input image, NOT the output image or view. + */ +-(void) drawX:(uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height; + +-(SAColorType) backgroundColor; ++(void) setFillColorTo: (SAColorType) color OnContext: (CGContextRef) context; + +@end diff --git a/coregraphics/tiling/SATileDrawingStrategy.m b/coregraphics/tiling/SATileDrawingStrategy.m new file mode 100755 index 0000000..f62fbad --- /dev/null +++ b/coregraphics/tiling/SATileDrawingStrategy.m @@ -0,0 +1,58 @@ +// +// SATileDrawingStrategy.m +// spiritedarray +// +// Created by Dave Horlick on 3/17/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SATileDrawingStrategy.h" + +@implementation SATileDrawingStrategy + +-(void) setMetapixelWidthInPixels:(uint)designatedMetapixelWidthInPixels +{ + metapixelWidthInPixels = designatedMetapixelWidthInPixels; +} + +-(void) setMetapixelHeightInPixels:(uint)designatedMetapixelHeightInPixels +{ + metapixelHeightInPixels = designatedMetapixelHeightInPixels; +} + +-(void) drawX: (uint)x Y: (uint)y Color: (SAColorType) color Context:(CGContextRef)context Height:(uint)height +{ + [SATileDrawingStrategy setFillColorTo:color OnContext:context]; + + CGRect rect = CGRectMake(x*metapixelWidthInPixels, + (height-y-1)*metapixelHeightInPixels, + metapixelWidthInPixels, + metapixelHeightInPixels); + + CGContextFillRect(context, rect); +} + +-(uint) metapixelWidthInPixels +{ + return metapixelWidthInPixels; +} + +-(uint) metapixelHeightInPixels +{ + return metapixelHeightInPixels; +} + +-(SAColorType) backgroundColor +{ + return [SpiritedArray white]; +} + ++(void) setFillColorTo: (SAColorType) color OnContext: (CGContextRef) context +{ + CGContextSetRGBFillColor (context, color.Red/255.0f, + color.Green/255.0f, + color.Blue/255.0f, + 1.0f); +} + +@end diff --git a/docs/animation_window.png b/docs/animation_window.png new file mode 100644 index 0000000..3cd4b36 Binary files /dev/null and b/docs/animation_window.png differ diff --git a/foundationkit/GifEncoder.h b/foundationkit/GifEncoder.h new file mode 100755 index 0000000..00e4dca --- /dev/null +++ b/foundationkit/GifEncoder.h @@ -0,0 +1,20 @@ +// +// GifEncoder.h +// spiritedarray +// +// Created by Dave Horlick on 4/21/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SpiritedArray.h" + +@interface GifEncoder : NSObject +{ +} + +-(void) encode: (SpiritedArray*) designatedSpiritedArray FilePath: (NSString*)designatedFilePath; +// +(uint) countColorsInSpiritedArray: (SpiritedArray*) spiritedArray; ++(unsigned long) lowestPowerOfTwoThatIsNotLessThan: (unsigned long) value; + +@end diff --git a/foundationkit/GifEncoder.m b/foundationkit/GifEncoder.m new file mode 100755 index 0000000..62314a9 --- /dev/null +++ b/foundationkit/GifEncoder.m @@ -0,0 +1,220 @@ +// +// GifEncoder.m +// spiritedarray +// +// Created by Dave Horlick on 4/21/13. +// Copyleft 2013 River Porpoise Software +// + +#import "GifEncoder.h" +#import "gif_lib.h" +#import "SAMetapixelPalette.h" +#import "SAColorTree.h" +// #import + +@implementation GifEncoder + +-(void) encode: (SpiritedArray*) designatedSpiritedArray FilePath: (NSString*)designatedFilePath +{ + GifFileType* gifFile = EGifOpenFileName([designatedFilePath UTF8String], 1); + + NSMutableSet* colors = [NSMutableSet new]; + + for (uint frame=0U; frame < [designatedSpiritedArray frames]; frame++) + { + for (uint y=0U; y < [designatedSpiritedArray height]; y++) + { + for (uint x = 0U; x < [designatedSpiritedArray width]; x++) + { + SAColorType color = [designatedSpiritedArray pixelColorAtFrame:frame X:x Y:y]; + uint colorIndex = [SAMetapixelPalette indexFor: color]; + NSNumber* colorIndexAsObject = [NSNumber numberWithUnsignedInt: colorIndex]; + [colors addObject: colorIndexAsObject]; + } + } + } + + unsigned long colorCount = [colors count]; + // NSLog(@"colors = %@", colors); + + GifPixelType* rasterBits = nil; + + // if (colorCount>256U) // TODO uncomment + /* + { + NSLog(@"Reducing colors from %lu via color tree…", colorCount); + SAColorTree* tree = [[SAColorTree alloc] initWithSpiritedArray:designatedSpiritedArray Colors:256U]; + NSLog(@"Immediately after initialization, tree has %u colors.", [tree colors]); + [tree reduceToColors: 256U]; + NSLog(@"reduced color tree to %u colors.", [tree colors]); + + GifColorType* gifColorTypeArray = (GifColorType*) malloc(256U*sizeof(GifColorType)); + + // TODO populate gifColorTypeArray + + ColorMapObject* gifColorMap = MakeMapObject(256U, gifColorTypeArray); + // TODO fill-out the color map with some kind of blank entries for unusued power-of-two cells? + + int putScreenDescResult = EGifPutScreenDesc(gifFile, [designatedSpiritedArray width], [designatedSpiritedArray height], 255U, 0, gifColorMap); + if (putScreenDescResult == GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"Call to EGifPutScreenDesc returned %i.", putScreenDescResult] userInfo: nil]; + } + + NSLog(@"Wrote color table. Now indexing individual pixels…"); + + rasterBits = (GifPixelType*) malloc ([designatedSpiritedArray width] * sizeof(GifPixelType)); + NSMutableArray *colorArray = [NSMutableArray new]; + + for (uint f=0U; f<[designatedSpiritedArray frames]; f++) + { + NSLog(@"Frame #%u…",f); + + int putImageDescResult = EGifPutImageDesc(gifFile, 0, 0, [designatedSpiritedArray width], [designatedSpiritedArray height], 0, 0); + // EGifPutExtensionFirst(gifFile); + // EGifPutExtensionNext(gifFile); + + if (putImageDescResult == GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"Call to EGifPutImageDesc returned %i.", putImageDescResult] userInfo: nil]; + } + + for (uint y=0U; y<[designatedSpiritedArray height]; y++) + { + for (uint x=0U; x<[designatedSpiritedArray width]; x++) + { + SAColorType originalColor = ([designatedSpiritedArray pixelColorAtFrame:f X:x Y:y]); + SAColorType reassignedColor = [tree assignColor: originalColor]; + uint colorIndex = [SAMetapixelPalette indexFor:reassignedColor]; + NSNumber* colorIndexAsObject = [NSNumber numberWithUnsignedInt: colorIndex]; + + NSUInteger ordinalIndex; + + if ([colorArray containsObject:colorIndexAsObject]) + ordinalIndex = [colorArray indexOfObject: colorIndexAsObject]; + else + { + ordinalIndex = [colorArray count]; + [colorArray addObject: colorIndexAsObject]; + } + + rasterBits[x] = (uint) ordinalIndex; + } + + EGifPutLine(gifFile, rasterBits, [designatedSpiritedArray width]); + } + } + + NSLog(@"…exported!"); + } + else + { */ + NSLog(@"NOT Reducing colors via color tree, there are only %lu", colorCount); + + GifColorType* gifColorTypeArray = (GifColorType*) malloc(colorCount*sizeof(GifColorType)); + + NSEnumerator *enumerator = [colors objectEnumerator]; + NSNumber* element = nil; + uint i=0U; + + while (element = [enumerator nextObject]) + { + GifColorType color = [GifEncoder gifColorFor: [element unsignedIntValue]]; + gifColorTypeArray[i] = color; + i++; + } + + NSArray *colorArray = [colors allObjects]; + + // double powerOfTwoColorCount = round(pow(ceil(log2((double)colorCount)), 2.0)); + unsigned long powerOfTwoColorCount = [GifEncoder lowestPowerOfTwoThatIsNotLessThan: colorCount]; + NSLog(@"powerOfTwoColorCount = %lu", powerOfTwoColorCount); + + ColorMapObject* gifColorMap = MakeMapObject((uint)powerOfTwoColorCount, gifColorTypeArray); + // TODO fill-out the color map with some kind of blank entries for unusued power-of-two cells? + + int putScreenDescResult = EGifPutScreenDesc(gifFile, [designatedSpiritedArray width], [designatedSpiritedArray height], 255U, 0, gifColorMap); + if (putScreenDescResult == GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"Call to EGifPutScreenDesc returned %i.", putScreenDescResult] userInfo: nil]; + } + + NSLog(@"Wrote color table. Now indexing individual pixels…"); + + rasterBits = (GifPixelType*) malloc ([designatedSpiritedArray width] * sizeof(GifPixelType)); + + for (uint f=0U; f<[designatedSpiritedArray frames]; f++) + { + NSLog(@"Frame #%u…",f); + + int putImageDescResult = EGifPutImageDesc(gifFile, 0, 0, [designatedSpiritedArray width], [designatedSpiritedArray height], 0, 0); + // EGifPutExtensionFirst(gifFile); + // EGifPutExtensionNext(gifFile); + + if (putImageDescResult == GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"Call to EGifPutImageDesc returned %i.", putImageDescResult] userInfo: nil]; + } + + for (uint y=0U; y<[designatedSpiritedArray height]; y++) + { + for (uint x=0U; x<[designatedSpiritedArray width]; x++) + { + SAColorType color = ([designatedSpiritedArray pixelColorAtFrame:f X:x Y:y]); + uint colorIndex = [SAMetapixelPalette indexFor:color]; + NSNumber* colorIndexAsObject = [NSNumber numberWithUnsignedInt: colorIndex]; + NSUInteger ordinalIndex = [colorArray indexOfObject: colorIndexAsObject]; + + rasterBits[x] = (uint) ordinalIndex; + } + + EGifPutLine(gifFile, rasterBits, [designatedSpiritedArray width]); + } + } + + NSLog(@"OK, done"); + // } + + // TODO FreeMapObject(gifColorMap); ? + EGifCloseFile(gifFile); + + free(rasterBits); +} + ++(GifColorType) saColorTypeToGifColorType: (SAColorType) pixelColor +{ + GifColorType result; + result.Red = pixelColor.Red; + result.Green = pixelColor.Green; + result.Blue = pixelColor.Blue; + return result; +} + ++(GifColorType) gifColorFor: (uint) index +{ + uint red = index / 65536U; + uint leftover = index % 65536U; + uint green = leftover / 256U; + uint blue = leftover % 256U; + GifColorType result = {red, green, blue}; + return result; +} + ++(unsigned long) lowestPowerOfTwoThatIsNotLessThan: (unsigned long) value +{ + unsigned long result = 1; + + for (uint i=0; i<256; i++) + { + result = result * 2; + + if (value <= result) + return result; + } + + // This algorithm probably isn't going to get me a CS doctorate, but it works and it isn't that inefficient. + + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:[NSString stringWithFormat:@"Couldn't find result for: %lu", value] userInfo: nil]; +} + +@end diff --git a/foundationkit/MemorizedSpiritedArray.h b/foundationkit/MemorizedSpiritedArray.h new file mode 100755 index 0000000..57c7117 --- /dev/null +++ b/foundationkit/MemorizedSpiritedArray.h @@ -0,0 +1,26 @@ +// +// MemorizedSpiritedArray.h +// spiritedarray +// +// Created by Dave Horlick on 11/4/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SpiritedArray.h" +#import "SpiritedArrayIterator.h" + +@interface MemorizedSpiritedArray : SpiritedArray +{ + SAColorType*** pixels; + NSMutableArray* delayInCentisAfterFrames; +} + +- (id) initWith:(uint)designatedFrames Width:(uint) designatedWidth Height:(uint) designatedHeight; +- (id) initWithSpiritedArrayIterator: (SpiritedArrayIterator*) spiritedArrayIterator; +- (id) initWithSpiritedArray: (SpiritedArray*) spiritedArray; +- (void) setDelayInCentisTo: (uint)delayInCentis AfterFrame:(uint)frame; + +- (uint) memoryFootprint; +- (void )fillWithColor:(SAColorType)color; + +@end diff --git a/foundationkit/MemorizedSpiritedArray.m b/foundationkit/MemorizedSpiritedArray.m new file mode 100755 index 0000000..02aef82 --- /dev/null +++ b/foundationkit/MemorizedSpiritedArray.m @@ -0,0 +1,172 @@ +// +// MemorizedSpiritedArray.m +// spiritedarray +// +// Created by Dave Horlick on 11/4/12. +// Copyleft 2012 River Porpoise Software +// + +#import "MemorizedSpiritedArray.h" +#import "SpiritedArrayIterator.h" + +@implementation MemorizedSpiritedArray + +- (id) init +{ + @throw [NSException exceptionWithName: @"UnsupportedOperation" reason:@"Please use one of the initWith methods, instead." + userInfo: nil]; + return nil; +} + +- (id) initWith:(uint)designatedFrames Width:(uint) designatedWidth Height:(uint) designatedHeight +{ + if (self = [super init]) + { + frames = designatedFrames; + width = designatedWidth; + height = designatedHeight; + + uint initFrame, initY; + + pixels = (SAColorType ***)malloc(frames * sizeof(SAColorType **)); + if (pixels==NULL) { + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Couldn't allocate memory for array dimension #1" userInfo:nil]; + } + + delayInCentisAfterFrames = [NSMutableArray arrayWithCapacity:designatedFrames]; + NSNumber* zero = [NSNumber numberWithUnsignedInt:0U]; + + for (initFrame = 0; initFrame < frames; initFrame++) + { + pixels[initFrame] = (SAColorType **)malloc(height * sizeof(SAColorType *)); + if (pixels[initFrame]==NULL) { + [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Couldn't allocate memory for array dimension #2" userInfo:nil]; + } + + for (initY = 0; initY < height; initY++) + { + pixels[initFrame][initY] = (SAColorType *)malloc(width * sizeof(SAColorType)); + if (pixels[initFrame][initY]==NULL) { + [NSException exceptionWithName:NSInternalInconsistencyException reason:@"Couldn't allocate memory for array dimension #3" userInfo:nil]; + } + + } + + [delayInCentisAfterFrames addObject:zero]; + } + } + + return self; +} + +-(id) initWithSpiritedArrayIterator: (SpiritedArrayIterator*) spiritedArrayIterator +{ + id result = [self initWith: [spiritedArrayIterator frames] Width:[spiritedArrayIterator width] Height:[spiritedArrayIterator height]]; + + int frame = 0; + int x = 0; + int y = 0; + + while ([spiritedArrayIterator arrayHasAnotherFrame]) + { + x = 0; + y = 0; + + [spiritedArrayIterator nextFrame]; + + while ([spiritedArrayIterator imageHasAnotherRow]) + { + x = 0; + + [spiritedArrayIterator nextRow]; + + while ([spiritedArrayIterator rowHasAnotherPixel]) + { + [self writePixelColorAtFrame:frame X:x Y:y Color:[spiritedArrayIterator nextPixel]]; + x++; + } + + y++; + } + + [delayInCentisAfterFrames replaceObjectAtIndex:frame withObject:[NSNumber numberWithUnsignedInt:[spiritedArrayIterator delayInCentisAfterFrame:frame]]]; + frame++; + } + + [spiritedArrayIterator close]; + + return result; +} + +- (id) initWithSpiritedArray: (SpiritedArray*) spiritedArray +{ + // TODO transcribe inter-frame delays, somehow + + SpiritedArrayIterator* spiritedArrayIterator = [[SpiritedArrayIterator alloc] initWithSpiritedArray:spiritedArray]; + id result = [self initWithSpiritedArrayIterator:spiritedArrayIterator]; + + return result; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + return pixels[frame][y][x]; +} + +- (void) writePixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y Color:(SAColorType)color +{ + pixels[frame][y][x] = color; +} + +- (uint) memoryFootprint +{ + return (3 * sizeof(uint)) // i.e. width, height, and frames + + (sizeof(unsigned char) * [self pixels]); +} + +- (void) dealloc +{ + uint initFrame, initY; + + for (initFrame = 0; initFrame < frames; initFrame++) + { + for (initY = 0; initY < height; initY++) + { + free(pixels[initFrame][initY]); + } + + free(pixels[initFrame]); + } + + free(pixels); +} + +- (uint) delayInCentisAfterFrame: (uint)frame +{ + NSNumber* delay = [delayInCentisAfterFrames objectAtIndex:frame]; + return [delay unsignedIntValue]; +} + +- (void) setDelayInCentisTo: (uint)delayInCentis AfterFrame:(uint)frame +{ + while ([delayInCentisAfterFrames count] <= frame) + [delayInCentisAfterFrames addObject:[NSNumber numberWithUnsignedInt:0U]]; + + [delayInCentisAfterFrames replaceObjectAtIndex:frame withObject:[NSNumber numberWithUnsignedInt:delayInCentis]]; +} + +- (void )fillWithColor:(SAColorType)color +{ + for (uint frame=0U; frame<[self frames]; frame++) + { + for (uint y=0U; y<[self height]; y++) + { + for (uint x=0U; x<[self width]; x++) + { + [self writePixelColorAtFrame:frame X:x Y:y Color:color]; + } + } + } +} + +@end diff --git a/foundationkit/OptimizedSpiritedArray.h b/foundationkit/OptimizedSpiritedArray.h new file mode 100755 index 0000000..95916c3 --- /dev/null +++ b/foundationkit/OptimizedSpiritedArray.h @@ -0,0 +1,18 @@ +// +// OptimizedSpiritedArray.h +// spiritedarray +// +// Created by Dave Horlick on 11/12/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SpiritedArray.h" + +@interface OptimizedSpiritedArray : SpiritedArray +{ + SpiritedArray* spiritedArray; +} + +- (id) initWith: (SpiritedArray*) designatedSpiritedArray; + +@end diff --git a/foundationkit/OptimizedSpiritedArray.m b/foundationkit/OptimizedSpiritedArray.m new file mode 100755 index 0000000..aa9d770 --- /dev/null +++ b/foundationkit/OptimizedSpiritedArray.m @@ -0,0 +1,54 @@ +// +// OptimizedSpiritedArray.m +// spiritedarray +// +// Created by Dave Horlick on 11/12/12. +// Copyleft 2012 River Porpoise Software +// + +#import "OptimizedSpiritedArray.h" +#import "MemorizedSpiritedArray.h" + +@implementation OptimizedSpiritedArray + +- (id) initWith: (SpiritedArray*) designatedSpiritedArray +{ + self = [super init]; + if (self) + { + if ([designatedSpiritedArray streamed] && [designatedSpiritedArray width] * [designatedSpiritedArray height] < 500000) + { + NSLog(@"Memorizing…"); + spiritedArray = [[MemorizedSpiritedArray alloc] initWithSpiritedArray:designatedSpiritedArray]; + NSLog(@"Memorized."); + } + else + { + NSLog(@"Proxying…"); + spiritedArray = designatedSpiritedArray; + } + + width = [spiritedArray width]; + height = [spiritedArray height]; + frames = [spiritedArray frames]; + } + + return self; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + return [spiritedArray pixelColorAtFrame:frame X:x Y:y]; +} + +- (void) close +{ + [spiritedArray close]; +} + +-(uint) delayInCentisAfterFrame:(uint)frame +{ + return [spiritedArray delayInCentisAfterFrame:frame]; +} + +@end diff --git a/foundationkit/SAColorTree.h b/foundationkit/SAColorTree.h new file mode 100755 index 0000000..5ef4f58 --- /dev/null +++ b/foundationkit/SAColorTree.h @@ -0,0 +1,84 @@ +// +// SAColorTree.h +// spiritedarray +// +// Created by Dave Horlick on 5/7/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "SpiritedArray.h" +#import "SAReductionContext.h" +#import "MemorizedSpiritedArray.h" + +@interface SAColorTree : NSObject +{ + NSMutableArray* branches; + uint depth; + uint minRed, maxRed, minGreen, maxGreen, minBlue, maxBlue; + + /** + number of pixels whose color is contained in the RGB cube which this node represents + */ + uint n1; + + /** + number of pixels whose color is not represented in a node at lower depth in the tree; initially, n2=0 for all nodes except leaves of the tree. + */ + uint n2; + + /** + sums of the red component values for all pixels not classified at a lower depth. The combination of these sums and n2 will ultimately characterize the mean color of a set of pixels represented by this node. + */ + uint Sr; + + /** + sums of the green component values for all pixels not classified at a lower depth. The combination of these sums and n2 will ultimately characterize the mean color of a set of pixels represented by this node. + */ + uint Sg; + + /** + sums of the blue component values for all pixels not classified at a lower depth. The combination of these sums and n2 will ultimately characterize the mean color of a set of pixels represented by this node. + */ + uint Sb; + + /** + the distance squared in RGB space between each pixel contained within a node and the nodes' center. This represents the quantization error for a node. + */ + uint E; + + MemorizedSpiritedArray* reassigned; +} + +-(id) initWithSpiritedArray:(SpiritedArray *)designatedSpiritedArray Colors: (uint) colors; + +-(uint) colors; + +-(SAReductionContext*) reduceToColors: (uint) colors; + +-(BOOL) leaf; + +-(SAColorType) centerColor; + +-(SAColorType) assignColor: (SAColorType) originalColor; + +-(SpiritedArray*) reassignSpiritedArray:(SpiritedArray*) designatedSpiritedArray; + +-(SAColorTree*) lowRedLowGreenLowBlue; +-(SAColorTree*) setLowRedLowGreenLowBlue: (SAColorTree*) branch; +-(SAColorTree*) highRedLowGreenLowBlue; +-(SAColorTree*) setHighRedLowGreenLowBlue: (SAColorTree*) branch; +-(SAColorTree*) lowRedHighGreenLowBlue; +-(SAColorTree*) setLowRedHighGreenLowBlue: (SAColorTree*) branch; +-(SAColorTree*) highRedHighGreenHighBlue; +-(SAColorTree*) setHighRedHighGreenHighBlue:(SAColorTree*) branch; +-(SAColorTree*) lowRedLowGreenHighBlue; +-(SAColorTree*) setLowRedLowGreenHighBlue: (SAColorTree*) branch; +-(SAColorTree*) lowRedHighGreenHighBlue; +-(SAColorTree*) setLowRedHighGreenHighBlue: (SAColorTree*) branch; +-(SAColorTree*) highRedLowGreenHighBlue; +-(SAColorTree*) setHighRedLowGreenHighBlue: (SAColorTree*) branch; +-(SAColorTree*) highRedHighGreenLowBlue; +-(SAColorTree*) setHighRedHighGreenLowBlue: (SAColorTree*) branch; + +@end diff --git a/foundationkit/SAColorTree.m b/foundationkit/SAColorTree.m new file mode 100755 index 0000000..d333a36 --- /dev/null +++ b/foundationkit/SAColorTree.m @@ -0,0 +1,557 @@ +// +// SAColorTree.m +// spiritedarray +// +// Created by Dave Horlick on 5/7/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAColorTree.h" +#import "math.h" +#import "SAReductionContext.h" + +@implementation SAColorTree + +-(id) init +{ + if (self = [super init]) + { + [self doSetup]; + } + + return self; +} + +-(id) initWithSpiritedArray:(SpiritedArray *)designatedSpiritedArray Colors: (uint) colors +{ + if (self = [super init]) + { + [self doSetup]; + [self classifySpiritedArray:designatedSpiritedArray]; + } + + return self; +} + +-(void) doSetup +{ + minRed = 0U; maxRed = 255U; + minGreen = 0U; maxGreen = 255U; + minBlue = 0U; maxBlue = 255U; + + branches = [[NSMutableArray alloc] initWithCapacity:8U]; + + for (uint i=0U; i<8; i++) + [branches addObject:[NSNull null]]; + + depth = 0U; + n1 = 0U; + n2 = 0U; +} + +-(void) setDepth: (uint) designatedDepth +{ + depth = designatedDepth; +} + +-(void) classifySpiritedArray: (SpiritedArray*) designatedSpiritedArray +{ + depth = 0U; + + // iterate over spirited array & classify pixel colors + + for (uint frame=0U; frame < [designatedSpiritedArray frames]; frame++) + { + for (uint y=0U; y < [designatedSpiritedArray height]; y++) + { + for (uint x = 0U; x < [designatedSpiritedArray width]; x++) + { + SAColorType color = [designatedSpiritedArray pixelColorAtFrame:frame X:x Y:y]; + [self classifyColor:color CurrentDepth:1U TargetDepth:5U]; + } + } + } +} + +-(SAColorType) centerColor +{ + SAColorType result = {(maxRed-minRed)/2, (maxGreen-minGreen)/2, (maxBlue-minBlue)/2}; + return result; +} + +-(void) classifyColor: (SAColorType) color CurrentDepth: (uint) designatedCurrentDepth TargetDepth: (uint) designatedTargetDepth +{ + depth = designatedCurrentDepth; + + n1++; + SAColorType centerColor = [self centerColor]; + E += (pow(color.Red-centerColor.Red, 2.0) + pow(color.Green-centerColor.Green, 2.0) + pow(color.Blue-centerColor.Blue, 2.0)); + + if (designatedCurrentDepth < designatedTargetDepth) + { + SAColorTree* subNode = [self associatedBranch: color]; + [subNode classifyColor:color CurrentDepth:designatedCurrentDepth+1U TargetDepth:designatedTargetDepth]; + } + else + { + n2++; + + Sr+=color.Red; + Sg+=color.Green; + Sb+=color.Blue; + } +} + +-(SAReductionContext*) reduceToColors: (uint) colors +{ + SAReductionContext* reductionContext = [SAReductionContext new]; + + BOOL firstTime = YES; + double Ep = 0.0; + + uint previousColorCount = 0U; + uint currentColorCount = 0U; + + while ((currentColorCount=[self colors]) > colors) + { + if (!firstTime) + { + if (previousColorCount==currentColorCount) + { + @throw [NSException exceptionWithName:@"Bug" reason:[NSString stringWithFormat:@"Color count isn't declining: %u", currentColorCount] userInfo:nil]; // bug + } + + Ep = [self minE]; + } + + [self reduceTo: Ep]; + + firstTime = NO; + previousColorCount = currentColorCount; + } + + return reductionContext; +} + +-(SAColorTree*) branchAtIndex:(uint) index +{ + id result = [branches objectAtIndex:0U]; + if ([[NSNull null] isEqual: result]) + return nil; + else + return result; +} + +-(SAColorTree*) setBranch: (SAColorTree*)branch AtIndex:(uint) index +{ + SAColorTree* oldValue = [self branchAtIndex:index]; + + if (branch!=nil) + [branches replaceObjectAtIndex:index withObject:branch]; + else + [branches replaceObjectAtIndex:index withObject:[NSNull null]]; + + return oldValue; +} + +-(SAColorTree*) lowRedLowGreenLowBlue +{ + return [self branchAtIndex:0U]; +} + +-(SAColorTree*) setLowRedLowGreenLowBlue: (SAColorTree*) branch; +{ + return [self setBranch: branch AtIndex: 0U]; +} + +-(SAColorTree*) highRedLowGreenLowBlue +{ + return [self branchAtIndex:1U]; +} + +-(SAColorTree*) setHighRedLowGreenLowBlue: (SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 1U]; +} + +-(SAColorTree*) lowRedHighGreenLowBlue +{ + return [self branchAtIndex: 2U]; +} + +-(SAColorTree*) setLowRedHighGreenLowBlue: (SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 2U]; +} + +-(SAColorTree*) highRedHighGreenHighBlue +{ + return [self branchAtIndex: 3U]; +} + +-(SAColorTree*) setHighRedHighGreenHighBlue:(SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 3U]; +} + +-(SAColorTree*) lowRedLowGreenHighBlue +{ + return [self branchAtIndex: 4U]; +} + +-(SAColorTree*) setLowRedLowGreenHighBlue: (SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 4U]; +} + +-(SAColorTree*) lowRedHighGreenHighBlue +{ + return [self branchAtIndex:5U]; +} + +-(SAColorTree*) setLowRedHighGreenHighBlue: (SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 5U]; +} + +-(SAColorTree*) highRedLowGreenHighBlue +{ + return [self branchAtIndex:6U]; +} + +-(SAColorTree*) setHighRedLowGreenHighBlue: (SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 6U]; +} + +-(SAColorTree*) highRedHighGreenLowBlue +{ + return [self branchAtIndex:7U]; +} + +-(SAColorTree*) setHighRedHighGreenLowBlue: (SAColorTree*) branch +{ + return [self setBranch: branch AtIndex: 7U]; +} + +-(void) reduceTo: (double) Ep +{ + if ([self lowRedLowGreenLowBlue] != nil) + { + if ([[self lowRedLowGreenLowBlue] leaf]) + { + [self assimilate: [self lowRedLowGreenLowBlue]]; + [self setLowRedLowGreenLowBlue: nil]; + } + else + [[self lowRedLowGreenLowBlue] reduceTo:Ep]; + } + + if ([self highRedLowGreenLowBlue]!=nil) + { + if ([[self highRedLowGreenLowBlue] leaf]) + { + [self assimilate:[self highRedLowGreenLowBlue]]; + [self setHighRedLowGreenLowBlue: nil]; + } + else + [[self highRedLowGreenLowBlue] reduceTo:Ep]; + } + + if ([self lowRedHighGreenLowBlue]!=nil) + { + if ([[self lowRedHighGreenLowBlue] leaf]) + { + [self assimilate:[self lowRedHighGreenLowBlue]]; + [self setLowRedHighGreenLowBlue: nil]; + } + else + [[self lowRedHighGreenLowBlue] reduceTo:Ep]; + } + + if ([self highRedHighGreenHighBlue]!=nil) + { + if ([[self highRedHighGreenHighBlue] leaf]) + { + [self assimilate:[self highRedHighGreenHighBlue]]; + [self setHighRedHighGreenHighBlue: nil]; + } + else + [[self highRedHighGreenHighBlue] reduceTo:Ep]; + } + + if ([self lowRedLowGreenHighBlue]!=nil) + { + if ([[self lowRedLowGreenHighBlue] leaf]) + { + [self assimilate:[self lowRedLowGreenHighBlue]]; + [self setLowRedLowGreenHighBlue: nil]; + } + else + [[self lowRedLowGreenHighBlue] reduceTo:Ep]; + } + + if ([self lowRedHighGreenHighBlue]!=nil) + { + if ([[self lowRedHighGreenHighBlue] leaf]) + { + [self assimilate:[self lowRedHighGreenHighBlue]]; + [self setLowRedHighGreenHighBlue: nil]; + } + else + [[self lowRedHighGreenHighBlue] reduceTo:Ep]; + } + + if ([self highRedLowGreenHighBlue]!=nil) + { + if ([[self highRedLowGreenHighBlue] leaf]) + { + [self assimilate:[self highRedLowGreenHighBlue]]; + [self setHighRedLowGreenHighBlue: nil]; + } + [[self highRedLowGreenHighBlue] reduceTo:Ep]; + } + + if ([self highRedHighGreenLowBlue]!=nil) + { + if ([[self highRedHighGreenLowBlue] leaf]) + { + [self assimilate:[self highRedHighGreenLowBlue]]; + [self setHighRedHighGreenLowBlue: nil]; + } + else + [[self highRedHighGreenLowBlue] reduceTo:Ep]; + } +} + +-(void) assimilate: (SAColorTree*) doomed +{ + // The values of n2, Sr, Sg, and Sb in a node being pruned are always added to the corresponding data in that node's parent. + + n2 += [doomed n2]; + Sr += [doomed Sr]; + Sg += [doomed Sg]; + Sb += [doomed Sb]; +} + +-(uint) colors +{ + uint colors = 1U; + + if ([self lowRedLowGreenLowBlue]!=nil) + colors += [[self lowRedLowGreenLowBlue] colors]; + if ([self highRedLowGreenLowBlue]!=nil) + colors += [[self highRedLowGreenLowBlue] colors]; + if ([self lowRedHighGreenLowBlue]!=nil) + colors += [[self lowRedHighGreenLowBlue] colors]; + if ([self highRedHighGreenHighBlue]!=nil) + colors += [[self highRedHighGreenHighBlue] colors]; + if ([self lowRedLowGreenHighBlue]!=nil) + colors += [[self lowRedLowGreenHighBlue] colors]; + if ([self lowRedHighGreenHighBlue]!=nil) + colors += [[self lowRedHighGreenHighBlue] colors]; + if ([self highRedLowGreenHighBlue]!=nil) + colors += [[self highRedLowGreenHighBlue] colors]; + if ([self highRedHighGreenLowBlue]!=nil) + colors += [[self highRedHighGreenLowBlue] colors]; + + return colors; +} + +-(BOOL) leaf +{ + return (n2 > 0); // is this right? +} + +-(double) minE +{ + BOOL foundAny = NO; + + double min = 0.0; + + if ([self leaf]) + { + min = E; + foundAny = YES; + } + else + { + if ([self lowRedLowGreenLowBlue]!=nil) + { + min = [SAColorTree max:[[self lowRedLowGreenLowBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self highRedLowGreenLowBlue]!=nil) + { + min = [SAColorTree max:[[self highRedLowGreenLowBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self lowRedHighGreenLowBlue]!=nil) + { + min = [SAColorTree max:[[self lowRedHighGreenLowBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self highRedHighGreenHighBlue]!=nil) + { + min = [SAColorTree max:[[self highRedHighGreenHighBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self lowRedLowGreenHighBlue]!=nil) + { + min = [SAColorTree max:[[self lowRedLowGreenHighBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self lowRedHighGreenHighBlue]!=nil) + { + min = [SAColorTree max:[[self lowRedHighGreenHighBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self highRedLowGreenHighBlue]!=nil) + { + min = [SAColorTree max:[[self highRedLowGreenHighBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + if ([self highRedHighGreenLowBlue]!=nil) + { + min = [SAColorTree max:[[self highRedHighGreenLowBlue] minE] B:min AlwaysTakeA:!foundAny]; + foundAny = YES; + } + } + + return min; +} + ++(double) max: (double) a B: (double) b AlwaysTakeA: (BOOL) alwaysTakeA; +{ + if (alwaysTakeA) + return a; + else if (a>b) + return a; + else + return b; +} + +-(uint) n1 +{ + return n1; +} + +-(uint) n2 +{ + return n2; +} + +-(uint) Sr +{ + return Sr; +} + +-(uint) Sg +{ + return Sg; +} + +-(uint) Sb +{ + return Sb; +} + +-(uint) E +{ + return E; +} + +-(NSArray*) branches +{ + NSMutableArray* result = [NSMutableArray new]; + for (uint i=0U; i<[branches count]; i++) + { + SAColorTree* thing = [self branchAtIndex:i]; + if (thing!=nil) + [result addObject: thing]; + // else + // ??? + } + + return result; +} + +-(SAColorTree*) associatedBranch: (SAColorType) color +{ + SAColorType centerColor = [self centerColor]; + + // TODO create a branch if necessary + + if (color.Red < centerColor.Red) + { + if (color.Green < centerColor.Green) + { + if (color.Blue < centerColor.Blue) + return [self lowRedLowGreenLowBlue]; + else + return [self lowRedLowGreenHighBlue]; + } + else + { + if (color.Blue < centerColor.Blue) + return [self lowRedHighGreenLowBlue]; + else + return [self lowRedHighGreenHighBlue]; + } + } + else + { + if (color.Green < centerColor.Green) + { + if (color.Blue < centerColor.Blue) + return [self highRedLowGreenLowBlue]; + else + return [self highRedLowGreenHighBlue]; + } + else + { + if (color.Blue < centerColor.Blue) + return [self highRedHighGreenLowBlue]; + else + return [self highRedHighGreenHighBlue]; + } + } + + return nil; +} + +-(SAColorType) assignColor: (SAColorType) originalColor +{ + SAColorTree* associated = [self associatedBranch: originalColor]; + + if (associated != nil) + { + return [associated assignColor:originalColor]; + } + else + { + return [self centerColor]; + } +} + +-(SpiritedArray*) reassignSpiritedArray:(SpiritedArray*) designatedSpiritedArray +{ + return designatedSpiritedArray; + + MemorizedSpiritedArray* result = [[MemorizedSpiritedArray alloc] initWith: [designatedSpiritedArray frames] Width: [designatedSpiritedArray width] Height: [designatedSpiritedArray height]]; + + for (uint frame=0U; frame<[designatedSpiritedArray frames]; frame++) + { + for (uint y=0U; y<[designatedSpiritedArray height]; y++) + { + for (uint x=0U; x<[designatedSpiritedArray width]; x++) + { + [result writePixelColorAtFrame:frame X:x Y:y Color:[self assignColor:[designatedSpiritedArray pixelColorAtFrame:frame X:x Y:y]]]; + } + } + } + + return result; +} + +@end diff --git a/foundationkit/SAConcreteBounded.h b/foundationkit/SAConcreteBounded.h new file mode 100755 index 0000000..9ae8fce --- /dev/null +++ b/foundationkit/SAConcreteBounded.h @@ -0,0 +1,19 @@ +// +// SAConcreteBounded.h +// spiritedarray +// +// Created by Dave Horlick on 10/4/13. +// Copyleft 2013 River Porpoise Software +// + +#import + +@interface SAConcreteBounded : NSObject +{ + NSRect bounds; +} + +-(id) initWith: (NSRect)designatedRect; +-(NSRect)bounds; + +@end diff --git a/foundationkit/SAConcreteBounded.m b/foundationkit/SAConcreteBounded.m new file mode 100755 index 0000000..1211094 --- /dev/null +++ b/foundationkit/SAConcreteBounded.m @@ -0,0 +1,33 @@ +// +// SAConcreteBounded.m +// spiritedarray +// +// Created by Dave Horlick on 10/4/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAConcreteBounded.h" + +@implementation SAConcreteBounded + +-(id) initWith: (NSRect)designatedBounds +{ + if (self = [super init]) + { + bounds = designatedBounds; + } + + return self; +} + +-(NSRect) bounds +{ + return bounds; +} + +-(NSString *)description +{ + return [NSString stringWithFormat:@"", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height]; +} + +@end diff --git a/foundationkit/SAFreezeFrame.h b/foundationkit/SAFreezeFrame.h new file mode 100755 index 0000000..db8c4b8 --- /dev/null +++ b/foundationkit/SAFreezeFrame.h @@ -0,0 +1,19 @@ +// +// SAFreezeFrame.h +// spiritedarray +// +// Created by Dave Horlick on 11/11/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SpiritedArray.h" + +@interface SAFreezeFrame : SpiritedArray +{ + SpiritedArray* spiritedArray; + uint frozenFrame; +} + +-(SpiritedArray*) spiritedArray; + +@end diff --git a/foundationkit/SAFreezeFrame.m b/foundationkit/SAFreezeFrame.m new file mode 100755 index 0000000..84aa2a8 --- /dev/null +++ b/foundationkit/SAFreezeFrame.m @@ -0,0 +1,54 @@ +// +// SAFreezeFrame.m +// spiritedarray +// +// Created by Dave Horlick on 11/11/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SAFreezeFrame.h" + +@implementation SAFreezeFrame + +-(id) initWith: (SpiritedArray*) designatedSpiritedArray Frame:(uint) designatedFrozenFrame +{ + if (self = [super init]) + { + spiritedArray = designatedSpiritedArray; + frozenFrame = designatedFrozenFrame; + } + + return self; +} + +-(uint) frames +{ + return 1; +} + +-(SpiritedArray*) spiritedArray +{ + return spiritedArray; +} + +-(uint) width +{ + return [spiritedArray width]; +} + +-(uint) height +{ + return [spiritedArray height]; +} + +-(SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + if (frame!=0) + { + @throw [NSException exceptionWithName:@"bad frame index" reason:@"Frame index must be zero." userInfo:nil]; + } + + return [spiritedArray pixelColorAtFrame:frozenFrame X:x Y:y]; +} + +@end diff --git a/foundationkit/SAHyperPlane.h b/foundationkit/SAHyperPlane.h new file mode 100755 index 0000000..2b59494 --- /dev/null +++ b/foundationkit/SAHyperPlane.h @@ -0,0 +1,21 @@ +// +// SAHyperPlane.h +// spiritedarray +// +// Created by Dave Horlick on 11/5/12. +// Copyleft 2012 River Porpoise Software +// + +@interface SAHyperPlane : NSObject +{ + uint width; + uint height; + uint frames; +} + +- (uint) frames; +- (uint) width; +- (uint) height; +- (uint) pixels; + +@end diff --git a/foundationkit/SAHyperPlane.m b/foundationkit/SAHyperPlane.m new file mode 100755 index 0000000..cddc3ba --- /dev/null +++ b/foundationkit/SAHyperPlane.m @@ -0,0 +1,33 @@ +// +// SAHyperCube.m +// spiritedarray +// +// Created by Dave Horlick on 11/5/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SAHyperPlane.h" + +@implementation SAHyperPlane + +- (uint) frames +{ + return frames; +} + +- (uint) width +{ + return width; +} + +- (uint) height +{ + return height; +} + +-(uint) pixels +{ + return frames * width * height; +} + +@end diff --git a/foundationkit/SAMetapixelPalette.h b/foundationkit/SAMetapixelPalette.h new file mode 100755 index 0000000..9a46b1e --- /dev/null +++ b/foundationkit/SAMetapixelPalette.h @@ -0,0 +1,34 @@ +// +// SAMetapixelPalette.h +// spiritedarray +// +// Created by Dave Horlick on 3/3/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import "MemorizedSpiritedArray.h" + +/** + A memorized spirited array whose bitmap can be used as a tile for rendering other + spirtied arrays. + + The palette dictionary contains color-filtered copies of the original tile content. They are outputed as Memorized Spirited Arrays. + + This is used to accomplish "meta" tiled drawing, as well as for user-specified animation tiles. + */ +@interface SAMetapixelPalette : NSObject +{ + MemorizedSpiritedArray* content; + NSMutableDictionary* palette; +} + +-(id)initWith: (MemorizedSpiritedArray*) designatedMemorizedSpiritedArray; +-(MemorizedSpiritedArray*) metapixelForColor: (SAColorType) color; +-(MemorizedSpiritedArray*) filterContent: (SAColorType) color; +-(MemorizedSpiritedArray*) content; + ++(uint) indexFor: (SAColorType) color; ++(SAColorType) colorFor: (uint) index; + +@end diff --git a/foundationkit/SAMetapixelPalette.m b/foundationkit/SAMetapixelPalette.m new file mode 100755 index 0000000..e384d81 --- /dev/null +++ b/foundationkit/SAMetapixelPalette.m @@ -0,0 +1,83 @@ +// +// SAMetapixelPalette.m +// spiritedarray +// +// Created by Dave Horlick on 3/3/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SpiritedArray.h" +#import "SAMetapixelPalette.h" + +@implementation SAMetapixelPalette + +-(id)initWith: (MemorizedSpiritedArray*) designatedMemorizedSpiritedArray +{ + if (self = [super init]) + { + content = designatedMemorizedSpiritedArray; + palette = [NSMutableDictionary new]; + } + + return self; +} + +-(MemorizedSpiritedArray*) metapixelForColor: (SAColorType) color +{ + uint colorIndex = [SAMetapixelPalette indexFor: color]; + NSNumber* key = [NSNumber numberWithUnsignedInt: colorIndex]; + MemorizedSpiritedArray* result = [palette objectForKey:key]; + + if (result == nil) + { + result = [self filterContent:color]; + [palette setObject:result forKey:key]; + } + + return result; +} + +-(MemorizedSpiritedArray*) filterContent: (SAColorType) color +{ + MemorizedSpiritedArray* filtered = [[MemorizedSpiritedArray alloc] initWith:[content frames] Width:[content width] Height:[content height]]; // TODO transcribe frames accurately + + for (uint frame=0; frame < [content frames]; frame++) + { + for (uint y=0; y < [content height]; y++) + { + for (uint x = 0; x < [content width]; x++) + { + SAColorType subPixelColor = filterPixel([content pixelColorAtFrame:frame X:x Y:y], color); + [filtered writePixelColorAtFrame:frame X:x Y:y Color:subPixelColor]; + } + } + } + + return filtered; +} + +-(MemorizedSpiritedArray*) content +{ + return content; +} + ++(uint) indexFor: (SAColorType) color +{ + uint result = (65536*color.Red) + + (256*color.Green) + + color.Blue; + + return result; +} + ++(SAColorType) colorFor: (uint) index +{ + uint red = index / 65536U; + uint leftover = index % 65536U; + uint green = leftover / 256U; + uint blue = leftover % 256U; + SAColorType result = {red, green, blue}; + return result; +} + +@end diff --git a/foundationkit/SAReductionContext.h b/foundationkit/SAReductionContext.h new file mode 100755 index 0000000..b213393 --- /dev/null +++ b/foundationkit/SAReductionContext.h @@ -0,0 +1,15 @@ +// +// SAReductionContext.h +// spiritedarray +// +// Created by Dave Horlick on 5/19/13. +// Copyleft 2013 River Porpoise Software +// + +#import + +@interface SAReductionContext : NSObject + +@property uint Ep; + +@end diff --git a/foundationkit/SAReductionContext.m b/foundationkit/SAReductionContext.m new file mode 100755 index 0000000..be2d05f --- /dev/null +++ b/foundationkit/SAReductionContext.m @@ -0,0 +1,15 @@ +// +// SAReductionContext.m +// spiritedarray +// +// Created by Dave Horlick on 5/19/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAReductionContext.h" + +@implementation SAReductionContext + +@synthesize Ep; + +@end diff --git a/foundationkit/SAVideoExportSettings.h b/foundationkit/SAVideoExportSettings.h new file mode 100755 index 0000000..49563f8 --- /dev/null +++ b/foundationkit/SAVideoExportSettings.h @@ -0,0 +1,20 @@ +// +// SAVideoExportSettings.h +// spiritedarray +// +// Created by Dave Horlick on 10/2/13. +// Copyleft 2013 River Porpoise Software +// + +#import +#import + +@interface SAVideoExportSettings : NSObject +{ + +} + +@property (copy) NSNumber* widthInPixels; +@property (copy) NSNumber* heightInPixels; + +@end diff --git a/foundationkit/SAVideoExportSettings.m b/foundationkit/SAVideoExportSettings.m new file mode 100755 index 0000000..178642c --- /dev/null +++ b/foundationkit/SAVideoExportSettings.m @@ -0,0 +1,13 @@ +// +// SAVideoExportSettings.m +// spiritedarray +// +// Created by Dave Horlick on 10/2/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SAVideoExportSettings.h" + +@implementation SAVideoExportSettings + +@end diff --git a/foundationkit/SpiritedArray.h b/foundationkit/SpiritedArray.h new file mode 100755 index 0000000..ee278f9 --- /dev/null +++ b/foundationkit/SpiritedArray.h @@ -0,0 +1,36 @@ +#import +#import "SAHyperPlane.h" + +@class MemorizedSpiritedArray; + +typedef unsigned char SAByteType; + +typedef struct SAColorType { + SAByteType Red, Green, Blue; +} SAColorType; + +BOOL SAEqualColorTypes(SAColorType aColorType, SAColorType bColorType); + +NSString* SADescribeColorType(SAColorType colorType); + +SAColorType filterPixel(SAColorType originalPixel, SAColorType filter); + +@interface SpiritedArray : SAHyperPlane +{ + +} + +- (id) initWithFileNameToRead: (NSString*) fileName; +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y; +- (void) writePixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y Color:(SAColorType)color; +- (void) close; +- (BOOL) streamed; +- (MemorizedSpiritedArray *) fitCopyToWidth:(uint)width Height:(uint)height; +- (uint) delayInCentisAfterFrame: (uint)frame; +- (uint) averageDelayInCentisBetweenFrames; + ++ (SAColorType) white; ++ (SAColorType) black; + +@end + diff --git a/foundationkit/SpiritedArray.m b/foundationkit/SpiritedArray.m new file mode 100755 index 0000000..78ce62b --- /dev/null +++ b/foundationkit/SpiritedArray.m @@ -0,0 +1,183 @@ +#import +#import "SpiritedArray.h" +#import "StreamedGifDecoder.h" +#import "MemorizedSpiritedArray.h" + +@implementation SpiritedArray + +static const SAColorType WHITE = {255, 255, 255}; +static const SAColorType BLACK = {0, 0, 0}; + +-(id) initWithFileNameToRead: (NSString*)fileName +{ + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +- (void) writePixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y Color:(SAColorType)color +{ + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +- (uint) delayInCentisAfterFrame: (uint)frame +{ + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)] + userInfo:nil]; +} + +-(uint) averageDelayInCentisBetweenFrames +{ + if (frames==0U) + return 0U; + + unsigned long total = 0UL; + for (uint frame=0U; frame %u", [self delayInCentisAfterFrame:frame]); + total += [self delayInCentisAfterFrame:frame]; + } + + return (uint)(total / frames); +} + +- (void) close +{ +} + +- (NSString *)description +{ + return [NSString stringWithFormat: @"[SpiritedArray width=%u height=%u frames=%u]", [self width], [self height], [self frames]]; +} + +- (BOOL) streamed +{ + return NO; +} + +- (MemorizedSpiritedArray *) fitCopyToWidth:(uint)designatedWidth Height:(uint)designatedHeight +{ + MemorizedSpiritedArray* result = [[MemorizedSpiritedArray alloc] initWith:[self frames] Width:designatedWidth Height:designatedHeight ]; + + float yFraction = (float) [self height] / (float) designatedHeight; + float xFraction = (float) [self width] / (float) designatedWidth; + + for (uint frame=0; frame < [self frames]; frame++) + { + for (uint scaledY=0; scaledY < designatedHeight; scaledY++) + { + for (uint scaledX = 0; scaledX < designatedWidth; scaledX++) + { + uint red = 0U; + uint green = 0U; + uint blue = 0U; + uint pixelCount = 0U; + + uint endY = (float)(scaledY+1U) * yFraction; + + for (uint y=(float)scaledY * yFraction; y < endY; y++) + { + uint endX = (float)(scaledX+1U) * xFraction; + + for (uint x=(float)scaledX * xFraction; x < endX; x++) + { + SAColorType color = [self pixelColorAtFrame:frame X:x Y:y]; + red += color.Red; + blue += color.Blue; + green += color.Green; + pixelCount++; + } + } + + SAColorType scaledColor; + + if (pixelCount>0) + { + scaledColor.Red=red/pixelCount; + scaledColor.Blue=blue/pixelCount; + scaledColor.Green=green/pixelCount; + } + else + { + scaledColor.Red = 0; + scaledColor.Green = 255; + scaledColor.Blue = 0; + + // TODO investigate + } + + [result writePixelColorAtFrame:frame X:scaledX Y:scaledY Color:scaledColor]; + } + } + } + + return result; +} + ++(SAColorType) white +{ + return WHITE; +} + ++(SAColorType) black +{ + return BLACK; +} + +@end + +/* int main(int argc, const char *argv[]) +{ + if (argc<=1) + { + NSLog (@"usage: spiritedarray file.[gif|mpng|apng]"); + return -1; + } + else + { + printf("arg1 = %s\n", argv[1]); + printf("arg0 = %s\n", argv[0]); + NSString* imageFileName = [[NSString alloc] initWithUTF8String: argv[1]]; + + SpiritedArray * spiritedArray = [SpiritedArray build: imageFileName]; + NSLog (@"Retrieving pixel color…"); + int pixelColor = [spiritedArray pixelColorAtFrame:0 X: 0 Y:0]; + NSLog (@"pixelColor = %i", pixelColor); + return pixelColor; + } +} */ + +BOOL SAEqualColorTypes(SAColorType aColorType, SAColorType bColorType) +{ + return (aColorType.Red==bColorType.Red + && aColorType.Green==bColorType.Green + && aColorType.Blue==bColorType.Blue); +} + +NSString* SADescribeColorType(SAColorType colorType) +{ + return [NSString localizedStringWithFormat:@"SAColorType {Red = %u, Green = %u, Blue = %u}", + colorType.Red, colorType.Green, colorType.Blue]; +} + +SAColorType filterPixel(SAColorType originalPixel, SAColorType filter) +{ + SAColorType reply = { + .Red = originalPixel.Red > filter.Red ? filter.Red : originalPixel.Red, + .Green = originalPixel.Green > filter.Green ? filter.Green : originalPixel.Green, + .Blue = originalPixel.Blue > filter.Blue ? filter.Blue : originalPixel.Blue }; + + return reply; +} + + diff --git a/foundationkit/SpiritedArrayFactory.h b/foundationkit/SpiritedArrayFactory.h new file mode 100755 index 0000000..3a21373 --- /dev/null +++ b/foundationkit/SpiritedArrayFactory.h @@ -0,0 +1,17 @@ +// +// SpirtedArrayFactory.h +// spiritedarray +// +// Created by Dave Horlick on 8/27/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SpiritedArray.h" +#import + +@interface SpiritedArrayFactory : NSObject + ++(SpiritedArray *) build:(NSString *)imageFileName; ++(NSString*) fileExtension: (NSString*) string; + +@end diff --git a/foundationkit/SpiritedArrayFactory.m b/foundationkit/SpiritedArrayFactory.m new file mode 100755 index 0000000..f5fae77 --- /dev/null +++ b/foundationkit/SpiritedArrayFactory.m @@ -0,0 +1,55 @@ +// +// SpirtedArrayFactory.m +// spiritedarray +// +// Created by Dave Horlick on 8/27/13. +// Copyleft 2013 River Porpoise Software +// + +#import "SpiritedArrayFactory.h" +#import "StreamedGifDecoder.h" + +@implementation SpiritedArrayFactory + ++(SpiritedArray *) build:(NSString *)imageFileName +{ + NSLog(@"imageFileName = %@", imageFileName); + NSString* extension = [SpiritedArrayFactory fileExtension: imageFileName]; + NSLog(@"extension = %@", extension); + + if ([extension caseInsensitiveCompare: @"gif"]==0) + { + StreamedGifDecoder* streamedGifDecoder = [[StreamedGifDecoder alloc] initWithFileNameToRead: imageFileName]; + + if (![streamedGifDecoder interlaced]) + return streamedGifDecoder; + else + { + NSLog(@"Boom, interlaced!"); + return [streamedGifDecoder unInterlace]; + } + } + else + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Unrecognized file extension %@. For non-GIF file types, please consult AppKitAwareSpiritedArrayFactory, instead.", extension] + userInfo:nil]; + } +} + ++ (NSString*) fileExtension: (NSString*) string +{ + for (long i=[string length]-1; i>=0; i--) + { + unichar ch = [string characterAtIndex: i]; + + if (ch=='.') + { + return [string substringFromIndex: i+1]; + } + } + + return nil; +} + +@end diff --git a/foundationkit/SpiritedArrayIterator.h b/foundationkit/SpiritedArrayIterator.h new file mode 100755 index 0000000..55f31ae --- /dev/null +++ b/foundationkit/SpiritedArrayIterator.h @@ -0,0 +1,51 @@ +// +// SpiritedArrayIterator.h +// spiritedarray +// +// Created by Dave Horlick on 10/29/12. +// Copyleft 2012 River Porpoise Software +// + +#import +#import "SpiritedArray.h" + +/** + * Usage pattern: + * + * while ([spiritedArrayIterator arrayHasAnotherFrame]) + * { + * [spiritedArrayIterator nextFrame]; + * + * while ([spiritedArrayIterator imageHasAnotherRow]) + * { + * [spiritedArrayIterator nextRow]; + * + * while ([spiritedArrayIterator rowHasAnotherPixel]) + * { + * SAPixelType pixel = [spiritedArrayIterator nextPixel]; + * // TODO … + * } + * } + * } + */ +@interface SpiritedArrayIterator : SAHyperPlane +{ + SpiritedArray* spiritedArray; + int x; + int y; + int frame; +} + +-(id)initWithSpiritedArray: (SpiritedArray*) designatedSpiritedArray; +-(BOOL)rowHasAnotherPixel; +-(SAColorType)nextPixel; +-(BOOL)imageHasAnotherRow; +-(void)nextRow; +-(BOOL)arrayHasAnotherFrame; +-(void)nextFrame; +-(uint) delayInCentisAfterFrame: (uint)frame; + +- (void) close; +-(void)abandon; + +@end diff --git a/foundationkit/SpiritedArrayIterator.m b/foundationkit/SpiritedArrayIterator.m new file mode 100755 index 0000000..8096b51 --- /dev/null +++ b/foundationkit/SpiritedArrayIterator.m @@ -0,0 +1,97 @@ +// +// SpiritedArrayIterator.m +// spiritedarray +// +// Created by Dave Horlick on 10/29/12. +// Copyleft 2012 River Porpoise Software +// + +#import "SpiritedArrayIterator.h" + +@implementation SpiritedArrayIterator + +-(id)initWithSpiritedArray: (SpiritedArray*) designatedSpiritedArray; +{ + if (self = [super init]) + { + spiritedArray = designatedSpiritedArray; + width = [designatedSpiritedArray width]; + height = [designatedSpiritedArray height]; + frames = [designatedSpiritedArray frames]; + x = -1U; + y = -1U; + frame = -1U; + } + return self; +} + +-(BOOL)rowHasAnotherPixel +{ + return x+1 < [spiritedArray width]; +} + +-(SAColorType)nextPixel +{ + if ([self rowHasAnotherPixel]) + x++; + else + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"No more pixels available" userInfo:nil]; + + return [spiritedArray pixelColorAtFrame:frame X:x Y:y]; +} + +-(BOOL)imageHasAnotherRow +{ + return y+1 < [spiritedArray height]; +} + +-(void)nextRow +{ + if ([self imageHasAnotherRow]) + { + y++; + x=-1; + } + else + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"No more rows." userInfo:nil]; +} + +-(BOOL)arrayHasAnotherFrame +{ + return frame+1 < [spiritedArray frames]; +} + +-(void)nextFrame +{ + if ([self arrayHasAnotherFrame]) + { + frame++; + x=-1; + y=-1; + } + else + @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:@"No more frames." userInfo:nil]; +} + +-(void)abandon +{ + if (frame>-1 || x>-1 || y>-1) + { + [spiritedArray close]; + frame = -1; + x = -1; + y = -1; + } +} + +- (void) close +{ + [spiritedArray close]; +} + +- (uint) delayInCentisAfterFrame: (uint)requestedFrame +{ + return [spiritedArray delayInCentisAfterFrame:requestedFrame]; +} + +@end diff --git a/foundationkit/StreamedGifDecoder.h b/foundationkit/StreamedGifDecoder.h new file mode 100755 index 0000000..f567885 --- /dev/null +++ b/foundationkit/StreamedGifDecoder.h @@ -0,0 +1,45 @@ +#import +#import "SpiritedArray.h" +#include "gif_lib.h" +#include "MemorizedSpiritedArray.h" + +@interface StreamedGifDecoder : SpiritedArray +{ + NSString* filePath; + + /** + * nil if closed + * not nil if open + */ + GifFileType* gifFile; + + BOOL readingImageData; + + int lineWithinFrame; + int frameIndex; + unsigned char* rasterBits; + void (^respoolHandler)(void); + int transparentColorIndex; + uint disposalMethod; + int backgroundColorIndex; + + BOOL mustMaintainTwoDimensionalState; + MemorizedSpiritedArray* twoDimensionalState; + BOOL interlaced; + NSMutableArray* delayInCentisAfterFrames; +} + +/** + * @param framesEncountered a pointer to an int with which to maintain a running tally, + * or NULL if you don't care + * @return yes, if explicitly terminated + */ +- (BOOL) nextChunk: (int*) framesEncountered; +- (void (^)(void)) respoolHandler; +- (void) setRespoolHandler:(void (^)(void))designatedHandler NS_AVAILABLE_MAC(10_6); +- (unsigned char) colorTableIndexAtFrame:(uint)requestedFrameIndex X:(uint)requestedX Y:(uint)requestedY; +- (SAColorType) pixelColorForColorTableIndex:(unsigned char) colorIndex; +- (BOOL) interlaced; +- (MemorizedSpiritedArray*) unInterlace; + +@end diff --git a/foundationkit/StreamedGifDecoder.m b/foundationkit/StreamedGifDecoder.m new file mode 100755 index 0000000..abd861a --- /dev/null +++ b/foundationkit/StreamedGifDecoder.m @@ -0,0 +1,652 @@ +#import +#import "StreamedGifDecoder.h" + +#undef _GBA_OPTMEM + +@implementation StreamedGifDecoder + +-(id) initWithFileNameToRead: (NSString*)designatedFilePath +{ + if (self = [super init]) + { + NSLog (@"opening file…"); + respoolHandler = nil; + frames = 0U; + filePath = designatedFilePath; + + [self openIfNecessary]; + + width = gifFile->SWidth; + height = gifFile->SHeight; + + if (gifFile->SColorMap!=NULL) + backgroundColorIndex = gifFile->SBackGroundColor; + else + backgroundColorIndex = -1; + + mustMaintainTwoDimensionalState = NO; + twoDimensionalState = nil; // If the GIF includes transparency, we need to keep track of the screen in order to determine the colors of composited pixels + + BOOL finishedReading = false; + delayInCentisAfterFrames = [[NSMutableArray alloc] init]; + + int initTimeFramesCounter = 0; + + do + { + finishedReading = [self nextChunk: &initTimeFramesCounter]; + // NSLog(@"frames so far = %i", frames); + } + while (!finishedReading); + + frames = initTimeFramesCounter; + // frames = 1; // TODO remove this + + NSLog(@"gifFile->ImageCount = %i", gifFile->ImageCount); + NSLog(@"mustMaintainTwoDimensionalState? %@", mustMaintainTwoDimensionalState?@"yes":@"no"); + + NSLog(@"SColorResolution: %i", gifFile->SColorResolution); + + if (frames==0 && gifFile->ImageCount==1) + { + // degenerate, static image case. + frames = 1; + } + + NSLog(@"frames after initialization = %u", frames); + + if (gifFile->Image.Interlace==0) + interlaced = NO; + else + interlaced = YES; + + [self close]; + [self reset]; + + // NSLog (@"returning self…"); + } + + return self; +} + +- (SAColorType) pixelColorAtFrame:(uint)requestedFrameIndex X:(uint)requestedX Y:(uint)requestedY +{ + while (frameIndex < requestedFrameIndex || !readingImageData) + { + [self openIfNecessary]; + + BOOL terminated = [self nextChunk: &frameIndex]; + if (terminated) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"hit end of file without hitting requested pixel (%u, %u) of frame %u", requestedX, requestedY, requestedFrameIndex] + userInfo:nil]; + } + } + + if (((GifWord)requestedX < gifFile->Image.Left) + || ((GifWord)requestedY < gifFile->Image.Top) + || ((GifWord)requestedX >= gifFile->Image.Left + gifFile->Image.Width) + || ((GifWord)requestedY >= gifFile->Image.Top + gifFile->Image.Height)) + { + return [twoDimensionalState pixelColorAtFrame:0U X:requestedX Y:requestedY]; + } + + unsigned char colorIndex = [self colorTableIndexAtFrame:requestedFrameIndex X:requestedX Y:requestedY]; + + if (disposalMethod==1 && colorIndex==transparentColorIndex) + { + return [twoDimensionalState pixelColorAtFrame:0U X:requestedX Y:requestedY]; + } + + SAColorType result = [self pixelColorForColorTableIndex:colorIndex]; + + if (mustMaintainTwoDimensionalState) + { + [twoDimensionalState writePixelColorAtFrame:0U X:requestedX Y:requestedY Color:result]; + } + + return result; +} + +- (SAColorType) pixelColorForColorTableIndex:(unsigned char) colorIndex +{ + if (transparentColorIndex>=0 && transparentColorIndex == colorIndex) + { + switch (disposalMethod) + { + case 1: + // Really not appropriate to be calling the method, but we'll do our best to answer. + break; + default: + if (backgroundColorIndex!=-1 && backgroundColorIndex!=colorIndex) + return [self pixelColorForColorTableIndex:backgroundColorIndex]; + + // TODO else something helpful, but not sure what + + break; + } + } + + ColorMapObject* colorMap; + if (gifFile->Image.ColorMap!=NULL) + colorMap = gifFile->Image.ColorMap; + else if (gifFile->SColorMap!=NULL) + colorMap = gifFile->SColorMap; + else + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:@"No local color map defined for this image or global color map defined for this GIF file." + userInfo:nil]; + } + + // if (colorIndex>pow(2,colorMap->ColorCount)) + if (colorIndex>colorMap->ColorCount) + { + /* + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Bad color index at (%u, %u) in frame %u. Color index is %u and color count is %u.", + x, y, frameIndex, colorIndex, colorMap->ColorCount] + userInfo:nil]; + */ + + // NSLog(@">>> Nonsense colorIndex %u", colorIndex); + + SAColorType reply = { .Red = 0, .Green = 100, .Blue = 0 }; + return reply; + } + else + { + SAColorType reply = { .Red = colorMap->Colors[colorIndex].Red, + .Green = colorMap->Colors[colorIndex].Green, + .Blue = colorMap->Colors[colorIndex].Blue }; // TODO cache colors? + return reply; + } +} + +- (unsigned char) colorTableIndexAtFrame:(uint)requestedFrameIndex X:(uint)requestedX Y:(uint)requestedY +{ + // NSLog(@"REQUEST for (%u, %u) of frame %u", requestedX, requestedY, requestedFrameIndex); + + if (gifFile!=nil && requestedY>=gifFile->SHeight && requestedX>=gifFile->SWidth && frameIndex==frames) + { + // NSLog (@"Deallocating line, etc."); + [self close]; + } + + if (requestedX==0 && lineWithinFrame>0 && lineWithinFrame % 50==0) + { + NSLog(@"lineWithinFrame = %i", lineWithinFrame); + } + + if ((frameIndex > requestedFrameIndex || (frameIndex==requestedFrameIndex && lineWithinFrame > requestedY)) && gifFile!=nil) + { + // need to respool GIF + NSLog (@"respooling GIF for REQUEST of (%u, %u) of frame %u when frameIndex = %u and lineWithinFrame = %u", requestedX, requestedY, requestedFrameIndex, frameIndex, lineWithinFrame); + + DGifCloseFile(gifFile); + gifFile = nil; + // NSLog (@"respooled"); + + [self reset]; + + if (respoolHandler != nil) + { + respoolHandler(); + } + } + + [self openIfNecessary]; + + // while (frameIndex > frame || y > lineWithinFrame || !readingImageData) + while (frameIndex < requestedFrameIndex || !readingImageData || (lineWithinFrame < (requestedY-gifFile->Image.Top))) + { + // NSLog(@"Still need frame %u and y %u", requestedY, requestedFrameIndex); + + BOOL terminated = [self nextChunk: &frameIndex]; + if (terminated) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"hit end of file without hitting requested pixel (%u, %u) of frame %u", requestedX, requestedY, requestedFrameIndex] + userInfo:nil]; + } + } + + return rasterBits[requestedX-gifFile->Image.Left]; +} + +- (BOOL) nextChunk: (int*) framesEncountered +{ + // NSLog (@"Fast-forwarding. frameIndex = %i and lineWithinFrame = %i and readingImageData %d", frameIndex, lineWithinFrame, readingImageData); + + // NSLog(@"type = %i", (type)); + + /* if (gifFile->Image.ColorMap!=NULL) + NSLog(@"Hey! have local color table."); */ + + if (readingImageData) + { + // iterate thru entire fricking pixel content + // TODO is this really necessary? + + if (lineWithinFrameImage.Height-1) + { + // NSLog(@"y = %i", y); + // NSLog(@"---> Gettin' a line…"); + + if (DGifGetLine(gifFile, rasterBits, gifFile->Image.Width) == GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Could not load line of pixels at y=%i, framesEncountered=%d", lineWithinFrame, *framesEncountered] + userInfo:nil]; + } + + lineWithinFrame++; + } + else + { + NSLog(@"lineWithinFrame %u matches or exceeds gifFile->SHeight %u", lineWithinFrame, gifFile->SHeight); + lineWithinFrame = -1; + readingImageData = false; + disposalMethod = 0; + } + } + else + { + GifRecordType type; + GifByteType* extensionData; + int extensionType; + + // NSLog(@"gifFile->ImageCount = %i", gifFile->ImageCount); + + if (DGifGetRecordType(gifFile, &type)==GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"DGifGetRecordType returned a GIF_ERROR"] + userInfo:nil]; + } + + switch (type) + { + case IMAGE_DESC_RECORD_TYPE: + NSLog(@"hit IMAGE_DESC_RECORD_TYPE"); + if (DGifGetImageDesc(gifFile)==GIF_ERROR) // TODO necessary? + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:@"DGifGetImageDesc returned GIF_ERROR." userInfo:nil]; + } + + /* if (gifFile->Image.ColorMap!=NULL) + NSLog(@"*** Found local color table!"); + else + NSLog(@"*** Did NOT find local color table!"); */ + + readingImageData = true; + lineWithinFrame = -1; + + if ((*framesEncountered)==-1) + { + (*framesEncountered) = 0; + NSLog(@"Hey, there! Incremented framesEncountered from -1 to 0"); + } + + // read in first line of pixel data + BOOL result = [self nextChunk: framesEncountered]; + + /* if (framesEncountered!=NULL) + NSLog(@"Jerp! framesEncountered = %u", *framesEncountered); */ + + return result; + + case EXTENSION_RECORD_TYPE: + if (DGifGetExtension(gifFile, &extensionType, &extensionData) != GIF_ERROR) // TODO make sure this can't indicate something other than a frame (like a textual comment, etc.) + { + // unsigned char bytesCount = extensionData[0]; + // NSLog (@"extensionType = %X and bytesCount = %u", extensionType, bytesCount); + + /* for (int i=1; i<=bytesCount; i++) + { + if (extensionType == GRAPHICS_EXT_FUNC_CODE) + NSLog(@"ExtensionData = %X", extensionData[i]); + } */ + + if (extensionType == GRAPHICS_EXT_FUNC_CODE) + { + // NSLog(@"******************"); + + unsigned char packedField = extensionData[1]; + // NSLog(@"packedField = %X", packedField); + + // * * * + // 1 2 3 4 5 6 7 8 + //128 64 32 16 8 4 2 1 + + // NSLog(@"disposal method in binary = %u %u %u", ((packedField & 16) == 16)?1:0, ((packedField & 8) == 8)?1:0, ((packedField & 4) == 4)?1:0); + + disposalMethod = (((packedField & 16) == 16)?4:0) + + (((packedField & 8) == 8)?2:0) + + (((packedField & 4) == 4)?1:0); + NSLog(@"disposal method = %u", disposalMethod); + + switch (disposalMethod) + { + case 0: /* No disposal specified. The decoder is + not required to take any action. */ + break; + case 1: /* Do not dispose. The graphic is to be left + in place. */ + mustMaintainTwoDimensionalState = YES; + break; + case 2: /* Restore to background color. The area used by the + graphic must be restored to the background color. */ + break; + case 3: /* Restore to previous. The decoder is required to + restore the area overwritten by the graphic with + what was there prior to rendering the graphic. + + Rare. */ + break; + default: + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"invalid disposal method %u", disposalMethod] + userInfo:nil]; + + } + + // unsigned int userInput = packedField & 2; + // NSLog(@"userInput = %u", userInput); + + // bitN = packedField & 2^N; + + unsigned int transparency = packedField & 1; // TODO use BOOL, instead? + // NSLog(@"transparency = %u", transparency); + + if (transparency==1) + NSLog(@"transparent"); + else + NSLog(@"opaque"); + + unsigned int delayTimeInCentis = extensionData[2] + (256*extensionData[3]); + + NSLog(@"delayTimeInCentis = %u", delayTimeInCentis); + // NSLog(@"delayInCentisAfterFrames = %@", delayInCentisAfterFrames); + + if (transparency) + transparentColorIndex = extensionData[4]; + else + transparentColorIndex = -1; + + NSLog(@"transparentColorIndex = %i", transparentColorIndex); + + if (framesEncountered != NULL) + { + (*framesEncountered)++; // This is either frames or the frameIndex, depending on whether we've intialized yet + + NSLog(@"Hey, dummy! Incrementing framesEncountered! %i", *framesEncountered); + + if (frames==0U || [delayInCentisAfterFrames count] < frames) + [delayInCentisAfterFrames addObject:[NSNumber numberWithUnsignedInt: delayTimeInCentis]]; + else + { + NSLog(@"[delayInCentisAfterFrames count] = %lu and frames = %u", [delayInCentisAfterFrames count], frames); + [delayInCentisAfterFrames replaceObjectAtIndex:*framesEncountered withObject:[NSNumber numberWithUnsignedInt: delayTimeInCentis]]; + } + } + + lineWithinFrame = 0; + } + } + else + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"gifunlib reported an extension block but would not disclose it."] + userInfo:nil]; + } + + while (extensionData != NULL) + { + if (DGifGetExtensionNext(gifFile, &extensionData) == GIF_ERROR) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"gifunlib reported an extension block but would not describe it further."] + userInfo:nil]; + } + + if (extensionData!=NULL) + { + int i=0; + while (((void *)extensionData[i])!=NULL) + { + // NSLog(@"extensionData = %X", extensionData[i]); + i++; + } + + // NSLog(@"******************"); + + } + /* else + NSLog(@"*** burp ***"); */ + } // TODO necessary? + + break; + case SCREEN_DESC_RECORD_TYPE: + // No need to read; read "automatically called once a file is opened, and therefore usually need not be called explicitly." + break; + case TERMINATE_RECORD_TYPE: + // NSLog(@"*** Terminated! ***"); + return TRUE; + case UNDEFINED_RECORD_TYPE: + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"gifunlib returned an error condition"] + userInfo:nil]; + } + } + + return FALSE; +} + +- (void) openIfNecessary +{ + if (gifFile == nil) + { + // NSLog (@"opening/re-opening GIF…"); + + gifFile = DGifOpenFileName([filePath UTF8String]); + if (gifFile == (GifFileType *)NULL) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat: @"Couldn't open file %@.", filePath] + userInfo:nil]; + } + + frameIndex = -1; + lineWithinFrame = 0; // TODO or is it -1 ? + readingImageData = false; + + // NSLog (@"mallocing…"); + + rasterBits = (unsigned char *) malloc (gifFile->SWidth * sizeof(GifPixelType)); + + // NSLog (@"malloced"); + + if (rasterBits == NULL) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:@"Couldn't allocate memory to load GIF image." + userInfo:nil]; + } + + if (gifFile->SColorMap!=NULL) + { + // NSLog(@"There is a global color table."); + + } + else + { + // NSLog(@"There is NO global color table."); + } + + // NSLog (@"GIF opened/re-opened."); + } +} + +- (void) close +{ + if (gifFile != nil) // TODO handle differently if open for writing + { + NSLog (@"Closing GIF…"); + + int result = DGifCloseFile(gifFile); + if (result == D_GIF_ERR_CLOSE_FAILED) + { + @throw [NSException exceptionWithName:NSInternalInconsistencyException + reason:[NSString stringWithFormat:@"Could not close GIF file."] + userInfo:nil]; + } + + readingImageData = false; + lineWithinFrame = 0; // TODO or is it -1 ? + frameIndex = -1; + gifFile = nil; + free(rasterBits); + twoDimensionalState = nil; + } +} + +-(void) reset +{ + lineWithinFrame = 0; // TODO or is it -1 ? + frameIndex = -1; + transparentColorIndex = -1; + disposalMethod = 0; + + if (mustMaintainTwoDimensionalState) + { + twoDimensionalState = [[MemorizedSpiritedArray alloc] initWith:1U Width:width Height:height]; + } +} + +- (BOOL) streamed +{ + return YES; +} + +- (void (^)(void)) respoolHandler +{ + return respoolHandler; +} + +- (void) setRespoolHandler:(void (^)(void))designatedHandler NS_AVAILABLE_MAC(10_6) +{ + respoolHandler = designatedHandler; +} + +-(BOOL) interlaced +{ + return interlaced; +} + +- (MemorizedSpiritedArray*) unInterlace +{ + MemorizedSpiritedArray* result = [[MemorizedSpiritedArray alloc] initWith:frames Width:width Height:height]; + + for (uint f=0U; f y1=%u", pass, y0, y1] + userInfo:nil]; + + return result; + } + + for (uint x=0U; xthis sampler. + */ + SamplingType samplingType; + uint targetWidth; + uint targetHeight; +} + +- (id) initWith: (SpiritedArray*) spiritedArray TargetWidth:(uint)designatedTargetWidth TargetHeight:(uint)designatedTargetHeight TileWidth:(uint)requestedTileWidth TileHeight:(uint)requestedTileHeight; + +- (SpiritedArray*) content; + +- (SamplingType) samplingType; + +@end diff --git a/foundationkit/UnUpSampler.m b/foundationkit/UnUpSampler.m new file mode 100755 index 0000000..c71bef3 --- /dev/null +++ b/foundationkit/UnUpSampler.m @@ -0,0 +1,353 @@ +// +// UnUpSampler.m +// spiritedarray +// +// Created by Dave Horlick on 10/27/12. +// Copyleft 2012 River Porpoise Software +// + +#import "UnUpSampler.h" +#import "SpiritedArray.h" + +@implementation UnUpSampler + +- (id) initWith: (SpiritedArray*) spiritedArray TargetWidth:(uint)designatedTargetWidth TargetHeight:(uint)designatedTargetHeight TileWidth:(uint)requestedTileWidth TileHeight:(uint)requestedTileHeight +{ + self = [super init]; + if (self) + { + NSLog(@"input [spiritedArray frames] = %u", [spiritedArray frames]); + + samplingType = UNDETERMINED; + + bool definitelyNotUnuped = NO; + + double spirtedArrayAspectRatio = (double)[spiritedArray height] / (double)[spiritedArray width]; + double targetAspectRatio = (double)designatedTargetHeight / (double)designatedTargetWidth; + + if (spirtedArrayAspectRatio>targetAspectRatio) + { + targetWidth = designatedTargetHeight / spirtedArrayAspectRatio; + targetHeight = designatedTargetHeight; + } + else + { + targetWidth = designatedTargetWidth; + targetHeight = spirtedArrayAspectRatio * designatedTargetWidth; + } + + /* dumbedDownMemorizedSpiritedArray = [[MemorizedSpiritedArray alloc] initWith:[spiritedArrayIterator frames] Width: targetWidth/requestedTileWidth Height: targetHeight/requestedTileHeight]; */ + // we'll try to avoid doing any new anti-aliasing + + SAColorType previousPixel; + uint candidateHorizontalRunLength = 0; + uint currentHorizontalRunLength = 0; + + // TODO consider frames? + + for (uint y=0; y<[spiritedArray height] && samplingType==UNDETERMINED && !definitelyNotUnuped; y++) + { + currentHorizontalRunLength = 0; + + for (uint x=0; x<[spiritedArray width] && samplingType==UNDETERMINED && !definitelyNotUnuped; x++) + { + SAColorType pixel = [spiritedArray pixelColorAtFrame:0 X:x Y:y]; + + if (x>0) + { + if (SAEqualColorTypes(pixel, previousPixel)) + { + if (currentHorizontalRunLength==0) + currentHorizontalRunLength = 2; + else + currentHorizontalRunLength++; + } + else + { + if (currentHorizontalRunLength > 1) + { + // if (candidateHorizontalRunLength%currentHorizontalRunLength==0) + if (candidateHorizontalRunLength==0 || currentHorizontalRunLength < candidateHorizontalRunLength) // TODO adjust this metric + { + // No reason as yet to suppose source image was not up-sampled + + if (candidateHorizontalRunLength==0 || currentHorizontalRunLength0) + { + if (SAEqualColorTypes(pixel, previousPixel)) + { + if (currentVerticalRunLength==0) + currentVerticalRunLength = 2; + else + currentVerticalRunLength++; + } + else + { + if (currentVerticalRunLength > 1) + { + if (candidateVerticalRunLength==0 || + currentVerticalRunLength < candidateVerticalRunLength) + { + // No reason as yet to suppose source image was not up-sampled + + if (candidateVerticalRunLength==0 || currentVerticalRunLength 2 && candidateHorizontalRunLength > 2) + { + CGFloat pixelAspectRatio = (CGFloat)candidateVerticalRunLength / (CGFloat)candidateHorizontalRunLength; + if (pixelAspectRatio > 0.8f && pixelAspectRatio < 1.25f) + { + // make sure scaled-up candidate width & height would accomodate tile footprint + + if (candidateWidth*requestedTileWidth <= designatedTargetWidth && candidateHeight*requestedTileHeight <= designatedTargetHeight) + { + samplingType = UN_UP; + } + } + else + { + NSLog(@"pixel aspect ratio outside parameter for un-up sampling, %f", pixelAspectRatio); + } + } + else + { + NSLog(@"candidate run lengths incompatible with un-up sampling: %u/%u", candidateVerticalRunLength, candidateHorizontalRunLength); + } + } + + if (samplingType==UNDETERMINED) + { + if ([spiritedArray width]*requestedTileWidth <= targetWidth + && [spiritedArray height]*requestedTileHeight <= targetHeight) + { + NSLog(@"No up-sampling detected, and no down-sampling is necessary."); + samplingType = NONE; + } + else + { + NSLog(@"Dumbed-down"); + samplingType = DUMBED_DOWN; + } + } + + uint y2 = 0; + uint x2 = 0; + CGFloat scaleX, scaleY; + + switch (samplingType) + { + case UN_UP: + NSLog(@"It's Un-up"); + content = [[MemorizedSpiritedArray alloc] initWith:[spiritedArray frames] Width:candidateWidth Height:candidateHeight]; + + for (uint frame=0U; frame <[spiritedArray frames]; frame++) + { + y2 = 0U; + + for (uint y=0U; y<[spiritedArray height] && y2 %i]", previousY2, y2); + // NSLog(@"h = [%u+1 -> %i]", previousX2, x2); + + for (uint v=(CGFloat)(y)/scaleY; v<(CGFloat)(y+1)/scaleY && v<[spiritedArray height]; v++) + { + for (uint h=(CGFloat)(x)/scaleX; h<(CGFloat)(x+1)/scaleX && h<[spiritedArray width]; h++) + { + SAColorType pixel = [spiritedArray pixelColorAtFrame:frame X:h Y:v]; + cumulativeRed += pixel.Red; + cumulativeGreen += pixel.Green; + cumulativeBlue += pixel.Blue; + pixels++; } + } + + switch (pixels) + { + case 0: + // TODO should this really happen? + [content writePixelColorAtFrame:frame X:x Y:y Color:unavailable]; + break; + case 1: + pixel.Red = (CGFloat)cumulativeRed; + pixel.Green = (CGFloat)cumulativeGreen; + pixel.Blue = (CGFloat)cumulativeBlue; + [content writePixelColorAtFrame:frame X:x Y:y Color:pixel]; + break; + default: + pixel.Red = (CGFloat)cumulativeRed/(CGFloat)pixels; + pixel.Green = (CGFloat)cumulativeGreen/(CGFloat)pixels; + pixel.Blue = (CGFloat)cumulativeBlue/(CGFloat)pixels; + [content writePixelColorAtFrame:frame X:x Y:y Color:pixel]; + + break; + } + } + } + + [((MemorizedSpiritedArray*)content) setDelayInCentisTo:[spiritedArray delayInCentisAfterFrame:frame] AfterFrame:frame]; + } + + break; + + case NONE: + content = spiritedArray; // TODO copy? + break; + + case UNDETERMINED: + default: + [NSException exceptionWithName:@"IllegalState" reason:@"bug" userInfo:nil]; + + } + } + + frames = [content frames]; + width = [content width]; + height = [content height]; + + NSLog(@"UUS initialization complete. Frames = %u", frames); + + return self; +} + +- (SAColorType) pixelColorAtFrame:(uint)frame X:(uint)x Y:(uint)y +{ + return [content pixelColorAtFrame:frame X:x Y:y]; +} + +- (SpiritedArray*) content +{ + return content; +} + +- (SamplingType) samplingType +{ + return samplingType; +} + +-(uint) delayInCentisAfterFrame:(uint)frame +{ + return [content delayInCentisAfterFrame:frame]; +} + +@end diff --git a/lib/gif_lib.h b/lib/gif_lib.h new file mode 100755 index 0000000..54acd91 --- /dev/null +++ b/lib/gif_lib.h @@ -0,0 +1,336 @@ +/****************************************************************************** + * In order to make life a little bit easier when using the GIF file format, + * this library was written, and which does all the dirty work... + * + * Written by Gershon Elber, Jun. 1989 + * Hacks by Eric S. Raymond, Sep. 1992 + ****************************************************************************** + * History: + * 14 Jun 89 - Version 1.0 by Gershon Elber. + * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names) + * 15 Sep 90 - Version 2.0 by Eric S. Raymond (Changes to suoport GIF slurp) + * 26 Jun 96 - Version 3.0 by Eric S. Raymond (Full GIF89 support) + * 17 Dec 98 - Version 4.0 by Toshio Kuratomi (Fix extension writing code) + *****************************************************************************/ + +#ifndef _GIF_LIB_H_ +#define _GIF_LIB_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define GIF_LIB_VERSION " Version 4.1, " + +#define GIF_ERROR 0 +#define GIF_OK 1 + +#ifndef TRUE +#define TRUE 1 +#endif /* TRUE */ +#ifndef FALSE +#define FALSE 0 +#endif /* FALSE */ + +#ifndef NULL +#define NULL 0 +#endif /* NULL */ + +#define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */ +#define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1 +#define GIF_VERSION_POS 3 /* Version first character in stamp. */ +#define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */ +#define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */ + +#define GIF_FILE_BUFFER_SIZE 16384 /* Files uses bigger buffers than usual. */ + +typedef int GifBooleanType; +typedef unsigned char GifPixelType; +typedef unsigned char *GifRowType; +typedef unsigned char GifByteType; +#ifdef _GBA_OPTMEM + typedef unsigned short GifPrefixType; + typedef short GifWord; +#else + typedef unsigned int GifPrefixType; + typedef int GifWord; +#endif + +#define GIF_MESSAGE(Msg) fprintf(stderr, "\n%s: %s\n", PROGRAM_NAME, Msg) +#define GIF_EXIT(Msg) { GIF_MESSAGE(Msg); exit(-3); } + +#ifdef SYSV +#define VoidPtr char * +#else +#define VoidPtr void * +#endif /* SYSV */ + +typedef struct GifColorType { + GifByteType Red, Green, Blue; +} GifColorType; + +typedef struct ColorMapObject { + int ColorCount; + int BitsPerPixel; + GifColorType *Colors; /* on malloc(3) heap */ +} ColorMapObject; + +typedef struct GifImageDesc { + GifWord Left, Top, Width, Height, /* Current image dimensions. */ + Interlace; /* Sequential/Interlaced lines. */ + ColorMapObject *ColorMap; /* The local color map */ +} GifImageDesc; + +typedef struct GifFileType { + GifWord SWidth, SHeight, /* Screen dimensions. */ + SColorResolution, /* How many colors can we generate? */ + SBackGroundColor; /* I hope you understand this one... */ + ColorMapObject *SColorMap; /* NULL if not exists. */ + int ImageCount; /* Number of current image */ + GifImageDesc Image; /* Block describing current image */ + struct SavedImage *SavedImages; /* Use this to accumulate file state */ + VoidPtr UserData; /* hook to attach user data (TVT) */ + VoidPtr Private; /* Don't mess with this! */ +} GifFileType; + +typedef enum { + UNDEFINED_RECORD_TYPE, + SCREEN_DESC_RECORD_TYPE, + IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */ + EXTENSION_RECORD_TYPE, /* Begin with '!' */ + TERMINATE_RECORD_TYPE /* Begin with ';' */ +} GifRecordType; + +/* DumpScreen2Gif routine constants identify type of window/screen to dump. + * Note all values below 1000 are reserved for the IBMPC different display + * devices (it has many!) and are compatible with the numbering TC2.0 + * (Turbo C 2.0 compiler for IBM PC) gives to these devices. + */ +typedef enum { + GIF_DUMP_SGI_WINDOW = 1000, + GIF_DUMP_X_WINDOW = 1001 +} GifScreenDumpType; + +/* func type to read gif data from arbitrary sources (TVT) */ +typedef int (*InputFunc) (GifFileType *, GifByteType *, int); + +/* func type to write gif data ro arbitrary targets. + * Returns count of bytes written. (MRB) + */ +typedef int (*OutputFunc) (GifFileType *, const GifByteType *, int); + +/****************************************************************************** + * GIF89 extension function codes +******************************************************************************/ + +#define COMMENT_EXT_FUNC_CODE 0xfe /* comment */ +#define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control */ +#define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */ +#define APPLICATION_EXT_FUNC_CODE 0xff /* application block */ + +/****************************************************************************** + * O.K., here are the routines one can access in order to encode GIF file: + * (GIF_LIB file EGIF_LIB.C). +******************************************************************************/ + +GifFileType *EGifOpenFileName(const char *GifFileName, + int GifTestExistance); +GifFileType *EGifOpenFileHandle(int GifFileHandle); +GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc); + +int EGifSpew(GifFileType * GifFile); +void EGifSetGifVersion(const char *Version); +int EGifPutScreenDesc(GifFileType * GifFile, + int GifWidth, int GifHeight, int GifColorRes, + int GifBackGround, + const ColorMapObject * GifColorMap); +int EGifPutImageDesc(GifFileType * GifFile, int GifLeft, int GifTop, + int Width, int GifHeight, int GifInterlace, + const ColorMapObject * GifColorMap); +int EGifPutLine(GifFileType * GifFile, GifPixelType * GifLine, + int GifLineLen); +int EGifPutPixel(GifFileType * GifFile, GifPixelType GifPixel); +int EGifPutComment(GifFileType * GifFile, const char *GifComment); +int EGifPutExtensionFirst(GifFileType * GifFile, int GifExtCode, + int GifExtLen, const VoidPtr GifExtension); +int EGifPutExtensionNext(GifFileType * GifFile, int GifExtCode, + int GifExtLen, const VoidPtr GifExtension); +int EGifPutExtensionLast(GifFileType * GifFile, int GifExtCode, + int GifExtLen, const VoidPtr GifExtension); +int EGifPutExtension(GifFileType * GifFile, int GifExtCode, int GifExtLen, + const VoidPtr GifExtension); +int EGifPutCode(GifFileType * GifFile, int GifCodeSize, + const GifByteType * GifCodeBlock); +int EGifPutCodeNext(GifFileType * GifFile, + const GifByteType * GifCodeBlock); +int EGifCloseFile(GifFileType * GifFile); + +#define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */ +#define E_GIF_ERR_WRITE_FAILED 2 +#define E_GIF_ERR_HAS_SCRN_DSCR 3 +#define E_GIF_ERR_HAS_IMAG_DSCR 4 +#define E_GIF_ERR_NO_COLOR_MAP 5 +#define E_GIF_ERR_DATA_TOO_BIG 6 +#define E_GIF_ERR_NOT_ENOUGH_MEM 7 +#define E_GIF_ERR_DISK_IS_FULL 8 +#define E_GIF_ERR_CLOSE_FAILED 9 +#define E_GIF_ERR_NOT_WRITEABLE 10 + +/****************************************************************************** + * O.K., here are the routines one can access in order to decode GIF file: + * (GIF_LIB file DGIF_LIB.C). + *****************************************************************************/ +#ifndef _GBA_NO_FILEIO +GifFileType *DGifOpenFileName(const char *GifFileName); +GifFileType *DGifOpenFileHandle(int GifFileHandle); +int DGifSlurp(GifFileType * GifFile); +#endif /* _GBA_NO_FILEIO */ +GifFileType *DGifOpen(void *userPtr, InputFunc readFunc); /* new one + * (TVT) */ +int DGifGetScreenDesc(GifFileType * GifFile); +int DGifGetRecordType(GifFileType * GifFile, GifRecordType * GifType); +int DGifGetImageDesc(GifFileType * GifFile); +int DGifGetLine(GifFileType * GifFile, GifPixelType * GifLine, int GifLineLen); +int DGifGetPixel(GifFileType * GifFile, GifPixelType GifPixel); +int DGifGetComment(GifFileType * GifFile, char *GifComment); +int DGifGetExtension(GifFileType * GifFile, int *GifExtCode, + GifByteType ** GifExtension); +int DGifGetExtensionNext(GifFileType * GifFile, GifByteType ** GifExtension); +int DGifGetCode(GifFileType * GifFile, int *GifCodeSize, + GifByteType ** GifCodeBlock); +int DGifGetCodeNext(GifFileType * GifFile, GifByteType ** GifCodeBlock); +int DGifGetLZCodes(GifFileType * GifFile, int *GifCode); +int DGifCloseFile(GifFileType * GifFile); + +#define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */ +#define D_GIF_ERR_READ_FAILED 102 +#define D_GIF_ERR_NOT_GIF_FILE 103 +#define D_GIF_ERR_NO_SCRN_DSCR 104 +#define D_GIF_ERR_NO_IMAG_DSCR 105 +#define D_GIF_ERR_NO_COLOR_MAP 106 +#define D_GIF_ERR_WRONG_RECORD 107 +#define D_GIF_ERR_DATA_TOO_BIG 108 +#define D_GIF_ERR_NOT_ENOUGH_MEM 109 +#define D_GIF_ERR_CLOSE_FAILED 110 +#define D_GIF_ERR_NOT_READABLE 111 +#define D_GIF_ERR_IMAGE_DEFECT 112 +#define D_GIF_ERR_EOF_TOO_SOON 113 + +/****************************************************************************** + * O.K., here are the routines from GIF_LIB file QUANTIZE.C. +******************************************************************************/ +int QuantizeBuffer(unsigned int Width, unsigned int Height, + int *ColorMapSize, GifByteType * RedInput, + GifByteType * GreenInput, GifByteType * BlueInput, + GifByteType * OutputBuffer, + GifColorType * OutputColorMap); + +/****************************************************************************** + * O.K., here are the routines from GIF_LIB file QPRINTF.C. +******************************************************************************/ +extern int GifQuietPrint; + +#ifdef HAVE_STDARG_H + extern void GifQprintf(char *Format, ...); +#elif defined (HAVE_VARARGS_H) + extern void GifQprintf(); +#endif /* HAVE_STDARG_H */ + +/****************************************************************************** + * O.K., here are the routines from GIF_LIB file GIF_ERR.C. +******************************************************************************/ +#ifndef _GBA_NO_FILEIO +extern void PrintGifError(void); +#endif /* _GBA_NO_FILEIO */ +extern int GifLastError(void); + +/****************************************************************************** + * O.K., here are the routines from GIF_LIB file DEV2GIF.C. +******************************************************************************/ +extern int DumpScreen2Gif(const char *FileName, + int ReqGraphDriver, + long ReqGraphMode1, + long ReqGraphMode2, + long ReqGraphMode3); + +/***************************************************************************** + * + * Everything below this point is new after version 1.2, supporting `slurp + * mode' for doing I/O in two big belts with all the image-bashing in core. + * + *****************************************************************************/ + +/****************************************************************************** + * Color Map handling from ALLOCGIF.C + *****************************************************************************/ + +extern ColorMapObject *MakeMapObject(int ColorCount, + const GifColorType * ColorMap); +extern void FreeMapObject(ColorMapObject * Object); +extern ColorMapObject *UnionColorMap(const ColorMapObject * ColorIn1, + const ColorMapObject * ColorIn2, + GifPixelType ColorTransIn2[]); +extern int BitSize(int n); + +/****************************************************************************** + * Support for the in-core structures allocation (slurp mode). + *****************************************************************************/ + +/* This is the in-core version of an extension record */ +typedef struct { + int ByteCount; + char *Bytes; /* on malloc(3) heap */ + int Function; /* Holds the type of the Extension block. */ +} ExtensionBlock; + +/* This holds an image header, its unpacked raster bits, and extensions */ +typedef struct SavedImage { + GifImageDesc ImageDesc; + unsigned char *RasterBits; /* on malloc(3) heap */ + int Function; /* DEPRECATED: Use ExtensionBlocks[x].Function instead */ + int ExtensionBlockCount; + ExtensionBlock *ExtensionBlocks; /* on malloc(3) heap */ +} SavedImage; + +extern void ApplyTranslation(SavedImage * Image, GifPixelType Translation[]); +extern void MakeExtension(SavedImage * New, int Function); +extern int AddExtensionBlock(SavedImage * New, int Len, + unsigned char ExtData[]); +extern void FreeExtension(SavedImage * Image); +extern SavedImage *MakeSavedImage(GifFileType * GifFile, + const SavedImage * CopyFrom); +extern void FreeSavedImages(GifFileType * GifFile); + +/****************************************************************************** + * The library's internal utility font + *****************************************************************************/ + +#define GIF_FONT_WIDTH 8 +#define GIF_FONT_HEIGHT 8 +extern unsigned char AsciiTable[][GIF_FONT_WIDTH]; + +#ifdef _WIN32 + extern void DrawGifText(SavedImage * Image, +#else + extern void DrawText(SavedImage * Image, +#endif + const int x, const int y, + const char *legend, const int color); + +extern void DrawBox(SavedImage * Image, + const int x, const int y, + const int w, const int d, const int color); + +void DrawRectangle(SavedImage * Image, + const int x, const int y, + const int w, const int d, const int color); + +extern void DrawBoxedText(SavedImage * Image, + const int x, const int y, + const char *legend, + const int border, const int bg, const int fg); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* _GIF_LIB_H */ diff --git a/lib/libungif.a b/lib/libungif.a new file mode 100755 index 0000000..157341f Binary files /dev/null and b/lib/libungif.a differ diff --git a/spiritedarray.xcodeproj/project.pbxproj b/spiritedarray.xcodeproj/project.pbxproj new file mode 100755 index 0000000..7ec874c --- /dev/null +++ b/spiritedarray.xcodeproj/project.pbxproj @@ -0,0 +1,844 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 2311D9F417245C28007B61EA /* GifEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 2311D9F317245C28007B61EA /* GifEncoder.m */; }; + 231500F917E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 231500F817E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.m */; }; + 2316BA2B1647E54300C492FB /* SAHyperPlane.m in Sources */ = {isa = PBXBuildFile; fileRef = 2316BA2A1647E54300C492FB /* SAHyperPlane.m */; }; + 232992DA1717930400EFAAB9 /* ImageMetapixelPalette.m in Sources */ = {isa = PBXBuildFile; fileRef = 232992D91717930400EFAAB9 /* ImageMetapixelPalette.m */; }; + 232C77481651F94B00EFB14F /* OptimizedSpiritedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 232C77471651F94B00EFB14F /* OptimizedSpiritedArray.m */; }; + 2331AE3518A3457100C872A5 /* StreamedH264Decoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 2331AE3418A3457100C872A5 /* StreamedH264Decoder.m */; }; + 233A593117F29E510061BF21 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 233A593017F29E510061BF21 /* CoreMedia.framework */; }; + 233A593317F29E5E0061BF21 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 233A593217F29E5E0061BF21 /* AVFoundation.framework */; }; + 233A593517F29E6A0061BF21 /* AudioUnit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 233A593417F29E6A0061BF21 /* AudioUnit.framework */; }; + 233A593717F29E720061BF21 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 233A593617F29E720061BF21 /* AudioToolbox.framework */; }; + 233A593917F29E7B0061BF21 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 233A593817F29E7B0061BF21 /* CoreAudio.framework */; }; + 233A593B17F29E910061BF21 /* CoreMIDI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 233A593A17F29E910061BF21 /* CoreMIDI.framework */; }; + 2341AD461650B1440002B3C5 /* SAFreezeFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 2341AD451650B1440002B3C5 /* SAFreezeFrame.m */; }; + 234E3A7016E40B2C00AD4FC8 /* SAMetapixelPalette.m in Sources */ = {isa = PBXBuildFile; fileRef = 234E3A6F16E40B2C00AD4FC8 /* SAMetapixelPalette.m */; }; + 234E3A7316E6E9D900AD4FC8 /* SACoreGraphicsConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 234E3A7216E6E9D900AD4FC8 /* SACoreGraphicsConverter.m */; }; + 234F5AA2171BB6A200D10388 /* SAFrameWheelViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 234F5AA1171BB6A200D10388 /* SAFrameWheelViewHelper.m */; }; + 2354BC60163246A100CF11F6 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2354BC5F163246A100CF11F6 /* Cocoa.framework */; }; + 2354BC6A163246A100CF11F6 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 2354BC68163246A100CF11F6 /* InfoPlist.strings */; }; + 2354BC6C163246A100CF11F6 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2354BC6B163246A100CF11F6 /* main.m */; }; + 2354BC70163246A100CF11F6 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 2354BC6E163246A100CF11F6 /* Credits.rtf */; }; + 2354BC73163246A100CF11F6 /* SAAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 2354BC72163246A100CF11F6 /* SAAppDelegate.m */; }; + 2354BC76163246A200CF11F6 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2354BC74163246A200CF11F6 /* MainMenu.xib */; }; + 235EAC6F17EAA371007CBE12 /* SAH264AvEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 235EAC6E17EAA371007CBE12 /* SAH264AvEncoder.m */; }; + 236D322117EFDDF400FB2C5A /* SAMacroblockedBounded.m in Sources */ = {isa = PBXBuildFile; fileRef = 236D322017EFDDF400FB2C5A /* SAMacroblockedBounded.m */; }; + 236E3FCC1748F05C00A071CC /* SAReductionContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 236E3FCB1748F05C00A071CC /* SAReductionContext.m */; }; + 23809813163305FB002DAC0F /* SpiritedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 2354BC9B163246C000CF11F6 /* SpiritedArray.m */; }; + 23809814163305FB002DAC0F /* StreamedGifDecoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 2354BC9D163246C000CF11F6 /* StreamedGifDecoder.m */; }; + 2380981C163C57E4002DAC0F /* libungif.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2380981B163C57E4002DAC0F /* libungif.a */; }; + 2380981F163C5918002DAC0F /* UnUpSampler.m in Sources */ = {isa = PBXBuildFile; fileRef = 2380981E163C5917002DAC0F /* UnUpSampler.m */; }; + 23809822163E78E6002DAC0F /* SpiritedArrayIterator.m in Sources */ = {isa = PBXBuildFile; fileRef = 23809821163E78E6002DAC0F /* SpiritedArrayIterator.m */; }; + 2380982516462261002DAC0F /* MemorizedSpiritedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 2380982416462261002DAC0F /* MemorizedSpiritedArray.m */; }; + 23867DCA17CC632C00C43F8C /* SpiritedArrayFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 23867DC917CC632C00C43F8C /* SpiritedArrayFactory.m */; }; + 23867DCD17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 23867DCC17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.m */; }; + 23A879201739FC4800DF7936 /* SAColorTree.m in Sources */ = {isa = PBXBuildFile; fileRef = 23A8791F1739FC4800DF7936 /* SAColorTree.m */; }; + 23AA186D2117527000C8AD16 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 23AA186C2117527000C8AD16 /* Assets.xcassets */; }; + 23AA186F2117966D00C8AD16 /* spiritied_array_app_icon_512.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA186E2117966D00C8AD16 /* spiritied_array_app_icon_512.png */; }; + 23AA18712117B4C900C8AD16 /* spiritied_array_app_icon_256.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA18702117B4C900C8AD16 /* spiritied_array_app_icon_256.png */; }; + 23AA18732117B55400C8AD16 /* spiritied_array_app_icon_1024.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA18722117B55400C8AD16 /* spiritied_array_app_icon_1024.png */; }; + 23AA18752117B57D00C8AD16 /* spiritied_array_app_icon_128.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA18742117B57D00C8AD16 /* spiritied_array_app_icon_128.png */; }; + 23AA18772117B5BE00C8AD16 /* spiritied_array_app_icon_64.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA18762117B5BE00C8AD16 /* spiritied_array_app_icon_64.png */; }; + 23AA18792117B5E300C8AD16 /* spiritied_array_app_icon_32.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA18782117B5E300C8AD16 /* spiritied_array_app_icon_32.png */; }; + 23AA187B2117B61100C8AD16 /* spiritied_array_app_icon_16.png in Resources */ = {isa = PBXBuildFile; fileRef = 23AA187A2117B61100C8AD16 /* spiritied_array_app_icon_16.png */; }; + 23AEEA9217E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 23AEEA9117E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.m */; }; + 23C0716E16EEC37F007AAF7D /* SAViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 2339945016ED9E2800B95575 /* SAViewHelper.m */; }; + 23C0716F16EEC5AE007AAF7D /* SAMacView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2339944D16ED9E0D00B95575 /* SAMacView.m */; }; + 23C0717216F17B6E007AAF7D /* SALayer.m in Sources */ = {isa = PBXBuildFile; fileRef = 23C0717116F17B6E007AAF7D /* SALayer.m */; }; + 23C0717416F2C200007AAF7D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 23C0717316F2C200007AAF7D /* QuartzCore.framework */; }; + 23C6863417FD18DA00C5EAF8 /* SAVideoExportSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 23C6863317FD18DA00C5EAF8 /* SAVideoExportSettings.m */; }; + 23C6863A17FE6F9B00C5EAF8 /* SAVideoExportSettingsController.m in Sources */ = {isa = PBXBuildFile; fileRef = 23C6863917FE6F9B00C5EAF8 /* SAVideoExportSettingsController.m */; }; + 23C6863D17FE7CB400C5EAF8 /* SAConcreteBounded.m in Sources */ = {isa = PBXBuildFile; fileRef = 23C6863C17FE7CB400C5EAF8 /* SAConcreteBounded.m */; }; + 23CD4C1318640A6900469B0A /* SACrossStitchTileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 23CD4C1218640A6900469B0A /* SACrossStitchTileDrawingStrategy.m */; }; + 23D57CAD17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 23D57CAC17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.m */; }; + 23EC072517C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 23EC072417C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.m */; }; + 23EC072817C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.m in Sources */ = {isa = PBXBuildFile; fileRef = 23EC072717C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.m */; }; + 23F0237816F6C560007736BC /* SATileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 23F0237716F6C560007736BC /* SATileDrawingStrategy.m */; }; + 23F0237B16F7F34D007736BC /* SAFatBitsTileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 23F0237A16F7F34C007736BC /* SAFatBitsTileDrawingStrategy.m */; }; + 23F0237E16F7F6F6007736BC /* SALightEmittingDiodeTileDrawingStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 23F0237D16F7F6F5007736BC /* SALightEmittingDiodeTileDrawingStrategy.m */; }; + 23F0E9B0210EC58200DF5860 /* nyan.gif in Resources */ = {isa = PBXBuildFile; fileRef = 23DCEFD916A3B99600A7F484 /* nyan.gif */; }; + 23F0E9B2210EC73D00DF5860 /* nyan_frame_1.png in Resources */ = {isa = PBXBuildFile; fileRef = 23F0E9B1210EC73D00DF5860 /* nyan_frame_1.png */; }; + 23F6224E210EC09400551FE6 /* spiritedarrayTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2354BC89163246A200CF11F6 /* spiritedarrayTests.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 23F62249210EC03200551FE6 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2354BC52163246A100CF11F6 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2354BC5A163246A100CF11F6; + remoteInfo = spiritedarray; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 230A7A07210EBABE00C47302 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; + 2311D9F217245C28007B61EA /* GifEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = GifEncoder.h; path = foundationkit/GifEncoder.h; sourceTree = SOURCE_ROOT; }; + 2311D9F317245C28007B61EA /* GifEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = GifEncoder.m; path = foundationkit/GifEncoder.m; sourceTree = SOURCE_ROOT; }; + 231500F717E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAGraphPaperTileDrawingStrategy.h; path = coregraphics/tiling/SAGraphPaperTileDrawingStrategy.h; sourceTree = SOURCE_ROOT; }; + 231500F817E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAGraphPaperTileDrawingStrategy.m; path = coregraphics/tiling/SAGraphPaperTileDrawingStrategy.m; sourceTree = SOURCE_ROOT; }; + 2316BA291647E54300C492FB /* SAHyperPlane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAHyperPlane.h; path = ../foundationkit/SAHyperPlane.h; sourceTree = ""; }; + 2316BA2A1647E54300C492FB /* SAHyperPlane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAHyperPlane.m; path = ../foundationkit/SAHyperPlane.m; sourceTree = ""; }; + 232992D81717930400EFAAB9 /* ImageMetapixelPalette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ImageMetapixelPalette.h; path = ../coregraphics/ImageMetapixelPalette.h; sourceTree = ""; }; + 232992D91717930400EFAAB9 /* ImageMetapixelPalette.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImageMetapixelPalette.m; path = ../coregraphics/ImageMetapixelPalette.m; sourceTree = ""; }; + 232C77461651F94B00EFB14F /* OptimizedSpiritedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OptimizedSpiritedArray.h; path = foundationkit/OptimizedSpiritedArray.h; sourceTree = SOURCE_ROOT; }; + 232C77471651F94B00EFB14F /* OptimizedSpiritedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OptimizedSpiritedArray.m; path = foundationkit/OptimizedSpiritedArray.m; sourceTree = SOURCE_ROOT; }; + 2331AE3318A3457100C872A5 /* StreamedH264Decoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StreamedH264Decoder.h; path = coregraphics/StreamedH264Decoder.h; sourceTree = SOURCE_ROOT; }; + 2331AE3418A3457100C872A5 /* StreamedH264Decoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StreamedH264Decoder.m; path = coregraphics/StreamedH264Decoder.m; sourceTree = SOURCE_ROOT; }; + 2339944C16ED9E0D00B95575 /* SAMacView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAMacView.h; path = ../appkit/SAMacView.h; sourceTree = ""; }; + 2339944D16ED9E0D00B95575 /* SAMacView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAMacView.m; path = ../appkit/SAMacView.m; sourceTree = ""; }; + 2339944F16ED9E2800B95575 /* SAViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAViewHelper.h; path = coregraphics/SAViewHelper.h; sourceTree = SOURCE_ROOT; }; + 2339945016ED9E2800B95575 /* SAViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAViewHelper.m; path = coregraphics/SAViewHelper.m; sourceTree = SOURCE_ROOT; }; + 233A593017F29E510061BF21 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; + 233A593217F29E5E0061BF21 /* AVFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVFoundation.framework; path = System/Library/Frameworks/AVFoundation.framework; sourceTree = SDKROOT; }; + 233A593417F29E6A0061BF21 /* AudioUnit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioUnit.framework; path = System/Library/Frameworks/AudioUnit.framework; sourceTree = SDKROOT; }; + 233A593617F29E720061BF21 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; + 233A593817F29E7B0061BF21 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; + 233A593A17F29E910061BF21 /* CoreMIDI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMIDI.framework; path = System/Library/Frameworks/CoreMIDI.framework; sourceTree = SDKROOT; }; + 2341AD441650B1440002B3C5 /* SAFreezeFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAFreezeFrame.h; path = foundationkit/SAFreezeFrame.h; sourceTree = SOURCE_ROOT; }; + 2341AD451650B1440002B3C5 /* SAFreezeFrame.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAFreezeFrame.m; path = foundationkit/SAFreezeFrame.m; sourceTree = SOURCE_ROOT; }; + 234E3A6E16E40B2C00AD4FC8 /* SAMetapixelPalette.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAMetapixelPalette.h; path = foundationkit/SAMetapixelPalette.h; sourceTree = SOURCE_ROOT; }; + 234E3A6F16E40B2C00AD4FC8 /* SAMetapixelPalette.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAMetapixelPalette.m; path = foundationkit/SAMetapixelPalette.m; sourceTree = SOURCE_ROOT; }; + 234E3A7116E6E9D900AD4FC8 /* SACoreGraphicsConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SACoreGraphicsConverter.h; path = coregraphics/SACoreGraphicsConverter.h; sourceTree = SOURCE_ROOT; }; + 234E3A7216E6E9D900AD4FC8 /* SACoreGraphicsConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SACoreGraphicsConverter.m; path = coregraphics/SACoreGraphicsConverter.m; sourceTree = SOURCE_ROOT; }; + 234F5AA0171BB6A200D10388 /* SAFrameWheelViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAFrameWheelViewHelper.h; path = coregraphics/SAFrameWheelViewHelper.h; sourceTree = SOURCE_ROOT; }; + 234F5AA1171BB6A200D10388 /* SAFrameWheelViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAFrameWheelViewHelper.m; path = coregraphics/SAFrameWheelViewHelper.m; sourceTree = SOURCE_ROOT; }; + 2354BC5B163246A100CF11F6 /* Spirited Array.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Spirited Array.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 2354BC5F163246A100CF11F6 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; + 2354BC62163246A100CF11F6 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; + 2354BC63163246A100CF11F6 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; + 2354BC64163246A100CF11F6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 2354BC67163246A100CF11F6 /* spiritedarray-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "spiritedarray-Info.plist"; sourceTree = ""; }; + 2354BC69163246A100CF11F6 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; + 2354BC6B163246A100CF11F6 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 2354BC6D163246A100CF11F6 /* spiritedarray-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "spiritedarray-Prefix.pch"; sourceTree = ""; }; + 2354BC6F163246A100CF11F6 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = ""; }; + 2354BC71163246A100CF11F6 /* SAAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SAAppDelegate.h; path = ../appkit/SAAppDelegate.h; sourceTree = ""; }; + 2354BC72163246A100CF11F6 /* SAAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SAAppDelegate.m; path = ../appkit/SAAppDelegate.m; sourceTree = ""; }; + 2354BC75163246A200CF11F6 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = ""; }; + 2354BC88163246A200CF11F6 /* spiritedarrayTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = spiritedarrayTests.h; sourceTree = ""; }; + 2354BC89163246A200CF11F6 /* spiritedarrayTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = spiritedarrayTests.m; sourceTree = ""; }; + 2354BC95163246C000CF11F6 /* gif_lib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = gif_lib.h; path = lib/gif_lib.h; sourceTree = SOURCE_ROOT; }; + 2354BC9A163246C000CF11F6 /* SpiritedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpiritedArray.h; path = foundationkit/SpiritedArray.h; sourceTree = SOURCE_ROOT; }; + 2354BC9B163246C000CF11F6 /* SpiritedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpiritedArray.m; path = foundationkit/SpiritedArray.m; sourceTree = SOURCE_ROOT; }; + 2354BC9C163246C000CF11F6 /* StreamedGifDecoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StreamedGifDecoder.h; path = foundationkit/StreamedGifDecoder.h; sourceTree = SOURCE_ROOT; }; + 2354BC9D163246C000CF11F6 /* StreamedGifDecoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = StreamedGifDecoder.m; path = foundationkit/StreamedGifDecoder.m; sourceTree = SOURCE_ROOT; }; + 235EAC6D17EAA371007CBE12 /* SAH264AvEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAH264AvEncoder.h; path = coregraphics/SAH264AvEncoder.h; sourceTree = SOURCE_ROOT; }; + 235EAC6E17EAA371007CBE12 /* SAH264AvEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAH264AvEncoder.m; path = coregraphics/SAH264AvEncoder.m; sourceTree = SOURCE_ROOT; }; + 236D321F17EFDDF400FB2C5A /* SAMacroblockedBounded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAMacroblockedBounded.h; path = coregraphics/SAMacroblockedBounded.h; sourceTree = SOURCE_ROOT; }; + 236D322017EFDDF400FB2C5A /* SAMacroblockedBounded.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAMacroblockedBounded.m; path = coregraphics/SAMacroblockedBounded.m; sourceTree = SOURCE_ROOT; }; + 236E3FCA1748F05C00A071CC /* SAReductionContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAReductionContext.h; path = foundationkit/SAReductionContext.h; sourceTree = SOURCE_ROOT; }; + 236E3FCB1748F05C00A071CC /* SAReductionContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAReductionContext.m; path = foundationkit/SAReductionContext.m; sourceTree = SOURCE_ROOT; }; + 2380981B163C57E4002DAC0F /* libungif.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libungif.a; sourceTree = ""; }; + 2380981D163C5917002DAC0F /* UnUpSampler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = UnUpSampler.h; path = foundationkit/UnUpSampler.h; sourceTree = SOURCE_ROOT; }; + 2380981E163C5917002DAC0F /* UnUpSampler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UnUpSampler.m; path = foundationkit/UnUpSampler.m; sourceTree = SOURCE_ROOT; }; + 23809820163E78E6002DAC0F /* SpiritedArrayIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpiritedArrayIterator.h; path = ../foundationkit/SpiritedArrayIterator.h; sourceTree = ""; }; + 23809821163E78E6002DAC0F /* SpiritedArrayIterator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpiritedArrayIterator.m; path = ../foundationkit/SpiritedArrayIterator.m; sourceTree = ""; }; + 2380982316462261002DAC0F /* MemorizedSpiritedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MemorizedSpiritedArray.h; path = ../foundationkit/MemorizedSpiritedArray.h; sourceTree = ""; }; + 2380982416462261002DAC0F /* MemorizedSpiritedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MemorizedSpiritedArray.m; path = ../foundationkit/MemorizedSpiritedArray.m; sourceTree = ""; }; + 23867DC817CC632C00C43F8C /* SpiritedArrayFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SpiritedArrayFactory.h; path = foundationkit/SpiritedArrayFactory.h; sourceTree = SOURCE_ROOT; }; + 23867DC917CC632C00C43F8C /* SpiritedArrayFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SpiritedArrayFactory.m; path = foundationkit/SpiritedArrayFactory.m; sourceTree = SOURCE_ROOT; }; + 23867DCB17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppKitAwareSpiritedArrayFactory.h; path = appkit/AppKitAwareSpiritedArrayFactory.h; sourceTree = SOURCE_ROOT; }; + 23867DCC17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppKitAwareSpiritedArrayFactory.m; path = appkit/AppKitAwareSpiritedArrayFactory.m; sourceTree = SOURCE_ROOT; }; + 23A8791E1739FC4800DF7936 /* SAColorTree.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAColorTree.h; path = foundationkit/SAColorTree.h; sourceTree = SOURCE_ROOT; }; + 23A8791F1739FC4800DF7936 /* SAColorTree.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAColorTree.m; path = foundationkit/SAColorTree.m; sourceTree = SOURCE_ROOT; }; + 23AA186C2117527000C8AD16 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 23AA186E2117966D00C8AD16 /* spiritied_array_app_icon_512.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_512.png; sourceTree = ""; }; + 23AA18702117B4C900C8AD16 /* spiritied_array_app_icon_256.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_256.png; sourceTree = ""; }; + 23AA18722117B55400C8AD16 /* spiritied_array_app_icon_1024.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_1024.png; sourceTree = ""; }; + 23AA18742117B57D00C8AD16 /* spiritied_array_app_icon_128.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_128.png; sourceTree = ""; }; + 23AA18762117B5BE00C8AD16 /* spiritied_array_app_icon_64.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_64.png; sourceTree = ""; }; + 23AA18782117B5E300C8AD16 /* spiritied_array_app_icon_32.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_32.png; sourceTree = ""; }; + 23AA187A2117B61100C8AD16 /* spiritied_array_app_icon_16.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = spiritied_array_app_icon_16.png; sourceTree = ""; }; + 23AEEA9017E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreGraphicsRGBADataBackedSpiritedArray.h; path = coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.h; sourceTree = SOURCE_ROOT; }; + 23AEEA9117E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CoreGraphicsRGBADataBackedSpiritedArray.m; path = coregraphics/CoreGraphicsRGBADataBackedSpiritedArray.m; sourceTree = SOURCE_ROOT; }; + 23C0717016F17B6E007AAF7D /* SALayer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SALayer.h; path = coregraphics/SALayer.h; sourceTree = SOURCE_ROOT; }; + 23C0717116F17B6E007AAF7D /* SALayer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SALayer.m; path = coregraphics/SALayer.m; sourceTree = SOURCE_ROOT; }; + 23C0717316F2C200007AAF7D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 23C6863217FD18DA00C5EAF8 /* SAVideoExportSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAVideoExportSettings.h; path = foundationkit/SAVideoExportSettings.h; sourceTree = SOURCE_ROOT; }; + 23C6863317FD18DA00C5EAF8 /* SAVideoExportSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAVideoExportSettings.m; path = foundationkit/SAVideoExportSettings.m; sourceTree = SOURCE_ROOT; }; + 23C6863817FE6F9B00C5EAF8 /* SAVideoExportSettingsController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAVideoExportSettingsController.h; path = appkit/SAVideoExportSettingsController.h; sourceTree = SOURCE_ROOT; }; + 23C6863917FE6F9B00C5EAF8 /* SAVideoExportSettingsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAVideoExportSettingsController.m; path = appkit/SAVideoExportSettingsController.m; sourceTree = SOURCE_ROOT; }; + 23C6863B17FE7CB400C5EAF8 /* SAConcreteBounded.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAConcreteBounded.h; path = foundationkit/SAConcreteBounded.h; sourceTree = SOURCE_ROOT; }; + 23C6863C17FE7CB400C5EAF8 /* SAConcreteBounded.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAConcreteBounded.m; path = foundationkit/SAConcreteBounded.m; sourceTree = SOURCE_ROOT; }; + 23CD4C1118640A6900469B0A /* SACrossStitchTileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SACrossStitchTileDrawingStrategy.h; path = coregraphics/tiling/SACrossStitchTileDrawingStrategy.h; sourceTree = SOURCE_ROOT; }; + 23CD4C1218640A6900469B0A /* SACrossStitchTileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SACrossStitchTileDrawingStrategy.m; path = coregraphics/tiling/SACrossStitchTileDrawingStrategy.m; sourceTree = SOURCE_ROOT; }; + 23D57CAB17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAColorLinePrinterTileDrawingStrategy.h; path = coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.h; sourceTree = SOURCE_ROOT; }; + 23D57CAC17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAColorLinePrinterTileDrawingStrategy.m; path = coregraphics/tiling/SAColorLinePrinterTileDrawingStrategy.m; sourceTree = SOURCE_ROOT; }; + 23DCEFD916A3B99600A7F484 /* nyan.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = nyan.gif; sourceTree = ""; }; + 23EC072317C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SALinePrinterTileDrawingStrategy.h; path = coregraphics/tiling/SALinePrinterTileDrawingStrategy.h; sourceTree = SOURCE_ROOT; }; + 23EC072417C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SALinePrinterTileDrawingStrategy.m; path = coregraphics/tiling/SALinePrinterTileDrawingStrategy.m; sourceTree = SOURCE_ROOT; }; + 23EC072617C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreGraphicsImageDataBackedSpiritedArray.h; path = coregraphics/CoreGraphicsImageDataBackedSpiritedArray.h; sourceTree = SOURCE_ROOT; }; + 23EC072717C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CoreGraphicsImageDataBackedSpiritedArray.m; path = coregraphics/CoreGraphicsImageDataBackedSpiritedArray.m; sourceTree = SOURCE_ROOT; }; + 23F0237616F6C560007736BC /* SATileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SATileDrawingStrategy.h; path = ../coregraphics/tiling/SATileDrawingStrategy.h; sourceTree = ""; }; + 23F0237716F6C560007736BC /* SATileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SATileDrawingStrategy.m; path = ../coregraphics/tiling/SATileDrawingStrategy.m; sourceTree = ""; }; + 23F0237916F7F34C007736BC /* SAFatBitsTileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SAFatBitsTileDrawingStrategy.h; path = coregraphics/tiling/SAFatBitsTileDrawingStrategy.h; sourceTree = SOURCE_ROOT; }; + 23F0237A16F7F34C007736BC /* SAFatBitsTileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SAFatBitsTileDrawingStrategy.m; path = coregraphics/tiling/SAFatBitsTileDrawingStrategy.m; sourceTree = SOURCE_ROOT; }; + 23F0237C16F7F6F5007736BC /* SALightEmittingDiodeTileDrawingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SALightEmittingDiodeTileDrawingStrategy.h; path = coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.h; sourceTree = SOURCE_ROOT; }; + 23F0237D16F7F6F5007736BC /* SALightEmittingDiodeTileDrawingStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SALightEmittingDiodeTileDrawingStrategy.m; path = coregraphics/tiling/SALightEmittingDiodeTileDrawingStrategy.m; sourceTree = SOURCE_ROOT; }; + 23F0E9B1210EC73D00DF5860 /* nyan_frame_1.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = nyan_frame_1.png; sourceTree = ""; }; + 23F62244210EC03200551FE6 /* spiritedarrayTests2.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = spiritedarrayTests2.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 23F62248210EC03200551FE6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 2354BC58163246A100CF11F6 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 233A593B17F29E910061BF21 /* CoreMIDI.framework in Frameworks */, + 233A593917F29E7B0061BF21 /* CoreAudio.framework in Frameworks */, + 233A593717F29E720061BF21 /* AudioToolbox.framework in Frameworks */, + 233A593517F29E6A0061BF21 /* AudioUnit.framework in Frameworks */, + 233A593317F29E5E0061BF21 /* AVFoundation.framework in Frameworks */, + 233A593117F29E510061BF21 /* CoreMedia.framework in Frameworks */, + 23C0717416F2C200007AAF7D /* QuartzCore.framework in Frameworks */, + 2354BC60163246A100CF11F6 /* Cocoa.framework in Frameworks */, + 2380981C163C57E4002DAC0F /* libungif.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 23F0E9B3210EC75400DF5860 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 2354BC50163246A100CF11F6 = { + isa = PBXGroup; + children = ( + 23AA186C2117527000C8AD16 /* Assets.xcassets */, + 23C0717316F2C200007AAF7D /* QuartzCore.framework */, + 2354BC65163246A100CF11F6 /* spiritedarray */, + 23F62245210EC03200551FE6 /* spiritedarrayTests2 */, + 2354BC5E163246A100CF11F6 /* Frameworks */, + 2354BC5C163246A100CF11F6 /* Products */, + ); + sourceTree = ""; + }; + 2354BC5C163246A100CF11F6 /* Products */ = { + isa = PBXGroup; + children = ( + 2354BC5B163246A100CF11F6 /* Spirited Array.app */, + 23F62244210EC03200551FE6 /* spiritedarrayTests2.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 2354BC5E163246A100CF11F6 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 230A7A07210EBABE00C47302 /* XCTest.framework */, + 233A593A17F29E910061BF21 /* CoreMIDI.framework */, + 233A593817F29E7B0061BF21 /* CoreAudio.framework */, + 233A593617F29E720061BF21 /* AudioToolbox.framework */, + 233A593417F29E6A0061BF21 /* AudioUnit.framework */, + 233A593217F29E5E0061BF21 /* AVFoundation.framework */, + 233A593017F29E510061BF21 /* CoreMedia.framework */, + 2354BC5F163246A100CF11F6 /* Cocoa.framework */, + 2354BC61163246A100CF11F6 /* Other Frameworks */, + ); + name = Frameworks; + sourceTree = ""; + }; + 2354BC61163246A100CF11F6 /* Other Frameworks */ = { + isa = PBXGroup; + children = ( + 2354BC62163246A100CF11F6 /* AppKit.framework */, + 2354BC63163246A100CF11F6 /* CoreData.framework */, + 2354BC64163246A100CF11F6 /* Foundation.framework */, + ); + name = "Other Frameworks"; + sourceTree = ""; + }; + 2354BC65163246A100CF11F6 /* spiritedarray */ = { + isa = PBXGroup; + children = ( + 2355D51E17CEF37900F81A2F /* appkit */, + 2355D51D17CEF33F00F81A2F /* coregraphics */, + 2355D52117CEFB0C00F81A2F /* foundationkit */, + 2354BC96163246C000CF11F6 /* lib */, + 2354BC74163246A200CF11F6 /* MainMenu.xib */, + 2354BC66163246A100CF11F6 /* Supporting Files */, + ); + path = spiritedarray; + sourceTree = ""; + }; + 2354BC66163246A100CF11F6 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 23AA187A2117B61100C8AD16 /* spiritied_array_app_icon_16.png */, + 23AA18782117B5E300C8AD16 /* spiritied_array_app_icon_32.png */, + 23AA18762117B5BE00C8AD16 /* spiritied_array_app_icon_64.png */, + 23AA18742117B57D00C8AD16 /* spiritied_array_app_icon_128.png */, + 23AA186E2117966D00C8AD16 /* spiritied_array_app_icon_512.png */, + 23AA18702117B4C900C8AD16 /* spiritied_array_app_icon_256.png */, + 23AA18722117B55400C8AD16 /* spiritied_array_app_icon_1024.png */, + 2354BC67163246A100CF11F6 /* spiritedarray-Info.plist */, + 2354BC68163246A100CF11F6 /* InfoPlist.strings */, + 2354BC6B163246A100CF11F6 /* main.m */, + 2354BC6D163246A100CF11F6 /* spiritedarray-Prefix.pch */, + 2354BC6E163246A100CF11F6 /* Credits.rtf */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 2354BC96163246C000CF11F6 /* lib */ = { + isa = PBXGroup; + children = ( + 2354BC95163246C000CF11F6 /* gif_lib.h */, + 2380981B163C57E4002DAC0F /* libungif.a */, + ); + path = lib; + sourceTree = SOURCE_ROOT; + }; + 2355D51D17CEF33F00F81A2F /* coregraphics */ = { + isa = PBXGroup; + children = ( + 23C0717016F17B6E007AAF7D /* SALayer.h */, + 23C0717116F17B6E007AAF7D /* SALayer.m */, + 2339944F16ED9E2800B95575 /* SAViewHelper.h */, + 2339945016ED9E2800B95575 /* SAViewHelper.m */, + 2355D51F17CEF65600F81A2F /* tiling */, + 232992D81717930400EFAAB9 /* ImageMetapixelPalette.h */, + 232992D91717930400EFAAB9 /* ImageMetapixelPalette.m */, + 234E3A7116E6E9D900AD4FC8 /* SACoreGraphicsConverter.h */, + 234E3A7216E6E9D900AD4FC8 /* SACoreGraphicsConverter.m */, + 23EC072617C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.h */, + 23EC072717C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.m */, + 23AEEA9017E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.h */, + 23AEEA9117E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.m */, + 234F5AA0171BB6A200D10388 /* SAFrameWheelViewHelper.h */, + 234F5AA1171BB6A200D10388 /* SAFrameWheelViewHelper.m */, + 235EAC6D17EAA371007CBE12 /* SAH264AvEncoder.h */, + 235EAC6E17EAA371007CBE12 /* SAH264AvEncoder.m */, + 236D321F17EFDDF400FB2C5A /* SAMacroblockedBounded.h */, + 236D322017EFDDF400FB2C5A /* SAMacroblockedBounded.m */, + 23C6863B17FE7CB400C5EAF8 /* SAConcreteBounded.h */, + 23C6863C17FE7CB400C5EAF8 /* SAConcreteBounded.m */, + 2331AE3318A3457100C872A5 /* StreamedH264Decoder.h */, + 2331AE3418A3457100C872A5 /* StreamedH264Decoder.m */, + ); + name = coregraphics; + sourceTree = ""; + }; + 2355D51E17CEF37900F81A2F /* appkit */ = { + isa = PBXGroup; + children = ( + 23867DCB17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.h */, + 23867DCC17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.m */, + 2354BC71163246A100CF11F6 /* SAAppDelegate.h */, + 2354BC72163246A100CF11F6 /* SAAppDelegate.m */, + 2339944C16ED9E0D00B95575 /* SAMacView.h */, + 2339944D16ED9E0D00B95575 /* SAMacView.m */, + 23C6863817FE6F9B00C5EAF8 /* SAVideoExportSettingsController.h */, + 23C6863917FE6F9B00C5EAF8 /* SAVideoExportSettingsController.m */, + ); + name = appkit; + sourceTree = ""; + }; + 2355D51F17CEF65600F81A2F /* tiling */ = { + isa = PBXGroup; + children = ( + 23F0237616F6C560007736BC /* SATileDrawingStrategy.h */, + 23F0237716F6C560007736BC /* SATileDrawingStrategy.m */, + 23F0237C16F7F6F5007736BC /* SALightEmittingDiodeTileDrawingStrategy.h */, + 23F0237D16F7F6F5007736BC /* SALightEmittingDiodeTileDrawingStrategy.m */, + 23F0237916F7F34C007736BC /* SAFatBitsTileDrawingStrategy.h */, + 23F0237A16F7F34C007736BC /* SAFatBitsTileDrawingStrategy.m */, + 23EC072317C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.h */, + 23EC072417C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.m */, + 23D57CAB17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.h */, + 23D57CAC17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.m */, + 231500F717E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.h */, + 231500F817E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.m */, + 23CD4C1118640A6900469B0A /* SACrossStitchTileDrawingStrategy.h */, + 23CD4C1218640A6900469B0A /* SACrossStitchTileDrawingStrategy.m */, + ); + name = tiling; + sourceTree = ""; + }; + 2355D52117CEFB0C00F81A2F /* foundationkit */ = { + isa = PBXGroup; + children = ( + 2354BC9A163246C000CF11F6 /* SpiritedArray.h */, + 2354BC9B163246C000CF11F6 /* SpiritedArray.m */, + 2354BC9C163246C000CF11F6 /* StreamedGifDecoder.h */, + 2354BC9D163246C000CF11F6 /* StreamedGifDecoder.m */, + 2316BA291647E54300C492FB /* SAHyperPlane.h */, + 2316BA2A1647E54300C492FB /* SAHyperPlane.m */, + 2380981D163C5917002DAC0F /* UnUpSampler.h */, + 2380981E163C5917002DAC0F /* UnUpSampler.m */, + 2380982316462261002DAC0F /* MemorizedSpiritedArray.h */, + 2380982416462261002DAC0F /* MemorizedSpiritedArray.m */, + 23809820163E78E6002DAC0F /* SpiritedArrayIterator.h */, + 23809821163E78E6002DAC0F /* SpiritedArrayIterator.m */, + 2311D9F217245C28007B61EA /* GifEncoder.h */, + 2311D9F317245C28007B61EA /* GifEncoder.m */, + 23A8791E1739FC4800DF7936 /* SAColorTree.h */, + 23A8791F1739FC4800DF7936 /* SAColorTree.m */, + 232C77461651F94B00EFB14F /* OptimizedSpiritedArray.h */, + 232C77471651F94B00EFB14F /* OptimizedSpiritedArray.m */, + 234E3A6E16E40B2C00AD4FC8 /* SAMetapixelPalette.h */, + 234E3A6F16E40B2C00AD4FC8 /* SAMetapixelPalette.m */, + 23867DC817CC632C00C43F8C /* SpiritedArrayFactory.h */, + 23867DC917CC632C00C43F8C /* SpiritedArrayFactory.m */, + 2341AD441650B1440002B3C5 /* SAFreezeFrame.h */, + 2341AD451650B1440002B3C5 /* SAFreezeFrame.m */, + 236E3FCA1748F05C00A071CC /* SAReductionContext.h */, + 236E3FCB1748F05C00A071CC /* SAReductionContext.m */, + 23C6863217FD18DA00C5EAF8 /* SAVideoExportSettings.h */, + 23C6863317FD18DA00C5EAF8 /* SAVideoExportSettings.m */, + ); + name = foundationkit; + sourceTree = ""; + }; + 23F62245210EC03200551FE6 /* spiritedarrayTests2 */ = { + isa = PBXGroup; + children = ( + 23DCEFD916A3B99600A7F484 /* nyan.gif */, + 23F0E9B1210EC73D00DF5860 /* nyan_frame_1.png */, + 2354BC88163246A200CF11F6 /* spiritedarrayTests.h */, + 2354BC89163246A200CF11F6 /* spiritedarrayTests.m */, + 23F62248210EC03200551FE6 /* Info.plist */, + ); + path = spiritedarrayTests2; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 2354BC5A163246A100CF11F6 /* spiritedarray */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2354BC8D163246A200CF11F6 /* Build configuration list for PBXNativeTarget "spiritedarray" */; + buildPhases = ( + 2354BC57163246A100CF11F6 /* Sources */, + 2354BC58163246A100CF11F6 /* Frameworks */, + 2354BC59163246A100CF11F6 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = spiritedarray; + productName = spiritedarray; + productReference = 2354BC5B163246A100CF11F6 /* Spirited Array.app */; + productType = "com.apple.product-type.application"; + }; + 23F62243210EC03200551FE6 /* spiritedarrayTests2 */ = { + isa = PBXNativeTarget; + buildConfigurationList = 23F6224D210EC03200551FE6 /* Build configuration list for PBXNativeTarget "spiritedarrayTests2" */; + buildPhases = ( + 23F62240210EC03200551FE6 /* Sources */, + 23F62242210EC03200551FE6 /* Resources */, + 23F0E9B3210EC75400DF5860 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + 23F6224A210EC03200551FE6 /* PBXTargetDependency */, + ); + name = spiritedarrayTests2; + productName = spiritedarrayTests2; + productReference = 23F62244210EC03200551FE6 /* spiritedarrayTests2.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 2354BC52163246A100CF11F6 /* Project object */ = { + isa = PBXProject; + attributes = { + CLASSPREFIX = SA; + LastSwiftUpdateCheck = 0940; + LastUpgradeCheck = 0940; + ORGANIZATIONNAME = "Riverporpoise Software"; + TargetAttributes = { + 23F62243210EC03200551FE6 = { + CreatedOnToolsVersion = 9.4.1; + ProvisioningStyle = Automatic; + TestTargetID = 2354BC5A163246A100CF11F6; + }; + }; + }; + buildConfigurationList = 2354BC55163246A100CF11F6 /* Build configuration list for PBXProject "spiritedarray" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 2354BC50163246A100CF11F6; + productRefGroup = 2354BC5C163246A100CF11F6 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 2354BC5A163246A100CF11F6 /* spiritedarray */, + 23F62243210EC03200551FE6 /* spiritedarrayTests2 */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 2354BC59163246A100CF11F6 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 23AA18752117B57D00C8AD16 /* spiritied_array_app_icon_128.png in Resources */, + 23AA186F2117966D00C8AD16 /* spiritied_array_app_icon_512.png in Resources */, + 2354BC6A163246A100CF11F6 /* InfoPlist.strings in Resources */, + 23AA187B2117B61100C8AD16 /* spiritied_array_app_icon_16.png in Resources */, + 23AA18792117B5E300C8AD16 /* spiritied_array_app_icon_32.png in Resources */, + 23AA18772117B5BE00C8AD16 /* spiritied_array_app_icon_64.png in Resources */, + 23AA18712117B4C900C8AD16 /* spiritied_array_app_icon_256.png in Resources */, + 2354BC70163246A100CF11F6 /* Credits.rtf in Resources */, + 23AA186D2117527000C8AD16 /* Assets.xcassets in Resources */, + 2354BC76163246A200CF11F6 /* MainMenu.xib in Resources */, + 23AA18732117B55400C8AD16 /* spiritied_array_app_icon_1024.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 23F62242210EC03200551FE6 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 23F0E9B0210EC58200DF5860 /* nyan.gif in Resources */, + 23F0E9B2210EC73D00DF5860 /* nyan_frame_1.png in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 2354BC57163246A100CF11F6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 23C0716F16EEC5AE007AAF7D /* SAMacView.m in Sources */, + 23C0716E16EEC37F007AAF7D /* SAViewHelper.m in Sources */, + 23809813163305FB002DAC0F /* SpiritedArray.m in Sources */, + 236D322117EFDDF400FB2C5A /* SAMacroblockedBounded.m in Sources */, + 23809814163305FB002DAC0F /* StreamedGifDecoder.m in Sources */, + 2354BC6C163246A100CF11F6 /* main.m in Sources */, + 2354BC73163246A100CF11F6 /* SAAppDelegate.m in Sources */, + 2380981F163C5918002DAC0F /* UnUpSampler.m in Sources */, + 23809822163E78E6002DAC0F /* SpiritedArrayIterator.m in Sources */, + 2380982516462261002DAC0F /* MemorizedSpiritedArray.m in Sources */, + 2316BA2B1647E54300C492FB /* SAHyperPlane.m in Sources */, + 2341AD461650B1440002B3C5 /* SAFreezeFrame.m in Sources */, + 23C6863D17FE7CB400C5EAF8 /* SAConcreteBounded.m in Sources */, + 232C77481651F94B00EFB14F /* OptimizedSpiritedArray.m in Sources */, + 234E3A7016E40B2C00AD4FC8 /* SAMetapixelPalette.m in Sources */, + 23C6863A17FE6F9B00C5EAF8 /* SAVideoExportSettingsController.m in Sources */, + 234E3A7316E6E9D900AD4FC8 /* SACoreGraphicsConverter.m in Sources */, + 23C0717216F17B6E007AAF7D /* SALayer.m in Sources */, + 23F0237816F6C560007736BC /* SATileDrawingStrategy.m in Sources */, + 23F0237B16F7F34D007736BC /* SAFatBitsTileDrawingStrategy.m in Sources */, + 23F0237E16F7F6F6007736BC /* SALightEmittingDiodeTileDrawingStrategy.m in Sources */, + 232992DA1717930400EFAAB9 /* ImageMetapixelPalette.m in Sources */, + 23C6863417FD18DA00C5EAF8 /* SAVideoExportSettings.m in Sources */, + 234F5AA2171BB6A200D10388 /* SAFrameWheelViewHelper.m in Sources */, + 2311D9F417245C28007B61EA /* GifEncoder.m in Sources */, + 2331AE3518A3457100C872A5 /* StreamedH264Decoder.m in Sources */, + 23A879201739FC4800DF7936 /* SAColorTree.m in Sources */, + 236E3FCC1748F05C00A071CC /* SAReductionContext.m in Sources */, + 23EC072517C0EDD500D24339 /* SALinePrinterTileDrawingStrategy.m in Sources */, + 23EC072817C1C27700D24339 /* CoreGraphicsImageDataBackedSpiritedArray.m in Sources */, + 23867DCA17CC632C00C43F8C /* SpiritedArrayFactory.m in Sources */, + 23867DCD17CC64AF00C43F8C /* AppKitAwareSpiritedArrayFactory.m in Sources */, + 23D57CAD17D8261F00D5F5A4 /* SAColorLinePrinterTileDrawingStrategy.m in Sources */, + 23AEEA9217E6294A00325068 /* CoreGraphicsRGBADataBackedSpiritedArray.m in Sources */, + 231500F917E6A83A00539CE1 /* SAGraphPaperTileDrawingStrategy.m in Sources */, + 235EAC6F17EAA371007CBE12 /* SAH264AvEncoder.m in Sources */, + 23CD4C1318640A6900469B0A /* SACrossStitchTileDrawingStrategy.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 23F62240210EC03200551FE6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 23F6224E210EC09400551FE6 /* spiritedarrayTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 23F6224A210EC03200551FE6 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2354BC5A163246A100CF11F6 /* spiritedarray */; + targetProxy = 23F62249210EC03200551FE6 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 2354BC68163246A100CF11F6 /* InfoPlist.strings */ = { + isa = PBXVariantGroup; + children = ( + 2354BC69163246A100CF11F6 /* en */, + ); + name = InfoPlist.strings; + sourceTree = ""; + }; + 2354BC6E163246A100CF11F6 /* Credits.rtf */ = { + isa = PBXVariantGroup; + children = ( + 2354BC6F163246A100CF11F6 /* en */, + ); + name = Credits.rtf; + sourceTree = ""; + }; + 2354BC74163246A200CF11F6 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 2354BC75163246A200CF11F6 /* en */, + ); + name = MainMenu.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 2354BC8B163246A200CF11F6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 2354BC8C163246A200CF11F6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.8; + SDKROOT = macosx; + }; + name = Release; + }; + 2354BC8E163246A200CF11F6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + COMBINE_HIDPI_IMAGES = YES; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "spiritedarray/spiritedarray-Prefix.pch"; + INFOPLIST_FILE = "spiritedarray/spiritedarray-Info.plist"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/lib\"", + ); + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_BUNDLE_IDENTIFIER = org.riverporpoise.spiritedarray; + PRODUCT_NAME = "Spirited Array"; + SDKROOT = macosx; + WRAPPER_EXTENSION = app; + }; + name = Debug; + }; + 2354BC8F163246A200CF11F6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + COMBINE_HIDPI_IMAGES = YES; + GCC_PRECOMPILE_PREFIX_HEADER = YES; + GCC_PREFIX_HEADER = "spiritedarray/spiritedarray-Prefix.pch"; + INFOPLIST_FILE = "spiritedarray/spiritedarray-Info.plist"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "\"$(SRCROOT)/lib\"", + ); + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_BUNDLE_IDENTIFIER = org.riverporpoise.spiritedarray; + PRODUCT_NAME = "Spirited Array"; + SDKROOT = macosx; + WRAPPER_EXTENSION = app; + }; + name = Release; + }; + 23F6224B210EC03200551FE6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = spiritedarrayTests2/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = org.riverporpoise.spiritedarrayTests2; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Spirited Array.app/Contents/MacOS/Spirited Array"; + }; + name = Debug; + }; + 23F6224C210EC03200551FE6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + ENABLE_NS_ASSERTIONS = NO; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + INFOPLIST_FILE = spiritedarrayTests2/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = org.riverporpoise.spiritedarrayTests2; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 4.0; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Spirited Array.app/Contents/MacOS/Spirited Array"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 2354BC55163246A100CF11F6 /* Build configuration list for PBXProject "spiritedarray" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2354BC8B163246A200CF11F6 /* Debug */, + 2354BC8C163246A200CF11F6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2354BC8D163246A200CF11F6 /* Build configuration list for PBXNativeTarget "spiritedarray" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2354BC8E163246A200CF11F6 /* Debug */, + 2354BC8F163246A200CF11F6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 23F6224D210EC03200551FE6 /* Build configuration list for PBXNativeTarget "spiritedarrayTests2" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 23F6224B210EC03200551FE6 /* Debug */, + 23F6224C210EC03200551FE6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 2354BC52163246A100CF11F6 /* Project object */; +} diff --git a/spiritedarray.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/spiritedarray.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100755 index 0000000..49ac8a5 --- /dev/null +++ b/spiritedarray.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/spiritedarray.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/spiritedarray.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/spiritedarray.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/UserInterfaceState.xcuserstate b/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100755 index 0000000..c2cf532 Binary files /dev/null and b/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/WorkspaceSettings.xcsettings b/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/WorkspaceSettings.xcsettings new file mode 100755 index 0000000..659c876 --- /dev/null +++ b/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/WorkspaceSettings.xcsettings @@ -0,0 +1,10 @@ + + + + + HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges + + SnapshotAutomaticallyBeforeSignificantChanges + + + diff --git a/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Expressions.xcexplist b/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Expressions.xcexplist new file mode 100755 index 0000000..16b0516 --- /dev/null +++ b/spiritedarray.xcodeproj/project.xcworkspace/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Expressions.xcexplist @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist new file mode 100755 index 0000000..8d7245f --- /dev/null +++ b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -0,0 +1,1838 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100755 index 0000000..af5c407 --- /dev/null +++ b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,2469 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcschemes/spiritedarray.xcscheme b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcschemes/spiritedarray.xcscheme new file mode 100755 index 0000000..7246f0c --- /dev/null +++ b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcschemes/spiritedarray.xcscheme @@ -0,0 +1,111 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcschemes/xcschememanagement.plist b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100755 index 0000000..5517cd5 --- /dev/null +++ b/spiritedarray.xcodeproj/xcuserdata/dhorlick.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + spiritedarray.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 2354BC5A163246A100CF11F6 + + primary + + + 2354BC7B163246A200CF11F6 + + primary + + + + + diff --git a/spiritedarray/en.lproj/Credits.rtf b/spiritedarray/en.lproj/Credits.rtf new file mode 100755 index 0000000..298fdca --- /dev/null +++ b/spiritedarray/en.lproj/Credits.rtf @@ -0,0 +1,10 @@ +{\rtf1\ansi\ansicpg1252\cocoartf1561\cocoasubrtf600 +{\fonttbl\f0\fswiss\fcharset0 Helvetica;} +{\colortbl;\red255\green255\blue255;} +{\*\expandedcolortbl;;} +\vieww9600\viewh8400\viewkind0 +\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\partightenfactor0 + +\f0\b\fs24 \cf0 Engineering: +\b0 \ + Dave Horlick} \ No newline at end of file diff --git a/spiritedarray/en.lproj/InfoPlist.strings b/spiritedarray/en.lproj/InfoPlist.strings new file mode 100755 index 0000000..477b28f --- /dev/null +++ b/spiritedarray/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + diff --git a/spiritedarray/en.lproj/MainMenu.xib b/spiritedarray/en.lproj/MainMenu.xib new file mode 100755 index 0000000..ed02ad0 --- /dev/null +++ b/spiritedarray/en.lproj/MainMenu.xib @@ -0,0 +1,385 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spiritedarray/main.m b/spiritedarray/main.m new file mode 100755 index 0000000..db77c0e --- /dev/null +++ b/spiritedarray/main.m @@ -0,0 +1,15 @@ +// +// main.m +// spiritedarray +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import + + +int main(int argc, char *argv[]) +{ + return NSApplicationMain(argc, (const char **)argv); +} diff --git a/spiritedarray/spiritedarray-Info.plist b/spiritedarray/spiritedarray-Info.plist new file mode 100755 index 0000000..157cb19 --- /dev/null +++ b/spiritedarray/spiritedarray-Info.plist @@ -0,0 +1,34 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSApplicationCategoryType + public.app-category.video + LSMinimumSystemVersion + ${MACOSX_DEPLOYMENT_TARGET} + NSHumanReadableCopyright + Copyright 2018 River Porpoise Software. Source code available under GNU GPLv3 license + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/spiritedarray/spiritedarray-Prefix.pch b/spiritedarray/spiritedarray-Prefix.pch new file mode 100755 index 0000000..0f84497 --- /dev/null +++ b/spiritedarray/spiritedarray-Prefix.pch @@ -0,0 +1,7 @@ +// +// Prefix header for all source files of the 'spiritedarray' target in the 'spiritedarray' project +// + +#ifdef __OBJC__ + #import +#endif diff --git a/spiritedarray/spiritied_array_app_icon_1024.png b/spiritedarray/spiritied_array_app_icon_1024.png new file mode 100755 index 0000000..d559a79 Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_1024.png differ diff --git a/spiritedarray/spiritied_array_app_icon_128.png b/spiritedarray/spiritied_array_app_icon_128.png new file mode 100755 index 0000000..c820279 Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_128.png differ diff --git a/spiritedarray/spiritied_array_app_icon_16.png b/spiritedarray/spiritied_array_app_icon_16.png new file mode 100755 index 0000000..cee7202 Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_16.png differ diff --git a/spiritedarray/spiritied_array_app_icon_256.png b/spiritedarray/spiritied_array_app_icon_256.png new file mode 100755 index 0000000..fd6e537 Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_256.png differ diff --git a/spiritedarray/spiritied_array_app_icon_32.png b/spiritedarray/spiritied_array_app_icon_32.png new file mode 100755 index 0000000..b684a43 Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_32.png differ diff --git a/spiritedarray/spiritied_array_app_icon_512.png b/spiritedarray/spiritied_array_app_icon_512.png new file mode 100755 index 0000000..372811a Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_512.png differ diff --git a/spiritedarray/spiritied_array_app_icon_64.png b/spiritedarray/spiritied_array_app_icon_64.png new file mode 100755 index 0000000..2822253 Binary files /dev/null and b/spiritedarray/spiritied_array_app_icon_64.png differ diff --git a/spiritedarrayTests2/Info.plist b/spiritedarrayTests2/Info.plist new file mode 100644 index 0000000..6c40a6c --- /dev/null +++ b/spiritedarrayTests2/Info.plist @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/spiritedarrayTests2/nyan.gif b/spiritedarrayTests2/nyan.gif new file mode 100755 index 0000000..0c3a45e Binary files /dev/null and b/spiritedarrayTests2/nyan.gif differ diff --git a/spiritedarrayTests2/nyan_frame_1.png b/spiritedarrayTests2/nyan_frame_1.png new file mode 100755 index 0000000..ba9a1b8 Binary files /dev/null and b/spiritedarrayTests2/nyan_frame_1.png differ diff --git a/spiritedarrayTests2/spiritedarrayTests.h b/spiritedarrayTests2/spiritedarrayTests.h new file mode 100755 index 0000000..52ee71c --- /dev/null +++ b/spiritedarrayTests2/spiritedarrayTests.h @@ -0,0 +1,22 @@ +// +// spiritedarrayTests.h +// spiritedarrayTests +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import +#import "SpiritedArray.h" +#import "SpiritedArrayIterator.h" + +@interface spiritedarrayTests : XCTestCase +{ +} + +-(void) makeSureArrayLooksRight: (SpiritedArray*)spiritedArray Red:(SAColorType)red Green:(SAColorType)green Blue:(SAColorType) blue; + +-(void) assertNextPixelColor:(NSString*)message SpiritedArrayIterator:(SpiritedArrayIterator*)sai Color:(SAColorType) color; + +@end + diff --git a/spiritedarrayTests2/spiritedarrayTests.m b/spiritedarrayTests2/spiritedarrayTests.m new file mode 100755 index 0000000..1e5de53 --- /dev/null +++ b/spiritedarrayTests2/spiritedarrayTests.m @@ -0,0 +1,291 @@ +// +// spiritedarrayTests.m +// spiritedarrayTests +// +// Created by Dave Horlick on 10/19/12. +// Copyleft 2012 River Porpoise Software +// + +#import "spiritedarrayTests.h" +#import "MemorizedSpiritedArray.h" +#import "UnUpSampler.h" +#import "SpiritedArray.h" +#import "OptimizedSpiritedArray.h" +#import "StreamedGifDecoder.h" +#import "GifEncoder.h" +#import "SpiritedArrayFactory.h" +#import "AppKitAwareSpiritedArrayFactory.h" + +@implementation spiritedarrayTests + +- (void)setUp +{ + [super setUp]; + + // Set-up code here. +} + +- (void)tearDown +{ + // Tear-down code here. + + [super tearDown]; +} + +- (void)testStuff +{ + // STFail(@"Unit tests are not implemented yet in spiritedarrayTests"); + MemorizedSpiritedArray* msa = [[MemorizedSpiritedArray alloc] initWith:1 Width:9 Height:6]; + + SAColorType red; + red.Red = 100; + red.Green = 0; + red.Blue = 0; + + SAColorType green; + green.Red = 0; + green.Green = 100; + green.Blue = 0; + + SAColorType blue; + green.Red = 0; + green.Green = 0; + green.Blue = 100; + + [msa writePixelColorAtFrame:0 X:0 Y:0 Color:red]; + [msa writePixelColorAtFrame:0 X:1 Y:0 Color:red]; + [msa writePixelColorAtFrame:0 X:2 Y:0 Color:red]; + [msa writePixelColorAtFrame:0 X:3 Y:0 Color:green]; + [msa writePixelColorAtFrame:0 X:4 Y:0 Color:green]; + [msa writePixelColorAtFrame:0 X:5 Y:0 Color:green]; + [msa writePixelColorAtFrame:0 X:6 Y:0 Color:blue]; + [msa writePixelColorAtFrame:0 X:7 Y:0 Color:blue]; + [msa writePixelColorAtFrame:0 X:8 Y:0 Color:blue]; + + [msa writePixelColorAtFrame:0 X:0 Y:1 Color:red]; + [msa writePixelColorAtFrame:0 X:1 Y:1 Color:red]; + [msa writePixelColorAtFrame:0 X:2 Y:1 Color:red]; + [msa writePixelColorAtFrame:0 X:3 Y:1 Color:green]; + [msa writePixelColorAtFrame:0 X:4 Y:1 Color:green]; + [msa writePixelColorAtFrame:0 X:5 Y:1 Color:green]; + [msa writePixelColorAtFrame:0 X:6 Y:1 Color:blue]; + [msa writePixelColorAtFrame:0 X:7 Y:1 Color:blue]; + [msa writePixelColorAtFrame:0 X:8 Y:1 Color:blue]; + + [msa writePixelColorAtFrame:0 X:0 Y:2 Color:red]; + [msa writePixelColorAtFrame:0 X:1 Y:2 Color:red]; + [msa writePixelColorAtFrame:0 X:2 Y:2 Color:red]; + [msa writePixelColorAtFrame:0 X:3 Y:2 Color:green]; + [msa writePixelColorAtFrame:0 X:4 Y:2 Color:green]; + [msa writePixelColorAtFrame:0 X:5 Y:2 Color:green]; + [msa writePixelColorAtFrame:0 X:6 Y:2 Color:blue]; + [msa writePixelColorAtFrame:0 X:7 Y:2 Color:blue]; + [msa writePixelColorAtFrame:0 X:8 Y:2 Color:blue]; + + [msa writePixelColorAtFrame:0 X:0 Y:3 Color:green]; + [msa writePixelColorAtFrame:0 X:1 Y:3 Color:green]; + [msa writePixelColorAtFrame:0 X:2 Y:3 Color:green]; + [msa writePixelColorAtFrame:0 X:3 Y:3 Color:red]; + [msa writePixelColorAtFrame:0 X:4 Y:3 Color:red]; + [msa writePixelColorAtFrame:0 X:5 Y:3 Color:red]; + [msa writePixelColorAtFrame:0 X:6 Y:3 Color:blue]; + [msa writePixelColorAtFrame:0 X:7 Y:3 Color:blue]; + [msa writePixelColorAtFrame:0 X:8 Y:3 Color:blue]; + + [msa writePixelColorAtFrame:0 X:0 Y:4 Color:green]; + [msa writePixelColorAtFrame:0 X:1 Y:4 Color:green]; + [msa writePixelColorAtFrame:0 X:2 Y:4 Color:green]; + [msa writePixelColorAtFrame:0 X:3 Y:4 Color:red]; + [msa writePixelColorAtFrame:0 X:4 Y:4 Color:red]; + [msa writePixelColorAtFrame:0 X:5 Y:4 Color:red]; + [msa writePixelColorAtFrame:0 X:6 Y:4 Color:blue]; + [msa writePixelColorAtFrame:0 X:7 Y:4 Color:blue]; + [msa writePixelColorAtFrame:0 X:8 Y:4 Color:blue]; + + [msa writePixelColorAtFrame:0 X:0 Y:5 Color:green]; + [msa writePixelColorAtFrame:0 X:1 Y:5 Color:green]; + [msa writePixelColorAtFrame:0 X:2 Y:5 Color:green]; + [msa writePixelColorAtFrame:0 X:3 Y:5 Color:red]; + [msa writePixelColorAtFrame:0 X:4 Y:5 Color:red]; + [msa writePixelColorAtFrame:0 X:5 Y:5 Color:red]; + [msa writePixelColorAtFrame:0 X:6 Y:5 Color:blue]; + [msa writePixelColorAtFrame:0 X:7 Y:5 Color:blue]; + [msa writePixelColorAtFrame:0 X:8 Y:5 Color:blue]; + XCTAssertEqual(1U, [msa frames], @"msa reports incorrect number of frames."); + [self makeSureArrayLooksRight: msa Red:red Green:green Blue:blue]; + [self makeSureArrayLooksRight: msa Red:red Green:green Blue:blue]; + + UnUpSampler* uus = [[UnUpSampler alloc] initWith:msa TargetWidth:100 TargetHeight:100 TileWidth:1 TileHeight:1]; + XCTAssertEqual(UN_UP, [uus samplingType], @"wrong sampling type"); + SpiritedArray* content = [uus content]; + XCTAssertEqual(3U, [content width]); // [NSString localizedStringWithFormat: @"wrong width %u", [content width]] + XCTAssertEqual(2U, [content height]); // [NSString localizedStringWithFormat: @"wrong height %u", [content height]] + + XCTAssertTrue(SAEqualColorTypes(red, [content pixelColorAtFrame:0 X:0 Y:0])); // @"pixel #1 isn't red" + XCTAssertTrue(SAEqualColorTypes(green, [content pixelColorAtFrame:0 X:1 Y:0])); // @"pixel #2 isn't green" + XCTAssertTrue(SAEqualColorTypes(blue, [content pixelColorAtFrame:0 X:2 Y:0])); // @"pixel #3 isn't blue" + + SAColorType pixel = [content pixelColorAtFrame:0 X:0 Y:1]; + XCTAssertTrue(SAEqualColorTypes(green, pixel)); // @"pixel #4 isn't green, it's %@", SADescribeColorType(pixel) + pixel = [content pixelColorAtFrame:0 X:1 Y:1]; + XCTAssertTrue(SAEqualColorTypes(red, pixel)); // @"pixel #5 isn't red, it's %@", SADescribeColorType(pixel) + pixel = [content pixelColorAtFrame:0 X:2 Y:1]; + XCTAssertTrue(SAEqualColorTypes(blue, pixel)); // @"pixel #6 isn't blue, it's %@" SADescribeColorType(pixel) + + SpiritedArrayIterator* sai =[[SpiritedArrayIterator alloc] initWithSpiritedArray:content]; + XCTAssertEqual(1U, [sai frames]); + XCTAssertEqual([sai width], [content width]); // @"iterator and iterator source report different widths" + XCTAssertEqual([sai height], [content height]); // @"iterator and iterator source report different heights" + XCTAssertTrue([sai arrayHasAnotherFrame]); // @"sai claims not to have any frames." + + uint x=0U,y=0U,frame=0U; + + while ([sai arrayHasAnotherFrame]) + { + x = -1; + y = -1; + [sai nextFrame]; + + while ([sai imageHasAnotherRow]) + { + x = -1; + [sai nextRow]; + + while ([sai rowHasAnotherPixel]) + { + [sai nextPixel]; + x++; + } + + y++; + } + + frame++; + } + + XCTAssertEqual(y, [content height]-1, @"iterator iterated over all rows"); + XCTAssertEqual(x, [content width]-1, @"iterator iterated over all column"); + + [sai close]; + + OptimizedSpiritedArray* osa = [[OptimizedSpiritedArray alloc] initWith:msa]; + [self makeSureArrayLooksRight:osa Red:red Green:green Blue:blue]; + + SAColorType filtered1 = filterPixel(red, red); + XCTAssertTrue(SAEqualColorTypes(filtered1, red), @"Red filtered against Red != Red; it's %@", SADescribeColorType(filtered1)); + + SAColorType white = {100, 100, 100}; + + SAColorType filtered2 = filterPixel(white, red); + XCTAssertTrue(SAEqualColorTypes(filtered2, red), @"White filtered against Red != Red; it's %@", SADescribeColorType(filtered2)); + + SAColorType black = {0, 0, 0}; + + SAColorType filtered3 = filterPixel(blue, red); + XCTAssertTrue(SAEqualColorTypes(filtered3, black), @"Blue filtered against Red != Black; it's %@", SADescribeColorType(filtered3)); + + SAColorType purple = {50, 0, 50}; + SAColorType darkRed = {50, 0, 0}; + + SAColorType filtered4 = filterPixel(purple, red); + XCTAssertTrue(SAEqualColorTypes(filtered4, darkRed), @"Purple filtered against Red != Dark Red; it's %@", SADescribeColorType(filtered4)); + + /* SAColorType filtered5 = filterPixel(red, purple); + XCTAssertTrue(SAEqualColorTypes(filtered5, purple), @"Red filtered against Purple != Purple; it's %@", SADescribeColorType(filtered5)); */ + + unsigned long anotherResult = [GifEncoder lowestPowerOfTwoThatIsNotLessThan: 61lu]; + XCTAssertEqual(64lu, anotherResult, @"%u != 64", anotherResult); + + unsigned long anotherOtherResult = [GifEncoder lowestPowerOfTwoThatIsNotLessThan:188lu]; + XCTAssertEqual(256lu, anotherOtherResult, @"%u != 256", anotherResult); +} + +-(void) dontTestGif +{ + StreamedGifDecoder *spiritedArrayFromFile = (StreamedGifDecoder*) [SpiritedArrayFactory build:@"spiritedarrayTests2/nyan.gif"]; // TODO unbreak this resource + + [spiritedArrayFromFile setRespoolHandler: ^() + { + XCTFail(@"respooled, but shouldn't have"); + }]; + + SpiritedArray* result = [[OptimizedSpiritedArray alloc] initWith:spiritedArrayFromFile]; + XCTAssertEqual([result frames], 6U, @"nyan.gif has wrong number of frames: %u", [result frames]); + XCTAssertEqual([result width], 258U, @"nyan.gif has wrong width: %u", [result width]); + XCTAssertEqual([result height], 181U, @"nyan.gif has wrong height: %u", [result height]); + + GifEncoder* encoder = [GifEncoder new]; + [encoder encode:result FilePath:[self pathForTemporaryFileWithPrefix:@"lalala"]]; +} + +-(void) dontTestPng +{ + SpiritedArray *spiritedArrayFromFile = [AppKitAwareSpiritedArrayFactory build:@"spiritedarrayTests2/nyan_frame_1.png"]; // TODO unbreak this resource + + XCTAssertEqual([spiritedArrayFromFile frames], 1U, @"nyan_frame_1 has wrong number of frames: %u", [spiritedArrayFromFile frames]); + XCTAssertEqual([spiritedArrayFromFile width], 258U, @"nyan_frame_1 has wrong width: %u", [spiritedArrayFromFile width]); + XCTAssertEqual([spiritedArrayFromFile height], 181U, @"nyan_frame_1 has wrong height: %u", [spiritedArrayFromFile height]); + + SpiritedArray* result = [[OptimizedSpiritedArray alloc] initWith:spiritedArrayFromFile]; + XCTAssertEqual([result frames], 1U, @"optimized view of nyan_frame_1 has wrong number of frames: %u", [result frames]); + XCTAssertEqual([result width], 258U, @"optimized view of nyan_frame_1 has wrong width: %u", [result width]); + XCTAssertEqual([result height], 181U, @"optimized view of nyan_frame_1 has wrong height: %u", [result height]); + + @try { + [AppKitAwareSpiritedArrayFactory build:@"spiritedarrayTests/i_dont_exist.png"]; + XCTFail(@"Attempt to open nonexistent PNG file didn't result in an exception."); + } + @catch (NSException * e) { + // good + } +} + +-(void) makeSureArrayLooksRight: (SpiritedArray*)spiritedArray Red:(SAColorType)red Green:(SAColorType)green Blue:(SAColorType) blue +{ + SpiritedArrayIterator* sai2 =[[SpiritedArrayIterator alloc] initWithSpiritedArray:spiritedArray]; + [sai2 nextFrame]; + [sai2 nextRow]; + + [self assertNextPixelColor:@"Test 1" SpiritedArrayIterator:sai2 Color:red]; + [self assertNextPixelColor:@"Test 2" SpiritedArrayIterator:sai2 Color:red]; + [self assertNextPixelColor:@"Test 3" SpiritedArrayIterator:sai2 Color:red]; + [self assertNextPixelColor:@"Test 4" SpiritedArrayIterator:sai2 Color:green]; + [self assertNextPixelColor:@"Test 5" SpiritedArrayIterator:sai2 Color:green]; + [self assertNextPixelColor:@"Test 6" SpiritedArrayIterator:sai2 Color:green]; + [self assertNextPixelColor:@"Test 7" SpiritedArrayIterator:sai2 Color:blue]; + [self assertNextPixelColor:@"Test 8" SpiritedArrayIterator:sai2 Color:blue]; + [self assertNextPixelColor:@"Test 9" SpiritedArrayIterator:sai2 Color:blue]; + [sai2 nextRow]; + [self assertNextPixelColor:@"Test 10" SpiritedArrayIterator:sai2 Color:red]; + + [sai2 close]; +} + +-(void) assertNextPixelColor:(NSString*)message SpiritedArrayIterator:(SpiritedArrayIterator*)sai Color:(SAColorType) color +{ + SAColorType result = [sai nextPixel]; + XCTAssertTrue(SAEqualColorTypes(result, color), @"%@: %@ != %@", message, SADescribeColorType(color), SADescribeColorType(result)); +} + +- (NSString *)pathForTemporaryFileWithPrefix:(NSString *)prefix +{ + NSString * result; + CFUUIDRef uuid; + CFStringRef uuidStr; + + uuid = CFUUIDCreate(NULL); + assert(uuid != NULL); + + uuidStr = CFUUIDCreateString(NULL, uuid); + assert(uuidStr != NULL); + + result = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@-%@", prefix, uuidStr]]; + assert(result != nil); + + CFRelease(uuidStr); + CFRelease(uuid); + + return result; +} + +@end