38209decac1d83ed758a98e58f1bd16868f985e7
Christian Heimke BlinkenSimJava v.0.1 (2004-...

Christian Heimke authored 12 years ago

1) public class Frame
2) {
3)   private int height;
4)   private int width;
5)   private int channels;
6)   private byte[][][] data;
7) 
8)   Frame( int height, int width, int channels )
9)   {
10)     this.height = height;
11)     this.width = width;
12)     this.channels = channels;
13)     data = new byte[height][width][channels];
14)   }
15) 
16)   Frame( Frame frame )
17)   {
18)     height = frame.height;
19)     width = frame.width;
20)     channels = frame.channels;
21)     data = (byte[][][])frame.data.clone( );
22)   }
23) 
24)   public void setData( int maxval, byte[] rawData, int startIndex )
25)   {
26)     int i, h, w, c;
27)     for( i = startIndex, h = 0; h < height; h++ )
28)       for( w = 0; w < width; w++ )
29)         for( c = 0; c < channels; c++, i++ )
30)           if( rawData[i] > maxval )
31)             data[h][w][c] = (byte)255;
32)           else
33)             data[h][w][c] = (byte)((rawData[i] & 0xFF) * 255 / maxval);
34)   }
35) 
36)   public int getHeight( )
37)   {
38)     return height;
39)   }
40) 
41)   public int getWidth( )
42)   {
43)     return width;
44)   }
45) 
46)   public int getChannels( )
47)   {
48)     return channels;
49)   }
50) 
51)   public byte[][][] getData( )
52)   {
53)     return data;
54)   }
55) 
Christian Heimke BlinkenSimJava v.0.1.1 (200...

Christian Heimke authored 12 years ago

56)   public void resize( int height, int width, int channels )
57)   {
58)     byte[][][] data;
59)     int y, x, c;
60)     int emptyY, emptyX, skipY, skipX, rangeY, rangeX, val;
61) 
62)     data = new byte[height][width][channels];
63)     for( y = 0; y < height; y++ )
64)       for( x = 0; x < width; x++ )
65)         for( c = 0; c < channels; c++ )
66)           data[y][x][c] = 0;
67) 
68)     if( height > this.height )
69)     {
70)       emptyY = (height - this.height) / 2; 
71)       skipY = 0;
72)       rangeY = this.height;
73)     }
74)     else
75)     {
76)       emptyY = 0;
77)       skipY = (this.height - height) / 2;
78)       rangeY = height;
79)     }
80)     if( width > this.width )
81)     {
82)       emptyX = (width - this.width) / 2; 
83)       skipX = 0;
84)       rangeX = this.width;
85)     }
86)     else
87)     {
88)       emptyX = 0;
89)       skipX = (this.width - width) / 2;
90)       rangeX = width;
91)     }
92) 
93)     for( y = 0; y < rangeY; y++ )
94)     {
95)       for( x = 0; x < rangeX; x++ )
96)       {
97)         val = 0;
98)         for( c = 0; c < this.channels; c++ )
99)           val += this.data[skipY + y][skipX + x][c] & 0xFF;
100)         val /= this.channels;
101)         for( c = 0; c < channels; c++ )
102)           data[emptyY + y][emptyX + x][c] = (byte)val;
103)       }
104)     }
105) 
106)     this.height = height;
107)     this.width = width;
108)     this.channels = channels;
109)     this.data = data;
110)   }
111)