JIU 0.12.0 Homepage

net.sourceforge.jiu.color.data
Class OnDemandHistogram3D

java.lang.Object
  extended bynet.sourceforge.jiu.color.data.OnDemandHistogram3D
All Implemented Interfaces:
Histogram3D

public class OnDemandHistogram3D
extends Object
implements Histogram3D

A data class for a three-dimensional histogram, creating counters on demand only, not allocating counters for all possible entries at the beginning. The creation on demand happens to save space. A naive implementation can become huge - for eight bits per component, you'd need 2(8 + 8 + 8) = 224 = 16,777,216 int values (64 MB), while a typical 24 bit image uses only a fraction of these possible colors.

Author:
Marco Schmidt

Constructor Summary
OnDemandHistogram3D(int maxValue)
          Creates a new object of this class with the argument as maximum value for all three index positions and the component values 0, 1, 2.
OnDemandHistogram3D(int maxValue1, int maxValue2, int maxValue3)
          Creates a new object of this class with maximum values as specified by the arguments and the component values 0, 1, 2.
OnDemandHistogram3D(int maxValue1, int maxValue2, int maxValue3, int c1, int c2, int c3)
          Creates a new object of this class with specified maximum values for all three indexes.
 
Method Summary
 void clear()
          Resets all counters to zero.
 int getEntry(int index1, int index2, int index3)
          Returns counter for the argument color given by its red, green and blue intensity.
 int getMaxValue(int index)
          Returns the maximum index value for one of the three indexes.
 int getNumUsedEntries()
          Returns the number of entries in this histogram with a counter value of one or higher (in other words: the number of colors that are in use).
 void increaseEntry(int red, int green, int blue)
          Increases the counter for the color given by the arguments red, green and blue.
 void setEntry(int r, int g, int b, int newValue)
          Sets one counter to a new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OnDemandHistogram3D

public OnDemandHistogram3D(int maxValue1,
                           int maxValue2,
                           int maxValue3,
                           int c1,
                           int c2,
                           int c3)
                    throws IllegalArgumentException
Creates a new object of this class with specified maximum values for all three indexes.

Parameters:
maxValue1 - the maximum value for the first index
maxValue2 - the maximum value for the second index
maxValue3 - the maximum value for the third index
c1 - the top level component for the internal tree
c2 - the second-level component for the internal tree
c3 - the third-level component for the internal tree

OnDemandHistogram3D

public OnDemandHistogram3D(int maxValue1,
                           int maxValue2,
                           int maxValue3)
Creates a new object of this class with maximum values as specified by the arguments and the component values 0, 1, 2. Simply calls this(maxValue1, maxValue2, maxValue3, 0, 1, 2);

Parameters:
maxValue1 - the maximum value for the first index
maxValue2 - the maximum value for the second index
maxValue3 - the maximum value for the third index

OnDemandHistogram3D

public OnDemandHistogram3D(int maxValue)
Creates a new object of this class with the argument as maximum value for all three index positions and the component values 0, 1, 2. Simply calls this(maxValue, maxValue, maxValue);

Parameters:
maxValue - the maximum value for all indexes
Method Detail

clear

public void clear()
Resets all counters to zero. As the Java VM's garbage collector is responsible for releasing unused memory, it is unclear when memory allocated for the histogram will be available again.

Specified by:
clear in interface Histogram3D

getEntry

public int getEntry(int index1,
                    int index2,
                    int index3)
             throws IllegalArgumentException
Returns counter for the argument color given by its red, green and blue intensity.

Specified by:
getEntry in interface Histogram3D
Parameters:
index1 - the first value of the index
index2 -
index3 -
Returns:
the counter value of the desired index
Throws:
IllegalArgumentException - this exception is thrown if the argument color is not in the valid interval, i.e., if at least one of the components is not from 0 .. max

getMaxValue

public int getMaxValue(int index)
                throws IllegalArgumentException
Description copied from interface: Histogram3D
Returns the maximum index value for one of the three indexes.

Specified by:
getMaxValue in interface Histogram3D
Throws:
IllegalArgumentException - if the index formed by the arguments is invalid

getNumUsedEntries

public int getNumUsedEntries()
Returns the number of entries in this histogram with a counter value of one or higher (in other words: the number of colors that are in use).

Specified by:
getNumUsedEntries in interface Histogram3D
Returns:
the number of unique colors

increaseEntry

public void increaseEntry(int red,
                          int green,
                          int blue)
                   throws IllegalArgumentException
Increases the counter for the color given by the arguments red, green and blue. This method could be implemented by the following code snippet:
  setEntry(red, green, blue, getEntry(red, green, blue) + 1);
 
However, this is not done to avoid slow-downs by accessing a counter value twice.

Specified by:
increaseEntry in interface Histogram3D
Parameters:
red - the red intensity of the color entry whose counter will be increased
green - the green intensity of the color entry whose counter will be increased
blue - the blue intensity of the color entry whose counter will be increased
Returns:
the counter value of the desired index
Throws:
IllegalArgumentException - if the argument color is not valid (minimum is 0, maximum is defined for each component independently)

setEntry

public void setEntry(int r,
                     int g,
                     int b,
                     int newValue)
              throws IllegalArgumentException
Sets one counter to a new value.

Specified by:
setEntry in interface Histogram3D
Parameters:
r - red component
g - green component
b - blue component
newValue - the new value for the counter
Throws:
IllegalArgumentException - if the components do not form a valid color

JIU 0.12.0 Homepage

Copyright © 2000, 2001, 2002, 2003, 2004 Marco Schmidt