fi.helsinki.cs.ohtu.mpeg2.video
Class IntraMacroblock

java.lang.Object
  extended by fi.helsinki.cs.ohtu.mpeg2.video.IntraMacroblock

public class IntraMacroblock
extends java.lang.Object

IntraMacroblock

A macroblock contains a section of the luminance component and the spatially corresponding chrominance components.

A 4:2:0 macroblock consists of 6 blocks. (YYYYCbCr)

TODO: Some methods must be changed in order to get other chromaformats working:
A 4:2:2 macroblock consists of 8 blocks. (YYYYCbCrCbCr)
A 4:4:4 macroblock consists of 12 blocks. (YYYYCbCrCbCrCbCrCbCr)


Field Summary
private  IntraBlock[] blocks
           
private  MacroblockHeader header
           
 
Constructor Summary
IntraMacroblock()
          Constructs a Macroblock high-level instance.
 
Method Summary
 int getAddressIncrement()
          Gets the address increment.
 IntraBlock getBlock(int blockNumber)
          Gets block(0-5) from macroblock.
 IntraBlock getBlock(IntraBlock.ColourComponent c, int x, int y)
          Gets block with given colour component and given position(x,y) from macroblock.
private static int getBlockIndex(IntraBlock.ColourComponent c, int x, int y)
          Calculates block's index(0-5).
private  int[] getMacroblockType()
          Gets macroblockType.
 int getQuantizerScaleCode()
          Gets the specified override quantizer scale code.
 boolean hasDCTType()
          Determines if the type of DCT used is specified.
 boolean hasQuantizerScaleCode()
          Determines if the macroblock specifies an override quantizer scale code.
 boolean isDCTTypeField()
          Determines if the specified DCT type is field-based.
 boolean isDCTTypeFrame()
          Determines if the specified DCT type is frame-based.
 void removeAllBlocks()
          Removes all blocks from macroblock.
 void removeBlock(int blockNumber)
          Removes selected block from macroblock.
 void removeBlock(IntraBlock.ColourComponent c, int x, int y)
          Removes block with given colour component and given position(x,y) from macroblock.
 void setAddressIncrement(int addressIncrement)
          Sets the address increment.
 void setBlock(int blockNumber, IntraBlock block)
          Add blocks to macroblock.
 void setBlock(IntraBlock.ColourComponent c, int x, int y, IntraBlock block)
          Add blocks to macroblock.
 void setDCTTypeField()
          Sets the macroblock to specify a field-based DCT type.
 void setDCTTypeFrame()
          Sets the macroblock to specify a frame-based DCT type.
 void setQuantizerScaleCode(int quantizerScaleCode)
          Sets the macroblock to specify an override quantizer scale code.
 void unsetDCTType()
          Unsets any DCT type specification previously set by setDCTTypeField() and/or setDCTTypeFrame().
 void unsetQuantizerScaleCode()
          Unsets any override quantizer scale code previously set by setQuantizerScaleCode().
 void writeTo(BitOutputStream stream)
          Writes the macroblock to a bit-by-bit output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

header

private MacroblockHeader header

blocks

private IntraBlock[] blocks
Constructor Detail

IntraMacroblock

public IntraMacroblock()
Constructs a Macroblock high-level instance.

Method Detail

setBlock

public void setBlock(int blockNumber,
                     IntraBlock block)

Add blocks to macroblock. Blocks are held in Array. In chromaformat 4:2:0 macroblock structure is following:
0:Y
1:Y
2:Y
3:Y
4:Cb
5:Cr

Parameters:
blockNumber - selects where block is going to be added
block - block to be added

setBlock

public void setBlock(IntraBlock.ColourComponent c,
                     int x,
                     int y,
                     IntraBlock block)

Add blocks to macroblock. Blocks are held in Array. In chromaformat 4:2:0 macroblock structure is following:
0:Y
1:Y
2:Y
3:Y
4:Cb
5:Cr

Parameters:
c - selects where block is going to be added
x - horizontal position of block
y - vertical position of block
block - block to be added

getBlock

public IntraBlock getBlock(IntraBlock.ColourComponent c,
                           int x,
                           int y)
Gets block with given colour component and given position(x,y) from macroblock.

Parameters:
c - ColourComponent
x - horizontal position of block
y - vertical position of block
Returns:
selected block from macroblock

removeBlock

public void removeBlock(IntraBlock.ColourComponent c,
                        int x,
                        int y)
Removes block with given colour component and given position(x,y) from macroblock.

Parameters:
c - ColourComponent
x - horizontal position of block
y - vertical position of block

getBlock

public IntraBlock getBlock(int blockNumber)
Gets block(0-5) from macroblock.

Parameters:
blockNumber - selects block to be returned
Returns:
selected block from macroblock

removeBlock

public void removeBlock(int blockNumber)
Removes selected block from macroblock.

Parameters:
blockNumber - selects the block to be removed

removeAllBlocks

public void removeAllBlocks()
Removes all blocks from macroblock.


setAddressIncrement

public void setAddressIncrement(int addressIncrement)
Sets the address increment.

Parameters:
addressIncrement - The increment to set. Must be positive.

getAddressIncrement

public int getAddressIncrement()
Gets the address increment.

Returns:
The increment. Will be positive.

setQuantizerScaleCode

public void setQuantizerScaleCode(int quantizerScaleCode)
Sets the macroblock to specify an override quantizer scale code.

Parameters:
quantizerScaleCode - The scale code to set. Must fit into 5 bits as an unsigned integer.

getQuantizerScaleCode

public int getQuantizerScaleCode()
Gets the specified override quantizer scale code.

Returns:
The code. Only the lowest 5 bits will be meaningful.

unsetQuantizerScaleCode

public void unsetQuantizerScaleCode()
Unsets any override quantizer scale code previously set by setQuantizerScaleCode(). The macroblock will no longer specify any override quantizer scale code.


hasQuantizerScaleCode

public boolean hasQuantizerScaleCode()
Determines if the macroblock specifies an override quantizer scale code.

Returns:
true if a scale code is specified, false if not.

hasDCTType

public boolean hasDCTType()
Determines if the type of DCT used is specified.

Returns:
true if a dct type is specified, false if not.

setDCTTypeField

public void setDCTTypeField()
Sets the macroblock to specify a field-based DCT type.


setDCTTypeFrame

public void setDCTTypeFrame()
Sets the macroblock to specify a frame-based DCT type.


unsetDCTType

public void unsetDCTType()
Unsets any DCT type specification previously set by setDCTTypeField() and/or setDCTTypeFrame(). The macroblock will no longer specify any DCT type.


isDCTTypeField

public boolean isDCTTypeField()
Determines if the specified DCT type is field-based.

Returns:
true if field-based, false if frame-based.

isDCTTypeFrame

public boolean isDCTTypeFrame()
Determines if the specified DCT type is frame-based.

Returns:
true if frame-based, false if field-based.

getMacroblockType

private int[] getMacroblockType()
Gets macroblockType.

Returns:
the macroblockType

getBlockIndex

private static int getBlockIndex(IntraBlock.ColourComponent c,
                                 int x,
                                 int y)
Calculates block's index(0-5). This one needs to be changed if other colourformat than 4:2:0 is used.

Parameters:
c - ColourComponent
x - horizontal position of block
y - vertical position of block
Returns:
blockindex (0-5)

writeTo

public void writeTo(BitOutputStream stream)
             throws java.io.IOException
Writes the macroblock to a bit-by-bit output stream.

Parameters:
stream - the stream to write to.
Throws:
java.io.IOException