Permalink
Browse files

pushing to github

  • Loading branch information...
0 parents commit a6ab8cd00aac793d4e42ce1825c16d78ba1ed1dd @pnitsch pnitsch committed Jul 23, 2012
0 README.md
No changes.
BIN copy_to_data/ofxAsciiArt/images/8x8.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 copy_to_data/ofxAsciiArt/shaders/ascii.frag
@@ -0,0 +1,130 @@
+#version 120
+
+uniform sampler2D inputTexture;
+uniform sampler2D asciiTexture;
+uniform sampler2D hashTexture;
+uniform vec2 imageSize;
+uniform vec2 canvasSize;
+
+varying float mode;
+varying float contrast;
+varying float depth;
+
+const float charMapSize = 2048.0;
+const float numChars = 256.0;
+const vec2 fontSize = vec2(8.0, 8.0);
+const vec2 hashSize = vec2(256.0, 256.0);
+
+vec4 pix = vec4(0.0, 0.0, 0.0, 1.0);
+vec2 ratio;
+float colorDepth;
+
+float packColor(vec4 color) {
+ return (color.r + (color.g*256.0) + (color.b*256.0*256.0) + (color.a*256.0*256.0*256.0));
+}
+
+vec4 contrastPix(float _x, float _y, float _contrast) {
+ float factor = (259.0 * (_contrast + 255.0)) / (255.0 * (259.0 - _contrast));
+ vec4 pix = texture2D(inputTexture, vec2(_x, _y));
+
+ pix.r = (factor * ((pix.r*255.0) - 128.0) + 128.0)/255.0;
+ pix.g = (factor * ((pix.g*255.0) - 128.0) + 128.0)/255.0;
+ pix.b = (factor * ((pix.b*255.0) - 128.0) + 128.0)/255.0;
+
+ return pix;
+}
+
+vec4 analyseQuads(vec2 _offset) {
+
+ // TODO: Clear these magic numbers.
+ float i_x = 1.0/(canvasSize.x*0.62);
+ float i_y = 1.0/(canvasSize.y*0.93);
+
+ float h_fs_x = (fontSize.x/2.0)/canvasSize.x;
+ float h_fs_y = (fontSize.y/2.0)/canvasSize.y;
+
+ vec4 lut_pix;
+ vec4 t_pix;
+ vec4 key = vec4(0.0, 0.0, 0.0, 0.0);
+
+ for(float y=_offset.y; y<_offset.y+h_fs_y; y+=i_y) {
+ for(float x=_offset.x; x<_offset.x+h_fs_x; x+=i_x) {
+ t_pix = vec4(0.0, 0.0, 0.0, 1.0);
+
+ lut_pix = contrastPix(x, y, contrast);
+ key.r += lut_pix.g;
+ lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
+ t_pix += lut_pix;
+
+ lut_pix = contrastPix(x+h_fs_x, y, contrast);
+ key.g += lut_pix.g;
+ lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
+ t_pix += lut_pix;
+
+ lut_pix = contrastPix(x, y+h_fs_y, contrast);
+ key.b += lut_pix.g;
+ lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
+ t_pix += lut_pix;
+
+ lut_pix = contrastPix(x+h_fs_x, y+h_fs_y, contrast);
+ key.a += lut_pix.g;
+ lut_pix.r = (floor((lut_pix.r*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.g = (floor((lut_pix.g*255.0)/colorDepth)*colorDepth)/255.0;
+ lut_pix.b = (floor((lut_pix.b*255.0)/colorDepth)*colorDepth)/255.0;
+ t_pix += lut_pix;
+
+ t_pix /= 4.0;
+ pix += t_pix;
+ }
+ }
+
+ pix /= fontSize.x+fontSize.y;
+ key = floor(key)/16.0;
+
+ return key;
+}
+
+void main()
+{
+ int m = int(mode);
+ colorDepth = 255.0/depth;
+
+ ivec2 ioffset = ivec2(gl_FragCoord.xy/fontSize.xy);
+ ioffset *= ivec2(fontSize.xy);
+ vec2 offset = vec2(ioffset);
+ offset /= canvasSize;
+
+ vec4 hashKey = analyseQuads(offset);
+ float index = packColor( hashKey )/256.0;
+
+ float hash_x = mod(floor(index), hashSize.x);
+ float hash_y = (index-hash_x)/hashSize.x;
+
+ vec4 char_pix = texture2D(hashTexture, vec2(hash_x/255.0, hash_y/255.0));
+ float char = floor((char_pix.g)*255.0);
+
+ vec2 pos = mod(gl_FragCoord.xy, fontSize.xy);
+ pos = pos / vec2(fontSize.x*numChars, fontSize.y);
+ pos.x += ((char*fontSize.x)/charMapSize);
+
+ vec4 ascii_pix = vec4(texture2D(asciiTexture, pos).rgb, 1.0);
+
+ if(ascii_pix.r > 0.0) {
+ if(m==1) {
+ ascii_pix.rgb = pix.rgb;
+ } else if(m==2) {
+ ascii_pix.rgb = vec3(pix.g*0.1, pix.g, pix.g*0.1);
+ } else if(m==3) {
+ float gray = (pix.r+pix.g+pix.b)/3.0;
+ ascii_pix.rgb = vec3(gray);
+ }
+ }
+
+ gl_FragColor = ascii_pix;
+}
18 copy_to_data/ofxAsciiArt/shaders/ascii.vert
@@ -0,0 +1,18 @@
+#version 120
+
+attribute float a_mode;
+attribute float a_contrast;
+attribute float a_depth;
+
+varying vec2 texCoord;
+varying float mode;
+varying float contrast;
+varying float depth;
+
+void main()
+{
+ mode = a_mode;
+ contrast = a_contrast;
+ depth = a_depth;
+ gl_Position = ftransform();
+}
50 example/src/gui/ofBaseGui.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include "ofxXmlSettings.h"
+#include "ofConstants.h"
+
+const ofColor
+headerBackgroundColor(64),
+backgroundColor(0),
+textColor(255),
+fillColor(128);
+
+const int textPadding = 4;
+const int defaultWidth = 200;
+const int defaultHeight = 16;
+
+class ofBaseGui{
+public:
+ ofBaseGui(){
+ bGuiActive = false;
+ }
+
+ virtual void mouseMoved(ofMouseEventArgs & args) = 0;
+ virtual void mousePressed(ofMouseEventArgs & args) = 0;
+ virtual void mouseDragged(ofMouseEventArgs & args) = 0;
+ virtual void mouseReleased(ofMouseEventArgs & args) = 0;
+
+ virtual void setValue(float mx, float my, bool bCheckBounds) = 0;
+ virtual void draw() = 0;
+
+ void saveToFile(string filename) {
+ ofxXmlSettings xml;
+ xml.loadFile(filename);
+ saveToXml(xml);
+ xml.saveFile(filename);
+ }
+
+ void loadFromFile(string filename) {
+ ofxXmlSettings xml;
+ xml.loadFile(filename);
+ loadFromXml(xml);
+ }
+
+ virtual void saveToXml(ofxXmlSettings& xml) = 0;
+ virtual void loadFromXml(ofxXmlSettings& xml) = 0;
+
+ string name;
+ unsigned long currentFrame;
+ ofRectangle b;
+ bool bGuiActive;
+};
5 example/src/gui/ofGui.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "ofToggle.h"
+#include "ofSlider.h"
+#include "ofPanel.h"
232 example/src/gui/ofPanel.h
@@ -0,0 +1,232 @@
+#pragma once
+
+#include "ofBaseGui.h"
+#include "ofConstants.h"
+#include "ofxXmlSettings.h"
+
+inline string saveStencilToHex(ofImage& img) {
+ stringstream strm;
+ int width = img.getWidth();
+ int height = img.getHeight();
+ int n = width * height;
+ unsigned char cur = 0;
+ int shift = 0;
+ strm << "{";
+ for(int i = 0; i < n;) {
+ if(img.getPixels()[i * 4 + 3] > 0) {
+ cur |= 1 << shift;
+ }
+ i++;
+ if(i % 8 == 0) {
+ strm << "0x" << hex << (unsigned int) cur;
+ cur = 0;
+ shift = 0;
+ if(i < n) {
+ strm << ",";
+ }
+ } else {
+ shift++;
+ }
+ }
+ strm << "}";
+ return strm.str();
+}
+
+inline void loadStencilFromHex(ofImage& img, unsigned char* data) {
+ int width = img.getWidth();
+ int height = img.getHeight();
+ int i = 0;
+ ofColor on(255, 255);
+ ofColor off(255, 0);
+ for(int y = 0; y < height; y++) {
+ for(int x = 0; x < width; x++) {
+ int shift = i % 8;
+ int offset = i / 8;
+ bool cur = (data[offset] >> shift) & 1;
+ img.setColor(x, y, cur ? on : off);
+ i++;
+ }
+ }
+ img.update();
+}
+
+class ofPanel : public ofBaseGui{
+public:
+ virtual ~ofPanel(){
+ ofUnregisterMouseEvents(this);
+ }
+
+ void setup(float x = 10, float y = 10) {
+ setup("", x, y);
+ }
+
+ void setup(string collectionName, float x = 10, float y = 10){
+ name = collectionName;
+ b.x = x;
+ b.y = y;
+ header = defaultHeight;
+ spacing = 1;
+ currentY = header + spacing;
+ b.width = defaultWidth;
+ b.height = 100; // weird to start out with something arbitrary like this
+ filename = "settings.xml";
+ ofRegisterMouseEvents(this);
+
+ unsigned char loadIconData[] = {0x38,0x88,0xa,0x6,0x7e,0x60,0x50,0x11,0x1c};
+ unsigned char saveIconData[] = {0xff,0x4a,0x95,0xea,0x15,0xa8,0x57,0xa9,0x7f};
+ loadIcon.allocate(9, 8, OF_IMAGE_COLOR_ALPHA);
+ saveIcon.allocate(9, 8, OF_IMAGE_COLOR_ALPHA);
+ loadStencilFromHex(loadIcon, loadIconData);
+ loadStencilFromHex(saveIcon, saveIconData);
+ int iconSpacing = 6;
+ loadBox.x = b.width - (loadIcon.getWidth() + saveIcon.getWidth() + iconSpacing + textPadding);
+ loadBox.y = header / 2 - loadIcon.getHeight() / 2;
+ loadBox.width = loadIcon.getWidth();
+ loadBox.height = loadIcon.getHeight();
+ saveBox.set(loadBox);
+ saveBox.x += loadIcon.getWidth() + iconSpacing;
+ }
+
+ virtual void saveToXml(ofxXmlSettings& xml) {
+ for(int i = 0; i < collection.size(); i++){
+ collection[i]->saveToXml(xml);
+ }
+ }
+
+ virtual void loadFromXml(ofxXmlSettings& xml) {
+ for(int i = 0; i < collection.size(); i++){
+ collection[i]->loadFromXml(xml);
+ }
+ }
+
+ void add(ofBaseGui * element){
+ collection.push_back( element );
+
+ element->b.y = currentY;
+ element->b.x = 0;
+ currentY += element->b.height + spacing;
+
+ if( currentY >= b.height ){
+ b.height += 40;
+ }
+ }
+
+ void clear(){
+ collection.clear();
+ }
+
+ virtual void mouseMoved(ofMouseEventArgs & args){
+ ofMouseEventArgs a = args;
+ a.x -= b.x;
+ a.y -= b.y;
+ for(int i = 0; i < collection.size(); i++){
+ collection[i]->mouseMoved(a);
+ }
+ }
+
+ virtual void mousePressed(ofMouseEventArgs & args){
+ setValue(args.x, args.y, true);
+ if( bGuiActive ){
+ ofMouseEventArgs a = args;
+ a.x -= b.x;
+ a.y -= b.y;
+ for(int i = 0; i < collection.size(); i++){
+ collection[i]->mousePressed(a);
+ }
+ }
+ }
+
+ virtual void mouseDragged(ofMouseEventArgs & args){
+ setValue(args.x, args.y, false);
+ if( bGuiActive ){
+ ofMouseEventArgs a = args;
+ a.x -= b.x;
+ a.y -= b.y;
+ for(int i = 0; i < collection.size(); i++){
+ collection[i]->mouseDragged(a);
+ }
+ }
+ }
+
+ virtual void mouseReleased(ofMouseEventArgs & args){
+ bGuiActive = false;
+ for(int k = 0; k < collection.size(); k++){
+ ofMouseEventArgs a = args;
+ a.x -= b.x;
+ a.y -= b.y;
+ collection[k]->mouseReleased(a);
+ }
+ }
+
+ void draw(){
+ ofPushStyle();
+ ofPushMatrix();
+
+ currentFrame = ofGetFrameNum();
+
+ ofTranslate(b.x, b.y);
+
+ ofFill();
+ ofSetColor(headerBackgroundColor);
+ ofRect(0, 0, b.width, header);
+
+ ofSetColor(textColor);
+ ofDrawBitmapString(name, textPadding, header / 2 + 4);
+
+ ofPushMatrix();
+ loadIcon.draw(loadBox.x, loadBox.y);
+ saveIcon.draw(saveBox.x, saveBox.y);
+ ofPopMatrix();
+
+ for(int i = 0; i < collection.size(); i++){
+ collection[i]->draw();
+ }
+
+ ofPopMatrix();
+ ofPopStyle();
+ }
+
+protected:
+
+ void setValue(float mx, float my, bool bCheck){
+
+ if( ofGetFrameNum() - currentFrame > 1 ){
+ bGrabbed = false;
+ bGuiActive = false;
+ return;
+ }
+ if( bCheck ){
+ if( b.inside(mx, my) ){
+ bGuiActive = true;
+
+ if( my > b.y && my <= b.y + header ){
+ bGrabbed = true;
+ grabPt.set(mx-b.x, my-b.y);
+ } else{
+ bGrabbed = false;
+ }
+
+ if(loadBox.inside(mx - b.x, my - b.y)) {
+ loadFromFile(filename);
+ }
+ if(saveBox.inside(mx - b.x, my - b.y)) {
+ saveToFile(filename);
+ }
+ }
+ } else if( bGrabbed ){
+ b.x = mx - grabPt.x;
+ b.y = my - grabPt.y;
+ }
+ }
+
+ ofPoint grabPt;
+ bool bGrabbed;
+ float currentY;
+ float spacing;
+ float header;
+ vector <ofBaseGui *> collection;
+
+ string filename;
+ ofImage loadIcon, saveIcon;
+ ofRectangle loadBox, saveBox;
+};
103 example/src/gui/ofSlider.h
@@ -0,0 +1,103 @@
+#pragma once
+
+#include "ofPanel.h"
+
+class ofSlider : public ofBaseGui{
+ friend class ofPanel;
+
+public:
+ ofSlider* setup(string sliderName, double _val, double _min, double _max, bool _bInt = false, float width = defaultWidth, float height = defaultHeight){
+ name = sliderName;
+ val = _val;
+ min = _min;
+ max = _max;
+ b.x = 0;
+ b.y = 0;
+ b.width = width;
+ b.height = height;
+ currentFrame = 0;
+ bGuiActive = false;
+ bInt = _bInt;
+ return this;
+ }
+
+ virtual void mouseMoved(ofMouseEventArgs & args){
+ }
+
+ virtual void mousePressed(ofMouseEventArgs & args){
+ setValue(args.x, args.y, true);
+ }
+
+ virtual void mouseDragged(ofMouseEventArgs & args){
+ setValue(args.x, args.y, false);
+ }
+
+ virtual void mouseReleased(ofMouseEventArgs & args){
+ bGuiActive = false;
+ }
+
+ virtual void saveToXml(ofxXmlSettings& xml) {
+ string xmlName = name;
+ ofStringReplace(xmlName," ","_");
+ xml.setValue(xmlName, val);
+ }
+
+ virtual void loadFromXml(ofxXmlSettings& xml) {
+ string xmlName = name;
+ ofStringReplace(xmlName," ","_");
+ val = xml.getValue(xmlName, val);
+ }
+
+ double getValue(){
+ if( bInt ){
+ return (int)val;
+ }
+ return val;
+ }
+
+ void draw(){
+ ofPushStyle();
+ ofPushMatrix();
+
+ currentFrame = ofGetFrameNum();
+ ofFill();
+ ofSetColor(backgroundColor);
+ ofRect(b);
+
+ ofTranslate(b.x, b.y);
+ float valAsPct = ofMap( val, min, max, 0, b.width-2, true );
+ ofEnableAlphaBlending();
+ ofSetColor(fillColor);
+ ofRect(1, 1, valAsPct, b.height-2);
+
+ ofTranslate(0, b.height / 2 + 4);
+ ofSetColor(textColor);
+ ofDrawBitmapString(name, textPadding, 0);
+ string valStr = ofToString(val, bInt ? 0 : 2);
+ ofDrawBitmapString(valStr, b.width - textPadding - valStr.length() * 8, 0);
+
+ ofPopMatrix();
+ ofPopStyle();
+ }
+
+protected:
+ double val, min, max;
+ bool bInt;
+
+ void setValue(float mx, float my, bool bCheck){
+ if( ofGetFrameNum() - currentFrame > 1 ){
+ bGuiActive = false;
+ return;
+ }
+ if( bCheck ){
+ if( b.inside(mx, my) ){
+ bGuiActive = true;
+ }else{
+ bGuiActive = false;
+ }
+ }
+ if( bGuiActive ){
+ val = ofMap(mx, b.x, b.x + b.width, min, max, true);
+ }
+ }
+};
113 example/src/gui/ofToggle.h
@@ -0,0 +1,113 @@
+#pragma once
+
+#include "ofPanel.h"
+
+class ofToggle : public ofBaseGui{
+ friend class ofPanel;
+
+public:
+ ofToggle* setup(string toggleName, bool _bVal, float width = defaultWidth, float height = defaultHeight){
+ name = toggleName;
+ b.x = 0;
+ b.y = 0;
+ b.width = width;
+ b.height = height;
+ currentFrame = 0;
+ bGuiActive = false;
+ bVal = _bVal;
+ checkboxRect.set(1, 1, b.height - 2, b.height - 2);
+ return this;
+ }
+
+ virtual void mouseMoved(ofMouseEventArgs & args){
+ }
+
+ virtual void mousePressed(ofMouseEventArgs & args){
+ setValue(args.x, args.y, true);
+ }
+
+ virtual void mouseDragged(ofMouseEventArgs & args){
+ }
+
+ virtual void mouseReleased(ofMouseEventArgs & args){
+ bGuiActive = false;
+ }
+
+ virtual void saveToXml(ofxXmlSettings& xml) {
+ string xmlName = name;
+ ofStringReplace(xmlName," ","_");
+ xml.setValue(xmlName, bVal);
+ }
+
+ virtual void loadFromXml(ofxXmlSettings& xml) {
+ string xmlName = name;
+ ofStringReplace(xmlName," ","_");
+ bVal = xml.getValue(xmlName, bVal);
+ }
+
+ bool getValue(){
+ return bVal;
+ }
+
+ void draw(){
+ currentFrame = ofGetFrameNum();
+
+ ofPushStyle();
+ ofPushMatrix();
+
+ ofSetColor(backgroundColor);
+ ofRect(b);
+
+ ofTranslate(b.x, b.y);
+
+ ofFill();
+ ofSetColor(fillColor);
+ ofRect(checkboxRect);
+
+ if( bVal ){
+ ofSetColor(textColor);
+ ofLine(checkboxRect.x, checkboxRect.y, checkboxRect.x + checkboxRect.width, checkboxRect.y + checkboxRect.height);
+ ofLine(checkboxRect.x, checkboxRect.y+ checkboxRect.height, checkboxRect.x + checkboxRect.width, checkboxRect.y);
+ } else {
+ ofSetColor(backgroundColor);
+ ofRect(checkboxRect.x + 1, checkboxRect.y + 1, checkboxRect.width - 2, checkboxRect.height - 2);
+ }
+
+ ofSetColor(textColor);
+ ofTranslate(0, b.height / 2 + 4);
+ ofDrawBitmapString(name, textPadding + checkboxRect.width, 0);
+ string valStr = bVal ? "true" : "false";
+ ofDrawBitmapString(valStr, b.width - textPadding - valStr.length() * 8, 0);
+
+ ofPopMatrix();
+ ofPopStyle();
+ }
+
+protected:
+ ofRectangle checkboxRect;
+ bool bVal;
+
+ void setValue(float mx, float my, bool bCheck){
+
+ if( ofGetFrameNum() - currentFrame > 1 ){
+ bGuiActive = false;
+ return;
+ }
+ if( bCheck ){
+ ofRectangle checkRect = checkboxRect;
+ checkRect.x += b.x;
+ checkRect.y += b.y;
+
+ if( checkRect.inside(mx, my) ){
+ bGuiActive = true;
+ }else{
+ bGuiActive = false;
+
+ }
+ }
+ if( bGuiActive ){
+ bVal = !bVal;
+ }
+ }
+
+};
10 example/src/main.cpp
@@ -0,0 +1,10 @@
+#include "testApp.h"
+#include "ofAppGlutWindow.h"
+
+//--------------------------------------------------------------
+int main(){
+ ofAppGlutWindow window; // create a window
+ // set width, height, mode (OF_WINDOW or OF_FULLSCREEN)
+ ofSetupOpenGL(&window, 1024, 768, OF_WINDOW);
+ ofRunApp(new testApp()); // start the app
+}
54 example/src/testApp.cpp
@@ -0,0 +1,54 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup(){
+ ofDisableArbTex();
+ ofSetFrameRate(24);
+
+ gui.setup("controls", 0, 0);
+ gui.add(contrast_slider.setup("contrast", 1.0, -100.0, 100.0, true));
+ gui.add(depth_slider.setup("color depth", 8.0, 1.0, 24.0, true));
+
+ vidGrabber.setVerbose(true);
+
+ /* Currently, the input source needs to have power-of-2 dimensions.
+ * This will change soon once I get NPOT textures working.
+ */
+ vidGrabber.initGrabber(512, 512, true);
+
+ /* Pass in only the texture reference, not the image object.
+ */
+ asciiArt.init(vidGrabber.getTextureReference(), ofGetWidth(), ofGetHeight());
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+ ofBackground(0);
+
+ vidGrabber.grabFrame();
+
+ asciiArt.setContrast(contrast_slider.getValue());
+ asciiArt.setColorDepth(depth_slider.getValue());
+ asciiArt.update();
+}
+
+
+
+//--------------------------------------------------------------
+void testApp::draw(){
+ ofSetColor(255);
+
+ asciiArt.draw((ofGetWidth() - asciiArt.getWidth())/2, (ofGetHeight() - asciiArt.getHeight())/2);
+ gui.draw();
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed(int key){
+
+ switch(key) {
+ case '0': asciiArt.setMode(ASCII_MODE_RAW); break;
+ case '1': asciiArt.setMode(ASCII_MODE_COLOR); break;
+ case '2': asciiArt.setMode(ASCII_MODE_GREEN); break;
+ case '3': asciiArt.setMode(ASCII_MODE_GRAY); break;
+ }
+}
23 example/src/testApp.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxAsciiArt.h"
+#include "gui/ofPanel.h"
+#include "gui/ofSlider.h"
+
+class testApp : public ofBaseApp{
+ public:
+ void setup();
+ void update();
+ void draw();
+
+ void keyPressed(int key);
+
+ ofPanel gui;
+ ofSlider contrast_slider;
+ ofSlider depth_slider;
+
+ ofVideoGrabber vidGrabber;
+
+ ofxAsciiArt asciiArt;
+};
424 src/ofxAsciiArt.cpp
@@ -0,0 +1,424 @@
+#include "ofxAsciiArt.h"
+
+#define IS_BIT(a,b) (((a) & (1 << (b))) ? 1 : 0)
+#define SQUARE(a) ((a) * (a))
+
+unsigned char asciiFontdata[12*256] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0,126,195,129,165,129,189,153,195,126, 0, 0,
+ 0,126,255,255,219,255,195,231,255,126, 0, 0,
+ 0, 0, 34,119,127,127,127, 62, 28, 8, 0, 0,
+ 0, 8, 28, 62,127,127, 62, 28, 8, 0, 0, 0,
+ 0, 24, 60, 60,255,231,231, 24, 24,126, 0, 0,
+ 0, 24, 60,126,255,255,126, 24, 24,126, 0, 0,
+ 0, 0, 0, 0, 60,126,126, 60, 0, 0, 0, 0,
+ 255,255,255,255,195,129,129,195,255,255,255,255,
+ 0, 0, 60,126,102, 66, 66,102,126, 60, 0, 0,
+ 255,255,195,129,153,189,189,153,129,195,255,255,
+ 0,124,112, 92, 78, 31, 51, 51, 51, 30, 0, 0,
+ 0, 60,102,102,102, 60, 24,126, 24, 24, 0, 0,
+ 0,248,152,152,248, 24, 24, 30, 31, 14, 0, 0,
+ 0,254,198,254,198,198,198,230,231,103, 3, 0,
+ 0, 0, 24,219,126,231,231,126,219, 24, 0, 0,
+ 0, 1, 3, 7, 31,127, 31, 7, 3, 1, 0, 0,
+ 0, 64, 96,112,124,127,124,112, 96, 64, 0, 0,
+ 0, 24, 60,126, 24, 24, 24,126, 60, 24, 0, 0,
+ 0,102,102,102,102,102, 0, 0,102,102, 0, 0,
+ 0,254,219,219,219,222,216,216,216,216, 0, 0,
+ 0,126,198, 12, 60,102,102, 60, 48, 99,126, 0,
+ 0, 0, 0, 0, 0, 0, 0,127,127,127, 0, 0,
+ 0, 24, 60,126, 24, 24, 24,126, 60, 24,126, 0,
+ 0, 24, 60,126, 24, 24, 24, 24, 24, 24, 0, 0,
+ 0, 24, 24, 24, 24, 24, 24,126, 60, 24, 0, 0,
+ 0, 0, 0, 24, 48,127, 48, 24, 0, 0, 0, 0,
+ 0, 0, 0, 12, 6,127, 6, 12, 0, 0, 0, 0,
+ 0, 0, 0, 0, 3, 3, 3,127, 0, 0, 0, 0,
+ 0, 0, 0, 36,102,255,102, 36, 0, 0, 0, 0,
+ 0, 0, 8, 8, 28, 28, 62, 62,127,127, 0, 0,
+ 0, 0,127,127, 62, 62, 28, 28, 8, 8, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,// ' '
+ 0, 12, 30, 30, 30, 12, 12, 0, 12, 12, 0, 0,// '!'
+ 0,102,102,102, 36, 0, 0, 0, 0, 0, 0, 0,// '"'
+ 0, 54, 54,127, 54, 54, 54,127, 54, 54, 0, 0,// '#'
+ 12, 12, 62, 3, 3, 30, 48, 48, 31, 12, 12, 0,// '$'
+ 0, 0, 0, 35, 51, 24, 12, 6, 51, 49, 0, 0,// '%'
+ 0, 14, 27, 27, 14, 95,123, 51, 59,110, 0, 0,// '&'
+ 0, 12, 12, 12, 6, 0, 0, 0, 0, 0, 0, 0,// '''
+ 0, 48, 24, 12, 6, 6, 6, 12, 24, 48, 0, 0,// '('
+ 0, 6, 12, 24, 48, 48, 48, 24, 12, 6, 0, 0,// ')'
+ 0, 0, 0,102, 60,255, 60,102, 0, 0, 0, 0,// '*'
+ 0, 0, 0, 24, 24,126, 24, 24, 0, 0, 0, 0,// '+'
+ 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 6, 0,// ','
+ 0, 0, 0, 0, 0,127, 0, 0, 0, 0, 0, 0,// '-'
+ 0, 0, 0, 0, 0, 0, 0, 0, 28, 28, 0, 0,// '.'
+ 0, 0, 64, 96, 48, 24, 12, 6, 3, 1, 0, 0,// '/'
+ 0, 62, 99,115,123,107,111,103, 99, 62, 0, 0,// '0'
+ 0, 8, 12, 15, 12, 12, 12, 12, 12, 63, 0, 0,// '1'
+ 0, 30, 51, 51, 48, 24, 12, 6, 51, 63, 0, 0,// '2'
+ 0, 30, 51, 48, 48, 28, 48, 48, 51, 30, 0, 0,// '3'
+ 0, 48, 56, 60, 54, 51,127, 48, 48,120, 0, 0,// '4'
+ 0, 63, 3, 3, 3, 31, 48, 48, 51, 30, 0, 0,// '5'
+ 0, 28, 6, 3, 3, 31, 51, 51, 51, 30, 0, 0,// '6'
+ 0,127, 99, 99, 96, 48, 24, 12, 12, 12, 0, 0,// '7'
+ 0, 30, 51, 51, 55, 30, 59, 51, 51, 30, 0, 0,// '8'
+ 0, 30, 51, 51, 51, 62, 24, 24, 12, 14, 0, 0,// '9'
+ 0, 0, 0, 28, 28, 0, 0, 28, 28, 0, 0, 0,// ':'
+ 0, 0, 0, 28, 28, 0, 0, 28, 28, 24, 12, 0,// ';'
+ 0, 48, 24, 12, 6, 3, 6, 12, 24, 48, 0, 0,// '<'
+ 0, 0, 0, 0,126, 0,126, 0, 0, 0, 0, 0,// '='
+ 0, 6, 12, 24, 48, 96, 48, 24, 12, 6, 0, 0,// '>'
+ 0, 30, 51, 48, 24, 12, 12, 0, 12, 12, 0, 0,// '?'
+ 0, 62, 99, 99,123,123,123, 3, 3, 62, 0, 0,// '@'
+ 0, 12, 30, 51, 51, 51, 63, 51, 51, 51, 0, 0,// 'A'
+ 0, 63,102,102,102, 62,102,102,102, 63, 0, 0,// 'B'
+ 0, 60,102, 99, 3, 3, 3, 99,102, 60, 0, 0,// 'C'
+ 0, 31, 54,102,102,102,102,102, 54, 31, 0, 0,// 'D'
+ 0,127, 70, 6, 38, 62, 38, 6, 70,127, 0, 0,// 'E'
+ 0,127,102, 70, 38, 62, 38, 6, 6, 15, 0, 0,// 'F'
+ 0, 60,102, 99, 3, 3,115, 99,102,124, 0, 0,// 'G'
+ 0, 51, 51, 51, 51, 63, 51, 51, 51, 51, 0, 0,// 'H'
+ 0, 30, 12, 12, 12, 12, 12, 12, 12, 30, 0, 0,// 'I'
+ 0,120, 48, 48, 48, 48, 51, 51, 51, 30, 0, 0,// 'J'
+ 0,103,102, 54, 54, 30, 54, 54,102,103, 0, 0,// 'K'
+ 0, 15, 6, 6, 6, 6, 70,102,102,127, 0, 0,// 'L'
+ 0, 99,119,127,127,107, 99, 99, 99, 99, 0, 0,// 'M'
+ 0, 99, 99,103,111,127,123,115, 99, 99, 0, 0,// 'N'
+ 0, 28, 54, 99, 99, 99, 99, 99, 54, 28, 0, 0,// 'O'
+ 0, 63,102,102,102, 62, 6, 6, 6, 15, 0, 0,// 'P'
+ 0, 28, 54, 99, 99, 99,115,123, 62, 48,120, 0,// 'Q'
+ 0, 63,102,102,102, 62, 54,102,102,103, 0, 0,// 'R'
+ 0, 30, 51, 51, 3, 14, 24, 51, 51, 30, 0, 0,// 'S'
+ 0, 63, 45, 12, 12, 12, 12, 12, 12, 30, 0, 0,// 'T'
+ 0, 51, 51, 51, 51, 51, 51, 51, 51, 30, 0, 0,// 'U'
+ 0, 51, 51, 51, 51, 51, 51, 51, 30, 12, 0, 0,// 'V'
+ 0, 99, 99, 99, 99,107,107, 54, 54, 54, 0, 0,// 'W'
+ 0, 51, 51, 51, 30, 12, 30, 51, 51, 51, 0, 0,// 'X'
+ 0, 51, 51, 51, 51, 30, 12, 12, 12, 30, 0, 0,// 'Y'
+ 0,127,115, 25, 24, 12, 6, 70, 99,127, 0, 0,// 'Z'
+ 0, 60, 12, 12, 12, 12, 12, 12, 12, 60, 0, 0,// '['
+ 0, 0, 1, 3, 6, 12, 24, 48, 96, 64, 0, 0,// '\'
+ 0, 60, 48, 48, 48, 48, 48, 48, 48, 60, 0, 0,// ']'
+ 8, 28, 54, 99, 0, 0, 0, 0, 0, 0, 0, 0,// '^'
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0,// '_'
+ 12, 12, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0,// '`'
+ 0, 0, 0, 0, 30, 48, 62, 51, 51,110, 0, 0,// 'a'
+ 0, 7, 6, 6, 62,102,102,102,102, 59, 0, 0,// 'b'
+ 0, 0, 0, 0, 30, 51, 3, 3, 51, 30, 0, 0,// 'c'
+ 0, 56, 48, 48, 62, 51, 51, 51, 51,110, 0, 0,// 'd'
+ 0, 0, 0, 0, 30, 51, 63, 3, 51, 30, 0, 0,// 'e'
+ 0, 28, 54, 6, 6, 31, 6, 6, 6, 15, 0, 0,// 'f'
+ 0, 0, 0, 0,110, 51, 51, 51, 62, 48, 51, 30,// 'g'
+ 0, 7, 6, 6, 54,110,102,102,102,103, 0, 0,// 'h'
+ 0, 24, 24, 0, 30, 24, 24, 24, 24,126, 0, 0,// 'i'
+ 0, 48, 48, 0, 60, 48, 48, 48, 48, 51, 51, 30,// 'j'
+ 0, 7, 6, 6,102, 54, 30, 54,102,103, 0, 0,// 'k'
+ 0, 30, 24, 24, 24, 24, 24, 24, 24,126, 0, 0,// 'l'
+ 0, 0, 0, 0, 63,107,107,107,107, 99, 0, 0,// 'm'
+ 0, 0, 0, 0, 31, 51, 51, 51, 51, 51, 0, 0,// 'n'
+ 0, 0, 0, 0, 30, 51, 51, 51, 51, 30, 0, 0,// 'o'
+ 0, 0, 0, 0, 59,102,102,102,102, 62, 6, 15,// 'p'
+ 0, 0, 0, 0,110, 51, 51, 51, 51, 62, 48,120,// 'q'
+ 0, 0, 0, 0, 55,118,110, 6, 6, 15, 0, 0,// 'r'
+ 0, 0, 0, 0, 30, 51, 6, 24, 51, 30, 0, 0,// 's'
+ 0, 0, 4, 6, 63, 6, 6, 6, 54, 28, 0, 0,// 't'
+ 0, 0, 0, 0, 51, 51, 51, 51, 51,110, 0, 0,// 'u'
+ 0, 0, 0, 0, 51, 51, 51, 51, 30, 12, 0, 0,// 'v'
+ 0, 0, 0, 0, 99, 99,107,107, 54, 54, 0, 0,// 'w'
+ 0, 0, 0, 0, 99, 54, 28, 28, 54, 99, 0, 0,// 'x'
+ 0, 0, 0, 0,102,102,102,102, 60, 48, 24, 15,// 'y'
+ 0, 0, 0, 0, 63, 49, 24, 6, 35, 63, 0, 0,// 'z'
+ 0, 56, 12, 12, 6, 3, 6, 12, 12, 56, 0, 0,// '{'
+ 0, 24, 24, 24, 24, 0, 24, 24, 24, 24, 0, 0,// '|'
+ 0, 7, 12, 12, 24, 48, 24, 12, 12, 7, 0, 0,// '}'
+ 0,206, 91,115, 0, 0, 0, 0, 0, 0, 0, 0,// '~'
+ 0, 0, 0, 8, 28, 54, 99, 99,127, 0, 0, 0,
+ 0, 30, 51, 51, 3, 3, 3, 51, 51, 30, 12, 15,// '€'
+ 0, 51, 51, 0, 51, 51, 51, 51, 51,110, 0, 0,// ''
+ 48, 24, 12, 0, 30, 51, 63, 3, 51, 30, 0, 0,// '‚'
+ 12, 30, 51, 0, 30, 48, 62, 51, 51,110, 0, 0,// 'ƒ'
+ 0, 51, 51, 0, 30, 48, 62, 51, 51,110, 0, 0,// '„'
+ 3, 6, 12, 0, 30, 48, 62, 51, 51,110, 0, 0,// '…'
+ 28, 54, 54, 28, 31, 48, 62, 51, 51,110, 0, 0,// '†'
+ 0, 0, 0, 0, 30, 51, 3, 3, 51, 30, 12, 15,// '‡'
+ 12, 30, 51, 0, 30, 51, 63, 3, 3, 62, 0, 0,// 'ˆ'
+ 0, 51, 51, 0, 30, 51, 63, 3, 3, 62, 0, 0,// '‰'
+ 3, 6, 12, 0, 30, 51, 63, 3, 3, 62, 0, 0,// 'Š'
+ 0, 54, 54, 0, 30, 24, 24, 24, 24,126, 0, 0,// '‹'
+ 8, 28, 54, 0, 30, 24, 24, 24, 24,126, 0, 0,// 'Œ'
+ 6, 12, 24, 0, 30, 24, 24, 24, 24,126, 0, 0,// ''
+ 0, 51, 0, 12, 30, 51, 51, 63, 51, 51, 0, 0,// 'Ž'
+ 30, 51, 51, 30, 30, 51, 51, 63, 51, 51, 0, 0,// ''
+ 48, 24, 12, 63, 35, 3, 31, 3, 35, 63, 0, 0,// ''
+ 0, 0, 0, 0,127,216,254, 27, 27,247, 0, 0,// '‘'
+ 0,124, 30, 27, 27,127, 27, 27, 27,123, 0, 0,// '’'
+ 12, 30, 51, 0, 30, 51, 51, 51, 51, 30, 0, 0,// '“'
+ 0, 51, 51, 0, 30, 51, 51, 51, 51, 30, 0, 0,// '”'
+ 3, 6, 12, 0, 30, 51, 51, 51, 51, 30, 0, 0,// '•'
+ 12, 30, 51, 0, 51, 51, 51, 51, 51,110, 0, 0,// '–'
+ 3, 6, 12, 0, 51, 51, 51, 51, 51,110, 0, 0,// '—'
+ 0,102,102, 0,102,102,102,102, 60, 48, 24, 15,// '˜'
+ 51, 0, 30, 51, 51, 51, 51, 51, 51, 30, 0, 0,// '™'
+ 51, 0, 51, 51, 51, 51, 51, 51, 51, 30, 0, 0,// 'š'
+ 0, 12, 12, 30, 51, 3, 3, 51, 30, 12, 12, 0,// '›'
+ 60,102, 6, 6, 6, 63, 6, 6, 3,127, 0, 0,// 'œ'
+ 51, 51, 51, 51, 30, 63, 12, 63, 12, 12, 0, 0,// ''
+ 15, 17, 17, 17, 15, 17,121, 49,177, 97, 0, 0,// 'ž'
+ 112,216, 24, 24,126, 24, 24, 24, 27, 14, 0, 0,// 'Ÿ'
+ 48, 24, 12, 0, 30, 48, 62, 51, 51,110, 0, 0,// ' '
+ 48, 24, 12, 0, 30, 24, 24, 24, 24,126, 0, 0,// '¡'
+ 48, 24, 12, 0, 30, 51, 51, 51, 51, 30, 0, 0,// '¢'
+ 48, 24, 12, 0, 51, 51, 51, 51, 51,110, 0, 0,// '£'
+ 0,110, 59, 0, 31, 51, 51, 51, 51, 51, 0, 0,// '¤'
+ 110, 59, 0, 99,103,111,123,115, 99, 99, 0, 0,// '¥'
+ 0, 30, 51, 51,126, 0,127, 0, 0, 0, 0, 0,// '¦'
+ 0, 30, 51, 51, 30, 0,127, 0, 0, 0, 0, 0,// '§'
+ 0, 12, 12, 0, 12, 6, 3, 3, 51, 30, 0, 0,// '¨'
+ 0, 0, 0, 0, 0, 63, 3, 3, 3, 0, 0, 0,// '©'
+ 0, 0, 0, 0, 0, 63, 48, 48, 48, 0, 0, 0,// 'ª'
+ 0, 66, 99, 51, 27, 12,118,195, 97, 48,248, 0,// '«'
+ 0,198,103, 54, 30,236,246,219,205,252,192, 0,// '¬'
+ 0, 12, 12, 0, 12, 12, 30, 30, 30, 12, 0, 0,// '­'
+ 0, 0, 0, 0,204,102, 51, 51,102,204, 0, 0,// '®'
+ 0, 0, 0, 0, 51,102,204,204,102, 51, 0, 0,// '¯'
+ 36, 73,146, 36, 73,146, 36, 73,146, 36, 73,146,// '°'
+ 170, 85,170, 85,170, 85,170, 85,170, 85,170, 85,// '±'
+ 182,219,109,182,219,109,182,219,109,182,219,109,// '²'
+ 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,// '³'
+ 24, 24, 24, 24, 24, 31, 24, 24, 24, 24, 24, 24,// '´'
+ 24, 24, 24, 24, 31, 24, 24, 31, 24, 24, 24, 24,// 'µ'
+ 102,102,102,102,102,103,102,102,102,102,102,102,// '¶'
+ 0, 0, 0, 0, 0,127,102,102,102,102,102,102,// '·'
+ 0, 0, 0, 0, 31, 24, 24, 31, 24, 24, 24, 24,// '¸'
+ 102,102,102,102,103, 96, 96,103,102,102,102,102,// '¹'
+ 102,102,102,102,102,102,102,102,102,102,102,102,// 'º'
+ 0, 0, 0, 0,127, 96, 96,103,102,102,102,102,// '»'
+ 102,102,102,102,103, 96, 96,127, 0, 0, 0, 0,// '¼'
+ 102,102,102,102,102,127, 0, 0, 0, 0, 0, 0,// '½'
+ 24, 24, 24, 24, 31, 24, 24, 31, 0, 0, 0, 0,// '¾'
+ 0, 0, 0, 0, 0, 31, 24, 24, 24, 24, 24, 24,// '¿'
+ 24, 24, 24, 24, 24,248, 0, 0, 0, 0, 0, 0,// 'À'
+ 24, 24, 24, 24, 24,255, 0, 0, 0, 0, 0, 0,// 'Á'
+ 0, 0, 0, 0, 0,255, 24, 24, 24, 24, 24, 24,// 'Â'
+ 24, 24, 24, 24, 24,248, 24, 24, 24, 24, 24, 24,// 'Ã'
+ 0, 0, 0, 0, 0,255, 0, 0, 0, 0, 0, 0,// 'Ä'
+ 24, 24, 24, 24, 24,255, 24, 24, 24, 24, 24, 24,// 'Å'
+ 24, 24, 24, 24,248, 24, 24,248, 24, 24, 24, 24,// 'Æ'
+ 102,102,102,102,102,230,102,102,102,102,102,102,// 'Ç'
+ 102,102,102,102,230, 6, 6,254, 0, 0, 0, 0,// 'È'
+ 0, 0, 0, 0,254, 6, 6,230,102,102,102,102,// 'É'
+ 102,102,102,102,231, 0, 0,255, 0, 0, 0, 0,// 'Ê'
+ 0, 0, 0, 0,255, 0, 0,231,102,102,102,102,// 'Ë'
+ 102,102,102,102,230, 6, 6,230,102,102,102,102,// 'Ì'
+ 0, 0, 0, 0,255, 0, 0,255, 0, 0, 0, 0,// 'Í'
+ 102,102,102,102,231, 0, 0,231,102,102,102,102,// 'Î'
+ 24, 24, 24, 24,255, 0, 0,255, 0, 0, 0, 0,// 'Ï'
+ 102,102,102,102,102,255, 0, 0, 0, 0, 0, 0,// 'Ð'
+ 0, 0, 0, 0,255, 0, 0,255, 24, 24, 24, 24,// 'Ñ'
+ 0, 0, 0, 0, 0,255,102,102,102,102,102,102,// 'Ò'
+ 102,102,102,102,102,254, 0, 0, 0, 0, 0, 0,// 'Ó'
+ 24, 24, 24, 24,248, 24, 24,248, 0, 0, 0, 0,// 'Ô'
+ 0, 0, 0, 0,248, 24, 24,248, 24, 24, 24, 24,// 'Õ'
+ 0, 0, 0, 0, 0,254,102,102,102,102,102,102,// 'Ö'
+ 102,102,102,102,102,231,102,102,102,102,102,102,// '×'
+ 24, 24, 24, 24,255, 0, 0,255, 24, 24, 24, 24,// 'Ø'
+ 24, 24, 24, 24, 24, 31, 0, 0, 0, 0, 0, 0,// 'Ù'
+ 0, 0, 0, 0, 0,248, 24, 24, 24, 24, 24, 24,// 'Ú'
+ 255,255,255,255,255,255,255,255,255,255,255,255,// 'Û'
+ 0, 0, 0, 0, 0, 0,255,255,255,255,255,255,// 'Ü'
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,// 'Ý'
+ 240,240,240,240,240,240,240,240,240,240,240,240,// 'Þ'
+ 255,255,255,255,255,255, 0, 0, 0, 0, 0, 0,// 'ß'
+ 0, 0, 0, 0,110,123, 51, 51,123,110, 0, 0,// 'à'
+ 0, 30, 51, 51, 27, 51, 51, 51, 31, 3, 6, 0,// 'á'
+ 0, 63, 51, 51, 3, 3, 3, 3, 3, 3, 0, 0,// 'â'
+ 0,127, 54, 54, 54, 54, 54, 54, 54,102, 0, 0,// 'ã'
+ 0, 63, 35, 38, 6, 12, 6, 38, 35, 63, 0, 0,// 'ä'
+ 0, 0, 0, 0,126, 19, 51, 51, 51, 30, 0, 0,// 'å'
+ 0, 0, 0, 0,102,102,102,102,102,222, 6, 3,// 'æ'
+ 0, 0, 0,110, 59, 24, 24, 24, 24,112, 0, 0,// 'ç'
+ 0, 63, 12, 30, 51, 51, 51, 30, 12, 63, 0, 0,// 'è'
+ 0, 30, 51, 51, 51, 63, 51, 51, 51, 30, 0, 0,// 'é'
+ 0, 62, 99, 99, 99, 99, 54, 54, 54,119, 0, 0,// 'ê'
+ 0, 60, 6, 12, 30, 51, 51, 51, 51, 30, 0, 0,// 'ë'
+ 0, 0, 0,110,219,219,219,118, 0, 0, 0, 0,// 'ì'
+ 0, 0, 96, 62,123,107,111, 62, 3, 0, 0, 0,// 'í'
+ 0, 60, 6, 3, 3, 63, 3, 3, 6, 60, 0, 0,// 'î'
+ 0, 0, 30, 51, 51, 51, 51, 51, 51, 51, 0, 0,// 'ï'
+ 0, 0, 63, 0, 0, 63, 0, 0, 63, 0, 0, 0,// 'ð'
+ 0, 0, 12, 12, 63, 12, 12, 0, 63, 0, 0, 0,// 'ñ'
+ 0, 6, 12, 24, 24, 12, 6, 0, 63, 0, 0, 0,// 'ò'
+ 0, 24, 12, 6, 6, 12, 24, 0, 63, 0, 0, 0,// 'ó'
+ 0, 0,112,216,216, 24, 24, 24, 24, 24, 24, 24,// 'ô'
+ 24, 24, 24, 24, 24, 24, 24, 27, 27, 14, 0, 0,// 'õ'
+ 0, 0, 12, 12, 0, 63, 0, 12, 12, 0, 0, 0,// 'ö'
+ 0, 0,206,219,115, 0,206,219,115, 0, 0, 0,// '÷'
+ 0, 60,102,102,102, 60, 0, 0, 0, 0, 0, 0,// 'ø'
+ 0, 0, 0, 0, 56, 56, 0, 0, 0, 0, 0, 0,// 'ù'
+ 0, 0, 0, 0, 0, 24, 0, 0, 0, 0, 0, 0,// 'ú'
+ 0,224, 32, 32, 32, 34, 38, 44, 56, 48, 0, 0,// 'û'
+ 0, 27, 54, 54, 54, 54, 0, 0, 0, 0, 0, 0,// 'ü'
+ 0, 30, 48, 24, 12, 62, 0, 0, 0, 0, 0, 0,// 'ý'
+ 0, 0, 60, 60, 60, 60, 60, 60, 60, 60, 0, 0,// 'þ'
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,// 'ÿ'
+};
+
+
+void ofxAsciiArt::init(ofTexture _source, int w, int h) {
+ mode = ASCII_MODE_COLOR;
+ contrast = 50.0;
+ depth = 16.0;
+ isReady = false;
+
+ source = _source;
+ ascii.loadImage("ofxAsciiArt/images/8x8.png");
+ hash.allocate(256, 256, OF_IMAGE_COLOR);
+ pix = ascii.getPixels();
+
+ shader.load("ofxAsciiArt/shaders/ascii.vert", "ofxAsciiArt/shaders/ascii.frag");
+
+ ofFbo::Settings settings;
+ settings.width = w;
+ settings.height = h;
+ settings.internalformat = GL_RGBA;
+ settings.textureTarget = GL_TEXTURE_2D;
+ fbo.allocate(settings);
+
+ buildHash();
+}
+
+void ofxAsciiArt::buildHash() {
+
+ int startchar = 32;
+ int endchar = 126;
+ int a, b, c, d, e, f, g, h, i;
+ int * reg;
+ reg = new int[256 * 4];
+ unsigned char * pchar = (unsigned char *)asciiFontdata;
+ unsigned char *asciiMap = new unsigned char[16 * 16 * 16 * 16];
+
+ // Step one: analyse font
+ int chars;
+ for (chars = startchar; chars <= endchar; chars++) {
+ int charoffset = chars * 12;
+ int i, j, c;
+ int scratch[8 * 12];
+ for (i = 0, c = 0; i < 12; i++) {
+ for (j = 0; j < 8; j++, c++) {
+ int cc = IS_BIT(*(pchar + i + charoffset), j) ? 255 : 0;
+ scratch[i * 8 + j] = cc;
+ }
+ }
+
+ int blurred[12 * 8];
+
+ for (i = 0, c = 0; i < 12; i++) {
+ for (j = 0; j < 8; j++, c++) {
+ blurred[c] =
+ (
+ scratch[((i + 0) % 12) * 8 + ((j + 0) % 8)] * 4 +
+ scratch[((i + 1) % 12) * 8 + ((j + 0) % 8)] * 2 * ((i == 11) ? 0 : 1) +
+ scratch[((i + 11) % 12) * 8 + ((j + 0) % 8)] * 2 * ((i == 0) ? 0 : 1) +
+ scratch[((i + 0) % 12) * 8 + ((j + 1) % 8)] * 2 * ((j == 7) ? 0 : 1) +
+ scratch[((i + 1) % 12) * 8 + ((j + 1) % 8)] * ((i == 11 || j == 7) ? 0 : 1) +
+ scratch[((i + 11) % 12) * 8 + ((j + 1) % 8)] * ((i == 0 || j == 7) ? 0 : 1) +
+ scratch[((i + 0) % 12) * 8 + ((j + 7) % 8)] * 2 * ((j == 0) ? 0 : 1) +
+ scratch[((i + 1) % 12) * 8 + ((j + 7) % 8)] * ((i == 11 || j == 0) ? 0 : 1) +
+ scratch[((i + 11) % 12) * 8 + ((j + 7) % 8)] * ((i == 0 || j == 0) ? 0 : 1)
+ ) / 8;
+ }
+ }
+
+ e = 0;
+ for (b = 0; b < 6; b++)
+ for (c = 0; c < 4; c++)
+ e += blurred[b * 8 + c];
+ *(reg + chars * 4 + 0) = e;
+ e = 0;
+ for (b = 0; b < 6; b++)
+ for (c = 0; c < 4; c++)
+ e += blurred[b * 8 + c + 4];
+ *(reg + chars * 4 + 1) = e;
+ e = 0;
+ for (b = 0; b < 6; b++)
+ for (c = 0; c < 4; c++)
+ e += blurred[b * 8 + c + 6 * 8];
+ *(reg + chars * 4 + 2) = e;
+ e = 0;
+ for (b = 0; b < 6; b++)
+ for (c = 0; c < 4; c++)
+ e += blurred[b * 8 + c + 6 * 8 + 4];
+ *(reg + chars * 4 + 3) = e;
+ }
+
+ for (a = 0; a < 16; a++) {
+ for (b = 0; b < 16; b++) {
+ for (c = 0; c < 16; c++) {
+ for (d = 0; d < 16; d++) {
+ f = 0x7fffffff;
+ g = 0;
+
+ for (h = startchar;h < (endchar + 1);h++) {
+ i = SQUARE(*(reg + h * 4 + 0) - a * 16 * 24) +
+ SQUARE(*(reg + h * 4 + 1) - b * 16 * 24) +
+ SQUARE(*(reg + h * 4 + 2) - c * 16 * 24) +
+ SQUARE(*(reg + h * 4 + 3) - d * 16 * 24);
+ if (i < f) {
+ f = i;
+ g = h;
+ }
+ }
+
+ asciiMap[(a << 12) + (b << 8) + (c << 4) + d] = g;
+ }
+ }
+ }
+ }
+ delete[] reg;
+
+ int x = 0;
+ int y = 0;
+ for(i=0; i<16*16*16*16; i++) {
+ hash.setColor(x, y, ofColor(0, asciiMap[i], 0, 0));
+ if(x == 255) {
+ x=0;
+ y++;
+ } else {
+ x++;
+ }
+ }
+
+ hash.update();
+ isReady = true;
+}
+
+void ofxAsciiArt::update() {
+ if(isReady) {
+ fbo.begin();
+ shader.begin();
+
+ shader.setAttribute1f(shader.getAttributeLocation("a_mode"), (float)mode);
+ shader.setAttribute1f(shader.getAttributeLocation("a_contrast"), contrast);
+ shader.setAttribute1f(shader.getAttributeLocation("a_depth"), depth);
+ shader.setUniform2f("imageSize", source.getWidth(), source.getHeight());
+ shader.setUniform2f("canvasSize", fbo.getWidth(), fbo.getHeight());
+ shader.setUniformTexture("inputTexture", source, source.getTextureData().textureID);
+ shader.setUniformTexture("asciiTexture", ascii.getTextureReference(), ascii.getTextureReference().getTextureData().textureID);
+ shader.setUniformTexture("hashTexture", hash.getTextureReference(), hash.getTextureReference().getTextureData().textureID);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
+ glTexCoord2f(source.getWidth(), 0); glVertex3f(fbo.getWidth(), 0, 0);
+ glTexCoord2f(source.getWidth(), source.getHeight()); glVertex3f(fbo.getWidth(), fbo.getHeight(), 0);
+ glTexCoord2f(0, source.getHeight()); glVertex3f(0, fbo.getHeight(), 0);
+ glEnd();
+
+ shader.end();
+ fbo.end();
+ }
+}
+
+void ofxAsciiArt::draw(int x, int y) {
+ if(isReady) {
+ fbo.draw(x, y, fbo.getWidth(), fbo.getHeight());
+ }
+}
69 src/ofxAsciiArt.h
@@ -0,0 +1,69 @@
+/*
+ * This add-on was inspired by Sol's work with TextFX http://sol.gfxile.net/textfx/index.html ,
+ * the major difference being ofxAsciiArt runs on the GPU. Font data and LUT creation were
+ * taken from TextFX.
+ *
+ * Created by Peter Nitsch on 12-06-21.
+ * Copyright 2012 Teehan+Lax. All rights reserved.
+ *
+ */
+
+#pragma once
+
+#include "ofMain.h"
+
+#define CHAR_WIDTH 8
+#define CHAR_HEIGHT 8
+
+#define ASCII_MODE_RAW 0
+#define ASCII_MODE_COLOR 1
+#define ASCII_MODE_GREEN 2
+#define ASCII_MODE_GRAY 3
+
+class ofxAsciiArt {
+
+public:
+ void init(ofTexture _source, int w, int h);
+ void update();
+ void draw(int x, int y);
+ void setMode(int _mode) {
+ if(_mode >= 0 && _mode <= 6) {
+ mode = _mode;
+ }
+ };
+ void setContrast(float _contrast) {
+ if(_contrast >= -100.0 && _contrast <= 100.0) {
+ contrast = _contrast;
+ }
+ };
+ void setColorDepth(float _depth) {
+ if(_depth >= 1.0 && _depth <= 24.0) {
+ depth = _depth;
+ }
+ };
+
+ bool isReady;
+ int getWidth(){ return fbo.getWidth(); };
+ int getHeight(){ return fbo.getHeight(); };
+ float getContrast() { return contrast; };
+ unsigned char* getPixels() {
+ fbo.readToPixels(pixels);
+ return pixels.getPixels();
+ };
+
+private:
+ void buildHash();
+
+ ofFbo fbo;
+ ofPixels pixels;
+ ofTexture source;
+ ofImage ascii;
+ ofImage hash;
+
+ ofShader shader;
+ int mode;
+ float contrast;
+ float depth;
+ bool isModeSet;
+ unsigned char * pix;
+};

0 comments on commit a6ab8cd

Please sign in to comment.