summaryrefslogtreecommitdiff
path: root/pdf/pdf_function.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-02-26 11:15:16 -0800
committerRobin Watts <robin@ghostscript.com>2012-02-26 19:36:30 +0000
commitbbfe635555dce16858403706e2031dd3bfa1a9f1 (patch)
tree6e414005f04f233a83dbeec5607c0665a6d498bc /pdf/pdf_function.c
parentca578b08dc1243dc6cbb3235272d52d9e2336925 (diff)
downloadmupdf-bbfe635555dce16858403706e2031dd3bfa1a9f1.tar.xz
Move fz_obj to be pdf_obj.
Currently, we are in the slightly strange position of having the PDF specific object types as part of fitz. Here we pull them out into the pdf layer instead. This has been made possible by the recent changes to make the store no longer be tied to having fz_obj's as keys. Most of this work is a simple huge rename; to help customers who may have code that use such functions we have provided a sed script to do the renaming; scripts/rename2.sed. Various other small tweaks are required; the store used to have some debugging code that still required knowledge of fz_obj types - we extract that into a nicer 'type' based function pointer. Also, the type 3 font handling used to have an fz_obj pointer for type 3 resources, and therefore needed to know how to free this; this has become a void * with a function to free it.
Diffstat (limited to 'pdf/pdf_function.c')
-rw-r--r--pdf/pdf_function.c138
1 files changed, 69 insertions, 69 deletions
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 17373f42..4273bbc6 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -828,7 +828,7 @@ parse_code(pdf_function *func, fz_stream *stream, int *codeptr)
}
static void
-load_postscript_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, int gen)
+load_postscript_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, int gen)
{
fz_stream *stream = NULL;
int codeptr;
@@ -900,37 +900,37 @@ eval_postscript_func(fz_context *ctx, pdf_function *func, float *in, float *out)
*/
static void
-load_sample_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num, int gen)
+load_sample_func(pdf_function *func, pdf_document *xref, pdf_obj *dict, int num, int gen)
{
fz_context *ctx = xref->ctx;
fz_stream *stream;
- fz_obj *obj;
+ pdf_obj *obj;
int samplecount;
int bps;
int i;
func->u.sa.samples = NULL;
- obj = fz_dict_gets(dict, "Size");
- if (!fz_is_array(obj) || fz_array_len(obj) != func->m)
+ obj = pdf_dict_gets(dict, "Size");
+ if (!pdf_is_array(obj) || pdf_array_len(obj) != func->m)
fz_throw(ctx, "malformed /Size");
for (i = 0; i < func->m; i++)
- func->u.sa.size[i] = fz_to_int(fz_array_get(obj, i));
+ func->u.sa.size[i] = pdf_to_int(pdf_array_get(obj, i));
- obj = fz_dict_gets(dict, "BitsPerSample");
- if (!fz_is_int(obj))
+ obj = pdf_dict_gets(dict, "BitsPerSample");
+ if (!pdf_is_int(obj))
fz_throw(ctx, "malformed /BitsPerSample");
- func->u.sa.bps = bps = fz_to_int(obj);
+ func->u.sa.bps = bps = pdf_to_int(obj);
- obj = fz_dict_gets(dict, "Encode");
- if (fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "Encode");
+ if (pdf_is_array(obj))
{
- if (fz_array_len(obj) != func->m * 2)
+ if (pdf_array_len(obj) != func->m * 2)
fz_throw(ctx, "malformed /Encode");
for (i = 0; i < func->m; i++)
{
- func->u.sa.encode[i][0] = fz_to_real(fz_array_get(obj, i*2+0));
- func->u.sa.encode[i][1] = fz_to_real(fz_array_get(obj, i*2+1));
+ func->u.sa.encode[i][0] = pdf_to_real(pdf_array_get(obj, i*2+0));
+ func->u.sa.encode[i][1] = pdf_to_real(pdf_array_get(obj, i*2+1));
}
}
else
@@ -942,15 +942,15 @@ load_sample_func(pdf_function *func, pdf_document *xref, fz_obj *dict, int num,
}
}
- obj = fz_dict_gets(dict, "Decode");
- if (fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "Decode");
+ if (pdf_is_array(obj))
{
- if (fz_array_len(obj) != func->n * 2)
+ if (pdf_array_len(obj) != func->n * 2)
fz_throw(ctx, "malformed /Decode");
for (i = 0; i < func->n; i++)
{
- func->u.sa.decode[i][0] = fz_to_real(fz_array_get(obj, i*2+0));
- func->u.sa.decode[i][1] = fz_to_real(fz_array_get(obj, i*2+1));
+ func->u.sa.decode[i][0] = pdf_to_real(pdf_array_get(obj, i*2+0));
+ func->u.sa.decode[i][1] = pdf_to_real(pdf_array_get(obj, i*2+1));
}
}
else
@@ -1111,27 +1111,27 @@ eval_sample_func(fz_context *ctx, pdf_function *func, float *in, float *out)
*/
static void
-load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict)
+load_exponential_func(fz_context *ctx, pdf_function *func, pdf_obj *dict)
{
- fz_obj *obj;
+ pdf_obj *obj;
int i;
if (func->m != 1)
fz_throw(ctx, "/Domain must be one dimension (%d)", func->m);
- obj = fz_dict_gets(dict, "N");
- if (!fz_is_int(obj) && !fz_is_real(obj))
+ obj = pdf_dict_gets(dict, "N");
+ if (!pdf_is_int(obj) && !pdf_is_real(obj))
fz_throw(ctx, "malformed /N");
- func->u.e.n = fz_to_real(obj);
+ func->u.e.n = pdf_to_real(obj);
- obj = fz_dict_gets(dict, "C0");
- if (fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "C0");
+ if (pdf_is_array(obj))
{
- func->n = fz_array_len(obj);
+ func->n = pdf_array_len(obj);
if (func->n >= MAXN)
fz_throw(ctx, "exponential function result array out of range");
for (i = 0; i < func->n; i++)
- func->u.e.c0[i] = fz_to_real(fz_array_get(obj, i));
+ func->u.e.c0[i] = pdf_to_real(pdf_array_get(obj, i));
}
else
{
@@ -1139,13 +1139,13 @@ load_exponential_func(fz_context *ctx, pdf_function *func, fz_obj *dict)
func->u.e.c0[0] = 0;
}
- obj = fz_dict_gets(dict, "C1");
- if (fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "C1");
+ if (pdf_is_array(obj))
{
- if (fz_array_len(obj) != func->n)
+ if (pdf_array_len(obj) != func->n)
fz_throw(ctx, "/C1 must match /C0 length");
for (i = 0; i < func->n; i++)
- func->u.e.c1[i] = fz_to_real(fz_array_get(obj, i));
+ func->u.e.c1[i] = pdf_to_real(pdf_array_get(obj, i));
}
else
{
@@ -1185,13 +1185,13 @@ eval_exponential_func(fz_context *ctx, pdf_function *func, float in, float *out)
*/
static void
-load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict)
+load_stitching_func(pdf_function *func, pdf_document *xref, pdf_obj *dict)
{
fz_context *ctx = xref->ctx;
pdf_function **funcs;
- fz_obj *obj;
- fz_obj *sub;
- fz_obj *num;
+ pdf_obj *obj;
+ pdf_obj *sub;
+ pdf_obj *num;
int k;
int i;
@@ -1200,11 +1200,11 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict)
if (func->m != 1)
fz_throw(ctx, "/Domain must be one dimension (%d)", func->m);
- obj = fz_dict_gets(dict, "Functions");
- if (!fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "Functions");
+ if (!pdf_is_array(obj))
fz_throw(ctx, "stitching function has no input functions");
{
- k = fz_array_len(obj);
+ k = pdf_array_len(obj);
func->u.st.funcs = fz_malloc_array(ctx, k, sizeof(pdf_function*));
func->u.st.bounds = fz_malloc_array(ctx, k - 1, sizeof(float));
@@ -1213,9 +1213,9 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict)
for (i = 0; i < k; i++)
{
- sub = fz_array_get(obj, i);
+ sub = pdf_array_get(obj, i);
funcs[i] = pdf_load_function(xref, sub);
- /* RJW: "cannot load sub function %d (%d %d R)", i, fz_to_num(sub), fz_to_gen(sub) */
+ /* RJW: "cannot load sub function %d (%d %d R)", i, pdf_to_num(sub), pdf_to_gen(sub) */
if (funcs[i]->m != 1 || funcs[i]->n != funcs[0]->n)
fz_throw(ctx, "sub function %d /Domain or /Range mismatch", i);
func->size += pdf_function_size(funcs[i]);
@@ -1228,19 +1228,19 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict)
fz_throw(ctx, "sub function /Domain or /Range mismatch");
}
- obj = fz_dict_gets(dict, "Bounds");
- if (!fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "Bounds");
+ if (!pdf_is_array(obj))
fz_throw(ctx, "stitching function has no bounds");
{
- if (fz_array_len(obj) != k - 1)
+ if (pdf_array_len(obj) != k - 1)
fz_throw(ctx, "malformed /Bounds (wrong length)");
for (i = 0; i < k-1; i++)
{
- num = fz_array_get(obj, i);
- if (!fz_is_int(num) && !fz_is_real(num))
+ num = pdf_array_get(obj, i);
+ if (!pdf_is_int(num) && !pdf_is_real(num))
fz_throw(ctx, "malformed /Bounds (item not real)");
- func->u.st.bounds[i] = fz_to_real(num);
+ func->u.st.bounds[i] = pdf_to_real(num);
if (i && func->u.st.bounds[i-1] > func->u.st.bounds[i])
fz_throw(ctx, "malformed /Bounds (item not monotonic)");
}
@@ -1250,16 +1250,16 @@ load_stitching_func(pdf_function *func, pdf_document *xref, fz_obj *dict)
fz_warn(ctx, "malformed shading function bounds (domain mismatch), proceeding anyway.");
}
- obj = fz_dict_gets(dict, "Encode");
- if (!fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "Encode");
+ if (!pdf_is_array(obj))
fz_throw(ctx, "stitching function is missing encoding");
{
- if (fz_array_len(obj) != k * 2)
+ if (pdf_array_len(obj) != k * 2)
fz_throw(ctx, "malformed /Encode");
for (i = 0; i < k; i++)
{
- func->u.st.encode[i*2+0] = fz_to_real(fz_array_get(obj, i*2+0));
- func->u.st.encode[i*2+1] = fz_to_real(fz_array_get(obj, i*2+1));
+ func->u.st.encode[i*2+0] = pdf_to_real(pdf_array_get(obj, i*2+0));
+ func->u.st.encode[i*2+1] = pdf_to_real(pdf_array_get(obj, i*2+1));
}
}
}
@@ -1356,11 +1356,11 @@ pdf_function_size(pdf_function *func)
}
pdf_function *
-pdf_load_function(pdf_document *xref, fz_obj *dict)
+pdf_load_function(pdf_document *xref, pdf_obj *dict)
{
fz_context *ctx = xref->ctx;
pdf_function *func;
- fz_obj *obj;
+ pdf_obj *obj;
int i;
if ((func = pdf_find_item(ctx, pdf_free_function_imp, dict)))
@@ -1372,28 +1372,28 @@ pdf_load_function(pdf_document *xref, fz_obj *dict)
FZ_INIT_STORABLE(func, 1, pdf_free_function_imp);
func->size = sizeof(*func);
- obj = fz_dict_gets(dict, "FunctionType");
- func->type = fz_to_int(obj);
+ obj = pdf_dict_gets(dict, "FunctionType");
+ func->type = pdf_to_int(obj);
/* required for all */
- obj = fz_dict_gets(dict, "Domain");
- func->m = fz_array_len(obj) / 2;
+ obj = pdf_dict_gets(dict, "Domain");
+ func->m = pdf_array_len(obj) / 2;
for (i = 0; i < func->m; i++)
{
- func->domain[i][0] = fz_to_real(fz_array_get(obj, i * 2 + 0));
- func->domain[i][1] = fz_to_real(fz_array_get(obj, i * 2 + 1));
+ func->domain[i][0] = pdf_to_real(pdf_array_get(obj, i * 2 + 0));
+ func->domain[i][1] = pdf_to_real(pdf_array_get(obj, i * 2 + 1));
}
/* required for type0 and type4, optional otherwise */
- obj = fz_dict_gets(dict, "Range");
- if (fz_is_array(obj))
+ obj = pdf_dict_gets(dict, "Range");
+ if (pdf_is_array(obj))
{
func->has_range = 1;
- func->n = fz_array_len(obj) / 2;
+ func->n = pdf_array_len(obj) / 2;
for (i = 0; i < func->n; i++)
{
- func->range[i][0] = fz_to_real(fz_array_get(obj, i * 2 + 0));
- func->range[i][1] = fz_to_real(fz_array_get(obj, i * 2 + 1));
+ func->range[i][0] = pdf_to_real(pdf_array_get(obj, i * 2 + 0));
+ func->range[i][1] = pdf_to_real(pdf_array_get(obj, i * 2 + 1));
}
}
else
@@ -1413,7 +1413,7 @@ pdf_load_function(pdf_document *xref, fz_obj *dict)
switch(func->type)
{
case SAMPLE:
- load_sample_func(func, xref, dict, fz_to_num(dict), fz_to_gen(dict));
+ load_sample_func(func, xref, dict, pdf_to_num(dict), pdf_to_gen(dict));
break;
case EXPONENTIAL:
@@ -1425,12 +1425,12 @@ pdf_load_function(pdf_document *xref, fz_obj *dict)
break;
case POSTSCRIPT:
- load_postscript_func(func, xref, dict, fz_to_num(dict), fz_to_gen(dict));
+ load_postscript_func(func, xref, dict, pdf_to_num(dict), pdf_to_gen(dict));
break;
default:
fz_free(ctx, func);
- fz_throw(ctx, "unknown function type (%d %d R)", fz_to_num(dict), fz_to_gen(dict));
+ fz_throw(ctx, "unknown function type (%d %d R)", pdf_to_num(dict), pdf_to_gen(dict));
}
pdf_store_item(ctx, dict, func, func->size);
@@ -1445,7 +1445,7 @@ pdf_load_function(pdf_document *xref, fz_obj *dict)
type == STITCHING ? "stitching" :
type == POSTSCRIPT ? "calculator" :
"unknown",
- fz_to_num(dict), fz_to_gen(dict));
+ pdf_to_num(dict), pdf_to_gen(dict));
}
return func;