gzz-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gzz-commits] fenfire ./Makefile docs/design_SpanImages.rst o...


From: Tuomas J. Lukka
Subject: [Gzz-commits] fenfire ./Makefile docs/design_SpanImages.rst o...
Date: Mon, 23 Jun 2003 08:28:50 -0400

CVSROOT:        /cvsroot/fenfire
Module name:    fenfire
Branch:         
Changes by:     Tuomas J. Lukka <address@hidden>        03/06/23 08:28:50

Modified files:
        .              : Makefile 
        docs           : design_SpanImages.rst 
        org/fenfire/spanimages: SpanImageFactory.java 
        org/fenfire/spanimages/gl: PageScrollBlockImager.java 
                                   ScrollBlockImager.java 
                                   SingleImage.java 
Added files:
        org/fenfire/spanimages/gl: CachingSpanImageFactory.java 
                                   DefaultSpanImageFactory.java 
                                   PlainPaperMaker.java 

Log message:
        Span image framework complete - now to test and debug...

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/Makefile.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/docs/design_SpanImages.rst.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/SpanImageFactory.java.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/CachingSpanImageFactory.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/DefaultSpanImageFactory.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/PlainPaperMaker.java?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/PageScrollBlockImager.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/fenfire/fenfire/org/fenfire/spanimages/gl/SingleImage.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text

Patches:
Index: fenfire/Makefile
diff -u fenfire/Makefile:1.20 fenfire/Makefile:1.21
--- fenfire/Makefile:1.20       Sun Jun 22 14:18:14 2003
+++ fenfire/Makefile    Mon Jun 23 08:28:50 2003
@@ -15,6 +15,8 @@
 
 
PYTHONPATH=-Dpython.path=../fenfire-depends/jythonlib.jar:../fenfire-depends/jython.jar:../fenfire-depends/pythonlib.jar:.:../libvob:../alph
 
 
+JAVA ?= java
+
 java:
        javac -d build -classpath $(CLASSPATH) `find org -name '*.java'`
 
@@ -23,13 +25,16 @@
 
 DEMO?=org/fenfire/demo/buoyoing.py
 
+runjython:
+       $(LDLIB) java -cp $(CLASSPATH) $(PYTHONPATH) org.python.util.jython 
$(DBG)
+
 rundemo:
        $(LDLIB) java -cp $(CLASSPATH) $(PYTHONPATH) org.python.util.jython 
../libvob/rundemo.py $(DBG) $(DEMO)
 
 BENCH=org.fenfire.swamp.bench.graph
 
 bench:
-       $(LDLIB) java -cp $(CLASSPATH) $(PYTHONPATH) org.python.util.jython 
../libvob/runbench.py $(BENCH)
+       $(LDLIB) $(JAVA) -cp $(CLASSPATH) $(PYTHONPATH) org.python.util.jython 
../libvob/runbench.py $(BENCH)
 
 .PHONY: docs
 
Index: fenfire/docs/design_SpanImages.rst
diff -u fenfire/docs/design_SpanImages.rst:1.8 
fenfire/docs/design_SpanImages.rst:1.9
--- fenfire/docs/design_SpanImages.rst:1.8      Sat Jun 21 09:56:14 2003
+++ fenfire/docs/design_SpanImages.rst  Mon Jun 23 08:28:50 2003
@@ -24,14 +24,16 @@
 
 There are several details which will make life difficult:
 
-- For PageImageSpans, there are several possible mappings from span 
+- For ``PageImageSpan`` objects, there are several possible 
+  mappings from span 
   to vob, since there are several possible renderings: without background
   paper, with background paper, with halos or blurring on the background
   paper &c.  Obviously, the code to go from an OpenGL texture to the
   rendered vob must be pluggable to allow for these features and future
   extensions in rendering of images of text.
 
-- Both the whole page and fragments of the page may be desired as separate vobs
+- Both the whole page and fragments of the page may be desired 
+  as separate vobs
 
 - The coordinate system of the page in the texture is not fixed between 
   different spans; different resolutions might be used.
@@ -81,7 +83,7 @@
     vertically(90, yy, org.nongnu.libvob.Vob, SpanImageVob);
     vertically(90, zz, org.nongnu.alph.ImageSpan, SpanImageFactory);
 
-Apart from the option of creating different kinds of SpanImageFactories
+Apart from the option of creating different ``SpanImageFactory`` objects
 with different properties for e.g. page backgrounds, this is all the
 other classes need to see.
 
@@ -92,11 +94,12 @@
 (once an AWT implementation is made, it will be in the package
 ``org.fenfire.spanimages.fuzzybear``).
 
-ImageSpan vs PageImageSpan
---------------------------
+``ImageSpan`` vs ``PageImageSpan``
+----------------------------------
 
-It is reasonable to expect different treatment of Image and PageImage
-spans: for PageImageSpans, we may want libpaper backgrounds and
+It is reasonable to expect different treatment of 
+``ImageSpan`` and ``PageImageSpan`` objects: 
+for ``PageImageSpan`` objects, we will often want libpaper backgrounds and
 text-enhancing transformations.
 
 ..  UML:: fenfirespansint2
@@ -109,20 +112,54 @@
     class MuxSpanImageFactory 
        jlink
        realize SpanImageFactory
+
+    foo = assoc MuxSpanImageFactory role(mux) - multi(1) role(imagefact) 
SpanImageFactory
+    bar = assoc MuxSpanImageFactory role(mux) - multi(1) role(pageimagefact) 
SpanImageFactory
+    ---
+    SpanImageFactory.c = (0,0);
+    horizontally(80, xx, SpanImageFactory, MuxSpanImageFactory);
+
+    sk=-.35;
+    foo.p = (MuxSpanImageFactory.c{sk,1}..SpanImageFactory.c{sk,-1});
+    bar.p = (MuxSpanImageFactory.c{sk,-1}..SpanImageFactory.c{sk,1});
+
+The ``MuxSpanImageFactory`` object
+delegates calls to one factory for ``PageImageSpan`` objects
+and to the other
+for plain ``ImageSpan`` objects.
+
+Caching of ``SpanImageVob`` objects
+-----------------------------------
+
+The caching is taken care by another step added to the chain:
+
+.. UML:: fenfirespans_caching
+
+    jlinkpackage org.fenfire.spanimages
+    class SpanImageFactory "abstract"
+       jlink
+
+    class CachingSpanImageFactory
+       realize SpanImageFactory
+       jlink
        fields
-           SpanImageFactory imageFactory
-           SpanImageFactory pageImageFactory
+           Map cache
+
+    foo = assoc CachingSpanImageFactory role(cache) - multi(1) role(orig) 
SpanImageFactory
 
     ---
-    horizontally(80, xx, MuxSpanImageFactory, SpanImageFactory);
+    SpanImageFactory.c = (0,0);
+    horizontally(80, xx, SpanImageFactory, CachingSpanImageFactory);
+    sk = -.35;
+    foo.p := (CachingSpanImageFactory.c{sk,1}..SpanImageFactory.c{sk,-1});
 
-MuxSpanImageFactory calls one factory for pageimagespans and the other
-for plain image spans.
+The ``CachingSpanImageFactory`` will first check its cache and 
+only if it does not find the object cached will it recreate it.
 
-Repository of loaded images
----------------------------
+Repository of loaded textures
+-----------------------------
 
-The class twin classes
+The twin classes
 ``PageScrollBlockImager`` and ``ImageScrollBlockImager``
 take care of mapping spans to OpenGL textures (mipzips).
 
@@ -172,7 +209,7 @@
     
 
 An important architectural feature is that the classes are not static:
-this allows us to, e.g, plug in filters for the images of PageImageSpan.
+this allows us to, e.g, plug in filters for the images of ``PageImageSpan``.
 
 The Single Image class
 ----------------------
@@ -186,7 +223,6 @@
 
     class SingleImage
        jlink
-       realize org.nongnu.libvob.gl.GL.StatsCallback
        assoc compos multi(1) - multi(1) org.nongnu.libvob.gl.MipzipLoader
        assoc compos multi(1) - multi(1) org.nongnu.libvob.gl.GL.TexAccum
        fields
@@ -249,15 +285,18 @@
 ------------------------------------------------
 
 Now we come to the *raison d'etre* of this architecture: centralized
-handling of the feedback from vobscene rendering.  The TexAccum class in
+handling of the feedback from vobscene rendering.  The ``TexAccum`` class in
 Libvob is able to accumulate the approximate number of pixels rendered
-at each mipmap level of each texture. This is collected by the SingleImage 
class.
+at each mipmap level of each texture. This is collected 
+by the ``SingleImage``
+.
 
-Because the ``MemoryPartitioner`` approach is a bit hard for us to interface 
with here
+Because the ``MemoryPartitioner`` approach is a bit hard 
+for us to interface with here
 (the quality - calling time stuff is not optimal for us) we have 
 our own partitioner.
 
-The PoolManager keeps a set of active textures.
+The ``PoolManager`` keeps a set of active textures.
 
 ..  UML:: fenfirespans_texaccum
 
Index: fenfire/org/fenfire/spanimages/SpanImageFactory.java
diff -u fenfire/org/fenfire/spanimages/SpanImageFactory.java:1.3 
fenfire/org/fenfire/spanimages/SpanImageFactory.java:1.4
--- fenfire/org/fenfire/spanimages/SpanImageFactory.java:1.3    Wed Jun 11 
13:00:24 2003
+++ fenfire/org/fenfire/spanimages/SpanImageFactory.java        Mon Jun 23 
08:28:50 2003
@@ -31,6 +31,10 @@
  * images of ImageSpans.
  * The backend of this interface takes care of all caching and other
  * operations necessary.
+ * <p>
+ * The normal size for the SpanImageVob (w and h) is either pixel-for-pixel,
+ * if the imagespan contains raster data, or 75 pixels per inch, if
+ * the imagespan contains vector data.
  */
 public abstract class SpanImageFactory {
     public static SpanImageFactory getDefaultInstance() {
Index: fenfire/org/fenfire/spanimages/gl/PageScrollBlockImager.java
diff -u fenfire/org/fenfire/spanimages/gl/PageScrollBlockImager.java:1.1 
fenfire/org/fenfire/spanimages/gl/PageScrollBlockImager.java:1.2
--- fenfire/org/fenfire/spanimages/gl/PageScrollBlockImager.java:1.1    Thu Jun 
12 07:07:45 2003
+++ fenfire/org/fenfire/spanimages/gl/PageScrollBlockImager.java        Mon Jun 
23 08:28:50 2003
@@ -1,7 +1,136 @@
 // (c) Tuomas J. Lukka
 
 package org.fenfire.spanimages.gl;
+import org.nongnu.alph.*;
+import org.nongnu.alph.util.*;
+import org.nongnu.libvob.util.*;
+import org.nongnu.storm.*;
+import org.python.util.*;
+import org.python.core.*;
+import java.awt.image.*;
+import java.io.*;
+import java.util.*;
+
+public class PageScrollBlockImager extends ScrollBlockImager {
+
+    public int RESOLUTION = 160;
+
+    /** A cache of block file names.
+     * Useful because usually pages of the same file are created
+     * right next to each other.
+     */
+    private Map block2pagefiles = Collections.synchronizedMap(
+                                   new CachingMap(200));
+
+    /** A list (index==page) of maps (key==blockid, value==SingleImage).
+     * There are far fewer pages than blocks - therefore,
+     * we'll use a list of pages and for each page, a map
+     * from block id to singleimage.
+     * A bit strange but efficient.
+     */
+    private List pageblock2singleimage  = Collections.synchronizedList(new 
ArrayList());
+    private Map getPageblock2singleimageMap(int i) {
+       while(i >= pageblock2singleimage.size()) 
+           pageblock2singleimage.add(null);
+       Map m = (Map)pageblock2singleimage.get(i);
+       if(m == null) {
+           m = Collections.synchronizedMap(new SoftValueMap());
+           pageblock2singleimage.set(i, m);
+       }
+       return m;
+    }
+
+    public SingleImage getSingleImage(ImageSpan img) {
+       PageImageSpan span = (PageImageSpan)img;
+       int page = span.getPageIndex();
+
+       Map map = getPageblock2singleimageMap(page);
+       ScrollBlock sb = img.getScrollBlock();
+       SingleImage singleImage = (SingleImage)map.get(sb.getID());
+
+       if(singleImage == null) {
+
+           try {
+               String[] pageFiles = getPageFiles(sb);
+               singleImage = new SingleImage(
+                       sb.getID(),
+                       page,
+                       pageFiles[page],
+                       RESOLUTION
+                       );
+           } catch(Exception e) {
+               throw new Error("Couldn't create singleimage!");
+           }
+           map.put(sb.getID(), singleImage);
+       }
+       return singleImage;
+    }
+
+    private String[] getPageFiles(ScrollBlock pages) 
+           throws FileNotFoundException {
+       String[] f = (String[]) block2pagefiles.get(pages);
+       if(f == null) {
+           f = makePageFiles(pages);
+           block2pagefiles.put(pages, f);
+       }
+       return f;
+    }
+
+    PythonInterpreter interp;
+
+    private synchronized String[] makePageFiles(ScrollBlock pages) 
+           throws java.io.FileNotFoundException {
+       String ct = pages.getContentType();
+       if(! (ct.equals("application/pdf") ||
+             ct.equals("application/postscript")))
+           throw new Error("Not a proper page scroll");
+
+       int n = ((Span1D)(pages.getCurrent())).length();
+
+       String prefix = protectChars(pages.getID()) + "-" + RESOLUTION + "-";
+
+       String[] tmppaths = new String[n];
+       String[] paths = new String[n];
+       boolean exist = true;
+       for(int i=0; i<n; i++) {
+           String base = prefix + (i+1);
+           File f = new File(tmp(), base);
+           paths[i] = f.getPath();
+           tmppaths[i] = new File(tmp(), "tmp"+base).getPath();
+           if(!f.exists()) exist = false;
+       }
+       if(exist) return paths;
+       
+       // Need to make them.
+       //
+       if(interp == null) {
+           interp = new PythonInterpreter();
+           interp.exec("import alph.util.psimages\n"+
+                       "import vob.putil.mipzipmaker\n"+
+                       "cv = alph.util.psimages.convertFile\n"+
+                       "mz = vob.putil.mipzipmaker.makeMipzip\n"
+                       );
+       }
+
+       // 1. Convert ps/pdf to .png files
+       BlockFile f = pages.getBlockFile();
+       if(! interp.get("cv").__call__(new PyObject[] {
+           new PyString(f.getFilename()),
+           new PyString(new File(tmp(), "tmp"+prefix).getPath()),
+           new PyInteger(RESOLUTION)
+       }).__nonzero__())
+           throw new Error("Conversion unsuccessful");
+
+       for(int i=0; i<n; i++) {
+           interp.get("mz").__call__(new PyObject[] {
+               new PyString(tmppaths[i]),
+               new PyString(paths[i])
+           });
+           (new File(tmppaths[i])).delete();
+       }
+
+       return paths;
+    }
 
-public abstract class PageScrollBlockImager {
 
 }
Index: fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java
diff -u fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java:1.1 
fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java:1.2
--- fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java:1.1        Thu Jun 
12 07:07:45 2003
+++ fenfire/org/fenfire/spanimages/gl/ScrollBlockImager.java    Mon Jun 23 
08:28:50 2003
@@ -2,6 +2,7 @@
 
 package org.fenfire.spanimages.gl;
 import java.io.File;
+import org.nongnu.alph.*;
 
 /** Base class for the classes holding scrollblock images.
  * Contains some necessary trappings.
@@ -17,7 +18,7 @@
 
     /** Hide the slash and colon characters from the filesystem.
      */
-    static private String protectChars(String s) {
+    static protected String protectChars(String s) {
        StringBuffer res = new StringBuffer();
        for(int i=0; i<s.length(); i++) {
            char c = s.charAt(i);
@@ -29,4 +30,7 @@
        }
        return res.toString();
     }
+
+    public abstract SingleImage getSingleImage(ImageSpan img) ;
+
 }
Index: fenfire/org/fenfire/spanimages/gl/SingleImage.java
diff -u fenfire/org/fenfire/spanimages/gl/SingleImage.java:1.2 
fenfire/org/fenfire/spanimages/gl/SingleImage.java:1.3
--- fenfire/org/fenfire/spanimages/gl/SingleImage.java:1.2      Sat Jun 21 
09:56:14 2003
+++ fenfire/org/fenfire/spanimages/gl/SingleImage.java  Mon Jun 23 08:28:50 2003
@@ -13,8 +13,8 @@
     public static boolean dbg = true;
     private static void p(String s) { System.out.println("SingleImage: "+s); }
 
-    public MipzipLoader loader;
-    public GL.TexAccum accum;
+    public final MipzipLoader loader;
+    public final GL.TexAccum accum;
 
     /** For each mipmap level of loader, the number of pixels
      * that would be rendered less than optimally.
@@ -47,7 +47,8 @@
      * @param filename The file to load the image from.
      * @param resolution The resolution (DPI) the image in the file is at.
      *          For example, if a PS file was compiled into an image at
-     *          160dpi, then this number is 160.
+     *          160dpi, then this number is 160. Zero or negative = unknown,
+     *          use pixel data.
      */
     public SingleImage(
                    String scrollBlock, int page,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]