Saturday, 12 April 2008

No more update

I won't update any more here, because I am going to start a new blog, which includes C/C++ and Java. I will leave a link here.

Friday, 21 September 2007

CSS study ------> part 2 ------> W3School

This is a very helpful place for you to study CSS. It has almost everything you need for CSS. And examples are very useful.

In your HTML page, you need to have style.css imported, which will help you to format your page properly, like
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>

This tells the browser to look for the style sheet for the web pages.
Generally the style sheet starts with some basic format definitions of the page,like h1, h2, h3, p and a etc.

Saturday, 15 September 2007

CSS study ------> part 1 ------> warm up

I just finished a Java-based tool for radiation beam modelling. Later I will put some GUI codes in this blog.


Recently I am trying to build website by myself. I know some simple CSS for web coding, but to make a beautiful website I have to study it again.

From W3C, you can have some idea about it.

There is class in style sheet, but it is not the class as in C++/Java. It starts with '.' (dot) and follows the name of the class, for example,

p.right {text-align: right}
p.center {text-align: center}

Used in HTML,
< p class="right" >
This paragraph will be right-aligned.
</p>
<p class="center">
This paragraph will be center-aligned.
</p>

If a class has no tag name, it could be used by any tag. If '#' starts before a name, it is an id selector and used with id in HTML.

Wednesday, 29 August 2007

Frondeg Guest House - An unpleasant experience

I was planning to have a bank holiday weekend in Harlech Wales. I booked a room from this B&B a month in advance.

I found this B&B from the Internet and I emailed the owner. On the same day I got the reply.

"
Hi,
I have reserved the twin ensuite for you for the 25 and 25 August. My house is 9 miles up the A496 from Barmouth 1 mile before Harlech you will see village sign called Llanfair 500yds from that sign you will see my house on the cross road on your right it is covered in green leaves. Hope you can make it I have your phone number if the weather looks bad I will phone you to see if you are coming.
"

From this email, which was sent on 8th August, I found the owner was very kind. And to correct her mistake of the dates I emailed her again on 8th August. Here is her reply.

"Hi,
Sorry my mistake 25 and 26 are reserved for you.
"

On 22th August, I received another email from her for confirmation.

"
Hi,
Just checking that you are coming to stay B&B at the weekend the weather promises to be good but I need a definite confirmation that you are coming as there is a big demand for the room. I cannot guarantee that I can keep the room for you unless you answer this email or phone me.
"

Once I received this email, I replied her immediately and asked her to keep the room for me. I was so happy to have a trip to Snowdonia.

In the evening of 24th August, I called her for asking the detail of check-in time etc., and she told me there would not be B&B for me, because her daughter was ill. She told me she'd sent an email to me for the cancellation.

I was shocked. I have never had this kind experience before.

A business woman can be just so easy to break her promise.

I've NEVER received the cancellation email she sent.

An email sent by her mentioned about large demanding for the room just 2 days ago makes me suspect about her excuse. I could not believe she just shut down B&B for every booked customer.

If this is really an emergency, she has not even tried to make sure I know the case. This ends up I could not find anywhere to stay. If I went there, the thing could be even worse!

In the telephone, she has not even made an apology for the cancellation!

This is just a very bad experience to me.

Conclusions for everyone:
Frondeg Guest House is not a B&B you can trust. To book it, it will be on your own risk, because it could be cancelled without letting you know. You might end up with nowhere to stay!

For me, I won't try it again.

Plan for next month

Do not have much time this month. I plan to keep on writing in September.

There will be some practical examples of Java. The C# will be the new content in my blog.

Monday, 30 July 2007

Image Display

JAI uses the Java 2D BufferedImage model for displaying images. The BufferedImage manages an image in memory and provides ways to store pixel data, interpret pixel data, and to render the pixel data to a Graphics2D context.

The display of images in JAI may be accomplished in several ways. First, the drawRenderedImage() call on Graphics2D may be used to produce an immediate rendering. Another method is to instantiate a display widget that responds to user requests such as scrolling and panning, as well as expose events, and requests image data from a RenderedImage source. This technique allows image data to be computed on demand.

* int getWidth()
returns the width of the rendered image.

* int getHeight()
returns the height of the rendered image.

* ScrollingImagePanel(RenderedImage im, int width, int height)
constructs a ScrollingImagePanel of a given size for a given RenderedImage.

* void setOrigin(int x, int y)
sets the image origin to a given (x, y) position. The scrollbars are updated appropriately.

* void setCenter(int x, int y)
sets the image center to a given (x, y) position. The scrollbars are updated appropriately.

* ImageCanvas(RenderedImage im, boolean drawBorder)
constructs an ImageCanvas to display a RenderedImage.

* ImageCanvas(java.awt.image.RenderedImage im)
constructs an ImageCanvas to display a RenderedImage.

* void set(RenderedImage im)
changes the source image to a new RenderedImage.

* void paint(java.awt.Graphics g)
paint the image onto a Graphics object.

* void setOrigin(int x, int y)
sets the origin of the image at x,y.

* int getXOrigin()
returns the x coordinate of the image origin.

* int getYOrigin()
returns the y coordinate of the image origin.

Tuesday, 24 July 2007

Reading Image Files

JAI directly supports several of the most common image file formats, BMP, FPX, GIF, JPEG, PNG, PNM, TIFF.

An image file usually has at least two parts: a file header and the image data. The header contains fields of pertinent information regarding the following image data. At the very least, the header must provide all the information necessary to reconstruct the original image from the stored image data. The image data itself may or may not be compressed.

For most image types, JAI offers the option of reading an image data file as a java.io.File object or as one of the subclasses of java.io.InputStream.

The Stream operation reads an image from a SeekableStream.
// Load the source image from a Stream.
RenderedImage im = JAI.create("stream", stream);


The FileLoad operation reads an image from a file.
// Load the source image from a file.
RenderedImage src = (RenderedImage)JAI.create("fileload", fileName);


The TIFF operation reads TIFF data from a TIFF SeekableStream.

For TIFF Palette color images, the colorMap always has entries of short data type, the color black being represented by 0,0,0 and white by 65536,65536,65536. To display these images, the default behavior is to dither the short values down to 8 bits. The dithering is done by calling the decode16BitsTo8Bit method for each short value that needs to be dithered.

A TIFF file may contain more than one Image File Directory (IFD). Each IFD defines a subfile, which may be used to describe related images. To determine the number of images in a TIFF file, use the TIFFDirectory.getNumDirectories() method.

API: com.sun.media.jai.codec.TIFFDecodeParam
* void setDecodePaletteAsShorts(boolean decodePaletteAsShorts)
if set, the entries in the palette will be decoded as shorts and no short-to-byte lookup will be applied to them.

* boolean getDecodePaletteAsShorts()
returns true if palette entries will be decoded as shorts, resulting in a output image with short datatype.

* byte decode16BitsTo8Bits(int s)
returns an unsigned 8-bit value computed by dithering the unsigned 16-bit value.

API: com.sun.media.jai.codec.TIFFDirectory
* static int getNumDirectories(SeekableStream stream)
returns the number of image directories (subimages) stored in a given TIFF file, represented by a SeekableStream.

API: com.sun.media.jai.codec.TIFFField
* int getTag()
returns the tag number, between 0 and 65535.

* int getType()
returns the type of the data stored in the IFD.

* int getCount()
returns the number of elements in the IFD.

API: com.sun.media.jai.codec.TIFFDirectory
* TIFFDirectory(SeekableStream stream, int directory)
constructs a TIFFDirectory from a SeekableStream.

* TIFFDirectory(SeekableStream stream, long ifd_offset)
constructs a TIFFDirectory by reading a SeekableStream.

* int getNumEntries()
returns the number of directory entries.

* TIFFField getField(int tag)
returns the value of a given tag as a TIFFField, or null if the tag is not present.

* boolean isTagPresent(int tag)
returns true if a tag appears in the directory.

* int[] getTags()
returns an ordered array of ints indicating the tag values.

* TIFFField[] getFields()
returns an array of TIFFFields containing all the fields in this directory.

* byte getFieldAsByte(int tag, int index)
returns the value of a particular index of a given tag as a byte.

* byte getFieldAsByte(int tag)
returns the value of index 0 of a given tag as a byte.

* long getFieldAsLong(int tag, int index)
returns the value of a particular index of a given tag as a long.

* long getFieldAsLong(int tag)
returns the value of index 0 of a given tag as a long.

* float getFieldAsFloat(int tag, int index)
returns the value of a particular index of a given tag as a float.

* float getFieldAsFloat(int tag)
returns the value of a index 0 of a given tag as a float.

* double getFieldAsDouble(int tag, int index)
returns the value of a particular index of a given tag as a double.

* double getFieldAsDouble(int tag)
returns the value of index 0 of a given tag as a double.


Example of Reading a BMP Image

// Wrap the InputStream in a SeekableStream.
InputStream is = new FileInputStream(filename);
SeekableStream s = SeekableStream.wrapInputStream(is, false);

// Create the ParameterBlock and add the SeekableStream to it.
ParameterBlock pb = new ParameterBlock();
pb.add(s);

// Perform the BMP operation
op = JAI.create("BMP", pb);


Example of Reading a PNM Image

// Create the ParameterBlock.
InputStream image = new FileInputStream(filename);
ParameterBlock pb = new ParameterBlock();
pb.add(image);

// Create the PNM operation.
op = JAI.create("PNM", pb);


Example of Reading an AWT Image

// Create the ParameterBlock.
ParameterBlock pb = new ParameterBlock();
pb.add(image);

// Create the AWTImage operation.
PlanarImage im = (PlanarImage)JAI.create("awtImage", pb);


Example of Reading a URL Image

// Define the URL to the image.
url = new URL("http://webstuff/images/duke.gif");

// Read the image from the designated URL.
RenderedOp src = JAI.create("url", url);


Example of Converting a Rendered Image to Renderable

// Derive the RenderableImage from the source RenderedImage.
ParameterBlock pb = new ParameterBlock();
pb.addSource(src);
pb.add(null).add(null).add(null).add(null).add(null);

// Create the Renderable operation.
RenderableImage ren = JAI.createRenderable("renderable", pb);


Example Constant Operation

// Create the ParameterBlock.
Byte[] bandValues = new Byte[1];
bandValues[0] = alpha1;
pb = new ParameterBlock();
pb.add(new Float(src1.getWidth())); // The width
pb.add(new Float(src1.getHeight())); // The height
pb.add(bandValues); // The band values

// Create the constant operation.
PlanarImage afa1 = (PlanarImage)JAI.create("constant", pb);