<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Thread.currentThread().join() &#187; Apache Sanselan</title>
	<atom:link href="http://www.ashishpaliwal.com/blog/tag/apache-sanselan/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ashishpaliwal.com/blog</link>
	<description>From Programmer, For Programmers</description>
	<lastBuildDate>Tue, 23 Aug 2011 03:53:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>[Apache Sanselan] Demystifying how Sanselan determines image format</title>
		<link>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-demystifying-how-sanselan-determines-image-format/</link>
		<comments>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-demystifying-how-sanselan-determines-image-format/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 16:08:20 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Apache Sanselan]]></category>

		<guid isPermaLink="false">http://www.ashishpaliwal.com/blog/?p=292</guid>
		<description><![CDATA[Apache Sanselan is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper. In previous articles, we saw how to retrieve Image metadata and information. In this post we shall see how Sanselan guesses the Image format. We shall [...]]]></description>
			<content:encoded><![CDATA[<p>Apache Sanselan is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper.</p>
<p>In previous articles, we saw how to retrieve Image metadata and information. In this post we shall see how Sanselan guesses the Image format. We shall take it in two steps</p>
<ul>
<li>First we shall look at the ImageFormat class</li>
<li>Then, we shall look into the implementation guessFormat() API</li>
</ul>
<h4><span style="text-decoration: underline;">ImageFormat class</span></h4>
<p><em><a href="http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageFormat.java?view=log" target="_blank">org.apache.sanselan.ImageFormat</a></em> Class has three members name, extension and actual. Name and extension are same, however I am not sure I understand the use of actual variable.</p>
<p>The class has list of formats (including Unknown) supported by the library. They are all instances of ImageFormat class. The list is</p>
<ol>
<li>IMAGE_FORMAT_UNKNOWN</li>
<li>IMAGE_FORMAT_PNG</li>
<li>IMAGE_FORMAT_GIF</li>
<li>IMAGE_FORMAT_ICO</li>
<li>IMAGE_FORMAT_TIFF</li>
<li>IMAGE_FORMAT_JPEG</li>
<li>IMAGE_FORMAT_BMP</li>
<li>IMAGE_FORMAT_PSD</li>
<li>IMAGE_FORMAT_PBM</li>
<li>IMAGE_FORMAT_PGM</li>
<li>IMAGE_FORMAT_PPM</li>
<li>IMAGE_FORMAT_PNM</li>
<li>IMAGE_FORMAT_TGA</li>
<li>IMAGE_FORMAT_JBIG2</li>
</ol>
<h4><span style="text-decoration: underline;">guessFormat API – Under the hood</span></h4>
<p>The guessFormat() API looks at the initial 2 to 4 bytes, also known as magic numbers, to determine the Image Format.</p>
<p>Algorithm is as follows:</p>
<ul>
<li>Read first two bytes</li>
<li>Match with existing set of magic numbers and determine format</li>
<li>It use byte 3 and 4 to determine format for JBig2</li>
</ul>
<p>The list of magic numbers for different formats is as follows</p>
<table border="1" width="300">
<tbody>
<tr>
<th width="171" scope="col">Format</th>
<th width="52" scope="col">Byte 1</th>
<th width="55" scope="col">Byte 2</th>
</tr>
<tr>
<td>IMAGE_FORMAT_GIF</td>
<td>0x47</td>
<td>0x49</td>
</tr>
<tr>
<td>IMAGE_FORMAT_PNG</td>
<td>0x89</td>
<td>0x50</td>
</tr>
<tr>
<td>IMAGE_FORMAT_JPEG</td>
<td>0xff</td>
<td>0xd8</td>
</tr>
<tr>
<td>IMAGE_FORMAT_BMP</td>
<td>0x42</td>
<td>0x4d</td>
</tr>
<tr>
<td>IMAGE_FORMAT_TIFF</p>
<p>(Motorola byte order)</td>
<td>0x4D</td>
<td>0x4D</td>
</tr>
<tr>
<td>IMAGE_FORMAT_TIFF</p>
<p>(Intel byte order)</td>
<td>0x49</td>
<td>0x49</td>
</tr>
<tr>
<td>IMAGE_FORMAT_PSD</td>
<td>0x38</td>
<td>0x42</td>
</tr>
<tr>
<td>IMAGE_FORMAT_PBM</td>
<td>0x50</td>
<td>0x31 or 0x34</td>
</tr>
<tr>
<td>IMAGE_FORMAT_PGM</td>
<td>0x50</td>
<td>0x32 or 0x35</td>
</tr>
<tr>
<td>IMAGE_FORMAT_PPM</td>
<td>0x50</td>
<td>0x33 or 0x36</td>
</tr>
<tr>
<td>IMAGE_FORMAT_JBIG2</td>
<td>0x97</td>
<td>0x4A</td>
</tr>
</tbody>
</table>
<p>In addition to this IMAGE_FORMAT_JBIG2 format, byte 3 must be equal to 0x42 and byte 4 must be equal to 0x32.</p>
<p>Based on this table, Sanselan recognizes the Image format. If the magic numbers don’t match from the one in the table, it returns IMAGE_FORMAT_UNKNOWN</p>
<p><strong><span style="text-decoration: underline;">References</span></strong></p>
<p><strong><a href="http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/Sanselan.java?view=log" target="_blank">Sanselan.java</a></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-demystifying-how-sanselan-determines-image-format/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Apache Sanselan] Retrieving Image Metadata using Sanselan</title>
		<link>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-metadata-using-sanselan/</link>
		<comments>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-metadata-using-sanselan/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 13:30:00 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Apache Sanselan]]></category>

		<guid isPermaLink="false">http://www.ashishpaliwal.com/blog/?p=287</guid>
		<description><![CDATA[Apache Sanselan is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper. In this article we shall see how to get Image metadata using Apache Sanselan. Let’s see how the code looks public static void main&#40;String&#91;&#93; args&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p>Apache Sanselan is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper.</p>
<p>In this article we shall see how to get Image metadata using Apache Sanselan.</p>
<p>Let’s see how the code looks</p>
<pre class="java5"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="color: #aaaadd; font-weight: bold;">String</span></a> imageFile = args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
         <span style="color: #808080; font-style: italic;">// Metadata details</span>
         IImageMetadata meta = Sanselan.<span style="color: #006600;">getMetadata</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span>imageFile<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
         <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;--- Image Metadata ----&quot;</span><span style="color: #66cc66;">&#41;</span>;
         <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>meta<span style="color: #66cc66;">&#41;</span>;
     <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span>ImageReadException e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
         e.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
     <span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/IOException.html"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
         e.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
     <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Most of the work is done in single line ?</p>
<p>getMetadata() API returns the IImageMetadata  details. The toString() method of actual instance class of IImageMetadata  prints the image information in a formatted fashion. The instance depends upon the format of the image.</p>
<p>Running the program on one the images shipped with Sanselan source produced this output</p>
<p>--- Image Metadata ----<br />
Exif metadata:<br />
Root:<br />
Image Description: '’'<br />
Make: 'Oregon Scientific'<br />
Model: 'DS6639'<br />
Orientation: 1<br />
XResolution: 72<br />
YResolution: 72<br />
Resolution Unit: 2<br />
Software: 'Adobe Photoshop 7.0'<br />
Modify Date: '2008:07:13 21:05:34'<br />
YCbCr Positioning: 2<br />
Exif Offset: 228</p>
<p>Exif:<br />
Exposure Time: 10/10266 (0.001)<br />
FNumber: 28/10 (2.8)<br />
Exposure Program: 2<br />
ISO: 55<br />
Exif Version: 48, 50, 50, 48<br />
Date Time Original: '2003:10:20 09:01:29'<br />
Create Date: '2003:10:20 09:01:29'<br />
Components Configuration: 1, 2, 3, 0<br />
Compressed Bits Per Pixel: 2<br />
Brightness Value: 9<br />
Exposure Compensation: 0<br />
Max Aperture Value: 3<br />
Metering Mode: 1<br />
Light Source: 0<br />
Flash: 0<br />
Focal Length: 864/100 (8.64)<br />
Subject Location: 27556, 57533, 60147, 20319<br />
Flashpix Version: 48, 49, 48, 48<br />
Color Space: 1<br />
Exif Image Width: 300<br />
Exif Image Length: 225<br />
File Source: 3<br />
Scene Type: 1<br />
Custom Rendered: 0<br />
Exposure Mode: 0<br />
White Balance: 1<br />
Digital Zoom Ratio: 1<br />
Focal Length In 3 5mm Format: 42<br />
Scene Capture Type: 0<br />
Gain Control: 0<br />
Contrast: 0<br />
Saturation: 0<br />
Sharpness: 0</p>
<p>Sub:  (jpegImageData)<br />
Compression: 6<br />
XResolution: 72<br />
YResolution: 72<br />
Resolution Unit: 2<br />
Jpg From Raw Start: 838<br />
Jpg From Raw Length: 6258</p>
<p>Photoshop (IPTC) metadata:<br />
Caption/Abstract: ?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-metadata-using-sanselan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Apache Sanselan] Retrieving Image Information using Sanselan</title>
		<link>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-information-using-sanselan/</link>
		<comments>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-information-using-sanselan/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 13:40:45 +0000</pubDate>
		<dc:creator>ashish</dc:creator>
				<category><![CDATA[Apache Sanselan]]></category>

		<guid isPermaLink="false">http://www.ashishpaliwal.com/blog/?p=281</guid>
		<description><![CDATA[Apache Sanselan is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper. In this article we shall see how to get Image Information using Apache Sanselan. Let’s see how the code looks public static void main&#40;String&#91;&#93; args&#41; &#123; [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://cwiki.apache.org/SANSELAN/" target="_blank">Apache Sanselan</a></strong> is a pure Java library for reading and Writing Image formats. It has recently graduated from Incubator and is now a proud member of Apache commons proper.</p>
<p>In this article we shall see how to get Image Information using Apache Sanselan.</p>
<p>Let’s see how the code looks</p>
<pre class="java5"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #993333;">void</span> main<span style="color: #66cc66;">&#40;</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="color: #aaaadd; font-weight: bold;">String</span></a><span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span> args<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html"><span style="color: #aaaadd; font-weight: bold;">String</span></a> imageFile = args<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Image File = &quot;</span>+imageFile<span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #66cc66;">&#123;</span>
ImageInfo imageInfo = Sanselan.<span style="color: #006600;">getImageInfo</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span>imageFile<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html"><span style="color: #aaaadd; font-weight: bold;">System</span></a>.<span style="color: #006600;">out</span>.<span style="color: #006600;">println</span><span style="color: #66cc66;">&#40;</span>imageInfo<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span>ImageReadException e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
e.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #66cc66;">&#40;</span><a href="http://java.sun.com/j2se/1.5.0/docs/api/java/io/IOException.html"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> e<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
e.<span style="color: #006600;">printStackTrace</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
<p>Most of the work is done in single line <img src='http://www.ashishpaliwal.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>getImageInfo() API returns the ImageInfo details. The toString() method of ImageInfo class prints the image information in a formatted fashion.</p>
<p>Running the program on one the images shipped with Sanselan source produced this output</p>
<address>Format Details: Jpeg/JFIF v.1.2</p>
<p>Bits Per Pixel: 24</p>
<p>Comments: 0</p>
<p>Format: JPEG</p>
<p>Format Name: JPEG (Joint Photographic Experts Group) Format</p>
<p>Compression Algorithm: JPEG</p>
<p>Height: 225</p>
<p>MimeType: image/jpeg</p>
<p>Number Of Images: 1</p>
<p>Physical Height Dpi: 72</p>
<p>Physical Height Inch: 3.125</p>
<p>Physical Width Dpi: 72</p>
<p>Physical Width Inch: 4.1666665</p>
<p>Width: 300</p>
<p>Is Progressive: true</p>
<p>Is Transparent: false</p>
<p>Color Type: RGB</p>
<p>Uses Palette: false</p>
</address>
<p>The ImageInfo class can be used programtically to arrange files, or for other purposes as well</p>
<p><strong>References</strong></p>
<p><a href="http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/" target="_blank"> Sanselan Source</a></p>
<p><a href="http://cwiki.apache.org/SANSELAN/" target="_blank"> Sanselan Wiki</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ashishpaliwal.com/blog/2009/07/apache-sanselan-retrieving-image-information-using-sanselan/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

