2020-11-13 12:10:19 +00:00
|
|
|
/*
|
2020-11-13 11:18:16 +00:00
|
|
|
|
2020-11-13 12:10:19 +00:00
|
|
|
PROCESSING file to read a raw rgb data file and display it
|
2021-02-26 11:10:27 +00:00
|
|
|
|
|
|
|
This would be a file created from the command: client.write(rgb, ARRAY_LENGTH);
|
2020-11-13 11:18:16 +00:00
|
|
|
|
2020-11-13 12:10:19 +00:00
|
|
|
Alanesq - 13Nov20
|
2020-11-13 11:18:16 +00:00
|
|
|
|
2020-11-13 12:10:19 +00:00
|
|
|
for info on coding with Processing see: https://thecodingtrain.com/
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------------------------------------------------- */
|
2020-11-13 11:18:16 +00:00
|
|
|
|
|
|
|
|
2020-11-13 12:10:19 +00:00
|
|
|
// General Settings
|
2020-11-13 11:59:37 +00:00
|
|
|
|
|
|
|
// image file to read (raw RGB)
|
2020-11-13 11:18:16 +00:00
|
|
|
String fileName = "q.rgb";
|
|
|
|
|
|
|
|
// Image resolution
|
|
|
|
int resX = 640;
|
|
|
|
int resY = 480;
|
|
|
|
|
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
// ----------------------------------------------------------
|
|
|
|
|
2020-11-13 12:10:19 +00:00
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
// Misc variables
|
|
|
|
|
|
|
|
byte[] rgbFile; // store for the file contents
|
2020-11-13 11:18:16 +00:00
|
|
|
|
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
// ----------------------------------------------------------
|
2020-11-13 11:18:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
// open the RGB file
|
2020-11-13 11:18:16 +00:00
|
|
|
rgbFile = loadBytes(fileName);
|
|
|
|
print(fileName + " file size = ");
|
|
|
|
println(rgbFile.length);
|
2020-11-13 15:26:43 +00:00
|
|
|
print("Drawing image");
|
2020-11-13 11:18:16 +00:00
|
|
|
|
2020-11-13 12:10:19 +00:00
|
|
|
size(640,480); // display screen size
|
2020-11-13 11:59:37 +00:00
|
|
|
background(0); // background colour of screen (0 = black)
|
2020-11-13 12:10:19 +00:00
|
|
|
noLoop(); // do not keep looping the draw procedure
|
2020-11-13 11:18:16 +00:00
|
|
|
|
|
|
|
} // setup
|
|
|
|
|
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
// ----------------------------------------------------------
|
2020-11-13 11:18:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
void draw() {
|
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
int xPos;
|
|
|
|
int yPos;
|
2020-11-13 12:10:19 +00:00
|
|
|
|
|
|
|
// work through the RGB file plotting each individual colour pixel on the screen
|
2020-11-13 11:18:16 +00:00
|
|
|
for(int i = 0; i < (rgbFile.length - 2); i+=3) {
|
2020-11-13 11:59:37 +00:00
|
|
|
// Calculate x and y location in image
|
|
|
|
xPos = (i / 3) % resX;
|
2020-11-13 15:26:43 +00:00
|
|
|
yPos = floor( (i / 3) / resX );
|
2020-11-13 11:59:37 +00:00
|
|
|
stroke(rgbFile[i+2] & 0xff,rgbFile[i+1] & 0xff,rgbFile[i+0] & 0xff);
|
2020-11-13 15:26:43 +00:00
|
|
|
point(xPos,yPos);
|
|
|
|
if ( (i % 5000) == 0 ) print("."); // show progress
|
2020-11-13 12:10:19 +00:00
|
|
|
}
|
2020-11-13 11:59:37 +00:00
|
|
|
|
2020-11-13 11:18:16 +00:00
|
|
|
println("Finished");
|
|
|
|
|
|
|
|
} // draw
|
|
|
|
|
|
|
|
|
2020-11-13 11:59:37 +00:00
|
|
|
// ----------------------------------------------------------
|
|
|
|
// end
|