samer@0
|
1 /*
|
samer@0
|
2 * IteratorImageSource.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.maths;
|
samer@0
|
13 import samer.tools.*;
|
samer@0
|
14 import java.awt.image.*;
|
samer@0
|
15
|
samer@0
|
16 /**
|
samer@0
|
17 This is an image source that gets its values
|
samer@0
|
18 from a Vec (vector) via its Vec.Iterator - ie,
|
samer@0
|
19 it does not need access to an array of value
|
samer@0
|
20 */
|
samer@0
|
21
|
samer@0
|
22 public class IteratorImageSource extends ImageSourceBase
|
samer@0
|
23 {
|
samer@0
|
24 Vec vec;
|
samer@0
|
25 byte [] buf;
|
samer@0
|
26
|
samer@0
|
27 public IteratorImageSource( Vec v) { this( v, v.size(), 1); }
|
samer@0
|
28 public IteratorImageSource( Vec v, int w, int h)
|
samer@0
|
29 {
|
samer@0
|
30 vec = v;
|
samer@0
|
31 width = w;
|
samer@0
|
32 height = h;
|
samer@0
|
33 buf = new byte[v.size()];
|
samer@0
|
34 }
|
samer@0
|
35
|
samer@0
|
36
|
samer@0
|
37 protected int getHints() {
|
samer@0
|
38 return ImageConsumer.TOPDOWNLEFTRIGHT
|
samer@0
|
39 | ImageConsumer.COMPLETESCANLINES
|
samer@0
|
40 | ImageConsumer.SINGLEPASS;
|
samer@0
|
41 }
|
samer@0
|
42
|
samer@0
|
43 protected void sendPixels(ImageConsumer ic)
|
samer@0
|
44 {
|
samer@0
|
45 Vec.Iterator it=vec.iterator();
|
samer@0
|
46
|
samer@0
|
47 for (int i=0; it.more(); i++) {
|
samer@0
|
48 buf[i] = (byte)map.clipInt(it.next());
|
samer@0
|
49 }
|
samer@0
|
50 ic.setPixels(0, 0, width, height, model, buf, 0, width);
|
samer@0
|
51 }
|
samer@0
|
52 }
|
samer@0
|
53
|