----------------------------------- Insectoid Tue Apr 19, 2011 5:28 pm Insectoid's Summer Programming Challenge ----------------------------------- So, I was watching a first-year Harvard lecture on C programming the other day. One of the assignments given to the students involved writing a program that takes a bmp file and a number n as input, and outputs the image multiplied in area by n to a bmp file. It was then that I realized that I had never done I/O on anything but text files. I didn't have a clue how other file types worked. My challenge for compsci.ca users (primarily students, but other people to, if you want) this summer is to write a program that does something with a common file format. A bitmap is a good place to start, as it's a fairly basic format. Add a watermark, change the colors, be creative! After that, move into more involved formats such as ZIP files or other compression formats, MS Word documents, etc. Maybe even design your own format for something. This isn't a contest. It's a challenge. Everybody wins, unless you don't learn anything. Then only everyone who learned something wins. ~Insectoid ----------------------------------- Raknarg Tue Apr 19, 2011 5:59 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- Is turing legal? :P ----------------------------------- Tony Tue Apr 19, 2011 6:05 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- As a file format? ----------------------------------- Insectoid Tue Apr 19, 2011 6:19 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- Use whatever language you want. The objective is that it isn't a text format- this includes .txt, .t, .cpp, .rb, etc. ----------------------------------- Dratino Wed Apr 20, 2011 8:55 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- I've worked with Microsoft BMP files before, but only to generate visual versions of certain types of output. ----------------------------------- SNIPERDUDE Thu Apr 21, 2011 12:09 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- Sounds fun, I might take a stab at it. I haven't worked with anything other than text files as well (besides my own encrypted "text" files for program saves). ----------------------------------- RandomLetters Thu Apr 21, 2011 9:50 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- I'm trying to write the header input for a bmp file editor right now in java. How can one convert a byte array into an integer? (stupid, stupid signed integers >>) ----------------------------------- DemonWasp Thu Apr 21, 2011 10:28 pm RE:Insectoid\'s Summer Programming Challenge ----------------------------------- Err... long i = b[3] = 0) { //check sign of "height" info, if it's positive, the image is "upside down" for(int r = bmpPixelArray.length - 1; r >= 0; r--) { for(byte[] bmpPixel : bmpPixelArray[r]) { in.read(bmpPixel); //reads 3 bytes into the pixel array } in.read(buffer); } } else { for(int r = 0; r < bmpPixelArray.length; r++) { //not upside down for(byte[] bmpPixel : bmpPixelArray[r]) { in.read(bmpPixel); } in.read(buffer); } } bmpOriginal = bmpPixelArray.clone(); } [/code] Is there any way to optimize this? Currently, I have a 2D array of pixels, which are themselves an array of 3 bytes. ----------------------------------- DemonWasp Sun Apr 24, 2011 10:28 am RE:Insectoid\'s Summer Programming Challenge ----------------------------------- BufferedInputStream: [code] InputStream in = new BufferedInputStream ( new FileInputStream ( file ) ); // Or, for extra fun: DataInputStream in = new DataInputStream ( new BufferedInputStream ( new FileInputStream ( file ) ) ); // that last one allows you to read whole integers and so on easily [/code] Also, don't forget to close your input streams when you're done with them. ----------------------------------- DtY Sun Apr 24, 2011 12:07 pm Re: Insectoid's Summer Programming Challenge ----------------------------------- Well, finished the program to load a 24 bit bitmap, and apply a tunnel effect, like that terrible, terrible feature in ipad photobooth :P It's still extremely slow to something like MS paint however, which most of the time is taken because of loading the bitmap into an array. There's a lot of overhead in using an array for each pixel. Instead, make each pixel a single integer, made up of red