CADI.Server.LogicalTarget.JPEG2000.RateDistortion
Class CoRDDelivery

java.lang.Object
  extended by CADI.Server.LogicalTarget.JPEG2000.RateDistortion.CoRDDelivery

public class CoRDDelivery
extends java.lang.Object

This class implements the Characterization of Rate Distortion (CoRD) algorithm.

Furthe Usage example:
  construct
  runResponseParameters
  getResponseViewWindow
  getQuality
  runResponseData
  getJPIPMessageData
  getEORReasonCode

Version:
1.1.2 2009/05/18
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  CODParameters codParameters
          Definition in CODParameters
private  int[][] comps
           
private  int EORReasonCode
          Definition in ServerLogicalTargetManager.EORReasonCode.
private  int[] fsiz
          Some internal attributes for passing values between diferents methods.
private  HTTPResponseSender httpResponseSender
          Definition in Worker.httpResponseSender
private  int[][][][][][] imageStructure
          Definition in GenerateImageStructure.imageStructure
private  long[][][] inClassIdentifierCorrespondence
          Is a multiple-dimensional array which will be a mapping between the component-resolutionlevel-precinct and the unique in-class identifier.
private  JPCParameters jpcParameters
          Definition in JPCParameters
private  JPIPMessageEncoder jpipMessageEncoder
          Definition in JP2LogicalTargetManager.
private  java.util.ArrayList<JPIPMessageHeader> jpipMessageHeaders
          Definition in ServerLogicalTargetManager.jpipMessageHeaders.
private  int layers
           
private  JP2LogicalTarget logicalTarget
          Definition in ServerLogicalTargetManager.EORReasonCode.
private  byte[] mainHeader
          Contains the encoded main header.
private  long maximumResponseLength
          Definition in DataLimitField.len
private  int maxNumLayers
          Definition in CODParameters.numLayers
private  int MSBPlane
          Definition in CADI.Server.LogicalTarget.JPEG2000.JP2LogicalTarget#MSBPlanes.
private  PacketHeadersEncoder packetHeading
          This object is used to build the packet headers.
private  int[][][] precinctsPerRLevel
          Is a mutiple-dimensional array which will contain the precincts belonging to the WOI.
private  int quality
          Definition in ServerLogicalTargetManager.quality.
private  long responseLength
          It is a temporal attribute to accumulate the response length which is sending to the client.
private  ViewWindowField responseViewWindow
          Definition in ServerLogicalTargetManager.responseViewWindow.
private  int[] roff
           
private  int[] rsiz
           
private  JPCServerCache serverCache
          This attribute contains the cache data for the client.
private  SIZParameters sizParameters
          Definition in SIZParameters
 
Constructor Summary
CoRDDelivery(JP2LogicalTarget logicalTarget, JPCServerCache serverCache, long maximumResponseLength)
          Constructor.
 
Method Summary
private  java.util.ArrayList<CodingPassID> adjustScanningOrder(java.util.ArrayList<BlockOrder> blockOrders)
           
 void calculateMaxMinBitPlanes(int[][][] precinctsPerRLevel, int[][][] maxsBP, int[][][] minsBP, long[][][] inClassIdentifierCorrespondence, int[] components)
          Construction of two structures which contain the max and min number of bit-planes of the code-blocks, by subbands Indexes mean: [component][rLevel][subbandBP]
private  void calculateSlopeStimations(float[][][][][] slopes, int[][][] minsBP)
          SLOPE ESTIMATIONS
private  void encodeMainHeader()
          Gets the main header as a byte array.
private  java.util.ArrayList<BlockOrder> findSubbandScanningOrder(float[][][][][] slopes, int[][][][] currSLs, int[][][] minsBP, int[] components)
           
private  java.util.ArrayList<BlockOrder> getDeliveryOrder(java.util.ArrayList relevantPrecincts)
          Performs the block building and reads the needed bytestreams using the number of bytes.
 int getEORReasonCode()
          Returns the EORReasonCode attribute.
 java.util.ArrayList<JPIPMessageHeader> getJPIPMessageHeaders()
          Returns the jpipMessageHeaders attribute.
 byte[] getMainHeader()
          Returns the main header.
private  int getMaxSubbandWeight()
          Calculate which is the maximum subband weight for the whole image.
 void getPrecinctsPerRLevel(java.util.ArrayList relevantPrecincts)
          Gets the relevant precincts for each subband.
 int getQuality()
          Returns the quality attribute.
 ViewWindowField getResponseViewWindow()
          Returns the responseViewWindow attribute.
private  int getSubbandWeight(int z, int rLevel, int subband)
          Returns a rate-distortion adjustment for a component, resolution level, and subband.
private  java.util.ArrayList<CodingPassID> includeCP(java.util.ArrayList<CodingPassID> orderOfCodingPasses, long inClassIdentifier, int component, int rLevel, int precinct, int subband, int yBlock, int xBlock, int codingLevelGlobal)
           
 void list(java.io.PrintStream out)
          Prints this CoRD delivery out to the specified output stream.
private static void printByteArray(byte[] buffer)
          Useful method for printing a byte array.
private  void responsePerLength(java.util.ArrayList<CodingPassID> scanningOrder)
          This method is used to deliver the requested window of interest when the maximum response length parameter has been set.
private  void responsePerQualityLayer(java.util.ArrayList<CodingPassID> scanningOrder)
          This method is used to deliver the requested window of interest when the layers parameter of the view window has been set.
 void runResponseData(HTTPResponseSender httpResponseSender, JPIPMessageEncoder jpipMessageEncoder, java.util.ArrayList<JPIPMessageHeader> jpipMessageHeaders)
          Gets the data of the response window of interest.
 void runResponseParameters(ViewWindowField viewWindow)
           
private  int[][][][][][] setFirstLayer(java.util.ArrayList<CodingPassID> scanningOrder)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

httpResponseSender

private HTTPResponseSender httpResponseSender
Definition in Worker.httpResponseSender


jpipMessageEncoder

private JPIPMessageEncoder jpipMessageEncoder
Definition in JP2LogicalTargetManager.


jpipMessageHeaders

private java.util.ArrayList<JPIPMessageHeader> jpipMessageHeaders
Definition in ServerLogicalTargetManager.jpipMessageHeaders.


mainHeader

private byte[] mainHeader
Contains the encoded main header.


responseViewWindow

private ViewWindowField responseViewWindow
Definition in ServerLogicalTargetManager.responseViewWindow.


quality

private int quality
Definition in ServerLogicalTargetManager.quality.


EORReasonCode

private int EORReasonCode
Definition in ServerLogicalTargetManager.EORReasonCode.


logicalTarget

private JP2LogicalTarget logicalTarget
Definition in ServerLogicalTargetManager.EORReasonCode.


serverCache

private JPCServerCache serverCache
This attribute contains the cache data for the client.

This reference is passed from the


maximumResponseLength

private long maximumResponseLength
Definition in DataLimitField.len


jpcParameters

private JPCParameters jpcParameters
Definition in JPCParameters


sizParameters

private SIZParameters sizParameters
Definition in SIZParameters


codParameters

private CODParameters codParameters
Definition in CODParameters


imageStructure

private int[][][][][][] imageStructure
Definition in GenerateImageStructure.imageStructure


MSBPlane

private int MSBPlane
Definition in CADI.Server.LogicalTarget.JPEG2000.JP2LogicalTarget#MSBPlanes.


responseLength

private long responseLength
It is a temporal attribute to accumulate the response length which is sending to the client.


fsiz

private int[] fsiz
Some internal attributes for passing values between diferents methods. They contains the view window attributes, then for a full description see ViewWindowField


roff

private int[] roff

rsiz

private int[] rsiz

comps

private int[][] comps

layers

private int layers

maxNumLayers

private int maxNumLayers
Definition in CODParameters.numLayers


precinctsPerRLevel

private int[][][] precinctsPerRLevel
Is a mutiple-dimensional array which will contain the precincts belonging to the WOI.


inClassIdentifierCorrespondence

private long[][][] inClassIdentifierCorrespondence
Is a multiple-dimensional array which will be a mapping between the component-resolutionlevel-precinct and the unique in-class identifier.


packetHeading

private PacketHeadersEncoder packetHeading
This object is used to build the packet headers.

Constructor Detail

CoRDDelivery

public CoRDDelivery(JP2LogicalTarget logicalTarget,
                    JPCServerCache serverCache,
                    long maximumResponseLength)
Constructor.

Parameters:
logicalTarget - definition in logicalTarget
serverCache - definition in serverCache
maximumResponseLength - definition in maximumResponseLength
Method Detail

runResponseParameters

public void runResponseParameters(ViewWindowField viewWindow)
Parameters:
viewWindow - the requested Window Of Interest

runResponseData

public void runResponseData(HTTPResponseSender httpResponseSender,
                            JPIPMessageEncoder jpipMessageEncoder,
                            java.util.ArrayList<JPIPMessageHeader> jpipMessageHeaders)
                     throws ErrorException,
                            java.io.IOException
Gets the data of the response window of interest. This data is calculate using the CoRD algorithm.

Parameters:
httpResponseSender - definition in httpResponseSender
jpipMessageEncoder - definition in jpipMessageEncoder
jpipMessageHeaders - definition in jpipMessageHeaders
Throws:
ErrorException
java.io.IOException

getMainHeader

public byte[] getMainHeader()
Returns the main header.

Returns:
the mainHeader.

getEORReasonCode

public int getEORReasonCode()
Returns the EORReasonCode attribute.

Returns:
the EORReasonCode attribute.

getResponseViewWindow

public ViewWindowField getResponseViewWindow()
Returns the responseViewWindow attribute.

Returns:
the responseViewWindow attribute.

getJPIPMessageHeaders

public java.util.ArrayList<JPIPMessageHeader> getJPIPMessageHeaders()
Returns the jpipMessageHeaders attribute.

Returns:
the jpipMessageHeaders attribute.

getQuality

public int getQuality()
Returns the quality attribute.

Returns:
the quality attribute.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

list

public void list(java.io.PrintStream out)
Prints this CoRD delivery out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

encodeMainHeader

private void encodeMainHeader()
Gets the main header as a byte array. This method can be called if the transcoding is done.


getSubbandWeight

private int getSubbandWeight(int z,
                             int rLevel,
                             int subband)
Returns a rate-distortion adjustment for a component, resolution level, and subband.

Parameters:
z - image component
rLevel - 0 is the LL subband, and 1, 2, ... represents next starting with the little one
subband - 0 - HL, 1 - LH, 2 - HH (if resolutionLevel == 0 --> 0 - LL)
Returns:
the rate-distortion adjustment for a component, resolution level, and subband.

getMaxSubbandWeight

private int getMaxSubbandWeight()
Calculate which is the maximum subband weight for the whole image.

Returns:
the maximum subband weight.
See Also:
method.

getDeliveryOrder

private java.util.ArrayList<BlockOrder> getDeliveryOrder(java.util.ArrayList relevantPrecincts)
                                                  throws ErrorException
Performs the block building and reads the needed bytestreams using the number of bytes.

Returns:
a bi-dimensional array with the order of precincts. The first index is the ordering number. And the second index is: if 1, indicates the current subband bit plane if 2, then number of bit planes if 3, the coding level if 4, if the coding pass must be concatenated
Throws:
ErrorException - when some problem reading file occurs

calculateSlopeStimations

private void calculateSlopeStimations(float[][][][][] slopes,
                                      int[][][] minsBP)
SLOPE ESTIMATIONS

Parameters:
slopes -
minsBP -

findSubbandScanningOrder

private java.util.ArrayList<BlockOrder> findSubbandScanningOrder(float[][][][][] slopes,
                                                                 int[][][][] currSLs,
                                                                 int[][][] minsBP,
                                                                 int[] components)
Parameters:
slopes -
currSLs -
minsBP -
Returns:

adjustScanningOrder

private java.util.ArrayList<CodingPassID> adjustScanningOrder(java.util.ArrayList<BlockOrder> blockOrders)
Parameters:
order -

includeCP

private java.util.ArrayList<CodingPassID> includeCP(java.util.ArrayList<CodingPassID> orderOfCodingPasses,
                                                    long inClassIdentifier,
                                                    int component,
                                                    int rLevel,
                                                    int precinct,
                                                    int subband,
                                                    int yBlock,
                                                    int xBlock,
                                                    int codingLevelGlobal)
Parameters:
blockOrder -
inClassIdentifier -
component -
rLevel -
precinct -
yBlock -
xBlock -
codingLevel -
Returns:

responsePerLength

private void responsePerLength(java.util.ArrayList<CodingPassID> scanningOrder)
                        throws ErrorException,
                               java.io.IOException
This method is used to deliver the requested window of interest when the maximum response length parameter has been set. This method, in order to keep the right scanning order given by the CoRD algorithm, sends only one coding-pass per packet.

Parameters:
scanningOrder - is an ArrayList with the order of precincts including the subband, yBlock, xBlock and coding passes to be sent.
Throws:
ErrorException
java.io.IOException

responsePerQualityLayer

private void responsePerQualityLayer(java.util.ArrayList<CodingPassID> scanningOrder)
                              throws ErrorException,
                                     java.io.IOException
This method is used to deliver the requested window of interest when the layers parameter of the view window has been set. This method, in order to keep the right scanning order given by the CoRD algorithm, sends only one coding-pass per packet.

Parameters:
scanningOrder -
Throws:
ErrorException
java.io.IOException

setFirstLayer

private int[][][][][][] setFirstLayer(java.util.ArrayList<CodingPassID> scanningOrder)
Parameters:
scanningOrder -
Returns:

getPrecinctsPerRLevel

public void getPrecinctsPerRLevel(java.util.ArrayList relevantPrecincts)
Gets the relevant precincts for each subband.

Parameters:
relevantPrecincts - an array list with the unique precinct identifier of the relevant precincts.

calculateMaxMinBitPlanes

public void calculateMaxMinBitPlanes(int[][][] precinctsPerRLevel,
                                     int[][][] maxsBP,
                                     int[][][] minsBP,
                                     long[][][] inClassIdentifierCorrespondence,
                                     int[] components)
Construction of two structures which contain the max and min number of bit-planes of the code-blocks, by subbands Indexes mean: [component][rLevel][subbandBP]

Parameters:
precinctsPerRLevel -
maxsBP -
minsBP -

printByteArray

private static void printByteArray(byte[] buffer)
Useful method for printing a byte array. Only for debugging purposes.

Parameters:
buffer - the byte array to be printed.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)