The image tile servlet is more or less complete, and I can now create tiles from images of any size (or so I believe) without using lots of memory. As I mentioned in my previous post, the largest image I'm currently testing with is 8192*9976*8 bits. I'll dig up some even larger ones soon and do some further testing.
The servlet now works as follows: The Google Maps image viewer figures out which tiles it needs based on the state of the view window, and makes HTTP GET-requests, like so: imageTileServlet?obsId=6&x=0&y=2&z=5
For each request, the image tile servlet should return a 256x256 pixel JPEG image. It looks up the obs with the given id, and opens the file given by its "complex" value. The servlet then reads metadata from the file (dimensions and bit depth). Based on this and the GET parameters, the servlet can calculate the relevant part of the image and set the correct image read parameters, like so:
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceRegion(new Rectangle(xpos, ypos, tileSize, tileSize);
param.setSourceSubsampling(subsampleLevel, subsampleLevel, 0, 0);
SourceRegion is the part of the image we are interested in decoding. SourceSubsampling allows the reader to skip pixels while reading, if set to 2 the reader will read every other row and column.
The servlet will then resize the image using a Graphics2D object, encode to JPEG and write the resulting stream to the HttpServletResponse object. The user's web browser will in most cases cache the images, so each tile shouldn't need to be requested more than once.
So far the source image must be a JPEG file, but adding PNG, GIF and BMP is a simple matter, as Java's Image I/O API has built-in support for these formats. I also plan to add DICOM image decoding at a later time.
Right now the tile servlet is a little sluggish. I have my test deployment of OpenMRS running on a Pentium III laptop with Ubuntu server. Loading an image tile from my largest JPEG takes several hundred milliseconds. Smaller images are read significantly faster.
I have created a portlet that contains the Google Maps-based image viewer. I'm currently ironing out a couple of JavaScript and CSS issues, which I expect to resolve soon. As the svn server is supposedly up and running, I'll probably make my first svn commit when this is completed, though I may do a little cleaning up and refactoring first.
I also believe it is time to update the wiki page for my project, I'll probably get that done within a couple of days. Next up is support for annotations.
Now, with all that out of the way, let's talk about something really interesting: Amusing facts from WWII.
During the war, the British developed a new class of bomb to use against bunkers and submarine pens, the so-called earthquake bomb. The design was built in two sizes: The 5400 kg 'Tallboy' and the 10000 kg 'Grand Slam'. The Grand Slam was the world's largest bomb at the time. These weapons were dropped from specially modified Lancaster bombers and reached supersonic speeds before hitting the ground. The bomb casings allowed the weapons to penetrate several meters of soil and concrete before detonating their massive load of torpex high explosive.
At RAF Scampton, a Royal Air Force base north of the English town of Lincoln, a Lancaster bomber and a Grand Slam bomb were set up as "gate guards" after the war. In 1958, the road going past was going to be extended and the gate guards had to be moved. They rolled out a crane and tried to lift the bomb, which for some reason wouldn't budge.
The RAF crew initially suspected that the bomb casing was filled with concrete, or had filled up with water over the years, but then someone got a horrible suspicion. "No... It couldn't be... could it?" This area had been open to the public, and a lot of people had climbed up on the bomb and taken pictures sitting astride.
So, they called up a technician who carefully scraped off the paint and opened a service hatch. Right enough, the Grand Slam bomb was still filled with explosives from 1944!
A bigger crane was called in and the bomb was carefully moved under police escort to the coastal experimental range at Shoeburyness. There it was rigged for demolition, and the resulting explosion proved without a doubt to anyone within a 16 km radius that the bomb was still very much alive.
The subsequent investigations failed to determine how a live earthquake bomb could have been set up as a gate guard. They crunched some numbers, and estimated the damage the bomb could have done if detonated at its location outside the RAF base. Besides taking out the base itself, the bomb might have flattened most of the northern part of Lincoln, including the cathedral dating back to 1250.




