View Full Version : running the CPU and GPU on a Raspberry pi.(Searching..) and I ran across this.

December 28th, 2014, 20:32
In the spirit of leaving a trail of breadcrumbs through the forest, I�m going to run through some of what I learned along the way.


Excellent article and has links to even more interesting documentation for the pi.

As a side note or tip for running mono C# code on raspberry pi.

static Object FileLock = new Object();
static void Main()
//Get the Directory This is executing from example "WorkFolder\XmlData\..."
System.IO.DirectoryInfo workingDirectory = new System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
//## requirement of being in the directory where the xml files to be parsed are.##
//read all the ProductData*.xml files in the current directory
System.IO.FileInfo[] xmlFiles = workingDirectory.GetFiles("ProductData*.xml";
//Create A thread Array equal to the number of files to parse
//Create a thread for each file found to parse in parallel
for (int i = 0; i < xmlFiles.Length - 1; i++) {
System.Threading.Thread T = new System.Threading.Thread(() => thread_parser(xmlFiles[I].FullName));

This will not work if the number of files and there sizes exceeds the memory Threshold of the device.
There are a few ways to accomplish this.
Use a global counter and to only allow a certain number of threads to be running in the code.
Remove the threading part all together and go for a function loop on thread_parser.
Implement a lock in thread_parser to only allow 1 thread.

January 5th, 2015, 18:46
Still reversing that esoteric stuff huh? Good on ya, keep it up
Sorry, we still haven't banned you after all these years

January 8th, 2015, 13:31
Nah, just got a pi for Christmas and jumped into what I thought was interesting in the community and wanted to see if I could write code to run on the GPU of the pi.

The code is the head of the implementation to parse GS1 1worldsync product data from manufacturers into NCR Power Menu for a distributor.(boring shit right there..)

Towards the last comment:
Self made shackles work best for me, breaking out of them is really hard and time consuming unlike anything you or others could have done to me.

This is supposed to be off-topic so I should have avoided your question and just rambled on..

January 9th, 2015, 20:50
I dont see any way I could ban him.

Anyway, interesting stuff regarding pi.


January 30th, 2015, 12:29

http://nullprogram.com/ more in depth usage examples

Enjoy the reading, any further information or usage experimentation notes would be greatly appreciated if a link was posted here.

January 30th, 2015, 12:56
So taking a idea from stenography and encoding 1 picture inside another using the least significant byte of a pixels RGB...So this is all well and good when combining 2 images, but what if I don't want to embed a image into another image. what if I want to embed Ascii into a image. I suppose the same method would work, read a the image data for RGBA, find the least significant byte and overwrite it with desired code for 1 value. But what if we don't care who see's my modifications to the image, this opens up RGB for storage in the full scale. To accomplish this I take image and load it into a canvas with image.width - 2 and image.height -2 to allow for a 1 pixel border region for data. I then directly associated ascii keycodes to color codes and write the desired text to the image. 1 of the most annoying things I ran across while implementing this functionality was CORS(cross origin resource sharing policy) and SORS(Same origin resource sharing Policy) which describe a set of permissions for editing and modifying content downloaded from the web.It seems chrome chokes on this much more then even IE, firefox or opera.

The next stage of this is taking the 2d data fragments and storing them into a 3D cylinders inner surface with multiple viewpoints set onto a line that runs up the middle of the cylinder. IE each viewpoint has a range of accessible data located next to that view point to which I can send a query to retrieve the data in question via reducing the overall space the query has to look through.

January 30th, 2015, 23:25
If you're into transmogrifying files, you might be interested or already seen some of these examples of binary polyglots.

https://code.google.com/p/corkami/ (under Binary Files)

A few of the polyglots are actual issues of the International Journal of Proof-of-Concept or Get The Fuck Out (PoC||GTFO)
(google 'pocgtfo' for some analysis of how to manipulate the file contents)

Issue 03 is, at the same time, several file formats: PDF/ZIP/JPG/Audio (raw AFSK)/PNG (encrypted with AES)
Issue 04: TrueCrypt, PDF , ZIP polyglots
Issue 05: Flash, Iso, PDF, ZIP polyglots

Pretty amazing stuff. I found that Foxit might open the pdf format if Adobe doesn't, and 7-zip or or 'nix unzip could handle it when the extension is changed to .zip.

Would be interested in seeing your ascii-in-jpg if you get a poc.


February 1st, 2015, 19:43
Code is written in Javascript, and I have posted it to codereview.stackexchange.com a few times to get idea's on improvements for my code.


<!DOCTYPE html>

<canvas id="myCanvas" width="200" height="200" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<p id="Start"></p>
<p id="End"></p>
<div id="img_store" style="display:none"></div>
<textarea id="WriteThis"></textarea>
<button onclick="loadImageAndWrite('download.png');">Load Image and Write Text</button>
var ColorizeData = function(canvas) {
this.canvas = canvas;
this.charToDecTable = {};
this.decToCharTable = {};
ColorizeData.prototype.initTables = function(){
var charDecPairs = [
[" ","09"],
[" ","32"],

for(i=0; i < charDecPairs.length; i++)
var pair = charDecPairs[I];
var cchar = pair[0];
var dec = pair[1];
this.charToDecTable[cchar] = dec;
this.decToCharTable[hex] = cchar;
ColorizeData.prototype.textToColor = function(arg){
var context = this.canvas.getContext("2d";
var upDown = 1;
var upDown1 = 1;
var leftRight = 0;
var cindex = 0;
arg = arg.toLowerCase();
if(cindex + 1 < arg.length)
if(cindex + 2 < arg.length)
context.fillStyle = rgbToHex(this.charToDecTable[arg.charAt(cindex)],this.charToDecTable[arg.charAt(cindex+1)],this.charToDecTable[arg.charAt(cindex+2)]);
cindex += 3;
context.fillStyle = rgbToHex(this.charToDecTable[prop], this.charToDecTable[arg.charAt(cindex+1)],0);
cindex += 2;
context.fillStyle = rgbToHex(this.charToDecTable[prop],0, 0);
cindex +=1;
if(context.fillStyle != "#000000"

if(cindex/3 < this.canvas.width) {
context.fillRect(leftRight, 0, 1, 1);
leftRight += 1;
if(upDown < this.canvas.height) {
upDown += 1;
if(upDown1 < this.canvas.height) {
leftRight = 0
upDown1 +=1
if(leftRight < this.canvas.width -2) {
leftRight+= 1;
}while(cindex < arg.length)
function componentToHex(c) {
var hex = Number(c).toString(16);
return hex.length == 1 ? "0" + hex : hex;
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
ColorizeData.prototype.colorToText = function(arg)
var text = "";
var context = this.canvas.getContext("2d";
var size = 0;
for(var index = 0;index<4;index++)
switch (index)
case 0:
imgData = context.getImageData(0,0, this.canvas.width,1);
size = this.canvas.width;
case 1:
imgData = context.getImageData(this.canvas.width - 1,1, 1,this.canvas.height - 1);
size = this.canvas.height - 1;
case 2:
imgData = context.getImageData(0,1, 1,this.canvas.height - 1);
size = this.canvas.height - 1;
imgData = context.getImageData(1,this.canvas.height -1, this.canvas.width-2, 1);
size = this.canvas.width - 2;
for(var i = 0; i < size; i += 4) {
//hide this pixel.
imgData.data[i + 3] = 0;
//check red for 0
if(imgData.data[i + 0] != 0)
text += this.decToCharTable[imgData.data[i + 0]];
//check green for 0
if(imgData.data[i + 1] != 0)
text += this.decToCharTable[imgData.data[i + 1]];
//check blue for 0
if(imgData.data[i + 2] != 0)
text += this.decToCharTable[imgData.data[i + 2]];

case 0:
case 1:
context.putImageData(imgData,this.canvas.width - 1,1);
case 2:
case 3:
context.putImageData(imgData,1,this.canvas.height -1);
document.getElementById(arg).innerText = text;
ColorizeData.prototype.loadImage = function(arg) {
var canvas = document.getElementById("myCanvas";
var context = canvas.getContext("2d";
var img = new Image();
img.onload = function () {
context.drawImage(img, 0, 0, 200, 200);
img.src = arg;
ColorizeData.prototype.loadImageAndRead = function(arg) {
var canvas = document.getElementById("myCanvas";
var context = canvas.getContext("2d";
var img = new Image();
img.onload = function () {
context.drawImage(img, 0, 0, 200, 200);
img.src = arg;
ColorizeData.prototype.loadImageAndWrite = function(arg) {
var canvas = document.getElementById("myCanvas";
var context = canvas.getContext("2d";
var img = new Image();
img.onload = function () {
context.drawImage(img, 0, 0, 200, 200);
img.src = arg;

ColorizeData.prototype.clear = function() {
var context = this.canvas.getContext("2d";
context.clearRect(0,0,this.canvas.width, this.canvas.height);
var Colorizer = new ColorizeData(document.getElementById("myCanvas");
Colorizer.textToColor("Testing 123...";


Example of (1st) generation image is attached. This code is 3rd generation, translation tables changed so it wont work for this image.
1st generation code is here.

Thanks for all the decent reading material.

February 1st, 2015, 20:01
I want to learn, even while I am dying.

http://stackoverflow.com/questions/28441774/i-need-help-implementing-this-algorithm-for-the-1worldsync-dam-api ("http://stackoverflow.com/questions/28441774/i-need-help-implementing-this-algorithm-for-the-1worldsync-dam-api")

December 26th, 2015, 10:48
I have more than the arts in mind kayaker.

I plan to use this concept to reduce http traffic on the web, by embedding content into images and have the client parse the images with javascript.

(Re)think my idea's please.

December 26th, 2015, 14:21


I want to learn, even while I am dying.


are you still stuck on the damapi ??
iirc you opened another thread here on the same damapi
if you are struck use this powershell script

i don't know if it works with your data or not in the link but it works with the damapi pdf example correctly


$a = New-Object System.Security.Cryptography.HMACSHA256
$a.key = [Text.Encoding]::ASCII.GetBytes($args[1])

run as


:\>powershell -f hmack.ps1 "/V2/assets?app_id=12345& ipGLN=1234567891234&senderGLN=1234567891234&TIMESTAMP=2012-12-06T13:08:02Z" 6

the input and output can be verified from page 36 of the damapi.pdf (retrieved around the date of the other damapi thread)

December 27th, 2015, 02:05
That's a pretty small implementation. But I finished it all. got it all working synchronously and then there like ok use it to upload 20k images.. it was to slow so I looked into speed it up with asynchronous tasks and was unable to get it to work properly so I reverted to type and wrote a html page with a javascript multi drop file handler for image files, made the load code wrap in a xml file with some predefined variables, zipped them up and sent them on as2 connection. :] But thank you for the effort good citizen. I appreciate it.

On a side note I have been thinking about something, that you might be able to help me with, has to do with javascript.

But I was wondering, if an idea I had was feasible, from my laymen perspective could 2 RGBA webgl pixels be combined to form a register?Could we define 0 as black or white and perform shader operations on the set color values? I mean couldn't we colorize a pair of RGBA 4 bytes each into a qword length buffer and store data in registers, and compare how far away from black or white it is to determine the value of it. The pixel paired registers could then be used to process instructions from some source.
I should patent the ideas I have, but I choose to just give them to the winds...

December 27th, 2015, 11:30
well to be frank i have no idea my JavaScript know-how is very limited
just because i wanted to get into my head something before i can make a half or quarter sensisible reply i followed into the
link (first generation thingy) a brief glance tell me you want to make some thing like this


Add-Type -AssemblyName *sys*forms*
Add-Type -AssemblyName System.Drawing
$fg=($f=New-Object Windows.Forms.Form).createGraphics()
$f.Width=350;$f.Height=70;$f.Text="Banme Games"
"y"="#306050";"z"="#408070";" "="#50a090";"-"="#60c0b0";"="="#70e0d0";"0"="#800000";
$in = "hello ban me @ 42 d0wnning greet!";3024
$i = $j = $k = 0;
$p = @(0..50);
$in.ToCharArray() | %{
$p[$j++] = New-Object Drawing.Solidbrush ($table.Item($_.tostring()))
} $f.ShowDialog() > null

December 27th, 2015, 12:48
Excellent stuff this what looks to be javascript, but probably is powershell.. excellently small. but no, I meant in a canvas with a pixel and a fragment shader.

This link might help in clarifying, what I am talking about.


I also heard about storing data in images even if they are resized? Is there further reading material for this as well? I need to be less of a librarian or something.. sorry.

Also greetz to you blabberer, much respect for the truths.

001010 0000a0 005090 005090 0080f0 50a090 000040 801000 000020 000040 00004 0000a0 00b060 0000a0 00b060.

and yes blabber png is the extension I misspoke before.but it doesn't matter, because you don't need to load and render the image on the canvas, because the canvas is the image. That's some "there is no spoon" shit right there if I ever saw it..

December 29th, 2015, 11:14
That is what I want to do, and I would like to do that in the gpu's renderings.So Not Image processing,processing in a image, emulated but realtime rendered. executing the input and giving a output instruction by instruction on something in that image and 'could' be rendered in a web page.

scrape a concept™ from UNU project

Maybe the question you ask yourself, is why the fuck does this bloke want to do any of this, what is his end goal, I have no fucking idea, but I do try and explore things and ideas differently because I wish to have my own. Even if it is coupling the many disparate and unrelated fields of my interests together.

December 30th, 2015, 11:49
Took me a bit to find the tools necessary to understand, and go forth with my own understanding. But I found a i8080 processor emulator that plays space invader.
There are reasons, I chose these, and low that they are limited, in their limitation(s) there is always a maximum to be achieved with careful rethought after the initial implementation.

Like for instance a dynamically resizable register length as long as 'space' is available., like implementing instructions that are complemented by the parallelism involved in graphics processing in the GPU.


So then I thought to myself. Well that's cool but what about a disassembler. found one.

https://github.com/begoon/i8080-js - disasm

I now have some grasp of the concepts and patterns involved. So On to the next part reimplementing the primitives, with webgl.

So what do I mean by the primitives? I mean the cpu embedded screen, IO,Memory, instructions registers flags and so forth, viewed totally.

I plan to ferret this one out..

I do this because, in my view the scene never died. It is in all of us, and in the time machine of the web.

So in the spirit described hence I come here; I am going behave in a respectable manner, and try and re-ignite community thinking, as group activity, and push for discourse.

December 30th, 2015, 17:08
Well like that doesn't sound interesting. A couple of things that you've probably come across before that might help in your thought processes if not in the actual implementation:

ODA Online Disassembler. According to the blog, it's built on libbfd and libopcodes (part of binutils) and recognizes PE, ELF and Mach-O files. I can't tell if your JS version supports all OS formats. Not sure if that fits in with your WebGL ideas but wanted to mention it.


For the emulation, I immediately thought of Ida-x86emu. Again it may not be directly relevant but there is source code which might help with the implementation of your JS version.


For sure keep us updated on whether this crazy scheme will work


December 30th, 2015, 17:51
I have heard of ODA, and actually suggested it as a tool to disassemble hex, but it is in the raw and has no idea of the system behind it, which could lead to data being interpreted as instructions..

I understand that subsetting to javascript and even further than that to webgl, limits the portability of the implementation, but as blabberer demonstrated and was once a requirement to the strains, reimplementation of ideas is easy if the tools are available to you and you have some want to seek.

My thought is to start small, and work my way up, like this arcade game, then maybe x86.. But I will take a look, and thank you for your interest.


January 4th, 2016, 17:35
[Originally Posted by "Kayaker"]I can't tell if your JS version supports all OS formats.

Ok so reconsidering this specific part, I have come to agree with you on this respect. I think that doing this in C++ would be more beneficial. Especially with the example planes on the internet. The C++ OpenGL pot is much bigger then the recent WebGL developments.

Next up is how to emulate a CPU in OpenGL 3.2. I do not want to make anything that looks like a CPU visually speaking. I want to use opengl functionalities to implement the functionality of the 8080.

So my question(s) to myself are; "What are the some way(s) to attack this problem?", and "What tactics did others use to solve similar problems to this one?" I will try and answer these questions and form some kinda of similar functionality mapping table between the js 8080 version and C++ opengl. I welcome everyone's input, and would gladly include your name and or code into a final design decision.