-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdisplayRGB.pde
75 lines (43 loc) · 1.68 KB
/
displayRGB.pde
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
/*
PROCESSING file to read a raw rgb data file and display it
This would be a file created from the command: client.write(rgb, ARRAY_LENGTH);
Alanesq - 13Nov20
for info on coding with Processing see: https://thecodingtrain.com/
// ---------------------------------------------------------- */
// General Settings
// image file to read (raw RGB)
String fileName = "q.rgb";
// Image resolution
int resX = 640;
int resY = 480;
// ----------------------------------------------------------
// Misc variables
byte[] rgbFile; // store for the file contents
// ----------------------------------------------------------
void setup() {
// open the RGB file
rgbFile = loadBytes(fileName);
print(fileName + " file size = ");
println(rgbFile.length);
print("Drawing image");
size(640,480); // display screen size
background(0); // background colour of screen (0 = black)
noLoop(); // do not keep looping the draw procedure
} // setup
// ----------------------------------------------------------
void draw() {
int xPos;
int yPos;
// work through the RGB file plotting each individual colour pixel on the screen
for(int i = 0; i < (rgbFile.length - 2); i+=3) {
// Calculate x and y location in image
xPos = (i / 3) % resX;
yPos = floor( (i / 3) / resX );
stroke(rgbFile[i+2] & 0xff,rgbFile[i+1] & 0xff,rgbFile[i+0] & 0xff);
point(xPos,yPos);
if ( (i % 5000) == 0 ) print("."); // show progress
}
println("Finished");
} // draw
// ----------------------------------------------------------
// end