1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
/*
* "$Id$"
*
* Dither test program for CUPS.
*
* Try the following:
*
* testdither 0 255 > filename.ppm
* testdither 0 127 255 > filename.ppm
* testdither 0 85 170 255 > filename.ppm
* testdither 0 63 127 170 198 227 255 > filename.ppm
* testdither 0 210 383 > filename.ppm
* testdither 0 82 255 > filename.ppm
*
* Copyright 2007-2011 by Apple Inc.
* Copyright 1993-2005 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
* law. Distribution and use rights are outlined in the file "LICENSE.txt"
* which should have been included with this file. If this file is
* file is missing or damaged, see the license at "http://www.cups.org/".
*
* Contents:
*
* main() - Test dithering and output a PPM file.
* usage() - Show program usage...
*/
/*
* Include necessary headers.
*/
#include "driver.h"
#include <config.h>
#include <string.h>
#include <ctype.h>
/*
* Local functions...
*/
void usage(void);
/*
* 'main()' - Test dithering and output a PPM file.
*/
int /* O - Exit status */
main(int argc, /* I - Number of command-line arguments */
char *argv[]) /* I - Command-line arguments */
{
int x, y; /* Current coordinate in image */
short line[512]; /* Line to dither */
unsigned char pixels[512], /* Dither pixels */
*pixptr; /* Pointer in line */
int output; /* Output pixel */
cups_lut_t *lut; /* Dither lookup table */
cups_dither_t *dither; /* Dither state */
int nlutvals; /* Number of lookup values */
float lutvals[16]; /* Lookup values */
int pixvals[16]; /* Pixel values */
/*
* See if we have lookup table values on the command-line...
*/
if (argc > 1)
{
/*
* Yes, collect them...
*/
nlutvals = 0;
for (x = 1; x < argc; x ++)
if (isdigit(argv[x][0]) && nlutvals < 16)
{
pixvals[nlutvals] = atoi(argv[x]);
lutvals[nlutvals] = atof(argv[x]) / 255.0;
nlutvals ++;
}
else
usage();
/*
* See if we have at least 2 values...
*/
if (nlutvals < 2)
usage();
}
else
{
/*
* Otherwise use the default 2-entry LUT with values of 0 and 255...
*/
nlutvals = 2;
lutvals[0] = 0.0;
lutvals[1] = 1.0;
pixvals[0] = 0;
pixvals[1] = 255;
}
/*
* Create the lookup table and dither state...
*/
lut = cupsLutNew(nlutvals, lutvals);
dither = cupsDitherNew(512);
/*
* Put out the PGM header for a raw 256x256x8-bit grayscale file...
*/
puts("P5\n512\n512\n255");
/*
* Dither 512 lines, which are written out in 256 image lines...
*/
for (y = 0; y < 512; y ++)
{
/*
* Create the grayscale data for the current line...
*/
for (x = 0; x < 512; x ++)
line[x] = 4095 * ((y / 32) * 16 + x / 32) / 255;
/*
* Dither the line...
*/
cupsDitherLine(dither, lut, line, 1, pixels);
if (y == 0)
{
fputs("DEBUG: pixels =", stderr);
for (x = 0; x < 512; x ++)
fprintf(stderr, " %d", pixels[x]);
fputs("\n", stderr);
}
/*
* Add or set the output pixel values...
*/
for (x = 0, pixptr = pixels; x < 512; x ++, pixptr ++)
{
output = 255 - pixvals[*pixptr];
if (output < 0)
putchar(0);
else
putchar(output);
}
}
/*
* Free the dither state and lookup table...
*/
cupsDitherDelete(dither);
cupsLutDelete(lut);
/*
* Return with no errors...
*/
return (0);
}
/*
* 'usage()' - Show program usage...
*/
void
usage(void)
{
puts("Usage: testdither [val1 val2 [... val16]] >filename.ppm");
exit(1);
}
/*
* End of "$Id$".
*/
|