1 /*
2  * Copyright (c) 1996, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 /*
27  * This file contains macro definitions for the Encoding category of
28  * the macros used by the generic scaleloop function.
29  *
30  * This implementation uses an ordered dithering error matrix to
31  * produce a moderately high quality version of an image with only
32  * an 8-bit (or less) RGB colormap or an 8-bit grayramp.  The ordered
33  * dithering technique does not rely on the order in which the pixels
34  * are processed so this file can be used in cases where the ImageProducer
35  * has not specified the TopDownLeftRight delivery hint.  The ordered
36  * dither technique is also much faster than the Floyd-Steinberg error
37  * diffusion algorithm so this implementation would also be appropriate
38  * for cases where performance is critical such as the processing of a
39  * video stream.
40  *
41  * This file can be used to provide the default implementation of the
42  * Encoding macros for RGB colormapped or grayscale displays.
43  */
44 
45 /*
46  * These definitions vector the standard macro names to the "Any"
47  * versions of those macros.  The "DitherDeclared" keyword is also
48  * defined to indicate to the other include files that they are not
49  * defining the primary implementation.  All other include files
50  * will check for the existance of the "DitherDeclared" keyword
51  * and define their implementations of the Encoding macros using
52  * more specific names without overriding the standard names.  This
53  * is done so that the other files can be included later to reuse
54  * their implementations for the specific cases.
55  */
56 #define DitherDeclared
57 #define DeclareDitherVars       DeclareAnyDitherVars
58 #define InitDither              InitAnyDither
59 #define StartDitherLine         StartAnyDitherLine
60 #define DitherPixel             AnyDitherPixel
61 #define DitherBufComplete       AnyDitherBufComplete
62 
63 /*
64  * Include the specific implementation for grayscale displays.
65  * The implementor will have to include one of the color display
66  * implementations (img_ordclrsgn.h or img_ordclruns.h) manually.
67  */
68 #include "img_ordgray.h"
69 
70 #define DeclareAnyDitherVars                                    \
71     int grayscale;                                              \
72     DeclareColorDitherVars                                      \
73     DeclareGrayDitherVars                                       \
74     int relx, rely;
75 
76 #define InitAnyDither(cvdata, clrdata, dstTW)                           \
77     do {                                                                \
78         if (grayscale = clrdata->grayscale) {                           \
79             InitGrayDither(cvdata, clrdata, dstTW);                     \
80         } else {                                                        \
81             InitColorDither(cvdata, clrdata, dstTW);                    \
82         }                                                               \
83     } while (0)
84 
85 #define StartAnyDitherLine(cvdata, dstX1, dstY)                         \
86     do {                                                                \
87         if (grayscale) {                                                \
88             StartGrayDitherLine(cvdata, dstX1, dstY);                   \
89         } else {                                                        \
90             StartColorDitherLine(cvdata, dstX1, dstY);                  \
91         }                                                               \
92     } while (0)
93 
94 #define AnyDitherPixel(dstX, dstY, pixel, red, green, blue)             \
95     do {                                                                \
96         if (grayscale) {                                                \
97             GrayDitherPixel(dstX, dstY, pixel, red, green, blue);       \
98         } else {                                                        \
99             ColorDitherPixel(dstX, dstY, pixel, red, green, blue);      \
100         }                                                               \
101     } while (0)
102 
103 #define AnyDitherBufComplete(cvdata, dstX1)                             \
104     do {                                                                \
105         if (grayscale) {                                                \
106             GrayDitherBufComplete(cvdata, dstX1);                       \
107         } else {                                                        \
108             ColorDitherBufComplete(cvdata, dstX1);                      \
109         }                                                               \
110     } while (0)
111