Extended to dither each RGB channel separately.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6407 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -24,6 +24,12 @@ public:
|
|||||||
TYPE2,
|
TYPE2,
|
||||||
TYPE3
|
TYPE3
|
||||||
};
|
};
|
||||||
|
enum GrayFunction {
|
||||||
|
kMixToGray,
|
||||||
|
kRedChannel,
|
||||||
|
kGreenChannel,
|
||||||
|
kBlueChannel
|
||||||
|
};
|
||||||
Halftone(color_space cs, double gamma = 1.4, DITHERTYPE dither_type = TYPE3);
|
Halftone(color_space cs, double gamma = 1.4, DITHERTYPE dither_type = TYPE3);
|
||||||
~Halftone();
|
~Halftone();
|
||||||
int dither(uchar *dst, const uchar *src, int x, int y, int width);
|
int dither(uchar *dst, const uchar *src, int x, int y, int width);
|
||||||
@@ -33,6 +39,7 @@ public:
|
|||||||
void setPattern(const uchar *pattern);
|
void setPattern(const uchar *pattern);
|
||||||
PFN_gray getGrayFunction() const;
|
PFN_gray getGrayFunction() const;
|
||||||
void setGrayFunction(PFN_gray gray);
|
void setGrayFunction(PFN_gray gray);
|
||||||
|
void setGrayFunction(GrayFunction grayFunction);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void createGammaTable(double gamma);
|
void createGammaTable(double gamma);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ using namespace std;
|
|||||||
|
|
||||||
#include "Pattern.h"
|
#include "Pattern.h"
|
||||||
|
|
||||||
uint gray(rgb_color c)
|
static uint gray(rgb_color c)
|
||||||
{
|
{
|
||||||
if (c.red == c.green && c.red == c.blue) {
|
if (c.red == c.green && c.red == c.blue) {
|
||||||
return 255 - c.red;
|
return 255 - c.red;
|
||||||
@@ -27,6 +27,21 @@ uint gray(rgb_color c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint channel_red(rgb_color c)
|
||||||
|
{
|
||||||
|
return c.red;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint channel_green(rgb_color c)
|
||||||
|
{
|
||||||
|
return c.green;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint channel_blue(rgb_color c)
|
||||||
|
{
|
||||||
|
return c.blue;
|
||||||
|
}
|
||||||
|
|
||||||
Halftone::Halftone(color_space cs, double gamma, DITHERTYPE dither_type)
|
Halftone::Halftone(color_space cs, double gamma, DITHERTYPE dither_type)
|
||||||
{
|
{
|
||||||
__pixel_depth = color_space2pixel_depth(cs);
|
__pixel_depth = color_space2pixel_depth(cs);
|
||||||
@@ -108,6 +123,23 @@ int Halftone::dither(
|
|||||||
return (this->*__dither)(dst, src, x, y, width);
|
return (this->*__dither)(dst, src, x, y, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Halftone::setGrayFunction(GrayFunction grayFunction)
|
||||||
|
{
|
||||||
|
PFN_gray function = NULL;
|
||||||
|
switch (grayFunction) {
|
||||||
|
case kMixToGray: function = gray;
|
||||||
|
break;
|
||||||
|
case kRedChannel: function = channel_red;
|
||||||
|
break;
|
||||||
|
case kGreenChannel: function = channel_green;
|
||||||
|
break;
|
||||||
|
case kBlueChannel: function = channel_blue;
|
||||||
|
break;
|
||||||
|
};
|
||||||
|
setGrayFunction(function);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int Halftone::ditherGRAY1(
|
int Halftone::ditherGRAY1(
|
||||||
uchar *dst,
|
uchar *dst,
|
||||||
const uchar *src,
|
const uchar *src,
|
||||||
|
|||||||
Reference in New Issue
Block a user