From c59fe5fe4739f0c61560f05d4e42b4e552219b27 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Sat, 28 May 2011 02:18:52 +0000 Subject: asy 2.10 git-svn-id: svn://tug.org/texlive/trunk@22633 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/utils/asymptote/psfile.cc | 52 ++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'Build/source/utils/asymptote/psfile.cc') diff --git a/Build/source/utils/asymptote/psfile.cc b/Build/source/utils/asymptote/psfile.cc index 659f7e09057..c2f0f24982e 100644 --- a/Build/source/utils/asymptote/psfile.cc +++ b/Build/source/utils/asymptote/psfile.cc @@ -15,11 +15,15 @@ #include "settings.h" #include "errormsg.h" #include "array.h" +#include "stack.h" using std::ofstream; using std::setw; using vm::array; using vm::read; +using vm::stack; +using vm::callable; +using vm::pop; namespace camp { @@ -48,6 +52,7 @@ psfile::psfile(const string& filename, bool pdfformat) } static const char *inconsistent="inconsistent colorspaces"; +static const char *rectangular="matrix is not rectangular"; void psfile::writefromRGB(unsigned char r, unsigned char g, unsigned char b, ColorSpace colorspace, size_t ncomponents) @@ -324,7 +329,7 @@ void psfile::latticeshade(const vm::array& a, const transform& t) array *ai=read(a,--i); checkArray(ai); size_t aisize=ai->size(); - if(aisize != m) reportError("shading matrix must be rectangular"); + if(aisize != m) reportError(rectangular); for(size_t j=0; j < m; j++) { pen *p=read(ai,j); p->convert(); @@ -561,7 +566,10 @@ void psfile::image(const array& a, const array& P, bool antialias) double max=min; for(size_t i=0; i < asize; i++) { array *ai=read(a,i); - for(size_t j=0; j < a0size; j++) { + size_t size=ai->size(); + if(size != a0size) + reportError(rectangular); + for(size_t j=0; j < size; j++) { double val=read(ai,j); if(val > max) max=val; else if(val < min) min=val; @@ -607,7 +615,10 @@ void psfile::image(const array& a, bool antialias) beginImage(ncomponents*a0size*asize); for(size_t i=0; i < asize; i++) { array *ai=read(a,i); - for(size_t j=0; j < a0size; j++) { + size_t size=ai->size(); + if(size != a0size) + reportError(rectangular); + for(size_t j=0; j < size; j++) { pen *p=read(ai,j); p->convert(); if(!p->promote(colorspace)) @@ -618,6 +629,41 @@ void psfile::image(const array& a, bool antialias) endImage(antialias,a0size,asize,ncomponents); } +void psfile::image(stack *Stack, callable *f, Int width, Int height, + bool antialias) +{ + if(width <= 0 || height <= 0) return; + + Stack->push(0); + Stack->push(0); + f->call(Stack); + pen p=pop(Stack); + + setopacity(p); + + ColorSpace colorspace=p.colorspace(); + checkColorSpace(colorspace); + + size_t ncomponents=ColorComponents[colorspace]; + + imageheader(width,height,colorspace); + + beginImage(ncomponents*width*height); + for(Int i=0; i < width; i++) { + for(Int j=0; j < height; j++) { + Stack->push(i); + Stack->push(j); + f->call(Stack); + pen p=pop(Stack); + p.convert(); + if(!p.promote(colorspace)) + reportError(inconsistent); + write(&p,ncomponents); + } + } + endImage(antialias,width,height,ncomponents); +} + void psfile::outImage(bool antialias, size_t width, size_t height, size_t ncomponents) { -- cgit v1.2.3