Utah Raster Toolkit  9999-git
URT Development version (post-3.1b)
Macros | Functions | Variables
dither.c File Reference
#include <math.h>
Include dependency graph for dither.c:

Go to the source code of this file.

Macros

#define DMAP(v, x, y)   (modN[v]>magic[x][y] ? divN[v] + 1 : divN[v])
 

Functions

void make_square ()
 
void dithermap (int levels, double gamma, rgbmap, divN, modN, magic)
 
void bwdithermap (int levels, double gamma, bwmap, divN, modN, magic)
 
void make_square (double N, divN, modN, magic)
 
int dithergb (int x, int y, int r, int g, int b, int levels, divN, modN, magic)
 
int ditherbw (int x, int y, int val, divN, modN, magic)
 

Variables

static char rcsid [] = "$Header: /l/spencer/src/urt/lib/RCS/dither.c,v 3.0.1.2 1992/04/30 14:07:02 spencer Exp $"
 
static int magic4x4 [4][4]
 

Macro Definition Documentation

#define DMAP (   v,
  x,
  y 
)    (modN[v]>magic[x][y] ? divN[v] + 1 : divN[v])

Definition at line 48 of file dither.c.

Function Documentation

void bwdithermap ( int  levels,
double  gamma,
bwmap  ,
divN  ,
modN  ,
magic   
)

Definition at line 142 of file dither.c.

Referenced by init_color(), and init_monochrome_colour_map().

149 {
150  double N;
151  register int i;
152  int gammamap[256];
153 
154  for ( i = 0; i < 256; i++ )
155  gammamap[i] = (int)(0.5 + 255 * pow( i / 255.0, 1.0/gamma ));
156 
157  N = 255.0 / (levels - 1); /* Get size of each step */
158 
159  /*
160  * Set up the color map entries.
161  */
162  for(i = 0; i < levels; i++)
163  bwmap[i] = gammamap[(int)(0.5 + i * N)];
164 
165  make_square( N, divN, modN, magic );
166 }
int gammamap[256]
Definition: rletopaint.c:59
int modN[256]
Definition: getap.c:80
void make_square()
#define N(node)
Definition: mcut.c:45
#define levels
Definition: getmex.c:31
int gamma(int x, float gamma_value)
Definition: gamma.c:24
int i
Definition: rletorla.c:82
int divN[256]
Definition: get_orion.c:51

Here is the caller graph for this function:

int ditherbw ( int  x,
int  y,
int  val,
divN  ,
modN  ,
magic   
)

Definition at line 279 of file dither.c.

284 {
285  int col = x % 16, row = y % 16;
286 
287  return DMAP(val, col, row);
288 }
static int y
Definition: getami.c:691
#define DMAP(v, x, y)
Definition: dither.c:48
static int x
Definition: getami.c:691
int row
Definition: rle.c:27
int dithergb ( int  x,
int  y,
int  r,
int  g,
int  b,
int  levels,
divN  ,
modN  ,
magic   
)

Definition at line 247 of file dither.c.

252 {
253  int col = x % 16, row = y % 16;
254 
255  return DMAP(r, col, row) +
256  DMAP(g, col, row) * levels +
257  DMAP(b, col, row) * levels*levels;
258 }
static unsigned char g
Definition: getami.c:692
static unsigned char r
Definition: getami.c:692
static int y
Definition: getami.c:691
#define DMAP(v, x, y)
Definition: dither.c:48
static unsigned char b
Definition: getami.c:692
static int x
Definition: getami.c:691
#define levels
Definition: getmex.c:31
int row
Definition: rle.c:27
void dithermap ( int  levels,
double  gamma,
rgbmap  ,
divN  ,
modN  ,
magic   
)

Definition at line 80 of file dither.c.

Referenced by init_8_bit_colour_map(), and init_color().

87 {
88  double N;
89  register int i;
90  int levelsq, levelsc;
91  int gammamap[256];
92 
93  for ( i = 0; i < 256; i++ )
94  gammamap[i] = (int)(0.5 + 255 * pow( i / 255.0, 1.0/gamma ));
95 
96  levelsq = levels*levels; /* squared */
97  levelsc = levels*levelsq; /* and cubed */
98 
99  N = 255.0 / (levels - 1); /* Get size of each step */
100 
101  /*
102  * Set up the color map entries.
103  */
104  for(i = 0; i < levelsc; i++) {
105  rgbmap[i][0] = gammamap[(int)(0.5 + (i%levels) * N)];
106  rgbmap[i][1] = gammamap[(int)(0.5 + ((i/levels)%levels) * N)];
107  rgbmap[i][2] = gammamap[(int)(0.5 + ((i/levelsq)%levels) * N)];
108  }
109 
110  make_square( N, divN, modN, magic );
111 }
int gammamap[256]
Definition: rletopaint.c:59
int modN[256]
Definition: getap.c:80
void make_square()
#define N(node)
Definition: mcut.c:45
#define levels
Definition: getmex.c:31
int gamma(int x, float gamma_value)
Definition: gamma.c:24
int
Definition: getami.c:848
int i
Definition: rletorla.c:82
int levelsq
Definition: getsun.c:73
int levelsc
Definition: getsun.c:73
int divN[256]
Definition: get_orion.c:51

Here is the caller graph for this function:

void make_square ( )
void make_square ( double  N,
divN  ,
modN  ,
magic   
)

Definition at line 192 of file dither.c.

Referenced by init_8_bit_color_map(), init_color(), init_dither(), and window_color_map().

197 {
198  register int i, j, k, l;
199  double magicfact;
200 
201  for ( i = 0; i < 256; i++ )
202  {
203  divN[i] = (int)(i / N);
204  modN[i] = i - (int)(N * divN[i]);
205  }
206  modN[255] = 0; /* always */
207 
208  /*
209  * Expand 4x4 dither pattern to 16x16. 4x4 leaves obvious patterning,
210  * and doesn't give us full intensity range (only 17 sublevels).
211  *
212  * magicfact is (N - 1)/16 so that we get numbers in the matrix from 0 to
213  * N - 1: mod N gives numbers in 0 to N - 1, don't ever want all
214  * pixels incremented to the next level (this is reserved for the
215  * pixel value with mod N == 0 at the next level).
216  */
217  magicfact = (N - 1) / 16.;
218  for ( i = 0; i < 4; i++ )
219  for ( j = 0; j < 4; j++ )
220  for ( k = 0; k < 4; k++ )
221  for ( l = 0; l < 4; l++ )
222  magic[4*k+i][4*l+j] =
223  (int)(0.5 + magic4x4[i][j] * magicfact +
224  (magic4x4[k][l] / 16.) * magicfact);
225 }
int modN[256]
Definition: getap.c:80
#define N(node)
Definition: mcut.c:45
int
Definition: getami.c:848
static int magic4x4[4][4]
Definition: dither.c:40
int i
Definition: rletorla.c:82
int divN[256]
Definition: get_orion.c:51

Here is the caller graph for this function:

Variable Documentation

int magic4x4[4][4]
static
Initial value:
= {
{ 0, 14, 3, 13},
{ 11, 5, 8, 6},
{ 12, 2, 15, 1},
{ 7, 9, 4, 10}
}

Definition at line 40 of file dither.c.

char rcsid[] = "$Header: /l/spencer/src/urt/lib/RCS/dither.c,v 3.0.1.2 1992/04/30 14:07:02 spencer Exp $"
static

Definition at line 30 of file dither.c.