Skip to content

Commit

Permalink
first steps toward the ditherer
Browse files Browse the repository at this point in the history
still needs TCLFast to be updated to use it.
most likely with a new class for cleanliness
  • Loading branch information
kukulski committed Nov 10, 2012
1 parent e41c94f commit 30e0a58
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ udpfast: udpfast.o UDPSender.o tclled.o

udpfast.o: udpfast.cpp UDPSender.h

main.o: main.cpp UDPSender.h
main.o: main.cpp UDPSender.h TCLFast.hxx TCLFast.o

UDPSender.o: UDPSender.cpp UDPSender.h

tclled.o: tclled.c tclled.h
tclled.o: tclled.c tclled.h

TCLFast.o: TCLFast.cpp TCLFast.hxx
13 changes: 13 additions & 0 deletions TCLFast.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "TCLFast.hxx"
#include <math.h>

float sGammaR[256], sGammaG[256], sGammaB[256];

void DitherPixel::initGamma(double gamma_red, double gamma_green, double gamma_blue) {
int i;

for(i=0;i<256;i++) {
sGammaR[i] = pow(i/255.0,gamma_red)*255.0;
sGammaG[i] = pow(i/255.0,gamma_green)*255.0;
sGammaB[i] = pow(i/255.0,gamma_blue)*255.0;
}
73 changes: 73 additions & 0 deletions TCLFast.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,79 @@
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <math.h>


class DitherChannel {
public:
unsigned char out;

void set(float val) {
target = val;
err = 0;
update();
}

unsigned char update() {
out = (target + err);
err = target - out;
return out;
}
private:
float target;
unsigned char intVal;
float err;
};

extern float sGammaR[256], sGammaG[256], sGammaB[256];

// static void setGamma(double gamma_red, double gamma_green, double gamma_blue) {
// int i;
//
// for(i=0;i<256;i++) {
// sGammaR[i] = pow(i/255.0,gamma_red)*255.0;
// sGammaG[i] = pow(i/255.0,gamma_green)*255.0;
// sGammaB[i] = pow(i/255.0,gamma_blue)*255.0;
// };

class DitherPixel {
public:


static void initGamma(double gamma_red, double gamma_green, double gamma_blue);

void setTCL(tcl_color *tcl) {
out = tcl;
}

void set(unsigned char r, unsigned char g, unsigned char b ) {
rDither.set(sGammaR[r]);
gDither.set(sGammaG[g]);
bDither.set(sGammaB[b]);
}

void update() {
::write_color(out, rDither.update(), gDither.update(), bDither.update());
}

private:

// in theory, we could do better and faster by using fixed point math
// if we get CPU bound, we'll make the change

tcl_color *out;
DitherChannel rDither, gDither, bDither;
};



class TCLFast {

public:




TCLFast(int wd, int ht) {
width = wd;
height = ht;
Expand Down Expand Up @@ -115,5 +183,10 @@ void initTCL() {

}
}; // class TCLFast


/// next: make a new class that uses pixelDither


#endif /* TCLFAST_HXX */

0 comments on commit 30e0a58

Please sign in to comment.