diff options
author | L Peter Deutsch <lpd@ghostscript.com> | 2000-03-19 07:24:53 +0000 |
---|---|---|
committer | L Peter Deutsch <lpd@ghostscript.com> | 2000-03-19 07:24:53 +0000 |
commit | 51d9850c022eb54f2cc8bcf4fb5d1510f8a1c847 (patch) | |
tree | cb91df0aabe1723ebd5469fdfc0decebfa13d5aa | |
parent | 66dc185ada48b72daae851a9383ff771d05f9bb3 (diff) |
Adds virtual procedures for Functions to write their parameters to a
parameter list, and to access their data source and subfunctions. This is
needed for writing Functions in PDF files. This change is also a
prerequisite for the C implemention of FunctionType 4 functions, even though
it appears later in the change log.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@142 a1074d23-0009-0410-80fe-cf8c14f379e6
-rw-r--r-- | gs/src/gsdsrc.h | 6 | ||||
-rw-r--r-- | gs/src/gsfunc.c | 35 | ||||
-rw-r--r-- | gs/src/gsfunc.h | 82 | ||||
-rw-r--r-- | gs/src/gsfunc0.c | 56 | ||||
-rw-r--r-- | gs/src/gsfunc3.c | 63 | ||||
-rw-r--r-- | gs/src/gsparam.c | 18 | ||||
-rw-r--r-- | gs/src/gsparam.h | 6 | ||||
-rw-r--r-- | gs/src/gxfunc.h | 6 |
8 files changed, 252 insertions, 20 deletions
diff --git a/gs/src/gsdsrc.h b/gs/src/gsdsrc.h index 5dd5a9de1..28983bb93 100644 --- a/gs/src/gsdsrc.h +++ b/gs/src/gsdsrc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved. This file is part of Aladdin Ghostscript. @@ -40,7 +40,6 @@ #ifndef stream_DEFINED # define stream_DEFINED typedef struct stream_s stream; - #endif /* @@ -60,7 +59,10 @@ typedef enum { data_source_type_floats, data_source_type_stream } gs_data_source_type_t; +#ifndef gs_data_source_DEFINED +# define gs_data_source_DEFINED typedef struct gs_data_source_s gs_data_source_t; +#endif struct gs_data_source_s { data_source_proc_access((*access)); gs_data_source_type_t type; diff --git a/gs/src/gsfunc.c b/gs/src/gsfunc.c index 435497b4f..c0b8b55b1 100644 --- a/gs/src/gsfunc.c +++ b/gs/src/gsfunc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved. This file is part of Aladdin Ghostscript. @@ -20,6 +20,7 @@ /* Generic Function support */ #include "gx.h" #include "gserrors.h" +#include "gsparam.h" #include "gxfunc.h" /* GC descriptors */ @@ -77,6 +78,36 @@ fn_domain_is_monotonic(const gs_function_t *pfn, gs_function_effort_t effort) return gs_function_is_monotonic(pfn, lower, upper, effort); } +/* Return default function information. */ +void +gs_function_get_info_default(const gs_function_t *pfn, gs_function_info_t *pfi) +{ + pfi->DataSource = 0; + pfi->Functions = 0; +} + +/* Write generic parameters (FunctionType, Domain, Range) on a parameter list. */ +int +fn_common_get_params(const gs_function_t *pfn, gs_param_list *plist) +{ + int ecode = param_write_int(plist, "FunctionType", &FunctionType(pfn)); + int code; + + if (pfn->params.Domain) { + code = param_write_float_values(plist, "Domain", pfn->params.Domain, + 2 * pfn->params.m, false); + if (code < 0) + ecode = code; + } + if (pfn->params.Range) { + code = param_write_float_values(plist, "Range", pfn->params.Range, + 2 * pfn->params.n, false); + if (code < 0) + ecode = code; + } + return ecode; +} + /* ---------------- Vanilla functions ---------------- */ /* GC descriptor */ @@ -117,6 +148,8 @@ gs_function_Va_init(gs_function_t ** ppfn, { NULL, /* filled in from params */ (fn_is_monotonic_proc_t) fn_Va_is_monotonic, + gs_function_get_info_default, + fn_common_get_params, /****** WHAT TO DO ABOUT THIS? ******/ (fn_free_params_proc_t) gs_function_Va_free_params, fn_common_free } diff --git a/gs/src/gsfunc.h b/gs/src/gsfunc.h index 55338e3e6..daff32781 100644 --- a/gs/src/gsfunc.h +++ b/gs/src/gsfunc.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved. This file is part of Aladdin Ghostscript. @@ -49,24 +49,68 @@ typedef enum { EFFORT_ESSENTIAL = 2 } gs_function_effort_t; +/* Define abstract types. */ +#ifndef gs_data_source_DEFINED +# define gs_data_source_DEFINED +typedef struct gs_data_source_s gs_data_source_t; +#endif +#ifndef gs_param_list_DEFINED +# define gs_param_list_DEFINED +typedef struct gs_param_list_s gs_param_list; +#endif + /* Define a generic function, for use as the target type of pointers. */ typedef struct gs_function_params_s { gs_function_params_common; } gs_function_params_t; +#ifndef gs_function_DEFINED typedef struct gs_function_s gs_function_t; -typedef int (*fn_evaluate_proc_t)(P3(const gs_function_t * pfn, - const float *in, float *out)); -typedef int (*fn_is_monotonic_proc_t)(P4(const gs_function_t * pfn, - const float *lower, - const float *upper, - gs_function_effort_t effort)); -typedef void (*fn_free_params_proc_t)(P2(gs_function_params_t * params, - gs_memory_t * mem)); -typedef void (*fn_free_proc_t)(P3(gs_function_t * pfn, - bool free_params, gs_memory_t * mem)); +# define gs_function_DEFINED +#endif +typedef struct gs_function_info_s { + const gs_data_source_t *DataSource; + ulong data_size; + const gs_function_t *const *Functions; + int num_Functions; +} gs_function_info_t; + +/* Evaluate a function. */ +#define FN_EVALUATE_PROC(proc)\ + int proc(P3(const gs_function_t * pfn, const float *in, float *out)) +typedef FN_EVALUATE_PROC((*fn_evaluate_proc_t)); + +/* Test whether a function is monotonic. */ +#define FN_IS_MONOTONIC_PROC(proc)\ + int proc(P4(const gs_function_t * pfn, const float *lower,\ + const float *upper, gs_function_effort_t effort)) +typedef FN_IS_MONOTONIC_PROC((*fn_is_monotonic_proc_t)); + +/* Get function information. */ +#define FN_GET_INFO_PROC(proc)\ + void proc(P2(const gs_function_t *pfn, gs_function_info_t *pfi)) +typedef FN_GET_INFO_PROC((*fn_get_info_proc_t)); + +/* Put function parameters on a parameter list. */ +#define FN_GET_PARAMS_PROC(proc)\ + int proc(P2(const gs_function_t *pfn, gs_param_list *plist)) +typedef FN_GET_PARAMS_PROC((*fn_get_params_proc_t)); + +/* Free function parameters. */ +#define FN_FREE_PARAMS_PROC(proc)\ + void proc(P2(gs_function_params_t * params, gs_memory_t * mem)) +typedef FN_FREE_PARAMS_PROC((*fn_free_params_proc_t)); + +/* Free a function. */ +#define FN_FREE_PROC(proc)\ + void proc(P3(gs_function_t * pfn, bool free_params, gs_memory_t * mem)) +typedef FN_FREE_PROC((*fn_free_proc_t)); + +/* Define the generic function structures. */ typedef struct gs_function_procs_s { fn_evaluate_proc_t evaluate; fn_is_monotonic_proc_t is_monotonic; + fn_get_info_proc_t get_info; + fn_get_params_proc_t get_params; fn_free_params_proc_t free_params; fn_free_proc_t free; } gs_function_procs_t; @@ -118,7 +162,7 @@ void gs_function_XxYy_free_params(P2(gs_function_XxYy_params_t *params, /* Evaluate a function. */ #define gs_function_evaluate(pfn, in, out)\ - (*(pfn)->head.procs.evaluate)(pfn, in, out) + ((pfn)->head.procs.evaluate)(pfn, in, out) /* * Test whether a function is monotonic on a given (closed) interval. If @@ -128,7 +172,7 @@ void gs_function_XxYy_free_params(P2(gs_function_XxYy_params_t *params, * domain. If lower[i] > upper[i], the result is not defined. */ #define gs_function_is_monotonic(pfn, lower, upper, effort)\ - (*(pfn)->head.procs.is_monotonic)(pfn, lower, upper, effort) + ((pfn)->head.procs.is_monotonic)(pfn, lower, upper, effort) /* * If the function is monotonic, is_monotonic returns the direction of * monotonicity for output value N in bits 2N and 2N+1. (Functions with @@ -137,13 +181,21 @@ void gs_function_XxYy_free_params(P2(gs_function_XxYy_params_t *params, #define FN_MONOTONIC_INCREASING 1 #define FN_MONOTONIC_DECREASING 2 +/* Get function information. */ +#define gs_function_get_info(pfn, pfi)\ + ((pfn)->head.procs.get_info(pfn, pfi)) + +/* Write function parameters. */ +#define gs_function_get_params(pfn, plist)\ + ((pfn)->head.procs.get_params(pfn, plist)) + /* Free function parameters. */ #define gs_function_free_params(pfn, mem)\ - (*(pfn)->head.procs.free_params)(&(pfn)->params, mem) + ((pfn)->head.procs.free_params(&(pfn)->params, mem)) /* Free a function's implementation, optionally including its parameters. */ #define gs_function_free(pfn, free_params, mem)\ - (*(pfn)->head.procs.free)(pfn, free_params, mem) + ((pfn)->head.procs.free(pfn, free_params, mem)) /* ---------------- Vanilla functions ---------------- */ diff --git a/gs/src/gsfunc0.c b/gs/src/gsfunc0.c index fb54e5079..5eec4565c 100644 --- a/gs/src/gsfunc0.c +++ b/gs/src/gsfunc0.c @@ -22,6 +22,7 @@ #include "gx.h" #include "gserrors.h" #include "gsfunc0.h" +#include "gsparam.h" #include "gxfarith.h" #include "gxfunc.h" @@ -338,6 +339,59 @@ fn_Sd_is_monotonic(const gs_function_t * pfn_common, return result; } +/* Return Sampled function information. */ +private void +fn_Sd_get_info(const gs_function_t *pfn_common, gs_function_info_t *pfi) +{ + const gs_function_Sd_t *const pfn = + (const gs_function_Sd_t *)pfn_common; + long size; + int i; + + gs_function_get_info_default(pfn_common, pfi); + pfi->DataSource = &pfn->params.DataSource; + for (i = 0, size = 1; i < pfn->params.m; ++i) + size *= pfn->params.Size[i]; + pfi->data_size = + (size * pfn->params.n * pfn->params.BitsPerSample + 7) >> 3; +} + +/* Write Sampled function parameters on a parameter list. */ +private int +fn_Sd_get_params(const gs_function_t *pfn_common, gs_param_list *plist) +{ + const gs_function_Sd_t *const pfn = + (const gs_function_Sd_t *)pfn_common; + int ecode = fn_common_get_params(pfn_common, plist); + int code; + + if (pfn->params.Order != 1) { + if ((code = param_write_int(plist, "Order", &pfn->params.Order)) < 0) + ecode = code; + } + if ((code = param_write_int(plist, "BitsPerSample", + &pfn->params.BitsPerSample)) < 0) + ecode = code; + if (pfn->params.Encode) { + if ((code = param_write_float_values(plist, "Encode", + pfn->params.Encode, + 2 * pfn->params.m, false)) < 0) + ecode = code; + } + if (pfn->params.Decode) { + if ((code = param_write_float_values(plist, "Decode", + pfn->params.Decode, + 2 * pfn->params.n, false)) < 0) + ecode = code; + } + if (pfn->params.Size) { + if ((code = param_write_int_values(plist, "Size", pfn->params.Size, + pfn->params.m, false)) < 0) + ecode = code; + } + return ecode; +} + /* Free the parameters of a Sampled function. */ void gs_function_Sd_free_params(gs_function_Sd_params_t * params, gs_memory_t * mem) @@ -358,6 +412,8 @@ gs_function_Sd_init(gs_function_t ** ppfn, { (fn_evaluate_proc_t) fn_Sd_evaluate, (fn_is_monotonic_proc_t) fn_Sd_is_monotonic, + (fn_get_info_proc_t) fn_Sd_get_info, + (fn_get_params_proc_t) fn_Sd_get_params, (fn_free_params_proc_t) gs_function_Sd_free_params, fn_common_free } diff --git a/gs/src/gsfunc3.c b/gs/src/gsfunc3.c index 0e189ca06..c7c597d44 100644 --- a/gs/src/gsfunc3.c +++ b/gs/src/gsfunc3.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1997, 1998, 1999 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved. This file is part of Aladdin Ghostscript. @@ -22,6 +22,7 @@ #include "gx.h" #include "gserrors.h" #include "gsfunc3.h" +#include "gsparam.h" #include "gxfunc.h" /* ---------------- Utilities ---------------- */ @@ -121,6 +122,30 @@ fn_ElIn_is_monotonic(const gs_function_t * pfn_common, return result; } +/* Write Exponential Interpolation function parameters on a parameter list. */ +private int +fn_ElIn_get_params(const gs_function_t *pfn_common, gs_param_list *plist) +{ + const gs_function_ElIn_t *const pfn = + (const gs_function_ElIn_t *)pfn_common; + int ecode = fn_common_get_params(pfn_common, plist); + int code; + + if (pfn->params.C0) { + if ((code = param_write_float_values(plist, "C0", pfn->params.C0, + pfn->params.n, false)) < 0) + ecode = code; + } + if (pfn->params.C1) { + if ((code = param_write_float_values(plist, "C1", pfn->params.C1, + pfn->params.n, false)) < 0) + ecode = code; + } + if ((code = param_write_float(plist, "N", &pfn->params.N)) < 0) + ecode = code; + return ecode; +} + /* Free the parameters of an Exponential Interpolation function. */ void gs_function_ElIn_free_params(gs_function_ElIn_params_t * params, @@ -142,6 +167,8 @@ gs_function_ElIn_init(gs_function_t ** ppfn, { (fn_evaluate_proc_t) fn_ElIn_evaluate, (fn_is_monotonic_proc_t) fn_ElIn_is_monotonic, + gs_function_get_info_default, + (fn_get_params_proc_t) fn_ElIn_get_params, (fn_free_params_proc_t) gs_function_ElIn_free_params, fn_common_free } @@ -280,6 +307,36 @@ fn_1ItSg_is_monotonic(const gs_function_t * pfn_common, return result; } +/* Return 1-Input Stitching function information. */ +private void +fn_1ItSg_get_info(const gs_function_t *pfn_common, gs_function_info_t *pfi) +{ + const gs_function_1ItSg_t *const pfn = + (const gs_function_1ItSg_t *)pfn_common; + + gs_function_get_info_default(pfn_common, pfi); + pfi->Functions = pfn->params.Functions; + pfi->num_Functions = pfn->params.k; +} + +/* Write 1-Input Stitching function parameters on a parameter list. */ +private int +fn_1ItSg_get_params(const gs_function_t *pfn_common, gs_param_list *plist) +{ + const gs_function_1ItSg_t *const pfn = + (const gs_function_1ItSg_t *)pfn_common; + int ecode = fn_common_get_params(pfn_common, plist); + int code; + + if ((code = param_write_float_values(plist, "Bounds", pfn->params.Bounds, + pfn->params.k - 1, false)) < 0) + ecode = code; + if ((code = param_write_float_values(plist, "Encode", pfn->params.Encode, + 2 * pfn->params.k, false)) < 0) + ecode = code; + return ecode; +} + /* Free the parameters of a 1-Input Stitching function. */ void gs_function_1ItSg_free_params(gs_function_1ItSg_params_t * params, @@ -301,6 +358,8 @@ gs_function_1ItSg_init(gs_function_t ** ppfn, { (fn_evaluate_proc_t) fn_1ItSg_evaluate, (fn_is_monotonic_proc_t) fn_1ItSg_is_monotonic, + (fn_get_info_proc_t) fn_1ItSg_get_info, + (fn_get_params_proc_t) fn_1ItSg_get_params, (fn_free_params_proc_t) gs_function_1ItSg_free_params, fn_common_free } @@ -415,6 +474,8 @@ gs_function_AdOt_init(gs_function_t ** ppfn, { (fn_evaluate_proc_t) fn_AdOt_evaluate, (fn_is_monotonic_proc_t) fn_AdOt_is_monotonic, + gs_function_get_info_default, /****** WRONG ******/ + fn_common_get_params, /****** WHAT TO DO ABOUT THIS? ******/ (fn_free_params_proc_t) gs_function_AdOt_free_params, fn_common_free } diff --git a/gs/src/gsparam.c b/gs/src/gsparam.c index a690ee07c..c7de967e8 100644 --- a/gs/src/gsparam.c +++ b/gs/src/gsparam.c @@ -341,12 +341,30 @@ param_write_int_array(gs_param_list * plist, gs_param_name pkey, RETURN_WRITE_TYPED(ia, gs_param_type_int_array); } int +param_write_int_values(gs_param_list * plist, gs_param_name pkey, + const int *values, uint size, bool persistent) +{ + gs_param_int_array ia; + + ia.data = values, ia.size = size, ia.persistent = persistent; + return param_write_int_array(plist, pkey, &ia); +} +int param_write_float_array(gs_param_list * plist, gs_param_name pkey, const gs_param_float_array * pvalue) { RETURN_WRITE_TYPED(fa, gs_param_type_float_array); } int +param_write_float_values(gs_param_list * plist, gs_param_name pkey, + const float *values, uint size, bool persistent) +{ + gs_param_float_array fa; + + fa.data = values, fa.size = size, fa.persistent = persistent; + return param_write_float_array(plist, pkey, &fa); +} +int param_write_string_array(gs_param_list * plist, gs_param_name pkey, const gs_param_string_array * pvalue) { diff --git a/gs/src/gsparam.h b/gs/src/gsparam.h index 27d80e278..5057878ab 100644 --- a/gs/src/gsparam.h +++ b/gs/src/gsparam.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 2000 Aladdin Enterprises. All rights reserved. +/* Copyright (C) 1993, 1995, 1998, 1999 Aladdin Enterprises. All rights reserved. This file is part of Aladdin Ghostscript. @@ -396,10 +396,14 @@ int param_read_int_array(P3(gs_param_list *, gs_param_name, gs_param_int_array *)); int param_write_int_array(P3(gs_param_list *, gs_param_name, const gs_param_int_array *)); +int param_write_int_values(P5(gs_param_list *, gs_param_name, + const int *, uint, bool)); int param_read_float_array(P3(gs_param_list *, gs_param_name, gs_param_float_array *)); int param_write_float_array(P3(gs_param_list *, gs_param_name, const gs_param_float_array *)); +int param_write_float_values(P5(gs_param_list *, gs_param_name, + const float *, uint, bool)); int param_read_string_array(P3(gs_param_list *, gs_param_name, gs_param_string_array *)); int param_write_string_array(P3(gs_param_list *, gs_param_name, diff --git a/gs/src/gxfunc.h b/gs/src/gxfunc.h index fee3bbad6..69bb6024e 100644 --- a/gs/src/gxfunc.h +++ b/gs/src/gxfunc.h @@ -48,4 +48,10 @@ int fn_check_mnDR(P3(const gs_function_params_t * params, int m, int n)); int fn_domain_is_monotonic(P2(const gs_function_t *pfn, gs_function_effort_t effort)); +/* Generic get_info implementation (no Functions or DataSource). */ +FN_GET_INFO_PROC(gs_function_get_info_default); + +/* Write generic parameters (FunctionType, Domain, Range) on a parameter list. */ +int fn_common_get_params(P2(const gs_function_t *pfn, gs_param_list *plist)); + #endif /* gxfunc_INCLUDED */ |