From aa36fbce3a7b2bd67c6282b26f730ee793f20aa6 Mon Sep 17 00:00:00 2001 From: Michael Pfeiffer Date: Thu, 29 Jan 2004 18:47:58 +0000 Subject: [PATCH] Extended to dither each RGB channel separately. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6407 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/print/libprint/Halftone.h | 7 ++++ .../drivers/shared/libprint/Halftone.cpp | 34 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/headers/private/print/libprint/Halftone.h b/headers/private/print/libprint/Halftone.h index f5837cb4eb..95c23ac4de 100644 --- a/headers/private/print/libprint/Halftone.h +++ b/headers/private/print/libprint/Halftone.h @@ -24,6 +24,12 @@ public: TYPE2, TYPE3 }; + enum GrayFunction { + kMixToGray, + kRedChannel, + kGreenChannel, + kBlueChannel + }; Halftone(color_space cs, double gamma = 1.4, DITHERTYPE dither_type = TYPE3); ~Halftone(); int dither(uchar *dst, const uchar *src, int x, int y, int width); @@ -33,6 +39,7 @@ public: void setPattern(const uchar *pattern); PFN_gray getGrayFunction() const; void setGrayFunction(PFN_gray gray); + void setGrayFunction(GrayFunction grayFunction); protected: void createGammaTable(double gamma); diff --git a/src/add-ons/print/drivers/shared/libprint/Halftone.cpp b/src/add-ons/print/drivers/shared/libprint/Halftone.cpp index 3555caf6f7..ed0928fa5d 100644 --- a/src/add-ons/print/drivers/shared/libprint/Halftone.cpp +++ b/src/add-ons/print/drivers/shared/libprint/Halftone.cpp @@ -18,7 +18,7 @@ using namespace std; #include "Pattern.h" -uint gray(rgb_color c) +static uint gray(rgb_color c) { if (c.red == c.green && c.red == c.blue) { 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) { __pixel_depth = color_space2pixel_depth(cs); @@ -108,6 +123,23 @@ int Halftone::dither( 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( uchar *dst, const uchar *src,