summaryrefslogtreecommitdiff
path: root/java/ImageProcessing/framework/ImageByteCounter.java
blob: 9b238c02b2286ca1ad6dc2828afec588dd3892e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package imaging.framework;

import java.io.*;
import java.awt.*;
import JACE.OS.*;

public class ImageByteCounter
{
  public ImageByteCounter (String title, Image image)
  {
    this.image_ = image;
  }

  public int count ()
  {
    indicator_ = new StatusIndicator ("");
    int length = 0;
    try
      {
	//	GIFOutputStream ostream = new GIFOutputStream (statusIndicator_);
	GIFOutputStream ostream = new GIFOutputStream (null);
	GifEncoder encoder = new GifEncoder (this.image_, ostream);
	encoder.encode ();

	length = ostream.count ();
	System.out.println ("send: " + length);
      }
    catch (IOException e)
      {
	ACE.ERROR ("Exception generating gif");
      }
    //    indicator_.dispose ();
    return length;
  }

  Image image_ = null;
  StatusIndicator indicator_ = null;
}

class GIFOutputStream extends OutputStream
{
  public GIFOutputStream (StatusIndicator indicator)
  {
    super ();
    this.indicator_ = indicator;
  }

  public synchronized void write (int b) throws IOException 
    {
      bytesWritten_++;
      if (this.indicator_ != null)
	this.indicator_.update (bytesWritten_);
    }

  public synchronized void write (byte buf[]) throws IOException 
    {
      bytesWritten_ += buf.length;
      if (this.indicator_ != null)
	this.indicator_.update (bytesWritten_);
    }

  public synchronized void write (byte buf[], int offset, int length) throws IOException 
    {
      bytesWritten_ += length;
      if (this.indicator_ != null)
	this.indicator_.update (bytesWritten_);
    }

  public int count ()
    {
      return this.bytesWritten_;
    }

  private int bytesWritten_ = 0;
  private StatusIndicator indicator_ = null;
}