3 * Copyright 1999-2000 Y.Takagi. All Rights Reserved.
9 #include <GraphicsDefs.h>
11 // definition for B_RGB32 (=B_RGB32_LITTLE) and B_RGBA32
16 uchar alpha
; // unused in B_RGB32
19 // definition for B_RGB32_BIG and B_RGBA32_BIG
21 uchar alpha
; // unused in B_RGB32_BIG
28 ColorRGB32Little little
;
34 typedef void (Halftone::*PFN_dither
)(uchar
* destination
, const uchar
* source
,
35 int x
, int y
, int width
);
37 typedef uint (*PFN_gray
)(ColorRGB32 c
);
56 kPlaneMonochrome1
, // 1 bit depth (0 white, 1 black)
57 kPlaneRGB1
, // 3 planes, 1 bit depth (0 black, 7 white)
65 Halftone(color_space colorSpace
, double gamma
= 1.4,
67 DitherType dither_type
= kTypeFloydSteinberg
);
70 void SetPlanes(Planes planes
);
71 void SetBlackValue(BlackValue blackValue
);
73 void Dither(uchar
*destination
, const uchar
*source
, int x
,
76 int GetPixelDepth() const;
78 const uchar
* GetPattern() const;
79 void SetPattern(const uchar
*pattern
);
82 Halftone(const Halftone
&);
84 Halftone
& operator=(const Halftone
&);
86 // PFN_gray: return value of 0 means low density (or black) and
87 // value of 255 means high density (or white)
88 PFN_gray
GetGrayFunction() const;
89 void SetGrayFunction(PFN_gray gray
);
90 void SetGrayFunction(GrayFunction grayFunction
);
92 void CreateGammaTable(double gamma
, double min
);
93 void InitElements(int x
, int y
, uchar
* elements
);
94 uint
GetDensity(ColorRGB32 c
) const;
95 uchar
ConvertUsingBlackValue(uchar byte
) const;
96 void DitherRGB32(uchar
* destination
, const uchar
* source
,
97 int x
, int y
, int width
);
99 void InitFloydSteinberg();
100 void DeleteErrorTables();
101 void UninitFloydSteinberg();
102 void SetupErrorBuffer(int x
, int y
, int width
);
103 void DitherFloydSteinberg(uchar
* destination
,
104 const uchar
* source
, int x
, int y
, int width
);
108 kGammaTableSize
= 256,
109 kMaxNumberOfPlanes
= 3
116 BlackValue fBlackValue
;
117 const uchar
* fPattern
;
118 uint fGammaTable
[kGammaTableSize
];
121 // fields used for floyd-steinberg dithering
125 int* fErrorTables
[kMaxNumberOfPlanes
];
130 Halftone::GetPixelDepth() const
137 Halftone::GetPattern() const
144 Halftone::SetPattern(const uchar
* pattern
)
151 Halftone::GetGrayFunction() const
158 Halftone::SetGrayFunction(PFN_gray gray
)
165 Halftone::GetDensity(ColorRGB32 c
) const
167 return fGammaTable
[fGray(c
)];
172 Halftone::ConvertUsingBlackValue(uchar byte
) const
174 // bits with value = '1' in byte mean black
175 if (fBlackValue
== kHighValueMeansBlack
)
182 #endif /* __HALFTONE_H */