/* * Copyright (c) 1992 The Regents of the University of California. * All rights reserved. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose, without fee, and without written agreement is * hereby granted, provided that the above copyright notice and the following * two paragraphs appear in all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ /* This file contains C code to implement an ordered dither. */ #include "display.h" #define DITH_SIZE 16 /* Structures used to implement hybrid ordered dither/floyd-steinberg dither algorithm. */ static unsigned char *l_darrays[DITH_SIZE]; static unsigned char *cr_darrays[DITH_SIZE]; static unsigned char *cb_darrays[DITH_SIZE]; /* *-------------------------------------------------------------- * * InitOrderedDither-- * * Structures intialized for ordered dithering. * * Results: * None. * * Side effects: * None. * *-------------------------------------------------------------- */ void InitOrderedDither() { int i, j, k, err_range, threshval; unsigned char *lmark, *cmark; for (i=0; i threshval) *lmark++ = ((j+1) * (CR_RANGE * CB_RANGE)); else *lmark++ = (j * (CR_RANGE * CB_RANGE)); } } for (j=lum_values[LUM_RANGE-1]; j<256; j++) { *lmark++ = (LUM_RANGE-1)*(CR_RANGE * CB_RANGE); } } for (i=0; i threshval) *cmark++ = ((j+1) * CB_RANGE); else *cmark++ = (j * CB_RANGE); } } for (j=cr_values[CR_RANGE-1]; j<256; j++) { *cmark++ = (CR_RANGE-1)*(CB_RANGE); } } for (i=0; i threshval) *cmark++ = j+1; else *cmark++ = j; } } for (j=cb_values[CB_RANGE-1]; j<256; j++) { *cmark++ = CB_RANGE-1; } } } /* *-------------------------------------------------------------- * * OrderedDitherImage -- * * Dithers an image using an ordered dither. * Assumptions made: * 1) The color space is allocated y:cr:cb = 8:4:4 * 2) The spatial resolution of y:cr:cb is 4:1:1 * The channels are dithered based on the standard * ordered dither pattern for a 4x4 area. * * Results: * None. * * Side effects: * None. * *-------------------------------------------------------------- */ void OrderedDitherImage (lum, cr, cb, out, h, w) unsigned char *lum; unsigned char *cr; unsigned char *cb; unsigned char *out; int w, h; { unsigned char *l, *r, *b, *o1, *o2; unsigned char *l2; unsigned char L, R, B; int i, j; l = lum; l2 = lum+w; r = cr; b = cb; o1 = out; o2 = out+w; for (i=0; i