Source Code Party

Sat, 25 Aug 2007

Due to non-zero demand, I've packaged the source for the resizing application. Then I realised that it used my image library, which I haven't released yet, so I've also packaged it up. Then I thought - how is a person going to build all of this? They could use gcc -std=c99 *.c, but that won't work right because not all the c files are in the same directory. Of course, I was just being an idiot when I thought that, because I know that the easiest way to build all of my things is with amkel. But, the version of amkel which I released before is probably too buggy to use, so I thought version 2epsilon is due. Finally, I thought - since I'm putting up 3 things, why not make it 4? So I did the dithering source code too.

So, here they are: (all under GPL3)

I find the image library really useful. It isn't powerful at all, it just lets you write C code that looks like this:

Image img = loadImage("someImage.bmp");

imageSetPixel(img, 51, 12, 128, 192, 15);   
imageSetPixelRgb(img, imageGetWidth(img) - 1, 10, imageGetPixelRgb(0, 0));

saveImage(img, "newImage.bmp");
destroyImage(img);

It might have support for some other simple file types, but I might have accidentally removed it (and even then, the interface stayed the same - it decided on the file type based on a file extension, rather than doing fancy stuff). It is great if you want to quickly try out an algorithm, and while it wasn't written to be efficient, it seems to be fast enough.

For building stuff, make sure amkel works. Type:

$ cd amkel # or where-ever you put it
$ cat > test.c
#include <stdio.h>
int main(int argc, char *argv[]) {
    printf("woo\n");
    return 0;
}
<ctrl+d>
$ ./amkel.rb test.c
$ ./test

And it should print 'woo'.

If you are feeling adventurous, make sure you have rubyscript2exe and tar2rubyscript installed so that amkel can find them, and run ./amkel.rb amkel.rb - this will create a single file which you can put somewhere in your $PATH. Which will make building stuff a whole lot easier.

Then put stuff in a structure like this:

/.../blah/image
/.../blah/resize
/.../blah/dither

And then you should be able to run amkel on 'resize.c' or on 'dither.c' and it will automatically include the image library and compile everything. If you haven't made the single-file version of amkel, then be aware that you will probably have to run amkel from inside its own directory.

Enjoy the source code party.

Can you post or point to any example images that you know work with the program? I tried a few .bmp's from http://wvnvaxa.wvnet.edu/vmswww/bmp.html, but got segfaults for each one I tried.
Michael
19 hours after story
Use a full 24-bit colour bitmap and it should work. I was lazy when doing the bitmap loader sorry.

Some 'known-not-to-segfault' images (don't trust this to be there in a week)

I made them by opening a jpeg in whatever the default image program is in Ubuntu and choosing 'save as' and giving it a .bmp extension. Make sure you read at least the main function in the resize.c file to work out how to use it.
Andy
20 hours after story
(and maybe one day I'll look into making that image library a bit more robust...)
Andy
20 hours after story
Whenever I run ./amkel.rb amkel.rb I get the following error; the testfile worked.

jvdimas@jvdimas-desktop:~/Desktop/ImageResize/amkel$ ./amkel.rb amkel.rb
initialising ruby
tar: ./amkel.rb.tar: file is the archive; not dumped
mv: cannot stat `amkel.rb.tar_linux': No such file or directory
3 days after story
Is there any chance of getting a example of how to set the flags? I can't seem to work out how to get the program to run properly, just keep getting the Usage, with no explanation of the flags...
anonymous
3 days after story
Jack: I think you can fix that by installing "rubyscript2exe" and "tar2rubyscript" (and possibly putting them in your path). They are both available in rubygems if you are familiar with that. Let me know if you are still having issues.

Anonymous: There aren't any flags, just give it the name of the bitmap file you want it to resize. It always outputs to the file "resized.bmp", with a fixed amount of resizing (recompile to change it)

./resize test.bmp

I was just too lazy to make a real interface... actually, looking at the source - I didn't put in a usage message at all... hope I've answered the right question. Even if you aren't a programmer, you should be able to come reasonably close to understanding how to modify the program. argv[1] is the first argument in case you are wondering.
Andy
3 days after story
Compiled (gcc ... *.c is fine with me) and ran perfectly. Massive thank for putting this out for us to play with.

I tried a shrink, rotate, shrink, rotate cycle and my lovely daughter turned into a monster! Poor love. (I know the original authors already acknowledge that faces need special treatment/protection.)
Bob
3 days after story
Oh duh. I feel like a complete idiot now. I know what I was doing wrong... Instead of calling the compiled program "resize" I was calling the UNIX command "resize". I shall go sit in the corner and flog myself.
anonymous
3 days after story
Does anyone know why reversing the energy function with "total = 255-total;" at the relevant place causes a bus error?

Also I can't figure out why readBmp() is failing (returning at line 37) on PPC Mac but not on an Intel Mac? I'm not a C porting guru... Can anyone point me in the right direction? Thanks! (with an 's' this time)
Bob
6 days after story
I have a few overflow errors in the code (when I try to draw to an x coordinate of -1 or width+1). If you modify Image.c to display an error message when this happens, you should be able to track down these problems.

The bitmap reading code doesn't try to fix up any endian correction (which is the big difference between the two styles of mac). There should be plenty of info around on how to fix it.
Andy
7 days after story
Thanks Andy - I suspected endian problems but wasn't confident enough to dive in and try to fix it. I'll post back the solution(s) if I find them.
Bob
8 days after story
Name & email are optional. Email will not be obfuscated.
HTML tags will be removed except hyperlinks.
 

About

I'm a nerd living in Sydney. This is a place where I can write stuff about my interests and not care that no one else is reading.

I like music, maths, programming, pretty pictures, filters and other good things.

(more info)

It should be fairly obvious that this isn't connected to my employer at all.

Email me (not a catchpa)

Email policy

Subscribe

RSS Feed RSS

Get an aggregator

Liferea (Linux)

Vienna (OSX)

Feedreader (Windows)

Google Reader (Web based)

I've only used Liferea, so I can't vouch for the other ones.

About this site

This site runs a (modified) version of blosxom.

The host is GeekISP, and they seem to do an excellent job.