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 a Floyd-Steinberg error diffusion technique 31 * to produce a very high quality version of an image with only an 8-bit 32 * (or less) RGB colormap or gray ramp. The error diffusion technique 33 * requires that the input color information be delivered in a special 34 * order from the top row to the bottom row and then left to right within 35 * each row, thus it is only valid in cases where the ImageProducer has 36 * specified the TopDownLeftRight delivery hint. If the data is not read 37 * in that order, no mathematical or memory access errors should occur, 38 * but the dithering error will be spread through the pixels of the output 39 * image in an unpleasant manner. 40 */ 41 42/* 43 * These definitions vector the standard macro names to the "Any" 44 * versions of those macros. The "DitherDeclared" keyword is also 45 * defined to indicate to the other include files that they are not 46 * defining the primary implementation. All other include files 47 * will check for the existance of the "DitherDeclared" keyword 48 * and define their implementations of the Encoding macros using 49 * more specific names without overriding the standard names. This 50 * is done so that the other files can be included here to reuse 51 * their implementations for the specific cases. 52 */ 53#define DitherDeclared 54#define DeclareDitherVars DeclareAnyDitherVars 55#define InitDither InitAnyDither 56#define StartDitherLine StartAnyDitherLine 57#define DitherPixel AnyDitherPixel 58#define DitherBufComplete AnyDitherBufComplete 59 60/* Include the specific implementations for color and grayscale displays */ 61#include "img_fscolor.h" 62#include "img_fsgray.h" 63 64#define DeclareAnyDitherVars \ 65 DeclareColorDitherVars \ 66 DeclareGrayDitherVars \ 67 int grayscale; 68 69#define InitAnyDither(cvdata, clrdata, dstTW) \ 70 do { \ 71 if (grayscale = clrdata->grayscale) { \ 72 InitGrayDither(cvdata, clrdata, dstTW); \ 73 } else { \ 74 InitColorDither(cvdata, clrdata, dstTW); \ 75 } \ 76 } while (0) 77 78#define StartAnyDitherLine(cvdata, dstX1, dstY) \ 79 do { \ 80 if (grayscale) { \ 81 StartGrayDitherLine(cvdata, dstX1, dstY); \ 82 } else { \ 83 StartColorDitherLine(cvdata, dstX1, dstY); \ 84 } \ 85 } while (0) 86 87#define AnyDitherPixel(dstX, dstY, pixel, red, green, blue) \ 88 do { \ 89 if (grayscale) { \ 90 GrayDitherPixel(dstX, dstY, pixel, red, green, blue); \ 91 } else { \ 92 ColorDitherPixel(dstX, dstY, pixel, red, green, blue); \ 93 } \ 94 } while (0) 95 96#define AnyDitherBufComplete(cvdata, dstX1) \ 97 do { \ 98 if (grayscale) { \ 99 GrayDitherBufComplete(cvdata, dstX1); \ 100 } else { \ 101 ColorDitherBufComplete(cvdata, dstX1); \ 102 } \ 103 } while (0) 104