Lesson 04
Simple Image Processing
A crash course on adding images to your applications.
Since Lesson 03 was released, I have been bombarded with e-mails, instant messages, phone calls, and even the
occasional reader banging on my front door pleading with me to release another tutorial. Overwhelmingly they have requested a lesson
on adding images to their programs. Well, you guys can finally stop all of that, because this long overdue article is finally here.
At this point, I'll assume that you already have CYGWIN and the PSP toolchain installed, understand how to compile source code into an EBOOT suitable for execution on the PSP, and have at least a basic understanding of the C programming language. If you don't meet these prerequisites, have no fear, read Lesson 01, Lesson 02, and Lesson 03, and then come back.
If it has been a while since you have updated your toolchain, you will need to do that since png.h is necessary for this tutorial and was
not originally included in the PSP toolchain. Revisit Lesson 01 if you need a refresher on how to do that. I had to update
before I was able to compile this program (if you already have CYGWIN installed, you can skip right to the step where you download the toolchain).
I would like to thank Psilocybeing for allowing me to use his example source code as a base for this tutorial.
I had originally planned on using my own example code (adapted from Shine's original Snake game in C) to demonstrate, but that code is
antiquated and unnecessarily complex. One major benefit of Psilocybeing's code is that all of the functions and
datatypes are defined in external files, allowing you to more easily integrate the code into your own projects.
Before we do anything, we will need to install some new libraries from SVN. What's SVN you ask? Well, SVN is a version management system (it is shorthand for "subversion"). What we will be doing is grabbing some code from online to add more functionality to our compiler. The packages that we will need are zlib and libpng. zlib is a compression library and libpng allows us to work with PNG files (a type of image). To install these libraries, we will need to type the following things into a CYGWIN Bash Shell.
So now we need to compile this new library, so we'll "cd" into the new folder.
Now we need to put the resulting files into a place where the compiler can access them. So, we'll install them:
Now for libpng. We just need to do the same thing, except we'll substitute "libpng" for "zlib."
Now we'll just clean up those install files by deleting them. To delete things via a Linux shell (which is what CYGWIN emulates), you use the "rm" command. We don't only want to delete one file, though, we want to delete a whole folder and all of its contents, so we'll add the "-R" modifier to it to signify a recursive removal. Basically this just means we want to delete a folder and everything inside of that folder. We'll also use the "-f" modifier to force the deletion of write-protected files so that we don't have to hit "y" for each file we want to delete. So we'll "cd" back to the parent directory and remove both the "zlib" and "libpng" temporary folders that we just created.
We'll move on to the second section of this tutorial to continue our program.
At this point, I'll assume that you already have CYGWIN and the PSP toolchain installed, understand how to compile source code into an EBOOT suitable for execution on the PSP, and have at least a basic understanding of the C programming language. If you don't meet these prerequisites, have no fear, read Lesson 01, Lesson 02, and Lesson 03, and then come back.
Before we do anything, we will need to install some new libraries from SVN. What's SVN you ask? Well, SVN is a version management system (it is shorthand for "subversion"). What we will be doing is grabbing some code from online to add more functionality to our compiler. The packages that we will need are zlib and libpng. zlib is a compression library and libpng allows us to work with PNG files (a type of image). To install these libraries, we will need to type the following things into a CYGWIN Bash Shell.
svn checkout svn://svn.pspdev.org/psp/trunk/zlib
"Checkout" is basically SVN's way of saying "download." This will download the zlib source into a folder called "zlib." It will take a minute, a bunch of
stuff should scroll down the screen and you should be left back at the "$" for input.So now we need to compile this new library, so we'll "cd" into the new folder.
cd zlib
We are now in the zlib folder, and are ready to compile. So, like any other thing that we want to compile, we just need to type
make
And voila, it compiles the library for us.Now we need to put the resulting files into a place where the compiler can access them. So, we'll install them:
make install
And BAM! We've installed zlib. Now wasn't that simple?Now for libpng. We just need to do the same thing, except we'll substitute "libpng" for "zlib."
cd ..
svn checkout svn://svn.pspdev.org/psp/trunk/libpng
cd libpng
make
make install
And there we are, ready to use PNG's in our program.svn checkout svn://svn.pspdev.org/psp/trunk/libpng
cd libpng
make
make install
Now we'll just clean up those install files by deleting them. To delete things via a Linux shell (which is what CYGWIN emulates), you use the "rm" command. We don't only want to delete one file, though, we want to delete a whole folder and all of its contents, so we'll add the "-R" modifier to it to signify a recursive removal. Basically this just means we want to delete a folder and everything inside of that folder. We'll also use the "-f" modifier to force the deletion of write-protected files so that we don't have to hit "y" for each file we want to delete. So we'll "cd" back to the parent directory and remove both the "zlib" and "libpng" temporary folders that we just created.
rm -Rf zlib
rm -Rf libpng
Now that we have that out of the way, we are ready to start programming.rm -Rf libpng
We'll move on to the second section of this tutorial to continue our program.
