<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">public class Frame
{
  private int height;
  private int width;
  private int channels;
  private byte[][][] data;

  Frame( int height, int width, int channels )
  {
    this.height = height;
    this.width = width;
    this.channels = channels;
    data = new byte[height][width][channels];
  }

  Frame( Frame frame )
  {
    height = frame.height;
    width = frame.width;
    channels = frame.channels;
    data = (byte[][][])frame.data.clone( );
  }

  public void setData( int maxval, byte[] rawData, int startIndex )
  {
    int i, h, w, c;
    for( i = startIndex, h = 0; h &lt; height; h++ )
      for( w = 0; w &lt; width; w++ )
        for( c = 0; c &lt; channels; c++, i++ )
          if( rawData[i] &gt; maxval )
            data[h][w][c] = (byte)255;
          else
            data[h][w][c] = (byte)((rawData[i] &amp; 0xFF) * 255 / maxval);
  }

  public int getHeight( )
  {
    return height;
  }

  public int getWidth( )
  {
    return width;
  }

  public int getChannels( )
  {
    return channels;
  }

  public byte[][][] getData( )
  {
    return data;
  }

  public void resize( int height, int width, int channels )
  {
    byte[][][] data;
    int y, x, c;
    int emptyY, emptyX, skipY, skipX, rangeY, rangeX, val;

    data = new byte[height][width][channels];
    for( y = 0; y &lt; height; y++ )
      for( x = 0; x &lt; width; x++ )
        for( c = 0; c &lt; channels; c++ )
          data[y][x][c] = 0;

    if( height &gt; this.height )
    {
      emptyY = (height - this.height) / 2; 
      skipY = 0;
      rangeY = this.height;
    }
    else
    {
      emptyY = 0;
      skipY = (this.height - height) / 2;
      rangeY = height;
    }
    if( width &gt; this.width )
    {
      emptyX = (width - this.width) / 2; 
      skipX = 0;
      rangeX = this.width;
    }
    else
    {
      emptyX = 0;
      skipX = (this.width - width) / 2;
      rangeX = width;
    }

    for( y = 0; y &lt; rangeY; y++ )
    {
      for( x = 0; x &lt; rangeX; x++ )
      {
        val = 0;
        for( c = 0; c &lt; this.channels; c++ )
          val += this.data[skipY + y][skipX + x][c] &amp; 0xFF;
        val /= this.channels;
        for( c = 0; c &lt; channels; c++ )
          data[emptyY + y][emptyX + x][c] = (byte)val;
      }
    }

    this.height = height;
    this.width = width;
    this.channels = channels;
    this.data = data;
  }

  public String toString( )
  {
    String str = "";
    int h, w, c, val;
    for( h = 0; h &lt; height; h++ )
    {
      for( w = 0; w &lt; width; w++ )
      {
        val = 0;
        for( val = 0, c = 0; c &lt; channels; c++ )
          val += (data[h][w][c] &amp; 0xFF);
        val /= channels * 32;
        str = str + " -+*%#&amp;@".substring( val, val + 1); 
      }
      str = str + "\n";
    }
    return str;
  }
}
</pre></body></html>