summaryrefslogtreecommitdiff
path: root/src/testpattern/testpatterny.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/testpattern/testpatterny.y')
-rw-r--r--src/testpattern/testpatterny.y593
1 files changed, 499 insertions, 94 deletions
diff --git a/src/testpattern/testpatterny.y b/src/testpattern/testpatterny.y
index 36bb996..6d92bad 100644
--- a/src/testpattern/testpatterny.y
+++ b/src/testpattern/testpatterny.y
@@ -1,5 +1,5 @@
/*
- * "$Id: testpatterny.y,v 1.3.2.1 2002/07/23 00:54:08 rlk Exp $"
+ * "$Id: testpatterny.y,v 1.26 2004/08/21 22:35:18 rlk Exp $"
*
* Test pattern generator for Gimp-Print
*
@@ -37,7 +37,6 @@ extern int yylex(void);
char *quotestrip(const char *i);
char *endstrip(const char *i);
-extern int mylineno;
extern char* yytext;
static int yyerror( const char *s )
@@ -46,31 +45,68 @@ static int yyerror( const char *s )
return 0;
}
+typedef struct
+{
+ const char *name;
+ int channel;
+} color_t;
+
+static color_t color_map[] =
+ {
+ { "black", 0 },
+ { "cyan", 1 },
+ { "red", 1 },
+ { "magenta", 2 },
+ { "green", 2 },
+ { "yellow", 3 },
+ { "blue", 3 },
+ { "l_black", 4 },
+ { "l_cyan", 5 },
+ { "l_magenta", 6 },
+ { "d_yellow", 4 },
+ { NULL, -1 }
+ };
+
+static int current_index = 0;
+static testpattern_t *current_testpattern;
+extern FILE *yyin;
+
+static int
+find_color(const char *name)
+{
+ int i = 0;
+ while (color_map[i].name)
+ {
+ if (strcmp(color_map[i].name, name) == 0)
+ return color_map[i].channel;
+ i++;
+ }
+ return -1;
+}
+
%}
%token <ival> tINT
%token <dval> tDOUBLE
%token <sval> tSTRING
-%token C_GAMMA
-%token M_GAMMA
-%token Y_GAMMA
-%token K_GAMMA
+%token CYAN
+%token L_CYAN
+%token MAGENTA
+%token L_MAGENTA
+%token YELLOW
+%token D_YELLOW
+%token BLACK
+%token L_BLACK
%token GAMMA
-%token C_LEVEL
-%token M_LEVEL
-%token Y_LEVEL
-%token LEVELS
+%token LEVEL
+%token STEPS
%token INK_LIMIT
-%token INK
-%token WIDTH
%token PRINTER
-%token INK_TYPE
-%token RESOLUTION
-%token MEDIA_SOURCE
-%token MEDIA_TYPE
-%token MEDIA_SIZE
-%token DITHER_ALGORITHM
+%token PARAMETER
+%token PARAMETER_INT
+%token PARAMETER_FLOAT
+%token PARAMETER_CURVE
%token DENSITY
%token TOP
%token LEFT
@@ -78,138 +114,507 @@ static int yyerror( const char *s )
%token VSIZE
%token BLACKLINE
%token PATTERN
+%token XPATTERN
+%token EXTENDED
%token IMAGE
+%token GRID
+%token SEMI
+%token CHANNEL
+%token CMYK
+%token KCMY
+%token RGB
+%token CMY
+%token GRAY
+%token WHITE
+%token RAW
+%token MODE
+%token PAGESIZE
+%token MESSAGE
+%token END
%start Thing
%%
-global_c_level: C_LEVEL tDOUBLE
- { global_c_level = $2; }
+COLOR: CYAN | L_CYAN | MAGENTA | L_MAGENTA
+ | YELLOW | D_YELLOW | BLACK | L_BLACK
;
-global_m_level: M_LEVEL tDOUBLE
- { global_m_level = $2; }
+
+cmykspec: CMYK tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>cmykspec %d\n", $2);
+ global_image_type = "CMYK";
+ global_channel_depth = 4;
+ global_invert_data = 0;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $2;
+ }
;
-global_y_level: Y_LEVEL tDOUBLE
- { global_y_level = $2; }
+
+kcmyspec: KCMY tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>kcmyspec %d\n", $2);
+ global_image_type = "KCMY";
+ global_channel_depth = 4;
+ global_invert_data = 0;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $2;
+ }
;
-global_c_gamma: C_GAMMA tDOUBLE
- { global_c_gamma = $2; }
+
+rgbspec: RGB tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>rgbspec %d\n", $2);
+ global_image_type = "RGB";
+ global_channel_depth = 3;
+ global_invert_data = 1;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $2;
+ }
;
-global_m_gamma: M_GAMMA tDOUBLE
- { global_m_gamma = $2; }
+
+cmyspec: CMY tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>cmyspec %d\n", $2);
+ global_image_type = "CMY";
+ global_channel_depth = 3;
+ global_invert_data = 0;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $2;
+ }
;
-global_y_gamma: Y_GAMMA tDOUBLE
- { global_y_gamma = $2; }
+
+grayspec: GRAY tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>grayspec %d\n", $2);
+ global_image_type = "Grayscale";
+ global_channel_depth = 1;
+ global_invert_data = 0;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $2;
+ }
+;
+
+whitespec: WHITE tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>whitespec %d\n", $2);
+ global_image_type = "Whitescale";
+ global_channel_depth = 1;
+ global_invert_data = 1;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $2;
+ }
+;
+
+extendedspec: EXTENDED tINT tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>extendedspec %d\n", $2);
+ global_image_type = "Raw";
+ global_invert_data = 0;
+ global_channel_depth = $2;
+ if ($2 == 8 || $2 == 16)
+ global_bit_depth = $3;
+ }
+;
+
+modespec: cmykspec | kcmyspec | rgbspec | cmyspec | grayspec | whitespec | extendedspec
+;
+
+inputspec: MODE modespec
+;
+
+level: LEVEL COLOR tDOUBLE
+ {
+ int channel = find_color($2.sval);
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>level %s %f\n", $2.sval, $3);
+ if (channel >= 0)
+ global_levels[channel] = $3;
+ }
+;
+
+channel_level: LEVEL tINT tDOUBLE
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>channel_level %d %f\n", $2, $3);
+ if ($2 >= 0 && $2 <= STP_CHANNEL_LIMIT)
+ global_levels[$2] = $3;
+ }
+;
+
+gamma: GAMMA COLOR tDOUBLE
+ {
+ int channel = find_color($2.sval);
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>gamma %s %f\n", $2.sval, $3);
+ if (channel >= 0)
+ global_gammas[channel] = $3;
+ }
;
-global_k_gamma: K_GAMMA tDOUBLE
- { global_k_gamma = $2; }
+
+channel_gamma: GAMMA tINT tDOUBLE
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>channel_gamma %d %f\n", $2, $3);
+ if ($2 >= 0 && $2 <= STP_CHANNEL_LIMIT)
+ global_gammas[$2] = $3;
+ }
;
+
global_gamma: GAMMA tDOUBLE
- { global_gamma = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>global_gamma %f\n", $2);
+ global_gamma = $2;
+ }
;
-levels: LEVELS tINT
- { levels = $2; }
+steps: STEPS tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>steps %d\n", $2);
+ global_steps = $2;
+ }
;
ink_limit: INK_LIMIT tDOUBLE
- { ink_limit = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>ink_limit %f\n", $2);
+ global_ink_limit = $2;
+ }
;
printer: PRINTER tSTRING
- { printer = c_strdup($2); }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>printer %s\n", $2);
+ global_printer = strdup($2);
+ free($2);
+ }
;
-ink_type: INK_TYPE tSTRING
- { ink_type = c_strdup($2); }
+
+page_size_name: PAGESIZE tSTRING
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>page_size_name %s\n", $2);
+ stp_set_string_parameter(global_vars, "PageSize", $2);
+ free($2);
+ }
;
-resolution: RESOLUTION tSTRING
- { resolution = c_strdup($2); }
+
+page_size_custom: PAGESIZE tINT tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>page_size_custom %d %d\n", $2, $3);
+ stp_set_page_width(global_vars, $2);
+ stp_set_page_height(global_vars, $3);
+ }
;
-media_source: MEDIA_SOURCE tSTRING
- { media_source = c_strdup($2); }
+
+page_size: page_size_name | page_size_custom
;
-media_type: MEDIA_TYPE tSTRING
- { media_type = c_strdup($2); }
+
+parameter_string: PARAMETER tSTRING tSTRING
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>parameter_string %s %s\n", $2, $3);
+ stp_set_string_parameter(global_vars, $2, $3);
+ free($2);
+ free($3);
+ }
+;
+
+parameter_int: PARAMETER_INT tSTRING tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>parameter_int %s %d\n", $2, $3);
+ stp_set_int_parameter(global_vars, $2, $3);
+ free($2);
+ }
;
-media_size: MEDIA_SIZE tSTRING
- { media_size = c_strdup($2); }
+
+parameter_float: PARAMETER_FLOAT tSTRING tDOUBLE
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>parameter_float %s %f\n", $2, $3);
+ stp_set_float_parameter(global_vars, $2, $3);
+ free($2);
+ }
+;
+
+parameter_curve: PARAMETER_CURVE tSTRING tSTRING
+ {
+ stp_curve_t *curve = stp_curve_create_from_string($3);
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>parameter_curve %s %s\n", $2, $3);
+ if (curve)
+ {
+ stp_set_curve_parameter(global_vars, $2, curve);
+ stp_curve_destroy(curve);
+ }
+ free($2);
+ }
;
-dither_algorithm: DITHER_ALGORITHM tSTRING
- { dither_algorithm = c_strdup($2); }
+
+parameter: parameter_string | parameter_int | parameter_float
;
density: DENSITY tDOUBLE
- { density = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>density %f\n", $2);
+ global_density = $2;
+ }
;
top: TOP tDOUBLE
- { xtop = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>top %f\n", $2);
+ global_xtop = $2;
+ }
;
left: LEFT tDOUBLE
- { xleft = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>left %f\n", $2);
+ global_xleft = $2;
+ }
;
hsize: HSIZE tDOUBLE
- { hsize = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>hsize %f\n", $2);
+ global_hsize = $2;
+ }
;
vsize: VSIZE tDOUBLE
- { vsize = $2; }
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>vsize %f\n", $2);
+ global_vsize = $2;
+ }
;
blackline: BLACKLINE tINT
- { noblackline = !($2); }
-;
-
-pattern: PATTERN tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE
- tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE
- tDOUBLE tDOUBLE
- {
- testpattern_t *t = get_next_testpattern();
- t->t = E_PATTERN;
- t->d.p.c_min = $2;
- t->d.p.c = $3;
- t->d.p.c_gamma = $4;
- t->d.p.m_min = $5;
- t->d.p.m = $6;
- t->d.p.m_gamma = $7;
- t->d.p.y_min = $8;
- t->d.p.y = $9;
- t->d.p.y_gamma = $10;
- t->d.p.k_min = $11;
- t->d.p.k = $12;
- t->d.p.k_gamma = $13;
- t->d.p.c_level = $14;
- t->d.p.m_level = $15;
- t->d.p.y_level = $16;
- t->d.p.lower = $17;
- t->d.p.upper = $18;
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>blackline %d\n", $2);
+ global_noblackline = !($2);
+ }
+;
+
+color_block1: tDOUBLE tDOUBLE tDOUBLE
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>color_block1 %f %f %f (%d)\n", $1, $2, $3,
+ current_index);
+ if (current_index < STP_CHANNEL_LIMIT)
+ {
+ current_testpattern->d.p.mins[current_index] = $1;
+ current_testpattern->d.p.vals[current_index] = $2;
+ current_testpattern->d.p.gammas[current_index] = $3;
+ current_index++;
+ }
+ }
+;
+
+color_blocks1a: color_block1 | color_blocks1a color_block1
+;
+
+color_blocks1b: /* empty */ | color_blocks1a
+;
+
+color_blocks1: color_block1 color_blocks1b
+;
+
+color_block2a: COLOR tDOUBLE tDOUBLE tDOUBLE
+ {
+ int channel = find_color($1.sval);
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>color_block2a %s %f %f %f\n", $1.sval, $2, $3, $4);
+ if (channel >= 0 && channel < STP_CHANNEL_LIMIT)
+ {
+ current_testpattern->d.p.mins[channel] = $2;
+ current_testpattern->d.p.vals[channel] = $3;
+ current_testpattern->d.p.gammas[channel] = $4;
+ }
+ }
+;
+
+color_block2b: CHANNEL tINT tDOUBLE tDOUBLE tDOUBLE
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>color_block2b %d %f %f %f\n", $2, $3, $4, $5);
+ if ($2 >= 0 && $2 < STP_CHANNEL_LIMIT)
+ {
+ current_testpattern->d.p.mins[$2] = $3;
+ current_testpattern->d.p.vals[$2] = $4;
+ current_testpattern->d.p.gammas[$2] = $5;
+ }
+ }
+;
+
+color_block2: color_block2a | color_block2b
+;
+
+color_blocks2a: color_block2 | color_blocks2a color_block2
+;
+
+color_blocks2: /* empty */ | color_blocks2a
+;
+
+color_blocks: color_blocks1 | color_blocks2
+;
+
+patvars: tDOUBLE tDOUBLE tDOUBLE tDOUBLE tDOUBLE
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>patvars %f %f %f %f %f\n", $1, $2, $3, $4, $5);
+ current_testpattern->t = E_PATTERN;
+ current_testpattern->d.p.lower = $1;
+ current_testpattern->d.p.upper = $2;
+ current_testpattern->d.p.levels[1] = $3;
+ current_testpattern->d.p.levels[2] = $4;
+ current_testpattern->d.p.levels[3] = $5;
+ current_testpattern = get_next_testpattern();
+ current_index = 0;
+ }
+;
+
+pattern: PATTERN patvars color_blocks
+;
+
+xpattern: XPATTERN color_blocks
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>xpattern\n");
+ if (global_channel_depth == 0)
+ {
+ fprintf(stderr, "xpattern may only be used with extended color depth\n");
+ exit(1);
+ }
+ current_testpattern->t = E_XPATTERN;
+ current_testpattern = get_next_testpattern();
+ current_index = 0;
+ }
+;
+
+grid: GRID tINT
+ {
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>grid %d\n", $2);
+ current_testpattern->t = E_GRID;
+ current_testpattern->d.g.ticks = $2;
+ current_testpattern = get_next_testpattern();
+ current_index = 0;
}
;
image: IMAGE tINT tINT
{
- testpattern_t *t = get_next_testpattern();
- t->t = E_IMAGE;
- t->d.i.x = $2;
- t->d.i.y = $3;
- if (t->d.i.x <= 0 || t->d.i.y <= 0)
+ if (getenv("STP_TESTPATTERN_DEBUG"))
+ fprintf(stderr, ">>>image %d %d\n", $2, $3);
+ current_testpattern->t = E_IMAGE;
+ current_testpattern->d.i.x = $2;
+ current_testpattern->d.i.y = $3;
+ if (current_testpattern->d.i.x <= 0 ||
+ current_testpattern->d.i.y <= 0)
{
fprintf(stderr, "image width and height must be greater than zero\n");
exit(1);
}
return 0;
}
+;
+
+Message0: MESSAGE tSTRING
+ {
+ fprintf(stderr, $2);
+ free($2);
+ }
+;
+Message1: MESSAGE tSTRING tSTRING
+ {
+ fprintf(stderr, $2, $3);
+ free($2);
+ free($3);
+ }
+;
+Message2: MESSAGE tSTRING tSTRING tSTRING
+ {
+ fprintf(stderr, $2, $3, $4);
+ free($2);
+ free($3);
+ free($4);
+ }
+;
+Message3: MESSAGE tSTRING tSTRING tSTRING tSTRING
+ {
+ fprintf(stderr, $2, $3, $4, $5);
+ free($2);
+ free($3);
+ free($4);
+ free($5);
+ }
+;
+Message4: MESSAGE tSTRING tSTRING tSTRING tSTRING tSTRING
+ {
+ fprintf(stderr, $2, $3, $4, $5, $6);
+ free($2);
+ free($3);
+ free($4);
+ free($5);
+ free($6);
+ }
+;
+
+A_Message: Message0 | Message1 | Message2 | Message3 | Message4
+;
+
+message: A_Message
+;
+
+A_Rule: gamma | channel_gamma | level | channel_level | global_gamma | steps
+ | ink_limit | printer | parameter | density | top | left | hsize
+ | vsize | blackline | inputspec | page_size | message
+;
+
+Rule: A_Rule SEMI
+ { global_did_something = 1; }
+;
-Empty:
+A_Pattern: pattern | xpattern | grid | message
+;
-Rule: global_c_level | global_m_level | global_y_level
- | global_c_gamma | global_m_gamma | global_y_gamma | global_k_gamma
- | global_gamma | levels | ink_limit | printer | ink_type | resolution
- | media_source | media_type | media_size | dither_algorithm | density
- | top | left | hsize | vsize | blackline
+Pattern: A_Pattern SEMI
+ { global_did_something = 1; }
+;
-Patterns: Patterns pattern | Empty
+Patterns: /* empty */ | Patterns Pattern
+;
Image: image
+ { global_did_something = 1; }
+;
-Rules: Rules Rule | Empty
+Rules: /* empty */ | Rules Rule
+;
Output: Patterns | Image
+;
-Thing: Rules Output Empty
+EOF: /* empty */ | END SEMI
+ { return 0; }
+;
+
+Thing: Rules
+ {
+ current_testpattern = get_next_testpattern();
+ }
+ Output EOF
+;
%%