* @return a populated ImageRecord object
* @throws DjatokaException
*/
public final ImageRecord getMetadata(ImageRecord r) throws DjatokaException {
if (!new File(r.getImageFile()).exists())
throw new DjatokaException("Image Does Not Exist");
Jp2_source inputSource = new Jp2_source();
Kdu_compressed_source kduIn = null;
Jp2_family_src jp2_family_in = new Jp2_family_src();
Jp2_locator loc = new Jp2_locator();
try {
jp2_family_in.Open(r.getImageFile(), true);
inputSource.Open(jp2_family_in, loc);
inputSource.Read_header();
kduIn = inputSource;
Kdu_codestream codestream = new Kdu_codestream();
codestream.Create(kduIn);
Kdu_channel_mapping channels = new Kdu_channel_mapping();
if (inputSource.Exists())
channels.Configure(inputSource, false);
else
channels.Configure(codestream);
int ref_component = channels.Get_source_component(0);
int minLevels = codestream.Get_min_dwt_levels();
int minLayers= codestream.Get_max_tile_layers();
Kdu_dims image_dims = new Kdu_dims();
codestream.Get_dims(ref_component, image_dims);
Kdu_coords imageSize = image_dims.Access_size();
r.setWidth(imageSize.Get_x());
r.setHeight(imageSize.Get_y());
r.setDWTLevels(minLevels);
channels.Native_destroy();
if (codestream.Exists())
codestream.Destroy();
kduIn.Native_destroy();
inputSource.Native_destroy();
jp2_family_in.Native_destroy();
} catch (KduException e) {
throw new DjatokaException(e);
}
return r;
}