Skip to content

Commit

Permalink
more accorate error diffusion
Browse files Browse the repository at this point in the history
  • Loading branch information
poeticAndroid committed Apr 13, 2020
1 parent 1375332 commit f9dcb0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
2 changes: 1 addition & 1 deletion source/machine.d
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import pixmap;
import image_loader;
import network;

const VERSION = "1.5.0"; /// version of the software
const VERSION = "1.5.2"; /// version of the software

/**
Class representing "the machine"!
Expand Down
14 changes: 5 additions & 9 deletions source/pixmap.d
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,7 @@ class Pixmap
ubyte _red = this.palette[i * 3 + 0];
ubyte _green = this.palette[i * 3 + 1];
ubyte _blue = this.palette[i * 3 + 2];
const diff = sqrt(cast(real)(pow(red - _red, 2) + pow(green - _green, 2) + pow(blue - _blue,
2)));
const diff = sqrt(cast(real)(pow(red - _red, 2) + pow(green - _green, 2) + pow(blue - _blue, 2)));
if (diff == 0)
return cast(ubyte) i;
if (diff < record)
Expand All @@ -213,15 +212,12 @@ class Pixmap
}
if (this.errorDiffusion)
{
red = cast(ubyte) min(max(0, red - this.redErr), 255);
green = cast(ubyte) min(max(0, green - this.greenErr), 255);
blue = cast(ubyte) min(max(0, blue - this.blueErr), 255);
ubyte _red = this.palette[best * 3 + 0];
ubyte _green = this.palette[best * 3 + 1];
ubyte _blue = this.palette[best * 3 + 2];
this.redErr += red - _red;
this.greenErr += green - _green;
this.blueErr += blue - _blue;
ubyte _blue = this.palette[best * 3 + 2];
this.redErr = red - _red;
this.greenErr = green - _green;
this.blueErr = blue - _blue;
}
return best;
}
Expand Down

0 comments on commit f9dcb0f

Please sign in to comment.