Permalink
Browse files

first commit

  • Loading branch information...
kylemcdonald committed Jan 7, 2011
0 parents commit 72c0f1207b8616755ed222054c1191d596824c96
@@ -0,0 +1,12 @@
+*.depend
+*.layout
+*.mode*v3
+*.pbxuser
+*.app*
+*.DS_*
+
+.svn/
+obj/
+bin/
+build/
+!data/
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIdentifier</key>
+ <string>com.yourcompany.openFrameworks</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+</dict>
+</plist>
@@ -0,0 +1,7 @@
+#include "testApp.h"
+
+int main() {
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 1680, 1050, OF_FULLSCREEN);
+ ofRunApp(new testApp());
+}
@@ -0,0 +1,83 @@
+#include "ofxRleImage.h"
+
+// This adds a 1-pixel vertical offset, which is important for drawing lines on some graphics cards.
+bool ofxRleImage::useDrawOffset = false;
+
+void ofxRleImage::setup(ofImage& img) {
+ if(img.type == OF_IMAGE_GRAYSCALE) {
+ data.clear();
+ width = img.getWidth();
+ height = img.getHeight();
+
+ unsigned char *raw = img.getPixels();
+
+ int nPixels = width * height;
+
+ // Scan through the image in 8-bytes chunks. (unsigned long long, or uint64_t).
+ // Achieve additional optimizations by assuming that the image is mostly black.
+
+ int bytesPerChunk = sizeof(uint64_t);
+
+ uint64_t *firstChunk = (uint64_t*) raw;
+ uint64_t *curChunk = &firstChunk[1];
+ uint64_t *lastChunk = &firstChunk[(nPixels / bytesPerChunk) - 1];
+
+ // Note: I ignore the first 8 and last 8 bytes of the image, for now.
+ // (that's the 1 and -1 above.)
+
+ int pixelIndex = 0;
+ unsigned char prevVal = 0;
+ while (curChunk < lastChunk){
+ uint64_t curChunkVal = *curChunk;
+ if (curChunkVal != 0){
+ uint64_t nextChunkVal = *(curChunk+1);
+ unsigned char *triplet = (unsigned char *) (curChunk - 1);
+
+ // We store all 24 bytes but only record edges
+ // in the curr (middle) set of 8 chars.
+ unsigned char prevVal = triplet[bytesPerChunk - 1];
+ for (int curIndex = bytesPerChunk; curIndex < (bytesPerChunk + bytesPerChunk + 1); curIndex++){
+ unsigned char curVal = triplet[curIndex];
+ if (curVal != prevVal) {
+ if (curIndex < (bytesPerChunk + bytesPerChunk)){
+ data.push_back( ((curChunk - firstChunk - 1) * bytesPerChunk) + curIndex );
+ } else if (nextChunkVal == 0){
+ data.push_back( ((curChunk - firstChunk - 1) * bytesPerChunk) + curIndex );
+ }
+ }
+ prevVal = curVal;
+ }
+ }
+ curChunk++;
+ }
+
+ // Convert RLE data into lines.
+ int nLineEndpoints = data.size();
+ lines.clear();
+ lines.resize(nLineEndpoints);
+ for (int i = 0; i < nLineEndpoints; i++){
+ int curIndex = data[i];
+ RlePoint2d& curPoint = lines[i];
+ curPoint.x = (curIndex % width);
+ curPoint.y = (curIndex / width);
+ }
+ }
+}
+
+void ofxRleImage::draw() {
+ int nLineEndpoints = data.size();
+
+ glPushMatrix();
+
+ if(useDrawOffset) {
+ glTranslatef(0, 1, 0);
+ }
+
+ // Draw lines as a vertex array.
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glVertexPointer(2, GL_FLOAT, 0, &lines[0]);
+ glDrawArrays(GL_LINES, 0, lines.size());
+ glDisableClientState(GL_VERTEX_ARRAY);
+
+ glPopMatrix();
+}
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "ofMain.h"
+
+class RlePoint2d {
+public:
+ float x, y;
+};
+
+class ofxRleImage {
+protected:
+ unsigned int width, height;
+ vector<int> data;
+ vector<RlePoint2d> lines;
+
+public:
+ void setup(ofImage& img);
+ void draw();
+
+ static bool useDrawOffset;
+};
@@ -0,0 +1,22 @@
+#include "testApp.h"
+
+void testApp::setup(){
+ eyeshineDemoImage.loadImage("eyeshine_demo.png");
+ rleImage.setup(eyeshineDemoImage);
+}
+
+void testApp::update(){
+}
+
+void testApp::draw(){
+ ofBackground(100, 100, 100);
+
+ ofSetColor(255);
+ eyeshineDemoImage.draw(0, 0);
+
+ ofSetColor(255, 0, 0);
+ rleImage.draw();
+
+ ofSetColor(255);
+ ofDrawBitmapString(ofToString((int) ofGetFrameRate()) + " fps", 10, 20);
+}
@@ -0,0 +1,16 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxOpenCv.h"
+#include "ofxRleImage.h"
+
+class testApp : public ofBaseApp{
+public:
+ void setup();
+ void update();
+ void draw();
+
+ ofxRleImage rleImage;
+
+ ofImage eyeshineDemoImage;
+};

0 comments on commit 72c0f12

Please sign in to comment.