Skip to content

Translate Operation

n-lagomarsini edited this page Jun 24, 2014 · 1 revision

This version of the JAI Translate Operation is very similar to the old version. The main difference is that the new version does not permit to make fractional translations but only integral ones.

The classes used by the Translate Operation are:

  • TranslateIntOpImage.java : this class is similar to the old version of the TranslateIntOpImage.
  • TranslateDescriptor.java: this class describes the parameters used by the TranslateIntOpImage and also provide an efficient method for calling the TranslateIntOpImage class.
  • TranslateCRIF.java: this class is used when the JAI.create("Translation") method is called.

The first class executes the translation operation for every image tile by simply calling the Raster.createTranslatedChild() method inside the getTile() method.

The second class is used when a new translation operation is requested. When the method TranslateDescriptor.create is called, then the descriptor takes the input parameters and puts them inside an instance of ParameterBlock. If the Image presents a translation X or Y value that is fractional or an image layout is present, then an IllegalArgumentException is thrown by the descriptor. If this condition doesn't happen the method JAI.create("Translation") is called. When the JAI.create() method is used, the JAI api searches for a RenderedImageFactory with the selected name and, in this case, finds the TranslateCRIF.java class. This class then calls the TranslateIntOpImage with the parameterBlock values taken as input.

A simple code for understanding the translate operation:

// minTileX, minTileY = minimum X and Y coordinate of the destination image tiles.
// numTileX, mnumTileY = number of tiles on the X and Y coordinate of the destination image.
// destinationTile, sourceTile = destination and source image tiles. 

// Cycle on all the image tiles and then create and return a 
for(int i = minTileX; i <numTileX; i++){
    for(int j = minTileY; j <numTileY; j++){
        destinationTile =  sourceTile.createTranslatedChild(methodParams...);
    }
}

The tests that checks the classes described above are these:

  • TranslateTest.java
  • ComparisonTest.java

The first test calculates the translate operation on 3 band images of all types. The test simply checks if the upper-left coordinate of any image is translated of the defined value. This class is an extension of the class TestBase.java , in which is defined the image creations method used by the subclass. The last test makes a comparison between the old and the new version of the TranslateDescriptor. The test repeatedly executes the translate operation on all the tiles of a Gray image by calling the getTiles() method and then updates the average computational time. At the end of every cycle the JAI TileCache is flushed so that all the image tiles must be recalculated every time. The average, maximum and minimum computation time are not updated for all the iterations, because the first N iterations are not considered due to the Java HotSpot compilation. The number of the iterations to consider and not can be set by passing respectively these 2 Integer parameters to the JVM: JAI.Ext.BenchmarkCycles and JAI.Ext.NotBenchmarkCycles. For selecting which of the 2 descriptors must be tested, the JAI.Ext.OldDescriptor JVM parameter must be set to true or false(true for the old descriptor and false for the new one). The statistics are print to the screen at the end of the process.